@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,34 @@
1
+ import { INSERT_GROUP } from "../../actionGroups.js";
2
+ import { defineAction } from "@weasel-js/routing";
3
+
4
+ // src/actions/insert/rotateAction.ts
5
+ /** Radians per unit of wheel deltaY. Tuned so a typical mouse-wheel click
6
+ * (deltaY ≈ 100) yields ~25°, while a trackpad event (deltaY ≈ 1–10)
7
+ * yields a smooth 0.25–2.5° increment. */
8
+ var ROTATION_SENSITIVITY = Math.PI / 720;
9
+ /**
10
+ * Companion to `insertAction` — adjusts the live insert gesture's
11
+ * `userRotation` based on wheel deltaY. Intended to be bound to
12
+ * Shift+wheel during the insert tool's engaged phase. No-op when no
13
+ * insert is in flight.
14
+ */
15
+ var insertRotateAction = defineAction({
16
+ id: "insert.rotate",
17
+ label: "Insert — rotate",
18
+ group: INSERT_GROUP,
19
+ eligible: { capability: "creates-shapes" },
20
+ invoker: {
21
+ timing: "immediate",
22
+ run: (deps, params) => {
23
+ const gesture = deps.insertLive?.gesture;
24
+ if (!gesture || !gesture.open) return;
25
+ const deltaY = params?.deltaY ?? 0;
26
+ if (deltaY === 0) return;
27
+ gesture.userRotation += deltaY * ROTATION_SENSITIVITY;
28
+ }
29
+ },
30
+ requires: ["insertLive"]
31
+ });
32
+
33
+ export { insertRotateAction };
34
+ //# sourceMappingURL=rotateAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotateAction.js","names":[],"sources":["../../../src/actions/insert/rotateAction.ts"],"sourcesContent":["import { defineAction } from '@weasel-js/routing';\nimport type { InsertLiveGesture } from './live';\nimport type {} from '@weasel-js/core';\nimport { INSERT_GROUP } from '../../actionGroups';\n\n/** Radians per unit of wheel deltaY. Tuned so a typical mouse-wheel click\n * (deltaY ≈ 100) yields ~25°, while a trackpad event (deltaY ≈ 1–10)\n * yields a smooth 0.25–2.5° increment. */\nconst ROTATION_SENSITIVITY = Math.PI / 720;\n\n/**\n * Companion to `insertAction` — adjusts the live insert gesture's\n * `userRotation` based on wheel deltaY. Intended to be bound to\n * Shift+wheel during the insert tool's engaged phase. No-op when no\n * insert is in flight.\n */\nexport const insertRotateAction = defineAction({\n id: 'insert.rotate',\n label: 'Insert — rotate',\n group: INSERT_GROUP,\n eligible: { capability: 'creates-shapes' },\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const gesture = deps.insertLive?.gesture as InsertLiveGesture | null | undefined;\n if (!gesture || !gesture.open) return;\n const deltaY = params?.deltaY ?? 0;\n if (deltaY === 0) return;\n gesture.userRotation += deltaY * ROTATION_SENSITIVITY;\n },\n },\n requires: ['insertLive'],\n});\n"],"mappings":";;;;;;;AAQA,IAAM,uBAAuB,KAAK,KAAK;;;;;;;AAQvC,IAAa,qBAAqB,aAAa;CAC7C,IAAI;CACJ,OAAO;CACP,OAAO;CACP,UAAU,EAAE,YAAY,iBAAiB;CACzC,SAAS;EACP,QAAQ;EACR,MAAM,MAAM,WAAW;GACrB,MAAM,UAAU,KAAK,YAAY;GACjC,IAAI,CAAC,WAAW,CAAC,QAAQ,MAAM;GAC/B,MAAM,SAAS,QAAQ,UAAU;GACjC,IAAI,WAAW,GAAG;GAClB,QAAQ,gBAAgB,SAAS;EACnC;CACF;CACA,UAAU,CAAC,YAAY;AACzB,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { moveGestureAdapter } from "../move/gestureAdapter.js";
2
+ import { insertKind } from "./shape.js";
3
+ import { createSpanSnap, gestureReaders, insertParent, pointerStateOf } from "@weasel-js/core";
4
+ import { resolveParams } from "@weasel-js/routing";
5
+ import { SNAP_ANGLE_STEP, operandMethods as operandMethods$1, snapMods } from "@weasel-js/core/engine";
6
+
7
+ // src/actions/insert/session.ts
8
+ /** The key an insert's single gesture point rides under in the behaviors'
9
+ * `draggedIds` / `origin` / `current` — insert has no node id yet. */
10
+ var GESTURE_KEY = "gesture";
11
+ /** The selection change an insert's commit carries: from what the press
12
+ * cleared back to nothing, so undo restores it. None when nothing was cleared. */
13
+ function clearedSelection(prior) {
14
+ return prior.length > 0 ? {
15
+ from: prior,
16
+ selectNode: false
17
+ } : void 0;
18
+ }
19
+ /** Capture an insert at press. Null with no `insert` dep. Clears the
20
+ * selection and runs each behavior's `onStart`. */
21
+ function beginInsert(ctx, opts) {
22
+ const dep = ctx.deps.insert;
23
+ if (!dep) return null;
24
+ const scene = ctx.deps.scene;
25
+ const selection = ctx.deps.operands;
26
+ const priorSelection = selection ? [...selection.get()] : [];
27
+ if (selection && priorSelection.length > 0) selection.set([]);
28
+ const { insertInto, canDropInto } = ctx.deps;
29
+ const parentAt = (p) => insertParent(scene, insertInto?.get(), canDropInto, p);
30
+ const site = {
31
+ x: ctx.world.x,
32
+ y: ctx.world.y
33
+ };
34
+ const place = {
35
+ site,
36
+ parent: parentAt(site),
37
+ parentAt
38
+ };
39
+ const constrain = () => insertKind(resolveParams(opts?.params)) === "line" ? { step: SNAP_ANGLE_STEP } : void 0;
40
+ const snap = createSpanSnap(ctx.deps.snap, constrain, () => place.parent === null ? {} : { parent: place.parent });
41
+ const behaviors = opts?.behaviors ?? [];
42
+ const readers = gestureReaders(ctx.deps);
43
+ const origin = snap.start({
44
+ x: ctx.world.x,
45
+ y: ctx.world.y
46
+ }, snapMods(ctx)).point;
47
+ const gestureCtx = {
48
+ draggedIds: [GESTURE_KEY],
49
+ origin: /* @__PURE__ */ new Map([[GESTURE_KEY, origin]]),
50
+ current: /* @__PURE__ */ new Map([[GESTURE_KEY, origin]]),
51
+ snap: null,
52
+ modifiers: { ...ctx.modifiers },
53
+ pointer: pointerStateOf(ctx.world, ctx),
54
+ view: readers.view(),
55
+ plane: readers.plane(),
56
+ kitSettings: readers.kitSettings,
57
+ adapter: scene ? moveGestureAdapter(scene, void 0, operandMethods$1(selection)) : void 0,
58
+ scratch: {}
59
+ };
60
+ for (const b of behaviors) b.onStart?.(gestureCtx);
61
+ if (snap.startHeld()) gestureCtx.origin.set(GESTURE_KEY, origin);
62
+ const startPoint = gestureCtx.origin.get(GESTURE_KEY);
63
+ snap.anchor(startPoint);
64
+ const startShift = {
65
+ x: startPoint.x - origin.x,
66
+ y: startPoint.y - origin.y
67
+ };
68
+ return {
69
+ session: {
70
+ dep,
71
+ snap,
72
+ opts,
73
+ priorSelection,
74
+ behaviors,
75
+ gestureCtx,
76
+ scene: ctx.deps.scene,
77
+ startShift,
78
+ place,
79
+ applyOps: ctx.deps.applyOps,
80
+ selection
81
+ },
82
+ readers,
83
+ frame: {
84
+ pointer: {
85
+ x: ctx.world.x,
86
+ y: ctx.world.y
87
+ },
88
+ points: ctx.drag?.points ?? null,
89
+ altHeld: ctx.modifiers.alt,
90
+ shaped: {
91
+ start: startPoint,
92
+ current: startPoint
93
+ }
94
+ }
95
+ };
96
+ }
97
+
98
+ export { GESTURE_KEY, beginInsert, clearedSelection };
99
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","names":["operandMethods"],"sources":["../../../src/actions/insert/session.ts"],"sourcesContent":["import type { BindingOptions, DragSample, InvocationCtx } from '@weasel-js/routing';\nimport { operandMethods, SNAP_ANGLE_STEP, snapMods } from '@weasel-js/core/engine';\nimport type { OperandsDep, GestureContext, InsertBehavior, InsertPoint, InsertDep, CommitSelection } from '@weasel-js/core/engine';\nimport { resolveParams } from '@weasel-js/routing';\nimport type { InsertParams, Op, NodeId, Scene } from '@weasel-js/core';\nimport { createSpanSnap, type SpanSnap, pointerStateOf, gestureReaders, type GestureReaders, insertParent } from '@weasel-js/core';\nimport { moveGestureAdapter } from '../move/gestureAdapter';\nimport { insertKind } from './shape';\n\n/** The key an insert's single gesture point rides under in the behaviors'\n * `draggedIds` / `origin` / `current` — insert has no node id yet. */\nexport const GESTURE_KEY = 'gesture';\n\n/** What an insert captured at press. Nothing here changes during the drag.\n * The deps are captured because the dispatcher builds the deps bag once, on\n * `start`: every later pump event carries `deps: {}`. */\nexport interface InsertSession {\n readonly dep: InsertDep;\n /** For the text kind's drop-into-the-caret step. */\n /** Snaps the drag's start and current point, so the live preview and the\n * committed geometry agree. Freehand pencil samples are deliberately NOT\n * snapped — a grid-quantized freehand trail is a staircase, not a stroke. */\n readonly snap: SpanSnap;\n /** The active binding's opts — re-resolved on every read so thunked\n * params see the latest tool state (e.g. polygon `sides` after ArrowUp). */\n readonly opts: BindingOptions<Partial<InsertParams>> | undefined;\n /** What was selected before the draw cleared it, to put back on cancel. */\n readonly priorSelection: readonly NodeId[];\n /** Behaviors from `opts.behaviors`; empty when none were bound. */\n readonly behaviors: readonly InsertBehavior<unknown>[];\n /** Reused gesture context handed to behaviors. Its `origin` holds the\n * start point under {@link GESTURE_KEY}, after `onStart` shaped it. */\n readonly gestureCtx: GestureContext<unknown>;\n /** For committing a behavior's `Op[]`. */\n readonly scene: Scene<unknown, string, unknown> | undefined;\n /** How far the behaviors' `onStart` moved the start off where the snap put\n * it at press. A carry keeps it. */\n readonly startShift: InsertPoint;\n /** Where the node lands. The one part of the session a drag changes: moving\n * the shape mid-draw carries it. */\n readonly place: InsertPlace;\n readonly applyOps: ((ops: Op[], label: string) => void) | undefined;\n readonly selection: OperandsDep | undefined;\n}\n\n/** The point that picks an insert's container (`InsertEnds.site`), and the\n * container it picks: null for the top of the tree. */\nexport interface InsertPlace {\n site: InsertPoint;\n parent: NodeId | null;\n /** The container for a site at `p`, as `insertParent` picks it. */\n readonly parentAt: (p: InsertPoint) => NodeId | null;\n}\n\n/** The selection change an insert's commit carries: from what the press\n * cleared back to nothing, so undo restores it. None when nothing was cleared. */\nexport function clearedSelection(prior: readonly NodeId[]): CommitSelection | undefined {\n return prior.length > 0 ? { from: prior, selectNode: false } : undefined;\n}\n\n/** What the latest pump event left. Replaced, not mutated, by the next. */\nexport interface InsertFrame {\n /** The raw (unsnapped) pointer in world space. */\n readonly pointer: InsertPoint;\n /** Pointer trail accumulated by the dispatcher in world space; pencil-kind\n * commits read it. */\n readonly points: ReadonlyArray<DragSample> | null;\n /** Alt inverts the binding's nominal `originMode` (corner ⇄ center), so\n * pressing or releasing it mid-drag flips the preview and the commit\n * without the dispatcher re-routing to another binding. */\n readonly altHeld: boolean;\n /** The endpoints after the snap session and the behaviors. */\n readonly shaped: { start: InsertPoint; current: InsertPoint };\n}\n\n/** Capture an insert at press. Null with no `insert` dep. Clears the\n * selection and runs each behavior's `onStart`. */\nexport function beginInsert(\n ctx: InvocationCtx<InsertParams>,\n opts: BindingOptions<Partial<InsertParams>> | undefined,\n): { session: InsertSession; readers: GestureReaders; frame: InsertFrame } | null {\n const dep = ctx.deps.insert;\n if (!dep) return null;\n const scene = ctx.deps.scene;\n\n // Starting a draw retires any prior selection — the lingering halo\n // around an unrelated node while the user is drawing a new shape is\n // just visual noise, and it primes the UX bug where a drag that\n // continues over the selected node would otherwise drive the move\n // action via fall-through. The clear is unconditional: the user has\n // committed to \"I'm making a new thing\" by engaging a creation tool.\n const selection = ctx.deps.operands;\n const priorSelection = selection ? [...selection.get()] : [];\n if (selection && priorSelection.length > 0) {\n selection.set([]);\n }\n\n const { insertInto, canDropInto } = ctx.deps;\n const parentAt = (p: InsertPoint) => insertParent(scene, insertInto?.get(), canDropInto, p);\n const site = { x: ctx.world.x, y: ctx.world.y };\n const place: InsertPlace = { site, parent: parentAt(site), parentAt };\n const constrain = () => (insertKind(resolveParams(opts?.params)) === 'line' ? { step: SNAP_ANGLE_STEP } : undefined);\n const snap = createSpanSnap(ctx.deps.snap, constrain, () => (place.parent === null ? {} : { parent: place.parent }));\n const behaviors = (opts?.behaviors ?? []) as InsertBehavior<unknown>[];\n const readers = gestureReaders(ctx.deps);\n const origin = snap.start({ x: ctx.world.x, y: ctx.world.y }, snapMods(ctx)).point;\n const gestureCtx: GestureContext<unknown> = {\n draggedIds: [GESTURE_KEY],\n origin: new Map<string, unknown>([[GESTURE_KEY, origin]]),\n current: new Map<string, unknown>([[GESTURE_KEY, origin]]),\n snap: null,\n modifiers: { ...ctx.modifiers },\n pointer: pointerStateOf(ctx.world, ctx),\n view: readers.view(),\n plane: readers.plane(),\n kitSettings: readers.kitSettings,\n // With no scene the `insert` dep mints the node itself, and no adapter exists to hand over.\n adapter: (scene\n ? moveGestureAdapter(scene, undefined, operandMethods(selection))\n : undefined) as unknown as GestureContext<unknown>['adapter'],\n scratch: {},\n };\n for (const b of behaviors) b.onStart?.(gestureCtx);\n // A snap target in range outranks a behavior's own snapping.\n if (snap.startHeld()) gestureCtx.origin.set(GESTURE_KEY, origin);\n const startPoint = gestureCtx.origin.get(GESTURE_KEY) as InsertPoint;\n snap.anchor(startPoint);\n const startShift = { x: startPoint.x - origin.x, y: startPoint.y - origin.y };\n\n const session: InsertSession = {\n dep,\n snap,\n opts,\n priorSelection,\n behaviors,\n gestureCtx,\n scene: ctx.deps.scene,\n startShift,\n place,\n applyOps: ctx.deps.applyOps,\n selection,\n };\n const frame: InsertFrame = {\n pointer: { x: ctx.world.x, y: ctx.world.y },\n points: ctx.drag?.points ?? null,\n altHeld: ctx.modifiers.alt,\n shaped: { start: startPoint, current: startPoint },\n };\n return { session, readers, frame };\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,cAAc;;;AA6C3B,SAAgB,iBAAiB,OAAuD;CACtF,OAAO,MAAM,SAAS,IAAI;EAAE,MAAM;EAAO,YAAY;CAAM,IAAI;AACjE;;;AAmBA,SAAgB,YACd,KACA,MACgF;CAChF,MAAM,MAAM,IAAI,KAAK;CACrB,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,QAAQ,IAAI,KAAK;CAQvB,MAAM,YAAY,IAAI,KAAK;CAC3B,MAAM,iBAAiB,YAAY,CAAC,GAAG,UAAU,IAAI,CAAC,IAAI,CAAC;CAC3D,IAAI,aAAa,eAAe,SAAS,GACvC,UAAU,IAAI,CAAC,CAAC;CAGlB,MAAM,EAAE,YAAY,gBAAgB,IAAI;CACxC,MAAM,YAAY,MAAmB,aAAa,OAAO,YAAY,IAAI,GAAG,aAAa,CAAC;CAC1F,MAAM,OAAO;EAAE,GAAG,IAAI,MAAM;EAAG,GAAG,IAAI,MAAM;CAAE;CAC9C,MAAM,QAAqB;EAAE;EAAM,QAAQ,SAAS,IAAI;EAAG;CAAS;CACpE,MAAM,kBAAmB,WAAW,cAAc,MAAM,MAAM,CAAC,MAAM,SAAS,EAAE,MAAM,gBAAgB,IAAI;CAC1G,MAAM,OAAO,eAAe,IAAI,KAAK,MAAM,iBAAkB,MAAM,WAAW,OAAO,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO,CAAE;CACnH,MAAM,YAAa,MAAM,aAAa,CAAC;CACvC,MAAM,UAAU,eAAe,IAAI,IAAI;CACvC,MAAM,SAAS,KAAK,MAAM;EAAE,GAAG,IAAI,MAAM;EAAG,GAAG,IAAI,MAAM;CAAE,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC;CAC7E,MAAM,aAAsC;EAC1C,YAAY,CAAC,WAAW;EACxB,wBAAQ,IAAI,IAAqB,CAAC,CAAC,aAAa,MAAM,CAAC,CAAC;EACxD,yBAAS,IAAI,IAAqB,CAAC,CAAC,aAAa,MAAM,CAAC,CAAC;EACzD,MAAM;EACN,WAAW,EAAE,GAAG,IAAI,UAAU;EAC9B,SAAS,eAAe,IAAI,OAAO,GAAG;EACtC,MAAM,QAAQ,KAAK;EACnB,OAAO,QAAQ,MAAM;EACrB,aAAa,QAAQ;EAErB,SAAU,QACN,mBAAmB,OAAO,QAAWA,iBAAe,SAAS,CAAC,IAC9D;EACJ,SAAS,CAAC;CACZ;CACA,KAAK,MAAM,KAAK,WAAW,EAAE,UAAU,UAAU;CAEjD,IAAI,KAAK,UAAU,GAAG,WAAW,OAAO,IAAI,aAAa,MAAM;CAC/D,MAAM,aAAa,WAAW,OAAO,IAAI,WAAW;CACpD,KAAK,OAAO,UAAU;CACtB,MAAM,aAAa;EAAE,GAAG,WAAW,IAAI,OAAO;EAAG,GAAG,WAAW,IAAI,OAAO;CAAE;CAqB5E,OAAO;EAAE;GAlBP;GACA;GACA;GACA;GACA;GACA;GACA,OAAO,IAAI,KAAK;GAChB;GACA;GACA,UAAU,IAAI,KAAK;GACnB;EAQO;EAAS;EAAS;GALzB,SAAS;IAAE,GAAG,IAAI,MAAM;IAAG,GAAG,IAAI,MAAM;GAAE;GAC1C,QAAQ,IAAI,MAAM,UAAU;GAC5B,SAAS,IAAI,UAAU;GACvB,QAAQ;IAAE,OAAO;IAAY,SAAS;GAAW;EAExB;CAAM;AACnC"}
@@ -0,0 +1,117 @@
1
+ import { applyUserRotation, buildExtras } from "./extras.js";
2
+ import { effectiveOriginMode, insertRectFor } from "./geometry.js";
3
+ import { insertStyleOf } from "./style.js";
4
+ import { minSizeOf } from "@weasel-js/core";
5
+ import { insertPreviewExtent } from "@weasel-js/core/engine";
6
+
7
+ // src/actions/insert/shape.ts
8
+ /** The node kind a binding's resolved params ask for. */
9
+ function insertKind(resolved) {
10
+ return resolved?.kind ?? "rect";
11
+ }
12
+ /** The effective endpoints: `shaped`, plus — for the `line` kind only — the
13
+ * alt/center reading as "mirror the start around the pointer" rather than
14
+ * "grow a symmetric AABB". */
15
+ function resolveEndpoints(shaped, kind, mode) {
16
+ let { start } = shaped;
17
+ const { current } = shaped;
18
+ if (kind === "line" && mode === "center") start = {
19
+ x: start.x - (current.x - start.x),
20
+ y: start.y - (current.y - start.y)
21
+ };
22
+ return {
23
+ start,
24
+ current
25
+ };
26
+ }
27
+ /** `current` moved out from `start` until the box they make is no smaller
28
+ * than `min`, along the way the drag went (rightward and down when it has
29
+ * not gone either way). */
30
+ function reachMinimum(start, current, min, mode) {
31
+ const k = mode === "center" ? .5 : 1;
32
+ const reach = (d, m) => Math.abs(d) >= m * k ? d : (d < 0 ? -1 : 1) * m * k;
33
+ return {
34
+ ...current,
35
+ x: start.x + reach(current.x - start.x, min.width),
36
+ y: start.y + reach(current.y - start.y, min.height)
37
+ };
38
+ }
39
+ /** Kinds a minimum size does not apply to: a line has no area, and a pencil
40
+ * trail is drawn where the pointer went. */
41
+ var NO_MINIMUM = /* @__PURE__ */ new Set(["line", "pencil"]);
42
+ /** The shape an insert has at `frame`. The live overlay and the commit both
43
+ * read it from here, so they can't disagree. Extras are derived with the
44
+ * effective origin mode, so polygon/star center+radius follow the live Alt
45
+ * toggle and not the binding's nominal `originMode`. */
46
+ function insertShape(resolved, frame, points, userRotation, landingAt, site) {
47
+ const mode = effectiveOriginMode(resolved?.["originMode"], frame.altHeld);
48
+ const kind = insertKind(resolved);
49
+ const ends = resolveEndpoints(frame.shaped, kind, mode);
50
+ const { start } = ends;
51
+ const min = NO_MINIMUM.has(kind) ? null : minSizeOf(resolved);
52
+ const current = min ? reachMinimum(start, ends.current, min, mode) : ends.current;
53
+ const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);
54
+ const extras = buildExtras({
55
+ ...resolved ?? {},
56
+ originMode: mode
57
+ }, start.x, start.y, current.x, current.y, points);
58
+ applyUserRotation(extras, userRotation);
59
+ if (min) extras.minSize = min;
60
+ const style = insertStyleOf(resolved);
61
+ if (style) extras.style = style;
62
+ const from = mode === "center" ? frame.shaped.start : start;
63
+ const landings = landingAt && endLandings(landingAt(from), landingAt(current));
64
+ return {
65
+ bounds,
66
+ extras,
67
+ start,
68
+ ends: {
69
+ start: {
70
+ x: from.x,
71
+ y: from.y
72
+ },
73
+ end: {
74
+ x: current.x,
75
+ y: current.y
76
+ },
77
+ ...mode === "center" ? { fromCenter: true } : {},
78
+ ...landings ? { landings } : {},
79
+ ...site ? { site: {
80
+ x: site.x,
81
+ y: site.y
82
+ } } : {}
83
+ }
84
+ };
85
+ }
86
+ function endLandings(start, end) {
87
+ if (start === void 0 && end === void 0) return void 0;
88
+ return {
89
+ ...start !== void 0 ? { start } : {},
90
+ ...end !== void 0 ? { end } : {}
91
+ };
92
+ }
93
+ /** Whether a drag produced enough extent to be worth committing. The test
94
+ * is kind-aware because "zero size" isn't one shape:
95
+ * - pencil: a sample trail can be meaningful even when start ≈ end
96
+ * (a closed loop), so no guard at all.
97
+ * - line: has no area by construction. An axis-aligned line has a
98
+ * zero-height (or zero-width) AABB and is perfectly valid — only
99
+ * a zero-LENGTH drag is degenerate. (Shift-constrain makes
100
+ * axis-aligned the common case, which is how this surfaced.)
101
+ * - everything else: a zero extent in either axis is degenerate, the
102
+ * extent being the shape the preview draws and the dep mints
103
+ * (`insertPreviewExtent`): a from-center polygon's is its radius, not the box. */
104
+ function isCommittableExtent(bounds, extras) {
105
+ const kind = extras.kind;
106
+ if (kind === "pencil") return true;
107
+ if (kind === "line") return bounds.width !== 0 || bounds.height !== 0;
108
+ const { width, height } = insertPreviewExtent({
109
+ shape: kind,
110
+ bounds,
111
+ extras
112
+ }).bounds;
113
+ return width !== 0 && height !== 0;
114
+ }
115
+
116
+ export { insertKind, insertShape, isCommittableExtent };
117
+ //# sourceMappingURL=shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.js","names":[],"sources":["../../../src/actions/insert/shape.ts"],"sourcesContent":["import type { DragSample } from '@weasel-js/routing';\nimport { insertPreviewExtent, type InsertPoint, type InsertEnds, type InsertExtras } from '@weasel-js/core/engine';\nimport { applyUserRotation, buildExtras } from './extras';\nimport { insertRectFor, effectiveOriginMode } from './geometry';\nimport type { InsertFrame } from './session';\nimport { minSizeOf, type MinSize } from '@weasel-js/core';\nimport { insertStyleOf, type InsertStyle } from './style';\nimport type { InsertParams } from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\n\n/** The node kind a binding's resolved params ask for. */\nexport function insertKind(resolved: Readonly<Partial<InsertParams>> | undefined): string {\n return resolved?.kind ?? 'rect';\n}\n\n/** The effective endpoints: `shaped`, plus — for the `line` kind only — the\n * alt/center reading as \"mirror the start around the pointer\" rather than\n * \"grow a symmetric AABB\". */\nfunction resolveEndpoints(\n shaped: InsertFrame['shaped'],\n kind: string,\n mode: 'corner' | 'center',\n): { start: InsertPoint; current: InsertPoint } {\n let { start } = shaped;\n const { current } = shaped;\n\n // A line has no area, so \"from center\" means the drag is a half-line:\n // mirror the start to the far side of the pointer.\n if (kind === 'line' && mode === 'center') {\n start = { x: start.x - (current.x - start.x), y: start.y - (current.y - start.y) };\n }\n return { start, current };\n}\n\n/** `current` moved out from `start` until the box they make is no smaller\n * than `min`, along the way the drag went (rightward and down when it has\n * not gone either way). */\nfunction reachMinimum(\n start: InsertPoint,\n current: InsertPoint,\n min: MinSize,\n mode: 'corner' | 'center',\n): InsertPoint {\n // A center drag makes a box twice its reach.\n const k = mode === 'center' ? 0.5 : 1;\n const reach = (d: number, m: number) => (Math.abs(d) >= m * k ? d : (d < 0 ? -1 : 1) * m * k);\n return {\n ...current,\n x: start.x + reach(current.x - start.x, min.width),\n y: start.y + reach(current.y - start.y, min.height),\n };\n}\n\n/** Kinds a minimum size does not apply to: a line has no area, and a pencil\n * trail is drawn where the pointer went. */\nconst NO_MINIMUM = new Set(['line', 'pencil']);\n\nexport interface InsertShape {\n bounds: Rect;\n extras: InsertExtras;\n /** Where the drag started, after the endpoints were resolved. */\n start: InsertPoint;\n /** The drag `bounds` came from. */\n ends: InsertEnds;\n}\n\n/** The shape an insert has at `frame`. The live overlay and the commit both\n * read it from here, so they can't disagree. Extras are derived with the\n * effective origin mode, so polygon/star center+radius follow the live Alt\n * toggle and not the binding's nominal `originMode`. */\nexport function insertShape(\n resolved: Readonly<Partial<InsertParams>> | undefined,\n frame: Pick<InsertFrame, 'shaped' | 'altHeld'>,\n points: ReadonlyArray<DragSample> | null,\n userRotation: number,\n /** The snap's landing for an end at `p` (`SpanSnap.landingAt`). */\n landingAt?: (p: InsertPoint) => unknown,\n /** The point that picked the container (`InsertEnds.site`). */\n site?: InsertPoint,\n): InsertShape {\n const mode = effectiveOriginMode(resolved?.['originMode'], frame.altHeld);\n const kind = insertKind(resolved);\n const ends = resolveEndpoints(frame.shaped, kind, mode);\n const { start } = ends;\n const min = NO_MINIMUM.has(kind) ? null : minSizeOf(resolved);\n const current = min ? reachMinimum(start, ends.current, min, mode) : ends.current;\n const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);\n const extras = buildExtras(\n { ...(resolved ?? {}), originMode: mode },\n start.x, start.y, current.x, current.y,\n points,\n );\n applyUserRotation(extras, userRotation);\n // The node keeps the minimum it was drawn to, whatever its kind's extras hold.\n if (min) (extras as { minSize?: MinSize }).minSize = min;\n const style = insertStyleOf(resolved);\n if (style) (extras as { style?: InsertStyle }).style = style;\n // A from-center drag's start is its center, a line's too, not the end mirrored from the pointer.\n const from = mode === 'center' ? frame.shaped.start : start;\n const landings = landingAt && endLandings(landingAt(from), landingAt(current));\n const drag: InsertEnds = {\n start: { x: from.x, y: from.y },\n end: { x: current.x, y: current.y },\n ...(mode === 'center' ? { fromCenter: true } : {}),\n ...(landings ? { landings } : {}),\n ...(site ? { site: { x: site.x, y: site.y } } : {}),\n };\n return { bounds, extras, start, ends: drag };\n}\n\nfunction endLandings(start: unknown, end: unknown): InsertEnds['landings'] | undefined {\n if (start === undefined && end === undefined) return undefined;\n return { ...(start !== undefined ? { start } : {}), ...(end !== undefined ? { end } : {}) };\n}\n\n/** Whether a drag produced enough extent to be worth committing. The test\n * is kind-aware because \"zero size\" isn't one shape:\n * - pencil: a sample trail can be meaningful even when start ≈ end\n * (a closed loop), so no guard at all.\n * - line: has no area by construction. An axis-aligned line has a\n * zero-height (or zero-width) AABB and is perfectly valid — only\n * a zero-LENGTH drag is degenerate. (Shift-constrain makes\n * axis-aligned the common case, which is how this surfaced.)\n * - everything else: a zero extent in either axis is degenerate, the\n * extent being the shape the preview draws and the dep mints\n * (`insertPreviewExtent`): a from-center polygon's is its radius, not the box. */\nexport function isCommittableExtent(bounds: Rect, extras: InsertExtras): boolean {\n const kind = extras.kind;\n if (kind === 'pencil') return true;\n if (kind === 'line') return bounds.width !== 0 || bounds.height !== 0;\n const { width, height } = insertPreviewExtent({ shape: kind, bounds, extras }).bounds;\n return width !== 0 && height !== 0;\n}\n"],"mappings":"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"}
@@ -0,0 +1,23 @@
1
+ // src/actions/insert/style.ts
2
+ /** The style params an insert reads, each a shape tool's option of the same name. */
3
+ var STYLE_OPTION_KEYS = [
4
+ "fill",
5
+ "stroke",
6
+ "strokeWidth",
7
+ "fillRule"
8
+ ];
9
+ /** The stroke width a new shape is drawn with, in world units, when nothing names one. */
10
+ var DEFAULT_STROKE_WIDTH = 2;
11
+ /** The style `params` carry, or `undefined` when they carry none. */
12
+ function insertStyleOf(params) {
13
+ if (!params) return void 0;
14
+ let style;
15
+ for (const key of STYLE_OPTION_KEYS) {
16
+ if (!Object.hasOwn(params, key) || params[key] === void 0) continue;
17
+ (style ??= {})[key] = params[key];
18
+ }
19
+ return style;
20
+ }
21
+
22
+ export { DEFAULT_STROKE_WIDTH, STYLE_OPTION_KEYS, insertStyleOf };
23
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","names":[],"sources":["../../../src/actions/insert/style.ts"],"sourcesContent":["import type { Paint } from '@weasel-js/paint';\nimport type { PathFillRule } from '@weasel-js/geom';\n\n/** The style params an insert reads, each a shape tool's option of the same name. */\nexport const STYLE_OPTION_KEYS = ['fill', 'stroke', 'strokeWidth', 'fillRule'] as const;\n/** One of {@link STYLE_OPTION_KEYS}. */\nexport type StyleOptionKey = (typeof STYLE_OPTION_KEYS)[number];\n\n/** The stroke width a new shape is drawn with, in world units, when nothing names one. */\nexport const DEFAULT_STROKE_WIDTH = 2;\n\n/** The style an insert is drawn with, as `extras.style` hands it to the `insert` dep. A key left out is the dep's\n * own choice; `null` paints none of it. */\nexport interface InsertStyle {\n fill?: Paint | null;\n stroke?: Paint | null;\n strokeWidth?: number;\n fillRule?: PathFillRule;\n}\n\n/** The style `params` carry, or `undefined` when they carry none. */\nexport function insertStyleOf(params: Readonly<Record<string, unknown>> | undefined): InsertStyle | undefined {\n if (!params) return undefined;\n let style: InsertStyle | undefined;\n for (const key of STYLE_OPTION_KEYS) {\n if (!Object.hasOwn(params, key) || params[key] === undefined) continue;\n (style ??= {})[key] = params[key] as never;\n }\n return style;\n}\n"],"mappings":";;AAIA,IAAa,oBAAoB;CAAC;CAAQ;CAAU;CAAe;AAAU;;AAK7E,IAAa,uBAAuB;;AAYpC,SAAgB,cAAc,QAAgF;CAC5G,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI;CACJ,KAAK,MAAM,OAAO,mBAAmB;EACnC,IAAI,CAAC,OAAO,OAAO,QAAQ,GAAG,KAAK,OAAO,SAAS,QAAW;EAC9D,CAAC,UAAU,CAAC,EAAA,CAAG,OAAO,OAAO;CAC/B;CACA,OAAO;AACT"}
@@ -0,0 +1,201 @@
1
+ import { LASSO_VERTICES, isTinyLasso } from "./behaviors/selectFromLasso.js";
2
+ import { applyOpsTo, finiteThroughout, gestureViewReader, pointerStateOf, reduceBehaviorEnd, runBehaviorCancel, runBehaviorSettled, selectionFromHits, targetsOf } from "@weasel-js/core";
3
+ import { defineAction, resolveParams, setScratch } from "@weasel-js/routing";
4
+
5
+ // src/actions/lassoSelect/action.ts
6
+ /**
7
+ * `lassoSelectAction` — ongoing Action descriptor for polygon lasso selection.
8
+ *
9
+ * A move adds a vertex unless it is closer than the binding's
10
+ * `params.minVertexSpacing` (default 2 world-px) to the last one. The commit
11
+ * hit-tests the polygon with `dep.hitTestLasso(polygon, mode)` — `mode` from
12
+ * the binding's `params.mode`, default `'intersect'` — falling back to the
13
+ * polygon's AABB via `dep.hitTestArea(bounds)`. Shift extends the selection.
14
+ * Always transient: no undo entry.
15
+ *
16
+ * `opts.behaviors` (`LassoSelectBehavior[]`) run over a `GestureContext`
17
+ * whose `origin.get('gesture')` is the start pose, whose scratch holds the
18
+ * vertices under `LASSO_VERTICES`, and whose adapter answers selection and
19
+ * hit-testing from the `lassoSelect` dep. `onEnd` is first-non-undefined-wins:
20
+ * `Op[]` is applied in place of the default selection, `null` aborts, and
21
+ * all-`undefined` falls through to it. A behavior's ops are applied
22
+ * transiently too.
23
+ */
24
+ /** Compute AABB of a polygon (for fallback hit-test when hitTestLasso is absent). */
25
+ function polygonAabb(pts) {
26
+ if (pts.length === 0) return null;
27
+ let minX = pts[0].x, minY = pts[0].y, maxX = pts[0].x, maxY = pts[0].y;
28
+ for (const p of pts) {
29
+ if (p.x < minX) minX = p.x;
30
+ if (p.y < minY) minY = p.y;
31
+ if (p.x > maxX) maxX = p.x;
32
+ if (p.y > maxY) maxY = p.y;
33
+ }
34
+ return {
35
+ x: minX,
36
+ y: minY,
37
+ width: maxX - minX,
38
+ height: maxY - minY
39
+ };
40
+ }
41
+ /** The dep's polygon test, or its rect test over the polygon's AABB when it
42
+ * has none, each hit taken at the depth a click selects. What both the
43
+ * default commit and a behavior's adapter ask. */
44
+ function hitTestPolygon(dep, vertices, mode, view) {
45
+ if (dep.hitTestLasso) return targetsOf(dep.hitTestLasso(vertices, mode, view), dep.targetOf);
46
+ const aabb = polygonAabb(vertices);
47
+ return aabb ? targetsOf(dep.hitTestArea(aabb, view), dep.targetOf) : [];
48
+ }
49
+ /** The adapter a behavior sees: selection and hit-testing from the dep,
50
+ * scoped to the view the lasso started in. */
51
+ function behaviorAdapter(dep, view) {
52
+ const adapter = {
53
+ getSelection: () => dep.getSelection(),
54
+ setSelection: (ids) => dep.setSelection(ids),
55
+ hitTestArea: (rect) => targetsOf(dep.hitTestArea(rect, view), dep.targetOf),
56
+ hitTestLasso: (polygon, mode) => hitTestPolygon(dep, polygon, mode, view),
57
+ applyOps: (ops) => applyOpsTo(adapter, ops)
58
+ };
59
+ return adapter;
60
+ }
61
+ var DEFAULT_MIN_VERTEX_SPACING = 2;
62
+ /**
63
+ * Static descriptor for the `lassoSelect` Action.
64
+ */
65
+ var lassoSelectAction = defineAction({
66
+ id: "lassoSelect",
67
+ label: "Lasso Select",
68
+ eligible: { capability: "creates-selection" },
69
+ requires: ["lassoSelect", "view"],
70
+ invoker: {
71
+ timing: "ongoing",
72
+ start(ctx, opts) {
73
+ const dep = ctx.deps.lassoSelect;
74
+ if (!dep || !finiteThroughout(ctx.world)) return {};
75
+ const params = resolveParams(opts?.params);
76
+ const view = ctx.deps.view;
77
+ const vertices = [{
78
+ x: ctx.world.x,
79
+ y: ctx.world.y
80
+ }];
81
+ const behaviors = opts?.behaviors ?? [];
82
+ let gesture = null;
83
+ const readView = gestureViewReader(ctx.deps);
84
+ if (behaviors.length > 0) {
85
+ const pose = {
86
+ worldX: ctx.world.x,
87
+ worldY: ctx.world.y,
88
+ shiftHeld: ctx.modifiers.shift
89
+ };
90
+ gesture = {
91
+ draggedIds: ["gesture"],
92
+ origin: /* @__PURE__ */ new Map([["gesture", pose]]),
93
+ current: /* @__PURE__ */ new Map([["gesture", { ...pose }]]),
94
+ snap: null,
95
+ modifiers: { ...ctx.modifiers },
96
+ pointer: pointerStateOf(ctx.world, ctx),
97
+ view: readView(),
98
+ adapter: behaviorAdapter(dep, view),
99
+ scratch: {}
100
+ };
101
+ setScratch(gesture.scratch, LASSO_VERTICES, vertices);
102
+ for (const b of behaviors) b.onStart?.(gesture);
103
+ }
104
+ const scratch = {
105
+ dep,
106
+ mode: params?.mode ?? "intersect",
107
+ minVertexSpacing: params?.minVertexSpacing ?? DEFAULT_MIN_VERTEX_SPACING,
108
+ view,
109
+ vertices,
110
+ shiftHeld: ctx.modifiers.shift,
111
+ currentX: ctx.world.x,
112
+ currentY: ctx.world.y,
113
+ open: true,
114
+ behaviors,
115
+ gesture
116
+ };
117
+ return {
118
+ kind: "lasso",
119
+ autoPan: true,
120
+ onMove(moveCtx) {
121
+ if (!finiteThroughout(moveCtx.world)) return;
122
+ const { x, y } = moveCtx.world;
123
+ scratch.currentX = x;
124
+ scratch.currentY = y;
125
+ const last = scratch.vertices[scratch.vertices.length - 1];
126
+ const dx = x - last.x;
127
+ const dy = y - last.y;
128
+ const min = scratch.minVertexSpacing;
129
+ if (dx * dx + dy * dy >= min * min) scratch.vertices.push({
130
+ x,
131
+ y
132
+ });
133
+ const g = scratch.gesture;
134
+ if (g) {
135
+ g.modifiers = { ...moveCtx.modifiers };
136
+ g.pointer = pointerStateOf(moveCtx.world, moveCtx);
137
+ g.view = readView();
138
+ g.current.set("gesture", {
139
+ worldX: x,
140
+ worldY: y,
141
+ shiftHeld: scratch.shiftHeld
142
+ });
143
+ const proposed = {
144
+ vertices: scratch.vertices,
145
+ shiftHeld: scratch.shiftHeld
146
+ };
147
+ for (const b of scratch.behaviors) b.onMove?.(g, proposed);
148
+ }
149
+ },
150
+ overlay() {
151
+ if (!scratch.open) return null;
152
+ return {
153
+ kind: "lasso",
154
+ vertices: scratch.vertices,
155
+ current: {
156
+ x: scratch.currentX,
157
+ y: scratch.currentY
158
+ },
159
+ shiftHeld: scratch.shiftHeld
160
+ };
161
+ },
162
+ onEnd(_endCtx, reason) {
163
+ let committed = false;
164
+ try {
165
+ committed = endLasso(scratch, reason);
166
+ } finally {
167
+ if (scratch.gesture) runBehaviorSettled(scratch.behaviors, scratch.gesture, committed);
168
+ }
169
+ }
170
+ };
171
+ }
172
+ },
173
+ enabled: () => true
174
+ });
175
+ /** Close the lasso. Returns whether it committed: a behavior's ops were
176
+ * applied, or the lasso set the selection. */
177
+ function endLasso(scratch, reason) {
178
+ scratch.open = false;
179
+ if (reason === "cancel") {
180
+ if (scratch.gesture) runBehaviorCancel(scratch.behaviors, scratch.gesture);
181
+ return false;
182
+ }
183
+ const { dep: d, mode, view, vertices, shiftHeld, gesture: g } = scratch;
184
+ if (g) {
185
+ const r = reduceBehaviorEnd(scratch.behaviors, g);
186
+ if (r !== void 0) {
187
+ if (r !== null) g.adapter.applyOps(r);
188
+ return r !== null;
189
+ }
190
+ }
191
+ if (isTinyLasso(vertices)) {
192
+ if (!shiftHeld) d.setSelection([]);
193
+ return !shiftHeld;
194
+ }
195
+ const hits = hitTestPolygon(d, vertices, mode, view);
196
+ d.setSelection(selectionFromHits(d.getSelection(), hits, shiftHeld));
197
+ return true;
198
+ }
199
+
200
+ export { lassoSelectAction };
201
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","names":[],"sources":["../../../src/actions/lassoSelect/action.ts"],"sourcesContent":["/**\n * `lassoSelectAction` — ongoing Action descriptor for polygon lasso selection.\n *\n * A move adds a vertex unless it is closer than the binding's\n * `params.minVertexSpacing` (default 2 world-px) to the last one. The commit\n * hit-tests the polygon with `dep.hitTestLasso(polygon, mode)` — `mode` from\n * the binding's `params.mode`, default `'intersect'` — falling back to the\n * polygon's AABB via `dep.hitTestArea(bounds)`. Shift extends the selection.\n * Always transient: no undo entry.\n *\n * `opts.behaviors` (`LassoSelectBehavior[]`) run over a `GestureContext`\n * whose `origin.get('gesture')` is the start pose, whose scratch holds the\n * vertices under `LASSO_VERTICES`, and whose adapter answers selection and\n * hit-testing from the `lassoSelect` dep. `onEnd` is first-non-undefined-wins:\n * `Op[]` is applied in place of the default selection, `null` aborts, and\n * all-`undefined` falls through to it. A behavior's ops are applied\n * transiently too.\n */\n\nimport { gestureViewReader, pointerStateOf, applyOpsTo, reduceBehaviorEnd, runBehaviorCancel, runBehaviorSettled, targetsOf, selectionFromHits, finiteThroughout } from '@weasel-js/core';\nimport { defineAction, resolveParams, setScratch } from '@weasel-js/routing';\nimport type { InvocationCtx, OngoingHandle, OngoingOverlay, Point2 } from '@weasel-js/routing';\nimport type { LassoSelectDep, ViewApi, LassoHitMode, LassoSelectAdapter, GestureContext, LassoSelectBehavior, LassoSelectPose } from '@weasel-js/core/engine';\nimport type { Op } from '@weasel-js/core';\nimport { LASSO_VERTICES, isTinyLasso } from './behaviors/selectFromLasso';\nimport type {} from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\n\n/** Compute AABB of a polygon (for fallback hit-test when hitTestLasso is absent). */\nfunction polygonAabb(\n pts: Point2[],\n): Rect | null {\n if (pts.length === 0) return null;\n let minX = pts[0].x, minY = pts[0].y, maxX = pts[0].x, maxY = pts[0].y;\n for (const p of pts) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/** The dep's polygon test, or its rect test over the polygon's AABB when it\n * has none, each hit taken at the depth a click selects. What both the\n * default commit and a behavior's adapter ask. */\nfunction hitTestPolygon(\n dep: LassoSelectDep,\n vertices: ReadonlyArray<Point2>,\n mode: LassoHitMode,\n view: ViewApi | undefined,\n): string[] {\n if (dep.hitTestLasso) return targetsOf(dep.hitTestLasso(vertices, mode, view), dep.targetOf);\n const aabb = polygonAabb(vertices as Point2[]);\n return aabb ? targetsOf(dep.hitTestArea(aabb, view), dep.targetOf) : [];\n}\n\n/** The adapter a behavior sees: selection and hit-testing from the dep,\n * scoped to the view the lasso started in. */\nfunction behaviorAdapter(dep: LassoSelectDep, view: ViewApi | undefined): LassoSelectAdapter {\n const adapter: LassoSelectAdapter = {\n getSelection: () => dep.getSelection(),\n setSelection: (ids) => dep.setSelection(ids),\n hitTestArea: (rect) => targetsOf(dep.hitTestArea(rect, view), dep.targetOf),\n hitTestLasso: (polygon, mode) => hitTestPolygon(dep, polygon, mode, view),\n applyOps: (ops: Op[]) => applyOpsTo(adapter, ops),\n };\n return adapter;\n}\n\nconst DEFAULT_MIN_VERTEX_SPACING = 2; // world-px\n\ninterface LassoScratch {\n dep: LassoSelectDep;\n mode: LassoHitMode;\n minVertexSpacing: number;\n /** The view the lasso started in: what it does not paint is not taken. */\n view: ViewApi | undefined;\n vertices: Point2[];\n shiftHeld: boolean;\n /** Current pointer position — paint the live \"close-line\" from the last\n * vertex back to the start while the gesture is open. Tracked separately\n * from `vertices` because we throttle vertex insertion. */\n currentX: number;\n currentY: number;\n /** Cleared by `onEnd` so post-commit `overlay()` returns null. */\n open: boolean;\n behaviors: LassoSelectBehavior[];\n /** Built only when there are behaviors to hand it to. */\n gesture: GestureContext<LassoSelectPose> | null;\n}\n\n/**\n * Static descriptor for the `lassoSelect` Action.\n */\nexport const lassoSelectAction = defineAction({\n id: 'lassoSelect',\n label: 'Lasso Select',\n eligible: { capability: 'creates-selection' },\n requires: ['lassoSelect', 'view'],\n invoker: {\n timing: 'ongoing',\n start(ctx, opts): OngoingHandle {\n const dep = ctx.deps.lassoSelect;\n // A press that is no finite number lands nowhere, as a move that is not does below.\n if (!dep || !finiteThroughout(ctx.world)) return {};\n\n const params = resolveParams(opts?.params);\n const view = ctx.deps.view;\n const vertices: Point2[] = [{ x: ctx.world.x, y: ctx.world.y }];\n const behaviors = (opts?.behaviors ?? []) as LassoSelectBehavior[];\n let gesture: GestureContext<LassoSelectPose> | null = null;\n const readView = gestureViewReader(ctx.deps);\n if (behaviors.length > 0) {\n const pose: LassoSelectPose = {\n worldX: ctx.world.x, worldY: ctx.world.y, shiftHeld: ctx.modifiers.shift,\n };\n gesture = {\n draggedIds: ['gesture'],\n origin: new Map([['gesture', pose]]),\n current: new Map([['gesture', { ...pose }]]),\n snap: null,\n modifiers: { ...ctx.modifiers },\n pointer: pointerStateOf(ctx.world, ctx),\n view: readView(),\n adapter: behaviorAdapter(dep, view) as unknown as GestureContext<LassoSelectPose>['adapter'],\n scratch: {},\n };\n // The live array, so a behavior reads every vertex added since.\n setScratch(gesture.scratch, LASSO_VERTICES, vertices);\n for (const b of behaviors) b.onStart?.(gesture);\n }\n const scratch: LassoScratch = {\n dep,\n mode: params?.mode ?? 'intersect',\n minVertexSpacing: params?.minVertexSpacing ?? DEFAULT_MIN_VERTEX_SPACING,\n view,\n vertices,\n shiftHeld: ctx.modifiers.shift,\n currentX: ctx.world.x,\n currentY: ctx.world.y,\n open: true,\n behaviors,\n gesture,\n };\n\n return {\n kind: 'lasso',\n autoPan: true,\n onMove(moveCtx: InvocationCtx): void {\n if (!finiteThroughout(moveCtx.world)) return;\n const { x, y } = moveCtx.world;\n scratch.currentX = x;\n scratch.currentY = y;\n const last = scratch.vertices[scratch.vertices.length - 1];\n const dx = x - last.x;\n const dy = y - last.y;\n const min = scratch.minVertexSpacing;\n if (dx * dx + dy * dy >= min * min) {\n scratch.vertices.push({ x, y });\n }\n const g = scratch.gesture;\n if (g) {\n g.modifiers = { ...moveCtx.modifiers };\n g.pointer = pointerStateOf(moveCtx.world, moveCtx);\n g.view = readView();\n g.current.set('gesture', { worldX: x, worldY: y, shiftHeld: scratch.shiftHeld });\n const proposed = { vertices: scratch.vertices, shiftHeld: scratch.shiftHeld };\n for (const b of scratch.behaviors) b.onMove?.(g, proposed);\n }\n },\n overlay(): OngoingOverlay | null {\n if (!scratch.open) return null;\n return {\n kind: 'lasso',\n vertices: scratch.vertices,\n current: { x: scratch.currentX, y: scratch.currentY },\n shiftHeld: scratch.shiftHeld,\n };\n },\n onEnd(_endCtx: InvocationCtx, reason: 'commit' | 'cancel'): void {\n let committed = false;\n try {\n committed = endLasso(scratch, reason);\n } finally {\n if (scratch.gesture) runBehaviorSettled(scratch.behaviors, scratch.gesture, committed);\n }\n },\n };\n },\n },\n enabled: () => true,\n});\n\n/** Close the lasso. Returns whether it committed: a behavior's ops were\n * applied, or the lasso set the selection. */\nfunction endLasso(scratch: LassoScratch, reason: 'commit' | 'cancel'): boolean {\n scratch.open = false;\n if (reason === 'cancel') {\n if (scratch.gesture) runBehaviorCancel(scratch.behaviors, scratch.gesture);\n return false;\n }\n\n const { dep: d, mode, view, vertices, shiftHeld, gesture: g } = scratch;\n\n if (g) {\n const r = reduceBehaviorEnd(scratch.behaviors, g);\n if (r !== undefined) {\n if (r !== null) (g.adapter as unknown as LassoSelectAdapter).applyOps!(r);\n return r !== null;\n }\n }\n\n if (isTinyLasso(vertices)) {\n if (!shiftHeld) d.setSelection([]);\n return !shiftHeld;\n }\n\n const hits = hitTestPolygon(d, vertices, mode, view);\n\n d.setSelection(selectionFromHits(d.getSelection(), hits, shiftHeld));\n return true;\n}\n"],"mappings":"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"}
@@ -0,0 +1,61 @@
1
+ import { selectionFromHits } from "@weasel-js/core";
2
+ import { getScratch, scratchKey } from "@weasel-js/routing";
3
+ import * as ops from "@weasel-js/core/ops";
4
+
5
+ // src/actions/lassoSelect/behaviors/selectFromLasso.ts
6
+ /** Typed scratch slot the lasso tool's gesture writes into for this behavior
7
+ * to consume. Shared identity: tools producing the polygon for a lasso
8
+ * selection write under this same key. */
9
+ var LASSO_VERTICES = scratchKey("lassoSelect.vertices");
10
+ var MIN_AREA = 4;
11
+ /** Whether a lasso through `vertices` is too small to enclose anything, so it reads as a click: fewer than
12
+ * three vertices, or a box under 4 world px². */
13
+ function isTinyLasso(vertices) {
14
+ return vertices.length < 3 || polygonAabbArea(vertices) < MIN_AREA;
15
+ }
16
+ /** A lasso behavior (`useLassoTool({ behaviors })`): replace selection with
17
+ * polygon hits in its own `mode`, or extend the existing selection when shift
18
+ * is held at gesture start. Tiny / degenerate lassos behave like a click —
19
+ * clear (or preserve, with shift). Hits come from the gesture adapter's
20
+ * `hitTestLasso`, which under `lassoSelectAction` is the `lassoSelect` dep. */
21
+ function selectFromLasso(opts) {
22
+ const mode = opts?.mode ?? "intersect";
23
+ return {
24
+ defaultTransient: true,
25
+ onEnd(ctx) {
26
+ const adapter = ctx.adapter;
27
+ if (!adapter.getSelection || !adapter.hitTestLasso) return null;
28
+ const vertices = getScratch(ctx.scratch, LASSO_VERTICES) ?? [];
29
+ const startPose = ctx.origin.get("gesture");
30
+ const shiftHeld = startPose ? startPose.shiftHeld === true : false;
31
+ const from = adapter.getSelection();
32
+ if (isTinyLasso(vertices)) {
33
+ const to = shiftHeld ? from : [];
34
+ return [ops.setSelection({
35
+ from,
36
+ to
37
+ })];
38
+ }
39
+ const hits = adapter.hitTestLasso(vertices, mode);
40
+ const to = selectionFromHits(from, hits, shiftHeld);
41
+ return [ops.setSelection({
42
+ from,
43
+ to
44
+ })];
45
+ }
46
+ };
47
+ }
48
+ function polygonAabbArea(vertices) {
49
+ if (vertices.length === 0) return 0;
50
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
51
+ for (const v of vertices) {
52
+ if (v.x < minX) minX = v.x;
53
+ if (v.y < minY) minY = v.y;
54
+ if (v.x > maxX) maxX = v.x;
55
+ if (v.y > maxY) maxY = v.y;
56
+ }
57
+ return (maxX - minX) * (maxY - minY);
58
+ }
59
+
60
+ export { LASSO_VERTICES, isTinyLasso, selectFromLasso };
61
+ //# sourceMappingURL=selectFromLasso.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectFromLasso.js","names":[],"sources":["../../../../src/actions/lassoSelect/behaviors/selectFromLasso.ts"],"sourcesContent":["import type { Op, NodeId } from '@weasel-js/core';\nimport type {\n LassoHitMode,\n LassoSelectAdapter,\n} from '@weasel-js/core/engine';\nimport type { LassoSelectBehavior } from '@weasel-js/core/engine';\nimport { scratchKey, getScratch } from '@weasel-js/routing';\nimport { selectionFromHits } from '@weasel-js/core';\nimport * as ops from '@weasel-js/core/ops';\n\n/** Typed scratch slot the lasso tool's gesture writes into for this behavior\n * to consume. Shared identity: tools producing the polygon for a lasso\n * selection write under this same key. */\nexport const LASSO_VERTICES = scratchKey<ReadonlyArray<{ x: number; y: number }>>('lassoSelect.vertices');\n\nconst MIN_AREA = 4;\n\n/** Whether a lasso through `vertices` is too small to enclose anything, so it reads as a click: fewer than\n * three vertices, or a box under 4 world px². */\nexport function isTinyLasso(vertices: ReadonlyArray<{ x: number; y: number }>): boolean {\n return vertices.length < 3 || polygonAabbArea(vertices) < MIN_AREA;\n}\n\n/** Options for `selectFromLasso`. */\nexport interface SelectFromLassoOptions {\n /** Hit mode for `hitTestLasso`. Default 'intersect'. */\n mode?: LassoHitMode;\n}\n\n/** A lasso behavior (`useLassoTool({ behaviors })`): replace selection with\n * polygon hits in its own `mode`, or extend the existing selection when shift\n * is held at gesture start. Tiny / degenerate lassos behave like a click —\n * clear (or preserve, with shift). Hits come from the gesture adapter's\n * `hitTestLasso`, which under `lassoSelectAction` is the `lassoSelect` dep. */\nexport function selectFromLasso(opts?: SelectFromLassoOptions): LassoSelectBehavior {\n const mode: LassoHitMode = opts?.mode ?? 'intersect';\n return {\n defaultTransient: true,\n onEnd(ctx) {\n const adapter = ctx.adapter as unknown as LassoSelectAdapter;\n if (!adapter.getSelection || !adapter.hitTestLasso) return null;\n\n const vertices = getScratch(ctx.scratch, LASSO_VERTICES) ?? [];\n const startPose = ctx.origin.get('gesture');\n const shiftHeld = startPose ? (startPose as { shiftHeld?: boolean }).shiftHeld === true : false;\n const from = adapter.getSelection();\n\n // Tiny / degenerate lassos behave like a click: clear (or preserve on shift).\n if (isTinyLasso(vertices)) {\n const to = shiftHeld ? from : [];\n const op: Op = ops.setSelection({ from: from as NodeId[], to: to as NodeId[] });\n return [op];\n }\n\n const hits = adapter.hitTestLasso(vertices, mode);\n const to = selectionFromHits(from, hits, shiftHeld);\n const op: Op = ops.setSelection({ from: from as NodeId[], to: to as NodeId[] });\n return [op];\n },\n };\n}\n\nfunction polygonAabbArea(vertices: ReadonlyArray<{ x: number; y: number }>): number {\n if (vertices.length === 0) return 0;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const v of vertices) {\n if (v.x < minX) minX = v.x;\n if (v.y < minY) minY = v.y;\n if (v.x > maxX) maxX = v.x;\n if (v.y > maxY) maxY = v.y;\n }\n return (maxX - minX) * (maxY - minY);\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,iBAAiB,WAAoD,sBAAsB;AAExG,IAAM,WAAW;;;AAIjB,SAAgB,YAAY,UAA4D;CACtF,OAAO,SAAS,SAAS,KAAK,gBAAgB,QAAQ,IAAI;AAC5D;;;;;;AAaA,SAAgB,gBAAgB,MAAoD;CAClF,MAAM,OAAqB,MAAM,QAAQ;CACzC,OAAO;EACL,kBAAkB;EAClB,MAAM,KAAK;GACT,MAAM,UAAU,IAAI;GACpB,IAAI,CAAC,QAAQ,gBAAgB,CAAC,QAAQ,cAAc,OAAO;GAE3D,MAAM,WAAW,WAAW,IAAI,SAAS,cAAc,KAAK,CAAC;GAC7D,MAAM,YAAY,IAAI,OAAO,IAAI,SAAS;GAC1C,MAAM,YAAY,YAAa,UAAsC,cAAc,OAAO;GAC1F,MAAM,OAAO,QAAQ,aAAa;GAGlC,IAAI,YAAY,QAAQ,GAAG;IACzB,MAAM,KAAK,YAAY,OAAO,CAAC;IAE/B,OAAO,CADQ,IAAI,aAAa;KAAQ;KAAsB;IAAe,CACrE,CAAE;GACZ;GAEA,MAAM,OAAO,QAAQ,aAAa,UAAU,IAAI;GAChD,MAAM,KAAK,kBAAkB,MAAM,MAAM,SAAS;GAElD,OAAO,CADQ,IAAI,aAAa;IAAQ;IAAsB;GAAe,CACrE,CAAE;EACZ;CACF;AACF;AAEA,SAAS,gBAAgB,UAA2D;CAClF,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,IAAI,OAAO,UAAU,OAAO,UAAU,OAAO,WAAW,OAAO;CAC/D,KAAK,MAAM,KAAK,UAAU;EACxB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;CAC3B;CACA,QAAQ,OAAO,SAAS,OAAO;AACjC"}
@@ -0,0 +1,20 @@
1
+ import { writtenBy } from "@weasel-js/core";
2
+ import { ActionDisabledReason } from "@weasel-js/routing";
3
+
4
+ // src/actions/lockedWrites.ts
5
+ /** Whether committing `ops` would write the pose or data of a locked node, which the scene's lock guard refuses:
6
+ * an envelope moves, turns, or mirrors by rewriting its sources, and one of them may be locked. */
7
+ function writesLocked(scene, ops) {
8
+ if (ops.length === 0 || typeof scene.isLocked !== "function") return false;
9
+ const written = writtenBy(scene, ops);
10
+ return written !== null && [...written.keys()].some((id) => scene.isLocked(id));
11
+ }
12
+ /** `enabled`'s answer for a command that would commit `ops` (ruled 2026-11-09 and 2026-11-10): not applicable when
13
+ * they change nothing, locked when they would rewrite a locked node. */
14
+ function opsAnswer(scene, ops) {
15
+ if (ops.length === 0) return ActionDisabledReason.NotApplicable;
16
+ return writesLocked(scene, ops) ? ActionDisabledReason.Locked : true;
17
+ }
18
+
19
+ export { opsAnswer, writesLocked };
20
+ //# sourceMappingURL=lockedWrites.js.map