@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.
- package/README.md +193 -2
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/dist/a11y/focus.d.ts +60 -0
- package/dist/a11y/focus.js +222 -0
- package/dist/a11y/index.d.ts +2 -0
- package/dist/a11y/index.js +4 -0
- package/dist/a11y/semantics.d.ts +37 -0
- package/dist/a11y/semantics.js +88 -0
- package/dist/commands/builtins.d.ts +88 -0
- package/dist/commands/builtins.js +362 -0
- package/dist/commands/command.d.ts +23 -0
- package/dist/commands/command.js +20 -0
- package/dist/commands/draft.d.ts +33 -0
- package/dist/commands/draft.js +96 -0
- package/dist/commands/history.d.ts +34 -0
- package/dist/commands/history.js +80 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/patch.d.ts +24 -0
- package/dist/commands/patch.js +44 -0
- package/dist/commands/transaction.d.ts +16 -0
- package/dist/commands/transaction.js +39 -0
- package/dist/core/diagnostics.d.ts +23 -0
- package/dist/core/diagnostics.js +23 -0
- package/dist/core/disposable.d.ts +14 -0
- package/dist/core/disposable.js +51 -0
- package/dist/core/engine.d.ts +108 -0
- package/dist/core/engine.js +323 -0
- package/dist/core/event-bus.d.ts +10 -0
- package/dist/core/event-bus.js +33 -0
- package/dist/core/ids.d.ts +13 -0
- package/dist/core/ids.js +6 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +7 -0
- package/dist/core/plugin.d.ts +20 -0
- package/dist/core/plugin.js +47 -0
- package/dist/core/services.d.ts +14 -0
- package/dist/core/services.js +20 -0
- package/dist/devtools/index.d.ts +1 -0
- package/dist/devtools/index.js +2 -0
- package/dist/devtools/panel.d.ts +39 -0
- package/dist/devtools/panel.js +100 -0
- package/dist/dom/a11y-layer.d.ts +32 -0
- package/dist/dom/a11y-layer.js +358 -0
- package/dist/dom/anchor.d.ts +34 -0
- package/dist/dom/anchor.js +35 -0
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.js +8 -0
- package/dist/dom/menu.d.ts +24 -0
- package/dist/dom/menu.js +122 -0
- package/dist/dom/overlays.d.ts +29 -0
- package/dist/dom/overlays.js +82 -0
- package/dist/dom/paint/collect.d.ts +8 -0
- package/dist/dom/paint/collect.js +589 -0
- package/dist/dom/paint/css.d.ts +86 -0
- package/dist/dom/paint/css.js +526 -0
- package/dist/dom/paint/draw.d.ts +16 -0
- package/dist/dom/paint/draw.js +413 -0
- package/dist/dom/paint/ghost.d.ts +2 -0
- package/dist/dom/paint/ghost.js +8 -0
- package/dist/dom/paint/index.d.ts +6 -0
- package/dist/dom/paint/index.js +9 -0
- package/dist/dom/paint/text.d.ts +26 -0
- package/dist/dom/paint/text.js +209 -0
- package/dist/dom/paint/types.d.ts +174 -0
- package/dist/dom/paint/types.js +7 -0
- package/dist/dom/paint/watch.d.ts +10 -0
- package/dist/dom/paint/watch.js +109 -0
- package/dist/dom/position.d.ts +37 -0
- package/dist/dom/position.js +125 -0
- package/dist/dom/text-editor.d.ts +27 -0
- package/dist/dom/text-editor.js +128 -0
- package/dist/events/event.d.ts +122 -0
- package/dist/events/event.js +130 -0
- package/dist/events/eventer.d.ts +24 -0
- package/dist/events/eventer.js +83 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +3 -0
- package/dist/events/interaction.d.ts +43 -0
- package/dist/events/interaction.js +203 -0
- package/dist/geometry/anchors.d.ts +14 -0
- package/dist/geometry/anchors.js +13 -0
- package/dist/geometry/bounds.d.ts +16 -0
- package/dist/geometry/bounds.js +42 -0
- package/dist/geometry/curves.d.ts +39 -0
- package/dist/geometry/curves.js +68 -0
- package/dist/geometry/index.d.ts +6 -0
- package/dist/geometry/index.js +6 -0
- package/dist/geometry/matrix.d.ts +22 -0
- package/dist/geometry/matrix.js +56 -0
- package/dist/geometry/spaces.d.ts +22 -0
- package/dist/geometry/spaces.js +28 -0
- package/dist/geometry/vec2.d.ts +12 -0
- package/dist/geometry/vec2.js +10 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +22 -0
- package/dist/interaction/behaviors.d.ts +10 -0
- package/dist/interaction/behaviors.js +744 -0
- package/dist/interaction/controller.d.ts +180 -0
- package/dist/interaction/controller.js +269 -0
- package/dist/interaction/hit-test.d.ts +45 -0
- package/dist/interaction/hit-test.js +119 -0
- package/dist/interaction/index.d.ts +4 -0
- package/dist/interaction/index.js +7 -0
- package/dist/interaction/web-input.d.ts +13 -0
- package/dist/interaction/web-input.js +172 -0
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +2 -0
- package/dist/layout/layout.d.ts +27 -0
- package/dist/layout/layout.js +266 -0
- package/dist/react/canvas/graph.d.ts +83 -0
- package/dist/react/canvas/graph.js +89 -0
- package/dist/react/canvas/hooks.d.ts +42 -0
- package/dist/react/canvas/hooks.js +78 -0
- package/dist/react/canvas/index.d.ts +35 -0
- package/dist/react/canvas/index.js +8 -0
- package/dist/react/components.d.ts +55 -0
- package/dist/react/components.js +197 -0
- package/dist/react/context.d.ts +4 -0
- package/dist/react/context.js +9 -0
- package/dist/react/flow/api/LICENSE +21 -0
- package/dist/react/flow/api/externals.d.ts +12 -0
- package/dist/react/flow/api/react/additional-components/Background/Background.d.ts +7 -0
- package/dist/react/flow/api/react/additional-components/Background/Patterns.d.ts +17 -0
- package/dist/react/flow/api/react/additional-components/Background/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/Background/types.d.ts +25 -0
- package/dist/react/flow/api/react/additional-components/Controls/ControlButton.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/Controls/Controls.d.ts +7 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/FitView.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Lock.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Minus.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Plus.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Unlock.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/Controls/types.d.ts +20 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/EdgeToolbar.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/types.d.ts +6 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMap.d.ts +8 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNode.d.ts +4 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNodes.d.ts +5 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/types.d.ts +44 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizeControl.d.ts +5 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizer.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/types.d.ts +32 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbar.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbarPortal.d.ts +4 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/types.d.ts +9 -0
- package/dist/react/flow/api/react/additional-components/index.d.ts +6 -0
- package/dist/react/flow/api/react/components/A11yDescriptions/index.d.ts +7 -0
- package/dist/react/flow/api/react/components/Attribution/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/BatchProvider/index.d.ts +10 -0
- package/dist/react/flow/api/react/components/BatchProvider/types.d.ts +6 -0
- package/dist/react/flow/api/react/components/BatchProvider/useQueue.d.ts +2 -0
- package/dist/react/flow/api/react/components/ConnectionLine/index.d.ts +11 -0
- package/dist/react/flow/api/react/components/EdgeLabelRenderer/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/EdgeUpdateAnchors.d.ts +14 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/utils.d.ts +11 -0
- package/dist/react/flow/api/react/components/Edges/BaseEdge.d.ts +2 -0
- package/dist/react/flow/api/react/components/Edges/BezierEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/EdgeAnchor.d.ts +13 -0
- package/dist/react/flow/api/react/components/Edges/EdgeText.d.ts +7 -0
- package/dist/react/flow/api/react/components/Edges/SimpleBezierEdge.d.ts +20 -0
- package/dist/react/flow/api/react/components/Edges/SmoothStepEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/StepEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/StraightEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/Handle/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/NodeWrapper/index.d.ts +4 -0
- package/dist/react/flow/api/react/components/NodeWrapper/useNodeObserver.d.ts +7 -0
- package/dist/react/flow/api/react/components/NodeWrapper/utils.d.ts +8 -0
- package/dist/react/flow/api/react/components/Nodes/DefaultNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/GroupNode.d.ts +1 -0
- package/dist/react/flow/api/react/components/Nodes/InputNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/OutputNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/utils.d.ts +12 -0
- package/dist/react/flow/api/react/components/NodesSelection/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/Panel/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/ReactFlowProvider/index.d.ts +20 -0
- package/dist/react/flow/api/react/components/SelectionListener/index.d.ts +6 -0
- package/dist/react/flow/api/react/components/StoreUpdater/index.d.ts +67 -0
- package/dist/react/flow/api/react/components/UserSelection/index.d.ts +1 -0
- package/dist/react/flow/api/react/components/ViewportPortal/index.d.ts +4 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/MarkerDefinitions.d.ts +9 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/MarkerSymbols.d.ts +8 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/index.d.ts +12 -0
- package/dist/react/flow/api/react/container/FlowRenderer/index.d.ts +13 -0
- package/dist/react/flow/api/react/container/GraphView/index.d.ts +10 -0
- package/dist/react/flow/api/react/container/GraphView/useNodeOrEdgeTypesWarning.d.ts +3 -0
- package/dist/react/flow/api/react/container/GraphView/useStylesLoadedWarning.d.ts +1 -0
- package/dist/react/flow/api/react/container/NodeRenderer/index.d.ts +9 -0
- package/dist/react/flow/api/react/container/NodeRenderer/useResizeObserver.d.ts +1 -0
- package/dist/react/flow/api/react/container/Pane/index.d.ts +10 -0
- package/dist/react/flow/api/react/container/ReactFlow/Wrapper.d.ts +19 -0
- package/dist/react/flow/api/react/container/ReactFlow/index.d.ts +3 -0
- package/dist/react/flow/api/react/container/ReactFlow/init-values.d.ts +3 -0
- package/dist/react/flow/api/react/container/Viewport/index.d.ts +6 -0
- package/dist/react/flow/api/react/container/ZoomPane/index.d.ts +7 -0
- package/dist/react/flow/api/react/contexts/HandleConfigContext.d.ts +11 -0
- package/dist/react/flow/api/react/contexts/NodeIdContext.d.ts +5 -0
- package/dist/react/flow/api/react/contexts/StoreContext.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useColorModeClass.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useConnection.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useDrag.d.ts +12 -0
- package/dist/react/flow/api/react/hooks/useEdges.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useGlobalKeyHandler.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useHandleConnections.d.ts +10 -0
- package/dist/react/flow/api/react/hooks/useInternalNode.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useKeyPress.d.ts +7 -0
- package/dist/react/flow/api/react/hooks/useMoveSelectedNodes.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useNodeConnections.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useNodes.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useNodesData.d.ts +4 -0
- package/dist/react/flow/api/react/hooks/useNodesEdgesState.d.ts +12 -0
- package/dist/react/flow/api/react/hooks/useNodesInitialized.d.ts +4 -0
- package/dist/react/flow/api/react/hooks/useOnEdgesChangeMiddleware.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useOnInitHandler.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useOnNodesChangeMiddleware.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useOnSelectionChange.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useOnViewportChange.d.ts +7 -0
- package/dist/react/flow/api/react/hooks/useReactFlow.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useResizeHandler.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useStore.d.ts +8 -0
- package/dist/react/flow/api/react/hooks/useUpdateNodeInternals.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useViewport.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useViewportHelper.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useViewportSync.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useVisibleEdgeIds.d.ts +1 -0
- package/dist/react/flow/api/react/hooks/useVisibleNodeIds.d.ts +1 -0
- package/dist/react/flow/api/react/index.d.ts +41 -0
- package/dist/react/flow/api/react/store/index.d.ts +18 -0
- package/dist/react/flow/api/react/store/initialState.d.ts +18 -0
- package/dist/react/flow/api/react/styles/utils.d.ts +2 -0
- package/dist/react/flow/api/react/types/component-props.d.ts +127 -0
- package/dist/react/flow/api/react/types/edges.d.ts +111 -0
- package/dist/react/flow/api/react/types/general.d.ts +53 -0
- package/dist/react/flow/api/react/types/index.d.ts +6 -0
- package/dist/react/flow/api/react/types/instance.d.ts +64 -0
- package/dist/react/flow/api/react/types/nodes.d.ts +41 -0
- package/dist/react/flow/api/react/types/store.d.ts +114 -0
- package/dist/react/flow/api/react/utils/changes.d.ts +15 -0
- package/dist/react/flow/api/react/utils/edges.d.ts +3 -0
- package/dist/react/flow/api/react/utils/general.d.ts +5 -0
- package/dist/react/flow/api/react/utils/index.d.ts +3 -0
- package/dist/react/flow/api/system/constants.d.ts +43 -0
- package/dist/react/flow/api/system/index.d.ts +8 -0
- package/dist/react/flow/api/system/types/changes.d.ts +48 -0
- package/dist/react/flow/api/system/types/edges.d.ts +72 -0
- package/dist/react/flow/api/system/types/general.d.ts +175 -0
- package/dist/react/flow/api/system/types/handles.d.ts +21 -0
- package/dist/react/flow/api/system/types/index.d.ts +7 -0
- package/dist/react/flow/api/system/types/nodes.d.ts +89 -0
- package/dist/react/flow/api/system/types/panzoom.d.ts +58 -0
- package/dist/react/flow/api/system/types/utils.d.ts +46 -0
- package/dist/react/flow/api/system/utils/attribution.d.ts +1 -0
- package/dist/react/flow/api/system/utils/connections.d.ts +4 -0
- package/dist/react/flow/api/system/utils/dom.d.ts +20 -0
- package/dist/react/flow/api/system/utils/edge-toolbar.d.ts +1 -0
- package/dist/react/flow/api/system/utils/edges/bezier-edge.d.ts +40 -0
- package/dist/react/flow/api/system/utils/edges/general.d.ts +44 -0
- package/dist/react/flow/api/system/utils/edges/index.d.ts +5 -0
- package/dist/react/flow/api/system/utils/edges/positions.d.ts +16 -0
- package/dist/react/flow/api/system/utils/edges/smoothstep-edge.d.ts +21 -0
- package/dist/react/flow/api/system/utils/edges/straight-edge.d.ts +13 -0
- package/dist/react/flow/api/system/utils/general.d.ts +56 -0
- package/dist/react/flow/api/system/utils/graph.d.ts +45 -0
- package/dist/react/flow/api/system/utils/index.d.ts +12 -0
- package/dist/react/flow/api/system/utils/marker.d.ts +8 -0
- package/dist/react/flow/api/system/utils/node-toolbar.d.ts +2 -0
- package/dist/react/flow/api/system/utils/shallow-node-data.d.ts +4 -0
- package/dist/react/flow/api/system/utils/store.d.ts +33 -0
- package/dist/react/flow/api/system/utils/types.d.ts +7 -0
- package/dist/react/flow/api/system/xydrag/XYDrag.d.ts +56 -0
- package/dist/react/flow/api/system/xydrag/index.d.ts +1 -0
- package/dist/react/flow/api/system/xydrag/utils.d.ts +22 -0
- package/dist/react/flow/api/system/xyhandle/XYHandle.d.ts +2 -0
- package/dist/react/flow/api/system/xyhandle/index.d.ts +1 -0
- package/dist/react/flow/api/system/xyhandle/types.d.ts +49 -0
- package/dist/react/flow/api/system/xyhandle/utils.d.ts +9 -0
- package/dist/react/flow/api/system/xyminimap/index.d.ts +27 -0
- package/dist/react/flow/api/system/xypanzoom/XYPanZoom.d.ts +11 -0
- package/dist/react/flow/api/system/xypanzoom/eventhandler.d.ts +45 -0
- package/dist/react/flow/api/system/xypanzoom/filter.d.ts +15 -0
- package/dist/react/flow/api/system/xypanzoom/index.d.ts +1 -0
- package/dist/react/flow/api/system/xypanzoom/utils.d.ts +8 -0
- package/dist/react/flow/api/system/xyresizer/XYResizer.d.ts +51 -0
- package/dist/react/flow/api/system/xyresizer/index.d.ts +2 -0
- package/dist/react/flow/api/system/xyresizer/types.d.ts +26 -0
- package/dist/react/flow/api/system/xyresizer/utils.d.ts +41 -0
- package/dist/react/flow/components.d.ts +148 -0
- package/dist/react/flow/components.js +526 -0
- package/dist/react/flow/configuration.d.ts +6 -0
- package/dist/react/flow/configuration.js +27 -0
- package/dist/react/flow/drag.d.ts +14 -0
- package/dist/react/flow/drag.js +273 -0
- package/dist/react/flow/extras.d.ts +155 -0
- package/dist/react/flow/extras.js +317 -0
- package/dist/react/flow/handle.d.ts +21 -0
- package/dist/react/flow/handle.js +149 -0
- package/dist/react/flow/hooks.d.ts +47 -0
- package/dist/react/flow/hooks.js +131 -0
- package/dist/react/flow/index.d.ts +78 -0
- package/dist/react/flow/index.js +73 -0
- package/dist/react/flow/queries.d.ts +20 -0
- package/dist/react/flow/queries.js +30 -0
- package/dist/react/flow/react-flow.d.ts +73 -0
- package/dist/react/flow/react-flow.js +1445 -0
- package/dist/react/flow/resize.d.ts +30 -0
- package/dist/react/flow/resize.js +49 -0
- package/dist/react/flow/store.d.ts +412 -0
- package/dist/react/flow/store.js +713 -0
- package/dist/react/flow/style.css +630 -0
- package/dist/react/flow/style.css.d.ts +2 -0
- package/dist/react/flow/system.d.ts +146 -0
- package/dist/react/flow/system.js +300 -0
- package/dist/react/flow/types.d.ts +131 -0
- package/dist/react/flow/types.js +1 -0
- package/dist/react/flow/utils.d.ts +77 -0
- package/dist/react/flow/utils.js +285 -0
- package/dist/react/hooks.d.ts +14 -0
- package/dist/react/hooks.js +44 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +5 -0
- package/dist/render/backend.d.ts +26 -0
- package/dist/render/backend.js +5 -0
- package/dist/render/canvas2d/backend.d.ts +7 -0
- package/dist/render/canvas2d/backend.js +122 -0
- package/dist/render/canvas2d/index.d.ts +1 -0
- package/dist/render/canvas2d/index.js +2 -0
- package/dist/render/color.d.ts +9 -0
- package/dist/render/color.js +69 -0
- package/dist/render/commands.d.ts +69 -0
- package/dist/render/commands.js +1 -0
- package/dist/render/display-list.d.ts +65 -0
- package/dist/render/display-list.js +316 -0
- package/dist/render/images.d.ts +35 -0
- package/dist/render/images.js +83 -0
- package/dist/render/index.d.ts +14 -0
- package/dist/render/index.js +16 -0
- package/dist/render/painters.d.ts +35 -0
- package/dist/render/painters.js +109 -0
- package/dist/render/renderer.d.ts +70 -0
- package/dist/render/renderer.js +162 -0
- package/dist/render/scene-index.d.ts +21 -0
- package/dist/render/scene-index.js +64 -0
- package/dist/render/text.d.ts +8 -0
- package/dist/render/text.js +100 -0
- package/dist/render/theme.d.ts +21 -0
- package/dist/render/theme.js +33 -0
- package/dist/render/ui.d.ts +63 -0
- package/dist/render/ui.js +188 -0
- package/dist/render/webgl2/atlas.d.ts +36 -0
- package/dist/render/webgl2/atlas.js +93 -0
- package/dist/render/webgl2/backend.d.ts +19 -0
- package/dist/render/webgl2/backend.js +338 -0
- package/dist/render/webgl2/index.d.ts +2 -0
- package/dist/render/webgl2/index.js +3 -0
- package/dist/render/webgl2/shaders.d.ts +6 -0
- package/dist/render/webgl2/shaders.js +112 -0
- package/dist/render/webgpu/index.d.ts +1 -0
- package/dist/render/webgpu/index.js +3 -0
- package/dist/scene/builtins.d.ts +25 -0
- package/dist/scene/builtins.js +60 -0
- package/dist/scene/dirty.d.ts +11 -0
- package/dist/scene/dirty.js +10 -0
- package/dist/scene/index.d.ts +5 -0
- package/dist/scene/index.js +5 -0
- package/dist/scene/record.d.ts +40 -0
- package/dist/scene/record.js +12 -0
- package/dist/scene/scene-graph.d.ts +58 -0
- package/dist/scene/scene-graph.js +178 -0
- package/dist/scene/schema.d.ts +27 -0
- package/dist/scene/schema.js +32 -0
- package/dist/sdk/create-avis.d.ts +109 -0
- package/dist/sdk/create-avis.js +162 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +2 -0
- package/dist/serialization/format.d.ts +46 -0
- package/dist/serialization/format.js +20 -0
- package/dist/serialization/index.d.ts +3 -0
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/migrate.d.ts +7 -0
- package/dist/serialization/migrate.js +54 -0
- package/dist/serialization/serialize.d.ts +10 -0
- package/dist/serialization/serialize.js +114 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.js +2 -0
- package/dist/state/selector.d.ts +6 -0
- package/dist/state/selector.js +29 -0
- package/dist/state/store.d.ts +91 -0
- package/dist/state/store.js +102 -0
- package/dist/style/computed.d.ts +84 -0
- package/dist/style/computed.js +296 -0
- package/dist/style/index.d.ts +6 -0
- package/dist/style/index.js +8 -0
- package/dist/style/style-engine.d.ts +33 -0
- package/dist/style/style-engine.js +113 -0
- package/dist/style/tokens.d.ts +49 -0
- package/dist/style/tokens.js +142 -0
- package/dist/style/utilities.d.ts +34 -0
- package/dist/style/utilities.js +341 -0
- package/dist/style/values.d.ts +30 -0
- package/dist/style/values.js +361 -0
- package/dist/style/variants.d.ts +38 -0
- package/dist/style/variants.js +55 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +1 -0
- package/dist/sync/save-queue.d.ts +24 -0
- package/dist/sync/save-queue.js +88 -0
- package/dist/wasm/index.d.ts +2 -0
- package/dist/wasm/index.js +2 -0
- package/dist/wasm/load.d.ts +7 -0
- package/dist/wasm/load.js +47 -0
- package/dist/wasm/pkg/avis_engine_wasm.d.ts +84 -0
- package/dist/wasm/pkg/avis_engine_wasm.js +339 -0
- package/dist/wasm/pkg/avis_engine_wasm_bg.wasm +0 -0
- package/dist/wasm/reference.d.ts +38 -0
- package/dist/wasm/reference.js +174 -0
- package/package.json +76 -4
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Disposable } from "../core/disposable.js";
|
|
2
|
+
import { type Engine } from "../core/engine.js";
|
|
3
|
+
import type { NodeId } from "../core/ids.js";
|
|
4
|
+
import type { Plugin } from "../core/plugin.js";
|
|
5
|
+
import { type FocusManager } from "../a11y/focus.js";
|
|
6
|
+
import { type AccessibilityLayer } from "../dom/a11y-layer.js";
|
|
7
|
+
import { type OverlayLayer } from "../dom/overlays.js";
|
|
8
|
+
import { type TextEditor } from "../dom/text-editor.js";
|
|
9
|
+
import { type InteractionController, type InteractionOptions } from "../interaction/controller.js";
|
|
10
|
+
import { type Renderer, type RendererOptions } from "../render/renderer.js";
|
|
11
|
+
import { type UIElement } from "../render/ui.js";
|
|
12
|
+
import { EventBus } from "../core/event-bus.js";
|
|
13
|
+
import type { NodeType } from "../scene/schema.js";
|
|
14
|
+
import { type StyleEngine } from "../style/style-engine.js";
|
|
15
|
+
import { TokenRegistry, type ThemeMode } from "../style/tokens.js";
|
|
16
|
+
import { type Devtools } from "../devtools/panel.js";
|
|
17
|
+
import { type Kernels } from "../wasm/reference.js";
|
|
18
|
+
export type AvisOptions = {
|
|
19
|
+
/** The element (or a selector) the canvas fills. It is made `position: relative`. */
|
|
20
|
+
container: HTMLElement | string;
|
|
21
|
+
/** "webgl" (WebGL2, falling back to Canvas2D), "canvas2d", or "auto" (the same as webgl). */
|
|
22
|
+
renderer?: "webgl" | "canvas2d" | "auto";
|
|
23
|
+
/** The DOM accessibility tree, focus and the text field (on by default). */
|
|
24
|
+
accessibility?: boolean;
|
|
25
|
+
/** Token CSS sources (Tailwind's theme.css, the app's CSS), or a registry. */
|
|
26
|
+
tokens?: readonly string[] | TokenRegistry;
|
|
27
|
+
mode?: ThemeMode;
|
|
28
|
+
/** Use the Rust kernels when they load (default), else the TypeScript ones. */
|
|
29
|
+
wasm?: boolean;
|
|
30
|
+
schemas?: readonly NodeType[];
|
|
31
|
+
plugins?: readonly Plugin<Engine>[];
|
|
32
|
+
interaction?: Partial<InteractionOptions>;
|
|
33
|
+
render?: Omit<Partial<RendererOptions>, "backend" | "kernels">;
|
|
34
|
+
label?: string;
|
|
35
|
+
/** The devtools panel (Ctrl+Shift+D toggles it); open at start when "open". */
|
|
36
|
+
devtools?: boolean | "open";
|
|
37
|
+
};
|
|
38
|
+
/** A node in the spec's shape: className and children make a styled node. */
|
|
39
|
+
export type AvisNodeInput = {
|
|
40
|
+
id?: string;
|
|
41
|
+
type?: string;
|
|
42
|
+
parentId?: string | null;
|
|
43
|
+
className?: string;
|
|
44
|
+
text?: string;
|
|
45
|
+
children?: UIElement[];
|
|
46
|
+
position?: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
};
|
|
50
|
+
size?: {
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
};
|
|
54
|
+
rotation?: number;
|
|
55
|
+
props?: Record<string, unknown>;
|
|
56
|
+
/** False makes the node locked (not draggable or resizable). */
|
|
57
|
+
draggable?: boolean;
|
|
58
|
+
visible?: boolean;
|
|
59
|
+
};
|
|
60
|
+
export type AvisEvents = {
|
|
61
|
+
/** An element with an action or role was pressed: a click or, with accessibility, Enter/Space on its DOM control. */
|
|
62
|
+
"element:press": {
|
|
63
|
+
nodeId: string;
|
|
64
|
+
action: string | undefined;
|
|
65
|
+
path: number[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type Avis = Disposable & {
|
|
69
|
+
readonly events: EventBus<AvisEvents>;
|
|
70
|
+
readonly engine: Engine;
|
|
71
|
+
readonly canvas: HTMLCanvasElement;
|
|
72
|
+
readonly renderer: Renderer;
|
|
73
|
+
readonly controller: InteractionController;
|
|
74
|
+
readonly style: StyleEngine | null;
|
|
75
|
+
readonly focus: FocusManager | null;
|
|
76
|
+
readonly a11y: AccessibilityLayer | null;
|
|
77
|
+
readonly overlays: OverlayLayer;
|
|
78
|
+
readonly editor: TextEditor | null;
|
|
79
|
+
readonly devtools: Devtools | null;
|
|
80
|
+
readonly kernels: Kernels & {
|
|
81
|
+
source?: string;
|
|
82
|
+
};
|
|
83
|
+
readonly selection: Engine["selection"];
|
|
84
|
+
readonly viewport: Engine["viewport"];
|
|
85
|
+
readonly commands: Engine["commands"];
|
|
86
|
+
readonly history: Engine["history"];
|
|
87
|
+
createNode(input: AvisNodeInput): NodeId;
|
|
88
|
+
updateNode(id: string, input: Partial<AvisNodeInput>): void;
|
|
89
|
+
setMode(mode: ThemeMode): void;
|
|
90
|
+
};
|
|
91
|
+
/** The spec's node input → the engine's create params. */
|
|
92
|
+
export declare function toCreateParams(input: AvisNodeInput): {
|
|
93
|
+
id: NodeId | undefined;
|
|
94
|
+
type: string;
|
|
95
|
+
parentId: NodeId | null;
|
|
96
|
+
transform: {
|
|
97
|
+
rotation?: number | undefined;
|
|
98
|
+
x?: number | undefined;
|
|
99
|
+
y?: number | undefined;
|
|
100
|
+
};
|
|
101
|
+
size: {
|
|
102
|
+
w: number;
|
|
103
|
+
h: number;
|
|
104
|
+
} | undefined;
|
|
105
|
+
props: Record<string, unknown>;
|
|
106
|
+
locked: boolean | undefined;
|
|
107
|
+
visible: boolean | undefined;
|
|
108
|
+
};
|
|
109
|
+
export declare function createAvis(options: AvisOptions): Promise<Avis>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createEngine } from "../core/engine.js";
|
|
2
|
+
import { a11yPlugin, FocusKey } from "../a11y/focus.js";
|
|
3
|
+
import { attachAccessibilityLayer } from "../dom/a11y-layer.js";
|
|
4
|
+
import { createOverlayLayer } from "../dom/overlays.js";
|
|
5
|
+
import { createTextEditor } from "../dom/text-editor.js";
|
|
6
|
+
import { interactionPlugin, InteractionKey } from "../interaction/controller.js";
|
|
7
|
+
import { attachWebInput } from "../interaction/web-input.js";
|
|
8
|
+
import { createCanvas2DBackend } from "../render/canvas2d/backend.js";
|
|
9
|
+
import { createRenderer } from "../render/renderer.js";
|
|
10
|
+
import { elementAt, uiType } from "../render/ui.js";
|
|
11
|
+
import { createTextMeasurer } from "../render/text.js";
|
|
12
|
+
import { EventBus } from "../core/event-bus.js";
|
|
13
|
+
import { applyToPoint, invert } from "../geometry/matrix.js";
|
|
14
|
+
import { createWebGL2Backend } from "../render/webgl2/backend.js";
|
|
15
|
+
import { StyleKey, stylePlugin } from "../style/style-engine.js";
|
|
16
|
+
import { TokenRegistry } from "../style/tokens.js";
|
|
17
|
+
import { loadKernels } from "../wasm/load.js";
|
|
18
|
+
import { attachDevtools } from "../devtools/panel.js";
|
|
19
|
+
import { referenceKernels } from "../wasm/reference.js";
|
|
20
|
+
/** The spec's node input → the engine's create params. */
|
|
21
|
+
export function toCreateParams(input) {
|
|
22
|
+
const styled = input.className !== undefined || input.children !== undefined || (input.text !== undefined && !input.type);
|
|
23
|
+
const type = input.type ?? (styled ? "ui" : "rect");
|
|
24
|
+
const props = { ...input.props };
|
|
25
|
+
if (styled && type === "ui")
|
|
26
|
+
props.root = { className: input.className ?? "", text: input.text, children: input.children };
|
|
27
|
+
else if (input.text !== undefined)
|
|
28
|
+
props.text = input.text;
|
|
29
|
+
return {
|
|
30
|
+
id: input.id,
|
|
31
|
+
type,
|
|
32
|
+
parentId: (input.parentId ?? null),
|
|
33
|
+
transform: { ...(input.position ?? {}), ...(input.rotation !== undefined ? { rotation: input.rotation } : {}) },
|
|
34
|
+
size: input.size ? { w: input.size.width, h: input.size.height } : undefined,
|
|
35
|
+
props,
|
|
36
|
+
locked: input.draggable === false ? true : undefined,
|
|
37
|
+
visible: input.visible,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export async function createAvis(options) {
|
|
41
|
+
const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
|
|
42
|
+
if (!container)
|
|
43
|
+
throw new Error(`No container ${String(options.container)}`);
|
|
44
|
+
if (getComputedStyle(container).position === "static")
|
|
45
|
+
container.style.position = "relative";
|
|
46
|
+
const kernels = options.wasm === false ? { ...referenceKernels, source: "reference" } : await loadKernels();
|
|
47
|
+
const tokens = options.tokens instanceof TokenRegistry ? options.tokens : options.tokens ? TokenRegistry.fromCss(options.tokens) : null;
|
|
48
|
+
const accessible = options.accessibility !== false;
|
|
49
|
+
const plugins = [interactionPlugin(options.interaction)];
|
|
50
|
+
if (tokens)
|
|
51
|
+
plugins.push(stylePlugin(tokens, options.mode));
|
|
52
|
+
if (accessible)
|
|
53
|
+
plugins.push(a11yPlugin());
|
|
54
|
+
const engine = createEngine({
|
|
55
|
+
schemas: [uiType, ...(options.schemas ?? [])],
|
|
56
|
+
plugins: [...plugins, ...(options.plugins ?? [])],
|
|
57
|
+
});
|
|
58
|
+
const canvas = document.createElement("canvas");
|
|
59
|
+
canvas.tabIndex = 0;
|
|
60
|
+
canvas.setAttribute("aria-label", options.label ?? "Canvas");
|
|
61
|
+
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;outline:none;touch-action:none";
|
|
62
|
+
container.append(canvas);
|
|
63
|
+
const backend = (() => {
|
|
64
|
+
if (options.renderer === "canvas2d")
|
|
65
|
+
return createCanvas2DBackend(canvas);
|
|
66
|
+
try {
|
|
67
|
+
return createWebGL2Backend(canvas);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return createCanvas2DBackend(canvas);
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
const renderer = createRenderer(engine, { ...options.render, backend, kernels });
|
|
74
|
+
const controller = engine.services.get(InteractionKey);
|
|
75
|
+
const input = attachWebInput(controller, canvas);
|
|
76
|
+
const overlays = createOverlayLayer(engine, { root: container });
|
|
77
|
+
const a11y = accessible ? attachAccessibilityLayer(engine, { root: container, canvas, label: options.label }) : null;
|
|
78
|
+
const editor = accessible
|
|
79
|
+
? createTextEditor(engine, { root: container, restoreFocus: (id) => a11y?.elementFor(id)?.focus({ preventScroll: true }) })
|
|
80
|
+
: null;
|
|
81
|
+
const style = engine.services.has(StyleKey) ? engine.services.get(StyleKey) : null;
|
|
82
|
+
// Presses on elements inside styled nodes: by pointer (hit-tested in the
|
|
83
|
+
// node's layout) and by keyboard (the DOM controls).
|
|
84
|
+
const events = new EventBus();
|
|
85
|
+
const measure = createTextMeasurer();
|
|
86
|
+
const offTap = controller.events.on("node:tap", ({ id, input: pointer }) => {
|
|
87
|
+
const node = engine.scene.get(id);
|
|
88
|
+
const root = node?.record.props.root;
|
|
89
|
+
if (!node || !root || !style)
|
|
90
|
+
return;
|
|
91
|
+
const inverse = invert(node.world);
|
|
92
|
+
if (!inverse)
|
|
93
|
+
return;
|
|
94
|
+
const local = applyToPoint(inverse, engine.viewport.toWorld({ x: pointer.clientX, y: pointer.clientY }));
|
|
95
|
+
const hit = elementAt(root, engine.scene.sizeOf(node), { hovered: true, selected: false, dragging: false, focused: false, states: [] }, style, measure, local);
|
|
96
|
+
if (hit && !hit.element.disabled)
|
|
97
|
+
events.emit("element:press", { nodeId: id, action: hit.element.action, path: hit.path });
|
|
98
|
+
});
|
|
99
|
+
const offControl = a11y?.events.on("control:activate", (event) => events.emit("element:press", event));
|
|
100
|
+
const devtools = options.devtools
|
|
101
|
+
? attachDevtools({ engine, renderer, style }, { root: container, open: options.devtools === "open" })
|
|
102
|
+
: null;
|
|
103
|
+
return {
|
|
104
|
+
events,
|
|
105
|
+
engine,
|
|
106
|
+
canvas,
|
|
107
|
+
renderer,
|
|
108
|
+
controller,
|
|
109
|
+
style,
|
|
110
|
+
focus: accessible ? engine.services.get(FocusKey) : null,
|
|
111
|
+
a11y,
|
|
112
|
+
overlays,
|
|
113
|
+
editor,
|
|
114
|
+
devtools,
|
|
115
|
+
kernels,
|
|
116
|
+
selection: engine.selection,
|
|
117
|
+
viewport: engine.viewport,
|
|
118
|
+
commands: engine.commands,
|
|
119
|
+
history: engine.history,
|
|
120
|
+
createNode: (node) => engine.createNode(toCreateParams(node)),
|
|
121
|
+
updateNode(id, node) {
|
|
122
|
+
const record = engine.store.get().document.nodes[id];
|
|
123
|
+
if (!record)
|
|
124
|
+
return;
|
|
125
|
+
engine.transact("update", (tx) => {
|
|
126
|
+
if (node.position)
|
|
127
|
+
tx.run("node.move", { id, position: node.position });
|
|
128
|
+
if (node.size)
|
|
129
|
+
tx.run("node.resize", { id, size: { w: node.size.width, h: node.size.height } });
|
|
130
|
+
const props = { ...node.props };
|
|
131
|
+
if (record.type === "ui" && (node.className !== undefined || node.children !== undefined || node.text !== undefined)) {
|
|
132
|
+
const root = record.props.root;
|
|
133
|
+
props.root = {
|
|
134
|
+
...root,
|
|
135
|
+
...(node.className !== undefined ? { className: node.className } : {}),
|
|
136
|
+
...(node.text !== undefined ? { text: node.text } : {}),
|
|
137
|
+
...(node.children !== undefined ? { children: node.children } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else if (node.text !== undefined) {
|
|
141
|
+
props.text = node.text;
|
|
142
|
+
}
|
|
143
|
+
if (Object.keys(props).length)
|
|
144
|
+
tx.run("node.update", { id, props });
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
setMode: (mode) => style?.setMode(mode),
|
|
148
|
+
dispose() {
|
|
149
|
+
devtools?.dispose();
|
|
150
|
+
offTap.dispose();
|
|
151
|
+
offControl?.dispose();
|
|
152
|
+
events.clear();
|
|
153
|
+
renderer.dispose();
|
|
154
|
+
editor?.dispose();
|
|
155
|
+
a11y?.dispose();
|
|
156
|
+
overlays.dispose();
|
|
157
|
+
input.dispose();
|
|
158
|
+
engine.dispose();
|
|
159
|
+
canvas.remove();
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-avis.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const DOCUMENT_FORMAT = "avis.document";
|
|
2
|
+
export declare const DOCUMENT_VERSION = 1;
|
|
3
|
+
export type NodeJSON = {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
typeVersion: number;
|
|
7
|
+
parentId: string | null;
|
|
8
|
+
childIds: string[];
|
|
9
|
+
transform: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
rotation: number;
|
|
13
|
+
scaleX: number;
|
|
14
|
+
scaleY: number;
|
|
15
|
+
};
|
|
16
|
+
size: {
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
};
|
|
20
|
+
props: Record<string, unknown>;
|
|
21
|
+
visible: boolean;
|
|
22
|
+
locked: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type RelationJSON = {
|
|
25
|
+
id: string;
|
|
26
|
+
kind: "connection";
|
|
27
|
+
source: {
|
|
28
|
+
nodeId: string;
|
|
29
|
+
anchor: string | null;
|
|
30
|
+
};
|
|
31
|
+
target: {
|
|
32
|
+
nodeId: string;
|
|
33
|
+
anchor: string | null;
|
|
34
|
+
};
|
|
35
|
+
props: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
export type AvisDocumentJSON = {
|
|
38
|
+
format: typeof DOCUMENT_FORMAT;
|
|
39
|
+
version: number;
|
|
40
|
+
rootIds: string[];
|
|
41
|
+
nodes: NodeJSON[];
|
|
42
|
+
relations: RelationJSON[];
|
|
43
|
+
meta: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
/** JSON with object keys sorted at every level: byte-stable output. */
|
|
46
|
+
export declare function stableStringify(value: unknown, space?: number): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The saved document: versioned JSON, nodes parent first, keys sorted, so
|
|
3
|
+
* the same document always gives the same bytes.
|
|
4
|
+
*/
|
|
5
|
+
export const DOCUMENT_FORMAT = "avis.document";
|
|
6
|
+
export const DOCUMENT_VERSION = 1;
|
|
7
|
+
/** JSON with object keys sorted at every level: byte-stable output. */
|
|
8
|
+
export function stableStringify(value, space) {
|
|
9
|
+
return JSON.stringify(sortKeys(value), null, space);
|
|
10
|
+
}
|
|
11
|
+
function sortKeys(value) {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(sortKeys);
|
|
14
|
+
if (value && typeof value === "object") {
|
|
15
|
+
return Object.fromEntries(Object.keys(value)
|
|
16
|
+
.sort()
|
|
17
|
+
.map((key) => [key, sortKeys(value[key])]));
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Older saved documents brought to the current version, one step at a time.
|
|
3
|
+
* Version 0 (before the engine) kept a node's position as flat `x`/`y` and
|
|
4
|
+
* its size as `width`/`height`.
|
|
5
|
+
*/
|
|
6
|
+
import { error } from "../core/diagnostics.js";
|
|
7
|
+
import { DOCUMENT_VERSION } from "./format.js";
|
|
8
|
+
const steps = {
|
|
9
|
+
0: (document) => ({
|
|
10
|
+
...document,
|
|
11
|
+
version: 1,
|
|
12
|
+
nodes: (document.nodes ?? []).map((node) => {
|
|
13
|
+
const { x = 0, y = 0, width = 0, height = 0, ...rest } = node;
|
|
14
|
+
return {
|
|
15
|
+
typeVersion: 1,
|
|
16
|
+
childIds: [],
|
|
17
|
+
visible: true,
|
|
18
|
+
locked: false,
|
|
19
|
+
props: {},
|
|
20
|
+
...rest,
|
|
21
|
+
transform: { x, y, rotation: 0, scaleX: 1, scaleY: 1 },
|
|
22
|
+
size: { w: width, h: height },
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
relations: document.relations ?? [],
|
|
26
|
+
meta: document.meta ?? {},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
export function migrateDocument(document) {
|
|
30
|
+
let current = document;
|
|
31
|
+
let version = typeof current.version === "number" ? current.version : 0;
|
|
32
|
+
if (version > DOCUMENT_VERSION) {
|
|
33
|
+
return {
|
|
34
|
+
document: current,
|
|
35
|
+
diagnostics: [
|
|
36
|
+
error("document.version", `Document version ${version} is newer than this engine (${DOCUMENT_VERSION})`),
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
while (version < DOCUMENT_VERSION) {
|
|
41
|
+
const step = steps[version];
|
|
42
|
+
if (!step) {
|
|
43
|
+
return {
|
|
44
|
+
document: current,
|
|
45
|
+
diagnostics: [
|
|
46
|
+
error("document.migrate", `No migration from version ${version}`),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
current = step(current);
|
|
51
|
+
version = current.version;
|
|
52
|
+
}
|
|
53
|
+
return { document: current, diagnostics: [] };
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Diagnostic } from "../core/diagnostics.js";
|
|
2
|
+
import type { DocumentState } from "../scene/record.js";
|
|
3
|
+
import type { SchemaRegistry } from "../scene/schema.js";
|
|
4
|
+
import { type AvisDocumentJSON } from "./format.js";
|
|
5
|
+
export declare function serialize(document: DocumentState, meta?: Record<string, unknown>): AvisDocumentJSON;
|
|
6
|
+
export declare const toJSONString: (document: DocumentState, meta?: Record<string, unknown>) => string;
|
|
7
|
+
export declare function deserialize(input: string | Record<string, unknown>, schemas: SchemaRegistry): {
|
|
8
|
+
document: DocumentState;
|
|
9
|
+
diagnostics: Diagnostic[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The document to and from its saved form. Loading migrates old versions,
|
|
3
|
+
* keeps nodes of unknown types (as "unknown", with their data and a
|
|
4
|
+
* diagnostic) and never drops what it can't read.
|
|
5
|
+
*/
|
|
6
|
+
import { error, warning } from "../core/diagnostics.js";
|
|
7
|
+
import { DOCUMENT_FORMAT, DOCUMENT_VERSION, stableStringify, } from "./format.js";
|
|
8
|
+
import { migrateDocument } from "./migrate.js";
|
|
9
|
+
export function serialize(document, meta = {}) {
|
|
10
|
+
const nodes = [];
|
|
11
|
+
const visit = (id) => {
|
|
12
|
+
const record = document.nodes[id];
|
|
13
|
+
if (!record)
|
|
14
|
+
return;
|
|
15
|
+
nodes.push({
|
|
16
|
+
id: record.id,
|
|
17
|
+
type: record.type,
|
|
18
|
+
typeVersion: record.typeVersion,
|
|
19
|
+
parentId: record.parentId,
|
|
20
|
+
childIds: [...record.childIds],
|
|
21
|
+
transform: { ...record.transform },
|
|
22
|
+
size: { ...record.size },
|
|
23
|
+
props: record.props,
|
|
24
|
+
visible: record.visible,
|
|
25
|
+
locked: record.locked,
|
|
26
|
+
});
|
|
27
|
+
record.childIds.forEach(visit);
|
|
28
|
+
};
|
|
29
|
+
document.rootIds.forEach(visit);
|
|
30
|
+
const relations = Object.values(document.relations)
|
|
31
|
+
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
32
|
+
.map((relation) => ({
|
|
33
|
+
id: relation.id,
|
|
34
|
+
kind: relation.kind,
|
|
35
|
+
source: { ...relation.source },
|
|
36
|
+
target: { ...relation.target },
|
|
37
|
+
props: relation.props,
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
format: DOCUMENT_FORMAT,
|
|
41
|
+
version: DOCUMENT_VERSION,
|
|
42
|
+
rootIds: [...document.rootIds],
|
|
43
|
+
nodes,
|
|
44
|
+
relations,
|
|
45
|
+
meta,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export const toJSONString = (document, meta) => stableStringify(serialize(document, meta));
|
|
49
|
+
export function deserialize(input, schemas) {
|
|
50
|
+
const diagnostics = [];
|
|
51
|
+
let raw;
|
|
52
|
+
try {
|
|
53
|
+
raw = typeof input === "string" ? JSON.parse(input) : input;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return {
|
|
57
|
+
document: { nodes: {}, relations: {}, rootIds: [] },
|
|
58
|
+
diagnostics: [error("document.json", "Not valid JSON")],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (raw.format !== undefined && raw.format !== DOCUMENT_FORMAT) {
|
|
62
|
+
diagnostics.push(error("document.format", `Not an AVIS document (${String(raw.format)})`));
|
|
63
|
+
return { document: { nodes: {}, relations: {}, rootIds: [] }, diagnostics };
|
|
64
|
+
}
|
|
65
|
+
const migrated = migrateDocument(raw);
|
|
66
|
+
diagnostics.push(...migrated.diagnostics);
|
|
67
|
+
const json = migrated.document;
|
|
68
|
+
const nodes = {};
|
|
69
|
+
for (const node of json.nodes ?? []) {
|
|
70
|
+
const schema = schemas.get(node.type);
|
|
71
|
+
if (!schema) {
|
|
72
|
+
diagnostics.push(warning("node.unknown-type", `Unknown node type "${node.type}", kept as "unknown"`, {
|
|
73
|
+
data: { id: node.id, type: node.type },
|
|
74
|
+
}));
|
|
75
|
+
nodes[node.id] = Object.freeze({
|
|
76
|
+
...node,
|
|
77
|
+
id: node.id,
|
|
78
|
+
parentId: node.parentId,
|
|
79
|
+
childIds: node.childIds,
|
|
80
|
+
type: "unknown",
|
|
81
|
+
typeVersion: 1,
|
|
82
|
+
props: { originalType: node.type, payload: node.props },
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
let props = node.props;
|
|
87
|
+
if (node.typeVersion < schema.version && schema.migrate) {
|
|
88
|
+
props = schema.migrate(props, node.typeVersion);
|
|
89
|
+
}
|
|
90
|
+
nodes[node.id] = Object.freeze({
|
|
91
|
+
...node,
|
|
92
|
+
id: node.id,
|
|
93
|
+
parentId: node.parentId,
|
|
94
|
+
childIds: node.childIds,
|
|
95
|
+
typeVersion: schema.version,
|
|
96
|
+
props: { ...schema.defaults(), ...props },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const relations = {};
|
|
100
|
+
for (const relation of json.relations ?? []) {
|
|
101
|
+
if (!nodes[relation.source.nodeId] || !nodes[relation.target.nodeId]) {
|
|
102
|
+
diagnostics.push(warning("relation.dangling", `Relation "${relation.id}" points at a missing node, dropped`));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
relations[relation.id] = Object.freeze(relation);
|
|
106
|
+
}
|
|
107
|
+
// Version 0 had no hierarchy: every node is a root.
|
|
108
|
+
const rootIds = (json.rootIds ??
|
|
109
|
+
Object.keys(nodes).filter((id) => !nodes[id].parentId));
|
|
110
|
+
return {
|
|
111
|
+
document: { nodes, relations, rootIds: rootIds.filter((id) => nodes[id]) },
|
|
112
|
+
diagnostics,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Equal when the same, or when every own key holds the same value. */
|
|
2
|
+
export declare function shallowEqual(a: unknown, b: unknown): boolean;
|
|
3
|
+
/** A selector that recomputes only when its inputs change (memoized). */
|
|
4
|
+
export declare function createSelector<S, I extends unknown[], R>(inputs: {
|
|
5
|
+
[K in keyof I]: (state: S) => I[K];
|
|
6
|
+
}, combine: (...values: I) => R): (state: S) => R;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Equal when the same, or when every own key holds the same value. */
|
|
2
|
+
export function shallowEqual(a, b) {
|
|
3
|
+
if (Object.is(a, b))
|
|
4
|
+
return true;
|
|
5
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b)
|
|
6
|
+
return false;
|
|
7
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
8
|
+
return false;
|
|
9
|
+
const keysA = Object.keys(a);
|
|
10
|
+
const keysB = Object.keys(b);
|
|
11
|
+
if (keysA.length !== keysB.length)
|
|
12
|
+
return false;
|
|
13
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) &&
|
|
14
|
+
Object.is(a[key], b[key]));
|
|
15
|
+
}
|
|
16
|
+
/** A selector that recomputes only when its inputs change (memoized). */
|
|
17
|
+
export function createSelector(inputs, combine) {
|
|
18
|
+
let last = null;
|
|
19
|
+
return (state) => {
|
|
20
|
+
const values = inputs.map((input) => input(state));
|
|
21
|
+
if (last &&
|
|
22
|
+
values.every((value, index) => Object.is(value, last.values[index]))) {
|
|
23
|
+
return last.result;
|
|
24
|
+
}
|
|
25
|
+
const result = combine(...values);
|
|
26
|
+
last = { values, result };
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
}
|