react-spring-carousel 2.0.19 → 3.0.0-beta001

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.
Files changed (34) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/esm/index2.js +1 -1
  5. package/dist/esm/index2.js.map +1 -1
  6. package/dist/esm/useSpringCarousel.js +2 -0
  7. package/dist/esm/useSpringCarousel.js.map +1 -0
  8. package/dist/esm/useThumbsModule-ce69c348.js +2 -0
  9. package/dist/esm/useThumbsModule-ce69c348.js.map +1 -0
  10. package/dist/types/index.d.ts +0 -1
  11. package/dist/types/mockedItems.d.ts +10 -0
  12. package/dist/types/modules/index.d.ts +1 -1
  13. package/dist/types/modules/useEventsModule.d.ts +44 -0
  14. package/dist/types/modules/useFullscreenModule.d.ts +6 -6
  15. package/dist/types/modules/useThumbsModule.d.ts +7 -13
  16. package/dist/types/types/common.d.ts +2 -0
  17. package/dist/types/types/index.d.ts +8 -49
  18. package/dist/types/types/internals.d.ts +82 -0
  19. package/dist/types/useSpringCarousel.d.ts +7 -0
  20. package/dist/umd/index.js +1 -1
  21. package/dist/umd/index.js.map +1 -1
  22. package/package.json +48 -75
  23. package/dist/esm/index3.js +0 -2
  24. package/dist/esm/index3.js.map +0 -1
  25. package/dist/esm/index4.js +0 -2
  26. package/dist/esm/index4.js.map +0 -1
  27. package/dist/esm/useThumbsModule-0944decf.js +0 -2
  28. package/dist/esm/useThumbsModule-0944decf.js.map +0 -1
  29. package/dist/types/modules/useCustomEventsModule.d.ts +0 -5
  30. package/dist/types/types/useSpringCarousel.d.ts +0 -124
  31. package/dist/types/types/useTransitionCarousel.d.ts +0 -39
  32. package/dist/types/useSpringCarousel/index.d.ts +0 -8
  33. package/dist/types/useTransitionCarousel/index.d.ts +0 -24
  34. package/dist/types/utils.d.ts +0 -5
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("react-spring"),r=require("@use-gesture/react"),i=require("rxjs");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(require("screenfull"));function u(){const e=t.useRef(new i.Subject);return{useListenToCustomEvent:function(n){t.useEffect((()=>{const t=e.current.subscribe(n);return()=>t.unsubscribe()}),[n])},emitObservable:t=>{e.current.next(t)}}}const c="undefined"!=typeof window?t.useLayoutEffect:t.useEffect;function l(e){const n=t.useRef(!1);c((()=>{if(!n.current){const t=e();return n.current=!0,()=>{t&&t()}}}),[])}function a({mainCarouselWrapperRef:e,emitObservable:n,handleResize:r}){const i=t.useRef(!1);function o(e){i.current=e}return l((()=>{function e(){document.fullscreenElement&&(o(!0),n({eventName:"onFullscreenChange",isFullscreen:!0}),r&&r()),document.fullscreenElement||(o(!1),n({eventName:"onFullscreenChange",isFullscreen:!1}),r&&r())}if(s.default.isEnabled)return s.default.on("change",e),()=>{s.default.isEnabled&&s.default.off("change",e)}})),{enterFullscreen:function(t){s.default.isEnabled&&s.default.request(t||e.current)},exitFullscreen:function(){s.default.isEnabled&&s.default.exit()},getIsFullscreen:function(){return i.current}}}function f({items:r,withThumbs:i,thumbsSlideAxis:o="x",springConfig:s,prepareThumbsData:u,getFluidWrapperScrollValue:c=(()=>0),getSlideValue:a=(()=>0),slideType:f}){const d=t.useRef(null),[h,g]=n.useSpring((()=>({x:0,y:0,config:s,onChange:({value:e})=>{d.current&&"fluid"===f&&(d.current["x"===o?"scrollLeft":"scrollTop"]=Math.abs(e[o]))}})));function m(){return d.current["x"===o?"scrollLeft":"scrollTop"]}function p(){var e;return Math.round(Number(null===(e=d.current)||void 0===e?void 0:e["x"===o?"scrollWidth":"scrollHeight"])-d.current.getBoundingClientRect()["x"===o?"width":"height"])}function v(){const e=Math.round(c()/a());return p()/e}l((()=>{if(i&&!d.current)throw new Error("The thumbs wrapper is not defined. If you've passed a Functional component, be sure to wrap your component in forwardRef.")}));return{thumbsFragment:i?e.jsx(n.animated.div,Object.assign({ref:d,className:"use-spring-carousel-thumbs-wrapper",onWheel:()=>{h[o].stop()},style:Object.assign({display:"flex",flex:1,position:"relative",width:"100%",height:"100%",flexDirection:"x"===o?"row":"column"},"x"===o?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"})},{children:function(){function e(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return u?u(e(r)):e(r)}().map((({id:t,renderThumb:n})=>{const r=`thumb-${t}`;return e.jsx("div",Object.assign({id:r,className:"thumb-item"},{children:n}),r)}))})):null,handleThumbsScroll:function(e,t){if("fluid"===f){const e=p();if("next"===t){const t=m()+v();g.start({from:{[o]:m()},to:{[o]:t>e?e:t}})}if("prev"===t){const e=m()-v();g.start({from:{[o]:m()},to:{[o]:e<0?0:e}})}}else{const n=d.current.querySelector(`#thumb-${r[e].id}`);if(n){const i=d.current,s="x"===o?"offsetWidth":"offsetHeight",u="x"===o?"scrollLeft":"scrollTop",c=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:n,offsetDimension:s,offsetDirection:"x"===o?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:i,offsetDimension:s}),a=function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:i,scrollDirection:u}),f=function({thumbWrapper:t,thumbOffsetPosition:n,thumbScrollDimension:i,offsetDimension:s}){const u="x"===o?"scrollWidth":"scrollHeight";return e===r.length-1||n-i>t[u]-t[s]?t[u]-t[s]:0===e?0:n-i}({thumbWrapper:i,thumbOffsetPosition:c,thumbScrollDimension:l,offsetDimension:s});g.start({from:{[o]:a},to:{[o]:"prev"===t&&f<0?0:f},onChange:({value:e})=>{"x"===o?d.current.scrollLeft=e.x:d.current.scrollTop=e.y}})}}}}}const d=t.createContext(void 0),h=Object.assign(Object.assign({},n.config.default),{mass:1,velocity:0});const g=t.createContext(void 0);exports.useSpringCarousel=function({items:i,withLoop:o=!1,draggingSlideTreshold:s,springConfig:g=n.config.default,shouldResizeOnWindowResize:m=!0,withThumbs:p=!1,enableThumbsWrapperScroll:v=!0,slideWhenThresholdIsReached:b=!0,carouselSlideAxis:x="x",thumbsSlideAxis:y="x",prepareThumbsData:w,initialActiveItem:T=0,initialStartingPosition:j,disableGestures:O=!1,gutter:S=0,startEndGutter:C=0,touchAction:I,slideAmount:R,freeScroll:E=!1,enableFreeScrollDrag:A,itemsPerSlide:N=1,slideType:F="fixed"}){const W=t.useRef(!0),D=t.useRef("initial"),L=o?i.length===N?[...i,...i,...i,...i,...i]:[...i,...i,...i]:i,P=t.useRef(T),$=t.useRef(null),M=t.useRef(null),q=t.useRef(!1),z=t.useRef(!1),B=t.useRef(!1),H=t.useRef(0),k=t.useRef(!1),V=t.useRef(0),G=t.useRef(0),Y=t.useRef(0),X=t.useRef(i),_=t.useRef(null!=s?s:0),J=t.useRef(N),K=t.useRef(S),Q=t.useRef(C),U=t.useRef(T),Z=t.useRef(j),ee=t.useRef(x);J.current=N,K.current=S,Q.current=C,U.current=T,Z.current=j,ee.current=x;const[te,ne]=n.useSpring((()=>({y:0,x:0,onChange:({value:e})=>{$.current&&E&&($.current["x"===ee.current?"scrollLeft":"scrollTop"]=Math.abs(e[ee.current]))}})));function re(){const e=null===(t=M.current)||void 0===t?void 0:t.querySelector(".use-spring-carousel-item");var t;if(!e)throw Error("No carousel items available!");return e.getBoundingClientRect()["x"===ee.current?"width":"height"]+K.current}function ie(){return te[ee.current].get()}function oe(){return re()*i.length<function(){if(!$.current)throw new Error("mainCarouselWrapperRef is not available");return $.current.getBoundingClientRect()["x"===ee.current?"width":"height"]}()}function se(){var e;return Math.round(Number(null===(e=M.current)||void 0===e?void 0:e["x"===ee.current?"scrollWidth":"scrollHeight"])-M.current.getBoundingClientRect()["x"===ee.current?"width":"height"])}function ue(){return 0===Se()}function ce(){if(!M.current)return 0;const e=re();if("fluid"===F&&"number"==typeof R){if(R<e)throw new Error("slideAmount must be greater than the width of a single item.");return R}return e}function le(e,t){const n="x"===ee.current?"left":"top";function r(){return re()*i.length}function s(r){o?(e.style.top="0px",e.style[n]=`-${r-Q.current}px`):(e.style.left="0px",e.style.top="0px",t&&W.current&&(e.style[n]=`calc(-${t} * 100%)`))}function u(){s(r())}if("fixed"===F){if(J.current>1)switch(Z.current){default:case"start":u();break;case"center":c=J.current,s(r()-ce()*Math.round((c-1)/2));break;case"end":!function(e){s(r()-ce()*Math.round(e-1))}(J.current)}else u()}else u();var c}function ae(){if(V.current=window.innerWidth,"fluid"===F){if(oe())return void ne.start({immediate:!0,[ee.current]:0});if(H.current=se(),k.current){const e=-H.current;ne.start({immediate:!0,[ee.current]:e})}G.current=window.innerWidth}else ne.start({immediate:!0,[ee.current]:-ce()*Se()});H.current=se(),le(M.current)}function fe(){window.innerWidth===V.current||E||ae()}c((()=>{_.current=s||Math.floor(ce()/2/2),ae()}),[s,N,S,C,T,j,x,y]);const{useListenToCustomEvent:de,emitObservable:he}=u(),{enterFullscreen:ge,exitFullscreen:me,getIsFullscreen:pe}=a({mainCarouselWrapperRef:$,emitObservable:he,handleResize:fe}),{thumbsFragment:ve,handleThumbsScroll:be}=f({withThumbs:p,items:i,thumbsSlideAxis:y,springConfig:g,prepareThumbsData:w,slideType:F,getFluidWrapperScrollValue:se,getSlideValue:ce});function xe(){if(!$.current)throw new Error("Missing mainCarouselWrapperRef.current");return $.current["x"===ee.current?"scrollLeft":"scrollTop"]}function ye(){return"boolean"==typeof A?A:"function"==typeof A&&A()}const we=r.useDrag((e=>{const t=e.dragging,n=e.offset["x"===ee.current?0:1],r=e.movement["x"===ee.current?0:1],i=r>_.current,s=r<-_.current,u=e.direction["x"===ee.current?0:1];function c(){e.cancel()}function l(){Te(u>0?"prev":"next")}function a(){he(Object.assign({eventName:"onDrag",slideActionType:je()},e))}function f(){"fluid"===F?oe()||ue()&&"prev"===je()?ne.start({[ee.current]:0,config:Object.assign({velocity:e.velocity},g)}):k.current&&"next"===je()?ne.start({[ee.current]:-H.current,config:Object.assign({velocity:e.velocity},g)}):ne.start({[ee.current]:Y.current,config:Object.assign({velocity:e.velocity},g)}):ne.start({[ee.current]:-Se()*ce(),config:Object.assign({velocity:e.velocity},g)})}function d(){Math.abs(ie())+100>=H.current&&"next"===je()&&(k.current=!0),"prev"===je()&&(k.current=!1)}if(E&&ye())return t&&(Re()||Ie(!0),l(),a(),d()),ne.start({from:{[ee.current]:xe()},to:{[ee.current]:-n},config:{velocity:e.velocity,friction:50,tension:1400}}),0===xe()&&"prev"===je()?void c():void(e.last&&("prev"===je()?Le(e.velocity):Pe(e.velocity),Ie(!1)));if(t){if(Re()||Ie(!0),a(),l(),d(),E){if(ye()){if(0===xe()&&"prev"===je())return void c();ne.start({config:{velocity:e.velocity,friction:50,tension:1400},from:{[ee.current]:xe()},to:{[ee.current]:-n}})}return}if(ne.start({[ee.current]:n,config:{velocity:e.velocity,friction:50,tension:1e3}}),(i||s)&&oe()&&"fluid"===F)c(),f();else if(k.current&&"next"===je()&&s)k.current=!1,c(),ne.start({[ee.current]:-H.current});else if(b){if(s)return c(),void(!o&&De()?f():Pe(e.velocity));if(i)return c(),void(!o&&ue()?f():Le(e.velocity))}}if(e.last&&!b&&(s||i)&&!E)return Ie(!1),void(s?!o&&De()?f():Pe(e.velocity):i&&(!o&&ue()?f():Le(e.velocity)));!e.last||s||i||E||(f(),he(Object.assign({eventName:"onDrag",slideActionType:je()},e)))}),{enabled:!O,axis:ee.current,from:()=>E?"x"===ee.current?[-xe(),0]:[0,-xe()]:[te.x.get(),te.y.get()]});function Te(e){D.current=e}function je(){return D.current}function Oe(e){P.current=e}function Se(){return P.current}function Ce(e){z.current=e}function Ie(e){q.current=e}function Re(){return q.current}function Ee(){const e=Se();return 0===e?i.length-1:e-1}function Ae(){const e=Se();return e===i.length-1?0:e+1}function Ne(e){return i.findIndex((t=>t.id===e))}function Fe(e,t){if("number"==typeof e)return{[ee.current]:e};if("number"!=typeof t)throw new Error("to values is not a number!");return{[ee.current]:-ce()*t}}function We({from:e,to:t=-1,customTo:n,immediate:r=!1,onRest:o=(()=>{}),velocity:s}){r||(Oe(t),Ce(!0),he({eventName:"onSlideStartChange",slideActionType:je(),nextItem:{index:"fluid"===F?-1:t,id:"fluid"===F?"":i[t].id}})),Y.current=Fe(n,t)[x],ne.start(Object.assign(Object.assign(Object.assign(Object.assign({},function(e){return"number"==typeof e?{from:{[ee.current]:e}}:{}}(e)),{to:Fe(n,t)}),s?{config:Object.assign(Object.assign({},h),{velocity:s,friction:void 0,tension:void 0})}:{config:Object.assign({velocity:0},g)}),{immediate:r,onRest:e=>{e.finished&&(Ie(!1),Ce(!1),o(),r||he({eventName:"onSlideChange",slideActionType:je(),currentItem:{index:"fluid"===F?-1:Se(),id:"fluid"===F?"":i[Se()].id}}))}})),v&&p&&!r&&be(t,je())}function De(){return Se()===i.length-1}function Le(e){if(Te("prev"),k.current=!1,"fluid"===F){if(k.current=!1,oe())return;const t=ie()+ce()+200;if(E){const t=$.current.scrollLeft-ce();We({customTo:t<0?0:t,from:$.current.scrollLeft,velocity:e})}else We(t>=0?o?{from:ie()-re()*i.length,velocity:e,customTo:ie()-re()*i.length+ce()}:{customTo:0,velocity:e}:{customTo:ie()+ce(),velocity:e})}else{if(!o&&0===Se()||B.current)return;ue()?We({from:ie()-ce()*i.length,to:i.length-1,velocity:e}):We({to:Ee(),velocity:e})}}function Pe(e){if(Te("next"),"fluid"===F){if(oe())return;const t=Math.abs(ie()-ce())+100>=H.current;if(E){const t=$.current.scrollLeft+ce()>H.current,n=$.current.scrollLeft+ce();We({velocity:e,customTo:t?H.current:n,from:$.current.scrollLeft})}else if(o&&Math.abs(ie()-ce())>=i.length*re()){const t=re()*i.length;We({from:ie()+t,customTo:ie()+t-ce(),velocity:e})}else{if(k.current)return;t?(k.current=!0,We({customTo:-H.current,velocity:e})):We({customTo:ie()-ce(),velocity:e})}}else{if(!o&&Se()===L.length-1||B.current)return;Math.abs(ie()-ce()+25)>H.current&&!Re()?k.current=!0:k.current?We({to:i.length-J.current,velocity:e}):De()?We({from:ie()+ce()*i.length,to:0,velocity:e}):We({to:Ae(),velocity:e})}}function $e(e){let t=0;if(t="string"==typeof e?i.findIndex((t=>t.id===e)):e,t>=i.length)throw Error("The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.");if(t===Se()||i.length!==X.current.length&&Se()<i.length)return;const n=Ne(X.current[Se()].id);Te(Ne(i[t].id)>n?"next":"prev"),We({to:t})}l((()=>{if(N%2==0&&Z.current)throw new Error("initialStartingPosition can be only used if itemsPerSlide is an even value.");if(_.current<0)throw new Error("draggingSlideTreshold must be greater than 0");if(_.current>ce()/2)throw new Error(`draggingSlideTreshold must be equal or less than the half of the width of an item, which is ${Math.floor(ce()/2)}`);if(J.current<1)throw new Error("The itemsPerSlide prop can't be less than 1.");if(J.current>i.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(U.current<0)throw new Error("The initialActiveItem cannot be less than 0.");if(U.current>i.length)throw new Error("The initialActiveItem cannot be greater than the total length of the items you provide.");m||console.warn("You set shouldResizeOnWindowResize={false}; be aware that the carousel could behave in a strange way if you also use the fullscreen functionality or if you change the mobile orientation.")})),l((()=>{function e(){document.hidden?B.current=!0:B.current=!1}return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),l((()=>{W.current=!1,H.current=se(),G.current=window.innerWidth,V.current=window.innerWidth,T>0&&(We({to:T,immediate:!0}),Oe(T),!o&&M.current&&(M.current.style.top="0px",M.current.style.left="0px"))})),c((()=>{T<i.length&&T!==P.current&&(We({to:T,immediate:!0}),Oe(T))}),[T]),c((()=>{if(m)return window.addEventListener("resize",fe),()=>{window.removeEventListener("resize",fe)}}),[m]),c((()=>{M.current&&("x"===ee.current&&(M.current.style.top="0px"),"y"===ee.current&&(M.current.style.left="0px"))}),[x]),c((()=>{H.current=se();!(i.length===X.current.length)&&i.length<X.current.length&&$e(i.length-1),X.current=i}),[se,i]);const Me=Object.assign({useListenToCustomEvent:de,getIsFullscreen:pe,enterFullscreen:ge,exitFullscreen:me,getIsAnimating:function(){return z.current},getIsDragging:Re,getIsNextItem:function(e){const t=Ne(e),n=Se();return o&&n===i.length-1?0===t:t===n+1},getIsPrevItem:function(e){const t=Ne(e),n=Se();return o&&0===n?t===i.length-1:t===n-1},slideToPrevItem(){Le()},slideToNextItem(){Pe()}},"fixed"===F?{slideToItem:$e,getIsActiveItem:e=>Ne(e)===Se(),getCurrentActiveItem:()=>({id:i[Se()].id,index:Se()})}:{}),qe=e.jsx(d.Provider,Object.assign({value:Me},{children:e.jsx("div",Object.assign({ref:$,className:"use-spring-carousel-main-wrapper","data-testid":"use-spring-carousel-wrapper"},E?{onWheel(){te[ee.current].stop()}}:{},{style:Object.assign({display:"flex",position:"relative",width:"100%",height:"100%"},E?"x"===ee.current?{overflowX:"auto"}:{overflowY:"auto"}:{})},{children:e.jsx(n.animated.div,Object.assign({},we(),{className:"use-spring-carousel-track-wrapper","data-testid":"use-spring-carousel-animated-wrapper",ref:e=>{e&&(M.current=e,le(e,U.current))},style:Object.assign(Object.assign(Object.assign({display:"flex",position:"relative",touchAction:O?"unset":I||("x"===ee.current?"pan-y":"pan-x"),flexDirection:"x"===ee.current?"row":"column"},function(){const e=`calc(100% - ${2*Q.current}px)`;return{width:"x"===ee.current?e:"100%",height:"y"===ee.current?e:"100%"}}()),function(){const e=i.length/N*100,t=100/N,n="x"===ee.current?"left":"y",r=Math.floor(50/t);if("fixed"===F){if("center"===Z.current)return{[n]:`calc(-${e}% + ${t*r}%)`};if("end"===Z.current)return{[n]:`calc(-${e}% + ${t*(2*r)}%)`}}return{[n]:"0px"}}()),E?{}:te)},{children:L.map((({id:t,renderItem:n},r)=>{return e.jsx("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:Object.assign({display:"flex",position:"relative"},(i=J.current,"fixed"===F?Object.assign(Object.assign({},"x"===ee.current?{marginRight:`${K.current}px`}:{marginBottom:`${K.current}px`}),{flex:`1 0 calc(100% / ${i} - ${K.current*(i-1)/i}px)`}):Object.assign({},"x"===ee.current?{marginRight:`${K.current}px`}:{marginBottom:`${K.current}px`})))},{children:n}),`${t}-${r}`);var i}))}))}))})),ze=e.jsx(d.Provider,Object.assign({value:Me},{children:ve}));return Object.assign(Object.assign({},Me),{carouselFragment:qe,thumbsFragment:ze})},exports.useSpringCarouselContext=function(){const e=t.useContext(d);if(!e)throw new Error("useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.");return e},exports.useTransitionCarousel=function({items:i,withLoop:o=!1,withThumbs:s=!1,springConfig:c=n.config.default,thumbsSlideAxis:l="x",enableThumbsWrapperScroll:d=!0,draggingSlideTreshold:h=50,prepareThumbsData:m,toPrevItemSpringProps:p,toNextItemSpringProps:v,disableGestures:b=!1,trail:x,exitBeforeEnter:y=!1,springAnimationProps:w={initial:{opacity:1,position:"absolute"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"absolute"},leave:{opacity:0,position:"absolute"}}}){const T=t.useRef("next"),j=t.useRef(null),O=t.useRef(!1),[S,C]=t.useState(0),{emitObservable:I,useListenToCustomEvent:R}=u(),{enterFullscreen:E,exitFullscreen:A,getIsFullscreen:N}=a({emitObservable:I,mainCarouselWrapperRef:j}),{thumbsFragment:F,handleThumbsScroll:W}=f({items:i,withThumbs:s,thumbsSlideAxis:l,springConfig:c,prepareThumbsData:m,slideType:"fixed"}),D=r.useDrag((({last:e,movement:[t]})=>{if(!P()&&e){const e=t>h,n=t<-h,r=0===S,s=S===i.length-1;if(n){if(!o&&s)return;z(),I({eventName:"onLeftSwipe"})}else if(e){if(!o&&r)return;B(),I({eventName:"onRightSwipe"})}}}),{enabled:!b}),L=n.useTransition(S,Object.assign(Object.assign({config:c},function(){const e=q();return"prev"===e&&p?{initial:Object.assign({},w.initial),from:Object.assign({},p.from),enter:Object.assign({},p.enter),leave:Object.assign({},p.leave)}:"next"===e&&v?{initial:Object.assign({},w.initial),from:Object.assign({},v.from),enter:Object.assign({},v.enter),leave:Object.assign({},v.leave)}:{initial:Object.assign({},w.initial),from:Object.assign({},w.from),enter:Object.assign({},w.enter),leave:Object.assign({},w.leave)}}()),{onStart:()=>$(!0),trail:x,exitBeforeEnter:y,key:i[S].id,onRest:e=>{e.finished&&($(!1),I({eventName:"onSlideChange",slideActionType:q(),currentItem:{index:S,id:i[S].id}}))}}))(((t,r)=>e.jsx(n.animated.div,Object.assign({style:Object.assign(Object.assign({},t),{flex:"1 0 100%",width:"100%",height:"100%"})},{children:i[r].renderItem}))));function P(){return O.current}function $(e){O.current=e}function M(e){T.current=e}function q(){return T.current}function z(){const e=S===i.length-1;o?(M("next"),e?(I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:0,id:i[0].id}}),C(0)):(I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S+1,id:i[S+1].id}}),C(S+1))):e||(I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S+1,id:i[S+1].id}}),M("next"),C(S+1))}function B(){const e=0===S;o?(M("prev"),e?(I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:i.length-1,id:i[i.length-1].id}}),C(i.length-1)):(I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S-1,id:i[S-1].id}}),C(S-1))):e||(M("prev"),I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:S-1,id:i[S-1].id}}),C(S-1))}function H(e){return i.findIndex((t=>t.id===e))}const k={activeItem:S,slideToItem:function(e){let t=0;if(t="string"==typeof e?i.findIndex((t=>t.id===e)):e,t>=i.length)throw Error("The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.");if(t===S)return;const n=H(i[S].id),r=H(i[t].id);I({eventName:"onSlideStartChange",slideActionType:q(),nextItem:{index:r,id:i[t].id}}),M(r>n?"next":"prev"),C(t),d&&s&&W(t)},slideToNextItem:z,slideToPrevItem:B,enterFullscreen:E,exitFullscreen:A,useListenToCustomEvent:R,getIsNextItem:function(e){const t=H(e);return o&&S===i.length-1?0===t:t===S+1},getIsPrevItem:function(e){const t=H(e);return o&&0===S?t===i.length-1:t===S-1},getIsAnimating:P,getIsFullscreen:N,getIsActiveItem:e=>H(e)===S,getCurrentActiveItem:()=>({id:i[S].id,index:S})},V=e.jsx(g.Provider,Object.assign({value:k},{children:e.jsx("div",Object.assign({ref:j},D(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:L}))})),G=e.jsx(g.Provider,Object.assign({value:k},{children:F}));return Object.assign({carouselFragment:V,thumbsFragment:G},k)},exports.useTransitionCarouselContext=function(){const e=t.useContext(g);if(!e)throw new Error("useTransitionCarouselContext isn't being used within the useTransitionCarousel context; \n use the context only inside a component that is rendered within the Carousel.");return e};
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("@react-spring/web"),r=require("react"),n=require("@use-gesture/react"),i=require("screenfull");function c({thumbsSlideAxis:n="x",withThumbs:i=!1,prepareThumbsData:c,items:u}){const o=r.useRef(null),[s,l]=t.useSpring((()=>({val:0})));function a(){var e;return Math.round(Number(null===(e=o.current)||void 0===e?void 0:e["x"===n?"scrollWidth":"scrollHeight"])-o.current.getBoundingClientRect()["x"===n?"width":"height"])}return{thumbsFragment:i?e.jsx("div",Object.assign({className:"use-spring-carousel-thumbs-wrapper",ref:o,onWheel:()=>s.val.stop(),style:Object.assign({display:"flex",flex:"1",position:"relative",width:"100%",height:"100%",flexDirection:"x"===n?"row":"column"},"x"===n?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"})},{children:function(){function e(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return c?c(e(u)):e(u)}().map((({id:t,renderThumb:r})=>{const n=`thumb-item-${t}`;return e.jsx("div",Object.assign({id:n,className:"thumb-item"},{children:r}),n)}))})):null,handleScroll:function(e){var t,r;const i=o.current?o.current.querySelector(`#thumb-item-${u[e].id}`):null;if(i&&o.current&&!function(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}(i)){const e=i.offsetLeft,c=e>a()?a():e;l.start({from:{val:null!==(r=null===(t=o.current)||void 0===t?void 0:t["x"===n?"scrollLeft":"scrollTop"])&&void 0!==r?r:0},to:{val:c},onChange:({value:e})=>{o.current&&(o.current["x"===n?"scrollLeft":"scrollTop"]=Math.abs(e.val))}})}}}}const u=r.createContext(void 0);exports.useSpringCarousel=function({items:u,init:o=!0,withThumbs:s,thumbsSlideAxis:l="x",itemsPerSlide:a=1,slideType:d="fixed",gutter:f=0,withLoop:v=!1,startEndGutter:m=0,carouselSlideAxis:g="x",disableGestures:h=!1,draggingSlideTreshold:x,slideWhenThresholdIsReached:p=!1,freeScroll:b,enableFreeScrollDrag:w,initialStartingPosition:y,prepareThumbsData:E,initialActiveItem:R=0}){const T=r.useRef(0),j=r.useRef(null!=x?x:0),C=r.useRef("initial"),I=r.useRef("initial"),S=r.useRef(0),[O,L]=t.useSpring((()=>({val:0,pause:!o,onChange({value:e}){b&&N.current?(ee(),"x"===g?N.current.scrollLeft=Math.abs(e.val):N.current.scrollTop=Math.abs(e.val)):$.current&&($.current.style.transform="x"===g?`translate3d(${e.val}px, 0px,0px)`:`translate3d(0px,${e.val}px,0px)`)}}))),M=r.useRef(R),F=r.useRef(0===R),A=r.useRef(!1),N=r.useRef(null),$=r.useRef(null),W=r.useCallback((()=>v?[...u.map((e=>Object.assign(Object.assign({},e),{id:`prev-repeated-item-${e.id}`}))),...u,...u.map((e=>Object.assign(Object.assign({},e),{id:`next-repeated-item-${e.id}`})))]:[...u]),[u,v])(),{emitEvent:q,useListenToCustomEvent:D}=function(){const e=r.useRef(null);return r.useEffect((()=>{e.current=document.createElement("div")}),[]),{useListenToCustomEvent:function(t){r.useEffect((()=>{function r(e){t(e.detail)}if(e.current)return e.current.addEventListener("RSC::Event",r,!1),()=>{var t;null===(t=e.current)||void 0===t||t.removeEventListener("RSC::Event",r,!1)}}),[])},emitEvent:function(t){if(e.current){const r=new CustomEvent("RSC::Event",{detail:t});e.current.dispatchEvent(r)}}}}(),{thumbsFragment:k,handleScroll:B}=c({withThumbs:!!s,thumbsSlideAxis:l,prepareThumbsData:E,items:u}),{enterFullscreen:H,exitFullscreen:z,getIsFullscreen:P}=function({mainCarouselWrapperRef:e,emitEvent:t,handleResize:n}){const c=r.useRef(!1);function u(e){c.current=e}return r.useEffect((()=>{function e(){document.fullscreenElement&&(u(!0),t({eventName:"onFullscreenChange",isFullscreen:!0}),n&&n()),document.fullscreenElement||(u(!1),t({eventName:"onFullscreenChange",isFullscreen:!1}),n&&n())}if(i.isEnabled)return i.on("change",e),()=>{i.isEnabled&&i.off("change",e)}}),[]),{enterFullscreen:function(t){i.isEnabled&&i.request(t||e.current)},exitFullscreen:function(){i.isEnabled&&i.exit()},getIsFullscreen:function(){return c.current}}}({mainCarouselWrapperRef:N,emitEvent:q,handleResize:()=>K()});function G(){var e;const t=null===(e=N.current)||void 0===e?void 0:e.querySelector(".use-spring-carousel-item");if(!t)throw Error("No carousel items available!");return t.getBoundingClientRect()["x"===g?"width":"height"]+f}function X({from:e,to:r,nextActiveItem:n,immediate:i=!1,slideMode:c}){I.current=c,"number"==typeof n&&(b||(M.current=n),q({eventName:"onSlideStartChange",slideActionType:C.current,slideMode:I.current,nextItem:{startReached:F.current,endReached:A.current,index:b?-1:M.current,id:b?"":u[M.current].id}})),S.current=r,L.start({immediate:i,from:{val:e},to:{val:r},config:Object.assign(Object.assign({},t.config.default),{velocity:O.val.velocity}),onRest(e){!i&&e.finished&&q({eventName:"onSlideChange",slideActionType:C.current,slideMode:I.current,currentItem:{startReached:F.current,endReached:A.current,index:b?-1:M.current,id:b?"":u[M.current].id}})}}),s&&!i&&B(M.current)}function Y(){var e;return v?G()*u.length:Math.round(Number(null===(e=$.current)||void 0===e?void 0:e["x"===g?"scrollWidth":"scrollHeight"])-$.current.getBoundingClientRect()["x"===g?"width":"height"])}function J(){var e;const t=null===(e=$.current)||void 0===e?void 0:e.querySelector(".use-spring-carousel-item");if(!t)throw Error("No carousel items available!");return t.getBoundingClientRect()["x"===g?"width":"height"]+f}function K(){const e="x"===g?"left":"top";function t(t){const r=$.current;r&&(v?(r.style.top="0px",r.style.left="0px",r.style[e]=`-${t-m}px`):(r.style.left="0px",r.style.top="0px"))}const r=Math.abs(Q());if(r<Y()&&A.current&&(A.current=!1),r>Y()){const e=-Y();return A.current=!0,S.current=e,void L.start({immediate:!0,val:e})}if(t("center"===y?J()*u.length-G()*Math.round((a-1)/2):"end"===y?J()*u.length-G()*Math.round(a-1):J()*u.length),!b&&"fixed"===d){const e=-G()*M.current;S.current=e,L.start({immediate:!0,val:e})}}function Q(){return b&&N.current?N.current["x"===g?"scrollLeft":"scrollTop"]:O.val.get()}function U(e,t){if(b&&"next"===e){const e=S.current+G();return e>Y()?Y():e}if(b&&"prev"===e){const e=S.current-G();return e<0?0:e}return"next"===e?t?-t*G():S.current-G():t?-t*G():S.current+G()}function V(e="click",t){if(!o||F.current&&!v)return;C.current="prev",A.current=!1;const r=t||M.current-1;if(!v){const r=U("prev",t)+G()/3>0;if(F.current)return;if(r)return F.current=!0,A.current=!1,void X({slideMode:e,from:Q(),to:0,nextActiveItem:0})}if(v&&F.current)return F.current=!1,A.current=!0,void X({slideMode:e,from:Q()-G()*u.length,to:-G()*u.length+G(),nextActiveItem:u.length-1});0===r&&(F.current=!0),r!==u.length-1&&-1!==r||(A.current=!0),X({slideMode:e,from:Q(),to:U("prev",t),nextActiveItem:r})}function Z(e="click",t){if(!o||A.current&&!v)return;C.current="next",F.current=!1;const r=t||M.current+1;if(!v){const n=Math.abs(U("next",t))>Y()-G()/3;if(A.current)return;if(n)return F.current=!1,A.current=!0,void X({slideMode:e,from:Q(),to:-Y(),nextActiveItem:r})}if(v&&A.current)return A.current=!1,F.current=!0,void X({slideMode:e,from:Q()+G()*u.length,to:0,nextActiveItem:0});0===r&&(F.current=!0),r===u.length-1&&(A.current=!0),X({slideMode:e,from:Q(),to:U("next",t),nextActiveItem:r})}r.useEffect((()=>{T.current=window.innerWidth}),[]),r.useEffect((()=>{K()}),[y,a,v,m,f,b,d,o]),r.useLayoutEffect((()=>{$.current&&K()}),[]),r.useEffect((()=>{j.current=x||Math.floor(G()/2/2)}),[x]),r.useEffect((()=>{function e(){window.innerWidth!==T.current&&(T.current=window.innerWidth,K())}return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}}),[]);const _=n.useDrag((e=>{const r=e.dragging,n=e.offset["x"===g?0:1],i=e.movement["x"===g?0:1],c=e.direction["x"===g?0:1],u=i>j.current,o=i<-j.current;if(r)return C.current=c>0?"prev":"next",q(Object.assign(Object.assign({},e),{eventName:"onDrag",slideActionType:C.current})),b?"prev"===C.current&&n>0?(e.cancel(),void L.start({from:{val:Q()},to:{val:0},config:{velocity:e.velocity,friction:50,tension:1e3}})):void L.start({from:{val:Q()},to:{val:-n},config:{velocity:e.velocity,friction:50,tension:1e3}}):(L.start({val:n,config:{velocity:e.velocity,friction:50,tension:1e3}}),void(p&&o?(Z("drag"),e.cancel()):p&&u&&(V("drag"),e.cancel())));e.last&&!e.canceled&&b&&("prev"===C.current&&V("drag"),"next"===C.current&&Z("drag")),!e.last||e.canceled||b||(o?!v&&A.current?L.start({val:-Y(),config:Object.assign(Object.assign({},t.config.default),{velocity:e.velocity})}):Z("drag"):u?!v&&F.current?L.start({val:0,config:Object.assign(Object.assign({},t.config.default),{velocity:e.velocity})}):V("drag"):L.start({val:S.current,config:Object.assign(Object.assign({},t.config.default),{velocity:e.velocity})}))}),{enabled:o&&!h&&!b||!!b&&!!w,axis:g,from:()=>b&&N.current?[-N.current.scrollLeft,-N.current.scrollTop]:[O.val.get(),O.val.get()]});function ee(){N.current&&(S.current=N.current["x"===g?"scrollLeft":"scrollTop"],0===N.current["x"===g?"scrollLeft":"scrollTop"]&&(F.current=!0,A.current=!1),N.current["x"===g?"scrollLeft":"scrollTop"]>0&&N.current["x"===g?"scrollLeft":"scrollTop"]<Y()&&(F.current=!1,A.current=!1),N.current["x"===g?"scrollLeft":"scrollTop"]===Y()&&(F.current=!1,A.current=!0))}function te(e){return u.findIndex((t=>t.id===e))}function re(e,t){let r=0;if(r="string"==typeof e?u.findIndex((t=>t.id===e)):e,r<0||r>=u.length)throw new Error(t);return r}return{useListenToCustomEvent:D,carouselFragment:e.jsx("div",Object.assign({ref:N},b?{onWheel(){O.val.stop(),ee()}}:{},{style:Object.assign({display:"flex",position:"relative",width:"100%",height:"100%"},b?"x"===g?{overflowX:"auto"}:{overflowY:"auto"}:{})},{children:e.jsx("div",Object.assign({ref:$},_(),{style:Object.assign({position:"relative",display:"flex",flexDirection:"x"===g?"row":"column",touchAction:"none"},function(){const e=`calc(100% - ${2*m}px)`;return{width:"x"===g?e:"100%",height:"y"===g?e:"100%"}}())},{children:W.map(((t,r)=>e.jsx("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:Object.assign({display:"flex",position:"relative",flex:"1"},"fixed"!==d||b?Object.assign({marginRight:`${f}px`}):{marginRight:`${f}px`,flex:`1 0 calc(100% / ${a} - ${f*(a-1)/a}px)`})},{children:t.renderItem}),`${t.id}-${r}`)))}))})),enterFullscreen:H,exitFullscreen:z,getIsFullscreen:P,thumbsFragment:k,slideToItem:function(e){if(!o)return;F.current=!1,A.current=!1;const t=re(e,"The item you want to slide to doesn't exist; please check che item id or the index you're passing to.");if(t===M.current)return;const r=te(u[M.current].id),n=te(u[t].id);n>r?Z("click",n):V("click",n)},getIsNextItem:function(e){const t=te(e),r=M.current;return v&&r===u.length-1?0===t:t===r+1},getIsPrevItem:function(e){const t=te(e),r=M.current;return v&&0===r?t===u.length-1:t===r-1},slideToPrevItem:()=>V(),slideToNextItem:()=>Z(),getIsActiveItem:e=>re(e,"The item you want to check doesn't exist")===M.current}},exports.useSpringCarouselContext=function(){const e=r.useContext(u);if(!e)throw new Error("useSpringCarouselContext must be used within the carousel.");return e};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/modules/useCustomEventsModule.tsx","../../src/utils.ts","../../src/modules/useFullscreenModule.tsx","../../src/modules/useThumbsModule.tsx","../../src/useSpringCarousel/index.tsx","../../src/useTransitionCarousel/index.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport {\n UseSpringCarouselEventsObservableProps,\n UseTransitionCarouselEventsObservableProps,\n ObservableCallbackFn,\n EmitObservableFn,\n} from '../types'\n\nexport function useCustomEventsModule<T>() {\n const eventsObserverRef = useRef(\n new Subject<\n T extends 'use-spring'\n ? UseSpringCarouselEventsObservableProps\n : UseTransitionCarouselEventsObservableProps\n >(),\n )\n\n function useListenToCustomEvent(fn: ObservableCallbackFn<T>) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn<T> = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, useLayoutEffect, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nconst useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nfunction useIsomorphicMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useIsomorphicLayoutEffect(() => {\n if (!isMounted.current) {\n const clean = callback()\n isMounted.current = true\n\n return () => {\n clean && clean()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n}\n\nexport { useIsomorphicLayoutEffect, useIsomorphicMount }\n","import { useRef, MutableRefObject } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\nimport { useIsomorphicMount } from '../utils'\n\ntype FullscreenModule<T> = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn<T>\n handleResize?(): void\n}\n\nexport function useFullscreenModule<T>({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule<T>) {\n const isFullscreen = useRef(false)\n\n useIsomorphicMount(() => {\n function handleFullscreenChange() {\n if (document.fullscreenElement) {\n setIsFullscreen(true)\n emitObservable({\n eventName: 'onFullscreenChange',\n isFullscreen: true,\n })\n\n handleResize && handleResize()\n }\n\n if (!document.fullscreenElement) {\n setIsFullscreen(false)\n emitObservable({\n eventName: 'onFullscreenChange',\n isFullscreen: false,\n })\n handleResize && handleResize()\n }\n }\n\n if (screenfull.isEnabled) {\n screenfull.on('change', handleFullscreenChange)\n return () => {\n if (screenfull.isEnabled) {\n screenfull.off('change', handleFullscreenChange)\n }\n }\n }\n })\n\n function setIsFullscreen(_isFullscreen: boolean) {\n isFullscreen.current = _isFullscreen\n }\n\n function getIsFullscreen() {\n return isFullscreen.current\n }\n\n function enterFullscreen(elementRef?: HTMLElement) {\n if (screenfull.isEnabled) {\n screenfull.request((elementRef || mainCarouselWrapperRef.current) as Element)\n }\n }\n\n function exitFullscreen() {\n screenfull.isEnabled && screenfull.exit()\n }\n\n return {\n enterFullscreen,\n exitFullscreen,\n getIsFullscreen,\n }\n}\n","import { useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport { useIsomorphicMount } from 'src/utils'\nimport { UseSpringCarouselProps, SlideActionType } from '../types'\nimport { ReactSpringCarouselItemWithThumbs } from '../types/useSpringCarousel'\nimport { PrepareThumbsData } from '../types/index'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: ReactSpringCarouselItemWithThumbs[]\n withThumbs: boolean\n slideType: UseSpringCarouselProps['slideType']\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n springConfig: SpringConfig\n prepareThumbsData?: UseSpringCarouselProps['prepareThumbsData']\n getFluidWrapperScrollValue?(): number\n getSlideValue?(): number\n}\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n prepareThumbsData,\n getFluidWrapperScrollValue = () => 0,\n getSlideValue = () => 0,\n slideType,\n}: Props) {\n const internalThumbsWrapperRef = useRef<HTMLDivElement | null>(null)\n const [thumbListStyles, setThumbListStyles] = useSpring(() => ({\n x: 0,\n y: 0,\n config: springConfig,\n onChange: ({ value }) => {\n if (internalThumbsWrapperRef.current && slideType === 'fluid') {\n internalThumbsWrapperRef.current[\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[thumbsSlideAxis])\n }\n },\n }))\n\n useIsomorphicMount(() => {\n if (withThumbs && !internalThumbsWrapperRef.current) {\n throw new Error(\n \"The thumbs wrapper is not defined. If you've passed a Functional component, be sure to wrap your component in forwardRef.\",\n )\n }\n })\n\n function getCurrentThumbScrollValue() {\n return internalThumbsWrapperRef.current![\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n function getThumbsTotalScrollableValue() {\n return Math.round(\n Number(\n internalThumbsWrapperRef.current?.[\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n ],\n ) -\n internalThumbsWrapperRef.current!.getBoundingClientRect()[\n thumbsSlideAxis === 'x' ? 'width' : 'height'\n ],\n )\n }\n\n function getThumbSlideValue() {\n const thumbSlideTotal = Math.round(getFluidWrapperScrollValue() / getSlideValue())\n const totalScrollableValue = getThumbsTotalScrollableValue()\n return totalScrollableValue / thumbSlideTotal\n }\n\n function handleThumbsScroll(activeItem: number, actionType?: SlideActionType) {\n if (slideType === 'fluid') {\n const totalScrollableValue = getThumbsTotalScrollableValue()\n\n if (actionType === 'next') {\n const nextValue = getCurrentThumbScrollValue() + getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]:\n nextValue > totalScrollableValue ? totalScrollableValue : nextValue,\n },\n })\n }\n if (actionType === 'prev') {\n const nextValue = getCurrentThumbScrollValue() - getThumbSlideValue()\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getCurrentThumbScrollValue(),\n },\n to: {\n [thumbsSlideAxis]: nextValue < 0 ? 0 : nextValue,\n },\n })\n }\n } else {\n function getOffsetDirection() {\n return thumbsSlideAxis === 'x' ? 'offsetLeft' : 'offsetTop'\n }\n function getOffsetDimension() {\n return thumbsSlideAxis === 'x' ? 'offsetWidth' : 'offsetHeight'\n }\n function getScrollDirecton() {\n return thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n }\n function getThumbNode() {\n return internalThumbsWrapperRef.current!.querySelector(\n `#thumb-${items[activeItem].id}`,\n ) as HTMLElement\n }\n function getThumbOffsetPosition({\n thumbNode,\n offsetDirection,\n offsetDimension,\n }: {\n thumbNode: HTMLElement\n offsetDirection: OffsetDirection\n offsetDimension: OffsetDimension\n }) {\n return thumbNode[offsetDirection] + thumbNode[offsetDimension] / 2\n }\n function getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n offsetDimension: OffsetDimension\n }) {\n return thumbWrapper[offsetDimension] / 2\n }\n function getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }: {\n thumbWrapper: HTMLDivElement\n scrollDirection: ScrollDirection\n }) {\n return thumbWrapper[scrollDirection]\n }\n function getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }: {\n thumbWrapper: HTMLDivElement\n thumbOffsetPosition: number\n thumbScrollDimension: number\n offsetDimension: OffsetDimension\n }) {\n const scrollDimensionProperty =\n thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight'\n\n if (\n activeItem === items.length - 1 ||\n thumbOffsetPosition - thumbScrollDimension >\n thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n ) {\n return thumbWrapper[scrollDimensionProperty] - thumbWrapper[offsetDimension]\n }\n if (activeItem === 0) {\n return 0\n }\n\n return thumbOffsetPosition - thumbScrollDimension\n }\n\n const thumbNode = getThumbNode()\n\n if (thumbNode) {\n const thumbWrapper = internalThumbsWrapperRef.current!\n const offsetDirection = getOffsetDirection()\n const offsetDimension = getOffsetDimension()\n const scrollDirection = getScrollDirecton()\n const thumbOffsetPosition = getThumbOffsetPosition({\n thumbNode,\n offsetDimension,\n offsetDirection,\n })\n const thumbScrollDimension = getThumbScrollDimension({\n thumbWrapper,\n offsetDimension,\n })\n\n const fromValue = getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n })\n const toValue = getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n })\n\n setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: fromValue,\n },\n to: {\n [thumbsSlideAxis]: actionType === 'prev' && toValue < 0 ? 0 : toValue,\n },\n onChange: ({ value }) => {\n if (thumbsSlideAxis === 'x') {\n internalThumbsWrapperRef!.current!.scrollLeft = value.x\n } else {\n internalThumbsWrapperRef!.current!.scrollTop = value.y\n }\n },\n })\n }\n }\n }\n function handlePrepareThumbsData() {\n function getPreparedItems(\n _items: ReturnType<PrepareThumbsData>,\n ): ReturnType<PrepareThumbsData> {\n return _items.map(i => ({\n id: i.id,\n renderThumb: i.renderThumb,\n }))\n }\n\n if (prepareThumbsData) {\n return prepareThumbsData(getPreparedItems(items))\n }\n return getPreparedItems(items)\n }\n\n const thumbsFragment = withThumbs ? (\n <animated.div\n ref={internalThumbsWrapperRef}\n className=\"use-spring-carousel-thumbs-wrapper\"\n onWheel={() => {\n thumbListStyles[thumbsSlideAxis].stop()\n }}\n style={{\n display: 'flex',\n flex: 1,\n position: 'relative',\n width: '100%',\n height: '100%',\n flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsData().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId} className=\"thumb-item\">\n {renderThumb}\n </div>\n )\n })}\n </animated.div>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n","import { useRef, createContext, useContext } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from '../modules'\nimport {\n SlideToItemFnProps,\n SlideActionType,\n UseSpringFixedSlideTypeReturnProps,\n} from '../types'\nimport { useIsomorphicLayoutEffect, useIsomorphicMount } from '../utils'\nimport {\n UseSpringCarouselProps,\n ReactSpringCarouselItemWithThumbs,\n UseSpringFluidSlideTypeReturnProps,\n UseSpringCarouselBaseProps,\n UseSpringCarouselWithThumbs,\n UseSpringCarouselFluidType,\n DisableGesturesProps,\n WithLoopProps,\n UseSpringCarouselWithNoThumbs,\n EnableGesturesProps,\n WithNoLoop,\n UseSpringCarouselFixedSlideType,\n} from '../types/useSpringCarousel'\n\ntype ReturnType<T> = T extends 'fixed'\n ? UseSpringFixedSlideTypeReturnProps\n : UseSpringFluidSlideTypeReturnProps\ntype ContextTypes<T> = Omit<ReturnType<T>, 'carouselFragment' | 'thumbsFragment'>\n\nconst Context = createContext<ContextTypes<'fixed' | 'fluid'> | undefined>(undefined)\n\nconst defaultDragSpringConfig = {\n ...config.default,\n mass: 1,\n velocity: 0,\n}\n\nfunction useSpringCarousel(\n props: UseSpringCarouselBaseProps &\n UseSpringCarouselFluidType &\n (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) &\n (DisableGesturesProps | EnableGesturesProps) &\n (WithLoopProps | WithNoLoop),\n): ReturnType<'fluid'>\nfunction useSpringCarousel(\n props: UseSpringCarouselBaseProps &\n UseSpringCarouselFixedSlideType &\n (UseSpringCarouselWithThumbs | UseSpringCarouselWithNoThumbs) &\n (DisableGesturesProps | EnableGesturesProps) &\n (WithLoopProps | WithNoLoop),\n): ReturnType<'fixed'>\n\nfunction useSpringCarousel({\n items,\n withLoop = false,\n draggingSlideTreshold,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n slideWhenThresholdIsReached = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n prepareThumbsData,\n initialActiveItem = 0,\n initialStartingPosition,\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction,\n slideAmount,\n freeScroll = false,\n enableFreeScrollDrag,\n itemsPerSlide = 1,\n slideType = 'fixed',\n}: UseSpringCarouselProps): ReturnType<'fixed' | 'fluid'> {\n function getItems() {\n if (withLoop) {\n if (items.length === itemsPerSlide) {\n return [...items, ...items, ...items, ...items, ...items]\n }\n return [...items, ...items, ...items]\n }\n return items\n }\n\n const isFirstMount = useRef(true)\n const slideActionType = useRef<SlideActionType>('initial' as SlideActionType)\n const internalItems = getItems()\n const activeItem = useRef(initialActiveItem)\n const mainCarouselWrapperRef = useRef<HTMLDivElement | null>(null)\n const carouselTrackWrapperRef = useRef<HTMLDivElement | null>(null)\n const isDragging = useRef(false)\n const isAnimating = useRef(false)\n const windowIsHidden = useRef(false)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideEndReached = useRef(false)\n const currentWindowWidth = useRef(0)\n const initialWindowWidth = useRef(0)\n const prevSlidedValue = useRef(0)\n const prevItems = useRef(items)\n\n /**\n * Instead of raw values, we store it in\n * useRef for performances reasons during external rerenders\n */\n const draggingSlideTresholdRef = useRef<number>(draggingSlideTreshold ?? 0)\n const itemsPerSlideRef = useRef(itemsPerSlide)\n const gutterRef = useRef(gutter)\n const startEndGutterRef = useRef(startEndGutter)\n const initialActiveItemRef = useRef(initialActiveItem)\n const initialStartingPositionRef = useRef(initialStartingPosition)\n const carouselSlideAxisRef = useRef(carouselSlideAxis)\n\n /**\n * Update inner values during external rerenders!\n */\n itemsPerSlideRef.current = itemsPerSlide\n gutterRef.current = gutter\n startEndGutterRef.current = startEndGutter\n initialActiveItemRef.current = initialActiveItem\n initialStartingPositionRef.current = initialStartingPosition\n carouselSlideAxisRef.current = carouselSlideAxis\n\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n onChange: ({ value }) => {\n if (mainCarouselWrapperRef.current && freeScroll) {\n mainCarouselWrapperRef.current[\n carouselSlideAxisRef.current === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[carouselSlideAxisRef.current])\n }\n },\n }))\n\n useIsomorphicLayoutEffect(() => {\n if (draggingSlideTreshold) {\n draggingSlideTresholdRef.current = draggingSlideTreshold\n } else {\n draggingSlideTresholdRef.current = Math.floor(getSlideValue() / 2 / 2)\n }\n\n resize()\n }, [\n draggingSlideTreshold,\n itemsPerSlide,\n gutter,\n startEndGutter,\n initialActiveItem,\n initialStartingPosition,\n carouselSlideAxis,\n thumbsSlideAxis,\n ])\n\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n function getMainCarouselWrapperWidth() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('mainCarouselWrapperRef is not available')\n }\n return mainCarouselWrapperRef.current.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ]\n }\n function getCarouselItemWidth() {\n const carouselItem = getCarouselItem()\n if (!carouselItem) {\n throw Error('No carousel items available!')\n }\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ] + gutterRef.current\n )\n }\n function getCurrentSlidedValue() {\n return carouselStyles[carouselSlideAxisRef.current].get()\n }\n function getIfItemsNotFillTheCarousel() {\n return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth()\n }\n function getFluidWrapperScrollValue() {\n return Math.round(\n Number(\n carouselTrackWrapperRef.current?.[\n carouselSlideAxisRef.current === 'x' ? 'scrollWidth' : 'scrollHeight'\n ],\n ) -\n carouselTrackWrapperRef.current!.getBoundingClientRect()[\n carouselSlideAxisRef.current === 'x' ? 'width' : 'height'\n ],\n )\n }\n function getIsFirstItem() {\n return getCurrentActiveItem() === 0\n }\n function getSlideValue() {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const itemVal = getCarouselItemWidth()\n\n if (slideType === 'fluid' && typeof slideAmount === 'number') {\n if (slideAmount < itemVal) {\n throw new Error('slideAmount must be greater than the width of a single item.')\n }\n return slideAmount\n }\n return itemVal\n }\n function adjustCarouselWrapperPosition(\n ref: HTMLDivElement,\n _initialActiveItem?: number,\n ) {\n const positionProperty = carouselSlideAxisRef.current === 'x' ? 'left' : 'top'\n function getDefaultPositionValue() {\n return getCarouselItemWidth() * items.length\n }\n function setPosition(v: number) {\n if (withLoop) {\n ref.style.top = '0px'\n ref.style[positionProperty] = `-${v - startEndGutterRef.current}px`\n } else {\n ref.style.left = '0px'\n ref.style.top = '0px'\n if (_initialActiveItem && isFirstMount.current) {\n ref.style[positionProperty] = `calc(-${_initialActiveItem} * 100%)`\n }\n }\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n\n if (slideType === 'fixed') {\n function setCenterPosition(i: number) {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((i as number) - 1) / 2),\n )\n }\n function setEndPosition(i: number) {\n setPosition(\n getDefaultPositionValue() - getSlideValue() * Math.round((i as number) - 1),\n )\n }\n\n if (itemsPerSlideRef.current > 1) {\n switch (initialStartingPositionRef.current) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition(itemsPerSlideRef.current)\n break\n }\n case 'end': {\n setEndPosition(itemsPerSlideRef.current)\n break\n }\n }\n } else {\n setStartPosition()\n }\n } else {\n setStartPosition()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function resize() {\n currentWindowWidth.current = window.innerWidth\n\n if (slideType === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: 0,\n })\n return\n }\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n\n if (slideEndReached.current) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: nextValue,\n })\n }\n\n initialWindowWidth.current = window.innerWidth\n } else {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxisRef.current]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n function handleResize() {\n if (window.innerWidth === currentWindowWidth.current || freeScroll) {\n return\n }\n resize()\n }\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule<'use-spring'>()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } =\n useFullscreenModule<'use-spring'>({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items: items as ReactSpringCarouselItemWithThumbs[],\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n slideType,\n getFluidWrapperScrollValue,\n getSlideValue,\n })\n\n function getWrapperScrollDirection() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('Missing mainCarouselWrapperRef.current')\n }\n return mainCarouselWrapperRef.current[\n carouselSlideAxisRef.current === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n function getIfShouldEnableFluidDrag() {\n if (typeof enableFreeScrollDrag === 'boolean') {\n return enableFreeScrollDrag\n } else if (typeof enableFreeScrollDrag === 'function') {\n return enableFreeScrollDrag()\n }\n return false\n }\n\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.offset[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n const currentMovement = props.movement[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n const prevItemTreshold = currentMovement > draggingSlideTresholdRef.current\n const nextItemTreshold = currentMovement < -draggingSlideTresholdRef.current\n const direction = props.direction[carouselSlideAxisRef.current === 'x' ? 0 : 1]\n function cancelDrag() {\n props.cancel()\n }\n function setDragDirection() {\n if (direction > 0) {\n setSlideActionType('prev')\n } else {\n setSlideActionType('next')\n }\n }\n function emitDragObservable() {\n emitObservable({\n eventName: 'onDrag',\n slideActionType: getSlideActionType(),\n ...props,\n })\n }\n function resetAnimation() {\n if (slideType === 'fluid') {\n if (\n getIfItemsNotFillTheCarousel() ||\n (getIsFirstItem() && getSlideActionType() === 'prev')\n ) {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: 0,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n } else if (slideEndReached.current && getSlideActionType() === 'next') {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -fluidTotalWrapperScrollValue.current,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: prevSlidedValue.current,\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -(getCurrentActiveItem() * getSlideValue()),\n config: {\n velocity: props.velocity,\n ...springConfig,\n },\n })\n }\n }\n function checkBounds() {\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue()) + 100 >= fluidTotalWrapperScrollValue.current\n\n if (nextItemWillExceed && getSlideActionType() === 'next') {\n slideEndReached.current = true\n }\n if (getSlideActionType() === 'prev') {\n slideEndReached.current = false\n }\n }\n\n if (freeScroll && getIfShouldEnableFluidDrag()) {\n if (isDragging) {\n if (!getIsDragging()) {\n setIsDragging(true)\n }\n\n setDragDirection()\n emitDragObservable()\n checkBounds()\n }\n\n setCarouselStyles.start({\n from: {\n [carouselSlideAxisRef.current]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxisRef.current]: -movement,\n },\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1400,\n },\n })\n\n if (getWrapperScrollDirection() === 0 && getSlideActionType() === 'prev') {\n cancelDrag()\n return\n }\n if (props.last) {\n if (getSlideActionType() === 'prev') {\n slideToPrevItem(props.velocity)\n } else {\n slideToNextItem(props.velocity)\n }\n setIsDragging(false)\n }\n return\n }\n\n if (isDragging) {\n if (!getIsDragging()) {\n setIsDragging(true)\n }\n\n emitDragObservable()\n setDragDirection()\n checkBounds()\n\n if (freeScroll) {\n if (getIfShouldEnableFluidDrag()) {\n if (getWrapperScrollDirection() === 0 && getSlideActionType() === 'prev') {\n cancelDrag()\n return\n } else {\n setCarouselStyles.start({\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1400,\n },\n from: {\n [carouselSlideAxisRef.current]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxisRef.current]: -movement,\n },\n })\n }\n }\n return\n } else {\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: movement,\n config: {\n velocity: props.velocity,\n friction: 50,\n tension: 1000,\n },\n })\n }\n\n if (\n (prevItemTreshold || nextItemTreshold) &&\n getIfItemsNotFillTheCarousel() &&\n slideType === 'fluid'\n ) {\n cancelDrag()\n resetAnimation()\n } else if (\n slideEndReached.current &&\n getSlideActionType() === 'next' &&\n nextItemTreshold\n ) {\n slideEndReached.current = false\n cancelDrag()\n setCarouselStyles.start({\n [carouselSlideAxisRef.current]: -fluidTotalWrapperScrollValue.current,\n })\n } else if (slideWhenThresholdIsReached) {\n if (nextItemTreshold) {\n cancelDrag()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem(props.velocity)\n }\n return\n } else if (prevItemTreshold) {\n cancelDrag()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem(props.velocity)\n }\n return\n }\n }\n }\n\n if (\n props.last &&\n !slideWhenThresholdIsReached &&\n (nextItemTreshold || prevItemTreshold) &&\n !freeScroll\n ) {\n setIsDragging(false)\n if (nextItemTreshold) {\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem(props.velocity)\n }\n } else if (prevItemTreshold) {\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem(props.velocity)\n }\n }\n return\n }\n\n if (props.last && !nextItemTreshold && !prevItemTreshold) {\n if (!freeScroll) {\n resetAnimation()\n emitObservable({\n eventName: 'onDrag',\n slideActionType: getSlideActionType(),\n ...props,\n })\n }\n }\n },\n {\n enabled: !disableGestures,\n axis: carouselSlideAxisRef.current,\n from: () => {\n if (freeScroll) {\n if (carouselSlideAxisRef.current === 'x') {\n return [-getWrapperScrollDirection(), 0]\n }\n return [0, -getWrapperScrollDirection()]\n }\n return [carouselStyles.x.get(), carouselStyles.y.get()]\n },\n },\n )\n\n function setSlideActionType(type: SlideActionType) {\n slideActionType.current = type\n }\n function getSlideActionType() {\n return slideActionType.current\n }\n function setActiveItem(newItem: number) {\n activeItem.current = newItem\n }\n function getCurrentActiveItem() {\n return activeItem.current\n }\n function getIsAnimating() {\n return isAnimating.current\n }\n function setIsAnimating(val: boolean) {\n isAnimating.current = val\n }\n function setIsDragging(val: boolean) {\n isDragging.current = val\n }\n function getIsDragging() {\n return isDragging.current\n }\n function getPrevItem() {\n const currentActiveItem = getCurrentActiveItem()\n if (currentActiveItem === 0) {\n return items.length - 1\n }\n return currentActiveItem - 1\n }\n function getNextItem() {\n const currentActiveItem = getCurrentActiveItem()\n if (currentActiveItem === items.length - 1) {\n return 0\n }\n return currentActiveItem + 1\n }\n function getIsNextItem(id: string) {\n const itemIndex = findItemIndex(id)\n const activeItem = getCurrentActiveItem()\n if (withLoop && activeItem === items.length - 1) {\n return itemIndex === 0\n }\n return itemIndex === activeItem + 1\n }\n function getIsPrevItem(id: string) {\n const itemIndex = findItemIndex(id)\n const activeItem = getCurrentActiveItem()\n if (withLoop && activeItem === 0) {\n return itemIndex === items.length - 1\n }\n return itemIndex === activeItem - 1\n }\n function findItemIndex(id: string) {\n return items.findIndex(item => item.id === id)\n }\n function getFromValue(from: SlideToItemFnProps['from']) {\n if (typeof from === 'number') {\n return {\n from: {\n [carouselSlideAxisRef.current]: from,\n },\n }\n }\n return {}\n }\n function getToValue(\n customTo: SlideToItemFnProps['customTo'],\n to: SlideToItemFnProps['to'],\n ) {\n if (typeof customTo === 'number') {\n return {\n [carouselSlideAxisRef.current]: customTo,\n }\n }\n if (typeof to !== 'number') {\n throw new Error(`to values is not a number!`)\n }\n return {\n [carouselSlideAxisRef.current]: -(getSlideValue() * to!),\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function slideToItem({\n from,\n to = -1,\n customTo,\n immediate = false,\n onRest = () => {},\n velocity,\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: slideType === 'fluid' ? -1 : to,\n id: slideType === 'fluid' ? '' : items[to].id,\n },\n })\n }\n prevSlidedValue.current = getToValue(customTo, to)[carouselSlideAxis]\n setCarouselStyles.start({\n ...getFromValue(from),\n to: getToValue(customTo, to),\n ...(velocity\n ? {\n config: {\n ...defaultDragSpringConfig,\n velocity,\n friction: undefined,\n tension: undefined,\n },\n }\n : {\n config: {\n velocity: 0,\n ...springConfig,\n },\n }),\n immediate,\n onRest: val => {\n if (val.finished) {\n setIsDragging(false)\n setIsAnimating(false)\n onRest()\n if (!immediate) {\n emitObservable({\n eventName: 'onSlideChange',\n slideActionType: getSlideActionType(),\n currentItem: {\n index: slideType === 'fluid' ? -1 : getCurrentActiveItem(),\n id: slideType === 'fluid' ? '' : items[getCurrentActiveItem()].id,\n },\n })\n }\n }\n },\n })\n if (enableThumbsWrapperScroll && withThumbs && !immediate) {\n handleThumbsScroll(to, getSlideActionType())\n }\n }\n function getIsLastItem() {\n return getCurrentActiveItem() === items.length - 1\n }\n function slideToPrevItem(velocity?: number[]) {\n setSlideActionType('prev')\n slideEndReached.current = false\n\n if (slideType === 'fluid') {\n slideEndReached.current = false\n\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n const nextPrevValue = getCurrentSlidedValue() + getSlideValue() + 200\n\n if (freeScroll) {\n const nextValue = mainCarouselWrapperRef.current!.scrollLeft - getSlideValue()\n slideToItem({\n customTo: nextValue < 0 ? 0 : nextValue,\n from: mainCarouselWrapperRef.current!.scrollLeft,\n velocity,\n })\n } else if (nextPrevValue >= 0) {\n if (withLoop) {\n slideToItem({\n from: getCurrentSlidedValue() - getCarouselItemWidth() * items.length,\n velocity,\n customTo:\n getCurrentSlidedValue() -\n getCarouselItemWidth() * items.length +\n getSlideValue(),\n })\n } else {\n slideToItem({\n customTo: 0,\n velocity,\n })\n }\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() + getSlideValue(),\n velocity,\n })\n }\n } else {\n if ((!withLoop && getCurrentActiveItem() === 0) || windowIsHidden.current) {\n return\n }\n\n if (getIsFirstItem()) {\n slideToItem({\n from: getCurrentSlidedValue() - getSlideValue() * items.length,\n to: items.length - 1,\n velocity,\n })\n } else {\n slideToItem({\n to: getPrevItem(),\n velocity,\n })\n }\n }\n }\n function slideToNextItem(velocity?: number[]) {\n setSlideActionType('next')\n\n if (slideType === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue() - getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (freeScroll) {\n const nextValue = mainCarouselWrapperRef.current!.scrollLeft + getSlideValue()\n const willExceed = nextValue > fluidTotalWrapperScrollValue.current\n const val = mainCarouselWrapperRef.current!.scrollLeft + getSlideValue()\n\n slideToItem({\n velocity,\n customTo: willExceed ? fluidTotalWrapperScrollValue.current : val,\n from: mainCarouselWrapperRef.current!.scrollLeft,\n })\n } else if (\n withLoop &&\n Math.abs(getCurrentSlidedValue() - getSlideValue()) >=\n items.length * getCarouselItemWidth()\n ) {\n const currentWidth = getCarouselItemWidth() * items.length\n slideToItem({\n from: getCurrentSlidedValue() + currentWidth,\n customTo: getCurrentSlidedValue() + currentWidth - getSlideValue(),\n velocity,\n })\n } else if (slideEndReached.current) {\n return\n } else if (nextItemWillExceed) {\n slideEndReached.current = true\n slideToItem({\n customTo: -fluidTotalWrapperScrollValue.current,\n velocity,\n })\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() - getSlideValue(),\n velocity,\n })\n }\n } else {\n if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n }\n\n const nextItemWillExceed =\n Math.abs(getCurrentSlidedValue() - getSlideValue() + 25) >\n fluidTotalWrapperScrollValue.current\n\n if (nextItemWillExceed && !getIsDragging()) {\n slideEndReached.current = true\n } else if (slideEndReached.current) {\n slideToItem({\n to: items.length - itemsPerSlideRef.current,\n velocity,\n })\n } else if (getIsLastItem()) {\n slideToItem({\n from: getCurrentSlidedValue() + getSlideValue() * items.length,\n to: 0,\n velocity,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n velocity,\n })\n }\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n function _slideToItem(item: string | number) {\n let itemIndex = 0\n\n if (typeof item === 'string') {\n itemIndex = items.findIndex(_item => _item.id === item)\n } else {\n itemIndex = item\n }\n\n if (itemIndex >= items.length) {\n throw Error(\n `The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.`,\n )\n }\n\n if (\n itemIndex === getCurrentActiveItem() ||\n (items.length !== prevItems.current.length && getCurrentActiveItem() < items.length)\n ) {\n return\n }\n\n const currentItem = findItemIndex(prevItems.current[getCurrentActiveItem()].id)\n const newActiveItem = findItemIndex(items[itemIndex].id)\n\n if (newActiveItem > currentItem) {\n setSlideActionType('next')\n } else {\n setSlideActionType('prev')\n }\n\n slideToItem({\n to: itemIndex,\n })\n }\n function getItemStyles(_itemsPerSlide: number) {\n if (slideType === 'fixed') {\n return {\n ...(carouselSlideAxisRef.current === 'x'\n ? { marginRight: `${gutterRef.current}px` }\n : { marginBottom: `${gutterRef.current}px` }),\n flex: `1 0 calc(100% / ${_itemsPerSlide} - ${\n (gutterRef.current * (_itemsPerSlide - 1)) / _itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxisRef.current === 'x'\n ? { marginRight: `${gutterRef.current}px` }\n : { marginBottom: `${gutterRef.current}px` }),\n }\n }\n function getAnimatedWrapperStyles() {\n const percentValue = `calc(100% - ${startEndGutterRef.current * 2}px)`\n return {\n width: carouselSlideAxisRef.current === 'x' ? percentValue : '100%',\n height: carouselSlideAxisRef.current === 'y' ? percentValue : '100%',\n }\n }\n function getOverflowStyles() {\n if (freeScroll) {\n if (carouselSlideAxisRef.current === 'x') {\n return {\n overflowX: 'auto',\n }\n }\n return {\n overflowY: 'auto',\n }\n }\n return {}\n }\n function getWheelEvent() {\n if (freeScroll) {\n return {\n onWheel() {\n carouselStyles[carouselSlideAxisRef.current].stop()\n },\n }\n }\n return {}\n }\n function getTouchAction() {\n if (disableGestures) {\n return 'unset'\n } else if (!touchAction) {\n if (carouselSlideAxisRef.current === 'x') {\n return 'pan-y'\n }\n return 'pan-x'\n }\n return touchAction\n }\n // Perform some check on first mount\n useIsomorphicMount(() => {\n if (itemsPerSlide % 2 === 0 && initialStartingPositionRef.current) {\n throw new Error(\n `initialStartingPosition can be only used if itemsPerSlide is an even value.`,\n )\n }\n if (draggingSlideTresholdRef.current < 0) {\n throw new Error('draggingSlideTreshold must be greater than 0')\n }\n if (draggingSlideTresholdRef.current > getSlideValue() / 2) {\n throw new Error(\n `draggingSlideTreshold must be equal or less than the half of the width of an item, which is ${Math.floor(\n getSlideValue() / 2,\n )}`,\n )\n }\n if (itemsPerSlideRef.current < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\n }\n if (itemsPerSlideRef.current > items.length) {\n throw new Error(\n `The itemsPerSlide prop can't be greater than the total length of the items you provide.`,\n )\n }\n if (initialActiveItemRef.current < 0) {\n throw new Error('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItemRef.current > items.length) {\n throw new Error(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n if (!shouldResizeOnWindowResize) {\n console.warn(\n 'You set shouldResizeOnWindowResize={false}; be aware that the carousel could behave in a strange way if you also use the fullscreen functionality or if you change the mobile orientation.',\n )\n }\n })\n useIsomorphicMount(() => {\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n })\n useIsomorphicMount(() => {\n isFirstMount.current = false\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n initialWindowWidth.current = window.innerWidth\n currentWindowWidth.current = window.innerWidth\n\n if (initialActiveItem > 0) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n if (!withLoop && carouselTrackWrapperRef.current) {\n carouselTrackWrapperRef.current.style.top = '0px'\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n })\n useIsomorphicLayoutEffect(() => {\n if (initialActiveItem < items.length && initialActiveItem !== activeItem.current) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n }, [initialActiveItem])\n useIsomorphicLayoutEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shouldResizeOnWindowResize])\n useIsomorphicLayoutEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxisRef.current === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxisRef.current === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\n useIsomorphicLayoutEffect(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n const itemsAreEqual = items.length === prevItems.current.length\n\n if (!itemsAreEqual && items.length < prevItems.current.length) {\n _slideToItem(items.length - 1)\n }\n\n prevItems.current = items\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getFluidWrapperScrollValue, items])\n\n const contextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem() {\n slideToPrevItem()\n },\n slideToNextItem() {\n slideToNextItem()\n },\n ...(slideType === 'fixed'\n ? {\n slideToItem: _slideToItem,\n getIsActiveItem: (id: string) => {\n return findItemIndex(id) === getCurrentActiveItem()\n },\n getCurrentActiveItem: () => ({\n id: items[getCurrentActiveItem()].id,\n index: getCurrentActiveItem(),\n }),\n }\n : {}),\n }\n\n const handleCarouselFragmentRef = (ref: HTMLDivElement | null) => {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n adjustCarouselWrapperPosition(ref, initialActiveItemRef.current)\n }\n }\n\n function getInitialStyles() {\n const totalValue = (items.length / itemsPerSlide) * 100\n const singleItemValue = 100 / itemsPerSlide\n const cssProp = carouselSlideAxisRef.current === 'x' ? 'left' : 'y'\n const quantityToMove = Math.floor(50 / singleItemValue)\n\n if (slideType === 'fixed') {\n if (initialStartingPositionRef.current === 'center') {\n return {\n [cssProp]: `calc(-${totalValue}% + ${singleItemValue * quantityToMove}%)`,\n }\n }\n if (initialStartingPositionRef.current === 'end') {\n return {\n [cssProp]: `calc(-${totalValue}% + ${singleItemValue * (quantityToMove * 2)}%)`,\n }\n }\n }\n return {\n [cssProp]: `0px`,\n }\n }\n\n const carouselFragment = (\n <Context.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\n className=\"use-spring-carousel-main-wrapper\"\n data-testid=\"use-spring-carousel-wrapper\"\n {...getWheelEvent()}\n // @ts-ignore\n style={{\n display: 'flex',\n position: 'relative',\n width: '100%',\n height: '100%',\n ...getOverflowStyles(),\n }}\n >\n <animated.div\n {...bindDrag()}\n className=\"use-spring-carousel-track-wrapper\"\n data-testid=\"use-spring-carousel-animated-wrapper\"\n ref={handleCarouselFragmentRef}\n style={{\n display: 'flex',\n position: 'relative',\n touchAction: getTouchAction(),\n flexDirection: carouselSlideAxisRef.current === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\n ...getInitialStyles(),\n ...(freeScroll ? {} : carouselStyles),\n }}\n >\n {internalItems.map(({ id, renderItem }, index) => {\n return (\n <div\n key={`${id}-${index}`}\n className=\"use-spring-carousel-item\"\n data-testid=\"use-spring-carousel-item-wrapper\"\n style={{\n display: 'flex',\n position: 'relative',\n ...getItemStyles(itemsPerSlideRef.current),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </Context.Provider>\n )\n const thumbsFragment = (\n <Context.Provider value={contextProps}>{_thumbsFragment}</Context.Provider>\n )\n\n return {\n ...contextProps,\n carouselFragment,\n thumbsFragment,\n }\n}\n\nfunction useSpringCarouselContext<T = 'fixed' | 'fluid'>() {\n const context = useContext(Context)\n if (!context) {\n throw new Error(\n 'useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.',\n )\n }\n return context as ContextTypes<T>\n}\n\nexport { useSpringCarousel, useSpringCarouselContext }\n","import { createContext, useRef, useState, useContext } from 'react'\nimport { useTransition, animated, config } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useThumbsModule, useFullscreenModule } from '../modules'\nimport { SlideActionType } from '../types'\nimport {\n UseTransitionCarouselContextProps,\n UseTransitionCarouselProps,\n} from '../types/useTransitionCarousel'\nimport { ReactSpringCarouselItemWithThumbs } from '../types/useSpringCarousel'\n\nconst UseTransitionCarouselContext = createContext<\n UseTransitionCarouselContextProps | undefined\n>(undefined)\n\nfunction useTransitionCarouselContext() {\n const context = useContext(UseTransitionCarouselContext)\n\n if (!context) {\n throw new Error(`useTransitionCarouselContext isn't being used within the useTransitionCarousel context; \n use the context only inside a component that is rendered within the Carousel.`)\n }\n\n return context\n}\n\nfunction useTransitionCarousel({\n items,\n withLoop = false,\n withThumbs = false,\n springConfig = config.default,\n thumbsSlideAxis = 'x',\n enableThumbsWrapperScroll = true,\n draggingSlideTreshold = 50,\n prepareThumbsData,\n toPrevItemSpringProps,\n toNextItemSpringProps,\n disableGestures = false,\n trail,\n exitBeforeEnter = false,\n springAnimationProps = {\n initial: {\n opacity: 1,\n position: 'absolute',\n },\n from: {\n opacity: 0,\n position: 'absolute',\n },\n enter: {\n opacity: 1,\n position: 'absolute',\n },\n leave: {\n opacity: 0,\n position: 'absolute',\n },\n },\n}: UseTransitionCarouselProps) {\n const slideActionType = useRef<SlideActionType>('next')\n const mainCarouselWrapperRef = useRef<HTMLDivElement | null>(null)\n const isAnimating = useRef(false)\n const [activeItem, setActiveItem] = useState(0)\n\n const { emitObservable, useListenToCustomEvent } =\n useCustomEventsModule<'use-transition'>()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n emitObservable,\n mainCarouselWrapperRef,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n items: items as ReactSpringCarouselItemWithThumbs[],\n withThumbs,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n slideType: 'fixed',\n })\n\n const bindSwipe = useDrag(\n ({ last, movement: [mx] }) => {\n if (getIsAnimating()) {\n return\n }\n\n if (last) {\n const prevItemTreshold = mx > draggingSlideTreshold\n const nextItemTreshold = mx < -draggingSlideTreshold\n const isFirstItem = activeItem === 0\n const isLastItem = activeItem === items.length - 1\n\n if (nextItemTreshold) {\n if (!withLoop && isLastItem) {\n return\n }\n\n slideToNextItem()\n emitObservable({\n eventName: 'onLeftSwipe',\n })\n } else if (prevItemTreshold) {\n if (!withLoop && isFirstItem) {\n return\n }\n\n slideToPrevItem()\n emitObservable({\n eventName: 'onRightSwipe',\n })\n }\n }\n },\n {\n enabled: !disableGestures,\n },\n )\n\n function getTransitionConfig() {\n const slideActionType = getSlideActionType()\n\n if (slideActionType === 'prev' && toPrevItemSpringProps) {\n return {\n initial: {\n ...springAnimationProps.initial,\n },\n from: {\n ...toPrevItemSpringProps.from,\n },\n enter: {\n ...toPrevItemSpringProps.enter,\n },\n leave: {\n ...toPrevItemSpringProps.leave,\n },\n }\n }\n\n if (slideActionType === 'next' && toNextItemSpringProps) {\n return {\n initial: {\n ...springAnimationProps.initial,\n },\n from: {\n ...toNextItemSpringProps.from,\n },\n enter: {\n ...toNextItemSpringProps.enter,\n },\n leave: {\n ...toNextItemSpringProps.leave,\n },\n }\n }\n\n return {\n initial: {\n ...springAnimationProps.initial,\n },\n from: {\n ...springAnimationProps.from,\n },\n enter: {\n ...springAnimationProps.enter,\n },\n leave: {\n ...springAnimationProps.leave,\n },\n }\n }\n\n const transitions = useTransition(activeItem, {\n config: springConfig,\n ...getTransitionConfig(),\n onStart: () => setIsAnimating(true),\n trail,\n exitBeforeEnter,\n key: items[activeItem].id,\n onRest: val => {\n if (val.finished) {\n setIsAnimating(false)\n emitObservable({\n eventName: 'onSlideChange',\n slideActionType: getSlideActionType(),\n currentItem: {\n index: activeItem,\n id: items[activeItem].id,\n },\n })\n }\n },\n })\n const itemsFragment = transitions((styles, item) => (\n <animated.div\n style={{\n ...styles,\n flex: '1 0 100%',\n width: '100%',\n height: '100%',\n }}\n >\n {items[item].renderItem}\n </animated.div>\n ))\n\n function getIsAnimating() {\n return isAnimating.current\n }\n function setIsAnimating(val: boolean) {\n isAnimating.current = val\n }\n function setSlideActionType(type: SlideActionType) {\n slideActionType.current = type\n }\n function getSlideActionType() {\n return slideActionType.current\n }\n function slideToItem(item: string | number) {\n let itemIndex = 0\n\n if (typeof item === 'string') {\n itemIndex = items.findIndex(_item => _item.id === item)\n } else {\n itemIndex = item\n }\n\n if (itemIndex >= items.length) {\n throw Error(\n `The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.`,\n )\n }\n\n if (itemIndex === activeItem) {\n return\n }\n\n const currentItem = findItemIndex(items[activeItem].id)\n const newActiveItem = findItemIndex(items[itemIndex].id)\n\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: newActiveItem,\n id: items[itemIndex].id,\n },\n })\n\n if (newActiveItem > currentItem) {\n setSlideActionType('next')\n } else {\n setSlideActionType('prev')\n }\n\n setActiveItem(itemIndex)\n\n if (enableThumbsWrapperScroll && withThumbs) {\n handleThumbsScroll(itemIndex)\n }\n }\n function slideToNextItem() {\n const isLastItem = activeItem === items.length - 1\n\n if (withLoop) {\n setSlideActionType('next')\n if (isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: 0,\n id: items[0].id,\n },\n })\n setActiveItem(0)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: activeItem + 1,\n id: items[activeItem + 1].id,\n },\n })\n setActiveItem(activeItem + 1)\n }\n } else {\n if (!isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: activeItem + 1,\n id: items[activeItem + 1].id,\n },\n })\n setSlideActionType('next')\n setActiveItem(activeItem + 1)\n }\n }\n }\n function slideToPrevItem() {\n const isFirstItem = activeItem === 0\n\n if (withLoop) {\n setSlideActionType('prev')\n if (isFirstItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: items.length - 1,\n id: items[items.length - 1].id,\n },\n })\n\n setActiveItem(items.length - 1)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: activeItem - 1,\n id: items[activeItem - 1].id,\n },\n })\n setActiveItem(activeItem - 1)\n }\n } else {\n if (!isFirstItem) {\n setSlideActionType('prev')\n emitObservable({\n eventName: 'onSlideStartChange',\n slideActionType: getSlideActionType(),\n nextItem: {\n index: activeItem - 1,\n id: items[activeItem - 1].id,\n },\n })\n setActiveItem(activeItem - 1)\n }\n }\n }\n function findItemIndex(id: string) {\n return items.findIndex(item => item.id === id)\n }\n function getIsNextItem(id: string) {\n const itemIndex = findItemIndex(id)\n\n if (withLoop && activeItem === items.length - 1) {\n return itemIndex === 0\n }\n\n return itemIndex === activeItem + 1\n }\n function getIsPrevItem(id: string) {\n const itemIndex = findItemIndex(id)\n\n if (withLoop && activeItem === 0) {\n return itemIndex === items.length - 1\n }\n\n return itemIndex === activeItem - 1\n }\n\n const contextProps: UseTransitionCarouselContextProps = {\n activeItem,\n slideToItem,\n slideToNextItem,\n slideToPrevItem,\n enterFullscreen,\n exitFullscreen,\n useListenToCustomEvent,\n getIsNextItem,\n getIsPrevItem,\n getIsAnimating,\n getIsFullscreen,\n getIsActiveItem: id => {\n return findItemIndex(id) === activeItem\n },\n getCurrentActiveItem: () => ({\n id: items[activeItem].id,\n index: activeItem,\n }),\n }\n\n const carouselFragment = (\n <UseTransitionCarouselContext.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\n {...bindSwipe()}\n style={{\n display: 'flex',\n position: 'relative',\n width: '100%',\n height: '100%',\n overflow: 'hidden',\n }}\n >\n {itemsFragment}\n </div>\n </UseTransitionCarouselContext.Provider>\n )\n\n const thumbsFragment = (\n <UseTransitionCarouselContext.Provider value={contextProps}>\n {_thumbsFragment}\n </UseTransitionCarouselContext.Provider>\n )\n\n return {\n carouselFragment,\n thumbsFragment,\n ...contextProps,\n }\n}\n\nexport { useTransitionCarouselContext, useTransitionCarousel }\n"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useIsomorphicLayoutEffect","window","useLayoutEffect","useIsomorphicMount","callback","isMounted","clean","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","prepareThumbsData","getFluidWrapperScrollValue","getSlideValue","slideType","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","x","y","config","onChange","value","Math","abs","getCurrentThumbScrollValue","getThumbsTotalScrollableValue","round","Number","getBoundingClientRect","getThumbSlideValue","thumbSlideTotal","Error","thumbsFragment","_jsx","animated","div","ref","className","onWheel","stop","style","display","flex","position","width","height","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsData","thumbId","handleThumbsScroll","activeItem","actionType","totalScrollableValue","nextValue","start","from","[object Object]","to","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","fromValue","getScrollFromValue","toValue","scrollDimensionProperty","length","getScrollToValue","scrollLeft","scrollTop","Context","createContext","undefined","defaultDragSpringConfig","default","mass","velocity","UseTransitionCarouselContext","withLoop","draggingSlideTreshold","shouldResizeOnWindowResize","enableThumbsWrapperScroll","slideWhenThresholdIsReached","carouselSlideAxis","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","freeScroll","enableFreeScrollDrag","itemsPerSlide","isFirstMount","slideActionType","internalItems","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","fluidTotalWrapperScrollValue","slideEndReached","currentWindowWidth","initialWindowWidth","prevSlidedValue","prevItems","draggingSlideTresholdRef","itemsPerSlideRef","gutterRef","startEndGutterRef","initialActiveItemRef","initialStartingPositionRef","carouselSlideAxisRef","carouselStyles","setCarouselStyles","getCarouselItemWidth","carouselItem","getCurrentSlidedValue","get","getIfItemsNotFillTheCarousel","getMainCarouselWrapperWidth","getIsFirstItem","getCurrentActiveItem","itemVal","adjustCarouselWrapperPosition","_initialActiveItem","positionProperty","getDefaultPositionValue","setPosition","v","top","left","setStartPosition","setEndPosition","resize","innerWidth","immediate","floor","_thumbsFragment","getWrapperScrollDirection","getIfShouldEnableFluidDrag","bindDrag","useDrag","props","dragging","movement","offset","currentMovement","prevItemTreshold","nextItemTreshold","direction","cancelDrag","cancel","setDragDirection","setSlideActionType","emitDragObservable","getSlideActionType","resetAnimation","checkBounds","getIsDragging","setIsDragging","friction","tension","last","slideToPrevItem","slideToNextItem","getIsLastItem","enabled","axis","type","setActiveItem","newItem","setIsAnimating","val","getPrevItem","currentActiveItem","getNextItem","findItemIndex","findIndex","item","getToValue","customTo","slideToItem","onRest","nextItem","index","getFromValue","finished","currentItem","nextPrevValue","nextItemWillExceed","willExceed","currentWidth","_slideToItem","itemIndex","_item","console","warn","handleVisibilityChange","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsNextItem","getIsPrevItem","getIsActiveItem","carouselFragment","Provider","percentValue","getAnimatedWrapperStyles","totalValue","singleItemValue","cssProp","quantityToMove","getInitialStyles","renderItem","_itemsPerSlide","marginRight","marginBottom","context","useContext","toPrevItemSpringProps","toNextItemSpringProps","trail","exitBeforeEnter","springAnimationProps","initial","opacity","enter","leave","useState","bindSwipe","mx","isFirstItem","isLastItem","itemsFragment","useTransition","getTransitionConfig","onStart","key","transitions","styles","newActiveItem","overflow"],"mappings":"sTASgBA,IACd,MAAMC,EAAoBC,SACxB,IAAIC,WAkBN,MAAO,CACLC,uBAZF,SAAgCC,GAC9BC,aAAU,KACR,MAAMC,EAAYN,EAAkBO,QAAQD,UAAUF,GACtD,MAAO,IAAME,EAAUE,gBACtB,CAACJ,KASJK,eAN0CC,IAC1CV,EAAkBO,QAAQI,KAAKD,KCtBnC,MAAME,EACc,oBAAXC,OAAyBC,kBAAkBT,YAEpD,SAASU,EAAmBC,GAC1B,MAAMC,EAAYhB,UAAO,GAEzBW,GAA0B,KACxB,IAAKK,EAAUV,QAAS,CACtB,MAAMW,EAAQF,IAGd,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CkK,cAnBF,SAAuBvK,GACrB,MAAM4J,EAAYjB,EAAc3I,GAEhC,OAAIuC,GAA2B,IAAflC,EACPuJ,IAAc7M,EAAM4E,OAAS,EAG/BiI,IAAcvJ,EAAa,GAalCgK,eAAAA,EACAxN,gBAAAA,EACA2N,gBAAiBxK,GACR2I,EAAc3I,KAAQK,EAE/B+E,qBAAsB,MACpBpF,GAAIjD,EAAMsD,GAAYL,GACtBmJ,MAAO9I,KAILoK,EACJ9L,MAAC2D,EAA6BoI,wBAAS3M,MAAOqM,aAC5CzL,2BACEG,IAAKnD,GACDuQ,KACJhN,MAAO,CACLC,QAAS,OACTE,SAAU,WACVC,MAAO,OACPC,OAAQ,OACRuN,SAAU,qBAGXR,QAKD5N,EACJC,MAAC2D,EAA6BoI,wBAAS3M,MAAOqM,aAC3ChE,KAIL,sBACEqE,iBAAAA,EACA/L,eAAAA,GACG0L,yCA9YP,WACE,MAAMkB,EAAUC,aAAWjJ,GAE3B,IAAKgJ,EACH,MAAM,IAAI7M,MAAM,+KAIlB,OAAO6M"}
1
+ {"version":3,"file":"index.js","sources":["../../src/modules/useThumbsModule.tsx","../../src/useSpringCarousel.tsx","../../src/modules/useEventsModule.ts","../../src/modules/useFullscreenModule.ts"],"sourcesContent":["import { useSpring } from \"@react-spring/web\";\nimport { useRef } from \"react\";\nimport {\n SpringCarouselWithThumbs,\n PrepareThumbsData,\n} from \"src/types/internals\";\n\ntype Props = {\n withThumbs?: boolean;\n thumbsSlideAxis: SpringCarouselWithThumbs[\"thumbsSlideAxis\"];\n prepareThumbsData?: PrepareThumbsData;\n items: SpringCarouselWithThumbs[\"items\"];\n};\n\nfunction isInViewport(el: HTMLElement) {\n const rect = el.getBoundingClientRect();\n return (\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <=\n (window.innerHeight || document.documentElement.clientHeight) &&\n rect.right <= (window.innerWidth || document.documentElement.clientWidth)\n );\n}\n\nexport function useThumbsModule({\n thumbsSlideAxis = \"x\",\n withThumbs = false,\n prepareThumbsData,\n items,\n}: Props) {\n const wrapperRef = useRef<HTMLDivElement | null>(null);\n const [spring, setSpring] = useSpring(() => ({\n val: 0,\n }));\n\n function getTotalScrollValue() {\n return Math.round(\n Number(\n wrapperRef.current?.[\n thumbsSlideAxis === \"x\" ? \"scrollWidth\" : \"scrollHeight\"\n ]\n ) -\n wrapperRef.current!.getBoundingClientRect()[\n thumbsSlideAxis === \"x\" ? \"width\" : \"height\"\n ]\n );\n }\n\n function handleScroll(activeItem: number) {\n function getThumbNode() {\n if (wrapperRef.current) {\n return wrapperRef.current.querySelector(\n `#thumb-item-${items[activeItem].id}`\n ) as HTMLElement;\n }\n return null;\n }\n\n const thumbNode = getThumbNode();\n if (thumbNode && wrapperRef.current) {\n if (!isInViewport(thumbNode)) {\n const offset = thumbNode.offsetLeft;\n const val =\n offset > getTotalScrollValue() ? getTotalScrollValue() : offset;\n\n setSpring.start({\n from: {\n val:\n wrapperRef.current?.[\n thumbsSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] ?? 0,\n },\n to: {\n val,\n },\n onChange: ({ value }) => {\n if (wrapperRef.current) {\n wrapperRef.current[\n thumbsSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] = Math.abs(value.val);\n }\n },\n });\n }\n }\n }\n\n function handlePrepareThumbsData() {\n function getPreparedItems(\n _items: ReturnType<PrepareThumbsData>\n ): ReturnType<PrepareThumbsData> {\n return _items.map((i) => ({\n id: i.id,\n renderThumb: i.renderThumb,\n }));\n }\n\n if (prepareThumbsData) {\n return prepareThumbsData(getPreparedItems(items));\n }\n return getPreparedItems(items);\n }\n\n const thumbsFragment = withThumbs ? (\n <div\n className=\"use-spring-carousel-thumbs-wrapper\"\n ref={wrapperRef}\n onWheel={() => spring.val.stop()}\n style={{\n display: \"flex\",\n flex: \"1\",\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n flexDirection: thumbsSlideAxis === \"x\" ? \"row\" : \"column\",\n ...(thumbsSlideAxis === \"x\"\n ? { overflowX: \"auto\" }\n : {\n overflowY: \"auto\",\n maxHeight: \"100%\",\n }),\n }}\n >\n {handlePrepareThumbsData().map(({ id, renderThumb }) => {\n const thumbId = `thumb-item-${id}`;\n return (\n <div key={thumbId} id={thumbId} className=\"thumb-item\">\n {renderThumb}\n </div>\n );\n })}\n </div>\n ) : null;\n\n return {\n thumbsFragment,\n handleScroll,\n };\n}\n","import { config, useSpring } from \"@react-spring/web\";\nimport React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from \"react\";\n\nimport { SlideActionType, SlideMode } from \"./types/common\";\nimport { useEventsModule } from \"./modules/useEventsModule\";\nimport { useDrag } from \"@use-gesture/react\";\nimport { useFullscreenModule } from \"./modules/useFullscreenModule\";\nimport { useThumbsModule } from \"./modules/useThumbsModule\";\nimport {\n UseSpringReturnType,\n UseSpringCarouselWithThumbs,\n UseSpringCarouselComplete,\n UseSpringCarouselWithNoThumbs,\n UseSpringCarouselWithFixedItems,\n UseSpringCarouselWithNoFixedItems,\n SpringCarouselWithThumbs,\n} from \"./types/internals\";\n\nfunction useSpringCarousel(\n props: UseSpringCarouselWithThumbs\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithNoThumbs\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithFixedItems\n): UseSpringReturnType;\nfunction useSpringCarousel(\n props: UseSpringCarouselWithNoFixedItems\n): UseSpringReturnType;\n\nfunction useSpringCarousel({\n items,\n init = true,\n withThumbs,\n thumbsSlideAxis = \"x\",\n itemsPerSlide = 1,\n slideType = \"fixed\",\n gutter = 0,\n withLoop = false,\n startEndGutter = 0,\n carouselSlideAxis = \"x\",\n disableGestures = false,\n draggingSlideTreshold: _draggingSlideTreshold,\n slideWhenThresholdIsReached = false,\n freeScroll,\n enableFreeScrollDrag,\n initialStartingPosition,\n prepareThumbsData,\n initialActiveItem = 0,\n}: UseSpringCarouselComplete) {\n const prevWindowWidth = useRef(0);\n const draggingSlideTreshold = useRef(_draggingSlideTreshold ?? 0);\n const slideActionType = useRef<SlideActionType>(\"initial\");\n const slideModeType = useRef<SlideMode>(\"initial\");\n const prevSlidedValue = useRef(0);\n const [spring, setSpring] = useSpring(() => ({\n val: 0,\n pause: !init,\n onChange({ value }) {\n if (freeScroll && mainCarouselWrapperRef.current) {\n setStartEndItemReachedOnFreeScroll();\n if (carouselSlideAxis === \"x\") {\n mainCarouselWrapperRef.current.scrollLeft = Math.abs(value.val);\n } else {\n mainCarouselWrapperRef.current.scrollTop = Math.abs(value.val);\n }\n } else if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === \"x\") {\n carouselTrackWrapperRef.current.style.transform = `translate3d(${value.val}px, 0px,0px)`;\n } else {\n carouselTrackWrapperRef.current.style.transform = `translate3d(0px,${value.val}px,0px)`;\n }\n }\n },\n }));\n const activeItem = useRef(initialActiveItem);\n const firstItemReached = useRef(initialActiveItem === 0);\n const lastItemReached = useRef(false);\n const mainCarouselWrapperRef = useRef<HTMLDivElement | null>(null);\n const carouselTrackWrapperRef = useRef<HTMLDivElement | null>(null);\n\n const getItems = useCallback(() => {\n if (withLoop) {\n return [\n ...items.map((i) => ({\n ...i,\n id: `prev-repeated-item-${i.id}`,\n })),\n ...items,\n ...items.map((i) => ({\n ...i,\n id: `next-repeated-item-${i.id}`,\n })),\n ];\n }\n return [...items];\n }, [items, withLoop]);\n const internalItems = getItems();\n\n const { emitEvent, useListenToCustomEvent } = useEventsModule();\n const { thumbsFragment, handleScroll } = useThumbsModule({\n withThumbs: !!withThumbs,\n thumbsSlideAxis,\n prepareThumbsData,\n items: items as SpringCarouselWithThumbs[\"items\"],\n });\n const { enterFullscreen, exitFullscreen, getIsFullscreen } =\n useFullscreenModule({\n mainCarouselWrapperRef,\n emitEvent,\n handleResize: () => adjustCarouselWrapperPosition(),\n });\n\n function getItemStyles() {\n if (slideType === \"fixed\" && !freeScroll) {\n return {\n marginRight: `${gutter}px`,\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n };\n }\n return {\n ...{ marginRight: `${gutter}px` },\n };\n }\n\n function getSlideValue() {\n const carouselItem = mainCarouselWrapperRef.current?.querySelector(\n \".use-spring-carousel-item\"\n );\n\n if (!carouselItem) {\n throw Error(\"No carousel items available!\");\n }\n\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ] + gutter\n );\n }\n\n type SlideToItem = {\n from: number;\n to: number;\n nextActiveItem?: number;\n immediate?: boolean;\n slideMode: \"click\" | \"drag\";\n };\n\n function slideToItem({\n from,\n to,\n nextActiveItem,\n immediate = false,\n slideMode,\n }: SlideToItem) {\n slideModeType.current = slideMode;\n\n if (typeof nextActiveItem === \"number\") {\n if (!freeScroll) {\n activeItem.current = nextActiveItem;\n }\n emitEvent({\n eventName: \"onSlideStartChange\",\n slideActionType: slideActionType.current,\n slideMode: slideModeType.current,\n nextItem: {\n startReached: firstItemReached.current,\n endReached: lastItemReached.current,\n index: freeScroll ? -1 : activeItem.current,\n id: freeScroll ? \"\" : items[activeItem.current].id,\n },\n });\n }\n\n prevSlidedValue.current = to;\n setSpring.start({\n immediate,\n from: {\n val: from,\n },\n to: {\n val: to,\n },\n config: {\n ...config.default,\n velocity: spring.val.velocity,\n },\n onRest(value) {\n if (!immediate && value.finished) {\n emitEvent({\n eventName: \"onSlideChange\",\n slideActionType: slideActionType.current,\n slideMode: slideModeType.current,\n currentItem: {\n startReached: firstItemReached.current,\n endReached: lastItemReached.current,\n index: freeScroll ? -1 : activeItem.current,\n id: freeScroll ? \"\" : items[activeItem.current].id,\n },\n });\n }\n },\n });\n if (withThumbs && !immediate) {\n handleScroll(activeItem.current);\n }\n }\n\n function getTotalScrollValue() {\n if (withLoop) {\n return getSlideValue() * items.length;\n }\n return Math.round(\n Number(\n carouselTrackWrapperRef.current?.[\n carouselSlideAxis === \"x\" ? \"scrollWidth\" : \"scrollHeight\"\n ]\n ) -\n carouselTrackWrapperRef.current!.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ]\n );\n }\n function getAnimatedWrapperStyles() {\n const percentValue = `calc(100% - ${startEndGutter * 2}px)`;\n return {\n width: carouselSlideAxis === \"x\" ? percentValue : \"100%\",\n height: carouselSlideAxis === \"y\" ? percentValue : \"100%\",\n };\n }\n\n function getCarouselItemWidth() {\n const carouselItem = carouselTrackWrapperRef.current?.querySelector(\n \".use-spring-carousel-item\"\n );\n if (!carouselItem) {\n throw Error(\"No carousel items available!\");\n }\n return (\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === \"x\" ? \"width\" : \"height\"\n ] + gutter\n );\n }\n function adjustCarouselWrapperPosition() {\n const positionProperty = carouselSlideAxis === \"x\" ? \"left\" : \"top\";\n\n function setPosition(v: number) {\n const ref = carouselTrackWrapperRef.current;\n if (!ref) return;\n\n if (withLoop) {\n ref.style.top = \"0px\";\n ref.style.left = \"0px\";\n ref.style[positionProperty] = `-${v - startEndGutter}px`;\n } else {\n ref.style.left = \"0px\";\n ref.style.top = \"0px\";\n }\n }\n\n const currentFromValue = Math.abs(getFromValue());\n\n if (currentFromValue < getTotalScrollValue() && lastItemReached.current) {\n lastItemReached.current = false;\n }\n if (currentFromValue > getTotalScrollValue()) {\n const val = -getTotalScrollValue();\n lastItemReached.current = true;\n prevSlidedValue.current = val;\n setSpring.start({\n immediate: true,\n val,\n });\n return;\n }\n\n if (initialStartingPosition === \"center\") {\n setPosition(\n getCarouselItemWidth() * items.length -\n getSlideValue() * Math.round((itemsPerSlide - 1) / 2)\n );\n } else if (initialStartingPosition === \"end\") {\n setPosition(\n getCarouselItemWidth() * items.length -\n getSlideValue() * Math.round(itemsPerSlide - 1)\n );\n } else {\n setPosition(getCarouselItemWidth() * items.length);\n }\n\n if (!freeScroll && slideType === \"fixed\") {\n const val = -(getSlideValue() * activeItem.current);\n prevSlidedValue.current = val;\n setSpring.start({\n immediate: true,\n val,\n });\n }\n }\n\n function getFromValue() {\n if (freeScroll && mainCarouselWrapperRef.current) {\n return mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ];\n }\n return spring.val.get();\n }\n function getToValue(type: \"next\" | \"prev\", index?: number) {\n if (freeScroll && type === \"next\") {\n const next = prevSlidedValue.current + getSlideValue();\n if (next > getTotalScrollValue()) {\n return getTotalScrollValue();\n }\n return next;\n }\n\n if (freeScroll && type === \"prev\") {\n const next = prevSlidedValue.current - getSlideValue();\n if (next < 0) {\n return 0;\n }\n return next;\n }\n\n if (type === \"next\") {\n if (index) {\n return -(index * getSlideValue());\n }\n return prevSlidedValue.current - getSlideValue();\n }\n\n if (index) {\n return -(index * getSlideValue());\n }\n return prevSlidedValue.current + getSlideValue();\n }\n function slideToPrevItem(\n type: Exclude<SlideMode, \"initial\"> = \"click\",\n index?: number\n ) {\n if (!init || (firstItemReached.current && !withLoop)) return;\n\n slideActionType.current = \"prev\";\n lastItemReached.current = false;\n\n const nextItem = index || activeItem.current - 1;\n\n if (!withLoop) {\n const nextItemWillExceed =\n getToValue(\"prev\", index) + getSlideValue() / 3 > 0;\n\n if (firstItemReached.current) return;\n if (nextItemWillExceed) {\n firstItemReached.current = true;\n lastItemReached.current = false;\n\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: 0,\n nextActiveItem: 0,\n });\n return;\n }\n }\n if (withLoop && firstItemReached.current) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n slideToItem({\n slideMode: type,\n from: getFromValue() - getSlideValue() * items.length,\n to: -(getSlideValue() * items.length) + getSlideValue(),\n nextActiveItem: items.length - 1,\n });\n return;\n }\n if (nextItem === 0) {\n firstItemReached.current = true;\n }\n if (nextItem === items.length - 1 || nextItem === -1) {\n lastItemReached.current = true;\n }\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: getToValue(\"prev\", index),\n nextActiveItem: nextItem,\n });\n }\n function slideToNextItem(\n type: Exclude<SlideMode, \"initial\"> = \"click\",\n index?: number\n ) {\n if (!init || (lastItemReached.current && !withLoop)) return;\n\n slideActionType.current = \"next\";\n firstItemReached.current = false;\n\n const nextItem = index || activeItem.current + 1;\n\n if (!withLoop) {\n const nextItemWillExceed =\n Math.abs(getToValue(\"next\", index)) >\n getTotalScrollValue() - getSlideValue() / 3;\n\n if (lastItemReached.current) return;\n if (nextItemWillExceed) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: -getTotalScrollValue(),\n nextActiveItem: nextItem,\n });\n return;\n }\n }\n if (withLoop && lastItemReached.current) {\n lastItemReached.current = false;\n firstItemReached.current = true;\n slideToItem({\n slideMode: type,\n from: getFromValue() + getSlideValue() * items.length,\n to: 0,\n nextActiveItem: 0,\n });\n return;\n }\n if (nextItem === 0) {\n firstItemReached.current = true;\n }\n if (nextItem === items.length - 1) {\n lastItemReached.current = true;\n }\n slideToItem({\n slideMode: type,\n from: getFromValue(),\n to: getToValue(\"next\", index),\n nextActiveItem: nextItem,\n });\n }\n\n useEffect(() => {\n prevWindowWidth.current = window.innerWidth;\n }, []);\n useEffect(() => {\n adjustCarouselWrapperPosition();\n }, [\n initialStartingPosition,\n itemsPerSlide,\n withLoop,\n startEndGutter,\n gutter,\n freeScroll,\n slideType,\n init,\n ]);\n useLayoutEffect(() => {\n /**\n * Set initial track position\n */\n if (carouselTrackWrapperRef.current) {\n adjustCarouselWrapperPosition();\n }\n }, []);\n useEffect(() => {\n if (_draggingSlideTreshold) {\n draggingSlideTreshold.current = _draggingSlideTreshold;\n } else {\n draggingSlideTreshold.current = Math.floor(getSlideValue() / 2 / 2);\n }\n }, [_draggingSlideTreshold]);\n useEffect(() => {\n function handleResize() {\n if (window.innerWidth === prevWindowWidth.current) return;\n prevWindowWidth.current = window.innerWidth;\n adjustCarouselWrapperPosition();\n }\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n };\n }, []);\n\n const bindDrag = useDrag(\n (state) => {\n const isDragging = state.dragging;\n const movement = state.offset[carouselSlideAxis === \"x\" ? 0 : 1];\n const currentMovement = state.movement[carouselSlideAxis === \"x\" ? 0 : 1];\n const direction = state.direction[carouselSlideAxis === \"x\" ? 0 : 1];\n\n const prevItemTreshold = currentMovement > draggingSlideTreshold.current;\n const nextItemTreshold = currentMovement < -draggingSlideTreshold.current;\n\n if (isDragging) {\n if (direction > 0) {\n slideActionType.current = \"prev\";\n } else {\n slideActionType.current = \"next\";\n }\n\n emitEvent({\n ...state,\n eventName: \"onDrag\",\n slideActionType: slideActionType.current,\n });\n\n if (freeScroll) {\n if (slideActionType.current === \"prev\" && movement > 0) {\n state.cancel();\n setSpring.start({\n from: {\n val: getFromValue(),\n },\n to: {\n val: 0,\n },\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n return;\n }\n\n setSpring.start({\n from: {\n val: getFromValue(),\n },\n to: {\n val: -movement,\n },\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n return;\n }\n\n setSpring.start({\n val: movement,\n config: {\n velocity: state.velocity,\n friction: 50,\n tension: 1000,\n },\n });\n\n if (slideWhenThresholdIsReached && nextItemTreshold) {\n slideToNextItem(\"drag\");\n state.cancel();\n } else if (slideWhenThresholdIsReached && prevItemTreshold) {\n slideToPrevItem(\"drag\");\n state.cancel();\n }\n return;\n }\n\n if (state.last && !state.canceled && freeScroll) {\n if (slideActionType.current === \"prev\") {\n slideToPrevItem(\"drag\");\n }\n if (slideActionType.current === \"next\") {\n slideToNextItem(\"drag\");\n }\n }\n\n if (state.last && !state.canceled && !freeScroll) {\n if (nextItemTreshold) {\n if (!withLoop && lastItemReached.current) {\n setSpring.start({\n val: -getTotalScrollValue(),\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n } else {\n slideToNextItem(\"drag\");\n }\n } else if (prevItemTreshold) {\n if (!withLoop && firstItemReached.current) {\n setSpring.start({\n val: 0,\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n } else {\n slideToPrevItem(\"drag\");\n }\n } else {\n setSpring.start({\n val: prevSlidedValue.current,\n config: {\n ...config.default,\n velocity: state.velocity,\n },\n });\n }\n }\n },\n {\n enabled:\n (init && !disableGestures && !freeScroll) ||\n (!!freeScroll && !!enableFreeScrollDrag),\n axis: carouselSlideAxis,\n from: () => {\n if (freeScroll && mainCarouselWrapperRef.current) {\n return [\n -mainCarouselWrapperRef.current.scrollLeft,\n -mainCarouselWrapperRef.current.scrollTop,\n ];\n }\n if (carouselSlideAxis === \"x\") {\n return [spring.val.get(), spring.val.get()];\n }\n return [spring.val.get(), spring.val.get()];\n },\n }\n );\n\n function getWrapperOverflowStyles() {\n if (freeScroll) {\n if (carouselSlideAxis === \"x\") {\n return {\n overflowX: \"auto\",\n };\n }\n return {\n overflowY: \"auto\",\n };\n }\n return {};\n }\n\n function setStartEndItemReachedOnFreeScroll() {\n if (mainCarouselWrapperRef.current) {\n prevSlidedValue.current =\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ];\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] === 0\n ) {\n firstItemReached.current = true;\n lastItemReached.current = false;\n }\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] > 0 &&\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] < getTotalScrollValue()\n ) {\n firstItemReached.current = false;\n lastItemReached.current = false;\n }\n if (\n mainCarouselWrapperRef.current[\n carouselSlideAxis === \"x\" ? \"scrollLeft\" : \"scrollTop\"\n ] === getTotalScrollValue()\n ) {\n firstItemReached.current = false;\n lastItemReached.current = true;\n }\n }\n }\n function getScrollHandlers() {\n if (freeScroll) {\n return {\n onWheel() {\n spring.val.stop();\n setStartEndItemReachedOnFreeScroll();\n },\n };\n }\n return {};\n }\n function findItemIndex(id: string) {\n return items.findIndex((item) => item.id === id);\n }\n function findItemIndexById(id: string | number, error: string) {\n let itemIndex = 0;\n if (typeof id === \"string\") {\n itemIndex = items.findIndex((_item) => _item.id === id);\n } else {\n itemIndex = id;\n }\n\n if (itemIndex < 0 || itemIndex >= items.length) {\n throw new Error(error);\n }\n\n return itemIndex;\n }\n function internalSlideToItem(id: string | number) {\n if (!init) return;\n\n firstItemReached.current = false;\n lastItemReached.current = false;\n\n const itemIndex = findItemIndexById(\n id,\n \"The item you want to slide to doesn't exist; please check che item id or the index you're passing to.\"\n );\n\n if (itemIndex === activeItem.current) {\n return;\n }\n\n const currentItem = findItemIndex(items[activeItem.current].id);\n const newActiveItem = findItemIndex(items[itemIndex].id);\n\n if (newActiveItem > currentItem) {\n slideToNextItem(\"click\", newActiveItem);\n } else {\n slideToPrevItem(\"click\", newActiveItem);\n }\n }\n function getIsNextItem(id: string) {\n const itemIndex = findItemIndex(id);\n const _activeItem = activeItem.current;\n if (withLoop && _activeItem === items.length - 1) {\n return itemIndex === 0;\n }\n return itemIndex === _activeItem + 1;\n }\n function getIsPrevItem(id: string) {\n const itemIndex = findItemIndex(id);\n const _activeItem = activeItem.current;\n if (withLoop && _activeItem === 0) {\n return itemIndex === items.length - 1;\n }\n return itemIndex === _activeItem - 1;\n }\n\n const carouselFragment = (\n <div\n ref={mainCarouselWrapperRef}\n {...getScrollHandlers()}\n style={{\n display: \"flex\",\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n ...(getWrapperOverflowStyles() as React.CSSProperties),\n }}\n >\n <div\n ref={carouselTrackWrapperRef}\n {...bindDrag()}\n style={{\n position: \"relative\",\n display: \"flex\",\n flexDirection: carouselSlideAxis === \"x\" ? \"row\" : \"column\",\n touchAction: \"none\",\n ...getAnimatedWrapperStyles(),\n }}\n >\n {internalItems.map((item, index) => {\n return (\n <div\n key={`${item.id}-${index}`}\n className=\"use-spring-carousel-item\"\n data-testid=\"use-spring-carousel-item-wrapper\"\n style={{\n display: \"flex\",\n position: \"relative\",\n flex: \"1\",\n ...getItemStyles(),\n }}\n >\n {item.renderItem}\n </div>\n );\n })}\n </div>\n </div>\n );\n\n return {\n useListenToCustomEvent,\n carouselFragment,\n enterFullscreen,\n exitFullscreen,\n getIsFullscreen,\n thumbsFragment,\n slideToItem: internalSlideToItem,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem: () => slideToPrevItem(),\n slideToNextItem: () => slideToNextItem(),\n getIsActiveItem: (id: string | number) => {\n return (\n findItemIndexById(id, \"The item you want to check doesn't exist\") ===\n activeItem.current\n );\n },\n };\n}\n\nconst Context =\n createContext<\n Omit<UseSpringReturnType, \"carouselFragment\" | \"thumbsFragment\"> | undefined\n >(undefined);\n\nfunction useSpringCarouselContext() {\n const context = useContext(Context);\n if (!context) {\n throw new Error(\n \"useSpringCarouselContext must be used within the carousel.\"\n );\n }\n return context;\n}\n\nexport { useSpringCarousel, useSpringCarouselContext };\n","import { FullGestureState } from \"@use-gesture/react\";\nimport { useEffect, useRef } from \"react\";\nimport { SlideActionType, SlideMode } from \"../types/common\";\n\nconst eventLabel = \"RSC::Event\";\n\ntype OnSlideStartChange = {\n eventName: \"onSlideStartChange\";\n slideActionType: SlideActionType;\n slideMode: SlideMode;\n nextItem: {\n index: number;\n id: string;\n startReached: boolean;\n endReached: boolean;\n };\n};\ntype OnSlideChange = {\n eventName: \"onSlideChange\";\n slideActionType: SlideActionType;\n slideMode: SlideMode;\n currentItem: {\n index: number;\n id: string;\n startReached: boolean;\n endReached: boolean;\n };\n};\ntype OnFullscreenChange = {\n eventName: \"onFullscreenChange\";\n isFullscreen: boolean;\n};\ntype OnDrag = Omit<FullGestureState<\"drag\">, \"event\"> & {\n eventName: \"onDrag\";\n slideActionType: SlideActionType;\n};\n\ntype Events = OnSlideStartChange | OnSlideChange | OnDrag | OnFullscreenChange;\n\ntype EventHandler = (props: Events) => void;\n\nexport type EmitEvent = (event: Events) => void;\nexport type UseListenToCustomEvent = {\n useListenToCustomEvent: (eventHandler: EventHandler) => void;\n emitEvent: (event: Events) => void;\n};\n\nexport function useEventsModule() {\n const targetEvent = useRef<HTMLDivElement | null>(null);\n\n useEffect(() => {\n targetEvent.current = document.createElement(\"div\");\n }, []);\n\n function useListenToCustomEvent(eventHandler: EventHandler) {\n useEffect(() => {\n function handleEvent(event: CustomEvent<Events>) {\n eventHandler(event.detail);\n }\n\n if (targetEvent.current) {\n // @ts-ignore\n targetEvent.current.addEventListener(eventLabel, handleEvent, false);\n return () => {\n // @ts-ignore\n targetEvent.current?.removeEventListener(\n eventLabel,\n handleEvent,\n false\n );\n };\n }\n }, []);\n }\n function emitEvent(event: Events) {\n if (targetEvent.current) {\n const newEvent = new CustomEvent(eventLabel, {\n detail: event,\n });\n targetEvent.current.dispatchEvent(newEvent);\n }\n }\n\n return {\n useListenToCustomEvent,\n emitEvent,\n };\n}\n","import { useRef, MutableRefObject, useEffect } from \"react\";\nimport screenfull from \"screenfull\";\nimport { EmitEvent } from \"./useEventsModule\";\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>;\n emitEvent: EmitEvent;\n handleResize?(): void;\n};\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitEvent,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false);\n\n useEffect(() => {\n function handleFullscreenChange() {\n if (document.fullscreenElement) {\n setIsFullscreen(true);\n emitEvent({\n eventName: \"onFullscreenChange\",\n isFullscreen: true,\n });\n\n handleResize && handleResize();\n }\n\n if (!document.fullscreenElement) {\n setIsFullscreen(false);\n emitEvent({\n eventName: \"onFullscreenChange\",\n isFullscreen: false,\n });\n handleResize && handleResize();\n }\n }\n\n if (screenfull.isEnabled) {\n screenfull.on(\"change\", handleFullscreenChange);\n return () => {\n if (screenfull.isEnabled) {\n screenfull.off(\"change\", handleFullscreenChange);\n }\n };\n }\n }, []);\n\n function setIsFullscreen(_isFullscreen: boolean) {\n isFullscreen.current = _isFullscreen;\n }\n\n function getIsFullscreen() {\n return isFullscreen.current;\n }\n\n function enterFullscreen(elementRef?: HTMLElement) {\n if (screenfull.isEnabled) {\n screenfull.request(\n (elementRef || mainCarouselWrapperRef.current) as Element\n );\n }\n }\n\n function exitFullscreen() {\n screenfull.isEnabled && screenfull.exit();\n }\n\n return {\n enterFullscreen,\n exitFullscreen,\n getIsFullscreen,\n };\n}\n"],"names":["useThumbsModule","thumbsSlideAxis","withThumbs","prepareThumbsData","items","wrapperRef","useRef","spring","setSpring","useSpring","val","getTotalScrollValue","Math","round","Number","_a","current","getBoundingClientRect","thumbsFragment","_jsx","jsx","Object","assign","className","ref","onWheel","stop","style","display","flex","position","width","height","flexDirection","overflowX","overflowY","maxHeight","children","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsData","thumbId","handleScroll","activeItem","thumbNode","querySelector","el","rect","top","left","bottom","window","innerHeight","document","documentElement","clientHeight","right","innerWidth","clientWidth","isInViewport","offset","offsetLeft","start","from","to","onChange","value","abs","Context","createContext","undefined","init","itemsPerSlide","slideType","gutter","withLoop","startEndGutter","carouselSlideAxis","disableGestures","draggingSlideTreshold","_draggingSlideTreshold","slideWhenThresholdIsReached","freeScroll","enableFreeScrollDrag","initialStartingPosition","initialActiveItem","prevWindowWidth","slideActionType","slideModeType","prevSlidedValue","pause","mainCarouselWrapperRef","setStartEndItemReachedOnFreeScroll","scrollLeft","scrollTop","carouselTrackWrapperRef","transform","firstItemReached","lastItemReached","internalItems","useCallback","getItems","emitEvent","useListenToCustomEvent","targetEvent","useEffect","createElement","eventHandler","handleEvent","event","detail","addEventListener","removeEventListener","newEvent","CustomEvent","dispatchEvent","useEventsModule","enterFullscreen","exitFullscreen","getIsFullscreen","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","fullscreenElement","eventName","screenfull","isEnabled","on","off","elementRef","request","exit","useFullscreenModule","adjustCarouselWrapperPosition","getSlideValue","carouselItem","Error","slideToItem","nextActiveItem","immediate","slideMode","nextItem","startReached","endReached","index","config","default","velocity","onRest","finished","currentItem","length","getCarouselItemWidth","positionProperty","setPosition","v","currentFromValue","getFromValue","get","getToValue","type","next","slideToPrevItem","nextItemWillExceed","slideToNextItem","useLayoutEffect","floor","bindDrag","useDrag","state","isDragging","dragging","movement","currentMovement","direction","prevItemTreshold","nextItemTreshold","cancel","friction","tension","last","canceled","enabled","axis","findItemIndex","findIndex","item","findItemIndexById","error","itemIndex","_item","carouselFragment","touchAction","percentValue","getAnimatedWrapperStyles","marginRight","renderItem","newActiveItem","getIsNextItem","_activeItem","getIsPrevItem","getIsActiveItem","context","useContext"],"mappings":"0JAyBgB,SAAAA,GAAgBC,gBAC9BA,EAAkB,IAAGC,WACrBA,GAAa,EAAKC,kBAClBA,EAAiBC,MACjBA,IAEA,MAAMC,EAAaC,SAA8B,OAC1CC,EAAQC,GAAaC,EAASA,WAAC,KAAO,CAC3CC,IAAK,MAGP,SAASC,UACP,OAAOC,KAAKC,MACVC,OACoB,QAAlBC,EAAAV,EAAWW,eAAO,IAAAD,OAAA,EAAAA,EACI,MAApBd,EAA0B,cAAgB,iBAG5CI,EAAWW,QAASC,wBACE,MAApBhB,EAA0B,QAAU,UAG3C,CAwFD,MAAO,CACLiB,eAhCqBhB,EACrBiB,EAAAC,IAAA,MAAAC,OAAAC,OAAA,CACEC,UAAU,qCACVC,IAAKnB,EACLoB,QAAS,IAAMlB,EAAOG,IAAIgB,OAC1BC,MAAKN,OAAAC,OAAA,CACHM,QAAS,OACTC,KAAM,IACNC,SAAU,WACVC,MAAO,OACPC,OAAQ,OACRC,cAAmC,MAApBhC,EAA0B,MAAQ,UACzB,MAApBA,EACA,CAAEiC,UAAW,QACb,CACEC,UAAW,OACXC,UAAW,UAIlB,CAAAC,SApCL,WACE,SAASC,EACPC,GAEA,OAAOA,EAAOC,KAAKC,IAAO,CACxBC,GAAID,EAAEC,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kBrK,GAEduJ,GAAkBvJ,EAAI,8CACtBK,EAAW/B,QAInB,mCAOA,WACE,MAAMgM,EAAUC,aAAWzI,GAC3B,IAAKwI,EACH,MAAM,IAAIlE,MACR,8DAGJ,OAAOkE,CACT"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export{useSpringCarousel,useSpringCarouselContext}from"./index2.js";export{useTransitionCarousel,useTransitionCarouselContext}from"./index3.js";import"react/jsx-runtime";import"react";import"react-spring";import"@use-gesture/react";import"./useThumbsModule-0944decf.js";import"rxjs";import"screenfull";
1
+ export{useSpringCarousel,useSpringCarouselContext}from"./useSpringCarousel.js";import"react/jsx-runtime";import"@react-spring/web";import"react";import"./useThumbsModule-ce69c348.js";import"screenfull";import"@use-gesture/react";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"react/jsx-runtime";import{createContext as t,useRef as r,useContext as n}from"react";import{config as i,useSpring as c,animated as o}from"react-spring";import{useDrag as u}from"@use-gesture/react";import{u as s,a as l,b as a,c as f,d}from"./useThumbsModule-0944decf.js";import"rxjs";import"screenfull";const h=t(void 0),g=Object.assign(Object.assign({},i.default),{mass:1,velocity:0});function m({items:t,withLoop:n=!1,draggingSlideTreshold:m,springConfig:v=i.default,shouldResizeOnWindowResize:p=!0,withThumbs:y=!1,enableThumbsWrapperScroll:b=!0,slideWhenThresholdIsReached:x=!0,carouselSlideAxis:w="x",thumbsSlideAxis:T="x",prepareThumbsData:O,initialActiveItem:j=0,initialStartingPosition:I,disableGestures:S=!1,gutter:E=0,startEndGutter:A=0,touchAction:C,slideAmount:R,freeScroll:$=!1,enableFreeScrollDrag:W,itemsPerSlide:L=1,slideType:M="fixed"}){const F=r(!0),N=r("initial"),P=n?t.length===L?[...t,...t,...t,...t,...t]:[...t,...t,...t]:t,z=r(j),D=r(null),B=r(null),k=r(!1),q=r(!1),G=r(!1),V=r(0),Y=r(!1),H=r(0),X=r(0),J=r(0),K=r(t),Q=r(null!=m?m:0),U=r(L),Z=r(E),_=r(A),ee=r(j),te=r(I),re=r(w);U.current=L,Z.current=E,_.current=A,ee.current=j,te.current=I,re.current=w;const[ne,ie]=c((()=>({y:0,x:0,onChange:({value:e})=>{D.current&&$&&(D.current["x"===re.current?"scrollLeft":"scrollTop"]=Math.abs(e[re.current]))}})));function ce(){const e=null===(t=B.current)||void 0===t?void 0:t.querySelector(".use-spring-carousel-item");var t;if(!e)throw Error("No carousel items available!");return e.getBoundingClientRect()["x"===re.current?"width":"height"]+Z.current}function oe(){return ne[re.current].get()}function ue(){return ce()*t.length<function(){if(!D.current)throw new Error("mainCarouselWrapperRef is not available");return D.current.getBoundingClientRect()["x"===re.current?"width":"height"]}()}function se(){var e;return Math.round(Number(null===(e=B.current)||void 0===e?void 0:e["x"===re.current?"scrollWidth":"scrollHeight"])-B.current.getBoundingClientRect()["x"===re.current?"width":"height"])}function le(){return 0===Ee()}function ae(){if(!B.current)return 0;const e=ce();if("fluid"===M&&"number"==typeof R){if(R<e)throw new Error("slideAmount must be greater than the width of a single item.");return R}return e}function fe(e,r){const i="x"===re.current?"left":"top";function c(){return ce()*t.length}function o(t){n?(e.style.top="0px",e.style[i]=`-${t-_.current}px`):(e.style.left="0px",e.style.top="0px",r&&F.current&&(e.style[i]=`calc(-${r} * 100%)`))}function u(){o(c())}if("fixed"===M){if(U.current>1)switch(te.current){default:case"start":u();break;case"center":s=U.current,o(c()-ae()*Math.round((s-1)/2));break;case"end":!function(e){o(c()-ae()*Math.round(e-1))}(U.current)}else u()}else u();var s}function de(){if(H.current=window.innerWidth,"fluid"===M){if(ue())return void ie.start({immediate:!0,[re.current]:0});if(V.current=se(),Y.current){const e=-V.current;ie.start({immediate:!0,[re.current]:e})}X.current=window.innerWidth}else ie.start({immediate:!0,[re.current]:-ae()*Ee()});V.current=se(),fe(B.current)}function he(){window.innerWidth===H.current||$||de()}s((()=>{Q.current=m||Math.floor(ae()/2/2),de()}),[m,L,E,A,j,I,w,T]);const{useListenToCustomEvent:ge,emitObservable:me}=l(),{enterFullscreen:ve,exitFullscreen:pe,getIsFullscreen:ye}=a({mainCarouselWrapperRef:D,emitObservable:me,handleResize:he}),{thumbsFragment:be,handleThumbsScroll:xe}=f({withThumbs:y,items:t,thumbsSlideAxis:T,springConfig:v,prepareThumbsData:O,slideType:M,getFluidWrapperScrollValue:se,getSlideValue:ae});function we(){if(!D.current)throw new Error("Missing mainCarouselWrapperRef.current");return D.current["x"===re.current?"scrollLeft":"scrollTop"]}function Te(){return"boolean"==typeof W?W:"function"==typeof W&&W()}const Oe=u((e=>{const t=e.dragging,r=e.offset["x"===re.current?0:1],i=e.movement["x"===re.current?0:1],c=i>Q.current,o=i<-Q.current,u=e.direction["x"===re.current?0:1];function s(){e.cancel()}function l(){je(u>0?"prev":"next")}function a(){me(Object.assign({eventName:"onDrag",slideActionType:Ie()},e))}function f(){"fluid"===M?ue()||le()&&"prev"===Ie()?ie.start({[re.current]:0,config:Object.assign({velocity:e.velocity},v)}):Y.current&&"next"===Ie()?ie.start({[re.current]:-V.current,config:Object.assign({velocity:e.velocity},v)}):ie.start({[re.current]:J.current,config:Object.assign({velocity:e.velocity},v)}):ie.start({[re.current]:-Ee()*ae(),config:Object.assign({velocity:e.velocity},v)})}function d(){Math.abs(oe())+100>=V.current&&"next"===Ie()&&(Y.current=!0),"prev"===Ie()&&(Y.current=!1)}if($&&Te())return t&&(Re()||Ce(!0),l(),a(),d()),ie.start({from:{[re.current]:we()},to:{[re.current]:-r},config:{velocity:e.velocity,friction:50,tension:1400}}),0===we()&&"prev"===Ie()?void s():void(e.last&&("prev"===Ie()?Pe(e.velocity):ze(e.velocity),Ce(!1)));if(t){if(Re()||Ce(!0),a(),l(),d(),$){if(Te()){if(0===we()&&"prev"===Ie())return void s();ie.start({config:{velocity:e.velocity,friction:50,tension:1400},from:{[re.current]:we()},to:{[re.current]:-r}})}return}if(ie.start({[re.current]:r,config:{velocity:e.velocity,friction:50,tension:1e3}}),(c||o)&&ue()&&"fluid"===M)s(),f();else if(Y.current&&"next"===Ie()&&o)Y.current=!1,s(),ie.start({[re.current]:-V.current});else if(x){if(o)return s(),void(!n&&Ne()?f():ze(e.velocity));if(c)return s(),void(!n&&le()?f():Pe(e.velocity))}}if(e.last&&!x&&(o||c)&&!$)return Ce(!1),void(o?!n&&Ne()?f():ze(e.velocity):c&&(!n&&le()?f():Pe(e.velocity)));!e.last||o||c||$||(f(),me(Object.assign({eventName:"onDrag",slideActionType:Ie()},e)))}),{enabled:!S,axis:re.current,from:()=>$?"x"===re.current?[-we(),0]:[0,-we()]:[ne.x.get(),ne.y.get()]});function je(e){N.current=e}function Ie(){return N.current}function Se(e){z.current=e}function Ee(){return z.current}function Ae(e){q.current=e}function Ce(e){k.current=e}function Re(){return k.current}function $e(){const e=Ee();return 0===e?t.length-1:e-1}function We(){const e=Ee();return e===t.length-1?0:e+1}function Le(e){return t.findIndex((t=>t.id===e))}function Me(e,t){if("number"==typeof e)return{[re.current]:e};if("number"!=typeof t)throw new Error("to values is not a number!");return{[re.current]:-ae()*t}}function Fe({from:e,to:r=-1,customTo:n,immediate:i=!1,onRest:c=(()=>{}),velocity:o}){i||(Se(r),Ae(!0),me({eventName:"onSlideStartChange",slideActionType:Ie(),nextItem:{index:"fluid"===M?-1:r,id:"fluid"===M?"":t[r].id}})),J.current=Me(n,r)[w],ie.start(Object.assign(Object.assign(Object.assign(Object.assign({},function(e){return"number"==typeof e?{from:{[re.current]:e}}:{}}(e)),{to:Me(n,r)}),o?{config:Object.assign(Object.assign({},g),{velocity:o,friction:void 0,tension:void 0})}:{config:Object.assign({velocity:0},v)}),{immediate:i,onRest:e=>{e.finished&&(Ce(!1),Ae(!1),c(),i||me({eventName:"onSlideChange",slideActionType:Ie(),currentItem:{index:"fluid"===M?-1:Ee(),id:"fluid"===M?"":t[Ee()].id}}))}})),b&&y&&!i&&xe(r,Ie())}function Ne(){return Ee()===t.length-1}function Pe(e){if(je("prev"),Y.current=!1,"fluid"===M){if(Y.current=!1,ue())return;const r=oe()+ae()+200;if($){const t=D.current.scrollLeft-ae();Fe({customTo:t<0?0:t,from:D.current.scrollLeft,velocity:e})}else Fe(r>=0?n?{from:oe()-ce()*t.length,velocity:e,customTo:oe()-ce()*t.length+ae()}:{customTo:0,velocity:e}:{customTo:oe()+ae(),velocity:e})}else{if(!n&&0===Ee()||G.current)return;le()?Fe({from:oe()-ae()*t.length,to:t.length-1,velocity:e}):Fe({to:$e(),velocity:e})}}function ze(e){if(je("next"),"fluid"===M){if(ue())return;const r=Math.abs(oe()-ae())+100>=V.current;if($){const t=D.current.scrollLeft+ae()>V.current,r=D.current.scrollLeft+ae();Fe({velocity:e,customTo:t?V.current:r,from:D.current.scrollLeft})}else if(n&&Math.abs(oe()-ae())>=t.length*ce()){const r=ce()*t.length;Fe({from:oe()+r,customTo:oe()+r-ae(),velocity:e})}else{if(Y.current)return;r?(Y.current=!0,Fe({customTo:-V.current,velocity:e})):Fe({customTo:oe()-ae(),velocity:e})}}else{if(!n&&Ee()===P.length-1||G.current)return;Math.abs(oe()-ae()+25)>V.current&&!Re()?Y.current=!0:Y.current?Fe({to:t.length-U.current,velocity:e}):Ne()?Fe({from:oe()+ae()*t.length,to:0,velocity:e}):Fe({to:We(),velocity:e})}}function De(e){let r=0;if(r="string"==typeof e?t.findIndex((t=>t.id===e)):e,r>=t.length)throw Error("The item you want to slide to doesn't exist. This could be due to the fact that \n you provide a wrong id or a higher numeric index.");if(r===Ee()||t.length!==K.current.length&&Ee()<t.length)return;const n=Le(K.current[Ee()].id);je(Le(t[r].id)>n?"next":"prev"),Fe({to:r})}d((()=>{if(L%2==0&&te.current)throw new Error("initialStartingPosition can be only used if itemsPerSlide is an even value.");if(Q.current<0)throw new Error("draggingSlideTreshold must be greater than 0");if(Q.current>ae()/2)throw new Error(`draggingSlideTreshold must be equal or less than the half of the width of an item, which is ${Math.floor(ae()/2)}`);if(U.current<1)throw new Error("The itemsPerSlide prop can't be less than 1.");if(U.current>t.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(ee.current<0)throw new Error("The initialActiveItem cannot be less than 0.");if(ee.current>t.length)throw new Error("The initialActiveItem cannot be greater than the total length of the items you provide.");p||console.warn("You set shouldResizeOnWindowResize={false}; be aware that the carousel could behave in a strange way if you also use the fullscreen functionality or if you change the mobile orientation.")})),d((()=>{function e(){document.hidden?G.current=!0:G.current=!1}return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),d((()=>{F.current=!1,V.current=se(),X.current=window.innerWidth,H.current=window.innerWidth,j>0&&(Fe({to:j,immediate:!0}),Se(j),!n&&B.current&&(B.current.style.top="0px",B.current.style.left="0px"))})),s((()=>{j<t.length&&j!==z.current&&(Fe({to:j,immediate:!0}),Se(j))}),[j]),s((()=>{if(p)return window.addEventListener("resize",he),()=>{window.removeEventListener("resize",he)}}),[p]),s((()=>{B.current&&("x"===re.current&&(B.current.style.top="0px"),"y"===re.current&&(B.current.style.left="0px"))}),[w]),s((()=>{V.current=se();!(t.length===K.current.length)&&t.length<K.current.length&&De(t.length-1),K.current=t}),[se,t]);const Be=Object.assign({useListenToCustomEvent:ge,getIsFullscreen:ye,enterFullscreen:ve,exitFullscreen:pe,getIsAnimating:function(){return q.current},getIsDragging:Re,getIsNextItem:function(e){const r=Le(e),i=Ee();return n&&i===t.length-1?0===r:r===i+1},getIsPrevItem:function(e){const r=Le(e),i=Ee();return n&&0===i?r===t.length-1:r===i-1},slideToPrevItem(){Pe()},slideToNextItem(){ze()}},"fixed"===M?{slideToItem:De,getIsActiveItem:e=>Le(e)===Ee(),getCurrentActiveItem:()=>({id:t[Ee()].id,index:Ee()})}:{});const ke=e(h.Provider,Object.assign({value:Be},{children:e("div",Object.assign({ref:D,className:"use-spring-carousel-main-wrapper","data-testid":"use-spring-carousel-wrapper"},$?{onWheel(){ne[re.current].stop()}}:{},{style:Object.assign({display:"flex",position:"relative",width:"100%",height:"100%"},$?"x"===re.current?{overflowX:"auto"}:{overflowY:"auto"}:{})},{children:e(o.div,Object.assign({},Oe(),{className:"use-spring-carousel-track-wrapper","data-testid":"use-spring-carousel-animated-wrapper",ref:e=>{e&&(B.current=e,fe(e,ee.current))},style:Object.assign(Object.assign(Object.assign({display:"flex",position:"relative",touchAction:S?"unset":C||("x"===re.current?"pan-y":"pan-x"),flexDirection:"x"===re.current?"row":"column"},function(){const e=`calc(100% - ${2*_.current}px)`;return{width:"x"===re.current?e:"100%",height:"y"===re.current?e:"100%"}}()),function(){const e=t.length/L*100,r=100/L,n="x"===re.current?"left":"y",i=Math.floor(50/r);if("fixed"===M){if("center"===te.current)return{[n]:`calc(-${e}% + ${r*i}%)`};if("end"===te.current)return{[n]:`calc(-${e}% + ${r*(2*i)}%)`}}return{[n]:"0px"}}()),$?{}:ne)},{children:P.map((({id:t,renderItem:r},n)=>{return e("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:Object.assign({display:"flex",position:"relative"},(i=U.current,"fixed"===M?Object.assign(Object.assign({},"x"===re.current?{marginRight:`${Z.current}px`}:{marginBottom:`${Z.current}px`}),{flex:`1 0 calc(100% / ${i} - ${Z.current*(i-1)/i}px)`}):Object.assign({},"x"===re.current?{marginRight:`${Z.current}px`}:{marginBottom:`${Z.current}px`})))},{children:r}),`${t}-${n}`);var i}))}))}))})),qe=e(h.Provider,Object.assign({value:Be},{children:be}));return Object.assign(Object.assign({},Be),{carouselFragment:ke,thumbsFragment:qe})}function v(){const e=n(h);if(!e)throw new Error("useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.");return e}export{m as useSpringCarousel,v as useSpringCarouselContext};
1
+ export{u as useEventsModule,b as useFullscreenModule,a as useThumbsModule}from"./useThumbsModule-ce69c348.js";import"react";import"screenfull";import"react/jsx-runtime";import"@react-spring/web";
2
2
  //# sourceMappingURL=index2.js.map