@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,744 @@
|
|
|
1
|
+
import { anchorPoint } from "../geometry/anchors.js";
|
|
2
|
+
import { intersects } from "../geometry/bounds.js";
|
|
3
|
+
import { applyToPoint, identity, invert } from "../geometry/matrix.js";
|
|
4
|
+
import { DragEvent, PointerEvent, } from "../events/event.js";
|
|
5
|
+
import { anchorWorldPoint } from "./hit-test.js";
|
|
6
|
+
const off = (controller, ids) => () => controller.eventer.off_(ids);
|
|
7
|
+
const worldOrigin = (node) => applyToPoint(node.world, { x: 0, y: 0 });
|
|
8
|
+
const parentInverse = (node) => (node.parent ? invert(node.parent.world) : null) ?? identity();
|
|
9
|
+
const pointerWorld = (controller, event) => controller.toWorld({ x: event.clientX, y: event.clientY });
|
|
10
|
+
/** Where the press of a drag was, in world space. */
|
|
11
|
+
const pressWorld = (controller, event) => controller.toWorld({
|
|
12
|
+
x: event.clientX - event.totalX,
|
|
13
|
+
y: event.clientY - event.totalY,
|
|
14
|
+
});
|
|
15
|
+
function select(controller, selectedIds, selectedRelationIds) {
|
|
16
|
+
controller.engine.store.set("interaction", {
|
|
17
|
+
selectedIds: [...selectedIds],
|
|
18
|
+
...(selectedRelationIds
|
|
19
|
+
? { selectedRelationIds: [...selectedRelationIds] }
|
|
20
|
+
: {}),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// ---- hover and cursor ---------------------------------------------------
|
|
24
|
+
const CURSORS = {
|
|
25
|
+
nw: "nwse-resize",
|
|
26
|
+
se: "nwse-resize",
|
|
27
|
+
ne: "nesw-resize",
|
|
28
|
+
sw: "nesw-resize",
|
|
29
|
+
rotate: "grab",
|
|
30
|
+
};
|
|
31
|
+
export const hoverBehavior = (controller) => {
|
|
32
|
+
const { engine, eventer } = controller;
|
|
33
|
+
return off(controller, [
|
|
34
|
+
eventer.on(PointerEvent.ENTER, (event) => {
|
|
35
|
+
const target = event.current;
|
|
36
|
+
if (target.kind === "node")
|
|
37
|
+
engine.store.set("interaction", { hoveredId: target.id });
|
|
38
|
+
if (target.kind === "edge") {
|
|
39
|
+
engine.store.set("interaction", { hoveredRelationId: target.id });
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
eventer.on(PointerEvent.LEAVE, (event) => {
|
|
43
|
+
const target = event.current;
|
|
44
|
+
const state = engine.store.get().interaction;
|
|
45
|
+
if (target.kind === "node" && state.hoveredId === target.id) {
|
|
46
|
+
engine.store.set("interaction", { hoveredId: null });
|
|
47
|
+
}
|
|
48
|
+
if (target.kind === "edge" && state.hoveredRelationId === target.id) {
|
|
49
|
+
engine.store.set("interaction", { hoveredRelationId: null });
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
eventer.on(PointerEvent.OVER, (event) => {
|
|
53
|
+
if (event.current !== event.target)
|
|
54
|
+
return;
|
|
55
|
+
const target = event.target;
|
|
56
|
+
const { tool } = engine.store.get().interaction;
|
|
57
|
+
const cursor = target.kind === "pane"
|
|
58
|
+
? tool === "hand" || controller.keys.space
|
|
59
|
+
? "grab"
|
|
60
|
+
: "default"
|
|
61
|
+
: target.kind === "handle"
|
|
62
|
+
? "crosshair"
|
|
63
|
+
: target.kind === "edge"
|
|
64
|
+
? "pointer"
|
|
65
|
+
: target.kind === "transform"
|
|
66
|
+
? CURSORS[target.handle]
|
|
67
|
+
: "grab";
|
|
68
|
+
engine.store.set("interaction", { cursor });
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
};
|
|
72
|
+
// ---- select ---------------------------------------------------------------
|
|
73
|
+
export const selectBehavior = (controller) => {
|
|
74
|
+
const { engine, eventer, events } = controller;
|
|
75
|
+
return off(controller, [
|
|
76
|
+
eventer.on(PointerEvent.TAP, (event) => {
|
|
77
|
+
const target = event.current;
|
|
78
|
+
const multi = controller.isMultiSelect(event.input);
|
|
79
|
+
const { selectedIds, selectedRelationIds } = engine.store.get().interaction;
|
|
80
|
+
if (target.kind === "handle") {
|
|
81
|
+
events.emit("anchor:tap", {
|
|
82
|
+
nodeId: target.nodeId,
|
|
83
|
+
anchor: target.handle,
|
|
84
|
+
input: event.input,
|
|
85
|
+
});
|
|
86
|
+
// The tap goes on to the node (React Flow selects it).
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (target.kind === "node") {
|
|
90
|
+
// xyflow's handleNodeClick.
|
|
91
|
+
const selected = selectedIds.includes(target.id);
|
|
92
|
+
if (!selected) {
|
|
93
|
+
if (multi)
|
|
94
|
+
select(controller, [...selectedIds, target.id]);
|
|
95
|
+
else
|
|
96
|
+
select(controller, [target.id], []);
|
|
97
|
+
}
|
|
98
|
+
else if (multi) {
|
|
99
|
+
select(controller, selectedIds.filter((id) => id !== target.id));
|
|
100
|
+
}
|
|
101
|
+
events.emit("node:tap", { id: target.id, input: event.input });
|
|
102
|
+
event.stop();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (target.kind === "edge") {
|
|
106
|
+
// xyflow's EdgeWrapper click.
|
|
107
|
+
const selected = selectedRelationIds.includes(target.id);
|
|
108
|
+
if (selected && multi) {
|
|
109
|
+
select(controller, selectedIds, selectedRelationIds.filter((id) => id !== target.id));
|
|
110
|
+
}
|
|
111
|
+
else if (multi) {
|
|
112
|
+
select(controller, selectedIds, [...selectedRelationIds, target.id]);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
select(controller, [], [target.id]);
|
|
116
|
+
}
|
|
117
|
+
events.emit("relation:tap", { id: target.id, input: event.input });
|
|
118
|
+
event.stop();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (target.kind === "pane" && event.target.kind === "pane") {
|
|
122
|
+
// A Shift-tap is a box that never started: nothing happens.
|
|
123
|
+
if (!event.shiftKey)
|
|
124
|
+
select(controller, [], []);
|
|
125
|
+
events.emit("pane:tap", {
|
|
126
|
+
point: pointerWorld(controller, event),
|
|
127
|
+
input: event.input,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}, { on: ["handle", "node", "edge", "pane"] }),
|
|
131
|
+
eventer.on(PointerEvent.DOUBLE_TAP, (event) => {
|
|
132
|
+
const target = event.current;
|
|
133
|
+
if (target.kind === "node") {
|
|
134
|
+
events.emit("node:doubletap", { id: target.id, input: event.input });
|
|
135
|
+
event.stop();
|
|
136
|
+
}
|
|
137
|
+
}, { on: "node" }),
|
|
138
|
+
eventer.on(PointerEvent.MENU, (event) => {
|
|
139
|
+
const target = event.current;
|
|
140
|
+
if (target.kind === "node") {
|
|
141
|
+
events.emit("node:menu", { id: target.id, input: event.input });
|
|
142
|
+
}
|
|
143
|
+
else if (target.kind === "edge") {
|
|
144
|
+
events.emit("relation:menu", { id: target.id, input: event.input });
|
|
145
|
+
}
|
|
146
|
+
else if (target.kind === "pane") {
|
|
147
|
+
events.emit("pane:menu", {
|
|
148
|
+
point: pointerWorld(controller, event),
|
|
149
|
+
input: event.input,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
event.stopDefault();
|
|
156
|
+
event.stop();
|
|
157
|
+
}, { on: ["node", "edge", "pane"] }),
|
|
158
|
+
]);
|
|
159
|
+
};
|
|
160
|
+
// ---- marquee ----------------------------------------------------------------
|
|
161
|
+
export const marqueeBehavior = (controller) => {
|
|
162
|
+
const { engine, eventer, events, arbiter } = controller;
|
|
163
|
+
let start = null;
|
|
164
|
+
let picked = [];
|
|
165
|
+
// The move that starts a drag counts as its first move.
|
|
166
|
+
const onDrag = (event) => {
|
|
167
|
+
if (!start || arbiter.current !== "marquee")
|
|
168
|
+
return;
|
|
169
|
+
const point = pointerWorld(controller, event);
|
|
170
|
+
const box = {
|
|
171
|
+
minX: Math.min(start.x, point.x),
|
|
172
|
+
minY: Math.min(start.y, point.y),
|
|
173
|
+
maxX: Math.max(start.x, point.x),
|
|
174
|
+
maxY: Math.max(start.y, point.y),
|
|
175
|
+
};
|
|
176
|
+
// Partly inside counts (xyflow's SelectionMode.Partial).
|
|
177
|
+
picked = [...engine.scene.walk()]
|
|
178
|
+
.filter((node) => node.record.visible && intersects(node.worldBounds, box))
|
|
179
|
+
.map((node) => node.id);
|
|
180
|
+
const set = new Set(picked);
|
|
181
|
+
const relations = Object.values(engine.store.get().document.relations)
|
|
182
|
+
.filter((relation) => set.has(relation.source.nodeId) || set.has(relation.target.nodeId))
|
|
183
|
+
.map((relation) => relation.id);
|
|
184
|
+
engine.store.set("interaction", {
|
|
185
|
+
marquee: box,
|
|
186
|
+
selectedIds: picked,
|
|
187
|
+
selectedRelationIds: relations,
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
return off(controller, [
|
|
191
|
+
eventer.on(DragEvent.START, (event) => {
|
|
192
|
+
if (event.target.kind !== "pane" || event.input.button !== 0)
|
|
193
|
+
return;
|
|
194
|
+
const { tool } = engine.store.get().interaction;
|
|
195
|
+
const keyed = event.shiftKey;
|
|
196
|
+
if (!keyed && (tool !== "select" || controller.keys.space))
|
|
197
|
+
return;
|
|
198
|
+
if (!arbiter.claim("marquee"))
|
|
199
|
+
return;
|
|
200
|
+
start = controller.toWorld({
|
|
201
|
+
x: event.clientX - event.totalX,
|
|
202
|
+
y: event.clientY - event.totalY,
|
|
203
|
+
});
|
|
204
|
+
picked = [];
|
|
205
|
+
// Starting clears the selection (xyflow's pane).
|
|
206
|
+
engine.store.set("interaction", {
|
|
207
|
+
selectedIds: [],
|
|
208
|
+
selectedRelationIds: [],
|
|
209
|
+
marquee: {
|
|
210
|
+
minX: start.x,
|
|
211
|
+
minY: start.y,
|
|
212
|
+
maxX: start.x,
|
|
213
|
+
maxY: start.y,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
events.emit("marquee:start", undefined);
|
|
217
|
+
onDrag(event);
|
|
218
|
+
}, { on: "pane" }),
|
|
219
|
+
eventer.on(DragEvent.DRAG, onDrag, { on: "pane" }),
|
|
220
|
+
eventer.on(DragEvent.END, () => {
|
|
221
|
+
if (!start || arbiter.current !== "marquee")
|
|
222
|
+
return;
|
|
223
|
+
start = null;
|
|
224
|
+
arbiter.release("marquee");
|
|
225
|
+
engine.store.set("interaction", { marquee: null });
|
|
226
|
+
events.emit("marquee:end", { ids: picked });
|
|
227
|
+
}, { on: "pane" }),
|
|
228
|
+
]);
|
|
229
|
+
};
|
|
230
|
+
// ---- pan and zoom ---------------------------------------------------------
|
|
231
|
+
export const panBehavior = (controller) => {
|
|
232
|
+
const { engine, eventer, arbiter } = controller;
|
|
233
|
+
return off(controller, [
|
|
234
|
+
// In capture, before node and pane gestures: the middle button pans
|
|
235
|
+
// over a node too.
|
|
236
|
+
eventer.on(DragEvent.START, (event) => {
|
|
237
|
+
if (event.current.kind !== "pane")
|
|
238
|
+
return;
|
|
239
|
+
const { tool } = engine.store.get().interaction;
|
|
240
|
+
const pans = event.input.button === 1 ||
|
|
241
|
+
(event.target.kind === "pane" &&
|
|
242
|
+
(tool === "hand" || controller.keys.space));
|
|
243
|
+
if (!pans || !arbiter.claim("pan"))
|
|
244
|
+
return;
|
|
245
|
+
engine.store.set("interaction", { cursor: "grabbing" });
|
|
246
|
+
// The move that started the drag pans too (d3-zoom pans from the press).
|
|
247
|
+
engine.viewport.panBy(event.moveX, event.moveY);
|
|
248
|
+
event.stopNow();
|
|
249
|
+
}, { capture: true }),
|
|
250
|
+
eventer.on(DragEvent.DRAG, (event) => {
|
|
251
|
+
if (arbiter.current !== "pan" || event.current.kind !== "pane")
|
|
252
|
+
return;
|
|
253
|
+
engine.viewport.panBy(event.moveX, event.moveY);
|
|
254
|
+
event.stopNow();
|
|
255
|
+
}, { capture: true }),
|
|
256
|
+
eventer.on(DragEvent.END, (event) => {
|
|
257
|
+
if (arbiter.current !== "pan" || event.current.kind !== "pane")
|
|
258
|
+
return;
|
|
259
|
+
arbiter.release("pan");
|
|
260
|
+
engine.store.set("interaction", { cursor: "grab" });
|
|
261
|
+
event.stopNow();
|
|
262
|
+
}, { capture: true }),
|
|
263
|
+
eventer.on(PointerEvent.DOUBLE_TAP, (event) => {
|
|
264
|
+
if (event.target.kind !== "pane")
|
|
265
|
+
return;
|
|
266
|
+
const { zoom } = engine.store.get().viewport.camera;
|
|
267
|
+
engine.viewport.zoomAt({ x: event.clientX, y: event.clientY }, zoom * 2);
|
|
268
|
+
}, { on: "pane" }),
|
|
269
|
+
]);
|
|
270
|
+
};
|
|
271
|
+
const snap = (value, step) => step * Math.round(value / step);
|
|
272
|
+
export const dragBehavior = (controller) => {
|
|
273
|
+
const { engine, eventer, events, arbiter, options } = controller;
|
|
274
|
+
let drag = null;
|
|
275
|
+
const finish = (cancelled) => {
|
|
276
|
+
const current = drag;
|
|
277
|
+
drag = null;
|
|
278
|
+
arbiter.release("drag");
|
|
279
|
+
if (!current)
|
|
280
|
+
return;
|
|
281
|
+
const preview = engine.store.get().interaction.preview;
|
|
282
|
+
const ids = current.items.map((item) => item.id);
|
|
283
|
+
engine.store.batch(() => {
|
|
284
|
+
if (!cancelled) {
|
|
285
|
+
const moved = current.items.filter((item) => {
|
|
286
|
+
const next = preview[item.id];
|
|
287
|
+
return next && (next.x !== item.from.x || next.y !== item.from.y);
|
|
288
|
+
});
|
|
289
|
+
if (moved.length) {
|
|
290
|
+
engine.transact("drag", (tx) => {
|
|
291
|
+
for (const item of moved) {
|
|
292
|
+
const next = preview[item.id];
|
|
293
|
+
tx.run("node.move", {
|
|
294
|
+
id: item.id,
|
|
295
|
+
position: { x: next.x, y: next.y },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
engine.store.set("interaction", { preview: {}, cursor: "grab" });
|
|
302
|
+
});
|
|
303
|
+
events.emit("drag:end", { ids, cancelled });
|
|
304
|
+
};
|
|
305
|
+
// The move that starts a drag counts as its first move.
|
|
306
|
+
const onDrag = (event) => {
|
|
307
|
+
if (!drag || event.current !== event.target)
|
|
308
|
+
return;
|
|
309
|
+
const point = pointerWorld(controller, event);
|
|
310
|
+
const dx = point.x - drag.pointer.x;
|
|
311
|
+
const dy = point.y - drag.pointer.y;
|
|
312
|
+
const [gx, gy] = options.snapGrid;
|
|
313
|
+
// A selection snaps by its first node's offset (xyflow).
|
|
314
|
+
const first = drag.items[0];
|
|
315
|
+
const offset = options.snapToGrid && first
|
|
316
|
+
? {
|
|
317
|
+
x: snap(first.start.x + dx, gx) - (first.start.x + dx),
|
|
318
|
+
y: snap(first.start.y + dy, gy) - (first.start.y + dy),
|
|
319
|
+
}
|
|
320
|
+
: { x: 0, y: 0 };
|
|
321
|
+
const preview = {};
|
|
322
|
+
for (const item of drag.items) {
|
|
323
|
+
const world = {
|
|
324
|
+
x: item.start.x + dx + offset.x,
|
|
325
|
+
y: item.start.y + dy + offset.y,
|
|
326
|
+
};
|
|
327
|
+
const local = applyToPoint(item.parentInverse, world);
|
|
328
|
+
preview[item.id] = {
|
|
329
|
+
x: options.snapToGrid && drag.items.length > 1
|
|
330
|
+
? Math.round(local.x)
|
|
331
|
+
: local.x,
|
|
332
|
+
y: options.snapToGrid && drag.items.length > 1
|
|
333
|
+
? Math.round(local.y)
|
|
334
|
+
: local.y,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
engine.store.set("interaction", { preview });
|
|
338
|
+
};
|
|
339
|
+
return off(controller, [
|
|
340
|
+
eventer.on(DragEvent.START, (event) => {
|
|
341
|
+
const target = event.current;
|
|
342
|
+
if (target.kind !== "node" || event.target !== target)
|
|
343
|
+
return;
|
|
344
|
+
if (event.input.button !== 0 || controller.keys.space)
|
|
345
|
+
return;
|
|
346
|
+
const state = engine.store.get().interaction;
|
|
347
|
+
if (state.tool === "hand")
|
|
348
|
+
return;
|
|
349
|
+
const node = engine.scene.get(target.id);
|
|
350
|
+
if (!node || node.record.locked || !arbiter.claim("drag"))
|
|
351
|
+
return;
|
|
352
|
+
event.stop();
|
|
353
|
+
const multi = controller.isMultiSelect(event.input);
|
|
354
|
+
let selection = state.selectedIds;
|
|
355
|
+
if (!selection.includes(target.id)) {
|
|
356
|
+
if (options.selectOnDrag) {
|
|
357
|
+
selection = multi ? [...selection, target.id] : [target.id];
|
|
358
|
+
select(controller, selection, multi ? undefined : []);
|
|
359
|
+
}
|
|
360
|
+
else if (!multi) {
|
|
361
|
+
// xyflow with selectNodesOnDrag off: the node moves alone and the
|
|
362
|
+
// selection clears.
|
|
363
|
+
selection = [];
|
|
364
|
+
select(controller, [], []);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const moving = new Set([...selection, target.id]);
|
|
368
|
+
const items = [];
|
|
369
|
+
for (const id of moving) {
|
|
370
|
+
const each = engine.scene.get(id);
|
|
371
|
+
if (!each || each.record.locked)
|
|
372
|
+
continue;
|
|
373
|
+
// A node moves with its frame when the frame moves too.
|
|
374
|
+
if ([...engine.scene.ancestors(id)].some((ancestor) => moving.has(ancestor.id)))
|
|
375
|
+
continue;
|
|
376
|
+
items.push({
|
|
377
|
+
id: each.id,
|
|
378
|
+
start: worldOrigin(each),
|
|
379
|
+
parentInverse: parentInverse(each),
|
|
380
|
+
from: { x: each.record.transform.x, y: each.record.transform.y },
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
// XYDrag measures from where the drag starts: the press with no
|
|
384
|
+
// threshold, else the first move past it (the node lags by it).
|
|
385
|
+
drag = {
|
|
386
|
+
items,
|
|
387
|
+
pointer: options.dragThreshold > 0
|
|
388
|
+
? pointerWorld(controller, event)
|
|
389
|
+
: pressWorld(controller, event),
|
|
390
|
+
};
|
|
391
|
+
engine.store.set("interaction", { cursor: "grabbing" });
|
|
392
|
+
events.emit("drag:start", { ids: items.map((item) => item.id) });
|
|
393
|
+
onDrag(event);
|
|
394
|
+
}, { on: "node" }),
|
|
395
|
+
eventer.on(DragEvent.DRAG, onDrag, { on: "node" }),
|
|
396
|
+
eventer.on(DragEvent.END, (event) => {
|
|
397
|
+
if (!drag || event.current !== event.target)
|
|
398
|
+
return;
|
|
399
|
+
finish(event.cancelled);
|
|
400
|
+
}, { on: "node" }),
|
|
401
|
+
]);
|
|
402
|
+
};
|
|
403
|
+
// ---- transform: resize and rotate ----------------------------------------------
|
|
404
|
+
export const transformBehavior = (controller) => {
|
|
405
|
+
const { engine, eventer, arbiter } = controller;
|
|
406
|
+
let state = null;
|
|
407
|
+
const finish = (cancelled) => {
|
|
408
|
+
const current = state;
|
|
409
|
+
state = null;
|
|
410
|
+
arbiter.release("transform");
|
|
411
|
+
if (!current)
|
|
412
|
+
return;
|
|
413
|
+
const { preview, previewSize } = engine.store.get().interaction;
|
|
414
|
+
engine.store.batch(() => {
|
|
415
|
+
if (!cancelled && preview[current.id]) {
|
|
416
|
+
engine.transact("transform", (tx) => tx.run("node.transform", {
|
|
417
|
+
id: current.id,
|
|
418
|
+
transform: preview[current.id],
|
|
419
|
+
size: previewSize[current.id],
|
|
420
|
+
}));
|
|
421
|
+
}
|
|
422
|
+
engine.store.set("interaction", { preview: {}, previewSize: {} });
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
// The move that starts a drag counts as its first move.
|
|
426
|
+
const onDrag = (event) => {
|
|
427
|
+
if (!state || event.target.kind !== "transform")
|
|
428
|
+
return;
|
|
429
|
+
const { w, h } = state.size;
|
|
430
|
+
const world = pointerWorld(controller, event);
|
|
431
|
+
if (state.handle === "rotate") {
|
|
432
|
+
const center = applyToPoint(state.local, { x: w / 2, y: h / 2 });
|
|
433
|
+
const point = applyToPoint(state.parentInverse, world);
|
|
434
|
+
let rotation = state.transform.rotation +
|
|
435
|
+
Math.atan2(point.y - center.y, point.x - center.x) -
|
|
436
|
+
state.startAngle;
|
|
437
|
+
if (event.shiftKey)
|
|
438
|
+
rotation = Math.round(rotation / (Math.PI / 12)) * (Math.PI / 12);
|
|
439
|
+
// About the centre: the origin moves so the centre stays.
|
|
440
|
+
const { scaleX, scaleY } = state.transform;
|
|
441
|
+
const cos = Math.cos(rotation);
|
|
442
|
+
const sin = Math.sin(rotation);
|
|
443
|
+
const hx = (scaleX * w) / 2;
|
|
444
|
+
const hy = (scaleY * h) / 2;
|
|
445
|
+
engine.store.set("interaction", {
|
|
446
|
+
preview: {
|
|
447
|
+
[state.id]: {
|
|
448
|
+
x: center.x - (cos * hx - sin * hy),
|
|
449
|
+
y: center.y - (sin * hx + cos * hy),
|
|
450
|
+
rotation,
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const pointer = applyToPoint(state.worldInverse, world);
|
|
457
|
+
const fixed = {
|
|
458
|
+
nw: { x: w, y: h },
|
|
459
|
+
ne: { x: 0, y: h },
|
|
460
|
+
se: { x: 0, y: 0 },
|
|
461
|
+
sw: { x: w, y: 0 },
|
|
462
|
+
}[state.handle];
|
|
463
|
+
let minX;
|
|
464
|
+
let minY;
|
|
465
|
+
let width;
|
|
466
|
+
let height;
|
|
467
|
+
if (event.altKey) {
|
|
468
|
+
// From the centre: both sides move.
|
|
469
|
+
width = Math.max(1, Math.abs(pointer.x - w / 2) * 2);
|
|
470
|
+
height = Math.max(1, Math.abs(pointer.y - h / 2) * 2);
|
|
471
|
+
if (event.shiftKey) {
|
|
472
|
+
const ratio = w / h || 1;
|
|
473
|
+
if (width / height > ratio)
|
|
474
|
+
height = width / ratio;
|
|
475
|
+
else
|
|
476
|
+
width = height * ratio;
|
|
477
|
+
}
|
|
478
|
+
minX = w / 2 - width / 2;
|
|
479
|
+
minY = h / 2 - height / 2;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
width = Math.max(1, Math.abs(pointer.x - fixed.x));
|
|
483
|
+
height = Math.max(1, Math.abs(pointer.y - fixed.y));
|
|
484
|
+
if (event.shiftKey) {
|
|
485
|
+
const ratio = w / h || 1;
|
|
486
|
+
if (width / height > ratio)
|
|
487
|
+
height = width / ratio;
|
|
488
|
+
else
|
|
489
|
+
width = height * ratio;
|
|
490
|
+
}
|
|
491
|
+
minX = pointer.x < fixed.x ? fixed.x - width : fixed.x;
|
|
492
|
+
minY = pointer.y < fixed.y ? fixed.y - height : fixed.y;
|
|
493
|
+
}
|
|
494
|
+
const origin = applyToPoint(state.local, { x: minX, y: minY });
|
|
495
|
+
engine.store.set("interaction", {
|
|
496
|
+
preview: { [state.id]: { x: origin.x, y: origin.y } },
|
|
497
|
+
previewSize: { [state.id]: { w: width, h: height } },
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
return off(controller, [
|
|
501
|
+
eventer.on(DragEvent.START, (event) => {
|
|
502
|
+
const target = event.current;
|
|
503
|
+
if (target.kind !== "transform" || event.input.button !== 0)
|
|
504
|
+
return;
|
|
505
|
+
const node = engine.scene.get(target.nodeId);
|
|
506
|
+
if (!node || !arbiter.claim("transform"))
|
|
507
|
+
return;
|
|
508
|
+
event.stop();
|
|
509
|
+
const size = engine.scene.sizeOf(node);
|
|
510
|
+
const parentInv = parentInverse(node);
|
|
511
|
+
const center = applyToPoint(node.local, {
|
|
512
|
+
x: size.w / 2,
|
|
513
|
+
y: size.h / 2,
|
|
514
|
+
});
|
|
515
|
+
const start = applyToPoint(parentInv, pressWorld(controller, event));
|
|
516
|
+
state = {
|
|
517
|
+
id: node.id,
|
|
518
|
+
handle: target.handle,
|
|
519
|
+
local: node.local,
|
|
520
|
+
worldInverse: invert(node.world) ?? identity(),
|
|
521
|
+
parentInverse: parentInv,
|
|
522
|
+
size,
|
|
523
|
+
transform: node.record.transform,
|
|
524
|
+
startAngle: Math.atan2(start.y - center.y, start.x - center.x),
|
|
525
|
+
};
|
|
526
|
+
onDrag(event);
|
|
527
|
+
}, { on: "transform" }),
|
|
528
|
+
eventer.on(DragEvent.DRAG, onDrag, { on: "transform" }),
|
|
529
|
+
eventer.on(DragEvent.END, (event) => {
|
|
530
|
+
if (!state || event.target.kind !== "transform")
|
|
531
|
+
return;
|
|
532
|
+
finish(event.cancelled);
|
|
533
|
+
}, { on: "transform" }),
|
|
534
|
+
]);
|
|
535
|
+
};
|
|
536
|
+
// ---- connect (XYHandle) -------------------------------------------------------
|
|
537
|
+
export const connectBehavior = (controller) => {
|
|
538
|
+
const { engine, eventer, events, arbiter, options } = controller;
|
|
539
|
+
let from = null;
|
|
540
|
+
/** The anchor within reach of a world point (xyflow's getClosestHandle). */
|
|
541
|
+
const closest = (point) => {
|
|
542
|
+
if (!from)
|
|
543
|
+
return null;
|
|
544
|
+
let best = [];
|
|
545
|
+
for (const node of engine.scene.walk()) {
|
|
546
|
+
if (!node.record.visible)
|
|
547
|
+
continue;
|
|
548
|
+
for (const anchor of engine.schemas.anchors(node.record)) {
|
|
549
|
+
if (node.id === from.nodeId &&
|
|
550
|
+
anchor.type === from.anchor.type &&
|
|
551
|
+
anchor.id === from.anchor.id) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
const at = anchorWorldPoint(node, anchor);
|
|
555
|
+
const distance = Math.hypot(at.x - point.x, at.y - point.y);
|
|
556
|
+
if (distance > options.connectionRadius)
|
|
557
|
+
continue;
|
|
558
|
+
if (!best.length || distance < best[0].distance)
|
|
559
|
+
best = [{ nodeId: node.id, anchor, point: at, distance }];
|
|
560
|
+
else if (distance === best[0].distance)
|
|
561
|
+
best.push({ nodeId: node.id, anchor, point: at, distance });
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (!best.length)
|
|
565
|
+
return null;
|
|
566
|
+
const opposite = from.anchor.type === "source" ? "target" : "source";
|
|
567
|
+
return best.find((item) => item.anchor.type === opposite) ?? best[0];
|
|
568
|
+
};
|
|
569
|
+
const connection = (near) => {
|
|
570
|
+
const own = { nodeId: from.nodeId, anchor: from.anchor.id };
|
|
571
|
+
const other = { nodeId: near.nodeId, anchor: near.anchor.id };
|
|
572
|
+
return from.anchor.type === "source"
|
|
573
|
+
? { source: own, target: other }
|
|
574
|
+
: { source: other, target: own };
|
|
575
|
+
};
|
|
576
|
+
const isValid = (near) => {
|
|
577
|
+
if (!from || near.anchor.type === from.anchor.type)
|
|
578
|
+
return false;
|
|
579
|
+
if (near.nodeId === from.nodeId) {
|
|
580
|
+
const record = engine.store.get().document.nodes[from.nodeId];
|
|
581
|
+
if (!engine.schemas.get(record.type)?.allowSelfConnection)
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
return options.isValidConnection(connection(near));
|
|
585
|
+
};
|
|
586
|
+
// The move that starts a drag counts as its first move.
|
|
587
|
+
const onDrag = (event) => {
|
|
588
|
+
if (!from || arbiter.current !== "connect")
|
|
589
|
+
return;
|
|
590
|
+
const point = pointerWorld(controller, event);
|
|
591
|
+
const near = closest(point);
|
|
592
|
+
engine.store.set("interaction", {
|
|
593
|
+
connection: {
|
|
594
|
+
from,
|
|
595
|
+
to: near ? near.point : point,
|
|
596
|
+
target: near
|
|
597
|
+
? { nodeId: near.nodeId, anchor: near.anchor, valid: isValid(near) }
|
|
598
|
+
: null,
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
return off(controller, [
|
|
603
|
+
eventer.on(DragEvent.START, (event) => {
|
|
604
|
+
const target = event.current;
|
|
605
|
+
if (target.kind !== "handle" ||
|
|
606
|
+
event.target !== target ||
|
|
607
|
+
event.input.button !== 0)
|
|
608
|
+
return;
|
|
609
|
+
if (engine.store.get().interaction.tool === "hand" ||
|
|
610
|
+
!arbiter.claim("connect"))
|
|
611
|
+
return;
|
|
612
|
+
event.stop();
|
|
613
|
+
const node = engine.scene.get(target.nodeId);
|
|
614
|
+
if (!node)
|
|
615
|
+
return;
|
|
616
|
+
const point = applyToPoint(node.world, anchorPoint(target.handle));
|
|
617
|
+
from = { nodeId: node.id, anchor: target.handle, point };
|
|
618
|
+
engine.store.set("interaction", {
|
|
619
|
+
connection: { from, to: point, target: null },
|
|
620
|
+
cursor: "crosshair",
|
|
621
|
+
});
|
|
622
|
+
events.emit("connect:start", { nodeId: node.id, anchor: target.handle });
|
|
623
|
+
onDrag(event);
|
|
624
|
+
}, { on: "handle" }),
|
|
625
|
+
eventer.on(DragEvent.DRAG, onDrag, { on: "handle" }),
|
|
626
|
+
eventer.on(DragEvent.END, (event) => {
|
|
627
|
+
if (!from || arbiter.current !== "connect")
|
|
628
|
+
return;
|
|
629
|
+
const start = from;
|
|
630
|
+
const point = pointerWorld(controller, event);
|
|
631
|
+
const near = event.cancelled ? null : closest(point);
|
|
632
|
+
const valid = near ? isValid(near) : null;
|
|
633
|
+
let relationId = null;
|
|
634
|
+
engine.store.batch(() => {
|
|
635
|
+
if (near && valid) {
|
|
636
|
+
const result = engine.transact("connect", (tx) => tx.run("relation.connect", connection(near)));
|
|
637
|
+
if (result.ok)
|
|
638
|
+
relationId = result.value;
|
|
639
|
+
}
|
|
640
|
+
engine.store.set("interaction", { connection: null });
|
|
641
|
+
});
|
|
642
|
+
from = null;
|
|
643
|
+
arbiter.release("connect");
|
|
644
|
+
if (event.cancelled)
|
|
645
|
+
return;
|
|
646
|
+
events.emit("connect:end", {
|
|
647
|
+
from: { nodeId: start.nodeId, anchor: start.anchor },
|
|
648
|
+
to: point,
|
|
649
|
+
target: near ? { nodeId: near.nodeId, anchor: near.anchor } : null,
|
|
650
|
+
valid,
|
|
651
|
+
relationId,
|
|
652
|
+
input: event.input,
|
|
653
|
+
});
|
|
654
|
+
}, { on: "handle" }),
|
|
655
|
+
]);
|
|
656
|
+
};
|
|
657
|
+
// ---- keyboard -------------------------------------------------------------------
|
|
658
|
+
const ARROWS = {
|
|
659
|
+
ArrowUp: { x: 0, y: -1 },
|
|
660
|
+
ArrowDown: { x: 0, y: 1 },
|
|
661
|
+
ArrowLeft: { x: -1, y: 0 },
|
|
662
|
+
ArrowRight: { x: 1, y: 0 },
|
|
663
|
+
};
|
|
664
|
+
export const keyboardBehavior = (controller) => {
|
|
665
|
+
const { engine, options, arbiter } = controller;
|
|
666
|
+
return controller.addKeyHandler((input) => {
|
|
667
|
+
if (input.typing)
|
|
668
|
+
return false;
|
|
669
|
+
const mod = input.metaKey || input.ctrlKey;
|
|
670
|
+
const { selectedIds, selectedRelationIds } = engine.store.get().interaction;
|
|
671
|
+
const key = input.key.toLowerCase();
|
|
672
|
+
if (mod && key === "z") {
|
|
673
|
+
if (input.shiftKey)
|
|
674
|
+
engine.history.redo();
|
|
675
|
+
else
|
|
676
|
+
engine.history.undo();
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
if (mod && key === "y") {
|
|
680
|
+
engine.history.redo();
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
if (mod && key === "a") {
|
|
684
|
+
select(controller, [...engine.scene.walk()]
|
|
685
|
+
.filter((node) => node.record.visible)
|
|
686
|
+
.map((node) => node.id), []);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
if (input.key === "Escape") {
|
|
690
|
+
if (arbiter.current) {
|
|
691
|
+
controller.cancelGesture();
|
|
692
|
+
return true;
|
|
693
|
+
}
|
|
694
|
+
if (selectedIds.length || selectedRelationIds.length) {
|
|
695
|
+
select(controller, [], []);
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
if (input.key === "Delete" || input.key === "Backspace") {
|
|
701
|
+
if (!selectedIds.length && !selectedRelationIds.length)
|
|
702
|
+
return false;
|
|
703
|
+
engine.transact("delete", (tx) => {
|
|
704
|
+
const nodes = selectedIds.filter((id) => !engine.store.get().document.nodes[id]?.locked);
|
|
705
|
+
if (nodes.length)
|
|
706
|
+
tx.run("node.delete", { ids: nodes });
|
|
707
|
+
for (const id of selectedRelationIds) {
|
|
708
|
+
// Gone already with a deleted node.
|
|
709
|
+
if (tx.draft.relation(id))
|
|
710
|
+
tx.run("relation.disconnect", { id });
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
select(controller, [], []);
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
const direction = ARROWS[input.key];
|
|
717
|
+
// Alt + arrows move the focus (the accessibility layer), not nodes.
|
|
718
|
+
if (direction && selectedIds.length && !input.altKey) {
|
|
719
|
+
const factor = input.shiftKey ? 4 : 1;
|
|
720
|
+
const [gx, gy] = options.snapToGrid
|
|
721
|
+
? options.snapGrid
|
|
722
|
+
: [options.arrowStep, options.arrowStep];
|
|
723
|
+
const ids = selectedIds.filter((id) => !engine.store.get().document.nodes[id]?.locked);
|
|
724
|
+
if (!ids.length)
|
|
725
|
+
return false;
|
|
726
|
+
engine.commands.execute("node.move", {
|
|
727
|
+
ids,
|
|
728
|
+
delta: { x: direction.x * gx * factor, y: direction.y * gy * factor },
|
|
729
|
+
}, { mergeKey: "arrows" });
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
return false;
|
|
733
|
+
});
|
|
734
|
+
};
|
|
735
|
+
export const DEFAULT_BEHAVIORS = [
|
|
736
|
+
hoverBehavior,
|
|
737
|
+
panBehavior,
|
|
738
|
+
selectBehavior,
|
|
739
|
+
marqueeBehavior,
|
|
740
|
+
dragBehavior,
|
|
741
|
+
transformBehavior,
|
|
742
|
+
connectBehavior,
|
|
743
|
+
keyboardBehavior,
|
|
744
|
+
];
|