@statelyai/flow 0.1.0 → 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.
@@ -1,6 +1,73 @@
1
- import * as _xstate_store0 from "@xstate/store";
2
- import { Graph, GraphEdge, GraphNode, GraphPort, PortDirection, Positioned as EntityRect, VisualEdge, VisualEdge as VisualEdge$1, VisualGraph, VisualGraphConfig, VisualNode, VisualNode as VisualNode$1, VisualPort, VisualPort as VisualPort$1 } from "@statelyai/graph";
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
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
4
71
  //#region src/types.d.ts
5
72
  type Point = {
6
73
  x: number;
@@ -33,6 +100,35 @@ type FlowNodeAttributes = {
33
100
  dy?: number;
34
101
  style?: StyleOverrides;
35
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;
36
132
  hidden?: boolean;
37
133
  selectable?: boolean;
38
134
  draggable?: boolean;
@@ -85,6 +181,27 @@ type FlowEdgeAttributes<TLabelData = unknown> = {
85
181
  reconnectable?: boolean;
86
182
  deletable?: boolean;
87
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
+ };
88
205
  /** A flow node: VisualNode + flow attributes */
89
206
  type FlowNode<TData = any> = VisualNode$1<TData> & FlowNodeAttributes;
90
207
  /** A flow edge: VisualEdge + flow attributes */
@@ -204,397 +321,113 @@ type FitViewOptions = ViewportAnimationOptions & {
204
321
  }>;
205
322
  };
206
323
  //#endregion
207
- //#region src/store/index.d.ts
208
- type FlowStoreContext = {
209
- graph: FlowGraph;
210
- parentNodeId: string | null;
211
- depth: number | null;
212
- viewport: Viewport;
213
- viewportSize: Size;
214
- viewportStack: Viewport[];
215
- minZoom: number;
216
- maxZoom: number;
217
- translateExtent: [Point, Point] | null;
218
- nodeExtent: [Point, Point] | null;
219
- selection: Set<string>;
220
- selectionBox: [Point, Point] | null;
221
- highlights: Set<string>;
222
- focusedEntityId: string | null;
223
- canvasState: CanvasState;
224
- draggedEntityId: string | null;
225
- dragThreshold: number;
226
- autoPanOnDrag: boolean;
227
- autoPanThreshold: number;
228
- autoPanSpeed: number;
229
- connection: ConnectionState | null;
230
- connectOnClick: boolean;
231
- connectionClickStartHandle: {
232
- nodeId: string;
233
- port: string | null;
234
- } | null;
235
- panOrigin: Point | null;
236
- panViewportOrigin: Viewport | null;
237
- resizingEntityId: string | null;
238
- resizeHandle: ResizeHandle | null;
239
- /** Two opposite corners during resize: [anchor, moving]. Derived bounds = min/max of these. */
240
- resizeCorners: [Point, Point] | null;
241
- interactionMode: InteractionMode;
242
- selectionMode: SelectionMode;
243
- snapToGrid: boolean;
244
- snapGrid: [number, number];
245
- enableSnapLines: boolean;
246
- snapThreshold: number;
247
- enableSpacingGuides: boolean;
248
- autoLayout: AutoLayoutState;
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[];
249
334
  };
250
- type FlowStoreOptions = {
251
- minZoom?: number;
252
- maxZoom?: number;
253
- translateExtent?: [Point, Point] | null;
254
- nodeExtent?: [Point, Point] | null;
255
- dragThreshold?: number;
256
- autoPanOnDrag?: boolean;
257
- autoPanThreshold?: number;
258
- autoPanSpeed?: number;
259
- snapToGrid?: boolean;
260
- snapGrid?: [number, number];
261
- enableSnapLines?: boolean;
262
- snapThreshold?: number;
263
- enableSpacingGuides?: boolean;
264
- connectOnClick?: boolean;
265
- connectionDragThreshold?: number;
266
- selectionMode?: SelectionMode;
267
- historyLimit?: number;
268
- beforeDelete?: (payload: {
269
- graph: FlowGraph;
270
- reason: 'deleteNode' | 'deleteEdge' | 'deleteSelected';
271
- nodes: FlowNode[];
272
- edges: FlowEdge[];
273
- }) => false | {
274
- nodes?: FlowNode[];
275
- edges?: FlowEdge[];
276
- } | void;
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;
277
413
  /**
278
- * Controls what happens to edges when a node is deleted.
279
- * - 'cascade' (default): delete all edges connected to the node
280
- * - 'retarget': edges connected to deleted node become self-loops on the other endpoint
281
- * - function: custom logic — receives graph + node ids to delete, returns { nodes, edges } to keep
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.
282
419
  */
283
- onDeleteNodes?: 'cascade' | 'retarget' | ((graph: FlowGraph, nodeIds: Set<string>) => {
284
- nodes: FlowNode[];
285
- edges: FlowEdge[];
286
- });
287
- };
288
- type LayoutRequestedEvent = {
289
- algorithm: string;
290
- graph: FlowGraph;
291
- };
292
- type ConnectEndTarget = {
293
- kind: 'node';
294
- nodeId: string;
295
- port: string | null;
296
- } | {
297
- kind: 'edge';
298
- edgeId: string;
299
- } | {
300
- kind: 'canvas';
301
- position: Point;
302
- } | {
303
- kind: 'none';
420
+ edgeOwner?: (edge: FlowEdge, context: FlowStoreContext) => string | null | undefined;
304
421
  };
305
- type ConnectionEndedEvent = {
306
- source: {
307
- nodeId: string;
308
- port: string | null;
309
- };
310
- target: ConnectEndTarget;
311
- connection: ConnectionState;
422
+ type RenderableEntitiesOptions = {
423
+ cull?: 'none' | 'viewport';
424
+ overscan?: number;
312
425
  };
313
- type TransactionMetadata = {
314
- transactionId?: string;
315
- };
316
- declare function createFlowStore(initialGraph?: FlowGraph, options?: FlowStoreOptions): _xstate_store0.Store<FlowStoreContext, {
317
- createNode: {
318
- node: FlowNode;
319
- } & TransactionMetadata;
320
- deleteNode: {
321
- id: string;
322
- } & TransactionMetadata;
323
- updateNodeData: {
324
- id: string;
325
- data: Record<string, unknown>;
326
- } & TransactionMetadata;
327
- createEdge: {
328
- edge: FlowEdge;
329
- } & TransactionMetadata;
330
- deleteEdge: {
331
- id: string;
332
- } & TransactionMetadata;
333
- updateEdgeData: {
334
- id: string;
335
- data: Record<string, unknown>;
336
- } & TransactionMetadata;
337
- deleteSelected: unknown;
338
- setGraph: {
339
- graph: FlowGraph;
340
- };
341
- reset: unknown;
342
- reparentNode: {
343
- id: string;
344
- parentId: string | null;
345
- } & TransactionMetadata;
346
- dragStart: {
347
- id: string;
348
- };
349
- dragMove: {
350
- dx: number;
351
- dy: number;
352
- };
353
- dragEnd: unknown;
354
- commitDrag: unknown;
355
- select: {
356
- ids: string[];
357
- mode?: "single" | "multi";
358
- };
359
- selectAll: unknown;
360
- clearSelection: unknown;
361
- selectionBoxStart: {
362
- point: Point;
363
- mode?: "single" | "multi";
364
- };
365
- selectionBoxMove: {
366
- point: Point;
367
- };
368
- selectionBoxEnd: unknown;
369
- focus: {
370
- entityId: string;
371
- };
372
- clearFocus: unknown;
373
- updateParentNodeId: {
374
- parentNodeId: string | null;
375
- };
376
- setViewport: Viewport;
377
- panBy: Point;
378
- zoomTo: {
379
- zoom: number;
380
- center: Point;
381
- };
382
- setMinZoom: {
383
- minZoom: number;
384
- };
385
- setMaxZoom: {
386
- maxZoom: number;
387
- };
388
- setDragThreshold: {
389
- dragThreshold: number;
390
- };
391
- setAutoPanOptions: {
392
- autoPanOnDrag?: boolean;
393
- autoPanThreshold?: number;
394
- autoPanSpeed?: number;
395
- };
396
- setTranslateExtent: {
397
- extent: [Point, Point] | null;
398
- };
399
- setNodeExtent: {
400
- extent: [Point, Point] | null;
401
- };
402
- updateViewportSize: Size;
403
- fitView: FitViewOptions | undefined;
404
- pushViewport: unknown;
405
- popViewport: unknown;
406
- panStart: Point;
407
- pan: Point;
408
- panEnd: unknown;
409
- setCanvasState: {
410
- state: CanvasState;
411
- };
412
- connectionStart: {
413
- sourceId: string;
414
- sourcePort: string | null;
415
- position: Point;
416
- };
417
- connectionMove: {
418
- position: Point;
419
- targetId?: string | null;
420
- targetPort?: string | null;
421
- isValid?: boolean;
422
- };
423
- connectionEnd: {
424
- target?: ConnectEndTarget;
425
- } | undefined;
426
- cancelConnection: unknown;
427
- setConnectionClickStartHandle: {
428
- nodeId: string;
429
- port: string | null;
430
- } | null;
431
- resizeStart: {
432
- id: string;
433
- handle: ResizeHandle;
434
- };
435
- resizeMove: Point;
436
- resizeEnd: unknown;
437
- resizeCancel: unknown;
438
- reconnectEdge: {
439
- edgeId: string;
440
- newSourceId?: string;
441
- newTargetId?: string;
442
- newSourcePort?: string;
443
- newTargetPort?: string;
444
- } & TransactionMetadata;
445
- reportPortMeasurements: {
446
- measurements: Array<{
447
- nodeId: string;
448
- portName: string;
449
- x: number;
450
- y: number;
451
- width: number;
452
- height: number;
453
- }>;
454
- };
455
- setInteractionMode: {
456
- mode: InteractionMode;
457
- };
458
- setSnapToGrid: {
459
- enabled: boolean;
460
- grid?: [number, number];
461
- };
462
- setSnapLines: {
463
- enabled: boolean;
464
- threshold?: number;
465
- spacing?: boolean;
466
- };
467
- moveNodes: {
468
- direction: Point;
469
- factor?: number;
470
- };
471
- requestLayout: {
472
- algorithm?: string;
473
- };
474
- applyLayoutResult: {
475
- positions: Map<string, {
476
- x: number;
477
- y: number;
478
- }>;
479
- edgeLabelPositions?: Map<string, {
480
- x: number;
481
- y: number;
482
- }>;
483
- } & TransactionMetadata;
484
- reportMeasurements: {
485
- measurements: Map<string, {
486
- width: number;
487
- height: number;
488
- }>;
489
- };
490
- bakeLabelPositions: {
491
- positions: Map<string, Point>;
492
- } & TransactionMetadata;
493
- } & {
494
- undo: null;
495
- redo: null;
496
- }, _xstate_store0.ExtractEvents<{
497
- layoutRequested: LayoutRequestedEvent;
498
- connectionEnded: ConnectionEndedEvent;
499
- }>>;
500
- type FlowStore = ReturnType<typeof createFlowStore>;
501
- //#endregion
502
- //#region src/routing/index.d.ts
503
- type EdgeRouterContext = {
504
- sourceBounds: Rect;
505
- targetBounds: Rect;
506
- sourceDirection: Direction;
507
- targetDirection: Direction;
508
- sourcePoint?: Point;
509
- targetPoint?: Point;
510
- /** All node bounds for obstacle avoidance */
511
- obstacles: Rect[];
512
- };
513
- type EdgeRouter = (edge: {
514
- sourceId: string;
515
- targetId: string;
516
- }, context: EdgeRouterContext) => PathData;
517
- declare const straightRouter: EdgeRouter;
518
- declare const stepRouter: EdgeRouter;
519
- declare const bezierRouter: EdgeRouter;
520
- /**
521
- * Determine the best side of `from` to connect toward `to`,
522
- * based on relative center positions.
523
- */
524
- declare function bestDirection(from: Rect, to: Rect): Direction;
525
- /**
526
- * Convert PathData points to an SVG path `d` attribute.
527
- * Handles 2 points (line), 3 points (quadratic), 4 points (cubic bezier).
528
- */
529
- declare function pathToSVG(path: PathData): string;
530
- //#endregion
531
- //#region src/snap.d.ts
532
- interface SnapLine {
533
- axis: 'x' | 'y';
534
- value: number;
535
- }
536
- interface SpacingGuide {
537
- axis: 'x' | 'y';
538
- /** Position on the perpendicular axis (y for 'x' axis, x for 'y') */
539
- position: number;
540
- /** The gap distance being matched */
541
- spacing: number;
542
- /** Segments showing where spacing applies */
543
- ranges: Array<{
544
- start: number;
545
- end: number;
546
- }>;
547
- }
548
- interface SnapResult {
549
- snapLines: SnapLine[];
550
- /** Adjusted rect position (size unchanged) */
551
- snapRect: Rect;
552
- spacingGuides?: SpacingGuide[];
553
- }
554
- interface SnapOptions {
555
- /** Distance threshold in canvas pixels (default 5) */
556
- threshold?: number;
557
- /** Enable equal-spacing guides (default false) */
558
- enableSpacing?: boolean;
559
- }
560
- /**
561
- * Compute snap lines for a dragged rect against other rects.
562
- *
563
- * Checks alignment of left/right/center-x and top/bottom/center-y
564
- * against all target rects. Optionally checks equal spacing between elements.
565
- *
566
- * Returns null if no snap is within threshold.
567
- */
568
- declare function getSnapLines(rect: Rect, otherRects: Rect[], {
569
- threshold,
570
- enableSpacing
571
- }?: SnapOptions): SnapResult | null;
572
- //#endregion
573
- //#region src/engine.d.ts
574
- type ProposedConnection = {
575
- sourceId: string;
576
- targetId: string;
577
- sourcePort?: string | null;
578
- targetPort?: string | null;
579
- };
580
- type FlowEngineOptions = {
581
- /** Default edge router (default: bezierRouter) */
582
- edgeRouter?: EdgeRouter;
583
- /** Default label anchor (default: 0.5 = midpoint) */
584
- labelAnchor?: LabelAnchor;
585
- /** Connection validation hook */
586
- canConnect?: (proposed: ProposedConnection) => boolean;
587
- /** Global behavior config */
588
- config?: Partial<FlowConfig>;
589
- /** Custom visibility function */
590
- isVisible?: (entity: FlowNode | FlowEdge, viewport: Viewport) => boolean;
591
- };
592
- type RenderableEntitiesOptions = {
593
- cull?: 'none' | 'viewport';
594
- overscan?: number;
426
+ type EdgePathOptions = {
427
+ graph?: FlowStoreContext['graph'];
595
428
  };
596
429
  declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions): {
597
- store: _xstate_store0.Store<FlowStoreContext, {
430
+ store: _xstate_store1.Store<FlowStoreContext, {
598
431
  createNode: {
599
432
  node: FlowNode;
600
433
  } & {
@@ -627,11 +460,11 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
627
460
  } & {
628
461
  transactionId?: string;
629
462
  };
630
- deleteSelected: unknown;
463
+ deleteSelected: undefined;
631
464
  setGraph: {
632
465
  graph: FlowGraph;
633
466
  };
634
- reset: unknown;
467
+ reset: undefined;
635
468
  reparentNode: {
636
469
  id: string;
637
470
  parentId: string | null;
@@ -640,19 +473,21 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
640
473
  };
641
474
  dragStart: {
642
475
  id: string;
476
+ } & {
477
+ transactionId?: string;
643
478
  };
644
479
  dragMove: {
645
480
  dx: number;
646
481
  dy: number;
647
482
  };
648
- dragEnd: unknown;
649
- commitDrag: unknown;
483
+ dragEnd: undefined;
484
+ commitDrag: undefined;
650
485
  select: {
651
486
  ids: string[];
652
487
  mode?: "single" | "multi";
653
488
  };
654
- selectAll: unknown;
655
- clearSelection: unknown;
489
+ selectAll: undefined;
490
+ clearSelection: undefined;
656
491
  selectionBoxStart: {
657
492
  point: Point;
658
493
  mode?: "single" | "multi";
@@ -660,11 +495,30 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
660
495
  selectionBoxMove: {
661
496
  point: Point;
662
497
  };
663
- selectionBoxEnd: unknown;
498
+ selectionBoxEnd: undefined;
664
499
  focus: {
665
500
  entityId: string;
666
501
  };
667
- clearFocus: unknown;
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;
668
522
  updateParentNodeId: {
669
523
  parentNodeId: string | null;
670
524
  };
@@ -674,6 +528,10 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
674
528
  zoom: number;
675
529
  center: Point;
676
530
  };
531
+ zoomBy: {
532
+ factor: number;
533
+ center?: Point;
534
+ };
677
535
  setMinZoom: {
678
536
  minZoom: number;
679
537
  };
@@ -696,11 +554,11 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
696
554
  };
697
555
  updateViewportSize: Size;
698
556
  fitView: FitViewOptions | undefined;
699
- pushViewport: unknown;
700
- popViewport: unknown;
557
+ pushViewport: undefined;
558
+ popViewport: undefined;
701
559
  panStart: Point;
702
560
  pan: Point;
703
- panEnd: unknown;
561
+ panEnd: undefined;
704
562
  setCanvasState: {
705
563
  state: CanvasState;
706
564
  };
@@ -718,7 +576,7 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
718
576
  connectionEnd: {
719
577
  target?: ConnectEndTarget;
720
578
  } | undefined;
721
- cancelConnection: unknown;
579
+ cancelConnection: undefined;
722
580
  setConnectionClickStartHandle: {
723
581
  nodeId: string;
724
582
  port: string | null;
@@ -726,10 +584,12 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
726
584
  resizeStart: {
727
585
  id: string;
728
586
  handle: ResizeHandle;
587
+ } & {
588
+ transactionId?: string;
729
589
  };
730
590
  resizeMove: Point;
731
- resizeEnd: unknown;
732
- resizeCancel: unknown;
591
+ resizeEnd: undefined;
592
+ resizeCancel: undefined;
733
593
  reconnectEdge: {
734
594
  edgeId: string;
735
595
  newSourceId?: string;
@@ -739,18 +599,8 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
739
599
  } & {
740
600
  transactionId?: string;
741
601
  };
742
- reportPortMeasurements: {
743
- measurements: Array<{
744
- nodeId: string;
745
- portName: string;
746
- x: number;
747
- y: number;
748
- width: number;
749
- height: number;
750
- }>;
751
- };
752
- setInteractionMode: {
753
- mode: InteractionMode;
602
+ setMode: {
603
+ mode: string;
754
604
  };
755
605
  setSnapToGrid: {
756
606
  enabled: boolean;
@@ -761,9 +611,14 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
761
611
  threshold?: number;
762
612
  spacing?: boolean;
763
613
  };
614
+ setColorMode: {
615
+ colorMode: FlowColorMode;
616
+ };
764
617
  moveNodes: {
765
618
  direction: Point;
766
619
  factor?: number;
620
+ } & {
621
+ transactionId?: string;
767
622
  };
768
623
  requestLayout: {
769
624
  algorithm?: string;
@@ -780,12 +635,15 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
780
635
  } & {
781
636
  transactionId?: string;
782
637
  };
783
- reportMeasurements: {
784
- measurements: Map<string, {
785
- width: number;
786
- height: number;
638
+ updateMeasurements: {
639
+ measurements: Array<{
640
+ id: string;
641
+ rect: Rect;
787
642
  }>;
788
643
  };
644
+ removeMeasurements: {
645
+ ids: string[];
646
+ };
789
647
  bakeLabelPositions: {
790
648
  positions: Map<string, Point>;
791
649
  } & {
@@ -794,147 +652,179 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
794
652
  } & {
795
653
  undo: null;
796
654
  redo: null;
797
- }, _xstate_store0.ExtractEvents<{
655
+ }, _xstate_store1.ExtractEvents<{
798
656
  layoutRequested: LayoutRequestedEvent;
799
657
  connectionEnded: ConnectionEndedEvent;
658
+ graphChanged: FlowGraphChangedEvent;
659
+ viewportChanged: FlowViewportChangedEvent;
660
+ selectionChanged: FlowSelectionChangedEvent;
661
+ entitiesDeleted: FlowEntitiesDeletedEvent;
662
+ error: FlowErrorEvent;
800
663
  }>>;
801
- trigger: {
802
- createNode: (eventPayload: Omit<{
664
+ trigger: _xstate_store1.TriggerObject<{
665
+ createNode: {
803
666
  node: FlowNode;
804
667
  } & {
805
668
  transactionId?: string;
806
- }, "type">) => void;
807
- deleteNode: (eventPayload: Omit<{
669
+ };
670
+ deleteNode: {
808
671
  id: string;
809
672
  } & {
810
673
  transactionId?: string;
811
- }, "type">) => void;
812
- updateNodeData: (eventPayload: Omit<{
674
+ };
675
+ updateNodeData: {
813
676
  id: string;
814
677
  data: Record<string, unknown>;
815
678
  } & {
816
679
  transactionId?: string;
817
- }, "type">) => void;
818
- createEdge: (eventPayload: Omit<{
680
+ };
681
+ createEdge: {
819
682
  edge: FlowEdge;
820
683
  } & {
821
684
  transactionId?: string;
822
- }, "type">) => void;
823
- deleteEdge: (eventPayload: Omit<{
685
+ };
686
+ deleteEdge: {
824
687
  id: string;
825
688
  } & {
826
689
  transactionId?: string;
827
- }, "type">) => void;
828
- updateEdgeData: (eventPayload: Omit<{
690
+ };
691
+ updateEdgeData: {
829
692
  id: string;
830
693
  data: Record<string, unknown>;
831
694
  } & {
832
695
  transactionId?: string;
833
- }, "type">) => void;
834
- deleteSelected: () => void;
835
- setGraph: (eventPayload: Omit<{
696
+ };
697
+ deleteSelected: undefined;
698
+ setGraph: {
836
699
  graph: FlowGraph;
837
- }, "type">) => void;
838
- reset: () => void;
839
- reparentNode: (eventPayload: Omit<{
700
+ };
701
+ reset: undefined;
702
+ reparentNode: {
840
703
  id: string;
841
704
  parentId: string | null;
842
705
  } & {
843
706
  transactionId?: string;
844
- }, "type">) => void;
845
- dragStart: (eventPayload: Omit<{
707
+ };
708
+ dragStart: {
846
709
  id: string;
847
- }, "type">) => void;
848
- dragMove: (eventPayload: Omit<{
710
+ } & {
711
+ transactionId?: string;
712
+ };
713
+ dragMove: {
849
714
  dx: number;
850
715
  dy: number;
851
- }, "type">) => void;
852
- dragEnd: () => void;
853
- commitDrag: () => void;
854
- select: (eventPayload: Omit<{
716
+ };
717
+ dragEnd: undefined;
718
+ commitDrag: undefined;
719
+ select: {
855
720
  ids: string[];
856
721
  mode?: "single" | "multi";
857
- }, "type">) => void;
858
- selectAll: () => void;
859
- clearSelection: () => void;
860
- selectionBoxStart: (eventPayload: Omit<{
722
+ };
723
+ selectAll: undefined;
724
+ clearSelection: undefined;
725
+ selectionBoxStart: {
861
726
  point: Point;
862
727
  mode?: "single" | "multi";
863
- }, "type">) => void;
864
- selectionBoxMove: (eventPayload: Omit<{
728
+ };
729
+ selectionBoxMove: {
865
730
  point: Point;
866
- }, "type">) => void;
867
- selectionBoxEnd: () => void;
868
- focus: (eventPayload: Omit<{
731
+ };
732
+ selectionBoxEnd: undefined;
733
+ focus: {
869
734
  entityId: string;
870
- }, "type">) => void;
871
- clearFocus: () => void;
872
- updateParentNodeId: (eventPayload: Omit<{
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: {
873
757
  parentNodeId: string | null;
874
- }, "type">) => void;
875
- setViewport: (eventPayload: Omit<Viewport, "type">) => void;
876
- panBy: (eventPayload: Omit<Point, "type">) => void;
877
- zoomTo: (eventPayload: Omit<{
758
+ };
759
+ setViewport: Viewport;
760
+ panBy: Point;
761
+ zoomTo: {
878
762
  zoom: number;
879
763
  center: Point;
880
- }, "type">) => void;
881
- setMinZoom: (eventPayload: Omit<{
764
+ };
765
+ zoomBy: {
766
+ factor: number;
767
+ center?: Point;
768
+ };
769
+ setMinZoom: {
882
770
  minZoom: number;
883
- }, "type">) => void;
884
- setMaxZoom: (eventPayload: Omit<{
771
+ };
772
+ setMaxZoom: {
885
773
  maxZoom: number;
886
- }, "type">) => void;
887
- setDragThreshold: (eventPayload: Omit<{
774
+ };
775
+ setDragThreshold: {
888
776
  dragThreshold: number;
889
- }, "type">) => void;
890
- setAutoPanOptions: (eventPayload: Omit<{
777
+ };
778
+ setAutoPanOptions: {
891
779
  autoPanOnDrag?: boolean;
892
780
  autoPanThreshold?: number;
893
781
  autoPanSpeed?: number;
894
- }, "type">) => void;
895
- setTranslateExtent: (eventPayload: Omit<{
782
+ };
783
+ setTranslateExtent: {
896
784
  extent: [Point, Point] | null;
897
- }, "type">) => void;
898
- setNodeExtent: (eventPayload: Omit<{
785
+ };
786
+ setNodeExtent: {
899
787
  extent: [Point, Point] | null;
900
- }, "type">) => void;
901
- updateViewportSize: (eventPayload: Omit<Size, "type">) => void;
902
- fitView: (eventPayload: Omit<undefined, "type"> | Omit<FitViewOptions, "type">) => void;
903
- pushViewport: () => void;
904
- popViewport: () => void;
905
- panStart: (eventPayload: Omit<Point, "type">) => void;
906
- pan: (eventPayload: Omit<Point, "type">) => void;
907
- panEnd: () => void;
908
- setCanvasState: (eventPayload: Omit<{
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: {
909
797
  state: CanvasState;
910
- }, "type">) => void;
911
- connectionStart: (eventPayload: Omit<{
798
+ };
799
+ connectionStart: {
912
800
  sourceId: string;
913
801
  sourcePort: string | null;
914
802
  position: Point;
915
- }, "type">) => void;
916
- connectionMove: (eventPayload: Omit<{
803
+ };
804
+ connectionMove: {
917
805
  position: Point;
918
806
  targetId?: string | null;
919
807
  targetPort?: string | null;
920
808
  isValid?: boolean;
921
- }, "type">) => void;
922
- connectionEnd: (eventPayload: Omit<undefined, "type"> | Omit<{
809
+ };
810
+ connectionEnd: {
923
811
  target?: ConnectEndTarget;
924
- }, "type">) => void;
925
- cancelConnection: () => void;
926
- setConnectionClickStartHandle: (eventPayload: Omit<null, "type"> | Omit<{
812
+ } | undefined;
813
+ cancelConnection: undefined;
814
+ setConnectionClickStartHandle: {
927
815
  nodeId: string;
928
816
  port: string | null;
929
- }, "type">) => void;
930
- resizeStart: (eventPayload: Omit<{
817
+ } | null;
818
+ resizeStart: {
931
819
  id: string;
932
820
  handle: ResizeHandle;
933
- }, "type">) => void;
934
- resizeMove: (eventPayload: Omit<Point, "type">) => void;
935
- resizeEnd: () => void;
936
- resizeCancel: () => void;
937
- reconnectEdge: (eventPayload: Omit<{
821
+ } & {
822
+ transactionId?: string;
823
+ };
824
+ resizeMove: Point;
825
+ resizeEnd: undefined;
826
+ resizeCancel: undefined;
827
+ reconnectEdge: {
938
828
  edgeId: string;
939
829
  newSourceId?: string;
940
830
  newTargetId?: string;
@@ -942,37 +832,32 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
942
832
  newTargetPort?: string;
943
833
  } & {
944
834
  transactionId?: string;
945
- }, "type">) => void;
946
- reportPortMeasurements: (eventPayload: Omit<{
947
- measurements: Array<{
948
- nodeId: string;
949
- portName: string;
950
- x: number;
951
- y: number;
952
- width: number;
953
- height: number;
954
- }>;
955
- }, "type">) => void;
956
- setInteractionMode: (eventPayload: Omit<{
957
- mode: InteractionMode;
958
- }, "type">) => void;
959
- setSnapToGrid: (eventPayload: Omit<{
835
+ };
836
+ setMode: {
837
+ mode: string;
838
+ };
839
+ setSnapToGrid: {
960
840
  enabled: boolean;
961
841
  grid?: [number, number];
962
- }, "type">) => void;
963
- setSnapLines: (eventPayload: Omit<{
842
+ };
843
+ setSnapLines: {
964
844
  enabled: boolean;
965
845
  threshold?: number;
966
846
  spacing?: boolean;
967
- }, "type">) => void;
968
- moveNodes: (eventPayload: Omit<{
847
+ };
848
+ setColorMode: {
849
+ colorMode: FlowColorMode;
850
+ };
851
+ moveNodes: {
969
852
  direction: Point;
970
853
  factor?: number;
971
- }, "type">) => void;
972
- requestLayout: (eventPayload: Omit<{
854
+ } & {
855
+ transactionId?: string;
856
+ };
857
+ requestLayout: {
973
858
  algorithm?: string;
974
- }, "type">) => void;
975
- applyLayoutResult: (eventPayload: Omit<{
859
+ };
860
+ applyLayoutResult: {
976
861
  positions: Map<string, {
977
862
  x: number;
978
863
  y: number;
@@ -983,33 +868,78 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
983
868
  }>;
984
869
  } & {
985
870
  transactionId?: string;
986
- }, "type">) => void;
987
- reportMeasurements: (eventPayload: Omit<{
988
- measurements: Map<string, {
989
- width: number;
990
- height: number;
871
+ };
872
+ updateMeasurements: {
873
+ measurements: Array<{
874
+ id: string;
875
+ rect: Rect;
991
876
  }>;
992
- }, "type">) => void;
993
- bakeLabelPositions: (eventPayload: Omit<{
877
+ };
878
+ removeMeasurements: {
879
+ ids: string[];
880
+ };
881
+ bakeLabelPositions: {
994
882
  positions: Map<string, Point>;
995
883
  } & {
996
884
  transactionId?: string;
997
- }, "type">) => void;
998
- undo: () => void;
999
- redo: () => void;
1000
- };
885
+ };
886
+ } & {
887
+ undo: null;
888
+ redo: null;
889
+ }>;
1001
890
  getContext: () => FlowStoreContext;
1002
891
  getNode: (id: string) => FlowNode | undefined;
1003
892
  getEdge: (id: string) => FlowEdge | undefined;
1004
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;
1005
897
  screenToCanvas: (screenPoint: Point) => Point;
1006
898
  canvasToScreen: (canvasPoint: Point) => Point;
1007
899
  entityAtPoint: (canvasPoint: Point) => FlowNode | FlowEdge | null;
1008
900
  entityIdAtPoint: (canvasPoint: Point) => string | null;
1009
901
  getEdgePath: (edgeId: string) => PathData | null;
1010
- getAllEdgePaths: () => Map<string, EdgePathData>;
902
+ getEdgePathBounds: (edgeId: string) => Rect | null;
903
+ getEdgeLabelBounds: (edgeId: string) => Rect | null;
904
+ getAllEdgePaths: (options?: EdgePathOptions) => Map<string, EdgePathData>;
1011
905
  resolvedPosition: (nodeOrId: FlowNode | string) => Point;
1012
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;
1013
943
  getGraphBounds: () => Rect;
1014
944
  getSelectionBounds: () => Rect | null;
1015
945
  entitiesInRect: (rect: Rect) => string[];
@@ -1032,21 +962,729 @@ declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions)
1032
962
  getVisibleEntities: () => {
1033
963
  nodes: FlowNode[];
1034
964
  edges: FlowEdge[];
1035
- };
1036
- getRenderableEntities: (options?: RenderableEntitiesOptions) => {
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>) => {
1037
1424
  nodes: FlowNode[];
1038
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;
1039
1449
  };
1040
- getIntersectingNodes: (nodeId: string) => FlowNode[];
1041
- getAriaLabel: (entityId: string) => string;
1042
- /** Compute snap result during drag. Returns null if not dragging or snap lines disabled.
1043
- * Only activates after actual movement (dx/dy != 0) to avoid showing on click. */
1044
- getSnapResult: () => SnapResult | null;
1045
- /** Get in-progress resize bounds, or null if not resizing */
1046
- getResizeBounds: () => Rect | null;
1047
- subscribe: (listener: (ctx: FlowStoreContext) => void) => () => void;
1450
+ target: ConnectEndTarget;
1451
+ connection: ConnectionState;
1048
1452
  };
1049
- type FlowEngine = ReturnType<typeof createFlowEngine>;
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>;
1050
1688
  //#endregion
1051
1689
  //#region src/createFlow.d.ts
1052
1690
  type LayoutAlgorithm<TNodeData = any, TEdgeData = any> = (graph: FlowGraph<TNodeData, TEdgeData>) => Promise<Map<string, {
@@ -1069,15 +1707,19 @@ interface FlowController {
1069
1707
  store: FlowStore;
1070
1708
  engine: FlowEngine;
1071
1709
  trigger: FlowStore['trigger'];
1710
+ on: FlowStore['on'];
1072
1711
  destroy: () => void;
1073
1712
  getContext: () => FlowStoreContext;
1074
1713
  subscribe: (listener: (context: FlowStoreContext) => void) => () => void;
1075
1714
  getNode: (id: string) => FlowNode | undefined;
1076
1715
  getEdge: (id: string) => FlowEdge | undefined;
1077
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;
1078
1720
  screenToCanvas: (point: Point) => Point;
1079
1721
  canvasToScreen: (point: Point) => Point;
1080
- getAllEdgePaths: () => Map<string, EdgePathData>;
1722
+ getAllEdgePaths: (options?: EdgePathOptions) => Map<string, EdgePathData>;
1081
1723
  getGraphBounds: () => Rect;
1082
1724
  getSelectionBounds: () => Rect | null;
1083
1725
  getRenderableEntities: (options?: RenderableEntitiesOptions) => {
@@ -1085,14 +1727,46 @@ interface FlowController {
1085
1727
  edges: FlowEdge[];
1086
1728
  };
1087
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;
1088
1738
  }
1089
1739
  declare function createFlow<TNodeData = any, TEdgeData = any>(options?: CreateFlowOptions<TNodeData, TEdgeData>): FlowController;
1090
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
1091
1758
  //#region src/spatial.d.ts
1092
1759
  /** Resolved visual position: layout position + drag offset */
1093
1760
  declare function resolvedPosition(node: FlowNode): Point;
1094
1761
  /** Resolved visual bounds: layout position + drag offset + dimensions.
1095
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
+
1096
1770
  declare function resolvedBounds(node: FlowNode): Rect;
1097
1771
  /** Resolved bounds with visual snap — for rendering during drag.
1098
1772
  * Applies grid snap and/or entity snap offset. */
@@ -1102,6 +1776,8 @@ snapOffset?: Point | null): Rect;
1102
1776
  declare function getGraphBounds(nodes: FlowNode[], edges?: FlowEdge[]): Rect;
1103
1777
  /** AABB intersection test */
1104
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;
1105
1781
  /** Snap a value to the nearest grid increment */
1106
1782
  declare function snapToGrid(value: number, gridSize: number): number;
1107
1783
  /** Snap a point to grid */
@@ -1250,12 +1926,85 @@ declare function panBy(viewport: Viewport, delta: Point): Viewport;
1250
1926
  declare function zoomTo(viewport: Viewport, zoom: number, center: Point): Viewport;
1251
1927
  /** Clamp zoom to min/max bounds */
1252
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>;
1253
1993
  //#endregion
1254
1994
  //#region src/shapes/index.d.ts
1255
1995
  declare function registerShape(name: string, handler: ShapeHandler): void;
1256
1996
  declare function getShape(name: string): ShapeHandler | undefined;
1257
1997
  declare function getShapeOrDefault(name: string): ShapeHandler;
1258
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
1259
2008
  //#region src/config.d.ts
1260
2009
  /** Default config: everything enabled */
1261
2010
  declare const defaultConfig: FlowConfig;
@@ -1281,5 +2030,6 @@ declare function createGraph<TNodeData = any, TEdgeData = any>(opts: Partial<Flo
1281
2030
  nodes: FlowNode<TNodeData>[];
1282
2031
  edges: FlowEdge<TEdgeData>[];
1283
2032
  }): FlowGraph<TNodeData, TEdgeData>;
2033
+ declare function createPort<TData = any>(opts: Partial<FlowPort<TData>> & Pick<FlowPort<TData>, 'name' | 'side' | 'direction'>): FlowPort<TData>;
1284
2034
  //#endregion
1285
- export { type AnchorSpec, type AnchorTransform, type AutoLayoutState, type BehaviorPredicate, type CanvasState, type ConnectEndTarget, type ConnectionEndedEvent, type ConnectionState, type CreateFlowOptions, type Direction, type EdgeDirection, type EdgePathData, type EdgeRouter, type EdgeRouterContext, type EdgeStyleConfig, type EntityColorSet, type EntityRect, type EntityVisualState, type FitViewOptions, type FlowConfig, type FlowController, type FlowEdge, type FlowEdgeAttributes, type FlowEdgeLabel, type FlowEdgeStyle, type FlowEngine, type FlowEngineOptions, type FlowGraph, type FlowNode, type FlowNodeAttributes, type FlowPort, type FlowStore, type FlowStoreContext, type FlowStoreOptions, type FlowTheme, type Graph, type GraphEdge, type GraphNode, type GraphPort, type InteractionMode, type LabelAnchor, type LayoutAlgorithm, type MarkerType, type PathData, type Point, type PortDirection, type ProposedConnection, type Rect, type RenderableEntitiesOptions, type ResizeHandle, type SelectionMode, type ShapeHandler, type Side, type Size, type SnapLine, type SnapOptions, type SnapResult, type SpacingGuide, type StyleOverrides, type Viewport, type ViewportAnimationOptions, type VisualEdge, type VisualGraph, type VisualNode, type VisualPort, type WheelInteraction, type WheelInteractionOptions, bestDirection, bezierRouter, boxToRect, calcAutoPan, canvasToScreen, clampZoom, constrainViewport, createEdge, createFlow, createFlowEngine, createFlowStore, createGraph, createNode, createViewport, defaultConfig, getAnchorTransform, getGraphBounds, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getVisibleBounds, isTrackpadPinch, normalizeWheelPan, panBy, pathToSVG, readonlyConfig, rectContains, rectsIntersect, registerShape, resolveBehavior, resolvedBounds, resolvedPosition, screenToCanvas, selectMode, snapPointToGrid, snapToGrid, snappedBounds, stepRouter, straightRouter, toSVGTransform, toViewBox, viewportForBounds, wheelInteraction, wheelZoomDelta, zoomTo };
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 };