@draftably/runtime 0.2.0 → 0.4.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 +14 -0
- package/dist/assets/render.worker-BXjS76Gy.js +8485 -0
- package/dist/compile-C2lvlbqE.js +7369 -0
- package/dist/element.js +275 -125
- package/dist/{font-data-tnqJ-kTK.js → font-data-DME3E71S.js} +1 -1
- package/dist/geometry-DfUVE8b2.js +79 -0
- package/dist/graph.js +632 -0
- package/dist/host.css +37 -0
- package/dist/host.js +16 -0
- package/dist/index.js +5 -4
- package/dist/render-CFWEEKPT.js +1160 -0
- package/dist/types/src/dsl/cells.d.ts +1 -0
- package/dist/types/src/dsl/compile.d.ts +15 -1
- package/dist/types/src/dsl/corridors.d.ts +38 -0
- package/dist/types/src/dsl/legend-notes.d.ts +14 -0
- package/dist/types/src/dsl/syntax.d.ts +2 -0
- package/dist/types/src/graph-api/core.d.ts +125 -0
- package/dist/types/src/graph-api/cytoscape.d.ts +48 -0
- package/dist/types/src/graph-api/dagre.d.ts +33 -0
- package/dist/types/src/graph-api/elk.d.ts +91 -0
- package/dist/types/src/graph-api/index.d.ts +60 -0
- package/dist/types/src/graph-api/react-flow.d.ts +100 -0
- package/dist/types/src/graph-api/transform.d.ts +6 -0
- package/dist/types/src/model/appearance.d.ts +19 -0
- package/dist/types/src/model/colors.d.ts +10 -2
- package/dist/types/src/model/labels.d.ts +22 -6
- package/dist/types/src/model/types.d.ts +9 -0
- package/dist/types/src/runtime/anchors.d.ts +46 -0
- package/dist/types/src/runtime/camera.d.ts +41 -0
- package/dist/types/src/runtime/element-base.d.ts +40 -0
- package/dist/types/src/runtime/element.d.ts +7 -0
- package/dist/types/src/runtime/geometry.d.ts +72 -0
- package/dist/types/src/runtime/host.d.ts +46 -0
- package/dist/types/src/runtime/index.d.ts +1 -0
- package/dist/types/src/runtime/page-shared.d.ts +24 -0
- package/dist/types/src/runtime/svg-renderer.d.ts +8 -0
- package/dist/types/src/runtime/types.d.ts +6 -0
- package/dist/types/src/runtime/viewer.d.ts +41 -7
- package/dist/version-CKs2Vl8m.js +4 -0
- package/dist/viewer.css +66 -9
- package/dist/viewer.js +689 -341
- package/package.json +10 -1
- package/dist/assets/render.worker-fWW85Tf9.js +0 -7661
- package/dist/render-ZzhO-2H6.js +0 -7676
package/dist/viewer.js
CHANGED
|
@@ -1,438 +1,786 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as
|
|
3
|
-
|
|
1
|
+
import { i as Ne, F as Ie } from "./geometry-DfUVE8b2.js";
|
|
2
|
+
import { f as vt } from "./geometry-DfUVE8b2.js";
|
|
3
|
+
import { r as Et } from "./version-CKs2Vl8m.js";
|
|
4
|
+
const $e = 0.02, ze = 8, Ze = 32, ye = (o, t = $e, a = ze) => Math.min(Math.max(o, Math.max($e, t)), Math.min(ze, a));
|
|
5
|
+
function Oe(o = {}) {
|
|
6
|
+
const t = o.padding ?? Ze;
|
|
7
|
+
return typeof t == "number" ? { top: t, right: t, bottom: t, left: t } : t;
|
|
8
|
+
}
|
|
9
|
+
function Ge(o) {
|
|
10
|
+
if (!o.length) return;
|
|
11
|
+
const t = Math.min(...o.map((d) => d.x)), a = Math.min(...o.map((d) => d.y)), r = Math.max(...o.map((d) => d.x + d.width)), c = Math.max(...o.map((d) => d.y + d.height));
|
|
12
|
+
return { x: t, y: a, width: r - t, height: c - a };
|
|
13
|
+
}
|
|
14
|
+
function Re(o, t, a = {}) {
|
|
15
|
+
const r = Oe(a), c = Math.max(1, t.width - r.left - r.right), d = Math.max(1, t.height - r.top - r.bottom), g = ye(
|
|
16
|
+
Math.min(c / Math.max(1, o.width), d / Math.max(1, o.height)),
|
|
17
|
+
a.minZoom,
|
|
18
|
+
a.maxZoom ?? 1
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
centerX: o.x + o.width / 2 - (r.left - r.right) / 2 / g,
|
|
22
|
+
centerY: o.y + o.height / 2 - (r.top - r.bottom) / 2 / g,
|
|
23
|
+
zoom: g
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function He(o, t, a, r = {}) {
|
|
27
|
+
const c = Oe(r), d = { width: a.width - c.left - c.right, height: a.height - c.top - c.bottom };
|
|
28
|
+
let { centerX: g, centerY: i, zoom: f } = o;
|
|
29
|
+
if (t.width * f > d.width || t.height * f > d.height)
|
|
30
|
+
return Re(t, a, { ...r, maxZoom: f });
|
|
31
|
+
f = ye(f, r.minZoom, r.maxZoom);
|
|
32
|
+
const p = (t.x - g) * f + a.width / 2, m = (t.y - i) * f + a.height / 2;
|
|
33
|
+
return p < c.left ? g -= (c.left - p) / f : p + t.width * f > a.width - c.right && (g += (p + t.width * f - (a.width - c.right)) / f), m < c.top ? i -= (c.top - m) / f : m + t.height * f > a.height - c.bottom && (i += (m + t.height * f - (a.height - c.bottom)) / f), { centerX: g, centerY: i, zoom: f };
|
|
34
|
+
}
|
|
35
|
+
const Ue = (o, t) => Math.abs(o.centerX - t.centerX) < 0.01 && Math.abs(o.centerY - t.centerY) < 0.01 && Math.abs(o.zoom - t.zoom) < 1e-6, Ke = 0.4, Je = (o, t) => o.nodes[t] ? "node" : o.groups[t] ? "group" : o.edges[t] ? "edge" : void 0, Te = (o, t, a) => ({
|
|
36
|
+
code: o,
|
|
37
|
+
severity: "warning",
|
|
38
|
+
message: t,
|
|
39
|
+
itemIds: [a]
|
|
40
|
+
});
|
|
41
|
+
function Qe(o, t = {}) {
|
|
42
|
+
const a = o.createElement("div"), r = o.createElement("div"), c = o.createElement("div");
|
|
43
|
+
a.className = "draft-anchors", r.className = "draft-anchors__bodies", c.className = "draft-anchors__overlays", a.append(r, c), a.dataset.draftDetail = "full";
|
|
44
|
+
const d = /* @__PURE__ */ new Map();
|
|
45
|
+
let g = [], i = null, f = !1, p = [], m = 1;
|
|
46
|
+
const N = /* @__PURE__ */ new Set(), b = o.defaultView, M = () => {
|
|
47
|
+
let l = !1;
|
|
48
|
+
for (const [w, h] of d) {
|
|
49
|
+
if (!h.body) continue;
|
|
50
|
+
const $ = (Z.get(h) ?? []).some(
|
|
51
|
+
(D) => D.offsetWidth > h.box.width + 0.5 || D.offsetHeight > h.box.height + 0.5
|
|
52
|
+
);
|
|
53
|
+
$ !== N.has(w) && (l = !0, $ ? N.add(w) : N.delete(w));
|
|
54
|
+
}
|
|
55
|
+
l && t.onOverflow?.();
|
|
56
|
+
}, x = b?.ResizeObserver ? new b.ResizeObserver(M) : void 0, Z = /* @__PURE__ */ new Map(), k = (l) => {
|
|
57
|
+
if (!x || !l.body) return;
|
|
58
|
+
for (const h of Z.get(l) ?? []) x.unobserve(h);
|
|
59
|
+
const w = U(l.el);
|
|
60
|
+
Z.set(l, w);
|
|
61
|
+
for (const h of w) x.observe(h);
|
|
62
|
+
}, X = (l) => {
|
|
63
|
+
for (const w of Z.get(l) ?? []) x?.unobserve(w);
|
|
64
|
+
Z.delete(l);
|
|
65
|
+
}, Y = (l) => {
|
|
66
|
+
const w = l.closest?.("[data-draft-anchor]")?.getAttribute("data-draft-anchor");
|
|
67
|
+
return w ? d.get(w) : void 0;
|
|
68
|
+
};
|
|
69
|
+
a.addEventListener("slotchange", (l) => {
|
|
70
|
+
const w = Y(l.target);
|
|
71
|
+
w && k(w);
|
|
72
|
+
});
|
|
73
|
+
const Q = b?.MutationObserver ? new b.MutationObserver((l) => {
|
|
74
|
+
const w = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const h of l) {
|
|
76
|
+
const $ = h.target.dataset?.draftAnchor ? Y(h.target) : void 0;
|
|
77
|
+
$ && !w.has($) && (w.add($), k($));
|
|
78
|
+
}
|
|
79
|
+
}) : void 0;
|
|
80
|
+
Q?.observe(r, { childList: !0, subtree: !0 });
|
|
81
|
+
let G = !1;
|
|
82
|
+
const j = () => G = !0, H = () => G = !1;
|
|
83
|
+
a.addEventListener("pointerdown", j, !0), o.addEventListener("pointerup", H, !0), o.addEventListener("pointercancel", H, !0);
|
|
84
|
+
function U(l) {
|
|
85
|
+
const w = l.firstElementChild;
|
|
86
|
+
return w instanceof HTMLSlotElement ? w.assignedElements().filter((h) => h instanceof HTMLElement) : [...l.children].filter((h) => h instanceof HTMLElement);
|
|
87
|
+
}
|
|
88
|
+
function ae() {
|
|
89
|
+
let l = o.activeElement;
|
|
90
|
+
for (; l?.shadowRoot?.activeElement; ) l = l.shadowRoot.activeElement;
|
|
91
|
+
return l;
|
|
92
|
+
}
|
|
93
|
+
function ee() {
|
|
94
|
+
let l = !1, w = !1;
|
|
95
|
+
const h = /* @__PURE__ */ new Set();
|
|
96
|
+
p = [];
|
|
97
|
+
let $;
|
|
98
|
+
const D = (E) => {
|
|
99
|
+
$ ??= new Map(
|
|
100
|
+
[i.nodes, i.groups, i.edges].flatMap(Object.keys).map((z, W) => [z, W])
|
|
101
|
+
);
|
|
102
|
+
const C = E.dataset.draftAnchor;
|
|
103
|
+
return $.get(C.slice(C.indexOf(":") + 1)) ?? 1 / 0;
|
|
104
|
+
};
|
|
105
|
+
for (const E of g) {
|
|
106
|
+
const C = E.indexOf(":"), z = E.slice(0, C), W = E.slice(C + 1), F = i ? Je(i, W) : void 0;
|
|
107
|
+
if (!i || !F || z === "body" && F !== "node" || h.has(E)) {
|
|
108
|
+
f && !h.has(E) && p.push(E);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
h.add(E);
|
|
112
|
+
const I = Ne(i, W);
|
|
113
|
+
let S = d.get(E);
|
|
114
|
+
if (!S || S.kind !== F) {
|
|
115
|
+
S && (S.el.remove(), X(S));
|
|
116
|
+
const T = o.createElement("div");
|
|
117
|
+
T.className = `draft-anchor draft-anchor--${z}`, T.dataset.draftAnchor = E, S = { el: T, id: W, kind: F, body: z === "body", box: I }, d.set(E, S);
|
|
118
|
+
const K = S.body ? r : c, ne = K.children, ce = D(T);
|
|
119
|
+
let B = 0, oe = ne.length;
|
|
120
|
+
for (; B < oe; ) {
|
|
121
|
+
const se = B + oe >> 1;
|
|
122
|
+
D(ne[se]) > ce ? oe = se : B = se + 1;
|
|
123
|
+
}
|
|
124
|
+
K.insertBefore(T, ne[B] ?? null), k(S), l = !0;
|
|
125
|
+
} else S.body && (S.box.width !== I.width || S.box.height !== I.height) && (w = !0);
|
|
126
|
+
if (S.box = I, S.body) {
|
|
127
|
+
const T = S.el.style;
|
|
128
|
+
T.left = `${I.x}px`, T.top = `${I.y}px`, T.width = `${I.width}px`, T.height = `${I.height}px`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const [E, C] of d) {
|
|
132
|
+
if (h.has(E)) continue;
|
|
133
|
+
const z = ae(), W = !!z && (C.el.contains(z) || U(C.el).some((F) => F.contains(z)));
|
|
134
|
+
C.el.remove(), X(C), d.delete(E), N.delete(E), l = !0, W && a.dispatchEvent(new CustomEvent("draft-anchor-focus-lost"));
|
|
135
|
+
}
|
|
136
|
+
return w && x && M(), l;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
el: a,
|
|
140
|
+
setSlots(l) {
|
|
141
|
+
return g = [...new Set(l)], ee();
|
|
142
|
+
},
|
|
143
|
+
hasSlots: () => g.length > 0,
|
|
144
|
+
setGeometry(l) {
|
|
145
|
+
return i = l, f = !0, ee();
|
|
146
|
+
},
|
|
147
|
+
place(l, w, h) {
|
|
148
|
+
if (!g.length) return;
|
|
149
|
+
(h !== m || !a.style.getPropertyValue("--draft-zoom")) && a.style.setProperty("--draft-zoom", String(h)), m = h, r.style.transform = `translate(${l}px, ${w}px) scale(${h})`;
|
|
150
|
+
for (const D of d.values()) {
|
|
151
|
+
if (D.body) continue;
|
|
152
|
+
const E = D.el.style;
|
|
153
|
+
E.transform = `translate(${l + D.box.x * h}px, ${w + D.box.y * h}px)`, E.width = `${D.box.width * h}px`, E.height = `${D.box.height * h}px`;
|
|
154
|
+
}
|
|
155
|
+
const $ = t.detail !== "full" && h < Ke;
|
|
156
|
+
a.dataset.draftDetail === "low" !== $ && (a.dataset.draftDetail = $ ? "low" : "full", r.inert = $);
|
|
157
|
+
},
|
|
158
|
+
anchors: () => [...d].map(([l, w]) => ({
|
|
159
|
+
slot: l,
|
|
160
|
+
id: w.id,
|
|
161
|
+
kind: w.kind,
|
|
162
|
+
el: w.el
|
|
163
|
+
})),
|
|
164
|
+
// Every anchored body, at any zoom: CSS shows titles again below LOW_DETAIL_ZOOM.
|
|
165
|
+
bodyIds: () => [...d.values()].filter((l) => l.body).map((l) => l.id),
|
|
166
|
+
warnings: () => [
|
|
167
|
+
...p.map(
|
|
168
|
+
(l) => Te(
|
|
169
|
+
"DRAFT_SLOT_UNKNOWN",
|
|
170
|
+
i ? `Slot ${l} names no item that can hold it. A body fills a node; an overlay covers a node, group or edge.` : `Slot ${l} shows nothing: this drawing repeats items (compare or states), so slots are off.`,
|
|
171
|
+
l.slice(l.indexOf(":") + 1)
|
|
172
|
+
)
|
|
173
|
+
),
|
|
174
|
+
...[...N].map(
|
|
175
|
+
(l) => Te(
|
|
176
|
+
"DRAFT_SLOT_OVERFLOW",
|
|
177
|
+
`The content of ${l} is larger than its node. Declare the room with size … min-height=.`,
|
|
178
|
+
l.slice(l.indexOf(":") + 1)
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
],
|
|
182
|
+
pressed: () => G,
|
|
183
|
+
idOf(l) {
|
|
184
|
+
for (const w of d.values())
|
|
185
|
+
if (w.el.contains(l) || U(w.el).some((h) => h.contains(l))) return w.id;
|
|
186
|
+
},
|
|
187
|
+
destroy() {
|
|
188
|
+
x?.disconnect(), Q?.disconnect(), o.removeEventListener("pointerup", H, !0), o.removeEventListener("pointercancel", H, !0), Z.clear(), d.clear(), a.remove();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const De = Math.max(
|
|
193
|
+
1,
|
|
194
|
+
Math.min(4, (globalThis.navigator?.hardwareConcurrency || 2) - 1)
|
|
195
|
+
), et = 3e4, Fe = /* @__PURE__ */ new Map();
|
|
196
|
+
let tt = 0;
|
|
197
|
+
const _e = "The worker is the module next to @draftably/runtime's viewer. With Vite, add optimizeDeps: { exclude: ['@draftably/runtime', '@draftably/editor'] } to vite.config.", rt = () => new Worker(new URL("./assets/render.worker-BXjS76Gy.js", import.meta.url), { type: "module" });
|
|
198
|
+
function fe(o, t, a) {
|
|
199
|
+
o.slots.splice(o.slots.indexOf(t), 1), clearTimeout(t.timer), clearTimeout(t.idle), t.worker.terminate();
|
|
200
|
+
const r = t.job;
|
|
201
|
+
t.job = void 0, r && a && r.reject(a);
|
|
202
|
+
}
|
|
203
|
+
function nt(o, t) {
|
|
204
|
+
let a;
|
|
205
|
+
try {
|
|
206
|
+
a = (o ?? rt)();
|
|
207
|
+
} catch (c) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Viewer render worker could not start${c instanceof Error ? `: ${c.message}` : ""}. ${_e}`,
|
|
210
|
+
{ cause: c }
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const r = { worker: a };
|
|
214
|
+
return t.slots.push(r), a.addEventListener("message", (c) => {
|
|
215
|
+
const d = r.job;
|
|
216
|
+
!d || c.data?.id !== d.id || (clearTimeout(r.timer), r.job = void 0, d.resolve(c.data.result), r.idle = setTimeout(() => fe(t, r), et), ie(o, t));
|
|
217
|
+
}), a.addEventListener("error", (c) => {
|
|
218
|
+
c.preventDefault(), fe(
|
|
219
|
+
t,
|
|
220
|
+
r,
|
|
221
|
+
new Error(`${c.message || "Viewer render worker failed."} ${_e}`)
|
|
222
|
+
), ie(o, t);
|
|
223
|
+
}), a.addEventListener("messageerror", () => {
|
|
224
|
+
fe(t, r, new Error("Viewer render worker returned an unreadable result.")), ie(o, t);
|
|
225
|
+
}), r;
|
|
226
|
+
}
|
|
227
|
+
function ie(o, t) {
|
|
228
|
+
for (; t.queue.length; ) {
|
|
229
|
+
const a = t.queue[0].options.idPrefix;
|
|
230
|
+
let r = t.slots.find((g) => !g.job && g.last === a);
|
|
231
|
+
if (!r && t.slots.length >= De && (r = t.slots.find((g) => !g.job)), !r && t.slots.length < De)
|
|
232
|
+
try {
|
|
233
|
+
r = nt(o, t);
|
|
234
|
+
} catch (g) {
|
|
235
|
+
for (const i of t.queue.splice(0)) i.reject(g);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!r) return;
|
|
239
|
+
const c = t.queue.shift();
|
|
240
|
+
clearTimeout(r.idle), r.job = c, r.last = a;
|
|
241
|
+
const d = r;
|
|
242
|
+
r.timer = setTimeout(() => {
|
|
243
|
+
fe(t, d, new Error("Viewer render worker timed out.")), ie(o, t);
|
|
244
|
+
}, c.timeoutMs), r.worker.postMessage({ id: c.id, source: c.source, options: c.options });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function ot(o, t, {
|
|
248
|
+
create: a,
|
|
249
|
+
timeoutMs: r = 5e3,
|
|
250
|
+
signal: c
|
|
251
|
+
}) {
|
|
252
|
+
return new Promise((d, g) => {
|
|
253
|
+
const i = Fe.get(a) ?? { slots: [], queue: [] };
|
|
254
|
+
Fe.set(a, i);
|
|
255
|
+
let f = !1;
|
|
256
|
+
const p = () => {
|
|
257
|
+
f = !0, c?.removeEventListener("abort", N);
|
|
258
|
+
}, m = {
|
|
259
|
+
id: ++tt,
|
|
260
|
+
source: o,
|
|
261
|
+
options: t,
|
|
262
|
+
timeoutMs: r,
|
|
263
|
+
resolve: (b) => f || (p(), d(b)),
|
|
264
|
+
reject: (b) => f || (p(), g(b))
|
|
265
|
+
}, N = () => {
|
|
266
|
+
const b = i.queue.indexOf(m);
|
|
267
|
+
b >= 0 && i.queue.splice(b, 1), m.reject(new Error("Viewer render was aborted."));
|
|
268
|
+
};
|
|
269
|
+
c?.addEventListener("abort", N, { once: !0 }), i.queue.push(m), ie(a, i);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const ue = /* @__PURE__ */ new WeakMap(), we = (o, t) => ue.get(o)?.get(t)?.face;
|
|
273
|
+
function st(o, t, a) {
|
|
274
|
+
const r = ue.get(o) ?? /* @__PURE__ */ new Map();
|
|
275
|
+
ue.set(o, r);
|
|
276
|
+
const c = r.get(t);
|
|
277
|
+
if (c) return void c.refs++;
|
|
278
|
+
o.fonts.add(a), r.set(t, { face: a, refs: 1 });
|
|
279
|
+
}
|
|
280
|
+
function pe(o, t) {
|
|
281
|
+
const a = ue.get(o), r = a?.get(t);
|
|
282
|
+
!r || --r.refs > 0 || (o.fonts.delete(r.face), a.delete(t));
|
|
283
|
+
}
|
|
284
|
+
const it = "http://www.w3.org/2000/svg", at = new Set(
|
|
4
285
|
"svg title desc metadata defs style marker g a path rect ellipse circle line polyline polygon text tspan".split(
|
|
5
286
|
" "
|
|
6
287
|
)
|
|
7
|
-
),
|
|
288
|
+
), ct = new Set(
|
|
8
289
|
"aria-labelledby role id data-id data-phase data-state data-theme xmlns viewBox width height x y x1 y1 x2 y2 cx cy r rx ry d points transform fill fill-rule fill-opacity stroke stroke-opacity stroke-width stroke-linecap stroke-linejoin stroke-dasharray opacity font-family font-size font-weight text-anchor dominant-baseline dy text-decoration marker-start marker-end markerWidth markerHeight markerUnits refX refY orient class clip-path nonce href target rel".split(
|
|
9
290
|
" "
|
|
10
291
|
)
|
|
11
292
|
);
|
|
12
|
-
let
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
293
|
+
let lt = 0;
|
|
294
|
+
function dt(o, t) {
|
|
295
|
+
return new o.defaultView.DOMParser().parseFromString(t, "image/svg+xml");
|
|
296
|
+
}
|
|
297
|
+
function ft(o) {
|
|
298
|
+
const t = /* @__PURE__ */ new Map();
|
|
299
|
+
for (const a of Array.from(o.querySelectorAll("text[font-family]"))) {
|
|
300
|
+
const r = (a.getAttribute("font-family") ?? "").split(",")[0].trim().replace(/^['"]|['"]$/g, ""), c = a.getAttribute("font-weight") ?? "400";
|
|
301
|
+
if (!Object.values(Ie).some((d) => d.family === r && String(d.weight) === c))
|
|
18
302
|
throw new Error("Runtime SVG requested an unknown bundled font face.");
|
|
19
|
-
|
|
303
|
+
t.set(`${r}:${c}`, { family: r, weight: c });
|
|
20
304
|
}
|
|
21
|
-
return [...
|
|
305
|
+
return [...t.values()];
|
|
22
306
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
for (const
|
|
26
|
-
const
|
|
27
|
-
for (const [,
|
|
28
|
-
const
|
|
29
|
-
!
|
|
307
|
+
function ut(o, t) {
|
|
308
|
+
const a = /* @__PURE__ */ new Map();
|
|
309
|
+
for (const r of Array.from(o.querySelectorAll("style"))) {
|
|
310
|
+
const c = r.textContent ?? "";
|
|
311
|
+
for (const [, d] of c.matchAll(/@font-face\s*\{([^{}]{1,200000})\}/g)) {
|
|
312
|
+
const g = /font-family\s*:\s*['"]([^'"]+)['"]/i.exec(d)?.[1], i = /font-weight\s*:\s*(\d{1,4})/i.exec(d)?.[1], f = /src\s*:\s*url\((data:font\/woff2;base64,[A-Za-z0-9+/=]+)\)/i.exec(d)?.[1];
|
|
313
|
+
!g || !i || !f || Object.values(Ie).some((p) => p.family === g && String(p.weight) === i) && a.set(`${g}:${i}`, { family: g, weight: i, data: f });
|
|
30
314
|
}
|
|
31
315
|
}
|
|
32
|
-
return
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
return
|
|
316
|
+
return t.map((r) => {
|
|
317
|
+
const c = a.get(`${r.family}:${r.weight}`);
|
|
318
|
+
if (!c) throw new Error(`Embedded font ${r.family} ${r.weight} is missing.`);
|
|
319
|
+
return c;
|
|
36
320
|
});
|
|
37
321
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
if (v.querySelector("parsererror") || v.documentElement.localName !== "svg")
|
|
322
|
+
function mt(o, t, a, r = 1e5) {
|
|
323
|
+
if (t.querySelector("parsererror") || t.documentElement.localName !== "svg")
|
|
41
324
|
throw new Error("Runtime returned invalid SVG.");
|
|
42
|
-
const
|
|
43
|
-
Array.from(
|
|
325
|
+
const c = new Set(
|
|
326
|
+
Array.from(t.querySelectorAll("[id]"), (i) => i.getAttribute("id") ?? "")
|
|
44
327
|
);
|
|
45
|
-
let
|
|
46
|
-
const
|
|
47
|
-
if (++
|
|
328
|
+
let d = 0;
|
|
329
|
+
const g = (i) => {
|
|
330
|
+
if (++d > r || !at.has(i.localName))
|
|
48
331
|
throw new Error("Runtime SVG exceeded the allowed drawing vocabulary.");
|
|
49
|
-
const
|
|
50
|
-
for (const { name: p, value: m } of Array.from(
|
|
332
|
+
const f = o.createElementNS(it, i.localName);
|
|
333
|
+
for (const { name: p, value: m } of Array.from(i.attributes)) {
|
|
51
334
|
if (/^on/i.test(p)) continue;
|
|
52
335
|
if (p === "href") {
|
|
53
|
-
if (
|
|
336
|
+
if (i.localName !== "a") continue;
|
|
54
337
|
try {
|
|
55
|
-
const
|
|
56
|
-
(
|
|
338
|
+
const b = new URL(m, o.baseURI);
|
|
339
|
+
(b.protocol === "http:" || b.protocol === "https:") && f.setAttribute("href", b.href);
|
|
57
340
|
} catch {
|
|
58
341
|
}
|
|
59
342
|
continue;
|
|
60
343
|
}
|
|
61
|
-
if (!
|
|
62
|
-
const
|
|
63
|
-
/url\s*\(/i.test(m) && (
|
|
344
|
+
if (!ct.has(p) && !/^data-[a-z0-9-]+$/.test(p)) continue;
|
|
345
|
+
const N = [...m.matchAll(/url\(#([^)]*)\)/g)].map((b) => b[1]);
|
|
346
|
+
/url\s*\(/i.test(m) && (N.length === 0 || N.some((b) => !c.has(b))) || p === "aria-labelledby" && m.split(/\s+/).some((b) => !c.has(b)) || f.setAttribute(p, m);
|
|
64
347
|
}
|
|
65
|
-
|
|
66
|
-
for (const p of Array.from(
|
|
67
|
-
if (p.nodeType === 1)
|
|
348
|
+
i.localName === "a" && f.getAttribute("target") === "_blank" && f.setAttribute("rel", "noopener noreferrer");
|
|
349
|
+
for (const p of Array.from(i.childNodes))
|
|
350
|
+
if (p.nodeType === 1) f.append(g(p));
|
|
68
351
|
else if (p.nodeType === 3) {
|
|
69
352
|
const m = p.nodeValue ?? "";
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
353
|
+
f.append(
|
|
354
|
+
o.createTextNode(
|
|
355
|
+
i.localName === "style" && a ? m.replace(/@font-face\s*\{[^{}]*\}/g, "") : m
|
|
73
356
|
)
|
|
74
357
|
);
|
|
75
358
|
}
|
|
76
|
-
return
|
|
359
|
+
return f;
|
|
77
360
|
};
|
|
78
|
-
return
|
|
361
|
+
return g(t.documentElement);
|
|
79
362
|
}
|
|
80
|
-
function
|
|
363
|
+
function de(o, t, a) {
|
|
81
364
|
return {
|
|
82
365
|
ok: !1,
|
|
83
|
-
reason:
|
|
84
|
-
diagnostics: [{ code:
|
|
366
|
+
reason: o,
|
|
367
|
+
diagnostics: [{ code: t, severity: "error", message: a, itemIds: [] }]
|
|
85
368
|
};
|
|
86
369
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
370
|
+
function wt(o, t = {}) {
|
|
371
|
+
const a = o?.ownerDocument?.defaultView;
|
|
372
|
+
if (!a || !(o instanceof a.HTMLElement))
|
|
90
373
|
throw new TypeError("host must be an HTMLElement.");
|
|
91
|
-
if (
|
|
92
|
-
if ((
|
|
374
|
+
if (o.childNodes.length) throw new Error("Viewer host must be empty and exclusively owned.");
|
|
375
|
+
if ((t.execution ?? { mode: "worker" }).mode === "worker" && t.render?.links?.mode === "safe" && t.render.links.resolve)
|
|
93
376
|
throw new TypeError('A link resolver requires execution: { mode: "main" }.');
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const f =
|
|
377
|
+
const r = o.ownerDocument, c = a, d = r.createElement("section");
|
|
378
|
+
d.className = "draft-viewer", t.outline !== "visible" && d.classList.add("draft-viewer--outline-hidden"), d.setAttribute("aria-label", t.label ?? "Diagram viewer");
|
|
379
|
+
const g = r.createElement("div");
|
|
380
|
+
g.className = "draft-viewer__toolbar", g.setAttribute("role", "toolbar"), g.setAttribute("aria-label", "Diagram controls");
|
|
381
|
+
const i = r.createElement("div");
|
|
382
|
+
i.className = "draft-viewer__viewport", i.tabIndex = 0, i.setAttribute("aria-label", t.label ?? "Diagram");
|
|
383
|
+
const f = r.createElement("p");
|
|
101
384
|
f.className = "draft-viewer__status", f.setAttribute("role", "status"), f.setAttribute("aria-live", "polite");
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
385
|
+
const p = r.createElement("ol");
|
|
386
|
+
p.className = "draft-viewer__outline", p.setAttribute("aria-label", "Diagram outline"), d.append(g, i, f, p);
|
|
387
|
+
const m = Qe(r, {
|
|
388
|
+
detail: t.detail,
|
|
389
|
+
onOverflow: () => l()
|
|
390
|
+
});
|
|
391
|
+
i.append(m.el), o.append(d);
|
|
392
|
+
const N = `draftViewer${(++lt).toString(36)}${Math.random().toString(36).slice(2, 9)}`;
|
|
393
|
+
let b = 0, M = !1, x = { centerX: 0, centerY: 0, zoom: 1 }, Z = !1, k, X = { width: 0, height: 0 };
|
|
394
|
+
const Y = /* @__PURE__ */ new Set(), Q = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map(), j = (e, s) => {
|
|
395
|
+
for (const n of Q.get(e) ?? [])
|
|
108
396
|
try {
|
|
109
|
-
|
|
397
|
+
n(s);
|
|
110
398
|
} catch {
|
|
111
399
|
}
|
|
112
|
-
},
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
e
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!r.width || !r.height) return;
|
|
128
|
-
const [t, S, g, n] = u.viewBox;
|
|
129
|
-
a = {
|
|
130
|
-
centerX: t + g / 2,
|
|
131
|
-
centerY: S + n / 2,
|
|
132
|
-
zoom: Math.min(1, re() * 0.92)
|
|
133
|
-
}, _ = !1, R(), L("camera", { camera: { ...a }, reason: e });
|
|
134
|
-
}, P = (e) => {
|
|
135
|
-
a.zoom = Math.max(0.02, Math.min(8, a.zoom * e)), _ = !0, R(), L("camera", { camera: { ...a }, reason: "user" });
|
|
136
|
-
}, ne = () => {
|
|
137
|
-
a.zoom = 1, _ = !0, R(), L("camera", { camera: { ...a }, reason: "user" });
|
|
400
|
+
}, H = (e, s) => {
|
|
401
|
+
const n = r.createElement("button");
|
|
402
|
+
n.type = "button", n.textContent = e, n.setAttribute("aria-label", e), n.addEventListener("click", s), g.append(n);
|
|
403
|
+
}, U = () => {
|
|
404
|
+
const e = i.querySelector("svg");
|
|
405
|
+
if (!e || !k) return;
|
|
406
|
+
const [s, n] = k.viewBox, v = X, A = x.zoom, O = v.width / 2 - (x.centerX - s) * A, u = v.height / 2 - (x.centerY - n) * A;
|
|
407
|
+
e.style.transformOrigin = "0 0", e.style.transform = `translate(${O}px, ${u}px) scale(${A})`, e.style.width = `${k.width}px`, e.style.height = `${k.height}px`, e.style.maxWidth = "none", m.place(O - s * A, u - n * A, A);
|
|
408
|
+
const R = m.el.dataset.draftDetail;
|
|
409
|
+
i.dataset.draftDetail !== R && (i.dataset.draftDetail = R);
|
|
410
|
+
}, ae = () => {
|
|
411
|
+
const e = new Set(m.bodyIds());
|
|
412
|
+
for (const s of i.querySelectorAll(":scope > svg [data-id]"))
|
|
413
|
+
s.toggleAttribute("data-draft-body", e.has(s.getAttribute("data-id")));
|
|
414
|
+
j("anchors", { anchors: m.anchors() });
|
|
138
415
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
416
|
+
let ee = {
|
|
417
|
+
revision: 0,
|
|
418
|
+
diagnostics: [],
|
|
419
|
+
stale: !1
|
|
420
|
+
};
|
|
421
|
+
const l = () => j("diagnostics", {
|
|
422
|
+
...ee,
|
|
423
|
+
diagnostics: [...ee.diagnostics, ...m.warnings()]
|
|
424
|
+
});
|
|
425
|
+
let w = "user", h = 0;
|
|
426
|
+
const $ = (e) => c.requestAnimationFrame ? c.requestAnimationFrame(e) : c.setTimeout(e, 16), D = (e) => {
|
|
427
|
+
w = e, !h && (h = $(() => {
|
|
428
|
+
h = 0, M || j("camera", { camera: { ...x }, reason: w });
|
|
429
|
+
}));
|
|
430
|
+
}, E = (e, s, n) => {
|
|
431
|
+
const v = { ...e, zoom: ye(e.zoom) };
|
|
432
|
+
return Z = n, Ue(x, v) ? "unchanged" : (x = v, U(), D(s), "moved");
|
|
433
|
+
}, C = () => {
|
|
434
|
+
const [e, s, n, v] = k.viewBox;
|
|
435
|
+
return { x: e, y: s, width: n, height: v };
|
|
436
|
+
};
|
|
437
|
+
let z = null;
|
|
438
|
+
const W = (e) => z ? Ne(z, e) : void 0;
|
|
439
|
+
let F;
|
|
440
|
+
const I = (e) => M ? "unchanged" : !k || !X.width || !X.height ? (F = e, "pending") : (F = void 0, e()), S = (e, s, n) => I(() => {
|
|
441
|
+
const v = e ? Ge(e.flatMap((A) => W(A) ?? [])) : C();
|
|
442
|
+
return v ? E(Re(v, X, s), n, !!e) : "missing";
|
|
443
|
+
}), T = (e = "fit") => S(void 0, void 0, e), K = (e) => E({ ...x, zoom: x.zoom * e }, "user", !0), ne = () => E({ ...x, zoom: 1 }, "user", !0);
|
|
444
|
+
H("Zoom in", () => K(1.2)), H("Zoom out", () => K(1 / 1.2)), H("Fit diagram", () => T()), H("Actual size", ne), g.hidden = t.toolbar === !1;
|
|
445
|
+
const ce = new c.ResizeObserver((e) => {
|
|
446
|
+
const s = e.at(-1)?.contentRect;
|
|
447
|
+
s && (X = { width: s.width, height: s.height }), !(k && !X.width) && (F ? I(F) : Z ? U() : T("resize"));
|
|
142
448
|
});
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
f.textContent =
|
|
146
|
-
}, oe = async (e,
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
149
|
-
if (!
|
|
150
|
-
if (
|
|
151
|
-
for (const
|
|
152
|
-
const
|
|
153
|
-
if (!(await
|
|
154
|
-
(
|
|
155
|
-
) || !
|
|
156
|
-
throw new Error(`Host font ${
|
|
449
|
+
ce.observe(i);
|
|
450
|
+
const B = (e, s) => {
|
|
451
|
+
f.textContent = s.map((n) => n.message).join(" "), d.classList.add("draft-viewer--stale"), ee = { revision: e, diagnostics: s, stale: !!k }, l();
|
|
452
|
+
}, oe = async (e, s) => {
|
|
453
|
+
const n = ft(e);
|
|
454
|
+
if (!n.length) return [];
|
|
455
|
+
if (!r.fonts) throw new Error("The host document cannot load diagram fonts.");
|
|
456
|
+
if (s === "host") {
|
|
457
|
+
for (const u of n) {
|
|
458
|
+
const R = `${u.weight} 12px "${u.family}"`;
|
|
459
|
+
if (!(await r.fonts.load(R)).some(
|
|
460
|
+
(q) => q.family.replace(/^['"]|['"]$/g, "") === u.family && q.weight === u.weight && q.status === "loaded"
|
|
461
|
+
) || !r.fonts.check(R))
|
|
462
|
+
throw new Error(`Host font ${u.family} ${u.weight} is unavailable.`);
|
|
157
463
|
}
|
|
158
464
|
return [];
|
|
159
465
|
}
|
|
160
|
-
const
|
|
161
|
-
if (
|
|
466
|
+
const v = n.map((u) => `${u.family}:${u.weight}`);
|
|
467
|
+
if (v.every((u) => we(r, u)))
|
|
468
|
+
return v.map((u) => ({ key: u, face: we(r, u) }));
|
|
469
|
+
const A = ut(e, n), O = c.FontFace;
|
|
470
|
+
if (!O) throw new Error("The browser cannot load embedded diagram fonts.");
|
|
162
471
|
return Promise.all(
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return { key: h, face: d };
|
|
472
|
+
A.map(async (u) => {
|
|
473
|
+
const R = `${u.family}:${u.weight}`, te = we(r, R);
|
|
474
|
+
if (te) return { key: R, face: te };
|
|
475
|
+
const L = new O(u.family, `url("${u.data}")`, { weight: u.weight });
|
|
476
|
+
if (await L.load(), L.status !== "loaded")
|
|
477
|
+
throw new Error(`Embedded font ${u.family} ${u.weight} did not load.`);
|
|
478
|
+
return { key: R, face: L };
|
|
171
479
|
})
|
|
172
480
|
);
|
|
173
|
-
},
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
let h = !1;
|
|
179
|
-
const C = () => {
|
|
180
|
-
F && (F.removeEventListener("message", E), F.removeEventListener("error", W), F.removeEventListener("messageerror", U), t?.removeEventListener("abort", H));
|
|
181
|
-
}, d = (k, D) => {
|
|
182
|
-
if (h) return;
|
|
183
|
-
h = !0;
|
|
184
|
-
const i = q;
|
|
185
|
-
i?.id === n && (q = void 0, v.clearTimeout(i.timer), i.cleanup()), D ? g(D) : S(k);
|
|
186
|
-
}, E = (k) => {
|
|
187
|
-
k.data?.id === n && d(k.data.result);
|
|
188
|
-
}, W = (k) => {
|
|
189
|
-
k.preventDefault(), z(new Error(k.message || "Viewer render worker failed."));
|
|
190
|
-
}, U = () => z(new Error("Viewer render worker returned an unreadable result.")), H = () => z(new Error("Viewer render was aborted."));
|
|
191
|
-
try {
|
|
192
|
-
F ??= c.execution?.mode === "worker" && c.execution.createWorker ? c.execution.createWorker() : new Worker(new URL(
|
|
193
|
-
/* @vite-ignore */
|
|
194
|
-
"" + new URL("assets/render.worker-fWW85Tf9.js", import.meta.url).href,
|
|
195
|
-
import.meta.url
|
|
196
|
-
), { type: "module" }), F.addEventListener("message", E), F.addEventListener("error", W), F.addEventListener("messageerror", U), t?.addEventListener("abort", H, { once: !0 });
|
|
197
|
-
const k = c.execution?.mode === "worker" ? c.execution.timeoutMs ?? 5e3 : 5e3, D = v.setTimeout(
|
|
198
|
-
() => z(new Error("Viewer render worker timed out.")),
|
|
199
|
-
k
|
|
200
|
-
);
|
|
201
|
-
q = { id: n, timer: D, finish: d, cleanup: C }, F.postMessage({ id: n, source: e, options: r });
|
|
202
|
-
} catch (k) {
|
|
203
|
-
z(
|
|
204
|
-
k instanceof Error ? k : new Error("Viewer render worker could not start.")
|
|
205
|
-
), g(k);
|
|
481
|
+
}, se = async (e, s, n) => {
|
|
482
|
+
const v = t.execution ?? { mode: "worker" };
|
|
483
|
+
if (v.mode === "main") {
|
|
484
|
+
const { renderSvg: A } = await import("./render-CFWEEKPT.js");
|
|
485
|
+
return A(e, { ...s, signal: n });
|
|
206
486
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
487
|
+
return ot(e, s, {
|
|
488
|
+
create: v.createWorker,
|
|
489
|
+
timeoutMs: v.timeoutMs,
|
|
490
|
+
signal: n
|
|
491
|
+
});
|
|
212
492
|
};
|
|
213
|
-
|
|
493
|
+
let _;
|
|
494
|
+
const Ce = (e) => {
|
|
495
|
+
const s = i.querySelector("svg"), n = s?.querySelector(":scope > rect");
|
|
496
|
+
return e === i || e === s || e === n;
|
|
497
|
+
}, ve = (e) => !(e.target instanceof c.Node) || !i.contains(e.target) || m.el.contains(e.target), qe = (e) => e.composedPath().some((s) => s instanceof c.Element && s.hasAttribute("data-draft-input"));
|
|
498
|
+
i.addEventListener(
|
|
214
499
|
"wheel",
|
|
215
500
|
(e) => {
|
|
216
|
-
e.preventDefault(),
|
|
501
|
+
qe(e) || (e.preventDefault(), K(e.deltaY < 0 ? 1.1 : 1 / 1.1));
|
|
217
502
|
},
|
|
218
503
|
{ passive: !1 }
|
|
219
|
-
),
|
|
220
|
-
!
|
|
504
|
+
), i.addEventListener("pointerdown", (e) => {
|
|
505
|
+
!Ce(e.target) || !k || (_ = {
|
|
221
506
|
pointerId: e.pointerId,
|
|
222
507
|
x: e.clientX,
|
|
223
508
|
y: e.clientY,
|
|
224
|
-
centerX:
|
|
225
|
-
centerY:
|
|
226
|
-
scale:
|
|
227
|
-
},
|
|
228
|
-
}),
|
|
229
|
-
|
|
509
|
+
centerX: x.centerX,
|
|
510
|
+
centerY: x.centerY,
|
|
511
|
+
scale: x.zoom
|
|
512
|
+
}, i.setPointerCapture(e.pointerId));
|
|
513
|
+
}), i.addEventListener("pointermove", (e) => {
|
|
514
|
+
_ && E(
|
|
515
|
+
{
|
|
516
|
+
centerX: _.centerX - (e.clientX - _.x) / _.scale,
|
|
517
|
+
centerY: _.centerY - (e.clientY - _.y) / _.scale,
|
|
518
|
+
zoom: x.zoom
|
|
519
|
+
},
|
|
520
|
+
"user",
|
|
521
|
+
!0
|
|
522
|
+
);
|
|
230
523
|
});
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
524
|
+
const be = () => {
|
|
525
|
+
if (_) {
|
|
233
526
|
try {
|
|
234
|
-
|
|
527
|
+
i.releasePointerCapture(_.pointerId);
|
|
235
528
|
} catch {
|
|
236
529
|
}
|
|
237
|
-
|
|
530
|
+
_ = void 0;
|
|
238
531
|
}
|
|
239
532
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
533
|
+
i.addEventListener("pointerup", be), i.addEventListener("pointercancel", be), i.addEventListener("click", (e) => {
|
|
534
|
+
if (ve(e)) return;
|
|
535
|
+
const s = e.target instanceof c.Element ? e.target : null, n = s?.closest("a[href]");
|
|
536
|
+
if (n && i.contains(n)) {
|
|
537
|
+
const O = n.querySelector("[data-id]")?.getAttribute("data-id"), u = n.getAttribute("href");
|
|
538
|
+
O && u && j("link", {
|
|
539
|
+
itemId: O,
|
|
540
|
+
href: u,
|
|
541
|
+
target: n.getAttribute("target") === "_blank" ? "_blank" : "_self",
|
|
248
542
|
preventDefault: () => e.preventDefault()
|
|
249
543
|
});
|
|
250
544
|
return;
|
|
251
545
|
}
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
}),
|
|
255
|
-
|
|
546
|
+
const v = s?.closest("[data-id]")?.getAttribute("data-id"), A = k?.items.find((O) => O.id === v);
|
|
547
|
+
A && j("itemactivate", { id: A.id, kind: A.kind, input: "pointer", revision: b });
|
|
548
|
+
}), i.addEventListener("contextmenu", (e) => {
|
|
549
|
+
if (ve(e)) return;
|
|
550
|
+
const n = (e.target instanceof c.Element ? e.target : null)?.closest("[data-id]")?.getAttribute("data-id") ?? null, v = n ? k?.items.find((A) => A.id === n) : void 0;
|
|
551
|
+
j("contextmenu", {
|
|
552
|
+
id: v?.id ?? null,
|
|
553
|
+
...v ? { kind: v.kind } : {},
|
|
554
|
+
clientX: e.clientX,
|
|
555
|
+
clientY: e.clientY,
|
|
556
|
+
preventDefault: () => e.preventDefault()
|
|
557
|
+
});
|
|
558
|
+
}), m.el.addEventListener("focusin", (e) => {
|
|
559
|
+
const s = e.target instanceof c.Node ? m.idOf(e.target) : void 0;
|
|
560
|
+
s && !m.pressed() && xe.reveal(s);
|
|
561
|
+
}), m.el.addEventListener("keydown", (e) => {
|
|
562
|
+
e.key === "Escape" && i.focus({ preventScroll: !0 });
|
|
563
|
+
}), m.el.addEventListener(
|
|
564
|
+
"draft-anchor-focus-lost",
|
|
565
|
+
() => i.focus({ preventScroll: !0 })
|
|
566
|
+
), i.addEventListener("keydown", (e) => {
|
|
567
|
+
e.target !== i || e.altKey || e.ctrlKey || e.metaKey || (e.key === "+" || e.key === "=" ? K(1.2) : e.key === "-" ? K(1 / 1.2) : e.key.toLowerCase() === "f" && T());
|
|
256
568
|
});
|
|
257
|
-
const
|
|
258
|
-
for (const [
|
|
259
|
-
|
|
569
|
+
const Ve = (e, s) => {
|
|
570
|
+
for (const [n, v] of G)
|
|
571
|
+
n !== e && v.resolve({ status: s, revision: n });
|
|
260
572
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
|
|
573
|
+
let me = () => {
|
|
574
|
+
};
|
|
575
|
+
const je = (e, s = {}) => {
|
|
576
|
+
const n = ++b;
|
|
577
|
+
if (M) return Promise.resolve({ status: "destroyed", revision: n });
|
|
578
|
+
Ve(n, "superseded"), me();
|
|
579
|
+
const v = new AbortController();
|
|
580
|
+
return me = () => v.abort(), new Promise((A) => {
|
|
581
|
+
let O = !1;
|
|
582
|
+
const u = (L) => {
|
|
583
|
+
if (O) return;
|
|
584
|
+
O = !0, s.signal?.removeEventListener("abort", R), G.delete(n);
|
|
585
|
+
const q = M ? { status: "destroyed", revision: n } : n !== b ? { status: "superseded", revision: n } : s.signal?.aborted ? { status: "aborted", revision: n } : L;
|
|
586
|
+
A(q);
|
|
587
|
+
}, R = () => {
|
|
588
|
+
v.abort(), u({ status: "aborted", revision: n });
|
|
589
|
+
};
|
|
590
|
+
if (G.set(n, { resolve: u }), s.signal?.aborted) {
|
|
591
|
+
R();
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
s.signal?.addEventListener("abort", R, { once: !0 });
|
|
595
|
+
const te = {
|
|
596
|
+
...t.render ?? {},
|
|
597
|
+
target: "inline",
|
|
598
|
+
idPrefix: N,
|
|
599
|
+
fonts: t.render?.fonts ?? "embed",
|
|
600
|
+
...s.state !== void 0 ? { state: s.state } : {}
|
|
601
|
+
};
|
|
602
|
+
se(e, te, v.signal).then(async (L) => {
|
|
603
|
+
if (M || n !== b || s.signal?.aborted) {
|
|
604
|
+
u({ status: "superseded", revision: n });
|
|
276
605
|
return;
|
|
277
606
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
if (!d.ok) {
|
|
292
|
-
X(t, d.diagnostics), n({ status: "error", revision: t, error: d });
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
let E;
|
|
296
|
-
try {
|
|
297
|
-
E = await oe(d.value.svg, C.fonts ?? "embed");
|
|
298
|
-
} catch (i) {
|
|
299
|
-
if (x || t !== m || r.signal?.aborted) {
|
|
300
|
-
n({
|
|
301
|
-
status: r.signal?.aborted ? "aborted" : "superseded",
|
|
302
|
-
revision: t
|
|
303
|
-
});
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const $ = K(
|
|
307
|
-
"environment",
|
|
308
|
-
"DRAFT_FONT_UNAVAILABLE",
|
|
309
|
-
i instanceof Error ? i.message : "Diagram fonts are unavailable."
|
|
310
|
-
);
|
|
311
|
-
X(t, $.diagnostics), n({ status: "error", revision: t, error: $ });
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (x || t !== m || r.signal?.aborted) {
|
|
315
|
-
n({ status: "superseded", revision: t });
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
let W;
|
|
319
|
-
try {
|
|
320
|
-
W = ge(s, d.value.svg, C.fonts !== "host");
|
|
321
|
-
} catch (i) {
|
|
322
|
-
const $ = i instanceof Error ? i.message : "Could not build safe SVG.", M = K("internal", "DRAFT_VIEWER_DOM", $);
|
|
323
|
-
X(t, M.diagnostics), n({ status: "error", revision: t, error: M });
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
const U = [];
|
|
327
|
-
try {
|
|
328
|
-
for (const i of E)
|
|
329
|
-
N.has(i.key) || (s.fonts.add(i.face), N.set(i.key, i.face), U.push(i));
|
|
330
|
-
} catch (i) {
|
|
331
|
-
for (const { key: M, face: Z } of U)
|
|
332
|
-
s.fonts.delete(Z), N.delete(M);
|
|
333
|
-
const $ = K(
|
|
334
|
-
"environment",
|
|
335
|
-
"DRAFT_FONT_UNAVAILABLE",
|
|
336
|
-
i instanceof Error ? i.message : "Loaded fonts could not be registered."
|
|
337
|
-
);
|
|
338
|
-
X(t, $.diagnostics), n({ status: "error", revision: t, error: $ });
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const H = !!u;
|
|
342
|
-
u = d.value, o.replaceChildren(W), w.replaceChildren(
|
|
343
|
-
...u.items.map((i) => {
|
|
344
|
-
const $ = s.createElement("li"), M = s.createElement("button");
|
|
345
|
-
M.type = "button";
|
|
346
|
-
const Z = i.label.trim() || (i.kind === "edge" ? `${i.from ?? "?"} to ${i.to ?? "?"}` : i.id);
|
|
347
|
-
return M.textContent = `${i.kind}: ${Z}`, M.dataset.itemId = i.id, M.addEventListener("click", () => {
|
|
348
|
-
L("itemactivate", {
|
|
349
|
-
id: i.id,
|
|
350
|
-
kind: i.kind,
|
|
351
|
-
input: "keyboard",
|
|
352
|
-
revision: t
|
|
353
|
-
});
|
|
354
|
-
const O = Array.from(o.querySelectorAll("[data-id]")).find(
|
|
355
|
-
(T) => T.getAttribute("data-id") === i.id
|
|
356
|
-
);
|
|
357
|
-
if (O) {
|
|
358
|
-
const T = O.getBoundingClientRect(), I = o.getBoundingClientRect();
|
|
359
|
-
(T.width || T.height) && I.width && I.height && (a = {
|
|
360
|
-
centerX: a.centerX + (T.left + T.width / 2 - (I.left + I.width / 2)) / a.zoom,
|
|
361
|
-
centerY: a.centerY + (T.top + T.height / 2 - (I.top + I.height / 2)) / a.zoom,
|
|
362
|
-
zoom: Math.max(1, a.zoom)
|
|
363
|
-
}, _ = !0, R(), L("camera", { camera: { ...a }, reason: "user" }));
|
|
364
|
-
}
|
|
365
|
-
}), $.append(M), $;
|
|
366
|
-
})
|
|
367
|
-
);
|
|
368
|
-
const k = new Set(E.map((i) => i.key));
|
|
369
|
-
for (const [i, $] of N)
|
|
370
|
-
k.has(i) || (s.fonts.delete($), N.delete(i));
|
|
371
|
-
l.classList.remove("draft-viewer--stale"), f.textContent = d.diagnostics.map((i) => i.message).join(" "), !H || r.camera === "fit" ? Y() : R();
|
|
372
|
-
const D = {
|
|
373
|
-
status: "committed",
|
|
374
|
-
revision: t,
|
|
375
|
-
value: u,
|
|
376
|
-
diagnostics: d.diagnostics
|
|
377
|
-
};
|
|
378
|
-
n(D), L("render", { revision: t, value: u }), L("diagnostics", { revision: t, diagnostics: d.diagnostics, stale: !1 });
|
|
379
|
-
}).catch((d) => {
|
|
380
|
-
if (x || t !== m || r.signal?.aborted) {
|
|
381
|
-
n({
|
|
382
|
-
status: r.signal?.aborted ? "aborted" : "superseded",
|
|
383
|
-
revision: t
|
|
607
|
+
if (!L.ok) {
|
|
608
|
+
B(n, L.diagnostics), u({ status: "error", revision: n, error: L });
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
let q, he;
|
|
612
|
+
try {
|
|
613
|
+
he = dt(r, L.value.svg), q = await oe(he, te.fonts ?? "embed");
|
|
614
|
+
} catch (y) {
|
|
615
|
+
if (M || n !== b || s.signal?.aborted) {
|
|
616
|
+
u({
|
|
617
|
+
status: s.signal?.aborted ? "aborted" : "superseded",
|
|
618
|
+
revision: n
|
|
384
619
|
});
|
|
385
620
|
return;
|
|
386
621
|
}
|
|
387
|
-
const
|
|
622
|
+
const V = de(
|
|
388
623
|
"environment",
|
|
389
|
-
"
|
|
390
|
-
|
|
624
|
+
"DRAFT_FONT_UNAVAILABLE",
|
|
625
|
+
y instanceof Error ? y.message : "Diagram fonts are unavailable."
|
|
391
626
|
);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
627
|
+
B(n, V.diagnostics), u({ status: "error", revision: n, error: V });
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (M || n !== b || s.signal?.aborted) {
|
|
631
|
+
u({ status: "superseded", revision: n });
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
let ge;
|
|
635
|
+
try {
|
|
636
|
+
ge = mt(r, he, te.fonts !== "host");
|
|
637
|
+
} catch (y) {
|
|
638
|
+
const V = y instanceof Error ? y.message : "Could not build safe SVG.", P = de("internal", "DRAFT_VIEWER_DOM", V);
|
|
639
|
+
B(n, P.diagnostics), u({ status: "error", revision: n, error: P });
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const ke = [];
|
|
643
|
+
try {
|
|
644
|
+
for (const y of q)
|
|
645
|
+
Y.has(y.key) || (st(r, y.key, y.face), Y.add(y.key), ke.push(y.key));
|
|
646
|
+
} catch (y) {
|
|
647
|
+
for (const P of ke)
|
|
648
|
+
pe(r, P), Y.delete(P);
|
|
649
|
+
const V = de(
|
|
650
|
+
"environment",
|
|
651
|
+
"DRAFT_FONT_UNAVAILABLE",
|
|
652
|
+
y instanceof Error ? y.message : "Loaded fonts could not be registered."
|
|
653
|
+
);
|
|
654
|
+
B(n, V.diagnostics), u({ status: "error", revision: n, error: V });
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const Xe = !!k;
|
|
658
|
+
k = L.value, z = k.geometry ? { ...k.geometry, revision: n } : null;
|
|
659
|
+
const Ae = i.querySelector(":scope > svg");
|
|
660
|
+
Ae ? Ae.replaceWith(ge) : i.prepend(ge), m.setGeometry(z);
|
|
661
|
+
const Se = p.getRootNode().activeElement, Le = p.contains(Se) ? Se.dataset.itemId : void 0;
|
|
662
|
+
p.replaceChildren(
|
|
663
|
+
...k.items.map((y) => {
|
|
664
|
+
const V = r.createElement("li"), P = r.createElement("button");
|
|
665
|
+
P.type = "button";
|
|
666
|
+
const Be = y.label.trim() || (y.kind === "edge" ? `${y.from ?? "?"} to ${y.to ?? "?"}` : y.id);
|
|
667
|
+
return P.textContent = `${y.kind}: ${Be}`, P.dataset.itemId = y.id, P.addEventListener("click", () => {
|
|
668
|
+
j("itemactivate", {
|
|
669
|
+
id: y.id,
|
|
670
|
+
kind: y.kind,
|
|
671
|
+
input: "keyboard",
|
|
672
|
+
revision: n
|
|
673
|
+
});
|
|
674
|
+
const Me = Array.from(i.querySelectorAll("[data-id]")).find(
|
|
675
|
+
(J) => J.getAttribute("data-id") === y.id
|
|
676
|
+
);
|
|
677
|
+
if (Me) {
|
|
678
|
+
const J = Me.getBoundingClientRect(), re = i.getBoundingClientRect();
|
|
679
|
+
(J.width || J.height) && re.width && re.height && E(
|
|
680
|
+
{
|
|
681
|
+
centerX: x.centerX + (J.left + J.width / 2 - (re.left + re.width / 2)) / x.zoom,
|
|
682
|
+
centerY: x.centerY + (J.top + J.height / 2 - (re.top + re.height / 2)) / x.zoom,
|
|
683
|
+
zoom: Math.max(1, x.zoom)
|
|
684
|
+
},
|
|
685
|
+
"user",
|
|
686
|
+
!0
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
}), V.append(P), V;
|
|
690
|
+
})
|
|
691
|
+
), Le !== void 0 && (Array.from(p.querySelectorAll("button")).find(
|
|
692
|
+
(V) => V.dataset.itemId === Le
|
|
693
|
+
) ?? i).focus({ preventScroll: !0 });
|
|
694
|
+
const Ye = new Set(q.map((y) => y.key));
|
|
695
|
+
for (const y of Y)
|
|
696
|
+
Ye.has(y) || (pe(r, y), Y.delete(y));
|
|
697
|
+
d.classList.remove("draft-viewer--stale"), f.textContent = L.diagnostics.map((y) => y.message).join(" "), F ? I(F) : !Xe || s.camera === "fit" ? T() : U();
|
|
698
|
+
const We = {
|
|
699
|
+
status: "committed",
|
|
700
|
+
revision: n,
|
|
701
|
+
value: k,
|
|
702
|
+
diagnostics: L.diagnostics
|
|
703
|
+
};
|
|
704
|
+
j("render", { revision: n, value: k, geometry: z }), ee = { revision: n, diagnostics: L.diagnostics, stale: !1 }, l(), ae(), u(We);
|
|
705
|
+
}).catch((L) => {
|
|
706
|
+
if (M || n !== b || s.signal?.aborted) {
|
|
707
|
+
u({
|
|
708
|
+
status: s.signal?.aborted ? "aborted" : "superseded",
|
|
709
|
+
revision: n
|
|
710
|
+
});
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const q = de(
|
|
714
|
+
"environment",
|
|
715
|
+
"DRAFT_VIEWER_WORKER",
|
|
716
|
+
L instanceof Error ? L.message : "Viewer render failed."
|
|
717
|
+
);
|
|
718
|
+
B(n, q.diagnostics), u({ status: "error", revision: n, error: q });
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
};
|
|
722
|
+
let le, Ee;
|
|
723
|
+
const Pe = new Promise((e) => Ee = e), xe = {
|
|
724
|
+
get ready() {
|
|
725
|
+
return le ?? Pe;
|
|
726
|
+
},
|
|
727
|
+
update: (e, s) => {
|
|
728
|
+
const n = je(e, s), v = n.then(
|
|
729
|
+
(A) => A.status === "superseded" && le !== v ? le : A
|
|
730
|
+
);
|
|
731
|
+
return le = v, v.then(Ee), n;
|
|
732
|
+
},
|
|
733
|
+
geometry: () => z,
|
|
734
|
+
anchor(e) {
|
|
735
|
+
if (M) return;
|
|
736
|
+
const s = m.warnings().length;
|
|
737
|
+
m.setSlots(e), U(), ae(), (m.warnings().length || s) && l();
|
|
395
738
|
},
|
|
396
|
-
on(e,
|
|
397
|
-
if (
|
|
739
|
+
on(e, s) {
|
|
740
|
+
if (M) return () => {
|
|
398
741
|
};
|
|
399
|
-
const
|
|
400
|
-
return
|
|
742
|
+
const n = Q.get(e) ?? /* @__PURE__ */ new Set();
|
|
743
|
+
return n.add(s), Q.set(e, n), () => n.delete(s);
|
|
401
744
|
},
|
|
402
|
-
getCamera: () => ({ ...
|
|
745
|
+
getCamera: () => ({ ...x }),
|
|
403
746
|
setCamera(e) {
|
|
404
|
-
|
|
405
|
-
},
|
|
406
|
-
fit: () => {
|
|
407
|
-
x || Y();
|
|
747
|
+
M || !Number.isFinite(e.centerX) || !Number.isFinite(e.centerY) || !Number.isFinite(e.zoom) || e.zoom <= 0 || E({ ...e }, "api", !0);
|
|
408
748
|
},
|
|
749
|
+
fit: (e, s) => S(e, s, "api"),
|
|
750
|
+
reveal: (e, s) => I(() => {
|
|
751
|
+
const n = W(e);
|
|
752
|
+
return n ? E(He(x, n, X, s), "api", !0) : "missing";
|
|
753
|
+
}),
|
|
409
754
|
focusItem(e) {
|
|
410
|
-
if (!
|
|
411
|
-
const
|
|
412
|
-
(
|
|
755
|
+
if (!k?.items.some((n) => n.id === e)) return !1;
|
|
756
|
+
const s = Array.from(p.querySelectorAll("button")).find(
|
|
757
|
+
(n) => n.dataset.itemId === e
|
|
413
758
|
);
|
|
414
|
-
return
|
|
759
|
+
return s?.focus(), !!s;
|
|
415
760
|
},
|
|
416
761
|
destroy() {
|
|
417
|
-
if (!
|
|
418
|
-
if (
|
|
762
|
+
if (!M) {
|
|
763
|
+
if (M = !0, b++, F = void 0, h && (c.cancelAnimationFrame ?? c.clearTimeout)(h), _) {
|
|
419
764
|
try {
|
|
420
|
-
|
|
765
|
+
i.releasePointerCapture(_.pointerId);
|
|
421
766
|
} catch {
|
|
422
767
|
}
|
|
423
|
-
|
|
768
|
+
_ = void 0;
|
|
424
769
|
}
|
|
425
|
-
for (const [e,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
for (const e of
|
|
429
|
-
|
|
770
|
+
for (const [e, s] of G)
|
|
771
|
+
s.resolve({ status: "destroyed", revision: e });
|
|
772
|
+
G.clear(), me();
|
|
773
|
+
for (const e of Y) pe(r, e);
|
|
774
|
+
Y.clear(), ce.disconnect(), j("anchors", { anchors: [] }), m.destroy(), Q.clear(), o.replaceChildren(), k = void 0;
|
|
430
775
|
}
|
|
431
776
|
}
|
|
432
777
|
};
|
|
778
|
+
return xe;
|
|
433
779
|
}
|
|
434
780
|
export {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
781
|
+
ze as ZOOM_MAX,
|
|
782
|
+
$e as ZOOM_MIN,
|
|
783
|
+
vt as fontMetricsVersion,
|
|
784
|
+
wt as mountViewer,
|
|
785
|
+
Et as runtimeVersion
|
|
438
786
|
};
|