{
  "version": 3,
  "sources": ["../../../../src/lib/components/default-components/DefaultShapeIndicators.tsx"],
  "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { TLShapeId } from '@tldraw/tlschema'\nimport { memo, useRef } from 'react'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useEditorComponents } from '../../hooks/useEditorComponents'\n\n/** @public @react */\nexport const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {\n\tconst editor = useEditor()\n\n\tconst rPreviousSelectedShapeIds = useRef<Set<TLShapeId>>(new Set())\n\n\tconst idsToDisplay = useValue(\n\t\t'should display selected ids',\n\t\t() => {\n\t\t\tconst prev = rPreviousSelectedShapeIds.current\n\t\t\tconst next = new Set<TLShapeId>()\n\n\t\t\tif (\n\t\t\t\t// We only show indicators when in the following states...\n\t\t\t\teditor.isInAny(\n\t\t\t\t\t'select.idle',\n\t\t\t\t\t'select.brushing',\n\t\t\t\t\t'select.scribble_brushing',\n\t\t\t\t\t'select.editing_shape',\n\t\t\t\t\t'select.pointing_shape',\n\t\t\t\t\t'select.pointing_selection',\n\t\t\t\t\t'select.pointing_handle'\n\t\t\t\t) &&\n\t\t\t\t// ...but we hide indicators when we've just changed a style (so that the user can see the change)\n\t\t\t\t!editor.getInstanceState().isChangingStyle\n\t\t\t) {\n\t\t\t\t// We always want to show indicators for the selected shapes, if any\n\t\t\t\tconst selected = editor.getSelectedShapeIds()\n\t\t\t\tfor (const id of selected) {\n\t\t\t\t\tnext.add(id)\n\t\t\t\t}\n\n\t\t\t\t// If we're idle or editing a shape, we want to also show an indicator for the hovered shape, if any\n\t\t\t\tif (editor.isInAny('select.idle', 'select.editing_shape')) {\n\t\t\t\t\tconst instanceState = editor.getInstanceState()\n\t\t\t\t\tif (instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {\n\t\t\t\t\t\tconst hovered = editor.getHoveredShapeId()\n\t\t\t\t\t\tif (hovered) next.add(hovered)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Ok, has anything changed?\n\n\t\t\t// If the number of items in the set is different, then the selection has changed. This catches most changes.\n\t\t\tif (prev.size !== next.size) {\n\t\t\t\trPreviousSelectedShapeIds.current = next\n\t\t\t\treturn next\n\t\t\t}\n\n\t\t\t// If any of the new ids are not in the previous set, then the selection has changed\n\t\t\tfor (const id of next) {\n\t\t\t\tif (!prev.has(id)) {\n\t\t\t\t\trPreviousSelectedShapeIds.current = next\n\t\t\t\t\treturn next\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If nothing has changed, then return the previous value\n\t\t\treturn prev\n\t\t},\n\t\t[editor]\n\t)\n\n\t// Show indicators only for the shapes that are currently being rendered (ie that are on screen)\n\tconst renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])\n\n\tconst { ShapeIndicator } = useEditorComponents()\n\tif (!ShapeIndicator) return null\n\n\treturn renderingShapes.map(({ id }) => (\n\t\t<ShapeIndicator key={id + '_indicator'} shapeId={id} hidden={!idsToDisplay.has(id)} />\n\t))\n})\n"],
  "mappings": "AA6EE;AA7EF,SAAS,gBAAgB;AAEzB,SAAS,MAAM,cAAc;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAG7B,MAAM,yBAAyB,KAAK,SAASA,0BAAyB;AAC5E,QAAM,SAAS,UAAU;AAEzB,QAAM,4BAA4B,OAAuB,oBAAI,IAAI,CAAC;AAElE,QAAM,eAAe;AAAA,IACpB;AAAA,IACA,MAAM;AACL,YAAM,OAAO,0BAA0B;AACvC,YAAM,OAAO,oBAAI,IAAe;AAEhC;AAAA;AAAA,QAEC,OAAO;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QAEA,CAAC,OAAO,iBAAiB,EAAE;AAAA,QAC1B;AAED,cAAM,WAAW,OAAO,oBAAoB;AAC5C,mBAAW,MAAM,UAAU;AAC1B,eAAK,IAAI,EAAE;AAAA,QACZ;AAGA,Y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