@reuse-sh/lightbox 0.2.2 → 0.3.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/ICONS-LICENSE.md +73 -0
- package/LICENSE +1 -1
- package/README.md +3 -2
- package/dist/base.css +37 -0
- 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/icons.d.ts +42 -12
- package/dist/icons.js +42 -18
- package/dist/index.js +167 -45
- package/dist/theme.css +126 -36
- package/dist/themes/dark.css +3 -0
- package/dist/themes/page.css +11 -0
- package/dist/unlayered/base.css +37 -0
- package/dist/unlayered/theme.css +126 -36
- package/dist/unlayered/themes/dark.css +3 -0
- package/dist/unlayered/themes/page.css +11 -0
- package/package.json +5 -4
package/dist/browser/video.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! @reuse-sh/lightbox 0.
|
|
1
|
+
/*! @reuse-sh/lightbox 0.3.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/carousel.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
const carouselInternals = Symbol.for("@reuse-sh/carousel internals");
|
|
1
2
|
export function connectCarousel(lightbox, carousel, { slideOf = (index) => index } = {}) {
|
|
3
|
+
const strip = carousel[carouselInternals];
|
|
2
4
|
const hold = (isHeld) => carousel.hold("lightbox", isHeld);
|
|
3
|
-
const follow = (
|
|
5
|
+
const follow = ({ index }) => {
|
|
6
|
+
const slide = slideOf(index);
|
|
7
|
+
const visible = strip?.willKeepVisible?.(slide) ??
|
|
8
|
+
carousel.getState().visible.includes(slide);
|
|
9
|
+
if (!visible)
|
|
10
|
+
carousel.goTo(slide, "instant");
|
|
11
|
+
};
|
|
4
12
|
const stops = [
|
|
5
13
|
lightbox.on("open", () => hold(true)),
|
|
6
14
|
lightbox.on("settle", follow),
|
package/dist/icons.d.ts
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
close:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
declare const icons: {
|
|
2
|
+
close: {
|
|
3
|
+
stroke: string;
|
|
4
|
+
paths: string[];
|
|
5
|
+
};
|
|
6
|
+
previous: {
|
|
7
|
+
stroke: string;
|
|
8
|
+
paths: string[];
|
|
9
|
+
};
|
|
10
|
+
next: {
|
|
11
|
+
stroke: string;
|
|
12
|
+
paths: string[];
|
|
13
|
+
};
|
|
14
|
+
zoomIn: {
|
|
15
|
+
stroke: string;
|
|
16
|
+
paths: string[];
|
|
17
|
+
};
|
|
18
|
+
zoomOut: {
|
|
19
|
+
stroke: string;
|
|
20
|
+
paths: string[];
|
|
21
|
+
};
|
|
22
|
+
fullscreenEnter: {
|
|
23
|
+
stroke: string;
|
|
24
|
+
paths: string[];
|
|
25
|
+
};
|
|
26
|
+
fullscreenExit: {
|
|
27
|
+
stroke: string;
|
|
28
|
+
paths: string[];
|
|
29
|
+
};
|
|
30
|
+
download: {
|
|
31
|
+
stroke: string;
|
|
32
|
+
paths: string[];
|
|
33
|
+
};
|
|
34
|
+
play: {
|
|
35
|
+
stroke: string;
|
|
36
|
+
paths: string[];
|
|
37
|
+
};
|
|
38
|
+
pause: {
|
|
39
|
+
stroke: string;
|
|
40
|
+
paths: string[];
|
|
41
|
+
};
|
|
12
42
|
};
|
|
13
|
-
export type BuiltInIcon = keyof typeof
|
|
43
|
+
export type BuiltInIcon = keyof typeof icons;
|
|
14
44
|
export declare function showIcon(button: Element, name: BuiltInIcon): void;
|
|
15
45
|
export {};
|
package/dist/icons.js
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// Icon paths from Hugeicons (MIT) and Lucide (ISC); their notices ship in ICONS-LICENSE.md.
|
|
2
|
+
const lens = "M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0M21 21l-4.35-4.35";
|
|
3
|
+
const icons = {
|
|
4
|
+
close: {
|
|
5
|
+
stroke: "1.5",
|
|
6
|
+
paths: ["M18 6L6.00081 17.9992M17.9992 18L6 6.00085"],
|
|
7
|
+
},
|
|
8
|
+
previous: { stroke: "1.8", paths: ["m15 18-6-6 6-6"] },
|
|
9
|
+
next: { stroke: "1.8", paths: ["m9 18 6-6-6-6"] },
|
|
10
|
+
zoomIn: { stroke: "1.5", paths: [lens, "M11 8v6M8 11h6"] },
|
|
11
|
+
zoomOut: { stroke: "1.5", paths: [lens, "M8 11h6"] },
|
|
12
|
+
fullscreenEnter: {
|
|
13
|
+
stroke: "1.5",
|
|
14
|
+
paths: [
|
|
15
|
+
"M15.5 21C16.8956 21 17.5933 21 18.1611 20.8278C19.4395 20.44 20.44 19.4395 20.8278 18.1611C21 17.5933 21 16.8956 21 15.5M21 8.5C21 7.10444 21 6.40666 20.8278 5.83886C20.44 4.56046 19.4395 3.56004 18.1611 3.17224C17.5933 3 16.8956 3 15.5 3M8.5 21C7.10444 21 6.40666 21 5.83886 20.8278C4.56046 20.44 3.56004 19.4395 3.17224 18.1611C3 17.5933 3 16.8956 3 15.5M3 8.5C3 7.10444 3 6.40666 3.17224 5.83886C3.56004 4.56046 4.56046 3.56004 5.83886 3.17224C6.40666 3 7.10444 3 8.5 3",
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
fullscreenExit: {
|
|
19
|
+
stroke: "1.5",
|
|
20
|
+
paths: [
|
|
21
|
+
"M13 4L13 7.00002C13 8.88563 13.0001 9.82843 13.5858 10.4142C14.1716 11 15.1144 11 17 11L20 11",
|
|
22
|
+
"M11.0001 20L11 17C11 15.1144 11 14.1715 10.4142 13.5858C9.82843 13 8.88563 13 7.00002 13L4.00006 13",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
download: {
|
|
26
|
+
stroke: "1.5",
|
|
27
|
+
paths: [
|
|
28
|
+
"M16.9504 12.1817C17.1981 12.814 16.5076 13.5726 15.1267 15.0899C13.6702 16.6902 12.9201 17.4904 12 17.5C11.0799 17.4904 10.3298 16.6902 8.87331 15.0899C7.49239 13.5726 6.80193 12.814 7.04964 12.1817C7.05868 12.1586 7.06851 12.1359 7.0791 12.1135C7.34928 11.542 8.24477 11.5029 10 11.5002V4.99998C10 4.53501 10 4.30253 10.0511 4.11179C10.1898 3.59414 10.5941 3.1898 11.1118 3.05111C11.3025 3 11.535 3 12 3C12.4649 3 12.6974 3 12.8882 3.05111C13.4058 3.1898 13.8102 3.59414 13.9489 4.11179C14 4.30253 14 4.53501 14 4.99998V11.5002C15.7552 11.5029 16.6507 11.542 16.9209 12.1135C16.9315 12.1359 16.9413 12.1586 16.9504 12.1817Z",
|
|
29
|
+
"M5.00006 21H19.0001",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
play: { stroke: "2", paths: ["M8 5v14l11-7z"] },
|
|
33
|
+
pause: { stroke: "2", paths: ["M9 5v14m6-14v14"] },
|
|
13
34
|
};
|
|
14
35
|
const svgNamespace = "http://www.w3.org/2000/svg";
|
|
15
36
|
export function showIcon(button, name) {
|
|
16
|
-
const
|
|
17
|
-
|
|
37
|
+
const { stroke, paths } = icons[name];
|
|
38
|
+
const shown = [...button.querySelectorAll("path")].map((path) => path.getAttribute("d"));
|
|
39
|
+
if (shown.join(" ") === paths.join(" "))
|
|
18
40
|
return;
|
|
19
41
|
const doc = button.ownerDocument;
|
|
20
42
|
const svg = doc.createElementNS(svgNamespace, "svg");
|
|
@@ -24,7 +46,7 @@ export function showIcon(button, name) {
|
|
|
24
46
|
viewBox: "0 0 24 24",
|
|
25
47
|
fill: "none",
|
|
26
48
|
stroke: "currentColor",
|
|
27
|
-
"stroke-width":
|
|
49
|
+
"stroke-width": stroke,
|
|
28
50
|
"stroke-linecap": "round",
|
|
29
51
|
"stroke-linejoin": "round",
|
|
30
52
|
"aria-hidden": "true",
|
|
@@ -33,8 +55,10 @@ export function showIcon(button, name) {
|
|
|
33
55
|
svg.setAttribute(key, value);
|
|
34
56
|
if (name === "previous" || name === "next")
|
|
35
57
|
svg.setAttribute("class", "re-lightbox-arrow-icon");
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
for (const d of paths) {
|
|
59
|
+
const path = doc.createElementNS(svgNamespace, "path");
|
|
60
|
+
path.setAttribute("d", d);
|
|
61
|
+
svg.append(path);
|
|
62
|
+
}
|
|
39
63
|
button.replaceChildren(svg);
|
|
40
64
|
}
|
package/dist/index.js
CHANGED
|
@@ -762,12 +762,42 @@ export function createLightbox(options = {}) {
|
|
|
762
762
|
x: (inset.right - inset.left) / 2,
|
|
763
763
|
y: inset.bottom / 2,
|
|
764
764
|
};
|
|
765
|
+
const left = rect.left + inset.left;
|
|
766
|
+
const right = rect.right - inset.right;
|
|
767
|
+
const bottom = rect.top + s.box.height;
|
|
768
|
+
let top = 0;
|
|
769
|
+
for (const group of s.toolbar.children) {
|
|
770
|
+
const shown = rendered(group);
|
|
771
|
+
if (shown)
|
|
772
|
+
top = Math.max(top, shown.bottom - rect.top);
|
|
773
|
+
}
|
|
774
|
+
const edge = {
|
|
775
|
+
top: top + padding,
|
|
776
|
+
right: padding,
|
|
777
|
+
bottom: padding,
|
|
778
|
+
left: padding,
|
|
779
|
+
};
|
|
780
|
+
for (const arrow of items.length > 1 ? [s.prev, s.next] : []) {
|
|
781
|
+
const shown = arrow && rendered(arrow);
|
|
782
|
+
if (!shown || shown.bottom <= rect.top + top || shown.top >= bottom)
|
|
783
|
+
continue;
|
|
784
|
+
if (shown.left + shown.right < left + right)
|
|
785
|
+
edge.left = Math.max(edge.left, shown.right - left + padding);
|
|
786
|
+
else
|
|
787
|
+
edge.right = Math.max(edge.right, right - shown.left + padding);
|
|
788
|
+
}
|
|
789
|
+
s.window = {
|
|
790
|
+
width: Math.max(1, s.box.width - edge.left - edge.right),
|
|
791
|
+
height: Math.max(1, s.box.height - edge.top - edge.bottom),
|
|
792
|
+
x: (edge.left - edge.right) / 2,
|
|
793
|
+
y: (edge.top - edge.bottom) / 2,
|
|
794
|
+
};
|
|
765
795
|
}
|
|
766
796
|
function view(s) {
|
|
767
797
|
return s.box;
|
|
768
798
|
}
|
|
769
799
|
function area(s, scale) {
|
|
770
|
-
return scale > 1 ? s.area : s
|
|
800
|
+
return scale > 1 ? s.area : room(state.index, s);
|
|
771
801
|
}
|
|
772
802
|
function bound(s, zoom) {
|
|
773
803
|
return boundZoom(zoom, fit(state.index, s), area(s, zoom.scale));
|
|
@@ -804,22 +834,67 @@ export function createLightbox(options = {}) {
|
|
|
804
834
|
return filling(image.naturalWidth / image.naturalHeight, s);
|
|
805
835
|
return view(s);
|
|
806
836
|
}
|
|
837
|
+
function framed(index, s) {
|
|
838
|
+
if (items[index].type || s.loaded.get(index)?.status === "failed")
|
|
839
|
+
return false;
|
|
840
|
+
const { width, height } = imageSize(index, s);
|
|
841
|
+
return height > 2 * width;
|
|
842
|
+
}
|
|
843
|
+
function room(index, s) {
|
|
844
|
+
return framed(index, s) ? s.window : view(s);
|
|
845
|
+
}
|
|
846
|
+
function spacing(index, s) {
|
|
847
|
+
return framed(index, s) ? 0 : padding;
|
|
848
|
+
}
|
|
807
849
|
function tall(index, s) {
|
|
808
|
-
if (items[index].type)
|
|
850
|
+
if (items[index].type || s.loaded.get(index)?.status === "failed")
|
|
809
851
|
return false;
|
|
810
|
-
return shapeOf(imageSize(index, s),
|
|
852
|
+
return (shapeOf(imageSize(index, s), room(index, s), spacing(index, s)) === "tall");
|
|
811
853
|
}
|
|
812
854
|
function fit(index, s) {
|
|
813
855
|
// A player leaves 24px at each side for a swipe that pages past it.
|
|
814
|
-
return (tall(index, s) ? widthFit : contain)(imageSize(index, s),
|
|
856
|
+
return (tall(index, s) ? widthFit : contain)(imageSize(index, s), room(index, s), items[index].type ? Math.max(padding, 24) : spacing(index, s));
|
|
857
|
+
}
|
|
858
|
+
function resting(s, index) {
|
|
859
|
+
const size = fit(index, s);
|
|
860
|
+
const space = room(index, s);
|
|
861
|
+
return boundZoom({
|
|
862
|
+
scale: 1,
|
|
863
|
+
x: 0,
|
|
864
|
+
y: tall(index, s) ? panRange(1, size, space).y.max : 0,
|
|
865
|
+
}, size, space);
|
|
815
866
|
}
|
|
816
867
|
function restZoom(s, index) {
|
|
817
|
-
const zoom =
|
|
818
|
-
? { scale: 1, x: 0, y: panRange(1, fit(index, s), view(s)).y.max }
|
|
819
|
-
: { ...identity };
|
|
868
|
+
const zoom = resting(s, index);
|
|
820
869
|
s.rest = zoom;
|
|
821
870
|
return zoom;
|
|
822
871
|
}
|
|
872
|
+
function photoRect(s) {
|
|
873
|
+
const box = s.loaded.get(state.index)?.frame.getBoundingClientRect();
|
|
874
|
+
if (!box || state.zoom.scale > 1 || !framed(state.index, s))
|
|
875
|
+
return box;
|
|
876
|
+
const { width, height, x = 0, y = 0 } = s.window;
|
|
877
|
+
const left = s.box.left + s.box.width / 2 + x - width / 2;
|
|
878
|
+
const top = s.box.top + s.box.height / 2 + y - height / 2;
|
|
879
|
+
return {
|
|
880
|
+
left: Math.max(box.left, left),
|
|
881
|
+
top: Math.max(box.top, top),
|
|
882
|
+
right: Math.min(box.right, left + width),
|
|
883
|
+
bottom: Math.min(box.bottom, top + height),
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function markFramed(s, index) {
|
|
887
|
+
const slide = s.slides[index];
|
|
888
|
+
if (!slide)
|
|
889
|
+
return;
|
|
890
|
+
if (!s.loaded.has(index) || !framed(index, s)) {
|
|
891
|
+
slide.removeAttribute("data-framed");
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const value = index === state.index && state.zoom.scale < 1 - 1e-3 ? "out" : "rest";
|
|
895
|
+
if (slide.dataset.framed !== value)
|
|
896
|
+
slide.dataset.framed = value;
|
|
897
|
+
}
|
|
823
898
|
function limits(s, index = state.index) {
|
|
824
899
|
const item = items[index];
|
|
825
900
|
const entry = s.loaded.get(index);
|
|
@@ -828,9 +903,9 @@ export function createLightbox(options = {}) {
|
|
|
828
903
|
return zoomLimits({
|
|
829
904
|
fileWidth: largestWidth(item?.srcset) ?? entry?.natural ?? item?.width,
|
|
830
905
|
image: imageSize(index, s),
|
|
831
|
-
viewport:
|
|
906
|
+
viewport: room(index, s),
|
|
832
907
|
zoomed: s.area,
|
|
833
|
-
padding,
|
|
908
|
+
padding: spacing(index, s),
|
|
834
909
|
svg: Boolean(item?.src &&
|
|
835
910
|
formatOf(item.src, s.dialog.ownerDocument.baseURI) === "svg"),
|
|
836
911
|
maxZoom: settings.maxZoom,
|
|
@@ -868,6 +943,8 @@ export function createLightbox(options = {}) {
|
|
|
868
943
|
showStateIcon(zoomButton, "zoom", "zoomOut", out);
|
|
869
944
|
s.dialog.dataset.zoomed = String(state.zoom.scale > 1);
|
|
870
945
|
s.dialog.dataset.zoom = out ? "out" : "in";
|
|
946
|
+
for (const index of s.loaded.keys())
|
|
947
|
+
markFramed(s, index);
|
|
871
948
|
if (s.watchedScale !== state.zoom.scale) {
|
|
872
949
|
s.watchedScale = state.zoom.scale;
|
|
873
950
|
clearTimeout(s.sharpTimer);
|
|
@@ -1235,12 +1312,25 @@ export function createLightbox(options = {}) {
|
|
|
1235
1312
|
else
|
|
1236
1313
|
win.requestIdleCallback(apply);
|
|
1237
1314
|
}
|
|
1315
|
+
function placeWindow(s, index, size) {
|
|
1316
|
+
const rest = resting(s, index);
|
|
1317
|
+
const x = s.inset.left + s.box.width / 2;
|
|
1318
|
+
const y = s.box.height / 2;
|
|
1319
|
+
const { width, height, x: dx = 0, y: dy = 0 } = s.window;
|
|
1320
|
+
const top = y + Math.max(rest.y - size.height / 2, dy - height / 2);
|
|
1321
|
+
const bottom = y + Math.min(rest.y + size.height / 2, dy + height / 2);
|
|
1322
|
+
const left = x + Math.max(rest.x - size.width / 2, dx - width / 2);
|
|
1323
|
+
const right = x + Math.min(rest.x + size.width / 2, dx + width / 2);
|
|
1324
|
+
s.slides[index]?.style.setProperty("--re-lightbox-window", `${top}px ${s.area.width - right}px ${s.area.height - bottom}px ${left}px`);
|
|
1325
|
+
}
|
|
1238
1326
|
function layout(s) {
|
|
1239
1327
|
const resting = s.rest !== undefined && sameZoom(state.zoom, s.rest);
|
|
1240
1328
|
for (const [index, entry] of s.loaded) {
|
|
1241
1329
|
const size = fit(index, s);
|
|
1242
1330
|
entry.frame.style.width = `${size.width}px`;
|
|
1243
1331
|
entry.frame.style.height = `${size.height}px`;
|
|
1332
|
+
if (framed(index, s))
|
|
1333
|
+
placeWindow(s, index, size);
|
|
1244
1334
|
}
|
|
1245
1335
|
requestSizes(s);
|
|
1246
1336
|
if (resting)
|
|
@@ -1329,6 +1419,7 @@ export function createLightbox(options = {}) {
|
|
|
1329
1419
|
entry.cancel();
|
|
1330
1420
|
entry.frame.remove();
|
|
1331
1421
|
s.loaded.delete(index);
|
|
1422
|
+
markFramed(s, index);
|
|
1332
1423
|
}
|
|
1333
1424
|
}
|
|
1334
1425
|
// The current image loads first; the neighbors wait until it has decoded or failed, and
|
|
@@ -1659,8 +1750,11 @@ export function createLightbox(options = {}) {
|
|
|
1659
1750
|
return;
|
|
1660
1751
|
failed();
|
|
1661
1752
|
settle("failed");
|
|
1662
|
-
if (
|
|
1663
|
-
|
|
1753
|
+
if (state.isClosing)
|
|
1754
|
+
return;
|
|
1755
|
+
layout(s);
|
|
1756
|
+
if (s.flying)
|
|
1757
|
+
entry.commit = () => layout(s);
|
|
1664
1758
|
};
|
|
1665
1759
|
if (item.srcset) {
|
|
1666
1760
|
loader.srcset = item.srcset;
|
|
@@ -2005,27 +2099,29 @@ export function createLightbox(options = {}) {
|
|
|
2005
2099
|
const thumb = s.thumbs[state.index];
|
|
2006
2100
|
if (!ring || !strip)
|
|
2007
2101
|
return;
|
|
2008
|
-
|
|
2009
|
-
|
|
2102
|
+
if (!thumb) {
|
|
2103
|
+
ring.hidden = true;
|
|
2010
2104
|
return;
|
|
2105
|
+
}
|
|
2011
2106
|
const instant = !glide || !ring.style.width;
|
|
2012
|
-
if (instant)
|
|
2013
|
-
ring.style.transition = "none";
|
|
2014
2107
|
const left = strip.offsetLeft + strip.clientLeft;
|
|
2015
2108
|
const top = strip.offsetTop + strip.clientTop;
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
ring.
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
ring.style.
|
|
2028
|
-
ring.style.
|
|
2109
|
+
const width = thumb.offsetWidth;
|
|
2110
|
+
const height = thumb.offsetHeight;
|
|
2111
|
+
const side = s.dialog.dataset.thumbnails === "side";
|
|
2112
|
+
const x = left + (side ? thumb.offsetLeft : strip.clientWidth / 2);
|
|
2113
|
+
const y = side ? `${top + strip.clientHeight / 2}px` : "";
|
|
2114
|
+
const bottom = side
|
|
2115
|
+
? ""
|
|
2116
|
+
: `${(ring.parentElement?.clientHeight ?? 0) - top - thumb.offsetTop - height}px`;
|
|
2117
|
+
ring.hidden = false;
|
|
2118
|
+
if (instant)
|
|
2119
|
+
ring.style.transition = "none";
|
|
2120
|
+
ring.style.left = `${x}px`;
|
|
2121
|
+
ring.style.top = y;
|
|
2122
|
+
ring.style.bottom = bottom;
|
|
2123
|
+
ring.style.width = `${width}px`;
|
|
2124
|
+
ring.style.height = `${height}px`;
|
|
2029
2125
|
if (!instant)
|
|
2030
2126
|
return;
|
|
2031
2127
|
void ring.offsetWidth;
|
|
@@ -2185,24 +2281,25 @@ export function createLightbox(options = {}) {
|
|
|
2185
2281
|
target.focus(options);
|
|
2186
2282
|
if (target.ownerDocument.activeElement !== target)
|
|
2187
2283
|
continue;
|
|
2188
|
-
if (quiet
|
|
2284
|
+
if (quiet)
|
|
2189
2285
|
quietFocus(target);
|
|
2190
2286
|
return;
|
|
2191
2287
|
}
|
|
2192
2288
|
}
|
|
2193
|
-
//
|
|
2194
|
-
// the dialog's own focus restore, gets an attribute the theme hides the ring by.
|
|
2289
|
+
// Some browsers ignore focusVisible or show the ring again on a repeated Escape.
|
|
2195
2290
|
function quietFocus(target) {
|
|
2291
|
+
if (target.hasAttribute("data-re-focus-quiet"))
|
|
2292
|
+
return;
|
|
2196
2293
|
const stop = new AbortController();
|
|
2197
2294
|
const clear = () => {
|
|
2198
2295
|
target.removeAttribute("data-re-focus-quiet");
|
|
2199
2296
|
stop.abort();
|
|
2200
2297
|
};
|
|
2201
2298
|
target.setAttribute("data-re-focus-quiet", "");
|
|
2202
|
-
target.
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
});
|
|
2299
|
+
target.addEventListener("keydown", (event) => {
|
|
2300
|
+
if (event.key !== "Escape")
|
|
2301
|
+
clear();
|
|
2302
|
+
}, { capture: true, signal: stop.signal });
|
|
2206
2303
|
target.addEventListener("blur", clear, { signal: stop.signal });
|
|
2207
2304
|
}
|
|
2208
2305
|
function setZoom(scale, focus, notify) {
|
|
@@ -2745,7 +2842,7 @@ export function createLightbox(options = {}) {
|
|
|
2745
2842
|
!gesture.pinched &&
|
|
2746
2843
|
!gesture.axis &&
|
|
2747
2844
|
Math.hypot(dx, dy) >= 10) {
|
|
2748
|
-
const range = panRange(gesture.zoom.scale, fit(state.index, s),
|
|
2845
|
+
const range = panRange(gesture.zoom.scale, fit(state.index, s), area(s, gesture.zoom.scale)).y;
|
|
2749
2846
|
gesture.axis =
|
|
2750
2847
|
Math.abs(dy) <= Math.abs(dx)
|
|
2751
2848
|
? "x"
|
|
@@ -2826,7 +2923,7 @@ export function createLightbox(options = {}) {
|
|
|
2826
2923
|
const now = Date.now();
|
|
2827
2924
|
s.suppressClickUntil = now + 400;
|
|
2828
2925
|
const current = point(event);
|
|
2829
|
-
const box = s
|
|
2926
|
+
const box = photoRect(s);
|
|
2830
2927
|
const onPhoto = box !== undefined &&
|
|
2831
2928
|
current.x >= box.left &&
|
|
2832
2929
|
current.x <= box.right &&
|
|
@@ -2919,7 +3016,7 @@ export function createLightbox(options = {}) {
|
|
|
2919
3016
|
target.closest("[data-lightbox-interactive],button,a,input,textarea,select"))
|
|
2920
3017
|
return;
|
|
2921
3018
|
// A pan captures the pointer, which retargets its click to the viewport.
|
|
2922
|
-
const box = s
|
|
3019
|
+
const box = photoRect(s);
|
|
2923
3020
|
const onPhoto = target.closest(".re-lightbox-frame") !== null ||
|
|
2924
3021
|
(box !== undefined &&
|
|
2925
3022
|
event.clientX >= box.left &&
|
|
@@ -3629,6 +3726,9 @@ export function createLightbox(options = {}) {
|
|
|
3629
3726
|
const previousFocus = isHTMLElement(doc.activeElement)
|
|
3630
3727
|
? doc.activeElement
|
|
3631
3728
|
: null;
|
|
3729
|
+
const opener = doc.defaultView?.event;
|
|
3730
|
+
const keyboardAtOpen = opener?.type === "keydown" ||
|
|
3731
|
+
(previousFocus && matches(previousFocus, ":focus-visible"));
|
|
3632
3732
|
(settings.container ?? doc.body).append(dialog);
|
|
3633
3733
|
const restoreScroll = lockScroll(doc);
|
|
3634
3734
|
try {
|
|
@@ -3650,6 +3750,7 @@ export function createLightbox(options = {}) {
|
|
|
3650
3750
|
heading: 1,
|
|
3651
3751
|
strings,
|
|
3652
3752
|
slots: [],
|
|
3753
|
+
toolbar,
|
|
3653
3754
|
footer,
|
|
3654
3755
|
thumbStrip,
|
|
3655
3756
|
thumbRing,
|
|
@@ -3694,6 +3795,7 @@ export function createLightbox(options = {}) {
|
|
|
3694
3795
|
paddingProbe,
|
|
3695
3796
|
box: { left: 0, top: 0, width: 1, height: 1 },
|
|
3696
3797
|
area: { width: 1, height: 1 },
|
|
3798
|
+
window: { width: 1, height: 1 },
|
|
3697
3799
|
inset: { left: 0, right: 0, bottom: 0 },
|
|
3698
3800
|
room: { left: 0, right: 0, bottom: 0 },
|
|
3699
3801
|
suppressClickUntil: 0,
|
|
@@ -3843,9 +3945,15 @@ export function createLightbox(options = {}) {
|
|
|
3843
3945
|
for (const [type, input] of [
|
|
3844
3946
|
["keydown", "keyboard"],
|
|
3845
3947
|
["pointerdown", "pointer"],
|
|
3948
|
+
["wheel", "pointer"],
|
|
3846
3949
|
])
|
|
3847
|
-
win?.addEventListener(type, () => {
|
|
3848
|
-
|
|
3950
|
+
win?.addEventListener(type, (event) => {
|
|
3951
|
+
if (type === "wheel" && state.isClosing)
|
|
3952
|
+
return;
|
|
3953
|
+
if (input === "keyboard" && event.key === "Escape")
|
|
3954
|
+
s.input ??= keyboardAtOpen ? "keyboard" : "pointer";
|
|
3955
|
+
else
|
|
3956
|
+
s.input = input;
|
|
3849
3957
|
}, { signal: abort.signal, capture: true, passive: true });
|
|
3850
3958
|
dialog.addEventListener("pointermove", (event) => {
|
|
3851
3959
|
if (event.pointerType === "mouse" && event.buttons === 0)
|
|
@@ -3867,15 +3975,20 @@ export function createLightbox(options = {}) {
|
|
|
3867
3975
|
chromeInput(s, { type: "focus" });
|
|
3868
3976
|
}, { signal: abort.signal });
|
|
3869
3977
|
const opening = closeButton ?? viewport;
|
|
3870
|
-
//
|
|
3871
|
-
const opener = win?.event;
|
|
3978
|
+
// Firefox gives keyboard-activated links a click detail of 1 and an empty pointerType.
|
|
3872
3979
|
const pointerOpen = opener !== undefined &&
|
|
3873
3980
|
(/^(pointer|touch|mouse)/.test(opener.type) ||
|
|
3874
|
-
(opener.type === "click" &&
|
|
3875
|
-
|
|
3981
|
+
(opener.type === "click" &&
|
|
3982
|
+
("pointerType" in opener
|
|
3983
|
+
? Boolean(opener.pointerType)
|
|
3984
|
+
: opener.detail > 0)));
|
|
3985
|
+
if (pointerOpen)
|
|
3986
|
+
s.input = "pointer";
|
|
3987
|
+
const quietOpening = pointerOpen || (!opener && !keyboardAtOpen);
|
|
3988
|
+
opening.focus(quietOpening
|
|
3876
3989
|
? { preventScroll: true, focusVisible: false }
|
|
3877
3990
|
: { preventScroll: true });
|
|
3878
|
-
if (
|
|
3991
|
+
if (quietOpening && matches(opening, ":focus-visible"))
|
|
3879
3992
|
quietFocus(opening);
|
|
3880
3993
|
watchControls(s);
|
|
3881
3994
|
readTiming(s);
|
|
@@ -3936,6 +4049,10 @@ export function createLightbox(options = {}) {
|
|
|
3936
4049
|
dialog.popover = "manual";
|
|
3937
4050
|
dialog.showPopover();
|
|
3938
4051
|
s.releasedFocus = dialog.ownerDocument.activeElement;
|
|
4052
|
+
if (s.input === "pointer" &&
|
|
4053
|
+
s.previousFocus &&
|
|
4054
|
+
s.releasedFocus === s.previousFocus)
|
|
4055
|
+
quietFocus(s.previousFocus);
|
|
3939
4056
|
}
|
|
3940
4057
|
// closed waits for the history back, unless open() or destroy() comes first.
|
|
3941
4058
|
function reportClosed(landing) {
|
|
@@ -4114,6 +4231,7 @@ export function createLightbox(options = {}) {
|
|
|
4114
4231
|
cancelAnimations(s);
|
|
4115
4232
|
s.viewport.append(...slides);
|
|
4116
4233
|
}
|
|
4234
|
+
const arrowsBefore = items.length > 1;
|
|
4117
4235
|
items = nextItems;
|
|
4118
4236
|
sources = [...input];
|
|
4119
4237
|
s.slides = slides;
|
|
@@ -4141,6 +4259,10 @@ export function createLightbox(options = {}) {
|
|
|
4141
4259
|
});
|
|
4142
4260
|
publish({ index: target, count: items.length });
|
|
4143
4261
|
update(s);
|
|
4262
|
+
if (arrowsBefore !== items.length > 1) {
|
|
4263
|
+
const win = s.dialog.ownerDocument.defaultView;
|
|
4264
|
+
s.resizeFrame ??= win?.requestAnimationFrame(() => resized(s));
|
|
4265
|
+
}
|
|
4144
4266
|
s.reported = target;
|
|
4145
4267
|
if (!kept)
|
|
4146
4268
|
arrived(s, target);
|