@uvalib/web-components 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,376 @@
1
+ import { l as e, o as t, p as n, r } from "./UvalibElement-pGONDAwB.js";
2
+ import { a as i } from "./analytics-DTTihuBD.js";
3
+ // src/components/uvalib-lightbox/compare.ts
4
+ var a = [
5
+ "switch",
6
+ "wipe",
7
+ "fade"
8
+ ], o = {
9
+ switch: "Switch",
10
+ wipe: "Reveal",
11
+ fade: "Fade"
12
+ }, s = { settle: 400 }, c = (e) => typeof e == "string" ? e.replace(/\s+/g, " ").trim() : "", l = (e) => Math.min(100, Math.max(0, Math.round(e))), u = (e) => `
13
+ ${e} .stack { isolation: isolate; }
14
+ ${e} .stack > img.top {
15
+ position: absolute; inset: 0; width: 100%; height: 100%;
16
+ max-width: none; max-height: none; margin: 0; opacity: 0; pointer-events: none;
17
+ }
18
+ ${e} .stack > img.top.on { opacity: 1; }
19
+ ${e} .compare-fade > img.top.on { opacity: var(--uvalib-compare-opacity, 1); }
20
+ ${e} .compare-wipe > img.top.on { clip-path: inset(0 calc(100% - var(--uvalib-compare, 50%)) 0 0); }
21
+ ${e} .compare-wipe:dir(rtl) > img.top.on { clip-path: inset(0 0 0 calc(100% - var(--uvalib-compare, 50%))); }
22
+ ${e} .compare-wipe { touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: col-resize; }
23
+ ${e} .compare-wipe img { -webkit-user-drag: none; }
24
+ ${e} .divider {
25
+ position: absolute; inset-block: 0; inset-inline-start: var(--uvalib-compare, 50%);
26
+ width: 0; pointer-events: none; forced-color-adjust: none;
27
+ }
28
+ ${e} .divider::before {
29
+ content: ''; position: absolute; inset-block: 0; inset-inline-start: -2px; width: 4px;
30
+ background: #fff; outline: 1px solid #000;
31
+ }
32
+ ${e} .handle {
33
+ position: absolute; top: 50%; inset-inline-start: -22px; box-sizing: border-box;
34
+ width: 44px; height: 44px; margin-top: -22px; border: 3px solid #000; border-radius: 50%;
35
+ background: #fff; outline: 2px solid #fff;
36
+ }
37
+ ${e} .handle::before, ${e} .handle::after {
38
+ content: ''; position: absolute; top: 50%; margin-top: -6px;
39
+ border-block: 6px solid transparent;
40
+ }
41
+ ${e} .handle::before { left: 7px; border-right: 8px solid #000; }
42
+ ${e} .handle::after { right: 7px; border-left: 8px solid #000; }
43
+ ${e} .side {
44
+ position: absolute; inset-block-end: 0.5rem; max-width: 40%; overflow: hidden;
45
+ padding: 0.125rem 0.5rem; background: #000; color: #fff; outline: 1px solid #fff;
46
+ font-size: 0.875rem; font-weight: 700; line-height: 1.3; white-space: nowrap;
47
+ text-overflow: ellipsis; pointer-events: none; forced-color-adjust: none;
48
+ }
49
+ ${e} .side-start { inset-inline-start: 0.5rem; }
50
+ ${e} .side-end { inset-inline-end: 0.5rem; }
51
+ ${e} .compare { display: flex; flex-direction: column; gap: 0.5rem; margin-block-start: 0.75rem; }
52
+ ${e} .compare-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
53
+ ${e} .mode-panels { display: grid; flex: 1 1 auto; min-width: 0; }
54
+ ${e} .mode-panel { grid-area: 1 / 1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
55
+ ${e} .mode-panel[data-off] { visibility: hidden; }
56
+ ${e} .seg-group { display: flex; flex-wrap: wrap; }
57
+ ${e} .slider { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; flex: 1 1 14rem; min-width: 0; }
58
+ ${e} .slider input { flex: 1 1 8rem; min-width: 0; min-height: 44px; margin: 0; }
59
+ ${e} .note { margin: 0; overflow-wrap: anywhere; }
60
+ ${e} .note[data-off] { visibility: hidden; }
61
+ ${e} .compare button.hold { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: none; }
62
+ @media (forced-colors: active) {
63
+ ${e} .divider::before { background: CanvasText; outline-color: Canvas; }
64
+ ${e} .handle { background: Canvas; border-color: Highlight; outline-color: Canvas; }
65
+ ${e} .handle::before { border-right-color: CanvasText; }
66
+ ${e} .handle::after { border-left-color: CanvasText; }
67
+ ${e} .side { background: CanvasText; color: Canvas; outline-color: Canvas; }
68
+ }
69
+ `, d = "var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))", f = "var(--uva-color-link, var(--uva-brand-blue, #232d4b))", p = (e) => `
70
+ ${e} .compare button.seg, ${e} .compare button.jump, ${e} .compare button.hold {
71
+ display: inline-flex; align-items: center; justify-content: center;
72
+ border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));
73
+ background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));
74
+ color: ${f}; font-size: 0.9375rem; font-weight: 600; line-height: 1.3;
75
+ }
76
+ ${e} .seg-group > button + button { margin-inline-start: -1px; }
77
+ ${e} .seg-group > button:first-child { border-start-start-radius: 0.3rem; border-end-start-radius: 0.3rem; }
78
+ ${e} .seg-group > button:last-child { border-start-end-radius: 0.3rem; border-end-end-radius: 0.3rem; }
79
+ ${e} .compare button.seg[aria-pressed='true'] {
80
+ position: relative; border-color: ${d}; background: ${d};
81
+ color: var(--uva-color-on-accent, #fff);
82
+ }
83
+ ${e} .compare button.seg[aria-pressed='true']::before {
84
+ content: ''; box-sizing: border-box; width: 0.375rem; height: 0.75rem;
85
+ margin-inline-end: 0.5rem; border: solid currentColor; border-width: 0 2px 2px 0;
86
+ transform: translateY(-0.0625rem) rotate(45deg);
87
+ }
88
+ ${e} .compare button:hover { border-color: ${f}; }
89
+ ${e} .compare button.seg[aria-pressed='true']:hover { border-color: ${d}; }
90
+ ${e} .compare button.hold[data-held] { background: var(--uva-color-surface-hover, #f1f1f1); }
91
+ ${e} .slider label { font-weight: 600; }
92
+ ${e} .slider input { accent-color: ${d}; }
93
+ ${e} .slider input:focus-visible {
94
+ outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
95
+ outline-offset: 2px;
96
+ }
97
+ ${e} .note { font-size: 0.9375rem; line-height: 1.5; }
98
+ @media (prefers-reduced-motion: no-preference) {
99
+ ${e} .compare-switch > img.top { transition: opacity 0.2s ease; }
100
+ }
101
+ @media (forced-colors: active) {
102
+ ${e} .compare button.seg, ${e} .compare button.jump, ${e} .compare button.hold { border-color: ButtonText; }
103
+ ${e} .compare button.seg[aria-pressed='true'] { background: Highlight; color: HighlightText; border-color: Highlight; }
104
+ }
105
+ `, m = /* @__PURE__ */ new WeakSet();
106
+ function h(e) {
107
+ let t = e.root;
108
+ if (e.light) {
109
+ let i = {
110
+ root: t,
111
+ scope: !1
112
+ };
113
+ r("uvalib-lightbox::compare-structure", n(u("uvalib-lightbox")), i), e.noStyle || r("uvalib-lightbox::compare", n(p("uvalib-lightbox")), i);
114
+ return;
115
+ }
116
+ if (!(t instanceof ShadowRoot) || m.has(t)) return;
117
+ m.add(t);
118
+ let i = u(":host") + (e.noStyle ? "" : p(":host")), a = n(i).styleSheet;
119
+ a && (t.adoptedStyleSheets = [...t.adoptedStyleSheets, a]);
120
+ }
121
+ var g = 0, _ = class {
122
+ constructor(e) {
123
+ this.host = e, this.list = [], this.slideKey = "", this.id = "", this.warned = !1, this.chosen = null, this.mode = "switch", this.other = 1, this.value = 50, this.shown = 0, this.holding = !1, this.requested = /* @__PURE__ */ new Set(), this.ready = /* @__PURE__ */ new Set(), this.failed = /* @__PURE__ */ new Set(), this.message = "", this.flip = !1, this.pendingAnnounce = !1, this.announceNext = !1, this.settleTimer = 0, this.settled = "", this.dragging = !1, this.dragEnd = 0, this.uid = `uvalib-compare-${++g}`, this.onInput = (e) => {
124
+ this.set(Number(e.target.value), !1);
125
+ }, this.onSliderKey = (e) => {
126
+ let t = getComputedStyle(e.target).direction === "rtl", n = e.key, r = 0;
127
+ n === "PageUp" ? r = 10 : n === "PageDown" ? r = -10 : e.shiftKey && (n === "ArrowUp" || n === "ArrowDown") ? r = n === "ArrowUp" ? 10 : -10 : e.shiftKey && (n === "ArrowLeft" || n === "ArrowRight") && (r = n === "ArrowRight" === t ? -10 : 10), r && (e.preventDefault(), this.set(this.value + r, !1));
128
+ }, this.onHold = (e) => {
129
+ let t = e.type;
130
+ if (t === "keydown" || t === "keyup") {
131
+ let n = e.key;
132
+ if (n !== " " && n !== "Enter") return;
133
+ this.hold(t === "keydown");
134
+ } else this.hold(t === "pointerdown");
135
+ }, h(e);
136
+ }
137
+ get active() {
138
+ return this.list.length > 1;
139
+ }
140
+ sync(e, t, n) {
141
+ let r = `${t}\n${e.href}\n${JSON.stringify(e.versions)}`;
142
+ r !== this.slideKey && (this.reset(), this.slideKey = r, this.id = e.id, this.list = this.parse(e), this.mode = this.chosen ?? (a.includes(this.host.mode()) ? this.host.mode() : "switch"), this.value = this.mode === "wipe" ? 50 : 0, this.need(), this.settled = this.encode()), n != null && this.active && this.restore(n);
143
+ }
144
+ reset() {
145
+ this.settleTimer && this.settle(!1), this.slideKey = "", this.list = [], this.other = 1, this.shown = 0, this.holding = !1, this.dragging = !1, this.requested = /* @__PURE__ */ new Set(), this.ready = /* @__PURE__ */ new Set(), this.failed = /* @__PURE__ */ new Set(), this.message = "", this.pendingAnnounce = !1;
146
+ }
147
+ parse(e) {
148
+ let t = e.versions, n = !1;
149
+ if (typeof t == "string") try {
150
+ t = JSON.parse(t);
151
+ } catch {
152
+ t = null, n = !0;
153
+ }
154
+ let r = [];
155
+ return Array.isArray(t) ? t.forEach((t, i) => {
156
+ let a = t && typeof t == "object" ? t : {}, o = c(a.label) || (i === 0 ? "Original" : ""), s = i === 0 ? e.href : c(a.href);
157
+ o && s && this.host.size(s) ? r.push({
158
+ label: o,
159
+ href: s,
160
+ note: c(a.note)
161
+ }) : i === 0 ? r.length = 0 : n = !0;
162
+ }) : n = !0, n && !this.warned && (this.warned = !0, console.warn("uvalib-lightbox: data-versions (or the versions callback) has entries without a label or a usable href; they are left out.")), r.length > 1 ? r : [];
163
+ }
164
+ restore(e) {
165
+ let t = /^(?:(switch|wipe|fade):)?(\d{1,3})(?::(\d{1,3}))?$/.exec(e.trim().toLowerCase());
166
+ if (!t) return;
167
+ let n = t[1] ?? "switch", r = Number(t[2]);
168
+ if (n === "switch") {
169
+ if (r >= this.list.length) return;
170
+ this.shown = r;
171
+ } else {
172
+ let e = t[3] ? Number(t[3]) : 1;
173
+ this.other = e >= 1 && e < this.list.length ? e : 1, this.value = l(r);
174
+ }
175
+ this.mode = this.chosen = n, this.need(), this.settled = this.encode();
176
+ }
177
+ encode() {
178
+ return this.mode === "switch" ? String(this.shown) : `${this.mode}:${this.value}${this.other === 1 ? "" : `:${this.other}`}`;
179
+ }
180
+ get top() {
181
+ return this.mode === "switch" ? this.shown : this.other;
182
+ }
183
+ get amount() {
184
+ return this.holding ? 0 : this.mode === "switch" ? this.shown > 0 ? 100 : 0 : this.value;
185
+ }
186
+ get seen() {
187
+ return this.top > 0 && this.ready.has(this.top) ? this.amount : 0;
188
+ }
189
+ label(e) {
190
+ return this.list[e]?.label ?? "";
191
+ }
192
+ need() {
193
+ this.amount > 0 && this.top > 0 && this.requested.add(this.top);
194
+ }
195
+ set(e, t) {
196
+ let n = l(e);
197
+ n !== this.value && (this.value = n, this.need(), this.host.update(), this.announceNext ||= t, window.clearTimeout(this.settleTimer), this.settleTimer = window.setTimeout(() => this.settle(), s.settle));
198
+ }
199
+ change(e) {
200
+ e(), this.need(), this.host.update(), this.announceNext = !0, this.settle();
201
+ }
202
+ settle(e = !0) {
203
+ window.clearTimeout(this.settleTimer), this.settleTimer = 0;
204
+ let t = this.encode(), n = this.announceNext;
205
+ if (this.announceNext = !1, t === this.settled || !this.active) return;
206
+ this.settled = t;
207
+ let r = this.top, a = this.host.el;
208
+ a.dispatchEvent(new CustomEvent("uvalib-lightbox-version", {
209
+ detail: {
210
+ id: this.id,
211
+ mode: this.mode,
212
+ index: r,
213
+ value: this.mode === "switch" ? null : this.value
214
+ },
215
+ bubbles: !0,
216
+ composed: !0
217
+ })), i(a, [
218
+ "uvalib-lightbox",
219
+ "compare",
220
+ this.mode,
221
+ r + 1
222
+ ]), e && (this.host.write(t), n && (this.amount > 0 && !this.ready.has(this.top) ? this.pendingAnnounce = !0 : this.say(this.stateText())));
223
+ }
224
+ say(e) {
225
+ this.pendingAnnounce = !1, this.flip = !this.flip, this.message = e + (this.flip ? "\xA0" : ""), this.host.update();
226
+ }
227
+ stateText() {
228
+ let e = this.amount;
229
+ return e <= 0 ? `${this.label(0)} shown` : e >= 100 ? `${this.label(this.top)} shown` : `${e}% ${this.label(this.top)}`;
230
+ }
231
+ setMode(e) {
232
+ e !== this.mode && this.change(() => {
233
+ e === "switch" ? this.shown = this.value >= 50 ? this.other : 0 : this.mode === "switch" && (this.shown > 0 && (this.other = this.shown), this.value = e === "wipe" ? 50 : this.shown > 0 ? 100 : 0), this.mode = this.chosen = e;
234
+ });
235
+ }
236
+ hold(e) {
237
+ e !== this.holding && (this.holding = e, this.host.update());
238
+ }
239
+ loaded(e) {
240
+ this.ready.add(e), this.host.update(), this.pendingAnnounce && e === this.top && this.say(this.stateText());
241
+ }
242
+ errored(e) {
243
+ this.failed.add(e), this.pendingAnnounce = !1, this.say(`${this.label(e)} could not be loaded.`);
244
+ }
245
+ key(e) {
246
+ return !this.active || e.key !== "o" && e.key !== "O" || e.altKey || e.ctrlKey || e.metaKey ? !1 : (this.hold(e.type === "keydown"), !0);
247
+ }
248
+ pointer(e) {
249
+ if (!this.active || this.mode !== "wipe") return;
250
+ let t = e.currentTarget;
251
+ if (e.type === "pointerdown") {
252
+ if (e.button !== 0 || !e.isPrimary) return;
253
+ this.dragging = !0;
254
+ try {
255
+ t.setPointerCapture(e.pointerId);
256
+ } catch {}
257
+ e.preventDefault();
258
+ } else if (e.type !== "pointermove") {
259
+ this.dragging && (this.dragEnd = performance.now()), this.dragging = !1;
260
+ return;
261
+ }
262
+ if (!this.dragging) return;
263
+ let n = t.getBoundingClientRect();
264
+ if (!n.width) return;
265
+ let r = getComputedStyle(t).direction === "rtl";
266
+ this.set((r ? n.right - e.clientX : e.clientX - n.left) / n.width * 100, !0);
267
+ }
268
+ dragged() {
269
+ return this.dragging || performance.now() - this.dragEnd < 100;
270
+ }
271
+ alt(e) {
272
+ let t = this.seen, n = this.label(0), r = this.label(this.top);
273
+ return `${e} (${t <= 0 ? n : t >= 100 ? r : `${n} and ${r}, ${this.mode === "wipe" ? "compared side by side" : "blended"}`})`;
274
+ }
275
+ get stackClass() {
276
+ return `compare-${this.mode}`;
277
+ }
278
+ get stackStyle() {
279
+ let e = this.mode === "switch" ? 100 : this.value;
280
+ return `--uvalib-compare: ${e}%; --uvalib-compare-opacity: ${e / 100}`;
281
+ }
282
+ layers() {
283
+ let n = this.top, r = this.seen > 0, i = this.list.map((i, a) => a === 0 ? t : e`<img
284
+ class="top ${a === n && r ? "on" : ""}"
285
+ data-version=${a}
286
+ alt=""
287
+ decoding="async"
288
+ draggable="false"
289
+ src=${this.requested.has(a) ? this.host.size(i.href) : t}
290
+ @load=${() => this.loaded(a)}
291
+ @error=${() => this.errored(a)}
292
+ />`);
293
+ if (this.mode !== "wipe") return i;
294
+ let a = this.seen;
295
+ return e`${i}
296
+ <div class="divider" aria-hidden="true"><span class="handle"></span></div>
297
+ <span class="side side-start" aria-hidden="true" ?hidden=${a <= 0}>${this.label(n)}</span>
298
+ <span class="side side-end" aria-hidden="true" ?hidden=${a >= 100}>${this.label(0)}</span>`;
299
+ }
300
+ controls(n) {
301
+ let r = this.seen, i = this.top, s = (e) => e === 0 ? r < 100 : e === i && r > 0, c = this.list.map((n, r) => n.note ? e`<p class="note" ?data-off=${!s(r)}><strong>${n.label}:</strong> ${n.note}</p>` : t), l = this.failed.has(i) && this.amount > 0 ? e`<p class="note">${this.label(i)} could not be loaded.</p>` : t, u = (t, n, r) => e`<button
302
+ type="button"
303
+ class="seg"
304
+ aria-pressed=${t ? "true" : "false"}
305
+ @click=${r}
306
+ >
307
+ ${n}
308
+ </button>`, d = this.label(0), f = this.label(this.other), p = this.mode === "switch", m = (t, n) => e`<div class="mode-panel" ?inert=${!t} ?data-off=${!t}>${n}</div>`, h = e`<div class="seg-group" role="group" aria-label="Version shown">
309
+ ${this.list.map((e, t) => u(this.shown === t, e.label, () => this.change(() => this.shown = t)))}
310
+ </div>`, g = e`${this.list.length > 2 ? e`<div class="seg-group" role="group" aria-label="Compare ${d} with">
311
+ ${this.list.map((e, n) => n ? u(this.other === n, e.label, () => this.change(() => this.other = n)) : t)}
312
+ </div>` : t}
313
+ <div class="slider">
314
+ <label for=${this.uid}>${this.mode === "fade" ? "Fade to" : "Reveal"} ${f}</label>
315
+ <input
316
+ id=${this.uid}
317
+ type="range"
318
+ min="0"
319
+ max="100"
320
+ step="1"
321
+ .value=${String(this.value)}
322
+ aria-valuetext="${this.value}% ${f}"
323
+ @input=${this.onInput}
324
+ @keydown=${this.onSliderKey}
325
+ />
326
+ </div>
327
+ <div class="seg-group" role="group" aria-label="Jump to">
328
+ ${[
329
+ [0, d],
330
+ [50, "50/50"],
331
+ [100, f]
332
+ ].map(([t, n]) => e`<button
333
+ type="button"
334
+ class="jump"
335
+ @click=${() => this.change(() => this.value = t)}
336
+ >
337
+ ${n}
338
+ </button>`)}
339
+ </div>
340
+ <button
341
+ type="button"
342
+ class="hold"
343
+ aria-keyshortcuts="O"
344
+ ?data-held=${this.holding}
345
+ @pointerdown=${this.onHold}
346
+ @pointerup=${this.onHold}
347
+ @pointerleave=${this.onHold}
348
+ @pointercancel=${this.onHold}
349
+ @keydown=${this.onHold}
350
+ @keyup=${this.onHold}
351
+ @blur=${() => this.hold(!1)}
352
+ @contextmenu=${(e) => e.preventDefault()}
353
+ >
354
+ Hold for ${d}
355
+ </button>`;
356
+ return e`<div class="compare" part="compare" slot=${n || t}>
357
+ ${c}${l}
358
+ <div class="compare-bar">
359
+ <div class="seg-group" role="group" aria-label="Compare versions">
360
+ ${a.map((e) => u(this.mode === e, o[e], () => this.setMode(e)))}
361
+ </div>
362
+ <div class="mode-panels">${m(p, h)}${m(!p, g)}</div>
363
+ </div>
364
+ <p class="visually-hidden" role="status">${this.message}</p>
365
+ </div>`;
366
+ }
367
+ full() {
368
+ return [0, this.mode === "switch" && this.shown || this.other].map((e) => ({
369
+ href: this.list[e].href,
370
+ label: this.label(e)
371
+ }));
372
+ }
373
+ };
374
+ export { _ as Compare, s as compareTiming };
375
+
376
+ //# sourceMappingURL=compare-D4VdaIJN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-D4VdaIJN.js","names":["unsafeCSS","nothing","b","A","r","trackEvent","MODES","MODE_NAMES","compareTiming","norm","s","clamp","n","structure","h","ACCENT","LINK","look","styled","install","root","host","opts","installLightDomStyles","text","sheet","nextId","Compare","rtl","k","d","key","index","slide","restore","raw","bad","out","o","v","label","href","m","param","mode","other","i","next","announce","fn","state","el","write","a","on","stack","l0","lk","base","top","layers","visible","notes","failed","seg","pressed","onClick","switching","panel","body","switchPanel","sliding","slot"],"sources":["../../src/components/uvalib-lightbox/compare.ts"],"sourcesContent":["/**\n * Versions of an image compared over the photo: Switch, Reveal (a wipe) and Fade. Loaded by\n * `<uvalib-lightbox>` the first time an open image has versions, so pages without them never\n * load it.\n */\nimport { html, nothing, unsafeCSS } from 'lit';\nimport { trackEvent } from '../../base/analytics.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\n\nexport type CompareMode = 'switch' | 'wipe' | 'fade';\n\nconst MODES: CompareMode[] = ['switch', 'wipe', 'fade'];\nconst MODE_NAMES: Record<CompareMode, string> = {\n switch: 'Switch',\n wipe: 'Reveal',\n fade: 'Fade',\n};\n\n/** How long (ms) after the last slider or drag change it counts as settled. Tests shorten it. */\nexport const compareTiming = { settle: 400 };\n\ninterface Version {\n label: string;\n href: string;\n note: string;\n}\n\n/** What the lightbox lends the comparison. */\nexport interface CompareHost {\n el: HTMLElement;\n light: boolean;\n root: Node;\n noStyle: boolean;\n /** The `compare` attribute: the first mode. */\n mode(): string;\n /** The URL the viewer would load for `href` ('' when it may not be shown). */\n size(href: string): string;\n /** Write the comparison to `version-param` (replaceState). */\n write(value: string | null): void;\n update(): void;\n}\n\n/** The parts of a lightbox slide the comparison reads. */\nexport interface CompareSlide {\n id: string;\n href: string;\n versions: string | unknown[] | null;\n}\n\nconst norm = (s: unknown) => (typeof s === 'string' ? s.replace(/\\s+/g, ' ').trim() : '');\nconst clamp = (n: number) => Math.min(100, Math.max(0, Math.round(n)));\n\n/**\n * Kept with `no-style`: the stacked layers, the clip and fade, the divider and its handle\n * (white inside black, so it shows on any photo), the side labels and the control layout.\n * `h` is `:host` (shadow) or the tag (light DOM).\n */\nconst structure = (h: string) => `\n ${h} .stack { isolation: isolate; }\n ${h} .stack > img.top {\n position: absolute; inset: 0; width: 100%; height: 100%;\n max-width: none; max-height: none; margin: 0; opacity: 0; pointer-events: none;\n }\n ${h} .stack > img.top.on { opacity: 1; }\n ${h} .compare-fade > img.top.on { opacity: var(--uvalib-compare-opacity, 1); }\n ${h} .compare-wipe > img.top.on { clip-path: inset(0 calc(100% - var(--uvalib-compare, 50%)) 0 0); }\n ${h} .compare-wipe:dir(rtl) > img.top.on { clip-path: inset(0 0 0 calc(100% - var(--uvalib-compare, 50%))); }\n ${h} .compare-wipe { touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: col-resize; }\n ${h} .compare-wipe img { -webkit-user-drag: none; }\n ${h} .divider {\n position: absolute; inset-block: 0; inset-inline-start: var(--uvalib-compare, 50%);\n width: 0; pointer-events: none; forced-color-adjust: none;\n }\n ${h} .divider::before {\n content: ''; position: absolute; inset-block: 0; inset-inline-start: -2px; width: 4px;\n background: #fff; outline: 1px solid #000;\n }\n ${h} .handle {\n position: absolute; top: 50%; inset-inline-start: -22px; box-sizing: border-box;\n width: 44px; height: 44px; margin-top: -22px; border: 3px solid #000; border-radius: 50%;\n background: #fff; outline: 2px solid #fff;\n }\n ${h} .handle::before, ${h} .handle::after {\n content: ''; position: absolute; top: 50%; margin-top: -6px;\n border-block: 6px solid transparent;\n }\n ${h} .handle::before { left: 7px; border-right: 8px solid #000; }\n ${h} .handle::after { right: 7px; border-left: 8px solid #000; }\n ${h} .side {\n position: absolute; inset-block-end: 0.5rem; max-width: 40%; overflow: hidden;\n padding: 0.125rem 0.5rem; background: #000; color: #fff; outline: 1px solid #fff;\n font-size: 0.875rem; font-weight: 700; line-height: 1.3; white-space: nowrap;\n text-overflow: ellipsis; pointer-events: none; forced-color-adjust: none;\n }\n ${h} .side-start { inset-inline-start: 0.5rem; }\n ${h} .side-end { inset-inline-end: 0.5rem; }\n ${h} .compare { display: flex; flex-direction: column; gap: 0.5rem; margin-block-start: 0.75rem; }\n ${h} .compare-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }\n ${h} .mode-panels { display: grid; flex: 1 1 auto; min-width: 0; }\n ${h} .mode-panel { grid-area: 1 / 1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }\n ${h} .mode-panel[data-off] { visibility: hidden; }\n ${h} .seg-group { display: flex; flex-wrap: wrap; }\n ${h} .slider { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; flex: 1 1 14rem; min-width: 0; }\n ${h} .slider input { flex: 1 1 8rem; min-width: 0; min-height: 44px; margin: 0; }\n ${h} .note { margin: 0; overflow-wrap: anywhere; }\n ${h} .note[data-off] { visibility: hidden; }\n ${h} .compare button.hold { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: none; }\n @media (forced-colors: active) {\n ${h} .divider::before { background: CanvasText; outline-color: Canvas; }\n ${h} .handle { background: Canvas; border-color: Highlight; outline-color: Canvas; }\n ${h} .handle::before { border-right-color: CanvasText; }\n ${h} .handle::after { border-left-color: CanvasText; }\n ${h} .side { background: CanvasText; color: Canvas; outline-color: Canvas; }\n }\n`;\n\nconst ACCENT = 'var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b))';\nconst LINK = 'var(--uva-color-link, var(--uva-brand-blue, #232d4b))';\n\n/** The look: segmented buttons like `<uvalib-chip-group segmented>`, the slider's accent. */\nconst look = (h: string) => `\n ${h} .compare button.seg, ${h} .compare button.jump, ${h} .compare button.hold {\n display: inline-flex; align-items: center; justify-content: center;\n border: 1px solid var(--uva-color-control-border, var(--uva-grey, #808080));\n background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));\n color: ${LINK}; font-size: 0.9375rem; font-weight: 600; line-height: 1.3;\n }\n ${h} .seg-group > button + button { margin-inline-start: -1px; }\n ${h} .seg-group > button:first-child { border-start-start-radius: 0.3rem; border-end-start-radius: 0.3rem; }\n ${h} .seg-group > button:last-child { border-start-end-radius: 0.3rem; border-end-end-radius: 0.3rem; }\n ${h} .compare button.seg[aria-pressed='true'] {\n position: relative; border-color: ${ACCENT}; background: ${ACCENT};\n color: var(--uva-color-on-accent, #fff);\n }\n ${h} .compare button.seg[aria-pressed='true']::before {\n content: ''; box-sizing: border-box; width: 0.375rem; height: 0.75rem;\n margin-inline-end: 0.5rem; border: solid currentColor; border-width: 0 2px 2px 0;\n transform: translateY(-0.0625rem) rotate(45deg);\n }\n ${h} .compare button:hover { border-color: ${LINK}; }\n ${h} .compare button.seg[aria-pressed='true']:hover { border-color: ${ACCENT}; }\n ${h} .compare button.hold[data-held] { background: var(--uva-color-surface-hover, #f1f1f1); }\n ${h} .slider label { font-weight: 600; }\n ${h} .slider input { accent-color: ${ACCENT}; }\n ${h} .slider input:focus-visible {\n outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));\n outline-offset: 2px;\n }\n ${h} .note { font-size: 0.9375rem; line-height: 1.5; }\n @media (prefers-reduced-motion: no-preference) {\n ${h} .compare-switch > img.top { transition: opacity 0.2s ease; }\n }\n @media (forced-colors: active) {\n ${h} .compare button.seg, ${h} .compare button.jump, ${h} .compare button.hold { border-color: ButtonText; }\n ${h} .compare button.seg[aria-pressed='true'] { background: Highlight; color: HighlightText; border-color: Highlight; }\n }\n`;\n\n/** Shadow roots that already have the comparison's sheets. */\nconst styled = new WeakSet<Node>();\n\nfunction install(host: CompareHost): void {\n const root = host.root;\n if (host.light) {\n const opts = { root: root as Document | ShadowRoot, scope: false };\n installLightDomStyles(\n 'uvalib-lightbox::compare-structure',\n unsafeCSS(structure('uvalib-lightbox')),\n opts,\n );\n if (!host.noStyle)\n installLightDomStyles('uvalib-lightbox::compare', unsafeCSS(look('uvalib-lightbox')), opts);\n return;\n }\n if (!(root instanceof ShadowRoot) || styled.has(root)) return;\n styled.add(root);\n const text = structure(':host') + (host.noStyle ? '' : look(':host'));\n const sheet = unsafeCSS(text).styleSheet;\n if (sheet) root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n}\n\nlet nextId = 0;\n\n/**\n * The comparison for one lightbox. State: the mode, the version shown (Switch) or compared\n * with the original (Reveal, Fade), and the percentage of it shown. Another version's image\n * is requested the first time it is needed, and drawn (and announced) once it has loaded.\n */\nexport class Compare {\n private list: Version[] = [];\n private slideKey = '';\n private id = '';\n private warned = false;\n /** The mode the visitor (or the address) chose; else the lightbox's `compare`. */\n private chosen: CompareMode | null = null;\n mode: CompareMode = 'switch';\n /** The version compared with the original (Reveal, Fade), from 1. */\n private other = 1;\n /** The percentage of `other` shown (Reveal, Fade). */\n private value = 50;\n /** The version shown (Switch), from 0. */\n private shown = 0;\n private holding = false;\n private requested = new Set<number>();\n private ready = new Set<number>();\n private failed = new Set<number>();\n private message = '';\n private flip = false;\n private pendingAnnounce = false;\n private announceNext = false;\n private settleTimer = 0;\n private settled = '';\n private dragging = false;\n private dragEnd = 0;\n private readonly uid = `uvalib-compare-${++nextId}`;\n\n constructor(private readonly host: CompareHost) {\n install(host);\n }\n\n /** At least two usable versions. */\n get active(): boolean {\n return this.list.length > 1;\n }\n\n /** Follow the open image: a new one starts again (in the current mode); `restore` is the address's value. */\n sync(slide: CompareSlide, index: number, restore: string | null): void {\n const key = `${index}\\n${slide.href}\\n${JSON.stringify(slide.versions)}`;\n if (key !== this.slideKey) {\n this.reset();\n this.slideKey = key;\n this.id = slide.id;\n this.list = this.parse(slide);\n this.mode =\n this.chosen ??\n (MODES.includes(this.host.mode() as CompareMode)\n ? (this.host.mode() as CompareMode)\n : 'switch');\n this.value = this.mode === 'wipe' ? 50 : 0;\n this.need();\n this.settled = this.encode();\n }\n if (restore != null && this.active) this.restore(restore);\n }\n\n /** Forget the open image (the viewer closed): report a change still settling first. */\n reset(): void {\n // Its event and analytics, but not the address: that is the next image's now.\n if (this.settleTimer) this.settle(false);\n this.slideKey = '';\n this.list = [];\n this.other = 1;\n this.shown = 0;\n this.holding = false;\n this.dragging = false;\n this.requested = new Set();\n this.ready = new Set();\n this.failed = new Set();\n this.message = '';\n this.pendingAnnounce = false;\n }\n\n private parse(slide: CompareSlide): Version[] {\n let raw: unknown = slide.versions;\n let bad = false;\n if (typeof raw === 'string') {\n try {\n raw = JSON.parse(raw);\n } catch {\n raw = null;\n bad = true;\n }\n }\n const out: Version[] = [];\n if (Array.isArray(raw)) {\n raw.forEach((v: unknown, i) => {\n const o = v && typeof v === 'object' ? (v as Record<string, unknown>) : {};\n const label = norm(o.label) || (i === 0 ? 'Original' : '');\n const href = i === 0 ? slide.href : norm(o.href);\n if (label && href && this.host.size(href)) out.push({ label, href, note: norm(o.note) });\n else if (i === 0) out.length = 0;\n else bad = true;\n });\n } else bad = true;\n if (bad && !this.warned) {\n this.warned = true;\n console.warn(\n 'uvalib-lightbox: data-versions (or the versions callback) has entries without a label or a usable href; they are left out.',\n );\n }\n return out.length > 1 ? out : [];\n }\n\n /** `2`, `switch:2`, `wipe:40`, `fade:60`, `wipe:40:2` (the version compared, from 1). */\n private restore(param: string): void {\n const m = /^(?:(switch|wipe|fade):)?(\\d{1,3})(?::(\\d{1,3}))?$/.exec(param.trim().toLowerCase());\n if (!m) return;\n const mode = (m[1] ?? 'switch') as CompareMode;\n const n = Number(m[2]);\n if (mode === 'switch') {\n if (n >= this.list.length) return;\n this.shown = n;\n } else {\n const other = m[3] ? Number(m[3]) : 1;\n this.other = other >= 1 && other < this.list.length ? other : 1;\n this.value = clamp(n);\n }\n this.mode = this.chosen = mode;\n this.need();\n this.settled = this.encode();\n }\n\n private encode(): string {\n if (this.mode === 'switch') return String(this.shown);\n return `${this.mode}:${this.value}${this.other !== 1 ? `:${this.other}` : ''}`;\n }\n\n /** The version over the original: shown (Switch) or compared (Reveal, Fade). */\n private get top(): number {\n return this.mode === 'switch' ? this.shown : this.other;\n }\n\n /** The percentage of the top version asked for. */\n private get amount(): number {\n if (this.holding) return 0;\n if (this.mode === 'switch') return this.shown > 0 ? 100 : 0;\n return this.value;\n }\n\n /** The percentage of it on screen: none until its image has loaded. */\n private get seen(): number {\n return this.top > 0 && this.ready.has(this.top) ? this.amount : 0;\n }\n\n private label(i: number): string {\n return this.list[i]?.label ?? '';\n }\n\n /** Request the top version's image the first time it is needed. */\n private need(): void {\n if (this.amount > 0 && this.top > 0) this.requested.add(this.top);\n }\n\n // ------------------------------------------------------------ changes\n\n private set(v: number, announce: boolean): void {\n const next = clamp(v);\n if (next === this.value) return;\n this.value = next;\n this.need();\n this.host.update();\n this.announceNext ||= announce;\n window.clearTimeout(this.settleTimer);\n this.settleTimer = window.setTimeout(() => this.settle(), compareTiming.settle);\n }\n\n private change(fn: () => void): void {\n fn();\n this.need();\n this.host.update();\n this.announceNext = true;\n this.settle();\n }\n\n /** A visitor's change has settled: the event, analytics, the address and the announcement. */\n private settle(write = true): void {\n window.clearTimeout(this.settleTimer);\n this.settleTimer = 0;\n const state = this.encode();\n const announce = this.announceNext;\n this.announceNext = false;\n if (state === this.settled || !this.active) return;\n this.settled = state;\n const index = this.top;\n const el = this.host.el;\n el.dispatchEvent(\n new CustomEvent('uvalib-lightbox-version', {\n detail: {\n id: this.id,\n mode: this.mode,\n index,\n value: this.mode === 'switch' ? null : this.value,\n },\n bubbles: true,\n composed: true,\n }),\n );\n trackEvent(el, ['uvalib-lightbox', 'compare', this.mode, index + 1]);\n if (!write) return;\n this.host.write(state);\n if (!announce) return;\n if (this.amount > 0 && !this.ready.has(this.top)) this.pendingAnnounce = true;\n else this.say(this.stateText());\n }\n\n private say(text: string): void {\n this.pendingAnnounce = false;\n // A repeated message is still a change, so it is read again.\n this.flip = !this.flip;\n this.message = text + (this.flip ? ' ' : '');\n this.host.update();\n }\n\n private stateText(): string {\n const a = this.amount;\n if (a <= 0) return `${this.label(0)} shown`;\n if (a >= 100) return `${this.label(this.top)} shown`;\n return `${a}% ${this.label(this.top)}`;\n }\n\n private setMode(mode: CompareMode): void {\n if (mode === this.mode) return;\n this.change(() => {\n if (mode === 'switch') this.shown = this.value >= 50 ? this.other : 0;\n else if (this.mode === 'switch') {\n if (this.shown > 0) this.other = this.shown;\n this.value = mode === 'wipe' ? 50 : this.shown > 0 ? 100 : 0;\n }\n this.mode = this.chosen = mode;\n });\n }\n\n private hold(on: boolean): void {\n if (on === this.holding) return;\n this.holding = on;\n this.host.update();\n }\n\n private loaded(i: number): void {\n this.ready.add(i);\n this.host.update();\n if (this.pendingAnnounce && i === this.top) this.say(this.stateText());\n }\n\n private errored(i: number): void {\n this.failed.add(i);\n this.pendingAnnounce = false;\n this.say(`${this.label(i)} could not be loaded.`);\n }\n\n // ------------------------------------------------------------ input\n\n /** The `o` key held anywhere in the dialog shows the original. True when handled. */\n key(e: KeyboardEvent): boolean {\n if (!this.active || (e.key !== 'o' && e.key !== 'O') || e.altKey || e.ctrlKey || e.metaKey)\n return false;\n this.hold(e.type === 'keydown');\n return true;\n }\n\n /** A press on the photo in Reveal moves the divider there; a drag keeps moving it. */\n pointer(e: PointerEvent): void {\n if (!this.active || this.mode !== 'wipe') return;\n const stack = e.currentTarget as HTMLElement;\n if (e.type === 'pointerdown') {\n if (e.button !== 0 || !e.isPrimary) return;\n this.dragging = true;\n try {\n stack.setPointerCapture(e.pointerId);\n } catch {\n // A synthetic pointer cannot be captured; the press still moves the divider.\n }\n e.preventDefault();\n } else if (e.type !== 'pointermove') {\n if (this.dragging) this.dragEnd = performance.now();\n this.dragging = false;\n return;\n }\n if (!this.dragging) return;\n const r = stack.getBoundingClientRect();\n if (!r.width) return;\n const rtl = getComputedStyle(stack).direction === 'rtl';\n this.set(((rtl ? r.right - e.clientX : e.clientX - r.left) / r.width) * 100, true);\n }\n\n /** A drag that ended outside the photo must not count as a click on the backdrop. */\n dragged(): boolean {\n return this.dragging || performance.now() - this.dragEnd < 100;\n }\n\n private readonly onInput = (e: Event): void => {\n this.set(Number((e.target as HTMLInputElement).value), false);\n };\n\n /** Shift with an arrow, and Page Up / Page Down, move 10%. */\n private readonly onSliderKey = (e: KeyboardEvent): void => {\n const rtl = getComputedStyle(e.target as Element).direction === 'rtl';\n const k = e.key;\n let d = 0;\n if (k === 'PageUp') d = 10;\n else if (k === 'PageDown') d = -10;\n else if (e.shiftKey && (k === 'ArrowUp' || k === 'ArrowDown')) d = k === 'ArrowUp' ? 10 : -10;\n else if (e.shiftKey && (k === 'ArrowLeft' || k === 'ArrowRight'))\n d = (k === 'ArrowRight') !== rtl ? 10 : -10;\n if (!d) return;\n e.preventDefault();\n this.set(this.value + d, false);\n };\n\n private readonly onHold = (e: Event): void => {\n const t = e.type;\n if (t === 'keydown' || t === 'keyup') {\n const k = (e as KeyboardEvent).key;\n if (k !== ' ' && k !== 'Enter') return;\n this.hold(t === 'keydown');\n } else this.hold(t === 'pointerdown');\n };\n\n // ------------------------------------------------------------ render\n\n /** The image's accessible name ends with what is on screen. */\n alt(base: string): string {\n const a = this.seen;\n const l0 = this.label(0);\n const lk = this.label(this.top);\n const what =\n a <= 0\n ? l0\n : a >= 100\n ? lk\n : `${l0} and ${lk}, ${this.mode === 'wipe' ? 'compared side by side' : 'blended'}`;\n return `${base} (${what})`;\n }\n\n get stackClass(): string {\n return `compare-${this.mode}`;\n }\n\n get stackStyle(): string {\n const a = this.mode === 'switch' ? 100 : this.value;\n return `--uvalib-compare: ${a}%; --uvalib-compare-opacity: ${a / 100}`;\n }\n\n /** The other versions' images (each requested on first use), the divider and the side labels. */\n layers() {\n const top = this.top;\n const on = this.seen > 0;\n const layers = this.list.map((v, i) =>\n i === 0\n ? nothing\n : html`<img\n class=\"top ${i === top && on ? 'on' : ''}\"\n data-version=${i}\n alt=\"\"\n decoding=\"async\"\n draggable=\"false\"\n src=${this.requested.has(i) ? this.host.size(v.href) : nothing}\n @load=${() => this.loaded(i)}\n @error=${() => this.errored(i)}\n />`,\n );\n if (this.mode !== 'wipe') return layers;\n const a = this.seen;\n return html`${layers}\n <div class=\"divider\" aria-hidden=\"true\"><span class=\"handle\"></span></div>\n <span class=\"side side-start\" aria-hidden=\"true\" ?hidden=${a <= 0}>${this.label(top)}</span>\n <span class=\"side side-end\" aria-hidden=\"true\" ?hidden=${a >= 100}>${this.label(0)}</span>`;\n }\n\n /** Notes of the versions on screen, then the controls. `slot` puts them under regions' image. */\n controls(slot: string) {\n const a = this.seen;\n const top = this.top;\n // Every note keeps its line (hidden while its version is not on screen), so showing\n // another version never moves the photo or the controls.\n const visible = (i: number) => (i === 0 ? a < 100 : i === top && a > 0);\n const notes = this.list.map((v, i) =>\n v.note\n ? html`<p class=\"note\" ?data-off=${!visible(i)}><strong>${v.label}:</strong> ${v.note}</p>`\n : nothing,\n );\n const failed =\n this.failed.has(top) && this.amount > 0\n ? html`<p class=\"note\">${this.label(top)} could not be loaded.</p>`\n : nothing;\n const seg = (pressed: boolean, text: string, onClick: () => void) =>\n html`<button\n type=\"button\"\n class=\"seg\"\n aria-pressed=${pressed ? 'true' : 'false'}\n @click=${onClick}\n >\n ${text}\n </button>`;\n const l0 = this.label(0);\n const lk = this.label(this.other);\n // Both panels are always drawn, in one grid cell: the row is as tall as the taller one,\n // so changing mode never moves the photo (the dialog re-centres on any height change).\n // The other panel is inert and hidden, out of the tab order and the accessibility tree.\n const switching = this.mode === 'switch';\n const panel = (on: boolean, body: unknown) =>\n html`<div class=\"mode-panel\" ?inert=${!on} ?data-off=${!on}>${body}</div>`;\n const switchPanel = html`<div class=\"seg-group\" role=\"group\" aria-label=\"Version shown\">\n ${this.list.map((v, i) =>\n seg(this.shown === i, v.label, () => this.change(() => (this.shown = i))),\n )}\n </div>`;\n const sliding = html`${\n this.list.length > 2\n ? html`<div class=\"seg-group\" role=\"group\" aria-label=\"Compare ${l0} with\">\n ${this.list.map((v, i) =>\n i\n ? seg(this.other === i, v.label, () => this.change(() => (this.other = i)))\n : nothing,\n )}\n </div>`\n : nothing\n }\n <div class=\"slider\">\n <label for=${this.uid}>${this.mode === 'fade' ? 'Fade to' : 'Reveal'} ${lk}</label>\n <input\n id=${this.uid}\n type=\"range\"\n min=\"0\"\n max=\"100\"\n step=\"1\"\n .value=${String(this.value)}\n aria-valuetext=\"${this.value}% ${lk}\"\n @input=${this.onInput}\n @keydown=${this.onSliderKey}\n />\n </div>\n <div class=\"seg-group\" role=\"group\" aria-label=\"Jump to\">\n ${[\n [0, l0],\n [50, '50/50'],\n [100, lk],\n ].map(\n ([v, text]) =>\n html`<button\n type=\"button\"\n class=\"jump\"\n @click=${() => this.change(() => (this.value = v as number))}\n >\n ${text}\n </button>`,\n )}\n </div>\n <button\n type=\"button\"\n class=\"hold\"\n aria-keyshortcuts=\"O\"\n ?data-held=${this.holding}\n @pointerdown=${this.onHold}\n @pointerup=${this.onHold}\n @pointerleave=${this.onHold}\n @pointercancel=${this.onHold}\n @keydown=${this.onHold}\n @keyup=${this.onHold}\n @blur=${() => this.hold(false)}\n @contextmenu=${(e: Event) => e.preventDefault()}\n >\n Hold for ${l0}\n </button>`;\n return html`<div class=\"compare\" part=\"compare\" slot=${slot || nothing}>\n ${notes}${failed}\n <div class=\"compare-bar\">\n <div class=\"seg-group\" role=\"group\" aria-label=\"Compare versions\">\n ${MODES.map((m) => seg(this.mode === m, MODE_NAMES[m], () => this.setMode(m)))}\n </div>\n <div class=\"mode-panels\">${panel(switching, switchPanel)}${panel(!switching, sliding)}</div>\n </div>\n <p class=\"visually-hidden\" role=\"status\">${this.message}</p>\n </div>`;\n }\n\n /**\n * Full size, in every mode: the original and the version shown (Switch) or compared (Reveal,\n * Fade), each named. The same two links in every mode keep the toolbar's height, so changing\n * mode never moves the photo; and a visitor can always open the original at full size.\n */\n full(): { href: string; label: string }[] {\n const k = this.mode === 'switch' ? this.shown || this.other : this.other;\n return [0, k].map((i) => ({ href: this.list[i]!.href, label: this.label(i) }));\n }\n}\n"],"mappings":";;;AAWA,IAAMM,IAAuB;CAAC;CAAU;CAAQ;AAAM,GAChDC,IAA0C;CAC9C,QAAQ;CACR,MAAM;CACN,MAAM;AACR,GAGaC,IAAgB,EAAE,QAAQ,IAAI,GA8BrCC,KAAQ,MAAgB,OAAOC,KAAM,WAAWA,EAAE,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,IAChFC,KAAS,MAAc,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,CAAC,CAAC,CAAC,GAO/DC,KAAa,MAAc;IAC7BC,EAAE;IACFA,EAAE;;;;IAIFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;;;;IAIFA,EAAE;;;;IAIFA,EAAE;;;;;IAKFA,EAAE,oBAAoBA,EAAE;;;;IAIxBA,EAAE;IACFA,EAAE;IACFA,EAAE;;;;;;IAMFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;;MAEAA,EAAE;MACFA,EAAE;MACFA,EAAE;MACFA,EAAE;MACFA,EAAE;;GAIFC,IAAS,8DACTC,IAAO,yDAGPC,KAAQ,MAAc;IACxBH,EAAE,wBAAwBA,EAAE,yBAAyBA,EAAE;;;;aAI9CE,EAAK;;IAEdF,EAAE;IACFA,EAAE;IACFA,EAAE;IACFA,EAAE;wCACkCC,EAAO,gBAAgBA,EAAO;;;IAGlED,EAAE;;;;;IAKFA,EAAE,yCAAyCE,EAAK;IAChDF,EAAE,kEAAkEC,EAAO;IAC3ED,EAAE;IACFA,EAAE;IACFA,EAAE,iCAAiCC,EAAO;IAC1CD,EAAE;;;;IAIFA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