@uvalib/web-components 1.7.0 → 1.8.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 (105) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +56 -12
  3. package/dist/base/states.d.ts +12 -0
  4. package/dist/base/states.js +33 -0
  5. package/dist/base/states.js.map +1 -0
  6. package/dist/base.css +15 -5
  7. package/dist/components/bento-box/BentoBox.js +1 -0
  8. package/dist/components/bento-box/BentoBox.js.map +1 -1
  9. package/dist/components/events-section/EventsSection.js +1 -0
  10. package/dist/components/events-section/EventsSection.js.map +1 -1
  11. package/dist/components/library-hours/hours-data.js +1 -1
  12. package/dist/components/library-hours/hours-data.js.map +1 -1
  13. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +1 -0
  14. package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -1
  15. package/dist/components/uvalib-card/UvalibCard.js +6 -0
  16. package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
  17. package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +27 -0
  18. package/dist/components/uvalib-combobox/UvalibCombobox.js +85 -1
  19. package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -1
  20. package/dist/components/uvalib-contents/UvalibContents.js +5 -0
  21. package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
  22. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +6 -0
  23. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +10 -0
  24. package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -1
  25. package/dist/components/uvalib-image-regions/UvalibImageRegions.js +2 -0
  26. package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -1
  27. package/dist/components/uvalib-image-regions/regions.d.ts +6 -2
  28. package/dist/components/uvalib-image-regions/regions.js +6 -3
  29. package/dist/components/uvalib-image-regions/regions.js.map +1 -1
  30. package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +9 -2
  31. package/dist/components/uvalib-lightbox/UvalibLightbox.js +23 -3
  32. package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
  33. package/dist/components/uvalib-lightbox/compare.d.ts +30 -3
  34. package/dist/components/uvalib-lightbox/compare.js +98 -29
  35. package/dist/components/uvalib-lightbox/compare.js.map +1 -1
  36. package/dist/components/uvalib-map/UvalibMap.js +2 -2
  37. package/dist/components/uvalib-map/UvalibMap.js.map +1 -1
  38. package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -0
  39. package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
  40. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +3 -1
  41. package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
  42. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +3 -3
  43. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +16 -8
  44. package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
  45. package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +4 -1
  46. package/dist/components/uvalib-tag-list/UvalibTagList.js +9 -2
  47. package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -1
  48. package/dist/custom-elements.json +1926 -1637
  49. package/dist/styles/message.js +4 -0
  50. package/dist/styles/message.js.map +1 -1
  51. package/dist/styles/result-list.js +25 -4
  52. package/dist/styles/result-list.js.map +1 -1
  53. package/dist/styles/results.js +17 -2
  54. package/dist/styles/results.js.map +1 -1
  55. package/dist-cdn/base.css +15 -5
  56. package/dist-cdn/bento-box.js +1 -0
  57. package/dist-cdn/bento-box.js.map +1 -1
  58. package/dist-cdn/chunks/{compare-DV6ltvsJ.js → compare-C0nhByn7.js} +66 -29
  59. package/dist-cdn/chunks/compare-C0nhByn7.js.map +1 -0
  60. package/dist-cdn/chunks/{hours-data-Bw6vkIw7.js → hours-data-gMu5uT7H.js} +2 -2
  61. package/dist-cdn/chunks/hours-data-gMu5uT7H.js.map +1 -0
  62. package/dist-cdn/chunks/{library-weekly-hours-CrV3TlP5.js → library-weekly-hours-BJgxAyah.js} +3 -2
  63. package/dist-cdn/chunks/library-weekly-hours-BJgxAyah.js.map +1 -0
  64. package/dist-cdn/chunks/{regions-B8ExwUGP.js → regions-B-rOwa-v.js} +15 -15
  65. package/dist-cdn/chunks/regions-B-rOwa-v.js.map +1 -0
  66. package/dist-cdn/chunks/states-DGXGzcte.js +17 -0
  67. package/dist-cdn/chunks/states-DGXGzcte.js.map +1 -0
  68. package/dist-cdn/custom-elements.json +1926 -1637
  69. package/dist-cdn/events-section.js +1 -0
  70. package/dist-cdn/events-section.js.map +1 -1
  71. package/dist-cdn/library-hours-setup.js +1 -1
  72. package/dist-cdn/library-weekly-hours.js +1 -1
  73. package/dist-cdn/manifest.json +1 -1
  74. package/dist-cdn/site-hours-section.js +1 -1
  75. package/dist-cdn/skills/uvalib-web-components/SKILL.md +5 -4
  76. package/dist-cdn/skills/uvalib-web-components/reference/components.md +33 -6
  77. package/dist-cdn/uvalib-card.js +6 -0
  78. package/dist-cdn/uvalib-card.js.map +1 -1
  79. package/dist-cdn/uvalib-combobox.js +107 -68
  80. package/dist-cdn/uvalib-combobox.js.map +1 -1
  81. package/dist-cdn/uvalib-contents.js +5 -0
  82. package/dist-cdn/uvalib-contents.js.map +1 -1
  83. package/dist-cdn/uvalib-filter-drawer.js +27 -25
  84. package/dist-cdn/uvalib-filter-drawer.js.map +1 -1
  85. package/dist-cdn/uvalib-image-regions.js +3 -1
  86. package/dist-cdn/uvalib-image-regions.js.map +1 -1
  87. package/dist-cdn/uvalib-lightbox.js +80 -69
  88. package/dist-cdn/uvalib-lightbox.js.map +1 -1
  89. package/dist-cdn/uvalib-map.js +2 -2
  90. package/dist-cdn/uvalib-map.js.map +1 -1
  91. package/dist-cdn/uvalib-metadata.js +3 -0
  92. package/dist-cdn/uvalib-metadata.js.map +1 -1
  93. package/dist-cdn/uvalib-pagefind-search.js +2 -1
  94. package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
  95. package/dist-cdn/uvalib-photo-grid.js +4 -5
  96. package/dist-cdn/uvalib-photo-grid.js.map +1 -1
  97. package/dist-cdn/uvalib-tag-list.js +21 -16
  98. package/dist-cdn/uvalib-tag-list.js.map +1 -1
  99. package/package.json +1 -1
  100. package/skills/uvalib-web-components/SKILL.md +5 -4
  101. package/skills/uvalib-web-components/reference/components.md +33 -6
  102. package/dist-cdn/chunks/compare-DV6ltvsJ.js.map +0 -1
  103. package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +0 -1
  104. package/dist-cdn/chunks/library-weekly-hours-CrV3TlP5.js.map +0 -1
  105. package/dist-cdn/chunks/regions-B8ExwUGP.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { l as e, o as t, p as n, r } from "./UvalibElement-pGONDAwB.js";
2
2
  import { a as i } from "./analytics-DTTihuBD.js";
3
- import { n as a } from "./regions-B8ExwUGP.js";
3
+ import { n as a } from "./regions-B-rOwa-v.js";
4
4
  // src/components/uvalib-lightbox/compare.ts
5
5
  var o = [
6
6
  "switch",
@@ -33,7 +33,7 @@ function u(e) {
33
33
  w: e.w / i * 100,
34
34
  h: e.h / a * 100
35
35
  })),
36
- covers: e.map(({ frame: e }) => !e || e.x + e.w <= 100.001 && e.y + e.h <= 100.001)
36
+ covers: e.map(({ frame: e }) => !e || e.x >= -.001 && e.y >= -.001 && e.x + e.w <= 100.001 && e.y + e.h <= 100.001)
37
37
  };
38
38
  }
39
39
  var d = (e) => Math.round(e * 1e4) / 1e4, f = (e) => `--uvalib-frame-x: ${d(e.x)}; --uvalib-frame-y: ${d(e.y)}; --uvalib-frame-w: ${d(e.w)}; --uvalib-frame-h: ${d(e.h)}`, p = (e) => typeof e == "string" ? e.replace(/\s+/g, " ").trim() : "", m = (e) => Math.min(100, Math.max(0, Math.round(e))), h = (e) => `
@@ -68,6 +68,12 @@ var d = (e) => Math.round(e * 1e4) / 1e4, f = (e) => `--uvalib-frame-x: ${d(e.x)
68
68
  ${e} .stack.framed.compare-wipe:dir(rtl) > img.top.on {
69
69
  clip-path: inset(0 0 0 max(0%, calc((100 - var(--uvalib-compare-n, 50) - var(--uvalib-frame-x)) / var(--uvalib-frame-w) * 100%)));
70
70
  }
71
+ ${e} .stack.framed.compare-wipe.top-part > img:not(.top) {
72
+ clip-path: inset(0 0 0 max(0%, calc((var(--uvalib-compare-n, 50) - var(--uvalib-frame-x)) / var(--uvalib-frame-w) * 100%)));
73
+ }
74
+ ${e} .stack.framed.compare-wipe.top-part:dir(rtl) > img:not(.top) {
75
+ clip-path: inset(0 max(0%, calc((var(--uvalib-compare-n, 50) + var(--uvalib-frame-x) + var(--uvalib-frame-w) - 100) / var(--uvalib-frame-w) * 100%)) 0 0);
76
+ }
71
77
  ${e} .divider {
72
78
  position: absolute; inset-block: 0; inset-inline-start: var(--uvalib-compare, 50%);
73
79
  width: 0; pointer-events: none; forced-color-adjust: none;
@@ -142,7 +148,7 @@ var d = (e) => Math.round(e * 1e4) / 1e4, f = (e) => `--uvalib-frame-x: ${d(e.x)
142
148
  outline-offset: 2px;
143
149
  }
144
150
  ${e} .note { font-size: 0.9375rem; line-height: 1.5; }
145
- ${e} .stack.framed {
151
+ ${e} .stack.framed:not(.starting) {
146
152
  background: repeating-linear-gradient(135deg, transparent 0 7px, rgb(128 128 128 / 0.2) 7px 9px);
147
153
  }
148
154
  @media (prefers-reduced-motion: no-preference) {
@@ -170,7 +176,7 @@ function b(e) {
170
176
  }
171
177
  var x = 0, S = class {
172
178
  constructor(e) {
173
- this.host = e, this.list = [], this.slideKey = "", this.id = "", this.warned = !1, this.warnedFrame = !1, this.geo = null, this.baseHref = "", 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-${++x}`, this.onInput = (e) => {
179
+ this.host = e, this.list = [], this.slideKey = "", this.id = "", this.warned = !1, this.warnedFrame = !1, this.warnedStart = !1, this.startPending = !1, this.geo = null, this.baseHref = "", 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-${++x}`, this.onInput = (e) => {
174
180
  this.set(Number(e.target.value), !1);
175
181
  }, this.onSliderKey = (e) => {
176
182
  let t = getComputedStyle(e.target).direction === "rtl", n = e.key, r = 0;
@@ -189,10 +195,15 @@ var x = 0, S = class {
189
195
  }
190
196
  sync(e, t, n) {
191
197
  let r = `${t}\n${e.href}\n${JSON.stringify(e.versions)}`;
192
- r !== this.slideKey && (this.reset(), this.slideKey = r, this.id = e.id, this.list = this.parse(e), this.geo = u(this.list), this.baseHref = e.href, this.mode = this.chosen ?? (o.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);
198
+ if (r !== this.slideKey) {
199
+ this.reset(), this.slideKey = r, this.id = e.id, this.list = this.parse(e), this.geo = u(this.list), this.baseHref = e.href, this.mode = this.chosen ?? (o.includes(this.host.mode()) ? this.host.mode() : "switch"), this.value = this.mode === "wipe" ? 50 : 0, this.need(), this.settled = this.encode();
200
+ let t = n != null && this.active && this.parseState(n, !1);
201
+ e.start && this.active && !t && this.begin(e.start);
202
+ }
203
+ n != null && this.active && this.restore(n);
193
204
  }
194
205
  reset() {
195
- this.settleTimer && this.settle(!1), this.slideKey = "", this.list = [], this.geo = null, 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;
206
+ this.settleTimer && this.settle(!1), this.slideKey = "", this.list = [], this.geo = null, 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, this.startPending = !1;
196
207
  }
197
208
  parse(e) {
198
209
  let t = e.versions, n = !1;
@@ -214,7 +225,7 @@ var x = 0, S = class {
214
225
  }
215
226
  frame(e, t) {
216
227
  if (e.frame == null || e.frame === "") return null;
217
- let n = t > 0 && typeof e.frame == "string" ? a(e.frame) : null, r = (e) => typeof e == "number" || typeof e == "string" ? Number(e) : 0, i = r(e.width), o = r(e.height);
228
+ let n = t > 0 && typeof e.frame == "string" ? a(e.frame, { signed: !0 }) : null, r = (e) => typeof e == "number" || typeof e == "string" ? Number(e) : 0, i = r(e.width), o = r(e.height);
218
229
  return n?.unit === "percent" ? {
219
230
  x: n.x,
220
231
  y: n.y,
@@ -229,24 +240,50 @@ var x = 0, S = class {
229
240
  }
230
241
  natural() {
231
242
  if (!this.geo) return null;
232
- let e = (this.host.light ? this.host.el : this.host.root).querySelector("dialog .stack > img:not(.top)");
233
- return !e?.complete || !e.naturalWidth || !e.naturalHeight || e.getAttribute("src") !== this.host.size(this.baseHref) ? null : {
243
+ let e = this.baseImg();
244
+ return !e?.complete || !e.naturalWidth || !e.naturalHeight ? null : {
234
245
  w: e.naturalWidth,
235
246
  h: e.naturalHeight
236
247
  };
237
248
  }
249
+ parseState(e, t) {
250
+ let n = /^(?:(switch|wipe|fade):)?(\d{1,3})(?::(\d{1,3}))?$/.exec(e.trim().toLowerCase());
251
+ if (!n) return null;
252
+ let r = n[1] ?? "switch", i = Number(n[2]);
253
+ if (r === "switch") return i < this.list.length && !n[3] ? {
254
+ mode: r,
255
+ shown: i,
256
+ other: this.other,
257
+ value: this.value
258
+ } : null;
259
+ let a = n[3] ? Number(n[3]) : 1, o = a >= 1 && a < this.list.length;
260
+ return t && (!o || i > 100) ? null : {
261
+ mode: r,
262
+ shown: this.shown,
263
+ other: o ? a : 1,
264
+ value: m(i)
265
+ };
266
+ }
267
+ apply(e) {
268
+ this.mode = e.mode, this.shown = e.shown, this.other = e.other, this.value = e.value, this.need(), this.settled = this.encode();
269
+ }
238
270
  restore(e) {
239
- let t = /^(?:(switch|wipe|fade):)?(\d{1,3})(?::(\d{1,3}))?$/.exec(e.trim().toLowerCase());
240
- if (!t) return;
241
- let n = t[1] ?? "switch", r = Number(t[2]);
242
- if (n === "switch") {
243
- if (r >= this.list.length) return;
244
- this.shown = r;
245
- } else {
246
- let e = t[3] ? Number(t[3]) : 1;
247
- this.other = e >= 1 && e < this.list.length ? e : 1, this.value = m(r);
248
- }
249
- this.mode = this.chosen = n, this.need(), this.settled = this.encode();
271
+ let t = this.parseState(e, !1);
272
+ t && (this.apply(t), this.chosen = t.mode);
273
+ }
274
+ begin(e) {
275
+ let t = this.parseState(e, !0);
276
+ t ? (this.apply(t), this.startPending = this.amount > 0) : this.warnedStart || (this.warnedStart = !0, console.warn(`uvalib-lightbox: data-version "${e.slice(0, 40)}" is not a version of its image (1, wipe:50, fade:50, wipe:40:2); it opens on the original.`));
277
+ }
278
+ baseImg() {
279
+ let e = (this.host.light ? this.host.el : this.host.root).querySelector("dialog .stack > img:not(.top)");
280
+ return e && e.getAttribute("src") === this.host.size(this.baseHref) ? e : null;
281
+ }
282
+ get starting() {
283
+ return !this.startPending || this.failed.has(this.top) ? !1 : !(this.ready.has(this.top) && this.baseImg()?.complete);
284
+ }
285
+ get named() {
286
+ return this.startPending && !this.failed.has(this.top) ? this.amount : this.seen;
250
287
  }
251
288
  encode() {
252
289
  return this.mode === "switch" ? String(this.shown) : `${this.mode}:${this.value}${this.other === 1 ? "" : `:${this.other}`}`;
@@ -268,10 +305,10 @@ var x = 0, S = class {
268
305
  }
269
306
  set(e, t) {
270
307
  let n = m(e);
271
- n !== this.value && (this.value = n, this.need(), this.host.update(), this.announceNext ||= t, window.clearTimeout(this.settleTimer), this.settleTimer = window.setTimeout(() => this.settle(), c.settle));
308
+ n !== this.value && (this.startPending = !1, this.value = n, this.need(), this.host.update(), this.announceNext ||= t, window.clearTimeout(this.settleTimer), this.settleTimer = window.setTimeout(() => this.settle(), c.settle));
272
309
  }
273
310
  change(e) {
274
- e(), this.need(), this.host.update(), this.announceNext = !0, this.settle();
311
+ this.startPending = !1, e(), this.need(), this.host.update(), this.announceNext = !0, this.settle();
275
312
  }
276
313
  settle(e = !0) {
277
314
  window.clearTimeout(this.settleTimer), this.settleTimer = 0;
@@ -343,14 +380,14 @@ var x = 0, S = class {
343
380
  return this.dragging || performance.now() - this.dragEnd < 100;
344
381
  }
345
382
  alt(e) {
346
- let t = this.seen, n = this.label(0), r = this.label(this.top);
383
+ let t = this.named, n = this.label(0), r = this.label(this.top);
347
384
  return `${e} (${t <= 0 ? n : t >= 100 ? r : `${n} and ${r}, ${this.mode === "wipe" ? "compared side by side" : "blended"}`})`;
348
385
  }
349
386
  get stackClass() {
350
- let e = this.natural() ? this.geo : null;
351
- if (!e) return `compare-${this.mode}`;
352
- let t = this.seen > 0, n = this.mode === "switch" && t && this.seen >= 100 && !e.covers[this.top];
353
- return `compare-${this.mode} framed${t ? " top-on" : ""}${n ? " hide-base" : ""}`;
387
+ let e = this.starting ? " starting" : "", t = this.natural() ? this.geo : null;
388
+ if (!t) return `compare-${this.mode}${e}`;
389
+ let n = this.seen > 0, r = n && !t.covers[this.top], i = this.mode === "switch" && r && this.seen >= 100;
390
+ return `compare-${this.mode} framed${n ? " top-on" : ""}${i ? " hide-base" : ""}${r && this.mode === "wipe" ? " top-part" : ""}${e}`;
354
391
  }
355
392
  get stackStyle() {
356
393
  let e = this.mode === "switch" ? 100 : this.value, t = `--uvalib-compare: ${e}%; --uvalib-compare-opacity: ${e / 100}`, n = this.natural() ? this.geo : null;
@@ -390,7 +427,7 @@ var x = 0, S = class {
390
427
  <span class="side side-end" aria-hidden="true" ?hidden=${c >= 100}>${this.label(0)}</span>`;
391
428
  }
392
429
  controls(n) {
393
- let r = this.seen, i = this.top, a = (e) => e === 0 ? r < 100 : e === i && r > 0, c = this.list.map((n, r) => n.note ? e`<p class="note" ?data-off=${!a(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
430
+ let r = this.named, i = this.top, a = (e) => e === 0 ? r < 100 : e === i && r > 0, c = this.list.map((n, r) => n.note ? e`<p class="note" ?data-off=${!a(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
394
431
  type="button"
395
432
  class="seg"
396
433
  aria-pressed=${t ? "true" : "false"}
@@ -465,4 +502,4 @@ var x = 0, S = class {
465
502
  };
466
503
  export { S as Compare, c as compareTiming };
467
504
 
468
- //# sourceMappingURL=compare-DV6ltvsJ.js.map
505
+ //# sourceMappingURL=compare-C0nhByn7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-C0nhByn7.js","names":["unsafeCSS","nothing","b","A","r","trackEvent","parseXywh","MODES","MODE_NAMES","compareTiming","MAX_SIDE","framing","list","v","ext","f","x0","y0","uw","uh","r4","n","place","norm","s","clamp","structure","h","ACCENT","LINK","look","styled","install","root","host","opts","installLightDomStyles","text","sheet","nextId","Compare","rtl","k","d","key","index","slide","fromUrl","restore","raw","bad","out","o","label","href","box","i","size","w","img","m","param","mode","other","ok","strict","st","start","next","announce","fn","state","el","write","a","on","stack","l0","lk","base","starting","geo","part","hide","top","sizer","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';\nimport { parseXywh } from '../uvalib-image-regions/regions.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\n/** A box in percent: of a version (its `frame`), or of the box that holds every version. */\ninterface Box {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\ninterface Version {\n label: string;\n href: string;\n note: string;\n /** Where the original sits in this version, in percent of the version; null: the same framing. */\n frame: Box | null;\n}\n\n/**\n * Versions with a different framing: every version's box (and the original's, first) in\n * percent of the box that holds them all, at the original's scale; `uw` × `uh` is that box in\n * original widths and heights; `covers` says whether a version covers the whole original.\n */\ninterface Framing {\n boxes: Box[];\n uw: number;\n uh: number;\n covers: boolean[];\n}\n\n/** The largest side of the sizer (a canvas never drawn on, so nothing is allocated). */\nconst MAX_SIDE = 4096;\n\nfunction framing(list: Version[]): Framing | null {\n if (!list.some((v) => v.frame)) return null;\n // Each version's extent in original units: the original is 0..1 across and down.\n const ext = list.map(({ frame: f }) =>\n f ? { x: -f.x / f.w, y: -f.y / f.h, w: 100 / f.w, h: 100 / f.h } : { x: 0, y: 0, w: 1, h: 1 },\n );\n const x0 = Math.min(...ext.map((e) => e.x));\n const y0 = Math.min(...ext.map((e) => e.y));\n const uw = Math.max(...ext.map((e) => e.x + e.w)) - x0;\n const uh = Math.max(...ext.map((e) => e.y + e.h)) - y0;\n return {\n uw,\n uh,\n boxes: ext.map((e) => ({\n x: ((e.x - x0) / uw) * 100,\n y: ((e.y - y0) / uh) * 100,\n w: (e.w / uw) * 100,\n h: (e.h / uh) * 100,\n })),\n // A version covers the original when the original's box lies inside it.\n covers: list.map(\n ({ frame: f }) =>\n !f || (f.x >= -0.001 && f.y >= -0.001 && f.x + f.w <= 100.001 && f.y + f.h <= 100.001),\n ),\n };\n}\n\nconst r4 = (n: number) => Math.round(n * 1e4) / 1e4;\n/** Custom properties placing a layer (numbers, percent of the stack). */\nconst place = (b: Box) =>\n `--uvalib-frame-x: ${r4(b.x)}; --uvalib-frame-y: ${r4(b.y)}; --uvalib-frame-w: ${r4(b.w)}; --uvalib-frame-h: ${r4(b.h)}`;\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 /** `data-version`: the comparison the image opens on (the `version-param` format). */\n start?: string | null;\n}\n\n/** A comparison state: `version-param`'s value, parsed. */\ninterface State {\n mode: CompareMode;\n /** The version shown (Switch). */\n shown: number;\n /** The version compared (Reveal, Fade), and the percentage of it shown. */\n other: number;\n value: number;\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} .stack.framed > img {\n position: absolute; inset: auto;\n left: calc(var(--uvalib-frame-x) * 1%); top: calc(var(--uvalib-frame-y) * 1%);\n width: calc(var(--uvalib-frame-w) * 1%); height: calc(var(--uvalib-frame-h) * 1%);\n max-width: none; max-height: none; margin: 0;\n }\n ${h} .stack.framed > canvas.frame-box {\n display: block; width: auto; height: auto; max-width: 100%; max-height: 70dvh; margin: auto;\n }\n ${h} .stack.framed.hide-base > img:not(.top) { opacity: 0; }\n ${h} .stack.framed.compare-fade > img.top.on { opacity: 1; }\n ${h} .stack.framed.compare-fade.top-on > img:not(.top) {\n z-index: 1; opacity: calc(1 - var(--uvalib-compare-opacity, 1));\n }\n ${h} .stack.framed.compare-wipe > img.top.on {\n clip-path: inset(0 max(0%, calc((var(--uvalib-frame-x) + var(--uvalib-frame-w) - var(--uvalib-compare-n, 50)) / var(--uvalib-frame-w) * 100%)) 0 0);\n }\n ${h} .stack.framed.compare-wipe:dir(rtl) > img.top.on {\n clip-path: inset(0 0 0 max(0%, calc((100 - var(--uvalib-compare-n, 50) - var(--uvalib-frame-x)) / var(--uvalib-frame-w) * 100%)));\n }\n ${h} .stack.framed.compare-wipe.top-part > img:not(.top) {\n clip-path: inset(0 0 0 max(0%, calc((var(--uvalib-compare-n, 50) - var(--uvalib-frame-x)) / var(--uvalib-frame-w) * 100%)));\n }\n ${h} .stack.framed.compare-wipe.top-part:dir(rtl) > img:not(.top) {\n clip-path: inset(0 max(0%, calc((var(--uvalib-compare-n, 50) + var(--uvalib-frame-x) + var(--uvalib-frame-w) - 100) / var(--uvalib-frame-w) * 100%)) 0 0);\n }\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 ${h} .stack.framed:not(.starting) {\n background: repeating-linear-gradient(135deg, transparent 0 7px, rgb(128 128 128 / 0.2) 7px 9px);\n }\n @media (prefers-reduced-motion: no-preference) {\n ${h} .compare-switch > img.top, ${h} .compare-switch.framed > img { 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 private warnedFrame = false;\n private warnedStart = false;\n /** The image opened on another version (`data-version`): hidden until that version is drawn. */\n private startPending = false;\n private geo: Framing | null = null;\n private baseHref = '';\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.geo = framing(this.list);\n this.baseHref = slide.href;\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 // The link's own start, unless the address says otherwise.\n const fromUrl = restore != null && this.active && this.parseState(restore, false);\n if (slide.start && this.active && !fromUrl) this.begin(slide.start);\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.geo = null;\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 this.startPending = 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))\n out.push({ label, href, note: norm(o.note), frame: this.frame(o, i) });\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 /**\n * A version's `frame`: the original's box in it, `percent:x,y,w,h`, or pixels\n * (`x,y,w,h` / `pixel:`) of the version's `width` × `height`. `x` and `y` may be negative\n * and `w` and `h` over the version (a crop: the original reaches past it); `w` and `h` must\n * be positive. Anything else is ignored (the same framing), with one warning.\n */\n private frame(o: Record<string, unknown>, i: number): Box | null {\n if (o.frame == null || o.frame === '') return null;\n const box = i > 0 && typeof o.frame === 'string' ? parseXywh(o.frame, { signed: true }) : null;\n const size = (v: unknown) => (typeof v === 'number' || typeof v === 'string' ? Number(v) : 0);\n const w = size(o.width);\n const h = size(o.height);\n if (box?.unit === 'percent') return { x: box.x, y: box.y, w: box.w, h: box.h };\n if (box && w > 0 && h > 0)\n return {\n x: (box.x / w) * 100,\n y: (box.y / h) * 100,\n w: (box.w / w) * 100,\n h: (box.h / h) * 100,\n };\n if (!this.warnedFrame) {\n this.warnedFrame = true;\n console.warn(\n \"uvalib-lightbox: a version has a frame that is not usable (on the first version, not percent:x,y,w,h, or pixels without the version's width and height); it is shown with the original's framing.\",\n );\n }\n return null;\n }\n\n /**\n * The original's natural size, once its image (the one rendered now) has loaded: the framed\n * layout needs it, and is used only from then on (before, the original sizes the stack).\n */\n private natural(): { w: number; h: number } | null {\n if (!this.geo) return null;\n const img = this.baseImg();\n if (!img?.complete || !img.naturalWidth || !img.naturalHeight) return null;\n return { w: img.naturalWidth, h: img.naturalHeight };\n }\n\n /**\n * `2`, `switch:2`, `wipe:40`, `fade:60`, `wipe:40:2` (the version compared, from 1), or\n * null. `strict` (`data-version`) refuses what the address forgives: a percentage over 100\n * or a version compared that does not exist.\n */\n private parseState(param: string, strict: boolean): State | null {\n const m = /^(?:(switch|wipe|fade):)?(\\d{1,3})(?::(\\d{1,3}))?$/.exec(param.trim().toLowerCase());\n if (!m) return null;\n const mode = (m[1] ?? 'switch') as CompareMode;\n const n = Number(m[2]);\n if (mode === 'switch')\n return n < this.list.length && !m[3]\n ? { mode, shown: n, other: this.other, value: this.value }\n : null;\n const other = m[3] ? Number(m[3]) : 1;\n const ok = other >= 1 && other < this.list.length;\n if (strict && (!ok || n > 100)) return null;\n return { mode, shown: this.shown, other: ok ? other : 1, value: clamp(n) };\n }\n\n private apply(st: State): void {\n this.mode = st.mode;\n this.shown = st.shown;\n this.other = st.other;\n this.value = st.value;\n this.need();\n this.settled = this.encode();\n }\n\n /** The comparison from the address: the visitor's mode from now on. */\n private restore(param: string): void {\n const st = this.parseState(param, false);\n if (!st) return;\n this.apply(st);\n this.chosen = st.mode;\n }\n\n /**\n * The link's starting version (`data-version`): not the visitor's change, so no event, no\n * analytics, nothing written to the address, and the mode chosen stays for other images.\n */\n private begin(start: string): void {\n const st = this.parseState(start, true);\n if (!st) {\n if (!this.warnedStart) {\n this.warnedStart = true;\n console.warn(\n `uvalib-lightbox: data-version \"${start.slice(0, 40)}\" is not a version of its image (1, wipe:50, fade:50, wipe:40:2); it opens on the original.`,\n );\n }\n return;\n }\n this.apply(st);\n this.startPending = this.amount > 0;\n }\n\n /** The open image's own image element (the original). */\n private baseImg(): HTMLImageElement | null {\n const scope = (this.host.light ? this.host.el : this.host.root) as ParentNode;\n const img = scope.querySelector<HTMLImageElement>('dialog .stack > img:not(.top)');\n return img && img.getAttribute('src') === this.host.size(this.baseHref) ? img : null;\n }\n\n /**\n * Opening on another version: the photo stays hidden until that version (and the\n * original, which sizes a framed stack) has loaded, so the original never flashes first.\n */\n private get starting(): boolean {\n if (!this.startPending || this.failed.has(this.top)) return false;\n return !(this.ready.has(this.top) && this.baseImg()?.complete);\n }\n\n /** The percentage of the top version named and noted: the start's at once, else what is drawn. */\n private get named(): number {\n return this.startPending && !this.failed.has(this.top) ? this.amount : this.seen;\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.startPending = false;\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 this.startPending = false;\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.named;\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 const starting = this.starting ? ' starting' : '';\n const geo = this.natural() ? this.geo : null;\n if (!geo) return `compare-${this.mode}${starting}`;\n const on = this.seen > 0;\n // A version that does not cover the whole original (a crop): Switch hides the original;\n // Reveal shows only the version on its side of the divider, the pattern around it.\n const part = on && !geo.covers[this.top];\n const hide = this.mode === 'switch' && part && this.seen >= 100;\n return `compare-${this.mode} framed${on ? ' top-on' : ''}${hide ? ' hide-base' : ''}${part && this.mode === 'wipe' ? ' top-part' : ''}${starting}`;\n }\n\n get stackStyle(): string {\n const a = this.mode === 'switch' ? 100 : this.value;\n const base = `--uvalib-compare: ${a}%; --uvalib-compare-opacity: ${a / 100}`;\n const geo = this.natural() ? this.geo : null;\n return geo ? `${base}; --uvalib-compare-n: ${a}; ${place(geo.boxes[0]!)}` : base;\n }\n\n /**\n * With a different framing, where the outlines of regions go: the original's box in the\n * stack, as `<uvalib-image-regions>`'s overlay inset. Empty otherwise.\n */\n get regionsStyle(): string {\n const geo = this.natural() ? this.geo : null;\n if (!geo) return '';\n const b = geo.boxes[0]!;\n return `--uvalib-image-regions-inset: ${r4(b.y)}% ${r4(100 - b.x - b.w)}% ${r4(100 - b.y - b.h)}% ${r4(b.x)}%`;\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 size = this.natural();\n const geo = size ? this.geo : null;\n // The stack's size, reserved from the frames and the original: a canvas of the whole box\n // at the original's scale (never drawn on), sized like the image it stands for.\n const sizer =\n geo && size\n ? (() => {\n const w = size.w * geo.uw;\n const h = size.h * geo.uh;\n const k = Math.min(1, MAX_SIDE / Math.max(w, h));\n return html`<canvas\n class=\"frame-box\"\n aria-hidden=\"true\"\n width=${Math.max(1, Math.round(w * k))}\n height=${Math.max(1, Math.round(h * k))}\n ></canvas>`;\n })()\n : nothing;\n const layers = this.list.map((v, i) =>\n i === 0\n ? nothing\n : html`<img\n class=\"top ${i === top && on ? 'on' : ''}\"\n style=${geo && v.frame ? place(geo.boxes[i]!) : nothing}\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 html`${sizer}${layers}`;\n const a = this.seen;\n return html`${sizer}${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.named;\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":";;;;AAYA,IAAMO,IAAuB;CAAC;CAAU;CAAQ;AAAM,GAChDC,IAA0C;CAC9C,QAAQ;CACR,MAAM;CACN,MAAM;AACR,GAGaC,IAAgB,EAAE,QAAQ,IAAI,GA+BrCC,IAAW;AAEjB,SAASC,EAAQ,GAAiC;CAChD,IAAI,CAACC,EAAK,MAAM,MAAMC,EAAE,KAAK,GAAG,OAAO;CAEvC,IAAMC,IAAMF,EAAK,KAAK,EAAE,OAAOG,QAC7BA,IAAI;EAAE,GAAG,CAACA,EAAE,IAAIA,EAAE;EAAG,GAAG,CAACA,EAAE,IAAIA,EAAE;EAAG,GAAG,MAAMA,EAAE;EAAG,GAAG,MAAMA,EAAE;CAAE,IAAI;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;CAAE,CAC9F,GACMC,IAAK,KAAK,IAAI,GAAGF,EAAI,KAAK,MAAM,EAAE,CAAC,CAAC,GACpCG,IAAK,KAAK,IAAI,GAAGH,EAAI,KAAK,MAAM,EAAE,CAAC,CAAC,GACpCI,IAAK,KAAK,IAAI,GAAGJ,EAAI,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAIE,GAC9CG,IAAK,KAAK,IAAI,GAAGL,EAAI,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAIG;CACpD,OAAO;EACL;EACA;EACA,OAAOH,EAAI,KAAK,OAAO;GACrB,IAAK,EAAE,IAAIE,KAAME,IAAM;GACvB,IAAK,EAAE,IAAID,KAAME,I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AAC,EAAE;;mCAEtDkC,EAAMD,GAAWG,CAAW,IAAIF,EAAM,CAACD,GAAWI,CAAO,EAAE;;iDAE7C,KAAK,QAAQ;;CAE5D;CAOA,OAA0C;EAExC,OAAO,CAAC,GADE,KAAK,SAAS,YAAW,KAAK,SAAS,KAAK,KAC1C,CAAC,CAAC,KAAK,OAAO;GAAE,MAAM,KAAK,KAAKzC,EAAE,CAAE;GAAM,OAAO,KAAK,MAAMA,CAAC;EAAE,EAAE;CAC/E;AACF"}
@@ -79,7 +79,7 @@ function h(e, t, n, r = Infinity) {
79
79
  }
80
80
  function g(e) {
81
81
  let t = (e) => e.priorityPlacement || Infinity;
82
- return [...e].sort((e, n) => t(e) - t(n) || e.title.localeCompare(n.title));
82
+ return e.toSorted((e, n) => t(e) - t(n) || e.title.localeCompare(n.title));
83
83
  }
84
84
  var _ = (e) => {
85
85
  let [t, n, r] = e.split("-").map(Number);
@@ -178,4 +178,4 @@ function F(e, t = document) {
178
178
  }
179
179
  export { r as a, S as c, C as d, w as f, b as h, n as i, F as l, D as m, k as n, h as o, g as p, T as r, f as s, y as t, i as u };
180
180
 
181
- //# sourceMappingURL=hours-data-Bw6vkIw7.js.map
181
+ //# sourceMappingURL=hours-data-gMu5uT7H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hours-data-gMu5uT7H.js","names":["fetchJsonWith","fetchJson$1","formatter","hoursEndpoints","hoursTiming","setHoursEndpoints","key","value","from","globalApplied","endpoints","fetchJson","url","orUndefined","v","parseLibraries","data","json","n","a","calId","uri","siteLink","node","librariesCache","loadLibraries","p","promise","hoursCache","HOURS_CACHE_MAX","loadHours","sorted","ids","b","to","hit","maxAge","out","c","lid","entry","sortLibraries","rank","l","libs","utc","y","m","d","iso","date","addDays","days","weekStart","fmt","options","longDate","shortDate","shortWeekday","fullDate","headingDate","weekHeadingDate","formatTime","time","ampm","formatDay","day","h","ALLOWED","DROPPED","SAFE_PROTOCOLS","safeHref","href","base","copyAllowed","doc","name","el","sanitizeHoursHtml","parsed","html"],"sources":["../../src/components/library-hours/hours-data.ts"],"sourcesContent":["// Shared data and formatting for the library-hours components. Internal: not exported from\n// the package entry (only the LibraryInfo and DayHours types are). No side effects on import.\n\nimport { fetchJson as fetchJsonWith } from '../../data/fetch-json.js';\nimport { TIME_ZONE, formatter, todayInNewYork } from '../../data/new-york.js';\n\n/** One day's hours from LibCal: a status and, when open, one or more ranges. */\nexport interface DayHours {\n /** `open`, `closed`, `24hours`, or another LibCal status, shown as is. */\n status: string;\n /** Opening ranges, LibCal's own text (`9:00am` to `12:00am`); `to` may be past midnight. */\n hours?: { from: string; to: string }[];\n}\n\n/** A library (or a space inside one) from the Drupal JSON:API, reduced to the fields used. */\nexport interface LibraryInfo {\n /** Drupal node UUID. */\n id: string;\n title: string;\n shortTitle?: string;\n slug?: string;\n /** LibCal calendar id. */\n calId?: number;\n /** `Library`, `space` or `other-professional`. */\n placeType?: string;\n priorityPlacement?: number;\n /** Site link, with Drupal's `internal:` prefix removed (other schemes are kept as is). */\n siteLink?: string;\n /** Drupal's processed `field_hours_information` HTML. Sanitise before display. */\n hoursInformation?: string;\n /** Parent library's node UUID. */\n parent?: string;\n}\n\n/** Hours per LibCal calendar id, each a map of `YYYY-MM-DD` to that day's hours. */\nexport type HoursByCalendar = Map<number, Record<string, DayHours>>;\n\n/** The two data URLs. */\nexport interface HoursEndpoints {\n /** The Drupal JSON:API library list (relative by default: same origin, no CORS). */\n libraries: string;\n /** LibCal hours, with `{ids}` for the comma-separated calendar ids; `from` / `to` are appended. */\n hours: string;\n}\n\n/**\n * Where the data comes from, shared by every hours element (and exposed to pages as the\n * elements' static `endpoints`). The LibCal key is LibCal's public client widget key\n * (already public in the live bundles). A page can also set `window.uvalibHoursEndpoints`\n * (`{ libraries?, hours? }`) before the elements' script runs; it is merged in at the\n * first fetch. Requests are cached by URL, so a change applies to the next load.\n */\nexport const hoursEndpoints: HoursEndpoints = {\n libraries: '/jsonapi/index/default_index?filter[type]=library&page[limit]=100',\n hours:\n 'https://cal.lib.virginia.edu/api/1.0/hours/{ids}?iid=863&key=e4b27d40b7099e8e392113da2f8bf30a',\n};\n\n/**\n * Fetch attempts, the delay between them (ms), each attempt's timeout (ms), and how often\n * elements check the date (ms).\n */\nexport const hoursTiming = { retries: 3, retryDelay: 1000, timeout: 10_000, tick: 60_000 };\n\ndeclare global {\n interface Window {\n /** Optional endpoint overrides for the library-hours elements, read at their first fetch. */\n uvalibHoursEndpoints?: Partial<HoursEndpoints>;\n }\n}\n\n/** Copy the known endpoint keys (strings only) from `from` into the shared endpoints. */\nexport function setHoursEndpoints(from: Partial<HoursEndpoints> | null | undefined): void {\n for (const key of ['libraries', 'hours'] as const) {\n const value = from?.[key];\n if (typeof value === 'string' && value) hoursEndpoints[key] = value;\n }\n}\n\nlet globalApplied = false;\n/** The endpoints to use now: the page's `window.uvalibHoursEndpoints` is merged in once. */\nfunction endpoints(): HoursEndpoints {\n if (!globalApplied) {\n globalApplied = true;\n setHoursEndpoints(globalThis.window?.uvalibHoursEndpoints);\n }\n return hoursEndpoints;\n}\n\nexport { TIME_ZONE, todayInNewYork };\n\n// --- fetching -------------------------------------------------------------------------\n\nconst fetchJson = (url: string) => fetchJsonWith(url, hoursTiming);\n\ninterface RawLibrary {\n id: string;\n attributes: {\n title: string;\n field_short_title?: string | null;\n field_slug?: string | null;\n field_libcal_id?: string | number | null;\n field_type_basic?: string | null;\n field_priority_placement?: number | null;\n field_library_site_link?: { uri?: string } | null;\n field_hours_information?: { processed?: string } | null;\n };\n relationships?: { field_parent?: { data?: { id?: string } | null } };\n}\n\nconst orUndefined = <T>(v: T | null | undefined): T | undefined => v ?? undefined;\n\n/** Reduce a JSON:API response to LibraryInfo, in response order. */\nexport function parseLibraries(json: unknown): LibraryInfo[] {\n const data = (json as { data?: RawLibrary[] } | null)?.data;\n if (!Array.isArray(data)) return [];\n return data\n .filter((n) => n?.id && n.attributes?.title)\n .map((n) => {\n const a = n.attributes;\n const calId = parseInt(String(a.field_libcal_id ?? ''), 10);\n const uri = a.field_library_site_link?.uri;\n return {\n id: n.id,\n title: a.title,\n shortTitle: orUndefined(a.field_short_title),\n slug: orUndefined(a.field_slug),\n calId: Number.isNaN(calId) ? undefined : calId,\n placeType: orUndefined(a.field_type_basic),\n priorityPlacement: orUndefined(a.field_priority_placement),\n siteLink: siteLink(uri),\n hoursInformation: orUndefined(a.field_hours_information?.processed),\n parent: orUndefined(n.relationships?.field_parent?.data?.id),\n };\n });\n}\n\n/**\n * A Drupal link field as an href: `internal:/rmc/` becomes `/rmc/` and `entity:node/807`\n * becomes `/node/807` (Drupal redirects it to the page's alias). Other `entity:` links have\n * no URL outside Drupal, so they are dropped.\n */\nfunction siteLink(uri: string | undefined): string | undefined {\n if (!uri) return undefined;\n if (uri.startsWith('internal:')) return uri.slice('internal:'.length) || undefined;\n const node = /^entity:node\\/(\\d+)$/.exec(uri);\n if (node) return `/node/${node[1]}`;\n return uri.startsWith('entity:') ? undefined : uri;\n}\n\nconst librariesCache = new Map<string, Promise<LibraryInfo[]>>();\n\n/** The library list, fetched once per page (per URL) and shared. A failure is not cached. */\nexport function loadLibraries(): Promise<LibraryInfo[]> {\n const url = endpoints().libraries;\n let p = librariesCache.get(url);\n if (!p) {\n const promise = fetchJson(url).then(parseLibraries);\n librariesCache.set(url, (p = promise));\n promise.catch(() => {\n if (librariesCache.get(url) === promise) librariesCache.delete(url);\n });\n }\n return p;\n}\n\ninterface CacheEntry {\n at: number;\n promise: Promise<HoursByCalendar>;\n}\nconst hoursCache = new Map<string, CacheEntry>();\nconst HOURS_CACHE_MAX = 50;\n\n/**\n * Hours for LibCal calendars `ids` from `from` to `to` (inclusive, `YYYY-MM-DD`, at most\n * 100 days). Identical requests share one fetch; a cached result older than `maxAge` ms is\n * fetched again. A failure is not cached.\n */\nexport function loadHours(\n ids: number[],\n from: string,\n to: string,\n maxAge = Infinity,\n): Promise<HoursByCalendar> {\n const sorted = [...new Set(ids)].sort((a, b) => a - b);\n if (!sorted.length) return Promise.resolve(new Map());\n const url =\n endpoints().hours.replace('{ids}', sorted.join(',')) +\n `&from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;\n const key = url;\n const hit = hoursCache.get(key);\n if (hit && performance.now() - hit.at <= maxAge) return hit.promise;\n const promise = fetchJson(url).then((json) => {\n const out: HoursByCalendar = new Map();\n if (Array.isArray(json)) {\n for (const c of json as { lid?: unknown; dates?: unknown }[]) {\n const lid = Number(c?.lid);\n if (Number.isFinite(lid) && c.dates && typeof c.dates === 'object')\n out.set(lid, c.dates as Record<string, DayHours>);\n }\n }\n return out;\n });\n const entry = { at: performance.now(), promise };\n hoursCache.delete(key);\n hoursCache.set(key, entry);\n if (hoursCache.size > HOURS_CACHE_MAX) hoursCache.delete(hoursCache.keys().next().value!);\n promise.catch(() => {\n if (hoursCache.get(key) === entry) hoursCache.delete(key);\n });\n return promise;\n}\n\n/** Forget the cached library list and hours (for tests). */\nexport function resetHoursCache(): void {\n librariesCache.clear();\n hoursCache.clear();\n globalApplied = false;\n}\n\n/** Libraries by priority placement (missing last), then title. Returns a new array. */\nexport function sortLibraries(libs: readonly LibraryInfo[]): LibraryInfo[] {\n const rank = (l: LibraryInfo) => l.priorityPlacement || Infinity;\n return libs.toSorted((a, b) => rank(a) - rank(b) || a.title.localeCompare(b.title));\n}\n\n// --- dates: all arithmetic on YYYY-MM-DD strings, in UTC -------------------------------\n\nconst utc = (iso: string): Date => {\n const [y, m, d] = iso.split('-').map(Number) as [number, number, number];\n return new Date(Date.UTC(y, m - 1, d));\n};\nconst iso = (date: Date): string => date.toISOString().slice(0, 10);\n\nexport function addDays(date: string, days: number): string {\n const d = utc(date);\n d.setUTCDate(d.getUTCDate() + days);\n return iso(d);\n}\n\n/** The Sunday on or before `date`. */\nexport function weekStart(date: string): string {\n return addDays(date, -utc(date).getUTCDay());\n}\n\nconst fmt = (key: string, options: Intl.DateTimeFormatOptions) => (date: string) =>\n formatter(key, { ...options, timeZone: 'UTC' }).format(utc(date));\n\n/** \"Monday, November 9\" */\nexport const longDate = fmt('long', { weekday: 'long', month: 'long', day: 'numeric' });\n/** \"Nov 9\" */\nexport const shortDate = fmt('short', { month: 'short', day: 'numeric' });\n/** \"Mon\" */\nexport const shortWeekday = fmt('weekday', { weekday: 'short' });\n/** \"Saturday, November 14, 2026\" */\nexport const fullDate = fmt('full', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n});\nconst headingDate = fmt('heading', { year: 'numeric', month: 'short', day: '2-digit' });\n/** \"Nov 08. 2026\": the live week heading's format, kept because Drupal's /hours shows it. */\nexport const weekHeadingDate = (date: string): string => headingDate(date).replace(',', '.');\n\n// --- hours text ----------------------------------------------------------------------\n\n/** `9:00am` → `9am`, `5:30pm` → `5:30pm`; anything else unchanged. */\nexport function formatTime(time: string): string {\n const m = /^(\\d+):(\\d+)\\s*(am|pm)$/i.exec(time.trim());\n if (!m) return time;\n const ampm = m[3]!.toLowerCase();\n return m[2] === '00' ? `${m[1]}${ampm}` : `${m[1]}:${m[2]}${ampm}`;\n}\n\n/** A day's hours as text: `9am - 6pm` (ranges joined by commas), `24 Hours`, `closed`, or ''. */\nexport function formatDay(day: DayHours | undefined): string {\n if (!day) return '';\n if (Array.isArray(day.hours) && day.hours.length)\n return day.hours.map((h) => `${formatTime(h.from)} - ${formatTime(h.to)}`).join(', ');\n return (day.status ?? '').replace('24hours', '24 Hours').replace('ByApp', 'By Appt').trim();\n}\n\n// --- HTML from Drupal ----------------------------------------------------------------\n\nconst ALLOWED = new Set(['a', 'p', 'br', 'strong', 'em']);\n/** Dropped with their content; any other element is unwrapped (its content kept). */\nconst DROPPED = new Set([\n 'script',\n 'style',\n 'template',\n 'iframe',\n 'object',\n 'embed',\n 'noscript',\n 'svg',\n 'math',\n 'title',\n 'textarea',\n 'select',\n 'img',\n 'video',\n 'audio',\n 'head',\n]);\nconst SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:']);\n\nfunction safeHref(href: string, base: string): boolean {\n try {\n return SAFE_PROTOCOLS.has(new URL(href, base).protocol);\n } catch {\n return false;\n }\n}\n\nfunction copyAllowed(from: Node, to: Node, doc: Document): void {\n for (const node of from.childNodes) {\n if (node.nodeType === Node.TEXT_NODE) {\n to.appendChild(doc.createTextNode((node as Text).data));\n } else if (node.nodeType === Node.ELEMENT_NODE) {\n const name = (node as Element).localName;\n if (ALLOWED.has(name)) {\n const el = doc.createElement(name);\n const href = (node as Element).getAttribute('href');\n if (name === 'a' && href && safeHref(href, doc.baseURI)) el.setAttribute('href', href);\n copyAllowed(node, el, doc);\n to.appendChild(el);\n } else if (!DROPPED.has(name)) {\n copyAllowed(node, to, doc);\n }\n }\n }\n}\n\n/**\n * Drupal's hours HTML reduced to an allowlist (`a[href]` with an http(s), mailto, tel or\n * relative URL, `p`, `br`, `strong`, `em`), as new nodes owned by `doc`. It is parsed in an\n * inert document, so nothing in it runs or loads. The same walk is used in every browser\n * (rather than `setHTML` where available) so the output never differs between browsers.\n */\nexport function sanitizeHoursHtml(html: string, doc: Document = document): DocumentFragment {\n const out = doc.createDocumentFragment();\n let parsed: Document;\n try {\n parsed = new DOMParser().parseFromString(html, 'text/html');\n } catch {\n // For example a page enforcing Trusted Types: fall back to the text alone.\n out.append(doc.createTextNode(html.replace(/<[^>]*>/g, '')));\n return out;\n }\n copyAllowed(parsed.body, out, doc);\n return out;\n}\n"],"mappings":";;;AAoDA,IAAaG,IAAiC;CAC5C,WAAW;CACX,OACE;AACJ,GAMaC,IAAc;CAAE,SAAS;CAAG,YAAY;CAAM,SAAS;CAAQ,MAAM;AAAO;AAUzF,SAAgBC,EAAkB,GAAwD;CACxF,KAAK,IAAMC,KAAO,CAAC,aAAa,OAAO,GAAY;EACjD,IAAMC,IAAQC,IAAOF;EACrB,AAAI,OAAOC,KAAU,YAAYA,MAAO,EAAeD,KAAOC;CAChE;AACF;AAEA,IAAIE,IAAgB;AAEpB,SAASC,IAA4B;CAKnC,OAJKD,MACH,IAAgB,IAChBJ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qB;CAC9D,KAAK,IAAMnD,KAAQf,EAAK,YACtB,IAAIe,EAAK,aAAa,KAAK,WACzB,EAAG,YAAYoD,EAAI,eAAgBpD,EAAc,IAAI,CAAC;MACjD,IAAIA,EAAK,aAAa,KAAK,cAAc;EAC9C,IAAMqD,IAAQrD,EAAiB;EAC/B,IAAI6C,EAAQ,IAAIQ,CAAI,GAAG;GACrB,IAAMC,IAAKF,EAAI,cAAcC,CAAI,GAC3BJ,IAAQjD,EAAiB,aAAa,MAAM;GAGlD,AAFIqD,MAAS,OAAOJ,KAAQD,EAASC,GAAMG,EAAI,OAAO,KAAGE,EAAG,aAAa,QAAQL,CAAI,GACrFE,EAAYnD,GAAMsD,GAAIF,CAAG,GACzBzC,EAAG,YAAY2C,CAAE;EACnB,OAAO,AAAKR,EAAQ,IAAIO,CAAI,KAC1BF,EAAYnD,GAAMW,GAAIyC,CAAG;CAE7B;AAEJ;AAQA,SAAgBG,EAAkB,GAAc,IAAgB,UAA4B;CAC1F,IAAMzC,IAAMsC,EAAI,uBAAuB,GACnCI;CACJ,IAAI;EACF,IAAS,IAAI,UAAU,CAAC,CAAC,gBAAgBC,GAAM,WAAW;CAC5D,QAAQ;EAGN,OADA3C,EAAI,OAAOsC,EAAI,eAAeK,EAAK,QAAQ,YAAY,EAAE,CAAC,CAAC,GACpD3C;CACT;CAEA,OADAqC,EAAYK,EAAO,MAAM1C,GAAKsC,CAAG,GAC1BtC;AACT"}
@@ -3,7 +3,7 @@ import { a as u, i as d } from "./analytics-DTTihuBD.js";
3
3
  import { t as f } from "./heading-level-DIuNS44-.js";
4
4
  import { t as p } from "./accessible-DJv7YOtS.js";
5
5
  import { r as m } from "./new-york-DkcnqvJ4.js";
6
- import { a as h, c as g, d as _, f as v, h as y, i as b, m as x, n as S, o as C, r as w, s as T, t as E, u as D } from "./hours-data-Bw6vkIw7.js";
6
+ import { a as h, c as g, d as _, f as v, h as y, i as b, m as x, n as S, o as C, r as w, s as T, t as E, u as D } from "./hours-data-gMu5uT7H.js";
7
7
  // src/components/library-weekly-hours/LibraryWeeklyHours.ts
8
8
  var O = 0, k = (e) => `
9
9
  ${e} { display: block; }
@@ -86,6 +86,7 @@ var O = 0, k = (e) => `
86
86
  font-size: 1.25rem;
87
87
  font-weight: bold;
88
88
  color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));
89
+ text-wrap: balance;
89
90
  }
90
91
  `
91
92
  ];
@@ -352,4 +353,4 @@ a([e({
352
353
  attribute: "headinglevelstart"
353
354
  })], j.prototype, "headingLevelStart", void 0), a([n()], j.prototype, "inferredLevel", void 0), a([n()], j.prototype, "_state", void 0), a([n()], j.prototype, "today", void 0), a([n()], j.prototype, "view", void 0), a([n()], j.prototype, "pending", void 0), a([n()], j.prototype, "announcement", void 0), i("library-weekly-hours", j);
354
355
 
355
- //# sourceMappingURL=library-weekly-hours-CrV3TlP5.js.map
356
+ //# sourceMappingURL=library-weekly-hours-BJgxAyah.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library-weekly-hours-BJgxAyah.js","names":["unsafeCSS","nothing","_decorate","property","state","n","i","r$1","b","define","__decorate","r","installLightDomStyles","UvalibElement","trackEvent","trackError","precedingHeadingLevel","accessible","todayInNewYork","hoursTiming","longDate","shortDate","shortWeekday","weekStart","hoursEndpoints","weekHeadingDate","formatDay","loadHours","fullDate","loadLibraries","addDays","setHoursEndpoints","instanceCounter","structuralRules","host","shadowStructure","LibraryWeeklyHours","_args","value","root","sheet","above","node","today","every","start","changed","id","announce","slug","days","background","libraries","library","l","spaces","ids","hours","maxAge","sameWeek","hadFocus","active","day","dates","calId","text","A","lib","cells","building","space","view","level","headingId","tableDays"],"sources":["../../src/components/library-weekly-hours/LibraryWeeklyHours.ts","../../src/components/library-weekly-hours/library-weekly-hours.ts"],"sourcesContent":["import { html, css, nothing, unsafeCSS, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { trackError, trackEvent } from '../../base/analytics.js';\nimport { UvalibElement } from '../../base/UvalibElement.js';\nimport { precedingHeadingLevel } from '../../base/heading-level.js';\nimport { installLightDomStyles } from '../../base/light-dom-styles.js';\nimport { accessible } from '../../styles/accessible.js';\nimport {\n addDays,\n formatDay,\n fullDate,\n hoursEndpoints,\n hoursTiming,\n setHoursEndpoints,\n loadHours,\n loadLibraries,\n longDate,\n shortDate,\n shortWeekday,\n todayInNewYork,\n weekHeadingDate,\n weekStart,\n type HoursByCalendar,\n type HoursEndpoints,\n type LibraryInfo,\n} from '../library-hours/hours-data.js';\n\n/** Element ids share the document id space in light DOM, so each instance gets its own prefix. */\nlet instanceCounter = 0;\n\n/** What the table shows: one week's data, kept on screen while the next week loads. */\ninterface WeekView {\n days: string[];\n library: LibraryInfo;\n spaces: LibraryInfo[];\n hours: HoursByCalendar;\n}\n\n/** `loading` until the first data arrives, then `ready`, or `error` when it cannot be loaded. */\nexport type HoursState = 'loading' | 'ready' | 'error';\n\n/**\n * The layout rules the week header and table need even with `no-style`: Drupal's /hours CSS\n * relies on them. `host` is `:host` (shadow) or the tag name (light DOM, so they stay scoped).\n */\nconst structuralRules = (host: string) => `\n ${host} { display: block; }\n ${host}[loading] { min-height: var(--library-weekly-hours-min-height, 0); }\n ${host} .hours-placeholder { visibility: hidden; }\n /* One line even when empty, so \"Loading hours…\" giving way to nothing moves nothing below. */\n ${host} .weekly-hours-status { min-height: 1.5em; min-height: 1lh; }\n ${host}[hidden], ${host} [hidden] { display: none !important; }\n ${host} .weekly-hours-header-section {\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n align-items: center;\n text-align: center;\n }\n ${host} .weekly-hours-header-section div[role='heading'] { flex: 1; }\n ${host} .visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n`;\nconst shadowStructure = unsafeCSS(structuralRules(':host'));\n\n/**\n * One library's opening hours for a week (Sunday to Saturday, in America/New_York): a\n * header with \"Previous week\" / \"Next week\" buttons and the date range, then a table with a\n * \"Building hours\" row and a row per space in the library. Data comes from the library\n * website's JSON:API (same origin) and LibCal, shared between all hours elements on a page.\n * Used on library.virginia.edu/hours through `<library-hours-setup>`.\n *\n * @tagname library-weekly-hours\n * @fires uvalib-analytics-event - For `<site-analytics>`: `['library-weekly-hours', 'week-change', 'next' | 'previous']` for the week buttons, and `['library-weekly-hours', 'error', 'hours-load']` once when the hours cannot be loaded. Bubbles and is composed.\n * @csspart building-hours - The \"Building hours\" table row (shadow mode).\n * @cssprop [--library-weekly-hours-min-height=0] - Height the element keeps during its first load (while it has the `loading` attribute, before any rows show), so content below does not jump when the hours arrive. Applies with `no-style` too. Pages can reserve the same height before the element upgrades with `library-weekly-hours:not(:defined) { display: block; min-height: … }`.\n * @cssprop [--uva-brand-orange=#e57200] - Border of today's column; focus ring colour.\n * @cssprop [--uva-brand-blue=#232d4b] - Header and button colour.\n * @cssprop --uva-color-border - Dark-mode role token: table cell borders (else #dadada).\n * @cssprop --uva-color-current - Dark-mode role token: today's column border (else `--uva-brand-orange`).\n * @cssprop --uva-color-link - Dark-mode role token: heading, button text and border (else `--uva-brand-blue`).\n * @cssprop --uva-color-surface-raised - Dark-mode role token: button background (else #fff).\n * @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).\n */\nexport class LibraryWeeklyHours extends UvalibElement {\n static styles = [\n accessible,\n shadowStructure,\n css`\n table {\n width: 100%;\n border-collapse: collapse;\n margin-block: 1rem;\n }\n th,\n td {\n padding: 0.5rem;\n border: 1px solid var(--uva-color-border, #dadada);\n text-align: center;\n vertical-align: middle;\n }\n tbody th {\n text-align: start;\n }\n th.today,\n td.today {\n border-inline: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n th.today {\n border-block-start: 2px solid var(--uva-color-current, var(--uva-brand-orange, #e57200));\n }\n .date-header-day {\n font-weight: bold;\n }\n tbody .date--mobile {\n display: none;\n }\n .uvalib-button {\n font: inherit;\n padding: 0.4rem 0.9rem;\n border: 1px solid var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n border-radius: 0.3rem;\n background: var(--uva-color-surface-raised, #fff);\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n cursor: pointer;\n }\n .heading-h1,\n .heading-h2,\n .heading-h3,\n .heading-h4,\n .heading-h5,\n .heading-h6 {\n font-size: 1.25rem;\n font-weight: bold;\n color: var(--uva-color-link, var(--uva-brand-blue, #232d4b));\n text-wrap: balance;\n }\n `,\n ];\n\n /**\n * The data endpoints shared by all hours elements: `libraries` (the Drupal JSON:API URL,\n * relative by default) and `hours` (LibCal, with `{ids}`). Assigning an object (or setting\n * a key) changes them for every hours element from the next load on. To repoint before\n * elements already in the HTML start fetching, set `window.uvalibHoursEndpoints` before\n * the define script runs.\n */\n static get endpoints(): HoursEndpoints {\n return hoursEndpoints;\n }\n static set endpoints(value: Partial<HoursEndpoints>) {\n setHoursEndpoints(value);\n }\n\n /** The library's `field_slug` in Drupal (for example `clemons`). */\n @property({ type: String, attribute: 'library-slug' })\n librarySlug?: string;\n\n /** Which week to show: 0 is this week, 1 next week, -1 last week. Changed by the buttons. */\n @property({ type: Number, attribute: 'week-count', reflect: true })\n weekCount = 0;\n\n /** How often (ms) the current week's hours are fetched again. 0 turns it off. */\n @property({ type: Number, attribute: 'refresh-every' })\n refreshEvery = 600000;\n\n /** Hide the \"Building hours\" row (for a library whose building calendar is one of its spaces). */\n @property({ type: Boolean, attribute: 'hide-building-hours', reflect: true })\n hideBuildingHours = false;\n\n /**\n * `aria-level` (1–6) of the week heading, also its `heading-h<n>` class. Unset (the\n * default), the level is one below the nearest heading before the element in the page\n * (`aria-level` 3 under a library's `<h2>` on /hours), or 2 when there is none, and the\n * class stays `heading-h2`, the one the library website's CSS styles.\n */\n @property({ type: Number, attribute: 'heading-level' })\n headingLevel?: number;\n\n /** Old name of `heading-level`, still accepted; `heading-level` wins. */\n @property({ type: Number, attribute: 'headinglevelstart' })\n headingLevelStart?: number;\n\n /** One below the nearest preceding heading, worked out on connect (see `level`). */\n @state() private inferredLevel = 2;\n\n /** `loading` (the default, until data arrives), `ready` or `error`. Read-only. */\n get state(): HoursState {\n return this._state;\n }\n\n @state() private _state: HoursState = 'loading';\n @state() private today = '';\n @state() private view?: WeekView;\n /**\n * During the first load, once the library list is in: the rows the table will have, so\n * placeholder rows can hold their height until the hours arrive.\n */\n @state() private pending?: Omit<WeekView, 'hours'>;\n @state() private announcement = '';\n\n private readonly uid = `library-weekly-hours-${++instanceCounter}`;\n private loadId = 0;\n /** Set by the week buttons and Retry: announce the result of the next load. */\n private userInitiated = false;\n private tickTimer?: ReturnType<typeof setInterval>;\n private refreshTimer?: ReturnType<typeof setInterval>;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n if (root instanceof ShadowRoot && this.noStyle) {\n const sheet = shadowStructure.styleSheet;\n if (sheet) root.adoptedStyleSheets = [sheet];\n }\n return root;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n const above = precedingHeadingLevel(this);\n this.inferredLevel = above === null ? 2 : Math.min(above + 1, 6);\n if (this.lightDom && this.noStyle) {\n const node = this.getRootNode();\n installLightDomStyles(\n `${this.localName}::structure`,\n unsafeCSS(structuralRules(this.localName)),\n {\n root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,\n scope: false,\n },\n );\n }\n this.today = todayInNewYork();\n clearInterval(this.tickTimer);\n this.tickTimer = setInterval(() => {\n const today = todayInNewYork();\n if (today !== this.today) this.today = today;\n else if (this._state === 'error') void this.load({ background: true });\n }, hoursTiming.tick);\n this.restartRefresh();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearInterval(this.tickTimer);\n clearInterval(this.refreshTimer);\n this.tickTimer = this.refreshTimer = undefined;\n }\n\n private restartRefresh() {\n clearInterval(this.refreshTimer);\n this.refreshTimer = undefined;\n const every = this.refreshEvery;\n if (!this.isConnected || !(every > 0)) return;\n this.refreshTimer = setInterval(() => {\n if (this.weekCount === 0 && this._state !== 'loading')\n void this.load({ background: true, maxAge: every / 2 });\n }, every);\n }\n\n /** The seven `YYYY-MM-DD` dates of the week shown. */\n private get days(): string[] {\n const start = addDays(weekStart(this.today), (Math.trunc(this.weekCount) || 0) * 7);\n return Array.from({ length: 7 }, (_, i) => addDays(start, i));\n }\n\n /** The level set by `heading-level` (or the old `headinglevelstart`), or null. */\n private get explicitLevel(): number | null {\n const n = Math.trunc(this.headingLevel ?? this.headingLevelStart ?? Number.NaN);\n return n >= 1 && n <= 6 ? n : null;\n }\n\n /** The week heading's `aria-level`: as set, else inferred from the page on connect. */\n private get level(): number {\n return this.explicitLevel ?? this.inferredLevel;\n }\n\n /** The `heading-h<n>` class: as set, else `heading-h2` (what the library's CSS styles). */\n private get headingClass(): number {\n return this.explicitLevel ?? 2;\n }\n\n // A plain map: `today` is private, which PropertyValues<this> does not cover.\n protected override willUpdate(changed: Map<PropertyKey, unknown>) {\n if (!this.isConnected || !this.today) return;\n if (!this.hasUpdated || changed.has('librarySlug') || changed.has('weekCount')) {\n void this.load();\n } else if (changed.has('today')) {\n // The date rolled over: reload quietly. The same week keeps its rows on a failure.\n void this.load({ background: this.view?.days[0] === this.days[0] });\n }\n }\n\n protected override updated(changed: PropertyValues<this>) {\n // Only the first load, before any rows show, reserves --library-weekly-hours-min-height.\n this.toggleAttribute('loading', this._state === 'loading' && !this.view);\n // The first value is picked up by connectedCallback.\n if (changed.has('refreshEvery') && changed.get('refreshEvery') !== undefined)\n this.restartRefresh();\n }\n\n /**\n * Load the week shown. The previous rows stay on screen (the table is `aria-busy`) until\n * the new data lands. A `background` load (refresh, retry from the interval or a rollover\n * within the week) does not change the state to loading and, if it fails while rows for\n * the same week are shown, keeps them. Only user-initiated loads announce their result.\n */\n private async load({\n background = false,\n maxAge = Infinity,\n }: { background?: boolean; maxAge?: number } = {}) {\n const id = ++this.loadId;\n const announce = this.userInitiated;\n this.userInitiated = false;\n const slug = this.librarySlug;\n if (!slug) {\n this._state = 'ready';\n this.view = undefined;\n return;\n }\n const days = this.days;\n if (!background) {\n this._state = 'loading';\n this.announcement = '';\n }\n try {\n const libraries = await loadLibraries();\n const library = libraries.find((l) => l.slug === slug);\n if (!library) throw new Error(`no library with slug \"${slug}\"`);\n const spaces = libraries.filter((l) => l.parent === library.id);\n if (id === this.loadId && !this.view) this.pending = { days, library, spaces };\n const ids = [library, ...spaces]\n .map((l) => l.calId)\n .filter((n): n is number => n !== undefined);\n const hours = await loadHours(ids, days[0]!, days[6]!, maxAge);\n if (id !== this.loadId) return; // a newer load owns the element\n this.view = { days, library, spaces, hours };\n this.pending = undefined;\n this._state = 'ready';\n if (announce)\n this.announcement = `Showing hours for ${fullDate(days[0]!)} to ${fullDate(days[6]!)}`;\n } catch {\n if (id !== this.loadId) return;\n const sameWeek = this.view?.days[0] === days[0];\n if (background && sameWeek && this._state !== 'error') return;\n if (!sameWeek) this.view = undefined;\n this.pending = undefined;\n this._state = 'error';\n trackError(this, 'library-weekly-hours', 'hours-load');\n }\n }\n\n private retry() {\n this.userInitiated = true;\n const hadFocus = this.focusedInside();\n void this.load().then(() => {\n // The Retry button is gone once the hours load; keep keyboard focus in the element.\n if (hadFocus && this._state === 'ready' && !this.focusedInside())\n this.renderRoot\n .querySelector<HTMLButtonElement>('.weekly-hours-header-section button')\n ?.focus();\n });\n }\n\n private focusedInside(): boolean {\n const active =\n this.renderRoot instanceof ShadowRoot\n ? this.renderRoot.activeElement\n : document.activeElement;\n return !!active && (this.renderRoot as Node).contains(active) && active !== this;\n }\n\n private previousWeek() {\n this.userInitiated = true;\n this.weekCount = (Math.trunc(this.weekCount) || 0) - 1;\n trackEvent(this, ['library-weekly-hours', 'week-change', 'previous']);\n }\n\n private nextWeek() {\n this.userInitiated = true;\n this.weekCount = (Math.trunc(this.weekCount) || 0) + 1;\n trackEvent(this, ['library-weekly-hours', 'week-change', 'next']);\n }\n\n private renderMobileDate(day: string) {\n return html`<div class=\"date--mobile\">\n <div class=\"date-header-day\">${shortWeekday(day)}</div>\n <div class=\"date-header-month\">${shortDate(day)}</div>\n </div>`;\n }\n\n private renderCells(days: string[], hours: HoursByCalendar, calId: number | undefined) {\n const dates = calId === undefined ? undefined : hours.get(calId);\n return days.map((day) => {\n const text = formatDay(dates?.[day]);\n return html`<td\n aria-label=${text ? `${longDate(day)}: ${text}` : longDate(day)}\n class=${day === this.today ? 'today' : nothing}\n >\n ${this.renderMobileDate(day)}${text}\n </td>`;\n });\n }\n\n /**\n * The first load's rows before the hours arrive: the real row headers with invisible,\n * typical hours text in each cell, so the table already has its final height in whatever\n * font the page uses and nothing below it moves when the hours replace the placeholders.\n */\n private renderPlaceholderRows({ days, library: lib, spaces }: Omit<WeekView, 'hours'>) {\n const cells = () =>\n days.map(\n (day) =>\n html`<td class=${day === this.today ? 'today' : nothing}>\n ${this.renderMobileDate(day)}<span class=\"hours-placeholder\" aria-hidden=\"true\"\n >10am - 10pm</span\n >\n </td>`,\n );\n const building =\n !this.hideBuildingHours && lib.calId !== undefined\n ? html`<tr part=\"building-hours\">\n <th scope=\"row\" colspan=\"2\">Building hours</th>\n ${cells()}\n </tr>`\n : nothing;\n return html`${building}${spaces.map(\n (space) =>\n html`<tr>\n <th scope=\"row\" colspan=\"2\">\n <span class=${space.siteLink ? 'lib-space-link' : 'lib-space'}>${space.title}</span>\n </th>\n ${cells()}\n </tr>`,\n )}`;\n }\n\n private renderRows(view: WeekView | undefined) {\n if (!view) {\n if (this.pending) return this.renderPlaceholderRows(this.pending);\n // Before the library list is in: the Building hours row nearly every library has, so\n // only a library's extra spaces can still move what follows the table.\n if (this._state === 'loading' && !this.hideBuildingHours)\n return this.renderPlaceholderRows({\n days: this.days,\n library: { calId: 0 } as LibraryInfo,\n spaces: [],\n });\n return nothing;\n }\n const { days, library: lib, spaces, hours } = view;\n const building =\n !this.hideBuildingHours && lib.calId !== undefined && hours.has(lib.calId)\n ? html`<tr part=\"building-hours\">\n <th scope=\"row\" colspan=\"2\" aria-label=\"Building hours\">Building hours</th>\n ${this.renderCells(days, hours, lib.calId)}\n </tr>`\n : nothing;\n return html`${building}${spaces.map(\n (space) =>\n html`<tr>\n <th scope=\"row\" colspan=\"2\" aria-label=${space.title}>\n ${\n space.siteLink\n ? html`<a class=\"lib-space-link\" href=${space.siteLink}>${space.title}</a>`\n : html`<span class=\"lib-space\">${space.title}</span>`\n }\n </th>\n ${this.renderCells(days, hours, space.calId)}\n </tr>`,\n )}`;\n }\n\n private renderStatus() {\n // Only the first load says so; later loads keep the previous rows (aria-busy) quietly.\n if (this._state === 'loading') return this.view ? nothing : 'Loading hours…';\n if (this._state === 'error')\n return html`Hours are unavailable right now.\n <button type=\"button\" class=\"uvalib-button uvalib-button--basic\" @click=${this.retry}>\n Retry\n </button>`;\n return this.announcement\n ? html`<span class=\"visually-hidden\">${this.announcement}</span>`\n : nothing;\n }\n\n render() {\n if (!this.librarySlug || !this.today) return nothing;\n const days = this.days;\n const level = this.level;\n const headingId = `${this.uid}-heading`;\n // The table shows the data it has (the previous week while the next one loads).\n const tableDays = this.view?.days ?? days;\n return html`<div class=\"weekly-hours-header-section\">\n <button\n type=\"button\"\n class=\"uvalib-button uvalib-button--basic\"\n aria-describedby=${headingId}\n @click=${this.previousWeek}\n >\n Previous week\n </button>\n <div\n class=\"heading-h${this.headingClass}\"\n role=\"heading\"\n aria-level=${level}\n id=${headingId}\n >\n ${weekHeadingDate(days[0]!)} - ${weekHeadingDate(days[6]!)}\n </div>\n <button\n type=\"button\"\n class=\"uvalib-button uvalib-button--basic\"\n aria-describedby=${headingId}\n @click=${this.nextWeek}\n >\n Next week\n </button>\n </div>\n <table\n class=\"weekly-hours-body-section\"\n aria-busy=${this._state === 'loading' ? 'true' : nothing}\n >\n <colgroup>\n <col class=\"location-column\" />\n ${tableDays.map(() => html`<col />`)}\n <col />\n </colgroup>\n <thead>\n <tr>\n <th colspan=\"2\" scope=\"col\"><span class=\"visually-hidden\">Day</span></th>\n ${tableDays.map(\n (day) =>\n html`<th\n scope=\"col\"\n aria-label=${longDate(day)}\n aria-current=${day === this.today ? 'date' : nothing}\n class=${day === this.today ? 'today' : nothing}\n >\n <div class=\"date-header\">${this.renderMobileDate(day)}</div>\n </th>`,\n )}\n </tr>\n </thead>\n <tbody>\n ${this.renderRows(this.view)}\n </tbody>\n </table>\n <div class=\"weekly-hours-status\" role=\"status\">${this.renderStatus()}</div>`;\n }\n}\n","import { define } from '../../base/define.js';\nimport { LibraryWeeklyHours } from './LibraryWeeklyHours.js';\n\ndefine('library-weekly-hours', LibraryWeeklyHours);\n"],"mappings":";;;;;;;AA4BA,IAAIgC,IAAkB,GAiBhBC,KAAmB,MAAiB;IACtCC,EAAK;IACLA,EAAK;IACLA,EAAK;;IAELA,EAAK;IACLA,EAAK,YAAYA,EAAK;IACtBA,EAAK;;;;;;;IAOLA,EAAK;IACLA,EAAK;;;;;;;;;;;GAYHC,IAAkBnC,EAAUiC,EAAgB,OAAO,CAAC,GAqB7CG,IAAb,cAAwCvB,EAAc;;EAwH5B,A,aA5CZ,KAAA,YAAA,GAIG,KAAA,eAAA,KAIK,KAAA,oBAAA,IAgBa,KAAA,gBAAA,GAOK,KAAA,SAAA,WACb,KAAA,QAAA,IAOO,KAAA,eAAA,IAET,KAAA,MAAA,wBAAwB,EAAEmB,KAChC,KAAA,SAAA,GAEO,KAAA,gBAAA;;;EAvHR,KAAA,SAAA;GACdf;GACAkB;GACA,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDL;;CASA,WAAW,YAA4B;EACrC,OAAOX;CACT;CACA,WAAW,UAAU,GAAgC;EACnD,EAAkBc,CAAK;CACzB;CAmCA,IAAI,QAAoB;EACtB,OAAO,KAAK;CACd;CAmBA,mBAAsE;EACpE,IAAMC,IAAO,MAAM,iBAAiB;EACpC,IAAIA,aAAgB,cAAc,KAAK,SAAS;GAC9C,IAAMC,IAAQL,EAAgB;GAC9B,AAAIK,MAAO,EAAK,qBAAqB,CAACA,C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AAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,SAAA,KAAA,CAAA,GACNlC,EAAA,CAAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,QAAA,KAAA,CAAA,GAKNlC,EAAA,CAAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,WAAA,KAAA,CAAA,GACNlC,EAAA,CAAAE,EAAM,CAAA,GAAAgC,EAAA,WAAA,gBAAA,KAAA,CAAA,GC7MT3B,EAAO,wBAAwB2B,CAAkB"}
@@ -1,18 +1,18 @@
1
1
  // src/components/uvalib-image-regions/regions.ts
2
- function e(e) {
3
- let t = String(e ?? "").trim(), n = t.lastIndexOf("xywh=");
4
- n >= 0 && (t = t.slice(n + 5)), t = t.split("&")[0].trim();
5
- let r = "px", i = /^(pixel|percent):/i.exec(t);
6
- i && (r = i[1].toLowerCase() === "percent" ? "percent" : "px", t = t.slice(i[0].length));
7
- let a = t.split(",");
8
- if (a.length !== 4 || a.some((e) => !/^\s*\d+(\.\d+)?\s*$/.test(e))) return null;
9
- let [o, s, c, l] = a.map(Number);
10
- return c <= 0 || l <= 0 ? null : {
11
- x: o,
12
- y: s,
13
- w: c,
14
- h: l,
15
- unit: r
2
+ function e(e, t = {}) {
3
+ let n = String(e ?? "").trim(), r = n.lastIndexOf("xywh=");
4
+ r >= 0 && (n = n.slice(r + 5)), n = n.split("&")[0].trim();
5
+ let i = "px", a = /^(pixel|percent):/i.exec(n);
6
+ a && (i = a[1].toLowerCase() === "percent" ? "percent" : "px", n = n.slice(a[0].length));
7
+ let o = n.split(","), s = t.signed ? /^\s*-?\d+(\.\d+)?\s*$/ : /^\s*\d+(\.\d+)?\s*$/;
8
+ if (o.length !== 4 || o.some((e) => !s.test(e))) return null;
9
+ let [c, l, u, d] = o.map(Number);
10
+ return u <= 0 || d <= 0 ? null : {
11
+ x: c,
12
+ y: l,
13
+ w: u,
14
+ h: d,
15
+ unit: i
16
16
  };
17
17
  }
18
18
  var t = (e) => String(e ?? "").replace(/\s+/g, " ").trim();
@@ -83,4 +83,4 @@ function i(e, t, n) {
83
83
  }
84
84
  export { n as i, e as n, i as r, r as t };
85
85
 
86
- //# sourceMappingURL=regions-B8ExwUGP.js.map
86
+ //# sourceMappingURL=regions-B-rOwa-v.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions-B-rOwa-v.js","names":["parseXywh","s","value","at","unit","prefix","parts","num","options","p","x","y","w","h","text","v","toRegion","o","label","box","n","out","parseRegions","list","r","entry","m","toPercent","width","height","clamp","left","top","right","bottom"],"sources":["../../src/components/uvalib-image-regions/regions.ts"],"sourcesContent":["/**\n * Region parsing shared by `<uvalib-image-regions>` and `<uvalib-lightbox>` (its\n * `data-regions`). No Lit, no DOM rendering: small enough for the lightbox to import\n * statically.\n */\n\n/** One region on an image. */\nexport interface ImageRegion {\n /** A stable id, sent back in events. */\n id?: string;\n /** The region's name, shown in the list and on the highlighted outline. */\n label: string;\n /** Left edge, in `unit`s from the image's left. */\n x: number;\n /** Top edge, in `unit`s from the image's top. */\n y: number;\n /** Width, in `unit`s. */\n w: number;\n /** Height, in `unit`s. */\n h: number;\n /**\n * `percent` (of the image's width and height) or `px` (pixels of the image's natural size,\n * or of `image-width` × `image-height` when set). Default `px`, as in IIIF.\n */\n unit?: 'px' | 'percent';\n /** Where the region's list entry links. */\n href?: string;\n /** A short description after the label in the list. */\n description?: string;\n}\n\n/** A region box: its unit and four numbers. */\nexport interface RegionBox {\n x: number;\n y: number;\n w: number;\n h: number;\n unit: 'px' | 'percent';\n}\n\n/**\n * A IIIF / Media Fragments `xywh` value: `percent:10,20,30,40`, `pixel:160,120,320,240`\n * or `160,120,320,240` (pixels), optionally as `xywh=…` or a URL ending `#xywh=…`.\n * Returns null for anything else, and for a zero width or height. Regions are unsigned;\n * `signed` also takes a negative `x` and `y` (a lightbox version's `frame`: the original's\n * box in a crop starts left of or above it). The width and height stay positive.\n */\nexport function parseXywh(\n value: string | null | undefined,\n options: { signed?: boolean } = {},\n): RegionBox | null {\n let s = String(value ?? '').trim();\n const at = s.lastIndexOf('xywh=');\n if (at >= 0) s = s.slice(at + 5);\n s = s.split('&')[0]!.trim();\n let unit: RegionBox['unit'] = 'px';\n const prefix = /^(pixel|percent):/i.exec(s);\n if (prefix) {\n unit = prefix[1]!.toLowerCase() === 'percent' ? 'percent' : 'px';\n s = s.slice(prefix[0].length);\n }\n const parts = s.split(',');\n const num = options.signed ? /^\\s*-?\\d+(\\.\\d+)?\\s*$/ : /^\\s*\\d+(\\.\\d+)?\\s*$/;\n if (parts.length !== 4 || parts.some((p) => !num.test(p))) return null;\n const [x, y, w, h] = parts.map(Number) as [number, number, number, number];\n if (w <= 0 || h <= 0) return null;\n return { x, y, w, h, unit };\n}\n\nconst text = (v: unknown): string =>\n String(v ?? '')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/** A usable region from an unknown value (an `items` entry or JSON), or null. */\nexport function toRegion(v: unknown): ImageRegion | null {\n if (!v || typeof v !== 'object') return null;\n const o = v as Record<string, unknown>;\n const label = text(o.label);\n let box: RegionBox | null = null;\n if (typeof o.xywh === 'string') box = parseXywh(o.xywh);\n else {\n const n = [o.x, o.y, o.w, o.h].map((x) => (typeof x === 'string' ? Number(x) : x));\n if (n.every((x) => typeof x === 'number' && Number.isFinite(x) && x >= 0)) {\n const [x, y, w, h] = n as number[];\n if (w! > 0 && h! > 0)\n box = { x: x!, y: y!, w: w!, h: h!, unit: o.unit === 'percent' ? 'percent' : 'px' };\n }\n }\n if (!box) return null;\n const out: ImageRegion = { label, ...box };\n if (o.id != null && text(o.id)) out.id = text(o.id);\n if (typeof o.href === 'string' && o.href.trim()) out.href = o.href.trim();\n if (o.description != null && text(o.description)) out.description = text(o.description);\n return out;\n}\n\n/**\n * Regions written in an attribute (the lightbox's `data-regions`): a JSON array of region\n * objects, or entries separated by `;`, each an `xywh` value then its label, e.g.\n * `percent:10,20,30,40 Person 1; percent:55,15,20,30 Sign`. Entries that do not parse are\n * dropped.\n */\nexport function parseRegions(value: string | null | undefined): ImageRegion[] {\n const s = String(value ?? '').trim();\n if (!s) return [];\n if (s.startsWith('[')) {\n try {\n const list: unknown = JSON.parse(s);\n return Array.isArray(list)\n ? list.map(toRegion).filter((r): r is ImageRegion => r !== null)\n : [];\n } catch {\n return [];\n }\n }\n const out: ImageRegion[] = [];\n for (const entry of s.split(';')) {\n const m = /^\\s*(\\S+)\\s*(.*)$/.exec(entry);\n if (!m) continue;\n const box = parseXywh(m[1]);\n if (box) out.push({ label: text(m[2]), ...box });\n }\n return out;\n}\n\n/**\n * The box in percent of the image, clamped to it. Pixel boxes need the coordinate space\n * (`width` × `height`); without it they return null (not drawn yet).\n */\nexport function toPercent(box: RegionBox, width: number, height: number): RegionBox | null {\n let { x, y, w, h } = box;\n if (box.unit === 'px') {\n if (!(width > 0) || !(height > 0)) return null;\n x = (x / width) * 100;\n w = (w / width) * 100;\n y = (y / height) * 100;\n h = (h / height) * 100;\n }\n const clamp = (v: number) => Math.min(100, Math.max(0, v));\n const left = clamp(x);\n const top = clamp(y);\n const right = clamp(x + w);\n const bottom = clamp(y + h);\n if (right <= left || bottom <= top) return null;\n return { x: left, y: top, w: right - left, h: bottom - top, unit: 'percent' };\n}\n"],"mappings":";AA+CA,SAAgBA,EACd,GACA,IAAgC,CAAC,GACf;CAClB,IAAIC,IAAI,OAAOC,KAAS,EAAE,CAAC,CAAC,KAAK,GAC3BC,IAAKF,EAAE,YAAY,OAAO;CAEhC,AADIE,KAAM,MAAG,IAAIF,EAAE,MAAME,IAAK,CAAC,IAC/B,IAAIF,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK;CAC1B,IAAIG,IAA0B,MACxBC,IAAS,qBAAqB,KAAKJ,CAAC;CAC1C,AAAII,MACF,IAAOA,EAAO,EAAE,CAAE,YAAY,MAAM,YAAY,YAAY,MAC5D,IAAIJ,EAAE,MAAMI,EAAO,EAAE,CAAC,MAAM;CAE9B,IAAMC,IAAQL,EAAE,MAAM,GAAG,GACnBM,IAAMC,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,GACnBsB,IAASJ,EAAMnB,IAAIE,CAAC;CAE1B,OADIoB,KAASF,KAAQG,KAAUF,IAAY,OACpC;EAAE,GAAGD;EAAM,GAAGC;EAAK,GAAGC,IAAQF;EAAM,GAAGG,IAASF;EAAK,MAAM;CAAU;AAC9E"}
@@ -0,0 +1,17 @@
1
+ // src/base/states.ts
2
+ function e(e) {
3
+ try {
4
+ return typeof e.attachInternals == "function" ? e.attachInternals() : void 0;
5
+ } catch {
6
+ return;
7
+ }
8
+ }
9
+ function t(e, t, n) {
10
+ let r = e?.states;
11
+ if (r) try {
12
+ n ? r.add(t) : r.delete(t);
13
+ } catch {}
14
+ }
15
+ export { t as n, e as t };
16
+
17
+ //# sourceMappingURL=states-DGXGzcte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"states-DGXGzcte.js","names":["attachStateInternals","el","setState","states","internals","on","name"],"sources":["../../src/base/states.ts"],"sourcesContent":["/**\n * Custom states (`ElementInternals.states`, matched by `:state(name)`): runtime flags a page\n * can style but not set. They reach CSS only, never assistive technologies, so each one\n * mirrors state the component already exposes (aria-expanded, aria-invalid, a dialog's open).\n */\n\n/** The element's internals, or undefined where the browser has none (or they are taken). */\nexport function attachStateInternals(el: HTMLElement): ElementInternals | undefined {\n try {\n return typeof el.attachInternals === 'function' ? el.attachInternals() : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Turn `name` on or off. A no-op without `states` (older engines), and where only the old\n * `--name` syntax is accepted (Chromium before 125 throws on a plain name).\n */\nexport function setState(internals: ElementInternals | undefined, name: string, on: boolean): void {\n const states = internals?.states;\n if (!states) return;\n try {\n if (on) states.add(name);\n else states.delete(name);\n } catch {\n // Not supported in this form: the state simply never matches.\n }\n}\n"],"mappings":";AAOA,SAAgBA,EAAqB,GAA+C;CAClF,IAAI;EACF,OAAO,OAAOC,EAAG,mBAAoB,aAAaA,EAAG,gBAAgB,IAAI,KAAA;CAC3E,QAAQ;EACN;CACF;AACF;AAMA,SAAgBC,EAAS,GAAyC,GAAc,GAAmB;CACjG,IAAMC,IAASC,GAAW;CAC1B,IAAKD,GACL,IAAI;EACF,AAAIE,IAAIF,EAAO,IAAIG,CAAI,IAClBH,EAAO,OAAOG,CAAI;CACzB,QAAQ,CAER;AACF"}