react-pic-gallery 1.5.16 → 2.0.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 +215 -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 +368 -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,368 @@
|
|
|
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
|
+
var u = 3;
|
|
49
|
+
function d({ images: e, onImageClick: n, columns: r, rowHeight: s, className: c = "", style: d }) {
|
|
50
|
+
let f = i([]), [p, m] = a(0), h = r && r > 0 ? r : u, g = e.length - 1, _ = Math.min(p, Math.max(g, 0)), v = t((e) => {
|
|
51
|
+
m(e), f.current[e]?.focus();
|
|
52
|
+
}, []), y = t((e, t) => {
|
|
53
|
+
let n = {
|
|
54
|
+
ArrowRight: 1,
|
|
55
|
+
ArrowLeft: -1,
|
|
56
|
+
ArrowDown: h,
|
|
57
|
+
ArrowUp: -h
|
|
58
|
+
}[e.key], r = null;
|
|
59
|
+
if (n !== void 0) {
|
|
60
|
+
let e = t + n;
|
|
61
|
+
e >= 0 && e <= g && (r = e);
|
|
62
|
+
} else if (e.key === "Home") r = 0;
|
|
63
|
+
else if (e.key === "End") r = g;
|
|
64
|
+
else return;
|
|
65
|
+
r !== null && r !== t && (e.preventDefault(), v(r));
|
|
66
|
+
}, [
|
|
67
|
+
h,
|
|
68
|
+
g,
|
|
69
|
+
v
|
|
70
|
+
]), b = typeof s == "number" ? `${s}px` : s, x = {
|
|
71
|
+
...d,
|
|
72
|
+
...r ? { gridTemplateColumns: `repeat(${r}, minmax(0, 1fr))` } : {},
|
|
73
|
+
...b ? { "--gallery-row-height": b } : {}
|
|
74
|
+
};
|
|
75
|
+
return /* @__PURE__ */ o("div", {
|
|
76
|
+
className: `react-pic-gallery__grid ${c}`.trim(),
|
|
77
|
+
style: x,
|
|
78
|
+
"data-testid": "react-pic-gallery-grid",
|
|
79
|
+
children: e.map((e, t) => /* @__PURE__ */ o("button", {
|
|
80
|
+
className: "react-pic-gallery__tile",
|
|
81
|
+
type: "button",
|
|
82
|
+
disabled: !n,
|
|
83
|
+
tabIndex: t === _ ? 0 : -1,
|
|
84
|
+
ref: (e) => {
|
|
85
|
+
f.current[t] = e;
|
|
86
|
+
},
|
|
87
|
+
onKeyDown: (e) => y(e, t),
|
|
88
|
+
onClick: () => {
|
|
89
|
+
m(t), n?.(t);
|
|
90
|
+
},
|
|
91
|
+
"aria-label": `Open ${e.alt}`,
|
|
92
|
+
children: /* @__PURE__ */ o(l, {
|
|
93
|
+
src: e.thumbnailSrc ?? e.src,
|
|
94
|
+
alt: e.alt,
|
|
95
|
+
objectFit: "cover",
|
|
96
|
+
width: e.width,
|
|
97
|
+
height: e.height
|
|
98
|
+
})
|
|
99
|
+
}, e.id ?? `${e.src}-${t}`))
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
var f = e(d), p = /* @__PURE__ */ new Set(), m = null, h = "a[href], button, input, select, textarea, [role=\"combobox\"], [role=\"menu\"], [role=\"slider\"], [role=\"spinbutton\"], [role=\"tab\"]", g = "input, select, textarea, [role=\"combobox\"], [role=\"menu\"], [role=\"slider\"], [role=\"spinbutton\"], [role=\"tab\"]", _ = "(max-width: 600px), (pointer: coarse)", v = .3;
|
|
103
|
+
function y(e) {
|
|
104
|
+
return e instanceof Element && e.closest(h) !== null;
|
|
105
|
+
}
|
|
106
|
+
function b(e) {
|
|
107
|
+
if (!p.has(e)) {
|
|
108
|
+
if (p.size === 0) {
|
|
109
|
+
let e = document.body, t = window.innerWidth - document.documentElement.clientWidth, n = Number.parseFloat(window.getComputedStyle(e).paddingRight) || 0;
|
|
110
|
+
m = {
|
|
111
|
+
overflow: e.style.overflow,
|
|
112
|
+
paddingRight: e.style.paddingRight
|
|
113
|
+
}, e.style.overflow = "hidden", t > 0 && (e.style.paddingRight = `${n + t}px`);
|
|
114
|
+
}
|
|
115
|
+
p.add(e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function x(e) {
|
|
119
|
+
return p.delete(e), p.size > 0 || !m ? !1 : (document.body.style.overflow = m.overflow, document.body.style.paddingRight = m.paddingRight, m = null, !0);
|
|
120
|
+
}
|
|
121
|
+
function S(e) {
|
|
122
|
+
let t = e.trim();
|
|
123
|
+
return t.endsWith("ms") ? Number.parseFloat(t) : t.endsWith("s") ? Number.parseFloat(t) * 1e3 : 0;
|
|
124
|
+
}
|
|
125
|
+
function ee(e) {
|
|
126
|
+
let t = window.getComputedStyle(e), n = t.animationDuration.split(","), r = t.animationDelay.split(",");
|
|
127
|
+
return Math.max(...n.map((e, t) => S(e) + S(r[t % r.length] ?? "0s")), 0);
|
|
128
|
+
}
|
|
129
|
+
function C() {
|
|
130
|
+
return /* @__PURE__ */ o("svg", {
|
|
131
|
+
viewBox: "0 0 24 24",
|
|
132
|
+
"aria-hidden": "true",
|
|
133
|
+
focusable: "false",
|
|
134
|
+
children: /* @__PURE__ */ o("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function w({ direction: e }) {
|
|
138
|
+
return /* @__PURE__ */ o("svg", {
|
|
139
|
+
viewBox: "0 0 24 24",
|
|
140
|
+
"aria-hidden": "true",
|
|
141
|
+
focusable: "false",
|
|
142
|
+
children: /* @__PURE__ */ o("path", { d: e === "left" ? "M14.5 5l-7 7 7 7" : "M9.5 5l7 7-7 7" })
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function T(...e) {
|
|
146
|
+
return e.filter(Boolean).join(" ");
|
|
147
|
+
}
|
|
148
|
+
function E({ images: e, index: u, onIndexChange: d, renderActions: f, renderCaption: p, renderControls: m, showCounter: h = !0, showNavigation: S = !0, className: E }) {
|
|
149
|
+
let D = i(null), O = i(d), k = i(null), A = i(null), j = i(null), M = i(!1), N = i(!1), P = i({}), F = i(e), I = i(null), L = r(), [R, z] = a(!1), [B, V] = a(null), H = u !== null && u >= 0 && u < e.length ? u : null, U = H === null ? void 0 : e[H];
|
|
150
|
+
O.current = d, j.current = H, M.current = R, F.current = e;
|
|
151
|
+
let W = t(() => {
|
|
152
|
+
k.current !== null && (window.clearTimeout(k.current), k.current = null), A.current = null;
|
|
153
|
+
}, []), G = t(() => {
|
|
154
|
+
let e = j.current;
|
|
155
|
+
if (e !== null && A.current === null) {
|
|
156
|
+
if (typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
|
|
157
|
+
O.current(null);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
A.current = { index: e }, M.current = !0, z(!0);
|
|
161
|
+
}
|
|
162
|
+
}, []), K = t(() => {
|
|
163
|
+
let e = j.current;
|
|
164
|
+
!M.current && e !== null && e > 0 && O.current(e - 1);
|
|
165
|
+
}, []), q = t(() => {
|
|
166
|
+
let e = j.current;
|
|
167
|
+
!M.current && e !== null && e < F.current.length - 1 && O.current(e + 1);
|
|
168
|
+
}, []), J = t(() => {
|
|
169
|
+
let e = j.current;
|
|
170
|
+
M.current || e === null || e === 0 || (V("previous"), O.current(e - 1));
|
|
171
|
+
}, []), Y = t(() => {
|
|
172
|
+
let e = j.current;
|
|
173
|
+
M.current || e === null || e >= F.current.length - 1 || (V("next"), O.current(e + 1));
|
|
174
|
+
}, []), te = t((e) => {
|
|
175
|
+
e.preventDefault(), G();
|
|
176
|
+
}, [G]), X = t(() => {
|
|
177
|
+
let e = A.current;
|
|
178
|
+
if (e) {
|
|
179
|
+
if (j.current !== e.index) {
|
|
180
|
+
W(), M.current = !1, z(!1);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
W(), M.current = !1, z(!1), O.current(null);
|
|
184
|
+
}
|
|
185
|
+
}, [W]), ne = t((e) => {
|
|
186
|
+
if (e.defaultPrevented) return;
|
|
187
|
+
let t = e.target;
|
|
188
|
+
t instanceof HTMLElement && (t.isContentEditable || t.closest(g)) || (e.key === "ArrowLeft" ? (e.preventDefault(), K()) : e.key === "ArrowRight" && (e.preventDefault(), q()));
|
|
189
|
+
}, [q, K]), re = t((e) => {
|
|
190
|
+
if (e.touches.length !== 1 || y(e.target)) {
|
|
191
|
+
I.current = null;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
let t = e.touches[0];
|
|
195
|
+
I.current = {
|
|
196
|
+
x: t.clientX,
|
|
197
|
+
y: t.clientY
|
|
198
|
+
};
|
|
199
|
+
}, []), ie = t((e) => {
|
|
200
|
+
let t = I.current;
|
|
201
|
+
if (I.current = null, !t || e.changedTouches.length === 0) return;
|
|
202
|
+
let n = e.changedTouches[0], r = n.clientX - t.x, i = n.clientY - t.y, a = Math.abs(r);
|
|
203
|
+
a < 48 || a <= Math.abs(i) || (r < 0 ? Y() : J());
|
|
204
|
+
}, [Y, J]), ae = t(() => {
|
|
205
|
+
I.current = null;
|
|
206
|
+
}, []), oe = t((e) => {
|
|
207
|
+
e.target === e.currentTarget && V(null);
|
|
208
|
+
}, []), se = t((e) => {
|
|
209
|
+
e.target === e.currentTarget && e.animationName === "react-pic-gallery-fade-out" && X();
|
|
210
|
+
}, [X]), ce = t(() => {
|
|
211
|
+
N.current || (W(), M.current = !1, z(!1), j.current !== null && O.current(null));
|
|
212
|
+
}, [W]);
|
|
213
|
+
if (n(() => {
|
|
214
|
+
let e = A.current;
|
|
215
|
+
e && H !== e.index && (W(), M.current = !1, z(!1));
|
|
216
|
+
}, [H, W]), n(() => {
|
|
217
|
+
if (!R || !A.current || !D.current) return;
|
|
218
|
+
let e = ee(D.current);
|
|
219
|
+
return k.current = window.setTimeout(X, e), () => {
|
|
220
|
+
k.current !== null && (window.clearTimeout(k.current), k.current = null);
|
|
221
|
+
};
|
|
222
|
+
}, [X, R]), n(() => {
|
|
223
|
+
if (H === null) return;
|
|
224
|
+
let e = D.current;
|
|
225
|
+
if (!e) return;
|
|
226
|
+
let t = document.activeElement;
|
|
227
|
+
return b(P.current), e.open || e.showModal(), () => {
|
|
228
|
+
W(), N.current = !0, e.open && e.close(), N.current = !1, x(P.current) && t?.isConnected && t.focus();
|
|
229
|
+
};
|
|
230
|
+
}, [H !== null, W]), H === null || !U || typeof document > "u") return null;
|
|
231
|
+
let Z = {
|
|
232
|
+
image: U,
|
|
233
|
+
index: H,
|
|
234
|
+
count: e.length,
|
|
235
|
+
close: G,
|
|
236
|
+
next: q,
|
|
237
|
+
previous: K,
|
|
238
|
+
canGoNext: H < e.length - 1,
|
|
239
|
+
canGoPrevious: H > 0
|
|
240
|
+
}, le = S && !m && Z.canGoPrevious, ue = S && !m && Z.canGoNext, Q = S && !m && e.length > 1, $ = (e) => {
|
|
241
|
+
e.target === e.currentTarget && G();
|
|
242
|
+
};
|
|
243
|
+
return c(/* @__PURE__ */ s("dialog", {
|
|
244
|
+
ref: D,
|
|
245
|
+
className: T("react-pic-gallery__lightbox", R ? "react-pic-gallery__lightbox--closing" : void 0, E),
|
|
246
|
+
"aria-labelledby": L,
|
|
247
|
+
onAnimationEnd: se,
|
|
248
|
+
onClose: ce,
|
|
249
|
+
onMouseDown: $,
|
|
250
|
+
onCancel: te,
|
|
251
|
+
onKeyDown: ne,
|
|
252
|
+
children: [
|
|
253
|
+
/* @__PURE__ */ o("h2", {
|
|
254
|
+
className: "react-pic-gallery__sr-only",
|
|
255
|
+
id: L,
|
|
256
|
+
children: "Image viewer"
|
|
257
|
+
}),
|
|
258
|
+
/* @__PURE__ */ s("p", {
|
|
259
|
+
className: "react-pic-gallery__sr-only",
|
|
260
|
+
"aria-live": "polite",
|
|
261
|
+
children: [
|
|
262
|
+
U.alt,
|
|
263
|
+
", image ",
|
|
264
|
+
H + 1,
|
|
265
|
+
" of ",
|
|
266
|
+
e.length
|
|
267
|
+
]
|
|
268
|
+
}),
|
|
269
|
+
/* @__PURE__ */ s("div", {
|
|
270
|
+
className: "react-pic-gallery__lightbox-content",
|
|
271
|
+
children: [
|
|
272
|
+
m ? /* @__PURE__ */ o("div", {
|
|
273
|
+
className: "react-pic-gallery__custom-controls",
|
|
274
|
+
children: m(Z)
|
|
275
|
+
}) : /* @__PURE__ */ s("div", {
|
|
276
|
+
className: "react-pic-gallery__toolbar",
|
|
277
|
+
children: [/* @__PURE__ */ s("div", {
|
|
278
|
+
className: "react-pic-gallery__toolbar-actions",
|
|
279
|
+
children: [h && /* @__PURE__ */ s("span", {
|
|
280
|
+
"aria-live": "polite",
|
|
281
|
+
children: [
|
|
282
|
+
H + 1,
|
|
283
|
+
" / ",
|
|
284
|
+
e.length
|
|
285
|
+
]
|
|
286
|
+
}), f?.(Z)]
|
|
287
|
+
}), /* @__PURE__ */ o("button", {
|
|
288
|
+
className: "react-pic-gallery__control",
|
|
289
|
+
type: "button",
|
|
290
|
+
onClick: G,
|
|
291
|
+
"aria-label": "Close image viewer",
|
|
292
|
+
children: /* @__PURE__ */ o(C, {})
|
|
293
|
+
})]
|
|
294
|
+
}),
|
|
295
|
+
/* @__PURE__ */ s("div", {
|
|
296
|
+
className: T("react-pic-gallery__viewport", Q ? "react-pic-gallery__viewport--has-navigation" : void 0),
|
|
297
|
+
onMouseDown: $,
|
|
298
|
+
onClick: (e) => {
|
|
299
|
+
if (!Q || M.current || !(e.target instanceof Element) || e.target.closest("button") || window.matchMedia?.(_)?.matches !== !0) return;
|
|
300
|
+
let t = e.currentTarget.getBoundingClientRect();
|
|
301
|
+
if (t.width <= 0) return;
|
|
302
|
+
let n = (e.clientX - t.left) / t.width;
|
|
303
|
+
n < v ? K() : n > .7 && q();
|
|
304
|
+
},
|
|
305
|
+
onTouchCancel: ae,
|
|
306
|
+
onTouchEnd: ie,
|
|
307
|
+
onTouchStart: re,
|
|
308
|
+
children: [
|
|
309
|
+
le && /* @__PURE__ */ o("button", {
|
|
310
|
+
className: "react-pic-gallery__control react-pic-gallery__control--previous",
|
|
311
|
+
type: "button",
|
|
312
|
+
onClick: K,
|
|
313
|
+
"aria-label": "Previous image",
|
|
314
|
+
children: /* @__PURE__ */ o(w, { direction: "left" })
|
|
315
|
+
}),
|
|
316
|
+
/* @__PURE__ */ o(l, {
|
|
317
|
+
src: U.src,
|
|
318
|
+
alt: U.alt,
|
|
319
|
+
eager: !0,
|
|
320
|
+
objectFit: "contain",
|
|
321
|
+
className: T("react-pic-gallery__lightbox-image", B ? `react-pic-gallery__lightbox-image--swipe-${B}` : void 0),
|
|
322
|
+
onAnimationEnd: oe
|
|
323
|
+
}, U.src),
|
|
324
|
+
ue && /* @__PURE__ */ o("button", {
|
|
325
|
+
className: "react-pic-gallery__control react-pic-gallery__control--next",
|
|
326
|
+
type: "button",
|
|
327
|
+
onClick: q,
|
|
328
|
+
"aria-label": "Next image",
|
|
329
|
+
children: /* @__PURE__ */ o(w, { direction: "right" })
|
|
330
|
+
})
|
|
331
|
+
]
|
|
332
|
+
}),
|
|
333
|
+
(p || U.caption) && /* @__PURE__ */ o("div", {
|
|
334
|
+
className: "react-pic-gallery__caption",
|
|
335
|
+
children: p ? p(Z) : U.caption
|
|
336
|
+
})
|
|
337
|
+
]
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
}), document.body);
|
|
341
|
+
}
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/lib/PicGallery.tsx
|
|
344
|
+
function D({ images: e, columns: t, rowHeight: n, className: r, galleryClassName: i, style: c, renderActions: l, renderCaption: u, renderControls: d, showCounter: p, showNavigation: m }) {
|
|
345
|
+
let [h, g] = a(null);
|
|
346
|
+
return /* @__PURE__ */ s("div", {
|
|
347
|
+
className: `react-pic-gallery ${r ?? ""}`.trim(),
|
|
348
|
+
style: c,
|
|
349
|
+
children: [/* @__PURE__ */ o(f, {
|
|
350
|
+
images: e,
|
|
351
|
+
columns: t,
|
|
352
|
+
rowHeight: n,
|
|
353
|
+
className: i,
|
|
354
|
+
onImageClick: g
|
|
355
|
+
}), /* @__PURE__ */ o(E, {
|
|
356
|
+
images: e,
|
|
357
|
+
index: h,
|
|
358
|
+
onIndexChange: g,
|
|
359
|
+
renderActions: l,
|
|
360
|
+
renderCaption: u,
|
|
361
|
+
renderControls: d,
|
|
362
|
+
showCounter: p,
|
|
363
|
+
showNavigation: m
|
|
364
|
+
})]
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
export { f as Gallery, E as Lightbox, D as PicGallery, D 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:100dvh;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{box-sizing:border-box;width:min(90rem,100vw - 2rem);min-width:0;max-width:100%;height:min(54rem,100dvh - 2rem);min-height:0;max-height:100%;animation:react-pic-gallery-rise-in var(--gallery-motion) ease both;flex-direction:column;display:flex}.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;flex:none;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}.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 pinch-zoom;flex:1 1 0;place-items:center;min-width:0;min-height:0;padding:.75rem;display:grid;position:relative;overflow:hidden}.react-pic-gallery__viewport--has-navigation{padding-inline:3.5rem}.react-pic-gallery__viewport--has-navigation .react-pic-gallery__lightbox-image{inset-inline:3.5rem}.react-pic-gallery__lightbox-image{pointer-events:none;width:auto;min-width:0;max-width:82rem;height:auto;min-height:0;max-height:none;animation:react-pic-gallery-image-in var(--gallery-motion) ease both;background:0 0;border-radius:0;grid-template-rows:minmax(0,1fr);grid-template-columns:minmax(0,1fr);place-items:center;margin-inline:auto;display:grid;position:absolute;inset:.75rem;overflow:visible}.react-pic-gallery__lightbox-image .react-pic-gallery__image-element{pointer-events:auto;touch-action:inherit;border-radius:var(--gallery-radius);background:0 0;width:auto;max-width:100%;height:auto;max-height:100%;object-fit:contain!important}.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{left:0}.react-pic-gallery__control--next{right:0}.react-pic-gallery__caption{color:#cbd5e1;text-align:center;flex:none;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}:where(dialog.react-pic-gallery__lightbox){padding:max(.375rem, env(safe-area-inset-top)) max(.375rem, env(safe-area-inset-right)) max(.375rem, env(safe-area-inset-bottom)) max(.375rem, env(safe-area-inset-left))}.react-pic-gallery__lightbox-content{width:min(90rem,100vw - .75rem);height:min(54rem,100dvh - .75rem)}.react-pic-gallery__toolbar,.react-pic-gallery__custom-controls{min-height:3rem}.react-pic-gallery__viewport{padding:.25rem}.react-pic-gallery__lightbox-image{inset:.25rem}.react-pic-gallery__viewport--has-navigation .react-pic-gallery__lightbox-image{inset-inline:.25rem}.react-pic-gallery__control--previous,.react-pic-gallery__control--next{display:none}}@media (height<=600px){:where(dialog.react-pic-gallery__lightbox){padding:max(.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(.25rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left))}.react-pic-gallery__lightbox-content{height:min(54rem,100dvh - .5rem)}.react-pic-gallery__toolbar,.react-pic-gallery__custom-controls{min-height:2.25rem}.react-pic-gallery__caption{max-height:4rem;padding:.35rem 0 0;font-size:.85rem}.react-pic-gallery__viewport{padding:.25rem}.react-pic-gallery__lightbox-image{inset:.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.1",
|
|
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 --dotfiles",
|
|
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;
|
package/dist/lib/main.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ImageObject, Options } from './models/models';
|
|
2
|
-
declare function PicGallery(props: {
|
|
3
|
-
imgList: ImageObject[];
|
|
4
|
-
options?: Options;
|
|
5
|
-
topCustomContent?: (props: {
|
|
6
|
-
imgObject: ImageObject;
|
|
7
|
-
closeLightbox: () => void;
|
|
8
|
-
}) => JSX.Element;
|
|
9
|
-
bottomCustomContent?: (props: {
|
|
10
|
-
imgObject: ImageObject;
|
|
11
|
-
closeLightbox: () => void;
|
|
12
|
-
}) => JSX.Element;
|
|
13
|
-
setExtLightboxChildren?: (imgLightbox: JSX.Element | undefined) => void;
|
|
14
|
-
}): JSX.Element;
|
|
15
|
-
export default PicGallery;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface ImageObject {
|
|
2
|
-
fullSrc: string;
|
|
3
|
-
thumbnailSrc: string;
|
|
4
|
-
[key: string]: string;
|
|
5
|
-
}
|
|
6
|
-
export interface Options {
|
|
7
|
-
externalLightbox?: boolean;
|
|
8
|
-
customLoadComponent?: () => JSX.Element;
|
|
9
|
-
hidePagination?: boolean;
|
|
10
|
-
rowHeight?: string | number;
|
|
11
|
-
/** Number of Pictures per row. Default: 3 */
|
|
12
|
-
picsPerRow?: number;
|
|
13
|
-
}
|
|
14
|
-
export declare const defaultOptions: {
|
|
15
|
-
downloadBtnDisplay: boolean;
|
|
16
|
-
descriptionBoxDisplay: boolean;
|
|
17
|
-
navigation: boolean;
|
|
18
|
-
};
|