@weasel-js/core 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +427 -0
- package/README.md +1 -1
- package/dist/animation/index.js +3 -3
- package/dist/animation/rig/bindRig.js +1 -1
- package/dist/animation/rig/rigNode.js.map +1 -1
- package/dist/barrel/canvas.js +7 -3
- package/dist/barrel/interactions.js +5 -4
- package/dist/barrel/paths.js +3 -3
- package/dist/barrel/renderer.js +3 -2
- package/dist/barrel/routing.js +6 -11
- package/dist/barrel/scene.js +8 -5
- package/dist/barrel/viewport.js +4 -3
- package/dist/canvas/Canvas.js +3 -1
- package/dist/canvas/Canvas.js.map +1 -1
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js +17 -3
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js.map +1 -1
- package/dist/canvas/SceneCanvas/builtinToolSets.js +30 -0
- package/dist/canvas/SceneCanvas/builtinToolSets.js.map +1 -0
- package/dist/canvas/SceneCanvas/canvasPassThrough.js +1 -0
- package/dist/canvas/SceneCanvas/canvasPassThrough.js.map +1 -1
- package/dist/canvas/SceneCanvas/coordTrace.js +5 -16
- package/dist/canvas/SceneCanvas/coordTrace.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js +5 -0
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
- package/dist/canvas/SceneCanvas/features.js +45 -5
- package/dist/canvas/SceneCanvas/features.js.map +1 -1
- package/dist/canvas/SceneCanvas/props.js +1 -11
- package/dist/canvas/SceneCanvas/props.js.map +1 -1
- package/dist/canvas/SceneCanvas/toolRegistry.js +8 -4
- package/dist/canvas/SceneCanvas/toolRegistry.js.map +1 -1
- package/dist/canvas/SceneCanvas/useActionsPropResolver.js +1 -11
- package/dist/canvas/SceneCanvas/useActionsPropResolver.js.map +1 -1
- package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useBuiltinTools.js +2 -9
- package/dist/canvas/SceneCanvas/useBuiltinTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useCanvasDevtoolsRoot.js +93 -0
- package/dist/canvas/SceneCanvas/useCanvasDevtoolsRoot.js.map +1 -0
- package/dist/canvas/SceneCanvas/useCanvasSelection.js +7 -2
- package/dist/canvas/SceneCanvas/useCanvasSelection.js.map +1 -1
- package/dist/canvas/SceneCanvas/useCanvasTools.js +8 -8
- package/dist/canvas/SceneCanvas/useCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useNodeKinds.js +1 -1
- package/dist/canvas/SceneCanvas/useNodeKinds.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js +13 -2
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +1 -3
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneChrome.js +6 -7
- package/dist/canvas/SceneCanvas/useSceneChrome.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js +5 -3
- package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js.map +1 -1
- package/dist/canvas/SceneCanvas/useScenePicking.js +2 -3
- package/dist/canvas/SceneCanvas/useScenePicking.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +2 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js +3 -4
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +16 -14
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/SurfaceCanvas.js +5 -22
- package/dist/canvas/SurfaceCanvas.js.map +1 -1
- package/dist/canvas/canvasRenderer.js +9 -5
- package/dist/canvas/canvasRenderer.js.map +1 -1
- package/dist/canvas/contextAttributes.js +14 -0
- package/dist/canvas/contextAttributes.js.map +1 -0
- package/dist/canvas/deps/editAnchors.js +9 -113
- package/dist/canvas/deps/editAnchors.js.map +1 -1
- package/dist/canvas/deps/insert.js +4 -2
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/pathEditCommits.js +193 -0
- package/dist/canvas/deps/pathEditCommits.js.map +1 -0
- package/dist/canvas/deps/snap.js +12 -9
- package/dist/canvas/deps/snap.js.map +1 -1
- package/dist/canvas/deps/transformFollowers.js +20 -0
- package/dist/canvas/deps/transformFollowers.js.map +1 -0
- package/dist/canvas/derivedPath.js +20 -1
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/drawnBounds.js +29 -3
- package/dist/canvas/drawnBounds.js.map +1 -1
- package/dist/canvas/nodeShapes/derivedPainter.js +9 -1
- package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/pathPainter.js +3 -2
- package/dist/canvas/nodeShapes/pathPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/shapePainter.js +1 -1
- package/dist/canvas/overlayRoleStrokes.js +12 -0
- package/dist/canvas/overlayRoleStrokes.js.map +1 -1
- package/dist/canvas/pathOverlay.js +27 -7
- package/dist/canvas/pathOverlay.js.map +1 -1
- package/dist/canvas/renderDebugSnapshot.js +1 -0
- package/dist/canvas/renderDebugSnapshot.js.map +1 -1
- package/dist/canvas/renderSceneToPixels.js +6 -5
- package/dist/canvas/renderSceneToPixels.js.map +1 -1
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/useCanvasPaint.js +2 -1
- package/dist/canvas/useCanvasPaint.js.map +1 -1
- package/dist/canvas/useInFlightBounds.js +52 -0
- package/dist/canvas/useInFlightBounds.js.map +1 -0
- package/dist/canvas/useViewHelpers.js +7 -9
- package/dist/canvas/useViewHelpers.js.map +1 -1
- package/dist/clipboard.d.ts +3 -2
- package/dist/{clone-DZDrfIlU.d.ts → clone-C3e0OTuF.d.ts} +8 -21
- package/dist/clone.d.ts +4 -3
- package/dist/core/geometry/autoPoseDescriptor.js +1 -1
- package/dist/core/ops/setDependsOn.js +37 -0
- package/dist/core/ops/setDependsOn.js.map +1 -0
- package/dist/core/ops/writtenBy.js +53 -0
- package/dist/core/ops/writtenBy.js.map +1 -0
- package/dist/core/pages/fitViewToPage.js +12 -1
- package/dist/core/pages/fitViewToPage.js.map +1 -1
- package/dist/core/pages/pageEdits.js +164 -0
- package/dist/core/pages/pageEdits.js.map +1 -0
- package/dist/core/pages/pages.js +30 -1
- package/dist/core/pages/pages.js.map +1 -1
- package/dist/core/scene/NodeRouting.js +8 -3
- package/dist/core/scene/NodeRouting.js.map +1 -1
- package/dist/core/scene/arrivalWindow.js.map +1 -1
- package/dist/core/scene/carryDescendants.js +51 -0
- package/dist/core/scene/carryDescendants.js.map +1 -0
- package/dist/core/scene/docValues.js +57 -0
- package/dist/core/scene/docValues.js.map +1 -0
- package/dist/core/scene/editPass.js +111 -0
- package/dist/core/scene/editPass.js.map +1 -0
- package/dist/core/scene/effectivePose.js +7 -1
- package/dist/core/scene/effectivePose.js.map +1 -1
- package/dist/core/scene/fieldEdits.js +4 -1
- package/dist/core/scene/fieldEdits.js.map +1 -1
- package/dist/core/scene/historyFacade.js +1 -0
- package/dist/core/scene/historyFacade.js.map +1 -1
- package/dist/core/scene/layoutPass.js +28 -3
- package/dist/core/scene/layoutPass.js.map +1 -1
- package/dist/core/scene/recorder.js +28 -19
- package/dist/core/scene/recorder.js.map +1 -1
- package/dist/core/scene/scene.js +15 -9
- package/dist/core/scene/scene.js.map +1 -1
- package/dist/core/scene/sceneChanges.js +13 -0
- package/dist/core/scene/sceneChanges.js.map +1 -0
- package/dist/core/scene/sceneEdits.js +8 -1
- package/dist/core/scene/sceneEdits.js.map +1 -1
- package/dist/core/scene/sceneMutators.js +1 -0
- package/dist/core/scene/sceneMutators.js.map +1 -1
- package/dist/core/scene/sceneRecording.js +20 -3
- package/dist/core/scene/sceneRecording.js.map +1 -1
- package/dist/core/scene/sceneSelection.js +4 -1
- package/dist/core/scene/sceneSelection.js.map +1 -1
- package/dist/core/scene/sceneState.js +11 -5
- package/dist/core/scene/sceneState.js.map +1 -1
- package/dist/core/scene/serialization.js +5 -3
- package/dist/core/scene/serialization.js.map +1 -1
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/scene/unitScopes.js +19 -1
- package/dist/core/scene/unitScopes.js.map +1 -1
- package/dist/core/selection/usePublishSceneSelection.js +6 -12
- package/dist/core/selection/usePublishSceneSelection.js.map +1 -1
- package/dist/core/shapeKinds.js +25 -11
- package/dist/core/shapeKinds.js.map +1 -1
- package/dist/{cornerHandles-Camw_yeu.d.ts → cornerHandles-BHuoMs1o.d.ts} +1 -1
- package/dist/debug/createDebugOverlayLayer.js +16 -111
- package/dist/debug/createDebugOverlayLayer.js.map +1 -1
- package/dist/debug/createDebugSink.js +2 -1
- package/dist/debug/createDebugSink.js.map +1 -1
- package/dist/debug/defaultTheme.js +4 -2
- package/dist/debug/defaultTheme.js.map +1 -1
- package/dist/debug/features.js +17 -0
- package/dist/debug/features.js.map +1 -0
- package/dist/debug/overlayPanels.js +117 -0
- package/dist/debug/overlayPanels.js.map +1 -0
- package/dist/debug/parseDebugFlags.js +4 -13
- package/dist/debug/parseDebugFlags.js.map +1 -1
- package/dist/{depSchema-Cgfu_G9s.d.ts → depSchema-BpZNOv7q.d.ts} +114 -892
- package/dist/devtools/handlers.js +112 -0
- package/dist/devtools/handlers.js.map +1 -0
- package/dist/devtools/history.js +71 -0
- package/dist/devtools/history.js.map +1 -0
- package/dist/devtools/hook.js +74 -0
- package/dist/devtools/hook.js.map +1 -0
- package/dist/devtools/label.js +25 -0
- package/dist/devtools/label.js.map +1 -0
- package/dist/devtools/notices.js +58 -0
- package/dist/devtools/notices.js.map +1 -0
- package/dist/devtools/protocol.js +7 -0
- package/dist/devtools/protocol.js.map +1 -0
- package/dist/devtools/registry.js +90 -0
- package/dist/devtools/registry.js.map +1 -0
- package/dist/devtools/root.js +80 -0
- package/dist/devtools/root.js.map +1 -0
- package/dist/devtools/serialize.js +86 -0
- package/dist/devtools/serialize.js.map +1 -0
- package/dist/devtools/session.js +111 -0
- package/dist/devtools/session.js.map +1 -0
- package/dist/devtools/transport.js +67 -0
- package/dist/devtools/transport.js.map +1 -0
- package/dist/devtools/useDevtoolsRoot.js +81 -0
- package/dist/devtools/useDevtoolsRoot.js.map +1 -0
- package/dist/devtools-protocol.d.ts +435 -0
- package/dist/devtools-protocol.js +7 -0
- package/dist/devtools.d.ts +8 -0
- package/dist/devtools.js +12 -0
- package/dist/devtools.js.map +1 -0
- package/dist/features/chrome-caps/useHoverTracking.js +16 -10
- package/dist/features/chrome-caps/useHoverTracking.js.map +1 -1
- package/dist/features/ingestion/contentHandlers.js +25 -2
- package/dist/features/ingestion/contentHandlers.js.map +1 -1
- package/dist/features/measure/measureCommands.js +7 -5
- package/dist/features/measure/measureCommands.js.map +1 -1
- package/dist/features/paths/index.js +2 -2
- package/dist/features/paths/pathEditExtension.js.map +1 -1
- package/dist/features/paths/pathSnap/pathSnapSource.js +5 -5
- package/dist/features/paths/pathSnap/pathSnapSource.js.map +1 -1
- package/dist/features/paths/pathSnap/sceneIndex.js +10 -3
- package/dist/features/paths/pathSnap/sceneIndex.js.map +1 -1
- package/dist/features/selection/selectionPose.js +4 -1
- package/dist/features/selection/selectionPose.js.map +1 -1
- package/dist/features/snap/gather.js +9 -1
- package/dist/features/snap/gather.js.map +1 -1
- package/dist/features/snap/lazySession.js +17 -0
- package/dist/features/snap/lazySession.js.map +1 -0
- package/dist/features/snap/marks.js.map +1 -1
- package/dist/features/snap/probes2d.js +27 -19
- package/dist/features/snap/probes2d.js.map +1 -1
- package/dist/features/snap/readoutLayer.js.map +1 -1
- package/dist/features/snap/roles.js +2 -1
- package/dist/features/snap/roles.js.map +1 -1
- package/dist/features/snap/rotationSource.js +25 -8
- package/dist/features/snap/rotationSource.js.map +1 -1
- package/dist/features/snap/sceneSession2d.js +6 -4
- package/dist/features/snap/sceneSession2d.js.map +1 -1
- package/dist/features/snap/session2d.js +37 -23
- package/dist/features/snap/session2d.js.map +1 -1
- package/dist/features/snap/spanSnap.js +5 -2
- package/dist/features/snap/spanSnap.js.map +1 -1
- package/dist/icons.table.js +1 -1
- package/dist/icons.table.js.map +1 -1
- package/dist/icons.table.json +0 -10
- package/dist/index.d.ts +701 -696
- package/dist/index.js +35 -29
- package/dist/interactions/actions/align/action.js +6 -4
- package/dist/interactions/actions/align/action.js.map +1 -1
- package/dist/interactions/actions/align/align.js.map +1 -1
- package/dist/interactions/actions/booleans/action.js +7 -1
- package/dist/interactions/actions/booleans/action.js.map +1 -1
- package/dist/interactions/actions/clone/action.js +1 -1
- package/dist/interactions/actions/clone/behaviors.js +4 -4
- package/dist/interactions/actions/clone/behaviors.js.map +1 -1
- package/dist/interactions/actions/defaults/bendSegment.js +1 -1
- package/dist/interactions/actions/defaults/bendSegment.js.map +1 -1
- package/dist/interactions/actions/defaults/createPaintAction.js +1 -1
- package/dist/interactions/actions/defaults/delete.js +48 -39
- package/dist/interactions/actions/defaults/delete.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +1 -1
- package/dist/interactions/actions/defaults/group.js +2 -2
- package/dist/interactions/actions/defaults/ingest.js +7 -5
- package/dist/interactions/actions/defaults/ingest.js.map +1 -1
- package/dist/interactions/actions/defaults/nudge.js +13 -38
- package/dist/interactions/actions/defaults/nudge.js.map +1 -1
- package/dist/interactions/actions/distribute/action.js +6 -4
- package/dist/interactions/actions/distribute/action.js.map +1 -1
- package/dist/interactions/actions/drawnBoxes.js +2 -1
- package/dist/interactions/actions/drawnBoxes.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/action.js +3 -6
- package/dist/interactions/actions/edit-anchors/action.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/preview.js +41 -8
- package/dist/interactions/actions/edit-anchors/preview.js.map +1 -1
- package/dist/interactions/actions/flip/action.js +6 -4
- package/dist/interactions/actions/flip/action.js.map +1 -1
- package/dist/interactions/actions/gestureLifecycle.js +5 -2
- package/dist/interactions/actions/gestureLifecycle.js.map +1 -1
- package/dist/interactions/actions/insert/action.js +1 -2
- package/dist/interactions/actions/insert/action.js.map +1 -1
- package/dist/interactions/actions/insert/commit.js +1 -1
- package/dist/interactions/actions/insert/parent.js +11 -0
- package/dist/interactions/actions/insert/parent.js.map +1 -0
- package/dist/interactions/actions/insert/placeAction.js +7 -2
- package/dist/interactions/actions/insert/placeAction.js.map +1 -1
- package/dist/interactions/actions/insert/session.js +5 -1
- package/dist/interactions/actions/insert/session.js.map +1 -1
- package/dist/interactions/actions/move/action.js +8 -4
- package/dist/interactions/actions/move/action.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/layoutDrop.js +0 -1
- package/dist/interactions/actions/move/behaviors/layoutDrop.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapToContainer.js +1 -1
- package/dist/interactions/actions/move/capture.js +1 -1
- package/dist/interactions/actions/move/commit/index.js +0 -2
- package/dist/interactions/actions/move/commit/index.js.map +1 -1
- package/dist/interactions/actions/move/commit/layoutDrop.js +2 -2
- package/dist/interactions/actions/move/commit/layoutRelease.js +2 -2
- package/dist/interactions/actions/move/commit/reparent.js +11 -5
- package/dist/interactions/actions/move/commit/reparent.js.map +1 -1
- package/dist/interactions/actions/move/frame.js +4 -10
- package/dist/interactions/actions/move/frame.js.map +1 -1
- package/dist/interactions/actions/move/landedDescendants.js +20 -17
- package/dist/interactions/actions/move/landedDescendants.js.map +1 -1
- package/dist/interactions/actions/move/layout/container.js +2 -1
- package/dist/interactions/actions/move/layout/container.js.map +1 -1
- package/dist/interactions/actions/move/layout/dragged.js +1 -1
- package/dist/interactions/actions/move/layout/dropPass.js +18 -1
- package/dist/interactions/actions/move/layout/dropPass.js.map +1 -1
- package/dist/interactions/actions/move/layout/exits.js +5 -5
- package/dist/interactions/actions/move/layout/exits.js.map +1 -1
- package/dist/interactions/actions/move/session.js +14 -3
- package/dist/interactions/actions/move/session.js.map +1 -1
- package/dist/interactions/actions/move/translate.js +8 -37
- package/dist/interactions/actions/move/translate.js.map +1 -1
- package/dist/interactions/actions/moveNodes.js +87 -0
- package/dist/interactions/actions/moveNodes.js.map +1 -0
- package/dist/interactions/actions/planeInput.js.map +1 -1
- package/dist/interactions/actions/resize/action.js +83 -72
- package/dist/interactions/actions/resize/action.js.map +1 -1
- package/dist/interactions/actions/resize/commit.js +2 -1
- package/dist/interactions/actions/resize/commit.js.map +1 -1
- package/dist/interactions/actions/resize/session.js +2 -0
- package/dist/interactions/actions/resize/session.js.map +1 -1
- package/dist/interactions/actions/resolvePreviews.js +3 -3
- package/dist/interactions/actions/resolvePreviews.js.map +1 -1
- package/dist/interactions/actions/rotate/action.js +7 -4
- package/dist/interactions/actions/rotate/action.js.map +1 -1
- package/dist/interactions/actions/rotate/commit.js +2 -1
- package/dist/interactions/actions/rotate/commit.js.map +1 -1
- package/dist/interactions/actions/rotate/session.js +2 -0
- package/dist/interactions/actions/rotate/session.js.map +1 -1
- package/dist/interactions/actions/selectionSubtree.js +13 -2
- package/dist/interactions/actions/selectionSubtree.js.map +1 -1
- package/dist/interactions/actions/testUtils.js.map +1 -1
- package/dist/interactions/actions/transform-again/action.js +5 -6
- package/dist/interactions/actions/transform-again/action.js.map +1 -1
- package/dist/interactions/actions/transformFinish.js +106 -0
- package/dist/interactions/actions/transformFinish.js.map +1 -0
- package/dist/kitSettingsSchema.js +0 -4
- package/dist/kitSettingsSchema.js.map +1 -1
- package/dist/move.d.ts +5 -4
- package/dist/{options-p9GZMXbY.d.ts → options-DBxEryYq.d.ts} +1 -1
- package/dist/resize.d.ts +4 -3
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +2 -2
- package/dist/test-hook/createTestHook.js +1 -1
- package/dist/test-hook/createTestHook.js.map +1 -1
- package/dist/test-hook/useTestHook.js +2 -1
- package/dist/test-hook/useTestHook.js.map +1 -1
- package/dist/test-seams.d.ts +9 -5
- package/dist/tools/builtin/pen/penHandle.js +3 -5
- package/dist/tools/builtin/pen/penHandle.js.map +1 -1
- package/dist/tools/index.js +26 -0
- package/dist/{types-CHVXGfYm.d.ts → types-7puAuVD2.d.ts} +3 -262
- package/dist/types-BN9hbdMI.d.ts +184 -0
- package/dist/types-CniVctmk.d.ts +949 -0
- package/dist/types-oFeQ5VjV.d.ts +264 -0
- package/dist/version.js +1 -1
- package/package.json +35 -25
- package/dist/canvas/SceneCanvas/useBuiltinRigTools.js +0 -65
- package/dist/canvas/SceneCanvas/useBuiltinRigTools.js.map +0 -1
- package/dist/tools/builtin/bone/boneActions.js +0 -156
- package/dist/tools/builtin/bone/boneActions.js.map +0 -1
- package/dist/tools/builtin/bone/boneOverlay.js +0 -71
- package/dist/tools/builtin/bone/boneOverlay.js.map +0 -1
- package/dist/tools/builtin/bone/placedRig.js +0 -28
- package/dist/tools/builtin/bone/placedRig.js.map +0 -1
- package/dist/tools/builtin/bone/rigEditState.js +0 -30
- package/dist/tools/builtin/bone/rigEditState.js.map +0 -1
- package/dist/tools/builtin/bone/useBoneTool.js +0 -125
- package/dist/tools/builtin/bone/useBoneTool.js.map +0 -1
- package/dist/tools/builtin/weight/useWeightTool.js +0 -101
- package/dist/tools/builtin/weight/useWeightTool.js.map +0 -1
- package/dist/tools/builtin/weight/weightActions.js +0 -140
- package/dist/tools/builtin/weight/weightActions.js.map +0 -1
- package/dist/tools/builtin/weight/weightOverlay.js +0 -78
- package/dist/tools/builtin/weight/weightOverlay.js.map +0 -1
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { createTransformOp } from "../../core/ops/transform.js";
|
|
2
|
-
import { createSetDataOp } from "../../core/ops/setData.js";
|
|
3
|
-
import { createDeleteOp } from "../../core/ops/delete.js";
|
|
4
1
|
import { locksOf } from "../../interactions/actions/edit-anchors/params.js";
|
|
5
2
|
import { representationOf } from "../../features/paths/pathRepresentation.js";
|
|
6
|
-
import { classifyPathStorage, pathEditPathOf, resolveEditablePathOf
|
|
7
|
-
import { withoutShapeGenerator } from "../../features/paths/shapeGenerator.js";
|
|
8
|
-
import { withoutGeometryBoundData } from "../../features/paths/pathEditExtension.js";
|
|
3
|
+
import { classifyPathStorage, pathEditPathOf, resolveEditablePathOf } from "../../features/paths/editablePath.js";
|
|
9
4
|
import { anchorDataPatch } from "../../features/paths/anchorData.js";
|
|
5
|
+
import { finishCtx, finishEdit, otherOps, pathEditFollower, reshapeOps } from "./pathEditCommits.js";
|
|
6
|
+
import { useTransformFollower } from "./transformFollowers.js";
|
|
10
7
|
import { createPathEditState, isSelectedNode } from "../../features/paths/pathEditState.js";
|
|
11
8
|
import { useState } from "react";
|
|
12
9
|
import { useLatest } from "@weasel-js/react";
|
|
13
|
-
import {
|
|
10
|
+
import { resolveParams } from "@weasel-js/routing";
|
|
14
11
|
import { useDepRegistry, useDepSource } from "@weasel-js/routing/react";
|
|
15
12
|
|
|
16
13
|
//#region src/canvas/deps/editAnchors.ts
|
|
@@ -56,7 +53,7 @@ function useEditAnchorsDepSource(scene, selection, adapter, externalState, tune)
|
|
|
56
53
|
setEditingId(id) {
|
|
57
54
|
const next = id ?? "";
|
|
58
55
|
if (effectiveId !== next) {
|
|
59
|
-
recordModeSwitch("editAnchors.editingId", effectiveId || null, next || null, next ? "enter" : "exit");
|
|
56
|
+
registry.get("dispatchTrace")?.recordModeSwitch("editAnchors.editingId", effectiveId || null, next || null, next ? "enter" : "exit");
|
|
60
57
|
state.setSelectedAnchors(EMPTY_ANCHOR_SELECTION);
|
|
61
58
|
state.setSelectedMark(null);
|
|
62
59
|
state.setMarquee(null);
|
|
@@ -95,96 +92,21 @@ function useEditAnchorsDepSource(scene, selection, adapter, externalState, tune)
|
|
|
95
92
|
...pathAccess(sc, ad, state.getExtensions())
|
|
96
93
|
};
|
|
97
94
|
});
|
|
98
|
-
|
|
99
|
-
/** The scene as an extension's `finishEdit` reads it. */
|
|
100
|
-
function finishCtx(sc, id, extensions) {
|
|
101
|
-
return {
|
|
102
|
-
id,
|
|
103
|
-
node(nid) {
|
|
104
|
-
const node = sc.get(nid);
|
|
105
|
-
return node ? {
|
|
106
|
-
pose: node.pose,
|
|
107
|
-
data: node.data,
|
|
108
|
-
dependsOn: node.dependsOn
|
|
109
|
-
} : null;
|
|
110
|
-
},
|
|
111
|
-
path(nid) {
|
|
112
|
-
return pathEditPathOf(sc.get(nid), extensions);
|
|
113
|
-
},
|
|
114
|
-
dependents(nid) {
|
|
115
|
-
if (!sc.get(nid)) return [];
|
|
116
|
-
return sc.removalClosure([nid]).filter((d) => d !== nid && !sc.ancestorsOf(d).includes(nid));
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/** `worldPath` finished by each of `extensions` in turn, the data they set
|
|
121
|
-
* beside it, and the other nodes they change; null when one cannot finish it. */
|
|
122
|
-
function finish(extensions, node, worldPath, origins, ctx) {
|
|
123
|
-
let path = worldPath;
|
|
124
|
-
let data = null;
|
|
125
|
-
const others = /* @__PURE__ */ new Map();
|
|
126
|
-
for (const ext of extensions) {
|
|
127
|
-
if (!ext.finishEdit) continue;
|
|
128
|
-
const done = ext.finishEdit(node, path, origins, ctx);
|
|
129
|
-
if (!done) return null;
|
|
130
|
-
path = done.path;
|
|
131
|
-
if (done.data) data = {
|
|
132
|
-
...data ?? {},
|
|
133
|
-
...done.data
|
|
134
|
-
};
|
|
135
|
-
for (const o of done.others ?? []) {
|
|
136
|
-
const had = others.get(o.id);
|
|
137
|
-
others.set(o.id, {
|
|
138
|
-
id: o.id,
|
|
139
|
-
path: o.path ?? had?.path,
|
|
140
|
-
data: o.data || had?.data ? {
|
|
141
|
-
...had?.data,
|
|
142
|
-
...o.data
|
|
143
|
-
} : void 0,
|
|
144
|
-
remove: o.remove || had?.remove
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
path,
|
|
150
|
-
data,
|
|
151
|
-
others
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/** The ops that commit the other nodes `done` changes. */
|
|
155
|
-
function otherOps(sc, done, label, extensions) {
|
|
156
|
-
return [...done.others.values()].flatMap((o) => {
|
|
157
|
-
const node = sc.get(o.id);
|
|
158
|
-
if (!node) return [];
|
|
159
|
-
if (o.remove) return [createDeleteOp({
|
|
160
|
-
node: sc.get(o.id),
|
|
161
|
-
label
|
|
162
|
-
})];
|
|
163
|
-
if (o.path) return reshapeOps(o.id, node, o.path, label, o.data ?? null, extensions);
|
|
164
|
-
return o.data ? [createSetDataOp({
|
|
165
|
-
id: o.id,
|
|
166
|
-
from: node.data,
|
|
167
|
-
to: {
|
|
168
|
-
...node.data,
|
|
169
|
-
...o.data
|
|
170
|
-
},
|
|
171
|
-
label
|
|
172
|
-
})] : [];
|
|
173
|
-
});
|
|
95
|
+
useTransformFollower(() => pathEditFollower(sceneRef.current, stateRef.current.getExtensions()));
|
|
174
96
|
}
|
|
175
97
|
/** The members of the dep that read the scene and commit to it. */
|
|
176
98
|
function pathAccess(sc, ad, extensions) {
|
|
177
99
|
const editOps = (id, worldPath, label, origins) => {
|
|
178
100
|
const node = sc.get(id);
|
|
179
101
|
if (!node) return [];
|
|
180
|
-
const done =
|
|
102
|
+
const done = finishEdit(extensions, node, worldPath, origins, finishCtx(sc, id, extensions));
|
|
181
103
|
if (!done) return [];
|
|
182
104
|
const before = origins && !representationOf(extensions, node.data) ? resolveEditablePathOf(node) : null;
|
|
183
105
|
const patch = {
|
|
184
106
|
...before && origins ? anchorDataPatch(node.data, before, done.path, origins) : {},
|
|
185
107
|
...done.data
|
|
186
108
|
};
|
|
187
|
-
return [...reshapeOps(id, node, done.path, label, Object.keys(patch).length > 0 ? patch : null, extensions), ...otherOps(sc, done, label, extensions)];
|
|
109
|
+
return [...reshapeOps(id, node, done.path, label, Object.keys(patch).length > 0 ? patch : null, extensions), ...otherOps(sc, done.others, label, extensions)];
|
|
188
110
|
};
|
|
189
111
|
return {
|
|
190
112
|
getEditablePath(id) {
|
|
@@ -217,7 +139,7 @@ function pathAccess(sc, ad, extensions) {
|
|
|
217
139
|
path: worldPath,
|
|
218
140
|
others: []
|
|
219
141
|
};
|
|
220
|
-
const done =
|
|
142
|
+
const done = finishEdit(extensions, node, worldPath, origins, finishCtx(sc, id, extensions));
|
|
221
143
|
if (!done) return null;
|
|
222
144
|
const others = [...done.others.values()].flatMap((o) => o.path && !o.remove ? [{
|
|
223
145
|
id: o.id,
|
|
@@ -235,32 +157,6 @@ function pathAccess(sc, ad, extensions) {
|
|
|
235
157
|
}
|
|
236
158
|
};
|
|
237
159
|
}
|
|
238
|
-
/** The ops that store `worldPath` where `node` keeps its polygon, with `patch` laid over its data. */
|
|
239
|
-
function reshapeOps(id, node, worldPath, label, patch, extensions) {
|
|
240
|
-
const next = storeEditablePath(node, worldPath, extensions);
|
|
241
|
-
if (!next) return [];
|
|
242
|
-
const reshape = createTransformOp({
|
|
243
|
-
id,
|
|
244
|
-
from: node.pose,
|
|
245
|
-
to: next.pose,
|
|
246
|
-
label
|
|
247
|
-
});
|
|
248
|
-
const data = withoutGeometryBoundData(next.data === node.data ? node.data : withoutShapeGenerator(next.data), [
|
|
249
|
-
"skin",
|
|
250
|
-
"constraints",
|
|
251
|
-
"representation"
|
|
252
|
-
]);
|
|
253
|
-
if (data === node.data && !patch) return [reshape];
|
|
254
|
-
return [reshape, createSetDataOp({
|
|
255
|
-
id,
|
|
256
|
-
from: node.data,
|
|
257
|
-
to: {
|
|
258
|
-
...data,
|
|
259
|
-
...patch
|
|
260
|
-
},
|
|
261
|
-
label
|
|
262
|
-
})];
|
|
263
|
-
}
|
|
264
160
|
|
|
265
161
|
//#endregion
|
|
266
162
|
export { resolveEditablePathOf, useEditAnchorsDepSource };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editAnchors.js","names":[],"sources":["../../../src/canvas/deps/editAnchors.ts"],"sourcesContent":["/**\n * `useEditAnchorsDepSource` — wires the `editAnchors` dep.\n *\n * A node's editable polygon lives in one of two places: the pose itself\n * (`pose.kind === 'polygon'`), or `data.path` with a rect pose, stored pose-local.\n * `getEditablePath` returns it in **world coords** either way, and `applyEdit` commits in the\n * correct storage shape as one undoable batch, preserving the render invariant\n * `pathInWorld(stored, pose) === world`. What the node keeps per anchor — a `data.skin`, vertex\n * colors — is renumbered in that batch when the caller says where the points came from, and each path-edit extension finishes\n * the edit first (`PathEditExtension.finishEdit`). Live previews ride the standard\n * `OngoingHandle.previewIds/Pose/Data` triple — this dep doesn't own preview state.\n */\nimport { useState } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { EditAnchorsDep } from 'interactions/actions/depSchema';\nimport { locksOf, type EditAnchorsParams } from 'interactions/actions/edit-anchors/params';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport type { PointOrigin, PolygonPath } from '@weasel-js/geom';\nimport { anchorDataPatch } from 'features/paths/anchorData';\nimport { classifyPathStorage, pathEditPathOf, resolveEditablePathOf, storeEditablePath } from 'features/paths/editablePath';\nimport { representationOf } from 'features/paths/pathRepresentation';\nimport { withoutShapeGenerator } from 'features/paths/shapeGenerator';\nimport {\n withoutGeometryBoundData, type PathEditExtension, type PathEditFinishCtx, type PathEditOther,\n} from 'features/paths/pathEditExtension';\nimport { createPathEditState, isSelectedNode, type PathEditState } from 'features/paths/pathEditState';\nimport { recordModeSwitch, resolveParams, type ActionTunings } from '@weasel-js/routing';\nimport type { Op } from 'core/ops/types';\nimport { createTransformOp } from 'core/ops/transform';\nimport { createSetDataOp } from 'core/ops/setData';\nimport { createDeleteOp } from 'core/ops/delete';\n\ninterface OpsApplier {\n applyOps(ops: Op[], label?: string): void;\n}\n\n/** The part of a `PathEditState` the dep reads and writes. */\nexport type EditAnchorsStateRef = Omit<PathEditState, 'subscribe' | 'getEditingIds' | 'setExtensions'>;\n/** The same, with the change notice chrome reading the dep waits on. */\nexport type EditAnchorsStateSource = EditAnchorsStateRef & Partial<Pick<PathEditState, 'subscribe'>>;\n\nexport { resolveEditablePathOf };\n\nfunction tunedHandleLock(tune: ActionTunings | undefined): EditAnchorsParams['handleLock'] {\n const params = resolveParams(tune?.editAnchors?.params as Parameters<typeof resolveParams>[0]);\n return (params as EditAnchorsParams | undefined)?.handleLock;\n}\n\nconst EMPTY_ANCHOR_SELECTION: ReadonlySet<number> = new Set<number>();\n\n/**\n * Publish the `editAnchors` dep for `scene`: its path access and commits\n * through `adapter`, and the edit state of `externalState` (or one of its\n * own), with the extensions that state holds finishing every edit.\n */\nexport function useEditAnchorsDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n adapter: OpsApplier,\n externalState?: EditAnchorsStateRef,\n /** `<SceneCanvas tune>`: the handle locks start from its `editAnchors`\n * `handleLock` param until a toggle sets them. */\n tune?: ActionTunings,\n): void {\n const registry = useDepRegistry();\n const tuneRef = useLatest(tune);\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const adapterRef = useLatest(adapter);\n\n // A caller that shares the state with nothing else gets one of its own.\n const [ownState] = useState(() => createPathEditState({\n isSelectedNode: (id) => isSelectedNode(sceneRef.current, selectionRef.current, id),\n }));\n const stateRef = useLatest(externalState ?? ownState);\n\n useDepSource('editAnchors', (): EditAnchorsDep => {\n const sc = sceneRef.current;\n const ad = adapterRef.current;\n const state = stateRef.current;\n const effectiveId = state.getEditingId();\n // Anchor selection and the marquee belong to one specific edited node, so never\n // hand them out alongside an empty id.\n const selectedAnchors = effectiveId ? state.getSelectedAnchors() : EMPTY_ANCHOR_SELECTION;\n const marquee = effectiveId ? state.getMarquee() : null;\n const tool = effectiveId ? state.getTool() : null;\n return {\n editingId: effectiveId,\n setEditingId(id: string | null) {\n const next = id ?? '';\n if (effectiveId !== next) {\n recordModeSwitch(\n 'editAnchors.editingId',\n effectiveId || null,\n next || null,\n next ? 'enter' : 'exit',\n );\n // Anchor indices only mean something relative to one path.\n state.setSelectedAnchors(EMPTY_ANCHOR_SELECTION);\n state.setSelectedMark(null);\n state.setMarquee(null);\n }\n stateRef.current.setEditingId(id);\n },\n selectedAnchors,\n setSelectedAnchors(next: Iterable<number>) {\n if (!effectiveId) return;\n const set = new Set(next);\n if (set.size > 0) state.setSelectedMark(null);\n state.setSelectedAnchors(set);\n },\n selectedMark: effectiveId ? state.getSelectedMark() : null,\n setSelectedMark(mark) {\n if (!effectiveId) return;\n if (mark !== null) state.setSelectedAnchors(EMPTY_ANCHOR_SELECTION);\n state.setSelectedMark(mark);\n },\n extensions: state.getExtensions(),\n marquee,\n setMarquee(rect) {\n if (!effectiveId) return;\n state.setMarquee(rect);\n },\n handleLocks: state.getHandleLocks() ?? locksOf(tunedHandleLock(tuneRef.current)),\n setHandleLocks(next) {\n state.setHandleLocks(next);\n registry.changed?.();\n },\n tool,\n setTool(id) {\n if (!effectiveId) return;\n state.setTool(id);\n },\n ...pathAccess(sc, ad, state.getExtensions()),\n };\n });\n}\n\n/** What {@link finish} answers: the edited path, the data set beside it, and the other nodes it changes, by id. */\ninterface Finished {\n path: PolygonPath;\n data: Record<string, unknown> | null;\n others: Map<string, PathEditOther>;\n}\n\n/** The scene as an extension's `finishEdit` reads it. */\nfunction finishCtx(\n sc: Scene<unknown, string, unknown>,\n id: string,\n extensions: readonly PathEditExtension[],\n): PathEditFinishCtx {\n return {\n id,\n node(nid) {\n const node = sc.get(nid as NodeId);\n return node ? { pose: node.pose, data: node.data, dependsOn: node.dependsOn } : null;\n },\n path(nid) {\n return pathEditPathOf(sc.get(nid as NodeId) as EditableNode | undefined, extensions);\n },\n dependents(nid) {\n if (!sc.get(nid as NodeId)) return [];\n return sc.removalClosure([nid as NodeId]).filter((d) => d !== nid && !sc.ancestorsOf(d).includes(nid as NodeId));\n },\n };\n}\n\n/** `worldPath` finished by each of `extensions` in turn, the data they set\n * beside it, and the other nodes they change; null when one cannot finish it. */\nfunction finish(\n extensions: readonly PathEditExtension[],\n node: EditableNode,\n worldPath: PolygonPath,\n origins: readonly (PointOrigin | null)[] | undefined,\n ctx: PathEditFinishCtx,\n): Finished | null {\n let path = worldPath;\n let data: Record<string, unknown> | null = null;\n const others = new Map<string, PathEditOther>();\n for (const ext of extensions) {\n if (!ext.finishEdit) continue;\n const done = ext.finishEdit(node, path, origins, ctx);\n if (!done) return null;\n path = done.path;\n if (done.data) data = { ...(data ?? {}), ...done.data };\n for (const o of done.others ?? []) {\n const had = others.get(o.id);\n others.set(o.id, {\n id: o.id,\n path: o.path ?? had?.path,\n data: o.data || had?.data ? { ...had?.data, ...o.data } : undefined,\n remove: o.remove || had?.remove,\n });\n }\n }\n return { path, data, others };\n}\n\n/** The ops that commit the other nodes `done` changes. */\nfunction otherOps(\n sc: Scene<unknown, string, unknown>,\n done: Finished,\n label: string,\n extensions: readonly PathEditExtension[],\n): Op[] {\n return [...done.others.values()].flatMap((o) => {\n const node = sc.get(o.id as NodeId) as EditableNode | undefined;\n if (!node) return [];\n if (o.remove) return [createDeleteOp({ node: sc.get(o.id as NodeId)!, label })];\n if (o.path) return reshapeOps(o.id, node, o.path, label, o.data ?? null, extensions);\n return o.data ? [createSetDataOp({ id: o.id, from: node.data, to: { ...(node.data as object), ...o.data }, label })] : [];\n });\n}\n\n/** The members of the dep that read the scene and commit to it. */\nfunction pathAccess(\n sc: Scene<unknown, string, unknown>,\n ad: OpsApplier,\n extensions: readonly PathEditExtension[],\n): Pick<\n EditAnchorsDep,\n 'getEditablePath' | 'getOutlinePath' | 'getStorageKind' | 'getNodeShape' | 'applyEdit' | 'editOps' | 'finishEdit' | 'store'\n> {\n const editOps = (id: string, worldPath: unknown, label: string, origins?: readonly (PointOrigin | null)[]): Op[] => {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n if (!node) return [];\n const done = finish(extensions, node, worldPath as PolygonPath, origins, finishCtx(sc, id, extensions));\n if (!done) return [];\n // A form's origins number the anchors of its edit path, not data.path's.\n const before = origins && !representationOf(extensions, node.data) ? resolveEditablePathOf(node) : null;\n const patch = { ...(before && origins ? anchorDataPatch(node.data, before, done.path, origins) : {}), ...done.data };\n return [\n ...reshapeOps(id, node, done.path, label, Object.keys(patch).length > 0 ? patch : null, extensions),\n ...otherOps(sc, done, label, extensions),\n ];\n };\n return {\n getEditablePath(id: string): PolygonPath | null {\n const node = sc.get(id as NodeId);\n return pathEditPathOf(node as { pose: unknown; data: unknown }, extensions);\n },\n getOutlinePath(id: string): PolygonPath | null {\n return resolveEditablePathOf(sc.get(id as NodeId) as { pose: unknown; data: unknown });\n },\n getStorageKind(id: string): 'pose' | 'data' | null {\n const node = sc.get(id as NodeId);\n const storage = classifyPathStorage(node as { pose: unknown; data: unknown });\n return storage?.kind ?? null;\n },\n getNodeShape(id: string): { pose: unknown; data: unknown } | null {\n const node = sc.get(id as NodeId);\n if (!node) return null;\n return { pose: node.pose, data: node.data };\n },\n applyEdit(id: string, worldPath: unknown, label: string, origins?: readonly (PointOrigin | null)[]) {\n const ops = editOps(id, worldPath, label, origins);\n if (ops.length > 0) ad.applyOps(ops, label);\n },\n editOps,\n finishEdit(id: string, worldPath: unknown, origins?: readonly (PointOrigin | null)[]) {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n if (!node) return { path: worldPath, others: [] };\n const done = finish(extensions, node, worldPath as PolygonPath, origins, finishCtx(sc, id, extensions));\n if (!done) return null;\n const others = [...done.others.values()].flatMap((o) => (o.path && !o.remove ? [{ id: o.id, path: o.path }] : []));\n return { path: done.path, others };\n },\n store(id, worldPath, label, data) {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n const ops = node ? reshapeOps(id, node, worldPath, label, data ?? null, extensions) : [];\n if (ops.length > 0) ad.applyOps(ops, label);\n },\n };\n}\n\ntype EditableNode = { pose: unknown; data: unknown };\n\n/** The ops that store `worldPath` where `node` keeps its polygon, with `patch` laid over its data. */\nfunction reshapeOps(\n id: string,\n node: EditableNode,\n worldPath: PolygonPath,\n label: string,\n patch: Record<string, unknown> | null,\n extensions: readonly PathEditExtension[],\n): Op[] {\n const next = storeEditablePath(node, worldPath, extensions);\n if (!next) return [];\n const reshape = createTransformOp({ id, from: node.pose, to: next.pose, label });\n // A path edited by hand is no longer what its generator or warp makes: it becomes plain geometry.\n // Its skin and constraints stay, renumbered by the caller's patch where it has one, and the\n // form it was drawn from as storing it left it.\n const data = withoutGeometryBoundData(\n next.data === node.data ? node.data : withoutShapeGenerator(next.data), ['skin', 'constraints', 'representation'],\n );\n if (data === node.data && !patch) return [reshape];\n return [reshape, createSetDataOp({ id, from: node.data, to: { ...(data as object), ...patch }, label })];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAS,gBAAgB,MAAkE;CAEzF,OADe,cAAc,MAAM,aAAa,MACxC,CAAA,EAA0C;AACpD;AAEA,IAAM,yCAA8C,IAAI,IAAY;;;;;;AAOpE,SAAgB,wBACd,OACA,WACA,SACA,eAGA,MACM;CACN,MAAM,WAAW,eAAe;CAChC,MAAM,UAAU,UAAU,IAAI;CAC9B,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,aAAa,UAAU,OAAO;CAGpC,MAAM,CAAC,YAAY,eAAe,oBAAoB,EACpD,iBAAiB,OAAO,eAAe,SAAS,SAAS,aAAa,SAAS,EAAE,EACnF,CAAC,CAAC;CACF,MAAM,WAAW,UAAU,iBAAiB,QAAQ;CAEpD,aAAa,qBAAqC;EAChD,MAAM,KAAK,SAAS;EACpB,MAAM,KAAK,WAAW;EACtB,MAAM,QAAQ,SAAS;EACvB,MAAM,cAAc,MAAM,aAAa;EAGvC,MAAM,kBAAkB,cAAc,MAAM,mBAAmB,IAAI;EACnE,MAAM,UAAU,cAAc,MAAM,WAAW,IAAI;EACnD,MAAM,OAAO,cAAc,MAAM,QAAQ,IAAI;EAC7C,OAAO;GACL,WAAW;GACX,aAAa,IAAmB;IAC9B,MAAM,OAAO,MAAM;IACnB,IAAI,gBAAgB,MAAM;KACxB,iBACE,yBACA,eAAe,MACf,QAAQ,MACR,OAA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AO,CAAC,OAAO;CACjD,OAAO,CAAC,SAAS,gBAAgB;EAAE;EAAI,MAAM,KAAK;EAAM,IAAI;GAAE,GAAI;GAAiB,GAAG;EAAM;EAAG;CAAM,CAAC,CAAC;AACzG"}
|
|
1
|
+
{"version":3,"file":"editAnchors.js","names":[],"sources":["../../../src/canvas/deps/editAnchors.ts"],"sourcesContent":["/**\n * `useEditAnchorsDepSource` — wires the `editAnchors` dep.\n *\n * A node's editable polygon lives in one of two places: the pose itself\n * (`pose.kind === 'polygon'`), or `data.path` with a rect pose, stored pose-local.\n * `getEditablePath` returns it in **world coords** either way, and `applyEdit` commits in the\n * correct storage shape as one undoable batch, preserving the render invariant\n * `pathInWorld(stored, pose) === world`. What the node keeps per anchor — a `data.skin`, vertex\n * colors — is renumbered in that batch when the caller says where the points came from, and each path-edit extension finishes\n * the edit first (`PathEditExtension.finishEdit`). Live previews ride the standard\n * `OngoingHandle.previewIds/Pose/Data` triple — this dep doesn't own preview state.\n */\nimport { useState } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { EditAnchorsDep } from 'interactions/actions/depSchema';\nimport { locksOf, type EditAnchorsParams } from 'interactions/actions/edit-anchors/params';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport type { PointOrigin, PolygonPath } from '@weasel-js/geom';\nimport { anchorDataPatch } from 'features/paths/anchorData';\nimport { classifyPathStorage, pathEditPathOf, resolveEditablePathOf } from 'features/paths/editablePath';\nimport { representationOf } from 'features/paths/pathRepresentation';\nimport type { PathEditExtension } from 'features/paths/pathEditExtension';\nimport {\n finishCtx, finishEdit, otherOps, pathEditFollower, reshapeOps, type EditableNode,\n} from './pathEditCommits';\nimport { useTransformFollower } from './transformFollowers';\nimport { createPathEditState, isSelectedNode, type PathEditState } from 'features/paths/pathEditState';\nimport { resolveParams, type ActionTunings } from '@weasel-js/routing';\nimport type { Op } from 'core/ops/types';\n\ninterface OpsApplier {\n applyOps(ops: Op[], label?: string): void;\n}\n\n/** The part of a `PathEditState` the dep reads and writes. */\nexport type EditAnchorsStateRef = Omit<PathEditState, 'subscribe' | 'getEditingIds' | 'setExtensions'>;\n/** The same, with the change notice chrome reading the dep waits on. */\nexport type EditAnchorsStateSource = EditAnchorsStateRef & Partial<Pick<PathEditState, 'subscribe'>>;\n\nexport { resolveEditablePathOf };\n\nfunction tunedHandleLock(tune: ActionTunings | undefined): EditAnchorsParams['handleLock'] {\n const params = resolveParams(tune?.editAnchors?.params as Parameters<typeof resolveParams>[0]);\n return (params as EditAnchorsParams | undefined)?.handleLock;\n}\n\nconst EMPTY_ANCHOR_SELECTION: ReadonlySet<number> = new Set<number>();\n\n/**\n * Publish the `editAnchors` dep for `scene`: its path access and commits\n * through `adapter`, and the edit state of `externalState` (or one of its\n * own), with the extensions that state holds finishing every edit.\n */\nexport function useEditAnchorsDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n adapter: OpsApplier,\n externalState?: EditAnchorsStateRef,\n /** `<SceneCanvas tune>`: the handle locks start from its `editAnchors`\n * `handleLock` param until a toggle sets them. */\n tune?: ActionTunings,\n): void {\n const registry = useDepRegistry();\n const tuneRef = useLatest(tune);\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const adapterRef = useLatest(adapter);\n\n // A caller that shares the state with nothing else gets one of its own.\n const [ownState] = useState(() => createPathEditState({\n isSelectedNode: (id) => isSelectedNode(sceneRef.current, selectionRef.current, id),\n }));\n const stateRef = useLatest(externalState ?? ownState);\n\n useDepSource('editAnchors', (): EditAnchorsDep => {\n const sc = sceneRef.current;\n const ad = adapterRef.current;\n const state = stateRef.current;\n const effectiveId = state.getEditingId();\n // Anchor selection and the marquee belong to one specific edited node, so never\n // hand them out alongside an empty id.\n const selectedAnchors = effectiveId ? state.getSelectedAnchors() : EMPTY_ANCHOR_SELECTION;\n const marquee = effectiveId ? state.getMarquee() : null;\n const tool = effectiveId ? state.getTool() : null;\n return {\n editingId: effectiveId,\n setEditingId(id: string | null) {\n const next = id ?? '';\n if (effectiveId !== next) {\n registry.get('dispatchTrace')?.recordModeSwitch(\n 'editAnchors.editingId',\n effectiveId || null,\n next || null,\n next ? 'enter' : 'exit',\n );\n // Anchor indices only mean something relative to one path.\n state.setSelectedAnchors(EMPTY_ANCHOR_SELECTION);\n state.setSelectedMark(null);\n state.setMarquee(null);\n }\n stateRef.current.setEditingId(id);\n },\n selectedAnchors,\n setSelectedAnchors(next: Iterable<number>) {\n if (!effectiveId) return;\n const set = new Set(next);\n if (set.size > 0) state.setSelectedMark(null);\n state.setSelectedAnchors(set);\n },\n selectedMark: effectiveId ? state.getSelectedMark() : null,\n setSelectedMark(mark) {\n if (!effectiveId) return;\n if (mark !== null) state.setSelectedAnchors(EMPTY_ANCHOR_SELECTION);\n state.setSelectedMark(mark);\n },\n extensions: state.getExtensions(),\n marquee,\n setMarquee(rect) {\n if (!effectiveId) return;\n state.setMarquee(rect);\n },\n handleLocks: state.getHandleLocks() ?? locksOf(tunedHandleLock(tuneRef.current)),\n setHandleLocks(next) {\n state.setHandleLocks(next);\n registry.changed?.();\n },\n tool,\n setTool(id) {\n if (!effectiveId) return;\n state.setTool(id);\n },\n ...pathAccess(sc, ad, state.getExtensions()),\n };\n });\n useTransformFollower(() => pathEditFollower(sceneRef.current, stateRef.current.getExtensions()));\n}\n\n/** The members of the dep that read the scene and commit to it. */\nfunction pathAccess(\n sc: Scene<unknown, string, unknown>,\n ad: OpsApplier,\n extensions: readonly PathEditExtension[],\n): Pick<\n EditAnchorsDep,\n | 'getEditablePath' | 'getOutlinePath' | 'getStorageKind' | 'getNodeShape' | 'applyEdit' | 'editOps' | 'finishEdit'\n | 'store'\n> {\n const editOps = (id: string, worldPath: unknown, label: string, origins?: readonly (PointOrigin | null)[]): Op[] => {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n if (!node) return [];\n const done = finishEdit(extensions, node, worldPath as PolygonPath, origins, finishCtx(sc, id, extensions));\n if (!done) return [];\n // A form's origins number the anchors of its edit path, not data.path's.\n const before = origins && !representationOf(extensions, node.data) ? resolveEditablePathOf(node) : null;\n const patch = { ...(before && origins ? anchorDataPatch(node.data, before, done.path, origins) : {}), ...done.data };\n return [\n ...reshapeOps(id, node, done.path, label, Object.keys(patch).length > 0 ? patch : null, extensions),\n ...otherOps(sc, done.others, label, extensions),\n ];\n };\n return {\n getEditablePath(id: string): PolygonPath | null {\n const node = sc.get(id as NodeId);\n return pathEditPathOf(node as { pose: unknown; data: unknown }, extensions);\n },\n getOutlinePath(id: string): PolygonPath | null {\n return resolveEditablePathOf(sc.get(id as NodeId) as { pose: unknown; data: unknown });\n },\n getStorageKind(id: string): 'pose' | 'data' | null {\n const node = sc.get(id as NodeId);\n const storage = classifyPathStorage(node as { pose: unknown; data: unknown });\n return storage?.kind ?? null;\n },\n getNodeShape(id: string): { pose: unknown; data: unknown } | null {\n const node = sc.get(id as NodeId);\n if (!node) return null;\n return { pose: node.pose, data: node.data };\n },\n applyEdit(id: string, worldPath: unknown, label: string, origins?: readonly (PointOrigin | null)[]) {\n const ops = editOps(id, worldPath, label, origins);\n if (ops.length > 0) ad.applyOps(ops, label);\n },\n editOps,\n finishEdit(id: string, worldPath: unknown, origins?: readonly (PointOrigin | null)[]) {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n if (!node) return { path: worldPath, others: [] };\n const done = finishEdit(extensions, node, worldPath as PolygonPath, origins, finishCtx(sc, id, extensions));\n if (!done) return null;\n const others = [...done.others.values()].flatMap((o) => (o.path && !o.remove ? [{ id: o.id, path: o.path }] : []));\n return { path: done.path, others };\n },\n store(id, worldPath, label, data) {\n const node = sc.get(id as NodeId) as EditableNode | undefined;\n const ops = node ? reshapeOps(id, node, worldPath, label, data ?? null, extensions) : [];\n if (ops.length > 0) ad.applyOps(ops, label);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,gBAAgB,MA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AAS,KAAK,KAAK;EAC5C;CACF;AACF"}
|
|
@@ -3,6 +3,7 @@ import { definesFrame } from "../../core/scene/effectivePose.js";
|
|
|
3
3
|
import { cycleFill, solid, strokeOf } from "../../util/paint.js";
|
|
4
4
|
import { insertPreviewExtent } from "../insertPreviewExtent.js";
|
|
5
5
|
import { minSizeOf } from "../../core/scene/minSize.js";
|
|
6
|
+
import { insertParent } from "../../interactions/actions/insert/parent.js";
|
|
6
7
|
import { createInsertOp } from "../../core/ops/create.js";
|
|
7
8
|
import { stickyData } from "../../tools/builtin/sticky/stickyNode.js";
|
|
8
9
|
import { ellipsePath, linePath, polygonFromPoints, rectPath, regularPolygonPath, schneiderFit, starPath } from "@weasel-js/geom";
|
|
@@ -86,12 +87,13 @@ function boxKindData(kind, bounds, extras, painted) {
|
|
|
86
87
|
* or the top of the tree, on the first layer, when it names no container.
|
|
87
88
|
*/
|
|
88
89
|
function insertSite(sc, into) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
90
|
+
const parentId = insertParent(sc, into);
|
|
91
|
+
if (parentId === null) return {
|
|
91
92
|
parent: null,
|
|
92
93
|
layer: sc.layers[0]?.id ?? "default",
|
|
93
94
|
local: (p) => p
|
|
94
95
|
};
|
|
96
|
+
const parent = sc.get(parentId);
|
|
95
97
|
const composition = sc.composition;
|
|
96
98
|
if (composition === void 0 || !composesFrames(composition)) return {
|
|
97
99
|
parent: parent.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.js","names":["e"],"sources":["../../../src/canvas/deps/insert.ts"],"sourcesContent":["/**\n * `useInsertDepSource` — wires the `insert` dep consumed by `insertAction`.\n *\n * `line`, `polygon`, `star`, and `pencil` receive the drag AABB from the insertAction invoker,\n * but `extras` may carry richer geometry (endpoints, center+radius+rotation, point trail).\n * `insertPreviewExtent` resolves the two into the node's real extent — the same resolution the\n * live preview and the reported gesture bounds use.\n */\nimport { useRef } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { InsertDep, InsertExtras, InsertLive } from 'interactions/actions/depSchema';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { Op } from 'core/ops/types';\nimport { createInsertOp } from 'core/ops/create';\nimport {\n rectPath,\n ellipsePath,\n regularPolygonPath,\n starPath,\n linePath,\n polygonFromPoints,\n schneiderFit,\n type PathFillRule,\n type PolygonPath,\n} from '@weasel-js/geom';\nimport { insertPreviewExtent } from '../insertPreviewExtent';\nimport type { ShapeGenerator } from 'features/paths/shapeGenerator';\nimport type { Stroke, Fill } from '@weasel-js/paint';\nimport { cycleFill, solid, strokeOf } from '../../util/paint';\nimport { composesFrames, composeWorldPose } from 'core/scene/composeFrame';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { stickyData, type StickyStyle } from '../../tools/builtin/sticky/stickyNode';\nimport { minSizeOf } from 'core/scene/minSize';\n\ninterface OpsApplier {\n applyOps(ops: Op[], label?: string): void;\n}\n\n/**\n * Consumer-supplied node factory for one insert `kind`. Given the drag AABB\n * and the tool's `extras`, returns the node's `data` (in the consumer's own\n * data shape) plus an optional `pose` override — the dep supplies id, layer,\n * and the undoable insert op. Return `null` to reject the insert.\n *\n * A factory registered for a kit kind (`rect`, `line`, …) fully replaces the\n * kit's default `{ path, fill }` factory for that kind; a factory for a novel\n * kind adds support the kit doesn't ship (e.g. `text`). To change only the\n * paint of a kit shape, pass an {@link InsertPaint}. See\n * `SceneCanvas`'s `insertNodeFactories` prop.\n */\nexport type InsertNodeFactory = (\n bounds: { x: number; y: number; width: number; height: number },\n extras: InsertExtras,\n) => { data: unknown; pose?: unknown } | null;\n\n/**\n * The paint a kit-built shape is inserted with. `kind` is the shape being\n * built and `seq` counts this canvas's inserts from 1. A key left out stays\n * off the node, so its painter's default applies; `null` is \"none\". A pencil\n * trail too short to fit is built as a rect and asks as one. A line and an\n * open pen path are inserted unfilled: a fill given to either is dropped.\n * `fillRule` is the rule a path that carries one is built with, where the\n * kit's own is nonzero; a rect or an ellipse has none to set.\n *\n * It paints only the shapes the kit builds: an `InsertNodeFactory` owns its\n * node's whole `data`. See `SceneCanvas`'s `insertPaint` prop.\n */\nexport type InsertPaint = (kind: string, seq: number) => {\n fill?: Fill | null;\n stroke?: Stroke | null;\n fillRule?: PathFillRule;\n};\n\nfunction paintKeys({ fill, stroke }: ReturnType<InsertPaint>): { fill?: Fill | null; stroke?: Stroke | null } {\n return { ...(fill !== undefined ? { fill } : {}), ...(stroke !== undefined ? { stroke } : {}) };\n}\n\nfunction withFillRule(data: unknown, rule: PathFillRule | undefined): unknown {\n const path = (data as { path?: object } | undefined)?.path;\n if (rule === undefined || path === undefined || !('fillRule' in path)) return data;\n return { ...(data as object), path: { ...path, fillRule: rule } };\n}\n\n/** The default {@link InsertPaint}: the next color of the kit palette, as a\n * fill on a closed shape, a fill and a stroke on a pen path, and a stroke\n * alone on a line or a pencil trail. */\nexport const paletteInsertPaint: InsertPaint = (kind, seq) => {\n const color = cycleFill(seq);\n if (kind === 'line' || kind === 'pencil') return { stroke: strokeOf(color, 2) };\n if (kind === 'path') return { fill: { paint: solid(color) }, stroke: strokeOf(color, 2) };\n return { fill: { paint: solid(color) } };\n};\n\n/** The kit's default data for a kind drawn as a box, or `null` for a kind it has none for. */\nfunction boxKindData(\n kind: string,\n bounds: { x: number; y: number; width: number; height: number },\n extras: InsertExtras,\n painted: (as?: string) => ReturnType<typeof paintKeys>,\n): unknown {\n switch (kind) {\n case 'rect':\n // The rect path lives at the origin and the pose carries position:\n // `pathInPoseFrame` rebases a rect path onto the pose box, so don't\n // double-count the position.\n return { path: rectPath(0, 0, bounds.width, bounds.height), ...painted() };\n case 'ellipse':\n return { path: ellipsePath(bounds), ...painted() };\n case 'path': {\n const e = extras as { path: PolygonPath; closed: boolean; data?: Readonly<Record<string, unknown>> };\n return { ...e.data, path: e.path, ...painted(), ...(e.closed ? {} : { fill: null }) };\n }\n case 'text': {\n // The built-in text tool drags an empty text box you then type into, so\n // `extras` carries no content. The kit:text painter matches on\n // `data.text != null` and applies style defaults at render time, so a bare\n // `{ text }` is a complete, editable node.\n const e = extras as Partial<{ text: string }>;\n return { text: e.text ?? '' };\n }\n case 'sticky':\n return stickyData(extras as StickyStyle & { text?: string });\n case 'image': {\n // The bitmap is loaded + cached by `imageCache` keyed on `src`;\n // only the (serializable) `src` lives on the node.\n const e = extras as Partial<{ src: string; opacity: number }>;\n return { image: { src: e.src ?? '', ...(e.opacity !== undefined ? { opacity: e.opacity } : {}) } };\n }\n default:\n return null;\n }\n}\n\n/**\n * Where an insert lands: the container the `insertInto` dep names, on that container's\n * layer, with the pose made local to it when the scene composes frames —\n * or the top of the tree, on the first layer, when it names no container.\n */\nfunction insertSite(\n sc: Scene<unknown, string, unknown>,\n into: string | null | undefined,\n): { parent: NodeId | null; layer: string; local: (world: unknown) => unknown } {\n const parent = into == null ? undefined : sc.get(into as NodeId);\n if (parent === undefined || parent.kind !== 'container') {\n return { parent: null, layer: (sc.layers[0]?.id ?? 'default') as string, local: (p) => p };\n }\n const composition = sc.composition;\n if (composition === undefined || !composesFrames(composition)) {\n return { parent: parent.id, layer: parent.layer, local: (p) => p };\n }\n const frame = composeWorldPose({\n getPose: (id) => sc.get(id as NodeId)!.pose,\n getParent: (id) => sc.get(id as NodeId)?.parent ?? null,\n definesFrame: (id) => definesFrame(sc.get(id as NodeId) ?? {}),\n }, parent.id, composition.compose);\n return { parent: parent.id, layer: parent.layer, local: (p) => composition.decompose(frame, p) };\n}\n\nexport function useInsertDepSource(\n scene: Scene<unknown, string, unknown>,\n adapter: OpsApplier,\n factories?: Record<string, InsertNodeFactory>,\n paint: InsertPaint = paletteInsertPaint,\n): void {\n const sceneRef = useLatest(scene);\n const adapterRef = useLatest(adapter);\n const factoriesRef = useLatest(factories);\n const paintRef = useLatest(paint);\n const registry = useDepRegistry();\n const insertSeqRef = useRef(0);\n const liveRef = useRef<InsertLive>({ gesture: null });\n useDepSource('insertLive', () => liveRef.current);\n\n useDepSource('insert', (): InsertDep => {\n const sc = sceneRef.current;\n const ad = adapterRef.current;\n\n const site = () => insertSite(sc, registry.get('insertInto')?.get());\n const build: NonNullable<InsertDep['build']> = (bounds, extras) => {\n const kind = extras.kind;\n const { parent, layer, local } = site();\n const seq = ++insertSeqRef.current;\n const id = sc.mintId();\n let asked: ReturnType<InsertPaint> | undefined;\n const painted = (as: string = kind) => paintKeys(asked = paintRef.current(as, seq));\n\n // The nascent node's extent — drag AABB reconciled with whatever\n // richer geometry `extras` carries.\n const extent = insertPreviewExtent({ shape: kind, bounds, extras });\n const pose: unknown = extent.bounds;\n\n // Consumer factory wins over the kit default for this kind. It owns the node's\n // data + optional pose; the dep still supplies id/layer/op.\n const factory = factoriesRef.current?.[kind];\n if (factory) {\n const built = factory(bounds, extras);\n if (built === null) return null;\n return {\n id,\n ops: [createInsertOp({ node: { id, kind: 'leaf', layer, parent, pose: local(built.pose ?? pose), data: built.data } as unknown as { id: string }, label: `Insert ${kind}` })],\n };\n }\n\n const geom = extent.geometry;\n let data: unknown;\n\n switch (geom.kind) {\n case 'line':\n data = { path: linePath(geom.a, geom.b), ...painted(), fill: null };\n break;\n case 'polygon':\n data = {\n path: regularPolygonPath(geom.center, geom.radius, geom.sides, geom.rotation),\n generator: { kind: 'polygon', sides: geom.sides, rotation: geom.rotation } satisfies ShapeGenerator,\n ...painted(),\n };\n break;\n case 'star':\n data = {\n path: starPath(geom.center, geom.outerRadius, geom.points, geom.innerRadius, geom.rotation),\n generator: {\n kind: 'star',\n points: geom.points,\n innerRadiusRatio: geom.outerRadius === 0 ? 0.5 : geom.innerRadius / geom.outerRadius,\n rotation: geom.rotation,\n } satisfies ShapeGenerator,\n ...painted(),\n };\n break;\n case 'pencil': {\n const samples = geom.samples as { x: number; y: number }[];\n if (samples.length >= 4) {\n data = { path: schneiderFit(samples, 2.0), ...painted() };\n } else if (samples.length >= 2) {\n data = { path: polygonFromPoints(samples), ...painted() };\n } else {\n data = { path: rectPath(0, 0, extent.bounds.width, extent.bounds.height), ...painted('rect') };\n }\n break;\n }\n case 'box':\n data = boxKindData(kind, extent.bounds, extras, painted);\n if (data === null) {\n console.warn(`weasel insertDep: no factory for kind=\"${kind}\". Skipping insert.`);\n return null;\n }\n break;\n }\n\n data = withFillRule(data, asked?.fillRule);\n const min = minSizeOf(extras);\n if (min) data = { ...(data as object), minSize: min };\n return {\n id,\n ops: [createInsertOp({ node: { id, kind: 'leaf', layer, parent, pose: local(pose), data } as unknown as { id: string }, label: `Insert ${kind}` })],\n };\n };\n return {\n layer: () => site().layer,\n build,\n commit(bounds, extras, ends): NodeId | null {\n const built = build(bounds, extras, ends);\n if (built === null) return null;\n ad.applyOps(built.ops, `Insert ${extras.kind}`);\n return built.id;\n },\n };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0EA,SAAS,UAAU,EAAE,MAAM,UAAmF;CAC5G,OAAO;EAAE,GAAI,SAAS,SAAY,EAAE,KAAK,IAAI,CAAC;EAAI,GAAI,WAAW,SAAY,EAAE,OAAO,IAAI,CAAC;CAAG;AAChG;AAEA,SAAS,aAAa,MAAe,MAAyC;CAC5E,MAAM,OAAQ,MAAwC;CACtD,IAAI,SAAS,UAAa,SAAS,UAAa,EAAE,cAAc,OAAO,OAAO;CAC9E,OAAO;EAAE,GAAI;EAAiB,MAAM;GAAE,GAAG;GAAM,UAAU;EAAK;CAAE;AAClE;;;;AAKA,IAAa,sBAAmC,MAAM,QAAQ;CAC5D,MAAM,QAAQ,UAAU,GAAG;CAC3B,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO,EAAE,QAAQ,SAAS,OAAO,CAAC,EAAE;CAC9E,IAAI,SAAS,QAAQ,OAAO;EAAE,MAAM,EAAE,OAAO,MAAM,KAAK,EAAE;EAAG,QAAQ,SAAS,OAAO,CAAC;CAAE;CACxF,OAAO,EAAE,MAAM,EAAE,OAAO,MAAM,KAAK,EAAE,EAAE;AACzC;;AAGA,SAAS,YACP,MACA,QACA,QACA,SACS;CACT,QAA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IACA,KAAK,CAAC,eAAe;KAAE,MAAM;MAAE;MAAI,MAAM;MAAQ;MAAO;MAAQ,MAAM,MAAM,IAAI;MAAG;KAAK;KAAgC,OAAO,UAAU;IAAO,CAAC,CAAC;GACpJ;EACJ;EACA,OAAO;GACL,aAAa,KAAK,CAAC,CAAC;GACpB;GACA,OAAO,QAAQ,QAAQ,MAAqB;IAC1C,MAAM,QAAQ,MAAM,QAAQ,QAAQ,IAAI;IACxC,IAAI,UAAU,MAAM,OAAO;IAC3B,GAAG,SAAS,MAAM,KAAK,UAAU,OAAO,MAAM;IAC9C,OAAO,MAAM;GACf;EACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"insert.js","names":["e"],"sources":["../../../src/canvas/deps/insert.ts"],"sourcesContent":["/**\n * `useInsertDepSource` — wires the `insert` dep consumed by `insertAction`.\n *\n * `line`, `polygon`, `star`, and `pencil` receive the drag AABB from the insertAction invoker,\n * but `extras` may carry richer geometry (endpoints, center+radius+rotation, point trail).\n * `insertPreviewExtent` resolves the two into the node's real extent — the same resolution the\n * live preview and the reported gesture bounds use.\n */\nimport { useRef } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { InsertDep, InsertExtras, InsertLive } from 'interactions/actions/depSchema';\nimport { insertParent } from 'interactions/actions/insert/parent';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { Op } from 'core/ops/types';\nimport { createInsertOp } from 'core/ops/create';\nimport {\n rectPath,\n ellipsePath,\n regularPolygonPath,\n starPath,\n linePath,\n polygonFromPoints,\n schneiderFit,\n type PathFillRule,\n type PolygonPath,\n} from '@weasel-js/geom';\nimport { insertPreviewExtent } from '../insertPreviewExtent';\nimport type { ShapeGenerator } from 'features/paths/shapeGenerator';\nimport type { Stroke, Fill } from '@weasel-js/paint';\nimport { cycleFill, solid, strokeOf } from '../../util/paint';\nimport { composesFrames, composeWorldPose } from 'core/scene/composeFrame';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { stickyData, type StickyStyle } from '../../tools/builtin/sticky/stickyNode';\nimport { minSizeOf } from 'core/scene/minSize';\n\ninterface OpsApplier {\n applyOps(ops: Op[], label?: string): void;\n}\n\n/**\n * Consumer-supplied node factory for one insert `kind`. Given the drag AABB\n * and the tool's `extras`, returns the node's `data` (in the consumer's own\n * data shape) plus an optional `pose` override — the dep supplies id, layer,\n * and the undoable insert op. Return `null` to reject the insert.\n *\n * A factory registered for a kit kind (`rect`, `line`, …) fully replaces the\n * kit's default `{ path, fill }` factory for that kind; a factory for a novel\n * kind adds support the kit doesn't ship (e.g. `text`). To change only the\n * paint of a kit shape, pass an {@link InsertPaint}. See\n * `SceneCanvas`'s `insertNodeFactories` prop.\n */\nexport type InsertNodeFactory = (\n bounds: { x: number; y: number; width: number; height: number },\n extras: InsertExtras,\n) => { data: unknown; pose?: unknown } | null;\n\n/**\n * The paint a kit-built shape is inserted with. `kind` is the shape being\n * built and `seq` counts this canvas's inserts from 1. A key left out stays\n * off the node, so its painter's default applies; `null` is \"none\". A pencil\n * trail too short to fit is built as a rect and asks as one. A line and an\n * open pen path are inserted unfilled: a fill given to either is dropped.\n * `fillRule` is the rule a path that carries one is built with, where the\n * kit's own is nonzero; a rect or an ellipse has none to set.\n *\n * It paints only the shapes the kit builds: an `InsertNodeFactory` owns its\n * node's whole `data`. See `SceneCanvas`'s `insertPaint` prop.\n */\nexport type InsertPaint = (kind: string, seq: number) => {\n fill?: Fill | null;\n stroke?: Stroke | null;\n fillRule?: PathFillRule;\n};\n\nfunction paintKeys({ fill, stroke }: ReturnType<InsertPaint>): { fill?: Fill | null; stroke?: Stroke | null } {\n return { ...(fill !== undefined ? { fill } : {}), ...(stroke !== undefined ? { stroke } : {}) };\n}\n\nfunction withFillRule(data: unknown, rule: PathFillRule | undefined): unknown {\n const path = (data as { path?: object } | undefined)?.path;\n if (rule === undefined || path === undefined || !('fillRule' in path)) return data;\n return { ...(data as object), path: { ...path, fillRule: rule } };\n}\n\n/** The default {@link InsertPaint}: the next color of the kit palette, as a\n * fill on a closed shape, a fill and a stroke on a pen path, and a stroke\n * alone on a line or a pencil trail. */\nexport const paletteInsertPaint: InsertPaint = (kind, seq) => {\n const color = cycleFill(seq);\n if (kind === 'line' || kind === 'pencil') return { stroke: strokeOf(color, 2) };\n if (kind === 'path') return { fill: { paint: solid(color) }, stroke: strokeOf(color, 2) };\n return { fill: { paint: solid(color) } };\n};\n\n/** The kit's default data for a kind drawn as a box, or `null` for a kind it has none for. */\nfunction boxKindData(\n kind: string,\n bounds: { x: number; y: number; width: number; height: number },\n extras: InsertExtras,\n painted: (as?: string) => ReturnType<typeof paintKeys>,\n): unknown {\n switch (kind) {\n case 'rect':\n // The rect path lives at the origin and the pose carries position:\n // `pathInPoseFrame` rebases a rect path onto the pose box, so don't\n // double-count the position.\n return { path: rectPath(0, 0, bounds.width, bounds.height), ...painted() };\n case 'ellipse':\n return { path: ellipsePath(bounds), ...painted() };\n case 'path': {\n const e = extras as { path: PolygonPath; closed: boolean; data?: Readonly<Record<string, unknown>> };\n return { ...e.data, path: e.path, ...painted(), ...(e.closed ? {} : { fill: null }) };\n }\n case 'text': {\n // The built-in text tool drags an empty text box you then type into, so\n // `extras` carries no content. The kit:text painter matches on\n // `data.text != null` and applies style defaults at render time, so a bare\n // `{ text }` is a complete, editable node.\n const e = extras as Partial<{ text: string }>;\n return { text: e.text ?? '' };\n }\n case 'sticky':\n return stickyData(extras as StickyStyle & { text?: string });\n case 'image': {\n // The bitmap is loaded + cached by `imageCache` keyed on `src`;\n // only the (serializable) `src` lives on the node.\n const e = extras as Partial<{ src: string; opacity: number }>;\n return { image: { src: e.src ?? '', ...(e.opacity !== undefined ? { opacity: e.opacity } : {}) } };\n }\n default:\n return null;\n }\n}\n\n/**\n * Where an insert lands: the container the `insertInto` dep names, on that container's\n * layer, with the pose made local to it when the scene composes frames —\n * or the top of the tree, on the first layer, when it names no container.\n */\nfunction insertSite(\n sc: Scene<unknown, string, unknown>,\n into: string | null | undefined,\n): { parent: NodeId | null; layer: string; local: (world: unknown) => unknown } {\n const parentId = insertParent(sc, into);\n if (parentId === null) {\n return { parent: null, layer: (sc.layers[0]?.id ?? 'default') as string, local: (p) => p };\n }\n const parent = sc.get(parentId)!;\n const composition = sc.composition;\n if (composition === undefined || !composesFrames(composition)) {\n return { parent: parent.id, layer: parent.layer, local: (p) => p };\n }\n const frame = composeWorldPose({\n getPose: (id) => sc.get(id as NodeId)!.pose,\n getParent: (id) => sc.get(id as NodeId)?.parent ?? null,\n definesFrame: (id) => definesFrame(sc.get(id as NodeId) ?? {}),\n }, parent.id, composition.compose);\n return { parent: parent.id, layer: parent.layer, local: (p) => composition.decompose(frame, p) };\n}\n\nexport function useInsertDepSource(\n scene: Scene<unknown, string, unknown>,\n adapter: OpsApplier,\n factories?: Record<string, InsertNodeFactory>,\n paint: InsertPaint = paletteInsertPaint,\n): void {\n const sceneRef = useLatest(scene);\n const adapterRef = useLatest(adapter);\n const factoriesRef = useLatest(factories);\n const paintRef = useLatest(paint);\n const registry = useDepRegistry();\n const insertSeqRef = useRef(0);\n const liveRef = useRef<InsertLive>({ gesture: null });\n useDepSource('insertLive', () => liveRef.current);\n\n useDepSource('insert', (): InsertDep => {\n const sc = sceneRef.current;\n const ad = adapterRef.current;\n\n const site = () => insertSite(sc, registry.get('insertInto')?.get());\n const build: NonNullable<InsertDep['build']> = (bounds, extras) => {\n const kind = extras.kind;\n const { parent, layer, local } = site();\n const seq = ++insertSeqRef.current;\n const id = sc.mintId();\n let asked: ReturnType<InsertPaint> | undefined;\n const painted = (as: string = kind) => paintKeys(asked = paintRef.current(as, seq));\n\n // The nascent node's extent — drag AABB reconciled with whatever\n // richer geometry `extras` carries.\n const extent = insertPreviewExtent({ shape: kind, bounds, extras });\n const pose: unknown = extent.bounds;\n\n // Consumer factory wins over the kit default for this kind. It owns the node's\n // data + optional pose; the dep still supplies id/layer/op.\n const factory = factoriesRef.current?.[kind];\n if (factory) {\n const built = factory(bounds, extras);\n if (built === null) return null;\n return {\n id,\n ops: [createInsertOp({ node: { id, kind: 'leaf', layer, parent, pose: local(built.pose ?? pose), data: built.data } as unknown as { id: string }, label: `Insert ${kind}` })],\n };\n }\n\n const geom = extent.geometry;\n let data: unknown;\n\n switch (geom.kind) {\n case 'line':\n data = { path: linePath(geom.a, geom.b), ...painted(), fill: null };\n break;\n case 'polygon':\n data = {\n path: regularPolygonPath(geom.center, geom.radius, geom.sides, geom.rotation),\n generator: { kind: 'polygon', sides: geom.sides, rotation: geom.rotation } satisfies ShapeGenerator,\n ...painted(),\n };\n break;\n case 'star':\n data = {\n path: starPath(geom.center, geom.outerRadius, geom.points, geom.innerRadius, geom.rotation),\n generator: {\n kind: 'star',\n points: geom.points,\n innerRadiusRatio: geom.outerRadius === 0 ? 0.5 : geom.innerRadius / geom.outerRadius,\n rotation: geom.rotation,\n } satisfies ShapeGenerator,\n ...painted(),\n };\n break;\n case 'pencil': {\n const samples = geom.samples as { x: number; y: number }[];\n if (samples.length >= 4) {\n data = { path: schneiderFit(samples, 2.0), ...painted() };\n } else if (samples.length >= 2) {\n data = { path: polygonFromPoints(samples), ...painted() };\n } else {\n data = { path: rectPath(0, 0, extent.bounds.width, extent.bounds.height), ...painted('rect') };\n }\n break;\n }\n case 'box':\n data = boxKindData(kind, extent.bounds, extras, painted);\n if (data === null) {\n console.warn(`weasel insertDep: no factory for kind=\"${kind}\". Skipping insert.`);\n return null;\n }\n break;\n }\n\n data = withFillRule(data, asked?.fillRule);\n const min = minSizeOf(extras);\n if (min) data = { ...(data as object), minSize: min };\n return {\n id,\n ops: [createInsertOp({ node: { id, kind: 'leaf', layer, parent, pose: local(pose), data } as unknown as { id: string }, label: `Insert ${kind}` })],\n };\n };\n return {\n layer: () => site().layer,\n build,\n commit(bounds, extras, ends): NodeId | null {\n const built = build(bounds, extras, ends);\n if (built === null) return null;\n ad.applyOps(built.ops, `Insert ${extras.kind}`);\n return built.id;\n },\n };\n });\n}\n"],"m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";
|
|
2
|
+
import { createSetDataOp } from "../../core/ops/setData.js";
|
|
3
|
+
import { createDeleteOp } from "../../core/ops/delete.js";
|
|
4
|
+
import { pathEditPathOf, storeEditablePath } from "../../features/paths/editablePath.js";
|
|
5
|
+
import { withoutShapeGenerator } from "../../features/paths/shapeGenerator.js";
|
|
6
|
+
import { withoutGeometryBoundData } from "../../features/paths/pathEditExtension.js";
|
|
7
|
+
import { writtenBy } from "../../core/ops/writtenBy.js";
|
|
8
|
+
|
|
9
|
+
//#region src/canvas/deps/pathEditCommits.ts
|
|
10
|
+
/** The nodes that list `id` in their `dependsOn`, directly or through others. */
|
|
11
|
+
function dependentsOf(sc, id) {
|
|
12
|
+
if (!sc.get(id)) return [];
|
|
13
|
+
return sc.removalClosure([id]).filter((d) => d !== id && !sc.ancestorsOf(d).includes(id));
|
|
14
|
+
}
|
|
15
|
+
/** The scene as an extension's `finishEdit` reads it. */
|
|
16
|
+
function finishCtx(sc, id, extensions) {
|
|
17
|
+
return {
|
|
18
|
+
id,
|
|
19
|
+
node(nid) {
|
|
20
|
+
const node = sc.get(nid);
|
|
21
|
+
return node ? {
|
|
22
|
+
pose: node.pose,
|
|
23
|
+
data: node.data,
|
|
24
|
+
dependsOn: node.dependsOn
|
|
25
|
+
} : null;
|
|
26
|
+
},
|
|
27
|
+
path: (nid) => pathEditPathOf(sc.get(nid), extensions),
|
|
28
|
+
dependents: (nid) => dependentsOf(sc, nid)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** `o` laid over what `others` already holds for its node. */
|
|
32
|
+
function addOther(others, o) {
|
|
33
|
+
const had = others.get(o.id);
|
|
34
|
+
others.set(o.id, {
|
|
35
|
+
id: o.id,
|
|
36
|
+
path: o.path ?? had?.path,
|
|
37
|
+
data: o.data || had?.data ? {
|
|
38
|
+
...had?.data,
|
|
39
|
+
...o.data
|
|
40
|
+
} : void 0,
|
|
41
|
+
remove: o.remove || had?.remove
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** `worldPath` finished by each of `extensions` in turn, the data they set
|
|
45
|
+
* beside it, and the other nodes they change; null when one cannot finish it. */
|
|
46
|
+
function finishEdit(extensions, node, worldPath, origins, ctx) {
|
|
47
|
+
let path = worldPath;
|
|
48
|
+
let data = null;
|
|
49
|
+
const others = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const ext of extensions) {
|
|
51
|
+
if (!ext.finishEdit) continue;
|
|
52
|
+
const done = ext.finishEdit(node, path, origins, ctx);
|
|
53
|
+
if (!done) return null;
|
|
54
|
+
path = done.path;
|
|
55
|
+
if (done.data) data = {
|
|
56
|
+
...data ?? {},
|
|
57
|
+
...done.data
|
|
58
|
+
};
|
|
59
|
+
for (const o of done.others ?? []) addOther(others, o);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
path,
|
|
63
|
+
data,
|
|
64
|
+
others
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The ops that commit `others`, each from its node as committed. */
|
|
68
|
+
function otherOps(sc, others, label, extensions) {
|
|
69
|
+
return [...others.values()].flatMap((o) => {
|
|
70
|
+
const node = sc.get(o.id);
|
|
71
|
+
if (!node) return [];
|
|
72
|
+
if (o.remove) return [createDeleteOp({
|
|
73
|
+
node: sc.get(o.id),
|
|
74
|
+
label
|
|
75
|
+
})];
|
|
76
|
+
if (o.path) return reshapeOps(o.id, node, o.path, label, o.data ?? null, extensions);
|
|
77
|
+
return o.data ? [createSetDataOp({
|
|
78
|
+
id: o.id,
|
|
79
|
+
from: node.data,
|
|
80
|
+
to: {
|
|
81
|
+
...node.data,
|
|
82
|
+
...o.data
|
|
83
|
+
},
|
|
84
|
+
label
|
|
85
|
+
})] : [];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** The ops that store `worldPath` where `node` keeps its polygon, with `patch` laid over its data. */
|
|
89
|
+
function reshapeOps(id, node, worldPath, label, patch, extensions) {
|
|
90
|
+
const next = storeEditablePath(node, worldPath, extensions);
|
|
91
|
+
if (!next) return [];
|
|
92
|
+
const reshape = createTransformOp({
|
|
93
|
+
id,
|
|
94
|
+
from: node.pose,
|
|
95
|
+
to: next.pose,
|
|
96
|
+
label
|
|
97
|
+
});
|
|
98
|
+
const data = withoutGeometryBoundData(next.data === node.data ? node.data : withoutShapeGenerator(next.data), [
|
|
99
|
+
"skin",
|
|
100
|
+
"constraints",
|
|
101
|
+
"representation"
|
|
102
|
+
]);
|
|
103
|
+
if (data === node.data && !patch) return [reshape];
|
|
104
|
+
return [reshape, createSetDataOp({
|
|
105
|
+
id,
|
|
106
|
+
from: node.data,
|
|
107
|
+
to: {
|
|
108
|
+
...data,
|
|
109
|
+
...patch
|
|
110
|
+
},
|
|
111
|
+
label
|
|
112
|
+
})];
|
|
113
|
+
}
|
|
114
|
+
/** The other nodes `extensions` change along with a transform that leaves the nodes in `after` as given; null when one refuses it. */
|
|
115
|
+
function transformOthers(sc, extensions, after) {
|
|
116
|
+
const others = /* @__PURE__ */ new Map();
|
|
117
|
+
const finishing = extensions.filter((e) => e.finishTransform);
|
|
118
|
+
if (finishing.length === 0 || after.size === 0) return others;
|
|
119
|
+
const nodeAfter = (id) => {
|
|
120
|
+
const node = sc.get(id);
|
|
121
|
+
if (!node) return null;
|
|
122
|
+
const written = after.get(id);
|
|
123
|
+
return {
|
|
124
|
+
pose: written?.pose ?? node.pose,
|
|
125
|
+
data: written?.data ?? node.data,
|
|
126
|
+
dependsOn: node.dependsOn
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const ctx = {
|
|
130
|
+
ids: [...after.keys()],
|
|
131
|
+
node: nodeAfter,
|
|
132
|
+
path: (id) => pathEditPathOf(nodeAfter(id) ?? void 0, extensions),
|
|
133
|
+
before: (id) => pathEditPathOf(sc.get(id), extensions),
|
|
134
|
+
dependents: (id) => dependentsOf(sc, id)
|
|
135
|
+
};
|
|
136
|
+
for (const ext of finishing) {
|
|
137
|
+
const done = ext.finishTransform(ctx);
|
|
138
|
+
if (!done) return null;
|
|
139
|
+
for (const o of done) if (!after.has(o.id)) addOther(others, o);
|
|
140
|
+
}
|
|
141
|
+
return others;
|
|
142
|
+
}
|
|
143
|
+
/** `ops`, a whole-node transform's batch, with the ops `extensions` add for the other nodes it changes; null when one refuses it. */
|
|
144
|
+
function transformOps(sc, extensions, ops, label) {
|
|
145
|
+
const after = extensions.some((e) => e.finishTransform) ? writtenBy(sc, ops) : null;
|
|
146
|
+
if (!after || after.size === 0) return [...ops];
|
|
147
|
+
const others = transformOthers(sc, extensions, after);
|
|
148
|
+
return others && [...ops, ...otherOps(sc, others, label, extensions)];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The other nodes `extensions` change along with a transform frame that
|
|
152
|
+
* poses the nodes in `poses` as given, each as it would be stored — what
|
|
153
|
+
* {@link transformOps} would commit for that frame, read the same way. Empty
|
|
154
|
+
* when nothing changes with it, or an extension refuses it.
|
|
155
|
+
*/
|
|
156
|
+
function transformPreview(sc, extensions, poses) {
|
|
157
|
+
if (poses.size === 0 || !extensions.some((e) => e.finishTransform)) return [];
|
|
158
|
+
const after = /* @__PURE__ */ new Map();
|
|
159
|
+
for (const [id, pose] of poses) {
|
|
160
|
+
const node = sc.get(id);
|
|
161
|
+
if (node) after.set(id, {
|
|
162
|
+
pose,
|
|
163
|
+
data: node.data
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return [...transformOthers(sc, extensions, after)?.values() ?? []].flatMap((o) => {
|
|
167
|
+
const node = sc.get(o.id);
|
|
168
|
+
const stored = node && o.path && !o.remove ? storeEditablePath(node, o.path, extensions) : null;
|
|
169
|
+
if (!node || !stored) return [];
|
|
170
|
+
return [stored.data === node.data ? {
|
|
171
|
+
id: o.id,
|
|
172
|
+
pose: stored.pose
|
|
173
|
+
} : {
|
|
174
|
+
id: o.id,
|
|
175
|
+
pose: stored.pose,
|
|
176
|
+
data: stored.data
|
|
177
|
+
}];
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** The transform follower `extensions` make: each one's `finishTransform`, as
|
|
181
|
+
* {@link transformOps} and {@link transformPreview} read it. Null when none
|
|
182
|
+
* has one, so a transform runs no follower for them. */
|
|
183
|
+
function pathEditFollower(sc, extensions) {
|
|
184
|
+
if (!extensions.some((e) => e.finishTransform)) return null;
|
|
185
|
+
return {
|
|
186
|
+
finish: (ops, label) => transformOps(sc, extensions, ops, label),
|
|
187
|
+
preview: (poses) => transformPreview(sc, extensions, poses)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
export { finishCtx, finishEdit, otherOps, pathEditFollower, reshapeOps, transformOps, transformPreview };
|
|
193
|
+
//# sourceMappingURL=pathEditCommits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathEditCommits.js","names":[],"sources":["../../../src/canvas/deps/pathEditCommits.ts"],"sourcesContent":["/**\n * What the `editAnchors` dep commits: an edit finished by every path-edit\n * extension, the other nodes the extensions change with it, and the same for\n * a whole-node transform's batch.\n */\nimport type { PointOrigin, PolygonPath } from '@weasel-js/geom';\nimport type { Op } from 'core/ops/types';\nimport { createTransformOp } from 'core/ops/transform';\nimport { createSetDataOp } from 'core/ops/setData';\nimport { createDeleteOp } from 'core/ops/delete';\nimport { writtenBy } from 'core/ops/writtenBy';\nimport type { TransformFollower, TransformPreviewNode } from 'interactions/actions/transformFinish';\nimport type { NodeId, Scene } from 'core/scene/types';\nimport { pathEditPathOf, storeEditablePath } from 'features/paths/editablePath';\nimport { withoutShapeGenerator } from 'features/paths/shapeGenerator';\nimport {\n withoutGeometryBoundData, type PathEditExtension, type PathEditFinishCtx, type PathEditOther, type PathTransformFinishCtx,\n} from 'features/paths/pathEditExtension';\n\ntype AnyScene = Scene<unknown, string, unknown>;\nexport type EditableNode = { pose: unknown; data: unknown };\n\n/** What {@link finishEdit} answers: the edited path, the data set beside it, and the other nodes it changes, by id. */\nexport interface Finished {\n path: PolygonPath;\n data: Record<string, unknown> | null;\n others: Map<string, PathEditOther>;\n}\n\n/** The nodes that list `id` in their `dependsOn`, directly or through others. */\nfunction dependentsOf(sc: AnyScene, id: string): readonly string[] {\n if (!sc.get(id as NodeId)) return [];\n return sc.removalClosure([id as NodeId]).filter((d) => d !== id && !sc.ancestorsOf(d).includes(id as NodeId));\n}\n\n/** The scene as an extension's `finishEdit` reads it. */\nexport function finishCtx(sc: AnyScene, id: string, extensions: readonly PathEditExtension[]): PathEditFinishCtx {\n return {\n id,\n node(nid) {\n const node = sc.get(nid as NodeId);\n return node ? { pose: node.pose, data: node.data, dependsOn: node.dependsOn } : null;\n },\n path: (nid) => pathEditPathOf(sc.get(nid as NodeId) as EditableNode | undefined, extensions),\n dependents: (nid) => dependentsOf(sc, nid),\n };\n}\n\n/** `o` laid over what `others` already holds for its node. */\nfunction addOther(others: Map<string, PathEditOther>, o: PathEditOther): void {\n const had = others.get(o.id);\n others.set(o.id, {\n id: o.id,\n path: o.path ?? had?.path,\n data: o.data || had?.data ? { ...had?.data, ...o.data } : undefined,\n remove: o.remove || had?.remove,\n });\n}\n\n/** `worldPath` finished by each of `extensions` in turn, the data they set\n * beside it, and the other nodes they change; null when one cannot finish it. */\nexport function finishEdit(\n extensions: readonly PathEditExtension[],\n node: EditableNode,\n worldPath: PolygonPath,\n origins: readonly (PointOrigin | null)[] | undefined,\n ctx: PathEditFinishCtx,\n): Finished | null {\n let path = worldPath;\n let data: Record<string, unknown> | null = null;\n const others = new Map<string, PathEditOther>();\n for (const ext of extensions) {\n if (!ext.finishEdit) continue;\n const done = ext.finishEdit(node, path, origins, ctx);\n if (!done) return null;\n path = done.path;\n if (done.data) data = { ...(data ?? {}), ...done.data };\n for (const o of done.others ?? []) addOther(others, o);\n }\n return { path, data, others };\n}\n\n/** The ops that commit `others`, each from its node as committed. */\nexport function otherOps(\n sc: AnyScene,\n others: ReadonlyMap<string, PathEditOther>,\n label: string,\n extensions: readonly PathEditExtension[],\n): Op[] {\n return [...others.values()].flatMap((o) => {\n const node = sc.get(o.id as NodeId) as EditableNode | undefined;\n if (!node) return [];\n if (o.remove) return [createDeleteOp({ node: sc.get(o.id as NodeId)!, label })];\n if (o.path) return reshapeOps(o.id, node, o.path, label, o.data ?? null, extensions);\n return o.data ? [createSetDataOp({ id: o.id, from: node.data, to: { ...(node.data as object), ...o.data }, label })] : [];\n });\n}\n\n/** The ops that store `worldPath` where `node` keeps its polygon, with `patch` laid over its data. */\nexport function reshapeOps(\n id: string,\n node: EditableNode,\n worldPath: PolygonPath,\n label: string,\n patch: Record<string, unknown> | null,\n extensions: readonly PathEditExtension[],\n): Op[] {\n const next = storeEditablePath(node, worldPath, extensions);\n if (!next) return [];\n const reshape = createTransformOp({ id, from: node.pose, to: next.pose, label });\n // A path edited by hand is no longer what its generator or warp makes: it becomes plain geometry.\n // Its skin and constraints stay, renumbered by the caller's patch where it has one, and the\n // form it was drawn from as storing it left it.\n const data = withoutGeometryBoundData(\n next.data === node.data ? node.data : withoutShapeGenerator(next.data), ['skin', 'constraints', 'representation'],\n );\n if (data === node.data && !patch) return [reshape];\n return [reshape, createSetDataOp({ id, from: node.data, to: { ...(data as object), ...patch }, label })];\n}\n\n/** The other nodes `extensions` change along with a transform that leaves the nodes in `after` as given; null when one refuses it. */\nfunction transformOthers(\n sc: AnyScene,\n extensions: readonly PathEditExtension[],\n after: ReadonlyMap<string, EditableNode>,\n): Map<string, PathEditOther> | null {\n const others = new Map<string, PathEditOther>();\n const finishing = extensions.filter((e) => e.finishTransform);\n if (finishing.length === 0 || after.size === 0) return others;\n const nodeAfter = (id: string) => {\n const node = sc.get(id as NodeId);\n if (!node) return null;\n const written = after.get(id);\n return { pose: written?.pose ?? node.pose, data: written?.data ?? node.data, dependsOn: node.dependsOn };\n };\n const ctx: PathTransformFinishCtx = {\n ids: [...after.keys()],\n node: nodeAfter,\n path: (id) => pathEditPathOf(nodeAfter(id) ?? undefined, extensions),\n before: (id) => pathEditPathOf(sc.get(id as NodeId) as EditableNode | undefined, extensions),\n dependents: (id) => dependentsOf(sc, id),\n };\n for (const ext of finishing) {\n const done = ext.finishTransform!(ctx);\n if (!done) return null;\n for (const o of done) if (!after.has(o.id)) addOther(others, o);\n }\n return others;\n}\n\n/** `ops`, a whole-node transform's batch, with the ops `extensions` add for the other nodes it changes; null when one refuses it. */\nexport function transformOps(\n sc: AnyScene,\n extensions: readonly PathEditExtension[],\n ops: readonly Op[],\n label: string,\n): Op[] | null {\n const after = extensions.some((e) => e.finishTransform) ? writtenBy(sc, ops) : null;\n if (!after || after.size === 0) return [...ops];\n const others = transformOthers(sc, extensions, after);\n return others && [...ops, ...otherOps(sc, others, label, extensions)];\n}\n\n/**\n * The other nodes `extensions` change along with a transform frame that\n * poses the nodes in `poses` as given, each as it would be stored — what\n * {@link transformOps} would commit for that frame, read the same way. Empty\n * when nothing changes with it, or an extension refuses it.\n */\nexport function transformPreview(\n sc: AnyScene,\n extensions: readonly PathEditExtension[],\n poses: ReadonlyMap<string, unknown>,\n): TransformPreviewNode[] {\n if (poses.size === 0 || !extensions.some((e) => e.finishTransform)) return [];\n const after = new Map<string, EditableNode>();\n for (const [id, pose] of poses) {\n const node = sc.get(id as NodeId);\n if (node) after.set(id, { pose, data: node.data });\n }\n const others = transformOthers(sc, extensions, after);\n return [...(others?.values() ?? [])].flatMap((o) => {\n const node = sc.get(o.id as NodeId) as EditableNode | undefined;\n const stored = node && o.path && !o.remove ? storeEditablePath(node, o.path, extensions) : null;\n if (!node || !stored) return [];\n return [stored.data === node.data ? { id: o.id, pose: stored.pose } : { id: o.id, pose: stored.pose, data: stored.data }];\n });\n}\n\n/** The transform follower `extensions` make: each one's `finishTransform`, as\n * {@link transformOps} and {@link transformPreview} read it. Null when none\n * has one, so a transform runs no follower for them. */\nexport function pathEditFollower(sc: AnyScene, extensions: readonly PathEditExtension[]): TransformFollower | null {\n if (!extensions.some((e) => e.finishTransform)) return null;\n return {\n finish: (ops, label) => transformOps(sc, extensions, ops, label),\n preview: (poses) => transformPreview(sc, extensions, po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OAAO,CAAC;CAC5E,MAAM,wBAAQ,IAAI,IAA0B;CAC5C,KAAK,MAAM,CAAC,IAAI,SAAS,OAAO;EAC9B,MAAM,OAAO,GAAG,IAAI,EAAY;EAChC,IAAI,MAAM,MAAM,IAAI,IAAI;GAAE;GAAM,MAAM,KAAK;EAAK,CAAC;CACnD;CAEA,OAAO,CAAC,GADO,gBAAgB,IAAI,YAAY,KACnC,CAAA,EAAQ,OAAO,KAAK,CAAC,CAAE,CAAC,CAAC,SAAS,MAAM;EAClD,MAAM,OAAO,GAAG,IAAI,EAAE,EAAY;EAClC,MAAM,SAAS,QAAQ,EAAE,QAAQ,CAAC,EAAE,SAAS,kBAAkB,MAAM,EAAE,MAAM,UAAU,IAAI;EAC3F,IAAI,CAAC,QAAQ,CAAC,QAAQ,OAAO,CAAC;EAC9B,OAAO,CAAC,OAAO,SAAS,KAAK,OAAO;GAAE,IAAI,EAAE;GAAI,MAAM,OAAO;EAAK,IAAI;GAAE,IAAI,EAAE;GAAI,MAAM,OAAO;GAAM,MAAM,OAAO;EAAK,CAAC;CAC1H,CAAC;AACH;;;;AAKA,SAAgB,iBAAiB,IAAc,YAAoE;CACjH,IAAI,CAAC,WAAW,MAAM,MAAM,EAAE,eAAe,GAAG,OAAO;CACvD,OAAO;EACL,SAAS,KAAK,UAAU,aAAa,IAAI,YAAY,KAAK,KAAK;EAC/D,UAAU,UAAU,iBAAiB,IAAI,YAAY,KAAK;CAC5D;AACF"}
|
package/dist/canvas/deps/snap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { snapSourcesFor } from "../../features/snap/gather.js";
|
|
1
|
+
import { assertSnapSourceIds, snapSourcesFor } from "../../features/snap/gather.js";
|
|
2
2
|
import { DEFAULT_SNAP_PX } from "../../features/snap/session2d.js";
|
|
3
3
|
import { ownGeometryAt, pathSnapSource } from "../../features/paths/pathSnap/pathSnapSource.js";
|
|
4
4
|
import { sceneSession2d } from "../../features/snap/sceneSession2d.js";
|
|
@@ -20,12 +20,12 @@ var DEFAULT_SNAP_SOURCES = [rotationSnapSource(), {
|
|
|
20
20
|
...pathSnapSource({ only: ["anchor"] }),
|
|
21
21
|
gestures: ["point"]
|
|
22
22
|
}];
|
|
23
|
-
/** `listed`,
|
|
24
|
-
*
|
|
23
|
+
/** `listed`, which must not repeat an id, then each default whose id is
|
|
24
|
+
* neither listed nor in `omit`. */
|
|
25
25
|
function withDefaults(listed, omit = []) {
|
|
26
|
-
|
|
27
|
-
const taken = /* @__PURE__ */ new Set([...
|
|
28
|
-
return [...listed
|
|
26
|
+
assertSnapSourceIds(listed);
|
|
27
|
+
const taken = /* @__PURE__ */ new Set([...listed.map((s) => s.id), ...omit]);
|
|
28
|
+
return [...listed, ...DEFAULT_SNAP_SOURCES.filter((s) => !taken.has(s.id))];
|
|
29
29
|
}
|
|
30
30
|
function useSnapDepSource(viewRef, session, store) {
|
|
31
31
|
const sessionRef = useLatest(session);
|
|
@@ -34,9 +34,12 @@ function useSnapDepSource(viewRef, session, store) {
|
|
|
34
34
|
useDepSource("snap", () => ({ begin: (req) => {
|
|
35
35
|
const s = sessionRef.current;
|
|
36
36
|
const view = viewRef.current;
|
|
37
|
-
const
|
|
37
|
+
const omit = new Set(req.omit);
|
|
38
|
+
const sources = [...withDefaults([...s.sources, ...s.registry?.list() ?? []], s.omit).filter((src) => !omit.has(src.id)), ...req.sources ?? []];
|
|
39
|
+
assertSnapSourceIds(sources);
|
|
38
40
|
const wantsGeometry = snapSourcesFor(sources, req.gesture).some((src) => src.roles.includes("geometry"));
|
|
39
41
|
const debug = s.debug?.() ?? void 0;
|
|
42
|
+
const reachPx = s.reachPx ?? kitSettings.get("targets.snapPx") ?? DEFAULT_SNAP_PX;
|
|
40
43
|
return sceneSession2d({
|
|
41
44
|
req,
|
|
42
45
|
scene: s.scene,
|
|
@@ -45,9 +48,9 @@ function useSnapDepSource(viewRef, session, store) {
|
|
|
45
48
|
...wantsGeometry ? { geometryAt: (press, ids) => ownGeometryAt(s.scene, press, ids, view?.scale ?? {
|
|
46
49
|
x: 1,
|
|
47
50
|
y: 1
|
|
48
|
-
}) } : {},
|
|
51
|
+
}, reachPx) } : {},
|
|
49
52
|
view: () => viewRef.current,
|
|
50
|
-
reachPx
|
|
53
|
+
reachPx,
|
|
51
54
|
...s.poseDescriptor ? { poseDescriptor: s.poseDescriptor } : {},
|
|
52
55
|
...s.originProjection ? { originProjection: s.originProjection } : {},
|
|
53
56
|
...debug ? { debug } : {},
|