@tldraw/editor 3.9.0-internal.7f0e15f4f7d9 → 3.10.0-canary.d4dfa96478a4

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 (138) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +1 -1
  3. package/dist-cjs/index.d.ts +41 -229
  4. package/dist-cjs/index.js +1 -9
  5. package/dist-cjs/index.js.map +2 -2
  6. package/dist-cjs/lib/TldrawEditor.js +6 -33
  7. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  8. package/dist-cjs/lib/components/LiveCollaborators.js +5 -0
  9. package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
  10. package/dist-cjs/lib/components/Shape.js +0 -7
  11. package/dist-cjs/lib/components/Shape.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
  13. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
  15. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  16. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  17. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  18. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  19. package/dist-cjs/lib/editor/Editor.js +435 -308
  20. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  21. package/dist-cjs/lib/editor/managers/TextManager.js +17 -23
  22. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  23. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +7 -13
  24. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  25. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  26. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  27. package/dist-cjs/lib/exports/FontEmbedder.js +2 -7
  28. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  29. package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
  30. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  31. package/dist-cjs/lib/exports/exportToSvg.js +2 -3
  32. package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
  33. package/dist-cjs/lib/exports/getSvgJsx.js +1 -18
  34. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  35. package/dist-cjs/lib/exports/parseCss.js +0 -1
  36. package/dist-cjs/lib/exports/parseCss.js.map +2 -2
  37. package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -2
  38. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  39. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -1
  40. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
  41. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  42. package/dist-cjs/lib/options.js +1 -2
  43. package/dist-cjs/lib/options.js.map +2 -2
  44. package/dist-cjs/lib/utils/dom.js +1 -1
  45. package/dist-cjs/lib/utils/dom.js.map +2 -2
  46. package/dist-cjs/version.js +3 -3
  47. package/dist-cjs/version.js.map +1 -1
  48. package/dist-esm/index.d.mts +41 -229
  49. package/dist-esm/index.mjs +1 -13
  50. package/dist-esm/index.mjs.map +2 -2
  51. package/dist-esm/lib/TldrawEditor.mjs +7 -34
  52. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  53. package/dist-esm/lib/components/LiveCollaborators.mjs +5 -0
  54. package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
  55. package/dist-esm/lib/components/Shape.mjs +1 -8
  56. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  57. package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
  58. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  59. package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
  60. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  61. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  62. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  63. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  64. package/dist-esm/lib/editor/Editor.mjs +432 -312
  65. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  66. package/dist-esm/lib/editor/managers/TextManager.mjs +17 -23
  67. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  68. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +7 -13
  69. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  70. package/dist-esm/lib/exports/FontEmbedder.mjs +2 -7
  71. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  72. package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
  73. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  74. package/dist-esm/lib/exports/exportToSvg.mjs +2 -3
  75. package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
  76. package/dist-esm/lib/exports/getSvgJsx.mjs +2 -19
  77. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  78. package/dist-esm/lib/exports/parseCss.mjs +0 -1
  79. package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
  80. package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -2
  81. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  82. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +1 -1
  83. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
  84. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  85. package/dist-esm/lib/options.mjs +1 -2
  86. package/dist-esm/lib/options.mjs.map +2 -2
  87. package/dist-esm/lib/utils/dom.mjs +1 -1
  88. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  89. package/dist-esm/version.mjs +3 -3
  90. package/dist-esm/version.mjs.map +1 -1
  91. package/editor.css +13 -127
  92. package/package.json +7 -10
  93. package/src/index.ts +2 -15
  94. package/src/lib/TldrawEditor.tsx +4 -52
  95. package/src/lib/components/LiveCollaborators.tsx +5 -0
  96. package/src/lib/components/Shape.tsx +1 -9
  97. package/src/lib/components/default-components/DefaultBrush.tsx +1 -0
  98. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -0
  99. package/src/lib/components/default-components/DefaultCursor.tsx +1 -0
  100. package/src/lib/components/default-components/DefaultErrorFallback.tsx +5 -3
  101. package/src/lib/components/default-components/DefaultScribble.tsx +1 -0
  102. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -0
  103. package/src/lib/editor/Editor.ts +561 -362
  104. package/src/lib/editor/managers/TextManager.ts +17 -42
  105. package/src/lib/editor/shapes/ShapeUtil.ts +32 -18
  106. package/src/lib/editor/types/emit-types.ts +0 -1
  107. package/src/lib/editor/types/external-content.ts +0 -1
  108. package/src/lib/exports/FontEmbedder.ts +1 -13
  109. package/src/lib/exports/StyleEmbedder.ts +1 -1
  110. package/src/lib/exports/exportToSvg.tsx +3 -4
  111. package/src/lib/exports/getSvgJsx.tsx +3 -22
  112. package/src/lib/exports/parseCss.ts +0 -1
  113. package/src/lib/hooks/useCanvasEvents.ts +1 -2
  114. package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +0 -1
  115. package/src/lib/hooks/usePassThroughWheelEvents.ts +1 -0
  116. package/src/lib/options.ts +0 -7
  117. package/src/lib/utils/dom.ts +1 -1
  118. package/src/version.ts +3 -3
  119. package/dist-cjs/lib/editor/managers/FontManager.js +0 -167
  120. package/dist-cjs/lib/editor/managers/FontManager.js.map +0 -7
  121. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +0 -48
  122. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +0 -7
  123. package/dist-cjs/lib/hooks/useViewportHeight.js +0 -56
  124. package/dist-cjs/lib/hooks/useViewportHeight.js.map +0 -7
  125. package/dist-cjs/lib/utils/richText.js +0 -46
  126. package/dist-cjs/lib/utils/richText.js.map +0 -7
  127. package/dist-esm/lib/editor/managers/FontManager.mjs +0 -153
  128. package/dist-esm/lib/editor/managers/FontManager.mjs.map +0 -7
  129. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +0 -28
  130. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +0 -7
  131. package/dist-esm/lib/hooks/useViewportHeight.mjs +0 -36
  132. package/dist-esm/lib/hooks/useViewportHeight.mjs.map +0 -7
  133. package/dist-esm/lib/utils/richText.mjs +0 -26
  134. package/dist-esm/lib/utils/richText.mjs.map +0 -7
  135. package/src/lib/editor/managers/FontManager.ts +0 -252
  136. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +0 -29
  137. package/src/lib/hooks/useViewportHeight.ts +0 -37
  138. package/src/lib/utils/richText.ts +0 -72
@@ -80,6 +80,7 @@ var import_state = require("@tldraw/state");
80
80
  var import_store = require("@tldraw/store");
81
81
  var import_tlschema = require("@tldraw/tlschema");
82
82
  var import_utils = require("@tldraw/utils");
83
+ var import_core_js = require("core-js");
83
84
  var import_eventemitter3 = __toESM(require("eventemitter3"));
84
85
  var import_TLEditorSnapshot = require("../config/TLEditorSnapshot");
85
86
  var import_createTLUser = require("../config/createTLUser");
@@ -114,7 +115,6 @@ var import_shapeIdsInCurrentPage = require("./derivations/shapeIdsInCurrentPage"
114
115
  var import_ClickManager = require("./managers/ClickManager");
115
116
  var import_EdgeScrollManager = require("./managers/EdgeScrollManager");
116
117
  var import_FocusManager = require("./managers/FocusManager");
117
- var import_FontManager = require("./managers/FontManager");
118
118
  var import_HistoryManager = require("./managers/HistoryManager");
119
119
  var import_ScribbleManager = require("./managers/ScribbleManager");
120
120
  var import_SnapManager = require("./managers/SnapManager/SnapManager");
@@ -122,8 +122,8 @@ var import_TextManager = require("./managers/TextManager");
122
122
  var import_TickManager = require("./managers/TickManager");
123
123
  var import_UserPreferencesManager = require("./managers/UserPreferencesManager");
124
124
  var import_RootState = require("./tools/RootState");
125
- var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, __notVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getShapeGeometryCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getIsMenuOpen_dec, _getOpenMenus_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
126
- class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getOpenMenus_dec = [import_state.computed], _getIsMenuOpen_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeGeometryCache_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], __notVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
125
+ var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, __notVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getIsMenuOpen_dec, _getOpenMenus_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
126
+ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getOpenMenus_dec = [import_state.computed], _getIsMenuOpen_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], __notVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
127
127
  constructor({
128
128
  store,
129
129
  user,
@@ -132,13 +132,11 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
132
132
  tools,
133
133
  getContainer,
134
134
  cameraOptions,
135
- textOptions,
136
135
  initialState,
137
136
  autoFocus,
138
137
  inferDarkMode,
139
138
  options,
140
- isShapeHidden,
141
- fontAssetUrls
139
+ isShapeHidden
142
140
  }) {
143
141
  super();
144
142
  __runInitializers(_init, 5, this);
@@ -196,12 +194,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
196
194
  * @public
197
195
  */
198
196
  __publicField(this, "textMeasure");
199
- /**
200
- * A utility for managing the set of fonts that should be rendered in the document.
201
- *
202
- * @public
203
- */
204
- __publicField(this, "fonts");
205
197
  /**
206
198
  * A manager for the editor's environment.
207
199
  *
@@ -273,9 +265,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
273
265
  __publicField(this, "_isChangingStyleTimeout", -1);
274
266
  // Menus
275
267
  __publicField(this, "menus", import_menus.tlmenus.forContext(this.contextId));
276
- // Rich text editor
277
- __publicField(this, "_currentRichTextEditor", (0, import_state.atom)("rich text editor", null));
278
- __publicField(this, "_textOptions");
279
268
  __publicField(this, "_cameraOptions", (0, import_state.atom)("camera options", import_constants.DEFAULT_CAMERA_OPTIONS));
280
269
  /** @internal */
281
270
  __publicField(this, "_viewportAnimation", null);
@@ -296,6 +285,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
296
285
  __publicField(this, "_cameraStateTimeoutRemaining", 0);
297
286
  /* @internal */
298
287
  __publicField(this, "_currentPageShapeIds");
288
+ /* --------------------- Shapes --------------------- */
289
+ __publicField(this, "_shapeGeometryCaches", {});
299
290
  // Parents and children
300
291
  /**
301
292
  * A cache of parents to children.
@@ -421,12 +412,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
421
412
  this.snaps = new import_SnapManager.SnapManager(this);
422
413
  this.disposables.add(this.timers.dispose);
423
414
  this._cameraOptions.set({ ...import_constants.DEFAULT_CAMERA_OPTIONS, ...cameraOptions });
424
- this._textOptions = (0, import_state.atom)("text options", textOptions ?? null);
425
415
  this.user = new import_UserPreferencesManager.UserPreferencesManager(user ?? (0, import_createTLUser.createTLUser)(), inferDarkMode ?? false);
426
416
  this.disposables.add(() => this.user.dispose());
427
417
  this.getContainer = getContainer;
428
418
  this.textMeasure = new import_TextManager.TextManager(this);
429
- this.fonts = new import_FontManager.FontManager(this, fontAssetUrls);
430
419
  this._tickManager = new import_TickManager.TickManager(this);
431
420
  class NewRoot extends import_RootState.RootState {
432
421
  static initial = initialState ?? "";
@@ -1598,7 +1587,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1598
1587
  */
1599
1588
  setEditingShape(shape) {
1600
1589
  const id = typeof shape === "string" ? shape : shape?.id ?? null;
1601
- this.setRichTextEditor(null);
1602
1590
  if (id !== this.getEditingShapeId()) {
1603
1591
  if (id) {
1604
1592
  const shape2 = this.getShape(id);
@@ -1615,36 +1603,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1615
1603
  this.run(
1616
1604
  () => {
1617
1605
  this._updateCurrentPageState({ editingShapeId: null });
1618
- this._currentRichTextEditor.set(null);
1619
1606
  },
1620
1607
  { history: "ignore" }
1621
1608
  );
1622
1609
  }
1623
1610
  return this;
1624
1611
  }
1625
- getRichTextEditor() {
1626
- return this._currentRichTextEditor.get();
1627
- }
1628
- /**
1629
- * Set the current editing shape's rich text editor.
1630
- *
1631
- * @example
1632
- * ```ts
1633
- * editor.setRichTextEditor(richTextEditorView)
1634
- * ```
1635
- *
1636
- * @param textEditor - The text editor to set as the current editing shape's text editor.
1637
- *
1638
- * @public
1639
- */
1640
- setRichTextEditor(textEditor) {
1641
- const current = this._currentRichTextEditor.__unsafe__getWithoutCapture();
1642
- if (current !== textEditor) {
1643
- current?.destroy();
1644
- }
1645
- this._currentRichTextEditor.set(textEditor);
1646
- return this;
1647
- }
1648
1612
  getHoveredShapeId() {
1649
1613
  return this.getCurrentPageState().hoveredShapeId;
1650
1614
  }
@@ -1790,18 +1754,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1790
1754
  }
1791
1755
  return this;
1792
1756
  }
1793
- /**
1794
- * Get the current text options.
1795
- *
1796
- * @example
1797
- * ```ts
1798
- * editor.getTextOptions()
1799
- * ```
1800
- *
1801
- * @public */
1802
- getTextOptions() {
1803
- return (0, import_utils.assertExists)(this._textOptions.get(), "Cannot use text without setting textOptions");
1804
- }
1805
1757
  _unsafe_getCameraId() {
1806
1758
  return import_tlschema.CameraRecordType.createId(this.getCurrentPageId());
1807
1759
  }
@@ -2143,9 +2095,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2143
2095
  this.stopFollowingUser();
2144
2096
  }
2145
2097
  const _point = import_Vec.Vec.Cast(point);
2146
- if (!Number.isFinite(_point.x)) _point.x = 0;
2147
- if (!Number.isFinite(_point.y)) _point.y = 0;
2148
- if (_point.z === void 0 || !Number.isFinite(_point.z)) point.z = this.getZoomLevel();
2098
+ if (!import_core_js.Number.isFinite(_point.x)) _point.x = 0;
2099
+ if (!import_core_js.Number.isFinite(_point.y)) _point.y = 0;
2100
+ if (_point.z === void 0 || !import_core_js.Number.isFinite(_point.z)) point.z = this.getZoomLevel();
2149
2101
  const camera = this.getConstrainedCamera(_point, opts);
2150
2102
  if (opts?.animation) {
2151
2103
  const { width, height } = this.getViewportScreenBounds();
@@ -3246,16 +3198,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3246
3198
  async uploadAsset(asset, file, abortSignal) {
3247
3199
  return await this.store.props.assets.upload(asset, file, abortSignal);
3248
3200
  }
3249
- _getShapeGeometryCache() {
3250
- return this.store.createComputedCache(
3251
- "bounds",
3252
- (shape) => {
3253
- this.fonts.trackFontsForShape(shape);
3254
- return this.getShapeUtil(shape).getGeometry(shape);
3255
- },
3256
- { areRecordsEqual: (a, b) => a.props === b.props }
3257
- );
3258
- }
3259
3201
  /**
3260
3202
  * Get the geometry of a shape.
3261
3203
  *
@@ -3263,14 +3205,26 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3263
3205
  * ```ts
3264
3206
  * editor.getShapeGeometry(myShape)
3265
3207
  * editor.getShapeGeometry(myShapeId)
3208
+ * editor.getShapeGeometry(myShapeId, { context: "arrow" })
3266
3209
  * ```
3267
3210
  *
3268
3211
  * @param shape - The shape (or shape id) to get the geometry for.
3212
+ * @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
3269
3213
  *
3270
3214
  * @public
3271
3215
  */
3272
- getShapeGeometry(shape) {
3273
- return this._getShapeGeometryCache().get(typeof shape === "string" ? shape : shape.id);
3216
+ getShapeGeometry(shape, opts) {
3217
+ const context = opts?.context ?? "none";
3218
+ if (!this._shapeGeometryCaches[context]) {
3219
+ this._shapeGeometryCaches[context] = this.store.createComputedCache(
3220
+ "bounds",
3221
+ (shape2) => this.getShapeUtil(shape2).getGeometry(shape2, opts),
3222
+ { areRecordsEqual: (a, b) => a.props === b.props }
3223
+ );
3224
+ }
3225
+ return this._shapeGeometryCaches[context].get(
3226
+ typeof shape === "string" ? shape : shape.id
3227
+ );
3274
3228
  }
3275
3229
  _getShapeHandlesCache() {
3276
3230
  return this.store.createComputedCache("handles", (shape) => {
@@ -3672,7 +3626,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3672
3626
  const geometry = this.getShapeGeometry(shape);
3673
3627
  const isGroup = geometry instanceof import_Group2d.Group2d;
3674
3628
  const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
3675
- if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "arrow") && shape.props.text.trim() || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && this.getShapeUtil(shape).getText(shape)?.trim()) {
3629
+ if (this.isShapeOfType(shape, "frame") || (this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shape.props.text.trim()) {
3676
3630
  for (const childGeometry of geometry.children) {
3677
3631
  if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
3678
3632
  return shape;
@@ -4336,27 +4290,28 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4336
4290
  });
4337
4291
  return this;
4338
4292
  }
4293
+ // Gets a shape partial that includes life cycle changes: on translate start, on translate, on translate end
4339
4294
  getChangesToTranslateShape(initialShape, newShapeCoords) {
4340
4295
  let workingShape = initialShape;
4341
4296
  const util = this.getShapeUtil(initialShape);
4342
- workingShape = applyPartialToRecordWithProps(
4343
- workingShape,
4344
- util.onTranslateStart?.(workingShape) ?? void 0
4345
- );
4297
+ const afterTranslateStart = util.onTranslateStart?.(workingShape);
4298
+ if (afterTranslateStart) {
4299
+ workingShape = applyPartialToRecordWithProps(workingShape, afterTranslateStart);
4300
+ }
4346
4301
  workingShape = applyPartialToRecordWithProps(workingShape, {
4347
4302
  id: initialShape.id,
4348
4303
  type: initialShape.type,
4349
4304
  x: newShapeCoords.x,
4350
4305
  y: newShapeCoords.y
4351
4306
  });
4352
- workingShape = applyPartialToRecordWithProps(
4353
- workingShape,
4354
- util.onTranslate?.(initialShape, workingShape) ?? void 0
4355
- );
4356
- workingShape = applyPartialToRecordWithProps(
4357
- workingShape,
4358
- util.onTranslateEnd?.(initialShape, workingShape) ?? void 0
4359
- );
4307
+ const afterTranslate = util.onTranslate?.(initialShape, workingShape);
4308
+ if (afterTranslate) {
4309
+ workingShape = applyPartialToRecordWithProps(workingShape, afterTranslate);
4310
+ }
4311
+ const afterTranslateEnd = util.onTranslateEnd?.(initialShape, workingShape);
4312
+ if (afterTranslateEnd) {
4313
+ workingShape = applyPartialToRecordWithProps(workingShape, afterTranslateEnd);
4314
+ }
4360
4315
  return workingShape;
4361
4316
  }
4362
4317
  /**
@@ -4663,6 +4618,30 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4663
4618
  if (changes) this.updateShapes(changes);
4664
4619
  return this;
4665
4620
  }
4621
+ /**
4622
+ * @internal
4623
+ */
4624
+ collectShapesViaArrowBindings(info) {
4625
+ const { initialShapes, resultShapes, resultBounds, bindings, visited } = info;
4626
+ for (const binding of bindings) {
4627
+ for (const id of [binding.fromId, binding.toId]) {
4628
+ if (!visited.has(id)) {
4629
+ const aligningShape = initialShapes.find((s) => s.id === id);
4630
+ if (aligningShape && !visited.has(aligningShape.id)) {
4631
+ visited.add(aligningShape.id);
4632
+ const shapePageBounds = this.getShapePageBounds(aligningShape);
4633
+ if (!shapePageBounds) continue;
4634
+ resultShapes.push(aligningShape);
4635
+ resultBounds.push(shapePageBounds);
4636
+ this.collectShapesViaArrowBindings({
4637
+ ...info,
4638
+ bindings: this.getBindingsInvolvingShape(aligningShape, "arrow")
4639
+ });
4640
+ }
4641
+ }
4642
+ }
4643
+ }
4644
+ }
4666
4645
  /**
4667
4646
  * Flip shape positions.
4668
4647
  *
@@ -4678,35 +4657,52 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4678
4657
  * @public
4679
4658
  */
4680
4659
  flipShapes(shapes, operation) {
4681
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4682
4660
  if (this.getIsReadonly()) return this;
4683
- let shapesToFlip = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4661
+ const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4662
+ const shapesToFlipFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4663
+ for (const shape of shapesToFlipFirstPass) {
4664
+ if (this.isShapeOfType(shape, "group")) {
4665
+ const childrenOfGroups = (0, import_utils.compact)(
4666
+ this.getSortedChildIdsForParent(shape.id).map((id) => this.getShape(id))
4667
+ );
4668
+ shapesToFlipFirstPass.push(...childrenOfGroups);
4669
+ }
4670
+ }
4671
+ const shapesToFlip = [];
4672
+ const allBounds = [];
4673
+ for (const shape of shapesToFlipFirstPass) {
4674
+ const util = this.getShapeUtil(shape);
4675
+ if (!util.canBeLaidOut(shape, {
4676
+ type: "flip",
4677
+ shapes: shapesToFlipFirstPass
4678
+ })) {
4679
+ continue;
4680
+ }
4681
+ const pageBounds = this.getShapePageBounds(shape);
4682
+ const localBounds = this.getShapeGeometry(shape).bounds;
4683
+ const pageTransform = this.getShapePageTransform(shape.id);
4684
+ if (!(pageBounds && localBounds && pageTransform)) continue;
4685
+ shapesToFlip.push({
4686
+ shape,
4687
+ localBounds,
4688
+ pageTransform,
4689
+ isAspectRatioLocked: util.isAspectRatioLocked(shape)
4690
+ });
4691
+ allBounds.push(pageBounds);
4692
+ }
4684
4693
  if (!shapesToFlip.length) return this;
4685
- shapesToFlip = (0, import_utils.compact)(
4686
- shapesToFlip.map((shape) => {
4687
- if (this.isShapeOfType(shape, "group")) {
4688
- return this.getSortedChildIdsForParent(shape.id).map((id) => this.getShape(id));
4689
- }
4690
- return shape;
4691
- }).flat()
4692
- );
4693
- const scaleOriginPage = import_Box.Box.Common(
4694
- (0, import_utils.compact)(shapesToFlip.map((id) => this.getShapePageBounds(id)))
4695
- ).center;
4694
+ const scaleOriginPage = import_Box.Box.Common(allBounds).center;
4696
4695
  this.run(() => {
4697
- for (const shape of shapesToFlip) {
4698
- const bounds = this.getShapeGeometry(shape).bounds;
4699
- const initialPageTransform = this.getShapePageTransform(shape.id);
4700
- if (!initialPageTransform) continue;
4696
+ for (const { shape, localBounds, pageTransform, isAspectRatioLocked } of shapesToFlip) {
4701
4697
  this.resizeShape(
4702
4698
  shape.id,
4703
4699
  { x: operation === "horizontal" ? -1 : 1, y: operation === "vertical" ? -1 : 1 },
4704
4700
  {
4705
- initialBounds: bounds,
4706
- initialPageTransform,
4701
+ initialBounds: localBounds,
4702
+ initialPageTransform: pageTransform,
4707
4703
  initialShape: shape,
4704
+ isAspectRatioLocked,
4708
4705
  mode: "scale_shape",
4709
- isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
4710
4706
  scaleOrigin: scaleOriginPage,
4711
4707
  scaleAxisRotation: 0
4712
4708
  }
@@ -4733,15 +4729,40 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4733
4729
  stackShapes(shapes, operation, gap) {
4734
4730
  const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4735
4731
  if (this.getIsReadonly()) return this;
4736
- const shapesToStack = ids.map((id) => this.getShape(id)).filter((shape) => {
4737
- if (!shape) return false;
4738
- return this.getShapeUtil(shape).canBeLaidOut(shape);
4739
- });
4740
- const len = shapesToStack.length;
4732
+ const shapesToStackFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4733
+ const shapeClustersToStack = [];
4734
+ const allBounds = [];
4735
+ const visited = /* @__PURE__ */ new Set();
4736
+ for (const shape of shapesToStackFirstPass) {
4737
+ if (visited.has(shape.id)) continue;
4738
+ visited.add(shape.id);
4739
+ const shapePageBounds = this.getShapePageBounds(shape);
4740
+ if (!shapePageBounds) continue;
4741
+ if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
4742
+ type: "stack",
4743
+ shapes: shapesToStackFirstPass
4744
+ })) {
4745
+ continue;
4746
+ }
4747
+ const shapesMovingTogether = [shape];
4748
+ const boundsOfShapesMovingTogether = [shapePageBounds];
4749
+ this.collectShapesViaArrowBindings({
4750
+ bindings: this.getBindingsToShape(shape.id, "arrow"),
4751
+ initialShapes: shapesToStackFirstPass,
4752
+ resultShapes: shapesMovingTogether,
4753
+ resultBounds: boundsOfShapesMovingTogether,
4754
+ visited
4755
+ });
4756
+ const commonPageBounds = import_Box.Box.Common(boundsOfShapesMovingTogether);
4757
+ if (!commonPageBounds) continue;
4758
+ shapeClustersToStack.push({
4759
+ shapes: shapesMovingTogether,
4760
+ pageBounds: commonPageBounds
4761
+ });
4762
+ allBounds.push(commonPageBounds);
4763
+ }
4764
+ const len = shapeClustersToStack.length;
4741
4765
  if (gap === 0 && len < 3 || len < 2) return this;
4742
- const pageBounds = Object.fromEntries(
4743
- shapesToStack.map((shape) => [shape.id, this.getShapePageBounds(shape)])
4744
- );
4745
4766
  let val;
4746
4767
  let min;
4747
4768
  let max;
@@ -4757,57 +4778,55 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4757
4778
  max = "maxY";
4758
4779
  dim = "height";
4759
4780
  }
4760
- let shapeGap;
4781
+ let shapeGap = 0;
4761
4782
  if (gap === 0) {
4762
- const gaps = [];
4763
- shapesToStack.sort((a, b) => pageBounds[a.id][min] - pageBounds[b.id][min]);
4783
+ const gaps = {};
4784
+ shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
4764
4785
  for (let i = 0; i < len - 1; i++) {
4765
- const shape = shapesToStack[i];
4766
- const nextShape = shapesToStack[i + 1];
4767
- const bounds = pageBounds[shape.id];
4768
- const nextBounds = pageBounds[nextShape.id];
4769
- const gap2 = nextBounds[min] - bounds[max];
4770
- const current = gaps.find((g) => g.gap === gap2);
4771
- if (current) {
4772
- current.count++;
4773
- } else {
4774
- gaps.push({ gap: gap2, count: 1 });
4786
+ const currCluster = shapeClustersToStack[i];
4787
+ const nextCluster = shapeClustersToStack[i + 1];
4788
+ const gap2 = nextCluster.pageBounds[min] - currCluster.pageBounds[max];
4789
+ if (!gaps[gap2]) {
4790
+ gaps[gap2] = 0;
4775
4791
  }
4792
+ gaps[gap2]++;
4776
4793
  }
4777
- let maxCount = 0;
4778
- gaps.forEach((g) => {
4779
- if (g.count > maxCount) {
4780
- maxCount = g.count;
4781
- shapeGap = g.gap;
4794
+ let maxCount = 1;
4795
+ for (const [gap2, count] of Object.entries(gaps)) {
4796
+ if (count > maxCount) {
4797
+ maxCount = count;
4798
+ shapeGap = parseFloat(gap2);
4782
4799
  }
4783
- });
4800
+ }
4784
4801
  if (maxCount === 1) {
4785
- shapeGap = Math.max(0, gaps.reduce((a, c) => a + c.gap * c.count, 0) / (len - 1));
4802
+ let totalCount = 0;
4803
+ for (const [gap2, count] of Object.entries(gaps)) {
4804
+ shapeGap += parseFloat(gap2) * count;
4805
+ totalCount += count;
4806
+ }
4807
+ shapeGap /= totalCount;
4786
4808
  }
4787
4809
  } else {
4788
4810
  shapeGap = gap;
4789
4811
  }
4790
4812
  const changes = [];
4791
- let v = pageBounds[shapesToStack[0].id][max];
4792
- shapesToStack.forEach((shape, i) => {
4793
- if (i === 0) return;
4794
- const delta = { x: 0, y: 0 };
4795
- delta[val] = v + shapeGap - pageBounds[shape.id][val];
4796
- const parent = this.getShapeParent(shape);
4797
- const localDelta = parent ? import_Vec.Vec.Rot(delta, -this.getShapePageTransform(parent).decompose().rotation) : delta;
4798
- const translateStartChanges = this.getShapeUtil(shape).onTranslateStart?.(shape);
4799
- changes.push(
4800
- translateStartChanges ? {
4801
- ...translateStartChanges,
4802
- [val]: shape[val] + localDelta[val]
4803
- } : {
4804
- id: shape.id,
4805
- type: shape.type,
4806
- [val]: shape[val] + localDelta[val]
4813
+ let v = shapeClustersToStack[0].pageBounds[max];
4814
+ for (let i = 1; i < shapeClustersToStack.length; i++) {
4815
+ const { shapes: shapes2, pageBounds } = shapeClustersToStack[i];
4816
+ const delta = new import_Vec.Vec();
4817
+ delta[val] = v + shapeGap - pageBounds[val];
4818
+ for (const shape of shapes2) {
4819
+ const shapeDelta = delta.clone();
4820
+ const parent = this.getShapeParent(shape);
4821
+ if (parent) {
4822
+ const parentTransform = this.getShapePageTransform(parent);
4823
+ if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
4807
4824
  }
4808
- );
4809
- v += pageBounds[shape.id][dim] + shapeGap;
4810
- });
4825
+ shapeDelta.add(shape);
4826
+ changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
4827
+ }
4828
+ v += pageBounds[dim] + shapeGap;
4829
+ }
4811
4830
  this.updateShapes(changes);
4812
4831
  return this;
4813
4832
  }
@@ -4825,91 +4844,101 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4825
4844
  * @param gap - The padding to apply to the packed shapes. Defaults to 16.
4826
4845
  */
4827
4846
  packShapes(shapes, gap) {
4828
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4829
4847
  if (this.getIsReadonly()) return this;
4830
- if (ids.length < 2) return this;
4831
- const shapesToPack = ids.map((id) => this.getShape(id)).filter((shape2) => {
4832
- if (!shape2) return false;
4833
- return this.getShapeUtil(shape2).canBeLaidOut(shape2);
4834
- });
4835
- const shapePageBounds = {};
4836
- const nextShapePageBounds = {};
4837
- let shape, bounds, area = 0;
4838
- for (let i = 0; i < shapesToPack.length; i++) {
4839
- shape = shapesToPack[i];
4840
- bounds = this.getShapePageBounds(shape);
4841
- shapePageBounds[shape.id] = bounds;
4842
- nextShapePageBounds[shape.id] = bounds.clone();
4843
- area += bounds.width * bounds.height;
4844
- }
4845
- const commonBounds = import_Box.Box.Common((0, import_utils.compact)(Object.values(shapePageBounds)));
4848
+ const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4849
+ const shapesToPackFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4850
+ const shapeClustersToPack = [];
4851
+ const allBounds = [];
4852
+ const visited = /* @__PURE__ */ new Set();
4853
+ for (const shape of shapesToPackFirstPass) {
4854
+ if (visited.has(shape.id)) continue;
4855
+ visited.add(shape.id);
4856
+ const shapePageBounds = this.getShapePageBounds(shape);
4857
+ if (!shapePageBounds) continue;
4858
+ if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
4859
+ type: "pack",
4860
+ shapes: shapesToPackFirstPass
4861
+ })) {
4862
+ continue;
4863
+ }
4864
+ const shapesMovingTogether = [shape];
4865
+ const boundsOfShapesMovingTogether = [shapePageBounds];
4866
+ this.collectShapesViaArrowBindings({
4867
+ bindings: this.getBindingsToShape(shape.id, "arrow"),
4868
+ initialShapes: shapesToPackFirstPass,
4869
+ resultShapes: shapesMovingTogether,
4870
+ resultBounds: boundsOfShapesMovingTogether,
4871
+ visited
4872
+ });
4873
+ const commonPageBounds = import_Box.Box.Common(boundsOfShapesMovingTogether);
4874
+ if (!commonPageBounds) continue;
4875
+ shapeClustersToPack.push({
4876
+ shapes: shapesMovingTogether,
4877
+ pageBounds: commonPageBounds,
4878
+ nextPageBounds: commonPageBounds.clone()
4879
+ });
4880
+ allBounds.push(commonPageBounds);
4881
+ }
4882
+ if (shapeClustersToPack.length < 2) return this;
4883
+ let area = 0;
4884
+ for (const { pageBounds } of shapeClustersToPack) {
4885
+ area += pageBounds.width * pageBounds.height;
4886
+ }
4887
+ const commonBounds = import_Box.Box.Common(allBounds);
4846
4888
  const maxWidth = commonBounds.width;
4847
- shapesToPack.sort((a, b) => shapePageBounds[b.id].height - shapePageBounds[a.id].height);
4889
+ shapeClustersToPack.sort((a, b) => a.pageBounds.width - b.pageBounds.width).sort((a, b) => a.pageBounds.height - b.pageBounds.height);
4848
4890
  const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
4849
4891
  const spaces = [new import_Box.Box(commonBounds.x, commonBounds.y, startWidth, Infinity)];
4850
4892
  let width = 0;
4851
4893
  let height = 0;
4852
4894
  let space;
4853
4895
  let last2;
4854
- for (let i = 0; i < shapesToPack.length; i++) {
4855
- shape = shapesToPack[i];
4856
- bounds = nextShapePageBounds[shape.id];
4857
- for (let i2 = spaces.length - 1; i2 >= 0; i2--) {
4858
- space = spaces[i2];
4859
- if (bounds.width > space.width || bounds.height > space.height) continue;
4860
- bounds.x = space.x;
4861
- bounds.y = space.y;
4862
- height = Math.max(height, bounds.maxY);
4863
- width = Math.max(width, bounds.maxX);
4864
- if (bounds.width === space.width && bounds.height === space.height) {
4896
+ for (const { nextPageBounds } of shapeClustersToPack) {
4897
+ for (let i = spaces.length - 1; i >= 0; i--) {
4898
+ space = spaces[i];
4899
+ if (nextPageBounds.width > space.width || nextPageBounds.height > space.height) continue;
4900
+ nextPageBounds.x = space.x;
4901
+ nextPageBounds.y = space.y;
4902
+ height = Math.max(height, nextPageBounds.maxY);
4903
+ width = Math.max(width, nextPageBounds.maxX);
4904
+ if (nextPageBounds.width === space.width && nextPageBounds.height === space.height) {
4865
4905
  last2 = spaces.pop();
4866
- if (i2 < spaces.length) spaces[i2] = last2;
4867
- } else if (bounds.height === space.height) {
4868
- space.x += bounds.width + gap;
4869
- space.width -= bounds.width + gap;
4870
- } else if (bounds.width === space.width) {
4871
- space.y += bounds.height + gap;
4872
- space.height -= bounds.height + gap;
4906
+ if (i < spaces.length) spaces[i] = last2;
4907
+ } else if (nextPageBounds.height === space.height) {
4908
+ space.x += nextPageBounds.width + gap;
4909
+ space.width -= nextPageBounds.width + gap;
4910
+ } else if (nextPageBounds.width === space.width) {
4911
+ space.y += nextPageBounds.height + gap;
4912
+ space.height -= nextPageBounds.height + gap;
4873
4913
  } else {
4874
4914
  spaces.push(
4875
4915
  new import_Box.Box(
4876
- space.x + (bounds.width + gap),
4916
+ space.x + (nextPageBounds.width + gap),
4877
4917
  space.y,
4878
- space.width - (bounds.width + gap),
4879
- bounds.height
4918
+ space.width - (nextPageBounds.width + gap),
4919
+ nextPageBounds.height
4880
4920
  )
4881
4921
  );
4882
- space.y += bounds.height + gap;
4883
- space.height -= bounds.height + gap;
4922
+ space.y += nextPageBounds.height + gap;
4923
+ space.height -= nextPageBounds.height + gap;
4884
4924
  }
4885
4925
  break;
4886
4926
  }
4887
4927
  }
4888
- const commonAfter = import_Box.Box.Common(Object.values(nextShapePageBounds));
4928
+ const commonAfter = import_Box.Box.Common(shapeClustersToPack.map((s) => s.nextPageBounds));
4889
4929
  const centerDelta = import_Vec.Vec.Sub(commonBounds.center, commonAfter.center);
4890
- let nextBounds;
4891
4930
  const changes = [];
4892
- for (let i = 0; i < shapesToPack.length; i++) {
4893
- shape = shapesToPack[i];
4894
- bounds = shapePageBounds[shape.id];
4895
- nextBounds = nextShapePageBounds[shape.id];
4896
- const delta = import_Vec.Vec.Sub(nextBounds.point, bounds.point).add(centerDelta);
4897
- const parentTransform = this.getShapeParentTransform(shape);
4898
- if (parentTransform) delta.rot(-parentTransform.rotation());
4899
- const change = {
4900
- id: shape.id,
4901
- type: shape.type,
4902
- x: shape.x + delta.x,
4903
- y: shape.y + delta.y
4904
- };
4905
- const translateStartChange = this.getShapeUtil(shape).onTranslateStart?.({
4906
- ...shape,
4907
- ...change
4908
- });
4909
- if (translateStartChange) {
4910
- changes.push({ ...change, ...translateStartChange });
4911
- } else {
4912
- changes.push(change);
4931
+ for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
4932
+ const delta = import_Vec.Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
4933
+ for (const shape of shapes2) {
4934
+ const shapeDelta = delta.clone();
4935
+ const parent = this.getShapeParent(shape);
4936
+ if (parent) {
4937
+ const parentTransform = this.getShapeParentTransform(shape);
4938
+ if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
4939
+ }
4940
+ shapeDelta.add(shape);
4941
+ changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
4913
4942
  }
4914
4943
  }
4915
4944
  if (changes.length) {
@@ -4932,19 +4961,45 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4932
4961
  * @public
4933
4962
  */
4934
4963
  alignShapes(shapes, operation) {
4935
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4936
4964
  if (this.getIsReadonly()) return this;
4937
- if (ids.length < 2) return this;
4938
- const shapesToAlign = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4939
- const shapePageBounds = Object.fromEntries(
4940
- shapesToAlign.map((shape) => [shape.id, this.getShapePageBounds(shape)])
4941
- );
4942
- const commonBounds = import_Box.Box.Common((0, import_utils.compact)(Object.values(shapePageBounds)));
4965
+ const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4966
+ const shapesToAlignFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
4967
+ const shapeClustersToAlign = [];
4968
+ const allBounds = [];
4969
+ const visited = /* @__PURE__ */ new Set();
4970
+ for (const shape of shapesToAlignFirstPass) {
4971
+ if (visited.has(shape.id)) continue;
4972
+ visited.add(shape.id);
4973
+ const shapePageBounds = this.getShapePageBounds(shape);
4974
+ if (!shapePageBounds) continue;
4975
+ if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
4976
+ type: "align",
4977
+ shapes: shapesToAlignFirstPass
4978
+ })) {
4979
+ continue;
4980
+ }
4981
+ const shapesMovingTogether = [shape];
4982
+ const boundsOfShapesMovingTogether = [shapePageBounds];
4983
+ this.collectShapesViaArrowBindings({
4984
+ bindings: this.getBindingsToShape(shape.id, "arrow"),
4985
+ initialShapes: shapesToAlignFirstPass,
4986
+ resultShapes: shapesMovingTogether,
4987
+ resultBounds: boundsOfShapesMovingTogether,
4988
+ visited
4989
+ });
4990
+ const commonPageBounds = import_Box.Box.Common(boundsOfShapesMovingTogether);
4991
+ if (!commonPageBounds) continue;
4992
+ shapeClustersToAlign.push({
4993
+ shapes: shapesMovingTogether,
4994
+ pageBounds: commonPageBounds
4995
+ });
4996
+ allBounds.push(commonPageBounds);
4997
+ }
4998
+ if (shapeClustersToAlign.length < 2) return this;
4999
+ const commonBounds = import_Box.Box.Common(allBounds);
4943
5000
  const changes = [];
4944
- shapesToAlign.forEach((shape) => {
4945
- const pageBounds = shapePageBounds[shape.id];
4946
- if (!pageBounds) return;
4947
- const delta = { x: 0, y: 0 };
5001
+ shapeClustersToAlign.forEach(({ shapes: shapes2, pageBounds }) => {
5002
+ const delta = new import_Vec.Vec();
4948
5003
  switch (operation) {
4949
5004
  case "top": {
4950
5005
  delta.y = commonBounds.minY - pageBounds.minY;
@@ -4971,9 +5026,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4971
5026
  break;
4972
5027
  }
4973
5028
  }
4974
- const parent = this.getShapeParent(shape);
4975
- const localDelta = parent ? import_Vec.Vec.Rot(delta, -this.getShapePageTransform(parent).decompose().rotation) : delta;
4976
- changes.push(this.getChangesToTranslateShape(shape, import_Vec.Vec.Add(shape, localDelta)));
5029
+ for (const shape of shapes2) {
5030
+ const shapeDelta = delta.clone();
5031
+ const parent = this.getShapeParent(shape);
5032
+ if (parent) {
5033
+ const parentTransform = this.getShapePageTransform(parent);
5034
+ if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
5035
+ }
5036
+ shapeDelta.add(shape);
5037
+ changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5038
+ }
4977
5039
  });
4978
5040
  this.updateShapes(changes);
4979
5041
  return this;
@@ -4993,47 +5055,95 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4993
5055
  * @public
4994
5056
  */
4995
5057
  distributeShapes(shapes, operation) {
4996
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
4997
5058
  if (this.getIsReadonly()) return this;
4998
- if (ids.length < 3) return this;
4999
- const len = ids.length;
5000
- const shapesToDistribute = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5001
- const pageBounds = Object.fromEntries(
5002
- shapesToDistribute.map((shape) => [shape.id, this.getShapePageBounds(shape)])
5003
- );
5059
+ const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5060
+ const shapesToDistributeFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5061
+ const shapeClustersToDistribute = [];
5062
+ const allBounds = [];
5063
+ const visited = /* @__PURE__ */ new Set();
5064
+ for (const shape of shapesToDistributeFirstPass) {
5065
+ if (visited.has(shape.id)) continue;
5066
+ visited.add(shape.id);
5067
+ const shapePageBounds = this.getShapePageBounds(shape);
5068
+ if (!shapePageBounds) continue;
5069
+ if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
5070
+ type: "distribute",
5071
+ shapes: shapesToDistributeFirstPass
5072
+ })) {
5073
+ continue;
5074
+ }
5075
+ const shapesMovingTogether = [shape];
5076
+ const boundsOfShapesMovingTogether = [shapePageBounds];
5077
+ this.collectShapesViaArrowBindings({
5078
+ bindings: this.getBindingsToShape(shape.id, "arrow"),
5079
+ initialShapes: shapesToDistributeFirstPass,
5080
+ resultShapes: shapesMovingTogether,
5081
+ resultBounds: boundsOfShapesMovingTogether,
5082
+ visited
5083
+ });
5084
+ const commonPageBounds = import_Box.Box.Common(boundsOfShapesMovingTogether);
5085
+ if (!commonPageBounds) continue;
5086
+ shapeClustersToDistribute.push({
5087
+ shapes: shapesMovingTogether,
5088
+ pageBounds: commonPageBounds
5089
+ });
5090
+ allBounds.push(commonPageBounds);
5091
+ }
5092
+ if (shapeClustersToDistribute.length < 3) return this;
5004
5093
  let val;
5005
5094
  let min;
5006
5095
  let max;
5007
- let mid;
5008
5096
  let dim;
5009
5097
  if (operation === "horizontal") {
5010
5098
  val = "x";
5011
5099
  min = "minX";
5012
5100
  max = "maxX";
5013
- mid = "midX";
5014
5101
  dim = "width";
5015
5102
  } else {
5016
5103
  val = "y";
5017
5104
  min = "minY";
5018
5105
  max = "maxY";
5019
- mid = "midY";
5020
5106
  dim = "height";
5021
5107
  }
5022
5108
  const changes = [];
5023
- const first = shapesToDistribute.sort(
5024
- (a, b) => pageBounds[a.id][min] - pageBounds[b.id][min]
5025
- )[0];
5026
- const last2 = shapesToDistribute.sort((a, b) => pageBounds[b.id][max] - pageBounds[a.id][max])[0];
5027
- const midFirst = pageBounds[first.id][mid];
5028
- const step = (pageBounds[last2.id][mid] - midFirst) / (len - 1);
5029
- const v = midFirst + step;
5030
- shapesToDistribute.filter((shape) => shape !== first && shape !== last2).sort((a, b) => pageBounds[a.id][mid] - pageBounds[b.id][mid]).forEach((shape, i) => {
5031
- const delta = { x: 0, y: 0 };
5032
- delta[val] = v + step * i - pageBounds[shape.id][dim] / 2 - pageBounds[shape.id][val];
5033
- const parent = this.getShapeParent(shape);
5034
- const localDelta = parent ? import_Vec.Vec.Rot(delta, -this.getShapePageTransform(parent).rotation()) : delta;
5035
- changes.push(this.getChangesToTranslateShape(shape, import_Vec.Vec.Add(shape, localDelta)));
5109
+ const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
5110
+ const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
5111
+ if (first === last2) {
5112
+ const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
5113
+ return this.distributeShapes(
5114
+ ids.filter((id) => !excludedShapeIds.has(id)),
5115
+ operation
5116
+ );
5117
+ }
5118
+ const shapeClustersToMove = shapeClustersToDistribute.filter((shape) => shape !== first && shape !== last2).sort((a, b) => {
5119
+ if (a.pageBounds[min] === b.pageBounds[min]) {
5120
+ return a.shapes[0].id < b.shapes[0].id ? -1 : 1;
5121
+ }
5122
+ return a.pageBounds[min] - b.pageBounds[min];
5036
5123
  });
5124
+ const maxFirst = first.pageBounds[max];
5125
+ const range = last2.pageBounds[min] - maxFirst;
5126
+ const summedShapeDimensions = shapeClustersToMove.reduce((acc, s) => acc + s.pageBounds[dim], 0);
5127
+ const gap = (range - summedShapeDimensions) / (shapeClustersToMove.length + 1);
5128
+ for (let v = maxFirst + gap, i = 0; i < shapeClustersToMove.length; i++) {
5129
+ const { shapes: shapes2, pageBounds } = shapeClustersToMove[i];
5130
+ const delta = new import_Vec.Vec();
5131
+ delta[val] = v - pageBounds[val];
5132
+ if (v + pageBounds[dim] > last2.pageBounds[max] - 1) {
5133
+ delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
5134
+ }
5135
+ for (const shape of shapes2) {
5136
+ const shapeDelta = delta.clone();
5137
+ const parent = this.getShapeParent(shape);
5138
+ if (parent) {
5139
+ const parentTransform = this.getShapePageTransform(parent);
5140
+ if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
5141
+ }
5142
+ shapeDelta.add(shape);
5143
+ changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
5144
+ }
5145
+ v += pageBounds[dim] + gap;
5146
+ }
5037
5147
  this.updateShapes(changes);
5038
5148
  return this;
5039
5149
  }
@@ -5054,59 +5164,78 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5054
5164
  stretchShapes(shapes, operation) {
5055
5165
  const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
5056
5166
  if (this.getIsReadonly()) return this;
5057
- if (ids.length < 2) return this;
5058
- const shapesToStretch = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
5059
- const shapeBounds = Object.fromEntries(ids.map((id) => [id, this.getShapeGeometry(id).bounds]));
5060
- const shapePageBounds = Object.fromEntries(ids.map((id) => [id, this.getShapePageBounds(id)]));
5061
- const commonBounds = import_Box.Box.Common((0, import_utils.compact)(Object.values(shapePageBounds)));
5062
- switch (operation) {
5063
- case "vertical": {
5064
- this.run(() => {
5065
- for (const shape of shapesToStretch) {
5066
- const pageRotation = this.getShapePageTransform(shape).rotation();
5067
- if (pageRotation % import_utils2.PI2) continue;
5068
- const bounds = shapeBounds[shape.id];
5069
- const pageBounds = shapePageBounds[shape.id];
5070
- const localOffset = new import_Vec.Vec(0, commonBounds.minY - pageBounds.minY);
5071
- const parentTransform = this.getShapeParentTransform(shape);
5072
- if (parentTransform) localOffset.rot(-parentTransform.rotation());
5073
- const { x, y } = import_Vec.Vec.Add(localOffset, shape);
5074
- this.updateShapes([{ id: shape.id, type: shape.type, x, y }]);
5075
- const scale = new import_Vec.Vec(1, commonBounds.height / pageBounds.height);
5076
- this.resizeShape(shape.id, scale, {
5077
- initialBounds: bounds,
5078
- scaleOrigin: new import_Vec.Vec(pageBounds.center.x, commonBounds.minY),
5079
- isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
5080
- scaleAxisRotation: 0
5081
- });
5082
- }
5083
- });
5084
- break;
5085
- }
5086
- case "horizontal": {
5087
- this.run(() => {
5088
- for (const shape of shapesToStretch) {
5089
- const bounds = shapeBounds[shape.id];
5090
- const pageBounds = shapePageBounds[shape.id];
5091
- const pageRotation = this.getShapePageTransform(shape).rotation();
5092
- if (pageRotation % import_utils2.PI2) continue;
5093
- const localOffset = new import_Vec.Vec(commonBounds.minX - pageBounds.minX, 0);
5094
- const parentTransform = this.getShapeParentTransform(shape);
5095
- if (parentTransform) localOffset.rot(-parentTransform.rotation());
5096
- const { x, y } = import_Vec.Vec.Add(localOffset, shape);
5097
- this.updateShapes([{ id: shape.id, type: shape.type, x, y }]);
5098
- const scale = new import_Vec.Vec(commonBounds.width / pageBounds.width, 1);
5099
- this.resizeShape(shape.id, scale, {
5100
- initialBounds: bounds,
5101
- scaleOrigin: new import_Vec.Vec(commonBounds.minX, pageBounds.center.y),
5102
- isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
5103
- scaleAxisRotation: 0
5104
- });
5105
- }
5106
- });
5107
- break;
5167
+ const shapesToStretchFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id))).filter(
5168
+ (s) => this.getShapePageTransform(s)?.rotation() % (import_utils2.PI / 2) === 0
5169
+ );
5170
+ const shapeClustersToStretch = [];
5171
+ const allBounds = [];
5172
+ const visited = /* @__PURE__ */ new Set();
5173
+ for (const shape of shapesToStretchFirstPass) {
5174
+ if (visited.has(shape.id)) continue;
5175
+ visited.add(shape.id);
5176
+ const shapePageBounds = this.getShapePageBounds(shape);
5177
+ if (!shapePageBounds) continue;
5178
+ const shapesMovingTogether = [shape];
5179
+ const boundsOfShapesMovingTogether = [shapePageBounds];
5180
+ if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
5181
+ type: "stretch",
5182
+ shapes: shapesToStretchFirstPass
5183
+ })) {
5184
+ continue;
5108
5185
  }
5186
+ this.collectShapesViaArrowBindings({
5187
+ bindings: this.getBindingsToShape(shape.id, "arrow"),
5188
+ initialShapes: shapesToStretchFirstPass,
5189
+ resultShapes: shapesMovingTogether,
5190
+ resultBounds: boundsOfShapesMovingTogether,
5191
+ visited
5192
+ });
5193
+ const commonPageBounds = import_Box.Box.Common(boundsOfShapesMovingTogether);
5194
+ if (!commonPageBounds) continue;
5195
+ shapeClustersToStretch.push({
5196
+ shapes: shapesMovingTogether,
5197
+ pageBounds: commonPageBounds
5198
+ });
5199
+ allBounds.push(commonPageBounds);
5109
5200
  }
5201
+ if (shapeClustersToStretch.length < 2) return this;
5202
+ const commonBounds = import_Box.Box.Common(allBounds);
5203
+ let val;
5204
+ let min;
5205
+ let dim;
5206
+ if (operation === "horizontal") {
5207
+ val = "x";
5208
+ min = "minX";
5209
+ dim = "width";
5210
+ } else {
5211
+ val = "y";
5212
+ min = "minY";
5213
+ dim = "height";
5214
+ }
5215
+ this.run(() => {
5216
+ shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
5217
+ const localOffset = new import_Vec.Vec();
5218
+ localOffset[val] = commonBounds[min] - pageBounds[min];
5219
+ const scaleOrigin = pageBounds.center.clone();
5220
+ scaleOrigin[val] = commonBounds[min];
5221
+ const scale = new import_Vec.Vec(1, 1);
5222
+ scale[val] = commonBounds[dim] / pageBounds[dim];
5223
+ for (const shape of shapes2) {
5224
+ const shapeLocalOffset = localOffset.clone();
5225
+ const parentTransform = this.getShapeParentTransform(shape);
5226
+ if (parentTransform) localOffset.rot(-parentTransform.rotation());
5227
+ shapeLocalOffset.add(shape);
5228
+ const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
5229
+ this.updateShape(changes);
5230
+ this.resizeShape(shape.id, scale, {
5231
+ initialBounds: this.getShapeGeometry(shape).bounds,
5232
+ scaleOrigin,
5233
+ isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
5234
+ scaleAxisRotation: 0
5235
+ });
5236
+ }
5237
+ });
5238
+ });
5110
5239
  return this;
5111
5240
  }
5112
5241
  /**
@@ -5121,8 +5250,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5121
5250
  resizeShape(shape, scale, opts = {}) {
5122
5251
  const id = typeof shape === "string" ? shape : shape.id;
5123
5252
  if (this.getIsReadonly()) return this;
5124
- if (!Number.isFinite(scale.x)) scale = new import_Vec.Vec(1, scale.y);
5125
- if (!Number.isFinite(scale.y)) scale = new import_Vec.Vec(scale.x, 1);
5253
+ if (!import_core_js.Number.isFinite(scale.x)) scale = new import_Vec.Vec(1, scale.y);
5254
+ if (!import_core_js.Number.isFinite(scale.y)) scale = new import_Vec.Vec(scale.x, 1);
5126
5255
  const initialShape = opts.initialShape ?? this.getShape(id);
5127
5256
  if (!initialShape) return this;
5128
5257
  const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center;
@@ -5310,7 +5439,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5310
5439
  * @example
5311
5440
  * ```ts
5312
5441
  * editor.createShape(myShape)
5313
- * editor.createShape({ id: 'box1', type: 'text', props: { richText: toRichText("ok") } })
5442
+ * editor.createShape({ id: 'box1', type: 'text', props: { text: "ok" } })
5314
5443
  * ```
5315
5444
  *
5316
5445
  * @param shape - The shape (or shape partial) to create.
@@ -5327,7 +5456,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5327
5456
  * @example
5328
5457
  * ```ts
5329
5458
  * editor.createShapes([myShape])
5330
- * editor.createShapes([{ id: 'box1', type: 'text', props: { richText: toRichText("ok") } }])
5459
+ * editor.createShapes([{ id: 'box1', type: 'text', props: { text: "ok" } }])
5331
5460
  * ```
5332
5461
  *
5333
5462
  * @param shapes - The shapes (or shape partials) to create.
@@ -7332,7 +7461,6 @@ __decorateElement(_init, 1, "getFocusedGroupId", _getFocusedGroupId_dec, Editor)
7332
7461
  __decorateElement(_init, 1, "getFocusedGroup", _getFocusedGroup_dec, Editor);
7333
7462
  __decorateElement(_init, 1, "getEditingShapeId", _getEditingShapeId_dec, Editor);
7334
7463
  __decorateElement(_init, 1, "getEditingShape", _getEditingShape_dec, Editor);
7335
- __decorateElement(_init, 1, "getRichTextEditor", _getRichTextEditor_dec, Editor);
7336
7464
  __decorateElement(_init, 1, "getHoveredShapeId", _getHoveredShapeId_dec, Editor);
7337
7465
  __decorateElement(_init, 1, "getHoveredShape", _getHoveredShape_dec, Editor);
7338
7466
  __decorateElement(_init, 1, "getHintingShapeIds", _getHintingShapeIds_dec, Editor);
@@ -7356,7 +7484,6 @@ __decorateElement(_init, 1, "getPages", _getPages_dec, Editor);
7356
7484
  __decorateElement(_init, 1, "getCurrentPageId", _getCurrentPageId_dec, Editor);
7357
7485
  __decorateElement(_init, 1, "getCurrentPageShapeIdsSorted", _getCurrentPageShapeIdsSorted_dec, Editor);
7358
7486
  __decorateElement(_init, 1, "_getAllAssetsQuery", __getAllAssetsQuery_dec, Editor);
7359
- __decorateElement(_init, 1, "_getShapeGeometryCache", __getShapeGeometryCache_dec, Editor);
7360
7487
  __decorateElement(_init, 1, "_getShapeHandlesCache", __getShapeHandlesCache_dec, Editor);
7361
7488
  __decorateElement(_init, 1, "_getShapePageTransformCache", __getShapePageTransformCache_dec, Editor);
7362
7489
  __decorateElement(_init, 1, "_getShapePageBoundsCache", __getShapePageBoundsCache_dec, Editor);
@@ -7446,7 +7573,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
7446
7573
  result = import_utils.Result.err(error);
7447
7574
  }
7448
7575
  });
7449
- editor.store.applyDiff((0, import_store.reverseRecordsDiff)(changes));
7576
+ editor.store.applyDiff((0, import_store.reverseRecordsDiff)(changes), { runCallbacks: false });
7450
7577
  },
7451
7578
  { history: "ignore" }
7452
7579
  );