@weasel-js/editing 0.0.0-stage → 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 (368) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -2
  3. package/dist/actionGroups.js +27 -0
  4. package/dist/actionGroups.js.map +1 -0
  5. package/dist/actions/align/action.js +105 -0
  6. package/dist/actions/align/action.js.map +1 -0
  7. package/dist/actions/align/align.js +115 -0
  8. package/dist/actions/align/align.js.map +1 -0
  9. package/dist/actions/clipboard/action.js +133 -0
  10. package/dist/actions/clipboard/action.js.map +1 -0
  11. package/dist/actions/clone/action.js +217 -0
  12. package/dist/actions/clone/action.js.map +1 -0
  13. package/dist/actions/clone/behaviors.js +65 -0
  14. package/dist/actions/clone/behaviors.js.map +1 -0
  15. package/dist/actions/delete/delete.js +123 -0
  16. package/dist/actions/delete/delete.js.map +1 -0
  17. package/dist/actions/derivedBox.js +16 -0
  18. package/dist/actions/derivedBox.js.map +1 -0
  19. package/dist/actions/distribute/action.js +96 -0
  20. package/dist/actions/distribute/action.js.map +1 -0
  21. package/dist/actions/distribute/distribute.js +61 -0
  22. package/dist/actions/distribute/distribute.js.map +1 -0
  23. package/dist/actions/distribute/plan.js +55 -0
  24. package/dist/actions/distribute/plan.js.map +1 -0
  25. package/dist/actions/edit/createPaintAction.js +138 -0
  26. package/dist/actions/edit/createPaintAction.js.map +1 -0
  27. package/dist/actions/edit/deselect.js +34 -0
  28. package/dist/actions/edit/deselect.js.map +1 -0
  29. package/dist/actions/edit/duplicate.js +93 -0
  30. package/dist/actions/edit/duplicate.js.map +1 -0
  31. package/dist/actions/edit/group.js +281 -0
  32. package/dist/actions/edit/group.js.map +1 -0
  33. package/dist/actions/edit/ingest.js +114 -0
  34. package/dist/actions/edit/ingest.js.map +1 -0
  35. package/dist/actions/edit/nudge.js +97 -0
  36. package/dist/actions/edit/nudge.js.map +1 -0
  37. package/dist/actions/edit/selectAll.js +48 -0
  38. package/dist/actions/edit/selectAll.js.map +1 -0
  39. package/dist/actions/edit/setFill.js +52 -0
  40. package/dist/actions/edit/setFill.js.map +1 -0
  41. package/dist/actions/edit/setFillOpacity.js +26 -0
  42. package/dist/actions/edit/setFillOpacity.js.map +1 -0
  43. package/dist/actions/edit/setStroke.js +57 -0
  44. package/dist/actions/edit/setStroke.js.map +1 -0
  45. package/dist/actions/edit/setStrokeOpacity.js +28 -0
  46. package/dist/actions/edit/setStrokeOpacity.js.map +1 -0
  47. package/dist/actions/edit/setStrokeWidth.js +53 -0
  48. package/dist/actions/edit/setStrokeWidth.js.map +1 -0
  49. package/dist/actions/edit/setVertexColor.js +45 -0
  50. package/dist/actions/edit/setVertexColor.js.map +1 -0
  51. package/dist/actions/flip/action.js +209 -0
  52. package/dist/actions/flip/action.js.map +1 -0
  53. package/dist/actions/flip/helpers.js +80 -0
  54. package/dist/actions/flip/helpers.js.map +1 -0
  55. package/dist/actions/group/enterGroup.js +81 -0
  56. package/dist/actions/group/enterGroup.js.map +1 -0
  57. package/dist/actions/insert/action.js +152 -0
  58. package/dist/actions/insert/action.js.map +1 -0
  59. package/dist/actions/insert/commit.js +52 -0
  60. package/dist/actions/insert/commit.js.map +1 -0
  61. package/dist/actions/insert/extras.js +88 -0
  62. package/dist/actions/insert/extras.js.map +1 -0
  63. package/dist/actions/insert/frame.js +96 -0
  64. package/dist/actions/insert/frame.js.map +1 -0
  65. package/dist/actions/insert/geometry.js +35 -0
  66. package/dist/actions/insert/geometry.js.map +1 -0
  67. package/dist/actions/insert/lands.js +41 -0
  68. package/dist/actions/insert/lands.js.map +1 -0
  69. package/dist/actions/insert/params.js +42 -0
  70. package/dist/actions/insert/params.js.map +1 -0
  71. package/dist/actions/insert/placeAction.js +137 -0
  72. package/dist/actions/insert/placeAction.js.map +1 -0
  73. package/dist/actions/insert/repositionAction.js +47 -0
  74. package/dist/actions/insert/repositionAction.js.map +1 -0
  75. package/dist/actions/insert/rotateAction.js +34 -0
  76. package/dist/actions/insert/rotateAction.js.map +1 -0
  77. package/dist/actions/insert/session.js +99 -0
  78. package/dist/actions/insert/session.js.map +1 -0
  79. package/dist/actions/insert/shape.js +117 -0
  80. package/dist/actions/insert/shape.js.map +1 -0
  81. package/dist/actions/insert/style.js +23 -0
  82. package/dist/actions/insert/style.js.map +1 -0
  83. package/dist/actions/lassoSelect/action.js +201 -0
  84. package/dist/actions/lassoSelect/action.js.map +1 -0
  85. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
  86. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
  87. package/dist/actions/lockedWrites.js +20 -0
  88. package/dist/actions/lockedWrites.js.map +1 -0
  89. package/dist/actions/move/action.js +138 -0
  90. package/dist/actions/move/action.js.map +1 -0
  91. package/dist/actions/move/behaviors/clampMove.js +42 -0
  92. package/dist/actions/move/behaviors/clampMove.js.map +1 -0
  93. package/dist/actions/move/behaviors/layoutDrop.js +84 -0
  94. package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
  95. package/dist/actions/move/behaviors/pageDrop.js +30 -0
  96. package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
  97. package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
  98. package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
  99. package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
  100. package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
  101. package/dist/actions/move/behaviors/snapToContainer.js +214 -0
  102. package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
  103. package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
  104. package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
  105. package/dist/actions/move/capture.js +116 -0
  106. package/dist/actions/move/capture.js.map +1 -0
  107. package/dist/actions/move/commit/index.js +47 -0
  108. package/dist/actions/move/commit/index.js.map +1 -0
  109. package/dist/actions/move/commit/layoutDrop.js +68 -0
  110. package/dist/actions/move/commit/layoutDrop.js.map +1 -0
  111. package/dist/actions/move/commit/layoutRelease.js +146 -0
  112. package/dist/actions/move/commit/layoutRelease.js.map +1 -0
  113. package/dist/actions/move/commit/pageDrop.js +162 -0
  114. package/dist/actions/move/commit/pageDrop.js.map +1 -0
  115. package/dist/actions/move/commit/rebase.js +24 -0
  116. package/dist/actions/move/commit/rebase.js.map +1 -0
  117. package/dist/actions/move/commit/reparent.js +157 -0
  118. package/dist/actions/move/commit/reparent.js.map +1 -0
  119. package/dist/actions/move/delta.js +127 -0
  120. package/dist/actions/move/delta.js.map +1 -0
  121. package/dist/actions/move/dragSnap.js +55 -0
  122. package/dist/actions/move/dragSnap.js.map +1 -0
  123. package/dist/actions/move/frame.js +67 -0
  124. package/dist/actions/move/frame.js.map +1 -0
  125. package/dist/actions/move/gestureAdapter.js +36 -0
  126. package/dist/actions/move/gestureAdapter.js.map +1 -0
  127. package/dist/actions/move/landedDescendants.js +50 -0
  128. package/dist/actions/move/landedDescendants.js.map +1 -0
  129. package/dist/actions/move/layout/container.js +119 -0
  130. package/dist/actions/move/layout/container.js.map +1 -0
  131. package/dist/actions/move/layout/dragged.js +75 -0
  132. package/dist/actions/move/layout/dragged.js.map +1 -0
  133. package/dist/actions/move/layout/dropPass.js +205 -0
  134. package/dist/actions/move/layout/dropPass.js.map +1 -0
  135. package/dist/actions/move/layout/exits.js +62 -0
  136. package/dist/actions/move/layout/exits.js.map +1 -0
  137. package/dist/actions/move/layout/glide.js +70 -0
  138. package/dist/actions/move/layout/glide.js.map +1 -0
  139. package/dist/actions/move/layout/view.js +60 -0
  140. package/dist/actions/move/layout/view.js.map +1 -0
  141. package/dist/actions/move/refusal.js +49 -0
  142. package/dist/actions/move/refusal.js.map +1 -0
  143. package/dist/actions/move/session.js +105 -0
  144. package/dist/actions/move/session.js.map +1 -0
  145. package/dist/actions/move/sessionOf.js +27 -0
  146. package/dist/actions/move/sessionOf.js.map +1 -0
  147. package/dist/actions/move/translate.js +49 -0
  148. package/dist/actions/move/translate.js.map +1 -0
  149. package/dist/actions/pathfinder/action.js +109 -0
  150. package/dist/actions/pathfinder/action.js.map +1 -0
  151. package/dist/actions/pathfinder/booleanGroupAction.js +117 -0
  152. package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -0
  153. package/dist/actions/pathfinder/keymap.js +51 -0
  154. package/dist/actions/pathfinder/keymap.js.map +1 -0
  155. package/dist/actions/reorder/reorder.js +245 -0
  156. package/dist/actions/reorder/reorder.js.map +1 -0
  157. package/dist/actions/resize/action.js +105 -0
  158. package/dist/actions/resize/action.js.map +1 -0
  159. package/dist/actions/resize/aspect.js +42 -0
  160. package/dist/actions/resize/aspect.js.map +1 -0
  161. package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
  162. package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
  163. package/dist/actions/resize/boxFrame.js +19 -0
  164. package/dist/actions/resize/boxFrame.js.map +1 -0
  165. package/dist/actions/resize/capture.js +121 -0
  166. package/dist/actions/resize/capture.js.map +1 -0
  167. package/dist/actions/resize/commit.js +104 -0
  168. package/dist/actions/resize/commit.js.map +1 -0
  169. package/dist/actions/resize/frame.js +171 -0
  170. package/dist/actions/resize/frame.js.map +1 -0
  171. package/dist/actions/resize/held.js +44 -0
  172. package/dist/actions/resize/held.js.map +1 -0
  173. package/dist/actions/resize/minimum.js +34 -0
  174. package/dist/actions/resize/minimum.js.map +1 -0
  175. package/dist/actions/resize/replay.js +58 -0
  176. package/dist/actions/resize/replay.js.map +1 -0
  177. package/dist/actions/resize/ruleBounds.js +11 -0
  178. package/dist/actions/resize/ruleBounds.js.map +1 -0
  179. package/dist/actions/resize/session.js +118 -0
  180. package/dist/actions/resize/session.js.map +1 -0
  181. package/dist/actions/rotate/action.js +99 -0
  182. package/dist/actions/rotate/action.js.map +1 -0
  183. package/dist/actions/rotate/commit.js +48 -0
  184. package/dist/actions/rotate/commit.js.map +1 -0
  185. package/dist/actions/rotate/frame.js +96 -0
  186. package/dist/actions/rotate/frame.js.map +1 -0
  187. package/dist/actions/rotate/replay.js +25 -0
  188. package/dist/actions/rotate/replay.js.map +1 -0
  189. package/dist/actions/rotate/session.js +135 -0
  190. package/dist/actions/rotate/session.js.map +1 -0
  191. package/dist/actions/select/areaSelect.js +83 -0
  192. package/dist/actions/select/areaSelect.js.map +1 -0
  193. package/dist/actions/select/clearSelection.js +33 -0
  194. package/dist/actions/select/clearSelection.js.map +1 -0
  195. package/dist/actions/swap/action.js +63 -0
  196. package/dist/actions/swap/action.js.map +1 -0
  197. package/dist/actions/swap/swapOps.js +160 -0
  198. package/dist/actions/swap/swapOps.js.map +1 -0
  199. package/dist/actions/transformAgain/action.js +90 -0
  200. package/dist/actions/transformAgain/action.js.map +1 -0
  201. package/dist/actions/transformAgain/transformSelection.js +49 -0
  202. package/dist/actions/transformAgain/transformSelection.js.map +1 -0
  203. package/dist/booleans/booleans.js +130 -0
  204. package/dist/booleans/booleans.js.map +1 -0
  205. package/dist/booleans/commit.js +45 -0
  206. package/dist/booleans/commit.js.map +1 -0
  207. package/dist/booleans/custom.js +48 -0
  208. package/dist/booleans/custom.js.map +1 -0
  209. package/dist/booleans/operands.js +50 -0
  210. package/dist/booleans/operands.js.map +1 -0
  211. package/dist/booleans/pieces.js +43 -0
  212. package/dist/booleans/pieces.js.map +1 -0
  213. package/dist/booleans/placement.js +37 -0
  214. package/dist/booleans/placement.js.map +1 -0
  215. package/dist/booleans/useBooleans.js +34 -0
  216. package/dist/booleans/useBooleans.js.map +1 -0
  217. package/dist/booleans/useBooleansAdapter.js +11 -0
  218. package/dist/booleans/useBooleansAdapter.js.map +1 -0
  219. package/dist/chrome/affordances/cornerResize.js +123 -0
  220. package/dist/chrome/affordances/cornerResize.js.map +1 -0
  221. package/dist/chrome/affordances/rotateCursor.js +17 -0
  222. package/dist/chrome/affordances/rotateCursor.js.map +1 -0
  223. package/dist/chrome/affordances/rotationHandle.js +117 -0
  224. package/dist/chrome/affordances/rotationHandle.js.map +1 -0
  225. package/dist/chrome/handleCommands.js +110 -0
  226. package/dist/chrome/handleCommands.js.map +1 -0
  227. package/dist/chrome/overlay.js +271 -0
  228. package/dist/chrome/overlay.js.map +1 -0
  229. package/dist/chrome/rotationBadge.js +132 -0
  230. package/dist/chrome/rotationBadge.js.map +1 -0
  231. package/dist/chrome/rotationHandleGeometry.js +49 -0
  232. package/dist/chrome/rotationHandleGeometry.js.map +1 -0
  233. package/dist/chrome/selectionChrome.js +25 -0
  234. package/dist/chrome/selectionChrome.js.map +1 -0
  235. package/dist/chrome/selectionPose.js +112 -0
  236. package/dist/chrome/selectionPose.js.map +1 -0
  237. package/dist/chrome/shapeOutline.js +137 -0
  238. package/dist/chrome/shapeOutline.js.map +1 -0
  239. package/dist/clipboard/clipboardOps.js +48 -0
  240. package/dist/clipboard/clipboardOps.js.map +1 -0
  241. package/dist/clipboard/materializePaste.js +34 -0
  242. package/dist/clipboard/materializePaste.js.map +1 -0
  243. package/dist/clipboard/osClipboard.js +67 -0
  244. package/dist/clipboard/osClipboard.js.map +1 -0
  245. package/dist/clipboard/useClipboard.js +64 -0
  246. package/dist/clipboard/useClipboard.js.map +1 -0
  247. package/dist/clipboard/wireFormat.js +108 -0
  248. package/dist/clipboard/wireFormat.js.map +1 -0
  249. package/dist/deps/areaSelect.js +42 -0
  250. package/dist/deps/areaSelect.js.map +1 -0
  251. package/dist/deps/booleans.js +99 -0
  252. package/dist/deps/booleans.js.map +1 -0
  253. package/dist/deps/insert.js +260 -0
  254. package/dist/deps/insert.js.map +1 -0
  255. package/dist/deps/lassoSelect.js +37 -0
  256. package/dist/deps/lassoSelect.js.map +1 -0
  257. package/dist/deps/presetDeps.js +40 -0
  258. package/dist/deps/presetDeps.js.map +1 -0
  259. package/dist/deps/resizePolicy.js +41 -0
  260. package/dist/deps/resizePolicy.js.map +1 -0
  261. package/dist/engine-BV9RDHOL.d.ts +339 -0
  262. package/dist/engine.d.ts +6 -0
  263. package/dist/engine.js +10 -0
  264. package/dist/engineStandardActions.js +54 -0
  265. package/dist/engineStandardActions.js.map +1 -0
  266. package/dist/groups.d.ts +27 -0
  267. package/dist/groups.js +4 -0
  268. package/dist/icons.gen.js +8 -0
  269. package/dist/icons.gen.js.map +1 -0
  270. package/dist/icons.table.d.ts +6 -0
  271. package/dist/icons.table.js +8 -0
  272. package/dist/icons.table.js.map +1 -0
  273. package/dist/icons.table.json +156 -0
  274. package/dist/icons2.table.js +163 -0
  275. package/dist/icons2.table.js.map +1 -0
  276. package/dist/index.d.ts +1867 -0
  277. package/dist/index.js +86 -0
  278. package/dist/ingest/ghost.js +58 -0
  279. package/dist/ingest/ghost.js.map +1 -0
  280. package/dist/ingest/imageHandler.js +80 -0
  281. package/dist/ingest/imageHandler.js.map +1 -0
  282. package/dist/ingest/kitHandlers.js +15 -0
  283. package/dist/ingest/kitHandlers.js.map +1 -0
  284. package/dist/ingest/svgHandler.js +97 -0
  285. package/dist/ingest/svgHandler.js.map +1 -0
  286. package/dist/ingest/weaselJsonHandler.js +68 -0
  287. package/dist/ingest/weaselJsonHandler.js.map +1 -0
  288. package/dist/namedPresets.js +83 -0
  289. package/dist/namedPresets.js.map +1 -0
  290. package/dist/presets/arrange.js +65 -0
  291. package/dist/presets/arrange.js.map +1 -0
  292. package/dist/presets/booleans.js +13 -0
  293. package/dist/presets/booleans.js.map +1 -0
  294. package/dist/presets/composites.js +46 -0
  295. package/dist/presets/composites.js.map +1 -0
  296. package/dist/presets/edit.js +125 -0
  297. package/dist/presets/edit.js.map +1 -0
  298. package/dist/presets/ingest.js +17 -0
  299. package/dist/presets/ingest.js.map +1 -0
  300. package/dist/presets/insert.js +28 -0
  301. package/dist/presets/insert.js.map +1 -0
  302. package/dist/presets/pathfinder.js +26 -0
  303. package/dist/presets/pathfinder.js.map +1 -0
  304. package/dist/presets/select.js +31 -0
  305. package/dist/presets/select.js.map +1 -0
  306. package/dist/presets/selection.js +13 -0
  307. package/dist/presets/selection.js.map +1 -0
  308. package/dist/presets/selectionChrome.js +15 -0
  309. package/dist/presets/selectionChrome.js.map +1 -0
  310. package/dist/presets/tools.js +84 -0
  311. package/dist/presets/tools.js.map +1 -0
  312. package/dist/presets/transform.js +52 -0
  313. package/dist/presets/transform.js.map +1 -0
  314. package/dist/presets.d.ts +104 -0
  315. package/dist/presets.js +15 -0
  316. package/dist/selection/useSelection.js +127 -0
  317. package/dist/selection/useSelection.js.map +1 -0
  318. package/dist/test-seams.d.ts +50 -0
  319. package/dist/test-seams.js +4 -0
  320. package/dist/tools/ellipse/useEllipseTool.js +72 -0
  321. package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
  322. package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
  323. package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
  324. package/dist/tools/image/useImageTool.js +57 -0
  325. package/dist/tools/image/useImageTool.js.map +1 -0
  326. package/dist/tools/lasso/useLassoTool.js +96 -0
  327. package/dist/tools/lasso/useLassoTool.js.map +1 -0
  328. package/dist/tools/line/useLineTool.js +67 -0
  329. package/dist/tools/line/useLineTool.js.map +1 -0
  330. package/dist/tools/polygon/usePolygonTool.js +149 -0
  331. package/dist/tools/polygon/usePolygonTool.js.map +1 -0
  332. package/dist/tools/rect/useRectTool.js +74 -0
  333. package/dist/tools/rect/useRectTool.js.map +1 -0
  334. package/dist/tools/select/adapterPointQuery.js +56 -0
  335. package/dist/tools/select/adapterPointQuery.js.map +1 -0
  336. package/dist/tools/select/collapseDeferred.js +35 -0
  337. package/dist/tools/select/collapseDeferred.js.map +1 -0
  338. package/dist/tools/select/extendPressLocked.js +17 -0
  339. package/dist/tools/select/extendPressLocked.js.map +1 -0
  340. package/dist/tools/select/groupEntry.js +73 -0
  341. package/dist/tools/select/groupEntry.js.map +1 -0
  342. package/dist/tools/select/pressDecision.js +39 -0
  343. package/dist/tools/select/pressDecision.js.map +1 -0
  344. package/dist/tools/select/selectDeep.js +39 -0
  345. package/dist/tools/select/selectDeep.js.map +1 -0
  346. package/dist/tools/select/selectPick.js +60 -0
  347. package/dist/tools/select/selectPick.js.map +1 -0
  348. package/dist/tools/select/selectionContributions.js +191 -0
  349. package/dist/tools/select/selectionContributions.js.map +1 -0
  350. package/dist/tools/select/usePickerSelectTool.js +145 -0
  351. package/dist/tools/select/usePickerSelectTool.js.map +1 -0
  352. package/dist/tools/select/useSelectTool.js +54 -0
  353. package/dist/tools/select/useSelectTool.js.map +1 -0
  354. package/dist/tools/shared/countOption.js +24 -0
  355. package/dist/tools/shared/countOption.js.map +1 -0
  356. package/dist/tools/shared/insertToolOptions.js +8 -0
  357. package/dist/tools/shared/insertToolOptions.js.map +1 -0
  358. package/dist/tools/shared/pointerFollower.js +23 -0
  359. package/dist/tools/shared/pointerFollower.js.map +1 -0
  360. package/dist/tools/shared/styleOptions.js +76 -0
  361. package/dist/tools/shared/styleOptions.js.map +1 -0
  362. package/dist/tools/star/useStarTool.js +149 -0
  363. package/dist/tools/star/useStarTool.js.map +1 -0
  364. package/dist/tools/toolSets.js +26 -0
  365. package/dist/tools/toolSets.js.map +1 -0
  366. package/dist/useStandardActions.js +26 -0
  367. package/dist/useStandardActions.js.map +1 -0
  368. package/package.json +87 -4
@@ -0,0 +1,50 @@
1
+ import { strokeRegion } from "@weasel-js/core";
2
+ import { resolveFill, resolveStroke } from "@weasel-js/paint";
3
+ import { pathUnion } from "@weasel-js/geom/booleans";
4
+
5
+ // src/booleans/operands.ts
6
+ function inkOf(source, strokes, frame, scale) {
7
+ const { path } = source;
8
+ const fill = resolveFill(source.fill);
9
+ const stroke = resolveStroke(source.stroke);
10
+ if (!stroke) return { path };
11
+ if (strokes === "ignore" || strokes === "unfilled" && fill !== null) return { path };
12
+ const ribbon = strokeRegion(path, stroke, frame, scale === void 0 ? {} : { scale });
13
+ if (ribbon.commands.length === 0) return { path };
14
+ return {
15
+ path: fill !== null ? pathUnion(path, ribbon) : ribbon,
16
+ paint: { fill: fill ?? { paint: stroke.paint } }
17
+ };
18
+ }
19
+ /**
20
+ * The operand behind `id`, or `undefined` for a node that is not one: a group,
21
+ * an outline that inks nothing, anything the adapter has neither a path nor an
22
+ * outline for. Throws `NodeOutlineError` for an outline that cannot be built.
23
+ */
24
+ function resolveOperand(adapter, id, { strokes = "ignore", scale }) {
25
+ const path = adapter.getWorldPath(id);
26
+ if (path) {
27
+ const paint = strokes === "ignore" ? void 0 : adapter.getPaint?.(id);
28
+ return paint ? inkOf({
29
+ path,
30
+ ...paint
31
+ }, strokes, adapter.getStrokeFrame?.(id), scale) : { path };
32
+ }
33
+ const outline = adapter.getOutline?.(id);
34
+ if (!outline) return void 0;
35
+ if (strokes === "ignore") {
36
+ const whole = outline.path();
37
+ return whole.kind === "rect" || whole.commands.length > 0 ? { path: whole } : void 0;
38
+ }
39
+ const inks = outline.parts().map((p) => inkOf(p, strokes, adapter.getStrokeFrame?.(id), scale));
40
+ if (inks.length === 0) return void 0;
41
+ const paint = inks.find((ink) => ink.paint)?.paint;
42
+ const whole = inks.length === 1 ? inks[0].path : pathUnion(...inks.map((ink) => ink.path));
43
+ return paint ? {
44
+ path: whole,
45
+ paint
46
+ } : { path: whole };
47
+ }
48
+
49
+ export { resolveOperand };
50
+ //# sourceMappingURL=operands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operands.js","names":[],"sources":["../../src/booleans/operands.ts"],"sourcesContent":["/**\n * What each selected node gives a Boolean operation: its path, its outline\n * (a text node's glyphs), or the region its ink covers once a stroke is counted.\n */\nimport type { Affine, Path, Scale2 } from '@weasel-js/geom';\nimport { pathUnion } from '@weasel-js/geom/booleans';\nimport { resolveFill, resolveStroke } from '@weasel-js/paint';\nimport type { PathPaint, NodeId, PaintedPath } from '@weasel-js/core';\nimport { strokeRegion } from '@weasel-js/core';\nimport type { BooleansAdapter } from './booleans';\n\n/**\n * What a stroked operand gives a Boolean operation.\n *\n * - `'ignore'`: its path, as though it had no stroke.\n * - `'unfilled'`: the region its stroke covers when it has no fill, as a line\n * or an open pencil stroke has none; its path when it is filled.\n * - `'include'`: what it paints — its fill and its stroke together, or the\n * stroke alone when it has no fill.\n *\n * Any mode but `'ignore'` needs {@link BooleansAdapter.getPaint}.\n */\nexport type BooleanStrokes = 'ignore' | 'unfilled' | 'include';\n\n/** Options for `applyBooleanOp`. */\nexport interface BooleanOpOptions {\n /** Default `'ignore'`. */\n strokes?: BooleanStrokes;\n /** The view scale a `{ px }` stroke width resolves against: one number, or\n * the view's own scale per axis. Default 1. */\n scale?: number | Scale2;\n}\n\n/** @internal */\nexport interface BooleanOperand {\n path: Path;\n /** Set when a stroke went into `path`: what a result standing in for this\n * operand wears, the stroke being part of its shape now. */\n paint?: PathPaint;\n}\n\nfunction inkOf(\n source: PaintedPath,\n strokes: BooleanStrokes,\n frame: Affine | null | undefined,\n scale: number | Scale2 | undefined,\n): BooleanOperand {\n const { path } = source;\n const fill = resolveFill(source.fill);\n const stroke = resolveStroke(source.stroke);\n if (!stroke) return { path };\n if (strokes === 'ignore' || (strokes === 'unfilled' && fill !== null)) return { path };\n const ribbon = strokeRegion(path, stroke, frame, scale === undefined ? {} : { scale });\n if (ribbon.commands.length === 0) return { path };\n return { path: fill !== null ? pathUnion(path, ribbon) : ribbon, paint: { fill: fill ?? { paint: stroke.paint } } };\n}\n\n/**\n * The operand behind `id`, or `undefined` for a node that is not one: a group,\n * an outline that inks nothing, anything the adapter has neither a path nor an\n * outline for. Throws `NodeOutlineError` for an outline that cannot be built.\n */\nexport function resolveOperand(\n adapter: BooleansAdapter,\n id: NodeId,\n { strokes = 'ignore', scale }: BooleanOpOptions,\n): BooleanOperand | undefined {\n const path = adapter.getWorldPath(id);\n if (path) {\n const paint = strokes === 'ignore' ? undefined : adapter.getPaint?.(id);\n return paint ? inkOf({ path, ...paint }, strokes, adapter.getStrokeFrame?.(id), scale) : { path };\n }\n const outline = adapter.getOutline?.(id);\n if (!outline) return undefined;\n if (strokes === 'ignore') {\n const whole = outline.path();\n return whole.kind === 'rect' || whole.commands.length > 0 ? { path: whole } : undefined;\n }\n const inks = outline.parts().map((p) => inkOf(p, strokes, adapter.getStrokeFrame?.(id), scale));\n if (inks.length === 0) return undefined;\n const paint = inks.find((ink) => ink.paint)?.paint;\n const whole = inks.length === 1 ? inks[0]!.path : pathUnion(...inks.map((ink) => ink.path));\n return paint ? { path: whole, paint } : { path: whole };\n}\n"],"mappings":";;;;;AAyCA,SAAS,MACP,QACA,SACA,OACA,OACgB;CAChB,MAAM,EAAE,SAAS;CACjB,MAAM,OAAO,YAAY,OAAO,IAAI;CACpC,MAAM,SAAS,cAAc,OAAO,MAAM;CAC1C,IAAI,CAAC,QAAQ,OAAO,EAAE,KAAK;CAC3B,IAAI,YAAY,YAAa,YAAY,cAAc,SAAS,MAAO,OAAO,EAAE,KAAK;CACrF,MAAM,SAAS,aAAa,MAAM,QAAQ,OAAO,UAAU,SAAY,CAAC,IAAI,EAAE,MAAM,CAAC;CACrF,IAAI,OAAO,SAAS,WAAW,GAAG,OAAO,EAAE,KAAK;CAChD,OAAO;EAAE,MAAM,SAAS,OAAO,UAAU,MAAM,MAAM,IAAI;EAAQ,OAAO,EAAE,MAAM,QAAQ,EAAE,OAAO,OAAO,MAAM,EAAE;CAAE;AACpH;;;;;;AAOA,SAAgB,eACd,SACA,IACA,EAAE,UAAU,UAAU,SACM;CAC5B,MAAM,OAAO,QAAQ,aAAa,EAAE;CACpC,IAAI,MAAM;EACR,MAAM,QAAQ,YAAY,WAAW,SAAY,QAAQ,WAAW,EAAE;EACtE,OAAO,QAAQ,MAAM;GAAE;GAAM,GAAG;EAAM,GAAG,SAAS,QAAQ,iBAAiB,EAAE,GAAG,KAAK,IAAI,EAAE,KAAK;CAClG;CACA,MAAM,UAAU,QAAQ,aAAa,EAAE;CACvC,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI,YAAY,UAAU;EACxB,MAAM,QAAQ,QAAQ,KAAK;EAC3B,OAAO,MAAM,SAAS,UAAU,MAAM,SAAS,SAAS,IAAI,EAAE,MAAM,MAAM,IAAI;CAChF;CACA,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,MAAM,MAAM,GAAG,SAAS,QAAQ,iBAAiB,EAAE,GAAG,KAAK,CAAC;CAC9F,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,MAAM,QAAQ,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,EAAE;CAC7C,MAAM,QAAQ,KAAK,WAAW,IAAI,KAAK,EAAE,CAAE,OAAO,UAAU,GAAG,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC;CAC1F,OAAO,QAAQ;EAAE,MAAM;EAAO;CAAM,IAAI,EAAE,MAAM,MAAM;AACxD"}
@@ -0,0 +1,43 @@
1
+ import { booleanOfPaths } from "@weasel-js/core";
2
+ import { pathCropPieces, pathDividePieces, pathMerge, pathTrim } from "@weasel-js/geom/booleans";
3
+
4
+ // src/booleans/pieces.ts
5
+ /** A piece stands in for the topmost input left in it. */
6
+ function bySource(pieces) {
7
+ return pieces.map((p) => ({
8
+ path: p.path,
9
+ source: p.sources[p.sources.length - 1]
10
+ }));
11
+ }
12
+ /** Run `op` over `paths`, back to front, dropping empty results. `mergeKey`
13
+ * answers alike for the paths a Merge unites. */
14
+ function booleanPieces(op, paths, mergeKey) {
15
+ const top = paths.length - 1;
16
+ const whole = (path) => [{
17
+ path,
18
+ source: top
19
+ }];
20
+ let pieces;
21
+ switch (op) {
22
+ case "union":
23
+ case "intersect":
24
+ case "exclude":
25
+ case "subtract":
26
+ pieces = whole(booleanOfPaths(op, paths));
27
+ break;
28
+ case "divide":
29
+ pieces = bySource(pathDividePieces(...paths));
30
+ break;
31
+ case "crop":
32
+ pieces = bySource(pathCropPieces(...paths));
33
+ break;
34
+ case "trim":
35
+ pieces = bySource(pathTrim(...paths));
36
+ break;
37
+ case "merge": pieces = bySource(pathMerge(paths, mergeKey));
38
+ }
39
+ return pieces.filter((p) => p.path.commands.length > 0);
40
+ }
41
+
42
+ export { booleanPieces };
43
+ //# sourceMappingURL=pieces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pieces.js","names":[],"sources":["../../src/booleans/pieces.ts"],"sourcesContent":["import {\n pathDividePieces,\n pathCropPieces,\n pathTrim,\n pathMerge,\n type BooleanPiece,\n} from '@weasel-js/geom/booleans';\nimport type { Path, PolygonPath } from '@weasel-js/geom';\nimport type { BooleanOp } from './booleans';\nimport { booleanOfPaths } from '@weasel-js/core';\n\n/** One result path, and the operand it stands in for: an index into the\n * operands, back to front. */\nexport interface ResultPiece {\n path: PolygonPath;\n source: number;\n}\n\n/** A piece stands in for the topmost input left in it. */\nfunction bySource(pieces: BooleanPiece[]): ResultPiece[] {\n return pieces.map((p) => ({ path: p.path, source: p.sources[p.sources.length - 1]! }));\n}\n\n/** Run `op` over `paths`, back to front, dropping empty results. `mergeKey`\n * answers alike for the paths a Merge unites. */\nexport function booleanPieces(op: BooleanOp, paths: Path[], mergeKey: (index: number) => unknown): ResultPiece[] {\n const top = paths.length - 1;\n const whole = (path: PolygonPath): ResultPiece[] => [{ path, source: top }];\n let pieces: ResultPiece[];\n switch (op) {\n case 'union':\n case 'intersect':\n case 'exclude':\n case 'subtract': pieces = whole(booleanOfPaths(op, paths)); break;\n case 'divide': pieces = bySource(pathDividePieces(...paths)); break;\n // Crop: every source below the topmost, clipped to it; the\n // topmost is consumed as the mask.\n case 'crop': pieces = bySource(pathCropPieces(...paths)); break;\n case 'trim': pieces = bySource(pathTrim(...paths)); break;\n case 'merge': pieces = bySource(pathMerge(paths, mergeKey)); break;\n }\n return pieces.filter((p) => p.path.commands.length > 0);\n}\n"],"mappings":";;;;;AAmBA,SAAS,SAAS,QAAuC;CACvD,OAAO,OAAO,KAAK,OAAO;EAAE,MAAM,EAAE;EAAM,QAAQ,EAAE,QAAQ,EAAE,QAAQ,SAAS;CAAI,EAAE;AACvF;;;AAIA,SAAgB,cAAc,IAAe,OAAe,UAAqD;CAC/G,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,SAAS,SAAqC,CAAC;EAAE;EAAM,QAAQ;CAAI,CAAC;CAC1E,IAAI;CACJ,QAAQ,IAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;GAAa,SAAS,MAAM,eAAe,IAAI,KAAK,CAAC;GAAG;EAC7D,KAAK;GAAa,SAAS,SAAS,iBAAiB,GAAG,KAAK,CAAC;GAAG;EAGjE,KAAK;GAAa,SAAS,SAAS,eAAe,GAAG,KAAK,CAAC;GAAG;EAC/D,KAAK;GAAa,SAAS,SAAS,SAAS,GAAG,KAAK,CAAC;GAAG;EACzD,KAAK,SAAa,SAAS,SAAS,UAAU,OAAO,QAAQ,CAAC;CAChE;CACA,OAAO,OAAO,QAAQ,MAAM,EAAE,KAAK,SAAS,SAAS,CAAC;AACxD"}
@@ -0,0 +1,37 @@
1
+ import { maxOf } from "@weasel-js/geom";
2
+ import * as coreOps from "@weasel-js/core/ops";
3
+
4
+ // src/booleans/placement.ts
5
+ /**
6
+ * The ops that put each result where its source was. Results are grouped by
7
+ * their source's parent, and each group lands as one block, in result order,
8
+ * in the slot of the topmost source in that parent.
9
+ *
10
+ * `sourceSlots` holds every source's slot, read before anything is deleted.
11
+ * The sources below a slot in the same parent are deleted before the reorder
12
+ * runs, so the block goes that many places lower. A result whose source has
13
+ * no slot is left wherever the insert put it.
14
+ */
15
+ function placementOps(results, sourceSlots) {
16
+ const groups = /* @__PURE__ */ new Map();
17
+ for (const r of results) {
18
+ if (!r.slot) continue;
19
+ const group = groups.get(r.slot.parentId);
20
+ if (group) group.push(r.id);
21
+ else groups.set(r.slot.parentId, [r.id]);
22
+ }
23
+ const ops = [];
24
+ for (const [parentId, ids] of groups) {
25
+ const indices = sourceSlots.flatMap((s) => s && s.parentId === parentId ? [s.index] : []);
26
+ const top = maxOf(indices);
27
+ ops.push(coreOps.moveToIndex({
28
+ ids,
29
+ parentId,
30
+ index: top - (indices.length - 1)
31
+ }));
32
+ }
33
+ return ops;
34
+ }
35
+
36
+ export { placementOps };
37
+ //# sourceMappingURL=placement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placement.js","names":[],"sources":["../../src/booleans/placement.ts"],"sourcesContent":["import type { Op } from '@weasel-js/core';\nimport { maxOf } from '@weasel-js/geom';\nimport type { BooleanZOrder } from './booleans';\nimport * as coreOps from '@weasel-js/core/ops';\n\n/**\n * The ops that put each result where its source was. Results are grouped by\n * their source's parent, and each group lands as one block, in result order,\n * in the slot of the topmost source in that parent.\n *\n * `sourceSlots` holds every source's slot, read before anything is deleted.\n * The sources below a slot in the same parent are deleted before the reorder\n * runs, so the block goes that many places lower. A result whose source has\n * no slot is left wherever the insert put it.\n */\nexport function placementOps(\n results: readonly { id: string; slot: BooleanZOrder | undefined }[],\n sourceSlots: readonly (BooleanZOrder | undefined)[],\n): Op[] {\n const groups = new Map<string | null, string[]>();\n for (const r of results) {\n if (!r.slot) continue;\n const group = groups.get(r.slot.parentId);\n if (group) group.push(r.id);\n else groups.set(r.slot.parentId, [r.id]);\n }\n const ops: Op[] = [];\n for (const [parentId, ids] of groups) {\n const indices = sourceSlots.flatMap((s) => (s && s.parentId === parentId ? [s.index] : []));\n const top = maxOf(indices);\n ops.push(coreOps.moveToIndex({ ids, parentId, index: top - (indices.length - 1) }));\n }\n return ops;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,aACd,SACA,aACM;CACN,MAAM,yBAAS,IAAI,IAA6B;CAChD,KAAK,MAAM,KAAK,SAAS;EACvB,IAAI,CAAC,EAAE,MAAM;EACb,MAAM,QAAQ,OAAO,IAAI,EAAE,KAAK,QAAQ;EACxC,IAAI,OAAO,MAAM,KAAK,EAAE,EAAE;OACrB,OAAO,IAAI,EAAE,KAAK,UAAU,CAAC,EAAE,EAAE,CAAC;CACzC;CACA,MAAM,MAAY,CAAC;CACnB,KAAK,MAAM,CAAC,UAAU,QAAQ,QAAQ;EACpC,MAAM,UAAU,YAAY,SAAS,MAAO,KAAK,EAAE,aAAa,WAAW,CAAC,EAAE,KAAK,IAAI,CAAC,CAAE;EAC1F,MAAM,MAAM,MAAM,OAAO;EACzB,IAAI,KAAK,QAAQ,YAAY;GAAE;GAAK;GAAU,OAAO,OAAO,QAAQ,SAAS;EAAG,CAAC,CAAC;CACpF;CACA,OAAO;AACT"}
@@ -0,0 +1,34 @@
1
+ import { applyBooleanOp } from "./booleans.js";
2
+ import { useCallback } from "react";
3
+ import { isDev, useLatest } from "@weasel-js/react";
4
+
5
+ // src/booleans/useBooleans.ts
6
+ /**
7
+ * `useBooleans` — selection-driven Boolean ops on path layers. No-ops are
8
+ * silent in production; in dev, `subtract` with < 2 selected paths emits a
9
+ * `console.warn`.
10
+ */
11
+ var dev = isDev();
12
+ /** Bind the Boolean path operations to an adapter that knows how to read the
13
+ * selection, fetch world-space paths and mint result nodes. */
14
+ function useBooleans(adapter, options = {}) {
15
+ const adapterRef = useLatest(adapter);
16
+ const optionsRef = useLatest(options);
17
+ const run = useCallback((op) => {
18
+ const result = applyBooleanOp(adapterRef.current, op, optionsRef.current);
19
+ if (dev && result.kind === "noop" && result.reason === "too-few-for-subtract") console.warn("[useBooleans] subtract requires at least 2 selected paths");
20
+ }, [adapterRef, optionsRef]);
21
+ return {
22
+ union: useCallback(() => run("union"), [run]),
23
+ intersect: useCallback(() => run("intersect"), [run]),
24
+ subtract: useCallback(() => run("subtract"), [run]),
25
+ exclude: useCallback(() => run("exclude"), [run]),
26
+ divide: useCallback(() => run("divide"), [run]),
27
+ crop: useCallback(() => run("crop"), [run]),
28
+ trim: useCallback(() => run("trim"), [run]),
29
+ merge: useCallback(() => run("merge"), [run])
30
+ };
31
+ }
32
+
33
+ export { useBooleans };
34
+ //# sourceMappingURL=useBooleans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBooleans.js","names":[],"sources":["../../src/booleans/useBooleans.ts"],"sourcesContent":["/**\n * `useBooleans` — selection-driven Boolean ops on path layers. No-ops are\n * silent in production; in dev, `subtract` with < 2 selected paths emits a\n * `console.warn`.\n */\nimport { useCallback } from 'react';\nimport { useLatest, isDev } from '@weasel-js/react';\nimport { applyBooleanOp, type BooleansAdapter, type BooleanOp } from './booleans';\nimport type { BooleanOpOptions } from './operands';\n\n/** The Boolean path operations, each acting on the current selection and\n * committing as one undo step. */\nexport interface UseBooleansReturn {\n union(): void;\n intersect(): void;\n subtract(): void;\n exclude(): void;\n divide(): void;\n crop(): void;\n trim(): void;\n merge(): void;\n}\n\n/** Options for `useBooleans`. */\nexport interface UseBooleansOptions extends BooleanOpOptions {\n /** No-op. Retained for source-compatibility; `useStandardActions`\n * registers the actions. */\n enableActions?: boolean;\n}\n\nconst dev = isDev();\n\n/** Bind the Boolean path operations to an adapter that knows how to read the\n * selection, fetch world-space paths and mint result nodes. */\nexport function useBooleans(\n adapter: BooleansAdapter,\n options: UseBooleansOptions = {},\n): UseBooleansReturn {\n const adapterRef = useLatest(adapter);\n const optionsRef = useLatest(options);\n\n const run = useCallback((op: BooleanOp) => {\n const result = applyBooleanOp(adapterRef.current, op, optionsRef.current);\n if (dev && result.kind === 'noop' && result.reason === 'too-few-for-subtract') {\n console.warn('[useBooleans] subtract requires at least 2 selected paths');\n }\n }, [adapterRef, optionsRef]);\n\n return {\n union: useCallback(() => run('union'), [run]),\n intersect: useCallback(() => run('intersect'), [run]),\n subtract: useCallback(() => run('subtract'), [run]),\n exclude: useCallback(() => run('exclude'), [run]),\n divide: useCallback(() => run('divide'), [run]),\n crop: useCallback(() => run('crop'), [run]),\n trim: useCallback(() => run('trim'), [run]),\n merge: useCallback(() => run('merge'), [run]),\n };\n}\n"],"mappings":";;;;;;;;;;AA8BA,IAAM,MAAM,MAAM;;;AAIlB,SAAgB,YACd,SACA,UAA8B,CAAC,GACZ;CACnB,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,aAAa,UAAU,OAAO;CAEpC,MAAM,MAAM,aAAa,OAAkB;EACzC,MAAM,SAAS,eAAe,WAAW,SAAS,IAAI,WAAW,OAAO;EACxE,IAAI,OAAO,OAAO,SAAS,UAAU,OAAO,WAAW,wBACrD,QAAQ,KAAK,2DAA2D;CAE5E,GAAG,CAAC,YAAY,UAAU,CAAC;CAE3B,OAAO;EACL,OAAO,kBAAkB,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC;EAC5C,WAAW,kBAAkB,IAAI,WAAW,GAAG,CAAC,GAAG,CAAC;EACpD,UAAU,kBAAkB,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC;EAClD,SAAS,kBAAkB,IAAI,SAAS,GAAG,CAAC,GAAG,CAAC;EAChD,QAAQ,kBAAkB,IAAI,QAAQ,GAAG,CAAC,GAAG,CAAC;EAC9C,MAAM,kBAAkB,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC;EAC1C,MAAM,kBAAkB,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC;EAC1C,OAAO,kBAAkB,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC;CAC9C;AACF"}
@@ -0,0 +1,11 @@
1
+ import { useDepSource } from "@weasel-js/routing/react";
2
+
3
+ // src/booleans/useBooleansAdapter.ts
4
+ /** Publish a Boolean-ops adapter so the built-in Pathfinder actions can run.
5
+ * Silently does nothing outside a `<DepRegistryProvider>`. */
6
+ function useBooleansAdapter(adapter) {
7
+ useDepSource("booleansAdapter", () => adapter);
8
+ }
9
+
10
+ export { useBooleansAdapter };
11
+ //# sourceMappingURL=useBooleansAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBooleansAdapter.js","names":[],"sources":["../../src/booleans/useBooleansAdapter.ts"],"sourcesContent":["import { useDepSource } from '@weasel-js/routing/react';\nimport type { BooleansAdapter } from './booleans';\n\n/** Publish a Boolean-ops adapter so the built-in Pathfinder actions can run.\n * Silently does nothing outside a `<DepRegistryProvider>`. */\nexport function useBooleansAdapter(adapter: BooleansAdapter): void {\n useDepSource('booleansAdapter', () => adapter);\n}\n"],"mappings":";;;;;AAKA,SAAgB,mBAAmB,SAAgC;CACjE,aAAa,yBAAyB,OAAO;AAC/C"}
@@ -0,0 +1,123 @@
1
+ import { HANDLE_FILL_COLOR, HANDLE_OUTLINE_COLOR } from "../handleCommands.js";
2
+ import { HANDLE_BASE_PX, MULTI_RESIZE_TARGET_ID, localToWorld, transformOf } from "@weasel-js/core";
3
+ import { RESIZE_HANDLE_ANCHORS, fixedCornerOf as fixedCornerOf$1, handlePoint, isCornerHandle } from "@weasel-js/core/engine";
4
+
5
+ // src/chrome/affordances/cornerResize.ts
6
+ /**
7
+ * Resize-handle affordance for the active selection (single member in
8
+ * single-mode; the union AABB in multi-mode): a handle at each corner and,
9
+ * unless `edges` is false, at each edge midpoint.
10
+ *
11
+ * Declares point regions in the target's local frame; the framework
12
+ * applies the target's bounds rotation for both paint and hit-test. A
13
+ * region's `bind()` carries only the scratch a hit hands to the resize
14
+ * action: the anchor, the target, and the world-space fixed point.
15
+ */
16
+ function createCornerResizeAffordance(opts = {}) {
17
+ const { handleHitRadius = HANDLE_BASE_PX, handleSize = HANDLE_BASE_PX, fill = HANDLE_FILL_COLOR, stroke = HANDLE_OUTLINE_COLOR, edges = true } = opts;
18
+ const entries = edges ? RESIZE_HANDLE_ANCHORS : RESIZE_HANDLE_ANCHORS.filter(isCornerHandle);
19
+ const paint = {
20
+ kind: "square",
21
+ sizePx: handleSize,
22
+ fill: { paint: { color: fill } },
23
+ stroke: {
24
+ paint: { color: stroke },
25
+ width: 1
26
+ }
27
+ };
28
+ return {
29
+ id: "selection.resize-handles",
30
+ regions(state) {
31
+ const target = pickRenderTarget(state);
32
+ if (!target) return [];
33
+ const b = target.bounds;
34
+ const xf = transformOf(state, target.id);
35
+ return entries.map((c) => {
36
+ const at = handlePoint(b, c);
37
+ const fixedLocal = fixedCornerOf$1(b, c.anchor);
38
+ const fixedPoint = localToWorld(xf, fixedLocal.x, fixedLocal.y);
39
+ const corner = isCornerHandle(c);
40
+ return {
41
+ id: `${corner ? "corner" : "edge"}-${c.tag}`,
42
+ targetId: target.id,
43
+ shape: {
44
+ kind: "point",
45
+ x: at.x,
46
+ y: at.y,
47
+ hitRadiusPx: handleHitRadius,
48
+ turned: true,
49
+ ...corner ? { cornerOf: {
50
+ width: b.width,
51
+ height: b.height,
52
+ outward: {
53
+ x: c.xEdge === "min" ? -1 : 1,
54
+ y: c.yEdge === "min" ? -1 : 1
55
+ }
56
+ } } : { edgeOf: {
57
+ width: b.width,
58
+ height: b.height
59
+ } }
60
+ },
61
+ paint,
62
+ hitKind: c.kind,
63
+ cursor: resizeCursor(c, xf),
64
+ bind: () => ({ initialScratch: {
65
+ anchor: c.anchor,
66
+ targetId: target.id,
67
+ fixedPoint
68
+ } })
69
+ };
70
+ });
71
+ }
72
+ };
73
+ }
74
+ /** The resize cursor along the axis a handle drags, as that axis is drawn on
75
+ * screen: through the target's frame, a turn or a mirror included, and the
76
+ * view's scale. The glyph is horizontal at angle 0. A corner drags along a
77
+ * diagonal of its box picked by fixed-corner parity: a matched-axis anchor
78
+ * (min-min / max-max fixed) drags along local (1, 1), mixed axes along
79
+ * (1, -1). The keyword is the fallback rather than the answer: CSS has four
80
+ * of them, which cannot express a target rotated to anything but a multiple
81
+ * of 45°. */
82
+ function resizeCursor(c, xf) {
83
+ const matched = c.anchor.x === c.anchor.y;
84
+ const [lx, ly, fallback] = c.anchor.y === "free" ? [
85
+ 1,
86
+ 0,
87
+ "ew-resize"
88
+ ] : c.anchor.x === "free" ? [
89
+ 0,
90
+ 1,
91
+ "ns-resize"
92
+ ] : [
93
+ 1,
94
+ matched ? 1 : -1,
95
+ matched ? "nwse-resize" : "nesw-resize"
96
+ ];
97
+ const [a, b, cc, d] = xf.toWorld;
98
+ const wx = a * lx + cc * ly;
99
+ const wy = b * lx + d * ly;
100
+ return (_at, view) => ({
101
+ glyph: "resize",
102
+ angle: Math.atan2(wy * view.scale.y, wx * view.scale.x),
103
+ fallback
104
+ });
105
+ }
106
+ function pickRenderTarget(state) {
107
+ if (state.multiActive && state.unionBounds) return {
108
+ id: MULTI_RESIZE_TARGET_ID,
109
+ bounds: state.unionBounds
110
+ };
111
+ if (state.selection.length === 1) {
112
+ const id = state.selection[0];
113
+ const b = state.boundsOf(id);
114
+ return b ? {
115
+ id,
116
+ bounds: b
117
+ } : null;
118
+ }
119
+ return null;
120
+ }
121
+
122
+ export { createCornerResizeAffordance };
123
+ //# sourceMappingURL=cornerResize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cornerResize.js","names":["fixedCornerOf"],"sources":["../../../src/chrome/affordances/cornerResize.ts"],"sourcesContent":["import type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from '@weasel-js/core';\nimport type { ChromeState, Bounds } from '@weasel-js/core';\nimport type { ResizeAnchor } from '@weasel-js/core';\nimport {\n RESIZE_HANDLE_ANCHORS, fixedCornerOf, handlePoint, isCornerHandle, type ResizeHandleAnchor,\n} from '@weasel-js/core/engine';\nimport { MULTI_RESIZE_TARGET_ID } from '@weasel-js/core';\nimport { localToWorld, transformOf, type TargetTransform } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { HANDLE_BASE_PX } from '@weasel-js/core';\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport { HANDLE_FILL_COLOR, HANDLE_OUTLINE_COLOR } from '../handleCommands';\n\n/** Options for `createCornerResizeAffordance` — the size and appearance of\n * the resize handles, and whether the edge midpoints get one. */\nexport interface CornerResizeAffordanceOptions {\n /** Hit radius (screen-px) for the handles. Default 8. */\n handleHitRadius?: number;\n /** Visual handle size (screen-px). Default 8. */\n handleSize?: number;\n fill?: string;\n stroke?: string;\n /** Add a handle at the middle of each edge, resizing along one axis with\n * the opposite edge pinned. A side under `EDGE_HANDLE_MIN_RADII` hit radii\n * on screen takes none. Default true. */\n edges?: boolean;\n}\n\n/** What a corner-resize hit hands to the resize action: which corner stays\n * put, what is being resized, and the world-space pivot to scale from. */\nexport interface CornerResizeScratch extends CommonAffordanceScratch {\n /** Resize anchor identifying the OPPOSITE corner or edge (the one that\n * stays fixed). Matches the kit's existing ResizeAnchor convention. */\n anchor: ResizeAnchor;\n /** Id of the resize target. In multi-mode this is `MULTI_RESIZE_TARGET_ID`. */\n targetId: string;\n /** The fixed corner (an edge handle's: the opposite edge's midpoint) in\n * **world** coords, with the target's rotation already applied. `resizeAction` scales from this point, and it has no access to\n * the target transform, so the affordance resolves it here. */\n fixedPoint: { x: number; y: number };\n}\n\n\n/**\n * Resize-handle affordance for the active selection (single member in\n * single-mode; the union AABB in multi-mode): a handle at each corner and,\n * unless `edges` is false, at each edge midpoint.\n *\n * Declares point regions in the target's local frame; the framework\n * applies the target's bounds rotation for both paint and hit-test. A\n * region's `bind()` carries only the scratch a hit hands to the resize\n * action: the anchor, the target, and the world-space fixed point.\n */\nexport function createCornerResizeAffordance(\n opts: CornerResizeAffordanceOptions = {},\n): Affordance {\n const {\n handleHitRadius = HANDLE_BASE_PX,\n handleSize = HANDLE_BASE_PX,\n fill = HANDLE_FILL_COLOR,\n stroke = HANDLE_OUTLINE_COLOR,\n edges = true,\n } = opts;\n const entries = edges ? RESIZE_HANDLE_ANCHORS : RESIZE_HANDLE_ANCHORS.filter(isCornerHandle);\n\n const paint = {\n kind: 'square' as const,\n sizePx: handleSize,\n fill: { paint: { color: fill } },\n stroke: { paint: { color: stroke }, width: 1 },\n };\n\n return {\n id: 'selection.resize-handles',\n regions(state: ChromeState): readonly AffordanceRegion[] {\n const target = pickRenderTarget(state);\n if (!target) return [];\n const b = target.bounds;\n // The transform the framework applies to these regions. Needed here too,\n // because `fixedPoint` leaves the local frame — it travels to\n // `resizeAction`, which works in world coords.\n const xf = transformOf(state, target.id);\n return entries.map((c) => {\n const at = handlePoint(b, c);\n const fixedLocal = fixedCornerOf(b, c.anchor);\n const fixedPoint = localToWorld(xf, fixedLocal.x, fixedLocal.y);\n const corner = isCornerHandle(c);\n return {\n id: `${corner ? 'corner' : 'edge'}-${c.tag}`,\n targetId: target.id,\n shape: {\n kind: 'point' as const,\n x: at.x,\n y: at.y,\n hitRadiusPx: handleHitRadius,\n turned: true,\n ...(corner\n ? {\n cornerOf: {\n width: b.width,\n height: b.height,\n outward: { x: c.xEdge === 'min' ? -1 : 1, y: c.yEdge === 'min' ? -1 : 1 },\n },\n }\n : { edgeOf: { width: b.width, height: b.height } }),\n },\n paint,\n hitKind: c.kind,\n cursor: resizeCursor(c, xf),\n bind: (): AffordanceBinding => ({\n initialScratch: {\n anchor: c.anchor,\n targetId: target.id,\n fixedPoint,\n } satisfies CornerResizeScratch,\n }),\n } satisfies AffordanceRegion;\n });\n },\n };\n}\n\n/** The resize cursor along the axis a handle drags, as that axis is drawn on\n * screen: through the target's frame, a turn or a mirror included, and the\n * view's scale. The glyph is horizontal at angle 0. A corner drags along a\n * diagonal of its box picked by fixed-corner parity: a matched-axis anchor\n * (min-min / max-max fixed) drags along local (1, 1), mixed axes along\n * (1, -1). The keyword is the fallback rather than the answer: CSS has four\n * of them, which cannot express a target rotated to anything but a multiple\n * of 45°. */\nfunction resizeCursor(c: ResizeHandleAnchor, xf: TargetTransform): (at: unknown, view: View) => CursorSpec {\n const matched = c.anchor.x === c.anchor.y;\n const [lx, ly, fallback]: [number, number, string] = c.anchor.y === 'free'\n ? [1, 0, 'ew-resize']\n : c.anchor.x === 'free'\n ? [0, 1, 'ns-resize']\n : [1, matched ? 1 : -1, matched ? 'nwse-resize' : 'nesw-resize'];\n const [a, b, cc, d] = xf.toWorld;\n const wx = a * lx + cc * ly;\n const wy = b * lx + d * ly;\n return (_at, view) => ({ glyph: 'resize', angle: Math.atan2(wy * view.scale.y, wx * view.scale.x), fallback });\n}\n\nfunction pickRenderTarget(state: ChromeState): { id: string; bounds: Bounds } | null {\n if (state.multiActive && state.unionBounds) {\n return { id: MULTI_RESIZE_TARGET_ID, bounds: state.unionBounds };\n }\n if (state.selection.length === 1) {\n const id = state.selection[0];\n const b = state.boundsOf(id);\n return b ? { id, bounds: b } : null;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqDA,SAAgB,6BACd,OAAsC,CAAC,GAC3B;CACZ,MAAM,EACJ,kBAAkB,gBAClB,aAAa,gBACb,OAAO,mBACP,SAAS,sBACT,QAAQ,SACN;CACJ,MAAM,UAAU,QAAQ,wBAAwB,sBAAsB,OAAO,cAAc;CAE3F,MAAM,QAAQ;EACZ,MAAM;EACN,QAAQ;EACR,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,EAAE;EAC/B,QAAQ;GAAE,OAAO,EAAE,OAAO,OAAO;GAAG,OAAO;EAAE;CAC/C;CAEA,OAAO;EACL,IAAI;EACJ,QAAQ,OAAiD;GACvD,MAAM,SAAS,iBAAiB,KAAK;GACrC,IAAI,CAAC,QAAQ,OAAO,CAAC;GACrB,MAAM,IAAI,OAAO;GAIjB,MAAM,KAAK,YAAY,OAAO,OAAO,EAAE;GACvC,OAAO,QAAQ,KAAK,MAAM;IACxB,MAAM,KAAK,YAAY,GAAG,CAAC;IAC3B,MAAM,aAAaA,gBAAc,GAAG,EAAE,MAAM;IAC5C,MAAM,aAAa,aAAa,IAAI,WAAW,GAAG,WAAW,CAAC;IAC9D,MAAM,SAAS,eAAe,CAAC;IAC/B,OAAO;KACL,IAAI,GAAG,SAAS,WAAW,OAAO,GAAG,EAAE;KACvC,UAAU,OAAO;KACjB,OAAO;MACL,MAAM;MACN,GAAG,GAAG;MACN,GAAG,GAAG;MACN,aAAa;MACb,QAAQ;MACR,GAAI,SACA,EACE,UAAU;OACR,OAAO,EAAE;OACT,QAAQ,EAAE;OACV,SAAS;QAAE,GAAG,EAAE,UAAU,QAAQ,KAAK;QAAG,GAAG,EAAE,UAAU,QAAQ,KAAK;OAAE;MAC1E,EACF,IACA,EAAE,QAAQ;OAAE,OAAO,EAAE;OAAO,QAAQ,EAAE;MAAO,EAAE;KACrD;KACA;KACA,SAAS,EAAE;KACX,QAAQ,aAAa,GAAG,EAAE;KAC1B,aAAgC,EAC9B,gBAAgB;MACd,QAAQ,EAAE;MACV,UAAU,OAAO;MACjB;KACF,EACF;IACF;GACF,CAAC;EACH;CACF;AACF;;;;;;;;;AAUA,SAAS,aAAa,GAAuB,IAA8D;CACzG,MAAM,UAAU,EAAE,OAAO,MAAM,EAAE,OAAO;CACxC,MAAM,CAAC,IAAI,IAAI,YAAsC,EAAE,OAAO,MAAM,SAChE;EAAC;EAAG;EAAG;CAAW,IAClB,EAAE,OAAO,MAAM,SACb;EAAC;EAAG;EAAG;CAAW,IAClB;EAAC;EAAG,UAAU,IAAI;EAAI,UAAU,gBAAgB;CAAa;CACnE,MAAM,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG;CACzB,MAAM,KAAK,IAAI,KAAK,KAAK;CACzB,MAAM,KAAK,IAAI,KAAK,IAAI;CACxB,QAAQ,KAAK,UAAU;EAAE,OAAO;EAAU,OAAO,KAAK,MAAM,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,MAAM,CAAC;EAAG;CAAS;AAC9G;AAEA,SAAS,iBAAiB,OAA2D;CACnF,IAAI,MAAM,eAAe,MAAM,aAC7B,OAAO;EAAE,IAAI;EAAwB,QAAQ,MAAM;CAAY;CAEjE,IAAI,MAAM,UAAU,WAAW,GAAG;EAChC,MAAM,KAAK,MAAM,UAAU;EAC3B,MAAM,IAAI,MAAM,SAAS,EAAE;EAC3B,OAAO,IAAI;GAAE;GAAI,QAAQ;EAAE,IAAI;CACjC;CACA,OAAO;AACT"}
@@ -0,0 +1,17 @@
1
+ // src/chrome/affordances/rotateCursor.ts
2
+ /**
3
+ * The `rotate` glyph for a pointer at world point `at` turning something
4
+ * about world point `pivot`, seen through a view of `scale`. The glyph's arc
5
+ * is drawn over the top of its box, so its up points from the pivot to the
6
+ * pointer and the opening faces what is being turned.
7
+ */
8
+ function rotateCursorAt(pivot, at, scale) {
9
+ return {
10
+ glyph: "rotate",
11
+ angle: Math.atan2((at.x - pivot.x) * scale.x, -(at.y - pivot.y) * scale.y),
12
+ fallback: "grab"
13
+ };
14
+ }
15
+
16
+ export { rotateCursorAt };
17
+ //# sourceMappingURL=rotateCursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotateCursor.js","names":[],"sources":["../../../src/chrome/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,SAAgB,eACd,OACA,IACA,OACY;CACZ,OAAO;EACL,OAAO;EACP,OAAO,KAAK,OAAO,GAAG,IAAI,MAAM,KAAK,MAAM,GAAG,EAAE,GAAG,IAAI,MAAM,KAAK,MAAM,CAAC;EACzE,UAAU;CACZ;AACF"}
@@ -0,0 +1,117 @@
1
+ import { rotateCursorAt } from "./rotateCursor.js";
2
+ import { targetCanRotate } from "../rotationHandleGeometry.js";
3
+ import { MULTI_RESIZE_TARGET_ID, localToWorld, transformOf } from "@weasel-js/core";
4
+
5
+ // src/chrome/affordances/rotationHandle.ts
6
+ var isAnnulusForm = (paint) => "fill" in paint || "stroke" in paint || "insetPx" in paint;
7
+ var DEFAULT_PAINT = {
8
+ fill: { paint: {
9
+ kind: "solid",
10
+ color: "rgba(26, 19, 13, 0.12)"
11
+ } },
12
+ insetPx: 10
13
+ };
14
+ /**
15
+ * Rotation affordance for the active selection: an elliptical ring that wraps the selection —
16
+ * the smallest ellipse containing the AABB, minus the AABB itself. Hovering the ring sets the
17
+ * cursor (default the `rotate` glyph) and a drag from it triggers `rotateAction`.
18
+ *
19
+ * The ring is target-local — under target rotation the ellipse rotates with the AABB.
20
+ * Visibility is gated by chrome-caps' `'selection.rotation-handle'` rule. `paint: null` leaves
21
+ * the cursor change as the only cue.
22
+ */
23
+ function createRotationAffordance(opts = {}) {
24
+ const { bandPx = 24, paint = DEFAULT_PAINT, cursor, handle } = opts;
25
+ const annulusPaint = (() => {
26
+ if (!paint) return null;
27
+ if (!isAnnulusForm(paint)) return {
28
+ kind: "annulus",
29
+ stroke: paint
30
+ };
31
+ return {
32
+ kind: "annulus",
33
+ ...paint.fill ? { fill: paint.fill } : {},
34
+ ...paint.stroke ? { stroke: paint.stroke } : {},
35
+ ...paint.insetPx !== void 0 ? { insetPx: paint.insetPx } : {}
36
+ };
37
+ })();
38
+ return {
39
+ id: "selection.rotation-handle",
40
+ regions(state) {
41
+ const target = pickTarget(state);
42
+ if (!target) return [];
43
+ const b = target.bounds;
44
+ const halfW = b.width / 2;
45
+ const halfH = b.height / 2;
46
+ const pivot = localToWorld(transformOf(state, target.id), b.x + halfW, b.y + halfH);
47
+ const regionCursor = cursor ?? ((at, view) => rotateCursorAt(pivot, at, view.scale));
48
+ const bind = () => ({ initialScratch: {
49
+ targetId: target.id,
50
+ fixedPoint: pivot
51
+ } });
52
+ const region = {
53
+ id: "selection.rotation-handle",
54
+ targetId: target.id,
55
+ shape: {
56
+ kind: "annulus",
57
+ cx: b.x + halfW,
58
+ cy: b.y + halfH,
59
+ rx: halfW * Math.SQRT2,
60
+ ry: halfH * Math.SQRT2,
61
+ innerX: b.x,
62
+ innerY: b.y,
63
+ innerWidth: b.width,
64
+ innerHeight: b.height,
65
+ minBandPx: bandPx
66
+ },
67
+ ...annulusPaint ? { paint: annulusPaint } : {},
68
+ hitKind: "rotate-handle",
69
+ cursor: regionCursor,
70
+ bind
71
+ };
72
+ if (!handle) return [region];
73
+ return [region, {
74
+ id: "rotation-badge",
75
+ targetId: target.id,
76
+ shape: {
77
+ kind: "point",
78
+ x: b.x + halfW,
79
+ y: b.y,
80
+ hitRadiusPx: handle.hitRadiusPx,
81
+ standoff: {
82
+ px: handle.distancePx,
83
+ normal: {
84
+ x: 0,
85
+ y: -1
86
+ }
87
+ }
88
+ },
89
+ hitKind: "rotate-handle",
90
+ cursor: regionCursor,
91
+ bind
92
+ }];
93
+ }
94
+ };
95
+ }
96
+ function pickTarget(state) {
97
+ if (state.selection.length === 1) {
98
+ const id = state.selection[0];
99
+ if (!targetCanRotate(state, id)) return null;
100
+ const b = state.boundsOf(id);
101
+ return b ? {
102
+ id,
103
+ bounds: b
104
+ } : null;
105
+ }
106
+ if (state.multiActive && state.unionBounds) {
107
+ if (!targetCanRotate(state, MULTI_RESIZE_TARGET_ID)) return null;
108
+ return {
109
+ id: MULTI_RESIZE_TARGET_ID,
110
+ bounds: state.unionBounds
111
+ };
112
+ }
113
+ return null;
114
+ }
115
+
116
+ export { createRotationAffordance };
117
+ //# sourceMappingURL=rotationHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotationHandle.js","names":[],"sources":["../../../src/chrome/affordances/rotationHandle.ts"],"sourcesContent":["import type { Affordance, AffordanceBinding, AffordanceRegion, CommonAffordanceScratch } from '@weasel-js/core';\nimport type { ChromeState, Bounds } from '@weasel-js/core';\nimport type { CommandStroke, CommandFill } from '@weasel-js/paint';\nimport { MULTI_RESIZE_TARGET_ID } from '@weasel-js/core';\nimport { localToWorld, transformOf } from '@weasel-js/core';\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport { rotateCursorAt } from './rotateCursor';\nimport { targetCanRotate } from '../rotationHandleGeometry';\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 * 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 // `rotateAction` recomputes its own union pivot for multi-selection,\n // but the single-target case reads this.\n fixedPoint: pivot,\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 (!targetCanRotate(state, 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 (!targetCanRotate(state, MULTI_RESIZE_TARGET_ID)) return null;\n return { id: MULTI_RESIZE_TARGET_ID, bounds: state.unionBounds };\n }\n return null;\n}\n"],"mappings":";;;;;AA+CA,IAAM,iBAAiB,UACrB,UAAU,SAAS,YAAY,SAAS,aAAa;AAEvD,IAAM,gBAAkC;CACtC,MAAM,EAAE,OAAO;EAAE,MAAM;EAAS,OAAO;CAAyB,EAAE;CAClE,SAAS;AACX;;;;;;;;;;AAWA,SAAgB,yBACd,OAAkC,CAAC,GACvB;CACZ,MAAM,EAAE,SAAS,IAAI,QAAQ,eAAe,QAAQ,WAAW;CAI/D,MAAM,sBAEY;EACd,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,CAAC,cAAc,KAAK,GACtB,OAAO;GAAE,MAAM;GAAoB,QAAQ;EAAM;EAEnD,OAAO;GACL,MAAM;GACN,GAAI,MAAM,OAAO,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;GACzC,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;GAC/C,GAAI,MAAM,YAAY,SAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;EAClE;CACF,EAAA,CAAG;CAEL,OAAO;EACL,IAAI;EACJ,QAAQ,OAAiD;GACvD,MAAM,SAAS,WAAW,KAAK;GAC/B,IAAI,CAAC,QAAQ,OAAO,CAAC;GACrB,MAAM,IAAI,OAAO;GAKjB,MAAM,QAAQ,EAAE,QAAQ;GACxB,MAAM,QAAQ,EAAE,SAAS;GAEzB,MAAM,QAAQ,aAAa,YAAY,OAAO,OAAO,EAAE,GAAG,EAAE,IAAI,OAAO,EAAE,IAAI,KAAK;GAClF,MAAM,eAA2C,YAC1C,IAAI,SAAS,eAAe,OAAO,IAAI,KAAK,KAAK;GACxD,MAAM,cAAiC,EACrC,gBAAgB;IACd,UAAU,OAAO;IAGjB,YAAY;GACd,EACF;GAEA,MAAM,SAA2B;IAC/B,IAAI;IACJ,UAAU,OAAO;IACjB,OAAO;KACL,MAAM;KACN,IAAI,EAAE,IAAI;KACV,IAAI,EAAE,IAAI;KACV,IAAI,QAAQ,KAAK;KACjB,IAAI,QAAQ,KAAK;KACjB,QAAQ,EAAE;KACV,QAAQ,EAAE;KACV,YAAY,EAAE;KACd,aAAa,EAAE;KACf,WAAW;IACb;IACA,GAAI,eAAe,EAAE,OAAO,aAAa,IAAI,CAAC;IAC9C,SAAS;IACT,QAAQ;IACR;GACF;GACA,IAAI,CAAC,QAAQ,OAAO,CAAC,MAAM;GAe3B,OAAO,CAAC,QAAQ;IAbd,IAAI;IACJ,UAAU,OAAO;IACjB,OAAO;KACL,MAAM;KACN,GAAG,EAAE,IAAI;KACT,GAAG,EAAE;KACL,aAAa,OAAO;KACpB,UAAU;MAAE,IAAI,OAAO;MAAY,QAAQ;OAAE,GAAG;OAAG,GAAG;MAAG;KAAE;IAC7D;IACA,SAAS;IACT,QAAQ;IACR;GAEc,CAAK;EACvB;CACF;AACF;AAEA,SAAS,WAAW,OAA2D;CAC7E,IAAI,MAAM,UAAU,WAAW,GAAG;EAChC,MAAM,KAAK,MAAM,UAAU;EAG3B,IAAI,CAAC,gBAAgB,OAAO,EAAE,GAAG,OAAO;EACxC,MAAM,IAAI,MAAM,SAAS,EAAE;EAC3B,OAAO,IAAI;GAAE;GAAI,QAAQ;EAAE,IAAI;CACjC;CAIA,IAAI,MAAM,eAAe,MAAM,aAAa;EAC1C,IAAI,CAAC,gBAAgB,OAAO,sBAAsB,GAAG,OAAO;EAC5D,OAAO;GAAE,IAAI;GAAwB,QAAQ,MAAM;EAAY;CACjE;CACA,OAAO;AACT"}
@@ -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,KAAK;CAGxB,MAAM,KAAK,KAAK,IAAI,KAAK,IAAI;CAC7B,MAAM,KAAK,KAAK,IAAI,KAAK,IAAI;CAC7B,OAAO,IAAI,aAAa;EACtB;EAAG;EAAG;EACN,CAAC;EAAG;EAAG;EACP;EAAI;EAAI;CACV,CAAC;AACH;;AAGA,SAAgB,kBACd,KACA,eACA,SACA,WACA,YACA,MACe;CACf,MAAM,SAA6B;EAAE,OAAO;EAAM,aAAa;EAAgB,GAAG;CAAW;CAC7F,MAAM,MAAqB,CAAC;CAC5B,MAAM,OAAO,QAAQ,OAAO;CAC5B,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,SAAS,cAAc,EAAE;EAC/B,IAAI,CAAC,QAAQ;EAGb,MAAM,KAAK,kBAAkB,MAAM;EACnC,MAAM,IAAI,gBAAgB,IAAI;EAC9B,MAAM,QAAQ,cAAc,QAAQ,EAAE,GAAG,KAAK,KAAK;EACnD,MAAM,KAAK,YACP,UAAU,MAAM,IAChB,iBAAiB,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM,YAAY,QAAQ,CAAC,CAAC;EACtF,KAAK,MAAM,UAAU,IAAI;GACvB,MAAM,SAAS,aAAa,IAAI,OAAO,GAAG,OAAO,CAAC;GAClD,MAAM,CAAC,KAAK,OAAO,cAAc,OAAO,GAAG,OAAO,GAAG,CAAC;GACtD,MAAM,SAAS;IAAE,GAAG;IAAK,GAAG;GAAI;GAChC,MAAM,WAAW;IACf,GAAG,OAAO,IAAI;IACd,GAAG,OAAO,IAAI;IACd,OAAO,QAAQ;IACf,QAAQ,QAAQ;GAClB;GACA,MAAM,UAAuB;IAC3B,MAAM;IACN,MAAM,YAAY,SAAS,GAAG,SAAS,GAAG,SAAS,OAAO,SAAS,MAAM;IACzE,MAAM,QAAQ;GAChB;GACA,MAAM,YAAyB;IAC7B,MAAM;IACN,MAAM,YAAY,SAAS,GAAG,SAAS,GAAG,SAAS,OAAO,SAAS,MAAM;IACzE,QAAQ,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"}