@weasel-js/editing 1.19.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/README.md +23 -11
  2. package/dist/actionGroups.js +27 -0
  3. package/dist/actionGroups.js.map +1 -0
  4. package/dist/actions/align/action.js +12 -9
  5. package/dist/actions/align/action.js.map +1 -1
  6. package/dist/actions/align/align.js +5 -4
  7. package/dist/actions/align/align.js.map +1 -1
  8. package/dist/actions/clipboard/action.js +10 -7
  9. package/dist/actions/clipboard/action.js.map +1 -1
  10. package/dist/actions/clone/action.js +217 -0
  11. package/dist/actions/clone/action.js.map +1 -0
  12. package/dist/actions/clone/behaviors.js +65 -0
  13. package/dist/actions/clone/behaviors.js.map +1 -0
  14. package/dist/actions/delete/delete.js +123 -0
  15. package/dist/actions/delete/delete.js.map +1 -0
  16. package/dist/actions/derivedBox.js +16 -0
  17. package/dist/actions/derivedBox.js.map +1 -0
  18. package/dist/actions/distribute/action.js +6 -3
  19. package/dist/actions/distribute/action.js.map +1 -1
  20. package/dist/actions/distribute/distribute.js +3 -2
  21. package/dist/actions/distribute/distribute.js.map +1 -1
  22. package/dist/actions/distribute/plan.js.map +1 -1
  23. package/dist/actions/edit/createPaintAction.js +42 -13
  24. package/dist/actions/edit/createPaintAction.js.map +1 -1
  25. package/dist/actions/edit/{escape.js → deselect.js} +8 -8
  26. package/dist/actions/edit/deselect.js.map +1 -0
  27. package/dist/actions/edit/duplicate.js +9 -7
  28. package/dist/actions/edit/duplicate.js.map +1 -1
  29. package/dist/actions/edit/group.js +24 -20
  30. package/dist/actions/edit/group.js.map +1 -1
  31. package/dist/actions/edit/ingest.js +4 -2
  32. package/dist/actions/edit/ingest.js.map +1 -1
  33. package/dist/actions/edit/nudge.js +14 -10
  34. package/dist/actions/edit/nudge.js.map +1 -1
  35. package/dist/actions/edit/selectAll.js +1 -1
  36. package/dist/actions/edit/setFill.js +1 -1
  37. package/dist/actions/edit/setFill.js.map +1 -1
  38. package/dist/actions/edit/setFillOpacity.js +5 -5
  39. package/dist/actions/edit/setFillOpacity.js.map +1 -1
  40. package/dist/actions/edit/setStroke.js +1 -1
  41. package/dist/actions/edit/setStroke.js.map +1 -1
  42. package/dist/actions/edit/setStrokeOpacity.js +6 -6
  43. package/dist/actions/edit/setStrokeOpacity.js.map +1 -1
  44. package/dist/actions/edit/setStrokeWidth.js +13 -8
  45. package/dist/actions/edit/setStrokeWidth.js.map +1 -1
  46. package/dist/actions/edit/setVertexColor.js +13 -6
  47. package/dist/actions/edit/setVertexColor.js.map +1 -1
  48. package/dist/actions/flip/action.js +19 -14
  49. package/dist/actions/flip/action.js.map +1 -1
  50. package/dist/actions/flip/helpers.js.map +1 -1
  51. package/dist/actions/group/enterGroup.js +81 -0
  52. package/dist/actions/group/enterGroup.js.map +1 -0
  53. package/dist/actions/insert/action.js +152 -0
  54. package/dist/actions/insert/action.js.map +1 -0
  55. package/dist/actions/insert/commit.js +52 -0
  56. package/dist/actions/insert/commit.js.map +1 -0
  57. package/dist/actions/insert/extras.js +88 -0
  58. package/dist/actions/insert/extras.js.map +1 -0
  59. package/dist/actions/insert/frame.js +96 -0
  60. package/dist/actions/insert/frame.js.map +1 -0
  61. package/dist/actions/insert/geometry.js +35 -0
  62. package/dist/actions/insert/geometry.js.map +1 -0
  63. package/dist/actions/insert/lands.js +41 -0
  64. package/dist/actions/insert/lands.js.map +1 -0
  65. package/dist/actions/insert/params.js +42 -0
  66. package/dist/actions/insert/params.js.map +1 -0
  67. package/dist/actions/insert/placeAction.js +137 -0
  68. package/dist/actions/insert/placeAction.js.map +1 -0
  69. package/dist/actions/insert/repositionAction.js +47 -0
  70. package/dist/actions/insert/repositionAction.js.map +1 -0
  71. package/dist/actions/insert/rotateAction.js +34 -0
  72. package/dist/actions/insert/rotateAction.js.map +1 -0
  73. package/dist/actions/insert/session.js +99 -0
  74. package/dist/actions/insert/session.js.map +1 -0
  75. package/dist/actions/insert/shape.js +117 -0
  76. package/dist/actions/insert/shape.js.map +1 -0
  77. package/dist/actions/insert/style.js +23 -0
  78. package/dist/actions/insert/style.js.map +1 -0
  79. package/dist/actions/lassoSelect/action.js +201 -0
  80. package/dist/actions/lassoSelect/action.js.map +1 -0
  81. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
  82. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
  83. package/dist/actions/lockedWrites.js +20 -0
  84. package/dist/actions/lockedWrites.js.map +1 -0
  85. package/dist/actions/move/action.js +138 -0
  86. package/dist/actions/move/action.js.map +1 -0
  87. package/dist/actions/move/behaviors/clampMove.js +42 -0
  88. package/dist/actions/move/behaviors/clampMove.js.map +1 -0
  89. package/dist/actions/move/behaviors/layoutDrop.js +84 -0
  90. package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
  91. package/dist/actions/move/behaviors/pageDrop.js +30 -0
  92. package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
  93. package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
  94. package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
  95. package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
  96. package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
  97. package/dist/actions/move/behaviors/snapToContainer.js +214 -0
  98. package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
  99. package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
  100. package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
  101. package/dist/actions/move/capture.js +116 -0
  102. package/dist/actions/move/capture.js.map +1 -0
  103. package/dist/actions/move/commit/index.js +47 -0
  104. package/dist/actions/move/commit/index.js.map +1 -0
  105. package/dist/actions/move/commit/layoutDrop.js +68 -0
  106. package/dist/actions/move/commit/layoutDrop.js.map +1 -0
  107. package/dist/actions/move/commit/layoutRelease.js +146 -0
  108. package/dist/actions/move/commit/layoutRelease.js.map +1 -0
  109. package/dist/actions/move/commit/pageDrop.js +162 -0
  110. package/dist/actions/move/commit/pageDrop.js.map +1 -0
  111. package/dist/actions/move/commit/rebase.js +24 -0
  112. package/dist/actions/move/commit/rebase.js.map +1 -0
  113. package/dist/actions/move/commit/reparent.js +157 -0
  114. package/dist/actions/move/commit/reparent.js.map +1 -0
  115. package/dist/actions/move/delta.js +127 -0
  116. package/dist/actions/move/delta.js.map +1 -0
  117. package/dist/actions/move/dragSnap.js +55 -0
  118. package/dist/actions/move/dragSnap.js.map +1 -0
  119. package/dist/actions/move/frame.js +67 -0
  120. package/dist/actions/move/frame.js.map +1 -0
  121. package/dist/actions/move/gestureAdapter.js +36 -0
  122. package/dist/actions/move/gestureAdapter.js.map +1 -0
  123. package/dist/actions/move/landedDescendants.js +50 -0
  124. package/dist/actions/move/landedDescendants.js.map +1 -0
  125. package/dist/actions/move/layout/container.js +119 -0
  126. package/dist/actions/move/layout/container.js.map +1 -0
  127. package/dist/actions/move/layout/dragged.js +75 -0
  128. package/dist/actions/move/layout/dragged.js.map +1 -0
  129. package/dist/actions/move/layout/dropPass.js +205 -0
  130. package/dist/actions/move/layout/dropPass.js.map +1 -0
  131. package/dist/actions/move/layout/exits.js +62 -0
  132. package/dist/actions/move/layout/exits.js.map +1 -0
  133. package/dist/actions/move/layout/glide.js +70 -0
  134. package/dist/actions/move/layout/glide.js.map +1 -0
  135. package/dist/actions/move/layout/view.js +60 -0
  136. package/dist/actions/move/layout/view.js.map +1 -0
  137. package/dist/actions/move/refusal.js +49 -0
  138. package/dist/actions/move/refusal.js.map +1 -0
  139. package/dist/actions/move/session.js +105 -0
  140. package/dist/actions/move/session.js.map +1 -0
  141. package/dist/actions/move/sessionOf.js +27 -0
  142. package/dist/actions/move/sessionOf.js.map +1 -0
  143. package/dist/actions/move/translate.js +49 -0
  144. package/dist/actions/move/translate.js.map +1 -0
  145. package/dist/actions/pathfinder/action.js +8 -6
  146. package/dist/actions/pathfinder/action.js.map +1 -1
  147. package/dist/actions/pathfinder/booleanGroupAction.js +16 -10
  148. package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -1
  149. package/dist/actions/pathfinder/keymap.js +2 -2
  150. package/dist/actions/pathfinder/keymap.js.map +1 -1
  151. package/dist/actions/reorder/reorder.js +13 -11
  152. package/dist/actions/reorder/reorder.js.map +1 -1
  153. package/dist/actions/resize/action.js +105 -0
  154. package/dist/actions/resize/action.js.map +1 -0
  155. package/dist/actions/resize/aspect.js +42 -0
  156. package/dist/actions/resize/aspect.js.map +1 -0
  157. package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
  158. package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
  159. package/dist/actions/resize/boxFrame.js +19 -0
  160. package/dist/actions/resize/boxFrame.js.map +1 -0
  161. package/dist/actions/resize/capture.js +121 -0
  162. package/dist/actions/resize/capture.js.map +1 -0
  163. package/dist/actions/resize/commit.js +104 -0
  164. package/dist/actions/resize/commit.js.map +1 -0
  165. package/dist/actions/resize/frame.js +171 -0
  166. package/dist/actions/resize/frame.js.map +1 -0
  167. package/dist/actions/resize/held.js +44 -0
  168. package/dist/actions/resize/held.js.map +1 -0
  169. package/dist/actions/resize/minimum.js +34 -0
  170. package/dist/actions/resize/minimum.js.map +1 -0
  171. package/dist/actions/resize/replay.js +58 -0
  172. package/dist/actions/resize/replay.js.map +1 -0
  173. package/dist/actions/resize/ruleBounds.js +11 -0
  174. package/dist/actions/resize/ruleBounds.js.map +1 -0
  175. package/dist/actions/resize/session.js +118 -0
  176. package/dist/actions/resize/session.js.map +1 -0
  177. package/dist/actions/rotate/action.js +99 -0
  178. package/dist/actions/rotate/action.js.map +1 -0
  179. package/dist/actions/rotate/commit.js +48 -0
  180. package/dist/actions/rotate/commit.js.map +1 -0
  181. package/dist/actions/rotate/frame.js +96 -0
  182. package/dist/actions/rotate/frame.js.map +1 -0
  183. package/dist/actions/rotate/replay.js +25 -0
  184. package/dist/actions/rotate/replay.js.map +1 -0
  185. package/dist/actions/rotate/session.js +135 -0
  186. package/dist/actions/rotate/session.js.map +1 -0
  187. package/dist/actions/select/areaSelect.js +83 -0
  188. package/dist/actions/select/areaSelect.js.map +1 -0
  189. package/dist/actions/select/clearSelection.js +33 -0
  190. package/dist/actions/select/clearSelection.js.map +1 -0
  191. package/dist/actions/swap/action.js +63 -0
  192. package/dist/actions/swap/action.js.map +1 -0
  193. package/dist/actions/swap/swapOps.js +160 -0
  194. package/dist/actions/swap/swapOps.js.map +1 -0
  195. package/dist/actions/transformAgain/action.js +16 -14
  196. package/dist/actions/transformAgain/action.js.map +1 -1
  197. package/dist/actions/transformAgain/transformSelection.js +19 -5
  198. package/dist/actions/transformAgain/transformSelection.js.map +1 -1
  199. package/dist/booleans/booleans.js +130 -0
  200. package/dist/booleans/booleans.js.map +1 -0
  201. package/dist/booleans/commit.js +45 -0
  202. package/dist/booleans/commit.js.map +1 -0
  203. package/dist/booleans/custom.js +48 -0
  204. package/dist/booleans/custom.js.map +1 -0
  205. package/dist/booleans/operands.js +50 -0
  206. package/dist/booleans/operands.js.map +1 -0
  207. package/dist/booleans/pieces.js +43 -0
  208. package/dist/booleans/pieces.js.map +1 -0
  209. package/dist/booleans/placement.js +37 -0
  210. package/dist/booleans/placement.js.map +1 -0
  211. package/dist/booleans/useBooleans.js +34 -0
  212. package/dist/booleans/useBooleans.js.map +1 -0
  213. package/dist/booleans/useBooleansAdapter.js +11 -0
  214. package/dist/booleans/useBooleansAdapter.js.map +1 -0
  215. package/dist/chrome/affordances/cornerResize.js +123 -0
  216. package/dist/chrome/affordances/cornerResize.js.map +1 -0
  217. package/dist/chrome/affordances/rotateCursor.js +17 -0
  218. package/dist/chrome/affordances/rotateCursor.js.map +1 -0
  219. package/dist/chrome/affordances/rotationHandle.js +117 -0
  220. package/dist/chrome/affordances/rotationHandle.js.map +1 -0
  221. package/dist/chrome/handleCommands.js +110 -0
  222. package/dist/chrome/handleCommands.js.map +1 -0
  223. package/dist/chrome/overlay.js +271 -0
  224. package/dist/chrome/overlay.js.map +1 -0
  225. package/dist/chrome/rotationBadge.js +132 -0
  226. package/dist/chrome/rotationBadge.js.map +1 -0
  227. package/dist/chrome/rotationHandleGeometry.js +49 -0
  228. package/dist/chrome/rotationHandleGeometry.js.map +1 -0
  229. package/dist/chrome/selectionChrome.js +25 -0
  230. package/dist/chrome/selectionChrome.js.map +1 -0
  231. package/dist/chrome/selectionPose.js +112 -0
  232. package/dist/chrome/selectionPose.js.map +1 -0
  233. package/dist/chrome/shapeOutline.js +137 -0
  234. package/dist/chrome/shapeOutline.js.map +1 -0
  235. package/dist/clipboard/clipboardOps.js +48 -0
  236. package/dist/clipboard/clipboardOps.js.map +1 -0
  237. package/dist/clipboard/materializePaste.js +34 -0
  238. package/dist/clipboard/materializePaste.js.map +1 -0
  239. package/dist/clipboard/osClipboard.js +67 -0
  240. package/dist/clipboard/osClipboard.js.map +1 -0
  241. package/dist/clipboard/useClipboard.js +64 -0
  242. package/dist/clipboard/useClipboard.js.map +1 -0
  243. package/dist/clipboard/wireFormat.js +108 -0
  244. package/dist/clipboard/wireFormat.js.map +1 -0
  245. package/dist/deps/areaSelect.js +42 -0
  246. package/dist/deps/areaSelect.js.map +1 -0
  247. package/dist/deps/booleans.js +99 -0
  248. package/dist/deps/booleans.js.map +1 -0
  249. package/dist/deps/insert.js +260 -0
  250. package/dist/deps/insert.js.map +1 -0
  251. package/dist/deps/lassoSelect.js +37 -0
  252. package/dist/deps/lassoSelect.js.map +1 -0
  253. package/dist/deps/presetDeps.js +40 -0
  254. package/dist/deps/presetDeps.js.map +1 -0
  255. package/dist/deps/resizePolicy.js +41 -0
  256. package/dist/deps/resizePolicy.js.map +1 -0
  257. package/dist/engine-BV9RDHOL.d.ts +339 -0
  258. package/dist/engine.d.ts +6 -0
  259. package/dist/engine.js +10 -0
  260. package/dist/engineStandardActions.js +16 -7
  261. package/dist/engineStandardActions.js.map +1 -1
  262. package/dist/groups.d.ts +27 -0
  263. package/dist/groups.js +4 -0
  264. package/dist/icons.gen.js +8 -0
  265. package/dist/icons.gen.js.map +1 -0
  266. package/dist/icons.table.d.ts +6 -0
  267. package/dist/icons.table.js +8 -0
  268. package/dist/icons.table.js.map +1 -0
  269. package/dist/icons.table.json +156 -0
  270. package/dist/icons2.table.js +163 -0
  271. package/dist/icons2.table.js.map +1 -0
  272. package/dist/index.d.ts +1293 -105
  273. package/dist/index.js +61 -12
  274. package/dist/ingest/ghost.js +58 -0
  275. package/dist/ingest/ghost.js.map +1 -0
  276. package/dist/ingest/imageHandler.js +80 -0
  277. package/dist/ingest/imageHandler.js.map +1 -0
  278. package/dist/ingest/kitHandlers.js +15 -0
  279. package/dist/ingest/kitHandlers.js.map +1 -0
  280. package/dist/ingest/svgHandler.js +97 -0
  281. package/dist/ingest/svgHandler.js.map +1 -0
  282. package/dist/ingest/weaselJsonHandler.js +68 -0
  283. package/dist/ingest/weaselJsonHandler.js.map +1 -0
  284. package/dist/namedPresets.js +23 -11
  285. package/dist/namedPresets.js.map +1 -1
  286. package/dist/presets/arrange.js +21 -7
  287. package/dist/presets/arrange.js.map +1 -1
  288. package/dist/presets/booleans.js +13 -0
  289. package/dist/presets/booleans.js.map +1 -0
  290. package/dist/presets/composites.js +8 -5
  291. package/dist/presets/composites.js.map +1 -1
  292. package/dist/presets/edit.js +25 -13
  293. package/dist/presets/edit.js.map +1 -1
  294. package/dist/presets/ingest.js +7 -3
  295. package/dist/presets/ingest.js.map +1 -1
  296. package/dist/presets/insert.js +28 -0
  297. package/dist/presets/insert.js.map +1 -0
  298. package/dist/presets/pathfinder.js +5 -2
  299. package/dist/presets/pathfinder.js.map +1 -1
  300. package/dist/presets/select.js +16 -3
  301. package/dist/presets/select.js.map +1 -1
  302. package/dist/presets/selection.js +13 -0
  303. package/dist/presets/selection.js.map +1 -0
  304. package/dist/presets/selectionChrome.js +15 -0
  305. package/dist/presets/selectionChrome.js.map +1 -0
  306. package/dist/presets/tools.js +78 -9
  307. package/dist/presets/tools.js.map +1 -1
  308. package/dist/presets/transform.js +20 -7
  309. package/dist/presets/transform.js.map +1 -1
  310. package/dist/presets.d.ts +104 -0
  311. package/dist/presets.js +15 -0
  312. package/dist/selection/useSelection.js +127 -0
  313. package/dist/selection/useSelection.js.map +1 -0
  314. package/dist/test-seams.d.ts +50 -0
  315. package/dist/test-seams.js +4 -0
  316. package/dist/tools/ellipse/useEllipseTool.js +72 -0
  317. package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
  318. package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
  319. package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
  320. package/dist/tools/image/useImageTool.js +57 -0
  321. package/dist/tools/image/useImageTool.js.map +1 -0
  322. package/dist/tools/lasso/useLassoTool.js +96 -0
  323. package/dist/tools/lasso/useLassoTool.js.map +1 -0
  324. package/dist/tools/line/useLineTool.js +67 -0
  325. package/dist/tools/line/useLineTool.js.map +1 -0
  326. package/dist/tools/polygon/usePolygonTool.js +149 -0
  327. package/dist/tools/polygon/usePolygonTool.js.map +1 -0
  328. package/dist/tools/rect/useRectTool.js +74 -0
  329. package/dist/tools/rect/useRectTool.js.map +1 -0
  330. package/dist/tools/select/adapterPointQuery.js +56 -0
  331. package/dist/tools/select/adapterPointQuery.js.map +1 -0
  332. package/dist/tools/select/collapseDeferred.js +35 -0
  333. package/dist/tools/select/collapseDeferred.js.map +1 -0
  334. package/dist/tools/select/extendPressLocked.js +17 -0
  335. package/dist/tools/select/extendPressLocked.js.map +1 -0
  336. package/dist/tools/select/groupEntry.js +73 -0
  337. package/dist/tools/select/groupEntry.js.map +1 -0
  338. package/dist/tools/select/pressDecision.js +39 -0
  339. package/dist/tools/select/pressDecision.js.map +1 -0
  340. package/dist/tools/select/selectDeep.js +39 -0
  341. package/dist/tools/select/selectDeep.js.map +1 -0
  342. package/dist/tools/select/selectPick.js +60 -0
  343. package/dist/tools/select/selectPick.js.map +1 -0
  344. package/dist/tools/select/selectionContributions.js +191 -0
  345. package/dist/tools/select/selectionContributions.js.map +1 -0
  346. package/dist/tools/select/usePickerSelectTool.js +145 -0
  347. package/dist/tools/select/usePickerSelectTool.js.map +1 -0
  348. package/dist/tools/select/useSelectTool.js +54 -0
  349. package/dist/tools/select/useSelectTool.js.map +1 -0
  350. package/dist/tools/shared/countOption.js +24 -0
  351. package/dist/tools/shared/countOption.js.map +1 -0
  352. package/dist/tools/shared/insertToolOptions.js +8 -0
  353. package/dist/tools/shared/insertToolOptions.js.map +1 -0
  354. package/dist/tools/shared/pointerFollower.js +23 -0
  355. package/dist/tools/shared/pointerFollower.js.map +1 -0
  356. package/dist/tools/shared/styleOptions.js +76 -0
  357. package/dist/tools/shared/styleOptions.js.map +1 -0
  358. package/dist/tools/star/useStarTool.js +149 -0
  359. package/dist/tools/star/useStarTool.js.map +1 -0
  360. package/dist/tools/toolSets.js +26 -0
  361. package/dist/tools/toolSets.js.map +1 -0
  362. package/package.json +39 -11
  363. package/dist/actions/edit/escape.js.map +0 -1
@@ -0,0 +1,110 @@
1
+ import { HANDLE_BASE_PX, angleOf, localToWorld, targetTransformOf } from "@weasel-js/core";
2
+ import { handlePoint, resizeHandlesFor, viewToTransform, worldToScreen } from "@weasel-js/core/engine";
3
+ import { screenAngleOf } from "@weasel-js/geom";
4
+
5
+ // src/chrome/handleCommands.ts
6
+ /** The colors a resize handle is filled and outlined in when its style names none. */
7
+ var HANDLE_FILL_COLOR = "#d4c4a8";
8
+ var HANDLE_OUTLINE_COLOR = "#1a130d";
9
+ var DEFAULT_HANDLE_FILL = { paint: {
10
+ kind: "solid",
11
+ color: HANDLE_FILL_COLOR
12
+ } };
13
+ var DEFAULT_HANDLE_OUTLINE = {
14
+ paint: {
15
+ kind: "solid",
16
+ color: HANDLE_OUTLINE_COLOR
17
+ },
18
+ width: 1
19
+ };
20
+ var DEFAULT_HANDLE_SIZE = HANDLE_BASE_PX;
21
+ function resolveHandles(opts) {
22
+ return {
23
+ size: opts?.size ?? DEFAULT_HANDLE_SIZE,
24
+ fill: opts?.fill ?? DEFAULT_HANDLE_FILL,
25
+ outline: opts?.outline ?? DEFAULT_HANDLE_OUTLINE
26
+ };
27
+ }
28
+ /** GL helper: emit a closed rect path (kind:'rect'). */
29
+ function rectPathFor(x, y, width, height) {
30
+ return {
31
+ kind: "rect",
32
+ x,
33
+ y,
34
+ width,
35
+ height
36
+ };
37
+ }
38
+ /**
39
+ * GL helper: build the matrix `translate(cx, cy) * rotate(θ) * translate(-cx, -cy)`
40
+ * used to wrap rotated outline / handle commands.
41
+ */
42
+ function rotateAboutMat3(cx, cy, theta) {
43
+ const c = Math.cos(theta);
44
+ const s = Math.sin(theta);
45
+ const tx = cx - c * cx + s * cy;
46
+ const ty = cy - s * cx - c * cy;
47
+ return new Float32Array([
48
+ c,
49
+ s,
50
+ 0,
51
+ -s,
52
+ c,
53
+ 0,
54
+ tx,
55
+ ty,
56
+ 1
57
+ ]);
58
+ }
59
+ /** GL helper: emit handle fill+stroke commands for one bounds entry. */
60
+ function handleCommandsFor(ids, resolveBounds, handles, handlesOf, layoutOpts, view) {
61
+ const layout = {
62
+ edges: true,
63
+ hitRadiusPx: HANDLE_BASE_PX,
64
+ ...layoutOpts
65
+ };
66
+ const out = [];
67
+ const half = handles.size / 2;
68
+ for (const id of ids) {
69
+ const worldB = resolveBounds(id);
70
+ if (!worldB) continue;
71
+ const xf = targetTransformOf(worldB);
72
+ const t = viewToTransform(view);
73
+ const angle = screenAngleOf(angleOf(xf), view.scale);
74
+ const at = handlesOf ? handlesOf(worldB) : resizeHandlesFor(layout, worldB, xf, view.scale).map((c) => handlePoint(worldB, c));
75
+ for (const hLocal of at) {
76
+ const hWorld = localToWorld(xf, hLocal.x, hLocal.y);
77
+ const [hsx, hsy] = worldToScreen(hWorld.x, hWorld.y, t);
78
+ const center = {
79
+ x: hsx,
80
+ y: hsy
81
+ };
82
+ const baseRect = {
83
+ x: center.x - half,
84
+ y: center.y - half,
85
+ width: handles.size,
86
+ height: handles.size
87
+ };
88
+ const fillCmd = {
89
+ kind: "path",
90
+ path: rectPathFor(baseRect.x, baseRect.y, baseRect.width, baseRect.height),
91
+ fill: handles.fill
92
+ };
93
+ const strokeCmd = {
94
+ kind: "path",
95
+ path: rectPathFor(baseRect.x, baseRect.y, baseRect.width, baseRect.height),
96
+ stroke: handles.outline
97
+ };
98
+ if (angle === 0) out.push(fillCmd, strokeCmd);
99
+ else out.push({
100
+ kind: "group",
101
+ transform: rotateAboutMat3(center.x, center.y, angle),
102
+ children: [fillCmd, strokeCmd]
103
+ });
104
+ }
105
+ }
106
+ return out;
107
+ }
108
+
109
+ export { HANDLE_FILL_COLOR, HANDLE_OUTLINE_COLOR, handleCommandsFor, rectPathFor, resolveHandles };
110
+ //# sourceMappingURL=handleCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleCommands.js","names":[],"sources":["../../src/chrome/handleCommands.ts"],"sourcesContent":["/**\n * The selection overlay's resize handles: their style, where the kit puts\n * them, and the commands that paint them.\n */\n\nimport type { DrawCommand, GlMat3 } from '@weasel-js/renderer';\nimport type { SelectionHandleStyle } from '@weasel-js/core';\nimport type { CommandStroke, CommandFill } from '@weasel-js/paint';\nimport { screenAngleOf } from '@weasel-js/geom';\nimport { angleOf, localToWorld, targetTransformOf } from '@weasel-js/core';\nimport type { Bounds } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { viewToTransform } from '@weasel-js/core/engine';\nimport { worldToScreen } from '@weasel-js/core/engine';\nimport { HANDLE_BASE_PX } from '@weasel-js/core';\nimport {\n handlePoint, resizeHandlesFor, type ResizeHandleLayout,\n} from '@weasel-js/core/engine';\n\nexport type { ResizeHandleLayout };\n\n/** The colors a resize handle is filled and outlined in when its style names none. */\nexport const HANDLE_FILL_COLOR = '#d4c4a8';\nexport const HANDLE_OUTLINE_COLOR = '#1a130d';\n\nconst DEFAULT_HANDLE_FILL: CommandFill = { paint: { kind: 'solid', color: HANDLE_FILL_COLOR } };\nconst DEFAULT_HANDLE_OUTLINE: CommandStroke = {\n paint: { kind: 'solid', color: HANDLE_OUTLINE_COLOR },\n width: 1,\n};\nconst DEFAULT_HANDLE_SIZE = HANDLE_BASE_PX;\n\n\nexport interface ResolvedHandles {\n size: number;\n fill: CommandFill;\n outline: CommandStroke;\n}\n\nexport function resolveHandles(opts?: SelectionHandleStyle): ResolvedHandles {\n return {\n size: opts?.size ?? DEFAULT_HANDLE_SIZE,\n fill: opts?.fill ?? DEFAULT_HANDLE_FILL,\n outline: opts?.outline ?? DEFAULT_HANDLE_OUTLINE,\n };\n}\n\n/** GL helper: emit a closed rect path (kind:'rect'). */\nexport function rectPathFor(x: number, y: number, width: number, height: number): { kind: 'rect'; x: number; y: number; width: number; height: number } {\n return { kind: 'rect', x, y, width, height };\n}\n\n/**\n * GL helper: build the matrix `translate(cx, cy) * rotate(θ) * translate(-cx, -cy)`\n * used to wrap rotated outline / handle commands.\n */\nfunction rotateAboutMat3(cx: number, cy: number, theta: number): GlMat3 {\n const c = Math.cos(theta);\n const s = Math.sin(theta);\n // Composed in column-major (matches mat3 helpers): T(cx,cy) · R(θ) · T(-cx,-cy).\n // After expansion: a=c, b=s, c'=-s, d=c, tx=cx - c*cx + s*cy, ty=cy - s*cx - c*cy.\n const tx = cx - c * cx + s * cy;\n const ty = cy - s * cx - c * cy;\n return new Float32Array([\n c, s, 0,\n -s, c, 0,\n tx, ty, 1,\n ]) as GlMat3;\n}\n\n/** GL helper: emit handle fill+stroke commands for one bounds entry. */\nexport function handleCommandsFor(\n ids: readonly string[],\n resolveBounds: (id: string) => Bounds | null,\n handles: ResolvedHandles,\n handlesOf: ((b: Bounds) => { x: number; y: number }[]) | undefined,\n layoutOpts: Partial<ResizeHandleLayout> | undefined,\n view: View,\n): DrawCommand[] {\n const layout: ResizeHandleLayout = { edges: true, hitRadiusPx: HANDLE_BASE_PX, ...layoutOpts };\n const out: DrawCommand[] = [];\n const half = handles.size / 2;\n for (const id of ids) {\n const worldB = resolveBounds(id);\n if (!worldB) continue;\n // Framed in world, then projected: turning the projected point instead\n // lands somewhere else under non-uniform zoom.\n const xf = targetTransformOf(worldB);\n const t = viewToTransform(view);\n const angle = screenAngleOf(angleOf(xf), view.scale);\n const at = handlesOf\n ? handlesOf(worldB)\n : resizeHandlesFor(layout, worldB, xf, view.scale).map((c) => handlePoint(worldB, c));\n for (const hLocal of at) {\n const hWorld = localToWorld(xf, hLocal.x, hLocal.y);\n const [hsx, hsy] = worldToScreen(hWorld.x, hWorld.y, t);\n const center = { x: hsx, y: hsy };\n const baseRect = {\n x: center.x - half,\n y: center.y - half,\n width: handles.size,\n height: handles.size,\n };\n const fillCmd: DrawCommand = {\n kind: 'path',\n path: rectPathFor(baseRect.x, baseRect.y, baseRect.width, baseRect.height),\n fill: handles.fill,\n };\n const strokeCmd: DrawCommand = {\n kind: 'path',\n path: rectPathFor(baseRect.x, baseRect.y, baseRect.width, baseRect.height),\n stroke: handles.outline,\n };\n if (angle === 0) {\n out.push(fillCmd, strokeCmd);\n } else {\n out.push({\n kind: 'group',\n transform: rotateAboutMat3(center.x, center.y, angle),\n children: [fillCmd, strokeCmd],\n });\n }\n }\n }\n return out;\n}\n"],"mappings":";;;;;;AAsBA,IAAa,oBAAoB;AACjC,IAAa,uBAAuB;AAEpC,IAAM,sBAAmC,EAAE,OAAO;CAAE,MAAM;CAAS,OAAO;AAAkB,EAAE;AAC9F,IAAM,yBAAwC;CAC5C,OAAO;EAAE,MAAM;EAAS,OAAO;CAAqB;CACpD,OAAO;AACT;AACA,IAAM,sBAAsB;AAS5B,SAAgB,eAAe,MAA8C;CAC3E,OAAO;EACL,MAAM,MAAM,QAAQ;EACpB,MAAM,MAAM,QAAQ;EACpB,SAAS,MAAM,WAAW;CAC5B;AACF;;AAGA,SAAgB,YAAY,GAAW,GAAW,OAAe,QAAuF;CACtJ,OAAO;EAAE,MAAM;EAAQ;EAAG;EAAG;EAAO;CAAO;AAC7C;;;;;AAMA,SAAS,gBAAgB,IAAY,IAAY,OAAuB;CACtE,MAAM,IAAI,KAAK,IAAI,KAAK;CACxB,MAAM,IAAI,KAAK,IAAI,KAA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Q,QAAQ;GAClB;GACA,IAAI,UAAU,GACZ,IAAI,KAAK,SAAS,SAAS;QAE3B,IAAI,KAAK;IACP,MAAM;IACN,WAAW,gBAAgB,OAAO,GAAG,OAAO,GAAG,KAAK;IACpD,UAAU,CAAC,SAAS,SAAS;GAC/B,CAAC;EAEL;CACF;CACA,OAAO;AACT"}
@@ -0,0 +1,271 @@
1
+ import { composeSelectionPose, containerAwareBoundsResolver } from "./selectionPose.js";
2
+ import { DEFAULT_ROTATION_HANDLE_DISTANCE, targetCanRotate } from "./rotationHandleGeometry.js";
3
+ import { rotationHandleCommands } from "./rotationBadge.js";
4
+ import { createShapeOutliner, shapeOutlineCommands, viewScaleOf } from "./shapeOutline.js";
5
+ import { handleCommandsFor, rectPathFor, resolveHandles } from "./handleCommands.js";
6
+ import { MULTI_RESIZE_TARGET_ID, effectivePoseFrom, previewPoseIn, previewSourcesFrom, targetCorners, targetTransformOf } from "@weasel-js/core";
7
+ import { resolveScreenLength } from "@weasel-js/paint";
8
+ import { AUTO_POSE_DESCRIPTOR, viewToTransform, worldToScreen } from "@weasel-js/core/engine";
9
+ import { PATH_L, PATH_M, PATH_Z } from "@weasel-js/geom";
10
+
11
+ // src/chrome/overlay.ts
12
+ /** Project world AABB into screen-space AABB using the active view. */
13
+ function projectBounds(b, view) {
14
+ const t = viewToTransform(view);
15
+ const [sx, sy] = worldToScreen(b.x, b.y, t);
16
+ const [w, h] = [b.width * view.scale.x, b.height * view.scale.y];
17
+ return {
18
+ ...b,
19
+ x: Math.min(sx, sx + w),
20
+ y: Math.min(sy, sy + h),
21
+ width: Math.abs(w),
22
+ height: Math.abs(h)
23
+ };
24
+ }
25
+ var DEFAULT_OUTLINE = {
26
+ paint: {
27
+ kind: "solid",
28
+ color: "#f0e0a8"
29
+ },
30
+ width: 2,
31
+ pad: 1
32
+ };
33
+ function resolveOutlineStroke(opts) {
34
+ const { pad, follow: _follow, ...rest } = opts ?? {};
35
+ return {
36
+ stroke: {
37
+ ...rest,
38
+ paint: rest.paint ?? DEFAULT_OUTLINE.paint,
39
+ width: rest.width ?? DEFAULT_OUTLINE.width
40
+ },
41
+ pad: pad ?? DEFAULT_OUTLINE.pad
42
+ };
43
+ }
44
+ /** GL helper: emit an outline command for one bounds entry. */
45
+ function outlineCommandsFor(ids, resolveBounds, stroke, pad, view) {
46
+ const out = [];
47
+ const align = stroke.align ?? "center";
48
+ const width = resolveScreenLength(stroke.width ?? 1, 1);
49
+ for (const id of ids) {
50
+ const worldB = resolveBounds(id);
51
+ if (!worldB) continue;
52
+ const b = projectBounds(worldB, view);
53
+ const padded = {
54
+ x: b.x - pad,
55
+ y: b.y - pad,
56
+ width: b.width + pad * 2,
57
+ height: b.height + pad * 2
58
+ };
59
+ const xf = targetTransformOf(worldB);
60
+ if (xf.identity) {
61
+ out.push({
62
+ kind: "path",
63
+ path: rectPathFor(padded.x, padded.y, padded.width, padded.height),
64
+ stroke
65
+ });
66
+ continue;
67
+ }
68
+ const q = screenCorners(worldB, xf, view, pad + (align === "outer" ? width / 2 : align === "inner" ? -width / 2 : 0));
69
+ out.push({
70
+ kind: "path",
71
+ path: {
72
+ kind: "polygon",
73
+ commands: new Uint8Array([
74
+ PATH_M,
75
+ PATH_L,
76
+ PATH_L,
77
+ PATH_L,
78
+ PATH_Z
79
+ ]),
80
+ coords: new Float32Array([
81
+ q[0].x,
82
+ q[0].y,
83
+ q[1].x,
84
+ q[1].y,
85
+ q[2].x,
86
+ q[2].y,
87
+ q[3].x,
88
+ q[3].y
89
+ ]),
90
+ fillRule: "nonzero"
91
+ },
92
+ stroke: {
93
+ ...stroke,
94
+ align: "center"
95
+ }
96
+ });
97
+ }
98
+ return out;
99
+ }
100
+ /**
101
+ * A framed target's corners on screen, TL/TR/BR/BL, each pushed `pad` screen
102
+ * pixels out from both edges that meet there.
103
+ */
104
+ function screenCorners(worldB, xf, view, pad) {
105
+ const t = viewToTransform(view);
106
+ const q = targetCorners(worldB, xf).map((w) => {
107
+ const [x, y] = worldToScreen(w.x, w.y, t);
108
+ return {
109
+ x,
110
+ y
111
+ };
112
+ });
113
+ if (pad === 0) return q;
114
+ const [ccx, ccy] = worldToScreen(worldB.x + worldB.width / 2, worldB.y + worldB.height / 2, t);
115
+ const normal = (a, b) => {
116
+ let nx = -(b.y - a.y), ny = b.x - a.x;
117
+ const l = Math.hypot(nx, ny) || 1;
118
+ nx /= l;
119
+ ny /= l;
120
+ const mx = (a.x + b.x) / 2 - ccx, my = (a.y + b.y) / 2 - ccy;
121
+ return nx * mx + ny * my < 0 ? {
122
+ x: -nx,
123
+ y: -ny
124
+ } : {
125
+ x: nx,
126
+ y: ny
127
+ };
128
+ };
129
+ return q.map((c, i) => {
130
+ const n1 = normal(q[(i + 3) % 4], c);
131
+ const n2 = normal(c, q[(i + 1) % 4]);
132
+ const k = pad / (1 + n1.x * n2.x + n1.y * n2.y);
133
+ return {
134
+ x: c.x + (n1.x + n2.x) * k,
135
+ y: c.y + (n1.y + n2.y) * k
136
+ };
137
+ });
138
+ }
139
+ function buildSelectionLayer(opts, passes) {
140
+ const { stroke, pad } = resolveOutlineStroke(opts.outline);
141
+ const handles = passes.handles && opts.handles !== false ? resolveHandles(opts.handles || void 0) : null;
142
+ const { handlesOf, resizeHandles } = opts;
143
+ const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;
144
+ const getPose = opts.getPose;
145
+ const poseBounds = getPose ? containerAwareBoundsResolver(getPose, d, opts.getChildren, opts.isContainer, opts.scene) : null;
146
+ const shapeOutliner = opts.outline?.follow === "shape" && opts.scene ? createShapeOutliner() : null;
147
+ const rotationHandleDistance = passes.handles ? rotationBadgeOf(opts)?.distancePx ?? null : null;
148
+ return {
149
+ id: passes.id,
150
+ label: passes.label,
151
+ space: "screen",
152
+ draw: (data, view) => {
153
+ const chromeState = asChromeState(data);
154
+ const allIds = opts.getSelection ? opts.getSelection() : chromeSelectionIds(chromeState);
155
+ if (allIds.length === 0) return [];
156
+ const suppressed = opts.getSuppressedIds?.();
157
+ const ids = suppressed && suppressed.size > 0 ? allIds.filter((id) => !suppressed.has(id)) : allIds;
158
+ if (ids.length === 0) return [];
159
+ const isVisible = asIsVisible(data);
160
+ const showOutline = passes.outline && (isVisible ? isVisible("selection.outline") : true);
161
+ const showHandles = isVisible ? isVisible("selection.resize-handles") : true;
162
+ const showRotation = isVisible ? isVisible("selection.rotation-handle") : true;
163
+ const resolveBounds = poseBounds ? (id) => poseBounds(id, view.scale) : (id) => chromeState?.boundsOf(id) ?? null;
164
+ const resolveTargetBounds = (id) => {
165
+ if (id === MULTI_RESIZE_TARGET_ID && chromeState?.unionBounds != null) return chromeState.unionBounds;
166
+ return resolveBounds(id);
167
+ };
168
+ const out = [];
169
+ if (showOutline) {
170
+ const outlineIdsRaw = opts.getOutlineIds ? opts.getOutlineIds() : opts.getSelection ? ids : chromeState?.selection ?? ids;
171
+ let boxed = suppressed && suppressed.size > 0 ? outlineIdsRaw.filter((id) => !suppressed.has(id)) : outlineIdsRaw;
172
+ if (shapeOutliner && opts.scene) {
173
+ const previews = previewSourcesFrom(data);
174
+ const traced = shapeOutliner.outline(boxed, {
175
+ scene: opts.scene,
176
+ poseOf: (id) => effectivePoseFrom(data, id) ?? getPose?.(id) ?? opts.scene.get(id)?.pose,
177
+ inFlight: (id) => previewPoseIn(previews, id) != null
178
+ }, viewScaleOf(view));
179
+ for (const cmd of shapeOutlineCommands(traced.paths, stroke, view)) out.push(cmd);
180
+ boxed = traced.boxed;
181
+ }
182
+ for (const cmd of outlineCommandsFor(boxed, resolveTargetBounds, stroke, pad, view)) out.push(cmd);
183
+ }
184
+ if (!handles) return out;
185
+ if (showHandles) for (const cmd of handleCommandsFor(ids, resolveTargetBounds, handles, handlesOf, resizeHandles, view)) out.push(cmd);
186
+ if (showRotation && rotationHandleDistance !== null) for (const id of ids) {
187
+ if (!targetCanRotate(chromeState, id)) continue;
188
+ const b = resolveTargetBounds(id);
189
+ if (!b) continue;
190
+ for (const cmd of rotationHandleCommands(b, handles, rotationHandleDistance, view)) out.push(cmd);
191
+ }
192
+ return out;
193
+ }
194
+ };
195
+ }
196
+ /** Where the overlay paints its rotate badge and how big it is, in screen
197
+ * pixels, or `null` when it paints none. The badge's grab region and its
198
+ * slops halo read this too, so all three agree on it. */
199
+ function rotationBadgeOf(opts) {
200
+ const r = opts.rotationHandle;
201
+ if (!r || opts.handles === false) return null;
202
+ return {
203
+ distancePx: r === true ? DEFAULT_ROTATION_HANDLE_DISTANCE : r.distance ?? DEFAULT_ROTATION_HANDLE_DISTANCE,
204
+ sizePx: resolveHandles(opts.handles || void 0).size
205
+ };
206
+ }
207
+ /**
208
+ * `RenderLayer` that draws selection outlines only. Stack alongside
209
+ * `createSelectionHandlesLayer` (or use `createSelectionOverlayLayer`, which
210
+ * runs both passes in one layer) when both are wanted.
211
+ */
212
+ function createSelectionOutlineLayer(opts) {
213
+ return buildSelectionLayer(opts, {
214
+ id: "selection-outline",
215
+ label: "Selection outline",
216
+ outline: true,
217
+ handles: false
218
+ });
219
+ }
220
+ /**
221
+ * `RenderLayer` that draws selection handles only. Stack on top of
222
+ * `createSelectionOutlineLayer` (handles render on top of the outline).
223
+ */
224
+ function createSelectionHandlesLayer(opts) {
225
+ return buildSelectionLayer(opts, {
226
+ id: "selection-handles",
227
+ label: "Selection handles",
228
+ outline: false,
229
+ handles: true
230
+ });
231
+ }
232
+ /**
233
+ * Draws outlines then handles in a single layer. Exactly equivalent to
234
+ * stacking `createSelectionOutlineLayer` and `createSelectionHandlesLayer` —
235
+ * all three run the same body. Pass `handles: false` to render outlines only.
236
+ */
237
+ function createSelectionOverlayLayer(opts) {
238
+ return buildSelectionLayer(opts, {
239
+ id: "selection-overlay",
240
+ label: "Selection",
241
+ outline: true,
242
+ handles: true
243
+ });
244
+ }
245
+ /** Pull a chrome-caps visibility predicate off the draw `data` envelope.
246
+ * Returns `null` when the caller passed bare data (no `getIsVisible`
247
+ * thunk) — the layer then renders unconditionally. */
248
+ function asIsVisible(data) {
249
+ const maybe = data;
250
+ if (typeof maybe?.getIsVisible === "function") return maybe.getIsVisible();
251
+ return null;
252
+ }
253
+ /** The ids the handle pass works against when the layer takes its selection
254
+ * from the envelope: the synthetic union id for a multi-selection, the
255
+ * selection itself otherwise. */
256
+ function chromeSelectionIds(state) {
257
+ if (!state) return [];
258
+ if (state.multiActive) return [MULTI_RESIZE_TARGET_ID];
259
+ return state.selection;
260
+ }
261
+ /** Pull live `ChromeState` off the draw `data` envelope. Returns `null` for
262
+ * callers that pass plain data with no `getChromeState` thunk — the layer
263
+ * then resolves the multi-union via the supplied `getPose` resolver. */
264
+ function asChromeState(data) {
265
+ const maybe = data;
266
+ if (typeof maybe?.getChromeState === "function") return maybe.getChromeState();
267
+ return null;
268
+ }
269
+
270
+ export { composeSelectionPose, createSelectionHandlesLayer, createSelectionOutlineLayer, createSelectionOverlayLayer, rotationBadgeOf };
271
+ //# sourceMappingURL=overlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay.js","names":[],"sources":["../../src/chrome/overlay.ts"],"sourcesContent":["/**\n * Selection overlay primitives — render layers for drawing selection\n * outlines and resize handles.\n *\n * **Pose shape:** TPose is generic; callers pass `poseDescriptor` for poses\n * `AUTO_POSE_DESCRIPTOR` can't read. Container ids reduce via `unionAabb`\n * over the projected AABBs.\n */\n\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport type {\n SelectionHandlesLayerOptions, SelectionOutlineLayerOptions, SelectionOverlayLayerOptions,\n} from '@weasel-js/core';\nimport type { NodeId } from '@weasel-js/core';\nimport type { RenderLayer } from '@weasel-js/core';\nimport type { PoseDescriptor } from '@weasel-js/core/engine';\nimport { containerAwareBoundsResolver } from './selectionPose';\nimport { targetCorners, targetTransformOf, type TargetTransform } from '@weasel-js/core';\nimport { AUTO_POSE_DESCRIPTOR } from '@weasel-js/core/engine';\nimport type { CommandStroke } from '@weasel-js/paint';\nimport { DEFAULT_ROTATION_HANDLE_DISTANCE, targetCanRotate } from './rotationHandleGeometry';\nimport type { Bounds } from '@weasel-js/core';\nimport type { ChromeState } from '@weasel-js/core';\nimport { MULTI_RESIZE_TARGET_ID } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { viewToTransform } from '@weasel-js/core/engine';\nimport { worldToScreen } from '@weasel-js/core/engine';\nimport { PATH_L, PATH_M, PATH_Z } from '@weasel-js/geom';\nimport { effectivePoseFrom, previewPoseIn, previewSourcesFrom } from '@weasel-js/core';\nimport { rotationHandleCommands } from './rotationBadge';\nimport { createShapeOutliner, shapeOutlineCommands, viewScaleOf } from './shapeOutline';\nimport {\n handleCommandsFor, rectPathFor, resolveHandles,\n} from './handleCommands';\n\nexport { composeSelectionPose, type ComposeSelectionPoseOptions } from './selectionPose';\n\n/** Project world AABB into screen-space AABB using the active view. */\nfunction projectBounds<B extends Bounds>(b: B, view: View): B {\n const t = viewToTransform(view);\n const [sx, sy] = worldToScreen(b.x, b.y, t);\n const [w, h] = [b.width * view.scale.x, b.height * view.scale.y];\n return { ...b, x: Math.min(sx, sx + w), y: Math.min(sy, sy + h), width: Math.abs(w), height: Math.abs(h) };\n}\n\nconst DEFAULT_OUTLINE: Required<Pick<CommandStroke, 'paint' | 'width'>> & { pad: number } = {\n paint: { kind: 'solid', color: '#f0e0a8' },\n width: 2,\n pad: 1,\n};\nfunction resolveOutlineStroke(opts?: CommandStroke & { pad?: number; follow?: unknown }): {\n stroke: CommandStroke;\n pad: number;\n} {\n // Everything the consumer set on the stroke reaches the renderer; only the\n // paint and width take a default, and the layer's own `pad` / `follow` stay out.\n const { pad, follow: _follow, ...rest } = opts ?? {};\n return {\n stroke: {\n ...rest,\n paint: rest.paint ?? DEFAULT_OUTLINE.paint,\n width: rest.width ?? DEFAULT_OUTLINE.width,\n },\n pad: pad ?? DEFAULT_OUTLINE.pad,\n };\n}\n\n/** GL helper: emit an outline command for one bounds entry. */\nfunction outlineCommandsFor(\n ids: readonly string[],\n resolveBounds: (id: string) => Bounds | null,\n stroke: CommandStroke,\n pad: number,\n view: View,\n): DrawCommand[] {\n const out: DrawCommand[] = [];\n const align = stroke.align ?? 'center';\n const width = resolveScreenLength(stroke.width ?? 1, 1);\n for (const id of ids) {\n const worldB = resolveBounds(id);\n if (!worldB) continue;\n const b = projectBounds(worldB, view);\n const padded = {\n x: b.x - pad,\n y: b.y - pad,\n width: b.width + pad * 2,\n height: b.height + pad * 2,\n };\n const xf = targetTransformOf(worldB);\n if (xf.identity) {\n // Upright, the renderer aligns the stroke on the rect itself.\n out.push({ kind: 'path', path: rectPathFor(padded.x, padded.y, padded.width, padded.height), stroke });\n continue;\n }\n // Turned or skewed, the target lands on screen as a parallelogram, so the\n // outline is traced through its projected corners, with the alignment's\n // half-width shift folded into the offset.\n const shift = align === 'outer' ? width / 2 : align === 'inner' ? -width / 2 : 0;\n const q = screenCorners(worldB, xf, view, pad + shift);\n out.push({\n kind: 'path',\n path: {\n kind: 'polygon',\n commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L, PATH_Z]),\n coords: new Float32Array([q[0].x, q[0].y, q[1].x, q[1].y, q[2].x, q[2].y, q[3].x, q[3].y]),\n fillRule: 'nonzero',\n },\n stroke: { ...stroke, align: 'center' },\n });\n }\n return out;\n}\n\n/**\n * A framed target's corners on screen, TL/TR/BR/BL, each pushed `pad` screen\n * pixels out from both edges that meet there.\n */\nfunction screenCorners(\n worldB: Bounds,\n xf: TargetTransform,\n view: View,\n pad: number,\n): { x: number; y: number }[] {\n const t = viewToTransform(view);\n const q = targetCorners(worldB, xf).map((w) => {\n const [x, y] = worldToScreen(w.x, w.y, t);\n return { x, y };\n });\n if (pad === 0) return q;\n const [ccx, ccy] = worldToScreen(worldB.x + worldB.width / 2, worldB.y + worldB.height / 2, t);\n const normal = (a: { x: number; y: number }, b: { x: number; y: number }) => {\n let nx = -(b.y - a.y), ny = b.x - a.x;\n const l = Math.hypot(nx, ny) || 1;\n nx /= l; ny /= l;\n const mx = (a.x + b.x) / 2 - ccx, my = (a.y + b.y) / 2 - ccy;\n return nx * mx + ny * my < 0 ? { x: -nx, y: -ny } : { x: nx, y: ny };\n };\n return q.map((c, i) => {\n const n1 = normal(q[(i + 3) % 4], c);\n const n2 = normal(c, q[(i + 1) % 4]);\n // The point `pad` off both edge lines.\n const k = pad / (1 + n1.x * n2.x + n1.y * n2.y);\n return { x: c.x + (n1.x + n2.x) * k, y: c.y + (n1.y + n2.y) * k };\n });\n}\n\n/** Which passes a selection layer runs. The three exported factories differ\n * only in this — everything else they do is shared, so a fix to one is a fix\n * to all three. */\ninterface SelectionPasses {\n readonly id: string;\n readonly label: string;\n readonly outline: boolean;\n readonly handles: boolean;\n}\n\nfunction buildSelectionLayer<TPose>(\n opts: SelectionOverlayLayerOptions<TPose>,\n passes: SelectionPasses,\n): RenderLayer<unknown> {\n const { stroke, pad } = resolveOutlineStroke(opts.outline);\n const handlesEnabled = passes.handles && opts.handles !== false;\n const handles = handlesEnabled ? resolveHandles(opts.handles || undefined) : null;\n const { handlesOf, resizeHandles } = opts;\n const d = (opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const getPose = opts.getPose;\n const poseBounds = getPose\n ? containerAwareBoundsResolver(getPose, d, opts.getChildren, opts.isContainer, opts.scene)\n : null;\n const shapeOutliner = opts.outline?.follow === 'shape' && opts.scene ? createShapeOutliner() : null;\n const rotationHandleDistance = passes.handles\n ? rotationBadgeOf(opts)?.distancePx ?? null\n : null;\n\n return {\n id: passes.id,\n label: passes.label,\n space: 'screen',\n draw: (data, view) => {\n // The synthetic multi-resize id resolves to `ChromeState.unionBounds`,\n // the same value the affordance hit-tester reads, so painted chrome\n // and its hit region stay in agreement. With no chromeState on the\n // draw envelope, fall through to the supplied resolver.\n const chromeState = asChromeState(data);\n const allIds = opts.getSelection\n ? opts.getSelection()\n : chromeSelectionIds(chromeState);\n if (allIds.length === 0) return [];\n const suppressed = opts.getSuppressedIds?.();\n const ids = suppressed && suppressed.size > 0\n ? allIds.filter((id) => !suppressed.has(id as unknown as string))\n : allIds;\n if (ids.length === 0) return [];\n // Chrome-caps: gate each pass on its canonical id. When no\n // `getIsVisible` is wired, every pass runs.\n const isVisible = asIsVisible(data);\n const showOutline = passes.outline && (isVisible ? isVisible('selection.outline') : true);\n const showHandles = isVisible ? isVisible('selection.resize-handles') : true;\n const showRotation = isVisible ? isVisible('selection.rotation-handle') : true;\n\n const resolveBounds = poseBounds\n ? (id: string) => poseBounds(id, view.scale)\n : (id: string) => chromeState?.boundsOf(id) ?? null;\n const resolveTargetBounds = (id: string): Bounds | null => {\n if (id === MULTI_RESIZE_TARGET_ID && chromeState?.unionBounds != null) {\n return chromeState.unionBounds;\n }\n return resolveBounds(id);\n };\n\n const out: DrawCommand[] = [];\n if (showOutline) {\n const outlineIdsRaw = opts.getOutlineIds\n ? opts.getOutlineIds()\n : (opts.getSelection ? ids : (chromeState?.selection ?? ids));\n const outlineIds = suppressed && suppressed.size > 0\n ? outlineIdsRaw.filter((id) => !suppressed.has(id as unknown as string))\n : outlineIdsRaw;\n let boxed = outlineIds as readonly string[];\n if (shapeOutliner && opts.scene) {\n const previews = previewSourcesFrom(data);\n const traced = shapeOutliner.outline(boxed, {\n scene: opts.scene,\n poseOf: (id) => effectivePoseFrom(data, id) ?? getPose?.(id as never) ?? opts.scene!.get(id as NodeId)?.pose,\n inFlight: (id) => previewPoseIn(previews, id) != null,\n }, viewScaleOf(view));\n for (const cmd of shapeOutlineCommands(traced.paths, stroke, view)) out.push(cmd);\n boxed = traced.boxed;\n }\n for (const cmd of outlineCommandsFor(boxed, resolveTargetBounds, stroke, pad, view)) out.push(cmd);\n }\n if (!handles) return out;\n if (showHandles) {\n for (const cmd of handleCommandsFor(ids, resolveTargetBounds, handles, handlesOf, resizeHandles, view)) out.push(cmd);\n }\n if (showRotation && rotationHandleDistance !== null) {\n for (const id of ids) {\n // Paint the badge only where the rotate affordance offers its grab region.\n if (!targetCanRotate(chromeState, id)) continue;\n const b = resolveTargetBounds(id);\n if (!b) continue;\n for (const cmd of rotationHandleCommands(b, handles, rotationHandleDistance, view)) {\n out.push(cmd);\n }\n }\n }\n return out;\n },\n };\n}\n\n/** Where the overlay paints its rotate badge and how big it is, in screen\n * pixels, or `null` when it paints none. The badge's grab region and its\n * slops halo read this too, so all three agree on it. */\nexport function rotationBadgeOf(\n opts: Pick<SelectionOverlayLayerOptions<unknown>, 'handles' | 'rotationHandle'>,\n): { distancePx: number; sizePx: number } | null {\n const r = opts.rotationHandle;\n if (!r || opts.handles === false) return null;\n return {\n distancePx: r === true ? DEFAULT_ROTATION_HANDLE_DISTANCE : r.distance ?? DEFAULT_ROTATION_HANDLE_DISTANCE,\n sizePx: resolveHandles(opts.handles || undefined).size,\n };\n}\n/**\n * `RenderLayer` that draws selection outlines only. Stack alongside\n * `createSelectionHandlesLayer` (or use `createSelectionOverlayLayer`, which\n * runs both passes in one layer) when both are wanted.\n */\nexport function createSelectionOutlineLayer<TPose>(\n opts: SelectionOutlineLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-outline',\n label: 'Selection outline',\n outline: true,\n handles: false,\n });\n}\n\n/**\n * `RenderLayer` that draws selection handles only. Stack on top of\n * `createSelectionOutlineLayer` (handles render on top of the outline).\n */\nexport function createSelectionHandlesLayer<TPose>(\n opts: SelectionHandlesLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-handles',\n label: 'Selection handles',\n outline: false,\n handles: true,\n });\n}\n\n/**\n * Draws outlines then handles in a single layer. Exactly equivalent to\n * stacking `createSelectionOutlineLayer` and `createSelectionHandlesLayer` —\n * all three run the same body. Pass `handles: false` to render outlines only.\n */\nexport function createSelectionOverlayLayer<TPose>(\n opts: SelectionOverlayLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-overlay',\n label: 'Selection',\n outline: true,\n handles: true,\n });\n}\n\n/** Pull a chrome-caps visibility predicate off the draw `data` envelope.\n * Returns `null` when the caller passed bare data (no `getIsVisible`\n * thunk) — the layer then renders unconditionally. */\nfunction asIsVisible(data: unknown): ((id: string) => boolean) | null {\n const maybe = data as { getIsVisible?: () => (id: string) => boolean };\n if (typeof maybe?.getIsVisible === 'function') return maybe.getIsVisible();\n return null;\n}\n\n/** The ids the handle pass works against when the layer takes its selection\n * from the envelope: the synthetic union id for a multi-selection, the\n * selection itself otherwise. */\nfunction chromeSelectionIds(state: ChromeState | null): readonly NodeId[] {\n if (!state) return [];\n if (state.multiActive) return [MULTI_RESIZE_TARGET_ID as NodeId];\n return state.selection;\n}\n\n/** Pull live `ChromeState` off the draw `data` envelope. Returns `null` for\n * callers that pass plain data with no `getChromeState` thunk — the layer\n * then resolves the multi-union via the supplied `getPose` resolver. */\nfunction asChromeState(data: unknown): ChromeState | null {\n const maybe = data as { getChromeState?: () => ChromeState };\n if (typeof maybe?.getChromeState === 'function') return maybe.getChromeState();\n return null;\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,SAAS,cAAgC,GAAM,MAAe;CAC5D,MAAM,IAAI,gBAAgB,IAAI;CAC9B,MAAM,CAAC,IAAI,MAAM,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC;CAC1C,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE,QAAQ,KAAK,MAAM,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC;CAC/D,OAAO;EAAE,GAAG;EAAG,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC;EAAG,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC;EAAG,OAAO,KAAK,IAAI,CAAC;EAAG,QAAQ,KAAK,IAAI,CAAC;CAAE;AAC3G;AAEA,IAAM,kBAAsF;CAC1F,OAAO;EAAE,MAAM;EAAS,OAAO;CAAU;CACzC,OAAO;CACP,KAAK;AACP;AACA,SAAS,qBAAqB,MAG5B;CAGA,MAAM,EAAE,KAAK,QAAQ,SAAS,GAAG,SAAS,QAAQ,CAAC;CACnD,OAA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Y,MAAM,OAAO,mCAAmC,EAAE,YAAY;EAC1E,QAAQ,eAAe,KAAK,WAAW,MAAS,CAAC,CAAC;CACpD;AACF;;;;;;AAMA,SAAgB,4BACd,MACsB;CACtB,OAAO,oBAAoB,MAAM;EAC/B,IAAI;EACJ,OAAO;EACP,SAAS;EACT,SAAS;CACX,CAAC;AACH;;;;;AAMA,SAAgB,4BACd,MACsB;CACtB,OAAO,oBAAoB,MAAM;EAC/B,IAAI;EACJ,OAAO;EACP,SAAS;EACT,SAAS;CACX,CAAC;AACH;;;;;;AAOA,SAAgB,4BACd,MACsB;CACtB,OAAO,oBAAoB,MAAM;EAC/B,IAAI;EACJ,OAAO;EACP,SAAS;EACT,SAAS;CACX,CAAC;AACH;;;;AAKA,SAAS,YAAY,MAAiD;CACpE,MAAM,QAAQ;CACd,IAAI,OAAO,OAAO,iBAAiB,YAAY,OAAO,MAAM,aAAa;CACzE,OAAO;AACT;;;;AAKA,SAAS,mBAAmB,OAA8C;CACxE,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,IAAI,MAAM,aAAa,OAAO,CAAC,sBAAgC;CAC/D,OAAO,MAAM;AACf;;;;AAKA,SAAS,cAAc,MAAmC;CACxD,MAAM,QAAQ;CACd,IAAI,OAAO,OAAO,mBAAmB,YAAY,OAAO,MAAM,eAAe;CAC7E,OAAO;AACT"}
@@ -0,0 +1,132 @@
1
+ import { rotationHandle } from "./rotationHandleGeometry.js";
2
+ import { resolveScreenLength } from "@weasel-js/paint";
3
+ import { viewToTransform, worldToScreen } from "@weasel-js/core/engine";
4
+ import { PATH_L, PATH_M } from "@weasel-js/geom";
5
+ import { mat3 } from "@weasel-js/renderer";
6
+
7
+ // src/chrome/rotationBadge.ts
8
+ /** GL helper: emit a curved double-headed arrow, the rotate badge above the
9
+ * rect. The arc opens *toward* the object (apex on top, mouth pointing
10
+ * down), with an arrowhead at each endpoint pointing along the tangent. */
11
+ function rotationHandleCommands(worldB, handles, distance, view) {
12
+ const hWorld = rotationHandle(worldB, distance, view.scale);
13
+ const rotation = hWorld.angle;
14
+ const t = viewToTransform(view);
15
+ const [scx, scy] = worldToScreen(hWorld.cx, hWorld.cy, t);
16
+ const size = handles.size;
17
+ const arcRadius = size;
18
+ const ARC_HALF_ANGLE = Math.PI * 240 / 360 / 2;
19
+ const N_SEGS = 18;
20
+ const arcWidth = resolveScreenLength(handles.outline.width ?? 1, 1) * 1.5;
21
+ const stroke = {
22
+ paint: handles.fill.paint,
23
+ width: arcWidth,
24
+ cap: "round",
25
+ join: "round"
26
+ };
27
+ const cmds = [PATH_M];
28
+ const xs = [];
29
+ const ys = [];
30
+ for (let i = 0; i <= N_SEGS; i++) {
31
+ const angle = ARC_HALF_ANGLE - i / N_SEGS * ARC_HALF_ANGLE * 2;
32
+ xs.push(arcRadius * Math.sin(angle));
33
+ ys.push(-arcRadius * Math.cos(angle));
34
+ if (i > 0) cmds.push(PATH_L);
35
+ }
36
+ const arcCoords = [];
37
+ for (let i = 0; i < xs.length; i++) arcCoords.push(xs[i], ys[i]);
38
+ const arcPath = {
39
+ kind: "polygon",
40
+ commands: new Uint8Array(cmds),
41
+ coords: new Float32Array(arcCoords),
42
+ fillRule: "nonzero"
43
+ };
44
+ const headLen = size * .6;
45
+ const headWidth = size * .4;
46
+ const arrowHead = (endX, endY, tx, ty) => {
47
+ const len = Math.hypot(tx, ty) || 1;
48
+ const ux = tx / len;
49
+ const uy = ty / len;
50
+ const px = -uy;
51
+ const py = ux;
52
+ const tipX = endX + ux * headLen;
53
+ const tipY = endY + uy * headLen;
54
+ const baseLeftX = endX + px * (headWidth / 2);
55
+ const baseLeftY = endY + py * (headWidth / 2);
56
+ const baseRightX = endX - px * (headWidth / 2);
57
+ const baseRightY = endY - py * (headWidth / 2);
58
+ return {
59
+ kind: "polygon",
60
+ commands: new Uint8Array([
61
+ PATH_M,
62
+ PATH_L,
63
+ PATH_L,
64
+ PATH_L
65
+ ]),
66
+ coords: new Float32Array([
67
+ tipX,
68
+ tipY,
69
+ baseLeftX,
70
+ baseLeftY,
71
+ baseRightX,
72
+ baseRightY,
73
+ tipX,
74
+ tipY
75
+ ]),
76
+ fillRule: "nonzero"
77
+ };
78
+ };
79
+ const angleA = ARC_HALF_ANGLE;
80
+ const endAX = arcRadius * Math.sin(angleA);
81
+ const endAY = -arcRadius * Math.cos(angleA);
82
+ const tangentAX = Math.cos(angleA);
83
+ const tangentAY = Math.sin(angleA);
84
+ const angleB = -ARC_HALF_ANGLE;
85
+ const endBX = arcRadius * Math.sin(angleB);
86
+ const endBY = -arcRadius * Math.cos(angleB);
87
+ const tangentBX = -Math.cos(angleB);
88
+ const tangentBY = -Math.sin(angleB);
89
+ const headA = arrowHead(endAX, endAY, tangentAX, tangentAY);
90
+ const headB = arrowHead(endBX, endBY, tangentBX, tangentBY);
91
+ let transform = mat3.translated(mat3.identity(), scx, scy);
92
+ if (rotation !== 0) {
93
+ const c = Math.cos(rotation);
94
+ const s = Math.sin(rotation);
95
+ const rot = new Float32Array([
96
+ c,
97
+ s,
98
+ 0,
99
+ -s,
100
+ c,
101
+ 0,
102
+ 0,
103
+ 0,
104
+ 1
105
+ ]);
106
+ transform = mat3.multiply(transform, rot);
107
+ }
108
+ return [{
109
+ kind: "group",
110
+ transform,
111
+ children: [
112
+ {
113
+ kind: "path",
114
+ path: arcPath,
115
+ stroke
116
+ },
117
+ {
118
+ kind: "path",
119
+ path: headA,
120
+ fill: handles.fill
121
+ },
122
+ {
123
+ kind: "path",
124
+ path: headB,
125
+ fill: handles.fill
126
+ }
127
+ ]
128
+ }];
129
+ }
130
+
131
+ export { rotationHandleCommands };
132
+ //# sourceMappingURL=rotationBadge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotationBadge.js","names":[],"sources":["../../src/chrome/rotationBadge.ts"],"sourcesContent":["import type { DrawCommand } from '@weasel-js/renderer';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport { mat3, type GlMat3 } from '@weasel-js/renderer';\nimport type { CommandStroke } from '@weasel-js/paint';\nimport { PATH_L, PATH_M, type PolygonPath } from '@weasel-js/geom';\nimport { rotationHandle } from './rotationHandleGeometry';\nimport type { Bounds } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { viewToTransform } from '@weasel-js/core/engine';\nimport { worldToScreen } from '@weasel-js/core/engine';\nimport type { ResolvedHandles } from './handleCommands';\n\n/** GL helper: emit a curved double-headed arrow, the rotate badge above the\n * rect. The arc opens *toward* the object (apex on top, mouth pointing\n * down), with an arrowhead at each endpoint pointing along the tangent. */\nexport function rotationHandleCommands(\n worldB: Bounds,\n handles: ResolvedHandles,\n distance: number,\n view: View,\n): DrawCommand[] {\n const hWorld = rotationHandle(worldB, distance, view.scale);\n const rotation = hWorld.angle;\n const t = viewToTransform(view);\n const [scx, scy] = worldToScreen(hWorld.cx, hWorld.cy, t);\n const size = handles.size;\n const arcRadius = size;\n const ARC_HALF_ANGLE = (Math.PI * 240) / 360 / 2; // 120°\n const N_SEGS = 18;\n const arcWidth = resolveScreenLength(handles.outline.width ?? 1, 1) * 1.5;\n const stroke: CommandStroke = {\n paint: handles.fill.paint,\n width: arcWidth,\n cap: 'round',\n join: 'round',\n };\n // The arc as a polyline in handle-local coords, centered on the handle\n // anchor: apex at -y, endpoints at +y near the rect side.\n const cmds: number[] = [PATH_M];\n const xs: number[] = [];\n const ys: number[] = [];\n for (let i = 0; i <= N_SEGS; i++) {\n const t = i / N_SEGS;\n const angle = ARC_HALF_ANGLE - t * ARC_HALF_ANGLE * 2;\n xs.push(arcRadius * Math.sin(angle));\n ys.push(-arcRadius * Math.cos(angle));\n if (i > 0) cmds.push(PATH_L);\n }\n const arcCoords: number[] = [];\n for (let i = 0; i < xs.length; i++) {\n arcCoords.push(xs[i], ys[i]);\n }\n const arcPath: PolygonPath = {\n kind: 'polygon',\n commands: new Uint8Array(cmds),\n coords: new Float32Array(arcCoords),\n fillRule: 'nonzero',\n };\n // Arrowheads: small filled triangles at each endpoint, pointing along\n // the tangent (away from the arc body).\n const headLen = size * 0.6;\n const headWidth = size * 0.4;\n const arrowHead = (endX: number, endY: number, tx: number, ty: number): PolygonPath => {\n // Normalize tangent.\n const len = Math.hypot(tx, ty) || 1;\n const ux = tx / len;\n const uy = ty / len;\n // Perpendicular (rotate tangent 90° CCW).\n const px = -uy;\n const py = ux;\n // Triangle: tip is endX+ux*headLen, base is endX (with +/- headWidth/2 along p).\n const tipX = endX + ux * headLen;\n const tipY = endY + uy * headLen;\n const baseLeftX = endX + px * (headWidth / 2);\n const baseLeftY = endY + py * (headWidth / 2);\n const baseRightX = endX - px * (headWidth / 2);\n const baseRightY = endY - py * (headWidth / 2);\n return {\n kind: 'polygon',\n commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L]),\n coords: new Float32Array([tipX, tipY, baseLeftX, baseLeftY, baseRightX, baseRightY, tipX, tipY]),\n fillRule: 'nonzero',\n };\n };\n // Endpoint A (right side, angle = +ARC_HALF_ANGLE). Arc point:\n // (sin(a)·R, -cos(a)·R). Tangent (d/da) = (cos(a)·R, sin(a)·R).\n const angleA = ARC_HALF_ANGLE;\n const endAX = arcRadius * Math.sin(angleA);\n const endAY = -arcRadius * Math.cos(angleA);\n const tangentAX = Math.cos(angleA);\n const tangentAY = Math.sin(angleA);\n // Endpoint B (left side, angle = -ARC_HALF_ANGLE): tangent in the\n // outward direction is the negation of the above.\n const angleB = -ARC_HALF_ANGLE;\n const endBX = arcRadius * Math.sin(angleB);\n const endBY = -arcRadius * Math.cos(angleB);\n const tangentBX = -Math.cos(angleB);\n const tangentBY = -Math.sin(angleB);\n const headA = arrowHead(endAX, endAY, tangentAX, tangentAY);\n const headB = arrowHead(endBX, endBY, tangentBX, tangentBY);\n // Build transform: translate(scx, scy) [* rotate(rotation)].\n let transform = mat3.translated(mat3.identity(), scx, scy);\n if (rotation !== 0) {\n const c = Math.cos(rotation);\n const s = Math.sin(rotation);\n const rot = new Float32Array([c, s, 0, -s, c, 0, 0, 0, 1]) as GlMat3;\n transform = mat3.multiply(transform, rot);\n }\n return [\n {\n kind: 'group',\n transform,\n children: [\n { kind: 'path', path: arcPath, stroke },\n { kind: 'path', path: headA, fill: handles.fill },\n { kind: 'path', path: headB, fill: handles.fill },\n ],\n },\n ];\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,uBACd,QACA,SACA,UACA,MACe;CACf,MAAM,SAAS,eAAe,QAAQ,UAAU,KAAK,KAAK;CAC1D,MAAM,WAAW,OAAO;CACxB,MAAM,IAAI,gBAAgB,IAAI;CAC9B,MAAM,CAAC,KAAK,OAAO,cAAc,OAAO,IAAI,OAAO,IAAI,CAAC;CACxD,MAAM,OAAO,QAAQ;CACrB,MAAM,YAAY;CAClB,MAAM,iBAAkB,KAAK,KAAK,MAAO,MAAM;CAC/C,MAAM,SAAS;CACf,MAAM,WAAW,oBAAoB,QAAQ,QAAQ,SAAS,GAAG,CAAC,IAAI;CACtE,MAAM,SAAwB;EAC5B,OAAO,QAAQ,KAAK;EACpB,OAAO;EACP,KAAK;EACL,MAAM;CACR;CAGA,MAAM,OAAiB,CAAC,MAAM;CAC9B,MAAM,KAAe,CAAC;CACtB,MAAM,KAAe,CAAC;CACtB,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,KAAK;EAEhC,MAAM,QAAQ,iBADJ,IAAI,SACqB,iBAAiB;EACpD,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC;EACnC,GAAG,KAAK,CAAC,YAAY,KAAK,IAAI,KAAK,CAAC;EACpC,IAAI,IAAI,GAAG,KAAK,KAAK,MAAM;CAC7B;CACA,MAAM,YAAsB,CAAC;CAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,QAAQ,KAC7B,UAAU,KAAK,GAAG,IAAI,GAAG,EAAE;CAE7B,MAAM,UAAuB;EAC3B,MAAM;EACN,UAAU,IAAI,WAAW,IAAI;EAC7B,QAAQ,IAAI,aAAa,SAAS;EAClC,UAAU;CACZ;CAGA,MAAM,UAAU,OAAO;CACvB,MAAM,YAA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AI,QAAQ;EAC3B,MAAM,MAAM,IAAI,aAAa;GAAC;GAAG;GAAG;GAAG,CAAC;GAAG;GAAG;GAAG;GAAG;GAAG;EAAC,CAAC;EACzD,YAAY,KAAK,SAAS,WAAW,GAAG;CAC1C;CACA,OAAO,CACL;EACE,MAAM;EACN;EACA,UAAU;GACR;IAAE,MAAM;IAAQ,MAAM;IAAS;GAAO;GACtC;IAAE,MAAM;IAAQ,MAAM;IAAO,MAAM,QAAQ;GAAK;GAChD;IAAE,MAAM;IAAQ,MAAM;IAAO,MAAM,QAAQ;GAAK;EAClD;CACF,CACF;AACF"}
@@ -0,0 +1,49 @@
1
+ import { MULTI_RESIZE_TARGET_ID, ROTATION_HANDLE_BASE_PX, localToWorld, normalToWorld, targetTransformOf } from "@weasel-js/core";
2
+ import { standoff } from "@weasel-js/geom";
3
+
4
+ // src/chrome/rotationHandleGeometry.ts
5
+ /** Default world-space distance from the rect's top edge to the rotation
6
+ * handle's center. Matches the demo's visual default; consumers can
7
+ * override per-call. Unscaled — kit-internal use sites multiply by
8
+ * `DeviceProfile.targetScale`. */
9
+ var DEFAULT_ROTATION_HANDLE_DISTANCE = ROTATION_HANDLE_BASE_PX;
10
+ /** Rotation handle for a box as its frame draws it: `distance` pixels off the
11
+ * top edge's midpoint, along that edge's outward normal as it lands on a
12
+ * screen whose per-axis zoom is `scale`. With no `scale`, a pixel is a world
13
+ * unit. */
14
+ function rotationHandle(pose, distance = DEFAULT_ROTATION_HANDLE_DISTANCE, scale = UNIT_SCALE) {
15
+ const xf = targetTransformOf(pose);
16
+ const top = localToWorld(xf, pose.x + pose.width / 2, pose.y);
17
+ const p = standoff(top, normalToWorld(xf, {
18
+ x: 0,
19
+ y: -1
20
+ }), distance, scale);
21
+ return {
22
+ cx: p.x,
23
+ cy: p.y,
24
+ angle: Math.atan2(p.nx, -p.ny)
25
+ };
26
+ }
27
+ var UNIT_SCALE = {
28
+ x: 1,
29
+ y: 1
30
+ };
31
+ /** Square hit-test: returns true if `(px, py)` is within `radius` of the
32
+ * handle's center on both axes. Mirrors `hitCornerHandle`. */
33
+ function hitRotationHandle(handle, px, py, radius) {
34
+ return Math.abs(px - handle.cx) <= radius && Math.abs(py - handle.cy) <= radius;
35
+ }
36
+ /** Whether a selection target can take a rotation: a node whose pose carries
37
+ * one, or the synthetic multi id when every selected member can. The rotate
38
+ * ring, its badge's grab region and the painted badge all ask this, so a
39
+ * badge is painted only where it can be grabbed. With no `canRotate` on the
40
+ * state, everything can. */
41
+ function targetCanRotate(state, id) {
42
+ const can = state?.canRotate;
43
+ if (!can) return true;
44
+ if (id === MULTI_RESIZE_TARGET_ID) return state.selection.every((m) => can.call(state, m));
45
+ return can.call(state, id);
46
+ }
47
+
48
+ export { DEFAULT_ROTATION_HANDLE_DISTANCE, hitRotationHandle, rotationHandle, targetCanRotate };
49
+ //# sourceMappingURL=rotationHandleGeometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotationHandleGeometry.js","names":[],"sources":["../../src/chrome/rotationHandleGeometry.ts"],"sourcesContent":["import { localToWorld, normalToWorld, targetTransformOf } from '@weasel-js/core';\nimport { MULTI_RESIZE_TARGET_ID, ROTATION_HANDLE_BASE_PX, type ChromeState } from '@weasel-js/core';\nimport { standoff, type PoseLinear, type Scale2 } from '@weasel-js/geom';\n\n/** Default world-space distance from the rect's top edge to the rotation\n * handle's center. Matches the demo's visual default; consumers can\n * override per-call. Unscaled — kit-internal use sites multiply by\n * `DeviceProfile.targetScale`. */\nexport const DEFAULT_ROTATION_HANDLE_DISTANCE = ROTATION_HANDLE_BASE_PX;\n\n/** Rotation handle position in world coords. */\nexport interface RotationHandle {\n /** Handle center in world coords. */\n cx: number;\n cy: number;\n /** How far the handle is turned on screen, radians: the angle from screen\n * up to the top edge's outward normal as it lands there. Equals the pose\n * rotation under uniform zoom. */\n angle: number;\n}\n\n/** Rotation handle for a box as its frame draws it: `distance` pixels off the\n * top edge's midpoint, along that edge's outward normal as it lands on a\n * screen whose per-axis zoom is `scale`. With no `scale`, a pixel is a world\n * unit. */\nexport function rotationHandle(\n pose: { x: number; y: number; width: number; height: number; rotation?: number; transform?: PoseLinear },\n distance: number = DEFAULT_ROTATION_HANDLE_DISTANCE,\n scale: Scale2 = UNIT_SCALE,\n): RotationHandle {\n const xf = targetTransformOf(pose);\n const top = localToWorld(xf, pose.x + pose.width / 2, pose.y);\n const p = standoff(top, normalToWorld(xf, { x: 0, y: -1 }), distance, scale);\n return { cx: p.x, cy: p.y, angle: Math.atan2(p.nx, -p.ny) };\n}\n\nconst UNIT_SCALE: Scale2 = { x: 1, y: 1 };\n\n/** Square hit-test: returns true if `(px, py)` is within `radius` of the\n * handle's center on both axes. Mirrors `hitCornerHandle`. */\nexport function hitRotationHandle(\n handle: Pick<RotationHandle, 'cx' | 'cy'>,\n px: number,\n py: number,\n radius: number,\n): boolean {\n return Math.abs(px - handle.cx) <= radius && Math.abs(py - handle.cy) <= radius;\n}\n\n/** Whether a selection target can take a rotation: a node whose pose carries\n * one, or the synthetic multi id when every selected member can. The rotate\n * ring, its badge's grab region and the painted badge all ask this, so a\n * badge is painted only where it can be grabbed. With no `canRotate` on the\n * state, everything can. */\nexport function targetCanRotate(\n state: Pick<ChromeState, 'canRotate' | 'selection'> | null,\n id: string,\n): boolean {\n const can = state?.canRotate;\n if (!can) return true;\n if (id === MULTI_RESIZE_TARGET_ID) return state.selection.every((m) => can.call(state, m));\n return can.call(state, id);\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,mCAAmC;;;;;AAiBhD,SAAgB,eACd,MACA,WAAmB,kCACnB,QAAgB,YACA;CAChB,MAAM,KAAK,kBAAkB,IAAI;CACjC,MAAM,MAAM,aAAa,IAAI,KAAK,IAAI,KAAK,QAAQ,GAAG,KAAK,CAAC;CAC5D,MAAM,IAAI,SAAS,KAAK,cAAc,IAAI;EAAE,GAAG;EAAG,GAAG;CAAG,CAAC,GAAG,UAAU,KAAK;CAC3E,OAAO;EAAE,IAAI,EAAE;EAAG,IAAI,EAAE;EAAG,OAAO,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;CAAE;AAC5D;AAEA,IAAM,aAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;AAIxC,SAAgB,kBACd,QACA,IACA,IACA,QACS;CACT,OAAO,KAAK,IAAI,KAAK,OAAO,EAAE,KAAK,UAAU,KAAK,IAAI,KAAK,OAAO,EAAE,KAAK;AAC3E;;;;;;AAOA,SAAgB,gBACd,OACA,IACS;CACT,MAAM,MAAM,OAAO;CACnB,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,OAAO,wBAAwB,OAAO,MAAM,UAAU,OAAO,MAAM,IAAI,KAAK,OAAO,CAAC,CAAC;CACzF,OAAO,IAAI,KAAK,OAAO,EAAE;AAC3B"}