@avis-studio/engine 0.0.0-stage → 0.1.0-beta.1

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 (424) hide show
  1. package/README.md +193 -2
  2. package/THIRD_PARTY_NOTICES.md +29 -0
  3. package/dist/a11y/focus.d.ts +60 -0
  4. package/dist/a11y/focus.js +222 -0
  5. package/dist/a11y/index.d.ts +2 -0
  6. package/dist/a11y/index.js +4 -0
  7. package/dist/a11y/semantics.d.ts +37 -0
  8. package/dist/a11y/semantics.js +88 -0
  9. package/dist/commands/builtins.d.ts +88 -0
  10. package/dist/commands/builtins.js +362 -0
  11. package/dist/commands/command.d.ts +23 -0
  12. package/dist/commands/command.js +20 -0
  13. package/dist/commands/draft.d.ts +33 -0
  14. package/dist/commands/draft.js +96 -0
  15. package/dist/commands/history.d.ts +34 -0
  16. package/dist/commands/history.js +80 -0
  17. package/dist/commands/index.d.ts +6 -0
  18. package/dist/commands/index.js +6 -0
  19. package/dist/commands/patch.d.ts +24 -0
  20. package/dist/commands/patch.js +44 -0
  21. package/dist/commands/transaction.d.ts +16 -0
  22. package/dist/commands/transaction.js +39 -0
  23. package/dist/core/diagnostics.d.ts +23 -0
  24. package/dist/core/diagnostics.js +23 -0
  25. package/dist/core/disposable.d.ts +14 -0
  26. package/dist/core/disposable.js +51 -0
  27. package/dist/core/engine.d.ts +108 -0
  28. package/dist/core/engine.js +323 -0
  29. package/dist/core/event-bus.d.ts +10 -0
  30. package/dist/core/event-bus.js +33 -0
  31. package/dist/core/ids.d.ts +13 -0
  32. package/dist/core/ids.js +6 -0
  33. package/dist/core/index.d.ts +7 -0
  34. package/dist/core/index.js +7 -0
  35. package/dist/core/plugin.d.ts +20 -0
  36. package/dist/core/plugin.js +47 -0
  37. package/dist/core/services.d.ts +14 -0
  38. package/dist/core/services.js +20 -0
  39. package/dist/devtools/index.d.ts +1 -0
  40. package/dist/devtools/index.js +2 -0
  41. package/dist/devtools/panel.d.ts +39 -0
  42. package/dist/devtools/panel.js +100 -0
  43. package/dist/dom/a11y-layer.d.ts +32 -0
  44. package/dist/dom/a11y-layer.js +358 -0
  45. package/dist/dom/anchor.d.ts +34 -0
  46. package/dist/dom/anchor.js +35 -0
  47. package/dist/dom/index.d.ts +6 -0
  48. package/dist/dom/index.js +8 -0
  49. package/dist/dom/menu.d.ts +24 -0
  50. package/dist/dom/menu.js +122 -0
  51. package/dist/dom/overlays.d.ts +29 -0
  52. package/dist/dom/overlays.js +82 -0
  53. package/dist/dom/paint/collect.d.ts +8 -0
  54. package/dist/dom/paint/collect.js +589 -0
  55. package/dist/dom/paint/css.d.ts +86 -0
  56. package/dist/dom/paint/css.js +526 -0
  57. package/dist/dom/paint/draw.d.ts +16 -0
  58. package/dist/dom/paint/draw.js +413 -0
  59. package/dist/dom/paint/ghost.d.ts +2 -0
  60. package/dist/dom/paint/ghost.js +8 -0
  61. package/dist/dom/paint/index.d.ts +6 -0
  62. package/dist/dom/paint/index.js +9 -0
  63. package/dist/dom/paint/text.d.ts +26 -0
  64. package/dist/dom/paint/text.js +209 -0
  65. package/dist/dom/paint/types.d.ts +174 -0
  66. package/dist/dom/paint/types.js +7 -0
  67. package/dist/dom/paint/watch.d.ts +10 -0
  68. package/dist/dom/paint/watch.js +109 -0
  69. package/dist/dom/position.d.ts +37 -0
  70. package/dist/dom/position.js +125 -0
  71. package/dist/dom/text-editor.d.ts +27 -0
  72. package/dist/dom/text-editor.js +128 -0
  73. package/dist/events/event.d.ts +122 -0
  74. package/dist/events/event.js +130 -0
  75. package/dist/events/eventer.d.ts +24 -0
  76. package/dist/events/eventer.js +83 -0
  77. package/dist/events/index.d.ts +3 -0
  78. package/dist/events/index.js +3 -0
  79. package/dist/events/interaction.d.ts +43 -0
  80. package/dist/events/interaction.js +203 -0
  81. package/dist/geometry/anchors.d.ts +14 -0
  82. package/dist/geometry/anchors.js +13 -0
  83. package/dist/geometry/bounds.d.ts +16 -0
  84. package/dist/geometry/bounds.js +42 -0
  85. package/dist/geometry/curves.d.ts +39 -0
  86. package/dist/geometry/curves.js +68 -0
  87. package/dist/geometry/index.d.ts +6 -0
  88. package/dist/geometry/index.js +6 -0
  89. package/dist/geometry/matrix.d.ts +22 -0
  90. package/dist/geometry/matrix.js +56 -0
  91. package/dist/geometry/spaces.d.ts +22 -0
  92. package/dist/geometry/spaces.js +28 -0
  93. package/dist/geometry/vec2.d.ts +12 -0
  94. package/dist/geometry/vec2.js +10 -0
  95. package/dist/index.d.ts +16 -0
  96. package/dist/index.js +22 -0
  97. package/dist/interaction/behaviors.d.ts +10 -0
  98. package/dist/interaction/behaviors.js +744 -0
  99. package/dist/interaction/controller.d.ts +180 -0
  100. package/dist/interaction/controller.js +269 -0
  101. package/dist/interaction/hit-test.d.ts +45 -0
  102. package/dist/interaction/hit-test.js +119 -0
  103. package/dist/interaction/index.d.ts +4 -0
  104. package/dist/interaction/index.js +7 -0
  105. package/dist/interaction/web-input.d.ts +13 -0
  106. package/dist/interaction/web-input.js +172 -0
  107. package/dist/layout/index.d.ts +1 -0
  108. package/dist/layout/index.js +2 -0
  109. package/dist/layout/layout.d.ts +27 -0
  110. package/dist/layout/layout.js +266 -0
  111. package/dist/react/canvas/graph.d.ts +83 -0
  112. package/dist/react/canvas/graph.js +89 -0
  113. package/dist/react/canvas/hooks.d.ts +42 -0
  114. package/dist/react/canvas/hooks.js +78 -0
  115. package/dist/react/canvas/index.d.ts +35 -0
  116. package/dist/react/canvas/index.js +8 -0
  117. package/dist/react/components.d.ts +55 -0
  118. package/dist/react/components.js +197 -0
  119. package/dist/react/context.d.ts +4 -0
  120. package/dist/react/context.js +9 -0
  121. package/dist/react/flow/api/LICENSE +21 -0
  122. package/dist/react/flow/api/externals.d.ts +12 -0
  123. package/dist/react/flow/api/react/additional-components/Background/Background.d.ts +7 -0
  124. package/dist/react/flow/api/react/additional-components/Background/Patterns.d.ts +17 -0
  125. package/dist/react/flow/api/react/additional-components/Background/index.d.ts +2 -0
  126. package/dist/react/flow/api/react/additional-components/Background/types.d.ts +25 -0
  127. package/dist/react/flow/api/react/additional-components/Controls/ControlButton.d.ts +2 -0
  128. package/dist/react/flow/api/react/additional-components/Controls/Controls.d.ts +7 -0
  129. package/dist/react/flow/api/react/additional-components/Controls/Icons/FitView.d.ts +1 -0
  130. package/dist/react/flow/api/react/additional-components/Controls/Icons/Lock.d.ts +1 -0
  131. package/dist/react/flow/api/react/additional-components/Controls/Icons/Minus.d.ts +1 -0
  132. package/dist/react/flow/api/react/additional-components/Controls/Icons/Plus.d.ts +1 -0
  133. package/dist/react/flow/api/react/additional-components/Controls/Icons/Unlock.d.ts +1 -0
  134. package/dist/react/flow/api/react/additional-components/Controls/index.d.ts +3 -0
  135. package/dist/react/flow/api/react/additional-components/Controls/types.d.ts +20 -0
  136. package/dist/react/flow/api/react/additional-components/EdgeToolbar/EdgeToolbar.d.ts +2 -0
  137. package/dist/react/flow/api/react/additional-components/EdgeToolbar/index.d.ts +2 -0
  138. package/dist/react/flow/api/react/additional-components/EdgeToolbar/types.d.ts +6 -0
  139. package/dist/react/flow/api/react/additional-components/MiniMap/MiniMap.d.ts +8 -0
  140. package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNode.d.ts +4 -0
  141. package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNodes.d.ts +5 -0
  142. package/dist/react/flow/api/react/additional-components/MiniMap/index.d.ts +3 -0
  143. package/dist/react/flow/api/react/additional-components/MiniMap/types.d.ts +44 -0
  144. package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizeControl.d.ts +5 -0
  145. package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizer.d.ts +2 -0
  146. package/dist/react/flow/api/react/additional-components/NodeResizer/index.d.ts +3 -0
  147. package/dist/react/flow/api/react/additional-components/NodeResizer/types.d.ts +32 -0
  148. package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbar.d.ts +2 -0
  149. package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbarPortal.d.ts +4 -0
  150. package/dist/react/flow/api/react/additional-components/NodeToolbar/index.d.ts +2 -0
  151. package/dist/react/flow/api/react/additional-components/NodeToolbar/types.d.ts +9 -0
  152. package/dist/react/flow/api/react/additional-components/index.d.ts +6 -0
  153. package/dist/react/flow/api/react/components/A11yDescriptions/index.d.ts +7 -0
  154. package/dist/react/flow/api/react/components/Attribution/index.d.ts +8 -0
  155. package/dist/react/flow/api/react/components/BatchProvider/index.d.ts +10 -0
  156. package/dist/react/flow/api/react/components/BatchProvider/types.d.ts +6 -0
  157. package/dist/react/flow/api/react/components/BatchProvider/useQueue.d.ts +2 -0
  158. package/dist/react/flow/api/react/components/ConnectionLine/index.d.ts +11 -0
  159. package/dist/react/flow/api/react/components/EdgeLabelRenderer/index.d.ts +5 -0
  160. package/dist/react/flow/api/react/components/EdgeWrapper/EdgeUpdateAnchors.d.ts +14 -0
  161. package/dist/react/flow/api/react/components/EdgeWrapper/index.d.ts +5 -0
  162. package/dist/react/flow/api/react/components/EdgeWrapper/utils.d.ts +11 -0
  163. package/dist/react/flow/api/react/components/Edges/BaseEdge.d.ts +2 -0
  164. package/dist/react/flow/api/react/components/Edges/BezierEdge.d.ts +4 -0
  165. package/dist/react/flow/api/react/components/Edges/EdgeAnchor.d.ts +13 -0
  166. package/dist/react/flow/api/react/components/Edges/EdgeText.d.ts +7 -0
  167. package/dist/react/flow/api/react/components/Edges/SimpleBezierEdge.d.ts +20 -0
  168. package/dist/react/flow/api/react/components/Edges/SmoothStepEdge.d.ts +4 -0
  169. package/dist/react/flow/api/react/components/Edges/StepEdge.d.ts +4 -0
  170. package/dist/react/flow/api/react/components/Edges/StraightEdge.d.ts +4 -0
  171. package/dist/react/flow/api/react/components/Edges/index.d.ts +5 -0
  172. package/dist/react/flow/api/react/components/Handle/index.d.ts +8 -0
  173. package/dist/react/flow/api/react/components/NodeWrapper/index.d.ts +4 -0
  174. package/dist/react/flow/api/react/components/NodeWrapper/useNodeObserver.d.ts +7 -0
  175. package/dist/react/flow/api/react/components/NodeWrapper/utils.d.ts +8 -0
  176. package/dist/react/flow/api/react/components/Nodes/DefaultNode.d.ts +2 -0
  177. package/dist/react/flow/api/react/components/Nodes/GroupNode.d.ts +1 -0
  178. package/dist/react/flow/api/react/components/Nodes/InputNode.d.ts +2 -0
  179. package/dist/react/flow/api/react/components/Nodes/OutputNode.d.ts +2 -0
  180. package/dist/react/flow/api/react/components/Nodes/utils.d.ts +12 -0
  181. package/dist/react/flow/api/react/components/NodesSelection/index.d.ts +8 -0
  182. package/dist/react/flow/api/react/components/Panel/index.d.ts +8 -0
  183. package/dist/react/flow/api/react/components/ReactFlowProvider/index.d.ts +20 -0
  184. package/dist/react/flow/api/react/components/SelectionListener/index.d.ts +6 -0
  185. package/dist/react/flow/api/react/components/StoreUpdater/index.d.ts +67 -0
  186. package/dist/react/flow/api/react/components/UserSelection/index.d.ts +1 -0
  187. package/dist/react/flow/api/react/components/ViewportPortal/index.d.ts +4 -0
  188. package/dist/react/flow/api/react/container/EdgeRenderer/MarkerDefinitions.d.ts +9 -0
  189. package/dist/react/flow/api/react/container/EdgeRenderer/MarkerSymbols.d.ts +8 -0
  190. package/dist/react/flow/api/react/container/EdgeRenderer/index.d.ts +12 -0
  191. package/dist/react/flow/api/react/container/FlowRenderer/index.d.ts +13 -0
  192. package/dist/react/flow/api/react/container/GraphView/index.d.ts +10 -0
  193. package/dist/react/flow/api/react/container/GraphView/useNodeOrEdgeTypesWarning.d.ts +3 -0
  194. package/dist/react/flow/api/react/container/GraphView/useStylesLoadedWarning.d.ts +1 -0
  195. package/dist/react/flow/api/react/container/NodeRenderer/index.d.ts +9 -0
  196. package/dist/react/flow/api/react/container/NodeRenderer/useResizeObserver.d.ts +1 -0
  197. package/dist/react/flow/api/react/container/Pane/index.d.ts +10 -0
  198. package/dist/react/flow/api/react/container/ReactFlow/Wrapper.d.ts +19 -0
  199. package/dist/react/flow/api/react/container/ReactFlow/index.d.ts +3 -0
  200. package/dist/react/flow/api/react/container/ReactFlow/init-values.d.ts +3 -0
  201. package/dist/react/flow/api/react/container/Viewport/index.d.ts +6 -0
  202. package/dist/react/flow/api/react/container/ZoomPane/index.d.ts +7 -0
  203. package/dist/react/flow/api/react/contexts/HandleConfigContext.d.ts +11 -0
  204. package/dist/react/flow/api/react/contexts/NodeIdContext.d.ts +5 -0
  205. package/dist/react/flow/api/react/contexts/StoreContext.d.ts +3 -0
  206. package/dist/react/flow/api/react/hooks/useColorModeClass.d.ts +2 -0
  207. package/dist/react/flow/api/react/hooks/useConnection.d.ts +3 -0
  208. package/dist/react/flow/api/react/hooks/useDrag.d.ts +12 -0
  209. package/dist/react/flow/api/react/hooks/useEdges.d.ts +2 -0
  210. package/dist/react/flow/api/react/hooks/useGlobalKeyHandler.d.ts +5 -0
  211. package/dist/react/flow/api/react/hooks/useHandleConnections.d.ts +10 -0
  212. package/dist/react/flow/api/react/hooks/useInternalNode.d.ts +2 -0
  213. package/dist/react/flow/api/react/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
  214. package/dist/react/flow/api/react/hooks/useKeyPress.d.ts +7 -0
  215. package/dist/react/flow/api/react/hooks/useMoveSelectedNodes.d.ts +5 -0
  216. package/dist/react/flow/api/react/hooks/useNodeConnections.d.ts +2 -0
  217. package/dist/react/flow/api/react/hooks/useNodes.d.ts +2 -0
  218. package/dist/react/flow/api/react/hooks/useNodesData.d.ts +4 -0
  219. package/dist/react/flow/api/react/hooks/useNodesEdgesState.d.ts +12 -0
  220. package/dist/react/flow/api/react/hooks/useNodesInitialized.d.ts +4 -0
  221. package/dist/react/flow/api/react/hooks/useOnEdgesChangeMiddleware.d.ts +3 -0
  222. package/dist/react/flow/api/react/hooks/useOnInitHandler.d.ts +2 -0
  223. package/dist/react/flow/api/react/hooks/useOnNodesChangeMiddleware.d.ts +3 -0
  224. package/dist/react/flow/api/react/hooks/useOnSelectionChange.d.ts +5 -0
  225. package/dist/react/flow/api/react/hooks/useOnViewportChange.d.ts +7 -0
  226. package/dist/react/flow/api/react/hooks/useReactFlow.d.ts +2 -0
  227. package/dist/react/flow/api/react/hooks/useResizeHandler.d.ts +2 -0
  228. package/dist/react/flow/api/react/hooks/useStore.d.ts +8 -0
  229. package/dist/react/flow/api/react/hooks/useUpdateNodeInternals.d.ts +2 -0
  230. package/dist/react/flow/api/react/hooks/useViewport.d.ts +2 -0
  231. package/dist/react/flow/api/react/hooks/useViewportHelper.d.ts +3 -0
  232. package/dist/react/flow/api/react/hooks/useViewportSync.d.ts +2 -0
  233. package/dist/react/flow/api/react/hooks/useVisibleEdgeIds.d.ts +1 -0
  234. package/dist/react/flow/api/react/hooks/useVisibleNodeIds.d.ts +1 -0
  235. package/dist/react/flow/api/react/index.d.ts +41 -0
  236. package/dist/react/flow/api/react/store/index.d.ts +18 -0
  237. package/dist/react/flow/api/react/store/initialState.d.ts +18 -0
  238. package/dist/react/flow/api/react/styles/utils.d.ts +2 -0
  239. package/dist/react/flow/api/react/types/component-props.d.ts +127 -0
  240. package/dist/react/flow/api/react/types/edges.d.ts +111 -0
  241. package/dist/react/flow/api/react/types/general.d.ts +53 -0
  242. package/dist/react/flow/api/react/types/index.d.ts +6 -0
  243. package/dist/react/flow/api/react/types/instance.d.ts +64 -0
  244. package/dist/react/flow/api/react/types/nodes.d.ts +41 -0
  245. package/dist/react/flow/api/react/types/store.d.ts +114 -0
  246. package/dist/react/flow/api/react/utils/changes.d.ts +15 -0
  247. package/dist/react/flow/api/react/utils/edges.d.ts +3 -0
  248. package/dist/react/flow/api/react/utils/general.d.ts +5 -0
  249. package/dist/react/flow/api/react/utils/index.d.ts +3 -0
  250. package/dist/react/flow/api/system/constants.d.ts +43 -0
  251. package/dist/react/flow/api/system/index.d.ts +8 -0
  252. package/dist/react/flow/api/system/types/changes.d.ts +48 -0
  253. package/dist/react/flow/api/system/types/edges.d.ts +72 -0
  254. package/dist/react/flow/api/system/types/general.d.ts +175 -0
  255. package/dist/react/flow/api/system/types/handles.d.ts +21 -0
  256. package/dist/react/flow/api/system/types/index.d.ts +7 -0
  257. package/dist/react/flow/api/system/types/nodes.d.ts +89 -0
  258. package/dist/react/flow/api/system/types/panzoom.d.ts +58 -0
  259. package/dist/react/flow/api/system/types/utils.d.ts +46 -0
  260. package/dist/react/flow/api/system/utils/attribution.d.ts +1 -0
  261. package/dist/react/flow/api/system/utils/connections.d.ts +4 -0
  262. package/dist/react/flow/api/system/utils/dom.d.ts +20 -0
  263. package/dist/react/flow/api/system/utils/edge-toolbar.d.ts +1 -0
  264. package/dist/react/flow/api/system/utils/edges/bezier-edge.d.ts +40 -0
  265. package/dist/react/flow/api/system/utils/edges/general.d.ts +44 -0
  266. package/dist/react/flow/api/system/utils/edges/index.d.ts +5 -0
  267. package/dist/react/flow/api/system/utils/edges/positions.d.ts +16 -0
  268. package/dist/react/flow/api/system/utils/edges/smoothstep-edge.d.ts +21 -0
  269. package/dist/react/flow/api/system/utils/edges/straight-edge.d.ts +13 -0
  270. package/dist/react/flow/api/system/utils/general.d.ts +56 -0
  271. package/dist/react/flow/api/system/utils/graph.d.ts +45 -0
  272. package/dist/react/flow/api/system/utils/index.d.ts +12 -0
  273. package/dist/react/flow/api/system/utils/marker.d.ts +8 -0
  274. package/dist/react/flow/api/system/utils/node-toolbar.d.ts +2 -0
  275. package/dist/react/flow/api/system/utils/shallow-node-data.d.ts +4 -0
  276. package/dist/react/flow/api/system/utils/store.d.ts +33 -0
  277. package/dist/react/flow/api/system/utils/types.d.ts +7 -0
  278. package/dist/react/flow/api/system/xydrag/XYDrag.d.ts +56 -0
  279. package/dist/react/flow/api/system/xydrag/index.d.ts +1 -0
  280. package/dist/react/flow/api/system/xydrag/utils.d.ts +22 -0
  281. package/dist/react/flow/api/system/xyhandle/XYHandle.d.ts +2 -0
  282. package/dist/react/flow/api/system/xyhandle/index.d.ts +1 -0
  283. package/dist/react/flow/api/system/xyhandle/types.d.ts +49 -0
  284. package/dist/react/flow/api/system/xyhandle/utils.d.ts +9 -0
  285. package/dist/react/flow/api/system/xyminimap/index.d.ts +27 -0
  286. package/dist/react/flow/api/system/xypanzoom/XYPanZoom.d.ts +11 -0
  287. package/dist/react/flow/api/system/xypanzoom/eventhandler.d.ts +45 -0
  288. package/dist/react/flow/api/system/xypanzoom/filter.d.ts +15 -0
  289. package/dist/react/flow/api/system/xypanzoom/index.d.ts +1 -0
  290. package/dist/react/flow/api/system/xypanzoom/utils.d.ts +8 -0
  291. package/dist/react/flow/api/system/xyresizer/XYResizer.d.ts +51 -0
  292. package/dist/react/flow/api/system/xyresizer/index.d.ts +2 -0
  293. package/dist/react/flow/api/system/xyresizer/types.d.ts +26 -0
  294. package/dist/react/flow/api/system/xyresizer/utils.d.ts +41 -0
  295. package/dist/react/flow/components.d.ts +148 -0
  296. package/dist/react/flow/components.js +526 -0
  297. package/dist/react/flow/configuration.d.ts +6 -0
  298. package/dist/react/flow/configuration.js +27 -0
  299. package/dist/react/flow/drag.d.ts +14 -0
  300. package/dist/react/flow/drag.js +273 -0
  301. package/dist/react/flow/extras.d.ts +155 -0
  302. package/dist/react/flow/extras.js +317 -0
  303. package/dist/react/flow/handle.d.ts +21 -0
  304. package/dist/react/flow/handle.js +149 -0
  305. package/dist/react/flow/hooks.d.ts +47 -0
  306. package/dist/react/flow/hooks.js +131 -0
  307. package/dist/react/flow/index.d.ts +78 -0
  308. package/dist/react/flow/index.js +73 -0
  309. package/dist/react/flow/queries.d.ts +20 -0
  310. package/dist/react/flow/queries.js +30 -0
  311. package/dist/react/flow/react-flow.d.ts +73 -0
  312. package/dist/react/flow/react-flow.js +1445 -0
  313. package/dist/react/flow/resize.d.ts +30 -0
  314. package/dist/react/flow/resize.js +49 -0
  315. package/dist/react/flow/store.d.ts +412 -0
  316. package/dist/react/flow/store.js +713 -0
  317. package/dist/react/flow/style.css +630 -0
  318. package/dist/react/flow/style.css.d.ts +2 -0
  319. package/dist/react/flow/system.d.ts +146 -0
  320. package/dist/react/flow/system.js +300 -0
  321. package/dist/react/flow/types.d.ts +131 -0
  322. package/dist/react/flow/types.js +1 -0
  323. package/dist/react/flow/utils.d.ts +77 -0
  324. package/dist/react/flow/utils.js +285 -0
  325. package/dist/react/hooks.d.ts +14 -0
  326. package/dist/react/hooks.js +44 -0
  327. package/dist/react/index.d.ts +3 -0
  328. package/dist/react/index.js +5 -0
  329. package/dist/render/backend.d.ts +26 -0
  330. package/dist/render/backend.js +5 -0
  331. package/dist/render/canvas2d/backend.d.ts +7 -0
  332. package/dist/render/canvas2d/backend.js +122 -0
  333. package/dist/render/canvas2d/index.d.ts +1 -0
  334. package/dist/render/canvas2d/index.js +2 -0
  335. package/dist/render/color.d.ts +9 -0
  336. package/dist/render/color.js +69 -0
  337. package/dist/render/commands.d.ts +69 -0
  338. package/dist/render/commands.js +1 -0
  339. package/dist/render/display-list.d.ts +65 -0
  340. package/dist/render/display-list.js +316 -0
  341. package/dist/render/images.d.ts +35 -0
  342. package/dist/render/images.js +83 -0
  343. package/dist/render/index.d.ts +14 -0
  344. package/dist/render/index.js +16 -0
  345. package/dist/render/painters.d.ts +35 -0
  346. package/dist/render/painters.js +109 -0
  347. package/dist/render/renderer.d.ts +70 -0
  348. package/dist/render/renderer.js +162 -0
  349. package/dist/render/scene-index.d.ts +21 -0
  350. package/dist/render/scene-index.js +64 -0
  351. package/dist/render/text.d.ts +8 -0
  352. package/dist/render/text.js +100 -0
  353. package/dist/render/theme.d.ts +21 -0
  354. package/dist/render/theme.js +33 -0
  355. package/dist/render/ui.d.ts +63 -0
  356. package/dist/render/ui.js +188 -0
  357. package/dist/render/webgl2/atlas.d.ts +36 -0
  358. package/dist/render/webgl2/atlas.js +93 -0
  359. package/dist/render/webgl2/backend.d.ts +19 -0
  360. package/dist/render/webgl2/backend.js +338 -0
  361. package/dist/render/webgl2/index.d.ts +2 -0
  362. package/dist/render/webgl2/index.js +3 -0
  363. package/dist/render/webgl2/shaders.d.ts +6 -0
  364. package/dist/render/webgl2/shaders.js +112 -0
  365. package/dist/render/webgpu/index.d.ts +1 -0
  366. package/dist/render/webgpu/index.js +3 -0
  367. package/dist/scene/builtins.d.ts +25 -0
  368. package/dist/scene/builtins.js +60 -0
  369. package/dist/scene/dirty.d.ts +11 -0
  370. package/dist/scene/dirty.js +10 -0
  371. package/dist/scene/index.d.ts +5 -0
  372. package/dist/scene/index.js +5 -0
  373. package/dist/scene/record.d.ts +40 -0
  374. package/dist/scene/record.js +12 -0
  375. package/dist/scene/scene-graph.d.ts +58 -0
  376. package/dist/scene/scene-graph.js +178 -0
  377. package/dist/scene/schema.d.ts +27 -0
  378. package/dist/scene/schema.js +32 -0
  379. package/dist/sdk/create-avis.d.ts +109 -0
  380. package/dist/sdk/create-avis.js +162 -0
  381. package/dist/sdk/index.d.ts +1 -0
  382. package/dist/sdk/index.js +2 -0
  383. package/dist/serialization/format.d.ts +46 -0
  384. package/dist/serialization/format.js +20 -0
  385. package/dist/serialization/index.d.ts +3 -0
  386. package/dist/serialization/index.js +3 -0
  387. package/dist/serialization/migrate.d.ts +7 -0
  388. package/dist/serialization/migrate.js +54 -0
  389. package/dist/serialization/serialize.d.ts +10 -0
  390. package/dist/serialization/serialize.js +114 -0
  391. package/dist/state/index.d.ts +2 -0
  392. package/dist/state/index.js +2 -0
  393. package/dist/state/selector.d.ts +6 -0
  394. package/dist/state/selector.js +29 -0
  395. package/dist/state/store.d.ts +91 -0
  396. package/dist/state/store.js +102 -0
  397. package/dist/style/computed.d.ts +84 -0
  398. package/dist/style/computed.js +296 -0
  399. package/dist/style/index.d.ts +6 -0
  400. package/dist/style/index.js +8 -0
  401. package/dist/style/style-engine.d.ts +33 -0
  402. package/dist/style/style-engine.js +113 -0
  403. package/dist/style/tokens.d.ts +49 -0
  404. package/dist/style/tokens.js +142 -0
  405. package/dist/style/utilities.d.ts +34 -0
  406. package/dist/style/utilities.js +341 -0
  407. package/dist/style/values.d.ts +30 -0
  408. package/dist/style/values.js +361 -0
  409. package/dist/style/variants.d.ts +38 -0
  410. package/dist/style/variants.js +55 -0
  411. package/dist/sync/index.d.ts +2 -0
  412. package/dist/sync/index.js +1 -0
  413. package/dist/sync/save-queue.d.ts +24 -0
  414. package/dist/sync/save-queue.js +88 -0
  415. package/dist/wasm/index.d.ts +2 -0
  416. package/dist/wasm/index.js +2 -0
  417. package/dist/wasm/load.d.ts +7 -0
  418. package/dist/wasm/load.js +47 -0
  419. package/dist/wasm/pkg/avis_engine_wasm.d.ts +84 -0
  420. package/dist/wasm/pkg/avis_engine_wasm.js +339 -0
  421. package/dist/wasm/pkg/avis_engine_wasm_bg.wasm +0 -0
  422. package/dist/wasm/reference.d.ts +38 -0
  423. package/dist/wasm/reference.js +174 -0
  424. package/package.json +76 -4
@@ -0,0 +1,180 @@
1
+ import { EventBus } from "../core/event-bus.js";
2
+ import type { Engine } from "../core/engine.js";
3
+ import type { NodeId } from "../core/ids.js";
4
+ import type { Plugin } from "../core/plugin.js";
5
+ import { type Disposable } from "../core/disposable.js";
6
+ import type { AnchorBox } from "../geometry/anchors.js";
7
+ import { type ScreenPoint, type WorldPoint } from "../geometry/spaces.js";
8
+ import { type PointerInput } from "../events/event.js";
9
+ import { CanvasEventer } from "../events/eventer.js";
10
+ import { type Hit } from "./hit-test.js";
11
+ export type InteractionOptions = {
12
+ /** Screen px before a press on a node becomes a drag (xyflow's nodeDragThreshold). */
13
+ dragThreshold: number;
14
+ /** Screen px before a press on an anchor becomes a connection. */
15
+ connectThreshold: number;
16
+ /** Extra reach around anchors, screen px. */
17
+ anchorSlop: number;
18
+ /** World units within which a dragged connection snaps to an anchor (xyflow's connectionRadius). */
19
+ connectionRadius: number;
20
+ /** Half a relation's hit width, screen px. */
21
+ relationTolerance: number;
22
+ handleSize: number;
23
+ rotateOffset: number;
24
+ /** A press on an unselected node selects it (xyflow's selectNodesOnDrag). */
25
+ selectOnDrag: boolean;
26
+ snapToGrid: boolean;
27
+ snapGrid: [number, number];
28
+ /** Arrow keys move by this (×4 with Shift), world units. */
29
+ arrowStep: number;
30
+ /** Wheel pans (trackpads); Ctrl/⌘ + wheel or a pinch zooms. */
31
+ panOnScroll: boolean;
32
+ /** Resize and rotation handles on the single selected node. */
33
+ transformHandles: boolean;
34
+ /** Decides whether a connection may be made (xyflow's isValidConnection). */
35
+ isValidConnection: (connection: {
36
+ source: {
37
+ nodeId: NodeId;
38
+ anchor: string | null;
39
+ };
40
+ target: {
41
+ nodeId: NodeId;
42
+ anchor: string | null;
43
+ };
44
+ }) => boolean;
45
+ };
46
+ export declare const DEFAULT_OPTIONS: InteractionOptions;
47
+ /** What happened, for the app (xyflow's callbacks). */
48
+ export type InteractionEvents = {
49
+ "node:tap": {
50
+ id: NodeId;
51
+ input: PointerInput;
52
+ };
53
+ "node:doubletap": {
54
+ id: NodeId;
55
+ input: PointerInput;
56
+ };
57
+ "node:menu": {
58
+ id: NodeId;
59
+ input: PointerInput;
60
+ };
61
+ "relation:tap": {
62
+ id: string;
63
+ input: PointerInput;
64
+ };
65
+ "relation:menu": {
66
+ id: string;
67
+ input: PointerInput;
68
+ };
69
+ "pane:tap": {
70
+ point: WorldPoint;
71
+ input: PointerInput;
72
+ };
73
+ "pane:menu": {
74
+ point: WorldPoint;
75
+ input: PointerInput;
76
+ };
77
+ "anchor:tap": {
78
+ nodeId: NodeId;
79
+ anchor: AnchorBox;
80
+ input: PointerInput;
81
+ };
82
+ "drag:start": {
83
+ ids: NodeId[];
84
+ };
85
+ "drag:end": {
86
+ ids: NodeId[];
87
+ cancelled: boolean;
88
+ };
89
+ "marquee:start": undefined;
90
+ "marquee:end": {
91
+ ids: NodeId[];
92
+ };
93
+ "connect:start": {
94
+ nodeId: NodeId;
95
+ anchor: AnchorBox;
96
+ };
97
+ /** valid: true (connected), false (an anchor refused it), null (none in reach). */
98
+ "connect:end": {
99
+ from: {
100
+ nodeId: NodeId;
101
+ anchor: AnchorBox;
102
+ };
103
+ to: WorldPoint;
104
+ target: {
105
+ nodeId: NodeId;
106
+ anchor: AnchorBox;
107
+ } | null;
108
+ valid: boolean | null;
109
+ relationId: string | null;
110
+ input: PointerInput;
111
+ };
112
+ };
113
+ export type WheelInput = {
114
+ clientX: number;
115
+ clientY: number;
116
+ deltaX: number;
117
+ deltaY: number;
118
+ ctrlKey: boolean;
119
+ metaKey: boolean;
120
+ shiftKey: boolean;
121
+ };
122
+ export type KeyInput = {
123
+ key: string;
124
+ metaKey: boolean;
125
+ ctrlKey: boolean;
126
+ shiftKey: boolean;
127
+ altKey: boolean;
128
+ /** The key went to a text field (shortcuts stay out of its way). */
129
+ typing?: boolean;
130
+ };
131
+ /** Owns the pointer for one gesture at a time. */
132
+ export declare class GestureArbiter {
133
+ private owner;
134
+ private readonly onChange;
135
+ constructor(onChange: (owner: string | null) => void);
136
+ get current(): string | null;
137
+ /** Takes the pointer for `name`; false when another gesture has it. */
138
+ claim(name: string): boolean;
139
+ release(name: string): void;
140
+ }
141
+ export type InteractionController = {
142
+ readonly engine: Engine;
143
+ readonly eventer: CanvasEventer;
144
+ readonly events: EventBus<InteractionEvents>;
145
+ readonly arbiter: GestureArbiter;
146
+ readonly options: InteractionOptions;
147
+ /** Keys held down that change gestures (Space pans). */
148
+ readonly keys: {
149
+ space: boolean;
150
+ };
151
+ setOptions(options: Partial<InteractionOptions>): void;
152
+ toWorld(screen: ScreenPoint): WorldPoint;
153
+ hitTest(screen: ScreenPoint): Hit;
154
+ isMultiSelect(input: {
155
+ metaKey: boolean;
156
+ ctrlKey: boolean;
157
+ }): boolean;
158
+ pointerDown(input: PointerInput): void;
159
+ pointerMove(input: PointerInput): void;
160
+ pointerUp(input: PointerInput): void;
161
+ pointerCancel(input: PointerInput): void;
162
+ pointerLeave(input: PointerInput): void;
163
+ doubleClick(input: PointerInput): void;
164
+ contextMenu(input: PointerInput): void;
165
+ wheel(input: WheelInput): boolean;
166
+ keyDown(input: KeyInput): boolean;
167
+ keyUp(input: KeyInput): void;
168
+ /** Adds a keyboard handler (true when it handled the key). */
169
+ addKeyHandler(handler: (input: KeyInput) => boolean): Disposable;
170
+ /** Adds a keyboard handler that runs before the others. */
171
+ prependKeyHandler(handler: (input: KeyInput) => boolean): Disposable;
172
+ /** Ends the gesture under way without committing it. */
173
+ cancelGesture(): void;
174
+ };
175
+ export declare const InteractionKey: import("../index.js").ServiceKey<InteractionController>;
176
+ /** A behaviour: listens to the controller's events; returns its cleanup. */
177
+ export type Behavior = (controller: InteractionController) => Disposable | (() => void);
178
+ export declare function createInteraction(engine: Engine, options?: Partial<InteractionOptions>, behaviors?: readonly Behavior[]): InteractionController & Disposable;
179
+ /** The interaction plugin: the controller as an engine service. */
180
+ export declare function interactionPlugin(options?: Partial<InteractionOptions>, behaviors?: readonly Behavior[]): Plugin<Engine>;
@@ -0,0 +1,269 @@
1
+ /*
2
+ * The interaction layer (spec §3.4–3.5): platform input in, engine events
3
+ * out (LeaferJS's Interaction), then behaviours — Leafer-editor-style
4
+ * plugins — turn them into selection, previews and commands.
5
+ *
6
+ * - Input arrives in screen space (CSS px within the canvas); the camera
7
+ * maps it to world space.
8
+ * - Gestures are arbitrated: one behaviour owns the pointer at a time
9
+ * (pan vs drag vs marquee vs connect vs transform).
10
+ * - Behaviours announce what happened on `controller.events`, xyflow's
11
+ * callbacks as events (connect end, node tap, menus…), for the app.
12
+ */
13
+ import { EventBus } from "../core/event-bus.js";
14
+ import { serviceKey } from "../core/services.js";
15
+ import { DisposableStack } from "../core/disposable.js";
16
+ import { screenToWorld, } from "../geometry/spaces.js";
17
+ import { PANE } from "../events/event.js";
18
+ import { CanvasEventer } from "../events/eventer.js";
19
+ import { CanvasInteraction } from "../events/interaction.js";
20
+ import { DEFAULT_BEHAVIORS } from "./behaviors.js";
21
+ import { hitTest } from "./hit-test.js";
22
+ export const DEFAULT_OPTIONS = {
23
+ dragThreshold: 1,
24
+ connectThreshold: 1,
25
+ anchorSlop: 6,
26
+ connectionRadius: 20,
27
+ relationTolerance: 12,
28
+ handleSize: 8,
29
+ rotateOffset: 24,
30
+ selectOnDrag: true,
31
+ snapToGrid: false,
32
+ snapGrid: [16, 16],
33
+ arrowStep: 5,
34
+ panOnScroll: true,
35
+ transformHandles: true,
36
+ isValidConnection: () => true,
37
+ };
38
+ /** Owns the pointer for one gesture at a time. */
39
+ export class GestureArbiter {
40
+ owner = null;
41
+ onChange;
42
+ constructor(onChange) {
43
+ this.onChange = onChange;
44
+ }
45
+ get current() {
46
+ return this.owner;
47
+ }
48
+ /** Takes the pointer for `name`; false when another gesture has it. */
49
+ claim(name) {
50
+ if (this.owner && this.owner !== name)
51
+ return false;
52
+ this.owner = name;
53
+ this.onChange(name);
54
+ return true;
55
+ }
56
+ release(name) {
57
+ if (this.owner !== name)
58
+ return;
59
+ this.owner = null;
60
+ this.onChange(null);
61
+ }
62
+ }
63
+ export const InteractionKey = serviceKey("interaction");
64
+ /** Hit results as event targets, with their path out to the pane. */
65
+ function targetOf(engine, hit) {
66
+ const ancestors = (id) => [...engine.scene.ancestors(id)].map((node) => ({
67
+ kind: "node",
68
+ id: node.id,
69
+ }));
70
+ switch (hit.kind) {
71
+ case "pane":
72
+ return { target: PANE, path: [PANE] };
73
+ case "node": {
74
+ const target = { kind: "node", id: hit.id };
75
+ return { target, path: [target, ...ancestors(hit.id), PANE] };
76
+ }
77
+ case "anchor": {
78
+ const target = {
79
+ kind: "handle",
80
+ nodeId: hit.nodeId,
81
+ handle: hit.anchor,
82
+ };
83
+ const node = { kind: "node", id: hit.nodeId };
84
+ return { target, path: [target, node, ...ancestors(hit.nodeId), PANE] };
85
+ }
86
+ case "transform": {
87
+ const target = {
88
+ kind: "transform",
89
+ nodeId: hit.nodeId,
90
+ handle: hit.handle,
91
+ };
92
+ const node = { kind: "node", id: hit.nodeId };
93
+ return { target, path: [target, node, ...ancestors(hit.nodeId), PANE] };
94
+ }
95
+ case "relation": {
96
+ const target = { kind: "edge", id: hit.id };
97
+ return { target, path: [target, PANE] };
98
+ }
99
+ }
100
+ }
101
+ export function createInteraction(engine, options = {}, behaviors = []) {
102
+ const stack = new DisposableStack();
103
+ const eventer = new CanvasEventer();
104
+ const events = new EventBus();
105
+ const settings = { ...DEFAULT_OPTIONS, ...options };
106
+ const keys = { space: false };
107
+ const arbiter = new GestureArbiter((owner) => engine.store.set("interaction", { gesture: owner }));
108
+ const toWorld = (screen) => screenToWorld(engine.store.get().viewport.camera, screen);
109
+ const hitAt = (screen) => {
110
+ const { selectedIds } = engine.store.get().interaction;
111
+ return hitTest(engine, toWorld(screen), {
112
+ zoom: engine.store.get().viewport.camera.zoom,
113
+ anchorSlop: settings.anchorSlop,
114
+ relationTolerance: settings.relationTolerance,
115
+ handleSize: settings.handleSize,
116
+ rotateOffset: settings.rotateOffset,
117
+ transformNodeId: settings.transformHandles && selectedIds.length === 1
118
+ ? selectedIds[0]
119
+ : null,
120
+ });
121
+ };
122
+ const interaction = new CanvasInteraction(eventer, {
123
+ pick(input) {
124
+ const hit = hitAt({ x: input.clientX, y: input.clientY });
125
+ // The selection key (Shift) with the button down makes a box
126
+ // anywhere, over nodes too (xyflow's pane); Shift on a transform
127
+ // handle keeps the ratio instead.
128
+ if (input.shiftKey &&
129
+ input.buttons & 1 &&
130
+ hit.kind !== "transform" &&
131
+ engine.store.get().interaction.tool === "select") {
132
+ return { target: PANE, path: [PANE] };
133
+ }
134
+ return targetOf(engine, hit);
135
+ },
136
+ dragDistance(target) {
137
+ if (target.kind === "handle")
138
+ return settings.connectThreshold;
139
+ if (target.kind === "pane")
140
+ return 0;
141
+ return settings.dragThreshold;
142
+ },
143
+ });
144
+ // Keyboard handlers behaviours add (each returns true when it handled).
145
+ const keyHandlers = [];
146
+ const controller = {
147
+ engine,
148
+ eventer,
149
+ events,
150
+ arbiter,
151
+ options: settings,
152
+ keys,
153
+ setOptions: (next) => void Object.assign(settings, next),
154
+ toWorld,
155
+ hitTest: hitAt,
156
+ isMultiSelect: (input) => input.metaKey || input.ctrlKey,
157
+ pointerDown(input) {
158
+ // The context menu's button only opens the menu.
159
+ if (input.button === 2)
160
+ return;
161
+ interaction.down(input);
162
+ },
163
+ pointerMove: (input) => void interaction.move(input),
164
+ pointerUp: (input) => void interaction.up(input),
165
+ pointerCancel(input) {
166
+ interaction.cancel(input);
167
+ },
168
+ pointerLeave: (input) => interaction.leave(input),
169
+ doubleClick: (input) => void interaction.doubleTap(input),
170
+ contextMenu: (input) => void interaction.menu(input),
171
+ wheel(input) {
172
+ const screen = { x: input.clientX, y: input.clientY };
173
+ const { camera } = engine.store.get().viewport;
174
+ if (input.ctrlKey || input.metaKey || !settings.panOnScroll) {
175
+ // A pinch or Ctrl/⌘ + wheel: zoom at the pointer.
176
+ engine.viewport.zoomAt(screen, camera.zoom * Math.exp(-input.deltaY * 0.01));
177
+ return true;
178
+ }
179
+ const dx = input.shiftKey && !input.deltaX ? input.deltaY : input.deltaX;
180
+ const dy = input.shiftKey && !input.deltaX ? 0 : input.deltaY;
181
+ engine.viewport.panBy(-dx, -dy);
182
+ return true;
183
+ },
184
+ keyDown(input) {
185
+ if (input.key === " " && !input.typing) {
186
+ // Space arms panning, and still reaches the handlers (React Flow's
187
+ // focused node selects on Space too).
188
+ keys.space = true;
189
+ keyHandlers.some((handler) => handler(input));
190
+ return true;
191
+ }
192
+ return keyHandlers.some((handler) => handler(input));
193
+ },
194
+ keyUp(input) {
195
+ if (input.key === " ")
196
+ keys.space = false;
197
+ },
198
+ prependKeyHandler(handler) {
199
+ keyHandlers.unshift(handler);
200
+ return {
201
+ dispose() {
202
+ const index = keyHandlers.indexOf(handler);
203
+ if (index >= 0)
204
+ keyHandlers.splice(index, 1);
205
+ },
206
+ };
207
+ },
208
+ addKeyHandler(handler) {
209
+ keyHandlers.push(handler);
210
+ return {
211
+ dispose() {
212
+ const index = keyHandlers.indexOf(handler);
213
+ if (index >= 0)
214
+ keyHandlers.splice(index, 1);
215
+ },
216
+ };
217
+ },
218
+ cancelGesture() {
219
+ interaction.cancel({
220
+ clientX: 0,
221
+ clientY: 0,
222
+ button: 0,
223
+ buttons: 0,
224
+ shiftKey: false,
225
+ metaKey: false,
226
+ ctrlKey: false,
227
+ altKey: false,
228
+ pointerType: "mouse",
229
+ origin: { preventDefault() { } },
230
+ });
231
+ },
232
+ dispose: () => stack.dispose(),
233
+ };
234
+ // Deleted nodes and relations leave the selection and hover (React Flow
235
+ // drops removed elements from its selection).
236
+ const prune = engine.store.subscribe((state) => [state.document.nodes, state.document.relations], ([nodes, relations]) => {
237
+ const { selectedIds, selectedRelationIds, hoveredId, hoveredRelationId } = engine.store.get().interaction;
238
+ const keptNodes = selectedIds.filter((id) => nodes[id]);
239
+ const keptRelations = selectedRelationIds.filter((id) => relations[id]);
240
+ if (keptNodes.length !== selectedIds.length ||
241
+ keptRelations.length !== selectedRelationIds.length ||
242
+ (hoveredId && !nodes[hoveredId]) ||
243
+ (hoveredRelationId && !relations[hoveredRelationId])) {
244
+ engine.store.set("interaction", {
245
+ selectedIds: keptNodes,
246
+ selectedRelationIds: keptRelations,
247
+ hoveredId: hoveredId && nodes[hoveredId] ? hoveredId : null,
248
+ hoveredRelationId: hoveredRelationId && relations[hoveredRelationId] ? hoveredRelationId : null,
249
+ });
250
+ }
251
+ }, { equals: (a, b) => a[0] === b[0] && a[1] === b[1] });
252
+ stack.use(() => prune.dispose());
253
+ for (const behavior of behaviors) {
254
+ const cleanup = behavior(controller);
255
+ stack.use(typeof cleanup === "function" ? cleanup : () => cleanup.dispose());
256
+ }
257
+ stack.use(() => events.clear());
258
+ return controller;
259
+ }
260
+ /** The interaction plugin: the controller as an engine service. */
261
+ export function interactionPlugin(options = {}, behaviors = DEFAULT_BEHAVIORS) {
262
+ return {
263
+ name: "interaction",
264
+ setup({ engine, track }) {
265
+ const controller = track(createInteraction(engine, options, behaviors));
266
+ track(engine.services.register(InteractionKey, controller));
267
+ },
268
+ };
269
+ }
@@ -0,0 +1,45 @@
1
+ import type { NodeId } from "../core/ids.js";
2
+ import { type AnchorBox } from "../geometry/anchors.js";
3
+ import type { WorldPoint } from "../geometry/spaces.js";
4
+ import type { Engine } from "../core/engine.js";
5
+ import type { SceneNode } from "../scene/scene-graph.js";
6
+ import type { TransformHandle } from "../events/event.js";
7
+ export type Hit = {
8
+ kind: "pane";
9
+ } | {
10
+ kind: "node";
11
+ id: NodeId;
12
+ } | {
13
+ kind: "anchor";
14
+ nodeId: NodeId;
15
+ anchor: AnchorBox;
16
+ } | {
17
+ kind: "relation";
18
+ id: string;
19
+ } | {
20
+ kind: "transform";
21
+ nodeId: NodeId;
22
+ handle: TransformHandle;
23
+ };
24
+ export type HitOptions = {
25
+ zoom: number;
26
+ /** Extra reach around an anchor box, screen px. */
27
+ anchorSlop: number;
28
+ /** Half the width of a relation's hit stroke, screen px. */
29
+ relationTolerance: number;
30
+ /** A transform handle's size, screen px. */
31
+ handleSize: number;
32
+ /** How far above the node the rotation handle sits, screen px. */
33
+ rotateOffset: number;
34
+ /** Transform handles for this node (the single selected one), if any. */
35
+ transformNodeId: NodeId | null;
36
+ /** Hidden nodes and those of collapsed frames aren't hit. */
37
+ isHittable?: (node: SceneNode) => boolean;
38
+ };
39
+ /** A point in a node's own space. */
40
+ export declare function toLocal(node: SceneNode, point: WorldPoint): import("../index.js").Vec2;
41
+ /** An anchor's box in world space (its centre and the same box around it). */
42
+ export declare function anchorWorldPoint(node: SceneNode, anchor: AnchorBox): WorldPoint;
43
+ export declare function hitTest(engine: Engine, point: WorldPoint, options: HitOptions): Hit;
44
+ /** A relation's curve in world space (`bezierControls`), or null. */
45
+ export declare function relationCurve(engine: Engine, relationId: string): [number, number, number, number, number, number, number, number] | null;
@@ -0,0 +1,119 @@
1
+ import { anchorPoint } from "../geometry/anchors.js";
2
+ import { applyToPoint, invert } from "../geometry/matrix.js";
3
+ import { bezierControls, distanceToBezier } from "../geometry/curves.js";
4
+ /** A point in a node's own space. */
5
+ export function toLocal(node, point) {
6
+ const inverse = invert(node.world);
7
+ return inverse ? applyToPoint(inverse, point) : { x: NaN, y: NaN };
8
+ }
9
+ const inside = (x, y, w, h, slop = 0) => x >= -slop && y >= -slop && x <= w + slop && y <= h + slop;
10
+ /** An anchor's box in world space (its centre and the same box around it). */
11
+ export function anchorWorldPoint(node, anchor) {
12
+ return applyToPoint(node.world, anchorPoint(anchor));
13
+ }
14
+ export function hitTest(engine, point, options) {
15
+ const scene = engine.scene;
16
+ const toWorldUnits = (px) => px / options.zoom;
17
+ const hittable = (node) => node.record.visible && (options.isHittable?.(node) ?? true);
18
+ // 1. The selected node's handles.
19
+ if (options.transformNodeId) {
20
+ const node = scene.get(options.transformNodeId);
21
+ if (node && hittable(node) && !node.record.locked) {
22
+ const local = toLocal(node, point);
23
+ const { w, h } = scene.sizeOf(node);
24
+ const scale = Math.hypot(node.world[0], node.world[1]) || 1;
25
+ const half = toWorldUnits(options.handleSize) / scale;
26
+ const corners = [
27
+ ["nw", 0, 0],
28
+ ["ne", w, 0],
29
+ ["se", w, h],
30
+ ["sw", 0, h],
31
+ ];
32
+ for (const [handle, x, y] of corners) {
33
+ if (Math.abs(local.x - x) <= half && Math.abs(local.y - y) <= half) {
34
+ return { kind: "transform", nodeId: node.id, handle };
35
+ }
36
+ }
37
+ const rotateY = -toWorldUnits(options.rotateOffset) / scale;
38
+ if (Math.hypot(local.x - w / 2, local.y - rotateY) <= half * 1.5) {
39
+ return { kind: "transform", nodeId: node.id, handle: "rotate" };
40
+ }
41
+ }
42
+ }
43
+ // 2–3. Anchors and nodes, topmost first (the walk is back to front).
44
+ const nodes = [...scene.walk()].filter(hittable);
45
+ for (let i = nodes.length - 1; i >= 0; i--) {
46
+ const node = nodes[i];
47
+ const local = toLocal(node, point);
48
+ const scale = Math.hypot(node.world[0], node.world[1]) || 1;
49
+ const slop = toWorldUnits(options.anchorSlop) / scale;
50
+ for (const anchor of engine.schemas.anchors(node.record)) {
51
+ if (inside(local.x - anchor.x, local.y - anchor.y, anchor.w, anchor.h, slop)) {
52
+ return { kind: "anchor", nodeId: node.id, anchor };
53
+ }
54
+ }
55
+ }
56
+ let best = null;
57
+ for (const node of nodes) {
58
+ const local = toLocal(node, point);
59
+ const { w, h } = scene.sizeOf(node);
60
+ if (!inside(local.x, local.y, w, h))
61
+ continue;
62
+ // Later in the walk is above; a frame never beats a node inside it.
63
+ best = node;
64
+ }
65
+ if (best)
66
+ return { kind: "node", id: best.id };
67
+ // 4. Relations.
68
+ const tolerance = toWorldUnits(options.relationTolerance);
69
+ const document = engine.store.get().document;
70
+ let nearest = null;
71
+ for (const relation of Object.values(document.relations)) {
72
+ const curve = relationCurve(engine, relation.id);
73
+ if (!curve)
74
+ continue;
75
+ const distance = distanceToBezier(curve, point);
76
+ if (distance <= tolerance && (!nearest || distance < nearest.distance)) {
77
+ nearest = { id: relation.id, distance };
78
+ }
79
+ }
80
+ if (nearest)
81
+ return { kind: "relation", id: nearest.id };
82
+ return { kind: "pane" };
83
+ }
84
+ /** A relation's curve in world space (`bezierControls`), or null. */
85
+ export function relationCurve(engine, relationId) {
86
+ const relation = engine.store.get().document.relations[relationId];
87
+ if (!relation)
88
+ return null;
89
+ const end = (nodeId, anchorId, type) => {
90
+ const node = engine.scene.get(nodeId);
91
+ if (!node)
92
+ return null;
93
+ const anchors = engine.schemas
94
+ .anchors(node.record)
95
+ .filter((anchor) => anchor.type === type);
96
+ const anchor = (anchorId ? anchors.find((each) => each.id === anchorId) : undefined) ??
97
+ anchors[0];
98
+ if (anchor)
99
+ return { point: anchorWorldPoint(node, anchor), side: anchor.side };
100
+ // No anchors: the side's middle of the node's box.
101
+ const { w, h } = engine.scene.sizeOf(node);
102
+ return {
103
+ point: applyToPoint(node.world, type === "source" ? { x: w, y: h / 2 } : { x: 0, y: h / 2 }),
104
+ side: type === "source" ? "right" : "left",
105
+ };
106
+ };
107
+ const source = end(relation.source.nodeId, relation.source.anchor, "source");
108
+ const target = end(relation.target.nodeId, relation.target.anchor, "target");
109
+ if (!source || !target)
110
+ return null;
111
+ return bezierControls({
112
+ sourceX: source.point.x,
113
+ sourceY: source.point.y,
114
+ sourceSide: source.side,
115
+ targetX: target.point.x,
116
+ targetY: target.point.y,
117
+ targetSide: target.side,
118
+ });
119
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./hit-test.js";
2
+ export * from "./controller.js";
3
+ export * from "./behaviors.js";
4
+ export * from "./web-input.js";
@@ -0,0 +1,7 @@
1
+ // AVIS Engine · interaction — Phase 2: hit testing, gestures with
2
+ // arbitration, the built-in behaviours and browser input
3
+ // (docs/canvas-engine-plan.md).
4
+ export * from "./hit-test.js";
5
+ export * from "./controller.js";
6
+ export * from "./behaviors.js";
7
+ export * from "./web-input.js";
@@ -0,0 +1,13 @@
1
+ import type { Disposable } from "../core/disposable.js";
2
+ import type { InteractionController } from "./controller.js";
3
+ /** What the adapter needs of the element (an HTMLElement has it all). */
4
+ export type InputElement = Pick<HTMLElement, "addEventListener" | "removeEventListener" | "getBoundingClientRect" | "style"> & Partial<Pick<HTMLElement, "setPointerCapture" | "releasePointerCapture" | "hasPointerCapture">>;
5
+ export type WebInputOptions = {
6
+ /** The window for the pixel ratio and blur (defaults to the global one). */
7
+ window?: Pick<Window, "addEventListener" | "removeEventListener"> & {
8
+ devicePixelRatio?: number;
9
+ };
10
+ /** Watches the element's size (defaults to ResizeObserver when there is one). */
11
+ observeSize?: (element: InputElement, onResize: () => void) => Disposable;
12
+ };
13
+ export declare function attachWebInput(controller: InteractionController, element: InputElement, options?: WebInputOptions): Disposable;