@statelyai/flow 0.0.1 → 0.4.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.
@@ -0,0 +1,2035 @@
1
+ import * as _xstate_store1 from "@xstate/store";
2
+ import { EntityRect, Graph, GraphEdge, GraphNode, GraphPort, PortDirection, VisualEdge, VisualEdge as VisualEdge$1, VisualGraph, VisualGraphConfig, VisualNode, VisualNode as VisualNode$1, VisualPort, VisualPort as VisualPort$1 } from "@statelyai/graph";
3
+
4
+ //#region src/hierarchy.d.ts
5
+ type GroupContentSide = 'top' | 'left' | 'bottom' | 'right';
6
+ type GroupInsets = {
7
+ top: number;
8
+ right: number;
9
+ bottom: number;
10
+ left: number;
11
+ };
12
+ type GroupLayout = {
13
+ type: 'derived';
14
+ /** Which side the content block occupies (default 'top'). */
15
+ content?: GroupContentSide;
16
+ /** Padding around the children union (default 16). */
17
+ padding?: number | Partial<GroupInsets>;
18
+ /** Minimum child-area size when the group is empty or tiny. */
19
+ minChildArea?: Size;
20
+ } | {
21
+ type: 'fixed';
22
+ content?: GroupContentSide;
23
+ padding?: number | Partial<GroupInsets>;
24
+ /**
25
+ * Size of the content block. Unlike `derived` groups (whose stored
26
+ * width/height ARE the content size), a fixed group's stored
27
+ * width/height describe the overall bounds, so the content block is
28
+ * configured here (default: no content block).
29
+ */
30
+ contentSize?: Size;
31
+ /** Clamp child drags to the child area (default 'none'). */
32
+ clampChildren?: 'x' | 'y' | 'both' | 'none';
33
+ };
34
+ type GroupGeometry = {
35
+ /** Overall group bounds. */
36
+ bounds: Rect;
37
+ /** The content block (title/body — the drag handle by convention). */
38
+ contentBounds: Rect;
39
+ /** Where children live (already inset by padding for `derived`). */
40
+ childArea: Rect;
41
+ };
42
+ declare function resolveGroupPadding(padding: number | Partial<GroupInsets> | undefined): GroupInsets;
43
+ declare function isGroup(node: FlowNode): boolean;
44
+ declare function isDerivedGroup(node: FlowNode): boolean;
45
+ /**
46
+ * Derive a `derived` group's geometry from its content size and the union of
47
+ * its children's bounds (pass null when the group has no children — the
48
+ * anchor point then places the group's top-left).
49
+ */
50
+ declare function deriveGroupGeometry(contentSize: Size, childrenBounds: Rect | null, layout: Extract<GroupLayout, {
51
+ type: 'derived';
52
+ }>, /** Anchor (stored node position) used only when there are no children. */
53
+ anchor?: Point): GroupGeometry;
54
+ /**
55
+ * Geometry for a `fixed` group: stored bounds are authoritative; the content
56
+ * block is carved from the configured side and the child area is the
57
+ * remainder inset by padding.
58
+ */
59
+ declare function fixedGroupGeometry(bounds: Rect, contentSize: Size, layout: Extract<GroupLayout, {
60
+ type: 'fixed';
61
+ }>): GroupGeometry;
62
+ /**
63
+ * The id of the node that contains this edge, or null for the root.
64
+ * Override per engine via `FlowEngineOptions.edgeOwner`.
65
+ */
66
+ declare function getEdgeOwner(edge: {
67
+ sourceId: string;
68
+ targetId: string;
69
+ }, nodes: FlowNode[]): string | null;
70
+ //#endregion
71
+ //#region src/types.d.ts
72
+ type Point = {
73
+ x: number;
74
+ y: number;
75
+ };
76
+ type Size = {
77
+ width: number;
78
+ height: number;
79
+ };
80
+ type Rect = Point & Size;
81
+ type Viewport = {
82
+ /** Pan offset x (canvas → screen translation) */
83
+ x: number;
84
+ /** Pan offset y */
85
+ y: number;
86
+ /** Scale factor (1 = 100%) */
87
+ zoom: number;
88
+ };
89
+ type Side = 'top' | 'bottom' | 'left' | 'right';
90
+ /** Port on a node — positioned by renderer, measured via observer */
91
+ type FlowPort<TPortData = unknown> = VisualPort$1<TPortData> & {
92
+ side: Side;
93
+ };
94
+ /**
95
+ * Flow node attributes — drag offset, ports, style overrides, behavior flags.
96
+ * Visual position = { x + dx, y + dy }
97
+ */
98
+ type FlowNodeAttributes = {
99
+ dx?: number;
100
+ dy?: number;
101
+ style?: StyleOverrides;
102
+ ports?: FlowPort[];
103
+ /**
104
+ * DOM-driven sizing (Stately-editor semantics): the rendered node owns its
105
+ * size — the renderer must NOT force `width`/`height` back onto it. The
106
+ * authored `width`/`height` are never overwritten; instead the measured
107
+ * size lands on `measured` (below) and geometry derives from it. The
108
+ * authored `width`/`height` only seed geometry until the first measurement.
109
+ */
110
+ autoSize?: boolean;
111
+ /**
112
+ * Last DOM-measured size (à la React Flow's `node.measured`), written by the
113
+ * measurement observer for `autoSize` nodes only. A *derived* overlay kept
114
+ * separate from the authored `width`/`height` so measurement never clobbers
115
+ * the model (which is what fed a render → measure → render growth loop).
116
+ * Geometry prefers this over the authored size for autoSize nodes — see
117
+ * `resolvedSize`. For the full measured *bounds* (rect, any entity) use the
118
+ * live measurements map via `engine.getBounds` / `useFlowMeasurement`.
119
+ */
120
+ measured?: {
121
+ width: number;
122
+ height: number;
123
+ };
124
+ /**
125
+ * Marks this node as a group and configures how its bounds relate to its
126
+ * children (nodes whose `parentId` points here). With `type: 'derived'`
127
+ * the stored width/height describe the content block and overall bounds
128
+ * are derived from the children; with `type: 'fixed'` stored geometry is
129
+ * authoritative and children can be clamped inside. See `GroupLayout`.
130
+ */
131
+ group?: GroupLayout;
132
+ hidden?: boolean;
133
+ selectable?: boolean;
134
+ draggable?: boolean;
135
+ connectable?: boolean;
136
+ deletable?: boolean;
137
+ resizable?: boolean;
138
+ };
139
+ /** Flow edge label — positioned like a node, lives on edge */
140
+ type FlowEdgeLabel<TData = unknown> = {
141
+ x: number;
142
+ y: number;
143
+ dx?: number;
144
+ dy?: number;
145
+ width: number;
146
+ height: number;
147
+ style?: StyleOverrides;
148
+ data: TData;
149
+ };
150
+ /**
151
+ * Label anchor: determines base position of edge label before dx/dy offset.
152
+ * - number (0..1): interpolation along source→target centers (0.5 = midpoint)
153
+ * - 'fixed': uses label's own x/y, ignores node positions
154
+ * - function: custom anchor returning center point given source/target bounds
155
+ */
156
+ type LabelAnchor = number | 'fixed' | ((sourceBounds: Rect, targetBounds: Rect) => Point);
157
+ /** Edge marker type */
158
+ type MarkerType = 'arrow' | 'arrow-closed' | 'circle' | 'none' | (string & {});
159
+ /** Edge visual style — read by renderer */
160
+ type FlowEdgeStyle = {
161
+ markerStart?: MarkerType;
162
+ markerEnd?: MarkerType;
163
+ strokeDasharray?: string;
164
+ strokeWidth?: number;
165
+ stroke?: string;
166
+ };
167
+ /** Flow edge attributes — label, ports, style, behavior flags */
168
+ type FlowEdgeAttributes<TLabelData = unknown> = {
169
+ dx?: number;
170
+ dy?: number;
171
+ label?: FlowEdgeLabel<TLabelData> | null;
172
+ labelAnchor?: LabelAnchor;
173
+ sourcePort?: string | null;
174
+ targetPort?: string | null;
175
+ kind?: string;
176
+ style?: FlowEdgeStyle;
177
+ hidden?: boolean;
178
+ selectable?: boolean;
179
+ draggable?: boolean;
180
+ connectable?: boolean;
181
+ reconnectable?: boolean;
182
+ deletable?: boolean;
183
+ };
184
+ type FlowAddressable = {
185
+ kind: 'node';
186
+ id: string;
187
+ node: FlowNode;
188
+ } | {
189
+ kind: 'edge';
190
+ id: string;
191
+ edge: FlowEdge;
192
+ } | {
193
+ kind: 'port';
194
+ id: string;
195
+ nodeId: string;
196
+ portName: string;
197
+ port: VisualPort$1;
198
+ } | {
199
+ kind: 'block';
200
+ id: string;
201
+ ownerId: string;
202
+ blockType: string;
203
+ data?: unknown;
204
+ };
205
+ /** A flow node: VisualNode + flow attributes */
206
+ type FlowNode<TData = any> = VisualNode$1<TData> & FlowNodeAttributes;
207
+ /** A flow edge: VisualEdge + flow attributes */
208
+ type FlowEdge<TEdgeData = any, TLabelData = any> = Omit<VisualEdge$1<TEdgeData>, 'label'> & FlowEdgeAttributes<TLabelData>;
209
+ /** A flow graph: VisualGraph with FlowNode/FlowEdge */
210
+ type FlowGraph<TNodeData = any, TEdgeData = any> = Omit<VisualGraphConfig<TNodeData, TEdgeData>, 'nodes' | 'edges'> & {
211
+ nodes: FlowNode<TNodeData>[];
212
+ edges: FlowEdge<TEdgeData>[];
213
+ };
214
+ /** Direction of the graph layout */
215
+ type EdgeDirection = 'up' | 'down' | 'left' | 'right';
216
+ type StyleOverrides = {
217
+ /** User-set dimension overrides (from manual resize) */
218
+ customWidth?: number;
219
+ customHeight?: number;
220
+ };
221
+ type InteractionMode = 'default' | 'pan' | 'connect' | 'select';
222
+ type SelectionMode = 'partial' | 'full';
223
+ type CanvasState = 'idle' | 'panning' | 'dragging' | 'connecting' | 'resizing' | 'selecting' | 'editing';
224
+ type ConnectionState = {
225
+ sourceId: string;
226
+ sourcePort: string | null;
227
+ /** null while dragging over empty space */
228
+ targetId: string | null;
229
+ targetPort: string | null;
230
+ /** Canvas position where the gesture began */
231
+ startPosition: Point;
232
+ /** Current pointer in canvas coords */
233
+ pointerPosition: Point;
234
+ /** Thresholded activation state for drag-based connections */
235
+ active: boolean;
236
+ /** canConnect result for current target */
237
+ isValid: boolean;
238
+ };
239
+ type ResizeHandle = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
240
+ type AutoLayoutState = {
241
+ status: 'idle' | 'pending' | 'running';
242
+ algorithm: string | null;
243
+ };
244
+ type EntityVisualState = {
245
+ selected: boolean;
246
+ focused: boolean;
247
+ hovered: boolean;
248
+ highlighted: boolean;
249
+ connectionValid: boolean;
250
+ connectionInvalid: boolean;
251
+ disabled: boolean;
252
+ dragging: boolean;
253
+ resizing: boolean;
254
+ editing: boolean;
255
+ };
256
+ type Direction = 'top' | 'bottom' | 'left' | 'right';
257
+ type PathData = {
258
+ points: Point[];
259
+ sourceDirection: Direction;
260
+ targetDirection: Direction;
261
+ };
262
+ /** Edge path result from engine — may contain two segments if edge has a label */
263
+ type EdgePathData = {
264
+ segments: PathData[];
265
+ labelBounds: Rect | null;
266
+ };
267
+ type ShapeHandler = {
268
+ hitTest: (point: Point, bounds: Rect) => boolean;
269
+ edgeAnchor: (bounds: Rect, direction: Direction) => Point;
270
+ };
271
+ type EntityColorSet = {
272
+ fill: string;
273
+ stroke: string;
274
+ text: string;
275
+ };
276
+ type EdgeStyleConfig = {
277
+ dashArray?: number[];
278
+ width: number;
279
+ };
280
+ type FlowTheme = {
281
+ colors: {
282
+ entity: Record<string, EntityColorSet>;
283
+ selection: string;
284
+ connection: string;
285
+ connectionValid: string;
286
+ connectionInvalid: string;
287
+ highlight: string;
288
+ focus: string;
289
+ canvas: string;
290
+ grid: string;
291
+ };
292
+ edgeStyles: Record<string, EdgeStyleConfig>;
293
+ spacing: {
294
+ gridSize: number;
295
+ snapSize: number;
296
+ portSize: number;
297
+ selectionPadding: number;
298
+ };
299
+ };
300
+ /** A behavior predicate: function or `false` to disable globally */
301
+ type BehaviorPredicate<TEntity = unknown, TState = unknown> = ((entity: TEntity, flowState: TState) => boolean) | false;
302
+ type FlowConfig<TEntity = unknown, TState = unknown> = {
303
+ selectable: BehaviorPredicate<TEntity, TState>;
304
+ draggable: BehaviorPredicate<TEntity, TState>;
305
+ connectable: BehaviorPredicate<TEntity, TState>;
306
+ reconnectable: BehaviorPredicate<TEntity, TState>;
307
+ deletable: BehaviorPredicate<TEntity, TState>;
308
+ resizable: BehaviorPredicate<TEntity, TState>;
309
+ visible: BehaviorPredicate<TEntity, TState>;
310
+ };
311
+ type ViewportAnimationOptions = {
312
+ duration?: number;
313
+ easing?: (t: number) => number;
314
+ };
315
+ type FitViewOptions = ViewportAnimationOptions & {
316
+ padding?: number;
317
+ minZoom?: number;
318
+ maxZoom?: number;
319
+ nodes?: Array<string | {
320
+ id: string;
321
+ }>;
322
+ };
323
+ //#endregion
324
+ //#region src/routing/index.d.ts
325
+ type EdgeRouterContext = {
326
+ sourceBounds: Rect;
327
+ targetBounds: Rect;
328
+ sourceDirection: Direction;
329
+ targetDirection: Direction;
330
+ sourcePoint?: Point;
331
+ targetPoint?: Point;
332
+ /** All node bounds for obstacle avoidance */
333
+ obstacles: Rect[];
334
+ };
335
+ type EdgeRouter = (edge: {
336
+ sourceId: string;
337
+ targetId: string;
338
+ }, context: EdgeRouterContext) => PathData;
339
+ declare const straightRouter: EdgeRouter;
340
+ declare const stepRouter: EdgeRouter;
341
+ declare const bezierRouter: EdgeRouter;
342
+ /**
343
+ * Determine the best side of `from` to connect toward `to`,
344
+ * based on relative center positions.
345
+ */
346
+ declare function bestDirection(from: Rect, to: Rect): Direction;
347
+ /**
348
+ * Convert PathData points to an SVG path `d` attribute.
349
+ * Handles 2 points (line), 3 points (quadratic), 4 points (cubic bezier).
350
+ */
351
+ declare function pathToSVG(path: PathData): string;
352
+ //#endregion
353
+ //#region src/snap.d.ts
354
+ interface SnapLine {
355
+ axis: 'x' | 'y';
356
+ value: number;
357
+ }
358
+ interface SpacingGuide {
359
+ axis: 'x' | 'y';
360
+ /** Position on the perpendicular axis (y for 'x' axis, x for 'y') */
361
+ position: number;
362
+ /** The gap distance being matched */
363
+ spacing: number;
364
+ /** Segments showing where spacing applies */
365
+ ranges: Array<{
366
+ start: number;
367
+ end: number;
368
+ }>;
369
+ }
370
+ interface SnapResult {
371
+ snapLines: SnapLine[];
372
+ /** Adjusted rect position (size unchanged) */
373
+ snapRect: Rect;
374
+ spacingGuides?: SpacingGuide[];
375
+ }
376
+ interface SnapOptions {
377
+ /** Distance threshold in canvas pixels (default 5) */
378
+ threshold?: number;
379
+ /** Enable equal-spacing guides (default false) */
380
+ enableSpacing?: boolean;
381
+ }
382
+ /**
383
+ * Compute snap lines for a dragged rect against other rects.
384
+ *
385
+ * Checks alignment of left/right/center-x and top/bottom/center-y
386
+ * against all target rects. Optionally checks equal spacing between elements.
387
+ *
388
+ * Returns null if no snap is within threshold.
389
+ */
390
+ declare function getSnapLines(rect: Rect, otherRects: Rect[], {
391
+ threshold,
392
+ enableSpacing
393
+ }?: SnapOptions): SnapResult | null;
394
+ //#endregion
395
+ //#region src/engine.d.ts
396
+ type ProposedConnection = {
397
+ sourceId: string;
398
+ targetId: string;
399
+ sourcePort?: string | null;
400
+ targetPort?: string | null;
401
+ };
402
+ type FlowEngineOptions = {
403
+ /** Default edge router (default: bezierRouter) */
404
+ edgeRouter?: EdgeRouter;
405
+ /** Default label anchor (default: 'fixed' — labels use their own x/y) */
406
+ labelAnchor?: LabelAnchor;
407
+ /** Connection validation hook */
408
+ canConnect?: (proposed: ProposedConnection) => boolean;
409
+ /** Global behavior config */
410
+ config?: Partial<FlowConfig>;
411
+ /** Custom visibility function */
412
+ isVisible?: (entity: FlowNode | FlowEdge, viewport: Viewport) => boolean;
413
+ /**
414
+ * Which node an edge belongs to (its labels contribute to that group's
415
+ * derived child bounds). Return a node id, null for the root, or undefined
416
+ * to fall back to the default rule: the deepest node containing both
417
+ * endpoints (an endpoint contains itself; self-edges go to the source's
418
+ * parent) — Stately-editor semantics.
419
+ */
420
+ edgeOwner?: (edge: FlowEdge, context: FlowStoreContext) => string | null | undefined;
421
+ };
422
+ type RenderableEntitiesOptions = {
423
+ cull?: 'none' | 'viewport';
424
+ overscan?: number;
425
+ };
426
+ type EdgePathOptions = {
427
+ graph?: FlowStoreContext['graph'];
428
+ };
429
+ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions): {
430
+ store: _xstate_store1.Store<FlowStoreContext, {
431
+ createNode: {
432
+ node: FlowNode;
433
+ } & {
434
+ transactionId?: string;
435
+ };
436
+ deleteNode: {
437
+ id: string;
438
+ } & {
439
+ transactionId?: string;
440
+ };
441
+ updateNodeData: {
442
+ id: string;
443
+ data: Record<string, unknown>;
444
+ } & {
445
+ transactionId?: string;
446
+ };
447
+ createEdge: {
448
+ edge: FlowEdge;
449
+ } & {
450
+ transactionId?: string;
451
+ };
452
+ deleteEdge: {
453
+ id: string;
454
+ } & {
455
+ transactionId?: string;
456
+ };
457
+ updateEdgeData: {
458
+ id: string;
459
+ data: Record<string, unknown>;
460
+ } & {
461
+ transactionId?: string;
462
+ };
463
+ deleteSelected: undefined;
464
+ setGraph: {
465
+ graph: FlowGraph;
466
+ };
467
+ reset: undefined;
468
+ reparentNode: {
469
+ id: string;
470
+ parentId: string | null;
471
+ } & {
472
+ transactionId?: string;
473
+ };
474
+ dragStart: {
475
+ id: string;
476
+ } & {
477
+ transactionId?: string;
478
+ };
479
+ dragMove: {
480
+ dx: number;
481
+ dy: number;
482
+ };
483
+ dragEnd: undefined;
484
+ commitDrag: undefined;
485
+ select: {
486
+ ids: string[];
487
+ mode?: "single" | "multi";
488
+ };
489
+ selectAll: undefined;
490
+ clearSelection: undefined;
491
+ selectionBoxStart: {
492
+ point: Point;
493
+ mode?: "single" | "multi";
494
+ };
495
+ selectionBoxMove: {
496
+ point: Point;
497
+ };
498
+ selectionBoxEnd: undefined;
499
+ focus: {
500
+ entityId: string;
501
+ };
502
+ clearFocus: undefined;
503
+ setHover: {
504
+ ids: string[];
505
+ };
506
+ clearHover: undefined;
507
+ setHighlights: {
508
+ kind: string;
509
+ entries: FlowHighlightEntry[];
510
+ };
511
+ addHighlights: {
512
+ kind: string;
513
+ entries: FlowHighlightEntry[];
514
+ };
515
+ removeHighlights: {
516
+ kind: string;
517
+ ids: string[];
518
+ };
519
+ clearHighlights: {
520
+ kind?: string;
521
+ } | undefined;
522
+ updateParentNodeId: {
523
+ parentNodeId: string | null;
524
+ };
525
+ setViewport: Viewport;
526
+ panBy: Point;
527
+ zoomTo: {
528
+ zoom: number;
529
+ center: Point;
530
+ };
531
+ zoomBy: {
532
+ factor: number;
533
+ center?: Point;
534
+ };
535
+ setMinZoom: {
536
+ minZoom: number;
537
+ };
538
+ setMaxZoom: {
539
+ maxZoom: number;
540
+ };
541
+ setDragThreshold: {
542
+ dragThreshold: number;
543
+ };
544
+ setAutoPanOptions: {
545
+ autoPanOnDrag?: boolean;
546
+ autoPanThreshold?: number;
547
+ autoPanSpeed?: number;
548
+ };
549
+ setTranslateExtent: {
550
+ extent: [Point, Point] | null;
551
+ };
552
+ setNodeExtent: {
553
+ extent: [Point, Point] | null;
554
+ };
555
+ updateViewportSize: Size;
556
+ fitView: FitViewOptions | undefined;
557
+ pushViewport: undefined;
558
+ popViewport: undefined;
559
+ panStart: Point;
560
+ pan: Point;
561
+ panEnd: undefined;
562
+ setCanvasState: {
563
+ state: CanvasState;
564
+ };
565
+ connectionStart: {
566
+ sourceId: string;
567
+ sourcePort: string | null;
568
+ position: Point;
569
+ };
570
+ connectionMove: {
571
+ position: Point;
572
+ targetId?: string | null;
573
+ targetPort?: string | null;
574
+ isValid?: boolean;
575
+ };
576
+ connectionEnd: {
577
+ target?: ConnectEndTarget;
578
+ } | undefined;
579
+ cancelConnection: undefined;
580
+ setConnectionClickStartHandle: {
581
+ nodeId: string;
582
+ port: string | null;
583
+ } | null;
584
+ resizeStart: {
585
+ id: string;
586
+ handle: ResizeHandle;
587
+ } & {
588
+ transactionId?: string;
589
+ };
590
+ resizeMove: Point;
591
+ resizeEnd: undefined;
592
+ resizeCancel: undefined;
593
+ reconnectEdge: {
594
+ edgeId: string;
595
+ newSourceId?: string;
596
+ newTargetId?: string;
597
+ newSourcePort?: string;
598
+ newTargetPort?: string;
599
+ } & {
600
+ transactionId?: string;
601
+ };
602
+ setMode: {
603
+ mode: string;
604
+ };
605
+ setSnapToGrid: {
606
+ enabled: boolean;
607
+ grid?: [number, number];
608
+ };
609
+ setSnapLines: {
610
+ enabled: boolean;
611
+ threshold?: number;
612
+ spacing?: boolean;
613
+ };
614
+ setColorMode: {
615
+ colorMode: FlowColorMode;
616
+ };
617
+ moveNodes: {
618
+ direction: Point;
619
+ factor?: number;
620
+ } & {
621
+ transactionId?: string;
622
+ };
623
+ requestLayout: {
624
+ algorithm?: string;
625
+ };
626
+ applyLayoutResult: {
627
+ positions: Map<string, {
628
+ x: number;
629
+ y: number;
630
+ }>;
631
+ edgeLabelPositions?: Map<string, {
632
+ x: number;
633
+ y: number;
634
+ }>;
635
+ } & {
636
+ transactionId?: string;
637
+ };
638
+ updateMeasurements: {
639
+ measurements: Array<{
640
+ id: string;
641
+ rect: Rect;
642
+ }>;
643
+ };
644
+ removeMeasurements: {
645
+ ids: string[];
646
+ };
647
+ bakeLabelPositions: {
648
+ positions: Map<string, Point>;
649
+ } & {
650
+ transactionId?: string;
651
+ };
652
+ } & {
653
+ undo: null;
654
+ redo: null;
655
+ }, _xstate_store1.ExtractEvents<{
656
+ layoutRequested: LayoutRequestedEvent;
657
+ connectionEnded: ConnectionEndedEvent;
658
+ graphChanged: FlowGraphChangedEvent;
659
+ viewportChanged: FlowViewportChangedEvent;
660
+ selectionChanged: FlowSelectionChangedEvent;
661
+ entitiesDeleted: FlowEntitiesDeletedEvent;
662
+ error: FlowErrorEvent;
663
+ }>>;
664
+ trigger: _xstate_store1.TriggerObject<{
665
+ createNode: {
666
+ node: FlowNode;
667
+ } & {
668
+ transactionId?: string;
669
+ };
670
+ deleteNode: {
671
+ id: string;
672
+ } & {
673
+ transactionId?: string;
674
+ };
675
+ updateNodeData: {
676
+ id: string;
677
+ data: Record<string, unknown>;
678
+ } & {
679
+ transactionId?: string;
680
+ };
681
+ createEdge: {
682
+ edge: FlowEdge;
683
+ } & {
684
+ transactionId?: string;
685
+ };
686
+ deleteEdge: {
687
+ id: string;
688
+ } & {
689
+ transactionId?: string;
690
+ };
691
+ updateEdgeData: {
692
+ id: string;
693
+ data: Record<string, unknown>;
694
+ } & {
695
+ transactionId?: string;
696
+ };
697
+ deleteSelected: undefined;
698
+ setGraph: {
699
+ graph: FlowGraph;
700
+ };
701
+ reset: undefined;
702
+ reparentNode: {
703
+ id: string;
704
+ parentId: string | null;
705
+ } & {
706
+ transactionId?: string;
707
+ };
708
+ dragStart: {
709
+ id: string;
710
+ } & {
711
+ transactionId?: string;
712
+ };
713
+ dragMove: {
714
+ dx: number;
715
+ dy: number;
716
+ };
717
+ dragEnd: undefined;
718
+ commitDrag: undefined;
719
+ select: {
720
+ ids: string[];
721
+ mode?: "single" | "multi";
722
+ };
723
+ selectAll: undefined;
724
+ clearSelection: undefined;
725
+ selectionBoxStart: {
726
+ point: Point;
727
+ mode?: "single" | "multi";
728
+ };
729
+ selectionBoxMove: {
730
+ point: Point;
731
+ };
732
+ selectionBoxEnd: undefined;
733
+ focus: {
734
+ entityId: string;
735
+ };
736
+ clearFocus: undefined;
737
+ setHover: {
738
+ ids: string[];
739
+ };
740
+ clearHover: undefined;
741
+ setHighlights: {
742
+ kind: string;
743
+ entries: FlowHighlightEntry[];
744
+ };
745
+ addHighlights: {
746
+ kind: string;
747
+ entries: FlowHighlightEntry[];
748
+ };
749
+ removeHighlights: {
750
+ kind: string;
751
+ ids: string[];
752
+ };
753
+ clearHighlights: {
754
+ kind?: string;
755
+ } | undefined;
756
+ updateParentNodeId: {
757
+ parentNodeId: string | null;
758
+ };
759
+ setViewport: Viewport;
760
+ panBy: Point;
761
+ zoomTo: {
762
+ zoom: number;
763
+ center: Point;
764
+ };
765
+ zoomBy: {
766
+ factor: number;
767
+ center?: Point;
768
+ };
769
+ setMinZoom: {
770
+ minZoom: number;
771
+ };
772
+ setMaxZoom: {
773
+ maxZoom: number;
774
+ };
775
+ setDragThreshold: {
776
+ dragThreshold: number;
777
+ };
778
+ setAutoPanOptions: {
779
+ autoPanOnDrag?: boolean;
780
+ autoPanThreshold?: number;
781
+ autoPanSpeed?: number;
782
+ };
783
+ setTranslateExtent: {
784
+ extent: [Point, Point] | null;
785
+ };
786
+ setNodeExtent: {
787
+ extent: [Point, Point] | null;
788
+ };
789
+ updateViewportSize: Size;
790
+ fitView: FitViewOptions | undefined;
791
+ pushViewport: undefined;
792
+ popViewport: undefined;
793
+ panStart: Point;
794
+ pan: Point;
795
+ panEnd: undefined;
796
+ setCanvasState: {
797
+ state: CanvasState;
798
+ };
799
+ connectionStart: {
800
+ sourceId: string;
801
+ sourcePort: string | null;
802
+ position: Point;
803
+ };
804
+ connectionMove: {
805
+ position: Point;
806
+ targetId?: string | null;
807
+ targetPort?: string | null;
808
+ isValid?: boolean;
809
+ };
810
+ connectionEnd: {
811
+ target?: ConnectEndTarget;
812
+ } | undefined;
813
+ cancelConnection: undefined;
814
+ setConnectionClickStartHandle: {
815
+ nodeId: string;
816
+ port: string | null;
817
+ } | null;
818
+ resizeStart: {
819
+ id: string;
820
+ handle: ResizeHandle;
821
+ } & {
822
+ transactionId?: string;
823
+ };
824
+ resizeMove: Point;
825
+ resizeEnd: undefined;
826
+ resizeCancel: undefined;
827
+ reconnectEdge: {
828
+ edgeId: string;
829
+ newSourceId?: string;
830
+ newTargetId?: string;
831
+ newSourcePort?: string;
832
+ newTargetPort?: string;
833
+ } & {
834
+ transactionId?: string;
835
+ };
836
+ setMode: {
837
+ mode: string;
838
+ };
839
+ setSnapToGrid: {
840
+ enabled: boolean;
841
+ grid?: [number, number];
842
+ };
843
+ setSnapLines: {
844
+ enabled: boolean;
845
+ threshold?: number;
846
+ spacing?: boolean;
847
+ };
848
+ setColorMode: {
849
+ colorMode: FlowColorMode;
850
+ };
851
+ moveNodes: {
852
+ direction: Point;
853
+ factor?: number;
854
+ } & {
855
+ transactionId?: string;
856
+ };
857
+ requestLayout: {
858
+ algorithm?: string;
859
+ };
860
+ applyLayoutResult: {
861
+ positions: Map<string, {
862
+ x: number;
863
+ y: number;
864
+ }>;
865
+ edgeLabelPositions?: Map<string, {
866
+ x: number;
867
+ y: number;
868
+ }>;
869
+ } & {
870
+ transactionId?: string;
871
+ };
872
+ updateMeasurements: {
873
+ measurements: Array<{
874
+ id: string;
875
+ rect: Rect;
876
+ }>;
877
+ };
878
+ removeMeasurements: {
879
+ ids: string[];
880
+ };
881
+ bakeLabelPositions: {
882
+ positions: Map<string, Point>;
883
+ } & {
884
+ transactionId?: string;
885
+ };
886
+ } & {
887
+ undo: null;
888
+ redo: null;
889
+ }>;
890
+ getContext: () => FlowStoreContext;
891
+ getNode: (id: string) => FlowNode | undefined;
892
+ getEdge: (id: string) => FlowEdge | undefined;
893
+ getEntity: (id: string) => FlowNode | FlowEdge | undefined;
894
+ getAddressable: (id: string) => FlowAddressable | null;
895
+ getOwnerEntity: (id: string) => FlowNode | FlowEdge | null;
896
+ getBounds: (id: string) => Rect | null;
897
+ screenToCanvas: (screenPoint: Point) => Point;
898
+ canvasToScreen: (canvasPoint: Point) => Point;
899
+ entityAtPoint: (canvasPoint: Point) => FlowNode | FlowEdge | null;
900
+ entityIdAtPoint: (canvasPoint: Point) => string | null;
901
+ getEdgePath: (edgeId: string) => PathData | null;
902
+ getEdgePathBounds: (edgeId: string) => Rect | null;
903
+ getEdgeLabelBounds: (edgeId: string) => Rect | null;
904
+ getAllEdgePaths: (options?: EdgePathOptions) => Map<string, EdgePathData>;
905
+ resolvedPosition: (nodeOrId: FlowNode | string) => Point;
906
+ resolvedBounds: (nodeOrId: FlowNode | string) => Rect;
907
+ /**
908
+ * All highlights on an entity as `{ kind, meta }` entries. Returns a
909
+ * referentially stable array (the same empty array when none), so
910
+ * subscribers can use identity equality.
911
+ */
912
+ getHighlights: (entityId: string) => ReadonlyArray<{
913
+ kind: string;
914
+ meta: unknown;
915
+ }>;
916
+ /** Whether the entity is currently hovered. */
917
+ isHovered: (entityId: string) => boolean;
918
+ /**
919
+ * Deepest group whose child area intersects `bounds`, with the overlap
920
+ * ratio (intersection / bounds area). Groups in `exclude` (and groups
921
+ * inside excluded subtrees) are skipped, and excluded nodes do not
922
+ * contribute to derived child areas — i.e. each group is evaluated as it
923
+ * would be without the moving nodes. Drives reparent-on-drop.
924
+ */
925
+ getGroupDropTarget: (bounds: Rect, options?: {
926
+ exclude?: Iterable<string>;
927
+ }) => {
928
+ id: string;
929
+ overlap: number;
930
+ childArea: Rect;
931
+ } | null;
932
+ /**
933
+ * Canvas-space anchor rect for toolbars: a node's (hierarchy-aware)
934
+ * bounds, an edge's label bounds — or, with no label, an assumed 1×1
935
+ * label at the path midpoint — and, given several ids (e.g. the
936
+ * selection), the union of their anchors. Null when nothing resolves.
937
+ */
938
+ getToolbarAnchor: (idOrIds: string | Iterable<string>) => Rect | null;
939
+ /** The node containing this edge (null = root). See `edgeOwner` option. */
940
+ getEdgeOwner: (edgeId: string) => string | null;
941
+ /** Group geometry (overall bounds, content block, child area), or null. */
942
+ getGroupGeometry: (nodeOrId: FlowNode | string) => GroupGeometry | null;
943
+ getGraphBounds: () => Rect;
944
+ getSelectionBounds: () => Rect | null;
945
+ entitiesInRect: (rect: Rect) => string[];
946
+ getPortPosition: (nodeId: string, portName: string) => Point | null;
947
+ getPortPositions: (nodeId: string) => Map<string, Point>;
948
+ getEdgeEndpoints: (edgeId: string) => {
949
+ source: Point;
950
+ target: Point;
951
+ } | null;
952
+ validateConnection: (proposed: ProposedConnection) => boolean;
953
+ resolveEntityConfig: (entityOrId: FlowNode | FlowEdge | string) => {
954
+ hidden: boolean;
955
+ selectable: boolean;
956
+ draggable: boolean;
957
+ connectable: boolean;
958
+ reconnectable: boolean;
959
+ deletable: boolean;
960
+ resizable: boolean;
961
+ };
962
+ getVisibleEntities: () => {
963
+ nodes: FlowNode[];
964
+ edges: FlowEdge[];
965
+ };
966
+ /**
967
+ * Renderable (visible, optionally viewport-culled) entities. Memoized per
968
+ * (store snapshot, cull/overscan) so several render layers can share one
969
+ * computation per frame. Treat the result as read-only.
970
+ */
971
+ getRenderableEntities: (options?: RenderableEntitiesOptions) => {
972
+ nodes: FlowNode[];
973
+ edges: FlowEdge[];
974
+ };
975
+ getIntersectingNodes: (nodeId: string) => FlowNode[];
976
+ getAriaLabel: (entityId: string) => string;
977
+ /** Compute snap result during drag. Returns null if not dragging or snap lines disabled.
978
+ * Only activates after actual movement (dx/dy != 0) to avoid showing on click. */
979
+ getSnapResult: () => SnapResult | null;
980
+ /** Get in-progress resize bounds, or null if not resizing */
981
+ getResizeBounds: () => Rect | null;
982
+ subscribe: (listener: (ctx: FlowStoreContext) => void) => () => void;
983
+ };
984
+ type FlowEngine = ReturnType<typeof createFlowEngine>;
985
+ //#endregion
986
+ //#region src/input/modes.d.ts
987
+ declare function keyboardMode(options?: {
988
+ allowDelete?: boolean;
989
+ allowUndo?: boolean;
990
+ }): FlowInputMode;
991
+ declare function keyboardNavMode(options?: {
992
+ allowMove?: boolean;
993
+ step?: number;
994
+ shiftStep?: number;
995
+ }): FlowInputMode;
996
+ declare function wheelMode(): FlowInputMode;
997
+ declare function panMode(): FlowInputMode;
998
+ type ReparentDropContext = {
999
+ /** Top-level dragged nodes (descendants of dragged nodes excluded). */
1000
+ nodes: FlowNode[];
1001
+ /** Combined visual bounds of the dragged nodes. */
1002
+ bounds: Rect;
1003
+ /** Best drop candidate (evaluated as if the dragged nodes were absent). */
1004
+ candidate: {
1005
+ id: string;
1006
+ overlap: number;
1007
+ } | null;
1008
+ /** Continuous time the current candidate has been hovered, in ms. */
1009
+ hoverMs: number;
1010
+ modifiers: {
1011
+ shift: boolean;
1012
+ meta: boolean;
1013
+ ctrl: boolean;
1014
+ alt: boolean;
1015
+ };
1016
+ };
1017
+ type ReparentDecision = string | null | undefined;
1018
+ type ReparentOptions = {
1019
+ /** Minimum overlap ratio (dragged bounds ∩ child area / dragged area). Default 0.5. */
1020
+ minOverlap?: number;
1021
+ /** Required continuous hover time over a candidate before it counts. Default 0. */
1022
+ delayMs?: number;
1023
+ /**
1024
+ * Geometric unparenting: when no candidate exists AND the current parent's
1025
+ * rendered child area no longer touches the dragged bounds, clear the
1026
+ * parent. Only ever fires for `fixed` groups — `derived` groups stretch to
1027
+ * keep containing their children, so they can only be left via the
1028
+ * modifier gesture or a custom `decide`. Default true.
1029
+ */
1030
+ unparent?: boolean;
1031
+ /**
1032
+ * Holding this modifier at drop forces unparenting (release it before
1033
+ * dropping to cancel). Default 'alt'; null disables.
1034
+ */
1035
+ unparentModifier?: 'alt' | 'shift' | 'meta' | 'ctrl' | null;
1036
+ /**
1037
+ * Full custom policy. Return a node id to reparent into it, null to clear
1038
+ * the parent, undefined to keep current parents. When provided, it
1039
+ * replaces the built-in decision entirely.
1040
+ */
1041
+ decide?: (drop: ReparentDropContext, ctx: FlowInputModeContext) => ReparentDecision;
1042
+ };
1043
+ declare function entityPressMode(options?: {
1044
+ drag?: boolean;
1045
+ reparent?: boolean | ReparentOptions;
1046
+ }): FlowInputMode;
1047
+ type ConnectModeOptions = {
1048
+ /**
1049
+ * Validity check for the current hover target during a connection drag.
1050
+ * Defaults to `engine.validateConnection` for node/port targets (rejecting
1051
+ * the source node itself) and `false` for everything else. Engine-level
1052
+ * validation policy belongs in `createFlowEngine({ canConnect })`; use this
1053
+ * override for gesture-specific rules (e.g. allowing canvas drops).
1054
+ */
1055
+ isValid?: (args: {
1056
+ source: {
1057
+ nodeId: string;
1058
+ port: string;
1059
+ };
1060
+ target: FlowInputTarget;
1061
+ point: Point;
1062
+ }, ctx: FlowInputModeContext) => boolean;
1063
+ };
1064
+ declare function connectMode(options?: ConnectModeOptions): FlowInputMode;
1065
+ declare function hoverMode(): FlowInputMode;
1066
+ declare function panePressMode(): FlowInputMode;
1067
+ /** Interactive default: full editing gestures. */
1068
+ declare const defaultInputModes: FlowInputMode[];
1069
+ /** Readonly: select and navigate, no mutation gestures. */
1070
+ declare const readonlyInputModes: FlowInputMode[];
1071
+ //#endregion
1072
+ //#region src/input/index.d.ts
1073
+ type FlowInputModifiers = {
1074
+ shift: boolean;
1075
+ meta: boolean;
1076
+ ctrl: boolean;
1077
+ alt: boolean;
1078
+ };
1079
+ type FlowInputTarget = {
1080
+ kind: 'pane';
1081
+ } | {
1082
+ kind: 'entity';
1083
+ id: string;
1084
+ part?: 'label';
1085
+ /**
1086
+ * Drag-handle gating (set by adapters from `data-flow-drag-handle`
1087
+ * markers): when the entity declares a handle, drags only start from
1088
+ * presses inside it — e.g. a group that is dragged by its content
1089
+ * block but not by its children area.
1090
+ */
1091
+ entityHasDragHandle?: boolean;
1092
+ pressedDragHandle?: boolean;
1093
+ } | {
1094
+ kind: 'port';
1095
+ nodeId: string;
1096
+ portName: string;
1097
+ } | {
1098
+ kind: 'none';
1099
+ };
1100
+ type FlowPointerInputEvent = {
1101
+ kind: 'pointer.down' | 'pointer.move' | 'pointer.up' | 'pointer.cancel';
1102
+ pointerId: number;
1103
+ /** Pressed button for down events (0 left, 1 middle); -1 for moves. */
1104
+ button: number;
1105
+ /** Pointer position in canvas (graph/world) coordinates. */
1106
+ point: Point;
1107
+ /** Pointer position in container-relative screen pixels. */
1108
+ screenPoint: Point;
1109
+ target: FlowInputTarget;
1110
+ modifiers: FlowInputModifiers;
1111
+ };
1112
+ type FlowWheelInputEvent = {
1113
+ kind: 'wheel';
1114
+ deltaX: number;
1115
+ deltaY: number;
1116
+ /** WheelEvent.deltaMode: 0 pixels, 1 lines, 2 pages. */
1117
+ deltaMode: number;
1118
+ point: Point;
1119
+ screenPoint: Point;
1120
+ target: FlowInputTarget;
1121
+ modifiers: FlowInputModifiers;
1122
+ };
1123
+ type FlowKeyInputEvent = {
1124
+ kind: 'key.down' | 'key.up';
1125
+ key: string;
1126
+ /** True when the event originated from a text input/contenteditable. */
1127
+ editableTarget: boolean;
1128
+ modifiers: FlowInputModifiers;
1129
+ };
1130
+ type FlowInputEvent = FlowPointerInputEvent | FlowWheelInputEvent | FlowKeyInputEvent;
1131
+ type FlowTriggerMap = FlowStore['trigger'];
1132
+ type FlowTriggerName = keyof FlowTriggerMap & string;
1133
+ type FlowTriggerCommand = {
1134
+ type: 'trigger';
1135
+ name: FlowTriggerName;
1136
+ params?: unknown;
1137
+ };
1138
+ type FlowCommand = FlowTriggerCommand | {
1139
+ type: 'preventDefault';
1140
+ } | {
1141
+ type: 'stopPropagation';
1142
+ };
1143
+ /** Typed constructor for trigger commands. */
1144
+ declare function trigger<K extends FlowTriggerName>(name: K, ...params: Parameters<FlowTriggerMap[K]>): FlowTriggerCommand;
1145
+ declare const preventDefault: FlowCommand;
1146
+ type FlowInputModeContext = {
1147
+ /** Current store snapshot context. */
1148
+ context: FlowStoreContext;
1149
+ /** Engine for read-only queries (hit info, behavior config). */
1150
+ engine: FlowEngine;
1151
+ /** Runtime-tracked transient input state (lives outside the store). */
1152
+ input: {
1153
+ spaceHeld: boolean;
1154
+ };
1155
+ };
1156
+ type FlowSessionResult = {
1157
+ commands?: FlowCommand[];
1158
+ /** 'continue' (default) keeps the session; 'end' terminates it. */
1159
+ status?: 'continue' | 'end';
1160
+ };
1161
+ type FlowInputSessionHandlers = {
1162
+ /** Receives subsequent events for the session's pointer. */
1163
+ update: (event: FlowInputEvent, ctx: FlowInputModeContext) => FlowSessionResult | void;
1164
+ /** Called when the runtime cancels the session (dispose, external cancel). */
1165
+ cancel?: (ctx: FlowInputModeContext) => FlowCommand[] | void;
1166
+ };
1167
+ type FlowInputReaction = {
1168
+ commands?: FlowCommand[];
1169
+ /** Begin an exclusive session that receives subsequent events. */
1170
+ session?: FlowInputSessionHandlers;
1171
+ };
1172
+ type FlowInputMode = {
1173
+ id: string;
1174
+ /** Higher priority runs earlier. Default 0. */
1175
+ priority?: number;
1176
+ /**
1177
+ * Inspect an event and either claim it (return a reaction — the event is
1178
+ * consumed and lower-priority modes are skipped) or pass (return null).
1179
+ */
1180
+ start: (event: FlowInputEvent, ctx: FlowInputModeContext) => FlowInputReaction | null | undefined | void;
1181
+ };
1182
+ type FlowInputEffects = {
1183
+ /** The adapter should call event.preventDefault(). */
1184
+ preventDefault: boolean;
1185
+ /** The adapter should call event.stopPropagation(). */
1186
+ stopPropagation: boolean;
1187
+ /** A session began on this event — adapters should capture the pointer. */
1188
+ sessionStarted: boolean;
1189
+ /** The active session ended — adapters should release the pointer. */
1190
+ sessionEnded: boolean;
1191
+ /** Id of the mode that handled the event, or null if unhandled. */
1192
+ handledBy: string | null;
1193
+ };
1194
+ type FlowInputRuntimeOptions = {
1195
+ store: FlowStore;
1196
+ engine: FlowEngine;
1197
+ /**
1198
+ * Input modes, or a resolver from store context (so the active set can
1199
+ * follow `context.mode`). Defaults to `defaultModesForContext`: the
1200
+ * interactive set, or the readonly set when `context.mode === 'readonly'`.
1201
+ */
1202
+ modes?: FlowInputMode[] | ((context: FlowStoreContext) => FlowInputMode[]);
1203
+ };
1204
+ type FlowInputRuntime = {
1205
+ /** Feed one normalized event; apply resulting commands to the store. */
1206
+ send: (event: FlowInputEvent) => FlowInputEffects;
1207
+ /** Cancel the active session, if any (applies its cancel commands). */
1208
+ cancelSession: () => void;
1209
+ /** Id of the mode owning the active session, or null. */
1210
+ getActiveSession: () => string | null;
1211
+ };
1212
+ declare function createFlowInputRuntime(options: FlowInputRuntimeOptions): FlowInputRuntime;
1213
+ /** Default mode resolution: follow the store's `context.mode`. */
1214
+ declare function defaultModesForContext(context: FlowStoreContext): FlowInputMode[];
1215
+ /**
1216
+ * Mode resolution driven by a store profile: the active store mode's
1217
+ * `input.modes` wins, then the profile-level `input.modes`, then the
1218
+ * built-in defaults.
1219
+ */
1220
+ declare function profileModesForContext(profile: FlowProfile): (context: FlowStoreContext) => FlowInputMode[];
1221
+ /**
1222
+ * Per-frame auto-pan step while a drag or connection gesture is near the
1223
+ * container edge. Returns the `calcAutoPan` screen-space delta (negate it for
1224
+ * `panBy`), or null when auto-pan should not run. Adapters call this from a
1225
+ * frame ticker while a gesture session is active and re-send the stationary
1226
+ * pointer afterwards so the dragged entity follows the panned canvas.
1227
+ */
1228
+ declare function getAutoPanDelta(context: FlowStoreContext, screenPoint: Point,
1229
+ /**
1230
+ * When provided (and dragging), auto-pan is additionally gated on the
1231
+ * dragged content: each pan direction fires only if the dragged selection
1232
+ * actually reaches that viewport edge. Prevents pointless scrolling when a
1233
+ * clamped child is pinned mid-canvas while the pointer overshoots.
1234
+ */
1235
+ engine?: FlowEngine): Point | null;
1236
+ //#endregion
1237
+ //#region src/profile.d.ts
1238
+ type FlowEventObject = {
1239
+ type: string;
1240
+ [key: string]: unknown;
1241
+ };
1242
+ type FlowTransition<TEvent extends FlowEventObject = FlowEventObject> = (context: FlowStoreContext, event: TEvent, enqueue: unknown) => FlowStoreContext;
1243
+ type FlowTransitions = Record<string, FlowTransition>;
1244
+ type FlowInputProfile = {
1245
+ /**
1246
+ * Input modes for this profile/mode. Resolved by
1247
+ * `profileModesForContext(profile)`: the active store mode's modes win,
1248
+ * then the profile-level modes, then the built-in defaults.
1249
+ */
1250
+ modes?: FlowInputMode[];
1251
+ options?: {
1252
+ dragThreshold?: number;
1253
+ clickDistance?: number;
1254
+ longPressDelay?: number;
1255
+ autoPan?: {
1256
+ enabled?: boolean;
1257
+ threshold?: number;
1258
+ speed?: number;
1259
+ };
1260
+ };
1261
+ };
1262
+ type FlowOrigin = "top-left" | "center" | "center-x" | "center-y" | {
1263
+ x: number;
1264
+ y: number;
1265
+ };
1266
+ type FlowSettings = {
1267
+ nodeMeasurementOrigin?: FlowOrigin;
1268
+ edgeLabelMeasurementOrigin?: FlowOrigin;
1269
+ snapToGrid?: boolean;
1270
+ snapGrid?: [number, number];
1271
+ };
1272
+ type FlowPolicies = {
1273
+ canSelect?: unknown;
1274
+ canFocus?: unknown;
1275
+ canHover?: unknown;
1276
+ canEdit?: unknown;
1277
+ canDelete?: unknown;
1278
+ canMove?: unknown;
1279
+ canConnect?: unknown;
1280
+ };
1281
+ type FlowRules = {
1282
+ delete?: unknown[];
1283
+ move?: unknown[];
1284
+ reparent?: unknown[];
1285
+ };
1286
+ type FlowResolvers = {
1287
+ blocks?: unknown;
1288
+ bounds?: unknown;
1289
+ owner?: unknown;
1290
+ ports?: unknown;
1291
+ };
1292
+ type FlowModeDefinition = {
1293
+ on?: FlowTransitions;
1294
+ input?: FlowInputProfile;
1295
+ policies?: Partial<FlowPolicies>;
1296
+ rules?: Partial<FlowRules>;
1297
+ settings?: Partial<FlowSettings>;
1298
+ };
1299
+ type FlowProfile = {
1300
+ defaultMode: string;
1301
+ on?: FlowTransitions;
1302
+ input?: FlowInputProfile;
1303
+ modes: Record<string, FlowModeDefinition>;
1304
+ resolvers?: FlowResolvers;
1305
+ policies?: FlowPolicies;
1306
+ rules?: FlowRules;
1307
+ settings?: FlowSettings;
1308
+ };
1309
+ declare function defineFlowProfile<TProfile extends FlowProfile>(profile: TProfile): TProfile;
1310
+ declare const defaultFlowProfile: {
1311
+ defaultMode: string;
1312
+ modes: {
1313
+ interactive: {};
1314
+ readonly: {};
1315
+ };
1316
+ };
1317
+ //#endregion
1318
+ //#region src/store/index.d.ts
1319
+ type FlowStoreContext = {
1320
+ graph: FlowGraph;
1321
+ parentNodeId: string | null;
1322
+ depth: number | null;
1323
+ viewport: Viewport;
1324
+ viewportSize: Size;
1325
+ viewportStack: Viewport[];
1326
+ minZoom: number;
1327
+ maxZoom: number;
1328
+ translateExtent: [Point, Point] | null;
1329
+ nodeExtent: [Point, Point] | null;
1330
+ selection: Set<string>;
1331
+ selectionBox: [Point, Point] | null;
1332
+ /** Entities currently under the pointer (driven by the input runtime). */
1333
+ hoveredEntityIds: Set<string>;
1334
+ /**
1335
+ * Semantic highlights: kind → (entity id → metadata). Kinds are
1336
+ * user-defined strings; metadata is user-defined (e.g. heatmap weights,
1337
+ * colors). Visual-only state — not undoable.
1338
+ */
1339
+ highlights: FlowHighlights;
1340
+ focusedEntityId: string | null;
1341
+ measurements: Map<string, Rect>;
1342
+ canvasState: CanvasState;
1343
+ draggedEntityId: string | null;
1344
+ dragThreshold: number;
1345
+ /**
1346
+ * Constrains where a node may move during drags/keyboard nudges. Receives
1347
+ * the node and its proposed absolute position (after extent/group clamps);
1348
+ * return an adjusted position, or null/undefined to accept. Drag sessions
1349
+ * are pointer-anchored, so constraint clamps never accumulate drift.
1350
+ * Example: prevent sibling overlap (see the PreventOverlap story).
1351
+ */
1352
+ constrainNodeMovement: ((node: FlowNode, proposed: Point, context: FlowStoreContext) => Point | null | undefined) | null;
1353
+ autoPanOnDrag: boolean;
1354
+ autoPanThreshold: number;
1355
+ autoPanSpeed: number;
1356
+ connection: ConnectionState | null;
1357
+ connectOnClick: boolean;
1358
+ connectionClickStartHandle: {
1359
+ nodeId: string;
1360
+ port: string | null;
1361
+ } | null;
1362
+ panOrigin: Point | null;
1363
+ panViewportOrigin: Viewport | null;
1364
+ resizingEntityId: string | null;
1365
+ resizeHandle: ResizeHandle | null;
1366
+ /** Two opposite corners during resize: [anchor, moving]. Derived bounds = min/max of these. */
1367
+ resizeCorners: [Point, Point] | null;
1368
+ mode: string;
1369
+ selectionMode: SelectionMode;
1370
+ snapToGrid: boolean;
1371
+ snapGrid: [number, number];
1372
+ enableSnapLines: boolean;
1373
+ snapThreshold: number;
1374
+ enableSpacingGuides: boolean;
1375
+ autoLayout: AutoLayoutState;
1376
+ colorMode: FlowColorMode;
1377
+ };
1378
+ type FlowColorMode = "light" | "dark" | "system";
1379
+ /** kind → (entity id → metadata) */
1380
+ type FlowHighlights = Map<string, Map<string, unknown>>;
1381
+ type FlowHighlightEntry = {
1382
+ id: string;
1383
+ meta?: unknown;
1384
+ };
1385
+ type FlowStoreOptions = {
1386
+ minZoom?: number;
1387
+ maxZoom?: number;
1388
+ translateExtent?: [Point, Point] | null;
1389
+ nodeExtent?: [Point, Point] | null;
1390
+ dragThreshold?: number;
1391
+ /** See `FlowStoreContext.constrainNodeMovement`. */
1392
+ constrainNodeMovement?: (node: FlowNode, proposed: Point, context: FlowStoreContext) => Point | null | undefined;
1393
+ autoPanOnDrag?: boolean;
1394
+ autoPanThreshold?: number;
1395
+ autoPanSpeed?: number;
1396
+ snapToGrid?: boolean;
1397
+ snapGrid?: [number, number];
1398
+ enableSnapLines?: boolean;
1399
+ snapThreshold?: number;
1400
+ enableSpacingGuides?: boolean;
1401
+ connectOnClick?: boolean;
1402
+ colorMode?: FlowColorMode;
1403
+ connectionDragThreshold?: number;
1404
+ selectionMode?: SelectionMode;
1405
+ historyLimit?: number;
1406
+ mode?: string;
1407
+ profile?: FlowProfile;
1408
+ beforeDelete?: (payload: {
1409
+ graph: FlowGraph;
1410
+ reason: "deleteNode" | "deleteEdge" | "deleteSelected";
1411
+ nodes: FlowNode[];
1412
+ edges: FlowEdge[];
1413
+ }) => false | {
1414
+ nodes?: FlowNode[];
1415
+ edges?: FlowEdge[];
1416
+ } | void;
1417
+ /**
1418
+ * Controls what happens to edges when a node is deleted.
1419
+ * - 'cascade' (default): delete all edges connected to the node
1420
+ * - 'retarget': edges connected to deleted node become self-loops on the other endpoint
1421
+ * - function: custom logic — receives graph + node ids to delete, returns { nodes, edges } to keep
1422
+ */
1423
+ onDeleteNodes?: "cascade" | "retarget" | ((graph: FlowGraph, nodeIds: Set<string>) => {
1424
+ nodes: FlowNode[];
1425
+ edges: FlowEdge[];
1426
+ });
1427
+ };
1428
+ type LayoutRequestedEvent = {
1429
+ algorithm: string;
1430
+ graph: FlowGraph;
1431
+ };
1432
+ type ConnectEndTarget = {
1433
+ kind: "node";
1434
+ nodeId: string;
1435
+ port: string | null;
1436
+ } | {
1437
+ kind: "edge";
1438
+ edgeId: string;
1439
+ } | {
1440
+ kind: "canvas";
1441
+ position: Point;
1442
+ } | {
1443
+ kind: "none";
1444
+ };
1445
+ type ConnectionEndedEvent = {
1446
+ source: {
1447
+ nodeId: string;
1448
+ port: string | null;
1449
+ };
1450
+ target: ConnectEndTarget;
1451
+ connection: ConnectionState;
1452
+ };
1453
+ type FlowGraphChangedEvent = {
1454
+ graph: FlowGraph;
1455
+ event: FlowEventObject;
1456
+ };
1457
+ type FlowViewportChangedEvent = {
1458
+ viewport: Viewport;
1459
+ event: FlowEventObject;
1460
+ };
1461
+ type FlowSelectionChangedEvent = {
1462
+ selection: Set<string>;
1463
+ event: FlowEventObject;
1464
+ };
1465
+ type FlowEntitiesDeletedEvent = {
1466
+ ids: string[];
1467
+ event: FlowEventObject;
1468
+ };
1469
+ type FlowErrorEvent = {
1470
+ error: unknown;
1471
+ event?: FlowEventObject;
1472
+ };
1473
+ type FlowEmittedPayloadMap = {
1474
+ layoutRequested: LayoutRequestedEvent;
1475
+ connectionEnded: ConnectionEndedEvent;
1476
+ graphChanged: FlowGraphChangedEvent;
1477
+ viewportChanged: FlowViewportChangedEvent;
1478
+ selectionChanged: FlowSelectionChangedEvent;
1479
+ entitiesDeleted: FlowEntitiesDeletedEvent;
1480
+ error: FlowErrorEvent;
1481
+ };
1482
+ type FlowEventPayloadMap = {
1483
+ createNode: {
1484
+ node: FlowNode;
1485
+ } & TransactionMetadata;
1486
+ deleteNode: {
1487
+ id: string;
1488
+ } & TransactionMetadata;
1489
+ updateNodeData: {
1490
+ id: string;
1491
+ data: Record<string, unknown>;
1492
+ } & TransactionMetadata;
1493
+ createEdge: {
1494
+ edge: FlowEdge;
1495
+ } & TransactionMetadata;
1496
+ deleteEdge: {
1497
+ id: string;
1498
+ } & TransactionMetadata;
1499
+ updateEdgeData: {
1500
+ id: string;
1501
+ data: Record<string, unknown>;
1502
+ } & TransactionMetadata;
1503
+ deleteSelected: undefined;
1504
+ setGraph: {
1505
+ graph: FlowGraph;
1506
+ };
1507
+ reset: undefined;
1508
+ reparentNode: {
1509
+ id: string;
1510
+ parentId: string | null;
1511
+ } & TransactionMetadata;
1512
+ dragStart: {
1513
+ id: string;
1514
+ } & TransactionMetadata;
1515
+ dragMove: {
1516
+ dx: number;
1517
+ dy: number;
1518
+ };
1519
+ dragEnd: undefined;
1520
+ commitDrag: undefined;
1521
+ select: {
1522
+ ids: string[];
1523
+ mode?: "single" | "multi";
1524
+ };
1525
+ selectAll: undefined;
1526
+ clearSelection: undefined;
1527
+ selectionBoxStart: {
1528
+ point: Point;
1529
+ mode?: "single" | "multi";
1530
+ };
1531
+ selectionBoxMove: {
1532
+ point: Point;
1533
+ };
1534
+ selectionBoxEnd: undefined;
1535
+ focus: {
1536
+ entityId: string;
1537
+ };
1538
+ clearFocus: undefined;
1539
+ setHover: {
1540
+ ids: string[];
1541
+ };
1542
+ clearHover: undefined;
1543
+ /** Replace one kind's highlight bucket (bulk update, e.g. heatmaps). */
1544
+ setHighlights: {
1545
+ kind: string;
1546
+ entries: FlowHighlightEntry[];
1547
+ };
1548
+ addHighlights: {
1549
+ kind: string;
1550
+ entries: FlowHighlightEntry[];
1551
+ };
1552
+ removeHighlights: {
1553
+ kind: string;
1554
+ ids: string[];
1555
+ };
1556
+ clearHighlights: {
1557
+ kind?: string;
1558
+ } | undefined;
1559
+ updateParentNodeId: {
1560
+ parentNodeId: string | null;
1561
+ };
1562
+ setViewport: Viewport;
1563
+ panBy: Point;
1564
+ zoomTo: {
1565
+ zoom: number;
1566
+ center: Point;
1567
+ };
1568
+ zoomBy: {
1569
+ factor: number;
1570
+ center?: Point;
1571
+ };
1572
+ setMinZoom: {
1573
+ minZoom: number;
1574
+ };
1575
+ setMaxZoom: {
1576
+ maxZoom: number;
1577
+ };
1578
+ setDragThreshold: {
1579
+ dragThreshold: number;
1580
+ };
1581
+ setAutoPanOptions: {
1582
+ autoPanOnDrag?: boolean;
1583
+ autoPanThreshold?: number;
1584
+ autoPanSpeed?: number;
1585
+ };
1586
+ setTranslateExtent: {
1587
+ extent: [Point, Point] | null;
1588
+ };
1589
+ setNodeExtent: {
1590
+ extent: [Point, Point] | null;
1591
+ };
1592
+ updateViewportSize: Size;
1593
+ fitView: FitViewOptions | undefined;
1594
+ pushViewport: undefined;
1595
+ popViewport: undefined;
1596
+ panStart: Point;
1597
+ pan: Point;
1598
+ panEnd: undefined;
1599
+ setCanvasState: {
1600
+ state: CanvasState;
1601
+ };
1602
+ connectionStart: {
1603
+ sourceId: string;
1604
+ sourcePort: string | null;
1605
+ position: Point;
1606
+ };
1607
+ connectionMove: {
1608
+ position: Point;
1609
+ targetId?: string | null;
1610
+ targetPort?: string | null;
1611
+ isValid?: boolean;
1612
+ };
1613
+ connectionEnd: {
1614
+ target?: ConnectEndTarget;
1615
+ } | undefined;
1616
+ cancelConnection: undefined;
1617
+ setConnectionClickStartHandle: {
1618
+ nodeId: string;
1619
+ port: string | null;
1620
+ } | null;
1621
+ resizeStart: {
1622
+ id: string;
1623
+ handle: ResizeHandle;
1624
+ } & TransactionMetadata;
1625
+ resizeMove: Point;
1626
+ resizeEnd: undefined;
1627
+ resizeCancel: undefined;
1628
+ reconnectEdge: {
1629
+ edgeId: string;
1630
+ newSourceId?: string;
1631
+ newTargetId?: string;
1632
+ newSourcePort?: string;
1633
+ newTargetPort?: string;
1634
+ } & TransactionMetadata;
1635
+ setMode: {
1636
+ mode: string;
1637
+ };
1638
+ setSnapToGrid: {
1639
+ enabled: boolean;
1640
+ grid?: [number, number];
1641
+ };
1642
+ setSnapLines: {
1643
+ enabled: boolean;
1644
+ threshold?: number;
1645
+ spacing?: boolean;
1646
+ };
1647
+ setColorMode: {
1648
+ colorMode: FlowColorMode;
1649
+ };
1650
+ moveNodes: {
1651
+ direction: Point;
1652
+ factor?: number;
1653
+ } & TransactionMetadata;
1654
+ requestLayout: {
1655
+ algorithm?: string;
1656
+ };
1657
+ applyLayoutResult: {
1658
+ positions: Map<string, {
1659
+ x: number;
1660
+ y: number;
1661
+ }>;
1662
+ edgeLabelPositions?: Map<string, {
1663
+ x: number;
1664
+ y: number;
1665
+ }>;
1666
+ } & TransactionMetadata;
1667
+ updateMeasurements: {
1668
+ measurements: Array<{
1669
+ id: string;
1670
+ rect: Rect;
1671
+ }>;
1672
+ };
1673
+ removeMeasurements: {
1674
+ ids: string[];
1675
+ };
1676
+ bakeLabelPositions: {
1677
+ positions: Map<string, Point>;
1678
+ } & TransactionMetadata;
1679
+ };
1680
+ type TransactionMetadata = {
1681
+ transactionId?: string;
1682
+ };
1683
+ declare function createFlowStore(initialGraph?: FlowGraph, options?: FlowStoreOptions): _xstate_store1.Store<FlowStoreContext, FlowEventPayloadMap & {
1684
+ undo: null;
1685
+ redo: null;
1686
+ }, _xstate_store1.ExtractEvents<FlowEmittedPayloadMap>>;
1687
+ type FlowStore = ReturnType<typeof createFlowStore>;
1688
+ //#endregion
1689
+ //#region src/createFlow.d.ts
1690
+ type LayoutAlgorithm<TNodeData = any, TEdgeData = any> = (graph: FlowGraph<TNodeData, TEdgeData>) => Promise<Map<string, {
1691
+ x: number;
1692
+ y: number;
1693
+ }>>;
1694
+ interface CreateFlowOptions<TNodeData = any, TEdgeData = any> {
1695
+ /** Initial graph owned by the controller. */
1696
+ graph?: FlowGraph<TNodeData, TEdgeData>;
1697
+ /** Layout algorithm used by `flow.runLayout()`. */
1698
+ layout?: LayoutAlgorithm<TNodeData, TEdgeData> | null;
1699
+ /** Store creation options. */
1700
+ store?: FlowStoreOptions;
1701
+ /** Engine creation options. */
1702
+ engine?: FlowEngineOptions;
1703
+ /** Optional listener for completed connection gestures. */
1704
+ onConnectionEnd?: (event: ConnectionEndedEvent) => void;
1705
+ }
1706
+ interface FlowController {
1707
+ store: FlowStore;
1708
+ engine: FlowEngine;
1709
+ trigger: FlowStore['trigger'];
1710
+ on: FlowStore['on'];
1711
+ destroy: () => void;
1712
+ getContext: () => FlowStoreContext;
1713
+ subscribe: (listener: (context: FlowStoreContext) => void) => () => void;
1714
+ getNode: (id: string) => FlowNode | undefined;
1715
+ getEdge: (id: string) => FlowEdge | undefined;
1716
+ getEntity: (id: string) => FlowNode | FlowEdge | undefined;
1717
+ getAddressable: (id: string) => FlowAddressable | null;
1718
+ getOwnerEntity: (id: string) => FlowNode | FlowEdge | null;
1719
+ getBounds: (id: string) => Rect | null;
1720
+ screenToCanvas: (point: Point) => Point;
1721
+ canvasToScreen: (point: Point) => Point;
1722
+ getAllEdgePaths: (options?: EdgePathOptions) => Map<string, EdgePathData>;
1723
+ getGraphBounds: () => Rect;
1724
+ getSelectionBounds: () => Rect | null;
1725
+ getRenderableEntities: (options?: RenderableEntitiesOptions) => {
1726
+ nodes: FlowNode[];
1727
+ edges: FlowEdge[];
1728
+ };
1729
+ runLayout: (layout?: LayoutAlgorithm) => Promise<void>;
1730
+ /** Undo the last undoable change (graph edits, drags, resizes, …). */
1731
+ undo: () => void;
1732
+ /** Redo the last undone change. */
1733
+ redo: () => void;
1734
+ /** Whether there is anything to undo. */
1735
+ canUndo: () => boolean;
1736
+ /** Whether there is anything to redo. */
1737
+ canRedo: () => boolean;
1738
+ }
1739
+ declare function createFlow<TNodeData = any, TEdgeData = any>(options?: CreateFlowOptions<TNodeData, TEdgeData>): FlowController;
1740
+ //#endregion
1741
+ //#region src/connectionPreview.d.ts
1742
+ declare const CONNECTION_PREVIEW_NODE_ID = "flow:connection-preview-node";
1743
+ declare const CONNECTION_PREVIEW_EDGE_ID = "flow:connection-preview-edge";
1744
+ type ConnectionPreviewData = {
1745
+ /** canConnect result for the hovered target (undefined over empty space). */
1746
+ isValid?: boolean;
1747
+ temp: {
1748
+ kind: 'connection-preview';
1749
+ };
1750
+ };
1751
+ type ConnectionPreviewGraphOptions = {
1752
+ nodeId?: string;
1753
+ edgeId?: string;
1754
+ nodeSize?: number;
1755
+ };
1756
+ declare function createConnectionPreviewGraph<TNodeData = any, TEdgeData = any>(graph: FlowGraph<TNodeData, TEdgeData>, connection: ConnectionState | null, options?: ConnectionPreviewGraphOptions): FlowGraph<TNodeData | ConnectionPreviewData, TEdgeData | ConnectionPreviewData>;
1757
+ //#endregion
1758
+ //#region src/spatial.d.ts
1759
+ /** Resolved visual position: layout position + drag offset */
1760
+ declare function resolvedPosition(node: FlowNode): Point;
1761
+ /** Resolved visual bounds: layout position + drag offset + dimensions.
1762
+ * Uses style.customWidth/customHeight when set (from resize), otherwise inherent width/height. */
1763
+ /** Size the geometry should use, in priority order:
1764
+ * 1. `style.customWidth/customHeight` (an explicit resize override),
1765
+ * 2. for `autoSize` nodes, the DOM-`measured` size (the renderer owns it),
1766
+ * 3. the authored `width/height`.
1767
+ * Authored `width/height` are never mutated — measured size lives on
1768
+ * `node.measured`, so this is the single place that reconciles the two. */
1769
+
1770
+ declare function resolvedBounds(node: FlowNode): Rect;
1771
+ /** Resolved bounds with visual snap — for rendering during drag.
1772
+ * Applies grid snap and/or entity snap offset. */
1773
+ declare function snappedBounds(node: FlowNode, grid: [number, number] | null, /** Optional snap offset from entity snap lines (snapRect.x - selectionRect.x) */
1774
+ snapOffset?: Point | null): Rect;
1775
+ /** Compute bounding rect of all nodes + edge labels (resolved positions) */
1776
+ declare function getGraphBounds(nodes: FlowNode[], edges?: FlowEdge[]): Rect;
1777
+ /** AABB intersection test */
1778
+ declare function rectsIntersect(a: Rect, b: Rect): boolean;
1779
+ /** Smallest axis-aligned rect containing both `a` and `b`. */
1780
+ declare function unionRect(a: Rect, b: Rect): Rect;
1781
+ /** Snap a value to the nearest grid increment */
1782
+ declare function snapToGrid(value: number, gridSize: number): number;
1783
+ /** Snap a point to grid */
1784
+ declare function snapPointToGrid(point: Point, gridSize: number): Point;
1785
+ /** Normalize a box (two points) into a Rect with positive width/height */
1786
+ declare function boxToRect(p1: Point, p2: Point): Rect;
1787
+ /** Get bounding rect of specific entities by id */
1788
+ declare function getSelectionBounds(nodes: FlowNode[], edges: FlowEdge[], selection: Set<string>): Rect | null;
1789
+ /** Determine select mode from a pointer/keyboard event */
1790
+ declare function selectMode(e: {
1791
+ shiftKey?: boolean;
1792
+ metaKey?: boolean;
1793
+ ctrlKey?: boolean;
1794
+ }): 'single' | 'multi';
1795
+ /** Does rect `a` fully contain rect `b`? */
1796
+ declare function rectContains(a: Rect, b: Rect): boolean;
1797
+ /**
1798
+ * Convert a wheel event into a logarithmic zoom exponent.
1799
+ * Accounts for deltaMode (pixels/lines/pages) and trackpad pinch (ctrlKey on macOS).
1800
+ * Use as: `newZoom = currentZoom * Math.pow(2, wheelZoomDelta(e))`
1801
+ */
1802
+ declare function wheelZoomDelta(e: {
1803
+ deltaY: number;
1804
+ deltaMode: number;
1805
+ ctrlKey: boolean;
1806
+ }): number;
1807
+ /**
1808
+ * Normalize wheel deltas for panning across browsers.
1809
+ * Firefox fires deltaMode=1 (lines) with small values; Chrome fires deltaMode=0 (pixels) with large values.
1810
+ */
1811
+ declare function normalizeWheelPan(e: {
1812
+ deltaX: number;
1813
+ deltaY: number;
1814
+ deltaMode: number;
1815
+ }): {
1816
+ x: number;
1817
+ y: number;
1818
+ };
1819
+ /**
1820
+ * Detect whether a wheel event is a trackpad pinch-to-zoom gesture.
1821
+ * Browsers send wheel events with ctrlKey=true for trackpad pinch.
1822
+ */
1823
+ declare function isTrackpadPinch(e: {
1824
+ ctrlKey: boolean;
1825
+ metaKey: boolean;
1826
+ }): boolean;
1827
+ type WheelInteraction = 'zoom' | 'pan' | 'block' | 'ignore';
1828
+ type WheelInteractionOptions = {
1829
+ /**
1830
+ * Whether ordinary wheel gestures pan the canvas.
1831
+ */
1832
+ panOnScroll?: boolean;
1833
+ /**
1834
+ * Whether browser pinch gestures zoom the canvas.
1835
+ *
1836
+ * Even when disabled, pinch wheels should still be blocked while the pointer is
1837
+ * over the canvas so the browser page does not zoom behind the app.
1838
+ */
1839
+ zoomOnPinch?: boolean;
1840
+ /**
1841
+ * Whether a floating layer such as a context menu, popover, or dialog is open.
1842
+ */
1843
+ floatingLayerOpen?: boolean;
1844
+ };
1845
+ /**
1846
+ * Decide how a wheel event should be handled by a flow canvas.
1847
+ *
1848
+ * This mirrors the important React Flow / d3-zoom behavior: browser pinch
1849
+ * gestures are always consumed over the canvas. Otherwise the whole page can
1850
+ * zoom even though the user is interacting with the diagram.
1851
+ */
1852
+ declare function wheelInteraction(e: {
1853
+ ctrlKey: boolean;
1854
+ metaKey: boolean;
1855
+ }, options?: WheelInteractionOptions): WheelInteraction;
1856
+ /**
1857
+ * Constrain viewport so content can't be panned entirely off-screen.
1858
+ * When zoomed out (content smaller than view), centers the content.
1859
+ * Matches d3-zoom's defaultConstrain behavior.
1860
+ */
1861
+ declare function constrainViewport(viewport: Viewport, viewportSize: {
1862
+ width: number;
1863
+ height: number;
1864
+ }, translateExtent: [Point, Point]): Viewport;
1865
+ /**
1866
+ * Compute auto-pan velocity when dragging near the viewport edge.
1867
+ * Returns screen-space delta to apply per frame. Returns {0,0} if cursor isn't near an edge.
1868
+ */
1869
+ declare function calcAutoPan(mousePosition: Point, containerBounds: {
1870
+ width: number;
1871
+ height: number;
1872
+ }, edgeWidth?: number, speed?: number): Point;
1873
+ type AnchorSpec = {
1874
+ x: number | string;
1875
+ y: number | string;
1876
+ offsetX?: number;
1877
+ offsetY?: number;
1878
+ };
1879
+ type AnchorTransform = {
1880
+ x: number;
1881
+ y: number;
1882
+ scale: number;
1883
+ };
1884
+ /**
1885
+ * Compute anchor transform for positioning overlays relative to a rect.
1886
+ * Returns canvas-space position + inverse zoom scale.
1887
+ *
1888
+ * Offsets are in screen pixels — divided by zoom so they stay constant.
1889
+ *
1890
+ * Usage (SVG): `transform="translate(${t.x}, ${t.y}) scale(${t.scale})"`
1891
+ * Usage (CSS): `transform: translate(${t.x}px, ${t.y}px) scale(${t.scale})`
1892
+ */
1893
+ declare function getAnchorTransform(bounds: Rect, viewport: Viewport, anchor: AnchorSpec): AnchorTransform;
1894
+ //#endregion
1895
+ //#region src/viewport/index.d.ts
1896
+ /** Create a default viewport (origin, no zoom) */
1897
+ declare function createViewport(x?: number, y?: number, zoom?: number): Viewport;
1898
+ /**
1899
+ * Convert viewport to SVG transform string.
1900
+ * Use on the root <g> wrapping all entities.
1901
+ *
1902
+ * @example
1903
+ * <g transform={toSVGTransform(viewport)}>...</g>
1904
+ */
1905
+ declare function toSVGTransform(viewport: Viewport): string;
1906
+ /**
1907
+ * Convert viewport + container size to an SVG viewBox string.
1908
+ *
1909
+ * @example
1910
+ * <svg viewBox={toViewBox(viewport, { width: 800, height: 600 })}>...</svg>
1911
+ */
1912
+ declare function toViewBox(viewport: Viewport, size: Size): string;
1913
+ /** Convert a screen-space point to canvas-space */
1914
+ declare function screenToCanvas(point: Point, viewport: Viewport): Point;
1915
+ /** Convert a canvas-space point to screen-space */
1916
+ declare function canvasToScreen(point: Point, viewport: Viewport): Point;
1917
+ /** Get the canvas-space bounding rect of what's visible on screen */
1918
+ declare function getVisibleBounds(viewport: Viewport, size: Size): Rect;
1919
+ /**
1920
+ * Compute a viewport that fits the given bounds into the given screen size.
1921
+ */
1922
+ declare function viewportForBounds(bounds: Rect, size: Size, options?: FitViewOptions): Viewport;
1923
+ /** Pan viewport by a delta */
1924
+ declare function panBy(viewport: Viewport, delta: Point): Viewport;
1925
+ /** Zoom to a specific level, keeping a screen-space point fixed */
1926
+ declare function zoomTo(viewport: Viewport, zoom: number, center: Point): Viewport;
1927
+ /** Clamp zoom to min/max bounds */
1928
+ declare function clampZoom(zoom: number, minZoom: number, maxZoom: number): number;
1929
+ /** Viewport that places the given canvas point at the center of the screen. */
1930
+ declare function viewportCenteredOn(center: Point, size: Size, zoom: number): Viewport;
1931
+ //#endregion
1932
+ //#region src/toolbar.d.ts
1933
+ type ToolbarPlacementInput = {
1934
+ /** Anchor rect in container-relative screen px (canvas rect × viewport). */
1935
+ anchor: Rect;
1936
+ /** Measured toolbar size (border box). */
1937
+ toolbarWidth: number;
1938
+ toolbarHeight: number;
1939
+ /** Container size in px. */
1940
+ viewportWidth: number;
1941
+ viewportHeight: number;
1942
+ /** Gap between anchor and toolbar (default 10). */
1943
+ offset?: number;
1944
+ /** Minimum gap from container edges (default 8). */
1945
+ padding?: number;
1946
+ };
1947
+ type ToolbarPlacement = {
1948
+ /** Top-left of the toolbar box, container-relative px. */
1949
+ left: number;
1950
+ top: number;
1951
+ side: 'top' | 'bottom';
1952
+ };
1953
+ declare function getToolbarPlacement(input: ToolbarPlacementInput): ToolbarPlacement;
1954
+ //#endregion
1955
+ //#region src/minimap.d.ts
1956
+ type MinimapProjectionOptions = {
1957
+ /** Canvas-space bounds the minimap must cover (e.g. `getGraphBounds()`). */
1958
+ contentBounds: Rect;
1959
+ /** Current viewport — the lens rect derives from it. */
1960
+ viewport: Viewport;
1961
+ /** Main container size in screen px. */
1962
+ viewportSize: Size;
1963
+ /** Minimap surface size in px. */
1964
+ width: number;
1965
+ height: number;
1966
+ /** Padding around content as a fraction of its size (default 0.1). */
1967
+ padding?: number;
1968
+ };
1969
+ type MinimapProjection = {
1970
+ /** Canvas px → minimap px. */
1971
+ scale: number;
1972
+ /** The padded canvas-space rect the minimap covers. */
1973
+ bounds: Rect;
1974
+ /** The main view's visible area, in minimap coordinates (the "lens"). */
1975
+ viewportRect: Rect;
1976
+ toMinimap(point: Point): Point;
1977
+ toCanvas(point: Point): Point;
1978
+ rectToMinimap(rect: Rect): Rect;
1979
+ };
1980
+ declare function getMinimapProjection(options: MinimapProjectionOptions): MinimapProjection;
1981
+ //#endregion
1982
+ //#region src/graph-index.d.ts
1983
+ declare function indexNodes(nodes: FlowNode[]): Map<string, FlowNode>;
1984
+ declare function indexEdges(edges: FlowEdge[]): Map<string, FlowEdge>;
1985
+ /** parentId → child nodes, cached on array identity. Self-parents ignored. */
1986
+ declare function indexChildren(nodes: FlowNode[]): Map<string, FlowNode[]>;
1987
+ /**
1988
+ * Hierarchy depth per node id (roots = 0), cached on array identity.
1989
+ * Cycle-safe; missing parents count as roots. Renderers can sort by this so
1990
+ * parents paint beneath children regardless of array order.
1991
+ */
1992
+ declare function nodeDepths(nodes: FlowNode[]): Map<string, number>;
1993
+ //#endregion
1994
+ //#region src/shapes/index.d.ts
1995
+ declare function registerShape(name: string, handler: ShapeHandler): void;
1996
+ declare function getShape(name: string): ShapeHandler | undefined;
1997
+ declare function getShapeOrDefault(name: string): ShapeHandler;
1998
+ //#endregion
1999
+ //#region src/entity-changes.d.ts
2000
+ type FlowEntityChangeNotifier = {
2001
+ /** Listen for changes that may affect the entity with this id. */
2002
+ subscribe(id: string, listener: () => void): () => void;
2003
+ /** Detach the underlying store subscription and drop all listeners. */
2004
+ destroy(): void;
2005
+ };
2006
+ declare function createEntityChangeNotifier(store: FlowStore): FlowEntityChangeNotifier;
2007
+ //#endregion
2008
+ //#region src/config.d.ts
2009
+ /** Default config: everything enabled */
2010
+ declare const defaultConfig: FlowConfig;
2011
+ /** Readonly preset: can select and view, cannot modify */
2012
+ declare const readonlyConfig: Partial<FlowConfig>;
2013
+ /**
2014
+ * Resolve a behavior predicate.
2015
+ * If `false`, returns false. If function, calls it. If undefined, returns default.
2016
+ */
2017
+ declare function resolveBehavior<TEntity, TState>(predicate: ((entity: TEntity, state: TState) => boolean) | false | undefined, entity: TEntity, state: TState, defaultValue?: boolean): boolean;
2018
+ //#endregion
2019
+ //#region src/factories.d.ts
2020
+ declare function createNode<TData = any>(opts: Partial<FlowNode<TData>> & {
2021
+ id: string;
2022
+ }): FlowNode<TData>;
2023
+ declare function createEdge<TEdgeData = any, TLabelData = any>(opts: Omit<Partial<FlowEdge<TEdgeData, TLabelData>>, 'label'> & Pick<FlowEdge<TEdgeData, TLabelData>, 'id' | 'sourceId' | 'targetId'> & {
2024
+ label?: Partial<FlowEdgeLabel<TLabelData>> & {
2025
+ width: number;
2026
+ height: number;
2027
+ };
2028
+ }): FlowEdge<TEdgeData, TLabelData>;
2029
+ declare function createGraph<TNodeData = any, TEdgeData = any>(opts: Partial<FlowGraph<TNodeData, TEdgeData>> & {
2030
+ nodes: FlowNode<TNodeData>[];
2031
+ edges: FlowEdge<TEdgeData>[];
2032
+ }): FlowGraph<TNodeData, TEdgeData>;
2033
+ declare function createPort<TData = any>(opts: Partial<FlowPort<TData>> & Pick<FlowPort<TData>, 'name' | 'side' | 'direction'>): FlowPort<TData>;
2034
+ //#endregion
2035
+ export { type AnchorSpec, type AnchorTransform, type AutoLayoutState, type BehaviorPredicate, CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, type CanvasState, type ConnectEndTarget, type ConnectModeOptions, type ConnectionEndedEvent, type ConnectionPreviewData, type ConnectionPreviewGraphOptions, type ConnectionState, type CreateFlowOptions, type Direction, type EdgeDirection, type EdgePathData, type EdgePathOptions, type EdgeRouter, type EdgeRouterContext, type EdgeStyleConfig, type EntityColorSet, type EntityRect, type EntityVisualState, type FitViewOptions, type FlowAddressable, type FlowColorMode, type FlowCommand, type FlowConfig, type FlowController, type FlowEdge, type FlowEdgeAttributes, type FlowEdgeLabel, type FlowEdgeStyle, type FlowEngine, type FlowEngineOptions, type FlowEntitiesDeletedEvent, type FlowEntityChangeNotifier, type FlowErrorEvent, type FlowEventObject, type FlowGraph, type FlowGraphChangedEvent, type FlowHighlightEntry, type FlowHighlights, type FlowInputEffects, type FlowInputEvent, type FlowInputMode, type FlowInputModeContext, type FlowInputModifiers, type FlowInputProfile, type FlowInputReaction, type FlowInputRuntime, type FlowInputRuntimeOptions, type FlowInputSessionHandlers, type FlowInputTarget, type FlowKeyInputEvent, type FlowModeDefinition, type FlowNode, type FlowNodeAttributes, type FlowOrigin, type FlowPointerInputEvent, type FlowPolicies, type FlowPort, type FlowProfile, type FlowResolvers, type FlowRules, type FlowSelectionChangedEvent, type FlowSessionResult, type FlowSettings, type FlowStore, type FlowStoreContext, type FlowStoreOptions, type FlowTheme, type FlowTransition, type FlowTransitions, type FlowTriggerCommand, type FlowTriggerName, type FlowViewportChangedEvent, type FlowWheelInputEvent, type Graph, type GraphEdge, type GraphNode, type GraphPort, type GroupContentSide, type GroupGeometry, type GroupInsets, type GroupLayout, type InteractionMode, type LabelAnchor, type LayoutAlgorithm, type LayoutRequestedEvent, type MarkerType, type MinimapProjection, type MinimapProjectionOptions, type PathData, type Point, type PortDirection, type ProposedConnection, type Rect, type RenderableEntitiesOptions, type ReparentDecision, type ReparentDropContext, type ReparentOptions, type ResizeHandle, type SelectionMode, type ShapeHandler, type Side, type Size, type SnapLine, type SnapOptions, type SnapResult, type SpacingGuide, type StyleOverrides, type ToolbarPlacement, type ToolbarPlacementInput, type Viewport, type ViewportAnimationOptions, type VisualEdge, type VisualGraph, type VisualNode, type VisualPort, type WheelInteraction, type WheelInteractionOptions, bestDirection, bezierRouter, boxToRect, calcAutoPan, canvasToScreen, clampZoom, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultModesForContext, defineFlowProfile, deriveGroupGeometry, entityPressMode, fixedGroupGeometry, getAnchorTransform, getAutoPanDelta, getEdgeOwner, getGraphBounds, getMinimapProjection, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdges, indexNodes, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, pathToSVG, preventDefault, profileModesForContext, readonlyConfig, readonlyInputModes, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolvedBounds, resolvedPosition, screenToCanvas, selectMode, snapPointToGrid, snapToGrid, snappedBounds, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, viewportCenteredOn, viewportForBounds, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };