@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,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Styled nodes (the Phase 4 deliverable): a "ui" node holds a tree of
|
|
3
|
+
* elements with Tailwind-like classes, drawn on the GPU. The styling engine
|
|
4
|
+
* computes each element's style from its classes, the node's state
|
|
5
|
+
* (hover, selected, dragging, focus, the app's extra states) and the theme
|
|
6
|
+
* mode; the layout engine places them inside the node's box; this painter
|
|
7
|
+
* turns them into shadows, boxes, rings and text runs.
|
|
8
|
+
*/
|
|
9
|
+
import { translated } from "../geometry/matrix.js";
|
|
10
|
+
import { layout } from "../layout/layout.js";
|
|
11
|
+
import { defineNodeType } from "../scene/schema.js";
|
|
12
|
+
import { withAlpha } from "./color.js";
|
|
13
|
+
import { layoutLines } from "./text.js";
|
|
14
|
+
export const uiType = defineNodeType({
|
|
15
|
+
type: "ui",
|
|
16
|
+
version: 1,
|
|
17
|
+
defaults: () => ({ root: { className: "" } }),
|
|
18
|
+
validate: (props) => props.root && typeof props.root === "object"
|
|
19
|
+
? []
|
|
20
|
+
: [{ code: "ui.root", level: "error", message: "A ui node needs a root element", source: "ui" }],
|
|
21
|
+
});
|
|
22
|
+
const fontOf = (style) => ({ family: style.fontFamily, size: style.fontSize, weight: style.fontWeight });
|
|
23
|
+
function textMeasure(styled, measure) {
|
|
24
|
+
const { style } = styled;
|
|
25
|
+
const font = fontOf(style);
|
|
26
|
+
const text = styled.element.text ?? "";
|
|
27
|
+
return (maxWidth) => {
|
|
28
|
+
const maxLines = style.truncate ? 1 : style.lineClamp || 1000;
|
|
29
|
+
const width = style.truncate || style.lineClamp ? maxWidth : Math.max(maxWidth, 1);
|
|
30
|
+
const lines = style.truncate && measure(text, font) <= maxWidth ? [text] : layoutLines(text, font, width, maxLines, measure);
|
|
31
|
+
styled.lines = lines;
|
|
32
|
+
const widest = Math.max(0, ...lines.map((line) => measure(line, font) + style.letterSpacing * line.length));
|
|
33
|
+
return { w: Math.min(widest, maxWidth), h: lines.length * style.lineHeight };
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The element's style state from the node's. */
|
|
37
|
+
export function elementState(element, node, isRoot) {
|
|
38
|
+
const disabled = element.disabled || node.states.includes("disabled");
|
|
39
|
+
const group = {
|
|
40
|
+
hover: node.hovered,
|
|
41
|
+
focus: node.focused,
|
|
42
|
+
focusVisible: node.focused,
|
|
43
|
+
active: node.dragging || node.states.includes("active"),
|
|
44
|
+
disabled,
|
|
45
|
+
data: {
|
|
46
|
+
selected: node.selected ? "true" : undefined,
|
|
47
|
+
dragging: node.dragging ? "true" : undefined,
|
|
48
|
+
...Object.fromEntries(node.states.map((state) => [state, "true"])),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return isRoot
|
|
52
|
+
? { ...group, data: { ...group.data, ...element.data }, group }
|
|
53
|
+
: { disabled, data: element.data, group };
|
|
54
|
+
}
|
|
55
|
+
/** Styles and lays out a ui node's tree; also used by tests and the DOM layer. */
|
|
56
|
+
export function layoutUI(root, size, node, style, measure) {
|
|
57
|
+
const build = (element, parent, isRoot) => {
|
|
58
|
+
const computed = style.compute(element.className ?? "", elementState(element, node, isRoot), {
|
|
59
|
+
parent,
|
|
60
|
+
style: element.style,
|
|
61
|
+
});
|
|
62
|
+
const styled = { element, style: computed, children: [] };
|
|
63
|
+
styled.children = (element.children ?? []).map((child) => build(child, computed, false));
|
|
64
|
+
return styled;
|
|
65
|
+
};
|
|
66
|
+
const tree = build(root, null, true);
|
|
67
|
+
const toLayout = (styled) => ({
|
|
68
|
+
style: styled.style,
|
|
69
|
+
children: styled.children.map(toLayout),
|
|
70
|
+
measure: styled.element.text !== undefined && !styled.children.length ? textMeasure(styled, measure) : undefined,
|
|
71
|
+
});
|
|
72
|
+
const box = layout(toLayout(tree), size.w, size.h);
|
|
73
|
+
return { tree, box };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The deepest element with a role or an action under a point in the node's
|
|
77
|
+
* own space (a click on a button drawn on the canvas), with its tree path.
|
|
78
|
+
*/
|
|
79
|
+
export function elementAt(root, size, node, style, measure, point) {
|
|
80
|
+
const { tree, box } = layoutUI(root, size, node, style, measure);
|
|
81
|
+
let found = null;
|
|
82
|
+
const visit = (styled, b, x, y, path) => {
|
|
83
|
+
const ax = x + b.x;
|
|
84
|
+
const ay = y + b.y;
|
|
85
|
+
if (point.x < ax || point.y < ay || point.x > ax + b.w || point.y > ay + b.h)
|
|
86
|
+
return;
|
|
87
|
+
if (styled.element.role || styled.element.action)
|
|
88
|
+
found = { element: styled.element, path };
|
|
89
|
+
styled.children.forEach((child, i) => visit(child, b.children[i], ax, ay, [...path, i]));
|
|
90
|
+
};
|
|
91
|
+
visit(tree, box, 0, 0, []);
|
|
92
|
+
return found;
|
|
93
|
+
}
|
|
94
|
+
function paintStyled(node, styled, box, x, y, opacity, out, measure) {
|
|
95
|
+
const { style } = styled;
|
|
96
|
+
if (style.display === "none")
|
|
97
|
+
return;
|
|
98
|
+
const alpha = opacity * style.opacity;
|
|
99
|
+
const ax = x + box.x;
|
|
100
|
+
const ay = y + box.y;
|
|
101
|
+
const matrix = translated(node.world, ax, ay);
|
|
102
|
+
for (const shadow of style.shadows) {
|
|
103
|
+
if (shadow.inset)
|
|
104
|
+
continue;
|
|
105
|
+
out.push({
|
|
106
|
+
kind: "shadow",
|
|
107
|
+
matrix,
|
|
108
|
+
w: box.w,
|
|
109
|
+
h: box.h,
|
|
110
|
+
radius: style.radius,
|
|
111
|
+
x: shadow.x,
|
|
112
|
+
y: shadow.y,
|
|
113
|
+
blur: shadow.blur,
|
|
114
|
+
spread: shadow.spread,
|
|
115
|
+
color: withAlpha(shadow.color, alpha),
|
|
116
|
+
nodeId: node.id,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (style.ring) {
|
|
120
|
+
const r = style.ring.width;
|
|
121
|
+
out.push({
|
|
122
|
+
kind: "rect",
|
|
123
|
+
matrix: translated(node.world, ax - r, ay - r),
|
|
124
|
+
w: box.w + 2 * r,
|
|
125
|
+
h: box.h + 2 * r,
|
|
126
|
+
radius: style.radius + r,
|
|
127
|
+
fill: null,
|
|
128
|
+
stroke: withAlpha(style.ring.color, alpha),
|
|
129
|
+
strokeWidth: r,
|
|
130
|
+
nodeId: node.id,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if ((style.background && style.background[3] > 0) || style.borderWidth > 0) {
|
|
134
|
+
out.push({
|
|
135
|
+
kind: "rect",
|
|
136
|
+
matrix,
|
|
137
|
+
w: box.w,
|
|
138
|
+
h: box.h,
|
|
139
|
+
radius: style.radius,
|
|
140
|
+
fill: style.background ? withAlpha(style.background, alpha) : null,
|
|
141
|
+
stroke: style.borderWidth > 0 ? withAlpha(style.borderColor, alpha) : null,
|
|
142
|
+
strokeWidth: style.borderWidth,
|
|
143
|
+
nodeId: node.id,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (styled.lines && styled.element.text) {
|
|
147
|
+
const font = fontOf(style);
|
|
148
|
+
const left = style.padding[3] + style.borderWidth;
|
|
149
|
+
const inner = box.w - left - style.padding[1] - style.borderWidth;
|
|
150
|
+
styled.lines.forEach((line, i) => {
|
|
151
|
+
const width = measure(line, font) + style.letterSpacing * line.length;
|
|
152
|
+
const offset = style.textAlign === "center" ? (inner - width) / 2 : style.textAlign === "right" ? inner - width : 0;
|
|
153
|
+
out.push({
|
|
154
|
+
kind: "text",
|
|
155
|
+
matrix,
|
|
156
|
+
x: left + offset,
|
|
157
|
+
y: style.padding[0] + style.borderWidth + i * style.lineHeight,
|
|
158
|
+
text: line,
|
|
159
|
+
font,
|
|
160
|
+
lineHeight: style.lineHeight,
|
|
161
|
+
color: withAlpha(style.color, alpha),
|
|
162
|
+
letterSpacing: style.letterSpacing || undefined,
|
|
163
|
+
nodeId: node.id,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
styled.children.forEach((child, i) => paintStyled(node, child, box.children[i], ax, ay, alpha, out, measure));
|
|
168
|
+
}
|
|
169
|
+
export const uiPainter = (node, size, out, ctx) => {
|
|
170
|
+
const root = node.record.props.root;
|
|
171
|
+
if (!ctx.style || !root) {
|
|
172
|
+
// No styling engine: a plain card, so the node still shows.
|
|
173
|
+
out.push({
|
|
174
|
+
kind: "rect",
|
|
175
|
+
matrix: node.world,
|
|
176
|
+
w: size.w,
|
|
177
|
+
h: size.h,
|
|
178
|
+
radius: 8,
|
|
179
|
+
fill: ctx.color(ctx.theme.nodeFill),
|
|
180
|
+
stroke: ctx.color(ctx.theme.nodeStroke),
|
|
181
|
+
strokeWidth: 1,
|
|
182
|
+
nodeId: node.id,
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const { tree, box } = layoutUI(root, size, ctx.state, ctx.style, ctx.measure);
|
|
187
|
+
paintStyled(node, tree, box, 0, 0, 1, out, ctx.measure);
|
|
188
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type TextCommand } from "../commands.js";
|
|
2
|
+
export type AtlasRegion = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
w: number;
|
|
6
|
+
h: number;
|
|
7
|
+
scale: number;
|
|
8
|
+
};
|
|
9
|
+
type Raster = {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
getContext(kind: "2d"): unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare const ATLAS_SIZE = 2048;
|
|
15
|
+
/** Device scale in steps of √2, so zooming reuses runs. */
|
|
16
|
+
export declare const scaleStep: (scale: number) => number;
|
|
17
|
+
export declare class TextAtlas {
|
|
18
|
+
private regions;
|
|
19
|
+
private shelves;
|
|
20
|
+
private top;
|
|
21
|
+
private readonly raster;
|
|
22
|
+
private readonly context;
|
|
23
|
+
/** Bumps when the page is cleared (the texture must be cleared too). */
|
|
24
|
+
generation: number;
|
|
25
|
+
constructor(createRaster: (w: number, h: number) => Raster);
|
|
26
|
+
get size(): number;
|
|
27
|
+
clear(): void;
|
|
28
|
+
private allocate;
|
|
29
|
+
/**
|
|
30
|
+
* The run's region; `upload` puts newly drawn pixels into the texture.
|
|
31
|
+
* Null when the page is full (clear it and try again next frame).
|
|
32
|
+
*/
|
|
33
|
+
get(command: TextCommand, deviceScale: number, upload: (source: Raster, x: number, y: number, w: number, h: number) => void): AtlasRegion | null;
|
|
34
|
+
}
|
|
35
|
+
export declare const ATLAS_PAD = 2;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Text runs rasterized by the browser (so shaping, hinting and fonts are
|
|
3
|
+
* its own) into one texture page, packed in shelves. Runs are cached by
|
|
4
|
+
* text, font and device scale; a full page is cleared and refilled.
|
|
5
|
+
*/
|
|
6
|
+
import { fontString } from "../commands.js";
|
|
7
|
+
export const ATLAS_SIZE = 2048;
|
|
8
|
+
const PAD = 2;
|
|
9
|
+
/** Device scale in steps of √2, so zooming reuses runs. */
|
|
10
|
+
export const scaleStep = (scale) => {
|
|
11
|
+
const step = Math.round(Math.log2(Math.max(0.125, Math.min(16, scale))) * 2) / 2;
|
|
12
|
+
return 2 ** step;
|
|
13
|
+
};
|
|
14
|
+
export class TextAtlas {
|
|
15
|
+
regions = new Map();
|
|
16
|
+
shelves = [];
|
|
17
|
+
top = 0;
|
|
18
|
+
raster;
|
|
19
|
+
context;
|
|
20
|
+
/** Bumps when the page is cleared (the texture must be cleared too). */
|
|
21
|
+
generation = 0;
|
|
22
|
+
constructor(createRaster) {
|
|
23
|
+
this.raster = createRaster(256, 64);
|
|
24
|
+
const context = this.raster.getContext("2d");
|
|
25
|
+
if (!context)
|
|
26
|
+
throw new Error("No 2D context for text");
|
|
27
|
+
this.context = context;
|
|
28
|
+
}
|
|
29
|
+
get size() {
|
|
30
|
+
return this.regions.size;
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.regions.clear();
|
|
34
|
+
this.shelves = [];
|
|
35
|
+
this.top = 0;
|
|
36
|
+
this.generation++;
|
|
37
|
+
}
|
|
38
|
+
allocate(w, h) {
|
|
39
|
+
if (w > ATLAS_SIZE || h > ATLAS_SIZE)
|
|
40
|
+
return null;
|
|
41
|
+
for (const shelf of this.shelves) {
|
|
42
|
+
if (h <= shelf.h && shelf.x + w <= ATLAS_SIZE) {
|
|
43
|
+
const at = { x: shelf.x, y: shelf.y };
|
|
44
|
+
shelf.x += w;
|
|
45
|
+
return at;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (this.top + h > ATLAS_SIZE)
|
|
49
|
+
return null;
|
|
50
|
+
const shelf = { y: this.top, h, x: w };
|
|
51
|
+
this.shelves.push(shelf);
|
|
52
|
+
this.top += h;
|
|
53
|
+
return { x: 0, y: shelf.y };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The run's region; `upload` puts newly drawn pixels into the texture.
|
|
57
|
+
* Null when the page is full (clear it and try again next frame).
|
|
58
|
+
*/
|
|
59
|
+
get(command, deviceScale, upload) {
|
|
60
|
+
const scale = scaleStep(deviceScale);
|
|
61
|
+
const font = fontString(command.font, scale);
|
|
62
|
+
const spacing = (command.letterSpacing ?? 0) * scale;
|
|
63
|
+
const key = `${scale}|${font}|${spacing}|${command.text}`;
|
|
64
|
+
const cached = this.regions.get(key);
|
|
65
|
+
if (cached)
|
|
66
|
+
return cached;
|
|
67
|
+
const ctx = this.context;
|
|
68
|
+
ctx.font = font;
|
|
69
|
+
if ("letterSpacing" in ctx)
|
|
70
|
+
ctx.letterSpacing = `${spacing}px`;
|
|
71
|
+
const w = Math.ceil(ctx.measureText(command.text).width) + PAD * 2;
|
|
72
|
+
const h = Math.ceil(command.lineHeight * scale) + PAD * 2;
|
|
73
|
+
const at = this.allocate(w, h);
|
|
74
|
+
if (!at)
|
|
75
|
+
return null;
|
|
76
|
+
if (this.raster.width < w || this.raster.height < h) {
|
|
77
|
+
this.raster.width = Math.max(this.raster.width, w);
|
|
78
|
+
this.raster.height = Math.max(this.raster.height, h);
|
|
79
|
+
}
|
|
80
|
+
ctx.clearRect(0, 0, this.raster.width, this.raster.height);
|
|
81
|
+
ctx.font = font;
|
|
82
|
+
if ("letterSpacing" in ctx)
|
|
83
|
+
ctx.letterSpacing = `${spacing}px`;
|
|
84
|
+
ctx.textBaseline = "middle";
|
|
85
|
+
ctx.fillStyle = "#ffffff";
|
|
86
|
+
ctx.fillText(command.text, PAD, PAD + (command.lineHeight * scale) / 2);
|
|
87
|
+
upload(this.raster, at.x, at.y, w, h);
|
|
88
|
+
const region = { x: at.x, y: at.y, w, h, scale };
|
|
89
|
+
this.regions.set(key, region);
|
|
90
|
+
return region;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export const ATLAS_PAD = PAD;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RenderBackend } from "../backend.js";
|
|
2
|
+
export type WebGL2Target = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
getContext(kind: "webgl2", options?: WebGLContextAttributes): unknown;
|
|
6
|
+
addEventListener?(type: string, listener: (event: Event) => void): void;
|
|
7
|
+
removeEventListener?(type: string, listener: (event: Event) => void): void;
|
|
8
|
+
};
|
|
9
|
+
export type WebGL2Options = {
|
|
10
|
+
/** Keeps the picture readable after the frame (tests, screenshots). */
|
|
11
|
+
preserveDrawingBuffer?: boolean;
|
|
12
|
+
/** A 2D canvas to rasterize text runs into (defaults to OffscreenCanvas or a DOM canvas). */
|
|
13
|
+
createRaster?: (w: number, h: number) => {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
getContext(kind: "2d"): unknown;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function createWebGL2Backend(canvas: WebGL2Target, options?: WebGL2Options): RenderBackend;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The WebGL2 backend (spec §5.1, the first GPU backend). Commands become
|
|
3
|
+
* draw batches in paint order:
|
|
4
|
+
* - boxes, images and text share one instanced quad program; a batch only
|
|
5
|
+
* breaks when an image or text needs another texture than the batch's
|
|
6
|
+
* (boxes take whatever is bound);
|
|
7
|
+
* - curves' triangles share one mesh buffer, a draw per run of meshes.
|
|
8
|
+
* All instance and vertex data goes up in one upload per frame. Matrices
|
|
9
|
+
* are applied on the CPU in device px, so large world coordinates keep
|
|
10
|
+
* their precision in float32.
|
|
11
|
+
*/
|
|
12
|
+
import { toDevice } from "../backend.js";
|
|
13
|
+
import { fitImage } from "../images.js";
|
|
14
|
+
import { ATLAS_PAD, ATLAS_SIZE, TextAtlas } from "./atlas.js";
|
|
15
|
+
import { MESH_FRAGMENT, MESH_VERTEX, QUAD_FLOATS, QUAD_FRAGMENT, QUAD_VERTEX } from "./shaders.js";
|
|
16
|
+
const defaultRaster = (w, h) => {
|
|
17
|
+
if (typeof OffscreenCanvas !== "undefined")
|
|
18
|
+
return new OffscreenCanvas(w, h);
|
|
19
|
+
const canvas = document.createElement("canvas");
|
|
20
|
+
canvas.width = w;
|
|
21
|
+
canvas.height = h;
|
|
22
|
+
return canvas;
|
|
23
|
+
};
|
|
24
|
+
function compile(gl, vertex, fragment) {
|
|
25
|
+
const program = gl.createProgram();
|
|
26
|
+
for (const [type, source] of [
|
|
27
|
+
[gl.VERTEX_SHADER, vertex],
|
|
28
|
+
[gl.FRAGMENT_SHADER, fragment],
|
|
29
|
+
]) {
|
|
30
|
+
const shader = gl.createShader(type);
|
|
31
|
+
gl.shaderSource(shader, source);
|
|
32
|
+
gl.compileShader(shader);
|
|
33
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
34
|
+
throw new Error(`Shader: ${gl.getShaderInfoLog(shader)}`);
|
|
35
|
+
}
|
|
36
|
+
gl.attachShader(program, shader);
|
|
37
|
+
}
|
|
38
|
+
gl.linkProgram(program);
|
|
39
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
40
|
+
throw new Error(`Program: ${gl.getProgramInfoLog(program)}`);
|
|
41
|
+
}
|
|
42
|
+
return program;
|
|
43
|
+
}
|
|
44
|
+
/** Grows a float buffer, keeping its contents. */
|
|
45
|
+
function grow(buffer, needed) {
|
|
46
|
+
if (buffer.length >= needed)
|
|
47
|
+
return buffer;
|
|
48
|
+
const next = new Float32Array(Math.max(needed, buffer.length * 2));
|
|
49
|
+
next.set(buffer);
|
|
50
|
+
return next;
|
|
51
|
+
}
|
|
52
|
+
export function createWebGL2Backend(canvas, options = {}) {
|
|
53
|
+
const gl = canvas.getContext("webgl2", {
|
|
54
|
+
antialias: true,
|
|
55
|
+
premultipliedAlpha: true,
|
|
56
|
+
alpha: false,
|
|
57
|
+
preserveDrawingBuffer: options.preserveDrawingBuffer ?? false,
|
|
58
|
+
});
|
|
59
|
+
if (!gl)
|
|
60
|
+
throw new Error("WebGL2 isn't available");
|
|
61
|
+
let lost = false;
|
|
62
|
+
let resources = setup(gl);
|
|
63
|
+
const atlas = new TextAtlas(options.createRaster ?? defaultRaster);
|
|
64
|
+
let atlasGeneration = -1;
|
|
65
|
+
const textures = new WeakMap();
|
|
66
|
+
let quads = new Float32Array(QUAD_FLOATS * 1024);
|
|
67
|
+
let meshes = new Float32Array(6 * 4096);
|
|
68
|
+
const onLost = (event) => {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
lost = true;
|
|
71
|
+
};
|
|
72
|
+
const onRestored = () => {
|
|
73
|
+
resources = setup(gl);
|
|
74
|
+
atlas.clear();
|
|
75
|
+
atlasGeneration = -1;
|
|
76
|
+
lost = false;
|
|
77
|
+
};
|
|
78
|
+
canvas.addEventListener?.("webglcontextlost", onLost);
|
|
79
|
+
canvas.addEventListener?.("webglcontextrestored", onRestored);
|
|
80
|
+
function setup(gl) {
|
|
81
|
+
const quad = compile(gl, QUAD_VERTEX, QUAD_FRAGMENT);
|
|
82
|
+
const mesh = compile(gl, MESH_VERTEX, MESH_FRAGMENT);
|
|
83
|
+
const quadVao = gl.createVertexArray();
|
|
84
|
+
gl.bindVertexArray(quadVao);
|
|
85
|
+
const corners = gl.createBuffer();
|
|
86
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, corners);
|
|
87
|
+
gl.bufferData(gl.ARRAY_BUFFER, Float32Array.of(0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1), gl.STATIC_DRAW);
|
|
88
|
+
gl.enableVertexAttribArray(0);
|
|
89
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
90
|
+
const instances = gl.createBuffer();
|
|
91
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, instances);
|
|
92
|
+
for (let i = 1; i <= 7; i++) {
|
|
93
|
+
gl.enableVertexAttribArray(i);
|
|
94
|
+
gl.vertexAttribDivisor(i, 1);
|
|
95
|
+
}
|
|
96
|
+
const meshVao = gl.createVertexArray();
|
|
97
|
+
gl.bindVertexArray(meshVao);
|
|
98
|
+
const vertices = gl.createBuffer();
|
|
99
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertices);
|
|
100
|
+
gl.enableVertexAttribArray(0);
|
|
101
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 24, 0);
|
|
102
|
+
gl.enableVertexAttribArray(1);
|
|
103
|
+
gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 24, 8);
|
|
104
|
+
gl.bindVertexArray(null);
|
|
105
|
+
const atlasTexture = gl.createTexture();
|
|
106
|
+
gl.bindTexture(gl.TEXTURE_2D, atlasTexture);
|
|
107
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, ATLAS_SIZE, ATLAS_SIZE);
|
|
108
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
109
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
110
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
111
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
112
|
+
return {
|
|
113
|
+
quad,
|
|
114
|
+
mesh,
|
|
115
|
+
quadVao,
|
|
116
|
+
meshVao,
|
|
117
|
+
instances,
|
|
118
|
+
vertices,
|
|
119
|
+
atlasTexture,
|
|
120
|
+
quadResolution: gl.getUniformLocation(quad, "u_resolution"),
|
|
121
|
+
quadTexture: gl.getUniformLocation(quad, "u_texture"),
|
|
122
|
+
meshResolution: gl.getUniformLocation(mesh, "u_resolution"),
|
|
123
|
+
meshCamera: gl.getUniformLocation(mesh, "u_camera"),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const clearAtlasTexture = () => {
|
|
127
|
+
gl.bindTexture(gl.TEXTURE_2D, resources.atlasTexture);
|
|
128
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, ATLAS_SIZE, ATLAS_SIZE, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(ATLAS_SIZE * ATLAS_SIZE * 4));
|
|
129
|
+
};
|
|
130
|
+
const textureOf = (image) => {
|
|
131
|
+
const key = image.source;
|
|
132
|
+
let texture = textures.get(key);
|
|
133
|
+
if (texture)
|
|
134
|
+
return texture;
|
|
135
|
+
texture = gl.createTexture();
|
|
136
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
137
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
138
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image.source);
|
|
139
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
140
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
141
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
142
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
143
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
144
|
+
textures.set(key, texture);
|
|
145
|
+
return texture;
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
kind: "webgl2",
|
|
149
|
+
render(frame) {
|
|
150
|
+
if (lost || gl.isContextLost())
|
|
151
|
+
return { drawCalls: 0, lost: 1 };
|
|
152
|
+
const width = Math.round(frame.width * frame.dpr);
|
|
153
|
+
const height = Math.round(frame.height * frame.dpr);
|
|
154
|
+
if (canvas.width !== width)
|
|
155
|
+
canvas.width = width;
|
|
156
|
+
if (canvas.height !== height)
|
|
157
|
+
canvas.height = height;
|
|
158
|
+
if (atlasGeneration !== atlas.generation) {
|
|
159
|
+
clearAtlasTexture();
|
|
160
|
+
atlasGeneration = atlas.generation;
|
|
161
|
+
}
|
|
162
|
+
// 1. Commands → instance and vertex data, and draw ops in order.
|
|
163
|
+
const ops = [];
|
|
164
|
+
let quadCount = 0;
|
|
165
|
+
let meshFloats = 0;
|
|
166
|
+
let atlasFull = false;
|
|
167
|
+
const FULL = [0, 0, 1, 1];
|
|
168
|
+
const pushQuad = (m, ox, oy, w, h, radius, strokeWidth, fill, stroke, uv, mode, texture, margin = 0) => {
|
|
169
|
+
// Boxes join any quad batch; a texture joins one with no texture
|
|
170
|
+
// yet or the same one.
|
|
171
|
+
const last = ops[ops.length - 1];
|
|
172
|
+
if (last?.type === "quad" && (texture === null || last.texture === null || last.texture === texture)) {
|
|
173
|
+
if (texture)
|
|
174
|
+
last.texture = texture;
|
|
175
|
+
last.count++;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
ops.push({ type: "quad", texture, first: quadCount, count: 1 });
|
|
179
|
+
}
|
|
180
|
+
quads = grow(quads, (quadCount + 1) * QUAD_FLOATS);
|
|
181
|
+
const o = quadCount * QUAD_FLOATS;
|
|
182
|
+
quads[o] = m[0];
|
|
183
|
+
quads[o + 1] = m[1];
|
|
184
|
+
quads[o + 2] = m[2];
|
|
185
|
+
quads[o + 3] = m[3];
|
|
186
|
+
quads[o + 4] = m[4];
|
|
187
|
+
quads[o + 5] = m[5];
|
|
188
|
+
quads[o + 6] = ox;
|
|
189
|
+
quads[o + 7] = oy;
|
|
190
|
+
quads[o + 8] = w;
|
|
191
|
+
quads[o + 9] = h;
|
|
192
|
+
quads[o + 10] = radius;
|
|
193
|
+
quads[o + 11] = strokeWidth;
|
|
194
|
+
for (let k = 0; k < 4; k++) {
|
|
195
|
+
quads[o + 12 + k] = fill ? fill[k] : 0;
|
|
196
|
+
quads[o + 16 + k] = stroke ? stroke[k] : 0;
|
|
197
|
+
quads[o + 20 + k] = uv[k];
|
|
198
|
+
}
|
|
199
|
+
quads[o + 24] = mode;
|
|
200
|
+
quads[o + 25] = margin;
|
|
201
|
+
quadCount++;
|
|
202
|
+
};
|
|
203
|
+
const upload = (source, x, y, w, h) => {
|
|
204
|
+
gl.bindTexture(gl.TEXTURE_2D, resources.atlasTexture);
|
|
205
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
206
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
207
|
+
};
|
|
208
|
+
const draw = (command) => {
|
|
209
|
+
if (command.kind === "mesh") {
|
|
210
|
+
const v = command.vertices;
|
|
211
|
+
const count = v.length / 2;
|
|
212
|
+
meshes = grow(meshes, meshFloats + count * 6);
|
|
213
|
+
const [r, g, b, a] = command.color;
|
|
214
|
+
for (let i = 0; i < count; i++) {
|
|
215
|
+
const o = meshFloats + i * 6;
|
|
216
|
+
meshes[o] = v[i * 2];
|
|
217
|
+
meshes[o + 1] = v[i * 2 + 1];
|
|
218
|
+
meshes[o + 2] = r;
|
|
219
|
+
meshes[o + 3] = g;
|
|
220
|
+
meshes[o + 4] = b;
|
|
221
|
+
meshes[o + 5] = a;
|
|
222
|
+
}
|
|
223
|
+
const last = ops[ops.length - 1];
|
|
224
|
+
if (last?.type === "mesh")
|
|
225
|
+
last.count += count;
|
|
226
|
+
else
|
|
227
|
+
ops.push({ type: "mesh", first: meshFloats / 6, count });
|
|
228
|
+
meshFloats += count * 6;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const m = toDevice(command.matrix, frame.camera, frame.dpr);
|
|
232
|
+
if (command.kind === "rect") {
|
|
233
|
+
if (!command.fill && !command.stroke)
|
|
234
|
+
return;
|
|
235
|
+
pushQuad(m, 0, 0, command.w, command.h, command.radius, command.stroke ? command.strokeWidth : 0, command.fill, command.stroke, FULL, 0, null);
|
|
236
|
+
}
|
|
237
|
+
else if (command.kind === "shadow") {
|
|
238
|
+
const s = command.spread;
|
|
239
|
+
// Room for the blur's tail (3 sigma).
|
|
240
|
+
pushQuad(m, command.x - s, command.y - s, command.w + 2 * s, command.h + 2 * s, Math.max(0, command.radius + s), command.blur, command.color, null, FULL, 3, null, command.blur * 1.5);
|
|
241
|
+
}
|
|
242
|
+
else if (command.kind === "image") {
|
|
243
|
+
const image = frame.images.get(command.src);
|
|
244
|
+
if (!image)
|
|
245
|
+
return;
|
|
246
|
+
const f = fitImage(command.fit, command.w, command.h, image.width, image.height);
|
|
247
|
+
const uv = [f.sx / image.width, f.sy / image.height, (f.sx + f.sw) / image.width, (f.sy + f.sh) / image.height];
|
|
248
|
+
// Contain draws a smaller box; the corner radius follows the box.
|
|
249
|
+
pushQuad(m, f.dx, f.dy, f.dw, f.dh, command.radius, 0, [1, 1, 1, command.opacity], null, uv, 1, textureOf(image));
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (atlasFull)
|
|
253
|
+
return;
|
|
254
|
+
const deviceScale = Math.hypot(m[0], m[1]);
|
|
255
|
+
const region = atlas.get(command, deviceScale, upload);
|
|
256
|
+
if (!region) {
|
|
257
|
+
// The page is full: clear it for the next frame, which redraws.
|
|
258
|
+
atlasFull = true;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// The run was drawn at `region.scale` px a local unit.
|
|
262
|
+
const unit = 1 / region.scale;
|
|
263
|
+
const w = region.w * unit;
|
|
264
|
+
const h = region.h * unit;
|
|
265
|
+
pushQuad(m, command.x - ATLAS_PAD * unit, command.y - ATLAS_PAD * unit, w, h, 0, 0, command.color, null, [region.x / ATLAS_SIZE, region.y / ATLAS_SIZE, (region.x + region.w) / ATLAS_SIZE, (region.y + region.h) / ATLAS_SIZE], 2, resources.atlasTexture);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
for (const command of frame.commands)
|
|
269
|
+
draw(command);
|
|
270
|
+
// 2. Upload and draw.
|
|
271
|
+
gl.viewport(0, 0, width, height);
|
|
272
|
+
const [br, bg, bb] = frame.background;
|
|
273
|
+
gl.clearColor(br, bg, bb, 1);
|
|
274
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
275
|
+
gl.enable(gl.BLEND);
|
|
276
|
+
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
277
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, resources.instances);
|
|
278
|
+
gl.bufferData(gl.ARRAY_BUFFER, quads.subarray(0, quadCount * QUAD_FLOATS), gl.STREAM_DRAW);
|
|
279
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, resources.vertices);
|
|
280
|
+
gl.bufferData(gl.ARRAY_BUFFER, meshes.subarray(0, meshFloats), gl.STREAM_DRAW);
|
|
281
|
+
let drawCalls = 0;
|
|
282
|
+
let program = null;
|
|
283
|
+
for (const op of ops) {
|
|
284
|
+
if (op.type === "quad") {
|
|
285
|
+
if (program !== "quad") {
|
|
286
|
+
gl.useProgram(resources.quad);
|
|
287
|
+
gl.uniform2f(resources.quadResolution, width, height);
|
|
288
|
+
gl.uniform1i(resources.quadTexture, 0);
|
|
289
|
+
gl.bindVertexArray(resources.quadVao);
|
|
290
|
+
program = "quad";
|
|
291
|
+
}
|
|
292
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, resources.instances);
|
|
293
|
+
const stride = QUAD_FLOATS * 4;
|
|
294
|
+
for (let i = 0; i < 7; i++) {
|
|
295
|
+
gl.vertexAttribPointer(i + 1, 4, gl.FLOAT, false, stride, op.first * stride + i * 16);
|
|
296
|
+
}
|
|
297
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
298
|
+
gl.bindTexture(gl.TEXTURE_2D, op.texture ?? resources.atlasTexture);
|
|
299
|
+
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, op.count);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
if (program !== "mesh") {
|
|
303
|
+
gl.useProgram(resources.mesh);
|
|
304
|
+
gl.uniform2f(resources.meshResolution, width, height);
|
|
305
|
+
gl.uniform4f(resources.meshCamera, frame.camera.x, frame.camera.y, frame.camera.zoom, frame.dpr);
|
|
306
|
+
gl.bindVertexArray(resources.meshVao);
|
|
307
|
+
program = "mesh";
|
|
308
|
+
}
|
|
309
|
+
gl.drawArrays(gl.TRIANGLES, op.first, op.count);
|
|
310
|
+
}
|
|
311
|
+
drawCalls++;
|
|
312
|
+
}
|
|
313
|
+
gl.bindVertexArray(null);
|
|
314
|
+
if (atlasFull)
|
|
315
|
+
atlas.clear();
|
|
316
|
+
return {
|
|
317
|
+
drawCalls,
|
|
318
|
+
quads: quadCount,
|
|
319
|
+
meshVertices: meshFloats / 6,
|
|
320
|
+
textRuns: atlas.size,
|
|
321
|
+
atlasFull: atlasFull ? 1 : 0,
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
dispose() {
|
|
325
|
+
canvas.removeEventListener?.("webglcontextlost", onLost);
|
|
326
|
+
canvas.removeEventListener?.("webglcontextrestored", onRestored);
|
|
327
|
+
if (gl.isContextLost())
|
|
328
|
+
return;
|
|
329
|
+
gl.deleteProgram(resources.quad);
|
|
330
|
+
gl.deleteProgram(resources.mesh);
|
|
331
|
+
gl.deleteBuffer(resources.instances);
|
|
332
|
+
gl.deleteBuffer(resources.vertices);
|
|
333
|
+
gl.deleteVertexArray(resources.quadVao);
|
|
334
|
+
gl.deleteVertexArray(resources.meshVao);
|
|
335
|
+
gl.deleteTexture(resources.atlasTexture);
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|