@statelyai/layout 0.2.0 → 0.3.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/README.md +71 -2
- package/dist/elkjs/index.cjs +3 -2
- package/dist/elkjs/index.d.cts +11 -2
- package/dist/elkjs/index.d.mts +11 -2
- package/dist/elkjs/index.mjs +3 -3
- package/dist/elkjs/main.cjs +2 -2
- package/dist/elkjs/main.d.cts +2 -2
- package/dist/elkjs/main.d.mts +2 -2
- package/dist/elkjs/main.mjs +2 -2
- package/dist/elkjs/worker-api.cjs +1 -1
- package/dist/elkjs/worker-api.d.cts +2 -2
- package/dist/elkjs/worker-api.d.mts +2 -2
- package/dist/elkjs/worker-api.mjs +1 -1
- package/dist/elkjs/worker.cjs +2 -2
- package/dist/elkjs/worker.mjs +2 -2
- package/dist/{elkjs-CFlfkEBz.mjs → elkjs-DaHMISnQ.mjs} +152 -3
- package/dist/{elkjs-BVnDwnBQ.cjs → elkjs-dMghiiWW.cjs} +157 -2
- package/dist/index-BEA_pzeT.d.cts +72 -0
- package/dist/{index-BSH2bloA.d.mts → index-D9dhxrRl.d.cts} +35 -3
- package/dist/index-DNTLRsDl.d.mts +72 -0
- package/dist/{index-CG712jzV.d.cts → index-DNixtE3h.d.mts} +35 -3
- package/dist/index.cjs +36 -9
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +4 -3
- package/dist/layered/index.cjs +1 -1
- package/dist/layered/index.d.cts +3 -2
- package/dist/layered/index.d.mts +3 -2
- package/dist/layered/index.mjs +1 -1
- package/dist/{layered-Cf9Rn8l7.cjs → layered-B2buJqMf.cjs} +417 -469
- package/dist/{layered-Bz2nWmVp.mjs → layered-DGFTeQSl.mjs} +391 -431
- package/dist/{layout-engine-WbC0YjjT.mjs → layout-engine-Cs5tatA6.mjs} +1 -1
- package/dist/{layout-engine-BNex9jxg.cjs → layout-engine-Dn1PiFwP.cjs} +1 -1
- package/dist/routing/index.cjs +28 -0
- package/dist/routing/index.d.cts +3 -0
- package/dist/routing/index.d.mts +3 -0
- package/dist/routing/index.mjs +3 -0
- package/dist/routing-A2hrK9MP.mjs +2396 -0
- package/dist/routing-ujEP7Qh6.cjs +2606 -0
- package/dist/types-CT2akdK0.d.mts +133 -0
- package/dist/types-uxPlGRof.d.cts +133 -0
- package/dist/{worker-client-DAT_z2OR.d.mts → worker-client-BwGGRD5y.d.mts} +1 -1
- package/dist/{worker-client-DVhklF6A.d.cts → worker-client-D4zNyPEI.d.cts} +1 -1
- package/package.json +7 -2
- package/src/authoring/coordinates.ts +10 -2
- package/src/elkjs/index.ts +5 -3
- package/src/elkjs/routes.ts +147 -0
- package/src/index.ts +6 -0
- package/src/layered/compound.ts +417 -0
- package/src/layered/index.ts +27 -102
- package/src/layered/types.ts +21 -0
- package/src/routing/adapters.ts +111 -0
- package/src/routing/algorithms.ts +676 -0
- package/src/routing/coordination.ts +86 -0
- package/src/routing/engine.ts +473 -0
- package/src/routing/index.ts +68 -0
- package/src/routing/layout-cache.ts +65 -0
- package/src/routing/model.ts +218 -0
- package/src/routing/path.ts +324 -0
- package/src/routing/persistent.ts +117 -0
- package/src/routing/search.ts +276 -0
- package/src/routing/spatial.ts +78 -0
- package/src/routing/types.ts +146 -0
- /package/dist/{public-types-B8rAALJq.d.mts → public-types-9NCPoqbp.d.mts} +0 -0
- /package/dist/{public-types-CVB0hXGk.d.cts → public-types-BcRZoJE3.d.cts} +0 -0
- /package/dist/{worker-client-DkwS4sHx.mjs → worker-client-BNjwT1AJ.mjs} +0 -0
- /package/dist/{worker-client-D3HMK33r.cjs → worker-client-D4oEvhAl.cjs} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { EntityRect, Graph, GraphDiff, Point } from "@statelyai/graph";
|
|
2
|
+
|
|
3
|
+
//#region src/routing/types.d.ts
|
|
4
|
+
type RoutePoint = Readonly<Point>;
|
|
5
|
+
type RouteSegment = {
|
|
6
|
+
readonly kind: "line";
|
|
7
|
+
readonly to: RoutePoint;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "quadratic";
|
|
10
|
+
readonly control: RoutePoint;
|
|
11
|
+
readonly to: RoutePoint;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "cubic";
|
|
14
|
+
readonly control1: RoutePoint;
|
|
15
|
+
readonly control2: RoutePoint;
|
|
16
|
+
readonly to: RoutePoint;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "arc";
|
|
19
|
+
readonly rx: number;
|
|
20
|
+
readonly ry: number;
|
|
21
|
+
readonly rotation: number;
|
|
22
|
+
readonly largeArc: boolean;
|
|
23
|
+
readonly sweep: boolean;
|
|
24
|
+
readonly to: RoutePoint;
|
|
25
|
+
};
|
|
26
|
+
interface RoutePath {
|
|
27
|
+
readonly start: RoutePoint;
|
|
28
|
+
readonly segments: readonly RouteSegment[];
|
|
29
|
+
}
|
|
30
|
+
type RouteEndpoint = {
|
|
31
|
+
readonly kind: "node";
|
|
32
|
+
readonly nodeId: string;
|
|
33
|
+
readonly port?: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "label";
|
|
36
|
+
readonly edgeId: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "junction";
|
|
39
|
+
readonly id: string;
|
|
40
|
+
};
|
|
41
|
+
interface RouteSection {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly from: RouteEndpoint;
|
|
44
|
+
readonly to: RouteEndpoint;
|
|
45
|
+
readonly path: RoutePath;
|
|
46
|
+
/** Same ID denotes a shared trunk; render it once. */
|
|
47
|
+
readonly sharedId?: string;
|
|
48
|
+
}
|
|
49
|
+
type RoutingDiagnosticCode = "MISSING_GEOMETRY" | "MISSING_PORT" | "ROUTE_CONFLICT" | "ROUTE_BLOCKED" | "SEARCH_BUDGET" | "CONSTRAINT_VIOLATION";
|
|
50
|
+
interface RoutingDiagnostic {
|
|
51
|
+
readonly code: RoutingDiagnosticCode;
|
|
52
|
+
readonly edgeId: string;
|
|
53
|
+
readonly message: string;
|
|
54
|
+
}
|
|
55
|
+
interface Route {
|
|
56
|
+
readonly edgeId: string;
|
|
57
|
+
readonly sections: readonly RouteSection[];
|
|
58
|
+
readonly status: "routed" | "fallback";
|
|
59
|
+
readonly diagnostics: readonly RoutingDiagnostic[];
|
|
60
|
+
}
|
|
61
|
+
type RoutePatch = {
|
|
62
|
+
readonly op: "set";
|
|
63
|
+
readonly edgeId: string;
|
|
64
|
+
readonly route: Route;
|
|
65
|
+
} | {
|
|
66
|
+
readonly op: "delete";
|
|
67
|
+
readonly edgeId: string;
|
|
68
|
+
};
|
|
69
|
+
type RouteStyle = "straight" | "bezier" | "orthogonal" | "polyline" | "octilinear" | "curved" | "organic" | "parallel" | "self-loop" | "fan" | "bus" | "bundle";
|
|
70
|
+
type RouteSide = "left" | "right" | "top" | "bottom";
|
|
71
|
+
interface RouteAttachment {
|
|
72
|
+
/** Node-local attachment rectangle, independent of its outer obstacle bounds. */
|
|
73
|
+
readonly bounds: RouteBounds;
|
|
74
|
+
readonly facing?: "inward" | "outward";
|
|
75
|
+
}
|
|
76
|
+
interface EdgeRoutingSettings {
|
|
77
|
+
readonly sourceAttachment?: RouteAttachment;
|
|
78
|
+
readonly targetAttachment?: RouteAttachment;
|
|
79
|
+
readonly sourceSide?: RouteSide;
|
|
80
|
+
readonly targetSide?: RouteSide;
|
|
81
|
+
readonly waypoints?: readonly RoutePoint[];
|
|
82
|
+
/** Explicit shared routing group. Native binary edges describe branches of a net. */
|
|
83
|
+
readonly group?: string;
|
|
84
|
+
}
|
|
85
|
+
interface RoutingSettings {
|
|
86
|
+
/** Native compound geometry is parent-relative; adapters may supply resolved world geometry. */
|
|
87
|
+
readonly coordinateSpace?: "parent" | "world";
|
|
88
|
+
readonly clearance?: number;
|
|
89
|
+
readonly radius?: number;
|
|
90
|
+
readonly edgeSpacing?: number;
|
|
91
|
+
readonly bendPenalty?: number;
|
|
92
|
+
/** Soft cost per crossing; finite costs keep detours proportionate. Default 80. */
|
|
93
|
+
readonly crossingPenalty?: number;
|
|
94
|
+
/** Cost per unit of parallel overlap within edgeSpacing. Default 8. */
|
|
95
|
+
readonly overlapPenalty?: number;
|
|
96
|
+
readonly maxSearchNodes?: number;
|
|
97
|
+
readonly organicIterations?: number;
|
|
98
|
+
readonly edges?: Readonly<Record<string, EdgeRoutingSettings>>;
|
|
99
|
+
}
|
|
100
|
+
interface RoutingMetrics {
|
|
101
|
+
readonly routedEdges: number;
|
|
102
|
+
readonly reusedEdges: number;
|
|
103
|
+
readonly affectedEdges: number;
|
|
104
|
+
readonly searchNodes: number;
|
|
105
|
+
readonly obstacleCandidates: number;
|
|
106
|
+
}
|
|
107
|
+
/** Immutable value. Retain it per canvas; the private state uses structural sharing. */
|
|
108
|
+
interface RoutingSnapshot {
|
|
109
|
+
readonly strategy: string;
|
|
110
|
+
readonly revision: number;
|
|
111
|
+
readonly routes: ReadonlyMap<string, Route>;
|
|
112
|
+
readonly metrics: RoutingMetrics;
|
|
113
|
+
}
|
|
114
|
+
interface RoutingUpdate {
|
|
115
|
+
readonly snapshot: RoutingSnapshot;
|
|
116
|
+
readonly patches: readonly RoutePatch[];
|
|
117
|
+
/** Compare identity before accepting an asynchronous result. */
|
|
118
|
+
readonly base: RoutingSnapshot;
|
|
119
|
+
}
|
|
120
|
+
type RoutingGraph = Graph<unknown, unknown, unknown, unknown>;
|
|
121
|
+
interface RoutingStrategy {
|
|
122
|
+
readonly id: string;
|
|
123
|
+
route(graph: RoutingGraph, settings?: RoutingSettings): RoutingSnapshot | Promise<RoutingSnapshot>;
|
|
124
|
+
update(graph: RoutingGraph, previous: RoutingSnapshot, diff: GraphDiff<unknown, unknown>, settings?: RoutingSettings): RoutingUpdate | Promise<RoutingUpdate>;
|
|
125
|
+
}
|
|
126
|
+
interface NativeRoutingStrategy extends RoutingStrategy {
|
|
127
|
+
readonly id: RouteStyle;
|
|
128
|
+
route(graph: RoutingGraph, settings?: RoutingSettings): RoutingSnapshot;
|
|
129
|
+
update(graph: RoutingGraph, previous: RoutingSnapshot, diff: GraphDiff<unknown, unknown>, settings?: RoutingSettings): RoutingUpdate;
|
|
130
|
+
}
|
|
131
|
+
type RouteBounds = Readonly<EntityRect>;
|
|
132
|
+
//#endregion
|
|
133
|
+
export { RoutingMetrics as _, RouteBounds as a, RoutingStrategy as b, RoutePath as c, RouteSegment as d, RouteSide as f, RoutingGraph as g, RoutingDiagnosticCode as h, RouteAttachment as i, RoutePoint as l, RoutingDiagnostic as m, NativeRoutingStrategy as n, RouteEndpoint as o, RouteStyle as p, Route as r, RoutePatch as s, EdgeRoutingSettings as t, RouteSection as u, RoutingSettings as v, RoutingUpdate as x, RoutingSnapshot as y };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { EntityRect, Graph, GraphDiff, Point } from "@statelyai/graph";
|
|
2
|
+
|
|
3
|
+
//#region src/routing/types.d.ts
|
|
4
|
+
type RoutePoint = Readonly<Point>;
|
|
5
|
+
type RouteSegment = {
|
|
6
|
+
readonly kind: "line";
|
|
7
|
+
readonly to: RoutePoint;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "quadratic";
|
|
10
|
+
readonly control: RoutePoint;
|
|
11
|
+
readonly to: RoutePoint;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "cubic";
|
|
14
|
+
readonly control1: RoutePoint;
|
|
15
|
+
readonly control2: RoutePoint;
|
|
16
|
+
readonly to: RoutePoint;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "arc";
|
|
19
|
+
readonly rx: number;
|
|
20
|
+
readonly ry: number;
|
|
21
|
+
readonly rotation: number;
|
|
22
|
+
readonly largeArc: boolean;
|
|
23
|
+
readonly sweep: boolean;
|
|
24
|
+
readonly to: RoutePoint;
|
|
25
|
+
};
|
|
26
|
+
interface RoutePath {
|
|
27
|
+
readonly start: RoutePoint;
|
|
28
|
+
readonly segments: readonly RouteSegment[];
|
|
29
|
+
}
|
|
30
|
+
type RouteEndpoint = {
|
|
31
|
+
readonly kind: "node";
|
|
32
|
+
readonly nodeId: string;
|
|
33
|
+
readonly port?: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "label";
|
|
36
|
+
readonly edgeId: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "junction";
|
|
39
|
+
readonly id: string;
|
|
40
|
+
};
|
|
41
|
+
interface RouteSection {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly from: RouteEndpoint;
|
|
44
|
+
readonly to: RouteEndpoint;
|
|
45
|
+
readonly path: RoutePath;
|
|
46
|
+
/** Same ID denotes a shared trunk; render it once. */
|
|
47
|
+
readonly sharedId?: string;
|
|
48
|
+
}
|
|
49
|
+
type RoutingDiagnosticCode = "MISSING_GEOMETRY" | "MISSING_PORT" | "ROUTE_CONFLICT" | "ROUTE_BLOCKED" | "SEARCH_BUDGET" | "CONSTRAINT_VIOLATION";
|
|
50
|
+
interface RoutingDiagnostic {
|
|
51
|
+
readonly code: RoutingDiagnosticCode;
|
|
52
|
+
readonly edgeId: string;
|
|
53
|
+
readonly message: string;
|
|
54
|
+
}
|
|
55
|
+
interface Route {
|
|
56
|
+
readonly edgeId: string;
|
|
57
|
+
readonly sections: readonly RouteSection[];
|
|
58
|
+
readonly status: "routed" | "fallback";
|
|
59
|
+
readonly diagnostics: readonly RoutingDiagnostic[];
|
|
60
|
+
}
|
|
61
|
+
type RoutePatch = {
|
|
62
|
+
readonly op: "set";
|
|
63
|
+
readonly edgeId: string;
|
|
64
|
+
readonly route: Route;
|
|
65
|
+
} | {
|
|
66
|
+
readonly op: "delete";
|
|
67
|
+
readonly edgeId: string;
|
|
68
|
+
};
|
|
69
|
+
type RouteStyle = "straight" | "bezier" | "orthogonal" | "polyline" | "octilinear" | "curved" | "organic" | "parallel" | "self-loop" | "fan" | "bus" | "bundle";
|
|
70
|
+
type RouteSide = "left" | "right" | "top" | "bottom";
|
|
71
|
+
interface RouteAttachment {
|
|
72
|
+
/** Node-local attachment rectangle, independent of its outer obstacle bounds. */
|
|
73
|
+
readonly bounds: RouteBounds;
|
|
74
|
+
readonly facing?: "inward" | "outward";
|
|
75
|
+
}
|
|
76
|
+
interface EdgeRoutingSettings {
|
|
77
|
+
readonly sourceAttachment?: RouteAttachment;
|
|
78
|
+
readonly targetAttachment?: RouteAttachment;
|
|
79
|
+
readonly sourceSide?: RouteSide;
|
|
80
|
+
readonly targetSide?: RouteSide;
|
|
81
|
+
readonly waypoints?: readonly RoutePoint[];
|
|
82
|
+
/** Explicit shared routing group. Native binary edges describe branches of a net. */
|
|
83
|
+
readonly group?: string;
|
|
84
|
+
}
|
|
85
|
+
interface RoutingSettings {
|
|
86
|
+
/** Native compound geometry is parent-relative; adapters may supply resolved world geometry. */
|
|
87
|
+
readonly coordinateSpace?: "parent" | "world";
|
|
88
|
+
readonly clearance?: number;
|
|
89
|
+
readonly radius?: number;
|
|
90
|
+
readonly edgeSpacing?: number;
|
|
91
|
+
readonly bendPenalty?: number;
|
|
92
|
+
/** Soft cost per crossing; finite costs keep detours proportionate. Default 80. */
|
|
93
|
+
readonly crossingPenalty?: number;
|
|
94
|
+
/** Cost per unit of parallel overlap within edgeSpacing. Default 8. */
|
|
95
|
+
readonly overlapPenalty?: number;
|
|
96
|
+
readonly maxSearchNodes?: number;
|
|
97
|
+
readonly organicIterations?: number;
|
|
98
|
+
readonly edges?: Readonly<Record<string, EdgeRoutingSettings>>;
|
|
99
|
+
}
|
|
100
|
+
interface RoutingMetrics {
|
|
101
|
+
readonly routedEdges: number;
|
|
102
|
+
readonly reusedEdges: number;
|
|
103
|
+
readonly affectedEdges: number;
|
|
104
|
+
readonly searchNodes: number;
|
|
105
|
+
readonly obstacleCandidates: number;
|
|
106
|
+
}
|
|
107
|
+
/** Immutable value. Retain it per canvas; the private state uses structural sharing. */
|
|
108
|
+
interface RoutingSnapshot {
|
|
109
|
+
readonly strategy: string;
|
|
110
|
+
readonly revision: number;
|
|
111
|
+
readonly routes: ReadonlyMap<string, Route>;
|
|
112
|
+
readonly metrics: RoutingMetrics;
|
|
113
|
+
}
|
|
114
|
+
interface RoutingUpdate {
|
|
115
|
+
readonly snapshot: RoutingSnapshot;
|
|
116
|
+
readonly patches: readonly RoutePatch[];
|
|
117
|
+
/** Compare identity before accepting an asynchronous result. */
|
|
118
|
+
readonly base: RoutingSnapshot;
|
|
119
|
+
}
|
|
120
|
+
type RoutingGraph = Graph<unknown, unknown, unknown, unknown>;
|
|
121
|
+
interface RoutingStrategy {
|
|
122
|
+
readonly id: string;
|
|
123
|
+
route(graph: RoutingGraph, settings?: RoutingSettings): RoutingSnapshot | Promise<RoutingSnapshot>;
|
|
124
|
+
update(graph: RoutingGraph, previous: RoutingSnapshot, diff: GraphDiff<unknown, unknown>, settings?: RoutingSettings): RoutingUpdate | Promise<RoutingUpdate>;
|
|
125
|
+
}
|
|
126
|
+
interface NativeRoutingStrategy extends RoutingStrategy {
|
|
127
|
+
readonly id: RouteStyle;
|
|
128
|
+
route(graph: RoutingGraph, settings?: RoutingSettings): RoutingSnapshot;
|
|
129
|
+
update(graph: RoutingGraph, previous: RoutingSnapshot, diff: GraphDiff<unknown, unknown>, settings?: RoutingSettings): RoutingUpdate;
|
|
130
|
+
}
|
|
131
|
+
type RouteBounds = Readonly<EntityRect>;
|
|
132
|
+
//#endregion
|
|
133
|
+
export { RoutingMetrics as _, RouteBounds as a, RoutingStrategy as b, RoutePath as c, RouteSegment as d, RouteSide as f, RoutingGraph as g, RoutingDiagnosticCode as h, RouteAttachment as i, RoutePoint as l, RoutingDiagnostic as m, NativeRoutingStrategy as n, RouteEndpoint as o, RouteStyle as p, Route as r, RoutePatch as s, EdgeRoutingSettings as t, RouteSection as u, RoutingSettings as v, RoutingUpdate as x, RoutingSnapshot as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as ElkLayoutCategoryDescription, f as ElkLayoutOptionDescription, l as ElkLayoutAlgorithmDescription, n as ELKConstructorArguments, p as ElkNode, t as ELK, u as ElkLayoutArguments, v as LaidOutElkNode } from "./public-types-
|
|
1
|
+
import { d as ElkLayoutCategoryDescription, f as ElkLayoutOptionDescription, l as ElkLayoutAlgorithmDescription, n as ELKConstructorArguments, p as ElkNode, t as ELK, u as ElkLayoutArguments, v as LaidOutElkNode } from "./public-types-9NCPoqbp.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/elkjs/worker-client.d.ts
|
|
4
4
|
declare class WorkerELK implements ELK {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as ElkLayoutCategoryDescription, f as ElkLayoutOptionDescription, l as ElkLayoutAlgorithmDescription, n as ELKConstructorArguments, p as ElkNode, t as ELK, u as ElkLayoutArguments, v as LaidOutElkNode } from "./public-types-
|
|
1
|
+
import { d as ElkLayoutCategoryDescription, f as ElkLayoutOptionDescription, l as ElkLayoutAlgorithmDescription, n as ELKConstructorArguments, p as ElkNode, t as ELK, u as ElkLayoutArguments, v as LaidOutElkNode } from "./public-types-BcRZoJE3.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/elkjs/worker-client.d.ts
|
|
4
4
|
declare class WorkerELK implements ELK {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/layout",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Extensible, graph-native layout algorithms for @statelyai/graph",
|
|
5
5
|
"license": "EPL-2.0 OR GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -59,7 +59,12 @@
|
|
|
59
59
|
"import": "./dist/layered/index.mjs",
|
|
60
60
|
"require": "./dist/layered/index.cjs"
|
|
61
61
|
},
|
|
62
|
-
"./package.json": "./package.json"
|
|
62
|
+
"./package.json": "./package.json",
|
|
63
|
+
"./routing": {
|
|
64
|
+
"types": "./src/routing/index.ts",
|
|
65
|
+
"import": "./dist/routing/index.mjs",
|
|
66
|
+
"require": "./dist/routing/index.cjs"
|
|
67
|
+
}
|
|
63
68
|
},
|
|
64
69
|
"publishConfig": {
|
|
65
70
|
"access": "public"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LayoutError } from "../errors";
|
|
2
2
|
import type { VisualGraph, Point } from "@statelyai/graph";
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** Legacy sibling edges are parent-relative; native compound output marks world-space edges. */
|
|
5
5
|
function frames<N, E, G, P>(graph: VisualGraph<N, E, G, P>) {
|
|
6
6
|
const nodes = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
7
7
|
const offsets = new Map<string, Point>();
|
|
@@ -33,6 +33,7 @@ function frames<N, E, G, P>(graph: VisualGraph<N, E, G, P>) {
|
|
|
33
33
|
const target = nodes.get(edge.targetId)!;
|
|
34
34
|
return [
|
|
35
35
|
edge.id,
|
|
36
|
+
(graph as VisualGraph & { edgeCoordinateSpace?: string }).edgeCoordinateSpace !== "world" &&
|
|
36
37
|
(source.parentId ?? null) === (target.parentId ?? null)
|
|
37
38
|
? offset(source.id)
|
|
38
39
|
: { x: 0, y: 0 },
|
|
@@ -44,8 +45,15 @@ function frames<N, E, G, P>(graph: VisualGraph<N, E, G, P>) {
|
|
|
44
45
|
|
|
45
46
|
export function worldGeometry<N, E, G, P>(graph: VisualGraph<N, E, G, P>): VisualGraph<N, E, G, P> {
|
|
46
47
|
const offsets = frames(graph);
|
|
48
|
+
const base = { ...graph } as VisualGraph<N, E, G, P> & {
|
|
49
|
+
compoundRoutes?: unknown;
|
|
50
|
+
compoundGeometry?: unknown;
|
|
51
|
+
};
|
|
52
|
+
// Authoring may change nodes, labels, or paths. Never carry derived full-layout caches.
|
|
53
|
+
delete base.compoundRoutes;
|
|
54
|
+
delete base.compoundGeometry;
|
|
47
55
|
return {
|
|
48
|
-
...
|
|
56
|
+
...base,
|
|
49
57
|
nodes: graph.nodes.map((n) => {
|
|
50
58
|
const p = offsets.nodes.get(n.id)!;
|
|
51
59
|
return p.x === 0 && p.y === 0 ? n : { ...n, x: n.x + p.x, y: n.y + p.y };
|
package/src/elkjs/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { createGraph, type Graph } from "@statelyai/graph";
|
|
2
|
-
import type { getLayeredLayout } from "../layered";
|
|
1
|
+
import { createGraph, type Graph, type VisualGraph } from "@statelyai/graph";
|
|
3
2
|
import {
|
|
4
3
|
elkLayeredOptionDefinitions,
|
|
5
4
|
type ElkLayeredOptionValueByName,
|
|
@@ -1388,7 +1387,7 @@ function toSection(edge: ElkEdge, points: readonly ElkPoint[]) {
|
|
|
1388
1387
|
|
|
1389
1388
|
function applyLayout(
|
|
1390
1389
|
root: ElkNode,
|
|
1391
|
-
graph:
|
|
1390
|
+
graph: VisualGraph,
|
|
1392
1391
|
padding: { top: number; right: number; bottom: number; left: number },
|
|
1393
1392
|
layoutOptions: Readonly<Record<string, unknown>>,
|
|
1394
1393
|
resultPolicy?: Elkjs0111ResultPolicy,
|
|
@@ -1901,3 +1900,6 @@ export type {
|
|
|
1901
1900
|
StatechartLayoutScore,
|
|
1902
1901
|
StatechartLayoutPlan,
|
|
1903
1902
|
} from "./statechart";
|
|
1903
|
+
|
|
1904
|
+
export { getElkRoutes } from "./routes";
|
|
1905
|
+
export type { ElkRouteOptions } from "./routes";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ElkExtendedEdge, ElkNode, ElkPoint } from "./public-types";
|
|
2
|
+
import { pathFromPoints } from "../routing/path";
|
|
3
|
+
import { pathFromSplinePoints } from "../routing/adapters";
|
|
4
|
+
import { freeze } from "../routing/model";
|
|
5
|
+
import type { Route, RouteEndpoint, RoutePath, RoutePoint, RouteSection } from "../routing/types";
|
|
6
|
+
|
|
7
|
+
export interface ElkRouteOptions {
|
|
8
|
+
/** ELK stores spline controls in bendPoints; the caller must identify that encoding. */
|
|
9
|
+
routing?: "ORTHOGONAL" | "POLYLINE" | "SPLINES";
|
|
10
|
+
}
|
|
11
|
+
/** Normalize any ELK layout's section geometry, preserving ports and hyperedge junctions. */
|
|
12
|
+
export function getElkRoutes(
|
|
13
|
+
graph: ElkNode,
|
|
14
|
+
options: ElkRouteOptions = {},
|
|
15
|
+
): ReadonlyMap<string, Route> {
|
|
16
|
+
const shapes = new Map<string, { ref: RouteEndpoint; center: RoutePoint }>(),
|
|
17
|
+
frames = new Map<string, RoutePoint>();
|
|
18
|
+
const edges: { edge: ElkExtendedEdge; offset: RoutePoint; routing: string }[] = [];
|
|
19
|
+
function visit(node: ElkNode, offset: RoutePoint, inherited: string) {
|
|
20
|
+
const position = { x: offset.x + (node.x ?? 0), y: offset.y + (node.y ?? 0) };
|
|
21
|
+
const routing =
|
|
22
|
+
node.layoutOptions?.["elk.edgeRouting"] ??
|
|
23
|
+
node.layoutOptions?.["org.eclipse.elk.edgeRouting"] ??
|
|
24
|
+
inherited;
|
|
25
|
+
frames.set(node.id, position);
|
|
26
|
+
shapes.set(node.id, {
|
|
27
|
+
ref: { kind: "node", nodeId: node.id },
|
|
28
|
+
center: { x: position.x + (node.width ?? 0) / 2, y: position.y + (node.height ?? 0) / 2 },
|
|
29
|
+
});
|
|
30
|
+
for (const port of node.ports ?? [])
|
|
31
|
+
shapes.set(port.id, {
|
|
32
|
+
ref: { kind: "node", nodeId: node.id, port: port.id },
|
|
33
|
+
center: {
|
|
34
|
+
x: position.x + (port.x ?? 0) + (port.width ?? 0) / 2,
|
|
35
|
+
y: position.y + (port.y ?? 0) + (port.height ?? 0) / 2,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
for (const edge of node.edges ?? [])
|
|
39
|
+
edges.push({
|
|
40
|
+
edge,
|
|
41
|
+
offset: position,
|
|
42
|
+
routing:
|
|
43
|
+
edge.layoutOptions?.["elk.edgeRouting"] ??
|
|
44
|
+
edge.layoutOptions?.["org.eclipse.elk.edgeRouting"] ??
|
|
45
|
+
routing,
|
|
46
|
+
});
|
|
47
|
+
for (const child of node.children ?? []) visit(child, position, routing);
|
|
48
|
+
}
|
|
49
|
+
visit(graph, { x: 0, y: 0 }, options.routing ?? "POLYLINE");
|
|
50
|
+
const result = new Map<string, Route>();
|
|
51
|
+
for (const { edge, offset: inheritedOffset, routing } of edges) {
|
|
52
|
+
const offset = edge.container
|
|
53
|
+
? (frames.get(edge.container) ?? inheritedOffset)
|
|
54
|
+
: inheritedOffset;
|
|
55
|
+
const point = (p: ElkPoint): RoutePoint => ({ x: p.x + offset.x, y: p.y + offset.y });
|
|
56
|
+
// Join section endpoints by topology, never by equal coordinates alone.
|
|
57
|
+
const parents = new Map<string, string>();
|
|
58
|
+
const root = (key: string): string => {
|
|
59
|
+
let current = key;
|
|
60
|
+
while (parents.has(current)) current = parents.get(current)!;
|
|
61
|
+
return current;
|
|
62
|
+
};
|
|
63
|
+
const join = (a: string, b: string) => {
|
|
64
|
+
const x = root(a),
|
|
65
|
+
y = root(b);
|
|
66
|
+
if (x !== y) parents.set(x < y ? y : x, x < y ? x : y);
|
|
67
|
+
};
|
|
68
|
+
for (const section of edge.sections ?? []) {
|
|
69
|
+
for (const id of section.outgoingSections ?? []) join(`${section.id}:end`, `${id}:start`);
|
|
70
|
+
for (const id of section.incomingSections ?? []) join(`${id}:end`, `${section.id}:start`);
|
|
71
|
+
}
|
|
72
|
+
const sections: RouteSection[] = [];
|
|
73
|
+
let malformed = false;
|
|
74
|
+
for (const section of edge.sections ?? []) {
|
|
75
|
+
const points = [section.startPoint, ...(section.bendPoints ?? []), section.endPoint].map(
|
|
76
|
+
point,
|
|
77
|
+
);
|
|
78
|
+
let path: RoutePath;
|
|
79
|
+
if (points.some((p) => !Number.isFinite(p.x) || !Number.isFinite(p.y))) {
|
|
80
|
+
malformed = true;
|
|
81
|
+
for (let i = 0; i < points.length; i++)
|
|
82
|
+
if (!Number.isFinite(points[i]!.x) || !Number.isFinite(points[i]!.y))
|
|
83
|
+
points[i] = { x: offset.x + i * 20, y: offset.y };
|
|
84
|
+
}
|
|
85
|
+
if (routing === "SPLINES") {
|
|
86
|
+
if ((points.length - 1) % 3 || points.length < 4) {
|
|
87
|
+
malformed = true;
|
|
88
|
+
path = pathFromPoints([points[0]!, points.at(-1)!]);
|
|
89
|
+
} else path = pathFromSplinePoints(points);
|
|
90
|
+
} else path = pathFromPoints(points);
|
|
91
|
+
const fromShape =
|
|
92
|
+
section.incomingShape ??
|
|
93
|
+
(!section.incomingSections?.length && edge.sources.length === 1
|
|
94
|
+
? edge.sources[0]
|
|
95
|
+
: undefined);
|
|
96
|
+
const toShape =
|
|
97
|
+
section.outgoingShape ??
|
|
98
|
+
(!section.outgoingSections?.length && edge.targets.length === 1
|
|
99
|
+
? edge.targets[0]
|
|
100
|
+
: undefined);
|
|
101
|
+
sections.push({
|
|
102
|
+
id: section.id,
|
|
103
|
+
from: fromShape
|
|
104
|
+
? (shapes.get(fromShape)?.ref ?? { kind: "node", nodeId: fromShape })
|
|
105
|
+
: { kind: "junction", id: `${edge.id}:${root(`${section.id}:start`)}` },
|
|
106
|
+
to: toShape
|
|
107
|
+
? (shapes.get(toShape)?.ref ?? { kind: "node", nodeId: toShape })
|
|
108
|
+
: { kind: "junction", id: `${edge.id}:${root(`${section.id}:end`)}` },
|
|
109
|
+
path,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (!sections.length) {
|
|
113
|
+
malformed = true;
|
|
114
|
+
const source = shapes.get(edge.sources[0] ?? ""),
|
|
115
|
+
origin = source?.center ?? { x: 0, y: 0 };
|
|
116
|
+
const targets = [...edge.targets, ...edge.sources.slice(1)];
|
|
117
|
+
for (const [i, id] of (targets.length ? targets : [""]).entries()) {
|
|
118
|
+
const target = shapes.get(id);
|
|
119
|
+
sections.push({
|
|
120
|
+
id: `${edge.id}:fallback:${i}`,
|
|
121
|
+
from: source?.ref ?? { kind: "node", nodeId: edge.sources[0] ?? "" },
|
|
122
|
+
to: target?.ref ?? { kind: "node", nodeId: id },
|
|
123
|
+
path: pathFromPoints([origin, target?.center ?? { x: origin.x + 40, y: origin.y + 40 }]),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
result.set(
|
|
128
|
+
edge.id,
|
|
129
|
+
freeze({
|
|
130
|
+
edgeId: edge.id,
|
|
131
|
+
sections,
|
|
132
|
+
status: malformed ? "fallback" : "routed",
|
|
133
|
+
diagnostics: malformed
|
|
134
|
+
? [
|
|
135
|
+
{
|
|
136
|
+
code: "MISSING_GEOMETRY",
|
|
137
|
+
edgeId: edge.id,
|
|
138
|
+
message:
|
|
139
|
+
"ELK sections contain missing or invalid geometry; rendered fallback paths",
|
|
140
|
+
},
|
|
141
|
+
]
|
|
142
|
+
: [],
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -71,6 +71,10 @@ export type {
|
|
|
71
71
|
EdgeRoutes,
|
|
72
72
|
LayerAssigner,
|
|
73
73
|
LayerAssignment,
|
|
74
|
+
CompoundVisualGraph,
|
|
75
|
+
CompoundLayoutOptions,
|
|
76
|
+
CompoundLayoutGeometry,
|
|
77
|
+
CompoundEdgeAttachment,
|
|
74
78
|
LayeredLayoutOptions,
|
|
75
79
|
LayeredAdvancedOptions,
|
|
76
80
|
ElkLayeredOptionId,
|
|
@@ -103,3 +107,5 @@ export type {
|
|
|
103
107
|
LinearConstraint,
|
|
104
108
|
WaypointConstraint,
|
|
105
109
|
} from "./constraints";
|
|
110
|
+
|
|
111
|
+
export * from "./routing";
|