@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 { uiPainter } from "./ui.js";
|
|
2
|
+
import { layoutLines } from "./text.js";
|
|
3
|
+
const string = (value, fallback = "") => (typeof value === "string" ? value : fallback);
|
|
4
|
+
const number = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
5
|
+
/** Lines of text inside a box, top-left, clamped to its height. */
|
|
6
|
+
export function paintText(node, out, ctx, text, box, font, color, lineHeight = 1.4) {
|
|
7
|
+
if (!text || box.w <= 0)
|
|
8
|
+
return;
|
|
9
|
+
const height = font.size * lineHeight;
|
|
10
|
+
const maxLines = Math.max(1, Math.floor(box.h / height));
|
|
11
|
+
const lines = layoutLines(text, font, box.w, maxLines, ctx.measure);
|
|
12
|
+
lines.forEach((line, index) => {
|
|
13
|
+
out.push({
|
|
14
|
+
kind: "text",
|
|
15
|
+
matrix: node.world,
|
|
16
|
+
x: box.x,
|
|
17
|
+
y: box.y + index * height,
|
|
18
|
+
text: line,
|
|
19
|
+
font,
|
|
20
|
+
lineHeight: height,
|
|
21
|
+
color,
|
|
22
|
+
nodeId: node.id,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const box = (node, size, fill, stroke, radius, strokeWidth = 1) => ({
|
|
27
|
+
kind: "rect",
|
|
28
|
+
matrix: node.world,
|
|
29
|
+
w: size.w,
|
|
30
|
+
h: size.h,
|
|
31
|
+
radius,
|
|
32
|
+
fill,
|
|
33
|
+
stroke,
|
|
34
|
+
strokeWidth,
|
|
35
|
+
nodeId: node.id,
|
|
36
|
+
});
|
|
37
|
+
/** Unregistered types: a card with their title, label or name. */
|
|
38
|
+
export const fallbackPainter = (node, size, out, ctx) => {
|
|
39
|
+
const { props } = node.record;
|
|
40
|
+
out.push(box(node, size, ctx.color(ctx.theme.nodeFill), ctx.color(ctx.theme.nodeStroke), number(props.radius, 8)));
|
|
41
|
+
const label = string(props.title) || string(props.label) || string(props.name);
|
|
42
|
+
paintText(node, out, ctx, label, { x: 12, y: 10, w: size.w - 24, h: size.h - 20 }, { family: ctx.theme.fontFamily, size: 13, weight: 500 }, ctx.color(ctx.theme.text));
|
|
43
|
+
};
|
|
44
|
+
export const BUILTIN_PAINTERS = {
|
|
45
|
+
group: () => { },
|
|
46
|
+
ui: uiPainter,
|
|
47
|
+
rect(node, size, out, ctx) {
|
|
48
|
+
const { props } = node.record;
|
|
49
|
+
out.push(box(node, size, ctx.color(string(props.fill) || ctx.theme.nodeFill), ctx.color(string(props.stroke) || ctx.theme.nodeStroke), number(props.radius, 0), number(props.strokeWidth, 1)));
|
|
50
|
+
},
|
|
51
|
+
frame(node, size, out, ctx) {
|
|
52
|
+
const { props } = node.record;
|
|
53
|
+
out.push(box(node, size, ctx.color(string(props.fill) || ctx.theme.frameFill), ctx.color(ctx.theme.frameStroke), number(props.radius, 8)));
|
|
54
|
+
paintText(node, out, ctx, string(props.title), { x: 10, y: 8, w: size.w - 20, h: 18 }, { family: ctx.theme.fontFamily, size: 12, weight: 500 }, ctx.color(ctx.theme.mutedText));
|
|
55
|
+
},
|
|
56
|
+
text(node, size, out, ctx) {
|
|
57
|
+
const { props } = node.record;
|
|
58
|
+
// The DOM text field shows the text while it is being edited.
|
|
59
|
+
if (ctx.state.states.includes("editing"))
|
|
60
|
+
return;
|
|
61
|
+
const fontSize = number(props.fontSize, 14);
|
|
62
|
+
paintText(node, out, ctx, string(props.text), { x: 0, y: 0, w: size.w, h: size.h }, { family: string(props.fontFamily) || ctx.theme.fontFamily, size: fontSize, weight: number(props.fontWeight, 400) }, ctx.color(string(props.color) || ctx.theme.text), number(props.lineHeight, 1.4));
|
|
63
|
+
},
|
|
64
|
+
image(node, size, out, ctx) {
|
|
65
|
+
const { props } = node.record;
|
|
66
|
+
const src = string(props.src);
|
|
67
|
+
const radius = number(props.radius, 8);
|
|
68
|
+
// The placeholder shows until the image loads (and behind transparency).
|
|
69
|
+
out.push(box(node, size, ctx.color(ctx.theme.nodeStroke), null, radius));
|
|
70
|
+
if (src) {
|
|
71
|
+
const fit = string(props.fit);
|
|
72
|
+
out.push({
|
|
73
|
+
kind: "image",
|
|
74
|
+
matrix: node.world,
|
|
75
|
+
w: size.w,
|
|
76
|
+
h: size.h,
|
|
77
|
+
radius,
|
|
78
|
+
src,
|
|
79
|
+
fit: fit === "contain" || fit === "fill" ? fit : "cover",
|
|
80
|
+
opacity: number(props.opacity, 1),
|
|
81
|
+
nodeId: node.id,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
unknown(node, size, out, ctx) {
|
|
86
|
+
out.push(box(node, size, ctx.color(ctx.theme.nodeFill), ctx.color(ctx.theme.invalid), 4, 1));
|
|
87
|
+
paintText(node, out, ctx, `Unknown type “${string(node.record.props.originalType, "?")}”`, { x: 8, y: 6, w: size.w - 16, h: size.h - 12 }, { family: ctx.theme.fontFamily, size: 11, weight: 400 }, ctx.color(ctx.theme.invalid));
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
export class PainterRegistry {
|
|
91
|
+
painters = new Map(Object.entries(BUILTIN_PAINTERS));
|
|
92
|
+
register(type, painter) {
|
|
93
|
+
const previous = this.painters.get(type);
|
|
94
|
+
this.painters.set(type, painter);
|
|
95
|
+
return {
|
|
96
|
+
dispose: () => {
|
|
97
|
+
if (this.painters.get(type) !== painter)
|
|
98
|
+
return;
|
|
99
|
+
if (previous)
|
|
100
|
+
this.painters.set(type, previous);
|
|
101
|
+
else
|
|
102
|
+
this.painters.delete(type);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
get(type) {
|
|
107
|
+
return this.painters.get(type) ?? fallbackPainter;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import type { Plugin } from "../core/plugin.js";
|
|
5
|
+
import { type Kernels } from "../wasm/reference.js";
|
|
6
|
+
import type { BackendStats, RenderBackend } from "./backend.js";
|
|
7
|
+
import { type DisplayListStats } from "./display-list.js";
|
|
8
|
+
import { ImageStore, type ImageLoader } from "./images.js";
|
|
9
|
+
import { PainterRegistry } from "./painters.js";
|
|
10
|
+
import { type TextMeasurer } from "./text.js";
|
|
11
|
+
import { type RenderTheme } from "./theme.js";
|
|
12
|
+
import { type StyleEngine } from "../style/style-engine.js";
|
|
13
|
+
export type RendererOptions = {
|
|
14
|
+
backend: RenderBackend;
|
|
15
|
+
/** The compute kernels (`loadKernels()`); the TypeScript reference by default. */
|
|
16
|
+
kernels?: Kernels;
|
|
17
|
+
theme?: Partial<RenderTheme>;
|
|
18
|
+
painters?: PainterRegistry;
|
|
19
|
+
measure?: TextMeasurer;
|
|
20
|
+
images?: ImageLoader;
|
|
21
|
+
/** Hover, selection, handles, marquee and the dragged connection. */
|
|
22
|
+
overlay?: boolean;
|
|
23
|
+
/** React Flow's handles on every node. */
|
|
24
|
+
anchors?: boolean;
|
|
25
|
+
/** Styled nodes and token colours (defaults to the engine's style service). */
|
|
26
|
+
style?: StyleEngine;
|
|
27
|
+
/** Grid cell for culling, world units. */
|
|
28
|
+
cellSize?: number;
|
|
29
|
+
/** Runs the frame later (requestAnimationFrame by default); returns a cancel. */
|
|
30
|
+
schedule?: (run: () => void) => () => void;
|
|
31
|
+
/** A clock for the stats (performance.now by default). */
|
|
32
|
+
now?: () => number;
|
|
33
|
+
};
|
|
34
|
+
export type FrameStats = DisplayListStats & {
|
|
35
|
+
frame: number;
|
|
36
|
+
backend: RenderBackend["kind"];
|
|
37
|
+
buildMs: number;
|
|
38
|
+
drawMs: number;
|
|
39
|
+
totalMs: number;
|
|
40
|
+
/** What the backend reported (draw calls, quads, …). */
|
|
41
|
+
gpu: BackendStats;
|
|
42
|
+
};
|
|
43
|
+
export type Renderer = {
|
|
44
|
+
readonly painters: PainterRegistry;
|
|
45
|
+
readonly images: ImageStore;
|
|
46
|
+
readonly events: EventBus<{
|
|
47
|
+
frame: FrameStats;
|
|
48
|
+
diagnostic: {
|
|
49
|
+
code: string;
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
readonly lastFrame: FrameStats | null;
|
|
54
|
+
/** Draws on the next frame (several asks make one frame). */
|
|
55
|
+
requestFrame(): void;
|
|
56
|
+
/** Draws now and returns the frame's stats. */
|
|
57
|
+
renderNow(): FrameStats;
|
|
58
|
+
setTheme(theme: Partial<RenderTheme>): void;
|
|
59
|
+
/** Frame-time percentiles over the last 120 frames, ms. */
|
|
60
|
+
perf(): {
|
|
61
|
+
frames: number;
|
|
62
|
+
p50: number;
|
|
63
|
+
p95: number;
|
|
64
|
+
max: number;
|
|
65
|
+
};
|
|
66
|
+
} & Disposable;
|
|
67
|
+
export declare const RendererKey: import("../index.js").ServiceKey<Renderer>;
|
|
68
|
+
export declare function createRenderer(engine: Engine, options: RendererOptions): Renderer;
|
|
69
|
+
/** The renderer as an engine service. */
|
|
70
|
+
export declare function rendererPlugin(options: RendererOptions): Plugin<Engine>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { EventBus } from "../core/event-bus.js";
|
|
2
|
+
import { serviceKey } from "../core/services.js";
|
|
3
|
+
import { screenToWorld } from "../geometry/spaces.js";
|
|
4
|
+
import { InteractionKey } from "../interaction/controller.js";
|
|
5
|
+
import { referenceKernels } from "../wasm/reference.js";
|
|
6
|
+
import { DisplayListBuilder } from "./display-list.js";
|
|
7
|
+
import { ImageStore } from "./images.js";
|
|
8
|
+
import { PainterRegistry } from "./painters.js";
|
|
9
|
+
import { SceneIndex } from "./scene-index.js";
|
|
10
|
+
import { createTextMeasurer } from "./text.js";
|
|
11
|
+
import { DEFAULT_THEME, TOKEN_THEME } from "./theme.js";
|
|
12
|
+
import { StyleKey } from "../style/style-engine.js";
|
|
13
|
+
export const RendererKey = serviceKey("renderer");
|
|
14
|
+
const defaultSchedule = (run) => {
|
|
15
|
+
if (typeof requestAnimationFrame !== "undefined") {
|
|
16
|
+
const id = requestAnimationFrame(run);
|
|
17
|
+
return () => cancelAnimationFrame(id);
|
|
18
|
+
}
|
|
19
|
+
const id = setTimeout(run, 16);
|
|
20
|
+
return () => clearTimeout(id);
|
|
21
|
+
};
|
|
22
|
+
const percentile = (sorted, p) => sorted.length ? sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))] : 0;
|
|
23
|
+
export function createRenderer(engine, options) {
|
|
24
|
+
const kernels = options.kernels ?? referenceKernels;
|
|
25
|
+
const now = options.now ?? (() => (typeof performance !== "undefined" ? performance.now() : Date.now()));
|
|
26
|
+
const schedule = options.schedule ?? defaultSchedule;
|
|
27
|
+
const events = new EventBus();
|
|
28
|
+
const painters = options.painters ?? new PainterRegistry();
|
|
29
|
+
const style = options.style ?? (engine.services.has(StyleKey) ? engine.services.get(StyleKey) : undefined);
|
|
30
|
+
const withFont = (next) => style ? { ...next, fontFamily: style.tokens.resolve(next.fontFamily, style.mode()) ?? DEFAULT_THEME.fontFamily } : next;
|
|
31
|
+
let theme = withFont({ ...(style ? TOKEN_THEME : DEFAULT_THEME), ...options.theme });
|
|
32
|
+
let cancel = null;
|
|
33
|
+
let disposed = false;
|
|
34
|
+
let frameNumber = 0;
|
|
35
|
+
let lastFrame = null;
|
|
36
|
+
const times = [];
|
|
37
|
+
const reported = new Set();
|
|
38
|
+
const onUnknownColor = (css) => {
|
|
39
|
+
if (reported.has(css))
|
|
40
|
+
return;
|
|
41
|
+
reported.add(css);
|
|
42
|
+
const diagnostic = { code: "render.color", message: `Can't read the colour "${css}"; it is drawn magenta` };
|
|
43
|
+
events.emit("diagnostic", diagnostic);
|
|
44
|
+
};
|
|
45
|
+
const images = new ImageStore(options.images, () => requestFrame());
|
|
46
|
+
const index = new SceneIndex(engine.scene, kernels.createSpatialGrid(options.cellSize ?? 512));
|
|
47
|
+
const overlayOptions = () => {
|
|
48
|
+
if (options.overlay === false)
|
|
49
|
+
return false;
|
|
50
|
+
const interaction = engine.services.has(InteractionKey) ? engine.services.get(InteractionKey).options : null;
|
|
51
|
+
return {
|
|
52
|
+
transformHandles: interaction?.transformHandles ?? true,
|
|
53
|
+
handleSize: interaction?.handleSize ?? 8,
|
|
54
|
+
rotateOffset: interaction?.rotateOffset ?? 24,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const builder = new DisplayListBuilder(engine, index, {
|
|
58
|
+
theme,
|
|
59
|
+
painters,
|
|
60
|
+
measure: options.measure ?? createTextMeasurer(),
|
|
61
|
+
kernels,
|
|
62
|
+
overlay: overlayOptions(),
|
|
63
|
+
anchors: options.anchors ?? true,
|
|
64
|
+
style,
|
|
65
|
+
onUnknownColor,
|
|
66
|
+
});
|
|
67
|
+
function renderNow() {
|
|
68
|
+
if (disposed)
|
|
69
|
+
throw new Error("The renderer is disposed");
|
|
70
|
+
cancel?.();
|
|
71
|
+
cancel = null;
|
|
72
|
+
const start = now();
|
|
73
|
+
const { viewport } = engine.store.get();
|
|
74
|
+
const { camera, size, dpr } = viewport;
|
|
75
|
+
// The visible world, with a margin for strokes, handles and anchors.
|
|
76
|
+
const margin = 32;
|
|
77
|
+
const topLeft = screenToWorld(camera, { x: -margin, y: -margin });
|
|
78
|
+
const bottomRight = screenToWorld(camera, { x: size.width + margin, y: size.height + margin });
|
|
79
|
+
builder.setOverlay(overlayOptions());
|
|
80
|
+
const { commands, stats } = builder.build({ minX: topLeft.x, minY: topLeft.y, maxX: bottomRight.x, maxY: bottomRight.y }, camera.zoom);
|
|
81
|
+
const built = now();
|
|
82
|
+
const backendStats = options.backend.render({
|
|
83
|
+
camera,
|
|
84
|
+
width: size.width,
|
|
85
|
+
height: size.height,
|
|
86
|
+
dpr,
|
|
87
|
+
background: builder.color(theme.background),
|
|
88
|
+
commands,
|
|
89
|
+
images,
|
|
90
|
+
});
|
|
91
|
+
const end = now();
|
|
92
|
+
const frame = {
|
|
93
|
+
...stats,
|
|
94
|
+
gpu: backendStats,
|
|
95
|
+
frame: ++frameNumber,
|
|
96
|
+
backend: options.backend.kind,
|
|
97
|
+
buildMs: built - start,
|
|
98
|
+
drawMs: end - built,
|
|
99
|
+
totalMs: end - start,
|
|
100
|
+
};
|
|
101
|
+
lastFrame = frame;
|
|
102
|
+
times.push(frame.totalMs);
|
|
103
|
+
if (times.length > 120)
|
|
104
|
+
times.shift();
|
|
105
|
+
events.emit("frame", frame);
|
|
106
|
+
// A full text atlas is cleared: draw again to fill it.
|
|
107
|
+
if (backendStats.atlasFull)
|
|
108
|
+
requestFrame();
|
|
109
|
+
return frame;
|
|
110
|
+
}
|
|
111
|
+
function requestFrame() {
|
|
112
|
+
if (disposed || cancel)
|
|
113
|
+
return;
|
|
114
|
+
cancel = schedule(() => {
|
|
115
|
+
cancel = null;
|
|
116
|
+
if (!disposed)
|
|
117
|
+
renderNow();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const subscription = engine.store.subscribe((state) => [state.document, state.viewport, state.interaction, state.style, state.a11y], () => requestFrame(), { equals: (a, b) => a.every((value, i) => value === b[i]) });
|
|
121
|
+
requestFrame();
|
|
122
|
+
return {
|
|
123
|
+
painters,
|
|
124
|
+
images,
|
|
125
|
+
events,
|
|
126
|
+
get lastFrame() {
|
|
127
|
+
return lastFrame;
|
|
128
|
+
},
|
|
129
|
+
requestFrame,
|
|
130
|
+
renderNow,
|
|
131
|
+
setTheme(next) {
|
|
132
|
+
theme = withFont({ ...theme, ...next });
|
|
133
|
+
builder.setOptions({ theme });
|
|
134
|
+
requestFrame();
|
|
135
|
+
},
|
|
136
|
+
perf() {
|
|
137
|
+
const sorted = [...times].sort((a, b) => a - b);
|
|
138
|
+
return { frames: times.length, p50: percentile(sorted, 0.5), p95: percentile(sorted, 0.95), max: sorted.at(-1) ?? 0 };
|
|
139
|
+
},
|
|
140
|
+
dispose() {
|
|
141
|
+
if (disposed)
|
|
142
|
+
return;
|
|
143
|
+
disposed = true;
|
|
144
|
+
cancel?.();
|
|
145
|
+
subscription.dispose();
|
|
146
|
+
index.dispose();
|
|
147
|
+
images.clear();
|
|
148
|
+
events.clear();
|
|
149
|
+
options.backend.dispose();
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** The renderer as an engine service. */
|
|
154
|
+
export function rendererPlugin(options) {
|
|
155
|
+
return {
|
|
156
|
+
name: "renderer",
|
|
157
|
+
setup({ engine, track }) {
|
|
158
|
+
const renderer = track(createRenderer(engine, options));
|
|
159
|
+
track(engine.services.register(RendererKey, renderer));
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Disposable } from "../core/disposable.js";
|
|
2
|
+
import type { Bounds } from "../geometry/bounds.js";
|
|
3
|
+
import type { SceneGraph, SceneNode } from "../scene/scene-graph.js";
|
|
4
|
+
import type { SpatialGrid } from "../wasm/reference.js";
|
|
5
|
+
export declare class SceneIndex implements Disposable {
|
|
6
|
+
private readonly scene;
|
|
7
|
+
private readonly grid;
|
|
8
|
+
private slots;
|
|
9
|
+
private nodes;
|
|
10
|
+
private freeSlots;
|
|
11
|
+
/** Paint order: a node's place in the back-to-front walk. */
|
|
12
|
+
private order;
|
|
13
|
+
private readonly subscription;
|
|
14
|
+
constructor(scene: SceneGraph, grid: SpatialGrid);
|
|
15
|
+
get size(): number;
|
|
16
|
+
private put;
|
|
17
|
+
private rebuild;
|
|
18
|
+
/** Nodes whose own box meets `bounds`, back to front. */
|
|
19
|
+
query(bounds: Bounds): SceneNode[];
|
|
20
|
+
dispose(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class SceneIndex {
|
|
2
|
+
scene;
|
|
3
|
+
grid;
|
|
4
|
+
slots = new Map();
|
|
5
|
+
nodes = [];
|
|
6
|
+
freeSlots = [];
|
|
7
|
+
/** Paint order: a node's place in the back-to-front walk. */
|
|
8
|
+
order = new Map();
|
|
9
|
+
subscription;
|
|
10
|
+
constructor(scene, grid) {
|
|
11
|
+
this.scene = scene;
|
|
12
|
+
this.grid = grid;
|
|
13
|
+
this.subscription = scene.onUpdate((change) => {
|
|
14
|
+
if (change.rebuilt)
|
|
15
|
+
this.rebuild();
|
|
16
|
+
else
|
|
17
|
+
for (const node of change.touched)
|
|
18
|
+
this.put(node);
|
|
19
|
+
});
|
|
20
|
+
this.rebuild();
|
|
21
|
+
}
|
|
22
|
+
get size() {
|
|
23
|
+
return this.grid.size;
|
|
24
|
+
}
|
|
25
|
+
put(node) {
|
|
26
|
+
let slot = this.slots.get(node.id);
|
|
27
|
+
if (slot === undefined) {
|
|
28
|
+
slot = this.freeSlots.pop() ?? this.nodes.length;
|
|
29
|
+
this.slots.set(node.id, slot);
|
|
30
|
+
}
|
|
31
|
+
this.nodes[slot] = node;
|
|
32
|
+
const b = node.worldBounds;
|
|
33
|
+
this.grid.insert(slot, b.minX, b.minY, b.maxX, b.maxY);
|
|
34
|
+
}
|
|
35
|
+
rebuild() {
|
|
36
|
+
this.grid.clear();
|
|
37
|
+
this.slots.clear();
|
|
38
|
+
this.nodes = [];
|
|
39
|
+
this.freeSlots = [];
|
|
40
|
+
this.order.clear();
|
|
41
|
+
let index = 0;
|
|
42
|
+
// The walk brings the scene up to date first (it never re-enters this).
|
|
43
|
+
for (const node of this.scene.walk()) {
|
|
44
|
+
this.order.set(node.id, index++);
|
|
45
|
+
this.put(node);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Nodes whose own box meets `bounds`, back to front. */
|
|
49
|
+
query(bounds) {
|
|
50
|
+
this.scene.update();
|
|
51
|
+
const found = [];
|
|
52
|
+
for (const slot of this.grid.query(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)) {
|
|
53
|
+
const node = this.nodes[slot];
|
|
54
|
+
if (node)
|
|
55
|
+
found.push(node);
|
|
56
|
+
}
|
|
57
|
+
return found.sort((a, b) => (this.order.get(a.id) ?? 0) - (this.order.get(b.id) ?? 0));
|
|
58
|
+
}
|
|
59
|
+
dispose() {
|
|
60
|
+
this.subscription.dispose();
|
|
61
|
+
this.grid.clear();
|
|
62
|
+
this.grid.free?.();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FontSpec } from "./commands.js";
|
|
2
|
+
export type TextMeasurer = (text: string, font: FontSpec) => number;
|
|
3
|
+
export declare function createTextMeasurer(): TextMeasurer;
|
|
4
|
+
/**
|
|
5
|
+
* Lines that fit `width` (words wrap; a word too long is cut), at most
|
|
6
|
+
* `maxLines`; the last one ends with "…" when text is left over.
|
|
7
|
+
*/
|
|
8
|
+
export declare function layoutLines(text: string, font: FontSpec, width: number, maxLines: number, measure: TextMeasurer): string[];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Text measuring and line breaking, shared by every backend so they place
|
|
3
|
+
* the same lines. Measuring uses a 2D canvas when there is one; in Node it
|
|
4
|
+
* estimates (0.55 em a character), which tests rely on.
|
|
5
|
+
*/
|
|
6
|
+
import { fontString } from "./commands.js";
|
|
7
|
+
export function createTextMeasurer() {
|
|
8
|
+
let context = null;
|
|
9
|
+
try {
|
|
10
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
11
|
+
context = new OffscreenCanvas(1, 1).getContext("2d");
|
|
12
|
+
}
|
|
13
|
+
else if (typeof document !== "undefined") {
|
|
14
|
+
context = document.createElement("canvas").getContext("2d");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
context = null;
|
|
19
|
+
}
|
|
20
|
+
const cache = new Map();
|
|
21
|
+
return (text, font) => {
|
|
22
|
+
const key = `${fontString(font)}|${text}`;
|
|
23
|
+
let width = cache.get(key);
|
|
24
|
+
if (width === undefined) {
|
|
25
|
+
if (context) {
|
|
26
|
+
context.font = fontString(font);
|
|
27
|
+
width = context.measureText(text).width;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
width = text.length * font.size * 0.55;
|
|
31
|
+
}
|
|
32
|
+
if (cache.size > 5000)
|
|
33
|
+
cache.clear();
|
|
34
|
+
cache.set(key, width);
|
|
35
|
+
}
|
|
36
|
+
return width;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Lines that fit `width` (words wrap; a word too long is cut), at most
|
|
41
|
+
* `maxLines`; the last one ends with "…" when text is left over.
|
|
42
|
+
*/
|
|
43
|
+
export function layoutLines(text, font, width, maxLines, measure) {
|
|
44
|
+
const lines = [];
|
|
45
|
+
const fits = (value) => measure(value, font) <= width;
|
|
46
|
+
let truncated = false;
|
|
47
|
+
const push = (line) => {
|
|
48
|
+
if (lines.length >= maxLines) {
|
|
49
|
+
truncated = true;
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
lines.push(line.trimEnd());
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
for (const paragraph of text.split("\n")) {
|
|
56
|
+
let line = "";
|
|
57
|
+
for (const token of paragraph.split(/(\s+)/).filter(Boolean)) {
|
|
58
|
+
if (fits(line + token)) {
|
|
59
|
+
line += token;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (/^\s+$/.test(token)) {
|
|
63
|
+
if (!push(line))
|
|
64
|
+
return finish();
|
|
65
|
+
line = "";
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (line.trim()) {
|
|
69
|
+
if (!push(line))
|
|
70
|
+
return finish();
|
|
71
|
+
line = "";
|
|
72
|
+
}
|
|
73
|
+
if (fits(token)) {
|
|
74
|
+
line = token;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// One word wider than the box: cut it by characters.
|
|
78
|
+
for (const char of token) {
|
|
79
|
+
if (line && !fits(line + char)) {
|
|
80
|
+
if (!push(line))
|
|
81
|
+
return finish();
|
|
82
|
+
line = "";
|
|
83
|
+
}
|
|
84
|
+
line += char;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!push(line))
|
|
88
|
+
return finish();
|
|
89
|
+
}
|
|
90
|
+
return finish();
|
|
91
|
+
function finish() {
|
|
92
|
+
if (truncated && lines.length) {
|
|
93
|
+
let last = lines[lines.length - 1];
|
|
94
|
+
while (last && !fits(last + "…"))
|
|
95
|
+
last = last.slice(0, -1);
|
|
96
|
+
lines[lines.length - 1] = last.trimEnd() + "…";
|
|
97
|
+
}
|
|
98
|
+
return lines;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type RenderTheme = {
|
|
2
|
+
background: string;
|
|
3
|
+
nodeFill: string;
|
|
4
|
+
nodeStroke: string;
|
|
5
|
+
text: string;
|
|
6
|
+
mutedText: string;
|
|
7
|
+
/** Selection, hover, handles and the marquee (--ring). */
|
|
8
|
+
accent: string;
|
|
9
|
+
relation: string;
|
|
10
|
+
relationSelected: string;
|
|
11
|
+
anchorFill: string;
|
|
12
|
+
anchorStroke: string;
|
|
13
|
+
frameFill: string;
|
|
14
|
+
frameStroke: string;
|
|
15
|
+
/** A refused connection, an unknown node type. */
|
|
16
|
+
invalid: string;
|
|
17
|
+
fontFamily: string;
|
|
18
|
+
};
|
|
19
|
+
/** The theme through the design tokens (with a styling engine, in its mode). */
|
|
20
|
+
export declare const TOKEN_THEME: RenderTheme;
|
|
21
|
+
export declare const DEFAULT_THEME: RenderTheme;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The theme through the design tokens (with a styling engine, in its mode). */
|
|
2
|
+
export const TOKEN_THEME = {
|
|
3
|
+
background: "var(--color-background)",
|
|
4
|
+
nodeFill: "var(--color-card)",
|
|
5
|
+
nodeStroke: "var(--color-border)",
|
|
6
|
+
text: "var(--color-foreground)",
|
|
7
|
+
mutedText: "var(--color-muted-foreground)",
|
|
8
|
+
accent: "var(--color-ring)",
|
|
9
|
+
relation: "var(--color-muted-foreground)",
|
|
10
|
+
relationSelected: "var(--color-foreground)",
|
|
11
|
+
anchorFill: "var(--color-foreground)",
|
|
12
|
+
anchorStroke: "var(--color-background)",
|
|
13
|
+
frameFill: "color-mix(in srgb, var(--color-muted) 60%, transparent)",
|
|
14
|
+
frameStroke: "var(--color-border)",
|
|
15
|
+
invalid: "var(--color-destructive)",
|
|
16
|
+
fontFamily: "var(--font-sans)",
|
|
17
|
+
};
|
|
18
|
+
export const DEFAULT_THEME = {
|
|
19
|
+
background: "#f5f5f5",
|
|
20
|
+
nodeFill: "#ffffff",
|
|
21
|
+
nodeStroke: "#e6e6e6",
|
|
22
|
+
text: "#1a1a1a",
|
|
23
|
+
mutedText: "#737373",
|
|
24
|
+
accent: "#0d99ff",
|
|
25
|
+
relation: "#b1b1b7",
|
|
26
|
+
relationSelected: "#555555",
|
|
27
|
+
anchorFill: "#1a1a1a",
|
|
28
|
+
anchorStroke: "#ffffff",
|
|
29
|
+
frameFill: "rgba(0, 0, 0, 0.03)",
|
|
30
|
+
frameStroke: "#e6e6e6",
|
|
31
|
+
invalid: "#ef4444",
|
|
32
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
33
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type LayoutBox } from "../layout/layout.js";
|
|
2
|
+
import type { Size } from "../scene/record.js";
|
|
3
|
+
import type { ComputedStyle, ElementState } from "../style/computed.js";
|
|
4
|
+
import type { StyleEngine } from "../style/style-engine.js";
|
|
5
|
+
import type { NodePainter } from "./painters.js";
|
|
6
|
+
import { type TextMeasurer } from "./text.js";
|
|
7
|
+
/** An element of a styled node: classes, text or children, and state. */
|
|
8
|
+
export type UIElement = {
|
|
9
|
+
className?: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
/** Explicit style, above the classes (spec §4.7). */
|
|
12
|
+
style?: Partial<ComputedStyle>;
|
|
13
|
+
/** data-* attributes for `data-[…]:` variants. */
|
|
14
|
+
data?: Record<string, string | boolean>;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** A name for the part (Root, Header, Label…). */
|
|
17
|
+
slot?: string;
|
|
18
|
+
/** An ARIA role: the DOM layer gives the element a real control (button…). */
|
|
19
|
+
role?: string;
|
|
20
|
+
/** Its accessible name, when its text isn't one. */
|
|
21
|
+
ariaLabel?: string;
|
|
22
|
+
/** What activating it does: sent as `control:activate` with this id. */
|
|
23
|
+
action?: string;
|
|
24
|
+
children?: UIElement[];
|
|
25
|
+
};
|
|
26
|
+
export declare const uiType: import("../index.js").NodeType<{
|
|
27
|
+
root: UIElement;
|
|
28
|
+
}>;
|
|
29
|
+
/** The node's state, as the Behavior Engine sees it. */
|
|
30
|
+
export type NodeVisualState = {
|
|
31
|
+
hovered: boolean;
|
|
32
|
+
selected: boolean;
|
|
33
|
+
dragging: boolean;
|
|
34
|
+
focused: boolean;
|
|
35
|
+
/** The app's own states (store `style.nodeStates`): disabled, open, active… */
|
|
36
|
+
states: readonly string[];
|
|
37
|
+
};
|
|
38
|
+
type Styled = {
|
|
39
|
+
element: UIElement;
|
|
40
|
+
style: ComputedStyle;
|
|
41
|
+
children: Styled[];
|
|
42
|
+
lines?: string[];
|
|
43
|
+
};
|
|
44
|
+
/** The element's style state from the node's. */
|
|
45
|
+
export declare function elementState(element: UIElement, node: NodeVisualState, isRoot: boolean): ElementState;
|
|
46
|
+
/** Styles and lays out a ui node's tree; also used by tests and the DOM layer. */
|
|
47
|
+
export declare function layoutUI(root: UIElement, size: Size, node: NodeVisualState, style: StyleEngine, measure: TextMeasurer): {
|
|
48
|
+
tree: Styled;
|
|
49
|
+
box: LayoutBox;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The deepest element with a role or an action under a point in the node's
|
|
53
|
+
* own space (a click on a button drawn on the canvas), with its tree path.
|
|
54
|
+
*/
|
|
55
|
+
export declare function elementAt(root: UIElement, size: Size, node: NodeVisualState, style: StyleEngine, measure: TextMeasurer, point: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
}): {
|
|
59
|
+
element: UIElement;
|
|
60
|
+
path: number[];
|
|
61
|
+
} | null;
|
|
62
|
+
export declare const uiPainter: NodePainter;
|
|
63
|
+
export {};
|