@niivue/nv-web-component 1.0.0-rc.2 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1363 @@
1
+ import e, { DRAG_MODE as t, DRAG_MODE as n, SHOW_RENDER as r, SLICE_TYPE as i, SLICE_TYPE as a } from "@niivue/niivue";
2
+ //#region ../../node_modules/@lit/reactive-element/css-tag.js
3
+ var o = globalThis, s = o.ShadowRoot && (o.ShadyCSS === void 0 || o.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, c = Symbol(), l = /* @__PURE__ */ new WeakMap(), u = class {
4
+ constructor(e, t, n) {
5
+ if (this._$cssResult$ = !0, n !== c) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
6
+ this.cssText = e, this.t = t;
7
+ }
8
+ get styleSheet() {
9
+ let e = this.o, t = this.t;
10
+ if (s && e === void 0) {
11
+ let n = t !== void 0 && t.length === 1;
12
+ n && (e = l.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), n && l.set(t, e));
13
+ }
14
+ return e;
15
+ }
16
+ toString() {
17
+ return this.cssText;
18
+ }
19
+ }, d = (e) => new u(typeof e == "string" ? e : e + "", void 0, c), ee = (e, ...t) => new u(e.length === 1 ? e[0] : t.reduce((t, n, r) => t + ((e) => {
20
+ if (!0 === e._$cssResult$) return e.cssText;
21
+ if (typeof e == "number") return e;
22
+ throw Error("Value passed to 'css' function must be a 'css' function result: " + e + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
23
+ })(n) + e[r + 1], e[0]), e, c), te = (e, t) => {
24
+ if (s) e.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
25
+ else for (let n of t) {
26
+ let t = document.createElement("style"), r = o.litNonce;
27
+ r !== void 0 && t.setAttribute("nonce", r), t.textContent = n.cssText, e.appendChild(t);
28
+ }
29
+ }, f = s ? (e) => e : (e) => e instanceof CSSStyleSheet ? ((e) => {
30
+ let t = "";
31
+ for (let n of e.cssRules) t += n.cssText;
32
+ return d(t);
33
+ })(e) : e, { is: ne, defineProperty: re, getOwnPropertyDescriptor: ie, getOwnPropertyNames: ae, getOwnPropertySymbols: oe, getPrototypeOf: se } = Object, p = globalThis, ce = p.trustedTypes, le = ce ? ce.emptyScript : "", ue = p.reactiveElementPolyfillSupport, m = (e, t) => e, h = {
34
+ toAttribute(e, t) {
35
+ switch (t) {
36
+ case Boolean:
37
+ e = e ? le : null;
38
+ break;
39
+ case Object:
40
+ case Array: e = e == null ? e : JSON.stringify(e);
41
+ }
42
+ return e;
43
+ },
44
+ fromAttribute(e, t) {
45
+ let n = e;
46
+ switch (t) {
47
+ case Boolean:
48
+ n = e !== null;
49
+ break;
50
+ case Number:
51
+ n = e === null ? null : Number(e);
52
+ break;
53
+ case Object:
54
+ case Array: try {
55
+ n = JSON.parse(e);
56
+ } catch {
57
+ n = null;
58
+ }
59
+ }
60
+ return n;
61
+ }
62
+ }, g = (e, t) => !ne(e, t), _ = {
63
+ attribute: !0,
64
+ type: String,
65
+ converter: h,
66
+ reflect: !1,
67
+ useDefault: !1,
68
+ hasChanged: g
69
+ };
70
+ Symbol.metadata ??= Symbol("metadata"), p.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
71
+ var v = class extends HTMLElement {
72
+ static addInitializer(e) {
73
+ this._$Ei(), (this.l ??= []).push(e);
74
+ }
75
+ static get observedAttributes() {
76
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
77
+ }
78
+ static createProperty(e, t = _) {
79
+ if (t.state && (t.attribute = !1), this._$Ei(), this.prototype.hasOwnProperty(e) && ((t = Object.create(t)).wrapped = !0), this.elementProperties.set(e, t), !t.noAccessor) {
80
+ let n = Symbol(), r = this.getPropertyDescriptor(e, n, t);
81
+ r !== void 0 && re(this.prototype, e, r);
82
+ }
83
+ }
84
+ static getPropertyDescriptor(e, t, n) {
85
+ let { get: r, set: i } = ie(this.prototype, e) ?? {
86
+ get() {
87
+ return this[t];
88
+ },
89
+ set(e) {
90
+ this[t] = e;
91
+ }
92
+ };
93
+ return {
94
+ get: r,
95
+ set(t) {
96
+ let a = r?.call(this);
97
+ i?.call(this, t), this.requestUpdate(e, a, n);
98
+ },
99
+ configurable: !0,
100
+ enumerable: !0
101
+ };
102
+ }
103
+ static getPropertyOptions(e) {
104
+ return this.elementProperties.get(e) ?? _;
105
+ }
106
+ static _$Ei() {
107
+ if (this.hasOwnProperty(m("elementProperties"))) return;
108
+ let e = se(this);
109
+ e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties);
110
+ }
111
+ static finalize() {
112
+ if (this.hasOwnProperty(m("finalized"))) return;
113
+ if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(m("properties"))) {
114
+ let e = this.properties, t = [...ae(e), ...oe(e)];
115
+ for (let n of t) this.createProperty(n, e[n]);
116
+ }
117
+ let e = this[Symbol.metadata];
118
+ if (e !== null) {
119
+ let t = litPropertyMetadata.get(e);
120
+ if (t !== void 0) for (let [e, n] of t) this.elementProperties.set(e, n);
121
+ }
122
+ this._$Eh = /* @__PURE__ */ new Map();
123
+ for (let [e, t] of this.elementProperties) {
124
+ let n = this._$Eu(e, t);
125
+ n !== void 0 && this._$Eh.set(n, e);
126
+ }
127
+ this.elementStyles = this.finalizeStyles(this.styles);
128
+ }
129
+ static finalizeStyles(e) {
130
+ let t = [];
131
+ if (Array.isArray(e)) {
132
+ let n = new Set(e.flat(Infinity).reverse());
133
+ for (let e of n) t.unshift(f(e));
134
+ } else e !== void 0 && t.push(f(e));
135
+ return t;
136
+ }
137
+ static _$Eu(e, t) {
138
+ let n = t.attribute;
139
+ return !1 === n ? void 0 : typeof n == "string" ? n : typeof e == "string" ? e.toLowerCase() : void 0;
140
+ }
141
+ constructor() {
142
+ super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
143
+ }
144
+ _$Ev() {
145
+ this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach((e) => e(this));
146
+ }
147
+ addController(e) {
148
+ (this._$EO ??= /* @__PURE__ */ new Set()).add(e), this.renderRoot !== void 0 && this.isConnected && e.hostConnected?.();
149
+ }
150
+ removeController(e) {
151
+ this._$EO?.delete(e);
152
+ }
153
+ _$E_() {
154
+ let e = /* @__PURE__ */ new Map(), t = this.constructor.elementProperties;
155
+ for (let n of t.keys()) this.hasOwnProperty(n) && (e.set(n, this[n]), delete this[n]);
156
+ e.size > 0 && (this._$Ep = e);
157
+ }
158
+ createRenderRoot() {
159
+ let e = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
160
+ return te(e, this.constructor.elementStyles), e;
161
+ }
162
+ connectedCallback() {
163
+ this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(!0), this._$EO?.forEach((e) => e.hostConnected?.());
164
+ }
165
+ enableUpdating(e) {}
166
+ disconnectedCallback() {
167
+ this._$EO?.forEach((e) => e.hostDisconnected?.());
168
+ }
169
+ attributeChangedCallback(e, t, n) {
170
+ this._$AK(e, n);
171
+ }
172
+ _$ET(e, t) {
173
+ let n = this.constructor.elementProperties.get(e), r = this.constructor._$Eu(e, n);
174
+ if (r !== void 0 && !0 === n.reflect) {
175
+ let i = (n.converter?.toAttribute === void 0 ? h : n.converter).toAttribute(t, n.type);
176
+ this._$Em = e, i == null ? this.removeAttribute(r) : this.setAttribute(r, i), this._$Em = null;
177
+ }
178
+ }
179
+ _$AK(e, t) {
180
+ let n = this.constructor, r = n._$Eh.get(e);
181
+ if (r !== void 0 && this._$Em !== r) {
182
+ let e = n.getPropertyOptions(r), i = typeof e.converter == "function" ? { fromAttribute: e.converter } : e.converter?.fromAttribute === void 0 ? h : e.converter;
183
+ this._$Em = r;
184
+ let a = i.fromAttribute(t, e.type);
185
+ this[r] = a ?? this._$Ej?.get(r) ?? a, this._$Em = null;
186
+ }
187
+ }
188
+ requestUpdate(e, t, n, r = !1, i) {
189
+ if (e !== void 0) {
190
+ let a = this.constructor;
191
+ if (!1 === r && (i = this[e]), n ??= a.getPropertyOptions(e), !((n.hasChanged ?? g)(i, t) || n.useDefault && n.reflect && i === this._$Ej?.get(e) && !this.hasAttribute(a._$Eu(e, n)))) return;
192
+ this.C(e, t, n);
193
+ }
194
+ !1 === this.isUpdatePending && (this._$ES = this._$EP());
195
+ }
196
+ C(e, t, { useDefault: n, reflect: r, wrapped: i }, a) {
197
+ n && !(this._$Ej ??= /* @__PURE__ */ new Map()).has(e) && (this._$Ej.set(e, a ?? t ?? this[e]), !0 !== i || a !== void 0) || (this._$AL.has(e) || (this.hasUpdated || n || (t = void 0), this._$AL.set(e, t)), !0 === r && this._$Em !== e && (this._$Eq ??= /* @__PURE__ */ new Set()).add(e));
198
+ }
199
+ async _$EP() {
200
+ this.isUpdatePending = !0;
201
+ try {
202
+ await this._$ES;
203
+ } catch (e) {
204
+ Promise.reject(e);
205
+ }
206
+ let e = this.scheduleUpdate();
207
+ return e != null && await e, !this.isUpdatePending;
208
+ }
209
+ scheduleUpdate() {
210
+ return this.performUpdate();
211
+ }
212
+ performUpdate() {
213
+ if (!this.isUpdatePending) return;
214
+ if (!this.hasUpdated) {
215
+ if (this.renderRoot ??= this.createRenderRoot(), this._$Ep) {
216
+ for (let [e, t] of this._$Ep) this[e] = t;
217
+ this._$Ep = void 0;
218
+ }
219
+ let e = this.constructor.elementProperties;
220
+ if (e.size > 0) for (let [t, n] of e) {
221
+ let { wrapped: e } = n, r = this[t];
222
+ !0 !== e || this._$AL.has(t) || r === void 0 || this.C(t, void 0, n, r);
223
+ }
224
+ }
225
+ let e = !1, t = this._$AL;
226
+ try {
227
+ e = this.shouldUpdate(t), e ? (this.willUpdate(t), this._$EO?.forEach((e) => e.hostUpdate?.()), this.update(t)) : this._$EM();
228
+ } catch (t) {
229
+ throw e = !1, this._$EM(), t;
230
+ }
231
+ e && this._$AE(t);
232
+ }
233
+ willUpdate(e) {}
234
+ _$AE(e) {
235
+ this._$EO?.forEach((e) => e.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(e)), this.updated(e);
236
+ }
237
+ _$EM() {
238
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
239
+ }
240
+ get updateComplete() {
241
+ return this.getUpdateComplete();
242
+ }
243
+ getUpdateComplete() {
244
+ return this._$ES;
245
+ }
246
+ shouldUpdate(e) {
247
+ return !0;
248
+ }
249
+ update(e) {
250
+ this._$Eq &&= this._$Eq.forEach((e) => this._$ET(e, this[e])), this._$EM();
251
+ }
252
+ updated(e) {}
253
+ firstUpdated(e) {}
254
+ };
255
+ v.elementStyles = [], v.shadowRootOptions = { mode: "open" }, v[m("elementProperties")] = /* @__PURE__ */ new Map(), v[m("finalized")] = /* @__PURE__ */ new Map(), ue?.({ ReactiveElement: v }), (p.reactiveElementVersions ??= []).push("2.1.2");
256
+ //#endregion
257
+ //#region ../../node_modules/lit-html/lit-html.js
258
+ var y = globalThis, b = (e) => e, x = y.trustedTypes, de = x ? x.createPolicy("lit-html", { createHTML: (e) => e }) : void 0, fe = "$lit$", S = `lit$${Math.random().toFixed(9).slice(2)}$`, pe = "?" + S, me = `<${pe}>`, C = document, w = () => C.createComment(""), T = (e) => e === null || typeof e != "object" && typeof e != "function", E = Array.isArray, he = (e) => E(e) || typeof e?.[Symbol.iterator] == "function", D = "[ \n\f\r]", O = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, k = /-->/g, A = />/g, j = RegExp(`>|${D}(?:([^\\s"'>=/]+)(${D}*=${D}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`, "g"), M = /'/g, N = /"/g, P = /^(?:script|style|textarea|title)$/i, F = ((e) => (t, ...n) => ({
259
+ _$litType$: e,
260
+ strings: t,
261
+ values: n
262
+ }))(1), I = Symbol.for("lit-noChange"), L = Symbol.for("lit-nothing"), R = /* @__PURE__ */ new WeakMap(), z = C.createTreeWalker(C, 129);
263
+ function B(e, t) {
264
+ if (!E(e) || !e.hasOwnProperty("raw")) throw Error("invalid template strings array");
265
+ return de === void 0 ? t : de.createHTML(t);
266
+ }
267
+ var ge = (e, t) => {
268
+ let n = e.length - 1, r = [], i, a = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", o = O;
269
+ for (let t = 0; t < n; t++) {
270
+ let n = e[t], s, c, l = -1, u = 0;
271
+ for (; u < n.length && (o.lastIndex = u, c = o.exec(n), c !== null);) u = o.lastIndex, o === O ? c[1] === "!--" ? o = k : c[1] === void 0 ? c[2] === void 0 ? c[3] !== void 0 && (o = j) : (P.test(c[2]) && (i = RegExp("</" + c[2], "g")), o = j) : o = A : o === j ? c[0] === ">" ? (o = i ?? O, l = -1) : c[1] === void 0 ? l = -2 : (l = o.lastIndex - c[2].length, s = c[1], o = c[3] === void 0 ? j : c[3] === "\"" ? N : M) : o === N || o === M ? o = j : o === k || o === A ? o = O : (o = j, i = void 0);
272
+ let d = o === j && e[t + 1].startsWith("/>") ? " " : "";
273
+ a += o === O ? n + me : l >= 0 ? (r.push(s), n.slice(0, l) + fe + n.slice(l) + S + d) : n + S + (l === -2 ? t : d);
274
+ }
275
+ return [B(e, a + (e[n] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), r];
276
+ }, V = class e {
277
+ constructor({ strings: t, _$litType$: n }, r) {
278
+ let i;
279
+ this.parts = [];
280
+ let a = 0, o = 0, s = t.length - 1, c = this.parts, [l, u] = ge(t, n);
281
+ if (this.el = e.createElement(l, r), z.currentNode = this.el.content, n === 2 || n === 3) {
282
+ let e = this.el.content.firstChild;
283
+ e.replaceWith(...e.childNodes);
284
+ }
285
+ for (; (i = z.nextNode()) !== null && c.length < s;) {
286
+ if (i.nodeType === 1) {
287
+ if (i.hasAttributes()) for (let e of i.getAttributeNames()) if (e.endsWith(fe)) {
288
+ let t = u[o++], n = i.getAttribute(e).split(S), r = /([.?@])?(.*)/.exec(t);
289
+ c.push({
290
+ type: 1,
291
+ index: a,
292
+ name: r[2],
293
+ strings: n,
294
+ ctor: r[1] === "." ? ve : r[1] === "?" ? ye : r[1] === "@" ? be : W
295
+ }), i.removeAttribute(e);
296
+ } else e.startsWith(S) && (c.push({
297
+ type: 6,
298
+ index: a
299
+ }), i.removeAttribute(e));
300
+ if (P.test(i.tagName)) {
301
+ let e = i.textContent.split(S), t = e.length - 1;
302
+ if (t > 0) {
303
+ i.textContent = x ? x.emptyScript : "";
304
+ for (let n = 0; n < t; n++) i.append(e[n], w()), z.nextNode(), c.push({
305
+ type: 2,
306
+ index: ++a
307
+ });
308
+ i.append(e[t], w());
309
+ }
310
+ }
311
+ } else if (i.nodeType === 8) if (i.data === pe) c.push({
312
+ type: 2,
313
+ index: a
314
+ });
315
+ else {
316
+ let e = -1;
317
+ for (; (e = i.data.indexOf(S, e + 1)) !== -1;) c.push({
318
+ type: 7,
319
+ index: a
320
+ }), e += S.length - 1;
321
+ }
322
+ a++;
323
+ }
324
+ }
325
+ static createElement(e, t) {
326
+ let n = C.createElement("template");
327
+ return n.innerHTML = e, n;
328
+ }
329
+ };
330
+ function H(e, t, n = e, r) {
331
+ if (t === I) return t;
332
+ let i = r === void 0 ? n._$Cl : n._$Co?.[r], a = T(t) ? void 0 : t._$litDirective$;
333
+ return i?.constructor !== a && (i?._$AO?.(!1), a === void 0 ? i = void 0 : (i = new a(e), i._$AT(e, n, r)), r === void 0 ? n._$Cl = i : (n._$Co ??= [])[r] = i), i !== void 0 && (t = H(e, i._$AS(e, t.values), i, r)), t;
334
+ }
335
+ var _e = class {
336
+ constructor(e, t) {
337
+ this._$AV = [], this._$AN = void 0, this._$AD = e, this._$AM = t;
338
+ }
339
+ get parentNode() {
340
+ return this._$AM.parentNode;
341
+ }
342
+ get _$AU() {
343
+ return this._$AM._$AU;
344
+ }
345
+ u(e) {
346
+ let { el: { content: t }, parts: n } = this._$AD, r = (e?.creationScope ?? C).importNode(t, !0);
347
+ z.currentNode = r;
348
+ let i = z.nextNode(), a = 0, o = 0, s = n[0];
349
+ for (; s !== void 0;) {
350
+ if (a === s.index) {
351
+ let t;
352
+ s.type === 2 ? t = new U(i, i.nextSibling, this, e) : s.type === 1 ? t = new s.ctor(i, s.name, s.strings, this, e) : s.type === 6 && (t = new xe(i, this, e)), this._$AV.push(t), s = n[++o];
353
+ }
354
+ a !== s?.index && (i = z.nextNode(), a++);
355
+ }
356
+ return z.currentNode = C, r;
357
+ }
358
+ p(e) {
359
+ let t = 0;
360
+ for (let n of this._$AV) n !== void 0 && (n.strings === void 0 ? n._$AI(e[t]) : (n._$AI(e, n, t), t += n.strings.length - 2)), t++;
361
+ }
362
+ }, U = class e {
363
+ get _$AU() {
364
+ return this._$AM?._$AU ?? this._$Cv;
365
+ }
366
+ constructor(e, t, n, r) {
367
+ this.type = 2, this._$AH = L, this._$AN = void 0, this._$AA = e, this._$AB = t, this._$AM = n, this.options = r, this._$Cv = r?.isConnected ?? !0;
368
+ }
369
+ get parentNode() {
370
+ let e = this._$AA.parentNode, t = this._$AM;
371
+ return t !== void 0 && e?.nodeType === 11 && (e = t.parentNode), e;
372
+ }
373
+ get startNode() {
374
+ return this._$AA;
375
+ }
376
+ get endNode() {
377
+ return this._$AB;
378
+ }
379
+ _$AI(e, t = this) {
380
+ e = H(this, e, t), T(e) ? e === L || e == null || e === "" ? (this._$AH !== L && this._$AR(), this._$AH = L) : e !== this._$AH && e !== I && this._(e) : e._$litType$ === void 0 ? e.nodeType === void 0 ? he(e) ? this.k(e) : this._(e) : this.T(e) : this.$(e);
381
+ }
382
+ O(e) {
383
+ return this._$AA.parentNode.insertBefore(e, this._$AB);
384
+ }
385
+ T(e) {
386
+ this._$AH !== e && (this._$AR(), this._$AH = this.O(e));
387
+ }
388
+ _(e) {
389
+ this._$AH !== L && T(this._$AH) ? this._$AA.nextSibling.data = e : this.T(C.createTextNode(e)), this._$AH = e;
390
+ }
391
+ $(e) {
392
+ let { values: t, _$litType$: n } = e, r = typeof n == "number" ? this._$AC(e) : (n.el === void 0 && (n.el = V.createElement(B(n.h, n.h[0]), this.options)), n);
393
+ if (this._$AH?._$AD === r) this._$AH.p(t);
394
+ else {
395
+ let e = new _e(r, this), n = e.u(this.options);
396
+ e.p(t), this.T(n), this._$AH = e;
397
+ }
398
+ }
399
+ _$AC(e) {
400
+ let t = R.get(e.strings);
401
+ return t === void 0 && R.set(e.strings, t = new V(e)), t;
402
+ }
403
+ k(t) {
404
+ E(this._$AH) || (this._$AH = [], this._$AR());
405
+ let n = this._$AH, r, i = 0;
406
+ for (let a of t) i === n.length ? n.push(r = new e(this.O(w()), this.O(w()), this, this.options)) : r = n[i], r._$AI(a), i++;
407
+ i < n.length && (this._$AR(r && r._$AB.nextSibling, i), n.length = i);
408
+ }
409
+ _$AR(e = this._$AA.nextSibling, t) {
410
+ for (this._$AP?.(!1, !0, t); e !== this._$AB;) {
411
+ let t = b(e).nextSibling;
412
+ b(e).remove(), e = t;
413
+ }
414
+ }
415
+ setConnected(e) {
416
+ this._$AM === void 0 && (this._$Cv = e, this._$AP?.(e));
417
+ }
418
+ }, W = class {
419
+ get tagName() {
420
+ return this.element.tagName;
421
+ }
422
+ get _$AU() {
423
+ return this._$AM._$AU;
424
+ }
425
+ constructor(e, t, n, r, i) {
426
+ this.type = 1, this._$AH = L, this._$AN = void 0, this.element = e, this.name = t, this._$AM = r, this.options = i, n.length > 2 || n[0] !== "" || n[1] !== "" ? (this._$AH = Array(n.length - 1).fill(/* @__PURE__ */ new String()), this.strings = n) : this._$AH = L;
427
+ }
428
+ _$AI(e, t = this, n, r) {
429
+ let i = this.strings, a = !1;
430
+ if (i === void 0) e = H(this, e, t, 0), a = !T(e) || e !== this._$AH && e !== I, a && (this._$AH = e);
431
+ else {
432
+ let r = e, o, s;
433
+ for (e = i[0], o = 0; o < i.length - 1; o++) s = H(this, r[n + o], t, o), s === I && (s = this._$AH[o]), a ||= !T(s) || s !== this._$AH[o], s === L ? e = L : e !== L && (e += (s ?? "") + i[o + 1]), this._$AH[o] = s;
434
+ }
435
+ a && !r && this.j(e);
436
+ }
437
+ j(e) {
438
+ e === L ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, e ?? "");
439
+ }
440
+ }, ve = class extends W {
441
+ constructor() {
442
+ super(...arguments), this.type = 3;
443
+ }
444
+ j(e) {
445
+ this.element[this.name] = e === L ? void 0 : e;
446
+ }
447
+ }, ye = class extends W {
448
+ constructor() {
449
+ super(...arguments), this.type = 4;
450
+ }
451
+ j(e) {
452
+ this.element.toggleAttribute(this.name, !!e && e !== L);
453
+ }
454
+ }, be = class extends W {
455
+ constructor(e, t, n, r, i) {
456
+ super(e, t, n, r, i), this.type = 5;
457
+ }
458
+ _$AI(e, t = this) {
459
+ if ((e = H(this, e, t, 0) ?? L) === I) return;
460
+ let n = this._$AH, r = e === L && n !== L || e.capture !== n.capture || e.once !== n.once || e.passive !== n.passive, i = e !== L && (n === L || r);
461
+ r && this.element.removeEventListener(this.name, this, n), i && this.element.addEventListener(this.name, this, e), this._$AH = e;
462
+ }
463
+ handleEvent(e) {
464
+ typeof this._$AH == "function" ? this._$AH.call(this.options?.host ?? this.element, e) : this._$AH.handleEvent(e);
465
+ }
466
+ }, xe = class {
467
+ constructor(e, t, n) {
468
+ this.element = e, this.type = 6, this._$AN = void 0, this._$AM = t, this.options = n;
469
+ }
470
+ get _$AU() {
471
+ return this._$AM._$AU;
472
+ }
473
+ _$AI(e) {
474
+ H(this, e);
475
+ }
476
+ }, Se = y.litHtmlPolyfillSupport;
477
+ Se?.(V, U), (y.litHtmlVersions ??= []).push("3.3.2");
478
+ var Ce = (e, t, n) => {
479
+ let r = n?.renderBefore ?? t, i = r._$litPart$;
480
+ if (i === void 0) {
481
+ let e = n?.renderBefore ?? null;
482
+ r._$litPart$ = i = new U(t.insertBefore(w(), e), e, void 0, n ?? {});
483
+ }
484
+ return i._$AI(e), i;
485
+ }, G = globalThis, K = class extends v {
486
+ constructor() {
487
+ super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
488
+ }
489
+ createRenderRoot() {
490
+ let e = super.createRenderRoot();
491
+ return this.renderOptions.renderBefore ??= e.firstChild, e;
492
+ }
493
+ update(e) {
494
+ let t = this.render();
495
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(e), this._$Do = Ce(t, this.renderRoot, this.renderOptions);
496
+ }
497
+ connectedCallback() {
498
+ super.connectedCallback(), this._$Do?.setConnected(!0);
499
+ }
500
+ disconnectedCallback() {
501
+ super.disconnectedCallback(), this._$Do?.setConnected(!1);
502
+ }
503
+ render() {
504
+ return I;
505
+ }
506
+ };
507
+ K._$litElement$ = !0, K.finalized = !0, G.litElementHydrateSupport?.({ LitElement: K });
508
+ var we = G.litElementPolyfillSupport;
509
+ we?.({ LitElement: K }), (G.litElementVersions ??= []).push("4.2.2");
510
+ var q = {
511
+ "1x1": {
512
+ slots: 1,
513
+ label: "1x1",
514
+ layoutFunction: () => ({
515
+ top: "0",
516
+ left: "0",
517
+ width: "100%",
518
+ height: "100%"
519
+ })
520
+ },
521
+ "1x2": {
522
+ slots: 2,
523
+ label: "1x2",
524
+ layoutFunction: (e, t) => ({
525
+ top: "0",
526
+ left: `${t * 50}%`,
527
+ width: "50%",
528
+ height: "100%"
529
+ })
530
+ },
531
+ "2x1": {
532
+ slots: 2,
533
+ label: "2x1",
534
+ layoutFunction: (e, t) => ({
535
+ top: `${t * 50}%`,
536
+ left: "0",
537
+ width: "100%",
538
+ height: "50%"
539
+ })
540
+ },
541
+ "1x3": {
542
+ slots: 3,
543
+ label: "1x3",
544
+ layoutFunction: (e, t) => ({
545
+ top: "0",
546
+ left: `${t * 33.333}%`,
547
+ width: "33.333%",
548
+ height: "100%"
549
+ })
550
+ },
551
+ "3x1": {
552
+ slots: 3,
553
+ label: "3x1",
554
+ layoutFunction: (e, t) => ({
555
+ top: `${t * 33.333}%`,
556
+ left: "0",
557
+ width: "100%",
558
+ height: "33.333%"
559
+ })
560
+ },
561
+ "2x2": {
562
+ slots: 4,
563
+ label: "2x2",
564
+ layoutFunction: (e, t) => {
565
+ let n = Math.floor(t / 2), r = t % 2;
566
+ return {
567
+ top: `${n * 50}%`,
568
+ left: `${r * 50}%`,
569
+ width: "50%",
570
+ height: "50%"
571
+ };
572
+ }
573
+ },
574
+ "3x3": {
575
+ slots: 9,
576
+ label: "3x3",
577
+ layoutFunction: (e, t) => {
578
+ let n = Math.floor(t / 3), r = t % 3;
579
+ return {
580
+ top: `${n * 33.333}%`,
581
+ left: `${r * 33.333}%`,
582
+ width: "33.333%",
583
+ height: "33.333%"
584
+ };
585
+ }
586
+ }
587
+ }, Te = [
588
+ {
589
+ sliceType: a.AXIAL,
590
+ position: [
591
+ 0,
592
+ 0,
593
+ 1,
594
+ .8
595
+ ]
596
+ },
597
+ {
598
+ sliceType: a.CORONAL,
599
+ position: [
600
+ 0,
601
+ .8,
602
+ .5,
603
+ .2
604
+ ]
605
+ },
606
+ {
607
+ sliceType: a.SAGITTAL,
608
+ position: [
609
+ .5,
610
+ .8,
611
+ .5,
612
+ .2
613
+ ]
614
+ }
615
+ ], Ee = [
616
+ {
617
+ sliceType: a.SAGITTAL,
618
+ position: [
619
+ 0,
620
+ 0,
621
+ .5,
622
+ 1
623
+ ]
624
+ },
625
+ {
626
+ sliceType: a.CORONAL,
627
+ position: [
628
+ .5,
629
+ 0,
630
+ .5,
631
+ .5
632
+ ]
633
+ },
634
+ {
635
+ sliceType: a.AXIAL,
636
+ position: [
637
+ .5,
638
+ .5,
639
+ .5,
640
+ .5
641
+ ]
642
+ }
643
+ ], De = [
644
+ {
645
+ sliceType: a.AXIAL,
646
+ position: [
647
+ 0,
648
+ 0,
649
+ .333,
650
+ 1
651
+ ]
652
+ },
653
+ {
654
+ sliceType: a.CORONAL,
655
+ position: [
656
+ .333,
657
+ 0,
658
+ .333,
659
+ 1
660
+ ]
661
+ },
662
+ {
663
+ sliceType: a.SAGITTAL,
664
+ position: [
665
+ .666,
666
+ 0,
667
+ .334,
668
+ 1
669
+ ]
670
+ }
671
+ ], Oe = [
672
+ {
673
+ sliceType: a.AXIAL,
674
+ position: [
675
+ 0,
676
+ 0,
677
+ 1,
678
+ .333
679
+ ]
680
+ },
681
+ {
682
+ sliceType: a.CORONAL,
683
+ position: [
684
+ 0,
685
+ .333,
686
+ 1,
687
+ .333
688
+ ]
689
+ },
690
+ {
691
+ sliceType: a.SAGITTAL,
692
+ position: [
693
+ 0,
694
+ .666,
695
+ 1,
696
+ .334
697
+ ]
698
+ }
699
+ ], ke = [
700
+ {
701
+ sliceType: a.AXIAL,
702
+ position: [
703
+ 0,
704
+ 0,
705
+ .5,
706
+ .5
707
+ ]
708
+ },
709
+ {
710
+ sliceType: a.CORONAL,
711
+ position: [
712
+ .5,
713
+ 0,
714
+ .5,
715
+ .5
716
+ ]
717
+ },
718
+ {
719
+ sliceType: a.SAGITTAL,
720
+ position: [
721
+ 0,
722
+ .5,
723
+ .5,
724
+ .5
725
+ ]
726
+ },
727
+ {
728
+ sliceType: a.RENDER,
729
+ position: [
730
+ .5,
731
+ .5,
732
+ .5,
733
+ .5
734
+ ]
735
+ }
736
+ ], Ae = [
737
+ {
738
+ sliceType: a.RENDER,
739
+ position: [
740
+ 0,
741
+ 0,
742
+ 1,
743
+ .7
744
+ ]
745
+ },
746
+ {
747
+ sliceType: a.AXIAL,
748
+ position: [
749
+ 0,
750
+ .7,
751
+ .333,
752
+ .3
753
+ ]
754
+ },
755
+ {
756
+ sliceType: a.CORONAL,
757
+ position: [
758
+ .333,
759
+ .7,
760
+ .333,
761
+ .3
762
+ ]
763
+ },
764
+ {
765
+ sliceType: a.SAGITTAL,
766
+ position: [
767
+ .666,
768
+ .7,
769
+ .334,
770
+ .3
771
+ ]
772
+ }
773
+ ], je = {
774
+ "axial-hero": {
775
+ label: "Axial Hero",
776
+ layout: Te
777
+ },
778
+ "sag-left": {
779
+ label: "Sag Left Split",
780
+ layout: Ee
781
+ },
782
+ "tri-h": {
783
+ label: "Tri Horizontal",
784
+ layout: De
785
+ },
786
+ "tri-v": {
787
+ label: "Tri Stacked",
788
+ layout: Oe
789
+ },
790
+ "quad-render": {
791
+ label: "Quad Render",
792
+ layout: ke
793
+ },
794
+ "render-hero": {
795
+ label: "Render Hero",
796
+ layout: Ae
797
+ }
798
+ }, J = {
799
+ crosshairGap: 5,
800
+ primaryDragMode: n.crosshair,
801
+ secondaryDragMode: n.pan
802
+ }, Y = class {
803
+ constructor(e = q, t = {}) {
804
+ this.containerElement = null, this.viewers = [], this.currentLayout = "1x1", this.listeners = /* @__PURE__ */ new Set(), this.snapshotCache = null, this.nextId = 0, this.viewersById = /* @__PURE__ */ new Map(), this.broadcasting = !1, this.broadcastOptions = {
805
+ "2d": !0,
806
+ "3d": !0
807
+ }, this.viewerSliceLayouts = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.loadingCounts = /* @__PURE__ */ new Map(), this.viewerErrors = /* @__PURE__ */ new Map(), this.subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e)), this.getSnapshot = () => {
808
+ if (!this.snapshotCache) {
809
+ let e = this.viewers.map((e) => ({
810
+ id: e.id,
811
+ loading: this.loadingCounts.get(e.id) ?? 0,
812
+ errors: this.viewerErrors.get(e.id) ?? []
813
+ }));
814
+ this.snapshotCache = {
815
+ currentLayout: this.currentLayout,
816
+ viewerCount: this.viewers.length,
817
+ slots: this.slots,
818
+ isBroadcasting: this.broadcasting,
819
+ isLoading: e.some((e) => e.loading > 0),
820
+ viewerStates: e
821
+ };
822
+ }
823
+ return this.snapshotCache;
824
+ }, this.layouts = e, this.slots = this.layouts[this.currentLayout]?.slots ?? 1, this.viewerDefaults = t;
825
+ }
826
+ on(e, t) {
827
+ return this.eventListeners.has(e) || this.eventListeners.set(e, /* @__PURE__ */ new Set()), this.eventListeners.get(e)?.add(t), () => this.off(e, t);
828
+ }
829
+ off(e, t) {
830
+ this.eventListeners.get(e)?.delete(t);
831
+ }
832
+ emit(e, ...t) {
833
+ let n = this.eventListeners.get(e);
834
+ if (n) for (let e of n) e(...t);
835
+ }
836
+ notify() {
837
+ this.snapshotCache = null, this.listeners.forEach((e) => {
838
+ e();
839
+ });
840
+ }
841
+ setContainerElement(e) {
842
+ this.containerElement = e, e && this.updateLayout();
843
+ }
844
+ setLayout(e) {
845
+ let t = this.layouts[e];
846
+ if (t) {
847
+ for (this.currentLayout = e, this.slots = t.slots; this.viewers.length > this.slots;) this.removeViewer(this.viewers.length - 1, !1);
848
+ if (this.containerElement) for (; this.viewers.length < this.slots;) this.addViewer().catch(() => void 0);
849
+ this.updateLayout(), this.notify();
850
+ }
851
+ }
852
+ updateLayout() {
853
+ if (!this.containerElement) return;
854
+ let e = this.layouts[this.currentLayout];
855
+ e && this.viewers.forEach((t, n) => {
856
+ let r = e.layoutFunction(this.containerElement, n, this.viewers.length);
857
+ Object.assign(t.containerDiv.style, {
858
+ position: "absolute",
859
+ top: r.top,
860
+ left: r.left,
861
+ width: r.width,
862
+ height: r.height
863
+ });
864
+ });
865
+ }
866
+ canAddViewer() {
867
+ return this.viewers.length < this.slots;
868
+ }
869
+ getNiivue(e) {
870
+ return this.viewers[e]?.niivue;
871
+ }
872
+ getAllNiivue() {
873
+ return this.viewers.map((e) => e.niivue);
874
+ }
875
+ forEachNiivue(e) {
876
+ this.viewers.forEach((t, n) => {
877
+ e(t.niivue, n);
878
+ });
879
+ }
880
+ hasSyncableContent(e) {
881
+ return e.volumes.length > 0 || e.meshes.length > 0;
882
+ }
883
+ safeBroadcastTo(e, t) {
884
+ let n = this.viewers[e];
885
+ if (n) try {
886
+ n.niivue.broadcastTo(t, this.broadcastOptions);
887
+ } catch (t) {
888
+ this.addError(n.id, t), this.emit("error", e, t), this.notify();
889
+ }
890
+ }
891
+ rewireBroadcasting() {
892
+ if (!this.broadcasting) {
893
+ this.viewers.forEach((e, t) => {
894
+ this.safeBroadcastTo(t, []);
895
+ });
896
+ return;
897
+ }
898
+ let e = this.viewers.filter((e) => this.hasSyncableContent(e.niivue));
899
+ this.viewers.forEach((t, n) => {
900
+ if (!this.hasSyncableContent(t.niivue)) {
901
+ this.safeBroadcastTo(n, []);
902
+ return;
903
+ }
904
+ let r = e.filter((e) => e.id !== t.id).map((e) => e.niivue);
905
+ this.safeBroadcastTo(n, r);
906
+ });
907
+ }
908
+ setBroadcasting(e, t) {
909
+ this.broadcasting = e, t && (this.broadcastOptions = {
910
+ ...this.broadcastOptions,
911
+ ...t
912
+ }), this.rewireBroadcasting(), this.notify();
913
+ }
914
+ isBroadcasting() {
915
+ return this.broadcasting;
916
+ }
917
+ setViewerSliceLayout(e, t) {
918
+ let n = this.viewers[e];
919
+ n && (this.viewerSliceLayouts.set(n.id, t), n.ready.then(() => {
920
+ this.viewersById.get(n.id) === n && (this.applySliceLayout(n.niivue, t), this.notify());
921
+ }));
922
+ }
923
+ getViewerSliceLayout(e) {
924
+ let t = this.viewers[e];
925
+ return t ? this.viewerSliceLayouts.get(t.id) ?? null : null;
926
+ }
927
+ applySliceLayout(e, t) {
928
+ t && t.length > 0 ? e.customLayout = t : (e.customLayout = null, e.sliceType = a.AXIAL, e.showRender = r.NEVER);
929
+ }
930
+ getNiivueById(e) {
931
+ return this.viewersById.get(e)?.niivue;
932
+ }
933
+ getViewerById(e) {
934
+ return this.viewersById.get(e);
935
+ }
936
+ async waitForViewerReady(e) {
937
+ return await e.ready, this.viewersById.get(e.id) === e;
938
+ }
939
+ async loadVolume(e, t) {
940
+ let n = this.viewers[e];
941
+ if (!n) throw Error(`No viewer at index ${e}`);
942
+ this.incrementLoading(n.id);
943
+ try {
944
+ if (!await this.waitForViewerReady(n)) throw Error(`Viewer at index ${e} was removed before it was ready`);
945
+ await n.niivue.addVolume(t);
946
+ let r = n.niivue.volumes, i = r[r.length - 1];
947
+ if (!i) throw Error("Volume was not added");
948
+ return this.emit("volumeAdded", e, t, i), this.broadcasting && this.rewireBroadcasting(), i;
949
+ } catch (t) {
950
+ throw this.addError(n.id, t), this.emit("error", e, t), t;
951
+ } finally {
952
+ this.decrementLoading(n.id);
953
+ }
954
+ }
955
+ async loadVolumes(e, t) {
956
+ let n = [];
957
+ for (let r of t) n.push(await this.loadVolume(e, r));
958
+ return n;
959
+ }
960
+ async removeVolume(e, t) {
961
+ let n = this.viewers[e];
962
+ if (!n || !await this.waitForViewerReady(n)) return;
963
+ let r = n.niivue, i = r.volumes.findIndex((e) => e.url === t || e.name === t);
964
+ i >= 0 && (await r.removeVolume(i), this.emit("volumeRemoved", e, t), this.broadcasting && this.rewireBroadcasting(), this.notify());
965
+ }
966
+ async findVolume(e, t) {
967
+ let n = this.viewers[e];
968
+ if (!n || !await this.waitForViewerReady(n)) return;
969
+ let r = n.niivue, i = r.volumes[t];
970
+ if (i) return {
971
+ nv: r,
972
+ vol: i,
973
+ volumeIndex: t
974
+ };
975
+ }
976
+ async setColormap(e, t, n) {
977
+ let r = await this.findVolume(e, t);
978
+ r && (await r.nv.setVolume(r.volumeIndex, { colormap: n }), this.emit("colormapChanged", e, t, n), this.notify());
979
+ }
980
+ async setCalMinMax(e, t, n, r) {
981
+ let i = await this.findVolume(e, t);
982
+ i && (await i.nv.setVolume(i.volumeIndex, {
983
+ calMin: n,
984
+ calMax: r
985
+ }), this.emit("intensityChanged", e, t, n, r), this.notify());
986
+ }
987
+ async setOpacity(e, t, n) {
988
+ let r = await this.findVolume(e, t);
989
+ r && (await r.nv.setVolume(r.volumeIndex, { opacity: n }), this.emit("opacityChanged", e, t, n), this.notify());
990
+ }
991
+ incrementLoading(e) {
992
+ this.loadingCounts.set(e, (this.loadingCounts.get(e) ?? 0) + 1), this.notify();
993
+ }
994
+ decrementLoading(e) {
995
+ let t = (this.loadingCounts.get(e) ?? 1) - 1;
996
+ this.loadingCounts.set(e, Math.max(0, t)), this.notify();
997
+ }
998
+ addError(e, t) {
999
+ let n = this.viewerErrors.get(e) ?? [];
1000
+ n.push(t), this.viewerErrors.set(e, n);
1001
+ }
1002
+ getViewerIndex(e) {
1003
+ return this.viewers.findIndex((t) => t.id === e.id);
1004
+ }
1005
+ addViewer(t) {
1006
+ if (!this.containerElement) throw Error("Container element not set");
1007
+ if (!this.canAddViewer()) throw Error(`Cannot add viewer: slot limit of ${this.slots} reached`);
1008
+ let n = document.createElement("div");
1009
+ n.className = "niivue-canvas-container", n.style.position = "relative", n.style.overflow = "hidden";
1010
+ let r = document.createElement("canvas");
1011
+ r.className = "niivue-canvas", r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "100%", r.style.height = "100%", n.appendChild(r), this.containerElement.appendChild(n);
1012
+ let i = new e({
1013
+ ...J,
1014
+ ...this.viewerDefaults,
1015
+ ...t
1016
+ }), a = `nv-${this.nextId++}`;
1017
+ this.viewerSliceLayouts.set(a, null), this.loadingCounts.set(a, 0), this.viewerErrors.set(a, []);
1018
+ let o = {
1019
+ id: a,
1020
+ niivue: i,
1021
+ canvasElement: r,
1022
+ containerDiv: n,
1023
+ ready: Promise.resolve()
1024
+ };
1025
+ this.viewers.push(o), this.viewersById.set(a, o), this.updateLayout();
1026
+ let s = this.viewers.length - 1;
1027
+ return i.addEventListener("locationChange", (e) => {
1028
+ let t = this.getViewerIndex(o);
1029
+ t >= 0 && this.emit("locationChange", t, e.detail);
1030
+ }), i.addEventListener("volumeLoaded", (e) => {
1031
+ let t = this.getViewerIndex(o);
1032
+ t >= 0 && this.emit("imageLoaded", t, e.detail.volume), this.broadcasting && this.rewireBroadcasting();
1033
+ }), i.addEventListener("meshLoaded", () => {
1034
+ this.broadcasting && this.rewireBroadcasting();
1035
+ }), this.onViewerCreated?.(i, s), this.emit("viewerCreated", i, s), this.notify(), o.ready = i.attachToCanvas(r).then(() => {
1036
+ if (this.viewersById.get(o.id) !== o) return;
1037
+ let e = this.viewerSliceLayouts.get(a) ?? null;
1038
+ this.applySliceLayout(i, e), this.broadcasting && this.setBroadcasting(!0), this.notify();
1039
+ }).catch((e) => {
1040
+ if (this.viewersById.get(o.id) === o) {
1041
+ let t = this.viewers.indexOf(o);
1042
+ this.addError(o.id, e), t >= 0 && (this.emit("error", t, e), this.removeViewer(t));
1043
+ }
1044
+ throw e;
1045
+ }), o.ready.then(() => o);
1046
+ }
1047
+ removeViewer(e, t = !0) {
1048
+ if (e < 0 || e >= this.viewers.length) return;
1049
+ let n = this.viewers[e];
1050
+ n && (this.viewersById.delete(n.id), this.viewerSliceLayouts.delete(n.id), this.loadingCounts.delete(n.id), this.viewerErrors.delete(n.id), this.disposeViewer(n), n.containerDiv.remove(), this.viewers.splice(e, 1), this.updateLayout(), this.broadcasting && this.viewers.length > 0 && this.rewireBroadcasting(), this.emit("viewerRemoved", e), t && this.notify());
1051
+ }
1052
+ disposeViewer(e) {
1053
+ e.niivue.destroy(), e.canvasElement.width = 0, e.canvasElement.height = 0;
1054
+ }
1055
+ clearViewers() {
1056
+ this.broadcasting = !1, this.viewers.forEach((e) => {
1057
+ this.disposeViewer(e), e.containerDiv.remove();
1058
+ }), this.viewers = [], this.viewersById.clear(), this.loadingCounts.clear(), this.viewerErrors.clear(), this.notify();
1059
+ }
1060
+ reset() {
1061
+ this.clearViewers(), this.currentLayout = "1x1", this.slots = this.layouts[this.currentLayout]?.slots ?? 1, this.notify();
1062
+ }
1063
+ }, Me = "niivue-viewer", Ne = "niivue-scene", X = (e) => typeof e.url == "string" ? e.url : e.url.name, Pe = (e) => e.url || e.name, Fe = (e) => ({
1064
+ colormap: e.colormap,
1065
+ calMin: e.calMin,
1066
+ calMax: e.calMax,
1067
+ opacity: e.opacity
1068
+ }), Ie = (e, t) => {
1069
+ let n = {};
1070
+ return e.colormap !== void 0 && e.colormap !== t.colormap && (n.colormap = e.colormap), e.calMin !== void 0 && e.calMin !== t.calMin && (n.calMin = e.calMin), e.calMax !== void 0 && e.calMax !== t.calMax && (n.calMax = e.calMax), e.opacity !== void 0 && e.opacity !== t.opacity && (n.opacity = e.opacity), n;
1071
+ }, Z = (e, t) => e.findIndex((e) => e.url === t || e.name === t), Q = (e, t, n) => {
1072
+ e.dispatchEvent(new CustomEvent(t, {
1073
+ detail: n,
1074
+ bubbles: !0,
1075
+ composed: !0
1076
+ }));
1077
+ }, Le = class extends K {
1078
+ constructor(...e) {
1079
+ super(...e), this.volumes = [], this.options = {}, this.sliceType = i.AXIAL, this.niivue = null, this.resizeObserver = null, this.loadedVolumes = /* @__PURE__ */ new Map(), this.attachmentReady = null, this.attachmentGeneration = 0;
1080
+ }
1081
+ static {
1082
+ this.properties = {
1083
+ volumes: { attribute: !1 },
1084
+ options: { attribute: !1 },
1085
+ sliceType: {
1086
+ type: Number,
1087
+ attribute: "slice-type"
1088
+ }
1089
+ };
1090
+ }
1091
+ static {
1092
+ this.styles = ee`
1093
+ :host {
1094
+ display: block;
1095
+ position: relative;
1096
+ min-height: 1px;
1097
+ }
1098
+
1099
+ #container {
1100
+ position: relative;
1101
+ width: 100%;
1102
+ height: 100%;
1103
+ min-height: inherit;
1104
+ }
1105
+
1106
+ canvas {
1107
+ position: absolute;
1108
+ inset: 0;
1109
+ width: 100%;
1110
+ height: 100%;
1111
+ }
1112
+ `;
1113
+ }
1114
+ get nv() {
1115
+ return this.niivue;
1116
+ }
1117
+ render() {
1118
+ return F`<div id="container"><canvas class="niivue-canvas"></canvas></div>`;
1119
+ }
1120
+ firstUpdated() {
1121
+ let t = this.renderRoot.querySelector("canvas"), n = this.renderRoot.querySelector("#container");
1122
+ if (!(t instanceof HTMLCanvasElement) || !(n instanceof HTMLElement)) return;
1123
+ let r = new e({
1124
+ ...J,
1125
+ ...this.options
1126
+ });
1127
+ r.addEventListener("locationChange", (e) => {
1128
+ Q(this, "location-change", e.detail);
1129
+ }), r.addEventListener("volumeLoaded", (e) => {
1130
+ Q(this, "image-loaded", e.detail.volume);
1131
+ }), this.niivue = r, this.resizeObserver = new ResizeObserver(() => r.resize()), this.resizeObserver.observe(n);
1132
+ let i = ++this.attachmentGeneration, a = r.attachToCanvas(t).then(() => r);
1133
+ this.attachmentReady = a, a.then(async (e) => {
1134
+ this.ownsAttachment(e, i) && (e.sliceType = this.sliceType, await e.updateGLVolume(), await this.syncVolumes());
1135
+ }).catch((e) => {
1136
+ this.ownsAttachment(r, i) && this.emitError(e);
1137
+ });
1138
+ }
1139
+ updated(e) {
1140
+ e.has("sliceType") && this.niivue && (this.niivue.sliceType = this.sliceType), e.has("volumes") && this.syncVolumes().catch((e) => this.emitError(e));
1141
+ }
1142
+ disconnectedCallback() {
1143
+ super.disconnectedCallback(), this.resizeObserver?.disconnect(), this.resizeObserver = null, this.attachmentGeneration++, this.attachmentReady = null, this.niivue?.destroy(), this.niivue = null, this.loadedVolumes.clear();
1144
+ }
1145
+ emitError(e) {
1146
+ this.niivue && Q(this, "niivue-error", e);
1147
+ }
1148
+ ownsAttachment(e, t) {
1149
+ return this.niivue === e && this.attachmentGeneration === t;
1150
+ }
1151
+ async getAttachedNiivue() {
1152
+ let e = this.attachmentReady;
1153
+ if (!e) return this.niivue;
1154
+ let t = await e;
1155
+ return this.niivue === t ? t : null;
1156
+ }
1157
+ async setColormap(e, t) {
1158
+ this.niivue?.volumes[e] && await this.niivue.setVolume(e, { colormap: t });
1159
+ }
1160
+ async setOpacity(e, t) {
1161
+ this.niivue?.volumes[e] && await this.niivue.setVolume(e, { opacity: t });
1162
+ }
1163
+ async setCalMinMax(e, t, n) {
1164
+ this.niivue?.volumes[e] && await this.niivue.setVolume(e, {
1165
+ calMin: t,
1166
+ calMax: n
1167
+ });
1168
+ }
1169
+ setColorbarVisible(e) {
1170
+ this.niivue && (this.niivue.isColorbarVisible = e);
1171
+ }
1172
+ setCrosshairVisible(e) {
1173
+ this.niivue && (this.niivue.isCrossLinesVisible = e, this.niivue.is3DCrosshairVisible = e);
1174
+ }
1175
+ setPrimaryDragMode(e) {
1176
+ this.niivue && (this.niivue.primaryDragMode = e);
1177
+ }
1178
+ setSecondaryDragMode(e) {
1179
+ this.niivue && (this.niivue.secondaryDragMode = e);
1180
+ }
1181
+ async syncVolumes() {
1182
+ let e = await this.getAttachedNiivue();
1183
+ if (!e) return;
1184
+ let t = new Set(this.volumes.map(X));
1185
+ for (let n of this.loadedVolumes.keys()) if (!t.has(n)) {
1186
+ let t = Z(e.volumes, n);
1187
+ t >= 0 && await e.removeVolume(t), this.loadedVolumes.delete(n);
1188
+ }
1189
+ for (let t of this.volumes) {
1190
+ let n = X(t), r = Fe(t), i = this.loadedVolumes.get(n);
1191
+ if (!i) {
1192
+ this.loadedVolumes.set(n, r);
1193
+ try {
1194
+ await e.addVolume(t);
1195
+ } catch (e) {
1196
+ this.loadedVolumes.delete(n), this.emitError(e);
1197
+ }
1198
+ continue;
1199
+ }
1200
+ let a = Z(e.volumes, n);
1201
+ if (a < 0) continue;
1202
+ let o = Ie(r, i);
1203
+ Object.keys(o).length > 0 && await e.setVolume(a, o), this.loadedVolumes.set(n, r);
1204
+ }
1205
+ await this.reconcileVolumeOrder(e);
1206
+ }
1207
+ async reconcileVolumeOrder(e) {
1208
+ let t = !1;
1209
+ for (let [n, r] of this.volumes.entries()) {
1210
+ let i = Z(e.volumes, X(r));
1211
+ i < 0 || i === n || e.model.moveVolume(i, n) && (t = !0);
1212
+ }
1213
+ t && await e.updateGLVolume();
1214
+ }
1215
+ }, Re = class extends K {
1216
+ static {
1217
+ this.properties = {
1218
+ layout: { type: String },
1219
+ broadcasting: {
1220
+ type: Boolean,
1221
+ reflect: !0
1222
+ },
1223
+ snapshot: { attribute: !1 }
1224
+ };
1225
+ }
1226
+ static {
1227
+ this.styles = ee`
1228
+ :host {
1229
+ display: block;
1230
+ position: relative;
1231
+ min-height: 1px;
1232
+ }
1233
+
1234
+ #scene {
1235
+ position: relative;
1236
+ width: 100%;
1237
+ height: 100%;
1238
+ min-height: inherit;
1239
+ overflow: hidden;
1240
+ }
1241
+ `;
1242
+ }
1243
+ constructor() {
1244
+ super(), this.layout = "1x1", this.broadcasting = !1, this.scene = new Y(q), this.unsubscribe = null, this.resizeObserver = null, this.snapshot = this.scene.getSnapshot(), this.forwardSceneEvents();
1245
+ }
1246
+ render() {
1247
+ return F`<div id="scene"></div>`;
1248
+ }
1249
+ firstUpdated() {
1250
+ let e = this.renderRoot.querySelector("#scene");
1251
+ e instanceof HTMLElement && (this.unsubscribe = this.scene.subscribe(() => {
1252
+ this.snapshot = this.scene.getSnapshot(), Q(this, "scene-change", this.snapshot);
1253
+ }), this.scene.setContainerElement(e), this.scene.setLayout(this.layout), this.scene.setBroadcasting(this.broadcasting), this.resizeObserver = new ResizeObserver(() => this.scene.updateLayout()), this.resizeObserver.observe(e));
1254
+ }
1255
+ updated(e) {
1256
+ e.has("layout") && this.scene.setLayout(this.layout), e.has("broadcasting") && this.scene.setBroadcasting(this.broadcasting);
1257
+ }
1258
+ disconnectedCallback() {
1259
+ super.disconnectedCallback(), this.resizeObserver?.disconnect(), this.resizeObserver = null, this.unsubscribe?.(), this.unsubscribe = null, this.scene.clearViewers(), this.scene.setContainerElement(null);
1260
+ }
1261
+ addViewer(e) {
1262
+ return this.scene.addViewer(e);
1263
+ }
1264
+ removeViewer(e) {
1265
+ this.scene.removeViewer(e);
1266
+ }
1267
+ canAddViewer() {
1268
+ return this.scene.canAddViewer();
1269
+ }
1270
+ setViewerSliceLayout(e, t) {
1271
+ this.scene.setViewerSliceLayout(e, t);
1272
+ }
1273
+ loadVolume(e, t) {
1274
+ return this.scene.loadVolume(e, t);
1275
+ }
1276
+ loadVolumes(e, t) {
1277
+ return this.scene.loadVolumes(e, t);
1278
+ }
1279
+ removeVolume(e, t) {
1280
+ return this.scene.removeVolume(e, t);
1281
+ }
1282
+ async setColormap(e, t, n) {
1283
+ await this.scene.setColormap(e, t, n);
1284
+ }
1285
+ async setOpacity(e, t, n) {
1286
+ await this.scene.setOpacity(e, t, n);
1287
+ }
1288
+ async setCalMinMax(e, t, n, r) {
1289
+ await this.scene.setCalMinMax(e, t, n, r);
1290
+ }
1291
+ setColorbarVisible(e, t) {
1292
+ this.forEachTargetViewer(t, (t) => {
1293
+ t.isColorbarVisible = e;
1294
+ });
1295
+ }
1296
+ setCrosshairVisible(e, t) {
1297
+ this.forEachTargetViewer(t, (t) => {
1298
+ t.isCrossLinesVisible = e, t.is3DCrosshairVisible = e;
1299
+ });
1300
+ }
1301
+ setPrimaryDragMode(e, t) {
1302
+ this.forEachTargetViewer(t, (t) => {
1303
+ t.primaryDragMode = e;
1304
+ });
1305
+ }
1306
+ setSecondaryDragMode(e, t) {
1307
+ this.forEachTargetViewer(t, (t) => {
1308
+ t.secondaryDragMode = e;
1309
+ });
1310
+ }
1311
+ forEachTargetViewer(e, t) {
1312
+ if (e === void 0) {
1313
+ this.scene.forEachNiivue(t);
1314
+ return;
1315
+ }
1316
+ let n = this.scene.getNiivue(e);
1317
+ n && t(n);
1318
+ }
1319
+ forwardSceneEvents() {
1320
+ this.scene.on("viewerCreated", (e, t) => {
1321
+ Q(this, "viewer-created", {
1322
+ niivue: e,
1323
+ index: t
1324
+ });
1325
+ }), this.scene.on("viewerRemoved", (e) => {
1326
+ Q(this, "viewer-removed", { index: e });
1327
+ }), this.scene.on("locationChange", (e, t) => {
1328
+ Q(this, "location-change", {
1329
+ viewerIndex: e,
1330
+ data: t
1331
+ });
1332
+ }), this.scene.on("imageLoaded", (e, t) => {
1333
+ Q(this, "image-loaded", {
1334
+ viewerIndex: e,
1335
+ volume: t
1336
+ });
1337
+ }), this.scene.on("error", (e, t) => {
1338
+ Q(this, "niivue-error", {
1339
+ viewerIndex: e,
1340
+ error: t
1341
+ });
1342
+ }), this.scene.on("volumeAdded", (e, t, n) => {
1343
+ Q(this, "volume-added", {
1344
+ viewerIndex: e,
1345
+ imageOptions: t,
1346
+ image: n
1347
+ });
1348
+ }), this.scene.on("volumeRemoved", (e, t) => {
1349
+ Q(this, "volume-removed", {
1350
+ viewerIndex: e,
1351
+ url: t
1352
+ });
1353
+ });
1354
+ }
1355
+ };
1356
+ function $(e = {}) {
1357
+ if (typeof customElements > "u") return;
1358
+ let t = e.elementName ?? "niivue-viewer", n = e.sceneElementName ?? "niivue-scene";
1359
+ customElements.get(t) || customElements.define(t, Le), customElements.get(n) || customElements.define(n, Re);
1360
+ }
1361
+ $();
1362
+ //#endregion
1363
+ export { t as DRAG_MODE, Re as NiivueSceneElement, Le as NiivueViewerElement, Y as NvSceneController, i as SLICE_TYPE, Me as defaultElementName, q as defaultLayouts, Ne as defaultSceneElementName, je as defaultSliceLayouts, J as defaultViewerOptions, $ as defineNiivueWebComponents, Fe as extractVisualProps, Pe as volumeIdentity, Z as volumeIndexByKey, X as volumeKey, Ie as volumeVisualUpdates };