@p10node/mermaid 0.0.0-stage → 0.11.1
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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/index.d.ts +16 -0
- package/dist/index.js +3144 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,3144 @@
|
|
|
1
|
+
function e(e, t, n, r) {
|
|
2
|
+
let i = e.length, a = n.length, o = Array.from({ length: i }, () => []), s = Array(i).fill(!0);
|
|
3
|
+
t.forEach((e, t) => {
|
|
4
|
+
e.v !== e.w && (o[e.v].push(t), s[e.w] = !1);
|
|
5
|
+
});
|
|
6
|
+
let c = Array(t.length).fill(!1), l = new Uint8Array(i), u = [...Array.from({ length: i }, (e, t) => t).filter((e) => s[e]), ...Array.from({ length: i }, (e, t) => t)];
|
|
7
|
+
for (let e of u) {
|
|
8
|
+
if (l[e]) continue;
|
|
9
|
+
l[e] = 1;
|
|
10
|
+
let n = [[e, 0]];
|
|
11
|
+
for (; n.length;) {
|
|
12
|
+
let e = n[n.length - 1], r = e[0];
|
|
13
|
+
if (e[1] < o[r].length) {
|
|
14
|
+
let i = o[r][e[1]++], a = t[i].w;
|
|
15
|
+
l[a] === 1 ? c[i] = !0 : l[a] || (l[a] = 1, n.push([a, 0]));
|
|
16
|
+
} else l[r] = 2, n.pop();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let d = /* @__PURE__ */ new Map();
|
|
20
|
+
r.sameRank?.forEach((e, t) => e.forEach((e) => d.set(e, t)));
|
|
21
|
+
let f = t.map((e, t) => {
|
|
22
|
+
let n = d.has(e.v) && d.get(e.v) === d.get(e.w);
|
|
23
|
+
return c[t] ? {
|
|
24
|
+
v: e.w,
|
|
25
|
+
w: e.v,
|
|
26
|
+
minlen: n ? 0 : e.minlen,
|
|
27
|
+
weight: e.weight
|
|
28
|
+
} : {
|
|
29
|
+
v: e.v,
|
|
30
|
+
w: e.w,
|
|
31
|
+
minlen: n ? 0 : e.minlen,
|
|
32
|
+
weight: e.weight
|
|
33
|
+
};
|
|
34
|
+
}), p = Array.from({ length: i }, () => []), m = Array.from({ length: i }, () => []);
|
|
35
|
+
f.forEach((e, t) => {
|
|
36
|
+
e.v !== e.w && (m[e.v].push(t), p[e.w].push(t));
|
|
37
|
+
});
|
|
38
|
+
let h = [];
|
|
39
|
+
{
|
|
40
|
+
let e = p.map((e) => e.length), t = Array.from({ length: i }, (e, t) => t).filter((t) => !e[t]);
|
|
41
|
+
for (; t.length;) {
|
|
42
|
+
let n = t.shift();
|
|
43
|
+
h.push(n);
|
|
44
|
+
for (let r of m[n]) --e[f[r].w] || t.push(f[r].w);
|
|
45
|
+
}
|
|
46
|
+
if (h.length < i) for (let e = 0; e < i; e++) h.includes(e) || h.push(e);
|
|
47
|
+
}
|
|
48
|
+
let g = Array(i).fill(0), _ = () => {
|
|
49
|
+
for (let e of h) for (let t of m[e]) g[f[t].w] = Math.max(g[f[t].w], g[e] + f[t].minlen);
|
|
50
|
+
};
|
|
51
|
+
_();
|
|
52
|
+
for (let e = 0; e < 60; e++) {
|
|
53
|
+
let t = !1, n = e % 2 ? [...h].reverse() : h;
|
|
54
|
+
for (let e of n) {
|
|
55
|
+
if (d.has(e)) continue;
|
|
56
|
+
let n = -Infinity, r = Infinity, i = 0, a = 0;
|
|
57
|
+
for (let t of p[e]) n = Math.max(n, g[f[t].v] + f[t].minlen), i += f[t].weight;
|
|
58
|
+
for (let t of m[e]) r = Math.min(r, g[f[t].w] - f[t].minlen), a += f[t].weight;
|
|
59
|
+
let o = g[e];
|
|
60
|
+
i > a && n > -Infinity ? o = n : a > i && r < Infinity && (o = r), o !== g[e] && (g[e] = o, t = !0);
|
|
61
|
+
}
|
|
62
|
+
if (!t) break;
|
|
63
|
+
}
|
|
64
|
+
if (r.sameRank?.length) for (let e = 0; e < 12; e++) {
|
|
65
|
+
let e = !1;
|
|
66
|
+
for (let t of r.sameRank) {
|
|
67
|
+
let n = Math.max(...t.map((e) => g[e]));
|
|
68
|
+
for (let r of t) g[r] !== n && (g[r] = n, e = !0);
|
|
69
|
+
}
|
|
70
|
+
if (_(), !e) break;
|
|
71
|
+
}
|
|
72
|
+
let v = g.reduce((e, t) => Math.min(e, t), 0);
|
|
73
|
+
for (let e = 0; e < i; e++) g[e] -= v;
|
|
74
|
+
let y = g.reduce((e, t) => Math.max(e, t), 0), b = (e) => {
|
|
75
|
+
let t = [];
|
|
76
|
+
for (let r = e; r >= 0; r = n[r].parent) t.unshift(r);
|
|
77
|
+
return t;
|
|
78
|
+
}, x = (e, t) => {
|
|
79
|
+
let n = b(e), r = b(t), i = 0;
|
|
80
|
+
for (; i < n.length && i < r.length && n[i] === r[i];) i++;
|
|
81
|
+
return i ? n[i - 1] : -1;
|
|
82
|
+
}, S = e.map((e) => e.w), C = e.map((e) => e.h), w = e.map(() => 0), T = e.map((e) => e.cluster), E = [...g], D = e.map((e) => e.loop ?? 0), O = e.map(() => -1), k = (e, t, n, r, i) => (S.push(e), C.push(t), w.push(n), T.push(r), E.push(i), D.push(0), O.push(n === 2 || n === 3 ? r : -1), S.length - 1), A = [], j = [], ee = (e, t, n) => {
|
|
83
|
+
for (; A.length < S.length;) A.push([]), j.push([]);
|
|
84
|
+
j[e].push([t, n]), A[t].push([e, n]);
|
|
85
|
+
}, te = 6e4;
|
|
86
|
+
for (let e of f) te -= Math.max(0, Math.abs(g[e.w] - g[e.v]) - 1);
|
|
87
|
+
if (te < 0) throw Error("The diagram is too large to draw");
|
|
88
|
+
let M = [], ne = [];
|
|
89
|
+
f.forEach((e, n) => {
|
|
90
|
+
if (e.v === e.w) {
|
|
91
|
+
M.push(null), ne.push(-1);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
let r = [e.v], i = g[e.w] - g[e.v], a = t[n].label, o = a && i >= 2 ? g[e.v] + Math.floor(i / 2) : -1, s = x(T[e.v], T[e.w]), c = -1;
|
|
95
|
+
for (let t = g[e.v] + 1; t < g[e.w]; t++) {
|
|
96
|
+
let e = t === o ? k(a.w, a.h, 1, s, t) : k(0, 0, 1, s, t);
|
|
97
|
+
t === o && (c = e), r.push(e);
|
|
98
|
+
}
|
|
99
|
+
r.push(e.w), M.push(i > 0 ? r : null), ne.push(c);
|
|
100
|
+
for (let t = 0; t + 1 < r.length && !(i <= 0); t++) {
|
|
101
|
+
let n = r[t], i = r[t + 1], a = +(w[n] === 1) + +(w[i] === 1);
|
|
102
|
+
ee(n, i, e.weight * (a === 2 ? 8 : a === 1 ? 2 : 1));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
let re = f.map((e, t) => e.v !== e.w && g[e.v] === g[e.w] && !M[t]), N = Array(a).fill(Infinity), P = Array(a).fill(-Infinity);
|
|
106
|
+
for (let e = 0; e < S.length; e++) for (let t of b(T[e])) N[t] = Math.min(N[t], E[e]), P[t] = Math.max(P[t], E[e]);
|
|
107
|
+
let F = Array.from({ length: a }, () => []), I = Array.from({ length: a }, () => []), ie = [];
|
|
108
|
+
for (let e = 0; e < a; e++) if (!(N[e] > P[e])) for (let t = N[e]; t <= P[e]; t++) F[e][t] = k(0, 0, 2, e, t), I[e][t] = k(0, 0, 3, e, t);
|
|
109
|
+
for (; A.length < S.length;) A.push([]), j.push([]);
|
|
110
|
+
for (let e = 0; e < S.length; e++) ie.push([]);
|
|
111
|
+
for (let e = 0; e < a; e++) for (let t = N[e]; t < P[e]; t++) ie[F[e][t]].push([F[e][t + 1], 1]), ie[F[e][t + 1]].push([F[e][t], 1]), ie[I[e][t]].push([I[e][t + 1], 1]), ie[I[e][t + 1]].push([I[e][t], 1]);
|
|
112
|
+
let L = S.length;
|
|
113
|
+
y = E.reduce((e, t) => Math.max(e, t), y);
|
|
114
|
+
let R = Array.from({ length: y + 1 }, () => []);
|
|
115
|
+
{
|
|
116
|
+
let e = new Uint8Array(L), t = Array.from({ length: L }, (e, t) => t).filter((e) => w[e] !== 2 && w[e] !== 3).sort((e, t) => E[e] - E[t] || e - t);
|
|
117
|
+
for (let n of t) {
|
|
118
|
+
if (e[n]) continue;
|
|
119
|
+
let t = [n];
|
|
120
|
+
for (; t.length;) {
|
|
121
|
+
let n = t.pop();
|
|
122
|
+
if (!e[n]) {
|
|
123
|
+
e[n] = 1, R[E[n]].push(n);
|
|
124
|
+
for (let r = j[n].length - 1; r >= 0; r--) e[j[n][r][0]] || t.push(j[n][r][0]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (let e = 0; e < L; e++) (w[e] === 2 || w[e] === 3) && R[E[e]].push(e);
|
|
129
|
+
}
|
|
130
|
+
let z = new Float64Array(L), B = () => R.forEach((e) => e.forEach((e, t) => z[e] = t));
|
|
131
|
+
B();
|
|
132
|
+
let V = new Float64Array(L), H = new Float64Array(a), U = () => {
|
|
133
|
+
for (let e = 0; e < a; e++) {
|
|
134
|
+
if (N[e] > P[e]) continue;
|
|
135
|
+
let t = 0;
|
|
136
|
+
for (let n = N[e]; n <= P[e]; n++) t += z[F[e][n]] / Math.max(1, R[n].length);
|
|
137
|
+
H[e] = t / (P[e] - N[e] + 1);
|
|
138
|
+
}
|
|
139
|
+
}, W = (e, t) => {
|
|
140
|
+
if (!a) return [...e].sort((e, t) => V[e] - V[t] || z[e] - z[t]);
|
|
141
|
+
let r = {
|
|
142
|
+
node: -1,
|
|
143
|
+
cluster: -1,
|
|
144
|
+
key: 0,
|
|
145
|
+
idx: 0,
|
|
146
|
+
items: []
|
|
147
|
+
}, i = /* @__PURE__ */ new Map(), o = (e) => {
|
|
148
|
+
if (e < 0) return r;
|
|
149
|
+
let a = i.get(e);
|
|
150
|
+
return a || (a = {
|
|
151
|
+
node: -1,
|
|
152
|
+
cluster: e,
|
|
153
|
+
key: 0,
|
|
154
|
+
idx: z[F[e][t]] ?? 0,
|
|
155
|
+
items: []
|
|
156
|
+
}, i.set(e, a), o(n[e].parent).items.push(a)), a;
|
|
157
|
+
};
|
|
158
|
+
for (let t of e) w[t] === 2 ? o(O[t]) : w[t] !== 3 && o(T[t]).items.push({
|
|
159
|
+
node: t,
|
|
160
|
+
cluster: -1,
|
|
161
|
+
key: V[t],
|
|
162
|
+
idx: z[t],
|
|
163
|
+
items: []
|
|
164
|
+
});
|
|
165
|
+
let s = (e) => {
|
|
166
|
+
let n = 0, r = 0;
|
|
167
|
+
for (let t of e.items) if (t.node >= 0) n += t.key, r++;
|
|
168
|
+
else {
|
|
169
|
+
let [e, i] = s(t);
|
|
170
|
+
n += e, r += i;
|
|
171
|
+
}
|
|
172
|
+
e.cluster >= 0 && (e.key = r ? n / r : V[F[e.cluster][t]]), e.items.sort((e, t) => e.key - t.key || e.idx - t.idx);
|
|
173
|
+
let i = e.items.map((e, t) => e.cluster >= 0 ? t : -1).filter((e) => e >= 0), a = i.map((t) => e.items[t]).sort((e, t) => H[e.cluster] - H[t.cluster]);
|
|
174
|
+
return i.forEach((t, n) => e.items[t] = a[n]), [n, r];
|
|
175
|
+
};
|
|
176
|
+
s(r);
|
|
177
|
+
let c = [], l = (e) => {
|
|
178
|
+
for (let n of e.items) n.node >= 0 ? c.push(n.node) : (c.push(F[n.cluster][t]), l(n), c.push(I[n.cluster][t]));
|
|
179
|
+
};
|
|
180
|
+
return l(r), c;
|
|
181
|
+
}, G = (e) => {
|
|
182
|
+
let t = 0;
|
|
183
|
+
for (let n = 0; n + 1 < e.length; n++) {
|
|
184
|
+
let r = [];
|
|
185
|
+
for (let t of e[n]) for (let [e] of j[t]) r.push([z[t], z[e]]);
|
|
186
|
+
r.sort((e, t) => e[0] - t[0] || e[1] - t[1]);
|
|
187
|
+
let i = e[n + 1].length + 1, a = new Float64Array(i + 1);
|
|
188
|
+
for (let e = 0; e < r.length; e++) {
|
|
189
|
+
let n = 0;
|
|
190
|
+
for (let t = r[e][1] + 1; t > 0; t -= t & -t) n += a[t];
|
|
191
|
+
t += e - n;
|
|
192
|
+
for (let t = r[e][1] + 1; t <= i; t += t & -t) a[t]++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return t;
|
|
196
|
+
}, ae = (e, t) => {
|
|
197
|
+
let n = 0, r = 0;
|
|
198
|
+
for (let [i, a] of t[e]) n += z[i] * a, r += a;
|
|
199
|
+
return r ? n / r : z[e];
|
|
200
|
+
};
|
|
201
|
+
for (let e of R) for (let t of e) V[t] = z[t];
|
|
202
|
+
U(), R = R.map((e, t) => W(e, t)), B();
|
|
203
|
+
let oe = R.map((e) => [...e]), K = G(R);
|
|
204
|
+
for (let e = 0; e < 24 && K > 0; e++) {
|
|
205
|
+
U();
|
|
206
|
+
let t = e % 2 == 0;
|
|
207
|
+
for (let e = 1; e <= y; e++) {
|
|
208
|
+
let n = t ? e : y - e, r = t ? A : j;
|
|
209
|
+
for (let e of R[n]) V[e] = ae(e, r);
|
|
210
|
+
R[n] = W(R[n], n), R[n].forEach((e, t) => z[e] = t);
|
|
211
|
+
}
|
|
212
|
+
let n = G(R);
|
|
213
|
+
n < K && (K = n, oe = R.map((e) => [...e]));
|
|
214
|
+
}
|
|
215
|
+
R = oe, B();
|
|
216
|
+
let se = R.map((e) => e.reduce((e, t) => Math.max(e, C[t]), 0)), ce = Array.from({ length: a }, () => []);
|
|
217
|
+
n.forEach((e, t) => e.parent >= 0 && ce[e.parent].push(t));
|
|
218
|
+
let q = (e) => n[e].pad[2] + Math.max(0, ...ce[e].filter((t) => N[t] === N[e]).map(q)), le = (e) => n[e].pad[3] + Math.max(0, ...ce[e].filter((t) => P[t] === P[e]).map(le)), ue = Array(y + 1).fill(0), J = Array(y + 1).fill(0);
|
|
219
|
+
for (let e = 0; e < a; e++) N[e] > P[e] || (ue[N[e]] = Math.max(ue[N[e]], q(e)), J[P[e]] = Math.max(J[P[e]], le(e)));
|
|
220
|
+
let de = [];
|
|
221
|
+
for (let e = 0; e <= y; e++) de[e] = e === 0 ? se[0] / 2 + ue[0] : de[e - 1] + se[e - 1] / 2 + J[e - 1] + r.ranksep + ue[e] + se[e] / 2;
|
|
222
|
+
let Y = de[y] + se[y] / 2 + J[y], X = (e) => w[e] === 2 || w[e] === 3 ? 0 : S[e] / 2, fe = (e, t) => {
|
|
223
|
+
let i = D[e], a = w[e], o = w[t];
|
|
224
|
+
return a === 2 && (i += n[O[e]].pad[0]), a === 3 && (i += r.nodesep / 2), o === 3 && (i += n[O[t]].pad[1]), o === 2 && (i += r.nodesep / 2), a < 2 && o < 2 && (i += a === 1 && o === 1 ? r.edgesep : a === 1 || o === 1 ? (r.nodesep + r.edgesep) / 2 : r.nodesep), X(e) + X(t) + i;
|
|
225
|
+
}, Z = new Float64Array(L);
|
|
226
|
+
for (let e of R) for (let t = 1; t < e.length; t++) Z[e[t]] = Z[e[t - 1]] + fe(e[t - 1], e[t]);
|
|
227
|
+
let pe = (e, t, n) => {
|
|
228
|
+
let r = e.length, i = [0];
|
|
229
|
+
for (let t = 1; t < r; t++) i[t] = i[t - 1] + fe(e[t - 1], e[t]);
|
|
230
|
+
let a = [];
|
|
231
|
+
for (let e = 0; e < r; e++) for (a.push({
|
|
232
|
+
s: e,
|
|
233
|
+
e,
|
|
234
|
+
w: n[e],
|
|
235
|
+
wt: n[e] * (t[e] - i[e])
|
|
236
|
+
}); a.length > 1;) {
|
|
237
|
+
let e = a[a.length - 2], t = a[a.length - 1];
|
|
238
|
+
if (e.wt / e.w < t.wt / t.w) break;
|
|
239
|
+
e.e = t.e, e.w += t.w, e.wt += t.wt, a.pop();
|
|
240
|
+
}
|
|
241
|
+
for (let t of a) for (let n = t.s; n <= t.e; n++) Z[e[n]] = t.wt / t.w + i[n];
|
|
242
|
+
};
|
|
243
|
+
for (let e = 0; e < 10; e++) {
|
|
244
|
+
let t = e >= 8, n = e % 2 == 0;
|
|
245
|
+
for (let e = 0; e <= y; e++) {
|
|
246
|
+
let r = n ? e : y - e, i = R[r];
|
|
247
|
+
if (!i.length) continue;
|
|
248
|
+
let a = [], o = [];
|
|
249
|
+
for (let e of i) {
|
|
250
|
+
let r = 0, i = 0, s = (e) => {
|
|
251
|
+
for (let [t, n] of e) r += Z[t] * n, i += n;
|
|
252
|
+
};
|
|
253
|
+
(t || n) && s(A[e]), (t || !n) && s(j[e]), s(ie[e]), a.push(i ? r / i : Z[e]), o.push(i || .01);
|
|
254
|
+
}
|
|
255
|
+
pe(i, a, o);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
let me = L, Q = (e) => w[e] === 2 ? me + 2 * O[e] : w[e] === 3 ? me + 2 * O[e] + 1 : e;
|
|
259
|
+
if (a) {
|
|
260
|
+
let e = L + 2 * a, t = new Float64Array(e);
|
|
261
|
+
for (let e = 0; e < L; e++) t[e] = Z[e];
|
|
262
|
+
for (let e = 0; e < a; e++) t[me + 2 * e] = Infinity, t[me + 2 * e + 1] = -Infinity;
|
|
263
|
+
for (let e = 0; e < L; e++) w[e] === 2 && (t[Q(e)] = Math.min(t[Q(e)], Z[e])), w[e] === 3 && (t[Q(e)] = Math.max(t[Q(e)], Z[e]));
|
|
264
|
+
let r = Array.from({ length: e }, () => []), i = new Int32Array(e), o = (e, t, n) => {
|
|
265
|
+
r[e].push([t, n]), i[t]++;
|
|
266
|
+
};
|
|
267
|
+
for (let e of R) for (let t = 1; t < e.length; t++) o(Q(e[t - 1]), Q(e[t]), fe(e[t - 1], e[t]));
|
|
268
|
+
for (let e = 0; e < a; e++) N[e] <= P[e] && o(me + 2 * e, me + 2 * e + 1, Math.max(n[e].minW, n[e].pad[0] + n[e].pad[1]));
|
|
269
|
+
let s = [];
|
|
270
|
+
for (let t = 0; t < e; t++) i[t] || s.push(t);
|
|
271
|
+
let c = 0, l = new Float64Array(t);
|
|
272
|
+
for (; s.length;) {
|
|
273
|
+
let e = s.pop();
|
|
274
|
+
c++;
|
|
275
|
+
for (let [t, n] of r[e]) Number.isFinite(l[e]) && (l[t] = Math.max(l[t], l[e] + n)), --i[t] || s.push(t);
|
|
276
|
+
}
|
|
277
|
+
if (c === e) for (let e = 0; e < L; e++) Z[e] = l[Q(e)];
|
|
278
|
+
}
|
|
279
|
+
let he = Infinity, ge = -Infinity;
|
|
280
|
+
for (let e = 0; e < L; e++) he = Math.min(he, Z[e] - X(e)), ge = Math.max(ge, Z[e] + X(e) + D[e]);
|
|
281
|
+
Number.isFinite(he) || (he = ge = 0);
|
|
282
|
+
for (let e = 0; e < L; e++) Z[e] -= he;
|
|
283
|
+
let _e = (e) => ({
|
|
284
|
+
x: Z[e],
|
|
285
|
+
y: de[E[e]]
|
|
286
|
+
}), ve = /* @__PURE__ */ new Map();
|
|
287
|
+
{
|
|
288
|
+
let t = /* @__PURE__ */ new Map(), n = (e, n, r) => {
|
|
289
|
+
let i = t.get(e);
|
|
290
|
+
i || t.set(e, i = []), i.push({
|
|
291
|
+
i: n,
|
|
292
|
+
nx: r
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
f.forEach((t, r) => {
|
|
296
|
+
let i = M[r];
|
|
297
|
+
i && !re[r] && (e[i[0]]?.spread && n(`${i[0]}:b`, r, Z[i[1]]), e[i[i.length - 1]]?.spread && n(`${i[i.length - 1]}:t`, r, Z[i[i.length - 2]]));
|
|
298
|
+
});
|
|
299
|
+
for (let [e, n] of t) {
|
|
300
|
+
if (n.length < 2) continue;
|
|
301
|
+
let t = Number(e.split(":")[0]);
|
|
302
|
+
n.sort((e, t) => e.nx - t.nx || e.i - t.i);
|
|
303
|
+
let r = Math.min(36, S[t] * .7 / (n.length - 1));
|
|
304
|
+
n.forEach((i, a) => ve.set(`${e}:${i.i}`, Z[t] + (a - (n.length - 1) / 2) * r));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
let ye = f.map((e, n) => {
|
|
308
|
+
if (e.v === e.w) return null;
|
|
309
|
+
if (re[n]) {
|
|
310
|
+
let r = _e(e.v), i = _e(e.w), a = Math.sign(i.x - r.x) || 1, o = {
|
|
311
|
+
x: r.x + a * S[e.v] / 2,
|
|
312
|
+
y: r.y
|
|
313
|
+
}, s = {
|
|
314
|
+
x: i.x - a * S[e.w] / 2,
|
|
315
|
+
y: i.y
|
|
316
|
+
}, [l, u] = c[n] ? [s, o] : [o, s];
|
|
317
|
+
return {
|
|
318
|
+
start: l,
|
|
319
|
+
segs: [{
|
|
320
|
+
c: "L",
|
|
321
|
+
p: [u]
|
|
322
|
+
}],
|
|
323
|
+
label: t[n].label ? {
|
|
324
|
+
x: (l.x + u.x) / 2,
|
|
325
|
+
y: l.y - 10
|
|
326
|
+
} : void 0
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
let r = M[n];
|
|
330
|
+
if (!r) return null;
|
|
331
|
+
let i = [], a = [], o = _e(r[0]);
|
|
332
|
+
i.push({
|
|
333
|
+
x: ve.get(`${r[0]}:b:${n}`) ?? o.x,
|
|
334
|
+
y: o.y + C[r[0]] / 2
|
|
335
|
+
});
|
|
336
|
+
for (let e = 1; e + 1 < r.length; e++) {
|
|
337
|
+
let t = _e(r[e]), n = se[E[r[e]]] / 2;
|
|
338
|
+
n > .5 ? (i.push({
|
|
339
|
+
x: t.x,
|
|
340
|
+
y: t.y - n
|
|
341
|
+
}, {
|
|
342
|
+
x: t.x,
|
|
343
|
+
y: t.y + n
|
|
344
|
+
}), a.push(!1, !0)) : (i.push(t), a.push(!1));
|
|
345
|
+
}
|
|
346
|
+
let s = _e(r[r.length - 1]);
|
|
347
|
+
i.push({
|
|
348
|
+
x: ve.get(`${r[r.length - 1]}:t:${n}`) ?? s.x,
|
|
349
|
+
y: s.y - C[r[r.length - 1]] / 2
|
|
350
|
+
}), a.push(!1);
|
|
351
|
+
let l = i.length, u = Array(l).fill(0), d = (e) => (i[e + 1].x - i[e].x) / Math.max(.5, i[e + 1].y - i[e].y);
|
|
352
|
+
for (let e = 1; e + 1 < l; e++) {
|
|
353
|
+
if (a[e - 1] || a[e]) continue;
|
|
354
|
+
let t = d(e - 1), n = d(e);
|
|
355
|
+
if (t * n <= 0) continue;
|
|
356
|
+
let r = i[e].y - i[e - 1].y, o = i[e + 1].y - i[e].y;
|
|
357
|
+
u[e] = 3 * (r + o) / ((2 * o + r) / t + (o + 2 * r) / n);
|
|
358
|
+
}
|
|
359
|
+
let f = [];
|
|
360
|
+
for (let e = 1; e < l; e++) {
|
|
361
|
+
let t = i[e - 1], n = i[e], r = (n.y - t.y) / 3;
|
|
362
|
+
a[e - 1] || Math.abs(t.x - n.x) < .5 && !u[e - 1] && !u[e] ? f.push({
|
|
363
|
+
c: "L",
|
|
364
|
+
p: [n]
|
|
365
|
+
}) : f.push({
|
|
366
|
+
c: "C",
|
|
367
|
+
p: [
|
|
368
|
+
{
|
|
369
|
+
x: t.x + u[e - 1] * r,
|
|
370
|
+
y: t.y + r
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
x: n.x - u[e] * r,
|
|
374
|
+
y: n.y - r
|
|
375
|
+
},
|
|
376
|
+
n
|
|
377
|
+
]
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
let p = ne[n] >= 0 ? _e(ne[n]) : void 0;
|
|
381
|
+
if (!c[n]) return {
|
|
382
|
+
start: i[0],
|
|
383
|
+
segs: f,
|
|
384
|
+
label: p
|
|
385
|
+
};
|
|
386
|
+
let m = [];
|
|
387
|
+
for (let e = l - 1; e >= 1; e--) {
|
|
388
|
+
let t = f[e - 1];
|
|
389
|
+
m.push(t.c === "C" ? {
|
|
390
|
+
c: "C",
|
|
391
|
+
p: [
|
|
392
|
+
t.p[1],
|
|
393
|
+
t.p[0],
|
|
394
|
+
i[e - 1]
|
|
395
|
+
]
|
|
396
|
+
} : {
|
|
397
|
+
c: "L",
|
|
398
|
+
p: [i[e - 1]]
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
start: i[l - 1],
|
|
403
|
+
segs: m,
|
|
404
|
+
label: p
|
|
405
|
+
};
|
|
406
|
+
}), $ = n.map((e, t) => {
|
|
407
|
+
if (N[t] > P[t]) return null;
|
|
408
|
+
let n = Infinity, r = -Infinity;
|
|
409
|
+
for (let e = N[t]; e <= P[t]; e++) n = Math.min(n, Z[F[t][e]]), r = Math.max(r, Z[I[t][e]]);
|
|
410
|
+
let i = de[N[t]] - se[N[t]] / 2 - q(t), a = de[P[t]] + se[P[t]] / 2 + le(t);
|
|
411
|
+
return {
|
|
412
|
+
x: n,
|
|
413
|
+
y: i,
|
|
414
|
+
w: r - n,
|
|
415
|
+
h: a - i
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
return {
|
|
419
|
+
nodes: Array.from({ length: i }, (e, t) => _e(t)),
|
|
420
|
+
edges: ye,
|
|
421
|
+
clusters: $,
|
|
422
|
+
w: ge - he,
|
|
423
|
+
h: Y
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
// src/core/diagram/svg.ts
|
|
427
|
+
var t = [
|
|
428
|
+
278,
|
|
429
|
+
278,
|
|
430
|
+
355,
|
|
431
|
+
556,
|
|
432
|
+
556,
|
|
433
|
+
889,
|
|
434
|
+
667,
|
|
435
|
+
191,
|
|
436
|
+
333,
|
|
437
|
+
333,
|
|
438
|
+
389,
|
|
439
|
+
584,
|
|
440
|
+
278,
|
|
441
|
+
333,
|
|
442
|
+
278,
|
|
443
|
+
278,
|
|
444
|
+
556,
|
|
445
|
+
556,
|
|
446
|
+
556,
|
|
447
|
+
556,
|
|
448
|
+
556,
|
|
449
|
+
556,
|
|
450
|
+
556,
|
|
451
|
+
556,
|
|
452
|
+
556,
|
|
453
|
+
556,
|
|
454
|
+
278,
|
|
455
|
+
278,
|
|
456
|
+
584,
|
|
457
|
+
584,
|
|
458
|
+
584,
|
|
459
|
+
556,
|
|
460
|
+
1015,
|
|
461
|
+
667,
|
|
462
|
+
667,
|
|
463
|
+
722,
|
|
464
|
+
722,
|
|
465
|
+
667,
|
|
466
|
+
611,
|
|
467
|
+
778,
|
|
468
|
+
722,
|
|
469
|
+
278,
|
|
470
|
+
500,
|
|
471
|
+
667,
|
|
472
|
+
556,
|
|
473
|
+
833,
|
|
474
|
+
722,
|
|
475
|
+
778,
|
|
476
|
+
667,
|
|
477
|
+
778,
|
|
478
|
+
722,
|
|
479
|
+
667,
|
|
480
|
+
611,
|
|
481
|
+
722,
|
|
482
|
+
667,
|
|
483
|
+
944,
|
|
484
|
+
667,
|
|
485
|
+
667,
|
|
486
|
+
611,
|
|
487
|
+
278,
|
|
488
|
+
278,
|
|
489
|
+
278,
|
|
490
|
+
469,
|
|
491
|
+
556,
|
|
492
|
+
333,
|
|
493
|
+
556,
|
|
494
|
+
556,
|
|
495
|
+
500,
|
|
496
|
+
556,
|
|
497
|
+
556,
|
|
498
|
+
278,
|
|
499
|
+
556,
|
|
500
|
+
556,
|
|
501
|
+
222,
|
|
502
|
+
222,
|
|
503
|
+
500,
|
|
504
|
+
222,
|
|
505
|
+
833,
|
|
506
|
+
556,
|
|
507
|
+
556,
|
|
508
|
+
556,
|
|
509
|
+
556,
|
|
510
|
+
333,
|
|
511
|
+
500,
|
|
512
|
+
278,
|
|
513
|
+
556,
|
|
514
|
+
500,
|
|
515
|
+
722,
|
|
516
|
+
500,
|
|
517
|
+
500,
|
|
518
|
+
500,
|
|
519
|
+
334,
|
|
520
|
+
260,
|
|
521
|
+
334,
|
|
522
|
+
584
|
|
523
|
+
];
|
|
524
|
+
function n(e) {
|
|
525
|
+
return e >= 32 && e <= 126 ? t[e - 32] : e >= 768 && e <= 879 || e >= 8203 && e <= 8207 || e === 65039 ? 0 : e >= 4352 && e <= 4447 || e >= 11904 && e <= 42191 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65072 && e <= 65103 || e >= 65280 && e <= 65376 || e >= 126976 ? 1e3 : 580;
|
|
526
|
+
}
|
|
527
|
+
function r(e, t = 14, r = !1, i = !1) {
|
|
528
|
+
let a = 0;
|
|
529
|
+
if (i) for (let t of e) a += n(t.codePointAt(0)) ? 600 : 0;
|
|
530
|
+
else for (let t of e) a += n(t.codePointAt(0));
|
|
531
|
+
return a * t * (r ? 1.08 : 1) / 1e3;
|
|
532
|
+
}
|
|
533
|
+
var i = (e) => Math.round(e * 1.3);
|
|
534
|
+
function a(e, t = 14, n = !1) {
|
|
535
|
+
let a = 0;
|
|
536
|
+
for (let i of e) a = Math.max(a, r(i, t, n));
|
|
537
|
+
return {
|
|
538
|
+
w: a,
|
|
539
|
+
h: e.length * i(t)
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function o(e, t, n = 14, i = !1) {
|
|
543
|
+
let a = [];
|
|
544
|
+
for (let o of e) {
|
|
545
|
+
if (r(o, n, i) <= t) {
|
|
546
|
+
a.push(o);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
let e = "";
|
|
550
|
+
for (let s of o.split(/ +/)) {
|
|
551
|
+
let o = e ? e + " " + s : s;
|
|
552
|
+
e && r(o, n, i) > t ? (a.push(e), e = s) : e = o;
|
|
553
|
+
}
|
|
554
|
+
a.push(e);
|
|
555
|
+
}
|
|
556
|
+
return a;
|
|
557
|
+
}
|
|
558
|
+
var s = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), c = /^[a-z]{3,24}$/;
|
|
559
|
+
function l(e) {
|
|
560
|
+
if (!e) return;
|
|
561
|
+
let t = e.trim().toLowerCase();
|
|
562
|
+
if (/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(t)) return t;
|
|
563
|
+
if (/^[0-9a-f]{6}$/.test(t)) return "#" + t;
|
|
564
|
+
if (/^rgba?\(\s*[\d.]+%?\s*,\s*[\d.]+%?\s*,\s*[\d.]+%?\s*(,\s*[\d.]+%?\s*)?\)$/.test(t) || /^rgba?\(\s*[\d.]+%?\s+[\d.]+%?\s+[\d.]+%?\s*(\/\s*[\d.]+%?\s*)?\)$/.test(t)) return t;
|
|
565
|
+
if (c.test(t)) return t === "transparent" ? "none" : t;
|
|
566
|
+
}
|
|
567
|
+
var u = {
|
|
568
|
+
ink: "#1f2937",
|
|
569
|
+
line: "#4b5563",
|
|
570
|
+
fill: "#eef2fb",
|
|
571
|
+
stroke: "#5b6f9a",
|
|
572
|
+
muted: "#6b7280",
|
|
573
|
+
cluster: "#f7f8fb",
|
|
574
|
+
clusterStroke: "#a3adc2",
|
|
575
|
+
note: "#fff6c8",
|
|
576
|
+
noteStroke: "#c9a227",
|
|
577
|
+
label: "#ffffff",
|
|
578
|
+
dark: "#2d3748",
|
|
579
|
+
series: [
|
|
580
|
+
"#5b8def",
|
|
581
|
+
"#f2994a",
|
|
582
|
+
"#3fb68b",
|
|
583
|
+
"#e5596b",
|
|
584
|
+
"#9b6be0",
|
|
585
|
+
"#d4b33a",
|
|
586
|
+
"#3bb3c9",
|
|
587
|
+
"#e07bb8",
|
|
588
|
+
"#8c9aaf",
|
|
589
|
+
"#7cbd4a"
|
|
590
|
+
]
|
|
591
|
+
}, d = (e) => Number.isFinite(e) ? Math.round(e * 100) / 100 : 0;
|
|
592
|
+
function f(e) {
|
|
593
|
+
let t = ` fill="${e.fill ?? "none"}"`;
|
|
594
|
+
return e.stroke && (t += ` stroke="${e.stroke}" stroke-width="${d(e.sw ?? 1)}"`), e.stroke && e.dash && (t += ` stroke-dasharray="${e.dash}"`), e.opacity !== void 0 && (t += ` opacity="${d(e.opacity)}"`), t;
|
|
595
|
+
}
|
|
596
|
+
var p = class {
|
|
597
|
+
out = [];
|
|
598
|
+
rect(e, t, n, r, i, a = 0) {
|
|
599
|
+
return this.out.push(`<rect x="${d(e)}" y="${d(t)}" width="${d(n)}" height="${d(r)}"${a ? ` rx="${d(a)}"` : ""}${f(i)}/>`), this;
|
|
600
|
+
}
|
|
601
|
+
circle(e, t, n, r) {
|
|
602
|
+
return this.out.push(`<circle cx="${d(e)}" cy="${d(t)}" r="${d(n)}"${f(r)}/>`), this;
|
|
603
|
+
}
|
|
604
|
+
ellipse(e, t, n, r, i) {
|
|
605
|
+
return this.out.push(`<ellipse cx="${d(e)}" cy="${d(t)}" rx="${d(n)}" ry="${d(r)}"${f(i)}/>`), this;
|
|
606
|
+
}
|
|
607
|
+
line(e, t, n, r, i) {
|
|
608
|
+
return this.out.push(`<line x1="${d(e)}" y1="${d(t)}" x2="${d(n)}" y2="${d(r)}"${f(i)}/>`), this;
|
|
609
|
+
}
|
|
610
|
+
poly(e, t, n = !0) {
|
|
611
|
+
let r = e.map(([e, t]) => `${d(e)},${d(t)}`).join(" ");
|
|
612
|
+
return this.out.push(`<${n ? "polygon" : "polyline"} points="${r}"${f(t)}/>`), this;
|
|
613
|
+
}
|
|
614
|
+
path(e, t) {
|
|
615
|
+
return this.out.push(`<path d="${e}"${f(t)}/>`), this;
|
|
616
|
+
}
|
|
617
|
+
text(e, t, n, r = {}) {
|
|
618
|
+
let a = typeof n == "string" ? [n] : n, o = r.size ?? 14, c = i(o), l = t - a.length * c / 2, f = ` font-family="${s(r.mono ? "Menlo, Consolas, \"Courier New\", monospace" : "Helvetica, Arial, sans-serif")}" font-size="${o}" fill="${r.color ?? u.ink}"`;
|
|
619
|
+
return r.anchor && r.anchor !== "start" && (f += ` text-anchor="${r.anchor}"`), r.bold && (f += " font-weight=\"bold\""), r.italic && (f += " font-style=\"italic\""), r.underline && (f += " text-decoration=\"underline\""), a.forEach((t, n) => {
|
|
620
|
+
t && this.out.push(`<text x="${d(e)}" y="${d(l + n * c + c / 2 + o * .35)}"${f}>${s(t)}</text>`);
|
|
621
|
+
}), this;
|
|
622
|
+
}
|
|
623
|
+
raw(e) {
|
|
624
|
+
return this.out.push(e), this;
|
|
625
|
+
}
|
|
626
|
+
body() {
|
|
627
|
+
return this.out.join("");
|
|
628
|
+
}
|
|
629
|
+
toString(e, t, n = "#ffffff") {
|
|
630
|
+
let r = Math.ceil(e), i = Math.ceil(t);
|
|
631
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${i}" viewBox="0 0 ${r} ${i}">` + (n ? `<rect x="0" y="0" width="${r}" height="${i}" fill="${n}"/>` : "") + this.out.join("") + "</svg>";
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
function m(e) {
|
|
635
|
+
return e.map((e) => e.c + e.p.map((e) => `${d(e.x)} ${d(e.y)}`).join(" ")).join(" ");
|
|
636
|
+
}
|
|
637
|
+
function h(e) {
|
|
638
|
+
return e.replace(/<br\s*\/?>/gi, "\n").replace(/\\n/g, "\n").replace(/<\/?[a-z][^>]*>/gi, "").replace(/#(\d+);/g, (e, t) => String.fromCodePoint(Math.min(Number(t), 1114111))).replace(/#([a-z]+);/gi, (e, t) => ({
|
|
639
|
+
quot: "\"",
|
|
640
|
+
amp: "&",
|
|
641
|
+
lt: "<",
|
|
642
|
+
gt: ">",
|
|
643
|
+
nbsp: " ",
|
|
644
|
+
apos: "'"
|
|
645
|
+
})[t.toLowerCase()] ?? e).replace(/&(quot|amp|lt|gt|nbsp|apos|#\d+);/g, (e, t) => t[0] === "#" ? String.fromCodePoint(Math.min(Number(t.slice(1)), 1114111)) : {
|
|
646
|
+
quot: "\"",
|
|
647
|
+
amp: "&",
|
|
648
|
+
lt: "<",
|
|
649
|
+
gt: ">",
|
|
650
|
+
nbsp: " ",
|
|
651
|
+
apos: "'"
|
|
652
|
+
}[t] ?? e);
|
|
653
|
+
}
|
|
654
|
+
var g = (e) => e.replace(/\*\*(.+?)\*\*|__(.+?)__/g, "$1$2").replace(/(^|\W)[*_](\S.*?\S|\S)[*_](?=\W|$)/g, "$1$2"), _ = class extends Error {}, v = class {
|
|
655
|
+
defShape;
|
|
656
|
+
g;
|
|
657
|
+
byId = /* @__PURE__ */ new Map();
|
|
658
|
+
clusterIds = /* @__PURE__ */ new Map();
|
|
659
|
+
constructor(e = "TB", t = "rect") {
|
|
660
|
+
this.defShape = t, this.g = {
|
|
661
|
+
dir: e,
|
|
662
|
+
nodes: [],
|
|
663
|
+
edges: [],
|
|
664
|
+
clusters: []
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
has(e) {
|
|
668
|
+
return this.byId.has(e);
|
|
669
|
+
}
|
|
670
|
+
get(e) {
|
|
671
|
+
return this.byId.get(e);
|
|
672
|
+
}
|
|
673
|
+
node(e, t = {}, n) {
|
|
674
|
+
let r = this.byId.get(e);
|
|
675
|
+
r || (r = {
|
|
676
|
+
id: e,
|
|
677
|
+
label: e,
|
|
678
|
+
shape: this.defShape,
|
|
679
|
+
cluster: n
|
|
680
|
+
}, this.byId.set(e, r), this.g.nodes.push(r));
|
|
681
|
+
for (let [e, n] of Object.entries(t)) n !== void 0 && (r[e] = n);
|
|
682
|
+
return r;
|
|
683
|
+
}
|
|
684
|
+
edge(e, t) {
|
|
685
|
+
return this.clusterIds.has(e.from) || this.node(e.from, {}, t), this.clusterIds.has(e.to) || this.node(e.to, {}, t), this.g.edges.push(e), e;
|
|
686
|
+
}
|
|
687
|
+
cluster(e, t, n) {
|
|
688
|
+
let r = this.clusterIds.get(e);
|
|
689
|
+
r ? t && (r.label = t) : (r = {
|
|
690
|
+
id: e,
|
|
691
|
+
label: t,
|
|
692
|
+
parent: n
|
|
693
|
+
}, this.clusterIds.set(e, r), this.g.clusters.push(r));
|
|
694
|
+
let i = this.byId.get(e);
|
|
695
|
+
return i && (this.byId.delete(e), this.g.nodes.splice(this.g.nodes.indexOf(i), 1)), r;
|
|
696
|
+
}
|
|
697
|
+
isCluster(e) {
|
|
698
|
+
return this.clusterIds.has(e);
|
|
699
|
+
}
|
|
700
|
+
}, y = 14, b = 13, x = 14, S = 9, C = i(y), w = (e) => e.split("\n"), T = (e) => Math.round(e * 100) / 100;
|
|
701
|
+
function E(e) {
|
|
702
|
+
let t = [];
|
|
703
|
+
for (let n of e.rows) n.forEach((n, i) => t[i] = Math.max(t[i] ?? 0, r(n, b, e.bold)));
|
|
704
|
+
return {
|
|
705
|
+
w: t.reduce((e, t) => e + t, 0) + Math.max(0, t.length - 1) * 12,
|
|
706
|
+
h: e.rows.length ? e.rows.length * i(b) + 10 : 8,
|
|
707
|
+
cols: t
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
function D(e, t) {
|
|
711
|
+
let n = e.shape === "none" || e.label === "" ? w(e.label) : o(w(e.label), 260, y, e.style?.bold), r = e.label === "" ? {
|
|
712
|
+
w: 0,
|
|
713
|
+
h: 0
|
|
714
|
+
} : a(n, y, e.style?.bold), i = t === "TB" || t === "BT";
|
|
715
|
+
if (e.sections?.length) {
|
|
716
|
+
let t = e.sections.map(E);
|
|
717
|
+
return {
|
|
718
|
+
w: Math.max(90, ...t.map((e) => e.w + 28)),
|
|
719
|
+
h: t.reduce((e, t) => e + t.h, 0),
|
|
720
|
+
text: n
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
let s = r.w + 28, c = r.h + 18;
|
|
724
|
+
switch (e.shape) {
|
|
725
|
+
case "start": return {
|
|
726
|
+
w: 20,
|
|
727
|
+
h: 20,
|
|
728
|
+
text: []
|
|
729
|
+
};
|
|
730
|
+
case "end": return {
|
|
731
|
+
w: 22,
|
|
732
|
+
h: 22,
|
|
733
|
+
text: []
|
|
734
|
+
};
|
|
735
|
+
case "point": return {
|
|
736
|
+
w: 8,
|
|
737
|
+
h: 8,
|
|
738
|
+
text: []
|
|
739
|
+
};
|
|
740
|
+
case "bar": return i ? {
|
|
741
|
+
w: 80,
|
|
742
|
+
h: 7,
|
|
743
|
+
text: []
|
|
744
|
+
} : {
|
|
745
|
+
w: 7,
|
|
746
|
+
h: 80,
|
|
747
|
+
text: []
|
|
748
|
+
};
|
|
749
|
+
case "none": return {
|
|
750
|
+
w: r.w + 8,
|
|
751
|
+
h: r.h + 6,
|
|
752
|
+
text: n
|
|
753
|
+
};
|
|
754
|
+
case "circle": {
|
|
755
|
+
let e = Math.max(r.w, r.h) + 18 + 4;
|
|
756
|
+
return {
|
|
757
|
+
w: e,
|
|
758
|
+
h: e,
|
|
759
|
+
text: n
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
case "doublecircle": {
|
|
763
|
+
let e = Math.max(r.w, r.h) + 18 + 14;
|
|
764
|
+
return {
|
|
765
|
+
w: e,
|
|
766
|
+
h: e,
|
|
767
|
+
text: n
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
case "ellipse": return {
|
|
771
|
+
w: Math.max(50, (r.w + x) * 1.42),
|
|
772
|
+
h: Math.max(36, (r.h + S) * 1.42),
|
|
773
|
+
text: n
|
|
774
|
+
};
|
|
775
|
+
case "diamond": {
|
|
776
|
+
let e = s + c / .6;
|
|
777
|
+
return {
|
|
778
|
+
w: e,
|
|
779
|
+
h: .6 * e,
|
|
780
|
+
text: n
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
case "stadium": return {
|
|
784
|
+
w: r.w + c + x,
|
|
785
|
+
h: c,
|
|
786
|
+
text: n
|
|
787
|
+
};
|
|
788
|
+
case "hexagon":
|
|
789
|
+
case "octagon": return {
|
|
790
|
+
w: s + c / 2,
|
|
791
|
+
h: c,
|
|
792
|
+
text: n
|
|
793
|
+
};
|
|
794
|
+
case "lean-r":
|
|
795
|
+
case "lean-l": return {
|
|
796
|
+
w: s + c / 2,
|
|
797
|
+
h: c,
|
|
798
|
+
text: n
|
|
799
|
+
};
|
|
800
|
+
case "trap-b":
|
|
801
|
+
case "trap-t": return {
|
|
802
|
+
w: s + c * .7,
|
|
803
|
+
h: c,
|
|
804
|
+
text: n
|
|
805
|
+
};
|
|
806
|
+
case "flag": return {
|
|
807
|
+
w: s + c / 3,
|
|
808
|
+
h: c,
|
|
809
|
+
text: n
|
|
810
|
+
};
|
|
811
|
+
case "cylinder": return {
|
|
812
|
+
w: Math.max(s, 50),
|
|
813
|
+
h: c + 16,
|
|
814
|
+
text: n
|
|
815
|
+
};
|
|
816
|
+
case "subroutine":
|
|
817
|
+
case "component": return {
|
|
818
|
+
w: s + 16,
|
|
819
|
+
h: c,
|
|
820
|
+
text: n
|
|
821
|
+
};
|
|
822
|
+
case "note":
|
|
823
|
+
case "folder": return {
|
|
824
|
+
w: s + 8,
|
|
825
|
+
h: c + (e.shape === "folder" ? 8 : 0),
|
|
826
|
+
text: n
|
|
827
|
+
};
|
|
828
|
+
case "box3d": return {
|
|
829
|
+
w: s + 8,
|
|
830
|
+
h: c + 8,
|
|
831
|
+
text: n
|
|
832
|
+
};
|
|
833
|
+
case "triangle": return {
|
|
834
|
+
w: s * 1.6,
|
|
835
|
+
h: c * 1.7,
|
|
836
|
+
text: n
|
|
837
|
+
};
|
|
838
|
+
case "actor": return {
|
|
839
|
+
w: Math.max(36, r.w + 8),
|
|
840
|
+
h: 46 + r.h,
|
|
841
|
+
text: n
|
|
842
|
+
};
|
|
843
|
+
default: return {
|
|
844
|
+
w: Math.max(s, 40),
|
|
845
|
+
h: c,
|
|
846
|
+
text: n
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function O(e) {
|
|
851
|
+
let t = e.style ?? {};
|
|
852
|
+
return {
|
|
853
|
+
fill: t.fill ?? u.fill,
|
|
854
|
+
stroke: t.stroke ?? u.stroke,
|
|
855
|
+
sw: t.sw ?? 1.3,
|
|
856
|
+
dash: t.dash
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function k(e, t, n, r, i) {
|
|
860
|
+
let { w: a, h: o } = n, s = r - a / 2, c = i - o / 2, l = O(t), d = t.style?.color ?? u.ink, f = (a = r, o = i) => e.text(a, o, n.text, {
|
|
861
|
+
anchor: "middle",
|
|
862
|
+
color: d,
|
|
863
|
+
bold: t.style?.bold,
|
|
864
|
+
italic: t.style?.italic
|
|
865
|
+
}), p = (t) => e.poly(t, l);
|
|
866
|
+
switch (t.shape) {
|
|
867
|
+
case "start":
|
|
868
|
+
e.circle(r, i, a / 2, { fill: t.style?.fill ?? u.dark });
|
|
869
|
+
return;
|
|
870
|
+
case "end":
|
|
871
|
+
e.circle(r, i, a / 2, {
|
|
872
|
+
fill: "#ffffff",
|
|
873
|
+
stroke: t.style?.stroke ?? u.dark,
|
|
874
|
+
sw: 1.5
|
|
875
|
+
}).circle(r, i, a / 2 - 4, { fill: t.style?.fill ?? u.dark });
|
|
876
|
+
return;
|
|
877
|
+
case "point":
|
|
878
|
+
e.circle(r, i, a / 2, { fill: t.style?.fill ?? u.dark });
|
|
879
|
+
return;
|
|
880
|
+
case "bar":
|
|
881
|
+
e.rect(s, c, a, o, { fill: t.style?.fill ?? u.dark }, 2);
|
|
882
|
+
return;
|
|
883
|
+
case "none":
|
|
884
|
+
f();
|
|
885
|
+
return;
|
|
886
|
+
case "round":
|
|
887
|
+
e.rect(s, c, a, o, l, 6);
|
|
888
|
+
break;
|
|
889
|
+
case "stadium":
|
|
890
|
+
e.rect(s, c, a, o, l, o / 2);
|
|
891
|
+
break;
|
|
892
|
+
case "subroutine":
|
|
893
|
+
e.rect(s, c, a, o, l).line(s + 8, c, s + 8, c + o, l).line(s + a - 8, c, s + a - 8, c + o, l);
|
|
894
|
+
break;
|
|
895
|
+
case "component":
|
|
896
|
+
e.rect(s + 6, c, a - 6, o, l), e.rect(s, c + o / 2 - 11, 12, 7, l).rect(s, c + o / 2 + 4, 12, 7, l), f(r + 4);
|
|
897
|
+
return;
|
|
898
|
+
case "cylinder":
|
|
899
|
+
e.path(`M${T(s)} ${T(c + 7)} A${T(a / 2)} 7 0 0 1 ${T(s + a)} ${T(c + 7)} L${T(s + a)} ${T(c + o - 7)} A${T(a / 2)} 7 0 0 1 ${T(s)} ${T(c + o - 7)} Z`, l), e.path(`M${T(s)} ${T(c + 7)} A${T(a / 2)} 7 0 0 0 ${T(s + a)} ${T(c + 7)}`, {
|
|
900
|
+
...l,
|
|
901
|
+
fill: "none"
|
|
902
|
+
}), f(r, i + 7 / 2);
|
|
903
|
+
return;
|
|
904
|
+
case "circle":
|
|
905
|
+
e.circle(r, i, a / 2, l);
|
|
906
|
+
break;
|
|
907
|
+
case "doublecircle":
|
|
908
|
+
e.circle(r, i, a / 2, l).circle(r, i, a / 2 - 5, {
|
|
909
|
+
...l,
|
|
910
|
+
fill: "none"
|
|
911
|
+
});
|
|
912
|
+
break;
|
|
913
|
+
case "ellipse":
|
|
914
|
+
e.ellipse(r, i, a / 2, o / 2, l);
|
|
915
|
+
break;
|
|
916
|
+
case "diamond":
|
|
917
|
+
p([
|
|
918
|
+
[r, c],
|
|
919
|
+
[s + a, i],
|
|
920
|
+
[r, c + o],
|
|
921
|
+
[s, i]
|
|
922
|
+
]);
|
|
923
|
+
break;
|
|
924
|
+
case "hexagon": {
|
|
925
|
+
let e = o / 4;
|
|
926
|
+
p([
|
|
927
|
+
[s + e, c],
|
|
928
|
+
[s + a - e, c],
|
|
929
|
+
[s + a, i],
|
|
930
|
+
[s + a - e, c + o],
|
|
931
|
+
[s + e, c + o],
|
|
932
|
+
[s, i]
|
|
933
|
+
]);
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
case "octagon": {
|
|
937
|
+
let e = o / 4;
|
|
938
|
+
p([
|
|
939
|
+
[s + e, c],
|
|
940
|
+
[s + a - e, c],
|
|
941
|
+
[s + a, c + e],
|
|
942
|
+
[s + a, c + o - e],
|
|
943
|
+
[s + a - e, c + o],
|
|
944
|
+
[s + e, c + o],
|
|
945
|
+
[s, c + o - e],
|
|
946
|
+
[s, c + e]
|
|
947
|
+
]);
|
|
948
|
+
break;
|
|
949
|
+
}
|
|
950
|
+
case "lean-r":
|
|
951
|
+
case "lean-l": {
|
|
952
|
+
let e = o / 2, n = t.shape === "lean-r";
|
|
953
|
+
p([
|
|
954
|
+
[n ? s + e : s, c],
|
|
955
|
+
[n ? s + a : s + a - e, c],
|
|
956
|
+
[n ? s + a - e : s + a, c + o],
|
|
957
|
+
[n ? s : s + e, c + o]
|
|
958
|
+
]);
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
case "trap-b":
|
|
962
|
+
case "trap-t": {
|
|
963
|
+
let e = o * .35, n = t.shape === "trap-b";
|
|
964
|
+
p([
|
|
965
|
+
[n ? s + e : s, c],
|
|
966
|
+
[n ? s + a - e : s + a, c],
|
|
967
|
+
[n ? s + a : s + a - e, c + o],
|
|
968
|
+
[n ? s : s + e, c + o]
|
|
969
|
+
]);
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
case "flag": {
|
|
973
|
+
let e = o / 3;
|
|
974
|
+
p([
|
|
975
|
+
[s, c],
|
|
976
|
+
[s + a, c],
|
|
977
|
+
[s + a, c + o],
|
|
978
|
+
[s, c + o],
|
|
979
|
+
[s + e, i]
|
|
980
|
+
]), f(r + e / 2);
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
case "note":
|
|
984
|
+
p([
|
|
985
|
+
[s, c],
|
|
986
|
+
[s + a - 10, c],
|
|
987
|
+
[s + a, c + 10],
|
|
988
|
+
[s + a, c + o],
|
|
989
|
+
[s, c + o]
|
|
990
|
+
]), e.poly([
|
|
991
|
+
[s + a - 10, c],
|
|
992
|
+
[s + a - 10, c + 10],
|
|
993
|
+
[s + a, c + 10]
|
|
994
|
+
], {
|
|
995
|
+
...l,
|
|
996
|
+
fill: "none"
|
|
997
|
+
}, !1);
|
|
998
|
+
break;
|
|
999
|
+
case "folder":
|
|
1000
|
+
e.rect(s, c, Math.min(a * .4, 40), 10, l, 2).rect(s, c + 8, a, o - 8, l), f(r, i + 4);
|
|
1001
|
+
return;
|
|
1002
|
+
case "box3d":
|
|
1003
|
+
p([
|
|
1004
|
+
[s, c + 8],
|
|
1005
|
+
[s + 8, c],
|
|
1006
|
+
[s + a, c],
|
|
1007
|
+
[s + a, c + o - 8],
|
|
1008
|
+
[s + a - 8, c + o],
|
|
1009
|
+
[s, c + o]
|
|
1010
|
+
]), e.poly([
|
|
1011
|
+
[s, c + 8],
|
|
1012
|
+
[s + a - 8, c + 8],
|
|
1013
|
+
[s + a, c]
|
|
1014
|
+
], {
|
|
1015
|
+
...l,
|
|
1016
|
+
fill: "none"
|
|
1017
|
+
}, !1).line(s + a - 8, c + 8, s + a - 8, c + o, l), f(r - 4, i + 4);
|
|
1018
|
+
return;
|
|
1019
|
+
case "cloud":
|
|
1020
|
+
e.rect(s, c, a, o, l, Math.min(o / 2, 20));
|
|
1021
|
+
break;
|
|
1022
|
+
case "triangle":
|
|
1023
|
+
p([
|
|
1024
|
+
[r, c],
|
|
1025
|
+
[s + a, c + o],
|
|
1026
|
+
[s, c + o]
|
|
1027
|
+
]), f(r, i + o / 6);
|
|
1028
|
+
return;
|
|
1029
|
+
case "actor": {
|
|
1030
|
+
let i = {
|
|
1031
|
+
fill: "none",
|
|
1032
|
+
stroke: t.style?.stroke ?? u.dark,
|
|
1033
|
+
sw: 1.5
|
|
1034
|
+
}, a = c + 2;
|
|
1035
|
+
e.circle(r, a + 7, 7, {
|
|
1036
|
+
...i,
|
|
1037
|
+
fill: t.style?.fill ?? u.fill
|
|
1038
|
+
}), e.line(r, a + 14, r, a + 28, i).line(r - 11, a + 19, r + 11, a + 19, i), e.line(r, a + 28, r - 9, a + 40, i).line(r, a + 28, r + 9, a + 40, i), e.text(r, a + 44 + n.text.length * C / 2, n.text, {
|
|
1039
|
+
anchor: "middle",
|
|
1040
|
+
color: d
|
|
1041
|
+
});
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
default:
|
|
1045
|
+
if (t.sections?.length) return A(e, t, s, c, a);
|
|
1046
|
+
e.rect(s, c, a, o, l);
|
|
1047
|
+
}
|
|
1048
|
+
f();
|
|
1049
|
+
}
|
|
1050
|
+
function A(e, t, n, r, a) {
|
|
1051
|
+
let o = O(t), s = t.sections.map(E), c = s.reduce((e, t) => e + t.h, 0);
|
|
1052
|
+
e.rect(n, r, a, c, o, t.shape === "round" ? 6 : 0);
|
|
1053
|
+
let l = r;
|
|
1054
|
+
t.sections.forEach((r, c) => {
|
|
1055
|
+
c && e.line(n, l, n + a, l, {
|
|
1056
|
+
stroke: o.stroke,
|
|
1057
|
+
sw: 1
|
|
1058
|
+
});
|
|
1059
|
+
let u = i(b);
|
|
1060
|
+
r.rows.forEach((i, o) => {
|
|
1061
|
+
let d = l + 5 + o * u + u / 2;
|
|
1062
|
+
if (r.center || i.length === 1 && c === 0) {
|
|
1063
|
+
e.text(n + a / 2, d, i.join(" "), {
|
|
1064
|
+
anchor: "middle",
|
|
1065
|
+
size: b,
|
|
1066
|
+
bold: r.bold,
|
|
1067
|
+
italic: r.italic,
|
|
1068
|
+
color: t.style?.color
|
|
1069
|
+
});
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
let f = n + x;
|
|
1073
|
+
i.forEach((n, i) => {
|
|
1074
|
+
e.text(f, d, n, {
|
|
1075
|
+
size: b,
|
|
1076
|
+
bold: r.bold,
|
|
1077
|
+
italic: r.italic,
|
|
1078
|
+
color: t.style?.color
|
|
1079
|
+
}), f += s[c].cols[i] + 12;
|
|
1080
|
+
});
|
|
1081
|
+
}), l += s[c].h;
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
var j = {
|
|
1085
|
+
arrow: 10,
|
|
1086
|
+
triangle: 13,
|
|
1087
|
+
diamond: 15,
|
|
1088
|
+
odiamond: 15,
|
|
1089
|
+
circle: 8,
|
|
1090
|
+
ocircle: 8
|
|
1091
|
+
};
|
|
1092
|
+
function ee(e, t) {
|
|
1093
|
+
let n = t.x - e.x, r = t.y - e.y, i = Math.hypot(n, r) || 1;
|
|
1094
|
+
return {
|
|
1095
|
+
x: n / i,
|
|
1096
|
+
y: r / i
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function te(e, t, n, r, i) {
|
|
1100
|
+
let a = -r.y, o = r.x, s = (e, t) => [n.x - r.x * e + a * t, n.y - r.y * e + o * t], c = (t, n) => e.line(t[0], t[1], n[0], n[1], {
|
|
1101
|
+
stroke: i,
|
|
1102
|
+
sw: 1.3
|
|
1103
|
+
});
|
|
1104
|
+
switch (t) {
|
|
1105
|
+
case "arrow":
|
|
1106
|
+
e.poly([
|
|
1107
|
+
s(0, 0),
|
|
1108
|
+
s(10, 4.5),
|
|
1109
|
+
s(10, -4.5)
|
|
1110
|
+
], {
|
|
1111
|
+
fill: i,
|
|
1112
|
+
stroke: i,
|
|
1113
|
+
sw: 1
|
|
1114
|
+
});
|
|
1115
|
+
break;
|
|
1116
|
+
case "open":
|
|
1117
|
+
e.poly([
|
|
1118
|
+
s(10, 5),
|
|
1119
|
+
s(0, 0),
|
|
1120
|
+
s(10, -5)
|
|
1121
|
+
], {
|
|
1122
|
+
stroke: i,
|
|
1123
|
+
sw: 1.4
|
|
1124
|
+
}, !1);
|
|
1125
|
+
break;
|
|
1126
|
+
case "triangle":
|
|
1127
|
+
e.poly([
|
|
1128
|
+
s(0, 0),
|
|
1129
|
+
s(13, 7),
|
|
1130
|
+
s(13, -7)
|
|
1131
|
+
], {
|
|
1132
|
+
fill: "#ffffff",
|
|
1133
|
+
stroke: i,
|
|
1134
|
+
sw: 1.2
|
|
1135
|
+
});
|
|
1136
|
+
break;
|
|
1137
|
+
case "diamond":
|
|
1138
|
+
case "odiamond":
|
|
1139
|
+
e.poly([
|
|
1140
|
+
s(0, 0),
|
|
1141
|
+
s(7.5, 5),
|
|
1142
|
+
s(15, 0),
|
|
1143
|
+
s(7.5, -5)
|
|
1144
|
+
], {
|
|
1145
|
+
fill: t === "diamond" ? i : "#ffffff",
|
|
1146
|
+
stroke: i,
|
|
1147
|
+
sw: 1.2
|
|
1148
|
+
});
|
|
1149
|
+
break;
|
|
1150
|
+
case "circle":
|
|
1151
|
+
case "ocircle": {
|
|
1152
|
+
let [n, r] = s(4, 0);
|
|
1153
|
+
e.circle(n, r, 4, {
|
|
1154
|
+
fill: t === "circle" ? i : "#ffffff",
|
|
1155
|
+
stroke: i,
|
|
1156
|
+
sw: 1.2
|
|
1157
|
+
});
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
case "cross":
|
|
1161
|
+
c(s(1, 5), s(11, -5)), c(s(1, -5), s(11, 5));
|
|
1162
|
+
break;
|
|
1163
|
+
case "one":
|
|
1164
|
+
case "zero-one":
|
|
1165
|
+
case "one-many":
|
|
1166
|
+
case "zero-many":
|
|
1167
|
+
case "many": {
|
|
1168
|
+
let n = t.endsWith("many");
|
|
1169
|
+
if (n && (c(s(0, 7), s(12, 0)), c(s(0, -7), s(12, 0))), (t === "one" || t === "one-many") && c(s(n ? 16 : 7, 6), s(n ? 16 : 7, -6)), t === "one" && c(s(12, 6), s(12, -6)), t === "zero-one" || t === "zero-many") {
|
|
1170
|
+
let [t, r] = s(n ? 20 : 17, 0);
|
|
1171
|
+
e.circle(t, r, 4.5, {
|
|
1172
|
+
fill: "#ffffff",
|
|
1173
|
+
stroke: i,
|
|
1174
|
+
sw: 1.2
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
t === "zero-one" && c(s(7, 6), s(7, -6));
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
function M(e, t, n) {
|
|
1183
|
+
let r = t[t.length - 1], i = r.p[r.p.length - 1], a = ee(r.c === "C" ? r.p[1] : t.length > 1 ? t[t.length - 2].p[t[t.length - 2].p.length - 1] : e, i);
|
|
1184
|
+
if (n) {
|
|
1185
|
+
let e = {
|
|
1186
|
+
x: i.x - a.x * n,
|
|
1187
|
+
y: i.y - a.y * n
|
|
1188
|
+
};
|
|
1189
|
+
if (r.p[r.p.length - 1] = e, r.c === "C") {
|
|
1190
|
+
let e = {
|
|
1191
|
+
x: r.p[1].x - a.x * Math.min(n, 6),
|
|
1192
|
+
y: r.p[1].y - a.y * Math.min(n, 6)
|
|
1193
|
+
}, t = Math.min(0, (e.x - r.p[0].x) * a.x + (e.y - r.p[0].y) * a.y);
|
|
1194
|
+
r.p[1] = {
|
|
1195
|
+
x: e.x - a.x * t,
|
|
1196
|
+
y: e.y - a.y * t
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return a;
|
|
1201
|
+
}
|
|
1202
|
+
function ne(e) {
|
|
1203
|
+
return e.color ?? u.line;
|
|
1204
|
+
}
|
|
1205
|
+
var re = 16, N = 3e3, P = 6e3;
|
|
1206
|
+
function F(t) {
|
|
1207
|
+
if (!t.nodes.length) throw new _("The diagram has no nodes");
|
|
1208
|
+
if (t.nodes.length > N || t.edges.length > P) throw new _(`The diagram is too large to draw (${t.nodes.length} nodes, ${t.edges.length} edges)`);
|
|
1209
|
+
let n = t.dir, o = n === "TB" || n === "BT", s = new p(), c = new Map(t.clusters.map((e, t) => [e.id, t])), l = new Map(t.nodes.map((e, t) => [e.id, t])), d = (e) => t.clusters[e].parent === void 0 ? -1 : c.get(t.clusters[e].parent) ?? -1, f = (e, n) => {
|
|
1210
|
+
for (let r = t.nodes[e].cluster === void 0 ? -1 : c.get(t.nodes[e].cluster) ?? -1; r >= 0; r = d(r)) if (r === n) return !0;
|
|
1211
|
+
return !1;
|
|
1212
|
+
}, h = (e, n) => {
|
|
1213
|
+
let r = l.get(e);
|
|
1214
|
+
if (r !== void 0) return r;
|
|
1215
|
+
let i = c.get(e);
|
|
1216
|
+
if (i === void 0) return -1;
|
|
1217
|
+
if (!n) return t.nodes.findIndex((e, t) => f(t, i));
|
|
1218
|
+
for (let e = t.nodes.length - 1; e >= 0; e--) if (f(e, i)) return e;
|
|
1219
|
+
return -1;
|
|
1220
|
+
}, g = t.nodes.map((e) => D(e, n)), v = t.edges.map((e) => ({
|
|
1221
|
+
e,
|
|
1222
|
+
v: h(e.from, !0),
|
|
1223
|
+
w: h(e.to, !1),
|
|
1224
|
+
cv: l.has(e.from) ? -1 : c.get(e.from) ?? -1,
|
|
1225
|
+
cw: l.has(e.to) ? -1 : c.get(e.to) ?? -1
|
|
1226
|
+
})).filter((e) => e.v >= 0 && e.w >= 0), y = v.some((e) => e.e.label), x = (e) => e ? a(w(e), b) : void 0, S = /* @__PURE__ */ new Map();
|
|
1227
|
+
for (let { e, v: t, w: n } of v) {
|
|
1228
|
+
if (t !== n) continue;
|
|
1229
|
+
let r = x(e.label);
|
|
1230
|
+
S.set(t, Math.max(S.get(t) ?? 0, 40 + (r ? (o ? r.w : r.h) + 6 : 0)));
|
|
1231
|
+
}
|
|
1232
|
+
let C = t.nodes.map((e, t) => {
|
|
1233
|
+
let n = g[t], r = e.cluster === void 0 ? -1 : c.get(e.cluster) ?? -1, i = !!e.sections?.length || ie.has(e.shape);
|
|
1234
|
+
return o ? {
|
|
1235
|
+
w: n.w,
|
|
1236
|
+
h: n.h,
|
|
1237
|
+
cluster: r,
|
|
1238
|
+
loop: S.get(t),
|
|
1239
|
+
spread: i
|
|
1240
|
+
} : {
|
|
1241
|
+
w: n.h,
|
|
1242
|
+
h: n.w,
|
|
1243
|
+
cluster: r,
|
|
1244
|
+
loop: S.get(t),
|
|
1245
|
+
spread: i
|
|
1246
|
+
};
|
|
1247
|
+
}), T = v.map(({ e, v: t, w: n }) => {
|
|
1248
|
+
let r = x(e.label), i = r ? {
|
|
1249
|
+
w: r.w + 8,
|
|
1250
|
+
h: r.h + 4
|
|
1251
|
+
} : void 0;
|
|
1252
|
+
return {
|
|
1253
|
+
v: t,
|
|
1254
|
+
w: n,
|
|
1255
|
+
minlen: (e.minlen ?? 1) * (y ? 2 : 1),
|
|
1256
|
+
weight: 1,
|
|
1257
|
+
label: i ? o ? i : {
|
|
1258
|
+
w: i.h,
|
|
1259
|
+
h: i.w
|
|
1260
|
+
} : void 0
|
|
1261
|
+
};
|
|
1262
|
+
}), E = t.clusters.map((e, t) => {
|
|
1263
|
+
let r = e.label ? a(w(e.label), b, !0) : {
|
|
1264
|
+
w: 0,
|
|
1265
|
+
h: 0
|
|
1266
|
+
}, i = 12 + (e.label ? r.h + 6 : 0), s = n === "TB" ? [
|
|
1267
|
+
12,
|
|
1268
|
+
12,
|
|
1269
|
+
i,
|
|
1270
|
+
12
|
|
1271
|
+
] : n === "BT" ? [
|
|
1272
|
+
12,
|
|
1273
|
+
12,
|
|
1274
|
+
12,
|
|
1275
|
+
i
|
|
1276
|
+
] : [
|
|
1277
|
+
i,
|
|
1278
|
+
12,
|
|
1279
|
+
12,
|
|
1280
|
+
12
|
|
1281
|
+
];
|
|
1282
|
+
return {
|
|
1283
|
+
parent: d(t),
|
|
1284
|
+
pad: s,
|
|
1285
|
+
minW: o ? r.w + 24 : r.h + i + 12
|
|
1286
|
+
};
|
|
1287
|
+
}), O = t.sameRank?.map((e) => e.map((e) => l.get(e)).filter((e) => e !== void 0)).filter((e) => e.length > 1), A = e(C, T, E, {
|
|
1288
|
+
nodesep: o ? 40 : 28,
|
|
1289
|
+
ranksep: (o ? 50 : 60) / (y ? 2 : 1),
|
|
1290
|
+
edgesep: 14,
|
|
1291
|
+
sameRank: O
|
|
1292
|
+
}), F = t.title ? 32 : 0, z = A.w, B = A.h, V = (e) => {
|
|
1293
|
+
let t = n === "TB" ? e : n === "BT" ? {
|
|
1294
|
+
x: e.x,
|
|
1295
|
+
y: B - e.y
|
|
1296
|
+
} : n === "LR" ? {
|
|
1297
|
+
x: e.y,
|
|
1298
|
+
y: e.x
|
|
1299
|
+
} : {
|
|
1300
|
+
x: B - e.y,
|
|
1301
|
+
y: e.x
|
|
1302
|
+
};
|
|
1303
|
+
return {
|
|
1304
|
+
x: t.x + re,
|
|
1305
|
+
y: t.y + re + F
|
|
1306
|
+
};
|
|
1307
|
+
}, H = (o ? z : B) + 32, U = (o ? B : z) + 32 + F, W = (e) => {
|
|
1308
|
+
let t = 0;
|
|
1309
|
+
for (let n = d(e); n >= 0; n = d(n)) t++;
|
|
1310
|
+
return t;
|
|
1311
|
+
}, G = t.clusters.map((e, t) => t).sort((e, t) => W(e) - W(t)), ae = t.clusters.map(() => null), oe = [];
|
|
1312
|
+
for (let e of G) {
|
|
1313
|
+
let r = A.clusters[e];
|
|
1314
|
+
if (!r) continue;
|
|
1315
|
+
let a = t.clusters[e], o = V({
|
|
1316
|
+
x: r.x,
|
|
1317
|
+
y: r.y
|
|
1318
|
+
}), c = V({
|
|
1319
|
+
x: r.x + r.w,
|
|
1320
|
+
y: r.y + r.h
|
|
1321
|
+
}), l = Math.min(o.x, c.x), d = Math.min(o.y, c.y), f = Math.abs(c.x - o.x), p = Math.abs(c.y - o.y), m = a.style ?? {};
|
|
1322
|
+
if (ae[e] = {
|
|
1323
|
+
x: l,
|
|
1324
|
+
y: d,
|
|
1325
|
+
w: f,
|
|
1326
|
+
h: p
|
|
1327
|
+
}, s.rect(l, d, f, p, {
|
|
1328
|
+
fill: m.fill ?? u.cluster,
|
|
1329
|
+
stroke: m.stroke ?? u.clusterStroke,
|
|
1330
|
+
sw: m.sw ?? 1,
|
|
1331
|
+
dash: m.dash
|
|
1332
|
+
}, 4), a.label) {
|
|
1333
|
+
let e = w(a.label), t = n === "BT" ? d + p - 8 - e.length * i(b) / 2 : d + 8 + e.length * i(b) / 2;
|
|
1334
|
+
oe.push({
|
|
1335
|
+
x: l + f / 2,
|
|
1336
|
+
y: t,
|
|
1337
|
+
text: e,
|
|
1338
|
+
color: m.color ?? u.ink,
|
|
1339
|
+
bg: m.fill && m.fill !== "none" ? m.fill : u.cluster
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
let K = [];
|
|
1344
|
+
v.forEach(({ e, v: t }, n) => {
|
|
1345
|
+
if (e.line === "hidden") return;
|
|
1346
|
+
let r = ne(e), i = {
|
|
1347
|
+
stroke: r,
|
|
1348
|
+
sw: e.sw ?? (e.line === "thick" ? 3 : 1.4),
|
|
1349
|
+
dash: e.line === "dashed" ? "6 4" : e.line === "dotted" ? "2 3" : void 0
|
|
1350
|
+
}, c = A.edges[n];
|
|
1351
|
+
if (!c) {
|
|
1352
|
+
if (v[n].v !== v[n].w) return;
|
|
1353
|
+
let c = V(A.nodes[t]), l = g[t], u, d, f, p, h;
|
|
1354
|
+
o ? (u = {
|
|
1355
|
+
x: c.x + l.w / 2,
|
|
1356
|
+
y: c.y - l.h / 4
|
|
1357
|
+
}, p = {
|
|
1358
|
+
x: c.x + l.w / 2,
|
|
1359
|
+
y: c.y + l.h / 4
|
|
1360
|
+
}, d = {
|
|
1361
|
+
x: u.x + 34,
|
|
1362
|
+
y: u.y - 12
|
|
1363
|
+
}, f = {
|
|
1364
|
+
x: p.x + 34,
|
|
1365
|
+
y: p.y + 12
|
|
1366
|
+
}, h = {
|
|
1367
|
+
x: c.x + l.w / 2 + 34,
|
|
1368
|
+
y: c.y
|
|
1369
|
+
}) : (u = {
|
|
1370
|
+
x: c.x - l.w / 4,
|
|
1371
|
+
y: c.y + l.h / 2
|
|
1372
|
+
}, p = {
|
|
1373
|
+
x: c.x + l.w / 4,
|
|
1374
|
+
y: c.y + l.h / 2
|
|
1375
|
+
}, d = {
|
|
1376
|
+
x: u.x - 12,
|
|
1377
|
+
y: u.y + 34
|
|
1378
|
+
}, f = {
|
|
1379
|
+
x: p.x + 12,
|
|
1380
|
+
y: p.y + 34
|
|
1381
|
+
}, h = {
|
|
1382
|
+
x: c.x,
|
|
1383
|
+
y: c.y + l.h / 2 + 34
|
|
1384
|
+
});
|
|
1385
|
+
let _ = [{
|
|
1386
|
+
c: "C",
|
|
1387
|
+
p: [
|
|
1388
|
+
d,
|
|
1389
|
+
f,
|
|
1390
|
+
p
|
|
1391
|
+
]
|
|
1392
|
+
}], y = e.head ?? "arrow", x = M(u, _, j[y] ?? 0);
|
|
1393
|
+
if (s.path(m([{
|
|
1394
|
+
c: "M",
|
|
1395
|
+
p: [u]
|
|
1396
|
+
}, ..._.map((e) => ({
|
|
1397
|
+
c: e.c,
|
|
1398
|
+
p: e.p
|
|
1399
|
+
}))]), i), te(s, y, p, x, r), e.label) {
|
|
1400
|
+
let t = a(w(e.label), b);
|
|
1401
|
+
K.push({
|
|
1402
|
+
p: o ? {
|
|
1403
|
+
x: h.x + t.w / 2 + 4,
|
|
1404
|
+
y: h.y
|
|
1405
|
+
} : {
|
|
1406
|
+
x: h.x,
|
|
1407
|
+
y: h.y + t.h / 2 + 4
|
|
1408
|
+
},
|
|
1409
|
+
text: w(e.label)
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
let l = {
|
|
1415
|
+
start: V(c.start),
|
|
1416
|
+
segs: c.segs.map((e) => ({
|
|
1417
|
+
c: e.c,
|
|
1418
|
+
p: e.p.map(V)
|
|
1419
|
+
})),
|
|
1420
|
+
label: c.label && V(c.label)
|
|
1421
|
+
}, { cv: u, cw: d } = v[n];
|
|
1422
|
+
if (u >= 0 && !f(v[n].w, u) || d >= 0 && !f(v[n].v, d)) {
|
|
1423
|
+
let e = L(l.start, l.segs);
|
|
1424
|
+
u >= 0 && ae[u] && (e = R(e, ae[u], !0)), d >= 0 && ae[d] && (e = R(e, ae[d], !1)), e.length > 1 && (l = {
|
|
1425
|
+
start: e[0],
|
|
1426
|
+
segs: e.slice(1).map((e) => ({
|
|
1427
|
+
c: "L",
|
|
1428
|
+
p: [e]
|
|
1429
|
+
})),
|
|
1430
|
+
label: l.label
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
let p = e.head ?? "none", h = e.tail ?? "none", _ = l.segs[l.segs.length - 1].p[l.segs[l.segs.length - 1].p.length - 1], y = M(l.start, l.segs, j[p] ?? 0), x = l.segs[0], S = ee((x.c, x.p[0]), l.start), C = l.start, T = j[h] ?? 0, E = T ? {
|
|
1434
|
+
x: l.start.x - S.x * T,
|
|
1435
|
+
y: l.start.y - S.y * T
|
|
1436
|
+
} : l.start;
|
|
1437
|
+
if (T && x.c === "C") {
|
|
1438
|
+
let e = {
|
|
1439
|
+
x: x.p[0].x - S.x * Math.min(T, 6),
|
|
1440
|
+
y: x.p[0].y - S.y * Math.min(T, 6)
|
|
1441
|
+
}, t = Math.max(0, (x.p[1].x - e.x) * S.x + (x.p[1].y - e.y) * S.y);
|
|
1442
|
+
x.p[0] = {
|
|
1443
|
+
x: e.x + S.x * t,
|
|
1444
|
+
y: e.y + S.y * t
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
if (s.path(m([{
|
|
1448
|
+
c: "M",
|
|
1449
|
+
p: [E]
|
|
1450
|
+
}, ...l.segs.map((e) => ({
|
|
1451
|
+
c: e.c,
|
|
1452
|
+
p: e.p
|
|
1453
|
+
}))]), i), p !== "none" && te(s, p, _, y, r), h !== "none" && te(s, h, C, S, r), e.label) {
|
|
1454
|
+
let t = l.label ?? I(l.start, _);
|
|
1455
|
+
K.push({
|
|
1456
|
+
p: t,
|
|
1457
|
+
text: w(e.label)
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
let D = (e, t, n) => {
|
|
1461
|
+
let r = a(w(n), b), i = -t.y, o = t.x, s = Math.abs(i) * (r.w / 2 + 5) + Math.abs(o) * (r.h / 2 + 3);
|
|
1462
|
+
K.push({
|
|
1463
|
+
p: {
|
|
1464
|
+
x: e.x - t.x * (16 + r.h / 2) + i * s,
|
|
1465
|
+
y: e.y - t.y * (14 + r.h / 2) + o * s
|
|
1466
|
+
},
|
|
1467
|
+
text: w(n),
|
|
1468
|
+
plain: !0
|
|
1469
|
+
});
|
|
1470
|
+
};
|
|
1471
|
+
e.headLabel && D(_, y, e.headLabel), e.tailLabel && D(C, S, e.tailLabel);
|
|
1472
|
+
});
|
|
1473
|
+
for (let e of oe) {
|
|
1474
|
+
let t = a(e.text, b, !0);
|
|
1475
|
+
s.rect(e.x - t.w / 2 - 4, e.y - t.h / 2 - 1, t.w + 8, t.h + 2, { fill: e.bg }, 2), s.text(e.x, e.y, e.text, {
|
|
1476
|
+
anchor: "middle",
|
|
1477
|
+
size: b,
|
|
1478
|
+
bold: !0,
|
|
1479
|
+
color: e.color
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
t.nodes.forEach((e, t) => {
|
|
1483
|
+
if (e.style?.hidden) return;
|
|
1484
|
+
let n = V(A.nodes[t]);
|
|
1485
|
+
k(s, e, g[t], n.x, n.y);
|
|
1486
|
+
});
|
|
1487
|
+
for (let e of K) {
|
|
1488
|
+
let t = a(e.text, b);
|
|
1489
|
+
e.plain || s.rect(e.p.x - t.w / 2 - 3, e.p.y - t.h / 2 - 1, t.w + 6, t.h + 2, {
|
|
1490
|
+
fill: u.label,
|
|
1491
|
+
opacity: .92
|
|
1492
|
+
}, 2), s.text(e.p.x, e.p.y, e.text, {
|
|
1493
|
+
anchor: "middle",
|
|
1494
|
+
size: b,
|
|
1495
|
+
color: e.color ?? u.ink
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
return t.title && (H = Math.max(H, r(t.title, 16, !0) + 32), s.text(H / 2, 27, t.title, {
|
|
1499
|
+
anchor: "middle",
|
|
1500
|
+
size: 16,
|
|
1501
|
+
bold: !0
|
|
1502
|
+
})), {
|
|
1503
|
+
svg: s.toString(H, U),
|
|
1504
|
+
w: Math.ceil(H),
|
|
1505
|
+
h: Math.ceil(U)
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
var I = (e, t) => ({
|
|
1509
|
+
x: (e.x + t.x) / 2,
|
|
1510
|
+
y: (e.y + t.y) / 2
|
|
1511
|
+
}), ie = /* @__PURE__ */ new Set([
|
|
1512
|
+
"rect",
|
|
1513
|
+
"round",
|
|
1514
|
+
"subroutine",
|
|
1515
|
+
"component",
|
|
1516
|
+
"note",
|
|
1517
|
+
"folder",
|
|
1518
|
+
"box3d",
|
|
1519
|
+
"cylinder",
|
|
1520
|
+
"stadium",
|
|
1521
|
+
"cloud"
|
|
1522
|
+
]);
|
|
1523
|
+
function L(e, t) {
|
|
1524
|
+
let n = [e], r = e;
|
|
1525
|
+
for (let e of t) {
|
|
1526
|
+
if (e.c === "L") n.push(e.p[0]);
|
|
1527
|
+
else {
|
|
1528
|
+
let [t, i, a] = e.p;
|
|
1529
|
+
for (let e = 1; e <= 12; e++) {
|
|
1530
|
+
let o = e / 12, s = 1 - o;
|
|
1531
|
+
n.push({
|
|
1532
|
+
x: s * s * s * r.x + 3 * s * s * o * t.x + 3 * s * o * o * i.x + o * o * o * a.x,
|
|
1533
|
+
y: s * s * s * r.y + 3 * s * s * o * t.y + 3 * s * o * o * i.y + o * o * o * a.y
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
r = n[n.length - 1];
|
|
1538
|
+
}
|
|
1539
|
+
return n;
|
|
1540
|
+
}
|
|
1541
|
+
function R(e, t, n) {
|
|
1542
|
+
let r = (e) => e.x > t.x && e.x < t.x + t.w && e.y > t.y && e.y < t.y + t.h, i = n ? e : [...e].reverse(), a = i.findIndex((e) => !r(e));
|
|
1543
|
+
if (a <= 0) return e;
|
|
1544
|
+
let o = i[a - 1], s = i[a], c = 1, l = s.x - o.x, u = s.y - o.y;
|
|
1545
|
+
l > 0 && (c = Math.min(c, (t.x + t.w - o.x) / l)), l < 0 && (c = Math.min(c, (t.x - o.x) / l)), u > 0 && (c = Math.min(c, (t.y + t.h - o.y) / u)), u < 0 && (c = Math.min(c, (t.y - o.y) / u));
|
|
1546
|
+
let d = [{
|
|
1547
|
+
x: o.x + l * c,
|
|
1548
|
+
y: o.y + u * c
|
|
1549
|
+
}, ...i.slice(a)];
|
|
1550
|
+
return n ? d : d.reverse();
|
|
1551
|
+
}
|
|
1552
|
+
// src/core/diagram/charts.ts
|
|
1553
|
+
var z = 16, B = (e) => Math.round(e * 100) / 100;
|
|
1554
|
+
function V(e) {
|
|
1555
|
+
let t = e.slices.filter((e) => e.value > 0 && Number.isFinite(e.value));
|
|
1556
|
+
if (!t.length) throw Error("The pie chart has no values");
|
|
1557
|
+
let n = t.reduce((e, t) => e + t.value, 0), i = new p(), a = z + (e.title ? 36 : 0) + 130, o = (e) => u.series[e % u.series.length], s = -Math.PI / 2, c = (e, t) => ({
|
|
1558
|
+
x: 146 + Math.cos(e) * t,
|
|
1559
|
+
y: a + Math.sin(e) * t
|
|
1560
|
+
});
|
|
1561
|
+
t.forEach((e, t) => {
|
|
1562
|
+
let r = e.value / n, l = s + r * 2 * Math.PI;
|
|
1563
|
+
if (r >= .9999) i.circle(146, a, 130, {
|
|
1564
|
+
fill: o(t),
|
|
1565
|
+
stroke: "#ffffff",
|
|
1566
|
+
sw: 2
|
|
1567
|
+
});
|
|
1568
|
+
else {
|
|
1569
|
+
let e = c(s, 130), n = c(l, 130);
|
|
1570
|
+
i.path(`M${B(146)} ${B(a)} L${B(e.x)} ${B(e.y)} A130 130 0 ${+(r > .5)} 1 ${B(n.x)} ${B(n.y)} Z`, {
|
|
1571
|
+
fill: o(t),
|
|
1572
|
+
stroke: "#ffffff",
|
|
1573
|
+
sw: 2
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
if (r >= .06) {
|
|
1577
|
+
let e = c((s + l) / 2, 85.8);
|
|
1578
|
+
i.text(e.x, e.y, `${Math.round(r * 1e3) / 10}%`, {
|
|
1579
|
+
anchor: "middle",
|
|
1580
|
+
size: 13,
|
|
1581
|
+
bold: !0,
|
|
1582
|
+
color: "#ffffff"
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
s = l;
|
|
1586
|
+
});
|
|
1587
|
+
let l = a - t.length * 24 / 2 + 12, d = 0;
|
|
1588
|
+
t.forEach((t, n) => {
|
|
1589
|
+
let a = e.showData ? `${t.label} [${H(t.value)}]` : t.label;
|
|
1590
|
+
i.rect(306, l + n * 24 - 8, 16, 16, { fill: o(n) }, 3), i.text(330, l + n * 24, a), d = Math.max(d, r(a, 14));
|
|
1591
|
+
});
|
|
1592
|
+
let f = 330 + d + z, m = Math.max(a + 130, l + t.length * 24) + z;
|
|
1593
|
+
return e.title && (f = Math.max(f, r(e.title, 16, !0) + 32), i.text(f / 2, 28, e.title, {
|
|
1594
|
+
anchor: "middle",
|
|
1595
|
+
size: 16,
|
|
1596
|
+
bold: !0
|
|
1597
|
+
})), {
|
|
1598
|
+
svg: i.toString(f, m),
|
|
1599
|
+
w: Math.ceil(f),
|
|
1600
|
+
h: Math.ceil(m)
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
var H = (e) => String(Number.isInteger(e) ? e : Math.round(e * 100) / 100), U = 36e5, W = 24 * U, G = (e) => String(e).padStart(2, "0");
|
|
1604
|
+
function ae(e) {
|
|
1605
|
+
let t = e.sections.flatMap((e) => e.tasks);
|
|
1606
|
+
if (!t.length) throw Error("The Gantt chart has no tasks");
|
|
1607
|
+
let n = Math.min(...t.map((e) => e.start)), i = Math.max(...t.map((e) => Math.max(e.end, e.start))), a = Math.max(i - n, U), s = Math.min(180, Math.max(0, ...e.sections.map((e) => r(e.name, 13, !0))) + 24), c = Math.max(560, Math.min(1100, t.length * 60)), l = c / a, d = e.title ? 36 : 0, f = z + s, m = z + d, h = (e) => f + (e - n) * l, g = new p(), _ = m + t.length * 28 + 24 + z + 6, v = [
|
|
1608
|
+
U,
|
|
1609
|
+
3 * U,
|
|
1610
|
+
6 * U,
|
|
1611
|
+
12 * U,
|
|
1612
|
+
W,
|
|
1613
|
+
2 * W,
|
|
1614
|
+
7 * W,
|
|
1615
|
+
14 * W,
|
|
1616
|
+
30 * W,
|
|
1617
|
+
91 * W,
|
|
1618
|
+
365 * W
|
|
1619
|
+
].find((e) => a / e <= 12) ?? 365 * W, y = Math.ceil(n / v) * v, b = (e) => {
|
|
1620
|
+
let t = new Date(e);
|
|
1621
|
+
return v < W ? `${G(t.getUTCHours())}:${G(t.getUTCMinutes())}` : v >= 365 * W ? String(t.getUTCFullYear()) : v >= 30 * W ? `${t.getUTCFullYear()}-${G(t.getUTCMonth() + 1)}` : `${t.getUTCFullYear()}-${G(t.getUTCMonth() + 1)}-${G(t.getUTCDate())}`;
|
|
1622
|
+
}, x = m + t.length * 28 + 4;
|
|
1623
|
+
for (let e = y; e <= i; e += v) {
|
|
1624
|
+
let t = h(e);
|
|
1625
|
+
g.line(t, m, t, x, {
|
|
1626
|
+
stroke: "#e3e6ec",
|
|
1627
|
+
sw: 1
|
|
1628
|
+
}), g.text(t, x + 12, b(e), {
|
|
1629
|
+
anchor: "middle",
|
|
1630
|
+
size: 11,
|
|
1631
|
+
color: u.muted
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
let S = 0;
|
|
1635
|
+
e.sections.forEach((e, t) => {
|
|
1636
|
+
let n = u.series[t % u.series.length], i = m + S * 28;
|
|
1637
|
+
t % 2 == 0 && g.rect(z, i, s + c, e.tasks.length * 28, { fill: "#f6f7fa" }), e.name && g.text(22, i + e.tasks.length * 28 / 2, o([e.name], s - 12, 13, !0), {
|
|
1638
|
+
size: 13,
|
|
1639
|
+
bold: !0
|
|
1640
|
+
});
|
|
1641
|
+
for (let t of e.tasks) {
|
|
1642
|
+
let e = m + S * 28 + 14;
|
|
1643
|
+
if (t.milestone) {
|
|
1644
|
+
let n = h(t.start);
|
|
1645
|
+
g.poly([
|
|
1646
|
+
[n, e - 8],
|
|
1647
|
+
[n + 8, e],
|
|
1648
|
+
[n, e + 8],
|
|
1649
|
+
[n - 8, e]
|
|
1650
|
+
], { fill: t.crit ? "#e5596b" : u.dark }), g.text(n + 14, e, t.name, { size: 12 });
|
|
1651
|
+
} else {
|
|
1652
|
+
let i = h(t.start), a = Math.max(3, h(t.end) - i), o = t.done ? "#c7ccd6" : n;
|
|
1653
|
+
g.rect(i, e - 9, a, 18, {
|
|
1654
|
+
fill: o,
|
|
1655
|
+
stroke: t.crit ? "#c0392b" : t.active ? u.dark : void 0,
|
|
1656
|
+
sw: t.crit || t.active ? 2 : 0
|
|
1657
|
+
}, 3);
|
|
1658
|
+
let s = r(t.name, 12);
|
|
1659
|
+
s + 10 < a ? g.text(i + a / 2, e, t.name, {
|
|
1660
|
+
anchor: "middle",
|
|
1661
|
+
size: 12,
|
|
1662
|
+
color: t.done ? u.ink : "#ffffff"
|
|
1663
|
+
}) : i + a + 6 + s < f + c + 200 ? g.text(i + a + 6, e, t.name, { size: 12 }) : g.text(i - 6, e, t.name, {
|
|
1664
|
+
anchor: "end",
|
|
1665
|
+
size: 12
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
S++;
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
let C = f + c + z;
|
|
1672
|
+
for (let e of t) C = Math.max(C, h(e.end) + 12 + r(e.name, 12) + z);
|
|
1673
|
+
return e.title && (C = Math.max(C, r(e.title, 16, !0) + 32), g.text(C / 2, 28, e.title, {
|
|
1674
|
+
anchor: "middle",
|
|
1675
|
+
size: 16,
|
|
1676
|
+
bold: !0
|
|
1677
|
+
})), {
|
|
1678
|
+
svg: g.toString(C, _),
|
|
1679
|
+
w: Math.ceil(C),
|
|
1680
|
+
h: Math.ceil(_)
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
var oe = 44, K = 12;
|
|
1684
|
+
function se(e, t) {
|
|
1685
|
+
let n = new p(), i = (e, t) => {
|
|
1686
|
+
let n = t === 0 ? 16 : t === 1 ? 14 : 13, r = o(e.label.split("\n"), 220, n, t === 0), i = a(r, n, t === 0), s = e.shape === "circle", c = Math.max(i.w, i.h) + 20;
|
|
1687
|
+
return {
|
|
1688
|
+
text: r,
|
|
1689
|
+
w: s ? c : i.w + (e.shape === "none" ? 8 : 24),
|
|
1690
|
+
h: s ? c : i.h + (e.shape === "none" ? 6 : 14),
|
|
1691
|
+
fs: n
|
|
1692
|
+
};
|
|
1693
|
+
}, s = (e, t, n) => {
|
|
1694
|
+
let r = i(e, t), a = e.children.map((e, r) => s(e, t + 1, t === 0 ? u.series[r % u.series.length] : n)), o = Math.max(r.h, a.reduce((e, t) => e + t.span, 0) + Math.max(0, a.length - 1) * K);
|
|
1695
|
+
return {
|
|
1696
|
+
n: e,
|
|
1697
|
+
w: r.w,
|
|
1698
|
+
h: r.h,
|
|
1699
|
+
text: r.text,
|
|
1700
|
+
x: 0,
|
|
1701
|
+
y: 0,
|
|
1702
|
+
color: n,
|
|
1703
|
+
depth: t,
|
|
1704
|
+
kids: a,
|
|
1705
|
+
span: o
|
|
1706
|
+
};
|
|
1707
|
+
}, c = s(e, 0, u.dark), l = [], d = [];
|
|
1708
|
+
if (c.kids.some((e) => e.n.side)) l = c.kids.filter((e) => e.n.side !== "left"), d = c.kids.filter((e) => e.n.side === "left");
|
|
1709
|
+
else if (c.kids.length > 3) {
|
|
1710
|
+
let e = c.kids.reduce((e, t) => e + t.span, 0), t = 0;
|
|
1711
|
+
for (let n of c.kids) t < e / 2 ? l.push(n) : d.push(n), t += n.span;
|
|
1712
|
+
} else l = c.kids;
|
|
1713
|
+
let f = (e, t, n, r) => {
|
|
1714
|
+
e.x = t;
|
|
1715
|
+
let i = n + (e.span - (e.kids.reduce((e, t) => e + t.span, 0) + Math.max(0, e.kids.length - 1) * K)) / 2;
|
|
1716
|
+
for (let n of e.kids) f(n, t + r * (e.w / 2 + oe + n.w / 2), i, r), i += n.span + K;
|
|
1717
|
+
e.y = e.kids.length ? (e.kids[0].y + e.kids[e.kids.length - 1].y) / 2 : n + e.span / 2;
|
|
1718
|
+
}, h = (e) => e.reduce((e, t) => e + t.span, 0) + Math.max(0, e.length - 1) * K, g = h(l), _ = h(d), v = Math.max(c.h, g, _), y = (v - g) / 2;
|
|
1719
|
+
for (let e of l) f(e, c.w / 2 + oe + e.w / 2, y, 1), y += e.span + K;
|
|
1720
|
+
y = (v - _) / 2;
|
|
1721
|
+
for (let e of d) f(e, -(c.w / 2 + oe + e.w / 2), y, -1), y += e.span + K;
|
|
1722
|
+
c.x = 0, c.y = v / 2;
|
|
1723
|
+
let b = Infinity, x = -Infinity, S = Infinity, C = -Infinity, w = [], T = (e) => {
|
|
1724
|
+
w.push(e), b = Math.min(b, e.x - e.w / 2), x = Math.max(x, e.x + e.w / 2), S = Math.min(S, e.y - e.h / 2), C = Math.max(C, e.y + e.h / 2), e.kids.forEach(T);
|
|
1725
|
+
};
|
|
1726
|
+
T(c);
|
|
1727
|
+
let E = t ? 36 : 0, D = z - b, O = z + E - S, k = (e) => ({
|
|
1728
|
+
x: e.x + D,
|
|
1729
|
+
y: e.y + O
|
|
1730
|
+
});
|
|
1731
|
+
for (let e of w) for (let t of e.kids) {
|
|
1732
|
+
let r = k(e), i = k(t), a = Math.sign(i.x - r.x) || 1, o = {
|
|
1733
|
+
x: r.x + a * e.w / 2,
|
|
1734
|
+
y: r.y
|
|
1735
|
+
}, s = {
|
|
1736
|
+
x: i.x - a * t.w / 2,
|
|
1737
|
+
y: i.y
|
|
1738
|
+
}, c = (o.x + s.x) / 2;
|
|
1739
|
+
n.path(m([{
|
|
1740
|
+
c: "M",
|
|
1741
|
+
p: [o]
|
|
1742
|
+
}, {
|
|
1743
|
+
c: "C",
|
|
1744
|
+
p: [
|
|
1745
|
+
{
|
|
1746
|
+
x: c,
|
|
1747
|
+
y: o.y
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
x: c,
|
|
1751
|
+
y: s.y
|
|
1752
|
+
},
|
|
1753
|
+
s
|
|
1754
|
+
]
|
|
1755
|
+
}]), {
|
|
1756
|
+
stroke: t.color,
|
|
1757
|
+
sw: Math.max(1.2, 3.2 - t.depth * .6)
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
for (let e of w) {
|
|
1761
|
+
let t = k(e), r = e.depth === 0 ? 16 : e.depth === 1 ? 14 : 13, i = t.x - e.w / 2, a = t.y - e.h / 2, o = e.n.shape ?? (e.depth, "round"), s = e.depth === 0 ? u.dark : e.depth === 1 ? e.color : ce(e.color), c = e.depth <= 1 ? "#ffffff" : u.ink;
|
|
1762
|
+
if (o === "none") n.line(i, a + e.h, i + e.w, a + e.h, {
|
|
1763
|
+
stroke: e.color,
|
|
1764
|
+
sw: 1.5
|
|
1765
|
+
}), n.text(t.x, t.y, e.text, {
|
|
1766
|
+
anchor: "middle",
|
|
1767
|
+
size: r
|
|
1768
|
+
});
|
|
1769
|
+
else {
|
|
1770
|
+
if (o === "circle") n.circle(t.x, t.y, e.w / 2, {
|
|
1771
|
+
fill: s,
|
|
1772
|
+
stroke: e.color,
|
|
1773
|
+
sw: 1.2
|
|
1774
|
+
});
|
|
1775
|
+
else if (o === "hexagon") {
|
|
1776
|
+
let r = e.h / 4;
|
|
1777
|
+
n.poly([
|
|
1778
|
+
[i + r, a],
|
|
1779
|
+
[i + e.w - r, a],
|
|
1780
|
+
[i + e.w, t.y],
|
|
1781
|
+
[i + e.w - r, a + e.h],
|
|
1782
|
+
[i + r, a + e.h],
|
|
1783
|
+
[i, t.y]
|
|
1784
|
+
], {
|
|
1785
|
+
fill: s,
|
|
1786
|
+
stroke: e.color,
|
|
1787
|
+
sw: 1.2
|
|
1788
|
+
});
|
|
1789
|
+
} else n.rect(i, a, e.w, e.h, {
|
|
1790
|
+
fill: s,
|
|
1791
|
+
stroke: e.depth === 0 ? void 0 : e.color,
|
|
1792
|
+
sw: 1.2
|
|
1793
|
+
}, o === "rect" ? 2 : o === "cloud" ? e.h / 2 : 8);
|
|
1794
|
+
n.text(t.x, t.y, e.text, {
|
|
1795
|
+
anchor: "middle",
|
|
1796
|
+
size: r,
|
|
1797
|
+
bold: e.depth === 0,
|
|
1798
|
+
color: c
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
let A = x - b + 32, j = C - S + 32 + E;
|
|
1803
|
+
return t && (A = Math.max(A, r(t, 16, !0) + 32), n.text(A / 2, 28, t, {
|
|
1804
|
+
anchor: "middle",
|
|
1805
|
+
size: 16,
|
|
1806
|
+
bold: !0
|
|
1807
|
+
})), {
|
|
1808
|
+
svg: n.toString(A, j),
|
|
1809
|
+
w: Math.ceil(A),
|
|
1810
|
+
h: Math.ceil(j)
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
function ce(e) {
|
|
1814
|
+
let t = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);
|
|
1815
|
+
return t ? "#" + [
|
|
1816
|
+
t[1],
|
|
1817
|
+
t[2],
|
|
1818
|
+
t[3]
|
|
1819
|
+
].map((e) => Math.round(parseInt(e, 16) * .22 + 198.9).toString(16).padStart(2, "0")).join("") : "#f1f3f7";
|
|
1820
|
+
}
|
|
1821
|
+
// src/core/diagram/sequence.ts
|
|
1822
|
+
var q = (e) => Math.round(e * 100) / 100, le = class {
|
|
1823
|
+
s = {
|
|
1824
|
+
participants: [],
|
|
1825
|
+
events: []
|
|
1826
|
+
};
|
|
1827
|
+
ids = /* @__PURE__ */ new Map();
|
|
1828
|
+
participant(e, t = {}) {
|
|
1829
|
+
let n = this.ids.get(e);
|
|
1830
|
+
n || (n = {
|
|
1831
|
+
id: e,
|
|
1832
|
+
label: e,
|
|
1833
|
+
kind: "participant"
|
|
1834
|
+
}, this.ids.set(e, n), this.s.participants.push(n));
|
|
1835
|
+
for (let [e, r] of Object.entries(t)) r !== void 0 && (n[e] = r);
|
|
1836
|
+
return n;
|
|
1837
|
+
}
|
|
1838
|
+
has(e) {
|
|
1839
|
+
return this.ids.has(e);
|
|
1840
|
+
}
|
|
1841
|
+
push(e) {
|
|
1842
|
+
e.t === "msg" ? (this.participant(e.from), this.participant(e.to)) : e.t === "note" ? e.who.forEach((e) => this.participant(e)) : (e.t === "act" || e.t === "destroy") && this.participant(e.who), this.s.events.push(e);
|
|
1843
|
+
}
|
|
1844
|
+
}, ue = 14, J = 13, de = i(J), Y = 16, X = (e) => e ? e.split("\n") : [];
|
|
1845
|
+
function fe(e) {
|
|
1846
|
+
let t = X(e.label), n = a(t, ue);
|
|
1847
|
+
switch (e.kind) {
|
|
1848
|
+
case "actor": return {
|
|
1849
|
+
w: Math.max(44, n.w + 8),
|
|
1850
|
+
h: 44 + n.h,
|
|
1851
|
+
text: t
|
|
1852
|
+
};
|
|
1853
|
+
case "boundary":
|
|
1854
|
+
case "control":
|
|
1855
|
+
case "entity": return {
|
|
1856
|
+
w: Math.max(44, n.w + 8),
|
|
1857
|
+
h: 34 + n.h,
|
|
1858
|
+
text: t
|
|
1859
|
+
};
|
|
1860
|
+
case "database": return {
|
|
1861
|
+
w: Math.max(64, n.w + 24),
|
|
1862
|
+
h: n.h + 30,
|
|
1863
|
+
text: t
|
|
1864
|
+
};
|
|
1865
|
+
default: return {
|
|
1866
|
+
w: Math.max(64, n.w + 24),
|
|
1867
|
+
h: n.h + 18,
|
|
1868
|
+
text: t
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
function Z(e, t, n, r, a) {
|
|
1873
|
+
let o = t.fill ?? u.fill, s = {
|
|
1874
|
+
fill: o,
|
|
1875
|
+
stroke: u.stroke,
|
|
1876
|
+
sw: 1.3
|
|
1877
|
+
}, c = {
|
|
1878
|
+
fill: "none",
|
|
1879
|
+
stroke: u.dark,
|
|
1880
|
+
sw: 1.5
|
|
1881
|
+
}, l = (t) => e.text(r, t + n.text.length * i(ue) / 2, n.text, { anchor: "middle" }), d = r - n.w / 2;
|
|
1882
|
+
switch (t.kind) {
|
|
1883
|
+
case "actor":
|
|
1884
|
+
e.circle(r, a + 8, 7, {
|
|
1885
|
+
...c,
|
|
1886
|
+
fill: o
|
|
1887
|
+
}), e.line(r, a + 15, r, a + 29, c).line(r - 11, a + 20, r + 11, a + 20, c), e.line(r, a + 29, r - 9, a + 41, c).line(r, a + 29, r + 9, a + 41, c), l(a + 44);
|
|
1888
|
+
return;
|
|
1889
|
+
case "boundary":
|
|
1890
|
+
e.circle(r + 4, a + 14, 12, s).line(r - 14, a + 4, r - 14, a + 24, c).line(r - 14, a + 14, r - 8, a + 14, c), l(a + 32);
|
|
1891
|
+
return;
|
|
1892
|
+
case "control":
|
|
1893
|
+
e.circle(r, a + 15, 12, s).poly([
|
|
1894
|
+
[r + 4, a - 1],
|
|
1895
|
+
[r - 2, a + 3],
|
|
1896
|
+
[r + 4, a + 7]
|
|
1897
|
+
], c, !1), l(a + 32);
|
|
1898
|
+
return;
|
|
1899
|
+
case "entity":
|
|
1900
|
+
e.circle(r, a + 13, 12, s).line(r - 12, a + 27, r + 12, a + 27, c), l(a + 32);
|
|
1901
|
+
return;
|
|
1902
|
+
case "database": {
|
|
1903
|
+
let t = n.w, i = n.h;
|
|
1904
|
+
e.path(`M${q(d)} ${q(a + 6)} A${q(t / 2)} 6 0 0 1 ${q(d + t)} ${q(a + 6)} L${q(d + t)} ${q(a + i - 6)} A${q(t / 2)} 6 0 0 1 ${q(d)} ${q(a + i - 6)} Z`, s), e.path(`M${q(d)} ${q(a + 6)} A${q(t / 2)} 6 0 0 0 ${q(d + t)} ${q(a + 6)}`, {
|
|
1905
|
+
...s,
|
|
1906
|
+
fill: "none"
|
|
1907
|
+
}), e.text(r, a + i / 2 + 3, n.text, { anchor: "middle" });
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
case "collections":
|
|
1911
|
+
e.rect(d + 4, a - 4, n.w, n.h, s, 3), e.rect(d, a, n.w, n.h, s, 3);
|
|
1912
|
+
break;
|
|
1913
|
+
case "queue":
|
|
1914
|
+
e.rect(d, a, n.w, n.h, s, n.h / 2);
|
|
1915
|
+
break;
|
|
1916
|
+
default: e.rect(d, a, n.w, n.h, s, 3);
|
|
1917
|
+
}
|
|
1918
|
+
e.text(r, a + n.h / 2, n.text, { anchor: "middle" });
|
|
1919
|
+
}
|
|
1920
|
+
function pe(e, t, n, r, i) {
|
|
1921
|
+
let a = u.line;
|
|
1922
|
+
switch (t) {
|
|
1923
|
+
case "filled":
|
|
1924
|
+
e.poly([
|
|
1925
|
+
[n, r],
|
|
1926
|
+
[n - i * 10, r - 4.5],
|
|
1927
|
+
[n - i * 10, r + 4.5]
|
|
1928
|
+
], {
|
|
1929
|
+
fill: a,
|
|
1930
|
+
stroke: a,
|
|
1931
|
+
sw: 1
|
|
1932
|
+
});
|
|
1933
|
+
break;
|
|
1934
|
+
case "open":
|
|
1935
|
+
e.poly([
|
|
1936
|
+
[n - i * 10, r - 5],
|
|
1937
|
+
[n, r],
|
|
1938
|
+
[n - i * 10, r + 5]
|
|
1939
|
+
], {
|
|
1940
|
+
stroke: a,
|
|
1941
|
+
sw: 1.4
|
|
1942
|
+
}, !1);
|
|
1943
|
+
break;
|
|
1944
|
+
case "half":
|
|
1945
|
+
e.poly([[n - i * 10, r - 5], [n, r]], {
|
|
1946
|
+
stroke: a,
|
|
1947
|
+
sw: 1.4
|
|
1948
|
+
}, !1);
|
|
1949
|
+
break;
|
|
1950
|
+
case "cross": e.line(n - 5 - i * 4, r - 5, n + 5 - i * 4, r + 5, {
|
|
1951
|
+
stroke: a,
|
|
1952
|
+
sw: 1.6
|
|
1953
|
+
}).line(n - 5 - i * 4, r + 5, n + 5 - i * 4, r - 5, {
|
|
1954
|
+
stroke: a,
|
|
1955
|
+
sw: 1.6
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
function me(e) {
|
|
1960
|
+
let t = e.participants;
|
|
1961
|
+
if (!t.length) throw new _("The sequence diagram has no participants");
|
|
1962
|
+
if (t.length > 300 || e.events.length > 8e3) throw new _("The sequence diagram is too large to draw");
|
|
1963
|
+
let n = new Map(t.map((e, t) => [e.id, t])), i = t.map(fe), o = t.length, s = Array(o).fill(0);
|
|
1964
|
+
for (let e = 1; e < o; e++) s[e] = (i[e - 1].w + i[e].w) / 2 + 28;
|
|
1965
|
+
let c = 0, l = 0, d = (e, t, n) => {
|
|
1966
|
+
if (e > t && ([e, t] = [t, e]), e === t) return;
|
|
1967
|
+
let r = 0;
|
|
1968
|
+
for (let n = e + 1; n <= t; n++) r += s[n];
|
|
1969
|
+
if (r >= n) return;
|
|
1970
|
+
let i = (n - r) / (t - e);
|
|
1971
|
+
for (let n = e + 1; n <= t; n++) s[n] += i;
|
|
1972
|
+
}, f = (t) => e.autonumber ? r(String(t), 10) + 14 : 0, m = 0;
|
|
1973
|
+
for (let t of e.events) if (t.t === "msg") {
|
|
1974
|
+
m++;
|
|
1975
|
+
let e = n.get(t.from), a = n.get(t.to), s = Math.max(0, ...X(t.text).map((e) => r(e, J))) + f(m);
|
|
1976
|
+
e === a ? e + 1 < o ? d(e, e + 1, i[e + 1].w / 2 + s + 44) : l = Math.max(l, s + 44 - i[e].w / 2) : d(e, a, s + 30);
|
|
1977
|
+
} else if (t.t === "note") {
|
|
1978
|
+
let e = a(X(t.text), J).w + 20, r = t.who.map((e) => n.get(e)), s = Math.min(...r), u = Math.max(...r);
|
|
1979
|
+
t.pos === "over" ? s !== u && d(s, u, e - 50) : t.pos === "left" ? s > 0 ? d(s - 1, s, e + 16 + i[s - 1].w / 2) : c = Math.max(c, e + 16 - i[0].w / 2) : u + 1 < o ? d(u, u + 1, e + 16 + i[u + 1].w / 2) : l = Math.max(l, e + 16 - i[u].w / 2);
|
|
1980
|
+
}
|
|
1981
|
+
let h = [], g = (() => {
|
|
1982
|
+
let t = 0, n = 0;
|
|
1983
|
+
for (let r of e.events) r.t === "block" ? n = Math.max(n, ++t) : r.t === "end" && (t = Math.max(0, t - 1));
|
|
1984
|
+
return n;
|
|
1985
|
+
})(), v = g ? 12 + g * 8 : 0;
|
|
1986
|
+
h[0] = Y + Math.max(i[0].w / 2, c + i[0].w / 2, v + 10);
|
|
1987
|
+
for (let e = 1; e < o; e++) h[e] = h[e - 1] + s[e];
|
|
1988
|
+
let y = h[o - 1] + Math.max(i[o - 1].w / 2, l + i[o - 1].w / 2, v + 10) + Y, b = Y + (e.title ? 34 : 0), x = Math.max(...i.map((e) => e.h)), S = b + x + 18, C = new p(), w = new p(), T = new p(), E = t.map(() => []), D = [], O = [], k = [], A = /* @__PURE__ */ new Map(), j = (e, t) => {
|
|
1989
|
+
for (let n of k) n.lo = Math.min(n.lo, e), n.hi = Math.max(n.hi, t);
|
|
1990
|
+
}, ee = (e, t) => {
|
|
1991
|
+
let n = E[e].length;
|
|
1992
|
+
return h[e] + (n ? t * 5 + (n - 1) * 5 : 0);
|
|
1993
|
+
}, te = (e, t) => E[e].push(t), M = (e, t) => {
|
|
1994
|
+
let n = E[e].pop();
|
|
1995
|
+
n !== void 0 && D.push({
|
|
1996
|
+
k: e,
|
|
1997
|
+
y0: n,
|
|
1998
|
+
y1: t,
|
|
1999
|
+
depth: E[e].length
|
|
2000
|
+
});
|
|
2001
|
+
};
|
|
2002
|
+
m = 0;
|
|
2003
|
+
for (let t of e.events) switch (t.t) {
|
|
2004
|
+
case "msg": {
|
|
2005
|
+
m++;
|
|
2006
|
+
let i = n.get(t.from), a = n.get(t.to), o = X(t.text), s = o.length * de, c = {
|
|
2007
|
+
stroke: u.line,
|
|
2008
|
+
sw: 1.4,
|
|
2009
|
+
dash: t.dashed ? "6 4" : void 0
|
|
2010
|
+
}, l = f(m);
|
|
2011
|
+
if (i === a) {
|
|
2012
|
+
S += s + 4;
|
|
2013
|
+
let n = ee(i, 1);
|
|
2014
|
+
w.poly([
|
|
2015
|
+
[n, S],
|
|
2016
|
+
[n + 34, S],
|
|
2017
|
+
[n + 34, S + 20],
|
|
2018
|
+
[n + 2, S + 20]
|
|
2019
|
+
], c, !1), pe(w, t.head, n, S + 20, -1), T.text(n + 6 + l, S - 4 - s / 2, o, { size: J }), e.autonumber && Q(T, n, S, m), j(h[i] - 10, n + 34 + 6 + l + Math.max(...o.map((e) => r(e, J)))), S += 20, t.activate && te(a, S), t.deactivate && M(i, S), S += 14;
|
|
2020
|
+
break;
|
|
2021
|
+
}
|
|
2022
|
+
S += s + 6;
|
|
2023
|
+
let d = a > i ? 1 : -1;
|
|
2024
|
+
t.activate && te(a, S);
|
|
2025
|
+
let p = ee(i, d), g = ee(a, -d);
|
|
2026
|
+
w.line(p, S, g, S, c), pe(w, t.head, g, S, d), t.both && pe(w, t.head, p, S, -d), T.text((p + g) / 2 + d * l / 2, S - 5 - s / 2, o, {
|
|
2027
|
+
anchor: "middle",
|
|
2028
|
+
size: J
|
|
2029
|
+
}), e.autonumber && Q(T, p, S, m), t.deactivate && M(i, S), j(Math.min(h[i], h[a]), Math.max(h[i], h[a])), S += 14;
|
|
2030
|
+
break;
|
|
2031
|
+
}
|
|
2032
|
+
case "act": {
|
|
2033
|
+
let e = n.get(t.who);
|
|
2034
|
+
t.on ? te(e, S - 6) : M(e, S - 6);
|
|
2035
|
+
break;
|
|
2036
|
+
}
|
|
2037
|
+
case "note": {
|
|
2038
|
+
let e = t.who.map((e) => n.get(e)), r = Math.min(...e), i = Math.max(...e), o = X(t.text), s = a(o, J), c = Math.max(s.w + 20, t.pos === "over" && r !== i ? h[i] - h[r] + 50 : 0, 60), l = s.h + 12;
|
|
2039
|
+
S += 6;
|
|
2040
|
+
let d = t.pos === "left" ? h[r] - 12 - c : t.pos === "right" ? h[i] + 12 : (h[r] + h[i]) / 2 - c / 2;
|
|
2041
|
+
T.poly([
|
|
2042
|
+
[d, S],
|
|
2043
|
+
[d + c - 8, S],
|
|
2044
|
+
[d + c, S + 8],
|
|
2045
|
+
[d + c, S + l],
|
|
2046
|
+
[d, S + l]
|
|
2047
|
+
], {
|
|
2048
|
+
fill: u.note,
|
|
2049
|
+
stroke: u.noteStroke,
|
|
2050
|
+
sw: 1
|
|
2051
|
+
}), T.text(d + 10, S + l / 2, o, { size: J }), j(d, d + c), S += l + 8;
|
|
2052
|
+
break;
|
|
2053
|
+
}
|
|
2054
|
+
case "block": {
|
|
2055
|
+
S += 10;
|
|
2056
|
+
let e = {
|
|
2057
|
+
kind: t.kind,
|
|
2058
|
+
label: t.label,
|
|
2059
|
+
fill: t.fill,
|
|
2060
|
+
y0: S,
|
|
2061
|
+
y1: S,
|
|
2062
|
+
lo: Infinity,
|
|
2063
|
+
hi: -Infinity,
|
|
2064
|
+
depth: k.length,
|
|
2065
|
+
elses: []
|
|
2066
|
+
};
|
|
2067
|
+
O.push(e), k.push(e), S += t.kind === "rect" ? 8 : 26;
|
|
2068
|
+
break;
|
|
2069
|
+
}
|
|
2070
|
+
case "else": {
|
|
2071
|
+
let e = k[k.length - 1];
|
|
2072
|
+
if (!e) break;
|
|
2073
|
+
S += 8, e.elses.push({
|
|
2074
|
+
y: S,
|
|
2075
|
+
label: t.label
|
|
2076
|
+
}), S += 24;
|
|
2077
|
+
break;
|
|
2078
|
+
}
|
|
2079
|
+
case "end": {
|
|
2080
|
+
let e = k.pop();
|
|
2081
|
+
if (!e) break;
|
|
2082
|
+
S += 10, e.y1 = S, S += 6;
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
case "divider": {
|
|
2086
|
+
S += 16;
|
|
2087
|
+
let e = a(X(t.text), J);
|
|
2088
|
+
T.line(Y / 2, S - 2, y - Y / 2, S - 2, {
|
|
2089
|
+
stroke: u.muted,
|
|
2090
|
+
sw: 1
|
|
2091
|
+
}).line(Y / 2, S + 2, y - Y / 2, S + 2, {
|
|
2092
|
+
stroke: u.muted,
|
|
2093
|
+
sw: 1
|
|
2094
|
+
}), t.text && (T.rect(y / 2 - e.w / 2 - 10, S - e.h / 2 - 4, e.w + 20, e.h + 8, {
|
|
2095
|
+
fill: "#ffffff",
|
|
2096
|
+
stroke: u.muted,
|
|
2097
|
+
sw: 1
|
|
2098
|
+
}, 3), T.text(y / 2, S, X(t.text), {
|
|
2099
|
+
anchor: "middle",
|
|
2100
|
+
size: J,
|
|
2101
|
+
bold: !0
|
|
2102
|
+
})), S += 22;
|
|
2103
|
+
break;
|
|
2104
|
+
}
|
|
2105
|
+
case "delay":
|
|
2106
|
+
S += 14, t.text && T.text(y / 2, S, X(t.text), {
|
|
2107
|
+
anchor: "middle",
|
|
2108
|
+
size: J,
|
|
2109
|
+
italic: !0,
|
|
2110
|
+
color: u.muted
|
|
2111
|
+
}), S += 18;
|
|
2112
|
+
break;
|
|
2113
|
+
case "space":
|
|
2114
|
+
S += t.h;
|
|
2115
|
+
break;
|
|
2116
|
+
case "destroy": {
|
|
2117
|
+
let e = n.get(t.who);
|
|
2118
|
+
S += 6, T.line(h[e] - 8, S - 8, h[e] + 8, S + 8, {
|
|
2119
|
+
stroke: "#c0392b",
|
|
2120
|
+
sw: 2
|
|
2121
|
+
}).line(h[e] - 8, S + 8, h[e] + 8, S - 8, {
|
|
2122
|
+
stroke: "#c0392b",
|
|
2123
|
+
sw: 2
|
|
2124
|
+
}), A.set(e, S), S += 14;
|
|
2125
|
+
break;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
for (let e = 0; e < o; e++) for (; E[e].length;) M(e, S);
|
|
2129
|
+
for (let e of k.splice(0)) e.y1 = S;
|
|
2130
|
+
S += 14;
|
|
2131
|
+
let ne = e.footer !== !1, re = S + (ne ? x : 0) + Y;
|
|
2132
|
+
for (let e of O) {
|
|
2133
|
+
let t = 12 + (g - e.depth) * 8;
|
|
2134
|
+
e.lo > e.hi && (e.lo = h[0], e.hi = h[o - 1]);
|
|
2135
|
+
let n = Math.max(4, e.lo - t), i = r(e.kind, 12, !0) + 16, a = [e.label ? i + 8 + r(`[${e.label}]`, 12) : i, ...e.elses.map((e) => 10 + r(`[${e.label}]`, 12))], s = Math.max(Math.min(y - 4, e.hi + t), e.kind === "rect" ? 0 : n + Math.max(...a) + 10);
|
|
2136
|
+
if (y = Math.max(y, s + 4), e.kind === "rect") {
|
|
2137
|
+
C.rect(n, e.y0, s - n, e.y1 - e.y0, { fill: e.fill ?? "rgba(200, 210, 230, 0.35)" }, 2);
|
|
2138
|
+
continue;
|
|
2139
|
+
}
|
|
2140
|
+
let c = {
|
|
2141
|
+
stroke: u.muted,
|
|
2142
|
+
sw: 1.2
|
|
2143
|
+
};
|
|
2144
|
+
w.rect(n, e.y0, s - n, e.y1 - e.y0, c);
|
|
2145
|
+
let l = i;
|
|
2146
|
+
w.poly([
|
|
2147
|
+
[n, e.y0],
|
|
2148
|
+
[n + l, e.y0],
|
|
2149
|
+
[n + l, e.y0 + 12],
|
|
2150
|
+
[n + l - 7, e.y0 + 19],
|
|
2151
|
+
[n, e.y0 + 19]
|
|
2152
|
+
], {
|
|
2153
|
+
fill: "#eef0f4",
|
|
2154
|
+
stroke: u.muted,
|
|
2155
|
+
sw: 1.2
|
|
2156
|
+
}), w.text(n + 7, e.y0 + 10, e.kind, {
|
|
2157
|
+
size: 12,
|
|
2158
|
+
bold: !0
|
|
2159
|
+
}), e.label && w.text(n + l + 8, e.y0 + 11, `[${e.label}]`, {
|
|
2160
|
+
size: 12,
|
|
2161
|
+
color: u.ink,
|
|
2162
|
+
italic: !0
|
|
2163
|
+
});
|
|
2164
|
+
for (let t of e.elses) w.line(n, t.y, s, t.y, {
|
|
2165
|
+
...c,
|
|
2166
|
+
dash: "5 4"
|
|
2167
|
+
}), t.label && w.text(n + 10, t.y + 12, `[${t.label}]`, {
|
|
2168
|
+
size: 12,
|
|
2169
|
+
italic: !0
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
let N = new p(), P = b + x;
|
|
2173
|
+
for (let e = 0; e < o; e++) N.line(h[e], P, h[e], A.get(e) ?? (ne ? S : S - 6), {
|
|
2174
|
+
stroke: "#9aa3b2",
|
|
2175
|
+
sw: 1,
|
|
2176
|
+
dash: "5 4"
|
|
2177
|
+
});
|
|
2178
|
+
N.raw(C.body());
|
|
2179
|
+
for (let e of D) {
|
|
2180
|
+
let t = h[e.k] - 5 + e.depth * 5;
|
|
2181
|
+
N.rect(t, e.y0, 10, Math.max(8, e.y1 - e.y0), {
|
|
2182
|
+
fill: "#f3f4f6",
|
|
2183
|
+
stroke: u.stroke,
|
|
2184
|
+
sw: 1
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
return N.raw(w.body()), N.raw(T.body()), t.forEach((e, t) => {
|
|
2188
|
+
Z(N, e, i[t], h[t], b + x - i[t].h), ne && !A.has(t) && Z(N, e, i[t], h[t], S);
|
|
2189
|
+
}), e.title && (y = Math.max(y, r(e.title, 16, !0) + 32), N.text(y / 2, 28, e.title, {
|
|
2190
|
+
anchor: "middle",
|
|
2191
|
+
size: 16,
|
|
2192
|
+
bold: !0
|
|
2193
|
+
})), {
|
|
2194
|
+
svg: N.toString(y, re),
|
|
2195
|
+
w: Math.ceil(y),
|
|
2196
|
+
h: Math.ceil(re)
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
function Q(e, t, n, i) {
|
|
2200
|
+
let a = Math.max(8, r(String(i), 10) / 2 + 4);
|
|
2201
|
+
e.circle(t, n, a, { fill: u.dark }), e.text(t, n, String(i), {
|
|
2202
|
+
anchor: "middle",
|
|
2203
|
+
size: 10,
|
|
2204
|
+
color: "#ffffff",
|
|
2205
|
+
bold: !0
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
// src/core/diagram/model.ts
|
|
2209
|
+
function he(e) {
|
|
2210
|
+
switch (e.t) {
|
|
2211
|
+
case "graph": return F(e.graph);
|
|
2212
|
+
case "sequence": return me(e.seq);
|
|
2213
|
+
case "pie": return V(e.pie);
|
|
2214
|
+
case "gantt": return ae(e.gantt);
|
|
2215
|
+
case "tree": return se(e.root, e.title);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
// src/core/diagram/mermaid.ts
|
|
2219
|
+
function ge(e) {
|
|
2220
|
+
let t = e.replace(/^/, "").replace(/\r\n?/g, "\n"), n, r = /^\s*---\n([\s\S]*?)\n---[ \t]*(\n|$)/.exec(t);
|
|
2221
|
+
return r && (n = /^title:\s*(.+)$/m.exec(r[1])?.[1].trim().replace(/^(["'])(.*)\1$/, "$2"), t = t.slice(r[0].length)), t = t.replace(/%%\{[\s\S]*?\}%%/g, ""), {
|
|
2222
|
+
lines: t.split("\n").filter((e) => !/^\s*%%/.test(e)),
|
|
2223
|
+
title: n
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
function _e(e) {
|
|
2227
|
+
let { lines: t, title: n } = ge(e), r = t.findIndex((e) => e.trim());
|
|
2228
|
+
if (r < 0) throw new _("The diagram is empty");
|
|
2229
|
+
let i = t[r].trim(), a = /^[\w-]+/.exec(i)?.[0] ?? i, o = t.slice(r + 1);
|
|
2230
|
+
switch (a) {
|
|
2231
|
+
case "graph":
|
|
2232
|
+
case "flowchart":
|
|
2233
|
+
case "flowchart-elk": return {
|
|
2234
|
+
t: "graph",
|
|
2235
|
+
graph: ke(i, o, n)
|
|
2236
|
+
};
|
|
2237
|
+
case "sequenceDiagram": return {
|
|
2238
|
+
t: "sequence",
|
|
2239
|
+
seq: Me(o, n)
|
|
2240
|
+
};
|
|
2241
|
+
case "classDiagram":
|
|
2242
|
+
case "classDiagram-v2": return {
|
|
2243
|
+
t: "graph",
|
|
2244
|
+
graph: Fe(o, n)
|
|
2245
|
+
};
|
|
2246
|
+
case "stateDiagram":
|
|
2247
|
+
case "stateDiagram-v2": return {
|
|
2248
|
+
t: "graph",
|
|
2249
|
+
graph: Ie(o, n)
|
|
2250
|
+
};
|
|
2251
|
+
case "erDiagram": return {
|
|
2252
|
+
t: "graph",
|
|
2253
|
+
graph: ze(o, n)
|
|
2254
|
+
};
|
|
2255
|
+
case "pie": return {
|
|
2256
|
+
t: "pie",
|
|
2257
|
+
pie: Be(i, o, n)
|
|
2258
|
+
};
|
|
2259
|
+
case "gantt": return {
|
|
2260
|
+
t: "gantt",
|
|
2261
|
+
gantt: Ue(o, n)
|
|
2262
|
+
};
|
|
2263
|
+
case "mindmap": return {
|
|
2264
|
+
t: "tree",
|
|
2265
|
+
root: Ge(o),
|
|
2266
|
+
title: n
|
|
2267
|
+
};
|
|
2268
|
+
default: throw new _(`Mermaid “${a}” diagrams are not supported yet`);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
var ve = (e) => he(_e(e)), ye = {
|
|
2272
|
+
TB: "TB",
|
|
2273
|
+
TD: "TB",
|
|
2274
|
+
BT: "BT",
|
|
2275
|
+
LR: "LR",
|
|
2276
|
+
RL: "RL"
|
|
2277
|
+
};
|
|
2278
|
+
function $(e) {
|
|
2279
|
+
let t = e.trim();
|
|
2280
|
+
return /^".*"$/s.test(t) && (t = t.slice(1, -1)), /^`.*`$/s.test(t) && (t = g(t.slice(1, -1))), t = t.replace(/\bfa[bkrs]?:fa-[\w-]+\s*/g, ""), h(t).trim();
|
|
2281
|
+
}
|
|
2282
|
+
function be(e) {
|
|
2283
|
+
let t = {};
|
|
2284
|
+
for (let n of e.split(/,(?![^(]*\))/)) {
|
|
2285
|
+
let e = n.indexOf(":");
|
|
2286
|
+
if (e < 0) continue;
|
|
2287
|
+
let r = n.slice(0, e).trim().toLowerCase(), i = n.slice(e + 1).trim().replace(/;$/, "");
|
|
2288
|
+
r === "fill" || r === "background" ? t.fill = l(i) : r === "stroke" ? t.stroke = l(i) : r === "color" ? t.color = l(i) : r === "stroke-width" ? t.sw = Math.min(8, parseFloat(i) || 1) : r === "stroke-dasharray" ? t.dash = /^[\d.\s]+$/.test(i) ? i : "5 5" : r === "font-weight" ? t.bold = /bold|[6-9]00/.test(i) : r === "font-style" && (t.italic = i === "italic");
|
|
2289
|
+
}
|
|
2290
|
+
return t;
|
|
2291
|
+
}
|
|
2292
|
+
var xe = (e, t) => {
|
|
2293
|
+
let n = { ...e };
|
|
2294
|
+
for (let [e, r] of Object.entries(t)) r !== void 0 && (n[e] = r);
|
|
2295
|
+
return n;
|
|
2296
|
+
};
|
|
2297
|
+
function Se(e, t) {
|
|
2298
|
+
let n = [], r = 0, i = "", a = "";
|
|
2299
|
+
for (let o of e) {
|
|
2300
|
+
if (i) o === i && (i = "");
|
|
2301
|
+
else if (o === "\"" || o === "`") i = o;
|
|
2302
|
+
else if ("([{".includes(o)) r++;
|
|
2303
|
+
else if (")]}".includes(o)) r = Math.max(0, r - 1);
|
|
2304
|
+
else if (o === t && !r) {
|
|
2305
|
+
n.push(a), a = "";
|
|
2306
|
+
continue;
|
|
2307
|
+
}
|
|
2308
|
+
a += o;
|
|
2309
|
+
}
|
|
2310
|
+
return n.push(a), n;
|
|
2311
|
+
}
|
|
2312
|
+
var Ce = [
|
|
2313
|
+
[
|
|
2314
|
+
"(((",
|
|
2315
|
+
[")))"],
|
|
2316
|
+
["doublecircle"]
|
|
2317
|
+
],
|
|
2318
|
+
[
|
|
2319
|
+
"((",
|
|
2320
|
+
["))"],
|
|
2321
|
+
["circle"]
|
|
2322
|
+
],
|
|
2323
|
+
[
|
|
2324
|
+
"([",
|
|
2325
|
+
["])"],
|
|
2326
|
+
["stadium"]
|
|
2327
|
+
],
|
|
2328
|
+
[
|
|
2329
|
+
"[[",
|
|
2330
|
+
["]]"],
|
|
2331
|
+
["subroutine"]
|
|
2332
|
+
],
|
|
2333
|
+
[
|
|
2334
|
+
"[(",
|
|
2335
|
+
[")]"],
|
|
2336
|
+
["cylinder"]
|
|
2337
|
+
],
|
|
2338
|
+
[
|
|
2339
|
+
"{{",
|
|
2340
|
+
["}}"],
|
|
2341
|
+
["hexagon"]
|
|
2342
|
+
],
|
|
2343
|
+
[
|
|
2344
|
+
"[/",
|
|
2345
|
+
["/]", "\\]"],
|
|
2346
|
+
["lean-r", "trap-b"]
|
|
2347
|
+
],
|
|
2348
|
+
[
|
|
2349
|
+
"[\\",
|
|
2350
|
+
["\\]", "/]"],
|
|
2351
|
+
["lean-l", "trap-t"]
|
|
2352
|
+
],
|
|
2353
|
+
[
|
|
2354
|
+
"[",
|
|
2355
|
+
["]"],
|
|
2356
|
+
["rect"]
|
|
2357
|
+
],
|
|
2358
|
+
[
|
|
2359
|
+
"(",
|
|
2360
|
+
[")"],
|
|
2361
|
+
["round"]
|
|
2362
|
+
],
|
|
2363
|
+
[
|
|
2364
|
+
"{",
|
|
2365
|
+
["}"],
|
|
2366
|
+
["diamond"]
|
|
2367
|
+
],
|
|
2368
|
+
[
|
|
2369
|
+
">",
|
|
2370
|
+
["]"],
|
|
2371
|
+
["flag"]
|
|
2372
|
+
]
|
|
2373
|
+
], we = {
|
|
2374
|
+
rect: "rect",
|
|
2375
|
+
rectangle: "rect",
|
|
2376
|
+
proc: "rect",
|
|
2377
|
+
process: "rect",
|
|
2378
|
+
rounded: "round",
|
|
2379
|
+
event: "round",
|
|
2380
|
+
stadium: "stadium",
|
|
2381
|
+
pill: "stadium",
|
|
2382
|
+
terminal: "stadium",
|
|
2383
|
+
subproc: "subroutine",
|
|
2384
|
+
subprocess: "subroutine",
|
|
2385
|
+
subroutine: "subroutine",
|
|
2386
|
+
"fr-rect": "subroutine",
|
|
2387
|
+
cyl: "cylinder",
|
|
2388
|
+
cylinder: "cylinder",
|
|
2389
|
+
database: "cylinder",
|
|
2390
|
+
db: "cylinder",
|
|
2391
|
+
circle: "circle",
|
|
2392
|
+
circ: "circle",
|
|
2393
|
+
"dbl-circ": "doublecircle",
|
|
2394
|
+
"double-circle": "doublecircle",
|
|
2395
|
+
diam: "diamond",
|
|
2396
|
+
diamond: "diamond",
|
|
2397
|
+
decision: "diamond",
|
|
2398
|
+
question: "diamond",
|
|
2399
|
+
hex: "hexagon",
|
|
2400
|
+
hexagon: "hexagon",
|
|
2401
|
+
prepare: "hexagon",
|
|
2402
|
+
"lean-r": "lean-r",
|
|
2403
|
+
"lean-right": "lean-r",
|
|
2404
|
+
"in-out": "lean-r",
|
|
2405
|
+
"lean-l": "lean-l",
|
|
2406
|
+
"lean-left": "lean-l",
|
|
2407
|
+
"out-in": "lean-l",
|
|
2408
|
+
"trap-b": "trap-b",
|
|
2409
|
+
trapezoid: "trap-b",
|
|
2410
|
+
priority: "trap-b",
|
|
2411
|
+
"trap-t": "trap-t",
|
|
2412
|
+
"inv-trapezoid": "trap-t",
|
|
2413
|
+
manual: "trap-t",
|
|
2414
|
+
odd: "flag",
|
|
2415
|
+
flag: "flag",
|
|
2416
|
+
doc: "note",
|
|
2417
|
+
document: "note",
|
|
2418
|
+
"sm-circ": "start",
|
|
2419
|
+
start: "start",
|
|
2420
|
+
"small-circle": "start",
|
|
2421
|
+
"fr-circ": "end",
|
|
2422
|
+
stop: "end",
|
|
2423
|
+
"framed-circle": "end",
|
|
2424
|
+
fork: "bar",
|
|
2425
|
+
join: "bar",
|
|
2426
|
+
text: "none",
|
|
2427
|
+
"notch-rect": "note",
|
|
2428
|
+
card: "note",
|
|
2429
|
+
"f-circ": "point",
|
|
2430
|
+
junction: "point"
|
|
2431
|
+
}, Te = /^[\p{L}\p{N}_$]+(?:-[\p{L}\p{N}_$]+)*/u;
|
|
2432
|
+
function Ee(e, t, n) {
|
|
2433
|
+
for (; e[t] === " " || e[t] === " ";) t++;
|
|
2434
|
+
let r = Te.exec(e.slice(t));
|
|
2435
|
+
if (!r) return null;
|
|
2436
|
+
let i = r[0];
|
|
2437
|
+
t += i.length;
|
|
2438
|
+
let a = {};
|
|
2439
|
+
if (e.startsWith("@{", t)) {
|
|
2440
|
+
let n = e.indexOf("}", t);
|
|
2441
|
+
if (n > 0) {
|
|
2442
|
+
let r = e.slice(t + 2, n), i = /shape\s*:\s*["']?([\w-]+)/.exec(r)?.[1], o = /label\s*:\s*("([^"]*)"|'([^']*)'|[^,]+)/.exec(r);
|
|
2443
|
+
i && we[i] && (a.shape = we[i]), o && (a.label = $(o[2] ?? o[3] ?? o[1])), t = n + 1;
|
|
2444
|
+
}
|
|
2445
|
+
} else for (let [n, r, i] of Ce) {
|
|
2446
|
+
if (!e.startsWith(n, t)) continue;
|
|
2447
|
+
let o = t + n.length, s = "";
|
|
2448
|
+
for (; e[o] === " ";) o++;
|
|
2449
|
+
if (e[o] === "\"") {
|
|
2450
|
+
let t = e.indexOf("\"", o + 1);
|
|
2451
|
+
if (t < 0) break;
|
|
2452
|
+
for (s = e.slice(o, t + 1), o = t + 1; e[o] === " ";) o++;
|
|
2453
|
+
}
|
|
2454
|
+
let c = -1, l = 0;
|
|
2455
|
+
if (r.forEach((t, n) => {
|
|
2456
|
+
let r = e.indexOf(t, o);
|
|
2457
|
+
r >= 0 && (c < 0 || r < c) && (c = r, l = n);
|
|
2458
|
+
}), c < 0) break;
|
|
2459
|
+
s ||= e.slice(o, c), a = {
|
|
2460
|
+
label: $(s),
|
|
2461
|
+
shape: i[l]
|
|
2462
|
+
}, t = c + r[l].length;
|
|
2463
|
+
break;
|
|
2464
|
+
}
|
|
2465
|
+
let o = /^:::([\w-]+)/.exec(e.slice(t));
|
|
2466
|
+
if (o && (n.classes.set(i, [...n.classes.get(i) ?? [], o[1]]), t += o[0].length), !n.b.isCluster(i)) {
|
|
2467
|
+
let e = n.b.node(i, a), t = n.clusters[n.clusters.length - 1];
|
|
2468
|
+
t !== void 0 && t !== i && (e.cluster === void 0 || n.clusters.includes(e.cluster)) && (e.cluster = t);
|
|
2469
|
+
}
|
|
2470
|
+
return [i, t];
|
|
2471
|
+
}
|
|
2472
|
+
var De = {
|
|
2473
|
+
">": "arrow",
|
|
2474
|
+
o: "circle",
|
|
2475
|
+
x: "cross"
|
|
2476
|
+
};
|
|
2477
|
+
function Oe(e, t) {
|
|
2478
|
+
let n = e.slice(t), r = /^\s*([<ox]?)(--|==|-\.)\s+(.+?)\s*(-{2,}|={2,}|\.+-)([>ox]?)(?=[\s\p{L}\p{N}_$"]|$)/u.exec(n), i, a = "", o = "", s = "", c = !1;
|
|
2479
|
+
if (r) [, a, , i, o, s] = r, c = r[2] === "-.";
|
|
2480
|
+
else {
|
|
2481
|
+
if (r = /^\s*(~{3,})/.exec(n), r) return [{
|
|
2482
|
+
line: "hidden",
|
|
2483
|
+
minlen: 1
|
|
2484
|
+
}, t + r[0].length];
|
|
2485
|
+
if (r = /^\s*([<ox]?)(-{2,}|={2,}|-\.+-)([>ox]?)(?![-=.])/.exec(n), !r) return null;
|
|
2486
|
+
[, a, o, s] = r, c = o.includes(".");
|
|
2487
|
+
}
|
|
2488
|
+
let l = r[0].length, u = /^\s*\|([^|]*)\|/.exec(n.slice(l));
|
|
2489
|
+
u && (i = u[1], l += u[0].length), (s === "x" || s === "o") && /^[\p{L}\p{N}_]/u.test(n.slice(l)) && !u && (s = "", l--);
|
|
2490
|
+
let d = o.includes("="), f = c ? (o.match(/\./g)?.length ?? 1) - 1 : o.length - (s ? 2 : 3);
|
|
2491
|
+
return [{
|
|
2492
|
+
label: i !== void 0 && i.trim() ? $(i) : void 0,
|
|
2493
|
+
head: De[s] ?? "none",
|
|
2494
|
+
tail: a === "<" ? "arrow" : a === "o" ? "circle" : a === "x" ? "cross" : "none",
|
|
2495
|
+
line: d ? "thick" : c ? "dashed" : "solid",
|
|
2496
|
+
minlen: 1 + Math.max(0, Math.min(f, 6))
|
|
2497
|
+
}, t + l];
|
|
2498
|
+
}
|
|
2499
|
+
function ke(e, t, n) {
|
|
2500
|
+
let r = /^\w+\s+(\w+)/.exec(e)?.[1]?.toUpperCase(), i = new v(ye[r ?? "TB"] ?? "TB", "rect"), a = {
|
|
2501
|
+
b: i,
|
|
2502
|
+
clusters: [],
|
|
2503
|
+
classes: /* @__PURE__ */ new Map(),
|
|
2504
|
+
defs: /* @__PURE__ */ new Map()
|
|
2505
|
+
}, o = [], s = t.flatMap((e) => Se(e, ";")).map((e) => e.trim()).filter(Boolean), c = Se(e, ";").slice(1).map((e) => e.trim()).filter(Boolean);
|
|
2506
|
+
for (let e of [...c, ...s]) {
|
|
2507
|
+
let t;
|
|
2508
|
+
if (t = /^subgraph\s+(.*)$/.exec(e)) {
|
|
2509
|
+
let e = t[1].trim(), n = e, r = e, o = /^([^\s[]+)\s*\[(.*)\]$/.exec(e);
|
|
2510
|
+
o && (n = o[1], r = o[2]), r = $(r), n = n.replace(/^"(.*)"$/, "$1");
|
|
2511
|
+
let s = a.clusters[a.clusters.length - 1];
|
|
2512
|
+
i.cluster(n, r, s), a.clusters.push(n);
|
|
2513
|
+
continue;
|
|
2514
|
+
}
|
|
2515
|
+
if (e === "end") {
|
|
2516
|
+
a.clusters.pop();
|
|
2517
|
+
continue;
|
|
2518
|
+
}
|
|
2519
|
+
if (/^direction\s+\w+$/.test(e)) continue;
|
|
2520
|
+
if (t = /^classDef\s+([\w,-]+)\s+(.+)$/.exec(e)) {
|
|
2521
|
+
for (let e of t[1].split(",")) a.defs.set(e.trim(), xe(a.defs.get(e.trim()), be(t[2])));
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
if (t = /^class\s+([^\s]+)\s+([\w-]+)$/.exec(e)) {
|
|
2525
|
+
for (let e of t[1].split(",")) a.classes.set(e.trim(), [...a.classes.get(e.trim()) ?? [], t[2]]);
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
if (t = /^style\s+([^\s]+)\s+(.+)$/.exec(e)) {
|
|
2529
|
+
let e = be(t[2]);
|
|
2530
|
+
for (let n of t[1].split(",")) if (i.isCluster(n)) {
|
|
2531
|
+
let t = i.g.clusters.find((e) => e.id === n);
|
|
2532
|
+
t.style = xe(t.style, e);
|
|
2533
|
+
} else i.node(n).style = xe(i.get(n)?.style, e);
|
|
2534
|
+
continue;
|
|
2535
|
+
}
|
|
2536
|
+
if (t = /^linkStyle\s+([\d,\s]+|default)\s+(.+)$/.exec(e)) {
|
|
2537
|
+
o.push([t[1].trim(), be(t[2])]);
|
|
2538
|
+
continue;
|
|
2539
|
+
}
|
|
2540
|
+
if (/^(click|accTitle|accDescr|callback)\b/.test(e)) continue;
|
|
2541
|
+
let n = 0, r = [], s = null;
|
|
2542
|
+
for (;;) {
|
|
2543
|
+
let t = [];
|
|
2544
|
+
for (;;) {
|
|
2545
|
+
let r = Ee(e, n, a);
|
|
2546
|
+
if (!r) break;
|
|
2547
|
+
t.push(r[0]), n = r[1];
|
|
2548
|
+
let i = /^\s*&\s*/.exec(e.slice(n));
|
|
2549
|
+
if (!i) break;
|
|
2550
|
+
n += i[0].length;
|
|
2551
|
+
}
|
|
2552
|
+
if (!t.length) break;
|
|
2553
|
+
if (s) for (let e of r) for (let n of t) i.edge({
|
|
2554
|
+
...s,
|
|
2555
|
+
from: e,
|
|
2556
|
+
to: n
|
|
2557
|
+
});
|
|
2558
|
+
r = t;
|
|
2559
|
+
let o = Oe(e, n);
|
|
2560
|
+
if (!o) break;
|
|
2561
|
+
s = o[0], n = o[1];
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
let l = a.defs.get("default");
|
|
2565
|
+
for (let e of i.g.nodes) {
|
|
2566
|
+
let t = l ? xe(void 0, l) : e.style;
|
|
2567
|
+
l && e.style && (t = xe(t, e.style));
|
|
2568
|
+
for (let n of a.classes.get(e.id) ?? []) t = xe(t, a.defs.get(n) ?? {});
|
|
2569
|
+
t && (e.style = t);
|
|
2570
|
+
}
|
|
2571
|
+
for (let e of i.g.clusters) for (let t of a.classes.get(e.id) ?? []) e.style = xe(e.style, a.defs.get(t) ?? {});
|
|
2572
|
+
for (let [e, t] of o) {
|
|
2573
|
+
let n = e === "default" ? i.g.edges.map((e, t) => t) : e.split(",").map((e) => Number(e.trim()));
|
|
2574
|
+
for (let e of n) {
|
|
2575
|
+
let n = i.g.edges[e];
|
|
2576
|
+
n && (t.stroke && (n.color = t.stroke), t.sw && (n.sw = t.sw), t.dash && (n.line = "dashed"));
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
return i.g.title = n, i.g;
|
|
2580
|
+
}
|
|
2581
|
+
var Ae = [
|
|
2582
|
+
[
|
|
2583
|
+
"<<-->>",
|
|
2584
|
+
!0,
|
|
2585
|
+
"filled",
|
|
2586
|
+
!0
|
|
2587
|
+
],
|
|
2588
|
+
[
|
|
2589
|
+
"<<->>",
|
|
2590
|
+
!1,
|
|
2591
|
+
"filled",
|
|
2592
|
+
!0
|
|
2593
|
+
],
|
|
2594
|
+
[
|
|
2595
|
+
"-->>",
|
|
2596
|
+
!0,
|
|
2597
|
+
"filled",
|
|
2598
|
+
!1
|
|
2599
|
+
],
|
|
2600
|
+
[
|
|
2601
|
+
"->>",
|
|
2602
|
+
!1,
|
|
2603
|
+
"filled",
|
|
2604
|
+
!1
|
|
2605
|
+
],
|
|
2606
|
+
[
|
|
2607
|
+
"--x",
|
|
2608
|
+
!0,
|
|
2609
|
+
"cross",
|
|
2610
|
+
!1
|
|
2611
|
+
],
|
|
2612
|
+
[
|
|
2613
|
+
"-x",
|
|
2614
|
+
!1,
|
|
2615
|
+
"cross",
|
|
2616
|
+
!1
|
|
2617
|
+
],
|
|
2618
|
+
[
|
|
2619
|
+
"--)",
|
|
2620
|
+
!0,
|
|
2621
|
+
"open",
|
|
2622
|
+
!1
|
|
2623
|
+
],
|
|
2624
|
+
[
|
|
2625
|
+
"-)",
|
|
2626
|
+
!1,
|
|
2627
|
+
"open",
|
|
2628
|
+
!1
|
|
2629
|
+
],
|
|
2630
|
+
[
|
|
2631
|
+
"-->",
|
|
2632
|
+
!0,
|
|
2633
|
+
"none",
|
|
2634
|
+
!1
|
|
2635
|
+
],
|
|
2636
|
+
[
|
|
2637
|
+
"->",
|
|
2638
|
+
!1,
|
|
2639
|
+
"none",
|
|
2640
|
+
!1
|
|
2641
|
+
]
|
|
2642
|
+
], je = {
|
|
2643
|
+
participant: "participant",
|
|
2644
|
+
actor: "actor",
|
|
2645
|
+
boundary: "boundary",
|
|
2646
|
+
control: "control",
|
|
2647
|
+
entity: "entity",
|
|
2648
|
+
database: "database",
|
|
2649
|
+
collections: "collections",
|
|
2650
|
+
queue: "queue"
|
|
2651
|
+
};
|
|
2652
|
+
function Me(e, t) {
|
|
2653
|
+
let n = new le();
|
|
2654
|
+
n.s.title = t;
|
|
2655
|
+
let r = [], i = RegExp(`^(.+?)\\s*(${Ae.map(([e]) => e.replace(/[()|]/g, "\\$&")).join("|")})\\s*([+-]?)\\s*([^:]+?)\\s*(?::(.*))?$`);
|
|
2656
|
+
for (let t of e) {
|
|
2657
|
+
let e = t.trim();
|
|
2658
|
+
if (!e) continue;
|
|
2659
|
+
let a;
|
|
2660
|
+
if (a = /^(?:create\s+)?(participant|actor)\s+(.+?)(?:@\{(.*)\})?(?:\s+as\s+(.+))?$/.exec(e)) {
|
|
2661
|
+
let e = a[2].trim(), t = a[3] ? /"type"\s*:\s*"(\w+)"/.exec(a[3])?.[1] : void 0;
|
|
2662
|
+
n.participant(e, {
|
|
2663
|
+
kind: je[t ?? a[1]] ?? "participant",
|
|
2664
|
+
label: a[4] ? $(a[4]) : e
|
|
2665
|
+
});
|
|
2666
|
+
} else if (a = /^destroy\s+(.+)$/.exec(e)) n.push({
|
|
2667
|
+
t: "destroy",
|
|
2668
|
+
who: a[1].trim()
|
|
2669
|
+
});
|
|
2670
|
+
else if (/^autonumber\b/.test(e)) n.s.autonumber = !/\boff\b/.test(e);
|
|
2671
|
+
else if (a = /^title\s*:?\s*(.+)$/.exec(e)) n.s.title = $(a[1]);
|
|
2672
|
+
else if (a = /^(activate|deactivate)\s+(.+)$/.exec(e)) n.push({
|
|
2673
|
+
t: "act",
|
|
2674
|
+
who: a[2].trim(),
|
|
2675
|
+
on: a[1] === "activate"
|
|
2676
|
+
});
|
|
2677
|
+
else if (a = /^note\s+(left of|right of|over)\s+([^:]+):(.*)$/i.exec(e)) {
|
|
2678
|
+
let e = a[1].toLowerCase().startsWith("left") ? "left" : a[1].toLowerCase().startsWith("right") ? "right" : "over";
|
|
2679
|
+
n.push({
|
|
2680
|
+
t: "note",
|
|
2681
|
+
pos: e,
|
|
2682
|
+
who: a[2].split(",").map((e) => e.trim()),
|
|
2683
|
+
text: $(a[3])
|
|
2684
|
+
});
|
|
2685
|
+
} else if (a = /^box\b/.exec(e)) r.push("box");
|
|
2686
|
+
else if (a = /^(loop|alt|opt|par|par_over|critical|break|rect)\b\s*(.*)$/.exec(e)) {
|
|
2687
|
+
r.push("frag");
|
|
2688
|
+
let e = a[1] === "par_over" ? "par" : a[1];
|
|
2689
|
+
n.push({
|
|
2690
|
+
t: "block",
|
|
2691
|
+
kind: e,
|
|
2692
|
+
label: e === "rect" ? "" : $(a[2]),
|
|
2693
|
+
fill: e === "rect" ? l(a[2]) : void 0
|
|
2694
|
+
});
|
|
2695
|
+
} else if (a = /^(else|and|option)\b\s*(.*)$/.exec(e)) n.push({
|
|
2696
|
+
t: "else",
|
|
2697
|
+
label: $(a[2])
|
|
2698
|
+
});
|
|
2699
|
+
else if (e === "end") r.pop() === "frag" && n.push({ t: "end" });
|
|
2700
|
+
else if (a = i.exec(e)) {
|
|
2701
|
+
let e = Ae.find(([e]) => e === a[2]);
|
|
2702
|
+
n.push({
|
|
2703
|
+
t: "msg",
|
|
2704
|
+
from: a[1].trim(),
|
|
2705
|
+
to: a[4].trim(),
|
|
2706
|
+
text: $(a[5] ?? ""),
|
|
2707
|
+
dashed: e[1],
|
|
2708
|
+
head: e[2],
|
|
2709
|
+
both: e[3],
|
|
2710
|
+
activate: a[3] === "+",
|
|
2711
|
+
deactivate: a[3] === "-"
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
return n.s;
|
|
2716
|
+
}
|
|
2717
|
+
var Ne = (e) => e.replace(/~([^~]*)~/g, "<$1>"), Pe = {
|
|
2718
|
+
"<|": "triangle",
|
|
2719
|
+
"|>": "triangle",
|
|
2720
|
+
"*": "diamond",
|
|
2721
|
+
o: "odiamond",
|
|
2722
|
+
"<": "open",
|
|
2723
|
+
">": "open",
|
|
2724
|
+
"()": "ocircle"
|
|
2725
|
+
};
|
|
2726
|
+
function Fe(e, t) {
|
|
2727
|
+
let n = new v("TB", "rect"), r = /* @__PURE__ */ new Map(), i = [], a = (e) => {
|
|
2728
|
+
let t = e.replace(/~.*~$/, "");
|
|
2729
|
+
return r.has(t) || r.set(t, {
|
|
2730
|
+
attrs: [],
|
|
2731
|
+
methods: [],
|
|
2732
|
+
label: e === t ? void 0 : Ne(e)
|
|
2733
|
+
}), n.node(t, {}, i[i.length - 1]), r.get(t);
|
|
2734
|
+
}, o = (e, t) => {
|
|
2735
|
+
let n = Ne(t.trim());
|
|
2736
|
+
if (!n) return;
|
|
2737
|
+
let r = /^<<(.+)>>$/.exec(n);
|
|
2738
|
+
r ? e.stereo = r[1] : n.includes("(") ? e.methods.push(n.replace(/[$*]$/, "")) : e.attrs.push(n.replace(/[$*]$/, ""));
|
|
2739
|
+
}, s = null, c = 0, l = /^([^\s"]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|o|<|\(\))?(--|\.\.)(\|>|\*|o|>|\(\))?\s*(?:"([^"]*)"\s*)?([^\s":]+)\s*(?::\s*(.*))?$/;
|
|
2740
|
+
for (let t of e) {
|
|
2741
|
+
let e = t.trim();
|
|
2742
|
+
if (!e) continue;
|
|
2743
|
+
if (s) {
|
|
2744
|
+
e === "}" ? s = null : o(s, e);
|
|
2745
|
+
continue;
|
|
2746
|
+
}
|
|
2747
|
+
let r;
|
|
2748
|
+
if (r = /^direction\s+(\w+)$/.exec(e)) n.g.dir = ye[r[1].toUpperCase()] ?? "TB";
|
|
2749
|
+
else if (r = /^namespace\s+([\w.]+)\s*\{$/.exec(e)) n.cluster(r[1], r[1], i[i.length - 1]), i.push(r[1]);
|
|
2750
|
+
else if (e === "}" && i.length) i.pop();
|
|
2751
|
+
else if (r = /^class\s+([\w$~,<>.-]+?)(?:\["([^"]*)"\])?(?::::[\w-]+)?\s*(\{)?\s*(\})?$/.exec(e)) {
|
|
2752
|
+
let e = a(r[1]);
|
|
2753
|
+
r[2] && (e.label = r[2]), r[3] && !r[4] && (s = e);
|
|
2754
|
+
} else if (r = /^<<(.+)>>\s+(\S+)$/.exec(e)) a(r[2]).stereo = r[1];
|
|
2755
|
+
else if (r = /^note\s+(?:for\s+(\S+)\s+)?"(.*)"$/.exec(e)) {
|
|
2756
|
+
let e = `__note${c++}`;
|
|
2757
|
+
n.node(e, {
|
|
2758
|
+
label: $(r[2]),
|
|
2759
|
+
shape: "note",
|
|
2760
|
+
style: {
|
|
2761
|
+
fill: "#fff6c8",
|
|
2762
|
+
stroke: "#c9a227"
|
|
2763
|
+
}
|
|
2764
|
+
}), r[1] && n.edge({
|
|
2765
|
+
from: e,
|
|
2766
|
+
to: r[1].replace(/~.*~$/, ""),
|
|
2767
|
+
line: "dashed",
|
|
2768
|
+
head: "none"
|
|
2769
|
+
});
|
|
2770
|
+
} else if (!/^(classDef|cssClass|click|callback|link|style)\b/.test(e)) {
|
|
2771
|
+
if (r = l.exec(e)) {
|
|
2772
|
+
let [, e, t, i, o, s, c, l, u] = r;
|
|
2773
|
+
a(e), a(l), n.edge({
|
|
2774
|
+
from: e.replace(/~.*~$/, ""),
|
|
2775
|
+
to: l.replace(/~.*~$/, ""),
|
|
2776
|
+
tail: i ? Pe[i] : "none",
|
|
2777
|
+
head: s ? Pe[s] : "none",
|
|
2778
|
+
line: o === ".." ? "dashed" : "solid",
|
|
2779
|
+
label: u ? $(u) : void 0,
|
|
2780
|
+
tailLabel: t || void 0,
|
|
2781
|
+
headLabel: c || void 0
|
|
2782
|
+
});
|
|
2783
|
+
} else (r = /^([\w$~.-]+)\s*:\s*(.+)$/.exec(e)) && o(a(r[1]), r[2]);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
for (let e of n.g.nodes) {
|
|
2787
|
+
let t = r.get(e.id);
|
|
2788
|
+
if (!t) continue;
|
|
2789
|
+
let n = [];
|
|
2790
|
+
t.stereo && n.push([`«${t.stereo}»`]), n.push([t.label ?? e.id]);
|
|
2791
|
+
let i = [{
|
|
2792
|
+
rows: n,
|
|
2793
|
+
bold: !0,
|
|
2794
|
+
center: !0
|
|
2795
|
+
}];
|
|
2796
|
+
(t.attrs.length || t.methods.length) && i.push({ rows: t.attrs.map((e) => [e]) }, { rows: t.methods.map((e) => [e]) }), e.sections = i;
|
|
2797
|
+
}
|
|
2798
|
+
return n.g.title = t, n.g;
|
|
2799
|
+
}
|
|
2800
|
+
function Ie(e, t) {
|
|
2801
|
+
let n = new v("TB", "round"), r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = 0, c = null, l = null, u = () => r[r.length - 1], d = (e, t) => {
|
|
2802
|
+
let r = e.trim(), i = /:::([\w-]+)$/.exec(r);
|
|
2803
|
+
if (i && (r = r.slice(0, i.index), o.set(r, [...o.get(r) ?? [], i[1]])), r === "[*]") {
|
|
2804
|
+
let e = `${u() ?? ""}__${t ? "end" : "start"}`;
|
|
2805
|
+
return n.node(e, {
|
|
2806
|
+
label: "",
|
|
2807
|
+
shape: t ? "end" : "start"
|
|
2808
|
+
}, u()), e;
|
|
2809
|
+
}
|
|
2810
|
+
return n.isCluster(r) || n.node(r, {}, u()), r;
|
|
2811
|
+
};
|
|
2812
|
+
for (let t of e) {
|
|
2813
|
+
let e = t.trim();
|
|
2814
|
+
if (c) {
|
|
2815
|
+
if (/^end\s*note$/i.test(e)) {
|
|
2816
|
+
let e = `__note${s++}`;
|
|
2817
|
+
n.node(e, {
|
|
2818
|
+
label: c.join("\n"),
|
|
2819
|
+
shape: "note",
|
|
2820
|
+
style: {
|
|
2821
|
+
fill: "#fff6c8",
|
|
2822
|
+
stroke: "#c9a227"
|
|
2823
|
+
}
|
|
2824
|
+
}, u()), l && n.edge({
|
|
2825
|
+
from: l.id,
|
|
2826
|
+
to: e,
|
|
2827
|
+
line: "dashed",
|
|
2828
|
+
head: "none"
|
|
2829
|
+
}), c = null;
|
|
2830
|
+
} else c.push(e);
|
|
2831
|
+
continue;
|
|
2832
|
+
}
|
|
2833
|
+
if (!e || e === "--") continue;
|
|
2834
|
+
let f;
|
|
2835
|
+
if (f = /^direction\s+(\w+)$/.exec(e)) r.length || (n.g.dir = ye[f[1].toUpperCase()] ?? "TB");
|
|
2836
|
+
else if (f = /^state\s+(?:"([^"]+)"\s+as\s+)?([\w.-]+)\s*(<<(fork|join|choice)>>)?\s*(\{)?$/.exec(e)) {
|
|
2837
|
+
let e = f[2];
|
|
2838
|
+
if (f[5]) {
|
|
2839
|
+
n.cluster(e, f[1] ? $(f[1]) : e, u()), r.push(e);
|
|
2840
|
+
continue;
|
|
2841
|
+
}
|
|
2842
|
+
let t = f[4];
|
|
2843
|
+
n.node(e, t === "fork" || t === "join" ? {
|
|
2844
|
+
shape: "bar",
|
|
2845
|
+
label: ""
|
|
2846
|
+
} : t === "choice" ? {
|
|
2847
|
+
shape: "diamond",
|
|
2848
|
+
label: ""
|
|
2849
|
+
} : f[1] ? { label: $(f[1]) } : {}, u());
|
|
2850
|
+
} else if (f = /^state\s+"([^"]+)"\s+as\s+([\w.-]+)\s*\{$/.exec(e)) n.cluster(f[2], $(f[1]), u()), r.push(f[2]);
|
|
2851
|
+
else if (e === "}") r.pop();
|
|
2852
|
+
else if (f = /^note\s+(left of|right of|over)\s+([\w.-]+)\s*(?::\s*(.*))?$/i.exec(e)) {
|
|
2853
|
+
let e = f[2];
|
|
2854
|
+
if (f[3] !== void 0) {
|
|
2855
|
+
let t = `__note${s++}`;
|
|
2856
|
+
n.node(t, {
|
|
2857
|
+
label: $(f[3]),
|
|
2858
|
+
shape: "note",
|
|
2859
|
+
style: {
|
|
2860
|
+
fill: "#fff6c8",
|
|
2861
|
+
stroke: "#c9a227"
|
|
2862
|
+
}
|
|
2863
|
+
}, u()), n.edge({
|
|
2864
|
+
from: e,
|
|
2865
|
+
to: t,
|
|
2866
|
+
line: "dashed",
|
|
2867
|
+
head: "none"
|
|
2868
|
+
});
|
|
2869
|
+
} else c = [], l = { id: e };
|
|
2870
|
+
} else if (f = /^classDef\s+([\w-]+)\s+(.+)$/.exec(e)) a.set(f[1], be(f[2]));
|
|
2871
|
+
else if (f = /^class\s+([\w,\s-]+?)\s+([\w-]+)$/.exec(e)) for (let e of f[1].split(",")) o.set(e.trim(), [...o.get(e.trim()) ?? [], f[2]]);
|
|
2872
|
+
else if (f = /^(.+?)\s*-->\s*([^:]+?)\s*(?::\s*(.*))?$/.exec(e)) {
|
|
2873
|
+
let e = d(f[1], !1), t = d(f[2], !0);
|
|
2874
|
+
n.edge({
|
|
2875
|
+
from: e,
|
|
2876
|
+
to: t,
|
|
2877
|
+
head: "arrow",
|
|
2878
|
+
label: f[3] ? $(f[3]) : void 0
|
|
2879
|
+
});
|
|
2880
|
+
} else (f = /^([\w.-]+)\s*:\s*(.+)$/.exec(e)) ? (d(f[1], !1), i.set(f[1], [...i.get(f[1]) ?? [], $(f[2])])) : (f = /^([\w.-]+)$/.exec(e)) && d(f[1], !1);
|
|
2881
|
+
}
|
|
2882
|
+
for (let e of n.g.nodes) {
|
|
2883
|
+
let t = i.get(e.id);
|
|
2884
|
+
t && e.shape === "round" && (e.sections = [{
|
|
2885
|
+
rows: [[e.label]],
|
|
2886
|
+
bold: !0,
|
|
2887
|
+
center: !0
|
|
2888
|
+
}, { rows: t.map((e) => [e]) }]);
|
|
2889
|
+
for (let t of o.get(e.id) ?? []) e.style = xe(e.style, a.get(t) ?? {});
|
|
2890
|
+
}
|
|
2891
|
+
return n.g.title = t, n.g;
|
|
2892
|
+
}
|
|
2893
|
+
var Le = {
|
|
2894
|
+
"|o": "zero-one",
|
|
2895
|
+
"o|": "zero-one",
|
|
2896
|
+
"||": "one",
|
|
2897
|
+
"}o": "zero-many",
|
|
2898
|
+
"o{": "zero-many",
|
|
2899
|
+
"}|": "one-many",
|
|
2900
|
+
"|{": "one-many"
|
|
2901
|
+
}, Re = {
|
|
2902
|
+
"one or zero": "zero-one",
|
|
2903
|
+
"zero or one": "zero-one",
|
|
2904
|
+
"one or more": "one-many",
|
|
2905
|
+
"one or many": "one-many",
|
|
2906
|
+
"many(1)": "one-many",
|
|
2907
|
+
"1+": "one-many",
|
|
2908
|
+
"zero or more": "zero-many",
|
|
2909
|
+
"zero or many": "zero-many",
|
|
2910
|
+
"many(0)": "zero-many",
|
|
2911
|
+
"0+": "zero-many",
|
|
2912
|
+
"only one": "one",
|
|
2913
|
+
1: "one"
|
|
2914
|
+
};
|
|
2915
|
+
function ze(e, t) {
|
|
2916
|
+
let n = new v("TB", "rect"), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = null, o = (e) => {
|
|
2917
|
+
let t = /^([\w-]+)(?:\[\s*"?([^"\]]*)"?\s*\])?$/.exec(e.trim().replace(/^"(.*)"$/, "$1")), a = t ? t[1] : e.trim().replace(/^"(.*)"$/, "$1");
|
|
2918
|
+
return t?.[2] && i.set(a, t[2]), n.node(a), r.has(a) || r.set(a, []), a;
|
|
2919
|
+
}, s = Object.keys(Re).sort((e, t) => t.length - e.length).map((e) => e.replace(/[()+]/g, "\\$&")).join("|"), c = /^(\S+)\s+(\|o|\|\||\}o|\}\|)(--|\.\.)(o\||\|\||o\{|\|\{)\s+(\S+)\s*:\s*(.*)$/, l = RegExp(`^(\\S+)\\s+(${s})\\s+(to|optionally to)\\s+(${s})\\s+(\\S+)\\s*:\\s*(.*)$`, "i");
|
|
2920
|
+
for (let t of e) {
|
|
2921
|
+
let e = t.trim();
|
|
2922
|
+
if (!e) continue;
|
|
2923
|
+
if (a) {
|
|
2924
|
+
if (e === "}") {
|
|
2925
|
+
a = null;
|
|
2926
|
+
continue;
|
|
2927
|
+
}
|
|
2928
|
+
let t = /^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)\s*,?)*)\s*(?:"(.*)")?$/.exec(e);
|
|
2929
|
+
t && r.get(a).push([
|
|
2930
|
+
t[1].replace(/~([^~]*)~/g, "<$1>"),
|
|
2931
|
+
t[2],
|
|
2932
|
+
t[3].replace(/\s+/g, " ").trim(),
|
|
2933
|
+
t[4] ?? ""
|
|
2934
|
+
]);
|
|
2935
|
+
continue;
|
|
2936
|
+
}
|
|
2937
|
+
let i;
|
|
2938
|
+
if (i = /^direction\s+(\w+)$/.exec(e)) n.g.dir = ye[i[1].toUpperCase()] ?? "TB";
|
|
2939
|
+
else if (i = /^(.+?)\s*\{$/.exec(e)) a = o(i[1]);
|
|
2940
|
+
else if (i = c.exec(e)) {
|
|
2941
|
+
let e = o(i[1]), t = o(i[5]);
|
|
2942
|
+
n.edge({
|
|
2943
|
+
from: e,
|
|
2944
|
+
to: t,
|
|
2945
|
+
tail: Le[i[2]],
|
|
2946
|
+
head: Le[i[4]],
|
|
2947
|
+
line: i[3] === ".." ? "dashed" : "solid",
|
|
2948
|
+
label: $(i[6]) || void 0
|
|
2949
|
+
});
|
|
2950
|
+
} else if (i = l.exec(e)) {
|
|
2951
|
+
let e = o(i[1]), t = o(i[5]);
|
|
2952
|
+
n.edge({
|
|
2953
|
+
from: e,
|
|
2954
|
+
to: t,
|
|
2955
|
+
tail: Re[i[2].toLowerCase()],
|
|
2956
|
+
head: Re[i[4].toLowerCase()],
|
|
2957
|
+
line: i[3].toLowerCase() === "to" ? "solid" : "dashed",
|
|
2958
|
+
label: $(i[6]) || void 0
|
|
2959
|
+
});
|
|
2960
|
+
} else (i = /^([\w-]+(?:\[[^\]]*\])?)$/.exec(e)) && o(i[1]);
|
|
2961
|
+
}
|
|
2962
|
+
for (let e of n.g.nodes) {
|
|
2963
|
+
let t = r.get(e.id) ?? [], n = t.map((e) => e.filter((e, t) => t < 2 || e));
|
|
2964
|
+
e.sections = [{
|
|
2965
|
+
rows: [[i.get(e.id) ?? e.id]],
|
|
2966
|
+
bold: !0,
|
|
2967
|
+
center: !0
|
|
2968
|
+
}], t.length && e.sections.push({ rows: n });
|
|
2969
|
+
}
|
|
2970
|
+
return n.g.title = t, n.g;
|
|
2971
|
+
}
|
|
2972
|
+
function Be(e, t, n) {
|
|
2973
|
+
let r = /\bshowData\b/.test(e), i = /\btitle\s+(.+)$/.exec(e)?.[1] ?? n, a = [];
|
|
2974
|
+
for (let e of t) {
|
|
2975
|
+
let t = e.trim(), n;
|
|
2976
|
+
(n = /^title\s+(.+)$/.exec(t)) ? i = n[1] : (n = /^"([^"]*)"\s*:\s*([-\d.eE+]+)$/.exec(t)) && a.push({
|
|
2977
|
+
label: $(n[1]),
|
|
2978
|
+
value: Number(n[2])
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
return {
|
|
2982
|
+
title: i ? $(i) : void 0,
|
|
2983
|
+
showData: r,
|
|
2984
|
+
slices: a
|
|
2985
|
+
};
|
|
2986
|
+
}
|
|
2987
|
+
var Ve = {
|
|
2988
|
+
ms: 1,
|
|
2989
|
+
s: 1e3,
|
|
2990
|
+
m: 6e4,
|
|
2991
|
+
h: 36e5,
|
|
2992
|
+
d: 864e5,
|
|
2993
|
+
w: 6048e5,
|
|
2994
|
+
M: 2592e6,
|
|
2995
|
+
y: 31536e6
|
|
2996
|
+
};
|
|
2997
|
+
function He(e, t) {
|
|
2998
|
+
if (e = e.trim(), t === "X") return Number(e) * 1e3;
|
|
2999
|
+
if (t === "x") return Number(e);
|
|
3000
|
+
let n = [], r = t.replace(/YYYY|YY|MM|M|DD|D|HH|H|mm|ss|SSS|[.*+?^${}()|[\]\\]/g, (e) => /^[.*+?^${}()|[\]\\]$/.test(e) ? "\\" + e : (n.push(e), e === "YYYY" ? "(\\d{4})" : e === "SSS" ? "(\\d{3})" : e.length === 1 ? "(\\d{1,2})" : "(\\d{2})")), i = RegExp(`^${r}$`).exec(e);
|
|
3001
|
+
if (!i) {
|
|
3002
|
+
let t = Date.parse(e.length === 10 ? e + "T00:00:00Z" : e);
|
|
3003
|
+
return Number.isFinite(t) ? t : void 0;
|
|
3004
|
+
}
|
|
3005
|
+
let a = {};
|
|
3006
|
+
n.forEach((e, t) => a[e[0]] = Number(i[t + 1]));
|
|
3007
|
+
let o = a.Y === void 0 ? 1970 : n.includes("YY") ? 2e3 + a.Y : a.Y;
|
|
3008
|
+
return Date.UTC(o, (a.M ?? 1) - 1, a.D ?? 1, a.H ?? 0, a.m ?? 0, a.s ?? 0, a.S ?? 0);
|
|
3009
|
+
}
|
|
3010
|
+
function Ue(e, t) {
|
|
3011
|
+
let n = "YYYY-MM-DD", r = t, i = [], a = /* @__PURE__ */ new Map(), o, s = (() => {
|
|
3012
|
+
let e = /* @__PURE__ */ new Date();
|
|
3013
|
+
return Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate());
|
|
3014
|
+
})();
|
|
3015
|
+
for (let t of e) {
|
|
3016
|
+
let e = t.trim();
|
|
3017
|
+
if (!e) continue;
|
|
3018
|
+
let c;
|
|
3019
|
+
if (c = /^dateFormat\s+(.+)$/.exec(e)) n = c[1].trim();
|
|
3020
|
+
else if (c = /^title\s+(.+)$/.exec(e)) r = c[1];
|
|
3021
|
+
else if (/^(axisFormat|tickInterval|excludes|includes|todayMarker|weekday|inclusiveEndDates|topAxis|displayMode)\b/.test(e)) continue;
|
|
3022
|
+
else if (c = /^section\s+(.*)$/.exec(e)) i.push({
|
|
3023
|
+
name: $(c[1]),
|
|
3024
|
+
tasks: []
|
|
3025
|
+
});
|
|
3026
|
+
else if (c = /^(.+?)\s*:\s*(.+)$/.exec(e)) {
|
|
3027
|
+
let e = $(c[1]), t = c[2].split(",").map((e) => e.trim()).filter(Boolean), r = {
|
|
3028
|
+
name: e,
|
|
3029
|
+
start: 0,
|
|
3030
|
+
end: 0
|
|
3031
|
+
};
|
|
3032
|
+
for (; t.length && /^(done|active|crit|milestone)$/.test(t[0]);) {
|
|
3033
|
+
let e = t.shift();
|
|
3034
|
+
r[e] = !0;
|
|
3035
|
+
}
|
|
3036
|
+
let l;
|
|
3037
|
+
t.length >= 3 && (l = t.shift());
|
|
3038
|
+
let u, d;
|
|
3039
|
+
t.length >= 2 ? [u, d] = t : d = t[0], t.length === 2 && !/^after\s/.test(u) && He(u, n) === void 0 && !/^\d/.test(u) && (l = u, u = void 0), r.start = ((e) => {
|
|
3040
|
+
if (!e) return o ? o.end : s;
|
|
3041
|
+
let t = /^after\s+(.+)$/.exec(e);
|
|
3042
|
+
if (t) {
|
|
3043
|
+
let e = t[1].split(/\s+/).map((e) => a.get(e)?.end).filter((e) => e !== void 0);
|
|
3044
|
+
return e.length ? Math.max(...e) : o ? o.end : s;
|
|
3045
|
+
}
|
|
3046
|
+
return He(e, n) ?? (o ? o.end : s);
|
|
3047
|
+
})(u);
|
|
3048
|
+
let f = d && /^([\d.]+)\s*(ms|s|m|h|d|w|M|y)$/.exec(d), p = d && /^until\s+(.+)$/.exec(d);
|
|
3049
|
+
r.end = f ? r.start + Number(f[1]) * Ve[f[2]] : p ? a.get(p[1].trim())?.start ?? r.start : d ? He(d, n) ?? r.start + 864e5 : r.start + 864e5, r.milestone && (r.end = r.start), l && a.set(l, r), i.length || i.push({
|
|
3050
|
+
name: "",
|
|
3051
|
+
tasks: []
|
|
3052
|
+
}), i[i.length - 1].tasks.push(r), o = r;
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
return {
|
|
3056
|
+
title: r ? $(r) : void 0,
|
|
3057
|
+
sections: i
|
|
3058
|
+
};
|
|
3059
|
+
}
|
|
3060
|
+
var We = [
|
|
3061
|
+
[/^[\w-]*\(\((.*)\)\)$/, "circle"],
|
|
3062
|
+
[/^[\w-]*\)\)(.*)\(\($/, "cloud"],
|
|
3063
|
+
[/^[\w-]*\)(.*)\($/, "cloud"],
|
|
3064
|
+
[/^[\w-]*\{\{(.*)\}\}$/, "hexagon"],
|
|
3065
|
+
[/^[\w-]*\[(.*)\]$/, "rect"],
|
|
3066
|
+
[/^[\w-]*\((.*)\)$/, "round"]
|
|
3067
|
+
];
|
|
3068
|
+
function Ge(e) {
|
|
3069
|
+
let t = [], n;
|
|
3070
|
+
for (let r of e) {
|
|
3071
|
+
if (!r.trim()) continue;
|
|
3072
|
+
let e = r.trim().replace(/:::[\w\s-]+$/, "").trim();
|
|
3073
|
+
if (/^::icon\(/.test(e) || !e) continue;
|
|
3074
|
+
let i = r.replace(/\t/g, " ").search(/\S/), a = e, o;
|
|
3075
|
+
for (let [t, n] of We) {
|
|
3076
|
+
let r = t.exec(e);
|
|
3077
|
+
if (r) {
|
|
3078
|
+
a = r[1], o = n;
|
|
3079
|
+
break;
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
let s = {
|
|
3083
|
+
label: $(a),
|
|
3084
|
+
shape: o,
|
|
3085
|
+
children: []
|
|
3086
|
+
};
|
|
3087
|
+
if (!n) n = s, t.push({
|
|
3088
|
+
indent: i,
|
|
3089
|
+
n: s
|
|
3090
|
+
});
|
|
3091
|
+
else {
|
|
3092
|
+
for (; t.length > 1 && t[t.length - 1].indent >= i;) t.pop();
|
|
3093
|
+
t[t.length - 1].n.children.push(s), t.push({
|
|
3094
|
+
indent: i,
|
|
3095
|
+
n: s
|
|
3096
|
+
});
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
if (!n) throw new _("The mind map is empty");
|
|
3100
|
+
return n;
|
|
3101
|
+
}
|
|
3102
|
+
// packages/diagram/src/dom.ts
|
|
3103
|
+
async function Ke(e, t = 2) {
|
|
3104
|
+
let n = (t) => Number(RegExp(`<svg[^>]*\\s${t}="([\\d.]+)"`).exec(e)?.[1] ?? 0), r = n("width"), i = n("height");
|
|
3105
|
+
if (!r || !i) throw Error("Not a picture with a size");
|
|
3106
|
+
let a = new Image();
|
|
3107
|
+
a.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`, await a.decode();
|
|
3108
|
+
let o = document.createElement("canvas");
|
|
3109
|
+
o.width = Math.max(1, Math.round(r * t)), o.height = Math.max(1, Math.round(i * t));
|
|
3110
|
+
let s = o.getContext("2d");
|
|
3111
|
+
if (!s) throw Error("No 2D canvas");
|
|
3112
|
+
return s.scale(t, t), s.drawImage(a, 0, 0, r, i), new Promise((e, t) => o.toBlob((n) => n ? e(n) : t(/* @__PURE__ */ Error("PNG export failed")), "image/png"));
|
|
3113
|
+
}
|
|
3114
|
+
function qe(e, t) {
|
|
3115
|
+
e.innerHTML = t.join("");
|
|
3116
|
+
}
|
|
3117
|
+
// packages/mermaid/src/index.ts
|
|
3118
|
+
var Je = class extends Error {
|
|
3119
|
+
constructor(e) {
|
|
3120
|
+
super(e), this.name = "DiagramError";
|
|
3121
|
+
}
|
|
3122
|
+
};
|
|
3123
|
+
function Ye(e) {
|
|
3124
|
+
try {
|
|
3125
|
+
let t = ve(e);
|
|
3126
|
+
return {
|
|
3127
|
+
svg: t.svg,
|
|
3128
|
+
width: t.w,
|
|
3129
|
+
height: t.h
|
|
3130
|
+
};
|
|
3131
|
+
} catch (e) {
|
|
3132
|
+
throw new Je(e.message);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
function Xe(e, t) {
|
|
3136
|
+
let n = Ye(t);
|
|
3137
|
+
return qe(e, [n.svg]), n;
|
|
3138
|
+
}
|
|
3139
|
+
function Ze(e, t = 2) {
|
|
3140
|
+
return Ke(e, t);
|
|
3141
|
+
}
|
|
3142
|
+
export { Je as DiagramError, Ye as render, Xe as renderTo, Ze as toPng };
|
|
3143
|
+
|
|
3144
|
+
//# sourceMappingURL=index.js.map
|