@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,174 @@
1
+ export type PaintRect = {
2
+ x: number;
3
+ y: number;
4
+ w: number;
5
+ h: number;
6
+ };
7
+ /** Corner radii: top-left, top-right, bottom-right, bottom-left. */
8
+ export type Radii = [number, number, number, number];
9
+ export type PaintClip = PaintRect & {
10
+ radii: Radii;
11
+ };
12
+ export type ColorStop = {
13
+ color: string;
14
+ at: number;
15
+ };
16
+ /** A CSS gradient, resolved against its box. */
17
+ export type Gradient = ({
18
+ kind: "linear";
19
+ angle: number;
20
+ stops: ColorStop[];
21
+ repeating?: boolean;
22
+ } | {
23
+ kind: "radial";
24
+ cx: number;
25
+ cy: number;
26
+ rx: number;
27
+ ry: number;
28
+ stops: ColorStop[];
29
+ } | {
30
+ kind: "conic";
31
+ cx: number;
32
+ cy: number;
33
+ from: number;
34
+ stops: ColorStop[];
35
+ }) & {
36
+ /** Its own size, repeated from the box's corner (`background-size`). */
37
+ tile?: {
38
+ w: number;
39
+ h: number;
40
+ };
41
+ };
42
+ /** One layer of a `mask-image` and how it combines with those under it. */
43
+ export type MaskLayer = {
44
+ gradient: Gradient;
45
+ composite: "add" | "subtract" | "intersect" | "exclude";
46
+ };
47
+ export type Shadow = {
48
+ inset: boolean;
49
+ x: number;
50
+ y: number;
51
+ blur: number;
52
+ spread: number;
53
+ color: string;
54
+ };
55
+ /** One side's border: top, right, bottom, left. */
56
+ export type BorderSide = {
57
+ width: number;
58
+ color: string;
59
+ style: string;
60
+ };
61
+ type Common = {
62
+ alpha: number;
63
+ /** One clip around the op (a rounded rect). */
64
+ clip?: PaintClip;
65
+ /**
66
+ * Every clip that cuts the op, outermost first: the nested `overflow`
67
+ * boxes around it (their padding boxes and inner radii). Applied after `clip`.
68
+ */
69
+ clips?: PaintClip[];
70
+ };
71
+ export type PaintOp = (Common & {
72
+ kind: "box";
73
+ rect: PaintRect;
74
+ radii: Radii;
75
+ fill?: string;
76
+ gradients?: Gradient[];
77
+ /** Uniform border (all sides alike), drawn inside the box as CSS does. */
78
+ stroke?: string;
79
+ strokeWidth?: number;
80
+ dash?: number[];
81
+ /** Borders that differ per side. */
82
+ sides?: [BorderSide, BorderSide, BorderSide, BorderSide];
83
+ shadows?: Shadow[];
84
+ outline?: {
85
+ width: number;
86
+ color: string;
87
+ offset: number;
88
+ style: string;
89
+ };
90
+ /** A mask cuts this out: the box paints only around it (a border ring). */
91
+ hole?: PaintClip;
92
+ /** A gradient mask over the box: it paints where the mask is opaque. */
93
+ mask?: Gradient;
94
+ /** Blurs what is under it, in px (`backdrop-filter: blur`). */
95
+ backdropBlur?: number;
96
+ }) | (Common & {
97
+ kind: "image";
98
+ rect: PaintRect;
99
+ radii: Radii;
100
+ source: CanvasImageSource;
101
+ sourceWidth: number;
102
+ sourceHeight: number;
103
+ fit: string;
104
+ /** Rotation about the rect's centre, in radians (a turned chevron). */
105
+ rotate?: number;
106
+ }) | (Common & {
107
+ kind: "text";
108
+ /** The line's box (its glyphs' content area). */
109
+ rect: PaintRect;
110
+ text: string;
111
+ font: string;
112
+ color: string;
113
+ /** Distance from the rect's top to the baseline. */
114
+ baseline: number;
115
+ letterSpacing?: string;
116
+ /** A text decoration line, in rect units. */
117
+ underline?: {
118
+ y: number;
119
+ thickness: number;
120
+ color: string;
121
+ };
122
+ }) | (Common & {
123
+ /**
124
+ * An element with a mask (a scroll area's faded edges): it and all it
125
+ * holds, drawn together and kept where the mask is opaque.
126
+ */
127
+ kind: "group";
128
+ rect: PaintRect;
129
+ ops: PaintOp[];
130
+ masks: MaskLayer[];
131
+ }) | (Common & {
132
+ kind: "caret";
133
+ rect: PaintRect;
134
+ color: string;
135
+ }) | (Common & {
136
+ kind: "highlight";
137
+ rect: PaintRect;
138
+ color: string;
139
+ });
140
+ export type NodePaint = {
141
+ ops: PaintOp[];
142
+ /** Everything the ops cover, relative to the root. */
143
+ bounds: PaintRect;
144
+ /** An image or video still loading: paint again once it has. */
145
+ pending: boolean;
146
+ };
147
+ export type CollectOptions = {
148
+ /** The zoom the DOM is laid out at (screen rects are divided by it). */
149
+ zoom?: number;
150
+ /** Leave these out (and what they hold). */
151
+ skip?: string;
152
+ /**
153
+ * Snap boxes, images and text lines to whole layout pixels, as the browser
154
+ * paints them (default). `false`: the exact, fractional layout.
155
+ */
156
+ snap?: boolean;
157
+ /** Read only these elements of the root (and what they hold), not all of it. */
158
+ only?: Iterable<Element>;
159
+ /** Paint what `visibility: hidden` hides too (DOM kept only to be read). */
160
+ ignoreVisibility?: boolean;
161
+ /**
162
+ * An image from elsewhere (an app cache) while the DOM's own one loads.
163
+ * With it (and `videoFrame`), a file not there yet doesn't leave the paint
164
+ * `pending`: the app knows which it asked for, and reads again.
165
+ */
166
+ image?: (url: string) => HTMLImageElement | null;
167
+ /** A video's first frame from elsewhere (an app cache) while it loads. */
168
+ videoFrame?: (url: string) => CanvasImageSource | null;
169
+ /** Paint the caret, the selection and an IME composition (a ghost node being edited). */
170
+ editing?: boolean;
171
+ /** Whether the caret shows now (it blinks). */
172
+ caretOn?: boolean;
173
+ };
174
+ export {};
@@ -0,0 +1,7 @@
1
+ /*
2
+ * The DOM painter's display list (docs/avis-engine/DOM-BRIDGE.md): what a
3
+ * piece of DOM looks like, read from the browser's computed styles and
4
+ * layout, in units relative to a root element (CSS px at zoom 1). Drawing it
5
+ * needs no DOM, so a node can be painted, cached and rasterised freely.
6
+ */
7
+ export {};
@@ -0,0 +1,10 @@
1
+ export type DomWatcher = {
2
+ /** Whether the caret shows now (it blinks; it stays on while typing). */
3
+ caretOn(): boolean;
4
+ /** Asks for a repaint (after something the watcher can't see). */
5
+ invalidate(): void;
6
+ dispose(): void;
7
+ };
8
+ /** Repaints when the browser finishes resolving a web font. */
9
+ export declare function watchFontSet(fonts: EventTarget | null | undefined, onChange: () => void): () => void;
10
+ export declare function watchDom(root: HTMLElement, onChange: () => void): DomWatcher;
@@ -0,0 +1,109 @@
1
+ /*
2
+ * Watches a piece of DOM that the canvas paints (a ghost node, DOM-BRIDGE.md)
3
+ * and asks for a repaint, at most once a frame, whenever what it shows may
4
+ * have changed: attributes (a library's data-* and aria-* states), text and
5
+ * children, field input and selection, focus, hover, scrolling, CSS
6
+ * transitions and animations (repainted every frame while they run), an IME
7
+ * composition, and the caret's blink.
8
+ */
9
+ import { setComposition } from "./collect.js";
10
+ const BLINK = 530;
11
+ /** Repaints when the browser finishes resolving a web font. */
12
+ export function watchFontSet(fonts, onChange) {
13
+ if (!fonts)
14
+ return () => { };
15
+ const changed = () => onChange();
16
+ fonts.addEventListener("loadingdone", changed);
17
+ fonts.addEventListener("loadingerror", changed);
18
+ return () => {
19
+ fonts.removeEventListener("loadingdone", changed);
20
+ fonts.removeEventListener("loadingerror", changed);
21
+ };
22
+ }
23
+ export function watchDom(root, onChange) {
24
+ let frame = 0;
25
+ let disposed = false;
26
+ let activity = performance.now();
27
+ let blinkTimer = 0;
28
+ const focusedInside = () => {
29
+ const active = document.activeElement;
30
+ return !!active && root.contains(active);
31
+ };
32
+ const schedule = () => {
33
+ if (disposed || frame)
34
+ return;
35
+ frame = requestAnimationFrame(() => {
36
+ frame = 0;
37
+ if (disposed)
38
+ return;
39
+ onChange();
40
+ // Running transitions and animations: a frame each until they end.
41
+ if (root.getAnimations({ subtree: true }).some((a) => a.playState === "running"))
42
+ schedule();
43
+ });
44
+ };
45
+ const blink = () => {
46
+ clearTimeout(blinkTimer);
47
+ if (disposed || !focusedInside())
48
+ return;
49
+ blinkTimer = window.setTimeout(() => {
50
+ schedule();
51
+ blink();
52
+ }, BLINK);
53
+ };
54
+ const touched = () => {
55
+ activity = performance.now();
56
+ schedule();
57
+ blink();
58
+ };
59
+ const observer = new MutationObserver(touched);
60
+ observer.observe(root, { subtree: true, childList: true, characterData: true, attributes: true });
61
+ const onComposition = (event) => {
62
+ const field = event.target;
63
+ if (field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement) {
64
+ if (event.type === "compositionend")
65
+ setComposition(field, null);
66
+ else {
67
+ const end = field.selectionEnd ?? field.value.length;
68
+ setComposition(field, { start: Math.max(0, end - (event.data?.length ?? 0)), end });
69
+ }
70
+ }
71
+ touched();
72
+ };
73
+ const events = ["input", "change", "focusin", "focusout", "pointerover", "pointerout", "pointerdown", "pointerup", "keyup", "transitionrun", "transitionend", "animationstart", "animationend", "load", "error"];
74
+ for (const type of events)
75
+ root.addEventListener(type, touched, true);
76
+ root.addEventListener("scroll", touched, true);
77
+ for (const type of ["compositionstart", "compositionupdate", "compositionend"])
78
+ root.addEventListener(type, onComposition, true);
79
+ const onSelection = () => {
80
+ if (focusedInside() || root.contains(document.getSelection()?.anchorNode ?? null))
81
+ touched();
82
+ };
83
+ document.addEventListener("selectionchange", onSelection);
84
+ const resize = new ResizeObserver(touched);
85
+ resize.observe(root);
86
+ const unwatchFonts = watchFontSet(document.fonts, touched);
87
+ schedule();
88
+ return {
89
+ caretOn() {
90
+ const idle = performance.now() - activity;
91
+ return idle < BLINK || Math.floor(idle / BLINK) % 2 === 0;
92
+ },
93
+ invalidate: schedule,
94
+ dispose() {
95
+ disposed = true;
96
+ cancelAnimationFrame(frame);
97
+ clearTimeout(blinkTimer);
98
+ observer.disconnect();
99
+ resize.disconnect();
100
+ unwatchFonts();
101
+ for (const type of events)
102
+ root.removeEventListener(type, touched, true);
103
+ root.removeEventListener("scroll", touched, true);
104
+ for (const type of ["compositionstart", "compositionupdate", "compositionend"])
105
+ root.removeEventListener(type, onComposition, true);
106
+ document.removeEventListener("selectionchange", onSelection);
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,37 @@
1
+ export type Side = "top" | "right" | "bottom" | "left";
2
+ export type Placement = Side | `${Side}-start` | `${Side}-end`;
3
+ export type Rect = {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export type PositionOptions = {
10
+ placement?: Placement;
11
+ /** Distance from the anchor (main) and along it (cross), px. */
12
+ offset?: number | {
13
+ mainAxis?: number;
14
+ crossAxis?: number;
15
+ };
16
+ /** Try the opposite side when this one overflows the boundary. */
17
+ flip?: boolean | {
18
+ padding?: number;
19
+ };
20
+ /** Slide along the anchor to stay inside the boundary. */
21
+ shift?: boolean | {
22
+ padding?: number;
23
+ };
24
+ /** The clipping area (the viewport or the canvas), in the same space. */
25
+ boundary: Rect;
26
+ };
27
+ export type PositionResult = {
28
+ x: number;
29
+ y: number;
30
+ placement: Placement;
31
+ /** The anchor is entirely outside the boundary (hide the floating element). */
32
+ referenceHidden: boolean;
33
+ };
34
+ export declare function computePosition(reference: Rect, floating: {
35
+ width: number;
36
+ height: number;
37
+ }, options: PositionOptions): PositionResult;
@@ -0,0 +1,125 @@
1
+ const OPPOSITE = { top: "bottom", bottom: "top", left: "right", right: "left" };
2
+ const sideOf = (p) => p.split("-")[0];
3
+ const alignmentOf = (p) => p.split("-")[1];
4
+ const isVertical = (side) => side === "top" || side === "bottom";
5
+ const opposite = (p) => p.replace(/^(top|bottom|left|right)/, (side) => OPPOSITE[side]);
6
+ function coordsFor(reference, floating, placement) {
7
+ const side = sideOf(placement);
8
+ const alignment = alignmentOf(placement);
9
+ const cx = reference.x + reference.width / 2 - floating.width / 2;
10
+ const cy = reference.y + reference.height / 2 - floating.height / 2;
11
+ let x;
12
+ let y;
13
+ switch (side) {
14
+ case "top":
15
+ x = cx;
16
+ y = reference.y - floating.height;
17
+ break;
18
+ case "bottom":
19
+ x = cx;
20
+ y = reference.y + reference.height;
21
+ break;
22
+ case "right":
23
+ x = reference.x + reference.width;
24
+ y = cy;
25
+ break;
26
+ default:
27
+ x = reference.x - floating.width;
28
+ y = cy;
29
+ }
30
+ const commonX = reference.width / 2 - floating.width / 2;
31
+ const commonY = reference.height / 2 - floating.height / 2;
32
+ if (alignment) {
33
+ if (isVertical(side))
34
+ x += alignment === "start" ? -commonX : commonX;
35
+ else
36
+ y += alignment === "start" ? -commonY : commonY;
37
+ }
38
+ return { x, y };
39
+ }
40
+ function overflowOf(rect, boundary, padding = 0) {
41
+ return {
42
+ top: boundary.y - rect.y + padding,
43
+ bottom: rect.y + rect.height - (boundary.y + boundary.height) + padding,
44
+ left: boundary.x - rect.x + padding,
45
+ right: rect.x + rect.width - (boundary.x + boundary.width) + padding,
46
+ };
47
+ }
48
+ const padOf = (option) => typeof option === "object" ? (option.padding ?? 0) : 0;
49
+ /** Floating UI's getAlignmentSides (left to right). */
50
+ function alignmentSides(placement, reference, floating) {
51
+ const alignment = alignmentOf(placement);
52
+ const axisX = isVertical(sideOf(placement));
53
+ const length = axisX ? "width" : "height";
54
+ let main = axisX ? (alignment === "start" ? "right" : "left") : alignment === "start" ? "bottom" : "top";
55
+ if (reference[length] > floating[length])
56
+ main = OPPOSITE[main];
57
+ return [main, OPPOSITE[main]];
58
+ }
59
+ export function computePosition(reference, floating, options) {
60
+ const initial = options.placement ?? "bottom";
61
+ const offset = typeof options.offset === "number" ? { mainAxis: options.offset } : (options.offset ?? {});
62
+ const place = (placement) => {
63
+ const coords = coordsFor(reference, floating, placement);
64
+ const side = sideOf(placement);
65
+ const main = (offset.mainAxis ?? 0) * (side === "top" || side === "left" ? -1 : 1);
66
+ const cross = offset.crossAxis ?? 0;
67
+ if (isVertical(side)) {
68
+ coords.x += cross;
69
+ coords.y += main;
70
+ }
71
+ else {
72
+ coords.x += main;
73
+ coords.y += cross;
74
+ }
75
+ return coords;
76
+ };
77
+ let placement = initial;
78
+ let coords = place(placement);
79
+ if (options.flip) {
80
+ const padding = padOf(options.flip);
81
+ // Floating UI's expanded placements: the other alignment, the opposite
82
+ // side, then the opposite side with the other alignment.
83
+ const otherAlignment = (p) => p.replace(/start|end/, (a) => (a === "start" ? "end" : "start"));
84
+ const candidates = alignmentOf(initial)
85
+ ? [initial, otherAlignment(initial), opposite(initial), otherAlignment(opposite(initial))]
86
+ : [initial, opposite(initial)];
87
+ const tried = [];
88
+ let found = false;
89
+ for (const candidate of candidates) {
90
+ const at = place(candidate);
91
+ const o = overflowOf({ ...at, ...floating }, options.boundary, padding);
92
+ const [a, b] = alignmentSides(candidate, reference, floating);
93
+ const overflows = [o[sideOf(candidate)], o[a], o[b]];
94
+ tried.push({ placement: candidate, overflows });
95
+ if (overflows.every((value) => value <= 0)) {
96
+ placement = candidate;
97
+ coords = at;
98
+ found = true;
99
+ break;
100
+ }
101
+ }
102
+ if (!found) {
103
+ // Floating UI: fits on the main side with the least cross overflow,
104
+ // else the least total overflow.
105
+ const fitting = tried.filter((t) => t.overflows[0] <= 0).sort((p, q) => p.overflows[1] - q.overflows[1])[0];
106
+ const best = fitting ??
107
+ tried
108
+ .map((t) => ({ ...t, total: t.overflows.filter((v) => v > 0).reduce((sum, v) => sum + v, 0) }))
109
+ .sort((p, q) => p.total - q.total)[0];
110
+ placement = best.placement;
111
+ coords = place(placement);
112
+ }
113
+ }
114
+ if (options.shift) {
115
+ const padding = padOf(options.shift);
116
+ const o = overflowOf({ ...coords, ...floating }, options.boundary, padding);
117
+ if (isVertical(sideOf(placement)))
118
+ coords.x = Math.max(coords.x + o.left, Math.min(coords.x, coords.x - o.right));
119
+ else
120
+ coords.y = Math.max(coords.y + o.top, Math.min(coords.y, coords.y - o.bottom));
121
+ }
122
+ const r = overflowOf(reference, options.boundary);
123
+ const referenceHidden = r.top - reference.height >= 0 || r.bottom - reference.height >= 0 || r.left - reference.width >= 0 || r.right - reference.width >= 0;
124
+ return { x: coords.x, y: coords.y, placement, referenceHidden };
125
+ }
@@ -0,0 +1,27 @@
1
+ import type { Disposable } from "../core/disposable.js";
2
+ import type { Engine } from "../core/engine.js";
3
+ import { EventBus } from "../core/event-bus.js";
4
+ export type TextEditorEvents = {
5
+ open: {
6
+ id: string;
7
+ };
8
+ commit: {
9
+ id: string;
10
+ text: string;
11
+ changed: boolean;
12
+ };
13
+ cancel: {
14
+ id: string;
15
+ };
16
+ };
17
+ export type TextEditor = Disposable & {
18
+ readonly events: EventBus<TextEditorEvents>;
19
+ readonly field: HTMLTextAreaElement | null;
20
+ open(id: string, prop?: string): void;
21
+ commit(): void;
22
+ cancel(): void;
23
+ };
24
+ export declare function createTextEditor(engine: Engine, options: {
25
+ root: HTMLElement;
26
+ restoreFocus?: (id: string) => void;
27
+ }): TextEditor;
@@ -0,0 +1,128 @@
1
+ import { EventBus } from "../core/event-bus.js";
2
+ import { FocusKey } from "../a11y/focus.js";
3
+ import { toCss } from "../render/color.js";
4
+ import { StyleKey } from "../style/style-engine.js";
5
+ import { cameraCss, matrixCss } from "./anchor.js";
6
+ export function createTextEditor(engine, options) {
7
+ const doc = options.root.ownerDocument;
8
+ const events = new EventBus();
9
+ const world = doc.createElement("div");
10
+ world.dataset.avisEditor = "";
11
+ world.style.cssText = "position:absolute;left:0;top:0;transform-origin:0 0;pointer-events:none";
12
+ options.root.append(world);
13
+ let editing = null;
14
+ const setEditing = (id, on) => {
15
+ engine.store.set("style", (style) => {
16
+ const states = (style.nodeStates[id] ?? []).filter((state) => state !== "editing");
17
+ return { ...style, nodeStates: { ...style.nodeStates, [id]: on ? [...states, "editing"] : states } };
18
+ });
19
+ };
20
+ const place = () => {
21
+ world.style.transform = cameraCss(engine.store.get().viewport.camera);
22
+ if (!editing)
23
+ return;
24
+ const node = engine.scene.get(editing.id);
25
+ if (!node)
26
+ return;
27
+ const size = engine.scene.sizeOf(node);
28
+ editing.field.style.transform = matrixCss(node.world);
29
+ editing.field.style.width = `${size.w}px`;
30
+ editing.field.style.height = `${size.h}px`;
31
+ };
32
+ const close = (commit) => {
33
+ const current = editing;
34
+ if (!current)
35
+ return;
36
+ editing = null;
37
+ const text = current.field.value;
38
+ const changed = commit && text !== current.original && Boolean(engine.store.get().document.nodes[current.id]);
39
+ if (changed)
40
+ engine.commands.execute("node.update", { id: current.id, props: { [current.prop]: text } });
41
+ current.field.remove();
42
+ setEditing(current.id, false);
43
+ if (commit)
44
+ events.emit("commit", { id: current.id, text, changed });
45
+ else
46
+ events.emit("cancel", { id: current.id });
47
+ options.restoreFocus?.(current.id);
48
+ };
49
+ const open = (id, prop = "text") => {
50
+ if (editing?.id === id)
51
+ return;
52
+ close(true);
53
+ const record = engine.store.get().document.nodes[id];
54
+ if (!record)
55
+ return;
56
+ const props = record.props;
57
+ const style = engine.services.has(StyleKey) ? engine.services.get(StyleKey) : null;
58
+ const colour = (typeof props.color === "string" && props.color) || "var(--color-foreground)";
59
+ const rgba = style?.tokens.color(colour, style.mode());
60
+ const fontSize = typeof props.fontSize === "number" ? props.fontSize : 14;
61
+ const lineHeight = typeof props.lineHeight === "number" ? props.lineHeight : 1.4;
62
+ const family = (typeof props.fontFamily === "string" && props.fontFamily) ||
63
+ style?.tokens.resolve("var(--font-sans)", style.mode()) ||
64
+ "Inter, system-ui, sans-serif";
65
+ const field = doc.createElement("textarea");
66
+ field.value = String(props[prop] ?? "");
67
+ field.setAttribute("aria-label", "Edit text");
68
+ field.spellcheck = true;
69
+ field.style.cssText = [
70
+ "position:absolute;left:0;top:0;transform-origin:0 0;pointer-events:auto",
71
+ "margin:0;padding:0;border:0;outline:none;resize:none;overflow:hidden;background:transparent",
72
+ "white-space:pre-wrap;overflow-wrap:break-word;box-sizing:border-box",
73
+ `font:${typeof props.fontWeight === "number" ? props.fontWeight : 400} ${fontSize}px/${fontSize * lineHeight}px ${family}`,
74
+ `color:${rgba ? toCss(rgba) : colour}`,
75
+ ].join(";");
76
+ editing = { id, prop, field, original: field.value, composing: false };
77
+ field.addEventListener("compositionstart", () => editing && (editing.composing = true));
78
+ field.addEventListener("compositionend", () => editing && (editing.composing = false));
79
+ field.addEventListener("keydown", (event) => {
80
+ // Shortcuts never see keys typed here.
81
+ event.stopPropagation();
82
+ if (event.isComposing || editing?.composing)
83
+ return;
84
+ if (event.key === "Escape") {
85
+ event.preventDefault();
86
+ close(false);
87
+ }
88
+ else if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
89
+ event.preventDefault();
90
+ close(true);
91
+ }
92
+ });
93
+ field.addEventListener("blur", () => {
94
+ if (editing?.field === field)
95
+ close(true);
96
+ });
97
+ world.append(field);
98
+ setEditing(id, true);
99
+ place();
100
+ field.focus({ preventScroll: true });
101
+ field.setSelectionRange(field.value.length, field.value.length);
102
+ events.emit("open", { id });
103
+ };
104
+ const subscription = engine.store.subscribe((state) => [state.viewport, state.document], () => {
105
+ if (editing && !engine.store.get().document.nodes[editing.id])
106
+ close(false);
107
+ else
108
+ place();
109
+ }, { equals: (a, b) => a[0] === b[0] && a[1] === b[1] });
110
+ const focus = engine.services.has(FocusKey) ? engine.services.get(FocusKey) : null;
111
+ const editSub = focus?.events.on("edit", ({ id, prop }) => open(id, prop));
112
+ return {
113
+ events,
114
+ get field() {
115
+ return editing?.field ?? null;
116
+ },
117
+ open,
118
+ commit: () => close(true),
119
+ cancel: () => close(false),
120
+ dispose() {
121
+ close(false);
122
+ subscription.dispose();
123
+ editSub?.dispose();
124
+ events.clear();
125
+ world.remove();
126
+ },
127
+ };
128
+ }