@tldraw/editor 3.16.0-canary.bcde131f3274 → 3.16.0-canary.bf7be9dad88b

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 (134) hide show
  1. package/dist-cjs/index.d.ts +83 -104
  2. package/dist-cjs/index.js +6 -6
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +2 -6
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +11 -1
  7. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +23 -113
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
  11. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +4 -2
  13. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +10 -0
  15. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  16. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  17. package/dist-cjs/lib/hooks/useCanvasEvents.js +15 -12
  18. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  19. package/dist-cjs/lib/hooks/useDocumentEvents.js +5 -5
  20. package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
  21. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -2
  22. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
  23. package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
  24. package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
  25. package/dist-cjs/lib/hooks/useHandleEvents.js +3 -3
  26. package/dist-cjs/lib/hooks/useHandleEvents.js.map +2 -2
  27. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  28. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  29. package/dist-cjs/lib/hooks/useSelectionEvents.js +4 -4
  30. package/dist-cjs/lib/hooks/useSelectionEvents.js.map +2 -2
  31. package/dist-cjs/lib/license/LicenseManager.js +143 -53
  32. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  33. package/dist-cjs/lib/license/LicenseProvider.js +39 -1
  34. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  35. package/dist-cjs/lib/license/Watermark.js +143 -75
  36. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  37. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  38. package/dist-cjs/lib/primitives/Vec.js +0 -4
  39. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  40. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
  41. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  42. package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
  43. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  44. package/dist-cjs/lib/utils/dom.js +12 -1
  45. package/dist-cjs/lib/utils/dom.js.map +2 -2
  46. package/dist-cjs/lib/utils/getPointerInfo.js +2 -2
  47. package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
  48. package/dist-cjs/lib/utils/reparenting.js +2 -35
  49. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  50. package/dist-cjs/version.js +3 -3
  51. package/dist-cjs/version.js.map +1 -1
  52. package/dist-esm/index.d.mts +83 -104
  53. package/dist-esm/index.mjs +9 -7
  54. package/dist-esm/index.mjs.map +2 -2
  55. package/dist-esm/lib/TldrawEditor.mjs +3 -7
  56. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  57. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +12 -2
  58. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  59. package/dist-esm/lib/editor/Editor.mjs +23 -113
  60. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  61. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
  62. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  63. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +4 -2
  64. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
  65. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +10 -0
  66. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  67. package/dist-esm/lib/hooks/useCanvasEvents.mjs +17 -13
  68. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  69. package/dist-esm/lib/hooks/useDocumentEvents.mjs +11 -6
  70. package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
  71. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +2 -3
  72. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
  73. package/dist-esm/lib/hooks/useGestureEvents.mjs +2 -2
  74. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
  75. package/dist-esm/lib/hooks/useHandleEvents.mjs +9 -4
  76. package/dist-esm/lib/hooks/useHandleEvents.mjs.map +2 -2
  77. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  78. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  79. package/dist-esm/lib/hooks/useSelectionEvents.mjs +6 -5
  80. package/dist-esm/lib/hooks/useSelectionEvents.mjs.map +2 -2
  81. package/dist-esm/lib/license/LicenseManager.mjs +144 -54
  82. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  83. package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
  84. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  85. package/dist-esm/lib/license/Watermark.mjs +144 -76
  86. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  87. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  88. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  89. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  90. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
  91. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  92. package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
  93. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  94. package/dist-esm/lib/utils/dom.mjs +12 -1
  95. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  96. package/dist-esm/lib/utils/getPointerInfo.mjs +2 -2
  97. package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
  98. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  99. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  100. package/dist-esm/version.mjs +3 -3
  101. package/dist-esm/version.mjs.map +1 -1
  102. package/editor.css +8 -3
  103. package/package.json +7 -7
  104. package/src/index.ts +4 -9
  105. package/src/lib/TldrawEditor.tsx +3 -15
  106. package/src/lib/components/default-components/DefaultCanvas.tsx +8 -2
  107. package/src/lib/editor/Editor.test.ts +90 -0
  108. package/src/lib/editor/Editor.ts +36 -150
  109. package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
  110. package/src/lib/editor/managers/FocusManager/FocusManager.ts +6 -2
  111. package/src/lib/editor/shapes/ShapeUtil.ts +32 -0
  112. package/src/lib/editor/types/misc-types.ts +0 -6
  113. package/src/lib/hooks/useCanvasEvents.ts +17 -11
  114. package/src/lib/hooks/useDocumentEvents.ts +11 -6
  115. package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +2 -2
  116. package/src/lib/hooks/useGestureEvents.ts +2 -2
  117. package/src/lib/hooks/useHandleEvents.ts +9 -4
  118. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  119. package/src/lib/hooks/useSelectionEvents.ts +6 -5
  120. package/src/lib/license/LicenseManager.test.ts +721 -382
  121. package/src/lib/license/LicenseManager.ts +204 -58
  122. package/src/lib/license/LicenseProvider.tsx +74 -2
  123. package/src/lib/license/Watermark.tsx +151 -77
  124. package/src/lib/license/useLicenseManagerState.ts +2 -2
  125. package/src/lib/primitives/Vec.ts +0 -5
  126. package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
  127. package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
  128. package/src/lib/primitives/geometry/Group2d.ts +10 -1
  129. package/src/lib/test/InFrontOfTheCanvas.test.tsx +187 -0
  130. package/src/lib/utils/dom.test.ts +94 -0
  131. package/src/lib/utils/dom.ts +38 -1
  132. package/src/lib/utils/getPointerInfo.ts +2 -1
  133. package/src/lib/utils/reparenting.ts +3 -69
  134. package/src/version.ts +3 -3
@@ -18,16 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var reparenting_exports = {};
20
20
  __export(reparenting_exports, {
21
- doesGeometryOverlapPolygon: () => doesGeometryOverlapPolygon,
22
21
  getDroppedShapesToNewParents: () => getDroppedShapesToNewParents,
23
22
  kickoutOccludedShapes: () => kickoutOccludedShapes
24
23
  });
25
24
  module.exports = __toCommonJS(reparenting_exports);
26
25
  var import_state = require("@tldraw/state");
27
26
  var import_utils = require("@tldraw/utils");
28
- var import_Group2d = require("../primitives/geometry/Group2d");
29
27
  var import_intersect = require("../primitives/intersect");
30
- var import_utils2 = require("../primitives/utils");
31
28
  function kickoutOccludedShapes(editor, shapeIds, opts) {
32
29
  const parentsToCheck = /* @__PURE__ */ new Set();
33
30
  for (const id of shapeIds) {
@@ -123,39 +120,9 @@ function getOverlappingShapes(editor, shape, otherShapes) {
123
120
  if (!shapePageBounds || !parentPageBounds.includes(shapePageBounds)) return false;
124
121
  const parentPolygonInShapeShape = editor.getShapePageTransform(childId).clone().invert().applyToPoints(parentPagePolygon);
125
122
  const geometry = editor.getShapeGeometry(childId);
126
- return doesGeometryOverlapPolygon(geometry, parentPolygonInShapeShape);
123
+ return geometry.overlapsPolygon(parentPolygonInShapeShape);
127
124
  });
128
125
  }
129
- function doesGeometryOverlapPolygon(geometry, parentCornersInShapeSpace) {
130
- if (geometry instanceof import_Group2d.Group2d) {
131
- return geometry.children.some(
132
- (childGeometry) => doesGeometryOverlapPolygon(childGeometry, parentCornersInShapeSpace)
133
- );
134
- }
135
- const { vertices, center, isFilled, isEmptyLabel, isClosed } = geometry;
136
- if (isEmptyLabel) return false;
137
- if (vertices.some((v) => (0, import_utils2.pointInPolygon)(v, parentCornersInShapeSpace))) {
138
- return true;
139
- }
140
- if (isClosed) {
141
- if (isFilled) {
142
- if ((0, import_utils2.pointInPolygon)(center, parentCornersInShapeSpace)) {
143
- return true;
144
- }
145
- if (parentCornersInShapeSpace.every((v) => (0, import_utils2.pointInPolygon)(v, vertices))) {
146
- return true;
147
- }
148
- }
149
- if ((0, import_intersect.polygonsIntersect)(parentCornersInShapeSpace, vertices)) {
150
- return true;
151
- }
152
- } else {
153
- if ((0, import_intersect.polygonIntersectsPolyline)(parentCornersInShapeSpace, vertices)) {
154
- return true;
155
- }
156
- }
157
- return false;
158
- }
159
126
  function getDroppedShapesToNewParents(editor, shapes, cb) {
160
127
  const shapesToActuallyCheck = new Set(shapes);
161
128
  const movingGroups = /* @__PURE__ */ new Set();
@@ -208,7 +175,7 @@ function getDroppedShapesToNewParents(editor, shapes, cb) {
208
175
  if (shapeGroupId !== parentShapeContainingGroupId) continue shapeCheck;
209
176
  if (editor.findShapeAncestor(parentShape, (s) => shape.id === s.id)) continue shapeCheck;
210
177
  const parentPolygonInShapeSpace = editor.getShapePageTransform(shape).clone().invert().applyToPoints(parentPagePolygon);
211
- if (doesGeometryOverlapPolygon(editor.getShapeGeometry(shape), parentPolygonInShapeSpace)) {
178
+ if (editor.getShapeGeometry(shape).overlapsPolygon(parentPolygonInShapeSpace)) {
212
179
  if (!editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type))
213
180
  continue shapeCheck;
214
181
  if (shape.parentId !== parentShape.id) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils/reparenting.ts"],
4
- "sourcesContent": ["import { EMPTY_ARRAY } from '@tldraw/state'\nimport { TLGroupShape, TLParentId, TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndexAbove, getIndexBetween } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { Vec } from '../primitives/Vec'\nimport { Geometry2d } from '../primitives/geometry/Geometry2d'\nimport { Group2d } from '../primitives/geometry/Group2d'\nimport {\n\tintersectPolygonPolygon,\n\tpolygonIntersectsPolyline,\n\tpolygonsIntersect,\n} from '../primitives/intersect'\nimport { pointInPolygon } from '../primitives/utils'\n\n/**\n * Reparents shapes that are no longer contained within their parent shapes.\n * todo: rename me to something more descriptive, like `reparentOccludedShapes` or `reparentAutoDroppedShapes`\n *\n * @param editor - The editor instance.\n * @param shapeIds - The IDs of the shapes to reparent.\n * @param opts - Optional options, including a callback to filter out certain parents, such as when removing a frame.\n *\n * @public\n */\nexport function kickoutOccludedShapes(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts?: { filter?(parent: TLShape): boolean }\n) {\n\tconst parentsToCheck = new Set<TLShape>()\n\n\tfor (const id of shapeIds) {\n\t\tconst shape = editor.getShape(id)\n\n\t\tif (!shape) continue\n\t\tparentsToCheck.add(shape)\n\n\t\tconst parent = editor.getShape(shape.parentId)\n\t\tif (!parent) continue\n\t\tparentsToCheck.add(parent)\n\t}\n\n\t// Check all of the parents and gather up parents who have lost children\n\tconst parentsToLostChildren = new Map<TLShape, TLShapeId[]>()\n\n\tfor (const parent of parentsToCheck) {\n\t\tconst childIds = editor.getSortedChildIdsForParent(parent)\n\t\tif (opts?.filter && !opts.filter(parent)) {\n\t\t\t// If the shape is filtered out, we kick out all of its children\n\t\t\tparentsToLostChildren.set(parent, childIds)\n\t\t} else {\n\t\t\tconst overlappingChildren = getOverlappingShapes(editor, parent.id, childIds)\n\t\t\tif (overlappingChildren.length < childIds.length) {\n\t\t\t\tparentsToLostChildren.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tchildIds.filter((id) => !overlappingChildren.includes(id))\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Get all of the shapes on the current page, sorted by their index\n\tconst sortedShapeIds = editor.getCurrentPageShapesSorted().map((s) => s.id)\n\n\tconst parentsToNewChildren: Record<\n\t\tTLParentId,\n\t\t{ parentId: TLParentId; shapeIds: TLShapeId[]; index?: IndexKey }\n\t> = {}\n\n\tfor (const [prevParent, lostChildrenIds] of parentsToLostChildren) {\n\t\tconst lostChildren = compact(lostChildrenIds.map((id) => editor.getShape(id)))\n\n\t\t// Don't fall \"up\" into frames in front of the shape\n\t\t// if (pageShapes.indexOf(shape) < frameSortPosition) continue shapeCheck\n\n\t\t// Otherwise, we have no next dropping shape under the cursor, so go find\n\t\t// all the frames on the page where the moving shapes will fall into\n\t\tconst { reparenting, remainingShapesToReparent } = getDroppedShapesToNewParents(\n\t\t\teditor,\n\t\t\tlostChildren,\n\t\t\t(shape, maybeNewParent) => {\n\t\t\t\t// If we're filtering out a potential parent, don't reparent shapes to the filtered out shape\n\t\t\t\tif (opts?.filter && !opts.filter(maybeNewParent)) return false\n\t\t\t\treturn (\n\t\t\t\t\tmaybeNewParent.id !== prevParent.id &&\n\t\t\t\t\tsortedShapeIds.indexOf(maybeNewParent.id) < sortedShapeIds.indexOf(shape.id)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treparenting.forEach((childrenToReparent, newParentId) => {\n\t\t\tif (childrenToReparent.length === 0) return\n\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\tshapeIds: [],\n\t\t\t\t}\n\t\t\t}\n\t\t\tparentsToNewChildren[newParentId].shapeIds.push(...childrenToReparent.map((s) => s.id))\n\t\t})\n\n\t\t// Reparent the rest to the page (or containing group)\n\t\tif (remainingShapesToReparent.size > 0) {\n\t\t\t// The remaining shapes are going to be reparented to the old parent's containing group, if there was one, or else to the page\n\t\t\tconst newParentId =\n\t\t\t\teditor.findShapeAncestor(prevParent, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))\n\t\t\t\t\t?.id ?? editor.getCurrentPageId()\n\n\t\t\tremainingShapesToReparent.forEach((shape) => {\n\t\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\t\tlet insertIndexKey: IndexKey | undefined\n\n\t\t\t\t\tconst oldParentSiblingIds = editor.getSortedChildIdsForParent(newParentId)\n\t\t\t\t\tconst oldParentIndex = oldParentSiblingIds.indexOf(prevParent.id)\n\t\t\t\t\tif (oldParentIndex > -1) {\n\t\t\t\t\t\t// If the old parent is a direct child of the new parent, then we'll add them above the old parent but below the next sibling.\n\t\t\t\t\t\tconst siblingsIndexAbove = oldParentSiblingIds[oldParentIndex + 1]\n\t\t\t\t\t\tconst indexKeyAbove = siblingsIndexAbove\n\t\t\t\t\t\t\t? editor.getShape(siblingsIndexAbove)!.index\n\t\t\t\t\t\t\t: getIndexAbove(prevParent.index)\n\t\t\t\t\t\tinsertIndexKey = getIndexBetween(prevParent.index, indexKeyAbove)\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the old parent is not a direct child of the new parent, then we'll add them to the \"top\" of the new parent's children.\n\t\t\t\t\t\t// This is done automatically if we leave the index undefined, so let's do that.\n\t\t\t\t\t}\n\n\t\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\t\tshapeIds: [],\n\t\t\t\t\t\tindex: insertIndexKey,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentsToNewChildren[newParentId].shapeIds.push(shape.id)\n\t\t\t})\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\tObject.values(parentsToNewChildren).forEach(({ parentId, shapeIds, index }) => {\n\t\t\tif (shapeIds.length === 0) return\n\t\t\t// Before we reparent, sort the new shape ids by their place in the original absolute order on the page\n\t\t\tshapeIds.sort((a, b) => (sortedShapeIds.indexOf(a) < sortedShapeIds.indexOf(b) ? -1 : 1))\n\t\t\teditor.reparentShapes(shapeIds, parentId, index)\n\t\t})\n\t})\n}\n\n/**\n * Get the shapes that overlap with a given shape.\n *\n * @param editor - The editor instance.\n * @param shape - The shapes or shape IDs to check against.\n * @param otherShapes - The shapes or shape IDs to check for overlap.\n * @returns An array of shapes or shape IDs that overlap with the given shape.\n */\nfunction getOverlappingShapes<T extends TLShape[] | TLShapeId[]>(\n\teditor: Editor,\n\tshape: T[number],\n\totherShapes: T\n) {\n\tif (otherShapes.length === 0) {\n\t\treturn EMPTY_ARRAY\n\t}\n\n\tconst parentPageBounds = editor.getShapePageBounds(shape)\n\tif (!parentPageBounds) return EMPTY_ARRAY\n\n\tconst parentGeometry = editor.getShapeGeometry(shape)\n\tconst parentPageTransform = editor.getShapePageTransform(shape)\n\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\n\tconst parentPageMaskVertices = editor.getShapeMask(shape)\n\tconst parentPagePolygon = parentPageMaskVertices\n\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t: parentPageCorners\n\n\tif (!parentPagePolygon) return EMPTY_ARRAY\n\n\treturn otherShapes.filter((childId) => {\n\t\tconst shapePageBounds = editor.getShapePageBounds(childId)\n\t\tif (!shapePageBounds || !parentPageBounds.includes(shapePageBounds)) return false\n\n\t\tconst parentPolygonInShapeShape = editor\n\t\t\t.getShapePageTransform(childId)\n\t\t\t.clone()\n\t\t\t.invert()\n\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\tconst geometry = editor.getShapeGeometry(childId)\n\n\t\treturn doesGeometryOverlapPolygon(geometry, parentPolygonInShapeShape)\n\t})\n}\n\n/**\n * @public\n */\nexport function doesGeometryOverlapPolygon(\n\tgeometry: Geometry2d,\n\tparentCornersInShapeSpace: Vec[]\n): boolean {\n\t// If the child is a group, check if any of its children overlap the box\n\tif (geometry instanceof Group2d) {\n\t\treturn geometry.children.some((childGeometry) =>\n\t\t\tdoesGeometryOverlapPolygon(childGeometry, parentCornersInShapeSpace)\n\t\t)\n\t}\n\n\t// Otherwise, check if the geometry overlaps the box\n\tconst { vertices, center, isFilled, isEmptyLabel, isClosed } = geometry\n\n\t// We'll do things in order of cheapest to most expensive checks\n\n\t// Skip empty labels\n\tif (isEmptyLabel) return false\n\n\t// If any of the shape's vertices are inside the occluder, it's inside\n\tif (vertices.some((v) => pointInPolygon(v, parentCornersInShapeSpace))) {\n\t\treturn true\n\t}\n\n\t// If the shape is filled and closed and its center is inside the parent, it's inside\n\tif (isClosed) {\n\t\tif (isFilled) {\n\t\t\t// If closed and filled, check if the center is inside the parent\n\t\t\tif (pointInPolygon(center, parentCornersInShapeSpace)) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// ..then, slightly more expensive check, see the shape covers the entire parent but not its center\n\t\t\tif (parentCornersInShapeSpace.every((v) => pointInPolygon(v, vertices))) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\t// If any the shape's vertices intersect the edge of the occluder, it's inside.\n\t\t// for example when a rotated rectangle is moved over the corner of a parent rectangle\n\t\t// If the child shape is closed, intersect as a polygon\n\t\tif (polygonsIntersect(parentCornersInShapeSpace, vertices)) {\n\t\t\treturn true\n\t\t}\n\t} else {\n\t\t// if the child shape is not closed, intersect as a polyline\n\t\tif (polygonIntersectsPolyline(parentCornersInShapeSpace, vertices)) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\t// If none of the above checks passed, the shape is outside the parent\n\treturn false\n}\n\n/**\n * Get the shapes that will be reparented to new parents when the shapes are dropped.\n *\n * @param editor - The editor instance.\n * @param shapes - The shapes to check.\n * @param cb - A callback to filter out certain shapes.\n * @returns An object with the shapes that will be reparented to new parents and the shapes that will be reparented to the page or their ancestral group.\n *\n * @public\n */\nexport function getDroppedShapesToNewParents(\n\teditor: Editor,\n\tshapes: Set<TLShape> | TLShape[],\n\tcb?: (shape: TLShape, parent: TLShape) => boolean\n) {\n\tconst shapesToActuallyCheck = new Set<TLShape>(shapes)\n\tconst movingGroups = new Set<TLGroupShape>()\n\n\tfor (const shape of shapes) {\n\t\tconst parent = editor.getShapeParent(shape)\n\t\tif (parent && editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\tmovingGroups.add(parent)\n\t\t\t}\n\t\t}\n\t}\n\n\t// If all of a group's children are moving, then move the group instead\n\tfor (const movingGroup of movingGroups) {\n\t\tconst children = compact(\n\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t)\n\t\tfor (const child of children) {\n\t\t\tshapesToActuallyCheck.delete(child)\n\t\t}\n\t\tshapesToActuallyCheck.add(movingGroup)\n\t}\n\n\t// this could be cached and passed in\n\tconst shapeGroupIds = new Map<TLShapeId, TLShapeId | undefined>()\n\n\tconst reparenting = new Map<TLShapeId, TLShape[]>()\n\n\tconst remainingShapesToReparent = new Set(shapesToActuallyCheck)\n\n\tconst potentialParentShapes = editor\n\t\t.getCurrentPageShapesSorted()\n\t\t// filter out any shapes that aren't frames or that are included among the provided shapes\n\t\t.filter(\n\t\t\t(s) =>\n\t\t\t\teditor.getShapeUtil(s).canReceiveNewChildrenOfType?.(s, s.type) &&\n\t\t\t\t!remainingShapesToReparent.has(s)\n\t\t)\n\n\tparentCheck: for (let i = potentialParentShapes.length - 1; i >= 0; i--) {\n\t\tconst parentShape = potentialParentShapes[i]\n\t\tconst parentShapeContainingGroupId = editor.findShapeAncestor(parentShape, (s) =>\n\t\t\teditor.isShapeOfType<TLGroupShape>(s, 'group')\n\t\t)?.id\n\n\t\tconst parentGeometry = editor.getShapeGeometry(parentShape)\n\t\tconst parentPageTransform = editor.getShapePageTransform(parentShape)\n\t\tconst parentPageMaskVertices = editor.getShapeMask(parentShape)\n\t\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\t\tconst parentPagePolygon = parentPageMaskVertices\n\t\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t\t: parentPageCorners\n\n\t\tif (!parentPagePolygon) continue parentCheck\n\n\t\tconst childrenToReparent = []\n\n\t\t// For each of the dropping shapes...\n\t\tshapeCheck: for (const shape of remainingShapesToReparent) {\n\t\t\t// Don't reparent a frame to itself\n\t\t\tif (parentShape.id === shape.id) continue shapeCheck\n\n\t\t\t// Use the callback to filter out certain shapes\n\t\t\tif (cb && !cb(shape, parentShape)) continue shapeCheck\n\n\t\t\tif (!shapeGroupIds.has(shape.id)) {\n\t\t\t\tshapeGroupIds.set(\n\t\t\t\t\tshape.id,\n\t\t\t\t\teditor.findShapeAncestor(shape, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))?.id\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst shapeGroupId = shapeGroupIds.get(shape.id)\n\n\t\t\t// Are the shape and the parent part of different groups?\n\t\t\tif (shapeGroupId !== parentShapeContainingGroupId) continue shapeCheck\n\n\t\t\t// Is the shape is actually the ancestor of the parent?\n\t\t\tif (editor.findShapeAncestor(parentShape, (s) => shape.id === s.id)) continue shapeCheck\n\n\t\t\t// Convert the parent polygon to the shape's space\n\t\t\tconst parentPolygonInShapeSpace = editor\n\t\t\t\t.getShapePageTransform(shape)\n\t\t\t\t.clone()\n\t\t\t\t.invert()\n\t\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\t\t// If the shape overlaps the parent polygon, reparent it to that parent\n\t\t\tif (doesGeometryOverlapPolygon(editor.getShapeGeometry(shape), parentPolygonInShapeSpace)) {\n\t\t\t\t// Use the util to check if the shape can be reparented to the parent\n\t\t\t\tif (\n\t\t\t\t\t!editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type)\n\t\t\t\t)\n\t\t\t\t\tcontinue shapeCheck\n\n\t\t\t\tif (shape.parentId !== parentShape.id) {\n\t\t\t\t\tchildrenToReparent.push(shape)\n\t\t\t\t}\n\t\t\t\tremainingShapesToReparent.delete(shape)\n\t\t\t\tcontinue shapeCheck\n\t\t\t}\n\t\t}\n\n\t\tif (childrenToReparent.length) {\n\t\t\treparenting.set(parentShape.id, childrenToReparent)\n\t\t}\n\t}\n\n\treturn {\n\t\t// these are the shapes that will be reparented to new parents\n\t\treparenting,\n\t\t// these are the shapes that will be reparented to the page or their ancestral group\n\t\tremainingShapesToReparent,\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAE5B,mBAAkE;AAIlE,qBAAwB;AACxB,uBAIO;AACP,IAAAA,gBAA+B;AAYxB,SAAS,sBACf,QACA,UACA,MACC;AACD,QAAM,iBAAiB,oBAAI,IAAa;AAExC,aAAW,MAAM,UAAU;AAC1B,UAAM,QAAQ,OAAO,SAAS,EAAE;AAEhC,QAAI,CAAC,MAAO;AACZ,mBAAe,IAAI,KAAK;AAExB,UAAM,SAAS,OAAO,SAAS,MAAM,QAAQ;AAC7C,QAAI,CAAC,OAAQ;AACb,mBAAe,IAAI,MAAM;AAAA,EAC1B;AAGA,QAAM,wBAAwB,oBAAI,IAA0B;AAE5D,aAAW,UAAU,gBAAgB;AACpC,UAAM,WAAW,OAAO,2BAA2B,MAAM;AACzD,QAAI,MAAM,UAAU,CAAC,KAAK,OAAO,MAAM,GAAG;AAEzC,4BAAsB,IAAI,QAAQ,QAAQ;AAAA,IAC3C,OAAO;AACN,YAAM,sBAAsB,qBAAqB,QAAQ,OAAO,IAAI,QAAQ;AAC5E,UAAI,oBAAoB,SAAS,SAAS,QAAQ;AACjD,8BAAsB;AAAA,UACrB;AA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AAE,GAAG;AACjC,sBAAc;AAAA,UACb,MAAM;AAAA,UACN,OAAO,kBAAkB,OAAO,CAAC,MAAM,OAAO,cAA4B,GAAG,OAAO,CAAC,GAAG;AAAA,QACzF;AAAA,MACD;AAEA,YAAM,eAAe,cAAc,IAAI,MAAM,EAAE;AAG/C,UAAI,iBAAiB,6BAA8B,UAAS;AAG5D,UAAI,OAAO,kBAAkB,aAAa,CAAC,MAAM,MAAM,OAAO,EAAE,EAAE,EAAG,UAAS;AAG9E,YAAM,4BAA4B,OAChC,sBAAsB,KAAK,EAC3B,MAAM,EACN,OAAO,EACP,cAAc,iBAAiB;AAGjC,UAAI,2BAA2B,OAAO,iBAAiB,KAAK,GAAG,yBAAyB,GAAG;AAE1F,YACC,CAAC,OAAO,aAAa,WAAW,EAAE,8BAA8B,aAAa,MAAM,IAAI;AAEvF,mBAAS;AAEV,YAAI,MAAM,aAAa,YAAY,IAAI;AACtC,6BAAmB,KAAK,KAAK;AAAA,QAC9B;AACA,kCAA0B,OAAO,KAAK;AACtC,iBAAS;AAAA,MACV;AAAA,IACD;AAEA,QAAI,mBAAmB,QAAQ;AAC9B,kBAAY,IAAI,YAAY,IAAI,kBAAkB;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA;AAAA,EACD;AACD;",
6
- "names": ["import_utils", "shapeIds"]
4
+ "sourcesContent": ["import { EMPTY_ARRAY } from '@tldraw/state'\nimport { TLGroupShape, TLParentId, TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndexAbove, getIndexBetween } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { intersectPolygonPolygon } from '../primitives/intersect'\n\n/**\n * Reparents shapes that are no longer contained within their parent shapes.\n * todo: rename me to something more descriptive, like `reparentOccludedShapes` or `reparentAutoDroppedShapes`\n *\n * @param editor - The editor instance.\n * @param shapeIds - The IDs of the shapes to reparent.\n * @param opts - Optional options, including a callback to filter out certain parents, such as when removing a frame.\n *\n * @public\n */\nexport function kickoutOccludedShapes(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts?: { filter?(parent: TLShape): boolean }\n) {\n\tconst parentsToCheck = new Set<TLShape>()\n\n\tfor (const id of shapeIds) {\n\t\tconst shape = editor.getShape(id)\n\n\t\tif (!shape) continue\n\t\tparentsToCheck.add(shape)\n\n\t\tconst parent = editor.getShape(shape.parentId)\n\t\tif (!parent) continue\n\t\tparentsToCheck.add(parent)\n\t}\n\n\t// Check all of the parents and gather up parents who have lost children\n\tconst parentsToLostChildren = new Map<TLShape, TLShapeId[]>()\n\n\tfor (const parent of parentsToCheck) {\n\t\tconst childIds = editor.getSortedChildIdsForParent(parent)\n\t\tif (opts?.filter && !opts.filter(parent)) {\n\t\t\t// If the shape is filtered out, we kick out all of its children\n\t\t\tparentsToLostChildren.set(parent, childIds)\n\t\t} else {\n\t\t\tconst overlappingChildren = getOverlappingShapes(editor, parent.id, childIds)\n\t\t\tif (overlappingChildren.length < childIds.length) {\n\t\t\t\tparentsToLostChildren.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tchildIds.filter((id) => !overlappingChildren.includes(id))\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Get all of the shapes on the current page, sorted by their index\n\tconst sortedShapeIds = editor.getCurrentPageShapesSorted().map((s) => s.id)\n\n\tconst parentsToNewChildren: Record<\n\t\tTLParentId,\n\t\t{ parentId: TLParentId; shapeIds: TLShapeId[]; index?: IndexKey }\n\t> = {}\n\n\tfor (const [prevParent, lostChildrenIds] of parentsToLostChildren) {\n\t\tconst lostChildren = compact(lostChildrenIds.map((id) => editor.getShape(id)))\n\n\t\t// Don't fall \"up\" into frames in front of the shape\n\t\t// if (pageShapes.indexOf(shape) < frameSortPosition) continue shapeCheck\n\n\t\t// Otherwise, we have no next dropping shape under the cursor, so go find\n\t\t// all the frames on the page where the moving shapes will fall into\n\t\tconst { reparenting, remainingShapesToReparent } = getDroppedShapesToNewParents(\n\t\t\teditor,\n\t\t\tlostChildren,\n\t\t\t(shape, maybeNewParent) => {\n\t\t\t\t// If we're filtering out a potential parent, don't reparent shapes to the filtered out shape\n\t\t\t\tif (opts?.filter && !opts.filter(maybeNewParent)) return false\n\t\t\t\treturn (\n\t\t\t\t\tmaybeNewParent.id !== prevParent.id &&\n\t\t\t\t\tsortedShapeIds.indexOf(maybeNewParent.id) < sortedShapeIds.indexOf(shape.id)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treparenting.forEach((childrenToReparent, newParentId) => {\n\t\t\tif (childrenToReparent.length === 0) return\n\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\tshapeIds: [],\n\t\t\t\t}\n\t\t\t}\n\t\t\tparentsToNewChildren[newParentId].shapeIds.push(...childrenToReparent.map((s) => s.id))\n\t\t})\n\n\t\t// Reparent the rest to the page (or containing group)\n\t\tif (remainingShapesToReparent.size > 0) {\n\t\t\t// The remaining shapes are going to be reparented to the old parent's containing group, if there was one, or else to the page\n\t\t\tconst newParentId =\n\t\t\t\teditor.findShapeAncestor(prevParent, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))\n\t\t\t\t\t?.id ?? editor.getCurrentPageId()\n\n\t\t\tremainingShapesToReparent.forEach((shape) => {\n\t\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\t\tlet insertIndexKey: IndexKey | undefined\n\n\t\t\t\t\tconst oldParentSiblingIds = editor.getSortedChildIdsForParent(newParentId)\n\t\t\t\t\tconst oldParentIndex = oldParentSiblingIds.indexOf(prevParent.id)\n\t\t\t\t\tif (oldParentIndex > -1) {\n\t\t\t\t\t\t// If the old parent is a direct child of the new parent, then we'll add them above the old parent but below the next sibling.\n\t\t\t\t\t\tconst siblingsIndexAbove = oldParentSiblingIds[oldParentIndex + 1]\n\t\t\t\t\t\tconst indexKeyAbove = siblingsIndexAbove\n\t\t\t\t\t\t\t? editor.getShape(siblingsIndexAbove)!.index\n\t\t\t\t\t\t\t: getIndexAbove(prevParent.index)\n\t\t\t\t\t\tinsertIndexKey = getIndexBetween(prevParent.index, indexKeyAbove)\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the old parent is not a direct child of the new parent, then we'll add them to the \"top\" of the new parent's children.\n\t\t\t\t\t\t// This is done automatically if we leave the index undefined, so let's do that.\n\t\t\t\t\t}\n\n\t\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\t\tshapeIds: [],\n\t\t\t\t\t\tindex: insertIndexKey,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentsToNewChildren[newParentId].shapeIds.push(shape.id)\n\t\t\t})\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\tObject.values(parentsToNewChildren).forEach(({ parentId, shapeIds, index }) => {\n\t\t\tif (shapeIds.length === 0) return\n\t\t\t// Before we reparent, sort the new shape ids by their place in the original absolute order on the page\n\t\t\tshapeIds.sort((a, b) => (sortedShapeIds.indexOf(a) < sortedShapeIds.indexOf(b) ? -1 : 1))\n\t\t\teditor.reparentShapes(shapeIds, parentId, index)\n\t\t})\n\t})\n}\n\n/**\n * Get the shapes that overlap with a given shape.\n *\n * @param editor - The editor instance.\n * @param shape - The shapes or shape IDs to check against.\n * @param otherShapes - The shapes or shape IDs to check for overlap.\n * @returns An array of shapes or shape IDs that overlap with the given shape.\n */\nfunction getOverlappingShapes<T extends TLShape[] | TLShapeId[]>(\n\teditor: Editor,\n\tshape: T[number],\n\totherShapes: T\n) {\n\tif (otherShapes.length === 0) {\n\t\treturn EMPTY_ARRAY\n\t}\n\n\tconst parentPageBounds = editor.getShapePageBounds(shape)\n\tif (!parentPageBounds) return EMPTY_ARRAY\n\n\tconst parentGeometry = editor.getShapeGeometry(shape)\n\tconst parentPageTransform = editor.getShapePageTransform(shape)\n\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\n\tconst parentPageMaskVertices = editor.getShapeMask(shape)\n\tconst parentPagePolygon = parentPageMaskVertices\n\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t: parentPageCorners\n\n\tif (!parentPagePolygon) return EMPTY_ARRAY\n\n\treturn otherShapes.filter((childId) => {\n\t\tconst shapePageBounds = editor.getShapePageBounds(childId)\n\t\tif (!shapePageBounds || !parentPageBounds.includes(shapePageBounds)) return false\n\n\t\tconst parentPolygonInShapeShape = editor\n\t\t\t.getShapePageTransform(childId)\n\t\t\t.clone()\n\t\t\t.invert()\n\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\tconst geometry = editor.getShapeGeometry(childId)\n\n\t\treturn geometry.overlapsPolygon(parentPolygonInShapeShape)\n\t})\n}\n\n/**\n * Get the shapes that will be reparented to new parents when the shapes are dropped.\n *\n * @param editor - The editor instance.\n * @param shapes - The shapes to check.\n * @param cb - A callback to filter out certain shapes.\n * @returns An object with the shapes that will be reparented to new parents and the shapes that will be reparented to the page or their ancestral group.\n *\n * @public\n */\nexport function getDroppedShapesToNewParents(\n\teditor: Editor,\n\tshapes: Set<TLShape> | TLShape[],\n\tcb?: (shape: TLShape, parent: TLShape) => boolean\n) {\n\tconst shapesToActuallyCheck = new Set<TLShape>(shapes)\n\tconst movingGroups = new Set<TLGroupShape>()\n\n\tfor (const shape of shapes) {\n\t\tconst parent = editor.getShapeParent(shape)\n\t\tif (parent && editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\tmovingGroups.add(parent)\n\t\t\t}\n\t\t}\n\t}\n\n\t// If all of a group's children are moving, then move the group instead\n\tfor (const movingGroup of movingGroups) {\n\t\tconst children = compact(\n\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t)\n\t\tfor (const child of children) {\n\t\t\tshapesToActuallyCheck.delete(child)\n\t\t}\n\t\tshapesToActuallyCheck.add(movingGroup)\n\t}\n\n\t// this could be cached and passed in\n\tconst shapeGroupIds = new Map<TLShapeId, TLShapeId | undefined>()\n\n\tconst reparenting = new Map<TLShapeId, TLShape[]>()\n\n\tconst remainingShapesToReparent = new Set(shapesToActuallyCheck)\n\n\tconst potentialParentShapes = editor\n\t\t.getCurrentPageShapesSorted()\n\t\t// filter out any shapes that aren't frames or that are included among the provided shapes\n\t\t.filter(\n\t\t\t(s) =>\n\t\t\t\teditor.getShapeUtil(s).canReceiveNewChildrenOfType?.(s, s.type) &&\n\t\t\t\t!remainingShapesToReparent.has(s)\n\t\t)\n\n\tparentCheck: for (let i = potentialParentShapes.length - 1; i >= 0; i--) {\n\t\tconst parentShape = potentialParentShapes[i]\n\t\tconst parentShapeContainingGroupId = editor.findShapeAncestor(parentShape, (s) =>\n\t\t\teditor.isShapeOfType<TLGroupShape>(s, 'group')\n\t\t)?.id\n\n\t\tconst parentGeometry = editor.getShapeGeometry(parentShape)\n\t\tconst parentPageTransform = editor.getShapePageTransform(parentShape)\n\t\tconst parentPageMaskVertices = editor.getShapeMask(parentShape)\n\t\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\t\tconst parentPagePolygon = parentPageMaskVertices\n\t\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t\t: parentPageCorners\n\n\t\tif (!parentPagePolygon) continue parentCheck\n\n\t\tconst childrenToReparent = []\n\n\t\t// For each of the dropping shapes...\n\t\tshapeCheck: for (const shape of remainingShapesToReparent) {\n\t\t\t// Don't reparent a frame to itself\n\t\t\tif (parentShape.id === shape.id) continue shapeCheck\n\n\t\t\t// Use the callback to filter out certain shapes\n\t\t\tif (cb && !cb(shape, parentShape)) continue shapeCheck\n\n\t\t\tif (!shapeGroupIds.has(shape.id)) {\n\t\t\t\tshapeGroupIds.set(\n\t\t\t\t\tshape.id,\n\t\t\t\t\teditor.findShapeAncestor(shape, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))?.id\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst shapeGroupId = shapeGroupIds.get(shape.id)\n\n\t\t\t// Are the shape and the parent part of different groups?\n\t\t\tif (shapeGroupId !== parentShapeContainingGroupId) continue shapeCheck\n\n\t\t\t// Is the shape is actually the ancestor of the parent?\n\t\t\tif (editor.findShapeAncestor(parentShape, (s) => shape.id === s.id)) continue shapeCheck\n\n\t\t\t// Convert the parent polygon to the shape's space\n\t\t\tconst parentPolygonInShapeSpace = editor\n\t\t\t\t.getShapePageTransform(shape)\n\t\t\t\t.clone()\n\t\t\t\t.invert()\n\t\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\t\t// If the shape overlaps the parent polygon, reparent it to that parent\n\t\t\tif (editor.getShapeGeometry(shape).overlapsPolygon(parentPolygonInShapeSpace)) {\n\t\t\t\t// Use the util to check if the shape can be reparented to the parent\n\t\t\t\tif (\n\t\t\t\t\t!editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type)\n\t\t\t\t)\n\t\t\t\t\tcontinue shapeCheck\n\n\t\t\t\tif (shape.parentId !== parentShape.id) {\n\t\t\t\t\tchildrenToReparent.push(shape)\n\t\t\t\t}\n\t\t\t\tremainingShapesToReparent.delete(shape)\n\t\t\t\tcontinue shapeCheck\n\t\t\t}\n\t\t}\n\n\t\tif (childrenToReparent.length) {\n\t\t\treparenting.set(parentShape.id, childrenToReparent)\n\t\t}\n\t}\n\n\treturn {\n\t\t// these are the shapes that will be reparented to new parents\n\t\treparenting,\n\t\t// these are the shapes that will be reparented to the page or their ancestral group\n\t\tremainingShapesToReparent,\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAE5B,mBAAkE;AAElE,uBAAwC;AAYjC,SAAS,sBACf,QACA,UACA,MACC;AACD,QAAM,iBAAiB,oBAAI,IAAa;AAExC,aAAW,MAAM,UAAU;AAC1B,UAAM,QAA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C,UAAI,iBAAiB,6BAA8B,UAAS;AAG5D,UAAI,OAAO,kBAAkB,aAAa,CAAC,MAAM,MAAM,OAAO,EAAE,EAAE,EAAG,UAAS;AAG9E,YAAM,4BAA4B,OAChC,sBAAsB,KAAK,EAC3B,MAAM,EACN,OAAO,EACP,cAAc,iBAAiB;AAGjC,UAAI,OAAO,iBAAiB,KAAK,EAAE,gBAAgB,yBAAyB,GAAG;AAE9E,YACC,CAAC,OAAO,aAAa,WAAW,EAAE,8BAA8B,aAAa,MAAM,IAAI;AAEvF,mBAAS;AAEV,YAAI,MAAM,aAAa,YAAY,IAAI;AACtC,6BAAmB,KAAK,KAAK;AAAA,QAC9B;AACA,kCAA0B,OAAO,KAAK;AACtC,iBAAS;AAAA,MACV;AAAA,IACD;AAEA,QAAI,mBAAmB,QAAQ;AAC9B,kBAAY,IAAI,YAAY,IAAI,kBAAkB;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA;AAAA,EACD;AACD;",
6
+ "names": ["shapeIds"]
7
7
  }
@@ -22,10 +22,10 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- const version = "3.16.0-canary.bcde131f3274";
25
+ const version = "3.16.0-canary.bf7be9dad88b";
26
26
  const publishDates = {
27
27
  major: "2024-09-13T14:36:29.063Z",
28
- minor: "2025-08-27T13:34:10.657Z",
29
- patch: "2025-08-27T13:34:10.657Z"
28
+ minor: "2025-09-17T15:01:00.589Z",
29
+ patch: "2025-09-17T15:01:00.589Z"
30
30
  };
31
31
  //# sourceMappingURL=version.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.bcde131f3274'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-27T13:34:10.657Z',\n\tpatch: '2025-08-27T13:34:10.657Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.bf7be9dad88b'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-09-17T15:01:00.589Z',\n\tpatch: '2025-09-17T15:01:00.589Z',\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -761,11 +761,6 @@ export declare class CubicSpline2d extends Geometry2d {
761
761
  /** @public */
762
762
  export declare function dataUrlToFile(url: string, filename: string, mimeType: string): Promise<File>;
763
763
 
764
- /**
765
- * @deprecated Licensing is now enabled in the tldraw SDK.
766
- * @public */
767
- export declare function debugEnableLicensing(): void;
768
-
769
764
  /* Excluded from this release type: DebugFlag */
770
765
 
771
766
  /* Excluded from this release type: DebugFlagDef */
@@ -984,7 +979,7 @@ export declare class EdgeScrollManager {
984
979
  /** @public */
985
980
  export declare class Editor extends EventEmitter<TLEventMap> {
986
981
  readonly id: string;
987
- constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, textOptions, initialState, autoFocus, inferDarkMode, options, isShapeHidden, getShapeVisibility, fontAssetUrls, }: TLEditorOptions);
982
+ constructor({ store, user, shapeUtils, bindingUtils, tools, getContainer, cameraOptions, textOptions, initialState, autoFocus, inferDarkMode, options, getShapeVisibility, fontAssetUrls, }: TLEditorOptions);
988
983
  private readonly _getShapeVisibility?;
989
984
  private getIsShapeHiddenCache;
990
985
  isShapeHidden(shapeOrId: TLShape | TLShapeId): boolean;
@@ -1051,22 +1046,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1051
1046
  * @public
1052
1047
  */
1053
1048
  readonly fonts: FontManager;
1054
- /**
1055
- * A manager for the editor's environment.
1056
- *
1057
- * @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
1058
- * @public
1059
- */
1060
- readonly environment: {
1061
- hasCanvasSupport: boolean;
1062
- isAndroid: boolean;
1063
- isChromeForIos: boolean;
1064
- isDarwin: boolean;
1065
- isFirefox: boolean;
1066
- isIos: boolean;
1067
- isSafari: boolean;
1068
- isWebview: boolean;
1069
- };
1070
1049
  /**
1071
1050
  * A manager for the editor's scribbles.
1072
1051
  *
@@ -1209,22 +1188,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1209
1188
  * @public
1210
1189
  */
1211
1190
  getCanRedo(): boolean;
1212
- /**
1213
- * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1214
- * any redos.
1215
- *
1216
- * @example
1217
- * ```ts
1218
- * editor.mark()
1219
- * editor.mark('flip shapes')
1220
- * ```
1221
- *
1222
- * @param markId - The mark's id, usually the reason for adding the mark.
1223
- *
1224
- * @public
1225
- * @deprecated use {@link Editor.markHistoryStoppingPoint} instead
1226
- */
1227
- mark(markId?: string): this;
1228
1191
  /**
1229
1192
  * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1230
1193
  * any redos. You typically want to do this just before a user interaction begins or is handled.
@@ -1314,10 +1277,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1314
1277
  * @public
1315
1278
  */
1316
1279
  run(fn: () => void, opts?: TLEditorRunOptions): this;
1317
- /**
1318
- * @deprecated Use `Editor.run` instead.
1319
- */
1320
- batch(fn: () => void, opts?: TLEditorRunOptions): this;
1321
1280
  /* Excluded from this release type: annotateError */
1322
1281
  /* Excluded from this release type: createErrorAnnotations */
1323
1282
  /* Excluded from this release type: _crashingError */
@@ -1439,36 +1398,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1439
1398
  hasOpenMenus: () => boolean;
1440
1399
  isMenuOpen: (id: string) => boolean;
1441
1400
  };
1442
- /**
1443
- * @deprecated Use `editor.menus.getOpenMenus` instead.
1444
- *
1445
- * @public
1446
- */
1447
- getOpenMenus(): string[];
1448
- /**
1449
- * @deprecated Use `editor.menus.addOpenMenu` instead.
1450
- *
1451
- * @public
1452
- */
1453
- addOpenMenu(id: string): this;
1454
- /**
1455
- * @deprecated Use `editor.menus.deleteOpenMenu` instead.
1456
- *
1457
- * @public
1458
- */
1459
- deleteOpenMenu(id: string): this;
1460
- /**
1461
- * @deprecated Use `editor.menus.clearOpenMenus` instead.
1462
- *
1463
- * @public
1464
- */
1465
- clearOpenMenus(): this;
1466
- /**
1467
- * @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
1468
- *
1469
- * @public
1470
- */
1471
- getIsMenuOpen(): boolean;
1472
1401
  /**
1473
1402
  * Set the cursor.
1474
1403
  *
@@ -2917,8 +2846,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
2917
2846
  * @public
2918
2847
  */
2919
2848
  getShapeAndDescendantIds(ids: TLShapeId[]): Set<TLShapeId>;
2920
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
2921
- getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined;
2922
2849
  /**
2923
2850
  * Get the shape that some shapes should be dropped on at a given point.
2924
2851
  *
@@ -3630,14 +3557,20 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3630
3557
  * Handle external content, such as files, urls, embeds, or plain text which has been put into the app, for example by pasting external text or dropping external images onto canvas.
3631
3558
  *
3632
3559
  * @param info - Info about the external content.
3560
+ * @param opts - Options for handling external content, including force flag to bypass readonly checks.
3633
3561
  */
3634
- putExternalContent<E>(info: TLExternalContent<E>): Promise<void>;
3562
+ putExternalContent<E>(info: TLExternalContent<E>, opts?: {
3563
+ force?: boolean;
3564
+ }): Promise<void>;
3635
3565
  /**
3636
3566
  * Handle replacing external content.
3637
3567
  *
3638
3568
  * @param info - Info about the external content.
3569
+ * @param opts - Options for handling external content, including force flag to bypass readonly checks.
3639
3570
  */
3640
- replaceExternalContent<E>(info: TLExternalContent<E>): Promise<void>;
3571
+ replaceExternalContent<E>(info: TLExternalContent<E>, opts?: {
3572
+ force?: boolean;
3573
+ }): Promise<void>;
3641
3574
  /**
3642
3575
  * Get content that can be exported for the given shape ids.
3643
3576
  *
@@ -3693,8 +3626,6 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3693
3626
  svg: string;
3694
3627
  width: number;
3695
3628
  } | undefined>;
3696
- /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
3697
- getSvg(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<SVGSVGElement | undefined>;
3698
3629
  /**
3699
3630
  * Get an exported image of the given shapes.
3700
3631
  *
@@ -4164,6 +4095,7 @@ export declare abstract class Geometry2d {
4164
4095
  isLabel: boolean;
4165
4096
  isEmptyLabel: boolean;
4166
4097
  isInternal: boolean;
4098
+ excludeFromShapeBounds: boolean;
4167
4099
  debugColor?: string;
4168
4100
  ignore?: boolean;
4169
4101
  constructor(opts: Geometry2dOptions);
@@ -4187,12 +4119,14 @@ export declare abstract class Geometry2d {
4187
4119
  * along the edge it is as a fraction of the total length.
4188
4120
  */
4189
4121
  uninterpolateAlongEdge(point: VecLike, _filters?: Geometry2dFilters): number;
4190
- /** @deprecated Iterate the vertices instead. */
4191
- nearestPointOnLineSegment(A: VecLike, B: VecLike): Vec;
4192
4122
  isPointInBounds(point: VecLike, margin?: number): boolean;
4123
+ overlapsPolygon(_polygon: VecLike[]): boolean;
4193
4124
  transform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d;
4194
4125
  private _vertices;
4195
4126
  get vertices(): Vec[];
4127
+ getBoundsVertices(): Vec[];
4128
+ private _boundsVertices;
4129
+ get boundsVertices(): Vec[];
4196
4130
  getBounds(): Box;
4197
4131
  private _bounds;
4198
4132
  get bounds(): Box;
@@ -4389,6 +4323,7 @@ export declare class Group2d extends Geometry2d {
4389
4323
  hitTestLineSegment(A: VecLike, B: VecLike, zoom: number, filters?: Geometry2dFilters): boolean;
4390
4324
  intersectLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters): VecLike[];
4391
4325
  intersectCircle(center: VecLike, radius: number, filters?: Geometry2dFilters): VecLike[];
4326
+ getBoundsVertices(): Vec[];
4392
4327
  intersectPolygon(polygon: VecLike[], filters?: Geometry2dFilters): VecLike[];
4393
4328
  intersectPolyline(polyline: VecLike[], filters?: Geometry2dFilters): VecLike[];
4394
4329
  interpolateAlongEdge(t: number, filters?: Geometry2dFilters): Vec;
@@ -4398,6 +4333,7 @@ export declare class Group2d extends Geometry2d {
4398
4333
  toSimpleSvgPath(): string;
4399
4334
  getLength(filters?: Geometry2dFilters): number;
4400
4335
  getSvgPathData(): string;
4336
+ overlapsPolygon(polygon: VecLike[]): boolean;
4401
4337
  }
4402
4338
 
4403
4339
  /** @public */
@@ -4638,12 +4574,16 @@ export declare function kickoutOccludedShapes(editor: Editor, shapeIds: TLShapeI
4638
4574
  filter?(parent: TLShape): boolean;
4639
4575
  }): void;
4640
4576
 
4577
+ /* Excluded from this release type: LICENSE_TIMEOUT */
4578
+
4641
4579
  /* Excluded from this release type: LicenseFromKeyResult */
4642
4580
 
4643
4581
  /* Excluded from this release type: LicenseInfo */
4644
4582
 
4645
4583
  /* Excluded from this release type: LicenseManager */
4646
4584
 
4585
+ /* Excluded from this release type: LicenseState */
4586
+
4647
4587
  /** @public */
4648
4588
  export declare function linesIntersect(A: VecLike, B: VecLike, C: VecLike, D: VecLike): boolean;
4649
4589
 
@@ -4676,6 +4616,23 @@ export declare function loadSnapshot(store: TLStore, _snapshot: Partial<TLEditor
4676
4616
  /** @public */
4677
4617
  export declare function loopToHtmlElement(elm: Element): HTMLElement;
4678
4618
 
4619
+ /**
4620
+ * In tldraw, events are sometimes handled by multiple components. For example, the shapes might
4621
+ * have events, but the canvas handles events too. The way that the canvas handles events can
4622
+ * interfere with the with the shapes event handlers - for example, it calls `.preventDefault()` on
4623
+ * `pointerDown`, which also prevents `click` events from firing on the shapes.
4624
+ *
4625
+ * You can use `.stopPropagation()` to prevent the event from propagating to the rest of the DOM,
4626
+ * but that can impact non-tldraw event handlers set up elsewhere. By using `markEventAsHandled`,
4627
+ * you'll stop other parts of tldraw from handling the event without impacting other, non-tldraw
4628
+ * event handlers. See also {@link wasEventAlreadyHandled}.
4629
+ *
4630
+ * @public
4631
+ */
4632
+ export declare function markEventAsHandled(e: {
4633
+ nativeEvent: Event;
4634
+ } | Event): void;
4635
+
4679
4636
  /** @public */
4680
4637
  export declare class Mat {
4681
4638
  constructor(a: number, b: number, c: number, d: number, e: number, f: number);
@@ -5249,7 +5206,34 @@ export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknown
5249
5206
  * @public
5250
5207
  */
5251
5208
  canBeLaidOut(_shape: Shape, _info: TLShapeUtilCanBeLaidOutOpts): boolean;
5209
+ /**
5210
+ * Whether this shape can be culled. By default, shapes are culled for
5211
+ * performance reasons when they are outside of the viewport. Culled shapes are still rendered
5212
+ * to the DOM, but have their `display` property set to `none`.
5213
+ *
5214
+ * @param shape - The shape.
5215
+ */
5216
+ canCull(_shape: Shape): boolean;
5252
5217
  /* Excluded from this release type: providesBackgroundForChildren */
5218
+ /**
5219
+ * Get the clip path to apply to this shape's children.
5220
+ *
5221
+ * @param shape - The shape to get the clip path for
5222
+ * @returns Array of points defining the clipping polygon in local coordinates, or undefined if no clipping
5223
+ * @public
5224
+ */
5225
+ getClipPath?(shape: Shape): undefined | Vec[];
5226
+ /**
5227
+ * Whether a specific child shape should be clipped by this shape.
5228
+ * Only called if getClipPath returns a valid polygon.
5229
+ *
5230
+ * If not defined, the default behavior is to clip all children.
5231
+ *
5232
+ * @param child - The child shape to check
5233
+ * @returns boolean indicating if this child should be clipped
5234
+ * @public
5235
+ */
5236
+ shouldClipChild?(child: TLShape): boolean;
5253
5237
  /**
5254
5238
  * Whether the shape should hide its resize handles when selected.
5255
5239
  *
@@ -5846,7 +5830,14 @@ export declare abstract class StateNode implements Partial<TLEventHandlers> {
5846
5830
  onExit?(info: any, to: string): void;
5847
5831
  }
5848
5832
 
5849
- /** @public */
5833
+ /**
5834
+ * Calls `event.stopPropagation()`.
5835
+ *
5836
+ * @deprecated Use {@link markEventAsHandled} instead, or manually call `event.stopPropagation()` if
5837
+ * that's what you really want.
5838
+ *
5839
+ * @public
5840
+ */
5850
5841
  export declare const stopEventPropagation: (e: any) => any;
5851
5842
 
5852
5843
  /* Excluded from this release type: StoreName */
@@ -6337,12 +6328,6 @@ export declare interface TldrawEditorBaseProps {
6337
6328
  * Options for syncing the editor's camera state with the URL.
6338
6329
  */
6339
6330
  deepLinks?: TLDeepLinkOptions | true;
6340
- /**
6341
- * Predicate for whether or not a shape should be hidden.
6342
- *
6343
- * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.
6344
- */
6345
- isShapeHidden?(shape: TLShape, editor: Editor): boolean;
6346
6331
  /**
6347
6332
  * Provides a way to hide shapes.
6348
6333
  *
@@ -6604,15 +6589,6 @@ export declare interface TLEditorOptions {
6604
6589
  fontAssetUrls?: {
6605
6590
  [key: string]: string | undefined;
6606
6591
  };
6607
- /**
6608
- * A predicate that should return true if the given shape should be hidden.
6609
- *
6610
- * @deprecated Use {@link Editor#getShapeVisibility} instead.
6611
- *
6612
- * @param shape - The shape to check.
6613
- * @param editor - The editor instance.
6614
- */
6615
- isShapeHidden?(shape: TLShape, editor: Editor): boolean;
6616
6592
  /**
6617
6593
  * Provides a way to hide shapes.
6618
6594
  *
@@ -7603,12 +7579,6 @@ export declare interface TLSvgExportOptions {
7603
7579
  preserveAspectRatio?: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio'];
7604
7580
  }
7605
7581
 
7606
- /**
7607
- * @public
7608
- * @deprecated use {@link TLImageExportOptions} instead
7609
- */
7610
- export declare type TLSvgOptions = TLImageExportOptions;
7611
-
7612
7582
  /** @public */
7613
7583
  export declare interface TLSvgTextExternalContent extends TLBaseExternalContent {
7614
7584
  type: 'svg-text';
@@ -7762,6 +7732,7 @@ export declare class TransformedGeometry2d extends Geometry2d {
7762
7732
  private readonly decomposed;
7763
7733
  constructor(geometry: Geometry2d, matrix: MatModel, opts?: TransformedGeometry2dOptions);
7764
7734
  getVertices(filters: Geometry2dFilters): Vec[];
7735
+ getBoundsVertices(): Vec[];
7765
7736
  nearestPoint(point: VecLike, filters?: Geometry2dFilters): Vec;
7766
7737
  hitTestPoint(point: VecLike, margin?: number, hitInside?: boolean, filters?: Geometry2dFilters): boolean;
7767
7738
  distanceToPoint(point: VecLike, hitInside?: boolean, filters?: Geometry2dFilters): number;
@@ -7782,6 +7753,7 @@ export declare interface TransformedGeometry2dOptions {
7782
7753
  isInternal?: boolean;
7783
7754
  debugColor?: string;
7784
7755
  ignore?: boolean;
7756
+ excludeFromShapeBounds?: boolean;
7785
7757
  }
7786
7758
 
7787
7759
  /** @public */
@@ -8016,8 +7988,6 @@ export declare class Vec {
8016
7988
  lrp(B: VecLike, t: number): Vec;
8017
7989
  equals(B: VecLike): boolean;
8018
7990
  equalsXY(x: number, y: number): boolean;
8019
- /** @deprecated use `uni` instead */
8020
- norm(): this;
8021
7991
  toFixed(): this;
8022
7992
  toString(): string;
8023
7993
  toJson(): VecModel;
@@ -8139,6 +8109,15 @@ export declare class Vec {
8139
8109
  /** @public */
8140
8110
  export declare type VecLike = Vec | VecModel;
8141
8111
 
8112
+ /**
8113
+ * Checks if an event has already been handled. See {@link markEventAsHandled}.
8114
+ *
8115
+ * @public
8116
+ */
8117
+ export declare function wasEventAlreadyHandled(e: {
8118
+ nativeEvent: Event;
8119
+ } | Event): boolean;
8120
+
8142
8121
 
8143
8122
  export * from "@tldraw/state";
8144
8123
  export * from "@tldraw/state-react";
@@ -175,6 +175,7 @@ import { useViewportHeight } from "./lib/hooks/useViewportHeight.mjs";
175
175
  import {
176
176
  LicenseManager
177
177
  } from "./lib/license/LicenseManager.mjs";
178
+ import { LICENSE_TIMEOUT } from "./lib/license/LicenseProvider.mjs";
178
179
  import { defaultTldrawOptions } from "./lib/options.mjs";
179
180
  import {
180
181
  Box,
@@ -268,10 +269,12 @@ import {
268
269
  import {
269
270
  activeElementShouldCaptureKeys,
270
271
  loopToHtmlElement,
272
+ markEventAsHandled,
271
273
  preventDefault,
272
274
  releasePointerCapture,
273
275
  setPointerCapture,
274
- stopEventPropagation
276
+ stopEventPropagation,
277
+ wasEventAlreadyHandled
275
278
  } from "./lib/utils/dom.mjs";
276
279
  import { EditorAtom } from "./lib/utils/EditorAtom.mjs";
277
280
  import { getIncrementedName } from "./lib/utils/getIncrementedName.mjs";
@@ -298,12 +301,9 @@ import { hardReset } from "./lib/utils/sync/hardReset.mjs";
298
301
  import { LocalIndexedDb, Table } from "./lib/utils/sync/LocalIndexedDb.mjs";
299
302
  import { uniq } from "./lib/utils/uniq.mjs";
300
303
  import { openWindow } from "./lib/utils/window-open.mjs";
301
- function debugEnableLicensing() {
302
- return;
303
- }
304
304
  registerTldrawLibraryVersion(
305
305
  "@tldraw/editor",
306
- "3.16.0-canary.bcde131f3274",
306
+ "3.16.0-canary.bf7be9dad88b",
307
307
  "esm"
308
308
  );
309
309
  export {
@@ -358,6 +358,7 @@ export {
358
358
  HTMLContainer,
359
359
  HandleSnaps,
360
360
  HistoryManager,
361
+ LICENSE_TIMEOUT,
361
362
  LicenseManager,
362
363
  LoadingScreen,
363
364
  LocalIndexedDb,
@@ -409,7 +410,6 @@ export {
409
410
  createTLStore,
410
411
  createTLUser,
411
412
  dataUrlToFile,
412
- debugEnableLicensing,
413
413
  debugFlags,
414
414
  defaultTldrawOptions,
415
415
  defaultUserPreferences,
@@ -454,6 +454,7 @@ export {
454
454
  loadSessionStateSnapshotIntoStore,
455
455
  loadSnapshot,
456
456
  loopToHtmlElement,
457
+ markEventAsHandled,
457
458
  maybeSnapToGrid,
458
459
  normalizeWheel,
459
460
  openWindow,
@@ -517,6 +518,7 @@ export {
517
518
  useTransform,
518
519
  useUniqueSafeId,
519
520
  useViewportHeight,
520
- userTypeValidator
521
+ userTypeValidator,
522
+ wasEventAlreadyHandled
521
523
  };
522
524
  //# sourceMappingURL=index.mjs.map