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