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