@weasel-js/core 1.11.0 → 1.12.0
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 +611 -0
- package/README.md +1 -1
- package/dist/WeaselProvider.js +1 -1
- package/dist/affordances/pathAnchors.js +10 -6
- package/dist/affordances/pathAnchors.js.map +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 +9 -3
- package/dist/barrel/interactions.js +5 -4
- package/dist/barrel/paint.js +4 -4
- package/dist/barrel/paths.js +10 -6
- package/dist/barrel/renderer.js +5 -3
- package/dist/barrel/routing.js +7 -12
- package/dist/barrel/scene.js +9 -5
- package/dist/barrel/text.js +2 -2
- package/dist/barrel/viewport.js +9 -4
- package/dist/canvas/Canvas.js +5 -2
- package/dist/canvas/Canvas.js.map +1 -1
- package/dist/canvas/CanvasView.js +23 -34
- package/dist/canvas/CanvasView.js.map +1 -1
- package/dist/canvas/ModalityHud.js +1 -1
- package/dist/canvas/NodeShape.js +4 -1
- package/dist/canvas/NodeShape.js.map +1 -1
- package/dist/canvas/SceneCanvas/ActionsProviderIfRoot.js +1 -1
- package/dist/canvas/SceneCanvas/DepRegistryProviderIfRoot.js +1 -1
- package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +1 -1
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js +17 -3
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js.map +1 -1
- package/dist/canvas/SceneCanvas/SurfaceDeclarations.js +23 -0
- package/dist/canvas/SceneCanvas/SurfaceDeclarations.js.map +1 -0
- package/dist/canvas/SceneCanvas/builtinToolSets.js +30 -0
- package/dist/canvas/SceneCanvas/builtinToolSets.js.map +1 -0
- package/dist/canvas/SceneCanvas/canvasPassThrough.js +2 -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/scenePointQuery.js +7 -3
- package/dist/canvas/SceneCanvas/scenePointQuery.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/useActionTunings.js +6 -1
- package/dist/canvas/SceneCanvas/useActionTunings.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 +94 -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 +15 -10
- 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/useSceneCanvasHandle.js +9 -3
- package/dist/canvas/SceneCanvas/useSceneCanvasHandle.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js +23 -4
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +2 -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 +24 -7
- 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 +5 -5
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +27 -24
- 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/ViewMarker.js +35 -0
- package/dist/canvas/ViewMarker.js.map +1 -0
- 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/defaultDrawOne.js +2 -0
- package/dist/canvas/defaultDrawOne.js.map +1 -1
- package/dist/canvas/deps/booleans.js +2 -1
- package/dist/canvas/deps/booleans.js.map +1 -1
- package/dist/canvas/deps/editAnchors.js +9 -113
- package/dist/canvas/deps/editAnchors.js.map +1 -1
- package/dist/canvas/deps/hitTestArea.js +2 -2
- package/dist/canvas/deps/hitTestArea.js.map +1 -1
- package/dist/canvas/deps/insert.js +10 -4
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/pathEditCommits.js +189 -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 +38 -4
- package/dist/canvas/drawnBounds.js.map +1 -1
- package/dist/canvas/inheritedPaints.js +44 -0
- package/dist/canvas/inheritedPaints.js.map +1 -0
- package/dist/canvas/nodeShapes/derivedPainter.js +23 -16
- package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/nodePaint.js +13 -34
- package/dist/canvas/nodeShapes/nodePaint.js.map +1 -1
- package/dist/canvas/nodeShapes/pathPainter.js +12 -10
- package/dist/canvas/nodeShapes/pathPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/rectFallbackPainter.js +4 -5
- package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/shapePainter.js +12 -11
- package/dist/canvas/nodeShapes/shapePainter.js.map +1 -1
- package/dist/canvas/nodeShapes/textPainter.js +13 -12
- package/dist/canvas/nodeShapes/textPainter.js.map +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/pickReach.js +3 -3
- package/dist/canvas/pickReach.js.map +1 -1
- package/dist/canvas/pickWalk.js +3 -1
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/renderDebugSnapshot.js +1 -0
- package/dist/canvas/renderDebugSnapshot.js.map +1 -1
- package/dist/canvas/renderSceneToPixels.js +7 -6
- package/dist/canvas/renderSceneToPixels.js.map +1 -1
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneSlotWiring.js +2 -1
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +2 -1
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/surfaceContribution.js +12 -8
- package/dist/canvas/surfaceContribution.js.map +1 -1
- package/dist/canvas/useCanvasPaint.js +2 -1
- package/dist/canvas/useCanvasPaint.js.map +1 -1
- package/dist/canvas/useCanvasView.js +4 -2
- package/dist/canvas/useCanvasView.js.map +1 -1
- package/dist/canvas/useInFlightBounds.js +52 -0
- package/dist/canvas/useInFlightBounds.js.map +1 -0
- package/dist/canvas/useLayerStack.js +6 -2
- package/dist/canvas/useLayerStack.js.map +1 -1
- package/dist/canvas/useViewAim.js +121 -0
- package/dist/canvas/useViewAim.js.map +1 -0
- package/dist/canvas/useViewHelpers.js +7 -9
- package/dist/canvas/useViewHelpers.js.map +1 -1
- package/dist/canvas/useViewNesting.js +3 -2
- package/dist/canvas/useViewNesting.js.map +1 -1
- package/dist/canvas/useViewRegistrySurface.js +4 -2
- package/dist/canvas/useViewRegistrySurface.js.map +1 -1
- package/dist/canvas/viewMarkers.js +63 -0
- package/dist/canvas/viewMarkers.js.map +1 -0
- package/dist/canvas/viewRegistry.js +27 -1
- package/dist/canvas/viewRegistry.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 +163 -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/paint/meshKindLazy.js +59 -2
- package/dist/core/paint/meshKindLazy.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/clipNothing.js +13 -0
- package/dist/core/scene/clipNothing.js.map +1 -0
- package/dist/core/scene/depMemo.js +11 -3
- package/dist/core/scene/depMemo.js.map +1 -1
- package/dist/core/scene/dependents.js +7 -1
- package/dist/core/scene/dependents.js.map +1 -1
- package/dist/core/scene/derivedParts.js +10 -11
- package/dist/core/scene/derivedParts.js.map +1 -1
- 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 +13 -2
- 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/fontReads.js +37 -0
- package/dist/core/scene/fontReads.js.map +1 -0
- package/dist/core/scene/historyFacade.js +1 -0
- package/dist/core/scene/historyFacade.js.map +1 -1
- package/dist/core/scene/inheritedPaint.js +75 -0
- package/dist/core/scene/inheritedPaint.js.map +1 -0
- package/dist/core/scene/kitRegistry.js +5 -0
- package/dist/core/scene/kitRegistry.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/nodeMemo.js +15 -7
- package/dist/core/scene/nodeMemo.js.map +1 -1
- package/dist/core/scene/pathEffects/blend.js.map +1 -1
- package/dist/core/scene/pathEffects/derive.js +7 -2
- package/dist/core/scene/pathEffects/derive.js.map +1 -1
- package/dist/core/scene/pathEffects/effects.js +3 -1
- package/dist/core/scene/pathEffects/effects.js.map +1 -1
- package/dist/core/scene/pathEffects/textAlong.js +95 -0
- package/dist/core/scene/pathEffects/textAlong.js.map +1 -0
- 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-p8fDIAKt.d.ts} +3 -2
- 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-mG19aEdD.d.ts} +174 -904
- 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/measure/measureContribution.js +4 -2
- package/dist/features/measure/measureContribution.js.map +1 -1
- package/dist/features/modes/modeTriggers.js +7 -3
- package/dist/features/modes/modeTriggers.js.map +1 -1
- package/dist/features/pathEffects/effectSources.js +60 -0
- package/dist/features/pathEffects/effectSources.js.map +1 -0
- package/dist/features/pathEffects/readSource.js +17 -1
- package/dist/features/pathEffects/readSource.js.map +1 -1
- package/dist/features/pathEffects/textItems.js +53 -0
- package/dist/features/pathEffects/textItems.js.map +1 -0
- package/dist/features/pathEffects/useEffectSourcesLayer.js +57 -0
- package/dist/features/pathEffects/useEffectSourcesLayer.js.map +1 -0
- package/dist/features/paths/index.js +2 -2
- package/dist/features/paths/pathEditExtension.js.map +1 -1
- package/dist/features/paths/pathEditState.js +5 -2
- package/dist/features/paths/pathEditState.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/features/text/sceneTextDrafts.js +65 -0
- package/dist/features/text/sceneTextDrafts.js.map +1 -0
- package/dist/features/text/textHitAt.js +31 -2
- package/dist/features/text/textHitAt.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +22 -18
- package/dist/features/text/useSceneTextEdit.js.map +1 -1
- package/dist/features/viewports/aim.js +105 -0
- package/dist/features/viewports/aim.js.map +1 -0
- package/dist/features/viewports/viewMarker.js +82 -0
- package/dist/features/viewports/viewMarker.js.map +1 -0
- package/dist/features/viewports/viewMarkerDrag.js +55 -0
- package/dist/features/viewports/viewMarkerDrag.js.map +1 -0
- 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 +1198 -894
- package/dist/index.js +55 -38
- 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/booleans/booleans.js +2 -1
- package/dist/interactions/actions/booleans/booleans.js.map +1 -1
- package/dist/interactions/actions/booleans/operands.js +6 -5
- package/dist/interactions/actions/booleans/operands.js.map +1 -1
- package/dist/interactions/actions/clipboard/action.js +27 -17
- package/dist/interactions/actions/clipboard/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/anchorEditing.js +44 -23
- package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
- package/dist/interactions/actions/defaults/anchorJoin.js +12 -6
- package/dist/interactions/actions/defaults/anchorJoin.js.map +1 -1
- package/dist/interactions/actions/defaults/bendSegment.js +8 -5
- package/dist/interactions/actions/defaults/bendSegment.js.map +1 -1
- package/dist/interactions/actions/defaults/cancelGesture.js +11 -8
- package/dist/interactions/actions/defaults/cancelGesture.js.map +1 -1
- package/dist/interactions/actions/defaults/contextMenu.js +17 -8
- package/dist/interactions/actions/defaults/contextMenu.js.map +1 -1
- package/dist/interactions/actions/defaults/createPaintAction.js +2 -2
- package/dist/interactions/actions/defaults/createPaintAction.js.map +1 -1
- package/dist/interactions/actions/defaults/delete.js +64 -41
- package/dist/interactions/actions/defaults/delete.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +12 -9
- package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
- package/dist/interactions/actions/defaults/enterPathEdit.js +19 -9
- package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/escape.js +11 -8
- package/dist/interactions/actions/defaults/escape.js.map +1 -1
- package/dist/interactions/actions/defaults/exitPathEdit.js +7 -4
- package/dist/interactions/actions/defaults/exitPathEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/group.js +21 -15
- package/dist/interactions/actions/defaults/group.js.map +1 -1
- package/dist/interactions/actions/defaults/ingest.js +17 -9
- package/dist/interactions/actions/defaults/ingest.js.map +1 -1
- package/dist/interactions/actions/defaults/insertPathAnchor.js +7 -4
- package/dist/interactions/actions/defaults/insertPathAnchor.js.map +1 -1
- package/dist/interactions/actions/defaults/nudge.js +21 -40
- package/dist/interactions/actions/defaults/nudge.js.map +1 -1
- package/dist/interactions/actions/defaults/pathEditTools.js +11 -8
- package/dist/interactions/actions/defaults/pathEditTools.js.map +1 -1
- package/dist/interactions/actions/defaults/pinchZoom.js +7 -4
- package/dist/interactions/actions/defaults/pinchZoom.js.map +1 -1
- package/dist/interactions/actions/defaults/reorder.js +24 -6
- package/dist/interactions/actions/defaults/reorder.js.map +1 -1
- package/dist/interactions/actions/defaults/selectAll.js +8 -5
- package/dist/interactions/actions/defaults/selectAll.js.map +1 -1
- package/dist/interactions/actions/defaults/setFill.js +7 -3
- package/dist/interactions/actions/defaults/setFill.js.map +1 -1
- package/dist/interactions/actions/defaults/setFillOpacity.js +1 -1
- package/dist/interactions/actions/defaults/setStroke.js +12 -11
- package/dist/interactions/actions/defaults/setStroke.js.map +1 -1
- package/dist/interactions/actions/defaults/setStrokeOpacity.js +1 -1
- package/dist/interactions/actions/defaults/toolActivate.js +7 -1
- package/dist/interactions/actions/defaults/toolActivate.js.map +1 -1
- package/dist/interactions/actions/defaults/toolResetToDefault.js +7 -4
- package/dist/interactions/actions/defaults/toolResetToDefault.js.map +1 -1
- package/dist/interactions/actions/defaults/undoRedo.js +19 -13
- package/dist/interactions/actions/defaults/undoRedo.js.map +1 -1
- package/dist/interactions/actions/defaults/viewportWheelPan.js +16 -7
- package/dist/interactions/actions/defaults/viewportWheelPan.js.map +1 -1
- package/dist/interactions/actions/defaults/viewportZoom.js +24 -6
- package/dist/interactions/actions/defaults/viewportZoom.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 +10 -10
- 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 +14 -6
- 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/repositionAction.js +2 -1
- package/dist/interactions/actions/insert/repositionAction.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 +15 -8
- 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/outlines/createOutlinesAction.js +8 -5
- package/dist/interactions/actions/outlines/createOutlinesAction.js.map +1 -1
- package/dist/interactions/actions/outlines/outlineStroke.js +5 -3
- package/dist/interactions/actions/outlines/outlineStroke.js.map +1 -1
- package/dist/interactions/actions/pathCommands/cutJoin.js +8 -5
- package/dist/interactions/actions/pathCommands/cutJoin.js.map +1 -1
- 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/cornerHandles.js +2 -1
- package/dist/interactions/actions/resize/cornerHandles.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 +25 -9
- 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 +13 -11
- 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/json.d.ts +4 -0
- package/dist/json.js +3 -0
- package/dist/kitSettingsSchema.js +8 -5
- package/dist/kitSettingsSchema.js.map +1 -1
- package/dist/{math-CrJULaZI.d.ts → math-B56zxVs5.d.ts} +10 -1
- package/dist/math.d.ts +1 -1
- package/dist/math.js +2 -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/ellipse/useEllipseTool.js +1 -0
- package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
- package/dist/tools/builtin/eyedropper/useEyedropperTool.js +2 -1
- package/dist/tools/builtin/eyedropper/useEyedropperTool.js.map +1 -1
- package/dist/tools/builtin/hand/dragPanContribution.js +4 -1
- package/dist/tools/builtin/hand/dragPanContribution.js.map +1 -1
- package/dist/tools/builtin/hand/useHandTool.js +7 -4
- package/dist/tools/builtin/hand/useHandTool.js.map +1 -1
- package/dist/tools/builtin/image/useImageTool.js +1 -0
- package/dist/tools/builtin/image/useImageTool.js.map +1 -1
- package/dist/tools/builtin/lasso/useLassoTool.js +1 -0
- package/dist/tools/builtin/lasso/useLassoTool.js.map +1 -1
- package/dist/tools/builtin/line/useLineTool.js +1 -0
- package/dist/tools/builtin/line/useLineTool.js.map +1 -1
- package/dist/tools/builtin/measure/useMeasureTool.js +12 -5
- package/dist/tools/builtin/measure/useMeasureTool.js.map +1 -1
- package/dist/tools/builtin/pen/penHandle.js +3 -5
- package/dist/tools/builtin/pen/penHandle.js.map +1 -1
- package/dist/tools/builtin/pen/usePenTool.js +14 -6
- package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
- package/dist/tools/builtin/pencil/usePencilTool.js +1 -0
- package/dist/tools/builtin/pencil/usePencilTool.js.map +1 -1
- package/dist/tools/builtin/polygon/usePolygonTool.js +13 -4
- package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
- package/dist/tools/builtin/rect/useRectTool.js +1 -0
- package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
- package/dist/tools/builtin/select/adapterPointQuery.js +3 -2
- package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
- package/dist/tools/builtin/select/pressDecision.js +32 -0
- package/dist/tools/builtin/select/pressDecision.js.map +1 -0
- package/dist/tools/builtin/select/selectionContributions.js +22 -13
- package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
- package/dist/tools/builtin/select/useSelectTool.js +13 -10
- package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
- package/dist/tools/builtin/slice/useSliceTool.js +22 -8
- package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
- package/dist/tools/builtin/star/useStarTool.js +13 -4
- package/dist/tools/builtin/star/useStarTool.js.map +1 -1
- package/dist/tools/builtin/sticky/stickyNode.js +4 -1
- package/dist/tools/builtin/sticky/stickyNode.js.map +1 -1
- package/dist/tools/builtin/sticky/useStickyTool.js +10 -5
- package/dist/tools/builtin/sticky/useStickyTool.js.map +1 -1
- package/dist/tools/builtin/text/useTextTool.js +3 -1
- package/dist/tools/builtin/text/useTextTool.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/util/paint.js +1 -3
- package/dist/util/paint.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +39 -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
|
@@ -23,6 +23,7 @@ function sceneMutators(scene) {
|
|
|
23
23
|
},
|
|
24
24
|
setData: (id, data) => scene.update(asNodeId(id), { data }),
|
|
25
25
|
setLayer: (id, layer) => scene.setLayer(asNodeId(id), layer),
|
|
26
|
+
setDependsOn: (id, dependsOn) => scene.setDependsOn(asNodeId(id), Array.isArray(dependsOn) ? dependsOn.map(asNodeId) : dependsOn),
|
|
26
27
|
setLayout: (id, layout) => scene.setLayout(asNodeId(id), layout),
|
|
27
28
|
setHidden: (id, hidden) => scene.setHidden(asNodeId(id), hidden),
|
|
28
29
|
setLocked: (id, locked) => scene.setLocked(asNodeId(id), locked),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneMutators.js","names":[],"sources":["../../../src/core/scene/sceneMutators.ts"],"sourcesContent":["/**\n * What every scene-backed adapter shares: the writes an op applies through,\n * and the structural reads those ops need. `sceneToAdapter`,\n * `defaultCommitAdapter`, and `moveGestureAdapter` all build on it.\n *\n * It leaves out the pose and node-list reads, where the adapters differ on\n * purpose. The canvas adapter answers with what is shown: the effective pose,\n * visible layers only. An adapter ops commit through answers with what the\n * document holds, which is {@link documentReads}.\n */\nimport type { LayoutStrategy } from '../../layout/types';\nimport { documentPose } from './effectivePose';\nimport { fnFieldsOfNode } from './nodeFnFields';\nimport { statedFields } from './statedFields';\nimport { asNodeId, type Node, type Scene } from './types';\n\nexport interface SceneMutators<TData, TLayer extends string, TPose> {\n getNode(id: string): Node<TData, TLayer, TPose> | undefined;\n getParent(id: string): string | null;\n /** Ordered children of `parentId`; `null` names the root siblings. */\n getChildren(parentId: string | null): string[];\n /** Every id removing `ids` takes: their subtrees and their dependents. */\n getRemovalClosure(ids: readonly string[]): string[];\n setPose(id: string, pose: TPose): void;\n setParent(id: string, parentId: string | null): void;\n /** One undo step when called bare; inside a batch it joins that batch. */\n setChildOrder(parentId: string | null, ids: string[]): void;\n setData(id: string, data: TData): void;\n setLayer(id: string, layer: TLayer): void;\n setLayout(id: string, layout: LayoutStrategy<TPose> | string | null): void;\n /** What a `setHidden` op writes through. */\n setHidden(id: string, hidden: boolean): void;\n /** What a `setLocked` op writes through. */\n setLocked(id: string, locked: boolean): void;\n removeNode(id: string): void;\n /** Re-add `node` as it was, at sibling `index` when one is given. */\n insertNode(node: Node<TData, TLayer, TPose>, index?: number): void;\n}\n\nexport function sceneMutators<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n): SceneMutators<TData, TLayer, TPose> {\n const getChildren = (parentId: string | null): string[] =>\n (parentId === null ? [...scene.roots] : [...scene.childrenOf(asNodeId(parentId))]);\n return {\n getNode: (id) => scene.get(asNodeId(id)),\n getParent: (id) => scene.get(asNodeId(id))?.parent ?? null,\n getChildren,\n getRemovalClosure: (ids) => [...scene.removalClosure(ids.map(asNodeId))],\n setPose: (id, pose) => scene.setPose(asNodeId(id), pose),\n setParent: (id, parentId) => scene.move(asNodeId(id), parentId == null ? null : asNodeId(parentId)),\n setChildOrder: (parentId, ids) => {\n scene.batch('Reorder', () => {\n for (let i = 0; i < ids.length; i++) {\n // Re-read each time: a reorder shifts later ids, sometimes into place.\n if (getChildren(parentId)[i] === ids[i]) continue;\n scene.reorder(asNodeId(ids[i]), i);\n }\n });\n },\n setData: (id, data) => scene.update(asNodeId(id), { data }),\n setLayer: (id, layer) => scene.setLayer(asNodeId(id), layer),\n setLayout: (id, layout) => scene.setLayout(asNodeId(id), layout),\n setHidden: (id, hidden) => scene.setHidden(asNodeId(id), hidden),\n setLocked: (id, locked) => scene.setLocked(asNodeId(id), locked),\n removeNode: (id) => scene.remove(asNodeId(id)),\n insertNode: (node, index) => {\n scene.add({\n kind: node.kind,\n layer: node.layer,\n pose: node.pose,\n data: node.data,\n id: node.id,\n ...(index !== undefined ? { index } : {}),\n ...(node.parent != null ? { parent: node.parent } : {}),\n // Derivation travels with the node, or undo of a delete brings an\n // edge back as a static path that never follows its endpoints again.\n ...(node.dependsOn !== undefined ? { dependsOn: node.dependsOn } : {}),\n ...statedFields(node),\n ...fnFieldsOfNode(node),\n });\n },\n };\n}\n\n/** The pose and node-list reads of an adapter ops commit through: the document,\n * whatever a gesture is showing and whichever layers are hidden. */\nexport function documentReads<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n): { getPose(id: string): TPose; getNodes(): Node<TData, TLayer, TPose>[] } {\n return {\n getPose: (id) => documentPose(scene, scene.get(asNodeId(id))!),\n getNodes: () => [...scene.renderOrderNodes()],\n };\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"sceneMutators.js","names":[],"sources":["../../../src/core/scene/sceneMutators.ts"],"sourcesContent":["/**\n * What every scene-backed adapter shares: the writes an op applies through,\n * and the structural reads those ops need. `sceneToAdapter`,\n * `defaultCommitAdapter`, and `moveGestureAdapter` all build on it.\n *\n * It leaves out the pose and node-list reads, where the adapters differ on\n * purpose. The canvas adapter answers with what is shown: the effective pose,\n * visible layers only. An adapter ops commit through answers with what the\n * document holds, which is {@link documentReads}.\n */\nimport type { LayoutStrategy } from '../../layout/types';\nimport { documentPose } from './effectivePose';\nimport { fnFieldsOfNode } from './nodeFnFields';\nimport { statedFields } from './statedFields';\nimport { asNodeId, type Node, type Scene } from './types';\n\nexport interface SceneMutators<TData, TLayer extends string, TPose> {\n getNode(id: string): Node<TData, TLayer, TPose> | undefined;\n getParent(id: string): string | null;\n /** Ordered children of `parentId`; `null` names the root siblings. */\n getChildren(parentId: string | null): string[];\n /** Every id removing `ids` takes: their subtrees and their dependents. */\n getRemovalClosure(ids: readonly string[]): string[];\n setPose(id: string, pose: TPose): void;\n setParent(id: string, parentId: string | null): void;\n /** One undo step when called bare; inside a batch it joins that batch. */\n setChildOrder(parentId: string | null, ids: string[]): void;\n setData(id: string, data: TData): void;\n setLayer(id: string, layer: TLayer): void;\n /** What a `setDependsOn` op writes through. */\n setDependsOn(id: string, dependsOn: readonly string[] | 'children' | undefined): void;\n setLayout(id: string, layout: LayoutStrategy<TPose> | string | null): void;\n /** What a `setHidden` op writes through. */\n setHidden(id: string, hidden: boolean): void;\n /** What a `setLocked` op writes through. */\n setLocked(id: string, locked: boolean): void;\n removeNode(id: string): void;\n /** Re-add `node` as it was, at sibling `index` when one is given. */\n insertNode(node: Node<TData, TLayer, TPose>, index?: number): void;\n}\n\nexport function sceneMutators<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n): SceneMutators<TData, TLayer, TPose> {\n const getChildren = (parentId: string | null): string[] =>\n (parentId === null ? [...scene.roots] : [...scene.childrenOf(asNodeId(parentId))]);\n return {\n getNode: (id) => scene.get(asNodeId(id)),\n getParent: (id) => scene.get(asNodeId(id))?.parent ?? null,\n getChildren,\n getRemovalClosure: (ids) => [...scene.removalClosure(ids.map(asNodeId))],\n setPose: (id, pose) => scene.setPose(asNodeId(id), pose),\n setParent: (id, parentId) => scene.move(asNodeId(id), parentId == null ? null : asNodeId(parentId)),\n setChildOrder: (parentId, ids) => {\n scene.batch('Reorder', () => {\n for (let i = 0; i < ids.length; i++) {\n // Re-read each time: a reorder shifts later ids, sometimes into place.\n if (getChildren(parentId)[i] === ids[i]) continue;\n scene.reorder(asNodeId(ids[i]), i);\n }\n });\n },\n setData: (id, data) => scene.update(asNodeId(id), { data }),\n setLayer: (id, layer) => scene.setLayer(asNodeId(id), layer),\n setDependsOn: (id, dependsOn) =>\n scene.setDependsOn(asNodeId(id), Array.isArray(dependsOn) ? dependsOn.map(asNodeId) : dependsOn as 'children' | undefined),\n setLayout: (id, layout) => scene.setLayout(asNodeId(id), layout),\n setHidden: (id, hidden) => scene.setHidden(asNodeId(id), hidden),\n setLocked: (id, locked) => scene.setLocked(asNodeId(id), locked),\n removeNode: (id) => scene.remove(asNodeId(id)),\n insertNode: (node, index) => {\n scene.add({\n kind: node.kind,\n layer: node.layer,\n pose: node.pose,\n data: node.data,\n id: node.id,\n ...(index !== undefined ? { index } : {}),\n ...(node.parent != null ? { parent: node.parent } : {}),\n // Derivation travels with the node, or undo of a delete brings an\n // edge back as a static path that never follows its endpoints again.\n ...(node.dependsOn !== undefined ? { dependsOn: node.dependsOn } : {}),\n ...statedFields(node),\n ...fnFieldsOfNode(node),\n });\n },\n };\n}\n\n/** The pose and node-list reads of an adapter ops commit through: the document,\n * whatever a gesture is showing and whichever layers are hidden. */\nexport function documentReads<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n): { getPose(id: string): TPose; getNodes(): Node<TData, TLayer, TPose>[] } {\n return {\n getPose: (id) => documentPose(scene, scene.get(asNodeId(id))!),\n getNodes: () => [...scene.renderOrderNodes()],\n };\n}\n"],"mappings":";;;;;;AAyCA,SAAgB,cACd,OACqC;CACrC,MAAM,eAAe,aAClB,aAAa,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,WAAW,SAAS,QAAQ,CAAC,CAAC;CAClF,OAAO;EACL,UAAU,OAAO,MAAM,IAAI,SAAS,EAAE,CAAC;EACvC,YAAY,OAAO,MAAM,IAAI,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU;EACtD;EACA,oBAAoB,QAAQ,CAAC,GAAG,MAAM,eAAe,IAAI,IAAI,QAAQ,CAAC,CAAC;EACvE,UAAU,IAAI,SAAS,MAAM,QAAQ,SAAS,EAAE,GAAG,IAAI;EACvD,YAAY,IAAI,aAAa,MAAM,KAAK,SAAS,EAAE,GAAG,YAAY,OAAO,OAAO,SAAS,QAAQ,CAAC;EAClG,gBAAgB,UAAU,QAAQ;GAChC,MAAM,MAAM,iBAAiB;IAC3B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;KAEnC,IAAI,YAAY,QAAQ,CAAC,CAAC,OAAO,IAAI,IAAI;KACzC,MAAM,QAAQ,SAAS,IAAI,EAAE,GAAG,CAAC;IACnC;GACF,CAAC;EACH;EACA,UAAU,IAAI,SAAS,MAAM,OAAO,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC;EAC1D,WAAW,IAAI,UAAU,MAAM,SAAS,SAAS,EAAE,GAAG,KAAK;EAC3D,eAAe,IAAI,cACjB,MAAM,aAAa,SAAS,EAAE,GAAG,MAAM,QAAQ,SAAS,IAAI,UAAU,IAAI,QAAQ,IAAI,SAAmC;EAC3H,YAAY,IAAI,WAAW,MAAM,UAAU,SAAS,EAAE,GAAG,MAAM;EAC/D,YAAY,IAAI,WAAW,MAAM,UAAU,SAAS,EAAE,GAAG,MAAM;EAC/D,YAAY,IAAI,WAAW,MAAM,UAAU,SAAS,EAAE,GAAG,MAAM;EAC/D,aAAa,OAAO,MAAM,OAAO,SAAS,EAAE,CAAC;EAC7C,aAAa,MAAM,UAAU;GAC3B,MAAM,IAAI;IACR,MAAM,KAAK;IACX,OAAO,KAAK;IACZ,MAAM,KAAK;IACX,MAAM,KAAK;IACX,IAAI,KAAK;IACT,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;IACvC,GAAI,KAAK,UAAU,OAAO,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;IAGrD,GAAI,KAAK,cAAc,SAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;IACpE,GAAG,aAAa,IAAI;IACpB,GAAG,eAAe,IAAI;GACxB,CAAC;EACH;CACF;AACF;;;AAIA,SAAgB,cACd,OAC0E;CAC1E,OAAO;EACL,UAAU,OAAO,aAAa,OAAO,MAAM,IAAI,SAAS,EAAE,CAAC,CAAE;EAC7D,gBAAgB,CAAC,GAAG,MAAM,iBAAiB,CAAC;CAC9C;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHistory } from "../ops/createHistory.js";
|
|
2
2
|
import { createAppliedLog } from "./appliedLog.js";
|
|
3
|
+
import { createEditPasses } from "./editPass.js";
|
|
3
4
|
import { createSceneHistory } from "./historyFacade.js";
|
|
4
5
|
import { createOpTable } from "./opTable.js";
|
|
5
6
|
import { createOuterOps } from "./outerOps.js";
|
|
@@ -9,6 +10,20 @@ import { createRecorder } from "./recorder.js";
|
|
|
9
10
|
function createSceneRecording(env) {
|
|
10
11
|
const { notifier, mode, stale, lifted, selection, arrivals, config, poseWrites } = env;
|
|
11
12
|
const { notify } = notifier;
|
|
13
|
+
const passes = createEditPasses({
|
|
14
|
+
adapter: env.passAdapter,
|
|
15
|
+
untracked: mode.untracked
|
|
16
|
+
});
|
|
17
|
+
/** Run an op-driven edit with its arrivals settled and its passes run at
|
|
18
|
+
* its end, in the same entry, when this call owns them. */
|
|
19
|
+
const runEdit = (ops, run) => arrivals.runEdit(ops, (all) => {
|
|
20
|
+
if (!passes.open()) return run(all);
|
|
21
|
+
try {
|
|
22
|
+
run([...all, passes.op()]);
|
|
23
|
+
} finally {
|
|
24
|
+
passes.abandon();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
12
27
|
const ops = createOpTable({
|
|
13
28
|
driven: mode.open,
|
|
14
29
|
replayAlone: (step) => {
|
|
@@ -51,6 +66,7 @@ function createSceneRecording(env) {
|
|
|
51
66
|
makeOp: ops.op,
|
|
52
67
|
log,
|
|
53
68
|
arrivals,
|
|
69
|
+
passes,
|
|
54
70
|
selection: selection.get,
|
|
55
71
|
writePose: env.writePose,
|
|
56
72
|
labeled: poseWrites.labeled
|
|
@@ -72,7 +88,7 @@ function createSceneRecording(env) {
|
|
|
72
88
|
replay,
|
|
73
89
|
notify,
|
|
74
90
|
refuseUntracked,
|
|
75
|
-
runArrivalEdit:
|
|
91
|
+
runArrivalEdit: runEdit,
|
|
76
92
|
labeled: (label, fn) => poseWrites.labeled(label, "ops", fn),
|
|
77
93
|
activeJournal: outer.activeJournal
|
|
78
94
|
});
|
|
@@ -90,14 +106,15 @@ function createSceneRecording(env) {
|
|
|
90
106
|
},
|
|
91
107
|
applyBatch(batch, label, adapter) {
|
|
92
108
|
refuseUntracked("applyBatch");
|
|
93
|
-
return poseWrites.labeled(label, "ops", () =>
|
|
109
|
+
return poseWrites.labeled(label, "ops", () => runEdit(batch, (all) => outer.apply(engine, all, label, adapter)));
|
|
94
110
|
},
|
|
95
111
|
history,
|
|
96
112
|
...methods,
|
|
97
113
|
batch: recorder.batch,
|
|
98
114
|
untracked: recorder.untracked,
|
|
99
115
|
setActiveJournalAccessor: outer.setActiveJournalAccessor,
|
|
100
|
-
setHistoryAdapter: outer.setHistoryAdapter
|
|
116
|
+
setHistoryAdapter: outer.setHistoryAdapter,
|
|
117
|
+
addEditPass: passes.add
|
|
101
118
|
}
|
|
102
119
|
};
|
|
103
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneRecording.js","names":[],"sources":["../../../src/core/scene/sceneRecording.ts"],"sourcesContent":["/**\n * How a scene's edits reach its undo stack: the op table, the log that takes\n * back an edit refused partway, the engine, and the recorder between them.\n */\nimport type { Journal } from '@weasel-js/history';\nimport { createHistory } from 'core/ops/createHistory';\nimport { createAppliedLog } from './appliedLog';\nimport type { ArrivalWindow } from './arrivalWindow';\nimport type { EditMode } from './editMode';\nimport { createSceneHistory, type SceneHistoryMethods } from './historyFacade';\nimport type { Notifier } from './notifier';\nimport type { PoseWriteLog } from './poseWrites';\nimport { createOpTable, type OpTable } from './opTable';\nimport { createOuterOps } from './outerOps';\nimport { createRecorder, type Recorder, type RecorderEnv } from './recorder';\nimport type { SceneSelection } from './sceneSelection';\nimport type { StaleReplay } from './staleReplay';\nimport type { NodeId, RegisteredOp, Scene } from './types';\n\nexport interface SceneRecordingEnv {\n notifier: Notifier;\n mode: EditMode;\n stale: StaleReplay;\n /** Run with the lock guard lifted. */\n lifted<T>(fn: () => T): T;\n selection: Pick<SceneSelection, 'get' | 'set' | 'replace'>;\n arrivals: RecorderEnv['arrivals'] & Pick<ArrivalWindow<unknown>, 'runEdit'>;\n writePose(id: string, pose: unknown): void;\n poseWrites: Pick<PoseWriteLog<unknown>, 'labeled' | 'replaying'>;\n config: {\n getActiveJournal?: (() => Journal | null) | undefined;\n coalesceWindowMs?: number | undefined;\n historyLimit?: number | undefined;\n };\n}\n\nexport interface SceneRecording {\n ops: Pick<OpTable, 'register' | 'run'>;\n recorder: Recorder;\n clearHistory(): void;\n methods: SceneHistoryMethods & Pick<\n Scene<unknown, string, unknown>,\n | 'registerOp' | 'recordOp' | 'applyBatch' | 'history' | 'batch' | 'untracked'\n | 'setActiveJournalAccessor' | 'setHistoryAdapter'\n >;\n}\n\nexport function createSceneRecording(env: SceneRecordingEnv): SceneRecording {\n const { notifier, mode, stale, lifted, selection, arrivals, config, poseWrites } = env;\n const { notify } = notifier;\n\n const ops = createOpTable({\n driven: mode.open,\n replayAlone: (step) => { replay(step); notify(); },\n skips: stale.skips,\n // Only a replay is logged: a first apply is recorded by the entry it\n // creates, and reverting it would leave that entry describing nothing.\n applied: (kind, payload, reverted) => { if (!mode.records()) logApplied(kind, payload, reverted); },\n });\n\n const outer = createOuterOps({\n own: (name, args) => (ops.handlers.has(name) ? ops.op(name, args) : null),\n recorder: () => recorder,\n // Deferred rather than muted, so a throwing op cannot strand subscribers\n // after earlier ops in the batch already mutated state.\n driving: (step) => notifier.deferred(() => mode.during('engine', () => atomically(step, () => true))),\n getActiveJournal: config.getActiveJournal ?? null,\n });\n\n // The scene's undo/redo engine. Its recorded ops close over their payloads,\n // so the engine's adapter argument is unused.\n const engine = createHistory(undefined, {\n selection: { get: selection.get, set: (ids) => selection.set(ids as readonly NodeId[]) },\n ...(config.coalesceWindowMs !== undefined ? { coalesceWindowMs: config.coalesceWindowMs } : {}),\n ...(config.historyLimit !== undefined ? { historyLimit: config.historyLimit } : {}),\n rebuildOp: outer.rebuild,\n });\n\n const log = createAppliedLog({\n registered: ops.handlers,\n lifted,\n getSelection: selection.get,\n setSelection: selection.replace,\n notify,\n });\n const { atomically, logApplied } = log;\n\n const recorder = createRecorder({\n notifier,\n mode,\n engine,\n runOp: ops.run,\n makeOp: ops.op,\n log,\n arrivals,\n selection: selection.get,\n writePose: env.writePose,\n labeled: poseWrites.labeled,\n });\n const { record, engineDriven } = recorder;\n\n /** Run an engine step that replays recorded ops — undo, redo, goto, a\n * journal stepping. The engine inverts whole ops when one throws; this\n * also reverts the scene writes of the op that threw partway. */\n function replay(step: () => void): void {\n poseWrites.replaying(() => atomically(() => lifted(() => stale.during(() => engineDriven(step))), () => true));\n }\n\n function refuseUntracked(verb: string): void {\n if (mode.untracked()) throw new Error(`Scene: cannot ${verb} inside untracked() — it records`);\n }\n\n const { history, methods } = createSceneHistory({\n engine,\n applying: (step) => atomically(() => engineDriven(step), () => true),\n causing: outer.causing,\n replay,\n notify,\n refuseUntracked,\n runArrivalEdit:
|
|
1
|
+
{"version":3,"file":"sceneRecording.js","names":[],"sources":["../../../src/core/scene/sceneRecording.ts"],"sourcesContent":["/**\n * How a scene's edits reach its undo stack: the op table, the log that takes\n * back an edit refused partway, the engine, and the recorder between them.\n */\nimport type { Journal } from '@weasel-js/history';\nimport type { Op } from 'core/ops/types';\nimport { createHistory } from 'core/ops/createHistory';\nimport { createAppliedLog } from './appliedLog';\nimport type { ArrivalWindow } from './arrivalWindow';\nimport type { EditMode } from './editMode';\nimport { createEditPasses } from './editPass';\nimport { createSceneHistory, type SceneHistoryMethods } from './historyFacade';\nimport type { Notifier } from './notifier';\nimport type { PoseWriteLog } from './poseWrites';\nimport { createOpTable, type OpTable } from './opTable';\nimport { createOuterOps } from './outerOps';\nimport { createRecorder, type Recorder, type RecorderEnv } from './recorder';\nimport type { SceneSelection } from './sceneSelection';\nimport type { StaleReplay } from './staleReplay';\nimport type { NodeId, RegisteredOp, Scene } from './types';\n\nexport interface SceneRecordingEnv {\n notifier: Notifier;\n mode: EditMode;\n stale: StaleReplay;\n /** Run with the lock guard lifted. */\n lifted<T>(fn: () => T): T;\n selection: Pick<SceneSelection, 'get' | 'set' | 'replace'>;\n arrivals: RecorderEnv['arrivals'] & Pick<ArrivalWindow<unknown>, 'runEdit'>;\n /** The adapter an edit pass's ops apply through. */\n passAdapter(): unknown;\n writePose(id: string, pose: unknown): void;\n poseWrites: Pick<PoseWriteLog<unknown>, 'labeled' | 'replaying'>;\n config: {\n getActiveJournal?: (() => Journal | null) | undefined;\n coalesceWindowMs?: number | undefined;\n historyLimit?: number | undefined;\n };\n}\n\nexport interface SceneRecording {\n ops: Pick<OpTable, 'register' | 'run'>;\n recorder: Recorder;\n clearHistory(): void;\n methods: SceneHistoryMethods & Pick<\n Scene<unknown, string, unknown>,\n | 'registerOp' | 'recordOp' | 'applyBatch' | 'history' | 'batch' | 'untracked'\n | 'setActiveJournalAccessor' | 'setHistoryAdapter' | 'addEditPass'\n >;\n}\n\nexport function createSceneRecording(env: SceneRecordingEnv): SceneRecording {\n const { notifier, mode, stale, lifted, selection, arrivals, config, poseWrites } = env;\n const { notify } = notifier;\n const passes = createEditPasses({ adapter: env.passAdapter, untracked: mode.untracked });\n\n /** Run an op-driven edit with its arrivals settled and its passes run at\n * its end, in the same entry, when this call owns them. */\n const runEdit = (ops: Op[], run: (ops: Op[]) => void): boolean => arrivals.runEdit(ops, (all) => {\n if (!passes.open()) return run(all);\n try {\n run([...all, passes.op()]);\n } finally {\n passes.abandon();\n }\n });\n\n const ops = createOpTable({\n driven: mode.open,\n replayAlone: (step) => { replay(step); notify(); },\n skips: stale.skips,\n // Only a replay is logged: a first apply is recorded by the entry it\n // creates, and reverting it would leave that entry describing nothing.\n applied: (kind, payload, reverted) => { if (!mode.records()) logApplied(kind, payload, reverted); },\n });\n\n const outer = createOuterOps({\n own: (name, args) => (ops.handlers.has(name) ? ops.op(name, args) : null),\n recorder: () => recorder,\n // Deferred rather than muted, so a throwing op cannot strand subscribers\n // after earlier ops in the batch already mutated state.\n driving: (step) => notifier.deferred(() => mode.during('engine', () => atomically(step, () => true))),\n getActiveJournal: config.getActiveJournal ?? null,\n });\n\n // The scene's undo/redo engine. Its recorded ops close over their payloads,\n // so the engine's adapter argument is unused.\n const engine = createHistory(undefined, {\n selection: { get: selection.get, set: (ids) => selection.set(ids as readonly NodeId[]) },\n ...(config.coalesceWindowMs !== undefined ? { coalesceWindowMs: config.coalesceWindowMs } : {}),\n ...(config.historyLimit !== undefined ? { historyLimit: config.historyLimit } : {}),\n rebuildOp: outer.rebuild,\n });\n\n const log = createAppliedLog({\n registered: ops.handlers,\n lifted,\n getSelection: selection.get,\n setSelection: selection.replace,\n notify,\n });\n const { atomically, logApplied } = log;\n\n const recorder = createRecorder({\n notifier,\n mode,\n engine,\n runOp: ops.run,\n makeOp: ops.op,\n log,\n arrivals,\n passes,\n selection: selection.get,\n writePose: env.writePose,\n labeled: poseWrites.labeled,\n });\n const { record, engineDriven } = recorder;\n\n /** Run an engine step that replays recorded ops — undo, redo, goto, a\n * journal stepping. The engine inverts whole ops when one throws; this\n * also reverts the scene writes of the op that threw partway. */\n function replay(step: () => void): void {\n poseWrites.replaying(() => atomically(() => lifted(() => stale.during(() => engineDriven(step))), () => true));\n }\n\n function refuseUntracked(verb: string): void {\n if (mode.untracked()) throw new Error(`Scene: cannot ${verb} inside untracked() — it records`);\n }\n\n const { history, methods } = createSceneHistory({\n engine,\n applying: (step) => atomically(() => engineDriven(step), () => true),\n causing: outer.causing,\n replay,\n notify,\n refuseUntracked,\n runArrivalEdit: runEdit,\n labeled: (label, fn) => poseWrites.labeled(label, 'ops', fn),\n activeJournal: outer.activeJournal,\n });\n\n return {\n ops,\n recorder,\n clearHistory: () => engine.clear(),\n methods: {\n registerOp(kind, handler) {\n if (kind.startsWith('kit:')) {\n throw new Error(`Scene: op kind \"${kind}\" is reserved (kit:* prefix)`);\n }\n ops.register(kind, handler as RegisteredOp<unknown>);\n },\n recordOp(op) {\n record(op.kind, op.payload, op.kind);\n },\n applyBatch(batch, label, adapter) {\n refuseUntracked('applyBatch');\n return poseWrites.labeled(label, 'ops', () =>\n runEdit(batch, (all) => outer.apply(engine, all, label, adapter)));\n },\n history,\n ...methods,\n batch: recorder.batch,\n untracked: recorder.untracked,\n setActiveJournalAccessor: outer.setActiveJournalAccessor,\n setHistoryAdapter: outer.setHistoryAdapter,\n addEditPass: passes.add,\n },\n };\n}\n"],"mappings":";;;;;;;;;AAmDA,SAAgB,qBAAqB,KAAwC;CAC3E,MAAM,EAAE,UAAU,MAAM,OAAO,QAAQ,WAAW,UAAU,QAAQ,eAAe;CACnF,MAAM,EAAE,WAAW;CACnB,MAAM,SAAS,iBAAiB;EAAE,SAAS,IAAI;EAAa,WAAW,KAAK;CAAU,CAAC;;;CAIvF,MAAM,WAAW,KAAW,QAAsC,SAAS,QAAQ,MAAM,QAAQ;EAC/F,IAAI,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,GAAG;EAClC,IAAI;GACF,IAAI,CAAC,GAAG,KAAK,OAAO,GAAG,CAAC,CAAC;EAC3B,UAAU;GACR,OAAO,QAAQ;EACjB;CACF,CAAC;CAED,MAAM,MAAM,cAAc;EACxB,QAAQ,KAAK;EACb,cAAc,SAAS;GAAE,OAAO,IAAI;GAAG,OAAO;EAAG;EACjD,OAAO,MAAM;EAGb,UAAU,MAAM,SAAS,aAAa;GAAE,IAAI,CAAC,KAAK,QAAQ,GAAG,WAAW,MAAM,SAAS,QAAQ;EAAG;CACpG,CAAC;CAED,MAAM,QAAQ,eAAe;EAC3B,MAAM,MAAM,SAAU,IAAI,SAAS,IAAI,IAAI,IAAI,IAAI,GAAG,MAAM,IAAI,IAAI;EACpE,gBAAgB;EAGhB,UAAU,SAAS,SAAS,eAAe,KAAK,OAAO,gBAAgB,WAAW,YAAY,IAAI,CAAC,CAAC;EACpG,kBAAkB,OAAO,oBAAoB;CAC/C,CAAC;CAID,MAAM,SAAS,cAAc,QAAW;EACtC,WAAW;GAAE,KAAK,UAAU;GAAK,MAAM,QAAQ,UAAU,IAAI,GAAwB;EAAE;EACvF,GAAI,OAAO,qBAAqB,SAAY,EAAE,kBAAkB,OAAO,iBAAiB,IAAI,CAAC;EAC7F,GAAI,OAAO,iBAAiB,SAAY,EAAE,cAAc,OAAO,aAAa,IAAI,CAAC;EACjF,WAAW,MAAM;CACnB,CAAC;CAED,MAAM,MAAM,iBAAiB;EAC3B,YAAY,IAAI;EAChB;EACA,cAAc,UAAU;EACxB,cAAc,UAAU;EACxB;CACF,CAAC;CACD,MAAM,EAAE,YAAY,eAAe;CAEnC,MAAM,WAAW,eAAe;EAC9B;EACA;EACA;EACA,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ;EACA;EACA;EACA,WAAW,UAAU;EACrB,WAAW,IAAI;EACf,SAAS,WAAW;CACtB,CAAC;CACD,MAAM,EAAE,QAAQ,iBAAiB;;;;CAKjC,SAAS,OAAO,MAAwB;EACtC,WAAW,gBAAgB,iBAAiB,aAAa,MAAM,aAAa,aAAa,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC;CAC/G;CAEA,SAAS,gBAAgB,MAAoB;EAC3C,IAAI,KAAK,UAAU,GAAG,MAAM,IAAI,MAAM,iBAAiB,KAAK,iCAAiC;CAC/F;CAEA,MAAM,EAAE,SAAS,YAAY,mBAAmB;EAC9C;EACA,WAAW,SAAS,iBAAiB,aAAa,IAAI,SAAS,IAAI;EACnE,SAAS,MAAM;EACf;EACA;EACA;EACA,gBAAgB;EAChB,UAAU,OAAO,OAAO,WAAW,QAAQ,OAAO,OAAO,EAAE;EAC3D,eAAe,MAAM;CACvB,CAAC;CAED,OAAO;EACL;EACA;EACA,oBAAoB,OAAO,MAAM;EACjC,SAAS;GACP,WAAW,MAAM,SAAS;IACxB,IAAI,KAAK,WAAW,MAAM,GACxB,MAAM,IAAI,MAAM,mBAAmB,KAAK,6BAA6B;IAEvE,IAAI,SAAS,MAAM,OAAgC;GACrD;GACA,SAAS,IAAI;IACX,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI;GACrC;GACA,WAAW,OAAO,OAAO,SAAS;IAChC,gBAAgB,YAAY;IAC5B,OAAO,WAAW,QAAQ,OAAO,aAC/B,QAAQ,QAAQ,QAAQ,MAAM,MAAM,QAAQ,KAAK,OAAO,OAAO,CAAC,CAAC;GACrE;GACA;GACA,GAAG;GACH,OAAO,SAAS;GAChB,WAAW,SAAS;GACpB,0BAA0B,MAAM;GAChC,mBAAmB,MAAM;GACzB,aAAa,OAAO;EACtB;CACF;AACF"}
|
|
@@ -3,11 +3,13 @@ import { createEmitter } from "@weasel-js/registry";
|
|
|
3
3
|
//#region src/core/scene/sceneSelection.ts
|
|
4
4
|
function createSceneSelection(reachable) {
|
|
5
5
|
let ids = [];
|
|
6
|
+
let changes = 0;
|
|
6
7
|
const changed = createEmitter();
|
|
7
8
|
return {
|
|
8
9
|
get: () => ids,
|
|
9
10
|
set(next) {
|
|
10
11
|
ids = reachable(next);
|
|
12
|
+
changes++;
|
|
11
13
|
changed.emit();
|
|
12
14
|
},
|
|
13
15
|
narrow(gone) {
|
|
@@ -16,7 +18,8 @@ function createSceneSelection(reachable) {
|
|
|
16
18
|
replace(next) {
|
|
17
19
|
ids = next;
|
|
18
20
|
},
|
|
19
|
-
subscribe: changed.subscribe
|
|
21
|
+
subscribe: changed.subscribe,
|
|
22
|
+
changes: () => changes
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
/** The scene's selection in the shape `createHistory` wants, for a consumer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneSelection.js","names":[],"sources":["../../../src/core/scene/sceneSelection.ts"],"sourcesContent":["/**\n * The scene's selection: the transient set of active ids. Not document\n * content, so it never reaches `toJSON`; it does ride on history entries.\n */\nimport type { HistorySelection } from '@weasel-js/history';\nimport { createEmitter } from '@weasel-js/registry';\nimport type { NodeId } from './types';\n\nexport interface SceneSelection {\n get(): readonly NodeId[];\n /** Select the ids of `ids` that are in reach, and tell subscribers. */\n set(ids: readonly NodeId[]): void;\n /** Drop the ids in `gone`, and any a lock has put out of reach. Tells no\n * one: the edit that took them is what subscribers hear about. */\n narrow(gone?: ReadonlySet<NodeId>): void;\n /** Put a selection in place exactly as given, telling no one: for a caller\n * returning what it read earlier, or one that has already filtered. */\n replace(ids: readonly NodeId[]): void;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createSceneSelection(\n /** `ids` less those out of reach; the same array when none is. */\n reachable: (ids: readonly NodeId[]) => readonly NodeId[],\n): SceneSelection {\n let ids: readonly NodeId[] = [];\n const changed = createEmitter();\n\n return {\n get: () => ids,\n set(next) {\n ids = reachable(next);\n changed.emit();\n },\n narrow(gone) {\n // A new array only when one is dropped: readers compare the selection by identity.\n const kept = gone !== undefined && ids.some((id) => gone.has(id)) ? ids.filter((id) => !gone.has(id)) : ids;\n ids = reachable(kept);\n },\n replace(next) {\n ids = next;\n },\n subscribe: changed.subscribe,\n };\n}\n\n/** The scene's selection in the shape `createHistory` wants, for a consumer\n * building a second History over the same scene (a modality machine, a\n * journal owner) that should restore selection the way the scene's own\n * history does. */\nexport function sceneSelectionStore(scene: {\n getSelection(): readonly NodeId[];\n setSelection(ids: readonly NodeId[]): void;\n}): HistorySelection {\n return {\n get: () => scene.getSelection(),\n set: (ids) => scene.setSelection(ids as readonly NodeId[]),\n };\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sceneSelection.js","names":[],"sources":["../../../src/core/scene/sceneSelection.ts"],"sourcesContent":["/**\n * The scene's selection: the transient set of active ids. Not document\n * content, so it never reaches `toJSON`; it does ride on history entries.\n */\nimport type { HistorySelection } from '@weasel-js/history';\nimport { createEmitter } from '@weasel-js/registry';\nimport type { NodeId } from './types';\n\nexport interface SceneSelection {\n get(): readonly NodeId[];\n /** Select the ids of `ids` that are in reach, and tell subscribers. */\n set(ids: readonly NodeId[]): void;\n /** Drop the ids in `gone`, and any a lock has put out of reach. Tells no\n * one: the edit that took them is what subscribers hear about. */\n narrow(gone?: ReadonlySet<NodeId>): void;\n /** Put a selection in place exactly as given, telling no one: for a caller\n * returning what it read earlier, or one that has already filtered. */\n replace(ids: readonly NodeId[]): void;\n subscribe(listener: () => void): () => void;\n /** How many times subscribers have been told the selection changed. */\n changes(): number;\n}\n\nexport function createSceneSelection(\n /** `ids` less those out of reach; the same array when none is. */\n reachable: (ids: readonly NodeId[]) => readonly NodeId[],\n): SceneSelection {\n let ids: readonly NodeId[] = [];\n let changes = 0;\n const changed = createEmitter();\n\n return {\n get: () => ids,\n set(next) {\n ids = reachable(next);\n changes++;\n changed.emit();\n },\n narrow(gone) {\n // A new array only when one is dropped: readers compare the selection by identity.\n const kept = gone !== undefined && ids.some((id) => gone.has(id)) ? ids.filter((id) => !gone.has(id)) : ids;\n ids = reachable(kept);\n },\n replace(next) {\n ids = next;\n },\n subscribe: changed.subscribe,\n changes: () => changes,\n };\n}\n\n/** The scene's selection in the shape `createHistory` wants, for a consumer\n * building a second History over the same scene (a modality machine, a\n * journal owner) that should restore selection the way the scene's own\n * history does. */\nexport function sceneSelectionStore(scene: {\n getSelection(): readonly NodeId[];\n setSelection(ids: readonly NodeId[]): void;\n}): HistorySelection {\n return {\n get: () => scene.getSelection(),\n set: (ids) => scene.setSelection(ids as readonly NodeId[]),\n };\n}\n"],"mappings":";;;AAuBA,SAAgB,qBAEd,WACgB;CAChB,IAAI,MAAyB,CAAC;CAC9B,IAAI,UAAU;CACd,MAAM,UAAU,cAAc;CAE9B,OAAO;EACL,WAAW;EACX,IAAI,MAAM;GACR,MAAM,UAAU,IAAI;GACpB;GACA,QAAQ,KAAK;EACf;EACA,OAAO,MAAM;GAGX,MAAM,UADO,SAAS,UAAa,IAAI,MAAM,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,IAAI,QAAQ,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,GACpF;EACtB;EACA,QAAQ,MAAM;GACZ,MAAM;EACR;EACA,WAAW,QAAQ;EACnB,eAAe;CACjB;AACF;;;;;AAMA,SAAgB,oBAAoB,OAGf;CACnB,OAAO;EACL,WAAW,MAAM,aAAa;EAC9B,MAAM,QAAQ,MAAM,aAAa,GAAwB;CAC3D;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createNodeFnFields } from "./nodeFnFields.js";
|
|
2
|
+
import { createDocStore } from "./docValues.js";
|
|
2
3
|
import { createLayerStack } from "./layerStack.js";
|
|
3
4
|
import { createStaleReplay } from "./staleReplay.js";
|
|
4
5
|
import { createLockGuard } from "./lockGuard.js";
|
|
@@ -12,12 +13,13 @@ import { createTreeReads } from "./treeReads.js";
|
|
|
12
13
|
* A scene's document state — its nodes, roots, and layers — with the modules
|
|
13
14
|
* that read and write it directly.
|
|
14
15
|
*/
|
|
15
|
-
function createSceneState(registry, initialLayers, layoutDeclared) {
|
|
16
|
+
function createSceneState(registry, initialLayers, layoutDeclared, initialDoc) {
|
|
16
17
|
const state = {
|
|
17
18
|
nodes: /* @__PURE__ */ new Map(),
|
|
18
19
|
roots: [],
|
|
19
20
|
layers: [],
|
|
20
|
-
layerIndex: /* @__PURE__ */ new Map()
|
|
21
|
+
layerIndex: /* @__PURE__ */ new Map(),
|
|
22
|
+
docValues: /* @__PURE__ */ new Map()
|
|
21
23
|
};
|
|
22
24
|
const order = createRenderOrder(state);
|
|
23
25
|
/** The registry-keyed function fields, each with its key maps. A function
|
|
@@ -29,6 +31,8 @@ function createSceneState(registry, initialLayers, layoutDeclared) {
|
|
|
29
31
|
const layers = createLayerStack(state, order.invalidate);
|
|
30
32
|
layers.reset(initialLayers);
|
|
31
33
|
const locks = createLockGuard(state);
|
|
34
|
+
const docValues = createDocStore(state.docValues);
|
|
35
|
+
docValues.reset(initialDoc);
|
|
32
36
|
const reads = {
|
|
33
37
|
...createTreeReads(state.nodes),
|
|
34
38
|
renderOrder: order.ids,
|
|
@@ -40,7 +44,7 @@ function createSceneState(registry, initialLayers, layoutDeclared) {
|
|
|
40
44
|
const node = state.nodes.get(id);
|
|
41
45
|
return node?.kind === "container" ? node.layout ?? null : null;
|
|
42
46
|
},
|
|
43
|
-
toJSON: () => serializeScene(state, fnFields)
|
|
47
|
+
toJSON: () => serializeScene(state, fnFields, docValues.toJSON())
|
|
44
48
|
};
|
|
45
49
|
return {
|
|
46
50
|
state,
|
|
@@ -51,8 +55,10 @@ function createSceneState(registry, initialLayers, layoutDeclared) {
|
|
|
51
55
|
store,
|
|
52
56
|
layers,
|
|
53
57
|
reads,
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
docValues,
|
|
59
|
+
/** Empty the document and give it `records` as its layers and `values` as its document values. */
|
|
60
|
+
reset(records, values) {
|
|
61
|
+
docValues.reset(values);
|
|
56
62
|
store.dependents.clear();
|
|
57
63
|
store.childDerived.clear();
|
|
58
64
|
state.nodes.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneState.js","names":[],"sources":["../../../src/core/scene/sceneState.ts"],"sourcesContent":["/**\n * A scene's document state — its nodes, roots, and layers — with the modules\n * that read and write it directly.\n */\nimport { createLayerStack } from './layerStack';\nimport { createLockGuard } from './lockGuard';\nimport { createNodeFnFields } from './nodeFnFields';\nimport { createNodeStore } from './nodeStore';\nimport { createRenderOrder } from './renderOrder';\nimport { serializeScene } from './serialization';\nimport { createStaleReplay } from './staleReplay';\nimport { createTreeReads } from './treeReads';\nimport type { LayerRecord, Node, NodeId, Scene, SceneRegistry } from './types';\n\nexport function createSceneState<TData, TLayer extends string, TPose>(\n registry: SceneRegistry<TPose, TData, TLayer>,\n initialLayers: readonly LayerRecord<TLayer>[],\n /** Called when a node is given a layout. */\n layoutDeclared: () => void,\n) {\n const state = {\n nodes: new Map<NodeId, Node<TData, TLayer, TPose>>(),\n roots: [] as NodeId[],\n layers: [] as LayerRecord<TLayer>[],\n layerIndex: new Map<TLayer, number>(),\n };\n const order = createRenderOrder(state);\n /** The registry-keyed function fields, each with its key maps. A function\n * cannot travel through a serializable op payload, so an op carries its key. */\n const fnFields = createNodeFnFields<TPose>(registry, (field) => {\n if (field === 'layout') layoutDeclared();\n });\n const store = createNodeStore(state, order.invalidate, fnFields);\n const layers = createLayerStack(state, order.invalidate);\n layers.reset(initialLayers);\n const locks = createLockGuard(state);\n\n const reads: Pick<\n Scene<TData, TLayer, TPose>,\n | 'get' | 'incarnation' | 'childrenOf' | 'ancestorsOf' | 'renderOrder' | 'renderOrderNodes'\n | 'nodesOnLayer' | 'isLocked' | 'isHidden' | 'layoutOf' | 'toJSON'\n > = {\n ...createTreeReads(state.nodes),\n renderOrder: order.ids,\n renderOrderNodes: order.nodes,\n nodesOnLayer: order.nodesOnLayer,\n isLocked: (id) => locks.isLocked(id),\n isHidden: (id) => locks.isHidden(id),\n layoutOf(id) {\n const node = state.nodes.get(id);\n return node?.kind === 'container' ? (node.layout ?? null) : null;\n },\n toJSON: () => serializeScene(state, fnFields),\n };\n\n return {\n state,\n order,\n locks,\n stale: createStaleReplay(state.nodes),\n fnFields,\n store,\n layers,\n reads,\n\n /** Empty the document and give it `records` as its layers. */\n reset(records: readonly LayerRecord<TLayer>[]): void {\n store.dependents.clear();\n store.childDerived.clear();\n state.nodes.clear();\n state.roots.length = 0;\n layers.reset(records);\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sceneState.js","names":[],"sources":["../../../src/core/scene/sceneState.ts"],"sourcesContent":["/**\n * A scene's document state — its nodes, roots, and layers — with the modules\n * that read and write it directly.\n */\nimport { createDocStore, type SerializedDoc } from './docValues';\nimport { createLayerStack } from './layerStack';\nimport { createLockGuard } from './lockGuard';\nimport { createNodeFnFields } from './nodeFnFields';\nimport { createNodeStore } from './nodeStore';\nimport { createRenderOrder } from './renderOrder';\nimport { serializeScene } from './serialization';\nimport { createStaleReplay } from './staleReplay';\nimport { createTreeReads } from './treeReads';\nimport type { LayerRecord, Node, NodeId, Scene, SceneRegistry } from './types';\n\nexport function createSceneState<TData, TLayer extends string, TPose>(\n registry: SceneRegistry<TPose, TData, TLayer>,\n initialLayers: readonly LayerRecord<TLayer>[],\n /** Called when a node is given a layout. */\n layoutDeclared: () => void,\n initialDoc?: SerializedDoc,\n) {\n const state = {\n nodes: new Map<NodeId, Node<TData, TLayer, TPose>>(),\n roots: [] as NodeId[],\n layers: [] as LayerRecord<TLayer>[],\n layerIndex: new Map<TLayer, number>(),\n docValues: new Map<string, unknown>(),\n };\n const order = createRenderOrder(state);\n /** The registry-keyed function fields, each with its key maps. A function\n * cannot travel through a serializable op payload, so an op carries its key. */\n const fnFields = createNodeFnFields<TPose>(registry, (field) => {\n if (field === 'layout') layoutDeclared();\n });\n const store = createNodeStore(state, order.invalidate, fnFields);\n const layers = createLayerStack(state, order.invalidate);\n layers.reset(initialLayers);\n const locks = createLockGuard(state);\n const docValues = createDocStore(state.docValues);\n docValues.reset(initialDoc);\n\n const reads: Pick<\n Scene<TData, TLayer, TPose>,\n | 'get' | 'incarnation' | 'childrenOf' | 'ancestorsOf' | 'renderOrder' | 'renderOrderNodes'\n | 'nodesOnLayer' | 'isLocked' | 'isHidden' | 'layoutOf' | 'toJSON'\n > = {\n ...createTreeReads(state.nodes),\n renderOrder: order.ids,\n renderOrderNodes: order.nodes,\n nodesOnLayer: order.nodesOnLayer,\n isLocked: (id) => locks.isLocked(id),\n isHidden: (id) => locks.isHidden(id),\n layoutOf(id) {\n const node = state.nodes.get(id);\n return node?.kind === 'container' ? (node.layout ?? null) : null;\n },\n toJSON: () => serializeScene(state, fnFields, docValues.toJSON()),\n };\n\n return {\n state,\n order,\n locks,\n stale: createStaleReplay(state.nodes),\n fnFields,\n store,\n layers,\n reads,\n docValues,\n\n /** Empty the document and give it `records` as its layers and `values` as its document values. */\n reset(records: readonly LayerRecord<TLayer>[], values?: SerializedDoc): void {\n docValues.reset(values);\n store.dependents.clear();\n store.childDerived.clear();\n state.nodes.clear();\n state.roots.length = 0;\n layers.reset(records);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,iBACd,UACA,eAEA,gBACA,YACA;CACA,MAAM,QAAQ;EACZ,uBAAO,IAAI,IAAwC;EACnD,OAAO,CAAC;EACR,QAAQ,CAAC;EACT,4BAAY,IAAI,IAAoB;EACpC,2BAAW,IAAI,IAAqB;CACtC;CACA,MAAM,QAAQ,kBAAkB,KAAK;;;CAGrC,MAAM,WAAW,mBAA0B,WAAW,UAAU;EAC9D,IAAI,UAAU,UAAU,eAAe;CACzC,CAAC;CACD,MAAM,QAAQ,gBAAgB,OAAO,MAAM,YAAY,QAAQ;CAC/D,MAAM,SAAS,iBAAiB,OAAO,MAAM,UAAU;CACvD,OAAO,MAAM,aAAa;CAC1B,MAAM,QAAQ,gBAAgB,KAAK;CACnC,MAAM,YAAY,eAAe,MAAM,SAAS;CAChD,UAAU,MAAM,UAAU;CAE1B,MAAM,QAIF;EACF,GAAG,gBAAgB,MAAM,KAAK;EAC9B,aAAa,MAAM;EACnB,kBAAkB,MAAM;EACxB,cAAc,MAAM;EACpB,WAAW,OAAO,MAAM,SAAS,EAAE;EACnC,WAAW,OAAO,MAAM,SAAS,EAAE;EACnC,SAAS,IAAI;GACX,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;GAC/B,OAAO,MAAM,SAAS,cAAe,KAAK,UAAU,OAAQ;EAC9D;EACA,cAAc,eAAe,OAAO,UAAU,UAAU,OAAO,CAAC;CAClE;CAEA,OAAO;EACL;EACA;EACA;EACA,OAAO,kBAAkB,MAAM,KAAK;EACpC;EACA;EACA;EACA;EACA;;EAGA,MAAM,SAAyC,QAA8B;GAC3E,UAAU,MAAM,MAAM;GACtB,MAAM,WAAW,MAAM;GACvB,MAAM,aAAa,MAAM;GACzB,MAAM,MAAM,MAAM;GAClB,MAAM,MAAM,SAAS;GACrB,OAAO,MAAM,OAAO;EACtB;CACF;AACF"}
|
|
@@ -29,9 +29,10 @@ function layerFromSerialized(spec) {
|
|
|
29
29
|
kind: "system"
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
/** The snapshot of `state`: layers in order, nodes in tree preorder
|
|
32
|
+
/** The snapshot of `state`: layers in order, nodes in tree preorder, and the
|
|
33
|
+
* document values when there are any. Throws
|
|
33
34
|
* when a node carries a function the registry has no key for. */
|
|
34
|
-
function serializeScene(state, fnFields) {
|
|
35
|
+
function serializeScene(state, fnFields, doc) {
|
|
35
36
|
const nodes = [];
|
|
36
37
|
for (const n of treePreorder(state.roots, state.nodes)) {
|
|
37
38
|
const id = n.id;
|
|
@@ -68,7 +69,8 @@ function serializeScene(state, fnFields) {
|
|
|
68
69
|
}
|
|
69
70
|
return layer;
|
|
70
71
|
}),
|
|
71
|
-
nodes
|
|
72
|
+
nodes,
|
|
73
|
+
...doc ? { doc } : {}
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
/** Map a `SerializedScene` to construction specs. Shared by `sceneFromJSON`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","names":[],"sources":["../../../src/core/scene/serialization.ts"],"sourcesContent":["/**\n * A scene to and from its JSON snapshot: the walk that writes one, and the\n * two readers that turn one back into layer records and node specs.\n */\nimport {\n NODE_FN_FIELDS, fnKeysOf, type FnBearingNode, type NodeFnField,\n} from './nodeFnFields';\nimport { treePreorder } from './treeOrder';\nimport type {\n AddNodeSpec, LayerRecord, Node, NodeId, SceneRegistry, SerializedLayer, SerializedNode, SerializedScene,\n} from './types';\n\n/** Whether `value` is a snapshot `specsFromSerialized` reads, as against a live scene. */\nexport function isSerializedScene<TData, TLayer extends string, TPose>(\n value: unknown,\n): value is SerializedScene<TData, TLayer, TPose> {\n return typeof value === 'object' && value != null\n && (value as { version?: unknown }).version === 1\n && Array.isArray((value as { nodes?: unknown }).nodes);\n}\n\n/** What a snapshot is written from. */\nexport interface SerializableState<TData, TLayer extends string, TPose> {\n nodes: Map<NodeId, Node<TData, TLayer, TPose>>;\n roots: NodeId[];\n layers: LayerRecord<TLayer>[];\n}\n\n/** One layer record from its snapshot form. A snapshot with no `kind` predates\n * user layers, so everything in it was a system layer. */\nexport function layerFromSerialized<TLayer extends string>(\n spec: SerializedLayer<TLayer>,\n): LayerRecord<TLayer> {\n const base = {\n id: spec.id,\n visible: spec.visible ?? true,\n locked: spec.locked ?? false,\n ...(spec.parallax ? { parallax: spec.parallax } : {}),\n ...(spec.annotation ? { annotation: true } : {}),\n };\n return spec.kind === 'user'\n ? { ...base, kind: 'user', name: spec.name ?? spec.id }\n : { ...base, kind: 'system' };\n}\n\n/** The snapshot of `state`: layers in order, nodes in tree preorder. Throws\n * when a node carries a function the registry has no key for. */\nexport function serializeScene<TData, TLayer extends string, TPose>(\n state: SerializableState<TData, TLayer, TPose>,\n fnFields: readonly NodeFnField[],\n): SerializedScene<TData, TLayer, TPose> {\n const nodes: SerializedNode<TData, TLayer, TPose>[] = [];\n for (const n of treePreorder(state.roots, state.nodes)) {\n const id = n.id;\n const out: SerializedNode<TData, TLayer, TPose> = {\n id,\n kind: n.kind,\n layer: n.layer,\n pose: n.pose,\n data: n.data,\n };\n if (n.parent != null) out.parent = n.parent;\n if (n.dependsOn === 'children') out.dependsOn = 'children';\n else if (n.dependsOn && n.dependsOn.length > 0) out.dependsOn = n.dependsOn;\n if (n.pickable === false) out.pickable = false;\n if (n.hidden === true) out.hidden = true;\n if (n.locked === true) out.locked = true;\n if (n.kind === 'container' && n.units !== undefined) out.units = n.units;\n Object.assign(\n out,\n fnKeysOf(fnFields, n as unknown as FnBearingNode, 'jsonKey', (field) => {\n throw new Error(\n `Scene.toJSON: node '${id}' has ${field.spec.field} but no matching registry key. ` +\n `The function must be registered via createScene's registry option to round-trip.`\n );\n }),\n );\n nodes.push(out);\n }\n const systemLayers = state.layers.map((l) => {\n const layer: SerializedLayer<TLayer> = { id: l.id };\n if (l.visible === false) layer.visible = false;\n if (l.locked === true) layer.locked = true;\n if (l.parallax) layer.parallax = l.parallax;\n if (l.annotation) layer.annotation = true;\n if (l.kind === 'user') {\n layer.kind = 'user';\n layer.name = l.name;\n }\n return layer;\n });\n return { version: 1, systemLayers, nodes };\n}\n\n/** Map a `SerializedScene` to construction specs. Shared by `sceneFromJSON`\n * (new instance) and `Scene.loadState` (in-place). Validates version and\n * resolves every `NODE_FN_FIELDS` key → function via the registry;\n * throws on an unsupported version or an unknown registry key. */\nexport function specsFromSerialized<TData, TLayer extends string, TPose>(\n json: SerializedScene<TData, TLayer, TPose>,\n registry: SceneRegistry<TPose, TData, TLayer>,\n): AddNodeSpec<TData, TLayer, TPose>[] {\n if (json.version !== 1) {\n throw new Error(`Scene: unsupported version ${json.version}; only v1 supported`);\n }\n return json.nodes.map((n) => {\n const spec: AddNodeSpec<TData, TLayer, TPose> = {\n id: n.id as NodeId,\n kind: n.kind,\n layer: n.layer,\n pose: n.pose,\n data: n.data,\n };\n if (n.parent !== undefined) spec.parent = n.parent as NodeId;\n if (n.pickable !== undefined) spec.pickable = n.pickable;\n if (n.hidden === true) spec.hidden = true;\n if (n.locked === true) spec.locked = true;\n if (n.units !== undefined) spec.units = n.units;\n if (n.dependsOn !== undefined) {\n spec.dependsOn = n.dependsOn === 'children'\n ? 'children'\n : (n.dependsOn as readonly NodeId[]);\n }\n const serialized = n as unknown as Record<string, string | undefined>;\n for (const field of NODE_FN_FIELDS) {\n const key = serialized[field.jsonKey];\n if (key === undefined) continue;\n const fn = (registry[field.field] as Record<string, unknown> | undefined)?.[key];\n if (!fn) {\n throw new Error(\n `Scene: unknown ${field.field} key '${key}'. ` +\n `Register a function with this key in the registry option.`,\n );\n }\n (spec as unknown as Record<string, unknown>)[field.field] = fn;\n }\n return spec;\n });\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"serialization.js","names":[],"sources":["../../../src/core/scene/serialization.ts"],"sourcesContent":["/**\n * A scene to and from its JSON snapshot: the walk that writes one, and the\n * two readers that turn one back into layer records and node specs.\n */\nimport {\n NODE_FN_FIELDS, fnKeysOf, type FnBearingNode, type NodeFnField,\n} from './nodeFnFields';\nimport type { SerializedDoc } from './docValues';\nimport { treePreorder } from './treeOrder';\nimport type {\n AddNodeSpec, LayerRecord, Node, NodeId, SceneRegistry, SerializedLayer, SerializedNode, SerializedScene,\n} from './types';\n\n/** Whether `value` is a snapshot `specsFromSerialized` reads, as against a live scene. */\nexport function isSerializedScene<TData, TLayer extends string, TPose>(\n value: unknown,\n): value is SerializedScene<TData, TLayer, TPose> {\n return typeof value === 'object' && value != null\n && (value as { version?: unknown }).version === 1\n && Array.isArray((value as { nodes?: unknown }).nodes);\n}\n\n/** What a snapshot is written from. */\nexport interface SerializableState<TData, TLayer extends string, TPose> {\n nodes: Map<NodeId, Node<TData, TLayer, TPose>>;\n roots: NodeId[];\n layers: LayerRecord<TLayer>[];\n}\n\n/** One layer record from its snapshot form. A snapshot with no `kind` predates\n * user layers, so everything in it was a system layer. */\nexport function layerFromSerialized<TLayer extends string>(\n spec: SerializedLayer<TLayer>,\n): LayerRecord<TLayer> {\n const base = {\n id: spec.id,\n visible: spec.visible ?? true,\n locked: spec.locked ?? false,\n ...(spec.parallax ? { parallax: spec.parallax } : {}),\n ...(spec.annotation ? { annotation: true } : {}),\n };\n return spec.kind === 'user'\n ? { ...base, kind: 'user', name: spec.name ?? spec.id }\n : { ...base, kind: 'system' };\n}\n\n/** The snapshot of `state`: layers in order, nodes in tree preorder, and the\n * document values when there are any. Throws\n * when a node carries a function the registry has no key for. */\nexport function serializeScene<TData, TLayer extends string, TPose>(\n state: SerializableState<TData, TLayer, TPose>,\n fnFields: readonly NodeFnField[],\n doc?: SerializedDoc,\n): SerializedScene<TData, TLayer, TPose> {\n const nodes: SerializedNode<TData, TLayer, TPose>[] = [];\n for (const n of treePreorder(state.roots, state.nodes)) {\n const id = n.id;\n const out: SerializedNode<TData, TLayer, TPose> = {\n id,\n kind: n.kind,\n layer: n.layer,\n pose: n.pose,\n data: n.data,\n };\n if (n.parent != null) out.parent = n.parent;\n if (n.dependsOn === 'children') out.dependsOn = 'children';\n else if (n.dependsOn && n.dependsOn.length > 0) out.dependsOn = n.dependsOn;\n if (n.pickable === false) out.pickable = false;\n if (n.hidden === true) out.hidden = true;\n if (n.locked === true) out.locked = true;\n if (n.kind === 'container' && n.units !== undefined) out.units = n.units;\n Object.assign(\n out,\n fnKeysOf(fnFields, n as unknown as FnBearingNode, 'jsonKey', (field) => {\n throw new Error(\n `Scene.toJSON: node '${id}' has ${field.spec.field} but no matching registry key. ` +\n `The function must be registered via createScene's registry option to round-trip.`\n );\n }),\n );\n nodes.push(out);\n }\n const systemLayers = state.layers.map((l) => {\n const layer: SerializedLayer<TLayer> = { id: l.id };\n if (l.visible === false) layer.visible = false;\n if (l.locked === true) layer.locked = true;\n if (l.parallax) layer.parallax = l.parallax;\n if (l.annotation) layer.annotation = true;\n if (l.kind === 'user') {\n layer.kind = 'user';\n layer.name = l.name;\n }\n return layer;\n });\n return { version: 1, systemLayers, nodes, ...(doc ? { doc } : {}) };\n}\n\n/** Map a `SerializedScene` to construction specs. Shared by `sceneFromJSON`\n * (new instance) and `Scene.loadState` (in-place). Validates version and\n * resolves every `NODE_FN_FIELDS` key → function via the registry;\n * throws on an unsupported version or an unknown registry key. */\nexport function specsFromSerialized<TData, TLayer extends string, TPose>(\n json: SerializedScene<TData, TLayer, TPose>,\n registry: SceneRegistry<TPose, TData, TLayer>,\n): AddNodeSpec<TData, TLayer, TPose>[] {\n if (json.version !== 1) {\n throw new Error(`Scene: unsupported version ${json.version}; only v1 supported`);\n }\n return json.nodes.map((n) => {\n const spec: AddNodeSpec<TData, TLayer, TPose> = {\n id: n.id as NodeId,\n kind: n.kind,\n layer: n.layer,\n pose: n.pose,\n data: n.data,\n };\n if (n.parent !== undefined) spec.parent = n.parent as NodeId;\n if (n.pickable !== undefined) spec.pickable = n.pickable;\n if (n.hidden === true) spec.hidden = true;\n if (n.locked === true) spec.locked = true;\n if (n.units !== undefined) spec.units = n.units;\n if (n.dependsOn !== undefined) {\n spec.dependsOn = n.dependsOn === 'children'\n ? 'children'\n : (n.dependsOn as readonly NodeId[]);\n }\n const serialized = n as unknown as Record<string, string | undefined>;\n for (const field of NODE_FN_FIELDS) {\n const key = serialized[field.jsonKey];\n if (key === undefined) continue;\n const fn = (registry[field.field] as Record<string, unknown> | undefined)?.[key];\n if (!fn) {\n throw new Error(\n `Scene: unknown ${field.field} key '${key}'. ` +\n `Register a function with this key in the registry option.`,\n );\n }\n (spec as unknown as Record<string, unknown>)[field.field] = fn;\n }\n return spec;\n });\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,kBACd,OACgD;CAChD,OAAO,OAAO,UAAU,YAAY,SAAS,QACvC,MAAgC,YAAY,KAC7C,MAAM,QAAS,MAA8B,KAAK;AACzD;;;AAWA,SAAgB,oBACd,MACqB;CACrB,MAAM,OAAO;EACX,IAAI,KAAK;EACT,SAAS,KAAK,WAAW;EACzB,QAAQ,KAAK,UAAU;EACvB,GAAI,KAAK,WAAW,EAAE,UAAU,KAAK,SAAS,IAAI,CAAC;EACnD,GAAI,KAAK,aAAa,EAAE,YAAY,KAAK,IAAI,CAAC;CAChD;CACA,OAAO,KAAK,SAAS,SACjB;EAAE,GAAG;EAAM,MAAM;EAAQ,MAAM,KAAK,QAAQ,KAAK;CAAG,IACpD;EAAE,GAAG;EAAM,MAAM;CAAS;AAChC;;;;AAKA,SAAgB,eACd,OACA,UACA,KACuC;CACvC,MAAM,QAAgD,CAAC;CACvD,KAAK,MAAM,KAAK,aAAa,MAAM,OAAO,MAAM,KAAK,GAAG;EACtD,MAAM,KAAK,EAAE;EACb,MAAM,MAA4C;GAChD;GACA,MAAM,EAAE;GACR,OAAO,EAAE;GACT,MAAM,EAAE;GACR,MAAM,EAAE;EACV;EACA,IAAI,EAAE,UAAU,MAAM,IAAI,SAAS,EAAE;EACrC,IAAI,EAAE,cAAc,YAAY,IAAI,YAAY;OAC3C,IAAI,EAAE,aAAa,EAAE,UAAU,SAAS,GAAG,IAAI,YAAY,EAAE;EAClE,IAAI,EAAE,aAAa,OAAO,IAAI,WAAW;EACzC,IAAI,EAAE,WAAW,MAAM,IAAI,SAAS;EACpC,IAAI,EAAE,WAAW,MAAM,IAAI,SAAS;EACpC,IAAI,EAAE,SAAS,eAAe,EAAE,UAAU,QAAW,IAAI,QAAQ,EAAE;EACnE,OAAO,OACL,KACA,SAAS,UAAU,GAA+B,YAAY,UAAU;GACtE,MAAM,IAAI,MACR,uBAAuB,GAAG,QAAQ,MAAM,KAAK,MAAM,gHAErD;EACF,CAAC,CACH;EACA,MAAM,KAAK,GAAG;CAChB;CAaA,OAAO;EAAE,SAAS;EAAG,cAZA,MAAM,OAAO,KAAK,MAAM;GAC3C,MAAM,QAAiC,EAAE,IAAI,EAAE,GAAG;GAClD,IAAI,EAAE,YAAY,OAAO,MAAM,UAAU;GACzC,IAAI,EAAE,WAAW,MAAM,MAAM,SAAS;GACtC,IAAI,EAAE,UAAU,MAAM,WAAW,EAAE;GACnC,IAAI,EAAE,YAAY,MAAM,aAAa;GACrC,IAAI,EAAE,SAAS,QAAQ;IACrB,MAAM,OAAO;IACb,MAAM,OAAO,EAAE;GACjB;GACA,OAAO;EACT,CACqB;EAAc;EAAO,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;CAAG;AACpE;;;;;AAMA,SAAgB,oBACd,MACA,UACqC;CACrC,IAAI,KAAK,YAAY,GACnB,MAAM,IAAI,MAAM,8BAA8B,KAAK,QAAQ,oBAAoB;CAEjF,OAAO,KAAK,MAAM,KAAK,MAAM;EAC3B,MAAM,OAA0C;GAC9C,IAAI,EAAE;GACN,MAAM,EAAE;GACR,OAAO,EAAE;GACT,MAAM,EAAE;GACR,MAAM,EAAE;EACV;EACA,IAAI,EAAE,WAAW,QAAW,KAAK,SAAS,EAAE;EAC5C,IAAI,EAAE,aAAa,QAAW,KAAK,WAAW,EAAE;EAChD,IAAI,EAAE,WAAW,MAAM,KAAK,SAAS;EACrC,IAAI,EAAE,WAAW,MAAM,KAAK,SAAS;EACrC,IAAI,EAAE,UAAU,QAAW,KAAK,QAAQ,EAAE;EAC1C,IAAI,EAAE,cAAc,QAClB,KAAK,YAAY,EAAE,cAAc,aAC7B,aACC,EAAE;EAET,MAAM,aAAa;EACnB,KAAK,MAAM,SAAS,gBAAgB;GAClC,MAAM,MAAM,WAAW,MAAM;GAC7B,IAAI,QAAQ,QAAW;GACvB,MAAM,KAAM,SAAS,MAAM,MAAM,GAA2C;GAC5E,IAAI,CAAC,IACH,MAAM,IAAI,MACR,kBAAkB,MAAM,MAAM,QAAQ,IAAI,6DAE5C;GAEF,KAA6C,MAAM,SAAS;EAC9D;EACA,OAAO;CACT,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/core/scene/types.ts"],"sourcesContent":["import type { History, SerializedHistory } from '@weasel-js/history';\nimport type { SerializedSceneHistory } from './historyForm';\nimport type { ParallaxOpts } from '../viewport/parallax';\nimport type { UnitScope } from '@weasel-js/quantity';\nimport type { LayoutStrategy } from '../../layout/types';\nimport type { AddLayerSpec, LayerRecord, SystemLayerRecord, SystemLayerSpec, UserLayerRecord } from './layerTypes';\nimport type { LayoutFrame, LayoutMove } from './layoutTypes';\nimport type { PoseComposition } from './composeFrame';\nimport type { PoseRemoval, PoseWrite, PoseWriteOrigin, RemovedNode, ScenePoseReports } from './poseWrites';\nimport type { PoseHold, PoseOverride, PoseOverrides } from './poseOverrideTypes';\nimport type { SerializedLayer, SerializedNode, SerializedScene } from './serializedTypes';\nimport type { UseSceneOptions } from './useSceneOptions';\n\nimport type { RectPose } from '../geometry/rectPose';\nexport type { RectPose };\nexport type { AddLayerSpec, LayerRecord, SystemLayerRecord, SystemLayerSpec, UserLayerRecord };\nexport type { UseSceneOptions };\nexport type { PoseRemoval, PoseWrite, PoseWriteOrigin, RemovedNode, ScenePoseReports };\nexport type { LayoutFrame, LayoutMove, PoseHold, PoseOverride, PoseOverrides, SerializedLayer, SerializedNode, SerializedScene };\n\n/**\n * # SceneNode — the thing in the scene\n *\n * Everything the user sees on the canvas — a shape, a group, an annotation,\n * a tile — is a node. Containers and leaves are both nodes; the kit has no\n * other concept of \"scene element.\"\n *\n * Every node carries three independent slots, plus its tree position:\n *\n * - **`data: TData`** — app-defined payload. The kit never inspects it.\n * - **`pose: TPose`** — local transform, relative to the node's direct\n * parent (or world, for root nodes).\n * - **`layer: TLayer`** — a string tag associating the node with a\n * visual `RenderLayer` at draw time. Separate from `LayerRecord` (the\n * per-layer visible/locked metadata held by the `Scene`).\n *\n * Nodes are addressed by `NodeId` everywhere outside the scene tree. Don't\n * hold references to a `Node` object across scene updates; look up by id\n * when you need the latest.\n *\n * The kit-internal name is `Node`; the public re-export is `SceneNode`\n * (avoids collision with DOM `Node` at call sites).\n */\n\n/** Opaque branded id. Treat as opaque outside the kit. */\nimport type { NodeId } from '@weasel-js/routing';\nexport type { NodeId };\n\n/** Brand a string as a NodeId. */\nexport const asNodeId = (s: string): NodeId => s as NodeId;\n\nimport type { DerivedDep, Bivariant, DerivePathFn, DerivePoseFn, ClipFromPoseFn, CopiesFromPoseFn } from './nodeFnTypes';\nexport type { DerivedDep, Bivariant, DerivePathFn, DerivePoseFn, ClipFromPoseFn, CopiesFromPoseFn };\n\ninterface NodeBase<TData, TLayer extends string, TPose> {\n id: NodeId;\n layer: TLayer;\n pose: TPose;\n data: TData;\n parent: NodeId | null;\n /** Nodes whose poses this node's geometry is computed from. Fixed at add\n * time. Absent or empty means the node's geometry is authored, which is the\n * normal case.\n *\n * `'children'` means \"my own children, in child order\" — a container that\n * hugs its contents, which a fixed id list cannot express because\n * reparenting would have to maintain it. The two forms differ in lifetime\n * as well as in membership: deleting a node deletes everything that names\n * it in `dependsOn`, but a container outlives the children it derives\n * from — an emptied group is still a group. */\n dependsOn?: readonly NodeId[] | 'children';\n /** Whether the hit-test walk can return this node. Default `true`; `false`\n * makes it transparent to picking, so a click on it lands on whatever is\n * behind — normally its own container.\n *\n * For content a container owns rather than content the user selects on its\n * own: the label inside a box, a body's rows. It does not hide the node\n * from anything else — it still paints, still clips, and a consumer can\n * still select it by id. */\n pickable?: boolean;\n /** Not drawn, with its whole subtree: picking, area selection, select-all,\n * snapping and the selection pass over it, and an SVG export writes it with\n * `display=\"none\"`. Absent means shown; `Scene.isHidden` folds in its\n * ancestors' flags and its layer's visibility. */\n hidden?: boolean;\n /** Out of reach, with its whole subtree: still drawn, but picking and area\n * selection pass over it, the selection drops it, and every edit to it\n * throws, as on a locked layer. Absent means unlocked; `Scene.isLocked`\n * folds in its ancestors' and its layer's. */\n locked?: boolean;\n /** Computes this node's path from its dependencies, in `dependsOn` order —\n * each one the node and the pose it is painted at.\n * A dependency that has been removed arrives as `undefined`.\n * Returning `null` means \"nothing to draw right now\". Re-evaluated when a\n * dependency's world pose changes, never authored. */\n derivePath?: DerivePathFn<TPose, TData, TLayer>;\n /** Computes this node's pose from its dependencies' poses, the same way\n * `derivePath` computes its path — same `dependsOn` list, same\n * registry-keyed serialization.\n *\n * Where a derived path is resolved at paint time and reaches only the\n * painter, a derived pose is what the node *is* at: it feeds bounds,\n * hit-testing, selection chrome, snapping and layout, and every reader\n * gets it through `effectivePose`. A pose override still wins over it.\n *\n * Returning `null` means \"I have nothing to derive from right now\", and\n * the node falls back to its authored `pose`. `setPose` on a derived node\n * still writes that authored pose; it is simply not what anything reads. */\n derivePose?: DerivePoseFn<TPose, TData, TLayer>;\n}\n\n/** A node with no children — a shape, a label, an image. */\nexport interface LeafNode<TData, TLayer extends string, TPose = RectPose>\n extends NodeBase<TData, TLayer, TPose> {\n kind: 'leaf';\n}\n\n/** A node with an ordered list of children. This is the real group: what\n * Cmd+G creates, what SVG `<g>` round-trips to. A container has its own pose,\n * which its children's poses are relative to, and may optionally clip them. */\nexport interface ContainerNode<TData, TLayer extends string, TPose = RectPose>\n extends NodeBase<TData, TLayer, TPose> {\n kind: 'container';\n children: NodeId[];\n /** Optional clip-path source. Re-evaluated each render. Returning `null`\n * means \"no clip for this container right now\"; an empty / zero-area path\n * means \"clip everything out\" (children render nowhere). */\n clipFromPose?: ClipFromPoseFn<TPose>;\n /** Draws the whole subtree again under each affine it returns, on top of\n * the original, which still draws once as authored. The copies are paint,\n * not nodes: nothing stores them, so they follow every edit to the\n * children, and a pick that lands on one answers with the child it copies.\n * A copy is a copy of the clipped content — the clip travels with it.\n * Re-evaluated each render; `null` or `[]` draws no copies. */\n copiesFromPose?: CopiesFromPoseFn<TPose, TData, TLayer>;\n /** How this container arranges its children. Whenever the container's\n * child set or order changes, or its bounds change size, the scene hands\n * the change to the strategy — `depart` for children that left it,\n * `arrive` for children that joined it, `childPoses` otherwise — and records the poses it writes in the same\n * undo entry as the change. A drag reads it too: it is the layout `move`\n * reflows and drops against. */\n layout?: LayoutStrategy<TPose>;\n /** The unit system this container's contents are written in, and what one\n * of its base units is worth in the enclosing scope's. It covers the\n * children, not the container; `sceneUnitScopes` reads the chain. */\n units?: UnitScope;\n}\n\n/** A node in the scene tree: either a leaf or a container. Re-exported\n * publicly as `SceneNode`, to avoid colliding with the DOM's `Node`. */\nexport type Node<TData, TLayer extends string, TPose = RectPose> =\n | LeafNode<TData, TLayer, TPose>\n | ContainerNode<TData, TLayer, TPose>;\n\n/** What `Scene.add` needs to mint a node. Everything except the id is\n * required; the id is generated unless one is supplied. */\nexport interface AddNodeSpec<TData, TLayer extends string, TPose = RectPose> {\n kind: 'leaf' | 'container';\n layer: TLayer;\n pose: TPose;\n data: TData;\n parent?: NodeId | null;\n index?: number;\n /** Explicit id wins over the Scene's `generateId` and the kit default. */\n id?: NodeId;\n /** Mirrors `SceneNode.pickable`. Omit for the default, which is pickable. */\n pickable?: boolean;\n /** Mirrors `SceneNode.hidden`. */\n hidden?: boolean;\n /** Mirrors `SceneNode.locked`. */\n locked?: boolean;\n /** Only meaningful when `kind === 'container'`. Attach a clip-path function\n * to the node; ignored for leaves. Mirrors `ContainerNode.clipFromPose`. */\n clipFromPose?: ClipFromPoseFn<TPose>;\n /** Mirrors `ContainerNode.copiesFromPose`; ignored for leaves. */\n copiesFromPose?: CopiesFromPoseFn<TPose, TData, TLayer>;\n /** Mirrors `SceneNode.dependsOn`. */\n dependsOn?: readonly NodeId[] | 'children';\n /** Mirrors `SceneNode.derivePath`. Taken as a live function; its registry key is\n * looked up from it, never passed in. */\n derivePath?: DerivePathFn<TPose, TData, TLayer>;\n /** Mirrors `SceneNode.derivePose`, on the same terms as `derivePath`. */\n derivePose?: DerivePoseFn<TPose, TData, TLayer>;\n /** Mirrors `ContainerNode.layout`; ignored for leaves. */\n layout?: LayoutStrategy<TPose>;\n /** Mirrors `ContainerNode.units`; ignored for leaves. */\n units?: UnitScope;\n}\n\n/** A custom scene mutation registered with `Scene.registerOp`: how to apply\n * it and how to undo it. The pair is what makes it participate in history. */\nexport interface RegisteredOp<P> {\n apply: (payload: P) => void;\n revert: (payload: P) => void;\n /** Opts this kind into coalescing under `UseSceneOptions.coalesceWindowMs`:\n * two entries of this kind that return the same key inside the window\n * merge, and undoing the merged entry calls `revert` with the first\n * payload only. Declare it only when `revert` restores an absolute state\n * (a stored \"from\" value), never for a relative payload such as a delta.\n * Omitted, or returning `undefined`, the op is always its own entry. */\n coalesceKey?: (payload: P) => string | undefined;\n}\n\n/** Per-scene registry mapping string keys to live function references.\n * Passed to `createScene({ ..., registry })` and `sceneFromJSON(json, { registry })`.\n * Each function-field type has its own keyed map. */\nexport interface SceneRegistry<TPose, TData = unknown, TLayer extends string = string> {\n /** Maps registry keys to `clipFromPose` factory functions for container nodes. */\n clipFromPose?: Readonly<Record<string, ClipFromPoseFn<TPose>>>;\n /** Maps registry keys to `copiesFromPose` functions for container nodes. */\n copiesFromPose?: Readonly<Record<string, CopiesFromPoseFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to `derivePath` functions for nodes with `dependsOn`. */\n derivePath?: Readonly<Record<string, DerivePathFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to `derivePose` functions for nodes with `dependsOn`. */\n derivePose?: Readonly<Record<string, DerivePoseFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to container layout strategies. */\n layout?: Readonly<Record<string, LayoutStrategy<TPose>>>;\n // A new function field is a row in `NODE_FN_FIELDS` (core/scene/nodeFnFields.ts)\n // plus its entry here; the field name is the registry key by construction.\n}\n\n/**\n * Decides what one edit's changes to containers do to their children.\n * `arrivals` maps each container to the ids that joined it — by an `add`\n * under it or a `move` into it, whatever op or call made them — in the order\n * they arrived. `changed` names every container whose child set or order\n * changed, or whose pose changed size, arrivals included. Both are read once\n * the edit's other mutations have landed.\n *\n * Return the poses to write, in each node's stored frame; they become part of\n * the same edit, and so of the same undo step. An empty map writes nothing.\n * Return `null` to refuse: the whole edit is reverted (see\n * `SceneArrivalRefused`).\n *\n * Runs only for live edits. Undo, redo and a restored history replay the\n * arrangement that was decided the first time. With none installed, a scene\n * holding declared layouts (`ContainerNode.layout`) runs its own.\n */\nexport type SceneArrivalHandler<TPose> = (\n arrivals: ReadonlyMap<NodeId, readonly NodeId[]>,\n changed: ReadonlySet<NodeId>,\n /** The nodes that left each container in the edit, by the container they\n * left — removed, or moved out. */\n departures: ReadonlyMap<NodeId, readonly NodeId[]>,\n) => ReadonlyMap<NodeId, TPose> | null;\n\n/**\n * The kit-owned scene tree: nodes, layers, and the undo history over both.\n *\n * A scene is logical, not visual — it says what exists and where, and nothing\n * about how it is painted. Every mutating method is undoable, and reads are\n * snapshots rather than live views. Nodes are addressed by `NodeId`; hold ids\n * across mutations, not node objects.\n *\n * Three type parameters keep it domain-agnostic: `TData` is the app's payload,\n * which the kit never inspects; `TPose` is the transform shape, `RectPose` by\n * default; `TLayer` is the union of layer names.\n */\nexport interface Scene<TData, TLayer extends string, TPose = RectPose>\n extends ScenePoseReports<TPose, Node<TData, TLayer, TPose>> {\n // Reads\n readonly nodes: ReadonlyMap<NodeId, Node<TData, TLayer, TPose>>;\n readonly roots: readonly NodeId[];\n readonly layers: readonly LayerRecord<TLayer>[];\n /** The registry this scene resolves node functions against — the consumer's\n * entries over the kit's. */\n readonly registry: SceneRegistry<TPose, TData, TLayer>;\n /** See {@link UseSceneOptions.composition}. */\n readonly composition: PoseComposition<TPose>;\n get(id: NodeId): Node<TData, TLayer, TPose> | undefined;\n /** A token for the node `id` names right now, for telling one node from a\n * later one that reuses its id. It holds for as long as the node stays in\n * the scene, whatever edits it takes, and is different every time the id\n * enters the scene — by `add`, by an undo or redo that brings it back, or\n * by `loadState`. `undefined` when `id` is not in the scene. Compare tokens\n * for equality only; their order means nothing. */\n incarnation(id: NodeId): number | undefined;\n childrenOf(id: NodeId): readonly NodeId[];\n ancestorsOf(id: NodeId): readonly NodeId[];\n renderOrder(): Iterable<NodeId>;\n /** The same layer-major sequence as {@link Scene.renderOrder}, as the nodes\n * themselves. Prefer this wherever the ids are only going to be resolved\n * back to nodes. Cached until a structural edit, so repeat calls hand back\n * the same array — a snapshot, not a live view, and not yours to mutate. */\n renderOrderNodes(): readonly Node<TData, TLayer, TPose>[];\n /** The nodes on one layer, in render order. Cached alongside\n * {@link Scene.renderOrderNodes} until a structural edit. A snapshot, not\n * a live view, and not yours to mutate. An unknown layer id yields an\n * empty array. */\n nodesOnLayer(layer: TLayer): readonly Node<TData, TLayer, TPose>[];\n\n /** A fresh id from this scene's `generateId`, or the kit default: the id\n * `add` would give a spec with none. For code that has to name a node\n * before it exists, such as one building an insert op. */\n mintId(): NodeId;\n\n // Mutations (all auto-undoable)\n add(spec: AddNodeSpec<TData, TLayer, TPose>): NodeId;\n /** Delete `id`, its **entire subtree**, and **everything that derives from**\n * any of those nodes — a node listing one of them in `dependsOn` goes too,\n * along with its own subtree, transitively. A dependent can live anywhere in\n * the tree, so this deletes nodes the caller never named and may unlink\n * several disjoint subtrees at once. Recorded as one undoable step; `undo()`\n * restores every one of them where it was, child order intact. */\n remove(id: NodeId): void;\n /** {@link remove} over several roots at once, as a **single** undoable step.\n * Ids resolve against the tree as it stands at the call, so an id that\n * another one would cascade away is absorbed rather than removed twice —\n * which is what makes it safe to pass a whole selection. Throws if any id is\n * not in the scene; an empty list does nothing and records no step. */\n removeMany(ids: readonly NodeId[]): void;\n /** Every node {@link removeMany} would take if given `ids`: each id, its\n * subtree, everything deriving from any of those, and those nodes' subtrees\n * in turn. Ids not in the scene come back unchanged.\n *\n * A set, not a restore order: a dependent can be reached before the parent\n * it sits under, which is also in the closure. */\n removalClosure(ids: readonly NodeId[]): readonly NodeId[];\n update(id: NodeId, patch: { data: TData }): void;\n setPose(id: NodeId, pose: TPose): void;\n /** Retag `id` to `layer`. On a **container this cascades**: every descendant\n * is moved to the same layer, recorded as a **single** undo step.\n *\n * Invariants:\n * - **Layer floor** — a child may not render below its parent, so retagging\n * to a layer *below* the node's parent throws. Retagging to the parent's\n * layer or any higher one is allowed; a node with no parent is\n * unconstrained.\n * - **No-op elision** — setting the layer a node already has does nothing\n * and pushes **no** history entry. */\n setLayer(id: NodeId, layer: TLayer): void;\n /** Point `id` at a different set of dependencies — retargeting an edge's end\n * onto another node, or switching a container between an id list and\n * `'children'`. Recorded as one undoable step.\n *\n * Order is significant: a derivation reads its dependencies positionally,\n * so `[b, a]` is not `[a, b]`. Ids need not be in the scene — a declared\n * dependency that appears later invalidates the node when it does, the same\n * as one declared at `add`. Passing `undefined` drops the declaration, after\n * which nothing cascades the node away.\n *\n * **No-op elision** — declaring what the node already declares does nothing\n * and pushes no history entry. */\n setDependsOn(id: NodeId, dependsOn: readonly NodeId[] | 'children' | undefined): void;\n /** Give container `id` a different layout — a strategy, its key in\n * `SceneRegistry.layout`, or `null` for none — and re-arrange its children\n * under it, as one undoable step. Throws for a leaf, or a key the registry\n * does not hold. A registered layout is recorded by its key, so a\n * serialized history restores it; an unregistered one lives only as long\n * as the session.\n *\n * **No-op elision** — setting the layout a container already has does\n * nothing and pushes no history entry. */\n setLayout(id: NodeId, layout: LayoutStrategy<TPose> | string | null): void;\n /** Reparent `id` under `parent` (or to a root when `parent` is `null`) at\n * `index` within the new sibling list, appending when `index` is omitted.\n * Siblings are reindexed. Recorded as one undoable step.\n *\n * Rejected (throws) when:\n * - `parent` exists but is a **leaf**, not a container;\n * - the move would form a **cycle** — `parent` is `id` itself or one of\n * `id`'s own descendants;\n * - it would drop `id` **below its new parent's layer** (child may not\n * render below its parent).\n *\n * `move(id, null)` — detaching to a root — is always allowed regardless of\n * layer, since a root has no parent to render beneath. */\n move(id: NodeId, parent: NodeId | null, index?: number): void;\n /** Shift `id` to `index` within its **current** parent's child list. Unlike\n * {@link move}, the parent never changes — only sibling order. */\n reorder(id: NodeId, index: number): void;\n /** Show or hide a layer. Hiding drops its nodes from the selection. */\n setLayerVisible(layer: TLayer, visible: boolean): void;\n /** Lock or unlock a layer. A locked layer still paints, but its nodes are\n * out of reach: picking and area selection pass over them, the selection\n * drops them, and every node mutation on them throws. Locking is never\n * blocked by the lock, and neither are the other layer operations. */\n setLayerLocked(layer: TLayer, locked: boolean): void;\n /** Set or clear (`undefined`) a layer's parallax — see\n * `LayerRecord.parallax`. Undoable; an animation tweening it writes inside\n * {@link Scene.untracked} so no frame becomes an undo step. */\n setLayerParallax(layer: TLayer, parallax: ParallaxOpts | undefined): void;\n /** Whether `id` is locked: it or an ancestor carries `locked`, or sits on a\n * locked layer. A lock covers its whole subtree, whatever layers the\n * descendants are tagged to. An id not in the scene is not locked. */\n isLocked(id: NodeId): boolean;\n /** Whether `id` is not drawn: its own layer is hidden, or it or an ancestor\n * carries `hidden`. A hidden layer hides only the nodes tagged to it. An\n * id not in the scene is not hidden. */\n isHidden(id: NodeId): boolean;\n /** Hide or show node `id` and its subtree — see `SceneNode.hidden`. One\n * undo step; hiding drops the subtree from the selection. Never blocked by\n * a lock, and setting what the node already has records nothing. */\n setHidden(id: NodeId, hidden: boolean): void;\n /** Lock or unlock node `id` and its subtree — see `SceneNode.locked`. One\n * undo step; locking drops the subtree from the selection. Never blocked\n * by a lock, and setting what the node already has records nothing. */\n setLocked(id: NodeId, locked: boolean): void;\n /** Run `fn` with the lock guard lifted, for a programmatic edit that has to\n * reach a locked node. Undo and redo never need it. */\n unlocked<T>(fn: () => T): T;\n addLayer(spec: AddLayerSpec<TLayer>): void;\n /** Drop a user layer and every node tagged to it, as one undoable step.\n * Removal cascades, so this also deletes nodes **on other layers** that\n * derive from a node on this one. */\n removeLayer(layer: TLayer): void;\n renameLayer(layer: TLayer, name: string): void;\n moveLayer(layer: TLayer, index: number): void;\n\n // Custom op seam\n registerOp<P>(kind: string, handler: RegisteredOp<P>): void;\n recordOp<P>(op: { kind: string; payload: P }): void;\n\n /** Install (or clear with `null`) the active-journal accessor after scene\n * construction, for a journal source built with `scene.history` as a\n * dependency. Overrides any `getActiveJournal` set in `UseSceneOptions`. */\n setActiveJournalAccessor(\n fn: (() => import('@weasel-js/history').Journal | null) | null,\n ): void;\n\n /** Install what the scene does when nodes join a container, replacing any\n * handler installed before; `null` removes it. Returns a function that\n * removes this handler, and does nothing once another has replaced it.\n * See {@link SceneArrivalHandler}. */\n setArrivalHandler(handler: SceneArrivalHandler<TPose> | null): () => void;\n\n /** Apply a batch of ops against `adapter` as one undo entry.\n *\n * The entry holds the scene writes the ops made, as a direct call records\n * them, and beside them any op that wrote no scene state, bound to\n * `adapter`. Undo restores those writes; it does not call an op's\n * `invert()` or the adapter again. **What an op states is not recorded**:\n * one applied over a document that already holds its result, as after an\n * `untracked` preview, records a write from that pose to itself, and undo\n * goes nowhere. Put the document back first.\n *\n * The entry lands in the open `batch` when there is one, else on the\n * active journal, else on the scene's own history, where it can coalesce\n * under `coalesceWindowMs` with one whose ops' keys match.\n *\n * Returns false when the arrival handler refused the batch: it is reverted\n * and unrecorded. Inside `batch` it is true; that batch may still refuse. */\n applyBatch(ops: import('core/ops/types').Op[], label: string, adapter: unknown): boolean;\n\n // Selection\n\n /** The transient set of active ids — \"operate on these N as a unit\".\n * Shared by every view over this scene unless a view supplies its own\n * (see `CanvasView.selection`). Not document content: it never appears\n * in `toJSON`. It does ride on history entries, so undo and redo put\n * back the selection an edit was made under; changing it is never an\n * undo step of its own. Removing a node deselects it. */\n getSelection(): readonly NodeId[];\n setSelection(ids: readonly NodeId[]): void;\n\n // Ephemeral presentation state\n\n /** Per-node pose / alpha overrides the render and hit-test paths read\n * through. Like {@link Scene.getSelection} this is not document content:\n * writes are never recorded, never serialized, and do not bump\n * {@link Scene.getVersion}. See {@link PoseOverrides}. */\n readonly overrides: PoseOverrides<TPose>;\n\n // History\n /** The scene's undo/redo engine, in the shape `@weasel-js/history` defines.\n * Mutating members route through\n * the scene's own wrappers, so an undo driven through this bumps\n * {@link Scene.getVersion} and notifies subscribers exactly as\n * {@link Scene.undo} does; `getVersion` / `subscribe` on it report the\n * engine's history version, not the scene's. */\n readonly history: History;\n undo(): boolean;\n redo(): boolean;\n canUndo(): boolean;\n canRedo(): boolean;\n batch<T>(label: string, fn: () => T): T;\n /** The layout container `id` declares, or `null` for a leaf or a\n * container that declares none. */\n layoutOf(id: NodeId): LayoutStrategy<TPose> | null;\n /** Declare the unit scope of container `id`, or clear it with `null`. */\n setUnits(id: NodeId, units: UnitScope | null): void;\n /** Run `fn` with every mutation applied but none recorded — for writes\n * that are not edits, such as a simulation stepping poses each frame.\n * Undo and redo move between recorded states and never restore an\n * untracked write; the next recorded change starts from whatever the\n * untracked writes left, so undoing it lands there. A `batch` inside\n * records nothing; inside a `batch`, these writes stay out of its entry.\n * Notifies once, reverts `fn`'s writes if it throws, and throws on\n * `applyBatch` and `history.apply` / `applyOps`, which exist to record. */\n untracked<T>(fn: () => T): T;\n /** Read-only snapshot of every history entry currently reachable from\n * the present state. Oldest applied first, then redoable entries in\n * the order they'd be re-applied. Each entry id is stable. */\n historyEntries(): readonly { id: string; label: string }[];\n /** Index of the \"current state\". Equals the count of applied entries;\n * `0` means \"nothing applied\" (initial). */\n historyIndex(): number;\n /** Jump to the given history index, clamped to [0, total]. Returns true\n * if any movement occurred. */\n jumpToHistoryIndex(index: number): boolean;\n\n // History persistence\n /** Snapshot the undo/redo history in a JSON-serializable form (the\n * engine's `SerializedHistory`, marked with the scene's recorded form).\n * An entry holds the scene's own ops, whichever way the edit was made.\n * An op handed to `applyBatch` that wrote no scene state is held as\n * itself, and an entry with a nameless one is dropped. Payload\n * JSON-safety (e.g. typed arrays inside poses) is the caller's concern.\n * Do not call mid-`batch` — the open batch's ops are not yet recorded. */\n serializeHistory(): SerializedSceneHistory;\n /** Replace the undo/redo history from a `serializeHistory()` snapshot.\n * Call on a scene whose node/layer state already matches the snapshot's\n * head state (i.e. right after `loadState` from the paired scene\n * snapshot); node state is NOT mutated. Ops re-registered via\n * `registerOp` before this call round-trip; unknown kinds become no-op\n * placeholders; external ops rebuild via the global op-factory registry\n * and replay against the `setHistoryAdapter` accessor. Restored entries\n * never coalesce with new ones. Notifies once. A snapshot that is not in\n * the current recorded form (see `SCENE_HISTORY_FORM`) is dropped:\n * the history is left as it was. Do not call mid-`batch`:\n * the stacks are replaced underneath the open batch, whose eventual\n * flush would graft onto (and evict against) the restored stacks. */\n restoreHistory(snapshot: SerializedHistory): void;\n /** Install (or clear with `null`) the accessor for the adapter that\n * RESTORED external ops apply against on undo/redo: the ops handed to\n * `applyBatch` that wrote no scene state, such as a selection change,\n * rebuilt from a `restoreHistory` snapshot. Resolved lazily at each\n * apply, so wiring order relative to `restoreHistory` doesn't matter.\n * Live `applyBatch` entries are unaffected (they bind their call-site\n * adapter). If unset when a restored op applies, the op is a debug-warned\n * no-op. */\n setHistoryAdapter(fn: (() => unknown) | null): void;\n\n // Serialization\n /** Snapshot the current scene state to a JSON-serializable shape.\n * History (undo/redo stacks) is NOT captured. Function fields like\n * `ContainerNode.clipFromPose` are translated to string keys via the\n * scene's registry; throws if any function field has no matching key. */\n toJSON(): SerializedScene<TData, TLayer, TPose>;\n /** Replace this scene's entire node + layer state in place from a snapshot\n * produced by `toJSON()`. Unlike `sceneFromJSON`, the existing Scene\n * instance is preserved — holders such as `<SceneCanvas>` keep their\n * reference. History (undo/redo) is cleared, matching `sceneFromJSON`.\n * Bumps `getVersion()` and notifies subscribers exactly once. Selected\n * ids the snapshot does not hold leave the selection, and every pose\n * override is cleared.\n *\n * Throws inside any other edit — `batch`, `untracked`, `applyBatch`, an\n * undo — which would revert to a state this replaces. Throws on an unsupported version or unknown registry/layer ids; on a\n * malformed snapshot the scene is left empty or partially populated (callers should treat a\n * `loadState` throw as fatal and reload). Snapshots from `toJSON()` are\n * always well-formed. */\n loadState(json: SerializedScene<TData, TLayer, TPose>): void;\n\n // Subscription (used by useScene; also for non-React observers)\n subscribe(listener: () => void): () => void;\n /** Monotonically increasing version. Snapshot for `useSyncExternalStore`. */\n getVersion(): number;\n}\n"],"mappings":";;AAiDA,IAAa,YAAY,MAAsB"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/core/scene/types.ts"],"sourcesContent":["import type { History, SerializedHistory } from '@weasel-js/history';\nimport type { SerializedSceneHistory } from './historyForm';\nimport type { ParallaxOpts } from '../viewport/parallax';\nimport type { UnitScope } from '@weasel-js/quantity';\nimport type { LayoutStrategy } from '../../layout/types';\nimport type { AddLayerSpec, LayerRecord, SystemLayerRecord, SystemLayerSpec, UserLayerRecord } from './layerTypes';\nimport type { LayoutFrame, LayoutMove } from './layoutTypes';\nimport type { PoseComposition } from './composeFrame';\nimport type { PoseRemoval, PoseWrite, PoseWriteOrigin, RemovedNode, ScenePoseReports } from './poseWrites';\nimport type { PoseHold, PoseOverride, PoseOverrides } from './poseOverrideTypes';\nimport type { SceneChanges } from './sceneChanges';\nimport type { SerializedLayer, SerializedNode, SerializedScene } from './serializedTypes';\nimport type { UseSceneOptions } from './useSceneOptions';\nimport type { SceneDocValues } from './docValues';\nimport type { SceneEditPasses } from './editPass';\nimport type { RectPose } from '../geometry/rectPose';\nexport type { RectPose, UseSceneOptions };\nexport type { AddLayerSpec, LayerRecord, SystemLayerRecord, SystemLayerSpec, UserLayerRecord };\nexport type { PoseRemoval, PoseWrite, PoseWriteOrigin, RemovedNode, ScenePoseReports };\nexport type { LayoutFrame, LayoutMove, PoseHold, PoseOverride, PoseOverrides, SerializedLayer, SerializedNode, SerializedScene };\n\n/**\n * # SceneNode — the thing in the scene\n *\n * Everything the user sees on the canvas — a shape, a group, an annotation,\n * a tile — is a node. Containers and leaves are both nodes; the kit has no\n * other concept of \"scene element.\"\n *\n * Every node carries three independent slots, plus its tree position:\n *\n * - **`data: TData`** — app-defined payload. The kit never inspects it.\n * - **`pose: TPose`** — local transform, relative to the node's direct\n * parent (or world, for root nodes).\n * - **`layer: TLayer`** — a string tag associating the node with a\n * visual `RenderLayer` at draw time. Separate from `LayerRecord` (the\n * per-layer visible/locked metadata held by the `Scene`).\n *\n * Nodes are addressed by `NodeId` everywhere outside the scene tree. Don't\n * hold references to a `Node` object across scene updates; look up by id\n * when you need the latest.\n *\n * The kit-internal name is `Node`; the public re-export is `SceneNode`\n * (avoids collision with DOM `Node` at call sites).\n */\n\n/** Opaque branded id. Treat as opaque outside the kit. */\nimport type { NodeId } from '@weasel-js/routing';\nexport type { NodeId };\n\n/** Brand a string as a NodeId. */\nexport const asNodeId = (s: string): NodeId => s as NodeId;\n\nimport type { DerivedDep, Bivariant, DerivePathFn, DerivePoseFn, ClipFromPoseFn, CopiesFromPoseFn } from './nodeFnTypes';\nexport type { DerivedDep, Bivariant, DerivePathFn, DerivePoseFn, ClipFromPoseFn, CopiesFromPoseFn };\n\ninterface NodeBase<TData, TLayer extends string, TPose> {\n id: NodeId;\n layer: TLayer;\n pose: TPose;\n data: TData;\n parent: NodeId | null;\n /** Nodes whose poses this node's geometry is computed from. Fixed at add\n * time. Absent or empty means the node's geometry is authored, which is the\n * normal case.\n *\n * `'children'` means \"my own children, in child order\" — a container that\n * hugs its contents, which a fixed id list cannot express because\n * reparenting would have to maintain it. The two forms differ in lifetime\n * as well as in membership: deleting a node deletes everything that names\n * it in `dependsOn`, but a container outlives the children it derives\n * from — an emptied group is still a group. */\n dependsOn?: readonly NodeId[] | 'children';\n /** Whether the hit-test walk can return this node. Default `true`; `false`\n * makes it transparent to picking, so a click on it lands on whatever is\n * behind — normally its own container.\n *\n * For content a container owns rather than content the user selects on its\n * own: the label inside a box, a body's rows. It does not hide the node\n * from anything else — it still paints, still clips, and a consumer can\n * still select it by id. */\n pickable?: boolean;\n /** Not drawn, with its whole subtree: picking, area selection, select-all,\n * snapping and the selection pass over it, and an SVG export writes it with\n * `display=\"none\"`. Absent means shown; `Scene.isHidden` folds in its\n * ancestors' flags and its layer's visibility. */\n hidden?: boolean;\n /** Out of reach, with its whole subtree: still drawn, but picking and area\n * selection pass over it, the selection drops it, and every edit to it\n * throws, as on a locked layer. Absent means unlocked; `Scene.isLocked`\n * folds in its ancestors' and its layer's. */\n locked?: boolean;\n /** Computes this node's path from its dependencies, in `dependsOn` order —\n * each one the node and the pose it is painted at.\n * A dependency that has been removed arrives as `undefined`.\n * Returning `null` means \"nothing to draw right now\". Re-evaluated when a\n * dependency's world pose changes, never authored. */\n derivePath?: DerivePathFn<TPose, TData, TLayer>;\n /** Computes this node's pose from its dependencies' poses, the same way\n * `derivePath` computes its path — same `dependsOn` list, same\n * registry-keyed serialization.\n *\n * Where a derived path is resolved at paint time and reaches only the\n * painter, a derived pose is what the node *is* at: it feeds bounds,\n * hit-testing, selection chrome, snapping and layout, and every reader\n * gets it through `effectivePose`. A pose override still wins over it.\n *\n * Returning `null` means \"I have nothing to derive from right now\", and\n * the node falls back to its authored `pose`. `setPose` on a derived node\n * still writes that authored pose; it is simply not what anything reads. */\n derivePose?: DerivePoseFn<TPose, TData, TLayer>;\n}\n\n/** A node with no children — a shape, a label, an image. */\nexport interface LeafNode<TData, TLayer extends string, TPose = RectPose>\n extends NodeBase<TData, TLayer, TPose> {\n kind: 'leaf';\n}\n\n/** A node with an ordered list of children. This is the real group: what\n * Cmd+G creates, what SVG `<g>` round-trips to. A container has its own pose,\n * which its children's poses are relative to, and may optionally clip them. */\nexport interface ContainerNode<TData, TLayer extends string, TPose = RectPose>\n extends NodeBase<TData, TLayer, TPose> {\n kind: 'container';\n children: NodeId[];\n /** Optional clip-path source. Re-evaluated each render. Returning `null`\n * means \"no clip for this container right now\"; an empty / zero-area path\n * means \"clip everything out\" (children render nowhere). */\n clipFromPose?: ClipFromPoseFn<TPose>;\n /** Draws the whole subtree again under each affine it returns, on top of\n * the original, which still draws once as authored. The copies are paint,\n * not nodes: nothing stores them, so they follow every edit to the\n * children, and a pick that lands on one answers with the child it copies.\n * A copy is a copy of the clipped content — the clip travels with it.\n * Re-evaluated each render; `null` or `[]` draws no copies. */\n copiesFromPose?: CopiesFromPoseFn<TPose, TData, TLayer>;\n /** How this container arranges its children. Whenever the container's\n * child set or order changes, its bounds change size, or a child's pose is\n * written, the scene hands the change to the strategy — `depart` for children that left it,\n * `arrive` for children that joined it, `childPoses` otherwise — and records the poses it writes in the same\n * undo entry as the change. A drag reads it too: it is the layout `move`\n * reflows and drops against. */\n layout?: LayoutStrategy<TPose>;\n /** The units its children are shown, typed and snapped in (their poses stay\n * in world units), and what one base unit is worth in the enclosing scope's.\n * It covers the children, not the container; `sceneUnitScopes` reads the chain. */\n units?: UnitScope;\n}\n\n/** A node in the scene tree: either a leaf or a container. Re-exported\n * publicly as `SceneNode`, to avoid colliding with the DOM's `Node`. */\nexport type Node<TData, TLayer extends string, TPose = RectPose> =\n | LeafNode<TData, TLayer, TPose>\n | ContainerNode<TData, TLayer, TPose>;\n\n/** What `Scene.add` needs to mint a node. Everything except the id is\n * required; the id is generated unless one is supplied. */\nexport interface AddNodeSpec<TData, TLayer extends string, TPose = RectPose> {\n kind: 'leaf' | 'container';\n layer: TLayer;\n pose: TPose;\n data: TData;\n parent?: NodeId | null;\n index?: number;\n /** Explicit id wins over the Scene's `generateId` and the kit default. */\n id?: NodeId;\n /** Mirrors `SceneNode.pickable`. Omit for the default, which is pickable. */\n pickable?: boolean;\n /** Mirrors `SceneNode.hidden`. */\n hidden?: boolean;\n /** Mirrors `SceneNode.locked`. */\n locked?: boolean;\n /** Only meaningful when `kind === 'container'`. Attach a clip-path function\n * to the node; ignored for leaves. Mirrors `ContainerNode.clipFromPose`. */\n clipFromPose?: ClipFromPoseFn<TPose>;\n /** Mirrors `ContainerNode.copiesFromPose`; ignored for leaves. */\n copiesFromPose?: CopiesFromPoseFn<TPose, TData, TLayer>;\n /** Mirrors `SceneNode.dependsOn`. */\n dependsOn?: readonly NodeId[] | 'children';\n /** Mirrors `SceneNode.derivePath`. Taken as a live function; its registry key is\n * looked up from it, never passed in. */\n derivePath?: DerivePathFn<TPose, TData, TLayer>;\n /** Mirrors `SceneNode.derivePose`, on the same terms as `derivePath`. */\n derivePose?: DerivePoseFn<TPose, TData, TLayer>;\n /** Mirrors `ContainerNode.layout`; ignored for leaves. */\n layout?: LayoutStrategy<TPose>;\n /** Mirrors `ContainerNode.units`; ignored for leaves. */\n units?: UnitScope;\n}\n\n/** A custom scene mutation registered with `Scene.registerOp`: how to apply\n * it and how to undo it. The pair is what makes it participate in history. */\nexport interface RegisteredOp<P> {\n apply: (payload: P) => void;\n revert: (payload: P) => void;\n /** Opts this kind into coalescing under `UseSceneOptions.coalesceWindowMs`:\n * two entries of this kind that return the same key inside the window\n * merge, and undoing the merged entry calls `revert` with the first\n * payload only. Declare it only when `revert` restores an absolute state\n * (a stored \"from\" value), never for a relative payload such as a delta.\n * Omitted, or returning `undefined`, the op is always its own entry. */\n coalesceKey?: (payload: P) => string | undefined;\n}\n\n/** Per-scene registry mapping string keys to live function references.\n * Passed to `createScene({ ..., registry })` and `sceneFromJSON(json, { registry })`.\n * Each function-field type has its own keyed map. */\nexport interface SceneRegistry<TPose, TData = unknown, TLayer extends string = string> {\n /** Maps registry keys to `clipFromPose` factory functions for container nodes. */\n clipFromPose?: Readonly<Record<string, ClipFromPoseFn<TPose>>>;\n /** Maps registry keys to `copiesFromPose` functions for container nodes. */\n copiesFromPose?: Readonly<Record<string, CopiesFromPoseFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to `derivePath` functions for nodes with `dependsOn`. */\n derivePath?: Readonly<Record<string, DerivePathFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to `derivePose` functions for nodes with `dependsOn`. */\n derivePose?: Readonly<Record<string, DerivePoseFn<TPose, TData, TLayer>>>;\n /** Maps registry keys to container layout strategies. */\n layout?: Readonly<Record<string, LayoutStrategy<TPose>>>;\n // A new function field is a row in `NODE_FN_FIELDS` (core/scene/nodeFnFields.ts)\n // plus its entry here; the field name is the registry key by construction.\n}\n\n/**\n * Decides what one edit's changes to containers do to their children.\n * `arrivals` maps each container to the ids that joined it — by an `add`\n * under it or a `move` into it, whatever op or call made them — in the order\n * they arrived. `changed` names every container whose child set or order\n * changed, whose pose changed size, or one of whose children was posed,\n * arrivals included. Both are read once the edit's other mutations have landed.\n *\n * Return the poses to write, in each node's stored frame; they become part of\n * the same edit, and so of the same undo step. An empty map writes nothing.\n * Return `null` to refuse: the whole edit is reverted (see\n * `SceneArrivalRefused`).\n *\n * Runs only for live edits. Undo, redo and a restored history replay the\n * arrangement that was decided the first time. With none installed, a scene\n * holding declared layouts (`ContainerNode.layout`) runs its own.\n */\nexport type SceneArrivalHandler<TPose> = (\n arrivals: ReadonlyMap<NodeId, readonly NodeId[]>,\n changed: ReadonlySet<NodeId>,\n /** The nodes that left each container in the edit, by the container they\n * left — removed, or moved out. */\n departures: ReadonlyMap<NodeId, readonly NodeId[]>,\n) => ReadonlyMap<NodeId, TPose> | null;\n\n/**\n * The kit-owned scene tree: nodes, layers, and the undo history over both.\n *\n * A scene is logical, not visual — it says what exists and where, and nothing\n * about how it is painted. Every mutating method is undoable, and reads are\n * snapshots rather than live views. Nodes are addressed by `NodeId`; hold ids\n * across mutations, not node objects.\n *\n * Three type parameters keep it domain-agnostic: `TData` is the app's payload,\n * which the kit never inspects; `TPose` is the transform shape, `RectPose` by\n * default; `TLayer` is the union of layer names.\n */\nexport interface Scene<TData, TLayer extends string, TPose = RectPose>\n extends ScenePoseReports<TPose, Node<TData, TLayer, TPose>>, SceneChanges, SceneDocValues, SceneEditPasses {\n // Reads\n readonly nodes: ReadonlyMap<NodeId, Node<TData, TLayer, TPose>>;\n readonly roots: readonly NodeId[];\n readonly layers: readonly LayerRecord<TLayer>[];\n /** The registry this scene resolves node functions against — the consumer's\n * entries over the kit's. */\n readonly registry: SceneRegistry<TPose, TData, TLayer>;\n /** See {@link UseSceneOptions.composition}. */\n readonly composition: PoseComposition<TPose>;\n get(id: NodeId): Node<TData, TLayer, TPose> | undefined;\n /** A token for the node `id` names right now, for telling one node from a\n * later one that reuses its id. It holds for as long as the node stays in\n * the scene, whatever edits it takes, and is different every time the id\n * enters the scene — by `add`, by an undo or redo that brings it back, or\n * by `loadState`. `undefined` when `id` is not in the scene. Compare tokens\n * for equality only; their order means nothing. */\n incarnation(id: NodeId): number | undefined;\n childrenOf(id: NodeId): readonly NodeId[];\n ancestorsOf(id: NodeId): readonly NodeId[];\n renderOrder(): Iterable<NodeId>;\n /** The same layer-major sequence as {@link Scene.renderOrder}, as the nodes\n * themselves. Prefer this wherever the ids are only going to be resolved\n * back to nodes. Cached until a structural edit, so repeat calls hand back\n * the same array — a snapshot, not a live view, and not yours to mutate. */\n renderOrderNodes(): readonly Node<TData, TLayer, TPose>[];\n /** The nodes on one layer, in render order. Cached alongside\n * {@link Scene.renderOrderNodes} until a structural edit. A snapshot, not\n * a live view, and not yours to mutate. An unknown layer id yields an\n * empty array. */\n nodesOnLayer(layer: TLayer): readonly Node<TData, TLayer, TPose>[];\n\n /** A fresh id from this scene's `generateId`, or the kit default: the id\n * `add` would give a spec with none. For code that has to name a node\n * before it exists, such as one building an insert op. */\n mintId(): NodeId;\n\n // Mutations (all auto-undoable)\n add(spec: AddNodeSpec<TData, TLayer, TPose>): NodeId;\n /** Delete `id`, its **entire subtree**, and **everything that derives from**\n * any of those nodes — a node listing one of them in `dependsOn` goes too,\n * along with its own subtree, transitively. A dependent can live anywhere in\n * the tree, so this deletes nodes the caller never named and may unlink\n * several disjoint subtrees at once. Recorded as one undoable step; `undo()`\n * restores every one of them where it was, child order intact. */\n remove(id: NodeId): void;\n /** {@link remove} over several roots at once, as a **single** undoable step.\n * Ids resolve against the tree as it stands at the call, so an id that\n * another one would cascade away is absorbed rather than removed twice —\n * which is what makes it safe to pass a whole selection. Throws if any id is\n * not in the scene; an empty list does nothing and records no step. */\n removeMany(ids: readonly NodeId[]): void;\n /** Every node {@link removeMany} would take if given `ids`: each id, its\n * subtree, everything deriving from any of those, and those nodes' subtrees\n * in turn. Ids not in the scene come back unchanged.\n *\n * A set, not a restore order: a dependent can be reached before the parent\n * it sits under, which is also in the closure. */\n removalClosure(ids: readonly NodeId[]): readonly NodeId[];\n update(id: NodeId, patch: { data: TData }): void;\n setPose(id: NodeId, pose: TPose): void;\n /** Retag `id` to `layer`. On a **container this cascades**: every descendant\n * is moved to the same layer, recorded as a **single** undo step.\n *\n * Invariants:\n * - **Layer floor** — a child may not render below its parent, so retagging\n * to a layer *below* the node's parent throws. Retagging to the parent's\n * layer or any higher one is allowed; a node with no parent is\n * unconstrained.\n * - **No-op elision** — setting the layer a node already has does nothing\n * and pushes **no** history entry. */\n setLayer(id: NodeId, layer: TLayer): void;\n /** Point `id` at a different set of dependencies — retargeting an edge's end\n * onto another node, or switching a container between an id list and\n * `'children'`. Recorded as one undoable step.\n *\n * Order is significant: a derivation reads its dependencies positionally,\n * so `[b, a]` is not `[a, b]`. Ids need not be in the scene — a declared\n * dependency that appears later invalidates the node when it does, the same\n * as one declared at `add`. Passing `undefined` drops the declaration, after\n * which nothing cascades the node away.\n *\n * **No-op elision** — declaring what the node already declares does nothing\n * and pushes no history entry. */\n setDependsOn(id: NodeId, dependsOn: readonly NodeId[] | 'children' | undefined): void;\n /** Give container `id` a different layout — a strategy, its key in\n * `SceneRegistry.layout`, or `null` for none — and re-arrange its children\n * under it, as one undoable step. Throws for a leaf, or a key the registry\n * does not hold. A registered layout is recorded by its key, so a\n * serialized history restores it; an unregistered one lives only as long\n * as the session.\n *\n * **No-op elision** — setting the layout a container already has does\n * nothing and pushes no history entry. */\n setLayout(id: NodeId, layout: LayoutStrategy<TPose> | string | null): void;\n /** Reparent `id` under `parent` (or to a root when `parent` is `null`) at\n * `index` within the new sibling list, appending when `index` is omitted.\n * Siblings are reindexed. Recorded as one undoable step.\n *\n * Rejected (throws) when:\n * - `parent` exists but is a **leaf**, not a container;\n * - the move would form a **cycle** — `parent` is `id` itself or one of\n * `id`'s own descendants;\n * - it would drop `id` **below its new parent's layer** (child may not\n * render below its parent).\n *\n * `move(id, null)` — detaching to a root — is always allowed regardless of\n * layer, since a root has no parent to render beneath. */\n move(id: NodeId, parent: NodeId | null, index?: number): void;\n /** Shift `id` to `index` within its **current** parent's child list. Unlike\n * {@link move}, the parent never changes — only sibling order. */\n reorder(id: NodeId, index: number): void;\n /** Show or hide a layer. Hiding drops its nodes from the selection. */\n setLayerVisible(layer: TLayer, visible: boolean): void;\n /** Lock or unlock a layer. A locked layer still paints, but its nodes are\n * out of reach: picking and area selection pass over them, the selection\n * drops them, and every node mutation on them throws. Locking is never\n * blocked by the lock, and neither are the other layer operations. */\n setLayerLocked(layer: TLayer, locked: boolean): void;\n /** Set or clear (`undefined`) a layer's parallax — see\n * `LayerRecord.parallax`. Undoable; an animation tweening it writes inside\n * {@link Scene.untracked} so no frame becomes an undo step. */\n setLayerParallax(layer: TLayer, parallax: ParallaxOpts | undefined): void;\n /** Whether `id` is locked: it or an ancestor carries `locked`, or sits on a\n * locked layer. A lock covers its whole subtree, whatever layers the\n * descendants are tagged to. An id not in the scene is not locked. */\n isLocked(id: NodeId): boolean;\n /** Whether `id` is not drawn: its own layer is hidden, or it or an ancestor\n * carries `hidden`. A hidden layer hides only the nodes tagged to it. An\n * id not in the scene is not hidden. */\n isHidden(id: NodeId): boolean;\n /** Hide or show node `id` and its subtree — see `SceneNode.hidden`. One\n * undo step; hiding drops the subtree from the selection. Never blocked by\n * a lock, and setting what the node already has records nothing. */\n setHidden(id: NodeId, hidden: boolean): void;\n /** Lock or unlock node `id` and its subtree — see `SceneNode.locked`. One\n * undo step; locking drops the subtree from the selection. Never blocked\n * by a lock, and setting what the node already has records nothing. */\n setLocked(id: NodeId, locked: boolean): void;\n /** Run `fn` with the lock guard lifted, for a programmatic edit that has to\n * reach a locked node. Undo and redo never need it. */\n unlocked<T>(fn: () => T): T;\n addLayer(spec: AddLayerSpec<TLayer>): void;\n /** Drop a user layer and every node tagged to it, as one undoable step.\n * Removal cascades, so this also deletes nodes **on other layers** that\n * derive from a node on this one. */\n removeLayer(layer: TLayer): void;\n renameLayer(layer: TLayer, name: string): void;\n moveLayer(layer: TLayer, index: number): void;\n\n // Custom op seam\n registerOp<P>(kind: string, handler: RegisteredOp<P>): void;\n recordOp<P>(op: { kind: string; payload: P }): void;\n\n /** Install (or clear with `null`) the active-journal accessor after scene\n * construction, for a journal source built with `scene.history` as a\n * dependency. Overrides any `getActiveJournal` set in `UseSceneOptions`. */\n setActiveJournalAccessor(\n fn: (() => import('@weasel-js/history').Journal | null) | null,\n ): void;\n\n /** Install what the scene does when nodes join a container, replacing any\n * handler installed before; `null` removes it. Returns a function that\n * removes this handler, and does nothing once another has replaced it.\n * See {@link SceneArrivalHandler}. */\n setArrivalHandler(handler: SceneArrivalHandler<TPose> | null): () => void;\n\n /** Apply a batch of ops against `adapter` as one undo entry.\n *\n * The entry holds the scene writes the ops made, as a direct call records\n * them, and beside them any op that wrote no scene state, bound to\n * `adapter`. Undo restores those writes; it does not call an op's\n * `invert()` or the adapter again. **What an op states is not recorded**:\n * one applied over a document that already holds its result, as after an\n * `untracked` preview, records a write from that pose to itself, and undo\n * goes nowhere. Put the document back first.\n *\n * The entry lands in the open `batch` when there is one, else on the\n * active journal, else on the scene's own history, where it can coalesce\n * under `coalesceWindowMs` with one whose ops' keys match.\n *\n * Returns false when the arrival handler refused the batch: it is reverted\n * and unrecorded. Inside `batch` it is true; that batch may still refuse. */\n applyBatch(ops: import('core/ops/types').Op[], label: string, adapter: unknown): boolean;\n\n // Selection\n\n /** The transient set of active ids — \"operate on these N as a unit\".\n * Shared by every view over this scene unless a view supplies its own\n * (see `CanvasView.selection`). Not document content: it never appears\n * in `toJSON`. It does ride on history entries, so undo and redo put\n * back the selection an edit was made under; changing it is never an\n * undo step of its own. Removing a node deselects it. */\n getSelection(): readonly NodeId[];\n setSelection(ids: readonly NodeId[]): void;\n\n // Ephemeral presentation state\n\n /** Per-node pose / alpha overrides the render and hit-test paths read\n * through. Like {@link Scene.getSelection} this is not document content:\n * writes are never recorded, never serialized, and do not bump\n * {@link Scene.getVersion}. See {@link PoseOverrides}. */\n readonly overrides: PoseOverrides<TPose>;\n\n // History\n /** The scene's undo/redo engine, in the shape `@weasel-js/history` defines.\n * Mutating members route through\n * the scene's own wrappers, so an undo driven through this bumps\n * {@link Scene.getVersion} and notifies subscribers exactly as\n * {@link Scene.undo} does; `getVersion` / `subscribe` on it report the\n * engine's history version, not the scene's. */\n readonly history: History;\n undo(): boolean;\n redo(): boolean;\n canUndo(): boolean;\n canRedo(): boolean;\n batch<T>(label: string, fn: () => T, options?: import('./recorder').SceneBatchOptions): T;\n /** The layout container `id` declares, or `null` for a leaf or a\n * container that declares none. */\n layoutOf(id: NodeId): LayoutStrategy<TPose> | null;\n /** Declare the unit scope of container `id`, or clear it with `null`. */\n setUnits(id: NodeId, units: UnitScope | null): void;\n /** Run `fn` with every mutation applied but none recorded — for writes\n * that are not edits, such as a simulation stepping poses each frame.\n * Undo and redo move between recorded states and never restore an\n * untracked write; the next recorded change starts from whatever the\n * untracked writes left, so undoing it lands there. A `batch` inside\n * records nothing; inside a `batch`, these writes stay out of its entry.\n * Notifies once, reverts `fn`'s writes if it throws, and throws on\n * `applyBatch` and `history.apply` / `applyOps`, which exist to record. */\n untracked<T>(fn: () => T): T;\n /** Read-only snapshot of every history entry currently reachable from\n * the present state. Oldest applied first, then redoable entries in\n * the order they'd be re-applied. Each entry id is stable. */\n historyEntries(): readonly { id: string; label: string }[];\n /** Index of the \"current state\". Equals the count of applied entries;\n * `0` means \"nothing applied\" (initial). */\n historyIndex(): number;\n /** Jump to the given history index, clamped to [0, total]. Returns true\n * if any movement occurred. */\n jumpToHistoryIndex(index: number): boolean;\n\n // History persistence\n /** Snapshot the undo/redo history in a JSON-serializable form (the\n * engine's `SerializedHistory`, marked with the scene's recorded form).\n * An entry holds the scene's own ops, whichever way the edit was made.\n * An op handed to `applyBatch` that wrote no scene state is held as\n * itself, and an entry with a nameless one is dropped. Payload\n * JSON-safety (e.g. typed arrays inside poses) is the caller's concern.\n * Do not call mid-`batch` — the open batch's ops are not yet recorded. */\n serializeHistory(): SerializedSceneHistory;\n /** Replace the undo/redo history from a `serializeHistory()` snapshot.\n * Call on a scene whose node/layer state already matches the snapshot's\n * head state (i.e. right after `loadState` from the paired scene\n * snapshot); node state is NOT mutated. Ops re-registered via\n * `registerOp` before this call round-trip; unknown kinds become no-op\n * placeholders; external ops rebuild via the global op-factory registry\n * and replay against the `setHistoryAdapter` accessor. Restored entries\n * never coalesce with new ones. Notifies once. A snapshot that is not in\n * the current recorded form (see `SCENE_HISTORY_FORM`) is dropped:\n * the history is left as it was. Do not call mid-`batch`:\n * the stacks are replaced underneath the open batch, whose eventual\n * flush would graft onto (and evict against) the restored stacks. */\n restoreHistory(snapshot: SerializedHistory): void;\n /** Install (or clear with `null`) the accessor for the adapter that\n * RESTORED external ops apply against on undo/redo: the ops handed to\n * `applyBatch` that wrote no scene state, such as a selection change,\n * rebuilt from a `restoreHistory` snapshot. Resolved lazily at each\n * apply, so wiring order relative to `restoreHistory` doesn't matter.\n * Live `applyBatch` entries are unaffected (they bind their call-site\n * adapter). If unset when a restored op applies, the op is a debug-warned\n * no-op. */\n setHistoryAdapter(fn: (() => unknown) | null): void;\n\n // Serialization\n /** Snapshot the current scene state to a JSON-serializable shape.\n * History (undo/redo stacks) is NOT captured. Function fields like\n * `ContainerNode.clipFromPose` are translated to string keys via the\n * scene's registry; throws if any function field has no matching key. */\n toJSON(): SerializedScene<TData, TLayer, TPose>;\n /** Replace this scene's entire node + layer state in place from a snapshot\n * produced by `toJSON()`. Unlike `sceneFromJSON`, the existing Scene\n * instance is preserved — holders such as `<SceneCanvas>` keep their\n * reference. History (undo/redo) is cleared, matching `sceneFromJSON`.\n * Bumps `getVersion()` and notifies subscribers exactly once. Selected\n * ids the snapshot does not hold leave the selection, and every pose\n * override is cleared.\n *\n * Throws inside any other edit — `batch`, `untracked`, `applyBatch`, an\n * undo — which would revert to a state this replaces. Throws on an unsupported version or unknown registry/layer ids; on a\n * malformed snapshot the scene is left empty or partially populated (callers should treat a\n * `loadState` throw as fatal and reload). Snapshots from `toJSON()` are\n * always well-formed. */\n loadState(json: SerializedScene<TData, TLayer, TPose>): void;\n\n}\n"],"mappings":";;AAkDA,IAAa,YAAY,MAAsB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deepEqual } from "@weasel-js/registry";
|
|
1
2
|
import { scopesOf } from "@weasel-js/quantity";
|
|
2
3
|
|
|
3
4
|
//#region src/core/scene/unitScopes.ts
|
|
@@ -14,7 +15,24 @@ function sceneUnitScopes(scene, id, root, opts = {}) {
|
|
|
14
15
|
...opts.inclusive ? { inclusive: true } : {}
|
|
15
16
|
});
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The unit scopes every node of `ids` sits in, outermost first: the run of
|
|
20
|
+
* their chains that agree, where two containers declaring equal scopes
|
|
21
|
+
* agree. What a reader showing or snapping several nodes as one reads them
|
|
22
|
+
* in; the root alone for no nodes.
|
|
23
|
+
*/
|
|
24
|
+
function sceneSharedUnitScopes(scene, ids, root) {
|
|
25
|
+
if (ids.length === 0) return [root];
|
|
26
|
+
let shared = sceneUnitScopes(scene, ids[0], root);
|
|
27
|
+
for (const id of ids.slice(1)) {
|
|
28
|
+
const chain = sceneUnitScopes(scene, id, root);
|
|
29
|
+
let n = 0;
|
|
30
|
+
while (n < shared.length && n < chain.length && deepEqual(shared[n], chain[n])) n++;
|
|
31
|
+
shared = shared.slice(0, n);
|
|
32
|
+
}
|
|
33
|
+
return shared;
|
|
34
|
+
}
|
|
17
35
|
|
|
18
36
|
//#endregion
|
|
19
|
-
export { sceneUnitScopes };
|
|
37
|
+
export { sceneSharedUnitScopes, sceneUnitScopes };
|
|
20
38
|
//# sourceMappingURL=unitScopes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unitScopes.js","names":[],"sources":["../../../src/core/scene/unitScopes.ts"],"sourcesContent":["import { scopesOf, type UnitScope } from '@weasel-js/quantity';\nimport type { NodeId } from './types';\n\n/** What reading scopes needs of a scene. A `Scene` satisfies it. */\nexport interface ScopedScene {\n get(id: NodeId): { kind: string; parent: NodeId | null; units?: UnitScope } | undefined;\n}\n\n/**\n * The unit scopes enclosing node `id`, outermost first, under the scene's own\n * `root`: what `resolveScoped` and `formatScoped` take for a value that\n * positions or sizes it. A container's own scope covers its children, so it\n * is counted only under `inclusive`, for a value written inside it.\n */\nexport function sceneUnitScopes(\n scene: ScopedScene,\n id: NodeId,\n root: UnitScope,\n opts: { inclusive?: boolean } = {},\n): UnitScope[] {\n return scopesOf(id, root, {\n parentOf: (at) => scene.get(at)?.parent,\n scopeOf: (at) => scene.get(at)?.units,\n ...(opts.inclusive ? { inclusive: true } : {}),\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"unitScopes.js","names":[],"sources":["../../../src/core/scene/unitScopes.ts"],"sourcesContent":["import { scopesOf, type UnitScope } from '@weasel-js/quantity';\nimport { deepEqual } from '@weasel-js/registry';\nimport type { NodeId } from './types';\n\n/** What reading scopes needs of a scene. A `Scene` satisfies it. */\nexport interface ScopedScene {\n get(id: NodeId): { kind: string; parent: NodeId | null; units?: UnitScope } | undefined;\n}\n\n/**\n * The unit scopes enclosing node `id`, outermost first, under the scene's own\n * `root`: what `resolveScoped` and `formatScoped` take for a value that\n * positions or sizes it. A container's own scope covers its children, so it\n * is counted only under `inclusive`, for a value written inside it.\n */\nexport function sceneUnitScopes(\n scene: ScopedScene,\n id: NodeId,\n root: UnitScope,\n opts: { inclusive?: boolean } = {},\n): UnitScope[] {\n return scopesOf(id, root, {\n parentOf: (at) => scene.get(at)?.parent,\n scopeOf: (at) => scene.get(at)?.units,\n ...(opts.inclusive ? { inclusive: true } : {}),\n });\n}\n\n/**\n * The unit scopes every node of `ids` sits in, outermost first: the run of\n * their chains that agree, where two containers declaring equal scopes\n * agree. What a reader showing or snapping several nodes as one reads them\n * in; the root alone for no nodes.\n */\nexport function sceneSharedUnitScopes(scene: ScopedScene, ids: readonly NodeId[], root: UnitScope): UnitScope[] {\n if (ids.length === 0) return [root];\n let shared = sceneUnitScopes(scene, ids[0]!, root);\n for (const id of ids.slice(1)) {\n const chain = sceneUnitScopes(scene, id, root);\n let n = 0;\n while (n < shared.length && n < chain.length && deepEqual(shared[n], chain[n])) n++;\n shared = shared.slice(0, n);\n }\n return shared;\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,gBACd,OACA,IACA,MACA,OAAgC,CAAC,GACpB;CACb,OAAO,SAAS,IAAI,MAAM;EACxB,WAAW,OAAO,MAAM,IAAI,EAAE,CAAC,EAAE;EACjC,UAAU,OAAO,MAAM,IAAI,EAAE,CAAC,EAAE;EAChC,GAAI,KAAK,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;CAC9C,CAAC;AACH;;;;;;;AAQA,SAAgB,sBAAsB,OAAoB,KAAwB,MAA8B;CAC9G,IAAI,IAAI,WAAW,GAAG,OAAO,CAAC,IAAI;CAClC,IAAI,SAAS,gBAAgB,OAAO,IAAI,IAAK,IAAI;CACjD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,GAAG;EAC7B,MAAM,QAAQ,gBAAgB,OAAO,IAAI,IAAI;EAC7C,IAAI,IAAI;EACR,OAAO,IAAI,OAAO,UAAU,IAAI,MAAM,UAAU,UAAU,OAAO,IAAI,MAAM,EAAE,GAAG;EAChF,SAAS,OAAO,MAAM,GAAG,CAAC;CAC5B;CACA,OAAO;AACT"}
|
|
@@ -2,28 +2,22 @@ import { useMemo } from "react";
|
|
|
2
2
|
import { usePublishSelection } from "@weasel-js/routing/react";
|
|
3
3
|
|
|
4
4
|
//#region src/core/selection/usePublishSceneSelection.ts
|
|
5
|
-
function defaultKindLabel(node) {
|
|
6
|
-
if (node.kind === "container") return "group";
|
|
7
|
-
const pose = node.pose;
|
|
8
|
-
if (pose && typeof pose === "object" && "kind" in pose && typeof pose.kind === "string") return "path";
|
|
9
|
-
}
|
|
10
5
|
/** The label published beside each selected id, parallel to `ids`; `undefined` when
|
|
11
|
-
* nothing is selected. `
|
|
12
|
-
function selectionKindLabels(scene, ids,
|
|
6
|
+
* nothing is selected. Without `describe`, every entry is unlabeled. */
|
|
7
|
+
function selectionKindLabels(scene, ids, describe) {
|
|
13
8
|
if (ids.length === 0) return void 0;
|
|
14
9
|
return ids.map((id) => {
|
|
15
10
|
const node = scene.get(id);
|
|
16
|
-
|
|
17
|
-
return describeKind ? describeKind(node) : defaultKindLabel(node);
|
|
11
|
+
return node && describe ? describe(node) : void 0;
|
|
18
12
|
});
|
|
19
13
|
}
|
|
20
14
|
/** Publishes a scene's selection, with a kind label per id, into any surrounding
|
|
21
15
|
* `<SelectionContextProvider>`. A no-op without one. */
|
|
22
|
-
function usePublishSceneSelection(scene, ids,
|
|
23
|
-
const kinds = useMemo(() => selectionKindLabels(scene, ids,
|
|
16
|
+
function usePublishSceneSelection(scene, ids, describe) {
|
|
17
|
+
const kinds = useMemo(() => selectionKindLabels(scene, ids, describe), [
|
|
24
18
|
scene,
|
|
25
19
|
ids,
|
|
26
|
-
|
|
20
|
+
describe
|
|
27
21
|
]);
|
|
28
22
|
usePublishSelection(ids, kinds);
|
|
29
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePublishSceneSelection.js","names":[],"sources":["../../../src/core/selection/usePublishSceneSelection.ts"],"sourcesContent":["import { usePublishSelection } from '@weasel-js/routing/react';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\nimport { useMemo } from 'react';\n\ntype KindLabel = string | undefined;\n\n
|
|
1
|
+
{"version":3,"file":"usePublishSceneSelection.js","names":[],"sources":["../../../src/core/selection/usePublishSceneSelection.ts"],"sourcesContent":["import { usePublishSelection } from '@weasel-js/routing/react';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\nimport { useMemo } from 'react';\n\ntype KindLabel = string | undefined;\n\n/** The label published beside each selected id, parallel to `ids`; `undefined` when\n * nothing is selected. Without `describe`, every entry is unlabeled. */\nexport function selectionKindLabels<TData, TLayer extends string, TPose>(\n scene: Pick<Scene<TData, TLayer, TPose>, 'get'>,\n ids: readonly NodeId[],\n describe?: (node: Node<TData, TLayer, TPose>) => KindLabel,\n): readonly KindLabel[] | undefined {\n if (ids.length === 0) return undefined;\n return ids.map((id) => {\n const node = scene.get(id);\n return node && describe ? describe(node) : undefined;\n });\n}\n\n/** Publishes a scene's selection, with a kind label per id, into any surrounding\n * `<SelectionContextProvider>`. A no-op without one. */\nexport function usePublishSceneSelection<TData, TLayer extends string, TPose>(\n scene: Pick<Scene<TData, TLayer, TPose>, 'get'>,\n ids: readonly NodeId[],\n describe?: (node: Node<TData, TLayer, TPose>) => KindLabel,\n): void {\n const kinds = useMemo(() => selectionKindLabels(scene, ids, describe), [scene, ids, describe]);\n usePublishSelection(ids, kinds);\n}\n"],"mappings":";;;;;;AAQA,SAAgB,oBACd,OACA,KACA,UACkC;CAClC,IAAI,IAAI,WAAW,GAAG,OAAO;CAC7B,OAAO,IAAI,KAAK,OAAO;EACrB,MAAM,OAAO,MAAM,IAAI,EAAE;EACzB,OAAO,QAAQ,WAAW,SAAS,IAAI,IAAI;CAC7C,CAAC;AACH;;;AAIA,SAAgB,yBACd,OACA,KACA,UACM;CACN,MAAM,QAAQ,cAAc,oBAAoB,OAAO,KAAK,QAAQ,GAAG;EAAC;EAAO;EAAK;CAAQ,CAAC;CAC7F,oBAAoB,KAAK,KAAK;AAChC"}
|