@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,285 @@
1
+ /*
2
+ * React Flow v12's utilities and enums, as the app uses them: paths
3
+ * (getBezierPath is the engine's, which matches xyflow), addEdge, and the
4
+ * change appliers behind useNodesState / useEdgesState.
5
+ */
6
+ import { bezierPath } from "../../geometry/curves.js";
7
+ export const Position = { Left: "left", Top: "top", Right: "right", Bottom: "bottom" };
8
+ export const SelectionMode = { Partial: "partial", Full: "full" };
9
+ export const ConnectionMode = { Strict: "strict", Loose: "loose" };
10
+ export const BackgroundVariant = { Lines: "lines", Dots: "dots", Cross: "cross" };
11
+ export const MarkerType = { Arrow: "arrow", ArrowClosed: "arrowclosed" };
12
+ export const PanOnScrollMode = { Free: "free", Vertical: "vertical", Horizontal: "horizontal" };
13
+ /** [path, labelX, labelY, offsetX, offsetY], as xyflow's. */
14
+ export function getBezierPath({ sourcePosition = "bottom", targetPosition = "top", ...rest }) {
15
+ const out = bezierPath({
16
+ ...rest,
17
+ sourceSide: sourcePosition,
18
+ targetSide: targetPosition,
19
+ });
20
+ return [out.d, out.labelX, out.labelY, out.offsetX, out.offsetY];
21
+ }
22
+ export function getStraightPath({ sourceX, sourceY, targetX, targetY }) {
23
+ const [labelX, labelY, offsetX, offsetY] = getEdgeCenter({ sourceX, sourceY, targetX, targetY });
24
+ return [`M ${sourceX},${sourceY}L ${targetX},${targetY}`, labelX, labelY, offsetX, offsetY];
25
+ }
26
+ const DIRECTIONS = { left: { x: -1, y: 0 }, right: { x: 1, y: 0 }, top: { x: 0, y: -1 }, bottom: { x: 0, y: 1 } };
27
+ const distance = (a, b) => Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2);
28
+ /** xyflow's getEdgeCenter (straight and simple smoothstep edges). */
29
+ export function getEdgeCenter({ sourceX, sourceY, targetX, targetY }) {
30
+ const xOffset = Math.abs(targetX - sourceX) / 2;
31
+ const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
32
+ const yOffset = Math.abs(targetY - sourceY) / 2;
33
+ const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset;
34
+ return [centerX, centerY, xOffset, yOffset];
35
+ }
36
+ // xyflow's getPoints and getBend (@xyflow/system smoothstep-edge, MIT).
37
+ function getPoints({ source, sourcePosition = "bottom", target, targetPosition = "top", center, offset, stepPosition, }) {
38
+ const sourceDir = DIRECTIONS[sourcePosition];
39
+ const targetDir = DIRECTIONS[targetPosition];
40
+ const sourceGapped = { x: source.x + sourceDir.x * offset, y: source.y + sourceDir.y * offset };
41
+ const targetGapped = { x: target.x + targetDir.x * offset, y: target.y + targetDir.y * offset };
42
+ const dir = sourcePosition === "left" || sourcePosition === "right"
43
+ ? sourceGapped.x < targetGapped.x
44
+ ? { x: 1, y: 0 }
45
+ : { x: -1, y: 0 }
46
+ : sourceGapped.y < targetGapped.y
47
+ ? { x: 0, y: 1 }
48
+ : { x: 0, y: -1 };
49
+ const axis = dir.x !== 0 ? "x" : "y";
50
+ const currDir = dir[axis];
51
+ let points;
52
+ let centerX;
53
+ let centerY;
54
+ const sourceGapOffset = { x: 0, y: 0 };
55
+ const targetGapOffset = { x: 0, y: 0 };
56
+ const [, , defaultOffsetX, defaultOffsetY] = getEdgeCenter({ sourceX: source.x, sourceY: source.y, targetX: target.x, targetY: target.y });
57
+ if (sourceDir[axis] * targetDir[axis] === -1) {
58
+ if (axis === "x") {
59
+ centerX = center.x ?? sourceGapped.x + (targetGapped.x - sourceGapped.x) * stepPosition;
60
+ centerY = center.y ?? (sourceGapped.y + targetGapped.y) / 2;
61
+ }
62
+ else {
63
+ centerX = center.x ?? (sourceGapped.x + targetGapped.x) / 2;
64
+ centerY = center.y ?? sourceGapped.y + (targetGapped.y - sourceGapped.y) * stepPosition;
65
+ }
66
+ const verticalSplit = [
67
+ { x: centerX, y: sourceGapped.y },
68
+ { x: centerX, y: targetGapped.y },
69
+ ];
70
+ const horizontalSplit = [
71
+ { x: sourceGapped.x, y: centerY },
72
+ { x: targetGapped.x, y: centerY },
73
+ ];
74
+ if (sourceDir[axis] === currDir)
75
+ points = axis === "x" ? verticalSplit : horizontalSplit;
76
+ else
77
+ points = axis === "x" ? horizontalSplit : verticalSplit;
78
+ }
79
+ else {
80
+ const sourceTarget = [{ x: sourceGapped.x, y: targetGapped.y }];
81
+ const targetSource = [{ x: targetGapped.x, y: sourceGapped.y }];
82
+ if (axis === "x")
83
+ points = sourceDir.x === currDir ? targetSource : sourceTarget;
84
+ else
85
+ points = sourceDir.y === currDir ? sourceTarget : targetSource;
86
+ if (sourcePosition === targetPosition) {
87
+ const diff = Math.abs(source[axis] - target[axis]);
88
+ if (diff <= offset) {
89
+ const gapOffset = Math.min(offset - 1, offset - diff);
90
+ if (sourceDir[axis] === currDir)
91
+ sourceGapOffset[axis] = (sourceGapped[axis] > source[axis] ? -1 : 1) * gapOffset;
92
+ else
93
+ targetGapOffset[axis] = (targetGapped[axis] > target[axis] ? -1 : 1) * gapOffset;
94
+ }
95
+ }
96
+ if (sourcePosition !== targetPosition) {
97
+ const opposite = axis === "x" ? "y" : "x";
98
+ const isSameDir = sourceDir[axis] === targetDir[opposite];
99
+ const sourceGtTargetOppo = sourceGapped[opposite] > targetGapped[opposite];
100
+ const sourceLtTargetOppo = sourceGapped[opposite] < targetGapped[opposite];
101
+ const flip = (sourceDir[axis] === 1 && ((!isSameDir && sourceGtTargetOppo) || (isSameDir && sourceLtTargetOppo))) ||
102
+ (sourceDir[axis] !== 1 && ((!isSameDir && sourceLtTargetOppo) || (isSameDir && sourceGtTargetOppo)));
103
+ if (flip)
104
+ points = axis === "x" ? sourceTarget : targetSource;
105
+ }
106
+ const sourceGapPoint = { x: sourceGapped.x + sourceGapOffset.x, y: sourceGapped.y + sourceGapOffset.y };
107
+ const targetGapPoint = { x: targetGapped.x + targetGapOffset.x, y: targetGapped.y + targetGapOffset.y };
108
+ const maxXDistance = Math.max(Math.abs(sourceGapPoint.x - points[0].x), Math.abs(targetGapPoint.x - points[0].x));
109
+ const maxYDistance = Math.max(Math.abs(sourceGapPoint.y - points[0].y), Math.abs(targetGapPoint.y - points[0].y));
110
+ if (maxXDistance >= maxYDistance) {
111
+ centerX = (sourceGapPoint.x + targetGapPoint.x) / 2;
112
+ centerY = points[0].y;
113
+ }
114
+ else {
115
+ centerX = points[0].x;
116
+ centerY = (sourceGapPoint.y + targetGapPoint.y) / 2;
117
+ }
118
+ }
119
+ const gappedSource = { x: sourceGapped.x + sourceGapOffset.x, y: sourceGapped.y + sourceGapOffset.y };
120
+ const gappedTarget = { x: targetGapped.x + targetGapOffset.x, y: targetGapped.y + targetGapOffset.y };
121
+ const last = points[points.length - 1];
122
+ const pathPoints = [
123
+ source,
124
+ ...(gappedSource.x !== points[0].x || gappedSource.y !== points[0].y ? [gappedSource] : []),
125
+ ...points,
126
+ ...(gappedTarget.x !== last.x || gappedTarget.y !== last.y ? [gappedTarget] : []),
127
+ target,
128
+ ];
129
+ return [pathPoints, centerX, centerY, defaultOffsetX, defaultOffsetY];
130
+ }
131
+ function getBend(a, b, c, size) {
132
+ const bendSize = Math.min(distance(a, b) / 2, distance(b, c) / 2, size);
133
+ const { x, y } = b;
134
+ if ((a.x === x && x === c.x) || (a.y === y && y === c.y))
135
+ return `L${x} ${y}`;
136
+ if (a.y === y) {
137
+ const xDir = a.x < c.x ? -1 : 1;
138
+ const yDir = a.y < c.y ? 1 : -1;
139
+ return `L ${x + bendSize * xDir},${y}Q ${x},${y} ${x},${y + bendSize * yDir}`;
140
+ }
141
+ const xDir = a.x < c.x ? 1 : -1;
142
+ const yDir = a.y < c.y ? -1 : 1;
143
+ return `L ${x},${y + bendSize * yDir}Q ${x},${y} ${x + bendSize * xDir},${y}`;
144
+ }
145
+ /** xyflow's getSmoothStepPath: right-angled with rounded bends. */
146
+ export function getSmoothStepPath({ sourceX, sourceY, sourcePosition = "bottom", targetX, targetY, targetPosition = "top", borderRadius = 5, centerX, centerY, offset = 20, stepPosition = 0.5, }) {
147
+ const [points, labelX, labelY, offsetX, offsetY] = getPoints({
148
+ source: { x: sourceX, y: sourceY },
149
+ sourcePosition,
150
+ target: { x: targetX, y: targetY },
151
+ targetPosition,
152
+ center: { x: centerX, y: centerY },
153
+ offset,
154
+ stepPosition,
155
+ });
156
+ let path = `M${points[0].x} ${points[0].y}`;
157
+ for (let i = 1; i < points.length - 1; i++)
158
+ path += getBend(points[i - 1], points[i], points[i + 1], borderRadius);
159
+ path += `L${points[points.length - 1].x} ${points[points.length - 1].y}`;
160
+ return [path, labelX, labelY, offsetX, offsetY];
161
+ }
162
+ const simpleControl = (pos, x1, y1, x2, y2) => pos === "left" || pos === "right" ? [0.5 * (x1 + x2), y1] : [x1, 0.5 * (y1 + y2)];
163
+ /** xyflow's getSimpleBezierPath. */
164
+ export function getSimpleBezierPath({ sourceX, sourceY, sourcePosition = "bottom", targetX, targetY, targetPosition = "top" }) {
165
+ const [scx, scy] = simpleControl(sourcePosition, sourceX, sourceY, targetX, targetY);
166
+ const [tcx, tcy] = simpleControl(targetPosition, targetX, targetY, sourceX, sourceY);
167
+ const labelX = sourceX * 0.125 + scx * 0.375 + tcx * 0.375 + targetX * 0.125;
168
+ const labelY = sourceY * 0.125 + scy * 0.375 + tcy * 0.375 + targetY * 0.125;
169
+ return [
170
+ `M${sourceX},${sourceY} C${scx},${scy} ${tcx},${tcy} ${targetX},${targetY}`,
171
+ labelX,
172
+ labelY,
173
+ Math.abs(labelX - sourceX),
174
+ Math.abs(labelY - sourceY),
175
+ ];
176
+ }
177
+ const edgeId = ({ source, sourceHandle, target, targetHandle }) => `xy-edge__${source}${sourceHandle || ""}-${target}${targetHandle || ""}`;
178
+ /** Adds an edge unless one with the same ends exists (xyflow's addEdge). */
179
+ export function addEdge(params, edges) {
180
+ if (!params.source || !params.target)
181
+ return edges;
182
+ const edge = ("id" in params && params.id ? params : { ...params, id: edgeId(params) });
183
+ const exists = edges.some((e) => e.source === edge.source &&
184
+ e.target === edge.target &&
185
+ (e.sourceHandle === edge.sourceHandle || (!e.sourceHandle && !edge.sourceHandle)) &&
186
+ (e.targetHandle === edge.targetHandle || (!e.targetHandle && !edge.targetHandle)));
187
+ return exists ? edges : [...edges, edge];
188
+ }
189
+ /** xyflow's applyChanges: remove and replace reset an item's list; adds go last. */
190
+ function applyChanges(changes, items, update) {
191
+ const updates = new Map();
192
+ const adds = [];
193
+ for (const change of changes) {
194
+ if (change.type === "add") {
195
+ adds.push({ item: change.item, index: change.index });
196
+ }
197
+ else if (change.type === "remove" || change.type === "replace") {
198
+ updates.set(change.id, [change]);
199
+ }
200
+ else {
201
+ const list = updates.get(change.id);
202
+ if (list)
203
+ list.push(change);
204
+ else
205
+ updates.set(change.id, [change]);
206
+ }
207
+ }
208
+ const out = [];
209
+ for (const item of items) {
210
+ const list = updates.get(item.id);
211
+ if (!list) {
212
+ out.push(item);
213
+ continue;
214
+ }
215
+ if (list[0].type === "remove")
216
+ continue;
217
+ if (list[0].type === "replace") {
218
+ out.push({ ...list[0].item });
219
+ continue;
220
+ }
221
+ let next = { ...item };
222
+ for (const change of list)
223
+ next = update(next, change);
224
+ out.push(next);
225
+ }
226
+ for (const { item, index } of adds) {
227
+ if (index === undefined)
228
+ out.push({ ...item });
229
+ else
230
+ out.splice(index, 0, { ...item });
231
+ }
232
+ return out;
233
+ }
234
+ export function applyNodeChanges(changes, nodes) {
235
+ return applyChanges(changes, nodes, (node, change) => {
236
+ const n = node;
237
+ switch (change.type) {
238
+ case "select":
239
+ n.selected = change.selected;
240
+ break;
241
+ case "position":
242
+ if (change.position)
243
+ n.position = change.position;
244
+ if (change.dragging !== undefined)
245
+ n.dragging = change.dragging;
246
+ break;
247
+ case "dimensions":
248
+ if (change.dimensions) {
249
+ n.measured = { ...n.measured, ...change.dimensions };
250
+ if (change.setAttributes) {
251
+ if (change.setAttributes === true || change.setAttributes === "width")
252
+ n.width = change.dimensions.width;
253
+ if (change.setAttributes === true || change.setAttributes === "height")
254
+ n.height = change.dimensions.height;
255
+ }
256
+ }
257
+ if (typeof change.resizing === "boolean")
258
+ n.resizing = change.resizing;
259
+ break;
260
+ }
261
+ return node;
262
+ });
263
+ }
264
+ export function applyEdgeChanges(changes, edges) {
265
+ return applyChanges(changes, edges, (edge, change) => {
266
+ if (change.type === "select")
267
+ edge.selected = change.selected;
268
+ return edge;
269
+ });
270
+ }
271
+ /** Where an edge leaves or meets a handle box, on its side (xyflow's getHandlePosition). */
272
+ export function handlePoint(box, origin) {
273
+ const x = origin.x + box.x;
274
+ const y = origin.y + box.y;
275
+ switch (box.position) {
276
+ case "left":
277
+ return { x, y: y + box.height / 2 };
278
+ case "right":
279
+ return { x: x + box.width, y: y + box.height / 2 };
280
+ case "top":
281
+ return { x: x + box.width / 2, y };
282
+ default:
283
+ return { x: x + box.width / 2, y: y + box.height };
284
+ }
285
+ }
@@ -0,0 +1,14 @@
1
+ import type { EngineState } from "../state/store.js";
2
+ import type { Avis } from "../sdk/create-avis.js";
3
+ export declare function useAvis(): Avis;
4
+ export declare function useEngineSelector<T>(selector: (state: EngineState) => T, equals?: (a: T, b: T) => boolean): T;
5
+ export declare const useSelection: () => readonly import("../index.js").NodeId[];
6
+ export declare const useViewport: () => import("../index.js").Camera;
7
+ export declare const useNode: (id: string | null) => import("../index.js").NodeRecord<Record<string, unknown>> | null;
8
+ export declare function useHistory(): {
9
+ canUndo: boolean;
10
+ canRedo: boolean;
11
+ undo: () => boolean;
12
+ redo: () => boolean;
13
+ };
14
+ export declare const useThemeMode: () => "light" | "dark";
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Hooks over the engine store, with useSyncExternalStore: a component
3
+ * re-renders only when its slice changes (by `equals`).
4
+ */
5
+ import { useCallback, useContext, useRef, useSyncExternalStore } from "react";
6
+ import { AvisContext } from "./context.js";
7
+ export function useAvis() {
8
+ const avis = useContext(AvisContext);
9
+ if (!avis)
10
+ throw new Error("useAvis needs an <AvisCanvas> above it");
11
+ return avis;
12
+ }
13
+ export function useEngineSelector(selector, equals = Object.is) {
14
+ const { engine } = useAvis();
15
+ const cache = useRef(null);
16
+ const subscribe = useCallback((onChange) => {
17
+ const subscription = engine.store.subscribe((state) => state, onChange);
18
+ return () => subscription.dispose();
19
+ }, [engine]);
20
+ const getSnapshot = () => {
21
+ const next = selector(engine.store.get());
22
+ if (cache.current && equals(cache.current.value, next))
23
+ return cache.current.value;
24
+ cache.current = { value: next };
25
+ return next;
26
+ };
27
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
28
+ }
29
+ const sameList = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
30
+ export const useSelection = () => useEngineSelector((state) => state.interaction.selectedIds, sameList);
31
+ export const useViewport = () => useEngineSelector((state) => state.viewport.camera);
32
+ export const useNode = (id) => useEngineSelector((state) => (id ? (state.document.nodes[id] ?? null) : null));
33
+ export function useHistory() {
34
+ const avis = useAvis();
35
+ // The document changes with every undoable step.
36
+ useEngineSelector((state) => state.document);
37
+ return {
38
+ canUndo: avis.history.canUndo,
39
+ canRedo: avis.history.canRedo,
40
+ undo: () => avis.history.undo(),
41
+ redo: () => avis.history.redo(),
42
+ };
43
+ }
44
+ export const useThemeMode = () => useEngineSelector((state) => state.style.theme);
@@ -0,0 +1,3 @@
1
+ export * from "./context.js";
2
+ export * from "./hooks.js";
3
+ export * from "./components.js";
@@ -0,0 +1,5 @@
1
+ // AVIS Engine · react — Phase 6: the React adapter (`@avis/engine/react`).
2
+ // The only place React is allowed in the engine (ESLint).
3
+ export * from "./context.js";
4
+ export * from "./hooks.js";
5
+ export * from "./components.js";
@@ -0,0 +1,26 @@
1
+ import type { Camera } from "../geometry/spaces.js";
2
+ import type { Mat2D } from "../geometry/matrix.js";
3
+ import type { Rgba } from "./color.js";
4
+ import type { RenderCommand } from "./commands.js";
5
+ import type { ImageStore } from "./images.js";
6
+ export type Frame = {
7
+ camera: Camera;
8
+ /** CSS px. */
9
+ width: number;
10
+ height: number;
11
+ dpr: number;
12
+ background: Rgba;
13
+ commands: readonly RenderCommand[];
14
+ images: ImageStore;
15
+ };
16
+ export type BackendStats = {
17
+ drawCalls: number;
18
+ [key: string]: number;
19
+ };
20
+ export interface RenderBackend {
21
+ readonly kind: "webgl2" | "canvas2d" | "webgpu";
22
+ render(frame: Frame): BackendStats;
23
+ dispose(): void;
24
+ }
25
+ /** A command's matrix with the camera and pixel ratio applied: local → device px. */
26
+ export declare function toDevice(m: Mat2D, camera: Camera, dpr: number): [number, number, number, number, number, number];
@@ -0,0 +1,5 @@
1
+ /** A command's matrix with the camera and pixel ratio applied: local → device px. */
2
+ export function toDevice(m, camera, dpr) {
3
+ const z = camera.zoom * dpr;
4
+ return [m[0] * z, m[1] * z, m[2] * z, m[3] * z, m[4] * z + camera.x * dpr, m[5] * z + camera.y * dpr];
5
+ }
@@ -0,0 +1,7 @@
1
+ import { type RenderBackend } from "../backend.js";
2
+ export type Canvas2DTarget = {
3
+ width: number;
4
+ height: number;
5
+ getContext(kind: "2d"): unknown;
6
+ };
7
+ export declare function createCanvas2DBackend(canvas: Canvas2DTarget): RenderBackend;
@@ -0,0 +1,122 @@
1
+ /*
2
+ * The Canvas2D backend: the fallback where WebGL2 is missing, and the
3
+ * reference the WebGL2 output is compared with.
4
+ */
5
+ import { toDevice } from "../backend.js";
6
+ import { toCss } from "../color.js";
7
+ import { fontString } from "../commands.js";
8
+ import { fitImage } from "../images.js";
9
+ function roundedRect(ctx, x, y, w, h, r) {
10
+ const radius = Math.max(0, Math.min(r, w / 2, h / 2));
11
+ ctx.beginPath();
12
+ ctx.moveTo(x + radius, y);
13
+ ctx.lineTo(x + w - radius, y);
14
+ ctx.arcTo(x + w, y, x + w, y + radius, radius);
15
+ ctx.lineTo(x + w, y + h - radius);
16
+ ctx.arcTo(x + w, y + h, x + w - radius, y + h, radius);
17
+ ctx.lineTo(x + radius, y + h);
18
+ ctx.arcTo(x, y + h, x, y + h - radius, radius);
19
+ ctx.lineTo(x, y + radius);
20
+ ctx.arcTo(x, y, x + radius, y, radius);
21
+ ctx.closePath();
22
+ }
23
+ export function createCanvas2DBackend(canvas) {
24
+ const ctx = canvas.getContext("2d");
25
+ if (!ctx)
26
+ throw new Error("No 2D context");
27
+ return {
28
+ kind: "canvas2d",
29
+ render(frame) {
30
+ const width = Math.round(frame.width * frame.dpr);
31
+ const height = Math.round(frame.height * frame.dpr);
32
+ if (canvas.width !== width)
33
+ canvas.width = width;
34
+ if (canvas.height !== height)
35
+ canvas.height = height;
36
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
37
+ ctx.globalAlpha = 1;
38
+ ctx.fillStyle = toCss(frame.background);
39
+ ctx.fillRect(0, 0, width, height);
40
+ let drawCalls = 0;
41
+ for (const command of frame.commands) {
42
+ if (command.kind === "mesh") {
43
+ const z = frame.camera.zoom * frame.dpr;
44
+ ctx.setTransform(z, 0, 0, z, frame.camera.x * frame.dpr, frame.camera.y * frame.dpr);
45
+ ctx.fillStyle = toCss(command.color);
46
+ ctx.beginPath();
47
+ const v = command.vertices;
48
+ for (let i = 0; i + 5 < v.length; i += 6) {
49
+ ctx.moveTo(v[i], v[i + 1]);
50
+ ctx.lineTo(v[i + 2], v[i + 3]);
51
+ ctx.lineTo(v[i + 4], v[i + 5]);
52
+ ctx.closePath();
53
+ }
54
+ ctx.fill();
55
+ drawCalls++;
56
+ continue;
57
+ }
58
+ ctx.setTransform(...toDevice(command.matrix, frame.camera, frame.dpr));
59
+ if (command.kind === "rect") {
60
+ if (command.fill && command.fill[3] > 0) {
61
+ roundedRect(ctx, 0, 0, command.w, command.h, command.radius);
62
+ ctx.fillStyle = toCss(command.fill);
63
+ ctx.fill();
64
+ drawCalls++;
65
+ }
66
+ if (command.stroke && command.strokeWidth > 0 && command.stroke[3] > 0) {
67
+ // Inside the box, as the WebGL2 shader strokes.
68
+ const s = command.strokeWidth;
69
+ roundedRect(ctx, s / 2, s / 2, command.w - s, command.h - s, Math.max(0, command.radius - s / 2));
70
+ ctx.strokeStyle = toCss(command.stroke);
71
+ ctx.lineWidth = s;
72
+ ctx.stroke();
73
+ drawCalls++;
74
+ }
75
+ }
76
+ else if (command.kind === "image") {
77
+ const image = frame.images.get(command.src);
78
+ if (!image)
79
+ continue;
80
+ const f = fitImage(command.fit, command.w, command.h, image.width, image.height);
81
+ ctx.save();
82
+ roundedRect(ctx, 0, 0, command.w, command.h, command.radius);
83
+ ctx.clip();
84
+ ctx.globalAlpha = command.opacity;
85
+ ctx.drawImage(image.source, f.sx, f.sy, f.sw, f.sh, f.dx, f.dy, f.dw, f.dh);
86
+ ctx.restore();
87
+ drawCalls++;
88
+ }
89
+ else if (command.kind === "shadow") {
90
+ // The shape is drawn far off to one side; the shadow's offset
91
+ // brings only the shadow back (canvas offsets are device px).
92
+ const m = toDevice(command.matrix, frame.camera, frame.dpr);
93
+ const scale = Math.hypot(m[0], m[1]) || 1;
94
+ const far = 100000 / scale;
95
+ ctx.save();
96
+ ctx.shadowColor = toCss(command.color);
97
+ ctx.shadowBlur = command.blur * scale;
98
+ ctx.shadowOffsetX = -m[0] * far + (m[0] * command.x + m[2] * command.y);
99
+ ctx.shadowOffsetY = -m[1] * far + (m[1] * command.x + m[3] * command.y);
100
+ ctx.fillStyle = "#000";
101
+ const s = command.spread;
102
+ roundedRect(ctx, far - s, -s, command.w + 2 * s, command.h + 2 * s, Math.max(0, command.radius + s));
103
+ ctx.fill();
104
+ ctx.restore();
105
+ drawCalls++;
106
+ }
107
+ else {
108
+ ctx.font = fontString(command.font);
109
+ if ("letterSpacing" in ctx)
110
+ ctx.letterSpacing = `${command.letterSpacing ?? 0}px`;
111
+ ctx.textBaseline = "middle";
112
+ ctx.fillStyle = toCss(command.color);
113
+ ctx.fillText(command.text, command.x, command.y + command.lineHeight / 2);
114
+ drawCalls++;
115
+ }
116
+ }
117
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
118
+ return { drawCalls };
119
+ },
120
+ dispose() { },
121
+ };
122
+ }
@@ -0,0 +1 @@
1
+ export * from "./backend.js";
@@ -0,0 +1,2 @@
1
+ // AVIS Engine · render/canvas2d — the Canvas2D fallback backend.
2
+ export * from "./backend.js";
@@ -0,0 +1,9 @@
1
+ export type Rgba = readonly [number, number, number, number];
2
+ export declare const TRANSPARENT: Rgba;
3
+ /** The colour, or null when it can't be read. */
4
+ export declare function tryParseColor(input: string): Rgba | null;
5
+ /** The colour; magenta (and one report) when it can't be read. */
6
+ export declare function parseColor(input: string, onUnknown?: (input: string) => void): Rgba;
7
+ export declare const withAlpha: (color: Rgba, alpha: number) => Rgba;
8
+ /** `rgba(…)` for Canvas2D. */
9
+ export declare function toCss([r, g, b, a]: Rgba): string;
@@ -0,0 +1,69 @@
1
+ export const TRANSPARENT = [0, 0, 0, 0];
2
+ const MISSING = [1, 0, 1, 1];
3
+ const NAMES = {
4
+ transparent: TRANSPARENT,
5
+ black: [0, 0, 0, 1],
6
+ white: [1, 1, 1, 1],
7
+ red: [1, 0, 0, 1],
8
+ green: [0, 128 / 255, 0, 1],
9
+ blue: [0, 0, 1, 1],
10
+ gray: [128 / 255, 128 / 255, 128 / 255, 1],
11
+ grey: [128 / 255, 128 / 255, 128 / 255, 1],
12
+ };
13
+ const cache = new Map();
14
+ const channel = (value, scale) => {
15
+ const number = parseFloat(value);
16
+ return value.trim().endsWith("%") ? number / 100 : number / scale;
17
+ };
18
+ function hslToRgb(h, s, l) {
19
+ const k = (n) => (n + h / 30) % 12;
20
+ const a = s * Math.min(l, 1 - l);
21
+ const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
22
+ return [f(0), f(8), f(4)];
23
+ }
24
+ /** The colour, or null when it can't be read. */
25
+ export function tryParseColor(input) {
26
+ const text = input.trim().toLowerCase();
27
+ if (cache.has(text))
28
+ return cache.get(text);
29
+ let out = NAMES[text] ?? null;
30
+ if (!out && text.startsWith("#")) {
31
+ const hex = text.slice(1);
32
+ const full = hex.length === 3 || hex.length === 4 ? [...hex].map((c) => c + c).join("") : hex;
33
+ if (/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(full)) {
34
+ const n = (i) => parseInt(full.slice(i, i + 2), 16) / 255;
35
+ out = [n(0), n(2), n(4), full.length === 8 ? n(6) : 1];
36
+ }
37
+ }
38
+ const fn = /^(rgba?|hsla?)\(([^)]*)\)$/.exec(text);
39
+ if (!out && fn) {
40
+ const parts = fn[2].split(/[\s,/]+/).filter(Boolean);
41
+ if (parts.length >= 3) {
42
+ const alpha = parts[3] === undefined ? 1 : channel(parts[3], 1);
43
+ if (fn[1].startsWith("rgb")) {
44
+ out = [channel(parts[0], 255), channel(parts[1], 255), channel(parts[2], 255), alpha];
45
+ }
46
+ else {
47
+ const [r, g, b] = hslToRgb(parseFloat(parts[0]), channel(parts[1], 100), channel(parts[2], 100));
48
+ out = [r, g, b, alpha];
49
+ }
50
+ if (out.some((value) => Number.isNaN(value)))
51
+ out = null;
52
+ }
53
+ }
54
+ cache.set(text, out);
55
+ return out;
56
+ }
57
+ /** The colour; magenta (and one report) when it can't be read. */
58
+ export function parseColor(input, onUnknown) {
59
+ const out = tryParseColor(input);
60
+ if (out)
61
+ return out;
62
+ onUnknown?.(input);
63
+ return MISSING;
64
+ }
65
+ export const withAlpha = (color, alpha) => [color[0], color[1], color[2], color[3] * alpha];
66
+ /** `rgba(…)` for Canvas2D. */
67
+ export function toCss([r, g, b, a]) {
68
+ return `rgba(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)}, ${a})`;
69
+ }