@reuse-sh/lightbox 0.3.0 → 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.
- package/README.md +4 -3
- package/dist/base.css +2 -1
- package/dist/browser/audio.js +1 -1
- package/dist/browser/carousel-link.js +2 -2
- package/dist/browser/carousel-link.js.map +1 -1
- package/dist/browser/embed.js +1 -1
- package/dist/browser/html.js +1 -1
- package/dist/browser/iframe.js +1 -1
- package/dist/browser/lightbox.js +2 -2
- package/dist/browser/lightbox.js.map +1 -1
- package/dist/browser/video.js +1 -1
- package/dist/carousel.js +9 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +242 -83
- package/dist/theme.css +6 -2
- package/dist/unlayered/base.css +2 -1
- package/dist/unlayered/theme.css +6 -2
- package/package.json +3 -3
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
|
|
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:
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
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
|
-
|
|
1232
|
-
?
|
|
1233
|
-
: (rect.width -
|
|
1234
|
-
|
|
1235
|
-
?
|
|
1236
|
-
: (rect.height -
|
|
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
|
|
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
|
-
|
|
1347
|
-
|
|
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
|
-
|
|
1351
|
-
|
|
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
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
-
{
|
|
1659
|
-
|
|
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
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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)
|
|
@@ -2099,27 +2202,29 @@ export function createLightbox(options = {}) {
|
|
|
2099
2202
|
const thumb = s.thumbs[state.index];
|
|
2100
2203
|
if (!ring || !strip)
|
|
2101
2204
|
return;
|
|
2102
|
-
|
|
2103
|
-
|
|
2205
|
+
if (!thumb) {
|
|
2206
|
+
ring.hidden = true;
|
|
2104
2207
|
return;
|
|
2208
|
+
}
|
|
2105
2209
|
const instant = !glide || !ring.style.width;
|
|
2106
|
-
if (instant)
|
|
2107
|
-
ring.style.transition = "none";
|
|
2108
2210
|
const left = strip.offsetLeft + strip.clientLeft;
|
|
2109
2211
|
const top = strip.offsetTop + strip.clientTop;
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
ring.
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
ring.style.
|
|
2122
|
-
ring.style.
|
|
2212
|
+
const width = thumb.offsetWidth;
|
|
2213
|
+
const height = thumb.offsetHeight;
|
|
2214
|
+
const side = s.dialog.dataset.thumbnails === "side";
|
|
2215
|
+
const x = left + (side ? thumb.offsetLeft : strip.clientWidth / 2);
|
|
2216
|
+
const y = side ? `${top + strip.clientHeight / 2}px` : "";
|
|
2217
|
+
const bottom = side
|
|
2218
|
+
? ""
|
|
2219
|
+
: `${(ring.parentElement?.clientHeight ?? 0) - top - thumb.offsetTop - height}px`;
|
|
2220
|
+
ring.hidden = false;
|
|
2221
|
+
if (instant)
|
|
2222
|
+
ring.style.transition = "none";
|
|
2223
|
+
ring.style.left = `${x}px`;
|
|
2224
|
+
ring.style.top = y;
|
|
2225
|
+
ring.style.bottom = bottom;
|
|
2226
|
+
ring.style.width = `${width}px`;
|
|
2227
|
+
ring.style.height = `${height}px`;
|
|
2123
2228
|
if (!instant)
|
|
2124
2229
|
return;
|
|
2125
2230
|
void ring.offsetWidth;
|
|
@@ -2279,24 +2384,25 @@ export function createLightbox(options = {}) {
|
|
|
2279
2384
|
target.focus(options);
|
|
2280
2385
|
if (target.ownerDocument.activeElement !== target)
|
|
2281
2386
|
continue;
|
|
2282
|
-
if (quiet
|
|
2387
|
+
if (quiet)
|
|
2283
2388
|
quietFocus(target);
|
|
2284
2389
|
return;
|
|
2285
2390
|
}
|
|
2286
2391
|
}
|
|
2287
|
-
//
|
|
2288
|
-
// the dialog's own focus restore, gets an attribute the theme hides the ring by.
|
|
2392
|
+
// Some browsers ignore focusVisible or show the ring again on a repeated Escape.
|
|
2289
2393
|
function quietFocus(target) {
|
|
2394
|
+
if (target.hasAttribute("data-re-focus-quiet"))
|
|
2395
|
+
return;
|
|
2290
2396
|
const stop = new AbortController();
|
|
2291
2397
|
const clear = () => {
|
|
2292
2398
|
target.removeAttribute("data-re-focus-quiet");
|
|
2293
2399
|
stop.abort();
|
|
2294
2400
|
};
|
|
2295
2401
|
target.setAttribute("data-re-focus-quiet", "");
|
|
2296
|
-
target.
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
});
|
|
2402
|
+
target.addEventListener("keydown", (event) => {
|
|
2403
|
+
if (event.key !== "Escape")
|
|
2404
|
+
clear();
|
|
2405
|
+
}, { capture: true, signal: stop.signal });
|
|
2300
2406
|
target.addEventListener("blur", clear, { signal: stop.signal });
|
|
2301
2407
|
}
|
|
2302
2408
|
function setZoom(scale, focus, notify) {
|
|
@@ -2657,7 +2763,7 @@ export function createLightbox(options = {}) {
|
|
|
2657
2763
|
const doc = s.dialog.ownerDocument;
|
|
2658
2764
|
const image = s.loaded.get(state.index)?.image;
|
|
2659
2765
|
const source = image?.currentSrc || image?.src;
|
|
2660
|
-
const size =
|
|
2766
|
+
const size = photoSize(state.index, s);
|
|
2661
2767
|
const draw = async (file) => {
|
|
2662
2768
|
const canvas = doc.createElement("canvas");
|
|
2663
2769
|
const context = canvas.getContext("2d");
|
|
@@ -3193,7 +3299,8 @@ export function createLightbox(options = {}) {
|
|
|
3193
3299
|
// The caption panel shows when some photo has a caption, so the photo keeps one width while paging.
|
|
3194
3300
|
function placeAside(s, relayout = false) {
|
|
3195
3301
|
const needed = Boolean(settings.slots?.aside) ||
|
|
3196
|
-
(settings.caption === "side" &&
|
|
3302
|
+
(settings.caption === "side" &&
|
|
3303
|
+
items.some((item) => item.caption || item.captionContent));
|
|
3197
3304
|
if (needed === Boolean(s.aside))
|
|
3198
3305
|
return;
|
|
3199
3306
|
if (s.aside) {
|
|
@@ -3723,6 +3830,9 @@ export function createLightbox(options = {}) {
|
|
|
3723
3830
|
const previousFocus = isHTMLElement(doc.activeElement)
|
|
3724
3831
|
? doc.activeElement
|
|
3725
3832
|
: null;
|
|
3833
|
+
const opener = doc.defaultView?.event;
|
|
3834
|
+
const keyboardAtOpen = opener?.type === "keydown" ||
|
|
3835
|
+
(previousFocus && matches(previousFocus, ":focus-visible"));
|
|
3726
3836
|
(settings.container ?? doc.body).append(dialog);
|
|
3727
3837
|
const restoreScroll = lockScroll(doc);
|
|
3728
3838
|
try {
|
|
@@ -3746,6 +3856,8 @@ export function createLightbox(options = {}) {
|
|
|
3746
3856
|
slots: [],
|
|
3747
3857
|
toolbar,
|
|
3748
3858
|
footer,
|
|
3859
|
+
footerSlots: [],
|
|
3860
|
+
footerRoom: 0,
|
|
3749
3861
|
thumbStrip,
|
|
3750
3862
|
thumbRing,
|
|
3751
3863
|
roving: -1,
|
|
@@ -3776,6 +3888,7 @@ export function createLightbox(options = {}) {
|
|
|
3776
3888
|
status,
|
|
3777
3889
|
caption,
|
|
3778
3890
|
captionText: "",
|
|
3891
|
+
captionShown: "",
|
|
3779
3892
|
prev,
|
|
3780
3893
|
next,
|
|
3781
3894
|
zoomButton,
|
|
@@ -3814,10 +3927,27 @@ export function createLightbox(options = {}) {
|
|
|
3814
3927
|
chrome: "shown",
|
|
3815
3928
|
});
|
|
3816
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());
|
|
3817
3938
|
mountSlots(s, {
|
|
3818
3939
|
toolbarStart: (node) => toolbarStart.append(node),
|
|
3819
3940
|
toolbarEnd: (node) => closeButton ? closeButton.before(node) : toolbarEnd.append(node),
|
|
3820
|
-
footer: (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
|
+
},
|
|
3821
3951
|
aside: (node) => s.aside?.append(node),
|
|
3822
3952
|
});
|
|
3823
3953
|
placeThumbs(s);
|
|
@@ -3939,9 +4069,15 @@ export function createLightbox(options = {}) {
|
|
|
3939
4069
|
for (const [type, input] of [
|
|
3940
4070
|
["keydown", "keyboard"],
|
|
3941
4071
|
["pointerdown", "pointer"],
|
|
4072
|
+
["wheel", "pointer"],
|
|
3942
4073
|
])
|
|
3943
|
-
win?.addEventListener(type, () => {
|
|
3944
|
-
|
|
4074
|
+
win?.addEventListener(type, (event) => {
|
|
4075
|
+
if (type === "wheel" && state.isClosing)
|
|
4076
|
+
return;
|
|
4077
|
+
if (input === "keyboard" && event.key === "Escape")
|
|
4078
|
+
s.input ??= keyboardAtOpen ? "keyboard" : "pointer";
|
|
4079
|
+
else
|
|
4080
|
+
s.input = input;
|
|
3945
4081
|
}, { signal: abort.signal, capture: true, passive: true });
|
|
3946
4082
|
dialog.addEventListener("pointermove", (event) => {
|
|
3947
4083
|
if (event.pointerType === "mouse" && event.buttons === 0)
|
|
@@ -3963,15 +4099,20 @@ export function createLightbox(options = {}) {
|
|
|
3963
4099
|
chromeInput(s, { type: "focus" });
|
|
3964
4100
|
}, { signal: abort.signal });
|
|
3965
4101
|
const opening = closeButton ?? viewport;
|
|
3966
|
-
//
|
|
3967
|
-
const opener = win?.event;
|
|
4102
|
+
// Firefox gives keyboard-activated links a click detail of 1 and an empty pointerType.
|
|
3968
4103
|
const pointerOpen = opener !== undefined &&
|
|
3969
4104
|
(/^(pointer|touch|mouse)/.test(opener.type) ||
|
|
3970
|
-
(opener.type === "click" &&
|
|
3971
|
-
|
|
4105
|
+
(opener.type === "click" &&
|
|
4106
|
+
("pointerType" in opener
|
|
4107
|
+
? Boolean(opener.pointerType)
|
|
4108
|
+
: opener.detail > 0)));
|
|
4109
|
+
if (pointerOpen)
|
|
4110
|
+
s.input = "pointer";
|
|
4111
|
+
const quietOpening = pointerOpen || (!opener && !keyboardAtOpen);
|
|
4112
|
+
opening.focus(quietOpening
|
|
3972
4113
|
? { preventScroll: true, focusVisible: false }
|
|
3973
4114
|
: { preventScroll: true });
|
|
3974
|
-
if (
|
|
4115
|
+
if (quietOpening && matches(opening, ":focus-visible"))
|
|
3975
4116
|
quietFocus(opening);
|
|
3976
4117
|
watchControls(s);
|
|
3977
4118
|
readTiming(s);
|
|
@@ -3986,6 +4127,9 @@ export function createLightbox(options = {}) {
|
|
|
3986
4127
|
s.flying = false;
|
|
3987
4128
|
swapHeld(s);
|
|
3988
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 = "";
|
|
3989
4133
|
if (current?.media?.mounted)
|
|
3990
4134
|
current.media.mounted.resume?.();
|
|
3991
4135
|
else if (current)
|
|
@@ -4032,6 +4176,10 @@ export function createLightbox(options = {}) {
|
|
|
4032
4176
|
dialog.popover = "manual";
|
|
4033
4177
|
dialog.showPopover();
|
|
4034
4178
|
s.releasedFocus = dialog.ownerDocument.activeElement;
|
|
4179
|
+
if (s.input === "pointer" &&
|
|
4180
|
+
s.previousFocus &&
|
|
4181
|
+
s.releasedFocus === s.previousFocus)
|
|
4182
|
+
quietFocus(s.previousFocus);
|
|
4035
4183
|
}
|
|
4036
4184
|
// closed waits for the history back, unless open() or destroy() comes first.
|
|
4037
4185
|
function reportClosed(landing) {
|
|
@@ -4408,12 +4556,21 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4408
4556
|
const tile = (image && (image.currentSrc || image.src)) || undefined;
|
|
4409
4557
|
const width = dimension(data("lightboxWidth"));
|
|
4410
4558
|
const height = dimension(data("lightboxHeight"));
|
|
4411
|
-
const
|
|
4559
|
+
const figcaption = trigger
|
|
4412
4560
|
.closest("figure")
|
|
4413
|
-
?.querySelector(":scope > figcaption")
|
|
4414
|
-
|
|
4561
|
+
?.querySelector(":scope > figcaption");
|
|
4562
|
+
const caption = figcaption?.textContent?.trim() ||
|
|
4415
4563
|
data("lightboxCaption") ||
|
|
4416
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;
|
|
4417
4574
|
const alt = image
|
|
4418
4575
|
? image.alt
|
|
4419
4576
|
: trigger.getAttribute("aria-label") || trigger.textContent?.trim();
|
|
@@ -4429,6 +4586,7 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4429
4586
|
height,
|
|
4430
4587
|
alt,
|
|
4431
4588
|
caption: caption || undefined,
|
|
4589
|
+
captionContent,
|
|
4432
4590
|
origin,
|
|
4433
4591
|
};
|
|
4434
4592
|
const src = (href && isImageFile(href, base) ? href : undefined) ||
|
|
@@ -4461,6 +4619,7 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4461
4619
|
: undefined),
|
|
4462
4620
|
alt,
|
|
4463
4621
|
caption: caption || undefined,
|
|
4622
|
+
captionContent,
|
|
4464
4623
|
origin,
|
|
4465
4624
|
};
|
|
4466
4625
|
}
|
|
@@ -4546,7 +4705,7 @@ export function bindLightboxGallery(root, lightbox, options = {}) {
|
|
|
4546
4705
|
if (!isElement(target) || target.closest(".re-lightbox"))
|
|
4547
4706
|
return;
|
|
4548
4707
|
const triggers = [...root.querySelectorAll(selector)].filter((element) => {
|
|
4549
|
-
if (element.
|
|
4708
|
+
if (element.closest(".re-lightbox-landing") ||
|
|
4550
4709
|
element.closest(".re-lightbox"))
|
|
4551
4710
|
return false;
|
|
4552
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
|
-
(
|
|
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);
|