@uvalib/web-components 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,10 +51,10 @@ function E(e, t) {
51
51
  }
52
52
  }
53
53
  // src/components/uvalib-lightbox/UvalibLightbox.ts
54
- var D = (e) => {
54
+ var D = "uvalib-regions-list", O = ["data-uvalib-region", "data-uvalib-active"], k = (e) => {
55
55
  let t = Number(e);
56
56
  return t > 0 ? t : void 0;
57
- }, O = (e) => String(e ?? "").replace(/\s+/g, " ").trim(), k = (e) => `
57
+ }, A = (e) => String(e ?? "").replace(/\s+/g, " ").trim(), j = (e) => `
58
58
  ${e} { display: block; }
59
59
  ${e} .viewer { display: contents; }
60
60
  ${e} dialog {
@@ -97,15 +97,15 @@ var D = (e) => {
97
97
  ${e} .details:empty { display: none; }
98
98
  ${e} > [slot="details"] { display: none; }
99
99
  ${e}[hidden], ${e} [hidden] { display: none !important; }
100
- `, A = s(k(":host")), j = 0, M = null;
101
- function N() {
102
- M || customElements.get("uvalib-image-regions") || (M = import("./uvalib-image-regions.js").catch((e) => {
103
- M = null, console.warn("uvalib-lightbox: could not load uvalib-image-regions.", e);
100
+ `, M = s(j(":host")), N = 0, P = null;
101
+ function F() {
102
+ P || customElements.get("uvalib-image-regions") || (P = import("./uvalib-image-regions.js").catch((e) => {
103
+ P = null, console.warn("uvalib-lightbox: could not load uvalib-image-regions.", e);
104
104
  }));
105
105
  }
106
- var P = class extends l {
106
+ var I = class extends l {
107
107
  constructor(...e) {
108
- super(...e), this.selector = "", this.urlParam = "", this.regionsLabel = "Regions", this.slides = [], this.index = 0, this.open = !1, this.status = "loading", this.fitW = 0, this.fitH = 0, this.showRegions = !0, this.captionId = `uvalib-lightbox-caption-${++j}`, this.trigger = null, this.historyPushed = !1, this.userClosed = !1, this.suppressClose = !1, this.warnedSelector = !1, this.lastSrc = "", this.syncQueued = !1, this.regionsChanged = !1, this.resizeTimer = 0, this.ignoreClose = !1, this.dismissing = !1, this.revealTries = 0, this.revealFrame = 0, this.listened = !1, this.pendingBack = !1, this.backInHash = !1, this.queuedOpen = null, this.reopenGuard = !1, this.parked = [], this.parkedKey = "", this.onResize = () => {
108
+ super(...e), this.selector = "", this.urlParam = "", this.regionsLabel = "Regions", this.slides = [], this.index = 0, this.open = !1, this.status = "loading", this.fitW = 0, this.fitH = 0, this.showRegions = !0, this.captionId = `uvalib-lightbox-caption-${++N}`, this.trigger = null, this.historyPushed = !1, this.userClosed = !1, this.suppressClose = !1, this.warnedSelector = !1, this.lastSrc = "", this.syncQueued = !1, this.regionsChanged = !1, this.resizeTimer = 0, this.ignoreClose = !1, this.dismissing = !1, this.revealTries = 0, this.revealFrame = 0, this.listened = !1, this.pendingBack = !1, this.backInHash = !1, this.queuedOpen = null, this.reopenGuard = !1, this.parked = [], this.parkedKey = "", this.lent = null, this.entryTabindex = /* @__PURE__ */ new WeakMap(), this.warnedList = !1, this.refocus = !1, this.onResize = () => {
109
109
  this.open && (window.clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => {
110
110
  this.isConnected && this.open && this.measure();
111
111
  }, 150));
@@ -161,7 +161,7 @@ var P = class extends l {
161
161
  static {
162
162
  this.styles = [
163
163
  d,
164
- A,
164
+ M,
165
165
  t`
166
166
  .panel {
167
167
  background: var(--uva-color-surface-raised, var(--uva-color-surface, #fff));
@@ -265,7 +265,7 @@ var P = class extends l {
265
265
  createRenderRoot() {
266
266
  if (!this.isLight) {
267
267
  let e = super.createRenderRoot();
268
- return this.noStyle && e instanceof ShadowRoot && (e.adoptedStyleSheets = [d.styleSheet, A.styleSheet].filter((e) => e != null)), e;
268
+ return this.noStyle && e instanceof ShadowRoot && (e.adoptedStyleSheets = [d.styleSheet, M.styleSheet].filter((e) => e != null)), e;
269
269
  }
270
270
  let e = this.ownerDocument.createElement("div");
271
271
  return e.className = "viewer", this.mount = e, this.append(e), e;
@@ -280,7 +280,7 @@ var P = class extends l {
280
280
  e?.open && e.close(), this.suppressClose = !1, this.ignoreClose = !1;
281
281
  }
282
282
  willUpdate() {
283
- if (!this.open) {
283
+ if (this.lendList(), !this.open) {
284
284
  this.lastSrc = "";
285
285
  return;
286
286
  }
@@ -288,14 +288,14 @@ var P = class extends l {
288
288
  e === this.lastSrc ? !e && this.status !== "error" && (this.status = "error") : (this.lastSrc = e, this.status = e ? "loading" : "error");
289
289
  }
290
290
  updated(e) {
291
- super.updated(e), e.has("selector") && this.watch(), e.has("regions") && this.isConnected && this.scheduleSync(!0), this.open ? ((e.has("open") || e.has("index") || e.has("slides")) && this.placeDetails(), this.current?.regions.length && N(), this.bindDialogObserver(), e.has("open") && this.reveal(), queueMicrotask(() => {
291
+ super.updated(e), e.has("selector") && this.watch(), (e.has("regions") || e.has("regionsList")) && this.isConnected && this.scheduleSync(!0), this.open ? ((e.has("open") || e.has("index") || e.has("slides")) && this.placeDetails(), (this.current?.regions.length || this.current?.list) && F(), this.lendList(!0), this.refocus && (this.refocus = !1, this.closeBtn?.focus()), this.bindDialogObserver(), e.has("open") && this.reveal(), queueMicrotask(() => {
292
292
  this.isConnected && this.settleImage();
293
293
  })) : e.has("open") && this.restoreDetails();
294
294
  }
295
295
  installLight(e) {
296
296
  if (!e) return;
297
297
  let t = this.getRootNode(), n = t instanceof Document || t instanceof ShadowRoot ? t : void 0;
298
- this.noStyle ? (c(`${this.localName}::structure`, s(k(this.localName)), {
298
+ this.noStyle ? (c(`${this.localName}::structure`, s(j(this.localName)), {
299
299
  root: n,
300
300
  scope: !1
301
301
  }), c(`${this.localName}::a11y`, d, { root: n })) : c(this.localName, this.constructor.elementStyles, { root: n });
@@ -332,6 +332,7 @@ var P = class extends l {
332
332
  "data-id",
333
333
  "data-details-id",
334
334
  "data-regions",
335
+ "data-regions-list",
335
336
  "data-image-width",
336
337
  "data-image-height",
337
338
  "slot"
@@ -347,7 +348,8 @@ var P = class extends l {
347
348
  e && (this.regionsChanged = !0), this.syncQueued || (this.syncQueued = !0, queueMicrotask(() => {
348
349
  if (this.syncQueued = !1, !this.isConnected) return;
349
350
  let e = this.collect(), t = this.regionsChanged;
350
- if (this.regionsChanged = !1, t || e.length !== this.slides.length || !e.every((e, t) => e.el === this.slides[t]?.el && e.href === this.slides[t]?.href && e.id === this.slides[t]?.id && e.caption === this.slides[t]?.caption && e.detailsId === this.slides[t]?.detailsId && JSON.stringify([
351
+ this.regionsChanged = !1;
352
+ let n = !t && e.length === this.slides.length && e.every((e, t) => e.el === this.slides[t]?.el && e.href === this.slides[t]?.href && e.id === this.slides[t]?.id && e.caption === this.slides[t]?.caption && e.detailsId === this.slides[t]?.detailsId && e.list === this.slides[t]?.list && JSON.stringify([
351
353
  e.regions,
352
354
  e.imageWidth,
353
355
  e.imageHeight
@@ -355,7 +357,8 @@ var P = class extends l {
355
357
  this.slides[t]?.regions,
356
358
  this.slides[t]?.imageWidth,
357
359
  this.slides[t]?.imageHeight
358
- ]))) {
360
+ ]));
361
+ if (this.noteEntries(), !n) {
359
362
  let t = this.current?.el;
360
363
  if (this.slides = e, this.open) {
361
364
  let n = t ? e.findIndex((e) => e.el === t) : -1;
@@ -380,7 +383,7 @@ var P = class extends l {
380
383
  }
381
384
  for (let e of r) n(e);
382
385
  let i = (n) => {
383
- if (!(n instanceof HTMLAnchorElement) || !n.hasAttribute("href") || n.closest("[hidden]") || this.mount?.contains(n) || n.closest("dialog") || n.closest("[slot=\"details\"]")) return;
386
+ if (!(n instanceof HTMLAnchorElement) || !n.hasAttribute("href") || n.closest("[hidden]") || this.mount?.contains(n) || n.closest("dialog") || n.closest("[slot=\"details\"]") || this.lent?.el.contains(n)) return;
384
387
  for (let e of t) if (e.contains(n)) return;
385
388
  let r = n.closest("uvalib-lightbox");
386
389
  r && r !== this || e.push(n);
@@ -394,17 +397,18 @@ var P = class extends l {
394
397
  }), a.map((e, t) => this.slide(e, t));
395
398
  }
396
399
  slide(e, t) {
397
- let n = e.getAttribute("href") ?? "", r = e.querySelector("img"), i = O(r?.getAttribute("data-uvalib-alt") || r?.getAttribute("alt")), a = this.linkText(e), o = O(e.dataset.caption) || i || a || O(e.getAttribute("title")) || "Image", s = O(e.dataset.id) || e.id || w(n, this.base) || String(t + 1);
398
- return {
400
+ let n = e.getAttribute("href") ?? "", r = e.querySelector("img"), i = A(r?.getAttribute("data-uvalib-alt") || r?.getAttribute("alt")), a = this.linkText(e), o = A(e.dataset.caption) || i || a || A(e.getAttribute("title")) || "Image", s = A(e.dataset.id) || e.id || w(n, this.base) || String(t + 1), c = this.listOf(e, s, n, t), l = this.regionsOf(e, s, n, t);
401
+ return c && l.length && !this.warnedList && (this.warnedList = !0, console.warn(`${this.localName}: an image has both regions and a regions list; the list is used.`)), {
399
402
  el: e,
400
403
  id: s,
401
404
  href: n,
402
405
  caption: o,
403
406
  alt: i || o,
404
- detailsId: O(e.dataset.detailsId) || null,
405
- regions: this.regionsOf(e, s, n, t),
406
- imageWidth: D(e.dataset.imageWidth),
407
- imageHeight: D(e.dataset.imageHeight)
407
+ detailsId: A(e.dataset.detailsId) || null,
408
+ regions: c ? [] : l,
409
+ list: c,
410
+ imageWidth: k(e.dataset.imageWidth),
411
+ imageHeight: k(e.dataset.imageHeight)
408
412
  };
409
413
  }
410
414
  regionsOf(e, t, n, r) {
@@ -428,11 +432,26 @@ var P = class extends l {
428
432
  }
429
433
  return i;
430
434
  }
435
+ listOf(e, t, n, r) {
436
+ let i = null, a = A(e.dataset.regionsList);
437
+ if (a) i = this.scope.getElementById(a);
438
+ else if (typeof this.regionsList == "function") try {
439
+ i = this.regionsList({
440
+ element: e,
441
+ id: t,
442
+ href: n,
443
+ index: r
444
+ });
445
+ } catch (e) {
446
+ console.warn(`${this.localName}: the regionsList callback threw.`, e);
447
+ }
448
+ return i instanceof HTMLOListElement || i instanceof HTMLUListElement ? i.contains(this) || i.contains(e) ? null : i : null;
449
+ }
431
450
  linkText(e) {
432
451
  let t = [], n = (e) => {
433
452
  e instanceof HTMLImageElement || e instanceof HTMLElement && (e.hidden || e.getAttribute("slot") === "details" || e.getAttribute("slot") === "badge" || e.classList.contains("badge") || e.classList.contains("visually-hidden") || e.hasAttribute("data-uvalib-generated-badge") || e.hasAttribute("data-uvalib-badge-sep")) || (e.nodeType === Node.TEXT_NODE ? t.push(e.textContent ?? "") : e.childNodes.forEach(n));
434
453
  };
435
- return e.childNodes.forEach(n), O(t.join(" "));
454
+ return e.childNodes.forEach(n), A(t.join(" "));
436
455
  }
437
456
  get current() {
438
457
  return this.slides[this.index];
@@ -647,7 +666,52 @@ var P = class extends l {
647
666
  }
648
667
  restoreDetails() {
649
668
  for (let e = this.parked.length - 1; e >= 0; e--) this.putBack(this.parked[e]);
650
- this.parked = [], this.parkedKey = "";
669
+ this.parked = [], this.parkedKey = "", this.returnList();
670
+ }
671
+ get wantedList() {
672
+ if (!this.open) return null;
673
+ let e = this.current?.list ?? null;
674
+ return e && this.displaySrc ? e : null;
675
+ }
676
+ lendList(e = !1) {
677
+ let t = this.wantedList;
678
+ if (this.lent && this.lent.el !== t && this.returnList(), !t || this.isLight && !e) return;
679
+ let n = this.isLight ? this.renderRoot.querySelector("uvalib-image-regions") : this;
680
+ if (n && t.parentNode !== n) {
681
+ if (!this.lent) {
682
+ let e = t.parentNode;
683
+ if (!e) return;
684
+ this.lent = {
685
+ el: t,
686
+ parent: e,
687
+ next: t.nextSibling,
688
+ hidden: t.hidden,
689
+ slot: t.getAttribute("slot")
690
+ };
691
+ }
692
+ this.noteEntries(), this.isLight ? t.removeAttribute("slot") : t.setAttribute("slot", D), t.hidden = !1, n.append(t);
693
+ }
694
+ }
695
+ noteEntries() {
696
+ let e = this.lent?.el;
697
+ if (e) for (let t of e.children) this.entryTabindex.has(t) || this.entryTabindex.set(t, t.getAttribute("tabindex"));
698
+ }
699
+ returnList() {
700
+ let e = this.lent;
701
+ if (!e) return;
702
+ this.lent = null;
703
+ let { el: t } = e, n = this.shadowRoot?.activeElement ?? this.ownerDocument.activeElement;
704
+ this.open && n && t.contains(n) && (this.refocus = !0);
705
+ for (let e of t.children) {
706
+ for (let t of O) e.removeAttribute(t);
707
+ if (this.entryTabindex.has(e)) {
708
+ let t = this.entryTabindex.get(e);
709
+ t == null ? e.removeAttribute("tabindex") : e.setAttribute("tabindex", t);
710
+ }
711
+ }
712
+ this.entryTabindex = /* @__PURE__ */ new WeakMap(), e.slot == null ? t.removeAttribute("slot") : t.setAttribute("slot", e.slot), t.hidden = e.hidden;
713
+ let r = e.next?.parentNode === e.parent ? e.next : null;
714
+ e.parent.insertBefore(t, r);
651
715
  }
652
716
  get statusText() {
653
717
  return this.open ? this.status === "loading" ? "Loading image." : this.status === "error" ? "This image could not be loaded." : "" : "";
@@ -655,27 +719,29 @@ var P = class extends l {
655
719
  renderImage(e, t, n) {
656
720
  let i = r`<img
657
721
  part="image"
658
- slot=${n ? "image" : o}
722
+ slot=${n || e.list ? "image" : o}
659
723
  alt=${e.alt}
660
724
  src=${t}
661
725
  aria-busy=${this.status === "loading" ? "true" : "false"}
662
726
  @load=${this.onLoad}
663
727
  @error=${this.onError}
664
728
  />`;
665
- return n ? r`<uvalib-image-regions
729
+ if (!n && !e.list) return i;
730
+ let a = e.list && !this.isLight ? r`<slot name=${D}></slot>` : o;
731
+ return r`<uvalib-image-regions
666
732
  class="regions"
667
733
  part="regions"
668
- .items=${n}
669
- label=${O(this.regionsLabel) || "Regions"}
734
+ .items=${e.list ? null : n}
735
+ label=${A(this.regionsLabel) || "Regions"}
670
736
  image-width=${e.imageWidth ?? o}
671
737
  image-height=${e.imageHeight ?? o}
672
738
  ?hide-outlines=${!this.showRegions}
673
739
  ?no-style=${this.noStyle}
674
- >${i}</uvalib-image-regions
675
- >` : i;
740
+ >${i}${a}</uvalib-image-regions
741
+ >`;
676
742
  }
677
743
  render() {
678
- let e = this.open ? this.current : void 0, t = e ? this.displaySrc : "", n = e && E(e.href, this.base) ? e.href : "", i = this.statusText, a = e?.regions.length ? e.regions : null, s = this.multiple ? r`<p class="count" aria-live="polite">${this.index + 1} of ${this.slides.length}</p>` : o;
744
+ let e = this.open ? this.current : void 0, t = e ? this.displaySrc : "", n = e && E(e.href, this.base) ? e.href : "", i = this.statusText, a = e?.regions.length ? e.regions : null, s = !!(a || e?.list), c = this.multiple ? r`<p class="count" aria-live="polite">${this.index + 1} of ${this.slides.length}</p>` : o;
679
745
  return r`
680
746
  ${this.isLight ? o : r`<slot></slot><slot name="details" hidden></slot>`}
681
747
  <dialog
@@ -695,7 +761,7 @@ var P = class extends l {
695
761
  <figure class="figure">${t ? this.renderImage(e, t, a) : o}</figure>
696
762
  <p class="status ${i ? "" : "visually-hidden"}" role="status">${i}</p>
697
763
  <div class="toolbar" part="controls">
698
- ${a && t ? r`<button
764
+ ${s && t ? r`<button
699
765
  type="button"
700
766
  class="regions-toggle"
701
767
  aria-pressed=${this.showRegions ? "true" : "false"}
@@ -707,7 +773,7 @@ var P = class extends l {
707
773
  Previous
708
774
  </button>
709
775
  <button type="button" class="next" @click=${() => this.step(1)}>Next</button>
710
- ${s}` : o}
776
+ ${c}` : o}
711
777
  ${n ? r`<a
712
778
  class="full"
713
779
  href=${n}
@@ -724,6 +790,6 @@ var P = class extends l {
724
790
  }
725
791
  };
726
792
  // src/components/uvalib-lightbox/uvalib-lightbox.ts
727
- a([e({ type: String })], P.prototype, "selector", void 0), a([e({ attribute: "url-param" })], P.prototype, "urlParam", void 0), a([e({ attribute: !1 })], P.prototype, "regions", void 0), a([e({ attribute: "regions-label" })], P.prototype, "regionsLabel", void 0), a([n()], P.prototype, "slides", void 0), a([n()], P.prototype, "index", void 0), a([n()], P.prototype, "open", void 0), a([n()], P.prototype, "status", void 0), a([n()], P.prototype, "fitW", void 0), a([n()], P.prototype, "fitH", void 0), a([n()], P.prototype, "showRegions", void 0), i("uvalib-lightbox", P);
793
+ a([e({ type: String })], I.prototype, "selector", void 0), a([e({ attribute: "url-param" })], I.prototype, "urlParam", void 0), a([e({ attribute: !1 })], I.prototype, "regions", void 0), a([e({ attribute: !1 })], I.prototype, "regionsList", void 0), a([e({ attribute: "regions-label" })], I.prototype, "regionsLabel", void 0), a([n()], I.prototype, "slides", void 0), a([n()], I.prototype, "index", void 0), a([n()], I.prototype, "open", void 0), a([n()], I.prototype, "status", void 0), a([n()], I.prototype, "fitW", void 0), a([n()], I.prototype, "fitH", void 0), a([n()], I.prototype, "showRegions", void 0), i("uvalib-lightbox", I);
728
794
 
729
795
  //# sourceMappingURL=uvalib-lightbox.js.map