UNPKG

react-gallery-layouts

Version:

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

34 lines (30 loc) 22.1 kB
(function(I,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],E):(I=typeof globalThis<"u"?globalThis:I||self,E(I.ReactGalleryLayouts={},I.React))})(this,function(I,E){"use strict";var fe={exports:{}},Q={};/** * @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 _e;function Be(){if(_e)return Q;_e=1;var o=E,i=Symbol.for("react.element"),a=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,S=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,M={key:!0,ref:!0,__self:!0,__source:!0};function A(P,p,k){var h,m={},g=null,R=null;k!==void 0&&(g=""+k),p.key!==void 0&&(g=""+p.key),p.ref!==void 0&&(R=p.ref);for(h in p)l.call(p,h)&&!M.hasOwnProperty(h)&&(m[h]=p[h]);if(P&&P.defaultProps)for(h in p=P.defaultProps,p)m[h]===void 0&&(m[h]=p[h]);return{$$typeof:i,type:P,key:g,ref:R,props:m,_owner:S.current}}return Q.Fragment=a,Q.jsx=A,Q.jsxs=A,Q}var q={};/** * @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 Se;function Je(){return Se||(Se=1,process.env.NODE_ENV!=="production"&&function(){var o=E,i=Symbol.for("react.element"),a=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),A=Symbol.for("react.provider"),P=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),k=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,j="@@iterator";function D(e){if(e===null||typeof e!="object")return null;var r=f&&e[f]||e[j];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,_=!1,T=!1,H=!1,G=!1,O;O=Symbol.for("react.module.reference");function V(e){return!!(typeof e=="string"||typeof e=="function"||e===l||e===M||G||e===S||e===k||e===h||H||e===R||y||_||T||typeof e=="object"&&e!==null&&(e.$$typeof===g||e.$$typeof===m||e.$$typeof===A||e.$$typeof===P||e.$$typeof===p||e.$$typeof===O||e.getModuleId!==void 0))}function L(e,r,t){var s=e.displayName;if(s)return s;var v=r.displayName||r.name||"";return v!==""?t+"("+v+")":t}function B(e){return e.displayName||"Context"}function F(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 M:return"Profiler";case S:return"StrictMode";case k:return"Suspense";case h:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case P:var r=e;return B(r)+".Consumer";case A:var t=e;return B(t._context)+".Provider";case p:return L(e,e.render,"ForwardRef");case m:var s=e.displayName||null;return s!==null?s:F(e.type)||"Memo";case g:{var v=e,b=v._payload,u=v._init;try{return F(u(b))}catch{return null}}}return null}var N=Object.assign,J=0,oe,U,re,xe,Pe,ke,Oe;function We(){}We.__reactDisabledLog=!0;function er(){{if(J===0){oe=console.log,U=console.info,re=console.warn,xe=console.error,Pe=console.group,ke=console.groupCollapsed,Oe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:We,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}J++}}function rr(){{if(J--,J===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},e,{value:oe}),info:N({},e,{value:U}),warn:N({},e,{value:re}),error:N({},e,{value:xe}),group:N({},e,{value:Pe}),groupCollapsed:N({},e,{value:ke}),groupEnd:N({},e,{value:Oe})})}J<0&&n("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var he=d.ReactCurrentDispatcher,pe;function se(e,r,t){{if(pe===void 0)try{throw Error()}catch(v){var s=v.stack.trim().match(/\n( *(at )?)/);pe=s&&s[1]||""}return` `+pe+e}}var ge=!1,le;{var tr=typeof WeakMap=="function"?WeakMap:Map;le=new tr}function Me(e,r){if(!e||ge)return"";{var t=le.get(e);if(t!==void 0)return t}var s;ge=!0;var v=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var b;b=he.current,he.current=null,er();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(z){s=z}Reflect.construct(e,[],u)}else{try{u.call()}catch(z){s=z}e.call(u.prototype)}}else{try{throw Error()}catch(z){s=z}e()}}catch(z){if(z&&s&&typeof z.stack=="string"){for(var c=z.stack.split(` `),Y=s.stack.split(` `),C=c.length-1,W=Y.length-1;C>=1&&W>=0&&c[C]!==Y[W];)W--;for(;C>=1&&W>=0;C--,W--)if(c[C]!==Y[W]){if(C!==1||W!==1)do if(C--,W--,W<0||c[C]!==Y[W]){var $=` `+c[C].replace(" at new "," at ");return e.displayName&&$.includes("<anonymous>")&&($=$.replace("<anonymous>",e.displayName)),typeof e=="function"&&le.set(e,$),$}while(C>=1&&W>=0);break}}}finally{ge=!1,he.current=b,rr(),Error.prepareStackTrace=v}var Z=e?e.displayName||e.name:"",K=Z?se(Z):"";return typeof e=="function"&&le.set(e,K),K}function nr(e,r,t){return Me(e,!1)}function ar(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function ce(e,r,t){if(e==null)return"";if(typeof e=="function")return Me(e,ar(e));if(typeof e=="string")return se(e);switch(e){case k:return se("Suspense");case h:return se("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case p:return nr(e.render);case m:return ce(e.type,r,t);case g:{var s=e,v=s._payload,b=s._init;try{return ce(b(v),r,t)}catch{}}}return""}var te=Object.prototype.hasOwnProperty,Ae={},Fe=d.ReactDebugCurrentFrame;function ue(e){if(e){var r=e._owner,t=ce(e.type,e._source,r?r.type:null);Fe.setExtraStackFrame(t)}else Fe.setExtraStackFrame(null)}function ir(e,r,t,s,v){{var b=Function.call.bind(te);for(var u in e)if(b(e,u)){var c=void 0;try{if(typeof e[u]!="function"){var Y=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 Y.name="Invariant Violation",Y}c=e[u](r,u,s,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(C){c=C}c&&!(c instanceof Error)&&(ue(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),ue(null)),c instanceof Error&&!(c.message in Ae)&&(Ae[c.message]=!0,ue(v),n("Failed %s type: %s",t,c.message),ue(null))}}}var or=Array.isArray;function ye(e){return or(e)}function sr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function lr(e){try{return De(e),!1}catch{return!0}}function De(e){return""+e}function Ge(e){if(lr(e))return n("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",sr(e)),De(e)}var ne=d.ReactCurrentOwner,cr={key:!0,ref:!0,__self:!0,__source:!0},Ne,Ye,me;me={};function ur(e){if(te.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function fr(e){if(te.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function dr(e,r){if(typeof e.ref=="string"&&ne.current&&r&&ne.current.stateNode!==r){var t=F(ne.current.type);me[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',F(ne.current.type),e.ref),me[t]=!0)}}function vr(e,r){{var t=function(){Ne||(Ne=!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 hr(e,r){{var t=function(){Ye||(Ye=!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 pr=function(e,r,t,s,v,b,u){var c={$$typeof:i,type:e,key:r,ref:t,props:u,_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 gr(e,r,t,s,v){{var b,u={},c=null,Y=null;t!==void 0&&(Ge(t),c=""+t),fr(r)&&(Ge(r.key),c=""+r.key),ur(r)&&(Y=r.ref,dr(r,v));for(b in r)te.call(r,b)&&!cr.hasOwnProperty(b)&&(u[b]=r[b]);if(e&&e.defaultProps){var C=e.defaultProps;for(b in C)u[b]===void 0&&(u[b]=C[b])}if(c||Y){var W=typeof e=="function"?e.displayName||e.name||"Unknown":e;c&&vr(u,W),Y&&hr(u,W)}return pr(e,c,Y,v,s,ne.current,u)}}var Re=d.ReactCurrentOwner,ze=d.ReactDebugCurrentFrame;function X(e){if(e){var r=e._owner,t=ce(e.type,e._source,r?r.type:null);ze.setExtraStackFrame(t)}else ze.setExtraStackFrame(null)}var we;we=!1;function be(e){return typeof e=="object"&&e!==null&&e.$$typeof===i}function Ie(){{if(Re.current){var e=F(Re.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function yr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Le={};function mr(e){{var r=Ie();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 Ve(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=mr(r);if(Le[t])return;Le[t]=!0;var s="";e&&e._owner&&e._owner!==Re.current&&(s=" It was passed a child from "+F(e._owner.type)+"."),X(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),X(null)}}function Ue(e,r){{if(typeof e!="object")return;if(ye(e))for(var t=0;t<e.length;t++){var s=e[t];be(s)&&Ve(s,r)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var v=D(e);if(typeof v=="function"&&v!==e.entries)for(var b=v.call(e),u;!(u=b.next()).done;)be(u.value)&&Ve(u.value,r)}}}function Rr(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||r.$$typeof===m))t=r.propTypes;else return;if(t){var s=F(r);ir(t,e.props,"prop",s,e)}else if(r.PropTypes!==void 0&&!we){we=!0;var v=F(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 wr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var s=r[t];if(s!=="children"&&s!=="key"){X(e),n("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),X(null);break}}e.ref!==null&&(X(e),n("Invalid attribute `ref` supplied to `React.Fragment`."),X(null))}}var $e={};function He(e,r,t,s,v,b){{var u=V(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 Y=yr(v);Y?c+=Y:c+=Ie();var C;e===null?C="null":ye(e)?C="array":e!==void 0&&e.$$typeof===i?(C="<"+(F(e.type)||"Unknown")+" />",c=" Did you accidentally export a JSX literal instead of a component?"):C=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",C,c)}var W=gr(e,r,t,v,b);if(W==null)return W;if(u){var $=r.children;if($!==void 0)if(s)if(ye($)){for(var Z=0;Z<$.length;Z++)Ue($[Z],e);Object.freeze&&Object.freeze($)}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 Ue($,e)}if(te.call(r,"key")){var K=F(e),z=Object.keys(r).filter(function(Tr){return Tr!=="key"}),Ee=z.length>0?"{key: someKey, "+z.join(": ..., ")+": ...}":"{key: someKey}";if(!$e[K+Ee]){var jr=z.length>0?"{"+z.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} />`,Ee,K,jr,K),$e[K+Ee]=!0}}return e===l?wr(W):Rr(W),W}}function br(e,r,t){return He(e,r,t,!0)}function Er(e,r,t){return He(e,r,t,!1)}var _r=Er,Sr=br;q.Fragment=l,q.jsx=_r,q.jsxs=Sr}()),q}process.env.NODE_ENV==="production"?fe.exports=Be():fe.exports=Je();var x=fe.exports;const Ke=(o,i)=>o/i,de=o=>o.map(i=>i.aspectRatio?i:i.width&&i.height?{...i,aspectRatio:Ke(i.width,i.height)}:{...i,aspectRatio:1}),Xe=(o,i)=>o*i,ae=(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,S)=>l-S);for(let l=a.length-1;l>=0;l--)if(i.width>=a[l])return o[a[l]];return o.default||3},ee=(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,S)=>l-S);for(let l=a.length-1;l>=0;l--)if(i.width>=a[l])return o[a[l]];return o.default||10},Ze=(o,i)=>{let a;return(...l)=>{clearTimeout(a),a=setTimeout(()=>o(...l),i)}},ie=()=>{const[o,i]=E.useState({width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0});return E.useEffect(()=>{if(typeof window>"u")return;const a=Ze(()=>{i({width:window.innerWidth,height:window.innerHeight})},300);return window.addEventListener("resize",a),a(),()=>window.removeEventListener("resize",a)},[]),o},Cr="",Qe=({item:o,index:i,itemHeight:a,aspectRatio:l,gutterSize:S,itemClassName:M="",itemStyle:A={},itemWidth:P,onItemClick:p,renderItem:k,lazyLoad:h=!1,maxColSpan:m=12})=>{const g=o.colSpan||1,R=o.rowSpan||1,[f,j]=E.useState(a);E.useEffect(()=>{const d=o.aspectRatio||l;j(d?P/d:a)},[a,l,o.aspectRatio,P]);const D=(d,n)=>x.jsx("img",{src:d.src,alt:d.alt||`Gallery item ${n}`,loading:h?"lazy":void 0});return x.jsx("div",{className:`gallery-item gallery-item-grid ${M}`,style:{gridColumn:`span ${Math.min(g,m)}`,gridRow:`span ${R}`,height:f*R+S*(R-1),...A},onClick:p?()=>p(o,i):void 0,children:k?k(o,h,i):D(o,i)})},je=({items:o,columns:i=3,gutter:a=10,itemHeight:l=200,aspectRatio:S,className:M="",containerWidth:A,style:P={},itemClassName:p="",itemStyle:k={},lazyLoad:h=!1,onItemClick:m,renderItem:g})=>{const R=ie(),f=E.useMemo(()=>ae(i,R),[i,R]),j=E.useMemo(()=>ee(a,R),[a,R]),D=E.useMemo(()=>(A-j*(f-1))/f,[A,j,f]);return x.jsx("div",{className:`gallery-layout layout-grid ${M}`,style:{gridTemplateColumns:`repeat(${f}, 1fr)`,gap:j,...P},children:o.map((d,n)=>x.jsx(Qe,{item:d,index:n,itemWidth:D,itemHeight:l,aspectRatio:S,gutterSize:j,itemClassName:p,itemStyle:k,onItemClick:m,renderItem:g,lazyLoad:h,maxColSpan:f},d.id||`grid-item-${n}`))})},Te=({items:o,targetRowHeight:i=200,containerWidth:a,maxRowHeight:l=400,containerPadding:S=0,gutter:M=10,renderItem:A,className:P="",style:p={},itemClassName:k="",itemStyle:h={},onItemClick:m,lazyLoad:g=!1})=>{const R=ie(),f=E.useMemo(()=>de(o),[o]),j=E.useMemo(()=>ee(M,R),[M,R]),D=E.useMemo(()=>{if(!a)return[];const n=a-2*S,w=[];let y=[],_=0;if(f.forEach(T=>{if(!T.aspectRatio)return;const H=T.colSpan||1,G=T.aspectRatio*H,O=Xe(i,G),V={...T,calculatedWidth:O,calculatedHeight:i};if(y.length>0&&_+O+j*y.length>n){const L=_+j*(y.length-1),B=Math.min(n/L,l/i),F=y.map(N=>({...N,calculatedWidth:N.calculatedWidth*B,calculatedHeight:N.calculatedHeight*B}));w.push({items:F,width:L*B}),y=[V],_=O}else y.push(V),_+=O}),y.length>0){const T=_+j*(y.length-1),H=Math.min(n/T,l/i),G=y.map(O=>({...O,calculatedWidth:O.calculatedWidth*H,calculatedHeight:O.calculatedHeight*H}));w.push({items:G,width:T*H})}return w},[f,a,i,l,S,M]),d=(n,w)=>x.jsx("img",{src:n.src,alt:n.alt||`Gallery item ${w}`,loading:g?"lazy":void 0});return x.jsx("div",{className:`gallery-layout layout-justified ${P}`,style:{padding:S,...p},children:D.map((n,w)=>x.jsx("div",{className:"gallery-row",style:{marginBottom:w<D.length-1?j:0},children:n.items.map((y,_)=>{const T=y.id||`justified-item-${w}-${_}`;return x.jsx("div",{className:`gallery-item gallery-item-justified ${k}`,style:{width:y.calculatedWidth,height:y.calculatedHeight,marginRight:_<n.items.length-1?j:0,...h},onClick:m?()=>m(y,_):void 0,children:A?A(y,g,_):d(y,_)},T)})},`row-${w}`))})},ve=({items:o,containerWidth:i,columns:a=3,gutter:l=10,renderItem:S,className:M="",style:A={},itemClassName:P="",itemStyle:p={},onItemClick:k,lazyLoad:h=!1})=>{const m=E.useMemo(()=>de(o),[o]),g=ie(),R=E.useMemo(()=>ae(a,g),[a,g]),f=E.useMemo(()=>ee(l,g),[l,g]),{itemsWithPosition:j,containerHeight:D}=E.useMemo(()=>{const n=Array(R).fill(0);let w=0;const y=i||g.width,_=Math.floor((y-(R-1)*f)/R),T=f;return{itemsWithPosition:m.map(G=>{const O=Math.min(G.colSpan||1,R);let V=0,L=1/0;for(let U=0;U<=R-O;U++){const re=Math.max(...n.slice(U,U+O));re<L&&(L=re,V=U)}const B=G.height&&G.width?G.height/G.width:1,F=_*O+(O-1)*T,N=Math.round(B*_);for(let U=V;U<V+O;U++)n[U]=L+N+T;w=Math.max(w,L+N+T);const J=V*(_+T),oe=L;return{...G,position:{left:`${J}px`,top:`${oe}px`,width:`${F}px`,height:`${N}px`}}}),containerHeight:w}},[m,R,f,i,g.width]),d=(n,w)=>x.jsx("img",{src:n.src,alt:n.alt||`Gallery item ${w}`,loading:h?"lazy":void 0});return x.jsx("div",{className:`gallery-layout layout-masonry ${M}`,style:{height:`${D}px`,width:i?`${i}px`:"100%",...A},children:j.map((n,w)=>{const y=n.id||`item-${w}`;return x.jsx("div",{className:`gallery-item gallery-item-masonry ${P}`,style:{position:"absolute",...n.position,...p},onClick:k?()=>k(n,w):void 0,children:S?S(n,h,w):d(n,w)},y)})})},Ce=({items:o,gutter:i=10,columns:a=3,maxWidth:l="100%",alignment:S="flex-start",renderItem:M,className:A="",style:P={},itemClassName:p="",itemStyle:k={},onItemClick:h,lazyLoad:m=!1})=>{const g=ie(),R=E.useMemo(()=>de(o),[o]),f=E.useMemo(()=>ae(a,g),[a,g]),j=E.useMemo(()=>ee(i,g),[i,g]),D=(d,n)=>x.jsx("img",{src:d.src,alt:d.alt||`Gallery item ${n}`,loading:m?"lazy":void 0});return x.jsx("div",{className:`gallery-layout layout-stack ${A}`,style:{width:l,gap:j,alignItems:S,...P},children:R.map((d,n)=>{const w=d.id||`stack-item-${n}`,y=Math.min(d.colSpan||1,f),_=d.rowSpan||1,T=`calc(${100/f*y}% - ${(f-y)*j/f}px)`;return x.jsx("div",{className:`gallery-item gallery-item-stack ${p}`,style:{width:"100%",height:_>1?`calc(100% + ${j}px * ${_-1})`:"100%",flexBasis:T,flexGrow:0,flexShrink:0,marginBottom:_>1?`calc(${j}px * ${_-1})`:0,...k},onClick:h?()=>h(d,n):void 0,children:M?M(d,m,n):D(d,n)},w)})})},qe=({items:o,layout:i="masonry",layoutOptions:a={},className:l="",style:S={},itemClassName:M="",itemStyle:A={},lazyLoad:P=!1,renderItem:p,onItemClick:k})=>{const h=E.useRef(null),[m,g]=E.useState(0);E.useEffect(()=>{const f=()=>{h.current&&g(h.current.clientWidth)};return f(),window.addEventListener("resize",f),()=>{window.removeEventListener("resize",f)}},[]);const R=()=>{var j,D,d,n,w,y,_,T,H,G,O,V,L,B,F;const f={items:o,renderItem:p,className:l,style:S,itemClassName:M,itemStyle:A,onItemClick:k,lazyLoad:P};switch(i){case"masonry":return x.jsx(ve,{...f,containerWidth:m,columns:(j=a.masonry)==null?void 0:j.columns,gutter:(D=a.masonry)==null?void 0:D.gutter});case"grid":return x.jsx(je,{...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 x.jsx(Ce,{...f,columns:(_=a.stack)==null?void 0:_.columns,gutter:(T=a.stack)==null?void 0:T.gutter,maxWidth:(H=a.stack)==null?void 0:H.maxWidth});case"justified":return x.jsx(Te,{...f,containerWidth:m,targetRowHeight:(G=a.justified)==null?void 0:G.targetRowHeight,maxRowHeight:(O=a.justified)==null?void 0:O.maxRowHeight,containerPadding:(V=a.justified)==null?void 0:V.containerPadding,gutter:(L=a.justified)==null?void 0:L.gutter});default:return x.jsx(ve,{...f,containerWidth:m,columns:(B=a.masonry)==null?void 0:B.columns,gutter:(F=a.masonry)==null?void 0:F.gutter})}};return x.jsx("div",{ref:h,className:`gallery-container ${l}`,style:S,children:R()})};I.Gallery=qe,I.GridGallery=je,I.JustifiedGallery=Te,I.MasonryGallery=ve,I.StackGallery=Ce,I.getColumnsCount=ae,I.getGutter=ee,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=react-gallery-layouts.js.map