@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.
@@ -1,165 +1,274 @@
1
- import { AvoidLib as H } from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/index.js";
2
- import _ from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/libavoid.wasm.js";
3
- let U;
4
- const F = { NORTH: 1, SOUTH: 2, WEST: 4, EAST: 8 }, v = ["NORTH", "EAST", "SOUTH", "WEST"], m = (s) => s.delete();
5
- async function L(s) {
6
- if (!s.nodes.length) return s;
7
- if (!s.edges.length) return W(s);
8
- await (U ??= H.load(_).catch((g) => {
9
- throw U = void 0, g;
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 n = H.getInstance(), x = new Map(s.nodes.map((g) => [g.id, g])), S = (g) => {
12
- const y = [];
13
- for (let a = x.get(g).parentId; a; a = x.get(a).parentId)
14
- y.push(a);
15
- return y;
16
- }, i = /* @__PURE__ */ new Map();
17
- for (const g of s.edges) {
18
- const y = /* @__PURE__ */ new Set([...S(g.source), ...S(g.target)]), a = JSON.stringify([...y].sort()), O = i.get(a) ?? { open: y, edges: [] };
19
- O.edges.push(g), i.set(a, O);
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 k = /* @__PURE__ */ new Map();
22
- for (const { open: g, edges: y } of i.values()) {
23
- const a = new n.Router(2);
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
- a.setRoutingParameter(n.RoutingParameter.shapeBufferDistance, 4), a.setRoutingParameter(n.RoutingParameter.idealNudgingDistance, 8), a.setRoutingParameter(n.RoutingParameter.crossingPenalty, 80), a.setRoutingParameter(n.RoutingParameter.fixedSharedPathPenalty, 120), a.setRoutingParameter(n.RoutingParameter.portDirectionPenalty, 0), a.setRoutingOption(n.RoutingOption.nudgeOrthogonalSegmentsConnectedToShapes, !1), a.setRoutingOption(n.RoutingOption.nudgeSharedPathsWithCommonEndPoint, !0);
26
- const O = new Map(
27
- s.nodes.filter((t) => !g.has(t.id) && S(t.id).every((r) => g.has(r))).map((t) => {
28
- const r = new n.Point(t.x, t.y), c = new n.Point(t.x + t.width, t.y + t.height), h = new n.Rectangle(r, c), o = new n.ShapeRef(a, h);
29
- return m(r), m(c), m(h), [t.id, o];
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
- for (const t of s.nodes) {
33
- const r = O.get(t.id);
34
- if (!r) continue;
35
- const c = y.flatMap(
36
- (e) => e.source === t.id ? [x.get(e.target)] : e.target === t.id ? [x.get(e.source)] : []
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
- if (!c.length) continue;
39
- const h = (e, f, p, M) => {
40
- const T = Math.max(e, p), R = Math.min(e + f, p + M), A = Math.min(8, f / 4);
41
- return T < R ? (T + R) / 2 : Math.max(e + A, Math.min(e + f - A, p + M / 2));
42
- }, o = (e, f) => {
43
- const p = Math.min(8, e / 4);
44
- return [
45
- .../* @__PURE__ */ new Set([
46
- e / 2,
47
- p,
48
- e - p,
49
- ...f.flatMap(
50
- (M) => Array.from(
51
- { length: c.length + 1 },
52
- (T, R) => Math.max(p, Math.min(e - p, M + (R - c.length / 2) * 8))
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
- M
63
+ d
78
64
  );
79
- R.setExclusive(T), R.setConnectionCost(
80
- t.width / 2 + t.height / 2 - Math.abs(f - t.width / 2) - Math.abs(p - t.height / 2)
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 e of u)
86
- d(e, 0, 1), d(e, t.height, 2);
87
- for (const e of w)
88
- d(0, e, 4), d(t.width, e, 8);
89
- for (const e of new Set(t.ports?.map((f) => f.side))) {
90
- const { x: f, y: p } = E(t, e);
91
- b(v.indexOf(e) + 2, f - t.x, p - t.y, F[e], !1);
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 N = (t, r, c, h) => {
96
- const o = x.get(t), u = O.get(t);
97
- if (u)
98
- return new n.ConnEnd(
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
- r ? v.indexOf(o.ports.find((d) => d.id === r).side) + 2 : t === c ? h ? 7 : 6 : 1
87
+ N.indexOf(h.ports.find((R) => R.id === o).side) + 2
101
88
  );
102
- const w = x.get(c), l = v.map((d) => E(o, d));
103
- l.sort((d, e) => B(d, w) - B(e, w));
104
- const P = r ? E(o, o.ports.find((d) => d.id === r).side) : l[0], C = new n.Point(P.x, P.y), b = new n.ConnEnd(C);
105
- return m(C), b;
106
- }, G = y.map((t) => {
107
- const r = N(t.source, t.sourcePort, t.target, !1), c = N(t.target, t.targetPort, t.source, !0), h = new n.ConnRef(a, r, c);
108
- if (m(r), m(c), t.source === t.target) {
109
- const o = x.get(t.source), u = new n.CheckpointVector();
110
- for (const w of [o.y + o.height / 3, o.y + o.height * 2 / 3]) {
111
- const l = new n.Point(o.x + o.width + 24, w), P = new n.Checkpoint(l);
112
- u.push_back(P), m(l), m(P);
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
- h.setRoutingCheckpoints(u), m(u);
126
+ d.setRoutingCheckpoints(M), O(M);
115
127
  }
116
- return { edge: t, connection: h };
128
+ return { edge: t, connection: d };
117
129
  });
118
- a.processTransaction();
119
- for (const { edge: t, connection: r } of G) {
120
- const c = r.displayRoute(), h = Array.from({ length: c.size() }, (o, u) => {
121
- const w = c.at(u), l = { x: w.x, y: w.y };
122
- return m(w), l;
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 (m(c), !r.hasValidRoute() || h.length < 2 || h.some((o) => !Number.isFinite(o.x) || !Number.isFinite(o.y)) || h.some((o, u) => u > 0 && o.x !== h[u - 1].x && o.y !== h[u - 1].y))
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
- k.set(t.id, h);
138
+ T.set(t.id, a);
127
139
  }
128
140
  } finally {
129
- a.delete();
141
+ i.delete();
130
142
  }
131
143
  }
132
- const D = s.edges.map((g) => ({ ...g, sections: [k.get(g.id)] }));
133
- return W({ nodes: s.nodes, edges: D, bounds: s.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
149
+ });
134
150
  }
135
- function W(s) {
136
- const n = [
137
- ...s.nodes.flatMap((i) => [
138
- { x: i.x, y: i.y },
139
- { x: i.x + i.width, y: i.y + i.height }
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
- ...s.edges.flatMap((i) => i.sections.flat())
142
- ], x = Math.min(...n.map((i) => i.x)), S = Math.min(...n.map((i) => i.y));
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: s.nodes,
145
- edges: s.edges,
160
+ nodes: n.nodes,
161
+ edges: n.edges,
146
162
  bounds: {
147
- x,
148
- y: S,
149
- width: Math.max(...n.map((i) => i.x)) - x,
150
- height: Math.max(...n.map((i) => i.y)) - S
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 E(s, n) {
170
+ function U(n, s) {
155
171
  return {
156
- x: n === "WEST" ? s.x : n === "EAST" ? s.x + s.width : s.x + s.width / 2,
157
- y: n === "NORTH" ? s.y : n === "SOUTH" ? s.y + s.height : s.y + s.height / 2
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(s, n) {
161
- return Math.max(n.x - s.x, 0, s.x - n.x - n.width) + Math.max(n.y - s.y, 0, s.y - n.y - n.height);
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
- L as routeGraphGeometry
273
+ $ as routeGraphGeometry
165
274
  };
@@ -52,8 +52,10 @@ export interface GraphLayoutOptions {
52
52
  positions?: readonly (GraphPoint & {
53
53
  nodeId: string;
54
54
  })[];
55
- /** Fixed (default) rejects impossible geometry. Preferred retains clear positions and separates colliding siblings, resizing groups around their content before routing. */
56
- positionMode?: 'fixed' | 'preferred';
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?: {