@draftably/runtime 0.2.0 → 0.3.0
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/README.md +13 -0
- package/dist/assets/render.worker-dvseyGmC.js +8310 -0
- package/dist/compile-Csfz4rk4.js +7267 -0
- package/dist/{font-data-tnqJ-kTK.js → font-data-DLXJur0j.js} +1 -1
- package/dist/graph.js +669 -0
- package/dist/index.js +5 -4
- package/dist/render-Dgo42PR4.js +1146 -0
- package/dist/types/src/dsl/compile.d.ts +13 -0
- package/dist/types/src/dsl/corridors.d.ts +38 -0
- package/dist/types/src/graph-api/core.d.ts +125 -0
- package/dist/types/src/graph-api/cytoscape.d.ts +48 -0
- package/dist/types/src/graph-api/dagre.d.ts +33 -0
- package/dist/types/src/graph-api/elk.d.ts +91 -0
- package/dist/types/src/graph-api/index.d.ts +60 -0
- package/dist/types/src/graph-api/react-flow.d.ts +100 -0
- package/dist/types/src/graph-api/transform.d.ts +6 -0
- package/dist/types/src/model/types.d.ts +9 -0
- package/dist/viewer.js +31 -29
- package/package.json +5 -1
- package/dist/assets/render.worker-fWW85Tf9.js +0 -7661
- package/dist/render-ZzhO-2H6.js +0 -7676
|
@@ -0,0 +1,1146 @@
|
|
|
1
|
+
import { i as Mt, s as N, j as O, k as Ue, l as be, G as Y, m as W, n as kt, o as vt, t as At, u as Et, N as qe, w as pe, x as _t, y as St, z as Te, A as ze, B as Ve, C as Rt, P as It, S as te, D as Lt, E as Ot, v as Me, H as ge, I as ne, J as Xe, K as Ge, L as Ke, g as Dt, M as Ft, O as Nt, Q as jt, R as Ee, T as Pt, U as Ht, V as _e, W as Bt, X as Ct, Y as Ut, Z as qt, _ as zt, $ as Vt, a0 as Xt, a1 as Gt, a2 as Kt, a3 as Wt, a4 as Zt, a5 as Yt, a6 as Qt, a7 as Jt, a8 as en, a as We, a9 as re, e as tn, h as nn, d as rn } from "./compile-Csfz4rk4.js";
|
|
2
|
+
const an = {
|
|
3
|
+
group: '<path d="M7 3H3v4m14-4h4v4M3 17v4h4m14-4v4h-4"/><rect x="7" y="7" width="10" height="10" rx="1.5"/>'
|
|
4
|
+
}, me = {
|
|
5
|
+
added: "added",
|
|
6
|
+
changed: "changed",
|
|
7
|
+
removed: "removed",
|
|
8
|
+
context: "shown for context"
|
|
9
|
+
}, Se = (e) => `${e} line${e === 1 ? "" : "s"}`, sn = ({ status: e, count: t, lines: n }) => t ? `${t} ${me[e]}${n ? ` · ${Se(n)}` : ""}` : `${Se(n)} ${me[e]}`, ae = { added: "green", changed: "amber", removed: "red" }, on = { added: 500, changed: 500, removed: 700 }, Ze = (e, t) => e.dark ? O(e, ae[t], 400).fill : Ue(O(e, ae[t], on[t]).fill, e.canvas, 3), $e = { r: 7, inset: 2 }, V = 4, Ye = (e) => Ue(O(e, "secondary", e.dark ? 300 : 500).fill, e.canvas, 3), Re = { opacity: 1, strike: !1 }, ln = 2.4;
|
|
10
|
+
function U(e, t, n) {
|
|
11
|
+
const r = cn(e, t);
|
|
12
|
+
return n === "focus" || n === "ring" ? { ...r, width: Math.max(r.width ?? 0, ln), halo: n === "ring" } : n === "dim" ? { ...r, opacity: Math.min(r.opacity, Qe) } : r;
|
|
13
|
+
}
|
|
14
|
+
const Qe = 0.45;
|
|
15
|
+
function cn(e, t) {
|
|
16
|
+
const n = t && ae[t] ? Ze(e, t) : void 0;
|
|
17
|
+
switch (t) {
|
|
18
|
+
case "added":
|
|
19
|
+
case "changed":
|
|
20
|
+
return { stroke: n, width: 2, opacity: 1, strike: !1 };
|
|
21
|
+
case "removed":
|
|
22
|
+
return {
|
|
23
|
+
stroke: n,
|
|
24
|
+
width: 2,
|
|
25
|
+
dash: "6 4",
|
|
26
|
+
opacity: 1,
|
|
27
|
+
strike: e.strikeRemoved,
|
|
28
|
+
inkFade: 0.8,
|
|
29
|
+
marker: !0
|
|
30
|
+
};
|
|
31
|
+
case "context":
|
|
32
|
+
return { ...Re, opacity: Qe };
|
|
33
|
+
default:
|
|
34
|
+
return Re;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const q = (e) => !!e.appearance.compare || Object.values(e.styles).some((t) => t.status) || e.graph.edges.some((t) => t.status);
|
|
38
|
+
function ye(e, t, n) {
|
|
39
|
+
const r = ae[t ?? "same"];
|
|
40
|
+
if (!r)
|
|
41
|
+
return n === "group" ? { fill: e.canvas, stroke: e.muted, ink: e.text } : e.node;
|
|
42
|
+
const o = t === "removed";
|
|
43
|
+
return {
|
|
44
|
+
fill: o && n === "group" && !e.dark ? e.canvas : O(e, r, e.dark ? 900 : n === "group" || o ? 50 : 100).fill,
|
|
45
|
+
stroke: Ze(e, t),
|
|
46
|
+
ink: O(e, r, e.dark ? 100 : 900).fill
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const se = (e, t, n) => U(e, t.status).stroke ?? (t.spot === "ring" ? Ye(e) : n || t.spot === "dim" ? e.muted : e.connection);
|
|
50
|
+
function Je(e, t) {
|
|
51
|
+
const n = e.appearance.states?.find((f) => f.id === t);
|
|
52
|
+
if (!n) return e;
|
|
53
|
+
const r = /* @__PURE__ */ new Set();
|
|
54
|
+
for (const f of n.ids)
|
|
55
|
+
if (r.add(f), e.graph.groups.some((g) => g.id === f)) for (const g of Mt(e, f)) r.add(g);
|
|
56
|
+
const o = new Map(
|
|
57
|
+
[...e.graph.nodes, ...e.graph.groups].map((f) => [f.id, f.parentId])
|
|
58
|
+
), s = /* @__PURE__ */ new Set();
|
|
59
|
+
for (const f of r) for (let g = o.get(f); g; g = o.get(g)) s.add(g);
|
|
60
|
+
const a = n.rest === "dim" ? "dim" : void 0, l = n.rest === "dim" ? "focus" : "ring", i = (f) => r.has(f) ? l : s.has(f) ? void 0 : a, h = { ...e.styles };
|
|
61
|
+
for (const f of [...e.graph.nodes, ...e.graph.groups]) {
|
|
62
|
+
const g = i(f.id);
|
|
63
|
+
g && (h[f.id] = { ...N(e, f.id), spot: g });
|
|
64
|
+
}
|
|
65
|
+
const c = e.graph.edges.map((f) => {
|
|
66
|
+
const g = r.has(f.id) || r.has(f.from) && r.has(f.to) ? l : a;
|
|
67
|
+
return g ? { ...f, spot: g } : f;
|
|
68
|
+
});
|
|
69
|
+
return { ...e, styles: h, graph: { ...e.graph, edges: c } };
|
|
70
|
+
}
|
|
71
|
+
function et(e) {
|
|
72
|
+
const t = new Set([...e.graph.nodes, ...e.graph.groups].map((r) => r.id)), n = Object.entries(e.styles).filter(([r]) => t.has(r)).map(([, r]) => r.status);
|
|
73
|
+
return Object.keys(me).map((r) => ({
|
|
74
|
+
status: r,
|
|
75
|
+
count: n.filter((o) => o === r).length,
|
|
76
|
+
lines: e.graph.edges.filter((o) => o.status === r).length
|
|
77
|
+
})).filter((r) => r.count || r.lines);
|
|
78
|
+
}
|
|
79
|
+
const tt = (e) => q(e) ? [] : e.appearance.legend ?? [];
|
|
80
|
+
function nt(e) {
|
|
81
|
+
const t = { ...e.styles }, n = e.layout.sequence, r = n?.before?.grow ?? 0;
|
|
82
|
+
for (const a of e.graph.nodes)
|
|
83
|
+
a.wasShape && (t[a.id] = { ...t[a.id], shape: a.wasShape });
|
|
84
|
+
const o = { ...e.layout.edges }, s = { ...e.layout.nodes };
|
|
85
|
+
for (const [a, l] of Object.entries(n?.before?.rows ?? {}))
|
|
86
|
+
o[a] = { ...o[a], row: l };
|
|
87
|
+
if (r)
|
|
88
|
+
for (const a of e.graph.groups) s[a.id] = { ...s[a.id], h: s[a.id].h + r };
|
|
89
|
+
return {
|
|
90
|
+
...e,
|
|
91
|
+
styles: t,
|
|
92
|
+
layout: {
|
|
93
|
+
...e.layout,
|
|
94
|
+
edges: o,
|
|
95
|
+
nodes: s,
|
|
96
|
+
...n?.before ? {
|
|
97
|
+
sequence: {
|
|
98
|
+
...n,
|
|
99
|
+
phases: n.before.phases,
|
|
100
|
+
panel: { ...n.panel, h: n.panel.h + r }
|
|
101
|
+
}
|
|
102
|
+
} : {}
|
|
103
|
+
},
|
|
104
|
+
graph: {
|
|
105
|
+
nodes: e.graph.nodes.map((a) => ({
|
|
106
|
+
...a,
|
|
107
|
+
title: a.was ?? a.title,
|
|
108
|
+
...a.wasCount !== void 0 ? { count: a.wasCount === 1 ? void 0 : a.wasCount } : {},
|
|
109
|
+
...a.lifeline ? { lifeline: a.lifeline + r } : {}
|
|
110
|
+
})),
|
|
111
|
+
groups: e.graph.groups.map((a) => ({ ...a, title: a.was ?? a.title })),
|
|
112
|
+
edges: e.graph.edges.map((a) => ({ ...a, label: a.was ?? a.label }))
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function rt(e) {
|
|
117
|
+
const t = e.layout.sequence;
|
|
118
|
+
if (!t?.inner) return e;
|
|
119
|
+
const { inner: n, notes: r, phaseX: o, ...s } = t;
|
|
120
|
+
return { ...e, layout: { ...e.layout, sequence: { ...s, panel: n } } };
|
|
121
|
+
}
|
|
122
|
+
function Ie(e, t) {
|
|
123
|
+
const n = t === "before" ? "added" : "removed", r = (i) => e.styles[i]?.status !== n, o = rt(e), s = t === "before" ? nt(o) : o, a = s.graph.nodes.filter((i) => r(i.id)), l = new Set(a.map((i) => i.id));
|
|
124
|
+
return hn(
|
|
125
|
+
{
|
|
126
|
+
...s,
|
|
127
|
+
graph: {
|
|
128
|
+
nodes: a,
|
|
129
|
+
groups: s.graph.groups.filter((i) => r(i.id)),
|
|
130
|
+
edges: s.graph.edges.filter(
|
|
131
|
+
(i) => i.status !== n && l.has(i.from) && l.has(i.to)
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
new Set(
|
|
136
|
+
e.graph.groups.filter((i) => !r(i.id)).map((i) => i.id).concat(e.graph.nodes.filter((i) => !r(i.id)).map((i) => i.id))
|
|
137
|
+
),
|
|
138
|
+
e
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function hn(e, t, n) {
|
|
142
|
+
if (!t.size) return e;
|
|
143
|
+
const r = new Map(
|
|
144
|
+
[...n.graph.nodes, ...n.graph.groups].map((h) => [h.id, h.parentId])
|
|
145
|
+
), o = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const h of t) for (let c = r.get(h); c; c = r.get(c)) o.add(c);
|
|
147
|
+
const s = be(e.appearance), a = { ...e.layout.nodes }, l = (h) => {
|
|
148
|
+
let c = 0;
|
|
149
|
+
for (let f = r.get(h); f; f = r.get(f)) c++;
|
|
150
|
+
return c;
|
|
151
|
+
}, i = [...e.graph.nodes, ...e.graph.groups];
|
|
152
|
+
for (const h of e.graph.groups.filter((c) => o.has(c.id)).sort((c, f) => l(f.id) - l(c.id))) {
|
|
153
|
+
const c = a[h.id], f = i.filter(($) => $.parentId === h.id).map(($) => a[$.id]);
|
|
154
|
+
if (!c || !f.length) continue;
|
|
155
|
+
const g = Math.min(
|
|
156
|
+
c.x + c.w,
|
|
157
|
+
Math.max(...f.map(($) => $.x + $.w)) + Y
|
|
158
|
+
), u = Math.min(c.y + c.h, Math.max(...f.map(($) => $.y + $.h)) + Y), d = W(h.title, s.groupTitle) + kt, m = Math.max(c.x, Math.min(...f.map(($) => $.x)) - Y), w = Math.max(c.y, Math.min(...f.map(($) => $.y)) - s.groupHeader), T = Math.max(c.x, Math.min(m, g - d)), p = Math.max(c.y, Math.min(w, u - s.groupHeader - Y));
|
|
159
|
+
a[h.id] = {
|
|
160
|
+
...c,
|
|
161
|
+
x: T,
|
|
162
|
+
y: p,
|
|
163
|
+
w: Math.min(c.x + c.w, Math.max(g, T + d)) - T,
|
|
164
|
+
h: u - p
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return { ...e, layout: { ...e.layout, nodes: a } };
|
|
168
|
+
}
|
|
169
|
+
const dn = [6, 3];
|
|
170
|
+
function fn(e) {
|
|
171
|
+
if (typeof e == "string" || e < 1e3) return `×${e}`;
|
|
172
|
+
const t = e / 1e3;
|
|
173
|
+
return `×${t < 10 ? t.toFixed(1).replace(/\.0$/, "") : Math.round(t)}k`;
|
|
174
|
+
}
|
|
175
|
+
const un = 24, pn = 10, Le = 4, gn = 16;
|
|
176
|
+
function mn(e, t, n) {
|
|
177
|
+
const r = At(e).subtitle, o = t.filter((i) => i.mark).map((i) => W(i.mark, r)), s = o.length ? Math.ceil(Math.max(...o)) + 10 : 0;
|
|
178
|
+
let a = pn;
|
|
179
|
+
const l = t.map((i) => {
|
|
180
|
+
const h = Et(i.text, Math.max(80, n - s), r), c = { note: i, lines: h, y: a };
|
|
181
|
+
return a += h.length * r.lineHeight + Le, c;
|
|
182
|
+
});
|
|
183
|
+
return { type: r, gutter: s, items: l, h: l.length ? a - Le + gn : 0 };
|
|
184
|
+
}
|
|
185
|
+
function $n(e, t, n) {
|
|
186
|
+
const { type: r, gutter: o } = e;
|
|
187
|
+
return e.items.flatMap(
|
|
188
|
+
(s, a) => s.lines.map((l, i) => ({
|
|
189
|
+
entry: a,
|
|
190
|
+
runs: l,
|
|
191
|
+
x: t + o,
|
|
192
|
+
y: n + s.y + i * r.lineHeight
|
|
193
|
+
}))
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function at(e, t, n, r, o = (s) => s) {
|
|
197
|
+
if (!t.items.length) return "";
|
|
198
|
+
const { type: s } = t, a = `font-family="${s.family.replace(/"/g, """)}" font-size="${s.size}" font-weight="${s.weight}"`, l = O(e, "primary", 700).fill, i = (f) => f + s.lineHeight / 2, h = t.items.filter((f) => f.note.mark).map(
|
|
199
|
+
(f) => `<text x="${n}" y="${i(r + f.y)}" dominant-baseline="central" ${a} fill="${e.muted}">${yn(f.note.mark)}</text>`
|
|
200
|
+
), c = $n(t, n, r).map(
|
|
201
|
+
(f) => `<text x="${f.x}" y="${i(f.y)}" dominant-baseline="central" ${a} fill="${e.text}">${vt(f.runs, l, o)}</text>`
|
|
202
|
+
);
|
|
203
|
+
return `<g class="diagram-footnotes"><line x1="${n}" x2="${n + un}" y1="${r}" y2="${r}" stroke="${e.muted}" stroke-opacity="0.6"/>` + h.join("") + c.join("") + "</g>";
|
|
204
|
+
}
|
|
205
|
+
const yn = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), Oe = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), st = (e, t, n, r, o = $e.r) => `<circle cx="${e}" cy="${t}" r="${o}" fill="${n}" stroke="${r}" stroke-width="${o / 4.5}"/><path d="M${e - o / 2},${t} h${o}" stroke="${r}" stroke-width="${o / 4}" stroke-linecap="round"/>`, xn = 24, wn = (e, t) => 24 + W(t, e.annotation);
|
|
206
|
+
function bn(e, t = [], n = [], r = 1 / 0) {
|
|
207
|
+
const o = Math.round(e.annotation.lineHeight + 8), s = [
|
|
208
|
+
...t.map((c) => ({ legend: c, label: c.label })),
|
|
209
|
+
...n.map((c) => ({ status: c, label: sn(c) }))
|
|
210
|
+
];
|
|
211
|
+
let a = 0, l = 0, i = 0;
|
|
212
|
+
const h = s.map((c) => {
|
|
213
|
+
const f = wn(e, c.label);
|
|
214
|
+
a && a + f > r && (a = 0, l += o);
|
|
215
|
+
const g = { ...c, x: a, y: l };
|
|
216
|
+
return i = Math.max(i, a + f), a += f + xn, g;
|
|
217
|
+
});
|
|
218
|
+
return { w: i, h: h.length ? l + o + 12 : 0, row: o, items: h };
|
|
219
|
+
}
|
|
220
|
+
function it(e, t, n, r) {
|
|
221
|
+
const { row: o } = t, { family: s, size: a, weight: l } = e.annotation;
|
|
222
|
+
return t.items.map((i) => {
|
|
223
|
+
const h = n + i.x, c = r + 12 + i.y, f = c + o / 2;
|
|
224
|
+
let g;
|
|
225
|
+
if (i.legend?.line)
|
|
226
|
+
g = `<line x1="${h}" y1="${f}" x2="${h + 16}" y2="${f}" stroke="${e.connection}" stroke-width="1.4"${i.legend.line === "dashed" ? ' stroke-dasharray="5 5"' : ""}/>`;
|
|
227
|
+
else if (i.legend) {
|
|
228
|
+
const u = O(e, i.legend.family, i.legend.shade ?? qe, "node");
|
|
229
|
+
g = De(h, c, o, `fill="${u.fill}" stroke="${u.stroke}"`);
|
|
230
|
+
} else {
|
|
231
|
+
const u = i.status.status, d = U(e, u), m = ye(e, u, "node");
|
|
232
|
+
g = De(
|
|
233
|
+
h,
|
|
234
|
+
c,
|
|
235
|
+
o,
|
|
236
|
+
`fill="${m.fill}" stroke="${m.stroke}" stroke-width="${d.width ?? 1}"${d.dash ? ' stroke-dasharray="3 2"' : ""} opacity="${d.opacity}"`
|
|
237
|
+
) + (d.marker ? st(h + 16, c + (o - 12) / 2, m.stroke, e.canvas, 4) : "");
|
|
238
|
+
}
|
|
239
|
+
return g + `<text x="${h + 24}" y="${f}" dominant-baseline="central" font-family="${Oe(s)}" font-size="${a}" font-weight="${l}" fill="${e.text}">${Oe(i.label)}</text>`;
|
|
240
|
+
}).join("");
|
|
241
|
+
}
|
|
242
|
+
const De = (e, t, n, r) => `<rect x="${e}" y="${t + (n - 12) / 2}" width="16" height="12" rx="3" ${r}/>`, H = 40, Q = 8;
|
|
243
|
+
function ot(e, t, n, r, o, s = [], a = []) {
|
|
244
|
+
const l = s.filter((y) => !y.inFrame).map((y) => y.rect), i = l.length ? pe([o, pe(l, H)]) : o, h = s.filter((y) => y.inFrame), c = _t(e, (t?.width ?? i.w) - H * 2), f = St(e, t, c), g = h.reduce((y, k) => y + k.rect.h + Q, f.h ? 0 : -Q), u = h.length ? { w: Math.max(f.w, ...h.map((y) => y.rect.w)), h: (f.h || 20) + g } : f, d = Math.max(i.w, u.w + H * 2, t?.width ?? 0) - H * 2, m = bn(e, n, r, d), w = mn(e, a, d), T = w.h && !m.h ? w.h + H / 2 : w.h, p = Math.max(i.w, u.w + H * 2, m.w + H * 2), $ = i.y - u.h, b = i.x + H;
|
|
245
|
+
let v = $ + 28 + (f.h ? f.h - 20 + Q : 0);
|
|
246
|
+
const x = s.map((y) => {
|
|
247
|
+
if (!y.inFrame) return y;
|
|
248
|
+
const k = { ...y.rect, x: b, y: v };
|
|
249
|
+
return v += y.rect.h + Q, { ...y, rect: k };
|
|
250
|
+
});
|
|
251
|
+
return {
|
|
252
|
+
x: i.x,
|
|
253
|
+
y: $,
|
|
254
|
+
w: Math.max(p, t?.width ?? 0),
|
|
255
|
+
h: i.h + u.h + T + m.h,
|
|
256
|
+
/** Width without the heading's `width`, which a drag never narrows past. */
|
|
257
|
+
natural: p,
|
|
258
|
+
head: u,
|
|
259
|
+
key: m,
|
|
260
|
+
heading: { x: b, y: $ + 28, wrap: c },
|
|
261
|
+
legend: { x: b, y: i.y + i.h - 12 + w.h },
|
|
262
|
+
/** The footnote block's top-left corner and layout. */
|
|
263
|
+
foot: { ...w, x: b, y: i.y + i.h - 12 },
|
|
264
|
+
/** Every note, placed. */
|
|
265
|
+
notes: x
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const Tn = 1, Mn = 3;
|
|
269
|
+
function ke(e, t, n) {
|
|
270
|
+
const r = N(e, n), o = Ve(e, n), s = r.color;
|
|
271
|
+
if (!s || s === "auto") return r.shade;
|
|
272
|
+
const a = r.shade ?? (o ? Rt(t.theme) : qe), l = Te(e, n)?.parentId, i = l ? ze(e, l) : void 0;
|
|
273
|
+
if (!i || N(e, i.id).color !== s) return a;
|
|
274
|
+
const h = ke(e, t, i.id);
|
|
275
|
+
if (h === void 0) return a;
|
|
276
|
+
const c = o ? Tn : Mn, f = It[t.theme]?.dark ? -1 : 1, g = te.indexOf(a), u = te.indexOf(h);
|
|
277
|
+
return (g - u) * f >= c || (u - g) * f > 2 ? a : vn(t, s, te[kn(u + c * f)]);
|
|
278
|
+
}
|
|
279
|
+
function z(e, t, n, r) {
|
|
280
|
+
if (q(e)) return ye(t, N(e, n).status, r);
|
|
281
|
+
if (N(e, n).spot === "dim") return ye(t, void 0, r);
|
|
282
|
+
const o = O(t, N(e, n).color, ke(e, t, n), r);
|
|
283
|
+
if (r === "node" && e.layout.sequence) {
|
|
284
|
+
const s = Te(e, n)?.parentId;
|
|
285
|
+
return {
|
|
286
|
+
fill: s && ze(e, s)?.frame !== "none" ? z(e, t, s, "group").fill : t.canvas,
|
|
287
|
+
stroke: lt(e, t, n) ?? o.stroke,
|
|
288
|
+
ink: t.text
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return o;
|
|
292
|
+
}
|
|
293
|
+
function lt(e, t, n) {
|
|
294
|
+
if (!e.layout.sequence || !Te(e, n) || Ve(e, n) || q(e) || N(e, n).spot === "dim") return;
|
|
295
|
+
const r = ke(e, t, n), o = N(e, n).color;
|
|
296
|
+
if (!((!o || o === "auto") && r === void 0))
|
|
297
|
+
return O(t, o, r, "node").fill;
|
|
298
|
+
}
|
|
299
|
+
const kn = (e) => Math.max(0, Math.min(te.length - 1, e));
|
|
300
|
+
function vn(e, t, n) {
|
|
301
|
+
const r = Lt(e, t);
|
|
302
|
+
return !r.length || r.includes(n) ? n : r.reduce((o, s) => Math.abs(s - n) < Math.abs(o - n) ? s : o);
|
|
303
|
+
}
|
|
304
|
+
const J = 4;
|
|
305
|
+
function An(e, t, n, r, o = 0) {
|
|
306
|
+
const s = [];
|
|
307
|
+
for (const a of t.nodes) {
|
|
308
|
+
const l = n.get(a.id);
|
|
309
|
+
l && s.push(Ot(e, a.id, a.title, l)), l && a.lifeline && s.push({ x: l.x + l.w / 2, y: l.y + l.h, w: 1, h: a.lifeline });
|
|
310
|
+
}
|
|
311
|
+
for (const a of t.groups) {
|
|
312
|
+
const l = n.get(a.id);
|
|
313
|
+
l && s.push(l);
|
|
314
|
+
}
|
|
315
|
+
e.layout.sequence && s.push(e.layout.sequence.panel);
|
|
316
|
+
for (const a of r) {
|
|
317
|
+
for (const i of a.points)
|
|
318
|
+
s.push({ x: i.x - J, y: i.y - J, w: J * 2, h: J * 2 });
|
|
319
|
+
const l = a.label;
|
|
320
|
+
l && s.push({ x: l.x - l.w / 2, y: l.y - l.h / 2, w: l.w, h: l.h });
|
|
321
|
+
}
|
|
322
|
+
return pe(s, o);
|
|
323
|
+
}
|
|
324
|
+
const fe = (e, t) => e.x >= t.x && e.x <= t.x + t.w && e.y >= t.y && e.y <= t.y + t.h, ct = (e) => e % 2 ? 0.03 : 0.12;
|
|
325
|
+
function ht(e) {
|
|
326
|
+
if (!e.layout.sequence) return !1;
|
|
327
|
+
const t = new Set(e.graph.groups.filter((n) => n.frame !== "none").map((n) => n.id));
|
|
328
|
+
return e.graph.nodes.some((n) => n.lifeline && !(n.parentId && t.has(n.parentId)));
|
|
329
|
+
}
|
|
330
|
+
function En(e, t) {
|
|
331
|
+
const { vg: n, rects: r } = Me(e), o = e.layout.sequence, s = !!o && ht(e);
|
|
332
|
+
return (a) => {
|
|
333
|
+
let l = t.canvas;
|
|
334
|
+
o && s && fe(a, o.panel) && (l = O(t, "slate", 50, "group").fill);
|
|
335
|
+
for (const h of n.groups) {
|
|
336
|
+
const c = r.get(h.id);
|
|
337
|
+
if (!c || h.frame === "none") continue;
|
|
338
|
+
(h.frame === "soft" && h.hull?.length ? h.hull : [{ x: 0, y: 0, w: c.w, h: c.h }]).some((g) => fe(a, { x: c.x + g.x, y: c.y + g.y, w: g.w, h: g.h })) && (l = z(e, t, h.id, "group").fill);
|
|
339
|
+
}
|
|
340
|
+
const i = o ? o.phases.findIndex((h) => a.y >= h.y && a.y <= h.y + h.h) : -1;
|
|
341
|
+
return i < 0 || !fe(a, o.panel) ? { fill: l } : {
|
|
342
|
+
fill: l,
|
|
343
|
+
tint: { fill: O(t, "slate", 100, "group").stroke, opacity: ct(i) }
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function _n(e, t) {
|
|
348
|
+
const n = /* @__PURE__ */ new Map();
|
|
349
|
+
for (const r of t.matchAll(/M([-\d.]+) ([-\d.]+)L([-\d.]+) ([-\d.]+)/g)) {
|
|
350
|
+
const [o, s, a, l] = r.slice(1).map(Number), i = e({ x: (o + a) / 2, y: (s + l) / 2 }), h = JSON.stringify(i), c = n.get(h);
|
|
351
|
+
c ? c.d += r[0] : n.set(h, { surface: i, d: r[0] });
|
|
352
|
+
}
|
|
353
|
+
return [...n.values()];
|
|
354
|
+
}
|
|
355
|
+
const E = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
356
|
+
class dt extends Error {
|
|
357
|
+
}
|
|
358
|
+
const Sn = new TextEncoder();
|
|
359
|
+
class ft extends Array {
|
|
360
|
+
constructor(t = 1 / 0) {
|
|
361
|
+
super(), this.limit = t;
|
|
362
|
+
}
|
|
363
|
+
bytes = 0;
|
|
364
|
+
push(...t) {
|
|
365
|
+
for (const n of t) {
|
|
366
|
+
if (this.bytes += Sn.encode(n).length + (this.length ? 1 : 0), this.bytes > this.limit) throw new dt("SVG output exceeds maxOutputBytes.");
|
|
367
|
+
super.push(n);
|
|
368
|
+
}
|
|
369
|
+
return this.length;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function ue(e, t, n) {
|
|
373
|
+
if (!e) return t;
|
|
374
|
+
const r = Qt(e).kind === "url";
|
|
375
|
+
return [
|
|
376
|
+
`<a class="link" href="${E(n.href?.(e) ?? e)}"${n.linkTarget === "_self" ? ' target="_self"' : n.linkTarget === "_blank" || r ? ' target="_blank" rel="noopener noreferrer"' : ""}>`,
|
|
377
|
+
...t,
|
|
378
|
+
"</a>"
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
const Fe = (e, t, n, r) => `<path class="link-mark" transform="translate(${t + e.x},${n + e.y}) scale(${e.size / 10})" d="${Jt}" fill="none" stroke="${r}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>`, ie = (e) => e.textHref ?? ((t) => e.href?.(t) ?? t), Rn = "a.link{cursor:pointer}a.link:hover .shape{stroke-width:2.4px}a.link:hover .link-mark{stroke-width:2px}", ee = (e) => (e.strike ? ' text-decoration="line-through"' : "") + (e.inkFade ? ` fill-opacity="${e.inkFade}"` : ""), Ne = (e, t, n, r) => e.marker ? st(t.x + t.w - $e.inset, t.y + $e.inset, n, r) : "", X = (e) => e.opacity < 1 ? ` opacity="${e.opacity}"` : "", F = (e) => `font-family="${E(e.family)}" font-size="${e.size}" font-weight="${e.weight}"`;
|
|
382
|
+
function xe(e, t, n, r, o = "") {
|
|
383
|
+
if (e === "diamond")
|
|
384
|
+
return `<path d="M${t.x + t.w / 2},${t.y} L${t.x + t.w},${t.y + t.h / 2} L${t.x + t.w / 2},${t.y + t.h} L${t.x},${t.y + t.h / 2} Z" ${r}/>`;
|
|
385
|
+
if (e === "circle")
|
|
386
|
+
return `<ellipse cx="${t.x + t.w / 2}" cy="${t.y + t.h / 2}" rx="${t.w / 2}" ry="${t.h / 2}" ${r}/>`;
|
|
387
|
+
if (e === "text") return "";
|
|
388
|
+
if (e === "marker")
|
|
389
|
+
return `<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="2" fill="${o}"/>`;
|
|
390
|
+
const s = e === "pill" ? t.h / 2 : n;
|
|
391
|
+
return `<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="${s}" ${r}/>`;
|
|
392
|
+
}
|
|
393
|
+
const je = (e, t, n) => xe(
|
|
394
|
+
e === "text" ? "box" : e,
|
|
395
|
+
{ x: t.x - V, y: t.y - V, w: t.w + 2 * V, h: t.h + 2 * V },
|
|
396
|
+
n.radius + V,
|
|
397
|
+
`fill="none" stroke="${Ye(n)}" stroke-width="2"`
|
|
398
|
+
);
|
|
399
|
+
function In(e, t, n, r) {
|
|
400
|
+
const o = e.layout.containers[n]?.cellsChrome, s = z(e, t, n, "group").ink;
|
|
401
|
+
return o ? [
|
|
402
|
+
...(o.ruler?.ticks ?? []).map(
|
|
403
|
+
(a) => `<text x="${r.x + a.x}" y="${r.y + o.ruler.y + o.ruler.h / 2}" text-anchor="middle" dominant-baseline="central" ${F(t.annotation)} fill="${s}">${E(a.label)}</text>`
|
|
404
|
+
),
|
|
405
|
+
...Object.entries(o.pieces ?? {}).flatMap(([a, l]) => {
|
|
406
|
+
const i = z(e, t, a, "node"), h = e.graph.nodes.find((c) => c.id === a)?.title ?? "";
|
|
407
|
+
return l.map(
|
|
408
|
+
(c) => `<rect x="${r.x + c.x}" y="${r.y + c.y}" width="${c.w}" height="${c.h}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1.2"/><text x="${r.x + c.x + c.w / 2}" y="${r.y + c.y + c.h / 2}" text-anchor="middle" dominant-baseline="central" ${F(t.annotation)} fill="${i.ink}" opacity="0.75">${E(ne(`… ${h}`, Math.max(0, c.w - 8), t.annotation))}</text>`
|
|
409
|
+
);
|
|
410
|
+
})
|
|
411
|
+
] : [];
|
|
412
|
+
}
|
|
413
|
+
function ce(e) {
|
|
414
|
+
const { vg: t, rects: n } = Me(e);
|
|
415
|
+
return Dt(e, t, n, { previous: [] }).routes;
|
|
416
|
+
}
|
|
417
|
+
function Ln(e, t) {
|
|
418
|
+
const n = new Set(e.graph.nodes.filter((a) => a.wasShape).map((a) => a.id)), r = new Set(e.graph.edges.filter((a) => a.was !== void 0).map((a) => a.id)), o = !!e.layout.sequence;
|
|
419
|
+
if (!o && !n.size && !r.size) return t;
|
|
420
|
+
const s = ce(nt(e));
|
|
421
|
+
return t.map((a) => {
|
|
422
|
+
const l = e.graph.edges.find((i) => i.id === a.id);
|
|
423
|
+
return o || n.has(l.from) || n.has(l.to) || r.has(l.id) ? s.find((i) => i.id === a.id) : a;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function ut(e, t, n, r, o) {
|
|
427
|
+
const { vg: s, rects: a } = Me(e), l = new Set(e.graph.edges.map((u) => u.id)), i = o ? o.filter((u) => l.has(u.id)) : ce(e), h = new ft(r.maxOutputBytes), c = q(e), f = Dn(e, t);
|
|
428
|
+
h.push(...f.panel);
|
|
429
|
+
for (const u of s.groups) {
|
|
430
|
+
const d = a.get(u.id), m = z(e, t, u.id, "group"), w = U(t, N(e, u.id).status, N(e, u.id).spot), T = Ft(e, u.id), p = T ? T / 2 : t.groupHeader / 2 - 7, $ = T ? 12 : 33, b = T ? [ne(u.title, Math.max(40, d.w - $ - 12), t.groupTitle)] : Nt(u.title, d.w, t, u.titleLines);
|
|
431
|
+
if (u.frame !== "none") {
|
|
432
|
+
if (u.frame === "soft") {
|
|
433
|
+
const v = u.hull?.length ? u.hull : [{ x: 0, y: 0, w: d.w, h: d.h }];
|
|
434
|
+
h.push(
|
|
435
|
+
...ue(
|
|
436
|
+
u.href,
|
|
437
|
+
[
|
|
438
|
+
`<g data-id="${E(u.id)}"${X(w)}>`,
|
|
439
|
+
...v.map(
|
|
440
|
+
(x) => `<rect x="${d.x + x.x}" y="${d.y + x.y}" width="${x.w}" height="${x.h}" rx="${jt}" fill="${m.fill}"/>`
|
|
441
|
+
),
|
|
442
|
+
`<text x="${d.x + v[0].x + Ee.x}" y="${d.y + v[0].y + Ee.y}" dominant-baseline="central" ${F(t.annotation)} fill="${m.ink}"${ee(w)}>${E(ne(u.title, Math.max(40, v[0].w - 2 * Pt), t.annotation))}</text>`,
|
|
443
|
+
"</g>"
|
|
444
|
+
],
|
|
445
|
+
r
|
|
446
|
+
)
|
|
447
|
+
);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
h.push(
|
|
451
|
+
...ue(
|
|
452
|
+
u.href,
|
|
453
|
+
[
|
|
454
|
+
`<g data-id="${E(u.id)}"${X(w)}>`,
|
|
455
|
+
w.halo ? je("box", d, { ...t, radius: Math.min(10, t.radius + 4) }) : "",
|
|
456
|
+
`<rect class="shape" x="${d.x}" y="${d.y}" width="${d.w}" height="${d.h}" rx="${T ? Math.min(4, t.radius) : Math.min(10, t.radius + 4)}" fill="${m.fill}" stroke="${m.stroke}" stroke-width="${w.width ?? 1}" stroke-opacity="${w.stroke ? 1 : 0.65}"${w.dash ? ` stroke-dasharray="${w.dash}"` : ""}/>`,
|
|
457
|
+
T ? "" : `<svg x="${d.x + 12}" y="${d.y + p - 6.5}" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="${m.ink}" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">${an.group}</svg>`,
|
|
458
|
+
...In(e, t, u.id, d),
|
|
459
|
+
...b.map(
|
|
460
|
+
(v, x) => `<text x="${d.x + $}" y="${d.y + p + x * t.groupTitle.lineHeight}" dominant-baseline="central" ${F(t.groupTitle)} fill="${m.ink}"${ee(w)}>${E(v)}</text>`
|
|
461
|
+
),
|
|
462
|
+
u.href ? Fe(
|
|
463
|
+
Ht(
|
|
464
|
+
b[b.length - 1],
|
|
465
|
+
t.groupTitle,
|
|
466
|
+
p + (b.length - 1) * t.groupTitle.lineHeight
|
|
467
|
+
),
|
|
468
|
+
d.x,
|
|
469
|
+
d.y,
|
|
470
|
+
m.ink
|
|
471
|
+
) : "",
|
|
472
|
+
Ne(w, d, m.stroke, t.canvas),
|
|
473
|
+
"</g>"
|
|
474
|
+
],
|
|
475
|
+
r
|
|
476
|
+
)
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
h.push(...f.phases);
|
|
481
|
+
for (const u of s.nodes) {
|
|
482
|
+
const d = a.get(u.id);
|
|
483
|
+
if (!d || !u.lifeline) continue;
|
|
484
|
+
const m = d.x + d.w / 2;
|
|
485
|
+
h.push(
|
|
486
|
+
`<line x1="${m}" y1="${d.y + d.h}" x2="${m}" y2="${d.y + d.h + u.lifeline}" stroke="${t.muted}" stroke-width="${_e.width}" stroke-dasharray="${_e.dash}"/>`
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
const g = En(e, t);
|
|
490
|
+
for (const u of i) {
|
|
491
|
+
const d = e.graph.edges.find((k) => k.id === u.id), m = U(t, d.status, d.spot), w = se(t, d, c), T = m.dash ?? (d.dashed ? "5 5" : ""), p = Ge(d), $ = Ke(d);
|
|
492
|
+
h.push(
|
|
493
|
+
`<g data-id="${E(d.id)}"${X(m)}>`,
|
|
494
|
+
..._n(g, u.halo).flatMap(
|
|
495
|
+
({ surface: k, d: L }) => Pe(
|
|
496
|
+
k,
|
|
497
|
+
(I) => `<path d="${L}" fill="none" stroke-width="${en}" ${I}/>`,
|
|
498
|
+
"stroke"
|
|
499
|
+
)
|
|
500
|
+
),
|
|
501
|
+
`<path d="${u.path}" fill="none" stroke="${w}" stroke-width="${m.width ? m.width - 0.5 : 1.4}" stroke-linecap="round" stroke-linejoin="round"${T ? ` stroke-dasharray="${T}"` : ""}${p === "none" ? "" : ` marker-end="url(#${n(p, w)})"`}${$ === "none" ? "" : ` marker-start="url(#${n($, w, !0)})"`}/>`
|
|
502
|
+
);
|
|
503
|
+
const b = u.label, v = e.layout.edges[u.id]?.row !== void 0, x = Bt(t, v), y = Ct(d.label, t, v);
|
|
504
|
+
b && h.push(
|
|
505
|
+
...Pe(
|
|
506
|
+
g(b),
|
|
507
|
+
(k) => `<rect x="${b.x - b.w / 2}" y="${b.y - b.h / 2}" width="${b.w}" height="${b.h}" rx="4" ${k}/>`
|
|
508
|
+
),
|
|
509
|
+
`<text x="${b.x}" y="${b.y - (y.length - 1) * x.lineHeight / 2}" text-anchor="middle" dominant-baseline="central" ${F(x)} fill="${w}"${ee(m)}>${y.length === 1 ? E(y[0]) : y.map((k, L) => `<tspan x="${b.x}" dy="${L ? x.lineHeight : 0}">${E(k)}</tspan>`).join("")}</text>`
|
|
510
|
+
), h.push("</g>");
|
|
511
|
+
}
|
|
512
|
+
for (const u of s.nodes) {
|
|
513
|
+
const d = a.get(u.id), m = N(e, u.id), w = z(e, t, u.id, "node"), T = U(t, m.status, m.spot), p = Ut(e, u.id) ? 0 : t.radius, $ = qt(e, u.id, u.title, d), b = d.y + $.y - ($.lines.length - 1) * $.lineHeight / 2, v = $.mode === "center" && m.shape !== "text" ? w.ink : t.text, x = lt(e, t, u.id), y = `class="shape" fill="${w.fill}" stroke="${w.stroke}" stroke-width="${T.width ?? (x ? 1.5 : 1.2)}"${T.dash ? ` stroke-dasharray="${T.dash}"` : ""}`, k = u.count ? fn(u.count) : "", L = W(k, t.annotation) + 12, I = t.annotation.lineHeight + 4, S = u.href ? zt(m.shape, d.w, d.h, k ? L : 0) : void 0;
|
|
514
|
+
h.push(
|
|
515
|
+
...ue(
|
|
516
|
+
u.href,
|
|
517
|
+
[
|
|
518
|
+
`<g data-id="${E(u.id)}"${X(T)}>`,
|
|
519
|
+
...u.count && m.shape !== "text" ? dn.map(
|
|
520
|
+
(_) => xe(m.shape, { ...d, x: d.x + _, y: d.y + _ }, p, y)
|
|
521
|
+
) : [],
|
|
522
|
+
T.halo ? je(m.shape, d, t) : "",
|
|
523
|
+
Vt(e, u.id) ? `<path d="${Xt(d)}" ${y}/>` : xe(m.shape, d, p, y, t.text),
|
|
524
|
+
x && m.shape === "box" ? `<path d="${Fn(d, p)}" fill="${x}"/>` : "",
|
|
525
|
+
`<text x="${d.x + $.x}" y="${b}" text-anchor="middle" dominant-baseline="central" ${F(t.title)} fill="${v}"${ee(T)}>` + $.lines.map(
|
|
526
|
+
(_, R) => `<tspan x="${d.x + $.x}" dy="${R ? $.lineHeight : 0}">${E(_)}</tspan>`
|
|
527
|
+
).join("") + "</text>",
|
|
528
|
+
k ? `<rect x="${d.x + d.w - L + 6}" y="${d.y - I / 2}" width="${L}" height="${I}" rx="${I / 2}" fill="${w.stroke}"/><text x="${d.x + d.w - L / 2 + 6}" y="${d.y}" text-anchor="middle" dominant-baseline="central" ${F(t.annotation)} fill="${t.canvas}">${E(k)}</text>` : "",
|
|
529
|
+
S ? Fe(S, d.x, d.y, S.inside ? w.ink : t.muted) : "",
|
|
530
|
+
k ? "" : Ne(T, d, w.stroke, t.canvas),
|
|
531
|
+
"</g>"
|
|
532
|
+
],
|
|
533
|
+
r
|
|
534
|
+
)
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
for (const u of i) {
|
|
538
|
+
if (!u.cross) continue;
|
|
539
|
+
const d = e.graph.edges.find(($) => $.id === u.id), m = U(t, d.status), w = se(t, d, c), [T, p] = u.cross;
|
|
540
|
+
h.push(
|
|
541
|
+
`<g${X(m)}>`,
|
|
542
|
+
`<line x1="${T.x}" y1="${T.y}" x2="${p.x}" y2="${p.y}" stroke="${w}" stroke-width="${m.width ? m.width - 0.5 : 1.4}"${m.dash || d.dashed ? ` stroke-dasharray="${m.dash ?? "5 5"}"` : ""}/>`,
|
|
543
|
+
`<circle cx="${p.x}" cy="${p.y}" r="3.5" fill="${w}"/>`,
|
|
544
|
+
"</g>"
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
markup: h.join(`
|
|
549
|
+
`),
|
|
550
|
+
bounds: An(e, s, a, i, 40),
|
|
551
|
+
rects: a,
|
|
552
|
+
routes: i
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
const we = 24, G = 0;
|
|
556
|
+
function pt(e, t, n = "") {
|
|
557
|
+
const r = [
|
|
558
|
+
.../* @__PURE__ */ new Set([
|
|
559
|
+
e.connection,
|
|
560
|
+
...t.flatMap((l) => l.graph.edges.map((i) => se(e, i, q(l))))
|
|
561
|
+
])
|
|
562
|
+
], o = (l, i, h = !1) => {
|
|
563
|
+
const c = r.indexOf(i);
|
|
564
|
+
return `${n}${l}${c ? `-${c}` : ""}${h ? "-tail" : ""}`;
|
|
565
|
+
}, s = /* @__PURE__ */ new Map(), a = (l, i, h = !1) => {
|
|
566
|
+
if (l === "none") return;
|
|
567
|
+
const c = Kt(l, h), f = o(l, i, h);
|
|
568
|
+
s.set(
|
|
569
|
+
f,
|
|
570
|
+
`<marker id="${f}" markerWidth="${c.markerWidth}" markerHeight="${c.markerHeight}" refX="${c.refX}" refY="${c.refY}" orient="${c.orient}" markerUnits="userSpaceOnUse"><path d="${Wt[l].d}" fill="${Yt(l, i, e.canvas)}" stroke="${i}" stroke-width="${Zt}" stroke-linecap="round" stroke-linejoin="round"/></marker>`
|
|
571
|
+
);
|
|
572
|
+
};
|
|
573
|
+
for (const l of r) a("arrow", l);
|
|
574
|
+
for (const l of t)
|
|
575
|
+
for (const i of l.graph.edges) {
|
|
576
|
+
const h = se(e, i, q(l));
|
|
577
|
+
a(Ge(i), h), a(Ke(i), h, !0);
|
|
578
|
+
}
|
|
579
|
+
return { defs: [...s.values()].join(""), marker: o };
|
|
580
|
+
}
|
|
581
|
+
function gt(e, t, n, { x: r, y: o, w: s, h: a, heading: l }, i) {
|
|
582
|
+
const h = i.idPrefix ?? "draft", c = Rn.replace(/a\.link/g, `#${h}-svg a.link`), f = new ft(i.maxOutputBytes);
|
|
583
|
+
return f.push(
|
|
584
|
+
`<svg xmlns="http://www.w3.org/2000/svg" id="${h}-svg" role="img" aria-labelledby="${h}-title${i.description ? ` ${h}-description` : ""}" viewBox="${r} ${o} ${s} ${a}" width="${s}" height="${a}" data-theme="${t.theme}">`,
|
|
585
|
+
`<title id="${h}-title">${E(i.title ?? e.title)}</title>`,
|
|
586
|
+
i.description ? `<desc id="${h}-description">${E(i.description)}</desc>` : "",
|
|
587
|
+
i.metadata ?? "",
|
|
588
|
+
`<defs><style${i.styleNonce ? ` nonce="${E(i.styleNonce)}"` : ""}>${i.fontCss ?? ""}${e.graph.nodes.some((g) => g.href) || e.graph.groups.some((g) => g.href) ? c : ""}</style>` + n + "</defs>",
|
|
589
|
+
`<rect x="${r}" y="${o}" width="${s}" height="${a}" fill="${t.canvas}"/>`,
|
|
590
|
+
// The title and subtitle sit above the drawing, left-aligned with the legend under it.
|
|
591
|
+
Gt(t, e.appearance.heading, l.x, l.y, l.wrap)
|
|
592
|
+
), f;
|
|
593
|
+
}
|
|
594
|
+
function On(e, t, n) {
|
|
595
|
+
const r = e.appearance.states ?? [], o = r.map((x) => Je(rt(e), x.id)), { defs: s, marker: a } = pt(t, o, n.idPrefix ? `${n.idPrefix}-` : ""), l = ce(e), i = o.map((x) => ut(x, t, a, n, l)), h = i.map((x) => x.bounds).reduce(mt), c = Math.floor(h.x), f = Math.floor(h.y), g = Math.ceil(h.x + h.w) - c, u = Math.ceil(h.y + h.h) - f + we, d = et(e), m = tt(e), w = ge(e, t, /* @__PURE__ */ new Map(), []), T = e.appearance.compare?.aspect ?? 1.6, p = (x) => {
|
|
596
|
+
const y = Math.ceil(r.length / x), k = ot(
|
|
597
|
+
t,
|
|
598
|
+
e.appearance.heading,
|
|
599
|
+
m,
|
|
600
|
+
d,
|
|
601
|
+
{ x: c, y: f, w: x * g, h: y * u },
|
|
602
|
+
w,
|
|
603
|
+
e.appearance.footnotes
|
|
604
|
+
);
|
|
605
|
+
return { cols: x, frame: k, w: k.w, h: k.h };
|
|
606
|
+
}, { cols: $, frame: b } = r.map((x, y) => p(y + 1)).reduce(
|
|
607
|
+
(x, y) => Math.abs(Math.log(y.w / y.h / T)) < Math.abs(Math.log(x.w / x.h / T)) ? y : x
|
|
608
|
+
), v = gt(e, t, s, b, n);
|
|
609
|
+
return i.forEach((x, y) => {
|
|
610
|
+
const k = y % $, L = Math.floor(y / $), I = c + k * g, S = f + L * u;
|
|
611
|
+
v.push(
|
|
612
|
+
`<text x="${I + 40}" y="${S + 36}" dominant-baseline="central" ${F(t.groupTitle)} fill="${t.text}">${E(r[y].label)}</text>`
|
|
613
|
+
), k && v.push(
|
|
614
|
+
`<line x1="${I}" x2="${I}" y1="${S + 16}" y2="${S + u - 16}" stroke="${t.muted}" stroke-opacity="0.35"/>`
|
|
615
|
+
), L && !k && v.push(
|
|
616
|
+
`<line x1="${c + 40}" x2="${c + $ * g - 40}" y1="${S}" y2="${S}" stroke="${t.muted}" stroke-opacity="0.35"/>`
|
|
617
|
+
), v.push(
|
|
618
|
+
`<g data-state="${E(r[y].id)}" transform="translate(${k * g},${L * u + we})">`,
|
|
619
|
+
x.markup,
|
|
620
|
+
"</g>"
|
|
621
|
+
);
|
|
622
|
+
}), v.push(at(t, b.foot, b.foot.x, b.foot.y, ie(n))), v.push(it(t, b.key, b.legend.x, b.legend.y)), v.push(Xe(t, b.notes, ie(n))), v.push(`</svg>
|
|
623
|
+
`), v.join(`
|
|
624
|
+
`);
|
|
625
|
+
}
|
|
626
|
+
function Dn(e, t) {
|
|
627
|
+
const n = e.layout.sequence;
|
|
628
|
+
if (!n) return { panel: [], phases: [] };
|
|
629
|
+
const { panel: r } = n, o = O(t, "slate", 100, "group"), s = n.phaseX ?? r.x;
|
|
630
|
+
return {
|
|
631
|
+
panel: [
|
|
632
|
+
ht(e) && `<rect class="sequence-panel" x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="${Math.min(10, t.radius + 4)}" fill="${O(t, "slate", 50, "group").fill}" stroke="${o.stroke}" stroke-opacity="0.6"/>`
|
|
633
|
+
].filter(Boolean),
|
|
634
|
+
// Alternate phases are tinted, so neighbours read apart even without their divider.
|
|
635
|
+
phases: n.phases.flatMap((a, l) => [
|
|
636
|
+
`<rect class="sequence-phase" data-phase="${E(a.id)}" x="${r.x}" y="${a.y}" width="${r.w}" height="${a.h}" fill="${o.stroke}" fill-opacity="${ct(l)}"/>`,
|
|
637
|
+
`<line x1="${r.x}" x2="${r.x + r.w}" y1="${a.y}" y2="${a.y}" stroke="${o.stroke}" stroke-opacity="0.5"/>`,
|
|
638
|
+
`<text x="${s + He}" y="${a.y + He}" dominant-baseline="hanging" ${F(t.annotation)} fill="${t.muted}">${E(a.label)}</text>`
|
|
639
|
+
])
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
function Pe(e, t, n = "fill") {
|
|
643
|
+
const r = e.tint;
|
|
644
|
+
return [
|
|
645
|
+
t(`${n}="${e.fill}"`),
|
|
646
|
+
r ? t(`${n}="${r.fill}" ${n}-opacity="${r.opacity}"`) : ""
|
|
647
|
+
];
|
|
648
|
+
}
|
|
649
|
+
const He = 8;
|
|
650
|
+
function Fn(e, t) {
|
|
651
|
+
const n = Math.min(t, e.w / 2, 4), r = 4;
|
|
652
|
+
return `M${e.x} ${e.y + r}V${e.y + n}Q${e.x} ${e.y} ${e.x + n} ${e.y}H${e.x + e.w - n}Q${e.x + e.w} ${e.y} ${e.x + e.w} ${e.y + n}V${e.y + r}Z`;
|
|
653
|
+
}
|
|
654
|
+
function Nn(e, t = {}) {
|
|
655
|
+
const n = be(e.appearance), r = e.appearance.compare;
|
|
656
|
+
if (t.states) return On(e, n, t);
|
|
657
|
+
const { defs: o, marker: s } = pt(n, [e], t.idPrefix ? `${t.idPrefix}-` : ""), a = r ? ce(e) : void 0, l = a ? [Ln(e, a), a] : [], i = (r ? [Ie(e, "before"), Ie(e, "after")] : [e]).map(
|
|
658
|
+
(_, R) => ut(_, n, s, t, l[R])
|
|
659
|
+
), h = i.map((_) => _.bounds).reduce(mt), c = Math.floor(h.x), f = Math.floor(h.y), g = Math.ceil(h.x + h.w) - c, u = Math.ceil(h.y + h.h) - f, d = r ? we : 0, m = et(e), w = tt(e), T = r ? ge(e, n, /* @__PURE__ */ new Map(), []) : ge(e, n, i[0].rects, i[0].routes), p = (_) => {
|
|
660
|
+
const R = i.map(
|
|
661
|
+
({ bounds: D }) => _ ? { from: Math.floor(D.y), size: Math.ceil(D.y + D.h) - Math.floor(D.y) } : { from: Math.floor(D.x), size: Math.ceil(D.x + D.w) - Math.floor(D.x) }
|
|
662
|
+
), j = R.map(
|
|
663
|
+
(D, de) => R.slice(0, de).reduce((bt, Tt) => bt + Tt.size + G + (_ ? d : 0), 0)
|
|
664
|
+
), P = j.at(-1) + R.at(-1).size, he = _ ? g : P, Z = _ ? P + d : u + d, C = ot(
|
|
665
|
+
n,
|
|
666
|
+
e.appearance.heading,
|
|
667
|
+
w,
|
|
668
|
+
m,
|
|
669
|
+
{ x: c, y: f, w: he, h: Z },
|
|
670
|
+
T,
|
|
671
|
+
e.appearance.footnotes
|
|
672
|
+
);
|
|
673
|
+
return { stacked: _, spans: R, starts: j, areaH: Z, frame: C, w: C.w, h: C.h };
|
|
674
|
+
}, $ = r?.aspect ?? 1.6, b = (_) => Math.abs(Math.log(_.w / _.h / $)), v = r?.direction ? [p(r.direction === "down")] : [p(!0), p(!1)], { stacked: x, spans: y, starts: k, areaH: L, frame: I } = v.reduce((_, R) => b(R) < b(_) ? R : _), S = gt(e, n, o, I, t);
|
|
675
|
+
return i.forEach((_, R) => {
|
|
676
|
+
const j = x ? c : c + k[R], P = x ? f + k[R] : f, he = x ? 0 : j - y[R].from, Z = (x ? P - y[R].from : 0) + d;
|
|
677
|
+
if (r) {
|
|
678
|
+
const C = R ? r.after : r.before;
|
|
679
|
+
if (S.push(
|
|
680
|
+
`<text x="${j + 40}" y="${P + 36}" dominant-baseline="central" ${F(n.groupTitle)} fill="${n.text}">${E(C)}</text>`
|
|
681
|
+
), !R && r.undrawn) {
|
|
682
|
+
const D = j + 40 + W(C, n.groupTitle) + 12, de = (x ? g : y[0].size) - (D - j) - 40;
|
|
683
|
+
S.push(
|
|
684
|
+
`<text x="${D}" y="${P + 36}" dominant-baseline="central" ${F(n.annotation)} fill="${n.muted}">${E(ne(`Drawn as new: ${r.undrawn}`, de, n.annotation))}</text>`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
R && S.push(
|
|
688
|
+
x ? `<line x1="${c + 40}" x2="${c + g - 40}" y1="${P - G / 2}" y2="${P - G / 2}" stroke="${n.muted}" stroke-opacity="0.35"/>` : `<line x1="${j - G / 2}" x2="${j - G / 2}" y1="${f}" y2="${f + L}" stroke="${n.muted}" stroke-opacity="0.35"/>`
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
S.push(`<g transform="translate(${he},${Z})">`, _.markup, "</g>");
|
|
692
|
+
}), S.push(at(n, I.foot, I.foot.x, I.foot.y, ie(t))), S.push(it(n, I.key, I.legend.x, I.legend.y)), S.push(Xe(n, I.notes, ie(t))), S.push(`</svg>
|
|
693
|
+
`), S.join(`
|
|
694
|
+
`);
|
|
695
|
+
}
|
|
696
|
+
const mt = (e, t) => {
|
|
697
|
+
const n = Math.min(e.x, t.x), r = Math.min(e.y, t.y);
|
|
698
|
+
return { x: n, y: r, w: Math.max(e.x + e.w, t.x + t.w) - n, h: Math.max(e.y + e.h, t.y + t.h) - r };
|
|
699
|
+
};
|
|
700
|
+
function jn(e) {
|
|
701
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
702
|
+
throw new TypeError("Render options must be an object.");
|
|
703
|
+
if (e.target !== void 0 && !["image", "inline"].includes(e.target))
|
|
704
|
+
throw new TypeError("target must be image or inline.");
|
|
705
|
+
if (e.target === "inline") {
|
|
706
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(e.idPrefix ?? ""))
|
|
707
|
+
throw new TypeError(
|
|
708
|
+
"Inline output needs an idPrefix with 1–64 letters, digits, underscores or hyphens, starting with a letter."
|
|
709
|
+
);
|
|
710
|
+
} else if (e.idPrefix !== void 0 || e.fonts === "host")
|
|
711
|
+
throw new TypeError("idPrefix and host fonts require target: inline.");
|
|
712
|
+
if (e.fonts !== void 0 && !["host", "embed"].includes(e.fonts))
|
|
713
|
+
throw new TypeError("fonts must be embed or host.");
|
|
714
|
+
for (const n of ["title", "description", "styleNonce", "sourceId"])
|
|
715
|
+
if (e[n] !== void 0 && typeof e[n] != "string")
|
|
716
|
+
throw new TypeError(`${n} must be a string.`);
|
|
717
|
+
if (e.state !== void 0 && e.state !== null && typeof e.state != "string")
|
|
718
|
+
throw new TypeError("state must be a string or null.");
|
|
719
|
+
if (e.includeSource !== void 0 && typeof e.includeSource != "boolean")
|
|
720
|
+
throw new TypeError("includeSource must be a boolean.");
|
|
721
|
+
const t = e.links;
|
|
722
|
+
if (t !== void 0) {
|
|
723
|
+
if (!t || !["none", "safe"].includes(t.mode))
|
|
724
|
+
throw new TypeError("links.mode must be none or safe.");
|
|
725
|
+
if (t.mode === "safe") {
|
|
726
|
+
if (t.target !== void 0 && !["_self", "_blank"].includes(t.target))
|
|
727
|
+
throw new TypeError("links.target must be _self or _blank.");
|
|
728
|
+
if (t.resolve !== void 0 && typeof t.resolve != "function")
|
|
729
|
+
throw new TypeError("links.resolve must be a function.");
|
|
730
|
+
if (t.baseUrl !== void 0 && !ve(t.baseUrl))
|
|
731
|
+
throw new TypeError("links.baseUrl must be an absolute HTTP(S) URL.");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
function ve(e, t) {
|
|
736
|
+
if (typeof e != "string" || [...e].some((n) => n.charCodeAt(0) <= 32 || n.charCodeAt(0) === 127))
|
|
737
|
+
return null;
|
|
738
|
+
try {
|
|
739
|
+
const n = new URL(e, t);
|
|
740
|
+
return n.protocol === "https:" || n.protocol === "http:" ? n.href : null;
|
|
741
|
+
} catch {
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const Pn = (e) => (t) => e.links?.mode === "safe" ? ve(t, e.links.baseUrl) : null;
|
|
746
|
+
function Hn(e, t) {
|
|
747
|
+
const n = [];
|
|
748
|
+
for (const r of [...e.graph.nodes, ...e.graph.groups]) {
|
|
749
|
+
if (!r.href) continue;
|
|
750
|
+
const o = t.links, s = o?.mode === "safe" ? o.resolve ? o.resolve({ itemId: r.id, href: r.href }) : r.href : null, a = s === null ? null : ve(s, o?.mode === "safe" ? o.baseUrl : void 0);
|
|
751
|
+
a ? r.href = a : (delete r.href, o?.mode === "safe" && n.push({
|
|
752
|
+
severity: "warning",
|
|
753
|
+
code: "DRAFT_LINK_BLOCKED",
|
|
754
|
+
message: "The host link policy blocked this destination.",
|
|
755
|
+
itemIds: [r.id]
|
|
756
|
+
}));
|
|
757
|
+
}
|
|
758
|
+
return n;
|
|
759
|
+
}
|
|
760
|
+
const Bn = "0.3.0", Be = Bn, B = {
|
|
761
|
+
maxSourceChars: 3e5,
|
|
762
|
+
maxSourceBytes: 1e6,
|
|
763
|
+
maxObjects: 500,
|
|
764
|
+
maxEdges: 1200,
|
|
765
|
+
maxDepth: 12,
|
|
766
|
+
maxOutputBytes: 8e6
|
|
767
|
+
}, $t = new TextEncoder(), Ce = (e) => e === 9 || e === 10 || e === 13 || e >= 32 && e <= 55295 || e >= 57344 && e <= 65533 || e >= 65536 && e <= 1114111;
|
|
768
|
+
function K(e) {
|
|
769
|
+
for (let t = 0; t < e.length; t++) {
|
|
770
|
+
const n = e.charCodeAt(t);
|
|
771
|
+
if (n >= 55296 && n <= 56319) {
|
|
772
|
+
const r = e.charCodeAt(t + 1);
|
|
773
|
+
if (!(r >= 56320 && r <= 57343) || (t++, !Ce(65536 + (n - 55296 << 10) + (r - 56320)))) return !1;
|
|
774
|
+
} else {
|
|
775
|
+
if (n >= 56320 && n <= 57343) return !1;
|
|
776
|
+
if (!Ce(n)) return !1;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return !0;
|
|
780
|
+
}
|
|
781
|
+
function oe(e, t = /* @__PURE__ */ new Set()) {
|
|
782
|
+
return typeof e == "string" ? !K(e) : !e || typeof e != "object" || t.has(e) ? !1 : (t.add(e), Array.isArray(e) ? e.some((n) => oe(n, t)) : Object.values(e).some((n) => oe(n, t)));
|
|
783
|
+
}
|
|
784
|
+
function yt(e, t = !1) {
|
|
785
|
+
if (e !== void 0 && (!e || typeof e != "object" || Array.isArray(e)))
|
|
786
|
+
throw new TypeError("limits must be an object.");
|
|
787
|
+
const n = t ? Object.keys(B).filter((o) => o !== "maxOutputBytes") : Object.keys(B);
|
|
788
|
+
for (const o of Object.keys(e ?? {}))
|
|
789
|
+
if (!n.includes(o)) throw new RangeError(`Unknown limit ${o}.`);
|
|
790
|
+
const r = { ...B, ...e };
|
|
791
|
+
for (const o of n) {
|
|
792
|
+
const s = r[o];
|
|
793
|
+
if (!Number.isSafeInteger(s) || s <= 0 || s > B[o])
|
|
794
|
+
throw new RangeError(
|
|
795
|
+
`${o} must be a positive safe integer no greater than ${B[o]}.`
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
return r;
|
|
799
|
+
}
|
|
800
|
+
const M = (e, t, n, r, o, s, a = []) => ({
|
|
801
|
+
code: e,
|
|
802
|
+
severity: "error",
|
|
803
|
+
message: t,
|
|
804
|
+
...r ? { location: { ...n ? { sourceId: n } : {}, line: r, ...o ? { column: o } : {} } } : {},
|
|
805
|
+
itemIds: [...a],
|
|
806
|
+
...s ? { nativeCode: s } : {}
|
|
807
|
+
});
|
|
808
|
+
function A(e, t) {
|
|
809
|
+
return { ok: !1, reason: e, diagnostics: [t] };
|
|
810
|
+
}
|
|
811
|
+
function Ae(e, t) {
|
|
812
|
+
return e instanceof re && /Limit:/.test(e.message) ? M(
|
|
813
|
+
"DRAFT_LIMIT",
|
|
814
|
+
e.message.replace(/^Line \d+(?:, column \d+)?: /, ""),
|
|
815
|
+
t,
|
|
816
|
+
e.line || void 0,
|
|
817
|
+
e.column || void 0
|
|
818
|
+
) : e instanceof re ? M(
|
|
819
|
+
"DRAFT_PARSE",
|
|
820
|
+
e.message.replace(/^Line \d+(?:, column \d+)?: /, ""),
|
|
821
|
+
t,
|
|
822
|
+
e.line || void 0,
|
|
823
|
+
e.column || void 0
|
|
824
|
+
) : M("DRAFT_INTERNAL", "The diagram could not be compiled.", t);
|
|
825
|
+
}
|
|
826
|
+
function xt(e, t, n) {
|
|
827
|
+
const r = e.objects.length;
|
|
828
|
+
if (r > t.maxObjects)
|
|
829
|
+
return M(
|
|
830
|
+
"DRAFT_LIMIT",
|
|
831
|
+
`The diagram has ${r} objects; the limit is ${t.maxObjects}.`,
|
|
832
|
+
n
|
|
833
|
+
);
|
|
834
|
+
if (e.edges.length > t.maxEdges)
|
|
835
|
+
return M(
|
|
836
|
+
"DRAFT_LIMIT",
|
|
837
|
+
`The diagram has ${e.edges.length} edges; the limit is ${t.maxEdges}.`,
|
|
838
|
+
n
|
|
839
|
+
);
|
|
840
|
+
const o = e.byId;
|
|
841
|
+
for (const s of e.objects) {
|
|
842
|
+
let a = 1, l = s.parent;
|
|
843
|
+
for (; l !== "root"; )
|
|
844
|
+
a++, l = o.get(l)?.parent ?? "root";
|
|
845
|
+
if (a > t.maxDepth)
|
|
846
|
+
return M(
|
|
847
|
+
"DRAFT_LIMIT",
|
|
848
|
+
`The diagram has containment depth ${a}; the limit is ${t.maxDepth}.`,
|
|
849
|
+
n,
|
|
850
|
+
s.line
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function Cn(e, t, n) {
|
|
855
|
+
if (e.objects.length > t.maxObjects)
|
|
856
|
+
return M(
|
|
857
|
+
"DRAFT_LIMIT",
|
|
858
|
+
`The diagram has ${e.objects.length} objects; the limit is ${t.maxObjects}.`,
|
|
859
|
+
n
|
|
860
|
+
);
|
|
861
|
+
if (e.edges.length > t.maxEdges)
|
|
862
|
+
return M(
|
|
863
|
+
"DRAFT_LIMIT",
|
|
864
|
+
`The diagram has ${e.edges.length} edges; the limit is ${t.maxEdges}.`,
|
|
865
|
+
n
|
|
866
|
+
);
|
|
867
|
+
const r = new Map(e.objects.map((o) => [o.id, o]));
|
|
868
|
+
for (const o of e.objects) {
|
|
869
|
+
let s = 1, a = o.parent;
|
|
870
|
+
for (; a !== "root"; )
|
|
871
|
+
s++, a = r.get(a)?.parent ?? "root";
|
|
872
|
+
if (s > t.maxDepth)
|
|
873
|
+
return M(
|
|
874
|
+
"DRAFT_LIMIT",
|
|
875
|
+
`The diagram has containment depth ${s}; the limit is ${t.maxDepth}.`,
|
|
876
|
+
n,
|
|
877
|
+
o.line
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
function wt(e, t, n) {
|
|
882
|
+
if (!(t.maxObjects === B.maxObjects && t.maxEdges === B.maxEdges && t.maxDepth === B.maxDepth))
|
|
883
|
+
try {
|
|
884
|
+
return Cn(rn(e), t, n);
|
|
885
|
+
} catch (r) {
|
|
886
|
+
return Ae(r, n);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const le = (e) => e.code === "DRAFT_INTERNAL" ? "internal" : e.code === "DRAFT_LIMIT" ? "limit" : "input";
|
|
890
|
+
async function Un(e, t = {}) {
|
|
891
|
+
if (jn(t), typeof e != "string") throw new TypeError("source must be a string.");
|
|
892
|
+
const n = yt(t.limits), r = t.sourceId;
|
|
893
|
+
if (t.signal?.aborted)
|
|
894
|
+
return {
|
|
895
|
+
result: A("aborted", M("DRAFT_ABORTED", "Rendering was aborted.", r))
|
|
896
|
+
};
|
|
897
|
+
if (e.length > n.maxSourceChars || $t.encode(e).byteLength > n.maxSourceBytes)
|
|
898
|
+
return {
|
|
899
|
+
result: A(
|
|
900
|
+
"limit",
|
|
901
|
+
M("DRAFT_LIMIT", "The source exceeds the configured size limit.", r)
|
|
902
|
+
)
|
|
903
|
+
};
|
|
904
|
+
if (!K(e) || [t.title, t.description, t.styleNonce].some(
|
|
905
|
+
(p) => p !== void 0 && !K(p)
|
|
906
|
+
))
|
|
907
|
+
return {
|
|
908
|
+
result: A(
|
|
909
|
+
"input",
|
|
910
|
+
M(
|
|
911
|
+
"DRAFT_TEXT_INVALID",
|
|
912
|
+
"The source contains text that XML cannot represent.",
|
|
913
|
+
r
|
|
914
|
+
)
|
|
915
|
+
)
|
|
916
|
+
};
|
|
917
|
+
const o = wt(e, n, r);
|
|
918
|
+
if (o) return { result: A(le(o), o) };
|
|
919
|
+
let s;
|
|
920
|
+
try {
|
|
921
|
+
s = await We(e);
|
|
922
|
+
} catch (p) {
|
|
923
|
+
const $ = Ae(p, r);
|
|
924
|
+
return {
|
|
925
|
+
result: A(
|
|
926
|
+
p instanceof re && /Limit:/.test(p.message) ? "limit" : le($),
|
|
927
|
+
$
|
|
928
|
+
)
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
if (t.signal?.aborted)
|
|
932
|
+
return {
|
|
933
|
+
result: A("aborted", M("DRAFT_ABORTED", "Rendering was aborted.", r))
|
|
934
|
+
};
|
|
935
|
+
const a = xt(s, n, r);
|
|
936
|
+
if (a) return { result: A("limit", a), scene: s };
|
|
937
|
+
if (s.diagnostics.some((p) => p.level === "error")) {
|
|
938
|
+
const p = s.diagnostics.find(($) => $.level === "error");
|
|
939
|
+
return {
|
|
940
|
+
result: A(
|
|
941
|
+
"input",
|
|
942
|
+
M("DRAFT_COMPILE", p.message, r, p.line, void 0, p.code, p.ids)
|
|
943
|
+
),
|
|
944
|
+
scene: s
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
if (oe(s))
|
|
948
|
+
return {
|
|
949
|
+
result: A(
|
|
950
|
+
"input",
|
|
951
|
+
M(
|
|
952
|
+
"DRAFT_TEXT_INVALID",
|
|
953
|
+
"A decoded diagram label contains text that XML cannot represent.",
|
|
954
|
+
r
|
|
955
|
+
)
|
|
956
|
+
),
|
|
957
|
+
scene: s
|
|
958
|
+
};
|
|
959
|
+
if (t.state != null && !(s.model.appearance.states ?? []).some((p) => p.id === t.state))
|
|
960
|
+
return {
|
|
961
|
+
result: A(
|
|
962
|
+
"input",
|
|
963
|
+
M("DRAFT_STATE_UNKNOWN", `Unknown state ${t.state}.`, r)
|
|
964
|
+
),
|
|
965
|
+
scene: s
|
|
966
|
+
};
|
|
967
|
+
if (t.signal?.aborted)
|
|
968
|
+
return {
|
|
969
|
+
result: A("aborted", M("DRAFT_ABORTED", "Rendering was aborted.", r))
|
|
970
|
+
};
|
|
971
|
+
let l = tn(s);
|
|
972
|
+
t.state && (l = Je(l, t.state));
|
|
973
|
+
const i = Hn(l, t), h = t.target === "inline" ? t.idPrefix : "draft", c = (p) => p.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), f = t.includeSource ? `<metadata id="${h}-source" data-draftably-source="1" data-draftably-version="${Be}">${c(e)}</metadata>` : void 0;
|
|
974
|
+
let g = "";
|
|
975
|
+
try {
|
|
976
|
+
t.fonts !== "host" && (g = (await import("./font-data-DLXJur0j.js")).fontFaceCss(be(l.appearance)));
|
|
977
|
+
} catch {
|
|
978
|
+
return {
|
|
979
|
+
result: A(
|
|
980
|
+
"environment",
|
|
981
|
+
M("DRAFT_ENVIRONMENT", "Bundled fonts could not be loaded.", r)
|
|
982
|
+
)
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
if (t.signal?.aborted)
|
|
986
|
+
return {
|
|
987
|
+
result: A("aborted", M("DRAFT_ABORTED", "Rendering was aborted.", r))
|
|
988
|
+
};
|
|
989
|
+
let u;
|
|
990
|
+
try {
|
|
991
|
+
u = Nn(l, {
|
|
992
|
+
idPrefix: h,
|
|
993
|
+
fontCss: g,
|
|
994
|
+
title: t.title,
|
|
995
|
+
description: t.description,
|
|
996
|
+
styleNonce: t.styleNonce,
|
|
997
|
+
linkTarget: t.links?.mode === "safe" ? t.links.target ?? "_self" : "_self",
|
|
998
|
+
textHref: Pn(t),
|
|
999
|
+
metadata: f,
|
|
1000
|
+
maxOutputBytes: n.maxOutputBytes
|
|
1001
|
+
});
|
|
1002
|
+
} catch (p) {
|
|
1003
|
+
return {
|
|
1004
|
+
result: p instanceof dt ? A("limit", M("DRAFT_LIMIT", p.message, r)) : A(
|
|
1005
|
+
"internal",
|
|
1006
|
+
M("DRAFT_INTERNAL", "The diagram could not be drawn.", r)
|
|
1007
|
+
),
|
|
1008
|
+
scene: s
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
if (!K(u))
|
|
1012
|
+
return {
|
|
1013
|
+
result: A(
|
|
1014
|
+
"input",
|
|
1015
|
+
M(
|
|
1016
|
+
"DRAFT_TEXT_INVALID",
|
|
1017
|
+
"The generated SVG contains text that XML cannot represent.",
|
|
1018
|
+
r
|
|
1019
|
+
)
|
|
1020
|
+
),
|
|
1021
|
+
scene: s
|
|
1022
|
+
};
|
|
1023
|
+
const d = /<svg[^>]*viewBox="([\d.-]+) ([\d.-]+) ([\d.]+) ([\d.]+)"[^>]*width="([\d.]+)"[^>]*height="([\d.]+)"/.exec(
|
|
1024
|
+
u
|
|
1025
|
+
);
|
|
1026
|
+
if (!d)
|
|
1027
|
+
return {
|
|
1028
|
+
result: A(
|
|
1029
|
+
"internal",
|
|
1030
|
+
M("DRAFT_INTERNAL", "The SVG dimensions could not be read.", r)
|
|
1031
|
+
),
|
|
1032
|
+
scene: s
|
|
1033
|
+
};
|
|
1034
|
+
const m = [
|
|
1035
|
+
...s.objects.map((p) => ({ id: p.id, kind: p.type, label: p.label, line: p.line })),
|
|
1036
|
+
...s.edges.map((p) => ({
|
|
1037
|
+
id: p.id,
|
|
1038
|
+
kind: "edge",
|
|
1039
|
+
label: p.label ?? "",
|
|
1040
|
+
line: p.line,
|
|
1041
|
+
from: p.source,
|
|
1042
|
+
to: p.target
|
|
1043
|
+
}))
|
|
1044
|
+
], w = {
|
|
1045
|
+
svg: u,
|
|
1046
|
+
title: t.title ?? s.title,
|
|
1047
|
+
...t.description !== void 0 ? { description: t.description } : {},
|
|
1048
|
+
width: Number(d[5]),
|
|
1049
|
+
height: Number(d[6]),
|
|
1050
|
+
viewBox: [Number(d[1]), Number(d[2]), Number(d[3]), Number(d[4])],
|
|
1051
|
+
items: m,
|
|
1052
|
+
states: (s.model.appearance.states ?? []).map((p) => ({ id: p.id, label: p.label })),
|
|
1053
|
+
activeState: t.state ?? null,
|
|
1054
|
+
provenance: {
|
|
1055
|
+
runtimeVersion: Be,
|
|
1056
|
+
fontMetricsVersion: nn,
|
|
1057
|
+
dslVersion: 1,
|
|
1058
|
+
renderContextVersion: "1"
|
|
1059
|
+
}
|
|
1060
|
+
}, T = s.diagnostics.map((p) => ({
|
|
1061
|
+
code: p.code === "fit" ? "DRAFT_LAYOUT_NOTE" : "DRAFT_COMPILE",
|
|
1062
|
+
severity: p.level,
|
|
1063
|
+
message: p.message,
|
|
1064
|
+
...p.line ? { location: { ...r ? { sourceId: r } : {}, line: p.line } } : {},
|
|
1065
|
+
itemIds: [...p.ids],
|
|
1066
|
+
nativeCode: p.code
|
|
1067
|
+
}));
|
|
1068
|
+
return t.signal?.aborted ? {
|
|
1069
|
+
result: A("aborted", M("DRAFT_ABORTED", "Rendering was aborted.", r)),
|
|
1070
|
+
scene: s
|
|
1071
|
+
} : { result: { ok: !0, value: w, diagnostics: [...T, ...i] }, scene: s };
|
|
1072
|
+
}
|
|
1073
|
+
async function zn(e, t) {
|
|
1074
|
+
return (await Un(e, t)).result;
|
|
1075
|
+
}
|
|
1076
|
+
async function Vn(e, t = {}) {
|
|
1077
|
+
if (!t || typeof t != "object" || Array.isArray(t))
|
|
1078
|
+
throw new TypeError("Validation options must be an object.");
|
|
1079
|
+
if (t.sourceId !== void 0 && typeof t.sourceId != "string")
|
|
1080
|
+
throw new TypeError("sourceId must be a string.");
|
|
1081
|
+
if (typeof e != "string") throw new TypeError("source must be a string.");
|
|
1082
|
+
const n = yt(t.limits, !0), r = t.sourceId;
|
|
1083
|
+
if (t.signal?.aborted)
|
|
1084
|
+
return A("aborted", M("DRAFT_ABORTED", "Validation was aborted.", r));
|
|
1085
|
+
if (e.length > n.maxSourceChars || $t.encode(e).byteLength > n.maxSourceBytes)
|
|
1086
|
+
return A(
|
|
1087
|
+
"limit",
|
|
1088
|
+
M("DRAFT_LIMIT", "The source exceeds the configured size limit.", r)
|
|
1089
|
+
);
|
|
1090
|
+
if (!K(e))
|
|
1091
|
+
return A(
|
|
1092
|
+
"input",
|
|
1093
|
+
M(
|
|
1094
|
+
"DRAFT_TEXT_INVALID",
|
|
1095
|
+
"The source contains text that XML cannot represent.",
|
|
1096
|
+
r
|
|
1097
|
+
)
|
|
1098
|
+
);
|
|
1099
|
+
const o = wt(e, n, r);
|
|
1100
|
+
if (o) return A(le(o), o);
|
|
1101
|
+
try {
|
|
1102
|
+
const s = await We(e);
|
|
1103
|
+
if (t.signal?.aborted)
|
|
1104
|
+
return A("aborted", M("DRAFT_ABORTED", "Validation was aborted.", r));
|
|
1105
|
+
const a = xt(s, n, r);
|
|
1106
|
+
if (a) return A("limit", a);
|
|
1107
|
+
if (oe(s))
|
|
1108
|
+
return A(
|
|
1109
|
+
"input",
|
|
1110
|
+
M(
|
|
1111
|
+
"DRAFT_TEXT_INVALID",
|
|
1112
|
+
"A decoded diagram label contains text that XML cannot represent.",
|
|
1113
|
+
r
|
|
1114
|
+
)
|
|
1115
|
+
);
|
|
1116
|
+
const l = s.diagnostics.filter((i) => i.level === "error");
|
|
1117
|
+
return l.length ? {
|
|
1118
|
+
ok: !1,
|
|
1119
|
+
reason: "input",
|
|
1120
|
+
diagnostics: l.map(
|
|
1121
|
+
(i) => M("DRAFT_COMPILE", i.message, r, i.line, void 0, i.code, i.ids)
|
|
1122
|
+
)
|
|
1123
|
+
} : {
|
|
1124
|
+
ok: !0,
|
|
1125
|
+
diagnostics: s.diagnostics.map((i) => ({
|
|
1126
|
+
code: "DRAFT_COMPILE",
|
|
1127
|
+
severity: i.level,
|
|
1128
|
+
message: i.message,
|
|
1129
|
+
...i.line ? { location: { ...r ? { sourceId: r } : {}, line: i.line } } : {},
|
|
1130
|
+
itemIds: [...i.ids],
|
|
1131
|
+
nativeCode: i.code
|
|
1132
|
+
}))
|
|
1133
|
+
};
|
|
1134
|
+
} catch (s) {
|
|
1135
|
+
const a = Ae(s, r);
|
|
1136
|
+
return A(
|
|
1137
|
+
s instanceof re && /Limit:/.test(s.message) ? "limit" : le(a),
|
|
1138
|
+
a
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
export {
|
|
1143
|
+
Be as a,
|
|
1144
|
+
zn as r,
|
|
1145
|
+
Vn as v
|
|
1146
|
+
};
|