@weasel-js/core 1.9.3 → 1.9.4
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 +356 -0
- package/README.md +2 -2
- package/dist/WeaselProvider.js +5 -5
- package/dist/affordances/composeAffordanceLayer.js +10 -20
- package/dist/affordances/composeAffordanceLayer.js.map +1 -1
- package/dist/affordances/cornerResize.js +25 -17
- package/dist/affordances/cornerResize.js.map +1 -1
- package/dist/affordances/hitAffordanceRegions.js +27 -20
- package/dist/affordances/hitAffordanceRegions.js.map +1 -1
- package/dist/affordances/rotationHandle.js +18 -18
- package/dist/affordances/rotationHandle.js.map +1 -1
- package/dist/animation/behaviors/momentum.js +93 -55
- package/dist/animation/behaviors/momentum.js.map +1 -1
- package/dist/animation/loop.js +10 -12
- package/dist/animation/loop.js.map +1 -1
- package/dist/animation/reflow.js +8 -8
- package/dist/animation/reflow.js.map +1 -1
- package/dist/animation/stagger.js +64 -56
- package/dist/animation/stagger.js.map +1 -1
- package/dist/animation/timeline/booking.js +62 -54
- package/dist/animation/timeline/booking.js.map +1 -1
- package/dist/animation/timeline/createTimeline.js +85 -76
- package/dist/animation/timeline/createTimeline.js.map +1 -1
- package/dist/animation/timeline/sampleTrack.js +13 -5
- package/dist/animation/timeline/sampleTrack.js.map +1 -1
- package/dist/animation/useAnimator.js +45 -35
- package/dist/animation/useAnimator.js.map +1 -1
- package/dist/animation/wrappers/animateLifecycle.js +31 -24
- package/dist/animation/wrappers/animateLifecycle.js.map +1 -1
- package/dist/animation/wrappers/animateOnSetPose.js +28 -26
- package/dist/animation/wrappers/animateOnSetPose.js.map +1 -1
- package/dist/animation/wrappers/instantPose.js +13 -0
- package/dist/animation/wrappers/instantPose.js.map +1 -0
- package/dist/{poseDescriptor-D-OH-tu5.d.ts → autoPoseDescriptor-Ct7yqivU.d.ts} +28 -3
- package/dist/barrel/chrome.js +16 -0
- package/dist/barrel/input.js +19 -0
- package/dist/barrel/interactions.js +42 -0
- package/dist/barrel/paint.js +18 -0
- package/dist/barrel/paths.js +19 -0
- package/dist/barrel/renderer.js +20 -0
- package/dist/barrel/routing.js +51 -0
- package/dist/barrel/text.js +18 -0
- package/dist/barrel/viewport.js +52 -0
- package/dist/builtins-DPcdghtB.d.ts +1223 -0
- package/dist/canvas/Canvas.js +363 -448
- package/dist/canvas/Canvas.js.map +1 -1
- package/dist/canvas/CanvasView.js +164 -165
- package/dist/canvas/CanvasView.js.map +1 -1
- package/dist/canvas/CursorCoordsHud.js +37 -32
- package/dist/canvas/CursorCoordsHud.js.map +1 -1
- package/dist/canvas/DrawCanvas.js +49 -43
- package/dist/canvas/DrawCanvas.js.map +1 -1
- package/dist/canvas/MinimapCanvas.js +26 -25
- package/dist/canvas/MinimapCanvas.js.map +1 -1
- package/dist/canvas/NodeShape.js +59 -377
- package/dist/canvas/NodeShape.js.map +1 -1
- package/dist/canvas/PickHud.js +50 -47
- package/dist/canvas/PickHud.js.map +1 -1
- package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js +167 -0
- package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js.map +1 -0
- package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +13 -13
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js +67 -0
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js.map +1 -0
- package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js +16 -0
- package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js.map +1 -0
- package/dist/canvas/SceneCanvas/coordTrace.js +10 -0
- package/dist/canvas/SceneCanvas/coordTrace.js.map +1 -0
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js +112 -70
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js +9 -8
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
- package/dist/canvas/SceneCanvas/features.js +1 -0
- package/dist/canvas/SceneCanvas/features.js.map +1 -1
- package/dist/canvas/SceneCanvas/isDev.js +12 -0
- package/dist/canvas/SceneCanvas/isDev.js.map +1 -0
- package/dist/canvas/SceneCanvas/poseGeometry.js +29 -28
- package/dist/canvas/SceneCanvas/poseGeometry.js.map +1 -1
- package/dist/canvas/SceneCanvas/poseRegistrars.js +13 -0
- package/dist/canvas/SceneCanvas/poseRegistrars.js.map +1 -0
- package/dist/canvas/SceneCanvas/props.js +38 -0
- package/dist/canvas/SceneCanvas/props.js.map +1 -0
- package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js +21 -62
- package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +46 -48
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +33 -33
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +534 -788
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/SceneViewCanvas.js +45 -43
- package/dist/canvas/SceneViewCanvas.js.map +1 -1
- package/dist/canvas/buildSceneLayer.js +91 -0
- package/dist/canvas/buildSceneLayer.js.map +1 -0
- package/dist/canvas/buildSceneTree.js +16 -19
- package/dist/canvas/buildSceneTree.js.map +1 -1
- package/dist/canvas/canvasRenderer.js +68 -52
- package/dist/canvas/canvasRenderer.js.map +1 -1
- package/dist/canvas/deps/changes.js +13 -0
- package/dist/canvas/deps/changes.js.map +1 -0
- package/dist/canvas/deps/editAnchors.js +28 -28
- package/dist/canvas/deps/insert.js +119 -91
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/slice.js +46 -45
- package/dist/canvas/deps/slice.js.map +1 -1
- package/dist/canvas/deps/textEdit.js +10 -9
- package/dist/canvas/deps/textEdit.js.map +1 -1
- package/dist/canvas/derivedPath.js +46 -23
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/getNodeAtPoint.js +7 -7
- package/dist/canvas/getNodeAtPoint.js.map +1 -1
- package/dist/canvas/hud.module.js +1 -1
- package/dist/canvas/hud.module.js.map +1 -1
- package/dist/canvas/kitRequirements.js +2 -2
- package/dist/canvas/kitRequirements.js.map +1 -1
- package/dist/canvas/layerOrder.js +13 -6
- package/dist/canvas/layerOrder.js.map +1 -1
- package/dist/canvas/minimapMath.js +12 -10
- package/dist/canvas/minimapMath.js.map +1 -1
- package/dist/canvas/nodeShapes/derivedPainter.js +34 -0
- package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/imagePainter.js +87 -0
- package/dist/canvas/nodeShapes/imagePainter.js.map +1 -0
- package/dist/canvas/nodeShapes/memo.js +9 -0
- package/dist/canvas/nodeShapes/memo.js.map +1 -0
- package/dist/canvas/nodeShapes/nodePaint.js +57 -0
- package/dist/canvas/nodeShapes/nodePaint.js.map +1 -0
- package/dist/canvas/nodeShapes/pathPainter.js +38 -0
- package/dist/canvas/nodeShapes/pathPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/poseBox.js +20 -0
- package/dist/canvas/nodeShapes/poseBox.js.map +1 -0
- package/dist/canvas/nodeShapes/rectFallbackPainter.js +38 -0
- package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/shapePainter.js +72 -0
- package/dist/canvas/nodeShapes/shapePainter.js.map +1 -0
- package/dist/canvas/nodeShapes/textPainter.js +55 -0
- package/dist/canvas/nodeShapes/textPainter.js.map +1 -0
- package/dist/canvas/overlayRoleStrokes.js.map +1 -1
- package/dist/canvas/paintCull.js +10 -11
- package/dist/canvas/paintCull.js.map +1 -1
- package/dist/canvas/pickWalk.js +52 -63
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/poseRotation.js +11 -23
- package/dist/canvas/poseRotation.js.map +1 -1
- package/dist/canvas/renderDebugSnapshot.js +5 -5
- package/dist/canvas/renderSceneToPixels.js +3 -1
- package/dist/canvas/renderSceneToPixels.js.map +1 -1
- package/dist/canvas/sceneAdapter.js +66 -148
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneClipboard.js +112 -0
- package/dist/canvas/sceneClipboard.js.map +1 -0
- package/dist/canvas/sceneSlotWiring.js +4 -4
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +39 -40
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/useCanvasRenderer.js +14 -6
- package/dist/canvas/useCanvasRenderer.js.map +1 -1
- package/dist/canvas/useCanvasView.js +58 -0
- package/dist/canvas/useCanvasView.js.map +1 -0
- package/dist/canvas/useFrameLoop.js +35 -26
- package/dist/canvas/useFrameLoop.js.map +1 -1
- package/dist/canvas/useSceneLayerList.js +21 -0
- package/dist/canvas/useSceneLayerList.js.map +1 -0
- package/dist/clipboard.d.ts +10 -6
- package/dist/clone.d.ts +4 -3
- package/dist/core/adapters/arrayAdapter.js +48 -39
- package/dist/core/adapters/arrayAdapter.js.map +1 -1
- package/dist/core/device/index.js +5 -4
- package/dist/core/device/useDeviceProfile.js +38 -44
- package/dist/core/device/useDeviceProfile.js.map +1 -1
- package/dist/core/device/watchDevicePixelRatio.js +17 -0
- package/dist/core/device/watchDevicePixelRatio.js.map +1 -0
- package/dist/core/fillInPoseFrame.js.map +1 -1
- package/dist/core/geometry/poseDescriptor.js +21 -19
- package/dist/core/geometry/poseDescriptor.js.map +1 -1
- package/dist/core/geometry/poseFrame.js +44 -0
- package/dist/core/geometry/poseFrame.js.map +1 -0
- package/dist/core/geometry/poseRotation.js.map +1 -1
- package/dist/core/geometry/regionHit.js +9 -10
- package/dist/core/geometry/regionHit.js.map +1 -1
- package/dist/core/geometry/unionBounds.js +31 -29
- package/dist/core/geometry/unionBounds.js.map +1 -1
- package/dist/core/isPlainObject.js +2 -11
- package/dist/core/ops/arrange.js +1 -0
- package/dist/core/ops/arrange.js.map +1 -1
- package/dist/core/ops/create.js +10 -5
- package/dist/core/ops/create.js.map +1 -1
- package/dist/core/ops/delete.js +12 -24
- package/dist/core/ops/delete.js.map +1 -1
- package/dist/core/ops/reorder/index.js +43 -40
- package/dist/core/ops/reorder/index.js.map +1 -1
- package/dist/core/ops/reorder/setChildOrder.js +34 -0
- package/dist/core/ops/reorder/setChildOrder.js.map +1 -0
- package/dist/core/paintKinds.js +5 -5
- package/dist/core/paintKinds.js.map +1 -1
- package/dist/core/scene/NodeProperties.js.map +1 -1
- package/dist/core/scene/appliedLog.js +37 -0
- package/dist/core/scene/appliedLog.js.map +1 -0
- package/dist/core/scene/arrivalWindow.js +101 -0
- package/dist/core/scene/arrivalWindow.js.map +1 -0
- package/dist/core/scene/derivedPath.js.map +1 -1
- package/dist/core/scene/historyFacade.js +84 -0
- package/dist/core/scene/historyFacade.js.map +1 -0
- package/dist/core/scene/kitOps.js +173 -0
- package/dist/core/scene/kitOps.js.map +1 -0
- package/dist/core/scene/layerStack.js +38 -0
- package/dist/core/scene/layerStack.js.map +1 -0
- package/dist/core/scene/lockGuard.js +37 -0
- package/dist/core/scene/lockGuard.js.map +1 -0
- package/dist/core/scene/nodeFnFields.js +5 -6
- package/dist/core/scene/nodeFnFields.js.map +1 -1
- package/dist/core/scene/nodeMemo.js +45 -19
- package/dist/core/scene/nodeMemo.js.map +1 -1
- package/dist/core/scene/nodeStore.js +126 -0
- package/dist/core/scene/nodeStore.js.map +1 -0
- package/dist/core/scene/pickability.js +6 -0
- package/dist/core/scene/pickability.js.map +1 -0
- package/dist/core/scene/poseFeed.js +38 -38
- package/dist/core/scene/poseFeed.js.map +1 -1
- package/dist/core/scene/poseOverrides.js +34 -38
- package/dist/core/scene/poseOverrides.js.map +1 -1
- package/dist/core/scene/renderOrder.js +84 -0
- package/dist/core/scene/renderOrder.js.map +1 -0
- package/dist/core/scene/scene.js +289 -866
- package/dist/core/scene/scene.js.map +1 -1
- package/dist/core/scene/serialization.js +68 -0
- package/dist/core/scene/serialization.js.map +1 -0
- package/dist/core/scene/treeOrder.js +13 -0
- package/dist/core/scene/treeOrder.js.map +1 -0
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/viewport/meanScale.js +1 -1
- package/dist/core/viewport/meanScale.js.map +1 -1
- package/dist/core/viewport/view.js +12 -12
- package/dist/core/viewport/view.js.map +1 -1
- package/dist/core/viewport/zoomBounds.js +10 -8
- package/dist/core/viewport/zoomBounds.js.map +1 -1
- package/dist/{cornerHandles-BCrDp_mH.d.ts → cornerHandles-CtCb8a3G.d.ts} +1 -1
- package/dist/debug/createDebugOverlayLayer.js +14 -14
- package/dist/debug/createDebugOverlayLayer.js.map +1 -1
- package/dist/debug/flag.js +2 -41
- package/dist/features/chrome-caps/useHoverTracking.js +22 -17
- package/dist/features/chrome-caps/useHoverTracking.js.map +1 -1
- package/dist/features/focus/gateLayer.js +3 -4
- package/dist/features/focus/gateLayer.js.map +1 -1
- package/dist/features/images/imageCache.js +19 -9
- package/dist/features/images/imageCache.js.map +1 -1
- package/dist/features/ingestion/contentHandlers.js +14 -11
- package/dist/features/ingestion/contentHandlers.js.map +1 -1
- package/dist/features/ingestion/index.js +1 -1
- package/dist/features/ingestion/registerKitHandlers.js +7 -7
- package/dist/features/ingestion/weaselJsonHandler.js +17 -14
- package/dist/features/ingestion/weaselJsonHandler.js.map +1 -1
- package/dist/features/meshPaint/lazyKind.js +201 -35
- package/dist/features/meshPaint/lazyKind.js.map +1 -1
- package/dist/features/meshPaint/meshPaint.js +82 -79
- package/dist/features/meshPaint/meshPaint.js.map +1 -1
- package/dist/features/minimap/createMinimapContribution.js +42 -42
- package/dist/features/minimap/layers.js +44 -62
- package/dist/features/minimap/layers.js.map +1 -1
- package/dist/features/parallax/createParallaxPlane.js +10 -14
- package/dist/features/parallax/createParallaxPlane.js.map +1 -1
- package/dist/features/paths/anchorEdits.js +19 -8
- package/dist/features/paths/anchorEdits.js.map +1 -1
- package/dist/features/paths/anchors.js +31 -26
- package/dist/features/paths/anchors.js.map +1 -1
- package/dist/features/paths/booleans.js +2 -2
- package/dist/features/paths/index.js +13 -11
- package/dist/features/paths/markerCommands.js +37 -36
- package/dist/features/paths/markerCommands.js.map +1 -1
- package/dist/features/paths/pathInWorld.js +19 -19
- package/dist/features/paths/pathInWorld.js.map +1 -1
- package/dist/features/paths/pathLayer.js.map +1 -1
- package/dist/features/paths/strokeToPath.js +40 -0
- package/dist/features/paths/strokeToPath.js.map +1 -0
- package/dist/features/paths/tessellate/stroke.js.map +1 -1
- package/dist/features/patterns/commandPaint.js +18 -0
- package/dist/features/patterns/commandPaint.js.map +1 -0
- package/dist/features/patterns/index.js +5 -17
- package/dist/features/patterns/index.js.map +1 -1
- package/dist/features/patterns/rasterizeTile.js +17 -0
- package/dist/features/patterns/rasterizeTile.js.map +1 -0
- package/dist/features/patterns/resolveSpec.js +52 -44
- package/dist/features/patterns/resolveSpec.js.map +1 -1
- package/dist/features/poseRun/usePoseRun.js +8 -3
- package/dist/features/poseRun/usePoseRun.js.map +1 -1
- package/dist/features/selection/SelectionContext.js +5 -0
- package/dist/features/selection/SelectionContext.js.map +1 -1
- package/dist/features/selection/overlay.js +18 -18
- package/dist/features/selection/overlay.js.map +1 -1
- package/dist/features/text/domOffsets.js +82 -0
- package/dist/features/text/domOffsets.js.map +1 -0
- package/dist/features/text/domRuns.js +103 -131
- package/dist/features/text/domRuns.js.map +1 -1
- package/dist/features/text/hitTest.js +5 -2
- package/dist/features/text/hitTest.js.map +1 -1
- package/dist/features/text/isTextData.js +8 -0
- package/dist/features/text/isTextData.js.map +1 -0
- package/dist/features/text/overlayDirection.js +15 -0
- package/dist/features/text/overlayDirection.js.map +1 -0
- package/dist/features/text/runs/rangeStyle.js +32 -34
- package/dist/features/text/runs/rangeStyle.js.map +1 -1
- package/dist/features/text/textCommand.js +34 -33
- package/dist/features/text/textCommand.js.map +1 -1
- package/dist/features/text/textToPath.js +40 -40
- package/dist/features/text/textToPath.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +76 -82
- package/dist/features/text/useSceneTextEdit.js.map +1 -1
- package/dist/features/text/useTextEdit.js +184 -160
- package/dist/features/text/useTextEdit.js.map +1 -1
- package/dist/features/tiling/createTiledLayer.js +24 -22
- package/dist/features/tiling/createTiledLayer.js.map +1 -1
- package/dist/index.d.ts +11033 -7749
- package/dist/index.js +316 -309
- package/dist/input/keyState.js +42 -43
- package/dist/input/keyState.js.map +1 -1
- package/dist/input/useKeyModifiers.js +11 -0
- package/dist/input/useKeyModifiers.js.map +1 -0
- package/dist/interactions/actions/align/align.js +8 -8
- package/dist/interactions/actions/clipboard/clipboardOps.js +34 -32
- package/dist/interactions/actions/clipboard/clipboardOps.js.map +1 -1
- package/dist/interactions/actions/clipboard/materializePaste.js +10 -7
- package/dist/interactions/actions/clipboard/materializePaste.js.map +1 -1
- package/dist/interactions/actions/clipboard/wireFormat.js.map +1 -1
- package/dist/interactions/actions/clone/behaviors/cloneByAltDrag.js.map +1 -1
- package/dist/interactions/actions/defaultCommitAdapter.js +20 -18
- package/dist/interactions/actions/defaultCommitAdapter.js.map +1 -1
- package/dist/interactions/actions/defaults/align.js +9 -10
- package/dist/interactions/actions/defaults/align.js.map +1 -1
- package/dist/interactions/actions/defaults/anchorEditing.js +59 -81
- package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
- package/dist/interactions/actions/defaults/areaSelect.js +35 -38
- package/dist/interactions/actions/defaults/areaSelect.js.map +1 -1
- package/dist/interactions/actions/defaults/clipboard.js +26 -10
- package/dist/interactions/actions/defaults/clipboard.js.map +1 -1
- package/dist/interactions/actions/defaults/clone.js +44 -60
- package/dist/interactions/actions/defaults/clone.js.map +1 -1
- package/dist/interactions/actions/defaults/copySubtree.js +40 -0
- package/dist/interactions/actions/defaults/copySubtree.js.map +1 -0
- package/dist/interactions/actions/defaults/distribute.js +14 -13
- package/dist/interactions/actions/defaults/distribute.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +17 -57
- package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
- package/dist/interactions/actions/defaults/editAnchors.js +18 -18
- package/dist/interactions/actions/defaults/enterTextEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/flip.js +52 -46
- package/dist/interactions/actions/defaults/flip.js.map +1 -1
- package/dist/interactions/actions/defaults/group.js +43 -48
- package/dist/interactions/actions/defaults/group.js.map +1 -1
- package/dist/interactions/actions/defaults/ingest.js +35 -33
- package/dist/interactions/actions/defaults/ingest.js.map +1 -1
- package/dist/interactions/actions/defaults/insert.js +50 -51
- package/dist/interactions/actions/defaults/insert.js.map +1 -1
- package/dist/interactions/actions/defaults/insertPathAnchor.js +7 -7
- package/dist/interactions/actions/defaults/lassoSelect.js +67 -70
- package/dist/interactions/actions/defaults/lassoSelect.js.map +1 -1
- package/dist/interactions/actions/defaults/move.js +267 -249
- package/dist/interactions/actions/defaults/move.js.map +1 -1
- package/dist/interactions/actions/defaults/nudge.js +40 -68
- package/dist/interactions/actions/defaults/nudge.js.map +1 -1
- package/dist/interactions/actions/defaults/nudgeSteps.js +37 -0
- package/dist/interactions/actions/defaults/nudgeSteps.js.map +1 -0
- package/dist/interactions/actions/defaults/reorder.js +2 -0
- package/dist/interactions/actions/defaults/reorder.js.map +1 -1
- package/dist/interactions/actions/defaults/resize.js +104 -98
- package/dist/interactions/actions/defaults/resize.js.map +1 -1
- package/dist/interactions/actions/defaults/rotate.js +111 -110
- package/dist/interactions/actions/defaults/rotate.js.map +1 -1
- package/dist/interactions/actions/defaults/setFill.js +7 -7
- package/dist/interactions/actions/defaults/setFillOpacity.js +4 -4
- package/dist/interactions/actions/defaults/setStroke.js +12 -12
- package/dist/interactions/actions/defaults/setStrokeOpacity.js +6 -6
- package/dist/interactions/actions/defaults/sliceOps.js +19 -19
- package/dist/interactions/actions/defaults/viewportDragPan.js +37 -26
- package/dist/interactions/actions/defaults/viewportDragPan.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/geometry.js +28 -23
- package/dist/interactions/actions/edit-anchors/geometry.js.map +1 -1
- package/dist/interactions/actions/flip/helpers.js +30 -17
- package/dist/interactions/actions/flip/helpers.js.map +1 -1
- package/dist/interactions/actions/hitSelection.js +8 -0
- package/dist/interactions/actions/hitSelection.js.map +1 -0
- package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js +14 -18
- package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js +5 -5
- package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapToContainer.js +32 -21
- package/dist/interactions/actions/move/behaviors/snapToContainer.js.map +1 -1
- package/dist/interactions/actions/move/gestureAdapter.js +32 -15
- package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
- package/dist/interactions/actions/move/landedDescendants.js +33 -0
- package/dist/interactions/actions/move/landedDescendants.js.map +1 -0
- package/dist/interactions/actions/outlines/createOutlines.js +18 -18
- package/dist/interactions/actions/poseDescriptorDep.js +16 -4
- package/dist/interactions/actions/poseDescriptorDep.js.map +1 -1
- package/dist/interactions/actions/poseFrame.js +11 -6
- package/dist/interactions/actions/poseFrame.js.map +1 -1
- package/dist/interactions/actions/previewOverrides.js +5 -5
- package/dist/interactions/actions/previewOverrides.js.map +1 -1
- package/dist/interactions/actions/selectionSubtree.js +69 -0
- package/dist/interactions/actions/selectionSubtree.js.map +1 -0
- package/dist/interactions/actions/useStandardActions.js +66 -62
- package/dist/interactions/actions/useStandardActions.js.map +1 -1
- package/dist/interactions/gestures/dragGesture/dragGesture.js +4 -7
- package/dist/interactions/gestures/dragGesture/dragGesture.js.map +1 -1
- package/dist/interactions/gestures/dragGesture/dragPointOf.js +23 -0
- package/dist/interactions/gestures/dragGesture/dragPointOf.js.map +1 -0
- package/dist/interactions/gestures/handleDrag/handleDrag.js +21 -26
- package/dist/interactions/gestures/handleDrag/handleDrag.js.map +1 -1
- package/dist/interactions/gestures/pointerDrag/pointerDrag.js +8 -6
- package/dist/interactions/gestures/pointerDrag/pointerDrag.js.map +1 -1
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +8 -4
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
- package/dist/{math-Drrw4ewZ.d.ts → math-J-ACHyEg.d.ts} +1 -2
- package/dist/math.d.ts +2 -3
- package/dist/move.d.ts +12 -11
- package/dist/{originProjection-DEklpDc_.d.ts → originProjection-gHnOup4e.d.ts} +1 -1
- package/dist/{registerProgram-BMZRDgrh.d.ts → registerProgram-T9S_PfAX.d.ts} +18 -7
- package/dist/renderer/DrawCommand.js.map +1 -1
- package/dist/renderer/WeaselRenderer.js +75 -73
- package/dist/renderer/WeaselRenderer.js.map +1 -1
- package/dist/renderer/cache/GLImageCache.js +15 -5
- package/dist/renderer/cache/GLImageCache.js.map +1 -1
- package/dist/renderer/cache/GLMeshCache.js +23 -23
- package/dist/renderer/cache/GLMeshCache.js.map +1 -1
- package/dist/renderer/cache/GLTextureCache.js +18 -1
- package/dist/renderer/cache/GLTextureCache.js.map +1 -1
- package/dist/renderer/cache/cache.js.map +1 -1
- package/dist/renderer/cache/markerCommandCache.js.map +1 -1
- package/dist/renderer/cache/strokeMeshCache.js.map +1 -1
- package/dist/renderer/cullDrawCommands.js +11 -11
- package/dist/renderer/draw/batch.js +133 -0
- package/dist/renderer/draw/batch.js.map +1 -0
- package/dist/renderer/draw/clip.js +89 -0
- package/dist/renderer/draw/clip.js.map +1 -0
- package/dist/renderer/draw/customShader.js +230 -0
- package/dist/renderer/draw/customShader.js.map +1 -0
- package/dist/renderer/draw/drawTriangles.js +8 -0
- package/dist/renderer/draw/drawTriangles.js.map +1 -0
- package/dist/renderer/draw/effects.js +28 -0
- package/dist/renderer/draw/effects.js.map +1 -0
- package/dist/renderer/draw/flushBatch.js +35 -0
- package/dist/renderer/draw/flushBatch.js.map +1 -0
- package/dist/renderer/draw/gradient.js +90 -0
- package/dist/renderer/draw/gradient.js.map +1 -0
- package/dist/renderer/draw/image.js +38 -0
- package/dist/renderer/draw/image.js.map +1 -0
- package/dist/renderer/draw/mesh.js +16 -0
- package/dist/renderer/draw/mesh.js.map +1 -0
- package/dist/renderer/draw/paintBind.js +70 -0
- package/dist/renderer/draw/paintBind.js.map +1 -0
- package/dist/renderer/draw/pathPaint.js +142 -0
- package/dist/renderer/draw/pathPaint.js.map +1 -0
- package/dist/renderer/draw/scratchPass.js +83 -0
- package/dist/renderer/draw/scratchPass.js.map +1 -0
- package/dist/renderer/draw/stencil.js +28 -0
- package/dist/renderer/draw/stencil.js.map +1 -0
- package/dist/renderer/draw/text.js +167 -0
- package/dist/renderer/draw/text.js.map +1 -0
- package/dist/renderer/draw/uniforms.js +77 -0
- package/dist/renderer/draw/uniforms.js.map +1 -0
- package/dist/renderer/draw.js +60 -1116
- package/dist/renderer/draw.js.map +1 -1
- package/dist/renderer/effects/EffectTargets.js +3 -0
- package/dist/renderer/effects/EffectTargets.js.map +1 -1
- package/dist/renderer/effects/composite.js +7 -5
- package/dist/renderer/effects/composite.js.map +1 -1
- package/dist/renderer/index.js +18 -17
- package/dist/renderer/math/color.js +63 -83
- package/dist/renderer/math/color.js.map +1 -1
- package/dist/renderer/math/mat3.js +15 -11
- package/dist/renderer/math/mat3.js.map +1 -1
- package/dist/renderer/math/viewToMat3.js +1 -1
- package/dist/renderer/math/viewToMat3.js.map +1 -1
- package/dist/renderer/shaders/ShaderProgram.js +13 -13
- package/dist/renderer/shaders/ShaderProgram.js.map +1 -1
- package/dist/renderer/shaders/glyphPaint.js +3 -3
- package/dist/renderer/shaders/glyphPaint.js.map +1 -1
- package/dist/renderer/shaders/gradFill.js +2 -1
- package/dist/renderer/shaders/gradFill.js.map +1 -1
- package/dist/renderer/shaders/pathFill.js +2 -1
- package/dist/renderer/shaders/pathFill.js.map +1 -1
- package/dist/renderer/shaders/patternFill.js +2 -1
- package/dist/renderer/shaders/patternFill.js.map +1 -1
- package/dist/renderer/shaders/registerProgram.js.map +1 -1
- package/dist/renderer/strokeLengths.js.map +1 -1
- package/dist/renderer/textures/registerTexture.js +25 -5
- package/dist/renderer/textures/registerTexture.js.map +1 -1
- package/dist/renderer.d.ts +16 -15
- package/dist/renderer.js +17 -16
- package/dist/resize.d.ts +5 -6
- package/dist/resize.js +5 -5
- package/dist/style.css +1 -1
- package/dist/test-hook/install.js +12 -6
- package/dist/test-hook/install.js.map +1 -1
- package/dist/{test-seams-CuIxe0xY.d.ts → test-seams-DM2B87-g.d.ts} +4 -4
- package/dist/test-seams.d.ts +2 -2
- package/dist/tools/builtin/ellipse/useEllipseTool.js +1 -0
- package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
- package/dist/tools/builtin/hand/useHandTool.js +1 -0
- package/dist/tools/builtin/hand/useHandTool.js.map +1 -1
- package/dist/tools/builtin/lasso/useLassoTool.js +11 -11
- 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/pen/usePenTool.js +153 -103
- 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 -8
- package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
- package/dist/tools/builtin/rect/useRectTool.js +1 -0
- package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
- package/dist/tools/builtin/select/selectionContributions.js +24 -23
- package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
- package/dist/tools/builtin/select/useSelectTool.js +51 -48
- package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
- package/dist/tools/builtin/shared/pointerFollower.js +17 -0
- package/dist/tools/builtin/shared/pointerFollower.js.map +1 -0
- package/dist/tools/builtin/slice/useSliceTool.js +49 -54
- package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
- package/dist/tools/builtin/star/useStarTool.js +22 -16
- package/dist/tools/builtin/star/useStarTool.js.map +1 -1
- package/dist/tools/builtin/text/useTextTool.js +1 -0
- package/dist/tools/builtin/text/useTextTool.js.map +1 -1
- package/dist/tools/useKeybindings.js +14 -30
- package/dist/tools/useKeybindings.js.map +1 -1
- package/dist/{types-B_9g6hMM.d.ts → types-B4iJRHC3.d.ts} +5 -1
- package/dist/{types-A37hYkeR.d.ts → types-k-5Oqh-U.d.ts} +31 -7
- package/dist/util/color.js +3 -3
- package/dist/util/color.js.map +1 -1
- package/dist/util/paint.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +20 -18
- package/dist/autoPoseDescriptor-vCdt55xm.d.ts +0 -27
- package/dist/builtins-C-VgUlWI.d.ts +0 -4514
- package/dist/core/isPlainObject.js.map +0 -1
- package/dist/debug/flag.js.map +0 -1
- package/dist/interactions/actions/defaults/freshNodeId.js +0 -10
- package/dist/interactions/actions/defaults/freshNodeId.js.map +0 -1
- package/dist/renderer/shaders/imageFill.js +0 -14
- package/dist/renderer/shaders/imageFill.js.map +0 -1
- package/dist/tools/prefs.js +0 -62
- package/dist/tools/prefs.js.map +0 -1
package/dist/canvas/pickWalk.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { planeMap as e } from "../core/viewport/parallax.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { asNodeId as
|
|
6
|
-
import {
|
|
7
|
-
import { clipCarrier as s } from "./planeClips.js";
|
|
2
|
+
import { resolveDerivedPath as t } from "../core/scene/derivedPath.js";
|
|
3
|
+
import { clipCarrier as n } from "./planeClips.js";
|
|
4
|
+
import { findShapeSilhouette as r } from "./NodeShape.js";
|
|
5
|
+
import { asNodeId as i } from "../core/scene/types.js";
|
|
6
|
+
import { sceneDerivedPathOf as a, scenePaintedPoseOf as o } from "./derivedPath.js";
|
|
8
7
|
//#region src/canvas/pickWalk.ts
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
-
return e.kind === "container" ? typeof e.clipFromPose == "function" ? e.clipFromPose(t) :
|
|
8
|
+
var s = [];
|
|
9
|
+
function c(e, t, n) {
|
|
10
|
+
return e.kind === "container" ? typeof e.clipFromPose == "function" ? e.clipFromPose(t) : r(e, t, { derivedPath: n }) : null;
|
|
12
11
|
}
|
|
13
|
-
function
|
|
14
|
-
let
|
|
15
|
-
let n =
|
|
12
|
+
function l(e, t) {
|
|
13
|
+
let r = t.includeContainers ?? !0, i = t.includeLocked === !0 ? void 0 : e.isLocked, a = [], o = /* @__PURE__ */ new Map(), s = n(e.planeOf ?? null), l = (t) => {
|
|
14
|
+
let n = o.get(t.id);
|
|
16
15
|
if (n !== void 0) return n;
|
|
17
|
-
let r =
|
|
18
|
-
return
|
|
16
|
+
let r = c(t, e.poseOf(t), e.derivedPathOf?.(t));
|
|
17
|
+
return o.set(t.id, r), r;
|
|
19
18
|
}, u = /* @__PURE__ */ new Map(), d = (n) => {
|
|
20
19
|
if (n === void 0 || e.planeOf === void 0) return t;
|
|
21
20
|
let r = u.get(n);
|
|
@@ -26,101 +25,91 @@ function u(e, t) {
|
|
|
26
25
|
return r;
|
|
27
26
|
};
|
|
28
27
|
for (let t of e.order()) {
|
|
29
|
-
if (!
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
let
|
|
33
|
-
if (!
|
|
28
|
+
if (!r && t.kind === "container" || t.pickable === !1 || t.layer !== void 0 && e.layerIsPainted?.(t.layer) === !1 || e.alphaOf !== void 0 && e.alphaOf(t.id) <= 0 || i !== void 0 && i(t)) continue;
|
|
29
|
+
let n = d(t.layer);
|
|
30
|
+
if (n === null) continue;
|
|
31
|
+
let o = e.poseOf(t), c = e.derivedPathOf?.(t);
|
|
32
|
+
if (!n.hits(t, o, c)) continue;
|
|
34
33
|
let u = !1;
|
|
35
|
-
for (let
|
|
36
|
-
let e =
|
|
37
|
-
if (e !== null && !
|
|
34
|
+
for (let r of e.parentsOf(t)) {
|
|
35
|
+
let e = l(r);
|
|
36
|
+
if (e !== null && !n.clipAdmits(s(e, r.layer, t.layer), t, o, c)) {
|
|
38
37
|
u = !0;
|
|
39
38
|
break;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
u ||
|
|
41
|
+
u || a.push(t.id);
|
|
43
42
|
}
|
|
44
|
-
return
|
|
43
|
+
return a;
|
|
45
44
|
}
|
|
46
|
-
function
|
|
45
|
+
function u(e) {
|
|
47
46
|
let t = null;
|
|
48
47
|
for (let n of e.layers ?? []) n.locked === !0 && (t ??= /* @__PURE__ */ new Set()).add(n.id);
|
|
49
48
|
if (t === null) return null;
|
|
50
49
|
let n = t;
|
|
51
50
|
return (t) => {
|
|
52
|
-
let r = e.get(
|
|
53
|
-
for (; r !== void 0 && !
|
|
51
|
+
let r = e.get(i(t)), a = /* @__PURE__ */ new Set();
|
|
52
|
+
for (; r !== void 0 && !a.has(r.id);) {
|
|
54
53
|
if (n.has(r.layer)) return !0;
|
|
55
|
-
|
|
54
|
+
a.add(r.id), r = r.parent === null ? void 0 : e.get(r.parent);
|
|
56
55
|
}
|
|
57
56
|
return !1;
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
|
-
function
|
|
59
|
+
function d(e) {
|
|
61
60
|
let t = /* @__PURE__ */ new Set();
|
|
62
61
|
for (let n of e ?? []) n.visible === !1 && t.add(n.id);
|
|
63
62
|
return t;
|
|
64
63
|
}
|
|
65
|
-
function
|
|
66
|
-
let
|
|
67
|
-
if (!
|
|
64
|
+
function f(e, n = {}) {
|
|
65
|
+
let r = d(e.layers), c = u(e), { getPose: l, alphaOf: f, layerIsPainted: m } = n, h = null, g = typeof e.overrides?.ids == "function";
|
|
66
|
+
if (!f && g) for (let t of e.overrides.ids()) {
|
|
68
67
|
let n = e.overrides.read(t)?.alpha;
|
|
69
|
-
n !== void 0 && n <= 0 && (
|
|
68
|
+
n !== void 0 && n <= 0 && (h ??= /* @__PURE__ */ new Set()).add(t);
|
|
70
69
|
}
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
let n = e.get(a(t));
|
|
74
|
-
return n ? i(e, n) : void 0;
|
|
75
|
-
},
|
|
76
|
-
getParent: (t) => e.get(a(t))?.parent ?? null,
|
|
77
|
-
definesFrame: (t) => {
|
|
78
|
-
let n = e.get(a(t));
|
|
79
|
-
return n === void 0 || r(n);
|
|
80
|
-
}
|
|
81
|
-
} : null, x = u ? (e) => u(e.id) : b ? (e) => t(b, e.id, y.compose) : (t) => i(e, t), S = (t) => e.childrenOf(t), C = (t) => {
|
|
82
|
-
let r = e.get(t);
|
|
70
|
+
let _ = f ?? (g ? h ? (e) => +!h.has(e) : void 0 : (t) => e.overrides.read(i(t))?.alpha ?? 1), v = n.poseComposition, y = o(e, void 0, v), b = l ? (e) => l(e.id) : (e) => y(e), x = (t) => e.childrenOf(t), S = (n) => {
|
|
71
|
+
let r = e.get(n);
|
|
83
72
|
if (r !== void 0) return {
|
|
84
73
|
node: r,
|
|
85
|
-
pose:
|
|
74
|
+
pose: b(r),
|
|
86
75
|
get path() {
|
|
87
|
-
return
|
|
76
|
+
return t(r, S, x);
|
|
88
77
|
}
|
|
89
78
|
};
|
|
90
|
-
}, w = (e) => {
|
|
91
|
-
let
|
|
92
|
-
return
|
|
93
|
-
}, T =
|
|
79
|
+
}, C = l ? null : a(e, void 0, v), w = (e) => {
|
|
80
|
+
let n = e;
|
|
81
|
+
return n.dependsOn === void 0 ? null : C ? C(n) : t(n, S, x);
|
|
82
|
+
}, T = n.camera ? p(e.layers, n.camera) : null;
|
|
94
83
|
return {
|
|
95
84
|
...T ? { planeOf: T } : {},
|
|
96
85
|
order: () => e.renderOrderNodes(),
|
|
97
86
|
derivedPathOf: w,
|
|
98
|
-
poseOf:
|
|
87
|
+
poseOf: b,
|
|
99
88
|
parentsOf(t) {
|
|
100
89
|
let n = t.parent ?? null;
|
|
101
|
-
if (n === null) return
|
|
102
|
-
let r = [],
|
|
103
|
-
for (; n !== null && !
|
|
104
|
-
|
|
105
|
-
let t = e.get(
|
|
90
|
+
if (n === null) return s;
|
|
91
|
+
let r = [], a = /* @__PURE__ */ new Set();
|
|
92
|
+
for (; n !== null && !a.has(n);) {
|
|
93
|
+
a.add(n);
|
|
94
|
+
let t = e.get(i(n));
|
|
106
95
|
if (!t) break;
|
|
107
96
|
r.push(t), n = t.parent ?? null;
|
|
108
97
|
}
|
|
109
98
|
return r;
|
|
110
99
|
},
|
|
111
|
-
...
|
|
112
|
-
...
|
|
113
|
-
...
|
|
100
|
+
..._ ? { alphaOf: _ } : {},
|
|
101
|
+
...c ? { isLocked: (e) => c(e.id) } : {},
|
|
102
|
+
...r.size > 0 || m ? { layerIsPainted: (e) => !r.has(e) && (m === void 0 || m(e)) } : {}
|
|
114
103
|
};
|
|
115
104
|
}
|
|
116
|
-
function
|
|
105
|
+
function p(t, n) {
|
|
117
106
|
let r = null;
|
|
118
107
|
for (let i of t ?? []) i.parallax && (r ??= /* @__PURE__ */ new Map()).set(i.id, e(n, i.parallax));
|
|
119
108
|
if (r === null) return null;
|
|
120
109
|
let i = r;
|
|
121
110
|
return (e) => i.get(e) ?? null;
|
|
122
111
|
}
|
|
123
|
-
function
|
|
112
|
+
function m(e, t = {}) {
|
|
124
113
|
let n = e, r = typeof e.getChildren == "function" && typeof e.getNode == "function", i = /* @__PURE__ */ new Map(), a = (t) => typeof e.getWorldPose == "function" ? e.getWorldPose(t) : e.getPose(t), o = (e) => ({
|
|
125
114
|
...n.getNode(e),
|
|
126
115
|
id: e,
|
|
@@ -153,6 +142,6 @@ function h(e, t = {}) {
|
|
|
153
142
|
};
|
|
154
143
|
}
|
|
155
144
|
//#endregion
|
|
156
|
-
export {
|
|
145
|
+
export { m as adapterPickSource, d as hiddenLayerIds, c as ownClipOf, l as pickWalk, f as scenePickSource, p as scenePlaneOf };
|
|
157
146
|
|
|
158
147
|
//# sourceMappingURL=pickWalk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pickWalk.js","names":["EMPTY_PARENTS","ownClipOf","node","pose","findShapeSilhouette","derived","pickWalk","includeContainers","q","isLocked","src","out","clipPath","carry","clipCarrier","clipOf","cached","ancestor","resolved","planeQueries","queryFor","layer","found","map","query","clipped","clip","lockedNodeTest","locked","scene","lockedLayers","cur","asNodeId","id","seen","hiddenLayerIds","layers","scenePickSource","hidden","opts","faded","enumerable","alphaOf","a","readAlpha","composition","chain","effectivePose","definesFrame","poseOf","getPose","composeWorldPose","childrenOf","depOf","dep","resolveDerivedPath","derivedPathOf","n","planeOf","scenePlaneOf","parentId","parent","layerIsPainted","maps","l","planeMap","camera","adapterPickSource","hier","adapter","hierarchical","parents","worldPose","nodeOf","next","visit","childId","gates"],"sources":["../../src/canvas/pickWalk.ts"],"sourcesContent":["/**\n * The one hit-test walk.\n *\n * Four walks used to answer this question — two point queries, two area\n * queries — over the same tree with the same gates. They drifted three times\n * without a failing test, because nothing held them to each other. Everything\n * that decides whether a node *can* be hit lives here now; a query supplies\n * only the shape test and the clip predicate for its own region.\n *\n * The gates, in the order the walk applies them:\n * 1. containers, when the query does not want them\n * 2. the layer is painted at all — scene visibility, and the asking view's\n * `layerVisibility` / `layerOrder`\n * 3. painted alpha is above zero\n * 4. the node is not locked, unless the query asks for locked nodes\n * 5. the query's own shape test\n * 6. every ancestor clip admits the query region\n *\n * 2, 3 and 6 are all \"the renderer did not put this on screen\". A pick path\n * that skips one answers for a node the user cannot see. 4 is the other axis:\n * a locked node is on screen and still out of reach.\n */\n\nimport type { Path } from '@weasel-js/geom';\nimport { findShapeSilhouette } from 'canvas/NodeShape';\nimport type { ClipFromPoseFn, DerivedDep, Node, NodeId, Scene } from 'core/scene/types';\nimport { asNodeId } from 'core/scene/types';\nimport { definesFrame, effectivePose } from 'core/scene/effectivePose';\nimport { resolveDerivedPath } from './derivedPath';\nimport { composeWorldPose, type PoseAdapter, type PoseComposition } from 'features/groups/composePose';\nimport { planeMap, type ParallaxOpts, type PlaneMap } from 'core/viewport/parallax';\nimport type { View } from 'core/viewport/view';\nimport { clipCarrier } from './planeClips';\n\n/** Shared, never mutated: most scenes are flat and every node returns it. */\nconst EMPTY_PARENTS: readonly never[] = [];\n\n/** The subset of a node the walk itself reads. Deliberately structural: a\n * bare adapter's node satisfies it as readily as a `SceneNode`. */\nexport interface PickCandidate<TPose> {\n id: string;\n kind?: string;\n layer?: string;\n pose: TPose;\n /** `false` makes the node transparent to the walk — see `SceneNode.pickable`. */\n pickable?: boolean;\n clipFromPose?: ClipFromPoseFn<TPose>;\n}\n\n/**\n * Everything the walk reads that a **view** owns.\n *\n * A layer must not hold state a view owns, so none of these are closed over\n * at construction — each is asked per walk, of the view being dispatched to.\n */\nexport interface PickSource<TPose> {\n /** Candidates in paint order, back-to-front. Containers included; the\n * query decides whether they can be hit. */\n order(): readonly PickCandidate<TPose>[];\n /** The pose the renderer draws — override-aware. Not `node.pose`, which is\n * how the render and pick paths came to disagree about where a node is. */\n poseOf(node: PickCandidate<TPose>): TPose;\n /** Ancestors, innermost first. Only walked for candidates that already\n * passed their own shape test. */\n parentsOf(node: PickCandidate<TPose>): readonly PickCandidate<TPose>[];\n /** Painted alpha for the asking view: the view's `alphaFor` times any\n * per-node override alpha. Omit when the source has no alpha concept. */\n alphaOf?(id: string): number;\n /** Whether this layer reaches the screen in the asking view. Omit for a\n * source with no layers. */\n layerIsPainted?(layer: string): boolean;\n /** Whether the node is locked — painted, but not something a pointer can\n * take. Omit for a source with no lock concept. */\n isLocked?(node: PickCandidate<TPose>): boolean;\n /** The path a node computes from its dependencies' poses, or null when it\n * derives nothing. Only a scene-backed source can answer — deriving needs\n * the dependencies' poses — so a bare adapter omits it, and every derived\n * node there keeps answering from its own (placeholder) pose. */\n derivedPathOf?(node: PickCandidate<TPose>): Path | null;\n /** How the asking view's world maps into a parallax layer's, or null for a\n * layer that moves with the camera. Omit for a source with no planes. */\n planeOf?(layer: string): PlaneMap | null;\n}\n\n/** One hit-test question: what region, and what counts as covering it. */\nexport interface PickQuery<TPose> {\n /** Default `true`. The area walks exclude containers so a marquee does not\n * return a container and its children both. */\n includeContainers?: boolean;\n /** Default `false`. Every selecting or editing query passes over locked\n * nodes; one that only samples what is painted can take them back. */\n includeLocked?: boolean;\n /** Does this node, drawn at this pose, cover the query region? `derived`\n * is the node's resolved path when it has one — a derived node's pose is a\n * placeholder, so a region test that reads only the pose answers for the\n * wrong box. */\n hits(node: PickCandidate<TPose>, pose: TPose, derived?: Path | null): boolean;\n /**\n * Does an ancestor's clip leave anything of `node` for this query to hit?\n *\n * A point query asks point-in-clip and ignores the node. An area query has\n * to ask about the node as well: the clip and the area can overlap where\n * the node is not, and the node and the clip can overlap where the area is\n * not, and only the two terms together reject both.\n */\n clipAdmits(\n clip: Path,\n node: PickCandidate<TPose>,\n pose: TPose,\n derived?: Path | null,\n ): boolean;\n /** The same question asked in a parallax plane's world: the region carried\n * through `map`, and any screen-pixel slop re-derived at the plane's scale.\n * A query without it cannot reach nodes on a plane — it would test them\n * where their poses sit rather than where they are painted. */\n inPlane?(map: PlaneMap): PickQuery<TPose>;\n}\n\n/** The clip a container imposes on its subtree, or null when it imposes none. */\nexport function ownClipOf<TPose>(\n node: PickCandidate<TPose>,\n pose: TPose,\n derived?: Path | null,\n): Path | null {\n if (node.kind !== 'container') return null;\n if (typeof node.clipFromPose === 'function') return node.clipFromPose(pose);\n return findShapeSilhouette(\n node as unknown as Node<unknown, string, TPose>,\n pose,\n { derivedPath: derived },\n );\n}\n\n/**\n * Collect every candidate the query hits, back-to-front — the last element is\n * the topmost, which is the order `pickTopMostHit` expects.\n */\nexport function pickWalk<TPose>(\n src: PickSource<TPose>,\n q: PickQuery<TPose>,\n): string[] {\n const includeContainers = q.includeContainers ?? true;\n const isLocked = q.includeLocked === true ? undefined : src.isLocked;\n const out: string[] = [];\n\n // Resolving a container's clip means `clipFromPose` or a silhouette build,\n // which is the expensive half; the predicate against it is cheap. So the\n // *path* is memoized per container for the walk and the predicate re-runs\n // per candidate — `clipAdmits` needs the candidate, and caching its answer\n // per container would answer the wrong question for an area query.\n const clipPath = new Map<string, Path | null>();\n // A clip is in its container's plane; the query is in the candidate's.\n const carry = clipCarrier(src.planeOf ?? null);\n\n const clipOf = (ancestor: PickCandidate<TPose>): Path | null => {\n const cached = clipPath.get(ancestor.id);\n if (cached !== undefined) return cached;\n const resolved = ownClipOf(\n ancestor, src.poseOf(ancestor), src.derivedPathOf?.(ancestor),\n );\n clipPath.set(ancestor.id, resolved);\n return resolved;\n };\n\n // One reprojected query per plane per walk; `null` marks a plane this\n // query cannot reach.\n const planeQueries = new Map<string, PickQuery<TPose> | null>();\n const queryFor = (layer: string | undefined): PickQuery<TPose> | null => {\n if (layer === undefined || src.planeOf === undefined) return q;\n let found = planeQueries.get(layer);\n if (found === undefined) {\n const map = src.planeOf(layer);\n found = map === null ? q : (q.inPlane?.(map) ?? null);\n planeQueries.set(layer, found);\n }\n return found;\n };\n\n for (const node of src.order()) {\n if (!includeContainers && node.kind === 'container') continue;\n // Transparent to picking: the click belongs to whatever is behind it,\n // which for a label inside a box is the box.\n if (node.pickable === false) continue;\n if (node.layer !== undefined && src.layerIsPainted?.(node.layer) === false) continue;\n if (src.alphaOf !== undefined && src.alphaOf(node.id) <= 0) continue;\n if (isLocked !== undefined && isLocked(node)) continue;\n\n const query = queryFor(node.layer);\n if (query === null) continue;\n const pose = src.poseOf(node);\n const derived = src.derivedPathOf?.(node);\n if (!query.hits(node, pose, derived)) continue;\n\n let clipped = false;\n for (const ancestor of src.parentsOf(node)) {\n const clip = clipOf(ancestor);\n if (clip === null) continue;\n if (!query.clipAdmits(carry(clip, ancestor.layer, node.layer), node, pose, derived)) {\n clipped = true;\n break;\n }\n }\n if (clipped) continue;\n\n out.push(node.id);\n }\n\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// Sources\n// ---------------------------------------------------------------------------\n\n/** Answers `Scene.isLocked` from the layer records and parent links alone,\n * so a partial scene stand-in works too. Null when nothing is locked, which\n * is what keeps the gate off the walk in the common case. */\nfunction lockedNodeTest(\n scene: Pick<Scene<unknown, string, unknown>, 'layers' | 'get'>,\n): ((id: string) => boolean) | null {\n let locked: Set<string> | null = null;\n for (const layer of scene.layers ?? []) {\n if (layer.locked === true) (locked ??= new Set()).add(layer.id);\n }\n if (locked === null) return null;\n const lockedLayers = locked;\n return (id) => {\n let cur = scene.get(asNodeId(id));\n const seen = new Set<string>();\n while (cur !== undefined && !seen.has(cur.id)) {\n if (lockedLayers.has(cur.layer)) return true;\n seen.add(cur.id);\n cur = cur.parent === null ? undefined : scene.get(cur.parent);\n }\n return false;\n };\n}\n\n/** Layer ids the scene reports as hidden. Only an explicit `false` hides a\n * layer: a partial scene stand-in that omits the flag stays pickable. */\nexport function hiddenLayerIds(\n layers: readonly { id: string; visible?: boolean }[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n for (const layer of layers ?? []) {\n if (layer.visible === false) out.add(layer.id);\n }\n return out;\n}\n\n/**\n * The two answers a pick needs from the view it is asked for rather than from\n * the data behind it: how that view paints a node, and whether it paints a\n * layer at all. A scene and a bare adapter take the same pair.\n */\nexport interface ViewPickGates {\n /** Painted alpha: the view's `alphaFor` times any per-node override alpha.\n * A node painted at alpha 0 cannot be hit. */\n alphaOf?: (id: string) => number;\n /** Whether a node's `layer` reaches the screen in the asking view. */\n layerIsPainted?: (layer: string) => boolean;\n}\n\n/** The gates a bare adapter takes from its view, plus how that view's camera\n * maps into each parallax layer — see `scenePlaneOf`. */\nexport interface AdapterPickGates extends ViewPickGates {\n planeOf?: (layer: string) => PlaneMap | null;\n}\n\nexport interface ScenePickSourceOptions<TPose> extends ViewPickGates {\n /** Pose lookup, when the caller holds an adapter that already resolves\n * overrides. Defaults to `effectivePose` against the scene's own. */\n getPose?: (id: string) => TPose;\n /** The asking view's composed alpha — `alphaFor(id)` times override alpha.\n * Defaults to the override alpha alone, which is all a bare scene knows. */\n alphaOf?: (id: string) => number;\n /** The asking view's answer to \"does this scene layer reach the screen\",\n * which is `layerVisibility` and `layerOrder` on top of the scene's own\n * `visible` flag. Consulted after the scene's flag, never instead of it. */\n layerIsPainted?: (layer: string) => boolean;\n /** How a child's stored pose folds into its parent's frame. Needed because\n * picking tests where a node is drawn, and under a composing strategy that\n * is not where its own pose says. Ignored when `getPose` already answers in\n * world coordinates. */\n poseComposition?: PoseComposition<TPose>;\n /** The asking view's camera. With it, a layer carrying `parallax` is picked\n * through its plane; without it, every layer is taken to move with the\n * camera. */\n camera?: View;\n}\n\nexport function scenePickSource<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n opts: ScenePickSourceOptions<TPose> = {},\n): PickSource<TPose> {\n const hidden = hiddenLayerIds(scene.layers);\n const locked = lockedNodeTest(scene as never);\n const { getPose, alphaOf, layerIsPainted } = opts;\n\n // Resolved once per walk rather than once per candidate: a scene with\n // nothing faded has nothing to say about alpha, and asking it per node is a\n // Map lookup on a linear scan that has no other reason to touch the\n // override table. Needs enumeration — a partial scene stand-in carrying\n // only `read` falls back to reading per node.\n let faded: Set<string> | null = null;\n const enumerable = typeof scene.overrides?.ids === 'function';\n if (!alphaOf && enumerable) {\n for (const id of scene.overrides.ids()) {\n const a = scene.overrides.read(id)?.alpha;\n if (a !== undefined && a <= 0) (faded ??= new Set()).add(id);\n }\n }\n const readAlpha = alphaOf\n ?? (enumerable\n ? (faded ? (id: string) => (faded.has(id) ? 0 : 1) : undefined)\n : (id: string) => scene.overrides.read(asNodeId(id))?.alpha ?? 1);\n\n // A composing strategy makes a node's own pose local, so picking has to fold\n // the parent chain the same way the render walk does or it tests where the\n // node is stored rather than where it is drawn.\n const composition = opts.poseComposition;\n const chain: PoseAdapter<TPose> | null =\n composition !== undefined && composition.closure !== 'identity'\n ? {\n getPose: (id: string) => {\n const n = scene.get(asNodeId(id));\n return n ? effectivePose(scene, n) : (undefined as unknown as TPose);\n },\n getParent: (id: string) => scene.get(asNodeId(id))?.parent ?? null,\n definesFrame: (id: string) => {\n const n = scene.get(asNodeId(id));\n return n === undefined || definesFrame(n);\n },\n }\n : null;\n\n const poseOf = getPose\n ? (node: PickCandidate<TPose>) => getPose(node.id)\n : chain\n ? (node: PickCandidate<TPose>) => composeWorldPose(chain, node.id, composition!.compose)\n : (node: PickCandidate<TPose>) => effectivePose(scene, node as never);\n\n // Through `poseOf`, not the document pose: a derived node has to be tested\n // where the renderer draws its dependencies, which is what an override says.\n const childrenOf = (id: NodeId): readonly NodeId[] => scene.childrenOf(id);\n const depOf = (id: NodeId): DerivedDep<TPose> | undefined => {\n const dep = scene.get(id);\n if (dep === undefined) return undefined;\n return {\n node: dep as Node<unknown, string, TPose>,\n pose: poseOf(dep as never),\n get path(): Path | null {\n return resolveDerivedPath(dep as never, depOf, childrenOf);\n },\n };\n };\n\n const derivedPathOf = (node: PickCandidate<TPose>): Path | null => {\n const n = node as unknown as Node<TData, TLayer, TPose>;\n if (n.dependsOn === undefined) return null;\n return resolveDerivedPath(n, depOf, childrenOf);\n };\n\n const planeOf = opts.camera ? scenePlaneOf(scene.layers, opts.camera) : null;\n\n return {\n ...(planeOf ? { planeOf } : {}),\n order: () => scene.renderOrderNodes() as unknown as readonly PickCandidate<TPose>[],\n derivedPathOf,\n poseOf,\n parentsOf(node) {\n let parentId = (node as { parent?: string | null }).parent ?? null;\n if (parentId === null) return EMPTY_PARENTS;\n const chain: PickCandidate<TPose>[] = [];\n const seen = new Set<string>();\n while (parentId !== null) {\n if (seen.has(parentId)) break;\n seen.add(parentId);\n const parent = scene.get(asNodeId(parentId));\n if (!parent) break;\n chain.push(parent as unknown as PickCandidate<TPose>);\n parentId = parent.parent ?? null;\n }\n return chain;\n },\n // Absent entirely when nothing is faded, so the walk skips the gate.\n ...(readAlpha ? { alphaOf: readAlpha } : {}),\n ...(locked ? { isLocked: (node: PickCandidate<TPose>) => locked(node.id) } : {}),\n ...(hidden.size > 0 || layerIsPainted\n ? {\n layerIsPainted: (layer: string) =>\n !hidden.has(layer) && (layerIsPainted === undefined || layerIsPainted(layer)),\n }\n : {}),\n };\n}\n\n/** Each parallax layer's plane map under `camera`, or null when no layer is a\n * plane — which keeps the per-layer lookup off the walk entirely. */\nexport function scenePlaneOf(\n layers: readonly { id: string; parallax?: ParallaxOpts }[] | undefined,\n camera: View,\n): ((layer: string) => PlaneMap | null) | null {\n let maps: Map<string, PlaneMap> | null = null;\n for (const l of layers ?? []) {\n if (l.parallax) (maps ??= new Map()).set(l.id, planeMap(camera, l.parallax));\n }\n if (maps === null) return null;\n const found = maps;\n return (layer) => found.get(layer) ?? null;\n}\n\n/** The adapter surface the walk can reach without a `Scene`. */\ninterface PickAdapter<TPose> {\n /** Composed world pose, when the adapter has a composition strategy.\n * Falls back to `getPose`, which is the same value under the\n * absolute-pose model. */\n getWorldPose?(id: string): TPose;\n getNodes(): readonly { id: string }[];\n getPose(id: string): TPose;\n getNode?: (id: string) => unknown;\n getChildren?: (parentId: string | null) => readonly string[];\n}\n\n/**\n * A source over a bare `SelectAdapter`, for consumers with no `Scene`.\n *\n * A hierarchical adapter is walked depth-first, parents before children —\n * the same back-to-front order `renderOrderNodes` produces for a single\n * layer. A flat adapter falls back to `getNodes()`, which carries no\n * parentage, so nothing clips.\n *\n * `gates` come from whichever view is picking, never from the adapter.\n */\nexport function adapterPickSource<TPose>(\n adapter: PickAdapter<TPose>,\n gates: AdapterPickGates = {},\n): PickSource<TPose> {\n const hier = adapter as Required<Pick<PickAdapter<TPose>, 'getNode' | 'getChildren'>>;\n const hierarchical =\n typeof adapter.getChildren === 'function' && typeof adapter.getNode === 'function';\n\n // Rebuilt per walk: the tree may have changed between queries, and a walk\n // is the only thing that reads it.\n let parents = new Map<string, PickCandidate<TPose>>();\n\n // The adapter composes if it has a strategy; `getPose` alone is the node's\n // own pose, which is not where a framed child is drawn.\n const worldPose = (id: string): TPose =>\n (typeof adapter.getWorldPose === 'function' ? adapter.getWorldPose(id) : adapter.getPose(id));\n\n const nodeOf = (id: string): PickCandidate<TPose> => {\n const raw = hier.getNode(id) as Partial<PickCandidate<TPose>>;\n return { ...raw, id, pose: worldPose(id) } as PickCandidate<TPose>;\n };\n\n return {\n order() {\n if (!hierarchical) {\n parents = new Map();\n return adapter.getNodes().map((n) => ({\n ...(n as object), id: n.id, pose: worldPose(n.id),\n })) as PickCandidate<TPose>[];\n }\n const out: PickCandidate<TPose>[] = [];\n const next = new Map<string, PickCandidate<TPose>>();\n const visit = (parentId: string | null, parent: PickCandidate<TPose> | null): void => {\n for (const childId of hier.getChildren(parentId)) {\n const node = nodeOf(childId);\n if (parent) next.set(childId, parent);\n out.push(node);\n visit(childId, node);\n }\n };\n visit(null, null);\n parents = next;\n return out;\n },\n ...(gates.alphaOf ? { alphaOf: gates.alphaOf } : {}),\n ...(gates.layerIsPainted ? { layerIsPainted: gates.layerIsPainted } : {}),\n ...(gates.planeOf ? { planeOf: gates.planeOf } : {}),\n poseOf: (node) => worldPose(node.id),\n parentsOf(node) {\n const chain: PickCandidate<TPose>[] = [];\n let cur = parents.get(node.id);\n const seen = new Set<string>();\n while (cur && !seen.has(cur.id)) {\n seen.add(cur.id);\n chain.push(cur);\n cur = parents.get(cur.id);\n }\n return chain;\n },\n };\n}\n"],"mappings":";;;;;;;;AAmCA,IAAMA,IAAkC,CAAC;AAoFzC,SAAgBC,EACd,GACA,GACA,GACa;CAGb,OAFIC,EAAK,SAAS,cACd,OAAOA,EAAK,gBAAiB,aAAmBA,EAAK,aAAaC,CAAI,IACnEC,EACLF,GACAC,GACA,EAAE,aAAaE,EAAQ,CACzB,IANsC;AAOxC;AAMA,SAAgBC,EACd,GACA,GACU;CACV,IAAMC,IAAoBC,EAAE,qBAAqB,IAC3CC,IAAWD,EAAE,kBAAkB,KAAO,KAAA,IAAYE,EAAI,UACtDC,IAAgB,CAAC,GAOjBC,oBAAW,IAAI,IAAyB,GAExCC,IAAQC,EAAYJ,EAAI,WAAW,IAAI,GAEvCK,KAAU,MAAgD;EAC9D,IAAMC,IAASJ,EAAS,IAAIK,EAAS,EAAE;EACvC,IAAID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CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"pickWalk.js","names":["EMPTY_PARENTS","ownClipOf","node","pose","findShapeSilhouette","derived","pickWalk","includeContainers","q","isLocked","src","out","clipPath","carry","clipCarrier","clipOf","cached","ancestor","resolved","planeQueries","queryFor","layer","found","map","query","clipped","clip","lockedNodeTest","locked","scene","lockedLayers","cur","asNodeId","id","seen","hiddenLayerIds","layers","scenePickSource","hidden","opts","faded","enumerable","alphaOf","a","readAlpha","composition","paintedPoseOf","scenePaintedPoseOf","poseOf","getPose","childrenOf","depOf","dep","resolveDerivedPath","sceneDerivedPath","sceneDerivedPathOf","derivedPathOf","planeOf","scenePlaneOf","parentId","chain","parent","layerIsPainted","maps","l","planeMap","camera","adapterPickSource","hier","adapter","hierarchical","parents","worldPose","nodeOf","n","next","visit","childId","gates"],"sources":["../../src/canvas/pickWalk.ts"],"sourcesContent":["/**\n * The one hit-test walk.\n *\n * Four walks used to answer this question — two point queries, two area\n * queries — over the same tree with the same gates. They drifted three times\n * without a failing test, because nothing held them to each other. Everything\n * that decides whether a node *can* be hit lives here now; a query supplies\n * only the shape test and the clip predicate for its own region.\n *\n * The gates, in the order the walk applies them:\n * 1. containers, when the query does not want them\n * 2. the layer is painted at all — scene visibility, and the asking view's\n * `layerVisibility` / `layerOrder`\n * 3. painted alpha is above zero\n * 4. the node is not locked, unless the query asks for locked nodes\n * 5. the query's own shape test\n * 6. every ancestor clip admits the query region\n *\n * 2, 3 and 6 are all \"the renderer did not put this on screen\". A pick path\n * that skips one answers for a node the user cannot see. 4 is the other axis:\n * a locked node is on screen and still out of reach.\n */\n\nimport type { Path } from '@weasel-js/geom';\nimport { findShapeSilhouette } from 'canvas/NodeShape';\nimport type { ClipFromPoseFn, DerivedDep, Node, NodeId, Scene } from 'core/scene/types';\nimport { asNodeId } from 'core/scene/types';\nimport { resolveDerivedPath, sceneDerivedPathOf, scenePaintedPoseOf } from './derivedPath';\nimport type { PoseComposition } from 'features/groups/composePose';\nimport { planeMap, type ParallaxOpts, type PlaneMap } from 'core/viewport/parallax';\nimport type { View } from 'core/viewport/view';\nimport { clipCarrier } from './planeClips';\n\n/** Shared, never mutated: most scenes are flat and every node returns it. */\nconst EMPTY_PARENTS: readonly never[] = [];\n\n/** The subset of a node the walk itself reads. Deliberately structural: a\n * bare adapter's node satisfies it as readily as a `SceneNode`. */\nexport interface PickCandidate<TPose> {\n id: string;\n kind?: string;\n layer?: string;\n pose: TPose;\n /** `false` makes the node transparent to the walk — see `SceneNode.pickable`. */\n pickable?: boolean;\n clipFromPose?: ClipFromPoseFn<TPose>;\n}\n\n/**\n * Everything the walk reads that a **view** owns.\n *\n * A layer must not hold state a view owns, so none of these are closed over\n * at construction — each is asked per walk, of the view being dispatched to.\n */\nexport interface PickSource<TPose> {\n /** Candidates in paint order, back-to-front. Containers included; the\n * query decides whether they can be hit. */\n order(): readonly PickCandidate<TPose>[];\n /** The pose the renderer draws — override-aware. Not `node.pose`, which is\n * how the render and pick paths came to disagree about where a node is. */\n poseOf(node: PickCandidate<TPose>): TPose;\n /** Ancestors, innermost first. Only walked for candidates that already\n * passed their own shape test. */\n parentsOf(node: PickCandidate<TPose>): readonly PickCandidate<TPose>[];\n /** Painted alpha for the asking view: the view's `alphaFor` times any\n * per-node override alpha. Omit when the source has no alpha concept. */\n alphaOf?(id: string): number;\n /** Whether this layer reaches the screen in the asking view. Omit for a\n * source with no layers. */\n layerIsPainted?(layer: string): boolean;\n /** Whether the node is locked — painted, but not something a pointer can\n * take. Omit for a source with no lock concept. */\n isLocked?(node: PickCandidate<TPose>): boolean;\n /** The path a node computes from its dependencies' poses, or null when it\n * derives nothing. Only a scene-backed source can answer — deriving needs\n * the dependencies' poses — so a bare adapter omits it, and every derived\n * node there keeps answering from its own (placeholder) pose. */\n derivedPathOf?(node: PickCandidate<TPose>): Path | null;\n /** How the asking view's world maps into a parallax layer's, or null for a\n * layer that moves with the camera. Omit for a source with no planes. */\n planeOf?(layer: string): PlaneMap | null;\n}\n\n/** One hit-test question: what region, and what counts as covering it. */\nexport interface PickQuery<TPose> {\n /** Default `true`. The area walks exclude containers so a marquee does not\n * return a container and its children both. */\n includeContainers?: boolean;\n /** Default `false`. Every selecting or editing query passes over locked\n * nodes; one that only samples what is painted can take them back. */\n includeLocked?: boolean;\n /** Does this node, drawn at this pose, cover the query region? `derived`\n * is the node's resolved path when it has one — a derived node's pose is a\n * placeholder, so a region test that reads only the pose answers for the\n * wrong box. */\n hits(node: PickCandidate<TPose>, pose: TPose, derived?: Path | null): boolean;\n /**\n * Does an ancestor's clip leave anything of `node` for this query to hit?\n *\n * A point query asks point-in-clip and ignores the node. An area query has\n * to ask about the node as well: the clip and the area can overlap where\n * the node is not, and the node and the clip can overlap where the area is\n * not, and only the two terms together reject both.\n */\n clipAdmits(\n clip: Path,\n node: PickCandidate<TPose>,\n pose: TPose,\n derived?: Path | null,\n ): boolean;\n /** The same question asked in a parallax plane's world: the region carried\n * through `map`, and any screen-pixel slop re-derived at the plane's scale.\n * A query without it cannot reach nodes on a plane — it would test them\n * where their poses sit rather than where they are painted. */\n inPlane?(map: PlaneMap): PickQuery<TPose>;\n}\n\n/** The clip a container imposes on its subtree, or null when it imposes none. */\nexport function ownClipOf<TPose>(\n node: PickCandidate<TPose>,\n pose: TPose,\n derived?: Path | null,\n): Path | null {\n if (node.kind !== 'container') return null;\n if (typeof node.clipFromPose === 'function') return node.clipFromPose(pose);\n return findShapeSilhouette(\n node as unknown as Node<unknown, string, TPose>,\n pose,\n { derivedPath: derived },\n );\n}\n\n/**\n * Collect every candidate the query hits, back-to-front — the last element is\n * the topmost, which is the order `pickTopMostHit` expects.\n */\nexport function pickWalk<TPose>(\n src: PickSource<TPose>,\n q: PickQuery<TPose>,\n): string[] {\n const includeContainers = q.includeContainers ?? true;\n const isLocked = q.includeLocked === true ? undefined : src.isLocked;\n const out: string[] = [];\n\n // Resolving a container's clip means `clipFromPose` or a silhouette build,\n // which is the expensive half; the predicate against it is cheap. So the\n // *path* is memoized per container for the walk and the predicate re-runs\n // per candidate — `clipAdmits` needs the candidate, and caching its answer\n // per container would answer the wrong question for an area query.\n const clipPath = new Map<string, Path | null>();\n // A clip is in its container's plane; the query is in the candidate's.\n const carry = clipCarrier(src.planeOf ?? null);\n\n const clipOf = (ancestor: PickCandidate<TPose>): Path | null => {\n const cached = clipPath.get(ancestor.id);\n if (cached !== undefined) return cached;\n const resolved = ownClipOf(\n ancestor, src.poseOf(ancestor), src.derivedPathOf?.(ancestor),\n );\n clipPath.set(ancestor.id, resolved);\n return resolved;\n };\n\n // One reprojected query per plane per walk; `null` marks a plane this\n // query cannot reach.\n const planeQueries = new Map<string, PickQuery<TPose> | null>();\n const queryFor = (layer: string | undefined): PickQuery<TPose> | null => {\n if (layer === undefined || src.planeOf === undefined) return q;\n let found = planeQueries.get(layer);\n if (found === undefined) {\n const map = src.planeOf(layer);\n found = map === null ? q : (q.inPlane?.(map) ?? null);\n planeQueries.set(layer, found);\n }\n return found;\n };\n\n for (const node of src.order()) {\n if (!includeContainers && node.kind === 'container') continue;\n // Transparent to picking: the click belongs to whatever is behind it,\n // which for a label inside a box is the box.\n if (node.pickable === false) continue;\n if (node.layer !== undefined && src.layerIsPainted?.(node.layer) === false) continue;\n if (src.alphaOf !== undefined && src.alphaOf(node.id) <= 0) continue;\n if (isLocked !== undefined && isLocked(node)) continue;\n\n const query = queryFor(node.layer);\n if (query === null) continue;\n const pose = src.poseOf(node);\n const derived = src.derivedPathOf?.(node);\n if (!query.hits(node, pose, derived)) continue;\n\n let clipped = false;\n for (const ancestor of src.parentsOf(node)) {\n const clip = clipOf(ancestor);\n if (clip === null) continue;\n if (!query.clipAdmits(carry(clip, ancestor.layer, node.layer), node, pose, derived)) {\n clipped = true;\n break;\n }\n }\n if (clipped) continue;\n\n out.push(node.id);\n }\n\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// Sources\n// ---------------------------------------------------------------------------\n\n/** Answers `Scene.isLocked` from the layer records and parent links alone,\n * so a partial scene stand-in works too. Null when nothing is locked, which\n * is what keeps the gate off the walk in the common case. */\nfunction lockedNodeTest(\n scene: Pick<Scene<unknown, string, unknown>, 'layers' | 'get'>,\n): ((id: string) => boolean) | null {\n let locked: Set<string> | null = null;\n for (const layer of scene.layers ?? []) {\n if (layer.locked === true) (locked ??= new Set()).add(layer.id);\n }\n if (locked === null) return null;\n const lockedLayers = locked;\n return (id) => {\n let cur = scene.get(asNodeId(id));\n const seen = new Set<string>();\n while (cur !== undefined && !seen.has(cur.id)) {\n if (lockedLayers.has(cur.layer)) return true;\n seen.add(cur.id);\n cur = cur.parent === null ? undefined : scene.get(cur.parent);\n }\n return false;\n };\n}\n\n/** Layer ids the scene reports as hidden. Only an explicit `false` hides a\n * layer: a partial scene stand-in that omits the flag stays pickable. */\nexport function hiddenLayerIds(\n layers: readonly { id: string; visible?: boolean }[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n for (const layer of layers ?? []) {\n if (layer.visible === false) out.add(layer.id);\n }\n return out;\n}\n\n/**\n * The two answers a pick needs from the view it is asked for rather than from\n * the data behind it: how that view paints a node, and whether it paints a\n * layer at all. A scene and a bare adapter take the same pair.\n */\nexport interface ViewPickGates {\n /** Painted alpha: the view's `alphaFor` times any per-node override alpha.\n * A node painted at alpha 0 cannot be hit. */\n alphaOf?: (id: string) => number;\n /** Whether a node's `layer` reaches the screen in the asking view. */\n layerIsPainted?: (layer: string) => boolean;\n}\n\n/** The gates a bare adapter takes from its view, plus how that view's camera\n * maps into each parallax layer — see `scenePlaneOf`. */\nexport interface AdapterPickGates extends ViewPickGates {\n planeOf?: (layer: string) => PlaneMap | null;\n}\n\nexport interface ScenePickSourceOptions<TPose> extends ViewPickGates {\n /** Pose lookup, when the caller holds an adapter that already resolves\n * overrides. Defaults to `effectivePose` against the scene's own. */\n getPose?: (id: string) => TPose;\n /** The asking view's composed alpha — `alphaFor(id)` times override alpha.\n * Defaults to the override alpha alone, which is all a bare scene knows. */\n alphaOf?: (id: string) => number;\n /** The asking view's answer to \"does this scene layer reach the screen\",\n * which is `layerVisibility` and `layerOrder` on top of the scene's own\n * `visible` flag. Consulted after the scene's flag, never instead of it. */\n layerIsPainted?: (layer: string) => boolean;\n /** How a child's stored pose folds into its parent's frame. Needed because\n * picking tests where a node is drawn, and under a composing strategy that\n * is not where its own pose says. Ignored when `getPose` already answers in\n * world coordinates. */\n poseComposition?: PoseComposition<TPose>;\n /** The asking view's camera. With it, a layer carrying `parallax` is picked\n * through its plane; without it, every layer is taken to move with the\n * camera. */\n camera?: View;\n}\n\nexport function scenePickSource<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n opts: ScenePickSourceOptions<TPose> = {},\n): PickSource<TPose> {\n const hidden = hiddenLayerIds(scene.layers);\n const locked = lockedNodeTest(scene as never);\n const { getPose, alphaOf, layerIsPainted } = opts;\n\n // Resolved once per walk rather than once per candidate: a scene with\n // nothing faded has nothing to say about alpha, and asking it per node is a\n // Map lookup on a linear scan that has no other reason to touch the\n // override table. Needs enumeration — a partial scene stand-in carrying\n // only `read` falls back to reading per node.\n let faded: Set<string> | null = null;\n const enumerable = typeof scene.overrides?.ids === 'function';\n if (!alphaOf && enumerable) {\n for (const id of scene.overrides.ids()) {\n const a = scene.overrides.read(id)?.alpha;\n if (a !== undefined && a <= 0) (faded ??= new Set()).add(id);\n }\n }\n const readAlpha = alphaOf\n ?? (enumerable\n ? (faded ? (id: string) => (faded.has(id) ? 0 : 1) : undefined)\n : (id: string) => scene.overrides.read(asNodeId(id))?.alpha ?? 1);\n\n // A composing strategy makes a node's own pose local, so picking folds the\n // parent chain the same way the render walk does: one definition of both.\n const composition = opts.poseComposition;\n const paintedPoseOf = scenePaintedPoseOf(scene, undefined, composition);\n const poseOf = getPose\n ? (node: PickCandidate<TPose>) => getPose(node.id)\n : (node: PickCandidate<TPose>) => paintedPoseOf(node as never);\n\n // Through `poseOf`, not the document pose: a derived node has to be tested\n // where the renderer draws its dependencies, which is what an override says.\n const childrenOf = (id: NodeId): readonly NodeId[] => scene.childrenOf(id);\n const depOf = (id: NodeId): DerivedDep<TPose> | undefined => {\n const dep = scene.get(id);\n if (dep === undefined) return undefined;\n return {\n node: dep as Node<unknown, string, TPose>,\n pose: poseOf(dep as never),\n get path(): Path | null {\n return resolveDerivedPath(dep as never, depOf, childrenOf);\n },\n };\n };\n\n const sceneDerivedPath = getPose ? null : sceneDerivedPathOf(scene, undefined, composition);\n const derivedPathOf = (node: PickCandidate<TPose>): Path | null => {\n const n = node as unknown as Node<TData, TLayer, TPose>;\n if (n.dependsOn === undefined) return null;\n return sceneDerivedPath ? sceneDerivedPath(n) : resolveDerivedPath(n, depOf, childrenOf);\n };\n\n const planeOf = opts.camera ? scenePlaneOf(scene.layers, opts.camera) : null;\n\n return {\n ...(planeOf ? { planeOf } : {}),\n order: () => scene.renderOrderNodes() as unknown as readonly PickCandidate<TPose>[],\n derivedPathOf,\n poseOf,\n parentsOf(node) {\n let parentId = (node as { parent?: string | null }).parent ?? null;\n if (parentId === null) return EMPTY_PARENTS;\n const chain: PickCandidate<TPose>[] = [];\n const seen = new Set<string>();\n while (parentId !== null) {\n if (seen.has(parentId)) break;\n seen.add(parentId);\n const parent = scene.get(asNodeId(parentId));\n if (!parent) break;\n chain.push(parent as unknown as PickCandidate<TPose>);\n parentId = parent.parent ?? null;\n }\n return chain;\n },\n // Absent entirely when nothing is faded, so the walk skips the gate.\n ...(readAlpha ? { alphaOf: readAlpha } : {}),\n ...(locked ? { isLocked: (node: PickCandidate<TPose>) => locked(node.id) } : {}),\n ...(hidden.size > 0 || layerIsPainted\n ? {\n layerIsPainted: (layer: string) =>\n !hidden.has(layer) && (layerIsPainted === undefined || layerIsPainted(layer)),\n }\n : {}),\n };\n}\n\n/** Each parallax layer's plane map under `camera`, or null when no layer is a\n * plane — which keeps the per-layer lookup off the walk entirely. */\nexport function scenePlaneOf(\n layers: readonly { id: string; parallax?: ParallaxOpts }[] | undefined,\n camera: View,\n): ((layer: string) => PlaneMap | null) | null {\n let maps: Map<string, PlaneMap> | null = null;\n for (const l of layers ?? []) {\n if (l.parallax) (maps ??= new Map()).set(l.id, planeMap(camera, l.parallax));\n }\n if (maps === null) return null;\n const found = maps;\n return (layer) => found.get(layer) ?? null;\n}\n\n/** The adapter surface the walk can reach without a `Scene`. */\ninterface PickAdapter<TPose> {\n /** Composed world pose, when the adapter has a composition strategy.\n * Falls back to `getPose`, which is the same value under the\n * absolute-pose model. */\n getWorldPose?(id: string): TPose;\n getNodes(): readonly { id: string }[];\n getPose(id: string): TPose;\n getNode?: (id: string) => unknown;\n getChildren?: (parentId: string | null) => readonly string[];\n}\n\n/**\n * A source over a bare `SelectAdapter`, for consumers with no `Scene`.\n *\n * A hierarchical adapter is walked depth-first, parents before children —\n * the same back-to-front order `renderOrderNodes` produces for a single\n * layer. A flat adapter falls back to `getNodes()`, which carries no\n * parentage, so nothing clips.\n *\n * `gates` come from whichever view is picking, never from the adapter.\n */\nexport function adapterPickSource<TPose>(\n adapter: PickAdapter<TPose>,\n gates: AdapterPickGates = {},\n): PickSource<TPose> {\n const hier = adapter as Required<Pick<PickAdapter<TPose>, 'getNode' | 'getChildren'>>;\n const hierarchical =\n typeof adapter.getChildren === 'function' && typeof adapter.getNode === 'function';\n\n // Rebuilt per walk: the tree may have changed between queries, and a walk\n // is the only thing that reads it.\n let parents = new Map<string, PickCandidate<TPose>>();\n\n // The adapter composes if it has a strategy; `getPose` alone is the node's\n // own pose, which is not where a framed child is drawn.\n const worldPose = (id: string): TPose =>\n (typeof adapter.getWorldPose === 'function' ? adapter.getWorldPose(id) : adapter.getPose(id));\n\n const nodeOf = (id: string): PickCandidate<TPose> => {\n const raw = hier.getNode(id) as Partial<PickCandidate<TPose>>;\n return { ...raw, id, pose: worldPose(id) } as PickCandidate<TPose>;\n };\n\n return {\n order() {\n if (!hierarchical) {\n parents = new Map();\n return adapter.getNodes().map((n) => ({\n ...(n as object), id: n.id, pose: worldPose(n.id),\n })) as PickCandidate<TPose>[];\n }\n const out: PickCandidate<TPose>[] = [];\n const next = new Map<string, PickCandidate<TPose>>();\n const visit = (parentId: string | null, parent: PickCandidate<TPose> | null): void => {\n for (const childId of hier.getChildren(parentId)) {\n const node = nodeOf(childId);\n if (parent) next.set(childId, parent);\n out.push(node);\n visit(childId, node);\n }\n };\n visit(null, null);\n parents = next;\n return out;\n },\n ...(gates.alphaOf ? { alphaOf: gates.alphaOf } : {}),\n ...(gates.layerIsPainted ? { layerIsPainted: gates.layerIsPainted } : {}),\n ...(gates.planeOf ? { planeOf: gates.planeOf } : {}),\n poseOf: (node) => worldPose(node.id),\n parentsOf(node) {\n const chain: PickCandidate<TPose>[] = [];\n let cur = parents.get(node.id);\n const seen = new Set<string>();\n while (cur && !seen.has(cur.id)) {\n seen.add(cur.id);\n chain.push(cur);\n cur = parents.get(cur.id);\n }\n return chain;\n },\n };\n}\n"],"mappings":";;;;;;;AAkCA,IAAMA,IAAkC,CAAC;AAoFzC,SAAgBC,EACd,GACA,GACA,GACa;CAGb,OAFIC,EAAK,SAAS,cACd,OAAOA,EAAK,gBAAiB,aAAmBA,EAAK,aAAaC,CAAI,IACnEC,EACLF,GACAC,GACA,EAAE,aAAaE,EAAQ,CACzB,IANsC;AAOxC;AAMA,SAAgBC,EACd,GACA,GACU;CACV,IAAMC,IAAoBC,EAAE,qBAAqB,IAC3CC,IAAWD,EAAE,kBAAkB,KAAO,KAAA,IAAYE,EAAI,UACtDC,IAAgB,CAAC,GAOjBC,oBAAW,IAAI,IAAyB,GAExCC,IAAQC,EAAYJ,EAAI,WAAW,IAAI,GAEvCK,KAAU,MAAgD;EAC9D,IAAMC,IAASJ,EAAS,IAAIK,EAAS,EAAE;EACvC,IAAID,MAAW,KAAA,GAAW,OAAOA;EACjC,IAAME,IAAWjB,EACfgB,GAAUP,EAAI,OAAOO,CAAQ,GAAGP,EAAI,gBAAgBO,CAAQ,CAC9D;EAEA,OADAL,EAAS,IAAIK,EAAS,IAAIC,CAAQ,GAC3BA;CACT,GAIMC,oBAAe,IAAI,I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ChD,IAAMzD,IAAOuE,EAAOI,CAAO;KAG3B,AAFIhB,KAAQc,EAAK,IAAIE,GAAShB,CAAM,GACpClD,EAAI,KAAKT,CAAI,GACb0E,EAAMC,GAAS3E,CAAI;IACrB;GACF;GAGA,OAFA0E,EAAM,MAAM,IAAI,GAChB,IAAUD,GACHhE;EACT;EACA,GAAImE,EAAM,UAAU,EAAE,SAASA,EAAM,QAAQ,IAAI,CAAC;EAClD,GAAIA,EAAM,iBAAiB,EAAE,gBAAgBA,EAAM,eAAe,IAAI,CAAC;EACvE,GAAIA,EAAM,UAAU,EAAE,SAASA,EAAM,QAAQ,IAAI,CAAC;EAClD,SAAS,MAASN,EAAUtE,EAAK,EAAE;EACnC,UAAU,GAAM;GACd,IAAM0D,IAAgC,CAAC,GACnC7B,IAAMwC,EAAQ,IAAIrE,EAAK,EAAE,GACvBgC,oBAAO,IAAI,IAAY;GAC7B,OAAOH,KAAO,CAACG,EAAK,IAAIH,EAAI,EAAE,IAG5B,AAFAG,EAAK,IAAIH,EAAI,EAAE,GACf6B,EAAM,KAAK7B,CAAG,GACd,IAAMwC,EAAQ,IAAIxC,EAAI,EAAE;GAE1B,OAAO6B;EACT;CACF;AACF"}
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mat3 as e } from "../renderer/math/mat3.js";
|
|
2
|
+
import { poseFrameOf as t } from "../core/geometry/poseFrame.js";
|
|
3
|
+
import { rotateAboutPoint as n } from "@weasel-js/geom";
|
|
3
4
|
//#region src/canvas/poseRotation.ts
|
|
4
|
-
function
|
|
5
|
-
return
|
|
6
|
-
e[0],
|
|
7
|
-
e[1],
|
|
8
|
-
0,
|
|
9
|
-
e[2],
|
|
10
|
-
e[3],
|
|
11
|
-
0,
|
|
12
|
-
e[4],
|
|
13
|
-
e[5],
|
|
14
|
-
1
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
function r(e, r, i) {
|
|
18
|
-
return n(t(e, r, i));
|
|
5
|
+
function r(t, r, i) {
|
|
6
|
+
return e.fromAffine(n(t, r, i));
|
|
19
7
|
}
|
|
20
8
|
function i(e, t, n, i, a) {
|
|
21
9
|
return r(e + n / 2, t + i / 2, a);
|
|
22
10
|
}
|
|
23
|
-
function a(
|
|
24
|
-
if (
|
|
25
|
-
let i =
|
|
11
|
+
function a(n, r) {
|
|
12
|
+
if (n.length === 0) return n;
|
|
13
|
+
let i = t(r);
|
|
26
14
|
return i ? [{
|
|
27
15
|
kind: "group",
|
|
28
|
-
transform:
|
|
29
|
-
children:
|
|
30
|
-
}] :
|
|
16
|
+
transform: e.fromAffine(i),
|
|
17
|
+
children: n
|
|
18
|
+
}] : n;
|
|
31
19
|
}
|
|
32
20
|
//#endregion
|
|
33
21
|
export { i as rotateAroundAABBCenter, r as rotationMatrixAbout, a as wrapWithPoseRotation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poseRotation.js","names":["
|
|
1
|
+
{"version":3,"file":"poseRotation.js","names":["rotationMatrixAbout","mat3","rotateAboutPoint","cx","cy","rotation","rotateAroundAABBCenter","x","width","y","height","wrapWithPoseRotation","cmds","frame","poseFrameOf","pose"],"sources":["../../src/canvas/poseRotation.ts"],"sourcesContent":["/**\n * Pose rotation helpers — extracted from `SceneCanvas` so the kit can apply\n * the auto-rotation wrap around EVERY per-node `drawOne` (consumer-supplied\n * or default), not only around the default painter's output.\n *\n * Without this, consumers who supply a custom `drawOne` get no rotation\n * visualization even though selection chrome (which reads `pose.rotation`\n * directly) does rotate — the rect sits still while its chrome spins.\n *\n * `wrapWithPoseRotation` is applied by `wrapNodeOutput` in both scene walks —\n * `buildSceneLayer` (main canvas) and `buildSceneViewCommands` (detached\n * renders) — and directly by `usePreviewGhostLayer.buildSubtree` (in-flight\n * preview), so every code path produces rotated geometry uniformly.\n */\nimport type { DrawCommand } from '../renderer';\nimport { poseFrameOf } from 'core/geometry/poseFrame';\nimport { rotateAboutPoint } from '@weasel-js/geom';\nimport { mat3, type GlMat3 } from '../renderer/math/mat3';\n\n/** Rotation by `rotation` about `(cx, cy)` as the render-tree's column-major\n * 3×3 affine. Composes on the kernel's `rotateAboutPoint` (single owner of the\n * rotate-about-point math); this only reshapes 6→9 for the WebGL upload. */\nexport function rotationMatrixAbout(cx: number, cy: number, rotation: number): GlMat3 {\n return mat3.fromAffine(rotateAboutPoint(cx, cy, rotation));\n}\n\n/** Rotation matrix about the AABB center of `(x, y, width, height)`. The pivot\n * matches `poseRotationOf` (the shared rotation convention). */\nexport function rotateAroundAABBCenter(\n x: number, y: number, width: number, height: number, rotation: number,\n): GlMat3 {\n return rotationMatrixAbout(x + width / 2, y + height / 2, rotation);\n}\n\n/** Wrap a per-node draw-command list in a group carrying the pose's frame\n * (`poseFrameOf`): its `rotation`, its `transform`, or both, about the AABB\n * center, matching the rotation-handle math, `pathInWorld`, and picking so\n * chrome and geometry stay aligned.\n *\n * No-ops when `cmds` is empty, when the pose has neither field, or when any\n * of the AABB fields are missing (the wrap requires a center to turn about).\n * Painters / consumers that need different semantics (e.g. pivot at origin)\n * should still wrap themselves. */\nexport function wrapWithPoseRotation(\n cmds: DrawCommand[],\n pose: unknown,\n): DrawCommand[] {\n if (cmds.length === 0) return cmds;\n const frame = poseFrameOf(pose);\n if (!frame) return cmds;\n return [{ kind: 'group', transform: mat3.fromAffine(frame), children: cmds }];\n}\n"],"mappings":";;;;AAsBA,SAAgBA,EAAoB,GAAY,GAAY,GAA0B;CACpF,OAAOC,EAAK,WAAWC,EAAiBC,GAAIC,GAAIC,CAAQ,CAAC;AAC3D;AAIA,SAAgBC,EACd,GAAW,GAAW,GAAe,GAAgB,GAC7C;CACR,OAAON,EAAoBO,IAAIC,IAAQ,GAAGC,IAAIC,IAAS,GAAGL,CAAQ;AACpE;AAWA,SAAgBM,EACd,GACA,GACe;CACf,IAAIC,EAAK,WAAW,GAAG,OAAOA;CAC9B,IAAMC,IAAQC,EAAYC,CAAI;CAE9B,OADKF,IACE,CAAC;EAAE,MAAM;EAAS,WAAWZ,EAAK,WAAWY,CAAK;EAAG,UAAUD;CAAK,CAAC,IADzDA;AAErB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { mat3 as e } from "../renderer/math/mat3.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { renderSceneToPixels as t } from "./renderSceneToPixels.js";
|
|
3
|
+
import { buildDebugOverlayCommands as n } from "../debug/createDebugOverlayLayer.js";
|
|
4
4
|
//#region src/canvas/renderDebugSnapshot.ts
|
|
5
5
|
function r(e) {
|
|
6
|
-
return
|
|
6
|
+
return t(i(e));
|
|
7
7
|
}
|
|
8
|
-
function i(
|
|
9
|
-
let { view: r, size: i, debug: a, config: o, pixelRatio: s = 1, ...c } =
|
|
8
|
+
function i(t) {
|
|
9
|
+
let { view: r, size: i, debug: a, config: o, pixelRatio: s = 1, ...c } = t, l = n(a, o, r, i);
|
|
10
10
|
return {
|
|
11
11
|
...c,
|
|
12
12
|
sourceRect: {
|
|
@@ -76,6 +76,8 @@ function f(e = {}) {
|
|
|
76
76
|
stencil: !0
|
|
77
77
|
}) ?? void 0)), !i || typeof i.enable != "function") throw Error("raster session: WebGL2 is unavailable — supply `gl` or a WebGL2-capable `createCanvas`");
|
|
78
78
|
if (p(i)) throw Error("raster session: the WebGL2 context is lost — dispose this session and open another");
|
|
79
|
+
let { drawingBufferWidth: a, drawingBufferHeight: o } = i;
|
|
80
|
+
if (a < n || o < r) throw Error(`raster session: a ${n} × ${r} render does not fit the context's ${a} × ${o} drawing buffer — lower \`scale\` or render the source rect in tiles`);
|
|
79
81
|
return i;
|
|
80
82
|
}
|
|
81
83
|
return {
|
|
@@ -105,7 +107,7 @@ function f(e = {}) {
|
|
|
105
107
|
};
|
|
106
108
|
},
|
|
107
109
|
dispose() {
|
|
108
|
-
o || (o = !0, a?.dispose(), a = null, t = null, i = void 0);
|
|
110
|
+
o || (o = !0, a?.dispose(), a = null, t && !e.createCanvas && i?.getExtension("WEBGL_lose_context")?.loseContext(), t = null, i = void 0);
|
|
109
111
|
}
|
|
110
112
|
};
|
|
111
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderSceneToPixels.js","names":["planPixelRender","args","label","v","sourceRect","scale","width","height","view","resolveImage","drawOne","defaultDrawOne","node","pose","ctx","commands","buildSceneViewCommands","defaultCreateCanvas","c","flipRows","rowBytes","out","raw","y","unpremultiply","i","data","a","inv","createRasterSession","options","canvas","gl","renderer","disposed","contextFor","isLost","plan","flattenTolerance","WeaselRenderer","viewToMat3","warmRender","opts","planned","err","needs","renderNeeds","isPaintKindKnown","warmFonts","families","warmPaintKinds","paintKinds","renderSceneToPixels","renderArgs","session"],"sources":["../../src/canvas/renderSceneToPixels.ts"],"sourcesContent":["/**\n * `renderSceneToPixels` — headless rasterization of a scene-space rect to\n * raw RGBA pixels at an explicit, per-axis scale.\n *\n * One renderer, two callers: this path drives the same WebGL2 pipeline\n * (`WeaselRenderer` + `buildSceneViewCommands`) as the on-screen view — it is\n * NOT a second renderer. Print, thumbnail, and export callers get the same\n * pixels the screen would produce at that scale.\n *\n * Environment contract:\n * - Density arrives exclusively via `scale` (output pixels per scene unit,\n * per axis — anisotropic values are first-class). This function never\n * reads `window.devicePixelRatio`.\n * - Rounding policy: output width = max(1, round(sourceRect.width × scale.x)),\n * height analogously. The scene-space rect is authoritative; the pixel\n * grid derives from it. When round() lands below rect × scale, the\n * rightmost/bottom sub-pixel band of scene content is cropped; when it\n * rounds up, that band is instead padded (the `background` fill, or\n * transparent, covers the pad).\n * - Context lifetime: each call opens a `RasterSession` — one\n * `WeaselRenderer` — and disposes it before returning, freeing every GL\n * object it created, caches included. Rendering in bulk, open one session\n * with `createRasterSession` and render through it: programs compile once\n * and bitmaps upload once for the whole batch, and `dispose()` frees them.\n * With a caller-supplied `gl`, the context itself is caller-owned: it is\n * never disposed here, and its drawing buffer must be at least\n * width × height pixels (the render targets the bottom-left region).\n * Auto-created canvases (`OffscreenCanvas` when available, else a detached\n * DOM canvas) are discarded with the session; a session grows its own\n * canvas to the largest render so far.\n * - Context loss: throws — a lost context cannot produce pixels, and the\n * silent-noop convention of the screen path would return all-zero bytes.\n * - Output: top-down row order, NON-premultiplied (\"straight\") RGBA. The GL\n * framebuffer is premultiplied (blendFunc ONE, ONE_MINUS_SRC_ALPHA) and\n * bottom-up; readback flips and unpremultiplies. Over an opaque\n * `background` both transforms are visually moot but still applied.\n * - Determinism: same context + same inputs → same bytes. Cross-driver /\n * cross-machine byte equality is NOT guaranteed (GL rasterization varies);\n * do not build golden-image tests on committed bytes.\n * - Image quality: image textures upload with mipmaps\n * (`imageMinification: 'mipmap'`) so minified bitmaps don't moiré, and\n * curve tessellation runs at an output-scale tolerance\n * (`flattenTolerancePx`, default 0.25 output px). A bitmap node's source\n * pixels are sampled exactly once, directly to the output grid.\n */\nimport { WeaselRenderer } from '../renderer/WeaselRenderer';\nimport { viewToMat3 } from '../renderer/math/viewToMat3';\nimport type { DrawCommand } from '../renderer/DrawCommand';\nimport type { View } from '../core/viewport/view';\nimport type { Node, Scene } from 'core/scene/types';\nimport { buildSceneViewCommands, type SceneViewDrawOne } from './sceneViewRender';\nimport type { ColorOverrideRegistry } from '../animation/colorRegistry';\nimport { defaultDrawOne } from './defaultDrawOne';\nimport { warmFonts, type FontRequest } from '@weasel-js/font';\nimport { isPaintKindKnown, warmPaintKinds } from '../core/paintKinds';\nimport { renderNeeds } from './renderNeeds';\n\n/** Plain RGBA raster — structurally `ImageData`-compatible ({ width, height,\n * data }), deliberately free of printer/dpi/physical-unit concepts. */\nexport interface RasterImage {\n width: number;\n height: number;\n /** Top-down, straight (non-premultiplied) RGBA, 4 bytes per pixel. */\n data: Uint8ClampedArray;\n}\n\n/** Minimal canvas contract for `createCanvas` injection: `OffscreenCanvas`,\n * an HTML canvas, or a test fake. */\nexport interface HeadlessCanvasLike {\n width: number;\n height: number;\n getContext(contextId: 'webgl2', options?: WebGLContextAttributes): unknown;\n}\n\n/** What to render, at what resolution, and with which quality settings. */\nexport interface RenderSceneToPixelsArgs<TData, TLayer extends string, TPose> {\n scene: Scene<TData, TLayer, TPose>;\n /** Scene-space rect to render (origin + size in scene units). Output pixel\n * dimensions follow from rect × scale (round, min 1 — see module doc). */\n sourceRect: { x: number; y: number; width: number; height: number };\n /** Output pixels per scene unit, per axis. Anisotropic values supported. */\n scale: { x: number; y: number };\n /** Per-node draw callback. Default: `defaultDrawOne` with `resolveImage`\n * merged into the `NodePaintCtx` the scene walk supplies. Custom `drawOne`\n * callers that still want resolver injection should call\n * `defaultDrawOne(node, pose, view, { ...ctx, resolveImage })` themselves —\n * dropping the walk's `ctx` drops derived geometry with it. */\n drawOne?: SceneViewDrawOne<TData, TLayer, TPose>;\n /** Bitmap resolver for image nodes — lets consumers reuse their own decode\n * caches. `undefined` results paint the deterministic grey placeholder\n * outline (see `NodePaintCtx.resolveImage`). */\n resolveImage?: (node: Node<TData, TLayer, TPose>) => ImageBitmap | undefined;\n /** Per-id alpha multiplier, mirroring `<SceneCanvas>`'s scene-slot\n * `alphaFor`. Pass the same function the on-screen canvas uses so an\n * export matches what the user is looking at. Defaults to `() => 1`. */\n alphaFor?: (id: string) => number;\n /** Animated vertex colors to paint, typically an animator's\n * `colorOverrides`, so an export shows the frame on screen. */\n colorOverrides?: ColorOverrideRegistry;\n /** Background fill (any CSS color accepted by the renderer). Default:\n * fully transparent. Passing a color is always valid. */\n background?: string;\n /** Caller-owned WebGL2 context to render with. Mutually exclusive with\n * `createCanvas`. Never disposed by this call. */\n gl?: WebGL2RenderingContext;\n /** One-shot canvas factory (DOM canvas, OffscreenCanvas, or test fake).\n * Mutually exclusive with `gl`. Default: `OffscreenCanvas` when\n * available, else `document.createElement('canvas')`. */\n createCanvas?: (widthPx: number, heightPx: number) => HeadlessCanvasLike;\n /** Max curve-flattening error in OUTPUT pixels. Default 0.25. Converted to\n * world units against the larger scale axis and passed to the renderer's\n * `flattenTolerance`. Explicitly passing 0.25 is always valid. */\n flattenTolerancePx?: number;\n /** Commands drawn over the scene in output-pixel space — origin at the\n * output's top-left, one unit per output pixel. Annotations, watermarks,\n * and `renderDebugSnapshot`'s overlay ride here. */\n overlay?: readonly DrawCommand[];\n}\n\n/** The result of planning a headless render: how big the output is, the view\n * that maps the source rect onto it, and the commands to draw. */\nexport interface PixelRenderPlan {\n width: number;\n height: number;\n view: View;\n commands: DrawCommand[];\n}\n\n/** Pure planning half of `renderSceneToPixels`: output dimensions, the\n * anisotropic `View`, and the full command list (background + view-wrapped\n * scene). Exported for tests and for callers targeting their own renderer. */\nexport function planPixelRender<TData, TLayer extends string, TPose>(\n args: Omit<RenderSceneToPixelsArgs<TData, TLayer, TPose>, 'gl' | 'createCanvas' | 'flattenTolerancePx'>,\n): PixelRenderPlan {\n const { sourceRect, scale } = args;\n for (const [label, v] of [\n ['sourceRect.width', sourceRect.width], ['sourceRect.height', sourceRect.height],\n ['scale.x', scale.x], ['scale.y', scale.y],\n ] as const) {\n if (!Number.isFinite(v) || v <= 0) {\n throw new Error(`renderSceneToPixels: ${label} must be a positive finite number, got ${v}`);\n }\n }\n for (const [label, v] of [\n ['sourceRect.x', sourceRect.x], ['sourceRect.y', sourceRect.y],\n ] as const) {\n if (!Number.isFinite(v)) {\n throw new Error(`renderSceneToPixels: ${label} must be a finite number, got ${v}`);\n }\n }\n const width = Math.max(1, Math.round(sourceRect.width * scale.x));\n const height = Math.max(1, Math.round(sourceRect.height * scale.y));\n const view: View = { x: sourceRect.x, y: sourceRect.y, scale: { x: scale.x, y: scale.y } };\n\n const resolveImage = args.resolveImage as ((n: Node<unknown, string, unknown>) => ImageBitmap | undefined) | undefined;\n const drawOne: SceneViewDrawOne<TData, TLayer, TPose> =\n args.drawOne ?? ((node, pose, view, ctx) => defaultDrawOne(node, pose, view, { ...ctx, resolveImage }));\n\n const commands: DrawCommand[] = [];\n if (args.background !== undefined) {\n // Screen-space (pre-view) fill so rounding can never leave uncovered\n // edge pixels.\n commands.push({\n kind: 'path',\n path: { kind: 'rect', x: 0, y: 0, width, height },\n fill: { fill: 'solid', color: args.background },\n });\n }\n commands.push(...buildSceneViewCommands(\n args.scene, view, drawOne, undefined, args.alphaFor, undefined, undefined, args.colorOverrides,\n ));\n if (args.overlay) commands.push(...args.overlay);\n return { width, height, view, commands };\n}\n\nfunction defaultCreateCanvas(width: number, height: number): HeadlessCanvasLike {\n if (typeof OffscreenCanvas !== 'undefined') {\n return new OffscreenCanvas(width, height);\n }\n if (typeof document !== 'undefined') {\n const c = document.createElement('canvas');\n c.width = width;\n c.height = height;\n return c;\n }\n throw new Error('renderSceneToPixels: no canvas source in this environment — supply `gl` or `createCanvas`');\n}\n\n/** Flip GL's bottom-up readback rows into top-down image order. */\nfunction flipRows(raw: Uint8Array, width: number, height: number): Uint8ClampedArray {\n const rowBytes = width * 4;\n const out = new Uint8ClampedArray(raw.length);\n for (let y = 0; y < height; y++) {\n out.set(raw.subarray((height - 1 - y) * rowBytes, (height - y) * rowBytes), y * rowBytes);\n }\n return out;\n}\n\n/** Convert premultiplied RGBA to straight RGBA in place. */\nfunction unpremultiply(data: Uint8ClampedArray): void {\n for (let i = 0; i < data.length; i += 4) {\n const a = data[i + 3];\n if (a === 0 || a === 255) continue;\n const inv = 255 / a;\n data[i] = data[i] * inv;\n data[i + 1] = data[i + 1] * inv;\n data[i + 2] = data[i + 2] * inv;\n }\n}\n\n/** Where a {@link RasterSession} draws. Pass `gl` or `createCanvas`, or\n * neither for the default canvas source. */\nexport interface RasterSessionOptions {\n /** Caller-owned WebGL2 context. The session never disposes it. Its drawing\n * buffer must be at least as large as every render the session does. */\n gl?: WebGL2RenderingContext;\n /** Canvas factory, called once, at the size of the first render. The\n * session grows the canvas when a later render needs more room and never\n * shrinks it. Default: `OffscreenCanvas` when available, else a detached\n * DOM canvas. */\n createCanvas?: (widthPx: number, heightPx: number) => HeadlessCanvasLike;\n}\n\n/** One render through a {@link RasterSession}: everything\n * `renderSceneToPixels` takes except where to draw. */\nexport type RasterRenderArgs<TData, TLayer extends string, TPose> =\n Omit<RenderSceneToPixelsArgs<TData, TLayer, TPose>, 'gl' | 'createCanvas'>;\n\n/** One renderer and its GPU caches, kept across any number of headless\n * renders. Scenes, source rects and scales may differ per render. */\nexport interface RasterSession {\n /** Same contract as `renderSceneToPixels`. Throws once disposed. */\n render<TData, TLayer extends string, TPose>(args: RasterRenderArgs<TData, TLayer, TPose>): RasterImage;\n /** Free every GL resource the session created — programs, geometry, and\n * the texture and mesh caches — and drop its own canvas. A caller-owned\n * context stays open. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Open a raster session: one `WeaselRenderer` that many headless renders\n * share, for a consumer producing thumbnails or pages in bulk. Programs\n * compile once, and a bitmap or recurring mesh uploads once, rather than per\n * render. `renderSceneToPixels` is a session opened for one render.\n *\n * The renderer is created on the first render, so opening a session costs\n * nothing and fails nothing. Each render draws into the bottom-left\n * `width × height` of the buffer and reads that region back.\n */\nexport function createRasterSession(options: RasterSessionOptions = {}): RasterSession {\n if (options.gl && options.createCanvas) {\n throw new Error('raster session: `gl` and `createCanvas` are mutually exclusive');\n }\n let canvas: HeadlessCanvasLike | null = null;\n let gl: WebGL2RenderingContext | undefined = options.gl;\n let renderer: WeaselRenderer | null = null;\n let disposed = false;\n\n function contextFor(width: number, height: number): WebGL2RenderingContext {\n if (!options.gl) {\n if (!canvas) {\n canvas = (options.createCanvas ?? defaultCreateCanvas)(width, height);\n canvas.width = width;\n canvas.height = height;\n // Same context attributes as the screen path (Canvas.tsx).\n gl = (canvas.getContext('webgl2', { preserveDrawingBuffer: true, stencil: true }) as WebGL2RenderingContext | null) ?? undefined;\n } else {\n if (canvas.width < width) canvas.width = width;\n if (canvas.height < height) canvas.height = height;\n }\n }\n if (!gl || typeof (gl as Partial<WebGL2RenderingContext>).enable !== 'function') {\n throw new Error('raster session: WebGL2 is unavailable — supply `gl` or a WebGL2-capable `createCanvas`');\n }\n if (isLost(gl)) {\n throw new Error('raster session: the WebGL2 context is lost — dispose this session and open another');\n }\n return gl;\n }\n\n return {\n render(args) {\n if (disposed) throw new Error('raster session: render() on a disposed session');\n const plan = planPixelRender(args);\n const { width, height } = plan;\n const ctx = contextFor(width, height);\n const flattenTolerance = (args.flattenTolerancePx ?? 0.25) / Math.max(args.scale.x, args.scale.y);\n if (!renderer) {\n renderer = new WeaselRenderer({\n gl: ctx,\n width,\n height,\n dpr: 1,\n imageMinification: 'mipmap',\n flattenTolerance,\n // Dynamic canvas-SDF glyphs must all bake inline — this path is\n // synchronous with no notify-and-redraw, and print must be complete.\n bakeBudget: Infinity,\n });\n } else {\n renderer.resize({ width, height, dpr: 1 });\n renderer.setFlattenTolerance(flattenTolerance);\n }\n renderer.render(plan.commands, viewToMat3(plan.view));\n if (isLost(ctx)) {\n throw new Error('raster session: the WebGL2 context was lost during render');\n }\n const raw = new Uint8Array(width * height * 4);\n ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, raw);\n const data = flipRows(raw, width, height);\n unpremultiply(data);\n return { width, height, data };\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n renderer?.dispose();\n renderer = null;\n canvas = null;\n gl = undefined;\n },\n };\n}\n\nfunction isLost(gl: WebGL2RenderingContext): boolean {\n return typeof gl.isContextLost === 'function' && gl.isContextLost() === true;\n}\n\n/** What {@link warmRender} loads. */\nexport interface WarmRenderOptions<TData = unknown, TLayer extends string = string, TPose = unknown> {\n /** The render about to happen, as `renderSceneToPixels` or\n * `RasterSession.render` will take it. Its commands are built the way the\n * render builds them, and only the faces and paint kinds they draw with\n * load. */\n render?: RasterRenderArgs<TData, TLayer, TPose>;\n /** Commands about to be drawn, read the same way as `render`'s. Both may be\n * given; what either needs loads. */\n commands?: readonly DrawCommand[];\n /** Fonts to load in place of the ones derived — family names or single\n * variants, as `warmFonts` takes them. */\n families?: readonly (string | FontRequest)[];\n /** Paint kinds to load in place of the ones derived, as `warmPaintKinds`\n * takes them. */\n paintKinds?: readonly string[];\n}\n\n/**\n * Load everything a synchronous render would otherwise draw as nothing — the\n * lazily registered font atlases and the paint kinds loaded on demand — so\n * that a `renderSceneToPixels` or `RasterSession.render` issued after it\n * resolves is complete.\n *\n * Pass the render (`{ render: args }`) or its commands, and only what they\n * draw with loads: each face their text is set in, through the same\n * resolution the renderer does, and each paint kind they name. A rejection\n * then means something this render needs failed to load. `families` and\n * `paintKinds` replace either derived list.\n *\n * With neither `render` nor `commands`, an omitted list loads everything\n * registered: every font family and every kind that has a loader — which\n * fails when any one of them does, and fetches what nothing draws.\n */\nexport function warmRender<TData, TLayer extends string, TPose>(\n opts: WarmRenderOptions<TData, TLayer, TPose> = {},\n): Promise<void> {\n let { families, paintKinds } = opts;\n if (opts.render || opts.commands) {\n let planned: DrawCommand[];\n try {\n planned = opts.render ? planPixelRender(opts.render).commands : [];\n } catch (err) {\n return Promise.reject(err);\n }\n const needs = renderNeeds([...planned, ...(opts.commands ?? [])]);\n families ??= needs.fonts;\n // A kind nothing registered draws nothing whether or not this waits.\n paintKinds ??= needs.paintKinds.filter(isPaintKindKnown);\n }\n return Promise.all([warmFonts(families), warmPaintKinds(paintKinds)]).then(() => undefined);\n}\n\n/**\n * Render part of a scene to raw pixels, with no canvas mounted and no React\n * involved — for export, thumbnails, print, and pixel-diff tests.\n *\n * Output size follows from the source rect and the requested scale, so\n * rendering the same region at a higher scale is a real resolution increase\n * rather than an upscale: curves are re-flattened and glyphs re-rasterized for\n * the output resolution.\n *\n * Synchronous, so nothing lands mid-render: a paint kind loaded on demand\n * (`mesh-gradient`, or one declared with `registerPaintKindLoader`) that has\n * not loaded yet draws nothing, and neither does text set in a font atlas\n * still fetching — one registered `{ lazy: true }` is not fetched until text\n * first asks for it. `await warmRender({ render: args })` first.\n *\n * Each call opens a {@link RasterSession} and disposes it before returning.\n * Rendering many scenes, open one with `createRasterSession` instead.\n */\nexport function renderSceneToPixels<TData, TLayer extends string, TPose>(\n args: RenderSceneToPixelsArgs<TData, TLayer, TPose>,\n): RasterImage {\n const { gl, createCanvas, ...renderArgs } = args;\n const session = createRasterSession({ gl, createCanvas });\n try {\n return session.render(renderArgs);\n } finally {\n session.dispose();\n }\n}\n"],"mappings":";;;;;;;;AAmIA,SAAgBA,EACd,GACiB;CACjB,IAAM,EAAE,eAAY,aAAUC;CAC9B,KAAK,IAAM,CAACC,GAAOC,MAAM;EACvB,CAAC,oBAAoBC,EAAW,KAAK;EAAG,CAAC,qBAAqBA,EAAW,MAAM;EAC/E,CAAC,WAAWC,EAAM,CAAC;EAAG,CAAC,WAAWA,EAAM,CAAC;CAC3C,GACE,IAAI,CAAC,OAAO,SAASF,CAAC,KAAKA,KAAK,GAC9B,MAAU,MAAM,wBAAwBD,EAAM,yCAAyCC,GAAG;CAG9F,KAAK,IAAM,CAACD,GAAOC,MAAM,CACvB,CAAC,gBAAgBC,EAAW,CAAC,GAAG,CAAC,gBAAgBA,EAAW,CAAC,CAC/D,GACE,IAAI,CAAC,OAAO,SAASD,CAAC,GACpB,MAAU,MAAM,wBAAwBD,EAAM,gCAAgCC,GAAG;CAGrF,IAAMG,IAAQ,KAAK,IAAI,GAAG,KAAK,MAAMF,EAAW,QAAQC,EAAM,CAAC,CAAC,GAC1DE,IAAS,KAAK,IAAI,GAAG,KAAK,MAAMH,EAAW,SAASC,EAAM,CAAC,CAAC,GAC5DG,IAAa;EAAE,GAAGJ,EAAW;EAAG,GAAGA,EAAW;EAAG,OAAO;GAAE,GAAGC,EAAM;GAAG,GAAGA,EAAM;EAAE;CAAE,GAEnFI,IAAeR,EAAK,cACpBS,IACJT,EAAK,aAAa,GAAM,GAAM,GAAM,MAAQU,EAAeC,GAAMC,GAAML,GAAM;EAAE,GAAGM;EAAK;CAAa,CAAC,IAEjGC,IAA0B,CAAC;CAcjC,OAbId,EAAK,eAAe,KAAA,KAGtBc,EAAS,KAAK;EACZ,MAAM;EACN,MAAM;GAAE,MAAM;GAAQ,GAAG;GAAG,GAAG;GAAG;GAAO;EAAO;EAChD,MAAM;GAAE,MAAM;GAAS,OAAOd,EAAK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CAAG;GACpE,IAAMI,IAAOP,EAASG,GAAKhB,GAAOC,CAAM;GAExC,OADAiB,EAAcE,CAAI,GACX;IAAE;IAAO;IAAQ;GAAK;EAC/B;EACA,UAAU;GACR,AAAIQ,MACJ,IAAW,IACXD,GAAU,QAAQ,GAClB,IAAW,MACX,IAAS,MACT,IAAK,KAAA;EACP;CACF;AACF;AAEA,SAASG,EAAO,GAAqC;CACnD,OAAO,OAAOJ,EAAG,iBAAkB,cAAcA,EAAG,cAAc,MAAM;AAC1E;AAoCA,SAAgBS,EACd,IAAgD,CAAC,GAClC;CACf,IAAI,EAAE,aAAU,kBAAeC;CAC/B,IAAIA,EAAK,UAAUA,EAAK,UAAU;EAChC,IAAIC;EACJ,IAAI;GACF,IAAUD,EAAK,SAAS1C,EAAgB0C,EAAK,MAAM,CAAC,CAAC,WAAW,CAAC;EACnE,SAASE,GAAK;GACZ,OAAO,QAAQ,OAAOA,CAAG;EAC3B;EACA,IAAMC,IAAQC,EAAY,CAAC,GAAGH,GAAS,GAAID,EAAK,YAAY,CAAC,CAAE,CAAC;EAGhE,AAFA,MAAaG,EAAM,OAEnB,MAAeA,EAAM,WAAW,OAAOE,CAAgB;CACzD;CACA,OAAO,QAAQ,IAAI,CAACC,EAAUC,CAAQ,GAAGC,EAAeC,CAAU,CAAC,CAAC,CAAC,CAAC,WAAW,KAAA,CAAS;AAC5F;AAoBA,SAAgBC,EACd,GACa;CACb,IAAM,EAAE,OAAI,iBAAc,GAAGC,MAAepD,GACtCqD,IAAUzB,EAAoB;EAAE;EAAI;CAAa,CAAC;CACxD,IAAI;EACF,OAAOyB,EAAQ,OAAOD,CAAU;CAClC,UAAU;EACR,EAAQ,QAAQ;CAClB;AACF"}
|
|
1
|
+
{"version":3,"file":"renderSceneToPixels.js","names":["planPixelRender","args","label","v","sourceRect","scale","width","height","view","resolveImage","drawOne","defaultDrawOne","node","pose","ctx","commands","buildSceneViewCommands","defaultCreateCanvas","c","flipRows","rowBytes","out","raw","y","unpremultiply","i","data","a","inv","createRasterSession","options","canvas","gl","renderer","disposed","contextFor","isLost","bufferW","bufferH","plan","flattenTolerance","WeaselRenderer","viewToMat3","warmRender","opts","planned","err","needs","renderNeeds","isPaintKindKnown","warmFonts","families","warmPaintKinds","paintKinds","renderSceneToPixels","renderArgs","session"],"sources":["../../src/canvas/renderSceneToPixels.ts"],"sourcesContent":["/**\n * `renderSceneToPixels` — headless rasterization of a scene-space rect to\n * raw RGBA pixels at an explicit, per-axis scale.\n *\n * One renderer, two callers: this path drives the same WebGL2 pipeline\n * (`WeaselRenderer` + `buildSceneViewCommands`) as the on-screen view — it is\n * NOT a second renderer. Print, thumbnail, and export callers get the same\n * pixels the screen would produce at that scale.\n *\n * Environment contract:\n * - Density arrives exclusively via `scale` (output pixels per scene unit,\n * per axis — anisotropic values are first-class). This function never\n * reads `window.devicePixelRatio`.\n * - Rounding policy: output width = max(1, round(sourceRect.width × scale.x)),\n * height analogously. The scene-space rect is authoritative; the pixel\n * grid derives from it. When round() lands below rect × scale, the\n * rightmost/bottom sub-pixel band of scene content is cropped; when it\n * rounds up, that band is instead padded (the `background` fill, or\n * transparent, covers the pad).\n * - Context lifetime: each call opens a `RasterSession` — one\n * `WeaselRenderer` — and disposes it before returning, freeing every GL\n * object it created, caches included. Rendering in bulk, open one session\n * with `createRasterSession` and render through it: programs compile once\n * and bitmaps upload once for the whole batch, and `dispose()` frees them.\n * With a caller-supplied `gl`, the context itself is caller-owned: it is\n * never disposed here, and its drawing buffer must be at least\n * width × height pixels (the render targets the bottom-left region).\n * Auto-created canvases (`OffscreenCanvas` when available, else a detached\n * DOM canvas) are discarded with the session; a session grows its own\n * canvas to the largest render so far.\n * - Context loss: throws — a lost context cannot produce pixels, and the\n * silent-noop convention of the screen path would return all-zero bytes.\n * - Output: top-down row order, NON-premultiplied (\"straight\") RGBA. The GL\n * framebuffer is premultiplied (blendFunc ONE, ONE_MINUS_SRC_ALPHA) and\n * bottom-up; readback flips and unpremultiplies. Over an opaque\n * `background` both transforms are visually moot but still applied.\n * - Determinism: same context + same inputs → same bytes. Cross-driver /\n * cross-machine byte equality is NOT guaranteed (GL rasterization varies);\n * do not build golden-image tests on committed bytes.\n * - Image quality: image textures upload with mipmaps\n * (`imageMinification: 'mipmap'`) so minified bitmaps don't moiré, and\n * curve tessellation runs at an output-scale tolerance\n * (`flattenTolerancePx`, default 0.25 output px). A bitmap node's source\n * pixels are sampled exactly once, directly to the output grid.\n */\nimport { WeaselRenderer } from '../renderer/WeaselRenderer';\nimport { viewToMat3 } from '../renderer/math/viewToMat3';\nimport type { DrawCommand } from '../renderer/DrawCommand';\nimport type { View } from '../core/viewport/view';\nimport type { Node, Scene } from 'core/scene/types';\nimport { buildSceneViewCommands, type SceneViewDrawOne } from './sceneViewRender';\nimport type { ColorOverrideRegistry } from '../animation/colorRegistry';\nimport { defaultDrawOne } from './defaultDrawOne';\nimport { warmFonts, type FontRequest } from '@weasel-js/font';\nimport { isPaintKindKnown, warmPaintKinds } from '../core/paintKinds';\nimport { renderNeeds } from './renderNeeds';\n\n/** Plain RGBA raster — structurally `ImageData`-compatible ({ width, height,\n * data }), deliberately free of printer/dpi/physical-unit concepts. */\nexport interface RasterImage {\n width: number;\n height: number;\n /** Top-down, straight (non-premultiplied) RGBA, 4 bytes per pixel. */\n data: Uint8ClampedArray;\n}\n\n/** Minimal canvas contract for `createCanvas` injection: `OffscreenCanvas`,\n * an HTML canvas, or a test fake. */\nexport interface HeadlessCanvasLike {\n width: number;\n height: number;\n getContext(contextId: 'webgl2', options?: WebGLContextAttributes): unknown;\n}\n\n/** What to render, at what resolution, and with which quality settings. */\nexport interface RenderSceneToPixelsArgs<TData, TLayer extends string, TPose> {\n scene: Scene<TData, TLayer, TPose>;\n /** Scene-space rect to render (origin + size in scene units). Output pixel\n * dimensions follow from rect × scale (round, min 1 — see module doc). */\n sourceRect: { x: number; y: number; width: number; height: number };\n /** Output pixels per scene unit, per axis. Anisotropic values supported. */\n scale: { x: number; y: number };\n /** Per-node draw callback. Default: `defaultDrawOne` with `resolveImage`\n * merged into the `NodePaintCtx` the scene walk supplies. Custom `drawOne`\n * callers that still want resolver injection should call\n * `defaultDrawOne(node, pose, view, { ...ctx, resolveImage })` themselves —\n * dropping the walk's `ctx` drops derived geometry with it. */\n drawOne?: SceneViewDrawOne<TData, TLayer, TPose>;\n /** Bitmap resolver for image nodes — lets consumers reuse their own decode\n * caches. `undefined` results paint the deterministic grey placeholder\n * outline (see `NodePaintCtx.resolveImage`). */\n resolveImage?: (node: Node<TData, TLayer, TPose>) => ImageBitmap | undefined;\n /** Per-id alpha multiplier, mirroring `<SceneCanvas>`'s scene-slot\n * `alphaFor`. Pass the same function the on-screen canvas uses so an\n * export matches what the user is looking at. Defaults to `() => 1`. */\n alphaFor?: (id: string) => number;\n /** Animated vertex colors to paint, typically an animator's\n * `colorOverrides`, so an export shows the frame on screen. */\n colorOverrides?: ColorOverrideRegistry;\n /** Background fill (any CSS color accepted by the renderer). Default:\n * fully transparent. Passing a color is always valid. */\n background?: string;\n /** Caller-owned WebGL2 context to render with. Mutually exclusive with\n * `createCanvas`. Never disposed by this call. */\n gl?: WebGL2RenderingContext;\n /** One-shot canvas factory (DOM canvas, OffscreenCanvas, or test fake).\n * Mutually exclusive with `gl`. Default: `OffscreenCanvas` when\n * available, else `document.createElement('canvas')`. */\n createCanvas?: (widthPx: number, heightPx: number) => HeadlessCanvasLike;\n /** Max curve-flattening error in OUTPUT pixels. Default 0.25. Converted to\n * world units against the larger scale axis and passed to the renderer's\n * `flattenTolerance`. Explicitly passing 0.25 is always valid. */\n flattenTolerancePx?: number;\n /** Commands drawn over the scene in output-pixel space — origin at the\n * output's top-left, one unit per output pixel. Annotations, watermarks,\n * and `renderDebugSnapshot`'s overlay ride here. */\n overlay?: readonly DrawCommand[];\n}\n\n/** The result of planning a headless render: how big the output is, the view\n * that maps the source rect onto it, and the commands to draw. */\nexport interface PixelRenderPlan {\n width: number;\n height: number;\n view: View;\n commands: DrawCommand[];\n}\n\n/** Pure planning half of `renderSceneToPixels`: output dimensions, the\n * anisotropic `View`, and the full command list (background + view-wrapped\n * scene). Exported for tests and for callers targeting their own renderer. */\nexport function planPixelRender<TData, TLayer extends string, TPose>(\n args: Omit<RenderSceneToPixelsArgs<TData, TLayer, TPose>, 'gl' | 'createCanvas' | 'flattenTolerancePx'>,\n): PixelRenderPlan {\n const { sourceRect, scale } = args;\n for (const [label, v] of [\n ['sourceRect.width', sourceRect.width], ['sourceRect.height', sourceRect.height],\n ['scale.x', scale.x], ['scale.y', scale.y],\n ] as const) {\n if (!Number.isFinite(v) || v <= 0) {\n throw new Error(`renderSceneToPixels: ${label} must be a positive finite number, got ${v}`);\n }\n }\n for (const [label, v] of [\n ['sourceRect.x', sourceRect.x], ['sourceRect.y', sourceRect.y],\n ] as const) {\n if (!Number.isFinite(v)) {\n throw new Error(`renderSceneToPixels: ${label} must be a finite number, got ${v}`);\n }\n }\n const width = Math.max(1, Math.round(sourceRect.width * scale.x));\n const height = Math.max(1, Math.round(sourceRect.height * scale.y));\n const view: View = { x: sourceRect.x, y: sourceRect.y, scale: { x: scale.x, y: scale.y } };\n\n const resolveImage = args.resolveImage as ((n: Node<unknown, string, unknown>) => ImageBitmap | undefined) | undefined;\n const drawOne: SceneViewDrawOne<TData, TLayer, TPose> =\n args.drawOne ?? ((node, pose, view, ctx) => defaultDrawOne(node, pose, view, { ...ctx, resolveImage }));\n\n const commands: DrawCommand[] = [];\n if (args.background !== undefined) {\n // Screen-space (pre-view) fill so rounding can never leave uncovered\n // edge pixels.\n commands.push({\n kind: 'path',\n path: { kind: 'rect', x: 0, y: 0, width, height },\n fill: { fill: 'solid', color: args.background },\n });\n }\n commands.push(...buildSceneViewCommands(\n args.scene, view, drawOne, undefined, args.alphaFor, undefined, undefined, args.colorOverrides,\n ));\n if (args.overlay) commands.push(...args.overlay);\n return { width, height, view, commands };\n}\n\nfunction defaultCreateCanvas(width: number, height: number): HeadlessCanvasLike {\n if (typeof OffscreenCanvas !== 'undefined') {\n return new OffscreenCanvas(width, height);\n }\n if (typeof document !== 'undefined') {\n const c = document.createElement('canvas');\n c.width = width;\n c.height = height;\n return c;\n }\n throw new Error('renderSceneToPixels: no canvas source in this environment — supply `gl` or `createCanvas`');\n}\n\n/** Flip GL's bottom-up readback rows into top-down image order. */\nfunction flipRows(raw: Uint8Array, width: number, height: number): Uint8ClampedArray {\n const rowBytes = width * 4;\n const out = new Uint8ClampedArray(raw.length);\n for (let y = 0; y < height; y++) {\n out.set(raw.subarray((height - 1 - y) * rowBytes, (height - y) * rowBytes), y * rowBytes);\n }\n return out;\n}\n\n/** Convert premultiplied RGBA to straight RGBA in place. */\nfunction unpremultiply(data: Uint8ClampedArray): void {\n for (let i = 0; i < data.length; i += 4) {\n const a = data[i + 3];\n if (a === 0 || a === 255) continue;\n const inv = 255 / a;\n data[i] = data[i] * inv;\n data[i + 1] = data[i + 1] * inv;\n data[i + 2] = data[i + 2] * inv;\n }\n}\n\n/** Where a {@link RasterSession} draws. Pass `gl` or `createCanvas`, or\n * neither for the default canvas source. */\nexport interface RasterSessionOptions {\n /** Caller-owned WebGL2 context. The session never disposes it. Its drawing\n * buffer must be at least as large as every render the session does. */\n gl?: WebGL2RenderingContext;\n /** Canvas factory, called once, at the size of the first render. The\n * session grows the canvas when a later render needs more room and never\n * shrinks it. Default: `OffscreenCanvas` when available, else a detached\n * DOM canvas. */\n createCanvas?: (widthPx: number, heightPx: number) => HeadlessCanvasLike;\n}\n\n/** One render through a {@link RasterSession}: everything\n * `renderSceneToPixels` takes except where to draw. */\nexport type RasterRenderArgs<TData, TLayer extends string, TPose> =\n Omit<RenderSceneToPixelsArgs<TData, TLayer, TPose>, 'gl' | 'createCanvas'>;\n\n/** One renderer and its GPU caches, kept across any number of headless\n * renders. Scenes, source rects and scales may differ per render. */\nexport interface RasterSession {\n /** Same contract as `renderSceneToPixels`. Throws once disposed. */\n render<TData, TLayer extends string, TPose>(args: RasterRenderArgs<TData, TLayer, TPose>): RasterImage;\n /** Free every GL resource the session created — programs, geometry, and\n * the texture and mesh caches — and drop its own canvas. A caller-owned\n * context stays open. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Open a raster session: one `WeaselRenderer` that many headless renders\n * share, for a consumer producing thumbnails or pages in bulk. Programs\n * compile once, and a bitmap or recurring mesh uploads once, rather than per\n * render. `renderSceneToPixels` is a session opened for one render.\n *\n * The renderer is created on the first render, so opening a session costs\n * nothing and fails nothing. Each render draws into the bottom-left\n * `width × height` of the buffer and reads that region back.\n */\nexport function createRasterSession(options: RasterSessionOptions = {}): RasterSession {\n if (options.gl && options.createCanvas) {\n throw new Error('raster session: `gl` and `createCanvas` are mutually exclusive');\n }\n let canvas: HeadlessCanvasLike | null = null;\n let gl: WebGL2RenderingContext | undefined = options.gl;\n let renderer: WeaselRenderer | null = null;\n let disposed = false;\n\n function contextFor(width: number, height: number): WebGL2RenderingContext {\n if (!options.gl) {\n if (!canvas) {\n canvas = (options.createCanvas ?? defaultCreateCanvas)(width, height);\n canvas.width = width;\n canvas.height = height;\n // Same context attributes as the screen path (Canvas.tsx).\n gl = (canvas.getContext('webgl2', { preserveDrawingBuffer: true, stencil: true }) as WebGL2RenderingContext | null) ?? undefined;\n } else {\n if (canvas.width < width) canvas.width = width;\n if (canvas.height < height) canvas.height = height;\n }\n }\n if (!gl || typeof (gl as Partial<WebGL2RenderingContext>).enable !== 'function') {\n throw new Error('raster session: WebGL2 is unavailable — supply `gl` or a WebGL2-capable `createCanvas`');\n }\n if (isLost(gl)) {\n throw new Error('raster session: the WebGL2 context is lost — dispose this session and open another');\n }\n // A context clamps a drawing buffer it cannot allocate, and reading past\n // the real one returns transparent pixels rather than failing.\n const { drawingBufferWidth: bufferW, drawingBufferHeight: bufferH } = gl;\n if (bufferW < width || bufferH < height) {\n throw new Error(\n `raster session: a ${width} × ${height} render does not fit the context's `\n + `${bufferW} × ${bufferH} drawing buffer — lower \\`scale\\` or render the source rect in tiles`,\n );\n }\n return gl;\n }\n\n return {\n render(args) {\n if (disposed) throw new Error('raster session: render() on a disposed session');\n const plan = planPixelRender(args);\n const { width, height } = plan;\n const ctx = contextFor(width, height);\n const flattenTolerance = (args.flattenTolerancePx ?? 0.25) / Math.max(args.scale.x, args.scale.y);\n if (!renderer) {\n renderer = new WeaselRenderer({\n gl: ctx,\n width,\n height,\n dpr: 1,\n imageMinification: 'mipmap',\n flattenTolerance,\n // Dynamic canvas-SDF glyphs must all bake inline — this path is\n // synchronous with no notify-and-redraw, and print must be complete.\n bakeBudget: Infinity,\n });\n } else {\n renderer.resize({ width, height, dpr: 1 });\n renderer.setFlattenTolerance(flattenTolerance);\n }\n renderer.render(plan.commands, viewToMat3(plan.view));\n if (isLost(ctx)) {\n throw new Error('raster session: the WebGL2 context was lost during render');\n }\n const raw = new Uint8Array(width * height * 4);\n ctx.readPixels(0, 0, width, height, ctx.RGBA, ctx.UNSIGNED_BYTE, raw);\n const data = flipRows(raw, width, height);\n unpremultiply(data);\n return { width, height, data };\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n renderer?.dispose();\n renderer = null;\n // A browser caps live contexts per page and evicts the oldest, which is\n // a canvas on screen; a dropped reference frees nothing until collected.\n if (canvas && !options.createCanvas) gl?.getExtension('WEBGL_lose_context')?.loseContext();\n canvas = null;\n gl = undefined;\n },\n };\n}\n\nfunction isLost(gl: WebGL2RenderingContext): boolean {\n return typeof gl.isContextLost === 'function' && gl.isContextLost() === true;\n}\n\n/** What {@link warmRender} loads. */\nexport interface WarmRenderOptions<TData = unknown, TLayer extends string = string, TPose = unknown> {\n /** The render about to happen, as `renderSceneToPixels` or\n * `RasterSession.render` will take it. Its commands are built the way the\n * render builds them, and only the faces and paint kinds they draw with\n * load. */\n render?: RasterRenderArgs<TData, TLayer, TPose>;\n /** Commands about to be drawn, read the same way as `render`'s. Both may be\n * given; what either needs loads. */\n commands?: readonly DrawCommand[];\n /** Fonts to load in place of the ones derived — family names or single\n * variants, as `warmFonts` takes them. */\n families?: readonly (string | FontRequest)[];\n /** Paint kinds to load in place of the ones derived, as `warmPaintKinds`\n * takes them. */\n paintKinds?: readonly string[];\n}\n\n/**\n * Load everything a synchronous render would otherwise draw as nothing — the\n * lazily registered font atlases and the paint kinds loaded on demand — so\n * that a `renderSceneToPixels` or `RasterSession.render` issued after it\n * resolves is complete.\n *\n * Pass the render (`{ render: args }`) or its commands, and only what they\n * draw with loads: each face their text is set in, through the same\n * resolution the renderer does, and each paint kind they name. A rejection\n * then means something this render needs failed to load. `families` and\n * `paintKinds` replace either derived list.\n *\n * With neither `render` nor `commands`, an omitted list loads everything\n * registered: every font family and every kind that has a loader — which\n * fails when any one of them does, and fetches what nothing draws.\n */\nexport function warmRender<TData, TLayer extends string, TPose>(\n opts: WarmRenderOptions<TData, TLayer, TPose> = {},\n): Promise<void> {\n let { families, paintKinds } = opts;\n if (opts.render || opts.commands) {\n let planned: DrawCommand[];\n try {\n planned = opts.render ? planPixelRender(opts.render).commands : [];\n } catch (err) {\n return Promise.reject(err);\n }\n const needs = renderNeeds([...planned, ...(opts.commands ?? [])]);\n families ??= needs.fonts;\n // A kind nothing registered draws nothing whether or not this waits.\n paintKinds ??= needs.paintKinds.filter(isPaintKindKnown);\n }\n return Promise.all([warmFonts(families), warmPaintKinds(paintKinds)]).then(() => undefined);\n}\n\n/**\n * Render part of a scene to raw pixels, with no canvas mounted and no React\n * involved — for export, thumbnails, print, and pixel-diff tests.\n *\n * Output size follows from the source rect and the requested scale, so\n * rendering the same region at a higher scale is a real resolution increase\n * rather than an upscale: curves are re-flattened and glyphs re-rasterized for\n * the output resolution.\n *\n * Synchronous, so nothing lands mid-render: a paint kind loaded on demand\n * (`mesh-gradient`, or one declared with `registerPaintKindLoader`) that has\n * not loaded yet draws nothing, and neither does text set in a font atlas\n * still fetching — one registered `{ lazy: true }` is not fetched until text\n * first asks for it. `await warmRender({ render: args })` first.\n *\n * Each call opens a {@link RasterSession} and disposes it before returning.\n * Rendering many scenes, open one with `createRasterSession` instead.\n */\nexport function renderSceneToPixels<TData, TLayer extends string, TPose>(\n args: RenderSceneToPixelsArgs<TData, TLayer, TPose>,\n): RasterImage {\n const { gl, createCanvas, ...renderArgs } = args;\n const session = createRasterSession({ gl, createCanvas });\n try {\n return session.render(renderArgs);\n } finally {\n session.dispose();\n }\n}\n"],"mappings":";;;;;;;;AAmIA,SAAgBA,EACd,GACiB;CACjB,IAAM,EAAE,eAAY,aAAUC;CAC9B,KAAK,IAAM,CAACC,GAAOC,MAAM;EACvB,CAAC,oBAAoBC,EAAW,KAAK;EAAG,CAAC,qBAAqBA,EAAW,MAAM;EAC/E,CAAC,WAAWC,EAAM,CAAC;EAAG,CAAC,WAAWA,EAAM,CAAC;CAC3C,GACE,IAAI,CAAC,OAAO,SAASF,CAAC,KAAKA,KAAK,GAC9B,MAAU,MAAM,wBAAwBD,EAAM,yCAAyCC,GAAG;CAG9F,KAAK,IAAM,CAACD,GAAOC,MAAM,CACvB,CAAC,gBAAgBC,EAAW,CAAC,GAAG,CAAC,gBAAgBA,EAAW,CAAC,CAC/D,GACE,IAAI,CAAC,OAAO,SAASD,CAAC,GACpB,MAAU,MAAM,wBAAwBD,EAAM,gCAAgCC,GAAG;CAGrF,IAAMG,IAAQ,KAAK,IAAI,GAAG,KAAK,MAAMF,EAAW,QAAQC,EAAM,CAAC,CAAC,GAC1DE,IAAS,KAAK,IAAI,GAAG,KAAK,MAAMH,EAAW,SAASC,EAAM,CAAC,CAAC,GAC5DG,IAAa;EAAE,GAAGJ,EAAW;EAAG,GAAGA,EAAW;EAAG,OAAO;GAAE,GAAGC,EAAM;GAAG,GAAGA,EAAM;EAAE;CAAE,GAEnFI,IAAeR,EAAK,cACpBS,IACJT,EAAK,aAAa,GAAM,GAAM,GAAM,MAAQU,EAAeC,GAAMC,GAAML,GAAM;EAAE,GAAGM;EAAK;CAAa,CAAC,IAEjGC,IAA0B,CAAC;CAcjC,OAbId,EAAK,eAAe,KAAA,KAGtBc,EAAS,KAAK;EACZ,MAAM;EACN,MAAM;GAAE,MAA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