@draftably/runtime 0.3.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.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/dist/assets/render.worker-D11vTqoO.js +8548 -0
  3. package/dist/compile-BAIrdu-8.js +7405 -0
  4. package/dist/element.js +275 -125
  5. package/dist/{font-data-DLXJur0j.js → font-data-DME3E71S.js} +1 -1
  6. package/dist/geometry-DfUVE8b2.js +79 -0
  7. package/dist/graph.js +336 -373
  8. package/dist/host.css +37 -0
  9. package/dist/host.js +24 -0
  10. package/dist/index.js +3 -3
  11. package/dist/render-CsJYFD3o.js +1188 -0
  12. package/dist/types/src/dsl/cells.d.ts +1 -0
  13. package/dist/types/src/dsl/compile.d.ts +2 -1
  14. package/dist/types/src/dsl/legend-notes.d.ts +14 -0
  15. package/dist/types/src/dsl/syntax.d.ts +2 -0
  16. package/dist/types/src/model/appearance.d.ts +27 -1
  17. package/dist/types/src/model/colors.d.ts +10 -2
  18. package/dist/types/src/model/labels.d.ts +22 -6
  19. package/dist/types/src/runtime/anchors.d.ts +46 -0
  20. package/dist/types/src/runtime/camera.d.ts +41 -0
  21. package/dist/types/src/runtime/color-scheme.d.ts +15 -0
  22. package/dist/types/src/runtime/element-base.d.ts +40 -0
  23. package/dist/types/src/runtime/element.d.ts +7 -0
  24. package/dist/types/src/runtime/geometry.d.ts +72 -0
  25. package/dist/types/src/runtime/host.d.ts +78 -0
  26. package/dist/types/src/runtime/index.d.ts +1 -0
  27. package/dist/types/src/runtime/page-shared.d.ts +24 -0
  28. package/dist/types/src/runtime/schemes.d.ts +2 -0
  29. package/dist/types/src/runtime/svg-renderer.d.ts +12 -0
  30. package/dist/types/src/runtime/types.d.ts +13 -0
  31. package/dist/types/src/runtime/viewer.d.ts +41 -7
  32. package/dist/version-CO7i33cq.js +4 -0
  33. package/dist/viewer.css +72 -9
  34. package/dist/viewer.js +713 -346
  35. package/package.json +6 -1
  36. package/dist/assets/render.worker-dvseyGmC.js +0 -8310
  37. package/dist/compile-Csfz4rk4.js +0 -7267
  38. package/dist/render-Dgo42PR4.js +0 -1146
package/dist/element.js CHANGED
@@ -1,131 +1,281 @@
1
- import { mountViewer as a } from "./viewer.js";
2
- const d = ".draft-viewer{--dv-border: #cbd5e1;--dv-ink: #1e293b;--dv-bg: #fff;position:relative;display:grid;grid-template-rows:auto minmax(8rem,1fr) auto auto;box-sizing:border-box;height:100%;min-height:16rem;border:1px solid var(--dv-border);border-radius:.5rem;color:var(--dv-ink);background:var(--dv-bg);font:14px/1.45 system-ui,sans-serif;overflow:hidden}.draft-viewer__toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;padding:.5rem;border-bottom:1px solid var(--dv-border)}.draft-viewer__toolbar button{font:inherit;padding:.25rem .55rem;border:1px solid var(--dv-border);border-radius:.3rem;background:var(--dv-bg);color:inherit}.draft-viewer button:focus-visible,.draft-viewer__viewport:focus-visible{outline:3px solid #2563eb;outline-offset:2px}.draft-viewer__viewport{position:relative;overflow:hidden;min-height:8rem;touch-action:none;cursor:grab}.draft-viewer__viewport:active{cursor:grabbing}.draft-viewer__viewport svg{position:absolute;left:0;top:0;overflow:visible}.draft-viewer__status{margin:0;padding:.35rem .65rem}.draft-viewer__outline{margin:0;padding:.4rem .8rem .6rem 2rem;max-height:7rem;overflow:auto;border-top:1px solid var(--dv-border)}.draft-viewer__outline:empty{display:none}.draft-viewer--outline-hidden .draft-viewer__outline:not(:focus-within){position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}.draft-viewer--outline-hidden .draft-viewer__outline:focus-within{position:absolute;inset:auto 0 0;background:var(--dv-bg);box-shadow:0 -4px 12px #0f172a1f}.draft-viewer--stale .draft-viewer__status{color:#9a3412;background:#fff7ed}.draft-viewer__status:empty{display:none}@media(prefers-reduced-motion:reduce){.draft-viewer *{scroll-behavior:auto!important;transition:none!important}}@media(max-width:600px){.draft-viewer__toolbar{gap:.3rem}.draft-viewer__toolbar button{padding-inline:.45rem}}", o = "draft-diagram";
3
- if (typeof globalThis.document < "u" && typeof globalThis.customElements < "u" && !customElements.get(o)) {
4
- class n extends HTMLElement {
5
- static get observedAttributes() {
6
- return ["source", "state", "label", "outline"];
7
- }
8
- _options = {};
9
- _viewer;
10
- _updateComplete = Promise.resolve(void 0);
11
- _host;
12
- _fallback;
13
- _status;
14
- _style;
15
- _generation = 0;
16
- _revision = 0;
17
- _pendingSource;
18
- _pendingOutline;
19
- _hasCommitted = !1;
20
- constructor() {
21
- super();
22
- const t = Object.hasOwn(this, "source") ? this.source : void 0, e = Object.hasOwn(this, "options") ? this.options : void 0, s = Object.hasOwn(this, "outline") ? this.outline : void 0;
23
- delete this.source, delete this.outline, delete this.options, this.attachShadow({ mode: "open" }), this._style = this.ownerDocument.createElement("style"), this._style.textContent = `${d}
24
- :host{display:block;height:26rem;min-height:16rem;box-sizing:border-box}.draft-diagram__viewer{height:100%;min-height:0}.draft-diagram__viewer[hidden]{display:none}.draft-diagram__fallback{display:block}.draft-diagram__fallback[hidden]{display:none}.draft-diagram__status{margin:.35rem 0;color:#9a3412;font:14px/1.45 system-ui,sans-serif}.draft-diagram__status:empty{display:none}`, this._host = this.ownerDocument.createElement("div"), this._host.className = "draft-diagram__viewer", this._host.hidden = !0, this._fallback = this.ownerDocument.createElement("slot"), this._fallback.className = "draft-diagram__fallback", this._status = this.ownerDocument.createElement("p"), this._status.className = "draft-diagram__status", this._status.setAttribute("role", "status"), this._status.setAttribute("aria-live", "polite"), this.shadowRoot.append(this._host, this._fallback, this._status), e && (this._options = e), s && (this._pendingOutline = s), t !== void 0 && (this._pendingSource = String(t ?? ""));
25
- }
26
- get source() {
27
- return this.getAttribute("source") ?? "";
28
- }
29
- set source(t) {
30
- const e = String(t ?? "");
31
- this.getAttribute("source") !== e && this.setAttribute("source", e);
32
- }
33
- get outline() {
34
- const t = this.getAttribute("outline");
35
- return t === null ? void 0 : t === "visible" ? "visible" : "hidden";
36
- }
37
- set outline(t) {
38
- t == null ? this.removeAttribute("outline") : this.getAttribute("outline") !== t && this.setAttribute("outline", t);
39
- }
40
- get options() {
41
- return this._options;
42
- }
43
- set options(t) {
44
- this._options = t ?? {}, this.isConnected && this._mount(!0);
45
- }
46
- get viewer() {
47
- return this._viewer;
48
- }
49
- get updateComplete() {
50
- return this._updateComplete;
1
+ import { CANCELABLE_EVENTS as x } from "./host.js";
2
+ import { HOST_EVENTS as F } from "./host.js";
3
+ import { r as p } from "./version-CO7i33cq.js";
4
+ import { mountViewer as C } from "./viewer.js";
5
+ const S = ".draft-viewer{--dv-border: var(--draft-border, light-dark(#cbd5e1, #3d4450));--dv-ink: var(--draft-ink, light-dark(#1e293b, #e7eaef));--dv-bg: var(--draft-bg, light-dark(#fff, #16191e));--dv-focus: var(--draft-focus, light-dark(#2563eb, #7fa4e6));--dv-shadow: var(--draft-shadow, light-dark(rgb(15 23 42 / .12), rgb(0 0 0 / .4)));--dv-warning-ink: var(--draft-warning-ink, light-dark(#9a3412, #fdba74));--dv-warning-bg: var(--draft-warning-bg, light-dark(#fff7ed, #431407));position:relative;display:grid;grid-template-rows:auto minmax(8rem,1fr) auto auto;box-sizing:border-box;height:100%;min-height:16rem;border:1px solid var(--dv-border);border-radius:.5rem;color:var(--dv-ink);background:var(--dv-bg);font:14px/1.45 system-ui,sans-serif;overflow:clip}.draft-viewer__toolbar[hidden]{display:none}.draft-viewer__toolbar{grid-row:1;display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;padding:.5rem;border-bottom:1px solid var(--dv-border)}.draft-viewer__toolbar button{font:inherit;padding:.25rem .55rem;border:1px solid var(--dv-border);border-radius:.3rem;background:var(--dv-bg);color:inherit}.draft-viewer button:focus-visible,.draft-viewer__viewport:focus-visible{outline:3px solid var(--dv-focus);outline-offset:2px}.draft-viewer__viewport{grid-row:2;position:relative;overflow:clip;min-height:8rem;touch-action:none;cursor:grab}.draft-viewer__viewport:active{cursor:grabbing}.draft-viewer__viewport svg{position:absolute;left:0;top:0;overflow:visible}.draft-viewer__status{grid-row:3;margin:0;padding:.35rem .65rem}.draft-viewer__outline{grid-row:4;margin:0;padding:.4rem .8rem .6rem 2rem;max-height:7rem;overflow:auto;border-top:1px solid var(--dv-border)}.draft-viewer__outline:empty{display:none}.draft-viewer--outline-hidden .draft-viewer__outline:not(:focus-within){position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}.draft-viewer--outline-hidden .draft-viewer__outline:focus-within{position:absolute;inset:auto 0 0;background:var(--dv-bg);box-shadow:0 -4px 12px var(--dv-shadow)}.draft-viewer--stale .draft-viewer__status{color:var(--dv-warning-ink);background:var(--dv-warning-bg)}.draft-viewer__status:empty{display:none}@media(prefers-reduced-motion:reduce){.draft-viewer *{scroll-behavior:auto!important;transition:none!important}}@media(max-width:600px){.draft-viewer__toolbar{gap:.3rem}.draft-viewer__toolbar button{padding-inline:.45rem}}.draft-anchors{position:absolute;inset:0;pointer-events:none;overflow:visible}.draft-anchors__bodies{position:absolute;left:0;top:0;width:0;height:0;transform-origin:0 0}.draft-anchors__overlays{position:absolute;inset:0}.draft-anchor{position:absolute;box-sizing:border-box;pointer-events:none}.draft-anchor [data-draft-input]{pointer-events:auto}.draft-anchor--body{overflow:clip}.draft-anchor--overlay{left:0;top:0;overflow:visible}.draft-anchors[data-draft-detail=low] .draft-anchors__bodies{visibility:hidden}.draft-viewer__viewport[data-draft-detail=full] [data-draft-body] text{opacity:0}";
6
+ function v(i, r) {
7
+ if (i === r || typeof i == "function" && typeof r == "function") return !0;
8
+ if (!i || !r || typeof i != "object" || typeof r != "object" || Array.isArray(i) !== Array.isArray(r)) return !1;
9
+ const t = Object.keys(i).filter((s) => i[s] !== void 0), e = Object.keys(r).filter((s) => r[s] !== void 0);
10
+ return t.length === e.length && t.every((s) => v(i[s], r[s]));
11
+ }
12
+ function _(i, r) {
13
+ if (!Object.hasOwn(i, r)) return;
14
+ const t = i[r];
15
+ return delete i[r], t;
16
+ }
17
+ function E(i) {
18
+ const r = customElements.get(i)?.runtimeVersion;
19
+ r !== p && console.warn(
20
+ `<${i}> is already defined by @draftably runtime ${r ?? "unknown"}; this copy (${p}) is not used. Install one copy of the runtime.`
21
+ );
22
+ }
23
+ function u(i, r, t) {
24
+ return i.dispatchEvent(
25
+ new CustomEvent(`draft-${r}`, {
26
+ detail: t,
27
+ bubbles: !0,
28
+ cancelable: x.includes(r)
29
+ })
30
+ );
31
+ }
32
+ function A(i, r, t) {
33
+ return {
34
+ status: "error",
35
+ revision: i,
36
+ error: {
37
+ ok: !1,
38
+ reason: "environment",
39
+ diagnostics: [
40
+ {
41
+ code: "DRAFT_ELEMENT_MOUNT",
42
+ severity: "error",
43
+ message: r instanceof Error ? r.message : t,
44
+ itemIds: []
45
+ }
46
+ ]
51
47
  }
52
- connectedCallback() {
53
- if (this._pendingOutline && (this.outline = this._pendingOutline, this._pendingOutline = void 0), this._pendingSource !== void 0) {
54
- const t = this._pendingSource;
55
- this._pendingSource = void 0, this.setAttribute("source", t);
48
+ };
49
+ }
50
+ const y = /* @__PURE__ */ new WeakMap();
51
+ function N(i, r, t) {
52
+ const e = i.defaultView;
53
+ if (!e || !("adoptedStyleSheets" in e.ShadowRoot.prototype) || !("replaceSync" in e.CSSStyleSheet.prototype))
54
+ return;
55
+ const s = y.get(i) ?? /* @__PURE__ */ new Map();
56
+ y.set(i, s);
57
+ let o = s.get(r);
58
+ return o || (o = new e.CSSStyleSheet(), o.replaceSync(t), s.set(r, o)), o;
59
+ }
60
+ function M(i, r, t) {
61
+ if (!("preventDefault" in t)) return void u(i, r, t);
62
+ const { preventDefault: e, ...s } = t;
63
+ u(i, r, s) || e();
64
+ }
65
+ function D(i, r, t) {
66
+ const e = i.ownerDocument, s = typeof HTMLSlotElement < "u" && "assign" in HTMLSlotElement.prototype, o = /* @__PURE__ */ new WeakMap();
67
+ let n = /* @__PURE__ */ new Map(), m = [];
68
+ const b = () => {
69
+ if (s)
70
+ for (const a of m) {
71
+ let d = o.get(a.el);
72
+ d || (d = e.createElement("slot"), a.el.append(d), o.set(a.el, d)), d.assign(...n.get(a.slot) ?? []);
56
73
  }
57
- this._mount(!1);
58
- }
59
- disconnectedCallback() {
60
- this._reset(), this._style.remove();
74
+ }, c = () => {
75
+ const a = [...n.keys()].join(`
76
+ `);
77
+ n = /* @__PURE__ */ new Map();
78
+ const d = [];
79
+ for (const l of i.childNodes) {
80
+ const f = l instanceof Element ? l.getAttribute("data-draft-slot") : null;
81
+ f ? n.set(f, [...n.get(f) ?? [], l]) : (l instanceof Element || l instanceof Text && l.data.trim()) && d.push(l);
61
82
  }
62
- _reset() {
63
- this._generation++, this._viewer?.destroy(), this._viewer = void 0, this._host.replaceChildren(), this._host.hidden = !0, this._fallback.hidden = !1, this._status.textContent = "", this._hasCommitted = !1;
64
- }
65
- attributeChangedCallback(t) {
66
- t === "source" ? this.isConnected && (this._viewer && this.source.trim() ? this._update() : this._mount(!0)) : this.isConnected && t === "state" ? this._update() : this.isConnected && (t === "label" || t === "outline") && this._mount(!0);
67
- }
68
- _mount(t) {
69
- if (!this.isConnected || (t && this._reset(), this._viewer)) return;
70
- const e = {
71
- ...this._options,
72
- ...this.hasAttribute("label") ? { label: this.getAttribute("label") } : {},
73
- ...this.outline ? { outline: this.outline } : {}
74
- }, s = e.render?.styleNonce;
75
- if (this._style.remove(), s ? this._style.setAttribute("nonce", s) : this._style.removeAttribute("nonce"), this.shadowRoot.prepend(this._style), !this.source.trim()) {
76
- this._updateComplete = Promise.resolve(void 0);
77
- return;
78
- }
79
- try {
80
- this._viewer = a(this._host, e);
81
- } catch (i) {
82
- this._mountFailure(i);
83
- return;
84
- }
85
- this._update();
86
- }
87
- _mountFailure(t) {
88
- const e = {
89
- status: "error",
90
- revision: ++this._revision,
91
- error: {
92
- ok: !1,
93
- reason: "environment",
94
- diagnostics: [
95
- {
96
- code: "DRAFT_ELEMENT_MOUNT",
97
- severity: "error",
98
- message: t instanceof Error ? t.message : "Diagram viewer could not start.",
99
- itemIds: []
100
- }
101
- ]
83
+ s && r?.assign(...d), [...n.keys()].join(`
84
+ `) !== a && t([...n.keys()]), b();
85
+ }, g = new MutationObserver(c), w = new MutationObserver((a) => {
86
+ a.some((d) => d.target.parentNode === i) && c();
87
+ });
88
+ return {
89
+ start() {
90
+ g.observe(i, { childList: !0 }), w.observe(i, {
91
+ subtree: !0,
92
+ attributes: !0,
93
+ attributeFilter: ["data-draft-slot"]
94
+ }), n = /* @__PURE__ */ new Map(), c();
95
+ },
96
+ stop() {
97
+ g.disconnect(), w.disconnect();
98
+ },
99
+ /** The handle's targets changed: put each slot's children in its target. */
100
+ setAnchors(a) {
101
+ m = a, b();
102
+ },
103
+ names: () => [...n.keys()]
104
+ };
105
+ }
106
+ const h = "draft-diagram", k = `${S}
107
+ :host{display:block;height:26rem;min-height:16rem;box-sizing:border-box}.draft-diagram__viewer{height:100%;min-height:0}.draft-diagram__viewer[hidden]{display:none}.draft-diagram__fallback{display:block}.draft-diagram__fallback[hidden]{display:none}.draft-diagram__status{margin:.35rem 0;color:var(--draft-warning-ink,#9a3412);font:14px/1.45 system-ui,sans-serif}.draft-diagram__status:empty{display:none}`, T = [
108
+ "anchors",
109
+ "render",
110
+ "diagnostics",
111
+ "camera",
112
+ "itemactivate",
113
+ "link",
114
+ "contextmenu"
115
+ ];
116
+ if (typeof globalThis.document < "u" && typeof globalThis.customElements < "u")
117
+ if (customElements.get(h)) E(h);
118
+ else {
119
+ class i extends HTMLElement {
120
+ static runtimeVersion = p;
121
+ static get observedAttributes() {
122
+ return ["source", "state", "label", "outline"];
123
+ }
124
+ _options = {};
125
+ /** The options object the viewer reads; changed in place for live fields. */
126
+ _live = {};
127
+ _viewer;
128
+ _updateComplete = Promise.resolve(void 0);
129
+ _host;
130
+ _fallback;
131
+ _status;
132
+ /** Only where the browser cannot adopt a shared sheet. */
133
+ _style;
134
+ _generation = 0;
135
+ _revision = 0;
136
+ _scheduled = !1;
137
+ _hasCommitted = !1;
138
+ _slotting;
139
+ constructor() {
140
+ super();
141
+ const t = _(this, "source"), e = _(this, "options"), s = _(this, "outline");
142
+ this.attachShadow({ mode: "open", slotAssignment: "manual" }), this._host = this.ownerDocument.createElement("div"), this._host.className = "draft-diagram__viewer", this._host.hidden = !0, this._fallback = this.ownerDocument.createElement("slot"), this._fallback.className = "draft-diagram__fallback", this._status = this.ownerDocument.createElement("p"), this._status.className = "draft-diagram__status", this._status.setAttribute("role", "status"), this._status.setAttribute("aria-live", "polite");
143
+ const o = N(this.ownerDocument, h, k);
144
+ o ? this.shadowRoot.adoptedStyleSheets = [o] : (this._style = this.ownerDocument.createElement("style"), this._style.textContent = k, this.shadowRoot.append(this._style)), this.shadowRoot.append(this._host, this._fallback, this._status), this._slotting = D(
145
+ this,
146
+ this._fallback,
147
+ (n) => this._viewer?.anchor(n)
148
+ ), e && (this._options = e), s && (this.outline = s), t !== void 0 && (this.source = t);
149
+ }
150
+ get source() {
151
+ return this.getAttribute("source") ?? "";
152
+ }
153
+ set source(t) {
154
+ const e = String(t ?? "");
155
+ this.getAttribute("source") !== e && this.setAttribute("source", e);
156
+ }
157
+ get outline() {
158
+ const t = this.getAttribute("outline");
159
+ return t === null ? void 0 : t === "visible" ? "visible" : "hidden";
160
+ }
161
+ set outline(t) {
162
+ t == null ? this.removeAttribute("outline") : this.getAttribute("outline") !== t && this.setAttribute("outline", t);
163
+ }
164
+ get options() {
165
+ return this._options;
166
+ }
167
+ set options(t) {
168
+ const e = this._options, s = t ?? {};
169
+ if (this._options = s, !this._viewer) return;
170
+ if (!v(e.execution, s.execution) || (e.render?.fonts ?? "embed") !== (s.render?.fonts ?? "embed")) {
171
+ this._reset(), this._schedule();
172
+ return;
102
173
  }
103
- };
104
- this._status.textContent = e.error.diagnostics[0].message, this._updateComplete = Promise.resolve(e), this.dispatchEvent(
105
- new CustomEvent("draft-update", { detail: e, bubbles: !0 })
106
- );
107
- }
108
- _update() {
109
- const t = this._viewer;
110
- if (!t || !this.isConnected) return;
111
- const e = ++this._generation;
112
- this._revision++;
113
- const s = t.update(this.source, { state: this.getAttribute("state") });
114
- this._updateComplete = s.then((i) => {
115
- if (e !== this._generation || !this.isConnected || t !== this._viewer)
116
- return i;
117
- if (i?.status === "committed") {
118
- const r = !this._hasCommitted;
119
- this._hasCommitted = !0, this._host.hidden = !1, this._fallback.hidden = !0, this._status.textContent = "", r && t.fit();
120
- } else if (i?.status === "error")
121
- this._status.textContent = this._hasCommitted ? "" : i.error.diagnostics.map((r) => r.message).join(" ");
122
- else
123
- return i;
124
- return this.dispatchEvent(
125
- new CustomEvent("draft-update", { detail: i, bubbles: !0 })
126
- ), i;
127
- });
174
+ const o = !v(e.render, s.render);
175
+ this._applyLive(), o && this._update();
176
+ }
177
+ get viewer() {
178
+ return this._viewer;
179
+ }
180
+ get updateComplete() {
181
+ return this._updateComplete;
182
+ }
183
+ connectedCallback() {
184
+ this._slotting.start(), this._schedule();
185
+ }
186
+ disconnectedCallback() {
187
+ this._slotting.stop(), this._reset(), this.removeAttribute("status");
188
+ }
189
+ attributeChangedCallback(t) {
190
+ this.isConnected && (t === "source" ? this._viewer && this.source.trim() ? this._update() : (this._reset(), this._schedule()) : t === "state" ? this._update() : this._applyLive());
191
+ }
192
+ /** Mount once, in a microtask, so every property a framework sets in this tick lands first. */
193
+ _schedule() {
194
+ if (this._scheduled) return;
195
+ this._scheduled = !0;
196
+ const t = new Promise(
197
+ (e) => queueMicrotask(() => {
198
+ this._scheduled = !1, this._mount(), e(this._updateComplete === t ? void 0 : this._updateComplete);
199
+ })
200
+ );
201
+ this._updateComplete = t;
202
+ }
203
+ _setStatus(t) {
204
+ t ? this.setAttribute("status", t) : this.removeAttribute("status");
205
+ }
206
+ _reset() {
207
+ this._generation++, this._viewer?.destroy(), this._viewer = void 0, this._host.replaceChildren(), this._host.hidden = !0, this._fallback.hidden = !1, this._status.textContent = "", this._hasCommitted = !1;
208
+ }
209
+ /** The options with the element's own attributes on top. */
210
+ _merged() {
211
+ return {
212
+ ...this._options,
213
+ ...this.hasAttribute("label") ? { label: this.getAttribute("label") } : {},
214
+ ...this.outline ? { outline: this.outline } : {}
215
+ };
216
+ }
217
+ /** Apply label, outline, toolbar and render settings without a new viewer. */
218
+ _applyLive() {
219
+ if (!this._viewer) return;
220
+ const t = this._merged();
221
+ for (const o of Object.keys(this._live))
222
+ delete this._live[o];
223
+ Object.assign(this._live, t);
224
+ const e = this._host.querySelector(".draft-viewer");
225
+ if (!e) return;
226
+ e.setAttribute("aria-label", t.label ?? "Diagram viewer"), e.querySelector(".draft-viewer__viewport")?.setAttribute("aria-label", t.label ?? "Diagram"), e.classList.toggle("draft-viewer--outline-hidden", t.outline !== "visible");
227
+ const s = e.querySelector(".draft-viewer__toolbar");
228
+ s && (s.hidden = t.toolbar === !1), this._setNonce();
229
+ }
230
+ _setNonce() {
231
+ const t = this._options.render?.styleNonce;
232
+ t ? this._style?.setAttribute("nonce", t) : this._style?.removeAttribute("nonce");
233
+ }
234
+ _mount() {
235
+ if (!this.isConnected || this._viewer) return;
236
+ if (this._setNonce(), !this.source.trim()) {
237
+ this._setStatus(null), this._updateComplete = Promise.resolve(void 0);
238
+ return;
239
+ }
240
+ this._setStatus("loading"), this._live = this._merged();
241
+ try {
242
+ this._viewer = C(this._host, this._live);
243
+ } catch (e) {
244
+ this._mountFailure(e);
245
+ return;
246
+ }
247
+ const t = this._viewer;
248
+ for (const e of T)
249
+ t.on(e, (s) => {
250
+ t === this._viewer && M(this, e, s);
251
+ });
252
+ t.on("anchors", ({ anchors: e }) => this._slotting.setAnchors(e)), t.anchor(this._slotting.names()), this._update();
253
+ }
254
+ _mountFailure(t) {
255
+ const e = A(++this._revision, t, "Diagram viewer could not start.");
256
+ this._status.textContent = e.error.diagnostics[0].message, this._setStatus("error"), this._updateComplete = Promise.resolve(e), u(this, "update", e);
257
+ }
258
+ _update() {
259
+ const t = this._viewer;
260
+ if (!t || !this.isConnected) return;
261
+ const e = ++this._generation;
262
+ this._revision++;
263
+ const s = t.update(this.source, { state: this.getAttribute("state") });
264
+ this._updateComplete = s.then((o) => {
265
+ if (e !== this._generation || !this.isConnected || t !== this._viewer)
266
+ return o;
267
+ if (o?.status === "committed")
268
+ this._hasCommitted = !0, this._host.hidden = !1, this._fallback.hidden = !0, this._status.textContent = "", this._setStatus("ready");
269
+ else if (o?.status === "error")
270
+ this._status.textContent = this._hasCommitted ? "" : o.error.diagnostics.map((n) => n.message).join(" "), this._hasCommitted || this._setStatus("error");
271
+ else
272
+ return o;
273
+ return u(this, "update", o), o;
274
+ });
275
+ }
128
276
  }
277
+ customElements.define(h, i);
129
278
  }
130
- customElements.define(o, n);
131
- }
279
+ export {
280
+ F as HOST_EVENTS
281
+ };