@floegence/floe-webapp-core 0.86.7 → 0.86.10
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/components/graph/layout.js +115 -85
- package/dist/components/graph/packing.js +141 -58
- package/dist/components/graph/positions.js +29 -29
- package/dist/components/graph/routing.js +238 -129
- package/dist/components/graph/types.d.ts +4 -2
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -1,165 +1,274 @@
|
|
|
1
|
-
import { AvoidLib as
|
|
2
|
-
import
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
async function
|
|
6
|
-
if (!
|
|
7
|
-
if (!
|
|
8
|
-
await (
|
|
9
|
-
throw
|
|
1
|
+
import { AvoidLib as G } from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/index.js";
|
|
2
|
+
import V from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/libavoid.wasm.js";
|
|
3
|
+
let J;
|
|
4
|
+
const j = { NORTH: 1, SOUTH: 2, WEST: 4, EAST: 8 }, N = ["NORTH", "EAST", "SOUTH", "WEST"], O = (n) => n.delete();
|
|
5
|
+
async function $(n) {
|
|
6
|
+
if (!n.nodes.length) return n;
|
|
7
|
+
if (!n.edges.length) return F(n);
|
|
8
|
+
await (J ??= G.load(V).catch((y) => {
|
|
9
|
+
throw J = void 0, y;
|
|
10
10
|
}));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
for (let
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
},
|
|
17
|
-
for (const
|
|
18
|
-
const
|
|
19
|
-
|
|
11
|
+
const s = G.getInstance(), r = new Map(n.nodes.map((y) => [y.id, y])), p = (y) => {
|
|
12
|
+
const m = [];
|
|
13
|
+
for (let i = r.get(y).parentId; i; i = r.get(i).parentId)
|
|
14
|
+
m.push(i);
|
|
15
|
+
return m;
|
|
16
|
+
}, x = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const y of n.edges) {
|
|
18
|
+
const m = /* @__PURE__ */ new Set([...p(y.source), ...p(y.target)]), i = JSON.stringify([...m].sort()), e = x.get(i) ?? { open: m, edges: [] };
|
|
19
|
+
e.edges.push(y), x.set(i, e);
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
for (const { open:
|
|
23
|
-
const
|
|
21
|
+
const T = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const { open: y, edges: m } of x.values()) {
|
|
23
|
+
const i = new s.Router(2);
|
|
24
24
|
try {
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return
|
|
25
|
+
i.setRoutingParameter(s.RoutingParameter.shapeBufferDistance, 4), i.setRoutingParameter(s.RoutingParameter.idealNudgingDistance, 8), i.setRoutingParameter(s.RoutingParameter.crossingPenalty, 80), i.setRoutingParameter(s.RoutingParameter.fixedSharedPathPenalty, 120), i.setRoutingParameter(s.RoutingParameter.portDirectionPenalty, 0), i.setRoutingOption(s.RoutingOption.nudgeOrthogonalSegmentsConnectedToShapes, !1), i.setRoutingOption(s.RoutingOption.nudgeSharedPathsWithCommonEndPoint, !0);
|
|
26
|
+
const e = new Map(
|
|
27
|
+
n.nodes.filter((t) => !y.has(t.id) && p(t.id).every((o) => y.has(o))).map((t) => {
|
|
28
|
+
const o = new s.Point(t.x, t.y), g = new s.Point(t.x + t.width, t.y + t.height), a = new s.Rectangle(o, g), h = new s.ShapeRef(i, a);
|
|
29
|
+
return O(o), O(g), O(a), [t.id, h];
|
|
30
30
|
})
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const r =
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
31
|
+
), c = /* @__PURE__ */ new Map(), S = n.nodes.filter((t) => e.has(t.id)), E = /* @__PURE__ */ new Map();
|
|
32
|
+
m.forEach((t) => {
|
|
33
|
+
const o = r.get(t.source), g = r.get(t.target), a = Y(o, g), h = t.sourcePort ? o.ports.find((P) => P.id === t.sourcePort).side : t.targetPort ? B(g.ports.find((P) => P.id === t.targetPort).side) : a.source, u = t.targetPort ? g.ports.find((P) => P.id === t.targetPort).side : t.sourcePort ? B(o.ports.find((P) => P.id === t.sourcePort).side) : a.target, d = [t.source, t.target].sort().join("\0"), f = E.get(d) ?? 0;
|
|
34
|
+
E.set(d, f + 1);
|
|
35
|
+
const M = f % 2 === 0 ? -6 : 6, R = t.source === t.target ? void 0 : X(
|
|
36
|
+
o,
|
|
37
|
+
g,
|
|
38
|
+
S,
|
|
39
|
+
a,
|
|
40
|
+
M,
|
|
41
|
+
t.sourcePort ? h : void 0,
|
|
42
|
+
t.targetPort ? u : void 0
|
|
37
43
|
);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
])
|
|
56
|
-
];
|
|
57
|
-
}, u = o(
|
|
58
|
-
t.width,
|
|
59
|
-
c.map((e) => h(t.x, t.width, e.x, e.width) - t.x)
|
|
60
|
-
), w = o(
|
|
61
|
-
t.height,
|
|
62
|
-
c.map((e) => h(t.y, t.height, e.y, e.height) - t.y)
|
|
63
|
-
), l = (t.ports ?? []).map((e) => E(t, e.side)), P = y.some((e) => e.source === t.id && e.target === t.id), C = [
|
|
64
|
-
...l,
|
|
65
|
-
...P ? [
|
|
66
|
-
{ x: t.x + t.width, y: t.y + t.height / 3 },
|
|
67
|
-
{ x: t.x + t.width, y: t.y + t.height * 2 / 3 }
|
|
68
|
-
] : []
|
|
69
|
-
], b = (e, f, p, M, T) => {
|
|
70
|
-
const R = new n.ShapeConnectionPin(
|
|
71
|
-
r,
|
|
72
|
-
e,
|
|
73
|
-
f / t.width,
|
|
74
|
-
p / t.height,
|
|
44
|
+
c.set(t.id, {
|
|
45
|
+
sourceSide: R?.source ?? h,
|
|
46
|
+
targetSide: R?.target ?? u,
|
|
47
|
+
offset: M
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
let l = N.length + 2;
|
|
51
|
+
const A = /* @__PURE__ */ new Map(), C = (t, o) => Math.max(0, Math.min(1, t / o));
|
|
52
|
+
for (const t of n.nodes) {
|
|
53
|
+
const o = e.get(t.id);
|
|
54
|
+
if (!o) continue;
|
|
55
|
+
const g = (a, h, u, d, f) => {
|
|
56
|
+
const M = new s.ShapeConnectionPin(
|
|
57
|
+
o,
|
|
58
|
+
a,
|
|
59
|
+
C(h, t.width),
|
|
60
|
+
C(u, t.height),
|
|
75
61
|
!0,
|
|
76
62
|
0,
|
|
77
|
-
|
|
63
|
+
d
|
|
78
64
|
);
|
|
79
|
-
|
|
80
|
-
t.width / 2 + t.height / 2 - Math.abs(
|
|
65
|
+
M.setExclusive(f), M.setConnectionCost(
|
|
66
|
+
t.width / 2 + t.height / 2 - Math.abs(h - t.width / 2) - Math.abs(u - t.height / 2)
|
|
81
67
|
);
|
|
82
|
-
}, d = (e, f, p) => {
|
|
83
|
-
C.some((M) => M.x === t.x + e && M.y === t.y + f) || b(1, e, f, p, !0);
|
|
84
68
|
};
|
|
85
|
-
for (const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
for (const a of new Set(t.ports?.map((h) => h.side))) {
|
|
70
|
+
const { x: h, y: u } = U(t, a), d = N.indexOf(a) + 2;
|
|
71
|
+
g(d, h - t.x, u - t.y, j[a], !1), A.set(
|
|
72
|
+
JSON.stringify([
|
|
73
|
+
t.id,
|
|
74
|
+
C(h - t.x, t.width),
|
|
75
|
+
C(u - t.y, t.height),
|
|
76
|
+
a
|
|
77
|
+
]),
|
|
78
|
+
d
|
|
79
|
+
);
|
|
92
80
|
}
|
|
93
|
-
P && (b(6, t.width, t.height / 3, 8, !1), b(7, t.width, t.height * 2 / 3, 8, !1));
|
|
94
81
|
}
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
if (u)
|
|
98
|
-
return new
|
|
82
|
+
const H = (t, o, g, a) => {
|
|
83
|
+
const h = r.get(t), u = e.get(t);
|
|
84
|
+
if (u && o)
|
|
85
|
+
return new s.ConnEnd(
|
|
99
86
|
u,
|
|
100
|
-
|
|
87
|
+
N.indexOf(h.ports.find((R) => R.id === o).side) + 2
|
|
101
88
|
);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
89
|
+
if (u) {
|
|
90
|
+
const R = C(g.x - h.x, h.width), P = C(g.y - h.y, h.height), b = JSON.stringify([t, R, P, a]), D = A.get(b);
|
|
91
|
+
if (D !== void 0) return new s.ConnEnd(u, D);
|
|
92
|
+
const k = l++;
|
|
93
|
+
return A.set(b, k), new s.ShapeConnectionPin(
|
|
94
|
+
u,
|
|
95
|
+
k,
|
|
96
|
+
R,
|
|
97
|
+
P,
|
|
98
|
+
!0,
|
|
99
|
+
0,
|
|
100
|
+
j[a]
|
|
101
|
+
).setExclusive(!1), new s.ConnEnd(u, k);
|
|
102
|
+
}
|
|
103
|
+
const d = o ? U(h, h.ports.find((R) => R.id === o).side) : g, f = new s.Point(d.x, d.y), M = new s.ConnEnd(f);
|
|
104
|
+
return O(f), M;
|
|
105
|
+
}, v = m.map((t) => {
|
|
106
|
+
const o = r.get(t.source), g = r.get(t.target), a = c.get(t.id), h = H(
|
|
107
|
+
t.source,
|
|
108
|
+
t.sourcePort,
|
|
109
|
+
t.source === t.target ? { x: o.x + o.width, y: o.y + o.height / 3 } : W(o, a.sourceSide, g, a.offset),
|
|
110
|
+
t.source === t.target ? "EAST" : a.sourceSide
|
|
111
|
+
), u = H(
|
|
112
|
+
t.target,
|
|
113
|
+
t.targetPort,
|
|
114
|
+
t.source === t.target ? {
|
|
115
|
+
x: g.x + g.width,
|
|
116
|
+
y: g.y + g.height * 2 / 3
|
|
117
|
+
} : W(g, a.targetSide, o, a.offset),
|
|
118
|
+
t.source === t.target ? "EAST" : a.targetSide
|
|
119
|
+
), d = new s.ConnRef(i, h, u);
|
|
120
|
+
if (O(h), O(u), t.source === t.target) {
|
|
121
|
+
const f = r.get(t.source), M = new s.CheckpointVector();
|
|
122
|
+
for (const R of [f.y + f.height / 3, f.y + f.height * 2 / 3]) {
|
|
123
|
+
const P = new s.Point(f.x + f.width + 24, R), b = new s.Checkpoint(P);
|
|
124
|
+
M.push_back(b), O(P), O(b);
|
|
113
125
|
}
|
|
114
|
-
|
|
126
|
+
d.setRoutingCheckpoints(M), O(M);
|
|
115
127
|
}
|
|
116
|
-
return { edge: t, connection:
|
|
128
|
+
return { edge: t, connection: d };
|
|
117
129
|
});
|
|
118
|
-
|
|
119
|
-
for (const { edge: t, connection:
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
return
|
|
130
|
+
i.processTransaction();
|
|
131
|
+
for (const { edge: t, connection: o } of v) {
|
|
132
|
+
const g = o.displayRoute(), a = Array.from({ length: g.size() }, (h, u) => {
|
|
133
|
+
const d = g.at(u), f = { x: d.x, y: d.y };
|
|
134
|
+
return O(d), f;
|
|
123
135
|
});
|
|
124
|
-
if (
|
|
136
|
+
if (O(g), !o.hasValidRoute() || a.length < 2 || a.some((h) => !Number.isFinite(h.x) || !Number.isFinite(h.y)) || a.some((h, u) => u > 0 && h.x !== a[u - 1].x && h.y !== a[u - 1].y))
|
|
125
137
|
throw new Error(`Graph edge cannot be routed: ${t.id}`);
|
|
126
|
-
|
|
138
|
+
T.set(t.id, a);
|
|
127
139
|
}
|
|
128
140
|
} finally {
|
|
129
|
-
|
|
141
|
+
i.delete();
|
|
130
142
|
}
|
|
131
143
|
}
|
|
132
|
-
const
|
|
133
|
-
return
|
|
144
|
+
const w = n.edges.map((y) => ({ ...y, sections: [T.get(y.id)] }));
|
|
145
|
+
return F({
|
|
146
|
+
nodes: n.nodes,
|
|
147
|
+
edges: w,
|
|
148
|
+
bounds: n.bounds
|
|
149
|
+
});
|
|
134
150
|
}
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
...
|
|
138
|
-
{ x:
|
|
139
|
-
{ x:
|
|
151
|
+
function F(n) {
|
|
152
|
+
const s = [
|
|
153
|
+
...n.nodes.flatMap((x) => [
|
|
154
|
+
{ x: x.x, y: x.y },
|
|
155
|
+
{ x: x.x + x.width, y: x.y + x.height }
|
|
140
156
|
]),
|
|
141
|
-
...
|
|
142
|
-
],
|
|
157
|
+
...n.edges.flatMap((x) => x.sections.flat())
|
|
158
|
+
], r = Math.min(...s.map((x) => x.x)), p = Math.min(...s.map((x) => x.y));
|
|
143
159
|
return {
|
|
144
|
-
nodes:
|
|
145
|
-
edges:
|
|
160
|
+
nodes: n.nodes,
|
|
161
|
+
edges: n.edges,
|
|
146
162
|
bounds: {
|
|
147
|
-
x,
|
|
148
|
-
y:
|
|
149
|
-
width: Math.max(...
|
|
150
|
-
height: Math.max(...
|
|
163
|
+
x: r,
|
|
164
|
+
y: p,
|
|
165
|
+
width: Math.max(...s.map((x) => x.x)) - r,
|
|
166
|
+
height: Math.max(...s.map((x) => x.y)) - p
|
|
151
167
|
}
|
|
152
168
|
};
|
|
153
169
|
}
|
|
154
|
-
function
|
|
170
|
+
function U(n, s) {
|
|
155
171
|
return {
|
|
156
|
-
x:
|
|
157
|
-
y:
|
|
172
|
+
x: s === "WEST" ? n.x : s === "EAST" ? n.x + n.width : n.x + n.width / 2,
|
|
173
|
+
y: s === "NORTH" ? n.y : s === "SOUTH" ? n.y + n.height : n.y + n.height / 2
|
|
158
174
|
};
|
|
159
175
|
}
|
|
160
|
-
function B(
|
|
161
|
-
return
|
|
176
|
+
function B(n) {
|
|
177
|
+
return {
|
|
178
|
+
NORTH: "SOUTH",
|
|
179
|
+
EAST: "WEST",
|
|
180
|
+
SOUTH: "NORTH",
|
|
181
|
+
WEST: "EAST"
|
|
182
|
+
}[n];
|
|
183
|
+
}
|
|
184
|
+
function X(n, s, r, p, x, T, w) {
|
|
185
|
+
let y;
|
|
186
|
+
const m = (i, e, c) => c === "NORTH" ? e.x === i.x && e.y < i.y : c === "SOUTH" ? e.x === i.x && e.y > i.y : c === "WEST" ? e.y === i.y && e.x < i.x : e.y === i.y && e.x > i.x;
|
|
187
|
+
for (const i of T ? [T] : N)
|
|
188
|
+
for (const e of w ? [w] : N) {
|
|
189
|
+
const c = T ? U(n, i) : W(n, i, s, x), S = w ? U(s, e) : W(s, e, n, x), E = c.x === S.x || c.y === S.y ? [[c, S]] : [
|
|
190
|
+
[c, { x: S.x, y: c.y }, S],
|
|
191
|
+
[c, { x: c.x, y: S.y }, S]
|
|
192
|
+
];
|
|
193
|
+
for (const l of E) {
|
|
194
|
+
if (r.includes(n) && !m(c, l[1], i) || r.includes(s) && !m(S, l.at(-2), e) || l.slice(1).some((H, v) => {
|
|
195
|
+
const t = l[v];
|
|
196
|
+
return r.some(
|
|
197
|
+
(o) => Math.max(t.x, H.x) > o.x && Math.min(t.x, H.x) < o.x + o.width && Math.max(t.y, H.y) > o.y && Math.min(t.y, H.y) < o.y + o.height
|
|
198
|
+
);
|
|
199
|
+
}))
|
|
200
|
+
continue;
|
|
201
|
+
const C = l.slice(1).reduce(
|
|
202
|
+
(H, v, t) => H + Math.abs(v.x - l[t].x) + Math.abs(v.y - l[t].y),
|
|
203
|
+
0
|
|
204
|
+
) + (l.length - 2) * 32 + (i === p.source ? 0 : 16) + (e === p.target ? 0 : 16);
|
|
205
|
+
(!y || C < y.score) && (y = { source: i, target: e, score: C });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return y;
|
|
209
|
+
}
|
|
210
|
+
function Y(n, s) {
|
|
211
|
+
const r = (e, c) => c.x >= e.x && c.y >= e.y && c.x + c.width <= e.x + e.width && c.y + c.height <= e.y + e.height, p = r(n, s) ? n : r(s, n) ? s : void 0;
|
|
212
|
+
if (p) {
|
|
213
|
+
const e = p === n ? s : n, c = {
|
|
214
|
+
NORTH: e.y - p.y,
|
|
215
|
+
EAST: p.x + p.width - e.x - e.width,
|
|
216
|
+
SOUTH: p.y + p.height - e.y - e.height,
|
|
217
|
+
WEST: e.x - p.x
|
|
218
|
+
}, S = [...N].sort((E, l) => c[E] - c[l])[0];
|
|
219
|
+
return { source: S, target: S };
|
|
220
|
+
}
|
|
221
|
+
const x = s.x + s.width / 2 - (n.x + n.width / 2), T = s.y + s.height / 2 - (n.y + n.height / 2), w = Math.max(n.x - (s.x + s.width), s.x - (n.x + n.width), 0), y = Math.max(
|
|
222
|
+
n.y - (s.y + s.height),
|
|
223
|
+
s.y - (n.y + n.height),
|
|
224
|
+
0
|
|
225
|
+
), i = (y === 0 && w > 0 ? !0 : w === 0 && y > 0 ? !1 : w === 0 && y === 0 ? Math.abs(x) >= Math.abs(T) : w <= y) ? x >= 0 ? "EAST" : "WEST" : T >= 0 ? "SOUTH" : "NORTH";
|
|
226
|
+
return { source: i, target: B(i) };
|
|
227
|
+
}
|
|
228
|
+
function W(n, s, r, p = 0) {
|
|
229
|
+
const x = (i) => Math.min(8, i / 4), T = (i, e, c) => Math.max(e + x(c), Math.min(e + c - x(c), i)), w = (i, e, c, S) => {
|
|
230
|
+
const E = Math.max(i, c), l = Math.min(i + e, c + S);
|
|
231
|
+
return E < l ? (E + l) / 2 + p : void 0;
|
|
232
|
+
}, y = r.x + r.width / 2, m = r.y + r.height / 2;
|
|
233
|
+
switch (s) {
|
|
234
|
+
case "NORTH":
|
|
235
|
+
return {
|
|
236
|
+
x: T(
|
|
237
|
+
w(n.x, n.width, r.x, r.width) ?? y + p,
|
|
238
|
+
n.x,
|
|
239
|
+
n.width
|
|
240
|
+
),
|
|
241
|
+
y: n.y
|
|
242
|
+
};
|
|
243
|
+
case "EAST":
|
|
244
|
+
return {
|
|
245
|
+
x: n.x + n.width,
|
|
246
|
+
y: T(
|
|
247
|
+
w(n.y, n.height, r.y, r.height) ?? m + p,
|
|
248
|
+
n.y,
|
|
249
|
+
n.height
|
|
250
|
+
)
|
|
251
|
+
};
|
|
252
|
+
case "SOUTH":
|
|
253
|
+
return {
|
|
254
|
+
x: T(
|
|
255
|
+
w(n.x, n.width, r.x, r.width) ?? y + p,
|
|
256
|
+
n.x,
|
|
257
|
+
n.width
|
|
258
|
+
),
|
|
259
|
+
y: n.y + n.height
|
|
260
|
+
};
|
|
261
|
+
case "WEST":
|
|
262
|
+
return {
|
|
263
|
+
x: n.x,
|
|
264
|
+
y: T(
|
|
265
|
+
w(n.y, n.height, r.y, r.height) ?? m + p,
|
|
266
|
+
n.y,
|
|
267
|
+
n.height
|
|
268
|
+
)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
162
271
|
}
|
|
163
272
|
export {
|
|
164
|
-
|
|
273
|
+
$ as routeGraphGeometry
|
|
165
274
|
};
|
|
@@ -52,8 +52,10 @@ export interface GraphLayoutOptions {
|
|
|
52
52
|
positions?: readonly (GraphPoint & {
|
|
53
53
|
nodeId: string;
|
|
54
54
|
})[];
|
|
55
|
-
/**
|
|
56
|
-
|
|
55
|
+
/** Root-level ranks. Unassigned roots are placed deterministically near their closest ranked neighbors. */
|
|
56
|
+
layers?: readonly (readonly string[])[];
|
|
57
|
+
/** Fixed (default) rejects impossible geometry. Preferred retains positions; compact uses them only as stable ordering hints. */
|
|
58
|
+
positionMode?: 'fixed' | 'preferred' | 'compact';
|
|
57
59
|
direction?: 'RIGHT' | 'DOWN' | 'LEFT' | 'UP';
|
|
58
60
|
spacing?: number;
|
|
59
61
|
groupPadding?: {
|