@uvalib/web-components 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,18 +94,19 @@ var D = "uvalib-regions-list", O = ["data-uvalib-region", "data-uvalib-active"],
94
94
  font: inherit;
95
95
  }
96
96
  ${e} .regions { display: block; }
97
+ ${e} .stack { position: relative; width: fit-content; max-width: 100%; margin-inline: auto; }
97
98
  ${e} .details:empty { display: none; }
98
99
  ${e} > [slot="details"] { display: none; }
99
100
  ${e}[hidden], ${e} [hidden] { display: none !important; }
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);
101
+ `, M = s(j(":host")), N = 0, P = null, F = null, I = null;
102
+ function L() {
103
+ I || customElements.get("uvalib-image-regions") || (I = import("./uvalib-image-regions.js").catch((e) => {
104
+ I = null, console.warn("uvalib-lightbox: could not load uvalib-image-regions.", e);
104
105
  }));
105
106
  }
106
- var I = class extends l {
107
+ var R = class extends l {
107
108
  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-${++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
+ super(...e), this.selector = "", this.urlParam = "", this.regionsLabel = "Regions", this.compare = "switch", this.versionParam = "", 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.pendingVersion = null, this.onResize = () => {
109
110
  this.open && (window.clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => {
110
111
  this.isConnected && this.open && this.measure();
111
112
  }, 150));
@@ -133,13 +134,15 @@ var I = class extends l {
133
134
  }
134
135
  this.userClosed = !1;
135
136
  let t = this.collect(), n = t.findIndex((t) => t.id === e);
136
- n < 0 ? this.open && this.dismiss("pop") : (this.slides = t, this.index = n, this.trigger = t[n]?.el ?? null, this.historyPushed = !0, this.measure(), this.armReopenGuard(), this.open ||= !0);
137
+ n < 0 ? this.open && this.dismiss("pop") : (this.pendingVersion = this.versionFromUrl(), this.slides = t, this.index = n, this.trigger = t[n]?.el ?? null, this.historyPushed = !0, this.measure(), this.armReopenGuard(), this.open ||= !0);
137
138
  }, this.onKey = (e) => {
138
- if (!this.multiple || this.typing(e)) return;
139
+ if (this.typing(e) || this.cmp?.key(e) || !this.multiple || e.type !== "keydown") return;
139
140
  let t = getComputedStyle(this).direction === "rtl", n = t ? "ArrowRight" : "ArrowLeft", r = t ? "ArrowLeft" : "ArrowRight";
140
141
  e.key !== n && e.key !== r || e.altKey || e.metaKey || e.ctrlKey || (e.preventDefault(), this.step(e.key === r ? 1 : -1));
141
142
  }, this.onDialogClick = (e) => {
142
- e.target === this.dialogEl && this.dismiss("ui");
143
+ e.target === this.dialogEl && !this.cmp?.dragged() && this.dismiss("ui");
144
+ }, this.onStack = (e) => {
145
+ this.cmp?.pointer(e);
143
146
  }, this.onDialogClose = () => {
144
147
  this.onNativeClose();
145
148
  }, this.onFullSize = () => {
@@ -284,11 +287,13 @@ var I = class extends l {
284
287
  this.lastSrc = "";
285
288
  return;
286
289
  }
287
- let e = this.displaySrc;
288
- e === this.lastSrc ? !e && this.status !== "error" && (this.status = "error") : (this.lastSrc = e, this.status = e ? "loading" : "error");
290
+ let e = this.current;
291
+ this.cmp && e && (this.cmp.sync(e, this.index, this.pendingVersion), this.pendingVersion = null);
292
+ let t = this.displaySrc;
293
+ t === this.lastSrc ? !t && this.status !== "error" && (this.status = "error") : (this.lastSrc = t, this.status = t ? "loading" : "error");
289
294
  }
290
295
  updated(e) {
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(() => {
296
+ super.updated(e), e.has("selector") && this.watch(), (e.has("regions") || e.has("regionsList") || e.has("versions")) && 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) && L(), this.current?.versions && this.loadCompare(), this.lendList(!0), this.refocus && (this.refocus = !1, this.closeBtn?.focus()), this.bindDialogObserver(), e.has("open") && this.reveal(), queueMicrotask(() => {
292
297
  this.isConnected && this.settleImage();
293
298
  })) : e.has("open") && this.restoreDetails();
294
299
  }
@@ -333,6 +338,7 @@ var I = class extends l {
333
338
  "data-details-id",
334
339
  "data-regions",
335
340
  "data-regions-list",
341
+ "data-versions",
336
342
  "data-image-width",
337
343
  "data-image-height",
338
344
  "slot"
@@ -352,11 +358,13 @@ var I = class extends l {
352
358
  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([
353
359
  e.regions,
354
360
  e.imageWidth,
355
- e.imageHeight
361
+ e.imageHeight,
362
+ e.versions
356
363
  ]) === JSON.stringify([
357
364
  this.slides[t]?.regions,
358
365
  this.slides[t]?.imageWidth,
359
- this.slides[t]?.imageHeight
366
+ this.slides[t]?.imageHeight,
367
+ this.slides[t]?.versions
360
368
  ]));
361
369
  if (this.noteEntries(), !n) {
362
370
  let t = this.current?.el;
@@ -408,7 +416,47 @@ var I = class extends l {
408
416
  regions: c ? [] : l,
409
417
  list: c,
410
418
  imageWidth: k(e.dataset.imageWidth),
411
- imageHeight: k(e.dataset.imageHeight)
419
+ imageHeight: k(e.dataset.imageHeight),
420
+ versions: this.versionsOf(e, s, n, t)
421
+ };
422
+ }
423
+ versionsOf(e, t, n, r) {
424
+ let i = e.dataset.versions?.trim();
425
+ if (i) return i;
426
+ if (typeof this.versions != "function") return null;
427
+ try {
428
+ let i = this.versions({
429
+ element: e,
430
+ id: t,
431
+ href: n,
432
+ index: r
433
+ });
434
+ return Array.isArray(i) && i.length ? [...i] : null;
435
+ } catch (e) {
436
+ return console.warn(`${this.localName}: the versions callback threw.`, e), null;
437
+ }
438
+ }
439
+ loadCompare() {
440
+ this.cmp || (P ? (this.cmp = new P.Compare(this.compareHost()), this.requestUpdate()) : (F ??= import("./chunks/compare-D4VdaIJN.js").then((e) => {
441
+ P = e;
442
+ }).catch((e) => {
443
+ F = null, console.warn("uvalib-lightbox: could not load the version comparison.", e);
444
+ }), F.then(() => {
445
+ P && this.isConnected && this.loadCompare();
446
+ })));
447
+ }
448
+ compareHost() {
449
+ return {
450
+ el: this,
451
+ light: this.isLight,
452
+ root: this.isLight ? this.scope : this.renderRoot,
453
+ noStyle: this.noStyle,
454
+ mode: () => this.compare,
455
+ size: (e) => this.sized(e),
456
+ write: (e) => {
457
+ this.versionParam && this.open && this.writeParam(this.current?.id ?? null, "replace", void 0, e);
458
+ },
459
+ update: () => this.requestUpdate()
412
460
  };
413
461
  }
414
462
  regionsOf(e, t, n, r) {
@@ -460,7 +508,9 @@ var I = class extends l {
460
508
  return this.slides.length > 1;
461
509
  }
462
510
  get displaySrc() {
463
- let e = this.current?.href ?? "";
511
+ return this.sized(this.current?.href ?? "");
512
+ }
513
+ sized(e) {
464
514
  if (!E(e, this.base)) return "";
465
515
  let t = this.fitW || T(window).w, n = this.fitH || T(window).h;
466
516
  return C(e, this.base, t, n) ?? e;
@@ -477,7 +527,7 @@ var I = class extends l {
477
527
  activate(e, t) {
478
528
  let n = this.open;
479
529
  if (!(n && this.index === e)) {
480
- if (this.slides = t, this.index = e, this.trigger = t[e]?.el ?? null, this.userClosed = !1, this.measure(), this.open = !0, this.pendingBack) this.queuedOpen = {
530
+ if (this.slides = t, this.index = e, this.trigger = t[e]?.el ?? null, this.userClosed = !1, this.pendingVersion = null, this.cmp?.reset(), this.measure(), this.open = !0, this.pendingBack) this.queuedOpen = {
481
531
  i: e,
482
532
  slides: t
483
533
  };
@@ -500,14 +550,19 @@ var I = class extends l {
500
550
  let t = this.slides.length ? this.slides : this.collect(), n = t.findIndex((t) => t.id === e);
501
551
  if (n < 0) return;
502
552
  this.slides = t, this.index = n, this.trigger = t[n]?.el ?? null, this.measure();
503
- let r = h(location.hash);
504
- this.writeParam(null, "replace", r), this.historyPushed = this.writeParam(e, "push", r), this.open = !0;
553
+ let r = this.versionFromUrl();
554
+ this.pendingVersion = r;
555
+ let i = h(location.hash);
556
+ this.writeParam(null, "replace", i), this.historyPushed = this.writeParam(e, "push", i, r), this.open = !0;
557
+ }
558
+ versionFromUrl() {
559
+ return this.versionParam ? m(this.loc(), this.versionParam) : null;
505
560
  }
506
561
  step(e) {
507
562
  let t = this.slides.length;
508
563
  if (t < 2) return;
509
564
  let n = (this.index + e + t) % t;
510
- this.index = n, this.trigger = this.slides[n]?.el ?? this.trigger, this.urlParam && this.writeParam(this.slides[n]?.id ?? null, "replace");
565
+ this.index = n, this.pendingVersion = null, this.trigger = this.slides[n]?.el ?? this.trigger, this.urlParam && this.writeParam(this.slides[n]?.id ?? null, "replace");
511
566
  let r = e < 0 ? "previous" : "next";
512
567
  u(this, [
513
568
  "uvalib-lightbox",
@@ -520,7 +575,7 @@ var I = class extends l {
520
575
  if (this.dismissing) return;
521
576
  let t = this.dialogEl;
522
577
  if (this.open || t?.open) {
523
- this.dismissing = !0;
578
+ this.dismissing = !0, this.cmp?.reset();
524
579
  try {
525
580
  let n = this.historyPushed;
526
581
  this.historyPushed = !1, this.ignoreClose = !0, this.cancelReveal(), this.open = !1, (e === "ui" || e === "empty") && (this.userClosed = !0), this.restoreDetails(), t?.open && t.close(), this.focusTrigger(), e === "ui" && this.urlParam ? n ? (this.backInHash = h(location.hash), this.pendingBack = !0, history.back()) : this.writeParam(null, "replace", h(location.hash)) : e === "empty" && this.urlParam && (this.pendingBack = !1, this.queuedOpen = null, this.writeParam(null, "replace", h(location.hash)));
@@ -529,16 +584,25 @@ var I = class extends l {
529
584
  }
530
585
  }
531
586
  }
532
- writeParam(e, t, n) {
587
+ writeParam(e, t, n, r = null) {
533
588
  if (!this.urlParam) return !1;
534
- let r = g(this.loc(), this.urlParam, e, n);
535
- if (r === location.pathname + location.search + location.hash) return !1;
536
- let i = history.state && typeof history.state == "object" ? history.state : {};
589
+ let i = this.loc(), a = g(i, this.urlParam, e, n), o = this.versionParam;
590
+ if (o && o !== this.urlParam) {
591
+ let t = a.slice(i.pathname.length), s = t.indexOf("#"), c = {
592
+ pathname: i.pathname,
593
+ search: s < 0 ? t : t.slice(0, s),
594
+ hash: s < 0 ? "" : t.slice(s)
595
+ };
596
+ a = g(c, o, e === null ? null : r, n);
597
+ }
598
+ let s = location.pathname + location.search + location.hash;
599
+ if (a === s) return !1;
600
+ let c = history.state && typeof history.state == "object" ? history.state : {};
537
601
  try {
538
602
  return history[t === "push" ? "pushState" : "replaceState"]({
539
- ...i,
603
+ ...c,
540
604
  uvalibLightbox: this.urlParam
541
- }, "", r), !0;
605
+ }, "", a), !0;
542
606
  } catch {
543
607
  return !1;
544
608
  }
@@ -717,17 +781,27 @@ var I = class extends l {
717
781
  return this.open ? this.status === "loading" ? "Loading image." : this.status === "error" ? "This image could not be loaded." : "" : "";
718
782
  }
719
783
  renderImage(e, t, n) {
720
- let i = r`<img
784
+ let i = !!(n || e.list), a = e.versions && this.cmp?.active ? this.cmp : null, s = r`<img
721
785
  part="image"
722
- slot=${n || e.list ? "image" : o}
723
- alt=${e.alt}
786
+ slot=${i && !e.versions ? "image" : o}
787
+ alt=${a ? a.alt(e.alt) : e.alt}
724
788
  src=${t}
725
789
  aria-busy=${this.status === "loading" ? "true" : "false"}
726
790
  @load=${this.onLoad}
727
791
  @error=${this.onError}
728
- />`;
729
- if (!n && !e.list) return i;
730
- let a = e.list && !this.isLight ? r`<slot name=${D}></slot>` : o;
792
+ />`, c = o;
793
+ if (e.versions && (s = r`<div
794
+ class="stack ${a?.stackClass ?? ""}"
795
+ slot=${i ? "image" : o}
796
+ style=${a?.stackStyle ?? o}
797
+ @pointerdown=${this.onStack}
798
+ @pointermove=${this.onStack}
799
+ @pointerup=${this.onStack}
800
+ @pointercancel=${this.onStack}
801
+ >
802
+ ${s}${a ? a.layers() : o}
803
+ </div>`, a && (c = a.controls(i ? "controls" : ""))), !i) return r`${s}${c}`;
804
+ let l = e.list && !this.isLight ? r`<slot name=${D}></slot>` : o;
731
805
  return r`<uvalib-image-regions
732
806
  class="regions"
733
807
  part="regions"
@@ -737,11 +811,11 @@ var I = class extends l {
737
811
  image-height=${e.imageHeight ?? o}
738
812
  ?hide-outlines=${!this.showRegions}
739
813
  ?no-style=${this.noStyle}
740
- >${i}${a}</uvalib-image-regions
814
+ >${s}${c}${l}</uvalib-image-regions
741
815
  >`;
742
816
  }
743
817
  render() {
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;
818
+ let e = this.open ? this.current : void 0, t = e ? this.displaySrc : "", n = e && E(e.href, this.base) ? e.href : "", i = n && e?.versions && this.cmp?.active ? this.cmp.full() : null, a = this.statusText, s = e?.regions.length ? e.regions : null, c = !!(s || e?.list), l = this.multiple ? r`<p class="count" aria-live="polite">${this.index + 1} of ${this.slides.length}</p>` : o;
745
819
  return r`
746
820
  ${this.isLight ? o : r`<slot></slot><slot name="details" hidden></slot>`}
747
821
  <dialog
@@ -750,6 +824,7 @@ var I = class extends l {
750
824
  @click=${this.onDialogClick}
751
825
  @close=${this.onDialogClose}
752
826
  @keydown=${this.onKey}
827
+ @keyup=${this.onKey}
753
828
  >
754
829
  <div class="panel" part="panel">
755
830
  <div class="head">
@@ -758,10 +833,10 @@ var I = class extends l {
758
833
  Close
759
834
  </button>
760
835
  </div>
761
- <figure class="figure">${t ? this.renderImage(e, t, a) : o}</figure>
762
- <p class="status ${i ? "" : "visually-hidden"}" role="status">${i}</p>
836
+ <figure class="figure">${t ? this.renderImage(e, t, s) : o}</figure>
837
+ <p class="status ${a ? "" : "visually-hidden"}" role="status">${a}</p>
763
838
  <div class="toolbar" part="controls">
764
- ${s && t ? r`<button
839
+ ${c && t ? r`<button
765
840
  type="button"
766
841
  class="regions-toggle"
767
842
  aria-pressed=${this.showRegions ? "true" : "false"}
@@ -773,15 +848,20 @@ var I = class extends l {
773
848
  Previous
774
849
  </button>
775
850
  <button type="button" class="next" @click=${() => this.step(1)}>Next</button>
776
- ${c}` : o}
777
- ${n ? r`<a
778
- class="full"
779
- href=${n}
780
- target="_blank"
781
- rel="noopener noreferrer"
782
- @click=${this.onFullSize}
783
- >Full size<span class="visually-hidden"> (opens in a new tab)</span></a
784
- >` : o}
851
+ ${l}` : o}
852
+ ${(i ?? (n ? [{
853
+ href: n,
854
+ label: ""
855
+ }] : [])).map((e) => r`<a
856
+ class="full"
857
+ href=${e.href}
858
+ target="_blank"
859
+ rel="noopener noreferrer"
860
+ @click=${this.onFullSize}
861
+ >Full size${e.label ? `, ${e.label}` : ""}<span class="visually-hidden">
862
+ (opens in a new tab)</span
863
+ ></a
864
+ >`)}
785
865
  </div>
786
866
  <div class="details" part="details"></div>
787
867
  </div>
@@ -790,6 +870,6 @@ var I = class extends l {
790
870
  }
791
871
  };
792
872
  // src/components/uvalib-lightbox/uvalib-lightbox.ts
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);
873
+ a([e({ type: String })], R.prototype, "selector", void 0), a([e({ attribute: "url-param" })], R.prototype, "urlParam", void 0), a([e({ attribute: !1 })], R.prototype, "regions", void 0), a([e({ attribute: !1 })], R.prototype, "regionsList", void 0), a([e({ attribute: "regions-label" })], R.prototype, "regionsLabel", void 0), a([e({ attribute: !1 })], R.prototype, "versions", void 0), a([e()], R.prototype, "compare", void 0), a([e({ attribute: "version-param" })], R.prototype, "versionParam", void 0), a([n()], R.prototype, "slides", void 0), a([n()], R.prototype, "index", void 0), a([n()], R.prototype, "open", void 0), a([n()], R.prototype, "status", void 0), a([n()], R.prototype, "fitW", void 0), a([n()], R.prototype, "fitH", void 0), a([n()], R.prototype, "showRegions", void 0), i("uvalib-lightbox", R);
794
874
 
795
875
  //# sourceMappingURL=uvalib-lightbox.js.map