@tldraw/editor 5.4.0-next.ef99ab47e5ce → 5.5.0-next.6d9e51e9f3f7
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 +119 -49
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +7 -2
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +6 -8
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasOverlays.js +1 -3
- package/dist-cjs/lib/components/default-components/CanvasOverlays.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 +1 -1
- package/dist-cjs/lib/config/TLUserPreferences.js +6 -2
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/config/createTLStore.js +1 -1
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/constants.js +2 -0
- package/dist-cjs/lib/constants.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +184 -296
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js +7 -3
- package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -3
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +8 -8
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +10 -6
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +2 -1
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +79 -6
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +7 -0
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +0 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +1 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +7 -3
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +6 -3
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +12 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/OverlayManager.js +3 -7
- package/dist-cjs/lib/editor/overlays/OverlayManager.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +0 -1
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +3 -1
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +1 -0
- package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +1 -1
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +3 -2
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/globals/editors.js +57 -0
- package/dist-cjs/lib/globals/editors.js.map +7 -0
- package/dist-cjs/lib/globals/menus.js +9 -4
- package/dist-cjs/lib/globals/menus.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +39 -9
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useLocalStore.js +10 -6
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +1 -0
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js +2 -1
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/license/LicenseManager.js +9 -2
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +16 -3
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/license/useLicenseManagerState.js +5 -4
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +2 -1
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +4 -3
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Edge2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Edge2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +71 -26
- package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Point2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Point2d.js.map +2 -2
- package/dist-cjs/lib/primitives/utils.js +2 -1
- package/dist-cjs/lib/primitives/utils.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js +5 -1
- package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
- package/dist-cjs/lib/utils/normalizeWheel.js +2 -0
- package/dist-cjs/lib/utils/normalizeWheel.js.map +2 -2
- package/dist-cjs/lib/utils/rotation.js +1 -9
- package/dist-cjs/lib/utils/rotation.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +17 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/lib/utils/sync/alerts.js +1 -1
- package/dist-cjs/lib/utils/sync/alerts.js.map +1 -1
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +119 -49
- package/dist-esm/index.mjs +9 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +9 -4
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +6 -8
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasOverlays.mjs +1 -3
- package/dist-esm/lib/components/default-components/CanvasOverlays.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 +1 -1
- package/dist-esm/lib/config/TLUserPreferences.mjs +6 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/config/createTLStore.mjs +1 -1
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/constants.mjs +2 -0
- package/dist-esm/lib/constants.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +193 -297
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs +7 -3
- package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -3
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +9 -9
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +10 -6
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +2 -1
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +81 -8
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +7 -0
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +0 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +2 -3
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +7 -3
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +6 -3
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +12 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs +3 -7
- package/dist-esm/lib/editor/overlays/OverlayManager.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +0 -1
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +3 -1
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +1 -0
- package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +1 -1
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +3 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/globals/editors.mjs +37 -0
- package/dist-esm/lib/globals/editors.mjs.map +7 -0
- package/dist-esm/lib/globals/menus.mjs +9 -4
- package/dist-esm/lib/globals/menus.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +40 -10
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useLocalStore.mjs +11 -7
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +1 -0
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +2 -1
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +9 -2
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +16 -3
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/license/useLicenseManagerState.mjs +5 -4
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +2 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +4 -3
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +75 -27
- package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Point2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Point2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/utils.mjs +2 -1
- package/dist-esm/lib/primitives/utils.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs +5 -1
- package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
- package/dist-esm/lib/utils/normalizeWheel.mjs +2 -0
- package/dist-esm/lib/utils/normalizeWheel.mjs.map +2 -2
- package/dist-esm/lib/utils/rotation.mjs +1 -9
- package/dist-esm/lib/utils/rotation.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +17 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/alerts.mjs +1 -1
- package/dist-esm/lib/utils/sync/alerts.mjs.map +1 -1
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +13 -7
- package/src/index.ts +6 -1
- package/src/lib/TldrawEditor.tsx +16 -4
- package/src/lib/components/MenuClickCapture.tsx +19 -18
- package/src/lib/components/default-components/CanvasOverlays.tsx +1 -3
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/config/TLUserPreferences.test.ts +18 -1
- package/src/lib/config/TLUserPreferences.ts +8 -4
- package/src/lib/config/createTLStore.ts +1 -1
- package/src/lib/constants.ts +8 -0
- package/src/lib/editor/Editor.ts +273 -386
- package/src/lib/editor/derivations/shapeIdsInCurrentPage.ts +7 -3
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +5 -3
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +9 -9
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +35 -4
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +13 -7
- package/src/lib/editor/managers/FontManager/FontManager.ts +2 -1
- package/src/lib/editor/managers/InputsManager/InputsManager.test.ts +199 -3
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +128 -9
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +12 -1
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +0 -2
- package/src/lib/editor/managers/TextManager/TextManager.ts +2 -6
- package/src/lib/editor/managers/ThemeManager/ThemeManager.test.ts +53 -0
- package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +9 -3
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +13 -0
- package/src/lib/editor/managers/TickManager/TickManager.ts +9 -3
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +64 -3
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +18 -1
- package/src/lib/editor/overlays/OverlayManager.ts +3 -7
- package/src/lib/editor/overlays/strokeShapeIndicators.ts +0 -1
- package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +5 -1
- package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +3 -0
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -1
- package/src/lib/editor/tools/StateNode.test.ts +64 -0
- package/src/lib/editor/tools/StateNode.ts +12 -2
- package/src/lib/globals/editors.test.ts +76 -0
- package/src/lib/globals/editors.ts +53 -0
- package/src/lib/globals/menus.test.ts +33 -0
- package/src/lib/globals/menus.ts +11 -4
- package/src/lib/hooks/useCanvasEvents.ts +2 -0
- package/src/lib/hooks/useDocumentEvents.ts +60 -16
- package/src/lib/hooks/useLocalStore.ts +16 -8
- package/src/lib/hooks/usePassThroughWheelEvents.ts +3 -0
- package/src/lib/hooks/usePeerIds.ts +2 -1
- package/src/lib/license/LicenseManager.test.ts +160 -0
- package/src/lib/license/LicenseManager.ts +13 -4
- package/src/lib/license/LicenseProvider.tsx +24 -3
- package/src/lib/license/useLicenseManagerState.ts +8 -6
- package/src/lib/primitives/Box.test.ts +9 -1
- package/src/lib/primitives/Box.ts +3 -1
- package/src/lib/primitives/Vec.test.ts +10 -0
- package/src/lib/primitives/Vec.ts +4 -4
- package/src/lib/primitives/geometry/Arc2d.test.ts +235 -3
- package/src/lib/primitives/geometry/Arc2d.ts +1 -1
- package/src/lib/primitives/geometry/CubicBezier2d.test.ts +186 -3
- package/src/lib/primitives/geometry/CubicBezier2d.ts +1 -1
- package/src/lib/primitives/geometry/CubicSpline2d.test.ts +160 -3
- package/src/lib/primitives/geometry/Edge2d.test.ts +21 -3
- package/src/lib/primitives/geometry/Edge2d.ts +1 -1
- package/src/lib/primitives/geometry/Ellipse2d.test.ts +243 -3
- package/src/lib/primitives/geometry/Geometry2d.test.ts +553 -1
- package/src/lib/primitives/geometry/Group2d.test.ts +419 -3
- package/src/lib/primitives/geometry/Group2d.ts +81 -34
- package/src/lib/primitives/geometry/Point2d.test.ts +14 -3
- package/src/lib/primitives/geometry/Point2d.ts +1 -1
- package/src/lib/primitives/geometry/Polyline2d.test.ts +207 -0
- package/src/lib/primitives/geometry/Stadium2d.test.ts +191 -3
- package/src/lib/primitives/utils.test.ts +10 -1
- package/src/lib/primitives/utils.ts +4 -1
- package/src/lib/test/useCanvasEvents.test.tsx +74 -0
- package/src/lib/test/useDocumentEvents.test.tsx +107 -0
- package/src/lib/test/usePassThroughWheelEvents.test.tsx +25 -2
- package/src/lib/utils/deepLinks.test.ts +15 -0
- package/src/lib/utils/deepLinks.ts +7 -1
- package/src/lib/utils/normalizeWheel.test.ts +39 -0
- package/src/lib/utils/normalizeWheel.ts +6 -0
- package/src/lib/utils/rotation.ts +4 -12
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +56 -0
- package/src/lib/utils/sync/TLLocalSyncClient.ts +24 -0
- package/src/lib/utils/sync/alerts.ts +1 -1
- package/src/version.ts +3 -3
- package/src/lib/primitives/geometry/Polyline.test.ts +0 -5
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
Result,
|
|
40
40
|
ZERO_INDEX_KEY,
|
|
41
41
|
annotateError,
|
|
42
|
+
areArraysShallowEqual,
|
|
42
43
|
assert,
|
|
43
44
|
assertExists,
|
|
44
45
|
bind,
|
|
@@ -74,6 +75,7 @@ import {
|
|
|
74
75
|
import {
|
|
75
76
|
DEFAULT_ANIMATION_OPTIONS,
|
|
76
77
|
DEFAULT_CAMERA_OPTIONS,
|
|
78
|
+
FRAME_MS_60HZ,
|
|
77
79
|
INTERNAL_POINTER_IDS,
|
|
78
80
|
LEFT_MOUSE_BUTTON,
|
|
79
81
|
MIDDLE_MOUSE_BUTTON,
|
|
@@ -83,6 +85,7 @@ import {
|
|
|
83
85
|
import { getOwnerWindow } from "../exports/domUtils.mjs";
|
|
84
86
|
import { exportToSvg } from "../exports/exportToSvg.mjs";
|
|
85
87
|
import { getSvgAsImageWithOptions, trimSvgToContent } from "../exports/getSvgAsImage.mjs";
|
|
88
|
+
import { registerMountedEditor, unregisterMountedEditor } from "../globals/editors.mjs";
|
|
86
89
|
import { tlmenus } from "../globals/menus.mjs";
|
|
87
90
|
import { tltime } from "../globals/time.mjs";
|
|
88
91
|
import { defaultTldrawOptions } from "../options.mjs";
|
|
@@ -91,7 +94,13 @@ import { EASINGS } from "../primitives/easings.mjs";
|
|
|
91
94
|
import { Group2d } from "../primitives/geometry/Group2d.mjs";
|
|
92
95
|
import { intersectPolygonPolygon } from "../primitives/intersect.mjs";
|
|
93
96
|
import { Mat } from "../primitives/Mat.mjs";
|
|
94
|
-
import {
|
|
97
|
+
import {
|
|
98
|
+
HALF_PI,
|
|
99
|
+
approximately,
|
|
100
|
+
areAnglesCompatible,
|
|
101
|
+
clamp,
|
|
102
|
+
pointInPolygon
|
|
103
|
+
} from "../primitives/utils.mjs";
|
|
95
104
|
import { Vec } from "../primitives/Vec.mjs";
|
|
96
105
|
import { areShapesContentEqual } from "../utils/areShapesContentEqual.mjs";
|
|
97
106
|
import { dataUrlToFile } from "../utils/assets.mjs";
|
|
@@ -289,6 +298,10 @@ class Editor extends EventEmitter {
|
|
|
289
298
|
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
290
299
|
nextPageState.editingShapeId = null;
|
|
291
300
|
}
|
|
301
|
+
if (prevPageState.croppingShapeId && shapesNoLongerInPage.has(prevPageState.croppingShapeId)) {
|
|
302
|
+
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
303
|
+
nextPageState.croppingShapeId = null;
|
|
304
|
+
}
|
|
292
305
|
const hintingShapeIds = prevPageState.hintingShapeIds.filter(
|
|
293
306
|
(id) => !shapesNoLongerInPage.has(id)
|
|
294
307
|
);
|
|
@@ -531,10 +544,11 @@ class Editor extends EventEmitter {
|
|
|
531
544
|
this.cancelDoubleClick();
|
|
532
545
|
}
|
|
533
546
|
if (prev?.selectedShapeIds !== next?.selectedShapeIds) {
|
|
547
|
+
const selectedShapeIds = new Set(next.selectedShapeIds);
|
|
534
548
|
const filtered = next.selectedShapeIds.filter((id) => {
|
|
535
549
|
let parentId = this.getShape(id)?.parentId;
|
|
536
550
|
while (isShapeId(parentId)) {
|
|
537
|
-
if (
|
|
551
|
+
if (selectedShapeIds.has(parentId)) {
|
|
538
552
|
return false;
|
|
539
553
|
}
|
|
540
554
|
parentId = this.getShape(parentId)?.parentId;
|
|
@@ -604,9 +618,11 @@ class Editor extends EventEmitter {
|
|
|
604
618
|
this.on("tick", this._flushEventsForTick);
|
|
605
619
|
this.on("mount", () => {
|
|
606
620
|
this._isMounted.set(true);
|
|
621
|
+
registerMountedEditor(this);
|
|
607
622
|
});
|
|
608
623
|
this.on("unmount", () => {
|
|
609
624
|
this._isMounted.set(false);
|
|
625
|
+
unregisterMountedEditor(this);
|
|
610
626
|
});
|
|
611
627
|
this.timers.requestAnimationFrame(() => {
|
|
612
628
|
this._tickManager.start();
|
|
@@ -616,7 +632,10 @@ class Editor extends EventEmitter {
|
|
|
616
632
|
const mode = this.store.props.collaboration.mode;
|
|
617
633
|
this.disposables.add(
|
|
618
634
|
react("update collaboration mode", () => {
|
|
619
|
-
|
|
635
|
+
const isReadonly = mode.get() === "readonly";
|
|
636
|
+
unsafe__withoutCapture(
|
|
637
|
+
() => this._updateInstanceState({ isReadonly }, { history: "ignore" })
|
|
638
|
+
);
|
|
620
639
|
})
|
|
621
640
|
);
|
|
622
641
|
}
|
|
@@ -646,6 +665,14 @@ class Editor extends EventEmitter {
|
|
|
646
665
|
);
|
|
647
666
|
}
|
|
648
667
|
options;
|
|
668
|
+
/**
|
|
669
|
+
* The license manager whose feature flags apply to this editor. Assigned by `<TldrawEditor />`
|
|
670
|
+
* when it creates the editor, so that UI rendered outside the editor tree can resolve the
|
|
671
|
+
* editor's license through the editor instance. Undefined for editors created directly.
|
|
672
|
+
*
|
|
673
|
+
* @internal
|
|
674
|
+
*/
|
|
675
|
+
licenseManager;
|
|
649
676
|
contextId = uniqueId();
|
|
650
677
|
/**
|
|
651
678
|
* The editor's store
|
|
@@ -840,6 +867,7 @@ class Editor extends EventEmitter {
|
|
|
840
867
|
if (this._isMounted.get()) {
|
|
841
868
|
this.emit("unmount");
|
|
842
869
|
}
|
|
870
|
+
unregisterMountedEditor(this);
|
|
843
871
|
this.stopCameraAnimation();
|
|
844
872
|
if (this.getInstanceState().followingUserId) {
|
|
845
873
|
this.stopFollowingUser();
|
|
@@ -965,7 +993,7 @@ class Editor extends EventEmitter {
|
|
|
965
993
|
getShapeUtil(arg) {
|
|
966
994
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
967
995
|
const shapeUtil = getOwnProperty(this.shapeUtils, type);
|
|
968
|
-
|
|
996
|
+
if (!shapeUtil) throw new Error(`No shape util found for type "${type}"`);
|
|
969
997
|
return shapeUtil;
|
|
970
998
|
}
|
|
971
999
|
hasShapeUtil(arg) {
|
|
@@ -1630,7 +1658,8 @@ class Editor extends EventEmitter {
|
|
|
1630
1658
|
if (direction === "next" || direction === "prev") {
|
|
1631
1659
|
const shapeIds = readingOrderShapes.map((shape2) => shape2.id);
|
|
1632
1660
|
const currentIndex = currentShapeId ? shapeIds.indexOf(currentShapeId) : -1;
|
|
1633
|
-
const
|
|
1661
|
+
const startIndex = currentIndex === -1 && direction === "prev" ? 0 : currentIndex;
|
|
1662
|
+
const adjacentIndex = (startIndex + (direction === "next" ? 1 : -1) + shapeIds.length) % shapeIds.length;
|
|
1634
1663
|
adjacentShapeId = shapeIds[adjacentIndex];
|
|
1635
1664
|
} else {
|
|
1636
1665
|
if (!currentShapeId) return;
|
|
@@ -1754,7 +1783,9 @@ class Editor extends EventEmitter {
|
|
|
1754
1783
|
const selectedShapes = this.getSelectedShapes();
|
|
1755
1784
|
if (!selectedShapes.length) return;
|
|
1756
1785
|
const selectedShape = selectedShapes[0];
|
|
1757
|
-
const children =
|
|
1786
|
+
const children = compact(
|
|
1787
|
+
this.getSortedChildIdsForParent(selectedShape.id).map((id) => this.getShape(id))
|
|
1788
|
+
);
|
|
1758
1789
|
const sortedChildren = this._getShapesInReadingOrder(children);
|
|
1759
1790
|
if (sortedChildren.length === 0) return;
|
|
1760
1791
|
this._selectShapesAndZoom([sortedChildren[0].id]);
|
|
@@ -1821,18 +1852,13 @@ class Editor extends EventEmitter {
|
|
|
1821
1852
|
* @internal
|
|
1822
1853
|
*/
|
|
1823
1854
|
getShapesSharedRotation(shapeIds) {
|
|
1824
|
-
let foundFirst = false;
|
|
1825
1855
|
let rotation = 0;
|
|
1826
1856
|
for (let i = 0, n = shapeIds.length; i < n; i++) {
|
|
1827
|
-
const
|
|
1828
|
-
if (
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1833
|
-
} else {
|
|
1834
|
-
foundFirst = true;
|
|
1835
|
-
rotation = pageTransform.rotation();
|
|
1857
|
+
const pageRotation = this.getShapePageTransform(shapeIds[i]).rotation();
|
|
1858
|
+
if (i === 0) {
|
|
1859
|
+
rotation = pageRotation;
|
|
1860
|
+
} else if (pageRotation !== rotation) {
|
|
1861
|
+
return 0;
|
|
1836
1862
|
}
|
|
1837
1863
|
}
|
|
1838
1864
|
return rotation;
|
|
@@ -1858,11 +1884,9 @@ class Editor extends EventEmitter {
|
|
|
1858
1884
|
return bounds;
|
|
1859
1885
|
}
|
|
1860
1886
|
const boxFromRotatedVertices = Box.FromPoints(
|
|
1861
|
-
shapeIds.flatMap(
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
return pageTransform.applyToPoints(this.getShapeGeometry(id).bounds.corners);
|
|
1865
|
-
}).map((p) => p.rot(-selectionRotation))
|
|
1887
|
+
shapeIds.flatMap(
|
|
1888
|
+
(id) => this.getShapePageTransform(id).applyToPoints(this.getShapeGeometry(id).bounds.corners)
|
|
1889
|
+
).map((p) => p.rot(-selectionRotation))
|
|
1866
1890
|
);
|
|
1867
1891
|
boxFromRotatedVertices.point = boxFromRotatedVertices.point.rot(selectionRotation);
|
|
1868
1892
|
return boxFromRotatedVertices;
|
|
@@ -1873,9 +1897,14 @@ class Editor extends EventEmitter {
|
|
|
1873
1897
|
getSelectionRotatedScreenBounds() {
|
|
1874
1898
|
const bounds = this.getSelectionRotatedPageBounds();
|
|
1875
1899
|
if (!bounds) return void 0;
|
|
1876
|
-
const
|
|
1877
|
-
const zoom = this.
|
|
1878
|
-
return new Box(
|
|
1900
|
+
const screenBounds = this.getViewportScreenBounds();
|
|
1901
|
+
const { x: cx, y: cy, z: zoom } = this.getCamera();
|
|
1902
|
+
return new Box(
|
|
1903
|
+
(bounds.x + cx) * zoom + screenBounds.x,
|
|
1904
|
+
(bounds.y + cy) * zoom + screenBounds.y,
|
|
1905
|
+
bounds.width * zoom,
|
|
1906
|
+
bounds.height * zoom
|
|
1907
|
+
);
|
|
1879
1908
|
}
|
|
1880
1909
|
getFocusedGroupId() {
|
|
1881
1910
|
return this.getCurrentPageState().focusedGroupId ?? this.getCurrentPageId();
|
|
@@ -1976,42 +2005,28 @@ class Editor extends EventEmitter {
|
|
|
1976
2005
|
*/
|
|
1977
2006
|
setEditingShape(shape) {
|
|
1978
2007
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
1979
|
-
if (!id)
|
|
2008
|
+
if (id && !this.canEditShape(id)) return this;
|
|
2009
|
+
this.run(() => {
|
|
2010
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
2011
|
+
if (prevEditingShapeId) {
|
|
2012
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
2013
|
+
if (prevEditingShape) {
|
|
2014
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
1980
2017
|
this.run(
|
|
1981
2018
|
() => {
|
|
1982
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
1983
|
-
if (prevEditingShapeId) {
|
|
1984
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
1985
|
-
if (prevEditingShape) {
|
|
1986
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
2019
|
this._updateCurrentPageState({ editingShapeId: null });
|
|
1990
2020
|
this._currentRichTextEditor.set(null);
|
|
2021
|
+
if (!id) return;
|
|
2022
|
+
this.select(id);
|
|
2023
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
2024
|
+
const nextEditingShape = this.getShape(id);
|
|
2025
|
+
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
1991
2026
|
},
|
|
1992
2027
|
{ history: "ignore" }
|
|
1993
2028
|
);
|
|
1994
|
-
|
|
1995
|
-
}
|
|
1996
|
-
if (!this.canEditShape(id)) return this;
|
|
1997
|
-
this.run(
|
|
1998
|
-
() => {
|
|
1999
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
2000
|
-
if (prevEditingShapeId) {
|
|
2001
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
2002
|
-
if (prevEditingShape) {
|
|
2003
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
this._updateCurrentPageState({ editingShapeId: null });
|
|
2007
|
-
this._currentRichTextEditor.set(null);
|
|
2008
|
-
this.select(id);
|
|
2009
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
2010
|
-
const nextEditingShape = this.getShape(id);
|
|
2011
|
-
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
2012
|
-
},
|
|
2013
|
-
{ history: "ignore" }
|
|
2014
|
-
);
|
|
2029
|
+
});
|
|
2015
2030
|
return this;
|
|
2016
2031
|
}
|
|
2017
2032
|
// Rich text editor
|
|
@@ -2117,19 +2132,12 @@ class Editor extends EventEmitter {
|
|
|
2117
2132
|
* @public
|
|
2118
2133
|
*/
|
|
2119
2134
|
setErasingShapes(shapes) {
|
|
2120
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
|
|
2135
|
+
const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
|
|
2121
2136
|
ids.sort();
|
|
2122
2137
|
const erasingShapeIds = this.getErasingShapeIds();
|
|
2123
2138
|
this.run(
|
|
2124
2139
|
() => {
|
|
2125
|
-
if (ids
|
|
2126
|
-
for (let i = 0; i < ids.length; i++) {
|
|
2127
|
-
if (ids[i] !== erasingShapeIds[i]) {
|
|
2128
|
-
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2129
|
-
break;
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
} else {
|
|
2140
|
+
if (!areArraysShallowEqual(ids, erasingShapeIds)) {
|
|
2133
2141
|
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2134
2142
|
}
|
|
2135
2143
|
},
|
|
@@ -2162,6 +2170,7 @@ class Editor extends EventEmitter {
|
|
|
2162
2170
|
if (!_shape) return false;
|
|
2163
2171
|
const util = this.getShapeUtil(_shape);
|
|
2164
2172
|
if (!util.canCrop(_shape)) return false;
|
|
2173
|
+
if (this.getIsReadonly()) return false;
|
|
2165
2174
|
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
2166
2175
|
return true;
|
|
2167
2176
|
}
|
|
@@ -2226,11 +2235,11 @@ class Editor extends EventEmitter {
|
|
|
2226
2235
|
const collaborators = this.getCollaborators();
|
|
2227
2236
|
let leaderPresence = null;
|
|
2228
2237
|
while (targetUserId && !visited.includes(targetUserId)) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2238
|
+
const nextPresence = collaborators.find((c) => c.userId === targetUserId);
|
|
2239
|
+
if (!nextPresence) break;
|
|
2240
|
+
leaderPresence = nextPresence;
|
|
2241
|
+
targetUserId = nextPresence.followingUserId ?? null;
|
|
2242
|
+
visited.push(nextPresence.userId);
|
|
2234
2243
|
}
|
|
2235
2244
|
return leaderPresence;
|
|
2236
2245
|
}
|
|
@@ -2293,39 +2302,7 @@ class Editor extends EventEmitter {
|
|
|
2293
2302
|
*
|
|
2294
2303
|
* @public */
|
|
2295
2304
|
getInitialZoom() {
|
|
2296
|
-
|
|
2297
|
-
if (!cameraOptions.constraints) return 1;
|
|
2298
|
-
if (cameraOptions.constraints.initialZoom === "default") return 1;
|
|
2299
|
-
const { zx, zy } = getCameraFitXFitY(this, cameraOptions);
|
|
2300
|
-
switch (cameraOptions.constraints.initialZoom) {
|
|
2301
|
-
case "fit-min": {
|
|
2302
|
-
return Math.max(zx, zy);
|
|
2303
|
-
}
|
|
2304
|
-
case "fit-max": {
|
|
2305
|
-
return Math.min(zx, zy);
|
|
2306
|
-
}
|
|
2307
|
-
case "fit-x": {
|
|
2308
|
-
return zx;
|
|
2309
|
-
}
|
|
2310
|
-
case "fit-y": {
|
|
2311
|
-
return zy;
|
|
2312
|
-
}
|
|
2313
|
-
case "fit-min-100": {
|
|
2314
|
-
return Math.min(1, Math.max(zx, zy));
|
|
2315
|
-
}
|
|
2316
|
-
case "fit-max-100": {
|
|
2317
|
-
return Math.min(1, Math.min(zx, zy));
|
|
2318
|
-
}
|
|
2319
|
-
case "fit-x-100": {
|
|
2320
|
-
return Math.min(1, zx);
|
|
2321
|
-
}
|
|
2322
|
-
case "fit-y-100": {
|
|
2323
|
-
return Math.min(1, zy);
|
|
2324
|
-
}
|
|
2325
|
-
default: {
|
|
2326
|
-
throw exhaustiveSwitchError(cameraOptions.constraints.initialZoom);
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2305
|
+
return this._getFitZoom(this.getCameraOptions().constraints?.initialZoom ?? "default");
|
|
2329
2306
|
}
|
|
2330
2307
|
/**
|
|
2331
2308
|
* Get the camera's base level for calculating actual zoom levels based on the zoom steps.
|
|
@@ -2337,11 +2314,13 @@ class Editor extends EventEmitter {
|
|
|
2337
2314
|
*
|
|
2338
2315
|
* @public */
|
|
2339
2316
|
getBaseZoom() {
|
|
2317
|
+
return this._getFitZoom(this.getCameraOptions().constraints?.baseZoom ?? "default");
|
|
2318
|
+
}
|
|
2319
|
+
_getFitZoom(fit) {
|
|
2340
2320
|
const cameraOptions = this.getCameraOptions();
|
|
2341
|
-
if (!cameraOptions.constraints) return 1;
|
|
2342
|
-
if (cameraOptions.constraints.baseZoom === "default") return 1;
|
|
2321
|
+
if (!cameraOptions.constraints || fit === "default") return 1;
|
|
2343
2322
|
const { zx, zy } = getCameraFitXFitY(this, cameraOptions);
|
|
2344
|
-
switch (
|
|
2323
|
+
switch (fit) {
|
|
2345
2324
|
case "fit-min": {
|
|
2346
2325
|
return Math.max(zx, zy);
|
|
2347
2326
|
}
|
|
@@ -2367,7 +2346,7 @@ class Editor extends EventEmitter {
|
|
|
2367
2346
|
return Math.min(1, zy);
|
|
2368
2347
|
}
|
|
2369
2348
|
default: {
|
|
2370
|
-
throw exhaustiveSwitchError(
|
|
2349
|
+
throw exhaustiveSwitchError(fit);
|
|
2371
2350
|
}
|
|
2372
2351
|
}
|
|
2373
2352
|
}
|
|
@@ -2401,7 +2380,7 @@ class Editor extends EventEmitter {
|
|
|
2401
2380
|
...this._cameraOptions.__unsafe__getWithoutCapture(),
|
|
2402
2381
|
...opts
|
|
2403
2382
|
});
|
|
2404
|
-
if (next.zoomSteps
|
|
2383
|
+
if (!next.zoomSteps || next.zoomSteps.length < 1) next.zoomSteps = [1];
|
|
2405
2384
|
this._cameraOptions.set(next);
|
|
2406
2385
|
this.setCamera(this.getCamera());
|
|
2407
2386
|
return this;
|
|
@@ -2422,8 +2401,8 @@ class Editor extends EventEmitter {
|
|
|
2422
2401
|
const vsb = this.getViewportScreenBounds();
|
|
2423
2402
|
if (cameraOptions.constraints) {
|
|
2424
2403
|
const { constraints } = cameraOptions;
|
|
2425
|
-
const
|
|
2426
|
-
const
|
|
2404
|
+
const px = Math.min(constraints.padding.x, vsb.w / 2);
|
|
2405
|
+
const py = Math.min(constraints.padding.y, vsb.h / 2);
|
|
2427
2406
|
const bounds = Box.From(cameraOptions.constraints.bounds);
|
|
2428
2407
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
2429
2408
|
const zy = (vsb.h - py * 2) / bounds.h;
|
|
@@ -2462,12 +2441,12 @@ class Editor extends EventEmitter {
|
|
|
2462
2441
|
break;
|
|
2463
2442
|
}
|
|
2464
2443
|
case "inside": {
|
|
2465
|
-
if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w);
|
|
2444
|
+
if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w - bounds.x);
|
|
2466
2445
|
else x = clamp(x, minX + freeW, minX);
|
|
2467
2446
|
break;
|
|
2468
2447
|
}
|
|
2469
2448
|
case "outside": {
|
|
2470
|
-
x = clamp(x, px / z - bounds.w, (vsb.w - px) / z);
|
|
2449
|
+
x = clamp(x, px / z - bounds.w - bounds.x, (vsb.w - px) / z - bounds.x);
|
|
2471
2450
|
break;
|
|
2472
2451
|
}
|
|
2473
2452
|
case "free": {
|
|
@@ -2488,12 +2467,12 @@ class Editor extends EventEmitter {
|
|
|
2488
2467
|
break;
|
|
2489
2468
|
}
|
|
2490
2469
|
case "inside": {
|
|
2491
|
-
if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h);
|
|
2470
|
+
if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h - bounds.y);
|
|
2492
2471
|
else y = clamp(y, minY + freeH, minY);
|
|
2493
2472
|
break;
|
|
2494
2473
|
}
|
|
2495
2474
|
case "outside": {
|
|
2496
|
-
y = clamp(y, py / z - bounds.h, (vsb.h - py) / z);
|
|
2475
|
+
y = clamp(y, py / z - bounds.h - bounds.y, (vsb.h - py) / z - bounds.y);
|
|
2497
2476
|
break;
|
|
2498
2477
|
}
|
|
2499
2478
|
case "free": {
|
|
@@ -2861,9 +2840,9 @@ class Editor extends EventEmitter {
|
|
|
2861
2840
|
}
|
|
2862
2841
|
const remaining = duration - elapsed;
|
|
2863
2842
|
const t = easing(1 - remaining / duration);
|
|
2864
|
-
const left = start.minX
|
|
2865
|
-
const top = start.minY
|
|
2866
|
-
const right = start.maxX
|
|
2843
|
+
const left = lerp(start.minX, end.minX, t);
|
|
2844
|
+
const top = lerp(start.minY, end.minY, t);
|
|
2845
|
+
const right = lerp(start.maxX, end.maxX, t);
|
|
2867
2846
|
this._setCamera(new Vec(-left, -top, this.getViewportScreenBounds().width / (right - left)), {
|
|
2868
2847
|
force: true
|
|
2869
2848
|
});
|
|
@@ -2941,12 +2920,12 @@ class Editor extends EventEmitter {
|
|
|
2941
2920
|
let newCy = cy + dy;
|
|
2942
2921
|
let newCz = cz;
|
|
2943
2922
|
if (dirZ !== 0) {
|
|
2944
|
-
newCz = cz * (
|
|
2923
|
+
newCz = cz * Math.exp(dirZ * currentSpeed * elapsed);
|
|
2945
2924
|
const center = this.getViewportScreenCenter();
|
|
2946
2925
|
newCx += center.x / newCz - center.x / cz;
|
|
2947
2926
|
newCy += center.y / newCz - center.y / cz;
|
|
2948
2927
|
}
|
|
2949
|
-
currentSpeed *= 1 - friction;
|
|
2928
|
+
currentSpeed *= (1 - friction) ** (elapsed / FRAME_MS_60HZ);
|
|
2950
2929
|
if (currentSpeed < speedThreshold) {
|
|
2951
2930
|
cancel();
|
|
2952
2931
|
} else {
|
|
@@ -3379,12 +3358,12 @@ class Editor extends EventEmitter {
|
|
|
3379
3358
|
const renderingShapes = [];
|
|
3380
3359
|
let nextIndex = this.options.maxShapesPerPage * 2;
|
|
3381
3360
|
let nextBackgroundIndex = this.options.maxShapesPerPage;
|
|
3382
|
-
const erasingShapeIds = this.getErasingShapeIds();
|
|
3361
|
+
const erasingShapeIds = new Set(this.getErasingShapeIds());
|
|
3383
3362
|
const addShapeById = (id, opacity, isAncestorErasing) => {
|
|
3384
3363
|
const shape = this.getShape(id);
|
|
3385
3364
|
if (!shape) return;
|
|
3386
3365
|
if (this.isShapeHidden(shape)) {
|
|
3387
|
-
const isErasing = isAncestorErasing || erasingShapeIds.
|
|
3366
|
+
const isErasing = isAncestorErasing || erasingShapeIds.has(id);
|
|
3388
3367
|
for (const childId of this.getSortedChildIdsForParent(id)) {
|
|
3389
3368
|
addShapeById(childId, opacity, isErasing);
|
|
3390
3369
|
}
|
|
@@ -3394,7 +3373,7 @@ class Editor extends EventEmitter {
|
|
|
3394
3373
|
let isShapeErasing = false;
|
|
3395
3374
|
const util = this.getShapeUtil(shape);
|
|
3396
3375
|
if (useEditorState) {
|
|
3397
|
-
isShapeErasing = !isAncestorErasing && erasingShapeIds.
|
|
3376
|
+
isShapeErasing = !isAncestorErasing && erasingShapeIds.has(id);
|
|
3398
3377
|
if (isShapeErasing) {
|
|
3399
3378
|
opacity *= 0.32;
|
|
3400
3379
|
}
|
|
@@ -3986,10 +3965,8 @@ class Editor extends EventEmitter {
|
|
|
3986
3965
|
}
|
|
3987
3966
|
_getShapePageBoundsCache() {
|
|
3988
3967
|
return this.store.createComputedCache("pageBoundsCache", (shape) => {
|
|
3989
|
-
const pageTransform = this.getShapePageTransform(shape);
|
|
3990
|
-
if (!pageTransform) return void 0;
|
|
3991
3968
|
return Box.FromPoints(
|
|
3992
|
-
|
|
3969
|
+
this.getShapePageTransform(shape).applyToPoints(this.getShapeGeometry(shape).boundsVertices)
|
|
3993
3970
|
);
|
|
3994
3971
|
});
|
|
3995
3972
|
}
|
|
@@ -4107,7 +4084,9 @@ class Editor extends EventEmitter {
|
|
|
4107
4084
|
if (pageMask) {
|
|
4108
4085
|
if (pageMask.length === 0) return void 0;
|
|
4109
4086
|
const { corners } = pageBounds;
|
|
4110
|
-
if (corners.every((p, i) =>
|
|
4087
|
+
if (pageMask.length === corners.length && corners.every((p, i) => Vec.Equals(p, pageMask[i]))) {
|
|
4088
|
+
return pageBounds.clone();
|
|
4089
|
+
}
|
|
4111
4090
|
const intersection = intersectPolygonPolygon(pageMask, corners);
|
|
4112
4091
|
if (!intersection) return;
|
|
4113
4092
|
return Box.FromPoints(intersection);
|
|
@@ -4331,23 +4310,22 @@ class Editor extends EventEmitter {
|
|
|
4331
4310
|
let inMarginClosestToEdgeHit = null;
|
|
4332
4311
|
const searchMargin = Math.max(innerMargin, outerMargin, this.getHitTestMargin());
|
|
4333
4312
|
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, searchMargin);
|
|
4334
|
-
const shapesToCheck =
|
|
4335
|
-
if (!candidateIds.has(shape.id) && !this.isShapeFrameLike(shape)) return false;
|
|
4336
|
-
if (shape.isLocked && !hitLocked || this.isShapeHidden(shape) || this.isShapeOfType(shape, "group"))
|
|
4337
|
-
return false;
|
|
4338
|
-
const pageMask = this.getShapeMask(shape);
|
|
4339
|
-
if (pageMask && !pointInPolygon(point, pageMask)) return false;
|
|
4340
|
-
if (filter && !filter(shape)) return false;
|
|
4341
|
-
return true;
|
|
4342
|
-
});
|
|
4313
|
+
const shapesToCheck = opts.renderingOnly ? this.getCurrentPageRenderingShapesSorted() : this.getCurrentPageShapesSorted();
|
|
4343
4314
|
for (let i = shapesToCheck.length - 1; i >= 0; i--) {
|
|
4344
4315
|
const shape = shapesToCheck[i];
|
|
4316
|
+
if (!candidateIds.has(shape.id) && !this.isShapeFrameLike(shape)) continue;
|
|
4317
|
+
if (shape.isLocked && !hitLocked || this.isShapeHidden(shape) || this.isShapeOfType(shape, "group")) {
|
|
4318
|
+
continue;
|
|
4319
|
+
}
|
|
4320
|
+
const pageMask = this.getShapeMask(shape);
|
|
4321
|
+
if (pageMask && !pointInPolygon(point, pageMask)) continue;
|
|
4322
|
+
if (filter && !filter(shape)) continue;
|
|
4345
4323
|
const geometry = this.getShapeGeometry(shape);
|
|
4346
4324
|
const isGroup = geometry instanceof Group2d;
|
|
4347
4325
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
4348
4326
|
const shapeUtil = this.getShapeUtil(shape);
|
|
4349
4327
|
const isShapeFrameLike = this.isShapeFrameLike(shape);
|
|
4350
|
-
if (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim()) {
|
|
4328
|
+
if (isGroup && (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim())) {
|
|
4351
4329
|
for (const childGeometry of geometry.children) {
|
|
4352
4330
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
4353
4331
|
return shape;
|
|
@@ -4446,11 +4424,15 @@ class Editor extends EventEmitter {
|
|
|
4446
4424
|
getShapesAtPoint(point, opts = {}) {
|
|
4447
4425
|
const margin = opts.margin ?? 0;
|
|
4448
4426
|
const candidateIds = this._spatialIndex.getShapeIdsAtPoint(point, margin);
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4427
|
+
const sorted = this.getCurrentPageShapesSorted();
|
|
4428
|
+
const result = [];
|
|
4429
|
+
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
4430
|
+
const shape = sorted[i];
|
|
4431
|
+
if (this.isShapeHidden(shape)) continue;
|
|
4432
|
+
if (!candidateIds.has(shape.id) && !this.isShapeFrameLike(shape)) continue;
|
|
4433
|
+
if (this.isPointInShape(shape, point, opts)) result.push(shape);
|
|
4434
|
+
}
|
|
4435
|
+
return result;
|
|
4454
4436
|
}
|
|
4455
4437
|
/**
|
|
4456
4438
|
* Get shape IDs within the given bounds.
|
|
@@ -4535,9 +4517,7 @@ class Editor extends EventEmitter {
|
|
|
4535
4517
|
const freshShape = this.getShape(id);
|
|
4536
4518
|
if (!freshShape) return new Vec(0, 0);
|
|
4537
4519
|
if (isPageId(freshShape.parentId)) return Vec.From(point);
|
|
4538
|
-
|
|
4539
|
-
if (!parentTransform) return Vec.From(point);
|
|
4540
|
-
return parentTransform.clone().invert().applyToPoint(point);
|
|
4520
|
+
return this.getShapePageTransform(freshShape.parentId).clone().invert().applyToPoint(point);
|
|
4541
4521
|
}
|
|
4542
4522
|
getCurrentPageShapes() {
|
|
4543
4523
|
return Array.from(this.getCurrentPageShapeIds(), (id) => this.store.get(id));
|
|
@@ -4649,23 +4629,7 @@ class Editor extends EventEmitter {
|
|
|
4649
4629
|
* @public
|
|
4650
4630
|
*/
|
|
4651
4631
|
isShapeInPage(shape, pageId = this.getCurrentPageId()) {
|
|
4652
|
-
|
|
4653
|
-
const shapeToCheck = this.getShape(id);
|
|
4654
|
-
if (!shapeToCheck) return false;
|
|
4655
|
-
let shapeIsInPage = false;
|
|
4656
|
-
if (shapeToCheck.parentId === pageId) {
|
|
4657
|
-
shapeIsInPage = true;
|
|
4658
|
-
} else {
|
|
4659
|
-
let parent = this.getShape(shapeToCheck.parentId);
|
|
4660
|
-
isInPageSearch: while (parent) {
|
|
4661
|
-
if (parent.parentId === pageId) {
|
|
4662
|
-
shapeIsInPage = true;
|
|
4663
|
-
break isInPageSearch;
|
|
4664
|
-
}
|
|
4665
|
-
parent = this.getShape(parent.parentId);
|
|
4666
|
-
}
|
|
4667
|
-
}
|
|
4668
|
-
return shapeIsInPage;
|
|
4632
|
+
return this.getAncestorPageId(shape) === pageId;
|
|
4669
4633
|
}
|
|
4670
4634
|
/**
|
|
4671
4635
|
* Get the id of the containing page for a given shape.
|
|
@@ -4746,10 +4710,7 @@ class Editor extends EventEmitter {
|
|
|
4746
4710
|
for (let i = 0; i < shapesToReparent.length; i++) {
|
|
4747
4711
|
const shape = shapesToReparent[i];
|
|
4748
4712
|
const pageTransform = this.getShapePageTransform(shape);
|
|
4749
|
-
|
|
4750
|
-
const pagePoint = pageTransform.point();
|
|
4751
|
-
if (!pagePoint) continue;
|
|
4752
|
-
const newPoint = invertedParentTransform.applyToPoint(pagePoint);
|
|
4713
|
+
const newPoint = invertedParentTransform.applyToPoint(pageTransform.point());
|
|
4753
4714
|
const newRotation = pageTransform.rotation() - parentPageRotation;
|
|
4754
4715
|
if (shape.id === parentId) {
|
|
4755
4716
|
throw Error("Attempted to reparent a shape to itself!");
|
|
@@ -4838,7 +4799,7 @@ class Editor extends EventEmitter {
|
|
|
4838
4799
|
*/
|
|
4839
4800
|
getShapeAndDescendantIds(ids) {
|
|
4840
4801
|
const shapeIds = /* @__PURE__ */ new Set();
|
|
4841
|
-
for (const shape of ids.map((id) => this.getShape(id)).sort(sortByIndex)) {
|
|
4802
|
+
for (const shape of compact(ids.map((id) => this.getShape(id))).sort(sortByIndex)) {
|
|
4842
4803
|
shapeIds.add(shape.id);
|
|
4843
4804
|
this.visitDescendants(shape, (descendantId) => {
|
|
4844
4805
|
shapeIds.add(descendantId);
|
|
@@ -4860,11 +4821,12 @@ class Editor extends EventEmitter {
|
|
|
4860
4821
|
const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
|
|
4861
4822
|
(s) => !s.isLocked && !this.isShapeHidden(s)
|
|
4862
4823
|
);
|
|
4824
|
+
const excludedIds = this.getShapeAndDescendantIds(draggingShapes.map((s) => s.id));
|
|
4863
4825
|
const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
|
|
4864
4826
|
hitInside: true,
|
|
4865
4827
|
margin: 0
|
|
4866
4828
|
}).filter(
|
|
4867
|
-
(s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !
|
|
4829
|
+
(s) => !droppingShapes.includes(s) && !s.isLocked && !this.isShapeHidden(s) && !excludedIds.has(s.id)
|
|
4868
4830
|
);
|
|
4869
4831
|
for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
|
|
4870
4832
|
const shapeUtil = this.getShapeUtil(maybeDraggingOverShape);
|
|
@@ -5117,8 +5079,7 @@ class Editor extends EventEmitter {
|
|
|
5117
5079
|
for (const id of ids) {
|
|
5118
5080
|
const shape = this.getShape(id);
|
|
5119
5081
|
const localDelta = Vec.From(offset);
|
|
5120
|
-
|
|
5121
|
-
if (parentTransform) localDelta.rot(-parentTransform.rotation());
|
|
5082
|
+
localDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5122
5083
|
changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
|
|
5123
5084
|
}
|
|
5124
5085
|
this.updateShapes(changes);
|
|
@@ -5173,7 +5134,7 @@ class Editor extends EventEmitter {
|
|
|
5173
5134
|
if (!originalShape) continue;
|
|
5174
5135
|
let ox = 0;
|
|
5175
5136
|
let oy = 0;
|
|
5176
|
-
if (offset && initialIds.has(originalId)) {
|
|
5137
|
+
if (offset && initialIds.has(originalId) && !shapeIdSet.has(originalShape.parentId)) {
|
|
5177
5138
|
const parentTransform = this.getShapeParentTransform(originalShape);
|
|
5178
5139
|
const vec = new Vec(offset.x, offset.y).rot(-parentTransform.rotation());
|
|
5179
5140
|
ox = vec.x;
|
|
@@ -5287,26 +5248,17 @@ class Editor extends EventEmitter {
|
|
|
5287
5248
|
toggleLock(shapes) {
|
|
5288
5249
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5289
5250
|
if (this.getIsReadonly() || ids.length === 0) return this;
|
|
5290
|
-
let allLocked = true
|
|
5251
|
+
let allLocked = true;
|
|
5291
5252
|
const shapesToToggle = [];
|
|
5292
5253
|
for (const id of ids) {
|
|
5293
5254
|
const shape = this.getShape(id);
|
|
5294
5255
|
if (shape) {
|
|
5295
5256
|
shapesToToggle.push(shape);
|
|
5296
|
-
if (shape.isLocked)
|
|
5297
|
-
allUnlocked = false;
|
|
5298
|
-
} else {
|
|
5299
|
-
allLocked = false;
|
|
5300
|
-
}
|
|
5257
|
+
if (!shape.isLocked) allLocked = false;
|
|
5301
5258
|
}
|
|
5302
5259
|
}
|
|
5303
5260
|
this.run(() => {
|
|
5304
|
-
if (
|
|
5305
|
-
this.updateShapes(
|
|
5306
|
-
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5307
|
-
);
|
|
5308
|
-
this.setSelectedShapes([]);
|
|
5309
|
-
} else if (allLocked) {
|
|
5261
|
+
if (allLocked) {
|
|
5310
5262
|
this.updateShapes(
|
|
5311
5263
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: false }))
|
|
5312
5264
|
);
|
|
@@ -5314,6 +5266,7 @@ class Editor extends EventEmitter {
|
|
|
5314
5266
|
this.updateShapes(
|
|
5315
5267
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5316
5268
|
);
|
|
5269
|
+
this.setSelectedShapes([]);
|
|
5317
5270
|
}
|
|
5318
5271
|
});
|
|
5319
5272
|
return this;
|
|
@@ -5424,9 +5377,10 @@ class Editor extends EventEmitter {
|
|
|
5424
5377
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5425
5378
|
let freshShapes = compact(ids.map((id) => this.getShape(id)));
|
|
5426
5379
|
if (opts?.filterAxisAligned) {
|
|
5427
|
-
freshShapes = freshShapes.filter(
|
|
5428
|
-
|
|
5429
|
-
|
|
5380
|
+
freshShapes = freshShapes.filter((s) => {
|
|
5381
|
+
const remainder = Math.abs(this.getShapePageTransform(s).rotation() % HALF_PI);
|
|
5382
|
+
return Math.min(remainder, HALF_PI - remainder) < 1e-9;
|
|
5383
|
+
});
|
|
5430
5384
|
}
|
|
5431
5385
|
const clusters = [];
|
|
5432
5386
|
const allBounds = [];
|
|
@@ -5591,9 +5545,9 @@ class Editor extends EventEmitter {
|
|
|
5591
5545
|
dim = "height";
|
|
5592
5546
|
}
|
|
5593
5547
|
let shapeGap = 0;
|
|
5548
|
+
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5594
5549
|
if (_gap === 0) {
|
|
5595
5550
|
const gaps = {};
|
|
5596
|
-
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5597
5551
|
for (let i = 0; i < len - 1; i++) {
|
|
5598
5552
|
const currCluster = shapeClustersToStack[i];
|
|
5599
5553
|
const nextCluster = shapeClustersToStack[i + 1];
|
|
@@ -5631,8 +5585,7 @@ class Editor extends EventEmitter {
|
|
|
5631
5585
|
const shapeDelta = delta.clone();
|
|
5632
5586
|
const parent = this.getShapeParent(shape);
|
|
5633
5587
|
if (parent) {
|
|
5634
|
-
|
|
5635
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5588
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5636
5589
|
}
|
|
5637
5590
|
shapeDelta.add(shape);
|
|
5638
5591
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5670,7 +5623,7 @@ class Editor extends EventEmitter {
|
|
|
5670
5623
|
}
|
|
5671
5624
|
const commonBounds = Box.Common(allBounds);
|
|
5672
5625
|
const maxWidth = commonBounds.width;
|
|
5673
|
-
shapeClustersToPack.sort((a, b) =>
|
|
5626
|
+
shapeClustersToPack.sort((a, b) => b.pageBounds.width - a.pageBounds.width).sort((a, b) => b.pageBounds.height - a.pageBounds.height);
|
|
5674
5627
|
const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
|
|
5675
5628
|
const spaces = [new Box(commonBounds.x, commonBounds.y, startWidth, Infinity)];
|
|
5676
5629
|
let width = 0;
|
|
@@ -5718,8 +5671,7 @@ class Editor extends EventEmitter {
|
|
|
5718
5671
|
const shapeDelta = delta.clone();
|
|
5719
5672
|
const parent = this.getShapeParent(shape);
|
|
5720
5673
|
if (parent) {
|
|
5721
|
-
|
|
5722
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5674
|
+
shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5723
5675
|
}
|
|
5724
5676
|
shapeDelta.add(shape);
|
|
5725
5677
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5785,8 +5737,7 @@ class Editor extends EventEmitter {
|
|
|
5785
5737
|
const shapeDelta = delta.clone();
|
|
5786
5738
|
const parent = this.getShapeParent(shape);
|
|
5787
5739
|
if (parent) {
|
|
5788
|
-
|
|
5789
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5740
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5790
5741
|
}
|
|
5791
5742
|
shapeDelta.add(shape);
|
|
5792
5743
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5860,8 +5811,7 @@ class Editor extends EventEmitter {
|
|
|
5860
5811
|
const shapeDelta = delta.clone();
|
|
5861
5812
|
const parent = this.getShapeParent(shape);
|
|
5862
5813
|
if (parent) {
|
|
5863
|
-
|
|
5864
|
-
if (parentTransform) shapeDelta.rot(-parentTransform.rotation());
|
|
5814
|
+
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5865
5815
|
}
|
|
5866
5816
|
shapeDelta.add(shape);
|
|
5867
5817
|
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
@@ -5916,8 +5866,7 @@ class Editor extends EventEmitter {
|
|
|
5916
5866
|
scale[val] = commonBounds[dim] / pageBounds[dim];
|
|
5917
5867
|
for (const shape of shapes2) {
|
|
5918
5868
|
const shapeLocalOffset = localOffset.clone();
|
|
5919
|
-
|
|
5920
|
-
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation());
|
|
5869
|
+
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5921
5870
|
shapeLocalOffset.add(shape);
|
|
5922
5871
|
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5923
5872
|
this.updateShape(changes);
|
|
@@ -5973,8 +5922,7 @@ class Editor extends EventEmitter {
|
|
|
5973
5922
|
);
|
|
5974
5923
|
for (const shape of shapes2) {
|
|
5975
5924
|
const shapeLocalOffset = localOffset.clone();
|
|
5976
|
-
|
|
5977
|
-
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation());
|
|
5925
|
+
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5978
5926
|
shapeLocalOffset.add(shape);
|
|
5979
5927
|
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5980
5928
|
this.updateShape(changes);
|
|
@@ -6023,9 +5971,7 @@ class Editor extends EventEmitter {
|
|
|
6023
5971
|
const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center;
|
|
6024
5972
|
if (!scaleOrigin) return null;
|
|
6025
5973
|
const pageTransform = opts.initialPageTransform ? Mat.Cast(opts.initialPageTransform) : this.getShapePageTransform(id);
|
|
6026
|
-
if (!pageTransform) return null;
|
|
6027
5974
|
const pageRotation = pageTransform.rotation();
|
|
6028
|
-
if (pageRotation == null) return null;
|
|
6029
5975
|
const scaleAxisRotation = opts.scaleAxisRotation ?? pageRotation;
|
|
6030
5976
|
const initialBounds = opts.initialBounds ?? this.getShapeGeometry(id).bounds;
|
|
6031
5977
|
if (!initialBounds) return null;
|
|
@@ -6176,7 +6122,6 @@ class Editor extends EventEmitter {
|
|
|
6176
6122
|
const currentLocalBounds = this.getShapeGeometry(id).bounds;
|
|
6177
6123
|
const currentPageCenter = Mat.applyToPoint(pageTransform, currentLocalBounds.center);
|
|
6178
6124
|
const shapePageTransformOrigin = pageTransform.point();
|
|
6179
|
-
if (!currentPageCenter || !shapePageTransformOrigin) return this;
|
|
6180
6125
|
const pageDelta = Vec.Sub(postScaleShapePageCenter, currentPageCenter);
|
|
6181
6126
|
const postScaleShapePagePoint = Vec.Add(shapePageTransformOrigin, pageDelta);
|
|
6182
6127
|
const { x, y } = this.getPointInParentSpace(id, postScaleShapePagePoint);
|
|
@@ -6435,10 +6380,10 @@ class Editor extends EventEmitter {
|
|
|
6435
6380
|
if (animationIdForShape !== animationId) continue;
|
|
6436
6381
|
updates.push({
|
|
6437
6382
|
...end,
|
|
6438
|
-
x: start.x
|
|
6439
|
-
y: start.y
|
|
6440
|
-
opacity: start.opacity
|
|
6441
|
-
rotation: start.rotation
|
|
6383
|
+
x: lerp(start.x, end.x, t),
|
|
6384
|
+
y: lerp(start.y, end.y, t),
|
|
6385
|
+
opacity: lerp(start.opacity, end.opacity, t),
|
|
6386
|
+
rotation: lerp(start.rotation, end.rotation, t),
|
|
6442
6387
|
props: this.getShapeUtil(end).getInterpolatedProps?.(start, end, t) ?? end.props
|
|
6443
6388
|
});
|
|
6444
6389
|
}
|
|
@@ -6564,7 +6509,7 @@ class Editor extends EventEmitter {
|
|
|
6564
6509
|
* @public
|
|
6565
6510
|
*/
|
|
6566
6511
|
updateShapes(partials) {
|
|
6567
|
-
const compactedPartials =
|
|
6512
|
+
const compactedPartials = [];
|
|
6568
6513
|
for (let i = 0, n = partials.length; i < n; i++) {
|
|
6569
6514
|
const partial = partials[i];
|
|
6570
6515
|
if (!partial) continue;
|
|
@@ -6635,28 +6580,32 @@ class Editor extends EventEmitter {
|
|
|
6635
6580
|
}
|
|
6636
6581
|
/* --------------------- Styles --------------------- */
|
|
6637
6582
|
/**
|
|
6638
|
-
*
|
|
6583
|
+
* Groups have no styles of their own: a style read or write on a selection applies to the
|
|
6584
|
+
* non-group shapes beneath each group, however deeply nested. Returns those shapes.
|
|
6639
6585
|
*
|
|
6640
6586
|
* @internal
|
|
6641
6587
|
*/
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
if (
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6588
|
+
_getStyleableShapes(shapes) {
|
|
6589
|
+
const result = [];
|
|
6590
|
+
const visit = (shape) => {
|
|
6591
|
+
if (this.isShapeOfType(shape, "group")) {
|
|
6592
|
+
for (const childId of this.getSortedChildIdsForParent(shape.id)) {
|
|
6593
|
+
const child = this.getShape(childId);
|
|
6594
|
+
if (child) visit(child);
|
|
6595
|
+
}
|
|
6596
|
+
} else {
|
|
6597
|
+
result.push(shape);
|
|
6652
6598
|
}
|
|
6653
|
-
}
|
|
6599
|
+
};
|
|
6600
|
+
for (const shape of shapes) visit(shape);
|
|
6601
|
+
return result;
|
|
6654
6602
|
}
|
|
6655
6603
|
_getSelectionSharedStyles() {
|
|
6656
|
-
const selectedShapes = this.getSelectedShapes();
|
|
6657
6604
|
const sharedStyles = new SharedStyleMap();
|
|
6658
|
-
for (const
|
|
6659
|
-
|
|
6605
|
+
for (const shape of this._getStyleableShapes(this.getSelectedShapes())) {
|
|
6606
|
+
for (const [style, propKey] of this.styleProps[shape.type]) {
|
|
6607
|
+
sharedStyles.applyValue(style, getOwnProperty(shape.props, propKey));
|
|
6608
|
+
}
|
|
6660
6609
|
}
|
|
6661
6610
|
return sharedStyles;
|
|
6662
6611
|
}
|
|
@@ -6688,38 +6637,16 @@ class Editor extends EventEmitter {
|
|
|
6688
6637
|
const styles = new SharedStyleMap();
|
|
6689
6638
|
if (!currentTool) return styles;
|
|
6690
6639
|
if (currentTool.shapeType) {
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
if (style.id === "tldraw:color") continue;
|
|
6694
|
-
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6695
|
-
}
|
|
6696
|
-
} else {
|
|
6697
|
-
for (const style of this.styleProps[currentTool.shapeType].keys()) {
|
|
6698
|
-
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6699
|
-
}
|
|
6640
|
+
for (const style of this.styleProps[currentTool.shapeType].keys()) {
|
|
6641
|
+
styles.applyValue(style, this.getStyleForNextShape(style));
|
|
6700
6642
|
}
|
|
6701
6643
|
}
|
|
6702
6644
|
return styles;
|
|
6703
6645
|
}
|
|
6704
6646
|
getSharedOpacity() {
|
|
6705
6647
|
if (this.isIn("select") && this.getSelectedShapeIds().length > 0) {
|
|
6706
|
-
const shapesToCheck = [];
|
|
6707
|
-
const addShape = (shapeId) => {
|
|
6708
|
-
const shape = this.getShape(shapeId);
|
|
6709
|
-
if (!shape) return;
|
|
6710
|
-
if (this.isShapeOfType(shape, "group")) {
|
|
6711
|
-
for (const childId of this.getSortedChildIdsForParent(shape.id)) {
|
|
6712
|
-
addShape(childId);
|
|
6713
|
-
}
|
|
6714
|
-
} else {
|
|
6715
|
-
shapesToCheck.push(shape);
|
|
6716
|
-
}
|
|
6717
|
-
};
|
|
6718
|
-
for (const shapeId of this.getSelectedShapeIds()) {
|
|
6719
|
-
addShape(shapeId);
|
|
6720
|
-
}
|
|
6721
6648
|
let opacity = null;
|
|
6722
|
-
for (const shape of
|
|
6649
|
+
for (const shape of this._getStyleableShapes(this.getSelectedShapes())) {
|
|
6723
6650
|
if (opacity === null) {
|
|
6724
6651
|
opacity = shape.opacity;
|
|
6725
6652
|
} else if (opacity !== shape.opacity) {
|
|
@@ -6758,28 +6685,12 @@ class Editor extends EventEmitter {
|
|
|
6758
6685
|
setOpacityForSelectedShapes(opacity) {
|
|
6759
6686
|
const selectedShapes = this.getSelectedShapes();
|
|
6760
6687
|
if (selectedShapes.length > 0) {
|
|
6761
|
-
const shapesToUpdate = [];
|
|
6762
|
-
const addShapeById = (shape) => {
|
|
6763
|
-
if (this.isShapeOfType(shape, "group")) {
|
|
6764
|
-
const childIds = this.getSortedChildIdsForParent(shape);
|
|
6765
|
-
for (const childId of childIds) {
|
|
6766
|
-
addShapeById(this.getShape(childId));
|
|
6767
|
-
}
|
|
6768
|
-
} else {
|
|
6769
|
-
shapesToUpdate.push(shape);
|
|
6770
|
-
}
|
|
6771
|
-
};
|
|
6772
|
-
for (const id of selectedShapes) {
|
|
6773
|
-
addShapeById(id);
|
|
6774
|
-
}
|
|
6775
6688
|
this.updateShapes(
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
};
|
|
6782
|
-
})
|
|
6689
|
+
this._getStyleableShapes(selectedShapes).map((shape) => ({
|
|
6690
|
+
id: shape.id,
|
|
6691
|
+
type: shape.type,
|
|
6692
|
+
opacity
|
|
6693
|
+
}))
|
|
6783
6694
|
);
|
|
6784
6695
|
}
|
|
6785
6696
|
return this;
|
|
@@ -6824,33 +6735,17 @@ class Editor extends EventEmitter {
|
|
|
6824
6735
|
const selectedShapes = this.getSelectedShapes();
|
|
6825
6736
|
if (selectedShapes.length > 0) {
|
|
6826
6737
|
const updates = [];
|
|
6827
|
-
const
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
const stylePropKey = this.styleProps[shape.type].get(style);
|
|
6836
|
-
if (stylePropKey) {
|
|
6837
|
-
const shapePartial = {
|
|
6838
|
-
id: shape.id,
|
|
6839
|
-
type: shape.type,
|
|
6840
|
-
props: { [stylePropKey]: value }
|
|
6841
|
-
};
|
|
6842
|
-
updates.push({
|
|
6843
|
-
util,
|
|
6844
|
-
originalShape: shape,
|
|
6845
|
-
updatePartial: shapePartial
|
|
6846
|
-
});
|
|
6847
|
-
}
|
|
6738
|
+
for (const shape of this._getStyleableShapes(selectedShapes)) {
|
|
6739
|
+
const stylePropKey = this.styleProps[shape.type].get(style);
|
|
6740
|
+
if (stylePropKey) {
|
|
6741
|
+
updates.push({
|
|
6742
|
+
id: shape.id,
|
|
6743
|
+
type: shape.type,
|
|
6744
|
+
props: { [stylePropKey]: value }
|
|
6745
|
+
});
|
|
6848
6746
|
}
|
|
6849
|
-
};
|
|
6850
|
-
for (const shape of selectedShapes) {
|
|
6851
|
-
addShapeById(shape);
|
|
6852
6747
|
}
|
|
6853
|
-
this.updateShapes(updates
|
|
6748
|
+
this.updateShapes(updates);
|
|
6854
6749
|
}
|
|
6855
6750
|
return this;
|
|
6856
6751
|
}
|
|
@@ -7246,7 +7141,6 @@ class Editor extends EventEmitter {
|
|
|
7246
7141
|
if (shapeIdMap.has(newShape.parentId)) {
|
|
7247
7142
|
newShape.parentId = shapeIdMap.get(oldShape.parentId);
|
|
7248
7143
|
} else {
|
|
7249
|
-
rootShapeIds.push(newShape.id);
|
|
7250
7144
|
newShape.index = index;
|
|
7251
7145
|
index = getIndexAbove(index);
|
|
7252
7146
|
}
|
|
@@ -7271,8 +7165,11 @@ class Editor extends EventEmitter {
|
|
|
7271
7165
|
continue;
|
|
7272
7166
|
}
|
|
7273
7167
|
if (asset.type === "image" && asset.props.src?.startsWith("data:image") || asset.type === "video" && asset.props.src?.startsWith("data:video")) {
|
|
7274
|
-
assetsToUpdate.push(
|
|
7275
|
-
|
|
7168
|
+
assetsToUpdate.push(asset);
|
|
7169
|
+
const assetWithoutSrc = structuredClone(asset);
|
|
7170
|
+
assetWithoutSrc.props.src = null;
|
|
7171
|
+
assetsToCreate.push(assetWithoutSrc);
|
|
7172
|
+
continue;
|
|
7276
7173
|
}
|
|
7277
7174
|
assetsToCreate.push(asset);
|
|
7278
7175
|
}
|
|
@@ -8099,7 +7996,7 @@ class Editor extends EventEmitter {
|
|
|
8099
7996
|
if (info.type === "misc") {
|
|
8100
7997
|
if (info.name === "cancel" || info.name === "complete") {
|
|
8101
7998
|
this.inputs.setIsDragging(false);
|
|
8102
|
-
if (this.inputs.getIsPanning()) {
|
|
7999
|
+
if (this.inputs.getIsPanning() && !this.inputs.keys.has("Space")) {
|
|
8103
8000
|
this.inputs.setIsPanning(false);
|
|
8104
8001
|
this.inputs.setIsSpacebarPanning(false);
|
|
8105
8002
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
@@ -8851,10 +8748,9 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8851
8748
|
}
|
|
8852
8749
|
function getCameraFitXFitY(editor, cameraOptions) {
|
|
8853
8750
|
if (!cameraOptions.constraints) throw Error("Should have constraints here");
|
|
8854
|
-
const {
|
|
8855
|
-
padding: { x: px, y: py }
|
|
8856
|
-
} = cameraOptions.constraints;
|
|
8857
8751
|
const vsb = editor.getViewportScreenBounds();
|
|
8752
|
+
const px = Math.min(cameraOptions.constraints.padding.x, vsb.w / 2);
|
|
8753
|
+
const py = Math.min(cameraOptions.constraints.padding.y, vsb.h / 2);
|
|
8858
8754
|
const bounds = Box.From(cameraOptions.constraints.bounds);
|
|
8859
8755
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
8860
8756
|
const zy = (vsb.h - py * 2) / bounds.h;
|