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