@weasel-js/core 1.11.0 → 1.12.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 (586) hide show
  1. package/CHANGELOG.md +611 -0
  2. package/README.md +1 -1
  3. package/dist/WeaselProvider.js +1 -1
  4. package/dist/affordances/pathAnchors.js +10 -6
  5. package/dist/affordances/pathAnchors.js.map +1 -1
  6. package/dist/animation/index.js +3 -3
  7. package/dist/animation/rig/bindRig.js +1 -1
  8. package/dist/animation/rig/rigNode.js.map +1 -1
  9. package/dist/barrel/canvas.js +9 -3
  10. package/dist/barrel/interactions.js +5 -4
  11. package/dist/barrel/paint.js +4 -4
  12. package/dist/barrel/paths.js +10 -6
  13. package/dist/barrel/renderer.js +5 -3
  14. package/dist/barrel/routing.js +7 -12
  15. package/dist/barrel/scene.js +9 -5
  16. package/dist/barrel/text.js +2 -2
  17. package/dist/barrel/viewport.js +9 -4
  18. package/dist/canvas/Canvas.js +5 -2
  19. package/dist/canvas/Canvas.js.map +1 -1
  20. package/dist/canvas/CanvasView.js +23 -34
  21. package/dist/canvas/CanvasView.js.map +1 -1
  22. package/dist/canvas/ModalityHud.js +1 -1
  23. package/dist/canvas/NodeShape.js +4 -1
  24. package/dist/canvas/NodeShape.js.map +1 -1
  25. package/dist/canvas/SceneCanvas/ActionsProviderIfRoot.js +1 -1
  26. package/dist/canvas/SceneCanvas/DepRegistryProviderIfRoot.js +1 -1
  27. package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +1 -1
  28. package/dist/canvas/SceneCanvas/SceneCanvasInput.js +17 -3
  29. package/dist/canvas/SceneCanvas/SceneCanvasInput.js.map +1 -1
  30. package/dist/canvas/SceneCanvas/SurfaceDeclarations.js +23 -0
  31. package/dist/canvas/SceneCanvas/SurfaceDeclarations.js.map +1 -0
  32. package/dist/canvas/SceneCanvas/builtinToolSets.js +30 -0
  33. package/dist/canvas/SceneCanvas/builtinToolSets.js.map +1 -0
  34. package/dist/canvas/SceneCanvas/canvasPassThrough.js +2 -0
  35. package/dist/canvas/SceneCanvas/canvasPassThrough.js.map +1 -1
  36. package/dist/canvas/SceneCanvas/coordTrace.js +5 -16
  37. package/dist/canvas/SceneCanvas/coordTrace.js.map +1 -1
  38. package/dist/canvas/SceneCanvas/defaultNodeProperties.js +5 -0
  39. package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
  40. package/dist/canvas/SceneCanvas/features.js +45 -5
  41. package/dist/canvas/SceneCanvas/features.js.map +1 -1
  42. package/dist/canvas/SceneCanvas/props.js +1 -11
  43. package/dist/canvas/SceneCanvas/props.js.map +1 -1
  44. package/dist/canvas/SceneCanvas/scenePointQuery.js +7 -3
  45. package/dist/canvas/SceneCanvas/scenePointQuery.js.map +1 -1
  46. package/dist/canvas/SceneCanvas/toolRegistry.js +8 -4
  47. package/dist/canvas/SceneCanvas/toolRegistry.js.map +1 -1
  48. package/dist/canvas/SceneCanvas/useActionTunings.js +6 -1
  49. package/dist/canvas/SceneCanvas/useActionTunings.js.map +1 -1
  50. package/dist/canvas/SceneCanvas/useActionsPropResolver.js +1 -11
  51. package/dist/canvas/SceneCanvas/useActionsPropResolver.js.map +1 -1
  52. package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js.map +1 -1
  53. package/dist/canvas/SceneCanvas/useBuiltinTools.js +2 -9
  54. package/dist/canvas/SceneCanvas/useBuiltinTools.js.map +1 -1
  55. package/dist/canvas/SceneCanvas/useCanvasDevtoolsRoot.js +94 -0
  56. package/dist/canvas/SceneCanvas/useCanvasDevtoolsRoot.js.map +1 -0
  57. package/dist/canvas/SceneCanvas/useCanvasSelection.js +7 -2
  58. package/dist/canvas/SceneCanvas/useCanvasSelection.js.map +1 -1
  59. package/dist/canvas/SceneCanvas/useCanvasTools.js +15 -10
  60. package/dist/canvas/SceneCanvas/useCanvasTools.js.map +1 -1
  61. package/dist/canvas/SceneCanvas/useNodeKinds.js +1 -1
  62. package/dist/canvas/SceneCanvas/useNodeKinds.js.map +1 -1
  63. package/dist/canvas/SceneCanvas/useSceneCanvasHandle.js +9 -3
  64. package/dist/canvas/SceneCanvas/useSceneCanvasHandle.js.map +1 -1
  65. package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js +23 -4
  66. package/dist/canvas/SceneCanvas/useSceneCanvasLayers.js.map +1 -1
  67. package/dist/canvas/SceneCanvas/useSceneCanvasTools.js +2 -3
  68. package/dist/canvas/SceneCanvas/useSceneCanvasTools.js.map +1 -1
  69. package/dist/canvas/SceneCanvas/useSceneChrome.js +6 -7
  70. package/dist/canvas/SceneCanvas/useSceneChrome.js.map +1 -1
  71. package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js +24 -7
  72. package/dist/canvas/SceneCanvas/useSceneGestureDispatcher.js.map +1 -1
  73. package/dist/canvas/SceneCanvas/useScenePicking.js +2 -3
  74. package/dist/canvas/SceneCanvas/useScenePicking.js.map +1 -1
  75. package/dist/canvas/SceneCanvas/useSceneSelectTool.js +2 -1
  76. package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
  77. package/dist/canvas/SceneCanvas/useSceneStandardActions.js +5 -5
  78. package/dist/canvas/SceneCanvas/useSceneStandardActions.js.map +1 -1
  79. package/dist/canvas/SceneCanvas.js +27 -24
  80. package/dist/canvas/SceneCanvas.js.map +1 -1
  81. package/dist/canvas/SurfaceCanvas.js +5 -22
  82. package/dist/canvas/SurfaceCanvas.js.map +1 -1
  83. package/dist/canvas/ViewMarker.js +35 -0
  84. package/dist/canvas/ViewMarker.js.map +1 -0
  85. package/dist/canvas/canvasRenderer.js +9 -5
  86. package/dist/canvas/canvasRenderer.js.map +1 -1
  87. package/dist/canvas/contextAttributes.js +14 -0
  88. package/dist/canvas/contextAttributes.js.map +1 -0
  89. package/dist/canvas/defaultDrawOne.js +2 -0
  90. package/dist/canvas/defaultDrawOne.js.map +1 -1
  91. package/dist/canvas/deps/booleans.js +2 -1
  92. package/dist/canvas/deps/booleans.js.map +1 -1
  93. package/dist/canvas/deps/editAnchors.js +9 -113
  94. package/dist/canvas/deps/editAnchors.js.map +1 -1
  95. package/dist/canvas/deps/hitTestArea.js +2 -2
  96. package/dist/canvas/deps/hitTestArea.js.map +1 -1
  97. package/dist/canvas/deps/insert.js +10 -4
  98. package/dist/canvas/deps/insert.js.map +1 -1
  99. package/dist/canvas/deps/pathEditCommits.js +189 -0
  100. package/dist/canvas/deps/pathEditCommits.js.map +1 -0
  101. package/dist/canvas/deps/snap.js +12 -9
  102. package/dist/canvas/deps/snap.js.map +1 -1
  103. package/dist/canvas/deps/transformFollowers.js +20 -0
  104. package/dist/canvas/deps/transformFollowers.js.map +1 -0
  105. package/dist/canvas/derivedPath.js +20 -1
  106. package/dist/canvas/derivedPath.js.map +1 -1
  107. package/dist/canvas/drawnBounds.js +38 -4
  108. package/dist/canvas/drawnBounds.js.map +1 -1
  109. package/dist/canvas/inheritedPaints.js +44 -0
  110. package/dist/canvas/inheritedPaints.js.map +1 -0
  111. package/dist/canvas/nodeShapes/derivedPainter.js +23 -16
  112. package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -1
  113. package/dist/canvas/nodeShapes/nodePaint.js +13 -34
  114. package/dist/canvas/nodeShapes/nodePaint.js.map +1 -1
  115. package/dist/canvas/nodeShapes/pathPainter.js +12 -10
  116. package/dist/canvas/nodeShapes/pathPainter.js.map +1 -1
  117. package/dist/canvas/nodeShapes/rectFallbackPainter.js +4 -5
  118. package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -1
  119. package/dist/canvas/nodeShapes/shapePainter.js +12 -11
  120. package/dist/canvas/nodeShapes/shapePainter.js.map +1 -1
  121. package/dist/canvas/nodeShapes/textPainter.js +13 -12
  122. package/dist/canvas/nodeShapes/textPainter.js.map +1 -1
  123. package/dist/canvas/overlayRoleStrokes.js +12 -0
  124. package/dist/canvas/overlayRoleStrokes.js.map +1 -1
  125. package/dist/canvas/pathOverlay.js +27 -7
  126. package/dist/canvas/pathOverlay.js.map +1 -1
  127. package/dist/canvas/pickReach.js +3 -3
  128. package/dist/canvas/pickReach.js.map +1 -1
  129. package/dist/canvas/pickWalk.js +3 -1
  130. package/dist/canvas/pickWalk.js.map +1 -1
  131. package/dist/canvas/renderDebugSnapshot.js +1 -0
  132. package/dist/canvas/renderDebugSnapshot.js.map +1 -1
  133. package/dist/canvas/renderSceneToPixels.js +7 -6
  134. package/dist/canvas/renderSceneToPixels.js.map +1 -1
  135. package/dist/canvas/sceneAdapter.js.map +1 -1
  136. package/dist/canvas/sceneSlotWiring.js +2 -1
  137. package/dist/canvas/sceneSlotWiring.js.map +1 -1
  138. package/dist/canvas/sceneViewRender.js +2 -1
  139. package/dist/canvas/sceneViewRender.js.map +1 -1
  140. package/dist/canvas/surfaceContribution.js +12 -8
  141. package/dist/canvas/surfaceContribution.js.map +1 -1
  142. package/dist/canvas/useCanvasPaint.js +2 -1
  143. package/dist/canvas/useCanvasPaint.js.map +1 -1
  144. package/dist/canvas/useCanvasView.js +4 -2
  145. package/dist/canvas/useCanvasView.js.map +1 -1
  146. package/dist/canvas/useInFlightBounds.js +52 -0
  147. package/dist/canvas/useInFlightBounds.js.map +1 -0
  148. package/dist/canvas/useLayerStack.js +6 -2
  149. package/dist/canvas/useLayerStack.js.map +1 -1
  150. package/dist/canvas/useViewAim.js +121 -0
  151. package/dist/canvas/useViewAim.js.map +1 -0
  152. package/dist/canvas/useViewHelpers.js +7 -9
  153. package/dist/canvas/useViewHelpers.js.map +1 -1
  154. package/dist/canvas/useViewNesting.js +3 -2
  155. package/dist/canvas/useViewNesting.js.map +1 -1
  156. package/dist/canvas/useViewRegistrySurface.js +4 -2
  157. package/dist/canvas/useViewRegistrySurface.js.map +1 -1
  158. package/dist/canvas/viewMarkers.js +63 -0
  159. package/dist/canvas/viewMarkers.js.map +1 -0
  160. package/dist/canvas/viewRegistry.js +27 -1
  161. package/dist/canvas/viewRegistry.js.map +1 -1
  162. package/dist/clipboard.d.ts +3 -2
  163. package/dist/{clone-DZDrfIlU.d.ts → clone-C3e0OTuF.d.ts} +8 -21
  164. package/dist/clone.d.ts +4 -3
  165. package/dist/core/geometry/autoPoseDescriptor.js +1 -1
  166. package/dist/core/ops/setDependsOn.js +37 -0
  167. package/dist/core/ops/setDependsOn.js.map +1 -0
  168. package/dist/core/ops/writtenBy.js +53 -0
  169. package/dist/core/ops/writtenBy.js.map +1 -0
  170. package/dist/core/pages/fitViewToPage.js +12 -1
  171. package/dist/core/pages/fitViewToPage.js.map +1 -1
  172. package/dist/core/pages/pageEdits.js +163 -0
  173. package/dist/core/pages/pageEdits.js.map +1 -0
  174. package/dist/core/pages/pages.js +30 -1
  175. package/dist/core/pages/pages.js.map +1 -1
  176. package/dist/core/paint/meshKindLazy.js +59 -2
  177. package/dist/core/paint/meshKindLazy.js.map +1 -1
  178. package/dist/core/scene/NodeRouting.js +8 -3
  179. package/dist/core/scene/NodeRouting.js.map +1 -1
  180. package/dist/core/scene/arrivalWindow.js.map +1 -1
  181. package/dist/core/scene/carryDescendants.js +51 -0
  182. package/dist/core/scene/carryDescendants.js.map +1 -0
  183. package/dist/core/scene/clipNothing.js +13 -0
  184. package/dist/core/scene/clipNothing.js.map +1 -0
  185. package/dist/core/scene/depMemo.js +11 -3
  186. package/dist/core/scene/depMemo.js.map +1 -1
  187. package/dist/core/scene/dependents.js +7 -1
  188. package/dist/core/scene/dependents.js.map +1 -1
  189. package/dist/core/scene/derivedParts.js +10 -11
  190. package/dist/core/scene/derivedParts.js.map +1 -1
  191. package/dist/core/scene/docValues.js +57 -0
  192. package/dist/core/scene/docValues.js.map +1 -0
  193. package/dist/core/scene/editPass.js +111 -0
  194. package/dist/core/scene/editPass.js.map +1 -0
  195. package/dist/core/scene/effectivePose.js +13 -2
  196. package/dist/core/scene/effectivePose.js.map +1 -1
  197. package/dist/core/scene/fieldEdits.js +4 -1
  198. package/dist/core/scene/fieldEdits.js.map +1 -1
  199. package/dist/core/scene/fontReads.js +37 -0
  200. package/dist/core/scene/fontReads.js.map +1 -0
  201. package/dist/core/scene/historyFacade.js +1 -0
  202. package/dist/core/scene/historyFacade.js.map +1 -1
  203. package/dist/core/scene/inheritedPaint.js +75 -0
  204. package/dist/core/scene/inheritedPaint.js.map +1 -0
  205. package/dist/core/scene/kitRegistry.js +5 -0
  206. package/dist/core/scene/kitRegistry.js.map +1 -1
  207. package/dist/core/scene/layoutPass.js +28 -3
  208. package/dist/core/scene/layoutPass.js.map +1 -1
  209. package/dist/core/scene/nodeMemo.js +15 -7
  210. package/dist/core/scene/nodeMemo.js.map +1 -1
  211. package/dist/core/scene/pathEffects/blend.js.map +1 -1
  212. package/dist/core/scene/pathEffects/derive.js +7 -2
  213. package/dist/core/scene/pathEffects/derive.js.map +1 -1
  214. package/dist/core/scene/pathEffects/effects.js +3 -1
  215. package/dist/core/scene/pathEffects/effects.js.map +1 -1
  216. package/dist/core/scene/pathEffects/textAlong.js +95 -0
  217. package/dist/core/scene/pathEffects/textAlong.js.map +1 -0
  218. package/dist/core/scene/recorder.js +28 -19
  219. package/dist/core/scene/recorder.js.map +1 -1
  220. package/dist/core/scene/scene.js +15 -9
  221. package/dist/core/scene/scene.js.map +1 -1
  222. package/dist/core/scene/sceneChanges.js +13 -0
  223. package/dist/core/scene/sceneChanges.js.map +1 -0
  224. package/dist/core/scene/sceneEdits.js +8 -1
  225. package/dist/core/scene/sceneEdits.js.map +1 -1
  226. package/dist/core/scene/sceneMutators.js +1 -0
  227. package/dist/core/scene/sceneMutators.js.map +1 -1
  228. package/dist/core/scene/sceneRecording.js +20 -3
  229. package/dist/core/scene/sceneRecording.js.map +1 -1
  230. package/dist/core/scene/sceneSelection.js +4 -1
  231. package/dist/core/scene/sceneSelection.js.map +1 -1
  232. package/dist/core/scene/sceneState.js +11 -5
  233. package/dist/core/scene/sceneState.js.map +1 -1
  234. package/dist/core/scene/serialization.js +5 -3
  235. package/dist/core/scene/serialization.js.map +1 -1
  236. package/dist/core/scene/types.js.map +1 -1
  237. package/dist/core/scene/unitScopes.js +19 -1
  238. package/dist/core/scene/unitScopes.js.map +1 -1
  239. package/dist/core/selection/usePublishSceneSelection.js +6 -12
  240. package/dist/core/selection/usePublishSceneSelection.js.map +1 -1
  241. package/dist/core/shapeKinds.js +25 -11
  242. package/dist/core/shapeKinds.js.map +1 -1
  243. package/dist/{cornerHandles-Camw_yeu.d.ts → cornerHandles-p8fDIAKt.d.ts} +3 -2
  244. package/dist/debug/createDebugOverlayLayer.js +16 -111
  245. package/dist/debug/createDebugOverlayLayer.js.map +1 -1
  246. package/dist/debug/createDebugSink.js +2 -1
  247. package/dist/debug/createDebugSink.js.map +1 -1
  248. package/dist/debug/defaultTheme.js +4 -2
  249. package/dist/debug/defaultTheme.js.map +1 -1
  250. package/dist/debug/features.js +17 -0
  251. package/dist/debug/features.js.map +1 -0
  252. package/dist/debug/overlayPanels.js +117 -0
  253. package/dist/debug/overlayPanels.js.map +1 -0
  254. package/dist/debug/parseDebugFlags.js +4 -13
  255. package/dist/debug/parseDebugFlags.js.map +1 -1
  256. package/dist/{depSchema-Cgfu_G9s.d.ts → depSchema-mG19aEdD.d.ts} +174 -904
  257. package/dist/devtools/handlers.js +112 -0
  258. package/dist/devtools/handlers.js.map +1 -0
  259. package/dist/devtools/history.js +71 -0
  260. package/dist/devtools/history.js.map +1 -0
  261. package/dist/devtools/hook.js +74 -0
  262. package/dist/devtools/hook.js.map +1 -0
  263. package/dist/devtools/label.js +25 -0
  264. package/dist/devtools/label.js.map +1 -0
  265. package/dist/devtools/notices.js +58 -0
  266. package/dist/devtools/notices.js.map +1 -0
  267. package/dist/devtools/protocol.js +7 -0
  268. package/dist/devtools/protocol.js.map +1 -0
  269. package/dist/devtools/registry.js +90 -0
  270. package/dist/devtools/registry.js.map +1 -0
  271. package/dist/devtools/root.js +80 -0
  272. package/dist/devtools/root.js.map +1 -0
  273. package/dist/devtools/serialize.js +86 -0
  274. package/dist/devtools/serialize.js.map +1 -0
  275. package/dist/devtools/session.js +111 -0
  276. package/dist/devtools/session.js.map +1 -0
  277. package/dist/devtools/transport.js +67 -0
  278. package/dist/devtools/transport.js.map +1 -0
  279. package/dist/devtools/useDevtoolsRoot.js +81 -0
  280. package/dist/devtools/useDevtoolsRoot.js.map +1 -0
  281. package/dist/devtools-protocol.d.ts +435 -0
  282. package/dist/devtools-protocol.js +7 -0
  283. package/dist/devtools.d.ts +8 -0
  284. package/dist/devtools.js +12 -0
  285. package/dist/devtools.js.map +1 -0
  286. package/dist/features/chrome-caps/useHoverTracking.js +16 -10
  287. package/dist/features/chrome-caps/useHoverTracking.js.map +1 -1
  288. package/dist/features/ingestion/contentHandlers.js +25 -2
  289. package/dist/features/ingestion/contentHandlers.js.map +1 -1
  290. package/dist/features/measure/measureCommands.js +7 -5
  291. package/dist/features/measure/measureCommands.js.map +1 -1
  292. package/dist/features/measure/measureContribution.js +4 -2
  293. package/dist/features/measure/measureContribution.js.map +1 -1
  294. package/dist/features/modes/modeTriggers.js +7 -3
  295. package/dist/features/modes/modeTriggers.js.map +1 -1
  296. package/dist/features/pathEffects/effectSources.js +60 -0
  297. package/dist/features/pathEffects/effectSources.js.map +1 -0
  298. package/dist/features/pathEffects/readSource.js +17 -1
  299. package/dist/features/pathEffects/readSource.js.map +1 -1
  300. package/dist/features/pathEffects/textItems.js +53 -0
  301. package/dist/features/pathEffects/textItems.js.map +1 -0
  302. package/dist/features/pathEffects/useEffectSourcesLayer.js +57 -0
  303. package/dist/features/pathEffects/useEffectSourcesLayer.js.map +1 -0
  304. package/dist/features/paths/index.js +2 -2
  305. package/dist/features/paths/pathEditExtension.js.map +1 -1
  306. package/dist/features/paths/pathEditState.js +5 -2
  307. package/dist/features/paths/pathEditState.js.map +1 -1
  308. package/dist/features/paths/pathSnap/pathSnapSource.js +5 -5
  309. package/dist/features/paths/pathSnap/pathSnapSource.js.map +1 -1
  310. package/dist/features/paths/pathSnap/sceneIndex.js +10 -3
  311. package/dist/features/paths/pathSnap/sceneIndex.js.map +1 -1
  312. package/dist/features/selection/selectionPose.js +4 -1
  313. package/dist/features/selection/selectionPose.js.map +1 -1
  314. package/dist/features/snap/gather.js +9 -1
  315. package/dist/features/snap/gather.js.map +1 -1
  316. package/dist/features/snap/lazySession.js +17 -0
  317. package/dist/features/snap/lazySession.js.map +1 -0
  318. package/dist/features/snap/marks.js.map +1 -1
  319. package/dist/features/snap/probes2d.js +27 -19
  320. package/dist/features/snap/probes2d.js.map +1 -1
  321. package/dist/features/snap/readoutLayer.js.map +1 -1
  322. package/dist/features/snap/roles.js +2 -1
  323. package/dist/features/snap/roles.js.map +1 -1
  324. package/dist/features/snap/rotationSource.js +25 -8
  325. package/dist/features/snap/rotationSource.js.map +1 -1
  326. package/dist/features/snap/sceneSession2d.js +6 -4
  327. package/dist/features/snap/sceneSession2d.js.map +1 -1
  328. package/dist/features/snap/session2d.js +37 -23
  329. package/dist/features/snap/session2d.js.map +1 -1
  330. package/dist/features/snap/spanSnap.js +5 -2
  331. package/dist/features/snap/spanSnap.js.map +1 -1
  332. package/dist/features/text/sceneTextDrafts.js +65 -0
  333. package/dist/features/text/sceneTextDrafts.js.map +1 -0
  334. package/dist/features/text/textHitAt.js +31 -2
  335. package/dist/features/text/textHitAt.js.map +1 -1
  336. package/dist/features/text/useSceneTextEdit.js +22 -18
  337. package/dist/features/text/useSceneTextEdit.js.map +1 -1
  338. package/dist/features/viewports/aim.js +105 -0
  339. package/dist/features/viewports/aim.js.map +1 -0
  340. package/dist/features/viewports/viewMarker.js +82 -0
  341. package/dist/features/viewports/viewMarker.js.map +1 -0
  342. package/dist/features/viewports/viewMarkerDrag.js +55 -0
  343. package/dist/features/viewports/viewMarkerDrag.js.map +1 -0
  344. package/dist/icons.table.js +1 -1
  345. package/dist/icons.table.js.map +1 -1
  346. package/dist/icons.table.json +0 -10
  347. package/dist/index.d.ts +1198 -894
  348. package/dist/index.js +55 -38
  349. package/dist/interactions/actions/align/action.js +6 -4
  350. package/dist/interactions/actions/align/action.js.map +1 -1
  351. package/dist/interactions/actions/align/align.js.map +1 -1
  352. package/dist/interactions/actions/booleans/action.js +7 -1
  353. package/dist/interactions/actions/booleans/action.js.map +1 -1
  354. package/dist/interactions/actions/booleans/booleans.js +2 -1
  355. package/dist/interactions/actions/booleans/booleans.js.map +1 -1
  356. package/dist/interactions/actions/booleans/operands.js +6 -5
  357. package/dist/interactions/actions/booleans/operands.js.map +1 -1
  358. package/dist/interactions/actions/clipboard/action.js +27 -17
  359. package/dist/interactions/actions/clipboard/action.js.map +1 -1
  360. package/dist/interactions/actions/clone/action.js +1 -1
  361. package/dist/interactions/actions/clone/behaviors.js +4 -4
  362. package/dist/interactions/actions/clone/behaviors.js.map +1 -1
  363. package/dist/interactions/actions/defaults/anchorEditing.js +44 -23
  364. package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
  365. package/dist/interactions/actions/defaults/anchorJoin.js +12 -6
  366. package/dist/interactions/actions/defaults/anchorJoin.js.map +1 -1
  367. package/dist/interactions/actions/defaults/bendSegment.js +8 -5
  368. package/dist/interactions/actions/defaults/bendSegment.js.map +1 -1
  369. package/dist/interactions/actions/defaults/cancelGesture.js +11 -8
  370. package/dist/interactions/actions/defaults/cancelGesture.js.map +1 -1
  371. package/dist/interactions/actions/defaults/contextMenu.js +17 -8
  372. package/dist/interactions/actions/defaults/contextMenu.js.map +1 -1
  373. package/dist/interactions/actions/defaults/createPaintAction.js +2 -2
  374. package/dist/interactions/actions/defaults/createPaintAction.js.map +1 -1
  375. package/dist/interactions/actions/defaults/delete.js +64 -41
  376. package/dist/interactions/actions/defaults/delete.js.map +1 -1
  377. package/dist/interactions/actions/defaults/duplicate.js +12 -9
  378. package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
  379. package/dist/interactions/actions/defaults/enterPathEdit.js +19 -9
  380. package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
  381. package/dist/interactions/actions/defaults/escape.js +11 -8
  382. package/dist/interactions/actions/defaults/escape.js.map +1 -1
  383. package/dist/interactions/actions/defaults/exitPathEdit.js +7 -4
  384. package/dist/interactions/actions/defaults/exitPathEdit.js.map +1 -1
  385. package/dist/interactions/actions/defaults/group.js +21 -15
  386. package/dist/interactions/actions/defaults/group.js.map +1 -1
  387. package/dist/interactions/actions/defaults/ingest.js +17 -9
  388. package/dist/interactions/actions/defaults/ingest.js.map +1 -1
  389. package/dist/interactions/actions/defaults/insertPathAnchor.js +7 -4
  390. package/dist/interactions/actions/defaults/insertPathAnchor.js.map +1 -1
  391. package/dist/interactions/actions/defaults/nudge.js +21 -40
  392. package/dist/interactions/actions/defaults/nudge.js.map +1 -1
  393. package/dist/interactions/actions/defaults/pathEditTools.js +11 -8
  394. package/dist/interactions/actions/defaults/pathEditTools.js.map +1 -1
  395. package/dist/interactions/actions/defaults/pinchZoom.js +7 -4
  396. package/dist/interactions/actions/defaults/pinchZoom.js.map +1 -1
  397. package/dist/interactions/actions/defaults/reorder.js +24 -6
  398. package/dist/interactions/actions/defaults/reorder.js.map +1 -1
  399. package/dist/interactions/actions/defaults/selectAll.js +8 -5
  400. package/dist/interactions/actions/defaults/selectAll.js.map +1 -1
  401. package/dist/interactions/actions/defaults/setFill.js +7 -3
  402. package/dist/interactions/actions/defaults/setFill.js.map +1 -1
  403. package/dist/interactions/actions/defaults/setFillOpacity.js +1 -1
  404. package/dist/interactions/actions/defaults/setStroke.js +12 -11
  405. package/dist/interactions/actions/defaults/setStroke.js.map +1 -1
  406. package/dist/interactions/actions/defaults/setStrokeOpacity.js +1 -1
  407. package/dist/interactions/actions/defaults/toolActivate.js +7 -1
  408. package/dist/interactions/actions/defaults/toolActivate.js.map +1 -1
  409. package/dist/interactions/actions/defaults/toolResetToDefault.js +7 -4
  410. package/dist/interactions/actions/defaults/toolResetToDefault.js.map +1 -1
  411. package/dist/interactions/actions/defaults/undoRedo.js +19 -13
  412. package/dist/interactions/actions/defaults/undoRedo.js.map +1 -1
  413. package/dist/interactions/actions/defaults/viewportWheelPan.js +16 -7
  414. package/dist/interactions/actions/defaults/viewportWheelPan.js.map +1 -1
  415. package/dist/interactions/actions/defaults/viewportZoom.js +24 -6
  416. package/dist/interactions/actions/defaults/viewportZoom.js.map +1 -1
  417. package/dist/interactions/actions/distribute/action.js +6 -4
  418. package/dist/interactions/actions/distribute/action.js.map +1 -1
  419. package/dist/interactions/actions/drawnBoxes.js +2 -1
  420. package/dist/interactions/actions/drawnBoxes.js.map +1 -1
  421. package/dist/interactions/actions/edit-anchors/action.js +10 -10
  422. package/dist/interactions/actions/edit-anchors/action.js.map +1 -1
  423. package/dist/interactions/actions/edit-anchors/preview.js +41 -8
  424. package/dist/interactions/actions/edit-anchors/preview.js.map +1 -1
  425. package/dist/interactions/actions/flip/action.js +14 -6
  426. package/dist/interactions/actions/flip/action.js.map +1 -1
  427. package/dist/interactions/actions/gestureLifecycle.js +5 -2
  428. package/dist/interactions/actions/gestureLifecycle.js.map +1 -1
  429. package/dist/interactions/actions/insert/action.js +1 -2
  430. package/dist/interactions/actions/insert/action.js.map +1 -1
  431. package/dist/interactions/actions/insert/commit.js +1 -1
  432. package/dist/interactions/actions/insert/parent.js +11 -0
  433. package/dist/interactions/actions/insert/parent.js.map +1 -0
  434. package/dist/interactions/actions/insert/placeAction.js +7 -2
  435. package/dist/interactions/actions/insert/placeAction.js.map +1 -1
  436. package/dist/interactions/actions/insert/repositionAction.js +2 -1
  437. package/dist/interactions/actions/insert/repositionAction.js.map +1 -1
  438. package/dist/interactions/actions/insert/session.js +5 -1
  439. package/dist/interactions/actions/insert/session.js.map +1 -1
  440. package/dist/interactions/actions/move/action.js +15 -8
  441. package/dist/interactions/actions/move/action.js.map +1 -1
  442. package/dist/interactions/actions/move/behaviors/layoutDrop.js +0 -1
  443. package/dist/interactions/actions/move/behaviors/layoutDrop.js.map +1 -1
  444. package/dist/interactions/actions/move/behaviors/snapToContainer.js +1 -1
  445. package/dist/interactions/actions/move/capture.js +1 -1
  446. package/dist/interactions/actions/move/commit/index.js +0 -2
  447. package/dist/interactions/actions/move/commit/index.js.map +1 -1
  448. package/dist/interactions/actions/move/commit/layoutDrop.js +2 -2
  449. package/dist/interactions/actions/move/commit/layoutRelease.js +2 -2
  450. package/dist/interactions/actions/move/commit/reparent.js +11 -5
  451. package/dist/interactions/actions/move/commit/reparent.js.map +1 -1
  452. package/dist/interactions/actions/move/frame.js +4 -10
  453. package/dist/interactions/actions/move/frame.js.map +1 -1
  454. package/dist/interactions/actions/move/landedDescendants.js +20 -17
  455. package/dist/interactions/actions/move/landedDescendants.js.map +1 -1
  456. package/dist/interactions/actions/move/layout/container.js +2 -1
  457. package/dist/interactions/actions/move/layout/container.js.map +1 -1
  458. package/dist/interactions/actions/move/layout/dragged.js +1 -1
  459. package/dist/interactions/actions/move/layout/dropPass.js +18 -1
  460. package/dist/interactions/actions/move/layout/dropPass.js.map +1 -1
  461. package/dist/interactions/actions/move/layout/exits.js +5 -5
  462. package/dist/interactions/actions/move/layout/exits.js.map +1 -1
  463. package/dist/interactions/actions/move/session.js +14 -3
  464. package/dist/interactions/actions/move/session.js.map +1 -1
  465. package/dist/interactions/actions/move/translate.js +8 -37
  466. package/dist/interactions/actions/move/translate.js.map +1 -1
  467. package/dist/interactions/actions/moveNodes.js +87 -0
  468. package/dist/interactions/actions/moveNodes.js.map +1 -0
  469. package/dist/interactions/actions/outlines/createOutlinesAction.js +8 -5
  470. package/dist/interactions/actions/outlines/createOutlinesAction.js.map +1 -1
  471. package/dist/interactions/actions/outlines/outlineStroke.js +5 -3
  472. package/dist/interactions/actions/outlines/outlineStroke.js.map +1 -1
  473. package/dist/interactions/actions/pathCommands/cutJoin.js +8 -5
  474. package/dist/interactions/actions/pathCommands/cutJoin.js.map +1 -1
  475. package/dist/interactions/actions/planeInput.js.map +1 -1
  476. package/dist/interactions/actions/resize/action.js +83 -72
  477. package/dist/interactions/actions/resize/action.js.map +1 -1
  478. package/dist/interactions/actions/resize/commit.js +2 -1
  479. package/dist/interactions/actions/resize/commit.js.map +1 -1
  480. package/dist/interactions/actions/resize/cornerHandles.js +2 -1
  481. package/dist/interactions/actions/resize/cornerHandles.js.map +1 -1
  482. package/dist/interactions/actions/resize/session.js +2 -0
  483. package/dist/interactions/actions/resize/session.js.map +1 -1
  484. package/dist/interactions/actions/resolvePreviews.js +3 -3
  485. package/dist/interactions/actions/resolvePreviews.js.map +1 -1
  486. package/dist/interactions/actions/rotate/action.js +7 -4
  487. package/dist/interactions/actions/rotate/action.js.map +1 -1
  488. package/dist/interactions/actions/rotate/commit.js +2 -1
  489. package/dist/interactions/actions/rotate/commit.js.map +1 -1
  490. package/dist/interactions/actions/rotate/session.js +2 -0
  491. package/dist/interactions/actions/rotate/session.js.map +1 -1
  492. package/dist/interactions/actions/selectionSubtree.js +25 -9
  493. package/dist/interactions/actions/selectionSubtree.js.map +1 -1
  494. package/dist/interactions/actions/testUtils.js.map +1 -1
  495. package/dist/interactions/actions/transform-again/action.js +13 -11
  496. package/dist/interactions/actions/transform-again/action.js.map +1 -1
  497. package/dist/interactions/actions/transformFinish.js +106 -0
  498. package/dist/interactions/actions/transformFinish.js.map +1 -0
  499. package/dist/json.d.ts +4 -0
  500. package/dist/json.js +3 -0
  501. package/dist/kitSettingsSchema.js +8 -5
  502. package/dist/kitSettingsSchema.js.map +1 -1
  503. package/dist/{math-CrJULaZI.d.ts → math-B56zxVs5.d.ts} +10 -1
  504. package/dist/math.d.ts +1 -1
  505. package/dist/math.js +2 -1
  506. package/dist/move.d.ts +5 -4
  507. package/dist/{options-p9GZMXbY.d.ts → options-DBxEryYq.d.ts} +1 -1
  508. package/dist/resize.d.ts +4 -3
  509. package/dist/routing.d.ts +1 -1
  510. package/dist/routing.js +2 -2
  511. package/dist/test-hook/createTestHook.js +1 -1
  512. package/dist/test-hook/createTestHook.js.map +1 -1
  513. package/dist/test-hook/useTestHook.js +2 -1
  514. package/dist/test-hook/useTestHook.js.map +1 -1
  515. package/dist/test-seams.d.ts +9 -5
  516. package/dist/tools/builtin/ellipse/useEllipseTool.js +1 -0
  517. package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
  518. package/dist/tools/builtin/eyedropper/useEyedropperTool.js +2 -1
  519. package/dist/tools/builtin/eyedropper/useEyedropperTool.js.map +1 -1
  520. package/dist/tools/builtin/hand/dragPanContribution.js +4 -1
  521. package/dist/tools/builtin/hand/dragPanContribution.js.map +1 -1
  522. package/dist/tools/builtin/hand/useHandTool.js +7 -4
  523. package/dist/tools/builtin/hand/useHandTool.js.map +1 -1
  524. package/dist/tools/builtin/image/useImageTool.js +1 -0
  525. package/dist/tools/builtin/image/useImageTool.js.map +1 -1
  526. package/dist/tools/builtin/lasso/useLassoTool.js +1 -0
  527. package/dist/tools/builtin/lasso/useLassoTool.js.map +1 -1
  528. package/dist/tools/builtin/line/useLineTool.js +1 -0
  529. package/dist/tools/builtin/line/useLineTool.js.map +1 -1
  530. package/dist/tools/builtin/measure/useMeasureTool.js +12 -5
  531. package/dist/tools/builtin/measure/useMeasureTool.js.map +1 -1
  532. package/dist/tools/builtin/pen/penHandle.js +3 -5
  533. package/dist/tools/builtin/pen/penHandle.js.map +1 -1
  534. package/dist/tools/builtin/pen/usePenTool.js +14 -6
  535. package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
  536. package/dist/tools/builtin/pencil/usePencilTool.js +1 -0
  537. package/dist/tools/builtin/pencil/usePencilTool.js.map +1 -1
  538. package/dist/tools/builtin/polygon/usePolygonTool.js +13 -4
  539. package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
  540. package/dist/tools/builtin/rect/useRectTool.js +1 -0
  541. package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
  542. package/dist/tools/builtin/select/adapterPointQuery.js +3 -2
  543. package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
  544. package/dist/tools/builtin/select/pressDecision.js +32 -0
  545. package/dist/tools/builtin/select/pressDecision.js.map +1 -0
  546. package/dist/tools/builtin/select/selectionContributions.js +22 -13
  547. package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
  548. package/dist/tools/builtin/select/useSelectTool.js +13 -10
  549. package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
  550. package/dist/tools/builtin/slice/useSliceTool.js +22 -8
  551. package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
  552. package/dist/tools/builtin/star/useStarTool.js +13 -4
  553. package/dist/tools/builtin/star/useStarTool.js.map +1 -1
  554. package/dist/tools/builtin/sticky/stickyNode.js +4 -1
  555. package/dist/tools/builtin/sticky/stickyNode.js.map +1 -1
  556. package/dist/tools/builtin/sticky/useStickyTool.js +10 -5
  557. package/dist/tools/builtin/sticky/useStickyTool.js.map +1 -1
  558. package/dist/tools/builtin/text/useTextTool.js +3 -1
  559. package/dist/tools/builtin/text/useTextTool.js.map +1 -1
  560. package/dist/tools/index.js +26 -0
  561. package/dist/{types-CHVXGfYm.d.ts → types-7puAuVD2.d.ts} +3 -262
  562. package/dist/types-BN9hbdMI.d.ts +184 -0
  563. package/dist/types-CniVctmk.d.ts +949 -0
  564. package/dist/types-oFeQ5VjV.d.ts +264 -0
  565. package/dist/util/paint.js +1 -3
  566. package/dist/util/paint.js.map +1 -1
  567. package/dist/version.js +1 -1
  568. package/package.json +39 -25
  569. package/dist/canvas/SceneCanvas/useBuiltinRigTools.js +0 -65
  570. package/dist/canvas/SceneCanvas/useBuiltinRigTools.js.map +0 -1
  571. package/dist/tools/builtin/bone/boneActions.js +0 -156
  572. package/dist/tools/builtin/bone/boneActions.js.map +0 -1
  573. package/dist/tools/builtin/bone/boneOverlay.js +0 -71
  574. package/dist/tools/builtin/bone/boneOverlay.js.map +0 -1
  575. package/dist/tools/builtin/bone/placedRig.js +0 -28
  576. package/dist/tools/builtin/bone/placedRig.js.map +0 -1
  577. package/dist/tools/builtin/bone/rigEditState.js +0 -30
  578. package/dist/tools/builtin/bone/rigEditState.js.map +0 -1
  579. package/dist/tools/builtin/bone/useBoneTool.js +0 -125
  580. package/dist/tools/builtin/bone/useBoneTool.js.map +0 -1
  581. package/dist/tools/builtin/weight/useWeightTool.js +0 -101
  582. package/dist/tools/builtin/weight/useWeightTool.js.map +0 -1
  583. package/dist/tools/builtin/weight/weightActions.js +0 -140
  584. package/dist/tools/builtin/weight/weightActions.js.map +0 -1
  585. package/dist/tools/builtin/weight/weightOverlay.js +0 -78
  586. package/dist/tools/builtin/weight/weightOverlay.js.map +0 -1
@@ -15,6 +15,7 @@ var DEFAULT_SNAP_PX = 8;
15
15
  function createSession2d(inputs) {
16
16
  const { req, store } = inputs;
17
17
  const sources = snapSourcesFor(inputs.sources, req.gesture);
18
+ const fixed = collectAtPress(inputs);
18
19
  return {
19
20
  at(p, mods) {
20
21
  const delta0 = {
@@ -29,7 +30,15 @@ function createSession2d(inputs) {
29
30
  }
30
31
  const view = inputs.view();
31
32
  const plane = req.plane?.() ?? null;
32
- const candidates = collectAll(inputs, sources, delta0, view, plane);
33
+ const subject = subjectAt(inputs, delta0);
34
+ const candidates = collectAll(sources, inputs.probes, {
35
+ ...fixed,
36
+ ...subject
37
+ }, {
38
+ delta0,
39
+ view,
40
+ plane
41
+ }, inputs.reachPx);
33
42
  const res = resolveSnap({
34
43
  probes: inputs.probes.map((q) => ({
35
44
  id: q.id,
@@ -67,47 +76,52 @@ function outcome(press, delta, held, marks) {
67
76
  marks
68
77
  };
69
78
  }
70
- function collectAll(inputs, sources, delta0, view, plane) {
79
+ function collectAtPress(inputs) {
71
80
  const { req } = inputs;
81
+ return {
82
+ gesture: req.gesture,
83
+ ...req.ids ? { ids: req.ids } : {},
84
+ ...req.parent !== void 0 ? { parent: req.parent } : {},
85
+ exclude: inputs.exclude ?? req.ids ?? [],
86
+ ...inputs.drawnBox ? { drawnBox: inputs.drawnBox } : {},
87
+ ...req.origin ? { origin: req.origin } : {},
88
+ ...req.also ? { also: req.also } : {},
89
+ ...inputs.scene ? { scene: inputs.scene } : {}
90
+ };
91
+ }
92
+ function collectAll(sources, probesAtPress, fixed, { delta0, view, plane }, reachPx) {
72
93
  const camera = view ? Math.min(Math.abs(view.scale.x), Math.abs(view.scale.y)) : 1;
73
94
  const scale = plane ? camera / Math.max(Math.abs(plane.scale.x), Math.abs(plane.scale.y)) : camera;
74
- const probes = inputs.probes.map((q) => ({
95
+ const probes = probesAtPress.map((q) => ({
75
96
  ...q,
76
97
  at: {
77
98
  x: q.at.x + delta0.x,
78
99
  y: q.at.y + delta0.y
79
100
  }
80
101
  }));
81
- return gatherSnapCandidates(sources, probes, (_source, offered, reachPx) => ({
82
- gesture: req.gesture,
102
+ return gatherSnapCandidates(sources, probes, (_source, offered, sourceReach) => ({
103
+ ...fixed,
83
104
  probes: offered,
84
105
  delta0,
85
- exclude: inputs.exclude ?? req.ids ?? [],
86
106
  ...plane ? { plane } : {},
87
- ...subjectAt(inputs, delta0),
88
- ...inputs.drawnBox ? { drawnBox: inputs.drawnBox } : {},
89
- ...req.origin ? { origin: req.origin } : {},
90
- ...req.also ? { also: req.also } : {},
91
107
  reachWorld: (px) => px / scale,
92
- reachPx,
93
- ...inputs.scene ? { scene: inputs.scene } : {}
108
+ reachPx: sourceReach
94
109
  }), {
95
110
  toVec: (p) => [p.x, p.y],
96
- reachPx: inputs.reachPx,
97
- ...req.origin ? { origin: req.origin } : {}
111
+ reachPx,
112
+ ...fixed.origin ? { origin: fixed.origin } : {}
98
113
  });
99
114
  }
100
115
  /** The subject's box where `delta0` puts it, and the sides that moved. */
101
- function subjectAt(inputs, delta0) {
102
- if (inputs.resize) return {
103
- box: resizedBox(inputs.resize, delta0),
104
- edges: resizeEdges(inputs.resize, delta0)
116
+ function subjectAt({ box, resize }, delta0) {
117
+ if (resize) return {
118
+ box: resizedBox(resize, delta0),
119
+ edges: resizeEdges(resize, delta0)
105
120
  };
106
- const b = inputs.req.gesture === "move" ? inputs.box : null;
107
- return b ? { box: {
108
- ...b,
109
- x: b.x + delta0.x,
110
- y: b.y + delta0.y
121
+ return box ? { box: {
122
+ ...box,
123
+ x: box.x + delta0.x,
124
+ y: box.y + delta0.y
111
125
  } } : {};
112
126
  }
113
127
  /** A session no source answers: it only holds the point to the gesture's
@@ -1 +1 @@
1
- {"version":3,"file":"session2d.js","names":[],"sources":["../../../src/features/snap/session2d.ts"],"sourcesContent":["import { closestOnFlat, resolveSnap, type SnapCandidate } from '@weasel-js/geom/nd';\nimport type { View } from '@weasel-js/geom';\nimport type { DebugSink } from '@weasel-js/routing';\nimport type { Scene } from 'core/scene/types';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport type { PlaneMap } from 'core/viewport/parallax';\nimport type { SnapBegin, SnapOutcome, SnapSession } from 'interactions/actions/snapDep';\nimport { angleAt } from './angle2d';\nimport { inputFlat } from './inputSubspace';\nimport { gatherSnapCandidates, resolvedSnapMarks, snapSourcesFor, type SnapCandidateMark } from './gather';\nimport { recordSnapCandidates } from './debugCandidates';\nimport { markFromPlane } from './marks';\nimport { createSnapOutcomeStore, type SnapOutcomeStore } from './outcomeStore';\nimport { resizedBox, resizeEdges, resizeSubject, type ResizeSubject } from './resizeBox';\nimport { screenOf } from './screen';\nimport type { SnapCollect, SnapMark, SnapProbeAt, SnapSource } from './types';\n\ntype Point = { x: number; y: number };\n\n/** The canvas's reach when neither a source nor the kit settings name one. */\nexport const DEFAULT_SNAP_PX = 8;\n\n\n/** What a 2D session runs on, captured at press. */\nexport interface Session2dInputs {\n req: SnapBegin;\n /** In source order: earlier wins a full tie. */\n sources: readonly SnapSource[];\n /** At press. */\n probes: readonly SnapProbeAt[];\n /** A move's subject: its drawn box at press. */\n box?: Bounds | null;\n /** A resize's box and frame. */\n resize?: ResizeSubject | null;\n /** `id`'s drawn box now, for sources measuring the scene the way the\n * subject's box was. */\n drawnBox?: (id: string) => Bounds | undefined;\n view(): View | null;\n /** The reach of a source that sets none, in screen px. */\n reachPx: number;\n scene?: Scene<unknown, string, unknown>;\n /** `id`'s world rotation, for angle targets; undefined for a node that\n * cannot turn. */\n rotationOf?: (id: string) => number | undefined;\n store: SnapOutcomeStore;\n /** Nodes that offer no targets. Default `req.ids`. */\n exclude?: readonly string[];\n /** Where each frame's candidates are recorded, cleared at `end`. */\n debug?: DebugSink;\n}\n\n/** A snap session over a 2D canvas: ctx points are world points. */\nexport function createSession2d(inputs: Session2dInputs): SnapSession {\n const { req, store } = inputs;\n const sources = snapSourcesFor(inputs.sources, req.gesture);\n return {\n at(p, mods) {\n const delta0 = { x: p.x - req.press.x, y: p.y - req.press.y };\n const input = inputFlat(req, mods, delta0, inputs.resize);\n if (mods.suspend) {\n store.set([]);\n inputs.debug?.clearSnap();\n return outcome(req.press, closestOnFlat(input, [delta0.x, delta0.y]), false, []);\n }\n const view = inputs.view();\n const plane = req.plane?.() ?? null;\n const candidates = collectAll(inputs, sources, delta0, view, plane);\n const res = resolveSnap({\n probes: inputs.probes.map((q) => ({ id: q.id, at: [q.at.x, q.at.y], role: q.role })),\n input,\n delta0: [delta0.x, delta0.y],\n candidates,\n toScreen: screenOf(view, plane),\n });\n if (inputs.debug) recordSnapCandidates(inputs.debug, candidates, res.satisfied, inputs.probes, delta0, plane);\n const delta = { x: res.delta[0], y: res.delta[1] };\n const marks = resolvedSnapMarks(res.satisfied, delta);\n store.set(plane ? marks.map((m) => markFromPlane(m, plane)) : marks);\n return outcome(req.press, res.delta, res.members.length > 0, marks);\n },\n angle: (theta, mods) => angleAt(inputs, sources, theta, mods),\n end() {\n store.set([]);\n inputs.debug?.clearSnap();\n },\n };\n}\n\nfunction outcome(press: Point, delta: readonly number[], held: boolean, marks: readonly SnapMark[]): SnapOutcome {\n return { point: { x: press.x + delta[0], y: press.y + delta[1] }, held, marks };\n}\n\nfunction collectAll(\n inputs: Session2dInputs, sources: readonly SnapSource[], delta0: Point, view: View | null, plane: PlaneMap | null,\n): SnapCandidate<SnapCandidateMark<Point>>[] {\n const { req } = inputs;\n const camera = view ? Math.min(Math.abs(view.scale.x), Math.abs(view.scale.y)) : 1;\n // A plane unit is `plane.scale` camera units the other way round.\n const scale = plane ? camera / Math.max(Math.abs(plane.scale.x), Math.abs(plane.scale.y)) : camera;\n const probes = inputs.probes.map((q) => ({ ...q, at: { x: q.at.x + delta0.x, y: q.at.y + delta0.y } }));\n return gatherSnapCandidates(sources, probes, (_source, offered, reachPx) => ({\n gesture: req.gesture, probes: offered, delta0, exclude: inputs.exclude ?? req.ids ?? [],\n ...(plane ? { plane } : {}),\n ...subjectAt(inputs, delta0),\n ...(inputs.drawnBox ? { drawnBox: inputs.drawnBox } : {}),\n ...(req.origin ? { origin: req.origin } : {}),\n ...(req.also ? { also: req.also } : {}),\n reachWorld: (px) => px / scale,\n reachPx,\n ...(inputs.scene ? { scene: inputs.scene } : {}),\n }), { toVec: (p) => [p.x, p.y], reachPx: inputs.reachPx, ...(req.origin ? { origin: req.origin } : {}) });\n}\n\n/** The subject's box where `delta0` puts it, and the sides that moved. */\nfunction subjectAt(inputs: Session2dInputs, delta0: Point): Pick<SnapCollect, 'box' | 'edges'> {\n if (inputs.resize) return { box: resizedBox(inputs.resize, delta0), edges: resizeEdges(inputs.resize, delta0) };\n const b = inputs.req.gesture === 'move' ? inputs.box : null;\n return b ? { box: { ...b, x: b.x + delta0.x, y: b.y + delta0.y } } : {};\n}\n\n/** A session no source answers: it only holds the point to the gesture's\n * input subspace, as when a host provides no `snap` dep. */\nexport function inputSession(req: SnapBegin): SnapSession {\n return createSession2d({\n req,\n sources: [],\n probes: [],\n resize: req.gesture === 'resize' && req.handle && req.box ? resizeSubject(req.box, req.handle) : null,\n view: () => null,\n reachPx: 0,\n store: createSnapOutcomeStore(),\n });\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAa,kBAAkB;;AAgC/B,SAAgB,gBAAgB,QAAsC;CACpE,MAAM,EAAE,KAAK,UAAU;CACvB,MAAM,UAAU,eAAe,OAAO,SAAS,IAAI,OAAO;CAC1D,OAAO;EACL,GAAG,GAAG,MAAM;GACV,MAAM,SAAS;IAAE,GAAG,EAAE,IAAI,IAAI,MAAM;IAAG,GAAG,EAAE,IAAI,IAAI,MAAM;GAAE;GAC5D,MAAM,QAAQ,UAAU,KAAK,MAAM,QAAQ,OAAO,MAAM;GACxD,IAAI,KAAK,SA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QAAQ,MAAM;CAAE;CAC9G,MAAM,IAAI,OAAO,IAAI,YAAY,SAAS,OAAO,MAAM;CACvD,OAAO,IAAI,EAAE,KAAK;EAAE,GAAG;EAAG,GAAG,EAAE,IAAI,OAAO;EAAG,GAAG,EAAE,IAAI,OAAO;CAAE,EAAE,IAAI,CAAC;AACxE;;;AAIA,SAAgB,aAAa,KAA6B;CACxD,OAAO,gBAAgB;EACrB;EACA,SAAS,CAAC;EACV,QAAQ,CAAC;EACT,QAAQ,IAAI,YAAY,YAAY,IAAI,UAAU,IAAI,MAAM,cAAc,IAAI,KAAK,IAAI,MAAM,IAAI;EACjG,YAAY;EACZ,SAAS;EACT,OAAO,uBAAuB;CAChC,CAAC;AACH"}
1
+ {"version":3,"file":"session2d.js","names":[],"sources":["../../../src/features/snap/session2d.ts"],"sourcesContent":["import { closestOnFlat, resolveSnap, type SnapCandidate } from '@weasel-js/geom/nd';\nimport type { View } from '@weasel-js/geom';\nimport type { DebugSink } from '@weasel-js/routing';\nimport type { Scene } from 'core/scene/types';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport type { PlaneMap } from 'core/viewport/parallax';\nimport type { SnapBegin, SnapOutcome, SnapSession } from 'interactions/actions/snapDep';\nimport { angleAt } from './angle2d';\nimport { inputFlat } from './inputSubspace';\nimport { gatherSnapCandidates, resolvedSnapMarks, snapSourcesFor, type SnapCandidateMark } from './gather';\nimport { recordSnapCandidates } from './debugCandidates';\nimport { markFromPlane } from './marks';\nimport { createSnapOutcomeStore, type SnapOutcomeStore } from './outcomeStore';\nimport { resizedBox, resizeEdges, resizeSubject, type ResizeSubject } from './resizeBox';\nimport { screenOf } from './screen';\nimport type { SnapCollect, SnapMark, SnapProbeAt, SnapSource } from './types';\n\ntype Point = { x: number; y: number };\n\n/** The canvas's reach when neither a source nor the kit settings name one. */\nexport const DEFAULT_SNAP_PX = 8;\n\n/** What a 2D session runs on, captured at press. */\nexport interface Session2dInputs {\n req: SnapBegin;\n /** In source order: earlier wins a full tie. */\n sources: readonly SnapSource[];\n /** At press. */\n probes: readonly SnapProbeAt[];\n /** A move's subject: its drawn box at press. */\n box?: Bounds | null;\n /** A resize's box and frame. */\n resize?: ResizeSubject | null;\n /** `id`'s drawn box now, for sources measuring the scene the way the\n * subject's box was. */\n drawnBox?: (id: string) => Bounds | undefined;\n view(): View | null;\n /** The reach of a source that sets none, in screen px. */\n reachPx: number;\n scene?: Scene<unknown, string, unknown>;\n /** `id`'s world rotation, for angle targets; undefined for a node that\n * cannot turn. */\n rotationOf?: (id: string) => number | undefined;\n store: SnapOutcomeStore;\n /** Nodes that offer no targets. Default `req.ids`. */\n exclude?: readonly string[];\n /** Where each frame's candidates are recorded, cleared at `end`. */\n debug?: DebugSink;\n}\n\n/** A snap session over a 2D canvas: ctx points are world points. */\nexport function createSession2d(inputs: Session2dInputs): SnapSession {\n const { req, store } = inputs;\n const sources = snapSourcesFor(inputs.sources, req.gesture);\n const fixed = collectAtPress(inputs);\n return {\n at(p, mods) {\n const delta0 = { x: p.x - req.press.x, y: p.y - req.press.y };\n const input = inputFlat(req, mods, delta0, inputs.resize);\n if (mods.suspend) {\n store.set([]);\n inputs.debug?.clearSnap();\n return outcome(req.press, closestOnFlat(input, [delta0.x, delta0.y]), false, []);\n }\n const view = inputs.view();\n const plane = req.plane?.() ?? null;\n const subject = subjectAt(inputs, delta0);\n const candidates = collectAll(sources, inputs.probes, { ...fixed, ...subject }, { delta0, view, plane }, inputs.reachPx);\n const res = resolveSnap({\n probes: inputs.probes.map((q) => ({ id: q.id, at: [q.at.x, q.at.y], role: q.role })),\n input,\n delta0: [delta0.x, delta0.y],\n candidates,\n toScreen: screenOf(view, plane),\n });\n if (inputs.debug) recordSnapCandidates(inputs.debug, candidates, res.satisfied, inputs.probes, delta0, plane);\n const delta = { x: res.delta[0], y: res.delta[1] };\n const marks = resolvedSnapMarks(res.satisfied, delta);\n store.set(plane ? marks.map((m) => markFromPlane(m, plane)) : marks);\n return outcome(req.press, res.delta, res.members.length > 0, marks);\n },\n angle: (theta, mods) => angleAt(inputs, sources, theta, mods),\n end() {\n store.set([]);\n inputs.debug?.clearSnap();\n },\n };\n}\n\nfunction outcome(press: Point, delta: readonly number[], held: boolean, marks: readonly SnapMark[]): SnapOutcome {\n return { point: { x: press.x + delta[0], y: press.y + delta[1] }, held, marks };\n}\n\n/** What a source is told that holds from press to release. */\ntype FixedCollect = Pick<SnapCollect, 'gesture' | 'ids' | 'parent' | 'exclude' | 'drawnBox' | 'origin' | 'also' | 'scene'>;\n\n/** What changes from one frame to the next. */\ninterface Frame {\n delta0: Point;\n view: View | null;\n plane: PlaneMap | null;\n}\n\nfunction collectAtPress(inputs: Session2dInputs): FixedCollect {\n const { req } = inputs;\n return {\n gesture: req.gesture,\n ...(req.ids ? { ids: req.ids } : {}),\n ...(req.parent !== undefined ? { parent: req.parent } : {}),\n exclude: inputs.exclude ?? req.ids ?? [],\n ...(inputs.drawnBox ? { drawnBox: inputs.drawnBox } : {}),\n ...(req.origin ? { origin: req.origin } : {}),\n ...(req.also ? { also: req.also } : {}),\n ...(inputs.scene ? { scene: inputs.scene } : {}),\n };\n}\n\nfunction collectAll(\n sources: readonly SnapSource[], probesAtPress: readonly SnapProbeAt[],\n fixed: FixedCollect & Pick<SnapCollect, 'box' | 'edges'>, { delta0, view, plane }: Frame, reachPx: number,\n): SnapCandidate<SnapCandidateMark<Point>>[] {\n const camera = view ? Math.min(Math.abs(view.scale.x), Math.abs(view.scale.y)) : 1;\n // A camera unit is `plane.scale` plane units.\n const scale = plane ? camera / Math.max(Math.abs(plane.scale.x), Math.abs(plane.scale.y)) : camera;\n const probes = probesAtPress.map((q) => ({ ...q, at: { x: q.at.x + delta0.x, y: q.at.y + delta0.y } }));\n return gatherSnapCandidates(sources, probes, (_source, offered, sourceReach) => ({\n ...fixed, probes: offered, delta0,\n ...(plane ? { plane } : {}),\n reachWorld: (px) => px / scale,\n reachPx: sourceReach,\n }), { toVec: (p) => [p.x, p.y], reachPx, ...(fixed.origin ? { origin: fixed.origin } : {}) });\n}\n\n/** The subject's box where `delta0` puts it, and the sides that moved. */\nfunction subjectAt(\n { box, resize }: Pick<Session2dInputs, 'box' | 'resize'>, delta0: Point,\n): Pick<SnapCollect, 'box' | 'edges'> {\n if (resize) return { box: resizedBox(resize, delta0), edges: resizeEdges(resize, delta0) };\n return box ? { box: { ...box, x: box.x + delta0.x, y: box.y + delta0.y } } : {};\n}\n\n/** A session no source answers: it only holds the point to the gesture's\n * input subspace, as when a host provides no `snap` dep. */\nexport function inputSession(req: SnapBegin): SnapSession {\n return createSession2d({\n req,\n sources: [],\n probes: [],\n resize: req.gesture === 'resize' && req.handle && req.box ? resizeSubject(req.box, req.handle) : null,\n view: () => null,\n reachPx: 0,\n store: createSnapOutcomeStore(),\n });\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAa,kBAAkB;;AA+B/B,SAAgB,gBAAgB,QAAsC;CACpE,MAAM,EAAE,KAAK,UAAU;CACvB,MAAM,UAAU,eAAe,OAAO,SAAS,IAAI,OAAO;CAC1D,MAAM,QAAQ,eAAe,MAAM;CACnC,OAAO;EACL,GAAG,GAAG,MAAM;GACV,MAAM,SAAS;IAAE,GAAG,EAAE,IAAI,IAAI,MAAM;IAAG,GAAG,EAAE,IAAI,IAAI,MAAM;GAAE;GAC5D,MAAM,QAAQ,UAAU,KAAK,MAAM,QAAQ,OAAO,MAAM;GACxD,IAAI,KAAK,SAAS;IAChB,MAAM,IAAI,CAAC,CAAC;IACZ,OAAO,OAAO,UAAU;IACxB,OAAO,QAAQ,IAAI,OAAO,cAAc,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;GACjF;GACA,MAAM,OAAO,OAAO,KAAK;GACzB,MAAM,QAAQ,IAAI,QAAQ,KAAK;GAC/B,MAAM,UAAU,UAAU,QAAQ,MAAM;GACxC,MAAM,aAAa,WAAW,SAAS,OAAO,QAAQ;IAAE,GAAG;IAAO,GAAG;GAAQ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AAO;EAAG,GAAG,IAAI,IAAI,OAAO;CAAE,EAAE,IAAI,CAAC;AAChF;;;AAIA,SAAgB,aAAa,KAA6B;CACxD,OAAO,gBAAgB;EACrB;EACA,SAAS,CAAC;EACV,QAAQ,CAAC;EACT,QAAQ,IAAI,YAAY,YAAY,IAAI,UAAU,IAAI,MAAM,cAAc,IAAI,KAAK,IAAI,MAAM,IAAI;EACjG,YAAY;EACZ,SAAS;EACT,OAAO,uBAAuB;CAChC,CAAC;AACH"}
@@ -6,9 +6,10 @@ import { inputSession } from "./session2d.js";
6
6
  * snapped start as its `origin`, so a `constrain` step turns about the start
7
7
  * as drawn. `constrain` is read whenever the end snaps, and a new value
8
8
  * reopens the end's session. With no `snap` dep, or one that runs no
9
- * sessions, only `constrain` applies.
9
+ * sessions, only `constrain` applies. `common` goes into every session's
10
+ * request.
10
11
  */
11
- function spanSnap(dep, constrain = () => void 0) {
12
+ function spanSnap(dep, constrain = () => void 0, common = {}) {
12
13
  const begin = (req) => dep?.begin(req) ?? inputSession(req);
13
14
  let raw = {
14
15
  x: 0,
@@ -24,6 +25,7 @@ function spanSnap(dep, constrain = () => void 0) {
24
25
  live?.session.end();
25
26
  live = {
26
27
  session: begin({
28
+ ...common,
27
29
  gesture: "point",
28
30
  press: start,
29
31
  origin: start,
@@ -38,6 +40,7 @@ function spanSnap(dep, constrain = () => void 0) {
38
40
  live?.session.end();
39
41
  live = null;
40
42
  const out = begin({
43
+ ...common,
41
44
  gesture: "point",
42
45
  press: p
43
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"spanSnap.js","names":[],"sources":["../../../src/features/snap/spanSnap.ts"],"sourcesContent":["import type { SnapBegin, SnapConstrain, SnapDep, SnapMods, SnapOutcome, SnapSession } from 'interactions/actions/snapDep';\nimport { inputSession } from './session2d';\n\ntype Point = { x: number; y: number };\n\n/** A two-point gesture's snapping: a drawn line, a measurement, a box. */\nexport interface SpanSnap {\n /** Snap the start, pressed at `p`. The end then snaps about where it lands. */\n start(p: Point, mods: SnapMods): SnapOutcome;\n /** Move the start by `(dx, dy)` from where it was pressed or last carried\n * to, unsnapped, and snap it there. */\n carry(dx: number, dy: number, mods: SnapMods): SnapOutcome;\n /** Snap the end. */\n end(p: Point, mods: SnapMods): SnapOutcome;\n /** Turn the end about `p`, a start placed by something other than this\n * snap. */\n anchor(p: Point): void;\n /** Whether a target holds the start. */\n startHeld(): boolean;\n /** Clears the gesture's marks. */\n close(): void;\n}\n\n/**\n * A `point` session for each end of a span. The end's session has the\n * snapped start as its `origin`, so a `constrain` step turns about the start\n * as drawn. `constrain` is read whenever the end snaps, and a new value\n * reopens the end's session. With no `snap` dep, or one that runs no\n * sessions, only `constrain` applies.\n */\nexport function spanSnap(dep: SnapDep | undefined, constrain: () => SnapConstrain | undefined = () => undefined): SpanSnap {\n const begin = (req: SnapBegin): SnapSession => dep?.begin(req) ?? inputSession(req);\n let raw: Point = { x: 0, y: 0 };\n let start: Point = raw;\n let held = false;\n let live: { session: SnapSession; key: string } | null = null;\n\n const open = (): SnapSession => {\n const c = constrain();\n const key = JSON.stringify(c ?? null);\n if (live?.key === key) return live.session;\n live?.session.end();\n live = { session: begin({ gesture: 'point', press: start, origin: start, ...(c ? { constrain: c } : {}) }), key };\n return live.session;\n };\n const place = (p: Point, mods: SnapMods): SnapOutcome => {\n raw = p;\n live?.session.end();\n live = null;\n const out = begin({ gesture: 'point', press: p });\n const landed = out.at(p, mods);\n out.end();\n start = landed.point;\n held = landed.held;\n // Draws the start's marks again, from the session the end runs in.\n open().at(start, { ...mods, constrain: false });\n return landed;\n };\n\n return {\n start: place,\n carry: (dx, dy, mods) => place({ x: raw.x + dx, y: raw.y + dy }, mods),\n end: (p, mods) => open().at(p, mods),\n anchor(p) {\n if (p.x === start.x && p.y === start.y) return;\n start = p;\n live?.session.end();\n live = null;\n },\n startHeld: () => held,\n close() {\n live?.session.end();\n live = null;\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAgB,SAAS,KAA0B,kBA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spanSnap.js","names":[],"sources":["../../../src/features/snap/spanSnap.ts"],"sourcesContent":["import type { SnapBegin, SnapConstrain, SnapDep, SnapMods, SnapOutcome, SnapSession } from 'interactions/actions/snapDep';\nimport { inputSession } from './session2d';\n\ntype Point = { x: number; y: number };\n\n/** A two-point gesture's snapping: a drawn line, a measurement, a box. */\nexport interface SpanSnap {\n /** Snap the start, pressed at `p`. The end then snaps about where it lands. */\n start(p: Point, mods: SnapMods): SnapOutcome;\n /** Move the start by `(dx, dy)` from where it was pressed or last carried\n * to, unsnapped, and snap it there. */\n carry(dx: number, dy: number, mods: SnapMods): SnapOutcome;\n /** Snap the end. */\n end(p: Point, mods: SnapMods): SnapOutcome;\n /** Turn the end about `p`, a start placed by something other than this\n * snap. */\n anchor(p: Point): void;\n /** Whether a target holds the start. */\n startHeld(): boolean;\n /** Clears the gesture's marks. */\n close(): void;\n}\n\n/**\n * A `point` session for each end of a span. The end's session has the\n * snapped start as its `origin`, so a `constrain` step turns about the start\n * as drawn. `constrain` is read whenever the end snaps, and a new value\n * reopens the end's session. With no `snap` dep, or one that runs no\n * sessions, only `constrain` applies. `common` goes into every session's\n * request.\n */\nexport function spanSnap(\n dep: SnapDep | undefined,\n constrain: () => SnapConstrain | undefined = () => undefined,\n common: Pick<SnapBegin, 'parent'> = {},\n): SpanSnap {\n const begin = (req: SnapBegin): SnapSession => dep?.begin(req) ?? inputSession(req);\n let raw: Point = { x: 0, y: 0 };\n let start: Point = raw;\n let held = false;\n let live: { session: SnapSession; key: string } | null = null;\n\n const open = (): SnapSession => {\n const c = constrain();\n const key = JSON.stringify(c ?? null);\n if (live?.key === key) return live.session;\n live?.session.end();\n live = { session: begin({ ...common, gesture: 'point', press: start, origin: start, ...(c ? { constrain: c } : {}) }), key };\n return live.session;\n };\n const place = (p: Point, mods: SnapMods): SnapOutcome => {\n raw = p;\n live?.session.end();\n live = null;\n const out = begin({ ...common, gesture: 'point', press: p });\n const landed = out.at(p, mods);\n out.end();\n start = landed.point;\n held = landed.held;\n // Draws the start's marks again, from the session the end runs in.\n open().at(start, { ...mods, constrain: false });\n return landed;\n };\n\n return {\n start: place,\n carry: (dx, dy, mods) => place({ x: raw.x + dx, y: raw.y + dy }, mods),\n end: (p, mods) => open().at(p, mods),\n anchor(p) {\n if (p.x === start.x && p.y === start.y) return;\n start = p;\n live?.session.end();\n live = null;\n },\n startHeld: () => held,\n close() {\n live?.session.end();\n live = null;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,SACd,KACA,kBAAmD,QACnD,SAAoC,CAAC,GAC3B;CACV,MAAM,SAAS,QAAgC,KAAK,MAAM,GAAG,KAAK,aAAa,GAAG;CAClF,IAAI,MAAa;EAAE,GAAG;EAAG,GAAG;CAAE;CAC9B,IAAI,QAAe;CACnB,IAAI,OAAO;CACX,IAAI,OAAqD;CAEzD,MAAM,aAA0B;EAC9B,MAAM,IAAI,UAAU;EACpB,MAAM,MAAM,KAAK,UAAU,KAAK,IAAI;EACpC,IAAI,MAAM,QAAQ,KAAK,OAAO,KAAK;EACnC,MAAM,QAAQ,IAAI;EAClB,OAAO;GAAE,SAAS,MAAM;IAAE,GAAG;IAAQ,SAAS;IAAS,OAAO;IAAO,QAAQ;IAAO,GAAI,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC;GAAG,CAAC;GAAG;EAAI;EAC3H,OAAO,KAAK;CACd;CACA,MAAM,SAAS,GAAU,SAAgC;EACvD,MAAM;EACN,MAAM,QAAQ,IAAI;EAClB,OAAO;EACP,MAAM,MAAM,MAAM;GAAE,GAAG;GAAQ,SAAS;GAAS,OAAO;EAAE,CAAC;EAC3D,MAAM,SAAS,IAAI,GAAG,GAAG,IAAI;EAC7B,IAAI,IAAI;EACR,QAAQ,OAAO;EACf,OAAO,OAAO;EAEd,KAAK,CAAC,CAAC,GAAG,OAAO;GAAE,GAAG;GAAM,WAAW;EAAM,CAAC;EAC9C,OAAO;CACT;CAEA,OAAO;EACL,OAAO;EACP,QAAQ,IAAI,IAAI,SAAS,MAAM;GAAE,GAAG,IAAI,IAAI;GAAI,GAAG,IAAI,IAAI;EAAG,GAAG,IAAI;EACrE,MAAM,GAAG,SAAS,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI;EACnC,OAAO,GAAG;GACR,IAAI,EAAE,MAAM,MAAM,KAAK,EAAE,MAAM,MAAM,GAAG;GACxC,QAAQ;GACR,MAAM,QAAQ,IAAI;GAClB,OAAO;EACT;EACA,iBAAiB;EACjB,QAAQ;GACN,MAAM,QAAQ,IAAI;GAClB,OAAO;EACT;CACF;AACF"}
@@ -0,0 +1,65 @@
1
+ import { sceneDependentsOf } from "../../core/scene/dependents.js";
2
+ import { asNodeId } from "../../core/scene/types.js";
3
+
4
+ //#region src/features/text/sceneTextDrafts.ts
5
+ /**
6
+ * A text edit written through to the scene keystroke by keystroke, for a node
7
+ * the canvas shows somewhere besides the overlay: text something derives
8
+ * from, such as the hidden text a path effect lays along a path.
9
+ */
10
+ /** `data` with an edit's text, runs and style folded in through the options' setters, for one `scene.update`. */
11
+ function editedData(data, edit, { setText, setRuns, setStyle }) {
12
+ let next = setText ? setText(data, edit.text) : {
13
+ ...data,
14
+ text: edit.text
15
+ };
16
+ if (edit.runs) next = setRuns ? setRuns(next, [...edit.runs]) : {
17
+ ...next,
18
+ runs: edit.runs
19
+ };
20
+ if (edit.style) next = setStyle ? setStyle(next, edit.style) : {
21
+ ...next,
22
+ style: edit.style
23
+ };
24
+ return next;
25
+ }
26
+ var nextSession = 0;
27
+ /** Where an edit's writes go. Each `draft` is written through when something derives from the node; the `commit`
28
+ * writes the result; `end` closes the edit, first putting back the data the drafts replaced when no commit came. All
29
+ * the writes of one edit fold into one undo entry, so a commit undoes to the text before the first draft, and a
30
+ * cancel leaves an entry that changes nothing. */
31
+ function sceneTextDrafts(sceneRef, optsRef) {
32
+ let from = null;
33
+ let session = nextSession++;
34
+ const write = (id, data) => {
35
+ const scene = sceneRef.current;
36
+ scene.batch("Edit text", () => scene.update(asNodeId(id), { data }), { coalesceKey: `text-edit:${id}:${session}` });
37
+ };
38
+ return {
39
+ draft: (id, draft) => {
40
+ const scene = sceneRef.current;
41
+ const nid = asNodeId(id);
42
+ const node = scene.get(nid);
43
+ if (!node || sceneDependentsOf(scene, nid).length === 0) return;
44
+ if (from?.id !== id) from = {
45
+ id,
46
+ data: node.data
47
+ };
48
+ write(id, editedData(node.data, draft, optsRef.current));
49
+ },
50
+ commit: (id, data) => {
51
+ from = null;
52
+ write(id, data);
53
+ },
54
+ end: (id) => {
55
+ const held = from;
56
+ from = null;
57
+ if (held?.id === id && sceneRef.current.get(asNodeId(id))) write(id, held.data);
58
+ session = nextSession++;
59
+ }
60
+ };
61
+ }
62
+
63
+ //#endregion
64
+ export { editedData, sceneTextDrafts };
65
+ //# sourceMappingURL=sceneTextDrafts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sceneTextDrafts.js","names":[],"sources":["../../../src/features/text/sceneTextDrafts.ts"],"sourcesContent":["/**\n * A text edit written through to the scene keystroke by keystroke, for a node\n * the canvas shows somewhere besides the overlay: text something derives\n * from, such as the hidden text a path effect lays along a path.\n */\nimport { sceneDependentsOf } from '../../core/scene/dependents';\nimport { asNodeId, type Scene } from '../../core/scene/types';\nimport type { StyledRun, TextStyle } from '@weasel-js/text';\nimport type { TextEditDraft } from '@weasel-js/text-dom';\nimport type { DefaultTextData, UseSceneTextEditOptions } from './useSceneTextEdit';\n\n/** `data` with an edit's text, runs and style folded in through the options' setters, for one `scene.update`. */\nexport function editedData<TData extends DefaultTextData>(\n data: TData,\n edit: { text: string; runs?: readonly StyledRun[]; style?: TextStyle },\n { setText, setRuns, setStyle }: UseSceneTextEditOptions<TData>,\n): TData {\n let next = setText ? setText(data, edit.text) : { ...data, text: edit.text };\n if (edit.runs) next = setRuns ? setRuns(next, [...edit.runs]) : { ...next, runs: edit.runs };\n if (edit.style) next = setStyle ? setStyle(next, edit.style) : { ...next, style: edit.style };\n return next;\n}\n\n// Shared by every instance, so two editors of one node never fold their edits together.\nlet nextSession = 0;\n\n/** Where an edit's writes go. Each `draft` is written through when something derives from the node; the `commit`\n * writes the result; `end` closes the edit, first putting back the data the drafts replaced when no commit came. All\n * the writes of one edit fold into one undo entry, so a commit undoes to the text before the first draft, and a\n * cancel leaves an entry that changes nothing. */\nexport function sceneTextDrafts<TData extends DefaultTextData, TLayer extends string, TPose>(\n sceneRef: { readonly current: Scene<TData, TLayer, TPose> },\n optsRef: { readonly current: UseSceneTextEditOptions<TData> },\n): {\n draft: (id: string, draft: TextEditDraft) => void;\n commit: (id: string, data: TData) => void;\n end: (id: string) => void;\n} {\n let from: { id: string; data: TData } | null = null;\n let session = nextSession++;\n const write = (id: string, data: TData): void => {\n const scene = sceneRef.current;\n scene.batch('Edit text', () => scene.update(asNodeId(id), { data }), { coalesceKey: `text-edit:${id}:${session}` });\n };\n return {\n draft: (id, draft) => {\n const scene = sceneRef.current;\n const nid = asNodeId(id);\n const node = scene.get(nid);\n if (!node || sceneDependentsOf(scene, nid).length === 0) return;\n if (from?.id !== id) from = { id, data: node.data };\n write(id, editedData(node.data, draft, optsRef.current));\n },\n commit: (id, data) => {\n from = null;\n write(id, data);\n },\n end: (id) => {\n const held = from;\n from = null;\n if (held?.id === id && sceneRef.current.get(asNodeId(id))) write(id, held.data);\n session = nextSession++;\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,WACd,MACA,MACA,EAAE,SAAS,SAAS,YACb;CACP,IAAI,OAAO,UAAU,QAAQ,MAAM,KAAK,IAAI,IAAI;EAAE,GAAG;EAAM,MAAM,KAAK;CAAK;CAC3E,IAAI,KAAK,MAAM,OAAO,UAAU,QAAQ,MAAM,CAAC,GAAG,KAAK,IAAI,CAAC,IAAI;EAAE,GAAG;EAAM,MAAM,KAAK;CAAK;CAC3F,IAAI,KAAK,OAAO,OAAO,WAAW,SAAS,MAAM,KAAK,KAAK,IAAI;EAAE,GAAG;EAAM,OAAO,KAAK;CAAM;CAC5F,OAAO;AACT;AAGA,IAAI,cAAc;;;;;AAMlB,SAAgB,gBACd,UACA,SAKA;CACA,IAAI,OAA2C;CAC/C,IAAI,UAAU;CACd,MAAM,SAAS,IAAY,SAAsB;EAC/C,MAAM,QAAQ,SAAS;EACvB,MAAM,MAAM,mBAAmB,MAAM,OAAO,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,aAAa,aAAa,GAAG,GAAG,UAAU,CAAC;CACpH;CACA,OAAO;EACL,QAAQ,IAAI,UAAU;GACpB,MAAM,QAAQ,SAAS;GACvB,MAAM,MAAM,SAAS,EAAE;GACvB,MAAM,OAAO,MAAM,IAAI,GAAG;GAC1B,IAAI,CAAC,QAAQ,kBAAkB,OAAO,GAAG,CAAC,CAAC,WAAW,GAAG;GACzD,IAAI,MAAM,OAAO,IAAI,OAAO;IAAE;IAAI,MAAM,KAAK;GAAK;GAClD,MAAM,IAAI,WAAW,KAAK,MAAM,OAAO,QAAQ,OAAO,CAAC;EACzD;EACA,SAAS,IAAI,SAAS;GACpB,OAAO;GACP,MAAM,IAAI,IAAI;EAChB;EACA,MAAM,OAAO;GACX,MAAM,OAAO;GACb,OAAO;GACP,IAAI,MAAM,OAAO,MAAM,SAAS,QAAQ,IAAI,SAAS,EAAE,CAAC,GAAG,MAAM,IAAI,KAAK,IAAI;GAC9E,UAAU;EACZ;CACF;AACF"}
@@ -1,6 +1,9 @@
1
+ import { derivedPartsOf } from "../../core/scene/derivedParts.js";
1
2
  import { targetTransformOf, worldToLocal } from "../../core/geometry/targetFrame.js";
2
3
  import { textBoxOf } from "../../canvas/nodeShapes/textPainter.js";
3
- import { scenePaintedPoseOf } from "../../canvas/derivedPath.js";
4
+ import { sceneDerivedPathOf, scenePaintedPoseOf } from "../../canvas/derivedPath.js";
5
+ import { effectSourceFor } from "../pathEffects/effectSources.js";
6
+ import { boundsOfPath, pathContainsPoint } from "@weasel-js/geom";
4
7
  import { caretIndexAt, pointInTextPose } from "@weasel-js/text";
5
8
 
6
9
  //#region src/features/text/textHitAt.ts
@@ -10,14 +13,30 @@ import { caretIndexAt, pointInTextPose } from "@weasel-js/text";
10
13
  * `pointInTextPose` and `caretIndexAt` work in the node's own box, so the
11
14
  * point is taken back through the frame the node is drawn in. The whole box
12
15
  * takes the point, padding included; the caret is placed in the inset one.
16
+ *
17
+ * A path effect hiding a text source answers for it within the bounds of any
18
+ * glyph it lays, counters included, with the caret at the end of the text.
19
+ * A curved glyph takes a double-click anywhere in its axis-aligned box, wider
20
+ * than the ink selection picks.
13
21
  */
14
22
  function textHitAt(scene, read, cx, cy) {
15
23
  const order = scene.renderOrderNodes();
16
24
  const paintedPoseOf = scenePaintedPoseOf(scene);
25
+ const derivedPathOf = sceneDerivedPathOf(scene);
17
26
  for (let i = order.length - 1; i >= 0; i--) {
18
27
  const node = order[i];
19
28
  if (scene.isLocked(node.id) || scene.isHidden(node.id)) continue;
20
- if (!read.isText(node.data)) continue;
29
+ if (!read.isText(node.data)) {
30
+ const source = effectSourceFor(scene, node.id, "text");
31
+ const text = source === null || scene.isLocked(source) ? void 0 : scene.get(source);
32
+ if (text === void 0 || !read.isText(text.data)) continue;
33
+ const path = derivedPathOf(node);
34
+ if (path !== null && onAGlyph(path, cx, cy)) return {
35
+ id: String(source),
36
+ caret: read.text(text.data).length
37
+ };
38
+ continue;
39
+ }
21
40
  const at = paintedPoseOf(node);
22
41
  const p = worldToLocal(targetTransformOf(at), cx, cy);
23
42
  if (!p) continue;
@@ -45,6 +64,16 @@ function textHitAt(scene, read, cx, cy) {
45
64
  }
46
65
  return null;
47
66
  }
67
+ /** Whether `(x, y)` is within the bounds of one of `path`'s parts: a glyph's box, so a stem too thin to land on and the
68
+ * hole in an o still take the click. */
69
+ function onAGlyph(path, x, y) {
70
+ const parts = derivedPartsOf(path);
71
+ if (parts === void 0) return pathContainsPoint(path, x, y);
72
+ return parts.some(({ path: part }) => {
73
+ const b = boundsOfPath(part);
74
+ return x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;
75
+ });
76
+ }
48
77
 
49
78
  //#endregion
50
79
  export { textHitAt };
@@ -1 +1 @@
1
- {"version":3,"file":"textHitAt.js","names":[],"sources":["../../../src/features/text/textHitAt.ts"],"sourcesContent":["import type { Scene } from '../../core/scene/types';\nimport type { RectPose } from 'core/geometry/unionBounds';\nimport { scenePaintedPoseOf } from '../../canvas/derivedPath';\nimport { targetTransformOf, worldToLocal } from 'core/geometry/targetFrame';\nimport { caretIndexAt, pointInTextPose, type StyledRun, type TextStyle, type TextVerticalAlign } from '@weasel-js/text';\nimport { textBoxOf } from '../../canvas/nodeShapes/textPainter';\n\n/** How a node's text fields are read from its `data`. */\nexport interface TextReads<TData> {\n isText(data: TData): boolean;\n text(data: TData): string;\n style(data: TData): TextStyle | undefined;\n runs(data: TData): readonly StyledRun[] | undefined;\n verticalAlign(data: TData): TextVerticalAlign | undefined;\n padding(data: TData): number | undefined;\n}\n\n/**\n * The top-most unlocked text node at world `(cx, cy)`, and the caret there.\n *\n * `pointInTextPose` and `caretIndexAt` work in the node's own box, so the\n * point is taken back through the frame the node is drawn in. The whole box\n * takes the point, padding included; the caret is placed in the inset one.\n */\nexport function textHitAt<TData, TPose extends RectPose>(\n scene: Scene<TData, string, TPose>,\n read: TextReads<TData>,\n cx: number,\n cy: number,\n): { id: string; caret: number } | null {\n // renderOrder() is back-to-front, so iterate in reverse and stop on the first hit.\n const order = scene.renderOrderNodes();\n const paintedPoseOf = scenePaintedPoseOf(scene);\n for (let i = order.length - 1; i >= 0; i--) {\n const node = order[i];\n if (scene.isLocked(node.id) || scene.isHidden(node.id)) continue;\n if (!read.isText(node.data)) continue;\n const at = paintedPoseOf(node);\n const p = worldToLocal(targetTransformOf(at), cx, cy);\n if (!p) continue;\n const pose = {\n ...textBoxOf({ padding: read.padding(node.data) }, at),\n text: read.text(node.data),\n runs: read.runs(node.data) as StyledRun[] | undefined,\n style: read.style(node.data),\n verticalAlign: read.verticalAlign(node.data),\n };\n const box = { x: at.x, y: at.y, width: at.width, height: at.height };\n if (!pointInTextPose(p.x, p.y, { ...pose, ...box })) continue;\n return { id: String(node.id), caret: caretIndexAt(p.x, p.y, pose) };\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,UACd,OACA,MACA,IACA,IACsC;CAEtC,MAAM,QAAQ,MAAM,iBAAiB;CACrC,MAAM,gBAAgB,mBAAmB,KAAK;CAC9C,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,OAAO,MAAM;EACnB,IAAI,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,SAAS,KAAK,EAAE,GAAG;EACxD,IAAI,CAAC,KAAK,OAAO,KAAK,IAAI,GAAG;EAC7B,MAAM,KAAK,cAAc,IAAI;EAC7B,MAAM,IAAI,aAAa,kBAAkB,EAAE,GAAG,IAAI,EAAE;EACpD,IAAI,CAAC,GAAG;EACR,MAAM,OAAO;GACX,GAAG,UAAU,EAAE,SAAS,KAAK,QAAQ,KAAK,IAAI,EAAE,GAAG,EAAE;GACrD,MAAM,KAAK,KAAK,KAAK,IAAI;GACzB,MAAM,KAAK,KAAK,KAAK,IAAI;GACzB,OAAO,KAAK,MAAM,KAAK,IAAI;GAC3B,eAAe,KAAK,cAAc,KAAK,IAAI;EAC7C;EACA,MAAM,MAAM;GAAE,GAAG,GAAG;GAAG,GAAG,GAAG;GAAG,OAAO,GAAG;GAAO,QAAQ,GAAG;EAAO;EACnE,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,GAAG;GAAE,GAAG;GAAM,GAAG;EAAI,CAAC,GAAG;EACrD,OAAO;GAAE,IAAI,OAAO,KAAK,EAAE;GAAG,OAAO,aAAa,EAAE,GAAG,EAAE,GAAG,IAAI;EAAE;CACpE;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"textHitAt.js","names":[],"sources":["../../../src/features/text/textHitAt.ts"],"sourcesContent":["import type { Scene } from '../../core/scene/types';\nimport type { RectPose } from 'core/geometry/unionBounds';\nimport { boundsOfPath, pathContainsPoint, type Path } from '@weasel-js/geom';\nimport { sceneDerivedPathOf, scenePaintedPoseOf } from '../../canvas/derivedPath';\nimport { derivedPartsOf } from '../../core/scene/derivedParts';\nimport { effectSourceFor } from '../pathEffects/effectSources';\nimport { targetTransformOf, worldToLocal } from 'core/geometry/targetFrame';\nimport { caretIndexAt, pointInTextPose, type StyledRun, type TextStyle, type TextVerticalAlign } from '@weasel-js/text';\nimport { textBoxOf } from '../../canvas/nodeShapes/textPainter';\n\n/** How a node's text fields are read from its `data`. */\nexport interface TextReads<TData> {\n isText(data: TData): boolean;\n text(data: TData): string;\n style(data: TData): TextStyle | undefined;\n runs(data: TData): readonly StyledRun[] | undefined;\n verticalAlign(data: TData): TextVerticalAlign | undefined;\n padding(data: TData): number | undefined;\n}\n\n/**\n * The top-most unlocked text node at world `(cx, cy)`, and the caret there.\n *\n * `pointInTextPose` and `caretIndexAt` work in the node's own box, so the\n * point is taken back through the frame the node is drawn in. The whole box\n * takes the point, padding included; the caret is placed in the inset one.\n *\n * A path effect hiding a text source answers for it within the bounds of any\n * glyph it lays, counters included, with the caret at the end of the text.\n * A curved glyph takes a double-click anywhere in its axis-aligned box, wider\n * than the ink selection picks.\n */\nexport function textHitAt<TData, TPose extends RectPose>(\n scene: Scene<TData, string, TPose>,\n read: TextReads<TData>,\n cx: number,\n cy: number,\n): { id: string; caret: number } | null {\n // renderOrder() is back-to-front, so iterate in reverse and stop on the first hit.\n const order = scene.renderOrderNodes();\n const paintedPoseOf = scenePaintedPoseOf(scene);\n const derivedPathOf = sceneDerivedPathOf(scene);\n for (let i = order.length - 1; i >= 0; i--) {\n const node = order[i];\n if (scene.isLocked(node.id) || scene.isHidden(node.id)) continue;\n if (!read.isText(node.data)) {\n const source = effectSourceFor(scene, node.id, 'text');\n const text = source === null || scene.isLocked(source) ? undefined : scene.get(source);\n if (text === undefined || !read.isText(text.data)) continue;\n const path = derivedPathOf(node);\n if (path !== null && onAGlyph(path, cx, cy)) return { id: String(source), caret: read.text(text.data).length };\n continue;\n }\n const at = paintedPoseOf(node);\n const p = worldToLocal(targetTransformOf(at), cx, cy);\n if (!p) continue;\n const pose = {\n ...textBoxOf({ padding: read.padding(node.data) }, at),\n text: read.text(node.data),\n runs: read.runs(node.data) as StyledRun[] | undefined,\n style: read.style(node.data),\n verticalAlign: read.verticalAlign(node.data),\n };\n const box = { x: at.x, y: at.y, width: at.width, height: at.height };\n if (!pointInTextPose(p.x, p.y, { ...pose, ...box })) continue;\n return { id: String(node.id), caret: caretIndexAt(p.x, p.y, pose) };\n }\n return null;\n}\n\n/** Whether `(x, y)` is within the bounds of one of `path`'s parts: a glyph's box, so a stem too thin to land on and the\n * hole in an o still take the click. */\nfunction onAGlyph(path: Path, x: number, y: number): boolean {\n const parts = derivedPartsOf(path);\n if (parts === undefined) return pathContainsPoint(path, x, y);\n return parts.some(({ path: part }) => {\n const b = boundsOfPath(part);\n return x >= b.x && x <= b.x + b.width && y >= b.y && y <= b.y + b.height;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,UACd,OACA,MACA,IACA,IACsC;CAEtC,MAAM,QAAQ,MAAM,iBAAiB;CACrC,MAAM,gBAAgB,mBAAmB,KAAK;CAC9C,MAAM,gBAAgB,mBAAmB,KAAK;CAC9C,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,OAAO,MAAM;EACnB,IAAI,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,SAAS,KAAK,EAAE,GAAG;EACxD,IAAI,CAAC,KAAK,OAAO,KAAK,IAAI,GAAG;GAC3B,MAAM,SAAS,gBAAgB,OAAO,KAAK,IAAI,MAAM;GACrD,MAAM,OAAO,WAAW,QAAQ,MAAM,SAAS,MAAM,IAAI,SAAY,MAAM,IAAI,MAAM;GACrF,IAAI,SAAS,UAAa,CAAC,KAAK,OAAO,KAAK,IAAI,GAAG;GACnD,MAAM,OAAO,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../../canvas/inheritedPaints.js";
1
3
  import { textBoxOf } from "../../canvas/nodeShapes/textPainter.js";
2
4
  import { asNodeId } from "../../core/scene/types.js";
3
5
  import { scenePaintedPoseOf } from "../../canvas/derivedPath.js";
4
6
  import { findMountedCanvas } from "../../canvas/mountedCanvases.js";
5
7
  import { drawOneEditing } from "./editingDrawOne.js";
6
8
  import { textHitAt } from "./textHitAt.js";
9
+ import { editedData, sceneTextDrafts } from "./sceneTextDrafts.js";
7
10
  import { poseFrameOf } from "@weasel-js/geom";
8
11
  import { useCallback, useMemo, useRef } from "react";
9
12
  import { useLatest } from "@weasel-js/react";
@@ -47,6 +50,7 @@ function useSceneTextEdit(scene, container, options = {}) {
47
50
  const optsRef = useLatest(options);
48
51
  const containerRef = useLatest(container);
49
52
  const openedOnRef = useRef(null);
53
+ const drafts = useMemo(() => sceneTextDrafts(sceneRef, optsRef), [sceneRef, optsRef]);
50
54
  const surface = () => {
51
55
  const root = containerRef.current;
52
56
  const canvas = root ? findMountedCanvas(root, openedOnRef.current) : null;
@@ -70,7 +74,11 @@ function useSceneTextEdit(scene, container, options = {}) {
70
74
  escape: options.escape,
71
75
  fontHold: options.fontHold,
72
76
  onStart: (id) => optsRef.current.onStart?.(id),
73
- onEnd: (id) => optsRef.current.onEnd?.(id),
77
+ onEnd: (id) => {
78
+ drafts.end(id);
79
+ optsRef.current.onEnd?.(id);
80
+ },
81
+ onDraft: drafts.draft,
74
82
  getText: (id) => {
75
83
  const node = sceneRef.current.get(asNodeId(id));
76
84
  return node ? read.text(node.data) : "";
@@ -83,10 +91,7 @@ function useSceneTextEdit(scene, container, options = {}) {
83
91
  const node = sceneRef.current.get(asNodeId(id));
84
92
  if (!node) return void 0;
85
93
  const get = optsRef.current.getPaint;
86
- return get ? get(node.data) : {
87
- fill: node.data.fill,
88
- stroke: node.data.stroke
89
- };
94
+ return get ? get(node.data) : shownTextPaint(sceneRef.current, node);
90
95
  },
91
96
  getScreenPose: (id) => {
92
97
  const scene = sceneRef.current;
@@ -105,20 +110,11 @@ function useSceneTextEdit(scene, container, options = {}) {
105
110
  const nid = asNodeId(id);
106
111
  const node = sceneRef.current.get(nid);
107
112
  if (!node) return;
108
- const { setText, setRuns, setStyle } = optsRef.current;
109
- let data = setText ? setText(node.data, text) : {
110
- ...node.data,
111
- text
112
- };
113
- if (runs) data = setRuns ? setRuns(data, runs) : {
114
- ...data,
115
- runs
116
- };
117
- if (style) data = setStyle ? setStyle(data, style) : {
118
- ...data,
113
+ drafts.commit(id, editedData(node.data, {
114
+ text,
115
+ runs,
119
116
  style
120
- };
121
- sceneRef.current.update(nid, { data });
117
+ }, optsRef.current));
122
118
  }
123
119
  });
124
120
  const onDoubleClick = useCallback((e) => {
@@ -219,6 +215,14 @@ function frameLinearOf(pose, stretch) {
219
215
  d * stretch
220
216
  ];
221
217
  }
218
+ /** A text node's paint as the canvas paints it: an inherited one is its container's. */
219
+ function shownTextPaint(scene, node) {
220
+ const { fill, stroke } = withInheritedPaint(node.data, inheritedPaintIn(scene, node));
221
+ return {
222
+ fill,
223
+ stroke
224
+ };
225
+ }
222
226
 
223
227
  //#endregion
224
228
  export { useSceneTextEdit };
@@ -1 +1 @@
1
- {"version":3,"file":"useSceneTextEdit.js","names":[],"sources":["../../../src/features/text/useSceneTextEdit.ts"],"sourcesContent":["/**\n * `useSceneTextEdit` — scene-aware wrapper around `useTextEdit`: scene\n * lookups for text / style / runs / screen-pose, and\n * `scene.update(id, { data })` for commits. The overlay and a double-click\n * both read the pose a node is painted at, so text inside a container whose\n * pose is a frame is edited where it is drawn.\n *\n * Defaults assume the node's `data` carries `text` / `style` / `runs`\n * directly. For custom data shapes, override any of the optional projections.\n * Consumers with non-rect poses should drop down to raw `useTextEdit` and\n * supply their own `getScreenPose`.\n */\nimport { useCallback, useMemo, useRef, type MouseEvent } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { asNodeId } from '../../core/scene/types';\nimport { scenePaintedPoseOf } from '../../canvas/derivedPath';\nimport type { Scene } from '../../core/scene/types';\nimport { drawOneEditing, type EditingDrawOne } from './editingDrawOne';\nimport { textHitAt } from './textHitAt';\nimport type { Stroke, Fill } from '@weasel-js/paint';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport { clientToCanvas } from '@weasel-js/routing';\nimport { findMountedCanvas, type MountedCanvas } from '../../canvas/mountedCanvases';\nimport type { View } from '../../core/viewport/view';\nimport type { RectPose } from 'core/geometry/unionBounds';\nimport { poseFrameOf } from '@weasel-js/geom';\nimport { isTextData, type StyledRun, type TextPaint, type TextStyle, type TextVerticalAlign } from '@weasel-js/text';\nimport { textBoxOf, type TextOverflow } from '../../canvas/nodeShapes/textPainter';\nimport { useTextEdit, type TextEditClipRect, type TextEditScreenPose, type UseTextEditReturn } from '@weasel-js/text-dom';\n\n/** Shape the default projections expect `data` to satisfy. All fields\n * optional so any object satisfies the constraint — projections fill in\n * the gaps for non-default shapes. */\nexport interface DefaultTextData {\n text?: string;\n style?: TextStyle;\n runs?: readonly StyledRun[];\n fill?: Fill | null;\n stroke?: Stroke | null;\n verticalAlign?: TextVerticalAlign;\n padding?: number;\n overflow?: TextOverflow;\n}\n\n/** All-optional projections + fontSize fallback. */\nexport interface UseSceneTextEditOptions<TData> {\n /**\n * Is this node text? A double-click opens an edit only on a node that\n * answers yes, and passes through any other to the text under it. Default:\n * `isTextData`, the test `inferredNodeRouting` classifies a text node by. Pass one when `getText` reads some other shape.\n */\n isText?: (data: TData) => boolean;\n /** Read plain text from `data`. Default: `data.text ?? ''`. */\n getText?: (data: TData) => string;\n /** Read style from `data`. Default: `data.style`. */\n getStyle?: (data: TData) => TextStyle | undefined;\n /** Read the node's paint from `data`. Default: `data.fill` / `data.stroke`. */\n getPaint?: (data: TData) => TextPaint | undefined;\n /** Read rich-text runs from `data`. Default: `data.runs`. */\n getRuns?: (data: TData) => readonly StyledRun[] | undefined;\n /** Read the box vertical alignment from `data`. Default: `data.verticalAlign`. */\n getVerticalAlign?: (data: TData) => TextVerticalAlign | undefined;\n /** Read the inset from the node's box to its text from `data`. Default: `data.padding`. */\n getPadding?: (data: TData) => number | undefined;\n /** Read whether the node cuts its text at its box from `data`, which the\n * overlay then does too. Default: `data.overflow`. */\n getOverflow?: (data: TData) => TextOverflow | undefined;\n /** Produce updated data with new text. Default: `{ ...data, text }`. */\n setText?: (data: TData, text: string) => TData;\n /** Produce updated data with new runs. Default: `{ ...data, runs }`. */\n setRuns?: (data: TData, runs: StyledRun[]) => TData;\n /**\n * Produce updated data with a new node-wide style. Default:\n * `{ ...data, style }`. Written only when a range toggle has to *clear* a\n * flag the node itself sets — the run algebra is additive, so that edit\n * lowers the node flag and raises it on the runs outside the range. See\n * `useTextEdit`'s `setStyle`.\n *\n * An edit's text, runs, and style are folded through these three and\n * written as one `scene.update`, so a commit is one undo step.\n */\n setStyle?: (data: TData, style: TextStyle) => TData;\n /** Fallback fontSize when `style.fontSize` is unset. Default `16`. */\n defaultFontSize?: number;\n /**\n * The view to project through. Omit it and the view is read live from the\n * weasel canvas mounted inside `container` (the one a double-click landed\n * on, when there are several). With no canvas there, the node's world box\n * is passed through as screen pixels.\n *\n * A thunk is re-read on every projection; a plain `View` is the value from\n * the render that supplied it.\n */\n view?: View | (() => View);\n /**\n * Forwarded to `useTextEdit`: is `el` part of the editor's own chrome?\n * Focus moving into it does not end the edit. Wire it to whatever renders\n * the character controls.\n */\n isEditorChrome?: (el: Element) => boolean;\n /** Forwarded to `useTextEdit`: what Escape does to the edit. */\n escape?: 'cancel' | 'commit';\n /** Forwarded to `useTextEdit`: how long an edit waits for its face. */\n fontHold?: number;\n /** Forwarded to `useTextEdit`: called as an edit of the node `id` opens,\n * whichever way it was started. */\n onStart?: (id: string) => void;\n /** Forwarded to `useTextEdit`: called as the edit of `id` closes, after\n * any commit has been written to the scene. */\n onEnd?: (id: string) => void;\n}\n\nfunction resolveView(view: View | (() => View) | undefined): View | undefined {\n return typeof view === 'function' ? view() : view;\n}\n\n/** Return shape extends `UseTextEditReturn` with an `onDoubleClick`\n * binding for the canvas container. Double-clicking inside a text\n * node enters edit mode with the caret seeded at the clicked glyph. */\nexport interface UseSceneTextEditReturn extends UseTextEditReturn {\n /** Bind to the element wrapping `<SceneCanvas>` (the same element\n * passed as `container`, or any ancestor that receives the dblclick\n * bubble). Starts an edit on the top-most text node under the cursor. */\n onDoubleClick: (e: MouseEvent<HTMLElement>) => void;\n /** The `isText` option asked of the node with this id: what\n * `TextEditDep.isTextNode` wants, so both ways into an edit agree. */\n isTextNode: (id: string) => boolean;\n /**\n * `defaultDrawOne`, less the glyphs of the node being edited: the overlay\n * stands in for its text, and the rest of the node, a `background` among\n * it, goes on painting. Pass it as `layers.scene.drawOne`, with\n * `paintBounds: defaultPaintBounds`, in place of an `alphaFor` that hides\n * the whole node.\n */\n drawOne: EditingDrawOne;\n}\n\n/** How each field is read from a node's `data`: the option's projection, else the default shape. */\nfunction projectionsOf<TData extends DefaultTextData>(opts: { readonly current: UseSceneTextEditOptions<TData> }) {\n return {\n isText: (data: TData): boolean =>\n opts.current.isText ? opts.current.isText(data) : isTextData(data),\n text: (data: TData): string =>\n opts.current.getText ? opts.current.getText(data) : (data.text ?? ''),\n style: (data: TData): TextStyle | undefined =>\n opts.current.getStyle ? opts.current.getStyle(data) : data.style,\n runs: (data: TData): readonly StyledRun[] | undefined =>\n opts.current.getRuns ? opts.current.getRuns(data) : data.runs,\n verticalAlign: (data: TData): TextVerticalAlign | undefined =>\n opts.current.getVerticalAlign ? opts.current.getVerticalAlign(data) : data.verticalAlign,\n padding: (data: TData): number | undefined =>\n opts.current.getPadding ? opts.current.getPadding(data) : data.padding,\n overflow: (data: TData): TextOverflow | undefined =>\n opts.current.getOverflow ? opts.current.getOverflow(data) : data.overflow,\n };\n}\n\n/** Wire double-click-to-edit text on a scene: mounts a DOM editing overlay\n * over the node being edited and writes the result back as an undoable op. */\nexport function useSceneTextEdit<\n TData extends DefaultTextData,\n TLayer extends string,\n TPose extends RectPose = RectPose,\n>(\n scene: Scene<TData, TLayer, TPose>,\n container: HTMLElement | null,\n options: UseSceneTextEditOptions<TData> = {},\n): UseSceneTextEditReturn {\n // Refs, so the useTextEdit callbacks always see the current values\n // without re-binding.\n const sceneRef = useLatest(scene);\n const optsRef = useLatest(options);\n const containerRef = useLatest(container);\n // The last double-click's target, so the overlay projects through the\n // canvas the edit was opened on.\n const openedOnRef = useRef<EventTarget | null>(null);\n\n // The canvas's box in container pixels is both the origin its view projects\n // from and the region its glyphs are clipped to.\n const surface = (): { canvas: MountedCanvas; box: TextEditClipRect } | null => {\n const root = containerRef.current;\n const canvas = root ? findMountedCanvas(root, openedOnRef.current) : null;\n if (!root || !canvas) return null;\n const a = canvas.element.getBoundingClientRect();\n const b = root.getBoundingClientRect();\n return {\n canvas,\n box: {\n x: a.left - b.left - root.clientLeft + root.scrollLeft,\n y: a.top - b.top - root.clientTop + root.scrollTop,\n width: a.width,\n height: a.height,\n },\n };\n };\n\n const read = useMemo(() => projectionsOf(optsRef), [optsRef]);\n\n const edit = useTextEdit({\n container,\n isEditorChrome: (el) => optsRef.current.isEditorChrome?.(el) ?? false,\n escape: options.escape,\n fontHold: options.fontHold,\n onStart: (id) => optsRef.current.onStart?.(id),\n onEnd: (id) => optsRef.current.onEnd?.(id),\n getText: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.text(node.data) : '';\n },\n getStyle: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.style(node.data) : undefined;\n },\n getPaint: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n if (!node) return undefined;\n const get = optsRef.current.getPaint;\n return get ? get(node.data) : { fill: node.data.fill, stroke: node.data.stroke };\n },\n getScreenPose: (id) => {\n const scene = sceneRef.current;\n const node = scene.get(asNodeId(id));\n if (!node) return null;\n const at = surface();\n const view = resolveView(optsRef.current.view) ?? at?.canvas.getView();\n return screenPoseOf(node.data, scenePaintedPoseOf(scene)(node), read, view, at?.box, optsRef.current.defaultFontSize);\n },\n getClipRect: () => surface()?.box ?? null,\n getRuns: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.runs(node.data) : undefined;\n },\n commit: (id, { text, runs, style }) => {\n const nid = asNodeId(id);\n const node = sceneRef.current.get(nid);\n if (!node) return;\n const { setText, setRuns, setStyle } = optsRef.current;\n let data = setText ? setText(node.data, text) : { ...node.data, text };\n if (runs) data = setRuns ? setRuns(data, runs) : { ...data, runs };\n if (style) data = setStyle ? setStyle(data, style) : { ...data, style };\n sceneRef.current.update(nid, { data });\n },\n });\n\n const onDoubleClick = useCallback((e: MouseEvent<HTMLElement>) => {\n // The dblclick bubbles from the canvas up to any wrapping container; the\n // element it started on is what the click coordinates are relative to.\n const canvas = e.target instanceof HTMLElement ? e.target : null;\n if (!canvas) return;\n // Inside the editor a double-click selects a word, and its target is a run\n // span whose box the click would be measured against as if it were a canvas.\n if (canvas.closest('[contenteditable=\"true\"]')) return;\n\n // The click is un-projected here; `textHitAt` takes it back through the\n // frame the node is drawn in.\n const [canvasX, canvasY] = clientToCanvas(canvas, e.clientX, e.clientY);\n const root = containerRef.current;\n const view = resolveView(optsRef.current.view)\n ?? (root ? findMountedCanvas(root, canvas)?.getView() : undefined);\n const cx = view ? canvasX / view.scale.x + view.x : canvasX;\n const cy = view ? canvasY / view.scale.y + view.y : canvasY;\n const hit = textHitAt(sceneRef.current, read, cx, cy);\n if (!hit) return;\n openedOnRef.current = canvas;\n edit.startEdit(hit.id, { caret: hit.caret });\n }, [edit, containerRef, optsRef, read, sceneRef]);\n\n const isTextNode = useCallback((id: string): boolean => {\n const node = sceneRef.current.get(asNodeId(id));\n return node !== undefined && read.isText(node.data);\n }, [read, sceneRef]);\n\n const drawOne = useMemo(() => drawOneEditing(edit.editingId), [edit.editingId]);\n return { ...edit, onDoubleClick, isTextNode, drawOne };\n}\n\n/** The overlay's pose for a node painted at `painted`: its text box, inset\n * about the box center, which is all the overlay's frame needs, projected\n * through `view`. */\nfunction screenPoseOf<TData extends DefaultTextData>(\n d: TData,\n painted: RectPose,\n read: ReturnType<typeof projectionsOf<TData>>,\n view: View | undefined,\n origin: TextEditClipRect | undefined,\n defaultFontSize = 16,\n): TextEditScreenPose {\n const inset = textBoxOf({ padding: read.padding(d) }, painted);\n const box = screenBoxOf({ ...painted, ...inset }, view, origin);\n return {\n ...box,\n // Against `zoom`, the same factor the overlay scales back up by, so a\n // `{ px }` size arrives on screen at the pixel count it names.\n fontSize: resolveScreenLength(read.style(d)?.fontSize ?? defaultFontSize, box.zoom),\n verticalAlign: read.verticalAlign(d),\n ...(read.overflow(d) === 'clip' ? { clip: clipToBox(inset, painted) } : {}),\n };\n}\n\n/** How far `box` reaches past `inner` on each side: the overlay's cut at\n * `box` when its own pose is `inner`. */\nfunction clipToBox(inner: RectPose, box: RectPose): NonNullable<TextEditScreenPose['clip']> {\n return {\n top: inner.y - box.y,\n left: inner.x - box.x,\n bottom: box.y + box.height - (inner.y + inner.height),\n right: box.x + box.width - (inner.x + inner.width),\n };\n}\n\n/**\n * `pose`'s box as the overlay takes it, `origin` being the canvas's corner in\n * container pixels. Only the box center is projected, since the overlay's\n * frame is about it. Width and height stay in world units and reach the\n * screen through the overlay's own `scale(zoom)` — see\n * `TextEditScreenPose.zoom`.\n */\nfunction screenBoxOf(\n pose: RectPose,\n view: View | undefined,\n origin: { x: number; y: number } | undefined,\n): Pick<TextEditScreenPose, 'x' | 'y' | 'width' | 'height' | 'frame'> & { zoom: number } {\n const zoom = view ? view.scale.x : 1;\n const zoomY = view ? view.scale.y : 1;\n const cx = (origin?.x ?? 0) + (pose.x + pose.width / 2 - (view?.x ?? 0)) * zoom;\n const cy = (origin?.y ?? 0) + (pose.y + pose.height / 2 - (view?.y ?? 0)) * zoomY;\n return {\n x: cx - (pose.width * zoom) / 2,\n y: cy - (pose.height * zoom) / 2,\n width: pose.width,\n height: pose.height,\n zoom,\n frame: frameLinearOf(pose, zoomY / zoom),\n };\n}\n\n/** The linear part of the frame `pose` is drawn in, as the overlay takes it.\n * `stretch` is the view's y scale over its x scale: the overlay scales both\n * axes by the x scale, so the frame carries what is left of y. */\nfunction frameLinearOf(pose: unknown, stretch: number): TextEditScreenPose['frame'] {\n const m = poseFrameOf(pose);\n if (!m && stretch === 1) return undefined;\n const [a, b, c, d] = m ?? [1, 0, 0, 1];\n return [a, b * stretch, c, d * stretch];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgHA,SAAS,YAAY,MAAyD;CAC5E,OAAO,OAAO,SAAS,aAAa,KAAK,IAAI;AAC/C;;AAwBA,SAAS,cAA6C,MAA4D;CAChH,OAAO;EACL,SAAS,SACP,KAAK,QAAQ,SAAS,KAAK,QAAQ,OAAO,IAAI,IAAI,WAAW,IAAI;EACnE,OAAO,SACL,KAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,IAAI,IAAK,KAAK,QAAQ;EACpE,QAAQ,SACN,KAAK,QAAQ,WAAW,KAAK,QAAQ,SAAS,IAAI,IAAI,KAAK;EAC7D,OAAO,SACL,KAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK;EAC3D,gBAAgB,SACd,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,iBAAiB,IAAI,IAAI,KAAK;EAC7E,UAAU,SACR,KAAK,QAAQ,aAAa,KAAK,QAAQ,WAAW,IAAI,IAAI,KAAK;EACjE,WAAW,SACT,KAAK,QAAQ,cAAc,KAAK,QAAQ,YAAY,IAAI,IAAI,KAAK;CACrE;AACF;;;AAIA,SAAgB,iBAKd,OACA,WACA,UAA0C,CAAC,GACnB;CAGxB,MAAM,WAAW,UAAU,KAAK;CAChC,MAAM,UAAU,UAAU,OAAO;CACjC,MAAM,eAAe,UAAU,SAAS;CAGxC,MAAM,cAAc,OAA2B,IAAI;CAInD,MAAM,gBAAyE;EAC7E,MAAM,OAAO,aAAa;EAC1B,MAAM,SAAS,OAAO,kBAAkB,MAAM,YAAY,OAAO,IAAI;EACrE,IAAI,CAAC,QAAQ,CAAC,QAAQ,OAAO;EAC7B,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ACP,MACA,MACA,QACuF;CACvF,MAAM,OAAO,OAAO,KAAK,MAAM,IAAI;CACnC,MAAM,QAAQ,OAAO,KAAK,MAAM,IAAI;CACpC,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,QAAQ,KAAK,MAAM,KAAK,MAAM;CAC3E,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,SAAS,KAAK,MAAM,KAAK,MAAM;CAC5E,OAAO;EACL,GAAG,KAAM,KAAK,QAAQ,OAAQ;EAC9B,GAAG,KAAM,KAAK,SAAS,OAAQ;EAC/B,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb;EACA,OAAO,cAAc,MAAM,QAAQ,IAAI;CACzC;AACF;;;;AAKA,SAAS,cAAc,MAAe,SAA8C;CAClF,MAAM,IAAI,YAAY,IAAI;CAC1B,IAAI,CAAC,KAAK,YAAY,GAAG,OAAO;CAChC,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,KAAK;EAAC;EAAG;EAAG;EAAG;CAAC;CACrC,OAAO;EAAC;EAAG,IAAI;EAAS;EAAG,IAAI;CAAO;AACxC"}
1
+ {"version":3,"file":"useSceneTextEdit.js","names":[],"sources":["../../../src/features/text/useSceneTextEdit.ts"],"sourcesContent":["/**\n * `useSceneTextEdit` — scene-aware wrapper around `useTextEdit`: scene\n * lookups for text / style / runs / screen-pose, and\n * `scene.update(id, { data })` for commits. The overlay and a double-click\n * both read the pose a node is painted at, so text inside a container whose\n * pose is a frame is edited where it is drawn.\n *\n * Defaults assume the node's `data` carries `text` / `style` / `runs`\n * directly. For custom data shapes, override any of the optional projections.\n * Consumers with non-rect poses should drop down to raw `useTextEdit` and\n * supply their own `getScreenPose`.\n */\nimport { useCallback, useMemo, useRef, type MouseEvent } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport { asNodeId } from '../../core/scene/types';\nimport { scenePaintedPoseOf } from '../../canvas/derivedPath';\nimport type { Scene } from '../../core/scene/types';\nimport { drawOneEditing, type EditingDrawOne } from './editingDrawOne';\nimport { textHitAt } from './textHitAt';\nimport { editedData, sceneTextDrafts } from './sceneTextDrafts';\nimport type { Stroke, Fill, Inherit } from '@weasel-js/paint';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport { inheritedPaintIn } from '../../canvas/inheritedPaints';\nimport { withInheritedPaint } from '../../core/scene/inheritedPaint';\nimport { clientToCanvas } from '@weasel-js/routing';\nimport { findMountedCanvas, type MountedCanvas } from '../../canvas/mountedCanvases';\nimport type { View } from '../../core/viewport/view';\nimport type { RectPose } from 'core/geometry/unionBounds';\nimport { poseFrameOf } from '@weasel-js/geom';\nimport { isTextData, type StyledRun, type TextPaint, type TextStyle, type TextVerticalAlign } from '@weasel-js/text';\nimport { textBoxOf, type TextOverflow } from '../../canvas/nodeShapes/textPainter';\nimport { useTextEdit, type TextEditClipRect, type TextEditScreenPose, type UseTextEditReturn } from '@weasel-js/text-dom';\n\n/** Shape the default projections expect `data` to satisfy. All fields\n * optional so any object satisfies the constraint — projections fill in\n * the gaps for non-default shapes. */\nexport interface DefaultTextData {\n text?: string;\n style?: TextStyle;\n runs?: readonly StyledRun[];\n fill?: Fill | Inherit | null;\n stroke?: Stroke | Inherit | null;\n verticalAlign?: TextVerticalAlign;\n padding?: number;\n overflow?: TextOverflow;\n}\n\n/** All-optional projections + fontSize fallback. */\nexport interface UseSceneTextEditOptions<TData> {\n /**\n * Is this node text? A double-click opens an edit only on a node that\n * answers yes, and passes through any other to the text under it. Default:\n * `isTextData`, the test `inferredNodeRouting` classifies a text node by. Pass one when `getText` reads some other shape.\n */\n isText?: (data: TData) => boolean;\n /** Read plain text from `data`. Default: `data.text ?? ''`. */\n getText?: (data: TData) => string;\n /** Read style from `data`. Default: `data.style`. */\n getStyle?: (data: TData) => TextStyle | undefined;\n /** Read the node's paint from `data`. Default: `data.fill` / `data.stroke`. */\n getPaint?: (data: TData) => TextPaint | undefined;\n /** Read rich-text runs from `data`. Default: `data.runs`. */\n getRuns?: (data: TData) => readonly StyledRun[] | undefined;\n /** Read the box vertical alignment from `data`. Default: `data.verticalAlign`. */\n getVerticalAlign?: (data: TData) => TextVerticalAlign | undefined;\n /** Read the inset from the node's box to its text from `data`. Default: `data.padding`. */\n getPadding?: (data: TData) => number | undefined;\n /** Read whether the node cuts its text at its box from `data`, which the\n * overlay then does too. Default: `data.overflow`. */\n getOverflow?: (data: TData) => TextOverflow | undefined;\n /** Produce updated data with new text. Default: `{ ...data, text }`. */\n setText?: (data: TData, text: string) => TData;\n /** Produce updated data with new runs. Default: `{ ...data, runs }`. */\n setRuns?: (data: TData, runs: StyledRun[]) => TData;\n /**\n * Produce updated data with a new node-wide style. Default:\n * `{ ...data, style }`. Written only when a range toggle has to *clear* a\n * flag the node itself sets — the run algebra is additive, so that edit\n * lowers the node flag and raises it on the runs outside the range. See\n * `useTextEdit`'s `setStyle`.\n *\n * An edit's text, runs, and style are folded through these three and\n * written as one `scene.update`, so a commit is one undo step.\n */\n setStyle?: (data: TData, style: TextStyle) => TData;\n /** Fallback fontSize when `style.fontSize` is unset. Default `16`. */\n defaultFontSize?: number;\n /**\n * The view to project through. Omit it and the view is read live from the\n * weasel canvas mounted inside `container` (the one a double-click landed\n * on, when there are several). With no canvas there, the node's world box\n * is passed through as screen pixels.\n *\n * A thunk is re-read on every projection; a plain `View` is the value from\n * the render that supplied it.\n */\n view?: View | (() => View);\n /**\n * Forwarded to `useTextEdit`: is `el` part of the editor's own chrome?\n * Focus moving into it does not end the edit. Wire it to whatever renders\n * the character controls.\n */\n isEditorChrome?: (el: Element) => boolean;\n /** Forwarded to `useTextEdit`: what Escape does to the edit. */\n escape?: 'cancel' | 'commit';\n /** Forwarded to `useTextEdit`: how long an edit waits for its face. */\n fontHold?: number;\n /** Forwarded to `useTextEdit`: called as an edit of the node `id` opens,\n * whichever way it was started. */\n onStart?: (id: string) => void;\n /** Forwarded to `useTextEdit`: called as the edit of `id` closes, after\n * any commit has been written to the scene. */\n onEnd?: (id: string) => void;\n}\n\nfunction resolveView(view: View | (() => View) | undefined): View | undefined {\n return typeof view === 'function' ? view() : view;\n}\n\n/** Return shape extends `UseTextEditReturn` with an `onDoubleClick`\n * binding for the canvas container. Double-clicking inside a text\n * node enters edit mode with the caret seeded at the clicked glyph. */\nexport interface UseSceneTextEditReturn extends UseTextEditReturn {\n /** Bind to the element wrapping `<SceneCanvas>` (the same element\n * passed as `container`, or any ancestor that receives the dblclick\n * bubble). Starts an edit on the top-most text node under the cursor. */\n onDoubleClick: (e: MouseEvent<HTMLElement>) => void;\n /** The `isText` option asked of the node with this id: what\n * `TextEditDep.isTextNode` wants, so both ways into an edit agree. */\n isTextNode: (id: string) => boolean;\n /**\n * `defaultDrawOne`, less the glyphs of the node being edited: the overlay\n * stands in for its text, and the rest of the node, a `background` among\n * it, goes on painting. Pass it as `layers.scene.drawOne`, with\n * `paintBounds: defaultPaintBounds`, in place of an `alphaFor` that hides\n * the whole node.\n */\n drawOne: EditingDrawOne;\n}\n\n/** How each field is read from a node's `data`: the option's projection, else the default shape. */\nfunction projectionsOf<TData extends DefaultTextData>(opts: { readonly current: UseSceneTextEditOptions<TData> }) {\n return {\n isText: (data: TData): boolean =>\n opts.current.isText ? opts.current.isText(data) : isTextData(data),\n text: (data: TData): string =>\n opts.current.getText ? opts.current.getText(data) : (data.text ?? ''),\n style: (data: TData): TextStyle | undefined =>\n opts.current.getStyle ? opts.current.getStyle(data) : data.style,\n runs: (data: TData): readonly StyledRun[] | undefined =>\n opts.current.getRuns ? opts.current.getRuns(data) : data.runs,\n verticalAlign: (data: TData): TextVerticalAlign | undefined =>\n opts.current.getVerticalAlign ? opts.current.getVerticalAlign(data) : data.verticalAlign,\n padding: (data: TData): number | undefined =>\n opts.current.getPadding ? opts.current.getPadding(data) : data.padding,\n overflow: (data: TData): TextOverflow | undefined =>\n opts.current.getOverflow ? opts.current.getOverflow(data) : data.overflow,\n };\n}\n\n/** Wire double-click-to-edit text on a scene: mounts a DOM editing overlay\n * over the node being edited and writes the result back as an undoable op. */\nexport function useSceneTextEdit<\n TData extends DefaultTextData,\n TLayer extends string,\n TPose extends RectPose = RectPose,\n>(\n scene: Scene<TData, TLayer, TPose>,\n container: HTMLElement | null,\n options: UseSceneTextEditOptions<TData> = {},\n): UseSceneTextEditReturn {\n // Refs, so the useTextEdit callbacks always see the current values\n // without re-binding.\n const sceneRef = useLatest(scene);\n const optsRef = useLatest(options);\n const containerRef = useLatest(container);\n // The last double-click's target, so the overlay projects through the\n // canvas the edit was opened on.\n const openedOnRef = useRef<EventTarget | null>(null);\n const drafts = useMemo(() => sceneTextDrafts(sceneRef, optsRef), [sceneRef, optsRef]);\n\n // The canvas's box in container pixels is both the origin its view projects\n // from and the region its glyphs are clipped to.\n const surface = (): { canvas: MountedCanvas; box: TextEditClipRect } | null => {\n const root = containerRef.current;\n const canvas = root ? findMountedCanvas(root, openedOnRef.current) : null;\n if (!root || !canvas) return null;\n const a = canvas.element.getBoundingClientRect();\n const b = root.getBoundingClientRect();\n return {\n canvas,\n box: {\n x: a.left - b.left - root.clientLeft + root.scrollLeft,\n y: a.top - b.top - root.clientTop + root.scrollTop,\n width: a.width,\n height: a.height,\n },\n };\n };\n\n const read = useMemo(() => projectionsOf(optsRef), [optsRef]);\n\n const edit = useTextEdit({\n container,\n isEditorChrome: (el) => optsRef.current.isEditorChrome?.(el) ?? false,\n escape: options.escape,\n fontHold: options.fontHold,\n onStart: (id) => optsRef.current.onStart?.(id),\n onEnd: (id) => {\n drafts.end(id);\n optsRef.current.onEnd?.(id);\n },\n onDraft: drafts.draft,\n getText: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.text(node.data) : '';\n },\n getStyle: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.style(node.data) : undefined;\n },\n getPaint: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n if (!node) return undefined;\n const get = optsRef.current.getPaint;\n return get ? get(node.data) : shownTextPaint(sceneRef.current, node);\n },\n getScreenPose: (id) => {\n const scene = sceneRef.current;\n const node = scene.get(asNodeId(id));\n if (!node) return null;\n const at = surface();\n const view = resolveView(optsRef.current.view) ?? at?.canvas.getView();\n return screenPoseOf(node.data, scenePaintedPoseOf(scene)(node), read, view, at?.box, optsRef.current.defaultFontSize);\n },\n getClipRect: () => surface()?.box ?? null,\n getRuns: (id) => {\n const node = sceneRef.current.get(asNodeId(id));\n return node ? read.runs(node.data) : undefined;\n },\n commit: (id, { text, runs, style }) => {\n const nid = asNodeId(id);\n const node = sceneRef.current.get(nid);\n if (!node) return;\n drafts.commit(id, editedData(node.data, { text, runs, style }, optsRef.current));\n },\n });\n\n const onDoubleClick = useCallback((e: MouseEvent<HTMLElement>) => {\n // The dblclick bubbles from the canvas up to any wrapping container; the\n // element it started on is what the click coordinates are relative to.\n const canvas = e.target instanceof HTMLElement ? e.target : null;\n if (!canvas) return;\n // Inside the editor a double-click selects a word, and its target is a run\n // span whose box the click would be measured against as if it were a canvas.\n if (canvas.closest('[contenteditable=\"true\"]')) return;\n\n // The click is un-projected here; `textHitAt` takes it back through the\n // frame the node is drawn in.\n const [canvasX, canvasY] = clientToCanvas(canvas, e.clientX, e.clientY);\n const root = containerRef.current;\n const view = resolveView(optsRef.current.view)\n ?? (root ? findMountedCanvas(root, canvas)?.getView() : undefined);\n const cx = view ? canvasX / view.scale.x + view.x : canvasX;\n const cy = view ? canvasY / view.scale.y + view.y : canvasY;\n const hit = textHitAt(sceneRef.current, read, cx, cy);\n if (!hit) return;\n openedOnRef.current = canvas;\n edit.startEdit(hit.id, { caret: hit.caret });\n }, [edit, containerRef, optsRef, read, sceneRef]);\n\n const isTextNode = useCallback((id: string): boolean => {\n const node = sceneRef.current.get(asNodeId(id));\n return node !== undefined && read.isText(node.data);\n }, [read, sceneRef]);\n\n const drawOne = useMemo(() => drawOneEditing(edit.editingId), [edit.editingId]);\n return { ...edit, onDoubleClick, isTextNode, drawOne };\n}\n\n/** The overlay's pose for a node painted at `painted`: its text box, inset\n * about the box center, which is all the overlay's frame needs, projected\n * through `view`. */\nfunction screenPoseOf<TData extends DefaultTextData>(\n d: TData,\n painted: RectPose,\n read: ReturnType<typeof projectionsOf<TData>>,\n view: View | undefined,\n origin: TextEditClipRect | undefined,\n defaultFontSize = 16,\n): TextEditScreenPose {\n const inset = textBoxOf({ padding: read.padding(d) }, painted);\n const box = screenBoxOf({ ...painted, ...inset }, view, origin);\n return {\n ...box,\n // Against `zoom`, the same factor the overlay scales back up by, so a\n // `{ px }` size arrives on screen at the pixel count it names.\n fontSize: resolveScreenLength(read.style(d)?.fontSize ?? defaultFontSize, box.zoom),\n verticalAlign: read.verticalAlign(d),\n ...(read.overflow(d) === 'clip' ? { clip: clipToBox(inset, painted) } : {}),\n };\n}\n\n/** How far `box` reaches past `inner` on each side: the overlay's cut at\n * `box` when its own pose is `inner`. */\nfunction clipToBox(inner: RectPose, box: RectPose): NonNullable<TextEditScreenPose['clip']> {\n return {\n top: inner.y - box.y,\n left: inner.x - box.x,\n bottom: box.y + box.height - (inner.y + inner.height),\n right: box.x + box.width - (inner.x + inner.width),\n };\n}\n\n/**\n * `pose`'s box as the overlay takes it, `origin` being the canvas's corner in\n * container pixels. Only the box center is projected, since the overlay's\n * frame is about it. Width and height stay in world units and reach the\n * screen through the overlay's own `scale(zoom)` — see\n * `TextEditScreenPose.zoom`.\n */\nfunction screenBoxOf(\n pose: RectPose,\n view: View | undefined,\n origin: { x: number; y: number } | undefined,\n): Pick<TextEditScreenPose, 'x' | 'y' | 'width' | 'height' | 'frame'> & { zoom: number } {\n const zoom = view ? view.scale.x : 1;\n const zoomY = view ? view.scale.y : 1;\n const cx = (origin?.x ?? 0) + (pose.x + pose.width / 2 - (view?.x ?? 0)) * zoom;\n const cy = (origin?.y ?? 0) + (pose.y + pose.height / 2 - (view?.y ?? 0)) * zoomY;\n return {\n x: cx - (pose.width * zoom) / 2,\n y: cy - (pose.height * zoom) / 2,\n width: pose.width,\n height: pose.height,\n zoom,\n frame: frameLinearOf(pose, zoomY / zoom),\n };\n}\n\n/** The linear part of the frame `pose` is drawn in, as the overlay takes it.\n * `stretch` is the view's y scale over its x scale: the overlay scales both\n * axes by the x scale, so the frame carries what is left of y. */\nfunction frameLinearOf(pose: unknown, stretch: number): TextEditScreenPose['frame'] {\n const m = poseFrameOf(pose);\n if (!m && stretch === 1) return undefined;\n const [a, b, c, d] = m ?? [1, 0, 0, 1];\n return [a, b * stretch, c, d * stretch];\n}\n\n/** A text node's paint as the canvas paints it: an inherited one is its container's. */\nfunction shownTextPaint<TData extends DefaultTextData>(\n scene: Scene<TData, string, unknown>,\n node: NonNullable<ReturnType<Scene<TData, string, unknown>['get']>>,\n): TextPaint {\n const { fill, stroke } = withInheritedPaint(node.data, inheritedPaintIn(scene, node));\n return { fill, stroke };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmHA,SAAS,YAAY,MAAyD;CAC5E,OAAO,OAAO,SAAS,aAAa,KAAK,IAAI;AAC/C;;AAwBA,SAAS,cAA6C,MAA4D;CAChH,OAAO;EACL,SAAS,SACP,KAAK,QAAQ,SAAS,KAAK,QAAQ,OAAO,IAAI,IAAI,WAAW,IAAI;EACnE,OAAO,SACL,KAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,IAAI,IAAK,KAAK,QAAQ;EACpE,QAAQ,SACN,KAAK,QAAQ,WAAW,KAAK,QAAQ,SAAS,IAAI,IAAI,KAAK;EAC7D,OAAO,SACL,KAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK;EAC3D,gBAAgB,SACd,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,iBAAiB,IAAI,IAAI,KAAK;EAC7E,UAAU,SACR,KAAK,QAAQ,aAAa,KAAK,QAAQ,WAAW,IAAI,IAAI,KAAK;EACjE,WAAW,SACT,KAAK,QAAQ,cAAc,KAAK,QAAQ,YAAY,IAAI,IAAI,KAAK;CACrE;AACF;;;AAIA,SAAgB,iBAKd,OACA,WACA,UAA0C,CAA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