@reuse-sh/lightbox 0.3.1 → 0.4.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.
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  function e(e,t,n){let r=t;return e.addEventListener(`play`,()=>r=!1,{signal:n}),{interactive:!0,ready:new Promise(t=>{e.addEventListener(`loadedmetadata`,t,{once:!0,signal:n}),e.addEventListener(`error`,t,{once:!0,signal:n})}),pause:()=>e.pause(),resume(){r&&(r=!1,e.play().catch(t=>{if(t.name===`NotAllowedError`)return e.muted=!0,e.play()}).catch(()=>{}))},unmount(){e.pause(),e.removeAttribute(`src`),e.load(),e.remove()}}}function t(){return{type:`video`,mount(t,{item:n,signal:r,autoplay:i}){let a=t.ownerDocument.createElement(`video`);return a.className=`re-lightbox-video`,a.controls=!0,a.playsInline=!0,a.preload=`metadata`,n.previewSrc&&(a.poster=n.previewSrc),a.src=n.src??``,n.alt&&a.setAttribute(`aria-label`,n.alt),t.append(a),e(a,i,r)}}}export{e as playerOf,t as video};
3
3
  //# sourceMappingURL=video.js.map
package/dist/index.d.ts CHANGED
@@ -67,7 +67,10 @@ export interface LightboxListenOptions {
67
67
  }
68
68
  interface LightboxItemBase {
69
69
  alt?: string;
70
+ /** The caption's text, which the announcement reads. */
70
71
  caption?: string;
72
+ /** Builds the shown caption, such as one with a link or bold text, in place of the text. */
73
+ captionContent?: () => Node;
71
74
  /** The file's own size; without it the viewer fits the preview's proportions until the file decodes. */
72
75
  width?: number;
73
76
  height?: number;
@@ -77,11 +80,20 @@ interface LightboxItemBase {
77
80
  /** The tile the photo opens from and closes to, read again whenever the photo changes. */
78
81
  origin?: HTMLElement | null | (() => HTMLElement | null);
79
82
  }
83
+ /** Room around the photo, each side a fraction of the photo's width, like a CSS padding percentage. */
84
+ export interface LightboxMargins {
85
+ top?: number;
86
+ right?: number;
87
+ bottom?: number;
88
+ left?: number;
89
+ }
80
90
  export interface LightboxImageItem extends LightboxItemBase {
81
91
  type?: undefined;
82
92
  src: string;
83
93
  srcset?: string;
84
94
  sizes?: string;
95
+ /** Makes the photo and this room around it one picture that fits, zooms, pans and flies as a whole; renderContent draws in it. */
96
+ margins?: LightboxMargins;
85
97
  }
86
98
  export interface LightboxMediaItem extends LightboxItemBase {
87
99
  /** Picks the content module whose type matches, such as "video" for video(). */
package/dist/index.js CHANGED
@@ -283,6 +283,10 @@ function validateItems(items, content = []) {
283
283
  (item.height !== undefined &&
284
284
  (!Number.isFinite(item.height) || item.height <= 0)))
285
285
  throw new TypeError("Image dimensions must be positive finite numbers.");
286
+ const margins = item.type === undefined ? item.margins : undefined;
287
+ if (margins &&
288
+ Object.values(margins).some((value) => value !== undefined && !(Number.isFinite(value) && value >= 0)))
289
+ throw new TypeError("Image margins must be finite and 0 or more.");
286
290
  return { ...item };
287
291
  });
288
292
  }
@@ -709,6 +713,19 @@ export function createLightbox(options = {}) {
709
713
  const rect = element.getBoundingClientRect();
710
714
  return rect.width > 0 && rect.height > 0 ? rect : undefined;
711
715
  }
716
+ function footerRoomOf(s) {
717
+ let room = 0;
718
+ if (!s.footerSlots.length)
719
+ return room;
720
+ const gap = Number.parseFloat(s.dialog.ownerDocument.defaultView?.getComputedStyle(s.footer).rowGap ??
721
+ "");
722
+ for (const node of s.footerSlots) {
723
+ const { height } = node.getBoundingClientRect();
724
+ if (height)
725
+ room += height + (gap || 0);
726
+ }
727
+ return room;
728
+ }
712
729
  function measure(s) {
713
730
  const rect = s.viewport.getBoundingClientRect();
714
731
  const win = s.viewport.ownerDocument.defaultView;
@@ -727,10 +744,15 @@ export function createLightbox(options = {}) {
727
744
  inset.left = Math.max(0, strip.right - rect.left);
728
745
  else if (strip && layout === "side")
729
746
  inset.right = Math.max(0, rect.right - strip.left);
747
+ const footerRoom = footerRoomOf(s);
748
+ if (footerRoom !== s.footerRoom) {
749
+ s.footerRoom = footerRoom;
750
+ s.dialog.style.setProperty("--re-lightbox-footer-room", `${footerRoom}px`);
751
+ }
730
752
  const kept = {
731
753
  left: 0,
732
754
  right: 0,
733
- bottom: Number.isFinite(room) ? room : 0,
755
+ bottom: (Number.isFinite(room) ? room : 0) + footerRoom,
734
756
  };
735
757
  const aside = s.aside && rendered(s.aside);
736
758
  if (aside) {
@@ -738,7 +760,7 @@ export function createLightbox(options = {}) {
738
760
  const before = height * Math.max(0, aside.left - rect.left);
739
761
  const after = height * Math.max(0, rect.right - aside.right);
740
762
  if (above >= before && above >= after)
741
- kept.bottom = Math.max(kept.bottom, rect.bottom - aside.top);
763
+ kept.bottom = Math.max(kept.bottom, rect.bottom - aside.top + footerRoom);
742
764
  else if (after > before)
743
765
  kept.left = Math.max(0, aside.right - rect.left);
744
766
  else
@@ -821,9 +843,31 @@ export function createLightbox(options = {}) {
821
843
  height: Math.max(height, width / aspect),
822
844
  };
823
845
  }
846
+ function marginsOf(index) {
847
+ const margins = items[index]?.type === undefined && items[index]?.margins;
848
+ if (!margins)
849
+ return undefined;
850
+ const { top = 0, right = 0, bottom = 0, left = 0 } = margins;
851
+ return { top, right, bottom, left };
852
+ }
853
+ // The picture is the photo and its margins, which the viewer fits, zooms, pans and flies as one.
854
+ function imageSize(index, s) {
855
+ const photo = photoSize(index, s);
856
+ const margins = marginsOf(index);
857
+ if (!margins)
858
+ return photo;
859
+ return {
860
+ width: photo.width * (1 + margins.left + margins.right),
861
+ height: photo.height + photo.width * (margins.top + margins.bottom),
862
+ };
863
+ }
864
+ function photoShare(index) {
865
+ const margins = marginsOf(index);
866
+ return margins ? 1 / (1 + margins.left + margins.right) : 1;
867
+ }
824
868
  // Before the file arrives, the shown preview or the tile gives only the proportions, since its
825
869
  // pixels are the tile's and not the file's; a player has no pixels to stop at. Both fill the screen.
826
- function imageSize(index, s) {
870
+ function photoSize(index, s) {
827
871
  const item = items[index];
828
872
  if (item.width && item.height)
829
873
  return { width: item.width, height: item.height };
@@ -900,8 +944,9 @@ export function createLightbox(options = {}) {
900
944
  const entry = s.loaded.get(index);
901
945
  if (entry?.status === "failed" || item?.type !== undefined)
902
946
  return { min: 1, max: 1, tap: 1 };
947
+ const fileWidth = largestWidth(item?.srcset) ?? entry?.natural ?? item?.width;
903
948
  return zoomLimits({
904
- fileWidth: largestWidth(item?.srcset) ?? entry?.natural ?? item?.width,
949
+ fileWidth: fileWidth && fileWidth / photoShare(index),
905
950
  image: imageSize(index, s),
906
951
  viewport: room(index, s),
907
952
  zoomed: s.area,
@@ -1121,8 +1166,9 @@ export function createLightbox(options = {}) {
1121
1166
  animation.startTime = now;
1122
1167
  return flying;
1123
1168
  }
1124
- function landingCopy(s, image, origin, rect, size, box) {
1169
+ function landingCopy(s, entry, origin, rect, size, box) {
1125
1170
  const doc = s.dialog.ownerDocument;
1171
+ const image = entry.image;
1126
1172
  const src = image.currentSrc || image.src;
1127
1173
  if (origin.ownerDocument !== doc ||
1128
1174
  !origin.parentNode ||
@@ -1130,18 +1176,28 @@ export function createLightbox(options = {}) {
1130
1176
  !image.complete ||
1131
1177
  !image.naturalWidth)
1132
1178
  return undefined;
1133
- const copy = doc.createElement("img");
1134
- copy.className = "re-lightbox-landing";
1135
- copy.alt = "";
1136
- copy.setAttribute("aria-hidden", "true");
1137
- copy.draggable = false;
1138
- copy.src = src;
1139
1179
  const reset = "position:absolute;left:0;top:0;right:auto;bottom:auto;display:block;box-sizing:content-box;min-width:0;min-height:0;max-width:none;max-height:none;margin:0;padding:0;border:0;border-radius:0;box-shadow:none;outline:0;opacity:1;visibility:visible;filter:none;transition:none;animation:none;transform:none;translate:none;rotate:none;scale:none;pointer-events:none";
1140
- copy.style.cssText = `${reset};width:${size.width}px;height:${size.height}px;object-fit:fill;transform-origin:center`;
1180
+ const photo = doc.createElement("img");
1181
+ photo.alt = "";
1182
+ photo.draggable = false;
1183
+ photo.src = src;
1184
+ photo.style.cssText = `${reset};position:relative;width:100%;height:100%;object-fit:contain`;
1185
+ // A photo's copy carries what renderContent drew, so the picture lands whole.
1186
+ let copy = photo;
1187
+ if (!entry.media) {
1188
+ copy = entry.frame.cloneNode(true);
1189
+ copy.querySelector(".re-lightbox-image")?.replaceWith(photo);
1190
+ for (const part of copy.querySelectorAll(".re-lightbox-loading, .re-lightbox-error"))
1191
+ part.remove();
1192
+ }
1193
+ copy.classList.add("re-lightbox-landing");
1194
+ copy.setAttribute("aria-hidden", "true");
1195
+ copy.style.cssText = `${reset};box-sizing:border-box;padding:${entry.frame.style.padding || 0};width:${size.width}px;height:${size.height}px;object-fit:fill;transform-origin:center`;
1141
1196
  // The box covers the tile and clips the copy, so the full-size copy adds no scrollable
1142
1197
  // overflow to a strip whose tiles have no position of their own.
1143
1198
  const holder = doc.createElement("span");
1144
1199
  holder.setAttribute("aria-hidden", "true");
1200
+ holder.inert = true;
1145
1201
  holder.style.cssText = `${reset};width:${rect.width}px;height:${rect.height}px;overflow:hidden;overflow:clip`;
1146
1202
  holder.append(copy);
1147
1203
  // A carousel of bare children would count a copy beside its slide as one more slide.
@@ -1222,18 +1278,28 @@ export function createLightbox(options = {}) {
1222
1278
  const positions = style.objectPosition
1223
1279
  .split(" ")
1224
1280
  .map((value) => Number.parseFloat(value) / 100);
1225
- const crop = style.objectFit === "contain"
1226
- ? contain(imageSize(state.index, s), rect, 0)
1227
- : cover(imageSize(state.index, s), rect, {
1281
+ // An image tile shows the photo alone, any other tile the whole picture.
1282
+ const margins = origin.localName === "img" && marginsOf(state.index);
1283
+ const shown = (margins ? photoSize : imageSize)(state.index, s);
1284
+ const placed = style.objectFit === "contain"
1285
+ ? contain(shown, rect, 0)
1286
+ : cover(shown, rect, {
1228
1287
  x: Number.isFinite(positions[0]) ? positions[0] : 0.5,
1229
1288
  y: Number.isFinite(positions[1]) ? positions[1] : 0.5,
1230
1289
  });
1231
- const left = "left" in crop && typeof crop.left === "number"
1232
- ? crop.left
1233
- : (rect.width - crop.width) / 2;
1234
- const top = "top" in crop && typeof crop.top === "number"
1235
- ? crop.top
1236
- : (rect.height - crop.height) / 2;
1290
+ let left = "left" in placed && typeof placed.left === "number"
1291
+ ? placed.left
1292
+ : (rect.width - placed.width) / 2;
1293
+ let top = "top" in placed && typeof placed.top === "number"
1294
+ ? placed.top
1295
+ : (rect.height - placed.height) / 2;
1296
+ const crop = { ...placed };
1297
+ if (margins) {
1298
+ left -= margins.left * placed.width;
1299
+ top -= margins.top * placed.width;
1300
+ crop.width = placed.width / photoShare(state.index);
1301
+ crop.height += placed.width * (margins.top + margins.bottom);
1302
+ }
1237
1303
  const scale = crop.width / size.width;
1238
1304
  const room = {
1239
1305
  left: box.left + s.inset.left,
@@ -1259,7 +1325,7 @@ export function createLightbox(options = {}) {
1259
1325
  if (!closing)
1260
1326
  return animate(s, entry.frame, [clipped, expanded], duration, ease);
1261
1327
  const made = landing && duration > 0
1262
- ? landingCopy(s, entry.image, origin, rect, size, room)
1328
+ ? landingCopy(s, entry, origin, rect, size, room)
1263
1329
  : undefined;
1264
1330
  if (!made)
1265
1331
  return animate(s, entry.frame, [live, clipped], duration, ease);
@@ -1287,7 +1353,7 @@ export function createLightbox(options = {}) {
1287
1353
  !entry.loader ||
1288
1354
  entry.status === "failed")
1289
1355
  continue;
1290
- const width = fit(index, s).width;
1356
+ const width = fit(index, s).width * photoShare(index);
1291
1357
  const scale = index === state.index ? Math.min(s.sharpScale, state.zoom.scale) : 1;
1292
1358
  const sizes = scale > 1
1293
1359
  ? `${Math.ceil(width * scale)}px`
@@ -1323,12 +1389,21 @@ export function createLightbox(options = {}) {
1323
1389
  const right = x + Math.min(rest.x + size.width / 2, dx + width / 2);
1324
1390
  s.slides[index]?.style.setProperty("--re-lightbox-window", `${top}px ${s.area.width - right}px ${s.area.height - bottom}px ${left}px`);
1325
1391
  }
1392
+ // With margins the frame is the picture, and its padding keeps the photo's place inside it.
1393
+ function placePhoto(s, index, frame) {
1394
+ const margins = marginsOf(index);
1395
+ const width = fit(index, s).width * photoShare(index);
1396
+ frame.style.padding = margins
1397
+ ? `${margins.top * width}px ${margins.right * width}px ${margins.bottom * width}px ${margins.left * width}px`
1398
+ : "";
1399
+ }
1326
1400
  function layout(s) {
1327
1401
  const resting = s.rest !== undefined && sameZoom(state.zoom, s.rest);
1328
1402
  for (const [index, entry] of s.loaded) {
1329
1403
  const size = fit(index, s);
1330
1404
  entry.frame.style.width = `${size.width}px`;
1331
1405
  entry.frame.style.height = `${size.height}px`;
1406
+ placePhoto(s, index, entry.frame);
1332
1407
  if (framed(index, s))
1333
1408
  placeWindow(s, index, size);
1334
1409
  }
@@ -1343,12 +1418,16 @@ export function createLightbox(options = {}) {
1343
1418
  }
1344
1419
  applyZoom(s);
1345
1420
  }
1346
- function resized(s) {
1347
- s.resizeFrame = undefined;
1421
+ // A footer slot that changes height keeps a flight or a page in progress running.
1422
+ function resized(s, footer = false) {
1423
+ if (!footer)
1424
+ s.resizeFrame = undefined;
1348
1425
  if (session !== s)
1349
1426
  return;
1350
- cancelAnimations(s, true);
1351
- clearStands(s);
1427
+ if (!footer) {
1428
+ cancelAnimations(s, true);
1429
+ clearStands(s);
1430
+ }
1352
1431
  const before = state.zoom;
1353
1432
  const from = fit(state.index, s);
1354
1433
  const resting = s.rest !== undefined && sameZoom(before, s.rest);
@@ -1371,11 +1450,12 @@ export function createLightbox(options = {}) {
1371
1450
  });
1372
1451
  }
1373
1452
  layout(s);
1374
- quietly(() => {
1375
- s.carousel.setEnabled(true);
1376
- s.carousel.refresh();
1377
- s.carousel.goTo(state.index, "instant");
1378
- });
1453
+ if (!footer)
1454
+ quietly(() => {
1455
+ s.carousel.setEnabled(true);
1456
+ s.carousel.refresh();
1457
+ s.carousel.goTo(state.index, "instant");
1458
+ });
1379
1459
  applyZoom(s, false);
1380
1460
  ringThumb(s, false);
1381
1461
  if (!sameZoom(before, state.zoom))
@@ -1549,6 +1629,7 @@ export function createLightbox(options = {}) {
1549
1629
  }
1550
1630
  function loadSlides(s) {
1551
1631
  trimSlides(s);
1632
+ const renders = [];
1552
1633
  for (let step = -preload; step <= preload; step++) {
1553
1634
  const index = looping() ? wrap(state.index + step) : state.index + step;
1554
1635
  if (index < 0 || index >= items.length || s.loaded.has(index))
@@ -1648,6 +1729,7 @@ export function createLightbox(options = {}) {
1648
1729
  }
1649
1730
  display(source.currentSrc || source.src);
1650
1731
  frame.removeAttribute("data-loading");
1732
+ const padding = frame.style.padding;
1651
1733
  layout(s);
1652
1734
  const after = before && fit(index, s);
1653
1735
  if (before &&
@@ -1655,8 +1737,16 @@ export function createLightbox(options = {}) {
1655
1737
  (Math.abs(after.width - before.width) > 0.5 ||
1656
1738
  Math.abs(after.height - before.height) > 0.5))
1657
1739
  void animate(s, frame, [
1658
- { width: `${before.width}px`, height: `${before.height}px` },
1659
- { width: `${after.width}px`, height: `${after.height}px` },
1740
+ {
1741
+ width: `${before.width}px`,
1742
+ height: `${before.height}px`,
1743
+ padding,
1744
+ },
1745
+ {
1746
+ width: `${after.width}px`,
1747
+ height: `${after.height}px`,
1748
+ padding: frame.style.padding,
1749
+ },
1660
1750
  ], nudgeDuration(s));
1661
1751
  };
1662
1752
  const failed = () => {
@@ -1786,14 +1876,19 @@ export function createLightbox(options = {}) {
1786
1876
  },
1787
1877
  };
1788
1878
  s.loaded.set(index, entry);
1789
- cleanup = settings.renderContent?.({
1790
- item: item,
1791
- index,
1792
- container: frame,
1793
- image,
1879
+ renders.push(() => {
1880
+ cleanup = settings.renderContent?.({
1881
+ item: item,
1882
+ index,
1883
+ container: frame,
1884
+ image,
1885
+ });
1794
1886
  });
1795
1887
  }
1796
1888
  layout(s);
1889
+ // Content draws into a frame that already has its resting size.
1890
+ for (const render of renders)
1891
+ render();
1797
1892
  startLoads(s);
1798
1893
  }
1799
1894
  let notifyingBeforeChange = false;
@@ -1853,12 +1948,20 @@ export function createLightbox(options = {}) {
1853
1948
  s.status.textContent = s.strings.slide(index, items.length, items[index]?.caption || undefined);
1854
1949
  emit("change", s);
1855
1950
  }
1856
- function showCaption(s, text, direction) {
1951
+ function showCaption(s, item, direction) {
1857
1952
  const caption = s.caption;
1953
+ const text = item.captionContent ?? item.caption ?? "";
1858
1954
  if (text === s.captionText)
1859
1955
  return;
1860
1956
  s.captionText = text;
1861
- const shown = caption.textContent ?? "";
1957
+ const shown = s.captionShown;
1958
+ const put = () => {
1959
+ s.captionShown = text;
1960
+ if (typeof text === "string")
1961
+ caption.textContent = text;
1962
+ else
1963
+ caption.replaceChildren(text());
1964
+ };
1862
1965
  const win = caption.ownerDocument.defaultView;
1863
1966
  const opacity = () => Number(win?.getComputedStyle(caption).opacity ?? 1);
1864
1967
  const running = s.captionFade;
@@ -1875,7 +1978,7 @@ export function createLightbox(options = {}) {
1875
1978
  duration <= 0 ||
1876
1979
  prefersReducedMotion(s) ||
1877
1980
  typeof caption.animate !== "function") {
1878
- caption.textContent = text;
1981
+ put();
1879
1982
  return;
1880
1983
  }
1881
1984
  const rest = opacity();
@@ -1899,7 +2002,7 @@ export function createLightbox(options = {}) {
1899
2002
  if (text === shown)
1900
2003
  return fadeIn(running ? at : rest, side, share);
1901
2004
  if (!shown) {
1902
- caption.textContent = text;
2005
+ put();
1903
2006
  return fadeIn(0, direction);
1904
2007
  }
1905
2008
  const fadeOut = run([{ opacity: running ? at : rest }, { opacity: 0 }], side, -direction, {
@@ -1912,7 +2015,7 @@ export function createLightbox(options = {}) {
1912
2015
  if (current?.fade !== fadeOut)
1913
2016
  return;
1914
2017
  s.captionFade = undefined;
1915
- caption.textContent = text;
2018
+ put();
1916
2019
  if (text)
1917
2020
  fadeIn(0, direction);
1918
2021
  current.fade.cancel();
@@ -1993,7 +2096,7 @@ export function createLightbox(options = {}) {
1993
2096
  hideOrigin(s);
1994
2097
  renderCounter(s, direction);
1995
2098
  const item = items[state.index];
1996
- showCaption(s, item.caption || "", direction);
2099
+ showCaption(s, item, direction);
1997
2100
  const single = items.length < 2;
1998
2101
  for (const control of [s.prev, s.next, ...s.counters, s.slideshowButton])
1999
2102
  if (control)
@@ -2660,7 +2763,7 @@ export function createLightbox(options = {}) {
2660
2763
  const doc = s.dialog.ownerDocument;
2661
2764
  const image = s.loaded.get(state.index)?.image;
2662
2765
  const source = image?.currentSrc || image?.src;
2663
- const size = imageSize(state.index, s);
2766
+ const size = photoSize(state.index, s);
2664
2767
  const draw = async (file) => {
2665
2768
  const canvas = doc.createElement("canvas");
2666
2769
  const context = canvas.getContext("2d");
@@ -3196,7 +3299,8 @@ export function createLightbox(options = {}) {
3196
3299
  // The caption panel shows when some photo has a caption, so the photo keeps one width while paging.
3197
3300
  function placeAside(s, relayout = false) {
3198
3301
  const needed = Boolean(settings.slots?.aside) ||
3199
- (settings.caption === "side" && items.some((item) => item.caption));
3302
+ (settings.caption === "side" &&
3303
+ items.some((item) => item.caption || item.captionContent));
3200
3304
  if (needed === Boolean(s.aside))
3201
3305
  return;
3202
3306
  if (s.aside) {
@@ -3752,6 +3856,8 @@ export function createLightbox(options = {}) {
3752
3856
  slots: [],
3753
3857
  toolbar,
3754
3858
  footer,
3859
+ footerSlots: [],
3860
+ footerRoom: 0,
3755
3861
  thumbStrip,
3756
3862
  thumbRing,
3757
3863
  roving: -1,
@@ -3782,6 +3888,7 @@ export function createLightbox(options = {}) {
3782
3888
  status,
3783
3889
  caption,
3784
3890
  captionText: "",
3891
+ captionShown: "",
3785
3892
  prev,
3786
3893
  next,
3787
3894
  zoomButton,
@@ -3820,10 +3927,27 @@ export function createLightbox(options = {}) {
3820
3927
  chrome: "shown",
3821
3928
  });
3822
3929
  placeAside(s);
3930
+ const host = doc.defaultView;
3931
+ const footerWatch = host && typeof host.ResizeObserver === "function"
3932
+ ? new host.ResizeObserver(() => {
3933
+ if (session === s && footerRoomOf(s) !== s.footerRoom)
3934
+ host.requestAnimationFrame(() => resized(s, true));
3935
+ })
3936
+ : undefined;
3937
+ abort.signal.addEventListener("abort", () => footerWatch?.disconnect());
3823
3938
  mountSlots(s, {
3824
3939
  toolbarStart: (node) => toolbarStart.append(node),
3825
3940
  toolbarEnd: (node) => closeButton ? closeButton.before(node) : toolbarEnd.append(node),
3826
- footer: (node) => footer.append(node),
3941
+ footer: (node) => {
3942
+ const parts = isElement(node)
3943
+ ? [node]
3944
+ : [...(node.children ?? [])];
3945
+ footer.append(node);
3946
+ for (const part of parts) {
3947
+ s.footerSlots.push(part);
3948
+ footerWatch?.observe(part);
3949
+ }
3950
+ },
3827
3951
  aside: (node) => s.aside?.append(node),
3828
3952
  });
3829
3953
  placeThumbs(s);
@@ -4003,6 +4127,9 @@ export function createLightbox(options = {}) {
4003
4127
  s.flying = false;
4004
4128
  swapHeld(s);
4005
4129
  const current = s.loaded.get(state.index);
4130
+ // The tile's crop ends with the flight, so content beside the photo is not cut.
4131
+ if (current)
4132
+ current.frame.style.clipPath = "";
4006
4133
  if (current?.media?.mounted)
4007
4134
  current.media.mounted.resume?.();
4008
4135
  else if (current)
@@ -4429,12 +4556,21 @@ export function lightboxItemFromElement(trigger) {
4429
4556
  const tile = (image && (image.currentSrc || image.src)) || undefined;
4430
4557
  const width = dimension(data("lightboxWidth"));
4431
4558
  const height = dimension(data("lightboxHeight"));
4432
- const caption = trigger
4559
+ const figcaption = trigger
4433
4560
  .closest("figure")
4434
- ?.querySelector(":scope > figcaption")
4435
- ?.textContent?.trim() ||
4561
+ ?.querySelector(":scope > figcaption");
4562
+ const caption = figcaption?.textContent?.trim() ||
4436
4563
  data("lightboxCaption") ||
4437
4564
  link?.dataset.lightboxCaption;
4565
+ // A figcaption with a link or emphasis shows a copy of its own nodes.
4566
+ const captionContent = figcaption?.firstElementChild && figcaption.textContent?.trim()
4567
+ ? () => {
4568
+ const copy = figcaption.cloneNode(true);
4569
+ const nodes = figcaption.ownerDocument.createDocumentFragment();
4570
+ nodes.append(...copy.childNodes);
4571
+ return nodes;
4572
+ }
4573
+ : undefined;
4438
4574
  const alt = image
4439
4575
  ? image.alt
4440
4576
  : trigger.getAttribute("aria-label") || trigger.textContent?.trim();
@@ -4450,6 +4586,7 @@ export function lightboxItemFromElement(trigger) {
4450
4586
  height,
4451
4587
  alt,
4452
4588
  caption: caption || undefined,
4589
+ captionContent,
4453
4590
  origin,
4454
4591
  };
4455
4592
  const src = (href && isImageFile(href, base) ? href : undefined) ||
@@ -4482,6 +4619,7 @@ export function lightboxItemFromElement(trigger) {
4482
4619
  : undefined),
4483
4620
  alt,
4484
4621
  caption: caption || undefined,
4622
+ captionContent,
4485
4623
  origin,
4486
4624
  };
4487
4625
  }
@@ -4567,7 +4705,7 @@ export function bindLightboxGallery(root, lightbox, options = {}) {
4567
4705
  if (!isElement(target) || target.closest(".re-lightbox"))
4568
4706
  return;
4569
4707
  const triggers = [...root.querySelectorAll(selector)].filter((element) => {
4570
- if (element.classList.contains("re-lightbox-landing") ||
4708
+ if (element.closest(".re-lightbox-landing") ||
4571
4709
  element.closest(".re-lightbox"))
4572
4710
  return false;
4573
4711
  const outer = element.parentElement?.closest(selector);
package/dist/theme.css CHANGED
@@ -174,7 +174,11 @@
174
174
  .re-lightbox-prev,
175
175
  .re-lightbox-next {
176
176
  top: calc(
177
- (100% - var(--re-lightbox-bottom-room)) /
177
+ (
178
+ 100% -
179
+ var(--re-lightbox-bottom-room) -
180
+ var(--re-lightbox-footer-room, 0px)
181
+ ) /
178
182
  2 -
179
183
  var(--re-lightbox-button-size) /
180
184
  2
@@ -279,7 +283,7 @@
279
283
  box-shadow: inset 0 0 0 1px var(--re-lightbox-media-ring);
280
284
  }
281
285
  .re-lightbox-frame:is([data-loading], [data-error]) {
282
- background: var(--re-lightbox-placeholder);
286
+ background: var(--re-lightbox-placeholder) content-box;
283
287
  }
284
288
  .re-lightbox-error {
285
289
  padding: var(--re-lightbox-error-padding);
@@ -99,11 +99,12 @@
99
99
  }
100
100
  .re-lightbox-frame {
101
101
  position: relative;
102
+ box-sizing: border-box;
102
103
  flex: none;
103
104
  transform-origin: center;
104
105
  }
105
106
  .re-lightbox-frame[data-transparent]:not([data-loading], [data-error]) {
106
- background: var(--re-lightbox-media-background);
107
+ background: var(--re-lightbox-media-background) content-box;
107
108
  }
108
109
  .re-lightbox[data-zoom="in"]:where([data-zoomable="true"]) .re-lightbox-frame {
109
110
  cursor: zoom-in;
@@ -172,7 +172,11 @@
172
172
  .re-lightbox-prev,
173
173
  .re-lightbox-next {
174
174
  top: calc(
175
- (100% - var(--re-lightbox-bottom-room)) /
175
+ (
176
+ 100% -
177
+ var(--re-lightbox-bottom-room) -
178
+ var(--re-lightbox-footer-room, 0px)
179
+ ) /
176
180
  2 -
177
181
  var(--re-lightbox-button-size) /
178
182
  2
@@ -277,7 +281,7 @@
277
281
  box-shadow: inset 0 0 0 1px var(--re-lightbox-media-ring);
278
282
  }
279
283
  .re-lightbox-frame:is([data-loading], [data-error]) {
280
- background: var(--re-lightbox-placeholder);
284
+ background: var(--re-lightbox-placeholder) content-box;
281
285
  }
282
286
  .re-lightbox-error {
283
287
  padding: var(--re-lightbox-error-padding);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuse-sh/lightbox",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "An image lightbox on native scrolling, with thumbnail transitions, zoom, pan, and pinch.",
5
5
  "keywords": [
6
6
  "reuse",