@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.
@@ -1,202 +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 W from "../../node_modules/.pnpm/libavoid-js@0.5.0-beta.5/node_modules/libavoid-js/dist/libavoid.wasm.js";
3
- let N;
4
- const B = { NORTH: 1, SOUTH: 2, WEST: 4, EAST: 8 }, v = ["NORTH", "EAST", "SOUTH", "WEST"], m = (t) => t.delete();
5
- async function F(t) {
6
- if (!t.nodes.length) return t;
7
- if (!t.edges.length) return C(t);
8
- await (N ??= H.load(W).catch((h) => {
9
- throw N = void 0, h;
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 e = H.getInstance(), s = new Map(t.nodes.map((h) => [h.id, h])), d = (h) => {
12
- const y = [];
13
- for (let r = s.get(h).parentId; r; r = s.get(r).parentId)
14
- y.push(r);
15
- return y;
16
- }, i = /* @__PURE__ */ new Map();
17
- for (const h of t.edges) {
18
- const y = /* @__PURE__ */ new Set([...d(h.source), ...d(h.target)]), r = JSON.stringify([...y].sort()), S = i.get(r) ?? { open: y, edges: [] };
19
- S.edges.push(h), i.set(r, S);
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 f = /* @__PURE__ */ new Map();
22
- for (const { open: h, edges: y } of i.values()) {
23
- const r = new e.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
- r.setRoutingParameter(e.RoutingParameter.shapeBufferDistance, 4), r.setRoutingParameter(e.RoutingParameter.idealNudgingDistance, 8), r.setRoutingParameter(e.RoutingParameter.crossingPenalty, 80), r.setRoutingParameter(e.RoutingParameter.fixedSharedPathPenalty, 120), r.setRoutingParameter(e.RoutingParameter.portDirectionPenalty, 0), r.setRoutingOption(e.RoutingOption.nudgeOrthogonalSegmentsConnectedToShapes, !1), r.setRoutingOption(e.RoutingOption.nudgeSharedPathsWithCommonEndPoint, !0);
26
- const S = new Map(
27
- t.nodes.filter((n) => !h.has(n.id) && d(n.id).every((a) => h.has(a))).map((n) => {
28
- const a = new e.Point(n.x, n.y), p = new e.Point(n.x + n.width, n.y + n.height), o = new e.Rectangle(a, p), c = new e.ShapeRef(r, o);
29
- return m(a), m(p), m(o), [n.id, c];
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
- ), P = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
32
- y.forEach((n) => {
33
- const a = s.get(n.source), p = s.get(n.target), o = D(a, p), c = n.sourcePort ? a.ports.find((u) => u.id === n.sourcePort).side : n.targetPort ? O(p.ports.find((u) => u.id === n.targetPort).side) : o.source, g = n.targetPort ? p.ports.find((u) => u.id === n.targetPort).side : n.sourcePort ? O(a.ports.find((u) => u.id === n.sourcePort).side) : o.target, w = [n.source, n.target].sort().join("\0"), x = R.get(w) ?? 0;
34
- R.set(w, x + 1), P.set(n.id, {
35
- sourceSide: c,
36
- targetSide: g,
37
- offset: x % 2 === 0 ? -6 : 6
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
- for (const n of t.nodes) {
41
- const a = S.get(n.id);
42
- if (!a) continue;
43
- const p = (o, c, g, w, x) => {
44
- const u = new e.ShapeConnectionPin(
45
- a,
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
- c / n.width,
48
- g / n.height,
58
+ a,
59
+ C(h, t.width),
60
+ C(u, t.height),
49
61
  !0,
50
62
  0,
51
- w
63
+ d
52
64
  );
53
- u.setExclusive(x), u.setConnectionCost(
54
- n.width / 2 + n.height / 2 - Math.abs(c - n.width / 2) - Math.abs(g - n.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)
55
67
  );
56
68
  };
57
- for (const o of new Set(n.ports?.map((c) => c.side))) {
58
- const { x: c, y: g } = A(n, o);
59
- p(v.indexOf(o) + 2, c - n.x, g - n.y, B[o], !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
+ );
60
80
  }
61
81
  }
62
- const l = (n, a, p) => {
63
- const o = s.get(n), c = S.get(n);
64
- if (c && a)
65
- return new e.ConnEnd(
66
- c,
67
- v.indexOf(o.ports.find((u) => u.id === a).side) + 2
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
- const g = a ? A(o, o.ports.find((u) => u.id === a).side) : p, w = new e.Point(g.x, g.y), x = new e.ConnEnd(w);
70
- return m(w), x;
71
- }, M = y.map((n) => {
72
- const a = s.get(n.source), p = s.get(n.target), o = P.get(n.id), c = l(
73
- n.source,
74
- n.sourcePort,
75
- n.source === n.target ? { x: a.x + a.width, y: a.y + a.height / 3 } : k(a, o.sourceSide, p, o.offset)
76
- ), g = l(
77
- n.target,
78
- n.targetPort,
79
- n.source === n.target ? {
80
- x: p.x + p.width,
81
- y: p.y + p.height * 2 / 3
82
- } : k(p, o.targetSide, a, o.offset)
83
- ), w = new e.ConnRef(r, c, g);
84
- if (m(c), m(g), n.source === n.target) {
85
- const x = s.get(n.source), u = new e.CheckpointVector();
86
- for (const U of [x.y + x.height / 3, x.y + x.height * 2 / 3]) {
87
- const E = new e.Point(x.x + x.width + 24, U), b = new e.Checkpoint(E);
88
- u.push_back(b), m(E), m(b);
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
- w.setRoutingCheckpoints(u), m(u);
126
+ d.setRoutingCheckpoints(M), O(M);
91
127
  }
92
- return { edge: n, connection: w };
128
+ return { edge: t, connection: d };
93
129
  });
94
- r.processTransaction();
95
- for (const { edge: n, connection: a } of M) {
96
- const p = a.displayRoute(), o = Array.from({ length: p.size() }, (c, g) => {
97
- const w = p.at(g), x = { x: w.x, y: w.y };
98
- return m(w), x;
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 (m(p), !a.hasValidRoute() || o.length < 2 || o.some((c) => !Number.isFinite(c.x) || !Number.isFinite(c.y)) || o.some((c, g) => g > 0 && c.x !== o[g - 1].x && c.y !== o[g - 1].y))
101
- throw new Error(`Graph edge cannot be routed: ${n.id}`);
102
- f.set(n.id, o);
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
- r.delete();
141
+ i.delete();
106
142
  }
107
143
  }
108
- const T = t.edges.map((h) => ({ ...h, sections: [f.get(h.id)] }));
109
- return C({
110
- nodes: t.nodes,
111
- edges: T,
112
- bounds: t.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 C(t) {
116
- const e = [
117
- ...t.nodes.flatMap((i) => [
118
- { x: i.x, y: i.y },
119
- { 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 }
120
156
  ]),
121
- ...t.edges.flatMap((i) => i.sections.flat())
122
- ], s = Math.min(...e.map((i) => i.x)), d = Math.min(...e.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));
123
159
  return {
124
- nodes: t.nodes,
125
- edges: t.edges,
160
+ nodes: n.nodes,
161
+ edges: n.edges,
126
162
  bounds: {
127
- x: s,
128
- y: d,
129
- width: Math.max(...e.map((i) => i.x)) - s,
130
- height: Math.max(...e.map((i) => i.y)) - d
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 A(t, e) {
170
+ function U(n, s) {
135
171
  return {
136
- x: e === "WEST" ? t.x : e === "EAST" ? t.x + t.width : t.x + t.width / 2,
137
- y: e === "NORTH" ? t.y : e === "SOUTH" ? t.y + t.height : t.y + t.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
138
174
  };
139
175
  }
140
- function O(t) {
176
+ function B(n) {
141
177
  return {
142
178
  NORTH: "SOUTH",
143
179
  EAST: "WEST",
144
180
  SOUTH: "NORTH",
145
181
  WEST: "EAST"
146
- }[t];
182
+ }[n];
147
183
  }
148
- function D(t, e) {
149
- const s = e.x + e.width / 2 - (t.x + t.width / 2), d = e.y + e.height / 2 - (t.y + t.height / 2), i = Math.max(t.x - (e.x + e.width), e.x - (t.x + t.width), 0), f = Math.max(
150
- t.y - (e.y + e.height),
151
- e.y - (t.y + t.height),
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
- ), h = (f === 0 && i > 0 ? !0 : i === 0 && f > 0 ? !1 : i === 0 && f === 0 ? Math.abs(s) >= Math.abs(d) : i <= f) ? s >= 0 ? "EAST" : "WEST" : d >= 0 ? "SOUTH" : "NORTH";
154
- return { source: h, target: O(h) };
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 k(t, e, s, d = 0) {
157
- const i = (r) => Math.min(8, r / 4), f = (r, S, P) => Math.max(S + i(P), Math.min(S + P - i(P), r)), T = (r, S, P, R) => {
158
- const l = Math.max(r, P), M = Math.min(r + S, P + R);
159
- return l < M ? (l + M) / 2 + d : void 0;
160
- }, h = s.x + s.width / 2, y = s.y + s.height / 2;
161
- switch (e) {
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: f(
165
- T(t.x, t.width, s.x, s.width) ?? h + d,
166
- t.x,
167
- t.width
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: t.y
241
+ y: n.y
170
242
  };
171
243
  case "EAST":
172
244
  return {
173
- x: t.x + t.width,
174
- y: f(
175
- T(t.y, t.height, s.y, s.height) ?? y + d,
176
- t.y,
177
- t.height
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: f(
183
- T(t.x, t.width, s.x, s.width) ?? h + d,
184
- t.x,
185
- t.width
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: t.y + t.height
259
+ y: n.y + n.height
188
260
  };
189
261
  case "WEST":
190
262
  return {
191
- x: t.x,
192
- y: f(
193
- T(t.y, t.height, s.y, s.height) ?? y + d,
194
- t.y,
195
- t.height
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
- F as routeGraphGeometry
273
+ $ as routeGraphGeometry
202
274
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.86.8",
3
+ "version": "0.86.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",