tldraw 4.3.0-next.2b3bfbba757b → 4.3.0-next.39f1d5b92226

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist-cjs/index.d.ts +14 -5
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
  4. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js.map +2 -2
  5. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  6. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  7. package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +2 -2
  8. package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
  9. package/dist-cjs/lib/shapes/arrow/elbow/elbowArrowSnapLines.js.map +2 -2
  10. package/dist-cjs/lib/shapes/arrow/shared.js.map +2 -2
  11. package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
  12. package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +2 -2
  13. package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js.map +2 -2
  14. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
  15. package/dist-cjs/lib/shapes/frame/FrameShapeTool.js.map +1 -1
  16. package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
  17. package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
  18. package/dist-cjs/lib/shapes/note/noteHelpers.js.map +2 -2
  19. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  20. package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
  21. package/dist-cjs/lib/shapes/shared/crop.js +1 -0
  22. package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
  23. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  24. package/dist-cjs/lib/shapes/shared/useEditableRichText.js.map +2 -2
  25. package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
  26. package/dist-cjs/lib/tools/EraserTool/childStates/Erasing.js.map +2 -2
  27. package/dist-cjs/lib/tools/EraserTool/childStates/Pointing.js.map +2 -2
  28. package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js +1 -4
  29. package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js.map +2 -2
  30. package/dist-cjs/lib/tools/SelectTool/childStates/Brushing.js.map +2 -2
  31. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js.map +2 -2
  32. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +1 -1
  33. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  34. package/dist-cjs/lib/tools/SelectTool/childStates/EditingShape.js.map +2 -2
  35. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  36. package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
  37. package/dist-cjs/lib/tools/SelectTool/childStates/PointingHandle.js.map +2 -2
  38. package/dist-cjs/lib/tools/SelectTool/childStates/PointingSelection.js.map +2 -2
  39. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
  40. package/dist-cjs/lib/tools/SelectTool/childStates/ScribbleBrushing.js.map +2 -2
  41. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  42. package/dist-cjs/lib/ui/components/EditLinkDialog.js +11 -1
  43. package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
  44. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  45. package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
  46. package/dist-cjs/lib/ui/context/actions.js +1 -2
  47. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  48. package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
  49. package/dist-cjs/lib/ui/hooks/useFlatten.js.map +2 -2
  50. package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
  51. package/dist-cjs/lib/ui/version.js +3 -3
  52. package/dist-cjs/lib/ui/version.js.map +1 -1
  53. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js +8 -0
  54. package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
  55. package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
  56. package/dist-cjs/lib/utils/frames/frames.js.map +2 -2
  57. package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
  58. package/dist-esm/index.d.mts +14 -5
  59. package/dist-esm/index.mjs +1 -1
  60. package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
  61. package/dist-esm/lib/canvas/TldrawSelectionForeground.mjs.map +2 -2
  62. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  63. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  64. package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +2 -2
  65. package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
  66. package/dist-esm/lib/shapes/arrow/elbow/elbowArrowSnapLines.mjs.map +2 -2
  67. package/dist-esm/lib/shapes/arrow/shared.mjs.map +2 -2
  68. package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
  69. package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +2 -2
  70. package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs.map +2 -2
  71. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
  72. package/dist-esm/lib/shapes/frame/FrameShapeTool.mjs.map +1 -1
  73. package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
  74. package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
  75. package/dist-esm/lib/shapes/note/noteHelpers.mjs.map +2 -2
  76. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  77. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
  78. package/dist-esm/lib/shapes/shared/crop.mjs +1 -0
  79. package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
  80. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  81. package/dist-esm/lib/shapes/shared/useEditableRichText.mjs.map +2 -2
  82. package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
  83. package/dist-esm/lib/tools/EraserTool/childStates/Erasing.mjs.map +2 -2
  84. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs +1 -4
  85. package/dist-esm/lib/tools/EraserTool/childStates/Pointing.mjs.map +2 -2
  86. package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs +1 -4
  87. package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs.map +2 -2
  88. package/dist-esm/lib/tools/SelectTool/childStates/Brushing.mjs.map +2 -2
  89. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs.map +2 -2
  90. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +1 -1
  91. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  92. package/dist-esm/lib/tools/SelectTool/childStates/EditingShape.mjs.map +2 -2
  93. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  94. package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
  95. package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs +1 -4
  96. package/dist-esm/lib/tools/SelectTool/childStates/PointingHandle.mjs.map +2 -2
  97. package/dist-esm/lib/tools/SelectTool/childStates/PointingSelection.mjs.map +2 -2
  98. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
  99. package/dist-esm/lib/tools/SelectTool/childStates/ScribbleBrushing.mjs.map +2 -2
  100. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  101. package/dist-esm/lib/ui/components/EditLinkDialog.mjs +11 -1
  102. package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
  103. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  104. package/dist-esm/lib/ui/components/menu-items.mjs +1 -4
  105. package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
  106. package/dist-esm/lib/ui/context/actions.mjs +1 -2
  107. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  108. package/dist-esm/lib/ui/hooks/menu-hooks.mjs +1 -4
  109. package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
  110. package/dist-esm/lib/ui/hooks/useFlatten.mjs.map +2 -2
  111. package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
  112. package/dist-esm/lib/ui/version.mjs +3 -3
  113. package/dist-esm/lib/ui/version.mjs.map +1 -1
  114. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +8 -0
  115. package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
  116. package/dist-esm/lib/utils/export/exportAs.mjs +1 -3
  117. package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
  118. package/dist-esm/lib/utils/frames/frames.mjs.map +2 -2
  119. package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
  120. package/package.json +10 -10
  121. package/src/lib/bindings/arrow/ArrowBindingUtil.ts +1 -1
  122. package/src/lib/canvas/TldrawSelectionForeground.tsx +4 -9
  123. package/src/lib/defaultExternalContentHandlers.ts +3 -4
  124. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +2 -2
  125. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +1 -1
  126. package/src/lib/shapes/arrow/arrowLabel.ts +1 -1
  127. package/src/lib/shapes/arrow/arrowTargetState.ts +1 -1
  128. package/src/lib/shapes/arrow/elbow/elbowArrowSnapLines.tsx +3 -3
  129. package/src/lib/shapes/arrow/shared.ts +4 -4
  130. package/src/lib/shapes/arrow/toolStates/Pointing.tsx +1 -1
  131. package/src/lib/shapes/bookmark/bookmarks.ts +3 -3
  132. package/src/lib/shapes/draw/toolStates/Drawing.ts +4 -4
  133. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +1 -1
  134. package/src/lib/shapes/frame/FrameShapeTool.ts +1 -1
  135. package/src/lib/shapes/geo/GeoShapeUtil.test.tsx +10 -2
  136. package/src/lib/shapes/geo/toolStates/Pointing.ts +3 -3
  137. package/src/lib/shapes/line/LineShapeTool.test.ts +6 -6
  138. package/src/lib/shapes/line/LineShapeUtil.test.tsx +5 -5
  139. package/src/lib/shapes/line/toolStates/Pointing.ts +1 -1
  140. package/src/lib/shapes/note/NoteShapeTool.test.ts +2 -1
  141. package/src/lib/shapes/note/noteHelpers.ts +2 -2
  142. package/src/lib/shapes/shared/PlainTextLabel.tsx +2 -1
  143. package/src/lib/shapes/shared/RichTextLabel.tsx +2 -1
  144. package/src/lib/shapes/shared/crop.ts +1 -0
  145. package/src/lib/shapes/shared/useEditablePlainText.ts +7 -3
  146. package/src/lib/shapes/shared/useEditableRichText.ts +7 -3
  147. package/src/lib/shapes/text/TextShapeTool.test.ts +4 -4
  148. package/src/lib/shapes/text/toolStates/Pointing.ts +1 -1
  149. package/src/lib/tools/EraserTool/childStates/Erasing.ts +3 -5
  150. package/src/lib/tools/EraserTool/childStates/Pointing.ts +3 -16
  151. package/src/lib/tools/SelectTool/DragAndDropManager.ts +2 -4
  152. package/src/lib/tools/SelectTool/childStates/Brushing.ts +2 -6
  153. package/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts +2 -3
  154. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +4 -7
  155. package/src/lib/tools/SelectTool/childStates/EditingShape.ts +2 -4
  156. package/src/lib/tools/SelectTool/childStates/Idle.ts +6 -10
  157. package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +1 -1
  158. package/src/lib/tools/SelectTool/childStates/PointingHandle.ts +4 -12
  159. package/src/lib/tools/SelectTool/childStates/PointingSelection.ts +2 -2
  160. package/src/lib/tools/SelectTool/childStates/Resizing.ts +2 -4
  161. package/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts +2 -4
  162. package/src/lib/tools/SelectTool/childStates/Translating.ts +1 -3
  163. package/src/lib/ui/components/EditLinkDialog.tsx +16 -6
  164. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +2 -2
  165. package/src/lib/ui/components/menu-items.tsx +6 -14
  166. package/src/lib/ui/context/actions.tsx +9 -13
  167. package/src/lib/ui/hooks/menu-hooks.ts +9 -19
  168. package/src/lib/ui/hooks/useFlatten.ts +1 -2
  169. package/src/lib/ui/hooks/useTools.tsx +1 -2
  170. package/src/lib/ui/version.ts +3 -3
  171. package/src/lib/utils/excalidraw/putExcalidrawContent.ts +8 -0
  172. package/src/lib/utils/export/exportAs.ts +2 -9
  173. package/src/lib/utils/frames/frames.ts +1 -1
  174. package/src/lib/utils/tldr/buildFromV1Document.ts +12 -17
  175. package/src/test/Editor.test.tsx +38 -12
  176. package/src/test/SelectTool.test.ts +11 -19
  177. package/src/test/TestEditor.ts +1 -4
  178. package/src/test/TldrawEditor.test.tsx +21 -18
  179. package/src/test/bindings.test.tsx +29 -25
  180. package/src/test/bindingsIndex.test.tsx +4 -4
  181. package/src/test/commands/createShape.test.ts +64 -0
  182. package/src/test/commands/createShapes.test.ts +15 -1
  183. package/src/test/commands/getSvgString.test.ts +2 -2
  184. package/src/test/commands/isShapeOfType.test.ts +44 -0
  185. package/src/test/commands/putContent.test.ts +1 -0
  186. package/src/test/commands/updateShape.test.ts +67 -0
  187. package/src/test/commands/updateShapes.test.ts +21 -5
  188. package/src/test/custom-clipping.test.ts +36 -35
  189. package/src/test/customSnapping.test.tsx +77 -62
  190. package/src/test/duplicate.test.ts +1 -1
  191. package/src/test/frames.test.ts +2 -2
  192. package/src/test/getCulledShapes.test.tsx +11 -3
  193. package/src/test/getShapeAtPoint.test.ts +2 -2
  194. package/src/test/groups.test.tsx +6 -3
  195. package/src/test/resizing.test.ts +9 -13
  196. package/src/test/selection-omnibus.test.ts +11 -11
  197. package/src/test/shapeutils.test.ts +1 -1
  198. package/src/test/styles2.test.tsx +1 -1
  199. package/src/test/styles3.test.ts +5 -5
  200. package/src/test/test-jsx.tsx +69 -57
  201. package/src/test/text.test.ts +15 -17
  202. package/src/test/translating.test.ts +6 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/tools/SelectTool/DragAndDropManager.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tIndexKey,\n\tTLGroupShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tVec,\n\tbind,\n\tcompact,\n\tisShapeId,\n} from '@tldraw/editor'\n\nconst SLOW_POINTER_LAG_DURATION = 320\nconst FAST_POINTER_LAG_DURATION = 60\n\n/** @public */\nexport class DragAndDropManager {\n\tconstructor(public editor: Editor) {\n\t\teditor.disposables.add(this.dispose)\n\t}\n\n\tshapesToActuallyMove: TLShape[] = []\n\tdraggedOverShapeIds = new Set<TLShapeId>()\n\n\tinitialGroupIds = new Map<TLShapeId, TLShapeId>()\n\tinitialParentIds = new Map<TLShapeId, TLParentId>()\n\tinitialIndices = new Map<TLShapeId, IndexKey>()\n\n\tinitialDraggingOverShape?: TLShape\n\tprevDraggingOverShape?: TLShape\n\tprevPagePoint = new Vec()\n\n\tintervalTimerId = -1\n\n\tstartDraggingShapes(movingShapes: TLShape[], point: Vec, cb: () => void) {\n\t\tconst { editor } = this\n\n\t\t// Only start dragging if we're not already dragging\n\t\tif (this.intervalTimerId !== -1) return\n\n\t\tconst shapesToActuallyMove = new Set(movingShapes)\n\t\tconst movingGroups = new Set<TLGroupShape>()\n\n\t\tfor (const shape of shapesToActuallyMove) {\n\t\t\tconst parent = editor.getShapeParent(shape)\n\t\t\tif (parent && editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\t\tmovingGroups.add(parent)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If all of a group's children are moving, then move the group instead\n\t\tfor (const movingGroup of movingGroups) {\n\t\t\tconst children = compact(\n\t\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t\t)\n\t\t\tshapesToActuallyMove.add(movingGroup)\n\t\t\tfor (const child of children) {\n\t\t\t\tshapesToActuallyMove.delete(child)\n\t\t\t}\n\t\t}\n\n\t\tthis.initialParentIds.clear()\n\t\tfor (const shape of shapesToActuallyMove) {\n\t\t\tconst parent = editor.getShapeParent(shape)\n\t\t\tif (parent) {\n\t\t\t\tthis.initialParentIds.set(shape.id, parent.id)\n\t\t\t}\n\t\t\tthis.initialIndices.set(shape.id, shape.index)\n\n\t\t\tconst group = editor.findShapeAncestor(shape, (s) =>\n\t\t\t\teditor.isShapeOfType<TLGroupShape>(s, 'group')\n\t\t\t)\n\t\t\tif (group) {\n\t\t\t\tthis.initialGroupIds.set(shape.id, group.id)\n\t\t\t}\n\t\t}\n\n\t\tconst allShapes = editor.getCurrentPageShapesSorted()\n\t\tthis.shapesToActuallyMove = Array.from(shapesToActuallyMove)\n\t\t\t.filter((s) => !s.isLocked)\n\t\t\t.sort((a, b) => allShapes.indexOf(a) - allShapes.indexOf(b))\n\n\t\tthis.initialDraggingOverShape = editor.getDraggingOverShape(point, this.shapesToActuallyMove)\n\t\tthis.prevDraggingOverShape = this.initialDraggingOverShape\n\n\t\t// run once on first frame\n\t\tthis.updateDraggingShapes(point, cb)\n\n\t\t// then once on an interval, skipping frames if moving quickly\n\t\tlet skip2of3FramesWhileMovingFast = 0\n\t\tthis.intervalTimerId = this.editor.timers.setInterval(\n\t\t\t() => {\n\t\t\t\tskip2of3FramesWhileMovingFast++\n\t\t\t\tif (skip2of3FramesWhileMovingFast % 3 && this.editor.inputs.pointerVelocity.len() > 0.5) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.updateDraggingShapes(editor.inputs.currentPagePoint, cb)\n\t\t\t},\n\t\t\tmovingShapes.length > 10 ? SLOW_POINTER_LAG_DURATION : FAST_POINTER_LAG_DURATION\n\t\t)\n\t}\n\n\tdropShapes(shapes: TLShape[]) {\n\t\tconst { editor } = this\n\t\tthis.updateDraggingShapes(editor.inputs.currentPagePoint)\n\n\t\tconst draggingOverShape = editor.getDraggingOverShape(editor.inputs.currentPagePoint, shapes)\n\n\t\tif (draggingOverShape) {\n\t\t\tconst util = editor.getShapeUtil(draggingOverShape)\n\t\t\tutil.onDropShapesOver?.(draggingOverShape, shapes, {\n\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t})\n\t\t}\n\n\t\tthis.dispose()\n\t}\n\n\tclear() {\n\t\tclearInterval(this.intervalTimerId)\n\t\tthis.intervalTimerId = -1\n\n\t\tthis.initialParentIds.clear()\n\t\tthis.initialIndices.clear()\n\t\tthis.shapesToActuallyMove = []\n\t\tthis.initialDraggingOverShape = undefined\n\t\tthis.prevDraggingOverShape = undefined\n\t\tthis.editor.setHintingShapes([])\n\t}\n\n\t@bind\n\tdispose() {\n\t\tthis.clear()\n\t}\n\n\tprivate updateDraggingShapes(point: Vec, cb?: () => void): void {\n\t\tconst { editor } = this\n\n\t\t// get fresh moving shapes\n\t\tconst draggingShapes = compact(this.shapesToActuallyMove.map((s) => editor.getShape(s)))\n\n\t\tif (!draggingShapes.length) return\n\n\t\t// This is the shape under the pointer that can handle at least one of the dragging shapes\n\t\tconst nextDraggingOverShape = editor.getDraggingOverShape(point, this.shapesToActuallyMove)\n\n\t\tconst cursorDidMove = !this.prevPagePoint.equals(editor.inputs.currentPagePoint)\n\t\tthis.prevPagePoint.setTo(editor.inputs.currentPagePoint)\n\n\t\teditor.run(() => {\n\t\t\tif (this.prevDraggingOverShape?.id === nextDraggingOverShape?.id) {\n\t\t\t\tif (\n\t\t\t\t\tcursorDidMove &&\n\t\t\t\t\tnextDraggingOverShape &&\n\t\t\t\t\tisShapeId(nextDraggingOverShape.id) &&\n\t\t\t\t\t!editor.inputs.previousPagePoint.equals(editor.inputs.currentPagePoint)\n\t\t\t\t) {\n\t\t\t\t\t// If the cursor moved, call onDragShapesOver for the previous dragging over shape\n\t\t\t\t\tconst util = editor.getShapeUtil(nextDraggingOverShape)\n\t\t\t\t\tutil.onDragShapesOver?.(nextDraggingOverShape, draggingShapes, {\n\t\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (this.prevDraggingOverShape) {\n\t\t\t\tconst util = editor.getShapeUtil(this.prevDraggingOverShape)\n\t\t\t\tutil.onDragShapesOut?.(this.editor.getShape(this.prevDraggingOverShape)!, draggingShapes, {\n\t\t\t\t\tnextDraggingOverShapeId: nextDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (nextDraggingOverShape) {\n\t\t\t\tconst util = editor.getShapeUtil(nextDraggingOverShape)\n\t\t\t\tutil.onDragShapesIn?.(nextDraggingOverShape, draggingShapes, {\n\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\tprevDraggingOverShapeId: this.prevDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t})\n\t\t\t\teditor.setHintingShapes([nextDraggingOverShape.id])\n\t\t\t} else if (this.prevDraggingOverShape) {\n\t\t\t\teditor.setHintingShapes([])\n\t\t\t}\n\n\t\t\t// This is the reparenting logic\n\t\t\tcb?.()\n\t\t})\n\n\t\tthis.prevDraggingOverShape = nextDraggingOverShape\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWO;AAXP;AAaA,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAyHjC,gBAAC;AAtHK,MAAM,mBAAmB;AAAA,EAC/B,YAAmB,QAAgB;AAAhB;AADb;AAKN,gDAAkC,CAAC;AACnC,+CAAsB,oBAAI,IAAe;AAEzC,2CAAkB,oBAAI,IAA0B;AAChD,4CAAmB,oBAAI,IAA2B;AAClD,0CAAiB,oBAAI,IAAyB;AAE9C;AACA;AACA,yCAAgB,IAAI,kBAAI;AAExB,2CAAkB;AAdjB,WAAO,YAAY,IAAI,KAAK,OAAO;AAAA,EACpC;AAAA,EAeA,oBAAoB,cAAyB,OAAY,IAAgB;AACxE,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,KAAK,oBAAoB,GAAI;AAEjC,UAAM,uBAAuB,IAAI,IAAI,YAAY;AACjD,UAAM,eAAe,oBAAI,IAAkB;AAE3C,eAAW,SAAS,sBAAsB;AACzC,YAAM,SAAS,OAAO,eAAe,KAAK;AAC1C,UAAI,UAAU,OAAO,cAA4B,QAAQ,OAAO,GAAG;AAClE,YAAI,CAAC,aAAa,IAAI,MAAM,GAAG;AAC9B,uBAAa,IAAI,MAAM;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAGA,eAAW,eAAe,cAAc;AACvC,YAAM,eAAW;AAAA,QAChB,OAAO,2BAA2B,WAAW,EAAE,IAAI,CAAC,OAAO,OAAO,SAAS,EAAE,CAAC;AAAA,MAC/E;AACA,2BAAqB,IAAI,WAAW;AACpC,iBAAW,SAAS,U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gBAAgB,KAAK;AAAA,UACtB,CAAC;AAAA,QACF;AACA;AAAA,MACD;AAEA,UAAI,KAAK,uBAAuB;AAC/B,cAAM,OAAO,OAAO,aAAa,KAAK,qBAAqB;AAC3D,aAAK,kBAAkB,KAAK,OAAO,SAAS,KAAK,qBAAqB,GAAI,gBAAgB;AAAA,UACzF,yBAAyB,uBAAuB,MAAM;AAAA,UACtD,4BAA4B,KAAK,0BAA0B,MAAM;AAAA,UACjE,kBAAkB,KAAK;AAAA,UACvB,gBAAgB,KAAK;AAAA,QACtB,CAAC;AAAA,MACF;AAEA,UAAI,uBAAuB;AAC1B,cAAM,OAAO,OAAO,aAAa,qBAAqB;AACtD,aAAK,iBAAiB,uBAAuB,gBAAgB;AAAA,UAC5D,4BAA4B,KAAK,0BAA0B,MAAM;AAAA,UACjE,yBAAyB,KAAK,uBAAuB,MAAM;AAAA,UAC3D,kBAAkB,KAAK;AAAA,UACvB,gBAAgB,KAAK;AAAA,QACtB,CAAC;AACD,eAAO,iBAAiB,CAAC,sBAAsB,EAAE,CAAC;AAAA,MACnD,WAAW,KAAK,uBAAuB;AACtC,eAAO,iBAAiB,CAAC,CAAC;AAAA,MAC3B;AAGA,WAAK;AAAA,IACN,CAAC;AAED,SAAK,wBAAwB;AAAA,EAC9B;AACD;AAzLO;AAuHN,uCADA,cAtHY;AAAN,2BAAM;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tIndexKey,\n\tTLGroupShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tVec,\n\tbind,\n\tcompact,\n\tisShapeId,\n} from '@tldraw/editor'\n\nconst SLOW_POINTER_LAG_DURATION = 320\nconst FAST_POINTER_LAG_DURATION = 60\n\n/** @public */\nexport class DragAndDropManager {\n\tconstructor(public editor: Editor) {\n\t\teditor.disposables.add(this.dispose)\n\t}\n\n\tshapesToActuallyMove: TLShape[] = []\n\tdraggedOverShapeIds = new Set<TLShapeId>()\n\n\tinitialGroupIds = new Map<TLShapeId, TLShapeId>()\n\tinitialParentIds = new Map<TLShapeId, TLParentId>()\n\tinitialIndices = new Map<TLShapeId, IndexKey>()\n\n\tinitialDraggingOverShape?: TLShape\n\tprevDraggingOverShape?: TLShape\n\tprevPagePoint = new Vec()\n\n\tintervalTimerId = -1\n\n\tstartDraggingShapes(movingShapes: TLShape[], point: Vec, cb: () => void) {\n\t\tconst { editor } = this\n\n\t\t// Only start dragging if we're not already dragging\n\t\tif (this.intervalTimerId !== -1) return\n\n\t\tconst shapesToActuallyMove = new Set(movingShapes)\n\t\tconst movingGroups = new Set<TLGroupShape>()\n\n\t\tfor (const shape of shapesToActuallyMove) {\n\t\t\tconst parent = editor.getShapeParent(shape)\n\t\t\tif (parent && editor.isShapeOfType(parent, 'group')) {\n\t\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\t\tmovingGroups.add(parent)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If all of a group's children are moving, then move the group instead\n\t\tfor (const movingGroup of movingGroups) {\n\t\t\tconst children = compact(\n\t\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t\t)\n\t\t\tshapesToActuallyMove.add(movingGroup)\n\t\t\tfor (const child of children) {\n\t\t\t\tshapesToActuallyMove.delete(child)\n\t\t\t}\n\t\t}\n\n\t\tthis.initialParentIds.clear()\n\t\tfor (const shape of shapesToActuallyMove) {\n\t\t\tconst parent = editor.getShapeParent(shape)\n\t\t\tif (parent) {\n\t\t\t\tthis.initialParentIds.set(shape.id, parent.id)\n\t\t\t}\n\t\t\tthis.initialIndices.set(shape.id, shape.index)\n\n\t\t\tconst group = editor.findShapeAncestor(shape, (s) => editor.isShapeOfType(s, 'group'))\n\t\t\tif (group) {\n\t\t\t\tthis.initialGroupIds.set(shape.id, group.id)\n\t\t\t}\n\t\t}\n\n\t\tconst allShapes = editor.getCurrentPageShapesSorted()\n\t\tthis.shapesToActuallyMove = Array.from(shapesToActuallyMove)\n\t\t\t.filter((s) => !s.isLocked)\n\t\t\t.sort((a, b) => allShapes.indexOf(a) - allShapes.indexOf(b))\n\n\t\tthis.initialDraggingOverShape = editor.getDraggingOverShape(point, this.shapesToActuallyMove)\n\t\tthis.prevDraggingOverShape = this.initialDraggingOverShape\n\n\t\t// run once on first frame\n\t\tthis.updateDraggingShapes(point, cb)\n\n\t\t// then once on an interval, skipping frames if moving quickly\n\t\tlet skip2of3FramesWhileMovingFast = 0\n\t\tthis.intervalTimerId = this.editor.timers.setInterval(\n\t\t\t() => {\n\t\t\t\tskip2of3FramesWhileMovingFast++\n\t\t\t\tif (skip2of3FramesWhileMovingFast % 3 && this.editor.inputs.pointerVelocity.len() > 0.5) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.updateDraggingShapes(editor.inputs.currentPagePoint, cb)\n\t\t\t},\n\t\t\tmovingShapes.length > 10 ? SLOW_POINTER_LAG_DURATION : FAST_POINTER_LAG_DURATION\n\t\t)\n\t}\n\n\tdropShapes(shapes: TLShape[]) {\n\t\tconst { editor } = this\n\t\tthis.updateDraggingShapes(editor.inputs.currentPagePoint)\n\n\t\tconst draggingOverShape = editor.getDraggingOverShape(editor.inputs.currentPagePoint, shapes)\n\n\t\tif (draggingOverShape) {\n\t\t\tconst util = editor.getShapeUtil(draggingOverShape)\n\t\t\tutil.onDropShapesOver?.(draggingOverShape, shapes, {\n\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t})\n\t\t}\n\n\t\tthis.dispose()\n\t}\n\n\tclear() {\n\t\tclearInterval(this.intervalTimerId)\n\t\tthis.intervalTimerId = -1\n\n\t\tthis.initialParentIds.clear()\n\t\tthis.initialIndices.clear()\n\t\tthis.shapesToActuallyMove = []\n\t\tthis.initialDraggingOverShape = undefined\n\t\tthis.prevDraggingOverShape = undefined\n\t\tthis.editor.setHintingShapes([])\n\t}\n\n\t@bind\n\tdispose() {\n\t\tthis.clear()\n\t}\n\n\tprivate updateDraggingShapes(point: Vec, cb?: () => void): void {\n\t\tconst { editor } = this\n\n\t\t// get fresh moving shapes\n\t\tconst draggingShapes = compact(this.shapesToActuallyMove.map((s) => editor.getShape(s)))\n\n\t\tif (!draggingShapes.length) return\n\n\t\t// This is the shape under the pointer that can handle at least one of the dragging shapes\n\t\tconst nextDraggingOverShape = editor.getDraggingOverShape(point, this.shapesToActuallyMove)\n\n\t\tconst cursorDidMove = !this.prevPagePoint.equals(editor.inputs.currentPagePoint)\n\t\tthis.prevPagePoint.setTo(editor.inputs.currentPagePoint)\n\n\t\teditor.run(() => {\n\t\t\tif (this.prevDraggingOverShape?.id === nextDraggingOverShape?.id) {\n\t\t\t\tif (\n\t\t\t\t\tcursorDidMove &&\n\t\t\t\t\tnextDraggingOverShape &&\n\t\t\t\t\tisShapeId(nextDraggingOverShape.id) &&\n\t\t\t\t\t!editor.inputs.previousPagePoint.equals(editor.inputs.currentPagePoint)\n\t\t\t\t) {\n\t\t\t\t\t// If the cursor moved, call onDragShapesOver for the previous dragging over shape\n\t\t\t\t\tconst util = editor.getShapeUtil(nextDraggingOverShape)\n\t\t\t\t\tutil.onDragShapesOver?.(nextDraggingOverShape, draggingShapes, {\n\t\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (this.prevDraggingOverShape) {\n\t\t\t\tconst util = editor.getShapeUtil(this.prevDraggingOverShape)\n\t\t\t\tutil.onDragShapesOut?.(this.editor.getShape(this.prevDraggingOverShape)!, draggingShapes, {\n\t\t\t\t\tnextDraggingOverShapeId: nextDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (nextDraggingOverShape) {\n\t\t\t\tconst util = editor.getShapeUtil(nextDraggingOverShape)\n\t\t\t\tutil.onDragShapesIn?.(nextDraggingOverShape, draggingShapes, {\n\t\t\t\t\tinitialDraggingOverShapeId: this.initialDraggingOverShape?.id ?? null,\n\t\t\t\t\tprevDraggingOverShapeId: this.prevDraggingOverShape?.id ?? null,\n\t\t\t\t\tinitialParentIds: this.initialParentIds,\n\t\t\t\t\tinitialIndices: this.initialIndices,\n\t\t\t\t})\n\t\t\t\teditor.setHintingShapes([nextDraggingOverShape.id])\n\t\t\t} else if (this.prevDraggingOverShape) {\n\t\t\t\teditor.setHintingShapes([])\n\t\t\t}\n\n\t\t\t// This is the reparenting logic\n\t\t\tcb?.()\n\t\t})\n\n\t\tthis.prevDraggingOverShape = nextDraggingOverShape\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWO;AAXP;AAaA,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAuHjC,gBAAC;AApHK,MAAM,mBAAmB;AAAA,EAC/B,YAAmB,QAAgB;AAAhB;AADb;AAKN,gDAAkC,CAAC;AACnC,+CAAsB,oBAAI,IAAe;AAEzC,2CAAkB,oBAAI,IAA0B;AAChD,4CAAmB,oBAAI,IAA2B;AAClD,0CAAiB,oBAAI,IAAyB;AAE9C;AACA;AACA,yCAAgB,IAAI,kBAAI;AAExB,2CAAkB;AAdjB,WAAO,YAAY,IAAI,KAAK,OAAO;AAAA,EACpC;AAAA,EAeA,oBAAoB,cAAyB,OAAY,IAAgB;AACxE,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,KAAK,oBAAoB,GAAI;AAEjC,UAAM,uBAAuB,IAAI,IAA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N,uCADA,cApHY;AAAN,2BAAM;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/Brushing.ts"],
4
- "sourcesContent": ["import {\n\tBox,\n\tMat,\n\tStateNode,\n\tTLCancelEventInfo,\n\tTLFrameShape,\n\tTLGroupShape,\n\tTLKeyboardEventInfo,\n\tTLPageId,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLShapeId,\n\tTLTickEventInfo,\n\tVec,\n\tpointInPolygon,\n\tpolygonsIntersect,\n\treact,\n} from '@tldraw/editor'\n\nexport class Brushing extends StateNode {\n\tstatic override id = 'brushing'\n\n\tinfo = {} as TLPointerEventInfo & { target: 'canvas' }\n\n\tinitialSelectedShapeIds: TLShapeId[] = []\n\texcludedShapeIds = new Set<TLShapeId>()\n\tisWrapMode = false\n\n\tviewportDidChange = false\n\tcleanupViewportChangeReactor() {\n\t\tvoid null\n\t} // cleanup function for the viewport reactor\n\n\toverride onEnter(info: TLPointerEventInfo & { target: 'canvas' }) {\n\t\tconst { editor } = this\n\t\tconst { altKey } = editor.inputs\n\n\t\tthis.isWrapMode = editor.user.getIsWrapMode()\n\n\t\tthis.viewportDidChange = false\n\n\t\tlet isInitialCheck = true\n\n\t\tthis.cleanupViewportChangeReactor = react('viewport change while brushing', () => {\n\t\t\teditor.getViewportPageBounds() // capture the viewport change\n\t\t\tif (!isInitialCheck && !this.viewportDidChange) {\n\t\t\t\tthis.viewportDidChange = true\n\t\t\t}\n\t\t})\n\n\t\tif (altKey) {\n\t\t\tthis.parent.transition('scribble_brushing', info)\n\t\t\treturn\n\t\t}\n\n\t\tthis.excludedShapeIds = new Set(\n\t\t\teditor\n\t\t\t\t.getCurrentPageShapes()\n\t\t\t\t.filter(\n\t\t\t\t\t(shape) =>\n\t\t\t\t\t\teditor.isShapeOfType<TLGroupShape>(shape, 'group') ||\n\t\t\t\t\t\teditor.isShapeOrAncestorLocked(shape)\n\t\t\t\t)\n\t\t\t\t.map((shape) => shape.id)\n\t\t)\n\n\t\tthis.info = info\n\t\tthis.initialSelectedShapeIds = editor.getSelectedShapeIds().slice()\n\t\tthis.hitTestShapes()\n\t\tisInitialCheck = false\n\t}\n\n\toverride onExit() {\n\t\tthis.initialSelectedShapeIds = []\n\t\tthis.editor.updateInstanceState({ brush: null })\n\n\t\tthis.cleanupViewportChangeReactor()\n\t}\n\n\toverride onTick({ elapsed }: TLTickEventInfo) {\n\t\tconst { editor } = this\n\t\teditor.edgeScrollManager.updateEdgeScrolling(elapsed)\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.hitTestShapes()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel(info: TLCancelEventInfo) {\n\t\tthis.editor.setSelectedShapes(this.initialSelectedShapeIds)\n\t\tthis.parent.transition('idle', info)\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tif (this.editor.inputs.altKey) {\n\t\t\tthis.parent.transition('scribble_brushing', info)\n\t\t} else {\n\t\t\tthis.hitTestShapes()\n\t\t}\n\t}\n\n\toverride onKeyUp() {\n\t\tthis.hitTestShapes()\n\t}\n\n\tprivate complete() {\n\t\tthis.hitTestShapes()\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate hitTestShapes() {\n\t\tconst { editor, excludedShapeIds, isWrapMode } = this\n\t\tconst {\n\t\t\tinputs: { originPagePoint, currentPagePoint, shiftKey, ctrlKey },\n\t\t} = editor\n\n\t\t// We'll be collecting shape ids of selected shapes; if we're holding shift key, we start from our initial shapes\n\t\tconst results = new Set(shiftKey ? this.initialSelectedShapeIds : [])\n\n\t\t// In wrap mode, we need to completely enclose a shape to select it\n\t\tconst isWrapping = isWrapMode ? !ctrlKey : ctrlKey\n\n\t\t// Set the brush to contain the current and origin points\n\t\tconst brush = Box.FromPoints([originPagePoint, currentPagePoint])\n\n\t\t// We'll be testing the corners of the brush against the shapes\n\t\tconst { corners } = brush\n\n\t\tlet A: Vec,\n\t\t\tB: Vec,\n\t\t\tshape: TLShape,\n\t\t\tpageBounds: Box | undefined,\n\t\t\tpageTransform: Mat | undefined,\n\t\t\tlocalCorners: Vec[]\n\n\t\t// Some notes on optimization. We could easily cache all of the shape positions at\n\t\t// the start of the interaction and then do very fast checks against them, but that\n\t\t// would mean changes introduced by other collaborators wouldn't be reflected\u2014a user\n\t\t// could select a shape by selecting where it _used_ to be.\n\n\t\t// We still want to avoid hit tests as much as possible, however, so we test only the\n\t\t// shapes that are on screen UNLESS: the user has scrolled their viewpor; or the user\n\t\t// is dragging outside of the screen (e.g. in a window). In those cases, we need to\n\t\t// test all shapes.\n\n\t\t// On a page with ~5000 shapes, on-screen hit tests are about 2x faster than\n\t\t// testing all shapes.\n\n\t\tconst brushBoxIsInsideViewport = editor.getViewportPageBounds().contains(brush)\n\t\tconst shapesToHitTest =\n\t\t\tbrushBoxIsInsideViewport && !this.viewportDidChange\n\t\t\t\t? editor.getCurrentPageRenderingShapesSorted()\n\t\t\t\t: editor.getCurrentPageShapesSorted()\n\n\t\tconst currentPageId = editor.getCurrentPageId()\n\n\t\ttestAllShapes: for (let i = 0, n = shapesToHitTest.length; i < n; i++) {\n\t\t\tshape = shapesToHitTest[i]\n\t\t\tif (excludedShapeIds.has(shape.id) || results.has(shape.id)) continue testAllShapes\n\n\t\t\tpageBounds = editor.getShapePageBounds(shape)\n\t\t\tif (!pageBounds) continue testAllShapes\n\n\t\t\t// If the brush fully wraps a shape, it's almost certainly a hit\n\t\t\tif (brush.contains(pageBounds)) {\n\t\t\t\tthis.handleHit(shape, currentPagePoint, currentPageId, results, corners)\n\t\t\t\tcontinue testAllShapes\n\t\t\t}\n\n\t\t\t// If we're in wrap mode and the brush did not fully encloses the shape, it's a miss\n\t\t\t// We also skip frames unless we've completely selected the frame.\n\t\t\tif (isWrapping || editor.isShapeOfType<TLFrameShape>(shape, 'frame')) {\n\t\t\t\tcontinue testAllShapes\n\t\t\t}\n\n\t\t\t// If the brush collides the page bounds, then do hit tests against\n\t\t\t// each of the brush's four sides.\n\t\t\tif (brush.collides(pageBounds)) {\n\t\t\t\t// Shapes expect to hit test line segments in their own coordinate system,\n\t\t\t\t// so we first need to get the brush corners in the shape's local space.\n\t\t\t\tpageTransform = editor.getShapePageTransform(shape)\n\t\t\t\tif (!pageTransform) continue testAllShapes\n\t\t\t\tlocalCorners = pageTransform.clone().invert().applyToPoints(corners)\n\t\t\t\t// See if any of the edges intersect the shape's geometry\n\t\t\t\tconst geometry = editor.getShapeGeometry(shape)\n\t\t\t\thitTestBrushEdges: for (let i = 0; i < 4; i++) {\n\t\t\t\t\tA = localCorners[i]\n\t\t\t\t\tB = localCorners[(i + 1) % 4]\n\t\t\t\t\tif (geometry.hitTestLineSegment(A, B, 0)) {\n\t\t\t\t\t\tthis.handleHit(shape, currentPagePoint, currentPageId, results, corners)\n\t\t\t\t\t\tbreak hitTestBrushEdges\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst currentBrush = editor.getInstanceState().brush\n\t\tif (!currentBrush || !brush.equals(currentBrush)) {\n\t\t\teditor.updateInstanceState({ brush: { ...brush.toJson() } })\n\t\t}\n\n\t\tconst current = editor.getSelectedShapeIds()\n\t\tif (current.length !== results.size || current.some((id) => !results.has(id))) {\n\t\t\teditor.setSelectedShapes(Array.from(results))\n\t\t}\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.editor.updateInstanceState({ brush: null })\n\t}\n\n\tprivate handleHit(\n\t\tshape: TLShape,\n\t\tcurrentPagePoint: Vec,\n\t\tcurrentPageId: TLPageId,\n\t\tresults: Set<TLShapeId>,\n\t\tcorners: Vec[]\n\t) {\n\t\tif (shape.parentId === currentPageId) {\n\t\t\tresults.add(shape.id)\n\t\t\treturn\n\t\t}\n\n\t\t// Find the outermost selectable shape, check to see if it has a\n\t\t// page mask; and if so, check to see if the brush intersects it\n\t\tconst selectedShape = this.editor.getOutermostSelectableShape(shape)\n\t\tconst pageMask = this.editor.getShapeMask(selectedShape.id)\n\t\tif (\n\t\t\tpageMask &&\n\t\t\t!polygonsIntersect(pageMask, corners) &&\n\t\t\t!pointInPolygon(currentPagePoint, pageMask)\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tresults.add(selectedShape.id)\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAiBO;AAEA,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB,OAAO,CAAC;AAAA,EAER,0BAAuC,CAAC;AAAA,EACxC,mBAAmB,oBAAI,IAAe;AAAA,EACtC,aAAa;AAAA,EAEb,oBAAoB;AAAA,EACpB,+BAA+B;AAAA,EAE/B;AAAA;AAAA,EAES,QAAQ,MAAiD;AACjE,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,EAAE,OAAO,IAAI,OAAO;AAE1B,SAAK,aAAa,OAAO,KAAK,cAAc;AAE5C,SAAK,oBAAoB;AAEzB,QAAI,iBAAiB;AAErB,SAAK,mCAA+B,qBAAM,kCAAkC,MAAM;AACjF,aAAO,sBAAsB;AAC7B,UAAI,CAAC,kBAAkB,CAAC,KAAK,mBAAmB;AAC/C,aAAK,oBAAoB;AAAA,MAC1B;AAAA,IACD,CAAC;AAED,QAAI,QAAQ;AACX,WAAK,OAAO,WAAW,qBAAqB,IAAI;AAChD;AAAA,IACD;AAEA,SAAK,mBAAmB,IAAI;AAAA,MAC3B,OACE,qBAAqB,EACrB;AAAA,QACA,CAAC,UACA,OAAO,cAA4B,OAAO,OAAO,KACjD,OAAO,wBAAwB,KAAK;AAAA,MACtC,EACC,IAAI,CAAC,UAAU,MAAM,EAAE;AAAA,IAC1B;AAEA,SAAK,OAAO;AACZ,SAAK,0BAA0B,OAAO,oBAAoB,EAAE,MAAM;AAClE,SAAK,cAAc;AACnB,qBAAiB;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,UAAU,OAAO,oBAAoB;AAC3C,QAAI,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,KAAK,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,GAAG;AAC9E,aAAO,kBAAkB,MAAM,KAAK,OAAO,CAAC;AAAA,IAC7C;AAAA,EACD;AAAA,EAES,cAAc;AACtB,SAAK,OAAO,oBAAoB,EAAE,OAAO,KAAK,CAAC;AAAA,EAChD;AAAA,EAEQ,UACP,OACA,kBACA,eACA,SACA,SACC;AACD,QAAI,MAAM,aAAa,eAAe;AACrC,cAAQ,IAAI,MAAM,EAAE;AACpB;AAAA,IACD;AAIA,UAAM,gBAAgB,KAAK,OAAO,4BAA4B,KAAK;AACnE,UAAM,WAAW,KAAK,OAAO,aAAa,cAAc,EAAE;AAC1D,QACC,YACA,KAAC,iCAAkB,UAAU,OAAO,KACpC,KAAC,8BAAe,kBAAkB,QAAQ,GACzC;AACD;AAAA,IACD;AACA,YAAQ,IAAI,cAAc,EAAE;AAAA,EAC7B;AACD;",
4
+ "sourcesContent": ["import {\n\tBox,\n\tMat,\n\tStateNode,\n\tTLCancelEventInfo,\n\tTLKeyboardEventInfo,\n\tTLPageId,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLShapeId,\n\tTLTickEventInfo,\n\tVec,\n\tpointInPolygon,\n\tpolygonsIntersect,\n\treact,\n} from '@tldraw/editor'\n\nexport class Brushing extends StateNode {\n\tstatic override id = 'brushing'\n\n\tinfo = {} as TLPointerEventInfo & { target: 'canvas' }\n\n\tinitialSelectedShapeIds: TLShapeId[] = []\n\texcludedShapeIds = new Set<TLShapeId>()\n\tisWrapMode = false\n\n\tviewportDidChange = false\n\tcleanupViewportChangeReactor() {\n\t\tvoid null\n\t} // cleanup function for the viewport reactor\n\n\toverride onEnter(info: TLPointerEventInfo & { target: 'canvas' }) {\n\t\tconst { editor } = this\n\t\tconst { altKey } = editor.inputs\n\n\t\tthis.isWrapMode = editor.user.getIsWrapMode()\n\n\t\tthis.viewportDidChange = false\n\n\t\tlet isInitialCheck = true\n\n\t\tthis.cleanupViewportChangeReactor = react('viewport change while brushing', () => {\n\t\t\teditor.getViewportPageBounds() // capture the viewport change\n\t\t\tif (!isInitialCheck && !this.viewportDidChange) {\n\t\t\t\tthis.viewportDidChange = true\n\t\t\t}\n\t\t})\n\n\t\tif (altKey) {\n\t\t\tthis.parent.transition('scribble_brushing', info)\n\t\t\treturn\n\t\t}\n\n\t\tthis.excludedShapeIds = new Set(\n\t\t\teditor\n\t\t\t\t.getCurrentPageShapes()\n\t\t\t\t.filter(\n\t\t\t\t\t(shape) => editor.isShapeOfType(shape, 'group') || editor.isShapeOrAncestorLocked(shape)\n\t\t\t\t)\n\t\t\t\t.map((shape) => shape.id)\n\t\t)\n\n\t\tthis.info = info\n\t\tthis.initialSelectedShapeIds = editor.getSelectedShapeIds().slice()\n\t\tthis.hitTestShapes()\n\t\tisInitialCheck = false\n\t}\n\n\toverride onExit() {\n\t\tthis.initialSelectedShapeIds = []\n\t\tthis.editor.updateInstanceState({ brush: null })\n\n\t\tthis.cleanupViewportChangeReactor()\n\t}\n\n\toverride onTick({ elapsed }: TLTickEventInfo) {\n\t\tconst { editor } = this\n\t\teditor.edgeScrollManager.updateEdgeScrolling(elapsed)\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.hitTestShapes()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel(info: TLCancelEventInfo) {\n\t\tthis.editor.setSelectedShapes(this.initialSelectedShapeIds)\n\t\tthis.parent.transition('idle', info)\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tif (this.editor.inputs.altKey) {\n\t\t\tthis.parent.transition('scribble_brushing', info)\n\t\t} else {\n\t\t\tthis.hitTestShapes()\n\t\t}\n\t}\n\n\toverride onKeyUp() {\n\t\tthis.hitTestShapes()\n\t}\n\n\tprivate complete() {\n\t\tthis.hitTestShapes()\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate hitTestShapes() {\n\t\tconst { editor, excludedShapeIds, isWrapMode } = this\n\t\tconst {\n\t\t\tinputs: { originPagePoint, currentPagePoint, shiftKey, ctrlKey },\n\t\t} = editor\n\n\t\t// We'll be collecting shape ids of selected shapes; if we're holding shift key, we start from our initial shapes\n\t\tconst results = new Set(shiftKey ? this.initialSelectedShapeIds : [])\n\n\t\t// In wrap mode, we need to completely enclose a shape to select it\n\t\tconst isWrapping = isWrapMode ? !ctrlKey : ctrlKey\n\n\t\t// Set the brush to contain the current and origin points\n\t\tconst brush = Box.FromPoints([originPagePoint, currentPagePoint])\n\n\t\t// We'll be testing the corners of the brush against the shapes\n\t\tconst { corners } = brush\n\n\t\tlet A: Vec,\n\t\t\tB: Vec,\n\t\t\tshape: TLShape,\n\t\t\tpageBounds: Box | undefined,\n\t\t\tpageTransform: Mat | undefined,\n\t\t\tlocalCorners: Vec[]\n\n\t\t// Some notes on optimization. We could easily cache all of the shape positions at\n\t\t// the start of the interaction and then do very fast checks against them, but that\n\t\t// would mean changes introduced by other collaborators wouldn't be reflected\u2014a user\n\t\t// could select a shape by selecting where it _used_ to be.\n\n\t\t// We still want to avoid hit tests as much as possible, however, so we test only the\n\t\t// shapes that are on screen UNLESS: the user has scrolled their viewpor; or the user\n\t\t// is dragging outside of the screen (e.g. in a window). In those cases, we need to\n\t\t// test all shapes.\n\n\t\t// On a page with ~5000 shapes, on-screen hit tests are about 2x faster than\n\t\t// testing all shapes.\n\n\t\tconst brushBoxIsInsideViewport = editor.getViewportPageBounds().contains(brush)\n\t\tconst shapesToHitTest =\n\t\t\tbrushBoxIsInsideViewport && !this.viewportDidChange\n\t\t\t\t? editor.getCurrentPageRenderingShapesSorted()\n\t\t\t\t: editor.getCurrentPageShapesSorted()\n\n\t\tconst currentPageId = editor.getCurrentPageId()\n\n\t\ttestAllShapes: for (let i = 0, n = shapesToHitTest.length; i < n; i++) {\n\t\t\tshape = shapesToHitTest[i]\n\t\t\tif (excludedShapeIds.has(shape.id) || results.has(shape.id)) continue testAllShapes\n\n\t\t\tpageBounds = editor.getShapePageBounds(shape)\n\t\t\tif (!pageBounds) continue testAllShapes\n\n\t\t\t// If the brush fully wraps a shape, it's almost certainly a hit\n\t\t\tif (brush.contains(pageBounds)) {\n\t\t\t\tthis.handleHit(shape, currentPagePoint, currentPageId, results, corners)\n\t\t\t\tcontinue testAllShapes\n\t\t\t}\n\n\t\t\t// If we're in wrap mode and the brush did not fully encloses the shape, it's a miss\n\t\t\t// We also skip frames unless we've completely selected the frame.\n\t\t\tif (isWrapping || editor.isShapeOfType(shape, 'frame')) {\n\t\t\t\tcontinue testAllShapes\n\t\t\t}\n\n\t\t\t// If the brush collides the page bounds, then do hit tests against\n\t\t\t// each of the brush's four sides.\n\t\t\tif (brush.collides(pageBounds)) {\n\t\t\t\t// Shapes expect to hit test line segments in their own coordinate system,\n\t\t\t\t// so we first need to get the brush corners in the shape's local space.\n\t\t\t\tpageTransform = editor.getShapePageTransform(shape)\n\t\t\t\tif (!pageTransform) continue testAllShapes\n\t\t\t\tlocalCorners = pageTransform.clone().invert().applyToPoints(corners)\n\t\t\t\t// See if any of the edges intersect the shape's geometry\n\t\t\t\tconst geometry = editor.getShapeGeometry(shape)\n\t\t\t\thitTestBrushEdges: for (let i = 0; i < 4; i++) {\n\t\t\t\t\tA = localCorners[i]\n\t\t\t\t\tB = localCorners[(i + 1) % 4]\n\t\t\t\t\tif (geometry.hitTestLineSegment(A, B, 0)) {\n\t\t\t\t\t\tthis.handleHit(shape, currentPagePoint, currentPageId, results, corners)\n\t\t\t\t\t\tbreak hitTestBrushEdges\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst currentBrush = editor.getInstanceState().brush\n\t\tif (!currentBrush || !brush.equals(currentBrush)) {\n\t\t\teditor.updateInstanceState({ brush: { ...brush.toJson() } })\n\t\t}\n\n\t\tconst current = editor.getSelectedShapeIds()\n\t\tif (current.length !== results.size || current.some((id) => !results.has(id))) {\n\t\t\teditor.setSelectedShapes(Array.from(results))\n\t\t}\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.editor.updateInstanceState({ brush: null })\n\t}\n\n\tprivate handleHit(\n\t\tshape: TLShape,\n\t\tcurrentPagePoint: Vec,\n\t\tcurrentPageId: TLPageId,\n\t\tresults: Set<TLShapeId>,\n\t\tcorners: Vec[]\n\t) {\n\t\tif (shape.parentId === currentPageId) {\n\t\t\tresults.add(shape.id)\n\t\t\treturn\n\t\t}\n\n\t\t// Find the outermost selectable shape, check to see if it has a\n\t\t// page mask; and if so, check to see if the brush intersects it\n\t\tconst selectedShape = this.editor.getOutermostSelectableShape(shape)\n\t\tconst pageMask = this.editor.getShapeMask(selectedShape.id)\n\t\tif (\n\t\t\tpageMask &&\n\t\t\t!polygonsIntersect(pageMask, corners) &&\n\t\t\t!pointInPolygon(currentPagePoint, pageMask)\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tresults.add(selectedShape.id)\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAeO;AAEA,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB,OAAO,CAAC;AAAA,EAER,0BAAuC,CAAC;AAAA,EACxC,mBAAmB,oBAAI,IAAe;AAAA,EACtC,aAAa;AAAA,EAEb,oBAAoB;AAAA,EACpB,+BAA+B;AAAA,EAE/B;AAAA;AAAA,EAES,QAAQ,MAAiD;AACjE,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,EAAE,OAAO,IAAI,OAAO;AAE1B,SAAK,aAAa,OAAO,KAAK,cAAc;AAE5C,SAAK,oBAAoB;AAEzB,QAAI,iBAAiB;AAErB,SAAK,mCAA+B,qBAAM,kCAAkC,MAAM;AACjF,aAAO,sBAAsB;AAC7B,UAAI,CAAC,kBAAkB,CAAC,KAAK,mBAAmB;AAC/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I,aAAaA,EAAC;AAClB,cAAI,cAAcA,KAAI,KAAK,CAAC;AAC5B,cAAI,SAAS,mBAAmB,GAAG,GAAG,CAAC,GAAG;AACzC,iBAAK,UAAU,OAAO,kBAAkB,eAAe,SAAS,OAAO;AACvE,kBAAM;AAAA,UACP;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,eAAe,OAAO,iBAAiB,EAAE;AAC/C,QAAI,CAAC,gBAAgB,CAAC,MAAM,OAAO,YAAY,GAAG;AACjD,aAAO,oBAAoB,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,EAAE,EAAE,CAAC;AAAA,IAC5D;AAEA,UAAM,UAAU,OAAO,oBAAoB;AAC3C,QAAI,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,KAAK,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,GAAG;AAC9E,aAAO,kBAAkB,MAAM,KAAK,OAAO,CAAC;AAAA,IAC7C;AAAA,EACD;AAAA,EAES,cAAc;AACtB,SAAK,OAAO,oBAAoB,EAAE,OAAO,KAAK,CAAC;AAAA,EAChD;AAAA,EAEQ,UACP,OACA,kBACA,eACA,SACA,SACC;AACD,QAAI,MAAM,aAAa,eAAe;AACrC,cAAQ,IAAI,MAAM,EAAE;AACpB;AAAA,IACD;AAIA,UAAM,gBAAgB,KAAK,OAAO,4BAA4B,KAAK;AACnE,UAAM,WAAW,KAAK,OAAO,aAAa,cAAc,EAAE;AAC1D,QACC,YACA,KAAC,iCAAkB,UAAU,OAAO,KACpC,KAAC,8BAAe,kBAAkB,QAAQ,GACzC;AACD;AAAA,IACD;AACA,YAAQ,IAAI,cAAc,EAAE;AAAA,EAC7B;AACD;",
6
6
  "names": ["i"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts"],
4
- "sourcesContent": ["import {\n\tShapeWithCrop,\n\tStateNode,\n\tTLClickEventInfo,\n\tTLGroupShape,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tVec,\n} from '@tldraw/editor'\nimport { getHitShapeOnCanvasPointerDown } from '../../../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getTranslateCroppedImageChange } from './crop_helpers'\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\toverride onEnter() {\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\n\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\tif (onlySelectedShape) {\n\t\t\tthis.editor.setCroppingShape(onlySelectedShape.id)\n\t\t}\n\t}\n\n\toverride onExit() {\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onCancel() {\n\t\tthis.editor.setCroppingShape(null)\n\t\tthis.editor.setCurrentTool('select.idle', {})\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tif (info.accelKey) {\n\t\t\tthis.cancel()\n\t\t\t// feed the event back into the statechart\n\t\t\tthis.editor.root.handleEvent(info)\n\t\t\treturn\n\t\t}\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !this.editor.isShapeOfType<TLGroupShape>(hitShape, 'group')) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthis.cancel()\n\t\t\t\t// feed the event back into the statechart\n\t\t\t\tthis.editor.root.handleEvent(info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tif (info.shape.id === this.editor.getCroppingShapeId()) {\n\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop', info)\n\t\t\t\t\treturn\n\t\t\t\t} else {\n\t\t\t\t\tif (this.editor.getShapeUtil(info.shape)?.canCrop(info.shape)) {\n\t\t\t\t\t\tthis.editor.setCroppingShape(info.shape.id)\n\t\t\t\t\t\tthis.editor.setSelectedShapes([info.shape.id])\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop', info)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.cancel()\n\t\t\t\t\t\t// feed the event back into the statechart\n\t\t\t\t\t\tthis.editor.root.handleEvent(info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.pointing_rotate_handle', {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\tonInteractionEnd: 'select.crop.idle',\n\t\t\t\t\t\t})\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop_handle', {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\tonInteractionEnd: 'select.crop.idle',\n\t\t\t\t\t\t})\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthis.cancel()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\t// Without this, the double click's \"settle\" would trigger the reset\n\t\t// after the user double clicked the edge to begin cropping\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\tconst croppingShapeId = this.editor.getCroppingShapeId()\n\t\tif (!croppingShapeId) return\n\t\tconst shape = this.editor.getShape(croppingShapeId)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (!util) return\n\n\t\tif (info.target === 'selection') {\n\t\t\tutil.onDoubleClickEdge?.(shape, info)\n\t\t\treturn\n\t\t}\n\n\t\t// If the user double clicks the canvas, we want to cancel cropping,\n\t\t// especially if it's an animated image, we want the image to continue playing.\n\t\tthis.cancel()\n\t\tthis.editor.root.handleEvent(info)\n\t}\n\n\toverride onKeyDown() {\n\t\tthis.nudgeCroppingImage(false)\n\t}\n\n\toverride onKeyRepeat() {\n\t\tthis.nudgeCroppingImage(true)\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\tthis.editor.setCroppingShape(null)\n\t\t\t\tthis.editor.setCurrentTool('select.idle', {})\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.setCroppingShape(null)\n\t\tthis.editor.setCurrentTool('select.idle', {})\n\t}\n\n\tprivate nudgeCroppingImage(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x += 1\n\t\tif (keys.has('ArrowRight')) delta.x -= 1\n\t\tif (keys.has('ArrowUp')) delta.y += 1\n\t\tif (keys.has('ArrowDown')) delta.y -= 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (shiftKey) delta.mul(10)\n\n\t\tconst shape = this.editor.getShape(this.editor.getCroppingShapeId()!) as ShapeWithCrop\n\t\tif (!shape) return\n\t\tconst partial = getTranslateCroppedImageChange(this.editor, shape, delta)\n\n\t\tif (partial) {\n\t\t\tif (!ephemeral) {\n\t\t\t\t// We don't want to create new marks if the user\n\t\t\t\t// is just holding down the arrow keys\n\t\t\t\tthis.editor.markHistoryStoppingPoint('translate crop')\n\t\t\t}\n\n\t\t\tthis.editor.updateShapes<ShapeWithCrop>([partial])\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAQO;AACP,4CAA+C;AAC/C,0BAA+C;AAExC,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAEZ,UAAU;AAClB,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;AAEtD,UAAM,oBAAoB,KAAK,OAAO,qBAAqB;AAE3D,QAAI,mBAAmB;AACtB,WAAK,OAAO,iBAAiB,kBAAkB,EAAE;AAAA,IAClD;AAAA,EACD;AAAA,EAES,SAAS;AACjB,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;AAAA,EACvD;AAAA,EAES,WAAW;AACnB,SAAK,OAAO,iBAAiB,IAAI;AACjC,SAAK,OAAO,eAAe,eAAe,CAAC,CAAC;AAAA,EAC7C;AAAA,EAES,cAAc,MAA0B;AAChD,QAAI,KAAK,UAAU;AAClB,WAAK,OAAO;AAEZ,WAAK,OAAO,KAAK,YAAY,IAAI;AACjC;AAAA,IACD;AAEA,YAAQ,KAAK,QAAQ;AAAA,MACpB,KAAK,UAAU;AACd,cAAM,eAAW,sEAA+B,KAAK,MAAM;AAC3D,YAAI,YAAY,CAAC,KAAK,OAAO,cAA4B,UAAU,OAAO,GAAG;AAC5E,eAAK,cAAc;AAAA,Y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AAI,MAAM,OAAO,IAAI,kBAAI,GAAG,CAAC,CAAC,EAAG;AAEjC,QAAI,SAAU,OAAM,IAAI,EAAE;AAE1B,UAAM,QAAQ,KAAK,OAAO,SAAS,KAAK,OAAO,mBAAmB,CAAE;AACpE,QAAI,CAAC,MAAO;AACZ,UAAM,cAAU,oDAA+B,KAAK,QAAQ,OAAO,KAAK;AAExE,QAAI,SAAS;AACZ,UAAI,CAAC,WAAW;AAGf,aAAK,OAAO,yBAAyB,gBAAgB;AAAA,MACtD;AAEA,WAAK,OAAO,aAA4B,CAAC,OAAO,CAAC;AAAA,IAClD;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import {\n\tShapeWithCrop,\n\tStateNode,\n\tTLClickEventInfo,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tVec,\n} from '@tldraw/editor'\nimport { getHitShapeOnCanvasPointerDown } from '../../../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getTranslateCroppedImageChange } from './crop_helpers'\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\toverride onEnter() {\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\n\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\tif (onlySelectedShape) {\n\t\t\tthis.editor.setCroppingShape(onlySelectedShape.id)\n\t\t}\n\t}\n\n\toverride onExit() {\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onCancel() {\n\t\tthis.editor.setCroppingShape(null)\n\t\tthis.editor.setCurrentTool('select.idle', {})\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tif (info.accelKey) {\n\t\t\tthis.cancel()\n\t\t\t// feed the event back into the statechart\n\t\t\tthis.editor.root.handleEvent(info)\n\t\t\treturn\n\t\t}\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !this.editor.isShapeOfType(hitShape, 'group')) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthis.cancel()\n\t\t\t\t// feed the event back into the statechart\n\t\t\t\tthis.editor.root.handleEvent(info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tif (info.shape.id === this.editor.getCroppingShapeId()) {\n\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop', info)\n\t\t\t\t\treturn\n\t\t\t\t} else {\n\t\t\t\t\tif (this.editor.getShapeUtil(info.shape)?.canCrop(info.shape)) {\n\t\t\t\t\t\tthis.editor.setCroppingShape(info.shape.id)\n\t\t\t\t\t\tthis.editor.setSelectedShapes([info.shape.id])\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop', info)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.cancel()\n\t\t\t\t\t\t// feed the event back into the statechart\n\t\t\t\t\t\tthis.editor.root.handleEvent(info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.pointing_rotate_handle', {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\tonInteractionEnd: 'select.crop.idle',\n\t\t\t\t\t\t})\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tthis.editor.setCurrentTool('select.crop.pointing_crop_handle', {\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\tonInteractionEnd: 'select.crop.idle',\n\t\t\t\t\t\t})\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthis.cancel()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\t// Without this, the double click's \"settle\" would trigger the reset\n\t\t// after the user double clicked the edge to begin cropping\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\tconst croppingShapeId = this.editor.getCroppingShapeId()\n\t\tif (!croppingShapeId) return\n\t\tconst shape = this.editor.getShape(croppingShapeId)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (!util) return\n\n\t\tif (info.target === 'selection') {\n\t\t\tutil.onDoubleClickEdge?.(shape, info)\n\t\t\treturn\n\t\t}\n\n\t\t// If the user double clicks the canvas, we want to cancel cropping,\n\t\t// especially if it's an animated image, we want the image to continue playing.\n\t\tthis.cancel()\n\t\tthis.editor.root.handleEvent(info)\n\t}\n\n\toverride onKeyDown() {\n\t\tthis.nudgeCroppingImage(false)\n\t}\n\n\toverride onKeyRepeat() {\n\t\tthis.nudgeCroppingImage(true)\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\tthis.editor.setCroppingShape(null)\n\t\t\t\tthis.editor.setCurrentTool('select.idle', {})\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.setCroppingShape(null)\n\t\tthis.editor.setCurrentTool('select.idle', {})\n\t}\n\n\tprivate nudgeCroppingImage(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x += 1\n\t\tif (keys.has('ArrowRight')) delta.x -= 1\n\t\tif (keys.has('ArrowUp')) delta.y += 1\n\t\tif (keys.has('ArrowDown')) delta.y -= 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (shiftKey) delta.mul(10)\n\n\t\tconst shape = this.editor.getShape(this.editor.getCroppingShapeId()!) as ShapeWithCrop\n\t\tif (!shape) return\n\t\tconst partial = getTranslateCroppedImageChange(this.editor, shape, delta)\n\n\t\tif (partial) {\n\t\t\tif (!ephemeral) {\n\t\t\t\t// We don't want to create new marks if the user\n\t\t\t\t// is just holding down the arrow keys\n\t\t\t\tthis.editor.markHistoryStoppingPoint('translate crop')\n\t\t\t}\n\n\t\t\tthis.editor.updateShapes([partial])\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAOO;AACP,4CAA+C;AAC/C,0BAA+C;AAExC,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAEZ,UAAU;AAClB,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;AAEtD,UAAM,oBAAoB,KAAK,OAAO,qBAAqB;AAE3D,QAAI,mBAAmB;AACtB,WAAK,OAAO,iBAAiB,kBAAkB,EAAE;AAAA,IAClD;AAAA,EACD;AAAA,EAES,SAAS;AACjB,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,CAAC;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C7C;AAAA,EAEQ,mBAAmB,YAAY,OAAO;AAC7C,UAAM;AAAA,MACL,QAAQ;AAAA,QACP,QAAQ,EAAE,KAAK;AAAA,MAChB;AAAA,IACD,IAAI;AAKJ,UAAM,WAAW,KAAK,IAAI,WAAW;AAErC,UAAM,QAAQ,IAAI,kBAAI,GAAG,CAAC;AAE1B,QAAI,KAAK,IAAI,WAAW,EAAG,OAAM,KAAK;AACtC,QAAI,KAAK,IAAI,YAAY,EAAG,OAAM,KAAK;AACvC,QAAI,KAAK,IAAI,SAAS,EAAG,OAAM,KAAK;AACpC,QAAI,KAAK,IAAI,WAAW,EAAG,OAAM,KAAK;AAEtC,QAAI,MAAM,OAAO,IAAI,kBAAI,GAAG,CAAC,CAAC,EAAG;AAEjC,QAAI,SAAU,OAAM,IAAI,EAAE;AAE1B,UAAM,QAAQ,KAAK,OAAO,SAAS,KAAK,OAAO,mBAAmB,CAAE;AACpE,QAAI,CAAC,MAAO;AACZ,UAAM,cAAU,oDAA+B,KAAK,QAAQ,OAAO,KAAK;AAExE,QAAI,SAAS;AACZ,UAAI,CAAC,WAAW;AAGf,aAAK,OAAO,yBAAyB,gBAAgB;AAAA,MACtD;AAEA,WAAK,OAAO,aAAa,CAAC,OAAO,CAAC;AAAA,IACnC;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -181,7 +181,7 @@ class DraggingHandle extends import_editor.StateNode {
181
181
  };
182
182
  const endChanges = util.onHandleDragEnd?.(shape, handleDragInfo);
183
183
  if (endChanges) {
184
- this.editor.updateShapes([{ ...endChanges, id: shape.id, type: shape.type }]);
184
+ this.editor.updateShapes([{ ...endChanges, id: shape.id }]);
185
185
  }
186
186
  }
187
187
  const { onInteractionEnd } = this.info;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/DraggingHandle.tsx"],
4
- "sourcesContent": ["import {\n\tMat,\n\tStateNode,\n\tTLArrowShape,\n\tTLHandle,\n\tTLLineShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tkickoutOccludedShapes,\n\tsnapAngle,\n\tsortByIndex,\n\tstructuredClone,\n\twarnOnce,\n} from '@tldraw/editor'\nimport { ArrowShapeUtil } from '../../../shapes/arrow/ArrowShapeUtil'\nimport { clearArrowTargetState } from '../../../shapes/arrow/arrowTargetState'\nimport { getArrowBindings } from '../../../shapes/arrow/shared'\n\nexport type DraggingHandleInfo = TLPointerEventInfo & {\n\tshape: TLArrowShape | TLLineShape\n\ttarget: 'handle'\n\tonInteractionEnd?: string | (() => void)\n\tisCreating?: boolean\n\tcreatingMarkId?: string\n}\n\nexport class DraggingHandle extends StateNode {\n\tstatic override id = 'dragging_handle'\n\n\tshapeId!: TLShapeId\n\tinitialHandle!: TLHandle\n\tinitialAdjacentHandle!: TLHandle | null\n\tinitialPagePoint!: Vec\n\n\tmarkId!: string\n\tinitialPageTransform!: Mat\n\tinitialPageRotation!: number\n\n\tinfo!: DraggingHandleInfo\n\n\tisPrecise = false\n\tisPreciseId: TLShapeId | null = null\n\tpointingId: TLShapeId | null = null\n\n\toverride onEnter(info: DraggingHandleInfo) {\n\t\tconst { shape, isCreating, creatingMarkId, handle } = info\n\t\tthis.info = info\n\t\tif (typeof info.onInteractionEnd === 'string') {\n\t\t\tthis.parent.setCurrentToolIdMask(info.onInteractionEnd)\n\t\t}\n\t\tthis.shapeId = shape.id\n\t\tthis.markId = ''\n\n\t\tif (isCreating) {\n\t\t\tif (creatingMarkId) {\n\t\t\t\tthis.markId = creatingMarkId\n\t\t\t} else {\n\t\t\t\t// handle legacy implicit `creating:{shapeId}` marks\n\t\t\t\tconst markId = this.editor.getMarkIdMatching(\n\t\t\t\t\t`creating:${this.editor.getOnlySelectedShapeId()}`\n\t\t\t\t)\n\t\t\t\tif (markId) {\n\t\t\t\t\tthis.markId = markId\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.markId = this.editor.markHistoryStoppingPoint('dragging handle')\n\t\t}\n\n\t\tthis.initialHandle = structuredClone(handle)\n\n\t\tthis.initialPageTransform = this.editor.getShapePageTransform(shape)!\n\t\tthis.initialPageRotation = this.initialPageTransform.rotation()\n\t\tthis.initialPagePoint = this.editor.inputs.originPagePoint.clone()\n\n\t\tthis.editor.setCursor({ type: isCreating ? 'cross' : 'grabbing', rotation: 0 })\n\n\t\tconst handles = this.editor.getShapeHandles(shape)!.sort(sortByIndex)\n\t\tconst index = handles.findIndex((h) => h.id === info.handle.id)\n\n\t\t// Find the adjacent handle\n\t\tthis.initialAdjacentHandle = null\n\n\t\t// First, check if the handle specifies a custom reference handle\n\t\tif (info.handle.snapReferenceHandleId) {\n\t\t\tconst customHandle = handles.find((h) => h.id === info.handle.snapReferenceHandleId)\n\t\t\tif (customHandle) {\n\t\t\t\tthis.initialAdjacentHandle = customHandle\n\t\t\t}\n\t\t}\n\n\t\t// If no custom reference handle, use default behavior\n\t\tif (!this.initialAdjacentHandle) {\n\t\t\t// Start from the handle and work forward\n\t\t\tfor (let i = index + 1; i < handles.length; i++) {\n\t\t\t\tconst handle = handles[i]\n\t\t\t\tif (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {\n\t\t\t\t\tthis.initialAdjacentHandle = handle\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If still no handle, start from the end and work backward\n\t\t\tif (!this.initialAdjacentHandle) {\n\t\t\t\tfor (let i = handles.length - 1; i >= 0; i--) {\n\t\t\t\t\tconst handle = handles[i]\n\t\t\t\t\tif (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {\n\t\t\t\t\t\tthis.initialAdjacentHandle = handle\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// <!-- Only relevant to arrows\n\t\tif (this.editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {\n\t\t\tconst initialBinding = getArrowBindings(this.editor, shape)[info.handle.id as 'start' | 'end']\n\n\t\t\tthis.isPrecise = false\n\n\t\t\tif (initialBinding) {\n\t\t\t\tthis.isPrecise = initialBinding.props.isPrecise\n\t\t\t\tif (this.isPrecise) {\n\t\t\t\t\tthis.isPreciseId = initialBinding.toId\n\t\t\t\t} else {\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// -->\n\n\t\t// Call onHandleDragStart callback\n\t\tconst handleDragInfo = {\n\t\t\thandle: this.initialHandle,\n\t\t\tisPrecise: this.isPrecise,\n\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\tinitial: shape,\n\t\t}\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tconst startChanges = util.onHandleDragStart?.(shape, handleDragInfo)\n\t\tif (startChanges) {\n\t\t\tthis.editor.updateShapes([{ ...startChanges, id: shape.id, type: shape.type }])\n\t\t}\n\n\t\tthis.update()\n\n\t\tthis.editor.select(this.shapeId)\n\t}\n\n\t// Only relevant to arrows\n\tprivate exactTimeout = -1\n\n\t// Only relevant to arrows\n\tprivate resetExactTimeout() {\n\t\tconst arrowUtil = this.editor.getShapeUtil<ArrowShapeUtil>('arrow')\n\t\tconst timeoutValue = arrowUtil.options.pointingPreciseTimeout\n\n\t\tif (this.exactTimeout !== -1) {\n\t\t\tthis.clearExactTimeout()\n\t\t}\n\n\t\tthis.exactTimeout = this.editor.timers.setTimeout(() => {\n\t\t\tif (this.getIsActive() && !this.isPrecise) {\n\t\t\t\tthis.isPrecise = true\n\t\t\t\tthis.isPreciseId = this.pointingId\n\t\t\t\tthis.update()\n\t\t\t}\n\t\t\tthis.exactTimeout = -1\n\t\t}, timeoutValue)\n\t}\n\n\t// Only relevant to arrows\n\tprivate clearExactTimeout() {\n\t\tif (this.exactTimeout !== -1) {\n\t\t\tclearTimeout(this.exactTimeout)\n\t\t\tthis.exactTimeout = -1\n\t\t}\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.update()\n\t}\n\n\toverride onKeyDown() {\n\t\tthis.update()\n\t}\n\n\toverride onKeyUp() {\n\t\tthis.update()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.update()\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onExit() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tclearArrowTargetState(this.editor)\n\t\tthis.editor.snaps.clearIndicators()\n\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\tprivate complete() {\n\t\tthis.editor.snaps.clearIndicators()\n\t\tkickoutOccludedShapes(this.editor, [this.shapeId])\n\n\t\t// Call onHandleDragEnd callback before state transitions\n\t\tconst shape = this.editor.getShape(this.shapeId)\n\t\tif (shape) {\n\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\tconst handleDragInfo = {\n\t\t\t\thandle: this.initialHandle,\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\t\tinitial: this.info.shape,\n\t\t\t}\n\t\t\tconst endChanges = util.onHandleDragEnd?.(shape, handleDragInfo)\n\t\t\tif (endChanges) {\n\t\t\t\tthis.editor.updateShapes([{ ...endChanges, id: shape.id, type: shape.type }])\n\t\t\t}\n\t\t}\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tif (this.editor.getInstanceState().isToolLocked && onInteractionEnd) {\n\t\t\t\t\t// Return to the tool that was active before this one but only if tool lock is turned on!\n\t\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, { shapeId: this.shapeId })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonInteractionEnd?.()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate cancel() {\n\t\t// Call onHandleDragCancel callback before bailing to mark\n\t\tconst shape = this.editor.getShape(this.shapeId)\n\t\tif (shape) {\n\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\tconst handleDragInfo = {\n\t\t\t\thandle: this.initialHandle,\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\t\tinitial: this.info.shape,\n\t\t\t}\n\t\t\tutil.onHandleDragCancel?.(shape, handleDragInfo)\n\t\t}\n\n\t\tthis.editor.bailToMark(this.markId)\n\t\tthis.editor.snaps.clearIndicators()\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\t// Return to the tool that was active before this one, whether tool lock is turned on or not!\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, { shapeId: this.shapeId })\n\t\t\t} else {\n\t\t\t\tonInteractionEnd?.()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate update() {\n\t\tconst { editor, shapeId, initialPagePoint } = this\n\t\tconst { initialHandle, initialPageRotation, initialAdjacentHandle } = this\n\t\tconst isSnapMode = this.editor.user.getIsSnapMode()\n\t\tconst {\n\t\t\tsnaps,\n\t\t\tinputs: { currentPagePoint, shiftKey, ctrlKey, altKey, pointerVelocity },\n\t\t} = editor\n\n\t\tconst initial = this.info.shape\n\n\t\tconst shape = editor.getShape(shapeId)\n\t\tif (!shape) return\n\t\tconst util = editor.getShapeUtil(shape)\n\n\t\tconst initialBinding = editor.isShapeOfType<TLArrowShape>(shape, 'arrow')\n\t\t\t? getArrowBindings(editor, shape)[initialHandle.id as 'start' | 'end']\n\t\t\t: undefined\n\n\t\tlet point = currentPagePoint\n\t\t\t.clone()\n\t\t\t.sub(initialPagePoint)\n\t\t\t.rot(-initialPageRotation)\n\t\t\t.add(initialHandle)\n\n\t\tif (shiftKey && initialAdjacentHandle && initialHandle.id !== 'middle') {\n\t\t\tconst angle = Vec.Angle(initialAdjacentHandle, point)\n\t\t\tconst snappedAngle = snapAngle(angle, 24)\n\t\t\tconst angleDifference = snappedAngle - angle\n\t\t\tpoint = Vec.RotWith(point, initialAdjacentHandle, angleDifference)\n\t\t}\n\n\t\t// Clear any existing snaps\n\t\teditor.snaps.clearIndicators()\n\n\t\tlet nextHandle = { ...initialHandle, x: point.x, y: point.y }\n\n\t\tlet canSnap = false\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tif (initialHandle.canSnap && initialHandle.snapType) {\n\t\t\twarnOnce(\n\t\t\t\t'canSnap is deprecated. Cannot use both canSnap and snapType together - snapping disabled. Please use only snapType.'\n\t\t\t)\n\t\t} else {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\t\tcanSnap = initialHandle.canSnap || initialHandle.snapType !== undefined\n\t\t}\n\n\t\tif (canSnap && (isSnapMode ? !ctrlKey : ctrlKey)) {\n\t\t\t// We're snapping\n\t\t\tconst pageTransform = editor.getShapePageTransform(shape.id)\n\t\t\tif (!pageTransform) throw Error('Expected a page transform')\n\n\t\t\tconst snap = snaps.handles.snapHandle({ currentShapeId: shapeId, handle: nextHandle })\n\n\t\t\tif (snap) {\n\t\t\t\tsnap.nudge.rot(-editor.getShapeParentTransform(shape)!.rotation())\n\t\t\t\tpoint.add(snap.nudge)\n\t\t\t\tnextHandle = { ...initialHandle, x: point.x, y: point.y }\n\t\t\t}\n\t\t}\n\n\t\tconst changes = util.onHandleDrag?.(shape, {\n\t\t\thandle: nextHandle,\n\t\t\tisPrecise: this.isPrecise || altKey,\n\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\tinitial: initial,\n\t\t})\n\n\t\tconst next: TLShapePartial<any> = { id: shape.id, type: shape.type, ...changes }\n\n\t\t// Arrows\n\t\tif (\n\t\t\tinitialHandle.type === 'vertex' &&\n\t\t\tthis.editor.isShapeOfType<TLArrowShape>(shape, 'arrow')\n\t\t) {\n\t\t\tconst bindingAfter = getArrowBindings(editor, shape)[initialHandle.id as 'start' | 'end']\n\n\t\t\tif (bindingAfter) {\n\t\t\t\tif (initialBinding?.toId !== bindingAfter.toId) {\n\t\t\t\t\tthis.pointingId = bindingAfter.toId\n\t\t\t\t\tthis.isPrecise = pointerVelocity.len() < 0.5 || altKey\n\t\t\t\t\tthis.isPreciseId = this.isPrecise ? bindingAfter.toId : null\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (initialBinding) {\n\t\t\t\t\tthis.pointingId = null\n\t\t\t\t\tthis.isPrecise = false\n\t\t\t\t\tthis.isPreciseId = null\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (changes) {\n\t\t\teditor.updateShapes([next])\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAeO;AAEP,8BAAsC;AACtC,oBAAiC;AAU1B,MAAM,uBAAuB,wBAAU;AAAA,EAC7C,OAAgB,KAAK;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA,YAAY;AAAA,EACZ,cAAgC;AAAA,EAChC,aAA+B;AAAA,EAEtB,QAAQ,MAA0B;AAC1C,UAAM,EAAE,OAAO,YAAY,gBAAgB,OAAO,IAAI;AACtD,SAAK,OAAO;AACZ,QAAI,OAAO,KAAK,qBAAqB,UAAU;AAC9C,WAAK,OAAO,qBAAqB,KAAK,gBAAgB;AAAA,IACvD;AACA,SAAK,UAAU,MAAM;AACrB,SAAK,SAAS;AAEd,QAAI,YAAY;AACf,UAAI,gBAAgB;AACnB,aAAK,SAAS;AAAA,MACf,OAAO;AAEN,cAAM,SAAS,KAAK,OAAO;AAAA,UAC1B,YAAY,KAAK,OAAO,uBAAuB,CAA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K,KAAK;AAAA,MAC7B;AAAA,IACD,CAAC;AAED,UAAM,OAA4B,EAAE,IAAI,MAAM,IAAI,MAAM,MAAM,MAAM,GAAG,QAAQ;AAG/E,QACC,cAAc,SAAS,YACvB,KAAK,OAAO,cAA4B,OAAO,OAAO,GACrD;AACD,YAAM,mBAAe,gCAAiB,QAAQ,KAAK,EAAE,cAAc,EAAqB;AAExF,UAAI,cAAc;AACjB,YAAI,gBAAgB,SAAS,aAAa,MAAM;AAC/C,eAAK,aAAa,aAAa;AAC/B,eAAK,YAAY,gBAAgB,IAAI,IAAI,OAAO;AAChD,eAAK,cAAc,KAAK,YAAY,aAAa,OAAO;AACxD,eAAK,kBAAkB;AAAA,QACxB;AAAA,MACD,OAAO;AACN,YAAI,gBAAgB;AACnB,eAAK,aAAa;AAClB,eAAK,YAAY;AACjB,eAAK,cAAc;AACnB,eAAK,kBAAkB;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,QAAI,SAAS;AACZ,aAAO,aAAa,CAAC,IAAI,CAAC;AAAA,IAC3B;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import {\n\tMat,\n\tStateNode,\n\tTLArrowShape,\n\tTLHandle,\n\tTLLineShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tkickoutOccludedShapes,\n\tsnapAngle,\n\tsortByIndex,\n\tstructuredClone,\n\twarnOnce,\n} from '@tldraw/editor'\nimport { ArrowShapeUtil } from '../../../shapes/arrow/ArrowShapeUtil'\nimport { clearArrowTargetState } from '../../../shapes/arrow/arrowTargetState'\nimport { getArrowBindings } from '../../../shapes/arrow/shared'\n\nexport type DraggingHandleInfo = TLPointerEventInfo & {\n\tshape: TLArrowShape | TLLineShape\n\ttarget: 'handle'\n\tonInteractionEnd?: string | (() => void)\n\tisCreating?: boolean\n\tcreatingMarkId?: string\n}\n\nexport class DraggingHandle extends StateNode {\n\tstatic override id = 'dragging_handle'\n\n\tshapeId!: TLShapeId\n\tinitialHandle!: TLHandle\n\tinitialAdjacentHandle!: TLHandle | null\n\tinitialPagePoint!: Vec\n\n\tmarkId!: string\n\tinitialPageTransform!: Mat\n\tinitialPageRotation!: number\n\n\tinfo!: DraggingHandleInfo\n\n\tisPrecise = false\n\tisPreciseId: TLShapeId | null = null\n\tpointingId: TLShapeId | null = null\n\n\toverride onEnter(info: DraggingHandleInfo) {\n\t\tconst { shape, isCreating, creatingMarkId, handle } = info\n\t\tthis.info = info\n\t\tif (typeof info.onInteractionEnd === 'string') {\n\t\t\tthis.parent.setCurrentToolIdMask(info.onInteractionEnd)\n\t\t}\n\t\tthis.shapeId = shape.id\n\t\tthis.markId = ''\n\n\t\tif (isCreating) {\n\t\t\tif (creatingMarkId) {\n\t\t\t\tthis.markId = creatingMarkId\n\t\t\t} else {\n\t\t\t\t// handle legacy implicit `creating:{shapeId}` marks\n\t\t\t\tconst markId = this.editor.getMarkIdMatching(\n\t\t\t\t\t`creating:${this.editor.getOnlySelectedShapeId()}`\n\t\t\t\t)\n\t\t\t\tif (markId) {\n\t\t\t\t\tthis.markId = markId\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.markId = this.editor.markHistoryStoppingPoint('dragging handle')\n\t\t}\n\n\t\tthis.initialHandle = structuredClone(handle)\n\n\t\tthis.initialPageTransform = this.editor.getShapePageTransform(shape)!\n\t\tthis.initialPageRotation = this.initialPageTransform.rotation()\n\t\tthis.initialPagePoint = this.editor.inputs.originPagePoint.clone()\n\n\t\tthis.editor.setCursor({ type: isCreating ? 'cross' : 'grabbing', rotation: 0 })\n\n\t\tconst handles = this.editor.getShapeHandles(shape)!.sort(sortByIndex)\n\t\tconst index = handles.findIndex((h) => h.id === info.handle.id)\n\n\t\t// Find the adjacent handle\n\t\tthis.initialAdjacentHandle = null\n\n\t\t// First, check if the handle specifies a custom reference handle\n\t\tif (info.handle.snapReferenceHandleId) {\n\t\t\tconst customHandle = handles.find((h) => h.id === info.handle.snapReferenceHandleId)\n\t\t\tif (customHandle) {\n\t\t\t\tthis.initialAdjacentHandle = customHandle\n\t\t\t}\n\t\t}\n\n\t\t// If no custom reference handle, use default behavior\n\t\tif (!this.initialAdjacentHandle) {\n\t\t\t// Start from the handle and work forward\n\t\t\tfor (let i = index + 1; i < handles.length; i++) {\n\t\t\t\tconst handle = handles[i]\n\t\t\t\tif (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {\n\t\t\t\t\tthis.initialAdjacentHandle = handle\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If still no handle, start from the end and work backward\n\t\t\tif (!this.initialAdjacentHandle) {\n\t\t\t\tfor (let i = handles.length - 1; i >= 0; i--) {\n\t\t\t\t\tconst handle = handles[i]\n\t\t\t\t\tif (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {\n\t\t\t\t\t\tthis.initialAdjacentHandle = handle\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// <!-- Only relevant to arrows\n\t\tif (this.editor.isShapeOfType(shape, 'arrow')) {\n\t\t\tconst initialBinding = getArrowBindings(this.editor, shape)[info.handle.id as 'start' | 'end']\n\n\t\t\tthis.isPrecise = false\n\n\t\t\tif (initialBinding) {\n\t\t\t\tthis.isPrecise = initialBinding.props.isPrecise\n\t\t\t\tif (this.isPrecise) {\n\t\t\t\t\tthis.isPreciseId = initialBinding.toId\n\t\t\t\t} else {\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// -->\n\n\t\t// Call onHandleDragStart callback\n\t\tconst handleDragInfo = {\n\t\t\thandle: this.initialHandle,\n\t\t\tisPrecise: this.isPrecise,\n\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\tinitial: shape,\n\t\t}\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tconst startChanges = util.onHandleDragStart?.(shape, handleDragInfo)\n\t\tif (startChanges) {\n\t\t\tthis.editor.updateShapes([{ ...startChanges, id: shape.id, type: shape.type }])\n\t\t}\n\n\t\tthis.update()\n\n\t\tthis.editor.select(this.shapeId)\n\t}\n\n\t// Only relevant to arrows\n\tprivate exactTimeout = -1\n\n\t// Only relevant to arrows\n\tprivate resetExactTimeout() {\n\t\tconst arrowUtil = this.editor.getShapeUtil<ArrowShapeUtil>('arrow')\n\t\tconst timeoutValue = arrowUtil.options.pointingPreciseTimeout\n\n\t\tif (this.exactTimeout !== -1) {\n\t\t\tthis.clearExactTimeout()\n\t\t}\n\n\t\tthis.exactTimeout = this.editor.timers.setTimeout(() => {\n\t\t\tif (this.getIsActive() && !this.isPrecise) {\n\t\t\t\tthis.isPrecise = true\n\t\t\t\tthis.isPreciseId = this.pointingId\n\t\t\t\tthis.update()\n\t\t\t}\n\t\t\tthis.exactTimeout = -1\n\t\t}, timeoutValue)\n\t}\n\n\t// Only relevant to arrows\n\tprivate clearExactTimeout() {\n\t\tif (this.exactTimeout !== -1) {\n\t\t\tclearTimeout(this.exactTimeout)\n\t\t\tthis.exactTimeout = -1\n\t\t}\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.update()\n\t}\n\n\toverride onKeyDown() {\n\t\tthis.update()\n\t}\n\n\toverride onKeyUp() {\n\t\tthis.update()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.update()\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onExit() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tclearArrowTargetState(this.editor)\n\t\tthis.editor.snaps.clearIndicators()\n\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\tprivate complete() {\n\t\tthis.editor.snaps.clearIndicators()\n\t\tkickoutOccludedShapes(this.editor, [this.shapeId])\n\n\t\t// Call onHandleDragEnd callback before state transitions\n\t\tconst shape = this.editor.getShape(this.shapeId)\n\t\tif (shape) {\n\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\tconst handleDragInfo = {\n\t\t\t\thandle: this.initialHandle,\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\t\tinitial: this.info.shape,\n\t\t\t}\n\t\t\tconst endChanges = util.onHandleDragEnd?.(shape, handleDragInfo)\n\t\t\tif (endChanges) {\n\t\t\t\tthis.editor.updateShapes([{ ...endChanges, id: shape.id }])\n\t\t\t}\n\t\t}\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tif (this.editor.getInstanceState().isToolLocked && onInteractionEnd) {\n\t\t\t\t\t// Return to the tool that was active before this one but only if tool lock is turned on!\n\t\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, { shapeId: this.shapeId })\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonInteractionEnd?.()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate cancel() {\n\t\t// Call onHandleDragCancel callback before bailing to mark\n\t\tconst shape = this.editor.getShape(this.shapeId)\n\t\tif (shape) {\n\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\tconst handleDragInfo = {\n\t\t\t\thandle: this.initialHandle,\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\t\tinitial: this.info.shape,\n\t\t\t}\n\t\t\tutil.onHandleDragCancel?.(shape, handleDragInfo)\n\t\t}\n\n\t\tthis.editor.bailToMark(this.markId)\n\t\tthis.editor.snaps.clearIndicators()\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\t// Return to the tool that was active before this one, whether tool lock is turned on or not!\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, { shapeId: this.shapeId })\n\t\t\t} else {\n\t\t\t\tonInteractionEnd?.()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate update() {\n\t\tconst { editor, shapeId, initialPagePoint } = this\n\t\tconst { initialHandle, initialPageRotation, initialAdjacentHandle } = this\n\t\tconst isSnapMode = this.editor.user.getIsSnapMode()\n\t\tconst {\n\t\t\tsnaps,\n\t\t\tinputs: { currentPagePoint, shiftKey, ctrlKey, altKey, pointerVelocity },\n\t\t} = editor\n\n\t\tconst initial = this.info.shape\n\n\t\tconst shape = editor.getShape(shapeId)\n\t\tif (!shape) return\n\t\tconst util = editor.getShapeUtil(shape)\n\n\t\tconst initialBinding = editor.isShapeOfType(shape, 'arrow')\n\t\t\t? getArrowBindings(editor, shape)[initialHandle.id as 'start' | 'end']\n\t\t\t: undefined\n\n\t\tlet point = currentPagePoint\n\t\t\t.clone()\n\t\t\t.sub(initialPagePoint)\n\t\t\t.rot(-initialPageRotation)\n\t\t\t.add(initialHandle)\n\n\t\tif (shiftKey && initialAdjacentHandle && initialHandle.id !== 'middle') {\n\t\t\tconst angle = Vec.Angle(initialAdjacentHandle, point)\n\t\t\tconst snappedAngle = snapAngle(angle, 24)\n\t\t\tconst angleDifference = snappedAngle - angle\n\t\t\tpoint = Vec.RotWith(point, initialAdjacentHandle, angleDifference)\n\t\t}\n\n\t\t// Clear any existing snaps\n\t\teditor.snaps.clearIndicators()\n\n\t\tlet nextHandle = { ...initialHandle, x: point.x, y: point.y }\n\n\t\tlet canSnap = false\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tif (initialHandle.canSnap && initialHandle.snapType) {\n\t\t\twarnOnce(\n\t\t\t\t'canSnap is deprecated. Cannot use both canSnap and snapType together - snapping disabled. Please use only snapType.'\n\t\t\t)\n\t\t} else {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\t\tcanSnap = initialHandle.canSnap || initialHandle.snapType !== undefined\n\t\t}\n\n\t\tif (canSnap && (isSnapMode ? !ctrlKey : ctrlKey)) {\n\t\t\t// We're snapping\n\t\t\tconst pageTransform = editor.getShapePageTransform(shape.id)\n\t\t\tif (!pageTransform) throw Error('Expected a page transform')\n\n\t\t\tconst snap = snaps.handles.snapHandle({ currentShapeId: shapeId, handle: nextHandle })\n\n\t\t\tif (snap) {\n\t\t\t\tsnap.nudge.rot(-editor.getShapeParentTransform(shape)!.rotation())\n\t\t\t\tpoint.add(snap.nudge)\n\t\t\t\tnextHandle = { ...initialHandle, x: point.x, y: point.y }\n\t\t\t}\n\t\t}\n\n\t\tconst changes = util.onHandleDrag?.(shape, {\n\t\t\thandle: nextHandle,\n\t\t\tisPrecise: this.isPrecise || altKey,\n\t\t\tisCreatingShape: !!this.info.isCreating,\n\t\t\tinitial: initial,\n\t\t})\n\n\t\tconst next: TLShapePartial<any> = { id: shape.id, type: shape.type, ...changes }\n\n\t\t// Arrows\n\t\tif (initialHandle.type === 'vertex' && this.editor.isShapeOfType(shape, 'arrow')) {\n\t\t\tconst bindingAfter = getArrowBindings(editor, shape)[initialHandle.id as 'start' | 'end']\n\n\t\t\tif (bindingAfter) {\n\t\t\t\tif (initialBinding?.toId !== bindingAfter.toId) {\n\t\t\t\t\tthis.pointingId = bindingAfter.toId\n\t\t\t\t\tthis.isPrecise = pointerVelocity.len() < 0.5 || altKey\n\t\t\t\t\tthis.isPreciseId = this.isPrecise ? bindingAfter.toId : null\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (initialBinding) {\n\t\t\t\t\tthis.pointingId = null\n\t\t\t\t\tthis.isPrecise = false\n\t\t\t\t\tthis.isPreciseId = null\n\t\t\t\t\tthis.resetExactTimeout()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (changes) {\n\t\t\teditor.updateShapes([next])\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;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QAAI,SAAS;AACZ,aAAO,aAAa,CAAC,IAAI,CAAC;AAAA,IAC3B;AAAA,EACD;AACD;",
6
6
  "names": ["handle"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/EditingShape.ts"],
4
- "sourcesContent": ["import {\n\tStateNode,\n\tTLCancelEventInfo,\n\tTLCompleteEventInfo,\n\ttlenv,\n\tTLFrameShape,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLTextShape,\n} from '@tldraw/editor'\nimport { getTextLabels } from '../../../utils/shapes/shapes'\nimport { renderPlaintextFromRichText } from '../../../utils/text/richText'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\n\ninterface EditingShapeInfo {\n\tisCreatingTextWhileToolLocked?: boolean\n}\n\nexport class EditingShape extends StateNode {\n\tstatic override id = 'editing_shape'\n\n\thitShapeForPointerUp: TLShape | null = null\n\tprivate info = {} as EditingShapeInfo\n\n\toverride onEnter(info: EditingShapeInfo) {\n\t\tconst editingShape = this.editor.getEditingShape()\n\t\tif (!editingShape) throw Error('Entered editing state without an editing shape')\n\t\tthis.hitShapeForPointerUp = null\n\n\t\tthis.info = info\n\n\t\tif (info.isCreatingTextWhileToolLocked) {\n\t\t\tthis.parent.setCurrentToolIdMask('text')\n\t\t}\n\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.editor.select(editingShape)\n\t}\n\n\toverride onExit() {\n\t\tconst { editingShapeId } = this.editor.getCurrentPageState()\n\t\tif (!editingShapeId) return\n\n\t\t// Clear the editing shape\n\t\tthis.editor.setEditingShape(null)\n\n\t\tupdateHoveredShapeId.cancel()\n\n\t\tif (this.info.isCreatingTextWhileToolLocked) {\n\t\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\t\tthis.editor.setCurrentTool('text', {})\n\t\t}\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\t// In the case where on pointer down we hit a shape's label, we need to check if the user is dragging.\n\t\t// and if they are, we need to transition to translating instead.\n\t\tif (this.hitShapeForPointerUp && this.editor.inputs.isDragging) {\n\t\t\tif (this.editor.getIsReadonly()) return\n\t\t\tif (this.hitShapeForPointerUp.isLocked) return\n\t\t\tthis.editor.select(this.hitShapeForPointerUp)\n\t\t\tthis.parent.transition('translating', info)\n\t\t\tthis.hitShapeForPointerUp = null\n\t\t\treturn\n\t\t}\n\n\t\tswitch (info.target) {\n\t\t\tcase 'shape':\n\t\t\tcase 'canvas': {\n\t\t\t\tupdateHoveredShapeId(this.editor)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tthis.hitShapeForPointerUp = null\n\n\t\tswitch (info.target) {\n\t\t\t// N.B. This bit of logic has a bit of history to it.\n\t\t\t// There was a PR that got rid of this logic: https://github.com/tldraw/tldraw/pull/4237\n\t\t\t// But here we bring it back to help support the new rich text world.\n\t\t\t// The original issue which is visible in the video attachments in the PR now seem\n\t\t\t// to have been resolved anyway via some other layer.\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor, true /* hitLabels */)\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape: selectingShape } = info\n\t\t\t\tconst editingShape = this.editor.getEditingShape()\n\n\t\t\t\tif (!editingShape) {\n\t\t\t\t\tthrow Error('Expected an editing shape!')\n\t\t\t\t}\n\n\t\t\t\t// for shapes with labels, check to see if the click was inside of the shape's label\n\t\t\t\tconst geometry = this.editor.getShapeUtil(selectingShape).getGeometry(selectingShape)\n\t\t\t\tconst textLabels = getTextLabels(geometry)\n\t\t\t\tconst textLabel = textLabels.length === 1 ? textLabels[0] : undefined\n\t\t\t\t// N.B. One nuance here is that we want empty text fields to be removed from the canvas when the user clicks away from them.\n\t\t\t\tconst isEmptyTextShape =\n\t\t\t\t\tthis.editor.isShapeOfType<TLTextShape>(editingShape, 'text') &&\n\t\t\t\t\trenderPlaintextFromRichText(this.editor, editingShape.props.richText).trim() === ''\n\t\t\t\tif (textLabel && !isEmptyTextShape) {\n\t\t\t\t\tconst pointInShapeSpace = this.editor.getPointInShapeSpace(\n\t\t\t\t\t\tselectingShape,\n\t\t\t\t\t\tthis.editor.inputs.currentPagePoint\n\t\t\t\t\t)\n\t\t\t\t\tif (\n\t\t\t\t\t\ttextLabel.bounds.containsPoint(pointInShapeSpace, 0) &&\n\t\t\t\t\t\ttextLabel.hitTestPoint(pointInShapeSpace)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// it's a hit to the label!\n\t\t\t\t\t\tif (selectingShape.id === editingShape.id) {\n\t\t\t\t\t\t\t// If we clicked on the editing geo / arrow shape's label, do nothing\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.hitShapeForPointerUp = selectingShape\n\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('editing on pointer up')\n\t\t\t\t\t\t\tthis.editor.select(selectingShape.id)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (selectingShape.id === editingShape.id) {\n\t\t\t\t\t\t// If we clicked on a frame, while editing its heading, cancel editing\n\t\t\t\t\t\tif (this.editor.isShapeOfType<TLFrameShape>(selectingShape, 'frame')) {\n\t\t\t\t\t\t\tthis.editor.setEditingShape(null)\n\t\t\t\t\t\t\tthis.parent.transition('idle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If we clicked on the editing shape (which isn't a shape with a label), do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// But if we clicked on a different shape of the same type, transition to pointing_shape instead\n\t\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\t// still here? Cancel editing and transition back to select idle\n\t\tthis.parent.transition('idle', info)\n\t\t// then feed the pointer down event back into the state chart as if it happened in that state\n\t\tthis.editor.root.handleEvent(info)\n\t}\n\n\toverride onPointerUp(info: TLPointerEventInfo) {\n\t\t// If we're not dragging, and it's a hit to the label, begin editing the shape.\n\t\tconst hitShape = this.hitShapeForPointerUp\n\t\tif (!hitShape) return\n\t\tthis.hitShapeForPointerUp = null\n\n\t\t// Stay in edit mode to maintain flow of editing.\n\t\tconst util = this.editor.getShapeUtil(hitShape)\n\t\tif (hitShape.isLocked) return\n\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(hitShape)) {\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.select(hitShape.id)\n\n\t\tconst currentEditingShape = this.editor.getEditingShape()\n\t\tconst isEditToEditAction = currentEditingShape && currentEditingShape.id !== hitShape.id\n\t\tthis.editor.setEditingShape(hitShape.id)\n\n\t\tconst isMobile = tlenv.isIos || tlenv.isAndroid\n\t\tif (!isMobile || !isEditToEditAction) {\n\t\t\tthis.editor.emit('place-caret', { shapeId: hitShape.id, point: info.point })\n\t\t} else if (isMobile && isEditToEditAction) {\n\t\t\tthis.editor.emit('select-all-text', { shapeId: hitShape.id })\n\t\t}\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onComplete(info: TLCompleteEventInfo) {\n\t\tthis.editor.getContainer().focus()\n\t\tthis.parent.transition('idle', info)\n\t}\n\n\toverride onCancel(info: TLCancelEventInfo) {\n\t\tthis.editor.getContainer().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C1C,SAAK,OAAO,aAAa,EAAE,MAAM;AACjC,SAAK,OAAO,WAAW,QAAQ,IAAI;AAAA,EACpC;AACD;",
4
+ "sourcesContent": ["import {\n\tStateNode,\n\tTLCancelEventInfo,\n\tTLCompleteEventInfo,\n\ttlenv,\n\tTLPointerEventInfo,\n\tTLShape,\n} from '@tldraw/editor'\nimport { getTextLabels } from '../../../utils/shapes/shapes'\nimport { renderPlaintextFromRichText } from '../../../utils/text/richText'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\n\ninterface EditingShapeInfo {\n\tisCreatingTextWhileToolLocked?: boolean\n}\n\nexport class EditingShape extends StateNode {\n\tstatic override id = 'editing_shape'\n\n\thitShapeForPointerUp: TLShape | null = null\n\tprivate info = {} as EditingShapeInfo\n\n\toverride onEnter(info: EditingShapeInfo) {\n\t\tconst editingShape = this.editor.getEditingShape()\n\t\tif (!editingShape) throw Error('Entered editing state without an editing shape')\n\t\tthis.hitShapeForPointerUp = null\n\n\t\tthis.info = info\n\n\t\tif (info.isCreatingTextWhileToolLocked) {\n\t\t\tthis.parent.setCurrentToolIdMask('text')\n\t\t}\n\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.editor.select(editingShape)\n\t}\n\n\toverride onExit() {\n\t\tconst { editingShapeId } = this.editor.getCurrentPageState()\n\t\tif (!editingShapeId) return\n\n\t\t// Clear the editing shape\n\t\tthis.editor.setEditingShape(null)\n\n\t\tupdateHoveredShapeId.cancel()\n\n\t\tif (this.info.isCreatingTextWhileToolLocked) {\n\t\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\t\tthis.editor.setCurrentTool('text', {})\n\t\t}\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\t// In the case where on pointer down we hit a shape's label, we need to check if the user is dragging.\n\t\t// and if they are, we need to transition to translating instead.\n\t\tif (this.hitShapeForPointerUp && this.editor.inputs.isDragging) {\n\t\t\tif (this.editor.getIsReadonly()) return\n\t\t\tif (this.hitShapeForPointerUp.isLocked) return\n\t\t\tthis.editor.select(this.hitShapeForPointerUp)\n\t\t\tthis.parent.transition('translating', info)\n\t\t\tthis.hitShapeForPointerUp = null\n\t\t\treturn\n\t\t}\n\n\t\tswitch (info.target) {\n\t\t\tcase 'shape':\n\t\t\tcase 'canvas': {\n\t\t\t\tupdateHoveredShapeId(this.editor)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tthis.hitShapeForPointerUp = null\n\n\t\tswitch (info.target) {\n\t\t\t// N.B. This bit of logic has a bit of history to it.\n\t\t\t// There was a PR that got rid of this logic: https://github.com/tldraw/tldraw/pull/4237\n\t\t\t// But here we bring it back to help support the new rich text world.\n\t\t\t// The original issue which is visible in the video attachments in the PR now seem\n\t\t\t// to have been resolved anyway via some other layer.\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor, true /* hitLabels */)\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape: selectingShape } = info\n\t\t\t\tconst editingShape = this.editor.getEditingShape()\n\n\t\t\t\tif (!editingShape) {\n\t\t\t\t\tthrow Error('Expected an editing shape!')\n\t\t\t\t}\n\n\t\t\t\t// for shapes with labels, check to see if the click was inside of the shape's label\n\t\t\t\tconst geometry = this.editor.getShapeUtil(selectingShape).getGeometry(selectingShape)\n\t\t\t\tconst textLabels = getTextLabels(geometry)\n\t\t\t\tconst textLabel = textLabels.length === 1 ? textLabels[0] : undefined\n\t\t\t\t// N.B. One nuance here is that we want empty text fields to be removed from the canvas when the user clicks away from them.\n\t\t\t\tconst isEmptyTextShape =\n\t\t\t\t\tthis.editor.isShapeOfType(editingShape, 'text') &&\n\t\t\t\t\trenderPlaintextFromRichText(this.editor, editingShape.props.richText).trim() === ''\n\t\t\t\tif (textLabel && !isEmptyTextShape) {\n\t\t\t\t\tconst pointInShapeSpace = this.editor.getPointInShapeSpace(\n\t\t\t\t\t\tselectingShape,\n\t\t\t\t\t\tthis.editor.inputs.currentPagePoint\n\t\t\t\t\t)\n\t\t\t\t\tif (\n\t\t\t\t\t\ttextLabel.bounds.containsPoint(pointInShapeSpace, 0) &&\n\t\t\t\t\t\ttextLabel.hitTestPoint(pointInShapeSpace)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// it's a hit to the label!\n\t\t\t\t\t\tif (selectingShape.id === editingShape.id) {\n\t\t\t\t\t\t\t// If we clicked on the editing geo / arrow shape's label, do nothing\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.hitShapeForPointerUp = selectingShape\n\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('editing on pointer up')\n\t\t\t\t\t\t\tthis.editor.select(selectingShape.id)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (selectingShape.id === editingShape.id) {\n\t\t\t\t\t\t// If we clicked on a frame, while editing its heading, cancel editing\n\t\t\t\t\t\tif (this.editor.isShapeOfType(selectingShape, 'frame')) {\n\t\t\t\t\t\t\tthis.editor.setEditingShape(null)\n\t\t\t\t\t\t\tthis.parent.transition('idle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If we clicked on the editing shape (which isn't a shape with a label), do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// But if we clicked on a different shape of the same type, transition to pointing_shape instead\n\t\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\t// still here? Cancel editing and transition back to select idle\n\t\tthis.parent.transition('idle', info)\n\t\t// then feed the pointer down event back into the state chart as if it happened in that state\n\t\tthis.editor.root.handleEvent(info)\n\t}\n\n\toverride onPointerUp(info: TLPointerEventInfo) {\n\t\t// If we're not dragging, and it's a hit to the label, begin editing the shape.\n\t\tconst hitShape = this.hitShapeForPointerUp\n\t\tif (!hitShape) return\n\t\tthis.hitShapeForPointerUp = null\n\n\t\t// Stay in edit mode to maintain flow of editing.\n\t\tconst util = this.editor.getShapeUtil(hitShape)\n\t\tif (hitShape.isLocked) return\n\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(hitShape)) {\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.select(hitShape.id)\n\n\t\tconst currentEditingShape = this.editor.getEditingShape()\n\t\tconst isEditToEditAction = currentEditingShape && currentEditingShape.id !== hitShape.id\n\t\tthis.editor.setEditingShape(hitShape.id)\n\n\t\tconst isMobile = tlenv.isIos || tlenv.isAndroid\n\t\tif (!isMobile || !isEditToEditAction) {\n\t\t\tthis.editor.emit('place-caret', { shapeId: hitShape.id, point: info.point })\n\t\t} else if (isMobile && isEditToEditAction) {\n\t\t\tthis.editor.emit('select-all-text', { shapeId: hitShape.id })\n\t\t}\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onComplete(info: TLCompleteEventInfo) {\n\t\tthis.editor.getContainer().focus()\n\t\tthis.parent.transition('idle', info)\n\t}\n\n\toverride onCancel(info: TLCancelEventInfo) {\n\t\tthis.editor.getContainer().focus()\n\t\tthis.parent.transition('idle', info)\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAOO;AACP,oBAA8B;AAC9B,sBAA4C;AAC5C,4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
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/Idle.ts"],
4
- "sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLAdjacentDirection,\n\tTLClickEventInfo,\n\tTLGroupShape,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tTLShape,\n\tTLTextShape,\n\tVec,\n\tVecLike,\n\tcreateShapeId,\n\tdebugFlags,\n\tkickoutOccludedShapes,\n\tpointInPolygon,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getShouldEnterCropMode } from '../../selection-logic/getShouldEnterCropModeOnPointerDown'\nimport { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\nimport { startEditingShapeWithLabel } from '../selectHelpers'\n\nconst SKIPPED_KEYS_FOR_AUTO_EDITING = [\n\t'Delete',\n\t'Backspace',\n\t'[',\n\t']',\n\t'Enter',\n\t' ',\n\t'Shift',\n\t'Tab',\n]\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\tselectedShapesOnKeyDown: TLShape[] = []\n\n\toverride onEnter() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.selectedShapesOnKeyDown = []\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\tupdateHoveredShapeId.cancel()\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tconst shouldEnterCropMode = info.ctrlKey && getShouldEnterCropMode(this.editor)\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\t// Check to see if we hit any shape under the pointer; if so,\n\t\t\t\t// handle this as a pointer down on the shape instead of the canvas\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !hitShape.isLocked) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tif (this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tif (this.editor.inputs.altKey) {\n\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t} else {\n\t\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\t\tthis.parent.transition('pointing_handle', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.parent.transition('pointing_rotate_handle', info)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tif (shouldEnterCropMode) {\n\t\t\t\t\t\t\tthis.parent.transition('crop.pointing_crop_handle', info)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.parent.transition('pointing_resize_handle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thoveredShape &&\n\t\t\t\t\t\t\t!this.editor.getSelectedShapeIds().includes(hoveredShape.id) &&\n\t\t\t\t\t\t\t!hoveredShape.isLocked\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\t\tshape: hoveredShape,\n\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.parent.transition('pointing_selection', info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\t// We don't want to double click while toggling shapes\n\t\tif (info.ctrlKey || info.shiftKey) return\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\n\t\t\t\t// todo\n\t\t\t\t// double clicking on the middle of a hollow geo shape without a label, or\n\t\t\t\t// over the label of a hollwo shape that has a label, should start editing\n\t\t\t\t// that shape's label. We can't support \"double click anywhere inside\"\n\t\t\t\t// of the shape yet because that also creates text shapes, and can produce\n\t\t\t\t// unexpected results when working \"inside of\" a hollow shape.\n\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: (this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint) ??\n\t\t\t\t\t\t\tthis.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t}))\n\n\t\t\t\tconst focusedGroupId = this.editor.getFocusedGroupId()\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tif (this.editor.isShapeOfType<TLGroupShape>(hitShape, 'group')) {\n\t\t\t\t\t\t// Probably select the shape\n\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst parent = this.editor.getShape(hitShape.parentId)\n\t\t\t\t\t\tif (parent && this.editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\t\t\t\t\t// The shape is the direct child of a group. If the group is\n\t\t\t\t\t\t\t// selected, then we can select the shape. If the group is the\n\t\t\t\t\t\t\t// focus layer id, then we can double click into it as usual.\n\t\t\t\t\t\t\tif (focusedGroupId && parent.id === focusedGroupId) {\n\t\t\t\t\t\t\t\t// noop, double click on the shape as normal below\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// The shape is the child of some group other than our current\n\t\t\t\t\t\t\t\t// focus layer. We should probably select the group instead.\n\t\t\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// double click on the shape. We'll start editing the\n\t\t\t\t\t// shape if it's editable or else do a double click on\n\t\t\t\t\t// the canvas.\n\t\t\t\t\tthis.onDoubleClick({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (!this.editor.inputs.shiftKey) {\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\t\t\tif (onlySelectedShape) {\n\t\t\t\t\tconst util = this.editor.getShapeUtil(onlySelectedShape)\n\n\t\t\t\t\tif (!this.canInteractWithShapeInReadOnly(onlySelectedShape)) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// Test edges for an onDoubleClickEdge handler\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'right' ||\n\t\t\t\t\t\tinfo.handle === 'left' ||\n\t\t\t\t\t\tinfo.handle === 'top' ||\n\t\t\t\t\t\tinfo.handle === 'bottom'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickEdge?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click edge')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'top_left' ||\n\t\t\t\t\t\tinfo.handle === 'top_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_left'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickCorner?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click corner')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// For corners OR edges but NOT rotation corners\n\t\t\t\t\tif (\n\t\t\t\t\t\tutil.canCrop(onlySelectedShape) &&\n\t\t\t\t\t\t!this.editor.isShapeOrAncestorLocked(onlySelectedShape)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\t\tthis.startEditingShape(onlySelectedShape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\n\t\t\t\t// Allow playing videos and embeds\n\t\t\t\tif (shape.type !== 'video' && shape.type !== 'embed' && this.editor.getIsReadonly()) break\n\n\t\t\t\tif (util.onDoubleClick) {\n\t\t\t\t\t// Call the shape's double click handler\n\t\t\t\t\tconst change = util.onDoubleClick?.(shape)\n\t\t\t\t\tif (change) {\n\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (util.canCrop(shape) && !this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\t// crop image etc on double click\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('select and crop')\n\t\t\t\t\tthis.editor.select(info.shape?.id)\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the shape can edit, then begin editing\n\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape cannot edit, then create a text shape and\n\t\t\t\t\t// begin editing the text shape\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tconst { shape, handle } = info\n\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\t\tconst changes = util.onDoubleClickHandle?.(shape, handle)\n\n\t\t\t\tif (changes) {\n\t\t\t\t\tthis.editor.updateShapes([changes])\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape can edit, then begin editing the shape.\n\t\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onRightClick(info: TLPointerEventInfo) {\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType<TLGroupShape>(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t\thitLabels: true,\n\t\t\t\t\t\t\t\thitLocked: true,\n\t\t\t\t\t\t\t\thitFrameInside: true,\n\t\t\t\t\t\t\t\trenderingOnly: true,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.editor.selectNone()\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { selectedShapeIds } = this.editor.getCurrentPageState()\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tconst targetShape = this.editor.getOutermostSelectableShape(\n\t\t\t\t\tshape,\n\t\t\t\t\t(parent) => !selectedShapeIds.includes(parent.id)\n\t\t\t\t)\n\n\t\t\t\tif (\n\t\t\t\t\t!selectedShapeIds.includes(targetShape.id) &&\n\t\t\t\t\t!this.editor.findShapeAncestor(targetShape, (shape) =>\n\t\t\t\t\t\tselectedShapeIds.includes(shape.id)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('selecting shape')\n\t\t\t\t\tthis.editor.setSelectedShapes([targetShape.id])\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tif (\n\t\t\tthis.editor.getFocusedGroupId() !== this.editor.getCurrentPageId() &&\n\t\t\tthis.editor.getSelectedShapeIds().length > 0\n\t\t) {\n\t\t\tthis.editor.popFocusedGroupId()\n\t\t} else {\n\t\t\tthis.editor.markHistoryStoppingPoint('clearing selection')\n\t\t\tthis.editor.selectNone()\n\t\t}\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tthis.selectedShapesOnKeyDown = this.editor.getSelectedShapes()\n\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tif (info.shiftKey) {\n\t\t\t\t\t\tif (info.code === 'ArrowDown') {\n\t\t\t\t\t\t\tthis.editor.selectFirstChildShape()\n\t\t\t\t\t\t} else if (info.code === 'ArrowUp') {\n\t\t\t\t\t\t\tthis.editor.selectParentShape()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(false)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (debugFlags['editOnType'].get()) {\n\t\t\t// This feature flag lets us start editing a note shape's label when a key is pressed.\n\t\t\t// We exclude certain keys to avoid conflicting with modifiers, but there are conflicts\n\t\t\t// with other action kbds, hence why this is kept behind a feature flag.\n\t\t\tif (!SKIPPED_KEYS_FOR_AUTO_EDITING.includes(info.key) && !info.altKey && !info.ctrlKey) {\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (\n\t\t\t\t\tonlySelectedShape &&\n\t\t\t\t\t// If it's a note shape, then edit on type\n\t\t\t\t\tthis.editor.isShapeOfType(onlySelectedShape, 'note') &&\n\t\t\t\t\t// If it's not locked or anything\n\t\t\t\t\tthis.shouldStartEditingShape(onlySelectedShape)\n\t\t\t\t) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyRepeat(info: TLKeyboardEventInfo) {\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(true)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\t// Because Enter onKeyDown can happen outside the canvas (but then focus the canvas potentially),\n\t\t\t\t// we need to check if the canvas was initially selecting something before continuing.\n\t\t\t\tif (!this.selectedShapesOnKeyDown.length) return\n\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\n\t\t\t\t// On enter, if every selected shape is a group, then select all of the children of the groups\n\t\t\t\tif (\n\t\t\t\t\tselectedShapes.every((shape) => this.editor.isShapeOfType<TLGroupShape>(shape, 'group'))\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.setSelectedShapes(\n\t\t\t\t\t\tselectedShapes.flatMap((shape) => this.editor.getSortedChildIdsForParent(shape.id))\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (onlySelectedShape && this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is croppable, then begin cropping it\n\t\t\t\tif (getShouldEnterCropMode(this.editor)) {\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate shouldStartEditingShape(\n\t\tshape: TLShape | null = this.editor.getOnlySelectedShape()\n\t): boolean {\n\t\tif (!shape) return false\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return false\n\t\tif (!this.canInteractWithShapeInReadOnly(shape)) return false\n\t\treturn this.editor.getShapeUtil(shape).canEdit(shape)\n\t}\n\n\tprivate startEditingShape(\n\t\tshape: TLShape,\n\t\tinfo: TLClickEventInfo | TLKeyboardEventInfo,\n\t\tshouldSelectAll?: boolean\n\t) {\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return\n\t\tthis.editor.markHistoryStoppingPoint('editing shape')\n\t\tstartEditingShapeWithLabel(this.editor, shape, shouldSelectAll)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tisOverArrowLabelTest(shape: TLShape | undefined) {\n\t\tif (!shape) return false\n\n\t\treturn isOverArrowLabel(this.editor, shape)\n\t}\n\n\thandleDoubleClickOnCanvas(info: TLClickEventInfo) {\n\t\t// Create text shape and transition to editing_shape\n\t\tif (this.editor.getIsReadonly()) return\n\n\t\tif (!this.editor.options.createTextOnCanvasDoubleClick) return\n\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\n\t\tconst id = createShapeId()\n\n\t\tconst { x, y } = this.editor.inputs.currentPagePoint\n\n\t\t// Allow this to trigger the max shapes reached alert\n\t\tthis.editor.createShapes<TLTextShape>([\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype: 'text',\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\tprops: {\n\t\t\t\t\trichText: toRichText(''),\n\t\t\t\t\tautoSize: true,\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\n\t\tconst shape = this.editor.getShape(id)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(shape)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.setEditingShape(id)\n\t\tthis.editor.select(id)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tprivate nudgeSelectedShapes(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x -= 1\n\t\tif (keys.has('ArrowRight')) delta.x += 1\n\t\tif (keys.has('ArrowUp')) delta.y -= 1\n\t\tif (keys.has('ArrowDown')) delta.y += 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (!ephemeral) this.editor.markHistoryStoppingPoint('nudge shapes')\n\n\t\tconst { gridSize } = this.editor.getDocumentSettings()\n\n\t\tconst step = this.editor.getInstanceState().isGridMode\n\t\t\t? shiftKey\n\t\t\t\t? gridSize * GRID_INCREMENT\n\t\t\t\t: gridSize\n\t\t\t: shiftKey\n\t\t\t\t? MAJOR_NUDGE_FACTOR\n\t\t\t\t: MINOR_NUDGE_FACTOR\n\n\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\tthis.editor.nudgeShapes(selectedShapeIds, delta.mul(step))\n\t\tkickoutOccludedShapes(this.editor, selectedShapeIds)\n\t}\n\n\tprivate canInteractWithShapeInReadOnly(shape: TLShape) {\n\t\tif (!this.editor.getIsReadonly()) return true\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (util.canEditInReadonly(shape)) return true\n\t\treturn false\n\t}\n}\n\nexport const MAJOR_NUDGE_FACTOR = 10\nexport const MINOR_NUDGE_FACTOR = 1\nexport const GRID_INCREMENT = 5\n\nfunction isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) {\n\tconst selectionBounds = editor.getSelectionRotatedPageBounds()\n\tif (!selectionBounds) return false\n\n\tconst selectionRotation = editor.getSelectionRotation()\n\tif (!selectionRotation) return selectionBounds.containsPoint(point)\n\n\treturn pointInPolygon(\n\t\tpoint,\n\t\tselectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation))\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAiBO;AACP,wBAAiC;AACjC,4CAA+C;AAC/C,iDAAuC;AACvC,qCAAwC;AACxC,kCAAqC;AACrC,2BAA2C;AAE3C,MAAM,gCAAgC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAErB,0BAAqC,CAAC;AAAA,EAE7B,UAAU;AAClB,SAAK,OAAO,qBAAqB,MAAS;AAC1C,0DAAqB,KAAK,MAAM;AAChC,SAAK,0BAA0B,CAAC;AAChC,SAAK,OAAO,UAAU,EAAE,MAAM,WAAW,UAAU,EAAE,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,qBAAqB;AACtD,MAAI,CAAC,kBAAmB,QAAO,gBAAgB,cAAc,KAAK;AAElE,aAAO;AAAA,IACN;AAAA,IACA,gBAAgB,QAAQ,IAAI,CAAC,MAAM,kBAAI,QAAQ,GAAG,gBAAgB,OAAO,iBAAiB,CAAC;AAAA,EAC5F;AACD;",
4
+ "sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLAdjacentDirection,\n\tTLClickEventInfo,\n\tTLKeyboardEventInfo,\n\tTLPointerEventInfo,\n\tTLShape,\n\tVec,\n\tVecLike,\n\tcreateShapeId,\n\tdebugFlags,\n\tkickoutOccludedShapes,\n\tpointInPolygon,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'\nimport { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'\nimport { getShouldEnterCropMode } from '../../selection-logic/getShouldEnterCropModeOnPointerDown'\nimport { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'\nimport { updateHoveredShapeId } from '../../selection-logic/updateHoveredShapeId'\nimport { startEditingShapeWithLabel } from '../selectHelpers'\n\nconst SKIPPED_KEYS_FOR_AUTO_EDITING = [\n\t'Delete',\n\t'Backspace',\n\t'[',\n\t']',\n\t'Enter',\n\t' ',\n\t'Shift',\n\t'Tab',\n]\n\nexport class Idle extends StateNode {\n\tstatic override id = 'idle'\n\n\tselectedShapesOnKeyDown: TLShape[] = []\n\n\toverride onEnter() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\t\tupdateHoveredShapeId(this.editor)\n\t\tthis.selectedShapesOnKeyDown = []\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\tupdateHoveredShapeId.cancel()\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateHoveredShapeId(this.editor)\n\t}\n\n\toverride onPointerDown(info: TLPointerEventInfo) {\n\t\tconst shouldEnterCropMode = info.ctrlKey && getShouldEnterCropMode(this.editor)\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\t// Check to see if we hit any shape under the pointer; if so,\n\t\t\t\t// handle this as a pointer down on the shape instead of the canvas\n\t\t\t\tconst hitShape = getHitShapeOnCanvasPointerDown(this.editor)\n\t\t\t\tif (hitShape && !hitShape.isLocked) {\n\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tif (this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\tthis.parent.transition('pointing_canvas', info)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tif (this.editor.inputs.altKey) {\n\t\t\t\t\tthis.parent.transition('pointing_shape', info)\n\t\t\t\t} else {\n\t\t\t\t\t// If we're holding ctrl key, we might select it, or start brushing...\n\t\t\t\t\tthis.parent.transition('pointing_handle', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tswitch (info.handle) {\n\t\t\t\t\tcase 'mobile_rotate':\n\t\t\t\t\tcase 'top_left_rotate':\n\t\t\t\t\tcase 'top_right_rotate':\n\t\t\t\t\tcase 'bottom_left_rotate':\n\t\t\t\t\tcase 'bottom_right_rotate': {\n\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.parent.transition('pointing_rotate_handle', info)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'top':\n\t\t\t\t\tcase 'right':\n\t\t\t\t\tcase 'bottom':\n\t\t\t\t\tcase 'left':\n\t\t\t\t\tcase 'top_left':\n\t\t\t\t\tcase 'top_right':\n\t\t\t\t\tcase 'bottom_left':\n\t\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\t\tif (shouldEnterCropMode) {\n\t\t\t\t\t\t\tthis.parent.transition('crop.pointing_crop_handle', info)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (info.accelKey) {\n\t\t\t\t\t\t\t\tthis.parent.transition('brushing', info)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.parent.transition('pointing_resize_handle', info)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thoveredShape &&\n\t\t\t\t\t\t\t!this.editor.getSelectedShapeIds().includes(hoveredShape.id) &&\n\t\t\t\t\t\t\t!hoveredShape.isLocked\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.onPointerDown({\n\t\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\t\tshape: hoveredShape,\n\t\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.parent.transition('pointing_selection', info)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\tif (this.editor.inputs.shiftKey || info.phase !== 'up') return\n\n\t\t// We don't want to double click while toggling shapes\n\t\tif (info.ctrlKey || info.shiftKey) return\n\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\n\t\t\t\t// todo\n\t\t\t\t// double clicking on the middle of a hollow geo shape without a label, or\n\t\t\t\t// over the label of a hollwo shape that has a label, should start editing\n\t\t\t\t// that shape's label. We can't support \"double click anywhere inside\"\n\t\t\t\t// of the shape yet because that also creates text shapes, and can produce\n\t\t\t\t// unexpected results when working \"inside of\" a hollow shape.\n\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: (this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint) ??\n\t\t\t\t\t\t\tthis.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t}))\n\n\t\t\t\tconst focusedGroupId = this.editor.getFocusedGroupId()\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tif (this.editor.isShapeOfType(hitShape, 'group')) {\n\t\t\t\t\t\t// Probably select the shape\n\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst parent = this.editor.getShape(hitShape.parentId)\n\t\t\t\t\t\tif (parent && this.editor.isShapeOfType(parent, 'group')) {\n\t\t\t\t\t\t\t// The shape is the direct child of a group. If the group is\n\t\t\t\t\t\t\t// selected, then we can select the shape. If the group is the\n\t\t\t\t\t\t\t// focus layer id, then we can double click into it as usual.\n\t\t\t\t\t\t\tif (focusedGroupId && parent.id === focusedGroupId) {\n\t\t\t\t\t\t\t\t// noop, double click on the shape as normal below\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// The shape is the child of some group other than our current\n\t\t\t\t\t\t\t\t// focus layer. We should probably select the group instead.\n\t\t\t\t\t\t\t\tselectOnCanvasPointerUp(this.editor, info)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// double click on the shape. We'll start editing the\n\t\t\t\t\t// shape if it's editable or else do a double click on\n\t\t\t\t\t// the canvas.\n\t\t\t\t\tthis.onDoubleClick({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (!this.editor.inputs.shiftKey) {\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selection': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\n\t\t\t\tif (onlySelectedShape) {\n\t\t\t\t\tconst util = this.editor.getShapeUtil(onlySelectedShape)\n\n\t\t\t\t\tif (!this.canInteractWithShapeInReadOnly(onlySelectedShape)) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// Test edges for an onDoubleClickEdge handler\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'right' ||\n\t\t\t\t\t\tinfo.handle === 'left' ||\n\t\t\t\t\t\tinfo.handle === 'top' ||\n\t\t\t\t\t\tinfo.handle === 'bottom'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickEdge?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click edge')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tinfo.handle === 'top_left' ||\n\t\t\t\t\t\tinfo.handle === 'top_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_right' ||\n\t\t\t\t\t\tinfo.handle === 'bottom_left'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst change = util.onDoubleClickCorner?.(onlySelectedShape, info)\n\t\t\t\t\t\tif (change) {\n\t\t\t\t\t\t\tthis.editor.markHistoryStoppingPoint('double click corner')\n\t\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\t\tkickoutOccludedShapes(this.editor, [onlySelectedShape.id])\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// For corners OR edges but NOT rotation corners\n\t\t\t\t\tif (\n\t\t\t\t\t\tutil.canCrop(onlySelectedShape) &&\n\t\t\t\t\t\t!this.editor.isShapeOrAncestorLocked(onlySelectedShape)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\t\tthis.startEditingShape(onlySelectedShape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { shape } = info\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\n\t\t\t\t// Allow playing videos and embeds\n\t\t\t\tif (shape.type !== 'video' && shape.type !== 'embed' && this.editor.getIsReadonly()) break\n\n\t\t\t\tif (util.onDoubleClick) {\n\t\t\t\t\t// Call the shape's double click handler\n\t\t\t\t\tconst change = util.onDoubleClick?.(shape)\n\t\t\t\t\tif (change) {\n\t\t\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (util.canCrop(shape) && !this.editor.isShapeOrAncestorLocked(shape)) {\n\t\t\t\t\t// crop image etc on double click\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('select and crop')\n\t\t\t\t\tthis.editor.select(info.shape?.id)\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the shape can edit, then begin editing\n\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape cannot edit, then create a text shape and\n\t\t\t\t\t// begin editing the text shape\n\t\t\t\t\tthis.handleDoubleClickOnCanvas(info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'handle': {\n\t\t\t\tif (this.editor.getIsReadonly()) break\n\t\t\t\tconst { shape, handle } = info\n\n\t\t\t\tconst util = this.editor.getShapeUtil(shape)\n\t\t\t\tconst changes = util.onDoubleClickHandle?.(shape, handle)\n\n\t\t\t\tif (changes) {\n\t\t\t\t\tthis.editor.updateShapes([changes])\n\t\t\t\t} else {\n\t\t\t\t\t// If the shape's double click handler has not created a change,\n\t\t\t\t\t// and if the shape can edit, then begin editing the shape.\n\t\t\t\t\tif (this.shouldStartEditingShape(shape)) {\n\t\t\t\t\t\tthis.startEditingShape(shape, info, true /* select all */)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onRightClick(info: TLPointerEventInfo) {\n\t\tswitch (info.target) {\n\t\t\tcase 'canvas': {\n\t\t\t\tconst hoveredShape = this.editor.getHoveredShape()\n\t\t\t\tconst hitShape =\n\t\t\t\t\thoveredShape && !this.editor.isShapeOfType(hoveredShape, 'group')\n\t\t\t\t\t\t? hoveredShape\n\t\t\t\t\t\t: this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint, {\n\t\t\t\t\t\t\t\tmargin: this.editor.options.hitTestMargin / this.editor.getZoomLevel(),\n\t\t\t\t\t\t\t\thitInside: false,\n\t\t\t\t\t\t\t\thitLabels: true,\n\t\t\t\t\t\t\t\thitLocked: true,\n\t\t\t\t\t\t\t\thitFrameInside: true,\n\t\t\t\t\t\t\t\trenderingOnly: true,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tif (hitShape) {\n\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t...info,\n\t\t\t\t\t\tshape: hitShape,\n\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tconst {\n\t\t\t\t\tinputs: { currentPagePoint },\n\t\t\t\t} = this.editor\n\n\t\t\t\tif (\n\t\t\t\t\tselectedShapeIds.length > 1 ||\n\t\t\t\t\t(onlySelectedShape &&\n\t\t\t\t\t\t!this.editor.getShapeUtil(onlySelectedShape).hideSelectionBoundsBg(onlySelectedShape))\n\t\t\t\t) {\n\t\t\t\t\tif (isPointInRotatedSelectionBounds(this.editor, currentPagePoint)) {\n\t\t\t\t\t\tthis.onRightClick({\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.editor.selectNone()\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'shape': {\n\t\t\t\tconst { selectedShapeIds } = this.editor.getCurrentPageState()\n\t\t\t\tconst { shape } = info\n\n\t\t\t\tconst targetShape = this.editor.getOutermostSelectableShape(\n\t\t\t\t\tshape,\n\t\t\t\t\t(parent) => !selectedShapeIds.includes(parent.id)\n\t\t\t\t)\n\n\t\t\t\tif (\n\t\t\t\t\t!selectedShapeIds.includes(targetShape.id) &&\n\t\t\t\t\t!this.editor.findShapeAncestor(targetShape, (shape) =>\n\t\t\t\t\t\tselectedShapeIds.includes(shape.id)\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthis.editor.markHistoryStoppingPoint('selecting shape')\n\t\t\t\t\tthis.editor.setSelectedShapes([targetShape.id])\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tif (\n\t\t\tthis.editor.getFocusedGroupId() !== this.editor.getCurrentPageId() &&\n\t\t\tthis.editor.getSelectedShapeIds().length > 0\n\t\t) {\n\t\t\tthis.editor.popFocusedGroupId()\n\t\t} else {\n\t\t\tthis.editor.markHistoryStoppingPoint('clearing selection')\n\t\t\tthis.editor.selectNone()\n\t\t}\n\t}\n\n\toverride onKeyDown(info: TLKeyboardEventInfo) {\n\t\tthis.selectedShapesOnKeyDown = this.editor.getSelectedShapes()\n\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tif (info.shiftKey) {\n\t\t\t\t\t\tif (info.code === 'ArrowDown') {\n\t\t\t\t\t\t\tthis.editor.selectFirstChildShape()\n\t\t\t\t\t\t} else if (info.code === 'ArrowUp') {\n\t\t\t\t\t\t\tthis.editor.selectParentShape()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(false)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (debugFlags['editOnType'].get()) {\n\t\t\t// This feature flag lets us start editing a note shape's label when a key is pressed.\n\t\t\t// We exclude certain keys to avoid conflicting with modifiers, but there are conflicts\n\t\t\t// with other action kbds, hence why this is kept behind a feature flag.\n\t\t\tif (!SKIPPED_KEYS_FOR_AUTO_EDITING.includes(info.key) && !info.altKey && !info.ctrlKey) {\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (\n\t\t\t\t\tonlySelectedShape &&\n\t\t\t\t\t// If it's a note shape, then edit on type\n\t\t\t\t\tthis.editor.isShapeOfType(onlySelectedShape, 'note') &&\n\t\t\t\t\t// If it's not locked or anything\n\t\t\t\t\tthis.shouldStartEditingShape(onlySelectedShape)\n\t\t\t\t) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyRepeat(info: TLKeyboardEventInfo) {\n\t\tswitch (info.code) {\n\t\t\tcase 'ArrowLeft':\n\t\t\tcase 'ArrowRight':\n\t\t\tcase 'ArrowUp':\n\t\t\tcase 'ArrowDown': {\n\t\t\t\tif (info.accelKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(\n\t\t\t\t\t\tinfo.code.replace('Arrow', '').toLowerCase() as TLAdjacentDirection\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.nudgeSelectedShapes(true)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\toverride onKeyUp(info: TLKeyboardEventInfo) {\n\t\tswitch (info.key) {\n\t\t\tcase 'Enter': {\n\t\t\t\t// Because Enter onKeyDown can happen outside the canvas (but then focus the canvas potentially),\n\t\t\t\t// we need to check if the canvas was initially selecting something before continuing.\n\t\t\t\tif (!this.selectedShapesOnKeyDown.length) return\n\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\n\t\t\t\t// On enter, if every selected shape is a group, then select all of the children of the groups\n\t\t\t\tif (selectedShapes.every((shape) => this.editor.isShapeOfType(shape, 'group'))) {\n\t\t\t\t\tthis.editor.setSelectedShapes(\n\t\t\t\t\t\tselectedShapes.flatMap((shape) => this.editor.getSortedChildIdsForParent(shape.id))\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is editable, then begin editing it\n\t\t\t\tconst onlySelectedShape = this.editor.getOnlySelectedShape()\n\t\t\t\tif (onlySelectedShape && this.shouldStartEditingShape(onlySelectedShape)) {\n\t\t\t\t\tthis.startEditingShape(\n\t\t\t\t\t\tonlySelectedShape,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...info,\n\t\t\t\t\t\t\ttarget: 'shape',\n\t\t\t\t\t\t\tshape: onlySelectedShape,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue /* select all */\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// If the only selected shape is croppable, then begin cropping it\n\t\t\t\tif (getShouldEnterCropMode(this.editor)) {\n\t\t\t\t\tthis.parent.transition('crop', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'Tab': {\n\t\t\t\tconst selectedShapes = this.editor.getSelectedShapes()\n\t\t\t\tif (selectedShapes.length && !info.altKey) {\n\t\t\t\t\tthis.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate shouldStartEditingShape(\n\t\tshape: TLShape | null = this.editor.getOnlySelectedShape()\n\t): boolean {\n\t\tif (!shape) return false\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return false\n\t\tif (!this.canInteractWithShapeInReadOnly(shape)) return false\n\t\treturn this.editor.getShapeUtil(shape).canEdit(shape)\n\t}\n\n\tprivate startEditingShape(\n\t\tshape: TLShape,\n\t\tinfo: TLClickEventInfo | TLKeyboardEventInfo,\n\t\tshouldSelectAll?: boolean\n\t) {\n\t\tif (this.editor.isShapeOrAncestorLocked(shape) && shape.type !== 'embed') return\n\t\tthis.editor.markHistoryStoppingPoint('editing shape')\n\t\tstartEditingShapeWithLabel(this.editor, shape, shouldSelectAll)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tisOverArrowLabelTest(shape: TLShape | undefined) {\n\t\tif (!shape) return false\n\n\t\treturn isOverArrowLabel(this.editor, shape)\n\t}\n\n\thandleDoubleClickOnCanvas(info: TLClickEventInfo) {\n\t\t// Create text shape and transition to editing_shape\n\t\tif (this.editor.getIsReadonly()) return\n\n\t\tif (!this.editor.options.createTextOnCanvasDoubleClick) return\n\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\n\t\tconst id = createShapeId()\n\n\t\tconst { x, y } = this.editor.inputs.currentPagePoint\n\n\t\t// Allow this to trigger the max shapes reached alert\n\t\tthis.editor.createShapes([\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype: 'text',\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\tprops: {\n\t\t\t\t\trichText: toRichText(''),\n\t\t\t\t\tautoSize: true,\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\n\t\tconst shape = this.editor.getShape(id)\n\t\tif (!shape) return\n\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (this.editor.getIsReadonly()) {\n\t\t\tif (!util.canEditInReadonly(shape)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.editor.setEditingShape(id)\n\t\tthis.editor.select(id)\n\t\tthis.parent.transition('editing_shape', info)\n\t}\n\n\tprivate nudgeSelectedShapes(ephemeral = false) {\n\t\tconst {\n\t\t\teditor: {\n\t\t\t\tinputs: { keys },\n\t\t\t},\n\t\t} = this\n\n\t\t// We want to use the \"actual\" shift key state,\n\t\t// not the one that's in the editor.inputs.shiftKey,\n\t\t// because that one uses a short timeout on release\n\t\tconst shiftKey = keys.has('ShiftLeft')\n\n\t\tconst delta = new Vec(0, 0)\n\n\t\tif (keys.has('ArrowLeft')) delta.x -= 1\n\t\tif (keys.has('ArrowRight')) delta.x += 1\n\t\tif (keys.has('ArrowUp')) delta.y -= 1\n\t\tif (keys.has('ArrowDown')) delta.y += 1\n\n\t\tif (delta.equals(new Vec(0, 0))) return\n\n\t\tif (!ephemeral) this.editor.markHistoryStoppingPoint('nudge shapes')\n\n\t\tconst { gridSize } = this.editor.getDocumentSettings()\n\n\t\tconst step = this.editor.getInstanceState().isGridMode\n\t\t\t? shiftKey\n\t\t\t\t? gridSize * GRID_INCREMENT\n\t\t\t\t: gridSize\n\t\t\t: shiftKey\n\t\t\t\t? MAJOR_NUDGE_FACTOR\n\t\t\t\t: MINOR_NUDGE_FACTOR\n\n\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\tthis.editor.nudgeShapes(selectedShapeIds, delta.mul(step))\n\t\tkickoutOccludedShapes(this.editor, selectedShapeIds)\n\t}\n\n\tprivate canInteractWithShapeInReadOnly(shape: TLShape) {\n\t\tif (!this.editor.getIsReadonly()) return true\n\t\tconst util = this.editor.getShapeUtil(shape)\n\t\tif (util.canEditInReadonly(shape)) return true\n\t\treturn false\n\t}\n}\n\nexport const MAJOR_NUDGE_FACTOR = 10\nexport const MINOR_NUDGE_FACTOR = 1\nexport const GRID_INCREMENT = 5\n\nfunction isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) {\n\tconst selectionBounds = editor.getSelectionRotatedPageBounds()\n\tif (!selectionBounds) return false\n\n\tconst selectionRotation = editor.getSelectionRotation()\n\tif (!selectionRotation) return selectionBounds.containsPoint(point)\n\n\treturn pointInPolygon(\n\t\tpoint,\n\t\tselectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation))\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAeO;AACP,wBAAiC;AACjC,4CAA+C;AAC/C,iDAAuC;AACvC,qCAAwC;AACxC,kCAAqC;AACrC,2BAA2C;AAE3C,MAAM,gCAAgC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,aAAa,wBAAU;AAAA,EACnC,OAAgB,KAAK;AAAA,EAErB,0BAAqC,CAAC;AAAA,EAE7B,UAAU;AAClB,SAAK,OAAO,qBAAqB,MAAS;AAC1C,0DAAqB,KAAK,MAAM;AAChC,SAAK,0BAA0B,CAAC;AAChC,SAAK,OAAO,U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AAO;AAE7B,QAAM,oBAAoB,OAAO,qBAAqB;AACtD,MAAI,CAAC,kBAAmB,QAAO,gBAAgB,cAAc,KAAK;AAElE,aAAO;AAAA,IACN;AAAA,IACA,gBAAgB,QAAQ,IAAI,CAAC,MAAM,kBAAI,QAAQ,GAAG,gBAAgB,OAAO,iBAAiB,CAAC;AAAA,EAC5F;AACD;",
6
6
  "names": ["shape"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts"],
4
- "sourcesContent": ["import {\n\tGroup2d,\n\tStateNode,\n\tTLArrowShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tVec,\n} from '@tldraw/editor'\nimport { ArrowShapeUtil } from '../../../shapes/arrow/ArrowShapeUtil'\nimport {\n\tgetArrowBodyGeometry,\n\tgetArrowLabelDefaultPosition,\n} from '../../../shapes/arrow/arrowLabel'\n\nexport class PointingArrowLabel extends StateNode {\n\tstatic override id = 'pointing_arrow_label'\n\n\tshapeId = '' as TLShapeId\n\tmarkId = ''\n\twasAlreadySelected = false\n\tdidDrag = false\n\tdidCtrlOnEnter = false\n\n\tprivate info = {} as TLPointerEventInfo & {\n\t\tshape: TLArrowShape\n\t\tonInteractionEnd?: string | (() => void)\n\t\tisCreating: boolean\n\t}\n\n\tprivate updateCursor() {\n\t\tthis.editor.setCursor({ type: 'grabbing', rotation: 0 })\n\t}\n\n\toverride onEnter(\n\t\tinfo: TLPointerEventInfo & {\n\t\t\tshape: TLArrowShape\n\t\t\tonInteractionEnd?: string | (() => void)\n\t\t\tisCreating: boolean\n\t\t}\n\t) {\n\t\tconst { shape } = info\n\t\tif (typeof info.onInteractionEnd === 'string') {\n\t\t\tthis.parent.setCurrentToolIdMask(info.onInteractionEnd)\n\t\t}\n\t\tthis.info = info\n\t\tthis.shapeId = shape.id\n\t\tthis.didDrag = false\n\t\tthis.didCtrlOnEnter = info.accelKey\n\t\tthis.wasAlreadySelected = this.editor.getOnlySelectedShapeId() === shape.id\n\t\tthis.updateCursor()\n\n\t\tconst geometry = this.editor.getShapeGeometry<Group2d>(shape)\n\t\tconst labelGeometry = geometry.children[1]\n\t\tif (!labelGeometry) {\n\t\t\tthrow Error(`Expected to find an arrow label geometry for shape: ${shape.id}`)\n\t\t}\n\t\tconst { currentPagePoint } = this.editor.inputs\n\t\tconst pointInShapeSpace = this.editor.getPointInShapeSpace(shape, currentPagePoint)\n\n\t\tthis._labelDragOffset = Vec.Sub(labelGeometry.center, pointInShapeSpace)\n\n\t\tthis.markId = this.editor.markHistoryStoppingPoint('label-drag start')\n\n\t\tconst additiveSelectionKey = info.shiftKey || info.accelKey\n\t\tif (additiveSelectionKey) {\n\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\tthis.editor.setSelectedShapes([...selectedShapeIds, this.shapeId])\n\n\t\t\treturn\n\t\t}\n\n\t\tthis.editor.setSelectedShapes([this.shapeId])\n\t}\n\n\toverride onExit() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\tprivate _labelDragOffset = new Vec(0, 0)\n\n\toverride onPointerMove() {\n\t\tconst { isDragging } = this.editor.inputs\n\t\tif (!isDragging) return\n\n\t\tif (this.didCtrlOnEnter) {\n\t\t\tthis.parent.transition('brushing', this.info)\n\t\t\treturn\n\t\t}\n\n\t\tconst shape = this.editor.getShape<TLArrowShape>(this.shapeId)\n\t\tif (!shape) return\n\n\t\tconst options = this.editor.getShapeUtil<ArrowShapeUtil>('arrow').options\n\t\tconst geometry = getArrowBodyGeometry(this.editor, shape)\n\t\tconst transform = this.editor.getShapePageTransform(shape.id)\n\n\t\tconst pointInShapeSpace = this.editor\n\t\t\t.getPointInShapeSpace(shape, this.editor.inputs.currentPagePoint)\n\t\t\t.add(this._labelDragOffset)\n\n\t\tconst defaultLabelPosition = getArrowLabelDefaultPosition(this.editor, shape)\n\n\t\tlet nextLabelPosition = geometry.uninterpolateAlongEdge(pointInShapeSpace)\n\n\t\tif (isNaN(nextLabelPosition)) {\n\t\t\tnextLabelPosition = defaultLabelPosition\n\t\t}\n\n\t\tconst nextLabelPoint = transform.applyToPoint(geometry.interpolateAlongEdge(nextLabelPosition))\n\t\tconst labelDefaultPoint = transform.applyToPoint(\n\t\t\tgeometry.interpolateAlongEdge(defaultLabelPosition)\n\t\t)\n\n\t\tif (\n\t\t\tVec.DistMin(\n\t\t\t\tnextLabelPoint,\n\t\t\t\tlabelDefaultPoint,\n\t\t\t\toptions.labelCenterSnapDistance / this.editor.getZoomLevel()\n\t\t\t)\n\t\t) {\n\t\t\tnextLabelPosition = defaultLabelPosition\n\t\t}\n\n\t\tthis.didDrag = true\n\t\tthis.editor.updateShape<TLArrowShape>({\n\t\t\tid: shape.id,\n\t\t\ttype: shape.type,\n\t\t\tprops: { labelPosition: nextLabelPosition },\n\t\t})\n\t}\n\n\toverride onPointerUp() {\n\t\tconst shape = this.editor.getShape<TLArrowShape>(this.shapeId)\n\t\tif (!shape) return\n\n\t\tif (this.didDrag || !this.wasAlreadySelected) {\n\t\t\tthis.complete()\n\t\t} else if (!this.editor.getIsReadonly()) {\n\t\t\t// Go into edit mode.\n\t\t\tthis.editor.setEditingShape(shape.id)\n\t\t\tthis.editor.setCurrentTool('select.editing_shape')\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, {})\n\t\t\t} else {\n\t\t\t\tonInteractionEnd()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.bailToMark(this.markId)\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, {})\n\t\t\t} else {\n\t\t\t\tonInteractionEnd()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAOO;AAEP,wBAGO;AAEA,MAAM,2BAA2B,wBAAU;AAAA,EACjD,OAAgB,KAAK;AAAA,EAErB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,qBAAqB;AAAA,EACrB,UAAU;AAAA,EACV,iBAAiB;AAAA,EAET,OAAO,CAAC;AAAA,EAMR,eAAe;AACtB,SAAK,OAAO,UAAU,EAAE,MAAM,YAAY,UAAU,EAAE,CAAC;AAAA,EACxD;AAAA,EAES,QACR,MAKC;AACD,UAAM,EAAE,MAAM,IAAI;AAClB,QAAI,OAAO,KAAK,qBAAqB,UAAU;AAC9C,WAAK,OAAO,qBAAqB,KAAK,gBAAgB;AAAA,IACvD;AACA,SAAK,OAAO;AACZ,SAAK,UAAU,MAAM;AACrB,SAAK,UAAU;AACf,SAAK,iBAAiB,KAAK;AAC3B,SAAK,qBAAqB,KAAK,OAAO,uBAAuB,MAAM,MAAM;AACzE,SAAK,aAAa;AAElB,UAAM,WAAW,KAAK,OAAO,iBAA0B,KAAK;AAC5D,UAAM,gBAAgB,SAAS,SAAS,CAAC;AACzC,QAAI,CAAC,eAAe;AACnB,YAAM,MAAM,uDAAuD,MAAM,EAAE,EAAE;AAAA,IAC9E;AACA,UAAM,EAAE,iBAAiB,IAAI,KAAK,OAAO;AACzC,UAAM,oBAAoB,KAAK,OAAO,qBAAqB,OAAO,gBAAgB;AAElF,SAAK,mBAAmB,kBAAI,IAAI,cAAc,QAAQ,iBAAiB;AAEvE,SAAK,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A,IACD;AACA,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AACD;",
4
+ "sourcesContent": ["import {\n\tGroup2d,\n\tStateNode,\n\tTLArrowShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tVec,\n} from '@tldraw/editor'\nimport { ArrowShapeUtil } from '../../../shapes/arrow/ArrowShapeUtil'\nimport {\n\tgetArrowBodyGeometry,\n\tgetArrowLabelDefaultPosition,\n} from '../../../shapes/arrow/arrowLabel'\n\nexport class PointingArrowLabel extends StateNode {\n\tstatic override id = 'pointing_arrow_label'\n\n\tshapeId = '' as TLShapeId\n\tmarkId = ''\n\twasAlreadySelected = false\n\tdidDrag = false\n\tdidCtrlOnEnter = false\n\n\tprivate info = {} as TLPointerEventInfo & {\n\t\tshape: TLArrowShape\n\t\tonInteractionEnd?: string | (() => void)\n\t\tisCreating: boolean\n\t}\n\n\tprivate updateCursor() {\n\t\tthis.editor.setCursor({ type: 'grabbing', rotation: 0 })\n\t}\n\n\toverride onEnter(\n\t\tinfo: TLPointerEventInfo & {\n\t\t\tshape: TLArrowShape\n\t\t\tonInteractionEnd?: string | (() => void)\n\t\t\tisCreating: boolean\n\t\t}\n\t) {\n\t\tconst { shape } = info\n\t\tif (typeof info.onInteractionEnd === 'string') {\n\t\t\tthis.parent.setCurrentToolIdMask(info.onInteractionEnd)\n\t\t}\n\t\tthis.info = info\n\t\tthis.shapeId = shape.id\n\t\tthis.didDrag = false\n\t\tthis.didCtrlOnEnter = info.accelKey\n\t\tthis.wasAlreadySelected = this.editor.getOnlySelectedShapeId() === shape.id\n\t\tthis.updateCursor()\n\n\t\tconst geometry = this.editor.getShapeGeometry<Group2d>(shape)\n\t\tconst labelGeometry = geometry.children[1]\n\t\tif (!labelGeometry) {\n\t\t\tthrow Error(`Expected to find an arrow label geometry for shape: ${shape.id}`)\n\t\t}\n\t\tconst { currentPagePoint } = this.editor.inputs\n\t\tconst pointInShapeSpace = this.editor.getPointInShapeSpace(shape, currentPagePoint)\n\n\t\tthis._labelDragOffset = Vec.Sub(labelGeometry.center, pointInShapeSpace)\n\n\t\tthis.markId = this.editor.markHistoryStoppingPoint('label-drag start')\n\n\t\tconst additiveSelectionKey = info.shiftKey || info.accelKey\n\t\tif (additiveSelectionKey) {\n\t\t\tconst selectedShapeIds = this.editor.getSelectedShapeIds()\n\t\t\tthis.editor.setSelectedShapes([...selectedShapeIds, this.shapeId])\n\n\t\t\treturn\n\t\t}\n\n\t\tthis.editor.setSelectedShapes([this.shapeId])\n\t}\n\n\toverride onExit() {\n\t\tthis.parent.setCurrentToolIdMask(undefined)\n\n\t\tthis.editor.setCursor({ type: 'default', rotation: 0 })\n\t}\n\n\tprivate _labelDragOffset = new Vec(0, 0)\n\n\toverride onPointerMove() {\n\t\tconst { isDragging } = this.editor.inputs\n\t\tif (!isDragging) return\n\n\t\tif (this.didCtrlOnEnter) {\n\t\t\tthis.parent.transition('brushing', this.info)\n\t\t\treturn\n\t\t}\n\n\t\tconst shape = this.editor.getShape<TLArrowShape>(this.shapeId)\n\t\tif (!shape) return\n\n\t\tconst options = this.editor.getShapeUtil<ArrowShapeUtil>('arrow').options\n\t\tconst geometry = getArrowBodyGeometry(this.editor, shape)\n\t\tconst transform = this.editor.getShapePageTransform(shape.id)\n\n\t\tconst pointInShapeSpace = this.editor\n\t\t\t.getPointInShapeSpace(shape, this.editor.inputs.currentPagePoint)\n\t\t\t.add(this._labelDragOffset)\n\n\t\tconst defaultLabelPosition = getArrowLabelDefaultPosition(this.editor, shape)\n\n\t\tlet nextLabelPosition = geometry.uninterpolateAlongEdge(pointInShapeSpace)\n\n\t\tif (isNaN(nextLabelPosition)) {\n\t\t\tnextLabelPosition = defaultLabelPosition\n\t\t}\n\n\t\tconst nextLabelPoint = transform.applyToPoint(geometry.interpolateAlongEdge(nextLabelPosition))\n\t\tconst labelDefaultPoint = transform.applyToPoint(\n\t\t\tgeometry.interpolateAlongEdge(defaultLabelPosition)\n\t\t)\n\n\t\tif (\n\t\t\tVec.DistMin(\n\t\t\t\tnextLabelPoint,\n\t\t\t\tlabelDefaultPoint,\n\t\t\t\toptions.labelCenterSnapDistance / this.editor.getZoomLevel()\n\t\t\t)\n\t\t) {\n\t\t\tnextLabelPosition = defaultLabelPosition\n\t\t}\n\n\t\tthis.didDrag = true\n\t\tthis.editor.updateShape({\n\t\t\tid: shape.id,\n\t\t\ttype: shape.type,\n\t\t\tprops: { labelPosition: nextLabelPosition },\n\t\t})\n\t}\n\n\toverride onPointerUp() {\n\t\tconst shape = this.editor.getShape<TLArrowShape>(this.shapeId)\n\t\tif (!shape) return\n\n\t\tif (this.didDrag || !this.wasAlreadySelected) {\n\t\t\tthis.complete()\n\t\t} else if (!this.editor.getIsReadonly()) {\n\t\t\t// Go into edit mode.\n\t\t\tthis.editor.setEditingShape(shape.id)\n\t\t\tthis.editor.setCurrentTool('select.editing_shape')\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, {})\n\t\t\t} else {\n\t\t\t\tonInteractionEnd()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.bailToMark(this.markId)\n\n\t\tconst { onInteractionEnd } = this.info\n\t\tif (onInteractionEnd) {\n\t\t\tif (typeof onInteractionEnd === 'string') {\n\t\t\t\tthis.editor.setCurrentTool(onInteractionEnd, {})\n\t\t\t} else {\n\t\t\t\tonInteractionEnd()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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