@reuse-sh/lightbox 0.3.1 → 0.4.1
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 +3 -2
- package/dist/base.css +2 -1
- package/dist/browser/audio.js +1 -1
- package/dist/browser/carousel-link.js +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/index.d.ts +12 -0
- package/dist/index.js +196 -55
- package/dist/theme.css +6 -2
- package/dist/unlayered/base.css +2 -1
- package/dist/unlayered/theme.css +6 -2
- package/package.json +1 -1
package/dist/browser/video.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @reuse-sh/lightbox 0.
|
|
1
|
+
/*! @reuse-sh/lightbox 0.4.1 | 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
|
@@ -140,12 +140,15 @@ function lockScroll(doc) {
|
|
|
140
140
|
y: win.scrollY,
|
|
141
141
|
};
|
|
142
142
|
locks.set(doc, lock);
|
|
143
|
-
const
|
|
143
|
+
const root = doc.documentElement;
|
|
144
|
+
const width = root.offsetWidth;
|
|
145
|
+
doc.body.style.overflow = "hidden";
|
|
146
|
+
// Only the width the hidden scrollbar hands back: a reserved gutter or an overlay scrollbar hands back none.
|
|
147
|
+
const gap = Math.max(0, root.offsetWidth - width);
|
|
144
148
|
if (gap)
|
|
145
149
|
doc.body.style.paddingRight = `${Number.parseFloat(win.getComputedStyle(doc.body).paddingRight || "0") + gap}px`;
|
|
146
150
|
// Fixed elements ignore body padding; they can add this gap themselves.
|
|
147
|
-
|
|
148
|
-
doc.body.style.overflow = "hidden";
|
|
151
|
+
root.style.setProperty("--re-scrollbar-gap", `${gap}px`);
|
|
149
152
|
}
|
|
150
153
|
lock.count++;
|
|
151
154
|
let restored = false;
|
|
@@ -283,6 +286,10 @@ function validateItems(items, content = []) {
|
|
|
283
286
|
(item.height !== undefined &&
|
|
284
287
|
(!Number.isFinite(item.height) || item.height <= 0)))
|
|
285
288
|
throw new TypeError("Image dimensions must be positive finite numbers.");
|
|
289
|
+
const margins = item.type === undefined ? item.margins : undefined;
|
|
290
|
+
if (margins &&
|
|
291
|
+
Object.values(margins).some((value) => value !== undefined && !(Number.isFinite(value) && value >= 0)))
|
|
292
|
+
throw new TypeError("Image margins must be finite and 0 or more.");
|
|
286
293
|
return { ...item };
|
|
287
294
|
});
|
|
288
295
|
}
|
|
@@ -709,6 +716,19 @@ export function createLightbox(options = {}) {
|
|
|
709
716
|
const rect = element.getBoundingClientRect();
|
|
710
717
|
return rect.width > 0 && rect.height > 0 ? rect : undefined;
|
|
711
718
|
}
|
|
719
|
+
function footerRoomOf(s) {
|
|
720
|
+
let room = 0;
|
|
721
|
+
if (!s.footerSlots.length)
|
|
722
|
+
return room;
|
|
723
|
+
const gap = Number.parseFloat(s.dialog.ownerDocument.defaultView?.getComputedStyle(s.footer).rowGap ??
|
|
724
|
+
"");
|
|
725
|
+
for (const node of s.footerSlots) {
|
|
726
|
+
const { height } = node.getBoundingClientRect();
|
|
727
|
+
if (height)
|
|
728
|
+
room += height + (gap || 0);
|
|
729
|
+
}
|
|
730
|
+
return room;
|
|
731
|
+
}
|
|
712
732
|
function measure(s) {
|
|
713
733
|
const rect = s.viewport.getBoundingClientRect();
|
|
714
734
|
const win = s.viewport.ownerDocument.defaultView;
|
|
@@ -727,10 +747,15 @@ export function createLightbox(options = {}) {
|
|
|
727
747
|
inset.left = Math.max(0, strip.right - rect.left);
|
|
728
748
|
else if (strip && layout === "side")
|
|
729
749
|
inset.right = Math.max(0, rect.right - strip.left);
|
|
750
|
+
const footerRoom = footerRoomOf(s);
|
|
751
|
+
if (footerRoom !== s.footerRoom) {
|
|
752
|
+
s.footerRoom = footerRoom;
|
|
753
|
+
s.dialog.style.setProperty("--re-lightbox-footer-room", `${footerRoom}px`);
|
|
754
|
+
}
|
|
730
755
|
const kept = {
|
|
731
756
|
left: 0,
|
|
732
757
|
right: 0,
|
|
733
|
-
bottom: Number.isFinite(room) ? room : 0,
|
|
758
|
+
bottom: (Number.isFinite(room) ? room : 0) + footerRoom,
|
|
734
759
|
};
|
|
735
760
|
const aside = s.aside && rendered(s.aside);
|
|
736
761
|
if (aside) {
|
|
@@ -738,7 +763,7 @@ export function createLightbox(options = {}) {
|
|
|
738
763
|
const before = height * Math.max(0, aside.left - rect.left);
|
|
739
764
|
const after = height * Math.max(0, rect.right - aside.right);
|
|
740
765
|
if (above >= before && above >= after)
|
|
741
|
-
kept.bottom = Math.max(kept.bottom, rect.bottom - aside.top);
|
|
766
|
+
kept.bottom = Math.max(kept.bottom, rect.bottom - aside.top + footerRoom);
|
|
742
767
|
else if (after > before)
|
|
743
768
|
kept.left = Math.max(0, aside.right - rect.left);
|
|
744
769
|
else
|
|
@@ -821,9 +846,31 @@ export function createLightbox(options = {}) {
|
|
|
821
846
|
height: Math.max(height, width / aspect),
|
|
822
847
|
};
|
|
823
848
|
}
|
|
849
|
+
function marginsOf(index) {
|
|
850
|
+
const margins = items[index]?.type === undefined && items[index]?.margins;
|
|
851
|
+
if (!margins)
|
|
852
|
+
return undefined;
|
|
853
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = margins;
|
|
854
|
+
return { top, right, bottom, left };
|
|
855
|
+
}
|
|
856
|
+
// The picture is the photo and its margins, which the viewer fits, zooms, pans and flies as one.
|
|
857
|
+
function imageSize(index, s) {
|
|
858
|
+
const photo = photoSize(index, s);
|
|
859
|
+
const margins = marginsOf(index);
|
|
860
|
+
if (!margins)
|
|
861
|
+
return photo;
|
|
862
|
+
return {
|
|
863
|
+
width: photo.width * (1 + margins.left + margins.right),
|
|
864
|
+
height: photo.height + photo.width * (margins.top + margins.bottom),
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
function photoShare(index) {
|
|
868
|
+
const margins = marginsOf(index);
|
|
869
|
+
return margins ? 1 / (1 + margins.left + margins.right) : 1;
|
|
870
|
+
}
|
|
824
871
|
// Before the file arrives, the shown preview or the tile gives only the proportions, since its
|
|
825
872
|
// pixels are the tile's and not the file's; a player has no pixels to stop at. Both fill the screen.
|
|
826
|
-
function
|
|
873
|
+
function photoSize(index, s) {
|
|
827
874
|
const item = items[index];
|
|
828
875
|
if (item.width && item.height)
|
|
829
876
|
return { width: item.width, height: item.height };
|
|
@@ -900,8 +947,9 @@ export function createLightbox(options = {}) {
|
|
|
900
947
|
const entry = s.loaded.get(index);
|
|
901
948
|
if (entry?.status === "failed" || item?.type !== undefined)
|
|
902
949
|
return { min: 1, max: 1, tap: 1 };
|
|
950
|
+
const fileWidth = largestWidth(item?.srcset) ?? entry?.natural ?? item?.width;
|
|
903
951
|
return zoomLimits({
|
|
904
|
-
fileWidth:
|
|
952
|
+
fileWidth: fileWidth && fileWidth / photoShare(index),
|
|
905
953
|
image: imageSize(index, s),
|
|
906
954
|
viewport: room(index, s),
|
|
907
955
|
zoomed: s.area,
|
|
@@ -1121,8 +1169,9 @@ export function createLightbox(options = {}) {
|
|
|
1121
1169
|
animation.startTime = now;
|
|
1122
1170
|
return flying;
|
|
1123
1171
|
}
|
|
1124
|
-
function landingCopy(s,
|
|
1172
|
+
function landingCopy(s, entry, origin, rect, size, box) {
|
|
1125
1173
|
const doc = s.dialog.ownerDocument;
|
|
1174
|
+
const image = entry.image;
|
|
1126
1175
|
const src = image.currentSrc || image.src;
|
|
1127
1176
|
if (origin.ownerDocument !== doc ||
|
|
1128
1177
|
!origin.parentNode ||
|
|
@@ -1130,18 +1179,28 @@ export function createLightbox(options = {}) {
|
|
|
1130
1179
|
!image.complete ||
|
|
1131
1180
|
!image.naturalWidth)
|
|
1132
1181
|
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
1182
|
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
|
-
|
|
1183
|
+
const photo = doc.createElement("img");
|
|
1184
|
+
photo.alt = "";
|
|
1185
|
+
photo.draggable = false;
|
|
1186
|
+
photo.src = src;
|
|
1187
|
+
photo.style.cssText = `${reset};position:relative;width:100%;height:100%;object-fit:contain`;
|
|
1188
|
+
// A photo's copy carries what renderContent drew, so the picture lands whole.
|
|
1189
|
+
let copy = photo;
|
|
1190
|
+
if (!entry.media) {
|
|
1191
|
+
copy = entry.frame.cloneNode(true);
|
|
1192
|
+
copy.querySelector(".re-lightbox-image")?.replaceWith(photo);
|
|
1193
|
+
for (const part of copy.querySelectorAll(".re-lightbox-loading, .re-lightbox-error"))
|
|
1194
|
+
part.remove();
|
|
1195
|
+
}
|
|
1196
|
+
copy.classList.add("re-lightbox-landing");
|
|
1197
|
+
copy.setAttribute("aria-hidden", "true");
|
|
1198
|
+
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
1199
|
// The box covers the tile and clips the copy, so the full-size copy adds no scrollable
|
|
1142
1200
|
// overflow to a strip whose tiles have no position of their own.
|
|
1143
1201
|
const holder = doc.createElement("span");
|
|
1144
1202
|
holder.setAttribute("aria-hidden", "true");
|
|
1203
|
+
holder.inert = true;
|
|
1145
1204
|
holder.style.cssText = `${reset};width:${rect.width}px;height:${rect.height}px;overflow:hidden;overflow:clip`;
|
|
1146
1205
|
holder.append(copy);
|
|
1147
1206
|
// A carousel of bare children would count a copy beside its slide as one more slide.
|
|
@@ -1222,18 +1281,28 @@ export function createLightbox(options = {}) {
|
|
|
1222
1281
|
const positions = style.objectPosition
|
|
1223
1282
|
.split(" ")
|
|
1224
1283
|
.map((value) => Number.parseFloat(value) / 100);
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1284
|
+
// An image tile shows the photo alone, any other tile the whole picture.
|
|
1285
|
+
const margins = origin.localName === "img" && marginsOf(state.index);
|
|
1286
|
+
const shown = (margins ? photoSize : imageSize)(state.index, s);
|
|
1287
|
+
const placed = style.objectFit === "contain"
|
|
1288
|
+
? contain(shown, rect, 0)
|
|
1289
|
+
: cover(shown, rect, {
|
|
1228
1290
|
x: Number.isFinite(positions[0]) ? positions[0] : 0.5,
|
|
1229
1291
|
y: Number.isFinite(positions[1]) ? positions[1] : 0.5,
|
|
1230
1292
|
});
|
|
1231
|
-
|
|
1232
|
-
?
|
|
1233
|
-
: (rect.width -
|
|
1234
|
-
|
|
1235
|
-
?
|
|
1236
|
-
: (rect.height -
|
|
1293
|
+
let left = "left" in placed && typeof placed.left === "number"
|
|
1294
|
+
? placed.left
|
|
1295
|
+
: (rect.width - placed.width) / 2;
|
|
1296
|
+
let top = "top" in placed && typeof placed.top === "number"
|
|
1297
|
+
? placed.top
|
|
1298
|
+
: (rect.height - placed.height) / 2;
|
|
1299
|
+
const crop = { ...placed };
|
|
1300
|
+
if (margins) {
|
|
1301
|
+
left -= margins.left * placed.width;
|
|
1302
|
+
top -= margins.top * placed.width;
|
|
1303
|
+
crop.width = placed.width / photoShare(state.index);
|
|
1304
|
+
crop.height += placed.width * (margins.top + margins.bottom);
|
|
1305
|
+
}
|
|
1237
1306
|
const scale = crop.width / size.width;
|
|
1238
1307
|
const room = {
|
|
1239
1308
|
left: box.left + s.inset.left,
|
|
@@ -1259,7 +1328,7 @@ export function createLightbox(options = {}) {
|
|
|
1259
1328
|
if (!closing)
|
|
1260
1329
|
return animate(s, entry.frame, [clipped, expanded], duration, ease);
|
|
1261
1330
|
const made = landing && duration > 0
|
|
1262
|
-
? landingCopy(s, entry
|
|
1331
|
+
? landingCopy(s, entry, origin, rect, size, room)
|
|
1263
1332
|
: undefined;
|
|
1264
1333
|
if (!made)
|
|
1265
1334
|
return animate(s, entry.frame, [live, clipped], duration, ease);
|
|
@@ -1287,7 +1356,7 @@ export function createLightbox(options = {}) {
|
|
|
1287
1356
|
!entry.loader ||
|
|
1288
1357
|
entry.status === "failed")
|
|
1289
1358
|
continue;
|
|
1290
|
-
const width = fit(index, s).width;
|
|
1359
|
+
const width = fit(index, s).width * photoShare(index);
|
|
1291
1360
|
const scale = index === state.index ? Math.min(s.sharpScale, state.zoom.scale) : 1;
|
|
1292
1361
|
const sizes = scale > 1
|
|
1293
1362
|
? `${Math.ceil(width * scale)}px`
|
|
@@ -1323,12 +1392,21 @@ export function createLightbox(options = {}) {
|
|
|
1323
1392
|
const right = x + Math.min(rest.x + size.width / 2, dx + width / 2);
|
|
1324
1393
|
s.slides[index]?.style.setProperty("--re-lightbox-window", `${top}px ${s.area.width - right}px ${s.area.height - bottom}px ${left}px`);
|
|
1325
1394
|
}
|
|
1395
|
+
// With margins the frame is the picture, and its padding keeps the photo's place inside it.
|
|
1396
|
+
function placePhoto(s, index, frame) {
|
|
1397
|
+
const margins = marginsOf(index);
|
|
1398
|
+
const width = fit(index, s).width * photoShare(index);
|
|
1399
|
+
frame.style.padding = margins
|
|
1400
|
+
? `${margins.top * width}px ${margins.right * width}px ${margins.bottom * width}px ${margins.left * width}px`
|
|
1401
|
+
: "";
|
|
1402
|
+
}
|
|
1326
1403
|
function layout(s) {
|
|
1327
1404
|
const resting = s.rest !== undefined && sameZoom(state.zoom, s.rest);
|
|
1328
1405
|
for (const [index, entry] of s.loaded) {
|
|
1329
1406
|
const size = fit(index, s);
|
|
1330
1407
|
entry.frame.style.width = `${size.width}px`;
|
|
1331
1408
|
entry.frame.style.height = `${size.height}px`;
|
|
1409
|
+
placePhoto(s, index, entry.frame);
|
|
1332
1410
|
if (framed(index, s))
|
|
1333
1411
|
placeWindow(s, index, size);
|
|
1334
1412
|
}
|
|
@@ -1343,12 +1421,16 @@ export function createLightbox(options = {}) {
|
|
|
1343
1421
|
}
|
|
1344
1422
|
applyZoom(s);
|
|
1345
1423
|
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1424
|
+
// A footer slot that changes height keeps a flight or a page in progress running.
|
|
1425
|
+
function resized(s, footer = false) {
|
|
1426
|
+
if (!footer)
|
|
1427
|
+
s.resizeFrame = undefined;
|
|
1348
1428
|
if (session !== s)
|
|
1349
1429
|
return;
|
|
1350
|
-
|
|
1351
|
-
|
|
1430
|
+
if (!footer) {
|
|
1431
|
+
cancelAnimations(s, true);
|
|
1432
|
+
clearStands(s);
|
|
1433
|
+
}
|
|
1352
1434
|
const before = state.zoom;
|
|
1353
1435
|
const from = fit(state.index, s);
|
|
1354
1436
|
const resting = s.rest !== undefined && sameZoom(before, s.rest);
|
|
@@ -1371,11 +1453,12 @@ export function createLightbox(options = {}) {
|
|
|
1371
1453
|
});
|
|
1372
1454
|
}
|
|
1373
1455
|
layout(s);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1456
|
+
if (!footer)
|
|
1457
|
+
quietly(() => {
|
|
1458
|
+
s.carousel.setEnabled(true);
|
|
1459
|
+
s.carousel.refresh();
|
|
1460
|
+
s.carousel.goTo(state.index, "instant");
|
|
1461
|
+
});
|
|
1379
1462
|
applyZoom(s, false);
|
|
1380
1463
|
ringThumb(s, false);
|
|
1381
1464
|
if (!sameZoom(before, state.zoom))
|
|
@@ -1549,6 +1632,7 @@ export function createLightbox(options = {}) {
|
|
|
1549
1632
|
}
|
|
1550
1633
|
function loadSlides(s) {
|
|
1551
1634
|
trimSlides(s);
|
|
1635
|
+
const renders = [];
|
|
1552
1636
|
for (let step = -preload; step <= preload; step++) {
|
|
1553
1637
|
const index = looping() ? wrap(state.index + step) : state.index + step;
|
|
1554
1638
|
if (index < 0 || index >= items.length || s.loaded.has(index))
|
|
@@ -1648,6 +1732,7 @@ export function createLightbox(options = {}) {
|
|
|
1648
1732
|
}
|
|
1649
1733
|
display(source.currentSrc || source.src);
|
|
1650
1734
|
frame.removeAttribute("data-loading");
|
|
1735
|
+
const padding = frame.style.padding;
|
|
1651
1736
|
layout(s);
|
|
1652
1737
|
const after = before && fit(index, s);
|
|
1653
1738
|
if (before &&
|
|
@@ -1655,8 +1740,16 @@ export function createLightbox(options = {}) {
|
|
|
1655
1740
|
(Math.abs(after.width - before.width) > 0.5 ||
|
|
1656
1741
|
Math.abs(after.height - before.height) > 0.5))
|
|
1657
1742
|
void animate(s, frame, [
|
|
1658
|
-
{
|
|
1659
|
-
|
|
1743
|
+
{
|
|
1744
|
+
width: `${before.width}px`,
|
|
1745
|
+
height: `${before.height}px`,
|
|
1746
|
+
padding,
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
width: `${after.width}px`,
|
|
1750
|
+
height: `${after.height}px`,
|
|
1751
|
+
padding: frame.style.padding,
|
|
1752
|
+
},
|
|
1660
1753
|
], nudgeDuration(s));
|
|
1661
1754
|
};
|
|
1662
1755
|
const failed = () => {
|
|
@@ -1786,14 +1879,19 @@ export function createLightbox(options = {}) {
|
|
|
1786
1879
|
},
|
|
1787
1880
|
};
|
|
1788
1881
|
s.loaded.set(index, entry);
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1882
|
+
renders.push(() => {
|
|
1883
|
+
cleanup = settings.renderContent?.({
|
|
1884
|
+
item: item,
|
|
1885
|
+
index,
|
|
1886
|
+
container: frame,
|
|
1887
|
+
image,
|
|
1888
|
+
});
|
|
1794
1889
|
});
|
|
1795
1890
|
}
|
|
1796
1891
|
layout(s);
|
|
1892
|
+
// Content draws into a frame that already has its resting size.
|
|
1893
|
+
for (const render of renders)
|
|
1894
|
+
render();
|
|
1797
1895
|
startLoads(s);
|
|
1798
1896
|
}
|
|
1799
1897
|
let notifyingBeforeChange = false;
|
|
@@ -1853,12 +1951,20 @@ export function createLightbox(options = {}) {
|
|
|
1853
1951
|
s.status.textContent = s.strings.slide(index, items.length, items[index]?.caption || undefined);
|
|
1854
1952
|
emit("change", s);
|
|
1855
1953
|
}
|
|
1856
|
-
function showCaption(s,
|
|
1954
|
+
function showCaption(s, item, direction) {
|
|
1857
1955
|
const caption = s.caption;
|
|
1956
|
+
const text = item.captionContent ?? item.caption ?? "";
|
|
1858
1957
|
if (text === s.captionText)
|
|
1859
1958
|
return;
|
|
1860
1959
|
s.captionText = text;
|
|
1861
|
-
const shown =
|
|
1960
|
+
const shown = s.captionShown;
|
|
1961
|
+
const put = () => {
|
|
1962
|
+
s.captionShown = text;
|
|
1963
|
+
if (typeof text === "string")
|
|
1964
|
+
caption.textContent = text;
|
|
1965
|
+
else
|
|
1966
|
+
caption.replaceChildren(text());
|
|
1967
|
+
};
|
|
1862
1968
|
const win = caption.ownerDocument.defaultView;
|
|
1863
1969
|
const opacity = () => Number(win?.getComputedStyle(caption).opacity ?? 1);
|
|
1864
1970
|
const running = s.captionFade;
|
|
@@ -1875,7 +1981,7 @@ export function createLightbox(options = {}) {
|
|
|
1875
1981
|
duration <= 0 ||
|
|
1876
1982
|
prefersReducedMotion(s) ||
|
|
1877
1983
|
typeof caption.animate !== "function") {
|
|
1878
|
-
|
|
1984
|
+
put();
|
|
1879
1985
|
return;
|
|
1880
1986
|
}
|
|
1881
1987
|
const rest = opacity();
|
|
@@ -1899,7 +2005,7 @@ export function createLightbox(options = {}) {
|
|
|
1899
2005
|
if (text === shown)
|
|
1900
2006
|
return fadeIn(running ? at : rest, side, share);
|
|
1901
2007
|
if (!shown) {
|
|
1902
|
-
|
|
2008
|
+
put();
|
|
1903
2009
|
return fadeIn(0, direction);
|
|
1904
2010
|
}
|
|
1905
2011
|
const fadeOut = run([{ opacity: running ? at : rest }, { opacity: 0 }], side, -direction, {
|
|
@@ -1912,7 +2018,7 @@ export function createLightbox(options = {}) {
|
|
|
1912
2018
|
if (current?.fade !== fadeOut)
|
|
1913
2019
|
return;
|
|
1914
2020
|
s.captionFade = undefined;
|
|
1915
|
-
|
|
2021
|
+
put();
|
|
1916
2022
|
if (text)
|
|
1917
2023
|
fadeIn(0, direction);
|
|
1918
2024
|
current.fade.cancel();
|
|
@@ -1993,7 +2099,7 @@ export function createLightbox(options = {}) {
|
|
|
1993
2099
|
hideOrigin(s);
|
|
1994
2100
|
renderCounter(s, direction);
|
|
1995
2101
|
const item = items[state.index];
|
|
1996
|
-
showCaption(s, item
|
|
2102
|
+
showCaption(s, item, direction);
|
|
1997
2103
|
const single = items.length < 2;
|
|
1998
2104
|
for (const control of [s.prev, s.next, ...s.counters, s.slideshowButton])
|
|
1999
2105
|
if (control)
|
|
@@ -2660,7 +2766,7 @@ export function createLightbox(options = {}) {
|
|
|
2660
2766
|
const doc = s.dialog.ownerDocument;
|
|
2661
2767
|
const image = s.loaded.get(state.index)?.image;
|
|
2662
2768
|
const source = image?.currentSrc || image?.src;
|
|
2663
|
-
const size =
|
|
2769
|
+
const size = photoSize(state.index, s);
|
|
2664
2770
|
const draw = async (file) => {
|
|
2665
2771
|
const canvas = doc.createElement("canvas");
|
|
2666
2772
|
const context = canvas.getContext("2d");
|
|
@@ -3196,7 +3302,8 @@ export function createLightbox(options = {}) {
|
|
|
3196
3302
|
// The caption panel shows when some photo has a caption, so the photo keeps one width while paging.
|
|
3197
3303
|
function placeAside(s, relayout = false) {
|
|
3198
3304
|
const needed = Boolean(settings.slots?.aside) ||
|
|
3199
|
-
(settings.caption === "side" &&
|
|
3305
|
+
(settings.caption === "side" &&
|
|
3306
|
+
items.some((item) => item.caption || item.captionContent));
|
|
3200
3307
|
if (needed === Boolean(s.aside))
|
|
3201
3308
|
return;
|
|
3202
3309
|
if (s.aside) {
|
|
@@ -3752,6 +3859,8 @@ export function createLightbox(options = {}) {
|
|
|
3752
3859
|
slots: [],
|
|
3753
3860
|
toolbar,
|
|
3754
3861
|
footer,
|
|
3862
|
+
footerSlots: [],
|
|
3863
|
+
footerRoom: 0,
|
|
3755
3864
|
thumbStrip,
|
|
3756
3865
|
thumbRing,
|
|
3757
3866
|
roving: -1,
|
|
@@ -3782,6 +3891,7 @@ export function createLightbox(options = {}) {
|
|
|
3782
3891
|
status,
|
|
3783
3892
|
caption,
|
|
3784
3893
|
captionText: "",
|
|
3894
|
+
captionShown: "",
|
|
3785
3895
|
prev,
|
|
3786
3896
|
next,
|
|
3787
3897
|
zoomButton,
|
|
@@ -3820,10 +3930,27 @@ export function createLightbox(options = {}) {
|
|
|
3820
3930
|
chrome: "shown",
|
|
3821
3931
|
});
|
|
3822
3932
|
placeAside(s);
|
|
3933
|
+
const host = doc.defaultView;
|
|
3934
|
+
const footerWatch = host && typeof host.ResizeObserver === "function"
|
|
3935
|
+
? new host.ResizeObserver(() => {
|
|
3936
|
+
if (session === s && footerRoomOf(s) !== s.footerRoom)
|
|
3937
|
+
host.requestAnimationFrame(() => resized(s, true));
|
|
3938
|
+
})
|
|
3939
|
+
: undefined;
|
|
3940
|
+
abort.signal.addEventListener("abort", () => footerWatch?.disconnect());
|
|
3823
3941
|
mountSlots(s, {
|
|
3824
3942
|
toolbarStart: (node) => toolbarStart.append(node),
|
|
3825
3943
|
toolbarEnd: (node) => closeButton ? closeButton.before(node) : toolbarEnd.append(node),
|
|
3826
|
-
footer: (node) =>
|
|
3944
|
+
footer: (node) => {
|
|
3945
|
+
const parts = isElement(node)
|
|
3946
|
+
? [node]
|
|
3947
|
+
: [...(node.children ?? [])];
|
|
3948
|
+
footer.append(node);
|
|
3949
|
+
for (const part of parts) {
|
|
3950
|
+
s.footerSlots.push(part);
|
|
3951
|
+
footerWatch?.observe(part);
|
|
3952
|
+
}
|
|
3953
|
+
},
|
|
3827
3954
|
aside: (node) => s.aside?.append(node),
|
|
3828
3955
|
});
|
|
3829
3956
|
placeThumbs(s);
|
|
@@ -4003,6 +4130,9 @@ export function createLightbox(options = {}) {
|
|
|
4003
4130
|
s.flying = false;
|
|
4004
4131
|
swapHeld(s);
|
|
4005
4132
|
const current = s.loaded.get(state.index);
|
|
4133
|
+
// The tile's crop ends with the flight, so content beside the photo is not cut.
|
|
4134
|
+
if (current)
|
|
4135
|
+
current.frame.style.clipPath = "";
|
|
4006
4136
|
if (current?.media?.mounted)
|
|
4007
4137
|
current.media.mounted.resume?.();
|
|
4008
4138
|
else if (current)
|
|
@@ -4429,12 +4559,21 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4429
4559
|
const tile = (image && (image.currentSrc || image.src)) || undefined;
|
|
4430
4560
|
const width = dimension(data("lightboxWidth"));
|
|
4431
4561
|
const height = dimension(data("lightboxHeight"));
|
|
4432
|
-
const
|
|
4562
|
+
const figcaption = trigger
|
|
4433
4563
|
.closest("figure")
|
|
4434
|
-
?.querySelector(":scope > figcaption")
|
|
4435
|
-
|
|
4564
|
+
?.querySelector(":scope > figcaption");
|
|
4565
|
+
const caption = figcaption?.textContent?.trim() ||
|
|
4436
4566
|
data("lightboxCaption") ||
|
|
4437
4567
|
link?.dataset.lightboxCaption;
|
|
4568
|
+
// A figcaption with a link or emphasis shows a copy of its own nodes.
|
|
4569
|
+
const captionContent = figcaption?.firstElementChild && figcaption.textContent?.trim()
|
|
4570
|
+
? () => {
|
|
4571
|
+
const copy = figcaption.cloneNode(true);
|
|
4572
|
+
const nodes = figcaption.ownerDocument.createDocumentFragment();
|
|
4573
|
+
nodes.append(...copy.childNodes);
|
|
4574
|
+
return nodes;
|
|
4575
|
+
}
|
|
4576
|
+
: undefined;
|
|
4438
4577
|
const alt = image
|
|
4439
4578
|
? image.alt
|
|
4440
4579
|
: trigger.getAttribute("aria-label") || trigger.textContent?.trim();
|
|
@@ -4450,6 +4589,7 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4450
4589
|
height,
|
|
4451
4590
|
alt,
|
|
4452
4591
|
caption: caption || undefined,
|
|
4592
|
+
captionContent,
|
|
4453
4593
|
origin,
|
|
4454
4594
|
};
|
|
4455
4595
|
const src = (href && isImageFile(href, base) ? href : undefined) ||
|
|
@@ -4482,6 +4622,7 @@ export function lightboxItemFromElement(trigger) {
|
|
|
4482
4622
|
: undefined),
|
|
4483
4623
|
alt,
|
|
4484
4624
|
caption: caption || undefined,
|
|
4625
|
+
captionContent,
|
|
4485
4626
|
origin,
|
|
4486
4627
|
};
|
|
4487
4628
|
}
|
|
@@ -4567,7 +4708,7 @@ export function bindLightboxGallery(root, lightbox, options = {}) {
|
|
|
4567
4708
|
if (!isElement(target) || target.closest(".re-lightbox"))
|
|
4568
4709
|
return;
|
|
4569
4710
|
const triggers = [...root.querySelectorAll(selector)].filter((element) => {
|
|
4570
|
-
if (element.
|
|
4711
|
+
if (element.closest(".re-lightbox-landing") ||
|
|
4571
4712
|
element.closest(".re-lightbox"))
|
|
4572
4713
|
return false;
|
|
4573
4714
|
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);
|
package/dist/unlayered/base.css
CHANGED
|
@@ -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;
|
package/dist/unlayered/theme.css
CHANGED
|
@@ -172,7 +172,11 @@
|
|
|
172
172
|
.re-lightbox-prev,
|
|
173
173
|
.re-lightbox-next {
|
|
174
174
|
top: calc(
|
|
175
|
-
(
|
|
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);
|