@statelyai/flow 0.8.2 → 0.9.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.
package/dist/esm/index.js CHANGED
@@ -561,6 +561,15 @@ function visualBounds(node) {
561
561
  }
562
562
  /** @deprecated Use `visualBounds`. */
563
563
  const resolvedBounds = visualBounds;
564
+ /** Bounds used by marquee selection, including transient node movement. */
565
+ function resolvedSelectionBounds(node) {
566
+ if (!node.selectionBounds) return visualBounds(node);
567
+ return {
568
+ ...node.selectionBounds,
569
+ x: node.selectionBounds.x + (node.dx ?? 0),
570
+ y: node.selectionBounds.y + (node.dy ?? 0)
571
+ };
572
+ }
564
573
  /**
565
574
  * Size used for edge-label geometry. `autoSize` labels retain authored
566
575
  * dimensions as a fallback while a transient DOM measurement owns the live
@@ -1244,41 +1253,71 @@ function getSnapLines(rect, otherRects, { threshold = 5, enableSpacing = false }
1244
1253
  //#endregion
1245
1254
  //#region src/graph-index.ts
1246
1255
  const nodeIndexCache = /* @__PURE__ */ new WeakMap();
1256
+ const nodePositionCache = /* @__PURE__ */ new WeakMap();
1257
+ const childrenIndexCache = /* @__PURE__ */ new WeakMap();
1247
1258
  const edgeIndexCache = /* @__PURE__ */ new WeakMap();
1259
+ const edgePositionCache = /* @__PURE__ */ new WeakMap();
1248
1260
  const edgeAdjacencyCache = /* @__PURE__ */ new WeakMap();
1249
1261
  function indexNodes(nodes) {
1250
1262
  let index = nodeIndexCache.get(nodes);
1251
1263
  if (!index) {
1252
1264
  index = /* @__PURE__ */ new Map();
1253
- for (const node of nodes) if (!index.has(node.id)) index.set(node.id, node);
1265
+ const positions = /* @__PURE__ */ new Map();
1266
+ const children = /* @__PURE__ */ new Map();
1267
+ for (let position = 0; position < nodes.length; position++) {
1268
+ const node = nodes[position];
1269
+ if (!index.has(node.id)) index.set(node.id, node);
1270
+ if (!positions.has(node.id)) positions.set(node.id, position);
1271
+ const parentId = node.parentId ?? null;
1272
+ if (parentId == null || parentId === node.id) continue;
1273
+ const bucket = children.get(parentId);
1274
+ if (bucket) bucket.push(node);
1275
+ else children.set(parentId, [node]);
1276
+ }
1254
1277
  nodeIndexCache.set(nodes, index);
1278
+ nodePositionCache.set(nodes, positions);
1279
+ childrenIndexCache.set(nodes, children);
1255
1280
  }
1256
1281
  return index;
1257
1282
  }
1283
+ function indexNodePositions(nodes) {
1284
+ if (!nodePositionCache.has(nodes)) indexNodes(nodes);
1285
+ return nodePositionCache.get(nodes);
1286
+ }
1258
1287
  function indexEdges(edges) {
1259
1288
  let index = edgeIndexCache.get(edges);
1260
1289
  if (!index) {
1261
1290
  index = /* @__PURE__ */ new Map();
1262
- for (const edge of edges) if (!index.has(edge.id)) index.set(edge.id, edge);
1291
+ const positions = /* @__PURE__ */ new Map();
1292
+ const adjacency = {
1293
+ bySource: /* @__PURE__ */ new Map(),
1294
+ byTarget: /* @__PURE__ */ new Map(),
1295
+ byNode: /* @__PURE__ */ new Map()
1296
+ };
1297
+ for (let position = 0; position < edges.length; position++) {
1298
+ const edge = edges[position];
1299
+ if (!index.has(edge.id)) index.set(edge.id, edge);
1300
+ if (!positions.has(edge.id)) positions.set(edge.id, position);
1301
+ pushEdge(adjacency.bySource, edge.sourceId, edge);
1302
+ pushEdge(adjacency.byTarget, edge.targetId, edge);
1303
+ pushEdge(adjacency.byNode, edge.sourceId, edge);
1304
+ if (edge.targetId !== edge.sourceId) pushEdge(adjacency.byNode, edge.targetId, edge);
1305
+ }
1263
1306
  edgeIndexCache.set(edges, index);
1307
+ edgePositionCache.set(edges, positions);
1308
+ edgeAdjacencyCache.set(edges, adjacency);
1264
1309
  }
1265
1310
  return index;
1266
1311
  }
1312
+ function indexEdgePositions(edges) {
1313
+ if (!edgePositionCache.has(edges)) indexEdges(edges);
1314
+ return edgePositionCache.get(edges);
1315
+ }
1267
1316
  function indexEdgeAdjacency(edges) {
1268
1317
  let index = edgeAdjacencyCache.get(edges);
1269
1318
  if (!index) {
1270
- index = {
1271
- bySource: /* @__PURE__ */ new Map(),
1272
- byTarget: /* @__PURE__ */ new Map(),
1273
- byNode: /* @__PURE__ */ new Map()
1274
- };
1275
- for (const edge of edges) {
1276
- pushEdge(index.bySource, edge.sourceId, edge);
1277
- pushEdge(index.byTarget, edge.targetId, edge);
1278
- pushEdge(index.byNode, edge.sourceId, edge);
1279
- if (edge.targetId !== edge.sourceId) pushEdge(index.byNode, edge.targetId, edge);
1280
- }
1281
- edgeAdjacencyCache.set(edges, index);
1319
+ indexEdges(edges);
1320
+ index = edgeAdjacencyCache.get(edges);
1282
1321
  }
1283
1322
  return index;
1284
1323
  }
@@ -1310,20 +1349,12 @@ function getNeighbors(graph, nodeId) {
1310
1349
  for (const node of getOutgoers(graph, nodeId)) neighborIds.add(node.id);
1311
1350
  return graph.nodes.filter((node) => neighborIds.has(node.id));
1312
1351
  }
1313
- const childrenIndexCache = /* @__PURE__ */ new WeakMap();
1314
1352
  /** parentId → child nodes, cached on array identity. Self-parents ignored. */
1315
1353
  function indexChildren(nodes) {
1316
1354
  let index = childrenIndexCache.get(nodes);
1317
1355
  if (!index) {
1318
- index = /* @__PURE__ */ new Map();
1319
- for (const node of nodes) {
1320
- const parentId = node.parentId ?? null;
1321
- if (parentId == null || parentId === node.id) continue;
1322
- const children = index.get(parentId);
1323
- if (children) children.push(node);
1324
- else index.set(parentId, [node]);
1325
- }
1326
- childrenIndexCache.set(nodes, index);
1356
+ indexNodes(nodes);
1357
+ index = childrenIndexCache.get(nodes);
1327
1358
  }
1328
1359
  return index;
1329
1360
  }
@@ -2632,37 +2663,53 @@ function invalidatePathsForNodeGeometry(draft, changedNodeIds, topologyNodes = d
2632
2663
  function isUndoableEventType(type) {
2633
2664
  return UNDOABLE_EVENT_TYPES.includes(type);
2634
2665
  }
2635
- function planNodeMovement(ctx, dx, dy, options = {}) {
2666
+ function createMovementTopology(nodes, edges) {
2667
+ const nodeArray = nodes;
2668
+ const edgeArray = edges;
2669
+ const nodeIndices = indexNodePositions(nodeArray);
2670
+ const edgeIndices = indexEdgePositions(edgeArray);
2671
+ const children = indexChildren(nodeArray);
2672
+ return {
2673
+ nodeIndices,
2674
+ edgeIndices,
2675
+ childrenByParent: children.size ? new Map([...children].map(([parentId, childNodes]) => [parentId, childNodes.map((node) => node.id)])) : null,
2676
+ nodeCount: nodes.length,
2677
+ edgeCount: edges.length
2678
+ };
2679
+ }
2680
+ function planNodeMovement(ctx, dx, dy, options = {}, topology) {
2636
2681
  const nodes = ctx.graph.nodes;
2637
2682
  const edges = ctx.graph.edges;
2638
- const nodeIndex = indexNodes(nodes);
2639
- const edgeIndex = indexEdges(edges);
2683
+ const usableTopology = topology?.nodeCount === nodes.length && topology.edgeCount === edges.length ? topology : createMovementTopology(nodes, edges);
2684
+ const nodeAt = (id) => {
2685
+ const index = usableTopology.nodeIndices.get(id);
2686
+ const node = index === void 0 ? void 0 : nodes[index];
2687
+ return node?.id === id ? node : void 0;
2688
+ };
2689
+ const edgeAt = (id) => {
2690
+ const index = usableTopology.edgeIndices.get(id);
2691
+ const edge = index === void 0 ? void 0 : edges[index];
2692
+ return edge?.id === id ? edge : void 0;
2693
+ };
2640
2694
  const movingNodeIds = /* @__PURE__ */ new Set();
2641
2695
  const labelEdgeIds = /* @__PURE__ */ new Set();
2642
2696
  for (const id of ctx.selection) {
2643
- const node = nodeIndex.get(id);
2697
+ const node = nodeAt(id);
2644
2698
  if (node) {
2645
2699
  if (node.draggable !== false) movingNodeIds.add(id);
2646
2700
  continue;
2647
2701
  }
2648
2702
  if (options.includeLabels) {
2649
- const edge = edgeIndex.get(id);
2703
+ const edge = edgeAt(id);
2650
2704
  if (edge && edge.draggable !== false && edge.label) labelEdgeIds.add(id);
2651
2705
  }
2652
2706
  }
2653
2707
  if (movingNodeIds.size === 0 && labelEdgeIds.size === 0) return null;
2654
- let childrenByParent = null;
2655
- for (const node of nodes) {
2656
- const parentId = node.parentId ?? null;
2657
- if (parentId == null || parentId === node.id) continue;
2658
- if (!childrenByParent) childrenByParent = /* @__PURE__ */ new Map();
2659
- const children = childrenByParent.get(parentId);
2660
- if (children) children.push(node.id);
2661
- else childrenByParent.set(parentId, [node.id]);
2662
- }
2708
+ const childrenByParent = usableTopology.childrenByParent;
2709
+ const hierarchyNodeIndex = childrenByParent ? indexNodes(nodes) : null;
2663
2710
  const deltasById = /* @__PURE__ */ new Map();
2664
2711
  for (const id of movingNodeIds) {
2665
- const node = nodeIndex.get(id);
2712
+ const node = nodeAt(id);
2666
2713
  const oldDx = node.dx ?? 0;
2667
2714
  const oldDy = node.dy ?? 0;
2668
2715
  let newDx = oldDx + dx;
@@ -2674,7 +2721,7 @@ function planNodeMovement(ctx, dx, dy, options = {}) {
2674
2721
  newDx = clampedX - node.x;
2675
2722
  newDy = clampedY - node.y;
2676
2723
  }
2677
- const parent = node.parentId ? nodeIndex.get(node.parentId) : void 0;
2724
+ const parent = node.parentId ? hierarchyNodeIndex?.get(node.parentId) : void 0;
2678
2725
  if (parent?.group?.type === "fixed") {
2679
2726
  const axes = parent.group.clampChildren ?? "none";
2680
2727
  if (axes !== "none") {
@@ -2711,9 +2758,9 @@ function planNodeMovement(ctx, dx, dy, options = {}) {
2711
2758
  if (childrenByParent) collectDescendantDeltas(childrenByParent, id, applied, movingNodeIds, deltasById);
2712
2759
  }
2713
2760
  const nodeDeltasByIndex = /* @__PURE__ */ new Map();
2714
- if (deltasById.size > 0) for (let i = 0; i < nodes.length; i++) {
2715
- const delta = deltasById.get(nodes[i].id);
2716
- if (delta) nodeDeltasByIndex.set(i, delta);
2761
+ if (deltasById.size > 0) for (const [id, delta] of deltasById) {
2762
+ const index = usableTopology.nodeIndices.get(id);
2763
+ if (index !== void 0 && nodes[index]?.id === id) nodeDeltasByIndex.set(index, delta);
2717
2764
  }
2718
2765
  const edgeDeltasByIndex = /* @__PURE__ */ new Map();
2719
2766
  const labelDeltasByIndex = /* @__PURE__ */ new Map();
@@ -2723,16 +2770,16 @@ function planNodeMovement(ctx, dx, dy, options = {}) {
2723
2770
  const carriesFixedLabel = !!edge.label && (edge.labelAnchor ?? ctx.labelAnchor) === "fixed";
2724
2771
  if (!carriesWaypoints && !carriesFixedLabel) continue;
2725
2772
  if (!deltasById.has(edge.sourceId) || !deltasById.has(edge.targetId)) continue;
2726
- const ownerId = getEdgeOwnerFromIndex(edge, nodeIndex);
2773
+ const ownerId = getEdgeOwnerFromIndex(edge, hierarchyNodeIndex);
2727
2774
  const ownerDelta = ownerId ? deltasById.get(ownerId) : void 0;
2728
2775
  if (!ownerDelta) continue;
2729
2776
  edgeDeltasByIndex.set(i, ownerDelta);
2730
2777
  if (carriesFixedLabel) labelDeltasByIndex.set(i, ownerDelta);
2731
2778
  }
2732
- if (labelEdgeIds.size > 0) for (let i = 0; i < edges.length; i++) {
2733
- const edge = edges[i];
2734
- if (!labelEdgeIds.has(edge.id) || labelDeltasByIndex.has(i)) continue;
2735
- labelDeltasByIndex.set(i, {
2779
+ if (labelEdgeIds.size > 0) for (const id of labelEdgeIds) {
2780
+ const index = usableTopology.edgeIndices.get(id);
2781
+ if (index === void 0 || edges[index]?.id !== id || labelDeltasByIndex.has(index)) continue;
2782
+ labelDeltasByIndex.set(index, {
2736
2783
  x: dx,
2737
2784
  y: dy
2738
2785
  });
@@ -2933,6 +2980,7 @@ function restoreHistoryContext(currentContext, historicalContext) {
2933
2980
  },
2934
2981
  canvasState: "idle",
2935
2982
  draggedEntityId: null,
2983
+ dragRevision: 0,
2936
2984
  selectionBox: null,
2937
2985
  selectionBoxBase: null,
2938
2986
  connection: null,
@@ -2952,22 +3000,51 @@ function plainViewport(viewport) {
2952
3000
  zoom: viewport.zoom
2953
3001
  };
2954
3002
  }
2955
- function entityPositions(graph, ids) {
3003
+ function entityPositions(graph, ids, movement, topology) {
2956
3004
  const positions = {};
3005
+ const usableTopology = topology?.nodeCount === graph.nodes.length && topology.edgeCount === graph.edges.length ? topology : null;
3006
+ const nodes = usableTopology ? null : indexNodes(graph.nodes);
3007
+ const edges = usableTopology ? null : indexEdges(graph.edges);
3008
+ const nodeAt = (id) => {
3009
+ const index = usableTopology?.nodeIndices.get(id);
3010
+ const node = index === void 0 ? nodes?.get(id) : graph.nodes[index];
3011
+ return node?.id === id ? node : void 0;
3012
+ };
3013
+ const edgeAt = (id) => {
3014
+ const index = usableTopology?.edgeIndices.get(id);
3015
+ const edge = index === void 0 ? edges?.get(id) : graph.edges[index];
3016
+ return edge?.id === id ? edge : void 0;
3017
+ };
3018
+ const nodeDeltas = /* @__PURE__ */ new Map();
3019
+ const labelDeltas = /* @__PURE__ */ new Map();
3020
+ if (movement) {
3021
+ for (const [index, delta] of movement.nodeDeltasByIndex) {
3022
+ const node = graph.nodes[index];
3023
+ if (node) nodeDeltas.set(node.id, delta);
3024
+ }
3025
+ for (const [index, delta] of movement.labelDeltasByIndex) {
3026
+ const edge = graph.edges[index];
3027
+ if (edge) labelDeltas.set(edge.id, delta);
3028
+ }
3029
+ }
2957
3030
  for (const id of ids) {
2958
- const node = graph.nodes.find((candidate) => candidate.id === id);
3031
+ const node = nodeAt(id);
2959
3032
  if (node) {
3033
+ const delta = nodeDeltas.get(id);
2960
3034
  positions[id] = {
2961
- x: node.x + (node.dx ?? 0),
2962
- y: node.y + (node.dy ?? 0)
3035
+ x: node.x + (node.dx ?? 0) + (delta?.x ?? 0),
3036
+ y: node.y + (node.dy ?? 0) + (delta?.y ?? 0)
2963
3037
  };
2964
3038
  continue;
2965
3039
  }
2966
- const edge = graph.edges.find((candidate) => candidate.id === id);
2967
- if (edge?.label) positions[id] = {
2968
- x: edge.label.x + (edge.label.dx ?? 0),
2969
- y: edge.label.y + (edge.label.dy ?? 0)
2970
- };
3040
+ const edge = edgeAt(id);
3041
+ if (edge?.label) {
3042
+ const delta = labelDeltas.get(id);
3043
+ positions[id] = {
3044
+ x: edge.label.x + (edge.label.dx ?? 0) + (delta?.x ?? 0),
3045
+ y: edge.label.y + (edge.label.dy ?? 0) + (delta?.y ?? 0)
3046
+ };
3047
+ }
2971
3048
  }
2972
3049
  return positions;
2973
3050
  }
@@ -3053,7 +3130,7 @@ function entitiesInBox(ctx, rect) {
3053
3130
  const nodes = ctx.graph.nodes;
3054
3131
  for (const node of nodes) {
3055
3132
  if (!isExplicitlyVisibleNode(node)) continue;
3056
- if (test(rect, resolvedBounds(node))) ids.add(node.id);
3133
+ if (test(rect, nodeSelectionBounds(ctx, node))) ids.add(node.id);
3057
3134
  }
3058
3135
  for (const edge of ctx.graph.edges) {
3059
3136
  if (!isExplicitlyVisibleEdge(edge, nodes)) continue;
@@ -3062,12 +3139,50 @@ function entitiesInBox(ctx, rect) {
3062
3139
  }
3063
3140
  return ids;
3064
3141
  }
3065
- function isExplicitlyDraggable(id, graph) {
3066
- const node = graph.nodes.find((candidate) => candidate.id === id);
3067
- if (node) return node.draggable !== false;
3068
- const edge = graph.edges.find((candidate) => candidate.id === id);
3069
- if (edge) return edge.draggable !== false;
3070
- return false;
3142
+ function nodeSelectionBounds(ctx, node, visiting = /* @__PURE__ */ new Set()) {
3143
+ if (node.selectionBounds) return resolvedSelectionBounds(node);
3144
+ if (!node.group || visiting.has(node.id)) return resolvedBounds(node);
3145
+ return groupGeometryForSelection(ctx, node, visiting).contentBounds;
3146
+ }
3147
+ function groupGeometryForSelection(ctx, node, visiting) {
3148
+ if (node.group.type === "fixed") return fixedGroupGeometry(resolvedBounds(node), node.group.contentSize ?? {
3149
+ width: 0,
3150
+ height: 0
3151
+ }, node.group);
3152
+ const nextVisiting = new Set(visiting).add(node.id);
3153
+ let childrenBounds = null;
3154
+ const addBounds = (bounds) => {
3155
+ if (!childrenBounds) {
3156
+ childrenBounds = bounds;
3157
+ return;
3158
+ }
3159
+ const x = Math.min(childrenBounds.x, bounds.x);
3160
+ const y = Math.min(childrenBounds.y, bounds.y);
3161
+ const right = Math.max(childrenBounds.x + childrenBounds.width, bounds.x + bounds.width);
3162
+ const bottom = Math.max(childrenBounds.y + childrenBounds.height, bounds.y + bounds.height);
3163
+ childrenBounds = {
3164
+ x,
3165
+ y,
3166
+ width: right - x,
3167
+ height: bottom - y
3168
+ };
3169
+ };
3170
+ for (const child of ctx.graph.nodes) {
3171
+ if (child.parentId !== node.id || !isExplicitlyVisibleNode(child)) continue;
3172
+ addBounds(child.group && !nextVisiting.has(child.id) ? groupGeometryForSelection(ctx, child, nextVisiting).bounds : resolvedBounds(child));
3173
+ }
3174
+ const nodeIndex = indexNodes(ctx.graph.nodes);
3175
+ for (const edge of ctx.graph.edges) {
3176
+ if (edge.hidden || !edge.label) continue;
3177
+ if (edge.sourceId === node.id && edge.targetId === node.id) continue;
3178
+ if (getEdgeOwnerFromIndex(edge, nodeIndex) !== node.id) continue;
3179
+ const labelBounds = resolvedEdgeLabelBounds(edge, ctx.measurements.get(edge.id));
3180
+ if (labelBounds) addBounds(labelBounds);
3181
+ }
3182
+ return deriveGroupGeometry(resolvedSize(node), childrenBounds, node.group, {
3183
+ x: node.x + (node.dx ?? 0),
3184
+ y: node.y + (node.dy ?? 0)
3185
+ });
3071
3186
  }
3072
3187
  function getMode(profile, mode) {
3073
3188
  return profile.modes[mode] ? mode : profile.defaultMode;
@@ -3117,6 +3232,7 @@ function createFlowStore(initialGraph = {
3117
3232
  measurements: /* @__PURE__ */ new Map(),
3118
3233
  canvasState: "idle",
3119
3234
  draggedEntityId: null,
3235
+ dragRevision: 0,
3120
3236
  dragThreshold: options.dragThreshold ?? 3,
3121
3237
  constrainNodeMovement: options.constrainNodeMovement ?? null,
3122
3238
  autoPanOnDrag: options.autoPanOnDrag ?? true,
@@ -3150,6 +3266,7 @@ function createFlowStore(initialGraph = {
3150
3266
  },
3151
3267
  colorMode: options.colorMode ?? "system"
3152
3268
  };
3269
+ let activeDragMovementTopology = null;
3153
3270
  return createStore({
3154
3271
  context: initialContext,
3155
3272
  on: {
@@ -3588,29 +3705,44 @@ function createFlowStore(initialGraph = {
3588
3705
  event: createEventObject("expandNode", event)
3589
3706
  });
3590
3707
  }),
3591
- dragStart: (ctx, event, enqueue) => produce(ctx, (draft) => {
3592
- if (!isExplicitlyDraggable(event.id, draft.graph)) return;
3593
- draft.canvasState = "dragging";
3594
- draft.draggedEntityId = event.id;
3595
- draft.selection.add(event.id);
3596
- const ids = [...draft.selection];
3597
- enqueue.emit.dragStarted({
3598
- ids,
3599
- positions: entityPositions(draft.graph, ids)
3708
+ dragStart: (ctx, event, enqueue) => {
3709
+ const topology = createMovementTopology(ctx.graph.nodes, ctx.graph.edges);
3710
+ const nodeIndex = topology.nodeIndices.get(event.id);
3711
+ const edgeIndex = topology.edgeIndices.get(event.id);
3712
+ const entity = nodeIndex === void 0 ? edgeIndex === void 0 ? void 0 : ctx.graph.edges[edgeIndex] : ctx.graph.nodes[nodeIndex];
3713
+ if (!entity || entity.draggable === false) {
3714
+ activeDragMovementTopology = null;
3715
+ return ctx;
3716
+ }
3717
+ activeDragMovementTopology = topology;
3718
+ const selectedIds = new Set(ctx.selection);
3719
+ selectedIds.add(event.id);
3720
+ const ids = [...selectedIds];
3721
+ const positions = entityPositions(ctx.graph, ids, void 0, topology);
3722
+ return produce(ctx, (draft) => {
3723
+ draft.canvasState = "dragging";
3724
+ draft.draggedEntityId = event.id;
3725
+ draft.selection.add(event.id);
3726
+ enqueue.emit.dragStarted({
3727
+ ids,
3728
+ positions
3729
+ });
3600
3730
  });
3601
- }),
3731
+ },
3602
3732
  dragMove: (ctx, event, enqueue) => {
3603
3733
  if (ctx.canvasState !== "dragging") return ctx;
3604
3734
  const { dx, dy } = event;
3605
3735
  if (dx === 0 && dy === 0) return ctx;
3606
- const plan = planNodeMovement(ctx, dx, dy, { includeLabels: true });
3736
+ const plan = planNodeMovement(ctx, dx, dy, { includeLabels: true }, activeDragMovementTopology ?? void 0);
3607
3737
  if (!plan) return ctx;
3738
+ const ids = [...ctx.selection];
3739
+ const positions = entityPositions(ctx.graph, ids, plan, activeDragMovementTopology ?? void 0);
3608
3740
  return produce(ctx, (draft) => {
3609
3741
  applyMovementPlan(draft, plan);
3610
- const ids = [...draft.selection];
3742
+ draft.dragRevision++;
3611
3743
  enqueue.emit.dragMoved({
3612
3744
  ids,
3613
- positions: entityPositions(draft.graph, ids),
3745
+ positions,
3614
3746
  delta: {
3615
3747
  x: dx,
3616
3748
  y: dy
@@ -3620,6 +3752,7 @@ function createFlowStore(initialGraph = {
3620
3752
  },
3621
3753
  dragEnd: (ctx, _event, enqueue) => {
3622
3754
  if (ctx.canvasState !== "dragging") return ctx;
3755
+ activeDragMovementTopology = null;
3623
3756
  return produce(ctx, (draft) => {
3624
3757
  const ids = [...draft.selection];
3625
3758
  enqueue.emit.dragEnded({
@@ -3630,22 +3763,25 @@ function createFlowStore(initialGraph = {
3630
3763
  draft.draggedEntityId = null;
3631
3764
  });
3632
3765
  },
3633
- dragCancel: (ctx) => produce(ctx, (draft) => {
3634
- for (const node of draft.graph.nodes) {
3635
- delete node.dx;
3636
- delete node.dy;
3637
- }
3638
- for (const edge of draft.graph.edges) {
3639
- delete edge.dx;
3640
- delete edge.dy;
3641
- if (edge.label) {
3642
- delete edge.label.dx;
3643
- delete edge.label.dy;
3766
+ dragCancel: (ctx) => {
3767
+ activeDragMovementTopology = null;
3768
+ return produce(ctx, (draft) => {
3769
+ for (const node of draft.graph.nodes) {
3770
+ delete node.dx;
3771
+ delete node.dy;
3644
3772
  }
3645
- }
3646
- draft.canvasState = "idle";
3647
- draft.draggedEntityId = null;
3648
- }),
3773
+ for (const edge of draft.graph.edges) {
3774
+ delete edge.dx;
3775
+ delete edge.dy;
3776
+ if (edge.label) {
3777
+ delete edge.label.dx;
3778
+ delete edge.label.dy;
3779
+ }
3780
+ }
3781
+ draft.canvasState = "idle";
3782
+ draft.draggedEntityId = null;
3783
+ });
3784
+ },
3649
3785
  commitDrag: (ctx, _event, enqueue) => produce(ctx, (draft) => {
3650
3786
  let snapOffX = _event?.snapOffset?.x ?? 0;
3651
3787
  let snapOffY = _event?.snapOffset?.y ?? 0;
@@ -4464,69 +4600,101 @@ function createFlowStore(initialGraph = {
4464
4600
  event: createEventObject("applyLayoutResult", event)
4465
4601
  });
4466
4602
  }),
4467
- updateMeasurements: (ctx, event) => produce(ctx, (draft) => {
4468
- for (const measurement of event.measurements) {
4469
- const node = draft.graph.nodes.find((n) => n.id === measurement.id);
4470
- if (node) {
4471
- if (node.autoSize) {
4472
- const previousSize = resolvedSize(node);
4473
- const previousOffset = node.measured?.anchorOffset ?? {
4474
- x: 0,
4475
- y: 0
4476
- };
4477
- const anchor = resolveAutoSizeAnchor(node.autoSizeAnchor);
4478
- const nextSize = {
4479
- width: node.style?.customWidth ?? measurement.rect.width,
4480
- height: node.style?.customHeight ?? measurement.rect.height
4481
- };
4482
- const delta = {
4483
- x: (previousSize.width - nextSize.width) * anchor.x,
4484
- y: (previousSize.height - nextSize.height) * anchor.y
4485
- };
4486
- const anchorOffset = {
4487
- x: previousOffset.x + delta.x,
4488
- y: previousOffset.y + delta.y
4489
- };
4490
- const normalizedRect = {
4491
- x: anchor.x === 0 ? measurement.rect.x : node.x + delta.x + (node.dx ?? 0),
4492
- y: anchor.y === 0 ? measurement.rect.y : node.y + delta.y + (node.dy ?? 0),
4493
- width: measurement.rect.width,
4494
- height: measurement.rect.height
4495
- };
4496
- const existing = draft.measurements.get(measurement.id);
4497
- if (delta.x === 0 && delta.y === 0 && node.measured?.width === measurement.rect.width && node.measured?.height === measurement.rect.height && previousOffset.x === anchorOffset.x && previousOffset.y === anchorOffset.y && existing?.x === normalizedRect.x && existing.y === normalizedRect.y && existing.width === normalizedRect.width && existing.height === normalizedRect.height) continue;
4498
- node.measured = {
4499
- width: measurement.rect.width,
4500
- height: measurement.rect.height,
4501
- ...anchorOffset.x !== 0 || anchorOffset.y !== 0 ? { anchorOffset } : {}
4502
- };
4503
- node.x += delta.x;
4504
- node.y += delta.y;
4505
- draft.measurements.set(measurement.id, normalizedRect);
4506
- } else draft.measurements.set(measurement.id, measurement.rect);
4507
- continue;
4603
+ updateMeasurements: (ctx, event) => {
4604
+ const nodeIndices = /* @__PURE__ */ new Map();
4605
+ for (let index = 0; index < ctx.graph.nodes.length; index++) {
4606
+ const id = ctx.graph.nodes[index].id;
4607
+ if (!nodeIndices.has(id)) nodeIndices.set(id, index);
4608
+ }
4609
+ const needsSecondaryIndices = event.measurements.some((measurement) => !nodeIndices.has(measurement.id));
4610
+ const edgeIndices = /* @__PURE__ */ new Map();
4611
+ const portIndices = /* @__PURE__ */ new Map();
4612
+ if (needsSecondaryIndices) {
4613
+ for (let index = 0; index < ctx.graph.edges.length; index++) {
4614
+ const id = ctx.graph.edges[index].id;
4615
+ if (!edgeIndices.has(id)) edgeIndices.set(id, index);
4508
4616
  }
4509
- draft.measurements.set(measurement.id, measurement.rect);
4510
- const edge = draft.graph.edges.find((e) => e.id === measurement.id);
4511
- if (edge?.label) {
4512
- if (!edge.label.autoSize) {
4513
- edge.label.width = measurement.rect.width;
4514
- edge.label.height = measurement.rect.height;
4617
+ for (let nodeIndex = 0; nodeIndex < ctx.graph.nodes.length; nodeIndex++) {
4618
+ const node = ctx.graph.nodes[nodeIndex];
4619
+ for (let portIndex = 0; portIndex < (node.ports?.length ?? 0); portIndex++) {
4620
+ const port = node.ports[portIndex];
4621
+ const target = {
4622
+ nodeIndex,
4623
+ portIndex
4624
+ };
4625
+ const address = `${node.id}:${port.name}`;
4626
+ if (!portIndices.has(address)) portIndices.set(address, target);
4627
+ const explicitId = port.id;
4628
+ if (explicitId && !portIndices.has(explicitId)) portIndices.set(explicitId, target);
4515
4629
  }
4516
- continue;
4517
4630
  }
4518
- for (const candidate of draft.graph.nodes) {
4519
- const port = candidate.ports?.find((p) => p.id === measurement.id || `${candidate.id}:${p.name}` === measurement.id);
4520
- if (port) {
4631
+ }
4632
+ return produce(ctx, (draft) => {
4633
+ for (const measurement of event.measurements) {
4634
+ const nodeIndex = nodeIndices.get(measurement.id);
4635
+ if (nodeIndex !== void 0) {
4636
+ const node = draft.graph.nodes[nodeIndex];
4637
+ if (node.autoSize) {
4638
+ const previousSize = resolvedSize(node);
4639
+ const previousOffset = node.measured?.anchorOffset ?? {
4640
+ x: 0,
4641
+ y: 0
4642
+ };
4643
+ const anchor = resolveAutoSizeAnchor(node.autoSizeAnchor);
4644
+ const nextSize = {
4645
+ width: node.style?.customWidth ?? measurement.rect.width,
4646
+ height: node.style?.customHeight ?? measurement.rect.height
4647
+ };
4648
+ const delta = {
4649
+ x: (previousSize.width - nextSize.width) * anchor.x,
4650
+ y: (previousSize.height - nextSize.height) * anchor.y
4651
+ };
4652
+ const anchorOffset = {
4653
+ x: previousOffset.x + delta.x,
4654
+ y: previousOffset.y + delta.y
4655
+ };
4656
+ const normalizedRect = {
4657
+ x: anchor.x === 0 ? measurement.rect.x : node.x + delta.x + (node.dx ?? 0),
4658
+ y: anchor.y === 0 ? measurement.rect.y : node.y + delta.y + (node.dy ?? 0),
4659
+ width: measurement.rect.width,
4660
+ height: measurement.rect.height
4661
+ };
4662
+ const existing = draft.measurements.get(measurement.id);
4663
+ if (delta.x === 0 && delta.y === 0 && node.measured?.width === measurement.rect.width && node.measured?.height === measurement.rect.height && previousOffset.x === anchorOffset.x && previousOffset.y === anchorOffset.y && existing?.x === normalizedRect.x && existing.y === normalizedRect.y && existing.width === normalizedRect.width && existing.height === normalizedRect.height) continue;
4664
+ node.measured = {
4665
+ width: measurement.rect.width,
4666
+ height: measurement.rect.height,
4667
+ ...anchorOffset.x !== 0 || anchorOffset.y !== 0 ? { anchorOffset } : {}
4668
+ };
4669
+ node.x += delta.x;
4670
+ node.y += delta.y;
4671
+ draft.measurements.set(measurement.id, normalizedRect);
4672
+ } else draft.measurements.set(measurement.id, measurement.rect);
4673
+ continue;
4674
+ }
4675
+ draft.measurements.set(measurement.id, measurement.rect);
4676
+ const edgeIndex = edgeIndices.get(measurement.id);
4677
+ const edge = edgeIndex === void 0 ? void 0 : draft.graph.edges[edgeIndex];
4678
+ if (edge?.label) {
4679
+ if (!edge.label.autoSize) {
4680
+ edge.label.width = measurement.rect.width;
4681
+ edge.label.height = measurement.rect.height;
4682
+ }
4683
+ continue;
4684
+ }
4685
+ const portTarget = portIndices.get(measurement.id);
4686
+ if (portTarget) {
4687
+ const candidate = draft.graph.nodes[portTarget.nodeIndex];
4688
+ const port = candidate.ports?.[portTarget.portIndex];
4689
+ if (!port) continue;
4521
4690
  port.x = measurement.rect.x - (candidate.x + (candidate.dx ?? 0));
4522
4691
  port.y = measurement.rect.y - (candidate.y + (candidate.dy ?? 0));
4523
4692
  port.width = measurement.rect.width;
4524
4693
  port.height = measurement.rect.height;
4525
- break;
4526
4694
  }
4527
4695
  }
4528
- }
4529
- }),
4696
+ });
4697
+ },
4530
4698
  removeMeasurements: (ctx, event) => produce(ctx, (draft) => {
4531
4699
  for (const id of event.ids) draft.measurements.delete(id);
4532
4700
  }),
@@ -4829,6 +4997,8 @@ function offsetEdgeWaypoints(edge, offset = {
4829
4997
  y: point.y + dy
4830
4998
  }));
4831
4999
  }
5000
+ const SPATIAL_CELL_SIZE = 512;
5001
+ const MAX_ENTITY_SPATIAL_CELLS = 4096;
4832
5002
  /**
4833
5003
  * Create the framework-agnostic derived-geometry and query layer for a store.
4834
5004
  *
@@ -4848,6 +5018,9 @@ function createFlowEngine(store, initialOptions = {}) {
4848
5018
  const snapOffsetCache = /* @__PURE__ */ new WeakMap();
4849
5019
  let renderableCache = /* @__PURE__ */ new WeakMap();
4850
5020
  let entityOrderCache = null;
5021
+ let baseEntityOrderCache = null;
5022
+ let entityRankCache = null;
5023
+ let renderableSpatialIndex = null;
4851
5024
  let graphBoundsCache = null;
4852
5025
  let groupGeometryCache = /* @__PURE__ */ new WeakMap();
4853
5026
  let visualGroupGeometryCache = /* @__PURE__ */ new WeakMap();
@@ -4911,6 +5084,9 @@ function createFlowEngine(store, initialOptions = {}) {
4911
5084
  stableEdgePathsCache = /* @__PURE__ */ new WeakMap();
4912
5085
  renderableCache = /* @__PURE__ */ new WeakMap();
4913
5086
  entityOrderCache = null;
5087
+ baseEntityOrderCache = null;
5088
+ entityRankCache = null;
5089
+ renderableSpatialIndex = null;
4914
5090
  graphBoundsCache = null;
4915
5091
  groupGeometryCache = /* @__PURE__ */ new WeakMap();
4916
5092
  visualGroupGeometryCache = /* @__PURE__ */ new WeakMap();
@@ -4940,9 +5116,18 @@ function createFlowEngine(store, initialOptions = {}) {
4940
5116
  }
4941
5117
  function edgeObstacles(edge, c) {
4942
5118
  const owner = edgeOwnerOf(edge, c);
5119
+ const nodeIndex = indexNodes(c.graph.nodes);
5120
+ const endpointLineage = /* @__PURE__ */ new Set();
5121
+ for (const endpointId of [edge.sourceId, edge.targetId]) {
5122
+ let node = nodeIndex.get(endpointId);
5123
+ while (node) {
5124
+ endpointLineage.add(node.id);
5125
+ node = node.parentId ? nodeIndex.get(node.parentId) : void 0;
5126
+ }
5127
+ }
4943
5128
  const result = [];
4944
5129
  for (const { id, bounds } of ownerObstacles(owner, c)) {
4945
- if (id === edge.sourceId || id === edge.targetId) continue;
5130
+ if (endpointLineage.has(id)) continue;
4946
5131
  result.push(bounds);
4947
5132
  }
4948
5133
  return result;
@@ -5314,6 +5499,39 @@ function createFlowEngine(store, initialOptions = {}) {
5314
5499
  const dy = point.y < rect.y ? rect.y - point.y : point.y > rect.y + rect.height ? point.y - (rect.y + rect.height) : 0;
5315
5500
  return Math.hypot(dx, dy);
5316
5501
  }
5502
+ function groupConnectionDistance(point, node, c) {
5503
+ const bounds = hierarchyBounds(node, c);
5504
+ const boundaryWidth = node.group?.connectionBoundaryWidth;
5505
+ if (boundaryWidth === void 0) return distanceToRect(point, bounds);
5506
+ const geometry = groupGeometryFor(c, node);
5507
+ if (!geometry) return distanceToRect(point, bounds);
5508
+ if (distanceToRect(point, geometry.contentBounds) === 0) return 0;
5509
+ const side = node.group?.content ?? "top";
5510
+ const childSurface = side === "top" ? {
5511
+ x: bounds.x,
5512
+ y: geometry.contentBounds.y + geometry.contentBounds.height,
5513
+ width: bounds.width,
5514
+ height: bounds.y + bounds.height - geometry.contentBounds.y - geometry.contentBounds.height
5515
+ } : side === "bottom" ? {
5516
+ x: bounds.x,
5517
+ y: bounds.y,
5518
+ width: bounds.width,
5519
+ height: geometry.contentBounds.y - bounds.y
5520
+ } : side === "left" ? {
5521
+ x: geometry.contentBounds.x + geometry.contentBounds.width,
5522
+ y: bounds.y,
5523
+ width: bounds.x + bounds.width - geometry.contentBounds.x - geometry.contentBounds.width,
5524
+ height: bounds.height
5525
+ } : {
5526
+ x: bounds.x,
5527
+ y: bounds.y,
5528
+ width: geometry.contentBounds.x - bounds.x,
5529
+ height: bounds.height
5530
+ };
5531
+ if (distanceToRect(point, childSurface) > 0) return distanceToRect(point, bounds);
5532
+ const inset = Math.max(0, boundaryWidth);
5533
+ return Math.min(point.x - childSurface.x, childSurface.x + childSurface.width - point.x, point.y - childSurface.y, childSurface.y + childSurface.height - point.y) <= inset ? 0 : Number.POSITIVE_INFINITY;
5534
+ }
5317
5535
  function getConnectionCandidate(pointer, options = {}) {
5318
5536
  const c = ctx();
5319
5537
  const { radius, mode } = connectionOptions(options);
@@ -5342,7 +5560,7 @@ function createFlowEngine(store, initialOptions = {}) {
5342
5560
  }
5343
5561
  if (mode !== "loose") continue;
5344
5562
  const bounds = hierarchyBounds(node, c);
5345
- const distance = distanceToRect(pointer, bounds);
5563
+ const distance = node.group ? groupConnectionDistance(pointer, node, c) : distanceToRect(pointer, bounds);
5346
5564
  if (distance > radius) continue;
5347
5565
  const isValid = isConnectionCandidateValid(options.source, node.id, null);
5348
5566
  if (!isValid) continue;
@@ -5423,9 +5641,7 @@ function createFlowEngine(store, initialOptions = {}) {
5423
5641
  if (!edge?.label) return null;
5424
5642
  const measured = c.measurements.get(edgeId);
5425
5643
  if (measured && !edge.label.autoSize) return measured;
5426
- const nodeMap = /* @__PURE__ */ new Map();
5427
- for (const n of c.graph.nodes) nodeMap.set(n.id, n);
5428
- return resolveEdgeLabelBounds(edge, nodeMap, measured);
5644
+ return resolveEdgeLabelBounds(edge, indexNodes(c.graph.nodes), measured);
5429
5645
  }
5430
5646
  function getBounds(id) {
5431
5647
  const c = ctx();
@@ -5527,9 +5743,8 @@ function createFlowEngine(store, initialOptions = {}) {
5527
5743
  height: maxY - minY
5528
5744
  };
5529
5745
  }
5530
- /** Collect snap target rects from non-selected nodes + resolved edge label bounds.
5531
- * Filters to entities at least partially in viewport and not overlapped by selection. */
5532
- function getSnapTargetRects(c, selection, selBounds) {
5746
+ /** Collect visible snap targets outside the moving selection subtree. */
5747
+ function getSnapTargetRects(c, selection) {
5533
5748
  const vp = c.viewport;
5534
5749
  const vs = c.viewportSize;
5535
5750
  const viewRect = {
@@ -5543,6 +5758,17 @@ function createFlowEngine(store, initialOptions = {}) {
5543
5758
  const selectedDerivedAncestorIds = /* @__PURE__ */ new Set();
5544
5759
  const visitedAncestorIds = /* @__PURE__ */ new Set();
5545
5760
  const nodeIndex = nodesById(c);
5761
+ const selectedSubtreeIds = new Set(selection);
5762
+ const childrenByParent = indexChildren(c.graph.nodes);
5763
+ const pendingDescendantIds = [...selection];
5764
+ while (pendingDescendantIds.length > 0) {
5765
+ const parentId = pendingDescendantIds.pop();
5766
+ for (const child of childrenByParent.get(parentId) ?? []) {
5767
+ if (selectedSubtreeIds.has(child.id)) continue;
5768
+ selectedSubtreeIds.add(child.id);
5769
+ pendingDescendantIds.push(child.id);
5770
+ }
5771
+ }
5546
5772
  for (const id of selection) {
5547
5773
  let parentId = nodeIndex.get(id)?.parentId;
5548
5774
  while (parentId && !visitedAncestorIds.has(parentId)) {
@@ -5555,15 +5781,17 @@ function createFlowEngine(store, initialOptions = {}) {
5555
5781
  }
5556
5782
  for (const n of c.graph.nodes) {
5557
5783
  nodeMap.set(n.id, n);
5558
- if (!selection.has(n.id) && !selectedDerivedAncestorIds.has(n.id) && !n.hidden) {
5784
+ if (!selectedSubtreeIds.has(n.id) && !selectedDerivedAncestorIds.has(n.id) && !n.hidden) {
5559
5785
  const b = hierarchyBounds(n, c);
5560
- if (rectsIntersect(b, viewRect) && (!selBounds || !rectContains(selBounds, b))) rects.push(b);
5786
+ if (rectsIntersect(b, viewRect)) rects.push(b);
5561
5787
  }
5562
5788
  }
5563
5789
  for (const edge of c.graph.edges) {
5564
5790
  if (selection.has(edge.id)) continue;
5791
+ const ownerId = edgeOwnerOf(edge, c);
5792
+ if (ownerId && selectedSubtreeIds.has(ownerId)) continue;
5565
5793
  const lb = resolveEdgeLabelBounds(edge, nodeMap, c.measurements.get(edge.id));
5566
- if (lb && rectsIntersect(lb, viewRect) && (!selBounds || !rectContains(selBounds, lb))) rects.push(lb);
5794
+ if (lb && rectsIntersect(lb, viewRect)) rects.push(lb);
5567
5795
  }
5568
5796
  return rects;
5569
5797
  }
@@ -5592,7 +5820,7 @@ function createFlowEngine(store, initialOptions = {}) {
5592
5820
  if ((nodesMoved || edgesMoved) && c.enableSnapLines) {
5593
5821
  const selBounds = getSelectionSnapBounds(c);
5594
5822
  if (selBounds) {
5595
- const snapResult = getSnapLines(selBounds, getSnapTargetRects(c, selection, selBounds), {
5823
+ const snapResult = getSnapLines(selBounds, getSnapTargetRects(c, selection), {
5596
5824
  threshold: c.snapThreshold / c.viewport.zoom,
5597
5825
  enableSpacing: c.enableSpacingGuides
5598
5826
  });
@@ -5860,7 +6088,7 @@ function createFlowEngine(store, initialOptions = {}) {
5860
6088
  computing.delete(edge.id);
5861
6089
  return null;
5862
6090
  }
5863
- const memoizableEdge = memoUsable && !engineOptions.edgeRouter && !isDerivedGroup(source) && !isDerivedGroup(target);
6091
+ const memoizableEdge = memoUsable && (!engineOptions.edgeRouter || engineOptions.edgeRouterDependencies === "endpoints") && !isDerivedGroup(source) && !isDerivedGroup(target);
5864
6092
  if (memoizableEdge) {
5865
6093
  const entry = edgePathMemo.get(edge.id);
5866
6094
  if (entry && entry.edge === edge && entry.source === source && entry.target === target) {
@@ -5967,6 +6195,93 @@ function createFlowEngine(store, initialOptions = {}) {
5967
6195
  };
5968
6196
  return value;
5969
6197
  }
6198
+ function spatialCells(rect) {
6199
+ const minX = Math.floor(rect.x / SPATIAL_CELL_SIZE);
6200
+ const minY = Math.floor(rect.y / SPATIAL_CELL_SIZE);
6201
+ const maxX = Math.floor((rect.x + Math.max(0, rect.width)) / SPATIAL_CELL_SIZE);
6202
+ const maxY = Math.floor((rect.y + Math.max(0, rect.height)) / SPATIAL_CELL_SIZE);
6203
+ if ((maxX - minX + 1) * (maxY - minY + 1) > MAX_ENTITY_SPATIAL_CELLS) return null;
6204
+ const cells = [];
6205
+ for (let y = minY; y <= maxY; y++) for (let x = minX; x <= maxX; x++) cells.push(`${x}:${y}`);
6206
+ return cells;
6207
+ }
6208
+ function addSpatialEntry(cells, globalIds, id, bounds) {
6209
+ const keys = spatialCells(bounds);
6210
+ if (!keys) {
6211
+ globalIds.push(id);
6212
+ return;
6213
+ }
6214
+ for (const key of keys) {
6215
+ const ids = cells.get(key);
6216
+ if (ids) ids.push(id);
6217
+ else cells.set(key, [id]);
6218
+ }
6219
+ }
6220
+ function edgeSpatialBounds(edge, path, c) {
6221
+ let bounds = path?.labelBounds ?? null;
6222
+ for (const segment of path?.segments ?? []) {
6223
+ const segmentBounds = pathBounds(segment);
6224
+ if (segmentBounds) bounds = bounds ? unionRect(bounds, segmentBounds) : segmentBounds;
6225
+ }
6226
+ if (bounds) return bounds;
6227
+ const source = getNode(edge.sourceId);
6228
+ const target = getNode(edge.targetId);
6229
+ if (!source || !target) return null;
6230
+ return unionRect(withLayoutOffset(resolvedBounds(source), source.id, c), withLayoutOffset(resolvedBounds(target), target.id, c));
6231
+ }
6232
+ /**
6233
+ * Viewport-query index keyed by geometry identities, never viewport. Building
6234
+ * is O(n + m); subsequent pan/zoom queries visit occupied viewport cells and
6235
+ * visible candidates instead of scanning the graph. Very large entities stay
6236
+ * in a small global list to cap cell fanout and retained memory.
6237
+ */
6238
+ function spatialIndexFor(c, order, paths) {
6239
+ const cached = renderableSpatialIndex;
6240
+ if (cached?.nodesInput === c.graph.nodes && cached.pathsInput === paths && cached.measurementsInput === c.measurements && cached.layoutOffsetsInput === c.layoutAnimation.offsets && cached.collapsedInput === c.collapsedNodeIds) return cached;
6241
+ const next = {
6242
+ nodesInput: c.graph.nodes,
6243
+ pathsInput: paths,
6244
+ measurementsInput: c.measurements,
6245
+ layoutOffsetsInput: c.layoutAnimation.offsets,
6246
+ collapsedInput: c.collapsedNodeIds,
6247
+ nodeCells: /* @__PURE__ */ new Map(),
6248
+ edgeCells: /* @__PURE__ */ new Map(),
6249
+ globalNodeIds: [],
6250
+ globalEdgeIds: [],
6251
+ nodeBounds: /* @__PURE__ */ new Map(),
6252
+ edgeBounds: /* @__PURE__ */ new Map()
6253
+ };
6254
+ for (const node of order.nodes) {
6255
+ const bounds = hierarchyBounds(node, c);
6256
+ next.nodeBounds.set(node.id, bounds);
6257
+ addSpatialEntry(next.nodeCells, next.globalNodeIds, node.id, bounds);
6258
+ }
6259
+ for (const edge of order.edges) {
6260
+ const bounds = edgeSpatialBounds(edge, paths.get(edge.id), c);
6261
+ if (!bounds) continue;
6262
+ next.edgeBounds.set(edge.id, bounds);
6263
+ addSpatialEntry(next.edgeCells, next.globalEdgeIds, edge.id, bounds);
6264
+ }
6265
+ renderableSpatialIndex = next;
6266
+ return next;
6267
+ }
6268
+ function spatialCandidates(cells, globalIds, rect) {
6269
+ const keys = spatialCells(rect);
6270
+ if (!keys) return null;
6271
+ const ids = new Set(globalIds);
6272
+ for (const key of keys) for (const id of cells.get(key) ?? []) ids.add(id);
6273
+ return ids;
6274
+ }
6275
+ function entityRanks(order) {
6276
+ if (entityRankCache?.order === order) return entityRankCache;
6277
+ const ranks = {
6278
+ order,
6279
+ nodes: new Map(order.nodes.map((node, index) => [node.id, index])),
6280
+ edges: new Map(order.edges.map((edge, index) => [edge.id, index]))
6281
+ };
6282
+ entityRankCache = ranks;
6283
+ return ranks;
6284
+ }
5970
6285
  function computeRenderableEntities(c, options) {
5971
6286
  const vp = c.viewport;
5972
6287
  const overscan = options.overscan ?? 0;
@@ -5979,6 +6294,26 @@ function createFlowEngine(store, initialOptions = {}) {
5979
6294
  };
5980
6295
  const cullMode = options.cull === "viewport" && rectContains(cullRect, graphBoundsFor(c)) ? "none" : options.cull;
5981
6296
  const order = getEntityOrderFor(c);
6297
+ if (cullMode === "viewport" && (c.canvasState === "idle" || c.canvasState === "panning")) {
6298
+ const spatial = spatialIndexFor(c, order, getAllEdgePaths());
6299
+ const nodeIds = spatialCandidates(spatial.nodeCells, spatial.globalNodeIds, cullRect);
6300
+ const edgeIds = spatialCandidates(spatial.edgeCells, spatial.globalEdgeIds, cullRect);
6301
+ if (nodeIds && edgeIds) {
6302
+ const ranks = entityRanks(order);
6303
+ return {
6304
+ nodes: [...nodeIds].sort((left, right) => (ranks.nodes.get(left) ?? 0) - (ranks.nodes.get(right) ?? 0)).flatMap((id) => {
6305
+ const node = getNode(id);
6306
+ const bounds = spatial.nodeBounds.get(id);
6307
+ return node && bounds && isNodeVisible(node, c, vp) && rectsIntersect(bounds, cullRect) ? [node] : [];
6308
+ }),
6309
+ edges: [...edgeIds].sort((left, right) => (ranks.edges.get(left) ?? 0) - (ranks.edges.get(right) ?? 0)).flatMap((id) => {
6310
+ const edge = getEdge(id);
6311
+ const bounds = spatial.edgeBounds.get(id);
6312
+ return edge && bounds && isEdgeVisible(edge, c.graph, c, vp) && rectsIntersect(bounds, cullRect) ? [edge] : [];
6313
+ })
6314
+ };
6315
+ }
6316
+ }
5982
6317
  const nodes = order.nodes.filter((n) => {
5983
6318
  if (!isNodeVisible(n, c, vp)) return false;
5984
6319
  if (cullMode === "viewport" && !rectsIntersect(hierarchyBounds(n, c), cullRect)) return false;
@@ -5990,10 +6325,13 @@ function createFlowEngine(store, initialOptions = {}) {
5990
6325
  edges: order.edges.filter((e) => {
5991
6326
  if (!isEdgeVisible(e, c.graph, c, vp)) return false;
5992
6327
  if (cullMode !== "viewport") return true;
6328
+ const path = edgePaths.get(e.id);
5993
6329
  if (e.label) {
5994
- if (rectsIntersect(getEdgeLabelBounds(e.id), cullRect)) return true;
6330
+ const labelRect = path?.labelBounds ?? getEdgeLabelBounds(e.id);
6331
+ if (!labelRect) return false;
6332
+ if (rectsIntersect(labelRect, cullRect)) return true;
5995
6333
  }
5996
- if (edgePaths.get(e.id)?.segments.some((segment) => {
6334
+ if (path?.segments.some((segment) => {
5997
6335
  const bounds = pathBounds(segment);
5998
6336
  return bounds !== null && rectsIntersect(bounds, cullRect);
5999
6337
  })) return true;
@@ -6007,40 +6345,44 @@ function createFlowEngine(store, initialOptions = {}) {
6007
6345
  if (kind === "node") return engineOptions.elevateOnSelect?.nodes ?? true;
6008
6346
  return engineOptions.elevateOnSelect?.edges ?? false;
6009
6347
  }
6010
- function getEntityOrderFor(c) {
6011
- const selectionInput = selectedBoostEnabled("node") || selectedBoostEnabled("edge") ? c.selection : null;
6012
- if (entityOrderCache?.nodesInput === c.graph.nodes && entityOrderCache.edgesInput === c.graph.edges && entityOrderCache.selectionInput === selectionInput && entityOrderCache.collapsedInput === c.collapsedNodeIds) return entityOrderCache.value;
6348
+ function getEntityOrderFor(c, options = {}) {
6349
+ const elevateSelected = options.elevateSelected ?? true;
6350
+ const selectionInput = elevateSelected && (selectedBoostEnabled("node") || selectedBoostEnabled("edge")) ? c.selection : null;
6351
+ const cache = elevateSelected ? entityOrderCache : baseEntityOrderCache;
6352
+ if (cache?.nodesInput === c.graph.nodes && cache.edgesInput === c.graph.edges && cache.selectionInput === selectionInput && cache.collapsedInput === c.collapsedNodeIds) return cache.value;
6013
6353
  const depths = nodeDepths(c.graph.nodes);
6014
- const nodeOrder = new Map(c.graph.nodes.map((node, index) => [node.id, index]));
6015
6354
  const foldedEdges = foldedEdgesFor(c).edges;
6016
- const edgeOrder = new Map([...c.graph.edges, ...foldedEdges].map((edge, index) => [edge.id, index]));
6355
+ const elevateNodes = elevateSelected && selectedBoostEnabled("node");
6356
+ const elevateEdges = elevateSelected && selectedBoostEnabled("edge");
6017
6357
  const value = {
6018
6358
  nodes: [...c.graph.nodes].sort((a, b) => {
6019
6359
  const depthDelta = (depths.get(a.id) ?? 0) - (depths.get(b.id) ?? 0);
6020
6360
  if (depthDelta !== 0) return depthDelta;
6021
6361
  const zDelta = (a.zIndex ?? 0) - (b.zIndex ?? 0);
6022
6362
  if (zDelta !== 0) return zDelta;
6023
- const selectedDelta = Number(selectedBoostEnabled("node") && c.selection.has(a.id)) - Number(selectedBoostEnabled("node") && c.selection.has(b.id));
6363
+ const selectedDelta = Number(elevateNodes && c.selection.has(a.id)) - Number(elevateNodes && c.selection.has(b.id));
6024
6364
  if (selectedDelta !== 0) return selectedDelta;
6025
- return (nodeOrder.get(a.id) ?? 0) - (nodeOrder.get(b.id) ?? 0);
6365
+ return 0;
6026
6366
  }),
6027
6367
  edges: [...c.graph.edges, ...foldedEdges].sort((a, b) => {
6028
6368
  const depthDelta = Math.max(depths.get(a.sourceId) ?? 0, depths.get(a.targetId) ?? 0) - Math.max(depths.get(b.sourceId) ?? 0, depths.get(b.targetId) ?? 0);
6029
6369
  if (depthDelta !== 0) return depthDelta;
6030
6370
  const zDelta = (a.zIndex ?? 0) - (b.zIndex ?? 0);
6031
6371
  if (zDelta !== 0) return zDelta;
6032
- const selectedDelta = Number(selectedBoostEnabled("edge") && c.selection.has(a.id)) - Number(selectedBoostEnabled("edge") && c.selection.has(b.id));
6372
+ const selectedDelta = Number(elevateEdges && c.selection.has(a.id)) - Number(elevateEdges && c.selection.has(b.id));
6033
6373
  if (selectedDelta !== 0) return selectedDelta;
6034
- return (edgeOrder.get(a.id) ?? 0) - (edgeOrder.get(b.id) ?? 0);
6374
+ return 0;
6035
6375
  })
6036
6376
  };
6037
- entityOrderCache = {
6377
+ const nextCache = {
6038
6378
  nodesInput: c.graph.nodes,
6039
6379
  edgesInput: c.graph.edges,
6040
6380
  selectionInput,
6041
6381
  collapsedInput: c.collapsedNodeIds,
6042
6382
  value
6043
6383
  };
6384
+ if (elevateSelected) entityOrderCache = nextCache;
6385
+ else baseEntityOrderCache = nextCache;
6044
6386
  return value;
6045
6387
  }
6046
6388
  function getPublicVisualBounds(nodeOrId) {
@@ -6227,7 +6569,7 @@ function createFlowEngine(store, initialOptions = {}) {
6227
6569
  const ids = [];
6228
6570
  for (const n of graph.nodes) {
6229
6571
  if (!isNodeVisible(n, c)) continue;
6230
- if (rectsIntersect(rect, visualBounds(n, getVisualSnapOffset()))) ids.push(n.id);
6572
+ if (rectsIntersect(rect, n.selectionBounds ? resolvedSelectionBounds(n) : visualBounds(n, getVisualSnapOffset()))) ids.push(n.id);
6231
6573
  }
6232
6574
  for (const e of graph.edges) {
6233
6575
  if (!isEdgeVisible(e, graph, c)) continue;
@@ -6279,16 +6621,16 @@ function createFlowEngine(store, initialOptions = {}) {
6279
6621
  validateConnection,
6280
6622
  validateConnectionDetailed,
6281
6623
  resolveEntityConfig,
6282
- getVisibleEntities: () => {
6624
+ getVisibleEntities: (options = {}) => {
6283
6625
  const c = ctx();
6284
- const order = getEntityOrderFor(c);
6626
+ const order = getEntityOrderFor(c, options);
6285
6627
  return {
6286
6628
  nodes: order.nodes.filter((n) => isNodeVisible(n, c)),
6287
6629
  edges: order.edges.filter((e) => isEdgeVisible(e, c.graph, c))
6288
6630
  };
6289
6631
  },
6290
6632
  /** Deterministic paint order. Later items should paint above earlier ones. */
6291
- getEntityOrder: () => getEntityOrderFor(ctx()),
6633
+ getEntityOrder: (options = {}) => getEntityOrderFor(ctx(), options),
6292
6634
  /**
6293
6635
  * Renderable (visible, optionally viewport-culled) entities. Memoized per
6294
6636
  * (store snapshot, cull/overscan) so several render layers can share one
@@ -6338,7 +6680,7 @@ function createFlowEngine(store, initialOptions = {}) {
6338
6680
  if (!nodesMoved && !edgesMoved) return null;
6339
6681
  const selBounds = getSelectionSnapBounds(c);
6340
6682
  if (!selBounds) return null;
6341
- const otherRects = getSnapTargetRects(c, c.selection, selBounds);
6683
+ const otherRects = getSnapTargetRects(c, c.selection);
6342
6684
  if (otherRects.length === 0) return null;
6343
6685
  return getSnapLines(selBounds, otherRects, {
6344
6686
  threshold: c.snapThreshold / c.viewport.zoom,
@@ -7679,7 +8021,19 @@ function createFlow(options = {}) {
7679
8021
  const ids = fitOptions?.nodes?.map((node) => typeof node === "string" ? node : node.id);
7680
8022
  const idSet = ids && ids.length > 0 ? new Set(ids) : null;
7681
8023
  const visible = getViewEntities({ includeHidden: fitOptions?.includeHidden });
7682
- const bounds = getGraphBounds(visible.nodes.filter((node) => !idSet || idSet.has(node.id)), visible.edges.filter((edge) => !idSet || idSet.has(edge.id)), context.measurements);
8024
+ const nodes = visible.nodes.filter((node) => !idSet || idSet.has(node.id));
8025
+ const edges = visible.edges.filter((edge) => !idSet || idSet.has(edge.id));
8026
+ const bounds = getGraphBounds(nodes.map((node) => {
8027
+ const visual = engine.visualBounds(node.id);
8028
+ return visual ? {
8029
+ ...node,
8030
+ ...visual,
8031
+ dx: 0,
8032
+ dy: 0,
8033
+ autoSize: false,
8034
+ style: void 0
8035
+ } : node;
8036
+ }), edges, context.measurements);
7683
8037
  if (bounds.width === 0 && bounds.height === 0) return null;
7684
8038
  const { nodes: _nodes, includeHidden: _includeHidden, ...viewportOptions } = fitOptions ?? {};
7685
8039
  return viewportForBounds(bounds, context.viewportSize, {
@@ -9108,6 +9462,7 @@ function entityPressMode(options = {}) {
9108
9462
  modifiers: event.modifiers
9109
9463
  })] };
9110
9464
  if (event.button !== 0) return null;
9465
+ if (event.target.part === "connection-boundary") return null;
9111
9466
  const entity = engine.getEntity(id);
9112
9467
  if (!entity) return null;
9113
9468
  const config = engine.resolveEntityConfig(entity);
@@ -9585,7 +9940,7 @@ function edgeEndpointFromPart(part) {
9585
9940
  if (part === "edge-endpoint:target") return "target";
9586
9941
  return null;
9587
9942
  }
9588
- function reconnectTarget(target, ctx) {
9943
+ function reconnectTarget(target, ctx, point) {
9589
9944
  if (target.kind === "port") return {
9590
9945
  nodeId: target.nodeId,
9591
9946
  port: target.portName
@@ -9594,10 +9949,17 @@ function reconnectTarget(target, ctx) {
9594
9949
  nodeId: target.id,
9595
9950
  port: null
9596
9951
  };
9952
+ if (point) {
9953
+ const candidate = ctx.engine.getConnectionCandidate(point);
9954
+ if (candidate) return {
9955
+ nodeId: candidate.nodeId,
9956
+ port: candidate.portName
9957
+ };
9958
+ }
9597
9959
  return null;
9598
9960
  }
9599
9961
  function defaultReconnectValidity(args, ctx) {
9600
- const candidate = reconnectTarget(args.target, ctx);
9962
+ const candidate = reconnectTarget(args.target, ctx, args.point);
9601
9963
  if (!candidate) return false;
9602
9964
  if (args.end === "source") return ctx.engine.validateConnection({
9603
9965
  sourceId: candidate.nodeId,
@@ -9655,7 +10017,7 @@ function reconnectSession(reconnect, options) {
9655
10017
  let active = reconnect.threshold === 0;
9656
10018
  function moveCommands(event, ctx, activate = false) {
9657
10019
  const edge = ctx.engine.getEdge(reconnect.edgeId);
9658
- const candidate = reconnectTarget(event.target, ctx);
10020
+ const candidate = reconnectTarget(event.target, ctx, event.point);
9659
10021
  const valid = !!edge && isValid({
9660
10022
  edge,
9661
10023
  end: reconnect.end,
@@ -9696,6 +10058,10 @@ function reconnectSession(reconnect, options) {
9696
10058
  const result = moveCommands(event, ctx);
9697
10059
  const commands = [...result.commands];
9698
10060
  if (result.candidate && result.valid) {
10061
+ const endTarget = connectEndTargetFor(targetFromConnectionCandidate({
10062
+ nodeId: result.candidate.nodeId,
10063
+ portName: result.candidate.port
10064
+ }), event.point, ctx);
9699
10065
  if (options.commit !== false) commands.push(trigger("reconnectEdge", {
9700
10066
  edgeId: reconnect.edgeId,
9701
10067
  ...reconnect.end === "source" ? {
@@ -9708,7 +10074,7 @@ function reconnectSession(reconnect, options) {
9708
10074
  transactionId: reconnect.transactionId
9709
10075
  }));
9710
10076
  commands.push(trigger("connectionEnd", {
9711
- target: connectEndTargetFor(event.target, event.point, ctx),
10077
+ target: endTarget,
9712
10078
  reconnectedEdgeId: reconnect.edgeId
9713
10079
  }));
9714
10080
  } else commands.push(trigger("connectionEnd", {
@@ -10188,31 +10554,13 @@ function getAutoPanDelta(context, screenPoint, engine) {
10188
10554
  }
10189
10555
  //#endregion
10190
10556
  //#region src/entity-changes.ts
10191
- const adjacencyCache = /* @__PURE__ */ new WeakMap();
10192
10557
  function adjacency(edges) {
10193
- let index = adjacencyCache.get(edges);
10194
- if (!index) {
10195
- index = /* @__PURE__ */ new Map();
10196
- for (const edge of edges) {
10197
- let source = index.get(edge.sourceId);
10198
- if (!source) index.set(edge.sourceId, source = []);
10199
- source.push(edge.id);
10200
- if (edge.targetId !== edge.sourceId) {
10201
- let target = index.get(edge.targetId);
10202
- if (!target) index.set(edge.targetId, target = []);
10203
- target.push(edge.id);
10204
- }
10205
- }
10206
- adjacencyCache.set(edges, index);
10207
- }
10208
- return index;
10558
+ return indexEdgeAdjacency(edges).byNode;
10209
10559
  }
10210
- function computeDirty(prev, next, options) {
10211
- if (next.canvasState !== prev.canvasState) return "all";
10560
+ function computeDirty(prev, next, options, dragDirtyIds) {
10212
10561
  if (next.mode !== prev.mode) return "all";
10213
10562
  if (next.configRevision !== prev.configRevision) return "all";
10214
10563
  if (next.collapsedNodeIds !== prev.collapsedNodeIds) return "all";
10215
- if (next.enableSnapLines && next.canvasState === "dragging") return "all";
10216
10564
  const dirty = /* @__PURE__ */ new Set();
10217
10565
  const markEdge = (edgeId) => {
10218
10566
  dirty.add(edgeId);
@@ -10220,7 +10568,7 @@ function computeDirty(prev, next, options) {
10220
10568
  };
10221
10569
  const markIncidentEdges = (nodeId, edges) => {
10222
10570
  const incident = adjacency(edges).get(nodeId);
10223
- if (incident) for (const edgeId of incident) markEdge(edgeId);
10571
+ if (incident) for (const edge of incident) markEdge(edge.id);
10224
10572
  };
10225
10573
  const markAncestors = (node) => {
10226
10574
  const nextIndex = indexNodes(next.graph.nodes);
@@ -10233,6 +10581,21 @@ function computeDirty(prev, next, options) {
10233
10581
  parentId = nextIndex.get(parentId)?.parentId ?? null;
10234
10582
  }
10235
10583
  };
10584
+ if (next.dragRevision !== prev.dragRevision && dragDirtyIds) return new Set(dragDirtyIds);
10585
+ if (next.canvasState !== prev.canvasState && (next.canvasState === "dragging" || prev.canvasState === "dragging")) if (prev.canvasState === "dragging" && dragDirtyIds) for (const id of dragDirtyIds) dirty.add(id);
10586
+ else for (const id of /* @__PURE__ */ new Set([...prev.selection, ...next.selection])) dirty.add(id);
10587
+ if (next.enableSnapLines && next.canvasState === "dragging") {
10588
+ const nodes = indexNodes(next.graph.nodes);
10589
+ const edges = indexEdges(next.graph.edges);
10590
+ for (const id of next.selection) {
10591
+ dirty.add(id);
10592
+ const node = nodes.get(id);
10593
+ if (node) {
10594
+ markIncidentEdges(id, next.graph.edges);
10595
+ markAncestors(node);
10596
+ } else if (edges.has(id)) markEdge(id);
10597
+ }
10598
+ }
10236
10599
  if (next.layoutAnimation.offsets !== prev.layoutAnimation.offsets) {
10237
10600
  const prevNodes = indexNodes(prev.graph.nodes);
10238
10601
  const nextNodes = indexNodes(next.graph.nodes);
@@ -10332,13 +10695,61 @@ function computeDirty(prev, next, options) {
10332
10695
  }
10333
10696
  return dirty;
10334
10697
  }
10698
+ function dirtyIdsForDrag(context, options) {
10699
+ const dirty = /* @__PURE__ */ new Set();
10700
+ const nodes = indexNodes(context.graph.nodes);
10701
+ const edges = indexEdges(context.graph.edges);
10702
+ const children = indexChildren(context.graph.nodes);
10703
+ const markEdge = (id) => {
10704
+ dirty.add(id);
10705
+ for (const dependentId of options.getEdgeDependents?.(id) ?? []) dirty.add(dependentId);
10706
+ };
10707
+ const markIncident = (id) => {
10708
+ for (const edge of adjacency(context.graph.edges).get(id) ?? []) markEdge(edge.id);
10709
+ };
10710
+ const markAncestors = (id) => {
10711
+ const seen = /* @__PURE__ */ new Set();
10712
+ let parentId = nodes.get(id)?.parentId ?? null;
10713
+ while (parentId && !seen.has(parentId)) {
10714
+ seen.add(parentId);
10715
+ dirty.add(parentId);
10716
+ markIncident(parentId);
10717
+ parentId = nodes.get(parentId)?.parentId ?? null;
10718
+ }
10719
+ };
10720
+ const markNodeSubtree = (id, seen = /* @__PURE__ */ new Set()) => {
10721
+ if (seen.has(id)) return;
10722
+ seen.add(id);
10723
+ dirty.add(id);
10724
+ markIncident(id);
10725
+ markAncestors(id);
10726
+ for (const child of children.get(id) ?? []) markNodeSubtree(child.id, seen);
10727
+ };
10728
+ for (const id of context.selection) if (nodes.has(id)) markNodeSubtree(id);
10729
+ else {
10730
+ const edge = edges.get(id);
10731
+ if (!edge) continue;
10732
+ markEdge(id);
10733
+ const source = nodes.get(edge.sourceId);
10734
+ const target = nodes.get(edge.targetId);
10735
+ if (source?.group) dirty.add(source.id);
10736
+ if (target?.group) dirty.add(target.id);
10737
+ markAncestors(edge.sourceId);
10738
+ markAncestors(edge.targetId);
10739
+ }
10740
+ return dirty;
10741
+ }
10335
10742
  function createEntityChangeNotifier(store, options = {}) {
10336
10743
  const listeners = /* @__PURE__ */ new Map();
10337
10744
  let prev = store.getSnapshot().context;
10745
+ let activeDragDirtyIds;
10338
10746
  const subscription = store.subscribe((snapshot) => {
10339
10747
  const next = snapshot.context;
10340
10748
  if (next === prev) return;
10341
- const dirty = computeDirty(prev, next, options);
10749
+ if (next.canvasState === "dragging" && (prev.canvasState !== "dragging" || next.selection !== prev.selection)) activeDragDirtyIds = dirtyIdsForDrag(next, options);
10750
+ const dirty = computeDirty(prev, next, options, activeDragDirtyIds);
10751
+ if (next.canvasState === "dragging" && next.dragRevision === prev.dragRevision && (next.graph.nodes !== prev.graph.nodes || next.graph.edges !== prev.graph.edges)) activeDragDirtyIds = dirtyIdsForDrag(next, options);
10752
+ else if (next.canvasState !== "dragging") activeDragDirtyIds = void 0;
10342
10753
  prev = next;
10343
10754
  if (dirty === "all") {
10344
10755
  for (const set of listeners.values()) for (const listener of [...set]) listener();
@@ -10369,4 +10780,4 @@ function createEntityChangeNotifier(store, options = {}) {
10369
10780
  };
10370
10781
  }
10371
10782
  //#endregion
10372
- export { CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, FlowGraphValidationError, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };
10783
+ export { CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, FlowGraphValidationError, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, resolvedSelectionBounds, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };