@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.
- package/CHANGELOG.md +90 -0
- package/README.md +1 -1
- package/dist-cjs/index.d.ts +41 -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/LiveCollaborators.js +5 -0
- package/dist-cjs/lib/components/LiveCollaborators.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/DefaultBrush.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCursor.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/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.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 +41 -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/LiveCollaborators.mjs +5 -0
- package/dist-esm/lib/components/LiveCollaborators.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/DefaultBrush.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCursor.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/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.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/LiveCollaborators.tsx +5 -0
- package/src/lib/components/Shape.tsx +1 -9
- package/src/lib/components/default-components/DefaultBrush.tsx +1 -0
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -0
- package/src/lib/components/default-components/DefaultCursor.tsx +1 -0
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +5 -3
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -0
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -0
- 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
|
@@ -46,15 +46,8 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
|
|
|
46
46
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
47
47
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
48
48
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
49
|
-
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,
|
|
50
|
-
import {
|
|
51
|
-
EMPTY_ARRAY,
|
|
52
|
-
atom,
|
|
53
|
-
computed,
|
|
54
|
-
react,
|
|
55
|
-
transact,
|
|
56
|
-
unsafe__withoutCapture
|
|
57
|
-
} from "@tldraw/state";
|
|
49
|
+
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;
|
|
50
|
+
import { EMPTY_ARRAY, atom, computed, react, transact, unsafe__withoutCapture } from "@tldraw/state";
|
|
58
51
|
import {
|
|
59
52
|
reverseRecordsDiff
|
|
60
53
|
} from "@tldraw/store";
|
|
@@ -99,6 +92,7 @@ import {
|
|
|
99
92
|
structuredClone,
|
|
100
93
|
uniqueId
|
|
101
94
|
} from "@tldraw/utils";
|
|
95
|
+
import { Number } from "core-js";
|
|
102
96
|
import EventEmitter from "eventemitter3";
|
|
103
97
|
import {
|
|
104
98
|
getSnapshot,
|
|
@@ -129,7 +123,7 @@ import { Vec } from "../primitives/Vec.mjs";
|
|
|
129
123
|
import { EASINGS } from "../primitives/easings.mjs";
|
|
130
124
|
import { Group2d } from "../primitives/geometry/Group2d.mjs";
|
|
131
125
|
import { intersectPolygonPolygon } from "../primitives/intersect.mjs";
|
|
132
|
-
import {
|
|
126
|
+
import { PI, approximately, areAnglesCompatible, clamp, pointInPolygon } from "../primitives/utils.mjs";
|
|
133
127
|
import { SharedStyleMap } from "../utils/SharedStylesMap.mjs";
|
|
134
128
|
import { dataUrlToFile } from "../utils/assets.mjs";
|
|
135
129
|
import { debugFlags } from "../utils/debug-flags.mjs";
|
|
@@ -148,7 +142,6 @@ import { deriveShapeIdsInCurrentPage } from "./derivations/shapeIdsInCurrentPage
|
|
|
148
142
|
import { ClickManager } from "./managers/ClickManager.mjs";
|
|
149
143
|
import { EdgeScrollManager } from "./managers/EdgeScrollManager.mjs";
|
|
150
144
|
import { FocusManager } from "./managers/FocusManager.mjs";
|
|
151
|
-
import { FontManager } from "./managers/FontManager.mjs";
|
|
152
145
|
import { HistoryManager } from "./managers/HistoryManager.mjs";
|
|
153
146
|
import { ScribbleManager } from "./managers/ScribbleManager.mjs";
|
|
154
147
|
import { SnapManager } from "./managers/SnapManager/SnapManager.mjs";
|
|
@@ -156,7 +149,7 @@ import { TextManager } from "./managers/TextManager.mjs";
|
|
|
156
149
|
import { TickManager } from "./managers/TickManager.mjs";
|
|
157
150
|
import { UserPreferencesManager } from "./managers/UserPreferencesManager.mjs";
|
|
158
151
|
import { RootState } from "./tools/RootState.mjs";
|
|
159
|
-
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _getCanUndo_dec = [computed], _getCanRedo_dec = [computed], _getPath_dec = [computed], _getCurrentTool_dec = [computed], _getCurrentToolId_dec = [computed], _getDocumentSettings_dec = [computed], _getInstanceState_dec = [computed], _getOpenMenus_dec = [computed], _getIsMenuOpen_dec = [computed], _getPageStates_dec = [computed], __getPageStatesQuery_dec = [computed], _getCurrentPageState_dec = [computed], __getCurrentPageStateId_dec = [computed], _getSelectedShapeIds_dec = [computed], _getSelectedShapes_dec = [computed], _getOnlySelectedShapeId_dec = [computed], _getOnlySelectedShape_dec = [computed], _getSelectionPageBounds_dec = [computed], _getSelectionRotation_dec = [computed], _getSelectionRotatedPageBounds_dec = [computed], _getSelectionRotatedScreenBounds_dec = [computed], _getFocusedGroupId_dec = [computed], _getFocusedGroup_dec = [computed], _getEditingShapeId_dec = [computed], _getEditingShape_dec = [computed],
|
|
152
|
+
class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed], _getCanUndo_dec = [computed], _getCanRedo_dec = [computed], _getPath_dec = [computed], _getCurrentTool_dec = [computed], _getCurrentToolId_dec = [computed], _getDocumentSettings_dec = [computed], _getInstanceState_dec = [computed], _getOpenMenus_dec = [computed], _getIsMenuOpen_dec = [computed], _getPageStates_dec = [computed], __getPageStatesQuery_dec = [computed], _getCurrentPageState_dec = [computed], __getCurrentPageStateId_dec = [computed], _getSelectedShapeIds_dec = [computed], _getSelectedShapes_dec = [computed], _getOnlySelectedShapeId_dec = [computed], _getOnlySelectedShape_dec = [computed], _getSelectionPageBounds_dec = [computed], _getSelectionRotation_dec = [computed], _getSelectionRotatedPageBounds_dec = [computed], _getSelectionRotatedScreenBounds_dec = [computed], _getFocusedGroupId_dec = [computed], _getFocusedGroup_dec = [computed], _getEditingShapeId_dec = [computed], _getEditingShape_dec = [computed], _getHoveredShapeId_dec = [computed], _getHoveredShape_dec = [computed], _getHintingShapeIds_dec = [computed], _getHintingShape_dec = [computed], _getErasingShapeIds_dec = [computed], _getErasingShapes_dec = [computed], __unsafe_getCameraId_dec = [computed], _getCamera_dec = [computed], _getViewportPageBoundsForFollowing_dec = [computed], _getCameraForFollowing_dec = [computed], _getZoomLevel_dec = [computed], _getViewportScreenBounds_dec = [computed], _getViewportScreenCenter_dec = [computed], _getViewportPageBounds_dec = [computed], __getCollaboratorsQuery_dec = [computed], _getCollaborators_dec = [computed], _getCollaboratorsOnCurrentPage_dec = [computed], _getRenderingShapes_dec = [computed], __getAllPagesQuery_dec = [computed], _getPages_dec = [computed], _getCurrentPageId_dec = [computed], _getCurrentPageShapeIdsSorted_dec = [computed], __getAllAssetsQuery_dec = [computed], __getShapeHandlesCache_dec = [computed], __getShapePageTransformCache_dec = [computed], __getShapePageBoundsCache_dec = [computed], __getShapeClipPathCache_dec = [computed], __getShapeMaskCache_dec = [computed], __getShapeMaskedPageBoundsCache_dec = [computed], __notVisibleShapes_dec = [computed], _getCulledShapes_dec = [computed], _getCurrentPageBounds_dec = [computed], _getCurrentPageShapes_dec = [computed], _getCurrentPageShapesSorted_dec = [computed], _getCurrentPageRenderingShapesSorted_dec = [computed], __getBindingsIndexCache_dec = [computed], __getSelectionSharedStyles_dec = [computed], _getSharedStyles_dec = [computed({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [computed], _getIsFocused_dec = [computed], _getIsReadonly_dec = [computed], __setShiftKeyTimeout_dec = [bind], __setAltKeyTimeout_dec = [bind], __setCtrlKeyTimeout_dec = [bind], __setMetaKeyTimeout_dec = [bind], _a) {
|
|
160
153
|
constructor({
|
|
161
154
|
store,
|
|
162
155
|
user,
|
|
@@ -165,13 +158,11 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
165
158
|
tools,
|
|
166
159
|
getContainer,
|
|
167
160
|
cameraOptions,
|
|
168
|
-
textOptions,
|
|
169
161
|
initialState,
|
|
170
162
|
autoFocus,
|
|
171
163
|
inferDarkMode,
|
|
172
164
|
options,
|
|
173
|
-
isShapeHidden
|
|
174
|
-
fontAssetUrls
|
|
165
|
+
isShapeHidden
|
|
175
166
|
}) {
|
|
176
167
|
super();
|
|
177
168
|
__runInitializers(_init, 5, this);
|
|
@@ -229,12 +220,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
229
220
|
* @public
|
|
230
221
|
*/
|
|
231
222
|
__publicField(this, "textMeasure");
|
|
232
|
-
/**
|
|
233
|
-
* A utility for managing the set of fonts that should be rendered in the document.
|
|
234
|
-
*
|
|
235
|
-
* @public
|
|
236
|
-
*/
|
|
237
|
-
__publicField(this, "fonts");
|
|
238
223
|
/**
|
|
239
224
|
* A manager for the editor's environment.
|
|
240
225
|
*
|
|
@@ -306,9 +291,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
306
291
|
__publicField(this, "_isChangingStyleTimeout", -1);
|
|
307
292
|
// Menus
|
|
308
293
|
__publicField(this, "menus", tlmenus.forContext(this.contextId));
|
|
309
|
-
// Rich text editor
|
|
310
|
-
__publicField(this, "_currentRichTextEditor", atom("rich text editor", null));
|
|
311
|
-
__publicField(this, "_textOptions");
|
|
312
294
|
__publicField(this, "_cameraOptions", atom("camera options", DEFAULT_CAMERA_OPTIONS));
|
|
313
295
|
/** @internal */
|
|
314
296
|
__publicField(this, "_viewportAnimation", null);
|
|
@@ -329,6 +311,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
329
311
|
__publicField(this, "_cameraStateTimeoutRemaining", 0);
|
|
330
312
|
/* @internal */
|
|
331
313
|
__publicField(this, "_currentPageShapeIds");
|
|
314
|
+
/* --------------------- Shapes --------------------- */
|
|
315
|
+
__publicField(this, "_shapeGeometryCaches", {});
|
|
332
316
|
// Parents and children
|
|
333
317
|
/**
|
|
334
318
|
* A cache of parents to children.
|
|
@@ -454,12 +438,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
454
438
|
this.snaps = new SnapManager(this);
|
|
455
439
|
this.disposables.add(this.timers.dispose);
|
|
456
440
|
this._cameraOptions.set({ ...DEFAULT_CAMERA_OPTIONS, ...cameraOptions });
|
|
457
|
-
this._textOptions = atom("text options", textOptions ?? null);
|
|
458
441
|
this.user = new UserPreferencesManager(user ?? createTLUser(), inferDarkMode ?? false);
|
|
459
442
|
this.disposables.add(() => this.user.dispose());
|
|
460
443
|
this.getContainer = getContainer;
|
|
461
444
|
this.textMeasure = new TextManager(this);
|
|
462
|
-
this.fonts = new FontManager(this, fontAssetUrls);
|
|
463
445
|
this._tickManager = new TickManager(this);
|
|
464
446
|
class NewRoot extends RootState {
|
|
465
447
|
static initial = initialState ?? "";
|
|
@@ -1631,7 +1613,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1631
1613
|
*/
|
|
1632
1614
|
setEditingShape(shape) {
|
|
1633
1615
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1634
|
-
this.setRichTextEditor(null);
|
|
1635
1616
|
if (id !== this.getEditingShapeId()) {
|
|
1636
1617
|
if (id) {
|
|
1637
1618
|
const shape2 = this.getShape(id);
|
|
@@ -1648,36 +1629,12 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1648
1629
|
this.run(
|
|
1649
1630
|
() => {
|
|
1650
1631
|
this._updateCurrentPageState({ editingShapeId: null });
|
|
1651
|
-
this._currentRichTextEditor.set(null);
|
|
1652
1632
|
},
|
|
1653
1633
|
{ history: "ignore" }
|
|
1654
1634
|
);
|
|
1655
1635
|
}
|
|
1656
1636
|
return this;
|
|
1657
1637
|
}
|
|
1658
|
-
getRichTextEditor() {
|
|
1659
|
-
return this._currentRichTextEditor.get();
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Set the current editing shape's rich text editor.
|
|
1663
|
-
*
|
|
1664
|
-
* @example
|
|
1665
|
-
* ```ts
|
|
1666
|
-
* editor.setRichTextEditor(richTextEditorView)
|
|
1667
|
-
* ```
|
|
1668
|
-
*
|
|
1669
|
-
* @param textEditor - The text editor to set as the current editing shape's text editor.
|
|
1670
|
-
*
|
|
1671
|
-
* @public
|
|
1672
|
-
*/
|
|
1673
|
-
setRichTextEditor(textEditor) {
|
|
1674
|
-
const current = this._currentRichTextEditor.__unsafe__getWithoutCapture();
|
|
1675
|
-
if (current !== textEditor) {
|
|
1676
|
-
current?.destroy();
|
|
1677
|
-
}
|
|
1678
|
-
this._currentRichTextEditor.set(textEditor);
|
|
1679
|
-
return this;
|
|
1680
|
-
}
|
|
1681
1638
|
getHoveredShapeId() {
|
|
1682
1639
|
return this.getCurrentPageState().hoveredShapeId;
|
|
1683
1640
|
}
|
|
@@ -1823,18 +1780,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1823
1780
|
}
|
|
1824
1781
|
return this;
|
|
1825
1782
|
}
|
|
1826
|
-
/**
|
|
1827
|
-
* Get the current text options.
|
|
1828
|
-
*
|
|
1829
|
-
* @example
|
|
1830
|
-
* ```ts
|
|
1831
|
-
* editor.getTextOptions()
|
|
1832
|
-
* ```
|
|
1833
|
-
*
|
|
1834
|
-
* @public */
|
|
1835
|
-
getTextOptions() {
|
|
1836
|
-
return assertExists(this._textOptions.get(), "Cannot use text without setting textOptions");
|
|
1837
|
-
}
|
|
1838
1783
|
_unsafe_getCameraId() {
|
|
1839
1784
|
return CameraRecordType.createId(this.getCurrentPageId());
|
|
1840
1785
|
}
|
|
@@ -3279,16 +3224,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3279
3224
|
async uploadAsset(asset, file, abortSignal) {
|
|
3280
3225
|
return await this.store.props.assets.upload(asset, file, abortSignal);
|
|
3281
3226
|
}
|
|
3282
|
-
_getShapeGeometryCache() {
|
|
3283
|
-
return this.store.createComputedCache(
|
|
3284
|
-
"bounds",
|
|
3285
|
-
(shape) => {
|
|
3286
|
-
this.fonts.trackFontsForShape(shape);
|
|
3287
|
-
return this.getShapeUtil(shape).getGeometry(shape);
|
|
3288
|
-
},
|
|
3289
|
-
{ areRecordsEqual: (a, b) => a.props === b.props }
|
|
3290
|
-
);
|
|
3291
|
-
}
|
|
3292
3227
|
/**
|
|
3293
3228
|
* Get the geometry of a shape.
|
|
3294
3229
|
*
|
|
@@ -3296,14 +3231,26 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3296
3231
|
* ```ts
|
|
3297
3232
|
* editor.getShapeGeometry(myShape)
|
|
3298
3233
|
* editor.getShapeGeometry(myShapeId)
|
|
3234
|
+
* editor.getShapeGeometry(myShapeId, { context: "arrow" })
|
|
3299
3235
|
* ```
|
|
3300
3236
|
*
|
|
3301
3237
|
* @param shape - The shape (or shape id) to get the geometry for.
|
|
3238
|
+
* @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
|
|
3302
3239
|
*
|
|
3303
3240
|
* @public
|
|
3304
3241
|
*/
|
|
3305
|
-
getShapeGeometry(shape) {
|
|
3306
|
-
|
|
3242
|
+
getShapeGeometry(shape, opts) {
|
|
3243
|
+
const context = opts?.context ?? "none";
|
|
3244
|
+
if (!this._shapeGeometryCaches[context]) {
|
|
3245
|
+
this._shapeGeometryCaches[context] = this.store.createComputedCache(
|
|
3246
|
+
"bounds",
|
|
3247
|
+
(shape2) => this.getShapeUtil(shape2).getGeometry(shape2, opts),
|
|
3248
|
+
{ areRecordsEqual: (a, b) => a.props === b.props }
|
|
3249
|
+
);
|
|
3250
|
+
}
|
|
3251
|
+
return this._shapeGeometryCaches[context].get(
|
|
3252
|
+
typeof shape === "string" ? shape : shape.id
|
|
3253
|
+
);
|
|
3307
3254
|
}
|
|
3308
3255
|
_getShapeHandlesCache() {
|
|
3309
3256
|
return this.store.createComputedCache("handles", (shape) => {
|
|
@@ -3705,7 +3652,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3705
3652
|
const geometry = this.getShapeGeometry(shape);
|
|
3706
3653
|
const isGroup = geometry instanceof Group2d;
|
|
3707
3654
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
3708
|
-
if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "arrow")
|
|
3655
|
+
if (this.isShapeOfType(shape, "frame") || (this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shape.props.text.trim()) {
|
|
3709
3656
|
for (const childGeometry of geometry.children) {
|
|
3710
3657
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
3711
3658
|
return shape;
|
|
@@ -4369,27 +4316,28 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4369
4316
|
});
|
|
4370
4317
|
return this;
|
|
4371
4318
|
}
|
|
4319
|
+
// Gets a shape partial that includes life cycle changes: on translate start, on translate, on translate end
|
|
4372
4320
|
getChangesToTranslateShape(initialShape, newShapeCoords) {
|
|
4373
4321
|
let workingShape = initialShape;
|
|
4374
4322
|
const util = this.getShapeUtil(initialShape);
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4323
|
+
const afterTranslateStart = util.onTranslateStart?.(workingShape);
|
|
4324
|
+
if (afterTranslateStart) {
|
|
4325
|
+
workingShape = applyPartialToRecordWithProps(workingShape, afterTranslateStart);
|
|
4326
|
+
}
|
|
4379
4327
|
workingShape = applyPartialToRecordWithProps(workingShape, {
|
|
4380
4328
|
id: initialShape.id,
|
|
4381
4329
|
type: initialShape.type,
|
|
4382
4330
|
x: newShapeCoords.x,
|
|
4383
4331
|
y: newShapeCoords.y
|
|
4384
4332
|
});
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4333
|
+
const afterTranslate = util.onTranslate?.(initialShape, workingShape);
|
|
4334
|
+
if (afterTranslate) {
|
|
4335
|
+
workingShape = applyPartialToRecordWithProps(workingShape, afterTranslate);
|
|
4336
|
+
}
|
|
4337
|
+
const afterTranslateEnd = util.onTranslateEnd?.(initialShape, workingShape);
|
|
4338
|
+
if (afterTranslateEnd) {
|
|
4339
|
+
workingShape = applyPartialToRecordWithProps(workingShape, afterTranslateEnd);
|
|
4340
|
+
}
|
|
4393
4341
|
return workingShape;
|
|
4394
4342
|
}
|
|
4395
4343
|
/**
|
|
@@ -4696,6 +4644,30 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4696
4644
|
if (changes) this.updateShapes(changes);
|
|
4697
4645
|
return this;
|
|
4698
4646
|
}
|
|
4647
|
+
/**
|
|
4648
|
+
* @internal
|
|
4649
|
+
*/
|
|
4650
|
+
collectShapesViaArrowBindings(info) {
|
|
4651
|
+
const { initialShapes, resultShapes, resultBounds, bindings, visited } = info;
|
|
4652
|
+
for (const binding of bindings) {
|
|
4653
|
+
for (const id of [binding.fromId, binding.toId]) {
|
|
4654
|
+
if (!visited.has(id)) {
|
|
4655
|
+
const aligningShape = initialShapes.find((s) => s.id === id);
|
|
4656
|
+
if (aligningShape && !visited.has(aligningShape.id)) {
|
|
4657
|
+
visited.add(aligningShape.id);
|
|
4658
|
+
const shapePageBounds = this.getShapePageBounds(aligningShape);
|
|
4659
|
+
if (!shapePageBounds) continue;
|
|
4660
|
+
resultShapes.push(aligningShape);
|
|
4661
|
+
resultBounds.push(shapePageBounds);
|
|
4662
|
+
this.collectShapesViaArrowBindings({
|
|
4663
|
+
...info,
|
|
4664
|
+
bindings: this.getBindingsInvolvingShape(aligningShape, "arrow")
|
|
4665
|
+
});
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4699
4671
|
/**
|
|
4700
4672
|
* Flip shape positions.
|
|
4701
4673
|
*
|
|
@@ -4711,35 +4683,52 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4711
4683
|
* @public
|
|
4712
4684
|
*/
|
|
4713
4685
|
flipShapes(shapes, operation) {
|
|
4714
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4715
4686
|
if (this.getIsReadonly()) return this;
|
|
4716
|
-
|
|
4687
|
+
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4688
|
+
const shapesToFlipFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
4689
|
+
for (const shape of shapesToFlipFirstPass) {
|
|
4690
|
+
if (this.isShapeOfType(shape, "group")) {
|
|
4691
|
+
const childrenOfGroups = compact(
|
|
4692
|
+
this.getSortedChildIdsForParent(shape.id).map((id) => this.getShape(id))
|
|
4693
|
+
);
|
|
4694
|
+
shapesToFlipFirstPass.push(...childrenOfGroups);
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
const shapesToFlip = [];
|
|
4698
|
+
const allBounds = [];
|
|
4699
|
+
for (const shape of shapesToFlipFirstPass) {
|
|
4700
|
+
const util = this.getShapeUtil(shape);
|
|
4701
|
+
if (!util.canBeLaidOut(shape, {
|
|
4702
|
+
type: "flip",
|
|
4703
|
+
shapes: shapesToFlipFirstPass
|
|
4704
|
+
})) {
|
|
4705
|
+
continue;
|
|
4706
|
+
}
|
|
4707
|
+
const pageBounds = this.getShapePageBounds(shape);
|
|
4708
|
+
const localBounds = this.getShapeGeometry(shape).bounds;
|
|
4709
|
+
const pageTransform = this.getShapePageTransform(shape.id);
|
|
4710
|
+
if (!(pageBounds && localBounds && pageTransform)) continue;
|
|
4711
|
+
shapesToFlip.push({
|
|
4712
|
+
shape,
|
|
4713
|
+
localBounds,
|
|
4714
|
+
pageTransform,
|
|
4715
|
+
isAspectRatioLocked: util.isAspectRatioLocked(shape)
|
|
4716
|
+
});
|
|
4717
|
+
allBounds.push(pageBounds);
|
|
4718
|
+
}
|
|
4717
4719
|
if (!shapesToFlip.length) return this;
|
|
4718
|
-
|
|
4719
|
-
shapesToFlip.map((shape) => {
|
|
4720
|
-
if (this.isShapeOfType(shape, "group")) {
|
|
4721
|
-
return this.getSortedChildIdsForParent(shape.id).map((id) => this.getShape(id));
|
|
4722
|
-
}
|
|
4723
|
-
return shape;
|
|
4724
|
-
}).flat()
|
|
4725
|
-
);
|
|
4726
|
-
const scaleOriginPage = Box.Common(
|
|
4727
|
-
compact(shapesToFlip.map((id) => this.getShapePageBounds(id)))
|
|
4728
|
-
).center;
|
|
4720
|
+
const scaleOriginPage = Box.Common(allBounds).center;
|
|
4729
4721
|
this.run(() => {
|
|
4730
|
-
for (const shape of shapesToFlip) {
|
|
4731
|
-
const bounds = this.getShapeGeometry(shape).bounds;
|
|
4732
|
-
const initialPageTransform = this.getShapePageTransform(shape.id);
|
|
4733
|
-
if (!initialPageTransform) continue;
|
|
4722
|
+
for (const { shape, localBounds, pageTransform, isAspectRatioLocked } of shapesToFlip) {
|
|
4734
4723
|
this.resizeShape(
|
|
4735
4724
|
shape.id,
|
|
4736
4725
|
{ x: operation === "horizontal" ? -1 : 1, y: operation === "vertical" ? -1 : 1 },
|
|
4737
4726
|
{
|
|
4738
|
-
initialBounds:
|
|
4739
|
-
initialPageTransform,
|
|
4727
|
+
initialBounds: localBounds,
|
|
4728
|
+
initialPageTransform: pageTransform,
|
|
4740
4729
|
initialShape: shape,
|
|
4730
|
+
isAspectRatioLocked,
|
|
4741
4731
|
mode: "scale_shape",
|
|
4742
|
-
isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
|
|
4743
4732
|
scaleOrigin: scaleOriginPage,
|
|
4744
4733
|
scaleAxisRotation: 0
|
|
4745
4734
|
}
|
|
@@ -4766,15 +4755,40 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4766
4755
|
stackShapes(shapes, operation, gap) {
|
|
4767
4756
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4768
4757
|
if (this.getIsReadonly()) return this;
|
|
4769
|
-
const
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
const
|
|
4758
|
+
const shapesToStackFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
4759
|
+
const shapeClustersToStack = [];
|
|
4760
|
+
const allBounds = [];
|
|
4761
|
+
const visited = /* @__PURE__ */ new Set();
|
|
4762
|
+
for (const shape of shapesToStackFirstPass) {
|
|
4763
|
+
if (visited.has(shape.id)) continue;
|
|
4764
|
+
visited.add(shape.id);
|
|
4765
|
+
const shapePageBounds = this.getShapePageBounds(shape);
|
|
4766
|
+
if (!shapePageBounds) continue;
|
|
4767
|
+
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
4768
|
+
type: "stack",
|
|
4769
|
+
shapes: shapesToStackFirstPass
|
|
4770
|
+
})) {
|
|
4771
|
+
continue;
|
|
4772
|
+
}
|
|
4773
|
+
const shapesMovingTogether = [shape];
|
|
4774
|
+
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
4775
|
+
this.collectShapesViaArrowBindings({
|
|
4776
|
+
bindings: this.getBindingsToShape(shape.id, "arrow"),
|
|
4777
|
+
initialShapes: shapesToStackFirstPass,
|
|
4778
|
+
resultShapes: shapesMovingTogether,
|
|
4779
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
4780
|
+
visited
|
|
4781
|
+
});
|
|
4782
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether);
|
|
4783
|
+
if (!commonPageBounds) continue;
|
|
4784
|
+
shapeClustersToStack.push({
|
|
4785
|
+
shapes: shapesMovingTogether,
|
|
4786
|
+
pageBounds: commonPageBounds
|
|
4787
|
+
});
|
|
4788
|
+
allBounds.push(commonPageBounds);
|
|
4789
|
+
}
|
|
4790
|
+
const len = shapeClustersToStack.length;
|
|
4774
4791
|
if (gap === 0 && len < 3 || len < 2) return this;
|
|
4775
|
-
const pageBounds = Object.fromEntries(
|
|
4776
|
-
shapesToStack.map((shape) => [shape.id, this.getShapePageBounds(shape)])
|
|
4777
|
-
);
|
|
4778
4792
|
let val;
|
|
4779
4793
|
let min;
|
|
4780
4794
|
let max;
|
|
@@ -4790,57 +4804,55 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4790
4804
|
max = "maxY";
|
|
4791
4805
|
dim = "height";
|
|
4792
4806
|
}
|
|
4793
|
-
let shapeGap;
|
|
4807
|
+
let shapeGap = 0;
|
|
4794
4808
|
if (gap === 0) {
|
|
4795
|
-
const gaps =
|
|
4796
|
-
|
|
4809
|
+
const gaps = {};
|
|
4810
|
+
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
4797
4811
|
for (let i = 0; i < len - 1; i++) {
|
|
4798
|
-
const
|
|
4799
|
-
const
|
|
4800
|
-
const
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
const current = gaps.find((g) => g.gap === gap2);
|
|
4804
|
-
if (current) {
|
|
4805
|
-
current.count++;
|
|
4806
|
-
} else {
|
|
4807
|
-
gaps.push({ gap: gap2, count: 1 });
|
|
4812
|
+
const currCluster = shapeClustersToStack[i];
|
|
4813
|
+
const nextCluster = shapeClustersToStack[i + 1];
|
|
4814
|
+
const gap2 = nextCluster.pageBounds[min] - currCluster.pageBounds[max];
|
|
4815
|
+
if (!gaps[gap2]) {
|
|
4816
|
+
gaps[gap2] = 0;
|
|
4808
4817
|
}
|
|
4818
|
+
gaps[gap2]++;
|
|
4809
4819
|
}
|
|
4810
|
-
let maxCount =
|
|
4811
|
-
|
|
4812
|
-
if (
|
|
4813
|
-
maxCount =
|
|
4814
|
-
shapeGap =
|
|
4820
|
+
let maxCount = 1;
|
|
4821
|
+
for (const [gap2, count] of Object.entries(gaps)) {
|
|
4822
|
+
if (count > maxCount) {
|
|
4823
|
+
maxCount = count;
|
|
4824
|
+
shapeGap = parseFloat(gap2);
|
|
4815
4825
|
}
|
|
4816
|
-
}
|
|
4826
|
+
}
|
|
4817
4827
|
if (maxCount === 1) {
|
|
4818
|
-
|
|
4828
|
+
let totalCount = 0;
|
|
4829
|
+
for (const [gap2, count] of Object.entries(gaps)) {
|
|
4830
|
+
shapeGap += parseFloat(gap2) * count;
|
|
4831
|
+
totalCount += count;
|
|
4832
|
+
}
|
|
4833
|
+
shapeGap /= totalCount;
|
|
4819
4834
|
}
|
|
4820
4835
|
} else {
|
|
4821
4836
|
shapeGap = gap;
|
|
4822
4837
|
}
|
|
4823
4838
|
const changes = [];
|
|
4824
|
-
let v =
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
const delta =
|
|
4828
|
-
delta[val] = v + shapeGap - pageBounds[
|
|
4829
|
-
const
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
[val]: shape[val] + localDelta[val]
|
|
4836
|
-
} : {
|
|
4837
|
-
id: shape.id,
|
|
4838
|
-
type: shape.type,
|
|
4839
|
-
[val]: shape[val] + localDelta[val]
|
|
4839
|
+
let v = shapeClustersToStack[0].pageBounds[max];
|
|
4840
|
+
for (let i = 1; i < shapeClustersToStack.length; i++) {
|
|
4841
|
+
const { shapes: shapes2, pageBounds } = shapeClustersToStack[i];
|
|
4842
|
+
const delta = new Vec();
|
|
4843
|
+
delta[val] = v + shapeGap - pageBounds[val];
|
|
4844
|
+
for (const shape of shapes2) {
|
|
4845
|
+
const shapeDelta = delta.clone();
|
|
4846
|
+
const parent = this.getShapeParent(shape);
|
|
4847
|
+
if (parent) {
|
|
4848
|
+
const parentTransform = this.getShapePageTransform(parent);
|
|
4849
|
+
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
4840
4850
|
}
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4851
|
+
shapeDelta.add(shape);
|
|
4852
|
+
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
4853
|
+
}
|
|
4854
|
+
v += pageBounds[dim] + shapeGap;
|
|
4855
|
+
}
|
|
4844
4856
|
this.updateShapes(changes);
|
|
4845
4857
|
return this;
|
|
4846
4858
|
}
|
|
@@ -4858,91 +4870,101 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4858
4870
|
* @param gap - The padding to apply to the packed shapes. Defaults to 16.
|
|
4859
4871
|
*/
|
|
4860
4872
|
packShapes(shapes, gap) {
|
|
4861
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4862
4873
|
if (this.getIsReadonly()) return this;
|
|
4863
|
-
|
|
4864
|
-
const
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
const
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4874
|
+
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4875
|
+
const shapesToPackFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
4876
|
+
const shapeClustersToPack = [];
|
|
4877
|
+
const allBounds = [];
|
|
4878
|
+
const visited = /* @__PURE__ */ new Set();
|
|
4879
|
+
for (const shape of shapesToPackFirstPass) {
|
|
4880
|
+
if (visited.has(shape.id)) continue;
|
|
4881
|
+
visited.add(shape.id);
|
|
4882
|
+
const shapePageBounds = this.getShapePageBounds(shape);
|
|
4883
|
+
if (!shapePageBounds) continue;
|
|
4884
|
+
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
4885
|
+
type: "pack",
|
|
4886
|
+
shapes: shapesToPackFirstPass
|
|
4887
|
+
})) {
|
|
4888
|
+
continue;
|
|
4889
|
+
}
|
|
4890
|
+
const shapesMovingTogether = [shape];
|
|
4891
|
+
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
4892
|
+
this.collectShapesViaArrowBindings({
|
|
4893
|
+
bindings: this.getBindingsToShape(shape.id, "arrow"),
|
|
4894
|
+
initialShapes: shapesToPackFirstPass,
|
|
4895
|
+
resultShapes: shapesMovingTogether,
|
|
4896
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
4897
|
+
visited
|
|
4898
|
+
});
|
|
4899
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether);
|
|
4900
|
+
if (!commonPageBounds) continue;
|
|
4901
|
+
shapeClustersToPack.push({
|
|
4902
|
+
shapes: shapesMovingTogether,
|
|
4903
|
+
pageBounds: commonPageBounds,
|
|
4904
|
+
nextPageBounds: commonPageBounds.clone()
|
|
4905
|
+
});
|
|
4906
|
+
allBounds.push(commonPageBounds);
|
|
4907
|
+
}
|
|
4908
|
+
if (shapeClustersToPack.length < 2) return this;
|
|
4909
|
+
let area = 0;
|
|
4910
|
+
for (const { pageBounds } of shapeClustersToPack) {
|
|
4911
|
+
area += pageBounds.width * pageBounds.height;
|
|
4912
|
+
}
|
|
4913
|
+
const commonBounds = Box.Common(allBounds);
|
|
4879
4914
|
const maxWidth = commonBounds.width;
|
|
4880
|
-
|
|
4915
|
+
shapeClustersToPack.sort((a, b) => a.pageBounds.width - b.pageBounds.width).sort((a, b) => a.pageBounds.height - b.pageBounds.height);
|
|
4881
4916
|
const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
|
|
4882
4917
|
const spaces = [new Box(commonBounds.x, commonBounds.y, startWidth, Infinity)];
|
|
4883
4918
|
let width = 0;
|
|
4884
4919
|
let height = 0;
|
|
4885
4920
|
let space;
|
|
4886
4921
|
let last2;
|
|
4887
|
-
for (
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
width = Math.max(width, bounds.maxX);
|
|
4897
|
-
if (bounds.width === space.width && bounds.height === space.height) {
|
|
4922
|
+
for (const { nextPageBounds } of shapeClustersToPack) {
|
|
4923
|
+
for (let i = spaces.length - 1; i >= 0; i--) {
|
|
4924
|
+
space = spaces[i];
|
|
4925
|
+
if (nextPageBounds.width > space.width || nextPageBounds.height > space.height) continue;
|
|
4926
|
+
nextPageBounds.x = space.x;
|
|
4927
|
+
nextPageBounds.y = space.y;
|
|
4928
|
+
height = Math.max(height, nextPageBounds.maxY);
|
|
4929
|
+
width = Math.max(width, nextPageBounds.maxX);
|
|
4930
|
+
if (nextPageBounds.width === space.width && nextPageBounds.height === space.height) {
|
|
4898
4931
|
last2 = spaces.pop();
|
|
4899
|
-
if (
|
|
4900
|
-
} else if (
|
|
4901
|
-
space.x +=
|
|
4902
|
-
space.width -=
|
|
4903
|
-
} else if (
|
|
4904
|
-
space.y +=
|
|
4905
|
-
space.height -=
|
|
4932
|
+
if (i < spaces.length) spaces[i] = last2;
|
|
4933
|
+
} else if (nextPageBounds.height === space.height) {
|
|
4934
|
+
space.x += nextPageBounds.width + gap;
|
|
4935
|
+
space.width -= nextPageBounds.width + gap;
|
|
4936
|
+
} else if (nextPageBounds.width === space.width) {
|
|
4937
|
+
space.y += nextPageBounds.height + gap;
|
|
4938
|
+
space.height -= nextPageBounds.height + gap;
|
|
4906
4939
|
} else {
|
|
4907
4940
|
spaces.push(
|
|
4908
4941
|
new Box(
|
|
4909
|
-
space.x + (
|
|
4942
|
+
space.x + (nextPageBounds.width + gap),
|
|
4910
4943
|
space.y,
|
|
4911
|
-
space.width - (
|
|
4912
|
-
|
|
4944
|
+
space.width - (nextPageBounds.width + gap),
|
|
4945
|
+
nextPageBounds.height
|
|
4913
4946
|
)
|
|
4914
4947
|
);
|
|
4915
|
-
space.y +=
|
|
4916
|
-
space.height -=
|
|
4948
|
+
space.y += nextPageBounds.height + gap;
|
|
4949
|
+
space.height -= nextPageBounds.height + gap;
|
|
4917
4950
|
}
|
|
4918
4951
|
break;
|
|
4919
4952
|
}
|
|
4920
4953
|
}
|
|
4921
|
-
const commonAfter = Box.Common(
|
|
4954
|
+
const commonAfter = Box.Common(shapeClustersToPack.map((s) => s.nextPageBounds));
|
|
4922
4955
|
const centerDelta = Vec.Sub(commonBounds.center, commonAfter.center);
|
|
4923
|
-
let nextBounds;
|
|
4924
4956
|
const changes = [];
|
|
4925
|
-
for (
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
y: shape.y + delta.y
|
|
4937
|
-
};
|
|
4938
|
-
const translateStartChange = this.getShapeUtil(shape).onTranslateStart?.({
|
|
4939
|
-
...shape,
|
|
4940
|
-
...change
|
|
4941
|
-
});
|
|
4942
|
-
if (translateStartChange) {
|
|
4943
|
-
changes.push({ ...change, ...translateStartChange });
|
|
4944
|
-
} else {
|
|
4945
|
-
changes.push(change);
|
|
4957
|
+
for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
|
|
4958
|
+
const delta = Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
|
|
4959
|
+
for (const shape of shapes2) {
|
|
4960
|
+
const shapeDelta = delta.clone();
|
|
4961
|
+
const parent = this.getShapeParent(shape);
|
|
4962
|
+
if (parent) {
|
|
4963
|
+
const parentTransform = this.getShapeParentTransform(shape);
|
|
4964
|
+
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
4965
|
+
}
|
|
4966
|
+
shapeDelta.add(shape);
|
|
4967
|
+
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
4946
4968
|
}
|
|
4947
4969
|
}
|
|
4948
4970
|
if (changes.length) {
|
|
@@ -4965,19 +4987,45 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4965
4987
|
* @public
|
|
4966
4988
|
*/
|
|
4967
4989
|
alignShapes(shapes, operation) {
|
|
4968
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4969
4990
|
if (this.getIsReadonly()) return this;
|
|
4970
|
-
|
|
4971
|
-
const
|
|
4972
|
-
const
|
|
4973
|
-
|
|
4974
|
-
);
|
|
4975
|
-
const
|
|
4991
|
+
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
4992
|
+
const shapesToAlignFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
4993
|
+
const shapeClustersToAlign = [];
|
|
4994
|
+
const allBounds = [];
|
|
4995
|
+
const visited = /* @__PURE__ */ new Set();
|
|
4996
|
+
for (const shape of shapesToAlignFirstPass) {
|
|
4997
|
+
if (visited.has(shape.id)) continue;
|
|
4998
|
+
visited.add(shape.id);
|
|
4999
|
+
const shapePageBounds = this.getShapePageBounds(shape);
|
|
5000
|
+
if (!shapePageBounds) continue;
|
|
5001
|
+
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
5002
|
+
type: "align",
|
|
5003
|
+
shapes: shapesToAlignFirstPass
|
|
5004
|
+
})) {
|
|
5005
|
+
continue;
|
|
5006
|
+
}
|
|
5007
|
+
const shapesMovingTogether = [shape];
|
|
5008
|
+
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5009
|
+
this.collectShapesViaArrowBindings({
|
|
5010
|
+
bindings: this.getBindingsToShape(shape.id, "arrow"),
|
|
5011
|
+
initialShapes: shapesToAlignFirstPass,
|
|
5012
|
+
resultShapes: shapesMovingTogether,
|
|
5013
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
5014
|
+
visited
|
|
5015
|
+
});
|
|
5016
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether);
|
|
5017
|
+
if (!commonPageBounds) continue;
|
|
5018
|
+
shapeClustersToAlign.push({
|
|
5019
|
+
shapes: shapesMovingTogether,
|
|
5020
|
+
pageBounds: commonPageBounds
|
|
5021
|
+
});
|
|
5022
|
+
allBounds.push(commonPageBounds);
|
|
5023
|
+
}
|
|
5024
|
+
if (shapeClustersToAlign.length < 2) return this;
|
|
5025
|
+
const commonBounds = Box.Common(allBounds);
|
|
4976
5026
|
const changes = [];
|
|
4977
|
-
|
|
4978
|
-
const
|
|
4979
|
-
if (!pageBounds) return;
|
|
4980
|
-
const delta = { x: 0, y: 0 };
|
|
5027
|
+
shapeClustersToAlign.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5028
|
+
const delta = new Vec();
|
|
4981
5029
|
switch (operation) {
|
|
4982
5030
|
case "top": {
|
|
4983
5031
|
delta.y = commonBounds.minY - pageBounds.minY;
|
|
@@ -5004,9 +5052,16 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5004
5052
|
break;
|
|
5005
5053
|
}
|
|
5006
5054
|
}
|
|
5007
|
-
const
|
|
5008
|
-
|
|
5009
|
-
|
|
5055
|
+
for (const shape of shapes2) {
|
|
5056
|
+
const shapeDelta = delta.clone();
|
|
5057
|
+
const parent = this.getShapeParent(shape);
|
|
5058
|
+
if (parent) {
|
|
5059
|
+
const parentTransform = this.getShapePageTransform(parent);
|
|
5060
|
+
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5061
|
+
}
|
|
5062
|
+
shapeDelta.add(shape);
|
|
5063
|
+
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5064
|
+
}
|
|
5010
5065
|
});
|
|
5011
5066
|
this.updateShapes(changes);
|
|
5012
5067
|
return this;
|
|
@@ -5026,47 +5081,95 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5026
5081
|
* @public
|
|
5027
5082
|
*/
|
|
5028
5083
|
distributeShapes(shapes, operation) {
|
|
5029
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5030
5084
|
if (this.getIsReadonly()) return this;
|
|
5031
|
-
|
|
5032
|
-
const
|
|
5033
|
-
const
|
|
5034
|
-
const
|
|
5035
|
-
|
|
5036
|
-
)
|
|
5085
|
+
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5086
|
+
const shapesToDistributeFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
5087
|
+
const shapeClustersToDistribute = [];
|
|
5088
|
+
const allBounds = [];
|
|
5089
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5090
|
+
for (const shape of shapesToDistributeFirstPass) {
|
|
5091
|
+
if (visited.has(shape.id)) continue;
|
|
5092
|
+
visited.add(shape.id);
|
|
5093
|
+
const shapePageBounds = this.getShapePageBounds(shape);
|
|
5094
|
+
if (!shapePageBounds) continue;
|
|
5095
|
+
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
5096
|
+
type: "distribute",
|
|
5097
|
+
shapes: shapesToDistributeFirstPass
|
|
5098
|
+
})) {
|
|
5099
|
+
continue;
|
|
5100
|
+
}
|
|
5101
|
+
const shapesMovingTogether = [shape];
|
|
5102
|
+
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5103
|
+
this.collectShapesViaArrowBindings({
|
|
5104
|
+
bindings: this.getBindingsToShape(shape.id, "arrow"),
|
|
5105
|
+
initialShapes: shapesToDistributeFirstPass,
|
|
5106
|
+
resultShapes: shapesMovingTogether,
|
|
5107
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
5108
|
+
visited
|
|
5109
|
+
});
|
|
5110
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether);
|
|
5111
|
+
if (!commonPageBounds) continue;
|
|
5112
|
+
shapeClustersToDistribute.push({
|
|
5113
|
+
shapes: shapesMovingTogether,
|
|
5114
|
+
pageBounds: commonPageBounds
|
|
5115
|
+
});
|
|
5116
|
+
allBounds.push(commonPageBounds);
|
|
5117
|
+
}
|
|
5118
|
+
if (shapeClustersToDistribute.length < 3) return this;
|
|
5037
5119
|
let val;
|
|
5038
5120
|
let min;
|
|
5039
5121
|
let max;
|
|
5040
|
-
let mid;
|
|
5041
5122
|
let dim;
|
|
5042
5123
|
if (operation === "horizontal") {
|
|
5043
5124
|
val = "x";
|
|
5044
5125
|
min = "minX";
|
|
5045
5126
|
max = "maxX";
|
|
5046
|
-
mid = "midX";
|
|
5047
5127
|
dim = "width";
|
|
5048
5128
|
} else {
|
|
5049
5129
|
val = "y";
|
|
5050
5130
|
min = "minY";
|
|
5051
5131
|
max = "maxY";
|
|
5052
|
-
mid = "midY";
|
|
5053
5132
|
dim = "height";
|
|
5054
5133
|
}
|
|
5055
5134
|
const changes = [];
|
|
5056
|
-
const first =
|
|
5057
|
-
|
|
5058
|
-
)
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5135
|
+
const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
|
|
5136
|
+
const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
|
|
5137
|
+
if (first === last2) {
|
|
5138
|
+
const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
|
|
5139
|
+
return this.distributeShapes(
|
|
5140
|
+
ids.filter((id) => !excludedShapeIds.has(id)),
|
|
5141
|
+
operation
|
|
5142
|
+
);
|
|
5143
|
+
}
|
|
5144
|
+
const shapeClustersToMove = shapeClustersToDistribute.filter((shape) => shape !== first && shape !== last2).sort((a, b) => {
|
|
5145
|
+
if (a.pageBounds[min] === b.pageBounds[min]) {
|
|
5146
|
+
return a.shapes[0].id < b.shapes[0].id ? -1 : 1;
|
|
5147
|
+
}
|
|
5148
|
+
return a.pageBounds[min] - b.pageBounds[min];
|
|
5069
5149
|
});
|
|
5150
|
+
const maxFirst = first.pageBounds[max];
|
|
5151
|
+
const range = last2.pageBounds[min] - maxFirst;
|
|
5152
|
+
const summedShapeDimensions = shapeClustersToMove.reduce((acc, s) => acc + s.pageBounds[dim], 0);
|
|
5153
|
+
const gap = (range - summedShapeDimensions) / (shapeClustersToMove.length + 1);
|
|
5154
|
+
for (let v = maxFirst + gap, i = 0; i < shapeClustersToMove.length; i++) {
|
|
5155
|
+
const { shapes: shapes2, pageBounds } = shapeClustersToMove[i];
|
|
5156
|
+
const delta = new Vec();
|
|
5157
|
+
delta[val] = v - pageBounds[val];
|
|
5158
|
+
if (v + pageBounds[dim] > last2.pageBounds[max] - 1) {
|
|
5159
|
+
delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
|
|
5160
|
+
}
|
|
5161
|
+
for (const shape of shapes2) {
|
|
5162
|
+
const shapeDelta = delta.clone();
|
|
5163
|
+
const parent = this.getShapeParent(shape);
|
|
5164
|
+
if (parent) {
|
|
5165
|
+
const parentTransform = this.getShapePageTransform(parent);
|
|
5166
|
+
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5167
|
+
}
|
|
5168
|
+
shapeDelta.add(shape);
|
|
5169
|
+
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5170
|
+
}
|
|
5171
|
+
v += pageBounds[dim] + gap;
|
|
5172
|
+
}
|
|
5070
5173
|
this.updateShapes(changes);
|
|
5071
5174
|
return this;
|
|
5072
5175
|
}
|
|
@@ -5087,59 +5190,78 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5087
5190
|
stretchShapes(shapes, operation) {
|
|
5088
5191
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5089
5192
|
if (this.getIsReadonly()) return this;
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
const
|
|
5094
|
-
const
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
const scale = new Vec(1, commonBounds.height / pageBounds.height);
|
|
5109
|
-
this.resizeShape(shape.id, scale, {
|
|
5110
|
-
initialBounds: bounds,
|
|
5111
|
-
scaleOrigin: new Vec(pageBounds.center.x, commonBounds.minY),
|
|
5112
|
-
isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
|
|
5113
|
-
scaleAxisRotation: 0
|
|
5114
|
-
});
|
|
5115
|
-
}
|
|
5116
|
-
});
|
|
5117
|
-
break;
|
|
5118
|
-
}
|
|
5119
|
-
case "horizontal": {
|
|
5120
|
-
this.run(() => {
|
|
5121
|
-
for (const shape of shapesToStretch) {
|
|
5122
|
-
const bounds = shapeBounds[shape.id];
|
|
5123
|
-
const pageBounds = shapePageBounds[shape.id];
|
|
5124
|
-
const pageRotation = this.getShapePageTransform(shape).rotation();
|
|
5125
|
-
if (pageRotation % PI2) continue;
|
|
5126
|
-
const localOffset = new Vec(commonBounds.minX - pageBounds.minX, 0);
|
|
5127
|
-
const parentTransform = this.getShapeParentTransform(shape);
|
|
5128
|
-
if (parentTransform) localOffset.rot(-parentTransform.rotation());
|
|
5129
|
-
const { x, y } = Vec.Add(localOffset, shape);
|
|
5130
|
-
this.updateShapes([{ id: shape.id, type: shape.type, x, y }]);
|
|
5131
|
-
const scale = new Vec(commonBounds.width / pageBounds.width, 1);
|
|
5132
|
-
this.resizeShape(shape.id, scale, {
|
|
5133
|
-
initialBounds: bounds,
|
|
5134
|
-
scaleOrigin: new Vec(commonBounds.minX, pageBounds.center.y),
|
|
5135
|
-
isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
|
|
5136
|
-
scaleAxisRotation: 0
|
|
5137
|
-
});
|
|
5138
|
-
}
|
|
5139
|
-
});
|
|
5140
|
-
break;
|
|
5193
|
+
const shapesToStretchFirstPass = compact(ids.map((id) => this.getShape(id))).filter(
|
|
5194
|
+
(s) => this.getShapePageTransform(s)?.rotation() % (PI / 2) === 0
|
|
5195
|
+
);
|
|
5196
|
+
const shapeClustersToStretch = [];
|
|
5197
|
+
const allBounds = [];
|
|
5198
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5199
|
+
for (const shape of shapesToStretchFirstPass) {
|
|
5200
|
+
if (visited.has(shape.id)) continue;
|
|
5201
|
+
visited.add(shape.id);
|
|
5202
|
+
const shapePageBounds = this.getShapePageBounds(shape);
|
|
5203
|
+
if (!shapePageBounds) continue;
|
|
5204
|
+
const shapesMovingTogether = [shape];
|
|
5205
|
+
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5206
|
+
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
5207
|
+
type: "stretch",
|
|
5208
|
+
shapes: shapesToStretchFirstPass
|
|
5209
|
+
})) {
|
|
5210
|
+
continue;
|
|
5141
5211
|
}
|
|
5212
|
+
this.collectShapesViaArrowBindings({
|
|
5213
|
+
bindings: this.getBindingsToShape(shape.id, "arrow"),
|
|
5214
|
+
initialShapes: shapesToStretchFirstPass,
|
|
5215
|
+
resultShapes: shapesMovingTogether,
|
|
5216
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
5217
|
+
visited
|
|
5218
|
+
});
|
|
5219
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether);
|
|
5220
|
+
if (!commonPageBounds) continue;
|
|
5221
|
+
shapeClustersToStretch.push({
|
|
5222
|
+
shapes: shapesMovingTogether,
|
|
5223
|
+
pageBounds: commonPageBounds
|
|
5224
|
+
});
|
|
5225
|
+
allBounds.push(commonPageBounds);
|
|
5142
5226
|
}
|
|
5227
|
+
if (shapeClustersToStretch.length < 2) return this;
|
|
5228
|
+
const commonBounds = Box.Common(allBounds);
|
|
5229
|
+
let val;
|
|
5230
|
+
let min;
|
|
5231
|
+
let dim;
|
|
5232
|
+
if (operation === "horizontal") {
|
|
5233
|
+
val = "x";
|
|
5234
|
+
min = "minX";
|
|
5235
|
+
dim = "width";
|
|
5236
|
+
} else {
|
|
5237
|
+
val = "y";
|
|
5238
|
+
min = "minY";
|
|
5239
|
+
dim = "height";
|
|
5240
|
+
}
|
|
5241
|
+
this.run(() => {
|
|
5242
|
+
shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5243
|
+
const localOffset = new Vec();
|
|
5244
|
+
localOffset[val] = commonBounds[min] - pageBounds[min];
|
|
5245
|
+
const scaleOrigin = pageBounds.center.clone();
|
|
5246
|
+
scaleOrigin[val] = commonBounds[min];
|
|
5247
|
+
const scale = new Vec(1, 1);
|
|
5248
|
+
scale[val] = commonBounds[dim] / pageBounds[dim];
|
|
5249
|
+
for (const shape of shapes2) {
|
|
5250
|
+
const shapeLocalOffset = localOffset.clone();
|
|
5251
|
+
const parentTransform = this.getShapeParentTransform(shape);
|
|
5252
|
+
if (parentTransform) localOffset.rot(-parentTransform.rotation());
|
|
5253
|
+
shapeLocalOffset.add(shape);
|
|
5254
|
+
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5255
|
+
this.updateShape(changes);
|
|
5256
|
+
this.resizeShape(shape.id, scale, {
|
|
5257
|
+
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
5258
|
+
scaleOrigin,
|
|
5259
|
+
isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
|
|
5260
|
+
scaleAxisRotation: 0
|
|
5261
|
+
});
|
|
5262
|
+
}
|
|
5263
|
+
});
|
|
5264
|
+
});
|
|
5143
5265
|
return this;
|
|
5144
5266
|
}
|
|
5145
5267
|
/**
|
|
@@ -5343,7 +5465,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5343
5465
|
* @example
|
|
5344
5466
|
* ```ts
|
|
5345
5467
|
* editor.createShape(myShape)
|
|
5346
|
-
* editor.createShape({ id: 'box1', type: 'text', props: {
|
|
5468
|
+
* editor.createShape({ id: 'box1', type: 'text', props: { text: "ok" } })
|
|
5347
5469
|
* ```
|
|
5348
5470
|
*
|
|
5349
5471
|
* @param shape - The shape (or shape partial) to create.
|
|
@@ -5360,7 +5482,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5360
5482
|
* @example
|
|
5361
5483
|
* ```ts
|
|
5362
5484
|
* editor.createShapes([myShape])
|
|
5363
|
-
* editor.createShapes([{ id: 'box1', type: 'text', props: {
|
|
5485
|
+
* editor.createShapes([{ id: 'box1', type: 'text', props: { text: "ok" } }])
|
|
5364
5486
|
* ```
|
|
5365
5487
|
*
|
|
5366
5488
|
* @param shapes - The shapes (or shape partials) to create.
|
|
@@ -7365,7 +7487,6 @@ __decorateElement(_init, 1, "getFocusedGroupId", _getFocusedGroupId_dec, Editor)
|
|
|
7365
7487
|
__decorateElement(_init, 1, "getFocusedGroup", _getFocusedGroup_dec, Editor);
|
|
7366
7488
|
__decorateElement(_init, 1, "getEditingShapeId", _getEditingShapeId_dec, Editor);
|
|
7367
7489
|
__decorateElement(_init, 1, "getEditingShape", _getEditingShape_dec, Editor);
|
|
7368
|
-
__decorateElement(_init, 1, "getRichTextEditor", _getRichTextEditor_dec, Editor);
|
|
7369
7490
|
__decorateElement(_init, 1, "getHoveredShapeId", _getHoveredShapeId_dec, Editor);
|
|
7370
7491
|
__decorateElement(_init, 1, "getHoveredShape", _getHoveredShape_dec, Editor);
|
|
7371
7492
|
__decorateElement(_init, 1, "getHintingShapeIds", _getHintingShapeIds_dec, Editor);
|
|
@@ -7389,7 +7510,6 @@ __decorateElement(_init, 1, "getPages", _getPages_dec, Editor);
|
|
|
7389
7510
|
__decorateElement(_init, 1, "getCurrentPageId", _getCurrentPageId_dec, Editor);
|
|
7390
7511
|
__decorateElement(_init, 1, "getCurrentPageShapeIdsSorted", _getCurrentPageShapeIdsSorted_dec, Editor);
|
|
7391
7512
|
__decorateElement(_init, 1, "_getAllAssetsQuery", __getAllAssetsQuery_dec, Editor);
|
|
7392
|
-
__decorateElement(_init, 1, "_getShapeGeometryCache", __getShapeGeometryCache_dec, Editor);
|
|
7393
7513
|
__decorateElement(_init, 1, "_getShapeHandlesCache", __getShapeHandlesCache_dec, Editor);
|
|
7394
7514
|
__decorateElement(_init, 1, "_getShapePageTransformCache", __getShapePageTransformCache_dec, Editor);
|
|
7395
7515
|
__decorateElement(_init, 1, "_getShapePageBoundsCache", __getShapePageBoundsCache_dec, Editor);
|
|
@@ -7479,7 +7599,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
7479
7599
|
result = Result.err(error);
|
|
7480
7600
|
}
|
|
7481
7601
|
});
|
|
7482
|
-
editor.store.applyDiff(reverseRecordsDiff(changes));
|
|
7602
|
+
editor.store.applyDiff(reverseRecordsDiff(changes), { runCallbacks: false });
|
|
7483
7603
|
},
|
|
7484
7604
|
{ history: "ignore" }
|
|
7485
7605
|
);
|