@tldraw/editor 5.5.0-next.c25ed1f4cf7f → 5.5.0-next.c91b2de0a423

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 (187) hide show
  1. package/dist-cjs/index.d.ts +49 -23
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +16 -12
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/MenuClickCapture.js +42 -3
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -1
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +2 -5
  11. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +3 -3
  12. package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +2 -2
  13. package/dist-cjs/lib/editor/Editor.js +154 -173
  14. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  15. package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
  16. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -2
  18. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/EditorManager.js +11 -2
  20. package/dist-cjs/lib/editor/managers/EditorManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +49 -63
  22. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +2 -2
  23. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -1
  24. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
  25. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +24 -24
  26. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  27. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +7 -1
  28. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  29. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +4 -3
  30. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
  31. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +4 -4
  32. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  33. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  34. package/dist-cjs/lib/exports/ExportDelay.js +10 -2
  35. package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
  36. package/dist-cjs/lib/exports/FontEmbedder.js +25 -11
  37. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  38. package/dist-cjs/lib/exports/StyleEmbedder.js +9 -4
  39. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  40. package/dist-cjs/lib/exports/fetchCache.js +3 -0
  41. package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
  42. package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
  43. package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
  44. package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
  45. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  46. package/dist-cjs/lib/exports/parseCss.js +1 -1
  47. package/dist-cjs/lib/exports/parseCss.js.map +1 -1
  48. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  49. package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -0
  50. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  51. package/dist-cjs/lib/hooks/useIdentity.js +6 -2
  52. package/dist-cjs/lib/hooks/useIdentity.js.map +3 -3
  53. package/dist-cjs/lib/license/LicenseManager.js +9 -1
  54. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  55. package/dist-cjs/lib/license/LicenseProvider.js +12 -4
  56. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  57. package/dist-cjs/lib/utils/debug-flags.js +0 -6
  58. package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
  59. package/dist-cjs/lib/utils/deepLinks.js +2 -1
  60. package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
  61. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +19 -8
  62. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  63. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -0
  64. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  65. package/dist-cjs/version.js +3 -3
  66. package/dist-cjs/version.js.map +1 -1
  67. package/dist-esm/index.d.mts +49 -23
  68. package/dist-esm/index.mjs +4 -2
  69. package/dist-esm/index.mjs.map +2 -2
  70. package/dist-esm/lib/TldrawEditor.mjs +17 -13
  71. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  72. package/dist-esm/lib/components/MenuClickCapture.mjs +42 -3
  73. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  74. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -1
  75. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  76. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -5
  77. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +3 -3
  78. package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
  79. package/dist-esm/lib/editor/Editor.mjs +154 -173
  80. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  81. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
  82. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  83. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -2
  84. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  85. package/dist-esm/lib/editor/managers/EditorManager.mjs +11 -2
  86. package/dist-esm/lib/editor/managers/EditorManager.mjs.map +2 -2
  87. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +49 -63
  88. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +2 -2
  89. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -1
  90. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
  91. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +24 -24
  92. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  93. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +7 -1
  94. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  95. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +4 -3
  96. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
  97. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +4 -4
  98. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  99. package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
  100. package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
  101. package/dist-esm/lib/exports/FontEmbedder.mjs +25 -11
  102. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  103. package/dist-esm/lib/exports/StyleEmbedder.mjs +9 -4
  104. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  105. package/dist-esm/lib/exports/fetchCache.mjs +3 -0
  106. package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
  107. package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
  108. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
  109. package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
  110. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  111. package/dist-esm/lib/exports/parseCss.mjs +1 -1
  112. package/dist-esm/lib/exports/parseCss.mjs.map +1 -1
  113. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  114. package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -0
  115. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  116. package/dist-esm/lib/hooks/useIdentity.mjs +7 -3
  117. package/dist-esm/lib/hooks/useIdentity.mjs.map +3 -3
  118. package/dist-esm/lib/license/LicenseManager.mjs +9 -1
  119. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  120. package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
  121. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  122. package/dist-esm/lib/utils/debug-flags.mjs +0 -6
  123. package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
  124. package/dist-esm/lib/utils/deepLinks.mjs +2 -1
  125. package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
  126. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +19 -8
  127. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  128. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -0
  129. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  130. package/dist-esm/version.mjs +3 -3
  131. package/dist-esm/version.mjs.map +1 -1
  132. package/editor.css +9 -1
  133. package/package.json +8 -11
  134. package/src/index.ts +5 -1
  135. package/src/lib/TldrawEditor.tsx +35 -21
  136. package/src/lib/components/MenuClickCapture.tsx +55 -4
  137. package/src/lib/components/default-components/DefaultCanvas.tsx +7 -1
  138. package/src/lib/components/default-components/DefaultErrorFallback.tsx +13 -5
  139. package/src/lib/components/default-components/DefaultSpinner.tsx +4 -1
  140. package/src/lib/editor/Editor.test.ts +65 -0
  141. package/src/lib/editor/Editor.ts +230 -279
  142. package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
  143. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +1 -0
  144. package/src/lib/editor/managers/ClickManager/ClickManager.ts +3 -2
  145. package/src/lib/editor/managers/EditorManager.test.ts +32 -1
  146. package/src/lib/editor/managers/EditorManager.ts +15 -3
  147. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +80 -0
  148. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +54 -81
  149. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
  150. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +32 -36
  151. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +13 -2
  152. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -0
  153. package/src/lib/editor/managers/SnapManager/SnapManager.ts +6 -4
  154. package/src/lib/editor/managers/TextManager/TextManager.test.ts +74 -0
  155. package/src/lib/editor/managers/TextManager/TextManager.ts +6 -5
  156. package/src/lib/editor/types/external-content.ts +5 -0
  157. package/src/lib/exports/ExportDelay.tsx +16 -4
  158. package/src/lib/exports/FontEmbedder.test.ts +99 -0
  159. package/src/lib/exports/FontEmbedder.ts +32 -11
  160. package/src/lib/exports/StyleEmbedder.ts +13 -4
  161. package/src/lib/exports/fetchCache.test.ts +22 -0
  162. package/src/lib/exports/fetchCache.ts +4 -0
  163. package/src/lib/exports/getSvgAsImage.ts +13 -5
  164. package/src/lib/exports/getSvgJsx.test.ts +43 -1
  165. package/src/lib/exports/getSvgJsx.tsx +28 -16
  166. package/src/lib/exports/parseCss.test.ts +4 -0
  167. package/src/lib/exports/parseCss.ts +2 -2
  168. package/src/lib/hooks/EditorComponentsContext.tsx +2 -1
  169. package/src/lib/hooks/useCanvasEvents.ts +42 -0
  170. package/src/lib/hooks/useIdentity.tsx +12 -1
  171. package/src/lib/license/LicenseManager.ts +13 -1
  172. package/src/lib/license/LicenseProvider.test.tsx +76 -0
  173. package/src/lib/license/LicenseProvider.tsx +19 -5
  174. package/src/lib/test/preserveFocus.test.tsx +81 -0
  175. package/src/lib/utils/debug-flags.ts +0 -6
  176. package/src/lib/utils/deepLinks.test.ts +15 -0
  177. package/src/lib/utils/deepLinks.ts +8 -3
  178. package/src/lib/utils/sync/LocalIndexedDb.test.ts +93 -1
  179. package/src/lib/utils/sync/LocalIndexedDb.ts +23 -8
  180. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +21 -1
  181. package/src/lib/utils/sync/TLLocalSyncClient.ts +6 -0
  182. package/src/version.ts +3 -3
  183. package/dist-cjs/lib/primitives/geometry/geometry.bench.js +0 -133
  184. package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +0 -7
  185. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +0 -132
  186. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +0 -7
  187. package/src/lib/primitives/geometry/geometry.bench.ts +0 -179
@@ -95,6 +95,10 @@ var import_UserPreferencesManager = require("./managers/UserPreferencesManager/U
95
95
  var import_OverlayManager = require("./overlays/OverlayManager");
96
96
  var import_RootState = require("./tools/RootState");
97
97
  const RENDERING_SHAPES_SORT_CACHE_THRESHOLD = 100;
98
+ const AXIS = {
99
+ horizontal: { val: "x", min: "minX", max: "maxX", dim: "width" },
100
+ vertical: { val: "y", min: "minY", max: "maxY", dim: "height" }
101
+ };
98
102
  class Editor extends import_eventemitter3.default {
99
103
  id = (0, import_utils.uniqueId)();
100
104
  constructor({
@@ -421,7 +425,7 @@ class Editor extends import_eventemitter3.default {
421
425
  }
422
426
  }
423
427
  if (deleteBindingIds.length) {
424
- this.deleteBindings(deleteBindingIds);
428
+ this.store.remove(deleteBindingIds);
425
429
  }
426
430
  }
427
431
  },
@@ -1381,6 +1385,7 @@ class Editor extends import_eventemitter3.default {
1381
1385
  * @public
1382
1386
  **/
1383
1387
  updateDocumentSettings(settings) {
1388
+ if (this.getIsReadonly()) return this;
1384
1389
  this.run(
1385
1390
  () => {
1386
1391
  this.store.put([{ ...this.getDocumentSettings(), ...settings }]);
@@ -1403,7 +1408,7 @@ class Editor extends import_eventemitter3.default {
1403
1408
  updateInstanceState(partial, historyOptions) {
1404
1409
  this._updateInstanceState(partial, { history: "ignore", ...historyOptions });
1405
1410
  if (partial.isChangingStyle !== void 0) {
1406
- clearTimeout(this._isChangingStyleTimeout);
1411
+ this.timers.clearTimeout(this._isChangingStyleTimeout);
1407
1412
  if (partial.isChangingStyle === true) {
1408
1413
  this._isChangingStyleTimeout = this.timers.setTimeout(() => {
1409
1414
  this._updateInstanceState({ isChangingStyle: false }, { history: "ignore" });
@@ -1540,7 +1545,7 @@ class Editor extends import_eventemitter3.default {
1540
1545
  * @public
1541
1546
  */
1542
1547
  select(...shapes) {
1543
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
1548
+ const ids = toShapeIds(shapes);
1544
1549
  this.setSelectedShapes(ids);
1545
1550
  return this;
1546
1551
  }
@@ -1555,7 +1560,7 @@ class Editor extends import_eventemitter3.default {
1555
1560
  * @public
1556
1561
  */
1557
1562
  deselect(...shapes) {
1558
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
1563
+ const ids = toShapeIds(shapes);
1559
1564
  const selectedShapeIds = this.getSelectedShapeIds();
1560
1565
  if (selectedShapeIds.length > 0 && ids.length > 0) {
1561
1566
  this.setSelectedShapes(selectedShapeIds.filter((id) => !ids.includes(id)));
@@ -1593,7 +1598,7 @@ class Editor extends import_eventemitter3.default {
1593
1598
  }
1594
1599
  const ids = this.getSortedChildIdsForParent(parentToSelectWithinId);
1595
1600
  if (ids.length <= 0) return this;
1596
- this.setSelectedShapes(this._getUnlockedShapeIds(ids));
1601
+ this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked));
1597
1602
  return this;
1598
1603
  }
1599
1604
  /**
@@ -1720,13 +1725,14 @@ class Editor extends import_eventemitter3.default {
1720
1725
  });
1721
1726
  if (shapesInDirection.length === 0) return currentShapeId;
1722
1727
  const lowestScoringShape = (0, import_utils.minBy)(shapesInDirection, ({ center }) => {
1723
- const distance = import_Vec.Vec.Dist2(currentCenter, center);
1728
+ const distance = import_Vec.Vec.Dist(currentCenter, center);
1724
1729
  const dirProp = ["left", "right"].includes(direction) ? "x" : "y";
1725
1730
  const directionalDistance = Math.abs(center[dirProp] - currentCenter[dirProp]);
1726
1731
  const offProp = ["left", "right"].includes(direction) ? "y" : "x";
1727
1732
  const offAxisDeviation = Math.abs(center[offProp] - currentCenter[offProp]);
1728
- const angle = Math.abs(import_Vec.Vec.Angle(currentCenter, center) * (180 / Math.PI));
1729
- const angleDeviation = Math.abs(angle - directionToAngle[direction]);
1733
+ const angle = (import_Vec.Vec.Angle(currentCenter, center) * (180 / Math.PI) + 360) % 360;
1734
+ const rawAngleDeviation = Math.abs(angle - directionToAngle[direction]);
1735
+ const angleDeviation = Math.min(rawAngleDeviation, 360 - rawAngleDeviation);
1730
1736
  return distance * 1 + // Base distance
1731
1737
  offAxisDeviation * 2 + // Heavy penalty for off-axis deviation
1732
1738
  (distance - directionalDistance) * 1.5 + // Penalty for diagonal distance
@@ -2064,7 +2070,7 @@ class Editor extends import_eventemitter3.default {
2064
2070
  * @public
2065
2071
  */
2066
2072
  setHintingShapes(shapes) {
2067
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
2073
+ const ids = toShapeIds(shapes);
2068
2074
  this.run(
2069
2075
  () => {
2070
2076
  this._updateCurrentPageState({ hintingShapeIds: (0, import_utils.dedupe)(ids) });
@@ -2094,7 +2100,7 @@ class Editor extends import_eventemitter3.default {
2094
2100
  * @public
2095
2101
  */
2096
2102
  setErasingShapes(shapes) {
2097
- const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
2103
+ const ids = toShapeIds(shapes).slice();
2098
2104
  ids.sort();
2099
2105
  const erasingShapeIds = this.getErasingShapeIds();
2100
2106
  this.run(
@@ -2501,7 +2507,7 @@ class Editor extends import_eventemitter3.default {
2501
2507
  setCamera(point, opts) {
2502
2508
  const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
2503
2509
  if (isLocked && !opts?.force) return this;
2504
- const _point = import_Vec.Vec.Cast(point);
2510
+ const _point = new import_Vec.Vec(point.x, point.y, point.z ?? this.getZoomLevel());
2505
2511
  if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
2506
2512
  throw Error(
2507
2513
  `Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
@@ -2795,11 +2801,14 @@ class Editor extends import_eventemitter3.default {
2795
2801
  _animateViewport(ms) {
2796
2802
  if (!this._viewportAnimation) return;
2797
2803
  this._viewportAnimation.elapsed += ms;
2798
- const { elapsed, easing, duration, start, end } = this._viewportAnimation;
2804
+ const { elapsed, easing, duration, start, end, opts } = this._viewportAnimation;
2799
2805
  if (elapsed > duration) {
2800
2806
  this.off("tick", this._animateViewport);
2801
2807
  this._viewportAnimation = null;
2802
- this._setCamera(new import_Vec.Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width));
2808
+ this._setCamera(
2809
+ new import_Vec.Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width),
2810
+ opts
2811
+ );
2803
2812
  return;
2804
2813
  }
2805
2814
  const remaining = duration - elapsed;
@@ -2837,7 +2846,8 @@ class Editor extends import_eventemitter3.default {
2837
2846
  duration: duration / animationSpeed,
2838
2847
  easing,
2839
2848
  start: viewportPageBounds.clone(),
2840
- end: targetViewportPage.clone()
2849
+ end: targetViewportPage.clone(),
2850
+ opts: rest
2841
2851
  };
2842
2852
  this.once("stop-camera-animation", () => {
2843
2853
  this.off("tick", this._animateViewport);
@@ -3755,7 +3765,9 @@ class Editor extends import_eventemitter3.default {
3755
3765
  if (ids.length <= 0) return this;
3756
3766
  this.run(
3757
3767
  () => {
3758
- this.store.props.assets.remove?.(ids);
3768
+ Promise.resolve(this.store.props.assets.remove?.(ids)).catch(
3769
+ (err) => console.error("Error while removing assets from the asset store:", err)
3770
+ );
3759
3771
  this.store.remove(ids);
3760
3772
  },
3761
3773
  { history: "ignore" }
@@ -4137,7 +4149,7 @@ class Editor extends import_eventemitter3.default {
4137
4149
  if (shapes.length === 0) {
4138
4150
  return;
4139
4151
  }
4140
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4152
+ const ids = toShapeIds(shapes);
4141
4153
  const freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4142
4154
  if (freshShapes.length === 1) {
4143
4155
  const parentId = freshShapes[0].parentId;
@@ -4234,12 +4246,14 @@ class Editor extends import_eventemitter3.default {
4234
4246
  */
4235
4247
  getSelectedShapeAtPoint(point) {
4236
4248
  const selectedShapeIds = this.getSelectedShapeIds();
4237
- const margin = this.options.hitTestMargin / this.getZoomLevel();
4249
+ if (selectedShapeIds.length === 0) return void 0;
4250
+ const selectedShapeIdSet = new Set(selectedShapeIds);
4251
+ const margin = this.getHitTestMargin();
4238
4252
  const sortedShapes = this.getCurrentPageShapesSorted();
4239
4253
  for (let i = sortedShapes.length - 1; i >= 0; i--) {
4240
4254
  const shape = sortedShapes[i];
4241
4255
  if (shape.type === "group") continue;
4242
- if (!selectedShapeIds.includes(shape.id)) continue;
4256
+ if (!selectedShapeIdSet.has(shape.id)) continue;
4243
4257
  if (this.getShapeGeometry(shape).hitTestPoint(
4244
4258
  this.getPointInShapeSpace(shape, point),
4245
4259
  margin,
@@ -4337,7 +4351,6 @@ class Editor extends import_eventemitter3.default {
4337
4351
  }
4338
4352
  return inMarginClosestToEdgeHit || shape;
4339
4353
  } else {
4340
- if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
4341
4354
  if (hitInside ? (
4342
4355
  // On hitInside, the distance will be negative for hits inside
4343
4356
  // If the distance is positive, check against the outer margin
@@ -4354,6 +4367,7 @@ class Editor extends import_eventemitter3.default {
4354
4367
  inMarginClosestToEdgeHit = shape;
4355
4368
  }
4356
4369
  } else if (!inMarginClosestToEdgeHit) {
4370
+ if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
4357
4371
  const { area } = geometry;
4358
4372
  if (area < inHollowSmallestArea) {
4359
4373
  inHollowSmallestArea = area;
@@ -4364,6 +4378,9 @@ class Editor extends import_eventemitter3.default {
4364
4378
  }
4365
4379
  } else {
4366
4380
  if (distance < this.getHitTestMargin()) {
4381
+ if (inMarginClosestToEdgeHit && inMarginClosestToEdgeDistance <= distance) {
4382
+ return inMarginClosestToEdgeHit;
4383
+ }
4367
4384
  return shape;
4368
4385
  }
4369
4386
  }
@@ -4640,7 +4657,7 @@ class Editor extends import_eventemitter3.default {
4640
4657
  * @public
4641
4658
  */
4642
4659
  reparentShapes(shapes, parentId, insertIndex) {
4643
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4660
+ const ids = toShapeIds(shapes);
4644
4661
  if (ids.length === 0) return this;
4645
4662
  const changes = [];
4646
4663
  const parentTransform = (0, import_tlschema.isPageId)(parentId) ? import_Mat.Mat.Identity() : this.getShapePageTransform(parentId);
@@ -4869,6 +4886,7 @@ class Editor extends import_eventemitter3.default {
4869
4886
  * binding, but the `type`, `toId`, and `fromId` must all be provided.
4870
4887
  */
4871
4888
  createBindings(partials) {
4889
+ if (this.getIsReadonly()) return this;
4872
4890
  const bindings = [];
4873
4891
  for (const partial of partials) {
4874
4892
  const fromShape = this.getShape(partial.fromId);
@@ -4903,6 +4921,7 @@ class Editor extends import_eventemitter3.default {
4903
4921
  * binding is skipped. The changes from the partial are merged into the existing record.
4904
4922
  */
4905
4923
  updateBindings(partials) {
4924
+ if (this.getIsReadonly()) return this;
4906
4925
  const updated = [];
4907
4926
  for (const partial of partials) {
4908
4927
  if (!partial) continue;
@@ -4931,6 +4950,16 @@ class Editor extends import_eventemitter3.default {
4931
4950
  * Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
4932
4951
  */
4933
4952
  deleteBindings(bindings, { isolateShapes = false } = {}) {
4953
+ if (this.getIsReadonly()) return this;
4954
+ return this._deleteBindings(bindings, { isolateShapes });
4955
+ }
4956
+ /**
4957
+ * Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
4958
+ * readonly mode; the public deleteBindings is what readonly blocks.
4959
+ *
4960
+ * @internal
4961
+ */
4962
+ _deleteBindings(bindings, { isolateShapes = false } = {}) {
4934
4963
  const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
4935
4964
  if (isolateShapes) {
4936
4965
  this.store.atomic(() => {
@@ -4989,7 +5018,7 @@ class Editor extends import_eventemitter3.default {
4989
5018
  * @param opts - The options for the rotation.
4990
5019
  */
4991
5020
  rotateShapesBy(shapes, delta, opts) {
4992
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5021
+ const ids = toShapeIds(shapes);
4993
5022
  if (ids.length <= 0) return this;
4994
5023
  const snapshot = (0, import_rotation.getRotationSnapshot)({ editor: this, ids });
4995
5024
  if (!snapshot) return this;
@@ -5026,6 +5055,14 @@ class Editor extends import_eventemitter3.default {
5026
5055
  }
5027
5056
  return workingShape;
5028
5057
  }
5058
+ // Counter-rotates the page-space delta into the parent's space; without that a child of a rotated
5059
+ // frame or group would move along its parent's axes instead of the page's.
5060
+ // todo: a shape laid out together with its own parent moves twice, once with the parent and once
5061
+ // on its own; the layout commands should skip shapes whose ancestors are also being laid out
5062
+ getChangesToTranslateShapeByPageDelta(shape, pageDelta) {
5063
+ const localDelta = import_Vec.Vec.From(pageDelta).rot(-this.getShapeParentTransform(shape).rotation());
5064
+ return this.getChangesToTranslateShape(shape, localDelta.add(shape));
5065
+ }
5029
5066
  /**
5030
5067
  * Move shapes by a delta.
5031
5068
  *
@@ -5038,14 +5075,12 @@ class Editor extends import_eventemitter3.default {
5038
5075
  * @param offset - The offset to apply to the shapes.
5039
5076
  */
5040
5077
  nudgeShapes(shapes, offset) {
5041
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5078
+ const ids = toShapeIds(shapes);
5042
5079
  if (ids.length <= 0) return this;
5043
5080
  const changes = [];
5044
5081
  for (const id of ids) {
5045
5082
  const shape = this.getShape(id);
5046
- const localDelta = import_Vec.Vec.From(offset);
5047
- localDelta.rot(-this.getShapeParentTransform(shape).rotation());
5048
- changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
5083
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, offset));
5049
5084
  }
5050
5085
  this.updateShapes(changes);
5051
5086
  return this;
@@ -5066,7 +5101,7 @@ class Editor extends import_eventemitter3.default {
5066
5101
  */
5067
5102
  duplicateShapes(shapes, offset) {
5068
5103
  this.run(() => {
5069
- const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5104
+ const _ids = toShapeIds(shapes);
5070
5105
  const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
5071
5106
  if (ids.length <= 0) return this;
5072
5107
  const initialIds = new Set(ids);
@@ -5175,7 +5210,7 @@ class Editor extends import_eventemitter3.default {
5175
5210
  * @public
5176
5211
  */
5177
5212
  moveShapesToPage(shapes, pageId) {
5178
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5213
+ const ids = toShapeIds(shapes);
5179
5214
  if (ids.length === 0) return this;
5180
5215
  if (this.getIsReadonly()) return this;
5181
5216
  const currentPageId = this.getCurrentPageId();
@@ -5211,7 +5246,7 @@ class Editor extends import_eventemitter3.default {
5211
5246
  * @public
5212
5247
  */
5213
5248
  toggleLock(shapes) {
5214
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5249
+ const ids = toShapeIds(shapes);
5215
5250
  if (this.getIsReadonly() || ids.length === 0) return this;
5216
5251
  let allLocked = true;
5217
5252
  const shapesToToggle = [];
@@ -5250,7 +5285,7 @@ class Editor extends import_eventemitter3.default {
5250
5285
  * @public
5251
5286
  */
5252
5287
  sendToBack(shapes) {
5253
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5288
+ const ids = toShapeIds(shapes);
5254
5289
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toBack", ids, {
5255
5290
  considerAllShapes: true
5256
5291
  });
@@ -5280,7 +5315,7 @@ class Editor extends import_eventemitter3.default {
5280
5315
  * @public
5281
5316
  */
5282
5317
  sendBackward(shapes, opts = {}) {
5283
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5318
+ const ids = toShapeIds(shapes);
5284
5319
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "backward", ids, opts);
5285
5320
  if (changes) this.updateShapes(changes);
5286
5321
  return this;
@@ -5308,7 +5343,7 @@ class Editor extends import_eventemitter3.default {
5308
5343
  * @public
5309
5344
  */
5310
5345
  bringForward(shapes, opts = {}) {
5311
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5346
+ const ids = toShapeIds(shapes);
5312
5347
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "forward", ids, opts);
5313
5348
  if (changes) this.updateShapes(changes);
5314
5349
  return this;
@@ -5327,7 +5362,7 @@ class Editor extends import_eventemitter3.default {
5327
5362
  * @public
5328
5363
  */
5329
5364
  bringToFront(shapes) {
5330
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5365
+ const ids = toShapeIds(shapes);
5331
5366
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toFront", ids);
5332
5367
  if (changes) this.updateShapes(changes);
5333
5368
  return this;
@@ -5339,7 +5374,7 @@ class Editor extends import_eventemitter3.default {
5339
5374
  * @internal
5340
5375
  */
5341
5376
  getShapeClusters(shapes, type, opts) {
5342
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5377
+ const ids = toShapeIds(shapes);
5343
5378
  let freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5344
5379
  if (opts?.filterAxisAligned) {
5345
5380
  freshShapes = freshShapes.filter((s) => {
@@ -5420,7 +5455,7 @@ class Editor extends import_eventemitter3.default {
5420
5455
  */
5421
5456
  flipShapes(shapes, operation) {
5422
5457
  if (this.getIsReadonly()) return this;
5423
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5458
+ const ids = toShapeIds(shapes);
5424
5459
  const shapesToFlipFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5425
5460
  for (const shape of shapesToFlipFirstPass) {
5426
5461
  if (this.isShapeOfType(shape, "group")) {
@@ -5494,21 +5529,7 @@ class Editor extends import_eventemitter3.default {
5494
5529
  const { clusters: shapeClustersToStack } = this.getShapeClusters(shapes, "stack");
5495
5530
  const len = shapeClustersToStack.length;
5496
5531
  if (_gap === 0 && len < 3 || len < 2) return this;
5497
- let val;
5498
- let min;
5499
- let max;
5500
- let dim;
5501
- if (operation === "horizontal") {
5502
- val = "x";
5503
- min = "minX";
5504
- max = "maxX";
5505
- dim = "width";
5506
- } else {
5507
- val = "y";
5508
- min = "minY";
5509
- max = "maxY";
5510
- dim = "height";
5511
- }
5532
+ const { val, min, max, dim } = AXIS[operation];
5512
5533
  let shapeGap = 0;
5513
5534
  shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
5514
5535
  if (_gap === 0) {
@@ -5547,13 +5568,7 @@ class Editor extends import_eventemitter3.default {
5547
5568
  const delta = new import_Vec.Vec();
5548
5569
  delta[val] = v + shapeGap - pageBounds[val];
5549
5570
  for (const shape of shapes2) {
5550
- const shapeDelta = delta.clone();
5551
- const parent = this.getShapeParent(shape);
5552
- if (parent) {
5553
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5554
- }
5555
- shapeDelta.add(shape);
5556
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5571
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5557
5572
  }
5558
5573
  v += pageBounds[dim] + shapeGap;
5559
5574
  }
@@ -5633,13 +5648,7 @@ class Editor extends import_eventemitter3.default {
5633
5648
  for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
5634
5649
  const delta = import_Vec.Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
5635
5650
  for (const shape of shapes2) {
5636
- const shapeDelta = delta.clone();
5637
- const parent = this.getShapeParent(shape);
5638
- if (parent) {
5639
- shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
5640
- }
5641
- shapeDelta.add(shape);
5642
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5651
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5643
5652
  }
5644
5653
  }
5645
5654
  if (changes.length) {
@@ -5699,13 +5708,7 @@ class Editor extends import_eventemitter3.default {
5699
5708
  }
5700
5709
  }
5701
5710
  for (const shape of shapes2) {
5702
- const shapeDelta = delta.clone();
5703
- const parent = this.getShapeParent(shape);
5704
- if (parent) {
5705
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5706
- }
5707
- shapeDelta.add(shape);
5708
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5711
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5709
5712
  }
5710
5713
  });
5711
5714
  this.updateShapes(changes);
@@ -5729,27 +5732,13 @@ class Editor extends import_eventemitter3.default {
5729
5732
  if (this.getIsReadonly()) return this;
5730
5733
  const { clusters: shapeClustersToDistribute } = this.getShapeClusters(shapes, "distribute");
5731
5734
  if (shapeClustersToDistribute.length < 3) return this;
5732
- let val;
5733
- let min;
5734
- let max;
5735
- let dim;
5736
- if (operation === "horizontal") {
5737
- val = "x";
5738
- min = "minX";
5739
- max = "maxX";
5740
- dim = "width";
5741
- } else {
5742
- val = "y";
5743
- min = "minY";
5744
- max = "maxY";
5745
- dim = "height";
5746
- }
5735
+ const { val, min, max, dim } = AXIS[operation];
5747
5736
  const changes = [];
5748
5737
  const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
5749
5738
  const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
5750
5739
  if (first === last2) {
5751
5740
  const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
5752
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5741
+ const ids = toShapeIds(shapes);
5753
5742
  return this.distributeShapes(
5754
5743
  ids.filter((id) => !excludedShapeIds.has(id)),
5755
5744
  operation
@@ -5773,13 +5762,7 @@ class Editor extends import_eventemitter3.default {
5773
5762
  delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
5774
5763
  }
5775
5764
  for (const shape of shapes2) {
5776
- const shapeDelta = delta.clone();
5777
- const parent = this.getShapeParent(shape);
5778
- if (parent) {
5779
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5780
- }
5781
- shapeDelta.add(shape);
5782
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5765
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5783
5766
  }
5784
5767
  v += pageBounds[dim] + gap;
5785
5768
  }
@@ -5809,32 +5792,17 @@ class Editor extends import_eventemitter3.default {
5809
5792
  );
5810
5793
  if (shapeClustersToStretch.length < 2) return this;
5811
5794
  const commonBounds = import_Box.Box.Common(allBounds);
5812
- let val;
5813
- let min;
5814
- let dim;
5815
- if (operation === "horizontal") {
5816
- val = "x";
5817
- min = "minX";
5818
- dim = "width";
5819
- } else {
5820
- val = "y";
5821
- min = "minY";
5822
- dim = "height";
5823
- }
5795
+ const { val, min, dim } = AXIS[operation];
5824
5796
  this.run(() => {
5825
5797
  shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
5826
- const localOffset = new import_Vec.Vec();
5827
- localOffset[val] = commonBounds[min] - pageBounds[min];
5798
+ const pageOffset = new import_Vec.Vec();
5799
+ pageOffset[val] = commonBounds[min] - pageBounds[min];
5828
5800
  const scaleOrigin = pageBounds.center.clone();
5829
5801
  scaleOrigin[val] = commonBounds[min];
5830
5802
  const scale = new import_Vec.Vec(1, 1);
5831
5803
  scale[val] = commonBounds[dim] / pageBounds[dim];
5832
5804
  for (const shape of shapes2) {
5833
- const shapeLocalOffset = localOffset.clone();
5834
- shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
5835
- shapeLocalOffset.add(shape);
5836
- const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
5837
- this.updateShape(changes);
5805
+ this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
5838
5806
  this.resizeShape(shape.id, scale, {
5839
5807
  initialBounds: this.getShapeGeometry(shape).bounds,
5840
5808
  scaleOrigin,
@@ -5877,7 +5845,7 @@ class Editor extends import_eventemitter3.default {
5877
5845
  const scaleY = targetBounds.height / commonBounds.height;
5878
5846
  const scale = new import_Vec.Vec(scaleX, scaleY);
5879
5847
  shapeClusters.forEach(({ shapes: shapes2, pageBounds }) => {
5880
- const localOffset = new import_Vec.Vec(
5848
+ const pageOffset = new import_Vec.Vec(
5881
5849
  targetBounds.minX - commonBounds.minX + (pageBounds.minX - commonBounds.minX) * (scaleX - 1),
5882
5850
  targetBounds.minY - commonBounds.minY + (pageBounds.minY - commonBounds.minY) * (scaleY - 1)
5883
5851
  );
@@ -5886,11 +5854,7 @@ class Editor extends import_eventemitter3.default {
5886
5854
  targetBounds.minY + (pageBounds.minY - commonBounds.minY) * scaleY
5887
5855
  );
5888
5856
  for (const shape of shapes2) {
5889
- const shapeLocalOffset = localOffset.clone();
5890
- shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
5891
- shapeLocalOffset.add(shape);
5892
- const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
5893
- this.updateShape(changes);
5857
+ this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
5894
5858
  this.resizeShape(shape.id, scale, {
5895
5859
  initialBounds: this.getShapeGeometry(shape).bounds,
5896
5860
  scaleOrigin,
@@ -6309,12 +6273,17 @@ class Editor extends import_eventemitter3.default {
6309
6273
  let remaining = duration;
6310
6274
  let t;
6311
6275
  const animations = [];
6276
+ const ignoreShapeLock = this._shouldIgnoreShapeLock;
6312
6277
  let partial, result;
6313
6278
  for (let i = 0, n = partials.length; i < n; i++) {
6314
6279
  partial = partials[i];
6315
6280
  if (!partial) continue;
6316
6281
  const shape = this.getShape(partial.id);
6317
6282
  if (!shape) continue;
6283
+ const unlocks = shape.isLocked && Object.hasOwn(partial, "isLocked") && !partial.isLocked;
6284
+ if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
6285
+ continue;
6286
+ }
6318
6287
  result = {
6319
6288
  start: (0, import_utils.structuredClone)(shape),
6320
6289
  end: applyPartialToRecordWithProps((0, import_utils.structuredClone)(shape), partial)
@@ -6330,7 +6299,7 @@ class Editor extends import_eventemitter3.default {
6330
6299
  (p) => p && animatingShapes2.get(p.id) === animationId
6331
6300
  );
6332
6301
  if (partialsToUpdate.length) {
6333
- this.updateShapes(partialsToUpdate);
6302
+ this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
6334
6303
  }
6335
6304
  this.off("tick", handleTick);
6336
6305
  return;
@@ -6363,13 +6332,13 @@ class Editor extends import_eventemitter3.default {
6363
6332
  throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");
6364
6333
  }
6365
6334
  if (this.getIsReadonly()) return this;
6366
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6367
- if (ids.length <= 1) return this;
6335
+ const ids = toShapeIds(shapes);
6368
6336
  const shapesToGroup = (0, import_utils.compact)(
6369
6337
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6370
6338
  (id) => this.getShape(id)
6371
6339
  )
6372
6340
  );
6341
+ if (shapesToGroup.length <= 1) return this;
6373
6342
  const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
6374
6343
  const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
6375
6344
  const pageBounds = import_Box.Box.Common(childBounds);
@@ -6378,8 +6347,11 @@ class Editor extends import_eventemitter3.default {
6378
6347
  }
6379
6348
  const { x, y } = pageBounds.point;
6380
6349
  const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
6381
- if (this.getCurrentToolId() !== "select") return this;
6382
- if (!this.isIn("select.idle")) {
6350
+ if (!this.canCreateShapes([groupId])) {
6351
+ alertMaxShapes(this);
6352
+ return this;
6353
+ }
6354
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6383
6355
  this.cancel();
6384
6356
  }
6385
6357
  const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
@@ -6407,15 +6379,14 @@ class Editor extends import_eventemitter3.default {
6407
6379
  ungroupShapes(shapes, opts = {}) {
6408
6380
  if (this.getIsReadonly()) return this;
6409
6381
  const { select = true } = opts;
6410
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6382
+ const ids = toShapeIds(shapes);
6411
6383
  const shapesToUngroup = (0, import_utils.compact)(
6412
6384
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6413
6385
  (id) => this.getShape(id)
6414
6386
  )
6415
6387
  );
6416
6388
  if (shapesToUngroup.length === 0) return this;
6417
- if (this.getCurrentToolId() !== "select") return this;
6418
- if (!this.isIn("select.idle")) {
6389
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6419
6390
  this.cancel();
6420
6391
  }
6421
6392
  const idsToSelect = /* @__PURE__ */ new Set();
@@ -6429,16 +6400,16 @@ class Editor extends import_eventemitter3.default {
6429
6400
  });
6430
6401
  if (groups.length === 0) return this;
6431
6402
  this.run(() => {
6432
- let group;
6433
6403
  for (let i = 0, n = groups.length; i < n; i++) {
6434
- group = groups[i];
6404
+ const group = this.getShape(groups[i].id);
6405
+ if (!group) continue;
6435
6406
  const childIds = this.getSortedChildIdsForParent(group.id);
6436
6407
  for (let j = 0, n2 = childIds.length; j < n2; j++) {
6437
6408
  idsToSelect.add(childIds[j]);
6438
6409
  }
6439
6410
  this.reparentShapes(childIds, group.parentId, group.index);
6440
6411
  }
6441
- this.deleteShapes(groups.map((group2) => group2.id));
6412
+ this.deleteShapes(groups.map((group) => group.id));
6442
6413
  if (select) {
6443
6414
  this.select(...idsToSelect);
6444
6415
  }
@@ -6519,14 +6490,14 @@ class Editor extends import_eventemitter3.default {
6519
6490
  }
6520
6491
  /** @internal */
6521
6492
  _getUnlockedShapeIds(ids) {
6522
- return ids.filter((id) => !this.getShape(id)?.isLocked);
6493
+ return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
6523
6494
  }
6524
6495
  deleteShapes(_ids) {
6525
6496
  if (this.getIsReadonly()) return this;
6526
6497
  if (!Array.isArray(_ids)) {
6527
6498
  throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");
6528
6499
  }
6529
- const shapeIds = typeof _ids[0] === "string" ? _ids : _ids.map((s) => s.id);
6500
+ const shapeIds = toShapeIds(_ids);
6530
6501
  const shapeIdsToDelete = this._shouldIgnoreShapeLock ? shapeIds : this._getUnlockedShapeIds(shapeIds);
6531
6502
  if (shapeIdsToDelete.length === 0) return this;
6532
6503
  const allShapeIdsToDelete = new Set(shapeIdsToDelete);
@@ -6871,7 +6842,7 @@ class Editor extends import_eventemitter3.default {
6871
6842
  * @public
6872
6843
  */
6873
6844
  getContentFromCurrentPage(shapes) {
6874
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6845
+ const ids = toShapeIds(shapes);
6875
6846
  if (!ids) return;
6876
6847
  if (ids.length === 0) return;
6877
6848
  const shapeIds = this.getShapeAndDescendantIds(ids);
@@ -6939,21 +6910,29 @@ class Editor extends import_eventemitter3.default {
6939
6910
  await Promise.allSettled(
6940
6911
  content.assets.map(async (asset) => {
6941
6912
  if ((asset.type === "image" || asset.type === "video") && !asset.props.src?.startsWith("data:image") && !asset.props.src?.startsWith("data:video") && !asset.props.src?.startsWith("http")) {
6942
- const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6943
- const objectUrl = await this.store.props.assets.resolve(asset, {
6944
- screenScale: 1,
6945
- steppedScreenScale: 1,
6946
- dpr: 1,
6947
- networkEffectiveType: null,
6948
- shouldResolveToOriginal: true
6949
- });
6950
- assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(
6951
- await (0, import_utils.fetch)(objectUrl).then((r) => r.blob())
6952
- );
6953
- assets.push(assetWithDataUrl);
6954
- } else {
6955
- assets.push(asset);
6913
+ try {
6914
+ const objectUrl = await this.store.props.assets.resolve(asset, {
6915
+ screenScale: 1,
6916
+ steppedScreenScale: 1,
6917
+ dpr: 1,
6918
+ networkEffectiveType: null,
6919
+ shouldResolveToOriginal: true
6920
+ });
6921
+ if (objectUrl) {
6922
+ const response = await (0, import_utils.fetch)(objectUrl);
6923
+ if (response.ok) {
6924
+ const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6925
+ assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(await response.blob());
6926
+ assets.push(assetWithDataUrl);
6927
+ return;
6928
+ }
6929
+ console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`);
6930
+ }
6931
+ } catch (err) {
6932
+ console.warn(`Could not inline asset ${asset.id}`, err);
6933
+ }
6956
6934
  }
6935
+ assets.push(asset);
6957
6936
  })
6958
6937
  );
6959
6938
  content.assets = assets;
@@ -7247,7 +7226,7 @@ class Editor extends import_eventemitter3.default {
7247
7226
  * @public
7248
7227
  */
7249
7228
  async getSvgElement(shapes, opts = {}) {
7250
- const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
7229
+ const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes);
7251
7230
  if (ids.length === 0) return void 0;
7252
7231
  await this.fonts.loadRequiredFontsForCurrentPage(this.options.maxFontsToLoadBeforeRender);
7253
7232
  return (0, import_exportToSvg.exportToSvg)(this, ids, opts);
@@ -7843,22 +7822,22 @@ class Editor extends import_eventemitter3.default {
7843
7822
  const releaseCtrl = this._ctrlKeyTimeout !== -1;
7844
7823
  const releaseMeta = this._metaKeyTimeout !== -1;
7845
7824
  if (releaseShift) {
7846
- clearTimeout(this._shiftKeyTimeout);
7825
+ this.timers.clearTimeout(this._shiftKeyTimeout);
7847
7826
  this._shiftKeyTimeout = -1;
7848
7827
  this.inputs.setShiftKey(false);
7849
7828
  }
7850
7829
  if (releaseAlt) {
7851
- clearTimeout(this._altKeyTimeout);
7830
+ this.timers.clearTimeout(this._altKeyTimeout);
7852
7831
  this._altKeyTimeout = -1;
7853
7832
  this.inputs.setAltKey(false);
7854
7833
  }
7855
7834
  if (releaseCtrl) {
7856
- clearTimeout(this._ctrlKeyTimeout);
7835
+ this.timers.clearTimeout(this._ctrlKeyTimeout);
7857
7836
  this._ctrlKeyTimeout = -1;
7858
7837
  this.inputs.setCtrlKey(false);
7859
7838
  }
7860
7839
  if (releaseMeta) {
7861
- clearTimeout(this._metaKeyTimeout);
7840
+ this.timers.clearTimeout(this._metaKeyTimeout);
7862
7841
  this._metaKeyTimeout = -1;
7863
7842
  this.inputs.setMetaKey(false);
7864
7843
  }
@@ -7972,28 +7951,28 @@ class Editor extends import_eventemitter3.default {
7972
7951
  return;
7973
7952
  }
7974
7953
  if (info.shiftKey) {
7975
- clearTimeout(this._shiftKeyTimeout);
7954
+ this.timers.clearTimeout(this._shiftKeyTimeout);
7976
7955
  this._shiftKeyTimeout = -1;
7977
7956
  inputs.setShiftKey(true);
7978
7957
  } else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
7979
7958
  this._shiftKeyTimeout = this.timers.setTimeout(this._releaseShiftKey, 150);
7980
7959
  }
7981
7960
  if (info.altKey) {
7982
- clearTimeout(this._altKeyTimeout);
7961
+ this.timers.clearTimeout(this._altKeyTimeout);
7983
7962
  this._altKeyTimeout = -1;
7984
7963
  inputs.setAltKey(true);
7985
7964
  } else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
7986
7965
  this._altKeyTimeout = this.timers.setTimeout(this._releaseAltKey, 150);
7987
7966
  }
7988
7967
  if (info.ctrlKey) {
7989
- clearTimeout(this._ctrlKeyTimeout);
7968
+ this.timers.clearTimeout(this._ctrlKeyTimeout);
7990
7969
  this._ctrlKeyTimeout = -1;
7991
7970
  inputs.setCtrlKey(true);
7992
7971
  } else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
7993
7972
  this._ctrlKeyTimeout = this.timers.setTimeout(this._releaseCtrlKey, 150);
7994
7973
  }
7995
7974
  if (info.metaKey && info.name !== "key_up") {
7996
- clearTimeout(this._metaKeyTimeout);
7975
+ this.timers.clearTimeout(this._metaKeyTimeout);
7997
7976
  this._metaKeyTimeout = -1;
7998
7977
  inputs.setMetaKey(true);
7999
7978
  } else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
@@ -8007,8 +7986,7 @@ class Editor extends import_eventemitter3.default {
8007
7986
  const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
8008
7987
  switch (type) {
8009
7988
  case "pinch": {
8010
- if (cameraOptions.isLocked) return;
8011
- clearTimeout(this._longPressTimeout);
7989
+ this.timers.clearTimeout(this._longPressTimeout);
8012
7990
  this.inputs.updateFromEvent(info);
8013
7991
  switch (info.name) {
8014
7992
  case "pinch_start": {
@@ -8029,6 +8007,7 @@ class Editor extends import_eventemitter3.default {
8029
8007
  }
8030
8008
  case "pinch": {
8031
8009
  if (!inputs.getIsPinching()) return;
8010
+ if (cameraOptions.isLocked) return;
8032
8011
  const {
8033
8012
  point: { z = 1 },
8034
8013
  delta: { x: dx, y: dy }
@@ -8084,7 +8063,7 @@ class Editor extends import_eventemitter3.default {
8084
8063
  const { panSpeed, zoomSpeed } = cameraOptions;
8085
8064
  let wheelBehavior = cameraOptions.wheelBehavior;
8086
8065
  const inputMode = this.user.getUserPreferences().inputMode;
8087
- if (inputMode !== null) {
8066
+ if (inputMode !== null && wheelBehavior !== "none") {
8088
8067
  wheelBehavior = inputMode === "trackpad" ? "pan" : "zoom";
8089
8068
  }
8090
8069
  if (wheelBehavior !== "none") {
@@ -8136,12 +8115,12 @@ class Editor extends import_eventemitter3.default {
8136
8115
  }
8137
8116
  case "pointer": {
8138
8117
  if (inputs.getIsPinching()) return;
8139
- this.inputs.updateFromEvent(info);
8140
8118
  const { isPen } = info;
8141
8119
  const { isPenMode } = instanceState;
8120
+ if (isPenMode && !isPen) return;
8121
+ this.inputs.updateFromEvent(info);
8142
8122
  switch (info.name) {
8143
8123
  case "pointer_down": {
8144
- if (isPenMode && !isPen) return;
8145
8124
  this._releaseDebouncedModifiers();
8146
8125
  if (!this.inputs.getIsPanning()) {
8147
8126
  this._longPressTimeout = this.timers.setTimeout(() => {
@@ -8165,11 +8144,12 @@ class Editor extends import_eventemitter3.default {
8165
8144
  inputs.buttons.add(info.button);
8166
8145
  inputs.setIsPointing(true);
8167
8146
  inputs.setIsDragging(false);
8147
+ this.stopCameraAnimation();
8168
8148
  if (!isPenMode && info.isPenDirect) {
8169
8149
  this.updateInstanceState({ isPenMode: true });
8170
8150
  this.interrupt();
8171
8151
  }
8172
- if (info.button === import_constants.STYLUS_ERASER_BUTTON) {
8152
+ if (info.button === import_constants.STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
8173
8153
  this._restoreToolId = this.getCurrentToolId();
8174
8154
  this.complete();
8175
8155
  this.setCurrentTool("eraser");
@@ -8178,10 +8158,10 @@ class Editor extends import_eventemitter3.default {
8178
8158
  this._prevCursor = this.getInstanceState().cursor.type;
8179
8159
  }
8180
8160
  this.inputs.setIsPanning(true);
8181
- clearTimeout(this._longPressTimeout);
8161
+ this.timers.clearTimeout(this._longPressTimeout);
8182
8162
  } else if (info.button === import_constants.RIGHT_MOUSE_BUTTON && this.options.rightClickPanning) {
8183
8163
  this.inputs.setIsRightPointing(true);
8184
- clearTimeout(this._longPressTimeout);
8164
+ this.timers.clearTimeout(this._longPressTimeout);
8185
8165
  return this;
8186
8166
  }
8187
8167
  if (this.inputs.getIsPanning()) {
@@ -8192,7 +8172,6 @@ class Editor extends import_eventemitter3.default {
8192
8172
  break;
8193
8173
  }
8194
8174
  case "pointer_move": {
8195
- if (!isPen && isPenMode) return;
8196
8175
  const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
8197
8176
  if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
8198
8177
  const currentScreenPoint = this.inputs.getCurrentScreenPoint();
@@ -8223,16 +8202,15 @@ class Editor extends import_eventemitter3.default {
8223
8202
  }
8224
8203
  if (inputs.getIsPointing() && !inputs.getIsDragging() && import_Vec.Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
8225
8204
  inputs.setIsDragging(true);
8226
- clearTimeout(this._longPressTimeout);
8205
+ this.timers.clearTimeout(this._longPressTimeout);
8227
8206
  }
8228
8207
  break;
8229
8208
  }
8230
8209
  case "pointer_up": {
8231
8210
  inputs.setIsDragging(false);
8232
8211
  inputs.setIsPointing(false);
8233
- clearTimeout(this._longPressTimeout);
8212
+ this.timers.clearTimeout(this._longPressTimeout);
8234
8213
  inputs.buttons.delete(info.button);
8235
- if (instanceState.isPenMode && !isPen) return;
8236
8214
  if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
8237
8215
  this.inputs.setIsRightPointing(false);
8238
8216
  this._selectedShapeIdsAtPointerDown = [];
@@ -8288,7 +8266,7 @@ class Editor extends import_eventemitter3.default {
8288
8266
  });
8289
8267
  }
8290
8268
  } else {
8291
- if (info.button === import_constants.STYLUS_ERASER_BUTTON) {
8269
+ if (info.button === import_constants.STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
8292
8270
  this.complete();
8293
8271
  this.setCurrentTool(this._restoreToolId);
8294
8272
  }
@@ -8315,7 +8293,7 @@ class Editor extends import_eventemitter3.default {
8315
8293
  }
8316
8294
  this.inputs.setIsPanning(true);
8317
8295
  this.inputs.setIsSpacebarPanning(true);
8318
- clearTimeout(this._longPressTimeout);
8296
+ this.timers.clearTimeout(this._longPressTimeout);
8319
8297
  this.setCursor({
8320
8298
  type: this.inputs.getIsPointing() ? "grabbing" : "grab",
8321
8299
  rotation: 0
@@ -8341,7 +8319,7 @@ class Editor extends import_eventemitter3.default {
8341
8319
  break;
8342
8320
  }
8343
8321
  }
8344
- if (offset) {
8322
+ if (offset && !cameraOptions.isLocked) {
8345
8323
  const bounds = this.getViewportPageBounds();
8346
8324
  const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
8347
8325
  this._animateToViewport(next, { animation: { duration: 320 } });
@@ -8381,7 +8359,7 @@ class Editor extends import_eventemitter3.default {
8381
8359
  this.setCurrentTool("select");
8382
8360
  }
8383
8361
  const { isPenMode } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
8384
- if (info.isPen === isPenMode) {
8362
+ if (!isPenMode || info.isPen) {
8385
8363
  const clickInfo = this._clickManager.handlePointerEvent(info);
8386
8364
  if (info.name !== clickInfo.name) {
8387
8365
  this.root.handleEvent(info);
@@ -8403,7 +8381,7 @@ class Editor extends import_eventemitter3.default {
8403
8381
  maybeTrackPerformance(name) {
8404
8382
  if (import_debug_flags.debugFlags.measurePerformance.get()) {
8405
8383
  if (this.performanceTracker.isStarted()) {
8406
- clearTimeout(this.performanceTrackerTimeout);
8384
+ this.timers.clearTimeout(this.performanceTrackerTimeout);
8407
8385
  } else {
8408
8386
  this.performanceTracker.start(name);
8409
8387
  }
@@ -8672,6 +8650,9 @@ function pushShapeWithDescendants(editor, id, result) {
8672
8650
  pushShapeWithDescendants(editor, childIds[i], result);
8673
8651
  }
8674
8652
  }
8653
+ function toShapeIds(shapes) {
8654
+ return typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
8655
+ }
8675
8656
  function withIsolatedShapes(editor, shapeIds, callback) {
8676
8657
  let result;
8677
8658
  editor.run(
@@ -8694,7 +8675,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
8694
8675
  }
8695
8676
  }
8696
8677
  }
8697
- editor.deleteBindings([...bindingsToRemove], { isolateShapes: true });
8678
+ editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
8698
8679
  try {
8699
8680
  result = import_utils.Result.ok(callback(bindingsWithBoth));
8700
8681
  } catch (error) {