react-spring-carousel 3.0.0-beta090.31 → 3.0.0-beta090.33
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/dist/index.cjs.js +6 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +189 -189
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ar;function mr(){if(ar)return Ye;ar=1;var n=l,b=Symbol.for("react.element"),y=Symbol.for("react.fragment"),D=Object.prototype.hasOwnProperty,Y=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function T(f,d,v){var W,
|
|
9
|
+
*/var ar;function mr(){if(ar)return Ye;ar=1;var n=l,b=Symbol.for("react.element"),y=Symbol.for("react.fragment"),D=Object.prototype.hasOwnProperty,Y=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function T(f,d,v){var W,U={},_=null,o=null;v!==void 0&&(_=""+v),d.key!==void 0&&(_=""+d.key),d.ref!==void 0&&(o=d.ref);for(W in d)D.call(d,W)&&!h.hasOwnProperty(W)&&(U[W]=d[W]);if(f&&f.defaultProps)for(W in d=f.defaultProps,d)U[W]===void 0&&(U[W]=d[W]);return{$$typeof:b,type:f,key:_,ref:o,props:U,_owner:Y.current}}return Ye.Fragment=y,Ye.jsx=T,Ye.jsxs=T,Ye}var qe={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var or;function br(){return or||(or=1,process.env.NODE_ENV!=="production"&&function(){var n=l,b=Symbol.for("react.element"),y=Symbol.for("react.portal"),D=Symbol.for("react.fragment"),Y=Symbol.for("react.strict_mode"),h=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),f=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),v=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),
|
|
18
|
-
`+pe+e}}var De=!1,Pe;{var
|
|
17
|
+
*/var or;function br(){return or||(or=1,process.env.NODE_ENV!=="production"&&function(){var n=l,b=Symbol.for("react.element"),y=Symbol.for("react.portal"),D=Symbol.for("react.fragment"),Y=Symbol.for("react.strict_mode"),h=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),f=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),v=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),U=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),o=Symbol.for("react.offscreen"),q=Symbol.iterator,R="@@iterator";function ae(e){if(e===null||typeof e!="object")return null;var t=q&&e[q]||e[R];return typeof t=="function"?t:null}var O=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function $(e){{for(var t=arguments.length,i=new Array(t>1?t-1:0),s=1;s<t;s++)i[s-1]=arguments[s];re("error",e,i)}}function re(e,t,i){{var s=O.ReactDebugCurrentFrame,x=s.getStackAddendum();x!==""&&(t+="%s",i=i.concat([x]));var w=i.map(function(m){return String(m)});w.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,w)}}var te=!1,J=!1,Z=!1,oe=!1,z=!1,ve;ve=Symbol.for("react.module.reference");function Ce(e){return!!(typeof e=="string"||typeof e=="function"||e===D||e===h||z||e===Y||e===v||e===W||oe||e===o||te||J||Z||typeof e=="object"&&e!==null&&(e.$$typeof===_||e.$$typeof===U||e.$$typeof===T||e.$$typeof===f||e.$$typeof===d||e.$$typeof===ve||e.getModuleId!==void 0))}function N(e,t,i){var s=e.displayName;if(s)return s;var x=t.displayName||t.name||"";return x!==""?i+"("+x+")":i}function k(e){return e.displayName||"Context"}function p(e){if(e==null)return null;if(typeof e.tag=="number"&&$("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 D:return"Fragment";case y:return"Portal";case h:return"Profiler";case Y:return"StrictMode";case v:return"Suspense";case W:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case f:var t=e;return k(t)+".Consumer";case T:var i=e;return k(i._context)+".Provider";case d:return N(e,e.render,"ForwardRef");case U:var s=e.displayName||null;return s!==null?s:p(e.type)||"Memo";case _:{var x=e,w=x._payload,m=x._init;try{return p(m(w))}catch{return null}}}return null}var E=Object.assign,P=0,he,ge,c,C,F,ne,L;function $e(){}$e.__reactDisabledLog=!0;function ke(){{if(P===0){he=console.log,ge=console.info,c=console.warn,C=console.error,F=console.group,ne=console.groupCollapsed,L=console.groupEnd;var e={configurable:!0,enumerable:!0,value:$e,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}}function ce(){{if(P--,P===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},e,{value:he}),info:E({},e,{value:ge}),warn:E({},e,{value:c}),error:E({},e,{value:C}),group:E({},e,{value:F}),groupCollapsed:E({},e,{value:ne}),groupEnd:E({},e,{value:L})})}P<0&&$("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var B=O.ReactCurrentDispatcher,pe;function se(e,t,i){{if(pe===void 0)try{throw Error()}catch(x){var s=x.stack.trim().match(/\n( *(at )?)/);pe=s&&s[1]||""}return`
|
|
18
|
+
`+pe+e}}var De=!1,Pe;{var Be=typeof WeakMap=="function"?WeakMap:Map;Pe=new Be}function Me(e,t){if(!e||De)return"";{var i=Pe.get(e);if(i!==void 0)return i}var s;De=!0;var x=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var w;w=B.current,B.current=null,ke();try{if(t){var m=function(){throw Error()};if(Object.defineProperty(m.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(m,[])}catch(de){s=de}Reflect.construct(e,[],m)}else{try{m.call()}catch(de){s=de}e.call(m.prototype)}}else{try{throw Error()}catch(de){s=de}e()}}catch(de){if(de&&s&&typeof de.stack=="string"){for(var g=de.stack.split(`
|
|
19
19
|
`),H=s.stack.split(`
|
|
20
|
-
`),
|
|
21
|
-
`+g[
|
|
20
|
+
`),S=g.length-1,V=H.length-1;S>=1&&V>=0&&g[S]!==H[V];)V--;for(;S>=1&&V>=0;S--,V--)if(g[S]!==H[V]){if(S!==1||V!==1)do if(S--,V--,V<0||g[S]!==H[V]){var Q=`
|
|
21
|
+
`+g[S].replace(" at new "," at ");return e.displayName&&Q.includes("<anonymous>")&&(Q=Q.replace("<anonymous>",e.displayName)),typeof e=="function"&&Pe.set(e,Q),Q}while(S>=1&&V>=0);break}}}finally{De=!1,B.current=w,ce(),Error.prepareStackTrace=x}var Fe=e?e.displayName||e.name:"",ur=Fe?se(Fe):"";return typeof e=="function"&&Pe.set(e,ur),ur}function Ue(e,t,i){return Me(e,!1)}function Ke(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function I(e,t,i){if(e==null)return"";if(typeof e=="function")return Me(e,Ke(e));if(typeof e=="string")return se(e);switch(e){case v:return se("Suspense");case W:return se("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return Ue(e.render);case U:return I(e.type,t,i);case _:{var s=e,x=s._payload,w=s._init;try{return I(w(x),t,i)}catch{}}}return""}var G=Object.prototype.hasOwnProperty,M={},Le=O.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,i=I(e.type,e._source,t?t.type:null);Le.setExtraStackFrame(i)}else Le.setExtraStackFrame(null)}function we(e,t,i,s,x){{var w=Function.call.bind(G);for(var m in e)if(w(e,m)){var g=void 0;try{if(typeof e[m]!="function"){var H=Error((s||"React class")+": "+i+" type `"+m+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[m]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw H.name="Invariant Violation",H}g=e[m](t,m,s,i,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(S){g=S}g&&!(g instanceof Error)&&(ie(x),$("%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",i,m,typeof g),ie(null)),g instanceof Error&&!(g.message in M)&&(M[g.message]=!0,ie(x),$("Failed %s type: %s",i,g.message),ie(null))}}}var je=Array.isArray;function X(e){return je(e)}function _e(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,i=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i}}function me(e){try{return le(e),!1}catch{return!0}}function le(e){return""+e}function He(e){if(me(e))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",_e(e)),le(e)}var be=O.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},Ae,Je,ye;ye={};function Qe(e){if(G.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function xe(e){if(G.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function We(e,t){if(typeof e.ref=="string"&&be.current&&t&&be.current.stateNode!==t){var i=p(be.current.type);ye[i]||($('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',p(be.current.type),e.ref),ye[i]=!0)}}function Ne(e,t){{var i=function(){Ae||(Ae=!0,$("%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)",t))};i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}}function Se(e,t){{var i=function(){Je||(Je=!0,$("%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)",t))};i.isReactWarning=!0,Object.defineProperty(e,"ref",{get:i,configurable:!0})}}var Ve=function(e,t,i,s,x,w,m){var g={$$typeof:b,type:e,key:t,ref:i,props:m,_owner:w};return g._store={},Object.defineProperty(g._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(g,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(g,"_source",{configurable:!1,enumerable:!1,writable:!1,value:x}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g};function Ge(e,t,i,s,x){{var w,m={},g=null,H=null;i!==void 0&&(He(i),g=""+i),xe(t)&&(He(t.key),g=""+t.key),Qe(t)&&(H=t.ref,We(t,x));for(w in t)G.call(t,w)&&!Ze.hasOwnProperty(w)&&(m[w]=t[w]);if(e&&e.defaultProps){var S=e.defaultProps;for(w in S)m[w]===void 0&&(m[w]=S[w])}if(g||H){var V=typeof e=="function"?e.displayName||e.name||"Unknown":e;g&&Ne(m,V),H&&Se(m,V)}return Ve(e,g,H,x,s,be.current,m)}}var Ie=O.ReactCurrentOwner,ze=O.ReactDebugCurrentFrame;function Re(e){if(e){var t=e._owner,i=I(e.type,e._source,t?t.type:null);ze.setExtraStackFrame(i)}else ze.setExtraStackFrame(null)}var r;r=!1;function a(e){return typeof e=="object"&&e!==null&&e.$$typeof===b}function u(){{if(Ie.current){var e=p(Ie.current.type);if(e)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+e+"`."}return""}}function j(e){{if(e!==void 0){var t=e.fileName.replace(/^.*[\\\/]/,""),i=e.lineNumber;return`
|
|
24
24
|
|
|
25
25
|
Check your code at `+t+":"+i+"."}return""}}var K={};function Ee(e){{var t=u();if(!t){var i=typeof e=="string"?e:e.displayName||e.name;i&&(t=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+i+">.")}return t}}function fe(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var i=Ee(t);if(K[i])return;K[i]=!0;var s="";e&&e._owner&&e._owner!==Ie.current&&(s=" It was passed a child from "+p(e._owner.type)+"."),Re(e),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,s),Re(null)}}function Xe(e,t){{if(typeof e!="object")return;if(X(e))for(var i=0;i<e.length;i++){var s=e[i];a(s)&&fe(s,t)}else if(a(e))e._store&&(e._store.validated=!0);else if(e){var x=ae(e);if(typeof x=="function"&&x!==e.entries)for(var w=x.call(e),m;!(m=w.next()).done;)a(m.value)&&fe(m.value,t)}}}function ue(e){{var t=e.type;if(t==null||typeof t=="string")return;var i;if(typeof t=="function")i=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===d||t.$$typeof===B))i=t.propTypes;else return;if(i){var s=p(t);we(i,e.props,"prop",s,e)}else if(t.PropTypes!==void 0&&!r){r=!0;var x=p(t);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",x||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function nr(e){{for(var t=Object.keys(e.props),i=0;i<t.length;i++){var s=t[i];if(s!=="children"&&s!=="key"){Re(e),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),Re(null);break}}e.ref!==null&&(Re(e),$("Invalid attribute `ref` supplied to `React.Fragment`."),Re(null))}}function ir(e,t,i,s,x,w){{var m=Ce(e);if(!m){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" 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 H=j(x);H?g+=H:g+=u();var N;e===null?N="null":X(e)?N="array":e!==void 0&&e.$$typeof===b?(N="<"+(p(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):N=typeof e,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",N,g)}var V=Ge(e,t,i,x,w);if(V==null)return V;if(m){var Q=t.children;if(Q!==void 0)if(s)if(X(Q)){for(var Fe=0;Fe<Q.length;Fe++)Xe(Q[Fe],e);Object.freeze&&Object.freeze(Q)}else $("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 Xe(Q,e)}return e===D?nr(V):ue(V),V}}function fr(e,t,i){return ir(e,t,i,!0)}function dr(e,t,i){return ir(e,t,i,!1)}var vr=dr,hr=fr;qe.Fragment=D,qe.jsx=vr,qe.jsxs=hr}()),qe}(function(n){process.env.NODE_ENV==="production"?n.exports=mr():n.exports=br()})(pr);const er="RSC::Event";function sr(){const n=l.useRef(null);function b(D){l.useEffect(()=>{n.current||(n.current=document.createElement("div"));function Y(h){D(h.detail)}if(n.current)return n.current.addEventListener(er,Y,!1),()=>{var h;(h=n.current)==null||h.removeEventListener(er,Y,!1)}},[D])}function y(D){if(n.current){const Y=new CustomEvent(er,{detail:D});n.current.dispatchEvent(Y)}}return{useListenToCustomEvent:b,emitEvent:y}}function yr({mainCarouselWrapperRef:n,onFullScreenChange:b,handleResize:y}){const D=l.useRef(!1);l.useEffect(()=>{function d(){document.fullscreenElement&&(Y(!0),b(!0),y&&y()),document.fullscreenElement||(Y(!1),b(!1),y&&y())}if(Te.isEnabled)return Te.on("change",d),()=>{Te.isEnabled&&Te.off("change",d)}},[]);function Y(d){D.current=d}function h(){return D.current}function T(d){Te.isEnabled&&Te.request(d||n.current)}function f(){Te.isEnabled&&Te.exit()}return{enterFullscreen:T,exitFullscreen:f,getIsFullscreen:h}}function xr(n){const b=n.getBoundingClientRect();return b.top>=0&&b.left>=0&&b.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&b.right<=(window.innerWidth||document.documentElement.clientWidth)}function lr({thumbsSlideAxis:n="x",withThumbs:b=!1,prepareThumbsData:y,items:D,renderThumbFnProps:Y}){const h=l.useRef(null),[T,f]=ee.useSpring(()=>({val:0}));function d(){var _;return h.current?Math.round(Number((_=h.current)==null?void 0:_[n==="x"?"scrollWidth":"scrollHeight"])-h.current.getBoundingClientRect()[n==="x"?"width":"height"]):0}function v(_){var R;function o(){return h.current?h.current.querySelector(`#thumb-item-${D[_].id}`):null}const q=o();if(q&&h.current&&!xr(q)){const ae=q.offsetLeft,O=ae>d()?d():ae;f.start({from:{val:((R=h.current)==null?void 0:R[n==="x"?"scrollLeft":"scrollTop"])??0},to:{val:O},onChange:({value:$})=>{h.current&&(h.current[n==="x"?"scrollLeft":"scrollTop"]=Math.abs($.val))}})}}function W(){function _(o){return o.map(q=>({id:q.id,renderThumb:q.renderThumb}))}return y?y(_(D)):_(D)}return{thumbsFragment:b?A.jsx("div",{className:"use-spring-carousel-thumbs-wrapper",ref:h,onWheel:()=>T.val.stop(),style:{display:"flex",flex:"1",position:"relative",width:"100%",height:"100%",flexDirection:n==="x"?"row":"column",...n==="x"?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"}},children:W().map(({id:_,renderThumb:o})=>{const q=`thumb-item-${_}`;return A.jsx("div",{id:q,className:"thumb-item",children:typeof o=="function"?o(Y):o},q)})}):null,handleScroll:v}}function Rr({items:n,init:b=!0,withThumbs:y,thumbsSlideAxis:D="x",itemsPerSlide:Y=1,slideType:h="fixed",gutter:T=0,withLoop:f=!1,startEndGutter:d=0,carouselSlideAxis:v="x",disableGestures:W=!1,draggingSlideTreshold:B,slideWhenThresholdIsReached:_=!1,freeScroll:o,enableFreeScrollDrag:q,initialStartingPosition:R,prepareThumbsData:ae,initialActiveItem:O=0,animateWhenActiveItemChange:$=!0,slideGroupOfItems:re=!1,slideAmount:te}){const J=Y>n.length?n.length:Y,Z=l.useRef(!1),oe=l.useRef(B??0),z=l.useRef("initial"),ve=l.useRef("initial"),Ce=l.useRef("initial"),S=l.useRef(O),k=l.useRef(O===0),p=l.useRef(h==="fixed"&&O===n.length-1),E=l.useRef(null),P=l.useRef(null),he=l.useRef(0),ge=l.useRef(0),c=l.useRef(0),C=l.useRef(f),F=l.useRef(h),ne=l.useRef(o),L=l.useRef(!1),ke=l.useCallback(()=>f?[...n.map(r=>({...r,id:`prev-repeated-item-${r.id}`})),...n,...n.map(r=>({...r,id:`next-repeated-item-${r.id}`}))]:[...n],[n,f])(),[ce,U]=ee.useSpring(()=>({val:0,pause:!b,onChange:({value:r})=>{o&&E.current?(v==="x"?E.current.scrollLeft=Math.abs(r.val):E.current.scrollTop=Math.abs(r.val),ye()):P.current&&(v==="x"?P.current.style.transform=`translate3d(${r.val}px, 0px,0px)`:P.current.style.transform=`translate3d(0px,${r.val}px,0px)`)}}),[o]),{emitEvent:pe,useListenToCustomEvent:se}=sr(),{thumbsFragment:De,handleScroll:Pe}=lr({withThumbs:!!y,thumbsSlideAxis:D,prepareThumbsData:ae,items:n,renderThumbFnProps:{getIsActiveItem:Ve,getIsPrevItem:Se,useListenToCustomEvent:se,getIsNextItem:Ne}}),{enterFullscreen:Ue,exitFullscreen:Me,getIsFullscreen:Be}=yr({mainCarouselWrapperRef:E,handleResize:()=>je(),onFullScreenChange:r=>{pe({eventName:"onFullscreenChange",isFullscreen:r})}});function Ke(r){return h==="fixed"&&!o?{marginRight:`${r?0:T}px`,flex:`1 0 calc(100% / ${J} - ${T*(J-1)/J}px)`}:{marginRight:`${r?0:T}px`}}const I=l.useCallback(()=>{var u;if(typeof te=="number"&&te>0&&(h==="fluid"||o))return te;const r=re?E.current:(u=E.current)==null?void 0:u.querySelector(".use-spring-carousel-item");if(!r)throw Error("No carousel items available!");let a=r.getBoundingClientRect()[v==="x"?"width":"height"];return re||(a+=T),re&&(a+=T-d*2),a},[v,o,T,te,re,h,d]);function G({from:r,to:a,nextActiveItem:u,immediate:j=!1,slideMode:K}){ve.current=K,typeof u=="number"&&(o||(S.current=u),pe({eventName:"onSlideStartChange",slideActionType:z.current,slideMode:ve.current,nextItem:{startReached:k.current,endReached:p.current,index:o?-1:S.current,id:o?"":n[S.current].id}})),c.current=a,U.start({immediate:j,from:{val:r},to:{val:a},config:{...ee.config.default,velocity:ce.val.velocity},onRest(Ee){!j&&Ee.finished&&pe({eventName:"onSlideChange",slideActionType:z.current,slideMode:ve.current,currentItem:{startReached:k.current,endReached:p.current,index:o?-1:S.current,id:o?"":n[S.current].id}})}}),y&&!j&&Pe(S.current)}const M=l.useCallback(()=>{var r;return P.current?f?I()*n.length:Math.round(Number((r=P.current)==null?void 0:r[v==="x"?"scrollWidth":"scrollHeight"])-P.current.getBoundingClientRect()[v==="x"?"width":"height"]-d*2):0},[v,I,n.length,d,f]);function Le(){const r=`calc(100% - ${d*2}px)`;return{width:v==="x"?r:"100%",height:v==="y"?r:"100%"}}const ie=l.useCallback(()=>{var a;const r=(a=P.current)==null?void 0:a.querySelector(".use-spring-carousel-item");if(!r)throw Error("No carousel items available!");return r.getBoundingClientRect()[v==="x"?"width":"height"]+T},[v,T]),we=l.useCallback(r=>{const a=v==="x"?"left":"top",u=P.current;u&&(f?(u.style.top="0px",u.style.left="0px",u.style[a]=`-${r-d}px`,k.current=!1,p.current=!1):(u.style.left="0px",u.style.top="0px"))},[v,d,f]),je=l.useCallback((r=!1)=>{if(P.current&&r&&(P.current.style.transform="translate3d(0px, 0px,0px)",P.current.style.left="0",P.current.style.top="0"),h==="fixed"&&we(R==="center"?ie()*n.length-I()*Math.round((J-1)/2):R==="end"?ie()*n.length-I()*Math.round(J-1):ie()*n.length),h==="fluid"){if(we(ie()*n.length),p.current&&M()!==Math.abs(c.current)&&!f){const a=-M();c.current=a,U.start({immediate:!0,val:c.current});return}if(Math.abs(c.current)>0&&M()!==Math.abs(c.current)&&!f&&!o&&Ce.current==="backward"){const a=he.current-M(),u=c.current+a;return U.start({immediate:!0,val:u}),()=>{c.current=u}}console.log("here");return}if(!o&&h==="fixed"){const a=-(I()*S.current);if(Math.abs(a)>M()&&!f){const u=-M();p.current=!0,c.current=u,U.start({immediate:!0,val:c.current})}else c.current=a,U.start({immediate:!0,val:a});setTimeout(()=>{Z.current=!1},0)}},[o,ie,I,M,R,n.length,J,we,U,h,f]);function X(){return o&&E.current?E.current[v==="x"?"scrollLeft":"scrollTop"]:ce.val.get()}function _e(r,a){if(o&&r==="next"){const u=c.current+I();return u>M()?M():u}if(o&&r==="prev"){const u=c.current-I();return u<0?0:u}return r==="next"?typeof a=="number"?-(a*I()):c.current-I():typeof a=="number"?-(a*I()):c.current+I()}function me({type:r,index:a,immediate:u}){if(!b||L.current||k.current&&!f)return;p.current&&(Ce.current="backward"),z.current="prev",p.current=!1;const j=typeof a=="number"?a:S.current-1;if(o&&ye(),!f){const K=o?_e("prev",a)-I()/3<0:_e("prev",a)+I()/3>0;if(k.current)return;if(K){k.current=!0,p.current=!1,G({slideMode:r,from:X(),to:0,nextActiveItem:0,immediate:u});return}}if(f&&(k.current||j<0)){k.current=!1,p.current=!0,G({slideMode:r,from:X()-I()*n.length,to:-(I()*n.length)+I(),nextActiveItem:n.length-1,immediate:u});return}j===0&&(k.current=!0),(j===n.length-1||j===-1)&&(p.current=!0),G({slideMode:r,from:X(),to:_e("prev",a),nextActiveItem:j,immediate:u})}function le({type:r,index:a,immediate:u}){if(console.log("here1"),!b||L.current||p.current&&!f)return;console.log("2"),k.current&&(Ce.current="forward"),z.current="next",k.current=!1;const j=a||S.current+1;if(o&&ye(),!f){console.log("3");const K=Math.abs(_e("next",a))>M()-I()/3;if(p.current)return;if(K){k.current=!1,p.current=!0,G({slideMode:r,from:X(),to:o?M():-M(),nextActiveItem:j,immediate:u});return}}if(f&&(p.current||j>n.length-1)){p.current=!1,k.current=!0,G({slideMode:r,from:X()+I()*n.length,to:0,nextActiveItem:0,immediate:u});return}j===0&&(k.current=!0),j===n.length-1&&(p.current=!0),G({slideMode:r,from:X(),to:_e("next",a),nextActiveItem:j,immediate:u})}function He(){B?oe.current=B:oe.current=Math.floor(I()/2/2)}function be(){P.current&&(he.current=M(),C.current=f,F.current=h,ne.current=o,ge.current=window.innerWidth,c.current=0,We({id:0,immediate:!0,shouldReset:!0}),He(),je())}const Ze=b&&!W&&!o||!!o&&!!q,Ae=cr.useDrag(r=>{const a=r.dragging,u=r.offset[v==="x"?0:1],j=r.movement[v==="x"?0:1],K=r.direction[v==="x"?0:1],Ee=j>oe.current,fe=j<-oe.current,Xe=M(),ue=r.velocity;if(a){if(K>0?z.current="prev":z.current="next",pe({...r,eventName:"onDrag",slideActionType:z.current}),o){if(u>0){U.start({from:{val:X()},to:{val:0},config:{velocity:ue,friction:50,tension:1e3}}),r.cancel();return}U.start({from:{val:X()},to:{val:-u},config:{velocity:ue,friction:50,tension:1e3}});return}U.start({val:u,config:{velocity:ue,friction:50,tension:1e3}}),_&&fe?(le({type:"drag"}),r.cancel()):_&&Ee&&(me({type:"drag"}),r.cancel()),Xe-Math.abs(u)<-(I()*2)&&r.cancel();return}if(r.last&&o&&u>0){U.start({from:{val:X()},to:{val:0},config:{velocity:ue,friction:50,tension:1e3}});return}r.last&&!r.canceled&&o&&(z.current==="prev"&&me({type:"drag"}),z.current==="next"&&le({type:"drag"})),r.last&&!r.canceled&&!o&&(fe?!f&&p.current?U.start({val:-M(),config:{...ee.config.default,velocity:ue}}):le({type:"drag"}):Ee?!f&&k.current?U.start({val:0,config:{...ee.config.default,velocity:ue}}):me({type:"drag"}):U.start({val:c.current,config:{...ee.config.default,velocity:ue}})),r.last&&r.canceled&&U.start({val:c.current,config:{...ee.config.default,velocity:ue}})},{enabled:Ze,axis:v,from:()=>o&&E.current?[-E.current.scrollLeft,-E.current.scrollTop]:v==="x"?[ce.val.get(),ce.val.get()]:[ce.val.get(),ce.val.get()]});function Je(){return o?v==="x"?{overflowX:"auto"}:{overflowY:"auto"}:{}}function ye(){E.current&&(c.current=E.current[v==="x"?"scrollLeft":"scrollTop"],E.current[v==="x"?"scrollLeft":"scrollTop"]===0&&(k.current=!0,p.current=!1),E.current[v==="x"?"scrollLeft":"scrollTop"]>0&&E.current[v==="x"?"scrollLeft":"scrollTop"]<M()&&(k.current=!1,p.current=!1),E.current[v==="x"?"scrollLeft":"scrollTop"]===M()&&(k.current=!1,p.current=!0))}function Qe(){return o?{onWheel(){ce.val.stop(),ye()}}:{}}function xe(r,a){let u=0;if(typeof r=="string"?u=n.findIndex(j=>j.id===r):u=r,u<0||u>=n.length){if(a)throw new Error(a);console.error(`The item doesn't exist; check that the id provided - ${r} - is correct.`),u=-1}return u}function We({id:r,immediate:a,shouldReset:u,type:j}){if(!b||L.current)return;k.current=!1,p.current=!1;const K=xe(r,"The item you want to slide to doesn't exist; check the provided id.");if(K===S.current&&!u)return;const Ee=xe(n[S.current].id),fe=xe(n[K].id);fe>Ee?le({type:j||u?"initial":"click",index:fe,immediate:a}):me({type:j||u?"initial":"click",index:fe,immediate:a})}function Ne(r){const a=xe(r,"The item doesn't exist; check the provided id."),u=S.current;return f&&u===n.length-1?a===0:a===u+1}function Se(r){const a=xe(r,"The item doesn't exist; check the provided id."),u=S.current;return f&&u===0?a===n.length-1:a===u-1}function Ve(r){return xe(r,"The item you want to check doesn't exist; check the provided id.")===S.current}function Ge(){return W?"unset":v==="x"?"pan-y":"pan-x"}const Ie=o?{useListenToCustomEvent:se,enterFullscreen:Ue,exitFullscreen:Me,getIsFullscreen:Be,slideToPrevItem:(r=!0)=>{me({type:"click",immediate:!r})},slideToNextItem:(r=!0)=>{le({type:"click",immediate:!r})}}:{useListenToCustomEvent:se,enterFullscreen:Ue,exitFullscreen:Me,getIsFullscreen:Be,slideToPrevItem:(r=!0)=>{me({type:"click",immediate:!r})},slideToNextItem:(r=!0)=>{le({type:"click",immediate:!r})},slideToItem:(r,a=!0)=>{We({id:r,immediate:!a})},getIsNextItem:Ne,getIsPrevItem:Se,getIsActiveItem:Ve};ee.useIsomorphicLayoutEffect(()=>{P.current&&b&&(Z.current=!0,be())},[b]),l.useEffect(()=>{S.current!==O&&(Z.current=!0,We({id:O,immediate:!$}))},[O]),l.useEffect(()=>{if(b){if(O>n.length-1)throw new Error(`initialActiveItem (${O}) is greater than the total quantity available items (${n.length}).`);J>n.length&&console.warn(`itemsPerSlide (${J}) is greater than the total quantity available items (${n.length}). Fallback to ${n.length})`)}},[O,n.length,J,b]),l.useEffect(()=>{ge.current=window.innerWidth},[]),l.useEffect(()=>{if(b){if(f&&o)throw new Error("`withLoop` and `freeScroll` can't be used together.");if(o&&h==="fixed")throw new Error("`freeScroll` can't be used when `scrollType: fixed`.");if(q&&(h!=="fluid"||!o))throw new Error("`enableFreeScrollDrag` must be used with `slideType: fluid` and `freeScroll=true`");if(re&&o)throw new Error("`slideGroupOfItems` and `freeScroll` can't be used together.");if(typeof te=="number"&&te>0&&h==="fixed")throw new Error("`slideAmount` must be used with `slideType: fluid`");Z.current=!0,be()}},[R,J,d,T,b,f,h,o,q,re]),l.useEffect(()=>{if(!b)return;function r(){document.hidden?L.current=!0:L.current=!1}return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[b]),l.useEffect(()=>{if(E.current){let r;const a=new gr(()=>{if(!L.current&&!Z.current){ge.current=window.innerWidth;const u=je();window.clearTimeout(r),r=setTimeout(()=>{he.current=M(),typeof u=="function"&&u()},100)}});return a.observe(E.current),()=>{a.disconnect()}}},[je,M]);const ze=A.jsx(rr.Provider,{value:Ie,children:De}),Re=A.jsx(rr.Provider,{value:Ie,children:A.jsx("div",{className:"use-spring-carousel-main-wrapper",ref:E,...Qe(),style:{display:"flex",position:"relative",width:"100%",height:"100%",...Je()},children:A.jsxs("div",{className:"use-spring-carousel-track-wrapper",ref:P,...Ae(),style:{position:"relative",display:"flex",flexDirection:v==="x"?"row":"column",touchAction:Ge(),...Le()},children:[(o||!f)&&d?A.jsx("div",{style:{flexShrink:0,width:d}}):null,ke.map((r,a)=>A.jsx("div",{className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",...h==="fixed"?{flex:"1"}:{},...Ke(a===ke.findIndex(u=>u.id===ke[ke.length-1].id))},children:typeof r.renderItem=="function"?r.renderItem({getIsActiveItem:Ve,getIsNextItem:Ne,getIsPrevItem:Se,useListenToCustomEvent:se}):r.renderItem},`${r.id}-${a}`)),(o||!f)&&d?A.jsx("div",{style:{flexShrink:0,width:d}}):null]})})});return{...Ie,carouselFragment:Re,thumbsFragment:ze}}const rr=l.createContext(void 0);function Er(){const n=l.useContext(rr);if(!n)throw new Error("useSpringCarouselContext must be used within the carousel.");return n}const Oe={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"relative"},enter:{position:"relative",opacity:1},leave:{opacity:1,position:"absolute"}};function Tr({init:n=!0,disableGestures:b=!1,items:y,springConfig:D=ee.config.default,exitBeforeEnter:Y=!1,trail:h,withLoop:T=!1,activeItem:f,toPrevItemSpringProps:d=Oe,toNextItemSpringProps:v=Oe,draggingSlideTreshold:W=50,thumbsSlideAxis:B="x"}){const _=l.useRef("next"),o=l.useRef("initial"),q=l.useRef(null),[R,ae]=l.useState(f??0),{emitEvent:O,useListenToCustomEvent:$}=sr(),{handleScroll:re,thumbsFragment:te}=lr({thumbsSlideAxis:B,items:y,renderThumbFnProps:{getIsNextItem:k,getIsPrevItem:p,useListenToCustomEvent:$,activeItem:{index:R,id:y[R].id}}});function J(){return _.current==="prev"?{initial:{...d.initial},from:{...d.from},enter:{...d.enter},leave:{...d.leave}}:_.current==="next"?{initial:{...v.initial},from:{...v.from},enter:{...v.enter},leave:{...v.leave}}:{initial:{...Oe.initial},from:{...Oe.from},enter:{...Oe.enter},leave:{...Oe.leave}}}l.useEffect(()=>{typeof f=="number"&&f!==R&&ae(f)},[f]);function Z({to:c,slideType:C,slideMode:F}){_.current=C,o.current=F,O({eventName:"onSlideStartChange",slideActionType:_.current,slideMode:o.current,nextItem:{index:c,id:y[c].id,startReached:c===0,endReached:c===y.length-1}}),ae(c),re(R)}function oe(c){if(!n)return;const C=R===0;!T&&C||Z(T&&C?{to:y.length-1,slideType:"prev",slideMode:c}:{to:R-1,slideType:"prev",slideMode:c})}function z(c){if(!n)return;const C=R===y.length-1;!T&&C||Z(T&&C?{to:0,slideType:"next",slideMode:c}:{to:R+1,slideType:"next",slideMode:c})}const ve=ee.useTransition(R,{config:D,key:null,trail:h,exitBeforeEnter:Y,...J(),onRest(c,C,F){c.finished&&F===R&&O({eventName:"onSlideChange",slideActionType:_.current,slideMode:o.current,currentItem:{index:R,id:y[R].id,startReached:R===0,endReached:R===y.length-1}})}}),Ce=cr.useDrag(({last:c,movement:[C]})=>{if(c){const F=C>W,ne=C<-W,L=R===0,$e=R===y.length-1;if(ne){if(!T&&$e)return;O({eventName:"onLeftSwipe"}),z("swipe")}else if(F){if(!T&&L)return;O({eventName:"onRightSwipe"}),oe("swipe")}}},{enabled:!b});function S(c,C){let F=0;if(typeof c=="string"?F=y.findIndex(ne=>ne.id===c):F=c,F<0||F>=y.length){if(C)throw new Error(C);console.error(`The item doesn't exist; check that the id provided - ${c} - is correct.`),F=-1}return F}function k(c){const C=S(c,"The item doesn't exist; check the provided id."),F=R;return T&&F===y.length-1?C===0:C===F+1}function p(c){const C=S(c,"The item doesn't exist; check the provided id."),F=R;return T&&F===0?C===y.length-1:C===F-1}const E=ve((c,C,F,ne)=>{const L=y[C].renderItem;return A.jsx(ee.a.div,{id:`use-transition-carousel-item-${ne}`,className:"use-transition-carousel-item",style:{...c,flex:"1 0 100%",width:"100%",height:"100%"},children:typeof L=="function"?L({useListenToCustomEvent:$,getIsNextItem:k,getIsPrevItem:p,activeItem:{index:R,id:y[R].id}}):L})}),P={useListenToCustomEvent:$,slideToPrevItem:()=>oe("click"),slideToNextItem:()=>z("click")},he=A.jsx(tr.Provider,{value:P,children:te}),ge=A.jsx(tr.Provider,{value:P,children:A.jsx("div",{ref:q,...Ce(),style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:E})});return{...P,carouselFragment:ge,thumbsFragment:he}}const tr=l.createContext(void 0);function Cr(){const n=l.useContext(tr);if(!n)throw new Error("useTransitionCarouselContext must be used within the carousel.");return n}exports.useSpringCarousel=Rr;exports.useSpringCarouselContext=Er;exports.useTransitionCarousel=Tr;exports.useTransitionCarouselContext=Cr;
|
|
27
|
+
Check the top-level render call using <`+i+">.")}return t}}function fe(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var i=Ee(t);if(K[i])return;K[i]=!0;var s="";e&&e._owner&&e._owner!==Ie.current&&(s=" It was passed a child from "+p(e._owner.type)+"."),Re(e),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,s),Re(null)}}function Xe(e,t){{if(typeof e!="object")return;if(X(e))for(var i=0;i<e.length;i++){var s=e[i];a(s)&&fe(s,t)}else if(a(e))e._store&&(e._store.validated=!0);else if(e){var x=ae(e);if(typeof x=="function"&&x!==e.entries)for(var w=x.call(e),m;!(m=w.next()).done;)a(m.value)&&fe(m.value,t)}}}function ue(e){{var t=e.type;if(t==null||typeof t=="string")return;var i;if(typeof t=="function")i=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===d||t.$$typeof===U))i=t.propTypes;else return;if(i){var s=p(t);we(i,e.props,"prop",s,e)}else if(t.PropTypes!==void 0&&!r){r=!0;var x=p(t);$("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",x||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&$("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function nr(e){{for(var t=Object.keys(e.props),i=0;i<t.length;i++){var s=t[i];if(s!=="children"&&s!=="key"){Re(e),$("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),Re(null);break}}e.ref!==null&&(Re(e),$("Invalid attribute `ref` supplied to `React.Fragment`."),Re(null))}}function ir(e,t,i,s,x,w){{var m=Ce(e);if(!m){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" 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 H=j(x);H?g+=H:g+=u();var S;e===null?S="null":X(e)?S="array":e!==void 0&&e.$$typeof===b?(S="<"+(p(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):S=typeof e,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,g)}var V=Ge(e,t,i,x,w);if(V==null)return V;if(m){var Q=t.children;if(Q!==void 0)if(s)if(X(Q)){for(var Fe=0;Fe<Q.length;Fe++)Xe(Q[Fe],e);Object.freeze&&Object.freeze(Q)}else $("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 Xe(Q,e)}return e===D?nr(V):ue(V),V}}function fr(e,t,i){return ir(e,t,i,!0)}function dr(e,t,i){return ir(e,t,i,!1)}var vr=dr,hr=fr;qe.Fragment=D,qe.jsx=vr,qe.jsxs=hr}()),qe}(function(n){process.env.NODE_ENV==="production"?n.exports=mr():n.exports=br()})(pr);const er="RSC::Event";function sr(){const n=l.useRef(null);function b(D){l.useEffect(()=>{n.current||(n.current=document.createElement("div"));function Y(h){D(h.detail)}if(n.current)return n.current.addEventListener(er,Y,!1),()=>{var h;(h=n.current)==null||h.removeEventListener(er,Y,!1)}},[D])}function y(D){if(n.current){const Y=new CustomEvent(er,{detail:D});n.current.dispatchEvent(Y)}}return{useListenToCustomEvent:b,emitEvent:y}}function yr({mainCarouselWrapperRef:n,onFullScreenChange:b,handleResize:y}){const D=l.useRef(!1);l.useEffect(()=>{function d(){document.fullscreenElement&&(Y(!0),b(!0),y&&y()),document.fullscreenElement||(Y(!1),b(!1),y&&y())}if(Te.isEnabled)return Te.on("change",d),()=>{Te.isEnabled&&Te.off("change",d)}},[]);function Y(d){D.current=d}function h(){return D.current}function T(d){Te.isEnabled&&Te.request(d||n.current)}function f(){Te.isEnabled&&Te.exit()}return{enterFullscreen:T,exitFullscreen:f,getIsFullscreen:h}}function xr(n){const b=n.getBoundingClientRect();return b.top>=0&&b.left>=0&&b.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&b.right<=(window.innerWidth||document.documentElement.clientWidth)}function lr({thumbsSlideAxis:n="x",withThumbs:b=!1,prepareThumbsData:y,items:D,renderThumbFnProps:Y}){const h=l.useRef(null),[T,f]=ee.useSpring(()=>({val:0}));function d(){var _;return h.current?Math.round(Number((_=h.current)==null?void 0:_[n==="x"?"scrollWidth":"scrollHeight"])-h.current.getBoundingClientRect()[n==="x"?"width":"height"]):0}function v(_){var R;function o(){return h.current?h.current.querySelector(`#thumb-item-${D[_].id}`):null}const q=o();if(q&&h.current&&!xr(q)){const ae=q.offsetLeft,O=ae>d()?d():ae;f.start({from:{val:((R=h.current)==null?void 0:R[n==="x"?"scrollLeft":"scrollTop"])??0},to:{val:O},onChange:({value:$})=>{h.current&&(h.current[n==="x"?"scrollLeft":"scrollTop"]=Math.abs($.val))}})}}function W(){function _(o){return o.map(q=>({id:q.id,renderThumb:q.renderThumb}))}return y?y(_(D)):_(D)}return{thumbsFragment:b?A.jsx("div",{className:"use-spring-carousel-thumbs-wrapper",ref:h,onWheel:()=>T.val.stop(),style:{display:"flex",flex:"1",position:"relative",width:"100%",height:"100%",flexDirection:n==="x"?"row":"column",...n==="x"?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"}},children:W().map(({id:_,renderThumb:o})=>{const q=`thumb-item-${_}`;return A.jsx("div",{id:q,className:"thumb-item",children:typeof o=="function"?o(Y):o},q)})}):null,handleScroll:v}}function Rr({items:n,init:b=!0,withThumbs:y,thumbsSlideAxis:D="x",itemsPerSlide:Y=1,slideType:h="fixed",gutter:T=0,withLoop:f=!1,startEndGutter:d=0,carouselSlideAxis:v="x",disableGestures:W=!1,draggingSlideTreshold:U,slideWhenThresholdIsReached:_=!1,freeScroll:o,enableFreeScrollDrag:q,initialStartingPosition:R,prepareThumbsData:ae,initialActiveItem:O=0,animateWhenActiveItemChange:$=!0,slideGroupOfItems:re=!1,slideAmount:te}){const J=Y>n.length?n.length:Y,Z=l.useRef(!1),oe=l.useRef(U??0),z=l.useRef("initial"),ve=l.useRef("initial"),Ce=l.useRef("initial"),N=l.useRef(O),k=l.useRef(O===0),p=l.useRef(h==="fixed"&&O===n.length-1),E=l.useRef(null),P=l.useRef(null),he=l.useRef(0),ge=l.useRef(0),c=l.useRef(0),C=l.useRef(f),F=l.useRef(h),ne=l.useRef(o),L=l.useRef(!1),ke=l.useCallback(()=>f?[...n.map(r=>({...r,id:`prev-repeated-item-${r.id}`})),...n,...n.map(r=>({...r,id:`next-repeated-item-${r.id}`}))]:[...n],[n,f])(),[ce,B]=ee.useSpring(()=>({val:0,pause:!b,onChange:({value:r})=>{console.log({value:r}),o&&E.current?(v==="x"?E.current.scrollLeft=Math.abs(r.val):E.current.scrollTop=Math.abs(r.val),ye()):P.current&&(v==="x"?P.current.style.transform=`translate3d(${r.val}px, 0px,0px)`:P.current.style.transform=`translate3d(0px,${r.val}px,0px)`)}}),[o]),{emitEvent:pe,useListenToCustomEvent:se}=sr(),{thumbsFragment:De,handleScroll:Pe}=lr({withThumbs:!!y,thumbsSlideAxis:D,prepareThumbsData:ae,items:n,renderThumbFnProps:{getIsActiveItem:Ve,getIsPrevItem:Se,useListenToCustomEvent:se,getIsNextItem:Ne}}),{enterFullscreen:Be,exitFullscreen:Me,getIsFullscreen:Ue}=yr({mainCarouselWrapperRef:E,handleResize:()=>je(),onFullScreenChange:r=>{pe({eventName:"onFullscreenChange",isFullscreen:r})}});function Ke(r){return h==="fixed"&&!o?{marginRight:`${r?0:T}px`,flex:`1 0 calc(100% / ${J} - ${T*(J-1)/J}px)`}:{marginRight:`${r?0:T}px`}}const I=l.useCallback(()=>{var u;if(typeof te=="number"&&te>0&&(h==="fluid"||o))return te;const r=re?E.current:(u=E.current)==null?void 0:u.querySelector(".use-spring-carousel-item");if(!r)throw Error("No carousel items available!");let a=r.getBoundingClientRect()[v==="x"?"width":"height"];return re||(a+=T),re&&(a+=T-d*2),a},[v,o,T,te,re,h,d]);function G({from:r,to:a,nextActiveItem:u,immediate:j=!1,slideMode:K}){ve.current=K,typeof u=="number"&&(o||(N.current=u),pe({eventName:"onSlideStartChange",slideActionType:z.current,slideMode:ve.current,nextItem:{startReached:k.current,endReached:p.current,index:o?-1:N.current,id:o?"":n[N.current].id}})),c.current=a,console.log("SET SPRING DB",{activeItem:N.current}),B.start({immediate:j,from:{val:r},to:{val:a},config:{...ee.config.default,velocity:ce.val.velocity},onRest(Ee){!j&&Ee.finished&&pe({eventName:"onSlideChange",slideActionType:z.current,slideMode:ve.current,currentItem:{startReached:k.current,endReached:p.current,index:o?-1:N.current,id:o?"":n[N.current].id}})}}),y&&!j&&Pe(N.current)}const M=l.useCallback(()=>{var r;return P.current?f?I()*n.length:Math.round(Number((r=P.current)==null?void 0:r[v==="x"?"scrollWidth":"scrollHeight"])-P.current.getBoundingClientRect()[v==="x"?"width":"height"]-d*2):0},[v,I,n.length,d,f]);function Le(){const r=`calc(100% - ${d*2}px)`;return{width:v==="x"?r:"100%",height:v==="y"?r:"100%"}}const ie=l.useCallback(()=>{var a;const r=(a=P.current)==null?void 0:a.querySelector(".use-spring-carousel-item");if(!r)throw Error("No carousel items available!");return r.getBoundingClientRect()[v==="x"?"width":"height"]+T},[v,T]),we=l.useCallback(r=>{const a=v==="x"?"left":"top",u=P.current;u&&(f?(u.style.top="0px",u.style.left="0px",u.style[a]=`-${r-d}px`,k.current=!1,p.current=!1):(u.style.left="0px",u.style.top="0px"))},[v,d,f]),je=l.useCallback((r=!1)=>{if(P.current&&r&&(P.current.style.transform="translate3d(0px, 0px,0px)",P.current.style.left="0",P.current.style.top="0"),h==="fixed"&&we(R==="center"?ie()*n.length-I()*Math.round((J-1)/2):R==="end"?ie()*n.length-I()*Math.round(J-1):ie()*n.length),h==="fluid"){if(we(ie()*n.length),p.current&&M()!==Math.abs(c.current)&&!f){const a=-M();c.current=a,B.start({immediate:!0,val:c.current});return}if(Math.abs(c.current)>0&&M()!==Math.abs(c.current)&&!f&&!o&&Ce.current==="backward"){const a=he.current-M(),u=c.current+a;return B.start({immediate:!0,val:u}),()=>{c.current=u}}console.log("here");return}if(!o&&h==="fixed"){const a=-(I()*N.current);if(Math.abs(a)>M()&&!f){const u=-M();p.current=!0,c.current=u,B.start({immediate:!0,val:c.current})}else c.current=a,B.start({immediate:!0,val:a});setTimeout(()=>{Z.current=!1},0)}},[o,ie,I,M,R,n.length,J,we,B,h,f]);function X(){return o&&E.current?E.current[v==="x"?"scrollLeft":"scrollTop"]:ce.val.get()}function _e(r,a){if(o&&r==="next"){const u=c.current+I();return u>M()?M():u}if(o&&r==="prev"){const u=c.current-I();return u<0?0:u}return r==="next"?typeof a=="number"?-(a*I()):c.current-I():typeof a=="number"?-(a*I()):c.current+I()}function me({type:r,index:a,immediate:u}){if(!b||L.current||k.current&&!f)return;p.current&&(Ce.current="backward"),z.current="prev",p.current=!1;const j=typeof a=="number"?a:N.current-1;if(o&&ye(),!f){const K=o?_e("prev",a)-I()/3<0:_e("prev",a)+I()/3>0;if(k.current)return;if(K){k.current=!0,p.current=!1,G({slideMode:r,from:X(),to:0,nextActiveItem:0,immediate:u});return}}if(f&&(k.current||j<0)){k.current=!1,p.current=!0,G({slideMode:r,from:X()-I()*n.length,to:-(I()*n.length)+I(),nextActiveItem:n.length-1,immediate:u});return}j===0&&(k.current=!0),(j===n.length-1||j===-1)&&(p.current=!0),G({slideMode:r,from:X(),to:_e("prev",a),nextActiveItem:j,immediate:u})}function le({type:r,index:a,immediate:u}){if(console.log("here1"),!b||L.current||p.current&&!f)return;console.log("2"),k.current&&(Ce.current="forward"),z.current="next",k.current=!1;const j=a||N.current+1;if(o&&ye(),!f){console.log("3");const K=Math.abs(_e("next",a))>M()-I()/3;if(p.current)return;if(K){k.current=!1,p.current=!0,G({slideMode:r,from:X(),to:o?M():-M(),nextActiveItem:j,immediate:u});return}}if(f&&(p.current||j>n.length-1)){p.current=!1,k.current=!0,G({slideMode:r,from:X()+I()*n.length,to:0,nextActiveItem:0,immediate:u});return}j===0&&(k.current=!0),j===n.length-1&&(p.current=!0),G({slideMode:r,from:X(),to:_e("next",a),nextActiveItem:j,immediate:u})}function He(){U?oe.current=U:oe.current=Math.floor(I()/2/2)}function be(){P.current&&(he.current=M(),C.current=f,F.current=h,ne.current=o,ge.current=window.innerWidth,c.current=0,We({id:0,immediate:!0,shouldReset:!0}),He(),je())}const Ze=b&&!W&&!o||!!o&&!!q,Ae=cr.useDrag(r=>{const a=r.dragging,u=r.offset[v==="x"?0:1],j=r.movement[v==="x"?0:1],K=r.direction[v==="x"?0:1],Ee=j>oe.current,fe=j<-oe.current,Xe=M(),ue=r.velocity;if(a){if(K>0?z.current="prev":z.current="next",pe({...r,eventName:"onDrag",slideActionType:z.current}),o){if(u>0){B.start({from:{val:X()},to:{val:0},config:{velocity:ue,friction:50,tension:1e3}}),r.cancel();return}B.start({from:{val:X()},to:{val:-u},config:{velocity:ue,friction:50,tension:1e3}});return}B.start({val:u,config:{velocity:ue,friction:50,tension:1e3}}),_&&fe?(le({type:"drag"}),r.cancel()):_&&Ee&&(me({type:"drag"}),r.cancel()),Xe-Math.abs(u)<-(I()*2)&&r.cancel();return}if(r.last&&o&&u>0){B.start({from:{val:X()},to:{val:0},config:{velocity:ue,friction:50,tension:1e3}});return}r.last&&!r.canceled&&o&&(z.current==="prev"&&me({type:"drag"}),z.current==="next"&&le({type:"drag"})),r.last&&!r.canceled&&!o&&(fe?!f&&p.current?B.start({val:-M(),config:{...ee.config.default,velocity:ue}}):le({type:"drag"}):Ee?!f&&k.current?B.start({val:0,config:{...ee.config.default,velocity:ue}}):me({type:"drag"}):B.start({val:c.current,config:{...ee.config.default,velocity:ue}})),r.last&&r.canceled&&B.start({val:c.current,config:{...ee.config.default,velocity:ue}})},{enabled:Ze,axis:v,from:()=>o&&E.current?[-E.current.scrollLeft,-E.current.scrollTop]:v==="x"?[ce.val.get(),ce.val.get()]:[ce.val.get(),ce.val.get()]});function Je(){return o?v==="x"?{overflowX:"auto"}:{overflowY:"auto"}:{}}function ye(){E.current&&(c.current=E.current[v==="x"?"scrollLeft":"scrollTop"],E.current[v==="x"?"scrollLeft":"scrollTop"]===0&&(k.current=!0,p.current=!1),E.current[v==="x"?"scrollLeft":"scrollTop"]>0&&E.current[v==="x"?"scrollLeft":"scrollTop"]<M()&&(k.current=!1,p.current=!1),E.current[v==="x"?"scrollLeft":"scrollTop"]===M()&&(k.current=!1,p.current=!0))}function Qe(){return o?{onWheel(){ce.val.stop(),ye()}}:{}}function xe(r,a){let u=0;if(typeof r=="string"?u=n.findIndex(j=>j.id===r):u=r,u<0||u>=n.length){if(a)throw new Error(a);console.error(`The item doesn't exist; check that the id provided - ${r} - is correct.`),u=-1}return u}function We({id:r,immediate:a,shouldReset:u,type:j}){if(!b||L.current)return;k.current=!1,p.current=!1;const K=xe(r,"The item you want to slide to doesn't exist; check the provided id.");if(K===N.current&&!u)return;const Ee=xe(n[N.current].id),fe=xe(n[K].id);fe>Ee?le({type:j||u?"initial":"click",index:fe,immediate:a}):me({type:j||u?"initial":"click",index:fe,immediate:a})}function Ne(r){const a=xe(r,"The item doesn't exist; check the provided id."),u=N.current;return f&&u===n.length-1?a===0:a===u+1}function Se(r){const a=xe(r,"The item doesn't exist; check the provided id."),u=N.current;return f&&u===0?a===n.length-1:a===u-1}function Ve(r){return xe(r,"The item you want to check doesn't exist; check the provided id.")===N.current}function Ge(){return W?"unset":v==="x"?"pan-y":"pan-x"}const Ie=o?{useListenToCustomEvent:se,enterFullscreen:Be,exitFullscreen:Me,getIsFullscreen:Ue,slideToPrevItem:(r=!0)=>{me({type:"click",immediate:!r})},slideToNextItem:(r=!0)=>{le({type:"click",immediate:!r})}}:{useListenToCustomEvent:se,enterFullscreen:Be,exitFullscreen:Me,getIsFullscreen:Ue,slideToPrevItem:(r=!0)=>{me({type:"click",immediate:!r})},slideToNextItem:(r=!0)=>{le({type:"click",immediate:!r})},slideToItem:(r,a=!0)=>{We({id:r,immediate:!a})},getIsNextItem:Ne,getIsPrevItem:Se,getIsActiveItem:Ve};ee.useIsomorphicLayoutEffect(()=>{P.current&&b&&(Z.current=!0,be())},[b]),l.useEffect(()=>{N.current!==O&&(Z.current=!0,We({id:O,immediate:!$}))},[O]),l.useEffect(()=>{if(b){if(O>n.length-1)throw new Error(`initialActiveItem (${O}) is greater than the total quantity available items (${n.length}).`);J>n.length&&console.warn(`itemsPerSlide (${J}) is greater than the total quantity available items (${n.length}). Fallback to ${n.length})`)}},[O,n.length,J,b]),l.useEffect(()=>{ge.current=window.innerWidth},[]),l.useEffect(()=>{if(b){if(f&&o)throw new Error("`withLoop` and `freeScroll` can't be used together.");if(o&&h==="fixed")throw new Error("`freeScroll` can't be used when `scrollType: fixed`.");if(q&&(h!=="fluid"||!o))throw new Error("`enableFreeScrollDrag` must be used with `slideType: fluid` and `freeScroll=true`");if(re&&o)throw new Error("`slideGroupOfItems` and `freeScroll` can't be used together.");if(typeof te=="number"&&te>0&&h==="fixed")throw new Error("`slideAmount` must be used with `slideType: fluid`");Z.current=!0,be()}},[R,J,d,T,b,f,h,o,q,re]),l.useEffect(()=>{if(!b)return;function r(){document.hidden?L.current=!0:L.current=!1}return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[b]),l.useEffect(()=>{if(E.current){let r;const a=new gr(()=>{if(!L.current&&!Z.current){ge.current=window.innerWidth;const u=je();window.clearTimeout(r),r=setTimeout(()=>{he.current=M(),typeof u=="function"&&u()},100)}});return a.observe(E.current),()=>{a.disconnect()}}},[je,M]);const ze=A.jsx(rr.Provider,{value:Ie,children:De}),Re=A.jsx(rr.Provider,{value:Ie,children:A.jsx("div",{className:"use-spring-carousel-main-wrapper",ref:E,...Qe(),style:{display:"flex",position:"relative",width:"100%",height:"100%",...Je()},children:A.jsxs("div",{className:"use-spring-carousel-track-wrapper",ref:P,...Ae(),style:{position:"relative",display:"flex",flexDirection:v==="x"?"row":"column",touchAction:Ge(),...Le()},children:[(o||!f)&&d?A.jsx("div",{style:{flexShrink:0,width:d}}):null,ke.map((r,a)=>A.jsx("div",{className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",...h==="fixed"?{flex:"1"}:{},...Ke(a===ke.findIndex(u=>u.id===ke[ke.length-1].id))},children:typeof r.renderItem=="function"?r.renderItem({getIsActiveItem:Ve,getIsNextItem:Ne,getIsPrevItem:Se,useListenToCustomEvent:se}):r.renderItem},`${r.id}-${a}`)),(o||!f)&&d?A.jsx("div",{style:{flexShrink:0,width:d}}):null]})})});return{...Ie,carouselFragment:Re,thumbsFragment:ze}}const rr=l.createContext(void 0);function Er(){const n=l.useContext(rr);if(!n)throw new Error("useSpringCarouselContext must be used within the carousel.");return n}const Oe={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"relative"},enter:{position:"relative",opacity:1},leave:{opacity:1,position:"absolute"}};function Tr({init:n=!0,disableGestures:b=!1,items:y,springConfig:D=ee.config.default,exitBeforeEnter:Y=!1,trail:h,withLoop:T=!1,activeItem:f,toPrevItemSpringProps:d=Oe,toNextItemSpringProps:v=Oe,draggingSlideTreshold:W=50,thumbsSlideAxis:U="x"}){const _=l.useRef("next"),o=l.useRef("initial"),q=l.useRef(null),[R,ae]=l.useState(f??0),{emitEvent:O,useListenToCustomEvent:$}=sr(),{handleScroll:re,thumbsFragment:te}=lr({thumbsSlideAxis:U,items:y,renderThumbFnProps:{getIsNextItem:k,getIsPrevItem:p,useListenToCustomEvent:$,activeItem:{index:R,id:y[R].id}}});function J(){return _.current==="prev"?{initial:{...d.initial},from:{...d.from},enter:{...d.enter},leave:{...d.leave}}:_.current==="next"?{initial:{...v.initial},from:{...v.from},enter:{...v.enter},leave:{...v.leave}}:{initial:{...Oe.initial},from:{...Oe.from},enter:{...Oe.enter},leave:{...Oe.leave}}}l.useEffect(()=>{typeof f=="number"&&f!==R&&ae(f)},[f]);function Z({to:c,slideType:C,slideMode:F}){_.current=C,o.current=F,O({eventName:"onSlideStartChange",slideActionType:_.current,slideMode:o.current,nextItem:{index:c,id:y[c].id,startReached:c===0,endReached:c===y.length-1}}),ae(c),re(R)}function oe(c){if(!n)return;const C=R===0;!T&&C||Z(T&&C?{to:y.length-1,slideType:"prev",slideMode:c}:{to:R-1,slideType:"prev",slideMode:c})}function z(c){if(!n)return;const C=R===y.length-1;!T&&C||Z(T&&C?{to:0,slideType:"next",slideMode:c}:{to:R+1,slideType:"next",slideMode:c})}const ve=ee.useTransition(R,{config:D,key:null,trail:h,exitBeforeEnter:Y,...J(),onRest(c,C,F){c.finished&&F===R&&O({eventName:"onSlideChange",slideActionType:_.current,slideMode:o.current,currentItem:{index:R,id:y[R].id,startReached:R===0,endReached:R===y.length-1}})}}),Ce=cr.useDrag(({last:c,movement:[C]})=>{if(c){const F=C>W,ne=C<-W,L=R===0,$e=R===y.length-1;if(ne){if(!T&&$e)return;O({eventName:"onLeftSwipe"}),z("swipe")}else if(F){if(!T&&L)return;O({eventName:"onRightSwipe"}),oe("swipe")}}},{enabled:!b});function N(c,C){let F=0;if(typeof c=="string"?F=y.findIndex(ne=>ne.id===c):F=c,F<0||F>=y.length){if(C)throw new Error(C);console.error(`The item doesn't exist; check that the id provided - ${c} - is correct.`),F=-1}return F}function k(c){const C=N(c,"The item doesn't exist; check the provided id."),F=R;return T&&F===y.length-1?C===0:C===F+1}function p(c){const C=N(c,"The item doesn't exist; check the provided id."),F=R;return T&&F===0?C===y.length-1:C===F-1}const E=ve((c,C,F,ne)=>{const L=y[C].renderItem;return A.jsx(ee.a.div,{id:`use-transition-carousel-item-${ne}`,className:"use-transition-carousel-item",style:{...c,flex:"1 0 100%",width:"100%",height:"100%"},children:typeof L=="function"?L({useListenToCustomEvent:$,getIsNextItem:k,getIsPrevItem:p,activeItem:{index:R,id:y[R].id}}):L})}),P={useListenToCustomEvent:$,slideToPrevItem:()=>oe("click"),slideToNextItem:()=>z("click")},he=A.jsx(tr.Provider,{value:P,children:te}),ge=A.jsx(tr.Provider,{value:P,children:A.jsx("div",{ref:q,...Ce(),style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:E})});return{...P,carouselFragment:ge,thumbsFragment:he}}const tr=l.createContext(void 0);function Cr(){const n=l.useContext(tr);if(!n)throw new Error("useTransitionCarouselContext must be used within the carousel.");return n}exports.useSpringCarousel=Rr;exports.useSpringCarouselContext=Er;exports.useTransitionCarousel=Tr;exports.useTransitionCarouselContext=Cr;
|
|
28
28
|
//# sourceMappingURL=index.cjs.js.map
|