@weasel-js/core 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +199 -0
- package/dist/animation/poseTarget.js +46 -15
- package/dist/animation/poseTarget.js.map +1 -1
- package/dist/animation/poseTransition.js +3 -3
- package/dist/animation/poseTransition.js.map +1 -1
- package/dist/animation/reflow.js +3 -6
- package/dist/animation/reflow.js.map +1 -1
- package/dist/animation/rig/bindRig.js +2 -2
- package/dist/animation/rig/bindRig.js.map +1 -1
- package/dist/animation/rig/skinBinding.js +2 -2
- package/dist/animation/rig/skinBinding.js.map +1 -1
- package/dist/barrel/canvas.js +5 -3
- package/dist/barrel/chrome.js +3 -1
- package/dist/barrel/paths.js +3 -2
- package/dist/barrel/routing.js +2 -2
- package/dist/barrel/scene.js +6 -1
- package/dist/barrel/text.js +2 -2
- package/dist/canvas/NodeShape.js +1 -0
- package/dist/canvas/NodeShape.js.map +1 -1
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js +2 -0
- package/dist/canvas/SceneCanvas/SceneCanvasInput.js.map +1 -1
- package/dist/canvas/SceneCanvas/canvasPassThrough.js +1 -1
- package/dist/canvas/SceneCanvas/canvasPassThrough.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js +2 -2
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
- package/dist/canvas/SceneCanvas/scenePointQuery.js +20 -2
- package/dist/canvas/SceneCanvas/scenePointQuery.js.map +1 -1
- package/dist/canvas/SceneCanvas/useCanvasTools.js +3 -0
- package/dist/canvas/SceneCanvas/useCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useContributionRoles.js +2 -0
- package/dist/canvas/SceneCanvas/useContributionRoles.js.map +1 -1
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +25 -19
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js +7 -0
- package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +1 -0
- package/dist/canvas/SceneCanvas/useSceneCanvasTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useScenePicking.js +31 -6
- package/dist/canvas/SceneCanvas/useScenePicking.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +4 -5
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js +5 -3
- package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +19 -2
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/accentColor.js +26 -3
- package/dist/canvas/accentColor.js.map +1 -1
- package/dist/canvas/buildSceneLayer.js +1 -1
- package/dist/canvas/buildSceneLayer.js.map +1 -1
- package/dist/canvas/buildSceneTree.js +14 -20
- package/dist/canvas/buildSceneTree.js.map +1 -1
- package/dist/canvas/canvasRenderer.js +6 -2
- package/dist/canvas/canvasRenderer.js.map +1 -1
- package/dist/canvas/copiesAbove.js +1 -1
- package/dist/canvas/copiesAbove.js.map +1 -1
- package/dist/canvas/defaultDrawOne.js +10 -7
- package/dist/canvas/defaultDrawOne.js.map +1 -1
- package/dist/canvas/deps/areaSelect.js +5 -2
- package/dist/canvas/deps/areaSelect.js.map +1 -1
- package/dist/canvas/deps/booleans.js +1 -1
- package/dist/canvas/deps/booleans.js.map +1 -1
- package/dist/canvas/deps/enteredGroup.js +81 -0
- package/dist/canvas/deps/enteredGroup.js.map +1 -0
- package/dist/canvas/deps/hitTestArea.js +27 -15
- package/dist/canvas/deps/hitTestArea.js.map +1 -1
- package/dist/canvas/deps/insert.js +4 -36
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/insertSite.js +39 -0
- package/dist/canvas/deps/insertSite.js.map +1 -0
- package/dist/canvas/deps/lassoSelect.js +6 -3
- package/dist/canvas/deps/lassoSelect.js.map +1 -1
- package/dist/canvas/deps/pathLeaf.js +1 -1
- package/dist/canvas/deps/pathLeaf.js.map +1 -1
- package/dist/canvas/deps/slice.js +2 -1
- package/dist/canvas/deps/slice.js.map +1 -1
- package/dist/canvas/derivedPath.js +14 -6
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/doubleClickTarget.js +9 -11
- package/dist/canvas/doubleClickTarget.js.map +1 -1
- package/dist/canvas/drawnBounds.js +16 -7
- package/dist/canvas/drawnBounds.js.map +1 -1
- package/dist/canvas/inheritedPaints.js +22 -11
- package/dist/canvas/inheritedPaints.js.map +1 -1
- package/dist/canvas/nodeShapes/nodePaint.js +1 -7
- package/dist/canvas/nodeShapes/nodePaint.js.map +1 -1
- package/dist/canvas/nodeShapes/pathPainter.js +2 -3
- package/dist/canvas/nodeShapes/pathPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/rectFallbackPainter.js +1 -1
- package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -1
- package/dist/canvas/nodeShapes/shapePainter.js +2 -3
- package/dist/canvas/nodeShapes/shapePainter.js.map +1 -1
- package/dist/canvas/ownClip.js +24 -0
- package/dist/canvas/ownClip.js.map +1 -0
- package/dist/canvas/paintCull.js.map +1 -1
- package/dist/canvas/pickIndex/nodeBroadBox.js +86 -0
- package/dist/canvas/pickIndex/nodeBroadBox.js.map +1 -0
- package/dist/canvas/pickIndex/scenePickIndex.js +208 -0
- package/dist/canvas/pickIndex/scenePickIndex.js.map +1 -0
- package/dist/canvas/pickWalk.js +14 -90
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/poseCascade.js +1 -1
- package/dist/canvas/poseCascade.js.map +1 -1
- package/dist/canvas/publishPreviews.js +97 -0
- package/dist/canvas/publishPreviews.js.map +1 -0
- package/dist/canvas/sceneAdapter.js +7 -5
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneClipboard.js +17 -10
- package/dist/canvas/sceneClipboard.js.map +1 -1
- package/dist/canvas/scenePickReads.js +37 -0
- package/dist/canvas/scenePickReads.js.map +1 -0
- package/dist/canvas/scenePickSource.js +74 -0
- package/dist/canvas/scenePickSource.js.map +1 -0
- package/dist/canvas/sceneSlotWiring.js +9 -4
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +13 -8
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/shownNodes.js +15 -0
- package/dist/canvas/shownNodes.js.map +1 -0
- package/dist/canvas/useCanvasPaint.js +3 -1
- package/dist/canvas/useCanvasPaint.js.map +1 -1
- package/dist/canvas/useSceneAdapter.js +5 -3
- package/dist/canvas/useSceneAdapter.js.map +1 -1
- package/dist/clipboard.d.ts +2 -2
- package/dist/{clone-C3e0OTuF.d.ts → clone-qb2e1F5p.d.ts} +2 -2
- package/dist/clone.d.ts +3 -3
- package/dist/core/isPlainObject.js +2 -2
- package/dist/core/layers/layerGroup.js.map +1 -1
- package/dist/core/layers/render.js.map +1 -1
- package/dist/core/scene/NodeRouting.js.map +1 -1
- package/dist/core/scene/arrivalWindow.js +1 -1
- package/dist/core/scene/arrivalWindow.js.map +1 -1
- package/dist/core/scene/clipNothing.js +2 -5
- package/dist/core/scene/clipNothing.js.map +1 -1
- package/dist/core/scene/declaredFieldSetters.js +44 -0
- package/dist/core/scene/declaredFieldSetters.js.map +1 -0
- package/dist/core/scene/depMemo.js +3 -0
- package/dist/core/scene/depMemo.js.map +1 -1
- package/dist/core/scene/dependents.js +3 -1
- package/dist/core/scene/dependents.js.map +1 -1
- package/dist/core/scene/documentOf.js +43 -0
- package/dist/core/scene/documentOf.js.map +1 -0
- package/dist/core/scene/effectivePose.js +37 -13
- package/dist/core/scene/effectivePose.js.map +1 -1
- package/dist/core/scene/fieldEdits.js +17 -14
- package/dist/core/scene/fieldEdits.js.map +1 -1
- package/dist/core/scene/historyForm.js +4 -4
- package/dist/core/scene/historyForm.js.map +1 -1
- package/dist/core/scene/inheritedPaint.js +27 -5
- package/dist/core/scene/inheritedPaint.js.map +1 -1
- package/dist/core/scene/kitOps.js +3 -23
- package/dist/core/scene/kitOps.js.map +1 -1
- package/dist/core/scene/layoutPass.js +1 -2
- package/dist/core/scene/layoutPass.js.map +1 -1
- package/dist/core/scene/nodeAsShown.js +72 -0
- package/dist/core/scene/nodeAsShown.js.map +1 -0
- package/dist/core/scene/nodeFnFields.js +2 -10
- package/dist/core/scene/nodeFnFields.js.map +1 -1
- package/dist/core/scene/nodeMemo.js +6 -1
- package/dist/core/scene/nodeMemo.js.map +1 -1
- package/dist/core/scene/nodeStore.js +2 -4
- package/dist/core/scene/nodeStore.js.map +1 -1
- package/dist/core/scene/pathEffects/derive.js +3 -2
- package/dist/core/scene/pathEffects/derive.js.map +1 -1
- package/dist/core/scene/pathEffects/foundHidden.js +35 -0
- package/dist/core/scene/pathEffects/foundHidden.js.map +1 -0
- package/dist/core/scene/plyStacks.js +89 -0
- package/dist/core/scene/plyStacks.js.map +1 -0
- package/dist/core/scene/poseHold.js +42 -24
- package/dist/core/scene/poseHold.js.map +1 -1
- package/dist/core/scene/poseOverrides.js +35 -38
- package/dist/core/scene/poseOverrides.js.map +1 -1
- package/dist/core/scene/posePlies.js +59 -0
- package/dist/core/scene/posePlies.js.map +1 -0
- package/dist/core/scene/reconcileSpecs.js +6 -15
- package/dist/core/scene/reconcileSpecs.js.map +1 -1
- package/dist/core/scene/renderOrder.js +10 -4
- package/dist/core/scene/renderOrder.js.map +1 -1
- package/dist/core/scene/sameValue.js +17 -0
- package/dist/core/scene/sameValue.js.map +1 -0
- package/dist/core/scene/scene.js +3 -3
- package/dist/core/scene/scene.js.map +1 -1
- package/dist/core/scene/sceneEdits.js +8 -0
- package/dist/core/scene/sceneEdits.js.map +1 -1
- package/dist/core/scene/sceneState.js +1 -2
- package/dist/core/scene/sceneState.js.map +1 -1
- package/dist/core/scene/serialization.js +45 -9
- package/dist/core/scene/serialization.js.map +1 -1
- package/dist/core/scene/staleReplay.js +5 -2
- package/dist/core/scene/staleReplay.js.map +1 -1
- package/dist/core/scene/statedFields.js +4 -2
- package/dist/core/scene/statedFields.js.map +1 -1
- package/dist/core/scene/treeEdits.js +2 -4
- package/dist/core/scene/treeEdits.js.map +1 -1
- package/dist/core/scene/treeOrder.js +3 -1
- package/dist/core/scene/treeOrder.js.map +1 -1
- package/dist/core/scene/treeReads.js +1 -2
- package/dist/core/scene/treeReads.js.map +1 -1
- package/dist/core/scene/treeShape.js +13 -0
- package/dist/core/scene/treeShape.js.map +1 -0
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/scene/useScene.js +1 -1
- package/dist/core/scene/useScene.js.map +1 -1
- package/dist/{cornerHandles-p8fDIAKt.d.ts → cornerHandles-CNCb7aTY.d.ts} +1 -1
- package/dist/{depSchema-mG19aEdD.d.ts → depSchema-CpIQzKWQ.d.ts} +38 -59
- package/dist/devtools/handlers.js +1 -1
- package/dist/devtools/handlers.js.map +1 -1
- package/dist/devtools/protocol.js.map +1 -1
- package/dist/devtools-protocol.d.ts +4 -3
- package/dist/devtools.d.ts +3 -2
- package/dist/features/measure/measureHit.js +5 -3
- package/dist/features/measure/measureHit.js.map +1 -1
- package/dist/features/measure/measurement.js +1 -1
- package/dist/features/measure/measurement.js.map +1 -1
- package/dist/features/modes/modeLayers.js +14 -7
- package/dist/features/modes/modeLayers.js.map +1 -1
- package/dist/features/modes/modeTriggers.js +3 -3
- package/dist/features/modes/modeTriggers.js.map +1 -1
- package/dist/features/pathEffects/effectSources.js +25 -16
- package/dist/features/pathEffects/effectSources.js.map +1 -1
- package/dist/features/pathEffects/readSource.js +1 -1
- package/dist/features/pathEffects/readSource.js.map +1 -1
- package/dist/features/pathEffects/useEffectSourcesLayer.js +15 -19
- package/dist/features/pathEffects/useEffectSourcesLayer.js.map +1 -1
- package/dist/features/paths/editablePath.js +1 -1
- package/dist/features/paths/editablePath.js.map +1 -1
- package/dist/features/paths/pathSnap/sceneIndex.js +1 -1
- package/dist/features/paths/pathSnap/sceneIndex.js.map +1 -1
- package/dist/features/selection/enteredGroupFrame.js +65 -0
- package/dist/features/selection/enteredGroupFrame.js.map +1 -0
- package/dist/features/selection/enteredGroupScope.js +44 -0
- package/dist/features/selection/enteredGroupScope.js.map +1 -0
- package/dist/features/text/sceneTextDrafts.js +26 -27
- package/dist/features/text/sceneTextDrafts.js.map +1 -1
- package/dist/features/text/textHitAt.js +4 -2
- package/dist/features/text/textHitAt.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +3 -3
- package/dist/features/text/useSceneTextEdit.js.map +1 -1
- package/dist/features/viewports/viewportLayer.js +2 -1
- package/dist/features/viewports/viewportLayer.js.map +1 -1
- package/dist/index.d.ts +230 -77
- package/dist/index.js +16 -6
- package/dist/interactions/actions/admitsChild.js +11 -0
- package/dist/interactions/actions/admitsChild.js.map +1 -0
- package/dist/interactions/actions/defaults/contextMenu.js +16 -3
- package/dist/interactions/actions/defaults/contextMenu.js.map +1 -1
- package/dist/interactions/actions/defaults/createPaintAction.js +4 -1
- package/dist/interactions/actions/defaults/createPaintAction.js.map +1 -1
- package/dist/interactions/actions/defaults/enterGroup.js +88 -0
- package/dist/interactions/actions/defaults/enterGroup.js.map +1 -0
- package/dist/interactions/actions/defaults/enterPathEdit.js +1 -1
- package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/enterTextEdit.js +1 -1
- package/dist/interactions/actions/defaults/enterTextEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/group.js +7 -7
- package/dist/interactions/actions/defaults/group.js.map +1 -1
- package/dist/interactions/actions/defaults/selectAll.js +7 -3
- package/dist/interactions/actions/defaults/selectAll.js.map +1 -1
- package/dist/interactions/actions/defaults/selectDeep.js +35 -0
- package/dist/interactions/actions/defaults/selectDeep.js.map +1 -0
- package/dist/interactions/actions/drawnBoxes.js +2 -1
- package/dist/interactions/actions/drawnBoxes.js.map +1 -1
- package/dist/interactions/actions/insert/action.js +1 -0
- package/dist/interactions/actions/insert/action.js.map +1 -1
- package/dist/interactions/actions/insert/parent.js +7 -5
- package/dist/interactions/actions/insert/parent.js.map +1 -1
- package/dist/interactions/actions/insert/placeAction.js +3 -2
- package/dist/interactions/actions/insert/placeAction.js.map +1 -1
- package/dist/interactions/actions/insert/session.js +2 -2
- package/dist/interactions/actions/insert/session.js.map +1 -1
- package/dist/interactions/actions/move/commit/reparent.js +1 -1
- package/dist/interactions/actions/move/commit/reparent.js.map +1 -1
- package/dist/interactions/actions/move/gestureAdapter.js +6 -7
- package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
- package/dist/interactions/actions/move/layout/exits.js +1 -1
- package/dist/interactions/actions/move/layout/exits.js.map +1 -1
- package/dist/interactions/actions/move/session.js +4 -4
- package/dist/interactions/actions/move/session.js.map +1 -1
- package/dist/interactions/actions/pathCommands/pathNodes.js +14 -5
- package/dist/interactions/actions/pathCommands/pathNodes.js.map +1 -1
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +14 -2
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
- package/dist/{math-B56zxVs5.d.ts → math-C_elShP_.d.ts} +2 -5
- package/dist/math.d.ts +1 -1
- package/dist/move.d.ts +4 -4
- package/dist/{options-DBxEryYq.d.ts → options-ClEm3SEl.d.ts} +1 -1
- package/dist/resize.d.ts +4 -4
- package/dist/test-seams.d.ts +6 -6
- package/dist/tools/builtin/pressTarget.js +22 -0
- package/dist/tools/builtin/pressTarget.js.map +1 -0
- package/dist/tools/builtin/select/adapterPointQuery.js +3 -3
- package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
- package/dist/tools/builtin/select/collapseDeferred.js +40 -0
- package/dist/tools/builtin/select/collapseDeferred.js.map +1 -0
- package/dist/tools/builtin/select/groupEntry.js +82 -0
- package/dist/tools/builtin/select/groupEntry.js.map +1 -0
- package/dist/tools/builtin/select/pressDecision.js +1 -1
- package/dist/tools/builtin/select/pressDecision.js.map +1 -1
- package/dist/tools/builtin/select/useSelectTool.js +61 -45
- package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
- package/dist/{types-7puAuVD2.d.ts → types-49uYJN3j.d.ts} +1 -1
- package/dist/{types-CniVctmk.d.ts → types-BEdRIhNc.d.ts} +272 -109
- package/dist/{types-oFeQ5VjV.d.ts → types-p2alu-R1.d.ts} +1 -1
- package/dist/version.js +1 -1
- package/package.json +25 -25
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenePickIndex.js","names":[],"sources":["../../../src/canvas/pickIndex/scenePickIndex.ts"],"sourcesContent":["/**\n * The per-scene pick index: one BVH per scene layer over every node's broad\n * box (`nodeBroadBox`), keyed by the node's place in the render order it was\n * built from. A pick after anything it read can have changed walks the scene\n * and only records that state; the next pick to find the scene unchanged\n * builds, so a scene edited before every pick never pays for a build. Nodes it\n * cannot box conservatively are on `always` and are tested by every walk.\n */\nimport { createBvh, type Bvh } from '@weasel-js/geom/nd';\nimport { markerGeneration } from '@weasel-js/stroke';\nimport { getNodeShapes } from 'canvas/NodeShape';\nimport { inheritedPaintOf, inheritsPaint } from 'core/scene/inheritedPaint';\nimport { nodesAsShown } from 'core/scene/nodeAsShown';\nimport { nodeMemoGeneration } from 'core/scene/nodeMemo';\nimport type { Scene } from 'core/scene/types';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport { scenePaintedPoseOf } from '../derivedPath';\nimport type { PickBroad, PickCandidate } from '../pickWalk';\nimport { sceneParentsOf, sceneShownPathOf } from '../scenePickReads';\nimport { nodeBroadBox, type Box2 } from './nodeBroadBox';\n\ntype AnyScene = Scene<unknown, string, unknown>;\ntype Order = readonly PickCandidate<unknown>[];\n\nexport interface ScenePickIndex {\n /** The layers holding indexed nodes; `undefined` for nodes with none. */\n readonly layers: readonly (string | undefined)[];\n readonly maxOutsetPx: number;\n}\n\nlet builds = 0;\n\n/** How many indexes have been built, for tests that pin when one rebuilds. */\nexport function pickIndexBuildCount(): number {\n return builds;\n}\n\ninterface Cached {\n version: number;\n overrides: number;\n memo: number;\n markers: number;\n /** Null until a second pick finds the same state. */\n index: BuiltIndex | null;\n}\n\nconst CACHE = new WeakMap<object, WeakMap<PoseDescriptor<unknown>, Cached>>();\n\n/** Past this share of the scene the index costs more than the walk it narrows. */\nconst MAX_SHARE = 0.5;\n\nclass BuiltIndex implements ScenePickIndex {\n readonly layers: readonly (string | undefined)[];\n /** The render order the candidates are read out of. */\n private order: Order;\n /** Build position to position in `order`, or null while they are the same array. */\n private remap: Int32Array | null = null;\n private readonly marks: Uint8Array;\n private found: Int32Array;\n\n constructor(\n private readonly built: Order,\n private readonly trees: Map<string | undefined, Bvh<number>>,\n private readonly always: Int32Array,\n readonly maxOutsetPx: number,\n ) {\n this.layers = [...trees.keys()];\n this.order = built;\n this.marks = new Uint8Array(built.length);\n this.found = new Int32Array(Math.max(16, always.length));\n }\n\n /** Follow a new render order array the scene hands back for the same state. */\n rankBy(order: Order): void {\n if (order === this.order) return;\n this.order = order;\n if (order === this.built) {\n this.remap = null;\n return;\n }\n const rank = new Map<string, number>();\n for (let i = 0; i < order.length; i++) rank.set(order[i].id, i);\n const remap = new Int32Array(this.built.length);\n for (let i = 0; i < remap.length; i++) remap[i] = rank.get(this.built[i].id) ?? -1;\n this.remap = remap;\n }\n\n /** The nodes the boxes reach, in render order, or null when that is most of the scene. */\n candidates(broads: readonly (PickBroad | null)[]): Order | null {\n const limit = Math.floor(this.order.length * MAX_SHARE);\n let count = 0;\n const add = (built: number): boolean => {\n const at = this.remap === null ? built : this.remap[built];\n if (at < 0) return true;\n if (count === this.found.length) {\n const next = new Int32Array(count * 2);\n next.set(this.found);\n this.found = next;\n }\n this.found[count++] = at;\n return count <= limit;\n };\n for (const i of this.always) if (!add(i)) return null;\n for (let l = 0; l < this.layers.length; l++) {\n const broad = broads[l];\n const tree = this.trees.get(this.layers[l]);\n if (broad === null || tree === undefined) continue;\n const { x, y, width, height } = broad.box;\n const k = broad.pxPerWorld;\n const by = this.maxOutsetPx > 0 && k !== undefined ? (k > 0 ? this.maxOutsetPx / k : Infinity) : 0;\n let over = false;\n tree.queryBox([x - by, y - by, x + width + by, y + height + by], (i) => {\n if (add(i)) return true;\n over = true;\n return false;\n });\n if (over) return null;\n }\n return this.readOut(count);\n }\n\n private readOut(count: number): Order {\n const { order, found } = this;\n const out: PickCandidate<unknown>[] = new Array(count);\n // A handful sorts faster than a pass over every mark.\n if (count * 32 < order.length) {\n const ranks = found.subarray(0, count).sort();\n for (let i = 0; i < count; i++) out[i] = order[ranks[i]];\n return out;\n }\n const marks = this.marks.length >= order.length ? this.marks : new Uint8Array(order.length);\n for (let i = 0; i < count; i++) marks[found[i]] = 1;\n let n = 0;\n for (let i = 0; n < count && i < order.length; i++) {\n if (marks[i] === 0) continue;\n marks[i] = 0;\n out[n++] = order[i];\n }\n return out;\n }\n}\n\nfunction hasCopyingAncestor(parents: Order): boolean {\n return parents.some((p) => typeof p.copiesFromPose === 'function');\n}\n\nfunction build(scene: AnyScene, descriptor: PoseDescriptor<unknown>, order: Order): BuiltIndex {\n builds++;\n const poseOf = scenePaintedPoseOf(scene);\n const pathOf = sceneShownPathOf(scene);\n const parentsOf = sceneParentsOf(scene);\n const entries = new Map<string | undefined, [number, Box2][]>();\n const always: number[] = [];\n let maxOutsetPx = 0;\n for (let i = 0; i < order.length; i++) {\n const node = order[i];\n const parents = parentsOf(node);\n // Also hit wherever an ancestor paints a copy of it, which its own box does not cover.\n if (hasCopyingAncestor(parents)) {\n always.push(i);\n continue;\n }\n const box: Box2 = [0, 0, 0, 0];\n let outsetPx: number;\n try {\n const inherited = inheritsPaint(node) ? inheritedPaintOf(node, parents) : undefined;\n outsetPx = nodeBroadBox(node, poseOf(node as never), pathOf(node), inherited, descriptor, box);\n } catch {\n always.push(i);\n continue;\n }\n if (!Number.isFinite(outsetPx) || !box.every(Number.isFinite)) {\n always.push(i);\n continue;\n }\n if (outsetPx > maxOutsetPx) maxOutsetPx = outsetPx;\n let list = entries.get(node.layer);\n if (list === undefined) entries.set(node.layer, (list = []));\n list.push([i, box]);\n }\n const trees = new Map<string | undefined, Bvh<number>>();\n for (const [layer, list] of entries) {\n const tree = createBvh<number>(2, list);\n // The tree drops an inverted box: test that node the old way.\n if (tree.size !== list.length) {\n for (const [i, box] of list) if (!(box[0] <= box[2] && box[1] <= box[3])) always.push(i);\n }\n trees.set(layer, tree);\n }\n return new BuiltIndex(order, trees, Int32Array.from(always), maxOutsetPx);\n}\n\n/** The index for `scene` read through `descriptor`, or null when this pick walks instead. */\nexport function scenePickIndex(scene: AnyScene, descriptor: PoseDescriptor<unknown>): ScenePickIndex | null {\n return current(scene, descriptor);\n}\n\nfunction current(scene: AnyScene, descriptor: PoseDescriptor<unknown>): BuiltIndex | null {\n // Registers the built-in painters first, which bumps the memo generation.\n getNodeShapes();\n const version = scene.getVersion();\n const overrides = scene.overrides.getGeneration();\n const memo = nodeMemoGeneration();\n const markers = markerGeneration();\n let perScene = CACHE.get(scene);\n if (perScene === undefined) CACHE.set(scene, (perScene = new WeakMap()));\n const hit = perScene.get(descriptor);\n // Boxed as shown, so a data override that grows a node's ink is met where it is painted.\n const order = nodesAsShown(scene.overrides, scene.renderOrderNodes()) as unknown as Order;\n if (hit && hit.version === version && hit.overrides === overrides && hit.memo === memo && hit.markers === markers) {\n if (hit.index === null) hit.index = build(scene, descriptor, order);\n else hit.index.rankBy(order);\n return hit.index;\n }\n perScene.set(descriptor, { version, overrides, memo, markers, index: null });\n return null;\n}\n\n/** What `PickSource.candidates` answers for a scene source with an index. */\nexport function indexedCandidates(\n scene: AnyScene,\n descriptor: PoseDescriptor<unknown>,\n broadFor: (layer: string | undefined) => PickBroad | null | undefined,\n): Order | null {\n const index = current(scene, descriptor);\n if (index === null) return null;\n const broads: (PickBroad | null)[] = [];\n for (const layer of index.layers) {\n const broad = broadFor(layer);\n if (broad === undefined) return null;\n if (broad !== null && Number.isNaN(broad.box.x + broad.box.y + broad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,SAAS,KAAK;EAC5B,IAAI,UAAU,QAAW,OAAO;EAChC,IAAI,UAAU,QAAQ,OAAO,MAAM,MAAM,IAAI,IAAI,MAAM,IAAI,IAAI,MAAM,IAAI,QAAQ,MAAM,IAAI,MAAM,GAAG,OAAO;EAC3G,OAAO,KAAK,KAAK;CACnB;CACA,OAAO,MAAM,WAAW,MAAM;AAChC"}
|
package/dist/canvas/pickWalk.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { planeMap } from "../core/viewport/parallax.js";
|
|
2
|
-
import { resolveDerivedPath } from "../core/scene/derivedPath.js";
|
|
3
1
|
import { inheritedPaintOf, inheritsPaint } from "../core/scene/inheritedPaint.js";
|
|
4
|
-
import { findShapeSilhouette } from "./NodeShape.js";
|
|
5
2
|
import { clipCarrier } from "./planeClips.js";
|
|
6
|
-
import {
|
|
7
|
-
import { annotationLayerIds } from "../core/scene/annotation.js";
|
|
8
|
-
import { nodeGates } from "../core/scene/nodeGates.js";
|
|
9
|
-
import { sceneDerivedPathOf, scenePaintedPoseOf, showsComputedPath } from "./derivedPath.js";
|
|
3
|
+
import { ownClipOf } from "./ownClip.js";
|
|
10
4
|
import { reaches } from "./pickReach.js";
|
|
5
|
+
import { scenePickSource, scenePlaneOf } from "./scenePickSource.js";
|
|
11
6
|
import { adapterPickSource } from "./adapterPickSource.js";
|
|
12
7
|
import { invert } from "@weasel-js/geom";
|
|
13
8
|
|
|
@@ -17,7 +12,7 @@ import { invert } from "@weasel-js/geom";
|
|
|
17
12
|
* query supplies only the shape test and the clip predicate for its own region.
|
|
18
13
|
*
|
|
19
14
|
* The gates, in the order the walk applies them:
|
|
20
|
-
* 1.
|
|
15
|
+
* 1. groups, when the query does not want them
|
|
21
16
|
* 2. the node is painted at all — not hidden in the scene (`nodeGates`),
|
|
22
17
|
* and on a layer the asking view's `layerVisibility` / `layerOrder` paints
|
|
23
18
|
* 3. painted alpha is above zero
|
|
@@ -29,20 +24,12 @@ import { invert } from "@weasel-js/geom";
|
|
|
29
24
|
* that skips one answers for a node the user cannot see. 4 is the other axis:
|
|
30
25
|
* a locked node is on screen and still out of reach.
|
|
31
26
|
*/
|
|
32
|
-
/** Shared, never mutated: most scenes are flat and every node returns it. */
|
|
33
|
-
var EMPTY_PARENTS = [];
|
|
34
|
-
/** The clip a container imposes on its subtree, or null when it imposes none. */
|
|
35
|
-
function ownClipOf(node, pose, derived) {
|
|
36
|
-
if (node.kind !== "container") return null;
|
|
37
|
-
if (typeof node.clipFromPose === "function") return node.clipFromPose(pose);
|
|
38
|
-
return findShapeSilhouette(node, pose, { derivedPath: derived });
|
|
39
|
-
}
|
|
40
27
|
/**
|
|
41
28
|
* Collect every candidate the query hits, back-to-front — the last element is
|
|
42
29
|
* the topmost, which is the order `pickTopMostHit` expects.
|
|
43
30
|
*/
|
|
44
31
|
function pickWalk(src, q) {
|
|
45
|
-
const
|
|
32
|
+
const includeGroups = q.includeGroups ?? true;
|
|
46
33
|
const isLocked = q.includeLocked === true ? void 0 : src.isLocked;
|
|
47
34
|
const out = [];
|
|
48
35
|
const clipPath = /* @__PURE__ */ new Map();
|
|
@@ -50,7 +37,7 @@ function pickWalk(src, q) {
|
|
|
50
37
|
const clipOf = (ancestor) => {
|
|
51
38
|
const cached = clipPath.get(ancestor.id);
|
|
52
39
|
if (cached !== void 0) return cached;
|
|
53
|
-
const resolved = ownClipOf(ancestor, src.poseOf(ancestor), src.derivedPathOf?.(ancestor));
|
|
40
|
+
const resolved = ownClipOf(ancestor, src.poseOf(ancestor), () => src.derivedPathOf?.(ancestor));
|
|
54
41
|
clipPath.set(ancestor.id, resolved);
|
|
55
42
|
return resolved;
|
|
56
43
|
};
|
|
@@ -58,7 +45,7 @@ function pickWalk(src, q) {
|
|
|
58
45
|
const copiesOf = (ancestor) => {
|
|
59
46
|
let found = copyMaps.get(ancestor.id);
|
|
60
47
|
if (found === void 0) {
|
|
61
|
-
const fn = ancestor.
|
|
48
|
+
const fn = ancestor.copiesFromPose;
|
|
62
49
|
found = (fn ? fn(src.poseOf(ancestor), ancestor) ?? [] : []).map(invert).filter((m) => m !== null);
|
|
63
50
|
copyMaps.set(ancestor.id, found);
|
|
64
51
|
}
|
|
@@ -76,9 +63,13 @@ function pickWalk(src, q) {
|
|
|
76
63
|
return found;
|
|
77
64
|
};
|
|
78
65
|
const order = src.order();
|
|
79
|
-
const copying = order.some((n) =>
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
const copying = order.some((n) => typeof n.copiesFromPose === "function");
|
|
67
|
+
const visit = (q.broad !== void 0 ? src.candidates?.((layer) => {
|
|
68
|
+
const query = queryFor(layer);
|
|
69
|
+
return query === null ? null : query.broad;
|
|
70
|
+
}) : null) ?? order;
|
|
71
|
+
for (const node of visit) {
|
|
72
|
+
if (!includeGroups && node.kind === "group") continue;
|
|
82
73
|
if (node.pickable === false) continue;
|
|
83
74
|
if (src.isHidden?.(node) === true) continue;
|
|
84
75
|
if (node.layer !== void 0 && src.layerIsPainted?.(node.layer) === false) continue;
|
|
@@ -98,74 +89,7 @@ function pickWalk(src, q) {
|
|
|
98
89
|
}
|
|
99
90
|
return out;
|
|
100
91
|
}
|
|
101
|
-
function scenePickSource(scene, opts = {}) {
|
|
102
|
-
const gates = nodeGates(scene);
|
|
103
|
-
const annotations = annotationLayerIds(scene.layers);
|
|
104
|
-
const { getPose, alphaOf, layerIsPainted } = opts;
|
|
105
|
-
let faded = null;
|
|
106
|
-
const enumerable = typeof scene.overrides?.ids === "function";
|
|
107
|
-
if (!alphaOf && enumerable) for (const id of scene.overrides.ids()) {
|
|
108
|
-
const a = scene.overrides.read(id)?.alpha;
|
|
109
|
-
if (a !== void 0 && a <= 0) (faded ??= /* @__PURE__ */ new Set()).add(id);
|
|
110
|
-
}
|
|
111
|
-
const readAlpha = alphaOf ?? (enumerable ? faded ? (id) => faded.has(id) ? 0 : 1 : void 0 : (id) => scene.overrides.read(asNodeId(id))?.alpha ?? 1);
|
|
112
|
-
const paintedPoseOf = scenePaintedPoseOf(scene);
|
|
113
|
-
const poseOf = getPose ? (node) => getPose(node.id) : (node) => paintedPoseOf(node);
|
|
114
|
-
const childrenOf = (id) => scene.childrenOf(id);
|
|
115
|
-
const depOf = (id) => {
|
|
116
|
-
const dep = scene.get(id);
|
|
117
|
-
if (dep === void 0) return void 0;
|
|
118
|
-
return {
|
|
119
|
-
node: dep,
|
|
120
|
-
pose: poseOf(dep),
|
|
121
|
-
get path() {
|
|
122
|
-
return resolveDerivedPath(dep, depOf, childrenOf);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
const sceneDerivedPath = getPose ? null : sceneDerivedPathOf(scene);
|
|
127
|
-
const derivedPathOf = (node) => {
|
|
128
|
-
const n = node;
|
|
129
|
-
if (!sceneDerivedPath) return n.dependsOn === void 0 ? null : resolveDerivedPath(n, depOf, childrenOf);
|
|
130
|
-
return showsComputedPath(scene, n) ? sceneDerivedPath(n) : null;
|
|
131
|
-
};
|
|
132
|
-
const planeOf = opts.camera ? scenePlaneOf(scene.layers, opts.camera) : null;
|
|
133
|
-
return {
|
|
134
|
-
...planeOf ? { planeOf } : {},
|
|
135
|
-
order: () => scene.renderOrderNodes(),
|
|
136
|
-
derivedPathOf,
|
|
137
|
-
poseOf,
|
|
138
|
-
parentsOf(node) {
|
|
139
|
-
let parentId = node.parent ?? null;
|
|
140
|
-
if (parentId === null) return EMPTY_PARENTS;
|
|
141
|
-
const chain = [];
|
|
142
|
-
const seen = /* @__PURE__ */ new Set();
|
|
143
|
-
while (parentId !== null) {
|
|
144
|
-
if (seen.has(parentId)) break;
|
|
145
|
-
seen.add(parentId);
|
|
146
|
-
const parent = scene.get(asNodeId(parentId));
|
|
147
|
-
if (!parent) break;
|
|
148
|
-
chain.push(parent);
|
|
149
|
-
parentId = parent.parent ?? null;
|
|
150
|
-
}
|
|
151
|
-
return chain;
|
|
152
|
-
},
|
|
153
|
-
...readAlpha ? { alphaOf: readAlpha } : {},
|
|
154
|
-
isLocked: (node) => gates.locked(node.id),
|
|
155
|
-
isHidden: (node) => gates.hidden(node.id),
|
|
156
|
-
...annotations.size > 0 || layerIsPainted ? { layerIsPainted: (layer) => !annotations.has(layer) && (layerIsPainted === void 0 || layerIsPainted(layer)) } : {}
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
/** Each parallax layer's plane map under `camera`, or null when no layer is a
|
|
160
|
-
* plane — which keeps the per-layer lookup off the walk entirely. */
|
|
161
|
-
function scenePlaneOf(layers, camera) {
|
|
162
|
-
let maps = null;
|
|
163
|
-
for (const l of layers ?? []) if (l.parallax) (maps ??= /* @__PURE__ */ new Map()).set(l.id, planeMap(camera, l.parallax));
|
|
164
|
-
if (maps === null) return null;
|
|
165
|
-
const found = maps;
|
|
166
|
-
return (layer) => found.get(layer) ?? null;
|
|
167
|
-
}
|
|
168
92
|
|
|
169
93
|
//#endregion
|
|
170
|
-
export { adapterPickSource,
|
|
94
|
+
export { adapterPickSource, pickWalk, scenePickSource, scenePlaneOf };
|
|
171
95
|
//# sourceMappingURL=pickWalk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pickWalk.js","names":[],"sources":["../../src/canvas/pickWalk.ts"],"sourcesContent":["/**\n * The one hit-test walk. Everything that decides whether a node *can* be hit lives here; a\n * query supplies 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 node is painted at all — not hidden in the scene (`nodeGates`),\n * and on a layer the asking view's `layerVisibility` / `layerOrder` paints\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 { invert, type Affine, type Path } from '@weasel-js/geom';\nimport { findShapeSilhouette } from 'canvas/NodeShape';\nimport type { ClipFromPoseFn, CopiesFromPoseFn, DerivedDep, Node, NodeId, Scene } from 'core/scene/types';\nimport { asNodeId } from 'core/scene/types';\nimport { annotationLayerIds } from 'core/scene/annotation';\nimport { nodeGates } from 'core/scene/nodeGates';\nimport { inheritedPaintOf, inheritsPaint, type InheritedPaint } from 'core/scene/inheritedPaint';\nimport { resolveDerivedPath, sceneDerivedPathOf, scenePaintedPoseOf, showsComputedPath } from './derivedPath';\nimport { planeMap, type ParallaxOpts, type PlaneMap } from 'core/viewport/parallax';\nimport type { View } from 'core/viewport/view';\nimport { clipCarrier } from './planeClips';\nimport { reaches } from './pickReach';\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 /** Read for an `'inherit'` fill or stroke, which takes its containers'. */\n data?: unknown;\n clipFromPose?: ClipFromPoseFn<TPose>;\n copiesFromPose?: CopiesFromPoseFn<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 /** Whether the source hides the node, so nothing of it is on screen. Omit\n * for a source that hides nothing. */\n isHidden?(node: PickCandidate<TPose>): boolean;\n /** The path a node computes from its dependencies, or null for none. */\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. `inherited` is what its `'inherit'` fields take from its\n * containers, for the ink it is tested against; absent when it inherits\n * nothing. */\n hits(node: PickCandidate<TPose>, pose: TPose, derived?: Path | null, inherited?: InheritedPaint): 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 /** The same question carried by `m`, an affine from world into the source\n * frame of a copy a container draws. A query without it cannot reach\n * copies — see `ContainerNode.copiesFromPose`. */\n inCopy?(m: Affine): 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 is the expensive half, so the *path* is memoized per\n // container for the walk. The predicate re-runs per candidate: caching its answer per\n // 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 const copyMaps = new Map<string, readonly Affine[]>();\n const copiesOf = (ancestor: PickCandidate<TPose>): readonly Affine[] => {\n let found = copyMaps.get(ancestor.id);\n if (found === undefined) {\n const fn = ancestor.kind === 'container' ? ancestor.copiesFromPose : undefined;\n const copies = fn ? fn(src.poseOf(ancestor), ancestor as never) ?? [] : [];\n found = copies.map(invert).filter((m): m is Affine => m !== null);\n copyMaps.set(ancestor.id, found);\n }\n return found;\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 const order = src.order();\n const copying = order.some((n) => n.kind === 'container' && typeof n.copiesFromPose === 'function');\n for (const node of 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 (src.isHidden?.(node) === true) 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 const inherited = inheritsPaint(node) ? inheritedPaintOf(node, src.parentsOf(node)) : undefined;\n if (!reaches(node, pose, derived, inherited, query, () => src.parentsOf(node), copying, { clipOf, copiesOf, carry })) continue;\n out.push(node.id);\n }\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 /** 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 // Partial scene stand-ins carry only `layers` and `get`, which is all the gates read.\n const gates = nodeGates(scene as never);\n const annotations = annotationLayerIds(scene.layers);\n const { getPose, alphaOf, layerIsPainted } = opts;\n\n // Resolved once per walk rather than once per candidate. Needs enumeration — a\n // partial scene stand-in carrying 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 paintedPoseOf = scenePaintedPoseOf(scene);\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);\n const derivedPathOf = (node: PickCandidate<TPose>): Path | null => {\n const n = node as unknown as Node<TData, TLayer, TPose>;\n if (!sceneDerivedPath) return n.dependsOn === undefined ? null : resolveDerivedPath(n, depOf, childrenOf);\n return showsComputedPath(scene, n) ? sceneDerivedPath(n) : null;\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 isLocked: (node: PickCandidate<TPose>) => gates.locked(node.id),\n isHidden: (node: PickCandidate<TPose>) => gates.hidden(node.id),\n ...(annotations.size > 0 || layerIsPainted\n ? {\n layerIsPainted: (layer: string) =>\n !annotations.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\nexport { adapterPickSource } from './adapterPickSource';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,gBAAkC,CAAC;;AA6FzC,SAAgB,UACd,MACA,MACA,SACa;CACb,IAAI,KAAK,SAAS,aAAa,OAAO;CACtC,IAAI,OAAO,KAAK,iBAAiB,YAAY,OAAO,KAAK,aAAa,IAAI;CAC1E,OAAO,oBACL,MACA,MACA,EAAE,aAAa,QAAQ,CACzB;AACF;;;;;AAMA,SAAgB,SACd,KACA,GACU;CACV,MAAM,oBAAoB,EAAE,qBAAqB;CACjD,MAAM,WAAW,EAAE,kBAAkB,OAAO,SAAY,IAAI;CAC5D,MAAM,MAAgB,CAAC;CAKvB,MAAM,2BAAW,IAAI,IAAyB;CAE9C,MAAM,QAAQ,YAAY,IAAI,WAAW,IAAI;CAE7C,MAAM,UAAU,aAAgD;EAC9D,MAAM,SAAS,SAAS,IAAI,SAAS,EAAE;EACvC,IAAI,WAAW,QAAW,OAAO;EACjC,MAAM,WAAW,UACf,UAAU,IAAI,OAAO,QAAQ,GAAG,IAAI,gBAAgB,QAAQ,CAC9D;EACA,SAAS,IAAI,SAAS,IAAI,QAAQ;EAClC,OAAO;CACT;CAEA,MAAM,2BAAW,IAAI,IAA+B;CACpD,MAAM,YAAY,aAAsD;EACtE,IAAI,QAAQ,SAAS,IAAI,SAAS,EAAE;EACpC,IAAI,UAAU,QAAW;GACvB,MAAM,KAAK,SAAS,SAAS,cAAc,SAAS,iBAAiB;GAErE,SADe,KAAK,GAAG,IAAI,OAAO,QAAQ,GAAG,QAAiB,KAAK,CAAC,IAAI,CAAC,EACjE,CAAO,IAAI,MAAM,CAAC,CAAC,QAAQ,MAAmB,MAAM,IAAI;GAChE,SAAS,IAAI,SAAS,IAAI,KAAK;EACjC;EACA,OAAO;CACT;CAIA,MAAM,+BAAe,IAAI,IAAqC;CAC9D,MAAM,YAAY,UAAuD;E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GACd,IAAI,WAAY,KAAoC,UAAU;GAC9D,IAAI,aAAa,MAAM,OAAO;GAC9B,MAAM,QAAgC,CAAC;GACvC,MAAM,uBAAO,IAAI,IAAY;GAC7B,OAAO,aAAa,MAAM;IACxB,IAAI,KAAK,IAAI,QAAQ,GAAG;IACxB,KAAK,IAAI,QAAQ;IACjB,MAAM,SAAS,MAAM,IAAI,SAAS,QAAQ,CAAC;IAC3C,IAAI,CAAC,QAAQ;IACb,MAAM,KAAK,MAAyC;IACpD,WAAW,OAAO,UAAU;GAC9B;GACA,OAAO;EACT;EAEA,GAAI,YAAY,EAAE,SAAS,UAAU,IAAI,CAAC;EAC1C,WAAW,SAA+B,MAAM,OAAO,KAAK,EAAE;EAC9D,WAAW,SAA+B,MAAM,OAAO,KAAK,EAAE;EAC9D,GAAI,YAAY,OAAO,KAAK,iBACxB,EACA,iBAAiB,UACf,CAAC,YAAY,IAAI,KAAK,MAAM,mBAAmB,UAAa,eAAe,KAAK,GACpF,IACE,CAAC;CACP;AACF;;;AAIA,SAAgB,aACd,QACA,QAC6C;CAC7C,IAAI,OAAqC;CACzC,KAAK,MAAM,KAAK,UAAU,CAAC,GACzB,IAAI,EAAE,UAAU,CAAC,yBAAS,IAAI,IAAI,EAAA,CAAG,IAAI,EAAE,IAAI,SAAS,QAAQ,EAAE,QAAQ,CAAC;CAE7E,IAAI,SAAS,MAAM,OAAO;CAC1B,MAAM,QAAQ;CACd,QAAQ,UAAU,MAAM,IAAI,KAAK,KAAK;AACxC"}
|
|
1
|
+
{"version":3,"file":"pickWalk.js","names":[],"sources":["../../src/canvas/pickWalk.ts"],"sourcesContent":["/**\n * The one hit-test walk. Everything that decides whether a node *can* be hit lives here; a\n * query supplies 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. groups, when the query does not want them\n * 2. the node is painted at all — not hidden in the scene (`nodeGates`),\n * and on a layer the asking view's `layerVisibility` / `layerOrder` paints\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 { invert, type Affine, type Path } from '@weasel-js/geom';\nimport type { CopiesFromPoseFn } from 'core/scene/types';\nimport { ownClipOf, type ClipBearing } from './ownClip';\nimport { inheritedPaintOf, inheritsPaint, type InheritedPaint } from 'core/scene/inheritedPaint';\nimport { rectToPlane, type PlaneMap } from 'core/viewport/parallax';\nimport { clipCarrier } from './planeClips';\nimport { reaches } from './pickReach';\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> extends ClipBearing<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 /** Read for an `'inherit'` fill or stroke, which takes its containers'. */\n data?: unknown;\n copiesFromPose?: CopiesFromPoseFn<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 /** Whether the source hides the node, so nothing of it is on screen. Omit\n * for a source that hides nothing. */\n isHidden?(node: PickCandidate<TPose>): boolean;\n /** The path a node computes from its dependencies, or null for none. */\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 * The candidates a query with these broad boxes can hit, back-to-front: a\n * subset of `order()` that drops only nodes no query inside the box could\n * hit. `broadFor(layer)` is the box for that layer's query: `null` for a\n * layer it cannot reach, `undefined` for one with no box, which makes this\n * answer `null` and the walk visit `order()`. Omit for a source with no index.\n */\n candidates?(\n broadFor: (layer: string | undefined) => PickBroad | null | undefined,\n ): readonly PickCandidate<TPose>[] | null;\n}\n\n/** The box a query cannot hit outside of, for a source's index to look up. */\nexport interface PickBroad {\n /** World box, already grown by the query's own slop. */\n box: { x: number; y: number; width: number; height: number };\n /** Screen px per world unit at the asking view (least axis); grows the box\n * by the largest `outsetPx` the index holds. Omit for a query whose test\n * reads no `outsetPx`. */\n pxPerWorld?: number;\n}\n\n/** `broad` carried into a plane's world, as `inPlane` carries the query. */\nexport function broadInPlane(broad: PickBroad, m: PlaneMap): PickBroad {\n const box = rectToPlane(m, broad.box);\n if (broad.pxPerWorld === undefined) return { box };\n // A plane's pixel is the same on screen, so its world unit holds fewer of them.\n const k = Math.max(Math.abs(m.scale.x), Math.abs(m.scale.y));\n return { box, pxPerWorld: broad.pxPerWorld / k };\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 groups so a marquee does not\n * return a group and its members both. */\n includeGroups?: 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 /** Where the query can hit at all, for a source with an index. `inPlane`\n * carries it with the query; without it the walk visits every node. */\n broad?: PickBroad;\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. `inherited` is what its `'inherit'` fields take from its\n * containers, for the ink it is tested against; absent when it inherits\n * nothing. */\n hits(node: PickCandidate<TPose>, pose: TPose, derived?: Path | null, inherited?: InheritedPaint): 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 /** The same question carried by `m`, an affine from world into the source\n * frame of a copy a container draws. A query without it cannot reach\n * copies — see `GroupNode.copiesFromPose`. */\n inCopy?(m: Affine): PickQuery<TPose>;\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 includeGroups = q.includeGroups ?? true;\n const isLocked = q.includeLocked === true ? undefined : src.isLocked;\n const out: string[] = [];\n\n // Resolving a container's clip is the expensive half, so the *path* is memoized per\n // container for the walk. The predicate re-runs per candidate: caching its answer per\n // 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 const copyMaps = new Map<string, readonly Affine[]>();\n const copiesOf = (ancestor: PickCandidate<TPose>): readonly Affine[] => {\n let found = copyMaps.get(ancestor.id);\n if (found === undefined) {\n const fn = ancestor.copiesFromPose;\n const copies = fn ? fn(src.poseOf(ancestor), ancestor as never) ?? [] : [];\n found = copies.map(invert).filter((m): m is Affine => m !== null);\n copyMaps.set(ancestor.id, found);\n }\n return found;\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 const order = src.order();\n const copying = order.some((n) => typeof n.copiesFromPose === 'function');\n const visit = (q.broad !== undefined ? src.candidates?.((layer) => {\n const query = queryFor(layer);\n return query === null ? null : query.broad;\n }) : null) ?? order;\n for (const node of visit) {\n if (!includeGroups && node.kind === 'group') 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 (src.isHidden?.(node) === true) 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 const inherited = inheritsPaint(node) ? inheritedPaintOf(node, src.parentsOf(node)) : undefined;\n if (!reaches(node, pose, derived, inherited, query, () => src.parentsOf(node), copying, { clipOf, copiesOf, carry })) continue;\n out.push(node.id);\n }\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 { scenePickSource, scenePlaneOf, type ScenePickSourceOptions } from './scenePickSource';\nexport { adapterPickSource } from './adapterPickSource';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuJA,SAAgB,SACd,KACA,GACU;CACV,MAAM,gBAAgB,EAAE,iBAAiB;CACzC,MAAM,WAAW,EAAE,kBAAkB,OAAO,SAAY,IAAI;CAC5D,MAAM,MAAgB,CAAC;CAKvB,MAAM,2BAAW,IAAI,IAAyB;CAE9C,MAAM,QAAQ,YAAY,IAAI,WAAW,IAAI;CAE7C,MAAM,UAAU,aAAgD;EAC9D,MAAM,SAAS,SAAS,IAAI,SAAS,EAAE;EACvC,IAAI,WAAW,QAAW,OAAO;EACjC,MAAM,WAAW,UACf,UAAU,IAAI,OAAO,QAAQ,SAAS,IAAI,gBAAgB,QAAQ,CACpE;EACA,SAAS,IAAI,SAAS,IAAI,QAAQ;EAClC,OAAO;CACT;CAEA,MAAM,2BAAW,IAAI,IAA+B;CACpD,MAAM,YAAY,aAAsD;EACtE,IAAI,QAAQ,SAAS,IAAI,SAAS,EAAE;EACpC,IAAI,UAAU,QAAW;GACvB,MAAM,KAAK,SAAS;GAEpB,SADe,KAAK,GAAG,IAAI,OAAO,QAAQ,GAAG,QAAiB,KAAK,CAAC,IAAI,CAAC,EACjE,CAAO,IAAI,MAAM,CAAC,CAAC,QAAQ,MAAmB,MAAM,IAAI;GAChE,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GAAG,SAAS;GAAE;GAAQ;GAAU;EAAM,CAAC,GAAG;EACtH,IAAI,KAAK,KAAK,EAAE;CAClB;CAEA,OAAO;AACT"}
|
|
@@ -42,7 +42,7 @@ function containerCascade(scene, id, d, write) {
|
|
|
42
42
|
function cascadingSetPose(scene, d) {
|
|
43
43
|
return (id, pose) => {
|
|
44
44
|
const node = scene.get(id);
|
|
45
|
-
if (!node || node.kind !== "
|
|
45
|
+
if (!node || node.kind !== "group") return scene.setPose(id, pose);
|
|
46
46
|
const g = poseDescriptorForNode(d, node);
|
|
47
47
|
const from = g.getBounds(node.pose);
|
|
48
48
|
const to = g.getBounds(pose);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poseCascade.js","names":[],"sources":["../../src/canvas/poseCascade.ts"],"sourcesContent":["import { poseDescriptorForNode, translatePoseViaDescriptor, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport type { NodeId } from 'core/scene/types';\nimport type { PoseCascade } from '../animation/poseTarget';\n\n/** The part of a scene a container's cascade reads. */\ninterface CascadeScene<TPose> {\n get(id: NodeId): { pose: TPose; kind?: '
|
|
1
|
+
{"version":3,"file":"poseCascade.js","names":[],"sources":["../../src/canvas/poseCascade.ts"],"sourcesContent":["import { poseDescriptorForNode, translatePoseViaDescriptor, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport type { NodeId } from 'core/scene/types';\nimport type { PoseCascade } from '../animation/poseTarget';\n\n/** The part of a scene a container's cascade reads. */\ninterface CascadeScene<TPose> {\n get(id: NodeId): { pose: TPose; kind?: 'mark' | 'group' } | undefined;\n childrenOf(id: NodeId): readonly NodeId[];\n}\n\n/** The part of a scene a cascading `setPose` writes. */\ninterface CascadeTarget<TPose> extends CascadeScene<TPose> {\n setPose(id: NodeId, pose: TPose): void;\n batch<T>(label: string, fn: () => T): T;\n}\n\n/** Every node under `id`, each after its parent. */\nexport function descendantsOf(scene: Pick<CascadeScene<unknown>, 'childrenOf'>, id: NodeId): NodeId[] {\n const out: NodeId[] = [];\n const collect = (root: NodeId): void => {\n for (const child of scene.childrenOf(root)) {\n out.push(child);\n collect(child);\n }\n };\n collect(id);\n return out;\n}\n\n/**\n * How container `id`'s pose target carries its descendants where each holds a pose of its own\n * in the same space: `write` commits a pose and moves them, and while the container shows\n * somewhere else each is shown moved by as much.\n */\nexport function containerCascade<TPose>(\n scene: CascadeScene<TPose>,\n id: NodeId,\n d: PoseDescriptor<TPose>,\n write: (pose: TPose) => void,\n): PoseCascade<TPose> {\n return {\n write,\n *beside(pose) {\n const node = scene.get(id);\n if (!node) return;\n const g = poseDescriptorForNode(d, node);\n const from = g.getBounds(node.pose);\n const to = g.getBounds(pose);\n for (const child of descendantsOf(scene, id)) {\n const n = scene.get(child);\n if (!n) continue;\n yield [child, translatePoseViaDescriptor(n.pose, to.x - from.x, to.y - from.y, poseDescriptorForNode(d, n))];\n }\n },\n };\n}\n\n/**\n * `setPose` for a scene of absolute poses: posing a container moves every\n * descendant by as much, in one undo step.\n */\nexport function cascadingSetPose<TPose>(\n scene: CascadeTarget<TPose>,\n d: PoseDescriptor<TPose>,\n): (id: NodeId, pose: TPose) => void {\n return (id, pose) => {\n const node = scene.get(id);\n if (!node || node.kind !== 'group') return scene.setPose(id, pose);\n const g = poseDescriptorForNode(d, node);\n const from = g.getBounds(node.pose);\n const to = g.getBounds(pose);\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n if (dx === 0 && dy === 0) return scene.setPose(id, pose);\n scene.batch('move container', () => {\n scene.setPose(id, pose);\n for (const child of descendantsOf(scene, id)) {\n const n = scene.get(child);\n if (!n) continue;\n scene.setPose(child, translatePoseViaDescriptor(n.pose, dx, dy, poseDescriptorForNode(d, n)));\n }\n });\n };\n}\n"],"mappings":";;;;AAiBA,SAAgB,cAAc,OAAkD,IAAsB;CACpG,MAAM,MAAgB,CAAC;CACvB,MAAM,WAAW,SAAuB;EACtC,KAAK,MAAM,SAAS,MAAM,WAAW,IAAI,GAAG;GAC1C,IAAI,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AAI,IAAI,sBAAsB,GAAG,CAAC,CAAC,CAAC;GAC9F;EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { isPlainObject } from "@weasel-js/registry";
|
|
2
|
+
|
|
3
|
+
//#region src/canvas/publishPreviews.ts
|
|
4
|
+
/**
|
|
5
|
+
* `publishPreviews` — what in-flight handles propose, published to the scene.
|
|
6
|
+
*
|
|
7
|
+
* A handle answering `previewPose` / `previewData` shows its proposal in the
|
|
8
|
+
* preview ghost, which nothing else reads. Publishing it as the scene's pose
|
|
9
|
+
* and data overrides is what lets the scene's other readers see it: a path
|
|
10
|
+
* effect over a path whose anchors are being dragged, text laid along it, a
|
|
11
|
+
* second view of the same scene.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Publish every in-flight handle's `previewPose` and `previewData` to
|
|
15
|
+
* `scene`'s overrides each time `dispatcher` notifies, through one hold, and
|
|
16
|
+
* release them when the handles end. Returns the unsubscribe, which also
|
|
17
|
+
* releases what is still published.
|
|
18
|
+
*
|
|
19
|
+
* Previewed data is shown as the fields it changes from what the node stored
|
|
20
|
+
* when its preview began, laid over what the node stores now: a write made
|
|
21
|
+
* mid-gesture, or its undo, shows through, as it will be kept when the edit
|
|
22
|
+
* commits against the node as it then stands. Data that is not a plain
|
|
23
|
+
* object is shown as it is.
|
|
24
|
+
*
|
|
25
|
+
* A handle with `previewHidesSource: false` previews a copy rather than its
|
|
26
|
+
* source, so it is left out. On an id another writer's override already holds —
|
|
27
|
+
* a transform's own frame, a live route — the preview is a ply over it, so a
|
|
28
|
+
* field the handle does not propose shows what that writer says. The dispatcher
|
|
29
|
+
* notifies after a handle's `onEnd`, so a commit has landed before its preview
|
|
30
|
+
* goes.
|
|
31
|
+
*/
|
|
32
|
+
function publishPreviews(scene, dispatcher) {
|
|
33
|
+
const hold = scene.overrides.hold();
|
|
34
|
+
const shownData = /* @__PURE__ */ new Map();
|
|
35
|
+
const dataFor = (id, value) => {
|
|
36
|
+
const held = shownData.get(id);
|
|
37
|
+
if (held !== void 0 && held.value === value) return held.data;
|
|
38
|
+
const origin = held !== void 0 ? held.origin : scene.get(id)?.data;
|
|
39
|
+
const data = changesOver(origin, value);
|
|
40
|
+
shownData.set(id, {
|
|
41
|
+
origin,
|
|
42
|
+
value,
|
|
43
|
+
data
|
|
44
|
+
});
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
const publish = () => {
|
|
48
|
+
const frame = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const handle of dispatcher.getInFlightHandles()) {
|
|
50
|
+
if (handle.previewHidesSource === false) continue;
|
|
51
|
+
collect(handle, frame, (id) => scene.get(id) !== void 0, dataFor);
|
|
52
|
+
}
|
|
53
|
+
for (const id of shownData.keys()) if (frame.get(id)?.data === void 0) shownData.delete(id);
|
|
54
|
+
if (frame.size === 0) hold.drop();
|
|
55
|
+
else hold.show(frame);
|
|
56
|
+
};
|
|
57
|
+
const unsubscribe = dispatcher.subscribe(publish);
|
|
58
|
+
publish();
|
|
59
|
+
return () => {
|
|
60
|
+
unsubscribe();
|
|
61
|
+
hold.drop();
|
|
62
|
+
shownData.clear();
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** `(stored) => value`'s changes from `origin` laid over `stored`. */
|
|
66
|
+
function changesOver(origin, value) {
|
|
67
|
+
if (!isPlainObject(origin) || !isPlainObject(value)) return () => value;
|
|
68
|
+
const changed = /* @__PURE__ */ new Set();
|
|
69
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(origin), ...Object.keys(value)])) if (origin[key] !== value[key]) changed.add(key);
|
|
70
|
+
return (stored) => {
|
|
71
|
+
if (stored === origin || !isPlainObject(stored)) return value;
|
|
72
|
+
const out = { ...stored };
|
|
73
|
+
for (const key of changed) if (key in value) out[key] = value[key];
|
|
74
|
+
else delete out[key];
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** `handle`'s proposals into `frame`, first answer per id winning. */
|
|
79
|
+
function collect(handle, frame, exists, dataFor) {
|
|
80
|
+
const ids = handle.previewIds?.();
|
|
81
|
+
if (!ids) return;
|
|
82
|
+
for (const raw of ids) {
|
|
83
|
+
const id = raw;
|
|
84
|
+
if (frame.has(id) || !exists(id)) continue;
|
|
85
|
+
const pose = handle.previewPose?.(raw);
|
|
86
|
+
const data = handle.previewData?.(raw);
|
|
87
|
+
if (pose == null && data == null) continue;
|
|
88
|
+
frame.set(id, {
|
|
89
|
+
...pose == null ? {} : { pose },
|
|
90
|
+
...data == null ? {} : { data: dataFor(id, data) }
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { publishPreviews };
|
|
97
|
+
//# sourceMappingURL=publishPreviews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publishPreviews.js","names":[],"sources":["../../src/canvas/publishPreviews.ts"],"sourcesContent":["/**\n * `publishPreviews` — what in-flight handles propose, published to the scene.\n *\n * A handle answering `previewPose` / `previewData` shows its proposal in the\n * preview ghost, which nothing else reads. Publishing it as the scene's pose\n * and data overrides is what lets the scene's other readers see it: a path\n * effect over a path whose anchors are being dragged, text laid along it, a\n * second view of the same scene.\n */\nimport { isPlainObject } from '@weasel-js/registry';\nimport type { Dispatcher, OngoingHandle } from '@weasel-js/routing';\nimport type { NodeId, Scene, ShownOverride } from 'core/scene/types';\n\ntype Fields = Record<string, unknown>;\n\n/** One id's previewed data and the function showing it, kept while the handle answers the same data. */\ninterface ShownData<TData> {\n /** What the node stored when its preview began: what the handle's data was worked out from. */\n origin: unknown;\n value: unknown;\n data: (stored: TData) => TData;\n}\n\n/**\n * Publish every in-flight handle's `previewPose` and `previewData` to\n * `scene`'s overrides each time `dispatcher` notifies, through one hold, and\n * release them when the handles end. Returns the unsubscribe, which also\n * releases what is still published.\n *\n * Previewed data is shown as the fields it changes from what the node stored\n * when its preview began, laid over what the node stores now: a write made\n * mid-gesture, or its undo, shows through, as it will be kept when the edit\n * commits against the node as it then stands. Data that is not a plain\n * object is shown as it is.\n *\n * A handle with `previewHidesSource: false` previews a copy rather than its\n * source, so it is left out. On an id another writer's override already holds —\n * a transform's own frame, a live route — the preview is a ply over it, so a\n * field the handle does not propose shows what that writer says. The dispatcher\n * notifies after a handle's `onEnd`, so a commit has landed before its preview\n * goes.\n */\nexport function publishPreviews<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n dispatcher: Pick<Dispatcher, 'getInFlightHandles' | 'subscribe'>,\n): () => void {\n const hold = scene.overrides.hold();\n const shownData = new Map<NodeId, ShownData<TData>>();\n\n const dataFor = (id: NodeId, value: unknown): ((stored: TData) => TData) => {\n const held = shownData.get(id);\n if (held !== undefined && held.value === value) return held.data;\n const origin = held !== undefined ? held.origin : scene.get(id)?.data;\n const data = changesOver(origin, value) as (stored: TData) => TData;\n shownData.set(id, { origin, value, data });\n return data;\n };\n\n const publish = (): void => {\n const frame = new Map<NodeId, ShownOverride<TPose, TData>>();\n for (const handle of dispatcher.getInFlightHandles()) {\n if (handle.previewHidesSource === false) continue;\n collect(handle, frame, (id) => scene.get(id) !== undefined, dataFor);\n }\n for (const id of shownData.keys()) {\n if (frame.get(id)?.data === undefined) shownData.delete(id);\n }\n if (frame.size === 0) hold.drop();\n else hold.show(frame);\n };\n\n const unsubscribe = dispatcher.subscribe(publish);\n publish();\n return () => {\n unsubscribe();\n hold.drop();\n shownData.clear();\n };\n}\n\n/** `(stored) => value`'s changes from `origin` laid over `stored`. */\nfunction changesOver(origin: unknown, value: unknown): (stored: unknown) => unknown {\n if (!isPlainObject(origin) || !isPlainObject(value)) return () => value;\n const changed = new Set<string>();\n for (const key of new Set([...Object.keys(origin), ...Object.keys(value)])) {\n if (origin[key] !== value[key]) changed.add(key);\n }\n return (stored) => {\n if (stored === origin || !isPlainObject(stored)) return value;\n const out: Fields = { ...stored };\n for (const key of changed) {\n if (key in value) out[key] = value[key];\n else delete out[key];\n }\n return out;\n };\n}\n\n/** `handle`'s proposals into `frame`, first answer per id winning. */\nfunction collect<TPose, TData>(\n handle: OngoingHandle,\n frame: Map<NodeId, ShownOverride<TPose, TData>>,\n exists: (id: NodeId) => boolean,\n dataFor: (id: NodeId, value: unknown) => (stored: TData) => TData,\n): void {\n const ids = handle.previewIds?.();\n if (!ids) return;\n for (const raw of ids) {\n const id = raw as NodeId;\n if (frame.has(id) || !exists(id)) continue;\n const pose = handle.previewPose?.(raw);\n const data = handle.previewData?.(raw);\n if (pose == null && data == null) continue;\n frame.set(id, {\n ...(pose == null ? {} : { pose: pose as TPose }),\n ...(data == null ? {} : { data: dataFor(id, data) }),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,gBACd,OACA,YACY;CACZ,MAAM,OAAO,MAAM,UAAU,KAAK;CAClC,MAAM,4BAAY,IAAI,IAA8B;CAEpD,MAAM,WAAW,IAAY,UAA+C;EAC1E,MAAM,OAAO,UAAU,IAAI,EAAE;EAC7B,IAAI,SAAS,UAAa,KAAK,UAAU,OAAO,OAAO,KAAK;EAC5D,MAAM,SAAS,SAAS,SAAY,KAAK,SAAS,MAAM,IAAI,EAAE,CAAC,EAAE;EACjE,MAAM,OAAO,YAAY,QAAQ,KAAK;EACtC,UAAU,IAAI,IAAI;GAAE;GAAQ;GAAO;EAAK,CAAC;EACzC,OAAO;CACT;CAEA,MAAM,gBAAsB;EAC1B,MAAM,wBAAQ,IAAI,IAAyC;EAC3D,KAAK,MAAM,UAAU,WAAW,mBAAmB,GAAG;GACpD,IAAI,OAAO,uBAAuB,OAAO;GACzC,QAAQ,QAAQ,QAAQ,OAAO,MAAM,IAAI,EAAE,MAAM,QAAW,OAAO;EACrE;EACA,KAAK,MAAM,MAAM,UAAU,KAAK,GAC9B,IAAI,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,QAAW,UAAU,OAAO,EAAE;EAE5D,IAAI,MAAM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
7
|
import { sceneMutators } from "../core/scene/sceneMutators.js";
|
|
8
8
|
import { applyOpsTo } from "../core/applyOps.js";
|
|
9
9
|
import { hitTestArea, hitTestLassoPolygon, regionPickOptions } from "./deps/hitTestArea.js";
|
|
10
|
+
import { insertSite } from "./deps/insertSite.js";
|
|
10
11
|
import { scenePoseTarget } from "../animation/poseTarget.js";
|
|
11
12
|
import { cascadingSetPose, containerCascade } from "./poseCascade.js";
|
|
12
13
|
import { pasteSceneSnapshot, snapshotSceneSelection } from "./sceneClipboard.js";
|
|
@@ -42,7 +43,8 @@ function sceneToAdapter(scene, options = {}) {
|
|
|
42
43
|
worldPoseOf: (id) => adapter.getWorldPose(id),
|
|
43
44
|
frameAtOrAbove: (id) => frameAtOrAbove(adapter, id),
|
|
44
45
|
poseBounds,
|
|
45
|
-
translate
|
|
46
|
+
translate,
|
|
47
|
+
...options.pasteInto ? { landing: () => insertSite(scene, options.pasteInto()) } : {}
|
|
46
48
|
};
|
|
47
49
|
const adapter = {
|
|
48
50
|
...sceneMutators(scene),
|
|
@@ -67,7 +69,7 @@ function sceneToAdapter(scene, options = {}) {
|
|
|
67
69
|
...composes ? { composePose: composition.compose } : {},
|
|
68
70
|
...cascade ? { setPose: (id, pose) => cascade.setPose(asNodeId(id), pose) } : {},
|
|
69
71
|
poseTarget(id, descriptor) {
|
|
70
|
-
if (cascade === null || scene.get(asNodeId(id))?.kind !== "
|
|
72
|
+
if (cascade === null || scene.get(asNodeId(id))?.kind !== "group") return scenePoseTarget(scene, id, descriptor ?? d);
|
|
71
73
|
const carried = containerCascade(scene, asNodeId(id), d, (pose) => adapter.setPose(id, pose));
|
|
72
74
|
return scenePoseTarget(scene, id, descriptor ?? d, carried);
|
|
73
75
|
},
|
|
@@ -85,17 +87,17 @@ function sceneToAdapter(scene, options = {}) {
|
|
|
85
87
|
getSelection,
|
|
86
88
|
setSelection,
|
|
87
89
|
hitTestArea(rect, view) {
|
|
88
|
-
return hitTestArea(scene, rect, pickOptsFor(view), d, {
|
|
90
|
+
return hitTestArea(scene, rect, pickOptsFor(view), d, { includeGroups: true });
|
|
89
91
|
},
|
|
90
92
|
hitTestLasso(polygon, mode, view) {
|
|
91
|
-
return hitTestLassoPolygon(scene, polygon, mode, pickOptsFor(view), d, {
|
|
93
|
+
return hitTestLassoPolygon(scene, polygon, mode, pickOptsFor(view), d, { includeGroups: true });
|
|
92
94
|
},
|
|
93
95
|
...options.commitInsert ? { commitInsert: (bounds) => {
|
|
94
96
|
const created = options.commitInsert(bounds);
|
|
95
97
|
if (!created) return null;
|
|
96
98
|
const layer = options.insertLayer ?? "default";
|
|
97
99
|
return {
|
|
98
|
-
kind: "
|
|
100
|
+
kind: "mark",
|
|
99
101
|
id: created.id === void 0 ? scene.mintId() : asNodeId(created.id),
|
|
100
102
|
layer,
|
|
101
103
|
pose: created.pose,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneAdapter.js","names":[],"sources":["../../src/canvas/sceneAdapter.ts"],"sourcesContent":["/**\n * Synthesize a `<Canvas>`-compatible adapter from a `Scene` primitive.\n * `getPose` / `setPose` return / write **local** coordinates (relative to\n * parent); world composition is the renderer's job via `composeWorldPose`.\n */\nimport type {\n AreaSelectAdapter,\n ClipboardSnapshot,\n InsertAdapter,\n PasteCtx,\n LassoHitMode,\n LassoSelectAdapter,\n RegionPickView,\n LayerEnumerableAdapter,\n MoveAdapter,\n ResizeAdapter,\n RotateAdapter,\n} from 'core/adapters/types';\nimport type { LayoutStrategy } from '../layout/types';\nimport type { Op } from 'core/ops/types';\nimport type { Node, Scene } from 'core/scene/types';\nimport { definesFrame, effectivePose } from 'core/scene/effectivePose';\nimport { sceneMutators } from 'core/scene/sceneMutators';\nimport { asNodeId } from 'core/scene/types';\nimport { nodeGates } from 'core/scene/nodeGates';\nimport { applyOpsTo } from 'core/applyOps';\nimport { hitTestArea, hitTestLassoPolygon, regionPickOptions } from 'canvas/deps/hitTestArea';\nimport type { ScenePickSourceOptions } from 'canvas/pickWalk';\nimport {\n poseDescriptorForNode,\n translatePoseViaDescriptor,\n visualBoundsViaDescriptor,\n type PoseDescriptor,\n} from 'interactions/actions/resize/geometry';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport { composesFrames, composeWorldPose, frameAtOrAbove } from 'core/scene/composePose';\nimport type { Bounds } from '../core/viewport/fitViewToBounds';\nimport { scenePoseTarget } from '../animation/poseTarget';\nimport { cascadingSetPose, containerCascade } from './poseCascade';\nimport { pasteSceneSnapshot, snapshotSceneSelection, type SceneClipboardEnv } from './sceneClipboard';\n\n/** Minimal selection contract `sceneToAdapter` needs to wire `getSelection` /\n * `setSelection`. Matches `useSelection().adapterMethods` plus an imperative\n * read; pass `useSelection()` itself or `selection.adapterMethods`. */\nexport interface SceneAdapterSelection {\n get?(): string[];\n set?(ids: string[]): void;\n getSelection?(): string[];\n setSelection?(ids: string[]): void;\n}\n\n/** Sibling z-order surface used by reorder ops. Inlined here (rather than\n * pulled from `core/ops/reorder` to avoid import cycles); the `null` parent\n * channel addresses the root sibling list. */\n/** @internal */\ninterface ReorderAdapter {\n getChildren(parentId: string | null): string[];\n setChildOrder(parentId: string | null, ids: string[]): void;\n}\n\n/** Everything the interaction layer can ask of a scene, as one type: the\n * move, resize, rotate, selection, layer and reorder contracts combined.\n * `<SceneCanvas>` synthesizes one of these, which is why most consumers never\n * touch an adapter directly. */\nexport type SceneCanvasAdapter<TData, TLayer extends string, TPose> =\n & MoveAdapter<Node<TData, TLayer, TPose>, TPose>\n & ResizeAdapter<Node<TData, TLayer, TPose>, TPose>\n & RotateAdapter<Node<TData, TLayer, TPose>, TPose>\n & AreaSelectAdapter\n & LassoSelectAdapter\n & LayerEnumerableAdapter<TLayer>\n & ReorderAdapter\n & Partial<InsertAdapter<Node<TData, TLayer, TPose>>>\n // Optional on the underlying adapter contracts, but unconditionally\n // provided by a scene-backed adapter.\n & {\n getParent(id: string): string | null;\n getLayers: NonNullable<LayerEnumerableAdapter<TLayer>['getLayers']>;\n /** The node's pose with every ancestor's frame folded in. Equal to\n * `getPose` unless the scene composes poses. */\n getWorldPose(id: string): TPose;\n /** Whether `id`'s pose is a frame its children are expressed in — see\n * `definesFrame`. */\n definesFrame(id: string): boolean;\n /** Present only when a composing strategy is configured; the render\n * walk feature-detects it. */\n composePose?(parent: TPose, child: TPose): TPose;\n getSelection(): string[];\n setSelection(ids: string[]): void;\n insertNode(node: Node<TData, TLayer, TPose>, index?: number): void;\n removeNode(id: string): void;\n /** Replace a node's `data` — what a `setData` op writes through. */\n setData(id: string, data: TData): void;\n /** Swap a container's layout — what a `setLayout` op writes through. */\n setLayout(id: string, layout: LayoutStrategy<TPose> | string | null): void;\n /** Move a node to another layer — what a `setLayer` op writes through. */\n setLayer(id: string, layer: TLayer): void;\n /** Retarget a derived node's sources — what a `setDependsOn` op writes through. */\n setDependsOn(id: string, dependsOn: readonly string[] | 'children' | undefined): void;\n /** Hide or show a node — what a `setHidden` op writes through. */\n setHidden(id: string, hidden: boolean): void;\n /** Lock or unlock a node — what a `setLocked` op writes through. */\n setLocked(id: string, locked: boolean): void;\n getRemovalClosure(ids: readonly string[]): string[];\n applyOps(ops: Op[], label?: string): void;\n snapshotSelection(ids: string[]): ClipboardSnapshot;\n commitPaste(\n clipboard: ClipboardSnapshot,\n offset: { dx: number; dy: number },\n ctx?: PasteCtx,\n ): Node<TData, TLayer, TPose>[];\n getPasteOffset(clipboard: ClipboardSnapshot): { dx: number; dy: number };\n };\n\n/** Optional extras for the synthesized adapter. Pass `commitInsert` to wire\n * the insert gesture into a Scene-owned canvas; the returned object becomes\n * a leaf on the layer named by `layer` (default `'default'`). */\nexport interface SceneToAdapterOptions<TData, TLayer extends string, TPose> {\n /** Factory for new objects. Returning `null` aborts the insert. */\n commitInsert?: (bounds: Bounds) => {\n pose: TPose;\n data: TData;\n id?: string;\n } | null;\n /** Layer to place inserted nodes on. Defaults to the trivial-form layer. */\n insertLayer?: TLayer;\n /** Selection source: the result of `useSelection()` (or its\n * `adapterMethods`). When omitted, `getSelection` returns `[]` and\n * `setSelection` is a noop, so the marquee gesture updates nothing. */\n selection?: SceneAdapterSelection;\n /** How to read and rewrite this scene's poses. Default `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<TPose>;\n}\n\n/** Derive the adapter for a scene. Reads go straight to the scene; writes are\n * ops applied through its history, so anything done through the adapter is\n * undoable.\n *\n * Moving a container carries its contents either way the scene composes\n * poses. Under a frame (`scene.composition`) the one pose written moves them.\n * Under the absolute-pose model `setPose` on a container translates every\n * descendant by the same delta, and a batch that poses descendants too undoes\n * exactly only when it goes through this adapter's `applyOps`. */\nexport function sceneToAdapter<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n options: SceneToAdapterOptions<TData, TLayer, TPose> = {},\n): SceneCanvasAdapter<TData, TLayer, TPose> {\n const sel = options.selection;\n const getSelection = sel?.getSelection ?? sel?.get ?? (() => [] as string[]);\n const setSelection = sel?.setSelection ?? sel?.set ?? (() => {});\n const d = (options.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const poseBounds = (p: TPose, node: unknown): Bounds =>\n visualBoundsViaDescriptor(p, poseDescriptorForNode(d, node));\n const translate = (p: TPose, dx: number, dy: number, node?: unknown): TPose =>\n translatePoseViaDescriptor(\n p, dx, dy, node === undefined ? d : poseDescriptorForNode(d, node),\n );\n\n const composition = scene.composition;\n const composes = composesFrames(composition);\n const pickOpts: ScenePickSourceOptions<unknown> = {};\n // The asking view's layer gate and camera, over the adapter's own options.\n const pickOptsFor = (view: RegionPickView | undefined): ScenePickSourceOptions<unknown> =>\n (view ? { ...pickOpts, ...regionPickOptions(view, undefined) } : pickOpts);\n\n const cascade = composes ? null : { setPose: cascadingSetPose(scene, d) };\n\n const clipboardEnv: SceneClipboardEnv<TData, TLayer, TPose> = {\n scene,\n composes,\n worldPoseOf: (id) => adapter.getWorldPose(id),\n frameAtOrAbove: (id) => frameAtOrAbove(adapter, id),\n poseBounds,\n translate,\n };\n\n const adapter: SceneCanvasAdapter<TData, TLayer, TPose> = {\n ...sceneMutators(scene),\n // What is shown, where the mutators' other users read the document:\n // the nodes not hidden, and the effective pose.\n getNodes() {\n const gates = nodeGates(scene);\n return scene.renderOrderNodes().filter((n) => !gates.hidden(n.id));\n },\n getPose(id) {\n const nid = asNodeId(id);\n const n = scene.get(nid);\n if (!n) throw new Error(`sceneToAdapter: unknown node \"${id}\"`);\n return effectivePose(scene, n);\n },\n definesFrame(id) {\n const n = scene.get(asNodeId(id));\n return n === undefined || definesFrame(n);\n },\n getWorldPose(id) {\n if (!composes) return adapter.getPose(id);\n return composeWorldPose(adapter, id, composition.compose);\n },\n // Only present when it would do something: the render walk skips the fold\n // entirely when this is absent, which is the absolute-pose path.\n ...(composes ? { composePose: composition.compose } : {}),\n ...(cascade ? { setPose: (id: string, pose: TPose) => cascade.setPose(asNodeId(id), pose) } : {}),\n poseTarget(id, descriptor) {\n if (cascade === null || scene.get(asNodeId(id))?.kind !== 'container') {\n return scenePoseTarget(scene, id, descriptor ?? d);\n }\n // Its descendants hold poses of their own: a commit moves them, and they are shown beside it.\n const carried = containerCascade(scene, asNodeId(id), d, (pose) => adapter.setPose(id, pose));\n return scenePoseTarget(scene, id, descriptor ?? d, carried);\n },\n getLayers: () => scene.layers.map((l) => ({ id: l.id, visible: l.visible, parallax: l.parallax })),\n subscribeLayers: (listener) => scene.subscribe(listener),\n getLayout: (id) => scene.layoutOf(asNodeId(id)),\n // With a label the ops are one batch checkpoint; without one they are\n // applied transiently, with no checkpoint (the AreaSelectAdapter contract).\n applyOps(ops: Op[], label?: string) {\n if (label !== undefined) {\n scene.applyBatch(ops, label, this);\n } else {\n applyOpsTo(this, ops);\n }\n },\n getSelection,\n setSelection,\n // The live marquee's and lasso's own hit-tests. Containers come back:\n // this adapter's consumer has nothing to fold children into them.\n hitTestArea(rect: Bounds, view?: RegionPickView) {\n return hitTestArea(\n scene,\n rect,\n pickOptsFor(view),\n d as PoseDescriptor<unknown>,\n { includeContainers: true },\n );\n },\n hitTestLasso(polygon, mode: LassoHitMode, view?: RegionPickView) {\n return hitTestLassoPolygon(\n scene,\n polygon,\n mode,\n pickOptsFor(view),\n d as PoseDescriptor<unknown>,\n { includeContainers: true },\n );\n },\n // A pure factory: it constructs a Node spec but does NOT touch the scene.\n // The `InsertOp` → `adapter.insertNode` → `scene.add` path is the sole\n // insertion path. Calling `scene.add` here too would double-insert, and\n // the second add throws on id collision.\n ...(options.commitInsert\n ? {\n commitInsert: (bounds: { x: number; y: number; width: number; height: number }) => {\n const created = options.commitInsert!(bounds);\n if (!created) return null;\n const layer = (options.insertLayer ?? ('default' as TLayer));\n const id = created.id === undefined ? scene.mintId() : asNodeId(created.id);\n return {\n kind: 'leaf',\n id,\n layer,\n pose: created.pose,\n data: created.data,\n parent: null,\n } as Node<TData, TLayer, TPose>;\n },\n }\n : {}),\n // Clipboard seam (`useClipboardOps` / the paste ingestion path).\n snapshotSelection(ids: string[]): ClipboardSnapshot {\n return snapshotSceneSelection(clipboardEnv, ids);\n },\n commitPaste(\n clipboard: ClipboardSnapshot,\n offset: { dx: number; dy: number },\n ctx?: PasteCtx,\n ): Node<TData, TLayer, TPose>[] {\n return pasteSceneSnapshot(clipboardEnv, clipboard, offset, ctx);\n },\n // Constant cascade: the hook re-snapshots the just-created items, so\n // repeated pastes stack +12/+12 each time.\n getPasteOffset(): { dx: number; dy: number } {\n return { dx: 12, dy: 12 };\n },\n };\n\n return adapter;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+IA,SAAgB,eACd,OACA,UAAuD,CAAC,GACd;CAC1C,MAAM,MAAM,QAAQ;CACpB,MAAM,eAAe,KAAK,gBAAgB,KAAK,cAAc,CAAC;CAC9D,MAAM,eAAe,KAAK,gBAAgB,KAAK,cAAc,CAAC;CAC9D,MAAM,IAAK,QAAQ,kBAAkB;CACrC,MAAM,cAAc,GAAU,SAC5B,0BAA0B,GAAG,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A,YACE,WACA,QACA,KAC8B;GAC9B,OAAO,mBAAmB,cAAc,WAAW,QAAQ,GAAG;EAChE;EAGA,iBAA6C;GAC3C,OAAO;IAAE,IAAI;IAAI,IAAI;GAAG;EAC1B;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"sceneAdapter.js","names":[],"sources":["../../src/canvas/sceneAdapter.ts"],"sourcesContent":["/**\n * Synthesize a `<Canvas>`-compatible adapter from a `Scene` primitive.\n * `getPose` / `setPose` return / write **local** coordinates (relative to\n * parent); world composition is the renderer's job via `composeWorldPose`.\n */\nimport type {\n AreaSelectAdapter,\n ClipboardSnapshot,\n InsertAdapter,\n PasteCtx,\n LassoHitMode,\n LassoSelectAdapter,\n RegionPickView,\n LayerEnumerableAdapter,\n MoveAdapter,\n ResizeAdapter,\n RotateAdapter,\n} from 'core/adapters/types';\nimport type { LayoutStrategy } from '../layout/types';\nimport type { Op } from 'core/ops/types';\nimport type { Node, Scene } from 'core/scene/types';\nimport { definesFrame, effectivePose } from 'core/scene/effectivePose';\nimport { sceneMutators } from 'core/scene/sceneMutators';\nimport { asNodeId } from 'core/scene/types';\nimport { nodeGates } from 'core/scene/nodeGates';\nimport { applyOpsTo } from 'core/applyOps';\nimport { hitTestArea, hitTestLassoPolygon, regionPickOptions } from 'canvas/deps/hitTestArea';\nimport type { ScenePickSourceOptions } from 'canvas/pickWalk';\nimport {\n poseDescriptorForNode,\n translatePoseViaDescriptor,\n visualBoundsViaDescriptor,\n type PoseDescriptor,\n} from 'interactions/actions/resize/geometry';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport { composesFrames, composeWorldPose, frameAtOrAbove } from 'core/scene/composePose';\nimport { insertSite } from './deps/insertSite';\nimport type { Bounds } from '../core/viewport/fitViewToBounds';\nimport { scenePoseTarget } from '../animation/poseTarget';\nimport { cascadingSetPose, containerCascade } from './poseCascade';\nimport { pasteSceneSnapshot, snapshotSceneSelection, type SceneClipboardEnv } from './sceneClipboard';\n\n/** Minimal selection contract `sceneToAdapter` needs to wire `getSelection` /\n * `setSelection`. Matches `useSelection().adapterMethods` plus an imperative\n * read; pass `useSelection()` itself or `selection.adapterMethods`. */\nexport interface SceneAdapterSelection {\n get?(): string[];\n set?(ids: string[]): void;\n getSelection?(): string[];\n setSelection?(ids: string[]): void;\n}\n\n/** Sibling z-order surface used by reorder ops. Inlined here (rather than\n * pulled from `core/ops/reorder` to avoid import cycles); the `null` parent\n * channel addresses the root sibling list. */\n/** @internal */\ninterface ReorderAdapter {\n getChildren(parentId: string | null): string[];\n setChildOrder(parentId: string | null, ids: string[]): void;\n}\n\n/** Everything the interaction layer can ask of a scene, as one type: the\n * move, resize, rotate, selection, layer and reorder contracts combined.\n * `<SceneCanvas>` synthesizes one of these, which is why most consumers never\n * touch an adapter directly. */\nexport type SceneCanvasAdapter<TData, TLayer extends string, TPose> =\n & MoveAdapter<Node<TData, TLayer, TPose>, TPose>\n & ResizeAdapter<Node<TData, TLayer, TPose>, TPose>\n & RotateAdapter<Node<TData, TLayer, TPose>, TPose>\n & AreaSelectAdapter\n & LassoSelectAdapter\n & LayerEnumerableAdapter<TLayer>\n & ReorderAdapter\n & Partial<InsertAdapter<Node<TData, TLayer, TPose>>>\n // Optional on the underlying adapter contracts, but unconditionally\n // provided by a scene-backed adapter.\n & {\n getParent(id: string): string | null;\n getLayers: NonNullable<LayerEnumerableAdapter<TLayer>['getLayers']>;\n /** The node's pose with every ancestor's frame folded in. Equal to\n * `getPose` unless the scene composes poses. */\n getWorldPose(id: string): TPose;\n /** Whether `id`'s pose is a frame its children are expressed in — see\n * `definesFrame`. */\n definesFrame(id: string): boolean;\n /** Present only when a composing strategy is configured; the render\n * walk feature-detects it. */\n composePose?(parent: TPose, child: TPose): TPose;\n getSelection(): string[];\n setSelection(ids: string[]): void;\n insertNode(node: Node<TData, TLayer, TPose>, index?: number): void;\n removeNode(id: string): void;\n /** Replace a node's `data` — what a `setData` op writes through. */\n setData(id: string, data: TData): void;\n /** Swap a container's layout — what a `setLayout` op writes through. */\n setLayout(id: string, layout: LayoutStrategy<TPose> | string | null): void;\n /** Move a node to another layer — what a `setLayer` op writes through. */\n setLayer(id: string, layer: TLayer): void;\n /** Retarget a derived node's sources — what a `setDependsOn` op writes through. */\n setDependsOn(id: string, dependsOn: readonly string[] | 'children' | undefined): void;\n /** Hide or show a node — what a `setHidden` op writes through. */\n setHidden(id: string, hidden: boolean): void;\n /** Lock or unlock a node — what a `setLocked` op writes through. */\n setLocked(id: string, locked: boolean): void;\n getRemovalClosure(ids: readonly string[]): string[];\n applyOps(ops: Op[], label?: string): void;\n snapshotSelection(ids: string[]): ClipboardSnapshot;\n commitPaste(\n clipboard: ClipboardSnapshot,\n offset: { dx: number; dy: number },\n ctx?: PasteCtx,\n ): Node<TData, TLayer, TPose>[];\n getPasteOffset(clipboard: ClipboardSnapshot): { dx: number; dy: number };\n };\n\n/** Optional extras for the synthesized adapter. Pass `commitInsert` to wire\n * the insert gesture into a Scene-owned canvas; the returned object becomes\n * a leaf on the layer named by `layer` (default `'default'`). */\nexport interface SceneToAdapterOptions<TData, TLayer extends string, TPose> {\n /** Factory for new objects. Returning `null` aborts the insert. */\n commitInsert?: (bounds: Bounds) => {\n pose: TPose;\n data: TData;\n id?: string;\n } | null;\n /** Layer to place inserted nodes on. Defaults to the trivial-form layer. */\n insertLayer?: TLayer;\n /** Selection source: the result of `useSelection()` (or its\n * `adapterMethods`). When omitted, `getSelection` returns `[]` and\n * `setSelection` is a noop, so the marquee gesture updates nothing. */\n selection?: SceneAdapterSelection;\n /** How to read and rewrite this scene's poses. Default `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<TPose>;\n /** The container a paste lands in, read at each paste: `<SceneCanvas>` passes the `insertInto` dep's. */\n pasteInto?: () => string | null;\n}\n\n/** Derive the adapter for a scene. Reads go straight to the scene; writes are\n * ops applied through its history, so anything done through the adapter is\n * undoable.\n *\n * Moving a container carries its contents either way the scene composes\n * poses. Under a frame (`scene.composition`) the one pose written moves them.\n * Under the absolute-pose model `setPose` on a container translates every\n * descendant by the same delta, and a batch that poses descendants too undoes\n * exactly only when it goes through this adapter's `applyOps`. */\nexport function sceneToAdapter<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n options: SceneToAdapterOptions<TData, TLayer, TPose> = {},\n): SceneCanvasAdapter<TData, TLayer, TPose> {\n const sel = options.selection;\n const getSelection = sel?.getSelection ?? sel?.get ?? (() => [] as string[]);\n const setSelection = sel?.setSelection ?? sel?.set ?? (() => {});\n const d = (options.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const poseBounds = (p: TPose, node: unknown): Bounds =>\n visualBoundsViaDescriptor(p, poseDescriptorForNode(d, node));\n const translate = (p: TPose, dx: number, dy: number, node?: unknown): TPose =>\n translatePoseViaDescriptor(\n p, dx, dy, node === undefined ? d : poseDescriptorForNode(d, node),\n );\n\n const composition = scene.composition;\n const composes = composesFrames(composition);\n const pickOpts: ScenePickSourceOptions<unknown> = {};\n // The asking view's layer gate and camera, over the adapter's own options.\n const pickOptsFor = (view: RegionPickView | undefined): ScenePickSourceOptions<unknown> =>\n (view ? { ...pickOpts, ...regionPickOptions(view, undefined) } : pickOpts);\n\n const cascade = composes ? null : { setPose: cascadingSetPose(scene, d) };\n\n const clipboardEnv: SceneClipboardEnv<TData, TLayer, TPose> = {\n scene,\n composes,\n worldPoseOf: (id) => adapter.getWorldPose(id),\n frameAtOrAbove: (id) => frameAtOrAbove(adapter, id),\n poseBounds,\n translate, ...(options.pasteInto ? { landing: () => insertSite(scene as never, options.pasteInto!()) } : {}),\n };\n\n const adapter: SceneCanvasAdapter<TData, TLayer, TPose> = {\n ...sceneMutators(scene),\n // What is shown, where the mutators' other users read the document:\n // the nodes not hidden, and the effective pose.\n getNodes() {\n const gates = nodeGates(scene);\n return scene.renderOrderNodes().filter((n) => !gates.hidden(n.id));\n },\n getPose(id) {\n const nid = asNodeId(id);\n const n = scene.get(nid);\n if (!n) throw new Error(`sceneToAdapter: unknown node \"${id}\"`);\n return effectivePose(scene, n);\n },\n definesFrame(id) {\n const n = scene.get(asNodeId(id));\n return n === undefined || definesFrame(n);\n },\n getWorldPose(id) {\n if (!composes) return adapter.getPose(id);\n return composeWorldPose(adapter, id, composition.compose);\n },\n // Only present when it would do something: the render walk skips the fold\n // entirely when this is absent, which is the absolute-pose path.\n ...(composes ? { composePose: composition.compose } : {}),\n ...(cascade ? { setPose: (id: string, pose: TPose) => cascade.setPose(asNodeId(id), pose) } : {}),\n poseTarget(id, descriptor) {\n if (cascade === null || scene.get(asNodeId(id))?.kind !== 'group') {\n return scenePoseTarget(scene, id, descriptor ?? d);\n }\n // Its descendants hold poses of their own: a commit moves them, and they are shown beside it.\n const carried = containerCascade(scene, asNodeId(id), d, (pose) => adapter.setPose(id, pose));\n return scenePoseTarget(scene, id, descriptor ?? d, carried);\n },\n getLayers: () => scene.layers.map((l) => ({ id: l.id, visible: l.visible, parallax: l.parallax })),\n subscribeLayers: (listener) => scene.subscribe(listener),\n getLayout: (id) => scene.layoutOf(asNodeId(id)),\n // With a label the ops are one batch checkpoint; without one they are\n // applied transiently, with no checkpoint (the AreaSelectAdapter contract).\n applyOps(ops: Op[], label?: string) {\n if (label !== undefined) {\n scene.applyBatch(ops, label, this);\n } else {\n applyOpsTo(this, ops);\n }\n },\n getSelection,\n setSelection,\n // The live marquee's and lasso's own hit-tests. Groups come back:\n // this adapter's consumer has nothing to fold children into them.\n hitTestArea(rect: Bounds, view?: RegionPickView) {\n return hitTestArea(\n scene,\n rect,\n pickOptsFor(view),\n d as PoseDescriptor<unknown>,\n { includeGroups: true },\n );\n },\n hitTestLasso(polygon, mode: LassoHitMode, view?: RegionPickView) {\n return hitTestLassoPolygon(\n scene,\n polygon,\n mode,\n pickOptsFor(view),\n d as PoseDescriptor<unknown>,\n { includeGroups: true },\n );\n },\n // A pure factory: it constructs a Node spec but does NOT touch the scene.\n // The `InsertOp` → `adapter.insertNode` → `scene.add` path is the sole\n // insertion path. Calling `scene.add` here too would double-insert, and\n // the second add throws on id collision.\n ...(options.commitInsert\n ? {\n commitInsert: (bounds: { x: number; y: number; width: number; height: number }) => {\n const created = options.commitInsert!(bounds);\n if (!created) return null;\n const layer = (options.insertLayer ?? ('default' as TLayer));\n const id = created.id === undefined ? scene.mintId() : asNodeId(created.id);\n return {\n kind: 'mark',\n id,\n layer,\n pose: created.pose,\n data: created.data,\n parent: null,\n } as Node<TData, TLayer, TPose>;\n },\n }\n : {}),\n // Clipboard seam (`useClipboardOps` / the paste ingestion path).\n snapshotSelection(ids: string[]): ClipboardSnapshot {\n return snapshotSceneSelection(clipboardEnv, ids);\n },\n commitPaste(\n clipboard: ClipboardSnapshot,\n offset: { dx: number; dy: number },\n ctx?: PasteCtx,\n ): Node<TData, TLayer, TPose>[] {\n return pasteSceneSnapshot(clipboardEnv, clipboard, offset, ctx);\n },\n // Constant cascade: the hook re-snapshots the just-created items, so\n // repeated pastes stack +12/+12 each time.\n getPasteOffset(): { dx: number; dy: number } {\n return { dx: 12, dy: 12 };\n },\n };\n\n return adapter;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkJA,SAAgB,eACd,OACA,UAAuD,CAAC,GACd;CAC1C,MAAM,MAAM,QAAQ;CACpB,MAAM,eAAe,KAAK,gBAAgB,KAAK,cAAc,CAAC;CAC9D,MAAM,eAAe,KAAK,gBAAgB,KAAK,cAAc,CAAC;CAC9D,MAAM,IAAK,QAAQ,kBAAkB;CACrC,MAAM,cAAc,GAAU,SAC5B,0BAA0B,GAAG,sBAAsB,GAAG,IAAI,CAAC;CAC7D,MAAM,aAAa,GAAU,IAAY,IAAY,SACnD,2BACE,GAAG,IAAI,IAAI,SAAS,SAAY,IAAI,sBAAsB,GAAG,IAAI,CACnE;CAEF,MAAM,cAAc,MAAM;CAC1B,MAAM,WAAW,eAAe,WAAW;CAC3C,MAAM,WAA4C,CAAC;CAEnD,MA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