@statelyai/flow 0.13.2 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -802,7 +802,7 @@ await animation.done;
802
802
 
803
803
  <!-- edge routers from src/routing/index.ts -->
804
804
 
805
- Four built-in routers. All return `PathData` (points + source/target direction). A custom router may also return `svgPath` to preserve rounded or otherwise custom SVG geometry; `points` remain required for bounds and endpoint handles, and exported `pathToSVG` safely prefers a finite override containing only SVG path commands and numeric parameters. Canonical graph `edge.points` are different from `waypoints`: they are a complete authoritative endpoint-to-endpoint route, interpreted by `edge.routing` (`polyline`, `orthogonal`, or chained `splines`) and never sent through a Flow router or split around a label. An optional edge `svgPath` preserves exact SVG paint while the authoritative points drive endpoints, bounds, hit testing, culling, transient DOM updates, and export. Core endpoint-geometry mutations invalidate precomputed route fields; layout results may atomically replace them with either interior router waypoints or complete `points` plus `routing`. Edge `waypoints` remain ordered interior router inputs passed through `EdgeRouterContext`; built-in routers honor them. Custom `EdgeRouter`s receive the full typed edge plus the exact canonical or projection `graph` currently being routed and a detached, read-only `getEntityBounds(id)` lookup for live node/edge-label geometry. The lookup never routes another edge. Use `configureBezierRouter(options)`, `configureStepRouter(options)`, and `configureAvoidRouter(options)` for customized built-in router variants. `avoidRouter` is opt-in and routes orthogonal polylines around sibling node obstacles. Set `engine.edgeRouterDependencies: 'endpoints'` only when a custom router does not inspect unrelated graph entities, bounds, or obstacles; Flow can then retain unaffected routes after local geometry changes. The safe default is `'graph'`.
805
+ Four built-in routers. All return `PathData` (points + source/target direction). A custom router may also return `svgPath` to preserve rounded or otherwise custom SVG geometry; `points` remain required for bounds and endpoint handles, and exported `pathToSVG` safely prefers a finite override containing only SVG path commands and numeric parameters. Canonical graph `edge.points` are different from `waypoints`: they are a complete authoritative endpoint-to-endpoint route, interpreted by `edge.routing` (`polyline`, `orthogonal`, or chained `splines`) and never sent through a Flow router or split around a label. An optional edge `svgPath` preserves exact SVG paint while the authoritative points drive endpoints, bounds, hit testing, culling, transient DOM updates, and export. Core endpoint-geometry mutations invalidate precomputed route fields; layout results may atomically replace them with either interior router waypoints or complete `points` plus `routing`. Edge `waypoints` remain ordered interior router inputs passed through `EdgeRouterContext`; built-in routers honor them. Custom `EdgeRouter`s receive the full typed edge plus the exact canonical or projection `graph` currently being routed and a detached, read-only `getEntityBounds(id)` lookup for live node/edge-label geometry. The lookup never routes another edge. Use `configureBezierRouter(options)`, `configureStepRouter(options)`, and `configureAvoidRouter(options)` for customized built-in router variants. `avoidRouter` is opt-in and routes orthogonal polylines around sibling node obstacles. Set `engine.edgeRouterDependencies: 'endpoints'` only when a custom router does not inspect unrelated graph entities, bounds, or obstacles; Flow can then retain unaffected routes after local geometry changes. The safe default is `'graph'`: Flow records the edge and graph fields a router reads, the bounds it looks up, and whether it reads obstacles, and skips routing when none of them and no call's geometry changed. Edits a router never reads, such as node `data`, then do not reroute. Replay only spans graph changes: a change to other routing state, such as measurements, appearances, or selection, reroutes. Set `'snapshot'` when a router reads state outside its context, such as `flow.getNode()` or measurements through a closure. Flow then never replays its results and reroutes on every graph or routing state change.
806
806
 
807
807
  Router obstacles exclude the source, target, and their ancestor groups, so an
808
808
  edge crossing a hierarchy boundary can pass through its endpoint container.
@@ -630,8 +630,11 @@ type EdgeRouterContext<TEdgeData = any, TLabelData = any, TNodeData = any> = {
630
630
  * Deterministic edge-routing function.
631
631
  *
632
632
  * Routers should depend only on the edge and supplied routing context. Do not
633
- * read viewport or external mutable state; Flow may reuse a path while graph
634
- * geometry and the router identity are unchanged.
633
+ * read viewport or external mutable state. With the default `graph`
634
+ * dependencies, the edge and `context.graph` are read-only views that record
635
+ * each field the router reads; Flow reuses a pass's paths while every recorded
636
+ * read and every call's inputs are unchanged. A router that freezes or clones
637
+ * those views is routed without tracking.
635
638
  */
636
639
  type EdgeRouter<TEdgeData = any, TLabelData = any, TNodeData = any> = (edge: Readonly<FlowEdge<TEdgeData, TLabelData>>, context: EdgeRouterContext<TEdgeData, TLabelData, TNodeData>) => PathData;
637
640
  type BezierRouterOptions = {
@@ -707,7 +710,7 @@ type ProposedConnection = {
707
710
  targetPort?: string | null;
708
711
  };
709
712
  type FlowConnectionMode = 'strict' | 'loose';
710
- type EdgeRouterDependencies = 'graph' | 'endpoints';
713
+ type EdgeRouterDependencies = 'graph' | 'endpoints' | 'snapshot';
711
714
  type FlowConnectionOptions = {
712
715
  /** Magnet radius in canvas pixels. Default 24. */
713
716
  radius?: number;
@@ -748,9 +751,15 @@ type FlowEngineOptions = {
748
751
  /** Default edge router (default: bezierRouter) */
749
752
  edgeRouter?: EdgeRouter;
750
753
  /**
751
- * Geometry read by a custom edge router. Defaults to `graph`, which safely
752
- * reroutes every edge after any graph geometry change. Use `endpoints` only
753
- * when the router depends on the edge and its endpoint/label inputs—not
754
+ * Geometry read by a custom edge router. Defaults to `graph`: Flow records
755
+ * what the router reads from the edge, the graph, `getEntityBounds`, and
756
+ * `obstacles` during a routing pass, and reroutes every edge when any of it,
757
+ * any call's geometry, or any other routing state (measurements,
758
+ * appearances, selection, connection, snapping) changes. Use `snapshot`
759
+ * when the router also reads state those views don't cover, such as
760
+ * `flow.getNode()` or measurements through a closure: Flow then reroutes on
761
+ * every graph or routing state change. Use `endpoints` only
762
+ * when the router depends on the edge and its endpoint/label inputs, not
754
763
  * arbitrary `graph`, `getEntityBounds`, or `obstacles` reads. That contract
755
764
  * lets Flow retain unaffected custom routes by identity.
756
765
  */
@@ -809,6 +818,13 @@ type PaintZIndices = {
809
818
  nodes: Map<string, number>;
810
819
  edges: Map<string, number>;
811
820
  };
821
+ /**
822
+ * Create the framework-agnostic derived-geometry and query layer for a store.
823
+ *
824
+ * The engine owns memoized graph indices, paint order, bounds, routing, and
825
+ * hit-testing. Returned collections are read-only views and may retain identity
826
+ * while their semantic inputs are unchanged.
827
+ */
812
828
  declare function createFlowEngine(store: FlowStore, initialOptions?: FlowEngineOptions): {
813
829
  store: import("@xstate/store").Store<FlowStoreContext, {
814
830
  createNode: {
package/dist/esm/index.js CHANGED
@@ -5424,6 +5424,204 @@ registerShape("rounded", roundedHandler);
5424
5424
  registerShape("ellipse", ellipseHandler);
5425
5425
  registerShape("diamond", diamondHandler);
5426
5426
  //#endregion
5427
+ //#region src/routing/readTracking.ts
5428
+ const OBJECT = "[object]";
5429
+ const ARRAY = "[array]";
5430
+ const FUNCTION = "[function]";
5431
+ function entityRootFor(root, path, value) {
5432
+ if (root !== "graph" || path.length !== 1) return null;
5433
+ if (!value || typeof value !== "object") return null;
5434
+ const id = value.id;
5435
+ if (typeof id !== "string") return null;
5436
+ if (path[0] === "nodes") return `node:${id}`;
5437
+ if (path[0] === "edges") return `edge:${id}`;
5438
+ return null;
5439
+ }
5440
+ function classify(root, path, value) {
5441
+ const entityRoot = entityRootFor(root, path, value);
5442
+ if (entityRoot) return entityRoot;
5443
+ if (typeof value === "function") return FUNCTION;
5444
+ if (value && typeof value === "object") return Array.isArray(value) ? ARRAY : OBJECT;
5445
+ return value;
5446
+ }
5447
+ function stringKeys(value) {
5448
+ return Reflect.ownKeys(value).filter((key) => typeof key === "string").join("\0");
5449
+ }
5450
+ /**
5451
+ * Read-only views of `graph` and its entities that log what a router reads.
5452
+ * Views are stable for the tracker's lifetime, so routers that cache by
5453
+ * object identity see the same graph and entity objects across calls.
5454
+ */
5455
+ function createRouterReadTracker(graph, getEntityBounds) {
5456
+ const log = {
5457
+ reads: [],
5458
+ bounds: /* @__PURE__ */ new Map()
5459
+ };
5460
+ const entityViews = /* @__PURE__ */ new Map();
5461
+ const sources = /* @__PURE__ */ new WeakMap();
5462
+ const view = (raw, root, path) => {
5463
+ const children = /* @__PURE__ */ new Map();
5464
+ const logged = /* @__PURE__ */ new Set();
5465
+ const record = (op, key, value) => {
5466
+ const id = `${op}\u0000${key ?? ""}`;
5467
+ if (logged.has(id)) return;
5468
+ logged.add(id);
5469
+ log.reads.push({
5470
+ root,
5471
+ path: key === null ? path : [...path, key],
5472
+ op,
5473
+ value
5474
+ });
5475
+ };
5476
+ const child = (key) => {
5477
+ if (children.has(key)) return children.get(key);
5478
+ const value = raw[key];
5479
+ let result = value;
5480
+ if (value && typeof value === "object") {
5481
+ const entityRoot = entityRootFor(root, path, value);
5482
+ result = entityRoot ? entityView(entityRoot, value) : view(value, root, [...path, key]);
5483
+ }
5484
+ children.set(key, result);
5485
+ return result;
5486
+ };
5487
+ const proxy = new Proxy(Array.isArray(raw) ? [] : {}, {
5488
+ get(_target, key) {
5489
+ if (typeof key === "symbol") return Reflect.get(raw, key);
5490
+ record("get", key, classify(root, path, raw[key]));
5491
+ return child(key);
5492
+ },
5493
+ has(_target, key) {
5494
+ const result = Reflect.has(raw, key);
5495
+ if (typeof key === "string") record("has", key, result);
5496
+ return result;
5497
+ },
5498
+ ownKeys() {
5499
+ record("keys", null, stringKeys(raw));
5500
+ return Reflect.ownKeys(raw);
5501
+ },
5502
+ getOwnPropertyDescriptor(_target, key) {
5503
+ const descriptor = Reflect.getOwnPropertyDescriptor(raw, key);
5504
+ if (typeof key === "string") {
5505
+ record("has", key, descriptor !== void 0);
5506
+ if (descriptor) record("get", key, classify(root, path, raw[key]));
5507
+ }
5508
+ if (!descriptor) return void 0;
5509
+ if (Array.isArray(raw) && key === "length") return {
5510
+ value: raw.length,
5511
+ writable: true,
5512
+ enumerable: false,
5513
+ configurable: false
5514
+ };
5515
+ return {
5516
+ value: typeof key === "string" ? child(key) : Reflect.get(raw, key),
5517
+ writable: false,
5518
+ enumerable: descriptor.enumerable,
5519
+ configurable: true
5520
+ };
5521
+ },
5522
+ getPrototypeOf() {
5523
+ return Reflect.getPrototypeOf(raw);
5524
+ },
5525
+ set() {
5526
+ return false;
5527
+ },
5528
+ defineProperty() {
5529
+ return false;
5530
+ },
5531
+ deleteProperty() {
5532
+ return false;
5533
+ }
5534
+ });
5535
+ sources.set(proxy, {
5536
+ raw,
5537
+ root,
5538
+ path
5539
+ });
5540
+ return proxy;
5541
+ };
5542
+ const release = (value) => {
5543
+ if (!value || typeof value !== "object") return value;
5544
+ const source = sources.get(value);
5545
+ if (source) {
5546
+ log.reads.push({
5547
+ root: source.root,
5548
+ path: source.path,
5549
+ op: "value",
5550
+ value: source.raw
5551
+ });
5552
+ return source.raw;
5553
+ }
5554
+ if (Array.isArray(value)) {
5555
+ const next = value.map(release);
5556
+ return next.some((entry, index) => entry !== value[index]) ? next : value;
5557
+ }
5558
+ if (Object.getPrototypeOf(value) !== Object.prototype) return value;
5559
+ let changed = false;
5560
+ const next = {};
5561
+ for (const [key, entry] of Object.entries(value)) {
5562
+ next[key] = release(entry);
5563
+ if (next[key] !== entry) changed = true;
5564
+ }
5565
+ return changed ? next : value;
5566
+ };
5567
+ const entityView = (root, raw) => {
5568
+ let existing = entityViews.get(root);
5569
+ if (!existing) {
5570
+ existing = view(raw, root, []);
5571
+ entityViews.set(root, existing);
5572
+ }
5573
+ return existing;
5574
+ };
5575
+ return {
5576
+ log,
5577
+ graph: view(graph, "graph", []),
5578
+ edge: (edge) => entityView(`edge:${edge.id}`, edge),
5579
+ /** Swap any views in a router result for raw values, logging them as reads. */
5580
+ release: (result) => release(result),
5581
+ getEntityBounds: (id) => {
5582
+ const bounds = getEntityBounds(id);
5583
+ if (!log.bounds.has(id)) log.bounds.set(id, bounds && { ...bounds });
5584
+ return bounds;
5585
+ }
5586
+ };
5587
+ }
5588
+ /** Whether every logged read resolves to the same value against `graph`. */
5589
+ function routerReadsUnchanged(log, graph, edgesById, getEntityBounds, valuesEqual) {
5590
+ let nodesById;
5591
+ const resolveRoot = (root) => {
5592
+ if (root === "graph") return graph;
5593
+ if (root.startsWith("edge:")) return edgesById.get(root.slice(5));
5594
+ nodesById ??= new Map(graph.nodes.map((node) => [node.id, node]));
5595
+ return nodesById.get(root.slice(5));
5596
+ };
5597
+ for (const read of log.reads) {
5598
+ let current = resolveRoot(read.root);
5599
+ if (current === void 0) return false;
5600
+ if (read.op === "value") {
5601
+ for (const key of read.path) {
5602
+ if (!current || typeof current !== "object") return false;
5603
+ current = current[key];
5604
+ }
5605
+ if (!valuesEqual(current, read.value)) return false;
5606
+ continue;
5607
+ }
5608
+ const parentPath = read.op === "keys" ? read.path : read.path.slice(0, -1);
5609
+ for (const key of parentPath) {
5610
+ if (!current || typeof current !== "object") return false;
5611
+ current = current[key];
5612
+ }
5613
+ if (!current || typeof current !== "object") return false;
5614
+ const key = read.path[read.path.length - 1];
5615
+ if (read.op === "keys") {
5616
+ if (stringKeys(current) !== read.value) return false;
5617
+ } else if (read.op === "has") {
5618
+ if (Reflect.has(current, key) !== read.value) return false;
5619
+ } else if (classify(read.root, parentPath, current[key]) !== read.value) return false;
5620
+ }
5621
+ for (const [id, bounds] of log.bounds) if (!valuesEqual(bounds, getEntityBounds(id))) return false;
5622
+ return true;
5623
+ }
5624
+ //#endregion
5427
5625
  //#region src/config.ts
5428
5626
  /** Default config: supported editing behaviors enabled */
5429
5627
  const defaultConfig = {
@@ -5482,13 +5680,7 @@ function normalizeConnection(proposed, graph) {
5482
5680
  }
5483
5681
  const SPATIAL_CELL_SIZE = 512;
5484
5682
  const MAX_ENTITY_SPATIAL_CELLS = 4096;
5485
- /**
5486
- * Create the framework-agnostic derived-geometry and query layer for a store.
5487
- *
5488
- * The engine owns memoized graph indices, paint order, bounds, routing, and
5489
- * hit-testing. Returned collections are read-only views and may retain identity
5490
- * while their semantic inputs are unchanged.
5491
- */
5683
+ const REPLAY_MISS = Symbol("replay miss");
5492
5684
  /** Structural equality for plain path data (objects, arrays, primitives). */
5493
5685
  function plainDataEqual(a, b) {
5494
5686
  if (a === b) return true;
@@ -5499,6 +5691,13 @@ function plainDataEqual(a, b) {
5499
5691
  const aKeys = Object.keys(aRecord);
5500
5692
  return aKeys.length === Object.keys(bRecord).length && aKeys.every((key) => plainDataEqual(aRecord[key], bRecord[key]));
5501
5693
  }
5694
+ /**
5695
+ * Create the framework-agnostic derived-geometry and query layer for a store.
5696
+ *
5697
+ * The engine owns memoized graph indices, paint order, bounds, routing, and
5698
+ * hit-testing. Returned collections are read-only views and may retain identity
5699
+ * while their semantic inputs are unchanged.
5700
+ */
5502
5701
  function createFlowEngine(store, initialOptions = {}) {
5503
5702
  let engineOptions = initialOptions;
5504
5703
  let optionsVersion = 0;
@@ -5663,6 +5862,8 @@ function createFlowEngine(store, initialOptions = {}) {
5663
5862
  obstacleCache = /* @__PURE__ */ new WeakMap();
5664
5863
  edgePathMemo.clear();
5665
5864
  lastCanonicalEdgePaths = null;
5865
+ lastRouting = null;
5866
+ routerReadTrackingDisabled = false;
5666
5867
  const appearances = replace ? partial.appearances ?? {} : partial.appearances;
5667
5868
  if (appearances !== void 0 && appearances !== previousAppearances) store.trigger.configure({ appearances });
5668
5869
  }
@@ -5683,8 +5884,8 @@ function createFlowEngine(store, initialOptions = {}) {
5683
5884
  byOwner.set(key, obstacles);
5684
5885
  return obstacles;
5685
5886
  }
5686
- function edgeObstacles(edge, c) {
5687
- const owner = edgeOwnerOf(edge, c);
5887
+ /** Both endpoints and their ancestors: never obstacles for their own edge. */
5888
+ function edgeEndpointLineage(edge, c) {
5688
5889
  const nodeIndex = indexNodes(c.graph.nodes);
5689
5890
  const endpointLineage = /* @__PURE__ */ new Set();
5690
5891
  for (const endpointId of [edge.sourceId, edge.targetId]) {
@@ -5694,6 +5895,11 @@ function createFlowEngine(store, initialOptions = {}) {
5694
5895
  node = node.parentId ? nodeIndex.get(node.parentId) : void 0;
5695
5896
  }
5696
5897
  }
5898
+ return endpointLineage;
5899
+ }
5900
+ function edgeObstacles(edge, c) {
5901
+ const owner = edgeOwnerOf(edge, c);
5902
+ const endpointLineage = edgeEndpointLineage(edge, c);
5697
5903
  const result = [];
5698
5904
  for (const { id, bounds } of ownerObstacles(owner, c)) {
5699
5905
  if (endpointLineage.has(id)) continue;
@@ -5782,6 +5988,8 @@ function createFlowEngine(store, initialOptions = {}) {
5782
5988
  return withLayoutOffset(resolvedBounds$1(node), node.id, c);
5783
5989
  }
5784
5990
  let lastCanonicalEdgePaths = null;
5991
+ let lastRouting = null;
5992
+ let routerReadTrackingDisabled = false;
5785
5993
  const edgePathMemo = /* @__PURE__ */ new Map();
5786
5994
  let edgePathMemoInputs = null;
5787
5995
  function layoutOffset(id, c = ctx()) {
@@ -6632,6 +6840,17 @@ function createFlowEngine(store, initialOptions = {}) {
6632
6840
  function sameEdgePathsCacheInputs(a, b) {
6633
6841
  return a.appearances === b.appearances && a.canonicalGraph === b.canonicalGraph && a.selection === b.selection && a.collapsedNodeIds === b.collapsedNodeIds && a.connection === b.connection && a.offsetX === b.offsetX && a.offsetY === b.offsetY && a.gridX === b.gridX && a.gridY === b.gridY && a.resizingEntityId === b.resizingEntityId && a.resizeCorners === b.resizeCorners && a.measurements === b.measurements && a.layoutOffsets === b.layoutOffsets;
6634
6842
  }
6843
+ /**
6844
+ * Whether routing state outside the graph is unchanged. Graph updates
6845
+ * replace idle layout offsets with a new empty map, so empty maps match.
6846
+ */
6847
+ function sameRoutingState(a, b) {
6848
+ return sameEdgePathsCacheInputs(a, {
6849
+ ...b,
6850
+ canonicalGraph: a.canonicalGraph,
6851
+ layoutOffsets: a.layoutOffsets.size === 0 && b.layoutOffsets.size === 0 ? a.layoutOffsets : b.layoutOffsets
6852
+ });
6853
+ }
6635
6854
  /** Route all edges. Callers must treat the returned Map as read-only. */
6636
6855
  function getAllEdgePaths(options = {}) {
6637
6856
  const c = ctx();
@@ -6669,11 +6888,118 @@ function createFlowEngine(store, initialOptions = {}) {
6669
6888
  byGraph.set(graph, paths);
6670
6889
  return paths;
6671
6890
  }
6891
+ /**
6892
+ * Route every edge. A custom router that has not declared `endpoints`
6893
+ * dependencies reads through tracked views of the edge and graph. When a
6894
+ * later pass finds every logged read unchanged and the same calls with the
6895
+ * same inputs, it reuses the previous results instead of calling the router,
6896
+ * so edits the router never looked at (a node's color, say) skip routing.
6897
+ * Replay only bridges graph changes: any other routing state change
6898
+ * (measurements, appearances, selection, ...) reroutes, because a router
6899
+ * may read that state through a closure. Any difference reroutes the whole
6900
+ * pass, which keeps routers that share work across calls exact.
6901
+ */
6672
6902
  function computeAllEdgePaths(c, graph, snap = getVisualSnapOffset()) {
6903
+ const router = engineOptions.edgeRouter;
6904
+ if (!router || (engineOptions.edgeRouterDependencies ?? "graph") !== "graph" || graph !== c.graph || routerReadTrackingDisabled) return computeEdgePathsPass(c, graph, snap, "plain");
6905
+ const previous = lastRouting?.router === router && sameRoutingState(lastRouting.inputs, edgePathsCacheInputs(c, snap)) ? lastRouting : null;
6906
+ if (previous) try {
6907
+ return computeEdgePathsPass(c, graph, snap, previous);
6908
+ } catch (error) {
6909
+ if (error !== REPLAY_MISS) throw error;
6910
+ }
6911
+ try {
6912
+ return computeEdgePathsPass(c, graph, snap, "record");
6913
+ } catch {
6914
+ routerReadTrackingDisabled = true;
6915
+ lastRouting = null;
6916
+ return computeEdgePathsPass(c, graph, snap, "plain");
6917
+ }
6918
+ }
6919
+ function createRoute(c, graph, edgeMap, getEntityBounds, snap, mode) {
6920
+ const router = engineOptions.edgeRouter ?? bezierRouter;
6921
+ if (mode === "plain") return {
6922
+ route: (edge, _key, values, getObstacles) => router(edge, {
6923
+ graph,
6924
+ getEntityBounds,
6925
+ ...values,
6926
+ get obstacles() {
6927
+ return getObstacles();
6928
+ }
6929
+ }),
6930
+ finish: () => {}
6931
+ };
6932
+ if (mode === "record") {
6933
+ const tracker = createRouterReadTracker(graph, getEntityBounds);
6934
+ const calls = [];
6935
+ const owners = /* @__PURE__ */ new Map();
6936
+ return {
6937
+ route: (edge, key, values, getObstacles) => {
6938
+ const call = {
6939
+ key,
6940
+ values,
6941
+ result: void 0
6942
+ };
6943
+ call.result = tracker.release(router(tracker.edge(edge), {
6944
+ graph: tracker.graph,
6945
+ getEntityBounds: tracker.getEntityBounds,
6946
+ ...values,
6947
+ get obstacles() {
6948
+ if (!call.obstacles) {
6949
+ const owner = edgeOwnerOf(edge, c);
6950
+ if (!owners.has(owner)) owners.set(owner, ownerObstacles(owner, c));
6951
+ call.obstacles = {
6952
+ owner,
6953
+ lineage: [...edgeEndpointLineage(edge, c)].join("\0")
6954
+ };
6955
+ }
6956
+ return getObstacles();
6957
+ }
6958
+ }));
6959
+ calls.push(call);
6960
+ return call.result;
6961
+ },
6962
+ finish: () => {
6963
+ lastRouting = {
6964
+ router,
6965
+ inputs: edgePathsCacheInputs(c, snap),
6966
+ log: tracker.log,
6967
+ owners,
6968
+ calls
6969
+ };
6970
+ }
6971
+ };
6972
+ }
6973
+ const edgesById = new Map([...edgeMap, ...foldedEdgesFor(c).byId]);
6974
+ if (!routerReadsUnchanged(mode.log, graph, edgesById, getEntityBounds, plainDataEqual)) throw REPLAY_MISS;
6975
+ const ownersUnchanged = /* @__PURE__ */ new Map();
6976
+ const obstaclesUnchanged = (edge, recorded) => {
6977
+ const owner = edgeOwnerOf(edge, c);
6978
+ if (owner !== recorded.owner) return false;
6979
+ let unchanged = ownersUnchanged.get(owner);
6980
+ if (unchanged === void 0) {
6981
+ unchanged = plainDataEqual(mode.owners.get(owner), ownerObstacles(owner, c));
6982
+ ownersUnchanged.set(owner, unchanged);
6983
+ }
6984
+ return unchanged && [...edgeEndpointLineage(edge, c)].join("\0") === recorded.lineage;
6985
+ };
6986
+ let index = 0;
6987
+ return {
6988
+ route: (edge, key, values) => {
6989
+ const call = mode.calls[index++];
6990
+ if (!call || call.key !== key || !plainDataEqual(call.values, values) || call.obstacles && !obstaclesUnchanged(edge, call.obstacles)) throw REPLAY_MISS;
6991
+ return call.result;
6992
+ },
6993
+ finish: () => {
6994
+ if (index !== mode.calls.length) throw REPLAY_MISS;
6995
+ }
6996
+ };
6997
+ }
6998
+ function computeEdgePathsPass(c, graph, snap, mode) {
6673
6999
  const paths = /* @__PURE__ */ new Map();
6674
7000
  const nodeMap = indexNodes(graph.nodes);
6675
7001
  const edgeMap = indexEdges(graph.edges);
6676
- const getEntityBounds = createRouterEntityBoundsLookup(graph, snap, nodeMap, edgeMap);
7002
+ const { route, finish: finishRouting } = createRoute(c, graph, edgeMap, createRouterEntityBoundsLookup(graph, snap, nodeMap, edgeMap), snap, mode);
6677
7003
  const computing = /* @__PURE__ */ new Set();
6678
7004
  const trackSourceDependencies = graph === c.graph;
6679
7005
  const nextEdgeSourceDependents = trackSourceDependencies ? /* @__PURE__ */ new Map() : edgeSourceDependents;
@@ -6741,55 +7067,40 @@ function createFlowEngine(store, initialOptions = {}) {
6741
7067
  const labelConnectionBounds = connectionBounds(edge.id, edge.label, labelBounds);
6742
7068
  const srcDir = portSideOf(source, edge.sourcePort) ?? connectionDirection(source, sourceBounds, labelConnectionBounds);
6743
7069
  const lblDir1 = connectionDirection(edge.label, labelConnectionBounds, sourceBounds);
6744
- const seg1 = (engineOptions.edgeRouter ?? bezierRouter)(edge, {
6745
- graph,
6746
- getEntityBounds,
7070
+ const seg1 = route(edge, `${edge.id}:0`, {
6747
7071
  sourceBounds,
6748
7072
  targetBounds: labelConnectionBounds,
6749
7073
  sourceDirection: srcDir,
6750
7074
  targetDirection: lblDir1,
6751
7075
  sourcePoint: resolveEndpointPoint(source, sourceBounds, edge.sourcePort, labelConnectionBounds, srcDir, snap),
6752
- waypoints,
6753
- get obstacles() {
6754
- return getObstacles();
6755
- }
6756
- });
7076
+ waypoints
7077
+ }, getObstacles);
6757
7078
  const lblDir2 = connectionDirection(edge.label, labelConnectionBounds, targetBounds);
6758
7079
  const tgtDir = portSideOf(target, edge.targetPort) ?? connectionDirection(target, targetBounds, labelConnectionBounds);
6759
7080
  pathData = {
6760
- segments: [seg1, (engineOptions.edgeRouter ?? bezierRouter)(edge, {
6761
- graph,
6762
- getEntityBounds,
7081
+ segments: [seg1, route(edge, `${edge.id}:1`, {
6763
7082
  sourceBounds: labelConnectionBounds,
6764
7083
  targetBounds,
6765
7084
  sourceDirection: lblDir2,
6766
7085
  targetDirection: tgtDir,
6767
7086
  targetPoint: resolveEndpointPoint(target, targetBounds, edge.targetPort, labelConnectionBounds, tgtDir, snap),
6768
- waypoints,
6769
- get obstacles() {
6770
- return getObstacles();
6771
- }
6772
- })],
7087
+ waypoints
7088
+ }, getObstacles)],
6773
7089
  labelBounds
6774
7090
  };
6775
7091
  } else {
6776
7092
  const srcDir = portSideOf(source, edge.sourcePort) ?? connectionDirection(source, sourceBounds, targetBounds);
6777
7093
  const tgtDir = portSideOf(target, edge.targetPort) ?? connectionDirection(target, targetBounds, sourceBounds);
6778
7094
  pathData = {
6779
- segments: [(engineOptions.edgeRouter ?? bezierRouter)(edge, {
6780
- graph,
6781
- getEntityBounds,
7095
+ segments: [route(edge, `${edge.id}:0`, {
6782
7096
  sourceBounds,
6783
7097
  targetBounds,
6784
7098
  sourceDirection: srcDir,
6785
7099
  targetDirection: tgtDir,
6786
7100
  sourcePoint,
6787
7101
  targetPoint,
6788
- waypoints,
6789
- get obstacles() {
6790
- return getObstacles();
6791
- }
6792
- })],
7102
+ waypoints
7103
+ }, getObstacles)],
6793
7104
  labelBounds: null
6794
7105
  };
6795
7106
  }
@@ -6806,6 +7117,7 @@ function createFlowEngine(store, initialOptions = {}) {
6806
7117
  return pathData;
6807
7118
  };
6808
7119
  for (const edge of [...graph.edges, ...foldedEdgesFor(c).edges]) computeEdgePath(edge);
7120
+ finishRouting();
6809
7121
  if (trackSourceDependencies) {
6810
7122
  edgeSourceDependents = nextEdgeSourceDependents;
6811
7123
  lastCanonicalEdgePaths = paths;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/flow",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "description": "Framework-agnostic flow visualization engine. Builds on @statelyai/graph.",
5
5
  "type": "module",
6
6
  "sideEffects": true,