@floegence/floe-webapp-core 0.86.8 → 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/routing.js +212 -140
- package/package.json +1 -1
|
@@ -1,202 +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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
43
|
+
);
|
|
44
|
+
c.set(t.id, {
|
|
45
|
+
sourceSide: R?.source ?? h,
|
|
46
|
+
targetSide: R?.target ?? u,
|
|
47
|
+
offset: M
|
|
38
48
|
});
|
|
39
49
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
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(
|
|
46
57
|
o,
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
a,
|
|
59
|
+
C(h, t.width),
|
|
60
|
+
C(u, t.height),
|
|
49
61
|
!0,
|
|
50
62
|
0,
|
|
51
|
-
|
|
63
|
+
d
|
|
52
64
|
);
|
|
53
|
-
|
|
54
|
-
|
|
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)
|
|
55
67
|
);
|
|
56
68
|
};
|
|
57
|
-
for (const
|
|
58
|
-
const { x:
|
|
59
|
-
|
|
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
|
+
);
|
|
60
80
|
}
|
|
61
81
|
}
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
return new
|
|
66
|
-
|
|
67
|
-
|
|
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(
|
|
86
|
+
u,
|
|
87
|
+
N.indexOf(h.ports.find((R) => R.id === o).side) + 2
|
|
68
88
|
);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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);
|
|
89
125
|
}
|
|
90
|
-
|
|
126
|
+
d.setRoutingCheckpoints(M), O(M);
|
|
91
127
|
}
|
|
92
|
-
return { edge:
|
|
128
|
+
return { edge: t, connection: d };
|
|
93
129
|
});
|
|
94
|
-
|
|
95
|
-
for (const { edge:
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
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;
|
|
99
135
|
});
|
|
100
|
-
if (
|
|
101
|
-
throw new Error(`Graph edge cannot be routed: ${
|
|
102
|
-
|
|
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))
|
|
137
|
+
throw new Error(`Graph edge cannot be routed: ${t.id}`);
|
|
138
|
+
T.set(t.id, a);
|
|
103
139
|
}
|
|
104
140
|
} finally {
|
|
105
|
-
|
|
141
|
+
i.delete();
|
|
106
142
|
}
|
|
107
143
|
}
|
|
108
|
-
const
|
|
109
|
-
return
|
|
110
|
-
nodes:
|
|
111
|
-
edges:
|
|
112
|
-
bounds:
|
|
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
|
|
113
149
|
});
|
|
114
150
|
}
|
|
115
|
-
function
|
|
116
|
-
const
|
|
117
|
-
...
|
|
118
|
-
{ x:
|
|
119
|
-
{ 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 }
|
|
120
156
|
]),
|
|
121
|
-
...
|
|
122
|
-
],
|
|
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));
|
|
123
159
|
return {
|
|
124
|
-
nodes:
|
|
125
|
-
edges:
|
|
160
|
+
nodes: n.nodes,
|
|
161
|
+
edges: n.edges,
|
|
126
162
|
bounds: {
|
|
127
|
-
x:
|
|
128
|
-
y:
|
|
129
|
-
width: Math.max(...
|
|
130
|
-
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
|
|
131
167
|
}
|
|
132
168
|
};
|
|
133
169
|
}
|
|
134
|
-
function
|
|
170
|
+
function U(n, s) {
|
|
135
171
|
return {
|
|
136
|
-
x:
|
|
137
|
-
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
|
|
138
174
|
};
|
|
139
175
|
}
|
|
140
|
-
function
|
|
176
|
+
function B(n) {
|
|
141
177
|
return {
|
|
142
178
|
NORTH: "SOUTH",
|
|
143
179
|
EAST: "WEST",
|
|
144
180
|
SOUTH: "NORTH",
|
|
145
181
|
WEST: "EAST"
|
|
146
|
-
}[
|
|
182
|
+
}[n];
|
|
147
183
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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),
|
|
152
224
|
0
|
|
153
|
-
),
|
|
154
|
-
return { source:
|
|
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) };
|
|
155
227
|
}
|
|
156
|
-
function
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
return
|
|
160
|
-
},
|
|
161
|
-
switch (
|
|
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) {
|
|
162
234
|
case "NORTH":
|
|
163
235
|
return {
|
|
164
|
-
x:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
236
|
+
x: T(
|
|
237
|
+
w(n.x, n.width, r.x, r.width) ?? y + p,
|
|
238
|
+
n.x,
|
|
239
|
+
n.width
|
|
168
240
|
),
|
|
169
|
-
y:
|
|
241
|
+
y: n.y
|
|
170
242
|
};
|
|
171
243
|
case "EAST":
|
|
172
244
|
return {
|
|
173
|
-
x:
|
|
174
|
-
y:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
178
250
|
)
|
|
179
251
|
};
|
|
180
252
|
case "SOUTH":
|
|
181
253
|
return {
|
|
182
|
-
x:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
254
|
+
x: T(
|
|
255
|
+
w(n.x, n.width, r.x, r.width) ?? y + p,
|
|
256
|
+
n.x,
|
|
257
|
+
n.width
|
|
186
258
|
),
|
|
187
|
-
y:
|
|
259
|
+
y: n.y + n.height
|
|
188
260
|
};
|
|
189
261
|
case "WEST":
|
|
190
262
|
return {
|
|
191
|
-
x:
|
|
192
|
-
y:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
|
196
268
|
)
|
|
197
269
|
};
|
|
198
270
|
}
|
|
199
271
|
}
|
|
200
272
|
export {
|
|
201
|
-
|
|
273
|
+
$ as routeGraphGeometry
|
|
202
274
|
};
|