@tldraw/editor 5.5.0-next.f9308d324e1c → 5.6.0-canary.5bfc37740468
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/dist-cjs/index.d.ts +49 -23
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +16 -12
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +42 -3
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +2 -5
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +3 -3
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +183 -185
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EditorManager.js +11 -2
- package/dist-cjs/lib/editor/managers/EditorManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +49 -63
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -1
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +24 -24
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +7 -1
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +4 -3
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +4 -4
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +14 -6
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +3 -3
- package/dist-cjs/lib/editor/shapes/shared/resizeBox.js +21 -16
- package/dist-cjs/lib/editor/shapes/shared/resizeBox.js.map +2 -2
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/ExportDelay.js +10 -2
- package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
- package/dist-cjs/lib/exports/FontEmbedder.js +25 -11
- package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/StyleEmbedder.js +9 -4
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/fetchCache.js +3 -0
- package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
- package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/exports/parseCss.js +1 -1
- package/dist-cjs/lib/exports/parseCss.js.map +1 -1
- package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useCursor.js +12 -8
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/hooks/useIdentity.js +6 -2
- package/dist-cjs/lib/hooks/useIdentity.js.map +3 -3
- package/dist-cjs/lib/license/LicenseManager.js +9 -1
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +12 -4
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/utils/debug-flags.js +0 -6
- package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js +2 -1
- package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +32 -25
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +88 -40
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.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 +49 -23
- package/dist-esm/index.mjs +4 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +17 -13
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +42 -3
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -5
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +3 -3
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +185 -186
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EditorManager.mjs +11 -2
- package/dist-esm/lib/editor/managers/EditorManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +49 -63
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +24 -24
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +7 -1
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +4 -3
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +4 -4
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +14 -6
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +3 -3
- package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs +21 -16
- package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs.map +2 -2
- package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
- package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
- package/dist-esm/lib/exports/FontEmbedder.mjs +25 -11
- package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +9 -4
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/fetchCache.mjs +3 -0
- package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
- package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/exports/parseCss.mjs +1 -1
- package/dist-esm/lib/exports/parseCss.mjs.map +1 -1
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCursor.mjs +12 -8
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useIdentity.mjs +7 -3
- package/dist-esm/lib/hooks/useIdentity.mjs.map +3 -3
- package/dist-esm/lib/license/LicenseManager.mjs +9 -1
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/utils/debug-flags.mjs +0 -6
- package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs +2 -1
- package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +32 -25
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +89 -41
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +9 -1
- package/package.json +18 -23
- package/src/index.ts +5 -1
- package/src/lib/TldrawEditor.tsx +35 -21
- package/src/lib/components/MenuClickCapture.tsx +55 -4
- package/src/lib/components/default-components/DefaultCanvas.tsx +7 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +13 -5
- package/src/lib/components/default-components/DefaultSpinner.tsx +4 -1
- package/src/lib/editor/Editor.test.ts +65 -0
- package/src/lib/editor/Editor.ts +299 -303
- package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +1 -0
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +3 -2
- package/src/lib/editor/managers/EditorManager.test.ts +32 -1
- package/src/lib/editor/managers/EditorManager.ts +15 -3
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +80 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +54 -81
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +32 -36
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +13 -2
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -0
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +6 -4
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +74 -0
- package/src/lib/editor/managers/TextManager/TextManager.ts +6 -5
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +23 -8
- package/src/lib/editor/shapes/shared/resizeBox.ts +21 -16
- package/src/lib/editor/types/external-content.ts +5 -0
- package/src/lib/exports/ExportDelay.tsx +16 -4
- package/src/lib/exports/FontEmbedder.test.ts +99 -0
- package/src/lib/exports/FontEmbedder.ts +32 -11
- package/src/lib/exports/StyleEmbedder.ts +13 -4
- package/src/lib/exports/fetchCache.test.ts +22 -0
- package/src/lib/exports/fetchCache.ts +4 -0
- package/src/lib/exports/getSvgAsImage.ts +13 -5
- package/src/lib/exports/getSvgJsx.test.ts +43 -1
- package/src/lib/exports/getSvgJsx.tsx +28 -16
- package/src/lib/exports/parseCss.test.ts +4 -0
- package/src/lib/exports/parseCss.ts +2 -2
- package/src/lib/hooks/EditorComponentsContext.tsx +2 -1
- package/src/lib/hooks/useCanvasEvents.ts +42 -0
- package/src/lib/hooks/useCursor.ts +14 -7
- package/src/lib/hooks/useIdentity.tsx +12 -1
- package/src/lib/license/LicenseManager.ts +13 -1
- package/src/lib/license/LicenseProvider.test.tsx +76 -0
- package/src/lib/license/LicenseProvider.tsx +19 -5
- package/src/lib/test/preserveFocus.test.tsx +81 -0
- package/src/lib/test/useCursor.test.tsx +36 -0
- package/src/lib/utils/debug-flags.ts +0 -6
- package/src/lib/utils/deepLinks.test.ts +15 -0
- package/src/lib/utils/deepLinks.ts +8 -3
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +121 -1
- package/src/lib/utils/sync/LocalIndexedDb.ts +41 -28
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +330 -1
- package/src/lib/utils/sync/TLLocalSyncClient.ts +129 -55
- package/src/version.ts +3 -3
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js +0 -133
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +0 -7
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +0 -132
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +0 -7
- package/src/lib/primitives/geometry/geometry.bench.ts +0 -179
|
@@ -99,7 +99,8 @@ import {
|
|
|
99
99
|
approximately,
|
|
100
100
|
areAnglesCompatible,
|
|
101
101
|
clamp,
|
|
102
|
-
pointInPolygon
|
|
102
|
+
pointInPolygon,
|
|
103
|
+
shortAngleDist
|
|
103
104
|
} from "../primitives/utils.mjs";
|
|
104
105
|
import { Vec } from "../primitives/Vec.mjs";
|
|
105
106
|
import { areShapesContentEqual } from "../utils/areShapesContentEqual.mjs";
|
|
@@ -136,6 +137,10 @@ import { UserPreferencesManager } from "./managers/UserPreferencesManager/UserPr
|
|
|
136
137
|
import { OverlayManager } from "./overlays/OverlayManager.mjs";
|
|
137
138
|
import { RootState } from "./tools/RootState.mjs";
|
|
138
139
|
const RENDERING_SHAPES_SORT_CACHE_THRESHOLD = 100;
|
|
140
|
+
const AXIS = {
|
|
141
|
+
horizontal: { val: "x", min: "minX", max: "maxX", dim: "width" },
|
|
142
|
+
vertical: { val: "y", min: "minY", max: "maxY", dim: "height" }
|
|
143
|
+
};
|
|
139
144
|
class Editor extends EventEmitter {
|
|
140
145
|
id = uniqueId();
|
|
141
146
|
constructor({
|
|
@@ -462,7 +467,7 @@ class Editor extends EventEmitter {
|
|
|
462
467
|
}
|
|
463
468
|
}
|
|
464
469
|
if (deleteBindingIds.length) {
|
|
465
|
-
this.
|
|
470
|
+
this.store.remove(deleteBindingIds);
|
|
466
471
|
}
|
|
467
472
|
}
|
|
468
473
|
},
|
|
@@ -1422,6 +1427,7 @@ class Editor extends EventEmitter {
|
|
|
1422
1427
|
* @public
|
|
1423
1428
|
**/
|
|
1424
1429
|
updateDocumentSettings(settings) {
|
|
1430
|
+
if (this.getIsReadonly()) return this;
|
|
1425
1431
|
this.run(
|
|
1426
1432
|
() => {
|
|
1427
1433
|
this.store.put([{ ...this.getDocumentSettings(), ...settings }]);
|
|
@@ -1444,7 +1450,7 @@ class Editor extends EventEmitter {
|
|
|
1444
1450
|
updateInstanceState(partial, historyOptions) {
|
|
1445
1451
|
this._updateInstanceState(partial, { history: "ignore", ...historyOptions });
|
|
1446
1452
|
if (partial.isChangingStyle !== void 0) {
|
|
1447
|
-
clearTimeout(this._isChangingStyleTimeout);
|
|
1453
|
+
this.timers.clearTimeout(this._isChangingStyleTimeout);
|
|
1448
1454
|
if (partial.isChangingStyle === true) {
|
|
1449
1455
|
this._isChangingStyleTimeout = this.timers.setTimeout(() => {
|
|
1450
1456
|
this._updateInstanceState({ isChangingStyle: false }, { history: "ignore" });
|
|
@@ -1581,7 +1587,7 @@ class Editor extends EventEmitter {
|
|
|
1581
1587
|
* @public
|
|
1582
1588
|
*/
|
|
1583
1589
|
select(...shapes) {
|
|
1584
|
-
const ids =
|
|
1590
|
+
const ids = toShapeIds(shapes);
|
|
1585
1591
|
this.setSelectedShapes(ids);
|
|
1586
1592
|
return this;
|
|
1587
1593
|
}
|
|
@@ -1596,7 +1602,7 @@ class Editor extends EventEmitter {
|
|
|
1596
1602
|
* @public
|
|
1597
1603
|
*/
|
|
1598
1604
|
deselect(...shapes) {
|
|
1599
|
-
const ids =
|
|
1605
|
+
const ids = toShapeIds(shapes);
|
|
1600
1606
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1601
1607
|
if (selectedShapeIds.length > 0 && ids.length > 0) {
|
|
1602
1608
|
this.setSelectedShapes(selectedShapeIds.filter((id) => !ids.includes(id)));
|
|
@@ -1634,7 +1640,7 @@ class Editor extends EventEmitter {
|
|
|
1634
1640
|
}
|
|
1635
1641
|
const ids = this.getSortedChildIdsForParent(parentToSelectWithinId);
|
|
1636
1642
|
if (ids.length <= 0) return this;
|
|
1637
|
-
this.setSelectedShapes(this.
|
|
1643
|
+
this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked));
|
|
1638
1644
|
return this;
|
|
1639
1645
|
}
|
|
1640
1646
|
/**
|
|
@@ -1651,12 +1657,15 @@ class Editor extends EventEmitter {
|
|
|
1651
1657
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1652
1658
|
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1653
1659
|
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !isPageId(firstParentId);
|
|
1654
|
-
const filteredShapes =
|
|
1655
|
-
|
|
1660
|
+
const filteredShapes = this.getCurrentPageShapes().filter(
|
|
1661
|
+
(shape2) => !this.isShapeOrAncestorLocked(shape2) && (isSelectedWithinContainer ? shape2.parentId === firstParentId : isPageId(shape2.parentId))
|
|
1662
|
+
);
|
|
1663
|
+
const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
|
|
1656
1664
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
1657
1665
|
let adjacentShapeId;
|
|
1658
1666
|
if (direction === "next" || direction === "prev") {
|
|
1659
1667
|
const shapeIds = readingOrderShapes.map((shape2) => shape2.id);
|
|
1668
|
+
if (shapeIds.length === 0) return;
|
|
1660
1669
|
const currentIndex = currentShapeId ? shapeIds.indexOf(currentShapeId) : -1;
|
|
1661
1670
|
const startIndex = currentIndex === -1 && direction === "prev" ? 0 : currentIndex;
|
|
1662
1671
|
const adjacentIndex = (startIndex + (direction === "next" ? 1 : -1) + shapeIds.length) % shapeIds.length;
|
|
@@ -1758,13 +1767,14 @@ class Editor extends EventEmitter {
|
|
|
1758
1767
|
});
|
|
1759
1768
|
if (shapesInDirection.length === 0) return currentShapeId;
|
|
1760
1769
|
const lowestScoringShape = minBy(shapesInDirection, ({ center }) => {
|
|
1761
|
-
const distance = Vec.
|
|
1770
|
+
const distance = Vec.Dist(currentCenter, center);
|
|
1762
1771
|
const dirProp = ["left", "right"].includes(direction) ? "x" : "y";
|
|
1763
1772
|
const directionalDistance = Math.abs(center[dirProp] - currentCenter[dirProp]);
|
|
1764
1773
|
const offProp = ["left", "right"].includes(direction) ? "y" : "x";
|
|
1765
1774
|
const offAxisDeviation = Math.abs(center[offProp] - currentCenter[offProp]);
|
|
1766
|
-
const angle =
|
|
1767
|
-
const
|
|
1775
|
+
const angle = (Vec.Angle(currentCenter, center) * (180 / Math.PI) + 360) % 360;
|
|
1776
|
+
const rawAngleDeviation = Math.abs(angle - directionToAngle[direction]);
|
|
1777
|
+
const angleDeviation = Math.min(rawAngleDeviation, 360 - rawAngleDeviation);
|
|
1768
1778
|
return distance * 1 + // Base distance
|
|
1769
1779
|
offAxisDeviation * 2 + // Heavy penalty for off-axis deviation
|
|
1770
1780
|
(distance - directionalDistance) * 1.5 + // Penalty for diagonal distance
|
|
@@ -2102,7 +2112,7 @@ class Editor extends EventEmitter {
|
|
|
2102
2112
|
* @public
|
|
2103
2113
|
*/
|
|
2104
2114
|
setHintingShapes(shapes) {
|
|
2105
|
-
const ids =
|
|
2115
|
+
const ids = toShapeIds(shapes);
|
|
2106
2116
|
this.run(
|
|
2107
2117
|
() => {
|
|
2108
2118
|
this._updateCurrentPageState({ hintingShapeIds: dedupe(ids) });
|
|
@@ -2132,7 +2142,7 @@ class Editor extends EventEmitter {
|
|
|
2132
2142
|
* @public
|
|
2133
2143
|
*/
|
|
2134
2144
|
setErasingShapes(shapes) {
|
|
2135
|
-
const ids =
|
|
2145
|
+
const ids = toShapeIds(shapes).slice();
|
|
2136
2146
|
ids.sort();
|
|
2137
2147
|
const erasingShapeIds = this.getErasingShapeIds();
|
|
2138
2148
|
this.run(
|
|
@@ -2539,14 +2549,16 @@ class Editor extends EventEmitter {
|
|
|
2539
2549
|
setCamera(point, opts) {
|
|
2540
2550
|
const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
2541
2551
|
if (isLocked && !opts?.force) return this;
|
|
2552
|
+
const _point = new Vec(point.x, point.y, point.z ?? this.getZoomLevel());
|
|
2553
|
+
if (!Number.isFinite(_point.x) || !Number.isFinite(_point.y) || !Number.isFinite(_point.z)) {
|
|
2554
|
+
throw Error(
|
|
2555
|
+
`Editor.setCamera: expected finite values, got (${_point.x}, ${_point.y}, ${_point.z}).`
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2542
2558
|
this.stopCameraAnimation();
|
|
2543
2559
|
if (this.getInstanceState().followingUserId) {
|
|
2544
2560
|
this.stopFollowingUser();
|
|
2545
2561
|
}
|
|
2546
|
-
const _point = Vec.Cast(point);
|
|
2547
|
-
if (!Number.isFinite(_point.x)) _point.x = 0;
|
|
2548
|
-
if (!Number.isFinite(_point.y)) _point.y = 0;
|
|
2549
|
-
if (_point.z === void 0 || !Number.isFinite(_point.z)) point.z = this.getZoomLevel();
|
|
2550
2562
|
const camera = this.getConstrainedCamera(_point, opts);
|
|
2551
2563
|
if (opts?.animation) {
|
|
2552
2564
|
const { width, height } = this.getViewportScreenBounds();
|
|
@@ -2831,11 +2843,14 @@ class Editor extends EventEmitter {
|
|
|
2831
2843
|
_animateViewport(ms) {
|
|
2832
2844
|
if (!this._viewportAnimation) return;
|
|
2833
2845
|
this._viewportAnimation.elapsed += ms;
|
|
2834
|
-
const { elapsed, easing, duration, start, end } = this._viewportAnimation;
|
|
2846
|
+
const { elapsed, easing, duration, start, end, opts } = this._viewportAnimation;
|
|
2835
2847
|
if (elapsed > duration) {
|
|
2836
2848
|
this.off("tick", this._animateViewport);
|
|
2837
2849
|
this._viewportAnimation = null;
|
|
2838
|
-
this._setCamera(
|
|
2850
|
+
this._setCamera(
|
|
2851
|
+
new Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width),
|
|
2852
|
+
opts
|
|
2853
|
+
);
|
|
2839
2854
|
return;
|
|
2840
2855
|
}
|
|
2841
2856
|
const remaining = duration - elapsed;
|
|
@@ -2873,7 +2888,8 @@ class Editor extends EventEmitter {
|
|
|
2873
2888
|
duration: duration / animationSpeed,
|
|
2874
2889
|
easing,
|
|
2875
2890
|
start: viewportPageBounds.clone(),
|
|
2876
|
-
end: targetViewportPage.clone()
|
|
2891
|
+
end: targetViewportPage.clone(),
|
|
2892
|
+
opts: rest
|
|
2877
2893
|
};
|
|
2878
2894
|
this.once("stop-camera-animation", () => {
|
|
2879
2895
|
this.off("tick", this._animateViewport);
|
|
@@ -2959,6 +2975,7 @@ class Editor extends EventEmitter {
|
|
|
2959
2975
|
}
|
|
2960
2976
|
const isOnSamePage = presence.currentPageId === this.getCurrentPageId();
|
|
2961
2977
|
if (!isOnSamePage) {
|
|
2978
|
+
this.markHistoryStoppingPoint("change-page");
|
|
2962
2979
|
this.setCurrentPage(presence.currentPageId);
|
|
2963
2980
|
}
|
|
2964
2981
|
if (opts && opts.animation && !isOnSamePage) {
|
|
@@ -3682,7 +3699,9 @@ class Editor extends EventEmitter {
|
|
|
3682
3699
|
const id = typeof page === "string" ? page : page.id;
|
|
3683
3700
|
const freshPage = this.getPage(id);
|
|
3684
3701
|
if (!freshPage) return this;
|
|
3685
|
-
const prevCamera = {
|
|
3702
|
+
const prevCamera = {
|
|
3703
|
+
...(this.store.get(CameraRecordType.createId(freshPage.id)) ?? this.getCamera())
|
|
3704
|
+
};
|
|
3686
3705
|
const content = this.getContentFromCurrentPage(this.getSortedChildIdsForParent(freshPage.id));
|
|
3687
3706
|
this.run(() => {
|
|
3688
3707
|
const pages = this.getPages();
|
|
@@ -3691,7 +3710,7 @@ class Editor extends EventEmitter {
|
|
|
3691
3710
|
this.setCurrentPage(createId);
|
|
3692
3711
|
this.setCamera(prevCamera);
|
|
3693
3712
|
if (content) {
|
|
3694
|
-
return this.putContentOntoCurrentPage(content);
|
|
3713
|
+
return this.putContentOntoCurrentPage(content, { preservePosition: true });
|
|
3695
3714
|
}
|
|
3696
3715
|
});
|
|
3697
3716
|
return this;
|
|
@@ -3790,7 +3809,9 @@ class Editor extends EventEmitter {
|
|
|
3790
3809
|
if (ids.length <= 0) return this;
|
|
3791
3810
|
this.run(
|
|
3792
3811
|
() => {
|
|
3793
|
-
this.store.props.assets.remove?.(ids)
|
|
3812
|
+
Promise.resolve(this.store.props.assets.remove?.(ids)).catch(
|
|
3813
|
+
(err) => console.error("Error while removing assets from the asset store:", err)
|
|
3814
|
+
);
|
|
3794
3815
|
this.store.remove(ids);
|
|
3795
3816
|
},
|
|
3796
3817
|
{ history: "ignore" }
|
|
@@ -4172,7 +4193,7 @@ class Editor extends EventEmitter {
|
|
|
4172
4193
|
if (shapes.length === 0) {
|
|
4173
4194
|
return;
|
|
4174
4195
|
}
|
|
4175
|
-
const ids =
|
|
4196
|
+
const ids = toShapeIds(shapes);
|
|
4176
4197
|
const freshShapes = compact(ids.map((id) => this.getShape(id)));
|
|
4177
4198
|
if (freshShapes.length === 1) {
|
|
4178
4199
|
const parentId = freshShapes[0].parentId;
|
|
@@ -4269,12 +4290,14 @@ class Editor extends EventEmitter {
|
|
|
4269
4290
|
*/
|
|
4270
4291
|
getSelectedShapeAtPoint(point) {
|
|
4271
4292
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
4272
|
-
|
|
4293
|
+
if (selectedShapeIds.length === 0) return void 0;
|
|
4294
|
+
const selectedShapeIdSet = new Set(selectedShapeIds);
|
|
4295
|
+
const margin = this.getHitTestMargin();
|
|
4273
4296
|
const sortedShapes = this.getCurrentPageShapesSorted();
|
|
4274
4297
|
for (let i = sortedShapes.length - 1; i >= 0; i--) {
|
|
4275
4298
|
const shape = sortedShapes[i];
|
|
4276
4299
|
if (shape.type === "group") continue;
|
|
4277
|
-
if (!
|
|
4300
|
+
if (!selectedShapeIdSet.has(shape.id)) continue;
|
|
4278
4301
|
if (this.getShapeGeometry(shape).hitTestPoint(
|
|
4279
4302
|
this.getPointInShapeSpace(shape, point),
|
|
4280
4303
|
margin,
|
|
@@ -4372,7 +4395,6 @@ class Editor extends EventEmitter {
|
|
|
4372
4395
|
}
|
|
4373
4396
|
return inMarginClosestToEdgeHit || shape;
|
|
4374
4397
|
} else {
|
|
4375
|
-
if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
|
|
4376
4398
|
if (hitInside ? (
|
|
4377
4399
|
// On hitInside, the distance will be negative for hits inside
|
|
4378
4400
|
// If the distance is positive, check against the outer margin
|
|
@@ -4389,6 +4411,7 @@ class Editor extends EventEmitter {
|
|
|
4389
4411
|
inMarginClosestToEdgeHit = shape;
|
|
4390
4412
|
}
|
|
4391
4413
|
} else if (!inMarginClosestToEdgeHit) {
|
|
4414
|
+
if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
|
|
4392
4415
|
const { area } = geometry;
|
|
4393
4416
|
if (area < inHollowSmallestArea) {
|
|
4394
4417
|
inHollowSmallestArea = area;
|
|
@@ -4399,6 +4422,9 @@ class Editor extends EventEmitter {
|
|
|
4399
4422
|
}
|
|
4400
4423
|
} else {
|
|
4401
4424
|
if (distance < this.getHitTestMargin()) {
|
|
4425
|
+
if (inMarginClosestToEdgeHit && inMarginClosestToEdgeDistance <= distance) {
|
|
4426
|
+
return inMarginClosestToEdgeHit;
|
|
4427
|
+
}
|
|
4402
4428
|
return shape;
|
|
4403
4429
|
}
|
|
4404
4430
|
}
|
|
@@ -4675,7 +4701,7 @@ class Editor extends EventEmitter {
|
|
|
4675
4701
|
* @public
|
|
4676
4702
|
*/
|
|
4677
4703
|
reparentShapes(shapes, parentId, insertIndex) {
|
|
4678
|
-
const ids =
|
|
4704
|
+
const ids = toShapeIds(shapes);
|
|
4679
4705
|
if (ids.length === 0) return this;
|
|
4680
4706
|
const changes = [];
|
|
4681
4707
|
const parentTransform = isPageId(parentId) ? Mat.Identity() : this.getShapePageTransform(parentId);
|
|
@@ -4904,6 +4930,7 @@ class Editor extends EventEmitter {
|
|
|
4904
4930
|
* binding, but the `type`, `toId`, and `fromId` must all be provided.
|
|
4905
4931
|
*/
|
|
4906
4932
|
createBindings(partials) {
|
|
4933
|
+
if (this.getIsReadonly()) return this;
|
|
4907
4934
|
const bindings = [];
|
|
4908
4935
|
for (const partial of partials) {
|
|
4909
4936
|
const fromShape = this.getShape(partial.fromId);
|
|
@@ -4938,6 +4965,7 @@ class Editor extends EventEmitter {
|
|
|
4938
4965
|
* binding is skipped. The changes from the partial are merged into the existing record.
|
|
4939
4966
|
*/
|
|
4940
4967
|
updateBindings(partials) {
|
|
4968
|
+
if (this.getIsReadonly()) return this;
|
|
4941
4969
|
const updated = [];
|
|
4942
4970
|
for (const partial of partials) {
|
|
4943
4971
|
if (!partial) continue;
|
|
@@ -4966,6 +4994,16 @@ class Editor extends EventEmitter {
|
|
|
4966
4994
|
* Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
|
|
4967
4995
|
*/
|
|
4968
4996
|
deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4997
|
+
if (this.getIsReadonly()) return this;
|
|
4998
|
+
return this._deleteBindings(bindings, { isolateShapes });
|
|
4999
|
+
}
|
|
5000
|
+
/**
|
|
5001
|
+
* Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
|
|
5002
|
+
* readonly mode; the public deleteBindings is what readonly blocks.
|
|
5003
|
+
*
|
|
5004
|
+
* @internal
|
|
5005
|
+
*/
|
|
5006
|
+
_deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4969
5007
|
const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
|
|
4970
5008
|
if (isolateShapes) {
|
|
4971
5009
|
this.store.atomic(() => {
|
|
@@ -5024,7 +5062,7 @@ class Editor extends EventEmitter {
|
|
|
5024
5062
|
* @param opts - The options for the rotation.
|
|
5025
5063
|
*/
|
|
5026
5064
|
rotateShapesBy(shapes, delta, opts) {
|
|
5027
|
-
const ids =
|
|
5065
|
+
const ids = toShapeIds(shapes);
|
|
5028
5066
|
if (ids.length <= 0) return this;
|
|
5029
5067
|
const snapshot = getRotationSnapshot({ editor: this, ids });
|
|
5030
5068
|
if (!snapshot) return this;
|
|
@@ -5061,6 +5099,14 @@ class Editor extends EventEmitter {
|
|
|
5061
5099
|
}
|
|
5062
5100
|
return workingShape;
|
|
5063
5101
|
}
|
|
5102
|
+
// Counter-rotates the page-space delta into the parent's space; without that a child of a rotated
|
|
5103
|
+
// frame or group would move along its parent's axes instead of the page's.
|
|
5104
|
+
// todo: a shape laid out together with its own parent moves twice, once with the parent and once
|
|
5105
|
+
// on its own; the layout commands should skip shapes whose ancestors are also being laid out
|
|
5106
|
+
getChangesToTranslateShapeByPageDelta(shape, pageDelta) {
|
|
5107
|
+
const localDelta = Vec.From(pageDelta).rot(-this.getShapeParentTransform(shape).rotation());
|
|
5108
|
+
return this.getChangesToTranslateShape(shape, localDelta.add(shape));
|
|
5109
|
+
}
|
|
5064
5110
|
/**
|
|
5065
5111
|
* Move shapes by a delta.
|
|
5066
5112
|
*
|
|
@@ -5073,14 +5119,12 @@ class Editor extends EventEmitter {
|
|
|
5073
5119
|
* @param offset - The offset to apply to the shapes.
|
|
5074
5120
|
*/
|
|
5075
5121
|
nudgeShapes(shapes, offset) {
|
|
5076
|
-
const ids =
|
|
5122
|
+
const ids = toShapeIds(shapes);
|
|
5077
5123
|
if (ids.length <= 0) return this;
|
|
5078
5124
|
const changes = [];
|
|
5079
5125
|
for (const id of ids) {
|
|
5080
5126
|
const shape = this.getShape(id);
|
|
5081
|
-
|
|
5082
|
-
localDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5083
|
-
changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
|
|
5127
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, offset));
|
|
5084
5128
|
}
|
|
5085
5129
|
this.updateShapes(changes);
|
|
5086
5130
|
return this;
|
|
@@ -5101,7 +5145,7 @@ class Editor extends EventEmitter {
|
|
|
5101
5145
|
*/
|
|
5102
5146
|
duplicateShapes(shapes, offset) {
|
|
5103
5147
|
this.run(() => {
|
|
5104
|
-
const _ids =
|
|
5148
|
+
const _ids = toShapeIds(shapes);
|
|
5105
5149
|
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
|
|
5106
5150
|
if (ids.length <= 0) return this;
|
|
5107
5151
|
const initialIds = new Set(ids);
|
|
@@ -5210,7 +5254,7 @@ class Editor extends EventEmitter {
|
|
|
5210
5254
|
* @public
|
|
5211
5255
|
*/
|
|
5212
5256
|
moveShapesToPage(shapes, pageId) {
|
|
5213
|
-
const ids =
|
|
5257
|
+
const ids = toShapeIds(shapes);
|
|
5214
5258
|
if (ids.length === 0) return this;
|
|
5215
5259
|
if (this.getIsReadonly()) return this;
|
|
5216
5260
|
const currentPageId = this.getCurrentPageId();
|
|
@@ -5246,7 +5290,7 @@ class Editor extends EventEmitter {
|
|
|
5246
5290
|
* @public
|
|
5247
5291
|
*/
|
|
5248
5292
|
toggleLock(shapes) {
|
|
5249
|
-
const ids =
|
|
5293
|
+
const ids = toShapeIds(shapes);
|
|
5250
5294
|
if (this.getIsReadonly() || ids.length === 0) return this;
|
|
5251
5295
|
let allLocked = true;
|
|
5252
5296
|
const shapesToToggle = [];
|
|
@@ -5285,7 +5329,7 @@ class Editor extends EventEmitter {
|
|
|
5285
5329
|
* @public
|
|
5286
5330
|
*/
|
|
5287
5331
|
sendToBack(shapes) {
|
|
5288
|
-
const ids =
|
|
5332
|
+
const ids = toShapeIds(shapes);
|
|
5289
5333
|
const changes = getReorderingShapesChanges(this, "toBack", ids, {
|
|
5290
5334
|
considerAllShapes: true
|
|
5291
5335
|
});
|
|
@@ -5315,7 +5359,7 @@ class Editor extends EventEmitter {
|
|
|
5315
5359
|
* @public
|
|
5316
5360
|
*/
|
|
5317
5361
|
sendBackward(shapes, opts = {}) {
|
|
5318
|
-
const ids =
|
|
5362
|
+
const ids = toShapeIds(shapes);
|
|
5319
5363
|
const changes = getReorderingShapesChanges(this, "backward", ids, opts);
|
|
5320
5364
|
if (changes) this.updateShapes(changes);
|
|
5321
5365
|
return this;
|
|
@@ -5343,7 +5387,7 @@ class Editor extends EventEmitter {
|
|
|
5343
5387
|
* @public
|
|
5344
5388
|
*/
|
|
5345
5389
|
bringForward(shapes, opts = {}) {
|
|
5346
|
-
const ids =
|
|
5390
|
+
const ids = toShapeIds(shapes);
|
|
5347
5391
|
const changes = getReorderingShapesChanges(this, "forward", ids, opts);
|
|
5348
5392
|
if (changes) this.updateShapes(changes);
|
|
5349
5393
|
return this;
|
|
@@ -5362,7 +5406,7 @@ class Editor extends EventEmitter {
|
|
|
5362
5406
|
* @public
|
|
5363
5407
|
*/
|
|
5364
5408
|
bringToFront(shapes) {
|
|
5365
|
-
const ids =
|
|
5409
|
+
const ids = toShapeIds(shapes);
|
|
5366
5410
|
const changes = getReorderingShapesChanges(this, "toFront", ids);
|
|
5367
5411
|
if (changes) this.updateShapes(changes);
|
|
5368
5412
|
return this;
|
|
@@ -5374,7 +5418,7 @@ class Editor extends EventEmitter {
|
|
|
5374
5418
|
* @internal
|
|
5375
5419
|
*/
|
|
5376
5420
|
getShapeClusters(shapes, type, opts) {
|
|
5377
|
-
const ids =
|
|
5421
|
+
const ids = toShapeIds(shapes);
|
|
5378
5422
|
let freshShapes = compact(ids.map((id) => this.getShape(id)));
|
|
5379
5423
|
if (opts?.filterAxisAligned) {
|
|
5380
5424
|
freshShapes = freshShapes.filter((s) => {
|
|
@@ -5399,7 +5443,7 @@ class Editor extends EventEmitter {
|
|
|
5399
5443
|
const shapesMovingTogether = [shape];
|
|
5400
5444
|
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5401
5445
|
this.collectShapesViaArrowBindings({
|
|
5402
|
-
bindings: this.
|
|
5446
|
+
bindings: this.getBindingsInvolvingShape(shape.id, "arrow"),
|
|
5403
5447
|
initialShapes: freshShapes,
|
|
5404
5448
|
resultShapes: shapesMovingTogether,
|
|
5405
5449
|
resultBounds: boundsOfShapesMovingTogether,
|
|
@@ -5455,7 +5499,7 @@ class Editor extends EventEmitter {
|
|
|
5455
5499
|
*/
|
|
5456
5500
|
flipShapes(shapes, operation) {
|
|
5457
5501
|
if (this.getIsReadonly()) return this;
|
|
5458
|
-
const ids =
|
|
5502
|
+
const ids = toShapeIds(shapes);
|
|
5459
5503
|
const shapesToFlipFirstPass = compact(ids.map((id) => this.getShape(id)));
|
|
5460
5504
|
for (const shape of shapesToFlipFirstPass) {
|
|
5461
5505
|
if (this.isShapeOfType(shape, "group")) {
|
|
@@ -5529,21 +5573,7 @@ class Editor extends EventEmitter {
|
|
|
5529
5573
|
const { clusters: shapeClustersToStack } = this.getShapeClusters(shapes, "stack");
|
|
5530
5574
|
const len = shapeClustersToStack.length;
|
|
5531
5575
|
if (_gap === 0 && len < 3 || len < 2) return this;
|
|
5532
|
-
|
|
5533
|
-
let min;
|
|
5534
|
-
let max;
|
|
5535
|
-
let dim;
|
|
5536
|
-
if (operation === "horizontal") {
|
|
5537
|
-
val = "x";
|
|
5538
|
-
min = "minX";
|
|
5539
|
-
max = "maxX";
|
|
5540
|
-
dim = "width";
|
|
5541
|
-
} else {
|
|
5542
|
-
val = "y";
|
|
5543
|
-
min = "minY";
|
|
5544
|
-
max = "maxY";
|
|
5545
|
-
dim = "height";
|
|
5546
|
-
}
|
|
5576
|
+
const { val, min, max, dim } = AXIS[operation];
|
|
5547
5577
|
let shapeGap = 0;
|
|
5548
5578
|
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5549
5579
|
if (_gap === 0) {
|
|
@@ -5582,13 +5612,7 @@ class Editor extends EventEmitter {
|
|
|
5582
5612
|
const delta = new Vec();
|
|
5583
5613
|
delta[val] = v + shapeGap - pageBounds[val];
|
|
5584
5614
|
for (const shape of shapes2) {
|
|
5585
|
-
|
|
5586
|
-
const parent = this.getShapeParent(shape);
|
|
5587
|
-
if (parent) {
|
|
5588
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5589
|
-
}
|
|
5590
|
-
shapeDelta.add(shape);
|
|
5591
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5615
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5592
5616
|
}
|
|
5593
5617
|
v += pageBounds[dim] + shapeGap;
|
|
5594
5618
|
}
|
|
@@ -5668,13 +5692,7 @@ class Editor extends EventEmitter {
|
|
|
5668
5692
|
for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
|
|
5669
5693
|
const delta = Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
|
|
5670
5694
|
for (const shape of shapes2) {
|
|
5671
|
-
|
|
5672
|
-
const parent = this.getShapeParent(shape);
|
|
5673
|
-
if (parent) {
|
|
5674
|
-
shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5675
|
-
}
|
|
5676
|
-
shapeDelta.add(shape);
|
|
5677
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5695
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5678
5696
|
}
|
|
5679
5697
|
}
|
|
5680
5698
|
if (changes.length) {
|
|
@@ -5734,13 +5752,7 @@ class Editor extends EventEmitter {
|
|
|
5734
5752
|
}
|
|
5735
5753
|
}
|
|
5736
5754
|
for (const shape of shapes2) {
|
|
5737
|
-
|
|
5738
|
-
const parent = this.getShapeParent(shape);
|
|
5739
|
-
if (parent) {
|
|
5740
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5741
|
-
}
|
|
5742
|
-
shapeDelta.add(shape);
|
|
5743
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5755
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5744
5756
|
}
|
|
5745
5757
|
});
|
|
5746
5758
|
this.updateShapes(changes);
|
|
@@ -5764,27 +5776,13 @@ class Editor extends EventEmitter {
|
|
|
5764
5776
|
if (this.getIsReadonly()) return this;
|
|
5765
5777
|
const { clusters: shapeClustersToDistribute } = this.getShapeClusters(shapes, "distribute");
|
|
5766
5778
|
if (shapeClustersToDistribute.length < 3) return this;
|
|
5767
|
-
|
|
5768
|
-
let min;
|
|
5769
|
-
let max;
|
|
5770
|
-
let dim;
|
|
5771
|
-
if (operation === "horizontal") {
|
|
5772
|
-
val = "x";
|
|
5773
|
-
min = "minX";
|
|
5774
|
-
max = "maxX";
|
|
5775
|
-
dim = "width";
|
|
5776
|
-
} else {
|
|
5777
|
-
val = "y";
|
|
5778
|
-
min = "minY";
|
|
5779
|
-
max = "maxY";
|
|
5780
|
-
dim = "height";
|
|
5781
|
-
}
|
|
5779
|
+
const { val, min, max, dim } = AXIS[operation];
|
|
5782
5780
|
const changes = [];
|
|
5783
5781
|
const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
|
|
5784
5782
|
const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
|
|
5785
5783
|
if (first === last2) {
|
|
5786
5784
|
const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
|
|
5787
|
-
const ids =
|
|
5785
|
+
const ids = toShapeIds(shapes);
|
|
5788
5786
|
return this.distributeShapes(
|
|
5789
5787
|
ids.filter((id) => !excludedShapeIds.has(id)),
|
|
5790
5788
|
operation
|
|
@@ -5808,13 +5806,7 @@ class Editor extends EventEmitter {
|
|
|
5808
5806
|
delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
|
|
5809
5807
|
}
|
|
5810
5808
|
for (const shape of shapes2) {
|
|
5811
|
-
|
|
5812
|
-
const parent = this.getShapeParent(shape);
|
|
5813
|
-
if (parent) {
|
|
5814
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5815
|
-
}
|
|
5816
|
-
shapeDelta.add(shape);
|
|
5817
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5809
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5818
5810
|
}
|
|
5819
5811
|
v += pageBounds[dim] + gap;
|
|
5820
5812
|
}
|
|
@@ -5844,32 +5836,17 @@ class Editor extends EventEmitter {
|
|
|
5844
5836
|
);
|
|
5845
5837
|
if (shapeClustersToStretch.length < 2) return this;
|
|
5846
5838
|
const commonBounds = Box.Common(allBounds);
|
|
5847
|
-
|
|
5848
|
-
let min;
|
|
5849
|
-
let dim;
|
|
5850
|
-
if (operation === "horizontal") {
|
|
5851
|
-
val = "x";
|
|
5852
|
-
min = "minX";
|
|
5853
|
-
dim = "width";
|
|
5854
|
-
} else {
|
|
5855
|
-
val = "y";
|
|
5856
|
-
min = "minY";
|
|
5857
|
-
dim = "height";
|
|
5858
|
-
}
|
|
5839
|
+
const { val, min, dim } = AXIS[operation];
|
|
5859
5840
|
this.run(() => {
|
|
5860
5841
|
shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5861
|
-
const
|
|
5862
|
-
|
|
5842
|
+
const pageOffset = new Vec();
|
|
5843
|
+
pageOffset[val] = commonBounds[min] - pageBounds[min];
|
|
5863
5844
|
const scaleOrigin = pageBounds.center.clone();
|
|
5864
5845
|
scaleOrigin[val] = commonBounds[min];
|
|
5865
5846
|
const scale = new Vec(1, 1);
|
|
5866
5847
|
scale[val] = commonBounds[dim] / pageBounds[dim];
|
|
5867
5848
|
for (const shape of shapes2) {
|
|
5868
|
-
|
|
5869
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5870
|
-
shapeLocalOffset.add(shape);
|
|
5871
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5872
|
-
this.updateShape(changes);
|
|
5849
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
|
|
5873
5850
|
this.resizeShape(shape.id, scale, {
|
|
5874
5851
|
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
5875
5852
|
scaleOrigin,
|
|
@@ -5912,7 +5889,7 @@ class Editor extends EventEmitter {
|
|
|
5912
5889
|
const scaleY = targetBounds.height / commonBounds.height;
|
|
5913
5890
|
const scale = new Vec(scaleX, scaleY);
|
|
5914
5891
|
shapeClusters.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5915
|
-
const
|
|
5892
|
+
const pageOffset = new Vec(
|
|
5916
5893
|
targetBounds.minX - commonBounds.minX + (pageBounds.minX - commonBounds.minX) * (scaleX - 1),
|
|
5917
5894
|
targetBounds.minY - commonBounds.minY + (pageBounds.minY - commonBounds.minY) * (scaleY - 1)
|
|
5918
5895
|
);
|
|
@@ -5921,11 +5898,7 @@ class Editor extends EventEmitter {
|
|
|
5921
5898
|
targetBounds.minY + (pageBounds.minY - commonBounds.minY) * scaleY
|
|
5922
5899
|
);
|
|
5923
5900
|
for (const shape of shapes2) {
|
|
5924
|
-
|
|
5925
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5926
|
-
shapeLocalOffset.add(shape);
|
|
5927
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5928
|
-
this.updateShape(changes);
|
|
5901
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
|
|
5929
5902
|
this.resizeShape(shape.id, scale, {
|
|
5930
5903
|
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
5931
5904
|
scaleOrigin,
|
|
@@ -6101,11 +6074,20 @@ class Editor extends EventEmitter {
|
|
|
6101
6074
|
initialShape: options.initialShape,
|
|
6102
6075
|
initialBounds: options.initialBounds,
|
|
6103
6076
|
isAspectRatioLocked: options.isAspectRatioLocked,
|
|
6104
|
-
initialPageTransform: options.initialPageTransform
|
|
6077
|
+
initialPageTransform: options.initialPageTransform,
|
|
6078
|
+
dragHandle: options.dragHandle,
|
|
6079
|
+
mode: options.mode,
|
|
6080
|
+
// this is one frame of the same resize, not a new one, so don't fire start/end again
|
|
6081
|
+
skipStartAndEndCallbacks: options.skipStartAndEndCallbacks
|
|
6105
6082
|
});
|
|
6106
6083
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
6107
6084
|
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
6108
|
-
const
|
|
6085
|
+
const parentDelta = shortAngleDist(
|
|
6086
|
+
Mat.Cast(options.initialPageTransform).rotation() - options.initialShape.rotation,
|
|
6087
|
+
parentRotation
|
|
6088
|
+
);
|
|
6089
|
+
const initialParentRotation = parentRotation - parentDelta;
|
|
6090
|
+
const rotation = 2 * options.scaleAxisRotation - options.initialShape.rotation - 2 * initialParentRotation - parentDelta;
|
|
6109
6091
|
this.updateShapes([{ id, type, rotation }]);
|
|
6110
6092
|
}
|
|
6111
6093
|
const preScaleShapePageCenter = Mat.applyToPoint(
|
|
@@ -6344,12 +6326,17 @@ class Editor extends EventEmitter {
|
|
|
6344
6326
|
let remaining = duration;
|
|
6345
6327
|
let t;
|
|
6346
6328
|
const animations = [];
|
|
6329
|
+
const ignoreShapeLock = this._shouldIgnoreShapeLock;
|
|
6347
6330
|
let partial, result;
|
|
6348
6331
|
for (let i = 0, n = partials.length; i < n; i++) {
|
|
6349
6332
|
partial = partials[i];
|
|
6350
6333
|
if (!partial) continue;
|
|
6351
6334
|
const shape = this.getShape(partial.id);
|
|
6352
6335
|
if (!shape) continue;
|
|
6336
|
+
const unlocks = shape.isLocked && Object.hasOwn(partial, "isLocked") && !partial.isLocked;
|
|
6337
|
+
if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
|
|
6338
|
+
continue;
|
|
6339
|
+
}
|
|
6353
6340
|
result = {
|
|
6354
6341
|
start: structuredClone(shape),
|
|
6355
6342
|
end: applyPartialToRecordWithProps(structuredClone(shape), partial)
|
|
@@ -6365,7 +6352,7 @@ class Editor extends EventEmitter {
|
|
|
6365
6352
|
(p) => p && animatingShapes2.get(p.id) === animationId
|
|
6366
6353
|
);
|
|
6367
6354
|
if (partialsToUpdate.length) {
|
|
6368
|
-
this.updateShapes(partialsToUpdate);
|
|
6355
|
+
this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock });
|
|
6369
6356
|
}
|
|
6370
6357
|
this.off("tick", handleTick);
|
|
6371
6358
|
return;
|
|
@@ -6398,13 +6385,13 @@ class Editor extends EventEmitter {
|
|
|
6398
6385
|
throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");
|
|
6399
6386
|
}
|
|
6400
6387
|
if (this.getIsReadonly()) return this;
|
|
6401
|
-
const ids =
|
|
6402
|
-
if (ids.length <= 1) return this;
|
|
6388
|
+
const ids = toShapeIds(shapes);
|
|
6403
6389
|
const shapesToGroup = compact(
|
|
6404
6390
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
|
|
6405
6391
|
(id) => this.getShape(id)
|
|
6406
6392
|
)
|
|
6407
6393
|
);
|
|
6394
|
+
if (shapesToGroup.length <= 1) return this;
|
|
6408
6395
|
const sortedShapeIds = shapesToGroup.sort(sortByIndex).map((s) => s.id);
|
|
6409
6396
|
const childBounds = compact(shapesToGroup.map((shape) => this.getShapePageBounds(shape)));
|
|
6410
6397
|
const pageBounds = Box.Common(childBounds);
|
|
@@ -6413,8 +6400,11 @@ class Editor extends EventEmitter {
|
|
|
6413
6400
|
}
|
|
6414
6401
|
const { x, y } = pageBounds.point;
|
|
6415
6402
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
6416
|
-
if (this.
|
|
6417
|
-
|
|
6403
|
+
if (!this.canCreateShapes([groupId])) {
|
|
6404
|
+
alertMaxShapes(this);
|
|
6405
|
+
return this;
|
|
6406
|
+
}
|
|
6407
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6418
6408
|
this.cancel();
|
|
6419
6409
|
}
|
|
6420
6410
|
const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(sortByIndex);
|
|
@@ -6442,15 +6432,14 @@ class Editor extends EventEmitter {
|
|
|
6442
6432
|
ungroupShapes(shapes, opts = {}) {
|
|
6443
6433
|
if (this.getIsReadonly()) return this;
|
|
6444
6434
|
const { select = true } = opts;
|
|
6445
|
-
const ids =
|
|
6435
|
+
const ids = toShapeIds(shapes);
|
|
6446
6436
|
const shapesToUngroup = compact(
|
|
6447
6437
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
|
|
6448
6438
|
(id) => this.getShape(id)
|
|
6449
6439
|
)
|
|
6450
6440
|
);
|
|
6451
6441
|
if (shapesToUngroup.length === 0) return this;
|
|
6452
|
-
if (this.
|
|
6453
|
-
if (!this.isIn("select.idle")) {
|
|
6442
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6454
6443
|
this.cancel();
|
|
6455
6444
|
}
|
|
6456
6445
|
const idsToSelect = /* @__PURE__ */ new Set();
|
|
@@ -6464,16 +6453,16 @@ class Editor extends EventEmitter {
|
|
|
6464
6453
|
});
|
|
6465
6454
|
if (groups.length === 0) return this;
|
|
6466
6455
|
this.run(() => {
|
|
6467
|
-
let group;
|
|
6468
6456
|
for (let i = 0, n = groups.length; i < n; i++) {
|
|
6469
|
-
group = groups[i];
|
|
6457
|
+
const group = this.getShape(groups[i].id);
|
|
6458
|
+
if (!group) continue;
|
|
6470
6459
|
const childIds = this.getSortedChildIdsForParent(group.id);
|
|
6471
6460
|
for (let j = 0, n2 = childIds.length; j < n2; j++) {
|
|
6472
6461
|
idsToSelect.add(childIds[j]);
|
|
6473
6462
|
}
|
|
6474
6463
|
this.reparentShapes(childIds, group.parentId, group.index);
|
|
6475
6464
|
}
|
|
6476
|
-
this.deleteShapes(groups.map((
|
|
6465
|
+
this.deleteShapes(groups.map((group) => group.id));
|
|
6477
6466
|
if (select) {
|
|
6478
6467
|
this.select(...idsToSelect);
|
|
6479
6468
|
}
|
|
@@ -6554,14 +6543,14 @@ class Editor extends EventEmitter {
|
|
|
6554
6543
|
}
|
|
6555
6544
|
/** @internal */
|
|
6556
6545
|
_getUnlockedShapeIds(ids) {
|
|
6557
|
-
return ids.filter((id) => !this.
|
|
6546
|
+
return ids.filter((id) => !this.isShapeOrAncestorLocked(id));
|
|
6558
6547
|
}
|
|
6559
6548
|
deleteShapes(_ids) {
|
|
6560
6549
|
if (this.getIsReadonly()) return this;
|
|
6561
6550
|
if (!Array.isArray(_ids)) {
|
|
6562
6551
|
throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");
|
|
6563
6552
|
}
|
|
6564
|
-
const shapeIds =
|
|
6553
|
+
const shapeIds = toShapeIds(_ids);
|
|
6565
6554
|
const shapeIdsToDelete = this._shouldIgnoreShapeLock ? shapeIds : this._getUnlockedShapeIds(shapeIds);
|
|
6566
6555
|
if (shapeIdsToDelete.length === 0) return this;
|
|
6567
6556
|
const allShapeIdsToDelete = new Set(shapeIdsToDelete);
|
|
@@ -6906,7 +6895,7 @@ class Editor extends EventEmitter {
|
|
|
6906
6895
|
* @public
|
|
6907
6896
|
*/
|
|
6908
6897
|
getContentFromCurrentPage(shapes) {
|
|
6909
|
-
const ids =
|
|
6898
|
+
const ids = toShapeIds(shapes);
|
|
6910
6899
|
if (!ids) return;
|
|
6911
6900
|
if (ids.length === 0) return;
|
|
6912
6901
|
const shapeIds = this.getShapeAndDescendantIds(ids);
|
|
@@ -6974,21 +6963,29 @@ class Editor extends EventEmitter {
|
|
|
6974
6963
|
await Promise.allSettled(
|
|
6975
6964
|
content.assets.map(async (asset) => {
|
|
6976
6965
|
if ((asset.type === "image" || asset.type === "video") && !asset.props.src?.startsWith("data:image") && !asset.props.src?.startsWith("data:video") && !asset.props.src?.startsWith("http")) {
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6966
|
+
try {
|
|
6967
|
+
const objectUrl = await this.store.props.assets.resolve(asset, {
|
|
6968
|
+
screenScale: 1,
|
|
6969
|
+
steppedScreenScale: 1,
|
|
6970
|
+
dpr: 1,
|
|
6971
|
+
networkEffectiveType: null,
|
|
6972
|
+
shouldResolveToOriginal: true
|
|
6973
|
+
});
|
|
6974
|
+
if (objectUrl) {
|
|
6975
|
+
const response = await fetch(objectUrl);
|
|
6976
|
+
if (response.ok) {
|
|
6977
|
+
const assetWithDataUrl = structuredClone(asset);
|
|
6978
|
+
assetWithDataUrl.props.src = await FileHelpers.blobToDataUrl(await response.blob());
|
|
6979
|
+
assets.push(assetWithDataUrl);
|
|
6980
|
+
return;
|
|
6981
|
+
}
|
|
6982
|
+
console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`);
|
|
6983
|
+
}
|
|
6984
|
+
} catch (err) {
|
|
6985
|
+
console.warn(`Could not inline asset ${asset.id}`, err);
|
|
6986
|
+
}
|
|
6991
6987
|
}
|
|
6988
|
+
assets.push(asset);
|
|
6992
6989
|
})
|
|
6993
6990
|
);
|
|
6994
6991
|
content.assets = assets;
|
|
@@ -7282,7 +7279,7 @@ class Editor extends EventEmitter {
|
|
|
7282
7279
|
* @public
|
|
7283
7280
|
*/
|
|
7284
7281
|
async getSvgElement(shapes, opts = {}) {
|
|
7285
|
-
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() :
|
|
7282
|
+
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes);
|
|
7286
7283
|
if (ids.length === 0) return void 0;
|
|
7287
7284
|
await this.fonts.loadRequiredFontsForCurrentPage(this.options.maxFontsToLoadBeforeRender);
|
|
7288
7285
|
return exportToSvg(this, ids, opts);
|
|
@@ -7878,22 +7875,22 @@ class Editor extends EventEmitter {
|
|
|
7878
7875
|
const releaseCtrl = this._ctrlKeyTimeout !== -1;
|
|
7879
7876
|
const releaseMeta = this._metaKeyTimeout !== -1;
|
|
7880
7877
|
if (releaseShift) {
|
|
7881
|
-
clearTimeout(this._shiftKeyTimeout);
|
|
7878
|
+
this.timers.clearTimeout(this._shiftKeyTimeout);
|
|
7882
7879
|
this._shiftKeyTimeout = -1;
|
|
7883
7880
|
this.inputs.setShiftKey(false);
|
|
7884
7881
|
}
|
|
7885
7882
|
if (releaseAlt) {
|
|
7886
|
-
clearTimeout(this._altKeyTimeout);
|
|
7883
|
+
this.timers.clearTimeout(this._altKeyTimeout);
|
|
7887
7884
|
this._altKeyTimeout = -1;
|
|
7888
7885
|
this.inputs.setAltKey(false);
|
|
7889
7886
|
}
|
|
7890
7887
|
if (releaseCtrl) {
|
|
7891
|
-
clearTimeout(this._ctrlKeyTimeout);
|
|
7888
|
+
this.timers.clearTimeout(this._ctrlKeyTimeout);
|
|
7892
7889
|
this._ctrlKeyTimeout = -1;
|
|
7893
7890
|
this.inputs.setCtrlKey(false);
|
|
7894
7891
|
}
|
|
7895
7892
|
if (releaseMeta) {
|
|
7896
|
-
clearTimeout(this._metaKeyTimeout);
|
|
7893
|
+
this.timers.clearTimeout(this._metaKeyTimeout);
|
|
7897
7894
|
this._metaKeyTimeout = -1;
|
|
7898
7895
|
this.inputs.setMetaKey(false);
|
|
7899
7896
|
}
|
|
@@ -8007,28 +8004,28 @@ class Editor extends EventEmitter {
|
|
|
8007
8004
|
return;
|
|
8008
8005
|
}
|
|
8009
8006
|
if (info.shiftKey) {
|
|
8010
|
-
clearTimeout(this._shiftKeyTimeout);
|
|
8007
|
+
this.timers.clearTimeout(this._shiftKeyTimeout);
|
|
8011
8008
|
this._shiftKeyTimeout = -1;
|
|
8012
8009
|
inputs.setShiftKey(true);
|
|
8013
8010
|
} else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
|
|
8014
8011
|
this._shiftKeyTimeout = this.timers.setTimeout(this._releaseShiftKey, 150);
|
|
8015
8012
|
}
|
|
8016
8013
|
if (info.altKey) {
|
|
8017
|
-
clearTimeout(this._altKeyTimeout);
|
|
8014
|
+
this.timers.clearTimeout(this._altKeyTimeout);
|
|
8018
8015
|
this._altKeyTimeout = -1;
|
|
8019
8016
|
inputs.setAltKey(true);
|
|
8020
8017
|
} else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
|
|
8021
8018
|
this._altKeyTimeout = this.timers.setTimeout(this._releaseAltKey, 150);
|
|
8022
8019
|
}
|
|
8023
8020
|
if (info.ctrlKey) {
|
|
8024
|
-
clearTimeout(this._ctrlKeyTimeout);
|
|
8021
|
+
this.timers.clearTimeout(this._ctrlKeyTimeout);
|
|
8025
8022
|
this._ctrlKeyTimeout = -1;
|
|
8026
8023
|
inputs.setCtrlKey(true);
|
|
8027
8024
|
} else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
|
|
8028
8025
|
this._ctrlKeyTimeout = this.timers.setTimeout(this._releaseCtrlKey, 150);
|
|
8029
8026
|
}
|
|
8030
8027
|
if (info.metaKey && info.name !== "key_up") {
|
|
8031
|
-
clearTimeout(this._metaKeyTimeout);
|
|
8028
|
+
this.timers.clearTimeout(this._metaKeyTimeout);
|
|
8032
8029
|
this._metaKeyTimeout = -1;
|
|
8033
8030
|
inputs.setMetaKey(true);
|
|
8034
8031
|
} else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
|
|
@@ -8042,8 +8039,7 @@ class Editor extends EventEmitter {
|
|
|
8042
8039
|
const cameraOptions = this._cameraOptions.__unsafe__getWithoutCapture();
|
|
8043
8040
|
switch (type) {
|
|
8044
8041
|
case "pinch": {
|
|
8045
|
-
|
|
8046
|
-
clearTimeout(this._longPressTimeout);
|
|
8042
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8047
8043
|
this.inputs.updateFromEvent(info);
|
|
8048
8044
|
switch (info.name) {
|
|
8049
8045
|
case "pinch_start": {
|
|
@@ -8064,6 +8060,7 @@ class Editor extends EventEmitter {
|
|
|
8064
8060
|
}
|
|
8065
8061
|
case "pinch": {
|
|
8066
8062
|
if (!inputs.getIsPinching()) return;
|
|
8063
|
+
if (cameraOptions.isLocked) return;
|
|
8067
8064
|
const {
|
|
8068
8065
|
point: { z = 1 },
|
|
8069
8066
|
delta: { x: dx, y: dy }
|
|
@@ -8119,7 +8116,7 @@ class Editor extends EventEmitter {
|
|
|
8119
8116
|
const { panSpeed, zoomSpeed } = cameraOptions;
|
|
8120
8117
|
let wheelBehavior = cameraOptions.wheelBehavior;
|
|
8121
8118
|
const inputMode = this.user.getUserPreferences().inputMode;
|
|
8122
|
-
if (inputMode !== null) {
|
|
8119
|
+
if (inputMode !== null && wheelBehavior !== "none") {
|
|
8123
8120
|
wheelBehavior = inputMode === "trackpad" ? "pan" : "zoom";
|
|
8124
8121
|
}
|
|
8125
8122
|
if (wheelBehavior !== "none") {
|
|
@@ -8171,12 +8168,12 @@ class Editor extends EventEmitter {
|
|
|
8171
8168
|
}
|
|
8172
8169
|
case "pointer": {
|
|
8173
8170
|
if (inputs.getIsPinching()) return;
|
|
8174
|
-
this.inputs.updateFromEvent(info);
|
|
8175
8171
|
const { isPen } = info;
|
|
8176
8172
|
const { isPenMode } = instanceState;
|
|
8173
|
+
if (isPenMode && !isPen) return;
|
|
8174
|
+
this.inputs.updateFromEvent(info);
|
|
8177
8175
|
switch (info.name) {
|
|
8178
8176
|
case "pointer_down": {
|
|
8179
|
-
if (isPenMode && !isPen) return;
|
|
8180
8177
|
this._releaseDebouncedModifiers();
|
|
8181
8178
|
if (!this.inputs.getIsPanning()) {
|
|
8182
8179
|
this._longPressTimeout = this.timers.setTimeout(() => {
|
|
@@ -8200,11 +8197,12 @@ class Editor extends EventEmitter {
|
|
|
8200
8197
|
inputs.buttons.add(info.button);
|
|
8201
8198
|
inputs.setIsPointing(true);
|
|
8202
8199
|
inputs.setIsDragging(false);
|
|
8200
|
+
this.stopCameraAnimation();
|
|
8203
8201
|
if (!isPenMode && info.isPenDirect) {
|
|
8204
8202
|
this.updateInstanceState({ isPenMode: true });
|
|
8205
8203
|
this.interrupt();
|
|
8206
8204
|
}
|
|
8207
|
-
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
8205
|
+
if (info.button === STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
|
|
8208
8206
|
this._restoreToolId = this.getCurrentToolId();
|
|
8209
8207
|
this.complete();
|
|
8210
8208
|
this.setCurrentTool("eraser");
|
|
@@ -8213,10 +8211,10 @@ class Editor extends EventEmitter {
|
|
|
8213
8211
|
this._prevCursor = this.getInstanceState().cursor.type;
|
|
8214
8212
|
}
|
|
8215
8213
|
this.inputs.setIsPanning(true);
|
|
8216
|
-
clearTimeout(this._longPressTimeout);
|
|
8214
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8217
8215
|
} else if (info.button === RIGHT_MOUSE_BUTTON && this.options.rightClickPanning) {
|
|
8218
8216
|
this.inputs.setIsRightPointing(true);
|
|
8219
|
-
clearTimeout(this._longPressTimeout);
|
|
8217
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8220
8218
|
return this;
|
|
8221
8219
|
}
|
|
8222
8220
|
if (this.inputs.getIsPanning()) {
|
|
@@ -8227,7 +8225,6 @@ class Editor extends EventEmitter {
|
|
|
8227
8225
|
break;
|
|
8228
8226
|
}
|
|
8229
8227
|
case "pointer_move": {
|
|
8230
|
-
if (!isPen && isPenMode) return;
|
|
8231
8228
|
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera());
|
|
8232
8229
|
if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
|
|
8233
8230
|
const currentScreenPoint = this.inputs.getCurrentScreenPoint();
|
|
@@ -8258,16 +8255,15 @@ class Editor extends EventEmitter {
|
|
|
8258
8255
|
}
|
|
8259
8256
|
if (inputs.getIsPointing() && !inputs.getIsDragging() && Vec.Dist2(inputs.getOriginPagePoint(), inputs.getCurrentPagePoint()) * this.getZoomLevel() > (instanceState.isCoarsePointer ? this.options.coarseDragDistanceSquared : this.options.dragDistanceSquared) / cz) {
|
|
8260
8257
|
inputs.setIsDragging(true);
|
|
8261
|
-
clearTimeout(this._longPressTimeout);
|
|
8258
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8262
8259
|
}
|
|
8263
8260
|
break;
|
|
8264
8261
|
}
|
|
8265
8262
|
case "pointer_up": {
|
|
8266
8263
|
inputs.setIsDragging(false);
|
|
8267
8264
|
inputs.setIsPointing(false);
|
|
8268
|
-
clearTimeout(this._longPressTimeout);
|
|
8265
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8269
8266
|
inputs.buttons.delete(info.button);
|
|
8270
|
-
if (instanceState.isPenMode && !isPen) return;
|
|
8271
8267
|
if (this.inputs.getIsRightPointing() && !this.inputs.getIsPanning()) {
|
|
8272
8268
|
this.inputs.setIsRightPointing(false);
|
|
8273
8269
|
this._selectedShapeIdsAtPointerDown = [];
|
|
@@ -8323,7 +8319,7 @@ class Editor extends EventEmitter {
|
|
|
8323
8319
|
});
|
|
8324
8320
|
}
|
|
8325
8321
|
} else {
|
|
8326
|
-
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
8322
|
+
if (info.button === STYLUS_ERASER_BUTTON && this.getStateDescendant("eraser")) {
|
|
8327
8323
|
this.complete();
|
|
8328
8324
|
this.setCurrentTool(this._restoreToolId);
|
|
8329
8325
|
}
|
|
@@ -8336,8 +8332,8 @@ class Editor extends EventEmitter {
|
|
|
8336
8332
|
break;
|
|
8337
8333
|
}
|
|
8338
8334
|
case "keyboard": {
|
|
8339
|
-
if (info.
|
|
8340
|
-
if (info.
|
|
8335
|
+
if (info.code === "ShiftRight") info.code = "ShiftLeft";
|
|
8336
|
+
if (info.code === "AltRight") info.code = "AltLeft";
|
|
8341
8337
|
if (info.code === "ControlRight") info.code = "ControlLeft";
|
|
8342
8338
|
if (info.code === "MetaRight") info.code = "MetaLeft";
|
|
8343
8339
|
switch (info.name) {
|
|
@@ -8350,7 +8346,7 @@ class Editor extends EventEmitter {
|
|
|
8350
8346
|
}
|
|
8351
8347
|
this.inputs.setIsPanning(true);
|
|
8352
8348
|
this.inputs.setIsSpacebarPanning(true);
|
|
8353
|
-
clearTimeout(this._longPressTimeout);
|
|
8349
|
+
this.timers.clearTimeout(this._longPressTimeout);
|
|
8354
8350
|
this.setCursor({
|
|
8355
8351
|
type: this.inputs.getIsPointing() ? "grabbing" : "grab",
|
|
8356
8352
|
rotation: 0
|
|
@@ -8376,7 +8372,7 @@ class Editor extends EventEmitter {
|
|
|
8376
8372
|
break;
|
|
8377
8373
|
}
|
|
8378
8374
|
}
|
|
8379
|
-
if (offset) {
|
|
8375
|
+
if (offset && !cameraOptions.isLocked) {
|
|
8380
8376
|
const bounds = this.getViewportPageBounds();
|
|
8381
8377
|
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }));
|
|
8382
8378
|
this._animateToViewport(next, { animation: { duration: 320 } });
|
|
@@ -8416,7 +8412,7 @@ class Editor extends EventEmitter {
|
|
|
8416
8412
|
this.setCurrentTool("select");
|
|
8417
8413
|
}
|
|
8418
8414
|
const { isPenMode } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID);
|
|
8419
|
-
if (info.isPen
|
|
8415
|
+
if (!isPenMode || info.isPen) {
|
|
8420
8416
|
const clickInfo = this._clickManager.handlePointerEvent(info);
|
|
8421
8417
|
if (info.name !== clickInfo.name) {
|
|
8422
8418
|
this.root.handleEvent(info);
|
|
@@ -8438,7 +8434,7 @@ class Editor extends EventEmitter {
|
|
|
8438
8434
|
maybeTrackPerformance(name) {
|
|
8439
8435
|
if (debugFlags.measurePerformance.get()) {
|
|
8440
8436
|
if (this.performanceTracker.isStarted()) {
|
|
8441
|
-
clearTimeout(this.performanceTrackerTimeout);
|
|
8437
|
+
this.timers.clearTimeout(this.performanceTrackerTimeout);
|
|
8442
8438
|
} else {
|
|
8443
8439
|
this.performanceTracker.start(name);
|
|
8444
8440
|
}
|
|
@@ -8707,6 +8703,9 @@ function pushShapeWithDescendants(editor, id, result) {
|
|
|
8707
8703
|
pushShapeWithDescendants(editor, childIds[i], result);
|
|
8708
8704
|
}
|
|
8709
8705
|
}
|
|
8706
|
+
function toShapeIds(shapes) {
|
|
8707
|
+
return typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
|
|
8708
|
+
}
|
|
8710
8709
|
function withIsolatedShapes(editor, shapeIds, callback) {
|
|
8711
8710
|
let result;
|
|
8712
8711
|
editor.run(
|
|
@@ -8729,7 +8728,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8729
8728
|
}
|
|
8730
8729
|
}
|
|
8731
8730
|
}
|
|
8732
|
-
editor.
|
|
8731
|
+
editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
|
|
8733
8732
|
try {
|
|
8734
8733
|
result = Result.ok(callback(bindingsWithBoth));
|
|
8735
8734
|
} catch (error) {
|