@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,713 @@
|
|
|
1
|
+
import { getHandlePosition, initialConnection } from "./system.js";
|
|
2
|
+
import { applyEdgeChanges, applyNodeChanges } from "./utils.js";
|
|
3
|
+
import { intersects, nodeConnections, queryRect } from "./queries.js";
|
|
4
|
+
import { defaultAriaLabels } from "./configuration.js";
|
|
5
|
+
const SOURCES = Symbol("sources");
|
|
6
|
+
/** The running viewport animation per store (a new transform cancels it). */
|
|
7
|
+
const animations = new WeakMap();
|
|
8
|
+
export function constrainTransform(state, transform) {
|
|
9
|
+
const k = Math.min(state.maxZoom, Math.max(state.minZoom, transform[2]));
|
|
10
|
+
const extent = state.translateExtent;
|
|
11
|
+
const clampAxis = (p, size, min, max) => {
|
|
12
|
+
const lo = size - max * k;
|
|
13
|
+
const hi = -min * k;
|
|
14
|
+
return (lo > hi ? (lo + hi) / 2 : Math.min(hi, Math.max(lo, p))) || 0;
|
|
15
|
+
};
|
|
16
|
+
return [clampAxis(transform[0], state.width, extent[0][0], extent[1][0]), clampAxis(transform[1], state.height, extent[0][1], extent[1][1]), k];
|
|
17
|
+
}
|
|
18
|
+
function applyTransform(store, transform, event = null) {
|
|
19
|
+
const s = store.getState();
|
|
20
|
+
if (!transform.every(Number.isFinite) || transform[2] <= 0)
|
|
21
|
+
return;
|
|
22
|
+
const next = constrainTransform(s, transform);
|
|
23
|
+
const zoom = next[2];
|
|
24
|
+
if (next[0] === s.transform[0] && next[1] === s.transform[1] && next[2] === s.transform[2])
|
|
25
|
+
return;
|
|
26
|
+
store.setState({ transform: next });
|
|
27
|
+
const viewport = { x: next[0], y: next[1], zoom };
|
|
28
|
+
const moving = moves.get(store);
|
|
29
|
+
if (!moving) {
|
|
30
|
+
;
|
|
31
|
+
s.onMoveStart?.(event, viewport);
|
|
32
|
+
s.onViewportChangeStart?.(viewport);
|
|
33
|
+
for (const handler of s.viewportHandlers)
|
|
34
|
+
handler.onStart?.(viewport);
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
clearTimeout(moving);
|
|
38
|
+
s.onViewportChange?.(viewport);
|
|
39
|
+
s.onMove?.(event, viewport);
|
|
40
|
+
for (const handler of s.viewportHandlers)
|
|
41
|
+
handler.onChange?.(viewport);
|
|
42
|
+
moves.set(store, setTimeout(() => {
|
|
43
|
+
moves.delete(store);
|
|
44
|
+
const [x, y, k] = store.getState().transform;
|
|
45
|
+
store.getState().onMoveEnd?.(event, { x, y, zoom: k });
|
|
46
|
+
store.getState().onViewportChangeEnd?.({ x, y, zoom: k });
|
|
47
|
+
for (const handler of store.getState().viewportHandlers)
|
|
48
|
+
handler.onEnd?.({ x, y, zoom: k });
|
|
49
|
+
}, 150));
|
|
50
|
+
}
|
|
51
|
+
/** The running move (its end timer) per store. */
|
|
52
|
+
const moves = new WeakMap();
|
|
53
|
+
export function disposeFlowViewport(store) {
|
|
54
|
+
animations.set(store, (animations.get(store) ?? 0) + 1);
|
|
55
|
+
const timer = moves.get(store);
|
|
56
|
+
if (timer)
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
moves.delete(store);
|
|
59
|
+
}
|
|
60
|
+
const isNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
61
|
+
/** Builds the internal nodes: absolute positions (parents first), z, sizes, handles. */
|
|
62
|
+
export function adoptNodes(state, nodes) {
|
|
63
|
+
// As xyflow: the same Map is refilled (selecting the lookup itself
|
|
64
|
+
// doesn't re-render on every change), from a copy of the previous one.
|
|
65
|
+
const previous = new Map(state.nodeLookup);
|
|
66
|
+
const lookup = state.nodeLookup;
|
|
67
|
+
lookup.clear();
|
|
68
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
69
|
+
const selectedZ = state.zIndexMode !== "manual" && state.elevateNodesOnSelect ? 1000 : 0;
|
|
70
|
+
const visit = (node, depth = 0) => {
|
|
71
|
+
const done = lookup.get(node.id);
|
|
72
|
+
if (done)
|
|
73
|
+
return done;
|
|
74
|
+
const parent = node.parentId && depth < 50 ? byId.get(node.parentId) : undefined;
|
|
75
|
+
const parentInternal = parent ? visit(parent, depth + 1) : undefined;
|
|
76
|
+
const measuredDom = state.measuredSizes.get(node.id);
|
|
77
|
+
// xyflow's checkEquality: an unchanged node keeps its internal object,
|
|
78
|
+
// so selectors on nodeLookup.get(id) don't re-render.
|
|
79
|
+
const before = previous.get(node.id);
|
|
80
|
+
const sources = [node, parentInternal, measuredDom, state.measuredHandles.get(node.id), state.elevateNodesOnSelect, state.zIndexMode, state.nodeOrigin];
|
|
81
|
+
if (before?.[SOURCES] && sources.every((value, i) => before[SOURCES][i] === value)) {
|
|
82
|
+
lookup.set(node.id, before);
|
|
83
|
+
return before;
|
|
84
|
+
}
|
|
85
|
+
const measured = {
|
|
86
|
+
// The DOM's size wins (React Flow measures rendered nodes itself).
|
|
87
|
+
width: measuredDom?.width ?? node.measured?.width ?? node.width ?? previous.get(node.id)?.measured.width,
|
|
88
|
+
height: measuredDom?.height ?? node.measured?.height ?? node.height ?? previous.get(node.id)?.measured.height,
|
|
89
|
+
};
|
|
90
|
+
const base = (isNumber(node.zIndex) ? node.zIndex : 0) + (node.selected ? selectedZ : 0);
|
|
91
|
+
const parentZ = parentInternal?.internals.z ?? 0;
|
|
92
|
+
const z = parentInternal && state.zIndexMode === "auto" ? (parentZ >= base ? parentZ + 1 : base) : base;
|
|
93
|
+
const origin = node.origin ?? state.nodeOrigin ?? [0, 0];
|
|
94
|
+
const positionAbsolute = parentInternal
|
|
95
|
+
? {
|
|
96
|
+
x: parentInternal.internals.positionAbsolute.x + node.position.x - (measured.width ?? 0) * origin[0],
|
|
97
|
+
y: parentInternal.internals.positionAbsolute.y + node.position.y - (measured.height ?? 0) * origin[1],
|
|
98
|
+
}
|
|
99
|
+
: { x: node.position.x - (measured.width ?? 0) * origin[0], y: node.position.y - (measured.height ?? 0) * origin[1] };
|
|
100
|
+
const dom = state.measuredHandles.get(node.id);
|
|
101
|
+
const declared = node.handles;
|
|
102
|
+
const handleBounds = dom
|
|
103
|
+
? { source: dom.source, target: dom.target }
|
|
104
|
+
: declared
|
|
105
|
+
? {
|
|
106
|
+
source: declared.filter((h) => h.type === "source").map((h) => ({ ...h, nodeId: node.id })),
|
|
107
|
+
target: declared.filter((h) => h.type === "target").map((h) => ({ ...h, nodeId: node.id })),
|
|
108
|
+
}
|
|
109
|
+
: undefined;
|
|
110
|
+
const internal = {
|
|
111
|
+
...node,
|
|
112
|
+
measured,
|
|
113
|
+
internals: { positionAbsolute, z, userNode: node, handleBounds },
|
|
114
|
+
};
|
|
115
|
+
// What it was built from (not enumerable: it stays out of spreads).
|
|
116
|
+
Object.defineProperty(internal, SOURCES, { value: sources });
|
|
117
|
+
lookup.set(node.id, internal);
|
|
118
|
+
return internal;
|
|
119
|
+
};
|
|
120
|
+
for (const node of nodes)
|
|
121
|
+
visit(node);
|
|
122
|
+
return lookup;
|
|
123
|
+
}
|
|
124
|
+
/** xyflow's getSelectionChanges (`mutate`: the internal items follow at once). */
|
|
125
|
+
export const selectionChanges = (items, selected, mutate = false) => {
|
|
126
|
+
const out = [];
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
const will = selected.has(item.id);
|
|
129
|
+
if (!(item.selected === undefined && !will) && item.selected !== will) {
|
|
130
|
+
if (mutate)
|
|
131
|
+
item.selected = will;
|
|
132
|
+
out.push({ type: "select", id: item.id, selected: will });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
};
|
|
137
|
+
export function createFlowStore() {
|
|
138
|
+
const listeners = new Set();
|
|
139
|
+
let state;
|
|
140
|
+
const store = {
|
|
141
|
+
getState: () => state,
|
|
142
|
+
setState(partial) {
|
|
143
|
+
const next = typeof partial === "function" ? partial(state) : partial;
|
|
144
|
+
state = { ...state, ...next };
|
|
145
|
+
for (const listener of [...listeners])
|
|
146
|
+
listener();
|
|
147
|
+
},
|
|
148
|
+
subscribe(listener) {
|
|
149
|
+
listeners.add(listener);
|
|
150
|
+
return () => void listeners.delete(listener);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const set = store.setState;
|
|
154
|
+
state = {
|
|
155
|
+
nodes: [],
|
|
156
|
+
edges: [],
|
|
157
|
+
nodeLookup: new Map(),
|
|
158
|
+
edgeLookup: new Map(),
|
|
159
|
+
visibleNodeIds: [],
|
|
160
|
+
selectedNodeCount: 0,
|
|
161
|
+
parentIds: new Set(),
|
|
162
|
+
transform: [0, 0, 1],
|
|
163
|
+
width: 0,
|
|
164
|
+
height: 0,
|
|
165
|
+
minZoom: 0.5,
|
|
166
|
+
maxZoom: 2,
|
|
167
|
+
translateExtent: [[-Infinity, -Infinity], [Infinity, Infinity]],
|
|
168
|
+
zIndexMode: "auto",
|
|
169
|
+
ariaLabelConfig: defaultAriaLabels,
|
|
170
|
+
viewportHandlers: new Set(),
|
|
171
|
+
domNode: null,
|
|
172
|
+
panZoom: null,
|
|
173
|
+
nodesSelectionActive: false,
|
|
174
|
+
userSelectionActive: false,
|
|
175
|
+
userSelectionRect: null,
|
|
176
|
+
multiSelectionActive: false,
|
|
177
|
+
elementsSelectable: true,
|
|
178
|
+
nodesDraggable: true,
|
|
179
|
+
nodesConnectable: true,
|
|
180
|
+
nodesFocusable: true,
|
|
181
|
+
selectNodesOnDrag: true,
|
|
182
|
+
snapToGrid: false,
|
|
183
|
+
snapGrid: [15, 15],
|
|
184
|
+
nodeDragThreshold: 1,
|
|
185
|
+
connectionDragThreshold: 1,
|
|
186
|
+
connectionRadius: 20,
|
|
187
|
+
connectionMode: "strict",
|
|
188
|
+
elevateNodesOnSelect: true,
|
|
189
|
+
fitViewDone: false,
|
|
190
|
+
connection: initialConnection,
|
|
191
|
+
connectionClickStartHandle: null,
|
|
192
|
+
paneDragging: false,
|
|
193
|
+
autoPanOnNodeDrag: true,
|
|
194
|
+
autoPanOnConnect: true,
|
|
195
|
+
autoPanSpeed: 15,
|
|
196
|
+
hasDefaultNodes: false,
|
|
197
|
+
hasDefaultEdges: false,
|
|
198
|
+
edgesFocusable: true,
|
|
199
|
+
rfId: "1",
|
|
200
|
+
onSelectionChangeHandlers: [],
|
|
201
|
+
onNodesChangeMiddlewareMap: new Map(),
|
|
202
|
+
onEdgesChangeMiddlewareMap: new Map(),
|
|
203
|
+
ariaLiveMessage: "",
|
|
204
|
+
autoPanOnNodeFocus: true,
|
|
205
|
+
measuredHandles: new Map(),
|
|
206
|
+
measuredSizes: new Map(),
|
|
207
|
+
triggerNodeChanges(changes) {
|
|
208
|
+
if (!changes.length)
|
|
209
|
+
return;
|
|
210
|
+
const s = store.getState();
|
|
211
|
+
if (s.debug)
|
|
212
|
+
console.debug("[AVIS Flow] node changes", changes);
|
|
213
|
+
if (s.hasDefaultNodes)
|
|
214
|
+
s.setNodes(applyNodeChanges(changes, s.nodes));
|
|
215
|
+
s.onNodesChange?.(changes);
|
|
216
|
+
},
|
|
217
|
+
triggerEdgeChanges(changes) {
|
|
218
|
+
if (!changes.length)
|
|
219
|
+
return;
|
|
220
|
+
const s = store.getState();
|
|
221
|
+
if (s.debug)
|
|
222
|
+
console.debug("[AVIS Flow] edge changes", changes);
|
|
223
|
+
if (s.hasDefaultEdges)
|
|
224
|
+
s.setEdges(applyEdgeChanges(changes, s.edges));
|
|
225
|
+
s.onEdgesChange?.(changes);
|
|
226
|
+
},
|
|
227
|
+
// xyflow's selection actions, with its hack: the internal nodes are
|
|
228
|
+
// updated at once (onNodesChange comes too late for a drag starting now).
|
|
229
|
+
addSelectedNodes(ids) {
|
|
230
|
+
const s = store.getState();
|
|
231
|
+
if (s.multiSelectionActive) {
|
|
232
|
+
s.triggerNodeChanges(ids.map((id) => ({ type: "select", id, selected: true })));
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
s.triggerNodeChanges(selectionChanges(s.nodeLookup.values(), new Set(ids), true));
|
|
236
|
+
s.triggerEdgeChanges(selectionChanges(s.edgeLookup.values(), new Set()));
|
|
237
|
+
},
|
|
238
|
+
addSelectedEdges(ids) {
|
|
239
|
+
const s = store.getState();
|
|
240
|
+
if (s.multiSelectionActive) {
|
|
241
|
+
s.triggerEdgeChanges(ids.map((id) => ({ type: "select", id, selected: true })));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
s.triggerEdgeChanges(selectionChanges(s.edgeLookup.values(), new Set(ids)));
|
|
245
|
+
s.triggerNodeChanges(selectionChanges(s.nodeLookup.values(), new Set(), true));
|
|
246
|
+
},
|
|
247
|
+
unselectNodesAndEdges({ nodes, edges } = {}) {
|
|
248
|
+
const s = store.getState();
|
|
249
|
+
const nodeChanges = [];
|
|
250
|
+
for (const node of nodes ?? s.nodes) {
|
|
251
|
+
if (!node.selected)
|
|
252
|
+
continue;
|
|
253
|
+
const internal = s.nodeLookup.get(node.id);
|
|
254
|
+
if (internal)
|
|
255
|
+
internal.selected = false;
|
|
256
|
+
nodeChanges.push({ type: "select", id: node.id, selected: false });
|
|
257
|
+
}
|
|
258
|
+
const edgeChanges = [];
|
|
259
|
+
for (const edge of edges ?? s.edges) {
|
|
260
|
+
if (!edge.selected)
|
|
261
|
+
continue;
|
|
262
|
+
edgeChanges.push({ type: "select", id: edge.id, selected: false });
|
|
263
|
+
}
|
|
264
|
+
s.triggerNodeChanges(nodeChanges);
|
|
265
|
+
s.triggerEdgeChanges(edgeChanges);
|
|
266
|
+
},
|
|
267
|
+
resetSelectedElements() {
|
|
268
|
+
const s = store.getState();
|
|
269
|
+
if (!s.elementsSelectable)
|
|
270
|
+
return;
|
|
271
|
+
s.triggerNodeChanges(s.nodes.filter((n) => n.selected).map((n) => ({ type: "select", id: n.id, selected: false })));
|
|
272
|
+
s.triggerEdgeChanges(s.edges.filter((e) => e.selected).map((e) => ({ type: "select", id: e.id, selected: false })));
|
|
273
|
+
},
|
|
274
|
+
setNodes(nodes) {
|
|
275
|
+
set((s) => {
|
|
276
|
+
const visible = [];
|
|
277
|
+
const parentIds = new Set();
|
|
278
|
+
let selected = 0;
|
|
279
|
+
for (const node of nodes) {
|
|
280
|
+
if (!node.hidden)
|
|
281
|
+
visible.push(node.id);
|
|
282
|
+
if (node.parentId)
|
|
283
|
+
parentIds.add(node.parentId);
|
|
284
|
+
if (node.selected)
|
|
285
|
+
selected++;
|
|
286
|
+
}
|
|
287
|
+
const sameVisible = visible.length === s.visibleNodeIds.length && visible.every((id, i) => id === s.visibleNodeIds[i]);
|
|
288
|
+
const sameParents = parentIds.size === s.parentIds.size && [...parentIds].every((id) => s.parentIds.has(id));
|
|
289
|
+
return {
|
|
290
|
+
nodes,
|
|
291
|
+
nodeLookup: adoptNodes(s, nodes),
|
|
292
|
+
visibleNodeIds: sameVisible ? s.visibleNodeIds : visible,
|
|
293
|
+
parentIds: sameParents ? s.parentIds : parentIds,
|
|
294
|
+
selectedNodeCount: selected,
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
setEdges(edges) {
|
|
299
|
+
set({ edges, edgeLookup: new Map(edges.map((edge) => [edge.id, edge])) });
|
|
300
|
+
},
|
|
301
|
+
setMinZoom: (minZoom) => { set({ minZoom }); store.getState().setTransform(store.getState().transform); },
|
|
302
|
+
setMaxZoom: (maxZoom) => { set({ maxZoom }); store.getState().setTransform(store.getState().transform); },
|
|
303
|
+
setTranslateExtent: (translateExtent) => { set({ translateExtent }); store.getState().setTransform(store.getState().transform); },
|
|
304
|
+
updateNodeInternals(ids) {
|
|
305
|
+
// Re-measures the given nodes from the DOM (React Flow's forced update), then rebuilds the internals.
|
|
306
|
+
const force = store.getState().forceMeasure;
|
|
307
|
+
if (ids?.length && force)
|
|
308
|
+
force(ids);
|
|
309
|
+
else
|
|
310
|
+
set((s) => ({ nodeLookup: adoptNodes(s, s.nodes) }));
|
|
311
|
+
},
|
|
312
|
+
panBy({ x, y }, event) {
|
|
313
|
+
const [tx, ty, zoom] = store.getState().transform;
|
|
314
|
+
if (!x && !y)
|
|
315
|
+
return false;
|
|
316
|
+
store.getState().setTransform([tx + x, ty + y, zoom], event);
|
|
317
|
+
const next = store.getState().transform;
|
|
318
|
+
return next[0] !== tx || next[1] !== ty;
|
|
319
|
+
},
|
|
320
|
+
updateNodePositions(items, dragging = false) {
|
|
321
|
+
const { nodeLookup, triggerNodeChanges, connection, updateConnection, onNodesChangeMiddlewareMap } = store.getState();
|
|
322
|
+
let changes = [];
|
|
323
|
+
for (const [id, item] of items) {
|
|
324
|
+
const node = nodeLookup.get(id);
|
|
325
|
+
const expandParent = Boolean(node?.expandParent && node?.parentId && item.position);
|
|
326
|
+
changes.push({
|
|
327
|
+
id,
|
|
328
|
+
type: "position",
|
|
329
|
+
position: expandParent ? { x: Math.max(0, item.position.x), y: Math.max(0, item.position.y) } : item.position,
|
|
330
|
+
dragging,
|
|
331
|
+
});
|
|
332
|
+
if (node && connection.inProgress && connection.fromNode?.id === node.id) {
|
|
333
|
+
updateConnection({ ...connection, from: getHandlePosition(node, connection.fromHandle, "left", true) });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
for (const middleware of onNodesChangeMiddlewareMap.values())
|
|
337
|
+
changes = middleware(changes);
|
|
338
|
+
triggerNodeChanges(changes);
|
|
339
|
+
},
|
|
340
|
+
updateConnection(connection) {
|
|
341
|
+
set({ connection });
|
|
342
|
+
},
|
|
343
|
+
cancelConnection() {
|
|
344
|
+
set({ connection: initialConnection });
|
|
345
|
+
},
|
|
346
|
+
setTransform(transform, event) {
|
|
347
|
+
// A new transform interrupts a running animation, as d3-zoom's do.
|
|
348
|
+
animations.set(store, (animations.get(store) ?? 0) + 1);
|
|
349
|
+
applyTransform(store, transform, event);
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
const scale = (zoom, duration) => {
|
|
353
|
+
const { transform, width, height, minZoom, maxZoom } = store.getState();
|
|
354
|
+
zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
|
355
|
+
const cx = width / 2;
|
|
356
|
+
const cy = height / 2;
|
|
357
|
+
const k = zoom / transform[2];
|
|
358
|
+
return animateTo(store, [cx - (cx - transform[0]) * k, cy - (cy - transform[1]) * k, zoom], duration);
|
|
359
|
+
};
|
|
360
|
+
state.panZoom = {
|
|
361
|
+
setViewport: (viewport, options) => animateTo(store, [viewport.x, viewport.y, viewport.zoom], options?.duration),
|
|
362
|
+
getViewport: () => {
|
|
363
|
+
const [x, y, zoom] = store.getState().transform;
|
|
364
|
+
return { x, y, zoom };
|
|
365
|
+
},
|
|
366
|
+
scaleTo: (zoom, options) => scale(zoom, options?.duration),
|
|
367
|
+
scaleBy: (factor, options) => scale(store.getState().transform[2] * factor, options?.duration),
|
|
368
|
+
setScaleExtent: ([minZoom, maxZoom]) => set({ minZoom, maxZoom }),
|
|
369
|
+
};
|
|
370
|
+
return store;
|
|
371
|
+
}
|
|
372
|
+
/** The visible box of nodes (absolute, measured). */
|
|
373
|
+
export function nodesBounds(state, ids, includeHidden) {
|
|
374
|
+
let minX = Infinity;
|
|
375
|
+
let minY = Infinity;
|
|
376
|
+
let maxX = -Infinity;
|
|
377
|
+
let maxY = -Infinity;
|
|
378
|
+
for (const node of state.nodeLookup.values()) {
|
|
379
|
+
if (ids && !ids.has(node.id))
|
|
380
|
+
continue;
|
|
381
|
+
if (node.hidden && !includeHidden)
|
|
382
|
+
continue;
|
|
383
|
+
const { width, height } = node.measured;
|
|
384
|
+
if (!width || !height)
|
|
385
|
+
continue;
|
|
386
|
+
const { x, y } = node.internals.positionAbsolute;
|
|
387
|
+
minX = Math.min(minX, x);
|
|
388
|
+
minY = Math.min(minY, y);
|
|
389
|
+
maxX = Math.max(maxX, x + width);
|
|
390
|
+
maxY = Math.max(maxY, y + height);
|
|
391
|
+
}
|
|
392
|
+
return minX === Infinity ? null : { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* xyflow's getViewportForBounds (@xyflow/system, MIT): a numeric padding
|
|
396
|
+
* becomes whole px per side, then the view shifts where a side got less.
|
|
397
|
+
*/
|
|
398
|
+
export function viewportForBounds(bounds, width, height, minZoom, maxZoom, padding) {
|
|
399
|
+
const px = (value, size) => typeof value === "number" ? Math.floor((size - size / (1 + value)) * 0.5) : value.endsWith("%") ? Math.floor(size * parseFloat(value) / 100) : Math.floor(parseFloat(value));
|
|
400
|
+
const p = typeof padding === "object" ? padding : { x: padding, y: padding };
|
|
401
|
+
const left = px(p.left ?? p.x ?? 0, width), right = px(p.right ?? p.x ?? 0, width);
|
|
402
|
+
const top = px(p.top ?? p.y ?? 0, height), bottom = px(p.bottom ?? p.y ?? 0, height);
|
|
403
|
+
const xZoom = (width - left - right) / bounds.width;
|
|
404
|
+
const yZoom = (height - top - bottom) / bounds.height;
|
|
405
|
+
const zoom = Math.min(maxZoom, Math.max(minZoom, Math.min(xZoom, yZoom)));
|
|
406
|
+
const x = width / 2 - (bounds.x + bounds.width / 2) * zoom;
|
|
407
|
+
const y = height / 2 - (bounds.y + bounds.height / 2) * zoom;
|
|
408
|
+
const applied = {
|
|
409
|
+
left: Math.floor(bounds.x * zoom + x),
|
|
410
|
+
top: Math.floor(bounds.y * zoom + y),
|
|
411
|
+
right: Math.floor(width - ((bounds.x + bounds.width) * zoom + x)),
|
|
412
|
+
bottom: Math.floor(height - ((bounds.y + bounds.height) * zoom + y)),
|
|
413
|
+
};
|
|
414
|
+
const offset = {
|
|
415
|
+
left: Math.min(applied.left - left, 0),
|
|
416
|
+
top: Math.min(applied.top - top, 0),
|
|
417
|
+
right: Math.min(applied.right - right, 0),
|
|
418
|
+
bottom: Math.min(applied.bottom - bottom, 0),
|
|
419
|
+
};
|
|
420
|
+
return [x - offset.left + offset.right, y - offset.top + offset.bottom, zoom];
|
|
421
|
+
}
|
|
422
|
+
export function animateTo(store, target, options = 0) {
|
|
423
|
+
if (!target.every(Number.isFinite) || target[2] <= 0)
|
|
424
|
+
return Promise.resolve(false);
|
|
425
|
+
target = constrainTransform(store.getState(), target);
|
|
426
|
+
const opts = typeof options === "number" ? { duration: options } : options;
|
|
427
|
+
const duration = opts.duration ?? 0;
|
|
428
|
+
const from = store.getState().transform;
|
|
429
|
+
if (!duration || typeof requestAnimationFrame === "undefined") {
|
|
430
|
+
store.getState().setTransform(target);
|
|
431
|
+
return Promise.resolve(true);
|
|
432
|
+
}
|
|
433
|
+
// This animation replaces any running one; a later transform stops it.
|
|
434
|
+
const token = (animations.get(store) ?? 0) + 1;
|
|
435
|
+
animations.set(store, token);
|
|
436
|
+
return new Promise((resolve) => {
|
|
437
|
+
const start = performance.now();
|
|
438
|
+
const step = (now) => {
|
|
439
|
+
if (animations.get(store) !== token)
|
|
440
|
+
return resolve(false);
|
|
441
|
+
const t = Math.min(1, (now - start) / duration);
|
|
442
|
+
// d3's default cubic in-out.
|
|
443
|
+
const e = opts.ease ? opts.ease(t) : t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
444
|
+
const zoom = opts.interpolate === "linear" ? from[2] + (target[2] - from[2]) * e : from[2] * (target[2] / from[2]) ** e;
|
|
445
|
+
applyTransform(store, [from[0] + (target[0] - from[0]) * e, from[1] + (target[1] - from[1]) * e, zoom]);
|
|
446
|
+
if (t < 1)
|
|
447
|
+
requestAnimationFrame(step);
|
|
448
|
+
else {
|
|
449
|
+
applyTransform(store, target);
|
|
450
|
+
resolve(true);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
requestAnimationFrame(step);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
export function fitView(store, options = {}) {
|
|
457
|
+
const s = store.getState();
|
|
458
|
+
const ids = options.nodes ? new Set(options.nodes.map((n) => n.id)) : null;
|
|
459
|
+
const bounds = nodesBounds(s, ids, options.includeHiddenNodes ?? false);
|
|
460
|
+
if (!bounds || !s.width || !s.height)
|
|
461
|
+
return Promise.resolve(false);
|
|
462
|
+
const target = viewportForBounds(bounds, s.width, s.height, options.minZoom ?? s.minZoom, options.maxZoom ?? s.maxZoom, options.padding ?? 0.1);
|
|
463
|
+
return animateTo(store, target, options);
|
|
464
|
+
}
|
|
465
|
+
/** The useReactFlow() instance for a store. */
|
|
466
|
+
export function createInstance(store) {
|
|
467
|
+
// setNodes/setEdges batch in a tick, each updater seeing the last one's result.
|
|
468
|
+
let pendingNodes = null;
|
|
469
|
+
let pendingEdges = null;
|
|
470
|
+
let flushing = false;
|
|
471
|
+
const flush = () => {
|
|
472
|
+
flushing = false;
|
|
473
|
+
const s = store.getState();
|
|
474
|
+
if (pendingNodes) {
|
|
475
|
+
const next = pendingNodes;
|
|
476
|
+
pendingNodes = null;
|
|
477
|
+
const lookup = s.nodeLookup;
|
|
478
|
+
const ids = new Set(next.map((n) => n.id));
|
|
479
|
+
const changes = [];
|
|
480
|
+
next.forEach((node, index) => {
|
|
481
|
+
const current = lookup.get(node.id)?.internals.userNode;
|
|
482
|
+
if (!current)
|
|
483
|
+
changes.push({ type: "add", item: node, index });
|
|
484
|
+
else if (current !== node)
|
|
485
|
+
changes.push({ type: "replace", id: node.id, item: node });
|
|
486
|
+
});
|
|
487
|
+
for (const node of s.nodes)
|
|
488
|
+
if (!ids.has(node.id))
|
|
489
|
+
changes.push({ type: "remove", id: node.id });
|
|
490
|
+
if (s.onNodesChange)
|
|
491
|
+
s.triggerNodeChanges(changes);
|
|
492
|
+
else
|
|
493
|
+
s.setNodes(next);
|
|
494
|
+
}
|
|
495
|
+
if (pendingEdges) {
|
|
496
|
+
const next = pendingEdges;
|
|
497
|
+
pendingEdges = null;
|
|
498
|
+
const ids = new Set(next.map((e) => e.id));
|
|
499
|
+
const changes = [];
|
|
500
|
+
next.forEach((edge, index) => {
|
|
501
|
+
const current = s.edgeLookup.get(edge.id);
|
|
502
|
+
if (!current)
|
|
503
|
+
changes.push({ type: "add", item: edge, index });
|
|
504
|
+
else if (current !== edge)
|
|
505
|
+
changes.push({ type: "replace", id: edge.id, item: edge });
|
|
506
|
+
});
|
|
507
|
+
for (const edge of s.edges)
|
|
508
|
+
if (!ids.has(edge.id))
|
|
509
|
+
changes.push({ type: "remove", id: edge.id });
|
|
510
|
+
if (s.onEdgesChange)
|
|
511
|
+
s.triggerEdgeChanges(changes);
|
|
512
|
+
else
|
|
513
|
+
s.setEdges(next);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const schedule = () => {
|
|
517
|
+
if (flushing)
|
|
518
|
+
return;
|
|
519
|
+
flushing = true;
|
|
520
|
+
queueMicrotask(flush);
|
|
521
|
+
};
|
|
522
|
+
const setNodes = (payload) => {
|
|
523
|
+
const base = pendingNodes ?? store.getState().nodes;
|
|
524
|
+
pendingNodes = typeof payload === "function" ? payload(base) : payload;
|
|
525
|
+
schedule();
|
|
526
|
+
};
|
|
527
|
+
const setEdges = (payload) => {
|
|
528
|
+
const base = pendingEdges ?? store.getState().edges;
|
|
529
|
+
pendingEdges = typeof payload === "function" ? payload(base) : payload;
|
|
530
|
+
schedule();
|
|
531
|
+
};
|
|
532
|
+
const toFlow = (point) => {
|
|
533
|
+
const { domNode, transform } = store.getState();
|
|
534
|
+
const rect = domNode?.getBoundingClientRect() ?? { left: 0, top: 0 };
|
|
535
|
+
return { x: (point.x - rect.left - transform[0]) / transform[2], y: (point.y - rect.top - transform[1]) / transform[2] };
|
|
536
|
+
};
|
|
537
|
+
const zoomBy = (factor, options) => {
|
|
538
|
+
const { transform, width, height, minZoom, maxZoom } = store.getState();
|
|
539
|
+
const zoom = Math.min(maxZoom, Math.max(minZoom, transform[2] * factor));
|
|
540
|
+
const cx = width / 2;
|
|
541
|
+
const cy = height / 2;
|
|
542
|
+
const k = zoom / transform[2];
|
|
543
|
+
return animateTo(store, [cx - (cx - transform[0]) * k, cy - (cy - transform[1]) * k, zoom], options);
|
|
544
|
+
};
|
|
545
|
+
async function deleteElements({ nodes = [], edges = [] }) {
|
|
546
|
+
const s = store.getState();
|
|
547
|
+
const nodeIds = new Set(nodes.map((n) => n.id));
|
|
548
|
+
const removableIds = new Set();
|
|
549
|
+
// Only accepted, deletable parents expand the deletion to descendants.
|
|
550
|
+
// A protected parent or child must not delete the subtree it still owns.
|
|
551
|
+
let grew = true;
|
|
552
|
+
while (grew) {
|
|
553
|
+
grew = false;
|
|
554
|
+
for (const node of s.nodes) {
|
|
555
|
+
if (node.deletable !== false && !removableIds.has(node.id) &&
|
|
556
|
+
(nodeIds.has(node.id) || (node.parentId && removableIds.has(node.parentId)))) {
|
|
557
|
+
removableIds.add(node.id);
|
|
558
|
+
grew = true;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
let matchingNodes = s.nodes.filter((n) => removableIds.has(n.id));
|
|
563
|
+
const edgeIds = new Set(edges.map((e) => e.id));
|
|
564
|
+
const removedNodeIds = new Set(matchingNodes.map((n) => n.id));
|
|
565
|
+
const deletableEdges = s.edges.filter(e => e.deletable !== false);
|
|
566
|
+
let matchingEdges = deletableEdges.filter(e => removedNodeIds.has(e.source) || removedNodeIds.has(e.target));
|
|
567
|
+
const connectedIds = new Set(matchingEdges.map(e => e.id));
|
|
568
|
+
matchingEdges.push(...deletableEdges.filter(e => edgeIds.has(e.id) && !connectedIds.has(e.id)));
|
|
569
|
+
if (s.onBeforeDelete) {
|
|
570
|
+
const answer = await s.onBeforeDelete({ nodes: matchingNodes, edges: matchingEdges });
|
|
571
|
+
if (answer === false)
|
|
572
|
+
return { deletedNodes: [], deletedEdges: [] };
|
|
573
|
+
if (typeof answer === "object") {
|
|
574
|
+
matchingNodes = answer.nodes;
|
|
575
|
+
matchingEdges = answer.edges;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const now = store.getState();
|
|
579
|
+
if (matchingEdges.length) {
|
|
580
|
+
now.onEdgesDelete?.(matchingEdges);
|
|
581
|
+
now.triggerEdgeChanges(matchingEdges.map((e) => ({ type: "remove", id: e.id })));
|
|
582
|
+
}
|
|
583
|
+
if (matchingNodes.length) {
|
|
584
|
+
now.onNodesDelete?.(matchingNodes);
|
|
585
|
+
now.triggerNodeChanges(matchingNodes.map((n) => ({ type: "remove", id: n.id })));
|
|
586
|
+
}
|
|
587
|
+
if (matchingNodes.length || matchingEdges.length)
|
|
588
|
+
now.onDelete?.({ nodes: matchingNodes, edges: matchingEdges });
|
|
589
|
+
return { deletedNodes: matchingNodes, deletedEdges: matchingEdges };
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
getNodes: () => store.getState().nodes.map(node => ({ ...node })),
|
|
593
|
+
getNode: (id) => store.getState().nodeLookup.get(id)?.internals.userNode,
|
|
594
|
+
getInternalNode: (id) => store.getState().nodeLookup.get(id),
|
|
595
|
+
// AVIS: a node's absolute position (inside frames too), no internals.
|
|
596
|
+
getNodePosition: (id) => {
|
|
597
|
+
const node = store.getState().nodeLookup.get(id);
|
|
598
|
+
return node ? { ...node.internals.positionAbsolute } : null;
|
|
599
|
+
},
|
|
600
|
+
// AVIS: a node's box (absolute position, measured size), no internals.
|
|
601
|
+
getNodeBox: (id) => {
|
|
602
|
+
const node = store.getState().nodeLookup.get(id);
|
|
603
|
+
if (!node)
|
|
604
|
+
return null;
|
|
605
|
+
const { x, y } = node.internals.positionAbsolute;
|
|
606
|
+
return { x, y, width: node.measured.width ?? 0, height: node.measured.height ?? 0 };
|
|
607
|
+
},
|
|
608
|
+
getEdges: () => store.getState().edges.map(edge => ({ ...edge })),
|
|
609
|
+
getEdge: (id) => store.getState().edgeLookup.get(id),
|
|
610
|
+
setNodes,
|
|
611
|
+
setEdges,
|
|
612
|
+
addNodes: (payload) => setNodes((nodes) => [...nodes, ...(Array.isArray(payload) ? payload : [payload])]),
|
|
613
|
+
addEdges: (payload) => setEdges((edges) => [...edges, ...(Array.isArray(payload) ? payload : [payload])]),
|
|
614
|
+
updateNode(id, update, options = {}) {
|
|
615
|
+
setNodes((nodes) => nodes.map((node) => {
|
|
616
|
+
if (node.id !== id)
|
|
617
|
+
return node;
|
|
618
|
+
const next = typeof update === "function" ? update(node) : update;
|
|
619
|
+
return (options.replace && next.id && next.position ? next : { ...node, ...next });
|
|
620
|
+
}));
|
|
621
|
+
},
|
|
622
|
+
updateNodeData(id, update, options = {}) {
|
|
623
|
+
setNodes((nodes) => nodes.map((node) => {
|
|
624
|
+
if (node.id !== id)
|
|
625
|
+
return node;
|
|
626
|
+
const next = typeof update === "function" ? update(node) : update;
|
|
627
|
+
return { ...node, data: options.replace ? next : { ...node.data, ...next } };
|
|
628
|
+
}));
|
|
629
|
+
},
|
|
630
|
+
updateEdge(id, update, options = {}) {
|
|
631
|
+
setEdges((edges) => edges.map((edge) => {
|
|
632
|
+
if (edge.id !== id)
|
|
633
|
+
return edge;
|
|
634
|
+
const next = typeof update === "function" ? update(edge) : update;
|
|
635
|
+
return (options.replace && next.id && next.source && next.target ? next : { ...edge, ...next });
|
|
636
|
+
}));
|
|
637
|
+
},
|
|
638
|
+
updateEdgeData(id, update, options = {}) {
|
|
639
|
+
setEdges((edges) => edges.map((edge) => {
|
|
640
|
+
if (edge.id !== id)
|
|
641
|
+
return edge;
|
|
642
|
+
const next = typeof update === "function" ? update(edge) : update;
|
|
643
|
+
return { ...edge, data: options.replace ? next : { ...edge.data, ...next } };
|
|
644
|
+
}));
|
|
645
|
+
},
|
|
646
|
+
deleteElements,
|
|
647
|
+
getViewport: () => {
|
|
648
|
+
const [x, y, zoom] = store.getState().transform;
|
|
649
|
+
return { x, y, zoom };
|
|
650
|
+
},
|
|
651
|
+
setViewport: (viewport, options) => {
|
|
652
|
+
const [x, y, zoom] = store.getState().transform;
|
|
653
|
+
return animateTo(store, [viewport.x ?? x, viewport.y ?? y, viewport.zoom ?? zoom], options);
|
|
654
|
+
},
|
|
655
|
+
getZoom: () => store.getState().transform[2],
|
|
656
|
+
zoomIn: (options) => zoomBy(1.2, options),
|
|
657
|
+
zoomOut: (options) => zoomBy(1 / 1.2, options),
|
|
658
|
+
zoomTo: (zoom, options) => zoomBy(zoom / store.getState().transform[2], options),
|
|
659
|
+
fitView: (options) => fitView(store, options),
|
|
660
|
+
setCenter: (x, y, options = {}) => {
|
|
661
|
+
const { width, height, transform, maxZoom } = store.getState();
|
|
662
|
+
void transform;
|
|
663
|
+
const zoom = options.zoom ?? maxZoom;
|
|
664
|
+
return animateTo(store, [width / 2 - x * zoom, height / 2 - y * zoom, zoom], options);
|
|
665
|
+
},
|
|
666
|
+
fitBounds: (bounds, options = {}) => {
|
|
667
|
+
const { width, height, minZoom, maxZoom } = store.getState();
|
|
668
|
+
return animateTo(store, viewportForBounds(bounds, width, height, minZoom, maxZoom, options.padding ?? 0.1), options);
|
|
669
|
+
},
|
|
670
|
+
screenToFlowPosition: (point, options = {}) => {
|
|
671
|
+
const p = toFlow(point);
|
|
672
|
+
const { snapGrid, snapToGrid } = store.getState();
|
|
673
|
+
if (options.snapToGrid ?? snapToGrid) {
|
|
674
|
+
return { x: snapGrid[0] * Math.round(p.x / snapGrid[0]), y: snapGrid[1] * Math.round(p.y / snapGrid[1]) };
|
|
675
|
+
}
|
|
676
|
+
return p;
|
|
677
|
+
},
|
|
678
|
+
flowToScreenPosition: (point) => {
|
|
679
|
+
const { domNode, transform } = store.getState();
|
|
680
|
+
const rect = domNode?.getBoundingClientRect() ?? { left: 0, top: 0 };
|
|
681
|
+
return { x: point.x * transform[2] + transform[0] + rect.left, y: point.y * transform[2] + transform[1] + rect.top };
|
|
682
|
+
},
|
|
683
|
+
getNodesBounds: (nodes) => {
|
|
684
|
+
const rects = nodes.map(n => queryRect(store.getState(), typeof n === "string" ? { id: n } : n)).filter((r) => !!r);
|
|
685
|
+
if (!rects.length)
|
|
686
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
687
|
+
const x = Math.min(...rects.map(r => r.x)), y = Math.min(...rects.map(r => r.y));
|
|
688
|
+
return { x, y, width: Math.max(...rects.map(r => r.x + r.width)) - x, height: Math.max(...rects.map(r => r.y + r.height)) - y };
|
|
689
|
+
},
|
|
690
|
+
getIntersectingNodes: (input, partially = true, nodes) => {
|
|
691
|
+
const state = store.getState(), rect = queryRect(state, input);
|
|
692
|
+
if (!rect)
|
|
693
|
+
return [];
|
|
694
|
+
return (nodes ?? state.nodes).filter(node => {
|
|
695
|
+
if ("id" in input && input.id === node.id)
|
|
696
|
+
return false;
|
|
697
|
+
const other = queryRect(state, node);
|
|
698
|
+
return other && intersects(other, rect, partially);
|
|
699
|
+
});
|
|
700
|
+
},
|
|
701
|
+
isNodeIntersecting: (input, area, partially = true) => {
|
|
702
|
+
const rect = queryRect(store.getState(), input);
|
|
703
|
+
return !!rect && intersects(rect, area, partially);
|
|
704
|
+
},
|
|
705
|
+
getHandleConnections: ({ type, id = null, nodeId }) => nodeConnections(store.getState(), { nodeId, type, handleId: id }),
|
|
706
|
+
getNodeConnections: (query) => nodeConnections(store.getState(), query),
|
|
707
|
+
toObject: () => {
|
|
708
|
+
const s = store.getState();
|
|
709
|
+
return { nodes: s.nodes.map(node => ({ ...node })), edges: s.edges.map(edge => ({ ...edge })), viewport: { x: s.transform[0], y: s.transform[1], zoom: s.transform[2] } };
|
|
710
|
+
},
|
|
711
|
+
get viewportInitialized() { return store.getState().domNode !== null; },
|
|
712
|
+
};
|
|
713
|
+
}
|