UNPKG

react-gallery-layouts

Version:

React gallery layouts library with masonry, stack, grid, and justified layouts

1,119 lines (1,115 loc) 34.3 kB
import Ue, { useState as Re, useEffect as we, useMemo as G, useRef as Rr } from "react"; var me = { exports: {} }, ee = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ie; function wr() { if (Ie) return ee; Ie = 1; var o = Ue, i = Symbol.for("react.element"), a = Symbol.for("react.fragment"), l = Object.prototype.hasOwnProperty, _ = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, O = { key: !0, ref: !0, __self: !0, __source: !0 }; function W(x, p, C) { var h, m = {}, g = null, R = null; C !== void 0 && (g = "" + C), p.key !== void 0 && (g = "" + p.key), p.ref !== void 0 && (R = p.ref); for (h in p) l.call(p, h) && !O.hasOwnProperty(h) && (m[h] = p[h]); if (x && x.defaultProps) for (h in p = x.defaultProps, p) m[h] === void 0 && (m[h] = p[h]); return { $$typeof: i, type: x, key: g, ref: R, props: m, _owner: _.current }; } return ee.Fragment = a, ee.jsx = W, ee.jsxs = W, ee; } var re = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Le; function br() { return Le || (Le = 1, process.env.NODE_ENV !== "production" && function() { var o = Ue, i = Symbol.for("react.element"), a = Symbol.for("react.portal"), l = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), O = Symbol.for("react.profiler"), W = Symbol.for("react.provider"), x = Symbol.for("react.context"), p = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), m = Symbol.for("react.memo"), g = Symbol.for("react.lazy"), R = Symbol.for("react.offscreen"), f = Symbol.iterator, S = "@@iterator"; function F(e) { if (e === null || typeof e != "object") return null; var r = f && e[f] || e[S]; return typeof r == "function" ? r : null; } var d = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function n(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), s = 1; s < r; s++) t[s - 1] = arguments[s]; w("error", e, t); } } function w(e, r, t) { { var s = d.ReactDebugCurrentFrame, v = s.getStackAddendum(); v !== "" && (r += "%s", t = t.concat([v])); var b = t.map(function(u) { return String(u); }); b.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, b); } } var y = !1, E = !1, j = !1, U = !1, D = !1, P; P = Symbol.for("react.module.reference"); function I(e) { return !!(typeof e == "string" || typeof e == "function" || e === l || e === O || D || e === _ || e === C || e === h || U || e === R || y || E || j || typeof e == "object" && e !== null && (e.$$typeof === g || e.$$typeof === m || e.$$typeof === W || e.$$typeof === x || e.$$typeof === p || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === P || e.getModuleId !== void 0)); } function z(e, r, t) { var s = e.displayName; if (s) return s; var v = r.displayName || r.name || ""; return v !== "" ? t + "(" + v + ")" : t; } function H(e) { return e.displayName || "Context"; } function A(e) { if (e == null) return null; if (typeof e.tag == "number" && n("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case l: return "Fragment"; case a: return "Portal"; case O: return "Profiler"; case _: return "StrictMode"; case C: return "Suspense"; case h: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case x: var r = e; return H(r) + ".Consumer"; case W: var t = e; return H(t._context) + ".Provider"; case p: return z(e, e.render, "ForwardRef"); case m: var s = e.displayName || null; return s !== null ? s : A(e.type) || "Memo"; case g: { var v = e, b = v._payload, u = v._init; try { return A(u(b)); } catch { return null; } } } return null; } var M = Object.assign, B = 0, te, L, X, _e, Se, je, Te; function xe() { } xe.__reactDisabledLog = !0; function He() { { if (B === 0) { te = console.log, L = console.info, X = console.warn, _e = console.error, Se = console.group, je = console.groupCollapsed, Te = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: xe, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } B++; } } function Be() { { if (B--, B === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: M({}, e, { value: te }), info: M({}, e, { value: L }), warn: M({}, e, { value: X }), error: M({}, e, { value: _e }), group: M({}, e, { value: Se }), groupCollapsed: M({}, e, { value: je }), groupEnd: M({}, e, { value: Te }) }); } B < 0 && n("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var ce = d.ReactCurrentDispatcher, ue; function ne(e, r, t) { { if (ue === void 0) try { throw Error(); } catch (v) { var s = v.stack.trim().match(/\n( *(at )?)/); ue = s && s[1] || ""; } return ` ` + ue + e; } } var fe = !1, ae; { var Ke = typeof WeakMap == "function" ? WeakMap : Map; ae = new Ke(); } function Ce(e, r) { if (!e || fe) return ""; { var t = ae.get(e); if (t !== void 0) return t; } var s; fe = !0; var v = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var b; b = ce.current, ce.current = null, He(); try { if (r) { var u = function() { throw Error(); }; if (Object.defineProperty(u.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(u, []); } catch (Y) { s = Y; } Reflect.construct(e, [], u); } else { try { u.call(); } catch (Y) { s = Y; } e.call(u.prototype); } } else { try { throw Error(); } catch (Y) { s = Y; } e(); } } catch (Y) { if (Y && s && typeof Y.stack == "string") { for (var c = Y.stack.split(` `), N = s.stack.split(` `), T = c.length - 1, k = N.length - 1; T >= 1 && k >= 0 && c[T] !== N[k]; ) k--; for (; T >= 1 && k >= 0; T--, k--) if (c[T] !== N[k]) { if (T !== 1 || k !== 1) do if (T--, k--, k < 0 || c[T] !== N[k]) { var V = ` ` + c[T].replace(" at new ", " at "); return e.displayName && V.includes("<anonymous>") && (V = V.replace("<anonymous>", e.displayName)), typeof e == "function" && ae.set(e, V), V; } while (T >= 1 && k >= 0); break; } } } finally { fe = !1, ce.current = b, Be(), Error.prepareStackTrace = v; } var q = e ? e.displayName || e.name : "", K = q ? ne(q) : ""; return typeof e == "function" && ae.set(e, K), K; } function Je(e, r, t) { return Ce(e, !1); } function qe(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function ie(e, r, t) { if (e == null) return ""; if (typeof e == "function") return Ce(e, qe(e)); if (typeof e == "string") return ne(e); switch (e) { case C: return ne("Suspense"); case h: return ne("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case p: return Je(e.render); case m: return ie(e.type, r, t); case g: { var s = e, v = s._payload, b = s._init; try { return ie(b(v), r, t); } catch { } } } return ""; } var Z = Object.prototype.hasOwnProperty, Pe = {}, ke = d.ReactDebugCurrentFrame; function oe(e) { if (e) { var r = e._owner, t = ie(e.type, e._source, r ? r.type : null); ke.setExtraStackFrame(t); } else ke.setExtraStackFrame(null); } function Xe(e, r, t, s, v) { { var b = Function.call.bind(Z); for (var u in e) if (b(e, u)) { var c = void 0; try { if (typeof e[u] != "function") { var N = Error((s || "React class") + ": " + t + " type `" + u + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[u] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw N.name = "Invariant Violation", N; } c = e[u](r, u, s, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (T) { c = T; } c && !(c instanceof Error) && (oe(v), n("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", s || "React class", t, u, typeof c), oe(null)), c instanceof Error && !(c.message in Pe) && (Pe[c.message] = !0, oe(v), n("Failed %s type: %s", t, c.message), oe(null)); } } } var Ze = Array.isArray; function de(e) { return Ze(e); } function Qe(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function er(e) { try { return $e(e), !1; } catch { return !0; } } function $e(e) { return "" + e; } function Oe(e) { if (er(e)) return n("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Qe(e)), $e(e); } var Q = d.ReactCurrentOwner, rr = { key: !0, ref: !0, __self: !0, __source: !0 }, We, Ae, ve; ve = {}; function tr(e) { if (Z.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function nr(e) { if (Z.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function ar(e, r) { if (typeof e.ref == "string" && Q.current && r && Q.current.stateNode !== r) { var t = A(Q.current.type); ve[t] || (n('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', A(Q.current.type), e.ref), ve[t] = !0); } } function ir(e, r) { { var t = function() { We || (We = !0, n("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } } function or(e, r) { { var t = function() { Ae || (Ae = !0, n("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "ref", { get: t, configurable: !0 }); } } var sr = function(e, r, t, s, v, b, u) { var c = { // This tag allows us to uniquely identify this as a React Element $$typeof: i, // Built-in properties that belong on the element type: e, key: r, ref: t, props: u, // Record the component responsible for creating this element. _owner: b }; return c._store = {}, Object.defineProperty(c._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(c, "_self", { configurable: !1, enumerable: !1, writable: !1, value: s }), Object.defineProperty(c, "_source", { configurable: !1, enumerable: !1, writable: !1, value: v }), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c; }; function lr(e, r, t, s, v) { { var b, u = {}, c = null, N = null; t !== void 0 && (Oe(t), c = "" + t), nr(r) && (Oe(r.key), c = "" + r.key), tr(r) && (N = r.ref, ar(r, v)); for (b in r) Z.call(r, b) && !rr.hasOwnProperty(b) && (u[b] = r[b]); if (e && e.defaultProps) { var T = e.defaultProps; for (b in T) u[b] === void 0 && (u[b] = T[b]); } if (c || N) { var k = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; c && ir(u, k), N && or(u, k); } return sr(e, c, N, v, s, Q.current, u); } } var he = d.ReactCurrentOwner, Fe = d.ReactDebugCurrentFrame; function J(e) { if (e) { var r = e._owner, t = ie(e.type, e._source, r ? r.type : null); Fe.setExtraStackFrame(t); } else Fe.setExtraStackFrame(null); } var pe; pe = !1; function ge(e) { return typeof e == "object" && e !== null && e.$$typeof === i; } function De() { { if (he.current) { var e = A(he.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function cr(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var Me = {}; function ur(e) { { var r = De(); if (!r) { var t = typeof e == "string" ? e : e.displayName || e.name; t && (r = ` Check the top-level render call using <` + t + ">."); } return r; } } function Ne(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = ur(r); if (Me[t]) return; Me[t] = !0; var s = ""; e && e._owner && e._owner !== he.current && (s = " It was passed a child from " + A(e._owner.type) + "."), J(e), n('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, s), J(null); } } function Ye(e, r) { { if (typeof e != "object") return; if (de(e)) for (var t = 0; t < e.length; t++) { var s = e[t]; ge(s) && Ne(s, r); } else if (ge(e)) e._store && (e._store.validated = !0); else if (e) { var v = F(e); if (typeof v == "function" && v !== e.entries) for (var b = v.call(e), u; !(u = b.next()).done; ) ge(u.value) && Ne(u.value, r); } } } function fr(e) { { var r = e.type; if (r == null || typeof r == "string") return; var t; if (typeof r == "function") t = r.propTypes; else if (typeof r == "object" && (r.$$typeof === p || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === m)) t = r.propTypes; else return; if (t) { var s = A(r); Xe(t, e.props, "prop", s, e); } else if (r.PropTypes !== void 0 && !pe) { pe = !0; var v = A(r); n("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", v || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && n("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function dr(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var s = r[t]; if (s !== "children" && s !== "key") { J(e), n("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", s), J(null); break; } } e.ref !== null && (J(e), n("Invalid attribute `ref` supplied to `React.Fragment`."), J(null)); } } var ze = {}; function Ge(e, r, t, s, v, b) { { var u = I(e); if (!u) { var c = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (c += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var N = cr(v); N ? c += N : c += De(); var T; e === null ? T = "null" : de(e) ? T = "array" : e !== void 0 && e.$$typeof === i ? (T = "<" + (A(e.type) || "Unknown") + " />", c = " Did you accidentally export a JSX literal instead of a component?") : T = typeof e, n("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", T, c); } var k = lr(e, r, t, v, b); if (k == null) return k; if (u) { var V = r.children; if (V !== void 0) if (s) if (de(V)) { for (var q = 0; q < V.length; q++) Ye(V[q], e); Object.freeze && Object.freeze(V); } else n("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else Ye(V, e); } if (Z.call(r, "key")) { var K = A(e), Y = Object.keys(r).filter(function(mr) { return mr !== "key"; }), ye = Y.length > 0 ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!ze[K + ye]) { var yr = Y.length > 0 ? "{" + Y.join(": ..., ") + ": ...}" : "{}"; n(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, ye, K, yr, K), ze[K + ye] = !0; } } return e === l ? dr(k) : fr(k), k; } } function vr(e, r, t) { return Ge(e, r, t, !0); } function hr(e, r, t) { return Ge(e, r, t, !1); } var pr = hr, gr = vr; re.Fragment = l, re.jsx = pr, re.jsxs = gr; }()), re; } process.env.NODE_ENV === "production" ? me.exports = wr() : me.exports = br(); var $ = me.exports; const Er = (o, i) => o / i, be = (o) => o.map((i) => i.aspectRatio ? i : i.width && i.height ? { ...i, aspectRatio: Er(i.width, i.height) } : { ...i, aspectRatio: 1 }), _r = (o, i) => o * i, Ee = (o = 3, i) => { if (typeof o == "number") return o; if (typeof window > "u") return o.default || 3; const a = Object.keys(o).filter((l) => l !== "default").map(Number).sort((l, _) => l - _); for (let l = a.length - 1; l >= 0; l--) if (i.width >= a[l]) return o[a[l]]; return o.default || 3; }, se = (o = 10, i) => { if (typeof o == "number") return o; if (typeof window > "u") return o.default || 10; const a = Object.keys(o).filter((l) => l !== "default").map(Number).sort((l, _) => l - _); for (let l = a.length - 1; l >= 0; l--) if (i.width >= a[l]) return o[a[l]]; return o.default || 10; }, Sr = (o, i) => { let a; return (...l) => { clearTimeout(a), a = setTimeout(() => o(...l), i); }; }, le = () => { const [o, i] = Re({ width: typeof window < "u" ? window.innerWidth : 0, height: typeof window < "u" ? window.innerHeight : 0 }); return we(() => { if (typeof window > "u") return; const a = Sr(() => { i({ width: window.innerWidth, height: window.innerHeight }); }, 300); return window.addEventListener("resize", a), a(), () => window.removeEventListener("resize", a); }, []), o; }; const jr = ({ item: o, index: i, itemHeight: a, aspectRatio: l, gutterSize: _, itemClassName: O = "", itemStyle: W = {}, itemWidth: x, onItemClick: p, renderItem: C, lazyLoad: h = !1, maxColSpan: m = 12 }) => { const g = o.colSpan || 1, R = o.rowSpan || 1, [f, S] = Re(a); we(() => { const d = o.aspectRatio || l; S(d ? x / d : a); }, [a, l, o.aspectRatio, x]); const F = (d, n) => /* @__PURE__ */ $.jsx( "img", { src: d.src, alt: d.alt || `Gallery item ${n}`, loading: h ? "lazy" : void 0 } ); return /* @__PURE__ */ $.jsx( "div", { className: `gallery-item gallery-item-grid ${O}`, style: { gridColumn: `span ${Math.min(g, m)}`, gridRow: `span ${R}`, height: f * R + _ * (R - 1), ...W }, onClick: p ? () => p(o, i) : void 0, children: C ? C(o, h, i) : F(o, i) } ); }, Tr = ({ items: o, columns: i = 3, gutter: a = 10, itemHeight: l = 200, aspectRatio: _, className: O = "", containerWidth: W, style: x = {}, itemClassName: p = "", itemStyle: C = {}, lazyLoad: h = !1, onItemClick: m, renderItem: g }) => { const R = le(), f = G(() => Ee(i, R), [i, R]), S = G(() => se(a, R), [a, R]), F = G(() => (W - S * (f - 1)) / f, [W, S, f]); return /* @__PURE__ */ $.jsx( "div", { className: `gallery-layout layout-grid ${O}`, style: { gridTemplateColumns: `repeat(${f}, 1fr)`, gap: S, ...x }, children: o.map((d, n) => /* @__PURE__ */ $.jsx( jr, { item: d, index: n, itemWidth: F, itemHeight: l, aspectRatio: _, gutterSize: S, itemClassName: p, itemStyle: C, onItemClick: m, renderItem: g, lazyLoad: h, maxColSpan: f }, d.id || `grid-item-${n}` )) } ); }, xr = ({ items: o, targetRowHeight: i = 200, containerWidth: a, maxRowHeight: l = 400, containerPadding: _ = 0, gutter: O = 10, renderItem: W, className: x = "", style: p = {}, itemClassName: C = "", itemStyle: h = {}, onItemClick: m, lazyLoad: g = !1 }) => { const R = le(), f = G(() => be(o), [o]), S = G(() => se(O, R), [O, R]), F = G(() => { if (!a) return []; const n = a - 2 * _, w = []; let y = [], E = 0; if (f.forEach((j) => { if (!j.aspectRatio) return; const U = j.colSpan || 1, D = j.aspectRatio * U, P = _r(i, D), I = { ...j, calculatedWidth: P, calculatedHeight: i }; if (y.length > 0 && E + P + S * y.length > n) { const z = E + S * (y.length - 1), H = Math.min(n / z, l / i), A = y.map((M) => ({ ...M, calculatedWidth: M.calculatedWidth * H, calculatedHeight: M.calculatedHeight * H })); w.push({ items: A, width: z * H }), y = [I], E = P; } else y.push(I), E += P; }), y.length > 0) { const j = E + S * (y.length - 1), U = Math.min(n / j, l / i), D = y.map((P) => ({ ...P, calculatedWidth: P.calculatedWidth * U, calculatedHeight: P.calculatedHeight * U })); w.push({ items: D, width: j * U }); } return w; }, [f, a, i, l, _, O]), d = (n, w) => /* @__PURE__ */ $.jsx( "img", { src: n.src, alt: n.alt || `Gallery item ${w}`, loading: g ? "lazy" : void 0 } ); return /* @__PURE__ */ $.jsx( "div", { className: `gallery-layout layout-justified ${x}`, style: { padding: _, ...p }, children: F.map((n, w) => /* @__PURE__ */ $.jsx( "div", { className: "gallery-row", style: { marginBottom: w < F.length - 1 ? S : 0 }, children: n.items.map((y, E) => { const j = y.id || `justified-item-${w}-${E}`; return /* @__PURE__ */ $.jsx( "div", { className: `gallery-item gallery-item-justified ${C}`, style: { width: y.calculatedWidth, height: y.calculatedHeight, marginRight: E < n.items.length - 1 ? S : 0, ...h }, onClick: m ? () => m(y, E) : void 0, children: W ? W(y, g, E) : d(y, E) }, j ); }) }, `row-${w}` )) } ); }, Ve = ({ items: o, containerWidth: i, columns: a = 3, gutter: l = 10, renderItem: _, className: O = "", style: W = {}, itemClassName: x = "", itemStyle: p = {}, onItemClick: C, lazyLoad: h = !1 }) => { const m = G(() => be(o), [o]), g = le(), R = G(() => Ee(a, g), [a, g]), f = G(() => se(l, g), [l, g]), { itemsWithPosition: S, containerHeight: F } = G(() => { const n = Array(R).fill(0); let w = 0; const y = i || g.width, E = Math.floor((y - (R - 1) * f) / R), j = f; return { itemsWithPosition: m.map((D) => { const P = Math.min(D.colSpan || 1, R); let I = 0, z = 1 / 0; for (let L = 0; L <= R - P; L++) { const X = Math.max(...n.slice(L, L + P)); X < z && (z = X, I = L); } const H = D.height && D.width ? D.height / D.width : 1, A = E * P + (P - 1) * j, M = Math.round(H * E); for (let L = I; L < I + P; L++) n[L] = z + M + j; w = Math.max(w, z + M + j); const B = I * (E + j), te = z; return { ...D, position: { left: `${B}px`, top: `${te}px`, width: `${A}px`, height: `${M}px` } }; }), containerHeight: w }; }, [m, R, f, i, g.width]), d = (n, w) => /* @__PURE__ */ $.jsx( "img", { src: n.src, alt: n.alt || `Gallery item ${w}`, loading: h ? "lazy" : void 0 } ); return /* @__PURE__ */ $.jsx( "div", { className: `gallery-layout layout-masonry ${O}`, style: { height: `${F}px`, width: i ? `${i}px` : "100%", ...W }, children: S.map((n, w) => { const y = n.id || `item-${w}`; return /* @__PURE__ */ $.jsx( "div", { className: `gallery-item gallery-item-masonry ${x}`, style: { position: "absolute", ...n.position, ...p }, onClick: C ? () => C(n, w) : void 0, children: _ ? _(n, h, w) : d(n, w) }, y ); }) } ); }, Cr = ({ items: o, gutter: i = 10, columns: a = 3, maxWidth: l = "100%", alignment: _ = "flex-start", renderItem: O, className: W = "", style: x = {}, itemClassName: p = "", itemStyle: C = {}, onItemClick: h, lazyLoad: m = !1 }) => { const g = le(), R = G(() => be(o), [o]), f = G(() => Ee(a, g), [a, g]), S = G(() => se(i, g), [i, g]), F = (d, n) => /* @__PURE__ */ $.jsx( "img", { src: d.src, alt: d.alt || `Gallery item ${n}`, loading: m ? "lazy" : void 0 } ); return /* @__PURE__ */ $.jsx( "div", { className: `gallery-layout layout-stack ${W}`, style: { width: l, gap: S, alignItems: _, ...x }, children: R.map((d, n) => { const w = d.id || `stack-item-${n}`, y = Math.min(d.colSpan || 1, f), E = d.rowSpan || 1, j = `calc(${100 / f * y}% - ${(f - y) * S / f}px)`; return /* @__PURE__ */ $.jsx( "div", { className: `gallery-item gallery-item-stack ${p}`, style: { width: "100%", height: E > 1 ? `calc(100% + ${S}px * ${E - 1})` : "100%", flexBasis: j, flexGrow: 0, flexShrink: 0, marginBottom: E > 1 ? `calc(${S}px * ${E - 1})` : 0, ...C }, onClick: h ? () => h(d, n) : void 0, children: O ? O(d, m, n) : F(d, n) }, w ); }) } ); }, kr = ({ items: o, layout: i = "masonry", layoutOptions: a = {}, className: l = "", style: _ = {}, itemClassName: O = "", itemStyle: W = {}, lazyLoad: x = !1, renderItem: p, onItemClick: C }) => { const h = Rr(null), [m, g] = Re(0); we(() => { const f = () => { h.current && g(h.current.clientWidth); }; return f(), window.addEventListener("resize", f), () => { window.removeEventListener("resize", f); }; }, []); const R = () => { var S, F, d, n, w, y, E, j, U, D, P, I, z, H, A; const f = { items: o, renderItem: p, className: l, style: _, itemClassName: O, itemStyle: W, onItemClick: C, lazyLoad: x }; switch (i) { case "masonry": return /* @__PURE__ */ $.jsx( Ve, { ...f, containerWidth: m, columns: (S = a.masonry) == null ? void 0 : S.columns, gutter: (F = a.masonry) == null ? void 0 : F.gutter } ); case "grid": return /* @__PURE__ */ $.jsx( Tr, { ...f, containerWidth: m, columns: (d = a.grid) == null ? void 0 : d.columns, gutter: (n = a.grid) == null ? void 0 : n.gutter, itemHeight: (w = a.grid) == null ? void 0 : w.itemHeight, aspectRatio: (y = a.grid) == null ? void 0 : y.aspectRatio } ); case "stack": return /* @__PURE__ */ $.jsx( Cr, { ...f, columns: (E = a.stack) == null ? void 0 : E.columns, gutter: (j = a.stack) == null ? void 0 : j.gutter, maxWidth: (U = a.stack) == null ? void 0 : U.maxWidth } ); case "justified": return /* @__PURE__ */ $.jsx( xr, { ...f, containerWidth: m, targetRowHeight: (D = a.justified) == null ? void 0 : D.targetRowHeight, maxRowHeight: (P = a.justified) == null ? void 0 : P.maxRowHeight, containerPadding: (I = a.justified) == null ? void 0 : I.containerPadding, gutter: (z = a.justified) == null ? void 0 : z.gutter } ); default: return /* @__PURE__ */ $.jsx( Ve, { ...f, containerWidth: m, columns: (H = a.masonry) == null ? void 0 : H.columns, gutter: (A = a.masonry) == null ? void 0 : A.gutter } ); } }; return /* @__PURE__ */ $.jsx( "div", { ref: h, className: `gallery-container ${l}`, style: _, children: R() } ); }; export { kr as Gallery, Tr as GridGallery, xr as JustifiedGallery, Ve as MasonryGallery, Cr as StackGallery, Ee as getColumnsCount, se as getGutter }; //# sourceMappingURL=react-gallery-layouts.mjs.map