@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.
Files changed (304) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/dist/animation/poseTarget.js +46 -15
  3. package/dist/animation/poseTarget.js.map +1 -1
  4. package/dist/animation/poseTransition.js +3 -3
  5. package/dist/animation/poseTransition.js.map +1 -1
  6. package/dist/animation/reflow.js +3 -6
  7. package/dist/animation/reflow.js.map +1 -1
  8. package/dist/animation/rig/bindRig.js +2 -2
  9. package/dist/animation/rig/bindRig.js.map +1 -1
  10. package/dist/animation/rig/skinBinding.js +2 -2
  11. package/dist/animation/rig/skinBinding.js.map +1 -1
  12. package/dist/barrel/canvas.js +5 -3
  13. package/dist/barrel/chrome.js +3 -1
  14. package/dist/barrel/paths.js +3 -2
  15. package/dist/barrel/routing.js +2 -2
  16. package/dist/barrel/scene.js +6 -1
  17. package/dist/barrel/text.js +2 -2
  18. package/dist/canvas/NodeShape.js +1 -0
  19. package/dist/canvas/NodeShape.js.map +1 -1
  20. package/dist/canvas/SceneCanvas/SceneCanvasInput.js +2 -0
  21. package/dist/canvas/SceneCanvas/SceneCanvasInput.js.map +1 -1
  22. package/dist/canvas/SceneCanvas/canvasPassThrough.js +1 -1
  23. package/dist/canvas/SceneCanvas/canvasPassThrough.js.map +1 -1
  24. package/dist/canvas/SceneCanvas/defaultNodeRouting.js +2 -2
  25. package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
  26. package/dist/canvas/SceneCanvas/scenePointQuery.js +20 -2
  27. package/dist/canvas/SceneCanvas/scenePointQuery.js.map +1 -1
  28. package/dist/canvas/SceneCanvas/useCanvasTools.js +3 -0
  29. package/dist/canvas/SceneCanvas/useCanvasTools.js.map +1 -1
  30. package/dist/canvas/SceneCanvas/useContributionRoles.js +2 -0
  31. package/dist/canvas/SceneCanvas/useContributionRoles.js.map +1 -1
  32. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +25 -19
  33. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
  34. package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js +7 -0
  35. package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
  36. package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +1 -0
  37. package/dist/canvas/SceneCanvas/useSceneCanvasTools.js.map +1 -1
  38. package/dist/canvas/SceneCanvas/useScenePicking.js +31 -6
  39. package/dist/canvas/SceneCanvas/useScenePicking.js.map +1 -1
  40. package/dist/canvas/SceneCanvas/useSceneSelectTool.js +4 -5
  41. package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
  42. package/dist/canvas/SceneCanvas/useSceneStandardActions.js +5 -3
  43. package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
  44. package/dist/canvas/SceneCanvas.js +19 -2
  45. package/dist/canvas/SceneCanvas.js.map +1 -1
  46. package/dist/canvas/accentColor.js +26 -3
  47. package/dist/canvas/accentColor.js.map +1 -1
  48. package/dist/canvas/buildSceneLayer.js +1 -1
  49. package/dist/canvas/buildSceneLayer.js.map +1 -1
  50. package/dist/canvas/buildSceneTree.js +14 -20
  51. package/dist/canvas/buildSceneTree.js.map +1 -1
  52. package/dist/canvas/canvasRenderer.js +6 -2
  53. package/dist/canvas/canvasRenderer.js.map +1 -1
  54. package/dist/canvas/copiesAbove.js +1 -1
  55. package/dist/canvas/copiesAbove.js.map +1 -1
  56. package/dist/canvas/defaultDrawOne.js +10 -7
  57. package/dist/canvas/defaultDrawOne.js.map +1 -1
  58. package/dist/canvas/deps/areaSelect.js +5 -2
  59. package/dist/canvas/deps/areaSelect.js.map +1 -1
  60. package/dist/canvas/deps/booleans.js +1 -1
  61. package/dist/canvas/deps/booleans.js.map +1 -1
  62. package/dist/canvas/deps/enteredGroup.js +81 -0
  63. package/dist/canvas/deps/enteredGroup.js.map +1 -0
  64. package/dist/canvas/deps/hitTestArea.js +27 -15
  65. package/dist/canvas/deps/hitTestArea.js.map +1 -1
  66. package/dist/canvas/deps/insert.js +4 -36
  67. package/dist/canvas/deps/insert.js.map +1 -1
  68. package/dist/canvas/deps/insertSite.js +39 -0
  69. package/dist/canvas/deps/insertSite.js.map +1 -0
  70. package/dist/canvas/deps/lassoSelect.js +6 -3
  71. package/dist/canvas/deps/lassoSelect.js.map +1 -1
  72. package/dist/canvas/deps/pathLeaf.js +1 -1
  73. package/dist/canvas/deps/pathLeaf.js.map +1 -1
  74. package/dist/canvas/deps/slice.js +2 -1
  75. package/dist/canvas/deps/slice.js.map +1 -1
  76. package/dist/canvas/derivedPath.js +14 -6
  77. package/dist/canvas/derivedPath.js.map +1 -1
  78. package/dist/canvas/doubleClickTarget.js +9 -11
  79. package/dist/canvas/doubleClickTarget.js.map +1 -1
  80. package/dist/canvas/drawnBounds.js +16 -7
  81. package/dist/canvas/drawnBounds.js.map +1 -1
  82. package/dist/canvas/inheritedPaints.js +22 -11
  83. package/dist/canvas/inheritedPaints.js.map +1 -1
  84. package/dist/canvas/nodeShapes/nodePaint.js +1 -7
  85. package/dist/canvas/nodeShapes/nodePaint.js.map +1 -1
  86. package/dist/canvas/nodeShapes/pathPainter.js +2 -3
  87. package/dist/canvas/nodeShapes/pathPainter.js.map +1 -1
  88. package/dist/canvas/nodeShapes/rectFallbackPainter.js +1 -1
  89. package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -1
  90. package/dist/canvas/nodeShapes/shapePainter.js +2 -3
  91. package/dist/canvas/nodeShapes/shapePainter.js.map +1 -1
  92. package/dist/canvas/ownClip.js +24 -0
  93. package/dist/canvas/ownClip.js.map +1 -0
  94. package/dist/canvas/paintCull.js.map +1 -1
  95. package/dist/canvas/pickIndex/nodeBroadBox.js +86 -0
  96. package/dist/canvas/pickIndex/nodeBroadBox.js.map +1 -0
  97. package/dist/canvas/pickIndex/scenePickIndex.js +208 -0
  98. package/dist/canvas/pickIndex/scenePickIndex.js.map +1 -0
  99. package/dist/canvas/pickWalk.js +14 -90
  100. package/dist/canvas/pickWalk.js.map +1 -1
  101. package/dist/canvas/poseCascade.js +1 -1
  102. package/dist/canvas/poseCascade.js.map +1 -1
  103. package/dist/canvas/publishPreviews.js +97 -0
  104. package/dist/canvas/publishPreviews.js.map +1 -0
  105. package/dist/canvas/sceneAdapter.js +7 -5
  106. package/dist/canvas/sceneAdapter.js.map +1 -1
  107. package/dist/canvas/sceneClipboard.js +17 -10
  108. package/dist/canvas/sceneClipboard.js.map +1 -1
  109. package/dist/canvas/scenePickReads.js +37 -0
  110. package/dist/canvas/scenePickReads.js.map +1 -0
  111. package/dist/canvas/scenePickSource.js +74 -0
  112. package/dist/canvas/scenePickSource.js.map +1 -0
  113. package/dist/canvas/sceneSlotWiring.js +9 -4
  114. package/dist/canvas/sceneSlotWiring.js.map +1 -1
  115. package/dist/canvas/sceneViewRender.js +13 -8
  116. package/dist/canvas/sceneViewRender.js.map +1 -1
  117. package/dist/canvas/shownNodes.js +15 -0
  118. package/dist/canvas/shownNodes.js.map +1 -0
  119. package/dist/canvas/useCanvasPaint.js +3 -1
  120. package/dist/canvas/useCanvasPaint.js.map +1 -1
  121. package/dist/canvas/useSceneAdapter.js +5 -3
  122. package/dist/canvas/useSceneAdapter.js.map +1 -1
  123. package/dist/clipboard.d.ts +2 -2
  124. package/dist/{clone-C3e0OTuF.d.ts → clone-qb2e1F5p.d.ts} +2 -2
  125. package/dist/clone.d.ts +3 -3
  126. package/dist/core/isPlainObject.js +2 -2
  127. package/dist/core/layers/layerGroup.js.map +1 -1
  128. package/dist/core/layers/render.js.map +1 -1
  129. package/dist/core/scene/NodeRouting.js.map +1 -1
  130. package/dist/core/scene/arrivalWindow.js +1 -1
  131. package/dist/core/scene/arrivalWindow.js.map +1 -1
  132. package/dist/core/scene/clipNothing.js +2 -5
  133. package/dist/core/scene/clipNothing.js.map +1 -1
  134. package/dist/core/scene/declaredFieldSetters.js +44 -0
  135. package/dist/core/scene/declaredFieldSetters.js.map +1 -0
  136. package/dist/core/scene/depMemo.js +3 -0
  137. package/dist/core/scene/depMemo.js.map +1 -1
  138. package/dist/core/scene/dependents.js +3 -1
  139. package/dist/core/scene/dependents.js.map +1 -1
  140. package/dist/core/scene/documentOf.js +43 -0
  141. package/dist/core/scene/documentOf.js.map +1 -0
  142. package/dist/core/scene/effectivePose.js +37 -13
  143. package/dist/core/scene/effectivePose.js.map +1 -1
  144. package/dist/core/scene/fieldEdits.js +17 -14
  145. package/dist/core/scene/fieldEdits.js.map +1 -1
  146. package/dist/core/scene/historyForm.js +4 -4
  147. package/dist/core/scene/historyForm.js.map +1 -1
  148. package/dist/core/scene/inheritedPaint.js +27 -5
  149. package/dist/core/scene/inheritedPaint.js.map +1 -1
  150. package/dist/core/scene/kitOps.js +3 -23
  151. package/dist/core/scene/kitOps.js.map +1 -1
  152. package/dist/core/scene/layoutPass.js +1 -2
  153. package/dist/core/scene/layoutPass.js.map +1 -1
  154. package/dist/core/scene/nodeAsShown.js +72 -0
  155. package/dist/core/scene/nodeAsShown.js.map +1 -0
  156. package/dist/core/scene/nodeFnFields.js +2 -10
  157. package/dist/core/scene/nodeFnFields.js.map +1 -1
  158. package/dist/core/scene/nodeMemo.js +6 -1
  159. package/dist/core/scene/nodeMemo.js.map +1 -1
  160. package/dist/core/scene/nodeStore.js +2 -4
  161. package/dist/core/scene/nodeStore.js.map +1 -1
  162. package/dist/core/scene/pathEffects/derive.js +3 -2
  163. package/dist/core/scene/pathEffects/derive.js.map +1 -1
  164. package/dist/core/scene/pathEffects/foundHidden.js +35 -0
  165. package/dist/core/scene/pathEffects/foundHidden.js.map +1 -0
  166. package/dist/core/scene/plyStacks.js +89 -0
  167. package/dist/core/scene/plyStacks.js.map +1 -0
  168. package/dist/core/scene/poseHold.js +42 -24
  169. package/dist/core/scene/poseHold.js.map +1 -1
  170. package/dist/core/scene/poseOverrides.js +35 -38
  171. package/dist/core/scene/poseOverrides.js.map +1 -1
  172. package/dist/core/scene/posePlies.js +59 -0
  173. package/dist/core/scene/posePlies.js.map +1 -0
  174. package/dist/core/scene/reconcileSpecs.js +6 -15
  175. package/dist/core/scene/reconcileSpecs.js.map +1 -1
  176. package/dist/core/scene/renderOrder.js +10 -4
  177. package/dist/core/scene/renderOrder.js.map +1 -1
  178. package/dist/core/scene/sameValue.js +17 -0
  179. package/dist/core/scene/sameValue.js.map +1 -0
  180. package/dist/core/scene/scene.js +3 -3
  181. package/dist/core/scene/scene.js.map +1 -1
  182. package/dist/core/scene/sceneEdits.js +8 -0
  183. package/dist/core/scene/sceneEdits.js.map +1 -1
  184. package/dist/core/scene/sceneState.js +1 -2
  185. package/dist/core/scene/sceneState.js.map +1 -1
  186. package/dist/core/scene/serialization.js +45 -9
  187. package/dist/core/scene/serialization.js.map +1 -1
  188. package/dist/core/scene/staleReplay.js +5 -2
  189. package/dist/core/scene/staleReplay.js.map +1 -1
  190. package/dist/core/scene/statedFields.js +4 -2
  191. package/dist/core/scene/statedFields.js.map +1 -1
  192. package/dist/core/scene/treeEdits.js +2 -4
  193. package/dist/core/scene/treeEdits.js.map +1 -1
  194. package/dist/core/scene/treeOrder.js +3 -1
  195. package/dist/core/scene/treeOrder.js.map +1 -1
  196. package/dist/core/scene/treeReads.js +1 -2
  197. package/dist/core/scene/treeReads.js.map +1 -1
  198. package/dist/core/scene/treeShape.js +13 -0
  199. package/dist/core/scene/treeShape.js.map +1 -0
  200. package/dist/core/scene/types.js.map +1 -1
  201. package/dist/core/scene/useScene.js +1 -1
  202. package/dist/core/scene/useScene.js.map +1 -1
  203. package/dist/{cornerHandles-p8fDIAKt.d.ts → cornerHandles-CNCb7aTY.d.ts} +1 -1
  204. package/dist/{depSchema-mG19aEdD.d.ts → depSchema-CpIQzKWQ.d.ts} +38 -59
  205. package/dist/devtools/handlers.js +1 -1
  206. package/dist/devtools/handlers.js.map +1 -1
  207. package/dist/devtools/protocol.js.map +1 -1
  208. package/dist/devtools-protocol.d.ts +4 -3
  209. package/dist/devtools.d.ts +3 -2
  210. package/dist/features/measure/measureHit.js +5 -3
  211. package/dist/features/measure/measureHit.js.map +1 -1
  212. package/dist/features/measure/measurement.js +1 -1
  213. package/dist/features/measure/measurement.js.map +1 -1
  214. package/dist/features/modes/modeLayers.js +14 -7
  215. package/dist/features/modes/modeLayers.js.map +1 -1
  216. package/dist/features/modes/modeTriggers.js +3 -3
  217. package/dist/features/modes/modeTriggers.js.map +1 -1
  218. package/dist/features/pathEffects/effectSources.js +25 -16
  219. package/dist/features/pathEffects/effectSources.js.map +1 -1
  220. package/dist/features/pathEffects/readSource.js +1 -1
  221. package/dist/features/pathEffects/readSource.js.map +1 -1
  222. package/dist/features/pathEffects/useEffectSourcesLayer.js +15 -19
  223. package/dist/features/pathEffects/useEffectSourcesLayer.js.map +1 -1
  224. package/dist/features/paths/editablePath.js +1 -1
  225. package/dist/features/paths/editablePath.js.map +1 -1
  226. package/dist/features/paths/pathSnap/sceneIndex.js +1 -1
  227. package/dist/features/paths/pathSnap/sceneIndex.js.map +1 -1
  228. package/dist/features/selection/enteredGroupFrame.js +65 -0
  229. package/dist/features/selection/enteredGroupFrame.js.map +1 -0
  230. package/dist/features/selection/enteredGroupScope.js +44 -0
  231. package/dist/features/selection/enteredGroupScope.js.map +1 -0
  232. package/dist/features/text/sceneTextDrafts.js +26 -27
  233. package/dist/features/text/sceneTextDrafts.js.map +1 -1
  234. package/dist/features/text/textHitAt.js +4 -2
  235. package/dist/features/text/textHitAt.js.map +1 -1
  236. package/dist/features/text/useSceneTextEdit.js +3 -3
  237. package/dist/features/text/useSceneTextEdit.js.map +1 -1
  238. package/dist/features/viewports/viewportLayer.js +2 -1
  239. package/dist/features/viewports/viewportLayer.js.map +1 -1
  240. package/dist/index.d.ts +230 -77
  241. package/dist/index.js +16 -6
  242. package/dist/interactions/actions/admitsChild.js +11 -0
  243. package/dist/interactions/actions/admitsChild.js.map +1 -0
  244. package/dist/interactions/actions/defaults/contextMenu.js +16 -3
  245. package/dist/interactions/actions/defaults/contextMenu.js.map +1 -1
  246. package/dist/interactions/actions/defaults/createPaintAction.js +4 -1
  247. package/dist/interactions/actions/defaults/createPaintAction.js.map +1 -1
  248. package/dist/interactions/actions/defaults/enterGroup.js +88 -0
  249. package/dist/interactions/actions/defaults/enterGroup.js.map +1 -0
  250. package/dist/interactions/actions/defaults/enterPathEdit.js +1 -1
  251. package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
  252. package/dist/interactions/actions/defaults/enterTextEdit.js +1 -1
  253. package/dist/interactions/actions/defaults/enterTextEdit.js.map +1 -1
  254. package/dist/interactions/actions/defaults/group.js +7 -7
  255. package/dist/interactions/actions/defaults/group.js.map +1 -1
  256. package/dist/interactions/actions/defaults/selectAll.js +7 -3
  257. package/dist/interactions/actions/defaults/selectAll.js.map +1 -1
  258. package/dist/interactions/actions/defaults/selectDeep.js +35 -0
  259. package/dist/interactions/actions/defaults/selectDeep.js.map +1 -0
  260. package/dist/interactions/actions/drawnBoxes.js +2 -1
  261. package/dist/interactions/actions/drawnBoxes.js.map +1 -1
  262. package/dist/interactions/actions/insert/action.js +1 -0
  263. package/dist/interactions/actions/insert/action.js.map +1 -1
  264. package/dist/interactions/actions/insert/parent.js +7 -5
  265. package/dist/interactions/actions/insert/parent.js.map +1 -1
  266. package/dist/interactions/actions/insert/placeAction.js +3 -2
  267. package/dist/interactions/actions/insert/placeAction.js.map +1 -1
  268. package/dist/interactions/actions/insert/session.js +2 -2
  269. package/dist/interactions/actions/insert/session.js.map +1 -1
  270. package/dist/interactions/actions/move/commit/reparent.js +1 -1
  271. package/dist/interactions/actions/move/commit/reparent.js.map +1 -1
  272. package/dist/interactions/actions/move/gestureAdapter.js +6 -7
  273. package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
  274. package/dist/interactions/actions/move/layout/exits.js +1 -1
  275. package/dist/interactions/actions/move/layout/exits.js.map +1 -1
  276. package/dist/interactions/actions/move/session.js +4 -4
  277. package/dist/interactions/actions/move/session.js.map +1 -1
  278. package/dist/interactions/actions/pathCommands/pathNodes.js +14 -5
  279. package/dist/interactions/actions/pathCommands/pathNodes.js.map +1 -1
  280. package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +14 -2
  281. package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
  282. package/dist/{math-B56zxVs5.d.ts → math-C_elShP_.d.ts} +2 -5
  283. package/dist/math.d.ts +1 -1
  284. package/dist/move.d.ts +4 -4
  285. package/dist/{options-DBxEryYq.d.ts → options-ClEm3SEl.d.ts} +1 -1
  286. package/dist/resize.d.ts +4 -4
  287. package/dist/test-seams.d.ts +6 -6
  288. package/dist/tools/builtin/pressTarget.js +22 -0
  289. package/dist/tools/builtin/pressTarget.js.map +1 -0
  290. package/dist/tools/builtin/select/adapterPointQuery.js +3 -3
  291. package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
  292. package/dist/tools/builtin/select/collapseDeferred.js +40 -0
  293. package/dist/tools/builtin/select/collapseDeferred.js.map +1 -0
  294. package/dist/tools/builtin/select/groupEntry.js +82 -0
  295. package/dist/tools/builtin/select/groupEntry.js.map +1 -0
  296. package/dist/tools/builtin/select/pressDecision.js +1 -1
  297. package/dist/tools/builtin/select/pressDecision.js.map +1 -1
  298. package/dist/tools/builtin/select/useSelectTool.js +61 -45
  299. package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
  300. package/dist/{types-7puAuVD2.d.ts → types-49uYJN3j.d.ts} +1 -1
  301. package/dist/{types-CniVctmk.d.ts → types-BEdRIhNc.d.ts} +272 -109
  302. package/dist/{types-oFeQ5VjV.d.ts → types-p2alu-R1.d.ts} +1 -1
  303. package/dist/version.js +1 -1
  304. package/package.json +25 -25
@@ -1 +1 @@
1
- {"version":3,"file":"buildSceneTree.js","names":[],"sources":["../../src/canvas/buildSceneTree.ts"],"sourcesContent":["import type { DrawCommand, GroupDrawCommand } from '@weasel-js/renderer';\nimport type { View } from 'core/viewport/view';\nimport { findShapeSilhouette } from './NodeShape';\nimport type { Node } from 'core/scene/types';\nimport { mat3, type Affine, type Path } from '@weasel-js/geom';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { deriveParallaxView, planeMap, type ParallaxOpts } from 'core/viewport/parallax';\nimport { scenePlaneOf } from './pickWalk';\nimport { clipCarrier, planeTransform } from './planeClips';\nimport { splitOverChildren } from './overChildren';\nimport { hidesSubtree } from 'core/scene/nodeGates';\n\n/** The scene-tree reading surface `buildSceneTree` walks. A `SceneCanvasAdapter` is one. */\nexport interface HierarchicalAdapter<TNode, TPose> {\n getLayers(): readonly { id: string; visible: boolean; parallax?: ParallaxOpts }[];\n getNode(id: string): TNode | undefined;\n getChildren(parentId: string | null): readonly string[];\n getPose(id: string): TPose;\n /** Folds a child's local pose into its parent's frame. Absent means the\n * scene stores absolute poses and a parent contributes no transform —\n * see `PoseComposition`. */\n composePose?(parent: TPose, child: TPose): TPose;\n}\n\n/** A clip on the chain, with the layer whose world it is drawn in, or the\n * transform of a copy a container draws — see `ContainerNode.copiesFromPose`. */\ntype ChainEntry = { path: Path; layer: string } | { copy: Affine };\n\n/** Wrap `cmds` in one nested group per chain entry, so the renderer intersects\n * the clips and applies each copy's transform to everything inside it.\n * Outermost group carries the ancestor-most entry; innermost holds `cmds`. */\nfunction wrapInChain(\n cmds: DrawCommand[],\n chain: readonly ChainEntry[],\n toLayer: string,\n carry: ReturnType<typeof clipCarrier>,\n): DrawCommand {\n let node: GroupDrawCommand = { kind: 'group', children: cmds };\n for (let i = chain.length - 1; i >= 0; i--) {\n const e = chain[i];\n node = 'copy' in e\n ? { kind: 'group', children: [node], transform: mat3.fromAffine(e.copy) }\n : { kind: 'group', children: [node], clip: carry(e.path, e.layer, toLayer) };\n }\n return node;\n}\n\n/**\n * Walk the adapter's scene tree once and emit each node's own paint into the bucket for\n * **that node's own `layer`** — not its parent's. A node carrying `hidden` is skipped with\n * its whole subtree; see `nodeGates`. So a child whose `layer` differs from its\n * parent draws in its own layer's pass while staying a tree child for hit-testing / move /\n * reparent. Output is one group per visible layer, in adapter (`getLayers`) order.\n *\n * A node paints before its children. What its `drawOne` wraps in `overChildren` paints after\n * them instead, in the node's own layer.\n *\n * `drawOne` returns world-coord commands. Because a node may be drawn outside its parent's\n * group, the tree nesting cannot carry geometry as renderer state; the walk folds each node's\n * pose into its parent's frame on the way down and hands the painter a **world** pose. Clips\n * are accumulated the same way — each in its container's plane, carried into the plane of the\n * node it clips. With no `composePose` on the adapter the fold is the identity.\n *\n * A layer carrying `parallax` is a plane: its painters and its cull see the view derived for\n * it, and its group carries the transform from its world to the camera's, so the caller's\n * single camera wrap still lands it right.\n */\nexport function buildSceneTree<\n TNode extends { id: string; layer: string; hidden?: boolean },\n TPose,\n>(\n adapter: HierarchicalAdapter<TNode, TPose>,\n drawOne: (obj: TNode, pose: TPose, view: View) => DrawCommand[],\n view: View,\n /** When set, only nodes on this layer paint (others are still walked for\n * ancestor clips) and only this layer's group is returned. */\n forLayer?: string,\n /** The path a container computes from its dependencies' poses: the scene's\n * lookup, or `adapterDerivedPathOf` for an adapter with no scene. Left out,\n * a derived container contributes no clip. */\n derivedPathOf?: (node: TNode, pose: TPose) => Path | null,\n /** True for a node whose paint cannot be seen — see `paintMissesView`. Its\n * painter is not called; its clip and its children are walked as usual. */\n culled?: (node: TNode, pose: TPose, view: View) => boolean,\n): DrawCommand[] {\n const layers = adapter.getLayers();\n // A hidden layer gets no bucket, and a node with no bucket is not painted.\n const buckets = new Map<string, DrawCommand[]>();\n for (const l of layers) if (l.visible) buckets.set(l.id, []);\n let planeViews: Map<string, View> | null = null;\n for (const l of layers) {\n if (l.parallax) (planeViews ??= new Map()).set(l.id, deriveParallaxView(view, l.parallax));\n }\n\n const compose = adapter.composePose?.bind(adapter);\n const carry = clipCarrier(planeViews ? scenePlaneOf(layers, view) : null);\n\n function visit(\n id: string,\n ancestorClips: readonly ChainEntry[],\n parentFrame: TPose | null,\n /** Under a copy: the pose is not where it paints, so the cull cannot judge it. */\n copied: boolean,\n ): void {\n const node = adapter.getNode(id);\n if (!node || hidesSubtree(node)) return;\n const local = adapter.getPose(id);\n // Fold once, on the way down: O(1) per node where walking the parent chain\n // per node would be O(depth).\n const pose = compose && parentFrame !== null ? compose(parentFrame, local) : local;\n // Skip the (potentially expensive) painter for nodes we won't emit; their\n // clip still extends the chain for descendants below.\n const bucket = forLayer === undefined || node.layer === forLayer\n ? buckets.get(node.layer) : undefined;\n const v = planeViews?.get(node.layer) ?? view;\n const { under: self, over } = splitOverChildren(\n bucket && (copied || !culled?.(node, pose, v)) ? drawOne(node, pose, v) : [],\n );\n\n // Extend the clip chain with this node's own clip when it is a container.\n let ownClips = ancestorClips;\n let ownClip: ChainEntry | null = null;\n const maybeContainer = node as {\n kind?: string;\n clipFromPose?: (pose: TPose) => unknown;\n copiesFromPose?: (pose: TPose, node: unknown) => readonly Affine[] | null;\n };\n if (maybeContainer.kind === 'container') {\n let clip: unknown;\n if (typeof maybeContainer.clipFromPose === 'function') {\n // Explicit per-node clip wins — no fallback to the painter silhouette.\n clip = maybeContainer.clipFromPose(pose);\n } else {\n // No explicit clip → the painter silhouette for the container's shape kind.\n clip = findShapeSilhouette(\n node as unknown as Node<unknown, string, TPose>,\n pose,\n { derivedPath: derivedPathOf?.(node, pose) },\n );\n }\n if (clip) {\n ownClip = { path: clip as Path, layer: node.layer };\n ownClips = [...ancestorClips, ownClip];\n }\n }\n\n // Every node emits a wrapper group even with empty paint, keeping the per-node tree\n // shape stable.\n if (bucket) {\n bucket.push(ownClips.length > 0 ? wrapInChain(self, ownClips, node.layer, carry) : { kind: 'group', children: self });\n }\n\n // An envelope's children share its own parent's frame.\n const childFrame = definesFrame(node as never) ? pose : parentFrame;\n const children = adapter.getChildren(id);\n for (const cid of children) visit(cid, ownClips, childFrame, copied);\n\n // A copy is a copy of the clipped content, so its transform encloses the\n // container's own clip and sits inside every clip above it.\n const copies = typeof maybeContainer.copiesFromPose === 'function'\n ? maybeContainer.copiesFromPose(pose, node) : null;\n for (const copy of copies ?? []) {\n const chain: ChainEntry[] = [...ancestorClips, { copy }, ...(ownClip ? [ownClip] : [])];\n for (const cid of children) visit(cid, chain, childFrame, true);\n }\n\n if (bucket && over.length > 0) {\n bucket.push(ownClips.length > 0 ? wrapInChain(over, ownClips, node.layer, carry) : { kind: 'group', children: over });\n }\n }\n\n for (const rootId of adapter.getChildren(null)) visit(rootId, [], null, false);\n\n const out: DrawCommand[] = [];\n for (const layer of layers) {\n if (!layer.visible) continue;\n if (forLayer !== undefined && layer.id !== forLayer) continue;\n const children = buckets.get(layer.id) ?? [];\n const transform = layer.parallax ? planeTransform(planeMap(view, layer.parallax), null) : undefined;\n out.push(transform ? { kind: 'group', transform, children } : { kind: 'group', children });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,SAAS,YACP,MACA,OACA,SACA,OACa;CACb,IAAI,OAAyB;EAAE,MAAM;EAAS,UAAU;CAAK;CAC7D,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,IAAI,MAAM;EAChB,OAAO,UAAU,IACb;GAAE,MAAM;GAAS,UAAU,CAAC,IAAI;GAAG,WAAW,KAAK,WAAW,EAAE,IAAI;EAAE,IACtE;GAAE,MAAM;GAAS,UAAU,CAAC,IAAI;GAAG,MAAM,MAAM,EAAE,MAAM,EAAE,OAAO,OAAO;EAAE;CAC/E;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,eAId,SACA,SACA,MAGA,UAIA,eAGA,QACe;CACf,MAAM,SAAS,QAAQ,UAAU;CAEjC,MAAM,0BAAU,IAAI,IAA2B;CAC/C,KAAK,MAAM,KAAK,QAAQ,IAAI,EAAE,SAAS,QAAQ,IAAI,EAAE,IAAI,CAAC,CAAC;CAC3D,IAAI,aAAuC;CAC3C,KAAK,MAAM,KAAK,QACd,IAAI,EAAE,UAAU,CAAC,+BAAe,IAAI,IAAI,EAAA,CAAG,IAAI,EAAE,IAAI,mBAAmB,MAAM,EAAE,QAAQ,CAAC;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AAO,eAAe,mBAAmB,aACpD,eAAe,eAAe,MAAM,IAAI,IAAI;EAChD,KAAK,MAAM,QAAQ,UAAU,CAAC,GAAG;GAC/B,MAAM,QAAsB;IAAC,GAAG;IAAe,EAAE,KAAK;IAAG,GAAI,UAAU,CAAC,OAAO,IAAI,CAAC;GAAE;GACtF,KAAK,MAAM,OAAO,UAAU,MAAM,KAAK,OAAO,YAAY,IAAI;EAChE;EAEA,IAAI,UAAU,KAAK,SAAS,GAC1B,OAAO,KAAK,SAAS,SAAS,IAAI,YAAY,MAAM,UAAU,KAAK,OAAO,KAAK,IAAI;GAAE,MAAM;GAAS,UAAU;EAAK,CAAC;CAExH;CAEA,KAAK,MAAM,UAAU,QAAQ,YAAY,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,MAAM,KAAK;CAE7E,MAAM,MAAqB,CAAC;CAC5B,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,aAAa,UAAa,MAAM,OAAO,UAAU;EACrD,MAAM,WAAW,QAAQ,IAAI,MAAM,EAAE,KAAK,CAAC;EAC3C,MAAM,YAAY,MAAM,WAAW,eAAe,SAAS,MAAM,MAAM,QAAQ,GAAG,IAAI,IAAI;EAC1F,IAAI,KAAK,YAAY;GAAE,MAAM;GAAS;GAAW;EAAS,IAAI;GAAE,MAAM;GAAS;EAAS,CAAC;CAC3F;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"buildSceneTree.js","names":[],"sources":["../../src/canvas/buildSceneTree.ts"],"sourcesContent":["import type { DrawCommand, GroupDrawCommand } from '@weasel-js/renderer';\nimport type { View } from 'core/viewport/view';\nimport { ownClipOf, type ClipBearing } from './ownClip';\nimport { mat3, type Affine, type Path } from '@weasel-js/geom';\nimport { definesFrame } from 'core/scene/effectivePose';\nimport { deriveParallaxView, planeMap, type ParallaxOpts } from 'core/viewport/parallax';\nimport { scenePlaneOf } from './pickWalk';\nimport { clipCarrier, planeTransform } from './planeClips';\nimport { splitOverChildren } from './overChildren';\nimport { hidesSubtree } from 'core/scene/nodeGates';\n\n/** The scene-tree reading surface `buildSceneTree` walks. A `SceneCanvasAdapter` is one. */\nexport interface HierarchicalAdapter<TNode, TPose> {\n getLayers(): readonly { id: string; visible: boolean; parallax?: ParallaxOpts }[];\n getNode(id: string): TNode | undefined;\n getChildren(parentId: string | null): readonly string[];\n getPose(id: string): TPose;\n /** Folds a child's local pose into its parent's frame. Absent means the\n * scene stores absolute poses and a parent contributes no transform —\n * see `PoseComposition`. */\n composePose?(parent: TPose, child: TPose): TPose;\n}\n\n/** A clip on the chain, with the layer whose world it is drawn in, or the\n * transform of a copy a container draws — see `GroupNode.copiesFromPose`. */\ntype ChainEntry = { path: Path; layer: string } | { copy: Affine };\n\n/** Wrap `cmds` in one nested group per chain entry, so the renderer intersects\n * the clips and applies each copy's transform to everything inside it.\n * Outermost group carries the ancestor-most entry; innermost holds `cmds`. */\nfunction wrapInChain(\n cmds: DrawCommand[],\n chain: readonly ChainEntry[],\n toLayer: string,\n carry: ReturnType<typeof clipCarrier>,\n): DrawCommand {\n let node: GroupDrawCommand = { kind: 'group', children: cmds };\n for (let i = chain.length - 1; i >= 0; i--) {\n const e = chain[i];\n node = 'copy' in e\n ? { kind: 'group', children: [node], transform: mat3.fromAffine(e.copy) }\n : { kind: 'group', children: [node], clip: carry(e.path, e.layer, toLayer) };\n }\n return node;\n}\n\n/**\n * Walk the adapter's scene tree once and emit each node's own paint into the bucket for\n * **that node's own `layer`** — not its parent's. A node carrying `hidden` is skipped with\n * its whole subtree; see `nodeGates`. So a child whose `layer` differs from its\n * parent draws in its own layer's pass while staying a tree child for hit-testing / move /\n * reparent. Output is one group per visible layer, in adapter (`getLayers`) order.\n *\n * A node paints before its children. What its `drawOne` wraps in `overChildren` paints after\n * them instead, in the node's own layer.\n *\n * `drawOne` returns world-coord commands. Because a node may be drawn outside its parent's\n * group, the tree nesting cannot carry geometry as renderer state; the walk folds each node's\n * pose into its parent's frame on the way down and hands the painter a **world** pose. Clips\n * are accumulated the same way — each in its container's plane, carried into the plane of the\n * node it clips. With no `composePose` on the adapter the fold is the identity.\n *\n * A layer carrying `parallax` is a plane: its painters and its cull see the view derived for\n * it, and its group carries the transform from its world to the camera's, so the caller's\n * single camera wrap still lands it right.\n */\nexport function buildSceneTree<\n TNode extends { id: string; layer: string; hidden?: boolean },\n TPose,\n>(\n adapter: HierarchicalAdapter<TNode, TPose>,\n drawOne: (obj: TNode, pose: TPose, view: View) => DrawCommand[],\n view: View,\n /** When set, only nodes on this layer paint (others are still walked for\n * ancestor clips) and only this layer's group is returned. */\n forLayer?: string,\n /** The path a container computes from its dependencies' poses: the scene's\n * lookup, or `adapterDerivedPathOf` for an adapter with no scene. Left out,\n * a derived container contributes no clip. */\n derivedPathOf?: (node: TNode, pose: TPose) => Path | null,\n /** True for a node whose paint cannot be seen — see `paintMissesView`. Its\n * painter is not called; its clip and its children are walked as usual. */\n culled?: (node: TNode, pose: TPose, view: View) => boolean,\n): DrawCommand[] {\n const layers = adapter.getLayers();\n // A hidden layer gets no bucket, and a node with no bucket is not painted.\n const buckets = new Map<string, DrawCommand[]>();\n for (const l of layers) if (l.visible) buckets.set(l.id, []);\n let planeViews: Map<string, View> | null = null;\n for (const l of layers) {\n if (l.parallax) (planeViews ??= new Map()).set(l.id, deriveParallaxView(view, l.parallax));\n }\n\n const compose = adapter.composePose?.bind(adapter);\n const carry = clipCarrier(planeViews ? scenePlaneOf(layers, view) : null);\n\n function visit(\n id: string,\n ancestorClips: readonly ChainEntry[],\n parentFrame: TPose | null,\n /** Under a copy: the pose is not where it paints, so the cull cannot judge it. */\n copied: boolean,\n ): void {\n const node = adapter.getNode(id);\n if (!node || hidesSubtree(node)) return;\n const local = adapter.getPose(id);\n // Fold once, on the way down: O(1) per node where walking the parent chain\n // per node would be O(depth).\n const pose = compose && parentFrame !== null ? compose(parentFrame, local) : local;\n // Skip the (potentially expensive) painter for nodes we won't emit; their\n // clip still extends the chain for descendants below.\n const bucket = forLayer === undefined || node.layer === forLayer\n ? buckets.get(node.layer) : undefined;\n const v = planeViews?.get(node.layer) ?? view;\n const { under: self, over } = splitOverChildren(\n bucket && (copied || !culled?.(node, pose, v)) ? drawOne(node, pose, v) : [],\n );\n\n let ownClips = ancestorClips;\n let ownClip: ChainEntry | null = null;\n const maybeContainer = node as ClipBearing<TPose> & {\n copiesFromPose?: (pose: TPose, node: unknown) => readonly Affine[] | null;\n };\n const clip = ownClipOf(maybeContainer, pose, () => derivedPathOf?.(node, pose));\n if (clip) {\n ownClip = { path: clip, layer: node.layer };\n ownClips = [...ancestorClips, ownClip];\n }\n\n // Every node emits a wrapper group even with empty paint, keeping the per-node tree\n // shape stable. A node's own clip is its children's, so its own paint, over\n // its children or under them, takes only the clips above it.\n const wrap = (cmds: DrawCommand[]): DrawCommand => (ancestorClips.length > 0\n ? wrapInChain(cmds, ancestorClips, node.layer, carry) : { kind: 'group', children: cmds });\n if (bucket) bucket.push(wrap(self));\n\n // An envelope's children share its own parent's frame.\n const childFrame = definesFrame(node as never) ? pose : parentFrame;\n const children = adapter.getChildren(id);\n for (const cid of children) visit(cid, ownClips, childFrame, copied);\n\n // A copy is a copy of the clipped content, so its transform encloses the\n // container's own clip and sits inside every clip above it.\n const copies = typeof maybeContainer.copiesFromPose === 'function'\n ? maybeContainer.copiesFromPose(pose, node) : null;\n for (const copy of copies ?? []) {\n const chain: ChainEntry[] = [...ancestorClips, { copy }, ...(ownClip ? [ownClip] : [])];\n for (const cid of children) visit(cid, chain, childFrame, true);\n }\n\n if (bucket && over.length > 0) bucket.push(wrap(over));\n }\n\n for (const rootId of adapter.getChildren(null)) visit(rootId, [], null, false);\n\n const out: DrawCommand[] = [];\n for (const layer of layers) {\n if (!layer.visible) continue;\n if (forLayer !== undefined && layer.id !== forLayer) continue;\n const children = buckets.get(layer.id) ?? [];\n const transform = layer.parallax ? planeTransform(planeMap(view, layer.parallax), null) : undefined;\n out.push(transform ? { kind: 'group', transform, children } : { kind: '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1B,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,aAAa,UAAa,MAAM,OAAO,UAAU;EACrD,MAAM,WAAW,QAAQ,IAAI,MAAM,EAAE,KAAK,CAAC;EAC3C,MAAM,YAAY,MAAM,WAAW,eAAe,SAAS,MAAM,MAAM,QAAQ,GAAG,IAAI,IAAI;EAC1F,IAAI,KAAK,YAAY;GAAE,MAAM;GAAS;GAAW;EAAS,IAAI;GAAE,MAAM;GAAS;EAAS,CAAC;CAC3F;CACA,OAAO;AACT"}
@@ -18,6 +18,10 @@ var TENANTS = /* @__PURE__ */ new WeakMap();
18
18
  /** Canvases whose context the renderer refused, so a redraw does not rebuild
19
19
  * and fail again, and the reason is reported once. */
20
20
  var REFUSED = /* @__PURE__ */ new WeakSet();
21
+ /** The density a canvas given `dpr` paints at. */
22
+ function resolveDpr(dpr) {
23
+ return dpr ?? (typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1);
24
+ }
21
25
  /** Identifies a set of custom programs by their ids, in order. */
22
26
  var shaderKeyOf = (shaders) => shaders?.map((h) => h.id).join("|") ?? "";
23
27
  function registerShaders(renderer, shaders) {
@@ -42,7 +46,7 @@ function leaseCanvasRenderer() {
42
46
  const restored = createEmitter();
43
47
  const bind = (canvas, size, options = {}) => {
44
48
  const { width, height } = size;
45
- const dpr = size.dpr ?? (typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1);
49
+ const dpr = resolveDpr(size.dpr);
46
50
  const tile = options.tile ?? null;
47
51
  const shared = tile !== null;
48
52
  if (held && (held.canvas !== canvas || held.shared !== shared)) {
@@ -186,5 +190,5 @@ function releaseCanvasRenderer(canvas) {
186
190
  }
187
191
 
188
192
  //#endregion
189
- export { leaseCanvasRenderer, paintCanvas, releaseCanvasRenderer, shaderKeyOf };
193
+ export { leaseCanvasRenderer, paintCanvas, releaseCanvasRenderer, resolveDpr, shaderKeyOf };
190
194
  //# sourceMappingURL=canvasRenderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"canvasRenderer.js","names":["viewToMat3"],"sources":["../../src/canvas/canvasRenderer.ts"],"sourcesContent":["/**\n * The one renderer lifetime in core. Every on-screen surface holds its\n * `WeaselRenderer` through a `leaseCanvasRenderer` lease.\n *\n * A lease holds its own renderer, so several can share one element: each\n * tenant painting a `tile` of a shared buffer gets a renderer of its own on\n * the element's one context. Release frees only what that renderer created;\n * the context itself is never lost.\n */\nimport { WeaselRenderer, type FlattenTolerance, type ImageMinification, type RenderOptions } from '@weasel-js/renderer';\nimport { viewToMat3 } from '@weasel-js/geom';\nimport type { ShaderProgramHandle } from '@weasel-js/renderer';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport type { View } from '../core/viewport/view';\nimport { createEmitter } from '@weasel-js/registry';\nimport { CANVAS_CONTEXT_ATTRIBUTES } from './contextAttributes';\n\n/** The live renderers painting into each element, across every lease. */\nconst TENANTS: WeakMap<HTMLCanvasElement, Set<WeaselRenderer>> = new WeakMap();\n\n/** Canvases whose context the renderer refused, so a redraw does not rebuild\n * and fail again, and the reason is reported once. */\nconst REFUSED: WeakSet<HTMLCanvasElement> = new WeakSet();\n\n/** A renderer painting into the canvas, if any lease holds one. Test seam. */\nexport function cachedCanvasRenderer(canvas: HTMLCanvasElement): WeaselRenderer | undefined {\n const set = TENANTS.get(canvas);\n return set ? set.values().next().value : undefined;\n}\n\n/** The size and density to paint a canvas at. `dpr` defaults to\n * `window.devicePixelRatio`, read per paint. */\nexport interface CanvasPaintSize {\n width: number;\n height: number;\n dpr?: number;\n}\n\n/** How one paint reaches the canvas, beyond its size. */\nexport interface CanvasPaintOptions {\n /** Paint a `width × height` tile of a buffer other surfaces share, at this\n * origin in CSS pixels. The buffer is then the caller's to size: the\n * renderer never resizes the element, which would have every co-tenant\n * resize it to its own pane. Omit to own the whole element. */\n tile?: { x: number; y: number } | null;\n /** `WeaselRendererOptions.flattenTolerance`, applied from this paint on. */\n flattenTolerance?: FlattenTolerance;\n /** `WeaselRendererOptions.retainBudget`, applied from this paint on. */\n retainBudget?: number;\n /** `WeaselRendererOptions.imageMinification`, applied from this paint on. */\n imageMinification?: ImageMinification;\n /** Custom programs to compile on the renderer. Compiled when the renderer\n * is created, and again when the set of ids changes. */\n shaders?: readonly ShaderProgramHandle[];\n}\n\n/** A paint's options, plus what `paint` hands `WeaselRenderer.render`. */\nexport interface CanvasRenderOptions extends CanvasPaintOptions {\n render?: RenderOptions;\n}\n\n/** A canvas renderer held for a surface's lifetime. */\nexport interface CanvasRendererLease {\n /** Draw `commands` into `canvas` — screen-space, one unit per CSS pixel,\n * with `view` passed on as the frame's world→screen transform. `bind`,\n * then render. Returns `false` without painting where `bind` finds no\n * renderer. */\n paint(\n canvas: HTMLCanvasElement,\n commands: DrawCommand[],\n view: View,\n size: CanvasPaintSize,\n options?: CanvasRenderOptions,\n ): boolean;\n /** The renderer that paints `canvas` at `size`, ready to render: created on\n * first use, resized, and given this paint's tile, tolerance, retain\n * budget, and shaders.\n * Frees the previous renderer first if the surface moved to another\n * element, or between owning it whole and painting a tile of it. `null`\n * where no WebGL2 context is available (jsdom, a failed context creation,\n * or a context that is lost for now). */\n bind(canvas: HTMLCanvasElement, size: CanvasPaintSize, options?: CanvasPaintOptions): WeaselRenderer | null;\n /** Run `fn` when the canvas gets a lost context back, after the renderer\n * has rebuilt itself on it. Nothing repaints a restored buffer on its own.\n * Returns an unsubscribe. */\n subscribeRestored(fn: () => void): () => void;\n /** Free the held renderer and every GL object it owns. A later `paint`\n * creates a fresh one. */\n release(): void;\n}\n\ninterface Held {\n canvas: HTMLCanvasElement;\n renderer: WeaselRenderer;\n shared: boolean;\n lost: boolean;\n onLost: () => void;\n onRestored: () => void;\n width: number;\n height: number;\n dpr: number;\n tileX: number | null;\n tileY: number | null;\n flattenTolerance: FlattenTolerance | undefined;\n retainBudget: number | undefined;\n imageMinification: ImageMinification | undefined;\n shaderKey: string;\n}\n\n/** Identifies a set of custom programs by their ids, in order. */\nexport const shaderKeyOf = (shaders: readonly ShaderProgramHandle[] | undefined): string =>\n shaders?.map((h) => h.id).join('|') ?? '';\n\nfunction registerShaders(renderer: WeaselRenderer, shaders: readonly ShaderProgramHandle[] | undefined): void {\n if (!shaders) return;\n for (const handle of shaders) {\n try {\n renderer.registerProgram(handle);\n } catch (e) {\n console.warn(`weasel: failed to register shader \"${handle.id}\":`, e);\n }\n }\n}\n\nfunction free(held: Held): void {\n const set = TENANTS.get(held.canvas);\n set?.delete(held.renderer);\n held.canvas.removeEventListener('webglcontextlost', held.onLost);\n held.canvas.removeEventListener('webglcontextrestored', held.onRestored);\n if (set && set.size === 0) TENANTS.delete(held.canvas);\n held.renderer.dispose();\n}\n\n/** Hold the renderer of the canvas a surface paints into, until released. */\nexport function leaseCanvasRenderer(): CanvasRendererLease {\n let held: Held | null = null;\n const restored = createEmitter();\n const bind = (canvas: HTMLCanvasElement, size: CanvasPaintSize, options: CanvasPaintOptions = {}): WeaselRenderer | null => {\n const { width, height } = size;\n const dpr = size.dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);\n const tile = options.tile ?? null;\n const shared = tile !== null;\n\n if (held && (held.canvas !== canvas || held.shared !== shared)) {\n free(held);\n held = null;\n }\n if (!held) {\n if (REFUSED.has(canvas)) return null;\n const gl = canvas.getContext('webgl2', CANVAS_CONTEXT_ATTRIBUTES);\n if (!gl || typeof (gl as Partial<WebGL2RenderingContext>).enable !== 'function') return null;\n let renderer: WeaselRenderer;\n try {\n renderer = new WeaselRenderer({\n gl: gl as WebGL2RenderingContext,\n ...(shared ? {} : { canvas }),\n width, height, dpr,\n flattenTolerance: options.flattenTolerance,\n retainBudget: options.retainBudget,\n imageMinification: options.imageMinification,\n });\n } catch (e) {\n // A lost context fails to compile and may yet come back; anything\n // else fails the same way next time.\n if (!(gl as Partial<WebGL2RenderingContext>).isContextLost?.()) {\n REFUSED.add(canvas);\n console.warn('weasel: this canvas cannot be painted:', e);\n }\n return null;\n }\n // Added after the renderer's own listeners, so a subscriber runs against\n // a renderer that has already recompiled.\n const mine: Held = held = {\n canvas, renderer, shared, width, height, dpr, tileX: null, tileY: null,\n flattenTolerance: options.flattenTolerance, retainBudget: options.retainBudget,\n imageMinification: options.imageMinification, shaderKey: '',\n lost: false,\n onLost: () => { mine.lost = true; },\n onRestored: () => {\n mine.lost = false;\n restored.emit();\n },\n };\n canvas.addEventListener('webglcontextlost', held.onLost);\n canvas.addEventListener('webglcontextrestored', held.onRestored);\n let set = TENANTS.get(canvas);\n if (!set) { set = new Set(); TENANTS.set(canvas, set); }\n set.add(renderer);\n } else {\n // React writes the element's `width` and `height` attributes in CSS\n // pixels on every size change, so a size that went away and came back\n // matches the record while the buffer does not.\n const stale = !shared\n && (canvas.width !== Math.round(width * dpr) || canvas.height !== Math.round(height * dpr));\n if (stale || held.width !== width || held.height !== height || held.dpr !== dpr) {\n held.renderer.resize({ width, height, dpr });\n held.width = width;\n held.height = height;\n held.dpr = dpr;\n }\n if (held.flattenTolerance !== options.flattenTolerance) {\n held.renderer.setFlattenTolerance(options.flattenTolerance);\n held.flattenTolerance = options.flattenTolerance;\n }\n if (held.retainBudget !== options.retainBudget) {\n held.renderer.setRetainBudget(options.retainBudget);\n held.retainBudget = options.retainBudget;\n }\n if (held.imageMinification !== options.imageMinification) {\n held.renderer.setImageMinification(options.imageMinification);\n held.imageMinification = options.imageMinification;\n }\n }\n\n if (held.lost) return null;\n const { renderer } = held;\n const shaderKey = shaderKeyOf(options.shaders);\n if (shaderKey !== held.shaderKey) {\n registerShaders(renderer, options.shaders);\n held.shaderKey = shaderKey;\n }\n const tileX = tile?.x ?? null;\n const tileY = tile?.y ?? null;\n if (tileX !== held.tileX || tileY !== held.tileY) {\n renderer.setTarget(tile ? { origin: { x: tile.x, y: tile.y } } : null);\n held.tileX = tileX;\n held.tileY = tileY;\n }\n return renderer;\n };\n return {\n bind,\n paint(canvas, commands, view, size, options) {\n const renderer = bind(canvas, size, options);\n if (!renderer) return false;\n renderer.render(commands, viewToMat3(view), options?.render);\n return true;\n },\n subscribeRestored: restored.subscribe,\n release() {\n if (held) free(held);\n held = null;\n },\n };\n}\n\n/** Leases held on a canvas's behalf by `paintCanvas`, one per element. */\nconst CANVAS_LEASES: WeakMap<HTMLCanvasElement, CanvasRendererLease> = new WeakMap();\n\n/**\n * Paint `canvas` through a lease held for the element itself, for callers\n * with no component lifetime of their own. The renderer lives until\n * `releaseCanvasRenderer(canvas)`.\n */\nexport function paintCanvas(\n canvas: HTMLCanvasElement,\n commands: DrawCommand[],\n view: View,\n size: CanvasPaintSize,\n): boolean {\n let lease = CANVAS_LEASES.get(canvas);\n if (!lease) {\n lease = leaseCanvasRenderer();\n CANVAS_LEASES.set(canvas, lease);\n }\n return lease.paint(canvas, commands, view, size);\n}\n\n/** Free the renderer `paintCanvas` holds for the canvas, and every GL object\n * it owns. The next paint creates a fresh one. Renderers a surface component\n * holds are that component's to free, on unmount. */\nexport function releaseCanvasRenderer(canvas: HTMLCanvasElement): void {\n const lease = CANVAS_LEASES.get(canvas);\n if (!lease) return;\n CANVAS_LEASES.delete(canvas);\n lease.release();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAM,0BAA2D,IAAI,QAAQ;;;AAI7E,IAAM,0BAAsC,IAAI,QAAQ;;AAwFxD,IAAa,eAAe,YAC1B,SAAS,KAAK,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,KAAK;AAEzC,SAAS,gBAAgB,UAA0B,SAA2D;CAC5G,IAAI,CAAC,SAAS;CACd,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,SAAS,gBAAgB,MAAM;CACjC,SAAS,GAAG;EACV,QAAQ,KAAK,sCAAsC,OAAO,GAAG,KAAK,CAAC;CACrE;AAEJ;AAEA,SAAS,KAAK,MAAkB;CAC9B,MAAM,MAAM,QAAQ,IAAI,KAAK,MAAM;CACnC,KAAK,OAAO,KAAK,QAAQ;CACzB,KAAK,OAAO,oBAAoB,oBAAoB,KAAK,MAAM;CAC/D,KAAK,OAAO,oBAAoB,wBAAwB,KAAK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AAG,GAAG,KAAK;GAAE,EAAE,IAAI,IAAI;GACrE,KAAK,QAAQ;GACb,KAAK,QAAQ;EACf;EACA,OAAO;CACT;CACA,OAAO;EACL;EACA,MAAM,QAAQ,UAAU,MAAM,MAAM,SAAS;GAC3C,MAAM,WAAW,KAAK,QAAQ,MAAM,OAAO;GAC3C,IAAI,CAAC,UAAU,OAAO;GACtB,SAAS,OAAO,UAAUA,aAAW,IAAI,GAAG,SAAS,MAAM;GAC3D,OAAO;EACT;EACA,mBAAmB,SAAS;EAC5B,UAAU;GACR,IAAI,MAAM,KAAK,IAAI;GACnB,OAAO;EACT;CACF;AACF;;AAGA,IAAM,gCAAiE,IAAI,QAAQ;;;;;;AAOnF,SAAgB,YACd,QACA,UACA,MACA,MACS;CACT,IAAI,QAAQ,cAAc,IAAI,MAAM;CACpC,IAAI,CAAC,OAAO;EACV,QAAQ,oBAAoB;EAC5B,cAAc,IAAI,QAAQ,KAAK;CACjC;CACA,OAAO,MAAM,MAAM,QAAQ,UAAU,MAAM,IAAI;AACjD;;;;AAKA,SAAgB,sBAAsB,QAAiC;CACrE,MAAM,QAAQ,cAAc,IAAI,MAAM;CACtC,IAAI,CAAC,OAAO;CACZ,cAAc,OAAO,MAAM;CAC3B,MAAM,QAAQ;AAChB"}
1
+ {"version":3,"file":"canvasRenderer.js","names":["viewToMat3"],"sources":["../../src/canvas/canvasRenderer.ts"],"sourcesContent":["/**\n * The one renderer lifetime in core. Every on-screen surface holds its\n * `WeaselRenderer` through a `leaseCanvasRenderer` lease.\n *\n * A lease holds its own renderer, so several can share one element: each\n * tenant painting a `tile` of a shared buffer gets a renderer of its own on\n * the element's one context. Release frees only what that renderer created;\n * the context itself is never lost.\n */\nimport { WeaselRenderer, type FlattenTolerance, type ImageMinification, type RenderOptions } from '@weasel-js/renderer';\nimport { viewToMat3 } from '@weasel-js/geom';\nimport type { ShaderProgramHandle } from '@weasel-js/renderer';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport type { View } from '../core/viewport/view';\nimport { createEmitter } from '@weasel-js/registry';\nimport { CANVAS_CONTEXT_ATTRIBUTES } from './contextAttributes';\n\n/** The live renderers painting into each element, across every lease. */\nconst TENANTS: WeakMap<HTMLCanvasElement, Set<WeaselRenderer>> = new WeakMap();\n\n/** Canvases whose context the renderer refused, so a redraw does not rebuild\n * and fail again, and the reason is reported once. */\nconst REFUSED: WeakSet<HTMLCanvasElement> = new WeakSet();\n\n/** A renderer painting into the canvas, if any lease holds one. Test seam. */\nexport function cachedCanvasRenderer(canvas: HTMLCanvasElement): WeaselRenderer | undefined {\n const set = TENANTS.get(canvas);\n return set ? set.values().next().value : undefined;\n}\n\n/** The size and density to paint a canvas at. `dpr` defaults to\n * `window.devicePixelRatio`, read per paint. */\nexport interface CanvasPaintSize {\n width: number;\n height: number;\n dpr?: number;\n}\n\n/** The density a canvas given `dpr` paints at. */\nexport function resolveDpr(dpr: number | undefined): number {\n return dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);\n}\n\n/** How one paint reaches the canvas, beyond its size. */\nexport interface CanvasPaintOptions {\n /** Paint a `width × height` tile of a buffer other surfaces share, at this\n * origin in CSS pixels. The buffer is then the caller's to size: the\n * renderer never resizes the element, which would have every co-tenant\n * resize it to its own pane. Omit to own the whole element. */\n tile?: { x: number; y: number } | null;\n /** `WeaselRendererOptions.flattenTolerance`, applied from this paint on. */\n flattenTolerance?: FlattenTolerance;\n /** `WeaselRendererOptions.retainBudget`, applied from this paint on. */\n retainBudget?: number;\n /** `WeaselRendererOptions.imageMinification`, applied from this paint on. */\n imageMinification?: ImageMinification;\n /** Custom programs to compile on the renderer. Compiled when the renderer\n * is created, and again when the set of ids changes. */\n shaders?: readonly ShaderProgramHandle[];\n}\n\n/** A paint's options, plus what `paint` hands `WeaselRenderer.render`. */\nexport interface CanvasRenderOptions extends CanvasPaintOptions {\n render?: RenderOptions;\n}\n\n/** A canvas renderer held for a surface's lifetime. */\nexport interface CanvasRendererLease {\n /** Draw `commands` into `canvas` — screen-space, one unit per CSS pixel,\n * with `view` passed on as the frame's world→screen transform. `bind`,\n * then render. Returns `false` without painting where `bind` finds no\n * renderer. */\n paint(\n canvas: HTMLCanvasElement,\n commands: DrawCommand[],\n view: View,\n size: CanvasPaintSize,\n options?: CanvasRenderOptions,\n ): boolean;\n /** The renderer that paints `canvas` at `size`, ready to render: created on\n * first use, resized, and given this paint's tile, tolerance, retain\n * budget, and shaders.\n * Frees the previous renderer first if the surface moved to another\n * element, or between owning it whole and painting a tile of it. `null`\n * where no WebGL2 context is available (jsdom, a failed context creation,\n * or a context that is lost for now). */\n bind(canvas: HTMLCanvasElement, size: CanvasPaintSize, options?: CanvasPaintOptions): WeaselRenderer | null;\n /** Run `fn` when the canvas gets a lost context back, after the renderer\n * has rebuilt itself on it. Nothing repaints a restored buffer on its own.\n * Returns an unsubscribe. */\n subscribeRestored(fn: () => void): () => void;\n /** Free the held renderer and every GL object it owns. A later `paint`\n * creates a fresh one. */\n release(): void;\n}\n\ninterface Held {\n canvas: HTMLCanvasElement;\n renderer: WeaselRenderer;\n shared: boolean;\n lost: boolean;\n onLost: () => void;\n onRestored: () => void;\n width: number;\n height: number;\n dpr: number;\n tileX: number | null;\n tileY: number | null;\n flattenTolerance: FlattenTolerance | undefined;\n retainBudget: number | undefined;\n imageMinification: ImageMinification | undefined;\n shaderKey: string;\n}\n\n/** Identifies a set of custom programs by their ids, in order. */\nexport const shaderKeyOf = (shaders: readonly ShaderProgramHandle[] | undefined): string =>\n shaders?.map((h) => h.id).join('|') ?? '';\n\nfunction registerShaders(renderer: WeaselRenderer, shaders: readonly ShaderProgramHandle[] | undefined): void {\n if (!shaders) return;\n for (const handle of shaders) {\n try {\n renderer.registerProgram(handle);\n } catch (e) {\n console.warn(`weasel: failed to register shader \"${handle.id}\":`, e);\n }\n }\n}\n\nfunction free(held: Held): void {\n const set = TENANTS.get(held.canvas);\n set?.delete(held.renderer);\n held.canvas.removeEventListener('webglcontextlost', held.onLost);\n held.canvas.removeEventListener('webglcontextrestored', held.onRestored);\n if (set && set.size === 0) TENANTS.delete(held.canvas);\n held.renderer.dispose();\n}\n\n/** Hold the renderer of the canvas a surface paints into, until released. */\nexport function leaseCanvasRenderer(): CanvasRendererLease {\n let held: Held | null = null;\n const restored = createEmitter();\n const bind = (canvas: HTMLCanvasElement, size: CanvasPaintSize, options: CanvasPaintOptions = {}): WeaselRenderer | null => {\n const { width, height } = size;\n const dpr = resolveDpr(size.dpr);\n const tile = options.tile ?? null;\n const shared = tile !== null;\n\n if (held && (held.canvas !== canvas || held.shared !== shared)) {\n free(held);\n held = null;\n }\n if (!held) {\n if (REFUSED.has(canvas)) return null;\n const gl = canvas.getContext('webgl2', CANVAS_CONTEXT_ATTRIBUTES);\n if (!gl || typeof (gl as Partial<WebGL2RenderingContext>).enable !== 'function') return null;\n let renderer: WeaselRenderer;\n try {\n renderer = new WeaselRenderer({\n gl: gl as WebGL2RenderingContext,\n ...(shared ? {} : { canvas }),\n width, height, dpr,\n flattenTolerance: options.flattenTolerance,\n retainBudget: options.retainBudget,\n imageMinification: options.imageMinification,\n });\n } catch (e) {\n // A lost context fails to compile and may yet come back; anything\n // else fails the same way next time.\n if (!(gl as Partial<WebGL2RenderingContext>).isContextLost?.()) {\n REFUSED.add(canvas);\n console.warn('weasel: this canvas cannot be painted:', e);\n }\n return null;\n }\n // Added after the renderer's own listeners, so a subscriber runs against\n // a renderer that has already recompiled.\n const mine: Held = held = {\n canvas, renderer, shared, width, height, dpr, tileX: null, tileY: null,\n flattenTolerance: options.flattenTolerance, retainBudget: options.retainBudget,\n imageMinification: options.imageMinification, shaderKey: '',\n lost: false,\n onLost: () => { mine.lost = true; },\n onRestored: () => {\n mine.lost = false;\n restored.emit();\n },\n };\n canvas.addEventListener('webglcontextlost', held.onLost);\n canvas.addEventListener('webglcontextrestored', held.onRestored);\n let set = TENANTS.get(canvas);\n if (!set) { set = new Set(); TENANTS.set(canvas, set); }\n set.add(renderer);\n } else {\n // React writes the element's `width` and `height` attributes in CSS\n // pixels on every size change, so a size that went away and came back\n // matches the record while the buffer does not.\n const stale = !shared\n && (canvas.width !== Math.round(width * dpr) || canvas.height !== Math.round(height * dpr));\n if (stale || held.width !== width || held.height !== height || held.dpr !== dpr) {\n held.renderer.resize({ width, height, dpr });\n held.width = width;\n held.height = height;\n held.dpr = dpr;\n }\n if (held.flattenTolerance !== options.flattenTolerance) {\n held.renderer.setFlattenTolerance(options.flattenTolerance);\n held.flattenTolerance = options.flattenTolerance;\n }\n if (held.retainBudget !== options.retainBudget) {\n held.renderer.setRetainBudget(options.retainBudget);\n held.retainBudget = options.retainBudget;\n }\n if (held.imageMinification !== options.imageMinification) {\n held.renderer.setImageMinification(options.imageMinification);\n held.imageMinification = options.imageMinification;\n }\n }\n\n if (held.lost) return null;\n const { renderer } = held;\n const shaderKey = shaderKeyOf(options.shaders);\n if (shaderKey !== held.shaderKey) {\n registerShaders(renderer, options.shaders);\n held.shaderKey = shaderKey;\n }\n const tileX = tile?.x ?? null;\n const tileY = tile?.y ?? null;\n if (tileX !== held.tileX || tileY !== held.tileY) {\n renderer.setTarget(tile ? { origin: { x: tile.x, y: tile.y } } : null);\n held.tileX = tileX;\n held.tileY = tileY;\n }\n return renderer;\n };\n return {\n bind,\n paint(canvas, commands, view, size, options) {\n const renderer = bind(canvas, size, options);\n if (!renderer) return false;\n renderer.render(commands, viewToMat3(view), options?.render);\n return true;\n },\n subscribeRestored: restored.subscribe,\n release() {\n if (held) free(held);\n held = null;\n },\n };\n}\n\n/** Leases held on a canvas's behalf by `paintCanvas`, one per element. */\nconst CANVAS_LEASES: WeakMap<HTMLCanvasElement, CanvasRendererLease> = new WeakMap();\n\n/**\n * Paint `canvas` through a lease held for the element itself, for callers\n * with no component lifetime of their own. The renderer lives until\n * `releaseCanvasRenderer(canvas)`.\n */\nexport function paintCanvas(\n canvas: HTMLCanvasElement,\n commands: DrawCommand[],\n view: View,\n size: CanvasPaintSize,\n): boolean {\n let lease = CANVAS_LEASES.get(canvas);\n if (!lease) {\n lease = leaseCanvasRenderer();\n CANVAS_LEASES.set(canvas, lease);\n }\n return lease.paint(canvas, commands, view, size);\n}\n\n/** Free the renderer `paintCanvas` holds for the canvas, and every GL object\n * it owns. The next paint creates a fresh one. Renderers a surface component\n * holds are that component's to free, on unmount. */\nexport function releaseCanvasRenderer(canvas: HTMLCanvasElement): void {\n const lease = CANVAS_LEASES.get(canvas);\n if (!lease) return;\n CANVAS_LEASES.delete(canvas);\n lease.release();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAM,0BAA2D,IAAI,QAAQ;;;AAI7E,IAAM,0BAAsC,IAAI,QAAQ;;AAiBxD,SAAgB,WAAW,KAAiC;CAC1D,OAAO,QAAQ,OAAO,WAAW,cAAc,OAAO,oBAAoB,IAAI;AAChF;;AA0EA,IAAa,eAAe,YAC1B,SAAS,KAAK,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,KAAK;AAEzC,SAAS,gBAAgB,UAA0B,SAA2D;CAC5G,IAAI,CAAC,SAAS;CACd,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,SAAS,gBAAgB,MAAM;CACjC,SAAS,GAAG;EACV,QAAQ,KAAK,sCAAsC,OAAO,GAAG,KAAK,CAAC;CACrE;AAEJ;AAEA,SAAS,KAAK,MAAkB;CAC9B,MAAM,MAAM,QAAQ,IAAI,KAAK,MAAM;CACnC,KAAK,OAAO,KAAK,QAAQ;CACzB,KAAK,OAAO,oBAAoB,oBAAoB,KAAK,MAAM;CAC/D,KAAK,OAAO,oBAAoB,wBAAwB,KAAK,UAAU;CACvE,IAAI,OAAO,IAAI,SAAS,GAAG,QAAQ,OAAO,KAAK,MAAM;CACrD,KAAK,SAAS,QAAQ;AACxB;;AAGA,SAAgB,sBAA2C;CACzD,IAAI,OAAoB;CACxB,MAAM,WAAW,cAAc;CAC/B,MAAM,QAAQ,QAA2B,MAAuB,UAA8B,CAAC,MAA6B;EAC1H,MAAM,EAAE,OAAO,W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,MAAM;GAC3D,OAAO;EACT;EACA,mBAAmB,SAAS;EAC5B,UAAU;GACR,IAAI,MAAM,KAAK,IAAI;GACnB,OAAO;EACT;CACF;AACF;;AAGA,IAAM,gCAAiE,IAAI,QAAQ;;;;;;AAOnF,SAAgB,YACd,QACA,UACA,MACA,MACS;CACT,IAAI,QAAQ,cAAc,IAAI,MAAM;CACpC,IAAI,CAAC,OAAO;EACV,QAAQ,oBAAoB;EAC5B,cAAc,IAAI,QAAQ,KAAK;CACjC;CACA,OAAO,MAAM,MAAM,QAAQ,UAAU,MAAM,IAAI;AACjD;;;;AAKA,SAAgB,sBAAsB,QAAiC;CACrE,MAAM,QAAQ,cAAc,IAAI,MAAM;CACtC,IAAI,CAAC,OAAO;CACZ,cAAc,OAAO,MAAM;CAC3B,MAAM,QAAQ;AAChB"}
@@ -20,7 +20,7 @@ function copiesWithin(scene, container, poseOf) {
20
20
  ]];
21
21
  for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {
22
22
  const a = scene.get(aid);
23
- if (a?.kind !== "container" || !a.copiesFromPose) continue;
23
+ if (!a?.copiesFromPose) continue;
24
24
  const copies = a.copiesFromPose(poseOf(a), a) ?? [];
25
25
  if (copies.length === 0) continue;
26
26
  all = all.flatMap((m) => [m, ...copies.map((c) => multiply(m, c))]);
@@ -1 +1 @@
1
- {"version":3,"file":"copiesAbove.js","names":[],"sources":["../../src/canvas/copiesAbove.ts"],"sourcesContent":["import { multiply, type Affine } from '@weasel-js/geom';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\n\n/**\n * Every transform content placed in `container` is drawn under besides as\n * authored: the `copiesFromPose` of the container and of each container above\n * it, composed outermost first, the identity left out. Empty for the top of\n * the tree, or when nothing there draws copies. `poseOf` is the pose a\n * container is painted at, which is what its copies are computed from.\n */\nexport function copiesWithin<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n container: NodeId | null,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n if (container === null || scene.get(container) === undefined) return [];\n let all: Affine[] = [[1, 0, 0, 1, 0, 0]];\n for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {\n const a = scene.get(aid);\n if (a?.kind !== 'container' || !a.copiesFromPose) continue;\n const copies = a.copiesFromPose(poseOf(a), a) ?? [];\n if (copies.length === 0) continue;\n // A copy at an outer level carries everything inside it, inner copies included.\n all = all.flatMap((m) => [m, ...copies.map((c) => multiply(m, c))]);\n }\n return all.slice(1);\n}\n\n/** Every transform the ancestors of `id` draw it under; see {@link copiesWithin}. */\nexport function copiesAbove<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n id: NodeId,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n return copiesWithin(scene, scene.get(id)?.parent ?? null, poseOf);\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,aACd,OACA,WACA,QACU;CACV,IAAI,cAAc,QAAQ,MAAM,IAAI,SAAS,MAAM,QAAW,OAAO,CAAC;CACtE,IAAI,MAAgB,CAAC;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC,CAAC;CACvC,KAAK,MAAM,OAAO,CAAC,WAAW,GAAG,MAAM,YAAY,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG;EACxE,MAAM,IAAI,MAAM,IAAI,GAAG;EACvB,IAAI,GAAG,SAAS,eAAe,CAAC,EAAE,gBAAgB;EAClD,MAAM,SAAS,EAAE,eAAe,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;EAClD,IAAI,OAAO,WAAW,GAAG;EAEzB,MAAM,IAAI,SAAS,MAAM,CAAC,GAAG,GAAG,OAAO,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;CACpE;CACA,OAAO,IAAI,MAAM,CAAC;AACpB;;AAGA,SAAgB,YACd,OACA,IACA,QACU;CACV,OAAO,aAAa,OAAO,MAAM,IAAI,EAAE,CAAC,EAAE,UAAU,MAAM,MAAM;AAClE"}
1
+ {"version":3,"file":"copiesAbove.js","names":[],"sources":["../../src/canvas/copiesAbove.ts"],"sourcesContent":["import { multiply, type Affine } from '@weasel-js/geom';\nimport type { Node, NodeId, Scene } from 'core/scene/types';\n\n/**\n * Every transform content placed in `container` is drawn under besides as\n * authored: the `copiesFromPose` of the container and of each container above\n * it, composed outermost first, the identity left out. Empty for the top of\n * the tree, or when nothing there draws copies. `poseOf` is the pose a\n * container is painted at, which is what its copies are computed from.\n */\nexport function copiesWithin<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n container: NodeId | null,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n if (container === null || scene.get(container) === undefined) return [];\n let all: Affine[] = [[1, 0, 0, 1, 0, 0]];\n for (const aid of [container, ...scene.ancestorsOf(container)].reverse()) {\n const a = scene.get(aid);\n if (!a?.copiesFromPose) continue;\n const copies = a.copiesFromPose(poseOf(a), a) ?? [];\n if (copies.length === 0) continue;\n // A copy at an outer level carries everything inside it, inner copies included.\n all = all.flatMap((m) => [m, ...copies.map((c) => multiply(m, c))]);\n }\n return all.slice(1);\n}\n\n/** Every transform the ancestors of `id` draw it under; see {@link copiesWithin}. */\nexport function copiesAbove<TData, TLayer extends string, TPose>(\n scene: Scene<TData, TLayer, TPose>,\n id: NodeId,\n poseOf: (node: Node<TData, TLayer, TPose>) => TPose,\n): Affine[] {\n return copiesWithin(scene, scene.get(id)?.parent ?? null, poseOf);\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,aACd,OACA,WACA,QACU;CACV,IAAI,cAAc,QAAQ,MAAM,IAAI,SAAS,MAAM,QAAW,OAAO,CAAC;CACtE,IAAI,MAAgB,CAAC;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC,CAAC;CACvC,KAAK,MAAM,OAAO,CAAC,WAAW,GAAG,MAAM,YAAY,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG;EACxE,MAAM,IAAI,MAAM,IAAI,GAAG;EACvB,IAAI,CAAC,GAAG,gBAAgB;EACxB,MAAM,SAAS,EAAE,eAAe,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;EAClD,IAAI,OAAO,WAAW,GAAG;EAEzB,MAAM,IAAI,SAAS,MAAM,CAAC,GAAG,GAAG,OAAO,KAAK,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;CACpE;CACA,OAAO,IAAI,MAAM,CAAC;AACpB;;AAGA,SAAgB,YACd,OACA,IACA,QACU;CACV,OAAO,aAAa,OAAO,MAAM,IAAI,EAAE,CAAC,EAAE,UAAU,MAAM,MAAM;AAClE"}
@@ -22,7 +22,7 @@ function viewOnlyCtx(view) {
22
22
  * registered node-shape painter that matches, then draw its `data.label` on
23
23
  * top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */
24
24
  function defaultDrawOne(node, pose, view, ctx) {
25
- const painter = findNodeShape(node);
25
+ const painter = node.kind === "group" ? void 0 : findNodeShape(node);
26
26
  const paintCtx = !view || ctx?.pixelScale !== void 0 ? ctx : ctx ? {
27
27
  ...ctx,
28
28
  pixelScale: pixelScaleOf(view)
@@ -41,24 +41,27 @@ function defaultDrawOne(node, pose, view, ctx) {
41
41
  fontFamily: "sans-serif",
42
42
  fontSize: 11
43
43
  });
44
- return [...primary, node.kind === "container" ? overChildren([label]) : label];
44
+ return [...primary, node.kind === "group" ? overChildren([label]) : label];
45
45
  }
46
46
  return primary;
47
47
  }
48
48
  /**
49
49
  * The box {@link defaultDrawOne}'s output for `node` fits in — the matched
50
50
  * painter's `bounds` — or `null` when it has none, or when a `data.label`
51
- * overlay adds text nothing bounds cheaply. The scene slot's `cull` reads it
52
- * to skip painting nodes the view cannot see.
51
+ * overlay adds text nothing bounds cheaply, or an inherited stroke with no
52
+ * `ctx.inherited` to say what it takes. The scene slot's `cull` reads it to
53
+ * skip painting nodes the view cannot see.
53
54
  */
54
- function defaultPaintBounds(node, pose, view) {
55
+ function defaultPaintBounds(node, pose, view, ctx) {
55
56
  const data = node.data;
56
57
  if (data?.label && data.text == null) return null;
57
- if (data?.stroke === INHERIT) return null;
58
+ const inherited = ctx?.inherited;
59
+ if (data?.stroke === INHERIT && inherited === void 0) return null;
58
60
  const sx = Math.abs(view.scale.x), sy = Math.abs(view.scale.y);
59
61
  return findShapeBounds(node, pose, {
60
62
  scale: Math.sqrt(sx * sy),
61
- leastScale: Math.min(sx, sy)
63
+ leastScale: Math.min(sx, sy),
64
+ inherited
62
65
  });
63
66
  }
64
67
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"defaultDrawOne.js","names":[],"sources":["../../src/canvas/defaultDrawOne.ts"],"sourcesContent":["/**\n * The kit's default per-node draw function, kept apart from `SceneCanvas.tsx` so non-React\n * callers (headless rasterization via `renderSceneToPixels`) can use it without importing the\n * React component tree.\n *\n * To teach the kit about a new kind of shape, register a painter (`registerNodeShape`) — do not\n * override `drawOne`. Override `drawOne` only for cross-cutting decoration.\n */\nimport type { Node } from 'core/scene/types';\nimport type { View } from 'core/viewport/view';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { textCommandFromRuns } from '@weasel-js/renderer';\nimport { findNodeShape, findShapeBounds, type NodePaintCtx } from './NodeShape';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { overChildren } from './overChildren';\nimport { INHERIT } from '@weasel-js/paint';\n\nfunction pixelScaleOf(view: View): number {\n const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;\n return Math.max(Math.abs(view.scale.x), Math.abs(view.scale.y)) * dpr;\n}\n\n// Shared across a frame's nodes, which all arrive with the same view.\nlet lastView: View | undefined;\nlet lastViewCtx: NodePaintCtx = {};\nfunction viewOnlyCtx(view: View): NodePaintCtx {\n const pixelScale = pixelScaleOf(view);\n if (view !== lastView || lastViewCtx.pixelScale !== pixelScale) {\n lastView = view;\n lastViewCtx = { pixelScale };\n }\n return lastViewCtx;\n}\n\n/** Paint one node the way the kit does by default: dispatch to the first\n * registered node-shape painter that matches, then draw its `data.label` on\n * top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */\nexport function defaultDrawOne<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view?: View,\n ctx?: NodePaintCtx,\n): DrawCommand[] {\n const painter = findNodeShape(node);\n const paintCtx = !view || ctx?.pixelScale !== undefined\n ? ctx\n : ctx ? { ...ctx, pixelScale: pixelScaleOf(view) } : viewOnlyCtx(view);\n const primary = painter ? painter.paint(node, pose, paintCtx) : [];\n\n // Label overlay — skipped for text nodes (their content is the label).\n const data = node.data as { label?: string; text?: string } | null;\n if (data?.label && data.text == null) {\n const p = pose as unknown as { x: number; y: number };\n // Copy rather than `push`. A painter's return value is not ours to grow:\n // one that memoizes its command list — which is the point of caching\n // `paint` — would gain another label command on every frame, forever.\n const label = textCommandFromRuns(\n p.x + 6,\n p.y + 14,\n [{ text: data.label, fill: { paint: { kind: 'solid', color: 'rgba(0,0,0,0.7)' } } }],\n { fontFamily: 'sans-serif', fontSize: 11 },\n );\n // A container's children would cover a label drawn with the container.\n return [...primary, node.kind === 'container' ? overChildren([label]) : label];\n }\n\n // Rotation and per-node alpha are applied OUTSIDE this function, by `wrapNodeOutput` in\n // the scene walks and the preview-ghost layer, so that consumer-supplied painters get\n // them too.\n return primary;\n}\n\n/**\n * The box {@link defaultDrawOne}'s output for `node` fits in — the matched\n * painter's `bounds` — or `null` when it has none, or when a `data.label`\n * overlay adds text nothing bounds cheaply. The scene slot's `cull` reads it\n * to skip painting nodes the view cannot see.\n */\nexport function defaultPaintBounds<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view: View,\n): Bounds | null {\n const data = node.data as { label?: string; text?: string; stroke?: unknown } | null;\n if (data?.label && data.text == null) return null;\n // No scene here to say what an inherited stroke reaches.\n if (data?.stroke === INHERIT) return null;\n const sx = Math.abs(view.scale.x), sy = Math.abs(view.scale.y);\n return findShapeBounds(node, pose, { scale: Math.sqrt(sx * sy), leastScale: Math.min(sx, sy) });\n}\n\n/**\n * `defaultPaintBounds` when `drawOne` is `defaultDrawOne`, and nothing\n * otherwise: a painter's box says nothing about what a replacement\n * `drawOne` paints.\n */\nexport function paintBoundsFor<TData, TLayer extends string, TPose>(\n drawOne: unknown,\n): typeof defaultPaintBounds<TData, TLayer, TPose> | undefined {\n return drawOne === defaultDrawOne ? defaultPaintBounds : undefined;\n}\n"],"mappings":";;;;;;AAiBA,SAAS,aAAa,MAAoB;CACxC,MAAM,MAAO,OAAO,WAAW,eAAe,OAAO,oBAAqB;CAC1E,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI;AACpE;AAGA,IAAI;AACJ,IAAI,cAA4B,CAAC;AACjC,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,aAAa,IAAI;CACpC,IAAI,SAAS,YAAY,YAAY,eAAe,YAAY;EAC9D,WAAW;EACX,cAAc,EAAE,WAAW;CAC7B;CACA,OAAO;AACT;;;;AAKA,SAAgB,eACd,MACA,MACA,MACA,KACe;CACf,MAAM,UAAU,cAAc,IAAI;CAClC,MAAM,WAAW,CAAC,QAAQ,KAAK,eAAe,SAC1C,MACA,MAAM;EAAE,GAAG;EAAK,YAAY,aAAa,IAAI;CAAE,IAAI,YAAY,IAAI;CACvE,MAAM,UAAU,UAAU,QAAQ,MAAM,MAAM,MAAM,QAAQ,IAAI,CAAC;CAGjE,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM;EACpC,MAAM,IAAI;EAIV,MAAM,QAAQ,oBACZ,EAAE,IAAI,GACN,EAAE,IAAI,IACN,CAAC;GAAE,MAAM,KAAK;GAAO,MAAM,EAAE,OAAO;IAAE,MAAM;IAAS,OAAO;GAAkB,EAAE;EAAE,CAAC,GACnF;GAAE,YAAY;GAAc,UAAU;EAAG,CAC3C;EAEA,OAAO,CAAC,GAAG,SAAS,KAAK,SAAS,cAAc,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK;CAC/E;CAKA,OAAO;AACT;;;;;;;AAQA,SAAgB,mBACd,MACA,MACA,MACe;CACf,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM,OAAO;CAE7C,IAAI,MAAM,WAAW,SAAS,OAAO;CACrC,MAAM,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC;CAC7D,OAAO,gBAAgB,MAAM,MAAM;EAAE,OAAO,KAAK,KAAK,KAAK,EAAE;EAAG,YAAY,KAAK,IAAI,IAAI,EAAE;CAAE,CAAC;AAChG;;;;;;AAOA,SAAgB,eACd,SAC6D;CAC7D,OAAO,YAAY,iBAAiB,qBAAqB;AAC3D"}
1
+ {"version":3,"file":"defaultDrawOne.js","names":[],"sources":["../../src/canvas/defaultDrawOne.ts"],"sourcesContent":["/**\n * The kit's default per-node draw function, kept apart from `SceneCanvas.tsx` so non-React\n * callers (headless rasterization via `renderSceneToPixels`) can use it without importing the\n * React component tree.\n *\n * To teach the kit about a new kind of shape, register a painter (`registerNodeShape`) — do not\n * override `drawOne`. Override `drawOne` only for cross-cutting decoration.\n */\nimport type { Node } from 'core/scene/types';\nimport type { View } from 'core/viewport/view';\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { textCommandFromRuns } from '@weasel-js/renderer';\nimport { findNodeShape, findShapeBounds, type NodePaintCtx } from './NodeShape';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { overChildren } from './overChildren';\nimport { INHERIT } from '@weasel-js/paint';\n\nfunction pixelScaleOf(view: View): number {\n const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;\n return Math.max(Math.abs(view.scale.x), Math.abs(view.scale.y)) * dpr;\n}\n\n// Shared across a frame's nodes, which all arrive with the same view.\nlet lastView: View | undefined;\nlet lastViewCtx: NodePaintCtx = {};\nfunction viewOnlyCtx(view: View): NodePaintCtx {\n const pixelScale = pixelScaleOf(view);\n if (view !== lastView || lastViewCtx.pixelScale !== pixelScale) {\n lastView = view;\n lastViewCtx = { pixelScale };\n }\n return lastViewCtx;\n}\n\n/** Paint one node the way the kit does by default: dispatch to the first\n * registered node-shape painter that matches, then draw its `data.label` on\n * top when it has one: on top of a container's children too. Consumers replace or wrap this via `drawOne`. */\nexport function defaultDrawOne<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view?: View,\n ctx?: NodePaintCtx,\n): DrawCommand[] {\n // A group is structure: it never paints, whatever its data holds.\n const painter = node.kind === 'group' ? undefined : findNodeShape(node);\n const paintCtx = !view || ctx?.pixelScale !== undefined\n ? ctx\n : ctx ? { ...ctx, pixelScale: pixelScaleOf(view) } : viewOnlyCtx(view);\n const primary = painter ? painter.paint(node, pose, paintCtx) : [];\n\n // Label overlay — skipped for text nodes (their content is the label).\n const data = node.data as { label?: string; text?: string } | null;\n if (data?.label && data.text == null) {\n const p = pose as unknown as { x: number; y: number };\n // Copy rather than `push`. A painter's return value is not ours to grow:\n // one that memoizes its command list — which is the point of caching\n // `paint` — would gain another label command on every frame, forever.\n const label = textCommandFromRuns(\n p.x + 6,\n p.y + 14,\n [{ text: data.label, fill: { paint: { kind: 'solid', color: 'rgba(0,0,0,0.7)' } } }],\n { fontFamily: 'sans-serif', fontSize: 11 },\n );\n // A container's children would cover a label drawn with the container.\n return [...primary, node.kind === 'group' ? overChildren([label]) : label];\n }\n\n // Rotation and per-node alpha are applied OUTSIDE this function, by `wrapNodeOutput` in\n // the scene walks and the preview-ghost layer, so that consumer-supplied painters get\n // them too.\n return primary;\n}\n\n/**\n * The box {@link defaultDrawOne}'s output for `node` fits in — the matched\n * painter's `bounds` — or `null` when it has none, or when a `data.label`\n * overlay adds text nothing bounds cheaply, or an inherited stroke with no\n * `ctx.inherited` to say what it takes. The scene slot's `cull` reads it to\n * skip painting nodes the view cannot see.\n */\nexport function defaultPaintBounds<TData, TLayer extends string, TPose>(\n node: Node<TData, TLayer, TPose>,\n pose: TPose,\n view: View,\n ctx?: Pick<NodePaintCtx, 'inherited'>,\n): Bounds | null {\n const data = node.data as { label?: string; text?: string; stroke?: unknown } | null;\n if (data?.label && data.text == null) return null;\n const inherited = ctx?.inherited;\n if (data?.stroke === INHERIT && inherited === undefined) return null;\n const sx = Math.abs(view.scale.x), sy = Math.abs(view.scale.y);\n return findShapeBounds(node, pose, { scale: Math.sqrt(sx * sy), leastScale: Math.min(sx, sy), inherited });\n}\n\n/**\n * `defaultPaintBounds` when `drawOne` is `defaultDrawOne`, and nothing\n * otherwise: a painter's box says nothing about what a replacement\n * `drawOne` paints.\n */\nexport function paintBoundsFor<TData, TLayer extends string, TPose>(\n drawOne: unknown,\n): typeof defaultPaintBounds<TData, TLayer, TPose> | undefined {\n return drawOne === defaultDrawOne ? defaultPaintBounds : undefined;\n}\n"],"mappings":";;;;;;AAiBA,SAAS,aAAa,MAAoB;CACxC,MAAM,MAAO,OAAO,WAAW,eAAe,OAAO,oBAAqB;CAC1E,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI;AACpE;AAGA,IAAI;AACJ,IAAI,cAA4B,CAAC;AACjC,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,aAAa,IAAI;CACpC,IAAI,SAAS,YAAY,YAAY,eAAe,YAAY;EAC9D,WAAW;EACX,cAAc,EAAE,WAAW;CAC7B;CACA,OAAO;AACT;;;;AAKA,SAAgB,eACd,MACA,MACA,MACA,KACe;CAEf,MAAM,UAAU,KAAK,SAAS,UAAU,SAAY,cAAc,IAAI;CACtE,MAAM,WAAW,CAAC,QAAQ,KAAK,eAAe,SAC1C,MACA,MAAM;EAAE,GAAG;EAAK,YAAY,aAAa,IAAI;CAAE,IAAI,YAAY,IAAI;CACvE,MAAM,UAAU,UAAU,QAAQ,MAAM,MAAM,MAAM,QAAQ,IAAI,CAAC;CAGjE,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM;EACpC,MAAM,IAAI;EAIV,MAAM,QAAQ,oBACZ,EAAE,IAAI,GACN,EAAE,IAAI,IACN,CAAC;GAAE,MAAM,KAAK;GAAO,MAAM,EAAE,OAAO;IAAE,MAAM;IAAS,OAAO;GAAkB,EAAE;EAAE,CAAC,GACnF;GAAE,YAAY;GAAc,UAAU;EAAG,CAC3C;EAEA,OAAO,CAAC,GAAG,SAAS,KAAK,SAAS,UAAU,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK;CAC3E;CAKA,OAAO;AACT;;;;;;;;AASA,SAAgB,mBACd,MACA,MACA,MACA,KACe;CACf,MAAM,OAAO,KAAK;CAClB,IAAI,MAAM,SAAS,KAAK,QAAQ,MAAM,OAAO;CAC7C,MAAM,YAAY,KAAK;CACvB,IAAI,MAAM,WAAW,WAAW,cAAc,QAAW,OAAO;CAChE,MAAM,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC;CAC7D,OAAO,gBAAgB,MAAM,MAAM;EAAE,OAAO,KAAK,KAAK,KAAK,EAAE;EAAG,YAAY,KAAK,IAAI,IAAI,EAAE;EAAG;CAAU,CAAC;AAC3G;;;;;;AAOA,SAAgB,eACd,SAC6D;CAC7D,OAAO,YAAY,iBAAiB,qBAAqB;AAC3D"}
@@ -14,18 +14,21 @@ import { useDepSource } from "@weasel-js/routing/react";
14
14
  * ref internally), so callers can pass fresh selection/scene refs without
15
15
  * triggering re-registration.
16
16
  */
17
- function useAreaSelectDepSource(scene, selection, descriptor, alphaOf) {
17
+ function useAreaSelectDepSource(scene, selection, descriptor, alphaOf, reachable) {
18
18
  const sceneRef = useLatest(scene);
19
19
  const selectionRef = useLatest(selection);
20
20
  const descriptorRef = useLatest(descriptor);
21
21
  const alphaOfRef = useLatest(alphaOf);
22
+ const reachableRef = useLatest(reachable);
22
23
  useDepSource("areaSelect", () => {
23
24
  const sc = sceneRef.current;
24
25
  const s = selectionRef.current;
25
26
  const d = descriptorRef.current;
26
27
  const a = alphaOfRef.current;
28
+ const r = reachableRef.current;
29
+ const keep = (ids) => r ? ids.filter((id) => r(id)) : ids;
27
30
  return {
28
- hitTestArea: (bounds, view) => hitTestArea(sc, bounds, regionPickOptions(view, a), d),
31
+ hitTestArea: (bounds, view) => keep(hitTestArea(sc, bounds, regionPickOptions(view, a), d)),
29
32
  getSelection: () => s.current,
30
33
  setSelection: (ids) => s.set(ids)
31
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"areaSelect.js","names":["hitTestAreaShared"],"sources":["../../../src/canvas/deps/areaSelect.ts"],"sourcesContent":["/**\n * `useAreaSelectDepSource` — wires the `areaSelect` dep consumed by\n * `areaSelectAction`. The dep exposes:\n * - `hitTestArea(bounds)` — silhouette-aware scan over `scene.renderOrderNodes()`\n * (rect poses by AABB; polygon poses by the kernel polygon-overlap test).\n * - `getSelection` / `setSelection` — passthrough to the kit selection api.\n *\n * Built once per render and stabilised by `useDepSource` (which reads via a\n * ref internally), so callers can pass fresh selection/scene refs without\n * triggering re-registration.\n */\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { AreaSelectDep } from 'interactions/actions/depSchema';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport { hitTestArea as hitTestAreaShared, regionPickOptions } from './hitTestArea';\n\nexport function useAreaSelectDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n descriptor?: PoseDescriptor<unknown>,\n /** The painted alpha the surface's layers apply, which every view shares. */\n alphaOf?: (id: string) => number,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const descriptorRef = useLatest(descriptor);\n const alphaOfRef = useLatest(alphaOf);\n\n useDepSource('areaSelect', (): AreaSelectDep => {\n const sc = sceneRef.current;\n const s = selectionRef.current;\n const d = descriptorRef.current;\n const a = alphaOfRef.current;\n return {\n hitTestArea: (bounds, view) =>\n hitTestAreaShared(sc, bounds, regionPickOptions(view, a), d),\n getSelection: () => s.current as NodeId[],\n setSelection: (ids) => s.set(ids),\n };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,uBACd,OACA,WACA,YAEA,SACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,gBAAgB,UAAU,UAAU;CAC1C,MAAM,aAAa,UAAU,OAAO;CAEpC,aAAa,oBAAmC;EAC9C,MAAM,KAAK,SAAS;EACpB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,cAAc;EACxB,MAAM,IAAI,WAAW;EACrB,OAAO;GACL,cAAc,QAAQ,SACpBA,YAAkB,IAAI,QAAQ,kBAAkB,MAAM,CAAC,GAAG,CAAC;GAC7D,oBAAoB,EAAE;GACtB,eAAe,QAAQ,EAAE,IAAI,GAAG;EAClC;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"areaSelect.js","names":["hitTestAreaShared"],"sources":["../../../src/canvas/deps/areaSelect.ts"],"sourcesContent":["/**\n * `useAreaSelectDepSource` — wires the `areaSelect` dep consumed by\n * `areaSelectAction`. The dep exposes:\n * - `hitTestArea(bounds)` — silhouette-aware scan over `scene.renderOrderNodes()`\n * (rect poses by AABB; polygon poses by the kernel polygon-overlap test).\n * - `getSelection` / `setSelection` — passthrough to the kit selection api.\n *\n * Built once per render and stabilised by `useDepSource` (which reads via a\n * ref internally), so callers can pass fresh selection/scene refs without\n * triggering re-registration.\n */\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { AreaSelectDep } from 'interactions/actions/depSchema';\nimport type { Scene, NodeId } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport type { PoseDescriptor } from 'interactions/actions/resize/geometry';\nimport { hitTestArea as hitTestAreaShared, regionPickOptions } from './hitTestArea';\n\nexport function useAreaSelectDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n descriptor?: PoseDescriptor<unknown>,\n /** The painted alpha the surface's layers apply, which every view shares. */\n alphaOf?: (id: string) => number,\n /** Whether a node can be reached at all: the canvas's one answer, which picking reads too. */\n reachable?: (id: string) => boolean,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const descriptorRef = useLatest(descriptor);\n const alphaOfRef = useLatest(alphaOf);\n const reachableRef = useLatest(reachable);\n\n useDepSource('areaSelect', (): AreaSelectDep => {\n const sc = sceneRef.current;\n const s = selectionRef.current;\n const d = descriptorRef.current;\n const a = alphaOfRef.current;\n const r = reachableRef.current;\n const keep = (ids: NodeId[]): NodeId[] => (r ? ids.filter((id) => r(id)) : ids);\n return {\n hitTestArea: (bounds, view) =>\n keep(hitTestAreaShared(sc, bounds, regionPickOptions(view, a), d)),\n getSelection: () => s.current as NodeId[],\n setSelection: (ids) => s.set(ids),\n };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,uBACd,OACA,WACA,YAEA,SAEA,WACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,gBAAgB,UAAU,UAAU;CAC1C,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,eAAe,UAAU,SAAS;CAExC,aAAa,oBAAmC;EAC9C,MAAM,KAAK,SAAS;EACpB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,cAAc;EACxB,MAAM,IAAI,WAAW;EACrB,MAAM,IAAI,aAAa;EACvB,MAAM,QAAQ,QAA6B,IAAI,IAAI,QAAQ,OAAO,EAAE,EAAE,CAAC,IAAI;EAC3E,OAAO;GACL,cAAc,QAAQ,SACpB,KAAKA,YAAkB,IAAI,QAAQ,kBAAkB,MAAM,CAAC,GAAG,CAAC,CAAC;GACnE,oBAAoB,EAAE;GACtB,eAAe,QAAQ,EAAE,IAAI,GAAG;EAClC;CACF,CAAC;AACH"}
@@ -82,7 +82,7 @@ function useBooleansAdapterSource(scene, selection, adapter, poseDescriptor) {
82
82
  };
83
83
  return {
84
84
  id: sceneRef.current.mintId(),
85
- kind: "leaf",
85
+ kind: "mark",
86
86
  layer: leaf.node.layer,
87
87
  parent: leaf.node.parent ?? null,
88
88
  pose: leaf.frame.local(sourceId, stored.pose),
@@ -1 +1 @@
1
- {"version":3,"file":"booleans.js","names":[],"sources":["../../../src/canvas/deps/booleans.ts"],"sourcesContent":["/**\n * The kit `booleansAdapter` dep: what the Pathfinder actions, and any tool\n * reading the dep, work on over a canvas's own path leaves.\n *\n * `<SceneCanvas>` publishes it over its own scene. A consumer replaces it with\n * `useBooleansAdapter` from under the canvas — for text operands, say, which\n * this one does not read; the newest registration wins, and a canvas child\n * registers after the canvas's own.\n */\nimport { sceneInheritedPaintOf } from 'canvas/inheritedPaints';\nimport { useMemo } from 'react';\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport { pathInWorld } from '@weasel-js/geom';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport { poseDescriptorForNode, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport { sceneMutators } from 'core/scene/sceneMutators';\nimport { asNodeId, type Scene } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport { scenePoseFrame } from 'interactions/actions/poseFrame';\nimport type { BooleansAdapter } from 'interactions/actions/booleans/booleans';\nimport { pathPaintOf, type PathPaint } from '../nodeShapes/nodePaint';\nimport { drawnPose, leafPath, storePiece } from './pathLeaf';\nimport type { OpsApplier } from './slice';\n\n/**\n * Publish a `booleansAdapter` over `scene`'s path leaves (`data.path` drawn\n * through the pose's box). A result is minted from the source it stands in\n * for: its layer, parent, frame, and data, with the result's path, and the\n * result's paint in place of the source's when the operation gives one.\n */\nexport function useBooleansAdapterSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n adapter: OpsApplier,\n poseDescriptor?: PoseDescriptor<unknown>,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const adapterRef = useLatest(adapter);\n const descriptorRef = useLatest(poseDescriptor);\n\n const booleans = useMemo<BooleansAdapter>(() => {\n const leafOf = (id: string) => {\n const sc = sceneRef.current;\n const node = sc.get(asNodeId(id));\n const path = node ? leafPath(sc, node) : null;\n if (!node || !path) return null;\n const frame = scenePoseFrame(sc);\n const g = poseDescriptorForNode(descriptorRef.current ?? AUTO_POSE_DESCRIPTOR, node);\n const drawn = drawnPose(g, frame.world(node.id));\n return drawn ? { node, path, drawn, frame } : null;\n };\n const tree = () => sceneMutators(sceneRef.current);\n return {\n getNode: (id) => tree().getNode(id),\n getParent: (id) => tree().getParent(id),\n getChildren: (parentId) => tree().getChildren(parentId),\n setChildOrder: (parentId, ids) => tree().setChildOrder(parentId, ids),\n getSelection: () => selectionRef.current.get(),\n getWorldPath: (id) => {\n const leaf = leafOf(id);\n return leaf ? pathInWorld(leaf.path, leaf.drawn.box) : undefined;\n },\n getPaint: (id) => {\n const leaf = leafOf(id);\n return leaf\n ? pathPaintOf(leaf.node.data as Parameters<typeof pathPaintOf>[0], sceneInheritedPaintOf(sceneRef.current)(leaf.node))\n : undefined;\n },\n compareZ: (a, b) => {\n const order = [...sceneRef.current.renderOrder()];\n return order.indexOf(asNodeId(a)) - order.indexOf(asNodeId(b));\n },\n createPathNode: (path, _op, sourceId, paint?: PathPaint) => {\n const leaf = leafOf(sourceId);\n if (!leaf) throw new Error(`[booleansAdapter] no path leaf behind source ${sourceId}`);\n const stored = storePiece(leaf.drawn, path);\n const { fill: _fill, stroke: _stroke, ...rest } = (leaf.node.data ?? {}) as Record<string, unknown>;\n const data = paint ? { ...rest, ...paint, path: stored.path } : { ...(leaf.node.data as object), path: stored.path };\n return {\n id: sceneRef.current.mintId(),\n kind: 'leaf',\n layer: leaf.node.layer,\n parent: leaf.node.parent ?? null,\n pose: leaf.frame.local(sourceId, stored.pose),\n data,\n };\n },\n applyOps: (ops, label) => adapterRef.current.applyOps(ops, label),\n };\n }, [sceneRef, selectionRef, adapterRef, descriptorRef]);\n\n useDepSource('booleansAdapter', () => booleans);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,yBACd,OACA,WACA,SACA,gBACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,gBAAgB,UAAU,cAAc;CAE9C,MAAM,WAAW,cAA+B;EAC9C,MAAM,UAAU,OAAe;GAC7B,MAAM,KAAK,SAAS;GACpB,MAAM,OAAO,GAAG,IAAI,SAAS,EAAE,CAAC;GAChC,MAAM,OAAO,OAAO,SAAS,IAAI,IAAI,IAAI;GACzC,IAAI,CAAC,QAAQ,CAAC,MAAM,OAAO;GAC3B,MAAM,QAAQ,eAAe,EAAE;GAC/B,MAAM,IAAI,sBAAsB,cAAc,WAAW,sBAAsB,IAAI;GACnF,MAAM,QAAQ,UAAU,GAAG,MAAM,MAAM,KAAK,EAAE,CAAC;GAC/C,OAAO,QAAQ;IAAE;IAAM;IAAM;IAAO;GAAM,IAAI;EAChD;EACA,MAAM,aAAa,cAAc,SAAS,OAAO;EACjD,OAAO;GACL,UAAU,OAAO,KAAK,CAAC,CAAC,QAAQ,EAAE;GAClC,YAAY,OAAO,KAAK,CAAC,CAAC,UAAU,EAAE;GACtC,cAAc,aAAa,KAAK,CAAC,CAAC,YAAY,QAAQ;GACtD,gBAAgB,UAAU,QAAQ,KAAK,CAAC,CAAC,cAAc,UAAU,GAAG;GACpE,oBAAoB,aAAa,QAAQ,IAAI;GAC7C,eAAe,OAAO;IACpB,MAAM,OAAO,OAAO,EAAE;IACtB,OAAO,OAAO,YAAY,KAAK,MAAM,KAAK,MAAM,GAAG,IAAI;GACzD;GACA,WAAW,OAAO;IAChB,MAAM,OAAO,OAAO,EAAE;IACtB,OAAO,OACH,YAAY,KAAK,KAAK,MAA2C,sBAAsB,SAAS,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,IACnH;GACN;GACA,WAAW,GAAG,MAAM;IAClB,MAAM,QAAQ,CAAC,GAAG,SAAS,QAAQ,YAAY,CAAC;IAChD,OAAO,MAAM,QAAQ,SAAS,CAAC,CAAC,IAAI,MAAM,QAAQ,SAAS,CAAC,CAAC;GAC/D;GACA,iBAAiB,MAAM,KAAK,UAAU,UAAsB;IAC1D,MAAM,OAAO,OAAO,QAAQ;IAC5B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,gDAAgD,UAAU;IACrF,MAAM,SAAS,WAAW,KAAK,OAAO,IAAI;IAC1C,MAAM,EAAE,MAAM,OAAO,QAAQ,SAAS,GAAG,SAAU,KAAK,KAAK,QAAQ,CAAC;IACtE,MAAM,OAAO,QAAQ;KAAE,GAAG;KAAM,GAAG;KAAO,MAAM,OAAO;IAAK,IAAI;KAAE,GAAI,KAAK,KAAK;KAAiB,MAAM,OAAO;IAAK;IACnH,OAAO;KACL,IAAI,SAAS,QAAQ,OAAO;KAC5B,MAAM;KACN,OAAO,KAAK,KAAK;KACjB,QAAQ,KAAK,KAAK,UAAU;KAC5B,MAAM,KAAK,MAAM,MAAM,UAAU,OAAO,IAAI;KAC5C;IACF;GACF;GACA,WAAW,KAAK,UAAU,WAAW,QAAQ,SAAS,KAAK,KAAK;EAClE;CACF,GAAG;EAAC;EAAU;EAAc;EAAY;CAAa,CAAC;CAEtD,aAAa,yBAAyB,QAAQ;AAChD"}
1
+ {"version":3,"file":"booleans.js","names":[],"sources":["../../../src/canvas/deps/booleans.ts"],"sourcesContent":["/**\n * The kit `booleansAdapter` dep: what the Pathfinder actions, and any tool\n * reading the dep, work on over a canvas's own path leaves.\n *\n * `<SceneCanvas>` publishes it over its own scene. A consumer replaces it with\n * `useBooleansAdapter` from under the canvas — for text operands, say, which\n * this one does not read; the newest registration wins, and a canvas child\n * registers after the canvas's own.\n */\nimport { sceneInheritedPaintOf } from 'canvas/inheritedPaints';\nimport { useMemo } from 'react';\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport { pathInWorld } from '@weasel-js/geom';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport { poseDescriptorForNode, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport { sceneMutators } from 'core/scene/sceneMutators';\nimport { asNodeId, type Scene } from 'core/scene/types';\nimport type { SelectionApi } from 'core/selection/useSelection';\nimport { scenePoseFrame } from 'interactions/actions/poseFrame';\nimport type { BooleansAdapter } from 'interactions/actions/booleans/booleans';\nimport { pathPaintOf, type PathPaint } from '../nodeShapes/nodePaint';\nimport { drawnPose, leafPath, storePiece } from './pathLeaf';\nimport type { OpsApplier } from './slice';\n\n/**\n * Publish a `booleansAdapter` over `scene`'s path leaves (`data.path` drawn\n * through the pose's box). A result is minted from the source it stands in\n * for: its layer, parent, frame, and data, with the result's path, and the\n * result's paint in place of the source's when the operation gives one.\n */\nexport function useBooleansAdapterSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n adapter: OpsApplier,\n poseDescriptor?: PoseDescriptor<unknown>,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const adapterRef = useLatest(adapter);\n const descriptorRef = useLatest(poseDescriptor);\n\n const booleans = useMemo<BooleansAdapter>(() => {\n const leafOf = (id: string) => {\n const sc = sceneRef.current;\n const node = sc.get(asNodeId(id));\n const path = node ? leafPath(sc, node) : null;\n if (!node || !path) return null;\n const frame = scenePoseFrame(sc);\n const g = poseDescriptorForNode(descriptorRef.current ?? AUTO_POSE_DESCRIPTOR, node);\n const drawn = drawnPose(g, frame.world(node.id));\n return drawn ? { node, path, drawn, frame } : null;\n };\n const tree = () => sceneMutators(sceneRef.current);\n return {\n getNode: (id) => tree().getNode(id),\n getParent: (id) => tree().getParent(id),\n getChildren: (parentId) => tree().getChildren(parentId),\n setChildOrder: (parentId, ids) => tree().setChildOrder(parentId, ids),\n getSelection: () => selectionRef.current.get(),\n getWorldPath: (id) => {\n const leaf = leafOf(id);\n return leaf ? pathInWorld(leaf.path, leaf.drawn.box) : undefined;\n },\n getPaint: (id) => {\n const leaf = leafOf(id);\n return leaf\n ? pathPaintOf(leaf.node.data as Parameters<typeof pathPaintOf>[0], sceneInheritedPaintOf(sceneRef.current)(leaf.node))\n : undefined;\n },\n compareZ: (a, b) => {\n const order = [...sceneRef.current.renderOrder()];\n return order.indexOf(asNodeId(a)) - order.indexOf(asNodeId(b));\n },\n createPathNode: (path, _op, sourceId, paint?: PathPaint) => {\n const leaf = leafOf(sourceId);\n if (!leaf) throw new Error(`[booleansAdapter] no path leaf behind source ${sourceId}`);\n const stored = storePiece(leaf.drawn, path);\n const { fill: _fill, stroke: _stroke, ...rest } = (leaf.node.data ?? {}) as Record<string, unknown>;\n const data = paint ? { ...rest, ...paint, path: stored.path } : { ...(leaf.node.data as object), path: stored.path };\n return {\n id: sceneRef.current.mintId(),\n kind: 'mark',\n layer: leaf.node.layer,\n parent: leaf.node.parent ?? null,\n pose: leaf.frame.local(sourceId, stored.pose),\n data,\n };\n },\n applyOps: (ops, label) => adapterRef.current.applyOps(ops, label),\n };\n }, [sceneRef, selectionRef, adapterRef, descriptorRef]);\n\n useDepSource('booleansAdapter', () => booleans);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,yBACd,OACA,WACA,SACA,gBACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,gBAAgB,UAAU,cAAc;CAE9C,MAAM,WAAW,cAA+B;EAC9C,MAAM,UAAU,OAAe;GAC7B,MAAM,KAAK,SAAS;GACpB,MAAM,OAAO,GAAG,IAAI,SAAS,EAA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AO,QAAQ,SAAS,GAAG,SAAU,KAAK,KAAK,QAAQ,CAAC;IACtE,MAAM,OAAO,QAAQ;KAAE,GAAG;KAAM,GAAG;KAAO,MAAM,OAAO;IAAK,IAAI;KAAE,GAAI,KAAK,KAAK;KAAiB,MAAM,OAAO;IAAK;IACnH,OAAO;KACL,IAAI,SAAS,QAAQ,OAAO;KAC5B,MAAM;KACN,OAAO,KAAK,KAAK;KACjB,QAAQ,KAAK,KAAK,UAAU;KAC5B,MAAM,KAAK,MAAM,MAAM,UAAU,OAAO,IAAI;KAC5C;IACF;GACF;GACA,WAAW,KAAK,UAAU,WAAW,QAAQ,SAAS,KAAK,KAAK;EAClE;CACF,GAAG;EAAC;EAAU;EAAc;EAAY;CAAa,CAAC;CAEtD,aAAa,yBAAyB,QAAQ;AAChD"}
@@ -0,0 +1,81 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import { useDepRegistry, useDepSource } from "@weasel-js/routing/react";
3
+
4
+ //#region src/canvas/deps/enteredGroup.ts
5
+ /**
6
+ * The entered group: the group a press resolves inside of. Session state beside
7
+ * the selection, not scene data, so it is never saved and never undone.
8
+ *
9
+ * It remembers the entered group and the groups above it. `get()` answers the
10
+ * innermost of those still in the scene, so deleting the group lands on its
11
+ * parent, and an undo that brings it back lands on it again.
12
+ */
13
+ /** Whether `id` is reachable while `group` is entered: inside it, and not the group itself. With
14
+ * nothing entered every node is. Picking, region selects and select-all all ask this. */
15
+ function reachableInGroup(scene, group, id) {
16
+ return group === null || scene.ancestorsOf(id).includes(group);
17
+ }
18
+ /** An entered-group store over `scene`, with nothing entered. */
19
+ function createEnteredGroup(scene) {
20
+ let chain = [];
21
+ let announced = null;
22
+ const listeners = /* @__PURE__ */ new Set();
23
+ const isGroup = (id) => scene.get(id)?.kind === "group";
24
+ const get = () => chain.find(isGroup) ?? null;
25
+ const groupsFrom = (id) => [id, ...scene.ancestorsOf(id)].filter(isGroup);
26
+ const announce = () => {
27
+ announced = get();
28
+ for (const fn of [...listeners]) fn();
29
+ };
30
+ let stopScene = null;
31
+ const watchScene = () => scene.subscribe(() => {
32
+ if (get() !== announced) announce();
33
+ });
34
+ return {
35
+ get,
36
+ enter(id) {
37
+ if (!isGroup(id)) return;
38
+ chain = groupsFrom(id);
39
+ announce();
40
+ },
41
+ leave() {
42
+ const here = get();
43
+ if (here === null) return;
44
+ chain = groupsFrom(here).slice(1);
45
+ announce();
46
+ },
47
+ leaveAll() {
48
+ if (get() === null) return;
49
+ chain = [];
50
+ announce();
51
+ },
52
+ subscribe(fn) {
53
+ if (listeners.size === 0) {
54
+ announced = get();
55
+ stopScene = watchScene();
56
+ }
57
+ listeners.add(fn);
58
+ return () => {
59
+ listeners.delete(fn);
60
+ if (listeners.size === 0) {
61
+ stopScene?.();
62
+ stopScene = null;
63
+ }
64
+ };
65
+ }
66
+ };
67
+ }
68
+ /** One entered-group store for the life of the scene. */
69
+ function useEnteredGroup(scene) {
70
+ return useMemo(() => createEnteredGroup(scene), [scene]);
71
+ }
72
+ function useEnteredGroupApiSource(dep) {
73
+ useDepSource("enteredGroup", () => dep);
74
+ useDepSource("insertInto", (below) => ({ get: () => below()?.get() ?? dep.get() }));
75
+ const registry = useDepRegistry();
76
+ useEffect(() => dep.subscribe(() => registry.changed?.()), [dep, registry]);
77
+ }
78
+
79
+ //#endregion
80
+ export { createEnteredGroup, reachableInGroup, useEnteredGroup, useEnteredGroupApiSource };
81
+ //# sourceMappingURL=enteredGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enteredGroup.js","names":[],"sources":["../../../src/canvas/deps/enteredGroup.ts"],"sourcesContent":["/**\n * The entered group: the group a press resolves inside of. Session state beside\n * the selection, not scene data, so it is never saved and never undone.\n *\n * It remembers the entered group and the groups above it. `get()` answers the\n * innermost of those still in the scene, so deleting the group lands on its\n * parent, and an undo that brings it back lands on it again.\n */\nimport { useEffect, useMemo } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport type { NodeId, Scene } from 'core/scene/types';\n\n/** The group a press resolves inside of, held beside the selection; `<SceneCanvas enteredGroup>` takes one. */\nexport interface EnteredGroupApi {\n get(): NodeId | null;\n enter(id: NodeId): void;\n /** Moves to the nearest group above the current one, or to none. */\n leave(): void;\n /** Leaves every entered group at once. */\n leaveAll(): void;\n subscribe(fn: () => void): () => void;\n}\n\n/** Whether `id` is reachable while `group` is entered: inside it, and not the group itself. With\n * nothing entered every node is. Picking, region selects and select-all all ask this. */\nexport function reachableInGroup(\n scene: Pick<Scene<unknown, string, unknown>, 'ancestorsOf'>,\n group: NodeId | null,\n id: string,\n): boolean {\n return group === null || scene.ancestorsOf(id as NodeId).includes(group);\n}\n\ntype SceneReads = Pick<Scene<unknown, string, unknown>, 'get' | 'ancestorsOf' | 'subscribe'>;\n\n/** An entered-group store over `scene`, with nothing entered. */\nexport function createEnteredGroup(scene: SceneReads): EnteredGroupApi {\n let chain: NodeId[] = [];\n let announced: NodeId | null = null;\n const listeners = new Set<() => void>();\n\n const isGroup = (id: NodeId) => scene.get(id)?.kind === 'group';\n const get = (): NodeId | null => chain.find(isGroup) ?? null;\n const groupsFrom = (id: NodeId): NodeId[] => [id, ...scene.ancestorsOf(id)].filter(isGroup);\n\n const announce = () => {\n announced = get();\n for (const fn of [...listeners]) fn();\n };\n\n let stopScene: (() => void) | null = null;\n const watchScene = () => scene.subscribe(() => {\n if (get() !== announced) announce();\n });\n\n return {\n get,\n enter(id) {\n if (!isGroup(id)) return;\n chain = groupsFrom(id);\n announce();\n },\n leave() {\n const here = get();\n if (here === null) return;\n chain = groupsFrom(here).slice(1);\n announce();\n },\n leaveAll() {\n if (get() === null) return;\n chain = [];\n announce();\n },\n subscribe(fn) {\n if (listeners.size === 0) {\n announced = get();\n stopScene = watchScene();\n }\n listeners.add(fn);\n return () => {\n listeners.delete(fn);\n if (listeners.size === 0) { stopScene?.(); stopScene = null; }\n };\n },\n };\n}\n\n/** One entered-group store for the life of the scene. */\nexport function useEnteredGroup(scene: SceneReads): EnteredGroupApi {\n return useMemo(() => createEnteredGroup(scene), [scene]);\n}\n\nexport function useEnteredGroupApiSource(dep: EnteredGroupApi): void {\n useDepSource('enteredGroup', () => dep);\n // What is drawn or pasted while a group is entered lands in it, unless a source\n // registered under this one, such as a symmetry group, names a container.\n useDepSource('insertInto', (below) => ({ get: () => below()?.get() ?? dep.get() }));\n const registry = useDepRegistry();\n useEffect(() => dep.subscribe(() => registry.changed?.()), [dep, registry]);\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,SAAgB,iBACd,OACA,OACA,IACS;CACT,OAAO,UAAU,QAAQ,MAAM,YAAY,EAAY,CAAC,CAAC,SAAS,KAAK;AACzE;;AAKA,SAAgB,mBAAmB,OAAoC;CACrE,IAAI,QAAkB,CAAC;CACvB,IAAI,YAA2B;CAC/B,MAAM,4BAAY,IAAI,IAAgB;CAEtC,MAAM,WAAW,OAAe,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS;CACxD,MAAM,YAA2B,MAAM,KAAK,OAAO,KAAK;CACxD,MAAM,cAAc,OAAyB,CAAC,IAAI,GAAG,MAAM,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,OAAO;CAE1F,MAAM,iBAAiB;EACrB,YAAY,IAAI;EAChB,KAAK,MAAM,MAAM,CAAC,GAAG,SAAS,GAAG,GAAG;CACtC;CAEA,IAAI,YAAiC;CACrC,MAAM,mBAAmB,MAAM,gBAAgB;EAC7C,IAAI,IAAI,MAAM,WAAW,SAAS;CACpC,CAAC;CAED,OAAO;EACL;EACA,MAAM,IAAI;GACR,IAAI,CAAC,QAAQ,EAAE,GAAG;GAClB,QAAQ,WAAW,EAAE;GACrB,SAAS;EACX;EACA,QAAQ;GACN,MAAM,OAAO,IAAI;GACjB,IAAI,SAAS,MAAM;GACnB,QAAQ,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC;GAChC,SAAS;EACX;EACA,WAAW;GACT,IAAI,IAAI,MAAM,MAAM;GACpB,QAAQ,CAAC;GACT,SAAS;EACX;EACA,UAAU,IAAI;GACZ,IAAI,UAAU,SAAS,GAAG;IACxB,YAAY,IAAI;IAChB,YAAY,WAAW;GACzB;GACA,UAAU,IAAI,EAAE;GAChB,aAAa;IACX,UAAU,OAAO,EAAE;IACnB,IAAI,UAAU,SAAS,GAAG;KAAE,YAAY;KAAG,YAAY;IAAM;GAC/D;EACF;CACF;AACF;;AAGA,SAAgB,gBAAgB,OAAoC;CAClE,OAAO,cAAc,mBAAmB,KAAK,GAAG,CAAC,KAAK,CAAC;AACzD;AAEA,SAAgB,yBAAyB,KAA4B;CACnE,aAAa,sBAAsB,GAAG;CAGtC,aAAa,eAAe,WAAW,EAAE,WAAW,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,IAAI,EAAE,EAAE;CAClF,MAAM,WAAW,eAAe;CAChC,gBAAgB,IAAI,gBAAgB,SAAS,UAAU,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC;AAC5E"}
@@ -2,9 +2,10 @@ import { rectToPlane, toPlane } from "../../core/viewport/parallax.js";
2
2
  import { poseDescriptorForNode, visualBoundsViaDescriptor } from "../../core/geometry/poseDescriptor.js";
3
3
  import { AUTO_POSE_DESCRIPTOR } from "../../core/geometry/autoPoseDescriptor.js";
4
4
  import { findShapeInk, findShapeSilhouette } from "../NodeShape.js";
5
- import { pickWalk, scenePickSource } from "../pickWalk.js";
6
5
  import { polygonRegion, poseOutline, rectRegion, regionBoundsOf, regionOf, regionTakes } from "../../core/geometry/regionHit.js";
7
- import { applyToPoint, pathIntersectsRect } from "@weasel-js/geom";
6
+ import { scenePickSource } from "../scenePickSource.js";
7
+ import { pickWalk } from "../pickWalk.js";
8
+ import { applyToPoint, boundsOfPath, pathIntersectsRect } from "@weasel-js/geom";
8
9
 
9
10
  //#region src/canvas/deps/hitTestArea.ts
10
11
  /** The pick options a region dep hands the shared walk: the asking view's
@@ -38,26 +39,37 @@ function asInked(filled, shape) {
38
39
  openFill: "none"
39
40
  };
40
41
  }
41
- /** The walk every region query shares: skip containers unless asked, gate on
42
+ /** The walk every region query shares: skip groups unless asked, gate on
42
43
  * the clip, and let `regionTakes` decide each node. */
43
44
  function walkArea(scene, region, mode, opts, descriptor, query) {
44
- const regionQuery = (r) => ({
45
- includeContainers: query.includeContainers === true,
46
- clipAdmits: (clip, node, pose) => {
45
+ const src = scenePickSource(scene, {
46
+ ...opts,
47
+ index: { descriptor }
48
+ });
49
+ return pickWalk(src, regionPickQuery(region, mode, descriptor, query));
50
+ }
51
+ /** The query a marquee or a lasso over `r` asks of each node. */
52
+ function regionPickQuery(r, mode, descriptor, query) {
53
+ return {
54
+ includeGroups: query.includeGroups === true,
55
+ broad: { box: r.bounds },
56
+ clipAdmits: (clip, node, pose, derived) => {
47
57
  const g = poseDescriptorForNode(descriptor, node);
48
- return pathIntersectsRect(clip, visualBoundsViaDescriptor(pose, g)) && pathIntersectsRect(clip, r.bounds);
58
+ return pathIntersectsRect(clip, derived ? boundsOfPath(derived) : visualBoundsViaDescriptor(pose, g)) && pathIntersectsRect(clip, r.bounds);
49
59
  },
50
- hits: (node, pose, _derived, inherited) => {
60
+ hits: (node, pose, derived, inherited) => {
51
61
  const g = poseDescriptorForNode(descriptor, node);
52
- const b = regionBoundsOf(node, pose, g);
62
+ const b = derived ? boundsOfPath(derived) : regionBoundsOf(node, pose, g);
53
63
  let ink;
54
64
  const filled = () => ink ??= findShapeInk(node, pose, { inherited })?.filled !== false;
55
- return regionTakes(r, mode, asInked(filled, pose), b, () => asInked(filled, findShapeSilhouette(node, pose) ?? poseOutline(pose, b)), filled);
65
+ return regionTakes(r, mode, asInked(filled, pose), b, () => asInked(filled, findShapeSilhouette(node, pose, { derivedPath: derived }) ?? derived ?? poseOutline(pose, b)), filled);
56
66
  },
57
- inPlane: (m) => regionQuery(regionInPlane(r, m)),
58
- inCopy: (m) => regionQuery(regionInCopy(r, m))
59
- });
60
- return pickWalk(scenePickSource(scene, opts), regionQuery(region));
67
+ inPlane: (m) => regionPickQuery(regionInPlane(r, m), mode, descriptor, query),
68
+ inCopy: (m) => ({
69
+ ...regionPickQuery(regionInCopy(r, m), mode, descriptor, query),
70
+ broad: void 0
71
+ })
72
+ };
61
73
  }
62
74
  /** `r` carried into a plane's world. The map is axis-aligned, so a rect stays
63
75
  * one; a flipped axis reverses the winding, which no region test reads. */
@@ -92,5 +104,5 @@ function regionInCopy(r, m) {
92
104
  }
93
105
 
94
106
  //#endregion
95
- export { hitTestArea, hitTestLassoPolygon, regionPickOptions };
107
+ export { hitTestArea, hitTestLassoPolygon, regionPickOptions, regionPickQuery };
96
108
  //# sourceMappingURL=hitTestArea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hitTestArea.js","names":[],"sources":["../../../src/canvas/deps/hitTestArea.ts"],"sourcesContent":["/**\n * Silhouette-aware area hit-test for marquee and lasso selection.\n *\n * The per-node decision is `regionTakes` (`core/geometry/regionHit`). This\n * module supplies the scene walk and the node's drawn outline: the painter's\n * world-frame silhouette (`findShapeSilhouette`), or with no painter the pose\n * rect, rotated if the pose is.\n */\nimport type { Scene, NodeId } from 'core/scene/types';\nimport { applyToPoint, pathIntersectsRect, type Affine } from '@weasel-js/geom';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport {\n poseDescriptorForNode,\n visualBoundsViaDescriptor,\n type PoseDescriptor,\n} from 'interactions/actions/resize/geometry';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport {\n pickWalk,\n scenePickSource,\n type PickQuery,\n type ScenePickSourceOptions,\n} from 'canvas/pickWalk';\nimport { rectToPlane, toPlane, type PlaneMap } from 'core/viewport/parallax';\n\nimport type { HitTestView } from 'interactions/actions/depSchema';\nimport { findShapeInk, findShapeSilhouette } from 'canvas/NodeShape';\nimport {\n polygonRegion,\n poseOutline,\n rectRegion,\n regionBoundsOf,\n regionOf,\n regionTakes,\n type SelectRegion,\n} from 'core/geometry/regionHit';\n\nexport interface AABBBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** What a region query takes back beyond leaves. */\nexport interface RegionQueryOptions {\n /** Default `false`: a region that takes a container and its children\n * selects the same ink twice. A bare-adapter consumer, which has nothing\n * to fold children back into their container, asks for them. */\n includeContainers?: boolean;\n}\n\n\n/** The pick options a region dep hands the shared walk: the asking view's\n * layer gate and camera, and the surface's alpha. */\nexport function regionPickOptions(\n view: HitTestView | undefined,\n alphaOf: ((id: string) => number) | undefined,\n): ScenePickSourceOptions<unknown> {\n const camera = view?.get?.();\n return {\n ...(alphaOf ? { alphaOf } : {}),\n ...(view?.layerIsPainted ? { layerIsPainted: (layer: string) => view.layerIsPainted!(layer) } : {}),\n ...(camera ? { camera } : {}),\n };\n}\n\n/** Marquee entry point: every node the rect `bounds` meets. */\nexport function hitTestArea(\n scene: Scene<unknown, string, unknown>,\n bounds: AABBBounds,\n opts?: ScenePickSourceOptions<unknown>,\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n return walkArea(scene, rectRegion(bounds), 'intersect', opts, descriptor, query);\n}\n\n/**\n * Every node an arbitrary closed area polygon meets. `area` is interleaved\n * `[x0,y0,x1,y1,…]`; `areaBounds` is its AABB, derived when omitted.\n */\nexport function hitTestAreaPolygon(\n scene: Scene<unknown, string, unknown>,\n area: ArrayLike<number>,\n areaBounds?: AABBBounds,\n /** True when `area` IS its own bounding rect, so `areaBounds` containment\n * implies containment in the area proper. Never pass this for a lasso\n * polygon — a node inside the hull's box can miss the hull. */\n areaIsRect = false,\n /** The asking view's alpha and layer accessors. A bare scene answers for\n * itself; a view that dims or reorders layers has to supply its own. */\n opts?: ScenePickSourceOptions<unknown>,\n /** How to read this scene's poses. Default `AUTO_POSE_DESCRIPTOR`. */\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n const region = regionOf(area, areaBounds, areaIsRect);\n return region ? walkArea(scene, region, 'intersect', opts, descriptor, query) : [];\n}\n\n/**\n * Lasso entry point: which nodes a closed lasso polygon picks under `mode`\n * (see `regionTakes`).\n */\nexport function hitTestLassoPolygon(\n scene: Scene<unknown, string, unknown>,\n polygon: ReadonlyArray<{ x: number; y: number }>,\n mode: LassoHitMode,\n opts?: ScenePickSourceOptions<unknown>,\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n const region = polygonRegion(polygon);\n return region ? walkArea(scene, region, mode, opts, descriptor, query) : [];\n}\n\n/** `shape` as a region reads it: a polygon path's open subpaths enclose\n * nothing when the node's painter lays down no fill. */\nfunction asInked<T>(filled: () => boolean, shape: T): T {\n if ((shape as { kind?: unknown } | null)?.kind !== 'polygon') return shape;\n return filled() ? shape : { ...shape, openFill: 'none' };\n}\n\n/** The walk every region query shares: skip containers unless asked, gate on\n * the clip, and let `regionTakes` decide each node. */\nfunction walkArea(\n scene: Scene<unknown, string, unknown>,\n region: SelectRegion,\n mode: LassoHitMode,\n opts: ScenePickSourceOptions<unknown> | undefined,\n descriptor: PoseDescriptor<unknown>,\n query: RegionQueryOptions,\n): NodeId[] {\n const regionQuery = (r: SelectRegion): PickQuery<unknown> => ({\n includeContainers: query.includeContainers === true,\n clipAdmits: (clip, node, pose) => {\n const g = poseDescriptorForNode(descriptor, node);\n return pathIntersectsRect(clip, visualBoundsViaDescriptor(pose, g))\n && pathIntersectsRect(clip, r.bounds);\n },\n hits: (node, pose, _derived, inherited) => {\n // The descriptor sees the node here, so a pose shape whose extent\n // depends on `node.data` bounds itself rather than its pose's default.\n const g = poseDescriptorForNode(descriptor, node);\n const b = regionBoundsOf(node as object, pose, g);\n let ink: boolean | undefined;\n const filled = (): boolean => ink ??= findShapeInk(node as never, pose, { inherited })?.filled !== false;\n return regionTakes(r, mode, asInked(filled, pose), b, () =>\n asInked(filled, findShapeSilhouette(node as never, pose) ?? poseOutline(pose, b)), filled);\n },\n inPlane: (m) => regionQuery(regionInPlane(r, m)),\n inCopy: (m) => regionQuery(regionInCopy(r, m)),\n });\n return pickWalk<unknown>(scenePickSource(scene, opts), regionQuery(region)) as NodeId[];\n}\n\n/** `r` carried into a plane's world. The map is axis-aligned, so a rect stays\n * one; a flipped axis reverses the winding, which no region test reads. */\nfunction regionInPlane(r: SelectRegion, m: PlaneMap): SelectRegion {\n const coords: number[] = [];\n for (const v of r.verts) {\n const p = toPlane(m, v);\n coords.push(p.x, p.y);\n }\n return regionOf(coords, rectToPlane(m, r.bounds), r.isRect)!;\n}\n\n/** `r` carried by an affine into a copy's source frame. A rect stays one only\n * while the map keeps the axes; a turn makes it a polygon. */\nfunction regionInCopy(r: SelectRegion, m: Affine): SelectRegion {\n const coords: number[] = [];\n let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;\n for (const v of r.verts) {\n const [x, y] = applyToPoint(m, v.x, v.y);\n coords.push(x, y);\n x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y);\n }\n const keepsAxes = (m[1] === 0 && m[2] === 0) || (m[0] === 0 && m[3] === 0);\n return regionOf(coords, { x: x0, y: y0, width: x1 - x0, height: y1 - y0 }, r.isRect && keepsAxes)!;\n}\n"],"mappings":";;;;;;;;;;;AAuDA,SAAgB,kBACd,MACA,SACiC;CACjC,MAAM,SAAS,MAAM,MAAM;CAC3B,OAAO;EACL,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,MAAM,iBAAiB,EAAE,iBAAiB,UAAkB,KAAK,eAAgB,KAAK,EAAE,IAAI,CAAC;EACjG,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;CAC7B;AACF;;AAGA,SAAgB,YACd,OACA,QACA,MACA,aAAsC,sBACtC,QAA4B,CAAC,GACnB;CACV,OAAO,SAAS,OAAO,WAAW,MAAM,GAAG,aAAa,MAAM,YAAY,KAAK;AACjF;;;;;AA6BA,SAAgB,oBACd,OACA,SACA,MACA,MACA,aAAsC,sBACtC,QA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AAC;CACtB;CACA,OAAO,SAAS,QAAQ,YAAY,GAAG,EAAE,MAAM,GAAG,EAAE,MAAM;AAC5D;;;AAIA,SAAS,aAAa,GAAiB,GAAyB;CAC9D,MAAM,SAAmB,CAAC;CAC1B,IAAI,KAAK,UAAU,KAAK,UAAU,KAAK,WAAW,KAAK;CACvD,KAAK,MAAM,KAAK,EAAE,OAAO;EACvB,MAAM,CAAC,GAAG,KAAK,aAAa,GAAG,EAAE,GAAG,EAAE,CAAC;EACvC,OAAO,KAAK,GAAG,CAAC;EAChB,KAAK,KAAK,IAAI,IAAI,CAAC;EAAG,KAAK,KAAK,IAAI,IAAI,CAAC;EAAG,KAAK,KAAK,IAAI,IAAI,CAAC;EAAG,KAAK,KAAK,IAAI,IAAI,CAAC;CACvF;CACA,MAAM,YAAa,EAAE,OAAO,KAAK,EAAE,OAAO,KAAO,EAAE,OAAO,KAAK,EAAE,OAAO;CACxE,OAAO,SAAS,QAAQ;EAAE,GAAG;EAAI,GAAG;EAAI,OAAO,KAAK;EAAI,QAAQ,KAAK;CAAG,GAAG,EAAE,UAAU,SAAS;AAClG"}
1
+ {"version":3,"file":"hitTestArea.js","names":[],"sources":["../../../src/canvas/deps/hitTestArea.ts"],"sourcesContent":["/**\n * Silhouette-aware area hit-test for marquee and lasso selection.\n *\n * The per-node decision is `regionTakes` (`core/geometry/regionHit`). This\n * module supplies the scene walk and the node's drawn outline: the painter's\n * world-frame silhouette (`findShapeSilhouette`), or with no painter the pose\n * rect, rotated if the pose is.\n */\nimport type { Scene, NodeId } from 'core/scene/types';\nimport { applyToPoint, boundsOfPath, pathIntersectsRect, type Affine } from '@weasel-js/geom';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport {\n poseDescriptorForNode,\n visualBoundsViaDescriptor,\n type PoseDescriptor,\n} from 'interactions/actions/resize/geometry';\nimport { AUTO_POSE_DESCRIPTOR } from 'core/geometry/autoPoseDescriptor';\nimport {\n pickWalk,\n scenePickSource,\n type PickQuery,\n type ScenePickSourceOptions,\n} from 'canvas/pickWalk';\nimport { rectToPlane, toPlane, type PlaneMap } from 'core/viewport/parallax';\n\nimport type { HitTestView } from 'interactions/actions/depSchema';\nimport { findShapeInk, findShapeSilhouette } from 'canvas/NodeShape';\nimport {\n polygonRegion,\n poseOutline,\n rectRegion,\n regionBoundsOf,\n regionOf,\n regionTakes,\n type SelectRegion,\n} from 'core/geometry/regionHit';\n\nexport interface AABBBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** What a region query takes back beyond leaves. */\nexport interface RegionQueryOptions {\n /** Default `false`: a region that takes a group and its members\n * selects the same ink twice. A bare-adapter consumer, which has nothing\n * to fold members back into their group, asks for them. */\n includeGroups?: boolean;\n}\n\n\n/** The pick options a region dep hands the shared walk: the asking view's\n * layer gate and camera, and the surface's alpha. */\nexport function regionPickOptions(\n view: HitTestView | undefined,\n alphaOf: ((id: string) => number) | undefined,\n): ScenePickSourceOptions<unknown> {\n const camera = view?.get?.();\n return {\n ...(alphaOf ? { alphaOf } : {}),\n ...(view?.layerIsPainted ? { layerIsPainted: (layer: string) => view.layerIsPainted!(layer) } : {}),\n ...(camera ? { camera } : {}),\n };\n}\n\n/** Marquee entry point: every node the rect `bounds` meets. */\nexport function hitTestArea(\n scene: Scene<unknown, string, unknown>,\n bounds: AABBBounds,\n opts?: ScenePickSourceOptions<unknown>,\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n return walkArea(scene, rectRegion(bounds), 'intersect', opts, descriptor, query);\n}\n\n/**\n * Every node an arbitrary closed area polygon meets. `area` is interleaved\n * `[x0,y0,x1,y1,…]`; `areaBounds` is its AABB, derived when omitted.\n */\nexport function hitTestAreaPolygon(\n scene: Scene<unknown, string, unknown>,\n area: ArrayLike<number>,\n areaBounds?: AABBBounds,\n /** True when `area` IS its own bounding rect, so `areaBounds` containment\n * implies containment in the area proper. Never pass this for a lasso\n * polygon — a node inside the hull's box can miss the hull. */\n areaIsRect = false,\n /** The asking view's alpha and layer accessors. A bare scene answers for\n * itself; a view that dims or reorders layers has to supply its own. */\n opts?: ScenePickSourceOptions<unknown>,\n /** How to read this scene's poses. Default `AUTO_POSE_DESCRIPTOR`. */\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n const region = regionOf(area, areaBounds, areaIsRect);\n return region ? walkArea(scene, region, 'intersect', opts, descriptor, query) : [];\n}\n\n/**\n * Lasso entry point: which nodes a closed lasso polygon picks under `mode`\n * (see `regionTakes`).\n */\nexport function hitTestLassoPolygon(\n scene: Scene<unknown, string, unknown>,\n polygon: ReadonlyArray<{ x: number; y: number }>,\n mode: LassoHitMode,\n opts?: ScenePickSourceOptions<unknown>,\n descriptor: PoseDescriptor<unknown> = AUTO_POSE_DESCRIPTOR,\n query: RegionQueryOptions = {},\n): NodeId[] {\n const region = polygonRegion(polygon);\n return region ? walkArea(scene, region, mode, opts, descriptor, query) : [];\n}\n\n/** `shape` as a region reads it: a polygon path's open subpaths enclose\n * nothing when the node's painter lays down no fill. */\nfunction asInked<T>(filled: () => boolean, shape: T): T {\n if ((shape as { kind?: unknown } | null)?.kind !== 'polygon') return shape;\n return filled() ? shape : { ...shape, openFill: 'none' };\n}\n\n/** The walk every region query shares: skip groups unless asked, gate on\n * the clip, and let `regionTakes` decide each node. */\nfunction walkArea(\n scene: Scene<unknown, string, unknown>,\n region: SelectRegion,\n mode: LassoHitMode,\n opts: ScenePickSourceOptions<unknown> | undefined,\n descriptor: PoseDescriptor<unknown>,\n query: RegionQueryOptions,\n): NodeId[] {\n const src = scenePickSource(scene, { ...opts, index: { descriptor } });\n return pickWalk<unknown>(src, regionPickQuery(region, mode, descriptor, query)) as NodeId[];\n}\n\n/** The query a marquee or a lasso over `r` asks of each node. */\nexport function regionPickQuery(\n r: SelectRegion,\n mode: LassoHitMode,\n descriptor: PoseDescriptor<unknown>,\n query: RegionQueryOptions,\n): PickQuery<unknown> {\n return {\n includeGroups: query.includeGroups === true,\n broad: { box: r.bounds },\n clipAdmits: (clip, node, pose, derived) => {\n const g = poseDescriptorForNode(descriptor, node);\n return pathIntersectsRect(clip, derived ? boundsOfPath(derived) : visualBoundsViaDescriptor(pose, g))\n && pathIntersectsRect(clip, r.bounds);\n },\n hits: (node, pose, derived, inherited) => {\n // The descriptor sees the node here, so a pose shape whose extent\n // depends on `node.data` bounds itself rather than its pose's default.\n const g = poseDescriptorForNode(descriptor, node);\n // A derived node's pose is a placeholder: its path is the extent and the fallback outline.\n const b = derived ? boundsOfPath(derived) : regionBoundsOf(node as object, pose, g);\n let ink: boolean | undefined;\n const filled = (): boolean => ink ??= findShapeInk(node as never, pose, { inherited })?.filled !== false;\n return regionTakes(r, mode, asInked(filled, pose), b, () =>\n asInked(filled, findShapeSilhouette(node as never, pose, { derivedPath: derived }) ?? derived ?? poseOutline(pose, b)), filled);\n },\n inPlane: (m) => regionPickQuery(regionInPlane(r, m), mode, descriptor, query),\n // A copy is tested by every walk, so the query carried into one asks no index.\n inCopy: (m) => ({ ...regionPickQuery(regionInCopy(r, m), mode, descriptor, query), broad: undefined }),\n };\n}\n\n/** `r` carried into a plane's world. The map is axis-aligned, so a rect stays\n * one; a flipped axis reverses the winding, which no region test reads. */\nfunction regionInPlane(r: SelectRegion, m: PlaneMap): SelectRegion {\n const coords: number[] = [];\n for (const v of r.verts) {\n const p = toPlane(m, v);\n coords.push(p.x, p.y);\n }\n return regionOf(coords, rectToPlane(m, r.bounds), r.isRect)!;\n}\n\n/** `r` carried by an affine into a copy's source frame. A rect stays one only\n * while the map keeps the axes; a turn makes it a polygon. */\nfunction regionInCopy(r: SelectRegion, m: Affine): SelectRegion {\n const coords: number[] = [];\n let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;\n for (const v of r.verts) {\n const [x, y] = applyToPoint(m, v.x, v.y);\n coords.push(x, y);\n x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y);\n }\n const keepsAxes = (m[1] === 0 && m[2] === 0) || (m[0] === 0 && m[3] === 0);\n return regionOf(coords, { x: x0, y: y0, width: x1 - x0, height: y1 - y0 }, r.isRect && keepsAxes)!;\n}\n"],"mappings":";;;;;;;;;;;;AAuDA,SAAgB,kBACd,MACA,SACiC;CACjC,MAAM,SAAS,MAAM,MAAM;CAC3B,OAAO;EACL,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,MAAM,iBAAiB,EAAE,iBAAiB,UAAkB,KAAK,eAAgB,KAAK,EAAE,IAAI,CAAC;EACjG,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;CAC7B;AACF;;AAGA,SAAgB,YACd,OACA,QACA,MACA,aAAsC,sBACtC,QAA4B,CAAC,GACnB;CACV,OAAO,SAAS,OAAO,WAAW,MAAM,GAAG,aAAa,MAAM,YAAY,KAAK;AACjF;;;;;AA6BA,SAAgB,oBACd,OACA,SACA,MACA,MACA,aAAsC,sBACtC,QAA4B,CAAC,GACnB;CACV,MAAM,SAAS,cAAc,OAAO;CACpC,OAAO,SAAS,SAAS,OAAO,QAAQ,MAAM,MAAM,YAAY,KAAK,IAAI,CAAC;AAC5E;;;AAIA,SAAS,QAAW,QAAuB,OAAa;CACtD,IAAK,OAAqC,SAAS,WAAW,OAAO;CACrE,OAAO,OAAO,IAAI,QAAQ;EAAE,GAAG;EAAO,UAAU;CAAO;AACzD;;;AAIA,SAAS,SACP,OACA,QACA,MACA,MACA,YACA,OACU;CACV,MAAM,MAAM,gBAAgB,OAAO;EAAE,GAAG;EAAM,OAAO,EAAE,WAAW;CAAE,CAAC;CACrE,OAAO,SAAkB,KAAK,gBAAgB,QAAQ,MAAM,YAAY,KAAK,CAAC;AAChF;;AAGA,SAAgB,gBACd,GACA,MACA,YACA,OACoB;CACpB,OAAO;EACL,eAAe,MAAM,kBAAkB;EACvC,OAAO,EAAE,KAAK,EAAE,OAAO;EACvB,aAA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