@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,6 +1,22 @@
|
|
|
1
1
|
import { never } from "../../features/chrome-caps/conditions.js";
|
|
2
|
+
import { toolIdsOf } from "@weasel-js/routing";
|
|
2
3
|
|
|
3
4
|
//#region src/canvas/SceneCanvas/features.ts
|
|
5
|
+
/**
|
|
6
|
+
* The behavior presets `<SceneCanvas features>` composes. A bare canvas renders
|
|
7
|
+
* its scene and keeps a selection nothing sets; every behavior beyond that is
|
|
8
|
+
* turned on by a preset.
|
|
9
|
+
*
|
|
10
|
+
* A preset is a {@link FeaturePreset} object: the actions, tools, bindings,
|
|
11
|
+
* chrome, and contributions one behavior brings. Core's own are named
|
|
12
|
+
* (`'select'`, `'draw'`) and live in `namedPresets.ts`; a package ships its
|
|
13
|
+
* own the same way and an app passes the object. Nothing here imports an
|
|
14
|
+
* action, so a canvas reaches only the presets it is handed.
|
|
15
|
+
*
|
|
16
|
+
* A preset is not one of the `packages/core/src/features/<name>/` source
|
|
17
|
+
* directories that `docs/taxonomy.md` calls a feature; the two share a word
|
|
18
|
+
* and nothing else.
|
|
19
|
+
*/
|
|
4
20
|
/** Every name `<SceneCanvas features>` accepts, each composite after the
|
|
5
21
|
* presets it names. */
|
|
6
22
|
var SCENE_CANVAS_FEATURES = [
|
|
@@ -23,6 +39,10 @@ var SCENE_CANVAS_FEATURES = [
|
|
|
23
39
|
* preset once, and every one placed ahead of the presets it `refines`. Ties
|
|
24
40
|
* keep the order given. Where names resolve, a `viewport` config turns on the
|
|
25
41
|
* `view` preset, since that prop only configures what `view` turns on.
|
|
42
|
+
*
|
|
43
|
+
* `selectRotates: false` is `selectTool.rotate === false`: every preset keeps
|
|
44
|
+
* its actions, but loses its ambient `rotate` bindings and the rotation handle
|
|
45
|
+
* from its chrome, which hides the handle unless a consumer rule shows it.
|
|
26
46
|
*/
|
|
27
47
|
function resolveFeatures(features, named, opts = {}) {
|
|
28
48
|
const listed = [];
|
|
@@ -49,27 +69,47 @@ function resolveFeatures(features, named, opts = {}) {
|
|
|
49
69
|
ordered.push(p);
|
|
50
70
|
};
|
|
51
71
|
for (const p of listed) place(p);
|
|
72
|
+
const presets = opts.selectRotates === false ? ordered.map(withoutSelectRotate) : ordered;
|
|
52
73
|
return {
|
|
53
|
-
presets
|
|
54
|
-
pathEdit:
|
|
55
|
-
snapSources:
|
|
74
|
+
presets,
|
|
75
|
+
pathEdit: presets.flatMap((p) => p.pathEdit ?? []),
|
|
76
|
+
snapSources: presets.flatMap((p) => p.snapSources ?? []),
|
|
56
77
|
has: (id) => byId.has(id)
|
|
57
78
|
};
|
|
58
79
|
}
|
|
80
|
+
var ROTATION_HANDLE = "selection.rotation-handle";
|
|
81
|
+
/** `p` without its ambient `rotate` bindings or the rotation handle. */
|
|
82
|
+
function withoutSelectRotate(p) {
|
|
83
|
+
const { ambient, chrome } = p;
|
|
84
|
+
if (!ambient && !chrome?.includes(ROTATION_HANDLE)) return p;
|
|
85
|
+
return {
|
|
86
|
+
...p,
|
|
87
|
+
...ambient ? { ambient: (o) => {
|
|
88
|
+
const c = ambient(o);
|
|
89
|
+
return c.bindings ? {
|
|
90
|
+
...c,
|
|
91
|
+
bindings: c.bindings.filter((b) => b.actionId !== "rotate")
|
|
92
|
+
} : c;
|
|
93
|
+
} } : {},
|
|
94
|
+
...chrome ? { chrome: chrome.filter((id) => id !== ROTATION_HANDLE) } : {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
59
97
|
/** The actions the given presets register, in registration order. */
|
|
60
98
|
function presetActions(enabled) {
|
|
61
99
|
return enabled.presets.flatMap((p) => p.actions ?? []);
|
|
62
100
|
}
|
|
101
|
+
/** Whether a preset's `tools` entry names built-ins, by id or set, rather than being a tool of its own. */
|
|
102
|
+
var namesBuiltins = (t) => typeof t === "string" || "members" in t;
|
|
63
103
|
/** The built-in tool ids the given presets mount. */
|
|
64
104
|
function presetBuiltinTools(enabled) {
|
|
65
105
|
const ids = /* @__PURE__ */ new Set();
|
|
66
|
-
for (const p of enabled.presets) for (const
|
|
106
|
+
for (const p of enabled.presets) for (const id of toolIdsOf((p.tools ?? []).filter(namesBuiltins))) ids.add(id);
|
|
67
107
|
return ids;
|
|
68
108
|
}
|
|
69
109
|
/** The tools of their own the given presets mount, by id. */
|
|
70
110
|
function presetOwnTools(enabled) {
|
|
71
111
|
const out = {};
|
|
72
|
-
for (const p of enabled.presets) for (const t of p.tools ?? []) if (
|
|
112
|
+
for (const p of enabled.presets) for (const t of p.tools ?? []) if (!namesBuiltins(t)) out[t.id] = t;
|
|
73
113
|
return out;
|
|
74
114
|
}
|
|
75
115
|
/** The given presets' ambient entries and contributions, in the order they are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.js","names":[],"sources":["../../../src/canvas/SceneCanvas/features.ts"],"sourcesContent":["/**\n * The behavior presets `<SceneCanvas features>` composes. A bare canvas renders\n * its scene and keeps a selection nothing sets; every behavior beyond that is\n * turned on by a preset.\n *\n * A preset is a {@link FeaturePreset} object: the actions, tools, bindings,\n * chrome, and contributions one behavior brings. Core's own are named\n * (`'select'`, `'draw'`) and live in `namedPresets.ts`; a package ships its\n * own the same way and an app passes the object. Nothing here imports an\n * action, so a canvas reaches only the presets it is handed.\n *\n * A preset is not one of the `packages/core/src/features/<name>/` source\n * directories that `docs/taxonomy.md` calls a feature; the two share a word\n * and nothing else.\n */\nimport type { Action } from '@weasel-js/routing';\nimport { never } from 'features/chrome-caps/conditions';\nimport type { ChromeId, VisibilityRules } from 'features/chrome-caps/types';\nimport type { MoveBehavior } from 'interactions/gestures/types';\nimport type { UseMoveOptions } from 'interactions/actions/move/options';\nimport type { UseRotateOptions } from 'interactions/actions/rotate/options';\nimport type { Contribution, Tool } from 'tools/overlayBinding';\nimport type { PathEditExtension } from 'features/paths/pathEditExtension';\nimport type { SnapSource } from 'features/snap/types';\nimport type { SurfaceContribution } from '../surfaceContribution';\nimport type { BuiltinToolId } from './props';\n\n/** A core preset that names one behavior and abbreviates nothing. */\nexport type BaseFeature =\n | 'view'\n | 'select'\n | 'outline'\n | 'move'\n | 'resize'\n | 'rotate'\n | 'edit'\n | 'arrange'\n | 'paths'\n | 'ingest';\n\n/** A core preset that abbreviates others: `pick` is `select` + `outline`,\n * `transform` is `resize` + `rotate`, and `draw` is every base preset. */\nexport type CompositeFeature = 'pick' | 'transform' | 'draw';\n\n/** A core preset's name, as `<SceneCanvas features>` takes it. */\nexport type Feature = BaseFeature | CompositeFeature;\n\n/** Every name `<SceneCanvas features>` accepts, each composite after the\n * presets it names. */\nexport const SCENE_CANVAS_FEATURES: readonly Feature[] = [\n 'view', 'select', 'outline', 'pick', 'move', 'resize', 'rotate', 'transform',\n 'edit', 'arrange', 'paths', 'ingest', 'draw',\n];\n\n/** What a preset's ambient bindings are built from: the `selectTool` options\n * that configure them. */\nexport interface FeatureBindingOptions {\n move?: UseMoveOptions<unknown>;\n rotate?: UseRotateOptions<unknown>;\n}\n\n/**\n * Everything turning one preset on means. Every role is optional.\n *\n * A package's preset is the unit an app opts into: the app imports it and\n * passes it to `features`, and an app that does not never loads its code.\n */\nexport interface FeaturePreset {\n /** Unique per canvas. `refines` names presets by it, and two different\n * presets with one id on one canvas throw. */\n readonly id: string;\n /** The action descriptors it registers, in the order they register. They\n * are standard actions: `<SceneCanvas actions>` overrides and mutes them,\n * and `tune` reaches them. */\n readonly actions?: readonly Action[];\n /** Tools it mounts: a built-in by id, or a tool of its own. */\n readonly tools?: readonly (BuiltinToolId | Tool)[];\n /** Its ambient bindings: an always-live entry routing a gesture to its\n * actions under any tool that does not claim the gesture itself. */\n readonly ambient?: (options: FeatureBindingOptions) => Contribution;\n /** Behaviors folded into every move the presets' ambient bindings run,\n * after the select tool's own: a snap, a readout of the drag. They reach\n * only a move some enabled preset binds, `move` or `draw`'s. */\n readonly moveBehaviors?: readonly MoveBehavior<unknown>[];\n /** Snap sources every snap session on the canvas asks, after\n * `<SceneCanvas snap.sources>` and the presets before it. */\n readonly snapSources?: readonly SnapSource[];\n /** The selection chrome that is drawn, and can be grabbed, only while it is on. */\n readonly chrome?: readonly ChromeId[];\n /** Default chrome-caps rules for chrome of its own, under the consumer's\n * `chromeVisibility`: a mark it draws only on request, say. */\n readonly chromeRules?: VisibilityRules;\n /** What it adds to path edit: marks, grabbable parts, what an edit keeps\n * true. Consulted in preset order. */\n readonly pathEdit?: readonly PathEditExtension[];\n /** Entries installed beside `<SceneCanvas ambient>`, with every role they\n * declare: deps, overlays, `attach`, views, frame hooks. A `tools` takeover\n * brings its own ambient and leaves them out. */\n readonly contributions?: readonly SurfaceContribution[];\n /** Ids of presets whose actions this one's register ahead of, so that where\n * both bind one gesture, this one's is tried first: anchor nudging ahead of\n * node nudging. A preset named here that is not on is ignored. */\n readonly refines?: readonly string[];\n /** Presets it turns on with itself, ahead of its own place in the order. */\n readonly includes?: readonly FeaturePreset[];\n}\n\n/** What `<SceneCanvas features>` takes: a core preset's name or any preset. */\nexport type FeatureEntry = Feature | FeaturePreset;\n\n/** The names a canvas resolves: one preset each, or the presets a composite\n * abbreviates. */\nexport interface NamedPresets {\n readonly base: Readonly<Record<BaseFeature, FeaturePreset>>;\n readonly composite: Readonly<Record<CompositeFeature, readonly BaseFeature[]>>;\n}\n\n/** Where a canvas finds presets beyond the objects it is handed: the names it\n * resolves, if any, and the actions it registers once a tool binds them. */\nexport interface PresetSource {\n readonly named: NamedPresets | null;\n /** Actions registered only when a tool or contribution binds them. */\n readonly pool: readonly Action[];\n}\n\n/** The presets a canvas runs with, in the order their actions register. */\nexport interface EnabledPresets {\n readonly presets: readonly FeaturePreset[];\n /** Their path-edit extensions, in order. */\n readonly pathEdit: readonly PathEditExtension[];\n /** Their snap sources, in order. */\n readonly snapSources: readonly SnapSource[];\n /** Whether a preset with this id is on. */\n has(id: string): boolean;\n}\n\n/**\n * The presets a canvas runs with: names expanded, `includes` pulled in, each\n * preset once, and every one placed ahead of the presets it `refines`. Ties\n * keep the order given. Where names resolve, a `viewport` config turns on the\n * `view` preset, since that prop only configures what `view` turns on.\n */\nexport function resolveFeatures(\n features: readonly FeatureEntry[] | undefined,\n named: NamedPresets | null,\n opts: { viewport?: boolean } = {},\n): EnabledPresets {\n const listed: FeaturePreset[] = [];\n const byId = new Map<string, FeaturePreset>();\n const add = (p: FeaturePreset): void => {\n const held = byId.get(p.id);\n if (held === p) return;\n if (held) throw new Error(`[SceneCanvas] two different presets have the id \"${p.id}\"`);\n byId.set(p.id, p);\n for (const inner of p.includes ?? []) add(inner);\n listed.push(p);\n };\n for (const f of features ?? []) {\n if (typeof f !== 'string') add(f);\n else if (!named) throw new Error(`[SceneCanvas] this canvas resolves no preset names; pass the preset for \"${f}\"`);\n else if (f in named.composite) for (const b of named.composite[f as CompositeFeature]) add(named.base[b]);\n else add(named.base[f as BaseFeature]);\n }\n if (opts.viewport && named) add(named.base.view);\n\n const ordered: FeaturePreset[] = [];\n const placed = new Set<string>();\n const place = (p: FeaturePreset): void => {\n if (placed.has(p.id)) return;\n placed.add(p.id);\n for (const r of listed) if (r.refines?.includes(p.id)) place(r);\n ordered.push(p);\n };\n for (const p of listed) place(p);\n return {\n presets: ordered,\n pathEdit: ordered.flatMap((p) => p.pathEdit ?? []),\n snapSources: ordered.flatMap((p) => p.snapSources ?? []),\n has: (id) => byId.has(id),\n };\n}\n\n/** The actions the given presets register, in registration order. */\nexport function presetActions(enabled: EnabledPresets): Action[] {\n return enabled.presets.flatMap((p) => p.actions ?? []);\n}\n\n/** The built-in tool ids the given presets mount. */\nexport function presetBuiltinTools(enabled: EnabledPresets): Set<BuiltinToolId> {\n const ids = new Set<BuiltinToolId>();\n for (const p of enabled.presets) for (const t of p.tools ?? []) if (typeof t === 'string') ids.add(t);\n return ids;\n}\n\n/** The tools of their own the given presets mount, by id. */\nexport function presetOwnTools(enabled: EnabledPresets): Record<string, Tool> {\n const out: Record<string, Tool> = {};\n for (const p of enabled.presets) for (const t of p.tools ?? []) if (typeof t !== 'string') out[t.id] = t;\n return out;\n}\n\n/** The given presets' ambient entries and contributions, in the order they are\n * matched. Their `moveBehaviors` follow the ones `options.move` brings. */\nexport function presetAmbient(enabled: EnabledPresets, options: FeatureBindingOptions): Contribution[] {\n const extra = enabled.presets.flatMap((p) => p.moveBehaviors ?? []);\n const move = extra.length === 0\n ? options.move\n : { ...options.move, behaviors: [...(options.move?.behaviors ?? []), ...extra] };\n const opts = { ...options, move };\n return enabled.presets.flatMap((p) => (p.ambient ? [p.ambient(opts)] : []));\n}\n\n/** The given presets' contributions, in preset order. */\nexport function presetContributions(enabled: EnabledPresets): SurfaceContribution[] {\n return enabled.presets.flatMap((p) => p.contributions ?? []);\n}\n\n/** The enabled presets' own `chromeRules`, then rules hiding each chrome id\n * in `owned` that no enabled preset turns on. `never` also takes a handle out\n * of hit-testing, so a hidden one cannot be grabbed. */\nexport function presetChromeRules(enabled: EnabledPresets, owned: readonly ChromeId[]): VisibilityRules {\n const on = new Set(enabled.presets.flatMap((p) => p.chrome ?? []));\n const rules: VisibilityRules = Object.assign({}, ...enabled.presets.map((p) => p.chromeRules ?? {}));\n for (const id of owned) if (!on.has(id)) rules[id] = never;\n return rules;\n}\n"],"mappings":";;;;;AAiDA,IAAa,wBAA4C;CACvD;CAAQ;CAAU;CAAW;CAAQ;CAAQ;CAAU;CAAU;CACjE;CAAQ;CAAW;CAAS;CAAU;AACxC;;;;;;;AA0FA,SAAgB,gBACd,UACA,OACA,OAA+B,CAAC,GAChB;CAChB,MAAM,SAA0B,CAAC;CACjC,MAAM,uBAAO,IAAI,IAA2B;CAC5C,MAAM,OAAO,MAA2B;EACtC,MAAM,OAAO,KAAK,IAAI,EAAE,EAAE;EAC1B,IAAI,SAAS,GAAG;EAChB,IAAI,MAAM,MAAM,IAAI,MAAM,oDAAoD,EAAE,GAAG,EAAE;EACrF,KAAK,IAAI,EAAE,IAAI,CAAC;EAChB,KAAK,MAAM,SAAS,EAAE,YAAY,CAAC,GAAG,IAAI,KAAK;EAC/C,OAAO,KAAK,CAAC;CACf;CACA,KAAK,MAAM,KAAK,YAAY,CAAC,GAC3B,IAAI,OAAO,MAAM,UAAU,IAAI,CAAC;MAC3B,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,4EAA4E,EAAE,EAAE;MAC5G,IAAI,KAAK,MAAM,WAAW,KAAK,MAAM,KAAK,MAAM,UAAU,IAAwB,IAAI,MAAM,KAAK,EAAE;MACnG,IAAI,MAAM,KAAK,EAAiB;CAEvC,IAAI,KAAK,YAAY,OAAO,IAAI,MAAM,KAAK,IAAI;CAE/C,MAAM,UAA2B,CAAC;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,SAAS,MAA2B;EACxC,IAAI,OAAO,IAAI,EAAE,EAAE,GAAG;EACtB,OAAO,IAAI,EAAE,EAAE;EACf,KAAK,MAAM,KAAK,QAAQ,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,CAAC;EAC9D,QAAQ,KAAK,CAAC;CAChB;CACA,KAAK,MAAM,KAAK,QAAQ,MAAM,CAAC;CAC/B,OAAO;EACL,SAAS;EACT,UAAU,QAAQ,SAAS,MAAM,EAAE,YAAY,CAAC,CAAC;EACjD,aAAa,QAAQ,SAAS,MAAM,EAAE,eAAe,CAAC,CAAC;EACvD,MAAM,OAAO,KAAK,IAAI,EAAE;CAC1B;AACF;;AAGA,SAAgB,cAAc,SAAmC;CAC/D,OAAO,QAAQ,QAAQ,SAAS,MAAM,EAAE,WAAW,CAAC,CAAC;AACvD;;AAGA,SAAgB,mBAAmB,SAA6C;CAC9E,MAAM,sBAAM,IAAI,IAAmB;CACnC,KAAK,MAAM,KAAK,QAAQ,SAAS,KAAK,MAAM,KAAK,EAAE,SAAS,CAAC,GAAG,IAAI,OAAO,MAAM,UAAU,IAAI,IAAI,CAAC;CACpG,OAAO;AACT;;AAGA,SAAgB,eAAe,SAA+C;CAC5E,MAAM,MAA4B,CAAC;CACnC,KAAK,MAAM,KAAK,QAAQ,SAAS,KAAK,MAAM,KAAK,EAAE,SAAS,CAAC,GAAG,IAAI,OAAO,MAAM,UAAU,IAAI,EAAE,MAAM;CACvG,OAAO;AACT;;;AAIA,SAAgB,cAAc,SAAyB,SAAgD;CACrG,MAAM,QAAQ,QAAQ,QAAQ,SAAS,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAClE,MAAM,OAAO,MAAM,WAAW,IAC1B,QAAQ,OACR;EAAE,GAAG,QAAQ;EAAM,WAAW,CAAC,GAAI,QAAQ,MAAM,aAAa,CAAC,GAAI,GAAG,KAAK;CAAE;CACjF,MAAM,OAAO;EAAE,GAAG;EAAS;CAAK;CAChC,OAAO,QAAQ,QAAQ,SAAS,MAAO,EAAE,UAAU,CAAC,EAAE,QAAQ,IAAI,CAAC,IAAI,CAAC,CAAE;AAC5E;;AAGA,SAAgB,oBAAoB,SAAgD;CAClF,OAAO,QAAQ,QAAQ,SAAS,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAC7D;;;;AAKA,SAAgB,kBAAkB,SAAyB,OAA6C;CACtG,MAAM,KAAK,IAAI,IAAI,QAAQ,QAAQ,SAAS,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACjE,MAAM,QAAyB,OAAO,OAAO,CAAC,GAAG,GAAG,QAAQ,QAAQ,KAAK,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CACnG,KAAK,MAAM,MAAM,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,MAAM;CACrD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"features.js","names":[],"sources":["../../../src/canvas/SceneCanvas/features.ts"],"sourcesContent":["/**\n * The behavior presets `<SceneCanvas features>` composes. A bare canvas renders\n * its scene and keeps a selection nothing sets; every behavior beyond that is\n * turned on by a preset.\n *\n * A preset is a {@link FeaturePreset} object: the actions, tools, bindings,\n * chrome, and contributions one behavior brings. Core's own are named\n * (`'select'`, `'draw'`) and live in `namedPresets.ts`; a package ships its\n * own the same way and an app passes the object. Nothing here imports an\n * action, so a canvas reaches only the presets it is handed.\n *\n * A preset is not one of the `packages/core/src/features/<name>/` source\n * directories that `docs/taxonomy.md` calls a feature; the two share a word\n * and nothing else.\n */\nimport { toolIdsOf, type Action, type ToolEntry } from '@weasel-js/routing';\nimport { never } from 'features/chrome-caps/conditions';\nimport type { ChromeId, VisibilityRules } from 'features/chrome-caps/types';\nimport type { MoveBehavior } from 'interactions/gestures/types';\nimport type { UseMoveOptions } from 'interactions/actions/move/options';\nimport type { UseRotateOptions } from 'interactions/actions/rotate/options';\nimport type { Contribution, Tool } from 'tools/overlayBinding';\nimport type { PathEditExtension } from 'features/paths/pathEditExtension';\nimport type { SnapSource } from 'features/snap/types';\nimport type { SurfaceContribution } from '../surfaceContribution';\nimport type { BuiltinToolId } from './props';\n\n/** A core preset that names one behavior and abbreviates nothing. */\nexport type BaseFeature =\n | 'view'\n | 'select'\n | 'outline'\n | 'move'\n | 'resize'\n | 'rotate'\n | 'edit'\n | 'arrange'\n | 'paths'\n | 'ingest';\n\n/** A core preset that abbreviates others: `pick` is `select` + `outline`,\n * `transform` is `resize` + `rotate`, and `draw` is every base preset. */\nexport type CompositeFeature = 'pick' | 'transform' | 'draw';\n\n/** A core preset's name, as `<SceneCanvas features>` takes it. */\nexport type Feature = BaseFeature | CompositeFeature;\n\n/** Every name `<SceneCanvas features>` accepts, each composite after the\n * presets it names. */\nexport const SCENE_CANVAS_FEATURES: readonly Feature[] = [\n 'view', 'select', 'outline', 'pick', 'move', 'resize', 'rotate', 'transform',\n 'edit', 'arrange', 'paths', 'ingest', 'draw',\n];\n\n/** What a preset's ambient bindings are built from: the `selectTool` options\n * that configure them. */\nexport interface FeatureBindingOptions {\n move?: UseMoveOptions<unknown>;\n rotate?: UseRotateOptions<unknown>;\n}\n\n/**\n * Everything turning one preset on means. Every role is optional.\n *\n * A package's preset is the unit an app opts into: the app imports it and\n * passes it to `features`, and an app that does not never loads its code.\n */\nexport interface FeaturePreset {\n /** Unique per canvas. `refines` names presets by it, and two different\n * presets with one id on one canvas throw. */\n readonly id: string;\n /** The action descriptors it registers, in the order they register. They\n * are standard actions: `<SceneCanvas actions>` overrides and mutes them,\n * and `tune` reaches them. */\n readonly actions?: readonly Action[];\n /** Tools it mounts: a built-in by id or a set of them, or a tool of its own. */\n readonly tools?: readonly (ToolEntry<BuiltinToolId> | Tool)[];\n /** Its ambient bindings: an always-live entry routing a gesture to its\n * actions under any tool that does not claim the gesture itself. */\n readonly ambient?: (options: FeatureBindingOptions) => Contribution;\n /** Behaviors folded into every move the presets' ambient bindings run,\n * after the select tool's own: a snap, a readout of the drag. They reach\n * only a move some enabled preset binds, `move` or `draw`'s. */\n readonly moveBehaviors?: readonly MoveBehavior<unknown>[];\n /** Snap sources every snap session on the canvas asks, after\n * `<SceneCanvas snap.sources>` and the presets before it. */\n readonly snapSources?: readonly SnapSource[];\n /** The selection chrome that is drawn, and can be grabbed, only while it is on. */\n readonly chrome?: readonly ChromeId[];\n /** Default chrome-caps rules for chrome of its own, under the consumer's\n * `chromeVisibility`: a mark it draws only on request, say. */\n readonly chromeRules?: VisibilityRules;\n /** What it adds to path edit: marks, grabbable parts, what an edit keeps\n * true. Consulted in preset order. */\n readonly pathEdit?: readonly PathEditExtension[];\n /** Entries installed beside `<SceneCanvas ambient>`, with every role they\n * declare: deps, overlays, `attach`, views, frame hooks. A `tools` takeover\n * brings its own ambient and leaves them out. */\n readonly contributions?: readonly SurfaceContribution[];\n /** Ids of presets whose actions this one's register ahead of, so that where\n * both bind one gesture, this one's is tried first: anchor nudging ahead of\n * node nudging. A preset named here that is not on is ignored. */\n readonly refines?: readonly string[];\n /** Presets it turns on with itself, ahead of its own place in the order. */\n readonly includes?: readonly FeaturePreset[];\n}\n\n/** What `<SceneCanvas features>` takes: a core preset's name or any preset. */\nexport type FeatureEntry = Feature | FeaturePreset;\n\n/** The names a canvas resolves: one preset each, or the presets a composite\n * abbreviates. */\nexport interface NamedPresets {\n readonly base: Readonly<Record<BaseFeature, FeaturePreset>>;\n readonly composite: Readonly<Record<CompositeFeature, readonly BaseFeature[]>>;\n}\n\n/** Where a canvas finds presets beyond the objects it is handed: the names it\n * resolves, if any, and the actions it registers once a tool binds them. */\nexport interface PresetSource {\n readonly named: NamedPresets | null;\n /** Actions registered only when a tool or contribution binds them. */\n readonly pool: readonly Action[];\n}\n\n/** The presets a canvas runs with, in the order their actions register. */\nexport interface EnabledPresets {\n readonly presets: readonly FeaturePreset[];\n /** Their path-edit extensions, in order. */\n readonly pathEdit: readonly PathEditExtension[];\n /** Their snap sources, in order. */\n readonly snapSources: readonly SnapSource[];\n /** Whether a preset with this id is on. */\n has(id: string): boolean;\n}\n\n/**\n * The presets a canvas runs with: names expanded, `includes` pulled in, each\n * preset once, and every one placed ahead of the presets it `refines`. Ties\n * keep the order given. Where names resolve, a `viewport` config turns on the\n * `view` preset, since that prop only configures what `view` turns on.\n *\n * `selectRotates: false` is `selectTool.rotate === false`: every preset keeps\n * its actions, but loses its ambient `rotate` bindings and the rotation handle\n * from its chrome, which hides the handle unless a consumer rule shows it.\n */\nexport function resolveFeatures(\n features: readonly FeatureEntry[] | undefined,\n named: NamedPresets | null,\n opts: { viewport?: boolean; selectRotates?: boolean } = {},\n): EnabledPresets {\n const listed: FeaturePreset[] = [];\n const byId = new Map<string, FeaturePreset>();\n const add = (p: FeaturePreset): void => {\n const held = byId.get(p.id);\n if (held === p) return;\n if (held) throw new Error(`[SceneCanvas] two different presets have the id \"${p.id}\"`);\n byId.set(p.id, p);\n for (const inner of p.includes ?? []) add(inner);\n listed.push(p);\n };\n for (const f of features ?? []) {\n if (typeof f !== 'string') add(f);\n else if (!named) throw new Error(`[SceneCanvas] this canvas resolves no preset names; pass the preset for \"${f}\"`);\n else if (f in named.composite) for (const b of named.composite[f as CompositeFeature]) add(named.base[b]);\n else add(named.base[f as BaseFeature]);\n }\n if (opts.viewport && named) add(named.base.view);\n\n const ordered: FeaturePreset[] = [];\n const placed = new Set<string>();\n const place = (p: FeaturePreset): void => {\n if (placed.has(p.id)) return;\n placed.add(p.id);\n for (const r of listed) if (r.refines?.includes(p.id)) place(r);\n ordered.push(p);\n };\n for (const p of listed) place(p);\n const presets = opts.selectRotates === false ? ordered.map(withoutSelectRotate) : ordered;\n return {\n presets,\n pathEdit: presets.flatMap((p) => p.pathEdit ?? []),\n snapSources: presets.flatMap((p) => p.snapSources ?? []),\n has: (id) => byId.has(id),\n };\n}\n\nconst ROTATION_HANDLE: ChromeId = 'selection.rotation-handle';\n\n/** `p` without its ambient `rotate` bindings or the rotation handle. */\nfunction withoutSelectRotate(p: FeaturePreset): FeaturePreset {\n const { ambient, chrome } = p;\n if (!ambient && !chrome?.includes(ROTATION_HANDLE)) return p;\n return {\n ...p,\n ...(ambient ? {\n ambient: (o: FeatureBindingOptions): Contribution => {\n const c = ambient(o);\n return c.bindings ? { ...c, bindings: c.bindings.filter((b) => b.actionId !== 'rotate') } : c;\n },\n } : {}),\n ...(chrome ? { chrome: chrome.filter((id) => id !== ROTATION_HANDLE) } : {}),\n };\n}\n\n/** The actions the given presets register, in registration order. */\nexport function presetActions(enabled: EnabledPresets): Action[] {\n return enabled.presets.flatMap((p) => p.actions ?? []);\n}\n\n/** Whether a preset's `tools` entry names built-ins, by id or set, rather than being a tool of its own. */\nconst namesBuiltins = (t: ToolEntry<BuiltinToolId> | Tool): t is ToolEntry<BuiltinToolId> =>\n typeof t === 'string' || 'members' in t;\n\n/** The built-in tool ids the given presets mount. */\nexport function presetBuiltinTools(enabled: EnabledPresets): Set<BuiltinToolId> {\n const ids = new Set<BuiltinToolId>();\n for (const p of enabled.presets) {\n for (const id of toolIdsOf((p.tools ?? []).filter(namesBuiltins))) ids.add(id);\n }\n return ids;\n}\n\n/** The tools of their own the given presets mount, by id. */\nexport function presetOwnTools(enabled: EnabledPresets): Record<string, Tool> {\n const out: Record<string, Tool> = {};\n for (const p of enabled.presets) for (const t of p.tools ?? []) if (!namesBuiltins(t)) out[t.id] = t;\n return out;\n}\n\n/** The given presets' ambient entries and contributions, in the order they are\n * matched. Their `moveBehaviors` follow the ones `options.move` brings. */\nexport function presetAmbient(enabled: EnabledPresets, options: FeatureBindingOptions): Contribution[] {\n const extra = enabled.presets.flatMap((p) => p.moveBehaviors ?? []);\n const move = extra.length === 0\n ? options.move\n : { ...options.move, behaviors: [...(options.move?.behaviors ?? []), ...extra] };\n const opts = { ...options, move };\n return enabled.presets.flatMap((p) => (p.ambient ? [p.ambient(opts)] : []));\n}\n\n/** The given presets' contributions, in preset order. */\nexport function presetContributions(enabled: EnabledPresets): SurfaceContribution[] {\n return enabled.presets.flatMap((p) => p.contributions ?? []);\n}\n\n/** The enabled presets' own `chromeRules`, then rules hiding each chrome id\n * in `owned` that no enabled preset turns on. `never` also takes a handle out\n * of hit-testing, so a hidden one cannot be grabbed. */\nexport function presetChromeRules(enabled: EnabledPresets, owned: readonly ChromeId[]): VisibilityRules {\n const on = new Set(enabled.presets.flatMap((p) => p.chrome ?? []));\n const rules: VisibilityRules = Object.assign({}, ...enabled.presets.map((p) => p.chromeRules ?? {}));\n for (const id of owned) if (!on.has(id)) rules[id] = never;\n return rules;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,wBAA4C;CACvD;CAAQ;CAAU;CAAW;CAAQ;CAAQ;CAAU;CAAU;CACjE;CAAQ;CAAW;CAAS;CAAU;AACxC;;;;;;;;;;;AA8FA,SAAgB,gBACd,UACA,OACA,OAAwD,CAAC,GACzC;CAChB,MAAM,SAA0B,CAAC;CACjC,MAAM,uBAAO,IAAI,IAA2B;CAC5C,MAAM,OAAO,MAA2B;EACtC,MAAM,OAAO,KAAK,IAAI,EAAE,EAAE;EAC1B,IAAI,SAAS,GAAG;EAChB,IAAI,MAAM,MAAM,IAAI,MAAM,oDAAoD,EAAE,GAAG,EAAE;EACrF,KAAK,IAAI,EAAE,IAAI,CAAC;EAChB,KAAK,MAAM,SAAS,EAAE,YAAY,CAAC,GAAG,IAAI,KAAK;EAC/C,OAAO,KAAK,CAAC;CACf;CACA,KAAK,MAAM,KAAK,YAAY,CAAC,GAC3B,IAAI,OAAO,MAAM,UAAU,IAAI,CAAC;MAC3B,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,4EAA4E,EAAE,EAAE;MAC5G,IAAI,KAAK,MAAM,WAAW,KAAK,MAAM,KAAK,MAAM,UAAU,IAAwB,IAAI,MAAM,KAAK,EAAE;MACnG,IAAI,MAAM,KAAK,EAAiB;CAEvC,IAAI,KAAK,YAAY,OAAO,IAAI,MAAM,KAAK,IAAI;CAE/C,MAAM,UAA2B,CAAC;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,SAAS,MAA2B;EACxC,IAAI,OAAO,IAAI,EAAE,EAAE,GAAG;EACtB,OAAO,IAAI,EAAE,EAAE;EACf,KAAK,MAAM,KAAK,QAAQ,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,CAAC;EAC9D,QAAQ,KAAK,CAAC;CAChB;CACA,KAAK,MAAM,KAAK,QAAQ,MAAM,CAAC;CAC/B,MAAM,UAAU,KAAK,kBAAkB,QAAQ,QAAQ,IAAI,mBAAmB,IAAI;CAClF,OAAO;EACL;EACA,UAAU,QAAQ,SAAS,MAAM,EAAE,YAAY,CAAC,CAAC;EACjD,aAAa,QAAQ,SAAS,MAAM,EAAE,eAAe,CAAC,CAAC;EACvD,MAAM,OAAO,KAAK,IAAI,EAAE;CAC1B;AACF;AAEA,IAAM,kBAA4B;;AAGlC,SAAS,oBAAoB,GAAiC;CAC5D,MAAM,EAAE,SAAS,WAAW;CAC5B,IAAI,CAAC,WAAW,CAAC,QAAQ,SAAS,eAAe,GAAG,OAAO;CAC3D,OAAO;EACL,GAAG;EACH,GAAI,UAAU,EACZ,UAAU,MAA2C;GACnD,MAAM,IAAI,QAAQ,CAAC;GACnB,OAAO,EAAE,WAAW;IAAE,GAAG;IAAG,UAAU,EAAE,SAAS,QAAQ,MAAM,EAAE,aAAa,QAAQ;GAAE,IAAI;EAC9F,EACF,IAAI,CAAC;EACL,GAAI,SAAS,EAAE,QAAQ,OAAO,QAAQ,OAAO,OAAO,eAAe,EAAE,IAAI,CAAC;CAC5E;AACF;;AAGA,SAAgB,cAAc,SAAmC;CAC/D,OAAO,QAAQ,QAAQ,SAAS,MAAM,EAAE,WAAW,CAAC,CAAC;AACvD;;AAGA,IAAM,iBAAiB,MACrB,OAAO,MAAM,YAAY,aAAa;;AAGxC,SAAgB,mBAAmB,SAA6C;CAC9E,MAAM,sBAAM,IAAI,IAAmB;CACnC,KAAK,MAAM,KAAK,QAAQ,SACtB,KAAK,MAAM,MAAM,WAAW,EAAE,SAAS,CAAC,EAAA,CAAG,OAAO,aAAa,CAAC,GAAG,IAAI,IAAI,EAAE;CAE/E,OAAO;AACT;;AAGA,SAAgB,eAAe,SAA+C;CAC5E,MAAM,MAA4B,CAAC;CACnC,KAAK,MAAM,KAAK,QAAQ,SAAS,KAAK,MAAM,KAAK,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,EAAE,MAAM;CACnG,OAAO;AACT;;;AAIA,SAAgB,cAAc,SAAyB,SAAgD;CACrG,MAAM,QAAQ,QAAQ,QAAQ,SAAS,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAClE,MAAM,OAAO,MAAM,WAAW,IAC1B,QAAQ,OACR;EAAE,GAAG,QAAQ;EAAM,WAAW,CAAC,GAAI,QAAQ,MAAM,aAAa,CAAC,GAAI,GAAG,KAAK;CAAE;CACjF,MAAM,OAAO;EAAE,GAAG;EAAS;CAAK;CAChC,OAAO,QAAQ,QAAQ,SAAS,MAAO,EAAE,UAAU,CAAC,EAAE,QAAQ,IAAI,CAAC,IAAI,CAAC,CAAE;AAC5E;;AAGA,SAAgB,oBAAoB,SAAgD;CAClF,OAAO,QAAQ,QAAQ,SAAS,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAC7D;;;;AAKA,SAAgB,kBAAkB,SAAyB,OAA6C;CACtG,MAAM,KAAK,IAAI,IAAI,QAAQ,QAAQ,SAAS,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CACjE,MAAM,QAAyB,OAAO,OAAO,CAAC,GAAG,GAAG,QAAQ,QAAQ,KAAK,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CACnG,KAAK,MAAM,MAAM,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,MAAM;CACrD,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HANDLE_BASE_PX } from "../../core/device/targets.js";
|
|
2
|
-
import {
|
|
2
|
+
import { BUILTIN_TOOL_IDS } from "./builtinToolSets.js";
|
|
3
3
|
import "@weasel-js/routing/react";
|
|
4
4
|
|
|
5
5
|
//#region src/canvas/SceneCanvas/props.ts
|
|
@@ -7,16 +7,6 @@ import "@weasel-js/routing/react";
|
|
|
7
7
|
* hit-test radius, at `targetScale = 1`. Deliberately unscaled; kit-internal
|
|
8
8
|
* use sites multiply by `DeviceProfile.targetScale`. */
|
|
9
9
|
var DEFAULT_HANDLE_SIZE = HANDLE_BASE_PX;
|
|
10
|
-
/** Every built-in tool id, in palette order: the navigation tools, the shape
|
|
11
|
-
* tools of the `core/shapeKinds` table, then the knife and the rig tools. */
|
|
12
|
-
var BUILTIN_TOOL_IDS = [
|
|
13
|
-
"select",
|
|
14
|
-
"hand",
|
|
15
|
-
...KIT_SHAPE_KINDS,
|
|
16
|
-
"slice",
|
|
17
|
-
"bone",
|
|
18
|
-
"weight"
|
|
19
|
-
];
|
|
20
10
|
|
|
21
11
|
//#endregion
|
|
22
12
|
export { BUILTIN_TOOL_IDS, DEFAULT_HANDLE_SIZE };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.js","names":[],"sources":["../../../src/canvas/SceneCanvas/props.ts"],"sourcesContent":["import type { ModeRegistry } from '@weasel-js/modes';\nimport type { PathEditHost, PathEditOpening } from './pathEditHost';\nimport type { SceneCanvasGeometry } from './geometryProps';\nimport type { SceneCanvasHit, SceneCanvasPointerProps } from './pointerProps';\nimport type { Paint } from '@weasel-js/paint';\nimport type { ActionsProp, ActionTunings } from '@weasel-js/routing';\nimport { Yoke } from '@weasel-js/routing/react';\nimport type { PasteOmission } from 'core/adapters/types';\nimport type { Op } from 'core/ops/types';\nimport type { Node, Scene, SerializedScene } from 'core/scene/types';\nimport type { SelectionApi, UseSelectionOptions } from 'core/selection/useSelection';\nimport { KIT_SHAPE_KINDS, type BuiltinShapeToolId } from 'core/shapeKinds';\nimport type { ContentHandlerEntry } from 'features/ingestion';\nimport type { SceneCanvasSnap } from 'features/snap/types';\nimport type { SvgIngestOptions } from 'interactions/actions/depSchema';\nimport type { GeometryProjection } from 'interactions/actions/geometryProjection';\nimport type { UseMoveOptions } from 'interactions/actions/move/options';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport type { UseResizeOptions } from 'interactions/actions/resize/options';\nimport type { UseRotateOptions } from 'interactions/actions/rotate/options';\nimport type { ReactNode } from 'react';\nimport type { Animator } from '@weasel-js/animator';\nimport type { PoseTransitionSeat } from '../../animation/poseTransition';\nimport { HANDLE_BASE_PX } from '../../core/device/targets';\nimport type { DeviceProfile } from '../../core/device/types';\nimport type { NodeRoutingEntry } from '../../core/scene/NodeRouting';\nimport type { DebugConfig } from '../../debug/types';\nimport type { LayoutDropTargetMode, ReflowTransition } from '../../layout/types';\nimport type { FlattenTolerance, ShaderProgramHandle } from '@weasel-js/renderer';\nimport type { Tool, ToolsApi } from '../../tools/overlayBinding';\nimport type { SceneSlotConfig } from '../buildSceneLayer';\nimport type { CanvasProps } from '../Canvas';\nimport type { LayersMap } from '../layerSlots';\nimport type { CanvasViewProps } from '../CanvasView';\nimport type { InsertNodeFactory, InsertPaint } from '../deps';\nimport type { SurfaceContribution } from '../surfaceContribution';\nimport type { CameraProps } from '../useCanvasView';\nimport type { FeatureEntry } from './features';\nimport type { BuiltinToolOptions } from './useBuiltinShapeTools';\nimport type { VersionCheck } from './useContributionRoles';\nimport type { SceneCanvasViewport } from './viewportProp';\n\n/** The adapter surface delete / duplicate / group / ungroup need, narrowed from\n * `SceneCanvasAdapter` because `useSceneStandardActions` is non-generic. */\nexport interface BridgeAdapter {\n applyOps(ops: Op[], label?: string): void;\n insertNode(node: { id: string; [k: string]: unknown }): void;\n removeNode(id: string): void;\n setSelection(ids: string[]): void;\n}\n\n/** Default size in CSS pixels for selection corner-handles AND their\n * hit-test radius, at `targetScale = 1`. Deliberately unscaled; kit-internal\n * use sites multiply by `DeviceProfile.targetScale`. */\nexport const DEFAULT_HANDLE_SIZE = HANDLE_BASE_PX;\n\n/** `<SceneCanvas longPress>`. */\nexport interface SceneCanvasLongPress {\n /**\n * Shown while a long-press is held and some binding would fire on it.\n * Default: a ring that fills around the press point\n * (`createLongPressFeedbackContribution()`), static under\n * `prefers-reduced-motion`. `false` shows nothing; a contribution replaces\n * it, reading the `longPress` dep. Installed beside `ambient`, so under a\n * `tools` takeover add it to your own `useTools` call instead.\n */\n feedback?: boolean | SurfaceContribution;\n /** Default true. A long-press some binding handled pulses\n * `navigator.vibrate` briefly, for touch and pen, where the API exists. */\n haptics?: boolean;\n /** Hold time in ms. Default `LONG_PRESS_MS` (500). */\n duration?: number;\n}\n\n/** `<SceneCanvas layers>`: a {@link LayersMap} whose scene slot may be partial,\n * since the defaults fill in whatever it leaves out. */\nexport type SceneCanvasLayers<TNode extends { id: string }, TPose> = LayersMap<\n TNode,\n TPose,\n Partial<SceneSlotConfig<TNode, TPose>>\n>;\n\n/** Built-in tool ids SceneCanvas knows how to mount when no `tools` prop\n * is supplied, via `defaultTools`. */\nexport type BuiltinToolId = 'select' | 'hand' | BuiltinShapeToolId | 'slice' | 'bone' | 'weight';\n\n/** Every built-in tool id, in palette order: the navigation tools, the shape\n * tools of the `core/shapeKinds` table, then the knife and the rig tools. */\nexport const BUILTIN_TOOL_IDS: readonly BuiltinToolId[] = ['select', 'hand', ...KIT_SHAPE_KINDS, 'slice', 'bone', 'weight'];\n\nexport type { SceneCanvasHit };\n\n/** Props for `<SceneCanvas>`. A scene is the only thing it needs. With nothing\n * else it renders that scene and keeps a selection no input sets; `features`\n * turns behavior on by preset, and the rest configures what those turn on. */\nexport type SceneCanvasProps<TData, TLayer extends string, TPose> =\n Omit<\n CanvasProps<TPose>,\n | 'adapter' | 'boundsOf' | 'selection' | 'tools'\n | 'viewState' // SceneCanvas makes the camera from the view props below\n | 'layers' // stripped so we can re-add as optional below\n | 'getIsVisible' // SceneCanvas synthesizes this from chromeVisibility\n | 'contentVersion' // SceneCanvas wires this to the scene's own version\n | 'layerVisibility' | 'layerOrder' // re-declared below: they gate picking here too\n | 'debug' // re-declared below with SceneCanvas's own `slops`\n > & CameraProps\n & {\n /** A `Scene` (typically from `useScene`) — or a `SerializedScene` JSON\n * object, which SceneCanvas bakes into a Scene on first render. The\n * serialized form is read once; pass a `key` on `<SceneCanvas>` to force\n * a fresh canvas from updated JSON.\n *\n * The JSON shape is relaxed (`version: number` rather than the `1`\n * literal) so an `import json from './x.json'` result satisfies the type\n * without an `as` cast. */\n scene:\n | Scene<TData, TLayer, TPose>\n | SerializedScene<TData, TLayer, TPose>\n | { version: number; systemLayers?: ReadonlyArray<{ id: string }>; nodes: ReadonlyArray<unknown> };\n\n /** Layer configuration. When omitted, SceneCanvas applies kit defaults\n * (a scene slot that paints `node.data.fill` rects + a default\n * selection overlay). A partial scene or selection-overlay config is\n * spread over that slot's defaults; pass `slot: null` to suppress a\n * default explicitly. */\n layers?: SceneCanvasLayers<Node<TData, TLayer, TPose>, TPose>;\n\n /** Which layout container a drag lands in when several contain the drop\n * point — the innermost (default), the topmost in paint order, or only\n * containers whose strategy declares a `dropRegion`. Decides both the\n * drag-time reflow preview and the commit. */\n layoutDropTarget?: LayoutDropTargetMode;\n\n /** Carries the siblings a layout reflow displaces to their slots over time\n * instead of snapping them — `useAnimatedReflow` builds one. Covers a\n * drag's reflow and every one the scene records (an insert, delete,\n * reorder or resize inside a laid-out container). Absent or `null`,\n * they snap. */\n reflowTransition?: ReflowTransition<TPose> | null;\n\n /** Glides what is shown when the scene writes a pose — a `scene.setPose`, an undo — and sees\n * removed nodes off with `exit`. Absent or `null`, writes snap. See {@link PoseTransitionSeat}. */\n poseTransition?: PoseTransitionSeat<TPose> | null;\n\n /**\n * Lets pose-transform actions (move, resize, nudge, flip — NOT rotate) also rewrite a\n * node's data-held geometry. Given a node and the affine `m` applied to its pose,\n * `transform(node, m)` returns updated `data`, or `null` for nodes with no data-held\n * geometry. When absent, the kit emits only the pose op and leaves `data` untouched.\n *\n * @see GeometryProjection\n */\n geometryProjection?: GeometryProjection;\n\n /**\n * Routing-trait classifiers. The kit builds a `NodeRouting` registry per `<SceneCanvas>`\n * from this prop and uses it to derive each hit's `kind`, which tool routing tables\n * (e.g. `{ target: 'rect', actionId: 'move' }`) match against. Pass `defaultNodeRouting`\n * for the kit's built-in shape kinds; spread additional entries for consumer-defined\n * kinds.\n *\n * **Memoize the `routing` value.** The registry is memoized on the prop's reference\n * identity: a fresh array each render rebuilds it and cascades into a new adapter,\n * churning gesture state.\n */\n routing?: readonly NodeRoutingEntry[];\n\n /** How to read and rewrite this scene's poses. Every built-in action,\n * the selection chrome and picking read it. Default `AUTO_POSE_DESCRIPTOR`\n * (rect poses and `Path` poses). */\n poseDescriptor?: PoseDescriptor<TPose>;\n\n // --- Geometry: hit-test + bounds overrides consumed by the internal\n // `useSelectTool`. Ignored if the consumer passes their own `tools`. ---\n geometry?: SceneCanvasGeometry;\n\n // --- Selection options. `pickBest` and `handleHitRadius` configure the\n // internal select tool, and are ignored under a `tools` takeover;\n // `move`, `resize` and `rotate` configure the `move`,\n // `resize` and `rotate` presets, and apply either way. ---\n selectTool?: {\n move?: UseMoveOptions<TPose>;\n resize?: UseResizeOptions<TPose>;\n /** Rotation options, or `false` to disable rotation entirely — drops the\n * `rotate` action AND hides the selection rotation-handle chrome. */\n rotate?: UseRotateOptions<TPose> | false;\n handleHitRadius?: number;\n /** Override the body-pick used on click/pointerdown. Alt-aware: receives\n * the live alt state + current selection so consumers can implement\n * alt-cycling through an overlapping stack. Default: top-most hit\n * (alt ignored). */\n pickBest?: (worldX: number, worldY: number, alt: boolean, sel: readonly string[]) => string | null;\n };\n\n /** Consumer node factories for the `insert` action, keyed by tool `kind`.\n * Each factory receives the drag AABB + tool `extras` and returns the\n * node's `data` (in this canvas's own data shape) plus an optional `pose`.\n * A factory for a kit kind (`rect`, `line`, …) replaces the kit's default\n * `{ path, fill }` node for that kind; a factory for a novel kind (e.g.\n * `text`) adds insert support the kit doesn't ship. The dep supplies id,\n * layer, and the undoable op. Return `null` to reject an insert. */\n insertNodeFactories?: Record<string, InsertNodeFactory>;\n\n /** The fill, stroke, and fill rule a kit-built shape is inserted with, by\n * tool `kind` and insert count; the kit keeps the geometry. Default\n * `paletteInsertPaint`, the kit palette in turn. A kind with a factory in\n * `insertNodeFactories` is not asked. */\n insertPaint?: InsertPaint;\n\n /** External-content ingestion (OS drop / clipboard paste / picker).\n *\n * - `handlers` — consumer content handlers registered for this canvas's\n * lifetime (priority 0 by default — they beat the kit's `image/*` /\n * `image/svg+xml` handlers at -100/-90).\n * - `resolveSrc` — overrides the image handler's `data:`-URI embed (e.g.\n * upload to an asset store, return the URL).\n * - `svg.unpack` — makes the kit SVG handler parse dropped SVG files into\n * native scene nodes instead of one embedded-image node each.\n * - `clipboard` — the kit weasel-JSON paste handler, enabled by default.\n * `reviver` restores JSON-unfriendly values the copying side encoded via\n * `jsonReplacer`. `enabled: false` opts the canvas out, but the kit\n * handler still consumes weasel-matching items and declines them inert\n * rather than letting them fall through. Also governs Cmd/Ctrl+V under\n * the `edit` preset; the rest takes the `ingest` preset.\n *\n * Memoize `handlers` and `clipboard.reviver`: an inline array literal\n * re-registers the handlers on every render. */\n ingestion?: {\n handlers?: ContentHandlerEntry[];\n resolveSrc?: (file: File) => Promise<string>;\n svg?: SvgIngestOptions;\n clipboard?: {\n reviver?: (key: string, value: unknown) => unknown;\n enabled?: boolean;\n /** Called when a paste left copied nodes out, with each one and the\n * reason. `useClipboardOps` takes the same callback as\n * `onPasteOmitted` for a paste from its own in-memory copy. */\n onOmitted?: (omitted: PasteOmission[]) => void;\n };\n };\n\n selection?: SelectionApi;\n selectionOptions?: UseSelectionOptions;\n\n /**\n * `false` stops the canvas writing the selection: no click, marquee,\n * lasso, action or tool, and no op committed through the adapter it hands\n * its tools. The consumer's own `SelectionApi` — the `selection` prop, or\n * `useSelection({ scene })` — still writes, and the canvas draws what it\n * holds. Undo and redo still restore the selection each history entry\n * recorded. Default `true`.\n *\n * Click policy (whether shift-click extends) is the selection's `mode`:\n * `useSelection({ mode: 'multi' })`, or `selectionOptions={{ mode: 'multi' }}`\n * for the selection the canvas builds itself.\n */\n selectable?: boolean;\n\n /**\n * Behavior presets to turn on, composable in any combination. A canvas\n * with none renders its scene and keeps a selection (the `selection` API\n * works) that no input sets: no tools, no standard actions or their keys,\n * no clipboard, no drop or paste, and no selection chrome. The dispatcher\n * is still mounted, so bindings a consumer adds work.\n *\n * - `view` — wheel pan and zoom, pinch, the zoom keys, and the hand tool\n * (H, or hold Space). Passing `viewport` implies it.\n * - `select` — the select tool, as the initial active tool and Escape's\n * return target: click to pick, drag on empty to marquee, click on empty\n * to clear.\n * - `outline` — the selection outline, whichever tool sets the selection.\n * - `pick` — `select` and `outline`.\n * - `move` — drag a body to move it, Alt-drag to clone it. Ambient, so it\n * runs under any tool that does not claim the drag.\n * - `resize` — resize handles, drawn and bound.\n * - `rotate` — the rotation handle, drawn and bound.\n * - `transform` — `resize` and `rotate`.\n * - `edit` — undo/redo, delete, duplicate, group/ungroup, nudge,\n * select-all, Escape, cancel-gesture, cut/copy/paste, fill and stroke,\n * and their keys. Cmd/Ctrl+V pastes nodes a kit canvas copied, from\n * this tab or another, and nothing else.\n * - `arrange` — align, distribute, reorder, flip.\n * - `paths` — pathfinder operations, path-edit entry and anchor editing.\n * - `ingest` — dropped and pasted content: images, SVG, files, and\n * whatever `ingestion.handlers` accept, on Cmd/Ctrl+V or an OS drop.\n * - `draw` — all of the above.\n *\n * Any `FeaturePreset` object goes beside the names: core's own\n * (`pathsPreset`), or one a package ships.\n * Tools add the actions they bind — a shape tool brings `insert` — so\n * `defaultTools` composes with any preset. `actions` then adds, overrides\n * or removes on top of what the presets registered.\n */\n features?: readonly FeatureEntry[];\n\n /** Extra tools or overrides keyed by id, or a full `ToolsApi` takeover.\n *\n * **Patch form** (`Record<string, Tool | true | false>`): merged\n * into the built-in registry on top of whatever `defaultTools` and\n * `features` already selected.\n * - `true` pulls in the built-in for this id (`'pen'`, `'lasso'`,\n * `'hand'`, …), the same as listing it in `defaultTools`. Unknown\n * built-in ids warn in dev and are ignored.\n * - `Tool` adds a new id or replaces an existing one\n * (dev-only warning on replace).\n * - `false` omits a bundled tool entirely.\n * Auto-wiring (keybindings, dispatcher, action registry) still runs.\n *\n * **Takeover form** (`ToolsApi`): the internal registry is bypassed and\n * this `tools` value is forwarded to Canvas as-is — the consumer owns\n * active-slot management, and `pick`'s select tool is theirs to supply.\n * Every other preset still applies. Keybindings are still auto-wired\n * against the supplied registry; pass `enableKeybindings={false}` to opt\n * out. */\n tools?: ToolsApi | Record<string, Tool | true | false>;\n\n /**\n * Auto-wire keyboard shortcuts. Default `true`. When `false`, SceneCanvas still mounts\n * its tools but routes no keyboard input to them — neither tool hotkeys nor\n * keyboard-bound actions like delete / escape / nudge. Pointer, wheel, and contextmenu\n * interactions are unaffected.\n */\n enableKeybindings?: boolean;\n\n /**\n * Take the keyboard on mount, as a press in the canvas would. A key that\n * reaches the page goes to the canvas the user last pressed or scrolled\n * in, and to no canvas before the first such interaction, so a canvas in a\n * side panel does not take Space from a page that wants it. An app whose\n * canvas is the page sets this so its shortcuts work before the first\n * click. Default `false`.\n */\n claimKeys?: boolean;\n\n /**\n * Auto-mount the gesture dispatcher (`useGestureDispatcher`). Default `true`. `false` is\n * for tests or demos that drive actions another way, or that call\n * `useGestureDispatcher` themselves.\n */\n enableGestureDispatcher?: boolean;\n\n /** Called with the `ToolsApi` SceneCanvas constructs or receives, whenever its identity\n * changes. For introspection. */\n onToolsCreated?: (tools: ToolsApi) => void;\n\n /**\n * Built-in tools SceneCanvas registers in its internal `useTools`, on top\n * of the ones presets bring (`select` from `pick`, `hand` from `view`).\n * Default: none. Each tool also registers the kit actions it binds, so\n * `['rect']` brings `insert`. Ignored when the consumer supplies their own\n * `tools` prop.\n */\n defaultTools?: readonly BuiltinToolId[];\n\n /** Per-tool option overrides for the built-in tools. Each entry is a\n * narrow subset of the underlying hook's options surface — `lasso.mode`,\n * `rig.state`, etc. */\n toolOptions?: BuiltinToolOptions;\n /** What gestures snap to, and how near it pulls. */\n snap?: SceneCanvasSnap;\n\n /** Initial active-slot tool id. Default: `'select'` when it is\n * registered, otherwise none — a canvas can run on ambient bindings\n * alone. Must be one of the registered tools. Ignored when the consumer\n * supplies their own `tools` prop. */\n initialActiveTool?: string;\n\n /** Always-on entries to register alongside the internal tools — every one\n * a `SurfaceContribution`, whose views, deps, overlay, bindings, actions\n * and `attach` all install from this one list, and uninstall when the\n * entry leaves it. A tool is a contribution too, so one can go here. If\n * you supply your own `tools` prop, this is ignored — wire `ambient`\n * through your own `useTools` call instead. */\n ambient?: readonly SurfaceContribution[];\n\n /** What an entry's `requires` does when the running kit does not meet\n * it: `'warn'` (the default) logs in development, `'strict'` throws,\n * `'off'` skips the check. */\n versionCheck?: VersionCheck;\n\n /** Touch and pen long-press: its hold time, its haptic, and the\n * feedback shown while it is held. */\n longPress?: SceneCanvasLongPress;\n\n /** Configures the `view` preset, and implies it. See {@link SceneCanvasViewport}. */\n viewport?: SceneCanvasViewport;\n\n /**\n * Tune actions on this canvas without restating them, keyed by action id:\n * `params` every invocation starts from, and `bindings` added beside the\n * action's own. A tuning applies to whichever descriptor holds the id, a\n * preset's or a tool's. Pass a stable object; a params thunk is read on\n * every call. See the core README (\"Tuning an action\").\n */\n tune?: ActionTunings;\n\n /**\n * Replace, add or mute whole action descriptors. Pass `null` to disable\n * all defaults. To change a built-in's params or add a key, use `tune`.\n */\n actions?: ActionsProp;\n\n /**\n * Given a scene node, return a short human-readable \"kind\" label (e.g. `'rectangle'`,\n * `'sticky note'`), which the kit publishes per id into any surrounding\n * `<SelectionContextProvider>`. Return `undefined` to skip an entry. When omitted,\n * containers report `'group'`, poses with a `kind` property report `'path'`, and\n * everything else is left unlabelled.\n */\n describeKind?: (node: Node<TData, TLayer, TPose>) => string | undefined;\n\n /**\n * Animator to bind for per-frame redraws. SceneCanvas requests a redraw on every active\n * animation frame and paints `animator.colorOverrides` onto the scene's nodes: the\n * kit's path and shape painters apply them, and a custom `drawOne` receives them as\n * `ctx.vertexColors`.\n */\n animator?: Animator;\n\n /**\n * Extra views on this canvas: each is a camera over a rect of the same\n * surface, drawn through one GL context, with input routed to it. The flat\n * `view` / `onViewChange` props above stay the canvas's own camera — view\n * zero — and are unaffected by anything declared here.\n *\n * Order is paint and hit order, low to high. Each entry is a\n * `<CanvasView>`; mounting one as a child is the same declaration, and\n * children land after every entry here.\n */\n views?: readonly CanvasViewProps[];\n\n /**\n * Children rendered alongside the canvas, inside its input scope (e.g.\n * shortcuts overlays, probes).\n */\n children?: ReactNode;\n\n /** A yoke to join, from `useYoke()`: canvases on one yoke share the active tool, the gesture\n * in flight and history. Omitted, this canvas keeps its own. */\n yoke?: Yoke;\n\n /**\n * Chrome-caps visibility overrides, keyed by chrome id (`selection.outline`,\n * `selection.rotation-handle`, `gesture.marquee`, …). Each entry is a composable\n * {@link Condition} built from the `cond()` builder, merged on top of the kit's\n * `defaultVisibilityRules`. Set an id to `never` to suppress a chrome element\n * entirely (also unhittable), or to `always` to force-show.\n */\n chromeVisibility?: import('features/chrome-caps').VisibilityRules;\n\n /**\n * The app's mode registry (`createModeRegistry` in `@weasel-js/modes`).\n * The canvas reads the active mode from it to gate chrome, tool\n * activation and the dispatcher's eligibility filter, repaints when it\n * switches, and hands every registered mode to the dev-time route-conflict\n * check. Omitted, the canvas behaves as the kit's normal mode and nothing\n * revokes anchor editing.\n */\n modes?: ModeRegistry;\n\n /** Hands which path is being anchor-edited to the host. See {@link PathEditHost}. */\n pathEdit?: PathEditHost;\n /** A path to open in anchor edit as the canvas mounts, with anchors selected. Read once. */\n defaultPathEdit?: PathEditOpening;\n\n /**\n * Override detected device facts. Merged over what `matchMedia` reports;\n * `targetScale` is re-derived from the merged `coarsePointer` unless you\n * override it explicitly.\n */\n device?: Partial<DeviceProfile>;\n\n /**\n * Live focus getter for chrome-caps' `focused` ctx field, for visibility rules that\n * read the `focused` atom (the kit's default `selection.rotation-handle` rule does).\n * Omit to default `focused` to `true`.\n */\n getFocused?: () => boolean;\n\n /** Custom shader programs to compile on the renderer. See `CanvasProps.shaders`. */\n shaders?: ShaderProgramHandle[];\n\n /** Flatness tolerance for curve tessellation. See `CanvasProps.flattenTolerance`. */\n flattenTolerance?: FlattenTolerance;\n\n /** Fill for the full canvas behind the scene, drawn as a screen-space layer slotted\n * before `'scene'` — independent of pan / zoom. */\n backgroundFill?: Paint;\n /** Dev HUD: a fixed-position widget showing live cursor coords in both viewport\n * (client) and canvas (world) frames. */\n cursorCoordsHud?: boolean;\n /** Dev HUD: a fixed-position widget listing the ids `pickEvery(world)` returns under\n * the cursor. */\n pickHud?: boolean;\n /**\n * The debug overlay: `<Canvas debug>`'s config, plus `slops: true` for\n * translucent halos at every affordance hit zone. `false` turns it off;\n * absent reads `?debug=…` from the URL, as `<Canvas>` does.\n */\n debug?: (DebugConfig & { slops?: boolean }) | false;\n /**\n * Dev HUD: when true (or object), mounts a fixed-position widget below\n * the pick HUD showing the active modality mode, active-slot tool, and\n * hotkey stack. Pass `{ modeId }` to populate the mode line.\n */\n modalityHud?: boolean | { modeId?: string };\n\n /**\n * Per-id alpha multiplier for the scene-render slot: each node's draw output is wrapped\n * in a group with the returned alpha, and 1 emits no wrapper. Typical use: dimming\n * non-active nodes during a mode transition.\n */\n alphaFor?: (id: string) => number;\n\n /**\n * Show or hide render layers in this canvas's own view, by id — the map\n * `<Canvas>` takes. Each scene layer paints as its own render layer, keyed\n * `scene:<layerId>`, so `{ 'scene:guides': false }` hides one scene layer\n * here and nowhere else.\n *\n * A layer hidden this way is gone from this view: it does not paint, and a\n * click, a marquee or Cmd+A here passes over it. Another view of the same\n * scene — a `<CanvasView>`, a second canvas, a minimap — still shows it and\n * can still take it. It applies on top of the scene's own\n * `LayerRecord.visible` and cannot show a layer the scene hides.\n */\n layerVisibility?: Record<string, boolean>;\n\n /**\n * Draw order for this view, by render-layer id, bottom first. A listed\n * order is the whole list: a scene layer left out of it is neither painted\n * nor picked here. See `CanvasProps.layerOrder`.\n */\n layerOrder?: string[];\n } & SceneCanvasPointerProps;\n"],"mappings":";;;;;;;;AAsDA,IAAa,sBAAsB;;;AAkCnC,IAAa,mBAA6C;CAAC;CAAU;CAAQ,GAAG;CAAiB;CAAS;CAAQ;AAAQ"}
|
|
1
|
+
{"version":3,"file":"props.js","names":[],"sources":["../../../src/canvas/SceneCanvas/props.ts"],"sourcesContent":["import type { ModeRegistry } from '@weasel-js/modes';\nimport type { PathEditHost, PathEditOpening } from './pathEditHost';\nimport type { SceneCanvasGeometry } from './geometryProps';\nimport type { SceneCanvasHit, SceneCanvasPointerProps } from './pointerProps';\nimport type { Paint } from '@weasel-js/paint';\nimport type { ActionsProp, ActionTunings } from '@weasel-js/routing';\nimport { Yoke } from '@weasel-js/routing/react';\nimport type { PasteOmission } from 'core/adapters/types';\nimport type { Op } from 'core/ops/types';\nimport type { Node, Scene, SerializedScene } from 'core/scene/types';\nimport type { SelectionApi, UseSelectionOptions } from 'core/selection/useSelection';\nimport type { ContentHandlerEntry } from 'features/ingestion';\nimport type { SceneCanvasSnap } from 'features/snap/types';\nimport type { SvgIngestOptions } from 'interactions/actions/depSchema';\nimport type { GeometryProjection } from 'interactions/actions/geometryProjection';\nimport type { UseMoveOptions } from 'interactions/actions/move/options';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport type { UseResizeOptions } from 'interactions/actions/resize/options';\nimport type { UseRotateOptions } from 'interactions/actions/rotate/options';\nimport type { ReactNode } from 'react';\nimport type { Animator } from '@weasel-js/animator';\nimport type { PoseTransitionSeat } from '../../animation/poseTransition';\nimport { HANDLE_BASE_PX } from '../../core/device/targets';\nimport type { DeviceProfile } from '../../core/device/types';\nimport type { NodeRoutingEntry } from '../../core/scene/NodeRouting';\nimport type { DebugConfig } from '../../debug/types';\nimport type { LayoutDropTargetMode, ReflowTransition } from '../../layout/types';\nimport type { FlattenTolerance, ShaderProgramHandle } from '@weasel-js/renderer';\nimport type { Tool, ToolsApi } from '../../tools/overlayBinding';\nimport type { SceneSlotConfig } from '../buildSceneLayer';\nimport type { CanvasProps } from '../Canvas';\nimport type { LayersMap } from '../layerSlots';\nimport type { CanvasViewProps } from '../CanvasView';\nimport type { InsertNodeFactory, InsertPaint } from '../deps';\nimport type { SurfaceContribution } from '../surfaceContribution';\nimport type { CameraProps } from '../useCanvasView';\nimport type { FeatureEntry } from './features';\nimport type { BuiltinToolOptions } from './useBuiltinShapeTools';\nimport type { VersionCheck } from './useContributionRoles';\nimport type { SceneCanvasViewport } from './viewportProp';\n\n/** The adapter surface delete / duplicate / group / ungroup need, narrowed from\n * `SceneCanvasAdapter` because `useSceneStandardActions` is non-generic. */\nexport interface BridgeAdapter {\n applyOps(ops: Op[], label?: string): void;\n insertNode(node: { id: string; [k: string]: unknown }): void;\n removeNode(id: string): void;\n setSelection(ids: string[]): void;\n}\n\n/** Default size in CSS pixels for selection corner-handles AND their\n * hit-test radius, at `targetScale = 1`. Deliberately unscaled; kit-internal\n * use sites multiply by `DeviceProfile.targetScale`. */\nexport const DEFAULT_HANDLE_SIZE = HANDLE_BASE_PX;\n\n/** `<SceneCanvas longPress>`. */\nexport interface SceneCanvasLongPress {\n /**\n * Shown while a long-press is held and some binding would fire on it.\n * Default: a ring that fills around the press point\n * (`createLongPressFeedbackContribution()`), static under\n * `prefers-reduced-motion`. `false` shows nothing; a contribution replaces\n * it, reading the `longPress` dep. Installed beside `ambient`, so under a\n * `tools` takeover add it to your own `useTools` call instead.\n */\n feedback?: boolean | SurfaceContribution;\n /** Default true. A long-press some binding handled pulses\n * `navigator.vibrate` briefly, for touch and pen, where the API exists. */\n haptics?: boolean;\n /** Hold time in ms. Default `LONG_PRESS_MS` (500). */\n duration?: number;\n}\n\n/** `<SceneCanvas layers>`: a {@link LayersMap} whose scene slot may be partial,\n * since the defaults fill in whatever it leaves out. */\nexport type SceneCanvasLayers<TNode extends { id: string }, TPose> = LayersMap<\n TNode,\n TPose,\n Partial<SceneSlotConfig<TNode, TPose>>\n>;\n\nimport type { BuiltinToolId } from './builtinToolSets';\nimport type { ToolEntry } from '@weasel-js/routing';\nexport { BUILTIN_TOOL_IDS, type BuiltinToolId } from './builtinToolSets';\n\nexport type { SceneCanvasHit };\n\n/** Props for `<SceneCanvas>`. A scene is the only thing it needs. With nothing\n * else it renders that scene and keeps a selection no input sets; `features`\n * turns behavior on by preset, and the rest configures what those turn on. */\nexport type SceneCanvasProps<TData, TLayer extends string, TPose> =\n Omit<\n CanvasProps<TPose>,\n | 'adapter' | 'boundsOf' | 'selection' | 'tools'\n | 'viewState' // SceneCanvas makes the camera from the view props below\n | 'layers' // stripped so we can re-add as optional below\n | 'getIsVisible' // SceneCanvas synthesizes this from chromeVisibility\n | 'contentVersion' // SceneCanvas wires this to the scene's own version\n | 'layerVisibility' | 'layerOrder' // re-declared below: they gate picking here too\n | 'debug' // re-declared below with SceneCanvas's own `slops`\n > & CameraProps\n & {\n /** A `Scene` (typically from `useScene`) — or a `SerializedScene` JSON\n * object, which SceneCanvas bakes into a Scene on first render. The\n * serialized form is read once; pass a `key` on `<SceneCanvas>` to force\n * a fresh canvas from updated JSON.\n *\n * The JSON shape is relaxed (`version: number` rather than the `1`\n * literal) so an `import json from './x.json'` result satisfies the type\n * without an `as` cast. */\n scene:\n | Scene<TData, TLayer, TPose>\n | SerializedScene<TData, TLayer, TPose>\n | { version: number; systemLayers?: ReadonlyArray<{ id: string }>; nodes: ReadonlyArray<unknown> };\n\n /** Layer configuration. When omitted, SceneCanvas applies kit defaults\n * (a scene slot that paints `node.data.fill` rects + a default\n * selection overlay). A partial scene or selection-overlay config is\n * spread over that slot's defaults; pass `slot: null` to suppress a\n * default explicitly. */\n layers?: SceneCanvasLayers<Node<TData, TLayer, TPose>, TPose>;\n\n /** Which layout container a drag lands in when several contain the drop\n * point — the innermost (default), the topmost in paint order, or only\n * containers whose strategy declares a `dropRegion`. Decides both the\n * drag-time reflow preview and the commit. */\n layoutDropTarget?: LayoutDropTargetMode;\n\n /** Carries the siblings a layout reflow displaces to their slots over time\n * instead of snapping them — `useAnimatedReflow` builds one. Covers a\n * drag's reflow and every one the scene records (an insert, delete,\n * reorder or resize inside a laid-out container). Absent or `null`,\n * they snap. */\n reflowTransition?: ReflowTransition<TPose> | null;\n\n /** Glides what is shown when the scene writes a pose — a `scene.setPose`, an undo — and sees\n * removed nodes off with `exit`. Absent or `null`, writes snap. See {@link PoseTransitionSeat}. */\n poseTransition?: PoseTransitionSeat<TPose> | null;\n\n /**\n * Lets pose-transform actions (move, resize, nudge, flip — NOT rotate) also rewrite a\n * node's data-held geometry. Given a node and the affine `m` applied to its pose,\n * `transform(node, m)` returns updated `data`, or `null` for nodes with no data-held\n * geometry. When absent, the kit emits only the pose op and leaves `data` untouched.\n *\n * @see GeometryProjection\n */\n geometryProjection?: GeometryProjection;\n\n /**\n * Routing-trait classifiers. The kit builds a `NodeRouting` registry per `<SceneCanvas>`\n * from this prop and uses it to derive each hit's `kind`, which tool routing tables\n * (e.g. `{ target: 'rect', actionId: 'move' }`) match against. Pass `defaultNodeRouting`\n * for the kit's built-in shape kinds; spread additional entries for consumer-defined\n * kinds.\n *\n * **Memoize the `routing` value.** The registry is memoized on the prop's reference\n * identity: a fresh array each render rebuilds it and cascades into a new adapter,\n * churning gesture state.\n */\n routing?: readonly NodeRoutingEntry[];\n\n /** How to read and rewrite this scene's poses. Every built-in action,\n * the selection chrome and picking read it. Default `AUTO_POSE_DESCRIPTOR`\n * (rect poses and `Path` poses). */\n poseDescriptor?: PoseDescriptor<TPose>;\n\n // --- Geometry: hit-test + bounds overrides consumed by the internal\n // `useSelectTool`. Ignored if the consumer passes their own `tools`. ---\n geometry?: SceneCanvasGeometry;\n\n // --- Selection options. `pickBest` and `handleHitRadius` configure the\n // internal select tool, and are ignored under a `tools` takeover;\n // `move`, `resize` and `rotate` configure the `move`,\n // `resize` and `rotate` presets, and apply either way. ---\n selectTool?: {\n move?: UseMoveOptions<TPose>;\n resize?: UseResizeOptions<TPose>;\n /** Rotation options, or `false` to hide the rotation handle and bind it to\n * nothing; the `rotate` action stays, for other tools and `actions.rotate`. */\n rotate?: UseRotateOptions<TPose> | false;\n handleHitRadius?: number;\n /** Override the body-pick used on click/pointerdown. Alt-aware: receives\n * the live alt state + current selection so consumers can implement\n * alt-cycling through an overlapping stack. Default: top-most hit\n * (alt ignored). */\n pickBest?: (worldX: number, worldY: number, alt: boolean, sel: readonly string[]) => string | null;\n };\n\n /** Consumer node factories for the `insert` action, keyed by tool `kind`.\n * Each factory receives the drag AABB + tool `extras` and returns the\n * node's `data` (in this canvas's own data shape) plus an optional `pose`.\n * A factory for a kit kind (`rect`, `line`, …) replaces the kit's default\n * `{ path, fill }` node for that kind; a factory for a novel kind (e.g.\n * `text`) adds insert support the kit doesn't ship. The dep supplies id,\n * layer, and the undoable op. Return `null` to reject an insert. */\n insertNodeFactories?: Record<string, InsertNodeFactory>;\n\n /** The fill, stroke, and fill rule a kit-built shape is inserted with, by\n * tool `kind` and insert count; the kit keeps the geometry. Default\n * `paletteInsertPaint`, the kit palette in turn. A kind with a factory in\n * `insertNodeFactories` is not asked. */\n insertPaint?: InsertPaint;\n\n /** External-content ingestion (OS drop / clipboard paste / picker).\n *\n * - `handlers` — consumer content handlers registered for this canvas's\n * lifetime (priority 0 by default — they beat the kit's `image/*` /\n * `image/svg+xml` handlers at -100/-90).\n * - `resolveSrc` — overrides the image handler's `data:`-URI embed (e.g.\n * upload to an asset store, return the URL).\n * - `svg.unpack` — makes the kit SVG handler parse dropped SVG files into\n * native scene nodes instead of one embedded-image node each.\n * - `clipboard` — the kit weasel-JSON paste handler, enabled by default.\n * `reviver` restores JSON-unfriendly values the copying side encoded via\n * `jsonReplacer`. `enabled: false` opts the canvas out, but the kit\n * handler still consumes weasel-matching items and declines them inert\n * rather than letting them fall through. Also governs Cmd/Ctrl+V under\n * the `edit` preset; the rest takes the `ingest` preset.\n *\n * Memoize `handlers` and `clipboard.reviver`: an inline array literal\n * re-registers the handlers on every render. */\n ingestion?: {\n handlers?: ContentHandlerEntry[];\n resolveSrc?: (file: File) => Promise<string>;\n svg?: SvgIngestOptions;\n clipboard?: {\n reviver?: (key: string, value: unknown) => unknown;\n enabled?: boolean;\n /** Called when a paste left copied nodes out, with each one and the\n * reason. `useClipboardOps` takes the same callback as\n * `onPasteOmitted` for a paste from its own in-memory copy. */\n onOmitted?: (omitted: PasteOmission[]) => void;\n };\n };\n\n selection?: SelectionApi;\n selectionOptions?: UseSelectionOptions;\n\n /**\n * `false` stops the canvas writing the selection: no click, marquee,\n * lasso, action or tool, and no op committed through the adapter it hands\n * its tools. The consumer's own `SelectionApi` — the `selection` prop, or\n * `useSelection({ scene })` — still writes, and the canvas draws what it\n * holds. Undo and redo still restore the selection each history entry\n * recorded. Default `true`.\n *\n * Click policy (whether shift-click extends) is the selection's `mode`:\n * `useSelection({ mode: 'multi' })`, or `selectionOptions={{ mode: 'multi' }}`\n * for the selection the canvas builds itself.\n */\n selectable?: boolean;\n\n /**\n * Behavior presets to turn on, composable in any combination. A canvas\n * with none renders its scene and keeps a selection (the `selection` API\n * works) that no input sets: no tools, no standard actions or their keys,\n * no clipboard, no drop or paste, and no selection chrome. The dispatcher\n * is still mounted, so bindings a consumer adds work.\n *\n * - `view` — wheel pan and zoom, pinch, the zoom keys, and the hand tool\n * (H, or hold Space). Passing `viewport` implies it.\n * - `select` — the select tool, as the initial active tool and Escape's\n * return target: click to pick, drag on empty to marquee, click on empty\n * to clear.\n * - `outline` — the selection outline, whichever tool sets the selection.\n * - `pick` — `select` and `outline`.\n * - `move` — drag a body to move it, Alt-drag to clone it. Ambient, so it\n * runs under any tool that does not claim the drag.\n * - `resize` — resize handles, drawn and bound.\n * - `rotate` — the rotation handle, drawn and bound.\n * - `transform` — `resize` and `rotate`.\n * - `edit` — undo/redo, delete, duplicate, group/ungroup, nudge,\n * select-all, Escape, cancel-gesture, cut/copy/paste, fill and stroke,\n * and their keys. Cmd/Ctrl+V pastes nodes a kit canvas copied, from\n * this tab or another, and nothing else.\n * - `arrange` — align, distribute, reorder, flip.\n * - `paths` — pathfinder operations, path-edit entry and anchor editing.\n * - `ingest` — dropped and pasted content: images, SVG, files, and\n * whatever `ingestion.handlers` accept, on Cmd/Ctrl+V or an OS drop.\n * - `draw` — all of the above.\n *\n * Any `FeaturePreset` object goes beside the names: core's own\n * (`pathsPreset`), or one a package ships.\n * Tools add the actions they bind — a shape tool brings `insert` — so\n * `defaultTools` composes with any preset. `actions` then adds, overrides\n * or removes on top of what the presets registered.\n */\n features?: readonly FeatureEntry[];\n\n /** Extra tools or overrides keyed by id, or a full `ToolsApi` takeover.\n *\n * **Patch form** (`Record<string, Tool | true | false>`): merged\n * into the built-in registry on top of whatever `defaultTools` and\n * `features` already selected.\n * - `true` pulls in the built-in for this id (`'pen'`, `'lasso'`,\n * `'hand'`, …), the same as listing it in `defaultTools`. Unknown\n * built-in ids warn in dev and are ignored.\n * - `Tool` adds a new id or replaces an existing one in place\n * (dev-only warning if `defaultTools` also names that id).\n * - `false` omits a bundled tool entirely.\n * Auto-wiring (keybindings, dispatcher, action registry) still runs.\n *\n * **Takeover form** (`ToolsApi`): the internal registry is bypassed and\n * this `tools` value is forwarded to Canvas as-is — the consumer owns\n * active-slot management, and `pick`'s select tool is theirs to supply.\n * Every other preset still applies. Keybindings are still auto-wired\n * against the supplied registry; pass `enableKeybindings={false}` to opt\n * out. */\n tools?: ToolsApi | Record<string, Tool | true | false>;\n\n /**\n * Auto-wire keyboard shortcuts. Default `true`. When `false`, SceneCanvas still mounts\n * its tools but routes no keyboard input to them — neither tool hotkeys nor\n * keyboard-bound actions like delete / escape / nudge. Pointer, wheel, and contextmenu\n * interactions are unaffected.\n */\n enableKeybindings?: boolean;\n\n /**\n * Take the keyboard on mount, as a press in the canvas would. A key that\n * reaches the page goes to the canvas the user last pressed or scrolled\n * in, and to no canvas before the first such interaction, so a canvas in a\n * side panel does not take Space from a page that wants it. An app whose\n * canvas is the page sets this so its shortcuts work before the first\n * click. Default `false`.\n */\n claimKeys?: boolean;\n\n /**\n * Auto-mount the gesture dispatcher (`useGestureDispatcher`). Default `true`. `false` is\n * for tests or demos that drive actions another way, or that call\n * `useGestureDispatcher` themselves.\n */\n enableGestureDispatcher?: boolean;\n\n /** Called with the `ToolsApi` SceneCanvas constructs or receives, whenever its identity\n * changes. For introspection. */\n onToolsCreated?: (tools: ToolsApi) => void;\n\n /**\n * Built-in tools SceneCanvas registers in its internal `useTools`, on top\n * of the ones presets bring (`select` from `pick`, `hand` from `view`):\n * ids, or sets of them such as `SHAPE_TOOLS`, or `withoutTools(...)` of one.\n * Default: none. Each tool also registers the kit actions it binds, so\n * `['rect']` brings `insert`. Ignored when the consumer supplies their own\n * `tools` prop.\n */\n defaultTools?: readonly ToolEntry<BuiltinToolId>[];\n\n /** Per-tool option overrides for the built-in tools. Each entry is a\n * narrow subset of the underlying hook's options surface — `lasso.mode`,\n * `rig.state`, etc. */\n toolOptions?: BuiltinToolOptions;\n /** What gestures snap to, and how near it pulls. */\n snap?: SceneCanvasSnap;\n\n /** Initial active-slot tool id. Default: `'select'` when it is\n * registered, otherwise none — a canvas can run on ambient bindings\n * alone. Must be one of the registered tools. Ignored when the consumer\n * supplies their own `tools` prop. */\n initialActiveTool?: string;\n\n /** Always-on entries to register alongside the internal tools — every one\n * a `SurfaceContribution`, whose views, deps, overlay, bindings, actions\n * and `attach` all install from this one list, and uninstall when the\n * entry leaves it. A tool is a contribution too, so one can go here. If\n * you supply your own `tools` prop, this is ignored — wire `ambient`\n * through your own `useTools` call instead. */\n ambient?: readonly SurfaceContribution[];\n\n /** What an entry's `requires` does when the running kit does not meet\n * it: `'warn'` (the default) logs in development, `'strict'` throws,\n * `'off'` skips the check. */\n versionCheck?: VersionCheck;\n\n /** Touch and pen long-press: its hold time, its haptic, and the\n * feedback shown while it is held. */\n longPress?: SceneCanvasLongPress;\n\n /** Configures the `view` preset, and implies it. See {@link SceneCanvasViewport}. */\n viewport?: SceneCanvasViewport;\n\n /**\n * Tune actions on this canvas without restating them, keyed by action id:\n * `params` every invocation starts from, and `bindings` added beside the\n * action's own. A tuning applies to whichever descriptor holds the id, a\n * preset's or a tool's. Pass a stable object; a params thunk is read on\n * every call. See the core README (\"Tuning an action\").\n */\n tune?: ActionTunings;\n\n /**\n * Replace, add or mute whole action descriptors. Pass `null` to disable\n * all defaults. To change a built-in's params or add a key, use `tune`.\n */\n actions?: ActionsProp;\n\n /**\n * Given a scene node, return a short human-readable \"kind\" label (e.g. `'rectangle'`,\n * `'sticky note'`), which the kit publishes per id into any surrounding\n * `<SelectionContextProvider>`. Return `undefined` to skip an entry. When omitted,\n * each node reports its routing kind (see `routing`), and a node that routes as\n * `'unknown'` is left unlabeled.\n */\n describeKind?: (node: Node<TData, TLayer, TPose>) => string | undefined;\n\n /**\n * Animator to bind for per-frame redraws. SceneCanvas requests a redraw on every active\n * animation frame and paints `animator.colorOverrides` onto the scene's nodes: the\n * kit's path and shape painters apply them, and a custom `drawOne` receives them as\n * `ctx.vertexColors`.\n */\n animator?: Animator;\n\n /**\n * Extra views on this canvas: each is a camera over a rect of the same\n * surface, drawn through one GL context, with input routed to it. The flat\n * `view` / `onViewChange` props above stay the canvas's own camera — view\n * zero — and are unaffected by anything declared here.\n *\n * Order is paint and hit order, low to high. Each entry is a\n * `<CanvasView>`; mounting one as a child is the same declaration, and\n * children land after every entry here.\n */\n views?: readonly CanvasViewProps[];\n\n /**\n * Children rendered alongside the canvas, inside its input scope (e.g.\n * shortcuts overlays, probes).\n */\n children?: ReactNode;\n\n /** A yoke to join, from `useYoke()`: canvases on one yoke share the active tool, the gesture\n * in flight and history. Omitted, this canvas keeps its own. */\n yoke?: Yoke;\n\n /**\n * Chrome-caps visibility overrides, keyed by chrome id (`selection.outline`,\n * `selection.rotation-handle`, `gesture.marquee`, …). Each entry is a composable\n * {@link Condition} built from the `cond()` builder, merged on top of the kit's\n * `defaultVisibilityRules`. Set an id to `never` to suppress a chrome element\n * entirely (also unhittable), or to `always` to force-show.\n */\n chromeVisibility?: import('features/chrome-caps').VisibilityRules;\n\n /**\n * The app's mode registry (`createModeRegistry` in `@weasel-js/modes`).\n * The canvas reads the active mode from it to gate chrome, tool\n * activation and the dispatcher's eligibility filter, repaints when it\n * switches, and hands every registered mode to the dev-time route-conflict\n * check. Omitted, the canvas behaves as the kit's normal mode and nothing\n * revokes anchor editing.\n */\n modes?: ModeRegistry;\n\n /** Hands which path is being anchor-edited to the host. See {@link PathEditHost}. */\n pathEdit?: PathEditHost;\n /** A path to open in anchor edit as the canvas mounts, with anchors selected. Read once. */\n defaultPathEdit?: PathEditOpening;\n\n /**\n * Override detected device facts. Merged over what `matchMedia` reports;\n * `targetScale` is re-derived from the merged `coarsePointer` unless you\n * override it explicitly.\n */\n device?: Partial<DeviceProfile>;\n\n /**\n * Live focus getter for chrome-caps' `focused` ctx field, for visibility rules that\n * read the `focused` atom (the kit's default `selection.rotation-handle` rule does).\n * Omit to default `focused` to `true`.\n */\n getFocused?: () => boolean;\n\n /** Custom shader programs to compile on the renderer. See `CanvasProps.shaders`. */\n shaders?: ShaderProgramHandle[];\n\n /** Flatness tolerance for curve tessellation. See `CanvasProps.flattenTolerance`. */\n flattenTolerance?: FlattenTolerance;\n\n /** Fill for the full canvas behind the scene, drawn as a screen-space layer slotted\n * before `'scene'` — independent of pan / zoom. */\n backgroundFill?: Paint;\n /** Dev HUD: a fixed-position widget showing live cursor coords in both viewport\n * (client) and canvas (world) frames. */\n cursorCoordsHud?: boolean;\n /** Dev HUD: a fixed-position widget listing the ids `pickEvery(world)` returns under\n * the cursor. */\n pickHud?: boolean;\n /**\n * The debug overlay: `<Canvas debug>`'s config, plus `slops: true` for\n * translucent halos at every affordance hit zone. `false` turns it off;\n * absent reads `?debug=…` from the URL, as `<Canvas>` does.\n */\n debug?: (DebugConfig & { slops?: boolean }) | false;\n /**\n * Dev HUD: when true (or object), mounts a fixed-position widget below\n * the pick HUD showing the active modality mode, active-slot tool, and\n * hotkey stack. Pass `{ modeId }` to populate the mode line.\n */\n modalityHud?: boolean | { modeId?: string };\n\n /**\n * Per-id alpha multiplier for the scene-render slot: each node's draw output is wrapped\n * in a group with the returned alpha, and 1 emits no wrapper. Typical use: dimming\n * non-active nodes during a mode transition.\n */\n alphaFor?: (id: string) => number;\n\n /**\n * Show or hide render layers in this canvas's own view, by id — the map\n * `<Canvas>` takes. Each scene layer paints as its own render layer, keyed\n * `scene:<layerId>`, so `{ 'scene:guides': false }` hides one scene layer\n * here and nowhere else.\n *\n * A layer hidden this way is gone from this view: it does not paint, and a\n * click, a marquee or Cmd+A here passes over it. Another view of the same\n * scene — a `<CanvasView>`, a second canvas, a minimap — still shows it and\n * can still take it. It applies on top of the scene's own\n * `LayerRecord.visible` and cannot show a layer the scene hides.\n */\n layerVisibility?: Record<string, boolean>;\n\n /**\n * Draw order for this view, by render-layer id, bottom first. A listed\n * order is the whole list: a scene layer left out of it is neither painted\n * nor picked here. See `CanvasProps.layerOrder`.\n */\n layerOrder?: string[];\n } & SceneCanvasPointerProps;\n"],"mappings":";;;;;;;;AAqDA,IAAa,sBAAsB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { presetBuiltinTools, presetOwnTools } from "./features.js";
|
|
2
|
-
import { BUILTIN_TOOL_IDS } from "./
|
|
2
|
+
import { BUILTIN_TOOL_IDS } from "./builtinToolSets.js";
|
|
3
3
|
import { isDev } from "@weasel-js/react";
|
|
4
|
+
import { toolIdsOf } from "@weasel-js/routing";
|
|
4
5
|
|
|
5
6
|
//#region src/canvas/SceneCanvas/toolRegistry.ts
|
|
6
7
|
/**
|
|
@@ -9,10 +10,13 @@ import { isDev } from "@weasel-js/react";
|
|
|
9
10
|
* Built-ins come first, in `BUILTIN_TOOL_IDS` order whatever order they were
|
|
10
11
|
* asked for in, then the presets' own tools in preset order; a patch tool
|
|
11
12
|
* replaces a mounted one where it stands, and any other is appended in patch
|
|
12
|
-
* order. That order is the palette's.
|
|
13
|
+
* order. That order is the palette's. Replacing a tool that is mounted only
|
|
14
|
+
* because a preset implies it is the documented way to restyle it, so only a
|
|
15
|
+
* patch tool for an id `defaultTools` also names is warned about.
|
|
13
16
|
*/
|
|
14
17
|
function resolveToolRegistry(args) {
|
|
15
|
-
const { builtins,
|
|
18
|
+
const { builtins, enabled, patch, dev = isDev() } = args;
|
|
19
|
+
const defaultTools = toolIdsOf(args.defaultTools ?? []);
|
|
16
20
|
const registry = {};
|
|
17
21
|
const preset = presetBuiltinTools(enabled);
|
|
18
22
|
for (const id of BUILTIN_TOOL_IDS) {
|
|
@@ -27,7 +31,7 @@ function resolveToolRegistry(args) {
|
|
|
27
31
|
if (dev && !BUILTIN_TOOL_IDS.includes(id)) console.warn(`[SceneCanvas] tools.${id}=true is not a known built-in id; ignoring`);
|
|
28
32
|
continue;
|
|
29
33
|
}
|
|
30
|
-
if (dev && id in registry) console.warn(`[SceneCanvas] tools prop overrides bundled "${id}" tool`);
|
|
34
|
+
if (dev && id in registry && defaultTools.includes(id)) console.warn(`[SceneCanvas] tools prop overrides bundled "${id}" tool`);
|
|
31
35
|
registry[id] = value;
|
|
32
36
|
}
|
|
33
37
|
return registry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolRegistry.js","names":[],"sources":["../../../src/canvas/SceneCanvas/toolRegistry.ts"],"sourcesContent":["import type { Tool } from 'tools/overlayBinding';\nimport { presetBuiltinTools, presetOwnTools, type EnabledPresets } from './features';\nimport { isDev } from '@weasel-js/react';\nimport { BUILTIN_TOOL_IDS, type BuiltinToolId } from './props';\n\n/** The patch form of `<SceneCanvas tools>`: per id, `true` mounts that\n * built-in, `false` leaves it out, and a tool adds or replaces one. */\nexport type ToolsPatch = Record<string, Tool | true | false>;\n\n/** One tool per built-in id, mounted or not. */\nexport type BuiltinTools = Record<BuiltinToolId, Tool>;\n\nexport interface ResolveToolRegistryArgs {\n builtins: BuiltinTools;\n /** Built-ins asked for by id. */\n defaultTools?: readonly BuiltinToolId[];\n /** The presets the canvas runs with, each bringing the tools it names. */\n enabled: EnabledPresets;\n patch: ToolsPatch | null;\n /** Whether to warn about a patch entry that is probably a mistake. */\n dev?: boolean;\n}\n\n/**\n * The tool registry a canvas mounts when it is not handed a whole `ToolsApi`.\n *\n * Built-ins come first, in `BUILTIN_TOOL_IDS` order whatever order they were\n * asked for in, then the presets' own tools in preset order; a patch tool\n * replaces a mounted one where it stands, and any other is appended in patch\n * order. That order is the palette's.\n */\nexport function resolveToolRegistry(args: ResolveToolRegistryArgs): Record<string, Tool> {\n const { builtins,
|
|
1
|
+
{"version":3,"file":"toolRegistry.js","names":[],"sources":["../../../src/canvas/SceneCanvas/toolRegistry.ts"],"sourcesContent":["import type { Tool } from 'tools/overlayBinding';\nimport { presetBuiltinTools, presetOwnTools, type EnabledPresets } from './features';\nimport { isDev } from '@weasel-js/react';\nimport { toolIdsOf, type ToolEntry } from '@weasel-js/routing';\nimport { BUILTIN_TOOL_IDS, type BuiltinToolId } from './props';\n\n/** The patch form of `<SceneCanvas tools>`: per id, `true` mounts that\n * built-in, `false` leaves it out, and a tool adds or replaces one. */\nexport type ToolsPatch = Record<string, Tool | true | false>;\n\n/** One tool per built-in id, mounted or not. */\nexport type BuiltinTools = Record<BuiltinToolId, Tool>;\n\nexport interface ResolveToolRegistryArgs {\n builtins: BuiltinTools;\n /** Built-ins asked for, by id or by set. */\n defaultTools?: readonly ToolEntry<BuiltinToolId>[];\n /** The presets the canvas runs with, each bringing the tools it names. */\n enabled: EnabledPresets;\n patch: ToolsPatch | null;\n /** Whether to warn about a patch entry that is probably a mistake. */\n dev?: boolean;\n}\n\n/**\n * The tool registry a canvas mounts when it is not handed a whole `ToolsApi`.\n *\n * Built-ins come first, in `BUILTIN_TOOL_IDS` order whatever order they were\n * asked for in, then the presets' own tools in preset order; a patch tool\n * replaces a mounted one where it stands, and any other is appended in patch\n * order. That order is the palette's. Replacing a tool that is mounted only\n * because a preset implies it is the documented way to restyle it, so only a\n * patch tool for an id `defaultTools` also names is warned about.\n */\nexport function resolveToolRegistry(args: ResolveToolRegistryArgs): Record<string, Tool> {\n const { builtins, enabled, patch, dev = isDev() } = args;\n const defaultTools = toolIdsOf(args.defaultTools ?? []);\n const registry: Record<string, Tool> = {};\n const preset = presetBuiltinTools(enabled);\n for (const id of BUILTIN_TOOL_IDS) {\n const patched = patch?.[id];\n if (patched === false) continue;\n const asked = patched === true || defaultTools.includes(id) || preset.has(id);\n if (asked) registry[id] = builtins[id];\n }\n for (const [id, tool] of Object.entries(presetOwnTools(enabled))) {\n if (patch?.[id] !== false) registry[id] = tool;\n }\n for (const [id, value] of Object.entries(patch ?? {})) {\n if (value === false) continue;\n if (value === true) {\n if (dev && !(BUILTIN_TOOL_IDS as readonly string[]).includes(id)) {\n console.warn(`[SceneCanvas] tools.${id}=true is not a known built-in id; ignoring`);\n }\n continue;\n }\n if (dev && id in registry && (defaultTools as string[]).includes(id)) {\n console.warn(`[SceneCanvas] tools prop overrides bundled \"${id}\" tool`);\n }\n registry[id] = value;\n }\n return registry;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,oBAAoB,MAAqD;CACvF,MAAM,EAAE,UAAU,SAAS,OAAO,MAAM,MAAM,MAAM;CACpD,MAAM,eAAe,UAAU,KAAK,gBAAgB,CAAC,CAAC;CACtD,MAAM,WAAiC,CAAC;CACxC,MAAM,SAAS,mBAAmB,OAAO;CACzC,KAAK,MAAM,MAAM,kBAAkB;EACjC,MAAM,UAAU,QAAQ;EACxB,IAAI,YAAY,OAAO;EAEvB,IADc,YAAY,QAAQ,aAAa,SAAS,EAAE,KAAK,OAAO,IAAI,EAAE,GACjE,SAAS,MAAM,SAAS;CACrC;CACA,KAAK,MAAM,CAAC,IAAI,SAAS,OAAO,QAAQ,eAAe,OAAO,CAAC,GAC7D,IAAI,QAAQ,QAAQ,OAAO,SAAS,MAAM;CAE5C,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,SAAS,CAAC,CAAC,GAAG;EACrD,IAAI,UAAU,OAAO;EACrB,IAAI,UAAU,MAAM;GAClB,IAAI,OAAO,CAAE,iBAAuC,SAAS,EAAE,GAC7D,QAAQ,KAAK,uBAAuB,GAAG,2CAA2C;GAEpF;EACF;EACA,IAAI,OAAO,MAAM,YAAa,aAA0B,SAAS,EAAE,GACjE,QAAQ,KAAK,+CAA+C,GAAG,OAAO;EAExE,SAAS,MAAM;CACjB;CACA,OAAO;AACT"}
|
|
@@ -70,17 +70,7 @@ function useActionsPropResolver(actions, rev) {
|
|
|
70
70
|
rev
|
|
71
71
|
]);
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
74
|
-
* `actions` with `id` muted. A caller's own entry for `id` still wins, and
|
|
75
|
-
* `null` (every default muted) is left as it is.
|
|
76
|
-
*/
|
|
77
|
-
function actionsMuting(actions, id) {
|
|
78
|
-
if (actions === null) return null;
|
|
79
|
-
const merged = { ...actions ?? {} };
|
|
80
|
-
if (!(id in merged)) merged[id] = null;
|
|
81
|
-
return merged;
|
|
82
|
-
}
|
|
83
73
|
|
|
84
74
|
//#endregion
|
|
85
|
-
export {
|
|
75
|
+
export { useActionsPropResolver };
|
|
86
76
|
//# sourceMappingURL=useActionsPropResolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActionsPropResolver.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useActionsPropResolver.ts"],"sourcesContent":["/**\n * Applies the `actions` prop overrides on top of whatever is already\n * registered, so the caller mounts this hook last.\n *\n * actions === null → mute every currently-registered action\n * actions[id] === null → mute that id\n * actions[id] = partial → merge onto the existing descriptor (slot wins\n * over entry.id; warns once on mismatch)\n * actions[id] = full (new) → register alongside defaults\n *\n * `null` mutes rather than unregisters: the opt-out belongs to this canvas, so\n * a sibling sharing the registry keeps the action and this canvas's unmount\n * gives it back.\n */\nimport { useEffect } from 'react';\nimport type { ActionsProp } from '@weasel-js/routing';\nimport { useActionsRegistry } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { Action } from '@weasel-js/routing';\n\n/** `rev` re-applies the overrides when it changes — pass whatever changes when\n * the set they sit on is re-registered. */\nexport function useActionsPropResolver(actions: ActionsProp | undefined, rev?: string): void {\n const reg = useActionsRegistry();\n const actionsRef = useLatest(actions);\n\n useEffect(() => {\n if (!reg) return;\n const prop = actionsRef.current;\n\n const unregisters: Array<() => void> = [];\n\n if (prop === null) {\n for (const id of reg.list().map((a) => a.id)) unregisters.push(reg.mute(id));\n return () => { for (const u of unregisters) u(); };\n }\n\n if (!prop) return;\n\n const warnedIds = new Set<string>();\n\n for (const [slotId, entry] of Object.entries(prop)) {\n if (entry === null) {\n unregisters.push(reg.mute(slotId));\n continue;\n }\n\n const isFull = (e: Partial<Action>): e is Action =>\n typeof e.id === 'string' && typeof e.label === 'string' && !!e.invoker;\n const existing = reg.list().find((a) => a.id === slotId);\n\n if (!existing) {\n if (isFull(entry)) {\n unregisters.push(reg.register(entry));\n } else if (!warnedIds.has(slotId)) {\n warnedIds.add(slotId);\n console.warn(\n `weasel actions resolver: actions[\"${slotId}\"] is a partial Action but no default ` +\n `with this id exists. Pass a complete {id, label, invoker} descriptor.`,\n );\n }\n continue;\n }\n\n if (entry.id !== undefined && entry.id !== slotId && !warnedIds.has(`mismatch:${slotId}`)) {\n warnedIds.add(`mismatch:${slotId}`);\n console.warn(\n `weasel actions resolver: actions[\"${slotId}\"].id=\"${entry.id as string}\" mismatches the slot key. ` +\n `Ignoring the id field; the action remains at id=\"${slotId}\".`,\n );\n }\n const { id: _drop, ...rest } = entry;\n void _drop;\n const merged: Action = { ...existing, ...rest };\n // No explicit restore: `register` stacks, so popping `merged` uncovers\n // the descriptor it displaced. Re-registering `existing` here would push\n // a stale snapshot back on top and never take it off again.\n unregisters.push(reg.register(merged));\n }\n\n return () => { for (const u of unregisters) u(); };\n }, [reg, actions, actionsRef, rev]);\n}\n
|
|
1
|
+
{"version":3,"file":"useActionsPropResolver.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useActionsPropResolver.ts"],"sourcesContent":["/**\n * Applies the `actions` prop overrides on top of whatever is already\n * registered, so the caller mounts this hook last.\n *\n * actions === null → mute every currently-registered action\n * actions[id] === null → mute that id\n * actions[id] = partial → merge onto the existing descriptor (slot wins\n * over entry.id; warns once on mismatch)\n * actions[id] = full (new) → register alongside defaults\n *\n * `null` mutes rather than unregisters: the opt-out belongs to this canvas, so\n * a sibling sharing the registry keeps the action and this canvas's unmount\n * gives it back.\n */\nimport { useEffect } from 'react';\nimport type { ActionsProp } from '@weasel-js/routing';\nimport { useActionsRegistry } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { Action } from '@weasel-js/routing';\n\n/** `rev` re-applies the overrides when it changes — pass whatever changes when\n * the set they sit on is re-registered. */\nexport function useActionsPropResolver(actions: ActionsProp | undefined, rev?: string): void {\n const reg = useActionsRegistry();\n const actionsRef = useLatest(actions);\n\n useEffect(() => {\n if (!reg) return;\n const prop = actionsRef.current;\n\n const unregisters: Array<() => void> = [];\n\n if (prop === null) {\n for (const id of reg.list().map((a) => a.id)) unregisters.push(reg.mute(id));\n return () => { for (const u of unregisters) u(); };\n }\n\n if (!prop) return;\n\n const warnedIds = new Set<string>();\n\n for (const [slotId, entry] of Object.entries(prop)) {\n if (entry === null) {\n unregisters.push(reg.mute(slotId));\n continue;\n }\n\n const isFull = (e: Partial<Action>): e is Action =>\n typeof e.id === 'string' && typeof e.label === 'string' && !!e.invoker;\n const existing = reg.list().find((a) => a.id === slotId);\n\n if (!existing) {\n if (isFull(entry)) {\n unregisters.push(reg.register(entry));\n } else if (!warnedIds.has(slotId)) {\n warnedIds.add(slotId);\n console.warn(\n `weasel actions resolver: actions[\"${slotId}\"] is a partial Action but no default ` +\n `with this id exists. Pass a complete {id, label, invoker} descriptor.`,\n );\n }\n continue;\n }\n\n if (entry.id !== undefined && entry.id !== slotId && !warnedIds.has(`mismatch:${slotId}`)) {\n warnedIds.add(`mismatch:${slotId}`);\n console.warn(\n `weasel actions resolver: actions[\"${slotId}\"].id=\"${entry.id as string}\" mismatches the slot key. ` +\n `Ignoring the id field; the action remains at id=\"${slotId}\".`,\n );\n }\n const { id: _drop, ...rest } = entry;\n void _drop;\n const merged: Action = { ...existing, ...rest };\n // No explicit restore: `register` stacks, so popping `merged` uncovers\n // the descriptor it displaced. Re-registering `existing` here would push\n // a stale snapshot back on top and never take it off again.\n unregisters.push(reg.register(merged));\n }\n\n return () => { for (const u of unregisters) u(); };\n }, [reg, actions, actionsRef, rev]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,uBAAuB,SAAkC,KAAoB;CAC3F,MAAM,MAAM,mBAAmB;CAC/B,MAAM,aAAa,UAAU,OAAO;CAEpC,gBAAgB;EACd,IAAI,CAAC,KAAK;EACV,MAAM,OAAO,WAAW;EAExB,MAAM,cAAiC,CAAC;EAExC,IAAI,SAAS,MAAM;GACjB,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,GAAG,YAAY,KAAK,IAAI,KAAK,EAAE,CAAC;GAC3E,aAAa;IAAE,KAAK,MAAM,KAAK,aAAa,EAAE;GAAG;EACnD;EAEA,IAAI,CAAC,MAAM;EAEX,MAAM,4BAAY,IAAI,IAAY;EAElC,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,IAAI,GAAG;GAClD,IAAI,UAAU,MAAM;IAClB,YAAY,KAAK,IAAI,KAAK,MAAM,CAAC;IACjC;GACF;GAEA,MAAM,UAAU,MACd,OAAO,EAAE,OAAO,YAAY,OAAO,EAAE,UAAU,YAAY,CAAC,CAAC,EAAE;GACjE,MAAM,WAAW,IAAI,KAAK,CAAC,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM;GAEvD,IAAI,CAAC,UAAU;IACb,IAAI,OAAO,KAAK,GACd,YAAY,KAAK,IAAI,SAAS,KAAK,CAAC;SAC/B,IAAI,CAAC,UAAU,IAAI,MAAM,GAAG;KACjC,UAAU,IAAI,MAAM;KACpB,QAAQ,KACN,qCAAqC,OAAO,4GAE9C;IACF;IACA;GACF;GAEA,IAAI,MAAM,OAAO,UAAa,MAAM,OAAO,UAAU,CAAC,UAAU,IAAI,YAAY,QAAQ,GAAG;IACzF,UAAU,IAAI,YAAY,QAAQ;IAClC,QAAQ,KACN,qCAAqC,OAAO,SAAS,MAAM,GAAa,8EACpB,OAAO,GAC7D;GACF;GACA,MAAM,EAAE,IAAI,OAAO,GAAG,SAAS;GAE/B,MAAM,SAAiB;IAAE,GAAG;IAAU,GAAG;GAAK;GAI9C,YAAY,KAAK,IAAI,SAAS,MAAM,CAAC;EACvC;EAEA,aAAa;GAAE,KAAK,MAAM,KAAK,aAAa,EAAE;EAAG;CACnD,GAAG;EAAC;EAAK;EAAS;EAAY;CAAG,CAAC;AACpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBuiltinShapeTools.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useBuiltinShapeTools.tsx"],"sourcesContent":["/**\n * Shape-tool synthesis for `<SceneCanvas>` — calls the kit's per-shape tool\n * hooks; the `insert` dep mints each tool's node. Lets consumers opt into\n * a complete drawing toolset via `<SceneCanvas defaultTools={['rect', 'ellipse']}>`\n * without writing per-tool factory code.\n *\n * All hooks are always called (React rules of hooks) — `resolveToolRegistry`\n * decides which the canvas registers.\n */\nimport { useEllipseTool } from 'tools/builtin/ellipse/useEllipseTool';\nimport { useLassoTool } from 'tools/builtin/lasso/useLassoTool';\nimport { useLineTool } from 'tools/builtin/line/useLineTool';\nimport { usePencilTool } from 'tools/builtin/pencil/usePencilTool';\nimport { usePenTool } from 'tools/builtin/pen/usePenTool';\nimport { usePolygonTool } from 'tools/builtin/polygon/usePolygonTool';\nimport { useRectTool } from 'tools/builtin/rect/useRectTool';\nimport { useStarTool } from 'tools/builtin/star/useStarTool';\nimport { useTextTool } from 'tools/builtin/text/useTextTool';\nimport { useStickyTool } from 'tools/builtin/sticky/useStickyTool';\nimport type { StickyStyle } from 'tools/builtin/sticky/stickyNode';\nimport type { Tool } from 'tools/overlayBinding';\nimport type { InsertToolOptions } from 'tools/builtin/shared/insertToolOptions';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport type { BuiltinShapeToolId } from 'core/shapeKinds';\
|
|
1
|
+
{"version":3,"file":"useBuiltinShapeTools.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useBuiltinShapeTools.tsx"],"sourcesContent":["/**\n * Shape-tool synthesis for `<SceneCanvas>` — calls the kit's per-shape tool\n * hooks; the `insert` dep mints each tool's node. Lets consumers opt into\n * a complete drawing toolset via `<SceneCanvas defaultTools={['rect', 'ellipse']}>`\n * without writing per-tool factory code.\n *\n * All hooks are always called (React rules of hooks) — `resolveToolRegistry`\n * decides which the canvas registers.\n */\nimport { useEllipseTool } from 'tools/builtin/ellipse/useEllipseTool';\nimport { useLassoTool } from 'tools/builtin/lasso/useLassoTool';\nimport { useLineTool } from 'tools/builtin/line/useLineTool';\nimport { usePencilTool } from 'tools/builtin/pencil/usePencilTool';\nimport { usePenTool } from 'tools/builtin/pen/usePenTool';\nimport { usePolygonTool } from 'tools/builtin/polygon/usePolygonTool';\nimport { useRectTool } from 'tools/builtin/rect/useRectTool';\nimport { useStarTool } from 'tools/builtin/star/useStarTool';\nimport { useTextTool } from 'tools/builtin/text/useTextTool';\nimport { useStickyTool } from 'tools/builtin/sticky/useStickyTool';\nimport type { StickyStyle } from 'tools/builtin/sticky/stickyNode';\nimport type { Tool } from 'tools/overlayBinding';\nimport type { InsertToolOptions } from 'tools/builtin/shared/insertToolOptions';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport type { BuiltinShapeToolId } from 'core/shapeKinds';\n\n/** Per-tool option overrides for the built-in tools.\n * Each entry is a narrow subset of the underlying hook's options surface\n * — just the knobs that need consumer control under the bundle pattern. */\nexport interface BuiltinToolOptions {\n lasso?: { mode?: LassoHitMode };\n /** Insert-action options for every drag-to-insert tool (rect / ellipse /\n * line / polygon / star / pencil / text / sticky): `behaviors` become each insert\n * binding's `opts.behaviors`, the way `selectTool.move.behaviors` do for\n * move. */\n insert?: InsertToolOptions;\n /** The look of the notes the sticky tool makes: paper, ink, padding,\n * typography, and the size a click places. */\n sticky?: StickyStyle;\n /** The knife: screen px around the first point within which a click closes the cut. */\n slice?: { closeHitRadius?: number };\n}\n\n// `BuiltinShapeToolId` / `KIT_SHAPE_KINDS` derive from the `core/shapeKinds`\n// table, a dependency-free module, so barrel-reachable code can reach them\n// without entering this file's `@weasel-js/core` self-import cycle.\n// Re-exported here so existing importers of this module keep working.\nexport { KIT_SHAPE_KINDS } from 'core/shapeKinds';\nexport type { BuiltinShapeToolId } from 'core/shapeKinds';\n\nexport interface UseBuiltinShapeToolsArgs {\n /** Per-tool option overrides (lasso mode, etc.). */\n options?: BuiltinToolOptions;\n}\n\nexport type BuiltinShapeTools = Record<BuiltinShapeToolId, Tool>;\n\n/** Synthesize the full shape-tool registry. Hooks always run;\n * `useBuiltinTools` registers the ones asked for. */\nexport function useBuiltinShapeTools(args: UseBuiltinShapeToolsArgs = {}): BuiltinShapeTools {\n const { options } = args;\n\n // Every tool here is a declarative shell: the `insert` dep\n // (`useInsertDepSource`) mints the node, so a consumer wanting its own node\n // shape overrides the dep, not the tool.\n const insert = options?.insert ?? {};\n const rect = useRectTool(insert);\n const ellipse = useEllipseTool(insert);\n const line = useLineTool(insert);\n const polygon = usePolygonTool(insert);\n const star = useStarTool(insert);\n const pencil = usePencilTool(insert);\n const pen = usePenTool();\n const lasso = useLassoTool(options?.lasso ?? {});\n const text = useTextTool(insert);\n const sticky = useStickyTool({ ...insert, ...options?.sticky });\n return { rect, ellipse, line, polygon, star, pen, pencil, lasso, text, sticky };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,qBAAqB,OAAiC,CAAC,GAAsB;CAC3F,MAAM,EAAE,YAAY;CAKpB,MAAM,SAAS,SAAS,UAAU,CAAC;CACnC,MAAM,OAAO,YAAY,MAAM;CAC/B,MAAM,UAAU,eAAe,MAAM;CACrC,MAAM,OAAO,YAAY,MAAM;CAC/B,MAAM,UAAU,eAAe,MAAM;CACrC,MAAM,OAAO,YAAY,MAAM;CAC/B,MAAM,SAAS,cAAc,MAAM;CAKnC,OAAO;EAAE;EAAM;EAAS;EAAM;EAAS;EAAM,KAJjC,WAIiC;EAAK;EAAQ,OAH5C,aAAa,SAAS,SAAS,CAAC,CAGY;EAAO,MAFpD,YAAY,MAEwC;EAAM,QADxD,cAAc;GAAE,GAAG;GAAQ,GAAG,SAAS;EAAO,CACU;CAAO;AAChF"}
|
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import { useHandTool } from "../../tools/builtin/hand/useHandTool.js";
|
|
2
2
|
import { useSliceTool } from "../../tools/builtin/slice/useSliceTool.js";
|
|
3
3
|
import { resolveToolRegistry } from "./toolRegistry.js";
|
|
4
|
-
import { useBuiltinRigTools } from "./useBuiltinRigTools.js";
|
|
5
4
|
import { useBuiltinShapeTools } from "./useBuiltinShapeTools.js";
|
|
6
5
|
|
|
7
6
|
//#region src/canvas/SceneCanvas/useBuiltinTools.ts
|
|
8
7
|
/** The registry of tools `<SceneCanvas>` mounts for itself. Every built-in's
|
|
9
8
|
* hook runs on every render; `resolveToolRegistry` decides which are in. */
|
|
10
9
|
function useBuiltinTools(args) {
|
|
11
|
-
const { select,
|
|
10
|
+
const { select, enabled, defaultTools, patch, toolOptions, inertia } = args;
|
|
12
11
|
const hand = useHandTool({ inertia });
|
|
13
12
|
const shapes = useBuiltinShapeTools({ options: toolOptions });
|
|
14
13
|
const slice = useSliceTool(toolOptions?.slice);
|
|
15
|
-
const rig = useBuiltinRigTools({
|
|
16
|
-
scene,
|
|
17
|
-
selection,
|
|
18
|
-
options: toolOptions
|
|
19
|
-
});
|
|
20
14
|
return resolveToolRegistry({
|
|
21
15
|
builtins: {
|
|
22
16
|
select,
|
|
23
17
|
hand,
|
|
24
18
|
...shapes,
|
|
25
|
-
slice
|
|
26
|
-
...rig
|
|
19
|
+
slice
|
|
27
20
|
},
|
|
28
21
|
defaultTools,
|
|
29
22
|
enabled,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBuiltinTools.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useBuiltinTools.ts"],"sourcesContent":["import type { InertiaConfig } from 'core/viewport/useDecayLoop';\nimport
|
|
1
|
+
{"version":3,"file":"useBuiltinTools.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useBuiltinTools.ts"],"sourcesContent":["import type { InertiaConfig } from 'core/viewport/useDecayLoop';\nimport { useHandTool } from 'tools/builtin/hand';\nimport { useSliceTool } from 'tools/builtin/slice';\nimport type { Tool } from 'tools/overlayBinding';\nimport type { EnabledPresets } from './features';\nimport type { BuiltinToolId } from './props';\nimport type { ToolEntry } from '@weasel-js/routing';\nimport { resolveToolRegistry, type ToolsPatch } from './toolRegistry';\nimport { useBuiltinShapeTools, type BuiltinToolOptions } from './useBuiltinShapeTools';\n\nexport interface UseBuiltinToolsArgs {\n /** The canvas's select tool, which is built from its scene and pickers. */\n select: Tool;\n enabled: EnabledPresets;\n defaultTools?: readonly ToolEntry<BuiltinToolId>[];\n patch: ToolsPatch | null;\n toolOptions?: BuiltinToolOptions;\n /** `viewport.inertia`, which is the hand tool's. */\n inertia?: boolean | InertiaConfig;\n}\n\n/** The registry of tools `<SceneCanvas>` mounts for itself. Every built-in's\n * hook runs on every render; `resolveToolRegistry` decides which are in. */\nexport function useBuiltinTools(args: UseBuiltinToolsArgs): Record<string, Tool> {\n const { select, enabled, defaultTools, patch, toolOptions, inertia } = args;\n const hand = useHandTool({ inertia });\n const shapes = useBuiltinShapeTools({ options: toolOptions });\n const slice = useSliceTool(toolOptions?.slice);\n return resolveToolRegistry({\n builtins: { select, hand, ...shapes, slice },\n defaultTools,\n enabled,\n patch,\n });\n}\n"],"mappings":";;;;;;;;AAuBA,SAAgB,gBAAgB,MAAiD;CAC/E,MAAM,EAAE,QAAQ,SAAS,cAAc,OAAO,aAAa,YAAY;CACvE,MAAM,OAAO,YAAY,EAAE,QAAQ,CAAC;CACpC,MAAM,SAAS,qBAAqB,EAAE,SAAS,YAAY,CAAC;CAC5D,MAAM,QAAQ,aAAa,aAAa,KAAK;CAC7C,OAAO,oBAAoB;EACzB,UAAU;GAAE;GAAQ;GAAM,GAAG;GAAQ;EAAM;EAC3C;EACA;EACA;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { parseDebugFlags } from "../../debug/parseDebugFlags.js";
|
|
2
|
+
import { recordHistory } from "../../devtools/history.js";
|
|
3
|
+
import { useDevtoolsLabel } from "../../devtools/label.js";
|
|
4
|
+
import { describeRegistry } from "../../devtools/registry.js";
|
|
5
|
+
import { useDevtoolsRoot } from "../../devtools/useDevtoolsRoot.js";
|
|
6
|
+
import { inferredNodeRouting } from "./defaultNodeRouting.js";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { createDispatchTrace, createTraceRing } from "@weasel-js/routing";
|
|
9
|
+
import { useActionsRegistry, useDepRegistry } from "@weasel-js/routing/react";
|
|
10
|
+
|
|
11
|
+
//#region src/canvas/SceneCanvas/useCanvasDevtoolsRoot.ts
|
|
12
|
+
function resolved(debug) {
|
|
13
|
+
if (debug === false) return null;
|
|
14
|
+
if (debug !== void 0) return debug;
|
|
15
|
+
return typeof window === "undefined" ? null : parseDebugFlags(window.location.search);
|
|
16
|
+
}
|
|
17
|
+
/** What `get-registry` reports of `deps`, as one comparable string; null for a registry that cannot list itself. */
|
|
18
|
+
function depListingKey(deps) {
|
|
19
|
+
return deps.list?.().map((d) => `${d.name}:${d.depth}:${d.stacked}`).join("\0") ?? null;
|
|
20
|
+
}
|
|
21
|
+
/** This canvas's trace buffers and its devtools root, read from the latest render. */
|
|
22
|
+
function useCanvasDevtoolsRoot(c) {
|
|
23
|
+
const [traces] = useState(() => ({
|
|
24
|
+
dispatch: createDispatchTrace(),
|
|
25
|
+
coords: createTraceRing(),
|
|
26
|
+
history: createTraceRing()
|
|
27
|
+
}));
|
|
28
|
+
const actions = useActionsRegistry();
|
|
29
|
+
const deps = useDepRegistry();
|
|
30
|
+
const framed = useDevtoolsLabel();
|
|
31
|
+
const root = useDevtoolsRoot({
|
|
32
|
+
label: () => {
|
|
33
|
+
const el = c.element.current;
|
|
34
|
+
return el?.getAttribute("aria-label") || el?.id || framed || el?.parentElement?.closest("[aria-label]")?.getAttribute("aria-label") || "";
|
|
35
|
+
},
|
|
36
|
+
scene: () => c.scene,
|
|
37
|
+
selection: () => c.selection.current,
|
|
38
|
+
select: (ids) => c.selection.set([...ids]),
|
|
39
|
+
view: () => c.viewState.getView(),
|
|
40
|
+
activeTool: () => c.tools.active ?? null,
|
|
41
|
+
tools: () => Object.keys(c.tools.registry),
|
|
42
|
+
setTool: (id) => c.tools.setActive(id),
|
|
43
|
+
trace: traces.dispatch,
|
|
44
|
+
coords: traces.coords,
|
|
45
|
+
frame: () => c.api.current?.getDebug()?.snapshot().frame ?? null,
|
|
46
|
+
overlays: () => resolved(c.devtools.debug),
|
|
47
|
+
setOverride: (o) => c.devtools.setOverride(o),
|
|
48
|
+
subscribeView: c.viewState.subscribeView,
|
|
49
|
+
registry: () => describeRegistry({
|
|
50
|
+
tools: c.tools,
|
|
51
|
+
contributions: c.contributions,
|
|
52
|
+
actions,
|
|
53
|
+
deps,
|
|
54
|
+
routingKinds: (c.routing ?? inferredNodeRouting).map((k) => k.name)
|
|
55
|
+
}),
|
|
56
|
+
subscribeRegistry(listener) {
|
|
57
|
+
let listed = depListingKey(deps);
|
|
58
|
+
const onDeps = () => {
|
|
59
|
+
const next = depListingKey(deps);
|
|
60
|
+
if (next !== null && next === listed) return;
|
|
61
|
+
listed = next;
|
|
62
|
+
listener();
|
|
63
|
+
};
|
|
64
|
+
const offs = [actions?.subscribe(listener), deps.subscribe?.(onDeps)];
|
|
65
|
+
return () => {
|
|
66
|
+
for (const off of offs) off?.();
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
history: traces.history
|
|
70
|
+
}, {
|
|
71
|
+
selection: c.selection.current,
|
|
72
|
+
tool: c.tools.active ?? null
|
|
73
|
+
});
|
|
74
|
+
useEffect(() => recordHistory(c.scene.history, traces.history), [c.scene, traces.history]);
|
|
75
|
+
const { registry, ambient } = c.tools;
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
root.notify("registry");
|
|
78
|
+
}, [
|
|
79
|
+
root,
|
|
80
|
+
registry,
|
|
81
|
+
ambient,
|
|
82
|
+
c.contributions,
|
|
83
|
+
c.routing
|
|
84
|
+
]);
|
|
85
|
+
return {
|
|
86
|
+
root,
|
|
87
|
+
traces
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { useCanvasDevtoolsRoot };
|
|
93
|
+
//# sourceMappingURL=useCanvasDevtoolsRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCanvasDevtoolsRoot.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useCanvasDevtoolsRoot.ts"],"sourcesContent":["import { useEffect, useState, type MutableRefObject, type RefObject } from 'react';\nimport {\n createDispatchTrace, createTraceRing, type Contribution, type DepRegistry, type DispatchTrace, type TraceRing,\n} from '@weasel-js/routing';\nimport { useActionsRegistry, useDepRegistry } from '@weasel-js/routing/react';\nimport type { NodeRoutingEntry } from 'core/scene/NodeRouting';\nimport type { NodeId, Scene } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport type { DebugConfig } from '../../debug/types';\nimport { parseDebugFlags } from '../../debug/parseDebugFlags';\nimport { recordHistory } from '../../devtools/history';\nimport type { DevtoolsHistoryRecord } from '../../devtools/protocol';\nimport { useDevtoolsLabel } from '../../devtools/label';\nimport { describeRegistry } from '../../devtools/registry';\nimport type { DevtoolsRoot } from '../../devtools/root';\nimport { useDevtoolsRoot, type DevtoolsOverride } from '../../devtools/useDevtoolsRoot';\nimport type { ToolsApi } from '../../tools/overlayBinding';\nimport type { CanvasExtensionApi } from '../canvasExtension';\nimport type { CanvasViewState } from '../useCanvasView';\nimport type { CoordTraceEntry } from './coordTrace';\nimport { inferredNodeRouting } from './defaultNodeRouting';\n\n/** A canvas's trace buffers: its dispatchers' decisions, its `clientToWorld` conversions, and its scene's history steps. */\nexport interface CanvasTraces {\n dispatch: DispatchTrace;\n coords: TraceRing<CoordTraceEntry>;\n history: TraceRing<DevtoolsHistoryRecord>;\n}\n\n/** What `<SceneCanvas>` hands its input wiring for devtools: the `debug` in effect and the override's setter. */\nexport interface CanvasDevtools {\n debug: DebugConfig | false | undefined;\n setOverride(override: DevtoolsOverride | null): void;\n}\n\nfunction resolved(debug: DebugConfig | false | undefined): DebugConfig | null {\n if (debug === false) return null;\n if (debug !== undefined) return debug;\n return typeof window === 'undefined' ? null : parseDebugFlags(window.location.search);\n}\n\n/** What `get-registry` reports of `deps`, as one comparable string; null for a registry that cannot list itself. */\nfunction depListingKey(deps: DepRegistry): string | null {\n return deps.list?.().map((d) => `${d.name}:${d.depth}:${d.stacked}`).join('\\u0000') ?? null;\n}\n\n/** This canvas's trace buffers and its devtools root, read from the latest render. */\nexport function useCanvasDevtoolsRoot(c: {\n scene: Scene<unknown, string, unknown>;\n selection: SelectionApi;\n viewState: CanvasViewState;\n tools: ToolsApi;\n /** The entries the canvas's `features` presets brought beside its tools. */\n contributions: readonly Contribution<unknown>[];\n routing: readonly NodeRoutingEntry[] | undefined;\n element: MutableRefObject<HTMLElement | null>;\n api: RefObject<CanvasExtensionApi | null>;\n devtools: CanvasDevtools;\n}): { root: DevtoolsRoot; traces: CanvasTraces } {\n const [traces] = useState<CanvasTraces>(() => ({\n dispatch: createDispatchTrace(),\n coords: createTraceRing<CoordTraceEntry>(),\n history: createTraceRing<DevtoolsHistoryRecord>(),\n }));\n const actions = useActionsRegistry();\n const deps = useDepRegistry();\n const framed = useDevtoolsLabel();\n const root = useDevtoolsRoot({\n label: () => {\n const el = c.element.current;\n return el?.getAttribute('aria-label') || el?.id || framed\n || el?.parentElement?.closest('[aria-label]')?.getAttribute('aria-label') || '';\n },\n scene: () => c.scene,\n selection: () => c.selection.current,\n select: (ids) => c.selection.set([...ids] as NodeId[]),\n view: () => c.viewState.getView(),\n activeTool: () => c.tools.active ?? null,\n tools: () => Object.keys(c.tools.registry),\n setTool: (id) => c.tools.setActive(id),\n trace: traces.dispatch,\n coords: traces.coords,\n frame: () => c.api.current?.getDebug()?.snapshot().frame ?? null,\n overlays: () => resolved(c.devtools.debug),\n setOverride: (o) => c.devtools.setOverride(o),\n subscribeView: c.viewState.subscribeView,\n registry: () => describeRegistry({\n tools: c.tools, contributions: c.contributions, actions, deps,\n routingKinds: (c.routing ?? inferredNodeRouting).map((k) => k.name),\n }),\n subscribeRegistry(listener) {\n // The dep registry also notifies when a source's value changes, as every selection does; only the listing is ours.\n let listed = depListingKey(deps);\n const onDeps = (): void => {\n const next = depListingKey(deps);\n if (next !== null && next === listed) return;\n listed = next;\n listener();\n };\n const offs = [actions?.subscribe(listener), deps.subscribe?.(onDeps)];\n return () => { for (const off of offs) off?.(); };\n },\n history: traces.history,\n }, { selection: c.selection.current, tool: c.tools.active ?? null });\n useEffect(() => recordHistory(c.scene.history, traces.history), [c.scene, traces.history]);\n const { registry, ambient } = c.tools;\n useEffect(() => { root.notify('registry'); }, [root, registry, ambient, c.contributions, c.routing]);\n return { root, traces };\n}\n"],"mappings":";;;;;;;;;;;AAmCA,SAAS,SAAS,OAA4D;CAC5E,IAAI,UAAU,OAAO,OAAO;CAC5B,IAAI,UAAU,QAAW,OAAO;CAChC,OAAO,OAAO,WAAW,cAAc,OAAO,gBAAgB,OAAO,SAAS,MAAM;AACtF;;AAGA,SAAS,cAAc,MAAkC;CACvD,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE,SAAS,CAAC,CAAC,KAAK,IAAQ,KAAK;AACzF;;AAGA,SAAgB,sBAAsB,GAWW;CAC/C,MAAM,CAAC,UAAU,gBAA8B;EAC7C,UAAU,oBAAoB;EAC9B,QAAQ,gBAAiC;EACzC,SAAS,gBAAuC;CAClD,EAAE;CACF,MAAM,UAAU,mBAAmB;CACnC,MAAM,OAAO,eAAe;CAC5B,MAAM,SAAS,iBAAiB;CAChC,MAAM,OAAO,gBAAgB;EAC3B,aAAa;GACX,MAAM,KAAK,EAAE,QAAQ;GACrB,OAAO,IAAI,aAAa,YAAY,KAAK,IAAI,MAAM,UAC9C,IAAI,eAAe,QAAQ,cAAc,CAAC,EAAE,aAAa,YAAY,KAAK;EACjF;EACA,aAAa,EAAE;EACf,iBAAiB,EAAE,UAAU;EAC7B,SAAS,QAAQ,EAAE,UAAU,IAAI,CAAC,GAAG,GAAG,CAAa;EACrD,YAAY,EAAE,UAAU,QAAQ;EAChC,kBAAkB,EAAE,MAAM,UAAU;EACpC,aAAa,OAAO,KAAK,EAAE,MAAM,QAAQ;EACzC,UAAU,OAAO,EAAE,MAAM,UAAU,EAAE;EACrC,OAAO,OAAO;EACd,QAAQ,OAAO;EACf,aAAa,EAAE,IAAI,SAAS,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,SAAS;EAC5D,gBAAgB,SAAS,EAAE,SAAS,KAAK;EACzC,cAAc,MAAM,EAAE,SAAS,YAAY,CAAC;EAC5C,eAAe,EAAE,UAAU;EAC3B,gBAAgB,iBAAiB;GAC/B,OAAO,EAAE;GAAO,eAAe,EAAE;GAAe;GAAS;GACzD,eAAe,EAAE,WAAW,oBAAA,CAAqB,KAAK,MAAM,EAAE,IAAI;EACpE,CAAC;EACD,kBAAkB,UAAU;GAE1B,IAAI,SAAS,cAAc,IAAI;GAC/B,MAAM,eAAqB;IACzB,MAAM,OAAO,cAAc,IAAI;IAC/B,IAAI,SAAS,QAAQ,SAAS,QAAQ;IACtC,SAAS;IACT,SAAS;GACX;GACA,MAAM,OAAO,CAAC,SAAS,UAAU,QAAQ,GAAG,KAAK,YAAY,MAAM,CAAC;GACpE,aAAa;IAAE,KAAK,MAAM,OAAO,MAAM,MAAM;GAAG;EAClD;EACA,SAAS,OAAO;CAClB,GAAG;EAAE,WAAW,EAAE,UAAU;EAAS,MAAM,EAAE,MAAM,UAAU;CAAK,CAAC;CACnE,gBAAgB,cAAc,EAAE,MAAM,SAAS,OAAO,OAAO,GAAG,CAAC,EAAE,OAAO,OAAO,OAAO,CAAC;CACzF,MAAM,EAAE,UAAU,YAAY,EAAE;CAChC,gBAAgB;EAAE,KAAK,OAAO,UAAU;CAAG,GAAG;EAAC;EAAM;EAAU;EAAS,EAAE;EAAe,EAAE;CAAO,CAAC;CACnG,OAAO;EAAE;EAAM;CAAO;AACxB"}
|