@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSceneStandardActions.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useSceneStandardActions.ts"],"sourcesContent":["import type { Action } from '@weasel-js/routing';\nimport type { Dispatcher } from '@weasel-js/routing';\nimport { useActionsRegistry, useDepSource } from '@weasel-js/routing/react';\nimport type { Scene } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport { useDecayLoop } from 'core/viewport/useDecayLoop';\nimport type { ViewAnimationApi } from 'core/viewport/useViewAnimation';\nimport type { View } from 'core/viewport/view';\nimport type { ClipboardIngestCtx } from 'interactions/actions/depSchema';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport { useActionSet, useStandardDeps } from 'interactions/actions/useActionSet';\nimport { drawnBoxes } from 'interactions/actions/drawnBoxes';\nimport type React from 'react';\nimport { useEffect, useMemo } from 'react';\nimport type { ReflowTransition } from '../../layout/types';\nimport type { SnapOutcomeStore } from 'features/snap/outcomeStore';\nimport type { SnapSourceRegistry } from 'features/snap/registry';\nimport type { SnapSource } from 'features/snap/types';\nimport type { CanvasExtensionApi } from '../canvasExtension';\nimport {\n useAreaSelectDepSource,\n useDebugDepSource,\n usePreviewPathsDepSource,\n useDepChangeNotices,\n useDispatcherDepSource,\n useEditAnchorsDepSource,\n useIngestionDepSource,\n useInsertDepSource,\n useLassoSelectDepSource,\n useLayoutDepSource,\n useNodeAtPointDepSource,\n usePoseDescriptorDepSource,\n usePathLeafDepSources,\n useSnapDepSource,\n useSurfaceDepSources,\n useTextEditDepSource,\n useViewDepSource,\n} from '../deps';\nimport type { BridgeAdapter, SceneCanvasProps } from './props';\nimport { useActionsPropResolver } from './useActionsPropResolver';\nimport { useActionTunings } from './useActionTunings';\nimport { useViewportActions, viewportZoomOption } from './useViewportActions';\n\n/** The `<SceneCanvas>` props the standard actions and their deps read. */\nexport type StandardActionsProps = Pick<\n SceneCanvasProps<unknown, string, unknown>,\n | 'actions' | 'tune' | 'geometry' | 'viewport' | 'layoutDropTarget'\n | 'reflowTransition' | 'insertNodeFactories' | 'insertPaint' | 'ingestion' | 'snap'\n>;\n\n/** What `<SceneCanvas>` hands {@link useSceneStandardActions}. */\nexport interface SceneStandardActionsInputs {\n props: StandardActionsProps;\n /** Whether the `view` preset is on; without it the viewport actions are off. */\n viewOn: boolean;\n selection: SelectionApi;\n scene: Scene<unknown, string, unknown>;\n adapter: BridgeAdapter;\n /** The standard actions this canvas registers: its presets' and the ones\n * its tools bind, in registration order. */\n standardActions: readonly Action[];\n currentViewRef: React.RefObject<View>;\n onViewChange: (v: View) => void;\n /** Wires the `poseDescriptor` dep every built-in pose-touching action reads. */\n poseDescriptor: PoseDescriptor<unknown>;\n /** Forwarded so `cancelGestureAction` and other actions that need to\n * abort in-flight handles can read the dispatcher's control surface. */\n dispatcher: Dispatcher;\n /** World-space picker forwarded so the `nodeAtPoint` dep source can\n * reuse the same hit-test plumbing the tool dispatcher uses. */\n pickEvery: (worldX: number, worldY: number) => string[];\n /** This canvas's own view gate for scene layers, published on the `view`\n * dep and read by the selecting actions. Absent when it hides nothing. */\n layerIsPainted?: (layerId: string) => boolean;\n /** The composed paint alpha, when the consumer fades anything, so a region\n * select passes over what is painted at zero. */\n alphaOf?: (id: string) => number;\n /** The canvas's camera runner, published on the `view` dep so\n * `viewport.zoom`'s discrete branches can animate. */\n viewAnimation: ViewAnimationApi;\n /** Lifted edit-mode state so the `pathEditingOverlay` chrome (rendered\n * outside this subtree) can read the same `editingId` the dep does. */\n editAnchorsExternalState: import('../deps/editAnchors').EditAnchorsStateSource;\n /** The snap sources a session asks: the prop's and the presets', then the registry's. */\n snap: { sources: readonly SnapSource[]; registry: SnapSourceRegistry | null; store: SnapOutcomeStore };\n /** The canvas element ref, so `useIngestionDepSource` can compute the\n * visible world rect from the client rect + current view. */\n canvasRef: React.RefObject<HTMLElement | null>;\n /** The canvas handle, whose debug sink backs the `debug` dep. */\n canvasApiRef: React.RefObject<CanvasExtensionApi | null>;\n /** Clipboard-paste ctx (this canvas's adapter + the consumer's reviver)\n * for the kit weasel-JSON handler, from `useCanvasIngestion`; absent\n * when disabled. */\n ingestionClipboard?: ClipboardIngestCtx;\n}\n\n/**\n * Registers this canvas's standard actions, and the deps they read, into its\n * input scope, then applies the `actions` prop and `tune` over them.\n *\n * Called from a component ahead of `<SceneCanvas>`'s children, never from the\n * canvas's own body: registrations stack newest-live in effect order, and a\n * parent's effects run after its children's, so a child's override would lose.\n */\nexport function useSceneStandardActions(inputs: SceneStandardActionsInputs): void {\n const {\n props, viewOn, selection, scene, adapter, standardActions, currentViewRef,\n onViewChange, poseDescriptor, dispatcher, pickEvery, layerIsPainted, alphaOf, viewAnimation,\n editAnchorsExternalState, snap, canvasRef, canvasApiRef, ingestionClipboard,\n } = inputs;\n const { tune, viewport, ingestion } = props;\n const boundsIncludeStroke = props.geometry?.boundsIncludeStroke ?? true;\n const reflowTransition = props.reflowTransition as ReflowTransition<unknown> | null | undefined;\n const viewportZoom = useMemo(\n () => viewportZoomOption(viewport?.zoom, viewport?.animatedZoom),\n [viewport?.zoom, viewport?.animatedZoom],\n );\n const registry = useActionsRegistry();\n\n // Wire the dispatcher into the registry so registry.begin() can delegate\n // to dispatcher.beginUiOngoing() for UI-driven ongoing actions (color,\n // opacity).\n useEffect(() => {\n if (!registry) return;\n return registry.setDispatcher(dispatcher);\n }, [registry, dispatcher]);\n\n // Momentum for `viewport.dragPan`. The loop must be a hook (it owns a\n // `useVisibleRaf`), so it is built here and republished on the view dep.\n const decayLoop = useDecayLoop();\n\n // Build the ViewApi (stable identity, refreshed closures) and hand it to\n // useStandardDeps (which publishes the `view` dep along with selection,\n // scene, history, activeTool). `hostSize` reads the live canvas\n // element so keyboard zoom (Cmd+=/-) can anchor at the visible center.\n const view = useViewDepSource(\n currentViewRef,\n onViewChange,\n viewport?.recenter,\n () => {\n const el = canvasRef.current;\n return el ? { width: el.clientWidth, height: el.clientHeight } : null;\n },\n viewAnimation,\n decayLoop,\n layerIsPainted,\n );\n useStandardDeps({ selection, scene, view, history: scene.history });\n useActionSet(standardActions);\n // A view overlays `view` with its own camera; this name it leaves alone.\n useDepSource('rootView', () => view);\n useSurfaceDepSources(canvasRef, currentViewRef);\n useDepSource('actionParams', () => registry?.paramsOf);\n\n // viewport.pan / viewport.zoom are SceneCanvas-coupled (need the `view` dep\n // published just above), so they're registered here rather than in\n // KIT_STANDARD_DESCRIPTORS. Both default ON; consumer opts out via\n // `viewport={{ pan: false }}` / `viewport={{ zoom: false }}`.\n useViewportActions({\n pan: viewOn ? (viewport?.pan ?? true) : false,\n zoom: viewOn ? viewportZoom : false,\n pinchZoom: viewOn ? (viewport?.pinchZoom ?? true) : false,\n });\n\n // Per-dep wiring modules under `src/canvas/deps/`. See each file for the\n // dep's contract and trade-offs.\n useAreaSelectDepSource(scene, selection, poseDescriptor, alphaOf);\n useNodeAtPointDepSource(pickEvery);\n useLayoutDepSource(scene, props.layoutDropTarget, reflowTransition);\n useInsertDepSource(scene, adapter, props.insertNodeFactories, props.insertPaint);\n usePathLeafDepSources(scene, selection, adapter, poseDescriptor);\n useSnapDepSource(\n currentViewRef,\n {\n scene, boxes: () => drawnBoxes({ scene, poseDescriptor, view, boundsIncludeStroke }), sources: snap.sources,\n ...(snap.registry ? { registry: snap.registry } : {}),\n ...(props.snap?.reachPx !== undefined ? { reachPx: props.snap.reachPx } : {}),\n ...(props.snap?.omit ? { omit: props.snap.omit } : {}),\n ...(props.snap?.originProjection ? { originProjection: props.snap.originProjection } : {}),\n poseDescriptor,\n debug: () => canvasApiRef.current?.getDebug(),\n },\n snap.store,\n );\n useDebugDepSource(canvasApiRef);\n usePreviewPathsDepSource(canvasApiRef);\n useDepChangeNotices(scene, selection.current, editAnchorsExternalState);\n useIngestionDepSource(canvasRef, () => currentViewRef.current, ingestion?.resolveSrc, ingestion?.svg, ingestionClipboard);\n useLassoSelectDepSource(scene, selection, poseDescriptor, alphaOf);\n useTextEditDepSource(scene);\n useEditAnchorsDepSource(scene, selection, adapter, editAnchorsExternalState, tune);\n useDispatcherDepSource(dispatcher);\n usePoseDescriptorDepSource(poseDescriptor);\n useDepSource('boundsIncludeStroke', () => boundsIncludeStroke);\n\n // Keyed on the set too: a re-registration of it would otherwise land over\n // the overrides applied on top of it.\n useActionsPropResolver(props.actions, standardActions.map((a) => a.id).join('|'));\n useActionTunings(tune);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,wBAAwB,QAA0C;CAChF,MAAM,EACJ,OAAO,QAAQ,WAAW,OAAO,SAAS,iBAAiB,gBAC3D,cAAc,gBAAgB,YAAY,WAAW,gBAAgB,SAAS,eAC9E,0BAA0B,MAAM,WAAW,cAAc,uBACvD;CACJ,MAAM,EAAE,MAAM,UAAU,cAAc;CACtC,MAAM,sBAAsB,MAAM,UAAU,uBAAuB;CACnE,MAAM,mBAAmB,MAAM;CAC/B,MAAM,eAAe,cACb,mBAAmB,UAAU,MAAM,UAAU,YAAY,GAC/D,CAAC,UAAU,MAAM,UAAU,YA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aAAa,SAAS,SAAS;CAC9C,GACA,KAAK,KACP;CACA,kBAAkB,YAAY;CAC9B,yBAAyB,YAAY;CACrC,oBAAoB,OAAO,UAAU,SAAS,wBAAwB;CACtE,sBAAsB,iBAAiB,eAAe,SAAS,WAAW,YAAY,WAAW,KAAK,kBAAkB;CACxH,wBAAwB,OAAO,WAAW,gBAAgB,OAAO;CACjE,qBAAqB,KAAK;CAC1B,wBAAwB,OAAO,WAAW,SAAS,0BAA0B,IAAI;CACjF,uBAAuB,UAAU;CACjC,2BAA2B,cAAc;CACzC,aAAa,6BAA6B,mBAAmB;CAI7D,uBAAuB,MAAM,SAAS,gBAAgB,KAAK,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC;CAChF,iBAAiB,IAAI;AACvB"}
|
|
1
|
+
{"version":3,"file":"useSceneStandardActions.js","names":[],"sources":["../../../src/canvas/SceneCanvas/useSceneStandardActions.ts"],"sourcesContent":["import type { Action } from '@weasel-js/routing';\nimport type { Dispatcher } from '@weasel-js/routing';\nimport { useActionsRegistry, useDepSource } from '@weasel-js/routing/react';\nimport type { Scene } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport { useDecayLoop } from 'core/viewport/useDecayLoop';\nimport type { ViewAnimationApi } from 'core/viewport/useViewAnimation';\nimport type { View } from 'core/viewport/view';\nimport type { ClipboardIngestCtx } from 'interactions/actions/depSchema';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport { useActionSet, useStandardDeps } from 'interactions/actions/useActionSet';\nimport { drawnBoxes } from 'interactions/actions/drawnBoxes';\nimport type React from 'react';\nimport { useEffect, useMemo } from 'react';\nimport type { ReflowTransition } from '../../layout/types';\nimport type { SnapOutcomeStore } from 'features/snap/outcomeStore';\nimport type { SnapSourceRegistry } from 'features/snap/registry';\nimport type { SnapSource } from 'features/snap/types';\nimport type { CanvasExtensionApi } from '../canvasExtension';\nimport {\n useAreaSelectDepSource,\n useDebugDepSource,\n usePreviewPathsDepSource,\n useDepChangeNotices,\n useDispatcherDepSource,\n useEditAnchorsDepSource,\n useEnteredGroupApiSource,\n useIngestionDepSource,\n useInsertDepSource,\n useLassoSelectDepSource,\n useLayoutDepSource,\n useNodeAtPointDepSource,\n usePoseDescriptorDepSource,\n usePathLeafDepSources,\n useSnapDepSource,\n useSurfaceDepSources,\n useTextEditDepSource,\n useViewDepSource,\n} from '../deps';\nimport type { EnteredGroupApi } from '../deps/enteredGroup';\nimport type { BridgeAdapter, SceneCanvasProps } from './props';\nimport { useActionsPropResolver } from './useActionsPropResolver';\nimport { useActionTunings, useBindingOverrides } from './useActionTunings';\nimport { useViewportActions, viewportZoomOption } from './useViewportActions';\n\n/** The `<SceneCanvas>` props the standard actions and their deps read. */\nexport type StandardActionsProps = Pick<\n SceneCanvasProps<unknown, string, unknown>,\n | 'actions' | 'tune' | 'bindingOverrides' | 'geometry' | 'viewport' | 'layoutDropTarget'\n | 'reflowTransition' | 'insertNodeFactories' | 'insertPaint' | 'ingestion' | 'snap'\n>;\n\n/** What `<SceneCanvas>` hands {@link useSceneStandardActions}. */\nexport interface SceneStandardActionsInputs {\n props: StandardActionsProps;\n /** Whether the `view` preset is on; without it the viewport actions are off. */\n viewOn: boolean;\n selection: SelectionApi;\n /** The group a press resolves inside of, shared with the picking that names double-clicks. */\n enteredGroup: EnteredGroupApi;\n scene: Scene<unknown, string, unknown>;\n adapter: BridgeAdapter;\n /** The standard actions this canvas registers: its presets' and the ones\n * its tools bind, in registration order. */\n standardActions: readonly Action[];\n currentViewRef: React.RefObject<View>;\n onViewChange: (v: View) => void;\n /** Wires the `poseDescriptor` dep every built-in pose-touching action reads. */\n poseDescriptor: PoseDescriptor<unknown>;\n /** Forwarded so `cancelGestureAction` and other actions that need to\n * abort in-flight handles can read the dispatcher's control surface. */\n dispatcher: Dispatcher;\n /** World-space picker forwarded so the `nodeAtPoint` dep source can\n * reuse the same hit-test plumbing the tool dispatcher uses. */\n pickEvery: (worldX: number, worldY: number) => string[];\n /** This canvas's own view gate for scene layers, published on the `view`\n * dep and read by the selecting actions. Absent when it hides nothing. */\n layerIsPainted?: (layerId: string) => boolean;\n /** The composed paint alpha, when the consumer fades anything, so a region\n * select passes over what is painted at zero. */\n alphaOf?: (id: string) => number;\n /** Whether a node takes hits: what a region select may take, as a press may. */\n reachable?: (id: string) => boolean;\n /** The canvas's camera runner, published on the `view` dep so\n * `viewport.zoom`'s discrete branches can animate. */\n viewAnimation: ViewAnimationApi;\n /** Lifted edit-mode state so the `pathEditingOverlay` chrome (rendered\n * outside this subtree) can read the same `editingId` the dep does. */\n editAnchorsExternalState: import('../deps/editAnchors').EditAnchorsStateSource;\n /** The snap sources a session asks: the prop's and the presets', then the registry's. */\n snap: { sources: readonly SnapSource[]; registry: SnapSourceRegistry | null; store: SnapOutcomeStore };\n /** The canvas element ref, so `useIngestionDepSource` can compute the\n * visible world rect from the client rect + current view. */\n canvasRef: React.RefObject<HTMLElement | null>;\n /** The canvas handle, whose debug sink backs the `debug` dep. */\n canvasApiRef: React.RefObject<CanvasExtensionApi | null>;\n /** Clipboard-paste ctx (this canvas's adapter + the consumer's reviver)\n * for the kit weasel-JSON handler, from `useCanvasIngestion`; absent\n * when disabled. */\n ingestionClipboard?: ClipboardIngestCtx;\n}\n\n/**\n * Registers this canvas's standard actions, and the deps they read, into its\n * input scope, then applies the `actions` prop and `tune` over them.\n *\n * Called from a component ahead of `<SceneCanvas>`'s children, never from the\n * canvas's own body: registrations stack newest-live in effect order, and a\n * parent's effects run after its children's, so a child's override would lose.\n */\nexport function useSceneStandardActions(inputs: SceneStandardActionsInputs): void {\n const {\n props, viewOn, selection, enteredGroup, scene, adapter, standardActions, currentViewRef,\n onViewChange, poseDescriptor, dispatcher, pickEvery, layerIsPainted, alphaOf, reachable, viewAnimation,\n editAnchorsExternalState, snap, canvasRef, canvasApiRef, ingestionClipboard,\n } = inputs;\n const { tune, viewport, ingestion } = props;\n const boundsIncludeStroke = props.geometry?.boundsIncludeStroke ?? true;\n const reflowTransition = props.reflowTransition as ReflowTransition<unknown> | null | undefined;\n const viewportZoom = useMemo(\n () => viewportZoomOption(viewport?.zoom, viewport?.animatedZoom),\n [viewport?.zoom, viewport?.animatedZoom],\n );\n const registry = useActionsRegistry();\n\n // Wire the dispatcher into the registry so registry.begin() can delegate\n // to dispatcher.beginUiOngoing() for UI-driven ongoing actions (color,\n // opacity).\n useEffect(() => {\n if (!registry) return;\n return registry.setDispatcher(dispatcher);\n }, [registry, dispatcher]);\n\n // Momentum for `viewport.dragPan`. The loop must be a hook (it owns a\n // `useVisibleRaf`), so it is built here and republished on the view dep.\n const decayLoop = useDecayLoop();\n\n // Build the ViewApi (stable identity, refreshed closures) and hand it to\n // useStandardDeps (which publishes the `view` dep along with selection,\n // scene, history, activeTool). `hostSize` reads the live canvas\n // element so keyboard zoom (Cmd+=/-) can anchor at the visible center.\n const view = useViewDepSource(\n currentViewRef,\n onViewChange,\n viewport?.recenter,\n () => {\n const el = canvasRef.current;\n return el ? { width: el.clientWidth, height: el.clientHeight } : null;\n },\n viewAnimation,\n decayLoop,\n layerIsPainted,\n );\n useStandardDeps({ selection, scene, view, history: scene.history });\n useActionSet(standardActions);\n // A view overlays `view` with its own camera; this name it leaves alone.\n useDepSource('rootView', () => view);\n useSurfaceDepSources(canvasRef, currentViewRef);\n useDepSource('actionParams', () => registry?.paramsOf);\n\n // viewport.pan / viewport.zoom are SceneCanvas-coupled (need the `view` dep\n // published just above), so they're registered here rather than in\n // KIT_STANDARD_DESCRIPTORS. Both default ON; consumer opts out via\n // `viewport={{ pan: false }}` / `viewport={{ zoom: false }}`.\n useViewportActions({\n pan: viewOn ? (viewport?.pan ?? true) : false,\n zoom: viewOn ? viewportZoom : false,\n pinchZoom: viewOn ? (viewport?.pinchZoom ?? true) : false,\n });\n\n // Per-dep wiring modules under `src/canvas/deps/`. See each file for the\n // dep's contract and trade-offs.\n useAreaSelectDepSource(scene, selection, poseDescriptor, alphaOf, reachable);\n useNodeAtPointDepSource(pickEvery);\n useLayoutDepSource(scene, props.layoutDropTarget, reflowTransition);\n useEnteredGroupApiSource(enteredGroup);\n useInsertDepSource(scene, adapter, props.insertNodeFactories, props.insertPaint);\n usePathLeafDepSources(scene, selection, adapter, poseDescriptor);\n useSnapDepSource(\n currentViewRef,\n {\n scene, boxes: () => drawnBoxes({ scene, poseDescriptor, view, boundsIncludeStroke }), sources: snap.sources,\n ...(snap.registry ? { registry: snap.registry } : {}),\n ...(props.snap?.reachPx !== undefined ? { reachPx: props.snap.reachPx } : {}),\n ...(props.snap?.omit ? { omit: props.snap.omit } : {}),\n ...(props.snap?.originProjection ? { originProjection: props.snap.originProjection } : {}),\n poseDescriptor,\n debug: () => canvasApiRef.current?.getDebug(),\n },\n snap.store,\n );\n useDebugDepSource(canvasApiRef);\n usePreviewPathsDepSource(canvasApiRef);\n useDepChangeNotices(scene, selection.current, editAnchorsExternalState);\n useIngestionDepSource(canvasRef, () => currentViewRef.current, ingestion?.resolveSrc, ingestion?.svg, ingestionClipboard);\n useLassoSelectDepSource(scene, selection, poseDescriptor, alphaOf, reachable);\n useTextEditDepSource(scene);\n useEditAnchorsDepSource(scene, selection, adapter, editAnchorsExternalState, tune);\n useDispatcherDepSource(dispatcher);\n usePoseDescriptorDepSource(poseDescriptor);\n useDepSource('boundsIncludeStroke', () => boundsIncludeStroke);\n\n // Keyed on the set too: a re-registration of it would otherwise land over\n // the overrides applied on top of it.\n useActionsPropResolver(props.actions, standardActions.map((a) => a.id).join('|'));\n useActionTunings(tune);\n useBindingOverrides(props.bindingOverrides);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8GA,SAAgB,wBAAwB,QAA0C;CAChF,MAAM,EACJ,OAAO,QAAQ,WAAW,cAAc,OAAO,SAAS,iBAAiB,gBACzE,cAAc,gBAAgB,YAAY,WAAW,gBAAgB,SAAS,WAAW,eACzF,0BAA0B,MAAM,WAAW,cAAc,uBACvD;CACJ,MAAM,EAAE,MAAM,U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,KAAK,QAAQ,IAAI,CAAC;EAC3E,GAAI,MAAM,MAAM,OAAO,EAAE,MAAM,MAAM,KAAK,KAAK,IAAI,CAAC;EACpD,GAAI,MAAM,MAAM,mBAAmB,EAAE,kBAAkB,MAAM,KAAK,iBAAiB,IAAI,CAAC;EACxF;EACA,aAAa,aAAa,SAAS,SAAS;CAC9C,GACA,KAAK,KACP;CACA,kBAAkB,YAAY;CAC9B,yBAAyB,YAAY;CACrC,oBAAoB,OAAO,UAAU,SAAS,wBAAwB;CACtE,sBAAsB,iBAAiB,eAAe,SAAS,WAAW,YAAY,WAAW,KAAK,kBAAkB;CACxH,wBAAwB,OAAO,WAAW,gBAAgB,SAAS,SAAS;CAC5E,qBAAqB,KAAK;CAC1B,wBAAwB,OAAO,WAAW,SAAS,0BAA0B,IAAI;CACjF,uBAAuB,UAAU;CACjC,2BAA2B,cAAc;CACzC,aAAa,6BAA6B,mBAAmB;CAI7D,uBAAuB,MAAM,SAAS,gBAAgB,KAAK,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC;CAChF,iBAAiB,IAAI;CACrB,oBAAoB,MAAM,gBAAgB;AAC5C"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DeviceProfileProvider, useDeviceProfile } from "../core/device/useDeviceProfile.js";
|
|
2
2
|
import { AUTO_POSE_DESCRIPTOR } from "../core/geometry/autoPoseDescriptor.js";
|
|
3
3
|
import { ViewRegistryProvider } from "./viewRegistry.js";
|
|
4
|
-
import { CanvasView } from "./CanvasView.js";
|
|
5
4
|
import { rotateAroundAABBCenter } from "./poseRotation.js";
|
|
6
5
|
import { defaultDrawOne } from "./defaultDrawOne.js";
|
|
6
|
+
import { chromeColorOf, watchThemeOf } from "./accentColor.js";
|
|
7
7
|
import { CORE_PRESET_SOURCE } from "./SceneCanvas/namedPresets.js";
|
|
8
|
+
import { useGroupEntryContribution } from "../tools/builtin/select/groupEntry.js";
|
|
8
9
|
import { useCanvasCamera } from "./SceneCanvas/useCanvasCamera.js";
|
|
9
10
|
import { useHeldModifiers } from "./SceneCanvas/useHeldModifiers.js";
|
|
10
11
|
import { useCanvasIngestion } from "../features/ingestion/useCanvasIngestion.js";
|
|
@@ -17,13 +18,16 @@ import { contributionEntries } from "./SceneCanvas/useContributionRoles.js";
|
|
|
17
18
|
import { SceneCanvasInput } from "./SceneCanvas/SceneCanvasInput.js";
|
|
18
19
|
import { useBakedScene } from "./SceneCanvas/useBakedScene.js";
|
|
19
20
|
import { useCanvasDispatcher } from "./SceneCanvas/useCanvasDispatcher.js";
|
|
21
|
+
import { publishPreviews } from "./publishPreviews.js";
|
|
20
22
|
import { useCanvasSelection } from "./SceneCanvas/useCanvasSelection.js";
|
|
21
23
|
import { SCENE_CANVAS_FEATURES } from "./SceneCanvas/features.js";
|
|
22
24
|
import { BUILTIN_TOOLS, BUILTIN_TOOL_IDS, DRAW_TOOLS, PAGE_TOOLS, SELECT_TOOLS, SHAPE_TOOLS, TYPE_TOOLS, VIEW_TOOLS } from "./SceneCanvas/builtinToolSets.js";
|
|
23
25
|
import { DEFAULT_HANDLE_SIZE } from "./SceneCanvas/props.js";
|
|
24
26
|
import { useEnabledFeatures } from "./SceneCanvas/useCanvasTools.js";
|
|
27
|
+
import { SurfaceDeclarations } from "./SceneCanvas/SurfaceDeclarations.js";
|
|
25
28
|
import { useAddedViews, useSceneCanvasHandle } from "./SceneCanvas/useSceneCanvasHandle.js";
|
|
26
29
|
import { mergeLayersWithDefaults } from "./SceneCanvas/mergeLayers.js";
|
|
30
|
+
import { ENTERED_FRAME_COLOR, ENTERED_FRAME_TOKEN } from "../features/selection/enteredGroupFrame.js";
|
|
27
31
|
import { useSceneCanvasLayers } from "./SceneCanvas/useSceneCanvasLayers.js";
|
|
28
32
|
import { useSceneCanvasPathEdit } from "./SceneCanvas/useSceneCanvasPathEdit.js";
|
|
29
33
|
import { useSceneCanvasTools } from "./SceneCanvas/useSceneCanvasTools.js";
|
|
@@ -32,10 +36,10 @@ import { useSceneRedrawSources } from "./SceneCanvas/useSceneRedrawSources.js";
|
|
|
32
36
|
import { useScenePicking } from "./SceneCanvas/useScenePicking.js";
|
|
33
37
|
import { useNodeKinds } from "./SceneCanvas/useNodeKinds.js";
|
|
34
38
|
import { useSurfaceViewInputs } from "./SceneCanvas/useSurfaceViewInputs.js";
|
|
35
|
-
import { forwardRef, useMemo, useRef } from "react";
|
|
39
|
+
import { forwardRef, useEffect, useMemo, useRef } from "react";
|
|
36
40
|
import { useLatest } from "@weasel-js/react";
|
|
37
|
-
import { InputScope, useActionsRegistry } from "@weasel-js/routing/react";
|
|
38
41
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
42
|
+
import { InputScope, useActionsRegistry } from "@weasel-js/routing/react";
|
|
39
43
|
import { getActiveModeFor } from "@weasel-js/modes";
|
|
40
44
|
|
|
41
45
|
//#region src/canvas/SceneCanvas.tsx
|
|
@@ -100,21 +104,34 @@ function SceneCanvasInner(props, ref) {
|
|
|
100
104
|
});
|
|
101
105
|
const { adapter, boundsOf, planeOfNode } = picking;
|
|
102
106
|
const getNodeAtPointRef = useLatest(picking.getNodeAtPoint);
|
|
107
|
+
const groupEntry = useGroupEntryContribution({
|
|
108
|
+
pickHit: picking.pickBest,
|
|
109
|
+
tree: adapter,
|
|
110
|
+
boxOf: boundsOf
|
|
111
|
+
});
|
|
103
112
|
const tools = useSceneCanvasTools({
|
|
104
113
|
props,
|
|
105
114
|
select: picking.selectTool,
|
|
106
115
|
move: picking.moveOptions,
|
|
107
116
|
enabled,
|
|
108
|
-
presetSource: props.presetSource
|
|
117
|
+
presetSource: props.presetSource,
|
|
118
|
+
groupEntry
|
|
109
119
|
});
|
|
110
120
|
const actionsRegistry = useActionsRegistry();
|
|
111
121
|
const { dispatcher, gestureSource, previewIdsExtra, previewPoseExtra } = useCanvasDispatcher(actionsRegistry);
|
|
122
|
+
useEffect(() => publishPreviews(scene, dispatcher), [scene, dispatcher]);
|
|
123
|
+
const frameColor = useMemo(() => ({
|
|
124
|
+
read: () => chromeColorOf(internalCanvasRef.current, ENTERED_FRAME_TOKEN, ENTERED_FRAME_COLOR),
|
|
125
|
+
changed: (fn) => watchThemeOf(() => internalCanvasRef.current, fn)
|
|
126
|
+
}), []);
|
|
112
127
|
const layered = useSceneCanvasLayers({
|
|
113
128
|
layers: props.layers,
|
|
114
129
|
targetScale: deviceProfile.targetScale,
|
|
115
130
|
scene,
|
|
116
131
|
adapter,
|
|
117
132
|
poseDescriptor: descriptor,
|
|
133
|
+
enteredGroup: picking.enteredGroup,
|
|
134
|
+
frameColor,
|
|
118
135
|
alphaFor: props.alphaFor,
|
|
119
136
|
colorOverrides: props.animator?.colorOverrides,
|
|
120
137
|
boundsOf,
|
|
@@ -159,7 +176,7 @@ function SceneCanvasInner(props, ref) {
|
|
|
159
176
|
dispatcher
|
|
160
177
|
});
|
|
161
178
|
const { ingest, clipboard: ingestionClipboard } = useCanvasIngestion(adapter, () => actionsRegistry, props.ingestion);
|
|
162
|
-
const { views: addedViews, addView, viewAt } = useAddedViews();
|
|
179
|
+
const { views: addedViews, addView, viewAt, aimOf, setAim } = useAddedViews();
|
|
163
180
|
const { handleRef, ready: canvasReady } = useSceneCanvasHandle({
|
|
164
181
|
ref,
|
|
165
182
|
elementRef: internalCanvasRef,
|
|
@@ -169,7 +186,9 @@ function SceneCanvasInner(props, ref) {
|
|
|
169
186
|
viewAnimation,
|
|
170
187
|
camera,
|
|
171
188
|
addView,
|
|
172
|
-
viewAt
|
|
189
|
+
viewAt,
|
|
190
|
+
aimOf,
|
|
191
|
+
setAim
|
|
173
192
|
});
|
|
174
193
|
const viewInputs = useSurfaceViewInputs({
|
|
175
194
|
picking,
|
|
@@ -243,12 +262,11 @@ function SceneCanvasInner(props, ref) {
|
|
|
243
262
|
snapSources: enabled.snapSources,
|
|
244
263
|
snapStore: layered.snapStore
|
|
245
264
|
}),
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
addedViews.map((v) => /* @__PURE__ */ jsx(CanvasView, { ...v }, `added:${v.id}`)),
|
|
265
|
+
/* @__PURE__ */ jsx(SurfaceDeclarations, {
|
|
266
|
+
views: props.views,
|
|
267
|
+
entries: contributionEntries(tools.tools),
|
|
268
|
+
added: addedViews
|
|
269
|
+
}),
|
|
252
270
|
props.children
|
|
253
271
|
]
|
|
254
272
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneCanvas.js","names":[],"sources":["../../src/canvas/SceneCanvas.tsx"],"sourcesContent":["/**\n * `<SceneCanvas>` — `<Canvas>` wired to a `Scene` primitive. Bare, it only renders: behavior\n * comes from the `features` presets (`canvas/SceneCanvas/features.ts`), each of which turns on\n * its own actions, tools, ambient bindings, and chrome.\n *\n * A consumer needing custom tools can pass `tools={useTools(...)}` and SceneCanvas forwards it\n * as-is — the internal tool registry is ignored in that case.\n */\nimport { getActiveModeFor } from '@weasel-js/modes';\nimport { useLatest } from '@weasel-js/react';\nimport { InputScope, useActionsRegistry } from '@weasel-js/routing/react';\nimport type { NodeId, Scene } from 'core/scene/types';\nimport { useCanvasCamera } from './SceneCanvas/useCanvasCamera';\nimport { useHeldModifiers } from './SceneCanvas/useHeldModifiers';\nimport { useCanvasIngestion } from 'features/ingestion/useCanvasIngestion';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport type React from 'react';\nimport { forwardRef, useMemo, useRef } from 'react';\nimport { DeviceProfileProvider, useDeviceProfile } from '../core/device/useDeviceProfile';\nimport { Canvas } from './Canvas';\nimport { CanvasView } from './CanvasView';\nimport { canvasDebug, DevHuds } from './SceneCanvas/DevHuds';\nimport { CanvasKitProviders } from './SceneCanvas/CanvasKitProviders';\nimport { canvasPassThrough } from './SceneCanvas/canvasPassThrough';\nimport { SceneCanvasInput, type SceneCanvasInputOptions } from './SceneCanvas/SceneCanvasInput';\nimport type { PresetSource } from './SceneCanvas/features';\nimport { CORE_PRESET_SOURCE } from './SceneCanvas/namedPresets';\nimport type { BridgeAdapter, SceneCanvasProps } from './SceneCanvas/props';\nimport { useBakedScene } from './SceneCanvas/useBakedScene';\nimport { useCanvasDispatcher } from './SceneCanvas/useCanvasDispatcher';\nimport { useCanvasSelection } from './SceneCanvas/useCanvasSelection';\nimport { useEnabledFeatures } from './SceneCanvas/useCanvasTools';\nimport { contributionEntries } from './SceneCanvas/useContributionRoles';\nimport { useAddedViews, useSceneCanvasHandle } from './SceneCanvas/useSceneCanvasHandle';\nimport { useSceneCanvasLayers } from './SceneCanvas/useSceneCanvasLayers';\nimport { useSceneCanvasPathEdit } from './SceneCanvas/useSceneCanvasPathEdit';\nimport { useSceneCanvasTools, type SceneCanvasToolProps } from './SceneCanvas/useSceneCanvasTools';\nimport { useSceneCanvasChrome } from './SceneCanvas/useSceneChrome';\nimport { useDevtoolsOverride } from '../devtools/useDevtoolsRoot';\nimport { useSceneRedrawSources } from './SceneCanvas/useSceneRedrawSources';\nimport { useScenePicking } from './SceneCanvas/useScenePicking';\nimport { useNodeKinds } from './SceneCanvas/useNodeKinds';\nimport { useSurfaceViewInputs } from './SceneCanvas/useSurfaceViewInputs';\nimport type { CanvasExtensionApi, SceneCanvasApi } from './canvasExtension';\nimport { ViewRegistryProvider } from './viewRegistry';\nexport { SCENE_CANVAS_FEATURES, type Feature } from './SceneCanvas/features';\nexport type { BuiltinToolOptions } from './SceneCanvas/useBuiltinShapeTools';\nexport { defaultDrawOne } from './defaultDrawOne';\nexport { rotateAroundAABBCenter } from './poseRotation';\n\nfunction SceneCanvasInner<TData, TLayer extends string, TPose>(\n props: SceneCanvasProps<TData, TLayer, TPose> & { presetSource: PresetSource },\n ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n const { selectTool: selectToolOpts, selectable = true, viewport, modes } = props;\n const devtools = useDevtoolsOverride(props.debug), { debug } = devtools;\n const descriptor = (props.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const deviceProfile = useDeviceProfile();\n const scene = useBakedScene(props.scene);\n const getActiveMode = useMemo(() => (modes ? getActiveModeFor(modes) : undefined), [modes]);\n const heldModifiers = useHeldModifiers();\n\n // Our own refs, so input listeners attach even when the consumer forwards its own ref.\n const internalCanvasRef = useRef<HTMLElement | null>(null);\n const canvasApiRef = useRef<CanvasExtensionApi | null>(null);\n const declaredSize = useLatest({ width: props.width ?? 0, height: props.height ?? 0 });\n const { viewState, viewAnimation, camera } = useCanvasCamera({\n view: props.view, defaultView: props.defaultView, onViewChange: props.onViewChange, viewBounds: props.viewBounds,\n dims: () => canvasApiRef.current?.getSurfaceRect() ?? declaredSize.current,\n requestRedraw: () => { canvasApiRef.current?.requestRedraw(); },\n });\n const { viewRef } = viewState;\n const kinds = useNodeKinds(scene, props.routing);\n const selection = useCanvasSelection({ scene, props, selectable, kindOf: kinds.kindOf });\n const enabled = useEnabledFeatures(\n props.features, props.presetSource.named, viewport !== undefined, selectToolOpts?.rotate !== false,\n );\n const { pathEditState, selectToolWithDefaults } = useSceneCanvasPathEdit({\n host: props.pathEdit, opening: props.defaultPathEdit, getActiveMode, scene, selection,\n extensions: enabled.pathEdit, selectTool: selectToolOpts,\n });\n const picking = useScenePicking({ scene, selection, descriptor, props, viewRef, selectTool: selectToolWithDefaults, kinds });\n const { adapter, boundsOf, planeOfNode } = picking;\n const getNodeAtPointRef = useLatest(picking.getNodeAtPoint);\n const tools = useSceneCanvasTools({\n props: props as SceneCanvasToolProps, select: picking.selectTool, move: picking.moveOptions,\n enabled, presetSource: props.presetSource,\n });\n\n // The wrapper's `<InputScope>` provides it.\n const actionsRegistry = useActionsRegistry();\n const { dispatcher, gestureSource, previewIdsExtra, previewPoseExtra } = useCanvasDispatcher(actionsRegistry);\n\n const layered = useSceneCanvasLayers({\n layers: props.layers, targetScale: deviceProfile.targetScale, scene, adapter, poseDescriptor: descriptor,\n alphaFor: props.alphaFor, colorOverrides: props.animator?.colorOverrides, boundsOf, planeOfNode,\n poseTransition: props.poseTransition, previewIds: previewIdsExtra, dispatcher, snapReadout: props.snap?.readout !== false, snapReadoutStyle: props.snap?.readoutStyle, pathEditState,\n slops: debug !== undefined && debug !== false && debug.slops === true,\n boundsIncludeStroke: props.geometry?.boundsIncludeStroke ?? true, selectTool: selectToolOpts,\n });\n const redrawOn = useSceneRedrawSources({ props, scene, heldModifiers, departures: layered.departures });\n\n const chrome = useSceneCanvasChrome({\n source: {\n getMode: getActiveMode, getFocused: props.getFocused, getModifiers: heldModifiers.get,\n resizable: selectToolOpts?.resize?.resizable,\n editingAnchors: () => pathEditState.getEditingId() !== '',\n device: deviceProfile,\n },\n rules: { enabled, selectable, chromeVisibility: props.chromeVisibility },\n hover: { canvasApiRef, nodeAtPointRef: getNodeAtPointRef, ...(props.onHover ? { onChange: props.onHover } : {}) },\n selection: selection.current as readonly NodeId[], viewRef, dispatcher,\n });\n\n const { ingest, clipboard: ingestionClipboard } = useCanvasIngestion(adapter, () => actionsRegistry, props.ingestion);\n const { views: addedViews, addView, viewAt } = useAddedViews();\n // The consumer's handle extends the primitive's with `ingest`, which needs the action stack.\n const { handleRef, ready: canvasReady } = useSceneCanvasHandle({\n ref, elementRef: internalCanvasRef, apiRef: canvasApiRef, onElement: chrome.trackHoverOn,\n ingest, viewAnimation, camera, addView, viewAt,\n });\n const viewInputs = useSurfaceViewInputs({ picking, selection, resizeHandles: layered.resizeHandles,\n descriptor: descriptor as PoseDescriptor<unknown>, chromeCaps: chrome.chromeCaps, rotationBadge: layered.rotationBadge,\n });\n\n return (\n <CanvasKitProviders viewInputs={viewInputs}>\n <Canvas<TPose>\n ref={handleRef} adapter={adapter} selection={selection} poseDescriptor={descriptor}\n tools={tools.tools} layers={layered.layers}\n // The chrome's bounds are the picker's: a node on a parallax plane is\n // boxed where the plane draws it, and a `geometry.boundsOf` reaches both.\n boundsOf={boundsOf} boundsOfPose={picking.boundsOfPose}\n getIsVisible={chrome.getIsVisible}\n // The gesture surface behind `helpersRef.getGestureBounds()` /\n // `subscribeGestures()` — Canvas has no dispatcher of its own.\n gestureSource={gestureSource}\n previewPoseExtra={previewPoseExtra}\n {...(debug !== undefined ? { debug: canvasDebug(debug) } : {})}\n contentVersion={scene.getVersion} layerVisibility={props.layerVisibility} layerOrder={props.layerOrder}\n viewState={viewState} redrawOn={redrawOn}\n {...canvasPassThrough(props)}\n />\n <DevHuds\n cursorCoords={props.cursorCoordsHud} pick={props.pickHud} modality={props.modalityHud}\n canvasRef={internalCanvasRef} canvasApiRef={canvasApiRef}\n detachedInput={props.paintInto ? props.inputElement ?? null : undefined}\n viewRef={viewRef} pickEvery={picking.pickEvery} pickBest={picking.pickBest}\n />\n <SceneCanvasInput\n props={props as SceneCanvasInputOptions} scene={scene as Scene<unknown, string, unknown>}\n selection={selection} descriptor={descriptor as PoseDescriptor<unknown>}\n picking={{ ...picking, adapter: adapter as unknown as BridgeAdapter }} nodeAtPointRef={getNodeAtPointRef}\n tools={tools} viewOn={enabled.has('view')} camera={{ viewState, viewAnimation }}\n dispatcher={dispatcher} pathEdit={{ state: pathEditState }}\n chrome={chrome} overlay={layered} ingestionClipboard={ingestionClipboard} devtools={devtools}\n canvas={{ elementRef: internalCanvasRef, apiRef: canvasApiRef, ready: canvasReady }} snapSources={enabled.snapSources} snapStore={layered.snapStore}\n />\n {props.views?.map((v, i) => <CanvasView key={v.id} {...v} order={v.order ?? i} />)}\n {contributionEntries(tools.tools).flatMap((e) => e.views ?? []).map((v) => (\n <CanvasView key={`contribution:${v.id}`} {...v} />\n ))}\n {addedViews.map((v) => <CanvasView key={`added:${v.id}`} {...v} />)}\n {props.children}\n </CanvasKitProviders>\n );\n}\n\nconst SceneCanvasInnerForwardRef = forwardRef(SceneCanvasInner);\n\n// The canvas's input scope sits above `SceneCanvasInner`, whose own hooks\n// (`useTools` among them) must already read this canvas's tool and registries.\n// Its device profile too, so the canvas and everything under it share one.\n/** A scene canvas resolving its `features` through `source`. */\nexport function renderSceneCanvas<TData, TLayer extends string, TPose>(\n source: PresetSource,\n { device, ...props }: SceneCanvasProps<TData, TLayer, TPose>,\n ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n return (\n <InputScope yoke={props.yoke}>\n <DeviceProfileProvider value={device}>\n <ViewRegistryProvider>\n <SceneCanvasInnerForwardRef {...(props as SceneCanvasProps<unknown, string, unknown>)} presetSource={source} ref={ref} />\n </ViewRegistryProvider>\n </DeviceProfileProvider>\n </InputScope>\n );\n}\n\nfunction SceneCanvasWrapper<TData, TLayer extends string, TPose>(\n props: SceneCanvasProps<TData, TLayer, TPose>, ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n return renderSceneCanvas(CORE_PRESET_SOURCE, props, ref);\n}\n\n// Marked pure so a bundle using only `LeanSceneCanvas` drops it, and core's named presets with it.\n/**\n * The canvas component: renders a `Scene` and wires the interaction stack\n * around it.\n *\n * Mounted bare it renders the scene, keeps a selection no input sets, and\n * runs a gesture dispatcher for whatever bindings the consumer adds. The\n * `features` presets turn the kit's behavior on — `features={['draw']}` is the\n * whole editor: tools, standard actions and their keys, selection chrome,\n * undo. This is the intended entry point; the lower-level primitives it\n * composes are not part of the public surface.\n *\n * Its ref exposes a `SceneCanvasApi` for the imperative operations that do not\n * fit a prop (view control, hit queries, redraw requests).\n */\nexport const SceneCanvas = /* @__PURE__ */ forwardRef(SceneCanvasWrapper) as <\n TData, TLayer extends string, TPose,\n>(\n props: SceneCanvasProps<TData, TLayer, TPose> & { ref?: React.Ref<SceneCanvasApi> },\n) => ReturnType<typeof SceneCanvasInner>;\n\nexport { DEFAULT_HANDLE_SIZE, BUILTIN_TOOL_IDS } from './SceneCanvas/props';\nexport {\n BUILTIN_TOOLS, SELECT_TOOLS, VIEW_TOOLS, SHAPE_TOOLS, DRAW_TOOLS, TYPE_TOOLS, PAGE_TOOLS,\n} from './SceneCanvas/builtinToolSets';\nexport { mergeLayersWithDefaults } from './SceneCanvas/mergeLayers';\nexport type {\n SceneCanvasProps, SceneCanvasHit, Sce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AAa,WAAW,QAAQ;GAC3I,CAAA;GACA,MAAM,OAAO,KAAK,GAAG,MAAM,oBAAC,YAAD;IAAuB,GAAI;IAAG,OAAO,EAAE,SAAS;GAAI,GAAnC,EAAE,EAAiC,CAAC;GAChF,oBAAoB,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,MACnE,oBAAC,YAAD,EAAyC,GAAI,EAAI,GAAhC,gBAAgB,EAAE,IAAc,CAClD;GACA,WAAW,KAAK,MAAM,oBAAC,YAAD,EAAkC,GAAI,EAAI,GAAzB,SAAS,EAAE,IAAc,CAAC;GACjE,MAAM;EACW;;AAExB;AAEA,IAAM,6BAA6B,WAAW,gBAAgB;;AAM9D,SAAgB,kBACd,QACA,EAAE,QAAQ,GAAG,SACb,KACA;CACA,OACE,oBAAC,YAAD;EAAY,MAAM,MAAM;EACtB,UAAA,oBAAC,uBAAD;GAAuB,OAAO;GAC5B,UAAA,oBAAC,sBAAD,EAAA,UACE,oBAAC,4BAAD;IAA4B,GAAK;IAAsD,cAAc;IAAa;GAAM,CAAA,EACpG,CAAA;EACD,CAAA;CACb,CAAA;AAEhB;AAEA,SAAS,mBACP,OAA+C,KAC/C;CACA,OAAO,kBAAkB,oBAAoB,OAAO,GAAG;AACzD;;;;;;;;;;;;;;;AAiBA,IAAa,cAA8B,2BAAW,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"SceneCanvas.js","names":[],"sources":["../../src/canvas/SceneCanvas.tsx"],"sourcesContent":["/**\n * `<SceneCanvas>` — `<Canvas>` wired to a `Scene` primitive. Bare, it only renders: behavior\n * comes from the `features` presets (`canvas/SceneCanvas/features.ts`), each of which turns on\n * its own actions, tools, ambient bindings, and chrome.\n *\n * A consumer needing custom tools can pass `tools={useTools(...)}` and SceneCanvas forwards it\n * as-is — the internal tool registry is ignored in that case.\n */\nimport { getActiveModeFor } from '@weasel-js/modes';\nimport { useLatest } from '@weasel-js/react';\nimport { InputScope, useActionsRegistry } from '@weasel-js/routing/react';\nimport type { NodeId, Scene } from 'core/scene/types';\nimport { useCanvasCamera } from './SceneCanvas/useCanvasCamera';\nimport { useHeldModifiers } from './SceneCanvas/useHeldModifiers';\nimport { useCanvasIngestion } from 'features/ingestion/useCanvasIngestion';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport type React from 'react';\nimport { forwardRef, useEffect, useMemo, useRef } from 'react';\nimport { DeviceProfileProvider, useDeviceProfile } from '../core/device/useDeviceProfile';\nimport { Canvas } from './Canvas';\nimport { canvasDebug, DevHuds } from './SceneCanvas/DevHuds';\nimport { CanvasKitProviders } from './SceneCanvas/CanvasKitProviders';\nimport { canvasPassThrough } from './SceneCanvas/canvasPassThrough';\nimport { SceneCanvasInput, type SceneCanvasInputOptions } from './SceneCanvas/SceneCanvasInput';\nimport type { PresetSource } from './SceneCanvas/features';\nimport { CORE_PRESET_SOURCE } from './SceneCanvas/namedPresets';\nimport type { BridgeAdapter, SceneCanvasProps } from './SceneCanvas/props';\nimport { useBakedScene } from './SceneCanvas/useBakedScene';\nimport { useCanvasDispatcher } from './SceneCanvas/useCanvasDispatcher';\nimport { publishPreviews } from './publishPreviews';\nimport { useCanvasSelection } from './SceneCanvas/useCanvasSelection';\nimport { useEnabledFeatures } from './SceneCanvas/useCanvasTools';\nimport { contributionEntries } from './SceneCanvas/useContributionRoles';\nimport { SurfaceDeclarations } from './SceneCanvas/SurfaceDeclarations';\nimport { useAddedViews, useSceneCanvasHandle } from './SceneCanvas/useSceneCanvasHandle';\nimport { useSceneCanvasLayers } from './SceneCanvas/useSceneCanvasLayers';\nimport { useSceneCanvasPathEdit } from './SceneCanvas/useSceneCanvasPathEdit';\nimport { useSceneCanvasTools, type SceneCanvasToolProps } from './SceneCanvas/useSceneCanvasTools';\nimport { useSceneCanvasChrome } from './SceneCanvas/useSceneChrome';\nimport { useDevtoolsOverride } from '../devtools/useDevtoolsRoot';\nimport { useSceneRedrawSources } from './SceneCanvas/useSceneRedrawSources';\nimport { useScenePicking } from './SceneCanvas/useScenePicking';\nimport { useGroupEntryContribution } from 'tools/builtin/select/groupEntry';\nimport { useNodeKinds } from './SceneCanvas/useNodeKinds';\nimport { useSurfaceViewInputs } from './SceneCanvas/useSurfaceViewInputs';\nimport type { CanvasExtensionApi, SceneCanvasApi } from './canvasExtension';\nimport { ViewRegistryProvider } from './viewRegistry';\nimport { chromeColorOf, watchThemeOf } from './accentColor';\nimport { ENTERED_FRAME_COLOR, ENTERED_FRAME_TOKEN } from 'features/selection/enteredGroupFrame';\nexport { SCENE_CANVAS_FEATURES, type Feature } from './SceneCanvas/features';\nexport type { BuiltinToolOptions } from './SceneCanvas/useBuiltinShapeTools';\nexport { defaultDrawOne } from './defaultDrawOne';\nexport { rotateAroundAABBCenter } from './poseRotation';\n\nfunction SceneCanvasInner<TData, TLayer extends string, TPose>(\n props: SceneCanvasProps<TData, TLayer, TPose> & { presetSource: PresetSource },\n ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n const { selectTool: selectToolOpts, selectable = true, viewport, modes } = props;\n const devtools = useDevtoolsOverride(props.debug), { debug } = devtools;\n const descriptor = (props.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const deviceProfile = useDeviceProfile();\n const scene = useBakedScene(props.scene);\n const getActiveMode = useMemo(() => (modes ? getActiveModeFor(modes) : undefined), [modes]);\n const heldModifiers = useHeldModifiers();\n\n // Our own refs, so input listeners attach even when the consumer forwards its own ref.\n const internalCanvasRef = useRef<HTMLElement | null>(null);\n const canvasApiRef = useRef<CanvasExtensionApi | null>(null);\n const declaredSize = useLatest({ width: props.width ?? 0, height: props.height ?? 0 });\n const { viewState, viewAnimation, camera } = useCanvasCamera({\n view: props.view, defaultView: props.defaultView, onViewChange: props.onViewChange, viewBounds: props.viewBounds,\n dims: () => canvasApiRef.current?.getSurfaceRect() ?? declaredSize.current,\n requestRedraw: () => { canvasApiRef.current?.requestRedraw(); },\n });\n const { viewRef } = viewState;\n const kinds = useNodeKinds(scene, props.routing);\n const selection = useCanvasSelection({ scene, props, selectable, kindOf: kinds.kindOf });\n const enabled = useEnabledFeatures(\n props.features, props.presetSource.named, viewport !== undefined, selectToolOpts?.rotate !== false,\n );\n const { pathEditState, selectToolWithDefaults } = useSceneCanvasPathEdit({\n host: props.pathEdit, opening: props.defaultPathEdit, getActiveMode, scene, selection,\n extensions: enabled.pathEdit, selectTool: selectToolOpts,\n });\n const picking = useScenePicking({ scene, selection, descriptor, props, viewRef, selectTool: selectToolWithDefaults, kinds });\n const { adapter, boundsOf, planeOfNode } = picking;\n const getNodeAtPointRef = useLatest(picking.getNodeAtPoint);\n const groupEntry = useGroupEntryContribution({ pickHit: picking.pickBest, tree: adapter, boxOf: boundsOf });\n const tools = useSceneCanvasTools({\n props: props as SceneCanvasToolProps, select: picking.selectTool, move: picking.moveOptions,\n enabled, presetSource: props.presetSource, groupEntry,\n });\n\n // The wrapper's `<InputScope>` provides it.\n const actionsRegistry = useActionsRegistry();\n const { dispatcher, gestureSource, previewIdsExtra, previewPoseExtra } = useCanvasDispatcher(actionsRegistry);\n useEffect(() => publishPreviews(scene, dispatcher), [scene, dispatcher]);\n\n const frameColor = useMemo(() => ({\n read: () => chromeColorOf(internalCanvasRef.current, ENTERED_FRAME_TOKEN, ENTERED_FRAME_COLOR),\n changed: (fn: () => void) => watchThemeOf(() => internalCanvasRef.current, fn),\n }), []);\n const layered = useSceneCanvasLayers({\n layers: props.layers, targetScale: deviceProfile.targetScale, scene, adapter, poseDescriptor: descriptor,\n enteredGroup: picking.enteredGroup, frameColor, alphaFor: props.alphaFor, colorOverrides: props.animator?.colorOverrides, boundsOf, planeOfNode,\n poseTransition: props.poseTransition, previewIds: previewIdsExtra, dispatcher, snapReadout: props.snap?.readout !== false, snapReadoutStyle: props.snap?.readoutStyle, pathEditState,\n slops: debug !== undefined && debug !== false && debug.slops === true,\n boundsIncludeStroke: props.geometry?.boundsIncludeStroke ?? true, selectTool: selectToolOpts,\n });\n const redrawOn = useSceneRedrawSources({ props, scene, heldModifiers, departures: layered.departures });\n\n const chrome = useSceneCanvasChrome({\n source: {\n getMode: getActiveMode, getFocused: props.getFocused, getModifiers: heldModifiers.get,\n resizable: selectToolOpts?.resize?.resizable,\n editingAnchors: () => pathEditState.getEditingId() !== '',\n device: deviceProfile,\n },\n rules: { enabled, selectable, chromeVisibility: props.chromeVisibility },\n hover: { canvasApiRef, nodeAtPointRef: getNodeAtPointRef, ...(props.onHover ? { onChange: props.onHover } : {}) },\n selection: selection.current as readonly NodeId[], viewRef, dispatcher,\n });\n\n const { ingest, clipboard: ingestionClipboard } = useCanvasIngestion(adapter, () => actionsRegistry, props.ingestion);\n const { views: addedViews, addView, viewAt, aimOf, setAim } = useAddedViews();\n // The consumer's handle extends the primitive's with `ingest`, which needs the action stack.\n const { handleRef, ready: canvasReady } = useSceneCanvasHandle({\n ref, elementRef: internalCanvasRef, apiRef: canvasApiRef, onElement: chrome.trackHoverOn,\n ingest, viewAnimation, camera, addView, viewAt, aimOf, setAim,\n });\n const viewInputs = useSurfaceViewInputs({ picking, selection, resizeHandles: layered.resizeHandles,\n descriptor: descriptor as PoseDescriptor<unknown>, chromeCaps: chrome.chromeCaps, rotationBadge: layered.rotationBadge,\n });\n\n return (\n <CanvasKitProviders viewInputs={viewInputs}>\n <Canvas<TPose>\n ref={handleRef} adapter={adapter} selection={selection} poseDescriptor={descriptor}\n tools={tools.tools} layers={layered.layers}\n // The chrome's bounds are the picker's: a node on a parallax plane is\n // boxed where the plane draws it, and a `geometry.boundsOf` reaches both.\n boundsOf={boundsOf} boundsOfPose={picking.boundsOfPose}\n getIsVisible={chrome.getIsVisible}\n // The gesture surface behind `helpersRef.getGestureBounds()` /\n // `subscribeGestures()` — Canvas has no dispatcher of its own.\n gestureSource={gestureSource}\n previewPoseExtra={previewPoseExtra}\n {...(debug !== undefined ? { debug: canvasDebug(debug) } : {})}\n contentVersion={scene.getVersion} layerVisibility={props.layerVisibility} layerOrder={props.layerOrder}\n viewState={viewState} redrawOn={redrawOn}\n {...canvasPassThrough(props)}\n />\n <DevHuds\n cursorCoords={props.cursorCoordsHud} pick={props.pickHud} modality={props.modalityHud}\n canvasRef={internalCanvasRef} canvasApiRef={canvasApiRef}\n detachedInput={props.paintInto ? props.inputElement ?? null : undefined}\n viewRef={viewRef} pickEvery={picking.pickEvery} pickBest={picking.pickBest}\n />\n <SceneCanvasInput\n props={props as SceneCanvasInputOptions} scene={scene as Scene<unknown, string, unknown>}\n selection={selection} descriptor={descriptor as PoseDescriptor<unknown>}\n picking={{ ...picking, adapter: adapter as unknown as BridgeAdapter }} nodeAtPointRef={getNodeAtPointRef}\n tools={tools} viewOn={enabled.has('view')} camera={{ viewState, viewAnimation }}\n dispatcher={dispatcher} pathEdit={{ state: pathEditState }}\n chrome={chrome} overlay={layered} ingestionClipboard={ingestionClipboard} devtools={devtools}\n canvas={{ elementRef: internalCanvasRef, apiRef: canvasApiRef, ready: canvasReady }} snapSources={enabled.snapSources} snapStore={layered.snapStore}\n />\n <SurfaceDeclarations views={props.views} entries={contributionEntries(tools.tools)} added={addedViews} />\n {props.children}\n </CanvasKitProviders>\n );\n}\n\nconst SceneCanvasInnerForwardRef = forwardRef(SceneCanvasInner);\n\n// The canvas's input scope sits above `SceneCanvasInner`, whose own hooks\n// (`useTools` among them) must already read this canvas's tool and registries.\n// Its device profile too, so the canvas and everything under it share one.\n/** A scene canvas resolving its `features` through `source`. */\nexport function renderSceneCanvas<TData, TLayer extends string, TPose>(\n source: PresetSource,\n { device, ...props }: SceneCanvasProps<TData, TLayer, TPose>,\n ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n return (\n <InputScope yoke={props.yoke}>\n <DeviceProfileProvider value={device}>\n <ViewRegistryProvider>\n <SceneCanvasInnerForwardRef {...(props as SceneCanvasProps<unknown, string, unknown>)} presetSource={source} ref={ref} />\n </ViewRegistryProvider>\n </DeviceProfileProvider>\n </InputScope>\n );\n}\n\nfunction SceneCanvasWrapper<TData, TLayer extends string, TPose>(\n props: SceneCanvasProps<TData, TLayer, TPose>, ref: React.ForwardedRef<SceneCanvasApi>,\n) {\n return renderSceneCanvas(CORE_PRESET_SOURCE, props, ref);\n}\n\n// Marked pure so a bundle using only `LeanSceneCanvas` drops it, and core's named presets with it.\n/**\n * The canvas component: renders a `Scene` and wires the interaction stack\n * around it.\n *\n * Mounted bare it renders the scene, keeps a selection no input sets, and\n * runs a gesture dispatcher for whatever bindings the consumer adds. The\n * `features` presets turn the kit's behavior on — `features={['draw']}` is the\n * whole editor: tools, standard actions and their keys, selection chrome,\n * undo. This is the intended entry point; the lower-level primitives it\n * composes are not part of the public surface.\n *\n * Its ref exposes a `SceneCanvasApi` for the imperative operations that do not\n * fit a prop (view control, hit queries, redraw requests).\n */\nexport const SceneCanvas = /* @__PURE__ */ forwardRef(SceneCanvasWrapper) as <\n TData, TLayer extends string, TPose,\n>(\n props: SceneCanvasProps<TData, TLayer, TPose> & { ref?: React.Ref<SceneCanvasApi> },\n) => ReturnType<typeof SceneCanvasInner>;\n\nexport { DEFAULT_HANDLE_SIZE, BUILTIN_TOOL_IDS } from './SceneCanvas/props';\nexport {\n BUILTIN_TOOLS, SELECT_TOOLS, VIEW_TOOLS, SHAPE_TOOLS, DRAW_TOOLS, TYPE_TOOLS, PAGE_TOOLS,\n} from './SceneCanvas/builtinToolSets';\nexport { mergeLayersWithDefaults } from './SceneCanvas/mergeLayers';\nexport type {\n SceneCanvasProps, SceneCanvasHit, SceneCanvasLayers, SceneCanvasLongPress, BuiltinToolId,\n} from './SceneCanvas/props';\nexport type { CoordTraceEntry } from './SceneCanvas/coordTrace';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAS,iBACP,OACA,KACA;CACA,MAAM,EAAE,YAAY,gBAAgB,aAAa,MAAM,UAAU,UAAU;CAC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Q,SAAS;IAA6B;IAA8B;IACpF,QAAQ;KAAE,YAAY;KAAmB,QAAQ;KAAc,OAAO;IAAY;IAAG,aAAa,QAAQ;IAAa,WAAW,QAAQ;GAC3I,CAAA;GACD,oBAAC,qBAAD;IAAqB,OAAO,MAAM;IAAO,SAAS,oBAAoB,MAAM,KAAK;IAAG,OAAO;GAAa,CAAA;GACvG,MAAM;EACW;;AAExB;AAEA,IAAM,6BAA6B,WAAW,gBAAgB;;AAM9D,SAAgB,kBACd,QACA,EAAE,QAAQ,GAAG,SACb,KACA;CACA,OACE,oBAAC,YAAD;EAAY,MAAM,MAAM;EACtB,UAAA,oBAAC,uBAAD;GAAuB,OAAO;GAC5B,UAAA,oBAAC,sBAAD,EAAA,UACE,oBAAC,4BAAD;IAA4B,GAAK;IAAsD,cAAc;IAAa;GAAM,CAAA,EACpG,CAAA;EACD,CAAA;CACb,CAAA;AAEhB;AAEA,SAAS,mBACP,OAA+C,KAC/C;CACA,OAAO,kBAAkB,oBAAoB,OAAO,GAAG;AACzD;;;;;;;;;;;;;;;AAiBA,IAAa,cAA8B,2BAAW,kBAAkB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useOptionalViewRegistry } from "./viewRegistry.js";
|
|
2
|
+
import { useCallback, useEffect } from "react";
|
|
3
|
+
import { useLatest } from "@weasel-js/react";
|
|
4
|
+
|
|
5
|
+
//#region src/canvas/ViewMarker.tsx
|
|
6
|
+
/**
|
|
7
|
+
* `<ViewMarker>` — one view's aim, outlined inside another view's frame: a
|
|
8
|
+
* minimap's indicator, a picture-in-picture's footprint on the main view.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Draws one view's aim inside another's frame, after that view's own layers.
|
|
12
|
+
*
|
|
13
|
+
* Renders nothing; outside a surface it is inert. Either view may mount after
|
|
14
|
+
* the marker does: until both are there it draws nothing.
|
|
15
|
+
*/
|
|
16
|
+
function ViewMarker(props) {
|
|
17
|
+
const registry = useOptionalViewRegistry();
|
|
18
|
+
const live = useLatest(props);
|
|
19
|
+
const read = useCallback(() => live.current, [live]);
|
|
20
|
+
const { id, target } = props;
|
|
21
|
+
useEffect(() => registry?.registerMarker(read), [
|
|
22
|
+
registry,
|
|
23
|
+
read,
|
|
24
|
+
id,
|
|
25
|
+
target
|
|
26
|
+
]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
registry?.surface()?.requestRedraw();
|
|
29
|
+
});
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ViewMarker };
|
|
35
|
+
//# sourceMappingURL=ViewMarker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewMarker.js","names":[],"sources":["../../src/canvas/ViewMarker.tsx"],"sourcesContent":["/**\n * `<ViewMarker>` — one view's aim, outlined inside another view's frame: a\n * minimap's indicator, a picture-in-picture's footprint on the main view.\n */\nimport { useCallback, useEffect } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport type { ViewMarkerProps } from 'features/viewports/viewMarker';\nimport { useOptionalViewRegistry } from './viewRegistry';\n\n/**\n * Draws one view's aim inside another's frame, after that view's own layers.\n *\n * Renders nothing; outside a surface it is inert. Either view may mount after\n * the marker does: until both are there it draws nothing.\n */\nexport function ViewMarker(props: ViewMarkerProps): null {\n const registry = useOptionalViewRegistry();\n const live = useLatest(props);\n const read = useCallback(() => live.current, [live]);\n const { id, target } = props;\n\n // Which stack the marker is listed in, and its layer's id, are fixed at\n // registration; everything else is read off `live` at draw time.\n useEffect(() => registry?.registerMarker(read), [registry, read, id, target]);\n\n useEffect(() => {\n registry?.surface()?.requestRedraw();\n });\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,WAAW,OAA8B;CACvD,MAAM,WAAW,wBAAwB;CACzC,MAAM,OAAO,UAAU,KAAK;CAC5B,MAAM,OAAO,kBAAkB,KAAK,SAAS,CAAC,IAAI,CAAC;CACnD,MAAM,EAAE,IAAI,WAAW;CAIvB,gBAAgB,UAAU,eAAe,IAAI,GAAG;EAAC;EAAU;EAAM;EAAI;CAAM,CAAC;CAE5E,gBAAgB;EACd,UAAU,QAAQ,CAAC,EAAE,cAAc;CACrC,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
//#region src/canvas/accentColor.ts
|
|
2
2
|
/** The accent canvas chrome paints in when the element sits under no theme. */
|
|
3
3
|
var FALLBACK_ACCENT = "#4c8dff";
|
|
4
|
+
/** Read the color custom property `name` off `el`, where the theme cascade lands on a canvas. */
|
|
5
|
+
function chromeColorOf(el, name, fallback) {
|
|
6
|
+
if (!el || typeof getComputedStyle !== "function") return fallback;
|
|
7
|
+
return getComputedStyle(el).getPropertyValue(name).trim() || fallback;
|
|
8
|
+
}
|
|
4
9
|
/** Read `--wzl-accent` off `el`, where the theme cascade lands on a canvas. */
|
|
5
10
|
function accentColorOf(el) {
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
return chromeColorOf(el, "--wzl-accent", FALLBACK_ACCENT);
|
|
12
|
+
}
|
|
13
|
+
var THEME_ATTRIBUTE = /^(data-wzl-|class$)/;
|
|
14
|
+
/**
|
|
15
|
+
* Hear that the colors read off an element may have changed: a theme, mode or class attribute
|
|
16
|
+
* changing on it or anything above it, or the system color scheme flipping. `el` is read when
|
|
17
|
+
* this is called; with none yet, the document root is watched. Returns the stop.
|
|
18
|
+
*/
|
|
19
|
+
function watchThemeOf(el, fn) {
|
|
20
|
+
if (typeof MutationObserver !== "function" || typeof document === "undefined") return () => {};
|
|
21
|
+
const observer = new MutationObserver((records) => {
|
|
22
|
+
if (records.some((r) => r.attributeName !== null && THEME_ATTRIBUTE.test(r.attributeName))) fn();
|
|
23
|
+
});
|
|
24
|
+
for (let node = el() ?? document.documentElement; node; node = node.parentElement) observer.observe(node, { attributes: true });
|
|
25
|
+
const scheme = typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
|
|
26
|
+
scheme?.addEventListener?.("change", fn);
|
|
27
|
+
return () => {
|
|
28
|
+
observer.disconnect();
|
|
29
|
+
scheme?.removeEventListener?.("change", fn);
|
|
30
|
+
};
|
|
8
31
|
}
|
|
9
32
|
|
|
10
33
|
//#endregion
|
|
11
|
-
export { FALLBACK_ACCENT, accentColorOf };
|
|
34
|
+
export { FALLBACK_ACCENT, accentColorOf, chromeColorOf, watchThemeOf };
|
|
12
35
|
//# sourceMappingURL=accentColor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accentColor.js","names":[],"sources":["../../src/canvas/accentColor.ts"],"sourcesContent":["/** The accent canvas chrome paints in when the element sits under no theme. */\nexport const FALLBACK_ACCENT = '#4c8dff';\n\n/** Read
|
|
1
|
+
{"version":3,"file":"accentColor.js","names":[],"sources":["../../src/canvas/accentColor.ts"],"sourcesContent":["/** The accent canvas chrome paints in when the element sits under no theme. */\nexport const FALLBACK_ACCENT = '#4c8dff';\n\n/** Read the color custom property `name` off `el`, where the theme cascade lands on a canvas. */\nexport function chromeColorOf(el: Element | null | undefined, name: `--${string}`, fallback: string): string {\n if (!el || typeof getComputedStyle !== 'function') return fallback;\n return getComputedStyle(el).getPropertyValue(name).trim() || fallback;\n}\n\n/** Read `--wzl-accent` off `el`, where the theme cascade lands on a canvas. */\nexport function accentColorOf(el: Element | null | undefined): string {\n return chromeColorOf(el, '--wzl-accent', FALLBACK_ACCENT);\n}\n\nconst THEME_ATTRIBUTE = /^(data-wzl-|class$)/;\n\n/**\n * Hear that the colors read off an element may have changed: a theme, mode or class attribute\n * changing on it or anything above it, or the system color scheme flipping. `el` is read when\n * this is called; with none yet, the document root is watched. Returns the stop.\n */\nexport function watchThemeOf(el: () => Element | null | undefined, fn: () => void): () => void {\n if (typeof MutationObserver !== 'function' || typeof document === 'undefined') return () => {};\n const observer = new MutationObserver((records) => {\n if (records.some((r) => r.attributeName !== null && THEME_ATTRIBUTE.test(r.attributeName))) fn();\n });\n for (let node: Element | null = el() ?? document.documentElement; node; node = node.parentElement) {\n observer.observe(node, { attributes: true });\n }\n const scheme = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n scheme?.addEventListener?.('change', fn);\n return () => {\n observer.disconnect();\n scheme?.removeEventListener?.('change', fn);\n };\n}\n"],"mappings":";;AACA,IAAa,kBAAkB;;AAG/B,SAAgB,cAAc,IAAgC,MAAqB,UAA0B;CAC3G,IAAI,CAAC,MAAM,OAAO,qBAAqB,YAAY,OAAO;CAC1D,OAAO,iBAAiB,EAAE,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,KAAK,KAAK;AAC/D;;AAGA,SAAgB,cAAc,IAAwC;CACpE,OAAO,cAAc,IAAI,gBAAgB,eAAe;AAC1D;AAEA,IAAM,kBAAkB;;;;;;AAOxB,SAAgB,aAAa,IAAsC,IAA4B;CAC7F,IAAI,OAAO,qBAAqB,cAAc,OAAO,aAAa,aAAa,aAAa,CAAC;CAC7F,MAAM,WAAW,IAAI,kBAAkB,YAAY;EACjD,IAAI,QAAQ,MAAM,MAAM,EAAE,kBAAkB,QAAQ,gBAAgB,KAAK,EAAE,aAAa,CAAC,GAAG,GAAG;CACjG,CAAC;CACD,KAAK,IAAI,OAAuB,GAAG,KAAK,SAAS,iBAAiB,MAAM,OAAO,KAAK,eAClF,SAAS,QAAQ,MAAM,EAAE,YAAY,KAAK,CAAC;CAE7C,MAAM,SAAS,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;CAC/F,QAAQ,mBAAmB,UAAU,EAAE;CACvC,aAAa;EACX,SAAS,WAAW;EACpB,QAAQ,sBAAsB,UAAU,EAAE;CAC5C;AACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { deriveParallaxView, planeMap } from "../core/viewport/parallax.js";
|
|
2
2
|
import { definesFrame } from "../core/scene/effectivePose.js";
|
|
3
|
-
import { findShapeSilhouette } from "./NodeShape.js";
|
|
4
3
|
import { clipCarrier, planeTransform } from "./planeClips.js";
|
|
5
4
|
import { splitOverChildren } from "./overChildren.js";
|
|
5
|
+
import { ownClipOf } from "./ownClip.js";
|
|
6
6
|
import { hidesSubtree } from "../core/scene/nodeGates.js";
|
|
7
|
-
import { scenePlaneOf } from "./
|
|
7
|
+
import { scenePlaneOf } from "./scenePickSource.js";
|
|
8
8
|
import { mat3 } from "@weasel-js/geom";
|
|
9
9
|
|
|
10
10
|
//#region src/canvas/buildSceneTree.ts
|
|
@@ -69,22 +69,19 @@ function buildSceneTree(adapter, drawOne, view, forLayer, derivedPathOf, culled)
|
|
|
69
69
|
let ownClips = ancestorClips;
|
|
70
70
|
let ownClip = null;
|
|
71
71
|
const maybeContainer = node;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
layer: node.layer
|
|
80
|
-
};
|
|
81
|
-
ownClips = [...ancestorClips, ownClip];
|
|
82
|
-
}
|
|
72
|
+
const clip = ownClipOf(maybeContainer, pose, () => derivedPathOf?.(node, pose));
|
|
73
|
+
if (clip) {
|
|
74
|
+
ownClip = {
|
|
75
|
+
path: clip,
|
|
76
|
+
layer: node.layer
|
|
77
|
+
};
|
|
78
|
+
ownClips = [...ancestorClips, ownClip];
|
|
83
79
|
}
|
|
84
|
-
|
|
80
|
+
const wrap = (cmds) => ancestorClips.length > 0 ? wrapInChain(cmds, ancestorClips, node.layer, carry) : {
|
|
85
81
|
kind: "group",
|
|
86
|
-
children:
|
|
87
|
-
}
|
|
82
|
+
children: cmds
|
|
83
|
+
};
|
|
84
|
+
if (bucket) bucket.push(wrap(self));
|
|
88
85
|
const childFrame = definesFrame(node) ? pose : parentFrame;
|
|
89
86
|
const children = adapter.getChildren(id);
|
|
90
87
|
for (const cid of children) visit(cid, ownClips, childFrame, copied);
|
|
@@ -97,10 +94,7 @@ function buildSceneTree(adapter, drawOne, view, forLayer, derivedPathOf, culled)
|
|
|
97
94
|
];
|
|
98
95
|
for (const cid of children) visit(cid, chain, childFrame, true);
|
|
99
96
|
}
|
|
100
|
-
if (bucket && over.length > 0) bucket.push(
|
|
101
|
-
kind: "group",
|
|
102
|
-
children: over
|
|
103
|
-
});
|
|
97
|
+
if (bucket && over.length > 0) bucket.push(wrap(over));
|
|
104
98
|
}
|
|
105
99
|
for (const rootId of adapter.getChildren(null)) visit(rootId, [], null, false);
|
|
106
100
|
const out = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSceneTree.js","names":[],"sources":["../../src/canvas/buildSceneTree.ts"],"sourcesContent":["import type { DrawCommand, GroupDrawCommand } from '@weasel-js/renderer';\nimport type { View } from 'core/viewport/view';\nimport { findShapeSilhouette } from './NodeShape';\nimport type { Node } from 'core/scene/types';\nimport { mat3, type Affine, type Path } from '@weasel-js/geom';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { deriveParallaxView, planeMap, type ParallaxOpts } from 'core/viewport/parallax';\nimport { scenePlaneOf } from './pickWalk';\nimport { clipCarrier, planeTransform } from './planeClips';\nimport { splitOverChildren } from './overChildren';\nimport { hidesSubtree } from 'core/scene/nodeGates';\n\n/** The scene-tree reading surface `buildSceneTree` walks. A `SceneCanvasAdapter` is one. */\nexport interface HierarchicalAdapter<TNode, TPose> {\n getLayers(): readonly { id: string; visible: boolean; parallax?: ParallaxOpts }[];\n getNode(id: string): TNode | undefined;\n getChildren(parentId: string | null): readonly string[];\n getPose(id: string): TPose;\n /** Folds a child's local pose into its parent's frame. Absent means the\n * scene stores absolute poses and a parent contributes no transform —\n * see `PoseComposition`. */\n composePose?(parent: TPose, child: TPose): TPose;\n}\n\n/** A clip on the chain, with the layer whose world it is drawn in, or the\n * transform of a copy a container draws — see `ContainerNode.copiesFromPose`. */\ntype ChainEntry = { path: Path; layer: string } | { copy: Affine };\n\n/** Wrap `cmds` in one nested group per chain entry, so the renderer intersects\n * the clips and applies each copy's transform to everything inside it.\n * Outermost group carries the ancestor-most entry; innermost holds `cmds`. */\nfunction wrapInChain(\n cmds: DrawCommand[],\n chain: readonly ChainEntry[],\n toLayer: string,\n carry: ReturnType<typeof clipCarrier>,\n): DrawCommand {\n let node: GroupDrawCommand = { kind: 'group', children: cmds };\n for (let i = chain.length - 1; i >= 0; i--) {\n const e = chain[i];\n node = 'copy' in e\n ? { kind: 'group', children: [node], transform: mat3.fromAffine(e.copy) }\n : { kind: 'group', children: [node], clip: carry(e.path, e.layer, toLayer) };\n }\n return node;\n}\n\n/**\n * Walk the adapter's scene tree once and emit each node's own paint into the bucket for\n * **that node's own `layer`** — not its parent's. A node carrying `hidden` is skipped with\n * its whole subtree; see `nodeGates`. So a child whose `layer` differs from its\n * parent draws in its own layer's pass while staying a tree child for hit-testing / move /\n * reparent. Output is one group per visible layer, in adapter (`getLayers`) order.\n *\n * A node paints before its children. What its `drawOne` wraps in `overChildren` paints after\n * them instead, in the node's own layer.\n *\n * `drawOne` returns world-coord commands. Because a node may be drawn outside its parent's\n * group, the tree nesting cannot carry geometry as renderer state; the walk folds each node's\n * pose into its parent's frame on the way down and hands the painter a **world** pose. Clips\n * are accumulated the same way — each in its container's plane, carried into the plane of the\n * node it clips. With no `composePose` on the adapter the fold is the identity.\n *\n * A layer carrying `parallax` is a plane: its painters and its cull see the view derived for\n * it, and its group carries the transform from its world to the camera's, so the caller's\n * single camera wrap still lands it right.\n */\nexport function buildSceneTree<\n TNode extends { id: string; layer: string; hidden?: boolean },\n TPose,\n>(\n adapter: HierarchicalAdapter<TNode, TPose>,\n drawOne: (obj: TNode, pose: TPose, view: View) => DrawCommand[],\n view: View,\n /** When set, only nodes on this layer paint (others are still walked for\n * ancestor clips) and only this layer's group is returned. */\n forLayer?: string,\n /** The path a container computes from its dependencies' poses: the scene's\n * lookup, or `adapterDerivedPathOf` for an adapter with no scene. Left out,\n * a derived container contributes no clip. */\n derivedPathOf?: (node: TNode, pose: TPose) => Path | null,\n /** True for a node whose paint cannot be seen — see `paintMissesView`. Its\n * painter is not called; its clip and its children are walked as usual. */\n culled?: (node: TNode, pose: TPose, view: View) => boolean,\n): DrawCommand[] {\n const layers = adapter.getLayers();\n // A hidden layer gets no bucket, and a node with no bucket is not painted.\n const buckets = new Map<string, DrawCommand[]>();\n for (const l of layers) if (l.visible) buckets.set(l.id, []);\n let planeViews: Map<string, View> | null = null;\n for (const l of layers) {\n if (l.parallax) (planeViews ??= new Map()).set(l.id, deriveParallaxView(view, l.parallax));\n }\n\n const compose = adapter.composePose?.bind(adapter);\n const carry = clipCarrier(planeViews ? scenePlaneOf(layers, view) : null);\n\n function visit(\n id: string,\n ancestorClips: readonly ChainEntry[],\n parentFrame: TPose | null,\n /** Under a copy: the pose is not where it paints, so the cull cannot judge it. */\n copied: boolean,\n ): void {\n const node = adapter.getNode(id);\n if (!node || hidesSubtree(node)) return;\n const local = adapter.getPose(id);\n // Fold once, on the way down: O(1) per node where walking the parent chain\n // per node would be O(depth).\n const pose = compose && parentFrame !== null ? compose(parentFrame, local) : local;\n // Skip the (potentially expensive) painter for nodes we won't emit; their\n // clip still extends the chain for descendants below.\n const bucket = forLayer === undefined || node.layer === forLayer\n ? buckets.get(node.layer) : undefined;\n const v = planeViews?.get(node.layer) ?? view;\n const { under: self, over } = splitOverChildren(\n bucket && (copied || !culled?.(node, pose, v)) ? drawOne(node, pose, v) : [],\n );\n\n // Extend the clip chain with this node's own clip when it is a container.\n let ownClips = ancestorClips;\n let ownClip: ChainEntry | null = null;\n const maybeContainer = node as {\n kind?: string;\n clipFromPose?: (pose: TPose) => unknown;\n copiesFromPose?: (pose: TPose, node: unknown) => readonly Affine[] | null;\n };\n if (maybeContainer.kind === 'container') {\n let clip: unknown;\n if (typeof maybeContainer.clipFromPose === 'function') {\n // Explicit per-node clip wins — no fallback to the painter silhouette.\n clip = maybeContainer.clipFromPose(pose);\n } else {\n // No explicit clip → the painter silhouette for the container's shape kind.\n clip = findShapeSilhouette(\n node as unknown as Node<unknown, string, TPose>,\n pose,\n { derivedPath: derivedPathOf?.(node, pose) },\n );\n }\n if (clip) {\n ownClip = { path: clip as Path, layer: node.layer };\n ownClips = [...ancestorClips, ownClip];\n }\n }\n\n // Every node emits a wrapper group even with empty paint, keeping the per-node tree\n // shape stable.\n if (bucket) {\n bucket.push(ownClips.length > 0 ? wrapInChain(self, ownClips, node.layer, carry) : { kind: 'group', children: self });\n }\n\n // An envelope's children share its own parent's frame.\n const childFrame = definesFrame(node as never) ? pose : parentFrame;\n const children = adapter.getChildren(id);\n for (const cid of children) visit(cid, ownClips, childFrame, copied);\n\n // A copy is a copy of the clipped content, so its transform encloses the\n // container's own clip and sits inside every clip above it.\n const copies = typeof maybeContainer.copiesFromPose === 'function'\n ? maybeContainer.copiesFromPose(pose, node) : null;\n for (const copy of copies ?? []) {\n const chain: ChainEntry[] = [...ancestorClips, { copy }, ...(ownClip ? [ownClip] : [])];\n for (const cid of children) visit(cid, chain, childFrame, true);\n }\n\n if (bucket && over.length > 0) {\n bucket.push(ownClips.length > 0 ? wrapInChain(over, ownClips, node.layer, carry) : { kind: 'group', children: over });\n }\n }\n\n for (const rootId of adapter.getChildren(null)) visit(rootId, [], null, false);\n\n const out: DrawCommand[] = [];\n for (const layer of layers) {\n if (!layer.visible) continue;\n if (forLayer !== undefined && layer.id !== forLayer) continue;\n const children = buckets.get(layer.id) ?? [];\n const transform = layer.parallax ? planeTransform(planeMap(view, layer.parallax), null) : undefined;\n out.push(transform ? { kind: 'group', transform, children } : { kind: 'group', children });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,SAAS,YACP,MACA,OACA,SACA,OACa;CACb,IAAI,OAAyB;EAAE,MAAM;EAAS,UAAU;CAAK;CAC7D,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,IAAI,MAAM;EAChB,OAAO,UAAU,IACb;GAAE,MAAM;GAAS,UAAU,CAAC,IAAI;GAAG,WAAW,KAAK,WAAW,EAAE,IAAI;EAAE,IACtE;GAAE,MAAM;GAAS,UAAU,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IAAI,IAAI;EAC1F,IAAI,KAAK,YAAY;GAAE,MAAM;GAAS;GAAW;EAAS,IAAI;GAAE,MAAM;GAAS;EAAS,CAAC;CAC3F;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"buildSceneTree.js","names":[],"sources":["../../src/canvas/buildSceneTree.ts"],"sourcesContent":["import type { DrawCommand, GroupDrawCommand } from '@weasel-js/renderer';\nimport type { View } from 'core/viewport/view';\nimport { ownClipOf, type ClipBearing } from './ownClip';\nimport { mat3, type Affine, type Path } from '@weasel-js/geom';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { deriveParallaxView, planeMap, type ParallaxOpts } from 'core/viewport/parallax';\nimport { scenePlaneOf } from './pickWalk';\nimport { clipCarrier, planeTransform } from './planeClips';\nimport { splitOverChildren } from './overChildren';\nimport { hidesSubtree } from 'core/scene/nodeGates';\n\n/** The scene-tree reading surface `buildSceneTree` walks. A `SceneCanvasAdapter` is one. */\nexport interface HierarchicalAdapter<TNode, TPose> {\n getLayers(): readonly { id: string; visible: boolean; parallax?: ParallaxOpts }[];\n getNode(id: string): TNode | undefined;\n getChildren(parentId: string | null): readonly string[];\n getPose(id: string): TPose;\n /** Folds a child's local pose into its parent's frame. Absent means the\n * scene stores absolute poses and a parent contributes no transform —\n * see `PoseComposition`. */\n composePose?(parent: TPose, child: TPose): TPose;\n}\n\n/** A clip on the chain, with the layer whose world it is drawn in, or the\n * transform of a copy a container draws — see `GroupNode.copiesFromPose`. */\ntype ChainEntry = { path: Path; layer: string } | { copy: Affine };\n\n/** Wrap `cmds` in one nested group per chain entry, so the renderer intersects\n * the clips and applies each copy's transform to everything inside it.\n * Outermost group carries the ancestor-most entry; innermost holds `cmds`. */\nfunction wrapInChain(\n cmds: DrawCommand[],\n chain: readonly ChainEntry[],\n toLayer: string,\n carry: ReturnType<typeof clipCarrier>,\n): DrawCommand {\n let node: GroupDrawCommand = { kind: 'group', children: cmds };\n for (let i = chain.length - 1; i >= 0; i--) {\n const e = chain[i];\n node = 'copy' in e\n ? { kind: 'group', children: [node], transform: mat3.fromAffine(e.copy) }\n : { kind: 'group', children: [node], clip: carry(e.path, e.layer, toLayer) };\n }\n return node;\n}\n\n/**\n * Walk the adapter's scene tree once and emit each node's own paint into the bucket for\n * **that node's own `layer`** — not its parent's. A node carrying `hidden` is skipped with\n * its whole subtree; see `nodeGates`. So a child whose `layer` differs from its\n * parent draws in its own layer's pass while staying a tree child for hit-testing / move /\n * reparent. Output is one group per visible layer, in adapter (`getLayers`) order.\n *\n * A node paints before its children. What its `drawOne` wraps in `overChildren` paints after\n * them instead, in the node's own layer.\n *\n * `drawOne` returns world-coord commands. Because a node may be drawn outside its parent's\n * group, the tree nesting cannot carry geometry as renderer state; the walk folds each node's\n * pose into its parent's frame on the way down and hands the painter a **world** pose. Clips\n * are accumulated the same way — each in its container's plane, carried into the plane of the\n * node it clips. With no `composePose` on the adapter the fold is the identity.\n *\n * A layer carrying `parallax` is a plane: its painters and its cull see the view derived for\n * it, and its group carries the transform from its world to the camera's, so the caller's\n * single camera wrap still lands it right.\n */\nexport function buildSceneTree<\n TNode extends { id: string; layer: string; hidden?: boolean },\n TPose,\n>(\n adapter: HierarchicalAdapter<TNode, TPose>,\n drawOne: (obj: TNode, pose: TPose, view: View) => DrawCommand[],\n view: View,\n /** When set, only nodes on this layer paint (others are still walked for\n * ancestor clips) and only this layer's group is returned. */\n forLayer?: string,\n /** The path a container computes from its dependencies' poses: the scene's\n * lookup, or `adapterDerivedPathOf` for an adapter with no scene. Left out,\n * a derived container contributes no clip. */\n derivedPathOf?: (node: TNode, pose: TPose) => Path | null,\n /** True for a node whose paint cannot be seen — see `paintMissesView`. Its\n * painter is not called; its clip and its children are walked as usual. */\n culled?: (node: TNode, pose: TPose, view: View) => boolean,\n): DrawCommand[] {\n const layers = adapter.getLayers();\n // A hidden layer gets no bucket, and a node with no bucket is not painted.\n const buckets = new Map<string, DrawCommand[]>();\n for (const l of layers) if (l.visible) buckets.set(l.id, []);\n let planeViews: Map<string, View> | null = null;\n for (const l of layers) {\n if (l.parallax) (planeViews ??= new Map()).set(l.id, deriveParallaxView(view, l.parallax));\n }\n\n const compose = adapter.composePose?.bind(adapter);\n const carry = clipCarrier(planeViews ? scenePlaneOf(layers, view) : null);\n\n function visit(\n id: string,\n ancestorClips: readonly ChainEntry[],\n parentFrame: TPose | null,\n /** Under a copy: the pose is not where it paints, so the cull cannot judge it. */\n copied: boolean,\n ): void {\n const node = adapter.getNode(id);\n if (!node || hidesSubtree(node)) return;\n const local = adapter.getPose(id);\n // Fold once, on the way down: O(1) per node where walking the parent chain\n // per node would be O(depth).\n const pose = compose && parentFrame !== null ? compose(parentFrame, local) : local;\n // Skip the (potentially expensive) painter for nodes we won't emit; their\n // clip still extends the chain for descendants below.\n const bucket = forLayer === undefined || node.layer === forLayer\n ? buckets.get(node.layer) : undefined;\n const v = planeViews?.get(node.layer) ?? view;\n const { under: self, over } = splitOverChildren(\n bucket && (copied || !culled?.(node, pose, v)) ? drawOne(node, pose, v) : [],\n );\n\n let ownClips = ancestorClips;\n let ownClip: ChainEntry | null = null;\n const maybeContainer = node as ClipBearing<TPose> & {\n copiesFromPose?: (pose: TPose, node: unknown) => readonly Affine[] | null;\n };\n const clip = ownClipOf(maybeContainer, pose, () => derivedPathOf?.(node, pose));\n if (clip) {\n ownClip = { path: clip, layer: node.layer };\n ownClips = [...ancestorClips, ownClip];\n }\n\n // Every node emits a wrapper group even with empty paint, keeping the per-node tree\n // shape stable. A node's own clip is its children's, so its own paint, over\n // its children or under them, takes only the clips above it.\n const wrap = (cmds: DrawCommand[]): DrawCommand => (ancestorClips.length > 0\n ? wrapInChain(cmds, ancestorClips, node.layer, carry) : { kind: 'group', children: cmds });\n if (bucket) bucket.push(wrap(self));\n\n // An envelope's children share its own parent's frame.\n const childFrame = definesFrame(node as never) ? pose : parentFrame;\n const children = adapter.getChildren(id);\n for (const cid of children) visit(cid, ownClips, childFrame, copied);\n\n // A copy is a copy of the clipped content, so its transform encloses the\n // container's own clip and sits inside every clip above it.\n const copies = typeof maybeContainer.copiesFromPose === 'function'\n ? maybeContainer.copiesFromPose(pose, node) : null;\n for (const copy of copies ?? []) {\n const chain: ChainEntry[] = [...ancestorClips, { copy }, ...(ownClip ? [ownClip] : [])];\n for (const cid of children) visit(cid, chain, childFrame, true);\n }\n\n if (bucket && over.length > 0) bucket.push(wrap(over));\n }\n\n for (const rootId of adapter.getChildren(null)) visit(rootId, [], null, false);\n\n const out: DrawCommand[] = [];\n for (const layer of layers) {\n if (!layer.visible) continue;\n if (forLayer !== undefined && layer.id !== forLayer) continue;\n const children = buckets.get(layer.id) ?? [];\n const transform = layer.parallax ? planeTransform(planeMap(view, layer.parallax), null) : undefined;\n out.push(transform ? { kind: 'group', transform, children } : { kind: 'group', children });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAS,YACP,MACA,OACA,SACA,OACa;CACb,IAAI,OAAyB;EAAE,MAAM;EAAS,UAAU;CAAK;CAC7D,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,IAAI,MAAM;EAChB,OAAO,UAAU,IACb;GAAE,MAAM;GAAS,UAAU,CAAC,IAAI;GAAG,WAAW,KAAK,WAAW,EAAE,IAAI;EAAE,IACtE;GAAE,MAAM;GAAS,UAAU,CAAC,IAAI;GAAG,MAAM,MAAM,EAAE,MAAM,EAAE,OAAO,OAAO;EAAE;CAC/E;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,eAId,SACA,SACA,MAGA,UAIA,eAGA,QACe;CACf,MAAM,SAAS,QAAQ,UAAU;CAEjC,MAAM,0BAAU,IAAI,IAA2B;CAC/C,KAAK,MAAM,KAAK,QAAQ,IAAI,EAAE,SAAS,QAAQ,IAAI,EAAE,IAAI,CAAC,CAAC;CAC3D,IAAI,aAAuC;CAC3C,KAAK,MAAM,KAAK,QACd,IAAI,EAAE,UAAU,CAAC,+BAAe,IAAI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,eAAe,mBAAmB,aACpD,eAAe,eAAe,MAAM,IAAI,IAAI;EAChD,KAAK,MAAM,QAAQ,UAAU,CAAC,GAAG;GAC/B,MAAM,QAAsB;IAAC,GAAG;IAAe,EAAE,KAAK;IAAG,GAAI,UAAU,CAAC,OAAO,IAAI,CAAC;GAAE;GACtF,KAAK,MAAM,OAAO,UAAU,MAAM,KAAK,OAAO,YAAY,IAAI;EAChE;EAEA,IAAI,UAAU,KAAK,SAAS,GAAG,OAAO,KAAK,KAAK,IAAI,CAAC;CACvD;CAEA,KAAK,MAAM,UAAU,QAAQ,YAAY,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,MAAM,KAAK;CAE7E,MAAM,MAAqB,CAAC;CAC5B,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,aAAa,UAAa,MAAM,OAAO,UAAU;EACrD,MAAM,WAAW,QAAQ,IAAI,MAAM,EAAE,KAAK,CAAC;EAC3C,MAAM,YAAY,MAAM,WAAW,eAAe,SAAS,MAAM,MAAM,QAAQ,GAAG,IAAI,IAAI;EAC1F,IAAI,KAAK,YAAY;GAAE,MAAM;GAAS;GAAW;EAAS,IAAI;GAAE,MAAM;GAAS;EAAS,CAAC;CAC3F;CACA,OAAO;AACT"}
|
|
@@ -20,7 +20,7 @@ function copiesWithin(scene, container, poseOf) {
|
|
|
20
20
|
]];
|
|
21
21
|
for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {
|
|
22
22
|
const a = scene.get(aid);
|
|
23
|
-
if (a?.
|
|
23
|
+
if (!a?.copiesFromPose) continue;
|
|
24
24
|
const copies = a.copiesFromPose(poseOf(a), a) ?? [];
|
|
25
25
|
if (copies.length === 0) continue;
|
|
26
26
|
all = all.flatMap((m) => [m, ...copies.map((c) => multiply(m, c))]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copiesAbove.js","names":[],"sources":["../../src/canvas/copiesAbove.ts"],"sourcesContent":["import { multiply, type Affine } from '@weasel-js/geom';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\n\n/**\n * Every transform content placed in `container` is drawn under besides as\n * authored: the `copiesFromPose` of the container and of each container above\n * it, composed outermost first, the identity left out. Empty for the top of\n * the tree, or when nothing there draws copies. `poseOf` is the pose a\n * container is painted at, which is what its copies are computed from.\n */\nexport function copiesWithin<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n container: NodeId | null,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n if (container === null || scene.get(container) === undefined) return [];\n let all: Affine[] = [[1, 0, 0, 1, 0, 0]];\n for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {\n const a = scene.get(aid);\n if (a?.
|
|
1
|
+
{"version":3,"file":"copiesAbove.js","names":[],"sources":["../../src/canvas/copiesAbove.ts"],"sourcesContent":["import { multiply, type Affine } from '@weasel-js/geom';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\n\n/**\n * Every transform content placed in `container` is drawn under besides as\n * authored: the `copiesFromPose` of the container and of each container above\n * it, composed outermost first, the identity left out. Empty for the top of\n * the tree, or when nothing there draws copies. `poseOf` is the pose a\n * container is painted at, which is what its copies are computed from.\n */\nexport function copiesWithin<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n container: NodeId | null,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n if (container === null || scene.get(container) === undefined) return [];\n let all: Affine[] = [[1, 0, 0, 1, 0, 0]];\n for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {\n const a = scene.get(aid);\n if (!a?.copiesFromPose) continue;\n const copies = a.copiesFromPose(poseOf(a), a) ?? [];\n if (copies.length === 0) continue;\n // A copy at an outer level carries everything inside it, inner copies included.\n all = all.flatMap((m) => [m, ...copies.map((c) => multiply(m, c))]);\n }\n return all.slice(1);\n}\n\n/** Every transform the ancestors of `id` draw it under; see {@link copiesWithin}. */\nexport function copiesAbove<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n id: NodeId,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n return copiesWithin(scene, scene.get(id)?.parent ?? null, poseOf);\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,aACd,OACA,WACA,QACU;CACV,IAAI,cAAc,QAAQ,MAAM,IAAI,SAAS,MAAM,QAAW,OAAO,CAAC;CACtE,IAAI,MAAgB,CAAC;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC,CAAC;CACvC,KAAK,MAAM,OAAO,CAAC,WAAW,GAAG,MAAM,YAAY,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG;EACxE,MAAM,IAAI,MAAM,IAAI,GAAG;EACvB,IAAI,CAAC,GAAG,gBAAgB;EACxB,MAAM,SAAS,EAAE,eAAe,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;EAClD,IAAI,OAAO,WAAW,GAAG;EAEzB,MAAM,IAAI,SAAS,MAAM,CAAC,GAAG,GAAG,OAAO,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;CACpE;CACA,OAAO,IAAI,MAAM,CAAC;AACpB;;AAGA,SAAgB,YACd,OACA,IACA,QACU;CACV,OAAO,aAAa,OAAO,MAAM,IAAI,EAAE,CAAC,EAAE,UAAU,MAAM,MAAM;AAClE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { findNodeShape, findShapeBounds } from "./NodeShape.js";
|
|
2
2
|
import { overChildren } from "./overChildren.js";
|
|
3
3
|
import { textCommandFromRuns } from "@weasel-js/renderer";
|
|
4
|
+
import { INHERIT } from "@weasel-js/paint";
|
|
4
5
|
|
|
5
6
|
//#region src/canvas/defaultDrawOne.ts
|
|
6
7
|
function pixelScaleOf(view) {
|
|
@@ -21,7 +22,7 @@ function viewOnlyCtx(view) {
|
|
|
21
22
|
* registered node-shape painter that matches, then draw its `data.label` on
|
|
22
23
|
* top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */
|
|
23
24
|
function defaultDrawOne(node, pose, view, ctx) {
|
|
24
|
-
const painter = findNodeShape(node);
|
|
25
|
+
const painter = node.kind === "group" ? void 0 : findNodeShape(node);
|
|
25
26
|
const paintCtx = !view || ctx?.pixelScale !== void 0 ? ctx : ctx ? {
|
|
26
27
|
...ctx,
|
|
27
28
|
pixelScale: pixelScaleOf(view)
|
|
@@ -40,23 +41,27 @@ function defaultDrawOne(node, pose, view, ctx) {
|
|
|
40
41
|
fontFamily: "sans-serif",
|
|
41
42
|
fontSize: 11
|
|
42
43
|
});
|
|
43
|
-
return [...primary, node.kind === "
|
|
44
|
+
return [...primary, node.kind === "group" ? overChildren([label]) : label];
|
|
44
45
|
}
|
|
45
46
|
return primary;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* The box {@link defaultDrawOne}'s output for `node` fits in — the matched
|
|
49
50
|
* painter's `bounds` — or `null` when it has none, or when a `data.label`
|
|
50
|
-
* overlay adds text nothing bounds cheaply
|
|
51
|
-
* to
|
|
51
|
+
* overlay adds text nothing bounds cheaply, or an inherited stroke with no
|
|
52
|
+
* `ctx.inherited` to say what it takes. The scene slot's `cull` reads it to
|
|
53
|
+
* skip painting nodes the view cannot see.
|
|
52
54
|
*/
|
|
53
|
-
function defaultPaintBounds(node, pose, view) {
|
|
55
|
+
function defaultPaintBounds(node, pose, view, ctx) {
|
|
54
56
|
const data = node.data;
|
|
55
57
|
if (data?.label && data.text == null) return null;
|
|
58
|
+
const inherited = ctx?.inherited;
|
|
59
|
+
if (data?.stroke === INHERIT && inherited === void 0) return null;
|
|
56
60
|
const sx = Math.abs(view.scale.x), sy = Math.abs(view.scale.y);
|
|
57
61
|
return findShapeBounds(node, pose, {
|
|
58
62
|
scale: Math.sqrt(sx * sy),
|
|
59
|
-
leastScale: Math.min(sx, sy)
|
|
63
|
+
leastScale: Math.min(sx, sy),
|
|
64
|
+
inherited
|
|
60
65
|
});
|
|
61
66
|
}
|
|
62
67
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultDrawOne.js","names":[],"sources":["../../src/canvas/defaultDrawOne.ts"],"sourcesContent":["/**\n * The kit's default per-node draw function, kept apart from `SceneCanvas.tsx` so non-React\n * callers (headless rasterization via `renderSceneToPixels`) can use it without importing the\n * React component tree.\n *\n * To teach the kit about a new kind of shape, register a painter (`registerNodeShape`) — do not\n * override `drawOne`. Override `drawOne` only for cross-cutting decoration.\n */\nimport type { Node } from 'core/scene/types';\nimport type { View } from 'core/viewport/view';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { textCommandFromRuns } from '@weasel-js/renderer';\nimport { findNodeShape, findShapeBounds, type NodePaintCtx } from './NodeShape';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { overChildren } from './overChildren';\n\nfunction pixelScaleOf(view: View): number {\n const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;\n return Math.max(Math.abs(view.scale.x), Math.abs(view.scale.y)) * dpr;\n}\n\n// Shared across a frame's nodes, which all arrive with the same view.\nlet lastView: View | undefined;\nlet lastViewCtx: NodePaintCtx = {};\nfunction viewOnlyCtx(view: View): NodePaintCtx {\n const pixelScale = pixelScaleOf(view);\n if (view !== lastView || lastViewCtx.pixelScale !== pixelScale) {\n lastView = view;\n lastViewCtx = { pixelScale };\n }\n return lastViewCtx;\n}\n\n/** Paint one node the way the kit does by default: dispatch to the first\n * registered node-shape painter that matches, then draw its `data.label` on\n * top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */\nexport function defaultDrawOne<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view?: View,\n ctx?: NodePaintCtx,\n): DrawCommand[] {\n const painter = findNodeShape(node);\n const paintCtx = !view || ctx?.pixelScale !== undefined\n ? ctx\n : ctx ? { ...ctx, pixelScale: pixelScaleOf(view) } : viewOnlyCtx(view);\n const primary = painter ? painter.paint(node, pose, paintCtx) : [];\n\n // Label overlay — skipped for text nodes (their content is the label).\n const data = node.data as { label?: string; text?: string } | null;\n if (data?.label && data.text == null) {\n const p = pose as unknown as { x: number; y: number };\n // Copy rather than `push`. A painter's return value is not ours to grow:\n // one that memoizes its command list — which is the point of caching\n // `paint` — would gain another label command on every frame, forever.\n const label = textCommandFromRuns(\n p.x + 6,\n p.y + 14,\n [{ text: data.label, fill: { paint: { kind: 'solid', color: 'rgba(0,0,0,0.7)' } } }],\n { fontFamily: 'sans-serif', fontSize: 11 },\n );\n // A container's children would cover a label drawn with the container.\n return [...primary, node.kind === '
|
|
1
|
+
{"version":3,"file":"defaultDrawOne.js","names":[],"sources":["../../src/canvas/defaultDrawOne.ts"],"sourcesContent":["/**\n * The kit's default per-node draw function, kept apart from `SceneCanvas.tsx` so non-React\n * callers (headless rasterization via `renderSceneToPixels`) can use it without importing the\n * React component tree.\n *\n * To teach the kit about a new kind of shape, register a painter (`registerNodeShape`) — do not\n * override `drawOne`. Override `drawOne` only for cross-cutting decoration.\n */\nimport type { Node } from 'core/scene/types';\nimport type { View } from 'core/viewport/view';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { textCommandFromRuns } from '@weasel-js/renderer';\nimport { findNodeShape, findShapeBounds, type NodePaintCtx } from './NodeShape';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { overChildren } from './overChildren';\nimport { INHERIT } from '@weasel-js/paint';\n\nfunction pixelScaleOf(view: View): number {\n const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;\n return Math.max(Math.abs(view.scale.x), Math.abs(view.scale.y)) * dpr;\n}\n\n// Shared across a frame's nodes, which all arrive with the same view.\nlet lastView: View | undefined;\nlet lastViewCtx: NodePaintCtx = {};\nfunction viewOnlyCtx(view: View): NodePaintCtx {\n const pixelScale = pixelScaleOf(view);\n if (view !== lastView || lastViewCtx.pixelScale !== pixelScale) {\n lastView = view;\n lastViewCtx = { pixelScale };\n }\n return lastViewCtx;\n}\n\n/** Paint one node the way the kit does by default: dispatch to the first\n * registered node-shape painter that matches, then draw its `data.label` on\n * top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */\nexport function defaultDrawOne<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view?: View,\n ctx?: NodePaintCtx,\n): DrawCommand[] {\n // A group is structure: it never paints, whatever its data holds.\n const painter = node.kind === 'group' ? undefined : findNodeShape(node);\n const paintCtx = !view || ctx?.pixelScale !== undefined\n ? ctx\n : ctx ? { ...ctx, pixelScale: pixelScaleOf(view) } : viewOnlyCtx(view);\n const primary = painter ? painter.paint(node, pose, paintCtx) : [];\n\n // Label overlay — skipped for text nodes (their content is the label).\n const data = node.data as { label?: string; text?: string } | null;\n if (data?.label && data.text == null) {\n const p = pose as unknown as { x: number; y: number };\n // Copy rather than `push`. A painter's return value is not ours to grow:\n // one that memoizes its command list — which is the point of caching\n // `paint` — would gain another label command on every frame, forever.\n const label = textCommandFromRuns(\n p.x + 6,\n p.y + 14,\n [{ text: data.label, fill: { paint: { kind: 'solid', color: 'rgba(0,0,0,0.7)' } } }],\n { fontFamily: 'sans-serif', fontSize: 11 },\n );\n // A container's children would cover a label drawn with the container.\n return [...primary, node.kind === 'group' ? overChildren([label]) : label];\n }\n\n // Rotation and per-node alpha are applied OUTSIDE this function, by `wrapNodeOutput` in\n // the scene walks and the preview-ghost layer, so that consumer-supplied painters get\n // them too.\n return primary;\n}\n\n/**\n * The box {@link defaultDrawOne}'s output for `node` fits in — the matched\n * painter's `bounds` — or `null` when it has none, or when a `data.label`\n * overlay adds text nothing bounds cheaply, or an inherited stroke with no\n * `ctx.inherited` to say what it takes. The scene slot's `cull` reads it to\n * skip painting nodes the view cannot see.\n */\nexport function defaultPaintBounds<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view: View,\n ctx?: Pick<NodePaintCtx, 'inherited'>,\n): Bounds | null {\n const data = node.data as { label?: string; text?: string; stroke?: unknown } | null;\n if (data?.label && data.text == null) return null;\n const inherited = ctx?.inherited;\n if (data?.stroke === INHERIT && inherited === undefined) return null;\n const sx = Math.abs(view.scale.x), sy = Math.abs(view.scale.y);\n return findShapeBounds(node, pose, { scale: Math.sqrt(sx * sy), leastScale: Math.min(sx, sy), inherited });\n}\n\n/**\n * `defaultPaintBounds` when `drawOne` is `defaultDrawOne`, and nothing\n * otherwise: a painter's box says nothing about what a replacement\n * `drawOne` paints.\n */\nexport function paintBoundsFor<TData, TLayer extends string, TPose>(\n drawOne: unknown,\n): typeof defaultPaintBounds<TData, TLayer, TPose> | undefined {\n return drawOne === defaultDrawOne ? defaultPaintBounds : undefined;\n}\n"],"mappings":";;;;;;AAiBA,SAAS,aAAa,MAAoB;CACxC,MAAM,MAAO,OAAO,WAAW,eAAe,OAAO,oBAAqB;CAC1E,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI;AACpE;AAGA,IAAI;AACJ,IAAI,cAA4B,CAAC;AACjC,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,aAAa,IAAI;CACpC,IAAI,SAAS,YAAY,YAAY,eAAe,YAAY;EAC9D,WAAW;EACX,cAAc,EAAE,WAAW;CAC7B;CACA,OAAO;AACT;;;;AAKA,SAAgB,eACd,MACA,MACA,MACA,KACe;CAEf,MAAM,UAAU,KAAK,SAAS,UAAU,SAAY,cAAc,IAAI;CACtE,MAAM,WAAW,CAAC,QAAQ,KAAK,eAAe,SAC1C,MACA,MAAM;EAAE,GAAG;EAAK,YAAY,aAAa,IAAI;CAAE,IAAI,YAAY,IAAI;CACvE,MAAM,UAAU,UAAU,QAAQ,MAAM,MAAM,MAAM,QAAQ,IAAI,CAAC;CAGjE,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM;EACpC,MAAM,IAAI;EAIV,MAAM,QAAQ,oBACZ,EAAE,IAAI,GACN,EAAE,IAAI,IACN,CAAC;GAAE,MAAM,KAAK;GAAO,MAAM,EAAE,OAAO;IAAE,MAAM;IAAS,OAAO;GAAkB,EAAE;EAAE,CAAC,GACnF;GAAE,YAAY;GAAc,UAAU;EAAG,CAC3C;EAEA,OAAO,CAAC,GAAG,SAAS,KAAK,SAAS,UAAU,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK;CAC3E;CAKA,OAAO;AACT;;;;;;;;AASA,SAAgB,mBACd,MACA,MACA,MACA,KACe;CACf,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM,OAAO;CAC7C,MAAM,YAAY,KAAK;CACvB,IAAI,MAAM,WAAW,WAAW,cAAc,QAAW,OAAO;CAChE,MAAM,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC;CAC7D,OAAO,gBAAgB,MAAM,MAAM;EAAE,OAAO,KAAK,KAAK,KAAK,EAAE;EAAG,YAAY,KAAK,IAAI,IAAI,EAAE;EAAG;CAAU,CAAC;AAC3G;;;;;;AAOA,SAAgB,eACd,SAC6D;CAC7D,OAAO,YAAY,iBAAiB,qBAAqB;AAC3D"}
|
|
@@ -14,18 +14,21 @@ import { useDepSource } from "@weasel-js/routing/react";
|
|
|
14
14
|
* ref internally), so callers can pass fresh selection/scene refs without
|
|
15
15
|
* triggering re-registration.
|
|
16
16
|
*/
|
|
17
|
-
function useAreaSelectDepSource(scene, selection, descriptor, alphaOf) {
|
|
17
|
+
function useAreaSelectDepSource(scene, selection, descriptor, alphaOf, reachable) {
|
|
18
18
|
const sceneRef = useLatest(scene);
|
|
19
19
|
const selectionRef = useLatest(selection);
|
|
20
20
|
const descriptorRef = useLatest(descriptor);
|
|
21
21
|
const alphaOfRef = useLatest(alphaOf);
|
|
22
|
+
const reachableRef = useLatest(reachable);
|
|
22
23
|
useDepSource("areaSelect", () => {
|
|
23
24
|
const sc = sceneRef.current;
|
|
24
25
|
const s = selectionRef.current;
|
|
25
26
|
const d = descriptorRef.current;
|
|
26
27
|
const a = alphaOfRef.current;
|
|
28
|
+
const r = reachableRef.current;
|
|
29
|
+
const keep = (ids) => r ? ids.filter((id) => r(id)) : ids;
|
|
27
30
|
return {
|
|
28
|
-
hitTestArea: (bounds, view) => hitTestArea(sc, bounds, regionPickOptions(view, a), d),
|
|
31
|
+
hitTestArea: (bounds, view) => keep(hitTestArea(sc, bounds, regionPickOptions(view, a), d)),
|
|
29
32
|
getSelection: () => s.current,
|
|
30
33
|
setSelection: (ids) => s.set(ids)
|
|
31
34
|
};
|