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