@tldraw/editor 3.9.0-internal.7f0e15f4f7d9 → 3.9.0
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.
- package/CHANGELOG.md +90 -0
- package/README.md +1 -1
- package/dist-cjs/index.d.ts +36 -229
- package/dist-cjs/index.js +1 -9
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +6 -33
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +0 -7
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +435 -308
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/managers/TextManager.js +17 -23
- package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +7 -13
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/FontEmbedder.js +2 -7
- package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/exportToSvg.js +2 -3
- package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +1 -18
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/exports/parseCss.js +0 -1
- package/dist-cjs/lib/exports/parseCss.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -1
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/options.js +1 -2
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/dom.js +1 -1
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +36 -229
- package/dist-esm/index.mjs +1 -13
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +7 -34
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +1 -8
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +432 -312
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/managers/TextManager.mjs +17 -23
- package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +7 -13
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/exports/FontEmbedder.mjs +2 -7
- package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/exportToSvg.mjs +2 -3
- package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +2 -19
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/exports/parseCss.mjs +0 -1
- package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +1 -1
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +1 -2
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/dom.mjs +1 -1
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +13 -127
- package/package.json +7 -10
- package/src/index.ts +2 -15
- package/src/lib/TldrawEditor.tsx +4 -52
- package/src/lib/components/Shape.tsx +1 -9
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +5 -3
- package/src/lib/editor/Editor.ts +561 -362
- package/src/lib/editor/managers/TextManager.ts +17 -42
- package/src/lib/editor/shapes/ShapeUtil.ts +32 -18
- package/src/lib/editor/types/emit-types.ts +0 -1
- package/src/lib/editor/types/external-content.ts +0 -1
- package/src/lib/exports/FontEmbedder.ts +1 -13
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/exports/exportToSvg.tsx +3 -4
- package/src/lib/exports/getSvgJsx.tsx +3 -22
- package/src/lib/exports/parseCss.ts +0 -1
- package/src/lib/hooks/useCanvasEvents.ts +1 -2
- package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +0 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +1 -0
- package/src/lib/options.ts +0 -7
- package/src/lib/utils/dom.ts +1 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/managers/FontManager.js +0 -167
- package/dist-cjs/lib/editor/managers/FontManager.js.map +0 -7
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +0 -48
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +0 -7
- package/dist-cjs/lib/hooks/useViewportHeight.js +0 -56
- package/dist-cjs/lib/hooks/useViewportHeight.js.map +0 -7
- package/dist-cjs/lib/utils/richText.js +0 -46
- package/dist-cjs/lib/utils/richText.js.map +0 -7
- package/dist-esm/lib/editor/managers/FontManager.mjs +0 -153
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +0 -7
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +0 -28
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +0 -7
- package/dist-esm/lib/hooks/useViewportHeight.mjs +0 -36
- package/dist-esm/lib/hooks/useViewportHeight.mjs.map +0 -7
- package/dist-esm/lib/utils/richText.mjs +0 -26
- package/dist-esm/lib/utils/richText.mjs.map +0 -7
- package/src/lib/editor/managers/FontManager.ts +0 -252
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +0 -29
- package/src/lib/hooks/useViewportHeight.ts +0 -37
- 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,
|
|
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],
|
|
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
|
-
|
|
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")
|
|
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
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
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
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
const
|
|
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
|
-
|
|
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
|
|
4766
|
-
const
|
|
4767
|
-
const
|
|
4768
|
-
|
|
4769
|
-
|
|
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 =
|
|
4778
|
-
|
|
4779
|
-
if (
|
|
4780
|
-
maxCount =
|
|
4781
|
-
shapeGap =
|
|
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
|
-
|
|
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 =
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
const delta =
|
|
4795
|
-
delta[val] = v + shapeGap - pageBounds[
|
|
4796
|
-
const
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4831
|
-
const
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
const
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
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
|
-
|
|
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 (
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
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 (
|
|
4867
|
-
} else if (
|
|
4868
|
-
space.x +=
|
|
4869
|
-
space.width -=
|
|
4870
|
-
} else if (
|
|
4871
|
-
space.y +=
|
|
4872
|
-
space.height -=
|
|
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 + (
|
|
4916
|
+
space.x + (nextPageBounds.width + gap),
|
|
4877
4917
|
space.y,
|
|
4878
|
-
space.width - (
|
|
4879
|
-
|
|
4918
|
+
space.width - (nextPageBounds.width + gap),
|
|
4919
|
+
nextPageBounds.height
|
|
4880
4920
|
)
|
|
4881
4921
|
);
|
|
4882
|
-
space.y +=
|
|
4883
|
-
space.height -=
|
|
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(
|
|
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 (
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
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
|
-
|
|
4938
|
-
const
|
|
4939
|
-
const
|
|
4940
|
-
|
|
4941
|
-
);
|
|
4942
|
-
const
|
|
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
|
-
|
|
4945
|
-
const
|
|
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
|
|
4975
|
-
|
|
4976
|
-
|
|
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
|
-
|
|
4999
|
-
const
|
|
5000
|
-
const
|
|
5001
|
-
const
|
|
5002
|
-
|
|
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 =
|
|
5024
|
-
|
|
5025
|
-
)
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
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
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
const
|
|
5061
|
-
const
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
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: {
|
|
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: {
|
|
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
|
);
|