react-pic-gallery 1.5.16 → 2.0.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 +204 -105
- package/dist/Gallery.d.ts +4 -0
- package/dist/Image.d.ts +16 -0
- package/dist/Lightbox.d.ts +2 -0
- package/dist/PicGallery.d.ts +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/react-pic-gallery.js +405 -0
- package/dist/styles.css +2 -0
- package/dist/types.d.ts +53 -0
- package/package.json +65 -51
- package/CHANGELOG.md +0 -23
- package/dist/lib/CircularLoading/CircularLoading.d.ts +0 -1
- package/dist/lib/ImgGallery/ImgGallery.d.ts +0 -9
- package/dist/lib/ImgLazyLoading.d.ts +0 -11
- package/dist/lib/ImgLightbox/ImgLightbox.d.ts +0 -17
- package/dist/lib/main.d.ts +0 -15
- package/dist/lib/models/models.d.ts +0 -18
- package/dist/lib/styles.d.ts +0 -5
- package/dist/react-pic-gallery.es.js +0 -2009
- package/dist/react-pic-gallery.umd.js +0 -67
- package/dist/vite-env.d.ts +0 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { memo as e, useCallback as t, useEffect as n, useId as r, useRef as i, useState as a } from "react";
|
|
2
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
3
|
+
import { createPortal as c } from "react-dom";
|
|
4
|
+
//#region src/lib/Image.tsx
|
|
5
|
+
function l({ src: e, alt: t, className: r = "", imageClassName: c = "", style: l, imageStyle: u, onAnimationEnd: d, eager: f = !1, objectFit: p = "cover", width: m, height: h }) {
|
|
6
|
+
let g = i(null), [_, v] = a("loading");
|
|
7
|
+
return n(() => {
|
|
8
|
+
v("loading");
|
|
9
|
+
let e = g.current;
|
|
10
|
+
e?.complete && v(e.naturalWidth > 0 ? "loaded" : "error");
|
|
11
|
+
}, [e]), /* @__PURE__ */ s("span", {
|
|
12
|
+
className: `react-pic-gallery__image ${r}`.trim(),
|
|
13
|
+
style: l,
|
|
14
|
+
"aria-busy": _ === "loading",
|
|
15
|
+
onAnimationEnd: d,
|
|
16
|
+
children: [
|
|
17
|
+
/* @__PURE__ */ o("img", {
|
|
18
|
+
ref: g,
|
|
19
|
+
src: e,
|
|
20
|
+
alt: t,
|
|
21
|
+
className: `react-pic-gallery__image-element ${c}`.trim(),
|
|
22
|
+
style: {
|
|
23
|
+
objectFit: p,
|
|
24
|
+
...u
|
|
25
|
+
},
|
|
26
|
+
loading: f ? "eager" : "lazy",
|
|
27
|
+
decoding: "async",
|
|
28
|
+
width: m,
|
|
29
|
+
height: h,
|
|
30
|
+
onLoad: () => v("loaded"),
|
|
31
|
+
onError: () => v("error")
|
|
32
|
+
}),
|
|
33
|
+
_ === "loading" && /* @__PURE__ */ o("span", {
|
|
34
|
+
className: "react-pic-gallery__image-loader",
|
|
35
|
+
role: "progressbar",
|
|
36
|
+
"aria-label": "Loading image"
|
|
37
|
+
}),
|
|
38
|
+
_ === "error" && /* @__PURE__ */ o("span", {
|
|
39
|
+
className: "react-pic-gallery__image-error",
|
|
40
|
+
role: "status",
|
|
41
|
+
children: "Unable to load image"
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/lib/Gallery.tsx
|
|
48
|
+
function u({ images: e, onImageClick: t, columns: n, rowHeight: r, className: i = "", style: a }) {
|
|
49
|
+
let s = typeof r == "number" ? `${r}px` : r, c = {
|
|
50
|
+
...a,
|
|
51
|
+
...n ? { gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))` } : {},
|
|
52
|
+
...s ? { "--gallery-row-height": s } : {}
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ o("div", {
|
|
55
|
+
className: `react-pic-gallery__grid ${i}`.trim(),
|
|
56
|
+
style: c,
|
|
57
|
+
"data-testid": "react-pic-gallery-grid",
|
|
58
|
+
children: e.map((e, n) => /* @__PURE__ */ o("button", {
|
|
59
|
+
className: "react-pic-gallery__tile",
|
|
60
|
+
type: "button",
|
|
61
|
+
disabled: !t,
|
|
62
|
+
onClick: () => t?.(n),
|
|
63
|
+
"aria-label": `Open ${e.alt}`,
|
|
64
|
+
children: /* @__PURE__ */ o(l, {
|
|
65
|
+
src: e.thumbnailSrc ?? e.src,
|
|
66
|
+
alt: e.alt,
|
|
67
|
+
objectFit: "cover",
|
|
68
|
+
width: e.width,
|
|
69
|
+
height: e.height
|
|
70
|
+
})
|
|
71
|
+
}, e.id ?? `${e.src}-${n}`))
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var d = e(u), f = /* @__PURE__ */ new Set(), p = null, m = "a[href], button, input, select, textarea, [role=\"combobox\"], [role=\"menu\"], [role=\"slider\"], [role=\"spinbutton\"], [role=\"tab\"]", h = ".react-pic-gallery__image-element", g = 3;
|
|
75
|
+
function _(e) {
|
|
76
|
+
return e instanceof Element && e.closest(m) !== null;
|
|
77
|
+
}
|
|
78
|
+
function v(e, t, n) {
|
|
79
|
+
return Math.min(Math.max(e, t), n);
|
|
80
|
+
}
|
|
81
|
+
function ee(e) {
|
|
82
|
+
if (!f.has(e)) {
|
|
83
|
+
if (f.size === 0) {
|
|
84
|
+
let e = document.body, t = window.innerWidth - document.documentElement.clientWidth, n = Number.parseFloat(window.getComputedStyle(e).paddingRight) || 0;
|
|
85
|
+
p = {
|
|
86
|
+
overflow: e.style.overflow,
|
|
87
|
+
paddingRight: e.style.paddingRight
|
|
88
|
+
}, e.style.overflow = "hidden", t > 0 && (e.style.paddingRight = `${n + t}px`);
|
|
89
|
+
}
|
|
90
|
+
f.add(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function te(e) {
|
|
94
|
+
return f.delete(e), f.size > 0 || !p ? !1 : (document.body.style.overflow = p.overflow, document.body.style.paddingRight = p.paddingRight, p = null, !0);
|
|
95
|
+
}
|
|
96
|
+
function y(e) {
|
|
97
|
+
let t = e.trim();
|
|
98
|
+
return t.endsWith("ms") ? Number.parseFloat(t) : t.endsWith("s") ? Number.parseFloat(t) * 1e3 : 0;
|
|
99
|
+
}
|
|
100
|
+
function ne(e) {
|
|
101
|
+
let t = window.getComputedStyle(e), n = t.animationDuration.split(","), r = t.animationDelay.split(",");
|
|
102
|
+
return Math.max(...n.map((e, t) => y(e) + y(r[t % r.length] ?? "0s")), 0);
|
|
103
|
+
}
|
|
104
|
+
function re() {
|
|
105
|
+
return /* @__PURE__ */ o("svg", {
|
|
106
|
+
viewBox: "0 0 24 24",
|
|
107
|
+
"aria-hidden": "true",
|
|
108
|
+
focusable: "false",
|
|
109
|
+
children: /* @__PURE__ */ o("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function b({ direction: e }) {
|
|
113
|
+
return /* @__PURE__ */ o("svg", {
|
|
114
|
+
viewBox: "0 0 24 24",
|
|
115
|
+
"aria-hidden": "true",
|
|
116
|
+
focusable: "false",
|
|
117
|
+
children: /* @__PURE__ */ o("path", { d: e === "left" ? "M14.5 5l-7 7 7 7" : "M9.5 5l7 7-7 7" })
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function x(...e) {
|
|
121
|
+
return e.filter(Boolean).join(" ");
|
|
122
|
+
}
|
|
123
|
+
function S({ images: e, index: u, onIndexChange: d, renderActions: f, renderCaption: p, renderControls: y, showCounter: S = !0, showNavigation: C = !0, className: ie }) {
|
|
124
|
+
let w = i(null), T = i(d), E = i(null), D = i(null), O = i(null), k = i(!1), A = i(!1), j = i({}), M = i(e), N = i(null), P = i(/* @__PURE__ */ new Map()), F = i(null), I = i(null), L = r(), [R, z] = a(!1), [B, V] = a(null), [H, U] = a(1), [W, G] = a({
|
|
125
|
+
x: 0,
|
|
126
|
+
y: 0
|
|
127
|
+
}), [ae, oe] = a("50% 50%"), K = u !== null && u >= 0 && u < e.length ? u : null, q = K === null ? void 0 : e[K];
|
|
128
|
+
T.current = d, O.current = K, k.current = R, M.current = e;
|
|
129
|
+
let J = t(() => {
|
|
130
|
+
E.current !== null && (window.clearTimeout(E.current), E.current = null), D.current = null;
|
|
131
|
+
}, []), Y = t(() => {
|
|
132
|
+
let e = O.current;
|
|
133
|
+
if (e !== null && D.current === null) {
|
|
134
|
+
if (typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
|
|
135
|
+
T.current(null);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
D.current = { index: e }, k.current = !0, z(!0);
|
|
139
|
+
}
|
|
140
|
+
}, []), X = t(() => {
|
|
141
|
+
let e = O.current;
|
|
142
|
+
!k.current && e !== null && e > 0 && T.current(e - 1);
|
|
143
|
+
}, []), Z = t(() => {
|
|
144
|
+
let e = O.current;
|
|
145
|
+
!k.current && e !== null && e < M.current.length - 1 && T.current(e + 1);
|
|
146
|
+
}, []), se = t(() => {
|
|
147
|
+
let e = O.current;
|
|
148
|
+
k.current || e === null || e === 0 || (V("previous"), T.current(e - 1));
|
|
149
|
+
}, []), ce = t(() => {
|
|
150
|
+
let e = O.current;
|
|
151
|
+
k.current || e === null || e >= M.current.length - 1 || (V("next"), T.current(e + 1));
|
|
152
|
+
}, []), le = t((e) => {
|
|
153
|
+
e.preventDefault(), Y();
|
|
154
|
+
}, [Y]), Q = t(() => {
|
|
155
|
+
let e = D.current;
|
|
156
|
+
if (e) {
|
|
157
|
+
if (O.current !== e.index) {
|
|
158
|
+
J(), k.current = !1, z(!1);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
J(), k.current = !1, z(!1), T.current(null);
|
|
162
|
+
}
|
|
163
|
+
}, [J]), ue = t((e) => {
|
|
164
|
+
if (e.defaultPrevented) return;
|
|
165
|
+
let t = e.target;
|
|
166
|
+
t instanceof HTMLElement && (t.isContentEditable || t.closest(m)) || (e.key === "ArrowLeft" ? (e.preventDefault(), X()) : e.key === "ArrowRight" && (e.preventDefault(), Z()));
|
|
167
|
+
}, [Z, X]), de = t((e) => {
|
|
168
|
+
if (H > 1 || e.touches.length !== 1 || _(e.target)) {
|
|
169
|
+
N.current = null;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let t = e.touches[0];
|
|
173
|
+
N.current = {
|
|
174
|
+
x: t.clientX,
|
|
175
|
+
y: t.clientY
|
|
176
|
+
};
|
|
177
|
+
}, [H]), fe = t((e) => {
|
|
178
|
+
let t = N.current;
|
|
179
|
+
if (N.current = null, !t || e.changedTouches.length === 0) return;
|
|
180
|
+
let n = e.changedTouches[0], r = n.clientX - t.x, i = n.clientY - t.y, a = Math.abs(r);
|
|
181
|
+
a < 48 || a <= Math.abs(i) || (r < 0 ? ce() : se());
|
|
182
|
+
}, [
|
|
183
|
+
ce,
|
|
184
|
+
se,
|
|
185
|
+
H
|
|
186
|
+
]), pe = t(() => {
|
|
187
|
+
N.current = null;
|
|
188
|
+
}, []), me = t((e) => {
|
|
189
|
+
if (!(e.target instanceof Element) || e.target.closest(h) === null || e.pointerType === "mouse" && e.button !== 0) return;
|
|
190
|
+
let t = P.current;
|
|
191
|
+
if (t.set(e.pointerId, {
|
|
192
|
+
x: e.clientX,
|
|
193
|
+
y: e.clientY
|
|
194
|
+
}), e.currentTarget.setPointerCapture?.(e.pointerId), t.size === 2) {
|
|
195
|
+
let [n, r] = [...t.values()], i = Math.hypot(r.x - n.x, r.y - n.y), a = e.currentTarget.querySelector(h)?.getBoundingClientRect(), o = (n.x + r.x) / 2, s = (n.y + r.y) / 2;
|
|
196
|
+
a && a.width > 0 && a.height > 0 && oe(`${v((o - a.left) / a.width * 100, 0, 100)}% ${v((s - a.top) / a.height * 100, 0, 100)}%`), F.current = {
|
|
197
|
+
distance: Math.max(i, 1),
|
|
198
|
+
scale: H,
|
|
199
|
+
offset: W
|
|
200
|
+
}, I.current = null;
|
|
201
|
+
} else H > 1 && (I.current = {
|
|
202
|
+
x: e.clientX,
|
|
203
|
+
y: e.clientY,
|
|
204
|
+
offset: W
|
|
205
|
+
});
|
|
206
|
+
}, [W, H]), he = t((e) => {
|
|
207
|
+
let t = P.current;
|
|
208
|
+
if (t.has(e.pointerId)) {
|
|
209
|
+
if (t.set(e.pointerId, {
|
|
210
|
+
x: e.clientX,
|
|
211
|
+
y: e.clientY
|
|
212
|
+
}), t.size >= 2 && F.current) {
|
|
213
|
+
let [n, r] = [...t.values()], i = Math.max(Math.hypot(r.x - n.x, r.y - n.y), 1), a = v(F.current.scale * (i / F.current.distance), 1, g);
|
|
214
|
+
U(a), G(F.current.offset), e.preventDefault();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (t.size === 1 && I.current && H > 1) {
|
|
218
|
+
let t = e.currentTarget.querySelector(h), n = t?.clientWidth ?? 0, r = t?.clientHeight ?? 0, i = Math.max(0, n * (H - 1) / 2), a = Math.max(0, r * (H - 1) / 2), o = I.current.offset.x + e.clientX - I.current.x, s = I.current.offset.y + e.clientY - I.current.y;
|
|
219
|
+
G({
|
|
220
|
+
x: v(o, -i, i),
|
|
221
|
+
y: v(s, -a, a)
|
|
222
|
+
}), e.preventDefault();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}, [H]), ge = t((e) => {
|
|
226
|
+
if (P.current.delete(e.pointerId), e.currentTarget.hasPointerCapture?.(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), P.current.size < 2 && (F.current = null), P.current.size === 1 && H > 1) {
|
|
227
|
+
let [e] = [...P.current.values()];
|
|
228
|
+
I.current = {
|
|
229
|
+
x: e.x,
|
|
230
|
+
y: e.y,
|
|
231
|
+
offset: W
|
|
232
|
+
};
|
|
233
|
+
} else I.current = null;
|
|
234
|
+
}, [W, H]), _e = t((e) => {
|
|
235
|
+
e.target === e.currentTarget && V(null);
|
|
236
|
+
}, []), ve = t((e) => {
|
|
237
|
+
e.target === e.currentTarget && e.animationName === "react-pic-gallery-fade-out" && Q();
|
|
238
|
+
}, [Q]), ye = t(() => {
|
|
239
|
+
A.current || (J(), k.current = !1, z(!1), O.current !== null && T.current(null));
|
|
240
|
+
}, [J]);
|
|
241
|
+
if (n(() => {
|
|
242
|
+
U(1), G({
|
|
243
|
+
x: 0,
|
|
244
|
+
y: 0
|
|
245
|
+
}), oe("50% 50%"), P.current.clear(), F.current = null, I.current = null;
|
|
246
|
+
}, [K]), n(() => {
|
|
247
|
+
let e = D.current;
|
|
248
|
+
e && K !== e.index && (J(), k.current = !1, z(!1));
|
|
249
|
+
}, [K, J]), n(() => {
|
|
250
|
+
if (!R || !D.current || !w.current) return;
|
|
251
|
+
let e = ne(w.current);
|
|
252
|
+
return E.current = window.setTimeout(Q, e), () => {
|
|
253
|
+
E.current !== null && (window.clearTimeout(E.current), E.current = null);
|
|
254
|
+
};
|
|
255
|
+
}, [Q, R]), n(() => {
|
|
256
|
+
if (K === null) return;
|
|
257
|
+
let e = w.current;
|
|
258
|
+
if (!e) return;
|
|
259
|
+
let t = document.activeElement;
|
|
260
|
+
return ee(j.current), e.open || e.showModal(), () => {
|
|
261
|
+
J(), A.current = !0, e.open && e.close(), A.current = !1, te(j.current) && t?.isConnected && t.focus();
|
|
262
|
+
};
|
|
263
|
+
}, [K !== null, J]), K === null || !q || typeof document > "u") return null;
|
|
264
|
+
let $ = {
|
|
265
|
+
image: q,
|
|
266
|
+
index: K,
|
|
267
|
+
count: e.length,
|
|
268
|
+
close: Y,
|
|
269
|
+
next: Z,
|
|
270
|
+
previous: X,
|
|
271
|
+
canGoNext: K < e.length - 1,
|
|
272
|
+
canGoPrevious: K > 0
|
|
273
|
+
}, be = C && !y && $.canGoPrevious, xe = C && !y && $.canGoNext, Se = C && !y && e.length > 1, Ce = (e) => {
|
|
274
|
+
e.target === e.currentTarget && Y();
|
|
275
|
+
};
|
|
276
|
+
return c(/* @__PURE__ */ s("dialog", {
|
|
277
|
+
ref: w,
|
|
278
|
+
className: x("react-pic-gallery__lightbox", R ? "react-pic-gallery__lightbox--closing" : void 0, ie),
|
|
279
|
+
"aria-labelledby": L,
|
|
280
|
+
onAnimationEnd: ve,
|
|
281
|
+
onClose: ye,
|
|
282
|
+
onMouseDown: Ce,
|
|
283
|
+
onCancel: le,
|
|
284
|
+
onKeyDown: ue,
|
|
285
|
+
children: [
|
|
286
|
+
/* @__PURE__ */ o("h2", {
|
|
287
|
+
className: "react-pic-gallery__sr-only",
|
|
288
|
+
id: L,
|
|
289
|
+
children: "Image viewer"
|
|
290
|
+
}),
|
|
291
|
+
/* @__PURE__ */ s("p", {
|
|
292
|
+
className: "react-pic-gallery__sr-only",
|
|
293
|
+
"aria-live": "polite",
|
|
294
|
+
children: [
|
|
295
|
+
q.alt,
|
|
296
|
+
", image ",
|
|
297
|
+
K + 1,
|
|
298
|
+
" of ",
|
|
299
|
+
e.length
|
|
300
|
+
]
|
|
301
|
+
}),
|
|
302
|
+
/* @__PURE__ */ s("div", {
|
|
303
|
+
className: "react-pic-gallery__lightbox-content",
|
|
304
|
+
children: [
|
|
305
|
+
y ? /* @__PURE__ */ o("div", {
|
|
306
|
+
className: "react-pic-gallery__custom-controls",
|
|
307
|
+
children: y($)
|
|
308
|
+
}) : /* @__PURE__ */ s("div", {
|
|
309
|
+
className: "react-pic-gallery__toolbar",
|
|
310
|
+
children: [/* @__PURE__ */ s("div", {
|
|
311
|
+
className: "react-pic-gallery__toolbar-actions",
|
|
312
|
+
children: [S && /* @__PURE__ */ s("span", {
|
|
313
|
+
"aria-live": "polite",
|
|
314
|
+
children: [
|
|
315
|
+
K + 1,
|
|
316
|
+
" / ",
|
|
317
|
+
e.length
|
|
318
|
+
]
|
|
319
|
+
}), f?.($)]
|
|
320
|
+
}), /* @__PURE__ */ o("button", {
|
|
321
|
+
className: "react-pic-gallery__control",
|
|
322
|
+
type: "button",
|
|
323
|
+
onClick: Y,
|
|
324
|
+
"aria-label": "Close image viewer",
|
|
325
|
+
children: /* @__PURE__ */ o(re, {})
|
|
326
|
+
})]
|
|
327
|
+
}),
|
|
328
|
+
/* @__PURE__ */ s("div", {
|
|
329
|
+
className: x("react-pic-gallery__viewport", Se ? "react-pic-gallery__viewport--has-navigation" : void 0),
|
|
330
|
+
onMouseDown: Ce,
|
|
331
|
+
onPointerCancel: ge,
|
|
332
|
+
onPointerDown: me,
|
|
333
|
+
onPointerMove: he,
|
|
334
|
+
onPointerUp: ge,
|
|
335
|
+
onTouchCancel: pe,
|
|
336
|
+
onTouchEnd: fe,
|
|
337
|
+
onTouchStart: de,
|
|
338
|
+
children: [
|
|
339
|
+
be && /* @__PURE__ */ o("button", {
|
|
340
|
+
className: "react-pic-gallery__control react-pic-gallery__control--previous",
|
|
341
|
+
type: "button",
|
|
342
|
+
onClick: X,
|
|
343
|
+
"aria-label": "Previous image",
|
|
344
|
+
children: /* @__PURE__ */ o(b, { direction: "left" })
|
|
345
|
+
}),
|
|
346
|
+
/* @__PURE__ */ o(l, {
|
|
347
|
+
src: q.src,
|
|
348
|
+
alt: q.alt,
|
|
349
|
+
eager: !0,
|
|
350
|
+
objectFit: "contain",
|
|
351
|
+
width: q.width,
|
|
352
|
+
height: q.height,
|
|
353
|
+
className: x("react-pic-gallery__lightbox-image", B ? `react-pic-gallery__lightbox-image--swipe-${B}` : void 0),
|
|
354
|
+
imageStyle: {
|
|
355
|
+
transform: `translate3d(${W.x}px, ${W.y}px, 0) scale(${H})`,
|
|
356
|
+
transformOrigin: ae,
|
|
357
|
+
transition: P.current.size > 0 ? "none" : void 0
|
|
358
|
+
},
|
|
359
|
+
onAnimationEnd: _e
|
|
360
|
+
}, q.src),
|
|
361
|
+
xe && /* @__PURE__ */ o("button", {
|
|
362
|
+
className: "react-pic-gallery__control react-pic-gallery__control--next",
|
|
363
|
+
type: "button",
|
|
364
|
+
onClick: Z,
|
|
365
|
+
"aria-label": "Next image",
|
|
366
|
+
children: /* @__PURE__ */ o(b, { direction: "right" })
|
|
367
|
+
})
|
|
368
|
+
]
|
|
369
|
+
}),
|
|
370
|
+
(p || q.caption) && /* @__PURE__ */ o("div", {
|
|
371
|
+
className: "react-pic-gallery__caption",
|
|
372
|
+
children: p ? p($) : q.caption
|
|
373
|
+
})
|
|
374
|
+
]
|
|
375
|
+
})
|
|
376
|
+
]
|
|
377
|
+
}), document.body);
|
|
378
|
+
}
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/lib/PicGallery.tsx
|
|
381
|
+
function C({ images: e, columns: t, rowHeight: n, className: r, galleryClassName: i, style: c, renderActions: l, renderCaption: u, renderControls: f, showCounter: p, showNavigation: m }) {
|
|
382
|
+
let [h, g] = a(null);
|
|
383
|
+
return /* @__PURE__ */ s("div", {
|
|
384
|
+
className: `react-pic-gallery ${r ?? ""}`.trim(),
|
|
385
|
+
style: c,
|
|
386
|
+
children: [/* @__PURE__ */ o(d, {
|
|
387
|
+
images: e,
|
|
388
|
+
columns: t,
|
|
389
|
+
rowHeight: n,
|
|
390
|
+
className: i,
|
|
391
|
+
onImageClick: g
|
|
392
|
+
}), /* @__PURE__ */ o(S, {
|
|
393
|
+
images: e,
|
|
394
|
+
index: h,
|
|
395
|
+
onIndexChange: g,
|
|
396
|
+
renderActions: l,
|
|
397
|
+
renderCaption: u,
|
|
398
|
+
renderControls: f,
|
|
399
|
+
showCounter: p,
|
|
400
|
+
showNavigation: m
|
|
401
|
+
})]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
export { d as Gallery, S as Lightbox, C as PicGallery, C as default };
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
:where(.react-pic-gallery,.react-pic-gallery__lightbox){--gallery-gap:.75rem;--gallery-radius:1rem;--gallery-row-height:12rem;--gallery-accent:#9ef01a;--gallery-overlay:#070b10f0;--gallery-control-size:2.75rem;--gallery-motion:.18s;color:#f8fafc}.react-pic-gallery{width:100%;min-width:0}.react-pic-gallery__grid{gap:var(--gallery-gap);grid-template-columns:repeat(3,minmax(0,1fr));width:100%;display:grid}.react-pic-gallery__tile{min-width:0;height:var(--gallery-row-height);cursor:pointer;border-radius:var(--gallery-radius);isolation:isolate;background:#e2e8f0;border:0;padding:0;position:relative;overflow:hidden}.react-pic-gallery__tile:after{content:"";pointer-events:none;border-radius:inherit;transition:border-color var(--gallery-motion) ease;border:2px solid #0000;position:absolute;inset:0}.react-pic-gallery__tile:hover .react-pic-gallery__image-element,.react-pic-gallery__tile:focus-visible .react-pic-gallery__image-element{transform:scale(1.04)}.react-pic-gallery__tile:focus-visible{outline:3px solid var(--gallery-accent);outline-offset:3px}.react-pic-gallery__tile:focus-visible:after{border-color:var(--gallery-accent)}.react-pic-gallery__tile:disabled{cursor:default}.react-pic-gallery__image{background:linear-gradient(135deg,#e2e8f0,#cbd5e1);width:100%;height:100%;display:block;position:relative;overflow:hidden}.react-pic-gallery__image-element{width:100%;height:100%;transition:transform var(--gallery-motion) ease, opacity var(--gallery-motion) ease;display:block}.react-pic-gallery__image-loader,.react-pic-gallery__image-error{place-items:center;display:grid;position:absolute;inset:0}.react-pic-gallery__image-loader:after{content:"";border:2px solid #0f172a29;border-top-color:var(--gallery-accent);border-radius:50%;width:1.5rem;height:1.5rem;animation:.7s linear infinite react-pic-gallery-spin}.react-pic-gallery__image-error{color:#475569;text-align:center;background:#e2e8f0e6;padding:1rem;font-size:.875rem}:where(dialog.react-pic-gallery__lightbox){z-index:1000;box-sizing:border-box;width:100%;max-width:none;height:100%;max-height:none;padding:max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));color:#f8fafc;background:var(--gallery-overlay);animation:react-pic-gallery-fade-in var(--gallery-motion) ease both;border:0;place-items:center;margin:0;display:grid;position:fixed;inset:0;overflow:hidden}dialog.react-pic-gallery__lightbox:not([open]){display:none}dialog.react-pic-gallery__lightbox::backdrop{background:0 0}.react-pic-gallery__lightbox--closing{animation:react-pic-gallery-fade-out var(--gallery-motion) ease both}.react-pic-gallery__lightbox-content{width:min(100%,90rem);height:min(100%,54rem);min-height:0;animation:react-pic-gallery-rise-in var(--gallery-motion) ease both;grid-template-rows:auto minmax(0,1fr) auto;display:grid}.react-pic-gallery__lightbox--closing .react-pic-gallery__lightbox-content{animation:react-pic-gallery-rise-out var(--gallery-motion) ease both}.react-pic-gallery__toolbar,.react-pic-gallery__custom-controls{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:1rem;min-height:3.5rem;display:flex}.react-pic-gallery__toolbar-actions{color:#cbd5e1;align-items:center;gap:.75rem;min-width:0;font-size:.875rem;display:flex}.react-pic-gallery__control{width:var(--gallery-control-size);height:var(--gallery-control-size);color:#f8fafc;cursor:pointer;transition:background var(--gallery-motion) ease, color var(--gallery-motion) ease, transform var(--gallery-motion) ease;background:0 0;border:0;border-radius:.7rem;flex:none;place-items:center;padding:0;font-size:1.4rem;line-height:1;display:inline-grid}.react-pic-gallery__control:hover{background:#f8fafc24;transform:translateY(-1px)}.react-pic-gallery__control:focus-visible{outline:3px solid var(--gallery-accent);outline-offset:3px}.react-pic-gallery__control svg{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.8px;width:1.25rem;height:1.25rem}.react-pic-gallery__viewport{touch-action:pan-y;place-items:center;min-height:0;padding:.75rem;display:grid;position:relative}.react-pic-gallery__viewport--has-navigation{padding-inline:3.5rem}.react-pic-gallery__lightbox-image{pointer-events:none;border-radius:var(--gallery-radius);width:min(100%,82rem);min-width:0;height:100%;min-height:0;animation:react-pic-gallery-image-in var(--gallery-motion) ease both;background:0 0;place-items:center;display:grid;overflow:visible}.react-pic-gallery__lightbox-image .react-pic-gallery__image-element{pointer-events:auto;touch-action:none;border-radius:inherit;object-fit:contain;background:0 0;width:auto;max-width:100%;height:auto;max-height:100%}.react-pic-gallery__lightbox-image .react-pic-gallery__image-loader{pointer-events:none;background:0 0}.react-pic-gallery__lightbox-image .react-pic-gallery__image-error{pointer-events:none}.react-pic-gallery__lightbox-image--swipe-next{animation-name:react-pic-gallery-slide-in-from-right}.react-pic-gallery__lightbox-image--swipe-previous{animation-name:react-pic-gallery-slide-in-from-left}.react-pic-gallery__control--previous,.react-pic-gallery__control--next{z-index:1;position:absolute;top:50%;transform:translateY(-50%)}.react-pic-gallery__control--previous:hover,.react-pic-gallery__control--next:hover{transform:translateY(calc(-50% - 1px))}.react-pic-gallery__control--previous{left:0}.react-pic-gallery__control--next{right:0}.react-pic-gallery__caption{color:#cbd5e1;text-align:center;max-height:8rem;padding:.75rem 0 0;font-size:.95rem;line-height:1.4;overflow:hidden}.react-pic-gallery__sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;padding:0;position:absolute;overflow:hidden}@keyframes react-pic-gallery-spin{to{transform:rotate(360deg)}}@keyframes react-pic-gallery-fade-in{0%{opacity:0}to{opacity:1}}@keyframes react-pic-gallery-fade-out{0%{opacity:1}to{opacity:0}}@keyframes react-pic-gallery-rise-in{0%{opacity:0;transform:translateY(.5rem)scale(.99)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes react-pic-gallery-rise-out{0%{opacity:1;transform:translateY(0)scale(1)}to{opacity:0;transform:translateY(.5rem)scale(.99)}}@keyframes react-pic-gallery-image-in{0%{opacity:0;transform:scale(.985)}to{opacity:1;transform:scale(1)}}@keyframes react-pic-gallery-slide-in-from-right{0%{opacity:0;transform:translate(18%)}to{opacity:1;transform:translate(0)}}@keyframes react-pic-gallery-slide-in-from-left{0%{opacity:0;transform:translate(-18%)}to{opacity:1;transform:translate(0)}}@media (width<=600px){:where(.react-pic-gallery,.react-pic-gallery__lightbox){--gallery-gap:.5rem;--gallery-radius:.75rem;--gallery-row-height:8rem}.react-pic-gallery__lightbox-content{height:100%}.react-pic-gallery__viewport{padding-inline:.25rem}.react-pic-gallery__viewport--has-navigation{padding-inline:2.75rem}.react-pic-gallery__control--previous{left:-.25rem}.react-pic-gallery__control--next{right:-.25rem}}@media (prefers-reduced-motion:reduce){:where(.react-pic-gallery,.react-pic-gallery__lightbox){--gallery-motion:0s}.react-pic-gallery__image-loader:after{animation:none}}
|
|
2
|
+
/*$vite$:1*/
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
export type GalleryImage = {
|
|
3
|
+
id?: string;
|
|
4
|
+
src: string;
|
|
5
|
+
thumbnailSrc?: string;
|
|
6
|
+
alt: string;
|
|
7
|
+
caption?: ReactNode;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
};
|
|
11
|
+
export type LightboxContext<T extends GalleryImage = GalleryImage> = {
|
|
12
|
+
image: T;
|
|
13
|
+
index: number;
|
|
14
|
+
count: number;
|
|
15
|
+
close: () => void;
|
|
16
|
+
next: () => void;
|
|
17
|
+
previous: () => void;
|
|
18
|
+
canGoNext: boolean;
|
|
19
|
+
canGoPrevious: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type LightboxRenderer<T extends GalleryImage = GalleryImage> = (context: LightboxContext<T>) => ReactNode;
|
|
22
|
+
export type GalleryProps<T extends GalleryImage = GalleryImage> = {
|
|
23
|
+
images: readonly T[];
|
|
24
|
+
onImageClick?: (index: number) => void;
|
|
25
|
+
columns?: number;
|
|
26
|
+
rowHeight?: CSSProperties['height'];
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
};
|
|
30
|
+
export type LightboxProps<T extends GalleryImage = GalleryImage> = {
|
|
31
|
+
images: readonly T[];
|
|
32
|
+
index: number | null;
|
|
33
|
+
onIndexChange: (index: number | null) => void;
|
|
34
|
+
renderActions?: LightboxRenderer<T>;
|
|
35
|
+
renderCaption?: LightboxRenderer<T>;
|
|
36
|
+
renderControls?: LightboxRenderer<T>;
|
|
37
|
+
showCounter?: boolean;
|
|
38
|
+
showNavigation?: boolean;
|
|
39
|
+
className?: string;
|
|
40
|
+
};
|
|
41
|
+
export type PicGalleryProps<T extends GalleryImage = GalleryImage> = {
|
|
42
|
+
images: readonly T[];
|
|
43
|
+
columns?: number;
|
|
44
|
+
rowHeight?: CSSProperties['height'];
|
|
45
|
+
className?: string;
|
|
46
|
+
galleryClassName?: string;
|
|
47
|
+
style?: CSSProperties;
|
|
48
|
+
renderActions?: LightboxRenderer<T>;
|
|
49
|
+
renderCaption?: LightboxRenderer<T>;
|
|
50
|
+
renderControls?: LightboxRenderer<T>;
|
|
51
|
+
showCounter?: boolean;
|
|
52
|
+
showNavigation?: boolean;
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,51 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-pic-gallery",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"react": "^
|
|
49
|
-
"react-dom": "^
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "react-pic-gallery",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Small, accessible React image gallery and lightbox.",
|
|
5
|
+
"author": "marcelrsoub",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/marcelrsoub/react-pic-gallery.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"module": "./dist/react-pic-gallery.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"./dist/styles.css"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/react-pic-gallery.js"
|
|
24
|
+
},
|
|
25
|
+
"./styles.css": "./dist/styles.css"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "npm run dev:docs",
|
|
29
|
+
"dev:library": "vite",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"build": "npm run typecheck && vite build",
|
|
32
|
+
"preview": "npm run preview:docs",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"build:demo": "npm run build:docs",
|
|
36
|
+
"dev:docs": "astro dev --config docs-site/astro.config.mjs",
|
|
37
|
+
"build:docs": "astro build --config docs-site/astro.config.mjs",
|
|
38
|
+
"preview:docs": "astro preview --config docs-site/astro.config.mjs",
|
|
39
|
+
"github-pages": "npm run build:docs && gh-pages -d build",
|
|
40
|
+
"prepack": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@astrojs/react": "^6.0.6",
|
|
44
|
+
"@astrojs/starlight": "^0.42.2",
|
|
45
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
46
|
+
"@testing-library/react": "^16.3.3",
|
|
47
|
+
"@types/node": "^24.0.0",
|
|
48
|
+
"@types/react": "^19.3.0",
|
|
49
|
+
"@types/react-dom": "^19.3.0",
|
|
50
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
51
|
+
"astro": "^7.3.3",
|
|
52
|
+
"gh-pages": "^6.3.0",
|
|
53
|
+
"jsdom": "^30.1.0",
|
|
54
|
+
"react": "^19.3.0",
|
|
55
|
+
"react-dom": "^19.3.0",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"vite": "^8.3.0",
|
|
58
|
+
"vite-plugin-dts": "^5.1.1",
|
|
59
|
+
"vitest": "^5.0.1"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": "^18.3.1 || ^19.0.0",
|
|
63
|
+
"react-dom": "^18.3.1 || ^19.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [1.5.16](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.15...v1.5.16) (2022-05-29)
|
|
6
|
-
|
|
7
|
-
### [1.5.15](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.14...v1.5.15) (2022-03-23)
|
|
8
|
-
|
|
9
|
-
### [1.5.14](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.13...v1.5.14) (2022-03-23)
|
|
10
|
-
|
|
11
|
-
### [1.5.13](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.12...v1.5.13) (2022-03-23)
|
|
12
|
-
|
|
13
|
-
### [1.5.12](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.11...v1.5.12) (2022-03-23)
|
|
14
|
-
|
|
15
|
-
### [1.5.11](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.10...v1.5.11) (2022-03-23)
|
|
16
|
-
|
|
17
|
-
### [1.5.10](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.9...v1.5.10) (2021-12-30)
|
|
18
|
-
|
|
19
|
-
### [1.5.9](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.8...v1.5.9) (2021-12-22)
|
|
20
|
-
|
|
21
|
-
### [1.5.8](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.5.7...v1.5.8) (2021-12-16)
|
|
22
|
-
|
|
23
|
-
### [1.5.7](https://github.com/marcelrsoub/react-pic-gallery/compare/v1.3.9...v1.5.7) (2021-12-16)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function CircularLoading(): JSX.Element;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ImageObject, Options } from '../models/models';
|
|
3
|
-
declare function ImgGallery(props: {
|
|
4
|
-
options?: Options;
|
|
5
|
-
imgList: ImageObject[];
|
|
6
|
-
onOpen: (index_of_image: number) => void;
|
|
7
|
-
}): JSX.Element;
|
|
8
|
-
declare const _default: React.MemoExoticComponent<typeof ImgGallery>;
|
|
9
|
-
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Options } from './models/models';
|
|
3
|
-
declare const ImgLazyLoading: (props: {
|
|
4
|
-
imgSrc: string;
|
|
5
|
-
id?: string;
|
|
6
|
-
style: React.CSSProperties;
|
|
7
|
-
options?: Options;
|
|
8
|
-
onClick?: () => void;
|
|
9
|
-
lightboxMode?: boolean;
|
|
10
|
-
}) => JSX.Element;
|
|
11
|
-
export default ImgLazyLoading;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ImageObject, Options } from '../models/models';
|
|
2
|
-
declare const ImgLightbox: (props: {
|
|
3
|
-
imgList: ImageObject[];
|
|
4
|
-
open: boolean;
|
|
5
|
-
currentImgIndex: number;
|
|
6
|
-
options?: Options | undefined;
|
|
7
|
-
onClose: () => void;
|
|
8
|
-
topCustomContent?: ((props2: {
|
|
9
|
-
imgObject: ImageObject;
|
|
10
|
-
closeLightbox: () => void;
|
|
11
|
-
}) => JSX.Element) | undefined;
|
|
12
|
-
bottomCustomContent?: ((props2: {
|
|
13
|
-
imgObject: ImageObject;
|
|
14
|
-
closeLightbox: () => void;
|
|
15
|
-
}) => JSX.Element) | undefined;
|
|
16
|
-
}) => JSX.Element;
|
|
17
|
-
export default ImgLightbox;
|