@weasel-js/core 1.10.0 → 1.10.1

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 (327) hide show
  1. package/CHANGELOG.md +168 -0
  2. package/README.md +33 -0
  3. package/dist/affordances/composeAffordanceLayer.js +21 -21
  4. package/dist/affordances/composeAffordanceLayer.js.map +1 -1
  5. package/dist/affordances/hitAffordanceRegions.js +48 -32
  6. package/dist/affordances/hitAffordanceRegions.js.map +1 -1
  7. package/dist/affordances/pathAnchors.js +50 -28
  8. package/dist/affordances/pathAnchors.js.map +1 -1
  9. package/dist/affordances/rotateCursor.js +12 -0
  10. package/dist/affordances/rotateCursor.js.map +1 -0
  11. package/dist/affordances/rotationHandle.js +40 -43
  12. package/dist/affordances/rotationHandle.js.map +1 -1
  13. package/dist/animation/rig/rigNode.js +9 -3
  14. package/dist/animation/rig/rigNode.js.map +1 -1
  15. package/dist/animation/rig/rigSeat.js +46 -13
  16. package/dist/animation/rig/rigSeat.js.map +1 -1
  17. package/dist/animation/rig/skinBinding.js +22 -14
  18. package/dist/animation/rig/skinBinding.js.map +1 -1
  19. package/dist/barrel/canvas.js +29 -28
  20. package/dist/barrel/interactions.js +33 -32
  21. package/dist/barrel/paths.js +11 -10
  22. package/dist/barrel/routing.js +49 -48
  23. package/dist/barrel/scene.js +10 -10
  24. package/dist/barrel/viewport.js +24 -21
  25. package/dist/canvas/Canvas.js +6 -17
  26. package/dist/canvas/Canvas.js.map +1 -1
  27. package/dist/canvas/CanvasView.js +34 -37
  28. package/dist/canvas/CanvasView.js.map +1 -1
  29. package/dist/canvas/CursorCoordsHud.js +3 -3
  30. package/dist/canvas/CursorCoordsHud.js.map +1 -1
  31. package/dist/canvas/DrawCanvas.js +3 -3
  32. package/dist/canvas/DrawCanvas.js.map +1 -1
  33. package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +24 -23
  34. package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js.map +1 -1
  35. package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js +40 -49
  36. package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js.map +1 -1
  37. package/dist/canvas/SceneCanvas/defaultNodeProperties.js +297 -259
  38. package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
  39. package/dist/canvas/SceneCanvas/features.js +3 -24
  40. package/dist/canvas/SceneCanvas/features.js.map +1 -1
  41. package/dist/canvas/SceneCanvas/insertPreviewCommands.js +97 -0
  42. package/dist/canvas/SceneCanvas/insertPreviewCommands.js.map +1 -0
  43. package/dist/canvas/SceneCanvas/poseGeometry.js.map +1 -1
  44. package/dist/canvas/SceneCanvas/props.js.map +1 -1
  45. package/dist/canvas/SceneCanvas/scenePointQuery.js +50 -0
  46. package/dist/canvas/SceneCanvas/scenePointQuery.js.map +1 -0
  47. package/dist/canvas/SceneCanvas/shapeGeneratorProperties.js +52 -0
  48. package/dist/canvas/SceneCanvas/shapeGeneratorProperties.js.map +1 -0
  49. package/dist/canvas/SceneCanvas/useActionTunings.js +17 -0
  50. package/dist/canvas/SceneCanvas/useActionTunings.js.map +1 -0
  51. package/dist/canvas/SceneCanvas/useCanvasCamera.js +37 -29
  52. package/dist/canvas/SceneCanvas/useCanvasCamera.js.map +1 -1
  53. package/dist/canvas/SceneCanvas/useCanvasDispatcher.js +11 -11
  54. package/dist/canvas/SceneCanvas/useCanvasDispatcher.js.map +1 -1
  55. package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js +45 -109
  56. package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js.map +1 -1
  57. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +49 -41
  58. package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
  59. package/dist/canvas/SceneCanvas/useSceneSelectTool.js +64 -96
  60. package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
  61. package/dist/canvas/SceneCanvas/worldPointAt.js +3 -4
  62. package/dist/canvas/SceneCanvas/worldPointAt.js.map +1 -1
  63. package/dist/canvas/SceneCanvas.js +77 -80
  64. package/dist/canvas/SceneCanvas.js.map +1 -1
  65. package/dist/canvas/SceneViewCanvas.js +3 -3
  66. package/dist/canvas/SceneViewCanvas.js.map +1 -1
  67. package/dist/canvas/SurfaceCanvas.js +40 -0
  68. package/dist/canvas/SurfaceCanvas.js.map +1 -0
  69. package/dist/canvas/adapterDerivedPath.js +13 -13
  70. package/dist/canvas/adapterDerivedPath.js.map +1 -1
  71. package/dist/canvas/adapterPickSource.js +34 -0
  72. package/dist/canvas/adapterPickSource.js.map +1 -0
  73. package/dist/canvas/affordanceAt.js +1 -1
  74. package/dist/canvas/affordanceAt.js.map +1 -1
  75. package/dist/canvas/buildSceneLayer.js.map +1 -1
  76. package/dist/canvas/buildSceneTree.js +56 -34
  77. package/dist/canvas/buildSceneTree.js.map +1 -1
  78. package/dist/canvas/copiesAbove.js +27 -0
  79. package/dist/canvas/copiesAbove.js.map +1 -0
  80. package/dist/canvas/defaultDrawOne.js +24 -23
  81. package/dist/canvas/defaultDrawOne.js.map +1 -1
  82. package/dist/canvas/deps/editAnchors.js +45 -50
  83. package/dist/canvas/deps/editAnchors.js.map +1 -1
  84. package/dist/canvas/deps/hitTestArea.js +30 -15
  85. package/dist/canvas/deps/hitTestArea.js.map +1 -1
  86. package/dist/canvas/deps/insert.js +134 -100
  87. package/dist/canvas/deps/insert.js.map +1 -1
  88. package/dist/canvas/deps/layout.js +9 -15
  89. package/dist/canvas/deps/layout.js.map +1 -1
  90. package/dist/canvas/derivedPath.js +53 -29
  91. package/dist/canvas/derivedPath.js.map +1 -1
  92. package/dist/canvas/insertPreviewExtent.js +33 -31
  93. package/dist/canvas/insertPreviewExtent.js.map +1 -1
  94. package/dist/canvas/overChildren.js +29 -0
  95. package/dist/canvas/overChildren.js.map +1 -0
  96. package/dist/canvas/paintedCursorLayer.js.map +1 -1
  97. package/dist/canvas/pickReach.js +23 -0
  98. package/dist/canvas/pickReach.js.map +1 -0
  99. package/dist/canvas/pickWalk.js +51 -80
  100. package/dist/canvas/pickWalk.js.map +1 -1
  101. package/dist/canvas/sceneAdapter.js +14 -35
  102. package/dist/canvas/sceneAdapter.js.map +1 -1
  103. package/dist/canvas/sceneSlotWiring.js +11 -10
  104. package/dist/canvas/sceneSlotWiring.js.map +1 -1
  105. package/dist/canvas/sceneViewRender.js +38 -44
  106. package/dist/canvas/sceneViewRender.js.map +1 -1
  107. package/dist/canvas/useCanvasView.js +42 -44
  108. package/dist/canvas/useCanvasView.js.map +1 -1
  109. package/dist/canvas/useSceneAdapter.js +22 -0
  110. package/dist/canvas/useSceneAdapter.js.map +1 -0
  111. package/dist/canvas/useSurfaceInput.js +13 -16
  112. package/dist/canvas/useSurfaceInput.js.map +1 -1
  113. package/dist/canvas/viewRegistry.js +31 -23
  114. package/dist/canvas/viewRegistry.js.map +1 -1
  115. package/dist/canvas/wrapNodeOutput.js +7 -2
  116. package/dist/canvas/wrapNodeOutput.js.map +1 -1
  117. package/dist/clipboard.d.ts +1 -1
  118. package/dist/{clone-2a5hVbBd.d.ts → clone-C0eADtS0.d.ts} +13 -13
  119. package/dist/clone.d.ts +2 -2
  120. package/dist/core/geometry/poseDescriptor.js +49 -23
  121. package/dist/core/geometry/poseDescriptor.js.map +1 -1
  122. package/dist/core/geometry/regionHit.js +2 -2
  123. package/dist/core/geometry/regionHit.js.map +1 -1
  124. package/dist/core/geometry/targetFrame.js.map +1 -1
  125. package/dist/core/layers/children.js +1 -3
  126. package/dist/core/layers/children.js.map +1 -1
  127. package/dist/core/ops/create.js +2 -2
  128. package/dist/core/ops/create.js.map +1 -1
  129. package/dist/core/ops/delete.js +19 -23
  130. package/dist/core/ops/delete.js.map +1 -1
  131. package/dist/core/ops/reorder/index.js +3 -7
  132. package/dist/core/ops/reorder/index.js.map +1 -1
  133. package/dist/core/ops/reorder/setChildOrder.js +2 -4
  134. package/dist/core/ops/reorder/setChildOrder.js.map +1 -1
  135. package/dist/core/ops/reparent.js +0 -1
  136. package/dist/core/ops/reparent.js.map +1 -1
  137. package/dist/core/ops/slot.js +3 -6
  138. package/dist/core/ops/slot.js.map +1 -1
  139. package/dist/core/pages/fitViewToPage.js +15 -0
  140. package/dist/core/pages/fitViewToPage.js.map +1 -0
  141. package/dist/core/pages/pages.js +65 -0
  142. package/dist/core/pages/pages.js.map +1 -0
  143. package/dist/core/pages/pagesLayer.js +27 -0
  144. package/dist/core/pages/pagesLayer.js.map +1 -0
  145. package/dist/core/paint/meshKindLazy.js +2 -2
  146. package/dist/core/paint/meshKindLazy.js.map +1 -1
  147. package/dist/core/scene/NodeProperties.js.map +1 -1
  148. package/dist/core/scene/composeFrame.js.map +1 -1
  149. package/dist/core/scene/composePose.js +58 -20
  150. package/dist/core/scene/composePose.js.map +1 -1
  151. package/dist/core/scene/effectivePose.js +5 -1
  152. package/dist/core/scene/effectivePose.js.map +1 -1
  153. package/dist/core/scene/historyFacade.js +19 -13
  154. package/dist/core/scene/historyFacade.js.map +1 -1
  155. package/dist/core/scene/nodeFnFields.js +7 -0
  156. package/dist/core/scene/nodeFnFields.js.map +1 -1
  157. package/dist/core/scene/outerOps.js +2 -1
  158. package/dist/core/scene/outerOps.js.map +1 -1
  159. package/dist/core/scene/reconcileSpecs.js +1 -1
  160. package/dist/core/scene/reconcileSpecs.js.map +1 -1
  161. package/dist/core/scene/sceneRecording.js +2 -1
  162. package/dist/core/scene/sceneRecording.js.map +1 -1
  163. package/dist/core/scene/types.js.map +1 -1
  164. package/dist/core/viewport/screenSlop.js.map +1 -1
  165. package/dist/core/viewport/useDecayLoop.js +28 -30
  166. package/dist/core/viewport/useDecayLoop.js.map +1 -1
  167. package/dist/core/viewport/useNodeOverlayFrame.js.map +1 -1
  168. package/dist/core/viewport/useViewAnimation.js +70 -69
  169. package/dist/core/viewport/useViewAnimation.js.map +1 -1
  170. package/dist/core/viewport/view.js +8 -5
  171. package/dist/core/viewport/view.js.map +1 -1
  172. package/dist/core/viewport/zoomAt.js +11 -2
  173. package/dist/core/viewport/zoomAt.js.map +1 -1
  174. package/dist/{cornerHandles-BEshc4z3.d.ts → cornerHandles-BSKbyuvQ.d.ts} +1 -1
  175. package/dist/features/paths/editablePath.js +24 -8
  176. package/dist/features/paths/editablePath.js.map +1 -1
  177. package/dist/features/paths/index.js +4 -4
  178. package/dist/features/paths/shapeGenerator.js +89 -0
  179. package/dist/features/paths/shapeGenerator.js.map +1 -0
  180. package/dist/features/paths/usePathEdit.js +13 -13
  181. package/dist/features/poseRun/usePoseRun.js +25 -25
  182. package/dist/features/poseRun/usePoseRun.js.map +1 -1
  183. package/dist/features/text/useSceneTextEdit.js +82 -64
  184. package/dist/features/text/useSceneTextEdit.js.map +1 -1
  185. package/dist/features/viewports/viewResolver.js +28 -24
  186. package/dist/features/viewports/viewResolver.js.map +1 -1
  187. package/dist/icons/SliceIcon.js +24 -0
  188. package/dist/icons/SliceIcon.js.map +1 -0
  189. package/dist/index.d.ts +956 -581
  190. package/dist/index.js +260 -251
  191. package/dist/interactions/actions/align/align.js +9 -9
  192. package/dist/interactions/actions/align/align.js.map +1 -1
  193. package/dist/interactions/actions/booleans/booleans.js +18 -18
  194. package/dist/interactions/actions/booleans/booleans.js.map +1 -1
  195. package/dist/interactions/actions/booleans/operands.js.map +1 -1
  196. package/dist/interactions/actions/clone/action.js +35 -30
  197. package/dist/interactions/actions/clone/action.js.map +1 -1
  198. package/dist/interactions/actions/defaults/anchorEditing.js +56 -59
  199. package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
  200. package/dist/interactions/actions/defaults/anchorHandles.js +42 -0
  201. package/dist/interactions/actions/defaults/anchorHandles.js.map +1 -0
  202. package/dist/interactions/actions/defaults/anchorJoin.js +92 -0
  203. package/dist/interactions/actions/defaults/anchorJoin.js.map +1 -0
  204. package/dist/interactions/actions/defaults/bendSegment.js +46 -0
  205. package/dist/interactions/actions/defaults/bendSegment.js.map +1 -0
  206. package/dist/interactions/actions/defaults/copySubtree.js +1 -1
  207. package/dist/interactions/actions/defaults/copySubtree.js.map +1 -1
  208. package/dist/interactions/actions/defaults/duplicate.js +32 -17
  209. package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
  210. package/dist/interactions/actions/defaults/enterPathEdit.js +19 -7
  211. package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
  212. package/dist/interactions/actions/defaults/icons/anchorIcons.js +75 -0
  213. package/dist/interactions/actions/defaults/icons/anchorIcons.js.map +1 -0
  214. package/dist/interactions/actions/defaults/icons/editIcons.js +35 -8
  215. package/dist/interactions/actions/defaults/icons/editIcons.js.map +1 -1
  216. package/dist/interactions/actions/defaults/insertPathAnchor.js +16 -31
  217. package/dist/interactions/actions/defaults/insertPathAnchor.js.map +1 -1
  218. package/dist/interactions/actions/defaults/nudge.js +28 -23
  219. package/dist/interactions/actions/defaults/nudge.js.map +1 -1
  220. package/dist/interactions/actions/defaults/pinchZoom.js +29 -29
  221. package/dist/interactions/actions/defaults/pinchZoom.js.map +1 -1
  222. package/dist/interactions/actions/defaults/segmentUnder.js +22 -0
  223. package/dist/interactions/actions/defaults/segmentUnder.js.map +1 -0
  224. package/dist/interactions/actions/defaults/viewportZoom.js +82 -79
  225. package/dist/interactions/actions/defaults/viewportZoom.js.map +1 -1
  226. package/dist/interactions/actions/distribute/distribute.js +8 -8
  227. package/dist/interactions/actions/distribute/distribute.js.map +1 -1
  228. package/dist/interactions/actions/edit-anchors/action.js +58 -55
  229. package/dist/interactions/actions/edit-anchors/action.js.map +1 -1
  230. package/dist/interactions/actions/edit-anchors/preview.js +26 -0
  231. package/dist/interactions/actions/edit-anchors/preview.js.map +1 -0
  232. package/dist/interactions/actions/edit-anchors/symmetry.js +11 -0
  233. package/dist/interactions/actions/edit-anchors/symmetry.js.map +1 -0
  234. package/dist/interactions/actions/flip/action.js.map +1 -1
  235. package/dist/interactions/actions/geometryProjection.js.map +1 -1
  236. package/dist/interactions/actions/insert/action.js +37 -30
  237. package/dist/interactions/actions/insert/action.js.map +1 -1
  238. package/dist/interactions/actions/insert/frame.js +9 -2
  239. package/dist/interactions/actions/insert/frame.js.map +1 -1
  240. package/dist/interactions/actions/insert/repositionAction.js +31 -0
  241. package/dist/interactions/actions/insert/repositionAction.js.map +1 -0
  242. package/dist/interactions/actions/lasso-select/action.js +32 -32
  243. package/dist/interactions/actions/move/action.js +29 -25
  244. package/dist/interactions/actions/move/action.js.map +1 -1
  245. package/dist/interactions/actions/move/behaviors/snapToContainer.js +12 -6
  246. package/dist/interactions/actions/move/behaviors/snapToContainer.js.map +1 -1
  247. package/dist/interactions/actions/move/capture.js +32 -23
  248. package/dist/interactions/actions/move/capture.js.map +1 -1
  249. package/dist/interactions/actions/move/frame.js +2 -14
  250. package/dist/interactions/actions/move/frame.js.map +1 -1
  251. package/dist/interactions/actions/move/session.js +1 -1
  252. package/dist/interactions/actions/move/session.js.map +1 -1
  253. package/dist/interactions/actions/move/translate.js.map +1 -1
  254. package/dist/interactions/actions/outlines/createOutlines.js.map +1 -1
  255. package/dist/interactions/actions/outlines/replaceWithPaths.js +13 -13
  256. package/dist/interactions/actions/outlines/replaceWithPaths.js.map +1 -1
  257. package/dist/interactions/actions/outlines/strokeRegion.js.map +1 -1
  258. package/dist/interactions/actions/pathCommands/cutJoin.js +102 -0
  259. package/dist/interactions/actions/pathCommands/cutJoin.js.map +1 -0
  260. package/dist/interactions/actions/pathCommands/livePathEdit.js +64 -0
  261. package/dist/interactions/actions/pathCommands/livePathEdit.js.map +1 -0
  262. package/dist/interactions/actions/pathCommands/pathNodes.js +99 -0
  263. package/dist/interactions/actions/pathCommands/pathNodes.js.map +1 -0
  264. package/dist/interactions/actions/pathCommands/simplifyOffset.js +42 -0
  265. package/dist/interactions/actions/pathCommands/simplifyOffset.js.map +1 -0
  266. package/dist/interactions/actions/resize/action.js +31 -20
  267. package/dist/interactions/actions/resize/action.js.map +1 -1
  268. package/dist/interactions/actions/resize/commit.js.map +1 -1
  269. package/dist/interactions/actions/resize/frame.js +29 -15
  270. package/dist/interactions/actions/resize/frame.js.map +1 -1
  271. package/dist/interactions/actions/resize/replay.js +47 -0
  272. package/dist/interactions/actions/resize/replay.js.map +1 -0
  273. package/dist/interactions/actions/resize/session.js +49 -35
  274. package/dist/interactions/actions/resize/session.js.map +1 -1
  275. package/dist/interactions/actions/resolveOverlays.js +2 -1
  276. package/dist/interactions/actions/resolveOverlays.js.map +1 -1
  277. package/dist/interactions/actions/rotate/action.js +40 -25
  278. package/dist/interactions/actions/rotate/action.js.map +1 -1
  279. package/dist/interactions/actions/rotate/frame.js +1 -1
  280. package/dist/interactions/actions/rotate/frame.js.map +1 -1
  281. package/dist/interactions/actions/rotate/replay.js +22 -0
  282. package/dist/interactions/actions/rotate/replay.js.map +1 -0
  283. package/dist/interactions/actions/rotate/session.js +42 -32
  284. package/dist/interactions/actions/rotate/session.js.map +1 -1
  285. package/dist/interactions/actions/transform-again/action.js +63 -0
  286. package/dist/interactions/actions/transform-again/action.js.map +1 -0
  287. package/dist/interactions/actions/transform-again/memory.js +35 -0
  288. package/dist/interactions/actions/transform-again/memory.js.map +1 -0
  289. package/dist/interactions/actions/useStandardActions.js +101 -83
  290. package/dist/interactions/actions/useStandardActions.js.map +1 -1
  291. package/dist/move.d.ts +4 -4
  292. package/dist/{originProjection-PPT88jZv.d.ts → originProjection-CoNVpITV.d.ts} +1 -1
  293. package/dist/resize.d.ts +3 -3
  294. package/dist/style.css +1 -1
  295. package/dist/tools/builtin/ellipse/useEllipseTool.js +16 -15
  296. package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
  297. package/dist/tools/builtin/line/useLineTool.js +16 -15
  298. package/dist/tools/builtin/line/useLineTool.js.map +1 -1
  299. package/dist/tools/builtin/pen/usePenTool.js +111 -111
  300. package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
  301. package/dist/tools/builtin/pickTopMostHit.js +11 -14
  302. package/dist/tools/builtin/pickTopMostHit.js.map +1 -1
  303. package/dist/tools/builtin/polygon/usePolygonTool.js +17 -15
  304. package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
  305. package/dist/tools/builtin/rect/useRectTool.js +15 -14
  306. package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
  307. package/dist/tools/builtin/select/adapterPointQuery.js +22 -18
  308. package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
  309. package/dist/tools/builtin/select/selectionContributions.js +1 -1
  310. package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
  311. package/dist/tools/builtin/select/useSelectTool.js +2 -1
  312. package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
  313. package/dist/tools/builtin/slice/useSliceTool.js +42 -40
  314. package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
  315. package/dist/tools/builtin/star/useStarTool.js +18 -16
  316. package/dist/tools/builtin/star/useStarTool.js.map +1 -1
  317. package/dist/tools/builtin/text/useTextTool.js +2 -2
  318. package/dist/tools/builtin/text/useTextTool.js.map +1 -1
  319. package/dist/{types-CIKDwlsP.d.ts → types-DBbbCy0i.d.ts} +22 -15
  320. package/dist/version.js +1 -1
  321. package/package.json +22 -22
  322. package/dist/canvas/surface.module.js +0 -6
  323. package/dist/canvas/surface.module.js.map +0 -1
  324. package/dist/canvas/surfaceBox.js +0 -16
  325. package/dist/canvas/surfaceBox.js.map +0 -1
  326. package/dist/layout/arrivals.js +0 -33
  327. package/dist/layout/arrivals.js.map +0 -1
@@ -1,54 +1,63 @@
1
1
  import { IDENTITY_TARGET as e, angleOf as t, localToWorld as n, normalToWorld as r, pxExtentIn as i, targetTransformOf as a, worldToLocal as o } from "../core/geometry/targetFrame.js";
2
- import { scaleDelta as s, screenAngleOf as c, standoff as l } from "@weasel-js/geom";
2
+ import { multiply as s, scale as c, scaleDelta as l, screenAngleOf as u, standoff as d, strokeHitTest as f } from "@weasel-js/geom";
3
3
  //#region src/affordances/hitAffordanceRegions.ts
4
- function u(e, t, n, r, i, a) {
4
+ function p(e, t, n, r, i, a) {
5
5
  for (let o = e.length - 1; o >= 0; o--) {
6
6
  let s = e[o];
7
7
  if (a && !a(s.id)) continue;
8
8
  let c = s.regions(r), l = null;
9
9
  for (let e = 0; e < c.length; e++) {
10
- let a = c[e], o = f(r, a.targetId);
11
- if (!v(a, t, n, o, i)) continue;
12
- let s = d(a, t, n, o, i);
10
+ let a = c[e], o = h(r, a.targetId);
11
+ if (!x(a, t, n, o, i)) continue;
12
+ let s = m(a, t, n, o, i);
13
13
  (l === null || s <= l.d2) && (l = {
14
14
  region: a,
15
15
  d2: s
16
16
  });
17
17
  }
18
- if (l) return {
19
- affordanceId: s.id,
20
- regionId: l.region.id,
21
- region: l.region,
22
- binding: l.region.bind()
23
- };
18
+ if (l) {
19
+ let { cursor: e } = l.region, r = typeof e == "function" ? e({
20
+ x: t,
21
+ y: n
22
+ }, i) : e;
23
+ return {
24
+ affordanceId: s.id,
25
+ regionId: l.region.id,
26
+ region: l.region,
27
+ ...r === void 0 ? {} : { cursor: r },
28
+ binding: l.region.bind()
29
+ };
30
+ }
24
31
  }
25
32
  return null;
26
33
  }
27
- function d(e, t, r, i, a) {
28
- let o = e.shape, s = o.kind === "point" ? g(o, i, a) : o.kind === "annulus" ? n(i, o.cx, o.cy) : n(i, o.x + o.width / 2, o.y + o.height / 2), c = s.x - t, l = s.y - r;
34
+ function m(e, t, r, i, a) {
35
+ let o = e.shape;
36
+ if (o.kind === "outline") return 0;
37
+ let s = o.kind === "point" ? y(o, i, a) : o.kind === "annulus" ? n(i, o.cx, o.cy) : n(i, o.x + o.width / 2, o.y + o.height / 2), c = s.x - t, l = s.y - r;
29
38
  return c * c + l * l;
30
39
  }
31
- function f(t, n) {
40
+ function h(t, n) {
32
41
  return n === null ? e : a(t.boundsOf(n));
33
42
  }
34
- function p(e, n, r) {
35
- let a = g(e, n, r), o = e.turned ? c(t(n), r.scale) : 0, s = e.hitRadiusPx, l = [-s, s], u = [-s, s], d = e.cornerOf;
43
+ function g(e, n, r) {
44
+ let a = y(e, n, r), o = e.turned ? u(t(n), r.scale) : 0, s = e.hitRadiusPx, c = [-s, s], l = [-s, s], d = e.cornerOf;
36
45
  if (d) {
37
- let e = i(m * s, r.scale, n), [t, a, o, c] = n.toWorld, f = d.outward.y * Math.sign(r.scale.x * r.scale.y * (t * c - a * o));
38
- d.width < e.x && (l[d.outward.x > 0 ? 0 : 1] = 0), d.height < e.y && (u[f > 0 ? 0 : 1] = 0);
46
+ let e = i(_ * s, r.scale, n), [t, a, o, u] = n.toWorld, f = d.outward.y * Math.sign(r.scale.x * r.scale.y * (t * u - a * o));
47
+ d.width < e.x && (c[d.outward.x > 0 ? 0 : 1] = 0), d.height < e.y && (l[f > 0 ? 0 : 1] = 0);
39
48
  }
40
49
  return {
41
50
  x: a.x,
42
51
  y: a.y,
43
52
  angle: o,
44
53
  half: s,
45
- u: l,
46
- v: u
54
+ u: c,
55
+ v: l
47
56
  };
48
57
  }
49
- var m = 4;
50
- function h(e, t, n, r) {
51
- let i = p(e, t, n), [a, o] = r(i.x, i.y), s = Math.cos(i.angle), c = Math.sin(i.angle);
58
+ var _ = 4;
59
+ function v(e, t, n, r) {
60
+ let i = g(e, t, n), [a, o] = r(i.x, i.y), s = Math.cos(i.angle), c = Math.sin(i.angle);
52
61
  return [
53
62
  [i.u[0], i.v[0]],
54
63
  [i.u[1], i.v[0]],
@@ -59,11 +68,11 @@ function h(e, t, n, r) {
59
68
  y: o + c * e + s * t
60
69
  }));
61
70
  }
62
- function g(e, t, i) {
71
+ function y(e, t, i) {
63
72
  let a = n(t, e.x, e.y);
64
- return e.standoff ? l(a, r(t, e.standoff.normal), e.standoff.px, i.scale) : a;
73
+ return e.standoff ? d(a, r(t, e.standoff.normal), e.standoff.px, i.scale) : a;
65
74
  }
66
- function _(t, n, r = e) {
75
+ function b(t, n, r = e) {
67
76
  let a = t.minBandPx ?? 0;
68
77
  if (a === 0) return {
69
78
  rx: t.rx,
@@ -75,25 +84,32 @@ function _(t, n, r = e) {
75
84
  ry: Math.max(t.ry, t.innerHeight / 2 + o.y)
76
85
  };
77
86
  }
78
- function v(e, t, n, r, i) {
87
+ function x(e, t, n, r, i) {
79
88
  if (e.shape.kind === "point") {
80
- let a = p(e.shape, r, i), o = s(t - a.x, n - a.y, i.scale), c = Math.cos(a.angle), l = Math.sin(a.angle), u = c * o.x + l * o.y, d = -l * o.x + c * o.y;
89
+ let a = g(e.shape, r, i), o = l(t - a.x, n - a.y, i.scale), s = Math.cos(a.angle), c = Math.sin(a.angle), u = s * o.x + c * o.y, d = -c * o.x + s * o.y;
81
90
  return u >= a.u[0] && u <= a.u[1] && d >= a.v[0] && d <= a.v[1];
82
91
  }
83
92
  let a = o(r, t, n);
84
93
  if (!a) return !1;
94
+ if (e.shape.kind === "outline") {
95
+ let t = e.shape;
96
+ return f(t.path, a.x, a.y, 0, { slop: {
97
+ px: t.hitRadiusPx,
98
+ transform: s(c(i.scale.x, i.scale.y), r.toWorld)
99
+ } });
100
+ }
85
101
  if (e.shape.kind === "annulus") {
86
102
  let t = e.shape;
87
103
  if (a.x >= t.innerX && a.x <= t.innerX + t.innerWidth && a.y >= t.innerY && a.y <= t.innerY + t.innerHeight) return !1;
88
- let { rx: n, ry: o } = _(t, i, r);
104
+ let { rx: n, ry: o } = b(t, i, r);
89
105
  if (n <= 0 || o <= 0) return !1;
90
106
  let s = (a.x - t.cx) / n, c = (a.y - t.cy) / o;
91
107
  return s * s + c * c <= 1;
92
108
  }
93
- let c = e.shape;
94
- return a.x >= c.x && a.x <= c.x + c.width && a.y >= c.y && a.y <= c.y + c.height;
109
+ let u = e.shape;
110
+ return a.x >= u.x && a.x <= u.x + u.width && a.y >= u.y && a.y <= u.y + u.height;
95
111
  }
96
112
  //#endregion
97
- export { t as angleOf, _ as annulusSemiAxes, u as hitAffordanceRegions, n as localToWorld, g as pointRegionAnchor, p as pointRegionFrame, h as pointRegionScreenQuad, f as transformOf };
113
+ export { t as angleOf, b as annulusSemiAxes, p as hitAffordanceRegions, n as localToWorld, y as pointRegionAnchor, g as pointRegionFrame, v as pointRegionScreenQuad, h as transformOf };
98
114
 
99
115
  //# sourceMappingURL=hitAffordanceRegions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hitAffordanceRegions.js","names":["hitAffordanceRegions","i","affordances","a","isVisible","regions","state","best","j","region","xf","transformOf","hitRegion","wx","wy","view","d2","regionDistance2","s","w","pointRegionAnchor","localToWorld","dx","dy","targetId","IDENTITY_TARGET","targetTransformOf","pointRegionFrame","shape","angle","screenAngleOf","angleOf","half","u","v","body","floor","pxExtentIn","SMALL_BODY_RADII","b","c","d","vOut","pointRegionScreenQuad","f","cx","cy","toScreen","sn","standoff","normalToWorld","annulusSemiAxes","bandPx","band","scaleDelta","local","worldToLocal","rx","ry","ex","ey","r"],"sources":["../../src/affordances/hitAffordanceRegions.ts"],"sourcesContent":["/**\n * The one affordance hit-test walk: an affordance's `regions()` is the single\n * source of truth for where its chrome is and what a press on it means.\n */\n\nimport type { View } from 'core/viewport/view';\nimport { scaleDelta, screenAngleOf, standoff } from '@weasel-js/geom';\nimport type { ChromeState } from 'core/selection/chromeState';\nimport {\n angleOf, IDENTITY_TARGET, localToWorld, normalToWorld, pxExtentIn, targetTransformOf, worldToLocal,\n type TargetTransform,\n} from 'core/geometry/targetFrame';\nimport type { Affordance, AffordanceBinding, AffordanceRegion } from './types';\n\n/** What the walk found: the region, plus the ids needed to describe it. */\nexport interface AffordanceRegionHit {\n /** `Affordance.id` — also the chrome-caps visibility id. */\n affordanceId: string;\n /** `AffordanceRegion.id`. */\n regionId: string;\n /** The region itself, so callers can read `hitKind` / `cursor`. */\n region: AffordanceRegion;\n /** Result of the region's `bind()`, called exactly once. */\n binding: AffordanceBinding;\n}\n\n/**\n * Walk affordances for a world-space hit, topmost first.\n *\n * **Across affordances**: order mirrors paint. Affordances are drawn first →\n * last (bottom → top), so the walk runs last → first and stops at the first\n * one that claims the point. Layering wins outright — a nearer region on a\n * lower affordance does not beat a farther one on top of it.\n *\n * **Within an affordance**: the *nearest* hit region wins, ties going to the\n * later-declared one. Regions overlap: the four corner handles of a selection\n * smaller than the hit radius all contain the same click.\n *\n * `isVisible` (when supplied) gates by the same chrome id used at paint time,\n * so chrome that isn't drawn can't be hit either.\n */\nexport function hitAffordanceRegions(\n affordances: readonly Affordance[],\n wx: number,\n wy: number,\n state: ChromeState,\n view: View,\n isVisible?: (id: string) => boolean,\n): AffordanceRegionHit | null {\n for (let i = affordances.length - 1; i >= 0; i--) {\n const a = affordances[i];\n if (isVisible && !isVisible(a.id)) continue;\n const regions = a.regions(state);\n let best: { region: AffordanceRegion; d2: number } | null = null;\n for (let j = 0; j < regions.length; j++) {\n const region = regions[j];\n const xf = transformOf(state, region.targetId);\n if (!hitRegion(region, wx, wy, xf, view)) continue;\n const d2 = regionDistance2(region, wx, wy, xf, view);\n // `<=` so a later-declared region wins an exact tie, preserving the\n // \"later is on top\" reading of declaration order.\n if (best === null || d2 <= best.d2) best = { region, d2 };\n }\n if (best) {\n return {\n affordanceId: a.id,\n regionId: best.region.id,\n region: best.region,\n binding: best.region.bind(),\n };\n }\n }\n return null;\n}\n\n/** Squared world distance from the point to a region's representative center,\n * used only to rank regions that all already contain the point. */\nfunction regionDistance2(\n region: AffordanceRegion,\n wx: number,\n wy: number,\n xf: TargetTransform,\n view: View,\n): number {\n const s = region.shape;\n const w = s.kind === 'point'\n ? pointRegionAnchor(s, xf, view)\n : s.kind === 'annulus'\n ? localToWorld(xf, s.cx, s.cy)\n : localToWorld(xf, s.x + s.width / 2, s.y + s.height / 2);\n const dx = w.x - wx;\n const dy = w.y - wy;\n return dx * dx + dy * dy;\n}\n\n// ─── Transform helpers ──────────────────────────────────────────────────────\n\nexport { angleOf, localToWorld, type TargetTransform };\n\n/** The frame `targetId`'s bounds are drawn in; identity for no target. */\nexport function transformOf(state: ChromeState, targetId: string | null): TargetTransform {\n if (targetId === null) return IDENTITY_TARGET;\n return targetTransformOf(state.boundsOf(targetId));\n}\n\n// ─── Shape resolution ───────────────────────────────────────────────────────\n\ntype PointShape = Extract<AffordanceRegion['shape'], { kind: 'point' }>;\n\n/** Where a point region's hit square sits: its center in world coords, its\n * turn on screen, its screen half-extent, and the span of the square that\n * takes a press along each of its own axes (`[-half, half]` unless\n * `cornerOf` cuts it). */\nexport function pointRegionFrame(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n): { x: number; y: number; angle: number; half: number; u: [number, number]; v: [number, number] } {\n const a = pointRegionAnchor(shape, xf, view);\n const angle = shape.turned ? screenAngleOf(angleOf(xf), view.scale) : 0;\n const half = shape.hitRadiusPx;\n const u: [number, number] = [-half, half];\n const v: [number, number] = [-half, half];\n const body = shape.cornerOf;\n if (body) {\n // The body in world units that spans four hit radii on screen, per axis.\n const floor = pxExtentIn(SMALL_BODY_RADII * half, view.scale, xf);\n // `v` runs a quarter turn on from `u` on screen, which is the target's +y\n // only while the view and the target's frame keep their handedness.\n const [a, b, c, d] = xf.toWorld;\n const vOut = body.outward.y * Math.sign(view.scale.x * view.scale.y * (a * d - b * c));\n if (body.width < floor.x) u[body.outward.x > 0 ? 0 : 1] = 0;\n if (body.height < floor.y) v[vOut > 0 ? 0 : 1] = 0;\n }\n return { x: a.x, y: a.y, angle, half, u, v };\n}\n\n/** A body under this many hit radii across gives up the inward half of each\n * corner's hit square, so there is somewhere on it that is not a handle. */\nconst SMALL_BODY_RADII = 4;\n\n/** A point region's hit square as four screen-space corners, relative to its\n * world center carried to the screen by `toScreen`. */\nexport function pointRegionScreenQuad(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n toScreen: (x: number, y: number) => [number, number],\n): { x: number; y: number }[] {\n const f = pointRegionFrame(shape, xf, view);\n const [cx, cy] = toScreen(f.x, f.y);\n const c = Math.cos(f.angle), sn = Math.sin(f.angle);\n return [[f.u[0], f.v[0]], [f.u[1], f.v[0]], [f.u[1], f.v[1]], [f.u[0], f.v[1]]].map(([u, v]) => ({\n x: cx + c * u - sn * v,\n y: cy + sn * u + c * v,\n }));\n}\n\n/** A point region's anchor in world coords, its `standoff` applied. */\nexport function pointRegionAnchor(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n): { x: number; y: number } {\n const a = localToWorld(xf, shape.x, shape.y);\n if (!shape.standoff) return a;\n return standoff(a, normalToWorld(xf, shape.standoff.normal), shape.standoff.px, view.scale);\n}\n\n/**\n * An annulus region's effective outer semi-axes, in world units, with the\n * screen-space `minBandPx` floor on band thickness applied. Paint calls it\n * too, so the visible ring and the hoverable ring are the same ring.\n */\nexport function annulusSemiAxes(\n shape: Extract<AffordanceRegion['shape'], { kind: 'annulus' }>,\n view: View,\n /** The target's frame, which decides what a screen pixel is along each of\n * its axes. */\n xf: TargetTransform = IDENTITY_TARGET,\n): { rx: number; ry: number } {\n const bandPx = shape.minBandPx ?? 0;\n if (bandPx === 0) return { rx: shape.rx, ry: shape.ry };\n const band = pxExtentIn(bandPx, view.scale, xf);\n return {\n rx: Math.max(shape.rx, shape.innerWidth / 2 + band.x),\n ry: Math.max(shape.ry, shape.innerHeight / 2 + band.y),\n };\n}\n\n// ─── Per-shape hit-test ─────────────────────────────────────────────────────\n\nfunction hitRegion(\n region: AffordanceRegion,\n wx: number,\n wy: number,\n xf: TargetTransform,\n view: View,\n): boolean {\n if (region.shape.kind === 'point') {\n // Square hit, not circular: the handle a `point` region paints is a\n // square, and a circle leaves its corners unclickable.\n //\n // Compared in screen space: testing it in the target's local frame would\n // stretch it under non-uniform zoom.\n const f = pointRegionFrame(region.shape, xf, view);\n const d = scaleDelta(wx - f.x, wy - f.y, view.scale);\n const c = Math.cos(f.angle), sn = Math.sin(f.angle);\n const u = c * d.x + sn * d.y, v = -sn * d.x + c * d.y;\n return u >= f.u[0] && u <= f.u[1] && v >= f.v[0] && v <= f.v[1];\n }\n const local = worldToLocal(xf, wx, wy);\n if (!local) return false;\n if (region.shape.kind === 'annulus') {\n const s = region.shape;\n // Outside the inner-rect cutout?\n const insideInner =\n local.x >= s.innerX && local.x <= s.innerX + s.innerWidth &&\n local.y >= s.innerY && local.y <= s.innerY + s.innerHeight;\n if (insideInner) return false;\n // Inside the outer ellipse? `((x-cx)/rx)² + ((y-cy)/ry)² ≤ 1`.\n const { rx, ry } = annulusSemiAxes(s, view, xf);\n if (rx <= 0 || ry <= 0) return false;\n const ex = (local.x - s.cx) / rx;\n const ey = (local.y - s.cy) / ry;\n return ex * ex + ey * ey <= 1;\n }\n // rect: axis-aligned in local frame.\n const r = region.shape;\n return local.x >= r.x && local.x <= r.x + r.width\n && local.y >= r.y && local.y <= r.y + r.height;\n}\n"],"mappings":";;;AAyCA,SAAgBA,EACd,GACA,GACA,GACA,GACA,GACA,GAC4B;CAC5B,KAAK,IAAIC,IAAIC,EAAY,SAAS,GAAGD,KAAK,GAAG,KAAK;EAChD,IAAME,IAAID,EAAYD;EACtB,IAAIG,KAAa,CAACA,EAAUD,EAAE,EAAE,GAAG;EACnC,IAAME,IAAUF,EAAE,QAAQG,CAAK,GAC3BC,IAAwD;EAC5D,KAAK,IAAIC,IAAI,GAAGA,IAAIH,EAAQ,QAAQ,KAAK;GACvC,IAAMI,IAASJ,EAAQG,IACjBE,IAAKC,EAAYL,GAAOG,EAAO,QAAQ;GAC7C,IAAI,CAACG,EAAUH,GAAQI,GAAIC,GAAIJ,GAAIK,CAAI,GAAG;GAC1C,IAAMC,IAAKC,EAAgBR,GAAQI,GAAIC,GAAIJ,GAAIK,CAAI;GAGnD,CAAIR,MAAS,QAAQS,KAAMT,EAAK,QAAI,IAAO;IAAE;IAAQ;GAAG;EAC1D;EACA,IAAIA,GACF,OAAO;GACL,cAAcJ,EAAE;GAChB,UAAUI,EAAK,OAAO;GACtB,QAAQA,EAAK;GACb,SAASA,EAAK,OAAO,KAAK;EAC5B;CAEJ;CACA,OAAO;AACT;AAIA,SAASU,EACP,GACA,GACA,GACA,GACA,GACQ;CACR,IAAMC,IAAIT,EAAO,OACXU,IAAID,EAAE,SAAS,UACjBE,EAAkBF,GAAGR,GAAIK,CAAI,IAC7BG,EAAE,SAAS,YACTG,EAAaX,GAAIQ,EAAE,IAAIA,EAAE,EAAE,IAC3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,IAAK8B,EAAE,GAAG7B,EAAK,KAAK,GAC7C,IAAI,KAAK,IAAI6B,EAAE,KAAK,GAAGI,IAAK,KAAK,IAAIJ,EAAE,KAAK,GAC5C,IAAI,IAAIH,EAAE,IAAIO,IAAKP,EAAE,GAAGP,IAAI,CAACc,IAAKP,EAAE,IAAI,IAAIA,EAAE;EACpD,OAAO,KAAKG,EAAE,EAAE,MAAM,KAAKA,EAAE,EAAE,MAAMV,KAAKU,EAAE,EAAE,MAAMV,KAAKU,EAAE,EAAE;CAC/D;CACA,IAAMW,IAAQC,EAAa9C,GAAIG,GAAIC,CAAE;CACrC,IAAI,CAACyC,GAAO,OAAO;CACnB,IAAI9C,EAAO,MAAM,SAAS,WAAW;EACnC,IAAMS,IAAIT,EAAO;EAKjB,IAFE8C,EAAM,KAAKrC,EAAE,UAAUqC,EAAM,KAAKrC,EAAE,SAASA,EAAE,cAC/CqC,EAAM,KAAKrC,EAAE,UAAUqC,EAAM,KAAKrC,EAAE,SAASA,EAAE,aAChC,OAAO;EAExB,IAAM,EAAE,OAAI,UAAOiC,EAAgBjC,GAAGH,GAAML,CAAE;EAC9C,IAAI+C,KAAM,KAAKC,KAAM,GAAG,OAAO;EAC/B,IAAMC,KAAMJ,EAAM,IAAIrC,EAAE,MAAMuC,GACxBG,KAAML,EAAM,IAAIrC,EAAE,MAAMwC;EAC9B,OAAOC,IAAKA,IAAKC,IAAKA,KAAM;CAC9B;CAEA,IAAMC,IAAIpD,EAAO;CACjB,OAAO8C,EAAM,KAAKM,EAAE,KAAKN,EAAM,KAAKM,EAAE,IAAIA,EAAE,SACrCN,EAAM,KAAKM,EAAE,KAAKN,EAAM,KAAKM,EAAE,IAAIA,EAAE;AAC9C"}
1
+ {"version":3,"file":"hitAffordanceRegions.js","names":["hitAffordanceRegions","i","affordances","a","isVisible","regions","state","best","j","region","xf","transformOf","hitRegion","wx","wy","view","d2","regionDistance2","at","cursor","s","w","pointRegionAnchor","localToWorld","dx","dy","targetId","IDENTITY_TARGET","targetTransformOf","pointRegionFrame","shape","angle","screenAngleOf","angleOf","half","u","v","body","floor","pxExtentIn","SMALL_BODY_RADII","b","c","d","vOut","pointRegionScreenQuad","f","cx","cy","toScreen","sn","standoff","normalToWorld","annulusSemiAxes","bandPx","band","scaleDelta","local","worldToLocal","strokeHitTest","multiply","scale","rx","ry","ex","ey","r"],"sources":["../../src/affordances/hitAffordanceRegions.ts"],"sourcesContent":["/**\n * The one affordance hit-test walk: an affordance's `regions()` is the single\n * source of truth for where its chrome is and what a press on it means.\n */\n\nimport type { View } from 'core/viewport/view';\nimport { multiply, scale, scaleDelta, screenAngleOf, standoff, strokeHitTest } from '@weasel-js/geom';\nimport type { ChromeState } from 'core/selection/chromeState';\nimport {\n angleOf, IDENTITY_TARGET, localToWorld, normalToWorld, pxExtentIn, targetTransformOf, worldToLocal,\n type TargetTransform,\n} from 'core/geometry/targetFrame';\nimport type { Affordance, AffordanceBinding, AffordanceRegion } from './types';\nimport type { CursorSpec } from '@weasel-js/cursor';\n\n/** What the walk found: the region, plus the ids needed to describe it. */\nexport interface AffordanceRegionHit {\n /** `Affordance.id` — also the chrome-caps visibility id. */\n affordanceId: string;\n /** `AffordanceRegion.id`. */\n regionId: string;\n /** The region itself, so callers can read `hitKind`. */\n region: AffordanceRegion;\n /** The region's cursor at the hit point. */\n cursor?: CursorSpec;\n /** Result of the region's `bind()`, called exactly once. */\n binding: AffordanceBinding;\n}\n\n/**\n * Walk affordances for a world-space hit, topmost first.\n *\n * **Across affordances**: order mirrors paint. Affordances are drawn first →\n * last (bottom → top), so the walk runs last → first and stops at the first\n * one that claims the point. Layering wins outright — a nearer region on a\n * lower affordance does not beat a farther one on top of it.\n *\n * **Within an affordance**: the *nearest* hit region wins, ties going to the\n * later-declared one. Regions overlap: the four corner handles of a selection\n * smaller than the hit radius all contain the same click.\n *\n * `isVisible` (when supplied) gates by the same chrome id used at paint time,\n * so chrome that isn't drawn can't be hit either.\n */\nexport function hitAffordanceRegions(\n affordances: readonly Affordance[],\n wx: number,\n wy: number,\n state: ChromeState,\n view: View,\n isVisible?: (id: string) => boolean,\n): AffordanceRegionHit | null {\n for (let i = affordances.length - 1; i >= 0; i--) {\n const a = affordances[i];\n if (isVisible && !isVisible(a.id)) continue;\n const regions = a.regions(state);\n let best: { region: AffordanceRegion; d2: number } | null = null;\n for (let j = 0; j < regions.length; j++) {\n const region = regions[j];\n const xf = transformOf(state, region.targetId);\n if (!hitRegion(region, wx, wy, xf, view)) continue;\n const d2 = regionDistance2(region, wx, wy, xf, view);\n // `<=` so a later-declared region wins an exact tie, preserving the\n // \"later is on top\" reading of declaration order.\n if (best === null || d2 <= best.d2) best = { region, d2 };\n }\n if (best) {\n const { cursor } = best.region;\n const at = typeof cursor === 'function' ? cursor({ x: wx, y: wy }, view) : cursor;\n return {\n affordanceId: a.id,\n regionId: best.region.id,\n region: best.region,\n ...(at !== undefined ? { cursor: at } : {}),\n binding: best.region.bind(),\n };\n }\n }\n return null;\n}\n\n/** Squared world distance from the point to a region's representative center,\n * used only to rank regions that all already contain the point. */\nfunction regionDistance2(\n region: AffordanceRegion,\n wx: number,\n wy: number,\n xf: TargetTransform,\n view: View,\n): number {\n const s = region.shape;\n if (s.kind === 'outline') return 0;\n const w = s.kind === 'point'\n ? pointRegionAnchor(s, xf, view)\n : s.kind === 'annulus'\n ? localToWorld(xf, s.cx, s.cy)\n : localToWorld(xf, s.x + s.width / 2, s.y + s.height / 2);\n const dx = w.x - wx;\n const dy = w.y - wy;\n return dx * dx + dy * dy;\n}\n\n// ─── Transform helpers ──────────────────────────────────────────────────────\n\nexport { angleOf, localToWorld, type TargetTransform };\n\n/** The frame `targetId`'s bounds are drawn in; identity for no target. */\nexport function transformOf(state: ChromeState, targetId: string | null): TargetTransform {\n if (targetId === null) return IDENTITY_TARGET;\n return targetTransformOf(state.boundsOf(targetId));\n}\n\n// ─── Shape resolution ───────────────────────────────────────────────────────\n\ntype PointShape = Extract<AffordanceRegion['shape'], { kind: 'point' }>;\n\n/** Where a point region's hit square sits: its center in world coords, its\n * turn on screen, its screen half-extent, and the span of the square that\n * takes a press along each of its own axes (`[-half, half]` unless\n * `cornerOf` cuts it). */\nexport function pointRegionFrame(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n): { x: number; y: number; angle: number; half: number; u: [number, number]; v: [number, number] } {\n const a = pointRegionAnchor(shape, xf, view);\n const angle = shape.turned ? screenAngleOf(angleOf(xf), view.scale) : 0;\n const half = shape.hitRadiusPx;\n const u: [number, number] = [-half, half];\n const v: [number, number] = [-half, half];\n const body = shape.cornerOf;\n if (body) {\n // The body in world units that spans four hit radii on screen, per axis.\n const floor = pxExtentIn(SMALL_BODY_RADII * half, view.scale, xf);\n // `v` runs a quarter turn on from `u` on screen, which is the target's +y\n // only while the view and the target's frame keep their handedness.\n const [a, b, c, d] = xf.toWorld;\n const vOut = body.outward.y * Math.sign(view.scale.x * view.scale.y * (a * d - b * c));\n if (body.width < floor.x) u[body.outward.x > 0 ? 0 : 1] = 0;\n if (body.height < floor.y) v[vOut > 0 ? 0 : 1] = 0;\n }\n return { x: a.x, y: a.y, angle, half, u, v };\n}\n\n/** A body under this many hit radii across gives up the inward half of each\n * corner's hit square, so there is somewhere on it that is not a handle. */\nconst SMALL_BODY_RADII = 4;\n\n/** A point region's hit square as four screen-space corners, relative to its\n * world center carried to the screen by `toScreen`. */\nexport function pointRegionScreenQuad(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n toScreen: (x: number, y: number) => [number, number],\n): { x: number; y: number }[] {\n const f = pointRegionFrame(shape, xf, view);\n const [cx, cy] = toScreen(f.x, f.y);\n const c = Math.cos(f.angle), sn = Math.sin(f.angle);\n return [[f.u[0], f.v[0]], [f.u[1], f.v[0]], [f.u[1], f.v[1]], [f.u[0], f.v[1]]].map(([u, v]) => ({\n x: cx + c * u - sn * v,\n y: cy + sn * u + c * v,\n }));\n}\n\n/** A point region's anchor in world coords, its `standoff` applied. */\nexport function pointRegionAnchor(\n shape: PointShape,\n xf: TargetTransform,\n view: View,\n): { x: number; y: number } {\n const a = localToWorld(xf, shape.x, shape.y);\n if (!shape.standoff) return a;\n return standoff(a, normalToWorld(xf, shape.standoff.normal), shape.standoff.px, view.scale);\n}\n\n/**\n * An annulus region's effective outer semi-axes, in world units, with the\n * screen-space `minBandPx` floor on band thickness applied. Paint calls it\n * too, so the visible ring and the hoverable ring are the same ring.\n */\nexport function annulusSemiAxes(\n shape: Extract<AffordanceRegion['shape'], { kind: 'annulus' }>,\n view: View,\n /** The target's frame, which decides what a screen pixel is along each of\n * its axes. */\n xf: TargetTransform = IDENTITY_TARGET,\n): { rx: number; ry: number } {\n const bandPx = shape.minBandPx ?? 0;\n if (bandPx === 0) return { rx: shape.rx, ry: shape.ry };\n const band = pxExtentIn(bandPx, view.scale, xf);\n return {\n rx: Math.max(shape.rx, shape.innerWidth / 2 + band.x),\n ry: Math.max(shape.ry, shape.innerHeight / 2 + band.y),\n };\n}\n\n// ─── Per-shape hit-test ─────────────────────────────────────────────────────\n\nfunction hitRegion(\n region: AffordanceRegion,\n wx: number,\n wy: number,\n xf: TargetTransform,\n view: View,\n): boolean {\n if (region.shape.kind === 'point') {\n // Square hit, not circular: the handle a `point` region paints is a\n // square, and a circle leaves its corners unclickable.\n //\n // Compared in screen space: testing it in the target's local frame would\n // stretch it under non-uniform zoom.\n const f = pointRegionFrame(region.shape, xf, view);\n const d = scaleDelta(wx - f.x, wy - f.y, view.scale);\n const c = Math.cos(f.angle), sn = Math.sin(f.angle);\n const u = c * d.x + sn * d.y, v = -sn * d.x + c * d.y;\n return u >= f.u[0] && u <= f.u[1] && v >= f.v[0] && v <= f.v[1];\n }\n const local = worldToLocal(xf, wx, wy);\n if (!local) return false;\n if (region.shape.kind === 'outline') {\n const s = region.shape;\n return strokeHitTest(s.path, local.x, local.y, 0, {\n slop: { px: s.hitRadiusPx, transform: multiply(scale(view.scale.x, view.scale.y), xf.toWorld) },\n });\n }\n if (region.shape.kind === 'annulus') {\n const s = region.shape;\n // Outside the inner-rect cutout?\n const insideInner =\n local.x >= s.innerX && local.x <= s.innerX + s.innerWidth &&\n local.y >= s.innerY && local.y <= s.innerY + s.innerHeight;\n if (insideInner) return false;\n // Inside the outer ellipse? `((x-cx)/rx)² + ((y-cy)/ry)² ≤ 1`.\n const { rx, ry } = annulusSemiAxes(s, view, xf);\n if (rx <= 0 || ry <= 0) return false;\n const ex = (local.x - s.cx) / rx;\n const ey = (local.y - s.cy) / ry;\n return ex * ex + ey * ey <= 1;\n }\n // rect: axis-aligned in local frame.\n const r = region.shape;\n return local.x >= r.x && local.x <= r.x + r.width\n && local.y >= r.y && local.y <= r.y + r.height;\n}\n"],"mappings":";;;AA4CA,SAAgBA,EACd,GACA,GACA,GACA,GACA,GACA,GAC4B;CAC5B,KAAK,IAAIC,IAAIC,EAAY,SAAS,GAAGD,KAAK,GAAG,KAAK;EAChD,IAAME,IAAID,EAAYD;EACtB,IAAIG,KAAa,CAACA,EAAUD,EAAE,EAAE,GAAG;EACnC,IAAME,IAAUF,EAAE,QAAQG,CAAK,GAC3BC,IAAwD;EAC5D,KAAK,IAAIC,IAAI,GAAGA,IAAIH,EAAQ,QAAQ,KAAK;GACvC,IAAMI,IAASJ,EAAQG,IACjBE,IAAKC,EAAYL,GAAOG,EAAO,QAAQ;GAC7C,IAAI,CAACG,EAAUH,GAAQI,GAAIC,GAAIJ,GAAIK,CAAI,GAAG;GAC1C,IAAMC,IAAKC,EAAgBR,GAAQI,GAAIC,GAAIJ,GAAIK,CAAI;GAGnD,CAAIR,MAAS,QAAQS,KAAMT,EAAK,QAAI,IAAO;IAAE;IAAQ;GAAG;EAC1D;EACA,IAAIA,GAAM;GACR,IAAM,EAAE,cAAWA,EAAK,QAClBW,IAAK,OAAOC,KAAW,aAAaA,EAAO;IAAE,GAAGN;IAAI,GAAGC;GAAG,GAAGC,CAAI,IAAII;GAC3E,OAAO;IACL,cAAchB,EAAE;IAChB,UAAUI,EAAK,OAAO;IACtB,QAAQA,EAAK;IACb,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KrC,EAAE,SAASA,EAAE,aAChC,OAAO;EAExB,IAAM,EAAE,OAAI,UAAOiC,EAAgBjC,GAAGL,GAAML,CAAE;EAC9C,IAAIoD,KAAM,KAAKC,KAAM,GAAG,OAAO;EAC/B,IAAMC,KAAMP,EAAM,IAAIrC,EAAE,MAAM0C,GACxBG,KAAMR,EAAM,IAAIrC,EAAE,MAAM2C;EAC9B,OAAOC,IAAKA,IAAKC,IAAKA,KAAM;CAC9B;CAEA,IAAMC,IAAIzD,EAAO;CACjB,OAAOgD,EAAM,KAAKS,EAAE,KAAKT,EAAM,KAAKS,EAAE,IAAIA,EAAE,SACrCT,EAAM,KAAKS,EAAE,KAAKT,EAAM,KAAKS,EAAE,IAAIA,EAAE;AAC9C"}
@@ -30,35 +30,57 @@ function n(n, r = {}) {
30
30
  targetId: t
31
31
  } })
32
32
  });
33
- return [{
34
- id: t,
35
- regions(t) {
36
- let r = n()?.editingId ?? null, i = [];
37
- for (let { id: n, path: a } of o(t)) if (r === null || n === r) for (let t of e(a)) i.push(s(`${n}:anchor:${t.anchorIndex}`, n, t.x, t.y, {
38
- targetId: n,
39
- anchorIndex: t.anchorIndex,
40
- part: "anchor"
41
- }, `anchor:${t.anchorIndex}`));
42
- return i;
43
- }
44
- }, {
45
- id: t,
46
- regions(t) {
47
- let r = n()?.editingId ?? null;
48
- if (r === null) return [];
49
- let i = [];
50
- for (let { id: n, path: a } of o(t)) if (n === r) for (let t of e(a)) t.controlIn && i.push(s(`${n}:controlIn:${t.anchorIndex}`, n, t.controlIn.x, t.controlIn.y, {
51
- targetId: n,
52
- anchorIndex: t.anchorIndex,
53
- part: "controlIn"
54
- }, `controlIn:${t.anchorIndex}`)), t.controlOut && i.push(s(`${n}:controlOut:${t.anchorIndex}`, n, t.controlOut.x, t.controlOut.y, {
55
- targetId: n,
56
- anchorIndex: t.anchorIndex,
57
- part: "controlOut"
58
- }, `controlOut:${t.anchorIndex}`));
59
- return i;
33
+ return [
34
+ {
35
+ id: t,
36
+ regions(e) {
37
+ let t = n()?.editingId ?? null;
38
+ if (t === null) return [];
39
+ let r = o(e).find(({ id: e }) => e === t);
40
+ return r ? [{
41
+ id: `${t}:segment`,
42
+ targetId: null,
43
+ shape: {
44
+ kind: "outline",
45
+ path: r.path,
46
+ hitRadiusPx: i
47
+ },
48
+ hitKind: "segment",
49
+ bind: () => ({ initialScratch: { targetId: t } })
50
+ }] : [];
51
+ }
52
+ },
53
+ {
54
+ id: t,
55
+ regions(t) {
56
+ let r = n()?.editingId ?? null, i = [];
57
+ for (let { id: n, path: a } of o(t)) if (r === null || n === r) for (let t of e(a)) i.push(s(`${n}:anchor:${t.anchorIndex}`, n, t.x, t.y, {
58
+ targetId: n,
59
+ anchorIndex: t.anchorIndex,
60
+ part: "anchor"
61
+ }, `anchor:${t.anchorIndex}`));
62
+ return i;
63
+ }
64
+ },
65
+ {
66
+ id: t,
67
+ regions(t) {
68
+ let r = n()?.editingId ?? null;
69
+ if (r === null) return [];
70
+ let i = [];
71
+ for (let { id: n, path: a } of o(t)) if (n === r) for (let t of e(a)) t.controlIn && i.push(s(`${n}:controlIn:${t.anchorIndex}`, n, t.controlIn.x, t.controlIn.y, {
72
+ targetId: n,
73
+ anchorIndex: t.anchorIndex,
74
+ part: "controlIn"
75
+ }, `controlIn:${t.anchorIndex}`)), t.controlOut && i.push(s(`${n}:controlOut:${t.anchorIndex}`, n, t.controlOut.x, t.controlOut.y, {
76
+ targetId: n,
77
+ anchorIndex: t.anchorIndex,
78
+ part: "controlOut"
79
+ }, `controlOut:${t.anchorIndex}`));
80
+ return i;
81
+ }
60
82
  }
61
- }];
83
+ ];
62
84
  }
63
85
  //#endregion
64
86
  export { t as PATH_ANCHOR_CHROME_ID, n as createPathAnchorAffordances };
@@ -1 +1 @@
1
- {"version":3,"file":"pathAnchors.js","names":["PATH_ANCHOR_CHROME_ID","createPathAnchorAffordances","opts","editablePaths","anchorState","getAnchorState","out","id","state","pose","point","hitRadius","scratch","editingId","a","enumerateAnchors","path"],"sources":["../../src/affordances/pathAnchors.ts"],"sourcesContent":["/** Path anchor + control-handle affordances. */\n\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from './types';\nimport type { ChromeState } from 'core/selection/chromeState';\nimport type { PolygonPath } from '@weasel-js/geom';\nimport { enumerateAnchors } from 'interactions/actions/edit-anchors/geometry';\n\n/**\n * Live anchor-editing state. The thunk that returns it is called on every\n * pointer event, so it must be cheap (O(1) field reads).\n */\nexport interface AnchorState {\n /** Id of the path currently in anchor-edit mode, or `null`. Control handles\n * are only hittable on the path that is being edited. */\n editingId: string | null;\n /** Current editable path for a node id. Non-polygon values are ignored. */\n getPose(id: string): unknown;\n}\n\n/** Options for the path-anchor affordances. */\nexport interface PathAnchorAffordanceOptions {\n /** Hit radius (screen-px) for anchor and control points. Default 8. */\n hitRadius?: number;\n /** Cursor while hovering an anchor or control. Defaults to `'pointer'`. */\n cursor?: CursorSpec;\n}\n\n/** What an anchor hit hands to the action that follows. */\nexport interface AnchorScratch extends CommonAffordanceScratch {\n /** Node id of the path the anchor belongs to. */\n targetId: string;\n /** Sequential anchor index in path walk order. */\n anchorIndex: number;\n /** Which of the anchor's three grabbable points this is. */\n part: 'anchor' | 'controlIn' | 'controlOut';\n}\n\n/** Chrome-caps id gating both returned affordances. */\nexport const PATH_ANCHOR_CHROME_ID = 'path-edit.anchors';\n\n/**\n * Anchor + control affordances for the selected paths, bottom → top.\n *\n * Returns **two** affordances rather than one so that a control handle beats\n * an anchor regardless of which is nearer, the way controls draw on top.\n * Within each of the two, nearest wins. They deliberately share one id:\n * chrome-caps gates anchor editing as a single piece of chrome.\n *\n * Order matters — spread this into an affordance list in the returned order.\n */\nexport function createPathAnchorAffordances(\n getAnchorState: () => AnchorState | null,\n opts: PathAnchorAffordanceOptions = {},\n): Affordance[] {\n const { hitRadius = 8, cursor = 'pointer' } = opts;\n\n /** Selected polygon paths, paired with their node id. */\n const editablePaths = (state: ChromeState): Array<{ id: string; path: PolygonPath }> => {\n const anchorState = getAnchorState();\n if (!anchorState) return [];\n const out: Array<{ id: string; path: PolygonPath }> = [];\n for (const id of state.selection) {\n const pose = anchorState.getPose(id);\n if (!pose || (pose as { kind?: string }).kind !== 'polygon') continue;\n out.push({ id, path: pose as PolygonPath });\n }\n return out;\n };\n\n const point = (\n id: string,\n targetId: string,\n x: number,\n y: number,\n scratch: AnchorScratch,\n hitKind: string,\n ): AffordanceRegion => ({\n id,\n // Anchor coordinates are already world space, pose rotation baked in.\n // Anchoring to `null` keeps the framework from applying it twice.\n targetId: null,\n shape: { kind: 'point', x, y, hitRadiusPx: hitRadius },\n hitKind,\n cursor,\n bind: (): AffordanceBinding => ({ initialScratch: { ...scratch, targetId } }),\n });\n\n const anchors: Affordance = {\n id: PATH_ANCHOR_CHROME_ID,\n regions(state) {\n const editingId = getAnchorState()?.editingId ?? null;\n const out: AffordanceRegion[] = [];\n for (const { id, path } of editablePaths(state)) {\n // `editAnchorsAction` edits whatever path the dep says is in edit\n // mode, ignoring which one was hit — so once a path IS being edited,\n // only its own anchors may claim the press.\n if (editingId !== null && id !== editingId) continue;\n for (const a of enumerateAnchors(path)) {\n out.push(point(\n `${id}:anchor:${a.anchorIndex}`,\n id, a.x, a.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'anchor' },\n `anchor:${a.anchorIndex}`,\n ));\n }\n }\n return out;\n },\n };\n\n const controls: Affordance = {\n id: PATH_ANCHOR_CHROME_ID,\n regions(state) {\n const anchorState = getAnchorState();\n const editingId = anchorState?.editingId ?? null;\n if (editingId === null) return [];\n const out: AffordanceRegion[] = [];\n for (const { id, path } of editablePaths(state)) {\n // Controls are grabbable only on the path actually in edit mode.\n if (id !== editingId) continue;\n for (const a of enumerateAnchors(path)) {\n if (a.controlIn) {\n out.push(point(\n `${id}:controlIn:${a.anchorIndex}`,\n id, a.controlIn.x, a.controlIn.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'controlIn' },\n `controlIn:${a.anchorIndex}`,\n ));\n }\n if (a.controlOut) {\n out.push(point(\n `${id}:controlOut:${a.anchorIndex}`,\n id, a.controlOut.x, a.controlOut.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'controlOut' },\n `controlOut:${a.anchorIndex}`,\n ));\n }\n }\n }\n return out;\n },\n };\n\n return [anchors, controls];\n}\n"],"mappings":";;AAuCA,IAAaA,IAAwB;AAYrC,SAAgBC,EACd,GACA,IAAoC,CAAC,GACvB;CACd,IAAM,EAAE,eAAY,GAAG,YAAS,cAAcC,GAGxCC,KAAiB,MAAiE;EACtF,IAAMC,IAAcC,EAAe;EACnC,IAAI,CAACD,GAAa,OAAO,CAAC;EAC1B,IAAME,IAAgD,CAAC;EACvD,KAAK,IAAMC,KAAMC,EAAM,WAAW;GAChC,IAAMC,IAAOL,EAAY,QAAQG,CAAE;GACnC,AAAKE,KAASA,EAA2B,SAAS,aAClDH,EAAI,KAAK;IAAE;IAAI,MAAMG;GAAoB,CAAC;EAC5C;EACA,OAAOH;CACT,GAEMI,KACJ,GACA,GACA,GACA,GACA,GACA,OACsB;EACtB;EAGA,UAAU;EACV,OAAO;GAAE,MAAM;GAAS;GAAG;GAAG,aAAaC;EAAU;EACrD;EACA;EACA,aAAgC,EAAE,gBAAgB;GAAE,GAAGC;GAAS;EAAS,EAAE;CAC7E;CA0DA,OAAO,CAAC;EAvDN,IAAIZ;EACJ,QAAQ,GAAO;GACb,IAAMa,IAAYR,EAAe,CAAC,EAAE,aAAa,MAC3CC,IAA0B,CAAC;GACjC,KAAK,IAAM,EAAE,OAAI,aAAUH,EAAcK,CAAK,GAI5C,IAAIK,MAAc,QAAQN,MAAOM,GACjC,KAAK,IAAMC,KAAKC,EAAiBC,CAAI,GACnC,EAAI,KAAKN,EACP,GAAGH,EAAG,UAAUO,EAAE,eAClBP,GAAIO,EAAE,GAAGA,EAAE,GACX;IAAE,UAAUP;IAAI,aAAaO,EAAE;IAAa,MAAM;GAAS,GAC3D,UAAUA,EAAE,aACd,CAAC;GAGL,OAAOR;EACT;CAoCM,GAAS;EAhCf,IAAIN;EACJ,QAAQ,GAAO;GAEb,IAAMa,IADcR,EACF,CAAA,EAAa,aAAa;GAC5C,IAAIQ,MAAc,MAAM,OAAO,CAAC;GAChC,IAAMP,IAA0B,CAAC;GACjC,KAAK,IAAM,EAAE,OAAI,aAAUH,EAAcK,CAAK,GAE5C,IAAID,MAAOM,GACX,KAAK,IAAMC,KAAKC,EAAiBC,CAAI,GASnC,AARIF,EAAE,aACJR,EAAI,KAAKI,EACP,GAAGH,EAAG,aAAaO,EAAE,eACrBP,GAAIO,EAAE,UAAU,GAAGA,EAAE,UAAU,GAC/B;IAAE,UAAUP;IAAI,aAAaO,EAAE;IAAa,MAAM;GAAY,GAC9D,aAAaA,EAAE,aACjB,CAAC,GAECA,EAAE,cACJR,EAAI,KAAKI,EACP,GAAGH,EAAG,cAAcO,EAAE,eACtBP,GAAIO,EAAE,WAAW,GAAGA,EAAE,WAAW,GACjC;IAAE,UAAUP;IAAI,aAAaO,EAAE;IAAa,MAAM;GAAa,GAC/D,cAAcA,EAAE,aAClB,CAAC;GAIP,OAAOR;EACT;CAGe,CAAQ;AAC3B"}
1
+ {"version":3,"file":"pathAnchors.js","names":["PATH_ANCHOR_CHROME_ID","createPathAnchorAffordances","opts","editablePaths","anchorState","getAnchorState","out","id","state","pose","point","hitRadius","scratch","editingId","edited","a","enumerateAnchors","path"],"sources":["../../src/affordances/pathAnchors.ts"],"sourcesContent":["/** Path anchor, control-handle, and segment affordances. */\n\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from './types';\nimport type { ChromeState } from 'core/selection/chromeState';\nimport type { PolygonPath } from '@weasel-js/geom';\nimport { enumerateAnchors } from 'interactions/actions/edit-anchors/geometry';\n\n/**\n * Live anchor-editing state. The thunk that returns it is called on every\n * pointer event, so it must be cheap (O(1) field reads).\n */\nexport interface AnchorState {\n /** Id of the path currently in anchor-edit mode, or `null`. Control handles\n * are only hittable on the path that is being edited. */\n editingId: string | null;\n /** Current editable path for a node id. Non-polygon values are ignored. */\n getPose(id: string): unknown;\n}\n\n/** Options for the path-anchor affordances. */\nexport interface PathAnchorAffordanceOptions {\n /** Hit radius (screen-px) for anchor and control points. Default 8. */\n hitRadius?: number;\n /** Cursor while hovering an anchor or control. Defaults to `'pointer'`. */\n cursor?: CursorSpec;\n}\n\n/** What an anchor hit hands to the action that follows. */\nexport interface AnchorScratch extends CommonAffordanceScratch {\n /** Node id of the path the anchor belongs to. */\n targetId: string;\n /** Sequential anchor index in path walk order. */\n anchorIndex: number;\n /** Which of the anchor's three grabbable points this is. */\n part: 'anchor' | 'controlIn' | 'controlOut';\n}\n\n/** Chrome-caps id gating every returned affordance. */\nexport const PATH_ANCHOR_CHROME_ID = 'path-edit.anchors';\n\n/**\n * Segment, anchor, and control affordances for the selected paths, bottom →\n * top.\n *\n * Three affordances rather than one, so that a control handle beats an anchor\n * regardless of which is nearer, the way controls draw on top, and both beat\n * the segment they sit on. Within each, nearest wins. A press on the edited\n * path's outline is a `segment` hit, which the segment bend binds to and a\n * selection move turns down. They deliberately share one id: chrome-caps\n * gates anchor editing as a single piece of chrome.\n *\n * Order matters — spread this into an affordance list in the returned order.\n */\nexport function createPathAnchorAffordances(\n getAnchorState: () => AnchorState | null,\n opts: PathAnchorAffordanceOptions = {},\n): Affordance[] {\n const { hitRadius = 8, cursor = 'pointer' } = opts;\n\n /** Selected polygon paths, paired with their node id. */\n const editablePaths = (state: ChromeState): Array<{ id: string; path: PolygonPath }> => {\n const anchorState = getAnchorState();\n if (!anchorState) return [];\n const out: Array<{ id: string; path: PolygonPath }> = [];\n for (const id of state.selection) {\n const pose = anchorState.getPose(id);\n if (!pose || (pose as { kind?: string }).kind !== 'polygon') continue;\n out.push({ id, path: pose as PolygonPath });\n }\n return out;\n };\n\n const point = (\n id: string,\n targetId: string,\n x: number,\n y: number,\n scratch: AnchorScratch,\n hitKind: string,\n ): AffordanceRegion => ({\n id,\n // Anchor coordinates are already world space, pose rotation baked in.\n // Anchoring to `null` keeps the framework from applying it twice.\n targetId: null,\n shape: { kind: 'point', x, y, hitRadiusPx: hitRadius },\n hitKind,\n cursor,\n bind: (): AffordanceBinding => ({ initialScratch: { ...scratch, targetId } }),\n });\n\n const anchors: Affordance = {\n id: PATH_ANCHOR_CHROME_ID,\n regions(state) {\n const editingId = getAnchorState()?.editingId ?? null;\n const out: AffordanceRegion[] = [];\n for (const { id, path } of editablePaths(state)) {\n // `editAnchorsAction` edits whatever path the dep says is in edit\n // mode, ignoring which one was hit — so once a path IS being edited,\n // only its own anchors may claim the press.\n if (editingId !== null && id !== editingId) continue;\n for (const a of enumerateAnchors(path)) {\n out.push(point(\n `${id}:anchor:${a.anchorIndex}`,\n id, a.x, a.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'anchor' },\n `anchor:${a.anchorIndex}`,\n ));\n }\n }\n return out;\n },\n };\n\n const controls: Affordance = {\n id: PATH_ANCHOR_CHROME_ID,\n regions(state) {\n const anchorState = getAnchorState();\n const editingId = anchorState?.editingId ?? null;\n if (editingId === null) return [];\n const out: AffordanceRegion[] = [];\n for (const { id, path } of editablePaths(state)) {\n // Controls are grabbable only on the path actually in edit mode.\n if (id !== editingId) continue;\n for (const a of enumerateAnchors(path)) {\n if (a.controlIn) {\n out.push(point(\n `${id}:controlIn:${a.anchorIndex}`,\n id, a.controlIn.x, a.controlIn.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'controlIn' },\n `controlIn:${a.anchorIndex}`,\n ));\n }\n if (a.controlOut) {\n out.push(point(\n `${id}:controlOut:${a.anchorIndex}`,\n id, a.controlOut.x, a.controlOut.y,\n { targetId: id, anchorIndex: a.anchorIndex, part: 'controlOut' },\n `controlOut:${a.anchorIndex}`,\n ));\n }\n }\n }\n return out;\n },\n };\n\n const segments: Affordance = {\n id: PATH_ANCHOR_CHROME_ID,\n regions(state) {\n const editingId = getAnchorState()?.editingId ?? null;\n if (editingId === null) return [];\n const edited = editablePaths(state).find(({ id }) => id === editingId);\n if (!edited) return [];\n return [{\n id: `${editingId}:segment`,\n targetId: null,\n shape: { kind: 'outline', path: edited.path, hitRadiusPx: hitRadius },\n hitKind: 'segment',\n bind: (): AffordanceBinding => ({ initialScratch: { targetId: editingId } }),\n }];\n },\n };\n\n return [segments, anchors, controls];\n}\n"],"mappings":";;AAuCA,IAAaA,IAAwB;AAerC,SAAgBC,EACd,GACA,IAAoC,CAAC,GACvB;CACd,IAAM,EAAE,eAAY,GAAG,YAAS,cAAcC,GAGxCC,KAAiB,MAAiE;EACtF,IAAMC,IAAcC,EAAe;EACnC,IAAI,CAACD,GAAa,OAAO,CAAC;EAC1B,IAAME,IAAgD,CAAC;EACvD,KAAK,IAAMC,KAAMC,EAAM,WAAW;GAChC,IAAMC,IAAOL,EAAY,QAAQG,CAAE;GACnC,AAAKE,KAASA,EAA2B,SAAS,aAClDH,EAAI,KAAK;IAAE;IAAI,MAAMG;GAAoB,CAAC;EAC5C;EACA,OAAOH;CACT,GAEMI,KACJ,GACA,GACA,GACA,GACA,GACA,OACsB;EACtB;EAGA,UAAU;EACV,OAAO;GAAE,MAAM;GAAS;GAAG;GAAG,aAAaC;EAAU;EACrD;EACA;EACA,aAAgC,EAAE,gBAAgB;GAAE,GAAGC;GAAS;EAAS,EAAE;CAC7E;CA2EA,OAAO;EAAC;GAhBN,IAAIZ;GACJ,QAAQ,GAAO;IACb,IAAMa,IAAYR,EAAe,CAAC,EAAE,aAAa;IACjD,IAAIQ,MAAc,MAAM,OAAO,CAAC;IAChC,IAAMC,IAASX,EAAcK,CAAK,CAAC,CAAC,MAAM,EAAE,YAASD,MAAOM,CAAS;IAErE,OADKC,IACE,CAAC;KACN,IAAI,GAAGD,EAAU;KACjB,UAAU;KACV,OAAO;MAAE,MAAM;MAAW,MAAMC,EAAO;MAAM,aAAaH;KAAU;KACpE,SAAS;KACT,aAAgC,EAAE,gBAA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 //#region src/affordances/rotateCursor.ts
2
+ function e(e, t, n) {
3
+ return {
4
+ glyph: "rotate",
5
+ angle: Math.atan2((t.x - e.x) * n.x, -(t.y - e.y) * n.y),
6
+ fallback: "grab"
7
+ };
8
+ }
9
+ //#endregion
10
+ export { e as rotateCursorAt };
11
+
12
+ //# sourceMappingURL=rotateCursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotateCursor.js","names":["rotateCursorAt","at","pivot","scale"],"sources":["../../src/affordances/rotateCursor.ts"],"sourcesContent":["import type { CursorSpec } from '@weasel-js/cursor';\nimport type { Scale2 } from '@weasel-js/geom';\n\n/**\n * The `rotate` glyph for a pointer at world point `at` turning something\n * about world point `pivot`, seen through a view of `scale`. The glyph's arc\n * is drawn over the top of its box, so its up points from the pivot to the\n * pointer and the opening faces what is being turned.\n */\nexport function rotateCursorAt(\n pivot: { x: number; y: number },\n at: { x: number; y: number },\n scale: Scale2,\n): CursorSpec {\n return {\n glyph: 'rotate',\n angle: Math.atan2((at.x - pivot.x) * scale.x, -(at.y - pivot.y) * scale.y),\n fallback: 'grab',\n };\n}\n"],"mappings":";AASA,SAAgBA,EACd,GACA,GACA,GACY;CACZ,OAAO;EACL,OAAO;EACP,OAAO,KAAK,OAAOC,EAAG,IAAIC,EAAM,KAAKC,EAAM,GAAG,EAAEF,EAAG,IAAIC,EAAM,KAAKC,EAAM,CAAC;EACzE,UAAU;CACZ;AACF"}
@@ -1,69 +1,66 @@
1
- import { angleOf as e } from "../core/geometry/targetFrame.js";
1
+ import { localToWorld as e } from "../core/geometry/targetFrame.js";
2
2
  import { transformOf as t } from "./hitAffordanceRegions.js";
3
3
  import { MULTI_RESIZE_TARGET_ID as n } from "../core/selection/selectionTarget.js";
4
+ import { rotateCursorAt as r } from "./rotateCursor.js";
4
5
  //#region src/affordances/rotationHandle.ts
5
- var r = (e) => "fill" in e || "stroke" in e || "insetPx" in e, i = {
6
+ var i = (e) => "fill" in e || "stroke" in e || "insetPx" in e, a = {
6
7
  fill: { paint: {
7
8
  kind: "solid",
8
9
  color: "rgba(26, 19, 13, 0.12)"
9
10
  } },
10
11
  insetPx: 10
11
12
  };
12
- function a(n = {}) {
13
- let { bandPx: a = 24, paint: s = i, cursor: c, handle: l } = n, u = s ? r(s) ? {
13
+ function o(n = {}) {
14
+ let { bandPx: o = 24, paint: c = a, cursor: l, handle: u } = n, d = c ? i(c) ? {
14
15
  kind: "annulus",
15
- ...s.fill ? { fill: s.fill } : {},
16
- ...s.stroke ? { stroke: s.stroke } : {},
17
- ...s.insetPx === void 0 ? {} : { insetPx: s.insetPx }
16
+ ...c.fill ? { fill: c.fill } : {},
17
+ ...c.stroke ? { stroke: c.stroke } : {},
18
+ ...c.insetPx === void 0 ? {} : { insetPx: c.insetPx }
18
19
  } : {
19
20
  kind: "annulus",
20
- stroke: s
21
+ stroke: c
21
22
  } : null;
22
23
  return {
23
24
  id: "selection.rotation-handle",
24
25
  regions(n) {
25
- let r = o(n);
26
- if (!r) return [];
27
- let i = r.bounds, s = i.width / 2, d = i.height / 2, f = c ?? {
28
- glyph: "rotate",
29
- angle: e(t(n, r.id)),
30
- fallback: "grab"
31
- }, p = () => ({ initialScratch: {
32
- targetId: r.id,
26
+ let i = s(n);
27
+ if (!i) return [];
28
+ let a = i.bounds, c = a.width / 2, f = a.height / 2, p = e(t(n, i.id), a.x + c, a.y + f), m = l ?? ((e, t) => r(p, e, t.scale)), h = () => ({ initialScratch: {
29
+ targetId: i.id,
33
30
  fixedPoint: {
34
- x: i.x + s,
35
- y: i.y + d
31
+ x: a.x + c,
32
+ y: a.y + f
36
33
  }
37
- } }), m = {
34
+ } }), g = {
38
35
  id: "selection.rotation-handle",
39
- targetId: r.id,
36
+ targetId: i.id,
40
37
  shape: {
41
38
  kind: "annulus",
42
- cx: i.x + s,
43
- cy: i.y + d,
44
- rx: s * Math.SQRT2,
45
- ry: d * Math.SQRT2,
46
- innerX: i.x,
47
- innerY: i.y,
48
- innerWidth: i.width,
49
- innerHeight: i.height,
50
- minBandPx: a
39
+ cx: a.x + c,
40
+ cy: a.y + f,
41
+ rx: c * Math.SQRT2,
42
+ ry: f * Math.SQRT2,
43
+ innerX: a.x,
44
+ innerY: a.y,
45
+ innerWidth: a.width,
46
+ innerHeight: a.height,
47
+ minBandPx: o
51
48
  },
52
- ...u ? { paint: u } : {},
49
+ ...d ? { paint: d } : {},
53
50
  hitKind: "rotate-handle",
54
- cursor: f,
55
- bind: p
51
+ cursor: m,
52
+ bind: h
56
53
  };
57
- return l ? [m, {
54
+ return u ? [g, {
58
55
  id: "rotation-badge",
59
- targetId: r.id,
56
+ targetId: i.id,
60
57
  shape: {
61
58
  kind: "point",
62
- x: i.x + s,
63
- y: i.y,
64
- hitRadiusPx: l.hitRadiusPx,
59
+ x: a.x + c,
60
+ y: a.y,
61
+ hitRadiusPx: u.hitRadiusPx,
65
62
  standoff: {
66
- px: l.distancePx,
63
+ px: u.distancePx,
67
64
  normal: {
68
65
  x: 0,
69
66
  y: -1
@@ -71,13 +68,13 @@ function a(n = {}) {
71
68
  }
72
69
  },
73
70
  hitKind: "rotate-handle",
74
- cursor: f,
75
- bind: p
76
- }] : [m];
71
+ cursor: m,
72
+ bind: h
73
+ }] : [g];
77
74
  }
78
75
  };
79
76
  }
80
- function o(e) {
77
+ function s(e) {
81
78
  if (e.selection.length === 1) {
82
79
  let t = e.selection[0];
83
80
  if (e.canRotate && !e.canRotate(t)) return null;
@@ -99,6 +96,6 @@ function o(e) {
99
96
  return null;
100
97
  }
101
98
  //#endregion
102
- export { a as createRotationAffordance };
99
+ export { o as createRotationAffordance };
103
100
 
104
101
  //# sourceMappingURL=rotationHandle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rotationHandle.js","names":["isAnnulusForm","paint","DEFAULT_PAINT","createRotationAffordance","opts","annulusPaint","target","pickTarget","state","b","halfW","halfH","regionCursor","cursor","angleOf","transformOf","bind","region","bandPx","handle","id","MULTI_RESIZE_TARGET_ID"],"sources":["../../src/affordances/rotationHandle.ts"],"sourcesContent":["import type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from './types';\nimport type { ChromeState, Bounds } from 'core/selection/chromeState';\nimport type { CommandStroke, CommandFill } from '@weasel-js/paint';\nimport { MULTI_RESIZE_TARGET_ID } from 'core/selection/selectionTarget';\nimport { angleOf, transformOf } from './hitAffordanceRegions';\nimport type { CursorSpec } from '@weasel-js/cursor';\n\n/** Options for `createRotationAffordance` — how thick the rotate band is\n * outside the selection, and how (or whether) it is painted. */\nexport interface RotationAffordanceOptions {\n /** Minimum screen-space thickness of the rotate-zone band outside the selection AABB, so\n * the zone stays hoverable at any zoom and any selection size. Default 24. */\n bandPx?: number;\n /** Paint for the ring. `null` / `false` = invisible. Default is a semi-transparent fill of\n * the band, contracted by `insetPx` screen pixels on the outer edge. Pass a `Stroke` (or\n * `{ fill, stroke, insetPx }`) to override. */\n paint?:\n | CommandStroke\n | { fill?: CommandFill; stroke?: CommandStroke; insetPx?: number }\n | null\n | false;\n /** Cursor while hovering the ring. Defaults to the `rotate` glyph turned\n * with the target, falling back to `'grab'` if the browser rejects the\n * image. */\n cursor?: CursorSpec;\n /** A grab region for a rotate badge painted off the top edge — the one\n * the selection overlay's `rotationHandle` draws. `distancePx` is how far\n * off the edge it sits and `hitRadiusPx` the half-extent of its square,\n * both in screen pixels. Placed by the same `standoff` the painted badge\n * is, so the two cannot drift apart. Omitted, only the ring rotates. */\n handle?: { distancePx: number; hitRadiusPx: number };\n}\n\n/** What a rotation-handle hit hands to the rotate action: what is being\n * rotated, and the world-space pivot it turns around. */\nexport interface RotationScratch extends CommonAffordanceScratch {\n /** Id of the rotation target — single selection id, or\n * `MULTI_RESIZE_TARGET_ID` for multi-selection. */\n targetId: string;\n /** Rotation pivot in world coords — the AABB (or union AABB) center. */\n fixedPoint: { x: number; y: number };\n}\n\ntype AnnulusPaintForm = { fill?: CommandFill; stroke?: CommandStroke; insetPx?: number };\n\nconst isAnnulusForm = (paint: CommandStroke | AnnulusPaintForm): paint is AnnulusPaintForm =>\n 'fill' in paint || 'stroke' in paint || 'insetPx' in paint;\n\nconst DEFAULT_PAINT: AnnulusPaintForm = {\n fill: { paint: { kind: 'solid', color: 'rgba(26, 19, 13, 0.12)' } },\n insetPx: 10,\n};\n\n/**\n * @experimental\n * Rotation affordance for the active selection: an elliptical ring that wraps the selection —\n * the smallest ellipse containing the AABB, minus the AABB itself. Hovering the ring sets the\n * cursor (default the `rotate` glyph) and a drag from it triggers `rotateAction`.\n *\n * The ring is target-local — under target rotation the ellipse rotates with the AABB.\n * Visibility is gated by chrome-caps' `'selection.rotation-handle'` rule. `paint: null` leaves\n * the cursor change as the only cue.\n */\nexport function createRotationAffordance(\n opts: RotationAffordanceOptions = {},\n): Affordance {\n const { bandPx = 24, paint = DEFAULT_PAINT, cursor, handle } = opts;\n\n // A bare `Stroke` carries none of the object form's three keys, and cannot be told apart\n // by its own `paint` since that is optional.\n const annulusPaint:\n | { kind: 'annulus'; fill?: CommandFill; stroke?: CommandStroke; insetPx?: number }\n | null = (() => {\n if (!paint) return null;\n if (!isAnnulusForm(paint)) {\n return { kind: 'annulus' as const, stroke: paint };\n }\n return {\n kind: 'annulus' as const,\n ...(paint.fill ? { fill: paint.fill } : {}),\n ...(paint.stroke ? { stroke: paint.stroke } : {}),\n ...(paint.insetPx !== undefined ? { insetPx: paint.insetPx } : {}),\n };\n })();\n\n return {\n id: 'selection.rotation-handle',\n regions(state: ChromeState): readonly AffordanceRegion[] {\n const target = pickTarget(state);\n if (!target) return [];\n const b = target.bounds;\n\n // The natural ring is the smallest ellipse containing the AABB. `minBandPx` asks the\n // framework to widen it to at least `bandPx` screen pixels outside the rect; the floor is\n // declared in screen units because `ChromeState` carries no view scale.\n const halfW = b.width / 2;\n const halfH = b.height / 2;\n\n // Turned with the target, so the arc follows the selection it rotates.\n const regionCursor: CursorSpec = cursor ?? {\n glyph: 'rotate',\n angle: angleOf(transformOf(state, target.id)),\n fallback: 'grab',\n };\n const bind = (): AffordanceBinding => ({\n initialScratch: {\n targetId: target.id,\n // Pivot. `rotateAction` recomputes its own union pivot for\n // multi-selection, but the single-target case reads this.\n fixedPoint: { x: b.x + halfW, y: b.y + halfH },\n } satisfies RotationScratch,\n });\n\n const region: AffordanceRegion = {\n id: 'selection.rotation-handle',\n targetId: target.id,\n shape: {\n kind: 'annulus',\n cx: b.x + halfW,\n cy: b.y + halfH,\n rx: halfW * Math.SQRT2,\n ry: halfH * Math.SQRT2,\n innerX: b.x,\n innerY: b.y,\n innerWidth: b.width,\n innerHeight: b.height,\n minBandPx: bandPx,\n },\n ...(annulusPaint ? { paint: annulusPaint } : {}),\n hitKind: 'rotate-handle',\n cursor: regionCursor,\n bind,\n };\n if (!handle) return [region];\n const badge: AffordanceRegion = {\n id: 'rotation-badge',\n targetId: target.id,\n shape: {\n kind: 'point',\n x: b.x + halfW,\n y: b.y,\n hitRadiusPx: handle.hitRadiusPx,\n standoff: { px: handle.distancePx, normal: { x: 0, y: -1 } },\n },\n hitKind: 'rotate-handle',\n cursor: regionCursor,\n bind,\n };\n return [region, badge];\n },\n };\n}\n\nfunction pickTarget(state: ChromeState): { id: string; bounds: Bounds } | null {\n if (state.selection.length === 1) {\n const id = state.selection[0];\n // Skip when the selected node's pose-descriptor declares it can't carry a rotation;\n // otherwise the ring would offer a rotate cursor over a node whose write is dropped.\n if (state.canRotate && !state.canRotate(id)) return null;\n const b = state.boundsOf(id);\n return b ? { id, bounds: b } : null;\n }\n // Multi-selection: anchor the ring to the union AABB; `rotateAction` ignores the synthetic\n // id and pivots at its own union center. Every selected id must support rotation — a\n // partial multi-rotate would feel broken.\n if (state.multiActive && state.unionBounds) {\n if (state.canRotate) {\n for (const id of state.selection) {\n if (!state.canRotate(id)) return null;\n }\n }\n return { id: MULTI_RESIZE_TARGET_ID, bounds: state.unionBounds };\n }\n return null;\n}\n"],"mappings":";;;;AA6CA,IAAMA,KAAiB,MACrB,UAAUC,KAAS,YAAYA,KAAS,aAAaA,GAEjDC,IAAkC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,SAAS;IACT,QAAQO;IACR;GACF;GAgBA,OAfKO,IAeE,CAACF,GAAQ;IAbd,IAAI;IACJ,UAAUX,EAAO;IACjB,OAAO;KACL,MAAM;KACN,GAAGG,EAAE,IAAIC;KACT,GAAGD,EAAE;KACL,aAAaU,EAAO;KACpB,UAAU;MAAE,IAAIA,EAAO;MAAY,QAAQ;OAAE,GAAG;OAAG,GAAG;MAAG;KAAE;IAC7D;IACA,SAAS;IACT,QAAQP;IACR;GAEc,CAAK,IAfD,CAACK,CAAM;EAgB7B;CACF;AACF;AAEA,SAASV,EAAW,GAA2D;CAC7E,IAAIC,EAAM,UAAU,WAAW,GAAG;EAChC,IAAMY,IAAKZ,EAAM,UAAU;EAG3B,IAAIA,EAAM,aAAa,CAACA,EAAM,UAAUY,CAAE,GAAG,OAAO;EACpD,IAAMX,IAAID,EAAM,SAASY,CAAE;EAC3B,OAAOX,IAAI;GAAE;GAAI,QAAQA;EAAE,IAAI;CACjC;CAIA,IAAID,EAAM,eAAeA,EAAM,aAAa;EAC1C,IAAIA,EAAM,WACH;QAAA,IAAMY,KAAMZ,EAAM,WACrB,IAAI,CAACA,EAAM,UAAUY,CAAE,GAAG,OAAO;EAAA;EAGrC,OAAO;GAAE,IAAIC;GAAwB,QAAQb,EAAM;EAAY;CACjE;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"rotationHandle.js","names":["isAnnulusForm","paint","DEFAULT_PAINT","createRotationAffordance","opts","annulusPaint","target","pickTarget","state","b","halfW","halfH","pivot","localToWorld","transformOf","regionCursor","cursor","rotateCursorAt","at","view","bind","region","bandPx","handle","id","MULTI_RESIZE_TARGET_ID"],"sources":["../../src/affordances/rotationHandle.ts"],"sourcesContent":["import type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from './types';\nimport type { ChromeState, Bounds } from 'core/selection/chromeState';\nimport type { CommandStroke, CommandFill } from '@weasel-js/paint';\nimport { MULTI_RESIZE_TARGET_ID } from 'core/selection/selectionTarget';\nimport { localToWorld, transformOf } from './hitAffordanceRegions';\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport { rotateCursorAt } from './rotateCursor';\n\n/** Options for `createRotationAffordance` — how thick the rotate band is\n * outside the selection, and how (or whether) it is painted. */\nexport interface RotationAffordanceOptions {\n /** Minimum screen-space thickness of the rotate-zone band outside the selection AABB, so\n * the zone stays hoverable at any zoom and any selection size. Default 24. */\n bandPx?: number;\n /** Paint for the ring. `null` / `false` = invisible. Default is a semi-transparent fill of\n * the band, contracted by `insetPx` screen pixels on the outer edge. Pass a `Stroke` (or\n * `{ fill, stroke, insetPx }`) to override. */\n paint?:\n | CommandStroke\n | { fill?: CommandFill; stroke?: CommandStroke; insetPx?: number }\n | null\n | false;\n /** Cursor while hovering the ring. Defaults to the `rotate` glyph turned\n * square to the line from the pivot to the pointer, falling back to\n * `'grab'` if the browser rejects the image. */\n cursor?: CursorSpec;\n /** A grab region for a rotate badge painted off the top edge — the one\n * the selection overlay's `rotationHandle` draws. `distancePx` is how far\n * off the edge it sits and `hitRadiusPx` the half-extent of its square,\n * both in screen pixels. Placed by the same `standoff` the painted badge\n * is, so the two cannot drift apart. Omitted, only the ring rotates. */\n handle?: { distancePx: number; hitRadiusPx: number };\n}\n\n/** What a rotation-handle hit hands to the rotate action: what is being\n * rotated, and the world-space pivot it turns around. */\nexport interface RotationScratch extends CommonAffordanceScratch {\n /** Id of the rotation target — single selection id, or\n * `MULTI_RESIZE_TARGET_ID` for multi-selection. */\n targetId: string;\n /** Rotation pivot in world coords — the AABB (or union AABB) center. */\n fixedPoint: { x: number; y: number };\n}\n\ntype AnnulusPaintForm = { fill?: CommandFill; stroke?: CommandStroke; insetPx?: number };\n\nconst isAnnulusForm = (paint: CommandStroke | AnnulusPaintForm): paint is AnnulusPaintForm =>\n 'fill' in paint || 'stroke' in paint || 'insetPx' in paint;\n\nconst DEFAULT_PAINT: AnnulusPaintForm = {\n fill: { paint: { kind: 'solid', color: 'rgba(26, 19, 13, 0.12)' } },\n insetPx: 10,\n};\n\n/**\n * @experimental\n * Rotation affordance for the active selection: an elliptical ring that wraps the selection —\n * the smallest ellipse containing the AABB, minus the AABB itself. Hovering the ring sets the\n * cursor (default the `rotate` glyph) and a drag from it triggers `rotateAction`.\n *\n * The ring is target-local — under target rotation the ellipse rotates with the AABB.\n * Visibility is gated by chrome-caps' `'selection.rotation-handle'` rule. `paint: null` leaves\n * the cursor change as the only cue.\n */\nexport function createRotationAffordance(\n opts: RotationAffordanceOptions = {},\n): Affordance {\n const { bandPx = 24, paint = DEFAULT_PAINT, cursor, handle } = opts;\n\n // A bare `Stroke` carries none of the object form's three keys, and cannot be told apart\n // by its own `paint` since that is optional.\n const annulusPaint:\n | { kind: 'annulus'; fill?: CommandFill; stroke?: CommandStroke; insetPx?: number }\n | null = (() => {\n if (!paint) return null;\n if (!isAnnulusForm(paint)) {\n return { kind: 'annulus' as const, stroke: paint };\n }\n return {\n kind: 'annulus' as const,\n ...(paint.fill ? { fill: paint.fill } : {}),\n ...(paint.stroke ? { stroke: paint.stroke } : {}),\n ...(paint.insetPx !== undefined ? { insetPx: paint.insetPx } : {}),\n };\n })();\n\n return {\n id: 'selection.rotation-handle',\n regions(state: ChromeState): readonly AffordanceRegion[] {\n const target = pickTarget(state);\n if (!target) return [];\n const b = target.bounds;\n\n // The natural ring is the smallest ellipse containing the AABB. `minBandPx` asks the\n // framework to widen it to at least `bandPx` screen pixels outside the rect; the floor is\n // declared in screen units because `ChromeState` carries no view scale.\n const halfW = b.width / 2;\n const halfH = b.height / 2;\n\n const pivot = localToWorld(transformOf(state, target.id), b.x + halfW, b.y + halfH);\n const regionCursor: AffordanceRegion['cursor'] = cursor\n ?? ((at, view) => rotateCursorAt(pivot, at, view.scale));\n const bind = (): AffordanceBinding => ({\n initialScratch: {\n targetId: target.id,\n // Pivot. `rotateAction` recomputes its own union pivot for\n // multi-selection, but the single-target case reads this.\n fixedPoint: { x: b.x + halfW, y: b.y + halfH },\n } satisfies RotationScratch,\n });\n\n const region: AffordanceRegion = {\n id: 'selection.rotation-handle',\n targetId: target.id,\n shape: {\n kind: 'annulus',\n cx: b.x + halfW,\n cy: b.y + halfH,\n rx: halfW * Math.SQRT2,\n ry: halfH * Math.SQRT2,\n innerX: b.x,\n innerY: b.y,\n innerWidth: b.width,\n innerHeight: b.height,\n minBandPx: bandPx,\n },\n ...(annulusPaint ? { paint: annulusPaint } : {}),\n hitKind: 'rotate-handle',\n cursor: regionCursor,\n bind,\n };\n if (!handle) return [region];\n const badge: AffordanceRegion = {\n id: 'rotation-badge',\n targetId: target.id,\n shape: {\n kind: 'point',\n x: b.x + halfW,\n y: b.y,\n hitRadiusPx: handle.hitRadiusPx,\n standoff: { px: handle.distancePx, normal: { x: 0, y: -1 } },\n },\n hitKind: 'rotate-handle',\n cursor: regionCursor,\n bind,\n };\n return [region, badge];\n },\n };\n}\n\nfunction pickTarget(state: ChromeState): { id: string; bounds: Bounds } | null {\n if (state.selection.length === 1) {\n const id = state.selection[0];\n // Skip when the selected node's pose-descriptor declares it can't carry a rotation;\n // otherwise the ring would offer a rotate cursor over a node whose write is dropped.\n if (state.canRotate && !state.canRotate(id)) return null;\n const b = state.boundsOf(id);\n return b ? { id, bounds: b } : null;\n }\n // Multi-selection: anchor the ring to the union AABB; `rotateAction` ignores the synthetic\n // id and pivots at its own union center. Every selected id must support rotation — a\n // partial multi-rotate would feel broken.\n if (state.multiActive && state.unionBounds) {\n if (state.canRotate) {\n for (const id of state.selection) {\n if (!state.canRotate(id)) return null;\n }\n }\n return { id: MULTI_RESIZE_TARGET_ID, bounds: state.unionBounds };\n }\n return null;\n}\n"],"mappings":";;;;;AA8CA,IAAMA,KAAiB,MACrB,UAAUC,KAAS,YAAYA,KAAS,aAAaA,GAEjDC,IAAkC;CACtC,MAAM,EAAE,OAAO;EAAE,MAAM;EAAS,OAAO;CAAyB,EAAE;CAClE,SAAS;AACX;AAYA,SAAgBC,EACd,IAAkC,CAAC,GACvB;CACZ,IAAM,EAAE,YAAS,IAAI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AUf,EAAO;IACjB,OAAO;KACL,MAAM;KACN,GAAGG,EAAE,IAAIC;KACT,GAAGD,EAAE;KACL,aAAac,EAAO;KACpB,UAAU;MAAE,IAAIA,EAAO;MAAY,QAAQ;OAAE,GAAG;OAAG,GAAG;MAAG;KAAE;IAC7D;IACA,SAAS;IACT,QAAQR;IACR;GAEc,CAAK,IAfD,CAACM,CAAM;EAgB7B;CACF;AACF;AAEA,SAASd,EAAW,GAA2D;CAC7E,IAAIC,EAAM,UAAU,WAAW,GAAG;EAChC,IAAMgB,IAAKhB,EAAM,UAAU;EAG3B,IAAIA,EAAM,aAAa,CAACA,EAAM,UAAUgB,CAAE,GAAG,OAAO;EACpD,IAAMf,IAAID,EAAM,SAASgB,CAAE;EAC3B,OAAOf,IAAI;GAAE;GAAI,QAAQA;EAAE,IAAI;CACjC;CAIA,IAAID,EAAM,eAAeA,EAAM,aAAa;EAC1C,IAAIA,EAAM,WACH;QAAA,IAAMgB,KAAMhB,EAAM,WACrB,IAAI,CAACA,EAAM,UAAUgB,CAAE,GAAG,OAAO;EAAA;EAGrC,OAAO;GAAE,IAAIC;GAAwB,QAAQjB,EAAM;EAAY;CACjE;CACA,OAAO;AACT"}
@@ -76,8 +76,14 @@ function _(r) {
76
76
  v
77
77
  ]), [b, x] = o(y), S = h(b, y) ? b : y;
78
78
  S !== b && x(y);
79
- let C = JSON.stringify(S.skeleton.joints.map((e) => e.name)), w = a(() => t(S.skeleton), [C]);
80
- return n({
79
+ let C = JSON.stringify(S.skeleton.joints.map((e) => e.name)), [w, T] = o(() => ({
80
+ joints: C,
81
+ seat: t(S.skeleton)
82
+ })), { seat: E } = w;
83
+ return w.joints !== C && (E = t(S.skeleton, w.seat), T({
84
+ joints: C,
85
+ seat: E
86
+ })), n({
81
87
  scene: i,
82
88
  skeleton: S.skeleton,
83
89
  bindings: S.bindings,
@@ -85,7 +91,7 @@ function _(r) {
85
91
  apply: l,
86
92
  descriptor: u,
87
93
  restPath: d
88
- }, w);
94
+ }, E);
89
95
  }
90
96
  //#endregion
91
97
  export { l as placeSkeleton, g as rigFromNode, u as unplaceSkeleton, _ as useRigNode };