@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,413 @@
|
|
|
1
|
+
/** A rect path with per-corner radii (clamped so they fit). */
|
|
2
|
+
export function roundRectPath(context, rect, radii) {
|
|
3
|
+
if (radii.some((r) => r > 0)) {
|
|
4
|
+
const limit = Math.max(0, Math.min(rect.w, rect.h) / 2);
|
|
5
|
+
context.roundRect(rect.x, rect.y, Math.max(0, rect.w), Math.max(0, rect.h), radii.map((r) => Math.max(0, Math.min(limit, r))));
|
|
6
|
+
}
|
|
7
|
+
else
|
|
8
|
+
context.rect(rect.x, rect.y, rect.w, rect.h);
|
|
9
|
+
}
|
|
10
|
+
const grow = (rect, by) => ({ x: rect.x - by, y: rect.y - by, w: rect.w + by * 2, h: rect.h + by * 2 });
|
|
11
|
+
const growRadii = (radii, by) => radii.map((r) => (r > 0 ? Math.max(0, r + by) : 0));
|
|
12
|
+
/** Where an image lands in its box, by `object-fit`. */
|
|
13
|
+
export function fitImage(fit, box, width, height) {
|
|
14
|
+
if (fit !== "cover" && fit !== "contain" && fit !== "scale-down")
|
|
15
|
+
return box;
|
|
16
|
+
let scale = fit === "cover" ? Math.max(box.w / width, box.h / height) : Math.min(box.w / width, box.h / height);
|
|
17
|
+
if (fit === "scale-down")
|
|
18
|
+
scale = Math.min(1, scale);
|
|
19
|
+
const w = width * scale;
|
|
20
|
+
const h = height * scale;
|
|
21
|
+
return { x: box.x + (box.w - w) / 2, y: box.y + (box.h - h) / 2, w, h };
|
|
22
|
+
}
|
|
23
|
+
function gradientFill(context, g, rect) {
|
|
24
|
+
if (g.kind === "linear") {
|
|
25
|
+
const a = (g.angle * Math.PI) / 180;
|
|
26
|
+
const dx = Math.sin(a);
|
|
27
|
+
const dy = -Math.cos(a);
|
|
28
|
+
const length = Math.abs(rect.w * dx) + Math.abs(rect.h * dy);
|
|
29
|
+
const cx = rect.x + rect.w / 2;
|
|
30
|
+
const cy = rect.y + rect.h / 2;
|
|
31
|
+
const grad = context.createLinearGradient(cx - (dx * length) / 2, cy - (dy * length) / 2, cx + (dx * length) / 2, cy + (dy * length) / 2);
|
|
32
|
+
for (const s of g.stops)
|
|
33
|
+
grad.addColorStop(s.at, s.color);
|
|
34
|
+
return grad;
|
|
35
|
+
}
|
|
36
|
+
if (g.kind === "conic") {
|
|
37
|
+
const grad = context.createConicGradient(((g.from - 90) * Math.PI) / 180, rect.x + g.cx, rect.y + g.cy);
|
|
38
|
+
for (const s of g.stops)
|
|
39
|
+
grad.addColorStop(s.at, s.color);
|
|
40
|
+
return grad;
|
|
41
|
+
}
|
|
42
|
+
const grad = context.createRadialGradient(0, 0, 0, 0, 0, Math.max(0.01, g.rx));
|
|
43
|
+
for (const s of g.stops)
|
|
44
|
+
grad.addColorStop(s.at, s.color);
|
|
45
|
+
return grad;
|
|
46
|
+
}
|
|
47
|
+
/** The device-pixel scale of the current transform (shadows are in device pixels). */
|
|
48
|
+
const deviceScale = (context) => {
|
|
49
|
+
const m = context.getTransform();
|
|
50
|
+
return Math.hypot(m.a, m.b) || 1;
|
|
51
|
+
};
|
|
52
|
+
const FAR = 100000;
|
|
53
|
+
/** An outer box shadow, drawn only outside the box, as CSS does. */
|
|
54
|
+
function outerShadow(context, s, rect, radii) {
|
|
55
|
+
const scale = deviceScale(context);
|
|
56
|
+
context.save();
|
|
57
|
+
context.beginPath();
|
|
58
|
+
context.rect(rect.x - FAR / 2, rect.y - FAR / 2, FAR, FAR);
|
|
59
|
+
roundRectPath(context, rect, radii);
|
|
60
|
+
context.clip("evenodd");
|
|
61
|
+
context.beginPath();
|
|
62
|
+
const shape = grow(rect, s.spread);
|
|
63
|
+
roundRectPath(context, { ...shape, x: shape.x - FAR }, growRadii(radii, s.spread));
|
|
64
|
+
context.shadowColor = s.color;
|
|
65
|
+
context.shadowBlur = s.blur * scale;
|
|
66
|
+
context.shadowOffsetX = (s.x + FAR) * scale;
|
|
67
|
+
context.shadowOffsetY = s.y * scale;
|
|
68
|
+
context.fillStyle = "#000";
|
|
69
|
+
context.fill();
|
|
70
|
+
context.restore();
|
|
71
|
+
}
|
|
72
|
+
/** An inset box shadow: a frame around the box's inside, its shadow cast inward. */
|
|
73
|
+
function insetShadow(context, s, rect, radii) {
|
|
74
|
+
const scale = deviceScale(context);
|
|
75
|
+
context.save();
|
|
76
|
+
context.beginPath();
|
|
77
|
+
roundRectPath(context, rect, radii);
|
|
78
|
+
context.clip();
|
|
79
|
+
context.beginPath();
|
|
80
|
+
const hole = grow(rect, -s.spread);
|
|
81
|
+
context.rect(rect.x - FAR - FAR / 2, rect.y - FAR / 2, FAR, FAR);
|
|
82
|
+
roundRectPath(context, { ...hole, x: hole.x - FAR }, growRadii(radii, -s.spread));
|
|
83
|
+
context.shadowColor = s.color;
|
|
84
|
+
context.shadowBlur = s.blur * scale;
|
|
85
|
+
context.shadowOffsetX = (s.x + FAR) * scale;
|
|
86
|
+
context.shadowOffsetY = s.y * scale;
|
|
87
|
+
context.fillStyle = "#000";
|
|
88
|
+
context.fill("evenodd");
|
|
89
|
+
context.restore();
|
|
90
|
+
}
|
|
91
|
+
/** A bitmap drawn once per box or gradient and scale (a mask, a tile). */
|
|
92
|
+
const layers = new WeakMap();
|
|
93
|
+
function layerFor(key, width, height, scale, paint) {
|
|
94
|
+
const cached = layers.get(key);
|
|
95
|
+
if (cached?.scale === scale)
|
|
96
|
+
return cached.canvas;
|
|
97
|
+
const canvas = document.createElement("canvas");
|
|
98
|
+
canvas.width = Math.max(1, Math.round(width * scale));
|
|
99
|
+
canvas.height = Math.max(1, Math.round(height * scale));
|
|
100
|
+
const context = canvas.getContext("2d");
|
|
101
|
+
if (context) {
|
|
102
|
+
context.scale(canvas.width / width, canvas.height / height);
|
|
103
|
+
paint(context);
|
|
104
|
+
}
|
|
105
|
+
layers.set(key, { scale, canvas });
|
|
106
|
+
return canvas;
|
|
107
|
+
}
|
|
108
|
+
/** Layer bitmaps step by half zooms, so a zoom gesture doesn't redraw them every frame. */
|
|
109
|
+
const layerScale = (context) => Math.min(4, Math.max(0.5, Math.ceil(deviceScale(context) * 2) / 2));
|
|
110
|
+
/** Fills a rect with one gradient, or with its tile repeated. */
|
|
111
|
+
function fillGradient(context, g, rect) {
|
|
112
|
+
if (g.tile) {
|
|
113
|
+
const { w, h } = g.tile;
|
|
114
|
+
const scale = layerScale(context);
|
|
115
|
+
const tile = layerFor(g, w, h, scale, (layer) => fillGradient(layer, { ...g, tile: undefined }, { x: 0, y: 0, w, h }));
|
|
116
|
+
const pattern = context.createPattern(tile, "repeat");
|
|
117
|
+
if (!pattern)
|
|
118
|
+
return;
|
|
119
|
+
pattern.setTransform(new DOMMatrix().translate(rect.x, rect.y).scale(w / tile.width, h / tile.height));
|
|
120
|
+
context.fillStyle = pattern;
|
|
121
|
+
context.fillRect(rect.x, rect.y, rect.w, rect.h);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (g.kind === "radial") {
|
|
125
|
+
context.save();
|
|
126
|
+
context.translate(rect.x + g.cx, rect.y + g.cy);
|
|
127
|
+
context.scale(1, g.ry / Math.max(0.01, g.rx));
|
|
128
|
+
context.fillStyle = gradientFill(context, g, rect);
|
|
129
|
+
context.fillRect(-FAR / 2, -FAR / 2, FAR, FAR);
|
|
130
|
+
context.restore();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
context.fillStyle = gradientFill(context, g, rect);
|
|
134
|
+
context.fillRect(rect.x, rect.y, rect.w, rect.h);
|
|
135
|
+
}
|
|
136
|
+
/** A masked box: drawn on a layer of its own, kept where the mask is opaque. */
|
|
137
|
+
function drawMasked(context, op, mask) {
|
|
138
|
+
const { rect } = op;
|
|
139
|
+
// Keyed by its mask (kept by `snapOp`), so the layer is drawn once per scale.
|
|
140
|
+
const layer = layerFor(mask, rect.w, rect.h, layerScale(context), (own) => {
|
|
141
|
+
own.translate(-rect.x, -rect.y);
|
|
142
|
+
drawBox(own, { ...op, mask: undefined, backdropBlur: undefined });
|
|
143
|
+
own.globalCompositeOperation = "destination-in";
|
|
144
|
+
fillGradient(own, mask, rect);
|
|
145
|
+
});
|
|
146
|
+
context.drawImage(layer, rect.x, rect.y, rect.w, rect.h);
|
|
147
|
+
}
|
|
148
|
+
/** Blurs what the canvas already shows under a box. */
|
|
149
|
+
function blurBackdrop(context, op, blur) {
|
|
150
|
+
if (!("filter" in context))
|
|
151
|
+
return;
|
|
152
|
+
const m = context.getTransform();
|
|
153
|
+
const radius = blur * deviceScale(context);
|
|
154
|
+
// Only what is under the box, its edges repeated outwards (CSS samples
|
|
155
|
+
// the backdrop within the element, clamped at its edges: what lies around
|
|
156
|
+
// it doesn't bleed in).
|
|
157
|
+
const x0 = Math.max(0, Math.floor(m.a * op.rect.x + m.e));
|
|
158
|
+
const y0 = Math.max(0, Math.floor(m.d * op.rect.y + m.f));
|
|
159
|
+
const x1 = Math.min(context.canvas.width, Math.ceil(m.a * (op.rect.x + op.rect.w) + m.e));
|
|
160
|
+
const y1 = Math.min(context.canvas.height, Math.ceil(m.d * (op.rect.y + op.rect.h) + m.f));
|
|
161
|
+
const w = x1 - x0;
|
|
162
|
+
const h = y1 - y0;
|
|
163
|
+
if (w <= 0 || h <= 0)
|
|
164
|
+
return;
|
|
165
|
+
const pad = Math.ceil(radius * 3);
|
|
166
|
+
const edges = document.createElement("canvas");
|
|
167
|
+
edges.width = w + pad * 2;
|
|
168
|
+
edges.height = h + pad * 2;
|
|
169
|
+
const e = edges.getContext("2d");
|
|
170
|
+
if (!e)
|
|
171
|
+
return;
|
|
172
|
+
e.drawImage(context.canvas, x0, y0, w, h, pad, pad, w, h);
|
|
173
|
+
// Sides, then corners, stretched from the outermost pixels.
|
|
174
|
+
e.drawImage(edges, pad, pad, 1, h, 0, pad, pad, h);
|
|
175
|
+
e.drawImage(edges, pad + w - 1, pad, 1, h, pad + w, pad, pad, h);
|
|
176
|
+
e.drawImage(edges, 0, pad, edges.width, 1, 0, 0, edges.width, pad);
|
|
177
|
+
e.drawImage(edges, 0, pad + h - 1, edges.width, 1, 0, pad + h, edges.width, pad);
|
|
178
|
+
const blurred = document.createElement("canvas");
|
|
179
|
+
blurred.width = edges.width;
|
|
180
|
+
blurred.height = edges.height;
|
|
181
|
+
const b = blurred.getContext("2d");
|
|
182
|
+
if (!b)
|
|
183
|
+
return;
|
|
184
|
+
b.filter = `blur(${radius}px)`;
|
|
185
|
+
b.drawImage(edges, 0, 0);
|
|
186
|
+
context.save();
|
|
187
|
+
context.beginPath();
|
|
188
|
+
roundRectPath(context, op.rect, op.radii);
|
|
189
|
+
context.clip();
|
|
190
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
191
|
+
context.drawImage(blurred, pad, pad, w, h, x0, y0, w, h);
|
|
192
|
+
context.restore();
|
|
193
|
+
}
|
|
194
|
+
function drawBox(context, op) {
|
|
195
|
+
if (op.mask) {
|
|
196
|
+
drawMasked(context, op, op.mask);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (op.backdropBlur)
|
|
200
|
+
blurBackdrop(context, op, op.backdropBlur);
|
|
201
|
+
const { rect, radii } = op;
|
|
202
|
+
if (op.hole) {
|
|
203
|
+
// A ring mask: everything the box paints (its shadows too), only between its edge and the hole.
|
|
204
|
+
context.beginPath();
|
|
205
|
+
roundRectPath(context, rect, radii);
|
|
206
|
+
roundRectPath(context, op.hole, op.hole.radii);
|
|
207
|
+
context.clip("evenodd");
|
|
208
|
+
}
|
|
209
|
+
const shadows = op.shadows ?? [];
|
|
210
|
+
// CSS lists the topmost shadow first.
|
|
211
|
+
for (const s of [...shadows].reverse())
|
|
212
|
+
if (!s.inset)
|
|
213
|
+
outerShadow(context, s, rect, radii);
|
|
214
|
+
if (op.fill || op.gradients) {
|
|
215
|
+
context.beginPath();
|
|
216
|
+
roundRectPath(context, rect, radii);
|
|
217
|
+
if (op.fill) {
|
|
218
|
+
context.fillStyle = op.fill;
|
|
219
|
+
context.fill();
|
|
220
|
+
}
|
|
221
|
+
for (const g of op.gradients ?? []) {
|
|
222
|
+
context.save();
|
|
223
|
+
context.beginPath();
|
|
224
|
+
roundRectPath(context, rect, radii);
|
|
225
|
+
context.clip();
|
|
226
|
+
fillGradient(context, g, rect);
|
|
227
|
+
context.restore();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const s of [...shadows].reverse())
|
|
231
|
+
if (s.inset)
|
|
232
|
+
insetShadow(context, s, rect, radii);
|
|
233
|
+
if (op.stroke && op.strokeWidth) {
|
|
234
|
+
const w = op.strokeWidth;
|
|
235
|
+
context.beginPath();
|
|
236
|
+
roundRectPath(context, grow(rect, -w / 2), growRadii(radii, -w / 2));
|
|
237
|
+
context.lineWidth = w;
|
|
238
|
+
context.strokeStyle = op.stroke;
|
|
239
|
+
if (op.dash)
|
|
240
|
+
context.setLineDash(op.dash);
|
|
241
|
+
context.stroke();
|
|
242
|
+
context.setLineDash([]);
|
|
243
|
+
}
|
|
244
|
+
else if (op.sides) {
|
|
245
|
+
const [top, right, bottom, left] = op.sides;
|
|
246
|
+
context.save();
|
|
247
|
+
context.beginPath();
|
|
248
|
+
roundRectPath(context, rect, radii);
|
|
249
|
+
context.clip();
|
|
250
|
+
const side = (s, x, y, w, h) => {
|
|
251
|
+
if (!s.width || s.style === "none")
|
|
252
|
+
return;
|
|
253
|
+
context.fillStyle = s.color;
|
|
254
|
+
context.fillRect(x, y, w, h);
|
|
255
|
+
};
|
|
256
|
+
side(top, rect.x, rect.y, rect.w, top.width);
|
|
257
|
+
side(bottom, rect.x, rect.y + rect.h - bottom.width, rect.w, bottom.width);
|
|
258
|
+
side(left, rect.x, rect.y, left.width, rect.h);
|
|
259
|
+
side(right, rect.x + rect.w - right.width, rect.y, right.width, rect.h);
|
|
260
|
+
context.restore();
|
|
261
|
+
}
|
|
262
|
+
if (op.outline) {
|
|
263
|
+
const { width, color, offset, style } = op.outline;
|
|
264
|
+
context.beginPath();
|
|
265
|
+
roundRectPath(context, grow(rect, offset + width / 2), growRadii(radii, offset + width / 2));
|
|
266
|
+
context.lineWidth = width;
|
|
267
|
+
context.strokeStyle = color;
|
|
268
|
+
if (style === "dashed")
|
|
269
|
+
context.setLineDash([width * 3, width * 2]);
|
|
270
|
+
if (style === "dotted")
|
|
271
|
+
context.setLineDash([width, width]);
|
|
272
|
+
context.stroke();
|
|
273
|
+
context.setLineDash([]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/** Narrows the current clip to a rounded rect (clips nest: each one intersects). */
|
|
277
|
+
export function clipTo(context, clip) {
|
|
278
|
+
context.beginPath();
|
|
279
|
+
roundRectPath(context, clip, clip.radii);
|
|
280
|
+
context.clip();
|
|
281
|
+
}
|
|
282
|
+
const COMPOSITE = {
|
|
283
|
+
add: "source-over",
|
|
284
|
+
subtract: "source-out",
|
|
285
|
+
intersect: "source-in",
|
|
286
|
+
exclude: "xor",
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* A masked element and all it holds: drawn on a layer of their own, then
|
|
290
|
+
* kept where the mask is opaque. CSS composites mask layers from the last
|
|
291
|
+
* (bottom) up, each with its own `mask-composite`.
|
|
292
|
+
*/
|
|
293
|
+
function drawGroup(context, op) {
|
|
294
|
+
const { rect } = op;
|
|
295
|
+
const scale = layerScale(context);
|
|
296
|
+
const layer = layerFor(op, rect.w, rect.h, scale, (own) => {
|
|
297
|
+
own.translate(-rect.x, -rect.y);
|
|
298
|
+
for (const child of op.ops)
|
|
299
|
+
drawOp(own, child);
|
|
300
|
+
if (!op.masks.length)
|
|
301
|
+
return;
|
|
302
|
+
const mask = document.createElement("canvas");
|
|
303
|
+
mask.width = own.canvas.width;
|
|
304
|
+
mask.height = own.canvas.height;
|
|
305
|
+
const m = mask.getContext("2d");
|
|
306
|
+
if (!m)
|
|
307
|
+
return;
|
|
308
|
+
m.scale(mask.width / rect.w, mask.height / rect.h);
|
|
309
|
+
const box = { x: 0, y: 0, w: rect.w, h: rect.h };
|
|
310
|
+
const layers = [...op.masks].reverse();
|
|
311
|
+
layers.forEach((layer, index) => {
|
|
312
|
+
m.globalCompositeOperation = index === 0 ? "source-over" : COMPOSITE[layer.composite];
|
|
313
|
+
fillGradient(m, layer.gradient, box);
|
|
314
|
+
});
|
|
315
|
+
own.setTransform(1, 0, 0, 1, 0, 0);
|
|
316
|
+
own.globalCompositeOperation = "destination-in";
|
|
317
|
+
own.drawImage(mask, 0, 0);
|
|
318
|
+
});
|
|
319
|
+
context.drawImage(layer, rect.x, rect.y, rect.w, rect.h);
|
|
320
|
+
}
|
|
321
|
+
function drawOp(context, op) {
|
|
322
|
+
if (op.kind === "group") {
|
|
323
|
+
context.save();
|
|
324
|
+
context.globalAlpha = op.alpha;
|
|
325
|
+
if (op.clip)
|
|
326
|
+
clipTo(context, op.clip);
|
|
327
|
+
if (op.clips)
|
|
328
|
+
for (const clip of op.clips)
|
|
329
|
+
clipTo(context, clip);
|
|
330
|
+
drawGroup(context, op);
|
|
331
|
+
context.restore();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
context.save();
|
|
335
|
+
context.globalAlpha = op.alpha;
|
|
336
|
+
if (op.clip)
|
|
337
|
+
clipTo(context, op.clip);
|
|
338
|
+
if (op.clips)
|
|
339
|
+
for (const clip of op.clips)
|
|
340
|
+
clipTo(context, clip);
|
|
341
|
+
if (op.kind === "box")
|
|
342
|
+
drawBox(context, op);
|
|
343
|
+
else if (op.kind === "image") {
|
|
344
|
+
if (op.rotate) {
|
|
345
|
+
const cx = op.rect.x + op.rect.w / 2;
|
|
346
|
+
const cy = op.rect.y + op.rect.h / 2;
|
|
347
|
+
context.translate(cx, cy);
|
|
348
|
+
context.rotate(op.rotate);
|
|
349
|
+
context.translate(-cx, -cy);
|
|
350
|
+
}
|
|
351
|
+
context.beginPath();
|
|
352
|
+
roundRectPath(context, op.rect, op.radii);
|
|
353
|
+
context.clip();
|
|
354
|
+
const target = fitImage(op.fit, op.rect, op.sourceWidth, op.sourceHeight);
|
|
355
|
+
// A picture shown smaller than it is: the better of canvas's filters
|
|
356
|
+
// (the browser's own, for <img>, stays a little sharper).
|
|
357
|
+
context.imageSmoothingQuality = "high";
|
|
358
|
+
try {
|
|
359
|
+
context.drawImage(op.source, target.x, target.y, target.w, target.h);
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
// A source that can't draw yet (a detached video) paints nothing.
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (op.kind === "text") {
|
|
366
|
+
context.font = op.font;
|
|
367
|
+
context.fillStyle = op.color;
|
|
368
|
+
context.textBaseline = "alphabetic";
|
|
369
|
+
context.textAlign = "left";
|
|
370
|
+
if (op.letterSpacing && "letterSpacing" in context)
|
|
371
|
+
context.letterSpacing = op.letterSpacing;
|
|
372
|
+
context.fillText(op.text, op.rect.x, op.rect.y + op.baseline);
|
|
373
|
+
if (op.underline) {
|
|
374
|
+
context.fillStyle = op.underline.color;
|
|
375
|
+
context.fillRect(op.rect.x, op.rect.y + op.underline.y, op.rect.w, op.underline.thickness);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
context.fillStyle = op.color;
|
|
380
|
+
context.fillRect(op.rect.x, op.rect.y, op.rect.w, op.rect.h);
|
|
381
|
+
}
|
|
382
|
+
context.restore();
|
|
383
|
+
}
|
|
384
|
+
/** Draws a display list as vectors, in its own units. */
|
|
385
|
+
export function drawPaint(context, paint) {
|
|
386
|
+
for (const op of paint.ops)
|
|
387
|
+
drawOp(context, op);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* The bitmap scale for a zoom: rounded up to a power of two, so a node is
|
|
391
|
+
* re-rasterised only when the zoom crosses a bucket.
|
|
392
|
+
*/
|
|
393
|
+
export function rasterScale(zoom, pixelRatio = 1) {
|
|
394
|
+
const target = Math.min(1, Math.max(1 / 64, zoom * pixelRatio));
|
|
395
|
+
return 2 ** Math.ceil(Math.log2(target));
|
|
396
|
+
}
|
|
397
|
+
const MAX_BITMAP = 2048;
|
|
398
|
+
/** Rasterises a display list at `scale` (bitmap px per unit). */
|
|
399
|
+
export function rasterizePaint(paint, scale) {
|
|
400
|
+
const { bounds } = paint;
|
|
401
|
+
const fit = Math.min(1, MAX_BITMAP / Math.max(bounds.w, bounds.h, 1) / scale);
|
|
402
|
+
const pixels = scale * fit;
|
|
403
|
+
const canvas = document.createElement("canvas");
|
|
404
|
+
canvas.width = Math.max(1, Math.ceil(bounds.w * pixels));
|
|
405
|
+
canvas.height = Math.max(1, Math.ceil(bounds.h * pixels));
|
|
406
|
+
const context = canvas.getContext("2d");
|
|
407
|
+
if (!context)
|
|
408
|
+
return canvas;
|
|
409
|
+
context.scale(pixels, pixels);
|
|
410
|
+
context.translate(-bounds.x, -bounds.y);
|
|
411
|
+
drawPaint(context, paint);
|
|
412
|
+
return canvas;
|
|
413
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The ghost: an element whose DOM stays alive (hit-tested, focusable, typed
|
|
3
|
+
* into, read by screen readers) but isn't seen; the canvas paints it instead
|
|
4
|
+
* (DOM-BRIDGE.md). `opacity: 0` on the root hides everything it holds, while
|
|
5
|
+
* the painter reads its children at full opacity.
|
|
6
|
+
*/
|
|
7
|
+
export const GHOST_ATTRIBUTE = "data-avis-ghost";
|
|
8
|
+
export const ghostCss = `[${GHOST_ATTRIBUTE}] { opacity: 0 !important; }`;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { collectPaint, loadedImage, setComposition } from "./collect.js";
|
|
2
|
+
export { clipTo, drawPaint, fitImage, rasterScale, rasterizePaint, roundRectPath } from "./draw.js";
|
|
3
|
+
export { backdropBlurOf, clipContains, clipRect, clipsContent, clipsFor, isTransparent, maskGradient, maskHole, paddingClip, parseGradient, parseGradients, parseRadius, parseShadows, pointInClip, pseudoText, pushClip, radiiOf, wrapWords, } from "./css.js";
|
|
4
|
+
export { watchDom, type DomWatcher } from "./watch.js";
|
|
5
|
+
export { GHOST_ATTRIBUTE, ghostCss } from "./ghost.js";
|
|
6
|
+
export type * from "./types.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AVIS Engine · DOM painter: paints any UI library's DOM on the canvas from
|
|
3
|
+
* what the browser computed (docs/avis-engine/DOM-BRIDGE.md).
|
|
4
|
+
*/
|
|
5
|
+
export { collectPaint, loadedImage, setComposition } from "./collect.js";
|
|
6
|
+
export { clipTo, drawPaint, fitImage, rasterScale, rasterizePaint, roundRectPath } from "./draw.js";
|
|
7
|
+
export { backdropBlurOf, clipContains, clipRect, clipsContent, clipsFor, isTransparent, maskGradient, maskHole, paddingClip, parseGradient, parseGradients, parseRadius, parseShadows, pointInClip, pseudoText, pushClip, radiiOf, wrapWords, } from "./css.js";
|
|
8
|
+
export { watchDom } from "./watch.js";
|
|
9
|
+
export { GHOST_ATTRIBUTE, ghostCss } from "./ghost.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type Line = {
|
|
2
|
+
text: string;
|
|
3
|
+
rect: DOMRect;
|
|
4
|
+
};
|
|
5
|
+
/** Whether the document's current font metrics are stable enough to cache. */
|
|
6
|
+
export declare function fontsSettled(status: "loading" | "loaded" | null | undefined): status is "loaded" | null | undefined;
|
|
7
|
+
/** The font's ascent (top of the content area to the baseline), as canvas measures it. */
|
|
8
|
+
export declare function fontMetrics(font: string, fallbackSize: number): {
|
|
9
|
+
ascent: number;
|
|
10
|
+
descent: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function textWidth(text: string, font: string, letterSpacing?: string): number;
|
|
13
|
+
export declare function transformText(text: string, transform: string): string;
|
|
14
|
+
/** A text node's lines: each word measured, words grouped by line. */
|
|
15
|
+
export declare function textLines(node: Text, whiteSpace: string): Line[];
|
|
16
|
+
export type FieldText = {
|
|
17
|
+
lines: Line[];
|
|
18
|
+
/** Caret or selection rects for [start, end), in page coordinates. */
|
|
19
|
+
range(start: number, end: number): DOMRect[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Lays out a field's text (its value, or `text`) in a hidden copy with the
|
|
23
|
+
* field's styles, at the field's position and scroll, so the lines, the
|
|
24
|
+
* caret and the selection land where the browser draws them.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fieldText(field: HTMLInputElement | HTMLTextAreaElement, text: string): FieldText;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Text as the browser laid it out: lines read from DOM ranges (so wrapping,
|
|
3
|
+
* alignment and spacing are the browser's), and form fields (<input>,
|
|
4
|
+
* <textarea>) laid out in a hidden mirror with the field's styles, since
|
|
5
|
+
* their text isn't in the DOM. Also the caret and selection rects of a field.
|
|
6
|
+
*/
|
|
7
|
+
let measure = null;
|
|
8
|
+
const metrics = new Map();
|
|
9
|
+
/** Whether the document's current font metrics are stable enough to cache. */
|
|
10
|
+
export function fontsSettled(status) {
|
|
11
|
+
return status !== "loading";
|
|
12
|
+
}
|
|
13
|
+
/** The font's ascent (top of the content area to the baseline), as canvas measures it. */
|
|
14
|
+
export function fontMetrics(font, fallbackSize) {
|
|
15
|
+
const cacheable = typeof document === "undefined" || fontsSettled(document.fonts?.status);
|
|
16
|
+
const cached = cacheable ? metrics.get(font) : undefined;
|
|
17
|
+
if (cached !== undefined)
|
|
18
|
+
return cached;
|
|
19
|
+
measure ??= document.createElement("canvas").getContext("2d");
|
|
20
|
+
let ascent = fallbackSize * 0.8;
|
|
21
|
+
let descent = fallbackSize * 0.2;
|
|
22
|
+
if (measure) {
|
|
23
|
+
measure.font = font;
|
|
24
|
+
const m = measure.measureText("Hg");
|
|
25
|
+
if (m.fontBoundingBoxAscent)
|
|
26
|
+
ascent = m.fontBoundingBoxAscent;
|
|
27
|
+
if (m.fontBoundingBoxDescent !== undefined)
|
|
28
|
+
descent = m.fontBoundingBoxDescent;
|
|
29
|
+
}
|
|
30
|
+
// A font that is still loading measures as its fallback face. Leave that
|
|
31
|
+
// value uncached so the next paint can use the real face's metrics.
|
|
32
|
+
const result = { ascent, descent };
|
|
33
|
+
if (cacheable)
|
|
34
|
+
metrics.set(font, result);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
export function textWidth(text, font, letterSpacing) {
|
|
38
|
+
measure ??= document.createElement("canvas").getContext("2d");
|
|
39
|
+
if (!measure)
|
|
40
|
+
return text.length * 7;
|
|
41
|
+
measure.font = font;
|
|
42
|
+
if (letterSpacing !== undefined && "letterSpacing" in measure)
|
|
43
|
+
measure.letterSpacing = letterSpacing;
|
|
44
|
+
return measure.measureText(text).width;
|
|
45
|
+
}
|
|
46
|
+
export function transformText(text, transform) {
|
|
47
|
+
if (transform === "uppercase")
|
|
48
|
+
return text.toUpperCase();
|
|
49
|
+
if (transform === "lowercase")
|
|
50
|
+
return text.toLowerCase();
|
|
51
|
+
if (transform === "capitalize")
|
|
52
|
+
return text.replace(/(^|\s)(\S)/g, (_, space, c) => space + c.toUpperCase());
|
|
53
|
+
return text;
|
|
54
|
+
}
|
|
55
|
+
const preserves = (whiteSpace) => /^pre/.test(whiteSpace) || whiteSpace === "break-spaces";
|
|
56
|
+
/** A text node's lines: each word measured, words grouped by line. */
|
|
57
|
+
export function textLines(node, whiteSpace) {
|
|
58
|
+
const data = node.data;
|
|
59
|
+
const range = document.createRange();
|
|
60
|
+
const lines = [];
|
|
61
|
+
const word = /\S+/g;
|
|
62
|
+
for (let m = word.exec(data); m; m = word.exec(data)) {
|
|
63
|
+
range.setStart(node, m.index);
|
|
64
|
+
range.setEnd(node, m.index + m[0].length);
|
|
65
|
+
const rects = range.getClientRects();
|
|
66
|
+
if (!rects.length)
|
|
67
|
+
continue;
|
|
68
|
+
if (rects.length === 1) {
|
|
69
|
+
add(lines, m.index, m.index + m[0].length, rects[0]);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// A word broken across lines (break-all, long URLs): one character at a time.
|
|
73
|
+
for (let i = m.index; i < m.index + m[0].length; i++) {
|
|
74
|
+
range.setStart(node, i);
|
|
75
|
+
range.setEnd(node, i + 1);
|
|
76
|
+
const r = range.getBoundingClientRect();
|
|
77
|
+
if (r.width || r.height)
|
|
78
|
+
add(lines, i, i + 1, r);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const keep = preserves(whiteSpace);
|
|
82
|
+
return lines.map(({ start, end, rect }) => {
|
|
83
|
+
let text = data.slice(start, end);
|
|
84
|
+
if (!keep)
|
|
85
|
+
text = text.replace(/\s+/g, " ");
|
|
86
|
+
return { text, rect };
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function add(lines, start, end, rect) {
|
|
90
|
+
const last = lines[lines.length - 1];
|
|
91
|
+
// The same line: overlapping vertically (a word on a line already started).
|
|
92
|
+
if (last && rect.top < last.rect.bottom - 1 && rect.bottom > last.rect.top + 1 && rect.left >= last.rect.left - 1) {
|
|
93
|
+
const left = Math.min(last.rect.left, rect.left);
|
|
94
|
+
const top = Math.min(last.rect.top, rect.top);
|
|
95
|
+
last.rect = new DOMRect(left, top, Math.max(last.rect.right, rect.right) - left, Math.max(last.rect.bottom, rect.bottom) - top);
|
|
96
|
+
last.end = end;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
lines.push({ start, end, rect });
|
|
100
|
+
}
|
|
101
|
+
// ---- form fields --------------------------------------------------------------------
|
|
102
|
+
const MIRRORED = [
|
|
103
|
+
"boxSizing",
|
|
104
|
+
"width",
|
|
105
|
+
"paddingTop",
|
|
106
|
+
"paddingRight",
|
|
107
|
+
"paddingBottom",
|
|
108
|
+
"paddingLeft",
|
|
109
|
+
"borderTopWidth",
|
|
110
|
+
"borderRightWidth",
|
|
111
|
+
"borderBottomWidth",
|
|
112
|
+
"borderLeftWidth",
|
|
113
|
+
"borderStyle",
|
|
114
|
+
"fontFamily",
|
|
115
|
+
"fontSize",
|
|
116
|
+
"fontStyle",
|
|
117
|
+
"fontWeight",
|
|
118
|
+
"fontStretch",
|
|
119
|
+
"fontVariant",
|
|
120
|
+
"fontFeatureSettings",
|
|
121
|
+
"lineHeight",
|
|
122
|
+
"letterSpacing",
|
|
123
|
+
"wordSpacing",
|
|
124
|
+
"textTransform",
|
|
125
|
+
"textIndent",
|
|
126
|
+
"textAlign",
|
|
127
|
+
"tabSize",
|
|
128
|
+
"wordBreak",
|
|
129
|
+
"overflowWrap",
|
|
130
|
+
];
|
|
131
|
+
let mirror = null;
|
|
132
|
+
/**
|
|
133
|
+
* Lays out a field's text (its value, or `text`) in a hidden copy with the
|
|
134
|
+
* field's styles, at the field's position and scroll, so the lines, the
|
|
135
|
+
* caret and the selection land where the browser draws them.
|
|
136
|
+
*/
|
|
137
|
+
export function fieldText(field, text) {
|
|
138
|
+
if (!mirror) {
|
|
139
|
+
mirror = document.createElement("div");
|
|
140
|
+
mirror.setAttribute("aria-hidden", "true");
|
|
141
|
+
mirror.dataset.avisPaintMirror = "";
|
|
142
|
+
Object.assign(mirror.style, { position: "fixed", visibility: "hidden", pointerEvents: "none", overflow: "hidden", left: "0px", top: "0px", contain: "strict" });
|
|
143
|
+
document.body.appendChild(mirror);
|
|
144
|
+
}
|
|
145
|
+
const style = getComputedStyle(field);
|
|
146
|
+
for (const key of MIRRORED)
|
|
147
|
+
mirror.style[key] = style[key];
|
|
148
|
+
const multiline = field instanceof HTMLTextAreaElement;
|
|
149
|
+
mirror.style.whiteSpace = multiline ? "pre-wrap" : "pre";
|
|
150
|
+
mirror.style.height = style.height;
|
|
151
|
+
const box = field.getBoundingClientRect();
|
|
152
|
+
mirror.style.transform = "none";
|
|
153
|
+
mirror.style.transformOrigin = "0 0";
|
|
154
|
+
mirror.style.left = `${box.left}px`;
|
|
155
|
+
mirror.style.top = `${box.top}px`;
|
|
156
|
+
// A field's content box is its own; an <input> centres one line vertically.
|
|
157
|
+
mirror.style.display = "block";
|
|
158
|
+
mirror.textContent = "";
|
|
159
|
+
const inner = document.createElement("span");
|
|
160
|
+
const node = document.createTextNode(text || "");
|
|
161
|
+
inner.appendChild(node);
|
|
162
|
+
mirror.appendChild(inner);
|
|
163
|
+
if (!multiline) {
|
|
164
|
+
mirror.style.display = "flex";
|
|
165
|
+
mirror.style.alignItems = "center";
|
|
166
|
+
}
|
|
167
|
+
// Computed CSS sizes are untransformed; Range rects are screen coordinates.
|
|
168
|
+
// The mirror lives outside the canvas viewport, so reproduce its scale once.
|
|
169
|
+
const natural = mirror.getBoundingClientRect();
|
|
170
|
+
const scaleX = natural.width ? box.width / natural.width : 1;
|
|
171
|
+
const scaleY = natural.height ? box.height / natural.height : 1;
|
|
172
|
+
mirror.style.transform = `scale(${scaleX}, ${scaleY})`;
|
|
173
|
+
const dx = -field.scrollLeft * scaleX;
|
|
174
|
+
const dy = -field.scrollTop * scaleY;
|
|
175
|
+
const shift = (r) => new DOMRect(r.left + dx, r.top + dy, r.width, r.height);
|
|
176
|
+
const lines = text ? textLines(node, multiline ? "pre-wrap" : "pre").map((l) => ({ text: l.text, rect: shift(l.rect) })) : [];
|
|
177
|
+
const range = (start, end) => {
|
|
178
|
+
const r = document.createRange();
|
|
179
|
+
const length = node.data.length;
|
|
180
|
+
const s = Math.min(start, length);
|
|
181
|
+
const e = Math.min(end, length);
|
|
182
|
+
if (s === e) {
|
|
183
|
+
// A caret: the left edge of the next character, or the right edge of the previous one.
|
|
184
|
+
if (s < length) {
|
|
185
|
+
r.setStart(node, s);
|
|
186
|
+
r.setEnd(node, s + 1);
|
|
187
|
+
const c = r.getClientRects()[0];
|
|
188
|
+
if (c)
|
|
189
|
+
return [shift(new DOMRect(c.left, c.top, 1, c.height))];
|
|
190
|
+
}
|
|
191
|
+
if (s > 0) {
|
|
192
|
+
r.setStart(node, s - 1);
|
|
193
|
+
r.setEnd(node, s);
|
|
194
|
+
const rects = r.getClientRects();
|
|
195
|
+
const c = rects[rects.length - 1];
|
|
196
|
+
if (c)
|
|
197
|
+
return [shift(new DOMRect(c.right, c.top, 1, c.height))];
|
|
198
|
+
}
|
|
199
|
+
r.setStart(node, 0);
|
|
200
|
+
r.setEnd(node, length);
|
|
201
|
+
const c = r.getBoundingClientRect();
|
|
202
|
+
return [shift(new DOMRect(c.left, c.top, 1, c.height || parseFloat(style.fontSize) * 1.2))];
|
|
203
|
+
}
|
|
204
|
+
r.setStart(node, s);
|
|
205
|
+
r.setEnd(node, e);
|
|
206
|
+
return [...r.getClientRects()].map(shift);
|
|
207
|
+
};
|
|
208
|
+
return { lines, range };
|
|
209
|
+
}
|