@tldraw/editor 5.5.0-canary.fa8dc460ac73 → 5.5.0-canary.fdb2d37fcb2a

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 (115) hide show
  1. package/dist-cjs/index.d.ts +2 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/TldrawEditor.js +16 -12
  4. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  5. package/dist-cjs/lib/components/MenuClickCapture.js +42 -3
  6. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  7. package/dist-cjs/lib/editor/Editor.js +132 -149
  8. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  9. package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
  10. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +4 -4
  12. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  13. package/dist-cjs/lib/exports/ExportDelay.js +10 -2
  14. package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
  15. package/dist-cjs/lib/exports/FontEmbedder.js +25 -11
  16. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  17. package/dist-cjs/lib/exports/StyleEmbedder.js +9 -4
  18. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  19. package/dist-cjs/lib/exports/fetchCache.js +3 -0
  20. package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
  21. package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
  22. package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
  23. package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
  24. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  25. package/dist-cjs/lib/exports/parseCss.js +1 -1
  26. package/dist-cjs/lib/exports/parseCss.js.map +1 -1
  27. package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -0
  28. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  29. package/dist-cjs/lib/hooks/useIdentity.js +6 -2
  30. package/dist-cjs/lib/hooks/useIdentity.js.map +3 -3
  31. package/dist-cjs/lib/license/LicenseManager.js +9 -1
  32. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  33. package/dist-cjs/lib/license/LicenseProvider.js +12 -4
  34. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  35. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +13 -17
  36. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  37. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +78 -40
  38. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  39. package/dist-cjs/version.js +3 -3
  40. package/dist-cjs/version.js.map +1 -1
  41. package/dist-esm/index.d.mts +2 -0
  42. package/dist-esm/index.mjs +1 -1
  43. package/dist-esm/lib/TldrawEditor.mjs +17 -13
  44. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  45. package/dist-esm/lib/components/MenuClickCapture.mjs +42 -3
  46. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  47. package/dist-esm/lib/editor/Editor.mjs +132 -149
  48. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  49. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
  50. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  51. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +4 -4
  52. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  53. package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
  54. package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
  55. package/dist-esm/lib/exports/FontEmbedder.mjs +25 -11
  56. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  57. package/dist-esm/lib/exports/StyleEmbedder.mjs +9 -4
  58. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  59. package/dist-esm/lib/exports/fetchCache.mjs +3 -0
  60. package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
  61. package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
  62. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
  63. package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
  64. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  65. package/dist-esm/lib/exports/parseCss.mjs +1 -1
  66. package/dist-esm/lib/exports/parseCss.mjs.map +1 -1
  67. package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -0
  68. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  69. package/dist-esm/lib/hooks/useIdentity.mjs +7 -3
  70. package/dist-esm/lib/hooks/useIdentity.mjs.map +3 -3
  71. package/dist-esm/lib/license/LicenseManager.mjs +9 -1
  72. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  73. package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
  74. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  75. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +13 -17
  76. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  77. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +78 -40
  78. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  79. package/dist-esm/version.mjs +3 -3
  80. package/dist-esm/version.mjs.map +1 -1
  81. package/package.json +8 -11
  82. package/src/lib/TldrawEditor.tsx +27 -15
  83. package/src/lib/components/MenuClickCapture.tsx +55 -4
  84. package/src/lib/editor/Editor.test.ts +20 -0
  85. package/src/lib/editor/Editor.ts +201 -252
  86. package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
  87. package/src/lib/editor/managers/TextManager/TextManager.test.ts +74 -0
  88. package/src/lib/editor/managers/TextManager/TextManager.ts +6 -5
  89. package/src/lib/exports/ExportDelay.tsx +16 -4
  90. package/src/lib/exports/FontEmbedder.test.ts +99 -0
  91. package/src/lib/exports/FontEmbedder.ts +32 -11
  92. package/src/lib/exports/StyleEmbedder.ts +13 -4
  93. package/src/lib/exports/fetchCache.test.ts +22 -0
  94. package/src/lib/exports/fetchCache.ts +4 -0
  95. package/src/lib/exports/getSvgAsImage.ts +13 -5
  96. package/src/lib/exports/getSvgJsx.test.ts +43 -1
  97. package/src/lib/exports/getSvgJsx.tsx +28 -16
  98. package/src/lib/exports/parseCss.test.ts +4 -0
  99. package/src/lib/exports/parseCss.ts +2 -2
  100. package/src/lib/hooks/useCanvasEvents.ts +42 -0
  101. package/src/lib/hooks/useIdentity.tsx +12 -1
  102. package/src/lib/license/LicenseManager.ts +13 -1
  103. package/src/lib/license/LicenseProvider.test.tsx +76 -0
  104. package/src/lib/license/LicenseProvider.tsx +19 -5
  105. package/src/lib/test/preserveFocus.test.tsx +81 -0
  106. package/src/lib/utils/sync/LocalIndexedDb.test.ts +28 -0
  107. package/src/lib/utils/sync/LocalIndexedDb.ts +18 -20
  108. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +236 -0
  109. package/src/lib/utils/sync/TLLocalSyncClient.ts +106 -54
  110. package/src/version.ts +3 -3
  111. package/dist-cjs/lib/primitives/geometry/geometry.bench.js +0 -133
  112. package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +0 -7
  113. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +0 -132
  114. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +0 -7
  115. 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 }]);
@@ -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
  /**
@@ -1610,12 +1615,15 @@ class Editor extends import_eventemitter3.default {
1610
1615
  const selectedShapeIds = this.getSelectedShapeIds();
1611
1616
  const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
1612
1617
  const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !(0, import_tlschema.isPageId)(firstParentId);
1613
- const filteredShapes = isSelectedWithinContainer ? this.getCurrentPageShapes().filter((shape2) => shape2.parentId === firstParentId) : this.getCurrentPageShapes().filter((shape2) => (0, import_tlschema.isPageId)(shape2.parentId));
1614
- const readingOrderShapes = isSelectedWithinContainer ? this._getShapesInReadingOrder(filteredShapes) : this.getCurrentPageShapesInReadingOrder();
1618
+ const filteredShapes = this.getCurrentPageShapes().filter(
1619
+ (shape2) => !this.isShapeOrAncestorLocked(shape2) && (isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId))
1620
+ );
1621
+ const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
1615
1622
  const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
1616
1623
  let adjacentShapeId;
1617
1624
  if (direction === "next" || direction === "prev") {
1618
1625
  const shapeIds = readingOrderShapes.map((shape2) => shape2.id);
1626
+ if (shapeIds.length === 0) return;
1619
1627
  const currentIndex = currentShapeId ? shapeIds.indexOf(currentShapeId) : -1;
1620
1628
  const startIndex = currentIndex === -1 && direction === "prev" ? 0 : currentIndex;
1621
1629
  const adjacentIndex = (startIndex + (direction === "next" ? 1 : -1) + shapeIds.length) % shapeIds.length;
@@ -1717,13 +1725,14 @@ class Editor extends import_eventemitter3.default {
1717
1725
  });
1718
1726
  if (shapesInDirection.length === 0) return currentShapeId;
1719
1727
  const lowestScoringShape = (0, import_utils.minBy)(shapesInDirection, ({ center }) => {
1720
- const distance = import_Vec.Vec.Dist2(currentCenter, center);
1728
+ const distance = import_Vec.Vec.Dist(currentCenter, center);
1721
1729
  const dirProp = ["left", "right"].includes(direction) ? "x" : "y";
1722
1730
  const directionalDistance = Math.abs(center[dirProp] - currentCenter[dirProp]);
1723
1731
  const offProp = ["left", "right"].includes(direction) ? "y" : "x";
1724
1732
  const offAxisDeviation = Math.abs(center[offProp] - currentCenter[offProp]);
1725
- const angle = Math.abs(import_Vec.Vec.Angle(currentCenter, center) * (180 / Math.PI));
1726
- 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);
1727
1736
  return distance * 1 + // Base distance
1728
1737
  offAxisDeviation * 2 + // Heavy penalty for off-axis deviation
1729
1738
  (distance - directionalDistance) * 1.5 + // Penalty for diagonal distance
@@ -2061,7 +2070,7 @@ class Editor extends import_eventemitter3.default {
2061
2070
  * @public
2062
2071
  */
2063
2072
  setHintingShapes(shapes) {
2064
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
2073
+ const ids = toShapeIds(shapes);
2065
2074
  this.run(
2066
2075
  () => {
2067
2076
  this._updateCurrentPageState({ hintingShapeIds: (0, import_utils.dedupe)(ids) });
@@ -2091,7 +2100,7 @@ class Editor extends import_eventemitter3.default {
2091
2100
  * @public
2092
2101
  */
2093
2102
  setErasingShapes(shapes) {
2094
- const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
2103
+ const ids = toShapeIds(shapes).slice();
2095
2104
  ids.sort();
2096
2105
  const erasingShapeIds = this.getErasingShapeIds();
2097
2106
  this.run(
@@ -2498,7 +2507,7 @@ class Editor extends import_eventemitter3.default {
2498
2507
  setCamera(point, opts) {
2499
2508
  const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
2500
2509
  if (isLocked && !opts?.force) return this;
2501
- const _point = import_Vec.Vec.Cast(point);
2510
+ const _point = new import_Vec.Vec(point.x, point.y, point.z ?? this.getZoomLevel());
2502
2511
  if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
2503
2512
  throw Error(
2504
2513
  `Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
@@ -2920,6 +2929,7 @@ class Editor extends import_eventemitter3.default {
2920
2929
  }
2921
2930
  const isOnSamePage = presence.currentPageId === this.getCurrentPageId();
2922
2931
  if (!isOnSamePage) {
2932
+ this.markHistoryStoppingPoint("change-page");
2923
2933
  this.setCurrentPage(presence.currentPageId);
2924
2934
  }
2925
2935
  if (opts && opts.animation && !isOnSamePage) {
@@ -3751,7 +3761,9 @@ class Editor extends import_eventemitter3.default {
3751
3761
  if (ids.length <= 0) return this;
3752
3762
  this.run(
3753
3763
  () => {
3754
- this.store.props.assets.remove?.(ids);
3764
+ Promise.resolve(this.store.props.assets.remove?.(ids)).catch(
3765
+ (err) => console.error("Error while removing assets from the asset store:", err)
3766
+ );
3755
3767
  this.store.remove(ids);
3756
3768
  },
3757
3769
  { history: "ignore" }
@@ -4133,7 +4145,7 @@ class Editor extends import_eventemitter3.default {
4133
4145
  if (shapes.length === 0) {
4134
4146
  return;
4135
4147
  }
4136
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4148
+ const ids = toShapeIds(shapes);
4137
4149
  const freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4138
4150
  if (freshShapes.length === 1) {
4139
4151
  const parentId = freshShapes[0].parentId;
@@ -4230,12 +4242,14 @@ class Editor extends import_eventemitter3.default {
4230
4242
  */
4231
4243
  getSelectedShapeAtPoint(point) {
4232
4244
  const selectedShapeIds = this.getSelectedShapeIds();
4233
- const margin = this.options.hitTestMargin / this.getZoomLevel();
4245
+ if (selectedShapeIds.length === 0) return void 0;
4246
+ const selectedShapeIdSet = new Set(selectedShapeIds);
4247
+ const margin = this.getHitTestMargin();
4234
4248
  const sortedShapes = this.getCurrentPageShapesSorted();
4235
4249
  for (let i = sortedShapes.length - 1; i >= 0; i--) {
4236
4250
  const shape = sortedShapes[i];
4237
4251
  if (shape.type === "group") continue;
4238
- if (!selectedShapeIds.includes(shape.id)) continue;
4252
+ if (!selectedShapeIdSet.has(shape.id)) continue;
4239
4253
  if (this.getShapeGeometry(shape).hitTestPoint(
4240
4254
  this.getPointInShapeSpace(shape, point),
4241
4255
  margin,
@@ -4333,7 +4347,6 @@ class Editor extends import_eventemitter3.default {
4333
4347
  }
4334
4348
  return inMarginClosestToEdgeHit || shape;
4335
4349
  } else {
4336
- if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
4337
4350
  if (hitInside ? (
4338
4351
  // On hitInside, the distance will be negative for hits inside
4339
4352
  // If the distance is positive, check against the outer margin
@@ -4350,6 +4363,7 @@ class Editor extends import_eventemitter3.default {
4350
4363
  inMarginClosestToEdgeHit = shape;
4351
4364
  }
4352
4365
  } else if (!inMarginClosestToEdgeHit) {
4366
+ if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
4353
4367
  const { area } = geometry;
4354
4368
  if (area < inHollowSmallestArea) {
4355
4369
  inHollowSmallestArea = area;
@@ -4360,6 +4374,9 @@ class Editor extends import_eventemitter3.default {
4360
4374
  }
4361
4375
  } else {
4362
4376
  if (distance < this.getHitTestMargin()) {
4377
+ if (inMarginClosestToEdgeHit && inMarginClosestToEdgeDistance <= distance) {
4378
+ return inMarginClosestToEdgeHit;
4379
+ }
4363
4380
  return shape;
4364
4381
  }
4365
4382
  }
@@ -4636,7 +4653,7 @@ class Editor extends import_eventemitter3.default {
4636
4653
  * @public
4637
4654
  */
4638
4655
  reparentShapes(shapes, parentId, insertIndex) {
4639
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4656
+ const ids = toShapeIds(shapes);
4640
4657
  if (ids.length === 0) return this;
4641
4658
  const changes = [];
4642
4659
  const parentTransform = (0, import_tlschema.isPageId)(parentId) ? import_Mat.Mat.Identity() : this.getShapePageTransform(parentId);
@@ -4865,6 +4882,7 @@ class Editor extends import_eventemitter3.default {
4865
4882
  * binding, but the `type`, `toId`, and `fromId` must all be provided.
4866
4883
  */
4867
4884
  createBindings(partials) {
4885
+ if (this.getIsReadonly()) return this;
4868
4886
  const bindings = [];
4869
4887
  for (const partial of partials) {
4870
4888
  const fromShape = this.getShape(partial.fromId);
@@ -4899,6 +4917,7 @@ class Editor extends import_eventemitter3.default {
4899
4917
  * binding is skipped. The changes from the partial are merged into the existing record.
4900
4918
  */
4901
4919
  updateBindings(partials) {
4920
+ if (this.getIsReadonly()) return this;
4902
4921
  const updated = [];
4903
4922
  for (const partial of partials) {
4904
4923
  if (!partial) continue;
@@ -4927,6 +4946,16 @@ class Editor extends import_eventemitter3.default {
4927
4946
  * Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
4928
4947
  */
4929
4948
  deleteBindings(bindings, { isolateShapes = false } = {}) {
4949
+ if (this.getIsReadonly()) return this;
4950
+ return this._deleteBindings(bindings, { isolateShapes });
4951
+ }
4952
+ /**
4953
+ * Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
4954
+ * readonly mode; the public deleteBindings is what readonly blocks.
4955
+ *
4956
+ * @internal
4957
+ */
4958
+ _deleteBindings(bindings, { isolateShapes = false } = {}) {
4930
4959
  const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
4931
4960
  if (isolateShapes) {
4932
4961
  this.store.atomic(() => {
@@ -4985,7 +5014,7 @@ class Editor extends import_eventemitter3.default {
4985
5014
  * @param opts - The options for the rotation.
4986
5015
  */
4987
5016
  rotateShapesBy(shapes, delta, opts) {
4988
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5017
+ const ids = toShapeIds(shapes);
4989
5018
  if (ids.length <= 0) return this;
4990
5019
  const snapshot = (0, import_rotation.getRotationSnapshot)({ editor: this, ids });
4991
5020
  if (!snapshot) return this;
@@ -5022,6 +5051,14 @@ class Editor extends import_eventemitter3.default {
5022
5051
  }
5023
5052
  return workingShape;
5024
5053
  }
5054
+ // Counter-rotates the page-space delta into the parent's space; without that a child of a rotated
5055
+ // frame or group would move along its parent's axes instead of the page's.
5056
+ // todo: a shape laid out together with its own parent moves twice, once with the parent and once
5057
+ // on its own; the layout commands should skip shapes whose ancestors are also being laid out
5058
+ getChangesToTranslateShapeByPageDelta(shape, pageDelta) {
5059
+ const localDelta = import_Vec.Vec.From(pageDelta).rot(-this.getShapeParentTransform(shape).rotation());
5060
+ return this.getChangesToTranslateShape(shape, localDelta.add(shape));
5061
+ }
5025
5062
  /**
5026
5063
  * Move shapes by a delta.
5027
5064
  *
@@ -5034,14 +5071,12 @@ class Editor extends import_eventemitter3.default {
5034
5071
  * @param offset - The offset to apply to the shapes.
5035
5072
  */
5036
5073
  nudgeShapes(shapes, offset) {
5037
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5074
+ const ids = toShapeIds(shapes);
5038
5075
  if (ids.length <= 0) return this;
5039
5076
  const changes = [];
5040
5077
  for (const id of ids) {
5041
5078
  const shape = this.getShape(id);
5042
- const localDelta = import_Vec.Vec.From(offset);
5043
- localDelta.rot(-this.getShapeParentTransform(shape).rotation());
5044
- changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
5079
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, offset));
5045
5080
  }
5046
5081
  this.updateShapes(changes);
5047
5082
  return this;
@@ -5062,7 +5097,7 @@ class Editor extends import_eventemitter3.default {
5062
5097
  */
5063
5098
  duplicateShapes(shapes, offset) {
5064
5099
  this.run(() => {
5065
- const _ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5100
+ const _ids = toShapeIds(shapes);
5066
5101
  const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
5067
5102
  if (ids.length <= 0) return this;
5068
5103
  const initialIds = new Set(ids);
@@ -5171,7 +5206,7 @@ class Editor extends import_eventemitter3.default {
5171
5206
  * @public
5172
5207
  */
5173
5208
  moveShapesToPage(shapes, pageId) {
5174
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5209
+ const ids = toShapeIds(shapes);
5175
5210
  if (ids.length === 0) return this;
5176
5211
  if (this.getIsReadonly()) return this;
5177
5212
  const currentPageId = this.getCurrentPageId();
@@ -5207,7 +5242,7 @@ class Editor extends import_eventemitter3.default {
5207
5242
  * @public
5208
5243
  */
5209
5244
  toggleLock(shapes) {
5210
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5245
+ const ids = toShapeIds(shapes);
5211
5246
  if (this.getIsReadonly() || ids.length === 0) return this;
5212
5247
  let allLocked = true;
5213
5248
  const shapesToToggle = [];
@@ -5246,7 +5281,7 @@ class Editor extends import_eventemitter3.default {
5246
5281
  * @public
5247
5282
  */
5248
5283
  sendToBack(shapes) {
5249
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5284
+ const ids = toShapeIds(shapes);
5250
5285
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toBack", ids, {
5251
5286
  considerAllShapes: true
5252
5287
  });
@@ -5276,7 +5311,7 @@ class Editor extends import_eventemitter3.default {
5276
5311
  * @public
5277
5312
  */
5278
5313
  sendBackward(shapes, opts = {}) {
5279
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5314
+ const ids = toShapeIds(shapes);
5280
5315
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "backward", ids, opts);
5281
5316
  if (changes) this.updateShapes(changes);
5282
5317
  return this;
@@ -5304,7 +5339,7 @@ class Editor extends import_eventemitter3.default {
5304
5339
  * @public
5305
5340
  */
5306
5341
  bringForward(shapes, opts = {}) {
5307
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5342
+ const ids = toShapeIds(shapes);
5308
5343
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "forward", ids, opts);
5309
5344
  if (changes) this.updateShapes(changes);
5310
5345
  return this;
@@ -5323,7 +5358,7 @@ class Editor extends import_eventemitter3.default {
5323
5358
  * @public
5324
5359
  */
5325
5360
  bringToFront(shapes) {
5326
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5361
+ const ids = toShapeIds(shapes);
5327
5362
  const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toFront", ids);
5328
5363
  if (changes) this.updateShapes(changes);
5329
5364
  return this;
@@ -5335,7 +5370,7 @@ class Editor extends import_eventemitter3.default {
5335
5370
  * @internal
5336
5371
  */
5337
5372
  getShapeClusters(shapes, type, opts) {
5338
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5373
+ const ids = toShapeIds(shapes);
5339
5374
  let freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5340
5375
  if (opts?.filterAxisAligned) {
5341
5376
  freshShapes = freshShapes.filter((s) => {
@@ -5360,7 +5395,7 @@ class Editor extends import_eventemitter3.default {
5360
5395
  const shapesMovingTogether = [shape];
5361
5396
  const boundsOfShapesMovingTogether = [shapePageBounds];
5362
5397
  this.collectShapesViaArrowBindings({
5363
- bindings: this.getBindingsToShape(shape.id, "arrow"),
5398
+ bindings: this.getBindingsInvolvingShape(shape.id, "arrow"),
5364
5399
  initialShapes: freshShapes,
5365
5400
  resultShapes: shapesMovingTogether,
5366
5401
  resultBounds: boundsOfShapesMovingTogether,
@@ -5416,7 +5451,7 @@ class Editor extends import_eventemitter3.default {
5416
5451
  */
5417
5452
  flipShapes(shapes, operation) {
5418
5453
  if (this.getIsReadonly()) return this;
5419
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5454
+ const ids = toShapeIds(shapes);
5420
5455
  const shapesToFlipFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5421
5456
  for (const shape of shapesToFlipFirstPass) {
5422
5457
  if (this.isShapeOfType(shape, "group")) {
@@ -5490,21 +5525,7 @@ class Editor extends import_eventemitter3.default {
5490
5525
  const { clusters: shapeClustersToStack } = this.getShapeClusters(shapes, "stack");
5491
5526
  const len = shapeClustersToStack.length;
5492
5527
  if (_gap === 0 && len < 3 || len < 2) return this;
5493
- let val;
5494
- let min;
5495
- let max;
5496
- let dim;
5497
- if (operation === "horizontal") {
5498
- val = "x";
5499
- min = "minX";
5500
- max = "maxX";
5501
- dim = "width";
5502
- } else {
5503
- val = "y";
5504
- min = "minY";
5505
- max = "maxY";
5506
- dim = "height";
5507
- }
5528
+ const { val, min, max, dim } = AXIS[operation];
5508
5529
  let shapeGap = 0;
5509
5530
  shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
5510
5531
  if (_gap === 0) {
@@ -5543,13 +5564,7 @@ class Editor extends import_eventemitter3.default {
5543
5564
  const delta = new import_Vec.Vec();
5544
5565
  delta[val] = v + shapeGap - pageBounds[val];
5545
5566
  for (const shape of shapes2) {
5546
- const shapeDelta = delta.clone();
5547
- const parent = this.getShapeParent(shape);
5548
- if (parent) {
5549
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5550
- }
5551
- shapeDelta.add(shape);
5552
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5567
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5553
5568
  }
5554
5569
  v += pageBounds[dim] + shapeGap;
5555
5570
  }
@@ -5629,13 +5644,7 @@ class Editor extends import_eventemitter3.default {
5629
5644
  for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
5630
5645
  const delta = import_Vec.Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
5631
5646
  for (const shape of shapes2) {
5632
- const shapeDelta = delta.clone();
5633
- const parent = this.getShapeParent(shape);
5634
- if (parent) {
5635
- shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
5636
- }
5637
- shapeDelta.add(shape);
5638
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5647
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5639
5648
  }
5640
5649
  }
5641
5650
  if (changes.length) {
@@ -5695,13 +5704,7 @@ class Editor extends import_eventemitter3.default {
5695
5704
  }
5696
5705
  }
5697
5706
  for (const shape of shapes2) {
5698
- const shapeDelta = delta.clone();
5699
- const parent = this.getShapeParent(shape);
5700
- if (parent) {
5701
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5702
- }
5703
- shapeDelta.add(shape);
5704
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5707
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5705
5708
  }
5706
5709
  });
5707
5710
  this.updateShapes(changes);
@@ -5725,27 +5728,13 @@ class Editor extends import_eventemitter3.default {
5725
5728
  if (this.getIsReadonly()) return this;
5726
5729
  const { clusters: shapeClustersToDistribute } = this.getShapeClusters(shapes, "distribute");
5727
5730
  if (shapeClustersToDistribute.length < 3) return this;
5728
- let val;
5729
- let min;
5730
- let max;
5731
- let dim;
5732
- if (operation === "horizontal") {
5733
- val = "x";
5734
- min = "minX";
5735
- max = "maxX";
5736
- dim = "width";
5737
- } else {
5738
- val = "y";
5739
- min = "minY";
5740
- max = "maxY";
5741
- dim = "height";
5742
- }
5731
+ const { val, min, max, dim } = AXIS[operation];
5743
5732
  const changes = [];
5744
5733
  const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
5745
5734
  const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
5746
5735
  if (first === last2) {
5747
5736
  const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
5748
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5737
+ const ids = toShapeIds(shapes);
5749
5738
  return this.distributeShapes(
5750
5739
  ids.filter((id) => !excludedShapeIds.has(id)),
5751
5740
  operation
@@ -5769,13 +5758,7 @@ class Editor extends import_eventemitter3.default {
5769
5758
  delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
5770
5759
  }
5771
5760
  for (const shape of shapes2) {
5772
- const shapeDelta = delta.clone();
5773
- const parent = this.getShapeParent(shape);
5774
- if (parent) {
5775
- shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
5776
- }
5777
- shapeDelta.add(shape);
5778
- changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5761
+ changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
5779
5762
  }
5780
5763
  v += pageBounds[dim] + gap;
5781
5764
  }
@@ -5805,32 +5788,17 @@ class Editor extends import_eventemitter3.default {
5805
5788
  );
5806
5789
  if (shapeClustersToStretch.length < 2) return this;
5807
5790
  const commonBounds = import_Box.Box.Common(allBounds);
5808
- let val;
5809
- let min;
5810
- let dim;
5811
- if (operation === "horizontal") {
5812
- val = "x";
5813
- min = "minX";
5814
- dim = "width";
5815
- } else {
5816
- val = "y";
5817
- min = "minY";
5818
- dim = "height";
5819
- }
5791
+ const { val, min, dim } = AXIS[operation];
5820
5792
  this.run(() => {
5821
5793
  shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
5822
- const localOffset = new import_Vec.Vec();
5823
- localOffset[val] = commonBounds[min] - pageBounds[min];
5794
+ const pageOffset = new import_Vec.Vec();
5795
+ pageOffset[val] = commonBounds[min] - pageBounds[min];
5824
5796
  const scaleOrigin = pageBounds.center.clone();
5825
5797
  scaleOrigin[val] = commonBounds[min];
5826
5798
  const scale = new import_Vec.Vec(1, 1);
5827
5799
  scale[val] = commonBounds[dim] / pageBounds[dim];
5828
5800
  for (const shape of shapes2) {
5829
- const shapeLocalOffset = localOffset.clone();
5830
- shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
5831
- shapeLocalOffset.add(shape);
5832
- const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
5833
- this.updateShape(changes);
5801
+ this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
5834
5802
  this.resizeShape(shape.id, scale, {
5835
5803
  initialBounds: this.getShapeGeometry(shape).bounds,
5836
5804
  scaleOrigin,
@@ -5873,7 +5841,7 @@ class Editor extends import_eventemitter3.default {
5873
5841
  const scaleY = targetBounds.height / commonBounds.height;
5874
5842
  const scale = new import_Vec.Vec(scaleX, scaleY);
5875
5843
  shapeClusters.forEach(({ shapes: shapes2, pageBounds }) => {
5876
- const localOffset = new import_Vec.Vec(
5844
+ const pageOffset = new import_Vec.Vec(
5877
5845
  targetBounds.minX - commonBounds.minX + (pageBounds.minX - commonBounds.minX) * (scaleX - 1),
5878
5846
  targetBounds.minY - commonBounds.minY + (pageBounds.minY - commonBounds.minY) * (scaleY - 1)
5879
5847
  );
@@ -5882,11 +5850,7 @@ class Editor extends import_eventemitter3.default {
5882
5850
  targetBounds.minY + (pageBounds.minY - commonBounds.minY) * scaleY
5883
5851
  );
5884
5852
  for (const shape of shapes2) {
5885
- const shapeLocalOffset = localOffset.clone();
5886
- shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
5887
- shapeLocalOffset.add(shape);
5888
- const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
5889
- this.updateShape(changes);
5853
+ this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
5890
5854
  this.resizeShape(shape.id, scale, {
5891
5855
  initialBounds: this.getShapeGeometry(shape).bounds,
5892
5856
  scaleOrigin,
@@ -6305,12 +6269,17 @@ class Editor extends import_eventemitter3.default {
6305
6269
  let remaining = duration;
6306
6270
  let t;
6307
6271
  const animations = [];
6272
+ const ignoreShapeLock = this._shouldIgnoreShapeLock;
6308
6273
  let partial, result;
6309
6274
  for (let i = 0, n = partials.length; i < n; i++) {
6310
6275
  partial = partials[i];
6311
6276
  if (!partial) continue;
6312
6277
  const shape = this.getShape(partial.id);
6313
6278
  if (!shape) continue;
6279
+ const unlocks = shape.isLocked && Object.hasOwn(partial, "isLocked") && !partial.isLocked;
6280
+ if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
6281
+ continue;
6282
+ }
6314
6283
  result = {
6315
6284
  start: (0, import_utils.structuredClone)(shape),
6316
6285
  end: applyPartialToRecordWithProps((0, import_utils.structuredClone)(shape), partial)
@@ -6326,7 +6295,7 @@ class Editor extends import_eventemitter3.default {
6326
6295
  (p) => p && animatingShapes2.get(p.id) === animationId
6327
6296
  );
6328
6297
  if (partialsToUpdate.length) {
6329
- this.updateShapes(partialsToUpdate);
6298
+ this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
6330
6299
  }
6331
6300
  this.off("tick", handleTick);
6332
6301
  return;
@@ -6359,13 +6328,13 @@ class Editor extends import_eventemitter3.default {
6359
6328
  throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");
6360
6329
  }
6361
6330
  if (this.getIsReadonly()) return this;
6362
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6363
- if (ids.length <= 1) return this;
6331
+ const ids = toShapeIds(shapes);
6364
6332
  const shapesToGroup = (0, import_utils.compact)(
6365
6333
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6366
6334
  (id) => this.getShape(id)
6367
6335
  )
6368
6336
  );
6337
+ if (shapesToGroup.length <= 1) return this;
6369
6338
  const sortedShapeIds = shapesToGroup.sort(import_utils.sortByIndex).map((s) => s.id);
6370
6339
  const childBounds = (0, import_utils.compact)(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
6371
6340
  const pageBounds = import_Box.Box.Common(childBounds);
@@ -6374,8 +6343,11 @@ class Editor extends import_eventemitter3.default {
6374
6343
  }
6375
6344
  const { x, y } = pageBounds.point;
6376
6345
  const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
6377
- if (this.getCurrentToolId() !== "select") return this;
6378
- if (!this.isIn("select.idle")) {
6346
+ if (!this.canCreateShapes([groupId])) {
6347
+ alertMaxShapes(this);
6348
+ return this;
6349
+ }
6350
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6379
6351
  this.cancel();
6380
6352
  }
6381
6353
  const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
@@ -6403,15 +6375,14 @@ class Editor extends import_eventemitter3.default {
6403
6375
  ungroupShapes(shapes, opts = {}) {
6404
6376
  if (this.getIsReadonly()) return this;
6405
6377
  const { select = true } = opts;
6406
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6378
+ const ids = toShapeIds(shapes);
6407
6379
  const shapesToUngroup = (0, import_utils.compact)(
6408
6380
  (this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
6409
6381
  (id) => this.getShape(id)
6410
6382
  )
6411
6383
  );
6412
6384
  if (shapesToUngroup.length === 0) return this;
6413
- if (this.getCurrentToolId() !== "select") return this;
6414
- if (!this.isIn("select.idle")) {
6385
+ if (this.isIn("select") && !this.isIn("select.idle")) {
6415
6386
  this.cancel();
6416
6387
  }
6417
6388
  const idsToSelect = /* @__PURE__ */ new Set();
@@ -6425,16 +6396,16 @@ class Editor extends import_eventemitter3.default {
6425
6396
  });
6426
6397
  if (groups.length === 0) return this;
6427
6398
  this.run(() => {
6428
- let group;
6429
6399
  for (let i = 0, n = groups.length; i < n; i++) {
6430
- group = groups[i];
6400
+ const group = this.getShape(groups[i].id);
6401
+ if (!group) continue;
6431
6402
  const childIds = this.getSortedChildIdsForParent(group.id);
6432
6403
  for (let j = 0, n2 = childIds.length; j < n2; j++) {
6433
6404
  idsToSelect.add(childIds[j]);
6434
6405
  }
6435
6406
  this.reparentShapes(childIds, group.parentId, group.index);
6436
6407
  }
6437
- this.deleteShapes(groups.map((group2) => group2.id));
6408
+ this.deleteShapes(groups.map((group) => group.id));
6438
6409
  if (select) {
6439
6410
  this.select(...idsToSelect);
6440
6411
  }
@@ -6515,14 +6486,14 @@ class Editor extends import_eventemitter3.default {
6515
6486
  }
6516
6487
  /** @internal */
6517
6488
  _getUnlockedShapeIds(ids) {
6518
- return ids.filter((id) => !this.getShape(id)?.isLocked);
6489
+ return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
6519
6490
  }
6520
6491
  deleteShapes(_ids) {
6521
6492
  if (this.getIsReadonly()) return this;
6522
6493
  if (!Array.isArray(_ids)) {
6523
6494
  throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");
6524
6495
  }
6525
- const shapeIds = typeof _ids[0] === "string" ? _ids : _ids.map((s) => s.id);
6496
+ const shapeIds = toShapeIds(_ids);
6526
6497
  const shapeIdsToDelete = this._shouldIgnoreShapeLock ? shapeIds : this._getUnlockedShapeIds(shapeIds);
6527
6498
  if (shapeIdsToDelete.length === 0) return this;
6528
6499
  const allShapeIdsToDelete = new Set(shapeIdsToDelete);
@@ -6867,7 +6838,7 @@ class Editor extends import_eventemitter3.default {
6867
6838
  * @public
6868
6839
  */
6869
6840
  getContentFromCurrentPage(shapes) {
6870
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6841
+ const ids = toShapeIds(shapes);
6871
6842
  if (!ids) return;
6872
6843
  if (ids.length === 0) return;
6873
6844
  const shapeIds = this.getShapeAndDescendantIds(ids);
@@ -6935,21 +6906,29 @@ class Editor extends import_eventemitter3.default {
6935
6906
  await Promise.allSettled(
6936
6907
  content.assets.map(async (asset) => {
6937
6908
  if ((asset.type === "image" || asset.type === "video") && !asset.props.src?.startsWith("data:image") && !asset.props.src?.startsWith("data:video") && !asset.props.src?.startsWith("http")) {
6938
- const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6939
- const objectUrl = await this.store.props.assets.resolve(asset, {
6940
- screenScale: 1,
6941
- steppedScreenScale: 1,
6942
- dpr: 1,
6943
- networkEffectiveType: null,
6944
- shouldResolveToOriginal: true
6945
- });
6946
- assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(
6947
- await (0, import_utils.fetch)(objectUrl).then((r) => r.blob())
6948
- );
6949
- assets.push(assetWithDataUrl);
6950
- } else {
6951
- assets.push(asset);
6909
+ try {
6910
+ const objectUrl = await this.store.props.assets.resolve(asset, {
6911
+ screenScale: 1,
6912
+ steppedScreenScale: 1,
6913
+ dpr: 1,
6914
+ networkEffectiveType: null,
6915
+ shouldResolveToOriginal: true
6916
+ });
6917
+ if (objectUrl) {
6918
+ const response = await (0, import_utils.fetch)(objectUrl);
6919
+ if (response.ok) {
6920
+ const assetWithDataUrl = (0, import_utils.structuredClone)(asset);
6921
+ assetWithDataUrl.props.src = await import_utils.FileHelpers.blobToDataUrl(await response.blob());
6922
+ assets.push(assetWithDataUrl);
6923
+ return;
6924
+ }
6925
+ console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`);
6926
+ }
6927
+ } catch (err) {
6928
+ console.warn(`Could not inline asset ${asset.id}`, err);
6929
+ }
6952
6930
  }
6931
+ assets.push(asset);
6953
6932
  })
6954
6933
  );
6955
6934
  content.assets = assets;
@@ -7243,7 +7222,7 @@ class Editor extends import_eventemitter3.default {
7243
7222
  * @public
7244
7223
  */
7245
7224
  async getSvgElement(shapes, opts = {}) {
7246
- const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
7225
+ const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes);
7247
7226
  if (ids.length === 0) return void 0;
7248
7227
  await this.fonts.loadRequiredFontsForCurrentPage(this.options.maxFontsToLoadBeforeRender);
7249
7228
  return (0, import_exportToSvg.exportToSvg)(this, ids, opts);
@@ -8161,6 +8140,7 @@ class Editor extends import_eventemitter3.default {
8161
8140
  inputs.buttons.add(info.button);
8162
8141
  inputs.setIsPointing(true);
8163
8142
  inputs.setIsDragging(false);
8143
+ this.stopCameraAnimation();
8164
8144
  if (!isPenMode && info.isPenDirect) {
8165
8145
  this.updateInstanceState({ isPenMode: true });
8166
8146
  this.interrupt();
@@ -8297,8 +8277,8 @@ class Editor extends import_eventemitter3.default {
8297
8277
  break;
8298
8278
  }
8299
8279
  case "keyboard": {
8300
- if (info.key === "ShiftRight") info.key = "ShiftLeft";
8301
- if (info.key === "AltRight") info.key = "AltLeft";
8280
+ if (info.code === "ShiftRight") info.code = "ShiftLeft";
8281
+ if (info.code === "AltRight") info.code = "AltLeft";
8302
8282
  if (info.code === "ControlRight") info.code = "ControlLeft";
8303
8283
  if (info.code === "MetaRight") info.code = "MetaLeft";
8304
8284
  switch (info.name) {
@@ -8668,6 +8648,9 @@ function pushShapeWithDescendants(editor, id, result) {
8668
8648
  pushShapeWithDescendants(editor, childIds[i], result);
8669
8649
  }
8670
8650
  }
8651
+ function toShapeIds(shapes) {
8652
+ return typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
8653
+ }
8671
8654
  function withIsolatedShapes(editor, shapeIds, callback) {
8672
8655
  let result;
8673
8656
  editor.run(
@@ -8690,7 +8673,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
8690
8673
  }
8691
8674
  }
8692
8675
  }
8693
- editor.deleteBindings([...bindingsToRemove], { isolateShapes: true });
8676
+ editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
8694
8677
  try {
8695
8678
  result = import_utils.Result.ok(callback(bindingsWithBoth));
8696
8679
  } catch (error) {