@weasel-js/core 1.11.1 → 1.13.0-rc.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 +275 -0
- package/dist/WeaselProvider.js +1 -1
- package/dist/affordances/pathAnchors.js +10 -6
- package/dist/affordances/pathAnchors.js.map +1 -1
- package/dist/animation/poseTarget.js +46 -15
- package/dist/animation/poseTarget.js.map +1 -1
- package/dist/animation/poseTransition.js +3 -3
- package/dist/animation/poseTransition.js.map +1 -1
- package/dist/animation/reflow.js +3 -6
- package/dist/animation/reflow.js.map +1 -1
- package/dist/animation/rig/bindRig.js +2 -2
- package/dist/animation/rig/bindRig.js.map +1 -1
- package/dist/animation/rig/skinBinding.js +2 -2
- package/dist/animation/rig/skinBinding.js.map +1 -1
- package/dist/barrel/canvas.js +5 -1
- package/dist/barrel/chrome.js +3 -1
- package/dist/barrel/paint.js +4 -4
- package/dist/barrel/paths.js +9 -4
- package/dist/barrel/renderer.js +3 -2
- package/dist/barrel/routing.js +4 -4
- package/dist/barrel/scene.js +7 -1
- package/dist/barrel/text.js +2 -2
- package/dist/barrel/viewport.js +6 -2
- package/dist/canvas/Canvas.js +2 -1
- 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 +5 -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 +2 -0
- 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/canvasPassThrough.js +2 -1
- package/dist/canvas/SceneCanvas/canvasPassThrough.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js +2 -2
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
- package/dist/canvas/SceneCanvas/props.js.map +1 -1
- package/dist/canvas/SceneCanvas/scenePointQuery.js +27 -5
- package/dist/canvas/SceneCanvas/scenePointQuery.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/useCanvasDevtoolsRoot.js +1 -0
- package/dist/canvas/SceneCanvas/useCanvasDevtoolsRoot.js.map +1 -1
- package/dist/canvas/SceneCanvas/useCanvasTools.js +10 -2
- package/dist/canvas/SceneCanvas/useCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +25 -19
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.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 +17 -2
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +2 -0
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js +19 -4
- package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js.map +1 -1
- package/dist/canvas/SceneCanvas/useScenePicking.js +31 -6
- package/dist/canvas/SceneCanvas/useScenePicking.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +4 -5
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js +7 -4
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +30 -12
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/ViewMarker.js +35 -0
- package/dist/canvas/ViewMarker.js.map +1 -0
- package/dist/canvas/accentColor.js +26 -3
- package/dist/canvas/accentColor.js.map +1 -1
- package/dist/canvas/buildSceneTree.js +14 -20
- package/dist/canvas/buildSceneTree.js.map +1 -1
- package/dist/canvas/copiesAbove.js +1 -1
- package/dist/canvas/copiesAbove.js.map +1 -1
- package/dist/canvas/defaultDrawOne.js +11 -6
- package/dist/canvas/defaultDrawOne.js.map +1 -1
- package/dist/canvas/deps/areaSelect.js +5 -2
- package/dist/canvas/deps/areaSelect.js.map +1 -1
- package/dist/canvas/deps/booleans.js +3 -2
- package/dist/canvas/deps/booleans.js.map +1 -1
- package/dist/canvas/deps/enteredGroup.js +81 -0
- package/dist/canvas/deps/enteredGroup.js.map +1 -0
- package/dist/canvas/deps/hitTestArea.js +28 -16
- package/dist/canvas/deps/hitTestArea.js.map +1 -1
- package/dist/canvas/deps/insert.js +10 -38
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/insertSite.js +39 -0
- package/dist/canvas/deps/insertSite.js.map +1 -0
- package/dist/canvas/deps/lassoSelect.js +6 -3
- package/dist/canvas/deps/lassoSelect.js.map +1 -1
- package/dist/canvas/deps/pathEditCommits.js +3 -7
- package/dist/canvas/deps/pathEditCommits.js.map +1 -1
- package/dist/canvas/deps/pathLeaf.js +1 -1
- package/dist/canvas/deps/pathLeaf.js.map +1 -1
- package/dist/canvas/deps/slice.js +2 -1
- package/dist/canvas/deps/slice.js.map +1 -1
- package/dist/canvas/derivedPath.js +14 -6
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/doubleClickTarget.js +9 -11
- package/dist/canvas/doubleClickTarget.js.map +1 -1
- package/dist/canvas/drawnBounds.js +26 -9
- package/dist/canvas/drawnBounds.js.map +1 -1
- package/dist/canvas/inheritedPaints.js +55 -0
- package/dist/canvas/inheritedPaints.js.map +1 -0
- package/dist/canvas/nodeShapes/derivedPainter.js +15 -16
- package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/nodePaint.js +7 -34
- package/dist/canvas/nodeShapes/nodePaint.js.map +1 -1
- package/dist/canvas/nodeShapes/pathPainter.js +7 -7
- 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 +9 -9
- 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/ownClip.js +24 -0
- package/dist/canvas/ownClip.js.map +1 -0
- package/dist/canvas/paintCull.js.map +1 -1
- package/dist/canvas/pickIndex/nodeBroadBox.js +86 -0
- package/dist/canvas/pickIndex/nodeBroadBox.js.map +1 -0
- package/dist/canvas/pickIndex/scenePickIndex.js +208 -0
- package/dist/canvas/pickIndex/scenePickIndex.js.map +1 -0
- package/dist/canvas/pickReach.js +3 -3
- package/dist/canvas/pickReach.js.map +1 -1
- package/dist/canvas/pickWalk.js +17 -91
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/poseCascade.js +1 -1
- package/dist/canvas/poseCascade.js.map +1 -1
- package/dist/canvas/publishPreviews.js +97 -0
- package/dist/canvas/publishPreviews.js.map +1 -0
- package/dist/canvas/renderSceneToPixels.js +1 -1
- package/dist/canvas/renderSceneToPixels.js.map +1 -1
- package/dist/canvas/sceneAdapter.js +7 -5
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneClipboard.js +17 -10
- package/dist/canvas/sceneClipboard.js.map +1 -1
- package/dist/canvas/scenePickReads.js +37 -0
- package/dist/canvas/scenePickReads.js.map +1 -0
- package/dist/canvas/scenePickSource.js +74 -0
- package/dist/canvas/scenePickSource.js.map +1 -0
- package/dist/canvas/sceneSlotWiring.js +9 -3
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +9 -4
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/shownNodes.js +15 -0
- package/dist/canvas/shownNodes.js.map +1 -0
- package/dist/canvas/surfaceContribution.js +12 -8
- package/dist/canvas/surfaceContribution.js.map +1 -1
- package/dist/canvas/useCanvasView.js +4 -2
- package/dist/canvas/useCanvasView.js.map +1 -1
- package/dist/canvas/useLayerStack.js +6 -2
- package/dist/canvas/useLayerStack.js.map +1 -1
- package/dist/canvas/useSceneAdapter.js +5 -3
- package/dist/canvas/useSceneAdapter.js.map +1 -1
- package/dist/canvas/useViewAim.js +121 -0
- package/dist/canvas/useViewAim.js.map +1 -0
- 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 +2 -2
- package/dist/{clone-C3e0OTuF.d.ts → clone-qb2e1F5p.d.ts} +2 -2
- package/dist/clone.d.ts +3 -3
- package/dist/core/isPlainObject.js +2 -2
- package/dist/core/layers/layerGroup.js.map +1 -1
- package/dist/core/pages/pageEdits.js +2 -3
- package/dist/core/pages/pageEdits.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.map +1 -1
- package/dist/core/scene/arrivalWindow.js +1 -1
- package/dist/core/scene/arrivalWindow.js.map +1 -1
- package/dist/core/scene/clipNothing.js +10 -0
- package/dist/core/scene/clipNothing.js.map +1 -0
- package/dist/core/scene/declaredFieldSetters.js +44 -0
- package/dist/core/scene/declaredFieldSetters.js.map +1 -0
- package/dist/core/scene/depMemo.js +14 -3
- package/dist/core/scene/depMemo.js.map +1 -1
- package/dist/core/scene/dependents.js +9 -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/documentOf.js +43 -0
- package/dist/core/scene/documentOf.js.map +1 -0
- package/dist/core/scene/effectivePose.js +44 -15
- package/dist/core/scene/effectivePose.js.map +1 -1
- package/dist/core/scene/fieldEdits.js +17 -14
- 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/historyForm.js +4 -4
- package/dist/core/scene/historyForm.js.map +1 -1
- package/dist/core/scene/inheritedPaint.js +97 -0
- package/dist/core/scene/inheritedPaint.js.map +1 -0
- package/dist/core/scene/kitOps.js +3 -23
- package/dist/core/scene/kitOps.js.map +1 -1
- package/dist/core/scene/kitRegistry.js +5 -0
- package/dist/core/scene/kitRegistry.js.map +1 -1
- package/dist/core/scene/layoutPass.js +1 -2
- package/dist/core/scene/layoutPass.js.map +1 -1
- package/dist/core/scene/nodeAsShown.js +72 -0
- package/dist/core/scene/nodeAsShown.js.map +1 -0
- package/dist/core/scene/nodeFnFields.js +2 -10
- package/dist/core/scene/nodeFnFields.js.map +1 -1
- package/dist/core/scene/nodeMemo.js +21 -8
- package/dist/core/scene/nodeMemo.js.map +1 -1
- package/dist/core/scene/nodeStore.js +2 -4
- package/dist/core/scene/nodeStore.js.map +1 -1
- package/dist/core/scene/pathEffects/blend.js.map +1 -1
- package/dist/core/scene/pathEffects/derive.js +10 -4
- 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/foundHidden.js +35 -0
- package/dist/core/scene/pathEffects/foundHidden.js.map +1 -0
- package/dist/core/scene/pathEffects/textAlong.js +95 -0
- package/dist/core/scene/pathEffects/textAlong.js.map +1 -0
- package/dist/core/scene/plyStacks.js +89 -0
- package/dist/core/scene/plyStacks.js.map +1 -0
- package/dist/core/scene/poseHold.js +42 -24
- package/dist/core/scene/poseHold.js.map +1 -1
- package/dist/core/scene/poseOverrides.js +35 -38
- package/dist/core/scene/poseOverrides.js.map +1 -1
- package/dist/core/scene/posePlies.js +59 -0
- package/dist/core/scene/posePlies.js.map +1 -0
- package/dist/core/scene/reconcileSpecs.js +6 -15
- package/dist/core/scene/reconcileSpecs.js.map +1 -1
- package/dist/core/scene/renderOrder.js +10 -4
- package/dist/core/scene/renderOrder.js.map +1 -1
- package/dist/core/scene/sameValue.js +17 -0
- package/dist/core/scene/sameValue.js.map +1 -0
- package/dist/core/scene/scene.js +3 -3
- package/dist/core/scene/scene.js.map +1 -1
- package/dist/core/scene/sceneEdits.js +8 -0
- package/dist/core/scene/sceneEdits.js.map +1 -1
- package/dist/core/scene/sceneState.js +1 -2
- package/dist/core/scene/sceneState.js.map +1 -1
- package/dist/core/scene/serialization.js +45 -9
- package/dist/core/scene/serialization.js.map +1 -1
- package/dist/core/scene/staleReplay.js +5 -2
- package/dist/core/scene/staleReplay.js.map +1 -1
- package/dist/core/scene/statedFields.js +4 -2
- package/dist/core/scene/statedFields.js.map +1 -1
- package/dist/core/scene/treeEdits.js +2 -4
- package/dist/core/scene/treeEdits.js.map +1 -1
- package/dist/core/scene/treeOrder.js +3 -1
- package/dist/core/scene/treeOrder.js.map +1 -1
- package/dist/core/scene/treeReads.js +1 -2
- package/dist/core/scene/treeReads.js.map +1 -1
- package/dist/core/scene/treeShape.js +13 -0
- package/dist/core/scene/treeShape.js.map +1 -0
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/scene/useScene.js +1 -1
- package/dist/core/scene/useScene.js.map +1 -1
- package/dist/{cornerHandles-BHuoMs1o.d.ts → cornerHandles-CNCb7aTY.d.ts} +3 -2
- package/dist/{depSchema-BpZNOv7q.d.ts → depSchema-B1RS-IJx.d.ts} +39 -18
- package/dist/devtools/handlers.js +1 -1
- package/dist/devtools/handlers.js.map +1 -1
- package/dist/devtools/protocol.js.map +1 -1
- package/dist/devtools/registry.js +4 -4
- package/dist/devtools/registry.js.map +1 -1
- package/dist/devtools-protocol.d.ts +4 -3
- package/dist/devtools.d.ts +3 -2
- package/dist/features/measure/measureContribution.js +4 -2
- package/dist/features/measure/measureContribution.js.map +1 -1
- package/dist/features/measure/measureHit.js +5 -3
- package/dist/features/measure/measureHit.js.map +1 -1
- package/dist/features/measure/measurement.js +1 -1
- package/dist/features/measure/measurement.js.map +1 -1
- package/dist/features/modes/modeLayers.js +14 -7
- package/dist/features/modes/modeLayers.js.map +1 -1
- package/dist/features/modes/modeTriggers.js +10 -6
- package/dist/features/modes/modeTriggers.js.map +1 -1
- package/dist/features/pathEffects/effectSources.js +69 -0
- package/dist/features/pathEffects/effectSources.js.map +1 -0
- package/dist/features/pathEffects/readSource.js +18 -2
- 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 +53 -0
- package/dist/features/pathEffects/useEffectSourcesLayer.js.map +1 -0
- package/dist/features/paths/editablePath.js +1 -1
- package/dist/features/paths/editablePath.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/sceneIndex.js +1 -1
- package/dist/features/paths/pathSnap/sceneIndex.js.map +1 -1
- package/dist/features/selection/enteredGroupFrame.js +65 -0
- package/dist/features/selection/enteredGroupFrame.js.map +1 -0
- package/dist/features/selection/enteredGroupScope.js +44 -0
- package/dist/features/selection/enteredGroupScope.js.map +1 -0
- package/dist/features/text/sceneTextDrafts.js +64 -0
- package/dist/features/text/sceneTextDrafts.js.map +1 -0
- package/dist/features/text/textHitAt.js +34 -3
- package/dist/features/text/textHitAt.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +23 -19
- 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/index.d.ts +709 -258
- package/dist/index.js +33 -12
- package/dist/interactions/actions/admitsChild.js +11 -0
- package/dist/interactions/actions/admitsChild.js.map +1 -0
- 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/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 +7 -4
- 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 +33 -11
- package/dist/interactions/actions/defaults/contextMenu.js.map +1 -1
- package/dist/interactions/actions/defaults/createPaintAction.js +5 -2
- package/dist/interactions/actions/defaults/createPaintAction.js.map +1 -1
- package/dist/interactions/actions/defaults/delete.js +28 -14
- package/dist/interactions/actions/defaults/delete.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +11 -8
- package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
- package/dist/interactions/actions/defaults/enterGroup.js +88 -0
- package/dist/interactions/actions/defaults/enterGroup.js.map +1 -0
- package/dist/interactions/actions/defaults/enterPathEdit.js +20 -10
- package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/enterTextEdit.js +1 -1
- package/dist/interactions/actions/defaults/enterTextEdit.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 +26 -20
- package/dist/interactions/actions/defaults/group.js.map +1 -1
- package/dist/interactions/actions/defaults/ingest.js +10 -4
- 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 +8 -2
- 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 +15 -8
- package/dist/interactions/actions/defaults/selectAll.js.map +1 -1
- package/dist/interactions/actions/defaults/selectDeep.js +35 -0
- package/dist/interactions/actions/defaults/selectDeep.js.map +1 -0
- 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/drawnBoxes.js +2 -1
- package/dist/interactions/actions/drawnBoxes.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/action.js +7 -4
- package/dist/interactions/actions/edit-anchors/action.js.map +1 -1
- package/dist/interactions/actions/flip/action.js +8 -2
- package/dist/interactions/actions/flip/action.js.map +1 -1
- package/dist/interactions/actions/insert/action.js +1 -0
- package/dist/interactions/actions/insert/action.js.map +1 -1
- package/dist/interactions/actions/insert/parent.js +7 -5
- package/dist/interactions/actions/insert/parent.js.map +1 -1
- package/dist/interactions/actions/insert/placeAction.js +3 -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 +2 -2
- package/dist/interactions/actions/insert/session.js.map +1 -1
- package/dist/interactions/actions/move/action.js +7 -4
- package/dist/interactions/actions/move/action.js.map +1 -1
- package/dist/interactions/actions/move/commit/reparent.js +1 -1
- package/dist/interactions/actions/move/commit/reparent.js.map +1 -1
- package/dist/interactions/actions/move/gestureAdapter.js +6 -7
- package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
- package/dist/interactions/actions/move/layout/exits.js +1 -1
- package/dist/interactions/actions/move/layout/exits.js.map +1 -1
- package/dist/interactions/actions/move/session.js +4 -4
- package/dist/interactions/actions/move/session.js.map +1 -1
- 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/pathCommands/pathNodes.js +14 -5
- package/dist/interactions/actions/pathCommands/pathNodes.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/selectionSubtree.js +12 -7
- package/dist/interactions/actions/selectionSubtree.js.map +1 -1
- package/dist/interactions/actions/transform-again/action.js +8 -5
- package/dist/interactions/actions/transform-again/action.js.map +1 -1
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +14 -2
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
- package/dist/json.d.ts +4 -0
- package/dist/json.js +3 -0
- package/dist/kitSettingsSchema.js +8 -1
- package/dist/kitSettingsSchema.js.map +1 -1
- package/dist/{math-CrJULaZI.d.ts → math-C_elShP_.d.ts} +7 -1
- package/dist/math.d.ts +1 -1
- package/dist/math.js +2 -1
- package/dist/move.d.ts +4 -4
- package/dist/{options-DBxEryYq.d.ts → options-ClEm3SEl.d.ts} +1 -1
- package/dist/resize.d.ts +4 -4
- package/dist/test-seams.d.ts +6 -6
- 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/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/pressTarget.js +22 -0
- package/dist/tools/builtin/pressTarget.js.map +1 -0
- 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 +6 -5
- package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
- package/dist/tools/builtin/select/collapseDeferred.js +40 -0
- package/dist/tools/builtin/select/collapseDeferred.js.map +1 -0
- package/dist/tools/builtin/select/groupEntry.js +82 -0
- package/dist/tools/builtin/select/groupEntry.js.map +1 -0
- 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 +74 -55
- 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/{types-7puAuVD2.d.ts → types-49uYJN3j.d.ts} +1 -1
- package/dist/{types-CniVctmk.d.ts → types-BEdRIhNc.d.ts} +272 -109
- package/dist/{types-oFeQ5VjV.d.ts → types-p2alu-R1.d.ts} +1 -1
- package/dist/util/paint.js +1 -3
- package/dist/util/paint.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +29 -25
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sameDependsOn } from "./dependents.js";
|
|
2
|
+
import { foundHiddenRetargeted } from "./pathEffects/foundHidden.js";
|
|
2
3
|
import { resized } from "./layoutPass.js";
|
|
3
4
|
|
|
4
5
|
//#region src/core/scene/fieldEdits.ts
|
|
@@ -22,9 +23,9 @@ function createFieldEdits(env) {
|
|
|
22
23
|
setPose(id, pose) {
|
|
23
24
|
const node = requireNode(id);
|
|
24
25
|
refuse(id, "set the pose of");
|
|
25
|
-
const resizes = node.
|
|
26
|
+
const resizes = node.layout !== void 0 && resized(layoutFrame, id, node.pose, pose);
|
|
26
27
|
const parent = node.parent === null ? void 0 : requireNode(node.parent);
|
|
27
|
-
const arranger = parent?.
|
|
28
|
+
const arranger = parent?.layout !== void 0 ? parent.id : null;
|
|
28
29
|
edit("setPose", resizes || arranger !== null, () => {
|
|
29
30
|
if (resizes) noteChange(id);
|
|
30
31
|
noteChange(arranger);
|
|
@@ -69,15 +70,27 @@ function createFieldEdits(env) {
|
|
|
69
70
|
const node = requireNode(id);
|
|
70
71
|
refuse(id, "retarget");
|
|
71
72
|
if (sameDependsOn(node.dependsOn, dependsOn)) return;
|
|
72
|
-
|
|
73
|
+
const data = foundHiddenRetargeted(node.data, node.dependsOn, dependsOn);
|
|
74
|
+
if (data === null) return void record("kit:setDependsOn", {
|
|
73
75
|
id,
|
|
74
76
|
from: node.dependsOn,
|
|
75
77
|
to: dependsOn
|
|
76
78
|
}, "setDependsOn");
|
|
79
|
+
batch("setDependsOn", () => {
|
|
80
|
+
record("kit:setDependsOn", {
|
|
81
|
+
id,
|
|
82
|
+
from: node.dependsOn,
|
|
83
|
+
to: dependsOn
|
|
84
|
+
}, "setDependsOn");
|
|
85
|
+
record("kit:setData", {
|
|
86
|
+
id,
|
|
87
|
+
from: node.data,
|
|
88
|
+
to: data
|
|
89
|
+
}, "setDependsOn");
|
|
90
|
+
});
|
|
77
91
|
},
|
|
78
92
|
setLayout(id, layout) {
|
|
79
93
|
const node = requireNode(id);
|
|
80
|
-
if (node.kind !== "container") throw new Error(`Scene: "${id}" is not a container`);
|
|
81
94
|
refuse(id, "set the layout of");
|
|
82
95
|
let to;
|
|
83
96
|
if (typeof layout === "string") {
|
|
@@ -102,16 +115,6 @@ function createFieldEdits(env) {
|
|
|
102
115
|
noteChange(id);
|
|
103
116
|
record("kit:setLayout", payload, "setLayout");
|
|
104
117
|
});
|
|
105
|
-
},
|
|
106
|
-
setUnits(id, units) {
|
|
107
|
-
const node = requireNode(id);
|
|
108
|
-
if (node.kind !== "container") throw new Error(`Scene: "${id}" is not a container`);
|
|
109
|
-
refuse(id, "set the units of");
|
|
110
|
-
record("kit:setUnits", {
|
|
111
|
-
id,
|
|
112
|
-
from: node.units,
|
|
113
|
-
to: units ?? void 0
|
|
114
|
-
}, "setUnits");
|
|
115
118
|
}
|
|
116
119
|
};
|
|
117
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldEdits.js","names":[],"sources":["../../../src/core/scene/fieldEdits.ts"],"sourcesContent":["/**\n * The scene's edits to one node's fields: its data, pose, layer, dependency\n * list,
|
|
1
|
+
{"version":3,"file":"fieldEdits.js","names":[],"sources":["../../../src/core/scene/fieldEdits.ts"],"sourcesContent":["/**\n * The scene's edits to one node's fields: its data, pose, layer, dependency\n * list, and layout. Each checks its arguments, then records.\n */\nimport type { LayoutStrategy } from '../../layout/types';\nimport type { ArrivalWindow } from './arrivalWindow';\nimport { sameDependsOn } from './dependents';\nimport { foundHiddenRetargeted } from './pathEffects/foundHidden';\nimport type { SetLayoutPayload } from './kitOps';\nimport type { createLayerStack } from './layerStack';\nimport { resized, type ResolvedLayoutFrame } from './layoutPass';\nimport type { LockGuard } from './lockGuard';\nimport type { NodeFnField } from './nodeFnFields';\nimport type { createNodeStore } from './nodeStore';\nimport type { Recorder } from './recorder';\nimport type { NodeId, Scene } from './types';\n\nexport interface FieldEditsEnv<TData, TLayer extends string, TPose> {\n store: Pick<ReturnType<typeof createNodeStore<TData, TLayer, TPose>>, 'requireNode' | 'descendants'>;\n locks: Pick<LockGuard<TLayer>, 'refuse' | 'refuseLayer'>;\n layers: Pick<ReturnType<typeof createLayerStack<TLayer>>, 'requireLayerIndex' | 'assertSubtreeLayer'>;\n recorder: Pick<Recorder, 'record' | 'edit' | 'batch'>;\n arrivals: Pick<ArrivalWindow<TPose>, 'noteChange' | 'layoutDeclared'>;\n layoutFrame: ResolvedLayoutFrame<TPose>;\n /** The registry's layouts, by key and back. */\n layoutField: NodeFnField;\n /** Where a live `kit:setLayout` payload's strategies are kept. */\n layoutRefs: WeakMap<object, { from: LayoutStrategy<TPose> | null; to: LayoutStrategy<TPose> | null }>;\n}\n\nexport type FieldEdits<TData, TLayer extends string, TPose> = Pick<\n Scene<TData, TLayer, TPose>,\n 'update' | 'setPose' | 'setLayer' | 'setDependsOn' | 'setLayout'\n>;\n\nexport function createFieldEdits<TData, TLayer extends string, TPose>(\n env: FieldEditsEnv<TData, TLayer, TPose>,\n): FieldEdits<TData, TLayer, TPose> {\n const { layoutFrame, layoutField, layoutRefs } = env;\n const { requireNode, descendants } = env.store;\n const { refuse, refuseLayer } = env.locks;\n const { requireLayerIndex, assertSubtreeLayer } = env.layers;\n const { record, edit, batch } = env.recorder;\n const { noteChange, layoutDeclared } = env.arrivals;\n\n return {\n update(id, patch) {\n const node = requireNode(id);\n refuse(id, 'update');\n record('kit:setData', { id, from: node.data, to: patch.data }, 'update');\n },\n\n setPose(id, pose) {\n const node = requireNode(id);\n refuse(id, 'set the pose of');\n const resizes = node.layout !== undefined && resized(layoutFrame, id, node.pose, pose);\n // A container with a layout owns where its children go, however one is moved.\n const parent = node.parent === null ? undefined : requireNode(node.parent);\n const arranger = parent?.layout !== undefined ? parent.id : null;\n edit('setPose', resizes || arranger !== null, () => {\n if (resizes) noteChange(id);\n noteChange(arranger);\n record('kit:setPose', { id, from: node.pose, to: pose }, 'setPose');\n });\n },\n\n setLayer(id, layer) {\n requireLayerIndex(layer);\n const node = requireNode(id);\n refuse(id, 'relayer');\n if (node.layer !== layer) refuseLayer(layer, 'move nodes onto');\n if (node.parent !== null) {\n const parentNode = requireNode(node.parent);\n assertSubtreeLayer(id, layer, node.parent, parentNode.layer, 'relayer');\n }\n if (node.layer === layer) return;\n const subtree: NodeId[] = [id];\n descendants(id, subtree);\n for (const sid of subtree) refuse(sid, 'relayer');\n if (subtree.length === 1) {\n record('kit:setLayer', { id, from: node.layer, to: layer }, 'setLayer');\n } else {\n batch('setLayer', () => {\n for (const sid of subtree) {\n const cur = requireNode(sid);\n if (cur.layer === layer) continue;\n record('kit:setLayer', { id: sid, from: cur.layer, to: layer }, 'setLayer');\n }\n });\n }\n },\n\n setDependsOn(id, dependsOn) {\n const node = requireNode(id);\n refuse(id, 'retarget');\n if (sameDependsOn(node.dependsOn, dependsOn)) return;\n const data = foundHiddenRetargeted(node.data, node.dependsOn, dependsOn);\n if (data === null) return void record('kit:setDependsOn', { id, from: node.dependsOn, to: dependsOn }, 'setDependsOn');\n batch('setDependsOn', () => {\n record('kit:setDependsOn', { id, from: node.dependsOn, to: dependsOn }, 'setDependsOn');\n record('kit:setData', { id, from: node.data, to: data }, 'setDependsOn');\n });\n },\n\n setLayout(id, layout) {\n const node = requireNode(id);\n refuse(id, 'set the layout of');\n let to: LayoutStrategy<TPose> | null;\n if (typeof layout === 'string') {\n to = (layoutField.fnOf(layout) as LayoutStrategy<TPose> | undefined) ?? null;\n if (to === null) throw new Error(`Scene: no layout \"${layout}\" in this scene's registry`);\n } else {\n to = layout;\n }\n const from = node.layout ?? null;\n if (from === to) return;\n if (to !== null) layoutDeclared();\n const fromKey = from === null ? undefined : layoutField.keyOf(from);\n const toKey = to === null ? undefined : layoutField.keyOf(to);\n const payload: SetLayoutPayload = {\n id,\n ...(fromKey !== undefined ? { fromKey } : {}),\n ...(toKey !== undefined ? { toKey } : {}),\n };\n layoutRefs.set(payload, { from, to });\n edit('setLayout', true, () => {\n noteChange(id);\n record('kit:setLayout', payload, 'setLayout');\n });\n },\n };\n}\n"],"mappings":";;;;;AAmCA,SAAgB,iBACd,KACkC;CAClC,MAAM,EAAE,aAAa,aAAa,eAAe;CACjD,MAAM,EAAE,aAAa,gBAAgB,IAAI;CACzC,MAAM,EAAE,QAAQ,gBAAgB,IAAI;CACpC,MAAM,EAAE,mBAAmB,uBAAuB,IAAI;CACtD,MAAM,EAAE,QAAQ,MAAM,UAAU,IAAI;CACpC,MAAM,EAAE,YAAY,mBAAmB,IAAI;CAE3C,OAAO;EACL,OAAO,IAAI,OAAO;GAChB,MAAM,OAAO,YAAY,EAAE;GAC3B,OAAO,IAAI,QAAQ;GACnB,OAAO,eAAe;IAAE;IAAI,MAAM,KAAK;IAAM,IAAI,MAAM;GAAK,GAAG,QAAQ;EACzE;EAEA,QAAQ,IAAI,MAAM;GAChB,MAAM,OAAO,YAAY,EAAE;GAC3B,OAAO,IAAI,iBAAiB;GAC5B,MAAM,UAAU,KAAK,WAAW,UAAa,QAAQ,aAAa,IAAI,KAAK,MAAM,IAAI;GAErF,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OAAO,oBAAoB;IAAE;IAAI,MAAM,KAAK;IAAW,IAAI;GAAU,GAAG,cAAc;GACrH,MAAM,sBAAsB;IAC1B,OAAO,oBAAoB;KAAE;KAAI,MAAM,KAAK;KAAW,IAAI;IAAU,GAAG,cAAc;IACtF,OAAO,eAAe;KAAE;KAAI,MAAM,KAAK;KAAM,IAAI;IAAK,GAAG,cAAc;GACzE,CAAC;EACH;EAEA,UAAU,IAAI,QAAQ;GACpB,MAAM,OAAO,YAAY,EAAE;GAC3B,OAAO,IAAI,mBAAmB;GAC9B,IAAI;GACJ,IAAI,OAAO,WAAW,UAAU;IAC9B,KAAM,YAAY,KAAK,MAAM,KAA2C;IACxE,IAAI,OAAO,MAAM,MAAM,IAAI,MAAM,qBAAqB,OAAO,2BAA2B;GAC1F,OACE,KAAK;GAEP,MAAM,OAAO,KAAK,UAAU;GAC5B,IAAI,SAAS,IAAI;GACjB,IAAI,OAAO,MAAM,eAAe;GAChC,MAAM,UAAU,SAAS,OAAO,SAAY,YAAY,MAAM,IAAI;GAClE,MAAM,QAAQ,OAAO,OAAO,SAAY,YAAY,MAAM,EAAE;GAC5D,MAAM,UAA4B;IAChC;IACA,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;IAC3C,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;GACzC;GACA,WAAW,IAAI,SAAS;IAAE;IAAM;GAAG,CAAC;GACpC,KAAK,aAAa,YAAY;IAC5B,WAAW,EAAE;IACb,OAAO,iBAAiB,SAAS,WAAW;GAC9C,CAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { faceGeneration } from "@weasel-js/font";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scene/fontReads.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether a derivation read glyph outlines. Outlines land asynchronously, so a
|
|
6
|
+
* derivation that read them while a face was loading is stale once it lands,
|
|
7
|
+
* with nothing in the scene changed. A derivation that noted a read records
|
|
8
|
+
* {@link fontGeneration} and re-derives when it moves.
|
|
9
|
+
*/
|
|
10
|
+
var noted = false;
|
|
11
|
+
/** Note that the derivation running now read glyph outlines. */
|
|
12
|
+
function noteFontRead() {
|
|
13
|
+
noted = true;
|
|
14
|
+
}
|
|
15
|
+
/** Run `fn`, reporting whether it — or anything it ran — noted a font read.
|
|
16
|
+
* A read inside counts toward any enclosing `withFontReads` too. */
|
|
17
|
+
function withFontReads(fn) {
|
|
18
|
+
const outer = noted;
|
|
19
|
+
noted = false;
|
|
20
|
+
try {
|
|
21
|
+
return {
|
|
22
|
+
value: fn(),
|
|
23
|
+
fonts: noted
|
|
24
|
+
};
|
|
25
|
+
} finally {
|
|
26
|
+
noted = outer || noted;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The face generation a font-reading derivation is checked against: it
|
|
30
|
+
* moves when a face lands, not on every glyph bake. */
|
|
31
|
+
function fontGeneration() {
|
|
32
|
+
return faceGeneration();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { fontGeneration, noteFontRead, withFontReads };
|
|
37
|
+
//# sourceMappingURL=fontReads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fontReads.js","names":[],"sources":["../../../src/core/scene/fontReads.ts"],"sourcesContent":["/**\n * Whether a derivation read glyph outlines. Outlines land asynchronously, so a\n * derivation that read them while a face was loading is stale once it lands,\n * with nothing in the scene changed. A derivation that noted a read records\n * {@link fontGeneration} and re-derives when it moves.\n */\nimport { faceGeneration } from '@weasel-js/font';\n\nlet noted = false;\n\n/** Note that the derivation running now read glyph outlines. */\nexport function noteFontRead(): void {\n noted = true;\n}\n\n/** Run `fn`, reporting whether it — or anything it ran — noted a font read.\n * A read inside counts toward any enclosing `withFontReads` too. */\nexport function withFontReads<T>(fn: () => T): { value: T; fonts: boolean } {\n const outer = noted;\n noted = false;\n try {\n const value = fn();\n return { value, fonts: noted };\n } finally {\n noted = outer || noted;\n }\n}\n\n/** The face generation a font-reading derivation is checked against: it\n * moves when a face lands, not on every glyph bake. */\nexport function fontGeneration(): number {\n return faceGeneration();\n}\n"],"mappings":";;;;;;;;;AAQA,IAAI,QAAQ;;AAGZ,SAAgB,eAAqB;CACnC,QAAQ;AACV;;;AAIA,SAAgB,cAAiB,IAA2C;CAC1E,MAAM,QAAQ;CACd,QAAQ;CACR,IAAI;EAEF,OAAO;GAAE,OADK,GACL;GAAO,OAAO;EAAM;CAC/B,UAAU;EACR,QAAQ,SAAS;CACnB;AACF;;;AAIA,SAAgB,iBAAyB;CACvC,OAAO,eAAe;AACxB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//#region src/core/scene/historyForm.ts
|
|
2
2
|
/** The form a scene's undo entries are recorded in. A serialized history
|
|
3
|
-
* carries it, and one carrying another is not restored. Form
|
|
4
|
-
* scene's own ops for every edit
|
|
5
|
-
* ops it was given. */
|
|
6
|
-
var SCENE_HISTORY_FORM =
|
|
3
|
+
* carries it, and one carrying another is not restored. Form 3 names
|
|
4
|
+
* nodes `mark` and `group`; form 2 held the scene's own ops for every edit,
|
|
5
|
+
* and before it an `applyBatch` entry held the ops it was given. */
|
|
6
|
+
var SCENE_HISTORY_FORM = 3;
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
9
|
export { SCENE_HISTORY_FORM };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historyForm.js","names":[],"sources":["../../../src/core/scene/historyForm.ts"],"sourcesContent":["import type { SerializedHistory } from '@weasel-js/history';\n\n/** The form a scene's undo entries are recorded in. A serialized history\n * carries it, and one carrying another is not restored. Form
|
|
1
|
+
{"version":3,"file":"historyForm.js","names":[],"sources":["../../../src/core/scene/historyForm.ts"],"sourcesContent":["import type { SerializedHistory } from '@weasel-js/history';\n\n/** The form a scene's undo entries are recorded in. A serialized history\n * carries it, and one carrying another is not restored. Form 3 names\n * nodes `mark` and `group`; form 2 held the scene's own ops for every edit,\n * and before it an `applyBatch` entry held the ops it was given. */\nexport const SCENE_HISTORY_FORM = 3;\n\n/** What `Scene.serializeHistory` answers with. */\nexport interface SerializedSceneHistory extends SerializedHistory {\n form: typeof SCENE_HISTORY_FORM;\n}\n"],"mappings":";;;;;AAMA,IAAa,qBAAqB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { INHERIT, resolveFill, resolveStroke } from "@weasel-js/paint";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scene/inheritedPaint.ts
|
|
4
|
+
/** Whether `node`'s fill or stroke is {@link INHERIT}, so painting it needs
|
|
5
|
+
* its containers' paint. */
|
|
6
|
+
function inheritsPaint(node) {
|
|
7
|
+
const d = node.data;
|
|
8
|
+
return d?.fill === INHERIT || d?.stroke === INHERIT;
|
|
9
|
+
}
|
|
10
|
+
var LAST = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/**
|
|
12
|
+
* {@link InheritedPaint} for `node`, given its ancestors innermost first. Any
|
|
13
|
+
* ancestor is a source, mark or group; one whose own field is `'inherit'`
|
|
14
|
+
* passes the question on to the next, and running out of ancestors is none.
|
|
15
|
+
*
|
|
16
|
+
* Hands back the object it returned last time for `node` while both values
|
|
17
|
+
* are the same references, so a memo can key on it.
|
|
18
|
+
*/
|
|
19
|
+
function inheritedPaintOf(node, ancestors) {
|
|
20
|
+
const d = node.data;
|
|
21
|
+
let wantFill = d?.fill === INHERIT;
|
|
22
|
+
let wantStroke = d?.stroke === INHERIT;
|
|
23
|
+
let fill = null;
|
|
24
|
+
let stroke = null;
|
|
25
|
+
for (const a of ancestors) {
|
|
26
|
+
if (!wantFill && !wantStroke) break;
|
|
27
|
+
const ad = a.data;
|
|
28
|
+
if (wantFill && ad?.fill !== INHERIT) {
|
|
29
|
+
fill = resolveFill(ad?.fill);
|
|
30
|
+
wantFill = false;
|
|
31
|
+
}
|
|
32
|
+
if (wantStroke && ad?.stroke !== INHERIT) {
|
|
33
|
+
stroke = resolveStroke(ad?.stroke);
|
|
34
|
+
wantStroke = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const last = LAST.get(node);
|
|
38
|
+
if (last !== void 0 && last.fill === fill && last.stroke === stroke) return last;
|
|
39
|
+
const next = {
|
|
40
|
+
fill,
|
|
41
|
+
stroke
|
|
42
|
+
};
|
|
43
|
+
LAST.set(node, next);
|
|
44
|
+
return next;
|
|
45
|
+
}
|
|
46
|
+
/** What `node`'s `'inherit'` fields take from its containers in `scene`, or
|
|
47
|
+
* `undefined` for a node that inherits nothing. */
|
|
48
|
+
function inheritedPaintIn(scene, node) {
|
|
49
|
+
if (!inheritsPaint(node)) return void 0;
|
|
50
|
+
return inheritedPaintOf(node, sceneAncestors((id) => scene.get(id), node));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The descendants of `id` whose `key` is `'inherit'` all the way up to it:
|
|
54
|
+
* those that paint whatever `id`'s own `key` holds, so a preview of that paint
|
|
55
|
+
* reaches them too. Parents before children.
|
|
56
|
+
*/
|
|
57
|
+
function paintInheritors(scene, id, key) {
|
|
58
|
+
const out = [];
|
|
59
|
+
const walk = (parent) => {
|
|
60
|
+
for (const child of scene.childrenOf(parent)) {
|
|
61
|
+
if ((scene.get(child)?.data)?.[key] !== INHERIT) continue;
|
|
62
|
+
out.push(child);
|
|
63
|
+
walk(child);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
walk(id);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/** `node`'s ancestors in `scene`, innermost first, read lazily off `parent`. */
|
|
70
|
+
function* sceneAncestors(get, node) {
|
|
71
|
+
const seen = /* @__PURE__ */ new Set();
|
|
72
|
+
let id = node.parent ?? null;
|
|
73
|
+
while (id !== null && !seen.has(id)) {
|
|
74
|
+
seen.add(id);
|
|
75
|
+
const p = get(id);
|
|
76
|
+
if (p === void 0) return;
|
|
77
|
+
yield p;
|
|
78
|
+
id = p.parent ?? null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `data` with an `'inherit'` fill or stroke replaced by what `inherited` says
|
|
83
|
+
* it resolves to, for a reader that wants the paint a node shows rather than
|
|
84
|
+
* the one it declares. Hands `data` back as is when nothing inherits.
|
|
85
|
+
*/
|
|
86
|
+
function withInheritedPaint(data, inherited) {
|
|
87
|
+
if (data.fill !== INHERIT && data.stroke !== INHERIT) return data;
|
|
88
|
+
return {
|
|
89
|
+
...data,
|
|
90
|
+
...data.fill === INHERIT ? { fill: inherited?.fill ?? null } : {},
|
|
91
|
+
...data.stroke === INHERIT ? { stroke: inherited?.stroke ?? null } : {}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { inheritedPaintIn, inheritedPaintOf, inheritsPaint, paintInheritors, sceneAncestors, withInheritedPaint };
|
|
97
|
+
//# sourceMappingURL=inheritedPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inheritedPaint.js","names":[],"sources":["../../../src/core/scene/inheritedPaint.ts"],"sourcesContent":["import {\n INHERIT, resolveFill, resolveStroke,\n type Fill, type Inherit, type PaintedFill, type PaintedStroke, type Stroke,\n} from '@weasel-js/paint';\n\n/**\n * What a node's `'inherit'` fill and stroke resolve to: its nearest enclosing\n * container's, `null` for none. A field the node does not inherit is `null`\n * here whatever its containers hold.\n */\nexport interface InheritedPaint {\n readonly fill: PaintedFill | null;\n readonly stroke: PaintedStroke | null;\n}\n\ntype PaintData = { fill?: Fill | Inherit | null; stroke?: Stroke | Inherit | null } | null | undefined;\n\n/** Whether `node`'s fill or stroke is {@link INHERIT}, so painting it needs\n * its containers' paint. */\nexport function inheritsPaint(node: { data?: unknown }): boolean {\n const d = node.data as PaintData;\n return d?.fill === INHERIT || d?.stroke === INHERIT;\n}\n\nconst LAST = new WeakMap<object, InheritedPaint>();\n\n/**\n * {@link InheritedPaint} for `node`, given its ancestors innermost first. Any\n * ancestor is a source, mark or group; one whose own field is `'inherit'`\n * passes the question on to the next, and running out of ancestors is none.\n *\n * Hands back the object it returned last time for `node` while both values\n * are the same references, so a memo can key on it.\n */\nexport function inheritedPaintOf(\n node: { data?: unknown },\n ancestors: Iterable<{ kind?: string; data?: unknown }>,\n): InheritedPaint {\n const d = node.data as PaintData;\n let wantFill = d?.fill === INHERIT;\n let wantStroke = d?.stroke === INHERIT;\n let fill: PaintedFill | null = null;\n let stroke: PaintedStroke | null = null;\n for (const a of ancestors) {\n if (!wantFill && !wantStroke) break;\n const ad = a.data as PaintData;\n if (wantFill && ad?.fill !== INHERIT) {\n fill = resolveFill(ad?.fill);\n wantFill = false;\n }\n if (wantStroke && ad?.stroke !== INHERIT) {\n stroke = resolveStroke(ad?.stroke);\n wantStroke = false;\n }\n }\n const last = LAST.get(node);\n if (last !== undefined && last.fill === fill && last.stroke === stroke) return last;\n const next: InheritedPaint = { fill, stroke };\n LAST.set(node, next);\n return next;\n}\n\n/** What `node`'s `'inherit'` fields take from its containers in `scene`, or\n * `undefined` for a node that inherits nothing. */\nexport function inheritedPaintIn<TNode extends { data?: unknown; parent?: string | null }>(\n scene: { get(id: never): TNode | undefined },\n node: TNode,\n): InheritedPaint | undefined {\n if (!inheritsPaint(node)) return undefined;\n return inheritedPaintOf(node, sceneAncestors((id: never) => scene.get(id), node));\n}\n\n/**\n * The descendants of `id` whose `key` is `'inherit'` all the way up to it:\n * those that paint whatever `id`'s own `key` holds, so a preview of that paint\n * reaches them too. Parents before children.\n */\nexport function paintInheritors(\n scene: { get(id: never): { data?: unknown } | undefined; childrenOf(id: never): readonly string[] },\n id: string,\n key: 'fill' | 'stroke',\n): string[] {\n const out: string[] = [];\n const walk = (parent: string): void => {\n for (const child of scene.childrenOf(parent as never)) {\n if ((scene.get(child as never)?.data as PaintData)?.[key] !== INHERIT) continue;\n out.push(child);\n walk(child);\n }\n };\n walk(id);\n return out;\n}\n\n/** `node`'s ancestors in `scene`, innermost first, read lazily off `parent`. */\nexport function* sceneAncestors<TNode extends { parent?: string | null }>(\n get: (id: never) => TNode | undefined,\n node: TNode,\n): Generator<TNode> {\n const seen = new Set<string>();\n let id = node.parent ?? null;\n while (id !== null && !seen.has(id)) {\n seen.add(id);\n const p = get(id as never);\n if (p === undefined) return;\n yield p;\n id = p.parent ?? null;\n }\n}\n\n/** The fields {@link withInheritedPaint} resolves. */\ntype ResolvedPaintFields<T> = Omit<T, 'fill' | 'stroke'> & {\n fill?: Exclude<T extends { fill?: infer F } ? F : never, Inherit>;\n stroke?: Exclude<T extends { stroke?: infer S } ? S : never, Inherit>;\n};\n\n/**\n * `data` with an `'inherit'` fill or stroke replaced by what `inherited` says\n * it resolves to, for a reader that wants the paint a node shows rather than\n * the one it declares. Hands `data` back as is when nothing inherits.\n */\nexport function withInheritedPaint<T extends { fill?: unknown; stroke?: unknown }>(\n data: T,\n inherited: InheritedPaint | undefined,\n): ResolvedPaintFields<T> {\n if (data.fill !== INHERIT && data.stroke !== INHERIT) return data as ResolvedPaintFields<T>;\n return {\n ...data,\n ...(data.fill === INHERIT ? { fill: inherited?.fill ?? null } : {}),\n ...(data.stroke === INHERIT ? { stroke: inherited?.stroke ?? null } : {}),\n } as ResolvedPaintFields<T>;\n}\n"],"mappings":";;;;;AAmBA,SAAgB,cAAc,MAAmC;CAC/D,MAAM,IAAI,KAAK;CACf,OAAO,GAAG,SAAS,WAAW,GAAG,WAAW;AAC9C;AAEA,IAAM,uBAAO,IAAI,QAAgC;;;;;;;;;AAUjD,SAAgB,iBACd,MACA,WACgB;CAChB,MAAM,IAAI,KAAK;CACf,IAAI,WAAW,GAAG,SAAS;CAC3B,IAAI,aAAa,GAAG,WAAW;CAC/B,IAAI,OAA2B;CAC/B,IAAI,SAA+B;CACnC,KAAK,MAAM,KAAK,WAAW;EACzB,IAAI,CAAC,YAAY,CAAC,YAAY;EAC9B,MAAM,KAAK,EAAE;EACb,IAAI,YAAY,IAAI,SAAS,SAAS;GACpC,OAAO,YAAY,IAAI,IAAI;GAC3B,WAAW;EACb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AW,UAAU,KAAK,IAAI,CAAC;CACzE;AACF"}
|
|
@@ -7,10 +7,6 @@ function setParallax(record, to) {
|
|
|
7
7
|
if (to === void 0) delete record.parallax;
|
|
8
8
|
else record.parallax = to;
|
|
9
9
|
}
|
|
10
|
-
function setUnits(node, to) {
|
|
11
|
-
if (to === void 0) delete node.units;
|
|
12
|
-
else node.units = to;
|
|
13
|
-
}
|
|
14
10
|
/** Register every kit op kind. Answers with the table a live `kit:setLayout`
|
|
15
11
|
* payload's strategies are kept in, which `scene.setLayout` fills. */
|
|
16
12
|
function registerKitOps(env) {
|
|
@@ -22,16 +18,8 @@ function registerKitOps(env) {
|
|
|
22
18
|
registerKitOp("kit:add", {
|
|
23
19
|
apply: (p) => {
|
|
24
20
|
if (state.nodes.has(p.id)) throw new Error(`Scene: id collision on "${p.id}"`);
|
|
25
|
-
const node =
|
|
26
|
-
kind:
|
|
27
|
-
id: p.id,
|
|
28
|
-
layer: p.layer,
|
|
29
|
-
pose: p.pose,
|
|
30
|
-
data: p.data,
|
|
31
|
-
parent: p.parent,
|
|
32
|
-
children: []
|
|
33
|
-
} : {
|
|
34
|
-
kind: "leaf",
|
|
21
|
+
const node = {
|
|
22
|
+
kind: p.kind,
|
|
35
23
|
id: p.id,
|
|
36
24
|
layer: p.layer,
|
|
37
25
|
pose: p.pose,
|
|
@@ -82,7 +70,7 @@ function registerKitOps(env) {
|
|
|
82
70
|
revert: (p) => {
|
|
83
71
|
const keys = new Map((p.fnKeys ?? []).map((k) => [k.id, k]));
|
|
84
72
|
for (const n of p.nodes) {
|
|
85
|
-
const clone = n.
|
|
73
|
+
const clone = n.children ? {
|
|
86
74
|
...n,
|
|
87
75
|
children: [...n.children]
|
|
88
76
|
} : { ...n };
|
|
@@ -136,14 +124,6 @@ function registerKitOps(env) {
|
|
|
136
124
|
retarget(p.id, p.from);
|
|
137
125
|
}
|
|
138
126
|
});
|
|
139
|
-
registerKitOp("kit:setUnits", {
|
|
140
|
-
apply: (p) => {
|
|
141
|
-
setUnits(requireNode(p.id), p.to);
|
|
142
|
-
},
|
|
143
|
-
revert: (p) => {
|
|
144
|
-
setUnits(requireNode(p.id), p.from);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
127
|
/** The strategies each live `kit:setLayout` payload swaps between. A payload
|
|
148
128
|
* replayed from a persisted history has none, and resolves its keys. */
|
|
149
129
|
const layoutRefs = /* @__PURE__ */ new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kitOps.js","names":[],"sources":["../../../src/core/scene/kitOps.ts"],"sourcesContent":["/**\n * The kit's own op kinds: `kit:add`, `kit:remove`, `kit:setPose`, and the\n * rest. They are registered like any other op; the scene's mutation methods\n * build serializable payloads and route through the same log and replay\n * machinery a consumer's ops do.\n */\nimport type { UnitScope } from '@weasel-js/quantity';\nimport type { ParallaxOpts } from 'core/viewport/parallax';\nimport { dwarn } from 'debug/flag';\nimport type { LayoutStrategy } from '../../layout/types';\nimport { restoreFn, type FnBearingNode, type NodeFnField } from './nodeFnFields';\nimport { statedFields } from './statedFields';\nimport type { createNodeStore } from './nodeStore';\nimport type {\n ContainerNode, LayerRecord, LeafNode, Node, NodeId, RegisteredOp, UserLayerRecord,\n} from './types';\n\n/**\n * Snapshot of every node a removal deletes, so revert restores it exactly.\n *\n * A cascade unlinks several disjoint subtrees, not one, so `detached` names\n * each node the tree has to re-link; everything else in `nodes` has a parent\n * that is also going and rides back in that parent's cloned `children`.\n * Entries are sorted by ascending sibling index — globally rather than\n * per-parent, because only same-parent order constrains re-insertion and\n * entries under different parents never interact.\n */\nexport interface RemoveSnapshot<TData, TLayer extends string, TPose> {\n nodes: Node<TData, TLayer, TPose>[];\n detached: { id: NodeId; parent: NodeId | null; index: number }[];\n /** Registry keys for the function-valued fields on `nodes`. The functions\n * themselves do not survive a persisted history, so revert re-resolves\n * them the way `kit:add` does. */\n fnKeys?: ({ id: NodeId } & Record<string, string | undefined>)[];\n}\n\n/** What a `kit:setLayout` op carries: the container, and each side's layout\n * by registry key when it has one. */\nexport interface SetLayoutPayload { id: NodeId; fromKey?: string; toKey?: string }\n\n/** What the op table needs from the scene it mutates. */\nexport interface KitOpsEnv<TData, TLayer extends string, TPose> {\n state: {\n nodes: Map<NodeId, Node<TData, TLayer, TPose>>;\n layers: LayerRecord<TLayer>[];\n };\n register(kind: string, handler: RegisteredOp<unknown>): void;\n store: ReturnType<typeof createNodeStore<TData, TLayer, TPose>>;\n requireLayerIndex(layer: TLayer): number;\n rebuildLayerIndex(): void;\n invalidateOrder(): void;\n fnFields: readonly NodeFnField[];\n /** Drop from the selection whatever a lock or a hide just put out of\n * reach, and the ids in `gone`. */\n narrowSelection(gone?: ReadonlySet<NodeId>): void;\n /** Drop the pose override of a node that is about to leave the scene: ids\n * are reusable, and one left behind would attach itself to whatever is\n * added under that id next. */\n clearOverride(id: NodeId): void;\n}\n\nfunction setParallax(record: { parallax?: ParallaxOpts }, to: ParallaxOpts | undefined): void {\n if (to === undefined) delete record.parallax;\n else record.parallax = to;\n}\n\nfunction setUnits(node: { units?: UnitScope }, to: UnitScope | undefined): void {\n if (to === undefined) delete node.units;\n else node.units = to;\n}\n\n/** Register every kit op kind. Answers with the table a live `kit:setLayout`\n * payload's strategies are kept in, which `scene.setLayout` fills. */\nexport function registerKitOps<TData, TLayer extends string, TPose>(\n env: KitOpsEnv<TData, TLayer, TPose>,\n): {\n layoutRefs: WeakMap<object, { from: LayoutStrategy<TPose> | null; to: LayoutStrategy<TPose> | null }>;\n} {\n const { state, requireLayerIndex, rebuildLayerIndex, invalidateOrder, fnFields } = env;\n const {\n dependents, childDerived, invalidateDependents, invalidateChildDerivedFrom, trackChildDerived, retarget,\n requireNode, detach, attach, addedFns, restoreNodeFunctions,\n } = env.store;\n\n function registerKitOp<P>(kind: string, handler: RegisteredOp<P>): void {\n env.register(kind, handler as RegisteredOp<unknown>);\n }\n\n registerKitOp<{\n id: NodeId; kind: 'leaf' | 'container'; layer: TLayer; pose: TPose; data: TData;\n parent: NodeId | null; index: number;\n dependsOn?: readonly NodeId[] | 'children';\n pickable?: boolean; hidden?: boolean; locked?: boolean;\n units?: UnitScope;\n } & Record<string, unknown>>('kit:add', {\n apply: (p) => {\n if (state.nodes.has(p.id)) {\n throw new Error(`Scene: id collision on \"${p.id}\"`);\n }\n const node: Node<TData, TLayer, TPose> = p.kind === 'container'\n ? ({ kind: 'container', id: p.id, layer: p.layer, pose: p.pose, data: p.data, parent: p.parent, children: [] } as ContainerNode<TData, TLayer, TPose>)\n : ({ kind: 'leaf', id: p.id, layer: p.layer, pose: p.pose, data: p.data, parent: p.parent } as LeafNode<TData, TLayer, TPose>);\n state.nodes.set(p.id, node);\n attach(p.id, p.parent, p.index);\n if (p.dependsOn !== undefined) node.dependsOn = p.dependsOn;\n Object.assign(node, statedFields(p));\n dependents.add(p.id, p.dependsOn === 'children' ? [] : p.dependsOn ?? []);\n trackChildDerived(p.id, p.dependsOn);\n // Two ways a function field comes back. Redo of a live add reads\n // what `scene.add` attached, since it replays the op without a spec.\n // A restored history has only the registry key the payload carries.\n const target = node as unknown as FnBearingNode;\n const attached = addedFns.get(p);\n for (const field of fnFields) {\n const fn = attached?.get(field);\n if (fn !== undefined) {\n field.write(target, fn);\n continue;\n }\n const key = p[field.spec.opKey] as string | undefined;\n if (key !== undefined) restoreFn(field, target, key, 'kit:add', dwarn);\n }\n invalidateDependents(p.id);\n },\n revert: (p) => {\n env.clearOverride(p.id);\n detach(p.id);\n state.nodes.delete(p.id);\n dependents.remove(p.id);\n childDerived.delete(p.id);\n invalidateChildDerivedFrom(p.parent);\n invalidateDependents(p.id);\n },\n });\n\n // Neither half invalidates dependents: removal's closure takes every live one.\n registerKitOp<RemoveSnapshot<TData, TLayer, TPose>>('kit:remove', {\n apply: (p) => {\n for (const n of p.nodes) env.clearOverride(n.id);\n for (const d of p.detached) detach(d.id);\n for (const n of p.nodes) {\n state.nodes.delete(n.id);\n dependents.remove(n.id);\n childDerived.delete(n.id);\n }\n // A `dependsOn: 'children'` container the removal did not take is now\n // hugging a smaller set.\n for (const d of p.detached) invalidateChildDerivedFrom(d.parent);\n env.narrowSelection(new Set(p.nodes.map((n) => n.id)));\n },\n revert: (p) => {\n const keys = new Map((p.fnKeys ?? []).map((k) => [k.id, k]));\n // Order-independent: every clone carries its own parent and children.\n for (const n of p.nodes) {\n const clone: Node<TData, TLayer, TPose> = n.kind === 'container'\n ? { ...n, children: [...n.children] }\n : { ...n };\n restoreNodeFunctions(clone, keys.get(n.id));\n state.nodes.set(n.id, clone);\n dependents.add(n.id, clone.dependsOn === 'children' ? [] : clone.dependsOn ?? []);\n trackChildDerived(n.id, clone.dependsOn);\n }\n for (const d of p.detached) attach(d.id, d.parent, d.index);\n for (const d of p.detached) invalidateChildDerivedFrom(d.parent);\n },\n });\n\n registerKitOp<{ id: NodeId; from: TPose; to: TPose }>('kit:setPose', {\n apply: (p) => {\n (requireNode(p.id) as { pose: TPose }).pose = p.to;\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { pose: TPose }).pose = p.from;\n invalidateDependents(p.id);\n },\n });\n\n // A derivation is handed its dependencies' nodes, not only their poses, so a\n // connector reading `data` or `layer` goes stale on these two exactly as it\n // does on a move.\n registerKitOp<{ id: NodeId; from: TData; to: TData }>('kit:setData', {\n apply: (p) => {\n (requireNode(p.id) as { data: TData }).data = p.to;\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { data: TData }).data = p.from;\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{ id: NodeId; from: TLayer; to: TLayer }>('kit:setLayer', {\n apply: (p) => {\n requireLayerIndex(p.to);\n (requireNode(p.id) as { layer: TLayer }).layer = p.to;\n invalidateOrder();\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { layer: TLayer }).layer = p.from;\n invalidateOrder();\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{\n id: NodeId;\n from: Node<TData, TLayer, TPose>['dependsOn'];\n to: Node<TData, TLayer, TPose>['dependsOn'];\n }>('kit:setDependsOn', {\n apply: (p) => { retarget(p.id, p.to); },\n revert: (p) => { retarget(p.id, p.from); },\n });\n\n registerKitOp<{ id: NodeId; from?: UnitScope; to?: UnitScope }>('kit:setUnits', {\n apply: (p) => { setUnits(requireNode(p.id) as { units?: UnitScope }, p.to); },\n revert: (p) => { setUnits(requireNode(p.id) as { units?: UnitScope }, p.from); },\n });\n\n /** The strategies each live `kit:setLayout` payload swaps between. A payload\n * replayed from a persisted history has none, and resolves its keys. */\n const layoutRefs = new WeakMap<object, { from: LayoutStrategy<TPose> | null; to: LayoutStrategy<TPose> | null }>();\n function placeLayout(p: SetLayoutPayload, side: 'from' | 'to'): void {\n const node = requireNode(p.id) as unknown as FnBearingNode;\n const field = fnFields.find((f) => f.spec.field === 'layout')!;\n const live = layoutRefs.get(p);\n const key = side === 'from' ? p.fromKey : p.toKey;\n if (live === undefined && key !== undefined) {\n delete node.layout;\n restoreFn(field, node, key, 'kit:setLayout', dwarn);\n return;\n }\n const layout = live?.[side] ?? null;\n if (layout === null) delete node.layout;\n else field.write(node, layout);\n }\n registerKitOp<SetLayoutPayload>('kit:setLayout', {\n apply: (p) => { placeLayout(p, 'to'); },\n revert: (p) => { placeLayout(p, 'from'); },\n });\n\n registerKitOp<{\n id: NodeId; fromParent: NodeId | null; fromIndex: number;\n toParent: NodeId | null; toIndex: number;\n }>('kit:move', {\n apply: (p) => {\n detach(p.id);\n attach(p.id, p.toParent, p.toIndex);\n // Both ends: the container it left no longer hugs it, and the one it\n // joined now does.\n invalidateChildDerivedFrom(p.fromParent);\n invalidateDependents(p.id);\n },\n revert: (p) => {\n detach(p.id);\n attach(p.id, p.fromParent, p.fromIndex);\n invalidateChildDerivedFrom(p.toParent);\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{ layer: TLayer; from: boolean; to: boolean }>('kit:setLayerVisible', {\n apply: (p) => { state.layers[requireLayerIndex(p.layer)].visible = p.to; if (!p.to) env.narrowSelection(); },\n revert: (p) => { state.layers[requireLayerIndex(p.layer)].visible = p.from; },\n });\n\n registerKitOp<{ layer: TLayer; from: boolean; to: boolean }>('kit:setLayerLocked', {\n apply: (p) => { state.layers[requireLayerIndex(p.layer)].locked = p.to; if (p.to) env.narrowSelection(); },\n revert: (p) => { state.layers[requireLayerIndex(p.layer)].locked = p.from; },\n });\n\n registerKitOp<{ layer: TLayer; from?: ParallaxOpts; to?: ParallaxOpts }>('kit:setLayerParallax', {\n apply: (p) => { setParallax(state.layers[requireLayerIndex(p.layer)], p.to); },\n revert: (p) => { setParallax(state.layers[requireLayerIndex(p.layer)], p.from); },\n });\n\n registerKitOp<{ record: UserLayerRecord<TLayer>; index: number }>('kit:addLayer', {\n apply: (p) => { state.layers.splice(p.index, 0, { ...p.record }); rebuildLayerIndex(); },\n revert: (p) => { state.layers.splice(p.index, 1); rebuildLayerIndex(); },\n });\n\n registerKitOp<{ record: LayerRecord<TLayer>; index: number }>('kit:removeLayer', {\n apply: (p) => { state.layers.splice(p.index, 1); rebuildLayerIndex(); },\n revert: (p) => { state.layers.splice(p.index, 0, { ...p.record } as LayerRecord<TLayer>); rebuildLayerIndex(); },\n });\n\n registerKitOp<{ layer: TLayer; from: string; to: string }>('kit:renameLayer', {\n apply: (p) => { (state.layers[requireLayerIndex(p.layer)] as UserLayerRecord<TLayer>).name = p.to; },\n revert: (p) => { (state.layers[requireLayerIndex(p.layer)] as UserLayerRecord<TLayer>).name = p.from; },\n });\n\n /** Finds the layer by id, not by where the payload last left it: moves of\n * one layer coalesce, and the entry then reverts the first payload from\n * wherever the last one put the layer. */\n function placeLayer(layer: TLayer, index: number): void {\n const [rec] = state.layers.splice(requireLayerIndex(layer), 1);\n state.layers.splice(index, 0, rec);\n rebuildLayerIndex();\n }\n\n registerKitOp<{ layer: TLayer; from: number; to: number }>('kit:moveLayer', {\n apply: (p) => placeLayer(p.layer, p.to),\n revert: (p) => placeLayer(p.layer, p.from),\n });\n\n return { layoutRefs };\n}\n"],"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AAkB,EAAE,KAAK,EAAE,CAA6B,OAAO,EAAE;EAAM;CACxG,CAAC;;;;CAKD,SAAS,WAAW,OAAe,OAAqB;EACtD,MAAM,CAAC,OAAO,MAAM,OAAO,OAAO,kBAAkB,KAAK,GAAG,CAAC;EAC7D,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG;EACjC,kBAAkB;CACpB;CAEA,cAA2D,iBAAiB;EAC1E,QAAQ,MAAM,WAAW,EAAE,OAAO,EAAE,EAAE;EACtC,SAAS,MAAM,WAAW,EAAE,OAAO,EAAE,IAAI;CAC3C,CAAC;CAED,OAAO,EAAE,WAAW;AACtB"}
|
|
1
|
+
{"version":3,"file":"kitOps.js","names":[],"sources":["../../../src/core/scene/kitOps.ts"],"sourcesContent":["/**\n * The kit's own op kinds: `kit:add`, `kit:remove`, `kit:setPose`, and the\n * rest. They are registered like any other op; the scene's mutation methods\n * build serializable payloads and route through the same log and replay\n * machinery a consumer's ops do.\n */\nimport type { UnitScope } from '@weasel-js/quantity';\nimport type { ParallaxOpts } from 'core/viewport/parallax';\nimport { dwarn } from 'debug/flag';\nimport type { LayoutStrategy } from '../../layout/types';\nimport { restoreFn, type FnBearingNode, type NodeFnField } from './nodeFnFields';\nimport { statedFields } from './statedFields';\nimport type { createNodeStore } from './nodeStore';\nimport type {\n LayerRecord, Node, NodeClip, NodeId, RegisteredOp, UserLayerRecord,\n} from './types';\n\n/**\n * Snapshot of every node a removal deletes, so revert restores it exactly.\n *\n * A cascade unlinks several disjoint subtrees, not one, so `detached` names\n * each node the tree has to re-link; everything else in `nodes` has a parent\n * that is also going and rides back in that parent's cloned `children`.\n * Entries are sorted by ascending sibling index — globally rather than\n * per-parent, because only same-parent order constrains re-insertion and\n * entries under different parents never interact.\n */\nexport interface RemoveSnapshot<TData, TLayer extends string, TPose> {\n nodes: Node<TData, TLayer, TPose>[];\n detached: { id: NodeId; parent: NodeId | null; index: number }[];\n /** Registry keys for the function-valued fields on `nodes`. The functions\n * themselves do not survive a persisted history, so revert re-resolves\n * them the way `kit:add` does. */\n fnKeys?: ({ id: NodeId } & Record<string, string | undefined>)[];\n}\n\n/** What a `kit:setLayout` op carries: the container, and each side's layout\n * by registry key when it has one. */\nexport interface SetLayoutPayload { id: NodeId; fromKey?: string; toKey?: string }\n\n/** What the op table needs from the scene it mutates. */\nexport interface KitOpsEnv<TData, TLayer extends string, TPose> {\n state: {\n nodes: Map<NodeId, Node<TData, TLayer, TPose>>;\n layers: LayerRecord<TLayer>[];\n };\n register(kind: string, handler: RegisteredOp<unknown>): void;\n store: ReturnType<typeof createNodeStore<TData, TLayer, TPose>>;\n requireLayerIndex(layer: TLayer): number;\n rebuildLayerIndex(): void;\n invalidateOrder(): void;\n fnFields: readonly NodeFnField[];\n /** Drop from the selection whatever a lock or a hide just put out of\n * reach, and the ids in `gone`. */\n narrowSelection(gone?: ReadonlySet<NodeId>): void;\n /** Drop the pose override of a node that is about to leave the scene: ids\n * are reusable, and one left behind would attach itself to whatever is\n * added under that id next. */\n clearOverride(id: NodeId): void;\n}\n\nfunction setParallax(record: { parallax?: ParallaxOpts }, to: ParallaxOpts | undefined): void {\n if (to === undefined) delete record.parallax;\n else record.parallax = to;\n}\n\n/** Register every kit op kind. Answers with the table a live `kit:setLayout`\n * payload's strategies are kept in, which `scene.setLayout` fills. */\nexport function registerKitOps<TData, TLayer extends string, TPose>(\n env: KitOpsEnv<TData, TLayer, TPose>,\n): {\n layoutRefs: WeakMap<object, { from: LayoutStrategy<TPose> | null; to: LayoutStrategy<TPose> | null }>;\n} {\n const { state, requireLayerIndex, rebuildLayerIndex, invalidateOrder, fnFields } = env;\n const {\n dependents, childDerived, invalidateDependents, invalidateChildDerivedFrom, trackChildDerived, retarget,\n requireNode, detach, attach, addedFns, restoreNodeFunctions,\n } = env.store;\n\n function registerKitOp<P>(kind: string, handler: RegisteredOp<P>): void {\n env.register(kind, handler as RegisteredOp<unknown>);\n }\n\n registerKitOp<{\n id: NodeId; kind: 'mark' | 'group'; layer: TLayer; pose: TPose; data: TData;\n parent: NodeId | null; index: number;\n dependsOn?: readonly NodeId[] | 'children';\n pickable?: boolean; hidden?: boolean; locked?: boolean;\n units?: UnitScope; clip?: NodeClip;\n } & Record<string, unknown>>('kit:add', {\n apply: (p) => {\n if (state.nodes.has(p.id)) {\n throw new Error(`Scene: id collision on \"${p.id}\"`);\n }\n const node = {\n kind: p.kind, id: p.id, layer: p.layer, pose: p.pose, data: p.data, parent: p.parent,\n } as Node<TData, TLayer, TPose>;\n state.nodes.set(p.id, node);\n attach(p.id, p.parent, p.index);\n if (p.dependsOn !== undefined) node.dependsOn = p.dependsOn;\n Object.assign(node, statedFields(p));\n dependents.add(p.id, p.dependsOn === 'children' ? [] : p.dependsOn ?? []);\n trackChildDerived(p.id, p.dependsOn);\n // Two ways a function field comes back. Redo of a live add reads\n // what `scene.add` attached, since it replays the op without a spec.\n // A restored history has only the registry key the payload carries.\n const target = node as unknown as FnBearingNode;\n const attached = addedFns.get(p);\n for (const field of fnFields) {\n const fn = attached?.get(field);\n if (fn !== undefined) {\n field.write(target, fn);\n continue;\n }\n const key = p[field.spec.opKey] as string | undefined;\n if (key !== undefined) restoreFn(field, target, key, 'kit:add', dwarn);\n }\n invalidateDependents(p.id);\n },\n revert: (p) => {\n env.clearOverride(p.id);\n detach(p.id);\n state.nodes.delete(p.id);\n dependents.remove(p.id);\n childDerived.delete(p.id);\n invalidateChildDerivedFrom(p.parent);\n invalidateDependents(p.id);\n },\n });\n\n // Neither half invalidates dependents: removal's closure takes every live one.\n registerKitOp<RemoveSnapshot<TData, TLayer, TPose>>('kit:remove', {\n apply: (p) => {\n for (const n of p.nodes) env.clearOverride(n.id);\n for (const d of p.detached) detach(d.id);\n for (const n of p.nodes) {\n state.nodes.delete(n.id);\n dependents.remove(n.id);\n childDerived.delete(n.id);\n }\n // A `dependsOn: 'children'` container the removal did not take is now\n // hugging a smaller set.\n for (const d of p.detached) invalidateChildDerivedFrom(d.parent);\n env.narrowSelection(new Set(p.nodes.map((n) => n.id)));\n },\n revert: (p) => {\n const keys = new Map((p.fnKeys ?? []).map((k) => [k.id, k]));\n // Order-independent: every clone carries its own parent and children.\n for (const n of p.nodes) {\n const clone: Node<TData, TLayer, TPose> = n.children\n ? { ...n, children: [...n.children] }\n : { ...n };\n restoreNodeFunctions(clone, keys.get(n.id));\n state.nodes.set(n.id, clone);\n dependents.add(n.id, clone.dependsOn === 'children' ? [] : clone.dependsOn ?? []);\n trackChildDerived(n.id, clone.dependsOn);\n }\n for (const d of p.detached) attach(d.id, d.parent, d.index);\n for (const d of p.detached) invalidateChildDerivedFrom(d.parent);\n },\n });\n\n registerKitOp<{ id: NodeId; from: TPose; to: TPose }>('kit:setPose', {\n apply: (p) => {\n (requireNode(p.id) as { pose: TPose }).pose = p.to;\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { pose: TPose }).pose = p.from;\n invalidateDependents(p.id);\n },\n });\n\n // A derivation is handed its dependencies' nodes, not only their poses, so a\n // connector reading `data` or `layer` goes stale on these two exactly as it\n // does on a move.\n registerKitOp<{ id: NodeId; from: TData; to: TData }>('kit:setData', {\n apply: (p) => {\n (requireNode(p.id) as { data: TData }).data = p.to;\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { data: TData }).data = p.from;\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{ id: NodeId; from: TLayer; to: TLayer }>('kit:setLayer', {\n apply: (p) => {\n requireLayerIndex(p.to);\n (requireNode(p.id) as { layer: TLayer }).layer = p.to;\n invalidateOrder();\n invalidateDependents(p.id);\n },\n revert: (p) => {\n (requireNode(p.id) as { layer: TLayer }).layer = p.from;\n invalidateOrder();\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{\n id: NodeId;\n from: Node<TData, TLayer, TPose>['dependsOn'];\n to: Node<TData, TLayer, TPose>['dependsOn'];\n }>('kit:setDependsOn', {\n apply: (p) => { retarget(p.id, p.to); },\n revert: (p) => { retarget(p.id, p.from); },\n });\n\n /** The strategies each live `kit:setLayout` payload swaps between. A payload\n * replayed from a persisted history has none, and resolves its keys. */\n const layoutRefs = new WeakMap<object, { from: LayoutStrategy<TPose> | null; to: LayoutStrategy<TPose> | null }>();\n function placeLayout(p: SetLayoutPayload, side: 'from' | 'to'): void {\n const node = requireNode(p.id) as unknown as FnBearingNode;\n const field = fnFields.find((f) => f.spec.field === 'layout')!;\n const live = layoutRefs.get(p);\n const key = side === 'from' ? p.fromKey : p.toKey;\n if (live === undefined && key !== undefined) {\n delete node.layout;\n restoreFn(field, node, key, 'kit:setLayout', dwarn);\n return;\n }\n const layout = live?.[side] ?? null;\n if (layout === null) delete node.layout;\n else field.write(node, layout);\n }\n registerKitOp<SetLayoutPayload>('kit:setLayout', {\n apply: (p) => { placeLayout(p, 'to'); },\n revert: (p) => { placeLayout(p, 'from'); },\n });\n\n registerKitOp<{\n id: NodeId; fromParent: NodeId | null; fromIndex: number;\n toParent: NodeId | null; toIndex: number;\n }>('kit:move', {\n apply: (p) => {\n detach(p.id);\n attach(p.id, p.toParent, p.toIndex);\n // Both ends: the container it left no longer hugs it, and the one it\n // joined now does.\n invalidateChildDerivedFrom(p.fromParent);\n invalidateDependents(p.id);\n },\n revert: (p) => {\n detach(p.id);\n attach(p.id, p.fromParent, p.fromIndex);\n invalidateChildDerivedFrom(p.toParent);\n invalidateDependents(p.id);\n },\n });\n\n registerKitOp<{ layer: TLayer; from: boolean; to: boolean }>('kit:setLayerVisible', {\n apply: (p) => { state.layers[requireLayerIndex(p.layer)].visible = p.to; if (!p.to) env.narrowSelection(); },\n revert: (p) => { state.layers[requireLayerIndex(p.layer)].visible = p.from; },\n });\n\n registerKitOp<{ layer: TLayer; from: boolean; to: boolean }>('kit:setLayerLocked', {\n apply: (p) => { state.layers[requireLayerIndex(p.layer)].locked = p.to; if (p.to) env.narrowSelection(); },\n revert: (p) => { state.layers[requireLayerIndex(p.layer)].locked = p.from; },\n });\n\n registerKitOp<{ layer: TLayer; from?: ParallaxOpts; to?: ParallaxOpts }>('kit:setLayerParallax', {\n apply: (p) => { setParallax(state.layers[requireLayerIndex(p.layer)], p.to); },\n revert: (p) => { setParallax(state.layers[requireLayerIndex(p.layer)], p.from); },\n });\n\n registerKitOp<{ record: UserLayerRecord<TLayer>; index: number }>('kit:addLayer', {\n apply: (p) => { state.layers.splice(p.index, 0, { ...p.record }); rebuildLayerIndex(); },\n revert: (p) => { state.layers.splice(p.index, 1); rebuildLayerIndex(); },\n });\n\n registerKitOp<{ record: LayerRecord<TLayer>; index: number }>('kit:removeLayer', {\n apply: (p) => { state.layers.splice(p.index, 1); rebuildLayerIndex(); },\n revert: (p) => { state.layers.splice(p.index, 0, { ...p.record } as LayerRecord<TLayer>); rebuildLayerIndex(); },\n });\n\n registerKitOp<{ layer: TLayer; from: string; to: string }>('kit:renameLayer', {\n apply: (p) => { (state.layers[requireLayerIndex(p.layer)] as UserLayerRecord<TLayer>).name = p.to; },\n revert: (p) => { (state.layers[requireLayerIndex(p.layer)] as UserLayerRecord<TLayer>).name = p.from; },\n });\n\n /** Finds the layer by id, not by where the payload last left it: moves of\n * one layer coalesce, and the entry then reverts the first payload from\n * wherever the last one put the layer. */\n function placeLayer(layer: TLayer, index: number): void {\n const [rec] = state.layers.splice(requireLayerIndex(layer), 1);\n state.layers.splice(index, 0, rec);\n rebuildLayerIndex();\n }\n\n registerKitOp<{ layer: TLayer; from: number; to: number }>('kit:moveLayer', {\n apply: (p) => placeLayer(p.layer, p.to),\n revert: (p) => placeLayer(p.layer, p.from),\n });\n\n return { layoutRefs };\n}\n"],"mappings":";;;;;AA6DA,SAAS,YAAY,QAAqC,IAAoC;CAC5F,IAAI,OAAO,QAAW,OAAO,OAAO;MAC/B,OAAO,WAAW;AACzB;;;AAIA,SAAgB,eACd,KAGA;CACA,MAAM,EAAE,OAAO,mBAAmB,mBAAmB,iBAAiB,aAAa;CACnF,MAAM,EACJ,YAAY,cAAc,sBAAsB,4BAA4B,mBAAmB,UAC/F,aAAa,QAAQ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AO,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC;GAAG,kBAAkB;EAAG;EACvF,SAAS,MAAM;GAAE,MAAM,OAAO,OAAO,EAAE,OAAO,CAAC;GAAG,kBAAkB;EAAG;CACzE,CAAC;CAED,cAA8D,mBAAmB;EAC/E,QAAQ,MAAM;GAAE,MAAM,OAAO,OAAO,EAAE,OAAO,CAAC;GAAG,kBAAkB;EAAG;EACtE,SAAS,MAAM;GAAE,MAAM,OAAO,OAAO,EAAE,OAAO,GAAG,EAAE,GAAG,EAAE,OAAO,CAAwB;GAAG,kBAAkB;EAAG;CACjH,CAAC;CAED,cAA2D,mBAAmB;EAC5E,QAAQ,MAAM;GAAE,MAAO,OAAO,kBAAkB,EAAE,KAAK,EAAE,CAA6B,OAAO,EAAE;EAAI;EACnG,SAAS,MAAM;GAAE,MAAO,OAAO,kBAAkB,EAAE,KAAK,EAAE,CAA6B,OAAO,EAAE;EAAM;CACxG,CAAC;;;;CAKD,SAAS,WAAW,OAAe,OAAqB;EACtD,MAAM,CAAC,OAAO,MAAM,OAAO,OAAO,kBAAkB,KAAK,GAAG,CAAC;EAC7D,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG;EACjC,kBAAkB;CACpB;CAEA,cAA2D,iBAAiB;EAC1E,QAAQ,MAAM,WAAW,EAAE,OAAO,EAAE,EAAE;EACtC,SAAS,MAAM,WAAW,EAAE,OAAO,EAAE,IAAI;CAC3C,CAAC;CAED,OAAO,EAAE,WAAW;AACtB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { unionAABB } from "../geometry/unionBounds.js";
|
|
2
|
+
import { CLIP_NOTHING, clipNothing } from "./clipNothing.js";
|
|
2
3
|
|
|
3
4
|
//#region src/core/scene/kitRegistry.ts
|
|
4
5
|
/**
|
|
@@ -48,6 +49,10 @@ function asRectPose(pose) {
|
|
|
48
49
|
function withKitRegistry(registry) {
|
|
49
50
|
return {
|
|
50
51
|
...registry,
|
|
52
|
+
clipFromPose: {
|
|
53
|
+
[CLIP_NOTHING]: clipNothing,
|
|
54
|
+
...registry.clipFromPose
|
|
55
|
+
},
|
|
51
56
|
derivePose: {
|
|
52
57
|
[UNION_OF_CHILDREN]: unionOfChildren,
|
|
53
58
|
...registry.derivePose
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kitRegistry.js","names":[],"sources":["../../../src/core/scene/kitRegistry.ts"],"sourcesContent":["/**\n * The `SceneRegistry` entries the kit owns.\n *\n * A registry-keyed function has to be resolvable by key in whatever scene\n * loads a snapshot, so a function the *kit* attaches to a node cannot live in\n * the consumer's registry alone — a document saved with a grouped container\n * would come back with a dead key. `createScene` merges these under the\n * consumer's, which stays the winner on a key collision.\n */\nimport { unionAABB } from '../geometry/unionBounds';\nimport type { RectPose, SceneRegistry } from './types';\n\n/** Registry key for {@link unionOfChildren}. */\nexport const UNION_OF_CHILDREN = 'kit:unionOfChildren';\n\n/**\n * A container's pose as the envelope of what it holds — `unionAABB`, so a\n * rotated member contributes the extent of its ink rather than its unrotated\n * box. Paired with `dependsOn: 'children'`, this is what makes a group's\n * bounds track its members.\n *\n * Returns `null` for an emptied container, which falls back to its authored\n * pose.\n *\n * Reads members as rect poses only: a scene whose poses are shaped otherwise\n * gets `null` here and its container keeps its authored pose. To make such a\n * container track its members, register `unionOfChildrenVia(itsDescriptor)`\n * under {@link UNION_OF_CHILDREN} — the consumer's entry wins the collision.\n */\nexport function unionOfChildren<TPose>(\n _node: unknown,\n deps: readonly ({ pose: TPose } | undefined)[],\n): TPose | null {\n const poses: RectPose[] = [];\n for (const d of deps) {\n if (d === undefined) continue;\n const rect = asRectPose(d.pose);\n if (rect === null) return null;\n poses.push(rect);\n }\n if (poses.length === 0) return null;\n const union = unionAABB(poses);\n // Sound by the check above: every member read as a rect, so the union is one\n // too, and a scene holding rect poses is a scene whose `TPose` is one.\n return union === null ? null : (union as unknown as TPose);\n}\n\n/** `pose` as a rect, or `null` when it is some other shape entirely. */\nexport function asRectPose(pose: unknown): RectPose | null {\n if (pose === null || typeof pose !== 'object') return null;\n const p = pose as Partial<RectPose>;\n const rect = typeof p.x === 'number' && typeof p.y === 'number'\n && typeof p.width === 'number' && typeof p.height === 'number';\n return rect ? (pose as RectPose) : null;\n}\n\n/** Merge the kit's own entries under a consumer registry. */\nexport function withKitRegistry<TPose, TData = unknown, TLayer extends string = string>(\n registry: SceneRegistry<TPose, TData, TLayer>,\n): SceneRegistry<TPose, TData, TLayer> {\n return {\n ...registry,\n derivePose: {\n [UNION_OF_CHILDREN]: unionOfChildren as NonNullable<\n SceneRegistry<TPose, TData, TLayer>['derivePose']\n >[string],\n ...registry.derivePose,\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"kitRegistry.js","names":[],"sources":["../../../src/core/scene/kitRegistry.ts"],"sourcesContent":["/**\n * The `SceneRegistry` entries the kit owns.\n *\n * A registry-keyed function has to be resolvable by key in whatever scene\n * loads a snapshot, so a function the *kit* attaches to a node cannot live in\n * the consumer's registry alone — a document saved with a grouped container\n * would come back with a dead key. `createScene` merges these under the\n * consumer's, which stays the winner on a key collision.\n */\nimport { unionAABB } from '../geometry/unionBounds';\nimport type { RectPose, SceneRegistry } from './types';\nimport { CLIP_NOTHING, clipNothing } from './clipNothing';\n\n/** Registry key for {@link unionOfChildren}. */\nexport const UNION_OF_CHILDREN = 'kit:unionOfChildren';\n\n/**\n * A container's pose as the envelope of what it holds — `unionAABB`, so a\n * rotated member contributes the extent of its ink rather than its unrotated\n * box. Paired with `dependsOn: 'children'`, this is what makes a group's\n * bounds track its members.\n *\n * Returns `null` for an emptied container, which falls back to its authored\n * pose.\n *\n * Reads members as rect poses only: a scene whose poses are shaped otherwise\n * gets `null` here and its container keeps its authored pose. To make such a\n * container track its members, register `unionOfChildrenVia(itsDescriptor)`\n * under {@link UNION_OF_CHILDREN} — the consumer's entry wins the collision.\n */\nexport function unionOfChildren<TPose>(\n _node: unknown,\n deps: readonly ({ pose: TPose } | undefined)[],\n): TPose | null {\n const poses: RectPose[] = [];\n for (const d of deps) {\n if (d === undefined) continue;\n const rect = asRectPose(d.pose);\n if (rect === null) return null;\n poses.push(rect);\n }\n if (poses.length === 0) return null;\n const union = unionAABB(poses);\n // Sound by the check above: every member read as a rect, so the union is one\n // too, and a scene holding rect poses is a scene whose `TPose` is one.\n return union === null ? null : (union as unknown as TPose);\n}\n\n/** `pose` as a rect, or `null` when it is some other shape entirely. */\nexport function asRectPose(pose: unknown): RectPose | null {\n if (pose === null || typeof pose !== 'object') return null;\n const p = pose as Partial<RectPose>;\n const rect = typeof p.x === 'number' && typeof p.y === 'number'\n && typeof p.width === 'number' && typeof p.height === 'number';\n return rect ? (pose as RectPose) : null;\n}\n\n/** Merge the kit's own entries under a consumer registry. */\nexport function withKitRegistry<TPose, TData = unknown, TLayer extends string = string>(\n registry: SceneRegistry<TPose, TData, TLayer>,\n): SceneRegistry<TPose, TData, TLayer> {\n return {\n ...registry,\n clipFromPose: {\n [CLIP_NOTHING]: clipNothing,\n ...registry.clipFromPose,\n },\n derivePose: {\n [UNION_OF_CHILDREN]: unionOfChildren as NonNullable<\n SceneRegistry<TPose, TData, TLayer>['derivePose']\n >[string],\n ...registry.derivePose,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,oBAAoB;;;;;;;;;;;;;;;AAgBjC,SAAgB,gBACd,OACA,MACc;CACd,MAAM,QAAoB,CAAC;CAC3B,KAAK,MAAM,KAAK,MAAM;EACpB,IAAI,MAAM,QAAW;EACrB,MAAM,OAAO,WAAW,EAAE,IAAI;EAC9B,IAAI,SAAS,MAAM,OAAO;EAC1B,MAAM,KAAK,IAAI;CACjB;CACA,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,QAAQ,UAAU,KAAK;CAG7B,OAAO,UAAU,OAAO,OAAQ;AAClC;;AAGA,SAAgB,WAAW,MAAgC;CACzD,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU,OAAO;CACtD,MAAM,IAAI;CAGV,OAFa,OAAO,EAAE,MAAM,YAAY,OAAO,EAAE,MAAM,YAClD,OAAO,EAAE,UAAU,YAAY,OAAO,EAAE,WAAW,WACzC,OAAoB;AACrC;;AAGA,SAAgB,gBACd,UACqC;CACrC,OAAO;EACL,GAAG;EACH,cAAc;IACX,eAAe;GAChB,GAAG,SAAS;EACd;EACA,YAAY;IACT,oBAAoB;GAGrB,GAAG,SAAS;EACd;CACF;AACF"}
|
|
@@ -66,11 +66,10 @@ function runLayoutPass(source, layoutOf, arrivals, changed, frame, departures =
|
|
|
66
66
|
const queue = [.../* @__PURE__ */ new Set([...arrivals.keys(), ...changed])];
|
|
67
67
|
const passes = /* @__PURE__ */ new Map();
|
|
68
68
|
const write = (id, pose) => {
|
|
69
|
-
const node = source.get(id);
|
|
70
69
|
const before = poseOf(id);
|
|
71
70
|
if (samePoseValue(before, pose)) return;
|
|
72
71
|
out.set(id, pose);
|
|
73
|
-
if (id !== current &&
|
|
72
|
+
if (id !== current && layoutOf(id) !== null && resized(frame, id, before, pose)) queue.push(id);
|
|
74
73
|
};
|
|
75
74
|
let current = null;
|
|
76
75
|
/** The container and its children as the strategy sees them, in world,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutPass.js","names":[],"sources":["../../../src/core/scene/layoutPass.ts"],"sourcesContent":["/**\n * The one computation behind a scene's container layouts: given the\n * containers one edit changed, the pose writes their layouts ask for.\n *\n * A container that lost children and whose strategy has `depart` rearranges\n * the rest through it (and may shrink). One that gained children and whose\n * strategy has `arrive` then places them through it (and may refuse, or\n * grow). Any other changed container — one that reordered children, was\n * resized, had a child moved, or gained or lost children with neither hook —\n * is put back in its resting arrangement, `childPoses`.\n *\n * `LayoutStrategy` is world-framed, so each pose is composed to world before\n * a strategy sees it and each result is rebased into its node's parent frame\n * after. A child already where the strategy puts it is left out, so a pass\n * that changes nothing writes nothing. A child the pass moves takes its own\n * descendants along (`carriedDescendants`). A container this pass resizes is\n * arranged in turn, so nested layouts settle in the same edit.\n */\nimport {\n composeWorldPose,\n rebaseLocalPose,\n type PoseAdapter,\n type PoseComposition,\n} from './composeFrame';\nimport type { ContainerBounds, LayoutArrival, LayoutChild, LayoutStrategy } from '../../layout/types';\nimport { carriedDescendants } from './carryDescendants';\nimport { definesFrame, documentPose, type PoseSource, type PosedNode } from './effectivePose';\nimport { asRectPose } from './kitRegistry';\nimport { samePoseValue } from './poseSnapshot';\nimport type { LayoutFrame, NodeId } from './types';\n\n/** What the pass reads a scene through. */\nexport interface LayoutPassSource<TPose> extends PoseSource<TPose> {\n get(id: NodeId): (PosedNode<TPose> & { parent: NodeId | null }) | undefined;\n readonly composition: PoseComposition<TPose>;\n}\n\n/** How the pass measures and resizes poses, with every default filled. */\nexport interface ResolvedLayoutFrame<TPose> {\n bounds(pose: TPose, id: NodeId): ContainerBounds | null;\n remap(pose: TPose, from: ContainerBounds, to: ContainerBounds, id: NodeId): TPose;\n}\n\n/** The pose writes one edit's layouts ask for, or `null` when a strategy\n * refused the children that joined it. */\nexport type LayoutPassResult<TPose> = Map<NodeId, TPose> | null;\n\nexport function resolveLayoutFrame<TPose>(frame: LayoutFrame<TPose> | undefined): ResolvedLayoutFrame<TPose> {\n return {\n bounds: frame?.bounds ?? ((pose) => {\n const r = asRectPose(pose);\n return r === null ? null : { x: r.x, y: r.y, width: r.width, height: r.height };\n }),\n remap: frame?.remap ?? ((pose, _from, to) => ({ ...(pose as object), ...to }) as TPose),\n };\n}\n\n/** Whether a node going from `from` to `to` changed size. */\nexport function resized<TPose>(frame: ResolvedLayoutFrame<TPose>, id: NodeId, from: TPose, to: TPose): boolean {\n const a = frame.bounds(from, id);\n const b = frame.bounds(to, id);\n if (a === null || b === null) return a !== b;\n return a.width !== b.width || a.height !== b.height;\n}\n\n/** How many times one pass may arrange a container before giving up on it —\n * only nested layouts that keep resizing each other get close. */\nconst MAX_PASSES = 16;\n\nexport function runLayoutPass<TPose>(\n source: LayoutPassSource<TPose>,\n layoutOf: (id: NodeId) => LayoutStrategy<TPose> | null,\n arrivals: ReadonlyMap<NodeId, readonly NodeId[]>,\n changed: ReadonlySet<NodeId>,\n frame: ResolvedLayoutFrame<TPose>,\n departures: ReadonlyMap<NodeId, readonly NodeId[]> = new Map(),\n): LayoutPassResult<TPose> {\n // Poses already decided in this pass, so a container resized here is the\n // frame its children are rebased into.\n const out = new Map<NodeId, TPose>();\n const poseOf = (id: NodeId): TPose => out.get(id) ?? documentPose(source, source.get(id)!);\n const pa: PoseAdapter<TPose> = {\n getPose: (id) => poseOf(id as NodeId),\n getParent: (id) => source.get(id as NodeId)?.parent ?? null,\n definesFrame: (id) => {\n const node = source.get(id as NodeId);\n return node === undefined || definesFrame(node);\n },\n };\n const { compose, decompose } = source.composition;\n const world = (id: NodeId): TPose => composeWorldPose(pa, id, compose);\n\n const queue: NodeId[] = [...new Set<NodeId>([...arrivals.keys(), ...changed])];\n const passes = new Map<NodeId, number>();\n const write = (id: NodeId, pose: TPose): void => {\n const node = source.get(id)!;\n const before = poseOf(id);\n if (samePoseValue(before, pose)) return;\n out.set(id, pose);\n // A container its own `depart` or `arrive` resized is arranged already.\n if (id !== current && node.kind === 'container' && layoutOf(id) !== null\n && resized(frame, id, before, pose)) queue.push(id);\n };\n let current: NodeId | null = null;\n\n /** The container and its children as the strategy sees them, in world,\n * with every write this pass has made so far folded in. */\n const frameOf = (containerId: NodeId) => {\n const pose = world(containerId);\n const bounds = frame.bounds(pose, containerId);\n if (bounds === null) return null;\n const children: LayoutChild<TPose>[] = source.childrenOf(containerId).map((cid) => ({\n id: cid as string,\n pose: world(cid),\n }));\n return { world: pose, container: { id: containerId as string, bounds }, children };\n };\n const apply = (\n containerId: NodeId,\n at: NonNullable<ReturnType<typeof frameOf>>,\n result: LayoutArrival<TPose>,\n ): void => {\n if (result.bounds) {\n const node = source.get(containerId)!;\n const sized = frame.remap(at.world, at.container.bounds, result.bounds, containerId);\n write(containerId, rebaseLocalPose(pa, sized, node.parent, compose, decompose));\n }\n for (const [cid, pose] of result.poses) {\n const id = cid as NodeId;\n if (source.get(id)?.parent !== containerId) continue;\n const before = frame.bounds(world(id), id);\n write(id, rebaseLocalPose(pa, pose, containerId, compose, decompose));\n carry(id, before);\n }\n };\n /** Moves `id`'s descendants by however far its write just moved it from `before`. */\n const carry = (id: NodeId, before: ContainerBounds | null): void => {\n const after = frame.bounds(world(id), id);\n if (before === null || after === null) return;\n const dx = after.x - before.x;\n const dy = after.y - before.y;\n if (dx === 0 && dy === 0) return;\n const carried = carriedDescendants(\n { childrenOf: (cid) => source.childrenOf(cid), poses: pa, composition: source.composition },\n id,\n (pose, cid) => {\n const b = frame.bounds(pose, cid);\n return b === null ? null : frame.remap(pose, b, { ...b, x: b.x + dx, y: b.y + dy }, cid);\n },\n );\n for (const [cid, pose] of carried) write(cid, pose);\n };\n\n while (queue.length > 0) {\n const containerId = queue.shift()!;\n current = containerId;\n const n = (passes.get(containerId) ?? 0) + 1;\n passes.set(containerId, n);\n if (n > MAX_PASSES) continue;\n const layout = layoutOf(containerId);\n if (layout === null || source.get(containerId) === undefined) continue;\n const joined = n === 1 ? arrivals.get(containerId) : undefined;\n const left = n === 1 ? departures.get(containerId) : undefined;\n let arranged = false;\n if (left !== undefined && layout.depart) {\n const at = frameOf(containerId);\n if (at === null) continue;\n const joinedSet = new Set<string>(joined ?? []);\n const staying = at.children.filter((c) => !joinedSet.has(c.id));\n apply(containerId, at, layout.depart(at.container, staying, new Set<string>(left)));\n arranged = true;\n }\n if (joined !== undefined && layout.arrive) {\n const at = frameOf(containerId);\n if (at === null) continue;\n const result = layout.arrive(at.container, at.children, new Set<string>(joined));\n if (result === null) return null;\n apply(containerId, at, result);\n } else if (!arranged || joined !== undefined) {\n const at = frameOf(containerId);\n if (at === null) continue;\n apply(containerId, at, { poses: layout.childPoses(at.container, at.children) });\n }\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBAA0B,OAAmE;CAC3G,OAAO;EACL,QAAQ,OA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AAM;GACjB,MAAM,SAAS,OAAO,OAAO,GAAG,WAAW,GAAG,UAAU,IAAI,IAAY,MAAM,CAAC;GAC/E,IAAI,WAAW,MAAM,OAAO;GAC5B,MAAM,aAAa,IAAI,MAAM;EAC/B,OAAO,IAAI,CAAC,YAAY,WAAW,QAAW;GAC5C,MAAM,KAAK,QAAQ,WAAW;GAC9B,IAAI,OAAO,MAAM;GACjB,MAAM,aAAa,IAAI,EAAE,OAAO,OAAO,WAAW,GAAG,WAAW,GAAG,QAAQ,EAAE,CAAC;EAChF;CACF;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"layoutPass.js","names":[],"sources":["../../../src/core/scene/layoutPass.ts"],"sourcesContent":["/**\n * The one computation behind a scene's container layouts: given the\n * containers one edit changed, the pose writes their layouts ask for.\n *\n * A container that lost children and whose strategy has `depart` rearranges\n * the rest through it (and may shrink). One that gained children and whose\n * strategy has `arrive` then places them through it (and may refuse, or\n * grow). Any other changed container — one that reordered children, was\n * resized, had a child moved, or gained or lost children with neither hook —\n * is put back in its resting arrangement, `childPoses`.\n *\n * `LayoutStrategy` is world-framed, so each pose is composed to world before\n * a strategy sees it and each result is rebased into its node's parent frame\n * after. A child already where the strategy puts it is left out, so a pass\n * that changes nothing writes nothing. A child the pass moves takes its own\n * descendants along (`carriedDescendants`). A container this pass resizes is\n * arranged in turn, so nested layouts settle in the same edit.\n */\nimport {\n composeWorldPose,\n rebaseLocalPose,\n type PoseAdapter,\n type PoseComposition,\n} from './composeFrame';\nimport type { ContainerBounds, LayoutArrival, LayoutChild, LayoutStrategy } from '../../layout/types';\nimport { carriedDescendants } from './carryDescendants';\nimport { definesFrame, documentPose, type PoseSource, type PosedNode } from './effectivePose';\nimport { asRectPose } from './kitRegistry';\nimport { samePoseValue } from './poseSnapshot';\nimport type { LayoutFrame, NodeId } from './types';\n\n/** What the pass reads a scene through. */\nexport interface LayoutPassSource<TPose> extends PoseSource<TPose> {\n get(id: NodeId): (PosedNode<TPose> & { parent: NodeId | null }) | undefined;\n readonly composition: PoseComposition<TPose>;\n}\n\n/** How the pass measures and resizes poses, with every default filled. */\nexport interface ResolvedLayoutFrame<TPose> {\n bounds(pose: TPose, id: NodeId): ContainerBounds | null;\n remap(pose: TPose, from: ContainerBounds, to: ContainerBounds, id: NodeId): TPose;\n}\n\n/** The pose writes one edit's layouts ask for, or `null` when a strategy\n * refused the children that joined it. */\nexport type LayoutPassResult<TPose> = Map<NodeId, TPose> | null;\n\nexport function resolveLayoutFrame<TPose>(frame: LayoutFrame<TPose> | undefined): ResolvedLayoutFrame<TPose> {\n return {\n bounds: frame?.bounds ?? ((pose) => {\n const r = asRectPose(pose);\n return r === null ? null : { x: r.x, y: r.y, width: r.width, height: r.height };\n }),\n remap: frame?.remap ?? ((pose, _from, to) => ({ ...(pose as object), ...to }) as TPose),\n };\n}\n\n/** Whether a node going from `from` to `to` changed size. */\nexport function resized<TPose>(frame: ResolvedLayoutFrame<TPose>, id: NodeId, from: TPose, to: TPose): boolean {\n const a = frame.bounds(from, id);\n const b = frame.bounds(to, id);\n if (a === null || b === null) return a !== b;\n return a.width !== b.width || a.height !== b.height;\n}\n\n/** How many times one pass may arrange a container before giving up on it —\n * only nested layouts that keep resizing each other get close. */\nconst MAX_PASSES = 16;\n\nexport function runLayoutPass<TPose>(\n source: LayoutPassSource<TPose>,\n layoutOf: (id: NodeId) => LayoutStrategy<TPose> | null,\n arrivals: ReadonlyMap<NodeId, readonly NodeId[]>,\n changed: ReadonlySet<NodeId>,\n frame: ResolvedLayoutFrame<TPose>,\n departures: ReadonlyMap<NodeId, readonly NodeId[]> = new Map(),\n): LayoutPassResult<TPose> {\n // Poses already decided in this pass, so a container resized here is the\n // frame its children are rebased into.\n const out = new Map<NodeId, TPose>();\n const poseOf = (id: NodeId): TPose => out.get(id) ?? documentPose(source, source.get(id)!);\n const pa: PoseAdapter<TPose> = {\n getPose: (id) => poseOf(id as NodeId),\n getParent: (id) => source.get(id as NodeId)?.parent ?? null,\n definesFrame: (id) => {\n const node = source.get(id as NodeId);\n return node === undefined || definesFrame(node);\n },\n };\n const { compose, decompose } = source.composition;\n const world = (id: NodeId): TPose => composeWorldPose(pa, id, compose);\n\n const queue: NodeId[] = [...new Set<NodeId>([...arrivals.keys(), ...changed])];\n const passes = new Map<NodeId, number>();\n const write = (id: NodeId, pose: TPose): void => {\n const before = poseOf(id);\n if (samePoseValue(before, pose)) return;\n out.set(id, pose);\n // A container its own `depart` or `arrive` resized is arranged already.\n if (id !== current && layoutOf(id) !== null\n && resized(frame, id, before, pose)) queue.push(id);\n };\n let current: NodeId | null = null;\n\n /** The container and its children as the strategy sees them, in world,\n * with every write this pass has made so far folded in. */\n const frameOf = (containerId: NodeId) => {\n const pose = world(containerId);\n const bounds = frame.bounds(pose, containerId);\n if (bounds === null) return null;\n const children: LayoutChild<TPose>[] = source.childrenOf(containerId).map((cid) => ({\n id: cid as string,\n pose: world(cid),\n }));\n return { world: pose, container: { id: containerId as string, bounds }, children };\n };\n const apply = (\n containerId: NodeId,\n at: NonNullable<ReturnType<typeof frameOf>>,\n result: LayoutArrival<TPose>,\n ): void => {\n if (result.bounds) {\n const node = source.get(containerId)!;\n const sized = frame.remap(at.world, at.container.bounds, result.bounds, containerId);\n write(containerId, rebaseLocalPose(pa, sized, node.parent, compose, decompose));\n }\n for (const [cid, pose] of result.poses) {\n const id = cid as NodeId;\n if (source.get(id)?.parent !== containerId) continue;\n const before = frame.bounds(world(id), id);\n write(id, rebaseLocalPose(pa, pose, containerId, compose, decompose));\n carry(id, before);\n }\n };\n /** Moves `id`'s descendants by however far its write just moved it from `before`. */\n const carry = (id: NodeId, before: ContainerBounds | null): void => {\n const after = frame.bounds(world(id), id);\n if (before === null || after === null) return;\n const dx = after.x - before.x;\n const dy = after.y - before.y;\n if (dx === 0 && dy === 0) return;\n const carried = carriedDescendants(\n { childrenOf: (cid) => source.childrenOf(cid), poses: pa, composition: source.composition },\n id,\n (pose, cid) => {\n const b = frame.bounds(pose, cid);\n return b === null ? null : frame.remap(pose, b, { ...b, x: b.x + dx, y: b.y + dy }, cid);\n },\n );\n for (const [cid, pose] of carried) write(cid, pose);\n };\n\n while (queue.length > 0) {\n const containerId = queue.shift()!;\n current = containerId;\n const n = (passes.get(containerId) ?? 0) + 1;\n passes.set(containerId, n);\n if (n > MAX_PASSES) continue;\n const layout = layoutOf(containerId);\n if (layout === null || source.get(containerId) === undefined) continue;\n const joined = n === 1 ? arrivals.get(containerId) : undefined;\n const left = n === 1 ? departures.get(containerId) : undefined;\n let arranged = false;\n if (left !== undefined && layout.depart) {\n const at = frameOf(containerId);\n if (at === null) continue;\n const joinedSet = new Set<string>(joined ?? []);\n const staying = at.children.filter((c) => !joinedSet.has(c.id));\n apply(containerId, at, layout.depart(at.container, staying, new Set<string>(left)));\n arranged = true;\n }\n if (joined !== undefined && layout.arrive) {\n const at = frameOf(containerId);\n if (at === null) continue;\n const result = layout.arrive(at.container, at.children, new Set<string>(joined));\n if (result === null) return null;\n apply(containerId, at, result);\n } else if (!arranged || joined !== undefined) {\n const at = frameOf(containerId);\n if (at === null) continue;\n apply(containerId, at, { poses: layout.childPoses(at.container, at.children) });\n }\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBAA0B,OAAmE;CAC3G,OAAO;EACL,QAAQ,OAAO,YAAY,SAAS;GAClC,MAAM,IAAI,WAAW,IAAI;GACzB,OAAO,MAAM,OAAO,OAAO;IAAE,GAAG,EAAE;IAAG,GAAG,EAAE;IAAG,OAAO,EAAE;IAAO,QAAQ,EAAE;GAAO;EAChF;EACA,OAAO,OAAO,WAAW,MAAM,OAAO,QAAQ;GAAE,GAAI;GAAiB,GAAG;EAAG;CAC7E;AACF;;AAGA,SAAgB,QAAe,OAAmC,IAAY,MAAa,IAAoB;CAC7G,MAAM,IAAI,MAAM,OAAO,MAAM,EAAE;CAC/B,MAAM,IAAI,MAAM,OAAO,IAAI,EAAE;CAC7B,IAAI,MAAM,QAAQ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key, so a spread
|
|
3
|
+
* of the node (`{ ...node, pose }`) carries it, and applying an override to a
|
|
4
|
+
* copy of a shown node is a no-op however the copy was made. */
|
|
5
|
+
var SHOWN = Symbol("weasel.shownData");
|
|
6
|
+
/** Per stored node, the last shown copy and what it was made from: keeping it
|
|
7
|
+
* is what lets a memo keyed on the node, or on its data, hit frame to frame
|
|
8
|
+
* while neither changes. */
|
|
9
|
+
var shownCopies = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
/**
|
|
11
|
+
* `node` with its `data` replaced by what its override's `data` answers from
|
|
12
|
+
* it, or `node` itself when nothing overrides its data or its data is already
|
|
13
|
+
* shown. The same object while the stored node, its data and the override's
|
|
14
|
+
* function are unchanged.
|
|
15
|
+
*/
|
|
16
|
+
function nodeAsShown(overrides, node) {
|
|
17
|
+
if (SHOWN in node) return node;
|
|
18
|
+
const data = overrides.read(node.id)?.data;
|
|
19
|
+
if (data === void 0) return node;
|
|
20
|
+
const held = shownCopies.get(node);
|
|
21
|
+
if (held !== void 0 && held.data === data && held.stored === node.data) return held.shown;
|
|
22
|
+
const shown = withShownData(node, data(node.data));
|
|
23
|
+
shownCopies.set(node, {
|
|
24
|
+
stored: node.data,
|
|
25
|
+
data,
|
|
26
|
+
shown
|
|
27
|
+
});
|
|
28
|
+
return shown;
|
|
29
|
+
}
|
|
30
|
+
/** `node` showing `data`, marked so that no override applies to it again: for
|
|
31
|
+
* a reader that already holds the data to show, such as a gesture's ghost. */
|
|
32
|
+
function withShownData(node, data) {
|
|
33
|
+
return {
|
|
34
|
+
...node,
|
|
35
|
+
data,
|
|
36
|
+
[SHOWN]: true
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The last copy `nodeAsShown` made of `node`, if any — what a reader handed
|
|
40
|
+
* the shown node memoized against, for invalidating with the stored one. */
|
|
41
|
+
function shownCopyOf(node) {
|
|
42
|
+
return shownCopies.get(node)?.shown;
|
|
43
|
+
}
|
|
44
|
+
/** `source`'s `get`, answering each node as it shows. For a reader that walks
|
|
45
|
+
* up from a node, such as inherited paint looking through its containers. */
|
|
46
|
+
function shownLookup(source) {
|
|
47
|
+
return { get: (id) => {
|
|
48
|
+
const node = source.get(id);
|
|
49
|
+
return node === void 0 ? void 0 : nodeAsShown(source.overrides, node);
|
|
50
|
+
} };
|
|
51
|
+
}
|
|
52
|
+
/** Per overrides table, whether any entry shows data, as of a generation. */
|
|
53
|
+
var anyData = /* @__PURE__ */ new WeakMap();
|
|
54
|
+
/** `nodes`, each as it shows; the same array when nothing overrides any node's
|
|
55
|
+
* data. Answers that from the table's generation, so a pick with nothing
|
|
56
|
+
* overridden allocates nothing. */
|
|
57
|
+
function nodesAsShown(overrides, nodes) {
|
|
58
|
+
const at = overrides.getGeneration();
|
|
59
|
+
let held = anyData.get(overrides);
|
|
60
|
+
if (held === void 0 || held.at !== at) {
|
|
61
|
+
held = {
|
|
62
|
+
at,
|
|
63
|
+
any: overrides.ids().some((id) => overrides.read(id)?.data !== void 0)
|
|
64
|
+
};
|
|
65
|
+
anyData.set(overrides, held);
|
|
66
|
+
}
|
|
67
|
+
return held.any ? nodes.map((node) => nodeAsShown(overrides, node)) : nodes;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { nodeAsShown, nodesAsShown, shownCopyOf, shownLookup, withShownData };
|
|
72
|
+
//# sourceMappingURL=nodeAsShown.js.map
|