@statelyai/flow 0.14.0 → 0.15.0

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.
Files changed (115) hide show
  1. package/README.md +2 -1
  2. package/dist/esm/index.d.ts +5 -2
  3. package/dist/esm/index.d.ts.map +1 -0
  4. package/dist/esm/index.js +19 -14
  5. package/dist/esm/index.js.map +1 -0
  6. package/dist/esm/layout/dagre.d.ts +2 -1
  7. package/dist/esm/layout/dagre.d.ts.map +1 -0
  8. package/dist/esm/layout/dagre.js +2 -0
  9. package/dist/esm/layout/dagre.js.map +1 -0
  10. package/dist/esm/layout/elk.d.ts +2 -1
  11. package/dist/esm/layout/elk.d.ts.map +1 -0
  12. package/dist/esm/layout/elk.js +2 -0
  13. package/dist/esm/layout/elk.js.map +1 -0
  14. package/dist/esm/layout/stately.d.ts +2 -1
  15. package/dist/esm/layout/stately.d.ts.map +1 -0
  16. package/dist/esm/layout/stately.js +2 -0
  17. package/dist/esm/layout/stately.js.map +1 -0
  18. package/dist/esm/shared.d.ts +2 -1
  19. package/dist/esm/shared.d.ts.map +1 -0
  20. package/dist/esm/shared.js +2 -0
  21. package/dist/esm/shared.js.map +1 -0
  22. package/package.json +4 -3
  23. package/src/__fixtures__/nested.ts +106 -0
  24. package/src/appearances.test.ts +428 -0
  25. package/src/appearances.ts +144 -0
  26. package/src/authoritative-route.ts +14 -0
  27. package/src/changeSet.test.ts +132 -0
  28. package/src/changeSet.ts +337 -0
  29. package/src/config.ts +41 -0
  30. package/src/configure.test.ts +212 -0
  31. package/src/connection-lifetime.ts +1 -0
  32. package/src/connectionPreview.test.ts +102 -0
  33. package/src/connectionPreview.ts +82 -0
  34. package/src/content.ts +203 -0
  35. package/src/createFlow.fit-frame.test.ts +256 -0
  36. package/src/createFlow.modern.test.ts +743 -0
  37. package/src/createFlow.test.ts +632 -0
  38. package/src/createFlow.ts +3463 -0
  39. package/src/createFlow.view.test.ts +212 -0
  40. package/src/createFlow.viewport-controls.test.ts +221 -0
  41. package/src/edge-geometry.ts +318 -0
  42. package/src/engine.cache.test.ts +728 -0
  43. package/src/engine.hierarchy.test.ts +1023 -0
  44. package/src/engine.test.ts +1965 -0
  45. package/src/engine.ts +3385 -0
  46. package/src/entity-changes.test.ts +309 -0
  47. package/src/entity-changes.ts +395 -0
  48. package/src/examples/flow-based-math.test.ts +25 -0
  49. package/src/examples/flow-based-math.ts +210 -0
  50. package/src/external-edit.test.ts +337 -0
  51. package/src/external-edit.ts +358 -0
  52. package/src/factories.test.ts +104 -0
  53. package/src/factories.ts +70 -0
  54. package/src/geometry.ts +13 -0
  55. package/src/graph-index.test.ts +56 -0
  56. package/src/graph-index.ts +194 -0
  57. package/src/hierarchy.test.ts +175 -0
  58. package/src/hierarchy.ts +330 -0
  59. package/src/highlights.test.ts +130 -0
  60. package/src/index.ts +469 -0
  61. package/src/input/index.ts +615 -0
  62. package/src/input/input.test.ts +2577 -0
  63. package/src/input/keymap.ts +111 -0
  64. package/src/input/modes.ts +1715 -0
  65. package/src/input/reparent.test.ts +214 -0
  66. package/src/layout/dagre.ts +138 -0
  67. package/src/layout/elk.ts +1382 -0
  68. package/src/layout/index.ts +12 -0
  69. package/src/layout/layout.test.ts +1248 -0
  70. package/src/layout/shared.ts +260 -0
  71. package/src/layout/stately-globals.d.ts +9 -0
  72. package/src/layout/stately.test.ts +246 -0
  73. package/src/layout/stately.ts +528 -0
  74. package/src/layout-animation.test.ts +223 -0
  75. package/src/layout-contract.test.ts +414 -0
  76. package/src/marker.test.ts +23 -0
  77. package/src/marker.ts +23 -0
  78. package/src/measurement-anchor.test.ts +232 -0
  79. package/src/minimap.test.ts +96 -0
  80. package/src/minimap.ts +137 -0
  81. package/src/nested-fixture.test.ts +178 -0
  82. package/src/port-measurement.test.ts +27 -0
  83. package/src/port-measurements.test.ts +187 -0
  84. package/src/profile.ts +124 -0
  85. package/src/projections.test.ts +103 -0
  86. package/src/projections.ts +295 -0
  87. package/src/render-invalidation.test.ts +62 -0
  88. package/src/render-invalidation.ts +55 -0
  89. package/src/renderer-geometry.test.ts +356 -0
  90. package/src/renderer-transactions.test.ts +234 -0
  91. package/src/routing/avoid.ts +417 -0
  92. package/src/routing/index.test.ts +361 -0
  93. package/src/routing/index.ts +366 -0
  94. package/src/routing/readTracking.test.ts +103 -0
  95. package/src/routing/readTracking.ts +233 -0
  96. package/src/selection-commands.test.ts +355 -0
  97. package/src/serialize.test.ts +167 -0
  98. package/src/serialize.ts +254 -0
  99. package/src/shapes/index.test.ts +45 -0
  100. package/src/shapes/index.ts +142 -0
  101. package/src/snap.test.ts +123 -0
  102. package/src/snap.ts +395 -0
  103. package/src/spatial.test.ts +676 -0
  104. package/src/spatial.ts +457 -0
  105. package/src/store/index.ts +4121 -0
  106. package/src/store.test.ts +2903 -0
  107. package/src/toolbar.test.ts +31 -0
  108. package/src/toolbar.ts +62 -0
  109. package/src/types.test.ts +15 -0
  110. package/src/types.ts +487 -0
  111. package/src/validation.ts +558 -0
  112. package/src/view.ts +172 -0
  113. package/src/viewport/animate.ts +285 -0
  114. package/src/viewport/index.ts +296 -0
  115. package/src/viewport.test.ts +569 -0
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { getToolbarPlacement } from './toolbar';
3
+
4
+ const base = {
5
+ anchor: { x: 300, y: 200, width: 100, height: 50 },
6
+ toolbarWidth: 120,
7
+ toolbarHeight: 36,
8
+ viewportWidth: 800,
9
+ viewportHeight: 600,
10
+ };
11
+
12
+ describe('getToolbarPlacement', () => {
13
+ it('prefers above the anchor, centered', () => {
14
+ const p = getToolbarPlacement(base);
15
+ expect(p.side).toBe('top');
16
+ expect(p.top).toBe(200 - 10 - 36);
17
+ expect(p.left).toBe(300 + 50 - 60);
18
+ });
19
+
20
+ it('flips below when the top would clip', () => {
21
+ const p = getToolbarPlacement({ ...base, anchor: { ...base.anchor, y: 20 } });
22
+ expect(p.side).toBe('bottom');
23
+ expect(p.top).toBe(20 + 50 + 10);
24
+ });
25
+
26
+ it('clamps horizontally and vertically inside the viewport', () => {
27
+ const p = getToolbarPlacement({ ...base, anchor: { x: -80, y: 700, width: 40, height: 40 } });
28
+ expect(p.left).toBeGreaterThanOrEqual(8);
29
+ expect(p.top + 36).toBeLessThanOrEqual(600 - 8);
30
+ });
31
+ });
package/src/toolbar.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { Rect } from './types';
2
+
3
+ // Toolbar placement — pure math, renderer-agnostic (Stately-editor
4
+ // semantics). Anchors come from `engine.getToolbarAnchor` (a node's bounds,
5
+ // an edge's label — or an assumed 1×1 label at the path midpoint — or the
6
+ // union over a selection); this function decides where a measured toolbar
7
+ // box sits: preferring above the anchor, flipping below when it would clip,
8
+ // and always clamping inside the viewport.
9
+
10
+ export type ToolbarPlacementInput = {
11
+ /** Anchor rect in container-relative screen px (canvas rect × viewport). */
12
+ anchor: Rect;
13
+ /** Measured toolbar size (border box). */
14
+ toolbarWidth: number;
15
+ toolbarHeight: number;
16
+ /** Container size in px. */
17
+ viewportWidth: number;
18
+ viewportHeight: number;
19
+ /** Gap between anchor and toolbar (default 10). */
20
+ offset?: number;
21
+ /** Minimum gap from container edges (default 8). */
22
+ padding?: number;
23
+ };
24
+
25
+ export type ToolbarPlacement = {
26
+ /** Top-left of the toolbar box, container-relative px. */
27
+ left: number;
28
+ top: number;
29
+ side: 'top' | 'bottom';
30
+ };
31
+
32
+ export function getToolbarPlacement(
33
+ input: ToolbarPlacementInput,
34
+ ): ToolbarPlacement {
35
+ const offset = input.offset ?? 10;
36
+ const padding = input.padding ?? 8;
37
+ const { toolbarWidth: tw, toolbarHeight: th, anchor } = input;
38
+
39
+ const topPlacementTop = anchor.y - offset - th;
40
+ const bottomPlacementTop = anchor.y + anchor.height + offset;
41
+ const topFits = topPlacementTop >= padding;
42
+ const bottomFits = bottomPlacementTop + th <= input.viewportHeight - padding;
43
+
44
+ let side: 'top' | 'bottom';
45
+ if (topFits) side = 'top';
46
+ else if (bottomFits) side = 'bottom';
47
+ else {
48
+ const topRoom = anchor.y;
49
+ const bottomRoom = input.viewportHeight - (anchor.y + anchor.height);
50
+ side = topRoom >= bottomRoom ? 'top' : 'bottom';
51
+ }
52
+
53
+ let top = side === 'top' ? topPlacementTop : bottomPlacementTop;
54
+ const maxTop = Math.max(input.viewportHeight - padding - th, padding);
55
+ top = Math.min(Math.max(top, padding), maxTop);
56
+
57
+ let left = anchor.x + anchor.width / 2 - tw / 2;
58
+ const maxLeft = Math.max(input.viewportWidth - padding - tw, padding);
59
+ left = Math.min(Math.max(left, padding), maxLeft);
60
+
61
+ return { left, top, side };
62
+ }
@@ -0,0 +1,15 @@
1
+ import { expect, expectTypeOf, it } from 'vitest';
2
+ import { createNode, createPort } from './factories';
3
+ import type { FlowNode, FlowPort } from './types';
4
+
5
+ it('retains Flow port attributes through array queries', () => {
6
+ const node: FlowNode = createNode({
7
+ id: 'a',
8
+ ports: [createPort({ id: 'explicit-out', name: 'out', side: 'right', direction: 'out' })],
9
+ });
10
+ const port = node.ports?.find((candidate) => candidate.name === 'out');
11
+ expectTypeOf(port).toEqualTypeOf<FlowPort | undefined>();
12
+ expectTypeOf(port?.id).toEqualTypeOf<string | undefined>();
13
+ expect(port?.side).toBe('right');
14
+ expect(port?.id).toBe('explicit-out');
15
+ });
package/src/types.ts ADDED
@@ -0,0 +1,487 @@
1
+ import { connectionLifetime } from './connection-lifetime';
2
+
3
+ // Core Types for @statelyai/flow
4
+ //
5
+ // Built on @statelyai/graph VisualGraph.
6
+ // Re-exports graph types and adds flow-specific types.
7
+
8
+
9
+ // Re-export graph types as the canonical data model
10
+ export type {
11
+ Graph,
12
+ GraphNode,
13
+ GraphEdge,
14
+ GraphPort,
15
+ EdgeRouting,
16
+ PortDirection,
17
+ VisualGraph,
18
+ VisualNode,
19
+ VisualEdge,
20
+ VisualPort,
21
+ EntityRect,
22
+ } from '@statelyai/graph';
23
+
24
+ import type {
25
+ EdgeRouting,
26
+ VisualNode,
27
+ VisualEdge,
28
+ VisualGraphConfig,
29
+ VisualPort,
30
+ } from '@statelyai/graph';
31
+
32
+
33
+ // Geometry primitives
34
+
35
+
36
+ export type Point = { x: number; y: number };
37
+ export type Size = { width: number; height: number };
38
+ export type Rect = Point & Size;
39
+
40
+ /** Anchor retained when an auto-sized node's DOM measurement changes. */
41
+ export type FlowAutoSizeAnchor =
42
+ | 'top-left'
43
+ | 'center'
44
+ | { x: number; y: number };
45
+
46
+
47
+ // Viewport
48
+
49
+
50
+ export type Viewport = {
51
+ /** Pan offset x (canvas → screen translation) */
52
+ x: number;
53
+ /** Pan offset y */
54
+ y: number;
55
+ /** Scale factor (1 = 100%) */
56
+ zoom: number;
57
+ };
58
+
59
+
60
+ // Ports
61
+
62
+
63
+ export type Side = 'top' | 'bottom' | 'left' | 'right';
64
+
65
+ /** Port on a node — positioned by renderer, measured via observer */
66
+ export type FlowPort<TPortData = unknown> = VisualPort<TPortData> & {
67
+ id?: string;
68
+ side: Side;
69
+ };
70
+
71
+
72
+ // Flow-specific attributes added to VisualGraph entities
73
+
74
+
75
+ import type { GroupLayout } from './hierarchy';
76
+
77
+ /**
78
+ * Flow node attributes — drag offset, ports, style overrides, behavior flags.
79
+ * Visual position = { x + dx, y + dy }
80
+ */
81
+ export type FlowNodeAttributes = {
82
+ appearance?: import("./appearances").FlowAppearance;
83
+ /** Application-defined node/rendering kind. `type` remains the structural `node` discriminant. */
84
+ kind?: string;
85
+ dx?: number;
86
+ dy?: number;
87
+ style?: StyleOverrides;
88
+ ports?: FlowPort[];
89
+ /**
90
+ * DOM-driven sizing (Stately-editor semantics): the rendered node owns its
91
+ * size — the renderer must NOT force `width`/`height` back onto it. The
92
+ * authored `width`/`height` are never overwritten; instead the measured
93
+ * size lands on `measured` (below) and geometry derives from it. The
94
+ * authored `width`/`height` only seed geometry until the first measurement.
95
+ */
96
+ autoSize?: boolean;
97
+ /**
98
+ * Visual anchor retained as DOM-owned dimensions change. Fractions are
99
+ * relative to the node box (`0` = start, `1` = end). Defaults to
100
+ * `top-left`; `center` is shorthand for `{ x: 0.5, y: 0.5 }`.
101
+ */
102
+ autoSizeAnchor?: FlowAutoSizeAnchor;
103
+ /**
104
+ * Last DOM-measured size (à la React Flow's `node.measured`), written by the
105
+ * measurement observer for `autoSize` nodes only. A *derived* overlay kept
106
+ * separate from the authored `width`/`height` so measurement never clobbers
107
+ * the model (which is what fed a render → measure → render growth loop).
108
+ * Geometry prefers this over the authored size for autoSize nodes — see
109
+ * `resolvedSize`. For the full measured *bounds* (rect, any entity) use the
110
+ * live measurements map via `engine.getBounds` / `useFlowMeasurement`.
111
+ */
112
+ measured?: {
113
+ width: number;
114
+ height: number;
115
+ /** Derived position correction excluded from serialization. */
116
+ anchorOffset?: Point;
117
+ /** Derived sizing state; excluded from serialization. */
118
+ appearanceAutoSize?: boolean;
119
+ appearanceKey?: string;
120
+ };
121
+ /**
122
+ * Marks this node as a group and configures how its bounds relate to its
123
+ * children (nodes whose `parentId` points here). With `type: 'derived'`
124
+ * the stored width/height describe the content block and overall bounds
125
+ * are derived from the children; with `type: 'fixed'` stored geometry is
126
+ * authoritative and children can be clamped inside. See `GroupLayout`.
127
+ */
128
+ group?: GroupLayout;
129
+ /**
130
+ * Optional authored hit rectangle for marquee selection. Useful when a
131
+ * node's visual family is larger than the surface that selects the node
132
+ * (for example, a compound state's header).
133
+ */
134
+ selectionBounds?: Rect;
135
+ /** Entity flag wins over global `FlowConfig.visible`; default true. */
136
+ hidden?: boolean;
137
+ /** Entity flag wins over global `FlowConfig.selectable`; default true. */
138
+ selectable?: boolean;
139
+ /** Whether renderers include the entity in keyboard focus order; default true. */
140
+ focusable?: boolean;
141
+ /** Entity flag wins over global `FlowConfig.draggable`; default true. */
142
+ draggable?: boolean;
143
+ /** Entity flag wins over global `FlowConfig.connectable`; default true. */
144
+ connectable?: boolean;
145
+ /** Entity flag wins over global `FlowConfig.deletable`; default true. */
146
+ deletable?: boolean;
147
+ /** Entity flag wins over global `FlowConfig.resizable`; default false. */
148
+ resizable?: boolean;
149
+ zIndex?: number;
150
+ /** Framework-neutral resize constraints consumed by the core resize reducer. */
151
+ resize?: ResizeConstraints;
152
+ };
153
+
154
+ /** Flow edge label — positioned like a node, lives on edge */
155
+ export type FlowEdgeLabel<TData = unknown> = {
156
+ appearance?: import("./appearances").FlowAppearance;
157
+ x: number;
158
+ y: number;
159
+ dx?: number;
160
+ dy?: number;
161
+ /**
162
+ * DOM-driven sizing: the rendered label owns its live size. Authored
163
+ * `width`/`height` remain fallback graph data; measurements stay transient.
164
+ */
165
+ autoSize?: boolean;
166
+ width: number;
167
+ height: number;
168
+ style?: StyleOverrides;
169
+ data: TData;
170
+ };
171
+
172
+ /**
173
+ * Label anchor: determines base position of edge label before dx/dy offset.
174
+ * - number (0..1): interpolation along source→target centers (0.5 = midpoint)
175
+ * - 'fixed': uses label's own x/y, ignores node positions
176
+ * - function: custom anchor returning center point given source/target bounds and edge
177
+ */
178
+ export type LabelAnchor =
179
+ | number
180
+ | 'fixed'
181
+ | ((sourceBounds: Rect, targetBounds: Rect, edge: FlowEdge) => Point);
182
+
183
+ /** Edge marker type */
184
+ export type MarkerType = 'arrow' | 'arrow-closed' | 'circle' | 'none' | (string & {});
185
+
186
+ /** Edge visual style — read by renderer */
187
+ export type FlowEdgeStyle = {
188
+ markerStart?: MarkerType;
189
+ markerEnd?: MarkerType;
190
+ strokeDasharray?: string;
191
+ strokeWidth?: number;
192
+ stroke?: string;
193
+ };
194
+
195
+ /** Flow edge attributes — label, ports, style, behavior flags */
196
+ export type FlowEdgeAttributes<TLabelData = unknown> = {
197
+ dx?: number;
198
+ dy?: number;
199
+ label?: FlowEdgeLabel<TLabelData> | null;
200
+ labelAnchor?: LabelAnchor;
201
+ waypoints?: Point[];
202
+ /**
203
+ * Exact SVG rendering for authoritative `points`. Points remain the source
204
+ * of truth for bounds, endpoints, hit testing, and non-SVG renderers.
205
+ */
206
+ svgPath?: string;
207
+ sourcePort?: string | null; // port name, '*' = closest, null = node center
208
+ targetPort?: string | null;
209
+ kind?: string;
210
+ style?: FlowEdgeStyle;
211
+ /** Entity flag wins over global `FlowConfig.visible`; default true. */
212
+ hidden?: boolean;
213
+ /** Entity flag wins over global `FlowConfig.selectable`; default true. */
214
+ selectable?: boolean;
215
+ /** Whether renderers include the entity in keyboard focus order; default true. */
216
+ focusable?: boolean;
217
+ /** Entity flag wins over global `FlowConfig.draggable`; default true. */
218
+ draggable?: boolean;
219
+ /** Entity flag wins over global `FlowConfig.connectable`; default true. */
220
+ connectable?: boolean;
221
+ /** Entity flag wins over global `FlowConfig.reconnectable`; default true. */
222
+ reconnectable?: boolean;
223
+ /** Entity flag wins over global `FlowConfig.deletable`; default true. */
224
+ deletable?: boolean;
225
+ zIndex?: number;
226
+ };
227
+
228
+ export type FlowEntityRef =
229
+ | { kind: 'node'; id: string; node: FlowNode }
230
+ | { kind: 'edge'; id: string; edge: FlowEdge }
231
+ | {
232
+ kind: 'port';
233
+ id: string;
234
+ nodeId: string;
235
+ portName: string;
236
+ port: VisualPort;
237
+ }
238
+ | {
239
+ kind: 'block';
240
+ id: string;
241
+ ownerId: string;
242
+ blockType: string;
243
+ data?: unknown;
244
+ };
245
+
246
+ /** @deprecated Use `FlowEntityRef`. */
247
+ export type FlowAddressable = FlowEntityRef;
248
+
249
+
250
+ // Combined flow entity types (VisualGraph + flow attributes)
251
+
252
+
253
+ /** A flow node: VisualNode + flow attributes */
254
+ export type FlowNode<TData = any> = Omit<VisualNode<TData>, 'ports'> & FlowNodeAttributes;
255
+
256
+ /**
257
+ * A flow edge: VisualEdge + flow attributes.
258
+ *
259
+ * `x`/`y`/`width`/`height` are inherited from the graph visual model and
260
+ * reserved for compatibility. Flow renderers route edges from endpoints unless
261
+ * canonical `points` provide an authoritative route; positioned edge content
262
+ * belongs on `label`.
263
+ */
264
+ export type FlowEdge<TEdgeData = any, TLabelData = any> = Omit<VisualEdge<TEdgeData>, 'label'> &
265
+ FlowEdgeAttributes<TLabelData>;
266
+
267
+ /** A flow graph: VisualGraph with FlowNode/FlowEdge */
268
+ export type FlowGraph<
269
+ TNodeData = any,
270
+ TEdgeData = any,
271
+ TLabelData = any,
272
+ > = Omit<VisualGraphConfig<TNodeData, TEdgeData>, 'nodes' | 'edges'> & {
273
+ nodes: FlowNode<TNodeData>[];
274
+ edges: FlowEdge<TEdgeData, TLabelData>[];
275
+ };
276
+
277
+ /** Direction of the graph layout */
278
+ export type EdgeDirection = 'up' | 'down' | 'left' | 'right';
279
+
280
+ export type StyleOverrides = {
281
+ /** User-set dimension overrides (from manual resize) */
282
+ customWidth?: number;
283
+ customHeight?: number;
284
+ };
285
+
286
+
287
+ // Canvas state
288
+
289
+
290
+
291
+ // Interaction mode (what pointer gestures do by default)
292
+
293
+
294
+ /** @deprecated Use profile mode names (`context.mode`) instead. */
295
+ export type InteractionMode =
296
+ | 'default' // normal: click=select, drag=move, pane-drag=pan/box-select
297
+ | 'pan' // space held: all drags pan
298
+ | 'connect' // connection mode: drags start connections
299
+ | 'select'; // selection mode: pane drags always box-select
300
+
301
+ export type SelectionMode = 'partial' | 'full';
302
+
303
+
304
+ // Canvas state
305
+
306
+
307
+ export type CanvasState =
308
+ | 'idle'
309
+ | 'panning'
310
+ | 'dragging'
311
+ | 'connecting'
312
+ | 'resizing'
313
+ | 'selecting';
314
+
315
+
316
+ // Connection state (in-progress connection drag)
317
+
318
+
319
+ export type ConnectionState = {
320
+ [connectionLifetime]?: object;
321
+ sourceId: string;
322
+ sourcePort: string | null;
323
+ /** null while dragging over empty space */
324
+ targetId: string | null;
325
+ targetPort: string | null;
326
+ /** Canvas position where the gesture began */
327
+ startPosition: Point;
328
+ /** Current pointer in canvas coords */
329
+ pointerPosition: Point;
330
+ /** Thresholded activation state for drag-based connections */
331
+ active: boolean;
332
+ /** Whether adapters should project the generic connection preview. */
333
+ preview?: boolean;
334
+ /** canConnect result for current target */
335
+ isValid: boolean;
336
+ /** Optional reason for the current invalid connection target. */
337
+ invalidReason?: string;
338
+ /** Edge id while reconnecting an existing edge endpoint. */
339
+ reconnectingEdgeId?: string | null;
340
+ /** Which endpoint is being dragged while reconnecting. */
341
+ reconnectingEnd?: 'source' | 'target' | null;
342
+ };
343
+
344
+
345
+ // Resize
346
+
347
+
348
+ export type ResizeHandle =
349
+ | 'top' | 'bottom' | 'left' | 'right'
350
+ | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
351
+
352
+ export type ResizeConstraints = {
353
+ min?: Partial<Size>;
354
+ max?: Partial<Size>;
355
+ /** true preserves the node's current aspect ratio; a number uses width / height. */
356
+ aspect?: boolean | number;
357
+ };
358
+
359
+
360
+ // Auto-layout state
361
+
362
+
363
+ export type AutoLayoutState = {
364
+ status: 'idle' | 'pending' | 'running';
365
+ algorithm: string | null;
366
+ };
367
+
368
+
369
+ // Entity visual state (computed by engine, consumed by renderer)
370
+
371
+
372
+ export type EntityVisualState = {
373
+ selected: boolean;
374
+ focused: boolean;
375
+ hovered: boolean;
376
+ highlighted: boolean;
377
+ connectionValid: boolean;
378
+ connectionInvalid: boolean;
379
+ disabled: boolean;
380
+ dragging: boolean;
381
+ resizing: boolean;
382
+ };
383
+
384
+
385
+ // Edge routing
386
+
387
+
388
+ export type Direction = 'top' | 'bottom' | 'left' | 'right';
389
+
390
+ export type PathData = {
391
+ points: Point[];
392
+ /** Explicit interpretation for authoritative graph-owned points. */
393
+ routing?: EdgeRouting;
394
+ sourceDirection: Direction;
395
+ targetDirection: Direction;
396
+ /**
397
+ * Optional router-owned SVG `d` override for custom curves or rounded paths.
398
+ * `points` remain required for bounds, endpoints, and interaction geometry.
399
+ */
400
+ svgPath?: string;
401
+ };
402
+
403
+ /** Edge path result from engine — may contain two segments if edge has a label */
404
+ export type EdgePathData = {
405
+ segments: PathData[];
406
+ labelBounds: Rect | null;
407
+ };
408
+
409
+
410
+ // Shape handler
411
+
412
+
413
+ export type ShapeHandler = {
414
+ hitTest: (point: Point, bounds: Rect) => boolean;
415
+ edgeAnchor: (bounds: Rect, direction: Direction) => Point;
416
+ };
417
+
418
+
419
+ // Behavior config
420
+
421
+
422
+ /** A behavior predicate: function or `false` to disable globally */
423
+ export type BehaviorPredicate<TEntity = unknown, TState = unknown> =
424
+ | ((entity: TEntity, flowState: TState) => boolean)
425
+ | false;
426
+
427
+ export type FlowConfig<TEntity = unknown, TState = unknown> = {
428
+ /** Entity `selectable` flag wins, then this predicate, then default true. */
429
+ selectable: BehaviorPredicate<TEntity, TState>;
430
+ /** Entity `focusable` flag wins, then this predicate, then default true. */
431
+ focusable: BehaviorPredicate<TEntity, TState>;
432
+ /** Entity `draggable` flag wins, then this predicate, then default true. */
433
+ draggable: BehaviorPredicate<TEntity, TState>;
434
+ /** Entity `connectable` flag wins, then this predicate, then default true. */
435
+ connectable: BehaviorPredicate<TEntity, TState>;
436
+ /** Entity `reconnectable` flag wins, then this predicate, then default true. */
437
+ reconnectable: BehaviorPredicate<TEntity, TState>;
438
+ /** Entity `deletable` flag wins, then this predicate, then default true. */
439
+ deletable: BehaviorPredicate<TEntity, TState>;
440
+ /** Entity `resizable` flag wins, then this predicate, then default false. */
441
+ resizable: BehaviorPredicate<TEntity, TState>;
442
+ /** Entity `hidden` flag wins, then this predicate, then default true. */
443
+ visible: BehaviorPredicate<TEntity, TState>;
444
+ };
445
+
446
+
447
+ // Viewport helper options
448
+
449
+
450
+ export type ViewportSpringOptions = {
451
+ stiffness?: number;
452
+ damping?: number;
453
+ mass?: number;
454
+ };
455
+
456
+ export type ViewportAnimationOptions = {
457
+ duration?: number;
458
+ easing?: (t: number) => number;
459
+ /**
460
+ * Exponential smoothing factor in `(0, 1]`. Each nominal 60 Hz frame lerps
461
+ * the current x, y, and zoom toward the target by this amount; actual frame
462
+ * deltas are normalized so the motion is refresh-rate independent. When set,
463
+ * this takes precedence over `duration` and `easing`.
464
+ */
465
+ lerp?: number;
466
+ /**
467
+ * Screen-space point to keep visually fixed during the animation (the focal
468
+ * anchor of the zoom). Defaults to the target viewport's frame of reference,
469
+ * which keeps a fit/zoomTo target centered without swimming.
470
+ */
471
+ center?: Point;
472
+ /**
473
+ * When set, drive the animation with a spring integrator instead of
474
+ * duration/easing lerp. Runs until settled. Sensible near-critically-damped
475
+ * defaults are used for any omitted field.
476
+ */
477
+ spring?: ViewportSpringOptions;
478
+ };
479
+
480
+ export type FitViewOptions = ViewportAnimationOptions & {
481
+ padding?: number;
482
+ minZoom?: number;
483
+ maxZoom?: number;
484
+ nodes?: Array<string | { id: string }>;
485
+ /** Screen-space target frame. Defaults to the full viewport. */
486
+ frame?: Rect;
487
+ };