@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,172 @@
1
+ const isTyping = (target) => {
2
+ const element = target;
3
+ if (!element)
4
+ return false;
5
+ if (element.isContentEditable)
6
+ return true;
7
+ return (element.tagName === "INPUT" ||
8
+ element.tagName === "TEXTAREA" ||
9
+ element.tagName === "SELECT");
10
+ };
11
+ export function attachWebInput(controller, element, options = {}) {
12
+ const { engine } = controller;
13
+ const win = options.window ?? (typeof window === "undefined" ? undefined : window);
14
+ const cleanups = [];
15
+ const listen = (target, type, handler, init) => {
16
+ target.addEventListener(type, handler, init);
17
+ cleanups.push(() => target.removeEventListener(type, handler, init));
18
+ };
19
+ // The button held since the press: a pointermove's own `button` is -1,
20
+ // and gestures check which button drags.
21
+ let pressedButton = null;
22
+ // The element's box, read once per event (layout may move it).
23
+ const local = (event) => {
24
+ const rect = element.getBoundingClientRect();
25
+ return {
26
+ clientX: event.clientX - rect.left,
27
+ clientY: event.clientY - rect.top,
28
+ button: event.button < 0 ? (pressedButton ?? 0) : event.button,
29
+ buttons: event.buttons,
30
+ shiftKey: event.shiftKey,
31
+ metaKey: event.metaKey,
32
+ ctrlKey: event.ctrlKey,
33
+ altKey: event.altKey,
34
+ pointerType: event.pointerType ?? "mouse",
35
+ origin: event,
36
+ };
37
+ };
38
+ // Only the first pointer drives a gesture (no multi-touch yet).
39
+ let activePointer = null;
40
+ listen(element, "pointerdown", (event) => {
41
+ if (activePointer !== null && activePointer !== event.pointerId)
42
+ return;
43
+ if (event.button !== 2) {
44
+ activePointer = event.pointerId;
45
+ pressedButton = event.button;
46
+ element.setPointerCapture?.(event.pointerId);
47
+ }
48
+ controller.pointerDown(local(event));
49
+ });
50
+ listen(element, "pointermove", (event) => {
51
+ if (activePointer !== null && activePointer !== event.pointerId)
52
+ return;
53
+ controller.pointerMove(local(event));
54
+ });
55
+ const release = (event) => {
56
+ if (element.hasPointerCapture?.(event.pointerId)) {
57
+ element.releasePointerCapture?.(event.pointerId);
58
+ }
59
+ activePointer = null;
60
+ pressedButton = null;
61
+ };
62
+ listen(element, "pointerup", (event) => {
63
+ if (activePointer !== null && activePointer !== event.pointerId)
64
+ return;
65
+ const input = local(event);
66
+ release(event);
67
+ controller.pointerUp(input);
68
+ });
69
+ listen(element, "pointercancel", (event) => {
70
+ if (activePointer !== event.pointerId)
71
+ return;
72
+ const input = local(event);
73
+ release(event);
74
+ controller.pointerCancel(input);
75
+ });
76
+ listen(element, "pointerleave", (event) => {
77
+ if (activePointer === null)
78
+ controller.pointerLeave(local(event));
79
+ });
80
+ listen(element, "dblclick", (event) => controller.doubleClick(local(event)));
81
+ listen(element, "contextmenu", (event) => {
82
+ event.preventDefault();
83
+ controller.contextMenu(local(event));
84
+ });
85
+ listen(element, "wheel", (event) => {
86
+ const rect = element.getBoundingClientRect();
87
+ // Lines and pages as pixels (Firefox's mouse wheels).
88
+ const scale = event.deltaMode === 1
89
+ ? 16
90
+ : event.deltaMode === 2
91
+ ? rect.height || 800
92
+ : 1;
93
+ const handled = controller.wheel({
94
+ clientX: event.clientX - rect.left,
95
+ clientY: event.clientY - rect.top,
96
+ deltaX: event.deltaX * scale,
97
+ deltaY: event.deltaY * scale,
98
+ ctrlKey: event.ctrlKey,
99
+ metaKey: event.metaKey,
100
+ shiftKey: event.shiftKey,
101
+ });
102
+ if (handled)
103
+ event.preventDefault();
104
+ }, { passive: false });
105
+ const keyInput = (event) => ({
106
+ key: event.key,
107
+ metaKey: event.metaKey,
108
+ ctrlKey: event.ctrlKey,
109
+ shiftKey: event.shiftKey,
110
+ altKey: event.altKey,
111
+ typing: isTyping(event.target),
112
+ });
113
+ listen(element, "keydown", (event) => {
114
+ if (event.isComposing)
115
+ return;
116
+ if (controller.keyDown(keyInput(event)))
117
+ event.preventDefault();
118
+ });
119
+ listen(element, "keyup", (event) => controller.keyUp(keyInput(event)));
120
+ // Keys held when the window loses focus never come back up.
121
+ if (win) {
122
+ listen(win, "blur", () => {
123
+ controller.keyUp({
124
+ key: " ",
125
+ metaKey: false,
126
+ ctrlKey: false,
127
+ shiftKey: false,
128
+ altKey: false,
129
+ });
130
+ });
131
+ }
132
+ // The viewport's size and pixel ratio.
133
+ const measure = () => {
134
+ const rect = element.getBoundingClientRect();
135
+ engine.store.set("viewport", {
136
+ size: { width: rect.width, height: rect.height },
137
+ dpr: win?.devicePixelRatio ?? 1,
138
+ });
139
+ };
140
+ measure();
141
+ const observeSize = options.observeSize ??
142
+ (typeof ResizeObserver === "undefined"
143
+ ? null
144
+ : (target, onResize) => {
145
+ const observer = new ResizeObserver(onResize);
146
+ observer.observe(target);
147
+ return { dispose: () => observer.disconnect() };
148
+ });
149
+ if (observeSize) {
150
+ const observer = observeSize(element, measure);
151
+ cleanups.push(() => observer.dispose());
152
+ }
153
+ // The cursor the behaviours ask for.
154
+ const previousCursor = element.style.cursor;
155
+ const cursor = engine.store.subscribe((state) => state.interaction.cursor, (value) => {
156
+ element.style.cursor = value;
157
+ }, { fireImmediately: true });
158
+ cleanups.push(() => {
159
+ cursor.dispose();
160
+ element.style.cursor = previousCursor;
161
+ });
162
+ let disposed = false;
163
+ return {
164
+ dispose() {
165
+ if (disposed)
166
+ return;
167
+ disposed = true;
168
+ for (const cleanup of cleanups.reverse())
169
+ cleanup();
170
+ },
171
+ };
172
+ }
@@ -0,0 +1 @@
1
+ export * from "./layout.js";
@@ -0,0 +1,2 @@
1
+ // AVIS Engine · layout — Phase 4: block, flex and grid layout of styled boxes.
2
+ export * from "./layout.js";
@@ -0,0 +1,27 @@
1
+ import type { ComputedStyle } from "../style/computed.js";
2
+ export type LayoutStyle = Pick<ComputedStyle, "display" | "flexDirection" | "alignItems" | "alignSelf" | "justifyContent" | "gapX" | "gapY" | "gridCols" | "colSpan" | "padding" | "margin" | "marginAuto" | "width" | "height" | "minWidth" | "minHeight" | "maxWidth" | "maxHeight" | "grow" | "shrink" | "basis" | "position" | "inset" | "borderWidth">;
3
+ export type LayoutNode = {
4
+ style: LayoutStyle;
5
+ children?: readonly LayoutNode[];
6
+ /** A leaf's content size at a width (text), in px. */
7
+ measure?: (maxWidth: number) => {
8
+ w: number;
9
+ h: number;
10
+ };
11
+ };
12
+ export type LayoutBox = {
13
+ x: number;
14
+ y: number;
15
+ w: number;
16
+ h: number;
17
+ children: LayoutBox[];
18
+ };
19
+ /** Max-content width, capped by `maxWidth` (shrink-to-fit). */
20
+ export declare function contentWidth(node: LayoutNode, maxWidth: number): number;
21
+ /**
22
+ * Lays a node out at width `w` (and height `h` when it is fixed by the
23
+ * parent); `containerH` resolves % heights.
24
+ */
25
+ export declare function layoutAt(node: LayoutNode, w: number, h: number | null, containerH?: number | null): LayoutBox;
26
+ /** Lays out a root that fills `width` (and `height` when given). */
27
+ export declare function layout(root: LayoutNode, width: number, height?: number | null): LayoutBox;
@@ -0,0 +1,266 @@
1
+ const resolve = (size, reference) => typeof size === "number" ? size : size === "auto" ? null : reference === null ? null : (size.percent / 100) * reference;
2
+ function clamp(value, min, max, reference) {
3
+ const lo = resolve(min, reference) ?? 0;
4
+ const hi = resolve(max, reference) ?? Infinity;
5
+ return Math.max(lo, Math.min(hi, value));
6
+ }
7
+ const edges = (s) => ({
8
+ left: s.padding[3] + s.borderWidth,
9
+ right: s.padding[1] + s.borderWidth,
10
+ top: s.padding[0] + s.borderWidth,
11
+ bottom: s.padding[2] + s.borderWidth,
12
+ });
13
+ const inFlow = (child) => child.style.display !== "none" && child.style.position !== "absolute";
14
+ const isColumn = (s) => s.display === "block" || (s.display === "flex" && s.flexDirection === "column");
15
+ const alignOf = (child, parent) => parent.display === "block" ? "stretch" : child.style.alignSelf === "auto" ? parent.alignItems : child.style.alignSelf;
16
+ /** Max-content width, capped by `maxWidth` (shrink-to-fit). */
17
+ export function contentWidth(node, maxWidth) {
18
+ const s = node.style;
19
+ const e = edges(s);
20
+ const fixed = resolve(s.width, maxWidth);
21
+ if (fixed !== null)
22
+ return clamp(fixed, s.minWidth, s.maxWidth, maxWidth);
23
+ const inner = Math.max(0, maxWidth - e.left - e.right);
24
+ let width;
25
+ if (node.measure) {
26
+ width = node.measure(inner).w;
27
+ }
28
+ else {
29
+ const children = (node.children ?? []).filter(inFlow);
30
+ const outer = children.map((child) => contentWidth(child, inner) + child.style.margin[1] + child.style.margin[3]);
31
+ if (s.display === "flex" && s.flexDirection === "row") {
32
+ width = outer.reduce((sum, w) => sum + w, 0) + s.gapX * Math.max(0, children.length - 1);
33
+ }
34
+ else if (s.display === "grid") {
35
+ const cols = Math.max(1, s.gridCols);
36
+ width = Math.max(0, ...outer) * cols + s.gapX * (cols - 1);
37
+ }
38
+ else {
39
+ width = Math.max(0, ...outer);
40
+ }
41
+ }
42
+ return clamp(Math.min(maxWidth, width + e.left + e.right), s.minWidth, s.maxWidth, maxWidth);
43
+ }
44
+ /**
45
+ * Lays a node out at width `w` (and height `h` when it is fixed by the
46
+ * parent); `containerH` resolves % heights.
47
+ */
48
+ export function layoutAt(node, w, h, containerH = null) {
49
+ const s = node.style;
50
+ const e = edges(s);
51
+ const innerW = Math.max(0, w - e.left - e.right);
52
+ const ownH = h ?? resolve(s.height, containerH);
53
+ const innerH = ownH === null ? null : Math.max(0, ownH - e.top - e.bottom);
54
+ const children = node.children ?? [];
55
+ const boxes = children.map(() => ({ x: 0, y: 0, w: 0, h: 0, children: [] }));
56
+ let contentH = 0;
57
+ if (node.measure && !children.length) {
58
+ contentH = node.measure(innerW).h;
59
+ }
60
+ else if (s.display === "grid") {
61
+ contentH = layoutGrid(node, innerW, innerH, boxes, e);
62
+ }
63
+ else if (isColumn(s)) {
64
+ contentH = layoutColumn(node, innerW, innerH, boxes, e);
65
+ }
66
+ else if (s.display === "flex") {
67
+ contentH = layoutRow(node, innerW, innerH, boxes, e);
68
+ }
69
+ let height = ownH ?? contentH + e.top + e.bottom;
70
+ height = clamp(height, s.minHeight, s.maxHeight, containerH);
71
+ // Absolute children, against the padding box.
72
+ children.forEach((child, i) => {
73
+ if (child.style.display === "none" || child.style.position !== "absolute")
74
+ return;
75
+ const cs = child.style;
76
+ const padW = w - 2 * s.borderWidth;
77
+ const padH = height - 2 * s.borderWidth;
78
+ const [top, right, bottom, left] = cs.inset.map((value, k) => resolve(value, k % 2 ? padW : padH));
79
+ let cw = resolve(cs.width, padW);
80
+ if (cw === null)
81
+ cw = left !== null && right !== null ? padW - left - right : contentWidth(child, padW);
82
+ let ch = resolve(cs.height, padH);
83
+ if (ch === null && top !== null && bottom !== null)
84
+ ch = padH - top - bottom;
85
+ const box = layoutAt(child, cw, ch, padH);
86
+ box.x = s.borderWidth + (left ?? (right !== null ? padW - right - box.w : 0));
87
+ box.y = s.borderWidth + (top ?? (bottom !== null ? padH - bottom - box.h : 0));
88
+ boxes[i] = box;
89
+ });
90
+ return { x: 0, y: 0, w, h: height, children: boxes };
91
+ }
92
+ /** Free space along the main axis → offsets (justify-content). */
93
+ function justify(mode, free, count) {
94
+ if (free <= 0 || count === 0)
95
+ return { start: 0, between: 0 };
96
+ switch (mode) {
97
+ case "center":
98
+ return { start: free / 2, between: 0 };
99
+ case "end":
100
+ return { start: free, between: 0 };
101
+ case "between":
102
+ return count > 1 ? { start: 0, between: free / (count - 1) } : { start: 0, between: 0 };
103
+ case "around":
104
+ return { start: free / count / 2, between: free / count };
105
+ case "evenly":
106
+ return { start: free / (count + 1), between: free / (count + 1) };
107
+ default:
108
+ return { start: 0, between: 0 };
109
+ }
110
+ }
111
+ /** Grow or shrink sizes to fill `available` (flex's free-space pass). */
112
+ function flex(nodes, basis, outerExtra, available, gaps, mainMin) {
113
+ const sizes = [...basis];
114
+ if (available === null)
115
+ return sizes;
116
+ const used = sizes.reduce((sum, v, i) => sum + v + outerExtra[i], 0) + gaps;
117
+ let free = available - used;
118
+ if (free > 0) {
119
+ const grow = nodes.reduce((sum, n) => sum + n.style.grow, 0);
120
+ if (grow > 0)
121
+ nodes.forEach((n, i) => (sizes[i] = mainMin(i, sizes[i] + (free * n.style.grow) / grow)));
122
+ }
123
+ else if (free < 0) {
124
+ // Shrink by weight shrink × basis, never under the min size.
125
+ for (let pass = 0; pass < 3 && free < -0.01; pass++) {
126
+ const weights = nodes.map((n, i) => n.style.shrink * sizes[i]);
127
+ const total = weights.reduce((sum, v) => sum + v, 0);
128
+ if (total <= 0)
129
+ break;
130
+ let taken = 0;
131
+ nodes.forEach((_, i) => {
132
+ const next = mainMin(i, sizes[i] + (free * weights[i]) / total);
133
+ taken += sizes[i] - next;
134
+ sizes[i] = next;
135
+ });
136
+ free += taken;
137
+ }
138
+ }
139
+ return sizes;
140
+ }
141
+ function layoutRow(node, innerW, innerH, boxes, e) {
142
+ const s = node.style;
143
+ const items = (node.children ?? []).map((child, i) => ({ child, i })).filter(({ child }) => inFlow(child));
144
+ const nodes = items.map(({ child }) => child);
145
+ const marginX = nodes.map((n) => n.style.margin[1] + n.style.margin[3]);
146
+ const basis = nodes.map((n) => {
147
+ const b = resolve(n.style.basis, innerW) ?? resolve(n.style.width, innerW);
148
+ return b ?? contentWidth(n, innerW);
149
+ });
150
+ const gaps = s.gapX * Math.max(0, nodes.length - 1);
151
+ const widths = flex(nodes, basis, marginX, innerW, gaps, (i, v) => clamp(Math.max(0, v), nodes[i].style.minWidth, nodes[i].style.maxWidth, innerW));
152
+ // Heights: fixed, or content; then stretch to the line.
153
+ const laid = nodes.map((n, i) => layoutAt(n, widths[i], resolve(n.style.height, innerH), innerH));
154
+ const line = innerH ?? Math.max(0, ...laid.map((box, i) => box.h + nodes[i].style.margin[0] + nodes[i].style.margin[2]));
155
+ nodes.forEach((n, i) => {
156
+ if (alignOf(n, s) === "stretch" && n.style.height === "auto") {
157
+ laid[i] = layoutAt(n, widths[i], Math.max(0, line - n.style.margin[0] - n.style.margin[2]), innerH);
158
+ }
159
+ });
160
+ const used = widths.reduce((sum, v, i) => sum + v + marginX[i], 0) + gaps;
161
+ // Auto margins take the free space first (then justify has none left).
162
+ const autos = nodes.reduce((sum, n) => sum + +n.style.marginAuto[3] + +n.style.marginAuto[1], 0);
163
+ const autoShare = autos ? Math.max(0, innerW - used) / autos : 0;
164
+ const { start, between } = autos ? { start: 0, between: 0 } : justify(s.justifyContent, innerW - used, nodes.length);
165
+ let x = e.left + start;
166
+ nodes.forEach((n, i) => {
167
+ const box = laid[i];
168
+ const m = n.style.margin;
169
+ if (n.style.marginAuto[3])
170
+ x += autoShare;
171
+ const outerH = box.h + m[0] + m[2];
172
+ const align = alignOf(n, s);
173
+ const offset = align === "center" ? (line - outerH) / 2 : align === "end" ? line - outerH : 0;
174
+ box.x = x + m[3];
175
+ box.y = e.top + offset + m[0];
176
+ boxes[items[i].i] = box;
177
+ x += box.w + marginX[i] + s.gapX + (i < nodes.length - 1 ? between : 0) + (n.style.marginAuto[1] ? autoShare : 0);
178
+ });
179
+ return line;
180
+ }
181
+ function layoutColumn(node, innerW, innerH, boxes, e) {
182
+ const s = node.style;
183
+ const gapY = s.display === "block" ? 0 : s.gapY;
184
+ const items = (node.children ?? []).map((child, i) => ({ child, i })).filter(({ child }) => inFlow(child));
185
+ const nodes = items.map(({ child }) => child);
186
+ const widths = nodes.map((n) => {
187
+ const mx = n.style.margin[1] + n.style.margin[3];
188
+ const fixed = resolve(n.style.width, innerW);
189
+ if (fixed !== null)
190
+ return clamp(fixed, n.style.minWidth, n.style.maxWidth, innerW);
191
+ if (alignOf(n, s) === "stretch")
192
+ return clamp(Math.max(0, innerW - mx), n.style.minWidth, n.style.maxWidth, innerW);
193
+ return contentWidth(n, Math.max(0, innerW - mx));
194
+ });
195
+ const marginY = nodes.map((n) => n.style.margin[0] + n.style.margin[2]);
196
+ const natural = nodes.map((n, i) => layoutAt(n, widths[i], resolve(n.style.basis, innerH) ?? resolve(n.style.height, innerH), innerH));
197
+ const gaps = gapY * Math.max(0, nodes.length - 1);
198
+ const heights = flex(nodes, natural.map((box) => box.h), marginY, s.display === "flex" ? innerH : null, gaps, (i, v) => clamp(Math.max(0, v), nodes[i].style.minHeight, nodes[i].style.maxHeight, innerH));
199
+ const laid = nodes.map((n, i) => (heights[i] !== natural[i].h ? layoutAt(n, widths[i], heights[i], innerH) : natural[i]));
200
+ const used = heights.reduce((sum, v, i) => sum + v + marginY[i], 0) + gaps;
201
+ const autos = innerH === null ? 0 : nodes.reduce((sum, n) => sum + +n.style.marginAuto[0] + +n.style.marginAuto[2], 0);
202
+ const autoShare = autos ? Math.max(0, innerH - used) / autos : 0;
203
+ const { start, between } = s.display === "flex" && innerH !== null && !autos ? justify(s.justifyContent, innerH - used, nodes.length) : { start: 0, between: 0 };
204
+ let y = e.top + start;
205
+ nodes.forEach((n, i) => {
206
+ const box = laid[i];
207
+ const m = n.style.margin;
208
+ if (n.style.marginAuto[0])
209
+ y += autoShare;
210
+ const outerW = box.w + m[1] + m[3];
211
+ const align = alignOf(n, s);
212
+ const offset = align === "center" ? (innerW - outerW) / 2 : align === "end" ? innerW - outerW : 0;
213
+ box.x = e.left + offset + m[3];
214
+ box.y = y + m[0];
215
+ boxes[items[i].i] = box;
216
+ y += box.h + marginY[i] + gapY + (i < nodes.length - 1 ? between : 0) + (n.style.marginAuto[2] ? autoShare : 0);
217
+ });
218
+ return y - e.top - (nodes.length ? gapY : 0) + 0;
219
+ }
220
+ function layoutGrid(node, innerW, innerH, boxes, e) {
221
+ const s = node.style;
222
+ const cols = Math.max(1, s.gridCols);
223
+ const colW = Math.max(0, (innerW - s.gapX * (cols - 1)) / cols);
224
+ const items = (node.children ?? []).map((child, i) => ({ child, i })).filter(({ child }) => inFlow(child));
225
+ // Place row-major with spans.
226
+ const rows = [];
227
+ let row = [];
228
+ let col = 0;
229
+ for (const item of items) {
230
+ const span = Math.min(cols, Math.max(1, item.child.style.colSpan));
231
+ if (col + span > cols) {
232
+ rows.push(row);
233
+ row = [];
234
+ col = 0;
235
+ }
236
+ row.push({ ...item, col, span });
237
+ col += span;
238
+ }
239
+ if (row.length)
240
+ rows.push(row);
241
+ let y = e.top;
242
+ rows.forEach((cells, r) => {
243
+ const laid = cells.map(({ child, span }) => {
244
+ const width = colW * span + s.gapX * (span - 1) - child.style.margin[1] - child.style.margin[3];
245
+ return layoutAt(child, Math.max(0, resolve(child.style.width, width) ?? width), resolve(child.style.height, innerH), innerH);
246
+ });
247
+ const height = Math.max(0, ...laid.map((box, k) => box.h + cells[k].child.style.margin[0] + cells[k].child.style.margin[2]));
248
+ cells.forEach((cell, k) => {
249
+ let box = laid[k];
250
+ const m = cell.child.style.margin;
251
+ if (cell.child.style.height === "auto" && alignOf(cell.child, { ...s, display: "flex" }) === "stretch") {
252
+ box = layoutAt(cell.child, box.w, height - m[0] - m[2], innerH);
253
+ }
254
+ box.x = e.left + cell.col * (colW + s.gapX) + m[3];
255
+ box.y = y + m[0];
256
+ boxes[cell.i] = box;
257
+ });
258
+ y += height + (r < rows.length - 1 ? s.gapY : 0);
259
+ });
260
+ return y - e.top;
261
+ }
262
+ /** Lays out a root that fills `width` (and `height` when given). */
263
+ export function layout(root, width, height = null) {
264
+ const w = resolve(root.style.width, width) ?? width;
265
+ return layoutAt(root, clamp(w, root.style.minWidth, root.style.maxWidth, width), height === null ? null : resolve(root.style.height, height) ?? height, height);
266
+ }
@@ -0,0 +1,83 @@
1
+ import type { Edge, EdgeChange, InternalNode, Node, NodeChange, ReactFlowState } from "../flow/index.js";
2
+ /** A node as the graph keeps it: read it with the accessors below. */
3
+ export type GraphNodeRef<N extends Node = Node> = InternalNode<N>;
4
+ /** A node's absolute position (inside frames too), in flow units. */
5
+ export declare function nodePosition(node: GraphNodeRef): {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ /** A node's size: measured from its DOM, else declared, else 0. */
10
+ export declare function nodeSize(node: GraphNodeRef): {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ /** A node's stacking layer (higher is drawn above). */
15
+ export declare function nodeLayer(node: GraphNodeRef): number;
16
+ /** A node's handle, relative to the node's top-left. */
17
+ export type NodeHandleRect = {
18
+ id?: string | null;
19
+ type: "source" | "target";
20
+ position: string;
21
+ x: number;
22
+ y: number;
23
+ width?: number;
24
+ height?: number;
25
+ };
26
+ /** A node's handles: measured from its DOM, else the declared `handles`. */
27
+ export declare function nodeHandles(node: GraphNodeRef): NodeHandleRect[];
28
+ /** The node as the app gave it (its data, type, flags). */
29
+ export declare function appNode<N extends Node = Node>(node: GraphNodeRef): N;
30
+ /** The canvas's behaviour settings (from <GraphCanvas> props and keys). */
31
+ export type GraphOptions = Pick<ReactFlowState, "elementsSelectable" | "nodesDraggable" | "nodesConnectable" | "selectNodesOnDrag" | "multiSelectionActive" | "snapToGrid" | "snapGrid" | "connectionMode" | "connectionRadius" | "nodeDragThreshold" | "connectionDragThreshold">;
32
+ /** The page's handlers given to <GraphCanvas>, for the engine to call. */
33
+ export type GraphHandlers = Pick<ReactFlowState, "onNodeDragStart" | "onNodeDrag" | "onNodeDragStop" | "onConnectStart" | "onConnect" | "onConnectEnd" | "isValidConnection">;
34
+ /** Reading the graph, the camera and the canvas element. */
35
+ export type GraphView = {
36
+ nodes(): IterableIterator<GraphNodeRef>;
37
+ node(id: string): GraphNodeRef | undefined;
38
+ edges(): Edge[];
39
+ edge(id: string): Edge | undefined;
40
+ viewport(): {
41
+ x: number;
42
+ y: number;
43
+ zoom: number;
44
+ };
45
+ paneSize(): {
46
+ width: number;
47
+ height: number;
48
+ };
49
+ element(): HTMLDivElement | null;
50
+ options(): GraphOptions;
51
+ /** Whether a selection box is being drawn. */
52
+ selectionRectActive(): boolean;
53
+ };
54
+ /** Reading and changing the graph (selection, positions, events). */
55
+ export type GraphController = GraphView & {
56
+ /** Node changes, through the page's onNodesChange (and selection events). */
57
+ applyNodeChanges(changes: NodeChange[]): void;
58
+ applyEdgeChanges(changes: EdgeChange[]): void;
59
+ /** Selects these nodes alone (with multi-select held: adds them). */
60
+ selectNodes(ids: string[]): void;
61
+ selectEdges(ids: string[]): void;
62
+ /** Unselects these, or everything when none are given. */
63
+ unselect(items?: {
64
+ nodes?: Node[];
65
+ edges?: Edge[];
66
+ }): void;
67
+ /** Unselects everything (respects `elementsSelectable`). */
68
+ clearSelection(): void;
69
+ /** Ends the box selection's "selected group" state. */
70
+ endNodesSelection(): void;
71
+ /** Removes the selection box. */
72
+ clearSelectionRect(): void;
73
+ handlers(): GraphHandlers;
74
+ /** Calls `listener` after every change of the graph or camera. */
75
+ subscribe(listener: () => void): () => void;
76
+ };
77
+ /** The canvas's graph controller (stable for the canvas's lifetime). */
78
+ export declare function useGraphController(): GraphController;
79
+ /**
80
+ * A value derived from the graph view; the component re-renders only when
81
+ * `equals` (default `Object.is`) says it changed.
82
+ */
83
+ export declare function useGraphView<T>(select: (graph: GraphView) => T, equals?: (a: T, b: T) => boolean): T;
@@ -0,0 +1,89 @@
1
+ /*
2
+ * AVIS Engine · the graph store behind <GraphCanvas>, as AVIS's own API
3
+ * (docs/avis-engine/NATIVE-API-PLAN.md, "Còn lại" 1, step 3).
4
+ *
5
+ * App code (the canvas engine's glue in features/canvas included) reads
6
+ * and changes the graph through a `GraphView` / `GraphController` and the
7
+ * node accessors below, never through the store's fields (`nodeLookup`,
8
+ * `internals`, `transform`, `domNode`, `triggerNodeChanges`…). The store
9
+ * keeps React Flow's shape inside the engine; it can change behind this API.
10
+ */
11
+ import { useMemo } from "react";
12
+ import { useStore, useStoreApi } from "../flow/hooks.js";
13
+ /** A node's absolute position (inside frames too), in flow units. */
14
+ export function nodePosition(node) {
15
+ return node.internals.positionAbsolute;
16
+ }
17
+ /** A node's size: measured from its DOM, else declared, else 0. */
18
+ export function nodeSize(node) {
19
+ return {
20
+ width: node.measured.width ?? node.width ?? 0,
21
+ height: node.measured.height ?? node.height ?? 0,
22
+ };
23
+ }
24
+ /** A node's stacking layer (higher is drawn above). */
25
+ export function nodeLayer(node) {
26
+ return node.internals.z;
27
+ }
28
+ /** A node's handles: measured from its DOM, else the declared `handles`. */
29
+ export function nodeHandles(node) {
30
+ const bounds = node.internals.handleBounds;
31
+ return (bounds
32
+ ? [...(bounds.source ?? []), ...(bounds.target ?? [])]
33
+ : (node.handles ?? []));
34
+ }
35
+ /** The node as the app gave it (its data, type, flags). */
36
+ export function appNode(node) {
37
+ return node.internals.userNode;
38
+ }
39
+ function viewOf(read) {
40
+ return {
41
+ nodes: () => read().nodeLookup.values(),
42
+ node: (id) => read().nodeLookup.get(id),
43
+ edges: () => read().edges,
44
+ edge: (id) => (read().edgeLookup.get(id) ??
45
+ read().edges.find((edge) => edge.id === id)),
46
+ viewport: () => {
47
+ const [x, y, zoom] = read().transform;
48
+ return { x, y, zoom };
49
+ },
50
+ paneSize: () => ({ width: read().width, height: read().height }),
51
+ element: () => read().domNode,
52
+ options: () => read(),
53
+ selectionRectActive: () => Boolean(read().userSelectionRect),
54
+ };
55
+ }
56
+ const controllers = new WeakMap();
57
+ function controllerOf(store) {
58
+ let controller = controllers.get(store);
59
+ if (controller)
60
+ return controller;
61
+ const read = () => store.getState();
62
+ controller = {
63
+ ...viewOf(read),
64
+ applyNodeChanges: (changes) => read().triggerNodeChanges(changes),
65
+ applyEdgeChanges: (changes) => read().triggerEdgeChanges(changes),
66
+ selectNodes: (ids) => read().addSelectedNodes(ids),
67
+ selectEdges: (ids) => read().addSelectedEdges(ids),
68
+ unselect: (items) => read().unselectNodesAndEdges(items),
69
+ clearSelection: () => read().resetSelectedElements(),
70
+ endNodesSelection: () => store.setState({ nodesSelectionActive: false }),
71
+ clearSelectionRect: () => store.setState({ userSelectionRect: null, userSelectionActive: false }),
72
+ handlers: () => read(),
73
+ subscribe: (listener) => store.subscribe(listener),
74
+ };
75
+ controllers.set(store, controller);
76
+ return controller;
77
+ }
78
+ /** The canvas's graph controller (stable for the canvas's lifetime). */
79
+ export function useGraphController() {
80
+ const store = useStoreApi();
81
+ return useMemo(() => controllerOf(store), [store]);
82
+ }
83
+ /**
84
+ * A value derived from the graph view; the component re-renders only when
85
+ * `equals` (default `Object.is`) says it changed.
86
+ */
87
+ export function useGraphView(select, equals) {
88
+ return useStore((state) => select(viewOf(() => state)), equals);
89
+ }