@reuse-sh/lightbox 0.1.1 → 0.2.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/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 +5 -0
- package/dist/index.js +53 -4
- package/package.json +2 -2
package/dist/browser/video.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @reuse-sh/lightbox 0.
|
|
1
|
+
/*! @reuse-sh/lightbox 0.2.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
|
@@ -48,9 +48,13 @@ export interface LightboxCancelableEvent extends LightboxEvent {
|
|
|
48
48
|
/** Keeps the viewer open. */
|
|
49
49
|
preventDefault(): void;
|
|
50
50
|
}
|
|
51
|
+
export interface LightboxBeforeChangeEvent extends LightboxEvent {
|
|
52
|
+
readonly nextIndex: number;
|
|
53
|
+
}
|
|
51
54
|
export interface LightboxEventMap {
|
|
52
55
|
open: LightboxEvent;
|
|
53
56
|
opened: LightboxEvent;
|
|
57
|
+
beforechange: LightboxBeforeChangeEvent;
|
|
54
58
|
change: LightboxEvent;
|
|
55
59
|
settle: LightboxEvent;
|
|
56
60
|
beforeclose: LightboxCancelableEvent;
|
|
@@ -143,6 +147,7 @@ export interface LightboxOptions<Item extends LightboxItem = LightboxItem> {
|
|
|
143
147
|
preload?: number;
|
|
144
148
|
controls?: Partial<Record<LightboxControl, boolean>>;
|
|
145
149
|
thumbnails?: false | "bottom" | "side";
|
|
150
|
+
thumbnailsVisible?: boolean;
|
|
146
151
|
caption?: "bottom" | "side";
|
|
147
152
|
slideshow?: {
|
|
148
153
|
interval?: number;
|
package/dist/index.js
CHANGED
|
@@ -455,13 +455,18 @@ export function createLightbox(options = {}) {
|
|
|
455
455
|
for (const slot of session?.slots ?? [])
|
|
456
456
|
slot.update?.(state);
|
|
457
457
|
}
|
|
458
|
-
function emit(type, s, cancelable = true) {
|
|
458
|
+
function emit(type, s, { cancelable = true, nextIndex, } = {}) {
|
|
459
459
|
let prevented = false;
|
|
460
460
|
const event = {
|
|
461
461
|
type,
|
|
462
462
|
index: state.index,
|
|
463
463
|
slide: s?.slides[state.index] ?? null,
|
|
464
464
|
};
|
|
465
|
+
if (type === "beforechange")
|
|
466
|
+
Object.defineProperty(event, "nextIndex", {
|
|
467
|
+
value: nextIndex,
|
|
468
|
+
enumerable: true,
|
|
469
|
+
});
|
|
465
470
|
if (type === "beforeclose")
|
|
466
471
|
Object.defineProperties(event, {
|
|
467
472
|
cancelable: { value: cancelable, enumerable: true },
|
|
@@ -1697,9 +1702,29 @@ export function createLightbox(options = {}) {
|
|
|
1697
1702
|
layout(s);
|
|
1698
1703
|
startLoads(s);
|
|
1699
1704
|
}
|
|
1705
|
+
let notifyingBeforeChange = false;
|
|
1706
|
+
function notifyBeforeChange(s, nextIndex) {
|
|
1707
|
+
if (notifyingBeforeChange)
|
|
1708
|
+
return true;
|
|
1709
|
+
const previousIndex = state.index;
|
|
1710
|
+
const previousItems = items;
|
|
1711
|
+
notifyingBeforeChange = true;
|
|
1712
|
+
try {
|
|
1713
|
+
emit("beforechange", s, { nextIndex });
|
|
1714
|
+
}
|
|
1715
|
+
finally {
|
|
1716
|
+
notifyingBeforeChange = false;
|
|
1717
|
+
}
|
|
1718
|
+
return (session === s &&
|
|
1719
|
+
!state.isClosing &&
|
|
1720
|
+
state.index === previousIndex &&
|
|
1721
|
+
items === previousItems);
|
|
1722
|
+
}
|
|
1700
1723
|
function activeChanged(s, index, report = true) {
|
|
1701
1724
|
if (session !== s || state.index === index || state.isClosing)
|
|
1702
1725
|
return;
|
|
1726
|
+
if (!notifyBeforeChange(s, index))
|
|
1727
|
+
return;
|
|
1703
1728
|
cancelAnimations(s);
|
|
1704
1729
|
s.backdrop.style.opacity = "";
|
|
1705
1730
|
const old = s.loaded.get(state.index);
|
|
@@ -3104,14 +3129,27 @@ export function createLightbox(options = {}) {
|
|
|
3104
3129
|
const win = s.dialog.ownerDocument.defaultView;
|
|
3105
3130
|
const side = settings.thumbnails === "side" &&
|
|
3106
3131
|
!win?.matchMedia?.("(max-width: 719.98px)").matches;
|
|
3107
|
-
const layout =
|
|
3132
|
+
const layout = settings.thumbnailsVisible === false
|
|
3133
|
+
? undefined
|
|
3134
|
+
: side
|
|
3135
|
+
? "side"
|
|
3136
|
+
: "bottom";
|
|
3108
3137
|
if (s.dialog.dataset.thumbnails === layout)
|
|
3109
3138
|
return;
|
|
3110
|
-
s.dialog.dataset.thumbnails = layout;
|
|
3111
3139
|
endScrub(s);
|
|
3112
3140
|
s.thumbCarousel?.destroy();
|
|
3113
3141
|
s.thumbCarousel = undefined;
|
|
3114
3142
|
s.chromeRoots = s.chromeRoots.filter((root) => root !== strip);
|
|
3143
|
+
if (!layout) {
|
|
3144
|
+
if (strip.contains(strip.ownerDocument.activeElement)) {
|
|
3145
|
+
s.viewport.focus({ preventScroll: true });
|
|
3146
|
+
}
|
|
3147
|
+
strip.remove();
|
|
3148
|
+
s.thumbRing?.remove();
|
|
3149
|
+
delete s.dialog.dataset.thumbnails;
|
|
3150
|
+
return;
|
|
3151
|
+
}
|
|
3152
|
+
s.dialog.dataset.thumbnails = layout;
|
|
3115
3153
|
if (side) {
|
|
3116
3154
|
s.stage.append(strip);
|
|
3117
3155
|
s.chromeRoots.push(strip);
|
|
@@ -3925,7 +3963,7 @@ export function createLightbox(options = {}) {
|
|
|
3925
3963
|
forcing = force;
|
|
3926
3964
|
let prevented;
|
|
3927
3965
|
try {
|
|
3928
|
-
prevented = emit("beforeclose", s, !force) && !forcing;
|
|
3966
|
+
prevented = emit("beforeclose", s, { cancelable: !force }) && !forcing;
|
|
3929
3967
|
}
|
|
3930
3968
|
finally {
|
|
3931
3969
|
vetting = false;
|
|
@@ -4035,6 +4073,8 @@ export function createLightbox(options = {}) {
|
|
|
4035
4073
|
}
|
|
4036
4074
|
if (target < 0)
|
|
4037
4075
|
target = clamp(state.index, 0, nextItems.length - 1);
|
|
4076
|
+
if ((!kept || target !== state.index) && !notifyBeforeChange(s, target))
|
|
4077
|
+
return;
|
|
4038
4078
|
const slides = nextItems.map((item, j) => {
|
|
4039
4079
|
const old = from[j];
|
|
4040
4080
|
if (old < 0)
|
|
@@ -4140,6 +4180,14 @@ export function createLightbox(options = {}) {
|
|
|
4140
4180
|
if (s)
|
|
4141
4181
|
relabel(s);
|
|
4142
4182
|
}
|
|
4183
|
+
if ("thumbnailsVisible" in next &&
|
|
4184
|
+
settings.thumbnailsVisible !== next.thumbnailsVisible) {
|
|
4185
|
+
settings.thumbnailsVisible = next.thumbnailsVisible;
|
|
4186
|
+
if (s?.thumbStrip && !state.isClosing) {
|
|
4187
|
+
placeThumbs(s);
|
|
4188
|
+
resized(s);
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4143
4191
|
if (!("loop" in next) || Boolean(next.loop) === loop)
|
|
4144
4192
|
return;
|
|
4145
4193
|
loop = Boolean(next.loop);
|
|
@@ -4322,6 +4370,7 @@ const MARKUP_OPTIONS = new Set([
|
|
|
4322
4370
|
"preload",
|
|
4323
4371
|
"controls",
|
|
4324
4372
|
"thumbnails",
|
|
4373
|
+
"thumbnailsVisible",
|
|
4325
4374
|
"caption",
|
|
4326
4375
|
"slideshow",
|
|
4327
4376
|
"autoHide",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reuse-sh/lightbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "An image lightbox on native scrolling, with thumbnail transitions, zoom, pan, and pinch.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"reuse",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@types/react": "19.3.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@reuse-sh/carousel": "0.2.
|
|
82
|
+
"@reuse-sh/carousel": "0.2.1",
|
|
83
83
|
"@reuse-sh/loaders": "0.0.4"
|
|
84
84
|
},
|
|
85
85
|
"publishConfig": {
|