@weasel-js/editing 1.19.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/README.md +23 -11
  2. package/dist/actionGroups.js +27 -0
  3. package/dist/actionGroups.js.map +1 -0
  4. package/dist/actions/align/action.js +12 -9
  5. package/dist/actions/align/action.js.map +1 -1
  6. package/dist/actions/align/align.js +5 -4
  7. package/dist/actions/align/align.js.map +1 -1
  8. package/dist/actions/clipboard/action.js +10 -7
  9. package/dist/actions/clipboard/action.js.map +1 -1
  10. package/dist/actions/clone/action.js +217 -0
  11. package/dist/actions/clone/action.js.map +1 -0
  12. package/dist/actions/clone/behaviors.js +65 -0
  13. package/dist/actions/clone/behaviors.js.map +1 -0
  14. package/dist/actions/delete/delete.js +123 -0
  15. package/dist/actions/delete/delete.js.map +1 -0
  16. package/dist/actions/derivedBox.js +16 -0
  17. package/dist/actions/derivedBox.js.map +1 -0
  18. package/dist/actions/distribute/action.js +6 -3
  19. package/dist/actions/distribute/action.js.map +1 -1
  20. package/dist/actions/distribute/distribute.js +3 -2
  21. package/dist/actions/distribute/distribute.js.map +1 -1
  22. package/dist/actions/distribute/plan.js.map +1 -1
  23. package/dist/actions/edit/createPaintAction.js +42 -13
  24. package/dist/actions/edit/createPaintAction.js.map +1 -1
  25. package/dist/actions/edit/{escape.js → deselect.js} +8 -8
  26. package/dist/actions/edit/deselect.js.map +1 -0
  27. package/dist/actions/edit/duplicate.js +9 -7
  28. package/dist/actions/edit/duplicate.js.map +1 -1
  29. package/dist/actions/edit/group.js +24 -20
  30. package/dist/actions/edit/group.js.map +1 -1
  31. package/dist/actions/edit/ingest.js +4 -2
  32. package/dist/actions/edit/ingest.js.map +1 -1
  33. package/dist/actions/edit/nudge.js +14 -10
  34. package/dist/actions/edit/nudge.js.map +1 -1
  35. package/dist/actions/edit/selectAll.js +1 -1
  36. package/dist/actions/edit/setFill.js +1 -1
  37. package/dist/actions/edit/setFill.js.map +1 -1
  38. package/dist/actions/edit/setFillOpacity.js +5 -5
  39. package/dist/actions/edit/setFillOpacity.js.map +1 -1
  40. package/dist/actions/edit/setStroke.js +1 -1
  41. package/dist/actions/edit/setStroke.js.map +1 -1
  42. package/dist/actions/edit/setStrokeOpacity.js +6 -6
  43. package/dist/actions/edit/setStrokeOpacity.js.map +1 -1
  44. package/dist/actions/edit/setStrokeWidth.js +13 -8
  45. package/dist/actions/edit/setStrokeWidth.js.map +1 -1
  46. package/dist/actions/edit/setVertexColor.js +13 -6
  47. package/dist/actions/edit/setVertexColor.js.map +1 -1
  48. package/dist/actions/flip/action.js +19 -14
  49. package/dist/actions/flip/action.js.map +1 -1
  50. package/dist/actions/flip/helpers.js.map +1 -1
  51. package/dist/actions/group/enterGroup.js +81 -0
  52. package/dist/actions/group/enterGroup.js.map +1 -0
  53. package/dist/actions/insert/action.js +152 -0
  54. package/dist/actions/insert/action.js.map +1 -0
  55. package/dist/actions/insert/commit.js +52 -0
  56. package/dist/actions/insert/commit.js.map +1 -0
  57. package/dist/actions/insert/extras.js +88 -0
  58. package/dist/actions/insert/extras.js.map +1 -0
  59. package/dist/actions/insert/frame.js +96 -0
  60. package/dist/actions/insert/frame.js.map +1 -0
  61. package/dist/actions/insert/geometry.js +35 -0
  62. package/dist/actions/insert/geometry.js.map +1 -0
  63. package/dist/actions/insert/lands.js +41 -0
  64. package/dist/actions/insert/lands.js.map +1 -0
  65. package/dist/actions/insert/params.js +42 -0
  66. package/dist/actions/insert/params.js.map +1 -0
  67. package/dist/actions/insert/placeAction.js +137 -0
  68. package/dist/actions/insert/placeAction.js.map +1 -0
  69. package/dist/actions/insert/repositionAction.js +47 -0
  70. package/dist/actions/insert/repositionAction.js.map +1 -0
  71. package/dist/actions/insert/rotateAction.js +34 -0
  72. package/dist/actions/insert/rotateAction.js.map +1 -0
  73. package/dist/actions/insert/session.js +99 -0
  74. package/dist/actions/insert/session.js.map +1 -0
  75. package/dist/actions/insert/shape.js +117 -0
  76. package/dist/actions/insert/shape.js.map +1 -0
  77. package/dist/actions/insert/style.js +23 -0
  78. package/dist/actions/insert/style.js.map +1 -0
  79. package/dist/actions/lassoSelect/action.js +201 -0
  80. package/dist/actions/lassoSelect/action.js.map +1 -0
  81. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
  82. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
  83. package/dist/actions/lockedWrites.js +20 -0
  84. package/dist/actions/lockedWrites.js.map +1 -0
  85. package/dist/actions/move/action.js +138 -0
  86. package/dist/actions/move/action.js.map +1 -0
  87. package/dist/actions/move/behaviors/clampMove.js +42 -0
  88. package/dist/actions/move/behaviors/clampMove.js.map +1 -0
  89. package/dist/actions/move/behaviors/layoutDrop.js +84 -0
  90. package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
  91. package/dist/actions/move/behaviors/pageDrop.js +30 -0
  92. package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
  93. package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
  94. package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
  95. package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
  96. package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
  97. package/dist/actions/move/behaviors/snapToContainer.js +214 -0
  98. package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
  99. package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
  100. package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
  101. package/dist/actions/move/capture.js +116 -0
  102. package/dist/actions/move/capture.js.map +1 -0
  103. package/dist/actions/move/commit/index.js +47 -0
  104. package/dist/actions/move/commit/index.js.map +1 -0
  105. package/dist/actions/move/commit/layoutDrop.js +68 -0
  106. package/dist/actions/move/commit/layoutDrop.js.map +1 -0
  107. package/dist/actions/move/commit/layoutRelease.js +146 -0
  108. package/dist/actions/move/commit/layoutRelease.js.map +1 -0
  109. package/dist/actions/move/commit/pageDrop.js +162 -0
  110. package/dist/actions/move/commit/pageDrop.js.map +1 -0
  111. package/dist/actions/move/commit/rebase.js +24 -0
  112. package/dist/actions/move/commit/rebase.js.map +1 -0
  113. package/dist/actions/move/commit/reparent.js +157 -0
  114. package/dist/actions/move/commit/reparent.js.map +1 -0
  115. package/dist/actions/move/delta.js +127 -0
  116. package/dist/actions/move/delta.js.map +1 -0
  117. package/dist/actions/move/dragSnap.js +55 -0
  118. package/dist/actions/move/dragSnap.js.map +1 -0
  119. package/dist/actions/move/frame.js +67 -0
  120. package/dist/actions/move/frame.js.map +1 -0
  121. package/dist/actions/move/gestureAdapter.js +36 -0
  122. package/dist/actions/move/gestureAdapter.js.map +1 -0
  123. package/dist/actions/move/landedDescendants.js +50 -0
  124. package/dist/actions/move/landedDescendants.js.map +1 -0
  125. package/dist/actions/move/layout/container.js +119 -0
  126. package/dist/actions/move/layout/container.js.map +1 -0
  127. package/dist/actions/move/layout/dragged.js +75 -0
  128. package/dist/actions/move/layout/dragged.js.map +1 -0
  129. package/dist/actions/move/layout/dropPass.js +205 -0
  130. package/dist/actions/move/layout/dropPass.js.map +1 -0
  131. package/dist/actions/move/layout/exits.js +62 -0
  132. package/dist/actions/move/layout/exits.js.map +1 -0
  133. package/dist/actions/move/layout/glide.js +70 -0
  134. package/dist/actions/move/layout/glide.js.map +1 -0
  135. package/dist/actions/move/layout/view.js +60 -0
  136. package/dist/actions/move/layout/view.js.map +1 -0
  137. package/dist/actions/move/refusal.js +49 -0
  138. package/dist/actions/move/refusal.js.map +1 -0
  139. package/dist/actions/move/session.js +105 -0
  140. package/dist/actions/move/session.js.map +1 -0
  141. package/dist/actions/move/sessionOf.js +27 -0
  142. package/dist/actions/move/sessionOf.js.map +1 -0
  143. package/dist/actions/move/translate.js +49 -0
  144. package/dist/actions/move/translate.js.map +1 -0
  145. package/dist/actions/pathfinder/action.js +8 -6
  146. package/dist/actions/pathfinder/action.js.map +1 -1
  147. package/dist/actions/pathfinder/booleanGroupAction.js +16 -10
  148. package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -1
  149. package/dist/actions/pathfinder/keymap.js +2 -2
  150. package/dist/actions/pathfinder/keymap.js.map +1 -1
  151. package/dist/actions/reorder/reorder.js +13 -11
  152. package/dist/actions/reorder/reorder.js.map +1 -1
  153. package/dist/actions/resize/action.js +105 -0
  154. package/dist/actions/resize/action.js.map +1 -0
  155. package/dist/actions/resize/aspect.js +42 -0
  156. package/dist/actions/resize/aspect.js.map +1 -0
  157. package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
  158. package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
  159. package/dist/actions/resize/boxFrame.js +19 -0
  160. package/dist/actions/resize/boxFrame.js.map +1 -0
  161. package/dist/actions/resize/capture.js +121 -0
  162. package/dist/actions/resize/capture.js.map +1 -0
  163. package/dist/actions/resize/commit.js +104 -0
  164. package/dist/actions/resize/commit.js.map +1 -0
  165. package/dist/actions/resize/frame.js +171 -0
  166. package/dist/actions/resize/frame.js.map +1 -0
  167. package/dist/actions/resize/held.js +44 -0
  168. package/dist/actions/resize/held.js.map +1 -0
  169. package/dist/actions/resize/minimum.js +34 -0
  170. package/dist/actions/resize/minimum.js.map +1 -0
  171. package/dist/actions/resize/replay.js +58 -0
  172. package/dist/actions/resize/replay.js.map +1 -0
  173. package/dist/actions/resize/ruleBounds.js +11 -0
  174. package/dist/actions/resize/ruleBounds.js.map +1 -0
  175. package/dist/actions/resize/session.js +118 -0
  176. package/dist/actions/resize/session.js.map +1 -0
  177. package/dist/actions/rotate/action.js +99 -0
  178. package/dist/actions/rotate/action.js.map +1 -0
  179. package/dist/actions/rotate/commit.js +48 -0
  180. package/dist/actions/rotate/commit.js.map +1 -0
  181. package/dist/actions/rotate/frame.js +96 -0
  182. package/dist/actions/rotate/frame.js.map +1 -0
  183. package/dist/actions/rotate/replay.js +25 -0
  184. package/dist/actions/rotate/replay.js.map +1 -0
  185. package/dist/actions/rotate/session.js +135 -0
  186. package/dist/actions/rotate/session.js.map +1 -0
  187. package/dist/actions/select/areaSelect.js +83 -0
  188. package/dist/actions/select/areaSelect.js.map +1 -0
  189. package/dist/actions/select/clearSelection.js +33 -0
  190. package/dist/actions/select/clearSelection.js.map +1 -0
  191. package/dist/actions/swap/action.js +63 -0
  192. package/dist/actions/swap/action.js.map +1 -0
  193. package/dist/actions/swap/swapOps.js +160 -0
  194. package/dist/actions/swap/swapOps.js.map +1 -0
  195. package/dist/actions/transformAgain/action.js +16 -14
  196. package/dist/actions/transformAgain/action.js.map +1 -1
  197. package/dist/actions/transformAgain/transformSelection.js +19 -5
  198. package/dist/actions/transformAgain/transformSelection.js.map +1 -1
  199. package/dist/booleans/booleans.js +130 -0
  200. package/dist/booleans/booleans.js.map +1 -0
  201. package/dist/booleans/commit.js +45 -0
  202. package/dist/booleans/commit.js.map +1 -0
  203. package/dist/booleans/custom.js +48 -0
  204. package/dist/booleans/custom.js.map +1 -0
  205. package/dist/booleans/operands.js +50 -0
  206. package/dist/booleans/operands.js.map +1 -0
  207. package/dist/booleans/pieces.js +43 -0
  208. package/dist/booleans/pieces.js.map +1 -0
  209. package/dist/booleans/placement.js +37 -0
  210. package/dist/booleans/placement.js.map +1 -0
  211. package/dist/booleans/useBooleans.js +34 -0
  212. package/dist/booleans/useBooleans.js.map +1 -0
  213. package/dist/booleans/useBooleansAdapter.js +11 -0
  214. package/dist/booleans/useBooleansAdapter.js.map +1 -0
  215. package/dist/chrome/affordances/cornerResize.js +123 -0
  216. package/dist/chrome/affordances/cornerResize.js.map +1 -0
  217. package/dist/chrome/affordances/rotateCursor.js +17 -0
  218. package/dist/chrome/affordances/rotateCursor.js.map +1 -0
  219. package/dist/chrome/affordances/rotationHandle.js +117 -0
  220. package/dist/chrome/affordances/rotationHandle.js.map +1 -0
  221. package/dist/chrome/handleCommands.js +110 -0
  222. package/dist/chrome/handleCommands.js.map +1 -0
  223. package/dist/chrome/overlay.js +271 -0
  224. package/dist/chrome/overlay.js.map +1 -0
  225. package/dist/chrome/rotationBadge.js +132 -0
  226. package/dist/chrome/rotationBadge.js.map +1 -0
  227. package/dist/chrome/rotationHandleGeometry.js +49 -0
  228. package/dist/chrome/rotationHandleGeometry.js.map +1 -0
  229. package/dist/chrome/selectionChrome.js +25 -0
  230. package/dist/chrome/selectionChrome.js.map +1 -0
  231. package/dist/chrome/selectionPose.js +112 -0
  232. package/dist/chrome/selectionPose.js.map +1 -0
  233. package/dist/chrome/shapeOutline.js +137 -0
  234. package/dist/chrome/shapeOutline.js.map +1 -0
  235. package/dist/clipboard/clipboardOps.js +48 -0
  236. package/dist/clipboard/clipboardOps.js.map +1 -0
  237. package/dist/clipboard/materializePaste.js +34 -0
  238. package/dist/clipboard/materializePaste.js.map +1 -0
  239. package/dist/clipboard/osClipboard.js +67 -0
  240. package/dist/clipboard/osClipboard.js.map +1 -0
  241. package/dist/clipboard/useClipboard.js +64 -0
  242. package/dist/clipboard/useClipboard.js.map +1 -0
  243. package/dist/clipboard/wireFormat.js +108 -0
  244. package/dist/clipboard/wireFormat.js.map +1 -0
  245. package/dist/deps/areaSelect.js +42 -0
  246. package/dist/deps/areaSelect.js.map +1 -0
  247. package/dist/deps/booleans.js +99 -0
  248. package/dist/deps/booleans.js.map +1 -0
  249. package/dist/deps/insert.js +260 -0
  250. package/dist/deps/insert.js.map +1 -0
  251. package/dist/deps/lassoSelect.js +37 -0
  252. package/dist/deps/lassoSelect.js.map +1 -0
  253. package/dist/deps/presetDeps.js +40 -0
  254. package/dist/deps/presetDeps.js.map +1 -0
  255. package/dist/deps/resizePolicy.js +41 -0
  256. package/dist/deps/resizePolicy.js.map +1 -0
  257. package/dist/engine-BV9RDHOL.d.ts +339 -0
  258. package/dist/engine.d.ts +6 -0
  259. package/dist/engine.js +10 -0
  260. package/dist/engineStandardActions.js +16 -7
  261. package/dist/engineStandardActions.js.map +1 -1
  262. package/dist/groups.d.ts +27 -0
  263. package/dist/groups.js +4 -0
  264. package/dist/icons.gen.js +8 -0
  265. package/dist/icons.gen.js.map +1 -0
  266. package/dist/icons.table.d.ts +6 -0
  267. package/dist/icons.table.js +8 -0
  268. package/dist/icons.table.js.map +1 -0
  269. package/dist/icons.table.json +156 -0
  270. package/dist/icons2.table.js +163 -0
  271. package/dist/icons2.table.js.map +1 -0
  272. package/dist/index.d.ts +1293 -105
  273. package/dist/index.js +61 -12
  274. package/dist/ingest/ghost.js +58 -0
  275. package/dist/ingest/ghost.js.map +1 -0
  276. package/dist/ingest/imageHandler.js +80 -0
  277. package/dist/ingest/imageHandler.js.map +1 -0
  278. package/dist/ingest/kitHandlers.js +15 -0
  279. package/dist/ingest/kitHandlers.js.map +1 -0
  280. package/dist/ingest/svgHandler.js +97 -0
  281. package/dist/ingest/svgHandler.js.map +1 -0
  282. package/dist/ingest/weaselJsonHandler.js +68 -0
  283. package/dist/ingest/weaselJsonHandler.js.map +1 -0
  284. package/dist/namedPresets.js +23 -11
  285. package/dist/namedPresets.js.map +1 -1
  286. package/dist/presets/arrange.js +21 -7
  287. package/dist/presets/arrange.js.map +1 -1
  288. package/dist/presets/booleans.js +13 -0
  289. package/dist/presets/booleans.js.map +1 -0
  290. package/dist/presets/composites.js +8 -5
  291. package/dist/presets/composites.js.map +1 -1
  292. package/dist/presets/edit.js +25 -13
  293. package/dist/presets/edit.js.map +1 -1
  294. package/dist/presets/ingest.js +7 -3
  295. package/dist/presets/ingest.js.map +1 -1
  296. package/dist/presets/insert.js +28 -0
  297. package/dist/presets/insert.js.map +1 -0
  298. package/dist/presets/pathfinder.js +5 -2
  299. package/dist/presets/pathfinder.js.map +1 -1
  300. package/dist/presets/select.js +16 -3
  301. package/dist/presets/select.js.map +1 -1
  302. package/dist/presets/selection.js +13 -0
  303. package/dist/presets/selection.js.map +1 -0
  304. package/dist/presets/selectionChrome.js +15 -0
  305. package/dist/presets/selectionChrome.js.map +1 -0
  306. package/dist/presets/tools.js +78 -9
  307. package/dist/presets/tools.js.map +1 -1
  308. package/dist/presets/transform.js +20 -7
  309. package/dist/presets/transform.js.map +1 -1
  310. package/dist/presets.d.ts +104 -0
  311. package/dist/presets.js +15 -0
  312. package/dist/selection/useSelection.js +127 -0
  313. package/dist/selection/useSelection.js.map +1 -0
  314. package/dist/test-seams.d.ts +50 -0
  315. package/dist/test-seams.js +4 -0
  316. package/dist/tools/ellipse/useEllipseTool.js +72 -0
  317. package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
  318. package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
  319. package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
  320. package/dist/tools/image/useImageTool.js +57 -0
  321. package/dist/tools/image/useImageTool.js.map +1 -0
  322. package/dist/tools/lasso/useLassoTool.js +96 -0
  323. package/dist/tools/lasso/useLassoTool.js.map +1 -0
  324. package/dist/tools/line/useLineTool.js +67 -0
  325. package/dist/tools/line/useLineTool.js.map +1 -0
  326. package/dist/tools/polygon/usePolygonTool.js +149 -0
  327. package/dist/tools/polygon/usePolygonTool.js.map +1 -0
  328. package/dist/tools/rect/useRectTool.js +74 -0
  329. package/dist/tools/rect/useRectTool.js.map +1 -0
  330. package/dist/tools/select/adapterPointQuery.js +56 -0
  331. package/dist/tools/select/adapterPointQuery.js.map +1 -0
  332. package/dist/tools/select/collapseDeferred.js +35 -0
  333. package/dist/tools/select/collapseDeferred.js.map +1 -0
  334. package/dist/tools/select/extendPressLocked.js +17 -0
  335. package/dist/tools/select/extendPressLocked.js.map +1 -0
  336. package/dist/tools/select/groupEntry.js +73 -0
  337. package/dist/tools/select/groupEntry.js.map +1 -0
  338. package/dist/tools/select/pressDecision.js +39 -0
  339. package/dist/tools/select/pressDecision.js.map +1 -0
  340. package/dist/tools/select/selectDeep.js +39 -0
  341. package/dist/tools/select/selectDeep.js.map +1 -0
  342. package/dist/tools/select/selectPick.js +60 -0
  343. package/dist/tools/select/selectPick.js.map +1 -0
  344. package/dist/tools/select/selectionContributions.js +191 -0
  345. package/dist/tools/select/selectionContributions.js.map +1 -0
  346. package/dist/tools/select/usePickerSelectTool.js +145 -0
  347. package/dist/tools/select/usePickerSelectTool.js.map +1 -0
  348. package/dist/tools/select/useSelectTool.js +54 -0
  349. package/dist/tools/select/useSelectTool.js.map +1 -0
  350. package/dist/tools/shared/countOption.js +24 -0
  351. package/dist/tools/shared/countOption.js.map +1 -0
  352. package/dist/tools/shared/insertToolOptions.js +8 -0
  353. package/dist/tools/shared/insertToolOptions.js.map +1 -0
  354. package/dist/tools/shared/pointerFollower.js +23 -0
  355. package/dist/tools/shared/pointerFollower.js.map +1 -0
  356. package/dist/tools/shared/styleOptions.js +76 -0
  357. package/dist/tools/shared/styleOptions.js.map +1 -0
  358. package/dist/tools/star/useStarTool.js +149 -0
  359. package/dist/tools/star/useStarTool.js.map +1 -0
  360. package/dist/tools/toolSets.js +26 -0
  361. package/dist/tools/toolSets.js.map +1 -0
  362. package/package.json +39 -11
  363. package/dist/actions/edit/escape.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ import { decodeSnapshot, dwarn, snapshotReplacer } from "@weasel-js/core";
2
+
3
+ // src/clipboard/wireFormat.ts
4
+ /** MIME type the kit writes its full-fidelity clipboard payload under, so a
5
+ * copy/paste between two weasel canvases round-trips scene nodes rather than
6
+ * the SVG or text flavors other apps read. */
7
+ var WEASEL_CLIPBOARD_MIME = "application/x-weasel-clipboard+json";
8
+ /** Chromium's async-clipboard spelling for custom formats. */
9
+ var WEASEL_CLIPBOARD_MIME_WEB = `web ${WEASEL_CLIPBOARD_MIME}`;
10
+ /** Serialize snapshot items into the versioned wire text.
11
+ *
12
+ * JSON drops a function-valued field (a container's `clipFromPose`, a
13
+ * node's `derivePath`). A scene adapter's snapshot also carries each one's
14
+ * `SceneRegistry` key (`clipFromPoseKey`, `derivePathKey`, …), which does
15
+ * cross, and its paste restores the function from the pasting scene's
16
+ * registry. A function that is not registered does not survive. Written with the snapshot codec unless
17
+ * `replacer` says otherwise, so typed arrays and non-finite numbers cross. */
18
+ function buildWeaselClipboardText(items, replacer = snapshotReplacer) {
19
+ return JSON.stringify({
20
+ weaselClipboard: 1,
21
+ nodes: items
22
+ }, replacer);
23
+ }
24
+ var isPayload = (parsed) => !!parsed && parsed.weaselClipboard === 1 && Array.isArray(parsed.nodes);
25
+ /** Cheap check: is this text a payload {@link parseWeaselClipboardText}
26
+ * accepts? Substring pre-check, then a guarded parse. */
27
+ function sniffWeaselClipboardText(text) {
28
+ if (!text.includes("\"weaselClipboard\"")) return false;
29
+ try {
30
+ return isPayload(JSON.parse(text));
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ var SVG_OPEN_TAG = /<svg(?:\s[^>]*)?>/i;
36
+ /**
37
+ * Embed a weasel clipboard payload in an SVG document as a `<metadata>`
38
+ * child of the root — legal SVG 1.1, ignored by external tools — so one
39
+ * `text/plain` flavor serves both audiences.
40
+ *
41
+ * Intended for OUR serializer's output only (`serializeSvg` — single
42
+ * `<svg ...>` open tag, XML-escaped attributes). When no open tag is found
43
+ * the input is returned unchanged with a debug warning.
44
+ */
45
+ function embedWeaselMetadataInSvg(svgText, payloadText) {
46
+ const open = SVG_OPEN_TAG.exec(svgText);
47
+ if (!open) {
48
+ dwarn("clipboard", "embedWeaselMetadataInSvg: no <svg ...> open tag found — returning input unchanged");
49
+ return svgText;
50
+ }
51
+ const cdata = `<![CDATA[${payloadText.replaceAll("]]>", "]]]]><![CDATA[>")}]]>`;
52
+ const at = open.index + open[0].length;
53
+ return `${svgText.slice(0, at)}<metadata>${cdata}</metadata>${svgText.slice(at)}`;
54
+ }
55
+ /**
56
+ * The weasel clipboard payload embedded in SVG text by
57
+ * {@link embedWeaselMetadataInSvg}, or null when the first `<metadata>` block
58
+ * is absent or not the weasel wire format. A text scan, not an XML parse.
59
+ */
60
+ function extractWeaselClipboardFromSvg(svgText) {
61
+ const open = /<metadata(?:\s[^>]*)?>/i.exec(svgText);
62
+ if (!open) return null;
63
+ const sections = [];
64
+ let plain = "";
65
+ let at = open.index + open[0].length;
66
+ for (;;) {
67
+ const cdata = svgText.indexOf("<![CDATA[", at);
68
+ const close = svgText.slice(at).search(/<\/metadata>/i);
69
+ if (close < 0) return null;
70
+ if (cdata < 0 || cdata > at + close) {
71
+ plain += svgText.slice(at, at + close);
72
+ break;
73
+ }
74
+ const end = svgText.indexOf("]]>", cdata + 9);
75
+ if (end < 0) return null;
76
+ plain += svgText.slice(at, cdata);
77
+ sections.push(svgText.slice(cdata + 9, end));
78
+ at = end + 3;
79
+ }
80
+ const payload = sections.length > 0 ? sections.join("") : plain;
81
+ return sniffWeaselClipboardText(payload) ? payload : null;
82
+ }
83
+ /** Parse wire text to snapshot items, or null when malformed/mismatched
84
+ * (callers decline to the next content handler). Decoded with the snapshot codec unless `reviver` says otherwise;
85
+ * a `reviver` that throws declines too, logged with `console.error`. */
86
+ function parseWeaselClipboardText(text, reviver) {
87
+ let reviverThrew = false;
88
+ const revive = reviver && ((key, value) => {
89
+ try {
90
+ return reviver(key, value);
91
+ } catch (err) {
92
+ reviverThrew = true;
93
+ throw err;
94
+ }
95
+ });
96
+ try {
97
+ const parsed = JSON.parse(text, revive);
98
+ if (!isPayload(parsed)) return null;
99
+ return reviver ? parsed.nodes : decodeSnapshot(parsed.nodes);
100
+ } catch (err) {
101
+ if (reviverThrew) console.error("weasel clipboard: the paste reviver threw, so the paste was declined.", err);
102
+ else dwarn("clipboard", `weasel payload failed to parse: ${String(err)}`);
103
+ return null;
104
+ }
105
+ }
106
+
107
+ export { WEASEL_CLIPBOARD_MIME, WEASEL_CLIPBOARD_MIME_WEB, buildWeaselClipboardText, embedWeaselMetadataInSvg, extractWeaselClipboardFromSvg, parseWeaselClipboardText, sniffWeaselClipboardText };
108
+ //# sourceMappingURL=wireFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wireFormat.js","names":[],"sources":["../../src/clipboard/wireFormat.ts"],"sourcesContent":["import { decodeSnapshot, snapshotReplacer, dwarn } from '@weasel-js/core';\n\n/** MIME type the kit writes its full-fidelity clipboard payload under, so a\n * copy/paste between two weasel canvases round-trips scene nodes rather than\n * the SVG or text flavors other apps read. */\nexport const WEASEL_CLIPBOARD_MIME = 'application/x-weasel-clipboard+json';\n/** Chromium's async-clipboard spelling for custom formats. */\nexport const WEASEL_CLIPBOARD_MIME_WEB = `web ${WEASEL_CLIPBOARD_MIME}`;\n\ninterface WeaselClipboardPayload { weaselClipboard: 1; nodes: unknown[] }\n\n/** Serialize snapshot items into the versioned wire text.\n *\n * JSON drops a function-valued field (a container's `clipFromPose`, a\n * node's `derivePath`). A scene adapter's snapshot also carries each one's\n * `SceneRegistry` key (`clipFromPoseKey`, `derivePathKey`, …), which does\n * cross, and its paste restores the function from the pasting scene's\n * registry. A function that is not registered does not survive. Written with the snapshot codec unless\n * `replacer` says otherwise, so typed arrays and non-finite numbers cross. */\nexport function buildWeaselClipboardText(\n items: unknown[],\n replacer: (key: string, value: unknown) => unknown = snapshotReplacer,\n): string {\n const payload: WeaselClipboardPayload = { weaselClipboard: 1, nodes: items };\n return JSON.stringify(payload, replacer);\n}\n\nconst isPayload = (parsed: Partial<WeaselClipboardPayload> | null): parsed is WeaselClipboardPayload =>\n !!parsed && parsed.weaselClipboard === 1 && Array.isArray(parsed.nodes);\n\n/** Cheap check: is this text a payload {@link parseWeaselClipboardText}\n * accepts? Substring pre-check, then a guarded parse. */\nexport function sniffWeaselClipboardText(text: string): boolean {\n if (!text.includes('\"weaselClipboard\"')) return false;\n try {\n return isPayload(JSON.parse(text) as Partial<WeaselClipboardPayload> | null);\n } catch {\n return false;\n }\n}\n\n// `[^>]*` is safe for OUR serializer's output only: attribute values are\n// XML-escaped, so no raw `>` can appear inside the tag.\nconst SVG_OPEN_TAG = /<svg(?:\\s[^>]*)?>/i;\n\n/**\n * Embed a weasel clipboard payload in an SVG document as a `<metadata>`\n * child of the root — legal SVG 1.1, ignored by external tools — so one\n * `text/plain` flavor serves both audiences.\n *\n * Intended for OUR serializer's output only (`serializeSvg` — single\n * `<svg ...>` open tag, XML-escaped attributes). When no open tag is found\n * the input is returned unchanged with a debug warning.\n */\nexport function embedWeaselMetadataInSvg(svgText: string, payloadText: string): string {\n const open = SVG_OPEN_TAG.exec(svgText);\n if (!open) {\n dwarn('clipboard', 'embedWeaselMetadataInSvg: no <svg ...> open tag found — returning input unchanged');\n return svgText;\n }\n const cdata = `<![CDATA[${payloadText.replaceAll(']]>', ']]]]><![CDATA[>')}]]>`;\n const at = open.index + open[0].length;\n return `${svgText.slice(0, at)}<metadata>${cdata}</metadata>${svgText.slice(at)}`;\n}\n\n/**\n * The weasel clipboard payload embedded in SVG text by\n * {@link embedWeaselMetadataInSvg}, or null when the first `<metadata>` block\n * is absent or not the weasel wire format. A text scan, not an XML parse.\n */\nexport function extractWeaselClipboardFromSvg(svgText: string): string | null {\n const open = /<metadata(?:\\s[^>]*)?>/i.exec(svgText);\n if (!open) return null;\n // CDATA sections are read whole before looking for the close, so a payload holding `</metadata>` survives.\n const sections: string[] = [];\n let plain = '';\n let at = open.index + open[0].length;\n for (;;) {\n const cdata = svgText.indexOf('<![CDATA[', at);\n const close = svgText.slice(at).search(/<\\/metadata>/i);\n if (close < 0) return null;\n if (cdata < 0 || cdata > at + close) {\n plain += svgText.slice(at, at + close);\n break;\n }\n const end = svgText.indexOf(']]>', cdata + 9);\n if (end < 0) return null;\n plain += svgText.slice(at, cdata);\n sections.push(svgText.slice(cdata + 9, end));\n at = end + 3;\n }\n const payload = sections.length > 0 ? sections.join('') : plain;\n return sniffWeaselClipboardText(payload) ? payload : null;\n}\n\n/** Parse wire text to snapshot items, or null when malformed/mismatched\n * (callers decline to the next content handler). Decoded with the snapshot codec unless `reviver` says otherwise;\n * a `reviver` that throws declines too, logged with `console.error`. */\nexport function parseWeaselClipboardText(text: string, reviver?: (key: string, value: unknown) => unknown): unknown[] | null {\n let reviverThrew = false;\n const revive = reviver && ((key: string, value: unknown): unknown => {\n try {\n return reviver(key, value);\n } catch (err) {\n reviverThrew = true;\n throw err;\n }\n });\n try {\n const parsed = JSON.parse(text, revive as Parameters<typeof JSON.parse>[1]) as\n Partial<WeaselClipboardPayload> | null;\n if (!isPayload(parsed)) return null;\n return reviver ? parsed.nodes : (decodeSnapshot(parsed.nodes) as unknown[]);\n } catch (err) {\n if (reviverThrew) console.error('weasel clipboard: the paste reviver threw, so the paste was declined.', err);\n else dwarn('clipboard', `weasel payload failed to parse: ${String(err)}`);\n return null;\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,wBAAwB;;AAErC,IAAa,4BAA4B,OAAO;;;;;;;;;AAYhD,SAAgB,yBACd,OACA,WAAqD,kBAC7C;CAER,OAAO,KAAK,UAAU;EADoB,iBAAiB;EAAG,OAAO;CAC/C,GAAS,QAAQ;AACzC;AAEA,IAAM,aAAa,WACjB,CAAC,CAAC,UAAU,OAAO,oBAAoB,KAAK,MAAM,QAAQ,OAAO,KAAK;;;AAIxE,SAAgB,yBAAyB,MAAuB;CAC9D,IAAI,CAAC,KAAK,SAAS,qBAAmB,GAAG,OAAO;CAChD,IAAI;EACF,OAAO,UAAU,KAAK,MAAM,IAAI,CAA2C;CAC7E,QAAQ;EACN,OAAO;CACT;AACF;AAIA,IAAM,eAAe;;;;;;;;;;AAWrB,SAAgB,yBAAyB,SAAiB,aAA6B;CACrF,MAAM,OAAO,aAAa,KAAK,OAAO;CACtC,IAAI,CAAC,MAAM;EACT,MAAM,aAAa,mFAAmF;EACtG,OAAO;CACT;CACA,MAAM,QAAQ,YAAY,YAAY,WAAW,OAAO,iBAAiB,EAAE;CAC3E,MAAM,KAAK,KAAK,QAAQ,KAAK,EAAE,CAAC;CAChC,OAAO,GAAG,QAAQ,MAAM,GAAG,EAAE,EAAE,YAAY,MAAM,aAAa,QAAQ,MAAM,EAAE;AAChF;;;;;;AAOA,SAAgB,8BAA8B,SAAgC;CAC5E,MAAM,OAAO,0BAA0B,KAAK,OAAO;CACnD,IAAI,CAAC,MAAM,OAAO;CAElB,MAAM,WAAqB,CAAC;CAC5B,IAAI,QAAQ;CACZ,IAAI,KAAK,KAAK,QAAQ,KAAK,EAAE,CAAC;CAC9B,SAAS;EACP,MAAM,QAAQ,QAAQ,QAAQ,aAAa,EAAE;EAC7C,MAAM,QAAQ,QAAQ,MAAM,EAAE,CAAC,CAAC,OAAO,eAAe;EACtD,IAAI,QAAQ,GAAG,OAAO;EACtB,IAAI,QAAQ,KAAK,QAAQ,KAAK,OAAO;GACnC,SAAS,QAAQ,MAAM,IAAI,KAAK,KAAK;GACrC;EACF;EACA,MAAM,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC;EAC5C,IAAI,MAAM,GAAG,OAAO;EACpB,SAAS,QAAQ,MAAM,IAAI,KAAK;EAChC,SAAS,KAAK,QAAQ,MAAM,QAAQ,GAAG,GAAG,CAAC;EAC3C,KAAK,MAAM;CACb;CACA,MAAM,UAAU,SAAS,SAAS,IAAI,SAAS,KAAK,EAAE,IAAI;CAC1D,OAAO,yBAAyB,OAAO,IAAI,UAAU;AACvD;;;;AAKA,SAAgB,yBAAyB,MAAc,SAAsE;CAC3H,IAAI,eAAe;CACnB,MAAM,SAAS,aAAa,KAAa,UAA4B;EACnE,IAAI;GACF,OAAO,QAAQ,KAAK,KAAK;EAC3B,SAAS,KAAK;GACZ,eAAe;GACf,MAAM;EACR;CACF;CACA,IAAI;EACF,MAAM,SAAS,KAAK,MAAM,MAAM,MAA0C;EAE1E,IAAI,CAAC,UAAU,MAAM,GAAG,OAAO;EAC/B,OAAO,UAAU,OAAO,QAAS,eAAe,OAAO,KAAK;CAC9D,SAAS,KAAK;EACZ,IAAI,cAAc,QAAQ,MAAM,yEAAyE,GAAG;OACvG,MAAM,aAAa,mCAAmC,OAAO,GAAG,GAAG;EACxE,OAAO;CACT;AACF"}
@@ -0,0 +1,42 @@
1
+ import { hitTestRect, regionPickOptions } from "@weasel-js/core";
2
+ import { useLatest } from "@weasel-js/react";
3
+ import { useDepSource } from "@weasel-js/routing/react";
4
+
5
+ // src/deps/areaSelect.ts
6
+ /**
7
+ * `useAreaSelectDepSource` — wires the `areaSelect` dep consumed by
8
+ * `areaSelectAction`. The dep exposes:
9
+ * - `hitTestArea(bounds)` — silhouette-aware scan over `scene.renderOrderNodes()`
10
+ * (rect poses by AABB; polygon poses by the kernel polygon-overlap test).
11
+ * - `getSelection` / `setSelection` — passthrough to the kit selection api.
12
+ *
13
+ * Built once per render and stabilised by `useDepSource` (which reads via a
14
+ * ref internally), so callers can pass fresh selection/scene refs without
15
+ * triggering re-registration.
16
+ */
17
+ function useAreaSelectDepSource(scene, selection, descriptor, alphaOf, reachable, targetOf) {
18
+ const sceneRef = useLatest(scene);
19
+ const selectionRef = useLatest(selection);
20
+ const descriptorRef = useLatest(descriptor);
21
+ const alphaOfRef = useLatest(alphaOf);
22
+ const reachableRef = useLatest(reachable);
23
+ const targetOfRef = useLatest(targetOf);
24
+ useDepSource("areaSelect", () => {
25
+ const sc = sceneRef.current;
26
+ const s = selectionRef.current;
27
+ const d = descriptorRef.current;
28
+ const a = alphaOfRef.current;
29
+ const r = reachableRef.current;
30
+ const t = targetOfRef.current;
31
+ const keep = (ids) => r ? ids.filter((id) => r(id)) : ids;
32
+ return {
33
+ hitTestArea: (bounds, view) => keep(hitTestRect(sc, bounds, regionPickOptions(view, a), d)),
34
+ ...t ? { targetOf: t } : {},
35
+ getSelection: () => s.current,
36
+ setSelection: (ids) => s.set(ids)
37
+ };
38
+ });
39
+ }
40
+
41
+ export { useAreaSelectDepSource };
42
+ //# sourceMappingURL=areaSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"areaSelect.js","names":[],"sources":["../../src/deps/areaSelect.ts"],"sourcesContent":["/**\n * `useAreaSelectDepSource` — wires the `areaSelect` dep consumed by\n * `areaSelectAction`. The dep exposes:\n * - `hitTestArea(bounds)` — silhouette-aware scan over `scene.renderOrderNodes()`\n * (rect poses by AABB; polygon poses by the kernel polygon-overlap test).\n * - `getSelection` / `setSelection` — passthrough to the kit selection api.\n *\n * Built once per render and stabilised by `useDepSource` (which reads via a\n * ref internally), so callers can pass fresh selection/scene refs without\n * triggering re-registration.\n */\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { AreaSelectDep, PoseDescriptor } from '@weasel-js/core/engine';\nimport type { Scene, NodeId } from '@weasel-js/core';\nimport type { SelectionApi } from '@weasel-js/routing';\nimport { hitTestRect, regionPickOptions } from '@weasel-js/core';\n\nexport function useAreaSelectDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n descriptor?: PoseDescriptor<unknown>,\n /** The painted alpha the surface's layers apply, which every view shares. */\n alphaOf?: (id: string) => number,\n /** Whether a node can be reached at all: the canvas's one answer, which picking reads too. */\n reachable?: (id: string) => boolean,\n /** The node selecting a hit selects, as a click picks. */\n targetOf?: (id: string) => string,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const descriptorRef = useLatest(descriptor);\n const alphaOfRef = useLatest(alphaOf);\n const reachableRef = useLatest(reachable);\n const targetOfRef = useLatest(targetOf);\n\n useDepSource('areaSelect', (): AreaSelectDep => {\n const sc = sceneRef.current;\n const s = selectionRef.current;\n const d = descriptorRef.current;\n const a = alphaOfRef.current;\n const r = reachableRef.current;\n const t = targetOfRef.current;\n const keep = (ids: NodeId[]): NodeId[] => (r ? ids.filter((id) => r(id)) : ids);\n return {\n hitTestArea: (bounds, view) =>\n keep(hitTestRect(sc, bounds, regionPickOptions(view, a), d)),\n ...(t ? { targetOf: t } : {}),\n getSelection: () => s.current as NodeId[],\n setSelection: (ids) => s.set(ids),\n };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,uBACd,OACA,WACA,YAEA,SAEA,WAEA,UACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,gBAAgB,UAAU,UAAU;CAC1C,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,cAAc,UAAU,QAAQ;CAEtC,aAAa,oBAAmC;EAC9C,MAAM,KAAK,SAAS;EACpB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,cAAc;EACxB,MAAM,IAAI,WAAW;EACrB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,YAAY;EACtB,MAAM,QAAQ,QAA6B,IAAI,IAAI,QAAQ,OAAO,EAAE,EAAE,CAAC,IAAI;EAC3E,OAAO;GACL,cAAc,QAAQ,SACpB,KAAK,YAAY,IAAI,QAAQ,kBAAkB,MAAM,CAAC,GAAG,CAAC,CAAC;GAC7D,GAAI,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC;GAC3B,oBAAoB,EAAE;GACtB,eAAe,QAAQ,EAAE,IAAI,GAAG;EAClC;CACF,CAAC;AACH"}
@@ -0,0 +1,99 @@
1
+ import { drawnPose, leafPath, pathPaintOf, renderOrderCompare, sceneInheritedPaintOf, storePiece, storesEdits } from "@weasel-js/core";
2
+ import { useMemo } from "react";
3
+ import { AUTO_POSE_DESCRIPTOR, asNodeId as asNodeId$1, poseDescriptorForNode, sceneMutators, scenePoseFrame as scenePoseFrame$1, withoutPageStructure as withoutPageStructure$1 } from "@weasel-js/core/engine";
4
+ import { pathInWorld, poseFrameOf } from "@weasel-js/geom";
5
+ import { useLatest } from "@weasel-js/react";
6
+ import { useDepSource } from "@weasel-js/routing/react";
7
+
8
+ // src/deps/booleans.ts
9
+ /**
10
+ * The kit `booleansAdapter` dep: what the Pathfinder actions, and any tool
11
+ * reading the dep, work on over a canvas's own path leaves.
12
+ *
13
+ * `presets.booleans` publishes it over the canvas's scene. A consumer replaces it
14
+ * with `useBooleansAdapter` from under the canvas — for text operands, say,
15
+ * which this one does not read; the newest registration wins, and a canvas
16
+ * child registers after the presets' components.
17
+ */
18
+ /**
19
+ * Publish a `booleansAdapter` over `scene`'s path leaves (`data.path` drawn
20
+ * through the pose's box), acting on `operands`. A result is minted from the source it stands in
21
+ * for: its layer, parent, frame, and data, with the result's path, and the
22
+ * result's paint in place of the source's when the operation gives one.
23
+ */
24
+ function useBooleansAdapterDepSource(scene, operands, adapter, poseDescriptor) {
25
+ const sceneRef = useLatest(scene);
26
+ const operandsRef = useLatest(operands);
27
+ const adapterRef = useLatest(adapter);
28
+ const descriptorRef = useLatest(poseDescriptor);
29
+ const booleans = useMemo(() => {
30
+ const leafOf = (id) => {
31
+ const sc = sceneRef.current;
32
+ const node = sc.get(asNodeId$1(id));
33
+ const path = node ? leafPath(sc, node) : null;
34
+ if (!node || !path || !storesEdits(sc, node)) return null;
35
+ const frame = scenePoseFrame$1(sc);
36
+ const g = poseDescriptorForNode(descriptorRef.current ?? AUTO_POSE_DESCRIPTOR, node);
37
+ const drawn = drawnPose(g, frame.world(node.id));
38
+ return drawn ? {
39
+ node,
40
+ path,
41
+ drawn,
42
+ frame
43
+ } : null;
44
+ };
45
+ const tree = () => sceneMutators(sceneRef.current);
46
+ return {
47
+ getNode: (id) => tree().getNode(id),
48
+ getParent: (id) => tree().getParent(id),
49
+ getChildren: (parentId) => tree().getChildren(parentId),
50
+ setChildOrder: (parentId, ids) => tree().setChildOrder(parentId, ids),
51
+ getSelection: () => withoutPageStructure$1(sceneRef.current, operandsRef.current.get()),
52
+ getWorldPath: (id) => {
53
+ const leaf = leafOf(id);
54
+ return leaf ? pathInWorld(leaf.path, leaf.drawn.box) : void 0;
55
+ },
56
+ getPaint: (id) => {
57
+ const leaf = leafOf(id);
58
+ return leaf ? pathPaintOf(leaf.node.data, sceneInheritedPaintOf(sceneRef.current)(leaf.node)) : void 0;
59
+ },
60
+ getStrokeFrame: (id) => {
61
+ const leaf = leafOf(id);
62
+ return leaf ? poseFrameOf(leaf.drawn.box) : void 0;
63
+ },
64
+ compareZ: (a, b) => renderOrderCompare(sceneRef.current)(a, b),
65
+ createPathNode: (path, _op, sourceId, paint) => {
66
+ const leaf = leafOf(sourceId);
67
+ if (!leaf) throw new Error(`[booleansAdapter] no path leaf behind source ${sourceId}`);
68
+ const stored = storePiece(leaf.drawn, path);
69
+ const { fill: _fill, stroke: _stroke, ...rest } = leaf.node.data ?? {};
70
+ const data = paint ? {
71
+ ...rest,
72
+ ...paint,
73
+ path: stored.path
74
+ } : {
75
+ ...leaf.node.data,
76
+ path: stored.path
77
+ };
78
+ return {
79
+ id: sceneRef.current.mintId(),
80
+ kind: "mark",
81
+ layer: leaf.node.layer,
82
+ parent: leaf.node.parent ?? null,
83
+ pose: leaf.frame.local(sourceId, stored.pose),
84
+ data
85
+ };
86
+ },
87
+ applyOps: (ops, label) => adapterRef.current.applyOps(ops, label)
88
+ };
89
+ }, [
90
+ sceneRef,
91
+ operandsRef,
92
+ adapterRef,
93
+ descriptorRef
94
+ ]);
95
+ useDepSource("booleansAdapter", () => booleans);
96
+ }
97
+
98
+ export { useBooleansAdapterDepSource };
99
+ //# sourceMappingURL=booleans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"booleans.js","names":["asNodeId","scenePoseFrame","withoutPageStructure","compareZ"],"sources":["../../src/deps/booleans.ts"],"sourcesContent":["/**\n * The kit `booleansAdapter` dep: what the Pathfinder actions, and any tool\n * reading the dep, work on over a canvas's own path leaves.\n *\n * `presets.booleans` publishes it over the canvas's scene. A consumer replaces it\n * with `useBooleansAdapter` from under the canvas — for text operands, say,\n * which this one does not read; the newest registration wins, and a canvas\n * child registers after the presets' components.\n */\nimport { renderOrderCompare as compareZ, sceneInheritedPaintOf, storesEdits, pathPaintOf, type PathPaint, drawnPose, leafPath, storePiece } from '@weasel-js/core';\nimport { useMemo } from 'react';\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport { pathInWorld, poseFrameOf } from '@weasel-js/geom';\nimport { AUTO_POSE_DESCRIPTOR, poseDescriptorForNode, type PoseDescriptor, sceneMutators, asNodeId, type Scene, withoutPageStructure, scenePoseFrame } from '@weasel-js/core/engine';\nimport type { OperandsDep } from '@weasel-js/core/engine';\nimport type { BooleansAdapter } from '../booleans/booleans';\nimport type { OpsApplier } from '@weasel-js/core';\n\n/**\n * Publish a `booleansAdapter` over `scene`'s path leaves (`data.path` drawn\n * through the pose's box), acting on `operands`. A result is minted from the source it stands in\n * for: its layer, parent, frame, and data, with the result's path, and the\n * result's paint in place of the source's when the operation gives one.\n */\nexport function useBooleansAdapterDepSource(\n scene: Scene<unknown, string, unknown>,\n operands: OperandsDep,\n adapter: OpsApplier,\n poseDescriptor?: PoseDescriptor<unknown>,\n): void {\n const sceneRef = useLatest(scene);\n const operandsRef = useLatest(operands);\n const adapterRef = useLatest(adapter);\n const descriptorRef = useLatest(poseDescriptor);\n\n const booleans = useMemo<BooleansAdapter>(() => {\n const leafOf = (id: string) => {\n const sc = sceneRef.current;\n const node = sc.get(asNodeId(id));\n const path = node ? leafPath(sc, node) : null;\n // A leaf in a singular frame draws flat, and no result could be stored in its place.\n if (!node || !path || !storesEdits(sc, node)) return null;\n const frame = scenePoseFrame(sc);\n const g = poseDescriptorForNode(descriptorRef.current ?? AUTO_POSE_DESCRIPTOR, node);\n const drawn = drawnPose(g, frame.world(node.id));\n return drawn ? { node, path, drawn, frame } : null;\n };\n const tree = () => sceneMutators(sceneRef.current);\n return {\n getNode: (id) => tree().getNode(id),\n getParent: (id) => tree().getParent(id),\n getChildren: (parentId) => tree().getChildren(parentId),\n setChildOrder: (parentId, ids) => tree().setChildOrder(parentId, ids),\n getSelection: () => withoutPageStructure(sceneRef.current, operandsRef.current.get()),\n getWorldPath: (id) => {\n const leaf = leafOf(id);\n return leaf ? pathInWorld(leaf.path, leaf.drawn.box) : undefined;\n },\n getPaint: (id) => {\n const leaf = leafOf(id);\n return leaf\n ? pathPaintOf(leaf.node.data as Parameters<typeof pathPaintOf>[0], sceneInheritedPaintOf(sceneRef.current)(leaf.node))\n : undefined;\n },\n getStrokeFrame: (id) => {\n const leaf = leafOf(id);\n return leaf ? poseFrameOf(leaf.drawn.box) : undefined;\n },\n compareZ: (a, b) => compareZ(sceneRef.current)(a, b),\n createPathNode: (path, _op, sourceId, paint?: PathPaint) => {\n const leaf = leafOf(sourceId);\n if (!leaf) throw new Error(`[booleansAdapter] no path leaf behind source ${sourceId}`);\n const stored = storePiece(leaf.drawn, path);\n const { fill: _fill, stroke: _stroke, ...rest } = (leaf.node.data ?? {}) as Record<string, unknown>;\n const data = paint ? { ...rest, ...paint, path: stored.path } : { ...(leaf.node.data as object), path: stored.path };\n return {\n id: sceneRef.current.mintId(),\n kind: 'mark',\n layer: leaf.node.layer,\n parent: leaf.node.parent ?? null,\n pose: leaf.frame.local(sourceId, stored.pose),\n data,\n };\n },\n applyOps: (ops, label) => adapterRef.current.applyOps(ops, label),\n };\n }, [sceneRef, operandsRef, adapterRef, descriptorRef]);\n\n useDepSource('booleansAdapter', () => booleans);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,4BACd,OACA,UACA,SACA,gBACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,cAAc,UAAU,QAAQ;CACtC,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,gBAAgB,UAAU,cAAc;CAE9C,MAAM,WAAW,cAA+B;EAC9C,MAAM,UAAU,OAAe;GAC7B,MAAM,KAAK,SAAS;GACpB,MAAM,OAAO,GAAG,IAAIA,WAAS,EAAE,CAAC;GAChC,MAAM,OAAO,OAAO,SAAS,IAAI,IAAI,IAAI;GAEzC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,IAAI,IAAI,GAAG,OAAO;GACrD,MAAM,QAAQC,iBAAe,EAAE;GAC/B,MAAM,IAAI,sBAAsB,cAAc,WAAW,sBAAsB,IAAI;GACnF,MAAM,QAAQ,UAAU,GAAG,MAAM,MAAM,KAAK,EAAE,CAAC;GAC/C,OAAO,QAAQ;IAAE;IAAM;IAAM;IAAO;GAAM,IAAI;EAChD;EACA,MAAM,aAAa,cAAc,SAAS,OAAO;EACjD,OAAO;GACL,UAAU,OAAO,KAAK,CAAC,CAAC,QAAQ,EAAE;GAClC,YAAY,OAAO,KAAK,CAAC,CAAC,UAAU,EAAE;GACtC,cA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EAAC;EAAU;EAAa;EAAY;CAAa,CAAC;CAErD,aAAa,yBAAyB,QAAQ;AAChD"}
@@ -0,0 +1,260 @@
1
+ import { DEFAULT_STROKE_WIDTH } from "../actions/insert/style.js";
2
+ import { insertSite, minSizeOf } from "@weasel-js/core";
3
+ import { paletteColorAt, solid, solidStroke, strokeWith } from "@weasel-js/paint";
4
+ import { useRef } from "react";
5
+ import { createCommitSelectionOps, insertPreviewExtent, poseDescriptorOf as poseDescriptorOf$1 } from "@weasel-js/core/engine";
6
+ import { ellipsePath, linePath, polygonFromPoints, rectPath, regularPolygonPath, schneiderFit, starPath } from "@weasel-js/geom";
7
+ import * as ops from "@weasel-js/core/ops";
8
+ import { getOwn } from "@weasel-js/registry";
9
+ import { useLatest } from "@weasel-js/react";
10
+ import { useDepRegistry, useDepSource } from "@weasel-js/routing/react";
11
+
12
+ // src/deps/insert.ts
13
+ /**
14
+ * `useInsertDepSource` — wires the `insert` dep consumed by `insertAction`.
15
+ *
16
+ * `line`, `polygon`, `star`, and `pencil` receive the drag AABB from the insertAction invoker,
17
+ * but `extras` may carry richer geometry (endpoints, center+radius+rotation, point trail).
18
+ * `insertPreviewExtent` resolves the two into the node's real extent — the same resolution the
19
+ * live preview and the reported gesture bounds use.
20
+ */
21
+ /** The paint a kit-built shape of `kind` is inserted with: its `style`, or for
22
+ * an insert carrying none (a tool declaring no style options), the next color
23
+ * of the kit palette, as a fill on a closed shape, a fill and a stroke on a
24
+ * pen path, and a stroke alone on a line or a pencil trail. A key the style
25
+ * leaves out stays off the node, which paints none of it. `seq` counts this
26
+ * canvas's inserts from 1. */
27
+ function paintOf(kind, style, seq) {
28
+ if (!style) {
29
+ const color = paletteColorAt(seq);
30
+ if (kind === "line" || kind === "pencil") return { stroke: solidStroke(color, DEFAULT_STROKE_WIDTH) };
31
+ if (kind === "path") return {
32
+ fill: { paint: solid(color) },
33
+ stroke: solidStroke(color, DEFAULT_STROKE_WIDTH)
34
+ };
35
+ return { fill: { paint: solid(color) } };
36
+ }
37
+ const out = {};
38
+ if (style.fill !== void 0) out.fill = style.fill === null ? null : { paint: style.fill };
39
+ if (style.stroke !== void 0) out.stroke = style.stroke === null ? null : strokeWith(style.stroke, style.strokeWidth ?? DEFAULT_STROKE_WIDTH);
40
+ return out;
41
+ }
42
+ function withFillRule(data, rule) {
43
+ const path = data?.path;
44
+ if (rule === void 0 || path === void 0 || !("fillRule" in path)) return data;
45
+ return {
46
+ ...data,
47
+ path: {
48
+ ...path,
49
+ fillRule: rule
50
+ }
51
+ };
52
+ }
53
+ /** The kinds {@link kitData} builds a node for with no factory. */
54
+ var KIT_INSERT_KINDS = Object.freeze([
55
+ "rect",
56
+ "ellipse",
57
+ "line",
58
+ "polygon",
59
+ "star",
60
+ "path",
61
+ "pencil",
62
+ "image"
63
+ ]);
64
+ /** The kit's default data for a kind drawn as a box, or `null` for a kind it has none for. */
65
+ function boxKindData(kind, bounds, extras, painted) {
66
+ switch (kind) {
67
+ case "rect": return {
68
+ path: rectPath(0, 0, bounds.width, bounds.height),
69
+ ...painted()
70
+ };
71
+ case "ellipse": return {
72
+ path: ellipsePath(bounds),
73
+ ...painted()
74
+ };
75
+ case "path": {
76
+ const e = extras;
77
+ return {
78
+ ...e.data,
79
+ path: e.path,
80
+ ...painted(),
81
+ ...e.closed ? {} : { fill: null }
82
+ };
83
+ }
84
+ case "image": {
85
+ const e = extras;
86
+ return { image: {
87
+ src: e.src ?? "",
88
+ ...e.opacity !== void 0 ? { opacity: e.opacity } : {}
89
+ } };
90
+ }
91
+ default: return null;
92
+ }
93
+ }
94
+ /** The data the kit builds for an insert of `kind` filling `extent`, or `null`
95
+ * for a box kind it has none for. */
96
+ function kitData(kind, extent, extras, painted) {
97
+ const geom = extent.geometry;
98
+ switch (geom.kind) {
99
+ case "line": return {
100
+ path: linePath(geom.a, geom.b),
101
+ ...painted(),
102
+ fill: null
103
+ };
104
+ case "polygon": return {
105
+ path: regularPolygonPath(geom.center, geom.radius, geom.sides, geom.rotation),
106
+ generator: {
107
+ kind: "polygon",
108
+ sides: geom.sides,
109
+ rotation: geom.rotation
110
+ },
111
+ ...painted()
112
+ };
113
+ case "star": return {
114
+ path: starPath(geom.center, geom.outerRadius, geom.points, geom.innerRadius, geom.rotation),
115
+ generator: {
116
+ kind: "star",
117
+ points: geom.points,
118
+ innerRadiusRatio: geom.outerRadius === 0 ? .5 : geom.innerRadius / geom.outerRadius,
119
+ rotation: geom.rotation
120
+ },
121
+ ...painted()
122
+ };
123
+ case "pencil": {
124
+ const samples = geom.samples;
125
+ if (samples.length >= 4) return {
126
+ path: schneiderFit(samples, 2),
127
+ ...painted()
128
+ };
129
+ if (samples.length >= 2) return {
130
+ path: polygonFromPoints(samples),
131
+ ...painted()
132
+ };
133
+ return {
134
+ path: rectPath(0, 0, extent.bounds.width, extent.bounds.height),
135
+ ...painted("rect")
136
+ };
137
+ }
138
+ case "box": return boxKindData(kind, extent.bounds, extras, painted);
139
+ default: return null;
140
+ }
141
+ }
142
+ /** Provides the `insert` dep, and the `insertLive` gesture state beside it, minting nodes into `scene` through
143
+ * `adapter` with `factories` in place of the kit's own. */
144
+ function useInsertDepSource(scene, adapter, factories) {
145
+ const sceneRef = useLatest(scene);
146
+ const adapterRef = useLatest(adapter);
147
+ const factoriesRef = useLatest(factories);
148
+ const registry = useDepRegistry();
149
+ const insertSeqRef = useRef(0);
150
+ const liveRef = useRef({ gesture: null });
151
+ useDepSource("insertLive", () => liveRef.current);
152
+ useDepSource("insert", () => {
153
+ const sc = sceneRef.current;
154
+ const ad = adapterRef.current;
155
+ const site = (at) => insertSite(sc, {
156
+ at,
157
+ into: registry.get("insertInto")?.get(),
158
+ canDropInto: registry.get("canDropInto"),
159
+ descriptor: poseDescriptorOf$1(registry.get("poseDescriptor"))
160
+ });
161
+ /** The node an insert numbered `seq` makes, with nothing minted or counted. A peek is quiet. */
162
+ const nodeFor = (bounds, extras, ends, seq, quiet = false) => {
163
+ const kind = extras.kind;
164
+ const { parent, layer, local } = site(ends?.site ?? ends?.start ?? {
165
+ x: bounds.x,
166
+ y: bounds.y
167
+ });
168
+ const style = extras.style;
169
+ const painted = (as = kind) => paintOf(as, style, seq);
170
+ const extent = insertPreviewExtent({
171
+ shape: kind,
172
+ bounds,
173
+ extras
174
+ });
175
+ const pose = extent.bounds;
176
+ const factories = factoriesRef.current;
177
+ const factory = factories ? getOwn(factories, kind) : void 0;
178
+ if (factory) {
179
+ const built = factory(bounds, extras);
180
+ if (built === null) return null;
181
+ return {
182
+ parent,
183
+ layer,
184
+ pose: local(built.pose ?? pose),
185
+ data: built.data,
186
+ batch: built.batch,
187
+ inserted: built.inserted
188
+ };
189
+ }
190
+ let data = kitData(kind, extent, extras, painted);
191
+ if (data === null) {
192
+ if (!quiet) console.warn(`weasel insertDep: no factory for kind="${kind}", so nothing was inserted. Give <SceneCanvas insertNodeFactories={{ '${kind}': (bounds, extras) => ({ data }) }}> one.`);
193
+ return null;
194
+ }
195
+ data = withFillRule(data, style?.fillRule);
196
+ const min = minSizeOf(extras);
197
+ if (min) data = {
198
+ ...data,
199
+ minSize: min
200
+ };
201
+ return {
202
+ parent,
203
+ layer,
204
+ pose: local(pose),
205
+ data
206
+ };
207
+ };
208
+ const make = (...args) => {
209
+ const [bounds, extras, ends] = args;
210
+ const made = nodeFor(bounds, extras, ends, ++insertSeqRef.current);
211
+ if (made === null) return null;
212
+ const { batch, inserted, ...node } = made;
213
+ const id = sc.mintId();
214
+ return {
215
+ id,
216
+ batch,
217
+ inserted,
218
+ ops: [ops.insert({
219
+ node: {
220
+ id,
221
+ kind: "mark",
222
+ ...node
223
+ },
224
+ label: `Insert ${extras.kind}`
225
+ })]
226
+ };
227
+ };
228
+ const build = (...args) => {
229
+ const made = make(...args);
230
+ return made && {
231
+ id: made.id,
232
+ ops: made.ops
233
+ };
234
+ };
235
+ return {
236
+ layer: () => site().layer,
237
+ build,
238
+ peek(bounds, extras, ends) {
239
+ const node = nodeFor(bounds, extras, ends, insertSeqRef.current + 1, true);
240
+ return node && {
241
+ data: node.data,
242
+ pose: node.pose
243
+ };
244
+ },
245
+ commit(bounds, extras, ends, select) {
246
+ const built = make(bounds, extras, ends);
247
+ if (built === null) return null;
248
+ const label = `Insert ${extras.kind}`;
249
+ const apply = () => ad.applyOps([...built.ops, ...createCommitSelectionOps(select, built.id, label)], label);
250
+ if (built.batch) sc.batch(label, apply, built.batch(String(built.id)));
251
+ else apply();
252
+ built.inserted?.(String(built.id), registry);
253
+ return built.id;
254
+ }
255
+ };
256
+ });
257
+ }
258
+
259
+ export { KIT_INSERT_KINDS, useInsertDepSource };
260
+ //# sourceMappingURL=insert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert.js","names":["poseDescriptorOf"],"sources":["../../src/deps/insert.ts"],"sourcesContent":["/**\n * `useInsertDepSource` — wires the `insert` dep consumed by `insertAction`.\n *\n * `line`, `polygon`, `star`, and `pencil` receive the drag AABB from the insertAction invoker,\n * but `extras` may carry richer geometry (endpoints, center+radius+rotation, point trail).\n * `insertPreviewExtent` resolves the two into the node's real extent — the same resolution the\n * live preview and the reported gesture bounds use.\n */\nimport { getOwn } from '@weasel-js/registry';\nimport { useRef } from 'react';\nimport { useDepRegistry, useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { InsertDep, InsertEnds, InsertExtras, InsertLive, ShapeGenerator } from '@weasel-js/core/engine';\nimport { paletteColorAt, solid, solidStroke, strokeWith } from '@weasel-js/paint';\nimport { insertSite, minSizeOf } from '@weasel-js/core';\nimport { poseDescriptorOf, createCommitSelectionOps, insertPreviewExtent } from '@weasel-js/core/engine';\nimport type { Scene, NodeId, OpsApplier, Op, InsertNodeFactories, InsertedNode } from '@weasel-js/core';\nimport {\n rectPath,\n ellipsePath,\n regularPolygonPath,\n starPath,\n linePath,\n polygonFromPoints,\n schneiderFit,\n type PathFillRule,\n type PolygonPath, type Rect,\n} from '@weasel-js/geom';\nimport type { Stroke, Fill } from '@weasel-js/paint';\nimport { DEFAULT_STROKE_WIDTH, type InsertStyle } from '../actions/insert/style';\nimport * as ops from '@weasel-js/core/ops';\n\ntype Hooks = Pick<InsertedNode, 'batch' | 'inserted'>;\n\ninterface Painted { fill?: Fill | null; stroke?: Stroke | null }\n\n/** The paint a kit-built shape of `kind` is inserted with: its `style`, or for\n * an insert carrying none (a tool declaring no style options), the next color\n * of the kit palette, as a fill on a closed shape, a fill and a stroke on a\n * pen path, and a stroke alone on a line or a pencil trail. A key the style\n * leaves out stays off the node, which paints none of it. `seq` counts this\n * canvas's inserts from 1. */\nfunction paintOf(kind: string, style: InsertStyle | undefined, seq: number): Painted {\n if (!style) {\n const color = paletteColorAt(seq);\n if (kind === 'line' || kind === 'pencil') return { stroke: solidStroke(color, DEFAULT_STROKE_WIDTH) };\n if (kind === 'path') return { fill: { paint: solid(color) }, stroke: solidStroke(color, DEFAULT_STROKE_WIDTH) };\n return { fill: { paint: solid(color) } };\n }\n const out: Painted = {};\n if (style.fill !== undefined) out.fill = style.fill === null ? null : { paint: style.fill };\n if (style.stroke !== undefined) {\n out.stroke = style.stroke === null ? null : strokeWith(style.stroke, style.strokeWidth ?? DEFAULT_STROKE_WIDTH);\n }\n return out;\n}\n\nfunction withFillRule(data: unknown, rule: PathFillRule | undefined): unknown {\n const path = (data as { path?: object } | undefined)?.path;\n if (rule === undefined || path === undefined || !('fillRule' in path)) return data;\n return { ...(data as object), path: { ...path, fillRule: rule } };\n}\n\n/** The kinds {@link kitData} builds a node for with no factory. */\nexport const KIT_INSERT_KINDS: readonly string[] = Object.freeze([\n 'rect', 'ellipse', 'line', 'polygon', 'star', 'path', 'pencil', 'image',\n]);\n\n/** The kit's default data for a kind drawn as a box, or `null` for a kind it has none for. */\nfunction boxKindData(\n kind: string,\n bounds: Rect,\n extras: InsertExtras,\n painted: (as?: string) => Painted,\n): unknown {\n switch (kind) {\n case 'rect':\n // The rect path lives at the origin and the pose carries position:\n // `pathInPoseBox` rebases a rect path onto the pose box, so don't\n // double-count the position.\n return { path: rectPath(0, 0, bounds.width, bounds.height), ...painted() };\n case 'ellipse':\n return { path: ellipsePath(bounds), ...painted() };\n case 'path': {\n const e = extras as { path: PolygonPath; closed: boolean; data?: Readonly<Record<string, unknown>> };\n return { ...e.data, path: e.path, ...painted(), ...(e.closed ? {} : { fill: null }) };\n }\n case 'image': {\n // The bitmap is loaded + cached by `imageCache` keyed on `src`;\n // only the (serializable) `src` lives on the node.\n const e = extras as Partial<{ src: string; opacity: number }>;\n return { image: { src: e.src ?? '', ...(e.opacity !== undefined ? { opacity: e.opacity } : {}) } };\n }\n default:\n return null;\n }\n}\n\n/** The data the kit builds for an insert of `kind` filling `extent`, or `null`\n * for a box kind it has none for. */\nfunction kitData(\n kind: string,\n extent: ReturnType<typeof insertPreviewExtent>,\n extras: InsertExtras,\n painted: (as?: string) => Painted,\n): unknown {\n const geom = extent.geometry;\n switch (geom.kind) {\n case 'line':\n return { path: linePath(geom.a, geom.b), ...painted(), fill: null };\n case 'polygon':\n return {\n path: regularPolygonPath(geom.center, geom.radius, geom.sides, geom.rotation),\n generator: { kind: 'polygon', sides: geom.sides, rotation: geom.rotation } satisfies ShapeGenerator,\n ...painted(),\n };\n case 'star':\n return {\n path: starPath(geom.center, geom.outerRadius, geom.points, geom.innerRadius, geom.rotation),\n generator: {\n kind: 'star',\n points: geom.points,\n innerRadiusRatio: geom.outerRadius === 0 ? 0.5 : geom.innerRadius / geom.outerRadius,\n rotation: geom.rotation,\n } satisfies ShapeGenerator,\n ...painted(),\n };\n case 'pencil': {\n const samples = geom.samples as { x: number; y: number }[];\n if (samples.length >= 4) return { path: schneiderFit(samples, 2.0), ...painted() };\n if (samples.length >= 2) return { path: polygonFromPoints(samples), ...painted() };\n return { path: rectPath(0, 0, extent.bounds.width, extent.bounds.height), ...painted('rect') };\n }\n case 'box':\n return boxKindData(kind, extent.bounds, extras, painted);\n default:\n return null;\n }\n}\n\n/** Provides the `insert` dep, and the `insertLive` gesture state beside it, minting nodes into `scene` through\n * `adapter` with `factories` in place of the kit's own. */\nexport function useInsertDepSource(\n scene: Scene<unknown, string, unknown>,\n adapter: OpsApplier,\n factories?: InsertNodeFactories,\n): void {\n const sceneRef = useLatest(scene);\n const adapterRef = useLatest(adapter);\n const factoriesRef = useLatest(factories);\n const registry = useDepRegistry();\n const insertSeqRef = useRef(0);\n const liveRef = useRef<InsertLive>({ gesture: null });\n useDepSource('insertLive', () => liveRef.current);\n\n useDepSource('insert', (): InsertDep => {\n const sc = sceneRef.current;\n const ad = adapterRef.current;\n\n const site = (at?: { x: number; y: number }) =>\n insertSite(sc, {\n at, into: registry.get('insertInto')?.get(), canDropInto: registry.get('canDropInto'),\n descriptor: poseDescriptorOf(registry.get('poseDescriptor')),\n });\n /** The node an insert numbered `seq` makes, with nothing minted or counted. A peek is quiet. */\n const nodeFor = (\n bounds: Parameters<NonNullable<InsertDep['build']>>[0],\n extras: InsertExtras,\n ends: InsertEnds | undefined,\n seq: number,\n quiet = false,\n ): ({ parent: NodeId | null; layer: string; pose: unknown; data: unknown } & Hooks) | null => {\n const kind = extras.kind;\n const { parent, layer, local } = site(ends?.site ?? ends?.start ?? { x: bounds.x, y: bounds.y });\n const style = (extras as { style?: InsertStyle }).style;\n const painted = (as: string = kind) => paintOf(as, style, seq);\n\n // The nascent node's extent — drag AABB reconciled with whatever\n // richer geometry `extras` carries.\n const extent = insertPreviewExtent({ shape: kind, bounds, extras });\n const pose: unknown = extent.bounds;\n\n // Consumer factory wins over the kit default for this kind. It owns the node's\n // data + optional pose; the dep still supplies id/layer/op.\n const factories = factoriesRef.current;\n const factory = factories ? getOwn(factories, kind) : undefined;\n if (factory) {\n const built = factory(bounds, extras);\n if (built === null) return null;\n return { parent, layer, pose: local(built.pose ?? pose), data: built.data, batch: built.batch, inserted: built.inserted };\n }\n\n let data = kitData(kind, extent, extras, painted);\n if (data === null) {\n if (!quiet) {\n console.warn(\n `weasel insertDep: no factory for kind=\"${kind}\", so nothing was inserted. ` +\n `Give <SceneCanvas insertNodeFactories={{ '${kind}': (bounds, extras) => ({ data }) }}> one.`,\n );\n }\n return null;\n }\n data = withFillRule(data, style?.fillRule);\n const min = minSizeOf(extras);\n if (min) data = { ...(data as object), minSize: min };\n return { parent, layer, pose: local(pose), data };\n };\n const make = (...args: Parameters<NonNullable<InsertDep['build']>>): ({ id: NodeId; ops: Op[] } & Hooks) | null => {\n const [bounds, extras, ends] = args;\n const made = nodeFor(bounds, extras, ends, ++insertSeqRef.current);\n if (made === null) return null;\n const { batch, inserted, ...node } = made;\n const id = sc.mintId();\n return {\n id, batch, inserted,\n ops: [ops.insert({ node: { id, kind: 'mark', ...node } as unknown as { id: string }, label: `Insert ${extras.kind}` })],\n };\n };\n const build: NonNullable<InsertDep['build']> = (...args) => {\n const made = make(...args);\n return made && { id: made.id, ops: made.ops };\n };\n return {\n layer: () => site().layer,\n build,\n peek(bounds, extras, ends) {\n const node = nodeFor(bounds, extras, ends, insertSeqRef.current + 1, true);\n return node && { data: node.data, pose: node.pose };\n },\n commit(bounds, extras, ends, select): NodeId | null {\n const built = make(bounds, extras, ends);\n if (built === null) return null;\n const label = `Insert ${extras.kind}`;\n const apply = () => ad.applyOps([...built.ops, ...createCommitSelectionOps(select, built.id, label)], label);\n // An adapter whose `applyOps` keeps its own history records nothing in the batch.\n if (built.batch) sc.batch(label, apply, built.batch(String(built.id)));\n else apply();\n built.inserted?.(String(built.id), registry);\n return built.id;\n },\n };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAS,QAAQ,MAAc,OAAgC,KAAsB;CACnF,IAAI,CAAC,OAAO;EACV,MAAM,QAAQ,eAAe,GAAG;EAChC,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO,EAAE,QAAQ,YAAY,OAAO,oBAAoB,EAAE;EACpG,IAAI,SAAS,QAAQ,OAAO;GAAE,MAAM,EAAE,OAAO,MAAM,KAAK,EAAE;GAAG,QAAQ,YAAY,OAAO,oBAAoB;EAAE;EAC9G,OAAO,EAAE,MAA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;GACf;EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,37 @@
1
+ import { hitTestLassoPolygon, hitTestRect, regionPickOptions } from "@weasel-js/core";
2
+ import { useLatest } from "@weasel-js/react";
3
+ import { useDepSource } from "@weasel-js/routing/react";
4
+
5
+ // src/deps/lassoSelect.ts
6
+ /**
7
+ * `useLassoSelectDepSource` — wires the `lassoSelect` dep consumed by
8
+ * `lassoSelectAction`: `hitTestLasso` tests the lasso polygon itself, and
9
+ * `hitTestArea` is the same silhouette-aware rect test `areaSelect` uses.
10
+ */
11
+ function useLassoSelectDepSource(scene, selection, descriptor, alphaOf, reachable, targetOf) {
12
+ const sceneRef = useLatest(scene);
13
+ const selectionRef = useLatest(selection);
14
+ const descriptorRef = useLatest(descriptor);
15
+ const alphaOfRef = useLatest(alphaOf);
16
+ const reachableRef = useLatest(reachable);
17
+ const targetOfRef = useLatest(targetOf);
18
+ useDepSource("lassoSelect", () => {
19
+ const sc = sceneRef.current;
20
+ const s = selectionRef.current;
21
+ const d = descriptorRef.current;
22
+ const a = alphaOfRef.current;
23
+ const r = reachableRef.current;
24
+ const t = targetOfRef.current;
25
+ const keep = (ids) => r ? ids.filter((id) => r(id)) : ids;
26
+ return {
27
+ hitTestLasso: (polygon, mode, view) => keep(hitTestLassoPolygon(sc, polygon, mode, regionPickOptions(view, a), d)),
28
+ hitTestArea: (bounds, view) => keep(hitTestRect(sc, bounds, regionPickOptions(view, a), d)),
29
+ ...t ? { targetOf: t } : {},
30
+ getSelection: () => s.current,
31
+ setSelection: (ids) => s.set(ids)
32
+ };
33
+ });
34
+ }
35
+
36
+ export { useLassoSelectDepSource };
37
+ //# sourceMappingURL=lassoSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lassoSelect.js","names":[],"sources":["../../src/deps/lassoSelect.ts"],"sourcesContent":["/**\n * `useLassoSelectDepSource` — wires the `lassoSelect` dep consumed by\n * `lassoSelectAction`: `hitTestLasso` tests the lasso polygon itself, and\n * `hitTestArea` is the same silhouette-aware rect test `areaSelect` uses.\n */\nimport { useDepSource } from '@weasel-js/routing/react';\nimport { useLatest } from '@weasel-js/react';\nimport type { LassoSelectDep, PoseDescriptor } from '@weasel-js/core/engine';\nimport type { Scene, NodeId } from '@weasel-js/core';\nimport type { SelectionApi } from '@weasel-js/routing';\nimport { hitTestRect, hitTestLassoPolygon, regionPickOptions } from '@weasel-js/core';\n\nexport function useLassoSelectDepSource(\n scene: Scene<unknown, string, unknown>,\n selection: SelectionApi,\n descriptor?: PoseDescriptor<unknown>,\n /** The painted alpha the surface's layers apply, which every view shares. */\n alphaOf?: (id: string) => number,\n /** Whether a node can be reached at all: the canvas's one answer, which picking reads too. */\n reachable?: (id: string) => boolean,\n /** The node selecting a hit selects, as a click picks. */\n targetOf?: (id: string) => string,\n): void {\n const sceneRef = useLatest(scene);\n const selectionRef = useLatest(selection);\n const descriptorRef = useLatest(descriptor);\n const alphaOfRef = useLatest(alphaOf);\n const reachableRef = useLatest(reachable);\n const targetOfRef = useLatest(targetOf);\n\n useDepSource('lassoSelect', (): LassoSelectDep => {\n const sc = sceneRef.current;\n const s = selectionRef.current;\n const d = descriptorRef.current;\n const a = alphaOfRef.current;\n const r = reachableRef.current;\n const t = targetOfRef.current;\n const keep = (ids: NodeId[]): NodeId[] => (r ? ids.filter((id) => r(id)) : ids);\n return {\n hitTestLasso: (polygon, mode, view) =>\n keep(hitTestLassoPolygon(sc, polygon, mode, regionPickOptions(view, a), d)),\n hitTestArea: (bounds, view) =>\n keep(hitTestRect(sc, bounds, regionPickOptions(view, a), d)),\n ...(t ? { targetOf: t } : {}),\n getSelection: () => s.current as NodeId[],\n setSelection: (ids) => s.set(ids as NodeId[]),\n };\n });\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,wBACd,OACA,WACA,YAEA,SAEA,WAEA,UACM;CACN,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,gBAAgB,UAAU,UAAU;CAC1C,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,cAAc,UAAU,QAAQ;CAEtC,aAAa,qBAAqC;EAChD,MAAM,KAAK,SAAS;EACpB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,cAAc;EACxB,MAAM,IAAI,WAAW;EACrB,MAAM,IAAI,aAAa;EACvB,MAAM,IAAI,YAAY;EACtB,MAAM,QAAQ,QAA6B,IAAI,IAAI,QAAQ,OAAO,EAAE,EAAE,CAAC,IAAI;EAC3E,OAAO;GACL,eAAe,SAAS,MAAM,SAC5B,KAAK,oBAAoB,IAAI,SAAS,MAAM,kBAAkB,MAAM,CAAC,GAAG,CAAC,CAAC;GAC5E,cAAc,QAAQ,SACpB,KAAK,YAAY,IAAI,QAAQ,kBAAkB,MAAM,CAAC,GAAG,CAAC,CAAC;GAC7D,GAAI,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC;GAC3B,oBAAoB,EAAE;GACtB,eAAe,QAAQ,EAAE,IAAI,GAAe;EAC9C;CACF,CAAC;AACH"}