@floegence/floe-webapp-core 0.86.14 → 0.86.16

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,20 +1,20 @@
1
- function W(n) {
2
- const { surface: E } = n, K = E.ownerDocument, u = K.defaultView;
3
- if (!u) throw new Error("Remote input requires an attached document");
4
- const t = K.createElement("textarea");
5
- t.className = "floe-remote-input", t.setAttribute("aria-label", n.label), t.setAttribute("autocorrect", "off"), t.autocomplete = "off", t.autocapitalize = "off", t.spellcheck = !1, t.wrap = "off", t.disabled = !0, t.tabIndex = -1, K.body.append(t);
6
- let l = null, g = 0, c = !1, S = !1, o = null, m = !1, s = null, h = "physical";
7
- const w = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Set();
8
- let T = null;
9
- const z = [];
10
- function a(e, i, r) {
11
- const k = r;
12
- e.addEventListener(i, k), z.push(() => e.removeEventListener(i, k));
1
+ function j(n) {
2
+ const { surface: A } = n, x = A.ownerDocument, c = x.defaultView;
3
+ if (!c) throw new Error("Remote input requires an attached document");
4
+ const i = x.createElement("textarea");
5
+ i.className = "floe-remote-input", i.setAttribute("aria-label", n.label), i.setAttribute("autocorrect", "off"), i.autocomplete = "off", i.autocapitalize = "off", i.spellcheck = !1, i.wrap = "off", i.disabled = !0, i.tabIndex = -1, x.body.append(i);
6
+ let l = null, K = 0, f = !1, R = !1, o = null, h = !1, a = null, w = "physical";
7
+ const k = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set();
8
+ let $ = null;
9
+ const V = [];
10
+ function s(e, t, r) {
11
+ const d = r;
12
+ e.addEventListener(t, d), V.push(() => e.removeEventListener(t, d));
13
13
  }
14
- const b = (e) => e.code || e.key, x = (e, i) => ({
14
+ const b = (e) => e.code || e.key, M = (e, t) => ({
15
15
  key: e.key,
16
16
  code: e.code,
17
- pressed: i,
17
+ pressed: t,
18
18
  repeat: e.repeat,
19
19
  location: e.location,
20
20
  shiftKey: e.shiftKey,
@@ -22,139 +22,147 @@ function W(n) {
22
22
  altKey: e.altKey,
23
23
  metaKey: e.metaKey
24
24
  });
25
- function C(e) {
26
- S !== e && (S = e, n.onKeyboardVisibilityChange?.(e));
27
- }
28
- function d() {
29
- const e = E.getBoundingClientRect(), i = u.visualViewport, r = Math.max(e.left, i?.offsetLeft ?? 0), k = Math.max(e.top, i?.offsetTop ?? 0), B = Math.min(e.right, (i?.offsetLeft ?? 0) + (i?.width ?? u.innerWidth)), P = Math.min(e.bottom, (i?.offsetTop ?? 0) + (i?.height ?? u.innerHeight)), R = Math.max(1, Math.min(320, B - r - 8));
30
- t.style.maxWidth = `${R}px`;
31
- const D = t.getBoundingClientRect(), $ = T?.x ?? r + 12, N = T?.y ?? k + 12;
32
- t.style.left = `${Math.max(r, Math.min($, B - D.width - 4))}px`, t.style.top = `${Math.max(k, Math.min(N, P - D.height - 4))}px`;
25
+ function T(e) {
26
+ R !== e && (R = e, n.onKeyboardVisibilityChange?.(e));
33
27
  }
34
28
  function p() {
35
- t.value = "", delete t.dataset.composing, s = null;
29
+ const e = A.getBoundingClientRect(), t = c.visualViewport, r = Math.max(e.left, t?.offsetLeft ?? 0), d = Math.max(e.top, t?.offsetTop ?? 0), y = Math.min(e.right, (t?.offsetLeft ?? 0) + (t?.width ?? c.innerWidth)), I = Math.min(e.bottom, (t?.offsetTop ?? 0) + (t?.height ?? c.innerHeight)), P = Math.max(1, Math.min(320, y - r - 8));
30
+ i.style.maxWidth = `${P}px`;
31
+ const B = i.getBoundingClientRect(), N = $?.x ?? r + 12, W = $?.y ?? d + 12;
32
+ i.style.left = `${Math.max(r, Math.min(N, y - B.width - 4))}px`, i.style.top = `${Math.max(d, Math.min(W, I - B.height - 4))}px`;
33
+ }
34
+ function m() {
35
+ i.value = "", delete i.dataset.composing, a = null;
36
36
  }
37
- function A() {
38
- const e = l, i = f.size > 0;
39
- f.clear(), w.clear(), e !== null && i && n.release(e);
37
+ function E() {
38
+ const e = l, t = u.size > 0;
39
+ u.clear(), k.clear(), C.clear(), e !== null && t && n.release(e);
40
40
  }
41
- function y() {
42
- g++, o && (o.cancelled = !0), m = !0, p(), A(), o && K.activeElement === t && t.blur();
41
+ function g() {
42
+ K++, o && (o.cancelled = !0), h = !0, m(), E(), o && x.activeElement === i && i.blur();
43
43
  }
44
- function V(e) {
45
- !e || l === null || c || (h === "text" && f.size && (f.clear(), n.release(l)), n.commitText(e, l));
44
+ function S(e) {
45
+ !e || l === null || f || (w === "text" && u.size && (u.clear(), C.clear(), n.release(l)), n.commitText(e, l));
46
46
  }
47
- function L(e) {
47
+ function z(e) {
48
48
  if (l !== null) {
49
- if (h === "text")
50
- for (const [i, r] of w)
51
- f.has(i) || (f.add(i), n.sendKey(r, l));
52
- f.add(e.code || e.key), n.sendKey(e, l);
49
+ if (!/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code))
50
+ for (const [t, r] of [
51
+ ["Shift", e.shiftKey],
52
+ ["Control", e.ctrlKey],
53
+ ["Alt", e.altKey],
54
+ ["Meta", e.metaKey]
55
+ ]) {
56
+ if (!r || [...u].some((y) => y === `${t}Left` || y === `${t}Right`)) continue;
57
+ const d = [...k.values()].find((y) => y.code === `${t}Left` || y.code === `${t}Right`) ?? { ...e, key: t, code: `${t}Left`, pressed: !0, repeat: !1, location: 1 };
58
+ u.add(d.code), k.has(d.code) || C.add(d.code), n.sendKey(d, l);
59
+ }
60
+ u.add(e.code || e.key), n.sendKey(e, l);
53
61
  }
54
62
  }
55
- function F(e) {
63
+ function D(e) {
56
64
  if (l === null) return;
57
- const i = { key: e, code: e, pressed: !0, repeat: !1, shiftKey: !1, ctrlKey: !1, altKey: !1, metaKey: !1, location: 0 }, r = l;
58
- n.sendKey(i, r), l === r && n.sendKey({ ...i, pressed: !1 }, r);
65
+ const t = { key: e, code: e, pressed: !0, repeat: !1, shiftKey: !1, ctrlKey: !1, altKey: !1, metaKey: !1, location: 0 }, r = l;
66
+ n.sendKey(t, r), l === r && n.sendKey({ ...t, pressed: !1 }, r);
59
67
  }
60
- function I(e) {
61
- if (l === null || c) {
62
- p();
68
+ function F(e) {
69
+ if (l === null || f) {
70
+ m();
63
71
  return;
64
72
  }
65
- if (o?.cancelled || o && o.epoch !== g) {
66
- p();
73
+ if (o?.cancelled || o && o.epoch !== K) {
74
+ m();
67
75
  return;
68
76
  }
69
77
  if (e.isComposing) {
70
- o ??= { epoch: g, committed: !1, cancelled: !1 }, t.dataset.composing = "true", d();
78
+ o ??= { epoch: K, committed: !1, cancelled: !1 }, i.dataset.composing = "true", p();
71
79
  return;
72
80
  }
73
81
  if (o) {
74
- !o.committed && t.value && (o.committed = !0, V(t.value)), p();
82
+ !o.committed && i.value && (o.committed = !0, S(i.value)), m();
75
83
  return;
76
84
  }
77
- if (m || e.inputType === "insertFromComposition") {
78
- m = !1, p();
85
+ if (h || e.inputType === "insertFromComposition") {
86
+ h = !1, m();
79
87
  return;
80
88
  }
81
- const i = t.value;
82
- if (h === "physical" && s && i === s.key && !s.altKey && i.length === 1) {
83
- const r = s;
84
- f.add(r.code || r.key), n.sendKey(r, l);
85
- } else V(i);
86
- p();
89
+ const t = i.value;
90
+ w === "physical" && a && t === a.key && !a.altKey && t.length === 1 ? z(a) : S(t), m();
87
91
  }
88
- return a(t, "keydown", (e) => {
89
- if (!(l === null || c)) {
92
+ return s(i, "keydown", (e) => {
93
+ if (!(l === null || f)) {
90
94
  if (e.stopPropagation(), o?.cancelled && !e.isComposing && e.key !== "Process" && e.keyCode !== 229 && (o = null), e.isComposing || o || e.key === "Process" || e.keyCode === 229) {
91
- M.add(b(e)), s = null;
95
+ L.add(b(e)), a = null;
92
96
  return;
93
97
  }
94
- if (M.delete(b(e)), m = !1, n.clipboard?.(e, l)) {
95
- s = null;
98
+ if (L.delete(b(e)), h = !1, n.clipboard?.(e, l)) {
99
+ a = null;
96
100
  return;
97
101
  }
98
- if (h === "text" && /^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code)) {
99
- w.set(b(e), x(e, !0));
102
+ if (w === "text" && /^(Shift|Control|Alt|Meta)(Left|Right)$/.test(e.code)) {
103
+ k.set(b(e), M(e, !0));
100
104
  return;
101
105
  }
102
106
  if (e.key === "Dead" || e.key === "Unidentified") {
103
- s = null;
107
+ a = null;
104
108
  return;
105
109
  }
106
110
  if (Array.from(e.key).length === 1 && !e.metaKey && (!e.ctrlKey || e.getModifierState("AltGraph"))) {
107
- s = x(e, !0);
111
+ a = M(e, !0);
108
112
  return;
109
113
  }
110
- e.preventDefault(), L(x(e, !0));
114
+ e.preventDefault(), z(M(e, !0));
115
+ }
116
+ }), s(i, "keyup", (e) => {
117
+ if (e.stopPropagation(), a = null, k.delete(b(e)), !L.delete(b(e)) && (l !== null && u.delete(b(e)) && n.sendKey(M(e, !1), l), l !== null && ![...u].some((t) => !/^(Shift|Control|Alt|Meta)(Left|Right)$/.test(t)))) {
118
+ for (const t of C)
119
+ u.delete(t), n.sendKey({ ...M(e, !1), code: t, key: t.replace(/Left$/, ""), location: 1 }, l);
120
+ C.clear();
111
121
  }
112
- }), a(t, "keyup", (e) => {
113
- e.stopPropagation(), s = null, w.delete(b(e)), !M.delete(b(e)) && l !== null && f.delete(b(e)) && n.sendKey(x(e, !1), l);
114
- }), a(t, "beforeinput", (e) => {
115
- if (l === null || c) {
122
+ }), s(i, "beforeinput", (e) => {
123
+ if (l === null || f) {
116
124
  e.preventDefault();
117
125
  return;
118
126
  }
119
127
  if (e.isComposing || o || e.inputType === "insertCompositionText" || e.inputType === "deleteCompositionText" || e.inputType === "insertFromComposition") return;
120
- m = !1;
128
+ h = !1;
121
129
  const r = { deleteContentBackward: "Backspace", deleteContentForward: "Delete", insertLineBreak: "Enter", insertParagraph: "Enter" }[e.inputType];
122
- r && (e.preventDefault(), p(), F(r));
123
- }), a(t, "input", I), a(t, "compositionstart", () => {
124
- o = { epoch: g, committed: !1, cancelled: l === null }, m = !1, s = null, t.dataset.composing = "true", d();
125
- }), a(t, "compositionend", (e) => {
126
- const i = o;
127
- o = null, m = !0, p(), i && !i.cancelled && !i.committed && i.epoch === g && V(e.data);
128
- }), a(t, "blur", () => {
129
- y(), C(!1);
130
- }), a(u, "blur", y), a(u, "pagehide", y), a(u, "resize", d), u.visualViewport && (a(u.visualViewport, "resize", d), a(u.visualViewport, "scroll", d)), d(), {
131
- element: t,
130
+ r && (e.preventDefault(), m(), D(r));
131
+ }), s(i, "input", F), s(i, "compositionstart", () => {
132
+ o = { epoch: K, committed: !1, cancelled: l === null }, h = !1, a = null, i.dataset.composing = "true", p();
133
+ }), s(i, "compositionend", (e) => {
134
+ const t = o;
135
+ o = null, h = !0, m(), t && !t.cancelled && !t.committed && t.epoch === K && S(e.data);
136
+ }), s(i, "blur", () => {
137
+ g(), T(!1);
138
+ }), s(c, "blur", g), s(c, "pagehide", g), s(c, "resize", p), c.visualViewport && (s(c.visualViewport, "resize", p), s(c.visualViewport, "scroll", p)), p(), {
139
+ element: i,
132
140
  bindTarget(e) {
133
- c || Object.is(l, e) || (y(), l = e, t.disabled = e === null);
141
+ f || Object.is(l, e) || (g(), l = e, i.disabled = e === null);
134
142
  },
135
143
  setTextInputMode(e) {
136
- c || e === h || (y(), h = e);
144
+ f || e === w || (g(), w = e);
137
145
  },
138
- setAnchor(e, i) {
139
- !Number.isFinite(e) || !Number.isFinite(i) || (T = { x: e, y: i }, d());
146
+ setAnchor(e, t) {
147
+ !Number.isFinite(e) || !Number.isFinite(t) || ($ = { x: e, y: t }, p());
140
148
  },
141
149
  focus() {
142
- l === null || c || (t.focus({ preventScroll: !0 }), d());
150
+ l === null || f || (i.focus({ preventScroll: !0 }), p());
143
151
  },
144
152
  setKeyboardVisible(e) {
145
- e && l !== null && !c ? (t.focus({ preventScroll: !0 }), C(!0), d()) : (t.blur(), C(!1));
153
+ e && l !== null && !f ? (i.focus({ preventScroll: !0 }), T(!0), p()) : (i.blur(), T(!1));
146
154
  },
147
- release: A,
148
- reset: y,
155
+ release: E,
156
+ reset: g,
149
157
  dispose() {
150
- if (!c) {
151
- y(), c = !0, l = null;
152
- for (const e of z) e();
153
- t.remove(), C(!1);
158
+ if (!f) {
159
+ g(), f = !0, l = null;
160
+ for (const e of V) e();
161
+ i.remove(), T(!1);
154
162
  }
155
163
  }
156
164
  };
157
165
  }
158
166
  export {
159
- W as createRemoteInput
167
+ j as createRemoteInput
160
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.86.14",
3
+ "version": "0.86.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +0,0 @@
1
- function r(o) {
2
- throw new Error('Could not dynamically require "' + o + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3
- }
4
- export {
5
- r as commonjsRequire
6
- };
@@ -1,6 +0,0 @@
1
- function e(t) {
2
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
3
- }
4
- export {
5
- e as getDefaultExportFromCjs
6
- };
@@ -1,7 +0,0 @@
1
- import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as e } from "../node_modules/.pnpm/elkjs@0.12.0/node_modules/elkjs/lib/elk-api.js";
3
- var o = e();
4
- const i = /* @__PURE__ */ r(o);
5
- export {
6
- i as default
7
- };
@@ -1,4 +0,0 @@
1
- var e = { exports: {} };
2
- export {
3
- e as __module
4
- };
@@ -1,160 +0,0 @@
1
- import { applyGraphPositions as G } from "./positions.js";
2
- import { computePackedGraphLayout as k } from "./packing.js";
3
- function $(d) {
4
- const r = /* @__PURE__ */ new Set(), c = (t) => {
5
- if (!t || r.has(t)) throw new Error(`Duplicate or empty graph ID: ${t}`);
6
- r.add(t);
7
- }, i = new Map(d.nodes.map((t) => [t.id, t]));
8
- for (const t of d.nodes) {
9
- if (c(t.id), ![t.width, t.height].every((n) => Number.isFinite(n) && n > 0))
10
- throw new Error(`Invalid dimensions for graph node: ${t.id}`);
11
- for (const n of t.ports ?? []) c(n.id);
12
- const s = /* @__PURE__ */ new Set([t.id]);
13
- let o = t.parentId;
14
- for (; o !== void 0; ) {
15
- const n = i.get(o);
16
- if (!n || n.kind !== "group")
17
- throw new Error(`Invalid parent for graph node: ${t.id}`);
18
- if (s.has(o)) throw new Error(`Cyclic graph containment: ${t.id}`);
19
- s.add(o), o = n.parentId;
20
- }
21
- }
22
- for (const t of d.edges) {
23
- c(t.id);
24
- for (const [s, o] of [
25
- [t.source, t.sourcePort],
26
- [t.target, t.targetPort]
27
- ]) {
28
- const n = i.get(s);
29
- if (!n || o !== void 0 && !n.ports?.some((h) => h.id === o))
30
- throw new Error(`Invalid endpoint for graph edge: ${t.id}`);
31
- }
32
- }
33
- }
34
- async function P(d, r, c) {
35
- if ($(d), r.edgeClearance !== void 0 && (!Number.isFinite(r.edgeClearance) || r.edgeClearance < 0))
36
- throw new Error("Graph edge clearance must be finite and nonnegative");
37
- const i = N(d, r);
38
- if (r.aspectRatio !== void 0 && (!Number.isFinite(r.aspectRatio) || r.aspectRatio <= 0))
39
- throw new Error("Graph layout aspect ratio must be finite and positive");
40
- const t = r.groupPadding ?? { top: 64, right: 28, bottom: 28, left: 28 };
41
- if (![...Object.values(t), r.spacing ?? 64].every((e) => Number.isFinite(e) && e >= 0))
42
- throw new Error("Graph layout spacing must be finite and nonnegative");
43
- if (r.layers && (O(d, r.layers), r.positionMode === "fixed" && r.positions?.length))
44
- throw new Error("Fixed positions cannot be combined with graph layers");
45
- if (r.aspectRatio !== void 0 || r.layers)
46
- return k(i, r, c);
47
- const s = /* @__PURE__ */ new Map();
48
- for (const e of i.nodes)
49
- s.set(e.id, {
50
- id: e.id,
51
- width: e.width,
52
- height: e.height,
53
- ...e.kind === "group" ? { children: [] } : {},
54
- ports: e.ports?.map((a) => ({
55
- id: a.id,
56
- width: 1,
57
- height: 1,
58
- layoutOptions: { "elk.port.side": a.side }
59
- })),
60
- layoutOptions: {
61
- "elk.portConstraints": "FIXED_ORDER",
62
- "elk.padding": `[top=${t.top},left=${t.left},bottom=${t.bottom},right=${t.right}]`
63
- }
64
- });
65
- const o = [];
66
- for (const e of i.nodes)
67
- (e.parentId ? s.get(e.parentId).children : o).push(s.get(e.id));
68
- const n = /* @__PURE__ */ new Set([
69
- ...i.nodes.flatMap((e) => [e.id, ...(e.ports ?? []).map((a) => a.id)]),
70
- ...i.edges.map((e) => e.id)
71
- ]);
72
- let h = "$graph";
73
- for (; n.has(h); ) h += "$";
74
- const p = await c.layout({
75
- id: h,
76
- children: o,
77
- edges: i.edges.map((e) => ({
78
- id: e.id,
79
- sources: [e.sourcePort ?? e.source],
80
- targets: [e.targetPort ?? e.target]
81
- })),
82
- layoutOptions: {
83
- "elk.algorithm": "layered",
84
- "elk.direction": r.direction ?? "RIGHT",
85
- "elk.edgeRouting": "ORTHOGONAL",
86
- "elk.hierarchyHandling": "INCLUDE_CHILDREN",
87
- "elk.spacing.nodeNode": String(r.spacing ?? 64),
88
- "elk.layered.spacing.nodeNodeBetweenLayers": String(r.spacing ?? 64),
89
- "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
90
- "elk.randomSeed": "1"
91
- }
92
- }), y = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), x = (e) => {
93
- for (const a of e.edges ?? []) {
94
- const g = a.container ?? e.id, f = y.get(g) ?? { x: 0, y: 0 };
95
- E.set(
96
- a.id,
97
- (a.sections ?? []).map(
98
- (l) => [l.startPoint, ...l.bendPoints ?? [], l.endPoint].map((m) => ({
99
- x: m.x + f.x,
100
- y: m.y + f.y
101
- }))
102
- )
103
- );
104
- }
105
- for (const a of e.children ?? []) x(a);
106
- }, v = (e, a, g) => {
107
- const f = a + (e.x ?? 0), l = g + (e.y ?? 0);
108
- y.set(e.id, { x: f, y: l, width: e.width ?? 0, height: e.height ?? 0 });
109
- for (const m of e.children ?? []) v(m, f, l);
110
- };
111
- for (const e of p.children ?? []) v(e, 0, 0);
112
- x(p);
113
- const w = (!r.positions?.length || r.positionMode === "compact") && r.anchor && y.get(r.anchor.nodeId), u = w ? r.anchor.position.x - w.x : 0, I = w ? r.anchor.position.y - w.y : 0, b = i.nodes.map((e) => {
114
- const a = y.get(e.id);
115
- return { ...e, ...a, x: a.x + u, y: a.y + I };
116
- });
117
- return G(
118
- {
119
- nodes: b,
120
- edges: i.edges.map((e) => ({
121
- ...e,
122
- sections: (E.get(e.id) ?? []).map(
123
- (a) => a.map((g) => ({ x: g.x + u, y: g.y + I }))
124
- )
125
- })),
126
- bounds: { x: u, y: I, width: p.width ?? 0, height: p.height ?? 0 }
127
- },
128
- r,
129
- i.nodes
130
- );
131
- }
132
- function N(d, r) {
133
- if (r.positionMode !== "compact" || !r.positions?.length) return d;
134
- const c = r.direction ?? "RIGHT", i = new Map(
135
- r.positions.map((o) => [
136
- o.nodeId,
137
- c === "RIGHT" || c === "LEFT" ? o.y : o.x
138
- ])
139
- ), t = new Map(d.nodes.map((o, n) => [o.id, n]));
140
- return { nodes: [...d.nodes].sort((o, n) => {
141
- const h = (o.parentId ?? "").localeCompare(n.parentId ?? ""), p = r.layers && !o.parentId && !n.parentId ? 0 : (i.get(o.id) ?? 1 / 0) - (i.get(n.id) ?? 1 / 0);
142
- return h || p || t.get(o.id) - t.get(n.id);
143
- }), edges: d.edges };
144
- }
145
- function O(d, r) {
146
- const c = new Map(d.nodes.map((t) => [t.id, t])), i = /* @__PURE__ */ new Set();
147
- for (const [t, s] of r.entries()) {
148
- if (!s.length) throw new Error(`Graph layer must not be empty: ${t}`);
149
- for (const o of s) {
150
- const n = c.get(o);
151
- if (!n || n.parentId) throw new Error(`Graph layer object must be a root node: ${o}`);
152
- if (i.has(o)) throw new Error(`Graph object appears in multiple layers: ${o}`);
153
- i.add(o);
154
- }
155
- }
156
- }
157
- export {
158
- P as computeGraphLayout,
159
- $ as validateGraphInput
160
- };
@@ -1,158 +0,0 @@
1
- import { applyGraphPositions as $ } from "./positions.js";
2
- import { routeGraphGeometry as P } from "./routing.js";
3
- async function j(f, s, S) {
4
- const y = new Map(f.nodes.map((e) => [e.id, { ...e, x: 0, y: 0 }])), O = new Map(f.nodes.map((e, d) => [e.id, d])), m = /* @__PURE__ */ new Map();
5
- for (const e of y.values()) {
6
- const d = m.get(e.parentId) ?? [];
7
- d.push(e), m.set(e.parentId, d);
8
- }
9
- const p = /* @__PURE__ */ new Set([
10
- ...f.nodes.flatMap((e) => [e.id, ...(e.ports ?? []).map((d) => d.id)]),
11
- ...f.edges.map((e) => e.id)
12
- ]);
13
- let T = "$packed";
14
- for (; p.has(T); ) T += "$";
15
- const k = s.groupPadding ?? { top: 64, right: 28, bottom: 28, left: 28 }, E = s.direction ?? "RIGHT", w = new Map(
16
- (s.positions ?? []).map((e) => [
17
- e.nodeId,
18
- E === "RIGHT" || E === "LEFT" ? e.y : e.x
19
- ])
20
- ), I = (e, d, i) => {
21
- e.x += d, e.y += i;
22
- for (const v of m.get(e.id) ?? []) I(v, d, i);
23
- }, x = (e, d) => {
24
- let i = y.get(e);
25
- for (; i && i.parentId !== d; )
26
- i = i.parentId ? y.get(i.parentId) : void 0;
27
- return i;
28
- }, G = async (e) => {
29
- const d = [...m.get(e) ?? []];
30
- (e !== void 0 || !s.layers) && d.sort(
31
- (o, a) => (w.get(o.id) ?? 1 / 0) - (w.get(a.id) ?? 1 / 0) || O.get(o.id) - O.get(a.id)
32
- );
33
- for (const o of d) {
34
- if (!m.has(o.id)) continue;
35
- const a = await G(o.id);
36
- o.width = Math.max(o.width, a.width), o.height = Math.max(o.height, a.height);
37
- }
38
- if (!d.length) return { width: 0, height: 0 };
39
- if (e === void 0 && s.layers)
40
- return z(d, f, s, x, I);
41
- const i = /* @__PURE__ */ new Map();
42
- for (const o of f.edges) {
43
- const a = x(o.source, e), M = x(o.target, e);
44
- if (!a || !M || a.id === M.id) continue;
45
- const H = JSON.stringify([a.id, M.id]);
46
- i.has(H) || i.set(H, { id: o.id, sources: [a.id], targets: [M.id] });
47
- }
48
- const v = await S.layout({
49
- id: e ?? T,
50
- children: d.map((o) => ({ id: o.id, width: o.width, height: o.height })),
51
- edges: [...i.values()],
52
- layoutOptions: {
53
- "elk.algorithm": i.size ? "layered" : "rectpacking",
54
- "elk.direction": E,
55
- "elk.edgeRouting": "ORTHOGONAL",
56
- "elk.separateConnectedComponents": "true",
57
- ...s.aspectRatio !== void 0 ? { "elk.aspectRatio": String(s.aspectRatio) } : {},
58
- "elk.spacing.componentComponent": String(s.spacing ?? 64),
59
- "elk.spacing.nodeNode": String(s.spacing ?? 64),
60
- "elk.layered.spacing.nodeNodeBetweenLayers": String(s.spacing ?? 64),
61
- "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
62
- "elk.padding": e ? `[top=${k.top},left=${k.left},bottom=${k.bottom},right=${k.right}]` : "[top=12,left=12,bottom=12,right=12]",
63
- "elk.randomSeed": "1"
64
- }
65
- });
66
- for (const o of v.children ?? []) {
67
- const a = y.get(o.id);
68
- I(a, (o.x ?? 0) - a.x, (o.y ?? 0) - a.y);
69
- }
70
- return { width: v.width ?? 0, height: v.height ?? 0 };
71
- }, u = await G(), R = (!s.positions?.length || s.positionMode === "compact" || s.layers) && s.anchor && y.get(s.anchor.nodeId);
72
- if (R) {
73
- const e = s.anchor.position.x - R.x, d = s.anchor.position.y - R.y;
74
- for (const i of m.get(void 0) ?? []) I(i, e, d);
75
- }
76
- const C = {
77
- nodes: [...y.values()],
78
- edges: f.edges.map((e) => ({ ...e, sections: [] })),
79
- bounds: { x: 0, y: 0, ...u }
80
- };
81
- return s.positions?.length && s.positionMode !== "compact" && !s.layers ? $(C, s, f.nodes) : P(C, s);
82
- }
83
- function z(f, s, S, y, O) {
84
- const m = S.direction ?? "RIGHT", p = m === "RIGHT" || m === "LEFT", T = m === "RIGHT" || m === "DOWN", k = new Map(f.map((t, n) => [t.id, n])), E = new Map(
85
- (S.positions ?? []).filter((t) => k.has(t.nodeId)).map((t) => [t.nodeId, p ? t.y : t.x])
86
- ), w = (t, n) => k.get(t) - k.get(n) || t.localeCompare(n), I = (t, n) => (E.get(t) ?? 1 / 0) - (E.get(n) ?? 1 / 0) || w(t, n), x = new Map(f.map((t) => [t.id, /* @__PURE__ */ new Set()]));
87
- for (const t of s.edges) {
88
- const n = y(t.source, void 0)?.id, r = y(t.target, void 0)?.id;
89
- n && r && n !== r && (x.get(n)?.add(r), x.get(r)?.add(n));
90
- }
91
- const G = S.layers ?? [], u = /* @__PURE__ */ new Map();
92
- G.forEach((t, n) => t.forEach((r) => u.set(r, n)));
93
- const R = new Set(f.map((t) => t.id)), C = [];
94
- for (const t of [...R].sort(w)) {
95
- if (!R.has(t)) continue;
96
- const n = [], r = [t];
97
- R.delete(t);
98
- for (let c = 0; c < r.length; c++) {
99
- const g = r[c];
100
- n.push(g);
101
- for (const h of [...x.get(g)].sort(w))
102
- R.delete(h) && r.push(h);
103
- }
104
- C.push(n);
105
- }
106
- let e = G.length;
107
- for (const t of C) {
108
- const n = t.filter((g) => u.has(g));
109
- if (!n.length) {
110
- t.sort(w).forEach((g) => u.set(g, e)), e++;
111
- continue;
112
- }
113
- const r = /* @__PURE__ */ new Map(), c = [...n].sort((g, h) => u.get(g) - u.get(h) || w(g, h));
114
- for (const g of c) r.set(g, 0);
115
- for (let g = 0; g < c.length; g++) {
116
- const h = c[g];
117
- for (const l of [...x.get(h)].sort(w))
118
- r.has(l) || (r.set(l, r.get(h) + 1), u.set(l, u.get(h)), c.push(l));
119
- }
120
- }
121
- const d = Math.max(G.length, e), i = Array.from({ length: d }, () => []);
122
- for (const t of f) i[u.get(t.id)].push(t);
123
- for (const t of i) t.sort((n, r) => I(n.id, r.id));
124
- const v = (t, n) => {
125
- const r = new Map(i[n].map((h, l) => [h.id, l])), c = new Map(i[t].map((h, l) => [h.id, l])), g = (h) => {
126
- const l = [...x.get(h) ?? []].flatMap((N) => {
127
- const b = r.get(N);
128
- return u.get(N) === n && b !== void 0 ? [b] : [];
129
- });
130
- return l.length ? l.reduce((N, b) => N + b, 0) / l.length : c.get(h);
131
- };
132
- i[t].sort((h, l) => g(h.id) - g(l.id) || I(h.id, l.id));
133
- };
134
- for (let t = 1; t < i.length; t++) v(t, t - 1);
135
- for (let t = i.length - 2; t >= 0; t--) v(t, t + 1);
136
- const o = S.spacing ?? 64;
137
- let a = 0, M = 0;
138
- const H = [], L = [];
139
- for (const t of i) {
140
- let n = 0;
141
- const r = Math.max(0, ...t.map((c) => p ? c.width : c.height));
142
- H.push(a), L.push(r);
143
- for (const c of t) {
144
- const g = a + (r - (p ? c.width : c.height)) / 2, h = p ? g : n, l = p ? n : g;
145
- O(c, h - c.x, l - c.y), n += (p ? c.height : c.width) + o;
146
- }
147
- M = Math.max(M, Math.max(0, n - o)), a += r + o;
148
- }
149
- if (a = Math.max(0, a - o), !T)
150
- for (const t of f) {
151
- const n = u.get(t.id), c = a - H[n] - L[n] + (L[n] - (p ? t.width : t.height)) / 2;
152
- O(t, p ? c - t.x : 0, p ? 0 : c - t.y);
153
- }
154
- return p ? { width: a, height: M } : { width: M, height: a };
155
- }
156
- export {
157
- j as computePackedGraphLayout
158
- };