@weasel-js/editing 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -2
  3. package/dist/actionGroups.js +27 -0
  4. package/dist/actionGroups.js.map +1 -0
  5. package/dist/actions/align/action.js +105 -0
  6. package/dist/actions/align/action.js.map +1 -0
  7. package/dist/actions/align/align.js +115 -0
  8. package/dist/actions/align/align.js.map +1 -0
  9. package/dist/actions/clipboard/action.js +133 -0
  10. package/dist/actions/clipboard/action.js.map +1 -0
  11. package/dist/actions/clone/action.js +217 -0
  12. package/dist/actions/clone/action.js.map +1 -0
  13. package/dist/actions/clone/behaviors.js +65 -0
  14. package/dist/actions/clone/behaviors.js.map +1 -0
  15. package/dist/actions/delete/delete.js +123 -0
  16. package/dist/actions/delete/delete.js.map +1 -0
  17. package/dist/actions/derivedBox.js +16 -0
  18. package/dist/actions/derivedBox.js.map +1 -0
  19. package/dist/actions/distribute/action.js +96 -0
  20. package/dist/actions/distribute/action.js.map +1 -0
  21. package/dist/actions/distribute/distribute.js +61 -0
  22. package/dist/actions/distribute/distribute.js.map +1 -0
  23. package/dist/actions/distribute/plan.js +55 -0
  24. package/dist/actions/distribute/plan.js.map +1 -0
  25. package/dist/actions/edit/createPaintAction.js +138 -0
  26. package/dist/actions/edit/createPaintAction.js.map +1 -0
  27. package/dist/actions/edit/deselect.js +34 -0
  28. package/dist/actions/edit/deselect.js.map +1 -0
  29. package/dist/actions/edit/duplicate.js +93 -0
  30. package/dist/actions/edit/duplicate.js.map +1 -0
  31. package/dist/actions/edit/group.js +281 -0
  32. package/dist/actions/edit/group.js.map +1 -0
  33. package/dist/actions/edit/ingest.js +114 -0
  34. package/dist/actions/edit/ingest.js.map +1 -0
  35. package/dist/actions/edit/nudge.js +97 -0
  36. package/dist/actions/edit/nudge.js.map +1 -0
  37. package/dist/actions/edit/selectAll.js +48 -0
  38. package/dist/actions/edit/selectAll.js.map +1 -0
  39. package/dist/actions/edit/setFill.js +52 -0
  40. package/dist/actions/edit/setFill.js.map +1 -0
  41. package/dist/actions/edit/setFillOpacity.js +26 -0
  42. package/dist/actions/edit/setFillOpacity.js.map +1 -0
  43. package/dist/actions/edit/setStroke.js +57 -0
  44. package/dist/actions/edit/setStroke.js.map +1 -0
  45. package/dist/actions/edit/setStrokeOpacity.js +28 -0
  46. package/dist/actions/edit/setStrokeOpacity.js.map +1 -0
  47. package/dist/actions/edit/setStrokeWidth.js +53 -0
  48. package/dist/actions/edit/setStrokeWidth.js.map +1 -0
  49. package/dist/actions/edit/setVertexColor.js +45 -0
  50. package/dist/actions/edit/setVertexColor.js.map +1 -0
  51. package/dist/actions/flip/action.js +209 -0
  52. package/dist/actions/flip/action.js.map +1 -0
  53. package/dist/actions/flip/helpers.js +80 -0
  54. package/dist/actions/flip/helpers.js.map +1 -0
  55. package/dist/actions/group/enterGroup.js +81 -0
  56. package/dist/actions/group/enterGroup.js.map +1 -0
  57. package/dist/actions/insert/action.js +152 -0
  58. package/dist/actions/insert/action.js.map +1 -0
  59. package/dist/actions/insert/commit.js +52 -0
  60. package/dist/actions/insert/commit.js.map +1 -0
  61. package/dist/actions/insert/extras.js +88 -0
  62. package/dist/actions/insert/extras.js.map +1 -0
  63. package/dist/actions/insert/frame.js +96 -0
  64. package/dist/actions/insert/frame.js.map +1 -0
  65. package/dist/actions/insert/geometry.js +35 -0
  66. package/dist/actions/insert/geometry.js.map +1 -0
  67. package/dist/actions/insert/lands.js +41 -0
  68. package/dist/actions/insert/lands.js.map +1 -0
  69. package/dist/actions/insert/params.js +42 -0
  70. package/dist/actions/insert/params.js.map +1 -0
  71. package/dist/actions/insert/placeAction.js +137 -0
  72. package/dist/actions/insert/placeAction.js.map +1 -0
  73. package/dist/actions/insert/repositionAction.js +47 -0
  74. package/dist/actions/insert/repositionAction.js.map +1 -0
  75. package/dist/actions/insert/rotateAction.js +34 -0
  76. package/dist/actions/insert/rotateAction.js.map +1 -0
  77. package/dist/actions/insert/session.js +99 -0
  78. package/dist/actions/insert/session.js.map +1 -0
  79. package/dist/actions/insert/shape.js +117 -0
  80. package/dist/actions/insert/shape.js.map +1 -0
  81. package/dist/actions/insert/style.js +23 -0
  82. package/dist/actions/insert/style.js.map +1 -0
  83. package/dist/actions/lassoSelect/action.js +201 -0
  84. package/dist/actions/lassoSelect/action.js.map +1 -0
  85. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
  86. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
  87. package/dist/actions/lockedWrites.js +20 -0
  88. package/dist/actions/lockedWrites.js.map +1 -0
  89. package/dist/actions/move/action.js +138 -0
  90. package/dist/actions/move/action.js.map +1 -0
  91. package/dist/actions/move/behaviors/clampMove.js +42 -0
  92. package/dist/actions/move/behaviors/clampMove.js.map +1 -0
  93. package/dist/actions/move/behaviors/layoutDrop.js +84 -0
  94. package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
  95. package/dist/actions/move/behaviors/pageDrop.js +30 -0
  96. package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
  97. package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
  98. package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
  99. package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
  100. package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
  101. package/dist/actions/move/behaviors/snapToContainer.js +214 -0
  102. package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
  103. package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
  104. package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
  105. package/dist/actions/move/capture.js +116 -0
  106. package/dist/actions/move/capture.js.map +1 -0
  107. package/dist/actions/move/commit/index.js +47 -0
  108. package/dist/actions/move/commit/index.js.map +1 -0
  109. package/dist/actions/move/commit/layoutDrop.js +68 -0
  110. package/dist/actions/move/commit/layoutDrop.js.map +1 -0
  111. package/dist/actions/move/commit/layoutRelease.js +146 -0
  112. package/dist/actions/move/commit/layoutRelease.js.map +1 -0
  113. package/dist/actions/move/commit/pageDrop.js +162 -0
  114. package/dist/actions/move/commit/pageDrop.js.map +1 -0
  115. package/dist/actions/move/commit/rebase.js +24 -0
  116. package/dist/actions/move/commit/rebase.js.map +1 -0
  117. package/dist/actions/move/commit/reparent.js +157 -0
  118. package/dist/actions/move/commit/reparent.js.map +1 -0
  119. package/dist/actions/move/delta.js +127 -0
  120. package/dist/actions/move/delta.js.map +1 -0
  121. package/dist/actions/move/dragSnap.js +55 -0
  122. package/dist/actions/move/dragSnap.js.map +1 -0
  123. package/dist/actions/move/frame.js +67 -0
  124. package/dist/actions/move/frame.js.map +1 -0
  125. package/dist/actions/move/gestureAdapter.js +36 -0
  126. package/dist/actions/move/gestureAdapter.js.map +1 -0
  127. package/dist/actions/move/landedDescendants.js +50 -0
  128. package/dist/actions/move/landedDescendants.js.map +1 -0
  129. package/dist/actions/move/layout/container.js +119 -0
  130. package/dist/actions/move/layout/container.js.map +1 -0
  131. package/dist/actions/move/layout/dragged.js +75 -0
  132. package/dist/actions/move/layout/dragged.js.map +1 -0
  133. package/dist/actions/move/layout/dropPass.js +205 -0
  134. package/dist/actions/move/layout/dropPass.js.map +1 -0
  135. package/dist/actions/move/layout/exits.js +62 -0
  136. package/dist/actions/move/layout/exits.js.map +1 -0
  137. package/dist/actions/move/layout/glide.js +70 -0
  138. package/dist/actions/move/layout/glide.js.map +1 -0
  139. package/dist/actions/move/layout/view.js +60 -0
  140. package/dist/actions/move/layout/view.js.map +1 -0
  141. package/dist/actions/move/refusal.js +49 -0
  142. package/dist/actions/move/refusal.js.map +1 -0
  143. package/dist/actions/move/session.js +105 -0
  144. package/dist/actions/move/session.js.map +1 -0
  145. package/dist/actions/move/sessionOf.js +27 -0
  146. package/dist/actions/move/sessionOf.js.map +1 -0
  147. package/dist/actions/move/translate.js +49 -0
  148. package/dist/actions/move/translate.js.map +1 -0
  149. package/dist/actions/pathfinder/action.js +109 -0
  150. package/dist/actions/pathfinder/action.js.map +1 -0
  151. package/dist/actions/pathfinder/booleanGroupAction.js +117 -0
  152. package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -0
  153. package/dist/actions/pathfinder/keymap.js +51 -0
  154. package/dist/actions/pathfinder/keymap.js.map +1 -0
  155. package/dist/actions/reorder/reorder.js +245 -0
  156. package/dist/actions/reorder/reorder.js.map +1 -0
  157. package/dist/actions/resize/action.js +105 -0
  158. package/dist/actions/resize/action.js.map +1 -0
  159. package/dist/actions/resize/aspect.js +42 -0
  160. package/dist/actions/resize/aspect.js.map +1 -0
  161. package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
  162. package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
  163. package/dist/actions/resize/boxFrame.js +19 -0
  164. package/dist/actions/resize/boxFrame.js.map +1 -0
  165. package/dist/actions/resize/capture.js +121 -0
  166. package/dist/actions/resize/capture.js.map +1 -0
  167. package/dist/actions/resize/commit.js +104 -0
  168. package/dist/actions/resize/commit.js.map +1 -0
  169. package/dist/actions/resize/frame.js +171 -0
  170. package/dist/actions/resize/frame.js.map +1 -0
  171. package/dist/actions/resize/held.js +44 -0
  172. package/dist/actions/resize/held.js.map +1 -0
  173. package/dist/actions/resize/minimum.js +34 -0
  174. package/dist/actions/resize/minimum.js.map +1 -0
  175. package/dist/actions/resize/replay.js +58 -0
  176. package/dist/actions/resize/replay.js.map +1 -0
  177. package/dist/actions/resize/ruleBounds.js +11 -0
  178. package/dist/actions/resize/ruleBounds.js.map +1 -0
  179. package/dist/actions/resize/session.js +118 -0
  180. package/dist/actions/resize/session.js.map +1 -0
  181. package/dist/actions/rotate/action.js +99 -0
  182. package/dist/actions/rotate/action.js.map +1 -0
  183. package/dist/actions/rotate/commit.js +48 -0
  184. package/dist/actions/rotate/commit.js.map +1 -0
  185. package/dist/actions/rotate/frame.js +96 -0
  186. package/dist/actions/rotate/frame.js.map +1 -0
  187. package/dist/actions/rotate/replay.js +25 -0
  188. package/dist/actions/rotate/replay.js.map +1 -0
  189. package/dist/actions/rotate/session.js +135 -0
  190. package/dist/actions/rotate/session.js.map +1 -0
  191. package/dist/actions/select/areaSelect.js +83 -0
  192. package/dist/actions/select/areaSelect.js.map +1 -0
  193. package/dist/actions/select/clearSelection.js +33 -0
  194. package/dist/actions/select/clearSelection.js.map +1 -0
  195. package/dist/actions/swap/action.js +63 -0
  196. package/dist/actions/swap/action.js.map +1 -0
  197. package/dist/actions/swap/swapOps.js +160 -0
  198. package/dist/actions/swap/swapOps.js.map +1 -0
  199. package/dist/actions/transformAgain/action.js +90 -0
  200. package/dist/actions/transformAgain/action.js.map +1 -0
  201. package/dist/actions/transformAgain/transformSelection.js +49 -0
  202. package/dist/actions/transformAgain/transformSelection.js.map +1 -0
  203. package/dist/booleans/booleans.js +130 -0
  204. package/dist/booleans/booleans.js.map +1 -0
  205. package/dist/booleans/commit.js +45 -0
  206. package/dist/booleans/commit.js.map +1 -0
  207. package/dist/booleans/custom.js +48 -0
  208. package/dist/booleans/custom.js.map +1 -0
  209. package/dist/booleans/operands.js +50 -0
  210. package/dist/booleans/operands.js.map +1 -0
  211. package/dist/booleans/pieces.js +43 -0
  212. package/dist/booleans/pieces.js.map +1 -0
  213. package/dist/booleans/placement.js +37 -0
  214. package/dist/booleans/placement.js.map +1 -0
  215. package/dist/booleans/useBooleans.js +34 -0
  216. package/dist/booleans/useBooleans.js.map +1 -0
  217. package/dist/booleans/useBooleansAdapter.js +11 -0
  218. package/dist/booleans/useBooleansAdapter.js.map +1 -0
  219. package/dist/chrome/affordances/cornerResize.js +123 -0
  220. package/dist/chrome/affordances/cornerResize.js.map +1 -0
  221. package/dist/chrome/affordances/rotateCursor.js +17 -0
  222. package/dist/chrome/affordances/rotateCursor.js.map +1 -0
  223. package/dist/chrome/affordances/rotationHandle.js +117 -0
  224. package/dist/chrome/affordances/rotationHandle.js.map +1 -0
  225. package/dist/chrome/handleCommands.js +110 -0
  226. package/dist/chrome/handleCommands.js.map +1 -0
  227. package/dist/chrome/overlay.js +271 -0
  228. package/dist/chrome/overlay.js.map +1 -0
  229. package/dist/chrome/rotationBadge.js +132 -0
  230. package/dist/chrome/rotationBadge.js.map +1 -0
  231. package/dist/chrome/rotationHandleGeometry.js +49 -0
  232. package/dist/chrome/rotationHandleGeometry.js.map +1 -0
  233. package/dist/chrome/selectionChrome.js +25 -0
  234. package/dist/chrome/selectionChrome.js.map +1 -0
  235. package/dist/chrome/selectionPose.js +112 -0
  236. package/dist/chrome/selectionPose.js.map +1 -0
  237. package/dist/chrome/shapeOutline.js +137 -0
  238. package/dist/chrome/shapeOutline.js.map +1 -0
  239. package/dist/clipboard/clipboardOps.js +48 -0
  240. package/dist/clipboard/clipboardOps.js.map +1 -0
  241. package/dist/clipboard/materializePaste.js +34 -0
  242. package/dist/clipboard/materializePaste.js.map +1 -0
  243. package/dist/clipboard/osClipboard.js +67 -0
  244. package/dist/clipboard/osClipboard.js.map +1 -0
  245. package/dist/clipboard/useClipboard.js +64 -0
  246. package/dist/clipboard/useClipboard.js.map +1 -0
  247. package/dist/clipboard/wireFormat.js +108 -0
  248. package/dist/clipboard/wireFormat.js.map +1 -0
  249. package/dist/deps/areaSelect.js +42 -0
  250. package/dist/deps/areaSelect.js.map +1 -0
  251. package/dist/deps/booleans.js +99 -0
  252. package/dist/deps/booleans.js.map +1 -0
  253. package/dist/deps/insert.js +260 -0
  254. package/dist/deps/insert.js.map +1 -0
  255. package/dist/deps/lassoSelect.js +37 -0
  256. package/dist/deps/lassoSelect.js.map +1 -0
  257. package/dist/deps/presetDeps.js +40 -0
  258. package/dist/deps/presetDeps.js.map +1 -0
  259. package/dist/deps/resizePolicy.js +41 -0
  260. package/dist/deps/resizePolicy.js.map +1 -0
  261. package/dist/engine-BV9RDHOL.d.ts +339 -0
  262. package/dist/engine.d.ts +6 -0
  263. package/dist/engine.js +10 -0
  264. package/dist/engineStandardActions.js +54 -0
  265. package/dist/engineStandardActions.js.map +1 -0
  266. package/dist/groups.d.ts +27 -0
  267. package/dist/groups.js +4 -0
  268. package/dist/icons.gen.js +8 -0
  269. package/dist/icons.gen.js.map +1 -0
  270. package/dist/icons.table.d.ts +6 -0
  271. package/dist/icons.table.js +8 -0
  272. package/dist/icons.table.js.map +1 -0
  273. package/dist/icons.table.json +156 -0
  274. package/dist/icons2.table.js +163 -0
  275. package/dist/icons2.table.js.map +1 -0
  276. package/dist/index.d.ts +1867 -0
  277. package/dist/index.js +86 -0
  278. package/dist/ingest/ghost.js +58 -0
  279. package/dist/ingest/ghost.js.map +1 -0
  280. package/dist/ingest/imageHandler.js +80 -0
  281. package/dist/ingest/imageHandler.js.map +1 -0
  282. package/dist/ingest/kitHandlers.js +15 -0
  283. package/dist/ingest/kitHandlers.js.map +1 -0
  284. package/dist/ingest/svgHandler.js +97 -0
  285. package/dist/ingest/svgHandler.js.map +1 -0
  286. package/dist/ingest/weaselJsonHandler.js +68 -0
  287. package/dist/ingest/weaselJsonHandler.js.map +1 -0
  288. package/dist/namedPresets.js +83 -0
  289. package/dist/namedPresets.js.map +1 -0
  290. package/dist/presets/arrange.js +65 -0
  291. package/dist/presets/arrange.js.map +1 -0
  292. package/dist/presets/booleans.js +13 -0
  293. package/dist/presets/booleans.js.map +1 -0
  294. package/dist/presets/composites.js +46 -0
  295. package/dist/presets/composites.js.map +1 -0
  296. package/dist/presets/edit.js +125 -0
  297. package/dist/presets/edit.js.map +1 -0
  298. package/dist/presets/ingest.js +17 -0
  299. package/dist/presets/ingest.js.map +1 -0
  300. package/dist/presets/insert.js +28 -0
  301. package/dist/presets/insert.js.map +1 -0
  302. package/dist/presets/pathfinder.js +26 -0
  303. package/dist/presets/pathfinder.js.map +1 -0
  304. package/dist/presets/select.js +31 -0
  305. package/dist/presets/select.js.map +1 -0
  306. package/dist/presets/selection.js +13 -0
  307. package/dist/presets/selection.js.map +1 -0
  308. package/dist/presets/selectionChrome.js +15 -0
  309. package/dist/presets/selectionChrome.js.map +1 -0
  310. package/dist/presets/tools.js +84 -0
  311. package/dist/presets/tools.js.map +1 -0
  312. package/dist/presets/transform.js +52 -0
  313. package/dist/presets/transform.js.map +1 -0
  314. package/dist/presets.d.ts +104 -0
  315. package/dist/presets.js +15 -0
  316. package/dist/selection/useSelection.js +127 -0
  317. package/dist/selection/useSelection.js.map +1 -0
  318. package/dist/test-seams.d.ts +50 -0
  319. package/dist/test-seams.js +4 -0
  320. package/dist/tools/ellipse/useEllipseTool.js +72 -0
  321. package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
  322. package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
  323. package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
  324. package/dist/tools/image/useImageTool.js +57 -0
  325. package/dist/tools/image/useImageTool.js.map +1 -0
  326. package/dist/tools/lasso/useLassoTool.js +96 -0
  327. package/dist/tools/lasso/useLassoTool.js.map +1 -0
  328. package/dist/tools/line/useLineTool.js +67 -0
  329. package/dist/tools/line/useLineTool.js.map +1 -0
  330. package/dist/tools/polygon/usePolygonTool.js +149 -0
  331. package/dist/tools/polygon/usePolygonTool.js.map +1 -0
  332. package/dist/tools/rect/useRectTool.js +74 -0
  333. package/dist/tools/rect/useRectTool.js.map +1 -0
  334. package/dist/tools/select/adapterPointQuery.js +56 -0
  335. package/dist/tools/select/adapterPointQuery.js.map +1 -0
  336. package/dist/tools/select/collapseDeferred.js +35 -0
  337. package/dist/tools/select/collapseDeferred.js.map +1 -0
  338. package/dist/tools/select/extendPressLocked.js +17 -0
  339. package/dist/tools/select/extendPressLocked.js.map +1 -0
  340. package/dist/tools/select/groupEntry.js +73 -0
  341. package/dist/tools/select/groupEntry.js.map +1 -0
  342. package/dist/tools/select/pressDecision.js +39 -0
  343. package/dist/tools/select/pressDecision.js.map +1 -0
  344. package/dist/tools/select/selectDeep.js +39 -0
  345. package/dist/tools/select/selectDeep.js.map +1 -0
  346. package/dist/tools/select/selectPick.js +60 -0
  347. package/dist/tools/select/selectPick.js.map +1 -0
  348. package/dist/tools/select/selectionContributions.js +191 -0
  349. package/dist/tools/select/selectionContributions.js.map +1 -0
  350. package/dist/tools/select/usePickerSelectTool.js +145 -0
  351. package/dist/tools/select/usePickerSelectTool.js.map +1 -0
  352. package/dist/tools/select/useSelectTool.js +54 -0
  353. package/dist/tools/select/useSelectTool.js.map +1 -0
  354. package/dist/tools/shared/countOption.js +24 -0
  355. package/dist/tools/shared/countOption.js.map +1 -0
  356. package/dist/tools/shared/insertToolOptions.js +8 -0
  357. package/dist/tools/shared/insertToolOptions.js.map +1 -0
  358. package/dist/tools/shared/pointerFollower.js +23 -0
  359. package/dist/tools/shared/pointerFollower.js.map +1 -0
  360. package/dist/tools/shared/styleOptions.js +76 -0
  361. package/dist/tools/shared/styleOptions.js.map +1 -0
  362. package/dist/tools/star/useStarTool.js +149 -0
  363. package/dist/tools/star/useStarTool.js.map +1 -0
  364. package/dist/tools/toolSets.js +26 -0
  365. package/dist/tools/toolSets.js.map +1 -0
  366. package/dist/useStandardActions.js +26 -0
  367. package/dist/useStandardActions.js.map +1 -0
  368. package/package.json +87 -4
@@ -0,0 +1,96 @@
1
+ import { effectiveOriginMode, insertRectFor } from "./geometry.js";
2
+ import { GESTURE_KEY } from "./session.js";
3
+ import { pointerStateOf } from "@weasel-js/core";
4
+ import { resolveParams } from "@weasel-js/routing";
5
+ import { snapMods } from "@weasel-js/core/engine";
6
+
7
+ // src/actions/insert/frame.ts
8
+ /**
9
+ * Shape the raw pointer into the drag's endpoints: the snap session (with
10
+ * the line kind's Shift step as its input subspace, about the snapped
11
+ * start), then each behavior's `onMove`, each seeing the points the one
12
+ * before it returned. A point a snap target holds is not moved by a
13
+ * behavior.
14
+ */
15
+ function shapeEndpoints(session, readers, raw, moveCtx) {
16
+ const gctx = session.gestureCtx;
17
+ let start = gctx.origin.get(GESTURE_KEY);
18
+ const end = session.snap.end(raw.pointer, snapMods(moveCtx));
19
+ let current = end.point;
20
+ if (session.behaviors.length > 0) {
21
+ const resolved = resolveParams(session.opts?.params);
22
+ const startHeld = session.snap.startHeld();
23
+ gctx.modifiers = { ...moveCtx.modifiers };
24
+ gctx.pointer = pointerStateOf(raw.pointer, moveCtx);
25
+ gctx.view = readers.view();
26
+ gctx.plane = readers.plane();
27
+ gctx.current.set(GESTURE_KEY, current);
28
+ const mode = effectiveOriginMode(resolved?.["originMode"], raw.altHeld);
29
+ let shapedEnd = false;
30
+ for (const b of session.behaviors) {
31
+ const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);
32
+ const r = b.onMove?.(gctx, {
33
+ start,
34
+ current,
35
+ bounds,
36
+ pose: bounds
37
+ });
38
+ if (!r) continue;
39
+ if (r.start && !startHeld) start = r.start;
40
+ if (r.current && !end.held) {
41
+ current = r.current;
42
+ shapedEnd = true;
43
+ }
44
+ }
45
+ if (!shapedEnd && session.snap.anchor(start)) current = session.snap.end(raw.pointer, snapMods(moveCtx)).point;
46
+ gctx.current.set(GESTURE_KEY, current);
47
+ }
48
+ return {
49
+ start,
50
+ current
51
+ };
52
+ }
53
+ /** Move the drag's start point by the pointer's step from `from` to `to`, so
54
+ * the shape travels with the pointer instead of resizing. The start is
55
+ * carried unsnapped and snapped where it lands, in the container its site
56
+ * is carried into. */
57
+ function carryStart(session, from, to, moveCtx) {
58
+ const dx = to.x - from.x;
59
+ const dy = to.y - from.y;
60
+ const { place } = session;
61
+ place.site = {
62
+ x: place.site.x + dx,
63
+ y: place.site.y + dy
64
+ };
65
+ place.parent = place.parentAt(place.site);
66
+ const landed = session.snap.carry(dx, dy, snapMods(moveCtx));
67
+ const shift = landed.held ? {
68
+ x: 0,
69
+ y: 0
70
+ } : session.startShift;
71
+ const origin = {
72
+ x: landed.point.x + shift.x,
73
+ y: landed.point.y + shift.y
74
+ };
75
+ session.gestureCtx.origin.set(GESTURE_KEY, origin);
76
+ session.snap.anchor(origin);
77
+ }
78
+ /** One pump event's pointer, modifiers, and trail, and the endpoints they
79
+ * shape to. Each behavior's `onMove` runs once per call. */
80
+ function nextFrame(session, readers, prev, moveCtx) {
81
+ const raw = {
82
+ pointer: {
83
+ x: moveCtx.world.x,
84
+ y: moveCtx.world.y
85
+ },
86
+ altHeld: moveCtx.modifiers.alt
87
+ };
88
+ return {
89
+ ...raw,
90
+ points: moveCtx.drag?.points ? moveCtx.drag.points : prev.points,
91
+ shaped: shapeEndpoints(session, readers, raw, moveCtx)
92
+ };
93
+ }
94
+
95
+ export { carryStart, nextFrame };
96
+ //# sourceMappingURL=frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.js","names":[],"sources":["../../../src/actions/insert/frame.ts"],"sourcesContent":["import type { InvocationCtx } from '@weasel-js/routing';\nimport { pointerStateOf } from '@weasel-js/core';\nimport { resolveParams } from '@weasel-js/routing';\nimport { snapMods } from '@weasel-js/core/engine';\nimport type { GestureReaders } from '@weasel-js/core';\nimport type { InsertPoint } from '@weasel-js/core/engine';\nimport { insertRectFor, effectiveOriginMode } from './geometry';\nimport { GESTURE_KEY, type InsertFrame, type InsertSession } from './session';\n\n/**\n * Shape the raw pointer into the drag's endpoints: the snap session (with\n * the line kind's Shift step as its input subspace, about the snapped\n * start), then each behavior's `onMove`, each seeing the points the one\n * before it returned. A point a snap target holds is not moved by a\n * behavior.\n */\nfunction shapeEndpoints(\n session: Pick<InsertSession, 'opts' | 'snap' | 'behaviors' | 'gestureCtx'>,\n readers: GestureReaders,\n raw: Pick<InsertFrame, 'pointer' | 'altHeld'>,\n moveCtx: Pick<InvocationCtx, 'modifiers' | 'screen' | 'roles'>,\n): { start: InsertPoint; current: InsertPoint } {\n const gctx = session.gestureCtx;\n let start = gctx.origin.get(GESTURE_KEY) as InsertPoint;\n const end = session.snap.end(raw.pointer, snapMods(moveCtx));\n let current = end.point;\n\n if (session.behaviors.length > 0) {\n const resolved = resolveParams(session.opts?.params);\n const startHeld = session.snap.startHeld();\n gctx.modifiers = { ...moveCtx.modifiers };\n gctx.pointer = pointerStateOf(raw.pointer, moveCtx);\n gctx.view = readers.view();\n gctx.plane = readers.plane();\n gctx.current.set(GESTURE_KEY, current);\n const mode = effectiveOriginMode(resolved?.['originMode'], raw.altHeld);\n let shapedEnd = false;\n for (const b of session.behaviors) {\n const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);\n const r = b.onMove?.(gctx, { start, current, bounds, pose: bounds });\n if (!r) continue;\n if (r.start && !startHeld) start = r.start;\n if (r.current && !end.held) { current = r.current; shapedEnd = true; }\n }\n // The end the snap placed turns about the start as drawn, the behaviors' included.\n if (!shapedEnd && session.snap.anchor(start)) current = session.snap.end(raw.pointer, snapMods(moveCtx)).point;\n gctx.current.set(GESTURE_KEY, current);\n }\n return { start, current };\n}\n\n/** Move the drag's start point by the pointer's step from `from` to `to`, so\n * the shape travels with the pointer instead of resizing. The start is\n * carried unsnapped and snapped where it lands, in the container its site\n * is carried into. */\nexport function carryStart(\n session: Pick<InsertSession, 'snap' | 'gestureCtx' | 'place' | 'startShift'>,\n from: InsertPoint,\n to: InsertPoint,\n moveCtx: Pick<InvocationCtx, 'modifiers' | 'roles'>,\n): void {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n // The site travels with the shape, and the container under it is the one the start snaps in.\n const { place } = session;\n place.site = { x: place.site.x + dx, y: place.site.y + dy };\n place.parent = place.parentAt(place.site);\n const landed = session.snap.carry(dx, dy, snapMods(moveCtx));\n // A snap target holds the start where it put it; otherwise the start keeps the behaviors' shaping.\n const shift = landed.held ? { x: 0, y: 0 } : session.startShift;\n const origin = { x: landed.point.x + shift.x, y: landed.point.y + shift.y };\n session.gestureCtx.origin.set(GESTURE_KEY, origin);\n session.snap.anchor(origin);\n}\n\n/** One pump event's pointer, modifiers, and trail, and the endpoints they\n * shape to. Each behavior's `onMove` runs once per call. */\nexport function nextFrame(\n session: InsertSession,\n readers: GestureReaders,\n prev: Pick<InsertFrame, 'points'>,\n moveCtx: InvocationCtx,\n): InsertFrame {\n const raw = {\n pointer: { x: moveCtx.world.x, y: moveCtx.world.y },\n // Each pointermove carries fresh modifier state from the dispatcher;\n // releasing / pressing a key mid-drag takes effect on the next move tick\n // (true modifier-only events don't fire without a cursor change).\n altHeld: moveCtx.modifiers.alt,\n };\n return {\n ...raw,\n // The dispatcher mutates its own per-gesture trail in place but\n // attaches the array reference to each InvocationCtx.drag — keep\n // the latest reference in case the dispatcher swaps it.\n points: moveCtx.drag?.points ? moveCtx.drag.points : prev.points,\n shaped: shapeEndpoints(session, readers, raw, moveCtx),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,eACP,SACA,SACA,KACA,SAC8C;CAC9C,MAAM,OAAO,QAAQ;CACrB,IAAI,QAAQ,KAAK,OAAO,IAAI,WAAW;CACvC,MAAM,MAAM,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,OAAO,CAAC;CAC3D,IAAI,UAAU,IAAI;CAElB,IAAI,QAAQ,UAAU,SAAS,GAAG;EAChC,MAAM,WAAW,cAAc,QAAQ,MAAM,MAAM;EACnD,MAAM,YAAY,QAAQ,KAAK,UAAU;EACzC,KAAK,YAAY,EAAE,GAAG,QAAQ,UAAU;EACxC,KAAK,UAAU,eAAe,IAAI,SAAS,OAAO;EAClD,KAAK,OAAO,QAAQ,KAAK;EACzB,KAAK,QAAQ,QAAQ,MAAM;EAC3B,KAAK,QAAQ,IAAI,aAAa,OAAO;EACrC,MAAM,OAAO,oBAAoB,WAAW,eAAe,IAAI,OAAO;EACtE,IAAI,YAAY;EAChB,KAAK,MAAM,KAAK,QAAQ,WAAW;GACjC,MAAM,SAAS,cAAc,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI;GACzE,MAAM,IAAI,EAAE,SAAS,MAAM;IAAE;IAAO;IAAS;IAAQ,MAAM;GAAO,CAAC;GACnE,IAAI,CAAC,GAAG;GACR,IAAI,EAAE,SAAS,CAAC,WAAW,QAAQ,EAAE;GACrC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM;IAAE,UAAU,EAAE;IAAS,YAAY;GAAM;EACvE;EAEA,IAAI,CAAC,aAAa,QAAQ,KAAK,OAAO,KAAK,GAAG,UAAU,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,OAAO,CAAC,CAAC,CAAC;EACzG,KAAK,QAAQ,IAAI,aAAa,OAAO;CACvC;CACA,OAAO;EAAE;EAAO;CAAQ;AAC1B;;;;;AAMA,SAAgB,WACd,SACA,MACA,IACA,SACM;CACN,MAAM,KAAK,GAAG,IAAI,KAAK;CACvB,MAAM,KAAK,GAAG,IAAI,KAAK;CAEvB,MAAM,EAAE,UAAU;CAClB,MAAM,OAAO;EAAE,GAAG,MAAM,KAAK,IAAI;EAAI,GAAG,MAAM,KAAK,IAAI;CAAG;CAC1D,MAAM,SAAS,MAAM,SAAS,MAAM,IAAI;CACxC,MAAM,SAAS,QAAQ,KAAK,MAAM,IAAI,IAAI,SAAS,OAAO,CAAC;CAE3D,MAAM,QAAQ,OAAO,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE,IAAI,QAAQ;CACrD,MAAM,SAAS;EAAE,GAAG,OAAO,MAAM,IAAI,MAAM;EAAG,GAAG,OAAO,MAAM,IAAI,MAAM;CAAE;CAC1E,QAAQ,WAAW,OAAO,IAAI,aAAa,MAAM;CACjD,QAAQ,KAAK,OAAO,MAAM;AAC5B;;;AAIA,SAAgB,UACd,SACA,SACA,MACA,SACa;CACb,MAAM,MAAM;EACV,SAAS;GAAE,GAAG,QAAQ,MAAM;GAAG,GAAG,QAAQ,MAAM;EAAE;EAIlD,SAAS,QAAQ,UAAU;CAC7B;CACA,OAAO;EACL,GAAG;EAIH,QAAQ,QAAQ,MAAM,SAAS,QAAQ,KAAK,SAAS,KAAK;EAC1D,QAAQ,eAAe,SAAS,SAAS,KAAK,OAAO;CACvD;AACF"}
@@ -0,0 +1,35 @@
1
+ import { rectBetween } from "@weasel-js/geom";
2
+
3
+ // src/actions/insert/geometry.ts
4
+ /** Resolve the effective origin mode from the binding's nominal opt
5
+ * and live Alt state. Alt inverts: `corner` ⇄ `center`. Applies to
6
+ * every shape kind — radial shapes (polygon/star) included; the
7
+ * overlay paints an `anchorPoint` dot at the click so corner mode
8
+ * reads as anchored even though no polygon vertex sits there.
9
+ */
10
+ function effectiveOriginMode(paramsOrigin, altHeld) {
11
+ const nominal = paramsOrigin === "center" ? "center" : "corner";
12
+ if (!altHeld) return nominal;
13
+ return nominal === "center" ? "corner" : "center";
14
+ }
15
+ /** Compute the insert AABB from drag endpoints.
16
+ * - `'corner'` (default): bounds = drag rect (top-left → bottom-right of cursor sweep).
17
+ * - `'center'`: bounds = symmetric AABB anchored on the start point.
18
+ * Used when the tool's Alt-modifier binding passes
19
+ * `originMode: 'center'`. */
20
+ function insertRectFor(startX, startY, currentX, currentY, originMode) {
21
+ if (originMode === "center") {
22
+ const dx = Math.abs(currentX - startX);
23
+ const dy = Math.abs(currentY - startY);
24
+ return {
25
+ x: startX - dx,
26
+ y: startY - dy,
27
+ width: dx * 2,
28
+ height: dy * 2
29
+ };
30
+ }
31
+ return rectBetween(startX, startY, currentX, currentY);
32
+ }
33
+
34
+ export { effectiveOriginMode, insertRectFor };
35
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","names":[],"sources":["../../../src/actions/insert/geometry.ts"],"sourcesContent":["import { rectBetween, type Rect } from '@weasel-js/geom';\n\n/** Resolve the effective origin mode from the binding's nominal opt\n * and live Alt state. Alt inverts: `corner` ⇄ `center`. Applies to\n * every shape kind — radial shapes (polygon/star) included; the\n * overlay paints an `anchorPoint` dot at the click so corner mode\n * reads as anchored even though no polygon vertex sits there.\n */\nexport function effectiveOriginMode(\n paramsOrigin: unknown,\n altHeld: boolean,\n): 'corner' | 'center' {\n const nominal: 'corner' | 'center' = paramsOrigin === 'center' ? 'center' : 'corner';\n if (!altHeld) return nominal;\n return nominal === 'center' ? 'corner' : 'center';\n}\n\n/** Compute the insert AABB from drag endpoints.\n * - `'corner'` (default): bounds = drag rect (top-left → bottom-right of cursor sweep).\n * - `'center'`: bounds = symmetric AABB anchored on the start point.\n * Used when the tool's Alt-modifier binding passes\n * `originMode: 'center'`. */\nexport function insertRectFor(\n startX: number, startY: number,\n currentX: number, currentY: number,\n originMode: 'corner' | 'center',\n): Rect {\n if (originMode === 'center') {\n const dx = Math.abs(currentX - startX);\n const dy = Math.abs(currentY - startY);\n return { x: startX - dx, y: startY - dy, width: dx * 2, height: dy * 2 };\n }\n return rectBetween(startX, startY, currentX, currentY);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,oBACd,cACA,SACqB;CACrB,MAAM,UAA+B,iBAAiB,WAAW,WAAW;CAC5E,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,YAAY,WAAW,WAAW;AAC3C;;;;;;AAOA,SAAgB,cACd,QAAgB,QAChB,UAAkB,UAClB,YACM;CACN,IAAI,eAAe,UAAU;EAC3B,MAAM,KAAK,KAAK,IAAI,WAAW,MAAM;EACrC,MAAM,KAAK,KAAK,IAAI,WAAW,MAAM;EACrC,OAAO;GAAE,GAAG,SAAS;GAAI,GAAG,SAAS;GAAI,OAAO,KAAK;GAAG,QAAQ,KAAK;EAAE;CACzE;CACA,OAAO,YAAY,QAAQ,QAAQ,UAAU,QAAQ;AACvD"}
@@ -0,0 +1,41 @@
1
+ import { outputGridOf, quantizedNodePose } from "@weasel-js/core";
2
+ import { AUTO_POSE_DESCRIPTOR, composeChildFrame as composeChildFrame$1, composesFrames, insertPreviewExtent, sceneViewPoseAdapter } from "@weasel-js/core/engine";
3
+
4
+ // src/actions/insert/lands.ts
5
+ /**
6
+ * Where an insert's shape lands when the scene's quantize rule moves it off
7
+ * the box the drag made, for the preview's `lands`: the node the `insert` dep
8
+ * would make, as `stored` commits it. `undefined` when the rule changes
9
+ * nothing, the scene has no grid, or the dep cannot say what it would make.
10
+ */
11
+ function insertLanding(scene, dep, bounds, extras, ends, parent = null) {
12
+ if (!scene.quantize?.stored || !outputGridOf(scene)) return void 0;
13
+ const node = dep.peek?.(bounds, extras, ends);
14
+ if (!node) return void 0;
15
+ const pose = quantizedNodePose(scene, node);
16
+ if (pose === node.pose) return void 0;
17
+ const world = worldOf(scene, parent);
18
+ const from = AUTO_POSE_DESCRIPTOR.getBounds(world(node.pose));
19
+ const to = AUTO_POSE_DESCRIPTOR.getBounds(world(pose));
20
+ const made = insertPreviewExtent({
21
+ shape: extras.kind,
22
+ bounds,
23
+ extras
24
+ }).bounds;
25
+ return {
26
+ x: made.x + to.x - from.x,
27
+ y: made.y + to.y - from.y,
28
+ width: made.width + to.width - from.width,
29
+ height: made.height + to.height - from.height
30
+ };
31
+ }
32
+ /** A pose stored under `parent`, as the world sees it. */
33
+ function worldOf(scene, parent) {
34
+ const composition = scene.composition;
35
+ if (parent === null || composition === void 0 || !composesFrames(composition)) return (p) => p;
36
+ const frame = composeChildFrame$1(sceneViewPoseAdapter(scene), parent, composition.compose);
37
+ return (p) => composition.compose(frame, p);
38
+ }
39
+
40
+ export { insertLanding };
41
+ //# sourceMappingURL=lands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lands.js","names":["composeChildFrame"],"sources":["../../../src/actions/insert/lands.ts"],"sourcesContent":["import { AUTO_POSE_DESCRIPTOR, composeChildFrame, composesFrames, insertPreviewExtent, sceneViewPoseAdapter } from '@weasel-js/core/engine';\nimport { outputGridOf, quantizedNodePose } from '@weasel-js/core';\nimport type { Scene, InsertDep, InsertEnds, InsertExtras } from '@weasel-js/core/engine';\nimport type { Bounds, NodeId } from '@weasel-js/core';\n\n/**\n * Where an insert's shape lands when the scene's quantize rule moves it off\n * the box the drag made, for the preview's `lands`: the node the `insert` dep\n * would make, as `stored` commits it. `undefined` when the rule changes\n * nothing, the scene has no grid, or the dep cannot say what it would make.\n */\nexport function insertLanding(\n scene: Scene<unknown, string, unknown>,\n dep: Pick<InsertDep, 'peek'>,\n bounds: Bounds,\n extras: InsertExtras,\n ends?: InsertEnds,\n /** The container the node lands in, whose frame its stored pose is in. */\n parent: NodeId | null = null,\n): Bounds | undefined {\n if (!scene.quantize?.stored || !outputGridOf(scene)) return undefined;\n const node = dep.peek?.(bounds, extras, ends);\n if (!node) return undefined;\n const pose = quantizedNodePose(scene, node);\n if (pose === node.pose) return undefined;\n const world = worldOf(scene, parent);\n const from = AUTO_POSE_DESCRIPTOR.getBounds(world(node.pose));\n const to = AUTO_POSE_DESCRIPTOR.getBounds(world(pose));\n const made = insertPreviewExtent({ shape: extras.kind, bounds, extras }).bounds;\n return {\n x: made.x + to.x - from.x,\n y: made.y + to.y - from.y,\n width: made.width + to.width - from.width,\n height: made.height + to.height - from.height,\n };\n}\n\n/** A pose stored under `parent`, as the world sees it. */\nfunction worldOf(scene: Scene<unknown, string, unknown>, parent: NodeId | null): (local: unknown) => unknown {\n const composition = scene.composition;\n if (parent === null || composition === undefined || !composesFrames(composition)) return (p) => p;\n const frame = composeChildFrame(sceneViewPoseAdapter(scene), parent, composition.compose);\n return (p) => composition.compose(frame, p);\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,cACd,OACA,KACA,QACA,QACA,MAEA,SAAwB,MACJ;CACpB,IAAI,CAAC,MAAM,UAAU,UAAU,CAAC,aAAa,KAAK,GAAG,OAAO;CAC5D,MAAM,OAAO,IAAI,OAAO,QAAQ,QAAQ,IAAI;CAC5C,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,OAAO,kBAAkB,OAAO,IAAI;CAC1C,IAAI,SAAS,KAAK,MAAM,OAAO;CAC/B,MAAM,QAAQ,QAAQ,OAAO,MAAM;CACnC,MAAM,OAAO,qBAAqB,UAAU,MAAM,KAAK,IAAI,CAAC;CAC5D,MAAM,KAAK,qBAAqB,UAAU,MAAM,IAAI,CAAC;CACrD,MAAM,OAAO,oBAAoB;EAAE,OAAO,OAAO;EAAM;EAAQ;CAAO,CAAC,CAAC,CAAC;CACzE,OAAO;EACL,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,OAAO,KAAK,QAAQ,GAAG,QAAQ,KAAK;EACpC,QAAQ,KAAK,SAAS,GAAG,SAAS,KAAK;CACzC;AACF;;AAGA,SAAS,QAAQ,OAAwC,QAAoD;CAC3G,MAAM,cAAc,MAAM;CAC1B,IAAI,WAAW,QAAQ,gBAAgB,UAAa,CAAC,eAAe,WAAW,GAAG,QAAQ,MAAM;CAChG,MAAM,QAAQA,oBAAkB,qBAAqB,KAAK,GAAG,QAAQ,YAAY,OAAO;CACxF,QAAQ,MAAM,YAAY,QAAQ,OAAO,CAAC;AAC5C"}
@@ -0,0 +1,42 @@
1
+ import { insertKind } from "./shape.js";
2
+ import { SHAPE_COUNT_RANGE, SHAPE_DEFAULTS, STAR_RATIO_RANGE } from "@weasel-js/core";
3
+ import { pref } from "@weasel-js/prefs-schema";
4
+
5
+ // src/actions/insert/params.ts
6
+ /** A polygon insert's params as a form, for the last-operation panel. */
7
+ var POLYGON_INSERT_PARAMS = pref.group("Polygon", { sides: pref.number("Sides", SHAPE_DEFAULTS.sides, {
8
+ min: SHAPE_COUNT_RANGE.min,
9
+ max: SHAPE_COUNT_RANGE.max,
10
+ step: 1,
11
+ control: "slider"
12
+ }) });
13
+ /** A star insert's params as a form, for the last-operation panel. */
14
+ var STAR_INSERT_PARAMS = pref.group("Star", {
15
+ points: pref.number("Points", SHAPE_DEFAULTS.points, {
16
+ min: SHAPE_COUNT_RANGE.min,
17
+ max: SHAPE_COUNT_RANGE.max,
18
+ step: 1,
19
+ control: "slider"
20
+ }),
21
+ innerRadiusRatio: pref.number("Inner radius", SHAPE_DEFAULTS.innerRadiusRatio, {
22
+ description: "Inner radius as a fraction of the outer one.",
23
+ min: STAR_RATIO_RANGE.min,
24
+ max: STAR_RATIO_RANGE.max,
25
+ step: .01,
26
+ control: "slider",
27
+ unit: {
28
+ scale: .01,
29
+ suffix: "%",
30
+ places: 0
31
+ }
32
+ })
33
+ });
34
+ /** The form an insert of the kind `params` names shows: a polygon's sides, a star's points and inner radius, and
35
+ * none for any other kind. */
36
+ function insertParams(params) {
37
+ const kind = insertKind(params);
38
+ return kind === "polygon" ? POLYGON_INSERT_PARAMS : kind === "star" ? STAR_INSERT_PARAMS : null;
39
+ }
40
+
41
+ export { POLYGON_INSERT_PARAMS, STAR_INSERT_PARAMS, insertParams };
42
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","names":[],"sources":["../../../src/actions/insert/params.ts"],"sourcesContent":["import { pref, type PrefGroup } from '@weasel-js/prefs-schema';\nimport { SHAPE_COUNT_RANGE, SHAPE_DEFAULTS, STAR_RATIO_RANGE } from '@weasel-js/core';\nimport { insertKind } from './shape';\n\n/** A polygon insert's params as a form, for the last-operation panel. */\nexport const POLYGON_INSERT_PARAMS = pref.group('Polygon', {\n sides: pref.number('Sides', SHAPE_DEFAULTS.sides, { min: SHAPE_COUNT_RANGE.min, max: SHAPE_COUNT_RANGE.max, step: 1, control: 'slider' }),\n});\n\n/** A star insert's params as a form, for the last-operation panel. */\nexport const STAR_INSERT_PARAMS = pref.group('Star', {\n points: pref.number('Points', SHAPE_DEFAULTS.points, { min: SHAPE_COUNT_RANGE.min, max: SHAPE_COUNT_RANGE.max, step: 1, control: 'slider' }),\n innerRadiusRatio: pref.number('Inner radius', SHAPE_DEFAULTS.innerRadiusRatio, {\n description: 'Inner radius as a fraction of the outer one.',\n min: STAR_RATIO_RANGE.min, max: STAR_RATIO_RANGE.max, step: 0.01, control: 'slider',\n unit: { scale: 0.01, suffix: '%', places: 0 },\n }),\n});\n\n/** The form an insert of the kind `params` names shows: a polygon's sides, a star's points and inner radius, and\n * none for any other kind. */\nexport function insertParams(params: Readonly<Record<string, unknown>>): PrefGroup | null {\n const kind = insertKind(params);\n return kind === 'polygon' ? POLYGON_INSERT_PARAMS : kind === 'star' ? STAR_INSERT_PARAMS : null;\n}\n"],"mappings":";;;;;;AAKA,IAAa,wBAAwB,KAAK,MAAM,WAAW,EACzD,OAAO,KAAK,OAAO,SAAS,eAAe,OAAO;CAAE,KAAK,kBAAkB;CAAK,KAAK,kBAAkB;CAAK,MAAM;CAAG,SAAS;AAAS,CAAC,EAC1I,CAAC;;AAGD,IAAa,qBAAqB,KAAK,MAAM,QAAQ;CACnD,QAAQ,KAAK,OAAO,UAAU,eAAe,QAAQ;EAAE,KAAK,kBAAkB;EAAK,KAAK,kBAAkB;EAAK,MAAM;EAAG,SAAS;CAAS,CAAC;CAC3I,kBAAkB,KAAK,OAAO,gBAAgB,eAAe,kBAAkB;EAC7E,aAAa;EACb,KAAK,iBAAiB;EAAK,KAAK,iBAAiB;EAAK,MAAM;EAAM,SAAS;EAC3E,MAAM;GAAE,OAAO;GAAM,QAAQ;GAAK,QAAQ;EAAE;CAC9C,CAAC;AACH,CAAC;;;AAID,SAAgB,aAAa,QAA6D;CACxF,MAAM,OAAO,WAAW,MAAM;CAC9B,OAAO,SAAS,YAAY,wBAAwB,SAAS,SAAS,qBAAqB;AAC7F"}
@@ -0,0 +1,137 @@
1
+ import { restoreSelection } from "./commit.js";
2
+ import { insertShape } from "./shape.js";
3
+ import { clearedSelection } from "./session.js";
4
+ import { INSERT_GROUP } from "../../actionGroups.js";
5
+ import { inPlane, insertLayer, insertParent, minSizeOf } from "@weasel-js/core";
6
+ import { defineAction } from "@weasel-js/routing";
7
+ import { SNAP_ROLES, snapMods } from "@weasel-js/core/engine";
8
+
9
+ // src/actions/insert/placeAction.ts
10
+ /** What the dispatcher lays under an immediate action's params for a click. */
11
+ var CLICK_FIELDS = [
12
+ "world",
13
+ "press",
14
+ "affordance",
15
+ "mods",
16
+ "roles"
17
+ ];
18
+ var NO_KEYS = {
19
+ alt: false,
20
+ ctrl: false,
21
+ meta: false,
22
+ shift: false
23
+ };
24
+ /** The keys a click held, and the roles the dispatcher resolved them to (`ImmediateParams`). */
25
+ function clickRoles(params) {
26
+ const p = params;
27
+ return {
28
+ modifiers: p?.mods ?? NO_KEYS,
29
+ ...p?.roles ? { roles: p.roles } : {}
30
+ };
31
+ }
32
+ /**
33
+ * Click-to-insert: the companion to `insertAction` for a click, which draws
34
+ * no box. It commits a node of `params.kind` at `params.size`, centered on the
35
+ * click, snapped through a `point` session of the `snap` dep unless the
36
+ * click held `snap.suspend` (Ctrl), and commits
37
+ * through the same `insert` dep a drag commits through. Its extras are the
38
+ * ones a drag out from the click's center to the size's corner makes
39
+ * (`insertShape`), built from the rest of the binding's params.
40
+ *
41
+ * A `minSize` in the params floors the size, and goes on to the node. Style
42
+ * params (a shape tool's fill, stroke, …) reach the dep as `extras.style`.
43
+ *
44
+ * A binding with no `size` places nothing: the kind's extent is the tool's to
45
+ * name, and a click has none of its own.
46
+ */
47
+ var placeAction = inPlane(defineAction({
48
+ id: "place",
49
+ label: "Place",
50
+ group: INSERT_GROUP,
51
+ eligible: { capability: "creates-shapes" },
52
+ modifierRoles: SNAP_ROLES,
53
+ requires: [
54
+ "insert",
55
+ "insertInto",
56
+ "canDropInto",
57
+ "operands",
58
+ "snap",
59
+ "scene"
60
+ ],
61
+ invoker: {
62
+ timing: "immediate",
63
+ run(deps, params) {
64
+ const dep = deps.insert;
65
+ const asked = params?.size;
66
+ const min = minSizeOf(params);
67
+ const size = asked && min ? {
68
+ width: Math.max(asked.width, min.width),
69
+ height: Math.max(asked.height, min.height)
70
+ } : asked;
71
+ const world = params?.world;
72
+ if (!dep || !size || !world) return;
73
+ const { x, y } = world;
74
+ if (!(size.width > 0 && size.height > 0)) return;
75
+ const prior = deps.operands ? [...deps.operands.get()] : [];
76
+ deps.operands?.set([]);
77
+ let committed = false;
78
+ try {
79
+ const parent = insertParent(deps.scene, deps.insertInto?.get(), deps.canDropInto, {
80
+ x,
81
+ y
82
+ });
83
+ const snap = deps.snap?.begin({
84
+ gesture: "point",
85
+ press: {
86
+ x,
87
+ y
88
+ },
89
+ ...parent === null ? {} : { parent }
90
+ });
91
+ let out;
92
+ try {
93
+ out = snap?.at({
94
+ x,
95
+ y
96
+ }, snapMods(clickRoles(params)));
97
+ } finally {
98
+ snap?.end();
99
+ }
100
+ const at = out ? out.point : {
101
+ x,
102
+ y
103
+ };
104
+ const binding = {
105
+ ...params,
106
+ originMode: "center"
107
+ };
108
+ for (const k of [...CLICK_FIELDS, "size"]) delete binding[k];
109
+ const landing = out?.landing;
110
+ const { bounds, extras, ends } = insertShape(binding, {
111
+ shaped: {
112
+ start: at,
113
+ current: {
114
+ x: at.x + size.width / 2,
115
+ y: at.y + size.height / 2
116
+ }
117
+ },
118
+ altHeld: false
119
+ }, null, 0, (p) => p === at ? landing : void 0, {
120
+ x,
121
+ y
122
+ });
123
+ committed = dep.commit(bounds, extras, ends, clearedSelection(prior)) !== null;
124
+ } finally {
125
+ if (!committed) restoreSelection({
126
+ priorSelection: prior,
127
+ selection: deps.operands
128
+ });
129
+ }
130
+ }
131
+ },
132
+ /** Like `insert`, needs no selection. */
133
+ enabled: () => true
134
+ }), insertLayer);
135
+
136
+ export { placeAction };
137
+ //# sourceMappingURL=placeAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeAction.js","names":[],"sources":["../../../src/actions/insert/placeAction.ts"],"sourcesContent":["import { defineAction, type Action, type ImmediateParams, type ModifierState } from '@weasel-js/routing';\nimport { SNAP_ROLES, snapMods } from '@weasel-js/core/engine';\nimport { inPlane, insertLayer, insertParent, minSizeOf } from '@weasel-js/core';\nimport { restoreSelection } from './commit';\nimport { insertShape } from './shape';\nimport { clearedSelection } from './session';\nimport type {} from '@weasel-js/core';\nimport { INSERT_GROUP } from '../../actionGroups';\n\n/** What the dispatcher lays under an immediate action's params for a click. */\nconst CLICK_FIELDS = ['world', 'press', 'affordance', 'mods', 'roles'] as const;\n\nconst NO_KEYS: ModifierState = { alt: false, ctrl: false, meta: false, shift: false };\n\n/** The keys a click held, and the roles the dispatcher resolved them to (`ImmediateParams`). */\nfunction clickRoles(params: Readonly<Record<string, unknown>> | undefined) {\n const p = params as ImmediateParams | undefined;\n return { modifiers: p?.mods ?? NO_KEYS, ...(p?.roles ? { roles: p.roles } : {}) };\n}\n\n/**\n * Click-to-insert: the companion to `insertAction` for a click, which draws\n * no box. It commits a node of `params.kind` at `params.size`, centered on the\n * click, snapped through a `point` session of the `snap` dep unless the\n * click held `snap.suspend` (Ctrl), and commits\n * through the same `insert` dep a drag commits through. Its extras are the\n * ones a drag out from the click's center to the size's corner makes\n * (`insertShape`), built from the rest of the binding's params.\n *\n * A `minSize` in the params floors the size, and goes on to the node. Style\n * params (a shape tool's fill, stroke, …) reach the dep as `extras.style`.\n *\n * A binding with no `size` places nothing: the kind's extent is the tool's to\n * name, and a click has none of its own.\n */\nexport const placeAction: Action = inPlane(defineAction({\n id: 'place',\n label: 'Place',\n group: INSERT_GROUP,\n eligible: { capability: 'creates-shapes' },\n modifierRoles: SNAP_ROLES,\n requires: ['insert', 'insertInto', 'canDropInto', 'operands', 'snap', 'scene'],\n invoker: {\n timing: 'immediate',\n run(deps, params) {\n const dep = deps.insert;\n const asked = params?.size;\n const min = minSizeOf(params);\n const size = asked && min\n ? { width: Math.max(asked.width, min.width), height: Math.max(asked.height, min.height) }\n : asked;\n const world = params?.world;\n if (!dep || !size || !world) return;\n const { x, y } = world;\n if (!(size.width > 0 && size.height > 0)) return;\n\n const prior = deps.operands ? [...deps.operands.get()] : [];\n deps.operands?.set([]);\n let committed = false;\n try {\n const parent = insertParent(deps.scene, deps.insertInto?.get(), deps.canDropInto, { x, y });\n const snap = deps.snap?.begin({ gesture: 'point', press: { x, y }, ...(parent === null ? {} : { parent }) });\n let out;\n try {\n out = snap?.at({ x, y }, snapMods(clickRoles(params)));\n } finally {\n snap?.end();\n }\n const at = out ? out.point : { x, y };\n const binding: Record<string, unknown> = { ...params, originMode: 'center' };\n for (const k of [...CLICK_FIELDS, 'size']) delete binding[k];\n const landing = out?.landing;\n const { bounds, extras, ends } = insertShape(\n binding,\n { shaped: { start: at, current: { x: at.x + size.width / 2, y: at.y + size.height / 2 } }, altHeld: false },\n null, 0,\n (p) => (p === at ? landing : undefined),\n { x, y },\n );\n committed = dep.commit(bounds, extras, ends, clearedSelection(prior)) !== null;\n } finally {\n if (!committed) restoreSelection({ priorSelection: prior, selection: deps.operands });\n }\n },\n },\n /** Like `insert`, needs no selection. */\n enabled: () => true as const,\n}), insertLayer);\n"],"mappings":";;;;;;;;;;AAUA,IAAM,eAAe;CAAC;CAAS;CAAS;CAAc;CAAQ;AAAO;AAErE,IAAM,UAAyB;CAAE,KAAK;CAAO,MAAM;CAAO,MAAM;CAAO,OAAO;AAAM;;AAGpF,SAAS,WAAW,QAAuD;CACzE,MAAM,IAAI;CACV,OAAO;EAAE,WAAW,GAAG,QAAQ;EAAS,GAAI,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;CAAG;AAClF;;;;;;;;;;;;;;;;AAiBA,IAAa,cAAsB,QAAQ,aAAa;CACtD,IAAI;CACJ,OAAO;CACP,OAAO;CACP,UAAU,EAAE,YAAY,iBAAiB;CACzC,eAAe;CACf,UAAU;EAAC;EAAU;EAAc;EAAe;EAAY;EAAQ;CAAO;CAC7E,SAAS;EACP,QAAQ;EACR,IAAI,MAAM,QAAQ;GAChB,MAAM,MAAM,KAAK;GACjB,MAAM,QAAQ,QAAQ;GACtB,MAAM,MAAM,UAAU,MAAM;GAC5B,MAAM,OAAO,SAAS,MAClB;IAAE,OAAO,KAAK,IAAI,MAAM,OAAO,IAAI,KAAK;IAAG,QAAQ,KAAK,IAAI,MAAM,QAAQ,IAAI,MAAM;GAAE,IACtF;GACJ,MAAM,QAAQ,QAAQ;GACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO;GAC7B,MAAM,EAAE,GAAG,MAAM;GACjB,IAAI,EAAE,KAAK,QAAQ,KAAK,KAAK,SAAS,IAAI;GAE1C,MAAM,QAAQ,KAAK,WAAW,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC;GAC1D,KAAK,UAAU,IAAI,CAAC,CAAC;GACrB,IAAI,YAAY;GAChB,IAAI;IACF,MAAM,SAAS,aAAa,KAAK,OAAO,KAAK,YAAY,IAAI,GAAG,KAAK,aAAa;KAAE;KAAG;IAAE,CAAC;IAC1F,MAAM,OAAO,KAAK,MAAM,MAAM;KAAE,SAAS;KAAS,OAAO;MAAE;MAAG;KAAE;KAAG,GAAI,WAAW,OAAO,CAAC,IAAI,EAAE,OAAO;IAAG,CAAC;IAC3G,IAAI;IACJ,IAAI;KACF,MAAM,MAAM,GAAG;MAAE;MAAG;KAAE,GAAG,SAAS,WAAW,MAAM,CAAC,CAAC;IACvD,UAAU;KACR,MAAM,IAAI;IACZ;IACA,MAAM,KAAK,MAAM,IAAI,QAAQ;KAAE;KAAG;IAAE;IACpC,MAAM,UAAmC;KAAE,GAAG;KAAQ,YAAY;IAAS;IAC3E,KAAK,MAAM,KAAK,CAAC,GAAG,cAAc,MAAM,GAAG,OAAO,QAAQ;IAC1D,MAAM,UAAU,KAAK;IACrB,MAAM,EAAE,QAAQ,QAAQ,SAAS,YAC/B,SACA;KAAE,QAAQ;MAAE,OAAO;MAAI,SAAS;OAAE,GAAG,GAAG,IAAI,KAAK,QAAQ;OAAG,GAAG,GAAG,IAAI,KAAK,SAAS;MAAE;KAAE;KAAG,SAAS;IAAM,GAC1G,MAAM,IACL,MAAO,MAAM,KAAK,UAAU,QAC7B;KAAE;KAAG;IAAE,CACT;IACA,YAAY,IAAI,OAAO,QAAQ,QAAQ,MAAM,iBAAiB,KAAK,CAAC,MAAM;GAC5E,UAAU;IACR,IAAI,CAAC,WAAW,iBAAiB;KAAE,gBAAgB;KAAO,WAAW,KAAK;IAAS,CAAC;GACtF;EACF;CACF;;CAEA,eAAe;AACjB,CAAC,GAAG,WAAW"}
@@ -0,0 +1,47 @@
1
+ import { INSERT_GROUP } from "../../actionGroups.js";
2
+ import { heldKeySpec } from "@weasel-js/routing";
3
+
4
+ // src/actions/insert/repositionAction.ts
5
+ /**
6
+ * Companion to `insertAction`: while its key is held, dragging moves the
7
+ * shape being drawn instead of resizing it; letting go resumes resizing from
8
+ * where the shape now sits. No-op when no insert is in flight.
9
+ */
10
+ var insertRepositionAction = {
11
+ id: "insert.reposition",
12
+ label: "Insert — reposition",
13
+ group: INSERT_GROUP,
14
+ eligible: { capability: "creates-shapes" },
15
+ invoker: {
16
+ timing: "ongoing",
17
+ start: (ctx) => {
18
+ const gesture = ctx.deps.insertLive?.gesture;
19
+ if (!gesture || !gesture.open) return {};
20
+ gesture.repositioning = true;
21
+ return {
22
+ kind: "insert.reposition",
23
+ onEnd: () => {
24
+ gesture.repositioning = false;
25
+ }
26
+ };
27
+ }
28
+ },
29
+ requires: ["insertLive"]
30
+ };
31
+ /**
32
+ * The binding a shape-drawing tool adds so holding Space mid-draw repositions
33
+ * the shape. Gated to the tool's own engaged phase, so Space between drags is
34
+ * left to the offhand hand tool. Shift and Alt may be down with it, so a
35
+ * constrained or from-center draw can be moved without letting go of them.
36
+ */
37
+ var INSERT_REPOSITION_BINDING = {
38
+ spec: {
39
+ ...heldKeySpec(" "),
40
+ phase: "engaged"
41
+ },
42
+ actionId: "insert.reposition",
43
+ opts: { id: "insert.reposition.held" }
44
+ };
45
+
46
+ export { INSERT_REPOSITION_BINDING, insertRepositionAction };
47
+ //# sourceMappingURL=repositionAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositionAction.js","names":[],"sources":["../../../src/actions/insert/repositionAction.ts"],"sourcesContent":["import { heldKeySpec, type Action, type GestureBinding } from '@weasel-js/routing';\nimport type { InsertLiveGesture } from './live';\nimport type {} from '@weasel-js/core';\nimport { INSERT_GROUP } from '../../actionGroups';\n\n/**\n * Companion to `insertAction`: while its key is held, dragging moves the\n * shape being drawn instead of resizing it; letting go resumes resizing from\n * where the shape now sits. No-op when no insert is in flight.\n */\nexport const insertRepositionAction: Action = {\n id: 'insert.reposition',\n label: 'Insert — reposition',\n group: INSERT_GROUP,\n eligible: { capability: 'creates-shapes' },\n invoker: {\n timing: 'ongoing',\n start: (ctx) => {\n const gesture = ctx.deps.insertLive?.gesture as InsertLiveGesture | null | undefined;\n if (!gesture || !gesture.open) return {};\n gesture.repositioning = true;\n return {\n kind: 'insert.reposition',\n onEnd: () => { gesture.repositioning = false; },\n };\n },\n },\n requires: ['insertLive'],\n};\n\n/**\n * The binding a shape-drawing tool adds so holding Space mid-draw repositions\n * the shape. Gated to the tool's own engaged phase, so Space between drags is\n * left to the offhand hand tool. Shift and Alt may be down with it, so a\n * constrained or from-center draw can be moved without letting go of them.\n */\nexport const INSERT_REPOSITION_BINDING: GestureBinding = {\n spec: { ...heldKeySpec(' '), phase: 'engaged' },\n actionId: 'insert.reposition',\n opts: { id: 'insert.reposition.held' },\n};\n"],"mappings":";;;;;;;;;AAUA,IAAa,yBAAiC;CAC5C,IAAI;CACJ,OAAO;CACP,OAAO;CACP,UAAU,EAAE,YAAY,iBAAiB;CACzC,SAAS;EACP,QAAQ;EACR,QAAQ,QAAQ;GACd,MAAM,UAAU,IAAI,KAAK,YAAY;GACrC,IAAI,CAAC,WAAW,CAAC,QAAQ,MAAM,OAAO,CAAC;GACvC,QAAQ,gBAAgB;GACxB,OAAO;IACL,MAAM;IACN,aAAa;KAAE,QAAQ,gBAAgB;IAAO;GAChD;EACF;CACF;CACA,UAAU,CAAC,YAAY;AACzB;;;;;;;AAQA,IAAa,4BAA4C;CACvD,MAAM;EAAE,GAAG,YAAY,GAAG;EAAG,OAAO;CAAU;CAC9C,UAAU;CACV,MAAM,EAAE,IAAI,yBAAyB;AACvC"}
@@ -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"}