@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,160 @@
1
+ import { documentOf, followerOpsFor, isEnvelope, moveEachOps, nodeDescriptors, poseDescriptorOf, sameValue, scenePoseFrame, translatePoseViaDescriptor } from "@weasel-js/core";
2
+ import * as coreOps from "@weasel-js/core/ops";
3
+
4
+ // src/actions/swap/swapOps.ts
5
+ function placeOf(scene, id) {
6
+ const node = scene.get(id);
7
+ const parent = node.parent ?? null;
8
+ const siblings = parent === null ? scene.roots : scene.childrenOf(parent);
9
+ const index = siblings.indexOf(id);
10
+ return {
11
+ parent,
12
+ layer: node.layer,
13
+ index,
14
+ before: siblings[index + 1] ?? null
15
+ };
16
+ }
17
+ /** The ops that put `id`, now at `from`, into `to`'s parent, layer and sibling slot. */
18
+ function landOps(id, from, to, label) {
19
+ const ops = [];
20
+ let parent = from.parent;
21
+ if (from.layer !== to.layer) {
22
+ if (parent !== null) {
23
+ ops.push(coreOps.reparent({
24
+ id,
25
+ fromParentId: parent,
26
+ toParentId: null,
27
+ label,
28
+ coalesceKey: `reparent:${id}:orphan`
29
+ }));
30
+ parent = null;
31
+ }
32
+ ops.push(coreOps.setLayer({
33
+ id,
34
+ from: from.layer,
35
+ to: to.layer,
36
+ label
37
+ }));
38
+ }
39
+ ops.push(coreOps.reparent({
40
+ id,
41
+ fromParentId: parent,
42
+ toParentId: to.parent,
43
+ toSlot: {
44
+ index: to.index,
45
+ before: to.before
46
+ },
47
+ label
48
+ }));
49
+ return ops;
50
+ }
51
+ /**
52
+ * The poses that keep `id`, translated to `world`, where it is once it is stored under `parent`: its own,
53
+ * and through an envelope, which stores its children in its parent's frame, those of its children. `from` is
54
+ * each pose as stored once the translation has applied. `null` when `parent`'s frame is singular.
55
+ */
56
+ function reframed(scene, frame, id, parent, worldOf, from, label) {
57
+ const ops = [];
58
+ const keep = (at) => {
59
+ const node = scene.get(at);
60
+ if (node === void 0) return true;
61
+ if (node.derivePose === void 0) {
62
+ const to = frame.localUnder(parent, worldOf(at));
63
+ if (to === null) return false;
64
+ const was = from(at);
65
+ if (!sameValue(was, to)) ops.push(coreOps.setPose({
66
+ id: at,
67
+ from: was,
68
+ to,
69
+ label
70
+ }));
71
+ }
72
+ return !isEnvelope(node) || scene.childrenOf(at).every(keep);
73
+ };
74
+ return keep(id) ? ops : null;
75
+ }
76
+ /**
77
+ * The ops that make `a` and `b` trade places, for one undo step: each moves onto the other's bounds, carrying
78
+ * what is inside it, and takes the other's parent, layer and place among its siblings. Poses are read from the
79
+ * document, so a drag in flight over either one does not count as where it is. `null` when either would land
80
+ * in a singular frame, or past the double range.
81
+ *
82
+ * This is the commit for the `swap` command and for a swap drop; whether the two may trade places is
83
+ * `swappable`'s to say.
84
+ */
85
+ function swapOps(scene, a, b, deps = {}, label = "Swap") {
86
+ const doc = documentOf(scene);
87
+ const ia = a;
88
+ const ib = b;
89
+ if (doc.get(ia) === void 0 || doc.get(ib) === void 0 || a === b) return null;
90
+ const frame = scenePoseFrame(doc);
91
+ const descriptorOf = nodeDescriptors(doc, poseDescriptorOf(deps.poseDescriptor));
92
+ const from = descriptorOf(ia).getBounds(frame.world(ia));
93
+ const to = descriptorOf(ib).getBounds(frame.world(ib));
94
+ const dx = to.x - from.x;
95
+ const dy = to.y - from.y;
96
+ const moved = moveEachOps(doc, [{
97
+ ids: [a],
98
+ dx,
99
+ dy
100
+ }, {
101
+ ids: [b],
102
+ dx: -dx,
103
+ dy: -dy
104
+ }], deps, label);
105
+ if (moved.length === 0 && (dx !== 0 || dy !== 0)) return null;
106
+ const ops = [...moved];
107
+ const pa = placeOf(doc, ia);
108
+ const pb = placeOf(doc, ib);
109
+ if (pa.parent === pb.parent) {
110
+ const siblings = [...pa.parent === null ? doc.roots : doc.childrenOf(pa.parent)];
111
+ siblings[pa.index] = b;
112
+ siblings[pb.index] = a;
113
+ ops.push(coreOps.setChildOrder({
114
+ orders: [{
115
+ parentId: pa.parent,
116
+ ids: siblings
117
+ }],
118
+ label
119
+ }));
120
+ if (pa.layer !== pb.layer) {
121
+ ops.push(coreOps.setLayer({
122
+ id: a,
123
+ from: pa.layer,
124
+ to: pb.layer,
125
+ label
126
+ }));
127
+ ops.push(coreOps.setLayer({
128
+ id: b,
129
+ from: pb.layer,
130
+ to: pa.layer,
131
+ label
132
+ }));
133
+ }
134
+ return ops;
135
+ }
136
+ ops.push(...landOps(ia, pa, pb, label), ...landOps(ib, pb, pa, label));
137
+ const stored = new Map(moved.filter((op) => op.name === "transform").map((op) => [op.args.id, op.args.to]));
138
+ const storedOf = (id) => stored.has(id) ? stored.get(id) : doc.get(id).pose;
139
+ const offsetOf = (root) => root === ia ? {
140
+ dx,
141
+ dy
142
+ } : {
143
+ dx: -dx,
144
+ dy: -dy
145
+ };
146
+ for (const [root, parent] of [[ia, pb.parent], [ib, pa.parent]]) {
147
+ const d = offsetOf(root);
148
+ const worldOf = (id) => translatePoseViaDescriptor(frame.world(id), d.dx, d.dy, descriptorOf(id));
149
+ const kept = reframed(doc, frame, root, parent, worldOf, storedOf, label);
150
+ if (kept === null) return null;
151
+ ops.push(...kept);
152
+ }
153
+ const followers = followerOpsFor(doc, /* @__PURE__ */ new Map([[a, pb.parent], [b, pa.parent]]), label);
154
+ if (followers === null) return null;
155
+ ops.push(...followers);
156
+ return ops;
157
+ }
158
+
159
+ export { swapOps };
160
+ //# sourceMappingURL=swapOps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swapOps.js","names":[],"sources":["../../../src/actions/swap/swapOps.ts"],"sourcesContent":["import type { ActionDeps } from '@weasel-js/routing';\nimport type { NodeId, Op, Scene } from '@weasel-js/core';\nimport {\n documentOf, followerOpsFor, isEnvelope, moveEachOps, nodeDescriptors, poseDescriptorOf, sameValue, scenePoseFrame,\n translatePoseViaDescriptor, type PoseFrame,\n} from '@weasel-js/core';\nimport * as coreOps from '@weasel-js/core/ops';\n\n\n/** Where a node sits: its parent, its layer, and the sibling it is just below (`null` when it is last). */\ninterface Place {\n parent: NodeId | null;\n layer: string;\n index: number;\n before: string | null;\n}\n\nfunction placeOf(scene: Scene<unknown, string, unknown>, id: NodeId): Place {\n const node = scene.get(id)!;\n const parent = node.parent ?? null;\n const siblings = parent === null ? scene.roots : scene.childrenOf(parent);\n const index = siblings.indexOf(id);\n return { parent, layer: node.layer, index, before: siblings[index + 1] ?? null };\n}\n\n/** The ops that put `id`, now at `from`, into `to`'s parent, layer and sibling slot. */\nfunction landOps(id: NodeId, from: Place, to: Place, label: string): Op[] {\n const ops: Op[] = [];\n let parent = from.parent as string | null;\n if (from.layer !== to.layer) {\n // The scene refuses a layer change on a node whose parent is on another layer.\n if (parent !== null) {\n ops.push(coreOps.reparent({ id, fromParentId: parent, toParentId: null, label, coalesceKey: `reparent:${id}:orphan` }));\n parent = null;\n }\n ops.push(coreOps.setLayer({ id, from: from.layer, to: to.layer, label }));\n }\n ops.push(coreOps.reparent({\n id, fromParentId: parent, toParentId: to.parent, toSlot: { index: to.index, before: to.before }, label,\n }));\n return ops;\n}\n\n/**\n * The poses that keep `id`, translated to `world`, where it is once it is stored under `parent`: its own,\n * and through an envelope, which stores its children in its parent's frame, those of its children. `from` is\n * each pose as stored once the translation has applied. `null` when `parent`'s frame is singular.\n */\nfunction reframed(\n scene: Scene<unknown, string, unknown>,\n frame: PoseFrame<unknown>,\n id: NodeId,\n parent: NodeId | null,\n worldOf: (id: NodeId) => unknown,\n from: (id: NodeId) => unknown,\n label: string,\n): Op[] | null {\n const ops: Op[] = [];\n const keep = (at: NodeId): boolean => {\n const node = scene.get(at);\n if (node === undefined) return true;\n // A derived pose is not stored, so it has nothing to rewrite.\n if (node.derivePose === undefined) {\n const to = frame.localUnder(parent, worldOf(at));\n if (to === null) return false;\n const was = from(at);\n if (!sameValue(was, to)) ops.push(coreOps.setPose<unknown>({ id: at, from: was, to, label }));\n }\n return !isEnvelope(node) || scene.childrenOf(at).every(keep);\n };\n return keep(id) ? ops : null;\n}\n\n/**\n * The ops that make `a` and `b` trade places, for one undo step: each moves onto the other's bounds, carrying\n * what is inside it, and takes the other's parent, layer and place among its siblings. Poses are read from the\n * document, so a drag in flight over either one does not count as where it is. `null` when either would land\n * in a singular frame, or past the double range.\n *\n * This is the commit for the `swap` command and for a swap drop; whether the two may trade places is\n * `swappable`'s to say.\n */\nexport function swapOps(\n scene: Scene<unknown, string, unknown>,\n a: string,\n b: string,\n deps: Pick<ActionDeps, 'poseDescriptor' | 'geometryProjection'> = {},\n label = 'Swap',\n): Op[] | null {\n const doc = documentOf(scene);\n const ia = a as NodeId;\n const ib = b as NodeId;\n if (doc.get(ia) === undefined || doc.get(ib) === undefined || a === b) return null;\n const frame = scenePoseFrame(doc);\n const descriptorOf = nodeDescriptors(doc, poseDescriptorOf(deps.poseDescriptor));\n const from = descriptorOf(ia).getBounds(frame.world(ia));\n const to = descriptorOf(ib).getBounds(frame.world(ib));\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n\n const moved = moveEachOps(doc, [{ ids: [a], dx, dy }, { ids: [b], dx: -dx, dy: -dy }], deps, label);\n if (moved.length === 0 && (dx !== 0 || dy !== 0)) return null;\n const ops: Op[] = [...moved];\n\n const pa = placeOf(doc, ia);\n const pb = placeOf(doc, ib);\n if (pa.parent === pb.parent) {\n const siblings = [...(pa.parent === null ? doc.roots : doc.childrenOf(pa.parent))] as string[];\n siblings[pa.index] = b;\n siblings[pb.index] = a;\n ops.push(coreOps.setChildOrder({ orders: [{ parentId: pa.parent, ids: siblings }], label }));\n if (pa.layer !== pb.layer) {\n ops.push(coreOps.setLayer({ id: a, from: pa.layer, to: pb.layer, label }));\n ops.push(coreOps.setLayer({ id: b, from: pb.layer, to: pa.layer, label }));\n }\n return ops;\n }\n\n ops.push(...landOps(ia, pa, pb, label), ...landOps(ib, pb, pa, label));\n // Each node, and an envelope's children, keeps its new world place in its new parent's frame.\n const stored = new Map(moved.filter((op) => op.name === 'transform')\n .map((op) => [(op.args as { id: string }).id, (op.args as { to: unknown }).to]));\n const storedOf = (id: NodeId): unknown => (stored.has(id) ? stored.get(id) : doc.get(id)!.pose);\n const offsetOf = (root: NodeId) => (root === ia ? { dx, dy } : { dx: -dx, dy: -dy });\n for (const [root, parent] of [[ia, pb.parent], [ib, pa.parent]] as const) {\n const d = offsetOf(root);\n const worldOf = (id: NodeId) => translatePoseViaDescriptor(frame.world(id), d.dx, d.dy, descriptorOf(id));\n const kept = reframed(doc, frame, root, parent, worldOf, storedOf, label);\n if (kept === null) return null;\n ops.push(...kept);\n }\n const followers = followerOpsFor(doc, new Map([[a, pb.parent], [b, pa.parent]]), label);\n if (followers === null) return null;\n ops.push(...followers);\n return ops;\n}\n"],"mappings":";;;;AAiBA,SAAS,QAAQ,OAAwC,IAAmB;CAC1E,MAAM,OAAO,MAAM,IAAI,EAAE;CACzB,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,WAAW,WAAW,OAAO,MAAM,QAAQ,MAAM,WAAW,MAAM;CACxE,MAAM,QAAQ,SAAS,QAAQ,E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rB,OAAO;AACT"}
@@ -0,0 +1,90 @@
1
+ import { duplicateAction, duplicateSelection } from "../edit/duplicate.js";
2
+ import { selectionTransformAnswer, selectionTransformOps } from "./transformSelection.js";
3
+ import { writesLocked } from "../lockedWrites.js";
4
+ import { EDIT_GROUP } from "../../actionGroups.js";
5
+ import { DUPLICATE_OFFSET, lastTransform, recordTransform, requiresContent, requiresOperands } from "@weasel-js/core";
6
+ import { ActionDisabledReason, BETWEEN_GESTURES, eligibleNow } from "@weasel-js/routing";
7
+ import { commitTransformOps as commitTransformOps$1 } from "@weasel-js/core/engine";
8
+
9
+ // src/actions/transformAgain/action.ts
10
+ var LABEL = "Transform Again";
11
+ /** With nothing recorded yet, a repeat is a plain duplicate. */
12
+ var FIRST = {
13
+ kind: "duplicate",
14
+ dx: DUPLICATE_OFFSET,
15
+ dy: DUPLICATE_OFFSET
16
+ };
17
+ /** Whether repeating `t` now would change anything: a duplicate where the
18
+ * mode lets Duplicate run and the selection holds content, a transform
19
+ * where it builds a batch the followers accept. */
20
+ function canRepeat(deps, t) {
21
+ if (t.kind === "duplicate") {
22
+ if (!eligibleNow(duplicateAction, deps.ruleCtx)) return ActionDisabledReason.NotApplicable;
23
+ return requiresContent(1)(deps);
24
+ }
25
+ return selectionTransformAnswer(deps, t, LABEL);
26
+ }
27
+ /** Apply `t` to the selection as one undo entry. Returns the ids selected
28
+ * afterwards, or null when nothing changed. */
29
+ function replay(deps, scene, t) {
30
+ if (t.kind === "duplicate") return duplicateSelection(deps, t.dx, t.dy, LABEL);
31
+ const selected = [...deps.operands.get()];
32
+ const ops = selectionTransformOps(deps, scene, selected, t, LABEL);
33
+ return !writesLocked(scene, ops) && commitTransformOps$1(deps, ops, LABEL) ? selected : null;
34
+ }
35
+ /**
36
+ * Repeat the last move, rotate, resize, nudge, duplicate, or Alt-drag clone on
37
+ * the current selection, as one undo entry. A repeated duplicate copies the
38
+ * selection — the last copies — again by the same offset, so pressing it over
39
+ * and over makes a step-and-repeat; moving the copies between a duplicate and
40
+ * its repeat changes that offset. With nothing to repeat it duplicates.
41
+ */
42
+ var transformAgainAction = {
43
+ id: "transformAgain",
44
+ label: LABEL,
45
+ icon: /* @icon */ "editing:transformAgain",
46
+ group: EDIT_GROUP,
47
+ defaultBinding: [{
48
+ spec: {
49
+ kind: "key",
50
+ key: "d",
51
+ mods: { mod: true },
52
+ phase: BETWEEN_GESTURES
53
+ },
54
+ opts: { id: "transformAgain.key" }
55
+ }],
56
+ eligible: { capability: "transforms-selection" },
57
+ requires: [
58
+ "scene",
59
+ "operands",
60
+ "applyOps",
61
+ "poseDescriptor",
62
+ "geometryProjection",
63
+ "resizePolicy",
64
+ "view",
65
+ "boundsIncludeStroke",
66
+ "drawnBoxes",
67
+ "transformFollowers",
68
+ "ruleCtx"
69
+ ],
70
+ invoker: {
71
+ timing: "immediate",
72
+ run: (deps) => {
73
+ const scene = deps.scene;
74
+ if (!scene || !deps.operands || deps.operands.get().length === 0) return;
75
+ const t = lastTransform(scene) ?? FIRST;
76
+ if (canRepeat(deps, t) !== true) return;
77
+ const subject = replay(deps, scene, t);
78
+ if (subject) recordTransform(scene, t, subject);
79
+ }
80
+ },
81
+ enabled: (deps) => {
82
+ const selected = requiresOperands(deps);
83
+ if (selected !== true) return selected;
84
+ if (!deps?.scene) return ActionDisabledReason.NotApplicable;
85
+ return canRepeat(deps, lastTransform(deps.scene) ?? FIRST);
86
+ }
87
+ };
88
+
89
+ export { transformAgainAction };
90
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","names":["commitTransformOps"],"sources":["../../../src/actions/transformAgain/action.ts"],"sourcesContent":["import { ActionDisabledReason, eligibleNow, type Action, type ActionDeps, type ActionUnavailable, BETWEEN_GESTURES } from '@weasel-js/routing';\nimport type { Scene } from '@weasel-js/core/engine';\nimport { commitTransformOps } from '@weasel-js/core/engine';\nimport { duplicateAction, duplicateSelection } from '../edit/duplicate';\nimport { DUPLICATE_OFFSET, requiresContent, requiresOperands, lastTransform, recordTransform, type RepeatableTransform } from '@weasel-js/core';\nimport { selectionTransformAnswer, selectionTransformOps } from './transformSelection';\nimport { icon } from '../../icons.gen';\nimport { writesLocked } from '../lockedWrites';\nimport { EDIT_GROUP } from '../../actionGroups';\n\nconst LABEL = 'Transform Again';\n\n/** With nothing recorded yet, a repeat is a plain duplicate. */\nconst FIRST: RepeatableTransform = { kind: 'duplicate', dx: DUPLICATE_OFFSET, dy: DUPLICATE_OFFSET };\n\ntype AnyScene = Scene<unknown, string, unknown>;\n\n/** Whether repeating `t` now would change anything: a duplicate where the\n * mode lets Duplicate run and the selection holds content, a transform\n * where it builds a batch the followers accept. */\nfunction canRepeat(deps: ActionDeps, t: RepeatableTransform): true | ActionUnavailable {\n if (t.kind === 'duplicate') {\n if (!eligibleNow(duplicateAction, deps.ruleCtx)) return ActionDisabledReason.NotApplicable;\n return requiresContent(1)(deps);\n }\n return selectionTransformAnswer(deps, t, LABEL);\n}\n\n/** Apply `t` to the selection as one undo entry. Returns the ids selected\n * afterwards, or null when nothing changed. */\nfunction replay(deps: ActionDeps, scene: AnyScene, t: RepeatableTransform): readonly string[] | null {\n if (t.kind === 'duplicate') return duplicateSelection(deps, t.dx, t.dy, LABEL);\n const selected = [...deps.operands!.get()] as string[];\n const ops = selectionTransformOps(deps, scene, selected, t, LABEL);\n return !writesLocked(scene, ops) && commitTransformOps(deps, ops, LABEL) ? selected : null;\n}\n\n/**\n * Repeat the last move, rotate, resize, nudge, duplicate, or Alt-drag clone on\n * the current selection, as one undo entry. A repeated duplicate copies the\n * selection — the last copies — again by the same offset, so pressing it over\n * and over makes a step-and-repeat; moving the copies between a duplicate and\n * its repeat changes that offset. With nothing to repeat it duplicates.\n */\nexport const transformAgainAction: Action & { requires: string[] } = {\n id: 'transformAgain',\n label: LABEL,\n icon: icon('transformAgain'),\n group: EDIT_GROUP,\n defaultBinding: [{ spec: { kind: 'key', key: 'd', mods: { mod: true }, phase: BETWEEN_GESTURES }, opts: { id: 'transformAgain.key' } }],\n eligible: { capability: 'transforms-selection' },\n requires: [\n 'scene', 'operands', 'applyOps', 'poseDescriptor', 'geometryProjection', 'resizePolicy', 'view',\n 'boundsIncludeStroke', 'drawnBoxes', 'transformFollowers', 'ruleCtx',\n ],\n invoker: {\n timing: 'immediate',\n run: (deps) => {\n const scene = deps.scene;\n if (!scene || !deps.operands || deps.operands.get().length === 0) return;\n const t = lastTransform(scene) ?? FIRST;\n if (canRepeat(deps, t) !== true) return;\n const subject = replay(deps, scene, t);\n if (subject) recordTransform(scene, t, subject);\n },\n },\n enabled: (deps) => {\n const selected = requiresOperands(deps);\n if (selected !== true) return selected;\n if (!deps?.scene) return ActionDisabledReason.NotApplicable;\n return canRepeat(deps, lastTransform(deps.scene) ?? FIRST);\n },\n};\n"],"mappings":";;;;;;;;;AAUA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;AAGd,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA6B;AAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAa,CAAA,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAkB,CAAA,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAiB,CAAA;;;;AAOnG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,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"../resize/replay.js";
2
+ import { rotateSelectionOps } from "../rotate/replay.js";
3
+ import { opsAnswer, writesLocked } from "../lockedWrites.js";
4
+ import { moveNodesOps, recordTransform } from "@weasel-js/core";
5
+ import { ActionDisabledReason } from "@weasel-js/routing";
6
+ import { commitTransformOps as commitTransformOps$1, finishTransformOps } from "@weasel-js/core/engine";
7
+
8
+ // src/actions/transformAgain/transformSelection.ts
9
+ /** The batch applying `t` to `selected`, not yet finished by the transform followers; empty when it changes nothing. */
10
+ function selectionTransformOps(deps, scene, selected, t, label) {
11
+ switch (t.kind) {
12
+ case "translate": return moveNodesOps(scene, selected, {
13
+ dx: t.dx,
14
+ dy: t.dy
15
+ }, deps, label);
16
+ case "rotate": return rotateSelectionOps(scene, selected, deps, t.angle, t.pivot, label);
17
+ case "scale": return resizeSelectionOps(scene, selected, t.anchor, t.to, deps, label);
18
+ }
19
+ }
20
+ /** `enabled`'s answer for applying `t` to the selection (ruled 2026-11-09 and 2026-11-10): not applicable when the
21
+ * batch the followers finish changes nothing, locked when it would rewrite a locked node. */
22
+ function selectionTransformAnswer(deps, t, label) {
23
+ const { scene, operands } = deps;
24
+ if (!scene || !operands) return ActionDisabledReason.NotApplicable;
25
+ const ops = selectionTransformOps(deps, scene, [...operands.get()], t, label);
26
+ const all = ops.length > 0 ? finishTransformOps(deps, ops, label) : null;
27
+ return all ? opsAnswer(scene, all) : ActionDisabledReason.NotApplicable;
28
+ }
29
+ /**
30
+ * Apply `t` to the selection as one undo entry labeled `label`, finished by
31
+ * the `transformFollowers` dep as a drag's transform is, and record it for
32
+ * Transform Again. An action calling it requires what Transform Again does
33
+ * for that kind: `scene`, `operands`, `applyOps`, `poseDescriptor`,
34
+ * `transformFollowers`, and `geometryProjection` for a move or `view`,
35
+ * `boundsIncludeStroke` and `drawnBoxes` for a rotate or a resize. Returns
36
+ * whether anything changed.
37
+ */
38
+ function transformSelection(deps, t, label) {
39
+ const { scene, operands } = deps;
40
+ if (!scene || !operands) return false;
41
+ const selected = [...operands.get()];
42
+ const ops = selectionTransformOps(deps, scene, selected, t, label);
43
+ if (writesLocked(scene, ops) || !commitTransformOps$1(deps, ops, label)) return false;
44
+ recordTransform(scene, t, selected);
45
+ return true;
46
+ }
47
+
48
+ export { selectionTransformAnswer, selectionTransformOps, transformSelection };
49
+ //# sourceMappingURL=transformSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformSelection.js","names":["commitTransformOps"],"sources":["../../../src/actions/transformAgain/transformSelection.ts"],"sourcesContent":["import type { ActionDeps } from '@weasel-js/routing';\nimport type { Op } from '@weasel-js/core';\nimport type { AnyScene } from '@weasel-js/core/engine';\nimport { commitTransformOps, finishTransformOps } from '@weasel-js/core/engine';\nimport { ActionDisabledReason, type ActionUnavailable } from '@weasel-js/routing';\nimport { moveNodesOps, recordTransform, type RepeatableTransform } from '@weasel-js/core';\nimport { resizeSelectionOps } from '../resize/replay';\nimport { rotateSelectionOps } from '../rotate/replay';\nimport { opsAnswer, writesLocked } from '../lockedWrites';\n\n/** A move, rotate or resize the selection can be given: a {@link RepeatableTransform} other than a duplicate. */\nexport type SelectionTransform = Exclude<RepeatableTransform, { kind: 'duplicate' }>;\n\n/** The batch applying `t` to `selected`, not yet finished by the transform followers; empty when it changes nothing. */\nexport function selectionTransformOps(\n deps: ActionDeps, scene: AnyScene, selected: readonly string[], t: SelectionTransform, label: string,\n): Op[] {\n switch (t.kind) {\n case 'translate':\n return moveNodesOps(scene, selected, { dx: t.dx, dy: t.dy }, deps, label);\n case 'rotate':\n return rotateSelectionOps(scene, selected, deps, t.angle, t.pivot, label);\n case 'scale':\n return resizeSelectionOps(scene, selected, t.anchor, t.to, deps, label);\n }\n}\n\n/** `enabled`'s answer for applying `t` to the selection (ruled 2026-11-09 and 2026-11-10): not applicable when the\n * batch the followers finish changes nothing, locked when it would rewrite a locked node. */\nexport function selectionTransformAnswer(deps: ActionDeps, t: SelectionTransform, label: string): true | ActionUnavailable {\n const { scene, operands } = deps;\n if (!scene || !operands) return ActionDisabledReason.NotApplicable;\n const ops = selectionTransformOps(deps, scene, [...operands.get()] as string[], t, label);\n const all = ops.length > 0 ? finishTransformOps(deps, ops, label) : null;\n return all ? opsAnswer(scene, all) : ActionDisabledReason.NotApplicable;\n}\n\n/**\n * Apply `t` to the selection as one undo entry labeled `label`, finished by\n * the `transformFollowers` dep as a drag's transform is, and record it for\n * Transform Again. An action calling it requires what Transform Again does\n * for that kind: `scene`, `operands`, `applyOps`, `poseDescriptor`,\n * `transformFollowers`, and `geometryProjection` for a move or `view`,\n * `boundsIncludeStroke` and `drawnBoxes` for a rotate or a resize. Returns\n * whether anything changed.\n */\nexport function transformSelection(deps: ActionDeps, t: SelectionTransform, label: string): boolean {\n const { scene, operands } = deps;\n if (!scene || !operands) return false;\n const selected = [...operands.get()] as string[];\n const ops = selectionTransformOps(deps, scene, selected, t, label);\n if (writesLocked(scene, ops) || !commitTransformOps(deps, ops, label)) return false;\n recordTransform(scene, t, selected);\n return true;\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,sBACd,MAAkB,OAAiB,UAA6B,GAAuB,OACjF;CACN,QAAQ,EAAE,MAAV;EACE,KAAK,aACH,OAAO,aAAa,OAAO,UAAU;GAAE,IAAI,EAAE;GAAI,IAAI,EAAE;EAAG,GAAG,MAAM,KAAK;EAC1E,KAAK,UACH,OAAO,mBAAmB,OAAO,UAAU,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK;EAC1E,KAAK,SACH,OAAO,mBAAmB,OAAO,UAAU,EAAE,QAAQ,EAAE,IAAI,MAAM,KAAK;CAC1E;AACF;;;AAIA,SAAgB,yBAAyB,MAAkB,GAAuB,OAAyC;CACzH,MAAM,EAAE,OAAO,aAAa;CAC5B,IAAI,CAAC,SAAS,CAAC,UAAU,OAAO,qBAAqB;CACrD,MAAM,MAAM,sBAAsB,MAAM,OAAO,CAAC,GAAG,SAAS,IAAI,CAAC,GAAe,GAAG,KAAK;CACxF,MAAM,MAAM,IAAI,SAAS,IAAI,mBAAmB,MAAM,KAAK,KAAK,IAAI;CACpE,OAAO,MAAM,UAAU,OAAO,GAAG,IAAI,qBAAqB;AAC5D;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAAkB,GAAuB,OAAwB;CAClG,MAAM,EAAE,OAAO,aAAa;CAC5B,IAAI,CAAC,SAAS,CAAC,UAAU,OAAO;CAChC,MAAM,WAAW,CAAC,GAAG,SAAS,IAAI,CAAC;CACnC,MAAM,MAAM,sBAAsB,MAAM,OAAO,UAAU,GAAG,KAAK;CACjE,IAAI,aAAa,OAAO,GAAG,KAAK,CAACA,qBAAmB,MAAM,KAAK,KAAK,GAAG,OAAO;CAC9E,gBAAgB,OAAO,GAAG,QAAQ;CAClC,OAAO;AACT"}
@@ -0,0 +1,130 @@
1
+ import { resolveOperand } from "./operands.js";
2
+ import { booleanPieces } from "./pieces.js";
3
+ import { commitPieces } from "./commit.js";
4
+ import { NodeOutlineError } from "@weasel-js/core";
5
+ import { resolveFill } from "@weasel-js/paint";
6
+
7
+ // src/booleans/booleans.ts
8
+ var LABEL = {
9
+ union: "Union",
10
+ intersect: "Intersect",
11
+ subtract: "Subtract",
12
+ exclude: "Exclude",
13
+ divide: "Divide",
14
+ crop: "Crop",
15
+ trim: "Trim",
16
+ merge: "Merge"
17
+ };
18
+ /** @internal The operands behind `sel`, back to front, or the result that
19
+ * says why there are too few. Reads the adapter and changes nothing. */
20
+ function resolveEntries(adapter, sel, op, opts) {
21
+ let resolved;
22
+ try {
23
+ resolved = sel.map((id) => ({
24
+ id,
25
+ operand: resolveOperand(adapter, id, opts)
26
+ }));
27
+ } catch (err) {
28
+ if (err instanceof NodeOutlineError) return {
29
+ kind: "failed",
30
+ reason: "outlines",
31
+ error: err
32
+ };
33
+ throw err;
34
+ }
35
+ const entries = resolved.filter((e) => e.operand != null).sort((a, b) => adapter.compareZ(a.id, b.id));
36
+ if (entries.length === 0) return {
37
+ kind: "noop",
38
+ reason: "no-paths"
39
+ };
40
+ if (op === "subtract" && entries.length < 2) return {
41
+ kind: "noop",
42
+ reason: "too-few-for-subtract"
43
+ };
44
+ if (entries.length < 2) return {
45
+ kind: "noop",
46
+ reason: "no-paths"
47
+ };
48
+ return entries;
49
+ }
50
+ /** How many of `sel` give an operand, read without outlining a stroke: what the Pathfinder actions'
51
+ * `enabled` counts. An outline that cannot be built yet counts, so a run can say why it stopped. */
52
+ function countOperands(adapter, sel) {
53
+ let n = 0;
54
+ for (const id of sel) try {
55
+ if (resolveOperand(adapter, id, { strokes: "ignore" })) n++;
56
+ } catch (err) {
57
+ if (!(err instanceof NodeOutlineError)) throw err;
58
+ n++;
59
+ }
60
+ return n;
61
+ }
62
+ /** The operands back to front and the pieces `op` makes of them, or the
63
+ * result that says why it makes none. Reads the adapter and changes nothing. */
64
+ function planBooleanOp(adapter, sel, op, opts) {
65
+ const entries = resolveEntries(adapter, sel, op, opts);
66
+ if ("kind" in entries) return entries;
67
+ const fillKey = (i) => {
68
+ const { id, operand } = entries[i];
69
+ const paint = operand.paint ?? adapter.getPaint?.(id);
70
+ return paint ? JSON.stringify(resolveFill(paint.fill)) : i;
71
+ };
72
+ const pieces = booleanPieces(op, entries.map((e) => e.operand.path), fillKey);
73
+ if (pieces.length === 0) return {
74
+ kind: "noop",
75
+ reason: "empty-result"
76
+ };
77
+ return {
78
+ entries,
79
+ pieces
80
+ };
81
+ }
82
+ /**
83
+ * What {@link applyBooleanOp} would make of the selection, without minting a
84
+ * node or committing anything: for drawing an operation before it is applied.
85
+ */
86
+ function previewBooleanOp(adapter, op, opts = {}) {
87
+ const plan = planBooleanOp(adapter, [...adapter.getSelection()], op, opts);
88
+ if ("kind" in plan) return plan;
89
+ return {
90
+ kind: "pieces",
91
+ pieces: plan.pieces.map((piece) => {
92
+ const { id, operand } = plan.entries[piece.source];
93
+ return operand.paint ? {
94
+ path: piece.path,
95
+ sourceId: id,
96
+ paint: operand.paint
97
+ } : {
98
+ path: piece.path,
99
+ sourceId: id
100
+ };
101
+ })
102
+ };
103
+ }
104
+ /**
105
+ * Run one Boolean operation over the selected paths and commit the result as a
106
+ * single undoable batch.
107
+ *
108
+ * Operands are ordered back-to-front, which is what makes `subtract` mean
109
+ * "everything in front removed from the backmost shape". Returns without
110
+ * mutating anything when the selection holds no paths, or too few for the
111
+ * requested operation. `opts.strokes` says what a stroked operand gives.
112
+ */
113
+ function applyBooleanOp(adapter, op, opts = {}) {
114
+ const sel = [...adapter.getSelection()];
115
+ const plan = planBooleanOp(adapter, sel, op, opts);
116
+ if ("kind" in plan) return plan;
117
+ const { entries, pieces } = plan;
118
+ const made = pieces.map((piece) => ({
119
+ path: piece.path,
120
+ source: piece.source,
121
+ producedBy: op
122
+ }));
123
+ return {
124
+ kind: "applied",
125
+ resultIds: commitPieces(adapter, sel, entries, made, LABEL[op])
126
+ };
127
+ }
128
+
129
+ export { applyBooleanOp, countOperands, previewBooleanOp, resolveEntries };
130
+ //# sourceMappingURL=booleans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"booleans.js","names":[],"sources":["../../src/booleans/booleans.ts"],"sourcesContent":["/**\n * Pure action core for path boolean operations. Resolves the current\n * selection into z-ordered paths, runs the chosen op, and dispatches a\n * single batch of `Op`s (delete sources + insert results + set selection).\n */\nimport type { Affine, Path } from '@weasel-js/geom';\nimport type { Op, NodeId, PathPaint } from '@weasel-js/core';\nimport { resolveFill } from '@weasel-js/paint';\nimport { NodeOutlineError, type NodeOutline } from '@weasel-js/core';\nimport { resolveOperand, type BooleanOpOptions, type BooleanOperand } from './operands';\nimport { booleanPieces, type ResultPiece } from './pieces';\nimport { commitPieces } from './commit';\n\ndeclare module '@weasel-js/routing' {\n interface DepSchema {\n /** What the Pathfinder actions and the shape builder read and mint paths through. `presets.booleans` publishes\n * one over the canvas's path leaves; a consumer replaces it with `useBooleansAdapter`. */\n booleansAdapter?: BooleansAdapter;\n }\n}\n\n/** Boolean op identifiers: the five Pathfinder primaries, and Crop, Trim, and Merge. */\nexport type BooleanOp = 'union' | 'intersect' | 'subtract' | 'exclude' | 'divide' | 'crop' | 'trim' | 'merge';\n\n/**\n * z-position descriptor for a path node. `parentId` is the direct parent\n * (or `null` for a top-level node); `index` is the position within that\n * parent's child order — never a global render index.\n */\n/** @internal */\nexport interface BooleanZOrder {\n parentId: string | null;\n index: number;\n}\n\n/** Adapter the hook and the pure core both consume. */\nexport interface BooleansAdapter {\n getSelection(): readonly NodeId[] | readonly string[];\n getWorldPath(id: NodeId): Path | undefined;\n /**\n * Optional: the outline of the node behind `id`, for an id `getWorldPath`\n * has no path for — `sceneNodeOutline`, which asks the node's painter. It\n * becomes the operand, so text, whose outline is its glyphs, can be cut,\n * united or intersected like any shape.\n */\n getOutline?(id: NodeId): NodeOutline | undefined;\n /**\n * Optional: the paint the path node behind `id` wears. An operation told to\n * count strokes (`BooleanOpOptions.strokes`) reads it to learn whether the\n * node is stroked and whether it is filled; without it every operand is its\n * path alone.\n */\n getPaint?(id: NodeId): PathPaint | undefined;\n /**\n * Optional: the frame the node behind `id` draws its stroke in, as the\n * matrix taking that frame to world (`poseFrameOf`); null or absent for a\n * node drawn straight. A counted world-width stroke is skewed and stretched\n * with it. Without it every stroke is outlined in world.\n */\n getStrokeFrame?(id: NodeId): Affine | null | undefined;\n compareZ(a: NodeId, b: NodeId): number;\n /**\n * Mint a new node from a boolean-op result `Path`. `producedBy` names the\n * op that synthesized it — adapters that store provenance (e.g. for a\n * layer-panel icon) record it; others ignore the arg. `sourceId` is the\n * source the result stands in for: the topmost, except that each piece of\n * a Divide, Crop, Trim, or Merge names the topmost source it was cut from. Give the\n * node that source's parent, or the kit's reorder cannot find it there.\n * `paint` is passed when that source's stroke went into the geometry, and\n * the node must wear it as given: wearing the source's stroke again would\n * draw it twice. Without `paint`, give it that source's paint. The kit never\n * reads a node's `data`: anything else the result should keep of its source,\n * a name say, is the adapter's to copy from `sourceId`.\n */\n createPathNode(path: Path, producedBy: BooleanOp, sourceId: NodeId, paint?: PathPaint): { id: string };\n /**\n * The full object for an id. The delete ops capture it, so their `invert`\n * (an insert) restores the complete object on undo.\n */\n getNode(id: NodeId): { id: string } | undefined | null;\n /**\n * The tree. The kit reads each source's slot among its siblings through\n * `getParent` and `getChildren`, and moves each result into the slot of\n * the topmost source in its own source's parent through `setChildOrder`.\n * `defaultCommitAdapter` supplies all three, and `getNode`.\n */\n getParent(id: string): string | null;\n getChildren(parentId: string | null): string[];\n setChildOrder(parentId: string | null, ids: string[]): void;\n applyOps?(ops: Op[], label?: string): void;\n setSelection?(ids: NodeId[]): void;\n insertNode?(node: { id: string }): void;\n removeNode?(id: string): void;\n}\n\n/** Outcome reported back to callers (lets the hook surface no-op signals). */\nexport type BooleanOpResult =\n | { kind: 'applied'; resultIds: string[] }\n | { kind: 'noop'; reason: 'no-paths' | 'too-few-for-subtract' | 'empty-result' }\n /** An operand's outline could not be built. Nothing was changed: an op that\n * quietly dropped the operand would commit a different shape than asked. */\n | { kind: 'failed'; reason: 'outlines'; error: NodeOutlineError };\n\nconst LABEL: Record<BooleanOp, string> = {\n union: 'Union',\n intersect: 'Intersect',\n subtract: 'Subtract',\n exclude: 'Exclude',\n divide: 'Divide',\n crop: 'Crop',\n trim: 'Trim',\n merge: 'Merge',\n};\n\n/** One path a Boolean operation would make. */\nexport interface BooleanPreviewPiece {\n path: Path;\n /** The source the piece stands in for; see `BooleansAdapter.createPathNode`. */\n sourceId: NodeId;\n /** Set when that source's stroke went into `path`: the paint the piece wears. */\n paint?: PathPaint;\n}\n\n/** What {@link previewBooleanOp} answers: the pieces, or why there are none. */\nexport type BooleanOpPreview =\n | { kind: 'pieces'; pieces: BooleanPreviewPiece[] }\n | Exclude<BooleanOpResult, { kind: 'applied' }>;\n\n/** @internal A selected node and the operand it gives. */\nexport type BooleanEntry = { id: NodeId; operand: BooleanOperand };\ntype Entry = BooleanEntry;\n\n/** @internal The operands behind `sel`, back to front, or the result that\n * says why there are too few. Reads the adapter and changes nothing. */\nexport function resolveEntries(\n adapter: BooleansAdapter,\n sel: readonly NodeId[],\n op: BooleanOp,\n opts: BooleanOpOptions,\n): Entry[] | Exclude<BooleanOpResult, { kind: 'applied' }> {\n // Sorted ascending by `compareZ` so the first entry is the bottommost\n // (back) member. `subtract` relies on this: it computes `back − union(rest)`.\n let resolved: { id: NodeId; operand: BooleanOperand | undefined }[];\n try {\n resolved = sel.map((id) => ({ id, operand: resolveOperand(adapter, id, opts) }));\n } catch (err) {\n if (err instanceof NodeOutlineError) return { kind: 'failed', reason: 'outlines', error: err };\n throw err;\n }\n const entries = resolved\n .filter((e): e is Entry => e.operand != null)\n .sort((a, b) => adapter.compareZ(a.id, b.id));\n\n if (entries.length === 0) return { kind: 'noop', reason: 'no-paths' };\n if (op === 'subtract' && entries.length < 2) {\n return { kind: 'noop', reason: 'too-few-for-subtract' };\n }\n if (entries.length < 2) return { kind: 'noop', reason: 'no-paths' };\n return entries;\n}\n\n/** How many of `sel` give an operand, read without outlining a stroke: what the Pathfinder actions'\n * `enabled` counts. An outline that cannot be built yet counts, so a run can say why it stopped. */\nexport function countOperands(adapter: BooleansAdapter, sel: readonly NodeId[]): number {\n let n = 0;\n for (const id of sel) {\n try {\n if (resolveOperand(adapter, id, { strokes: 'ignore' })) n++;\n } catch (err) {\n if (!(err instanceof NodeOutlineError)) throw err;\n n++;\n }\n }\n return n;\n}\n\n/** The operands back to front and the pieces `op` makes of them, or the\n * result that says why it makes none. Reads the adapter and changes nothing. */\nfunction planBooleanOp(\n adapter: BooleansAdapter,\n sel: readonly NodeId[],\n op: BooleanOp,\n opts: BooleanOpOptions,\n): { entries: Entry[]; pieces: ResultPiece[] } | Exclude<BooleanOpResult, { kind: 'applied' }> {\n const entries = resolveEntries(adapter, sel, op, opts);\n if ('kind' in entries) return entries;\n // Merge unites the operands that wear one fill; one whose paint is unknown is united with nothing.\n const fillKey = (i: number): unknown => {\n const { id, operand } = entries[i]!;\n const paint = operand.paint ?? adapter.getPaint?.(id);\n return paint ? JSON.stringify(resolveFill(paint.fill)) : i;\n };\n const pieces = booleanPieces(op, entries.map((e) => e.operand.path), fillKey);\n if (pieces.length === 0) return { kind: 'noop', reason: 'empty-result' };\n return { entries, pieces };\n}\n\n/**\n * What {@link applyBooleanOp} would make of the selection, without minting a\n * node or committing anything: for drawing an operation before it is applied.\n */\nexport function previewBooleanOp(\n adapter: BooleansAdapter,\n op: BooleanOp,\n opts: BooleanOpOptions = {},\n): BooleanOpPreview {\n const plan = planBooleanOp(adapter, [...adapter.getSelection()] as NodeId[], op, opts);\n if ('kind' in plan) return plan;\n return {\n kind: 'pieces',\n pieces: plan.pieces.map((piece) => {\n const { id, operand } = plan.entries[piece.source]!;\n return operand.paint ? { path: piece.path, sourceId: id, paint: operand.paint } : { path: piece.path, sourceId: id };\n }),\n };\n}\n\n/**\n * Run one Boolean operation over the selected paths and commit the result as a\n * single undoable batch.\n *\n * Operands are ordered back-to-front, which is what makes `subtract` mean\n * \"everything in front removed from the backmost shape\". Returns without\n * mutating anything when the selection holds no paths, or too few for the\n * requested operation. `opts.strokes` says what a stroked operand gives.\n */\nexport function applyBooleanOp(\n adapter: BooleansAdapter,\n op: BooleanOp,\n opts: BooleanOpOptions = {},\n): BooleanOpResult {\n const sel = [...adapter.getSelection()] as NodeId[];\n const plan = planBooleanOp(adapter, sel, op, opts);\n if ('kind' in plan) return plan;\n const { entries, pieces } = plan;\n const made = pieces.map((piece) => ({ path: piece.path, source: piece.source, producedBy: op }));\n return { kind: 'applied', resultIds: commitPieces(adapter, sel, entries, made, LABEL[op]) };\n}\n"],"mappings":";;;;;;;AAuGA,IAAM,QAAmC;CACvC,OAAO;CACP,WAAW;CACX,UAAU;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,MAAM;CACN,OAAO;AACT;;;AAsBA,SAAgB,eACd,SACA,KACA,IACA,MACyD;CAGzD,IAAI;CACJ,IAAI;EACF,WAAW,IAAI,KAAK,QAAQ;GAAE;GAAI,SAAS,eAAe,SAAS,IAAI,IAAI;EAAE,EAAE;CACjF,SAAS,KAAK;EACZ,IAAI,eAA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AM,OAAO,cAAc,SAAS,CAAC,GAAG,QAAQ,aAAa,CAAC,GAAe,IAAI,IAAI;CACrF,IAAI,UAAU,MAAM,OAAO;CAC3B,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,OAAO,KAAK,UAAU;GACjC,MAAM,EAAE,IAAI,YAAY,KAAK,QAAQ,MAAM;GAC3C,OAAO,QAAQ,QAAQ;IAAE,MAAM,MAAM;IAAM,UAAU;IAAI,OAAO,QAAQ;GAAM,IAAI;IAAE,MAAM,MAAM;IAAM,UAAU;GAAG;EACrH,CAAC;CACH;AACF;;;;;;;;;;AAWA,SAAgB,eACd,SACA,IACA,OAAyB,CAAC,GACT;CACjB,MAAM,MAAM,CAAC,GAAG,QAAQ,aAAa,CAAC;CACtC,MAAM,OAAO,cAAc,SAAS,KAAK,IAAI,IAAI;CACjD,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,EAAE,SAAS,WAAW;CAC5B,MAAM,OAAO,OAAO,KAAK,WAAW;EAAE,MAAM,MAAM;EAAM,QAAQ,MAAM;EAAQ,YAAY;CAAG,EAAE;CAC/F,OAAO;EAAE,MAAM;EAAW,WAAW,aAAa,SAAS,KAAK,SAAS,MAAM,MAAM,GAAG;CAAE;AAC5F"}
@@ -0,0 +1,45 @@
1
+ import { placementOps } from "./placement.js";
2
+ import { dispatchApplyBatch, locateChild } from "@weasel-js/core";
3
+ import * as coreOps from "@weasel-js/core/ops";
4
+
5
+ // src/booleans/commit.ts
6
+ /**
7
+ * Replace every entry with `pieces` as one undoable batch, and select what
8
+ * was made. Each piece is minted from its own source, wears the paint a stroke
9
+ * folded into that source left it, and takes its slot. Returns the new ids.
10
+ */
11
+ function commitPieces(adapter, sel, entries, pieces, label) {
12
+ const slots = entries.map((e) => locateChild(adapter, e.id) ?? void 0);
13
+ const made = pieces.map((piece) => {
14
+ const { id, operand } = entries[piece.source];
15
+ return {
16
+ node: adapter.createPathNode(piece.path, piece.producedBy, id, operand.paint),
17
+ slot: slots[piece.source]
18
+ };
19
+ });
20
+ const newNodes = made.map((m) => m.node);
21
+ const ops = [];
22
+ const captured = entries.map((e, i) => ({
23
+ node: adapter.getNode(e.id) ?? { id: e.id },
24
+ index: slots[i]?.index ?? -1
25
+ }));
26
+ captured.sort((a, b) => b.index - a.index);
27
+ for (const { node, index } of captured) ops.push(coreOps.delete({
28
+ node,
29
+ index
30
+ }));
31
+ for (const n of newNodes) ops.push(coreOps.insert({ node: n }));
32
+ ops.push(...placementOps(made.map((m) => ({
33
+ id: m.node.id,
34
+ slot: m.slot
35
+ })), slots));
36
+ ops.push(coreOps.setSelection({
37
+ from: sel,
38
+ to: newNodes.map((n) => n.id)
39
+ }));
40
+ dispatchApplyBatch(adapter, ops, label);
41
+ return newNodes.map((n) => n.id);
42
+ }
43
+
44
+ export { commitPieces };
45
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.js","names":[],"sources":["../../src/booleans/commit.ts"],"sourcesContent":["import type { Path } from '@weasel-js/geom';\nimport { locateChild, dispatchApplyBatch } from '@weasel-js/core';\nimport type { Op, NodeId } from '@weasel-js/core';\nimport type { BooleanEntry, BooleanOp, BooleansAdapter, BooleanZOrder } from './booleans';\nimport { placementOps } from './placement';\nimport * as coreOps from '@weasel-js/core/ops';\n\n/** One path to mint: the index of the source it stands in for, and the op it\n * is recorded as made by. */\nexport interface BooleanCommitPiece {\n path: Path;\n source: number;\n producedBy: BooleanOp;\n}\n\n/**\n * Replace every entry with `pieces` as one undoable batch, and select what\n * was made. Each piece is minted from its own source, wears the paint a stroke\n * folded into that source left it, and takes its slot. Returns the new ids.\n */\nexport function commitPieces(\n adapter: BooleansAdapter,\n sel: readonly NodeId[],\n entries: readonly BooleanEntry[],\n pieces: readonly BooleanCommitPiece[],\n label: string,\n): string[] {\n // Every source's slot, read before the scene is mutated.\n const slots: (BooleanZOrder | undefined)[] =\n entries.map((e) => locateChild(adapter, e.id) ?? undefined);\n const made = pieces.map((piece) => {\n const { id, operand } = entries[piece.source]!;\n return { node: adapter.createPathNode(piece.path, piece.producedBy, id, operand.paint), slot: slots[piece.source] };\n });\n const newNodes = made.map((m) => m.node);\n const ops: Op[] = [];\n // Capture the full node so the delete's `invert()` (an insert) restores\n // every field on undo. The index is -1 for a source its parent does not list.\n const captured = entries.map((e, i) => ({\n node: adapter.getNode(e.id) ?? { id: e.id },\n index: slots[i]?.index ?? -1,\n }));\n // Order by index DESC so reverse-then-invert (history's undo path)\n // re-inserts ASC — each splice lands on a correctly-sized array\n // instead of clamping high indices to a still-growing length.\n captured.sort((a, b) => b.index - a.index);\n for (const { node, index } of captured) ops.push(coreOps.delete({ node, index }));\n for (const n of newNodes) ops.push(coreOps.insert({ node: n }));\n ops.push(...placementOps(made.map((m) => ({ id: m.node.id, slot: m.slot })), slots));\n ops.push(coreOps.setSelection({ from: sel, to: newNodes.map((n) => n.id as NodeId) }));\n dispatchApplyBatch(adapter, ops, label);\n return newNodes.map((n) => n.id);\n}\n"],"mappings":";;;;;;;;;;AAoBA,SAAgB,aACd,SACA,KACA,SACA,QACA,OACU;CAEV,MAAM,QACJ,QAAQ,KAAK,MAAM,YAAY,SAAS,EAAE,EAAE,KAAK,MAAS;CAC5D,MAAM,OAAO,OAAO,KAAK,UAAU;EACjC,MAAM,EAAE,IAAI,YAAY,QAAQ,MAAM;EACtC,OAAO;GAAE,MAAM,QAAQ,eAAe,MAAM,MAAM,MAAM,YAAY,IAAI,QAAQ,KAAK;GAAG,MAAM,MAAM,MAAM;EAAQ;CACpH,CAAC;CACD,MAAM,WAAW,KAAK,KAAK,MAAM,EAAE,IAAI;CACvC,MAAM,MAAY,CAAC;CAGnB,MAAM,WAAW,QAAQ,KAAK,GAAG,OAAO;EACtC,MAAM,QAAQ,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG;EAC1C,OAAO,MAAM,EAAE,EAAE,SAAS;CAC5B,EAAE;CAIF,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;CACzC,KAAK,MAAM,EAAE,MAAM,WAAW,UAAU,IAAI,KAAK,QAAQ,OAAO;EAAE;EAAM;CAAM,CAAC,CAAC;CAChF,KAAK,MAAM,KAAK,UAAU,IAAI,KAAK,QAAQ,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;CAC9D,IAAI,KAAK,GAAG,aAAa,KAAK,KAAK,OAAO;EAAE,IAAI,EAAE,KAAK;EAAI,MAAM,EAAE;CAAK,EAAE,GAAG,KAAK,CAAC;CACnF,IAAI,KAAK,QAAQ,aAAa;EAAE,MAAM;EAAK,IAAI,SAAS,KAAK,MAAM,EAAE,EAAY;CAAE,CAAC,CAAC;CACrF,mBAAmB,SAAS,KAAK,KAAK;CACtC,OAAO,SAAS,KAAK,MAAM,EAAE,EAAE;AACjC"}
@@ -0,0 +1,48 @@
1
+ import { resolveEntries } from "./booleans.js";
2
+ import { commitPieces } from "./commit.js";
3
+
4
+ // src/booleans/custom.ts
5
+ /**
6
+ * The operands the nodes among `ids` (the selection, when not given) give a
7
+ * Boolean operation, back to front, as the built-in operations resolve them;
8
+ * or why there are fewer than two.
9
+ * Reads the adapter and changes nothing.
10
+ */
11
+ function resolveBooleanOperands(adapter, opts = {}, ids) {
12
+ const selection = [...adapter.getSelection()];
13
+ const entries = resolveEntries(adapter, ids ?? selection, "divide", opts);
14
+ if ("kind" in entries) return entries;
15
+ return {
16
+ selection,
17
+ sources: entries.map(({ id, operand: { path, paint } }) => paint ? {
18
+ id,
19
+ path,
20
+ paint
21
+ } : {
22
+ id,
23
+ path
24
+ })
25
+ };
26
+ }
27
+ /**
28
+ * Replace `operands`' sources with `pieces` as one undo step named `label`,
29
+ * and select what was made. Each piece is minted from the source it names, as
30
+ * `BooleansAdapter.createPathNode` says, and stacks in that source's slot. An
31
+ * empty `pieces` deletes every source.
32
+ */
33
+ function commitBooleanPieces(adapter, operands, pieces, label) {
34
+ const entries = operands.sources.map(({ id, path, paint }) => ({
35
+ id,
36
+ operand: paint ? {
37
+ path,
38
+ paint
39
+ } : { path }
40
+ }));
41
+ return {
42
+ kind: "applied",
43
+ resultIds: commitPieces(adapter, operands.selection, entries, pieces, label)
44
+ };
45
+ }
46
+
47
+ export { commitBooleanPieces, resolveBooleanOperands };
48
+ //# sourceMappingURL=custom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.js","names":[],"sources":["../../src/booleans/custom.ts"],"sourcesContent":["/**\n * A Boolean operation of the caller's own over the selection: the operands the\n * kit resolves from it, and the commit that replaces them with the pieces the\n * caller cut from those operands, as one undo step.\n */\nimport type { Path } from '@weasel-js/geom';\nimport type { PathPaint, NodeId } from '@weasel-js/core';\nimport { resolveEntries, type BooleanEntry, type BooleanOpResult, type BooleansAdapter } from './booleans';\nimport { commitPieces, type BooleanCommitPiece } from './commit';\nimport type { BooleanOpOptions } from './operands';\n\n/** One selected node's operand. */\nexport interface BooleanSource {\n id: NodeId;\n /** In world: its path, its glyph outlines, or the region its ink covers\n * once a stroke is counted. */\n path: Path;\n /** Set when a stroke went into `path`: what a piece standing in for this\n * source wears. */\n paint?: PathPaint;\n}\n\n/** What {@link resolveBooleanOperands} answers. */\nexport interface BooleanOperands {\n /** The selection the operands were read from. */\n selection: readonly NodeId[];\n /** Back to front. */\n sources: readonly BooleanSource[];\n}\n\n/**\n * The operands the nodes among `ids` (the selection, when not given) give a\n * Boolean operation, back to front, as the built-in operations resolve them;\n * or why there are fewer than two.\n * Reads the adapter and changes nothing.\n */\nexport function resolveBooleanOperands(\n adapter: BooleansAdapter,\n opts: BooleanOpOptions = {},\n ids?: readonly NodeId[],\n): BooleanOperands | Exclude<BooleanOpResult, { kind: 'applied' }> {\n const selection = [...adapter.getSelection()] as NodeId[];\n const entries = resolveEntries(adapter, ids ?? selection, 'divide', opts);\n if ('kind' in entries) return entries;\n return {\n selection,\n sources: entries.map(({ id, operand: { path, paint } }) => (paint ? { id, path, paint } : { id, path })),\n };\n}\n\n/**\n * Replace `operands`' sources with `pieces` as one undo step named `label`,\n * and select what was made. Each piece is minted from the source it names, as\n * `BooleansAdapter.createPathNode` says, and stacks in that source's slot. An\n * empty `pieces` deletes every source.\n */\nexport function commitBooleanPieces(\n adapter: BooleansAdapter,\n operands: BooleanOperands,\n pieces: readonly BooleanCommitPiece[],\n label: string,\n): Extract<BooleanOpResult, { kind: 'applied' }> {\n const entries = operands.sources.map(({ id, path, paint }): BooleanEntry => ({\n id,\n operand: paint ? { path, paint } : { path },\n }));\n return { kind: 'applied', resultIds: commitPieces(adapter, operands.selection, entries, pieces, label) };\n}\n\nexport type { BooleanCommitPiece };\n"],"mappings":";;;;;;;;;;AAoCA,SAAgB,uBACd,SACA,OAAyB,CAAC,GAC1B,KACiE;CACjE,MAAM,YAAY,CAAC,GAAG,QAAQ,aAAa,CAAC;CAC5C,MAAM,UAAU,eAAe,SAAS,OAAO,WAAW,UAAU,IAAI;CACxE,IAAI,UAAU,SAAS,OAAO;CAC9B,OAAO;EACL;EACA,SAAS,QAAQ,KAAK,EAAE,IAAI,SAAS,EAAE,MAAM,cAAe,QAAQ;GAAE;GAAI;GAAM;EAAM,IAAI;GAAE;GAAI;EAAK,CAAE;CACzG;AACF;;;;;;;AAQA,SAAgB,oBACd,SACA,UACA,QACA,OAC+C;CAC/C,MAAM,UAAU,SAAS,QAAQ,KAAK,EAAE,IAAI,MAAM,aAA2B;EAC3E;EACA,SAAS,QAAQ;GAAE;GAAM;EAAM,IAAI,EAAE,KAAK;CAC5C,EAAE;CACF,OAAO;EAAE,MAAM;EAAW,WAAW,aAAa,SAAS,SAAS,WAAW,SAAS,QAAQ,KAAK;CAAE;AACzG"}