@weasel-js/core 1.9.2 → 1.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (542) hide show
  1. package/CHANGELOG.md +393 -0
  2. package/README.md +2 -2
  3. package/dist/WeaselProvider.js +5 -5
  4. package/dist/affordances/composeAffordanceLayer.js +10 -20
  5. package/dist/affordances/composeAffordanceLayer.js.map +1 -1
  6. package/dist/affordances/cornerResize.js +25 -17
  7. package/dist/affordances/cornerResize.js.map +1 -1
  8. package/dist/affordances/hitAffordanceRegions.js +27 -20
  9. package/dist/affordances/hitAffordanceRegions.js.map +1 -1
  10. package/dist/affordances/rotationHandle.js +18 -18
  11. package/dist/affordances/rotationHandle.js.map +1 -1
  12. package/dist/animation/behaviors/momentum.js +93 -55
  13. package/dist/animation/behaviors/momentum.js.map +1 -1
  14. package/dist/animation/loop.js +10 -12
  15. package/dist/animation/loop.js.map +1 -1
  16. package/dist/animation/reflow.js +8 -8
  17. package/dist/animation/reflow.js.map +1 -1
  18. package/dist/animation/stagger.js +64 -56
  19. package/dist/animation/stagger.js.map +1 -1
  20. package/dist/animation/timeline/booking.js +62 -54
  21. package/dist/animation/timeline/booking.js.map +1 -1
  22. package/dist/animation/timeline/createTimeline.js +85 -76
  23. package/dist/animation/timeline/createTimeline.js.map +1 -1
  24. package/dist/animation/timeline/sampleTrack.js +13 -5
  25. package/dist/animation/timeline/sampleTrack.js.map +1 -1
  26. package/dist/animation/useAnimator.js +45 -35
  27. package/dist/animation/useAnimator.js.map +1 -1
  28. package/dist/animation/wrappers/animateLifecycle.js +31 -24
  29. package/dist/animation/wrappers/animateLifecycle.js.map +1 -1
  30. package/dist/animation/wrappers/animateOnSetPose.js +28 -26
  31. package/dist/animation/wrappers/animateOnSetPose.js.map +1 -1
  32. package/dist/animation/wrappers/instantPose.js +13 -0
  33. package/dist/animation/wrappers/instantPose.js.map +1 -0
  34. package/dist/{poseDescriptor-D-OH-tu5.d.ts → autoPoseDescriptor-Ct7yqivU.d.ts} +28 -3
  35. package/dist/barrel/chrome.js +16 -0
  36. package/dist/barrel/input.js +19 -0
  37. package/dist/barrel/interactions.js +42 -0
  38. package/dist/barrel/paint.js +18 -0
  39. package/dist/barrel/paths.js +19 -0
  40. package/dist/barrel/renderer.js +20 -0
  41. package/dist/barrel/routing.js +51 -0
  42. package/dist/barrel/text.js +18 -0
  43. package/dist/barrel/viewport.js +52 -0
  44. package/dist/builtins-DPcdghtB.d.ts +1223 -0
  45. package/dist/canvas/Canvas.js +363 -448
  46. package/dist/canvas/Canvas.js.map +1 -1
  47. package/dist/canvas/CanvasView.js +164 -165
  48. package/dist/canvas/CanvasView.js.map +1 -1
  49. package/dist/canvas/CursorCoordsHud.js +37 -32
  50. package/dist/canvas/CursorCoordsHud.js.map +1 -1
  51. package/dist/canvas/DrawCanvas.js +49 -43
  52. package/dist/canvas/DrawCanvas.js.map +1 -1
  53. package/dist/canvas/MinimapCanvas.js +26 -25
  54. package/dist/canvas/MinimapCanvas.js.map +1 -1
  55. package/dist/canvas/NodeShape.js +59 -377
  56. package/dist/canvas/NodeShape.js.map +1 -1
  57. package/dist/canvas/PickHud.js +50 -47
  58. package/dist/canvas/PickHud.js.map +1 -1
  59. package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js +167 -0
  60. package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js.map +1 -0
  61. package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +13 -13
  62. package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js +67 -0
  63. package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js.map +1 -0
  64. package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js +16 -0
  65. package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js.map +1 -0
  66. package/dist/canvas/SceneCanvas/coordTrace.js +10 -0
  67. package/dist/canvas/SceneCanvas/coordTrace.js.map +1 -0
  68. package/dist/canvas/SceneCanvas/defaultNodeProperties.js +146 -92
  69. package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
  70. package/dist/canvas/SceneCanvas/defaultNodeRouting.js +9 -8
  71. package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
  72. package/dist/canvas/SceneCanvas/features.js +1 -0
  73. package/dist/canvas/SceneCanvas/features.js.map +1 -1
  74. package/dist/canvas/SceneCanvas/isDev.js +12 -0
  75. package/dist/canvas/SceneCanvas/isDev.js.map +1 -0
  76. package/dist/canvas/SceneCanvas/poseGeometry.js +29 -28
  77. package/dist/canvas/SceneCanvas/poseGeometry.js.map +1 -1
  78. package/dist/canvas/SceneCanvas/poseRegistrars.js +13 -0
  79. package/dist/canvas/SceneCanvas/poseRegistrars.js.map +1 -0
  80. package/dist/canvas/SceneCanvas/props.js +38 -0
  81. package/dist/canvas/SceneCanvas/props.js.map +1 -0
  82. package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js +21 -62
  83. package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js.map +1 -1
  84. package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js.map +1 -1
  85. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +46 -48
  86. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
  87. package/dist/canvas/SceneCanvas/useSceneSelectTool.js +33 -33
  88. package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
  89. package/dist/canvas/SceneCanvas.js +534 -788
  90. package/dist/canvas/SceneCanvas.js.map +1 -1
  91. package/dist/canvas/SceneViewCanvas.js +45 -43
  92. package/dist/canvas/SceneViewCanvas.js.map +1 -1
  93. package/dist/canvas/buildSceneLayer.js +91 -0
  94. package/dist/canvas/buildSceneLayer.js.map +1 -0
  95. package/dist/canvas/buildSceneTree.js +16 -19
  96. package/dist/canvas/buildSceneTree.js.map +1 -1
  97. package/dist/canvas/canvasRenderer.js +68 -52
  98. package/dist/canvas/canvasRenderer.js.map +1 -1
  99. package/dist/canvas/deps/changes.js +13 -0
  100. package/dist/canvas/deps/changes.js.map +1 -0
  101. package/dist/canvas/deps/editAnchors.js +28 -28
  102. package/dist/canvas/deps/insert.js +119 -91
  103. package/dist/canvas/deps/insert.js.map +1 -1
  104. package/dist/canvas/deps/slice.js +46 -45
  105. package/dist/canvas/deps/slice.js.map +1 -1
  106. package/dist/canvas/deps/textEdit.js +10 -9
  107. package/dist/canvas/deps/textEdit.js.map +1 -1
  108. package/dist/canvas/derivedPath.js +46 -23
  109. package/dist/canvas/derivedPath.js.map +1 -1
  110. package/dist/canvas/getNodeAtPoint.js +7 -7
  111. package/dist/canvas/getNodeAtPoint.js.map +1 -1
  112. package/dist/canvas/hud.module.js +1 -1
  113. package/dist/canvas/hud.module.js.map +1 -1
  114. package/dist/canvas/kitRequirements.js +2 -2
  115. package/dist/canvas/kitRequirements.js.map +1 -1
  116. package/dist/canvas/layerOrder.js +13 -6
  117. package/dist/canvas/layerOrder.js.map +1 -1
  118. package/dist/canvas/minimapMath.js +12 -10
  119. package/dist/canvas/minimapMath.js.map +1 -1
  120. package/dist/canvas/nodeShapes/derivedPainter.js +34 -0
  121. package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -0
  122. package/dist/canvas/nodeShapes/imagePainter.js +87 -0
  123. package/dist/canvas/nodeShapes/imagePainter.js.map +1 -0
  124. package/dist/canvas/nodeShapes/memo.js +9 -0
  125. package/dist/canvas/nodeShapes/memo.js.map +1 -0
  126. package/dist/canvas/nodeShapes/nodePaint.js +57 -0
  127. package/dist/canvas/nodeShapes/nodePaint.js.map +1 -0
  128. package/dist/canvas/nodeShapes/pathPainter.js +38 -0
  129. package/dist/canvas/nodeShapes/pathPainter.js.map +1 -0
  130. package/dist/canvas/nodeShapes/poseBox.js +20 -0
  131. package/dist/canvas/nodeShapes/poseBox.js.map +1 -0
  132. package/dist/canvas/nodeShapes/rectFallbackPainter.js +38 -0
  133. package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -0
  134. package/dist/canvas/nodeShapes/shapePainter.js +72 -0
  135. package/dist/canvas/nodeShapes/shapePainter.js.map +1 -0
  136. package/dist/canvas/nodeShapes/textPainter.js +55 -0
  137. package/dist/canvas/nodeShapes/textPainter.js.map +1 -0
  138. package/dist/canvas/overlayRoleStrokes.js.map +1 -1
  139. package/dist/canvas/paintCull.js +10 -11
  140. package/dist/canvas/paintCull.js.map +1 -1
  141. package/dist/canvas/pickWalk.js +52 -63
  142. package/dist/canvas/pickWalk.js.map +1 -1
  143. package/dist/canvas/poseRotation.js +11 -23
  144. package/dist/canvas/poseRotation.js.map +1 -1
  145. package/dist/canvas/renderDebugSnapshot.js +5 -5
  146. package/dist/canvas/renderSceneToPixels.js +3 -1
  147. package/dist/canvas/renderSceneToPixels.js.map +1 -1
  148. package/dist/canvas/sceneAdapter.js +66 -148
  149. package/dist/canvas/sceneAdapter.js.map +1 -1
  150. package/dist/canvas/sceneClipboard.js +112 -0
  151. package/dist/canvas/sceneClipboard.js.map +1 -0
  152. package/dist/canvas/sceneSlotWiring.js +4 -4
  153. package/dist/canvas/sceneSlotWiring.js.map +1 -1
  154. package/dist/canvas/sceneViewRender.js +39 -40
  155. package/dist/canvas/sceneViewRender.js.map +1 -1
  156. package/dist/canvas/useCanvasRenderer.js +14 -6
  157. package/dist/canvas/useCanvasRenderer.js.map +1 -1
  158. package/dist/canvas/useCanvasView.js +58 -0
  159. package/dist/canvas/useCanvasView.js.map +1 -0
  160. package/dist/canvas/useFrameLoop.js +35 -26
  161. package/dist/canvas/useFrameLoop.js.map +1 -1
  162. package/dist/canvas/useSceneLayerList.js +21 -0
  163. package/dist/canvas/useSceneLayerList.js.map +1 -0
  164. package/dist/clipboard.d.ts +10 -6
  165. package/dist/clone.d.ts +4 -3
  166. package/dist/core/adapters/arrayAdapter.js +48 -39
  167. package/dist/core/adapters/arrayAdapter.js.map +1 -1
  168. package/dist/core/device/index.js +5 -4
  169. package/dist/core/device/useDeviceProfile.js +38 -44
  170. package/dist/core/device/useDeviceProfile.js.map +1 -1
  171. package/dist/core/device/watchDevicePixelRatio.js +17 -0
  172. package/dist/core/device/watchDevicePixelRatio.js.map +1 -0
  173. package/dist/core/fillInPoseFrame.js.map +1 -1
  174. package/dist/core/geometry/poseDescriptor.js +21 -19
  175. package/dist/core/geometry/poseDescriptor.js.map +1 -1
  176. package/dist/core/geometry/poseFrame.js +44 -0
  177. package/dist/core/geometry/poseFrame.js.map +1 -0
  178. package/dist/core/geometry/poseRotation.js.map +1 -1
  179. package/dist/core/geometry/regionHit.js +9 -10
  180. package/dist/core/geometry/regionHit.js.map +1 -1
  181. package/dist/core/geometry/unionBounds.js +31 -29
  182. package/dist/core/geometry/unionBounds.js.map +1 -1
  183. package/dist/core/isPlainObject.js +2 -11
  184. package/dist/core/ops/arrange.js +1 -0
  185. package/dist/core/ops/arrange.js.map +1 -1
  186. package/dist/core/ops/create.js +10 -5
  187. package/dist/core/ops/create.js.map +1 -1
  188. package/dist/core/ops/delete.js +12 -24
  189. package/dist/core/ops/delete.js.map +1 -1
  190. package/dist/core/ops/reorder/index.js +43 -40
  191. package/dist/core/ops/reorder/index.js.map +1 -1
  192. package/dist/core/ops/reorder/setChildOrder.js +34 -0
  193. package/dist/core/ops/reorder/setChildOrder.js.map +1 -0
  194. package/dist/core/paintKinds.js +5 -5
  195. package/dist/core/paintKinds.js.map +1 -1
  196. package/dist/core/scene/NodeProperties.js.map +1 -1
  197. package/dist/core/scene/appliedLog.js +37 -0
  198. package/dist/core/scene/appliedLog.js.map +1 -0
  199. package/dist/core/scene/arrivalWindow.js +101 -0
  200. package/dist/core/scene/arrivalWindow.js.map +1 -0
  201. package/dist/core/scene/derivedPath.js.map +1 -1
  202. package/dist/core/scene/historyFacade.js +84 -0
  203. package/dist/core/scene/historyFacade.js.map +1 -0
  204. package/dist/core/scene/kitOps.js +173 -0
  205. package/dist/core/scene/kitOps.js.map +1 -0
  206. package/dist/core/scene/layerStack.js +38 -0
  207. package/dist/core/scene/layerStack.js.map +1 -0
  208. package/dist/core/scene/lockGuard.js +37 -0
  209. package/dist/core/scene/lockGuard.js.map +1 -0
  210. package/dist/core/scene/nodeFnFields.js +5 -6
  211. package/dist/core/scene/nodeFnFields.js.map +1 -1
  212. package/dist/core/scene/nodeMemo.js +45 -19
  213. package/dist/core/scene/nodeMemo.js.map +1 -1
  214. package/dist/core/scene/nodeStore.js +126 -0
  215. package/dist/core/scene/nodeStore.js.map +1 -0
  216. package/dist/core/scene/pickability.js +6 -0
  217. package/dist/core/scene/pickability.js.map +1 -0
  218. package/dist/core/scene/poseFeed.js +38 -38
  219. package/dist/core/scene/poseFeed.js.map +1 -1
  220. package/dist/core/scene/poseOverrides.js +34 -38
  221. package/dist/core/scene/poseOverrides.js.map +1 -1
  222. package/dist/core/scene/renderOrder.js +84 -0
  223. package/dist/core/scene/renderOrder.js.map +1 -0
  224. package/dist/core/scene/scene.js +289 -866
  225. package/dist/core/scene/scene.js.map +1 -1
  226. package/dist/core/scene/serialization.js +68 -0
  227. package/dist/core/scene/serialization.js.map +1 -0
  228. package/dist/core/scene/treeOrder.js +13 -0
  229. package/dist/core/scene/treeOrder.js.map +1 -0
  230. package/dist/core/scene/types.js.map +1 -1
  231. package/dist/core/viewport/meanScale.js +1 -1
  232. package/dist/core/viewport/meanScale.js.map +1 -1
  233. package/dist/core/viewport/view.js +12 -12
  234. package/dist/core/viewport/view.js.map +1 -1
  235. package/dist/core/viewport/zoomBounds.js +10 -8
  236. package/dist/core/viewport/zoomBounds.js.map +1 -1
  237. package/dist/{cornerHandles-BCrDp_mH.d.ts → cornerHandles-CtCb8a3G.d.ts} +1 -1
  238. package/dist/debug/createDebugOverlayLayer.js +14 -14
  239. package/dist/debug/createDebugOverlayLayer.js.map +1 -1
  240. package/dist/debug/flag.js +2 -41
  241. package/dist/features/chrome-caps/useHoverTracking.js +22 -17
  242. package/dist/features/chrome-caps/useHoverTracking.js.map +1 -1
  243. package/dist/features/focus/gateLayer.js +3 -4
  244. package/dist/features/focus/gateLayer.js.map +1 -1
  245. package/dist/features/images/imageCache.js +19 -9
  246. package/dist/features/images/imageCache.js.map +1 -1
  247. package/dist/features/ingestion/contentHandlers.js +14 -11
  248. package/dist/features/ingestion/contentHandlers.js.map +1 -1
  249. package/dist/features/ingestion/index.js +1 -1
  250. package/dist/features/ingestion/registerKitHandlers.js +7 -7
  251. package/dist/features/ingestion/weaselJsonHandler.js +17 -14
  252. package/dist/features/ingestion/weaselJsonHandler.js.map +1 -1
  253. package/dist/features/meshPaint/lazyKind.js +201 -35
  254. package/dist/features/meshPaint/lazyKind.js.map +1 -1
  255. package/dist/features/meshPaint/meshPaint.js +82 -79
  256. package/dist/features/meshPaint/meshPaint.js.map +1 -1
  257. package/dist/features/minimap/createMinimapContribution.js +42 -42
  258. package/dist/features/minimap/layers.js +44 -62
  259. package/dist/features/minimap/layers.js.map +1 -1
  260. package/dist/features/parallax/createParallaxPlane.js +10 -14
  261. package/dist/features/parallax/createParallaxPlane.js.map +1 -1
  262. package/dist/features/paths/anchorEdits.js +19 -8
  263. package/dist/features/paths/anchorEdits.js.map +1 -1
  264. package/dist/features/paths/anchors.js +31 -26
  265. package/dist/features/paths/anchors.js.map +1 -1
  266. package/dist/features/paths/booleans.js +2 -2
  267. package/dist/features/paths/index.js +13 -11
  268. package/dist/features/paths/markerCommands.js +37 -36
  269. package/dist/features/paths/markerCommands.js.map +1 -1
  270. package/dist/features/paths/pathInWorld.js +19 -19
  271. package/dist/features/paths/pathInWorld.js.map +1 -1
  272. package/dist/features/paths/pathLayer.js.map +1 -1
  273. package/dist/features/paths/strokeToPath.js +40 -0
  274. package/dist/features/paths/strokeToPath.js.map +1 -0
  275. package/dist/features/paths/tessellate/stroke.js.map +1 -1
  276. package/dist/features/patterns/commandPaint.js +18 -0
  277. package/dist/features/patterns/commandPaint.js.map +1 -0
  278. package/dist/features/patterns/index.js +5 -17
  279. package/dist/features/patterns/index.js.map +1 -1
  280. package/dist/features/patterns/rasterizeTile.js +17 -0
  281. package/dist/features/patterns/rasterizeTile.js.map +1 -0
  282. package/dist/features/patterns/resolveSpec.js +52 -44
  283. package/dist/features/patterns/resolveSpec.js.map +1 -1
  284. package/dist/features/poseRun/usePoseRun.js +8 -3
  285. package/dist/features/poseRun/usePoseRun.js.map +1 -1
  286. package/dist/features/selection/SelectionContext.js +5 -0
  287. package/dist/features/selection/SelectionContext.js.map +1 -1
  288. package/dist/features/selection/overlay.js +18 -18
  289. package/dist/features/selection/overlay.js.map +1 -1
  290. package/dist/features/text/domOffsets.js +82 -0
  291. package/dist/features/text/domOffsets.js.map +1 -0
  292. package/dist/features/text/domRuns.js +103 -131
  293. package/dist/features/text/domRuns.js.map +1 -1
  294. package/dist/features/text/hitTest.js +5 -2
  295. package/dist/features/text/hitTest.js.map +1 -1
  296. package/dist/features/text/isTextData.js +8 -0
  297. package/dist/features/text/isTextData.js.map +1 -0
  298. package/dist/features/text/overlayDirection.js +15 -0
  299. package/dist/features/text/overlayDirection.js.map +1 -0
  300. package/dist/features/text/runs/rangeStyle.js +32 -34
  301. package/dist/features/text/runs/rangeStyle.js.map +1 -1
  302. package/dist/features/text/textCommand.js +34 -33
  303. package/dist/features/text/textCommand.js.map +1 -1
  304. package/dist/features/text/textToPath.js +40 -40
  305. package/dist/features/text/textToPath.js.map +1 -1
  306. package/dist/features/text/useSceneTextEdit.js +76 -82
  307. package/dist/features/text/useSceneTextEdit.js.map +1 -1
  308. package/dist/features/text/useTextEdit.js +184 -160
  309. package/dist/features/text/useTextEdit.js.map +1 -1
  310. package/dist/features/tiling/createTiledLayer.js +24 -22
  311. package/dist/features/tiling/createTiledLayer.js.map +1 -1
  312. package/dist/index.d.ts +11010 -7700
  313. package/dist/index.js +316 -309
  314. package/dist/input/keyState.js +42 -43
  315. package/dist/input/keyState.js.map +1 -1
  316. package/dist/input/useKeyModifiers.js +11 -0
  317. package/dist/input/useKeyModifiers.js.map +1 -0
  318. package/dist/interactions/actions/align/align.js +8 -8
  319. package/dist/interactions/actions/clipboard/clipboardOps.js +34 -32
  320. package/dist/interactions/actions/clipboard/clipboardOps.js.map +1 -1
  321. package/dist/interactions/actions/clipboard/materializePaste.js +10 -7
  322. package/dist/interactions/actions/clipboard/materializePaste.js.map +1 -1
  323. package/dist/interactions/actions/clipboard/wireFormat.js.map +1 -1
  324. package/dist/interactions/actions/clone/behaviors/cloneByAltDrag.js.map +1 -1
  325. package/dist/interactions/actions/defaultCommitAdapter.js +20 -18
  326. package/dist/interactions/actions/defaultCommitAdapter.js.map +1 -1
  327. package/dist/interactions/actions/defaults/align.js +9 -10
  328. package/dist/interactions/actions/defaults/align.js.map +1 -1
  329. package/dist/interactions/actions/defaults/anchorEditing.js +59 -81
  330. package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
  331. package/dist/interactions/actions/defaults/areaSelect.js +35 -38
  332. package/dist/interactions/actions/defaults/areaSelect.js.map +1 -1
  333. package/dist/interactions/actions/defaults/clipboard.js +26 -10
  334. package/dist/interactions/actions/defaults/clipboard.js.map +1 -1
  335. package/dist/interactions/actions/defaults/clone.js +44 -60
  336. package/dist/interactions/actions/defaults/clone.js.map +1 -1
  337. package/dist/interactions/actions/defaults/copySubtree.js +40 -0
  338. package/dist/interactions/actions/defaults/copySubtree.js.map +1 -0
  339. package/dist/interactions/actions/defaults/distribute.js +14 -13
  340. package/dist/interactions/actions/defaults/distribute.js.map +1 -1
  341. package/dist/interactions/actions/defaults/duplicate.js +17 -57
  342. package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
  343. package/dist/interactions/actions/defaults/editAnchors.js +18 -18
  344. package/dist/interactions/actions/defaults/enterTextEdit.js.map +1 -1
  345. package/dist/interactions/actions/defaults/flip.js +52 -46
  346. package/dist/interactions/actions/defaults/flip.js.map +1 -1
  347. package/dist/interactions/actions/defaults/group.js +43 -48
  348. package/dist/interactions/actions/defaults/group.js.map +1 -1
  349. package/dist/interactions/actions/defaults/ingest.js +35 -33
  350. package/dist/interactions/actions/defaults/ingest.js.map +1 -1
  351. package/dist/interactions/actions/defaults/insert.js +50 -51
  352. package/dist/interactions/actions/defaults/insert.js.map +1 -1
  353. package/dist/interactions/actions/defaults/insertPathAnchor.js +7 -7
  354. package/dist/interactions/actions/defaults/lassoSelect.js +67 -70
  355. package/dist/interactions/actions/defaults/lassoSelect.js.map +1 -1
  356. package/dist/interactions/actions/defaults/move.js +267 -249
  357. package/dist/interactions/actions/defaults/move.js.map +1 -1
  358. package/dist/interactions/actions/defaults/nudge.js +40 -68
  359. package/dist/interactions/actions/defaults/nudge.js.map +1 -1
  360. package/dist/interactions/actions/defaults/nudgeSteps.js +37 -0
  361. package/dist/interactions/actions/defaults/nudgeSteps.js.map +1 -0
  362. package/dist/interactions/actions/defaults/reorder.js +2 -0
  363. package/dist/interactions/actions/defaults/reorder.js.map +1 -1
  364. package/dist/interactions/actions/defaults/resize.js +104 -98
  365. package/dist/interactions/actions/defaults/resize.js.map +1 -1
  366. package/dist/interactions/actions/defaults/rotate.js +111 -110
  367. package/dist/interactions/actions/defaults/rotate.js.map +1 -1
  368. package/dist/interactions/actions/defaults/setFill.js +7 -7
  369. package/dist/interactions/actions/defaults/setFillOpacity.js +4 -4
  370. package/dist/interactions/actions/defaults/setStroke.js +12 -12
  371. package/dist/interactions/actions/defaults/setStrokeOpacity.js +6 -6
  372. package/dist/interactions/actions/defaults/sliceOps.js +19 -19
  373. package/dist/interactions/actions/defaults/viewportDragPan.js +37 -26
  374. package/dist/interactions/actions/defaults/viewportDragPan.js.map +1 -1
  375. package/dist/interactions/actions/edit-anchors/geometry.js +28 -23
  376. package/dist/interactions/actions/edit-anchors/geometry.js.map +1 -1
  377. package/dist/interactions/actions/flip/helpers.js +30 -17
  378. package/dist/interactions/actions/flip/helpers.js.map +1 -1
  379. package/dist/interactions/actions/hitSelection.js +8 -0
  380. package/dist/interactions/actions/hitSelection.js.map +1 -0
  381. package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js +14 -18
  382. package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js.map +1 -1
  383. package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js +5 -5
  384. package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js.map +1 -1
  385. package/dist/interactions/actions/move/behaviors/snapToContainer.js +32 -21
  386. package/dist/interactions/actions/move/behaviors/snapToContainer.js.map +1 -1
  387. package/dist/interactions/actions/move/gestureAdapter.js +32 -15
  388. package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
  389. package/dist/interactions/actions/move/landedDescendants.js +33 -0
  390. package/dist/interactions/actions/move/landedDescendants.js.map +1 -0
  391. package/dist/interactions/actions/outlines/createOutlines.js +18 -18
  392. package/dist/interactions/actions/poseDescriptorDep.js +16 -4
  393. package/dist/interactions/actions/poseDescriptorDep.js.map +1 -1
  394. package/dist/interactions/actions/poseFrame.js +11 -6
  395. package/dist/interactions/actions/poseFrame.js.map +1 -1
  396. package/dist/interactions/actions/previewOverrides.js +5 -5
  397. package/dist/interactions/actions/previewOverrides.js.map +1 -1
  398. package/dist/interactions/actions/selectionSubtree.js +69 -0
  399. package/dist/interactions/actions/selectionSubtree.js.map +1 -0
  400. package/dist/interactions/actions/useStandardActions.js +66 -62
  401. package/dist/interactions/actions/useStandardActions.js.map +1 -1
  402. package/dist/interactions/gestures/dragGesture/dragGesture.js +4 -7
  403. package/dist/interactions/gestures/dragGesture/dragGesture.js.map +1 -1
  404. package/dist/interactions/gestures/dragGesture/dragPointOf.js +23 -0
  405. package/dist/interactions/gestures/dragGesture/dragPointOf.js.map +1 -0
  406. package/dist/interactions/gestures/handleDrag/handleDrag.js +21 -26
  407. package/dist/interactions/gestures/handleDrag/handleDrag.js.map +1 -1
  408. package/dist/interactions/gestures/pointerDrag/pointerDrag.js +8 -6
  409. package/dist/interactions/gestures/pointerDrag/pointerDrag.js.map +1 -1
  410. package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +8 -4
  411. package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
  412. package/dist/{math-Drrw4ewZ.d.ts → math-J-ACHyEg.d.ts} +1 -2
  413. package/dist/math.d.ts +2 -3
  414. package/dist/move.d.ts +12 -11
  415. package/dist/{originProjection-DEklpDc_.d.ts → originProjection-gHnOup4e.d.ts} +1 -1
  416. package/dist/{registerProgram-BMZRDgrh.d.ts → registerProgram-T9S_PfAX.d.ts} +18 -7
  417. package/dist/renderer/DrawCommand.js.map +1 -1
  418. package/dist/renderer/WeaselRenderer.js +75 -73
  419. package/dist/renderer/WeaselRenderer.js.map +1 -1
  420. package/dist/renderer/cache/GLImageCache.js +15 -5
  421. package/dist/renderer/cache/GLImageCache.js.map +1 -1
  422. package/dist/renderer/cache/GLMeshCache.js +23 -23
  423. package/dist/renderer/cache/GLMeshCache.js.map +1 -1
  424. package/dist/renderer/cache/GLTextureCache.js +18 -1
  425. package/dist/renderer/cache/GLTextureCache.js.map +1 -1
  426. package/dist/renderer/cache/cache.js.map +1 -1
  427. package/dist/renderer/cache/markerCommandCache.js.map +1 -1
  428. package/dist/renderer/cache/strokeMeshCache.js.map +1 -1
  429. package/dist/renderer/cullDrawCommands.js +11 -11
  430. package/dist/renderer/draw/batch.js +133 -0
  431. package/dist/renderer/draw/batch.js.map +1 -0
  432. package/dist/renderer/draw/clip.js +89 -0
  433. package/dist/renderer/draw/clip.js.map +1 -0
  434. package/dist/renderer/draw/customShader.js +230 -0
  435. package/dist/renderer/draw/customShader.js.map +1 -0
  436. package/dist/renderer/draw/drawTriangles.js +8 -0
  437. package/dist/renderer/draw/drawTriangles.js.map +1 -0
  438. package/dist/renderer/draw/effects.js +28 -0
  439. package/dist/renderer/draw/effects.js.map +1 -0
  440. package/dist/renderer/draw/flushBatch.js +35 -0
  441. package/dist/renderer/draw/flushBatch.js.map +1 -0
  442. package/dist/renderer/draw/gradient.js +90 -0
  443. package/dist/renderer/draw/gradient.js.map +1 -0
  444. package/dist/renderer/draw/image.js +38 -0
  445. package/dist/renderer/draw/image.js.map +1 -0
  446. package/dist/renderer/draw/mesh.js +16 -0
  447. package/dist/renderer/draw/mesh.js.map +1 -0
  448. package/dist/renderer/draw/paintBind.js +70 -0
  449. package/dist/renderer/draw/paintBind.js.map +1 -0
  450. package/dist/renderer/draw/pathPaint.js +142 -0
  451. package/dist/renderer/draw/pathPaint.js.map +1 -0
  452. package/dist/renderer/draw/scratchPass.js +83 -0
  453. package/dist/renderer/draw/scratchPass.js.map +1 -0
  454. package/dist/renderer/draw/stencil.js +28 -0
  455. package/dist/renderer/draw/stencil.js.map +1 -0
  456. package/dist/renderer/draw/text.js +167 -0
  457. package/dist/renderer/draw/text.js.map +1 -0
  458. package/dist/renderer/draw/uniforms.js +77 -0
  459. package/dist/renderer/draw/uniforms.js.map +1 -0
  460. package/dist/renderer/draw.js +60 -1116
  461. package/dist/renderer/draw.js.map +1 -1
  462. package/dist/renderer/effects/EffectTargets.js +3 -0
  463. package/dist/renderer/effects/EffectTargets.js.map +1 -1
  464. package/dist/renderer/effects/composite.js +7 -5
  465. package/dist/renderer/effects/composite.js.map +1 -1
  466. package/dist/renderer/index.js +18 -17
  467. package/dist/renderer/math/color.js +63 -83
  468. package/dist/renderer/math/color.js.map +1 -1
  469. package/dist/renderer/math/mat3.js +15 -11
  470. package/dist/renderer/math/mat3.js.map +1 -1
  471. package/dist/renderer/math/viewToMat3.js +1 -1
  472. package/dist/renderer/math/viewToMat3.js.map +1 -1
  473. package/dist/renderer/shaders/ShaderProgram.js +13 -13
  474. package/dist/renderer/shaders/ShaderProgram.js.map +1 -1
  475. package/dist/renderer/shaders/glyphPaint.js +3 -3
  476. package/dist/renderer/shaders/glyphPaint.js.map +1 -1
  477. package/dist/renderer/shaders/gradFill.js +2 -1
  478. package/dist/renderer/shaders/gradFill.js.map +1 -1
  479. package/dist/renderer/shaders/pathFill.js +2 -1
  480. package/dist/renderer/shaders/pathFill.js.map +1 -1
  481. package/dist/renderer/shaders/patternFill.js +2 -1
  482. package/dist/renderer/shaders/patternFill.js.map +1 -1
  483. package/dist/renderer/shaders/registerProgram.js.map +1 -1
  484. package/dist/renderer/strokeLengths.js.map +1 -1
  485. package/dist/renderer/textures/registerTexture.js +25 -5
  486. package/dist/renderer/textures/registerTexture.js.map +1 -1
  487. package/dist/renderer.d.ts +16 -15
  488. package/dist/renderer.js +17 -16
  489. package/dist/resize.d.ts +5 -6
  490. package/dist/resize.js +5 -5
  491. package/dist/style.css +1 -1
  492. package/dist/test-hook/install.js +12 -6
  493. package/dist/test-hook/install.js.map +1 -1
  494. package/dist/{test-seams-CuIxe0xY.d.ts → test-seams-DM2B87-g.d.ts} +4 -4
  495. package/dist/test-seams.d.ts +2 -2
  496. package/dist/tools/builtin/ellipse/useEllipseTool.js +1 -0
  497. package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
  498. package/dist/tools/builtin/hand/useHandTool.js +1 -0
  499. package/dist/tools/builtin/hand/useHandTool.js.map +1 -1
  500. package/dist/tools/builtin/lasso/useLassoTool.js +11 -11
  501. package/dist/tools/builtin/lasso/useLassoTool.js.map +1 -1
  502. package/dist/tools/builtin/line/useLineTool.js +1 -0
  503. package/dist/tools/builtin/line/useLineTool.js.map +1 -1
  504. package/dist/tools/builtin/pen/usePenTool.js +153 -103
  505. package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
  506. package/dist/tools/builtin/pencil/usePencilTool.js +1 -0
  507. package/dist/tools/builtin/pencil/usePencilTool.js.map +1 -1
  508. package/dist/tools/builtin/polygon/usePolygonTool.js +13 -8
  509. package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
  510. package/dist/tools/builtin/rect/useRectTool.js +1 -0
  511. package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
  512. package/dist/tools/builtin/select/selectionContributions.js +24 -23
  513. package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
  514. package/dist/tools/builtin/select/useSelectTool.js +51 -48
  515. package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
  516. package/dist/tools/builtin/shared/pointerFollower.js +17 -0
  517. package/dist/tools/builtin/shared/pointerFollower.js.map +1 -0
  518. package/dist/tools/builtin/slice/useSliceTool.js +49 -54
  519. package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
  520. package/dist/tools/builtin/star/useStarTool.js +22 -16
  521. package/dist/tools/builtin/star/useStarTool.js.map +1 -1
  522. package/dist/tools/builtin/text/useTextTool.js +13 -2
  523. package/dist/tools/builtin/text/useTextTool.js.map +1 -1
  524. package/dist/tools/useKeybindings.js +14 -30
  525. package/dist/tools/useKeybindings.js.map +1 -1
  526. package/dist/{types-B_9g6hMM.d.ts → types-B4iJRHC3.d.ts} +5 -1
  527. package/dist/{types-A37hYkeR.d.ts → types-k-5Oqh-U.d.ts} +31 -7
  528. package/dist/util/color.js +3 -3
  529. package/dist/util/color.js.map +1 -1
  530. package/dist/util/paint.js.map +1 -1
  531. package/dist/version.js +1 -1
  532. package/package.json +20 -18
  533. package/dist/autoPoseDescriptor-vCdt55xm.d.ts +0 -27
  534. package/dist/builtins-C-VgUlWI.d.ts +0 -4514
  535. package/dist/core/isPlainObject.js.map +0 -1
  536. package/dist/debug/flag.js.map +0 -1
  537. package/dist/interactions/actions/defaults/freshNodeId.js +0 -10
  538. package/dist/interactions/actions/defaults/freshNodeId.js.map +0 -1
  539. package/dist/renderer/shaders/imageFill.js +0 -14
  540. package/dist/renderer/shaders/imageFill.js.map +0 -1
  541. package/dist/tools/prefs.js +0 -47
  542. package/dist/tools/prefs.js.map +0 -1
@@ -1,50 +1,52 @@
1
- import { toPlane as e } from "../../../core/viewport/parallax.js";
2
- import { meanScale as t } from "../../../core/viewport/meanScale.js";
1
+ import { meanScale as e } from "../../../core/viewport/meanScale.js";
2
+ import { toPlane as t } from "../../../core/viewport/parallax.js";
3
3
  import { poseDescriptorForNode as n } from "../../../core/geometry/poseDescriptor.js";
4
4
  import { AUTO_POSE_DESCRIPTOR as r } from "../../../interactions/actions/resize/autoPoseDescriptor.js";
5
- import { defineTool as i } from "../../overlayBinding.js";
6
- import a from "../../../icons/SelectIcon.js";
7
- import { shapeCoversPoint as o } from "../../../canvas/NodeShape.js";
8
- import { adapterPickSource as s, ownClipOf as c, pickWalk as l, scenePlaneOf as u } from "../../../canvas/pickWalk.js";
5
+ import "../../../core/selection/selectionTarget.js";
6
+ import { shapeCoversPoint as i } from "../../../canvas/NodeShape.js";
7
+ import { adapterPickSource as a, ownClipOf as o, pickWalk as s, scenePlaneOf as c } from "../../../canvas/pickWalk.js";
8
+ import { defineTool as l } from "../../overlayBinding.js";
9
+ import u from "../../../icons/SelectIcon.js";
9
10
  import { pickTopMostHit as d } from "../pickTopMostHit.js";
10
11
  import { onEmptyCanvas as f } from "./selectionContributions.js";
11
- import "../../../core/selection/selectionTarget.js";
12
12
  import { pathContainsPoint as p } from "@weasel-js/geom";
13
13
  import { createElement as m, useMemo as h, useRef as g } from "react";
14
14
  import { useLatest as _ } from "@weasel-js/react";
15
15
  import { ActionDisabledReason as v } from "@weasel-js/routing";
16
+ import { hitPredicate as y } from "@weasel-js/gestures";
16
17
  //#region src/tools/builtin/select/useSelectTool.ts
17
- function y(y, b) {
18
- let x = b.poseDescriptor ?? r, S = b.leafPicking === "silhouette", C = b.pickTolerance ?? 0, w = b.pickEvery ?? ((r, i) => {
19
- let a = (r, i, s) => {
20
- let l = (e, t, n) => {
21
- let a = S ? s : 0;
22
- return r >= n.x - a && r <= n.x + n.width + a && i >= n.y - a && i <= n.y + n.height + a ? !S || o(e, t, r, i, { tolerance: s }) : !1;
18
+ var b = y((e) => e == null);
19
+ function x(y, x) {
20
+ let S = x.poseDescriptor ?? r, C = x.leafPicking === "silhouette", w = x.pickTolerance ?? 0, T = x.pickEvery ?? ((r, l) => {
21
+ let u = (r, a, s) => {
22
+ let c = (e, t, n) => {
23
+ let o = C ? s : 0;
24
+ return r >= n.x - o && r <= n.x + n.width + o && a >= n.y - o && a <= n.y + n.height + o ? !C || i(e, t, r, a, { tolerance: s }) : !1;
23
25
  };
24
26
  return {
25
27
  hits: (e, t) => {
26
- let a = n(x, e).getBounds(t);
27
- if (e.kind !== "container") return l(e, t, a);
28
- if (!(r >= a.x && r <= a.x + a.width && i >= a.y && i <= a.y + a.height)) return !1;
29
- let o = c(e, t);
30
- return o === null || p(o, r, i);
28
+ let i = n(S, e).getBounds(t);
29
+ if (e.kind !== "container") return c(e, t, i);
30
+ if (!(r >= i.x && r <= i.x + i.width && a >= i.y && a <= i.y + i.height)) return !1;
31
+ let s = o(e, t);
32
+ return s === null || p(s, r, a);
31
33
  },
32
- clipAdmits: (e) => p(e, r, i),
34
+ clipAdmits: (e) => p(e, r, a),
33
35
  inPlane: (n) => {
34
- let o = e(n, {
36
+ let i = t(n, {
35
37
  x: r,
36
- y: i
38
+ y: a
37
39
  });
38
- return a(o.x, o.y, s * t(n.scale));
40
+ return u(i.x, i.y, s * e(n.scale));
39
41
  }
40
42
  };
41
- }, d = b.getView?.() ?? null, f = d ? u(y.getLayers?.(), d) : null;
42
- return l(s(y, {
43
- ...b.alphaOf ? { alphaOf: b.alphaOf } : {},
44
- ...b.layerIsPainted ? { layerIsPainted: b.layerIsPainted } : {},
43
+ }, d = x.getView?.() ?? null, f = d ? c(y.getLayers?.(), d) : null;
44
+ return s(a(y, {
45
+ ...x.alphaOf ? { alphaOf: x.alphaOf } : {},
46
+ ...x.layerIsPainted ? { layerIsPainted: x.layerIsPainted } : {},
45
47
  ...f ? { planeOf: f } : {}
46
- }), a(r, i, C));
47
- }), T = _(w), E = g({ deferredClickId: null }), D = _(b), O = _(y), k = h(() => ({
48
+ }), u(r, l, w));
49
+ }), E = _(T), D = g({ deferredClickId: null }), O = _(x), k = _(y), A = h(() => ({
48
50
  id: "select.pick",
49
51
  label: "Select — pick under pointer",
50
52
  eligible: { capability: "creates-selection" },
@@ -59,33 +61,33 @@ function y(y, b) {
59
61
  ctrl: !1,
60
62
  meta: !1,
61
63
  shift: !1
62
- }, a = D.current, o = r.get(), s = a.pickBest ? a.pickBest(n.worldX, n.worldY, i.alt, o) : (() => {
63
- let e = T.current(n.worldX, n.worldY);
64
- return e.length === 0 ? null : d(e, O.current) ?? e[0];
64
+ }, a = O.current, o = r.get(), s = a.pickBest ? a.pickBest(n.worldX, n.worldY, i.alt, o) : (() => {
65
+ let e = E.current(n.worldX, n.worldY);
66
+ return e.length === 0 ? null : d(e, k.current) ?? e[0];
65
67
  })();
66
68
  if (s === null) {
67
- E.current = { deferredClickId: null };
69
+ D.current = { deferredClickId: null };
68
70
  return;
69
71
  }
70
72
  let c = o.includes(s), l = i.shift || i.meta, u = l && a.extendClickLocked?.() === !0, f = c && o.length > 1 && !l;
71
- !f && !u && r.applyClick(s, i), E.current = { deferredClickId: f ? s : null };
73
+ !f && !u && r.applyClick(s, i), D.current = { deferredClickId: f ? s : null };
72
74
  }
73
75
  }
74
76
  }), [
75
- D,
76
- T,
77
- O
78
- ]), A = h(() => ({
77
+ O,
78
+ E,
79
+ k
80
+ ]), j = h(() => ({
79
81
  id: "select.collapseDeferred",
80
82
  label: "Select — collapse deferred click",
81
83
  eligible: { capability: "creates-selection" },
82
84
  requires: ["selection"],
83
- enabled: () => E.current.deferredClickId !== null || v.NotApplicable,
85
+ enabled: () => D.current.deferredClickId !== null || v.NotApplicable,
84
86
  invoker: {
85
87
  timing: "immediate",
86
88
  run: (e, t) => {
87
- let n = E.current.deferredClickId;
88
- if (E.current = { deferredClickId: null }, n === null) return;
89
+ let n = D.current.deferredClickId;
90
+ if (D.current = { deferredClickId: null }, n === null) return;
89
91
  let r = e.selection;
90
92
  if (!r) return;
91
93
  let i = t;
@@ -99,23 +101,24 @@ function y(y, b) {
99
101
  }
100
102
  }), []);
101
103
  return h(() => ({
102
- ...i({
104
+ ...l({
103
105
  id: "select",
106
+ keybinding: { key: "V" },
104
107
  capabilities: ["creates-selection"],
105
108
  hookName: "useSelectTool",
106
109
  cursor: "default",
107
110
  presentation: {
108
111
  label: "Select",
109
- icon: m(a),
112
+ icon: m(u),
110
113
  group: "select"
111
114
  },
112
- actions: [k, A]
115
+ actions: [A, j]
113
116
  }),
114
117
  bindings: [
115
118
  {
116
119
  spec: {
117
120
  kind: "pointerDown",
118
- target: { kindOf: (e) => e == null },
121
+ target: { kindOf: b },
119
122
  mods: {
120
123
  shift: "optional",
121
124
  alt: "optional",
@@ -128,7 +131,7 @@ function y(y, b) {
128
131
  {
129
132
  spec: {
130
133
  kind: "click",
131
- target: { kindOf: (e) => e == null },
134
+ target: { kindOf: b },
132
135
  mods: {
133
136
  shift: "optional",
134
137
  alt: "optional",
@@ -148,15 +151,15 @@ function y(y, b) {
148
151
  {
149
152
  spec: {
150
153
  kind: "click",
151
- target: { kindOf: (e, t) => e == null && t === "empty" },
154
+ target: { kindOf: f },
152
155
  mods: {}
153
156
  },
154
157
  actionId: "clearSelection"
155
158
  }
156
159
  ]
157
- }), [k, A]);
160
+ }), [A, j]);
158
161
  }
159
162
  //#endregion
160
- export { y as useSelectTool };
163
+ export { x as useSelectTool };
161
164
 
162
165
  //# sourceMappingURL=useSelectTool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectTool.js","names":["SelectIcon","useSelectTool","d","options","AUTO_POSE_DESCRIPTOR","preciseLeaves","tolerance","pickEveryFn","pointQuery","covers","slop","t","px","b","py","shapeCoversPoint","node","pose","poseDescriptorForNode","own","ownClipOf","pathContainsPoint","clip","p","toPlane","m","meanScale","camera","planeOf","scenePlaneOf","adapter","pickWalk","adapterPickSource","worldX","worldY","pickEveryRef","useLatest","pressRef","useRef","optionsRef","adapterRef","pickAction","useMemo","params","selection","deps","mods","opts","sel","top","ids","pickTopMostHit","hitAlreadySelected","isExtend","extendLocked","deferClick","collapseDeferredAction","ActionDisabledReason","deferred","defineTool","createElement","hit","onEmptyCanvas","body"],"sources":["../../../../src/tools/builtin/select/useSelectTool.ts"],"sourcesContent":["import { useMemo, useRef, createElement } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { SelectIcon } from '../../../icons';\nimport { pathContainsPoint } from '@weasel-js/geom';\nimport { shapeCoversPoint } from 'canvas/NodeShape';\nimport { pickWalk, adapterPickSource, ownClipOf, scenePlaneOf, type PickQuery } from 'canvas/pickWalk';\nimport { toPlane } from 'core/viewport/parallax';\nimport { meanScale } from 'core/viewport/meanScale';\nimport type { View } from 'core/viewport/view';\nimport type { LayerEnumerableAdapter } from 'core/adapters/types';\nimport type { Node } from 'core/scene/types';\nimport type { MoveAdapter } from 'core/adapters/types';\nimport type { AreaSelectAdapter } from 'core/adapters/types';\nimport type { NodeId } from 'core/scene/types';\nimport { defineTool } from '../../overlayBinding';\nimport type { Action } from '@weasel-js/routing';\nimport { ActionDisabledReason } from '@weasel-js/routing';\nimport type { Tool } from '../../overlayBinding';\nimport { pickTopMostHit } from '../pickTopMostHit';\nimport { onEmptyCanvas } from './selectionContributions';\nimport { poseDescriptorForNode, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport { AUTO_POSE_DESCRIPTOR } from 'interactions/actions/resize/autoPoseDescriptor';\nimport { MULTI_RESIZE_TARGET_ID, type Bounds } from '../shared/selectionTarget';\nexport type { Bounds };\nexport { MULTI_RESIZE_TARGET_ID };\n\n/** Options for `useSelectTool`: how a point resolves to nodes, how a click\n * chooses among them, and the appearance of the marquee. */\nexport interface UseSelectToolOptions<TPose> {\n /** Return ids of all objects whose painted body covers (worldX, worldY).\n * Order doesn't matter — the tool collapses parent/child overlap via\n * `pickTopMostHit`. When omitted, defaults to an AABB-vs-point scan over\n * `adapter.getNodes()` using the pose descriptor. Override for tighter\n * shapes (path / polygon hit-tests). */\n pickEvery?: (worldX: number, worldY: number) => string[];\n /** Optional alt-aware selection-update hit returning the single id the\n * click should act on. */\n pickBest?: (\n worldX: number,\n worldY: number,\n alt: boolean,\n selection: readonly string[],\n ) => string | null;\n /** How to read poses for the default `pickEvery`. Default\n * `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<TPose>;\n /**\n * How the default `pickEvery` decides a **leaf** node covers the pointer.\n * Ignored when `pickEvery` is supplied.\n *\n * - `'aabb'` (default) — the pose rect. Cheap, and the historical behavior:\n * a click anywhere in the bounding box selects the node.\n * - `'silhouette'` — the pose rect as a pre-test, then the ink the painter\n * lays down: `findShapeSilhouette` filled or not per the painter's `ink`,\n * plus its outline widened by the stroke half-width and `pickTolerance`.\n * A click inside the bounding box but outside the drawn shape misses —\n * the concave notch of a star, the corner outside an ellipse, the blank\n * half of a text box — while a click on the thin outline of an unfilled\n * shape hits.\n *\n * Container nodes already consult their silhouette unconditionally (it is\n * how their clip is derived); this extends the same test to leaves. Not the\n * default because it changes what a click selects for every existing\n * consumer, and a painter with no `silhouette` is unaffected either way —\n * it falls back to the AABB.\n */\n leafPicking?: 'aabb' | 'silhouette';\n /**\n * Grab slop around a shape's outline, in **world** units. Default 0.\n *\n * Only consulted under `leafPicking: 'silhouette'`. World units because\n * this hook has no view; `<SceneCanvas>` takes a screen-pixel figure\n * (`geometry.pickTolerancePx`) and divides by scale on its own pick path.\n * Without some slop a hairline outline is an unhittable target.\n */\n pickTolerance?: number;\n /** Painted alpha per node in the view this tool picks for. A node painted\n * at alpha 0 is not under the pointer. Ignored when `pickEvery` is\n * supplied. */\n alphaOf?: (id: string) => number;\n /** Whether a node's `layer` reaches the screen in the view this tool picks\n * for. Ignored when `pickEvery` is supplied. */\n layerIsPainted?: (layer: string) => boolean;\n /** The camera of the view this tool picks for. With it, a node on an\n * adapter layer carrying `parallax` (`getLayers`) is picked where that\n * camera's plane paints it; without it, every layer is taken to move with\n * the camera. Ignored when `pickEvery` is supplied. */\n getView?: () => View | null;\n /**\n * When this returns true, a Shift/Meta extend-click must NOT change the\n * node selection.\n *\n * `<SceneCanvas>` wires it to \"a path is in anchor-edit mode\", where\n * Shift-click means \"add this anchor to the anchor selection\". Without\n * the lock the same click also toggles the edited node out of the node\n * selection, and the `editAnchors` dep treats that as the edit target\n * disappearing — so multi-selecting anchors silently exited edit mode.\n *\n * Only extend-clicks are locked. A plain click still re-selects, so\n * clicking a different node exits edit mode as usual.\n */\n extendClickLocked?: () => boolean;\n}\n\n/** Intersection of the move + area-select adapter interfaces.\n * Resize and rotate run through `resizeAction` / `rotateAction`. */\nexport type SelectAdapter<TNode extends { id: string }, TPose> =\n MoveAdapter<TNode, TPose>\n & AreaSelectAdapter\n & LayerEnumerableAdapter;\n\n/**\n * What the press classified, carried from `select.pick` (pointerDown) to\n * `select.collapseDeferred` (click) and to the tool's cursor.\n *\n * This is tool-local bookkeeping between two dispatches of the same gesture,\n * so it lives in a ref the tool owns rather than in dispatcher state. It used\n * to be the tool's `SelectScratch`, held by the tool-routing dispatcher, and\n * carried an `ids` list that nothing ever read — `moveAction` computes its own\n * ids from the live selection.\n *\n * @internal\n */\ninterface PressClassification {\n /**\n * Set when the press hit an already-selected node inside a multi-selection\n * with no extend modifier.\n *\n * The selection is deliberately NOT collapsed on the press: the user may be\n * starting a drag of the whole set. If the gesture turns out to be a click,\n * `select.collapseDeferred` collapses to this id on release.\n */\n deferredClickId: string | null;\n}\n\n/** Active-slot Tool:\n * - `select.pick` classifies the press (pointerDown) — it runs the tool's own\n * pickBest/pickEvery so click semantics (selection replace, extend,\n * deferred collapse) live in one place.\n * - an empty drag marquees (`areaSelect`) and a click on empty clears the\n * selection (`clearSelection`); the marquee renders via the dispatcher\n * overlay layer, driven by areaSelectAction's `overlay()`.\n * - moving and transforming the selection are not the tool's: they are the\n * ambient bindings in `selectionContributions.ts`.\n */\nexport function useSelectTool<TNode extends { id: string }, TPose>(\n adapter: SelectAdapter<TNode, TPose>,\n options: UseSelectToolOptions<TPose>,\n): Tool<null> {\n\n // pickEvery / boundsOf defaults — for any adapter the kit can derive both\n // from `adapter.getNodes()` + `adapter.getPose(id)` + the descriptor.\n const d = (options.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const preciseLeaves = options.leafPicking === 'silhouette';\n // World units here, not screen: this hook has no view. `<SceneCanvas>`\n // converts from screen px on its own pick path; a bare `useSelectTool`\n // consumer that zooms should pass `pickTolerance` from its own scale.\n const tolerance = options.pickTolerance ?? 0;\n const pickEveryFn = options.pickEvery ?? ((worldX: number, worldY: number): string[] => {\n /** A point query at (px, py) with `t` world units of slop. AABB first\n * (cheap), then the painter's ink when asked for and available. A painter\n * with no `silhouette` — or one that returns null, as `kit:text` does for\n * an empty node — keeps the AABB answer.\n *\n * The AABB pre-filter is grown by the slop for the same reason\n * `<SceneCanvas>`'s is: a shape's outline, and the slop around it, reach\n * outside the shape's own bounds, and an un-grown pre-filter would\n * discard those hits before the refinement could claim them. */\n const pointQuery = (px: number, py: number, t: number): PickQuery<TPose> => {\n const covers = (node: unknown, pose: TPose, b: Bounds): boolean => {\n const slop = preciseLeaves ? t : 0;\n if (!(px >= b.x - slop && px <= b.x + b.width + slop\n && py >= b.y - slop && py <= b.y + b.height + slop)) {\n return false;\n }\n if (!preciseLeaves) return true;\n return shapeCoversPoint(\n node as Node<unknown, string, TPose>, pose, px, py, { tolerance: t },\n );\n };\n return {\n hits: (node, pose) => {\n const b = poseDescriptorForNode(d, node).getBounds(pose);\n if (node.kind !== 'container') return covers(node, pose, b);\n // A container's own clip *is* its hit shape — it is picked where it\n // paints, and it paints only inside its clip. Ancestor clips are the\n // walk's business; this one is not.\n const inAabb = px >= b.x && px <= b.x + b.width\n && py >= b.y && py <= b.y + b.height;\n if (!inAabb) return false;\n const own = ownClipOf(node, pose);\n return own === null || pathContainsPoint(own, px, py);\n },\n clipAdmits: (clip) => pathContainsPoint(clip, px, py),\n inPlane: (m) => {\n const p = toPlane(m, { x: px, y: py });\n return pointQuery(p.x, p.y, t * meanScale(m.scale));\n },\n };\n };\n\n const camera = options.getView?.() ?? null;\n const planeOf = camera ? scenePlaneOf(adapter.getLayers?.(), camera) : null;\n return pickWalk<TPose>(adapterPickSource(adapter as never, {\n ...(options.alphaOf ? { alphaOf: options.alphaOf } : {}),\n ...(options.layerIsPainted ? { layerIsPainted: options.layerIsPainted } : {}),\n ...(planeOf ? { planeOf } : {}),\n }), pointQuery(worldX, worldY, tolerance));\n });\n\n const pickEveryRef = useLatest(pickEveryFn);\n\n // What the last press classified. Written by `select.pick`, read by\n // `select.collapseDeferred` and the cursor. See `PressClassification`.\n const pressRef = useRef<PressClassification>({ deferredClickId: null });\n\n // Options in a ref so the actions — built once — always see the live\n // callbacks without rebuilding the Tool record.\n const optionsRef = useLatest(options);\n const adapterRef = useLatest(adapter);\n\n /**\n * `select.pick` — classifies the press and updates the node selection.\n *\n * Bound to `pointerDown` rather than `click` on purpose: pressing an\n * unselected node must highlight it while the button is still down, and any\n * drag that follows has to start from the updated selection (both\n * `moveAction` and `cloneAction` read `selection.get()` in their `start`).\n *\n * Eligibility replaces the `selectionAllowed` option the audit added as an\n * interim per-route patch: this action carries the same\n * `creates-selection` capability rule the `clearSelection` binding declares,\n * so a mode that forbids selection now gates both halves of the tool by one\n * mechanism instead of by which dispatcher the route happened to live on.\n */\n const pickAction = useMemo<Action>(() => ({\n id: 'select.pick',\n label: 'Select — pick under pointer',\n eligible: { capability: 'creates-selection' },\n requires: ['selection'],\n invoker: {\n timing: 'immediate' as const,\n run: (deps, params) => {\n const p = params as {\n worldX?: number; worldY?: number;\n affordance?: unknown;\n mods?: { alt: boolean; ctrl: boolean; meta: boolean; shift: boolean };\n } | undefined;\n const selection = deps.selection;\n if (!selection || p?.worldX === undefined || p.worldY === undefined) return;\n const mods = p.mods ?? { alt: false, ctrl: false, meta: false, shift: false };\n const opts = optionsRef.current;\n\n const sel = selection.get();\n const top = opts.pickBest\n ? opts.pickBest(p.worldX, p.worldY, mods.alt, sel)\n : (() => {\n const ids = pickEveryRef.current(p.worldX, p.worldY);\n if (ids.length === 0) return null;\n return pickTopMostHit(ids, adapterRef.current) ?? ids[0];\n })();\n\n if (top === null) {\n pressRef.current = { deferredClickId: null };\n return;\n }\n\n const hitAlreadySelected = sel.includes(top as NodeId);\n const isExtend = mods.shift || mods.meta;\n // While a path is in anchor-edit mode, an extend-click belongs to the\n // anchor selection, not the node selection. Letting it through would\n // toggle the edited node out of the node selection, which the\n // `editAnchors` dep reads as \"the edit target is gone\" — so\n // shift-clicking a second anchor silently tore down edit mode.\n // Plain clicks still fall through: clicking a different node exits\n // edit mode, which is what you'd expect.\n //\n // This stays an option rather than becoming `Action.enabled` because\n // it only applies to *extend* presses, and `enabled` is evaluated\n // without the event's modifiers.\n const extendLocked = isExtend && opts.extendClickLocked?.() === true;\n const deferClick = hitAlreadySelected && sel.length > 1 && !isExtend;\n if (!deferClick && !extendLocked) {\n selection.applyClick(top as NodeId, mods);\n }\n pressRef.current = { deferredClickId: deferClick ? top : null };\n },\n },\n }), [optionsRef, pickEveryRef, adapterRef]);\n\n /**\n * `select.collapseDeferred` — the release half of the deferred multi-click.\n *\n * Pressing an already-selected node inside a multi-selection leaves the\n * selection alone so the press can start a drag of the whole set. If the\n * gesture ends without a drag, this collapses to the clicked node.\n */\n const collapseDeferredAction = useMemo<Action>(() => ({\n id: 'select.collapseDeferred',\n label: 'Select — collapse deferred click',\n eligible: { capability: 'creates-selection' },\n requires: ['selection'],\n // Declining when there is nothing deferred is what keeps this binding\n // from swallowing every click. It is bound with no target (any click can\n // in principle be the release of a deferred press) at ACTIVE scope, so\n // without the gate it would outrank ambient click bindings like\n // `selectAnchor` and silently break anchor selection. Same fall-through\n // contract `clearSelection.enabled` relies on.\n enabled: () =>\n pressRef.current.deferredClickId !== null\n ? true\n : ActionDisabledReason.NotApplicable,\n invoker: {\n timing: 'immediate' as const,\n run: (deps, params) => {\n const deferred = pressRef.current.deferredClickId;\n pressRef.current = { deferredClickId: null };\n if (deferred === null) return;\n const selection = deps.selection;\n if (!selection) return;\n const p = params as {\n mods?: { alt: boolean; ctrl: boolean; meta: boolean; shift: boolean };\n } | undefined;\n selection.applyClick(\n deferred as NodeId,\n p?.mods ?? { alt: false, ctrl: false, meta: false, shift: false },\n );\n },\n },\n }), []);\n\n return useMemo(\n () => {\n const base = defineTool<null>({\n id: 'select',\n capabilities: ['creates-selection'],\n hookName: 'useSelectTool',\n // A plain string: the mid-gesture cursors this used to compute from\n // gesture scratch now live on the actions that own those gestures\n // (`moveAction.activeCursor`, `areaSelectAction.activeCursor`), so\n // they apply to any consumer binding them, not just this tool.\n cursor: 'default',\n presentation: {\n label: 'Select',\n icon: createElement(SelectIcon),\n group: 'select',\n },\n actions: [pickAction, collapseDeferredAction],\n });\n\n return {\n ...base,\n // Declarative bindings for the gesture dispatcher. The select tool\n // only chooses: press → classify + select, release → collapse a\n // deferred multi-click, empty drag → marquee, click on empty → clear.\n // Moving, cloning, resizing and rotating the selection are ambient\n // bindings owned by the selection (`selectionContributions.ts`), so\n // they run under any tool that leaves the gesture unclaimed.\n bindings: [\n // Every press that landed on the scene rather than on chrome. This\n // is the former `initial.pointerDown['*']` route: it classifies the\n // press and applies the selection change, and it does not consume\n // the gesture — the same press goes on to open a drag or synthesize\n // a click.\n //\n // The no-affordance target is load-bearing twice over. A press on a\n // resize handle, a rotate ring, a path anchor, or a registered\n // layer's own chrome is not a body pick, and re-picking underneath\n // it would change the selection the user was about to act on. And\n // because it is expressed in the SPEC rather than as an early\n // return in the action, the press falls through to whatever owns\n // that chrome instead of being consumed here — which is how an\n // ambient binding (`@weasel-js/hud`) gets to see it at all. The old\n // pipeline got both properties by construction: affordance hits\n // bypassed the active tool entirely.\n //\n // Modifiers are all `'optional'` because they are *data* here\n // (forwarded to `SelectionApi.applyClick`, which resolves them\n // against the host's configured extend key) rather than a route.\n {\n spec: {\n kind: 'pointerDown' as const,\n target: { kindOf: (hit: unknown) => hit == null },\n mods: { shift: 'optional' as const, alt: 'optional' as const, meta: 'optional' as const, ctrl: 'optional' as const },\n },\n actionId: 'select.pick',\n },\n // Release half of the deferred multi-click. Same `'optional'`\n // modifiers, same reason.\n {\n spec: {\n kind: 'click' as const,\n target: { kindOf: (hit: unknown) => hit == null },\n mods: { shift: 'optional' as const, alt: 'optional' as const, meta: 'optional' as const, ctrl: 'optional' as const },\n },\n actionId: 'select.collapseDeferred',\n },\n // Empty drag → marquee. `onEmptyCanvas` rather than a bare `'empty'`\n // target: the ambient bindings that own the handles rank below this\n // active one, so `'empty'` took drags that start on them.\n {\n spec: { kind: 'drag' as const, target: { kindOf: onEmptyCanvas } },\n actionId: 'areaSelect',\n },\n // resize/rotate bind only drag (no click), so a click on either handle\n // (body genuinely empty) would hit target:'empty' and wrongly clear selection.\n {\n spec: {\n kind: 'click' as const,\n target: { kindOf: (hit: unknown, body?: string) => hit == null && body === 'empty' },\n mods: {},\n },\n actionId: 'clearSelection',\n },\n ],\n };\n },\n [pickAction, collapseDeferredAction],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiJA,SAAgBC,EACd,GACA,GACY;CAIZ,IAAMC,IAAKC,EAAQ,kBAAkBC,GAC/BC,IAAgBF,EAAQ,gBAAgB,cAIxCG,IAAYH,EAAQ,iBAAiB,GACrCI,IAAcJ,EAAQ,eAAe,GAAgB,MAA6B;EAUtF,IAAMK,KAAc,GAAY,GAAY,MAAgC;GAC1E,IAAMC,KAAU,GAAe,GAAa,MAAuB;IACjE,IAAMC,IAAOL,IAAgBM,IAAI;IAMjC,OALMC,KAAMC,EAAE,IAAIH,KAAQE,KAAMC,EAAE,IAAIA,EAAE,QAAQH,KACvCI,KAAMD,EAAE,IAAIH,KAAQI,KAAMD,EAAE,IAAIA,EAAE,SAASH,IAGpD,CAAKL,KACEU,EACLC,GAAsCC,GAAML,GAAIE,GAAI,EAAE,WAAWH,EAAE,CACrE,IALS;GAMX;GACA,OAAO;IACL,OAAO,GAAM,MAAS;KACpB,IAAME,IAAIK,EAAsBhB,GAAGc,CAAI,CAAC,CAAC,UAAUC,CAAI;KACvD,IAAID,EAAK,SAAS,aAAa,OAAOP,EAAOO,GAAMC,GAAMJ,CAAC;KAM1D,IAAI,EAFWD,KAAMC,EAAE,KAAKD,KAAMC,EAAE,IAAIA,EAAE,SACrCC,KAAMD,EAAE,KAAKC,KAAMD,EAAE,IAAIA,EAAE,SACnB,OAAO;KACpB,IAAMM,IAAMC,EAAUJ,GAAMC,CAAI;KAChC,OAAOE,MAAQ,QAAQE,EAAkBF,GAAKP,GAAIE,CAAE;IACt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OAAO;IACP,MAAMC,EAAc5D,CAAU;IAC9B,OAAO;GACT;GACA,SAAS,CAACyC,GAAYe,CAAsB;EAC9C,CAGK;EAOH,UAAU;GAqBR;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,SAAS,MAAiBK,KAAO,KAAK;KAChD,MAAM;MAAE,OAAO;MAAqB,KAAK;MAAqB,MAAM;MAAqB,MAAM;KAAoB;IACrH;IACA,UAAU;GACZ;GAGA;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,SAAS,MAAiBA,KAAO,KAAK;KAChD,MAAM;MAAE,OAAO;MAAqB,KAAK;MAAqB,MAAM;MAAqB,MAAM;KAAoB;IACrH;IACA,UAAU;GACZ;GAIA;IACE,MAAM;KAAE,MAAM;KAAiB,QAAQ,EAAE,QAAQC,EAAc;IAAE;IACjE,UAAU;GACZ;GAGA;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,SAAS,GAAc,MAAkBD,KAAO,QAAQE,MAAS,QAAQ;KACnF,MAAM,CAAC;IACT;IACA,UAAU;GACZ;EACF;CACF,IAEF,CAACtB,GAAYe,CAAsB,CACrC;AACF"}
1
+ {"version":3,"file":"useSelectTool.js","names":["SelectIcon","offChrome","hitPredicate","hit","useSelectTool","d","options","AUTO_POSE_DESCRIPTOR","preciseLeaves","tolerance","pickEveryFn","pointQuery","covers","slop","t","px","b","py","shapeCoversPoint","node","pose","poseDescriptorForNode","own","ownClipOf","pathContainsPoint","clip","p","toPlane","m","meanScale","camera","planeOf","scenePlaneOf","adapter","pickWalk","adapterPickSource","worldX","worldY","pickEveryRef","useLatest","pressRef","useRef","optionsRef","adapterRef","pickAction","useMemo","params","selection","deps","mods","opts","sel","top","ids","pickTopMostHit","hitAlreadySelected","isExtend","extendLocked","deferClick","collapseDeferredAction","ActionDisabledReason","deferred","defineTool","createElement","onEmptyCanvas"],"sources":["../../../../src/tools/builtin/select/useSelectTool.ts"],"sourcesContent":["import { useMemo, useRef, createElement } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { SelectIcon } from '../../../icons';\nimport { pathContainsPoint } from '@weasel-js/geom';\nimport { shapeCoversPoint } from 'canvas/NodeShape';\nimport { pickWalk, adapterPickSource, ownClipOf, scenePlaneOf, type PickQuery } from 'canvas/pickWalk';\nimport { toPlane } from 'core/viewport/parallax';\nimport { meanScale } from 'core/viewport/meanScale';\nimport type { View } from 'core/viewport/view';\nimport type { LayerEnumerableAdapter } from 'core/adapters/types';\nimport type { Node } from 'core/scene/types';\nimport type { MoveAdapter } from 'core/adapters/types';\nimport type { AreaSelectAdapter } from 'core/adapters/types';\nimport type { NodeId } from 'core/scene/types';\nimport { defineTool } from '../../overlayBinding';\nimport type { Action } from '@weasel-js/routing';\nimport { ActionDisabledReason } from '@weasel-js/routing';\nimport type { Tool } from '../../overlayBinding';\nimport { pickTopMostHit } from '../pickTopMostHit';\nimport { onEmptyCanvas } from './selectionContributions';\nimport { hitPredicate } from '@weasel-js/gestures';\nimport { poseDescriptorForNode, type PoseDescriptor } from 'core/geometry/poseDescriptor';\nimport { AUTO_POSE_DESCRIPTOR } from 'interactions/actions/resize/autoPoseDescriptor';\nimport { MULTI_RESIZE_TARGET_ID, type Bounds } from '../shared/selectionTarget';\nexport type { Bounds };\nexport { MULTI_RESIZE_TARGET_ID };\n\n/** Options for `useSelectTool`: how a point resolves to nodes, how a click\n * chooses among them, and the appearance of the marquee. */\nexport interface UseSelectToolOptions<TPose> {\n /** Return ids of all objects whose painted body covers (worldX, worldY).\n * Order doesn't matter — the tool collapses parent/child overlap via\n * `pickTopMostHit`. When omitted, defaults to an AABB-vs-point scan over\n * `adapter.getNodes()` using the pose descriptor. Override for tighter\n * shapes (path / polygon hit-tests). */\n pickEvery?: (worldX: number, worldY: number) => string[];\n /** Optional alt-aware selection-update hit returning the single id the\n * click should act on. */\n pickBest?: (\n worldX: number,\n worldY: number,\n alt: boolean,\n selection: readonly string[],\n ) => string | null;\n /** How to read poses for the default `pickEvery`. Default\n * `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<TPose>;\n /**\n * How the default `pickEvery` decides a **leaf** node covers the pointer.\n * Ignored when `pickEvery` is supplied.\n *\n * - `'aabb'` (default) — the pose rect. Cheap, and the historical behavior:\n * a click anywhere in the bounding box selects the node.\n * - `'silhouette'` — the pose rect as a pre-test, then the ink the painter\n * lays down: `findShapeSilhouette` filled or not per the painter's `ink`,\n * plus its outline widened by the stroke half-width and `pickTolerance`.\n * A click inside the bounding box but outside the drawn shape misses —\n * the concave notch of a star, the corner outside an ellipse, the blank\n * half of a text box — while a click on the thin outline of an unfilled\n * shape hits.\n *\n * Container nodes already consult their silhouette unconditionally (it is\n * how their clip is derived); this extends the same test to leaves. Not the\n * default because it changes what a click selects for every existing\n * consumer, and a painter with no `silhouette` is unaffected either way —\n * it falls back to the AABB.\n */\n leafPicking?: 'aabb' | 'silhouette';\n /**\n * Grab slop around a shape's outline, in **world** units. Default 0.\n *\n * Only consulted under `leafPicking: 'silhouette'`. World units because\n * this hook has no view; `<SceneCanvas>` takes a screen-pixel figure\n * (`geometry.pickTolerancePx`) and divides by scale on its own pick path.\n * Without some slop a hairline outline is an unhittable target.\n */\n pickTolerance?: number;\n /** Painted alpha per node in the view this tool picks for. A node painted\n * at alpha 0 is not under the pointer. Ignored when `pickEvery` is\n * supplied. */\n alphaOf?: (id: string) => number;\n /** Whether a node's `layer` reaches the screen in the view this tool picks\n * for. Ignored when `pickEvery` is supplied. */\n layerIsPainted?: (layer: string) => boolean;\n /** The camera of the view this tool picks for. With it, a node on an\n * adapter layer carrying `parallax` (`getLayers`) is picked where that\n * camera's plane paints it; without it, every layer is taken to move with\n * the camera. Ignored when `pickEvery` is supplied. */\n getView?: () => View | null;\n /**\n * When this returns true, a Shift/Meta extend-click must NOT change the\n * node selection.\n *\n * `<SceneCanvas>` wires it to \"a path is in anchor-edit mode\", where\n * Shift-click means \"add this anchor to the anchor selection\". Without\n * the lock the same click also toggles the edited node out of the node\n * selection, and the `editAnchors` dep treats that as the edit target\n * disappearing — so multi-selecting anchors silently exited edit mode.\n *\n * Only extend-clicks are locked. A plain click still re-selects, so\n * clicking a different node exits edit mode as usual.\n */\n extendClickLocked?: () => boolean;\n}\n\n/** Intersection of the move + area-select adapter interfaces.\n * Resize and rotate run through `resizeAction` / `rotateAction`. */\nexport type SelectAdapter<TNode extends { id: string }, TPose> =\n MoveAdapter<TNode, TPose>\n & AreaSelectAdapter\n & LayerEnumerableAdapter;\n\n/**\n * What the press classified, carried from `select.pick` (pointerDown) to\n * `select.collapseDeferred` (click) and to the tool's cursor.\n *\n * This is tool-local bookkeeping between two dispatches of the same gesture,\n * so it lives in a ref the tool owns rather than in dispatcher state. It used\n * to be the tool's `SelectScratch`, held by the tool-routing dispatcher, and\n * carried an `ids` list that nothing ever read — `moveAction` computes its own\n * ids from the live selection.\n *\n * @internal\n */\ninterface PressClassification {\n /**\n * Set when the press hit an already-selected node inside a multi-selection\n * with no extend modifier.\n *\n * The selection is deliberately NOT collapsed on the press: the user may be\n * starting a drag of the whole set. If the gesture turns out to be a click,\n * `select.collapseDeferred` collapses to this id on release.\n */\n deferredClickId: string | null;\n}\n\n\n/** A press that landed on the scene rather than on chrome over it. */\nconst offChrome = hitPredicate((hit) => hit == null);\n\n/** Active-slot Tool:\n * - `select.pick` classifies the press (pointerDown) — it runs the tool's own\n * pickBest/pickEvery so click semantics (selection replace, extend,\n * deferred collapse) live in one place.\n * - an empty drag marquees (`areaSelect`) and a click on empty clears the\n * selection (`clearSelection`); the marquee renders via the dispatcher\n * overlay layer, driven by areaSelectAction's `overlay()`.\n * - moving and transforming the selection are not the tool's: they are the\n * ambient bindings in `selectionContributions.ts`.\n */\nexport function useSelectTool<TNode extends { id: string }, TPose>(\n adapter: SelectAdapter<TNode, TPose>,\n options: UseSelectToolOptions<TPose>,\n): Tool<null> {\n\n // pickEvery / boundsOf defaults — for any adapter the kit can derive both\n // from `adapter.getNodes()` + `adapter.getPose(id)` + the descriptor.\n const d = (options.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const preciseLeaves = options.leafPicking === 'silhouette';\n // World units here, not screen: this hook has no view. `<SceneCanvas>`\n // converts from screen px on its own pick path; a bare `useSelectTool`\n // consumer that zooms should pass `pickTolerance` from its own scale.\n const tolerance = options.pickTolerance ?? 0;\n const pickEveryFn = options.pickEvery ?? ((worldX: number, worldY: number): string[] => {\n /** A point query at (px, py) with `t` world units of slop. AABB first\n * (cheap), then the painter's ink when asked for and available. A painter\n * with no `silhouette` — or one that returns null, as `kit:text` does for\n * an empty node — keeps the AABB answer.\n *\n * The AABB pre-filter is grown by the slop for the same reason\n * `<SceneCanvas>`'s is: a shape's outline, and the slop around it, reach\n * outside the shape's own bounds, and an un-grown pre-filter would\n * discard those hits before the refinement could claim them. */\n const pointQuery = (px: number, py: number, t: number): PickQuery<TPose> => {\n const covers = (node: unknown, pose: TPose, b: Bounds): boolean => {\n const slop = preciseLeaves ? t : 0;\n if (!(px >= b.x - slop && px <= b.x + b.width + slop\n && py >= b.y - slop && py <= b.y + b.height + slop)) {\n return false;\n }\n if (!preciseLeaves) return true;\n return shapeCoversPoint(\n node as Node<unknown, string, TPose>, pose, px, py, { tolerance: t },\n );\n };\n return {\n hits: (node, pose) => {\n const b = poseDescriptorForNode(d, node).getBounds(pose);\n if (node.kind !== 'container') return covers(node, pose, b);\n // A container's own clip *is* its hit shape — it is picked where it\n // paints, and it paints only inside its clip. Ancestor clips are the\n // walk's business; this one is not.\n const inAabb = px >= b.x && px <= b.x + b.width\n && py >= b.y && py <= b.y + b.height;\n if (!inAabb) return false;\n const own = ownClipOf(node, pose);\n return own === null || pathContainsPoint(own, px, py);\n },\n clipAdmits: (clip) => pathContainsPoint(clip, px, py),\n inPlane: (m) => {\n const p = toPlane(m, { x: px, y: py });\n return pointQuery(p.x, p.y, t * meanScale(m.scale));\n },\n };\n };\n\n const camera = options.getView?.() ?? null;\n const planeOf = camera ? scenePlaneOf(adapter.getLayers?.(), camera) : null;\n return pickWalk<TPose>(adapterPickSource(adapter as never, {\n ...(options.alphaOf ? { alphaOf: options.alphaOf } : {}),\n ...(options.layerIsPainted ? { layerIsPainted: options.layerIsPainted } : {}),\n ...(planeOf ? { planeOf } : {}),\n }), pointQuery(worldX, worldY, tolerance));\n });\n\n const pickEveryRef = useLatest(pickEveryFn);\n\n // What the last press classified. Written by `select.pick`, read by\n // `select.collapseDeferred` and the cursor. See `PressClassification`.\n const pressRef = useRef<PressClassification>({ deferredClickId: null });\n\n // Options in a ref so the actions — built once — always see the live\n // callbacks without rebuilding the Tool record.\n const optionsRef = useLatest(options);\n const adapterRef = useLatest(adapter);\n\n /**\n * `select.pick` — classifies the press and updates the node selection.\n *\n * Bound to `pointerDown` rather than `click` on purpose: pressing an\n * unselected node must highlight it while the button is still down, and any\n * drag that follows has to start from the updated selection (both\n * `moveAction` and `cloneAction` read `selection.get()` in their `start`).\n *\n * Eligibility replaces the `selectionAllowed` option the audit added as an\n * interim per-route patch: this action carries the same\n * `creates-selection` capability rule the `clearSelection` binding declares,\n * so a mode that forbids selection now gates both halves of the tool by one\n * mechanism instead of by which dispatcher the route happened to live on.\n */\n const pickAction = useMemo<Action>(() => ({\n id: 'select.pick',\n label: 'Select — pick under pointer',\n eligible: { capability: 'creates-selection' },\n requires: ['selection'],\n invoker: {\n timing: 'immediate' as const,\n run: (deps, params) => {\n const p = params as {\n worldX?: number; worldY?: number;\n affordance?: unknown;\n mods?: { alt: boolean; ctrl: boolean; meta: boolean; shift: boolean };\n } | undefined;\n const selection = deps.selection;\n if (!selection || p?.worldX === undefined || p.worldY === undefined) return;\n const mods = p.mods ?? { alt: false, ctrl: false, meta: false, shift: false };\n const opts = optionsRef.current;\n\n const sel = selection.get();\n const top = opts.pickBest\n ? opts.pickBest(p.worldX, p.worldY, mods.alt, sel)\n : (() => {\n const ids = pickEveryRef.current(p.worldX, p.worldY);\n if (ids.length === 0) return null;\n return pickTopMostHit(ids, adapterRef.current) ?? ids[0];\n })();\n\n if (top === null) {\n pressRef.current = { deferredClickId: null };\n return;\n }\n\n const hitAlreadySelected = sel.includes(top as NodeId);\n const isExtend = mods.shift || mods.meta;\n // While a path is in anchor-edit mode, an extend-click belongs to the\n // anchor selection, not the node selection. Letting it through would\n // toggle the edited node out of the node selection, which the\n // `editAnchors` dep reads as \"the edit target is gone\" — so\n // shift-clicking a second anchor silently tore down edit mode.\n // Plain clicks still fall through: clicking a different node exits\n // edit mode, which is what you'd expect.\n //\n // This stays an option rather than becoming `Action.enabled` because\n // it only applies to *extend* presses, and `enabled` is evaluated\n // without the event's modifiers.\n const extendLocked = isExtend && opts.extendClickLocked?.() === true;\n const deferClick = hitAlreadySelected && sel.length > 1 && !isExtend;\n if (!deferClick && !extendLocked) {\n selection.applyClick(top as NodeId, mods);\n }\n pressRef.current = { deferredClickId: deferClick ? top : null };\n },\n },\n }), [optionsRef, pickEveryRef, adapterRef]);\n\n /**\n * `select.collapseDeferred` — the release half of the deferred multi-click.\n *\n * Pressing an already-selected node inside a multi-selection leaves the\n * selection alone so the press can start a drag of the whole set. If the\n * gesture ends without a drag, this collapses to the clicked node.\n */\n const collapseDeferredAction = useMemo<Action>(() => ({\n id: 'select.collapseDeferred',\n label: 'Select — collapse deferred click',\n eligible: { capability: 'creates-selection' },\n requires: ['selection'],\n // Declining when there is nothing deferred is what keeps this binding\n // from swallowing every click. It is bound with no target (any click can\n // in principle be the release of a deferred press) at ACTIVE scope, so\n // without the gate it would outrank ambient click bindings like\n // `selectAnchor` and silently break anchor selection. Same fall-through\n // contract `clearSelection.enabled` relies on.\n enabled: () =>\n pressRef.current.deferredClickId !== null\n ? true\n : ActionDisabledReason.NotApplicable,\n invoker: {\n timing: 'immediate' as const,\n run: (deps, params) => {\n const deferred = pressRef.current.deferredClickId;\n pressRef.current = { deferredClickId: null };\n if (deferred === null) return;\n const selection = deps.selection;\n if (!selection) return;\n const p = params as {\n mods?: { alt: boolean; ctrl: boolean; meta: boolean; shift: boolean };\n } | undefined;\n selection.applyClick(\n deferred as NodeId,\n p?.mods ?? { alt: false, ctrl: false, meta: false, shift: false },\n );\n },\n },\n }), []);\n\n return useMemo(\n () => {\n const base = defineTool<null>({\n id: 'select',\n keybinding: { key: 'V' },\n capabilities: ['creates-selection'],\n hookName: 'useSelectTool',\n // A plain string: the mid-gesture cursors this used to compute from\n // gesture scratch now live on the actions that own those gestures\n // (`moveAction.activeCursor`, `areaSelectAction.activeCursor`), so\n // they apply to any consumer binding them, not just this tool.\n cursor: 'default',\n presentation: {\n label: 'Select',\n icon: createElement(SelectIcon),\n group: 'select',\n },\n actions: [pickAction, collapseDeferredAction],\n });\n\n return {\n ...base,\n // Declarative bindings for the gesture dispatcher. The select tool\n // only chooses: press → classify + select, release → collapse a\n // deferred multi-click, empty drag → marquee, click on empty → clear.\n // Moving, cloning, resizing and rotating the selection are ambient\n // bindings owned by the selection (`selectionContributions.ts`), so\n // they run under any tool that leaves the gesture unclaimed.\n bindings: [\n // Every press that landed on the scene rather than on chrome. This\n // is the former `initial.pointerDown['*']` route: it classifies the\n // press and applies the selection change, and it does not consume\n // the gesture — the same press goes on to open a drag or synthesize\n // a click.\n //\n // The no-affordance target is load-bearing twice over. A press on a\n // resize handle, a rotate ring, a path anchor, or a registered\n // layer's own chrome is not a body pick, and re-picking underneath\n // it would change the selection the user was about to act on. And\n // because it is expressed in the SPEC rather than as an early\n // return in the action, the press falls through to whatever owns\n // that chrome instead of being consumed here — which is how an\n // ambient binding (`@weasel-js/hud`) gets to see it at all. The old\n // pipeline got both properties by construction: affordance hits\n // bypassed the active tool entirely.\n //\n // Modifiers are all `'optional'` because they are *data* here\n // (forwarded to `SelectionApi.applyClick`, which resolves them\n // against the host's configured extend key) rather than a route.\n {\n spec: {\n kind: 'pointerDown' as const,\n target: { kindOf: offChrome },\n mods: { shift: 'optional' as const, alt: 'optional' as const, meta: 'optional' as const, ctrl: 'optional' as const },\n },\n actionId: 'select.pick',\n },\n // Release half of the deferred multi-click. Same `'optional'`\n // modifiers, same reason.\n {\n spec: {\n kind: 'click' as const,\n target: { kindOf: offChrome },\n mods: { shift: 'optional' as const, alt: 'optional' as const, meta: 'optional' as const, ctrl: 'optional' as const },\n },\n actionId: 'select.collapseDeferred',\n },\n // Empty drag → marquee. `onEmptyCanvas` rather than a bare `'empty'`\n // target: the ambient bindings that own the handles rank below this\n // active one, so `'empty'` took drags that start on them.\n {\n spec: { kind: 'drag' as const, target: { kindOf: onEmptyCanvas } },\n actionId: 'areaSelect',\n },\n // resize/rotate bind only drag (no click), so a click on either handle\n // (body genuinely empty) would hit target:'empty' and wrongly clear selection.\n {\n spec: {\n kind: 'click' as const,\n target: { kindOf: onEmptyCanvas },\n mods: {},\n },\n actionId: 'clearSelection',\n },\n ],\n };\n },\n [pickAction, collapseDeferredAction],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0IA,IAAMC,IAAYC,GAAc,MAAQC,KAAO,IAAI;AAYnD,SAAgBC,EACd,GACA,GACY;CAIZ,IAAMC,IAAKC,EAAQ,kBAAkBC,GAC/BC,IAAgBF,EAAQ,gBAAgB,cAIxCG,IAAYH,EAAQ,iBAAiB,GACrCI,IAAcJ,EAAQ,eAAe,GAAgB,MAA6B;EAUtF,IAAMK,KAAc,GAAY,GAAY,MAAgC;GAC1E,IAAMC,KAAU,GAAe,GAAa,MAAuB;IACjE,IAAMC,IAAOL,IAAgBM,IAAI;IAMjC,OALMC,KAAMC,EAAE,IAAIH,KAAQE,KAAMC,EAAE,IAAIA,EAAE,QAAQH,KACvCI,KAAMD,EAAE,IAAIH,KAAQI,KAAMD,EAAE,IAAIA,EAAE,SAASH,IAGpD,CAAKL,KACEU,EACLC,GAAsCC,GAAML,GAAIE,GAAI,EAAE,WAAWH,EAAE,CACrE,IALS;GAMX;GACA,OAAO;IACL,OAAO,GAAM,MAAS;KACpB,IAAME,IAAIK,EAAsBhB,GAAGc,CAAI,CAAC,CAAC,UAAUC,CAAI;KACvD,IAAID,EAAK,SAAS,aA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B,IAAMrB,IAAIoB;IAGV,EAAU,WACRe,GACAnC,GAAG,QAAQ;KAAE,KAAK;KAAO,MAAM;KAAO,MAAM;KAAO,OAAO;IAAM,CAClE;GACF;EACF;CACF,IAAI,CAAC,CAAC;CAEN,OAAOmB,SAoBI;EACL,GAnBWiB,EAAiB;GAC5B,IAAI;GACJ,YAAY,EAAE,KAAK,IAAI;GACvB,cAAc,CAAC,mBAAmB;GAClC,UAAU;GAKV,QAAQ;GACR,cAAc;IACZ,OAAO;IACP,MAAMC,EAAc/D,CAAU;IAC9B,OAAO;GACT;GACA,SAAS,CAAC4C,GAAYe,CAAsB;EAC9C,CAGK;EAOH,UAAU;GAqBR;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,QAAQ1D,EAAU;KAC5B,MAAM;MAAE,OAAO;MAAqB,KAAK;MAAqB,MAAM;MAAqB,MAAM;KAAoB;IACrH;IACA,UAAU;GACZ;GAGA;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,QAAQA,EAAU;KAC5B,MAAM;MAAE,OAAO;MAAqB,KAAK;MAAqB,MAAM;MAAqB,MAAM;KAAoB;IACrH;IACA,UAAU;GACZ;GAIA;IACE,MAAM;KAAE,MAAM;KAAiB,QAAQ,EAAE,QAAQ+D,EAAc;IAAE;IACjE,UAAU;GACZ;GAGA;IACE,MAAM;KACJ,MAAM;KACN,QAAQ,EAAE,QAAQA,EAAc;KAChC,MAAM,CAAC;IACT;IACA,UAAU;GACZ;EACF;CACF,IAEF,CAACpB,GAAYe,CAAsB,CACrC;AACF"}
@@ -0,0 +1,17 @@
1
+ //#region src/tools/builtin/shared/pointerFollower.ts
2
+ function e(e) {
3
+ let t = null, n = null;
4
+ return {
5
+ pointer: () => t,
6
+ follow(r) {
7
+ r && r !== t && (n?.(), t = r, n = r.subscribe(e));
8
+ },
9
+ unfollow() {
10
+ n?.(), n = null, t = null;
11
+ }
12
+ };
13
+ }
14
+ //#endregion
15
+ export { e as createPointerFollower };
16
+
17
+ //# sourceMappingURL=pointerFollower.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pointerFollower.js","names":["createPointerFollower","pointer","off","next","onMove"],"sources":["../../../../src/tools/builtin/shared/pointerFollower.ts"],"sourcesContent":["import type { PointerContextValue } from 'features/pointer/PointerContext';\n\n/** A tool's subscription to the `pointer` dep, held only while it has\n * something trailing to the pointer. */\nexport interface PointerFollower {\n /** The store being followed, or `null`. */\n pointer(): PointerContextValue | null;\n /** Start following `next`; a no-op for the store already followed. */\n follow(next: PointerContextValue | undefined): void;\n unfollow(): void;\n}\n\n/** `onMove` runs after every change of the followed pointer. */\nexport function createPointerFollower(onMove: () => void): PointerFollower {\n let pointer: PointerContextValue | null = null;\n let off: (() => void) | null = null;\n return {\n pointer: () => pointer,\n follow(next) {\n if (!next || next === pointer) return;\n off?.();\n pointer = next;\n off = next.subscribe(onMove);\n },\n unfollow() {\n off?.();\n off = null;\n pointer = null;\n },\n };\n}\n"],"mappings":";AAaA,SAAgBA,EAAsB,GAAqC;CACzE,IAAIC,IAAsC,MACtCC,IAA2B;CAC/B,OAAO;EACL,eAAeD;EACf,OAAO,GAAM;GACX,AAAKE,KAAQA,MAASF,MACtBC,IAAM,GACN,IAAUC,GACV,IAAMA,EAAK,UAAUC,CAAM;EAC7B;EACA,WAAW;GAGT,AAFAF,IAAM,GACN,IAAM,MACN,IAAU;EACZ;CACF;AACF"}
@@ -3,36 +3,31 @@ import { worldToScreen as t } from "../../../core/viewport/viewTransform.js";
3
3
  import { withinPxRadius as n } from "../../../core/viewport/pxExtent.js";
4
4
  import { sliceAction as r } from "../../../interactions/actions/defaults/slice.js";
5
5
  import { defineTool as i } from "../../overlayBinding.js";
6
- import { OVERLAY_ROLE_STROKES as a } from "../../../canvas/overlayRoleStrokes.js";
7
- import { ellipsePath as o, polylineFromPoints as s } from "@weasel-js/geom";
8
- import { useMemo as c, useRef as l } from "react";
9
- import { useLatest as u } from "@weasel-js/react";
10
- import { ActionDisabledReason as d } from "@weasel-js/routing";
6
+ import { createPointerFollower as a } from "../shared/pointerFollower.js";
7
+ import { OVERLAY_ROLE_STROKES as o } from "../../../canvas/overlayRoleStrokes.js";
8
+ import { ellipsePath as s, polylineFromPoints as c } from "@weasel-js/geom";
9
+ import { useMemo as l, useRef as u } from "react";
10
+ import { useLatest as d } from "@weasel-js/react";
11
+ import { ActionDisabledReason as f } from "@weasel-js/routing";
11
12
  //#region src/tools/builtin/slice/useSliceTool.ts
12
- var f = 3;
13
- function p(p = {}) {
14
- let m = l({ points: [] }), h = u({ closeHitRadius: p.closeHitRadius ?? 8 }), g = c(() => {
15
- let e = /* @__PURE__ */ new Set(), t = null, n = null, r = () => {
13
+ var p = 3;
14
+ function m(m = {}) {
15
+ let h = u({ points: [] }), g = d({ closeHitRadius: m.closeHitRadius ?? 8 }), _ = l(() => {
16
+ let e = /* @__PURE__ */ new Set(), t = () => {
16
17
  for (let t of [...e]) t();
17
18
  };
18
19
  return {
19
- notify: r,
20
+ notify: t,
20
21
  listen(t) {
21
22
  return e.add(t), () => {
22
23
  e.delete(t);
23
24
  };
24
25
  },
25
- pointer: () => t,
26
- follow(e) {
27
- e && e !== t && (n?.(), t = e, n = e.subscribe(r));
28
- },
29
- unfollow() {
30
- n?.(), n = null, t = null;
31
- }
26
+ ...a(t)
32
27
  };
33
- }, []), _ = c(() => {
34
- let e = () => m.current.points, t = () => e().length > 0 || d.NotApplicable, i = () => {
35
- m.current.points = [], g.unfollow(), g.notify();
28
+ }, []), v = l(() => {
29
+ let e = () => h.current.points, t = () => e().length > 0 || f.NotApplicable, i = () => {
30
+ h.current.points = [], _.unfollow(), _.notify();
36
31
  }, a = (t) => {
37
32
  let n = e().slice();
38
33
  i(), n.length >= 2 && t.slice?.commit(n);
@@ -41,7 +36,7 @@ function p(p = {}) {
41
36
  x: 1,
42
37
  y: 1
43
38
  };
44
- if (o.length >= 3 && n(r - s.x, i - s.y, h.current.closeHitRadius, c)) {
39
+ if (o.length >= 3 && n(r - s.x, i - s.y, g.current.closeHitRadius, c)) {
45
40
  o.push({
46
41
  x: s.x,
47
42
  y: s.y
@@ -51,7 +46,7 @@ function p(p = {}) {
51
46
  o.push({
52
47
  x: r,
53
48
  y: i
54
- }), g.follow(t.pointer), g.notify();
49
+ }), _.follow(t.pointer), _.notify();
55
50
  }, s = { capability: "edits-page" };
56
51
  return [
57
52
  r,
@@ -64,7 +59,7 @@ function p(p = {}) {
64
59
  "view",
65
60
  "pointer"
66
61
  ],
67
- enabled: (e) => e?.slice ? !0 : d.NotApplicable,
62
+ enabled: (e) => e?.slice ? !0 : f.NotApplicable,
68
63
  invoker: {
69
64
  timing: "immediate",
70
65
  run: (e, t) => {
@@ -85,12 +80,12 @@ function p(p = {}) {
85
80
  enabled: t,
86
81
  invoker: {
87
82
  timing: "ongoing",
88
- start: () => ({
83
+ start: ({ deps: t }) => ({
89
84
  onMove: () => {},
90
- onEnd: (t, n) => {
91
- if (n === "cancel" || e().length === 0) return;
92
- let r = t.drag?.current ?? t.world;
93
- o(t.deps, r.x, r.y);
85
+ onEnd: (n, r) => {
86
+ if (r === "cancel" || e().length === 0) return;
87
+ let i = n.drag?.current ?? n.world;
88
+ o(t, i.x, i.y);
94
89
  }
95
90
  })
96
91
  }
@@ -116,7 +111,7 @@ function p(p = {}) {
116
111
  invoker: {
117
112
  timing: "immediate",
118
113
  run: () => {
119
- e().pop(), e().length === 0 ? i() : g.notify();
114
+ e().pop(), e().length === 0 ? i() : _.notify();
120
115
  }
121
116
  }
122
117
  },
@@ -131,45 +126,45 @@ function p(p = {}) {
131
126
  }
132
127
  }
133
128
  ];
134
- }, [g, h]), v = c(() => ({
129
+ }, [_, g]), y = l(() => ({
135
130
  id: "slice-pending-cut",
136
131
  label: "Slice — pending cut",
137
132
  space: "screen",
138
- subscribe: g.listen,
133
+ subscribe: _.listen,
139
134
  draw: (n, r) => {
140
- let i = m.current.points;
135
+ let i = h.current.points;
141
136
  if (i.length === 0) return [];
142
- let c = e(r), l = (e) => {
143
- let [n, r] = t(e.x, e.y, c);
137
+ let a = e(r), l = (e) => {
138
+ let [n, r] = t(e.x, e.y, a);
144
139
  return {
145
140
  x: n,
146
141
  y: r
147
142
  };
148
- }, u = i.map(l), d = g.pointer()?.get();
143
+ }, u = i.map(l), d = _.pointer()?.get();
149
144
  d && u.push(l({
150
145
  x: d.worldX,
151
146
  y: d.worldY
152
147
  }));
153
- let p = a.cut, h = [];
154
- u.length >= 2 && h.push({
148
+ let f = o.cut, m = [];
149
+ u.length >= 2 && m.push({
155
150
  kind: "path",
156
- path: s(u),
157
- stroke: p
151
+ path: c(u),
152
+ stroke: f
158
153
  });
159
- for (let e of i.map(l)) h.push({
154
+ for (let e of i.map(l)) m.push({
160
155
  kind: "path",
161
- path: o({
162
- x: e.x - f,
163
- y: e.y - f,
156
+ path: s({
157
+ x: e.x - p,
158
+ y: e.y - p,
164
159
  width: 6,
165
160
  height: 6
166
161
  }),
167
- fill: p.paint
162
+ fill: f.paint
168
163
  });
169
- return h;
164
+ return m;
170
165
  }
171
- }), [g]), { keybinding: y } = p;
172
- return c(() => i({
166
+ }), [_]), { keybinding: b } = m;
167
+ return l(() => i({
173
168
  id: "slice",
174
169
  capabilities: ["edits-page"],
175
170
  hookName: "useSliceTool",
@@ -178,11 +173,11 @@ function p(p = {}) {
178
173
  label: "Slice",
179
174
  group: "shape"
180
175
  },
181
- ...y === null ? {} : { keybinding: y ?? { key: "K" } },
182
- actions: _,
183
- overlay: v,
176
+ ...b === null ? {} : { keybinding: b ?? { key: "K" } },
177
+ actions: v,
178
+ overlay: y,
184
179
  onDeactivate: () => {
185
- m.current.points = [], g.unfollow(), g.notify();
180
+ h.current.points = [], _.unfollow(), _.notify();
186
181
  },
187
182
  bindings: [
188
183
  {
@@ -251,13 +246,13 @@ function p(p = {}) {
251
246
  }
252
247
  ]
253
248
  }), [
254
- _,
255
249
  v,
256
250
  y,
257
- g
251
+ b,
252
+ _
258
253
  ]);
259
254
  }
260
255
  //#endregion
261
- export { p as useSliceTool };
256
+ export { m as useSliceTool };
262
257
 
263
258
  //# sourceMappingURL=useSliceTool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSliceTool.js","names":["VERTEX_RADIUS_PX","useSliceTool","scratchRef","useRef","optsRef","useLatest","options","live","useMemo","listeners","pointer","offPointer","notify","fn","next","actions","points","pending","ActionDisabledReason","reset","commit","cut","deps","place","pts","first","scale","withinPxRadius","x","y","eligible","sliceAction","\"slice\"","p","params","reason","at","endCtx","overlay","t","viewToTransform","view","toScreen","worldToScreen","run","stroke","OVERLAY_ROLE_STROKES","\"cut\"","out","polylineFromPoints","ellipsePath","defineTool","keybinding"],"sources":["../../../../src/tools/builtin/slice/useSliceTool.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { defineTool } from '../../overlayBinding';\nimport type { Tool } from '../../overlayBinding';\nimport type { RenderLayer } from 'core/layers/render';\nimport type { DrawCommand } from '../../../renderer';\nimport type { Action, ActionDeps, InvocationCtx, ToolKeybinding } from '@weasel-js/routing';\nimport { ActionDisabledReason } from '@weasel-js/routing';\nimport type { PointerContextValue } from 'features/pointer/PointerContext';\nimport { sliceAction } from 'interactions/actions/defaults/slice';\nimport { withinPxRadius } from 'core/viewport/pxExtent';\nimport { worldToScreen } from 'core/viewport/viewTransform';\nimport { viewToTransform } from 'core/viewport/view';\nimport { ellipsePath, polylineFromPoints } from '@weasel-js/geom';\nimport { OVERLAY_ROLE_STROKES } from 'canvas/overlayRoleStrokes';\n\n/** Options for `useSliceTool`. */\nexport interface UseSliceToolOptions {\n /** Override the default keybinding (`{ key: 'K' }`). Pass `null` to omit. */\n keybinding?: ToolKeybinding | null;\n /** Screen-px radius around the first point within which a click closes the\n * cut into a loop and commits it. Default `8`. */\n closeHitRadius?: number;\n}\n\n/** The click-by-click cut in progress, in world coords. */\nexport interface SliceScratch {\n points: { x: number; y: number }[];\n}\n\nconst VERTEX_RADIUS_PX = 3;\n\n/**\n * Knife tool. A drag cuts along a straight line, and an Alt-drag along its\n * freehand trail, through `sliceAction`. Clicks place a cut one point at a\n * time: Enter or a double-click commits it, Escape discards it, Backspace\n * takes back the last point, and a click on the first point closes it into a\n * loop and commits. While points are placed, a drag places one more where it\n * is released instead of cutting on its own.\n *\n * Every cut goes to the `slice` dep, which decides what it does to the scene.\n * `<SceneCanvas>` publishes one that cuts every path the cut crosses. The pending cut paints through\n * `Tool.overlay`, trailing to the pointer when the host publishes one.\n */\nexport function useSliceTool(options: UseSliceToolOptions = {}): Tool<null> {\n const scratchRef = useRef<SliceScratch>({ points: [] });\n const optsRef = useLatest({ closeHitRadius: options.closeHitRadius ?? 8 });\n\n // What the overlay layer's `subscribe` hears: a change to the points, and,\n // while any are placed, every move of the pointer the rubber band follows.\n const live = useMemo(() => {\n const listeners = new Set<() => void>();\n let pointer: PointerContextValue | null = null;\n let offPointer: (() => void) | null = null;\n const notify = (): void => { for (const fn of [...listeners]) fn(); };\n return {\n notify,\n listen(fn: () => void): () => void {\n listeners.add(fn);\n return () => { listeners.delete(fn); };\n },\n pointer: () => pointer,\n follow(next: PointerContextValue | undefined): void {\n if (!next || next === pointer) return;\n offPointer?.();\n pointer = next;\n offPointer = next.subscribe(notify);\n },\n unfollow(): void {\n offPointer?.();\n offPointer = null;\n pointer = null;\n },\n };\n }, []);\n\n const actions = useMemo<Action[]>(() => {\n const points = () => scratchRef.current.points;\n const pending = () => (points().length > 0 ? true : ActionDisabledReason.NotApplicable);\n\n const reset = (): void => {\n scratchRef.current.points = [];\n live.unfollow();\n live.notify();\n };\n const commit = (deps: ActionDeps): void => {\n const cut = points().slice();\n reset();\n if (cut.length >= 2) deps.slice?.commit(cut);\n };\n const place = (deps: ActionDeps, x: number, y: number): void => {\n const pts = points();\n const first = pts[0];\n const scale = deps.view?.get().scale ?? { x: 1, y: 1 };\n if (pts.length >= 3 && withinPxRadius(x - first.x, y - first.y, optsRef.current.closeHitRadius, scale)) {\n pts.push({ x: first.x, y: first.y });\n commit(deps);\n return;\n }\n pts.push({ x, y });\n live.follow(deps.pointer);\n live.notify();\n };\n\n const eligible = { capability: 'edits-page' } as const;\n return [\n sliceAction,\n {\n id: 'slice.addPoint',\n label: 'Slice — place point',\n eligible,\n requires: ['slice', 'view', 'pointer'],\n enabled: (deps) => (deps?.['slice'] ? true : ActionDisabledReason.NotApplicable),\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const p = params as { pressX?: number; pressY?: number } | undefined;\n if (p?.pressX === undefined || p.pressY === undefined) return;\n place(deps, p.pressX, p.pressY);\n },\n },\n },\n {\n id: 'slice.dragPoint',\n label: 'Slice — drag out a point',\n eligible,\n requires: ['slice', 'view', 'pointer'],\n enabled: pending,\n invoker: {\n timing: 'ongoing',\n start: () => ({\n onMove: () => {},\n onEnd: (endCtx: InvocationCtx, reason: 'commit' | 'cancel') => {\n if (reason === 'cancel' || points().length === 0) return;\n const at = endCtx.drag?.current ?? endCtx.world;\n place(endCtx.deps, at.x, at.y);\n },\n }),\n },\n },\n {\n id: 'slice.finish',\n label: 'Slice — cut along the points',\n eligible,\n requires: ['slice'],\n enabled: pending,\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n // A double click arrives after both of its clicks, so the second\n // has already placed a point on top of the first.\n if ((params as { viaDoubleClick?: boolean } | undefined)?.viaDoubleClick) points().pop();\n commit(deps);\n },\n },\n },\n {\n id: 'slice.dropPoint',\n label: 'Slice — take back the last point',\n eligible,\n enabled: pending,\n invoker: {\n timing: 'immediate',\n run: () => {\n points().pop();\n if (points().length === 0) reset();\n else live.notify();\n },\n },\n },\n {\n id: 'slice.cancel',\n label: 'Slice — discard the points',\n eligible,\n // Declining with nothing placed leaves Escape to the ambient `escape`.\n enabled: pending,\n invoker: { timing: 'immediate', run: () => reset() },\n },\n ];\n }, [live, optsRef]);\n\n const overlay = useMemo<RenderLayer<unknown>>(() => ({\n id: 'slice-pending-cut',\n label: 'Slice — pending cut',\n space: 'screen',\n subscribe: live.listen,\n draw: (_data, view) => {\n const pts = scratchRef.current.points;\n if (pts.length === 0) return [];\n const t = viewToTransform(view);\n const toScreen = (p: { x: number; y: number }) => {\n const [x, y] = worldToScreen(p.x, p.y, t);\n return { x, y };\n };\n const run = pts.map(toScreen);\n const at = live.pointer()?.get();\n if (at) run.push(toScreen({ x: at.worldX, y: at.worldY }));\n const stroke = OVERLAY_ROLE_STROKES['cut'];\n const out: DrawCommand[] = [];\n if (run.length >= 2) out.push({ kind: 'path', path: polylineFromPoints(run), stroke });\n for (const p of pts.map(toScreen)) {\n out.push({\n kind: 'path',\n path: ellipsePath({\n x: p.x - VERTEX_RADIUS_PX,\n y: p.y - VERTEX_RADIUS_PX,\n width: VERTEX_RADIUS_PX * 2,\n height: VERTEX_RADIUS_PX * 2,\n }),\n fill: stroke.paint,\n });\n }\n return out;\n },\n }), [live]);\n\n const { keybinding } = options;\n return useMemo(() => defineTool<null>({\n id: 'slice',\n capabilities: ['edits-page'],\n hookName: 'useSliceTool',\n cursor: 'crosshair',\n presentation: { label: 'Slice', group: 'shape' },\n ...(keybinding === null ? {} : { keybinding: keybinding ?? { key: 'K' } }),\n actions,\n overlay,\n onDeactivate: () => {\n scratchRef.current.points = [];\n live.unfollow();\n live.notify();\n },\n bindings: [\n { spec: { kind: 'click', mods: { shift: 'optional', alt: 'optional' } }, actionId: 'slice.addPoint' },\n {\n spec: { kind: 'doubleClick', mods: { shift: 'optional', alt: 'optional' } },\n actionId: 'slice.finish',\n opts: { params: { viaDoubleClick: true } },\n },\n // Ahead of the cutting drags: it declines unless points are placed.\n { spec: { kind: 'drag', mods: { shift: 'optional', alt: 'optional' } }, actionId: 'slice.dragPoint' },\n { spec: { kind: 'drag' }, actionId: 'slice' },\n { spec: { kind: 'drag', mods: { alt: true } }, actionId: 'slice', opts: { params: { cut: 'freehand' } } },\n { spec: { kind: 'key', key: 'Enter' }, actionId: 'slice.finish' },\n { spec: { kind: 'key', key: 'Escape' }, actionId: 'slice.cancel' },\n { spec: { kind: 'key', key: 'Backspace' },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+ {"version":3,"file":"useSliceTool.js","names":["VERTEX_RADIUS_PX","useSliceTool","scratchRef","useRef","optsRef","useLatest","options","live","useMemo","listeners","notify","fn","createPointerFollower","actions","points","pending","ActionDisabledReason","reset","commit","cut","deps","place","pts","first","scale","withinPxRadius","x","y","eligible","sliceAction","\"slice\"","p","params","reason","at","endCtx","overlay","t","viewToTransform","view","toScreen","worldToScreen","run","stroke","OVERLAY_ROLE_STROKES","\"cut\"","out","polylineFromPoints","ellipsePath","defineTool","keybinding"],"sources":["../../../../src/tools/builtin/slice/useSliceTool.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { defineTool } from '../../overlayBinding';\nimport type { Tool } from '../../overlayBinding';\nimport type { RenderLayer } from 'core/layers/render';\nimport type { DrawCommand } from '../../../renderer';\nimport type { Action, ActionDeps, InvocationCtx, ToolKeybinding } from '@weasel-js/routing';\nimport { ActionDisabledReason } from '@weasel-js/routing';\nimport { createPointerFollower } from '../shared/pointerFollower';\nimport { sliceAction } from 'interactions/actions/defaults/slice';\nimport { withinPxRadius } from 'core/viewport/pxExtent';\nimport { worldToScreen } from 'core/viewport/viewTransform';\nimport { viewToTransform } from 'core/viewport/view';\nimport { ellipsePath, polylineFromPoints } from '@weasel-js/geom';\nimport { OVERLAY_ROLE_STROKES } from 'canvas/overlayRoleStrokes';\n\n/** Options for `useSliceTool`. */\nexport interface UseSliceToolOptions {\n /** Override the default keybinding (`{ key: 'K' }`). Pass `null` to omit. */\n keybinding?: ToolKeybinding | null;\n /** Screen-px radius around the first point within which a click closes the\n * cut into a loop and commits it. Default `8`. */\n closeHitRadius?: number;\n}\n\n/** The click-by-click cut in progress, in world coords. */\nexport interface SliceScratch {\n points: { x: number; y: number }[];\n}\n\nconst VERTEX_RADIUS_PX = 3;\n\n/**\n * Knife tool. A drag cuts along a straight line, and an Alt-drag along its\n * freehand trail, through `sliceAction`. Clicks place a cut one point at a\n * time: Enter or a double-click commits it, Escape discards it, Backspace\n * takes back the last point, and a click on the first point closes it into a\n * loop and commits. While points are placed, a drag places one more where it\n * is released instead of cutting on its own.\n *\n * Every cut goes to the `slice` dep, which decides what it does to the scene.\n * `<SceneCanvas>` publishes one that cuts every path the cut crosses. The pending cut paints through\n * `Tool.overlay`, trailing to the pointer when the host publishes one.\n */\nexport function useSliceTool(options: UseSliceToolOptions = {}): Tool<null> {\n const scratchRef = useRef<SliceScratch>({ points: [] });\n const optsRef = useLatest({ closeHitRadius: options.closeHitRadius ?? 8 });\n\n // What the overlay layer's `subscribe` hears: a change to the points, and,\n // while any are placed, every move of the pointer the rubber band follows.\n const live = useMemo(() => {\n const listeners = new Set<() => void>();\n const notify = (): void => { for (const fn of [...listeners]) fn(); };\n return {\n notify,\n listen(fn: () => void): () => void {\n listeners.add(fn);\n return () => { listeners.delete(fn); };\n },\n ...createPointerFollower(notify),\n };\n }, []);\n\n const actions = useMemo<Action[]>(() => {\n const points = () => scratchRef.current.points;\n const pending = () => (points().length > 0 ? true : ActionDisabledReason.NotApplicable);\n\n const reset = (): void => {\n scratchRef.current.points = [];\n live.unfollow();\n live.notify();\n };\n const commit = (deps: ActionDeps): void => {\n const cut = points().slice();\n reset();\n if (cut.length >= 2) deps.slice?.commit(cut);\n };\n const place = (deps: ActionDeps, x: number, y: number): void => {\n const pts = points();\n const first = pts[0];\n const scale = deps.view?.get().scale ?? { x: 1, y: 1 };\n if (pts.length >= 3 && withinPxRadius(x - first.x, y - first.y, optsRef.current.closeHitRadius, scale)) {\n pts.push({ x: first.x, y: first.y });\n commit(deps);\n return;\n }\n pts.push({ x, y });\n live.follow(deps.pointer);\n live.notify();\n };\n\n const eligible = { capability: 'edits-page' } as const;\n return [\n sliceAction,\n {\n id: 'slice.addPoint',\n label: 'Slice — place point',\n eligible,\n requires: ['slice', 'view', 'pointer'],\n enabled: (deps) => (deps?.['slice'] ? true : ActionDisabledReason.NotApplicable),\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const p = params as { pressX?: number; pressY?: number } | undefined;\n if (p?.pressX === undefined || p.pressY === undefined) return;\n place(deps, p.pressX, p.pressY);\n },\n },\n },\n {\n id: 'slice.dragPoint',\n label: 'Slice — drag out a point',\n eligible,\n requires: ['slice', 'view', 'pointer'],\n enabled: pending,\n invoker: {\n timing: 'ongoing',\n // The dispatcher hands `onEnd` a context with empty deps.\n start: ({ deps }: InvocationCtx) => ({\n onMove: () => {},\n onEnd: (endCtx: InvocationCtx, reason: 'commit' | 'cancel') => {\n if (reason === 'cancel' || points().length === 0) return;\n const at = endCtx.drag?.current ?? endCtx.world;\n place(deps, at.x, at.y);\n },\n }),\n },\n },\n {\n id: 'slice.finish',\n label: 'Slice — cut along the points',\n eligible,\n requires: ['slice'],\n enabled: pending,\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n // A double click arrives after both of its clicks, so the second\n // has already placed a point on top of the first.\n if ((params as { viaDoubleClick?: boolean } | undefined)?.viaDoubleClick) points().pop();\n commit(deps);\n },\n },\n },\n {\n id: 'slice.dropPoint',\n label: 'Slice — take back the last point',\n eligible,\n enabled: pending,\n invoker: {\n timing: 'immediate',\n run: () => {\n points().pop();\n if (points().length === 0) reset();\n else live.notify();\n },\n },\n },\n {\n id: 'slice.cancel',\n label: 'Slice — discard the points',\n eligible,\n // Declining with nothing placed leaves Escape to the ambient `escape`.\n enabled: pending,\n invoker: { timing: 'immediate', run: () => reset() },\n },\n ];\n }, [live, optsRef]);\n\n const overlay = useMemo<RenderLayer<unknown>>(() => ({\n id: 'slice-pending-cut',\n label: 'Slice — pending cut',\n space: 'screen',\n subscribe: live.listen,\n draw: (_data, view) => {\n const pts = scratchRef.current.points;\n if (pts.length === 0) return [];\n const t = viewToTransform(view);\n const toScreen = (p: { x: number; y: number }) => {\n const [x, y] = worldToScreen(p.x, p.y, t);\n return { x, y };\n };\n const run = pts.map(toScreen);\n const at = live.pointer()?.get();\n if (at) run.push(toScreen({ x: at.worldX, y: at.worldY }));\n const stroke = OVERLAY_ROLE_STROKES['cut'];\n const out: DrawCommand[] = [];\n if (run.length >= 2) out.push({ kind: 'path', path: polylineFromPoints(run), stroke });\n for (const p of pts.map(toScreen)) {\n out.push({\n kind: 'path',\n path: ellipsePath({\n x: p.x - VERTEX_RADIUS_PX,\n y: p.y - VERTEX_RADIUS_PX,\n width: VERTEX_RADIUS_PX * 2,\n height: VERTEX_RADIUS_PX * 2,\n }),\n fill: stroke.paint,\n });\n }\n return out;\n },\n }), [live]);\n\n const { keybinding } = options;\n return useMemo(() => defineTool<null>({\n id: 'slice',\n capabilities: ['edits-page'],\n hookName: 'useSliceTool',\n cursor: 'crosshair',\n presentation: { label: 'Slice', group: 'shape' },\n ...(keybinding === null ? {} : { keybinding: keybinding ?? { key: 'K' } }),\n actions,\n overlay,\n onDeactivate: () => {\n scratchRef.current.points = [];\n live.unfollow();\n live.notify();\n },\n bindings: [\n { spec: { kind: 'click', mods: { shift: 'optional', alt: 'optional' } }, actionId: 'slice.addPoint' },\n {\n spec: { kind: 'doubleClick', mods: { shift: 'optional', alt: 'optional' } },\n actionId: 'slice.finish',\n opts: { params: { viaDoubleClick: true } },\n },\n // Ahead of the cutting drags: it declines unless points are placed.\n { spec: { kind: 'drag', mods: { shift: 'optional', alt: 'optional' } }, actionId: 'slice.dragPoint' },\n { spec: { kind: 'drag' }, actionId: 'slice' },\n { spec: { kind: 'drag', mods: { alt: true } }, actionId: 'slice', opts: { params: { cut: 'freehand' } } },\n { spec: { kind: 'key', key: 'Enter' }, actionId: 'slice.finish' },\n { spec: { kind: 'key', key: 'Escape' }, actionId: 'slice.cancel' },\n { spec: { kind: 'key', key: 'Backspace' }, actionId: 'slice.dropPoint' },\n ],\n }), [actions, overlay, keybinding, live]);\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,IAAMA,IAAmB;AAczB,SAAgBC,EAAa,IAA+B,CAAC,GAAe;CAC1E,IAAMC,IAAaC,EAAqB,EAAE,QAAQ,CAAC,EAAE,CAAC,GAChDC,IAAUC,EAAU,EA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