react-spring-carousel 1.9.29-beta2 → 1.9.29-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useRef as t,useEffect as n,createContext as r,useCallback as i,useContext as o,useState as s}from"react";import{useSpring as u,animated as l,config as c,useTransition as a}from"react-spring";import{useDrag as d}from"@use-gesture/react";import{Subject as m}from"rxjs";import f from"screenfull";function h(){const e=t(new m);return{useListenToCustomEvent:function(t){n((()=>{const n=e.current.subscribe(t);return()=>n.unsubscribe()}),[t])},emitObservable:t=>{e.current.next(t)}}}function g({mainCarouselWrapperRef:e,emitObservable:r,handleResize:i}){const o=t(!1);function s(e){o.current=e}return n((()=>{function e(){document.fullscreenElement&&(s(!0),r({eventName:"onFullscreenChange",isFullscreen:!0}),i&&i()),document.fullscreenElement||(s(!1),r({eventName:"onFullscreenChange",isFullscreen:!1}),i&&i())}if(f.isEnabled)return f.on("change",e),()=>{f.isEnabled&&f.off("change",e)}})),{enterFullscreen:function(t){f.isEnabled&&f.request(t||e.current)},exitFullscreen:function(){f.isEnabled&&f.exit()},getIsFullscreen:function(){return o.current}}}function p(e){const r=t(!1);n((()=>{if(!r.current){const t=e();return r.current=!0,()=>{t&&t()}}}),[])}function b({items:n,withThumbs:r,thumbsSlideAxis:i="x",springConfig:o,thumbsWrapperRef:s,prepareThumbsData:c}){const a=t(null),[d,m]=u((()=>({[i]:0,config:o})));p((()=>{if(r){if(n.some((e=>!e.renderThumb)))throw new Error("The renderThumb property is missing in one or more items. You need to add the renderThumb property to every item of the carousel when the prop withThumbs={true} or eventually set withThumbs={false}.")}}));return{thumbsFragment:r?e(l.div,Object.assign({ref:a},"x"===i?{scrollLeft:d.x}:{scrollTop:d.y},{style:{display:"flex",flex:1,position:"relative",flexDirection:"x"===i?"row":"column",..."x"===i?{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(n)):e(n)}().map((({id:t,renderThumb:n})=>{const r=`thumb-${t}`;return e("div",Object.assign({id:r},{children:n}),r)}))}),void 0):null,handleThumbsScroll:function(e){s&&s.current&&(a.current=s.current);const t=a.current.querySelector(`#thumb-${n[e].id}`);if(t){const r=a.current,o="x"===i?"offsetWidth":"offsetHeight",s="x"===i?"scrollLeft":"scrollTop",u=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:t,offsetDimension:o,offsetDirection:"x"===i?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:r,offsetDimension:o});m.start({from:{[i]:function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:r,scrollDirection:s})},to:{[i]:function({thumbWrapper:t,thumbOffsetPosition:r,thumbScrollDimension:o,offsetDimension:s}){const u="x"===i?"scrollWidth":"scrollHeight";return e===n.length-1||r-o>t[u]-t[s]?t[u]-t[s]:0===e?0:r-o}({thumbWrapper:r,thumbOffsetPosition:u,thumbScrollDimension:l,offsetDimension:o})},onChange:e=>{"x"===i?a.current.scrollLeft=e.x:a.current.scrollTop=e.y}})}}}}const v=r(void 0);function x(){const e=o(v);if(!e)throw new Error("useSpringCarouselContext isn't being used within the useSringCarousel context; \n use the context only inside a component that is rendered within the Carousel.");return e}function w({items:r,withLoop:o=!1,draggingSlideTreshold:s=140,springConfig:a=c.default,shouldResizeOnWindowResize:m=!0,withThumbs:f=!1,enableThumbsWrapperScroll:x=!0,carouselSlideAxis:w="x",thumbsSlideAxis:y="x",thumbsWrapperRef:T,prepareThumbsData:I,itemsPerSlide:S=1,initialActiveItem:C=0,initialStartingPosition:A="start",disableGestures:N=!1,gutter:E=0,startEndGutter:F=0,touchAction:R="none",slideAmount:D}){const O=t("next"),W=o?[...r,...r,...r]:r,P=t(C),L=t(null),j=t(null),$=t(!1),z=t(!1),B=t(!1),M=t(0),q=t(0),H=t(!1),k=t(0),G=t(0);const Y=i((()=>Math.round(Number(j.current?.["x"===w?"scrollWidth":"scrollHeight"])-j.current.getBoundingClientRect()["x"===w?"width":"height"])),[w]),[X,J]=u((()=>({y:0,x:0,config:a,onRest:({value:e})=>{k.current=e[w],G.current=e[w]}}))),K=i((()=>{if(!j.current)return 0;const e=j.current?.querySelector(".use-spring-carousel-item");if(!e)throw Error("No carousel items available!");const t=e.getBoundingClientRect()["x"===w?"width":"height"]+E;if("fluid"===S&&"number"==typeof D){if(D<t)throw new Error("slideAmount must be greater than the width of a single item.");return D}return t}),[w,E,S,D]),Q=i((e=>{if("fluid"!==S&&"number"==typeof S){const o="x"===w?"left":"top";function t(){return K()*r.length}function n(t){e.style.top="0px",e.style.left="0px",e.style[o]=`-${t-F}px`}function i(){n(t())}if(S>1)switch(A){default:case"start":i();break;case"center":n(t()-K()*Math.round((S-1)/2));break;case"end":n(t()-K()*Math.round(S-1))}else i()}}),[F,w,K,A,r.length,S]),U=i((()=>{if(window.innerWidth!==M.current){if(M.current=window.innerWidth,"fluid"===S)if(q.current=Y(),H.current)J.start({immediate:!0,[w]:-q.current});else{const e=document.querySelector(".use-spring-carousel-item:last-of-type");console.log({lastItem:e.offsetLeft})}else J.start({immediate:!0,x:0,y:0}),J.start({immediate:!0,[w]:-K()*le()});o&&Q(j.current)}}),[Q,w,K,J,o,S,Y]),{useListenToCustomEvent:V,emitObservable:Z}=h(),{enterFullscreen:_,exitFullscreen:ee,getIsFullscreen:te}=g({mainCarouselWrapperRef:L,emitObservable:Z,handleResize:U}),{thumbsFragment:ne,handleThumbsScroll:re}=b({withThumbs:f,items:r,thumbsSlideAxis:y,springConfig:a,thumbsWrapperRef:T,prepareThumbsData:I});const ie=d((e=>{const t=e.dragging,n=e.movement["x"===w?0:1];function i(){"fluid"===S?pe()?ve():H.current?J.start({[w]:-q.current}):J.start({[w]:G.current}):J.start({[w]:-le()*K()})}if(e.first&&(k.current=X[w].get()),t){ae(!0),Z({eventName:"onDrag",...e}),J.start({[w]:k.current+n});const t=n>s,u=n<-s;L.current.getBoundingClientRect().width>=r.length*K()&&(H.current=!0),H.current&&n<0?u&&(e.cancel(),J.start({[w]:-q.current})):u?(e.cancel(),!o&&be()?i():xe()):t&&(e.cancel(),!o&&pe()?i():ve())}e.last&&!e.pressed&&i()}),{enabled:!N});function oe(e){O.current=e}function se(){return O.current}function ue(e){P.current=e}function le(){return P.current}function ce(e){z.current=e}function ae(e){$.current=e}function de(){const e=le();return 0===e?r.length-1:e-1}function me(){const e=le();return e===r.length-1?0:e+1}function fe(e){return r.findIndex((t=>t.id===e))}function he({from:e,to:t,customTo:n,immediate:r=!1,onRest:i=(()=>{})}){r||(ue(t),ce(!0),Z({eventName:"onSlideStartChange",nextItem:t,slideActionType:se()})),J.start({...e?{from:{[w]:e}}:{},to:n?{[w]:n}:{[w]:-K()*t},immediate:r,onRest:e=>{e.finished&&(ae(!1),ce(!1),i(),r||Z({eventName:"onSlideChange",currentItem:le(),slideActionType:se()}))}}),x&&f&&!r&&re(t)}function ge(e){if("none"===e.style.transform)return 0;const t=e.style.transform.split(/\w+\(|\);?/);return Number(t[1].split(/,\s?/g)["x"===w?0:1].replace("px",""))}function pe(){return 0===le()}function be(){return le()===r.length-1}function ve(){if("fluid"!==S||o){if(!o&&0===le()||B.current)return;oe("prev"),pe()?he({from:-(Math.abs(ge(j.current))+K()*r.length),to:r.length-1}):he({to:de()})}else{const e=ge(j.current)+K()+100;if(pe())return void he({to:0});if(e>=0)he({to:0}),G.current=0;else{const e=G.current+K();G.current=e,he({to:de(),customTo:e})}H.current&&(H.current=!1)}}function xe(){if("fluid"!==S||o){if(!o&&le()===W.length-1||B.current)return;oe("next"),be()?he({from:ge(j.current)+K()*r.length,to:0}):he({to:me()})}else{const e=Math.abs(me()*K())+100>=q.current;if(L.current.getBoundingClientRect().width>=r.length*K()&&(H.current=!0),H.current)return;if(e){const e=-q.current;H.current=!0,G.current=e,he({to:me(),customTo:e})}else{const e=G.current-K();G.current=e,he({to:me(),customTo:e})}}}p((()=>{if("fluid"!==S&&!Number.isInteger(S))throw new Error("itemsPerSlide should be an integer.");if(S>r.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(S<1)throw new Error("The itemsPerSlide prop can't be less than 1.");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."),C<0&&console.warn("The initialActiveItem cannot be less than 0."),C>r.length&&console.warn("The initialActiveItem cannot be greater than the total length of the items you provide.")})),p((()=>{function e(){document.hidden?B.current=!0:B.current=!1}if(q.current=Y(),"undefined"!=typeof window)return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),p((()=>{C>0&&C<=r.length&&(he({to:C,immediate:!0}),ue(C))})),n((()=>{if(m)return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U)}}),[U,m]),n((()=>{j.current&&("x"===w&&(j.current.style.top="0px"),"y"===w&&(j.current.style.left="0px"))}),[w]);const we={useListenToCustomEvent:V,getIsFullscreen:te,enterFullscreen:_,exitFullscreen:ee,getIsAnimating:function(){return z.current},getIsDragging:function(){return $.current},getIsNextItem:function(e){const t=fe(e),n=le();return o&&n===r.length-1?0===t:t===n+1},getIsPrevItem:function(e){const t=fe(e),n=le();return o&&0===n?t===r.length-1:t===n-1},slideToPrevItem:ve,slideToNextItem:xe,slideToItem:function(e){let t=0;if(t="string"==typeof e?r.findIndex((t=>t.id===e)):e,t>=r.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===le())return;const n=fe(r[le()].id);oe(fe(r[t].id)>n?"next":"prev"),he({to:t})},getIsActiveItem:e=>fe(e)===le(),getCurrentActiveItem:()=>({id:r[le()].id,index:le()})};return{carouselFragment:e(v.Provider,Object.assign({value:we},{children:e("div",Object.assign({ref:L,"data-testid":"use-spring-carousel-wrapper",style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:e(l.div,Object.assign({},ie(),{"data-testid":"use-spring-carousel-animated-wrapper",style:{display:"flex",top:0,left:0,position:"relative",touchAction:R,flexDirection:"x"===w?"row":"column",...function(){const e=`calc(100% - ${2*F}px)`;return{width:"x"===w?e:"100%",height:"y"===w?e:"100%"}}(),...X},ref:e=>{e&&(j.current=e,o&&Q(e))}},{children:W.map((({id:t,renderItem:n},r)=>e("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",..."number"==typeof S?{..."x"===w?{marginRight:`${E}px`}:{marginBottom:`${E}px`},flex:`1 0 calc(100% / ${S} - ${E*(S-1)/S}px)`}:{..."x"===w?{marginRight:`${E}px`}:{marginBottom:`${E}px`}}}},{children:n}),`${t}-${r}`)))}),void 0)}),void 0)}),void 0),thumbsFragment:e(v.Provider,Object.assign({value:we},{children:ne}),void 0),...we}}const y=r(void 0);function T(){const e=o(y);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}function I({items:n,withLoop:r=!1,withThumbs:i=!1,springConfig:o=c.default,thumbsSlideAxis:u="x",enableThumbsWrapperScroll:m=!0,draggingSlideTreshold:f=50,prepareThumbsData:p,toPrevItemSpringProps:v,toNextItemSpringProps:x,disableGestures:w=!1,springAnimationProps:T={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"relative"},leave:{opacity:0,position:"absolute"}}}){const I=t("next"),S=t(null),C=t(!1),[A,N]=s(0),{emitObservable:E,useListenToCustomEvent:F}=h(),{enterFullscreen:R,exitFullscreen:D,getIsFullscreen:O}=g({emitObservable:E,mainCarouselWrapperRef:S}),{thumbsFragment:W,handleThumbsScroll:P}=b({items:n,withThumbs:i,thumbsSlideAxis:u,springConfig:o,prepareThumbsData:p}),L=d((({last:e,movement:[t]})=>{if(!$()&&e){const e=t>f,i=t<-f,o=0===A,s=A===n.length-1;if(i){if(!r&&s)return;q(),E({eventName:"onLeftSwipe"})}else if(e){if(!r&&o)return;H(),E({eventName:"onRightSwipe"})}}}),{enabled:!w});const j=a(A,{config:o,...function(){const e=M();return"prev"===e&&v?{initial:{...T.initial},from:{...v.from},enter:{...v.enter},leave:{...v.leave}}:"next"===e&&x?{initial:{...T.initial},from:{...x.from},enter:{...x.enter},leave:{...x.leave}}:{initial:{...T.initial},from:{...T.from},enter:{...T.enter},leave:{...T.leave}}}(),onStart:()=>z(!0),keys:null,onRest:e=>{e.finished&&(z(!1),E({eventName:"onSlideChange",currentItem:A,slideActionType:M()}))}})(((t,r)=>e(l.div,Object.assign({style:{...t,flex:"1 0 100%",width:"100%",height:"100%"}},{children:n[r].renderItem}),void 0)));function $(){return C.current}function z(e){C.current=e}function B(e){I.current=e}function M(){return I.current}function q(){const e=A===n.length-1;r?(B("next"),e?(E({eventName:"onSlideStartChange",nextItem:0,slideActionType:M()}),N(0)):(E({eventName:"onSlideStartChange",nextItem:A+1,slideActionType:M()}),N(A+1))):e||(E({eventName:"onSlideStartChange",nextItem:A+1,slideActionType:M()}),B("next"),N(A+1))}function H(){const e=0===A;r?(B("prev"),e?(E({eventName:"onSlideStartChange",nextItem:n.length-1,slideActionType:M()}),N(n.length-1)):(E({eventName:"onSlideStartChange",nextItem:A-1,slideActionType:M()}),N(A-1))):e||(B("prev"),E({eventName:"onSlideStartChange",nextItem:A-1,slideActionType:M()}),N(A-1))}function k(e){return n.findIndex((t=>t.id===e))}const G={activeItem:A,slideToItem:function(e){let t=0;if(t="string"==typeof e?n.findIndex((t=>t.id===e)):e,t>=n.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===A)return;const r=k(n[A].id),o=k(n[t].id);E({eventName:"onSlideStartChange",nextItem:o,slideActionType:M()}),B(o>r?"next":"prev"),N(t),m&&i&&P(t)},slideToNextItem:q,slideToPrevItem:H,enterFullscreen:R,exitFullscreen:D,useListenToCustomEvent:F,getIsNextItem:function(e){const t=k(e);return r&&A===n.length-1?0===t:t===A+1},getIsPrevItem:function(e){const t=k(e);return r&&0===A?t===n.length-1:t===A-1},getIsAnimating:$,getIsFullscreen:O,getIsActiveItem:e=>k(e)===A,getCurrentActiveItem:()=>({id:n[A].id,index:A})};return{carouselFragment:e(y.Provider,Object.assign({value:G},{children:e("div",Object.assign({ref:S},L(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:j}),void 0)}),void 0),thumbsFragment:e(y.Provider,Object.assign({value:G},{children:W}),void 0),...G}}export{w as useSpringCarousel,x as useSpringCarouselContext,I as useTransitionCarousel,T as useTransitionCarouselContext};
1
+ import{jsx as e}from"react/jsx-runtime";import{useRef as t,useEffect as n,forwardRef as r,createContext as i,useCallback as o,useContext as s,useState as u}from"react";import{animated as l,useSpring as c,config as a,useTransition as m}from"react-spring";import{useDrag as d}from"@use-gesture/react";import{Subject as f}from"rxjs";import h from"screenfull";function p(){const e=t(new f);return{useListenToCustomEvent:function(t){n((()=>{const n=e.current.subscribe(t);return()=>n.unsubscribe()}),[t])},emitObservable:t=>{e.current.next(t)}}}function g({mainCarouselWrapperRef:e,emitObservable:r,handleResize:i}){const o=t(!1);function s(e){o.current=e}return n((()=>{function e(){document.fullscreenElement&&(s(!0),r({eventName:"onFullscreenChange",isFullscreen:!0}),i&&i()),document.fullscreenElement||(s(!1),r({eventName:"onFullscreenChange",isFullscreen:!1}),i&&i())}if(h.isEnabled)return h.on("change",e),()=>{h.isEnabled&&h.off("change",e)}})),{enterFullscreen:function(t){h.isEnabled&&h.request(t||e.current)},exitFullscreen:function(){h.isEnabled&&h.exit()},getIsFullscreen:function(){return o.current}}}function b(e){const r=t(!1);n((()=>{if(!r.current){const t=e();return r.current=!0,()=>{t&&t()}}}),[])}const v=r((({children:t,...n},r)=>e(l.div,Object.assign({},n,{ref:r},{children:t}),void 0)));function x({items:n,withThumbs:r,thumbsSlideAxis:i="x",springConfig:o,prepareThumbsData:s,itemsPerSlide:u,getFluidWrapperScrollValue:a=(()=>0),getSlideValue:m=(()=>0),CustomThumbsWrapperComponent:d}){const f=t(null),[h,p]=c((()=>({x:0,y:0,config:o,onChange:({value:e})=>{f.current&&(f.current["x"===i?"scrollLeft":"scrollTop"]=Math.abs(e[i]))}})));function g(){return f.current["x"===i?"scrollLeft":"scrollTop"]}function x(){return Math.round(Number(f.current?.["x"===i?"scrollWidth":"scrollHeight"])-f.current.getBoundingClientRect()["x"===i?"width":"height"])}function w(){const e=Math.round(a()/m());return x()/e}b((()=>{if(r&&!f.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.")}));const T=d?l(d):v;return{thumbsFragment:r?e(T,Object.assign({ref:f,className:"use-spring-carousel-thumbs-wrapper",onWheel:()=>{h[i].stop()},style:{display:"flex",flex:1,position:"relative",flexDirection:"x"===i?"row":"column",..."x"===i?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"}}},{children:function(){function e(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return s?s(e(n)):e(n)}().map((({id:t,renderThumb:n})=>{const r=`thumb-${t}`;return e("div",Object.assign({id:r},{children:n}),r)}))}),void 0):null,handleThumbsScroll:function(e,t){if("fluid"===u){const e=x();if("next"===t){const t=g()+w();p.start({from:{[i]:g()},to:{[i]:t>e?e:t}})}if("prev"===t){const e=g()-w();p.start({from:{[i]:g()},to:{[i]:e<0?0:e}})}}else{const t=f.current.querySelector(`#thumb-${n[e].id}`);if(t){const r=f.current,o="x"===i?"offsetWidth":"offsetHeight",s="x"===i?"scrollLeft":"scrollTop",u=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:t,offsetDimension:o,offsetDirection:"x"===i?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:r,offsetDimension:o});p.start({from:{[i]:function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:r,scrollDirection:s})},to:{[i]:function({thumbWrapper:t,thumbOffsetPosition:r,thumbScrollDimension:o,offsetDimension:s}){const u="x"===i?"scrollWidth":"scrollHeight";return e===n.length-1||r-o>t[u]-t[s]?t[u]-t[s]:0===e?0:r-o}({thumbWrapper:r,thumbOffsetPosition:u,thumbScrollDimension:l,offsetDimension:o})},onChange:e=>{"x"===i?f.current.scrollLeft=e.x:f.current.scrollTop=e.y}})}}}}}const w=i(void 0);function T({itemsPerSlide:r=1,items:i,withLoop:s=!1,draggingSlideTreshold:u=140,springConfig:m=a.default,shouldResizeOnWindowResize:f=!0,withThumbs:h=!1,enableThumbsWrapperScroll:v=!0,carouselSlideAxis:T="x",thumbsSlideAxis:y="x",prepareThumbsData:C,initialActiveItem:S=0,initialStartingPosition:I="start",disableGestures:W=!1,gutter:A=0,startEndGutter:F=0,touchAction:E="none",slideAmount:N,freeScroll:L=!1,CustomThumbsWrapperComponent:R}){const O=t("initial"),D=s?[...i,...i,...i]:i,P=t(S),j=t(null),M=t(null),$=t(!1),z=t(!1),B=t(!1),H=t(0),V=t(0),k=t(!1),q=t(0),[G,Y]=c((()=>({y:0,x:0,config:m,onChange:({value:e})=>{j.current&&L&&(j.current["x"===T?"scrollLeft":"scrollTop"]=Math.abs(e[T]))}})));const X=o((()=>{if(!j.current)throw new Error("mainCarouselWrapperRef is not available");return j.current.getBoundingClientRect()["x"===T?"width":"height"]}),[T]),J=o((()=>{const e=M.current?.querySelector(".use-spring-carousel-item");if(!e)throw Error("No carousel items available!");return e.getBoundingClientRect()["x"===T?"width":"height"]+A}),[T,A]),K=o((()=>G[T].get()),[T,G]),Q=o((()=>J()*i.length<X()),[J,X,i.length]),U=o((()=>Math.round(Number(M.current?.["x"===T?"scrollWidth":"scrollHeight"])-M.current.getBoundingClientRect()["x"===T?"width":"height"])),[T]),Z=o((()=>0===he()),[]),_=o((()=>{if(!M.current)return 0;const e=J();if("fluid"===r&&"number"==typeof N){if(N<e)throw new Error("slideAmount must be greater than the width of a single item.");return N}return e}),[J,r,N]),ee=o((e=>{const t="x"===T?"left":"top";function n(){return J()*i.length}function o(n){e.style.top="0px",e.style.left="0px",e.style[t]=`-${n-F}px`}function s(){o(n())}if("fluid"!==r&&"number"==typeof r){if(r>1)switch(I){default:case"start":s();break;case"center":o(n()-_()*Math.round((r-1)/2));break;case"end":o(n()-_()*Math.round(r-1))}else s()}else s()}),[T,r,J,i.length,F,_,I]),te=o((()=>{if(window.innerWidth!==H.current&&!L){if(H.current=window.innerWidth,"fluid"===r){if(Q())return void Y.start({immediate:!0,[T]:0});V.current=U();const e=H.current-q.current;if(k.current){const e=-V.current;Y.start({immediate:!0,[T]:e})}else{const t=K()+e;Y.start({immediate:!0,[T]:t})}q.current=window.innerWidth}else Y.start({immediate:!0,x:0,y:0}),Y.start({immediate:!0,[T]:-_()*he()});s&&ee(M.current)}}),[r,s,Q,U,L,Y,T,K,_,ee]),{useListenToCustomEvent:ne,emitObservable:re}=p(),{enterFullscreen:ie,exitFullscreen:oe,getIsFullscreen:se}=g({mainCarouselWrapperRef:j,emitObservable:re,handleResize:te}),{thumbsFragment:ue,handleThumbsScroll:le}=x({withThumbs:h,items:i,thumbsSlideAxis:y,springConfig:m,prepareThumbsData:C,itemsPerSlide:r,getFluidWrapperScrollValue:U,getSlideValue:_,CustomThumbsWrapperComponent:R});function ce(){if(!j.current)throw new Error("Missing mainCarouselWrapperRef.current");return j.current["x"===T?"scrollLeft":"scrollTop"]}const ae=d((e=>{const t=e.dragging,n=e.movement["x"===T?0:1];function o(){"fluid"===r?Q()?Y.start({[T]:0}):Z()?ye():k.current?Y.start({[T]:-V.current}):Y.start({[T]:K()}):Y.start({[T]:-he()*_()})}if(t){if(ge(!0),re({eventName:"onDrag",...e}),L){const t=e.direction["x"===T?0:1];0===ce()&&t>0?e.cancel():Y.start({from:{[T]:ce()},to:{[T]:t>0?ce()-Math.abs(n):ce()+Math.abs(n)}})}else Y.start({[T]:K()+n});const t=n>u,r=n<-u;if(j.current.getBoundingClientRect().width>=i.length*_()&&(k.current=!0),(t||r)&&Q())return e.cancel(),void o();k.current&&n<0?r&&(e.cancel(),Y.start({[T]:-V.current})):r?(e.cancel(),!s&&Te()?o():Ce()):t&&(e.cancel(),!s&&Z()?o():ye())}!e.last||e.pressed||L||o()}),{enabled:!W});function me(e){O.current=e}function de(){return O.current}function fe(e){P.current=e}function he(){return P.current}function pe(e){z.current=e}function ge(e){$.current=e}function be(){const e=he();return 0===e?i.length-1:e-1}function ve(){const e=he();return e===i.length-1?0:e+1}function xe(e){return i.findIndex((t=>t.id===e))}function we({from:e,to:t=-1,customTo:n,immediate:r=!1,onRest:i=(()=>{})}){r||(fe(t),pe(!0),re({eventName:"onSlideStartChange",nextItem:t,slideActionType:de()})),Y.start({..."number"==typeof e?{from:{[T]:e}}:{},to:"number"==typeof n?{[T]:n}:{[T]:-_()*t},immediate:r,onRest:e=>{e.finished&&(ge(!1),pe(!1),i(),r||re({eventName:"onSlideChange",currentItem:he(),slideActionType:de()}))}}),v&&h&&!r&&le(t,de())}function Te(){return he()===i.length-1}function ye(){if(me("prev"),"fluid"===r){if(Q())return;const e=K()+_()+200;if(L){const e=j.current.scrollLeft-_();we({customTo:e<0?0:e,from:j.current.scrollLeft})}else we(e>=0?s?{from:K()-J()*i.length,customTo:K()-J()*i.length+_()}:{customTo:0}:{customTo:K()+_()});k.current&&(k.current=!1)}else{if(!s&&0===he()||B.current)return;Z()?we({from:K()-_()*i.length,to:i.length-1}):we({to:be()})}}function Ce(){if(me("next"),"fluid"===r){if(Q())return;const e=Math.abs(K()-_())+100>=V.current;if(L)we({customTo:j.current.scrollLeft+_(),from:j.current.scrollLeft});else if(s&&Math.abs(K()-_())>=i.length*J()){const e=J()*i.length;we({from:K()+e,customTo:K()+e-_()})}else{if(k.current)return;e?(k.current=!0,we({customTo:-V.current})):we({customTo:K()-_()})}}else{if(!s&&he()===D.length-1||B.current)return;Te()?we({from:K()+_()*i.length,to:0}):we({to:ve()})}}b((()=>{if("fluid"!==r&&!Number.isInteger(r))throw new Error("itemsPerSlide should be an integer.");if(r>i.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(r<1)throw new Error("The itemsPerSlide prop can't be less than 1.");f||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."),S<0&&console.warn("The initialActiveItem cannot be less than 0."),S>i.length&&console.warn("The initialActiveItem cannot be greater than the total length of the items you provide.")})),b((()=>{function e(){document.hidden?B.current=!0:B.current=!1}if(V.current=U(),"undefined"!=typeof window)return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),b((()=>{q.current=window.innerWidth,S>0&&S<=i.length&&(we({to:S,immediate:!0}),fe(S))})),n((()=>{if(f)return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te)}}),[te,f]),n((()=>{M.current&&("x"===T&&(M.current.style.top="0px"),"y"===T&&(M.current.style.left="0px"))}),[T]);const Se={useListenToCustomEvent:ne,getIsFullscreen:se,enterFullscreen:ie,exitFullscreen:oe,getIsAnimating:function(){return z.current},getIsDragging:function(){return $.current},getIsNextItem:function(e){const t=xe(e),n=he();return s&&n===i.length-1?0===t:t===n+1},getIsPrevItem:function(e){const t=xe(e),n=he();return s&&0===n?t===i.length-1:t===n-1},slideToPrevItem:ye,slideToNextItem:Ce,..."number"==typeof r?{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===he())return;const n=xe(i[he()].id);me(xe(i[t].id)>n?"next":"prev"),we({to:t})},getIsActiveItem:e=>xe(e)===he(),getCurrentActiveItem:()=>({id:i[he()].id,index:he()})}:{}};const Ie=e(w.Provider,Object.assign({value:Se},{children:e("div",Object.assign({ref:j,"data-testid":"use-spring-carousel-wrapper"},L?{onWheel(){G[T].stop()}}:{},{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden",...L?"x"===T?{overflowX:"auto"}:{overflowY:"auto"}:{}}},{children:e(l.div,Object.assign({},ae(),{"data-testid":"use-spring-carousel-animated-wrapper",ref:function(e){e&&(M.current=e,s&&ee(e))},style:{display:"flex",top:0,left:0,position:"relative",touchAction:E,flexDirection:"x"===T?"row":"column",...function(){const e=`calc(100% - ${2*F}px)`;return{width:"x"===T?e:"100%",height:"y"===T?e:"100%"}}(),...L?{}:G}},{children:D.map((({id:t,renderItem:n},i)=>e("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",..."number"==typeof r?{..."x"===T?{marginRight:`${A}px`}:{marginBottom:`${A}px`},flex:`1 0 calc(100% / ${r} - ${A*(r-1)/r}px)`}:{..."x"===T?{marginRight:`${A}px`}:{marginBottom:`${A}px`}}}},{children:n}),`${t}-${i}`)))}),void 0)}),void 0)}),void 0),We=e(w.Provider,Object.assign({value:Se},{children:ue}),void 0);return{...Se,carouselFragment:Ie,thumbsFragment:We}}function y(){const e=s(w);if(!e)throw new Error("useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.");return e}const C=i(void 0);function S(){const e=s(C);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}function I({items:n,withLoop:r=!1,withThumbs:i=!1,springConfig:o=a.default,thumbsSlideAxis:s="x",enableThumbsWrapperScroll:c=!0,draggingSlideTreshold:f=50,prepareThumbsData:h,toPrevItemSpringProps:b,toNextItemSpringProps:v,disableGestures:w=!1,CustomThumbsWrapperComponent:T,springAnimationProps:y={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"relative"},leave:{opacity:0,position:"absolute"}}}){const S=t("next"),I=t(null),W=t(!1),[A,F]=u(0),{emitObservable:E,useListenToCustomEvent:N}=p(),{enterFullscreen:L,exitFullscreen:R,getIsFullscreen:O}=g({emitObservable:E,mainCarouselWrapperRef:I}),{thumbsFragment:D,handleThumbsScroll:P}=x({items:n,withThumbs:i,thumbsSlideAxis:s,springConfig:o,prepareThumbsData:h,CustomThumbsWrapperComponent:T}),j=d((({last:e,movement:[t]})=>{if(!$()&&e){const e=t>f,i=t<-f,o=0===A,s=A===n.length-1;if(i){if(!r&&s)return;V(),E({eventName:"onLeftSwipe"})}else if(e){if(!r&&o)return;k(),E({eventName:"onRightSwipe"})}}}),{enabled:!w});const M=m(A,{config:o,...function(){const e=H();return"prev"===e&&b?{initial:{...y.initial},from:{...b.from},enter:{...b.enter},leave:{...b.leave}}:"next"===e&&v?{initial:{...y.initial},from:{...v.from},enter:{...v.enter},leave:{...v.leave}}:{initial:{...y.initial},from:{...y.from},enter:{...y.enter},leave:{...y.leave}}}(),onStart:()=>z(!0),keys:null,onRest:e=>{e.finished&&(z(!1),E({eventName:"onSlideChange",currentItem:A,slideActionType:H()}))}})(((t,r)=>e(l.div,Object.assign({style:{...t,flex:"1 0 100%",width:"100%",height:"100%"}},{children:n[r].renderItem}),void 0)));function $(){return W.current}function z(e){W.current=e}function B(e){S.current=e}function H(){return S.current}function V(){const e=A===n.length-1;r?(B("next"),e?(E({eventName:"onSlideStartChange",nextItem:0,slideActionType:H()}),F(0)):(E({eventName:"onSlideStartChange",nextItem:A+1,slideActionType:H()}),F(A+1))):e||(E({eventName:"onSlideStartChange",nextItem:A+1,slideActionType:H()}),B("next"),F(A+1))}function k(){const e=0===A;r?(B("prev"),e?(E({eventName:"onSlideStartChange",nextItem:n.length-1,slideActionType:H()}),F(n.length-1)):(E({eventName:"onSlideStartChange",nextItem:A-1,slideActionType:H()}),F(A-1))):e||(B("prev"),E({eventName:"onSlideStartChange",nextItem:A-1,slideActionType:H()}),F(A-1))}function q(e){return n.findIndex((t=>t.id===e))}const G={activeItem:A,slideToItem:function(e){let t=0;if(t="string"==typeof e?n.findIndex((t=>t.id===e)):e,t>=n.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===A)return;const r=q(n[A].id),o=q(n[t].id);E({eventName:"onSlideStartChange",nextItem:o,slideActionType:H()}),B(o>r?"next":"prev"),F(t),c&&i&&P(t)},slideToNextItem:V,slideToPrevItem:k,enterFullscreen:L,exitFullscreen:R,useListenToCustomEvent:N,getIsNextItem:function(e){const t=q(e);return r&&A===n.length-1?0===t:t===A+1},getIsPrevItem:function(e){const t=q(e);return r&&0===A?t===n.length-1:t===A-1},getIsAnimating:$,getIsFullscreen:O,getIsActiveItem:e=>q(e)===A,getCurrentActiveItem:()=>({id:n[A].id,index:A})};return{carouselFragment:e(C.Provider,Object.assign({value:G},{children:e("div",Object.assign({ref:I},j(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:M}),void 0)}),void 0),thumbsFragment:e(C.Provider,Object.assign({value:G},{children:D}),void 0),...G}}export{T as useSpringCarousel,y as useSpringCarouselContext,I as useTransitionCarousel,S as useTransitionCarouselContext};
2
2
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/modules/useCustomEventsModule.tsx","../src/modules/useFullscreenModule.tsx","../src/utils.ts","../src/modules/useThumbsModule.tsx","../src/useSpringCarousel.tsx","../src/useTransitionCarousel.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport { EventsObservableProps, ObservableCallbackFn, EmitObservableFn } from '../types'\n\nexport function useCustomEventsModule() {\n const eventsObserverRef = useRef(new Subject<EventsObservableProps>())\n\n function useListenToCustomEvent(fn: ObservableCallbackFn) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, MutableRefObject, useEffect } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn\n handleResize?(): void\n}\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false)\n\n useEffect(() => {\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\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, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nexport function useMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useEffect(() => {\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 function getIsBrowser() {\n return typeof window !== 'undefined'\n}\n","import { useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport {\n UseSpringCarouselProps,\n ReactSpringThumbItem,\n PrepareThumbsData,\n UseSpringCarouselItems,\n} from '../types'\nimport { useMount } from '../utils'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: UseSpringCarouselItems['items']\n withThumbs: boolean\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n thumbsWrapperRef?: UseSpringCarouselProps['thumbsWrapperRef']\n springConfig: SpringConfig\n prepareThumbsData?: PrepareThumbsData\n}\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n thumbsWrapperRef,\n prepareThumbsData,\n}: Props) {\n const internalThumbsWrapperRef = useRef<HTMLDivElement | null>(null)\n const [thumbListStyles, setThumbListStyles] = useSpring(() => ({\n [thumbsSlideAxis]: 0,\n config: springConfig,\n }))\n\n useMount(() => {\n if (withThumbs) {\n const missingThumbs = items.some(item => !item.renderThumb)\n if (missingThumbs) {\n throw new Error(\n 'The renderThumb property is missing in one or more items. You need to add the renderThumb property to every item of the carousel when the prop withThumbs={true} or eventually set withThumbs={false}.',\n )\n }\n }\n })\n\n function handleThumbsScroll(activeItem: number) {\n function getOffsetDirection() {\n return thumbsSlideAxis === 'x' ? 'offsetLeft' : 'offsetTop'\n }\n function getOffsetDimension() {\n return thumbsSlideAxis === 'x' ? 'offsetWidth' : 'offsetHeight'\n }\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 if (thumbsWrapperRef && thumbsWrapperRef.current) {\n internalThumbsWrapperRef.current = thumbsWrapperRef.current\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 setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }),\n },\n to: {\n [thumbsSlideAxis]: getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }),\n },\n onChange: val => {\n if (thumbsSlideAxis === 'x') {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollLeft = val.x\n } else {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollTop = val.y\n }\n },\n })\n }\n }\n function handlePrepareThumbsDate() {\n function getPreparedItems(\n _items: UseSpringCarouselItems['items'],\n ): ReactSpringThumbItem[] {\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 function getScrollDirectionSpringValue() {\n if (thumbsSlideAxis === 'x') {\n return {\n // @ts-ignore\n scrollLeft: thumbListStyles.x,\n }\n }\n\n return {\n // @ts-ignore\n scrollTop: thumbListStyles.y,\n }\n }\n\n const thumbsFragment = withThumbs ? (\n <animated.div\n ref={internalThumbsWrapperRef}\n {...getScrollDirectionSpringValue()}\n style={{\n display: 'flex',\n flex: 1,\n position: 'relative',\n flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsDate().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId}>\n {renderThumb}\n </div>\n )\n })}\n </animated.div>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n","import { useRef, createContext, useCallback, useContext, useEffect } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from './modules'\nimport {\n UseSpringCarouselProps,\n UseSpringCarouselContextProps,\n SlideToItemFnProps,\n SlideActionType,\n} from './types'\nimport { useMount } from './utils'\nimport { getIsBrowser } from './utils'\n\nconst UseSpringCarouselContext = createContext<UseSpringCarouselContextProps | undefined>(\n undefined,\n)\n\nexport function useSpringCarouselContext() {\n const context = useContext(UseSpringCarouselContext)\n\n if (!context) {\n throw new Error(`useSpringCarouselContext isn't being used within the useSringCarousel context; \n use the context only inside a component that is rendered within the Carousel.`)\n }\n\n return context\n}\n\nexport default function useSpringCarousel({\n items,\n withLoop = false,\n draggingSlideTreshold = 140,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n thumbsWrapperRef,\n prepareThumbsData,\n itemsPerSlide = 1,\n initialActiveItem = 0,\n initialStartingPosition = 'start',\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction = 'none',\n slideAmount,\n}: UseSpringCarouselProps) {\n function getItems() {\n if (withLoop) {\n return [...items, ...items, ...items]\n }\n return items\n }\n const slideActionType = useRef<SlideActionType>('next')\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 currentWindowWidth = useRef(0)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideFluidEndReached = useRef(false)\n const currentSlidedValue = useRef(0)\n const currentStepSlideValue = useRef(0)\n\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n const getFluidWrapperScrollValue = useCallback(() => {\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 }, [carouselSlideAxis])\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n config: springConfig,\n onRest: ({ value }) => {\n currentSlidedValue.current = value[carouselSlideAxis]\n currentStepSlideValue.current = value[carouselSlideAxis]\n },\n }))\n const getSlideValue = useCallback(() => {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const carouselItem = getCarouselItem()\n\n if (!carouselItem) {\n throw Error('No carousel items available!')\n }\n const itemVal =\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === 'x' ? 'width' : 'height'\n ] + gutter\n\n if (itemsPerSlide === '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 }, [carouselSlideAxis, gutter, itemsPerSlide, slideAmount])\n const adjustCarouselWrapperPosition = useCallback(\n (ref: HTMLDivElement) => {\n if (itemsPerSlide !== 'fluid' && typeof itemsPerSlide === 'number') {\n const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top'\n\n function getDefaultPositionValue() {\n return getSlideValue() * items.length\n }\n function setPosition(v: number) {\n ref.style.top = '0px'\n ref.style.left = '0px'\n ref.style[positionProperty] = `-${v - startEndGutter}px`\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n function setCenterPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((itemsPerSlide as number) - 1) / 2),\n )\n }\n function setEndPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round((itemsPerSlide as number) - 1),\n )\n }\n\n if (itemsPerSlide > 1) {\n switch (initialStartingPosition) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition()\n break\n }\n case 'end': {\n setEndPosition()\n break\n }\n }\n } else {\n setStartPosition()\n }\n }\n },\n [\n startEndGutter,\n carouselSlideAxis,\n getSlideValue,\n initialStartingPosition,\n items.length,\n itemsPerSlide,\n ],\n )\n const handleResize = useCallback(() => {\n if (window.innerWidth === currentWindowWidth.current) {\n return\n }\n currentWindowWidth.current = window.innerWidth\n\n if (itemsPerSlide === 'fluid') {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n const lastItem = document.querySelector(\n '.use-spring-carousel-item:last-of-type',\n )! as HTMLDivElement\n console.log({\n lastItem: lastItem.offsetLeft,\n })\n }\n } else {\n setCarouselStyles.start({\n immediate: true,\n x: 0,\n y: 0,\n })\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n if (withLoop) {\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n }, [\n adjustCarouselWrapperPosition,\n carouselSlideAxis,\n getSlideValue,\n setCarouselStyles,\n withLoop,\n itemsPerSlide,\n getFluidWrapperScrollValue,\n ])\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items,\n thumbsSlideAxis,\n springConfig,\n thumbsWrapperRef,\n prepareThumbsData,\n })\n function getCurrentSlidedValue() {\n return carouselStyles[carouselSlideAxis].get()\n }\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.movement[carouselSlideAxis === 'x' ? 0 : 1]\n function resetAnimation() {\n if (itemsPerSlide === 'fluid') {\n if (getIsFirstItem()) {\n slideToPrevItem()\n } else if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: currentStepSlideValue.current,\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: -(getCurrentActiveItem() * getSlideValue()),\n })\n }\n }\n\n if (props.first) {\n currentSlidedValue.current = getCurrentSlidedValue()\n }\n if (isDragging) {\n setIsDragging(true)\n emitObservable({\n eventName: 'onDrag',\n ...props,\n })\n\n setCarouselStyles.start({\n [carouselSlideAxis]: currentSlidedValue.current + movement,\n })\n\n const prevItemTreshold = movement > draggingSlideTreshold\n const nextItemTreshold = movement < -draggingSlideTreshold\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n\n if (slideFluidEndReached.current && movement < 0) {\n if (nextItemTreshold) {\n props.cancel()\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n }\n } else if (nextItemTreshold) {\n props.cancel()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem()\n }\n } else if (prevItemTreshold) {\n props.cancel()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem()\n }\n }\n }\n if (props.last && !props.pressed) {\n resetAnimation()\n }\n },\n {\n enabled: !disableGestures,\n },\n )\n\n // Perform some check on first mount\n useMount(() => {\n if (itemsPerSlide !== 'fluid' && !Number.isInteger(itemsPerSlide)) {\n throw new Error(`itemsPerSlide should be an integer.`)\n }\n if (itemsPerSlide > 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 (itemsPerSlide < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\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 if (initialActiveItem < 0) {\n console.warn('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItem > items.length) {\n console.warn(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n })\n useMount(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n if (getIsBrowser()) {\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n }\n })\n useMount(() => {\n if (initialActiveItem > 0 && initialActiveItem <= items.length) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n })\n useEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n }, [handleResize, shouldResizeOnWindowResize])\n useEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxis === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\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 slideToItem({\n from,\n to,\n customTo,\n immediate = false,\n onRest = () => {},\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: to,\n slideActionType: getSlideActionType(),\n })\n }\n\n function getFromValue() {\n if (from) {\n return {\n from: {\n [carouselSlideAxis]: from,\n },\n }\n }\n return {}\n }\n function getToValue() {\n if (customTo) {\n return {\n [carouselSlideAxis]: customTo,\n }\n }\n return {\n [carouselSlideAxis]: -(getSlideValue() * to),\n }\n }\n\n setCarouselStyles.start({\n ...getFromValue(),\n to: getToValue(),\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 currentItem: getCurrentActiveItem(),\n slideActionType: getSlideActionType(),\n })\n }\n }\n },\n })\n if (enableThumbsWrapperScroll && withThumbs && !immediate) {\n handleThumbsScroll(to)\n }\n }\n function getWrapperFromValue(element: HTMLDivElement) {\n if (element.style.transform === 'none') {\n return 0\n }\n const values = element.style.transform.split(/\\w+\\(|\\);?/)\n return Number(\n values[1].split(/,\\s?/g)[carouselSlideAxis === 'x' ? 0 : 1].replace('px', ''),\n )\n }\n function getIsFirstItem() {\n return getCurrentActiveItem() === 0\n }\n function getIsLastItem() {\n return getCurrentActiveItem() === items.length - 1\n }\n function slideToPrevItem() {\n if (itemsPerSlide === 'fluid' && !withLoop) {\n const currentSlideVal = getWrapperFromValue(carouselTrackWrapperRef.current!)\n const nextPrevValue = currentSlideVal + getSlideValue() + 100\n\n if (getIsFirstItem()) {\n slideToItem({\n to: 0,\n })\n return\n }\n if (nextPrevValue >= 0) {\n slideToItem({\n to: 0,\n })\n currentStepSlideValue.current = 0\n } else {\n const nextVal = currentStepSlideValue.current + getSlideValue()\n currentStepSlideValue.current = nextVal\n slideToItem({\n to: getPrevItem(),\n customTo: nextVal,\n })\n }\n if (slideFluidEndReached.current) {\n slideFluidEndReached.current = false\n }\n } else if ((!withLoop && getCurrentActiveItem() === 0) || windowIsHidden.current) {\n return\n } else {\n setSlideActionType('prev')\n\n if (getIsFirstItem()) {\n slideToItem({\n from: -(\n Math.abs(getWrapperFromValue(carouselTrackWrapperRef.current!)) +\n getSlideValue() * items.length\n ),\n to: items.length - 1,\n })\n } else {\n slideToItem({\n to: getPrevItem(),\n })\n }\n }\n }\n function slideToNextItem() {\n if (itemsPerSlide === 'fluid' && !withLoop) {\n const willGoAfterLastFluidItem =\n Math.abs(getNextItem() * getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n if (slideFluidEndReached.current) {\n return\n }\n if (willGoAfterLastFluidItem) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n slideFluidEndReached.current = true\n currentStepSlideValue.current = nextValue\n\n slideToItem({\n to: getNextItem(),\n customTo: nextValue,\n })\n } else {\n const nextValue = currentStepSlideValue.current - getSlideValue()\n currentStepSlideValue.current = nextValue\n\n slideToItem({\n to: getNextItem(),\n customTo: nextValue,\n })\n }\n } else if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n } else {\n setSlideActionType('next')\n\n if (getIsLastItem()) {\n slideToItem({\n from:\n getWrapperFromValue(carouselTrackWrapperRef.current!) +\n getSlideValue() * items.length,\n to: 0,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n })\n }\n }\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 if (itemIndex === getCurrentActiveItem()) {\n return\n }\n\n const currentItem = findItemIndex(items[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 const contextProps: UseSpringCarouselContextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem,\n slideToNextItem,\n slideToItem: _slideToItem,\n getIsActiveItem: id => {\n return findItemIndex(id) === getCurrentActiveItem()\n },\n getCurrentActiveItem: () => ({\n id: items[getCurrentActiveItem()].id,\n index: getCurrentActiveItem(),\n }),\n }\n function getItemStyles() {\n if (typeof itemsPerSlide === 'number') {\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\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 const carouselFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\n data-testid=\"use-spring-carousel-wrapper\"\n style={{\n display: 'flex',\n position: 'relative',\n width: '100%',\n height: '100%',\n overflow: 'hidden',\n }}\n >\n <animated.div\n {...bindDrag()}\n data-testid=\"use-spring-carousel-animated-wrapper\"\n style={{\n display: 'flex',\n top: 0,\n left: 0,\n position: 'relative',\n touchAction,\n flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\n ...carouselStyles,\n }}\n ref={ref => {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n if (withLoop) {\n adjustCarouselWrapperPosition(ref)\n }\n }\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(),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </UseSpringCarouselContext.Provider>\n )\n const thumbsFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n {_thumbsFragment}\n </UseSpringCarouselContext.Provider>\n )\n\n return {\n carouselFragment,\n thumbsFragment,\n ...contextProps,\n }\n}\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 {\n UseTransitionCarouselContextProps,\n UseTransitionCarouselProps,\n SlideActionType,\n} from './types'\n\nconst UseTransitionCarouselContext = createContext<\n UseTransitionCarouselContextProps | undefined\n>(undefined)\n\nexport function 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\nexport default function 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 springAnimationProps = {\n initial: {\n opacity: 1,\n position: 'relative',\n },\n from: {\n opacity: 0,\n position: 'absolute',\n },\n enter: {\n opacity: 1,\n position: 'relative',\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 } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n emitObservable,\n mainCarouselWrapperRef,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\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 keys: null,\n onRest: val => {\n if (val.finished) {\n setIsAnimating(false)\n emitObservable({\n eventName: 'onSlideChange',\n currentItem: activeItem,\n slideActionType: getSlideActionType(),\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 nextItem: newActiveItem,\n slideActionType: getSlideActionType(),\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 nextItem: 0,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(0)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem + 1)\n }\n } else {\n if (!isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\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 nextItem: items.length - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(items.length - 1)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem - 1)\n }\n } else {\n if (!isFirstItem) {\n setSlideActionType('prev')\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\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"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useMount","callback","isMounted","clean","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","thumbsWrapperRef","prepareThumbsData","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","[object Object]","config","some","item","renderThumb","Error","thumbsFragment","_jsx","animated","div","ref","scrollLeft","x","scrollTop","y","style","display","flex","position","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","handlePrepareThumbsDate","thumbId","handleThumbsScroll","activeItem","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","start","from","getScrollFromValue","to","scrollDimensionProperty","length","getScrollToValue","onChange","val","UseSpringCarouselContext","createContext","undefined","useSpringCarouselContext","context","useContext","useSpringCarousel","withLoop","draggingSlideTreshold","default","shouldResizeOnWindowResize","enableThumbsWrapperScroll","carouselSlideAxis","itemsPerSlide","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","slideActionType","internalItems","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","currentWindowWidth","fluidTotalWrapperScrollValue","slideFluidEndReached","currentSlidedValue","currentStepSlideValue","getFluidWrapperScrollValue","useCallback","Math","round","Number","getBoundingClientRect","carouselStyles","setCarouselStyles","onRest","value","getSlideValue","carouselItem","itemVal","adjustCarouselWrapperPosition","positionProperty","getDefaultPositionValue","setPosition","v","top","left","setStartPosition","window","innerWidth","immediate","lastItem","console","log","offsetLeft","getCurrentActiveItem","_thumbsFragment","bindDrag","useDrag","props","dragging","movement","resetAnimation","getIsFirstItem","slideToPrevItem","first","get","setIsDragging","prevItemTreshold","nextItemTreshold","width","cancel","getIsLastItem","slideToNextItem","last","pressed","enabled","setSlideActionType","type","getSlideActionType","setActiveItem","newItem","setIsAnimating","getPrevItem","currentActiveItem","getNextItem","findItemIndex","findIndex","slideToItem","customTo","nextItem","finished","currentItem","getWrapperFromValue","element","transform","values","split","replace","abs","nextPrevValue","nextVal","willGoAfterLastFluidItem","nextValue","isInteger","warn","handleVisibilityChange","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsDragging","getIsNextItem","itemIndex","getIsPrevItem","_item","getIsActiveItem","index","carouselFragment","Provider","height","overflow","percentValue","getAnimatedWrapperStyles","renderItem","className","marginRight","marginBottom","UseTransitionCarouselContext","useTransitionCarouselContext","useTransitionCarousel","toPrevItemSpringProps","toNextItemSpringProps","springAnimationProps","initial","opacity","enter","leave","useState","bindSwipe","mx","isFirstItem","isLastItem","itemsFragment","useTransition","getTransitionConfig","onStart","keys","transitions","styles","newActiveItem"],"mappings":"6VAIgBA,IACd,MAAMC,EAAoBC,EAAO,IAAIC,GAarC,MAAO,CACLC,uBAZF,SAAgCC,GAC9BC,GAAU,KACR,MAAMC,EAAYN,EAAkBO,QAAQD,UAAUF,GACtD,MAAO,IAAME,EAAUE,gBACtB,CAACJ,KASJK,eANuCC,IACvCV,EAAkBO,QAAQI,KAAKD,cCLnBE,GAAoBC,uBAClCA,EAAsBJ,eACtBA,EAAcK,aACdA,IAEA,MAAMC,EAAed,GAAO,GAmC5B,SAASe,EAAgBC,GACvBF,EAAaR,QAAUU,EAiBzB,OAnDAZ,GAAU,KACR,SAASa,IACHC,SAASC,oBACXJ,GAAgB,GAChBP,EAAe,CACbY,UAAW,qBACXN,cAAc,IAGhBD,GAAgBA,KAGbK,SAASC,oBACZJ,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GAEhC,OAAI+B,GAAY3B,IAAezC,EAAMyD,OAAS,EACvB,IAAd2H,EAGFA,IAAc3I,EAAa,GAqBlC4I,cAnBF,SAAuBhJ,GACrB,MAAM+I,EAAY5B,EAAcnH,GAEhC,OAAI+B,GAA2B,IAAf3B,EACP2I,IAAcpL,EAAMyD,OAAS,EAG/B2H,IAAc3I,EAAa,GAalCwI,eAAAA,EACAvL,gBAAAA,EACA6L,gBAAiBlJ,GACRmH,EAAcnH,KAAQI,EAE/BgF,qBAAsB,MACpBpF,GAAIrC,EAAMyC,GAAYJ,GACtBmJ,MAAO/I,KA4BX,MAAO,CACLgJ,iBAxBAxK,EAACkL,EAA6BT,wBAASpF,MAAO0E,aAC5C/J,uBACEG,IAAK5C,GACDsO,KACJrL,MAAO,CACLC,QAAS,OACTE,SAAU,WACV4G,MAAO,OACPmD,OAAQ,OACRC,SAAU,qBAGXsB,sBAaLlM,eAPAC,EAACkL,EAA6BT,wBAASpF,MAAO0E,aAC3CtD,eAOAsD"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/modules/useCustomEventsModule.tsx","../src/modules/useFullscreenModule.tsx","../src/utils.ts","../src/modules/useThumbsModule.tsx","../src/useSpringCarousel.tsx","../src/useTransitionCarousel.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport { EventsObservableProps, ObservableCallbackFn, EmitObservableFn } from '../types'\n\nexport function useCustomEventsModule() {\n const eventsObserverRef = useRef(new Subject<EventsObservableProps>())\n\n function useListenToCustomEvent(fn: ObservableCallbackFn) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, MutableRefObject, useEffect } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn\n handleResize?(): void\n}\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false)\n\n useEffect(() => {\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, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nexport function useMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useEffect(() => {\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 function getIsBrowser() {\n return typeof window !== 'undefined'\n}\n","import { forwardRef, HTMLAttributes, useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport { useMount } from 'src/utils'\nimport {\n UseSpringCarouselProps,\n ReactSpringThumbItem,\n PrepareThumbsData,\n UseSpringCarouselItems,\n SlideActionType,\n} from '../types'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: UseSpringCarouselItems['items']\n withThumbs: boolean\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n springConfig: SpringConfig\n prepareThumbsData?: PrepareThumbsData\n itemsPerSlide?: UseSpringCarouselProps['itemsPerSlide']\n CustomThumbsWrapperComponent?: UseSpringCarouselProps['CustomThumbsWrapperComponent']\n getFluidWrapperScrollValue?(): number\n getSlideValue?(): number\n}\n\ntype WrapperProps = {\n children: React.ReactNode\n} & HTMLAttributes<HTMLDivElement>\n\nconst InternalWrapper = forwardRef<HTMLDivElement, WrapperProps>(\n ({ children, ...rest }, ref) => {\n return (\n <animated.div {...rest} ref={ref}>\n {children}\n </animated.div>\n )\n },\n)\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n prepareThumbsData,\n itemsPerSlide,\n getFluidWrapperScrollValue = () => 0,\n getSlideValue = () => 0,\n CustomThumbsWrapperComponent,\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) {\n internalThumbsWrapperRef.current[\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[thumbsSlideAxis])\n }\n },\n }))\n\n useMount(() => {\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 (itemsPerSlide === '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 setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }),\n },\n to: {\n [thumbsSlideAxis]: getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }),\n },\n onChange: val => {\n if (thumbsSlideAxis === 'x') {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollLeft = val.x\n } else {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollTop = val.y\n }\n },\n })\n }\n }\n }\n function handlePrepareThumbsDate() {\n function getPreparedItems(\n _items: UseSpringCarouselItems['items'],\n ): ReactSpringThumbItem[] {\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 Wrapper = CustomThumbsWrapperComponent\n ? animated(CustomThumbsWrapperComponent)\n : InternalWrapper\n\n const thumbsFragment = withThumbs ? (\n <Wrapper\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 flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsDate().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId}>\n {renderThumb}\n </div>\n )\n })}\n </Wrapper>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n","import { useRef, createContext, useCallback, useContext, useEffect } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from './modules'\nimport {\n UseSpringCarouselProps,\n SlideToItemFnProps,\n SlideActionType,\n UseSpringDafaultTypeReturnProps,\n UseSpringFluidTypeReturnProps,\n} from './types'\nimport { useMount } from './utils'\nimport { getIsBrowser } from './utils'\n\ntype ReturnHook<T> = T extends 'fluid'\n ? UseSpringFluidTypeReturnProps\n : UseSpringDafaultTypeReturnProps\n\nconst UseSpringCarouselContext = createContext<\n (UseSpringFluidTypeReturnProps | UseSpringDafaultTypeReturnProps) | undefined\n>(undefined)\n\nexport default function useSpringCarousel<T>({\n itemsPerSlide = 1,\n items,\n withLoop = false,\n draggingSlideTreshold = 140,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n prepareThumbsData,\n initialActiveItem = 0,\n initialStartingPosition = 'start',\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction = 'none',\n slideAmount,\n freeScroll = false,\n CustomThumbsWrapperComponent,\n}: UseSpringCarouselProps): ReturnHook<T> & {\n carouselFragment: JSX.Element\n thumbsFragment: JSX.Element\n} {\n function getItems() {\n if (withLoop) {\n return [...items, ...items, ...items]\n }\n return items\n }\n const slideActionType = useRef<SlideActionType>('initial')\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 currentWindowWidth = useRef(0)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideFluidEndReached = useRef(false)\n const initialWindowWidth = useRef(0)\n\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n config: springConfig,\n onChange: ({ value }) => {\n if (mainCarouselWrapperRef.current && freeScroll) {\n mainCarouselWrapperRef.current[\n carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[carouselSlideAxis])\n }\n },\n }))\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n const getMainCarouselWrapperWidth = useCallback(() => {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('mainCarouselWrapperRef is not available')\n }\n return mainCarouselWrapperRef.current.getBoundingClientRect()[\n carouselSlideAxis === 'x' ? 'width' : 'height'\n ]\n }, [carouselSlideAxis])\n const getCarouselItemWidth = useCallback(() => {\n const carouselItem = getCarouselItem()\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 }, [carouselSlideAxis, gutter])\n const getCurrentSlidedValue = useCallback(() => {\n return carouselStyles[carouselSlideAxis].get()\n }, [carouselSlideAxis, carouselStyles])\n const getIfItemsNotFillTheCarousel = useCallback(() => {\n return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth()\n }, [getCarouselItemWidth, getMainCarouselWrapperWidth, items.length])\n const getFluidWrapperScrollValue = useCallback(() => {\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 }, [carouselSlideAxis])\n const getIsFirstItem = useCallback(() => {\n return getCurrentActiveItem() === 0\n }, [])\n const getSlideValue = useCallback(() => {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const itemVal = getCarouselItemWidth()\n\n if (itemsPerSlide === '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 }, [getCarouselItemWidth, itemsPerSlide, slideAmount])\n const adjustCarouselWrapperPosition = useCallback(\n (ref: HTMLDivElement) => {\n const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top'\n function getDefaultPositionValue() {\n return getCarouselItemWidth() * items.length\n }\n function setPosition(v: number) {\n ref.style.top = '0px'\n ref.style.left = '0px'\n ref.style[positionProperty] = `-${v - startEndGutter}px`\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n\n if (itemsPerSlide !== 'fluid' && typeof itemsPerSlide === 'number') {\n function setCenterPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((itemsPerSlide as number) - 1) / 2),\n )\n }\n function setEndPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round((itemsPerSlide as number) - 1),\n )\n }\n\n if (itemsPerSlide > 1) {\n switch (initialStartingPosition) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition()\n break\n }\n case 'end': {\n setEndPosition()\n break\n }\n }\n } else {\n setStartPosition()\n }\n } else {\n setStartPosition()\n }\n },\n [\n carouselSlideAxis,\n itemsPerSlide,\n getCarouselItemWidth,\n items.length,\n startEndGutter,\n getSlideValue,\n initialStartingPosition,\n ],\n )\n const handleResize = useCallback(() => {\n if (window.innerWidth === currentWindowWidth.current || freeScroll) {\n return\n }\n currentWindowWidth.current = window.innerWidth\n\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: 0,\n })\n return\n }\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n const diff = currentWindowWidth.current - initialWindowWidth.current\n\n if (slideFluidEndReached.current) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: nextValue,\n })\n } else {\n const nextValue = getCurrentSlidedValue() + diff\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: nextValue,\n })\n }\n\n initialWindowWidth.current = window.innerWidth\n } else {\n setCarouselStyles.start({\n immediate: true,\n x: 0,\n y: 0,\n })\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n if (withLoop) {\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n }, [\n itemsPerSlide,\n withLoop,\n getIfItemsNotFillTheCarousel,\n getFluidWrapperScrollValue,\n freeScroll,\n setCarouselStyles,\n carouselSlideAxis,\n getCurrentSlidedValue,\n getSlideValue,\n adjustCarouselWrapperPosition,\n ])\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n itemsPerSlide,\n getFluidWrapperScrollValue,\n getSlideValue,\n CustomThumbsWrapperComponent,\n })\n\n function getWrapperScrollDirection() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('Missing mainCarouselWrapperRef.current')\n }\n return mainCarouselWrapperRef.current[\n carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.movement[carouselSlideAxis === 'x' ? 0 : 1]\n function resetAnimation() {\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n [carouselSlideAxis]: 0,\n })\n } else if (getIsFirstItem()) {\n slideToPrevItem()\n } else if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: getCurrentSlidedValue(),\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: -(getCurrentActiveItem() * getSlideValue()),\n })\n }\n }\n\n if (isDragging) {\n setIsDragging(true)\n emitObservable({\n eventName: 'onDrag',\n ...props,\n })\n\n if (freeScroll) {\n const direction = props.direction[carouselSlideAxis === 'x' ? 0 : 1]\n if (getWrapperScrollDirection() === 0 && direction > 0) {\n props.cancel()\n } else {\n setCarouselStyles.start({\n from: {\n [carouselSlideAxis]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxis]:\n direction > 0\n ? getWrapperScrollDirection() - Math.abs(movement)\n : getWrapperScrollDirection() + Math.abs(movement),\n },\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: getCurrentSlidedValue() + movement,\n })\n }\n\n const prevItemTreshold = movement > draggingSlideTreshold\n const nextItemTreshold = movement < -draggingSlideTreshold\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n\n if ((prevItemTreshold || nextItemTreshold) && getIfItemsNotFillTheCarousel()) {\n props.cancel()\n resetAnimation()\n return\n }\n\n if (slideFluidEndReached.current && movement < 0) {\n if (nextItemTreshold) {\n props.cancel()\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n }\n } else if (nextItemTreshold) {\n props.cancel()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem()\n }\n } else if (prevItemTreshold) {\n props.cancel()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem()\n }\n }\n }\n if (props.last && !props.pressed && !freeScroll) {\n resetAnimation()\n }\n },\n {\n enabled: !disableGestures,\n },\n )\n\n // Perform some check on first mount\n useMount(() => {\n if (itemsPerSlide !== 'fluid' && !Number.isInteger(itemsPerSlide)) {\n throw new Error(`itemsPerSlide should be an integer.`)\n }\n if (itemsPerSlide > 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 (itemsPerSlide < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\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 if (initialActiveItem < 0) {\n console.warn('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItem > items.length) {\n console.warn(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n })\n useMount(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n if (getIsBrowser()) {\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n }\n })\n useMount(() => {\n initialWindowWidth.current = window.innerWidth\n if (initialActiveItem > 0 && initialActiveItem <= items.length) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n })\n useEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n }, [handleResize, shouldResizeOnWindowResize])\n useEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxis === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\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 slideToItem({\n from,\n to = -1,\n customTo,\n immediate = false,\n onRest = () => {},\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: to,\n slideActionType: getSlideActionType(),\n })\n }\n\n function getFromValue() {\n if (typeof from === 'number') {\n return {\n from: {\n [carouselSlideAxis]: from,\n },\n }\n }\n return {}\n }\n function getToValue() {\n if (typeof customTo === 'number') {\n return {\n [carouselSlideAxis]: customTo,\n }\n }\n return {\n [carouselSlideAxis]: -(getSlideValue() * to),\n }\n }\n\n setCarouselStyles.start({\n ...getFromValue(),\n to: getToValue(),\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 currentItem: getCurrentActiveItem(),\n slideActionType: getSlideActionType(),\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() {\n setSlideActionType('prev')\n\n if (itemsPerSlide === 'fluid') {\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 })\n } else if (nextPrevValue >= 0) {\n if (withLoop) {\n slideToItem({\n from: getCurrentSlidedValue() - getCarouselItemWidth() * items.length,\n customTo:\n getCurrentSlidedValue() -\n getCarouselItemWidth() * items.length +\n getSlideValue(),\n })\n } else {\n slideToItem({\n customTo: 0,\n })\n }\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() + getSlideValue(),\n })\n }\n if (slideFluidEndReached.current) {\n slideFluidEndReached.current = false\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 })\n } else {\n slideToItem({\n to: getPrevItem(),\n })\n }\n }\n }\n function slideToNextItem() {\n setSlideActionType('next')\n\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n const willGoAfterLastFluidItem =\n Math.abs(getCurrentSlidedValue() - getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (freeScroll) {\n slideToItem({\n customTo: mainCarouselWrapperRef.current!.scrollLeft + getSlideValue(),\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 })\n } else if (slideFluidEndReached.current) {\n return\n } else if (willGoAfterLastFluidItem) {\n slideFluidEndReached.current = true\n slideToItem({\n customTo: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() - getSlideValue(),\n })\n }\n } else {\n if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n }\n\n if (getIsLastItem()) {\n slideToItem({\n from: getCurrentSlidedValue() + getSlideValue() * items.length,\n to: 0,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n })\n }\n }\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 if (itemIndex === getCurrentActiveItem()) {\n return\n }\n\n const currentItem = findItemIndex(items[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\n const contextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem,\n slideToNextItem,\n ...(typeof itemsPerSlide === 'number'\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 function getItemStyles() {\n if (typeof itemsPerSlide === 'number') {\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\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 function handleCarouselFragmentRef(ref: HTMLDivElement | null) {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n if (withLoop) {\n adjustCarouselWrapperPosition(ref)\n }\n }\n }\n function getOverflowStyles() {\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 function getWheelEvent() {\n if (freeScroll) {\n return {\n onWheel() {\n carouselStyles[carouselSlideAxis].stop()\n },\n }\n }\n return {}\n }\n const carouselFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\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 overflow: 'hidden',\n ...getOverflowStyles(),\n }}\n >\n <animated.div\n {...bindDrag()}\n data-testid=\"use-spring-carousel-animated-wrapper\"\n ref={handleCarouselFragmentRef}\n style={{\n display: 'flex',\n top: 0,\n left: 0,\n position: 'relative',\n touchAction,\n flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\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(),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </UseSpringCarouselContext.Provider>\n )\n const thumbsFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n {_thumbsFragment}\n </UseSpringCarouselContext.Provider>\n )\n\n return {\n ...(contextProps as ReturnHook<T>),\n carouselFragment,\n thumbsFragment,\n }\n}\n\nexport function useSpringCarouselContext<T>() {\n const context = useContext(UseSpringCarouselContext)\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 ReturnHook<T>\n}\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 {\n UseTransitionCarouselContextProps,\n UseTransitionCarouselProps,\n SlideActionType,\n} from './types'\n\nconst UseTransitionCarouselContext = createContext<\n UseTransitionCarouselContextProps | undefined\n>(undefined)\n\nexport function 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\nexport default function 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 CustomThumbsWrapperComponent,\n springAnimationProps = {\n initial: {\n opacity: 1,\n position: 'relative',\n },\n from: {\n opacity: 0,\n position: 'absolute',\n },\n enter: {\n opacity: 1,\n position: 'relative',\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 } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n emitObservable,\n mainCarouselWrapperRef,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n CustomThumbsWrapperComponent,\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 keys: null,\n onRest: val => {\n if (val.finished) {\n setIsAnimating(false)\n emitObservable({\n eventName: 'onSlideChange',\n currentItem: activeItem,\n slideActionType: getSlideActionType(),\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 nextItem: newActiveItem,\n slideActionType: getSlideActionType(),\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 nextItem: 0,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(0)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem + 1)\n }\n } else {\n if (!isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\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 nextItem: items.length - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(items.length - 1)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem - 1)\n }\n } else {\n if (!isFirstItem) {\n setSlideActionType('prev')\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\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"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useMount","callback","isMounted","clean","InternalWrapper","forwardRef","children","rest","ref","_jsx","animated","div","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","prepareThumbsData","itemsPerSlide","getFluidWrapperScrollValue","getSlideValue","CustomThumbsWrapperComponent","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","x","y","config","onChange","value","Math","abs","getCurrentThumbScrollValue","getThumbsTotalScrollableValue","round","Number","getBoundingClientRect","getThumbSlideValue","thumbSlideTotal","Error","Wrapper","thumbsFragment","className","onWheel","stop","style","display","flex","position","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsDate","thumbId","handleThumbsScroll","activeItem","actionType","totalScrollableValue","nextValue","start","from","[object Object]","to","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","getScrollFromValue","scrollDimensionProperty","length","getScrollToValue","val","scrollLeft","scrollTop","UseSpringCarouselContext","createContext","undefined","useSpringCarousel","withLoop","draggingSlideTreshold","default","shouldResizeOnWindowResize","enableThumbsWrapperScroll","carouselSlideAxis","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","freeScroll","slideActionType","internalItems","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","currentWindowWidth","fluidTotalWrapperScrollValue","slideFluidEndReached","initialWindowWidth","carouselStyles","setCarouselStyles","getMainCarouselWrapperWidth","useCallback","getCarouselItemWidth","carouselItem","getCurrentSlidedValue","get","getIfItemsNotFillTheCarousel","getIsFirstItem","getCurrentActiveItem","itemVal","adjustCarouselWrapperPosition","positionProperty","getDefaultPositionValue","setPosition","v","top","left","setStartPosition","window","innerWidth","immediate","diff","_thumbsFragment","getWrapperScrollDirection","bindDrag","useDrag","props","dragging","movement","resetAnimation","slideToPrevItem","setIsDragging","direction","cancel","prevItemTreshold","nextItemTreshold","width","getIsLastItem","slideToNextItem","last","pressed","enabled","setSlideActionType","type","getSlideActionType","setActiveItem","newItem","setIsAnimating","getPrevItem","currentActiveItem","getNextItem","findItemIndex","findIndex","item","slideToItem","customTo","onRest","nextItem","finished","currentItem","nextPrevValue","willGoAfterLastFluidItem","currentWidth","isInteger","console","warn","handleVisibilityChange","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsDragging","getIsNextItem","itemIndex","getIsPrevItem","_item","getIsActiveItem","index","carouselFragment","Provider","height","overflow","percentValue","getAnimatedWrapperStyles","renderItem","marginRight","marginBottom","useSpringCarouselContext","context","useContext","UseTransitionCarouselContext","useTransitionCarouselContext","useTransitionCarousel","toPrevItemSpringProps","toNextItemSpringProps","springAnimationProps","initial","opacity","enter","leave","useState","bindSwipe","mx","isFirstItem","isLastItem","itemsFragment","useTransition","getTransitionConfig","onStart","keys","transitions","styles","newActiveItem"],"mappings":"6WAIgBA,IACd,MAAMC,EAAoBC,EAAO,IAAIC,GAarC,MAAO,CACLC,uBAZF,SAAgCC,GAC9BC,GAAU,KACR,MAAMC,EAAYN,EAAkBO,QAAQD,UAAUF,GACtD,MAAO,IAAME,EAAUE,gBACtB,CAACJ,KASJK,eANuCC,IACvCV,EAAkBO,QAAQI,KAAKD,cCLnBE,GAAoBC,uBAClCA,EAAsBJ,eACtBA,EAAcK,aACdA,IAEA,MAAMC,EAAed,GAAO,GAkC5B,SAASe,EAAgBC,GACvBF,EAAaR,QAAUU,EAiBzB,OAlDAZ,GAAU,KACR,SAASa,IACHC,SAASC,oBACXJ,GAAgB,GAChBP,EAAe,CACbY,UAAW,qBACXN,cAAc,IAGhBD,GAAgBA,KAGbK,SAASC,oBACZJ,GAAgB,GAChBP,EAAe,CACbY,UAAW,qBACXN,cAAc,IAEhBD,GAAgBA,KAIpB,GAAIQ,EAAWC,UAEb,OADAD,EAAWE,GAAG,SAAUN,GACjB,KACDI,EAAWC,WACbD,EAAWG,IAAI,SAAUP,OAwB1B,CACLQ,gBAXF,SAAyBC,GACnBL,EAAWC,WACbD,EAAWM,QAASD,GAAcd,EAAuBN,UAU3DsB,eANF,WACEP,EAAWC,WAAaD,EAAWQ,QAMnCC,gBAjBF,WACE,OAAOhB,EAAaR,mBClDRyB,EAASC,GACvB,MAAMC,EAAYjC,GAAO,GAEzBI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K,MAAO8J,aAC3ChD,eAOAgD"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react/jsx-runtime"),require("react"),require("react-spring"),require("@use-gesture/react"),require("rxjs"),require("screenfull")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react","react-spring","@use-gesture/react","rxjs","screenfull"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactSpringCarousel={},e.jsxRuntime,e.React,e.reactSpring,e.reactUseGesture,e.rxjs,e.screenfull)}(this,(function(e,t,n,r,i,o,s){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=u(s);function c(){const e=n.useRef(new o.Subject);return{useListenToCustomEvent:function(t){n.useEffect((()=>{const n=e.current.subscribe(t);return()=>n.unsubscribe()}),[t])},emitObservable:t=>{e.current.next(t)}}}function a({mainCarouselWrapperRef:e,emitObservable:t,handleResize:r}){const i=n.useRef(!1);function o(e){i.current=e}return n.useEffect((()=>{function e(){document.fullscreenElement&&(o(!0),t({eventName:"onFullscreenChange",isFullscreen:!0}),r&&r()),document.fullscreenElement||(o(!1),t({eventName:"onFullscreenChange",isFullscreen:!1}),r&&r())}if(l.default.isEnabled)return l.default.on("change",e),()=>{l.default.isEnabled&&l.default.off("change",e)}})),{enterFullscreen:function(t){l.default.isEnabled&&l.default.request(t||e.current)},exitFullscreen:function(){l.default.isEnabled&&l.default.exit()},getIsFullscreen:function(){return i.current}}}function f(e){const t=n.useRef(!1);n.useEffect((()=>{if(!t.current){const n=e();return t.current=!0,()=>{n&&n()}}}),[])}function d({items:e,withThumbs:i,thumbsSlideAxis:o="x",springConfig:s,thumbsWrapperRef:u,prepareThumbsData:l}){const c=n.useRef(null),[a,d]=r.useSpring((()=>({[o]:0,config:s})));f((()=>{if(i){if(e.some((e=>!e.renderThumb)))throw new Error("The renderThumb property is missing in one or more items. You need to add the renderThumb property to every item of the carousel when the prop withThumbs={true} or eventually set withThumbs={false}.")}}));return{thumbsFragment:i?t.jsx(r.animated.div,Object.assign({ref:c},"x"===o?{scrollLeft:a.x}:{scrollTop:a.y},{style:{display:"flex",flex:1,position:"relative",flexDirection:"x"===o?"row":"column",..."x"===o?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"}}},{children:function(){function t(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return l?l(t(e)):t(e)}().map((({id:e,renderThumb:n})=>{const r=`thumb-${e}`;return t.jsx("div",Object.assign({id:r},{children:n}),r)}))}),void 0):null,handleThumbsScroll:function(t){u&&u.current&&(c.current=u.current);const n=c.current.querySelector(`#thumb-${e[t].id}`);if(n){const r=c.current,i="x"===o?"offsetWidth":"offsetHeight",s="x"===o?"scrollLeft":"scrollTop",u=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:n,offsetDimension:i,offsetDirection:"x"===o?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:r,offsetDimension:i});d.start({from:{[o]:function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:r,scrollDirection:s})},to:{[o]:function({thumbWrapper:n,thumbOffsetPosition:r,thumbScrollDimension:i,offsetDimension:s}){const u="x"===o?"scrollWidth":"scrollHeight";return t===e.length-1||r-i>n[u]-n[s]?n[u]-n[s]:0===t?0:r-i}({thumbWrapper:r,thumbOffsetPosition:u,thumbScrollDimension:l,offsetDimension:i})},onChange:e=>{"x"===o?c.current.scrollLeft=e.x:c.current.scrollTop=e.y}})}}}}const m=n.createContext(void 0);const h=n.createContext(void 0);e.useSpringCarousel=function({items:e,withLoop:o=!1,draggingSlideTreshold:s=140,springConfig:u=r.config.default,shouldResizeOnWindowResize:l=!0,withThumbs:h=!1,enableThumbsWrapperScroll:g=!0,carouselSlideAxis:p="x",thumbsSlideAxis:x="x",thumbsWrapperRef:b,prepareThumbsData:v,itemsPerSlide:w=1,initialActiveItem:y=0,initialStartingPosition:T="start",disableGestures:S=!1,gutter:C=0,startEndGutter:I=0,touchAction:R="none",slideAmount:j}){const E=n.useRef("next"),A=o?[...e,...e,...e]:e,N=n.useRef(y),F=n.useRef(null),D=n.useRef(null),O=n.useRef(!1),W=n.useRef(!1),P=n.useRef(!1),L=n.useRef(0),$=n.useRef(0),q=n.useRef(!1),z=n.useRef(0),k=n.useRef(0),B=n.useCallback((()=>Math.round(Number(D.current?.["x"===p?"scrollWidth":"scrollHeight"])-D.current.getBoundingClientRect()["x"===p?"width":"height"])),[p]),[M,G]=r.useSpring((()=>({y:0,x:0,config:u,onRest:({value:e})=>{z.current=e[p],k.current=e[p]}}))),H=n.useCallback((()=>{if(!D.current)return 0;const e=D.current?.querySelector(".use-spring-carousel-item");if(!e)throw Error("No carousel items available!");const t=e.getBoundingClientRect()["x"===p?"width":"height"]+C;if("fluid"===w&&"number"==typeof j){if(j<t)throw new Error("slideAmount must be greater than the width of a single item.");return j}return t}),[p,C,w,j]),Y=n.useCallback((t=>{if("fluid"!==w&&"number"==typeof w){const o="x"===p?"left":"top";function n(){return H()*e.length}function r(e){t.style.top="0px",t.style.left="0px",t.style[o]=`-${e-I}px`}function i(){r(n())}if(w>1)switch(T){default:case"start":i();break;case"center":r(n()-H()*Math.round((w-1)/2));break;case"end":r(n()-H()*Math.round(w-1))}else i()}}),[I,p,H,T,e.length,w]),_=n.useCallback((()=>{if(window.innerWidth!==L.current){if(L.current=window.innerWidth,"fluid"===w)if($.current=B(),q.current)G.start({immediate:!0,[p]:-$.current});else{const e=document.querySelector(".use-spring-carousel-item:last-of-type");console.log({lastItem:e.offsetLeft})}else G.start({immediate:!0,x:0,y:0}),G.start({immediate:!0,[p]:-H()*ie()});o&&Y(D.current)}}),[Y,p,H,G,o,w,B]),{useListenToCustomEvent:U,emitObservable:X}=c(),{enterFullscreen:J,exitFullscreen:K,getIsFullscreen:Q}=a({mainCarouselWrapperRef:F,emitObservable:X,handleResize:_}),{thumbsFragment:V,handleThumbsScroll:Z}=d({withThumbs:h,items:e,thumbsSlideAxis:x,springConfig:u,thumbsWrapperRef:b,prepareThumbsData:v}),ee=i.useDrag((t=>{const n=t.dragging,r=t.movement["x"===p?0:1];function i(){"fluid"===w?de()?he():q.current?G.start({[p]:-$.current}):G.start({[p]:k.current}):G.start({[p]:-ie()*H()})}if(t.first&&(z.current=M[p].get()),n){se(!0),X({eventName:"onDrag",...t}),G.start({[p]:z.current+r});const n=r>s,u=r<-s;F.current.getBoundingClientRect().width>=e.length*H()&&(q.current=!0),q.current&&r<0?u&&(t.cancel(),G.start({[p]:-$.current})):u?(t.cancel(),!o&&me()?i():ge()):n&&(t.cancel(),!o&&de()?i():he())}t.last&&!t.pressed&&i()}),{enabled:!S});function te(e){E.current=e}function ne(){return E.current}function re(e){N.current=e}function ie(){return N.current}function oe(e){W.current=e}function se(e){O.current=e}function ue(){const t=ie();return 0===t?e.length-1:t-1}function le(){const t=ie();return t===e.length-1?0:t+1}function ce(t){return e.findIndex((e=>e.id===t))}function ae({from:e,to:t,customTo:n,immediate:r=!1,onRest:i=(()=>{})}){r||(re(t),oe(!0),X({eventName:"onSlideStartChange",nextItem:t,slideActionType:ne()})),G.start({...e?{from:{[p]:e}}:{},to:n?{[p]:n}:{[p]:-H()*t},immediate:r,onRest:e=>{e.finished&&(se(!1),oe(!1),i(),r||X({eventName:"onSlideChange",currentItem:ie(),slideActionType:ne()}))}}),g&&h&&!r&&Z(t)}function fe(e){if("none"===e.style.transform)return 0;const t=e.style.transform.split(/\w+\(|\);?/);return Number(t[1].split(/,\s?/g)["x"===p?0:1].replace("px",""))}function de(){return 0===ie()}function me(){return ie()===e.length-1}function he(){if("fluid"!==w||o){if(!o&&0===ie()||P.current)return;te("prev"),de()?ae({from:-(Math.abs(fe(D.current))+H()*e.length),to:e.length-1}):ae({to:ue()})}else{const e=fe(D.current)+H()+100;if(de())return void ae({to:0});if(e>=0)ae({to:0}),k.current=0;else{const e=k.current+H();k.current=e,ae({to:ue(),customTo:e})}q.current&&(q.current=!1)}}function ge(){if("fluid"!==w||o){if(!o&&ie()===A.length-1||P.current)return;te("next"),me()?ae({from:fe(D.current)+H()*e.length,to:0}):ae({to:le()})}else{const t=Math.abs(le()*H())+100>=$.current;if(F.current.getBoundingClientRect().width>=e.length*H()&&(q.current=!0),q.current)return;if(t){const e=-$.current;q.current=!0,k.current=e,ae({to:le(),customTo:e})}else{const e=k.current-H();k.current=e,ae({to:le(),customTo:e})}}}f((()=>{if("fluid"!==w&&!Number.isInteger(w))throw new Error("itemsPerSlide should be an integer.");if(w>e.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(w<1)throw new Error("The itemsPerSlide prop can't be less than 1.");l||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."),y<0&&console.warn("The initialActiveItem cannot be less than 0."),y>e.length&&console.warn("The initialActiveItem cannot be greater than the total length of the items you provide.")})),f((()=>{function e(){document.hidden?P.current=!0:P.current=!1}if($.current=B(),"undefined"!=typeof window)return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),f((()=>{y>0&&y<=e.length&&(ae({to:y,immediate:!0}),re(y))})),n.useEffect((()=>{if(l)return window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}}),[_,l]),n.useEffect((()=>{D.current&&("x"===p&&(D.current.style.top="0px"),"y"===p&&(D.current.style.left="0px"))}),[p]);const pe={useListenToCustomEvent:U,getIsFullscreen:Q,enterFullscreen:J,exitFullscreen:K,getIsAnimating:function(){return W.current},getIsDragging:function(){return O.current},getIsNextItem:function(t){const n=ce(t),r=ie();return o&&r===e.length-1?0===n:n===r+1},getIsPrevItem:function(t){const n=ce(t),r=ie();return o&&0===r?n===e.length-1:n===r-1},slideToPrevItem:he,slideToNextItem:ge,slideToItem:function(t){let n=0;if(n="string"==typeof t?e.findIndex((e=>e.id===t)):t,n>=e.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(n===ie())return;const r=ce(e[ie()].id);te(ce(e[n].id)>r?"next":"prev"),ae({to:n})},getIsActiveItem:e=>ce(e)===ie(),getCurrentActiveItem:()=>({id:e[ie()].id,index:ie()})};return{carouselFragment:t.jsx(m.Provider,Object.assign({value:pe},{children:t.jsx("div",Object.assign({ref:F,"data-testid":"use-spring-carousel-wrapper",style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:t.jsx(r.animated.div,Object.assign({},ee(),{"data-testid":"use-spring-carousel-animated-wrapper",style:{display:"flex",top:0,left:0,position:"relative",touchAction:R,flexDirection:"x"===p?"row":"column",...function(){const e=`calc(100% - ${2*I}px)`;return{width:"x"===p?e:"100%",height:"y"===p?e:"100%"}}(),...M},ref:e=>{e&&(D.current=e,o&&Y(e))}},{children:A.map((({id:e,renderItem:n},r)=>t.jsx("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",..."number"==typeof w?{..."x"===p?{marginRight:`${C}px`}:{marginBottom:`${C}px`},flex:`1 0 calc(100% / ${w} - ${C*(w-1)/w}px)`}:{..."x"===p?{marginRight:`${C}px`}:{marginBottom:`${C}px`}}}},{children:n}),`${e}-${r}`)))}),void 0)}),void 0)}),void 0),thumbsFragment:t.jsx(m.Provider,Object.assign({value:pe},{children:V}),void 0),...pe}},e.useSpringCarouselContext=function(){const e=n.useContext(m);if(!e)throw new Error("useSpringCarouselContext isn't being used within the useSringCarousel context; \n use the context only inside a component that is rendered within the Carousel.");return e},e.useTransitionCarousel=function({items:e,withLoop:o=!1,withThumbs:s=!1,springConfig:u=r.config.default,thumbsSlideAxis:l="x",enableThumbsWrapperScroll:f=!0,draggingSlideTreshold:m=50,prepareThumbsData:g,toPrevItemSpringProps:p,toNextItemSpringProps:x,disableGestures:b=!1,springAnimationProps:v={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"relative"},leave:{opacity:0,position:"absolute"}}}){const w=n.useRef("next"),y=n.useRef(null),T=n.useRef(!1),[S,C]=n.useState(0),{emitObservable:I,useListenToCustomEvent:R}=c(),{enterFullscreen:j,exitFullscreen:E,getIsFullscreen:A}=a({emitObservable:I,mainCarouselWrapperRef:y}),{thumbsFragment:N,handleThumbsScroll:F}=d({items:e,withThumbs:s,thumbsSlideAxis:l,springConfig:u,prepareThumbsData:g}),D=i.useDrag((({last:t,movement:[n]})=>{if(!W()&&t){const t=n>m,r=n<-m,i=0===S,s=S===e.length-1;if(r){if(!o&&s)return;q(),I({eventName:"onLeftSwipe"})}else if(t){if(!o&&i)return;z(),I({eventName:"onRightSwipe"})}}}),{enabled:!b}),O=r.useTransition(S,{config:u,...function(){const e=$();return"prev"===e&&p?{initial:{...v.initial},from:{...p.from},enter:{...p.enter},leave:{...p.leave}}:"next"===e&&x?{initial:{...v.initial},from:{...x.from},enter:{...x.enter},leave:{...x.leave}}:{initial:{...v.initial},from:{...v.from},enter:{...v.enter},leave:{...v.leave}}}(),onStart:()=>P(!0),keys:null,onRest:e=>{e.finished&&(P(!1),I({eventName:"onSlideChange",currentItem:S,slideActionType:$()}))}})(((n,i)=>t.jsx(r.animated.div,Object.assign({style:{...n,flex:"1 0 100%",width:"100%",height:"100%"}},{children:e[i].renderItem}),void 0)));function W(){return T.current}function P(e){T.current=e}function L(e){w.current=e}function $(){return w.current}function q(){const t=S===e.length-1;o?(L("next"),t?(I({eventName:"onSlideStartChange",nextItem:0,slideActionType:$()}),C(0)):(I({eventName:"onSlideStartChange",nextItem:S+1,slideActionType:$()}),C(S+1))):t||(I({eventName:"onSlideStartChange",nextItem:S+1,slideActionType:$()}),L("next"),C(S+1))}function z(){const t=0===S;o?(L("prev"),t?(I({eventName:"onSlideStartChange",nextItem:e.length-1,slideActionType:$()}),C(e.length-1)):(I({eventName:"onSlideStartChange",nextItem:S-1,slideActionType:$()}),C(S-1))):t||(L("prev"),I({eventName:"onSlideStartChange",nextItem:S-1,slideActionType:$()}),C(S-1))}function k(t){return e.findIndex((e=>e.id===t))}const B={activeItem:S,slideToItem:function(t){let n=0;if(n="string"==typeof t?e.findIndex((e=>e.id===t)):t,n>=e.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(n===S)return;const r=k(e[S].id),i=k(e[n].id);I({eventName:"onSlideStartChange",nextItem:i,slideActionType:$()}),L(i>r?"next":"prev"),C(n),f&&s&&F(n)},slideToNextItem:q,slideToPrevItem:z,enterFullscreen:j,exitFullscreen:E,useListenToCustomEvent:R,getIsNextItem:function(t){const n=k(t);return o&&S===e.length-1?0===n:n===S+1},getIsPrevItem:function(t){const n=k(t);return o&&0===S?n===e.length-1:n===S-1},getIsAnimating:W,getIsFullscreen:A,getIsActiveItem:e=>k(e)===S,getCurrentActiveItem:()=>({id:e[S].id,index:S})};return{carouselFragment:t.jsx(h.Provider,Object.assign({value:B},{children:t.jsx("div",Object.assign({ref:y},D(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:O}),void 0)}),void 0),thumbsFragment:t.jsx(h.Provider,Object.assign({value:B},{children:N}),void 0),...B}},e.useTransitionCarouselContext=function(){const e=n.useContext(h);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},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react/jsx-runtime"),require("react"),require("react-spring"),require("@use-gesture/react"),require("rxjs"),require("screenfull")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react","react-spring","@use-gesture/react","rxjs","screenfull"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactSpringCarousel={},e.jsxRuntime,e.React,e.reactSpring,e.reactUseGesture,e.rxjs,e.screenfull)}(this,(function(e,t,n,r,i,o,s){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=u(s);function c(){const e=n.useRef(new o.Subject);return{useListenToCustomEvent:function(t){n.useEffect((()=>{const n=e.current.subscribe(t);return()=>n.unsubscribe()}),[t])},emitObservable:t=>{e.current.next(t)}}}function a({mainCarouselWrapperRef:e,emitObservable:t,handleResize:r}){const i=n.useRef(!1);function o(e){i.current=e}return n.useEffect((()=>{function e(){document.fullscreenElement&&(o(!0),t({eventName:"onFullscreenChange",isFullscreen:!0}),r&&r()),document.fullscreenElement||(o(!1),t({eventName:"onFullscreenChange",isFullscreen:!1}),r&&r())}if(l.default.isEnabled)return l.default.on("change",e),()=>{l.default.isEnabled&&l.default.off("change",e)}})),{enterFullscreen:function(t){l.default.isEnabled&&l.default.request(t||e.current)},exitFullscreen:function(){l.default.isEnabled&&l.default.exit()},getIsFullscreen:function(){return i.current}}}function f(e){const t=n.useRef(!1);n.useEffect((()=>{if(!t.current){const n=e();return t.current=!0,()=>{n&&n()}}}),[])}const d=n.forwardRef((({children:e,...n},i)=>t.jsx(r.animated.div,Object.assign({},n,{ref:i},{children:e}),void 0)));function m({items:e,withThumbs:i,thumbsSlideAxis:o="x",springConfig:s,prepareThumbsData:u,itemsPerSlide:l,getFluidWrapperScrollValue:c=(()=>0),getSlideValue:a=(()=>0),CustomThumbsWrapperComponent:m}){const h=n.useRef(null),[g,p]=r.useSpring((()=>({x:0,y:0,config:s,onChange:({value:e})=>{h.current&&(h.current["x"===o?"scrollLeft":"scrollTop"]=Math.abs(e[o]))}})));function b(){return h.current["x"===o?"scrollLeft":"scrollTop"]}function x(){return Math.round(Number(h.current?.["x"===o?"scrollWidth":"scrollHeight"])-h.current.getBoundingClientRect()["x"===o?"width":"height"])}function v(){const e=Math.round(c()/a());return x()/e}f((()=>{if(i&&!h.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.")}));const w=m?r.animated(m):d;return{thumbsFragment:i?t.jsx(w,Object.assign({ref:h,className:"use-spring-carousel-thumbs-wrapper",onWheel:()=>{g[o].stop()},style:{display:"flex",flex:1,position:"relative",flexDirection:"x"===o?"row":"column",..."x"===o?{overflowX:"auto"}:{overflowY:"auto",maxHeight:"100%"}}},{children:function(){function t(e){return e.map((e=>({id:e.id,renderThumb:e.renderThumb})))}return u?u(t(e)):t(e)}().map((({id:e,renderThumb:n})=>{const r=`thumb-${e}`;return t.jsx("div",Object.assign({id:r},{children:n}),r)}))}),void 0):null,handleThumbsScroll:function(t,n){if("fluid"===l){const e=x();if("next"===n){const t=b()+v();p.start({from:{[o]:b()},to:{[o]:t>e?e:t}})}if("prev"===n){const e=b()-v();p.start({from:{[o]:b()},to:{[o]:e<0?0:e}})}}else{const n=h.current.querySelector(`#thumb-${e[t].id}`);if(n){const r=h.current,i="x"===o?"offsetWidth":"offsetHeight",s="x"===o?"scrollLeft":"scrollTop",u=function({thumbNode:e,offsetDirection:t,offsetDimension:n}){return e[t]+e[n]/2}({thumbNode:n,offsetDimension:i,offsetDirection:"x"===o?"offsetLeft":"offsetTop"}),l=function({thumbWrapper:e,offsetDimension:t}){return e[t]/2}({thumbWrapper:r,offsetDimension:i});p.start({from:{[o]:function({thumbWrapper:e,scrollDirection:t}){return e[t]}({thumbWrapper:r,scrollDirection:s})},to:{[o]:function({thumbWrapper:n,thumbOffsetPosition:r,thumbScrollDimension:i,offsetDimension:s}){const u="x"===o?"scrollWidth":"scrollHeight";return t===e.length-1||r-i>n[u]-n[s]?n[u]-n[s]:0===t?0:r-i}({thumbWrapper:r,thumbOffsetPosition:u,thumbScrollDimension:l,offsetDimension:i})},onChange:e=>{"x"===o?h.current.scrollLeft=e.x:h.current.scrollTop=e.y}})}}}}}const h=n.createContext(void 0);const g=n.createContext(void 0);e.useSpringCarousel=function({itemsPerSlide:e=1,items:o,withLoop:s=!1,draggingSlideTreshold:u=140,springConfig:l=r.config.default,shouldResizeOnWindowResize:d=!0,withThumbs:g=!1,enableThumbsWrapperScroll:p=!0,carouselSlideAxis:b="x",thumbsSlideAxis:x="x",prepareThumbsData:v,initialActiveItem:w=0,initialStartingPosition:T="start",disableGestures:C=!1,gutter:y=0,startEndGutter:S=0,touchAction:I="none",slideAmount:R,freeScroll:j=!1,CustomThumbsWrapperComponent:E}){const W=n.useRef("initial"),A=s?[...o,...o,...o]:o,F=n.useRef(w),N=n.useRef(null),D=n.useRef(null),L=n.useRef(!1),O=n.useRef(!1),P=n.useRef(!1),M=n.useRef(0),k=n.useRef(0),$=n.useRef(!1),q=n.useRef(0),[z,B]=r.useSpring((()=>({y:0,x:0,config:l,onChange:({value:e})=>{N.current&&j&&(N.current["x"===b?"scrollLeft":"scrollTop"]=Math.abs(e[b]))}}))),H=n.useCallback((()=>{if(!N.current)throw new Error("mainCarouselWrapperRef is not available");return N.current.getBoundingClientRect()["x"===b?"width":"height"]}),[b]),G=n.useCallback((()=>{const e=D.current?.querySelector(".use-spring-carousel-item");if(!e)throw Error("No carousel items available!");return e.getBoundingClientRect()["x"===b?"width":"height"]+y}),[b,y]),V=n.useCallback((()=>z[b].get()),[b,z]),Y=n.useCallback((()=>G()*o.length<H()),[G,H,o.length]),X=n.useCallback((()=>Math.round(Number(D.current?.["x"===b?"scrollWidth":"scrollHeight"])-D.current.getBoundingClientRect()["x"===b?"width":"height"])),[b]),_=n.useCallback((()=>0===ae()),[]),U=n.useCallback((()=>{if(!D.current)return 0;const t=G();if("fluid"===e&&"number"==typeof R){if(R<t)throw new Error("slideAmount must be greater than the width of a single item.");return R}return t}),[G,e,R]),J=n.useCallback((t=>{const n="x"===b?"left":"top";function r(){return G()*o.length}function i(e){t.style.top="0px",t.style.left="0px",t.style[n]=`-${e-S}px`}function s(){i(r())}if("fluid"!==e&&"number"==typeof e){if(e>1)switch(T){default:case"start":s();break;case"center":i(r()-U()*Math.round((e-1)/2));break;case"end":i(r()-U()*Math.round(e-1))}else s()}else s()}),[b,e,G,o.length,S,U,T]),K=n.useCallback((()=>{if(window.innerWidth!==M.current&&!j){if(M.current=window.innerWidth,"fluid"===e){if(Y())return void B.start({immediate:!0,[b]:0});k.current=X();const e=M.current-q.current;if($.current){const e=-k.current;B.start({immediate:!0,[b]:e})}else{const t=V()+e;B.start({immediate:!0,[b]:t})}q.current=window.innerWidth}else B.start({immediate:!0,x:0,y:0}),B.start({immediate:!0,[b]:-U()*ae()});s&&J(D.current)}}),[e,s,Y,X,j,B,b,V,U,J]),{useListenToCustomEvent:Q,emitObservable:Z}=c(),{enterFullscreen:ee,exitFullscreen:te,getIsFullscreen:ne}=a({mainCarouselWrapperRef:N,emitObservable:Z,handleResize:K}),{thumbsFragment:re,handleThumbsScroll:ie}=m({withThumbs:g,items:o,thumbsSlideAxis:x,springConfig:l,prepareThumbsData:v,itemsPerSlide:e,getFluidWrapperScrollValue:X,getSlideValue:U,CustomThumbsWrapperComponent:E});function oe(){if(!N.current)throw new Error("Missing mainCarouselWrapperRef.current");return N.current["x"===b?"scrollLeft":"scrollTop"]}const se=i.useDrag((t=>{const n=t.dragging,r=t.movement["x"===b?0:1];function i(){"fluid"===e?Y()?B.start({[b]:0}):_()?xe():$.current?B.start({[b]:-k.current}):B.start({[b]:V()}):B.start({[b]:-ae()*U()})}if(n){if(de(!0),Z({eventName:"onDrag",...t}),j){const e=t.direction["x"===b?0:1];0===oe()&&e>0?t.cancel():B.start({from:{[b]:oe()},to:{[b]:e>0?oe()-Math.abs(r):oe()+Math.abs(r)}})}else B.start({[b]:V()+r});const e=r>u,n=r<-u;if(N.current.getBoundingClientRect().width>=o.length*U()&&($.current=!0),(e||n)&&Y())return t.cancel(),void i();$.current&&r<0?n&&(t.cancel(),B.start({[b]:-k.current})):n?(t.cancel(),!s&&be()?i():ve()):e&&(t.cancel(),!s&&_()?i():xe())}!t.last||t.pressed||j||i()}),{enabled:!C});function ue(e){W.current=e}function le(){return W.current}function ce(e){F.current=e}function ae(){return F.current}function fe(e){O.current=e}function de(e){L.current=e}function me(){const e=ae();return 0===e?o.length-1:e-1}function he(){const e=ae();return e===o.length-1?0:e+1}function ge(e){return o.findIndex((t=>t.id===e))}function pe({from:e,to:t=-1,customTo:n,immediate:r=!1,onRest:i=(()=>{})}){r||(ce(t),fe(!0),Z({eventName:"onSlideStartChange",nextItem:t,slideActionType:le()})),B.start({..."number"==typeof e?{from:{[b]:e}}:{},to:"number"==typeof n?{[b]:n}:{[b]:-U()*t},immediate:r,onRest:e=>{e.finished&&(de(!1),fe(!1),i(),r||Z({eventName:"onSlideChange",currentItem:ae(),slideActionType:le()}))}}),p&&g&&!r&&ie(t,le())}function be(){return ae()===o.length-1}function xe(){if(ue("prev"),"fluid"===e){if(Y())return;const e=V()+U()+200;if(j){const e=N.current.scrollLeft-U();pe({customTo:e<0?0:e,from:N.current.scrollLeft})}else pe(e>=0?s?{from:V()-G()*o.length,customTo:V()-G()*o.length+U()}:{customTo:0}:{customTo:V()+U()});$.current&&($.current=!1)}else{if(!s&&0===ae()||P.current)return;_()?pe({from:V()-U()*o.length,to:o.length-1}):pe({to:me()})}}function ve(){if(ue("next"),"fluid"===e){if(Y())return;const e=Math.abs(V()-U())+100>=k.current;if(j)pe({customTo:N.current.scrollLeft+U(),from:N.current.scrollLeft});else if(s&&Math.abs(V()-U())>=o.length*G()){const e=G()*o.length;pe({from:V()+e,customTo:V()+e-U()})}else{if($.current)return;e?($.current=!0,pe({customTo:-k.current})):pe({customTo:V()-U()})}}else{if(!s&&ae()===A.length-1||P.current)return;be()?pe({from:V()+U()*o.length,to:0}):pe({to:he()})}}f((()=>{if("fluid"!==e&&!Number.isInteger(e))throw new Error("itemsPerSlide should be an integer.");if(e>o.length)throw new Error("The itemsPerSlide prop can't be greater than the total length of the items you provide.");if(e<1)throw new Error("The itemsPerSlide prop can't be less than 1.");d||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."),w<0&&console.warn("The initialActiveItem cannot be less than 0."),w>o.length&&console.warn("The initialActiveItem cannot be greater than the total length of the items you provide.")})),f((()=>{function e(){document.hidden?P.current=!0:P.current=!1}if(k.current=X(),"undefined"!=typeof window)return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}})),f((()=>{q.current=window.innerWidth,w>0&&w<=o.length&&(pe({to:w,immediate:!0}),ce(w))})),n.useEffect((()=>{if(d)return window.addEventListener("resize",K),()=>{window.removeEventListener("resize",K)}}),[K,d]),n.useEffect((()=>{D.current&&("x"===b&&(D.current.style.top="0px"),"y"===b&&(D.current.style.left="0px"))}),[b]);const we={useListenToCustomEvent:Q,getIsFullscreen:ne,enterFullscreen:ee,exitFullscreen:te,getIsAnimating:function(){return O.current},getIsDragging:function(){return L.current},getIsNextItem:function(e){const t=ge(e),n=ae();return s&&n===o.length-1?0===t:t===n+1},getIsPrevItem:function(e){const t=ge(e),n=ae();return s&&0===n?t===o.length-1:t===n-1},slideToPrevItem:xe,slideToNextItem:ve,..."number"==typeof e?{slideToItem:function(e){let t=0;if(t="string"==typeof e?o.findIndex((t=>t.id===e)):e,t>=o.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===ae())return;const n=ge(o[ae()].id);ue(ge(o[t].id)>n?"next":"prev"),pe({to:t})},getIsActiveItem:e=>ge(e)===ae(),getCurrentActiveItem:()=>({id:o[ae()].id,index:ae()})}:{}},Te=t.jsx(h.Provider,Object.assign({value:we},{children:t.jsx("div",Object.assign({ref:N,"data-testid":"use-spring-carousel-wrapper"},j?{onWheel(){z[b].stop()}}:{},{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden",...j?"x"===b?{overflowX:"auto"}:{overflowY:"auto"}:{}}},{children:t.jsx(r.animated.div,Object.assign({},se(),{"data-testid":"use-spring-carousel-animated-wrapper",ref:function(e){e&&(D.current=e,s&&J(e))},style:{display:"flex",top:0,left:0,position:"relative",touchAction:I,flexDirection:"x"===b?"row":"column",...function(){const e=`calc(100% - ${2*S}px)`;return{width:"x"===b?e:"100%",height:"y"===b?e:"100%"}}(),...j?{}:z}},{children:A.map((({id:n,renderItem:r},i)=>t.jsx("div",Object.assign({className:"use-spring-carousel-item","data-testid":"use-spring-carousel-item-wrapper",style:{display:"flex",position:"relative",..."number"==typeof e?{..."x"===b?{marginRight:`${y}px`}:{marginBottom:`${y}px`},flex:`1 0 calc(100% / ${e} - ${y*(e-1)/e}px)`}:{..."x"===b?{marginRight:`${y}px`}:{marginBottom:`${y}px`}}}},{children:r}),`${n}-${i}`)))}),void 0)}),void 0)}),void 0),Ce=t.jsx(h.Provider,Object.assign({value:we},{children:re}),void 0);return{...we,carouselFragment:Te,thumbsFragment:Ce}},e.useSpringCarouselContext=function(){const e=n.useContext(h);if(!e)throw new Error("useSpringCarouselContext must be used only inside a component that is rendered inside the Carousel.");return e},e.useTransitionCarousel=function({items:e,withLoop:o=!1,withThumbs:s=!1,springConfig:u=r.config.default,thumbsSlideAxis:l="x",enableThumbsWrapperScroll:f=!0,draggingSlideTreshold:d=50,prepareThumbsData:h,toPrevItemSpringProps:p,toNextItemSpringProps:b,disableGestures:x=!1,CustomThumbsWrapperComponent:v,springAnimationProps:w={initial:{opacity:1,position:"relative"},from:{opacity:0,position:"absolute"},enter:{opacity:1,position:"relative"},leave:{opacity:0,position:"absolute"}}}){const T=n.useRef("next"),C=n.useRef(null),y=n.useRef(!1),[S,I]=n.useState(0),{emitObservable:R,useListenToCustomEvent:j}=c(),{enterFullscreen:E,exitFullscreen:W,getIsFullscreen:A}=a({emitObservable:R,mainCarouselWrapperRef:C}),{thumbsFragment:F,handleThumbsScroll:N}=m({items:e,withThumbs:s,thumbsSlideAxis:l,springConfig:u,prepareThumbsData:h,CustomThumbsWrapperComponent:v}),D=i.useDrag((({last:t,movement:[n]})=>{if(!O()&&t){const t=n>d,r=n<-d,i=0===S,s=S===e.length-1;if(r){if(!o&&s)return;$(),R({eventName:"onLeftSwipe"})}else if(t){if(!o&&i)return;q(),R({eventName:"onRightSwipe"})}}}),{enabled:!x}),L=r.useTransition(S,{config:u,...function(){const e=k();return"prev"===e&&p?{initial:{...w.initial},from:{...p.from},enter:{...p.enter},leave:{...p.leave}}:"next"===e&&b?{initial:{...w.initial},from:{...b.from},enter:{...b.enter},leave:{...b.leave}}:{initial:{...w.initial},from:{...w.from},enter:{...w.enter},leave:{...w.leave}}}(),onStart:()=>P(!0),keys:null,onRest:e=>{e.finished&&(P(!1),R({eventName:"onSlideChange",currentItem:S,slideActionType:k()}))}})(((n,i)=>t.jsx(r.animated.div,Object.assign({style:{...n,flex:"1 0 100%",width:"100%",height:"100%"}},{children:e[i].renderItem}),void 0)));function O(){return y.current}function P(e){y.current=e}function M(e){T.current=e}function k(){return T.current}function $(){const t=S===e.length-1;o?(M("next"),t?(R({eventName:"onSlideStartChange",nextItem:0,slideActionType:k()}),I(0)):(R({eventName:"onSlideStartChange",nextItem:S+1,slideActionType:k()}),I(S+1))):t||(R({eventName:"onSlideStartChange",nextItem:S+1,slideActionType:k()}),M("next"),I(S+1))}function q(){const t=0===S;o?(M("prev"),t?(R({eventName:"onSlideStartChange",nextItem:e.length-1,slideActionType:k()}),I(e.length-1)):(R({eventName:"onSlideStartChange",nextItem:S-1,slideActionType:k()}),I(S-1))):t||(M("prev"),R({eventName:"onSlideStartChange",nextItem:S-1,slideActionType:k()}),I(S-1))}function z(t){return e.findIndex((e=>e.id===t))}const B={activeItem:S,slideToItem:function(t){let n=0;if(n="string"==typeof t?e.findIndex((e=>e.id===t)):t,n>=e.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(n===S)return;const r=z(e[S].id),i=z(e[n].id);R({eventName:"onSlideStartChange",nextItem:i,slideActionType:k()}),M(i>r?"next":"prev"),I(n),f&&s&&N(n)},slideToNextItem:$,slideToPrevItem:q,enterFullscreen:E,exitFullscreen:W,useListenToCustomEvent:j,getIsNextItem:function(t){const n=z(t);return o&&S===e.length-1?0===n:n===S+1},getIsPrevItem:function(t){const n=z(t);return o&&0===S?n===e.length-1:n===S-1},getIsAnimating:O,getIsFullscreen:A,getIsActiveItem:e=>z(e)===S,getCurrentActiveItem:()=>({id:e[S].id,index:S})};return{carouselFragment:t.jsx(g.Provider,Object.assign({value:B},{children:t.jsx("div",Object.assign({ref:C},D(),{style:{display:"flex",position:"relative",width:"100%",height:"100%",overflow:"hidden"}},{children:L}),void 0)}),void 0),thumbsFragment:t.jsx(g.Provider,Object.assign({value:B},{children:F}),void 0),...B}},e.useTransitionCarouselContext=function(){const e=n.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},Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/modules/useCustomEventsModule.tsx","../src/modules/useFullscreenModule.tsx","../src/utils.ts","../src/modules/useThumbsModule.tsx","../src/useSpringCarousel.tsx","../src/useTransitionCarousel.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport { EventsObservableProps, ObservableCallbackFn, EmitObservableFn } from '../types'\n\nexport function useCustomEventsModule() {\n const eventsObserverRef = useRef(new Subject<EventsObservableProps>())\n\n function useListenToCustomEvent(fn: ObservableCallbackFn) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, MutableRefObject, useEffect } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn\n handleResize?(): void\n}\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false)\n\n useEffect(() => {\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\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, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nexport function useMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useEffect(() => {\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 function getIsBrowser() {\n return typeof window !== 'undefined'\n}\n","import { useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport {\n UseSpringCarouselProps,\n ReactSpringThumbItem,\n PrepareThumbsData,\n UseSpringCarouselItems,\n} from '../types'\nimport { useMount } from '../utils'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: UseSpringCarouselItems['items']\n withThumbs: boolean\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n thumbsWrapperRef?: UseSpringCarouselProps['thumbsWrapperRef']\n springConfig: SpringConfig\n prepareThumbsData?: PrepareThumbsData\n}\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n thumbsWrapperRef,\n prepareThumbsData,\n}: Props) {\n const internalThumbsWrapperRef = useRef<HTMLDivElement | null>(null)\n const [thumbListStyles, setThumbListStyles] = useSpring(() => ({\n [thumbsSlideAxis]: 0,\n config: springConfig,\n }))\n\n useMount(() => {\n if (withThumbs) {\n const missingThumbs = items.some(item => !item.renderThumb)\n if (missingThumbs) {\n throw new Error(\n 'The renderThumb property is missing in one or more items. You need to add the renderThumb property to every item of the carousel when the prop withThumbs={true} or eventually set withThumbs={false}.',\n )\n }\n }\n })\n\n function handleThumbsScroll(activeItem: number) {\n function getOffsetDirection() {\n return thumbsSlideAxis === 'x' ? 'offsetLeft' : 'offsetTop'\n }\n function getOffsetDimension() {\n return thumbsSlideAxis === 'x' ? 'offsetWidth' : 'offsetHeight'\n }\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 if (thumbsWrapperRef && thumbsWrapperRef.current) {\n internalThumbsWrapperRef.current = thumbsWrapperRef.current\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 setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }),\n },\n to: {\n [thumbsSlideAxis]: getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }),\n },\n onChange: val => {\n if (thumbsSlideAxis === 'x') {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollLeft = val.x\n } else {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollTop = val.y\n }\n },\n })\n }\n }\n function handlePrepareThumbsDate() {\n function getPreparedItems(\n _items: UseSpringCarouselItems['items'],\n ): ReactSpringThumbItem[] {\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 function getScrollDirectionSpringValue() {\n if (thumbsSlideAxis === 'x') {\n return {\n // @ts-ignore\n scrollLeft: thumbListStyles.x,\n }\n }\n\n return {\n // @ts-ignore\n scrollTop: thumbListStyles.y,\n }\n }\n\n const thumbsFragment = withThumbs ? (\n <animated.div\n ref={internalThumbsWrapperRef}\n {...getScrollDirectionSpringValue()}\n style={{\n display: 'flex',\n flex: 1,\n position: 'relative',\n flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsDate().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId}>\n {renderThumb}\n </div>\n )\n })}\n </animated.div>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n","import { useRef, createContext, useCallback, useContext, useEffect } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from './modules'\nimport {\n UseSpringCarouselProps,\n UseSpringCarouselContextProps,\n SlideToItemFnProps,\n SlideActionType,\n} from './types'\nimport { useMount } from './utils'\nimport { getIsBrowser } from './utils'\n\nconst UseSpringCarouselContext = createContext<UseSpringCarouselContextProps | undefined>(\n undefined,\n)\n\nexport function useSpringCarouselContext() {\n const context = useContext(UseSpringCarouselContext)\n\n if (!context) {\n throw new Error(`useSpringCarouselContext isn't being used within the useSringCarousel context; \n use the context only inside a component that is rendered within the Carousel.`)\n }\n\n return context\n}\n\nexport default function useSpringCarousel({\n items,\n withLoop = false,\n draggingSlideTreshold = 140,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n thumbsWrapperRef,\n prepareThumbsData,\n itemsPerSlide = 1,\n initialActiveItem = 0,\n initialStartingPosition = 'start',\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction = 'none',\n slideAmount,\n}: UseSpringCarouselProps) {\n function getItems() {\n if (withLoop) {\n return [...items, ...items, ...items]\n }\n return items\n }\n const slideActionType = useRef<SlideActionType>('next')\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 currentWindowWidth = useRef(0)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideFluidEndReached = useRef(false)\n const currentSlidedValue = useRef(0)\n const currentStepSlideValue = useRef(0)\n\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n const getFluidWrapperScrollValue = useCallback(() => {\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 }, [carouselSlideAxis])\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n config: springConfig,\n onRest: ({ value }) => {\n currentSlidedValue.current = value[carouselSlideAxis]\n currentStepSlideValue.current = value[carouselSlideAxis]\n },\n }))\n const getSlideValue = useCallback(() => {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const carouselItem = getCarouselItem()\n\n if (!carouselItem) {\n throw Error('No carousel items available!')\n }\n const itemVal =\n carouselItem.getBoundingClientRect()[\n carouselSlideAxis === 'x' ? 'width' : 'height'\n ] + gutter\n\n if (itemsPerSlide === '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 }, [carouselSlideAxis, gutter, itemsPerSlide, slideAmount])\n const adjustCarouselWrapperPosition = useCallback(\n (ref: HTMLDivElement) => {\n if (itemsPerSlide !== 'fluid' && typeof itemsPerSlide === 'number') {\n const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top'\n\n function getDefaultPositionValue() {\n return getSlideValue() * items.length\n }\n function setPosition(v: number) {\n ref.style.top = '0px'\n ref.style.left = '0px'\n ref.style[positionProperty] = `-${v - startEndGutter}px`\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n function setCenterPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((itemsPerSlide as number) - 1) / 2),\n )\n }\n function setEndPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round((itemsPerSlide as number) - 1),\n )\n }\n\n if (itemsPerSlide > 1) {\n switch (initialStartingPosition) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition()\n break\n }\n case 'end': {\n setEndPosition()\n break\n }\n }\n } else {\n setStartPosition()\n }\n }\n },\n [\n startEndGutter,\n carouselSlideAxis,\n getSlideValue,\n initialStartingPosition,\n items.length,\n itemsPerSlide,\n ],\n )\n const handleResize = useCallback(() => {\n if (window.innerWidth === currentWindowWidth.current) {\n return\n }\n currentWindowWidth.current = window.innerWidth\n\n if (itemsPerSlide === 'fluid') {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n const lastItem = document.querySelector(\n '.use-spring-carousel-item:last-of-type',\n )! as HTMLDivElement\n console.log({\n lastItem: lastItem.offsetLeft,\n })\n }\n } else {\n setCarouselStyles.start({\n immediate: true,\n x: 0,\n y: 0,\n })\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n if (withLoop) {\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n }, [\n adjustCarouselWrapperPosition,\n carouselSlideAxis,\n getSlideValue,\n setCarouselStyles,\n withLoop,\n itemsPerSlide,\n getFluidWrapperScrollValue,\n ])\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items,\n thumbsSlideAxis,\n springConfig,\n thumbsWrapperRef,\n prepareThumbsData,\n })\n function getCurrentSlidedValue() {\n return carouselStyles[carouselSlideAxis].get()\n }\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.movement[carouselSlideAxis === 'x' ? 0 : 1]\n function resetAnimation() {\n if (itemsPerSlide === 'fluid') {\n if (getIsFirstItem()) {\n slideToPrevItem()\n } else if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: currentStepSlideValue.current,\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: -(getCurrentActiveItem() * getSlideValue()),\n })\n }\n }\n\n if (props.first) {\n currentSlidedValue.current = getCurrentSlidedValue()\n }\n if (isDragging) {\n setIsDragging(true)\n emitObservable({\n eventName: 'onDrag',\n ...props,\n })\n\n setCarouselStyles.start({\n [carouselSlideAxis]: currentSlidedValue.current + movement,\n })\n\n const prevItemTreshold = movement > draggingSlideTreshold\n const nextItemTreshold = movement < -draggingSlideTreshold\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n\n if (slideFluidEndReached.current && movement < 0) {\n if (nextItemTreshold) {\n props.cancel()\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n }\n } else if (nextItemTreshold) {\n props.cancel()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem()\n }\n } else if (prevItemTreshold) {\n props.cancel()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem()\n }\n }\n }\n if (props.last && !props.pressed) {\n resetAnimation()\n }\n },\n {\n enabled: !disableGestures,\n },\n )\n\n // Perform some check on first mount\n useMount(() => {\n if (itemsPerSlide !== 'fluid' && !Number.isInteger(itemsPerSlide)) {\n throw new Error(`itemsPerSlide should be an integer.`)\n }\n if (itemsPerSlide > 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 (itemsPerSlide < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\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 if (initialActiveItem < 0) {\n console.warn('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItem > items.length) {\n console.warn(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n })\n useMount(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n if (getIsBrowser()) {\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n }\n })\n useMount(() => {\n if (initialActiveItem > 0 && initialActiveItem <= items.length) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n })\n useEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n }, [handleResize, shouldResizeOnWindowResize])\n useEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxis === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\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 slideToItem({\n from,\n to,\n customTo,\n immediate = false,\n onRest = () => {},\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: to,\n slideActionType: getSlideActionType(),\n })\n }\n\n function getFromValue() {\n if (from) {\n return {\n from: {\n [carouselSlideAxis]: from,\n },\n }\n }\n return {}\n }\n function getToValue() {\n if (customTo) {\n return {\n [carouselSlideAxis]: customTo,\n }\n }\n return {\n [carouselSlideAxis]: -(getSlideValue() * to),\n }\n }\n\n setCarouselStyles.start({\n ...getFromValue(),\n to: getToValue(),\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 currentItem: getCurrentActiveItem(),\n slideActionType: getSlideActionType(),\n })\n }\n }\n },\n })\n if (enableThumbsWrapperScroll && withThumbs && !immediate) {\n handleThumbsScroll(to)\n }\n }\n function getWrapperFromValue(element: HTMLDivElement) {\n if (element.style.transform === 'none') {\n return 0\n }\n const values = element.style.transform.split(/\\w+\\(|\\);?/)\n return Number(\n values[1].split(/,\\s?/g)[carouselSlideAxis === 'x' ? 0 : 1].replace('px', ''),\n )\n }\n function getIsFirstItem() {\n return getCurrentActiveItem() === 0\n }\n function getIsLastItem() {\n return getCurrentActiveItem() === items.length - 1\n }\n function slideToPrevItem() {\n if (itemsPerSlide === 'fluid' && !withLoop) {\n const currentSlideVal = getWrapperFromValue(carouselTrackWrapperRef.current!)\n const nextPrevValue = currentSlideVal + getSlideValue() + 100\n\n if (getIsFirstItem()) {\n slideToItem({\n to: 0,\n })\n return\n }\n if (nextPrevValue >= 0) {\n slideToItem({\n to: 0,\n })\n currentStepSlideValue.current = 0\n } else {\n const nextVal = currentStepSlideValue.current + getSlideValue()\n currentStepSlideValue.current = nextVal\n slideToItem({\n to: getPrevItem(),\n customTo: nextVal,\n })\n }\n if (slideFluidEndReached.current) {\n slideFluidEndReached.current = false\n }\n } else if ((!withLoop && getCurrentActiveItem() === 0) || windowIsHidden.current) {\n return\n } else {\n setSlideActionType('prev')\n\n if (getIsFirstItem()) {\n slideToItem({\n from: -(\n Math.abs(getWrapperFromValue(carouselTrackWrapperRef.current!)) +\n getSlideValue() * items.length\n ),\n to: items.length - 1,\n })\n } else {\n slideToItem({\n to: getPrevItem(),\n })\n }\n }\n }\n function slideToNextItem() {\n if (itemsPerSlide === 'fluid' && !withLoop) {\n const willGoAfterLastFluidItem =\n Math.abs(getNextItem() * getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n if (slideFluidEndReached.current) {\n return\n }\n if (willGoAfterLastFluidItem) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n slideFluidEndReached.current = true\n currentStepSlideValue.current = nextValue\n\n slideToItem({\n to: getNextItem(),\n customTo: nextValue,\n })\n } else {\n const nextValue = currentStepSlideValue.current - getSlideValue()\n currentStepSlideValue.current = nextValue\n\n slideToItem({\n to: getNextItem(),\n customTo: nextValue,\n })\n }\n } else if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n } else {\n setSlideActionType('next')\n\n if (getIsLastItem()) {\n slideToItem({\n from:\n getWrapperFromValue(carouselTrackWrapperRef.current!) +\n getSlideValue() * items.length,\n to: 0,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n })\n }\n }\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 if (itemIndex === getCurrentActiveItem()) {\n return\n }\n\n const currentItem = findItemIndex(items[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 const contextProps: UseSpringCarouselContextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem,\n slideToNextItem,\n slideToItem: _slideToItem,\n getIsActiveItem: id => {\n return findItemIndex(id) === getCurrentActiveItem()\n },\n getCurrentActiveItem: () => ({\n id: items[getCurrentActiveItem()].id,\n index: getCurrentActiveItem(),\n }),\n }\n function getItemStyles() {\n if (typeof itemsPerSlide === 'number') {\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\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 const carouselFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\n data-testid=\"use-spring-carousel-wrapper\"\n style={{\n display: 'flex',\n position: 'relative',\n width: '100%',\n height: '100%',\n overflow: 'hidden',\n }}\n >\n <animated.div\n {...bindDrag()}\n data-testid=\"use-spring-carousel-animated-wrapper\"\n style={{\n display: 'flex',\n top: 0,\n left: 0,\n position: 'relative',\n touchAction,\n flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\n ...carouselStyles,\n }}\n ref={ref => {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n if (withLoop) {\n adjustCarouselWrapperPosition(ref)\n }\n }\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(),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </UseSpringCarouselContext.Provider>\n )\n const thumbsFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n {_thumbsFragment}\n </UseSpringCarouselContext.Provider>\n )\n\n return {\n carouselFragment,\n thumbsFragment,\n ...contextProps,\n }\n}\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 {\n UseTransitionCarouselContextProps,\n UseTransitionCarouselProps,\n SlideActionType,\n} from './types'\n\nconst UseTransitionCarouselContext = createContext<\n UseTransitionCarouselContextProps | undefined\n>(undefined)\n\nexport function 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\nexport default function 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 springAnimationProps = {\n initial: {\n opacity: 1,\n position: 'relative',\n },\n from: {\n opacity: 0,\n position: 'absolute',\n },\n enter: {\n opacity: 1,\n position: 'relative',\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 } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n emitObservable,\n mainCarouselWrapperRef,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\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 keys: null,\n onRest: val => {\n if (val.finished) {\n setIsAnimating(false)\n emitObservable({\n eventName: 'onSlideChange',\n currentItem: activeItem,\n slideActionType: getSlideActionType(),\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 nextItem: newActiveItem,\n slideActionType: getSlideActionType(),\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 nextItem: 0,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(0)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem + 1)\n }\n } else {\n if (!isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\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 nextItem: items.length - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(items.length - 1)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem - 1)\n }\n } else {\n if (!isFirstItem) {\n setSlideActionType('prev')\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\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"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useMount","callback","isMounted","clean","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","thumbsWrapperRef","prepareThumbsData","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","[object Object]","config","some","item","renderThumb","Error","thumbsFragment","_jsx","animated","div","ref","scrollLeft","x","scrollTop","y","style","display","flex","position","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","handlePrepareThumbsDate","thumbId","handleThumbsScroll","activeItem","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","start","from","getScrollFromValue","to","scrollDimensionProperty","length","getScrollToValue","onChange","val","UseSpringCarouselContext","createContext","undefined","UseTransitionCarouselContext","withLoop","draggingSlideTreshold","default","shouldResizeOnWindowResize","enableThumbsWrapperScroll","carouselSlideAxis","itemsPerSlide","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","slideActionType","internalItems","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","currentWindowWidth","fluidTotalWrapperScrollValue","slideFluidEndReached","currentSlidedValue","currentStepSlideValue","getFluidWrapperScrollValue","useCallback","Math","round","Number","getBoundingClientRect","carouselStyles","setCarouselStyles","onRest","value","getSlideValue","carouselItem","itemVal","adjustCarouselWrapperPosition","positionProperty","getDefaultPositionValue","setPosition","v","top","left","setStartPosition","window","innerWidth","immediate","lastItem","console","log","offsetLeft","getCurrentActiveItem","_thumbsFragment","bindDrag","useDrag","props","dragging","movement","resetAnimation","getIsFirstItem","slideToPrevItem","first","get","setIsDragging","prevItemTreshold","nextItemTreshold","width","cancel","getIsLastItem","slideToNextItem","last","pressed","enabled","setSlideActionType","type","getSlideActionType","setActiveItem","newItem","setIsAnimating","getPrevItem","currentActiveItem","getNextItem","findItemIndex","findIndex","slideToItem","customTo","nextItem","finished","currentItem","getWrapperFromValue","element","transform","values","split","replace","abs","nextPrevValue","nextVal","willGoAfterLastFluidItem","nextValue","isInteger","warn","handleVisibilityChange","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsDragging","getIsNextItem","itemIndex","getIsPrevItem","_item","getIsActiveItem","index","carouselFragment","Provider","height","overflow","percentValue","getAnimatedWrapperStyles","renderItem","className","marginRight","marginBottom","context","useContext","toPrevItemSpringProps","toNextItemSpringProps","springAnimationProps","initial","opacity","enter","leave","useState","bindSwipe","mx","isFirstItem","isLastItem","itemsFragment","useTransition","getTransitionConfig","onStart","keys","transitions","styles","newActiveItem"],"mappings":"0oBAIgBA,IACd,MAAMC,EAAoBC,SAAO,IAAIC,WAarC,MAAO,CACLC,uBAZF,SAAgCC,GAC9BC,aAAU,KACR,MAAMC,EAAYN,EAAkBO,QAAQD,UAAUF,GACtD,MAAO,IAAME,EAAUE,gBACtB,CAACJ,KASJK,eANuCC,IACvCV,EAAkBO,QAAQI,KAAKD,cCLnBE,GAAoBC,uBAClCA,EAAsBJ,eACtBA,EAAcK,aACdA,IAEA,MAAMC,EAAed,UAAO,GAmC5B,SAASe,EAAgBC,GACvBF,EAAaR,QAAUU,EAiBzB,OAnDAZ,aAAU,KACR,SAASa,IACHC,SAASC,oBACXJ,GAAgB,GAChBP,EAAe,CACbY,UAAW,qBACXN,cAAc,IAGhBD,GAAgBA,KAGbK,SAASC,oBACZJ,GAAgB,GAChBP,EAAe,CACbY,UAAW,qBACXN,cAAc,IAEhBD,GAAgBA,KAIpB,GAAIQ,UAAWC,UAGb,OAFAD,UAAWE,GAAG,SAAUN,GAEjB,KACDI,UAAWC,WACbD,UAAWG,IAAI,SAAUP,OAwB1B,CACLQ,gBAXF,SAAyBC,GACnBL,UAAWC,WACbD,UAAWM,QAASD,GAAcd,EAAuBN,UAU3DsB,eANF,WACEP,UAAWC,WAAaD,UAAWQ,QAMnCC,gBAjBF,WACE,OAAO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ACJjL,MAAO,CACLC,QAAS,OACTE,SAAU,WACVyG,MAAO,OACPmD,OAAQ,OACRC,SAAU,qBAGXqB,sBAaL9L,eAPAC,MAAC+C,EAA6BuH,wBAASpF,MAAO0E,aAC3CtD,eAOAsD,8CA9WL,MAAMmB,EAAUC,aAAWjI,GAE3B,IAAKgI,EACH,MAAM,IAAIjL,MAAM,+KAIlB,OAAOiL"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/modules/useCustomEventsModule.tsx","../src/modules/useFullscreenModule.tsx","../src/utils.ts","../src/modules/useThumbsModule.tsx","../src/useSpringCarousel.tsx","../src/useTransitionCarousel.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { Subject } from 'rxjs'\nimport { EventsObservableProps, ObservableCallbackFn, EmitObservableFn } from '../types'\n\nexport function useCustomEventsModule() {\n const eventsObserverRef = useRef(new Subject<EventsObservableProps>())\n\n function useListenToCustomEvent(fn: ObservableCallbackFn) {\n useEffect(() => {\n const subscribe = eventsObserverRef.current.subscribe(fn)\n return () => subscribe.unsubscribe()\n }, [fn])\n }\n\n const emitObservable: EmitObservableFn = data => {\n eventsObserverRef.current.next(data)\n }\n\n return {\n useListenToCustomEvent,\n emitObservable,\n }\n}\n","import { useRef, MutableRefObject, useEffect } from 'react'\nimport screenfull from 'screenfull'\nimport { EmitObservableFn } from '../types'\n\ntype FullscreenModule = {\n mainCarouselWrapperRef: MutableRefObject<HTMLDivElement | null>\n emitObservable: EmitObservableFn\n handleResize?(): void\n}\n\nexport function useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n}: FullscreenModule) {\n const isFullscreen = useRef(false)\n\n useEffect(() => {\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, useEffect } from 'react'\n\ntype Callback = () => void | (() => void)\n\nexport function useMount(callback: Callback) {\n const isMounted = useRef(false)\n\n useEffect(() => {\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 function getIsBrowser() {\n return typeof window !== 'undefined'\n}\n","import { forwardRef, HTMLAttributes, useRef } from 'react'\nimport { useSpring, SpringConfig, animated } from 'react-spring'\nimport { useMount } from 'src/utils'\nimport {\n UseSpringCarouselProps,\n ReactSpringThumbItem,\n PrepareThumbsData,\n UseSpringCarouselItems,\n SlideActionType,\n} from '../types'\n\ntype OffsetDimension = 'offsetWidth' | 'offsetHeight'\ntype OffsetDirection = 'offsetLeft' | 'offsetTop'\ntype ScrollDirection = 'scrollLeft' | 'scrollTop'\n\ntype Props = {\n items: UseSpringCarouselItems['items']\n withThumbs: boolean\n thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis']\n springConfig: SpringConfig\n prepareThumbsData?: PrepareThumbsData\n itemsPerSlide?: UseSpringCarouselProps['itemsPerSlide']\n CustomThumbsWrapperComponent?: UseSpringCarouselProps['CustomThumbsWrapperComponent']\n getFluidWrapperScrollValue?(): number\n getSlideValue?(): number\n}\n\ntype WrapperProps = {\n children: React.ReactNode\n} & HTMLAttributes<HTMLDivElement>\n\nconst InternalWrapper = forwardRef<HTMLDivElement, WrapperProps>(\n ({ children, ...rest }, ref) => {\n return (\n <animated.div {...rest} ref={ref}>\n {children}\n </animated.div>\n )\n },\n)\n\nexport function useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis = 'x',\n springConfig,\n prepareThumbsData,\n itemsPerSlide,\n getFluidWrapperScrollValue = () => 0,\n getSlideValue = () => 0,\n CustomThumbsWrapperComponent,\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) {\n internalThumbsWrapperRef.current[\n thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[thumbsSlideAxis])\n }\n },\n }))\n\n useMount(() => {\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 (itemsPerSlide === '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 setThumbListStyles.start({\n from: {\n [thumbsSlideAxis]: getScrollFromValue({\n thumbWrapper,\n scrollDirection,\n }),\n },\n to: {\n [thumbsSlideAxis]: getScrollToValue({\n thumbWrapper,\n thumbOffsetPosition,\n thumbScrollDimension,\n offsetDimension,\n }),\n },\n onChange: val => {\n if (thumbsSlideAxis === 'x') {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollLeft = val.x\n } else {\n // @ts-ignore\n internalThumbsWrapperRef!.current!.scrollTop = val.y\n }\n },\n })\n }\n }\n }\n function handlePrepareThumbsDate() {\n function getPreparedItems(\n _items: UseSpringCarouselItems['items'],\n ): ReactSpringThumbItem[] {\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 Wrapper = CustomThumbsWrapperComponent\n ? animated(CustomThumbsWrapperComponent)\n : InternalWrapper\n\n const thumbsFragment = withThumbs ? (\n <Wrapper\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 flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column',\n ...(thumbsSlideAxis === 'x'\n ? { overflowX: 'auto' }\n : {\n overflowY: 'auto',\n maxHeight: '100%',\n }),\n }}\n >\n {handlePrepareThumbsDate().map(({ id, renderThumb }) => {\n const thumbId = `thumb-${id}`\n return (\n <div key={thumbId} id={thumbId}>\n {renderThumb}\n </div>\n )\n })}\n </Wrapper>\n ) : null\n\n return {\n thumbsFragment,\n handleThumbsScroll,\n }\n}\n","import { useRef, createContext, useCallback, useContext, useEffect } from 'react'\nimport { useSpring, config, animated } from 'react-spring'\nimport { useDrag } from '@use-gesture/react'\nimport { useCustomEventsModule, useFullscreenModule, useThumbsModule } from './modules'\nimport {\n UseSpringCarouselProps,\n SlideToItemFnProps,\n SlideActionType,\n UseSpringDafaultTypeReturnProps,\n UseSpringFluidTypeReturnProps,\n} from './types'\nimport { useMount } from './utils'\nimport { getIsBrowser } from './utils'\n\ntype ReturnHook<T> = T extends 'fluid'\n ? UseSpringFluidTypeReturnProps\n : UseSpringDafaultTypeReturnProps\n\nconst UseSpringCarouselContext = createContext<\n (UseSpringFluidTypeReturnProps | UseSpringDafaultTypeReturnProps) | undefined\n>(undefined)\n\nexport default function useSpringCarousel<T>({\n itemsPerSlide = 1,\n items,\n withLoop = false,\n draggingSlideTreshold = 140,\n springConfig = config.default,\n shouldResizeOnWindowResize = true,\n withThumbs = false,\n enableThumbsWrapperScroll = true,\n carouselSlideAxis = 'x',\n thumbsSlideAxis = 'x',\n prepareThumbsData,\n initialActiveItem = 0,\n initialStartingPosition = 'start',\n disableGestures = false,\n gutter = 0,\n startEndGutter = 0,\n touchAction = 'none',\n slideAmount,\n freeScroll = false,\n CustomThumbsWrapperComponent,\n}: UseSpringCarouselProps): ReturnHook<T> & {\n carouselFragment: JSX.Element\n thumbsFragment: JSX.Element\n} {\n function getItems() {\n if (withLoop) {\n return [...items, ...items, ...items]\n }\n return items\n }\n const slideActionType = useRef<SlideActionType>('initial')\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 currentWindowWidth = useRef(0)\n const fluidTotalWrapperScrollValue = useRef(0)\n const slideFluidEndReached = useRef(false)\n const initialWindowWidth = useRef(0)\n\n const [carouselStyles, setCarouselStyles] = useSpring(() => ({\n y: 0,\n x: 0,\n config: springConfig,\n onChange: ({ value }) => {\n if (mainCarouselWrapperRef.current && freeScroll) {\n mainCarouselWrapperRef.current[\n carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ] = Math.abs(value[carouselSlideAxis])\n }\n },\n }))\n function getCarouselItem() {\n return carouselTrackWrapperRef.current?.querySelector('.use-spring-carousel-item')\n }\n const getMainCarouselWrapperWidth = useCallback(() => {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('mainCarouselWrapperRef is not available')\n }\n return mainCarouselWrapperRef.current.getBoundingClientRect()[\n carouselSlideAxis === 'x' ? 'width' : 'height'\n ]\n }, [carouselSlideAxis])\n const getCarouselItemWidth = useCallback(() => {\n const carouselItem = getCarouselItem()\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 }, [carouselSlideAxis, gutter])\n const getCurrentSlidedValue = useCallback(() => {\n return carouselStyles[carouselSlideAxis].get()\n }, [carouselSlideAxis, carouselStyles])\n const getIfItemsNotFillTheCarousel = useCallback(() => {\n return getCarouselItemWidth() * items.length < getMainCarouselWrapperWidth()\n }, [getCarouselItemWidth, getMainCarouselWrapperWidth, items.length])\n const getFluidWrapperScrollValue = useCallback(() => {\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 }, [carouselSlideAxis])\n const getIsFirstItem = useCallback(() => {\n return getCurrentActiveItem() === 0\n }, [])\n const getSlideValue = useCallback(() => {\n if (!carouselTrackWrapperRef.current) {\n return 0\n }\n const itemVal = getCarouselItemWidth()\n\n if (itemsPerSlide === '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 }, [getCarouselItemWidth, itemsPerSlide, slideAmount])\n const adjustCarouselWrapperPosition = useCallback(\n (ref: HTMLDivElement) => {\n const positionProperty = carouselSlideAxis === 'x' ? 'left' : 'top'\n function getDefaultPositionValue() {\n return getCarouselItemWidth() * items.length\n }\n function setPosition(v: number) {\n ref.style.top = '0px'\n ref.style.left = '0px'\n ref.style[positionProperty] = `-${v - startEndGutter}px`\n }\n function setStartPosition() {\n setPosition(getDefaultPositionValue())\n }\n\n if (itemsPerSlide !== 'fluid' && typeof itemsPerSlide === 'number') {\n function setCenterPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round(((itemsPerSlide as number) - 1) / 2),\n )\n }\n function setEndPosition() {\n setPosition(\n getDefaultPositionValue() -\n getSlideValue() * Math.round((itemsPerSlide as number) - 1),\n )\n }\n\n if (itemsPerSlide > 1) {\n switch (initialStartingPosition) {\n default:\n case 'start': {\n setStartPosition()\n break\n }\n case 'center': {\n setCenterPosition()\n break\n }\n case 'end': {\n setEndPosition()\n break\n }\n }\n } else {\n setStartPosition()\n }\n } else {\n setStartPosition()\n }\n },\n [\n carouselSlideAxis,\n itemsPerSlide,\n getCarouselItemWidth,\n items.length,\n startEndGutter,\n getSlideValue,\n initialStartingPosition,\n ],\n )\n const handleResize = useCallback(() => {\n if (window.innerWidth === currentWindowWidth.current || freeScroll) {\n return\n }\n currentWindowWidth.current = window.innerWidth\n\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: 0,\n })\n return\n }\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n const diff = currentWindowWidth.current - initialWindowWidth.current\n\n if (slideFluidEndReached.current) {\n const nextValue = -fluidTotalWrapperScrollValue.current\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: nextValue,\n })\n } else {\n const nextValue = getCurrentSlidedValue() + diff\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: nextValue,\n })\n }\n\n initialWindowWidth.current = window.innerWidth\n } else {\n setCarouselStyles.start({\n immediate: true,\n x: 0,\n y: 0,\n })\n setCarouselStyles.start({\n immediate: true,\n [carouselSlideAxis]: -(getSlideValue() * getCurrentActiveItem()),\n })\n }\n if (withLoop) {\n adjustCarouselWrapperPosition(carouselTrackWrapperRef.current!)\n }\n }, [\n itemsPerSlide,\n withLoop,\n getIfItemsNotFillTheCarousel,\n getFluidWrapperScrollValue,\n freeScroll,\n setCarouselStyles,\n carouselSlideAxis,\n getCurrentSlidedValue,\n getSlideValue,\n adjustCarouselWrapperPosition,\n ])\n // Custom modules\n const { useListenToCustomEvent, emitObservable } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n mainCarouselWrapperRef,\n emitObservable,\n handleResize,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n withThumbs,\n items,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n itemsPerSlide,\n getFluidWrapperScrollValue,\n getSlideValue,\n CustomThumbsWrapperComponent,\n })\n\n function getWrapperScrollDirection() {\n if (!mainCarouselWrapperRef.current) {\n throw new Error('Missing mainCarouselWrapperRef.current')\n }\n return mainCarouselWrapperRef.current[\n carouselSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'\n ]\n }\n\n const bindDrag = useDrag(\n props => {\n const isDragging = props.dragging\n const movement = props.movement[carouselSlideAxis === 'x' ? 0 : 1]\n function resetAnimation() {\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n setCarouselStyles.start({\n [carouselSlideAxis]: 0,\n })\n } else if (getIsFirstItem()) {\n slideToPrevItem()\n } else if (slideFluidEndReached.current) {\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: getCurrentSlidedValue(),\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: -(getCurrentActiveItem() * getSlideValue()),\n })\n }\n }\n\n if (isDragging) {\n setIsDragging(true)\n emitObservable({\n eventName: 'onDrag',\n ...props,\n })\n\n if (freeScroll) {\n const direction = props.direction[carouselSlideAxis === 'x' ? 0 : 1]\n if (getWrapperScrollDirection() === 0 && direction > 0) {\n props.cancel()\n } else {\n setCarouselStyles.start({\n from: {\n [carouselSlideAxis]: getWrapperScrollDirection(),\n },\n to: {\n [carouselSlideAxis]:\n direction > 0\n ? getWrapperScrollDirection() - Math.abs(movement)\n : getWrapperScrollDirection() + Math.abs(movement),\n },\n })\n }\n } else {\n setCarouselStyles.start({\n [carouselSlideAxis]: getCurrentSlidedValue() + movement,\n })\n }\n\n const prevItemTreshold = movement > draggingSlideTreshold\n const nextItemTreshold = movement < -draggingSlideTreshold\n\n if (\n mainCarouselWrapperRef.current!.getBoundingClientRect().width >=\n items.length * getSlideValue()\n ) {\n slideFluidEndReached.current = true\n }\n\n if ((prevItemTreshold || nextItemTreshold) && getIfItemsNotFillTheCarousel()) {\n props.cancel()\n resetAnimation()\n return\n }\n\n if (slideFluidEndReached.current && movement < 0) {\n if (nextItemTreshold) {\n props.cancel()\n setCarouselStyles.start({\n [carouselSlideAxis]: -fluidTotalWrapperScrollValue.current,\n })\n }\n } else if (nextItemTreshold) {\n props.cancel()\n if (!withLoop && getIsLastItem()) {\n resetAnimation()\n } else {\n slideToNextItem()\n }\n } else if (prevItemTreshold) {\n props.cancel()\n if (!withLoop && getIsFirstItem()) {\n resetAnimation()\n } else {\n slideToPrevItem()\n }\n }\n }\n if (props.last && !props.pressed && !freeScroll) {\n resetAnimation()\n }\n },\n {\n enabled: !disableGestures,\n },\n )\n\n // Perform some check on first mount\n useMount(() => {\n if (itemsPerSlide !== 'fluid' && !Number.isInteger(itemsPerSlide)) {\n throw new Error(`itemsPerSlide should be an integer.`)\n }\n if (itemsPerSlide > 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 (itemsPerSlide < 1) {\n throw new Error(`The itemsPerSlide prop can't be less than 1.`)\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 if (initialActiveItem < 0) {\n console.warn('The initialActiveItem cannot be less than 0.')\n }\n if (initialActiveItem > items.length) {\n console.warn(\n 'The initialActiveItem cannot be greater than the total length of the items you provide.',\n )\n }\n })\n useMount(() => {\n fluidTotalWrapperScrollValue.current = getFluidWrapperScrollValue()\n function handleVisibilityChange() {\n if (document.hidden) {\n windowIsHidden.current = true\n } else {\n windowIsHidden.current = false\n }\n }\n if (getIsBrowser()) {\n document.addEventListener('visibilitychange', handleVisibilityChange)\n return () => {\n document.removeEventListener('visibilitychange', handleVisibilityChange)\n }\n }\n })\n useMount(() => {\n initialWindowWidth.current = window.innerWidth\n if (initialActiveItem > 0 && initialActiveItem <= items.length) {\n slideToItem({\n to: initialActiveItem,\n immediate: true,\n })\n setActiveItem(initialActiveItem)\n }\n })\n useEffect(() => {\n if (shouldResizeOnWindowResize) {\n window.addEventListener('resize', handleResize)\n return () => {\n window.removeEventListener('resize', handleResize)\n }\n }\n }, [handleResize, shouldResizeOnWindowResize])\n useEffect(() => {\n if (carouselTrackWrapperRef.current) {\n if (carouselSlideAxis === 'x') {\n carouselTrackWrapperRef.current.style.top = '0px'\n }\n if (carouselSlideAxis === 'y') {\n carouselTrackWrapperRef.current.style.left = '0px'\n }\n }\n }, [carouselSlideAxis])\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 slideToItem({\n from,\n to = -1,\n customTo,\n immediate = false,\n onRest = () => {},\n }: SlideToItemFnProps) {\n if (!immediate) {\n setActiveItem(to)\n setIsAnimating(true)\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: to,\n slideActionType: getSlideActionType(),\n })\n }\n\n function getFromValue() {\n if (typeof from === 'number') {\n return {\n from: {\n [carouselSlideAxis]: from,\n },\n }\n }\n return {}\n }\n function getToValue() {\n if (typeof customTo === 'number') {\n return {\n [carouselSlideAxis]: customTo,\n }\n }\n return {\n [carouselSlideAxis]: -(getSlideValue() * to),\n }\n }\n\n setCarouselStyles.start({\n ...getFromValue(),\n to: getToValue(),\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 currentItem: getCurrentActiveItem(),\n slideActionType: getSlideActionType(),\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() {\n setSlideActionType('prev')\n\n if (itemsPerSlide === 'fluid') {\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 })\n } else if (nextPrevValue >= 0) {\n if (withLoop) {\n slideToItem({\n from: getCurrentSlidedValue() - getCarouselItemWidth() * items.length,\n customTo:\n getCurrentSlidedValue() -\n getCarouselItemWidth() * items.length +\n getSlideValue(),\n })\n } else {\n slideToItem({\n customTo: 0,\n })\n }\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() + getSlideValue(),\n })\n }\n if (slideFluidEndReached.current) {\n slideFluidEndReached.current = false\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 })\n } else {\n slideToItem({\n to: getPrevItem(),\n })\n }\n }\n }\n function slideToNextItem() {\n setSlideActionType('next')\n\n if (itemsPerSlide === 'fluid') {\n if (getIfItemsNotFillTheCarousel()) {\n return\n }\n const willGoAfterLastFluidItem =\n Math.abs(getCurrentSlidedValue() - getSlideValue()) + 100 >=\n fluidTotalWrapperScrollValue.current\n\n if (freeScroll) {\n slideToItem({\n customTo: mainCarouselWrapperRef.current!.scrollLeft + getSlideValue(),\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 })\n } else if (slideFluidEndReached.current) {\n return\n } else if (willGoAfterLastFluidItem) {\n slideFluidEndReached.current = true\n slideToItem({\n customTo: -fluidTotalWrapperScrollValue.current,\n })\n } else {\n slideToItem({\n customTo: getCurrentSlidedValue() - getSlideValue(),\n })\n }\n } else {\n if (\n (!withLoop && getCurrentActiveItem() === internalItems.length - 1) ||\n windowIsHidden.current\n ) {\n return\n }\n\n if (getIsLastItem()) {\n slideToItem({\n from: getCurrentSlidedValue() + getSlideValue() * items.length,\n to: 0,\n })\n } else {\n slideToItem({\n to: getNextItem(),\n })\n }\n }\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 if (itemIndex === getCurrentActiveItem()) {\n return\n }\n\n const currentItem = findItemIndex(items[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\n const contextProps = {\n useListenToCustomEvent,\n getIsFullscreen,\n enterFullscreen,\n exitFullscreen,\n getIsAnimating,\n getIsDragging,\n getIsNextItem,\n getIsPrevItem,\n slideToPrevItem,\n slideToNextItem,\n ...(typeof itemsPerSlide === 'number'\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 function getItemStyles() {\n if (typeof itemsPerSlide === 'number') {\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\n flex: `1 0 calc(100% / ${itemsPerSlide} - ${\n (gutter * (itemsPerSlide - 1)) / itemsPerSlide\n }px)`,\n }\n }\n return {\n ...(carouselSlideAxis === 'x'\n ? { marginRight: `${gutter}px` }\n : { marginBottom: `${gutter}px` }),\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 function handleCarouselFragmentRef(ref: HTMLDivElement | null) {\n if (ref) {\n carouselTrackWrapperRef.current = ref\n if (withLoop) {\n adjustCarouselWrapperPosition(ref)\n }\n }\n }\n function getOverflowStyles() {\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 function getWheelEvent() {\n if (freeScroll) {\n return {\n onWheel() {\n carouselStyles[carouselSlideAxis].stop()\n },\n }\n }\n return {}\n }\n const carouselFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n <div\n ref={mainCarouselWrapperRef}\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 overflow: 'hidden',\n ...getOverflowStyles(),\n }}\n >\n <animated.div\n {...bindDrag()}\n data-testid=\"use-spring-carousel-animated-wrapper\"\n ref={handleCarouselFragmentRef}\n style={{\n display: 'flex',\n top: 0,\n left: 0,\n position: 'relative',\n touchAction,\n flexDirection: carouselSlideAxis === 'x' ? 'row' : 'column',\n ...getAnimatedWrapperStyles(),\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(),\n }}\n >\n {renderItem}\n </div>\n )\n })}\n </animated.div>\n </div>\n </UseSpringCarouselContext.Provider>\n )\n const thumbsFragment = (\n <UseSpringCarouselContext.Provider value={contextProps}>\n {_thumbsFragment}\n </UseSpringCarouselContext.Provider>\n )\n\n return {\n ...(contextProps as ReturnHook<T>),\n carouselFragment,\n thumbsFragment,\n }\n}\n\nexport function useSpringCarouselContext<T>() {\n const context = useContext(UseSpringCarouselContext)\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 ReturnHook<T>\n}\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 {\n UseTransitionCarouselContextProps,\n UseTransitionCarouselProps,\n SlideActionType,\n} from './types'\n\nconst UseTransitionCarouselContext = createContext<\n UseTransitionCarouselContextProps | undefined\n>(undefined)\n\nexport function 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\nexport default function 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 CustomThumbsWrapperComponent,\n springAnimationProps = {\n initial: {\n opacity: 1,\n position: 'relative',\n },\n from: {\n opacity: 0,\n position: 'absolute',\n },\n enter: {\n opacity: 1,\n position: 'relative',\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 } = useCustomEventsModule()\n const { enterFullscreen, exitFullscreen, getIsFullscreen } = useFullscreenModule({\n emitObservable,\n mainCarouselWrapperRef,\n })\n const { thumbsFragment: _thumbsFragment, handleThumbsScroll } = useThumbsModule({\n items,\n withThumbs,\n thumbsSlideAxis,\n springConfig,\n prepareThumbsData,\n CustomThumbsWrapperComponent,\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 keys: null,\n onRest: val => {\n if (val.finished) {\n setIsAnimating(false)\n emitObservable({\n eventName: 'onSlideChange',\n currentItem: activeItem,\n slideActionType: getSlideActionType(),\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 nextItem: newActiveItem,\n slideActionType: getSlideActionType(),\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 nextItem: 0,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(0)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem + 1)\n }\n } else {\n if (!isLastItem) {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem + 1,\n slideActionType: getSlideActionType(),\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 nextItem: items.length - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(items.length - 1)\n } else {\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\n })\n setActiveItem(activeItem - 1)\n }\n } else {\n if (!isFirstItem) {\n setSlideActionType('prev')\n emitObservable({\n eventName: 'onSlideStartChange',\n nextItem: activeItem - 1,\n slideActionType: getSlideActionType(),\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"],"names":["useCustomEventsModule","eventsObserverRef","useRef","Subject","useListenToCustomEvent","fn","useEffect","subscribe","current","unsubscribe","emitObservable","data","next","useFullscreenModule","mainCarouselWrapperRef","handleResize","isFullscreen","setIsFullscreen","_isFullscreen","handleFullscreenChange","document","fullscreenElement","eventName","screenfull","isEnabled","on","off","enterFullscreen","elementRef","request","exitFullscreen","exit","getIsFullscreen","useMount","callback","isMounted","clean","InternalWrapper","forwardRef","children","rest","ref","_jsx","animated","div","useThumbsModule","items","withThumbs","thumbsSlideAxis","springConfig","prepareThumbsData","itemsPerSlide","getFluidWrapperScrollValue","getSlideValue","CustomThumbsWrapperComponent","internalThumbsWrapperRef","thumbListStyles","setThumbListStyles","useSpring","x","y","config","onChange","value","Math","abs","getCurrentThumbScrollValue","getThumbsTotalScrollableValue","round","Number","getBoundingClientRect","getThumbSlideValue","thumbSlideTotal","Error","Wrapper","thumbsFragment","className","onWheel","stop","style","display","flex","position","flexDirection","overflowX","overflowY","maxHeight","getPreparedItems","_items","map","i","id","renderThumb","handlePrepareThumbsDate","thumbId","handleThumbsScroll","activeItem","actionType","totalScrollableValue","nextValue","start","from","[object Object]","to","thumbNode","querySelector","thumbWrapper","offsetDimension","scrollDirection","thumbOffsetPosition","offsetDirection","getThumbOffsetPosition","thumbScrollDimension","getThumbScrollDimension","getScrollFromValue","scrollDimensionProperty","length","getScrollToValue","val","scrollLeft","scrollTop","UseSpringCarouselContext","createContext","undefined","UseTransitionCarouselContext","withLoop","draggingSlideTreshold","default","shouldResizeOnWindowResize","enableThumbsWrapperScroll","carouselSlideAxis","initialActiveItem","initialStartingPosition","disableGestures","gutter","startEndGutter","touchAction","slideAmount","freeScroll","slideActionType","internalItems","carouselTrackWrapperRef","isDragging","isAnimating","windowIsHidden","currentWindowWidth","fluidTotalWrapperScrollValue","slideFluidEndReached","initialWindowWidth","carouselStyles","setCarouselStyles","getMainCarouselWrapperWidth","useCallback","getCarouselItemWidth","carouselItem","getCurrentSlidedValue","get","getIfItemsNotFillTheCarousel","getIsFirstItem","getCurrentActiveItem","itemVal","adjustCarouselWrapperPosition","positionProperty","getDefaultPositionValue","setPosition","v","top","left","setStartPosition","window","innerWidth","immediate","diff","_thumbsFragment","getWrapperScrollDirection","bindDrag","useDrag","props","dragging","movement","resetAnimation","slideToPrevItem","setIsDragging","direction","cancel","prevItemTreshold","nextItemTreshold","width","getIsLastItem","slideToNextItem","last","pressed","enabled","setSlideActionType","type","getSlideActionType","setActiveItem","newItem","setIsAnimating","getPrevItem","currentActiveItem","getNextItem","findItemIndex","findIndex","item","slideToItem","customTo","onRest","nextItem","finished","currentItem","nextPrevValue","willGoAfterLastFluidItem","currentWidth","isInteger","console","warn","handleVisibilityChange","hidden","addEventListener","removeEventListener","contextProps","getIsAnimating","getIsDragging","getIsNextItem","itemIndex","getIsPrevItem","_item","getIsActiveItem","index","carouselFragment","Provider","height","overflow","percentValue","getAnimatedWrapperStyles","renderItem","marginRight","marginBottom","context","useContext","toPrevItemSpringProps","toNextItemSpringProps","springAnimationProps","initial","opacity","enter","leave","useState","bindSwipe","mx","isFirstItem","isLastItem","itemsFragment","useTransition","getTransitionConfig","onStart","keys","transitions","styles","newActiveItem"],"mappings":"0oBAIgBA,IACd,MAAMC,EAAoBC,SAAO,IAAIC,WAarC,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ACAG,eAAAA,EACA1B,uBAAAA,EACA4N,cA3BF,SAAuBrI,GACrB,MAAMsI,EAAYvB,EAAc/G,GAEhC,OAAIkC,GAAY7B,IAAelD,EAAMsE,OAAS,EACvB,IAAd6G,EAGFA,IAAcjI,EAAa,GAqBlCkI,cAnBF,SAAuBvI,GACrB,MAAMsI,EAAYvB,EAAc/G,GAEhC,OAAIkC,GAA2B,IAAf7B,EACPiI,IAAcnL,EAAMsE,OAAS,EAG/B6G,IAAcjI,EAAa,GAalC8H,eAAAA,EACA9L,gBAAAA,EACAoM,gBAAiBzI,GACR+G,EAAc/G,KAAQK,EAE/B+D,qBAAsB,MACpBpE,GAAI7C,EAAMkD,GAAYL,GACtB0I,MAAOrI,KA4BX,MAAO,CACLsI,iBAxBA5L,MAACkF,EAA6B2G,wBAASxK,MAAO8J,aAC5CnL,2BACED,IAAK3B,GACD2O,KACJ1K,MAAO,CACLC,QAAS,OACTE,SAAU,WACVyG,MAAO,OACP6C,OAAQ,OACRC,SAAU,qBAGXoB,sBAaLlL,eAPAjC,MAACkF,EAA6B2G,wBAASxK,MAAO8J,aAC3ChD,eAOAgD,8CAhXL,MAAMkB,EAAUC,aAAWpH,GAE3B,IAAKmH,EACH,MAAM,IAAItK,MAAM,+KAIlB,OAAOsK"}
@@ -1,16 +1,19 @@
1
1
  /// <reference types="react" />
2
2
  import { SpringConfig } from 'react-spring';
3
- import { UseSpringCarouselProps, PrepareThumbsData, UseSpringCarouselItems } from '../types';
3
+ import { UseSpringCarouselProps, PrepareThumbsData, UseSpringCarouselItems, SlideActionType } from '../types';
4
4
  declare type Props = {
5
5
  items: UseSpringCarouselItems['items'];
6
6
  withThumbs: boolean;
7
7
  thumbsSlideAxis: UseSpringCarouselProps['thumbsSlideAxis'];
8
- thumbsWrapperRef?: UseSpringCarouselProps['thumbsWrapperRef'];
9
8
  springConfig: SpringConfig;
10
9
  prepareThumbsData?: PrepareThumbsData;
10
+ itemsPerSlide?: UseSpringCarouselProps['itemsPerSlide'];
11
+ CustomThumbsWrapperComponent?: UseSpringCarouselProps['CustomThumbsWrapperComponent'];
12
+ getFluidWrapperScrollValue?(): number;
13
+ getSlideValue?(): number;
11
14
  };
12
- export declare function useThumbsModule({ items, withThumbs, thumbsSlideAxis, springConfig, thumbsWrapperRef, prepareThumbsData, }: Props): {
15
+ export declare function useThumbsModule({ items, withThumbs, thumbsSlideAxis, springConfig, prepareThumbsData, itemsPerSlide, getFluidWrapperScrollValue, getSlideValue, CustomThumbsWrapperComponent, }: Props): {
13
16
  thumbsFragment: JSX.Element | null;
14
- handleThumbsScroll: (activeItem: number) => void;
17
+ handleThumbsScroll: (activeItem: number, actionType?: SlideActionType | undefined) => void;
15
18
  };
16
19
  export {};
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- /// <reference types="react" />
2
1
  import { SpringConfig, TransitionFrom, TransitionTo } from 'react-spring';
2
+ import { FullGestureState } from '@use-gesture/react';
3
+ import { HTMLAttributes } from 'react';
3
4
  export declare type ReactSpringThumbItem = {
4
5
  id: string;
5
6
  renderThumb: React.ReactNode;
@@ -12,9 +13,13 @@ export declare type ReactSpringCarouselItem = {
12
13
  declare type ItemWithThumb = {
13
14
  withThumbs: true;
14
15
  items: ReactSpringCarouselItem[];
16
+ enableThumbsWrapperScroll?: boolean;
17
+ prepareThumbsData?: PrepareThumbsData;
15
18
  };
16
19
  declare type ItemWithNoThumb = {
17
20
  withThumbs?: false;
21
+ enableThumbsWrapperScroll?: never;
22
+ prepareThumbsData?: never;
18
23
  items: {
19
24
  id: string;
20
25
  renderItem: React.ReactNode;
@@ -25,42 +30,45 @@ export declare type UseSpringCarouselItems = ItemWithThumb | ItemWithNoThumb;
25
30
  export declare type BaseCarouselSharedProps = {
26
31
  withLoop?: boolean;
27
32
  disableGestures?: boolean;
28
- enableThumbsWrapperScroll?: boolean;
29
33
  draggingSlideTreshold?: number;
30
- prepareThumbsData?: PrepareThumbsData;
31
34
  springConfig?: SpringConfig;
32
35
  thumbsSlideAxis?: 'x' | 'y';
36
+ CustomThumbsWrapperComponent?: React.FC<HTMLAttributes<HTMLElement>>;
33
37
  };
34
38
  declare type UseSpringCarouselLoopProps = {
35
- withLoop?: true;
39
+ withLoop: true;
36
40
  startEndGutter?: number;
41
+ freeScroll?: never;
37
42
  };
38
43
  declare type UseSpringCarouselNoLoopProps = {
39
44
  withLoop?: false;
40
45
  startEndGutter?: never;
46
+ freeScroll?: boolean;
41
47
  };
42
- declare type UseSpringCarouselFluidType = {
43
- itemsPerSlide?: 'fluid';
48
+ export declare type UseSpringCarouselFluidType = {
49
+ itemsPerSlide: 'fluid';
44
50
  slideAmount?: number;
45
51
  initialStartingPosition?: never;
52
+ initialActiveItem?: never;
53
+ freeScroll?: boolean;
46
54
  };
47
55
  declare type UseSpringCarouselNumericSlideType = {
48
56
  itemsPerSlide?: number;
49
57
  slideAmount?: never;
50
58
  initialStartingPosition?: 'start' | 'center' | 'end';
59
+ initialActiveItem?: number;
60
+ freeScroll?: never;
51
61
  };
52
62
  export declare type UseSpringCarouselProps = Omit<BaseCarouselSharedProps, 'withLoop'> & {
53
63
  shouldResizeOnWindowResize?: boolean;
54
64
  carouselSlideAxis?: 'x' | 'y';
55
- thumbsWrapperRef?: React.MutableRefObject<HTMLDivElement | null>;
56
- initialActiveItem?: number;
57
65
  gutter?: number;
58
66
  touchAction?: 'none' | 'pan';
59
67
  } & (UseSpringCarouselLoopProps | UseSpringCarouselNoLoopProps) & (UseSpringCarouselFluidType | UseSpringCarouselNumericSlideType) & UseSpringCarouselItems;
60
68
  export declare type PrepareThumbsData = (items: ReactSpringThumbItem[]) => ReactSpringThumbItem[];
61
69
  export declare type SlideToItemFnProps = {
62
70
  from?: number;
63
- to: number;
71
+ to?: number;
64
72
  newIndex?: number;
65
73
  immediate?: boolean;
66
74
  customTo?: number;
@@ -72,12 +80,25 @@ export declare type SpringAnimationProps = {
72
80
  enter: TransitionTo<ReactSpringCarouselItem>;
73
81
  leave: TransitionTo<ReactSpringCarouselItem>;
74
82
  };
75
- export declare type UseTransitionCarouselProps = BaseCarouselSharedProps & {
83
+ export declare type UseTransitionCarouselProps = BaseCarouselSharedProps & UseSpringCarouselItems & {
76
84
  toPrevItemSpringProps?: SpringAnimationProps;
77
85
  toNextItemSpringProps?: SpringAnimationProps;
78
86
  springAnimationProps?: SpringAnimationProps;
79
87
  };
80
- declare type BaseContextSharedProps = {
88
+ export declare type UseSpringFluidTypeReturnProps = {
89
+ useListenToCustomEvent: UseListenToCustomEvent;
90
+ getIsFullscreen(): boolean;
91
+ getIsPrevItem(id: string): boolean;
92
+ getIsNextItem(id: string): boolean;
93
+ enterFullscreen(elementRef?: HTMLElement): void;
94
+ exitFullscreen(): void;
95
+ slideToNextItem(): void;
96
+ slideToPrevItem(): void;
97
+ getIsAnimating(): boolean;
98
+ getIsDragging(): boolean;
99
+ };
100
+ export declare type UseSpringDafaultTypeReturnProps = {
101
+ useListenToCustomEvent: UseListenToCustomEvent;
81
102
  getIsFullscreen(): boolean;
82
103
  getIsPrevItem(id: string): boolean;
83
104
  getIsNextItem(id: string): boolean;
@@ -88,20 +109,31 @@ declare type BaseContextSharedProps = {
88
109
  getIsAnimating(): boolean;
89
110
  slideToItem(item: string | number): void;
90
111
  getIsActiveItem(id: string): boolean;
112
+ getIsDragging(): boolean;
91
113
  getCurrentActiveItem(): {
92
114
  id: string;
93
115
  index: number;
94
116
  };
95
- useListenToCustomEvent: UseListenToCustomEvent;
96
- };
97
- export declare type UseSpringCarouselContextProps = BaseContextSharedProps & {
98
- getIsDragging(): boolean;
99
117
  };
100
- export declare type UseTransitionCarouselContextProps = BaseContextSharedProps & {
118
+ export declare type UseTransitionCarouselContextProps = {
119
+ useListenToCustomEvent: UseListenToCustomEvent;
120
+ getIsFullscreen(): boolean;
121
+ getIsPrevItem(id: string): boolean;
122
+ getIsNextItem(id: string): boolean;
123
+ enterFullscreen(elementRef?: HTMLElement): void;
124
+ exitFullscreen(): void;
125
+ slideToNextItem(): void;
126
+ slideToPrevItem(): void;
127
+ getIsAnimating(): boolean;
128
+ slideToItem(item: string | number): void;
129
+ getIsActiveItem(id: string): boolean;
130
+ getCurrentActiveItem(): {
131
+ id: string;
132
+ index: number;
133
+ };
101
134
  activeItem: number;
102
135
  };
103
- import { FullGestureState } from '@use-gesture/react';
104
- export declare type SlideActionType = 'prev' | 'next';
136
+ export declare type SlideActionType = 'initial' | 'prev' | 'next';
105
137
  declare type OnSlideStartChange = {
106
138
  eventName: 'onSlideStartChange';
107
139
  nextItem: number;
@@ -1,23 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { UseSpringCarouselProps, UseSpringCarouselContextProps } from './types';
3
- export declare function useSpringCarouselContext(): UseSpringCarouselContextProps;
4
- export default function useSpringCarousel({ items, withLoop, draggingSlideTreshold, springConfig, shouldResizeOnWindowResize, withThumbs, enableThumbsWrapperScroll, carouselSlideAxis, thumbsSlideAxis, thumbsWrapperRef, prepareThumbsData, itemsPerSlide, initialActiveItem, initialStartingPosition, disableGestures, gutter, startEndGutter, touchAction, slideAmount, }: UseSpringCarouselProps): {
5
- getIsFullscreen(): boolean;
6
- getIsPrevItem(id: string): boolean;
7
- getIsNextItem(id: string): boolean;
8
- enterFullscreen(elementRef?: HTMLElement | undefined): void;
9
- exitFullscreen(): void;
10
- slideToNextItem(): void;
11
- slideToPrevItem(): void;
12
- getIsAnimating(): boolean;
13
- slideToItem(item: string | number): void;
14
- getIsActiveItem(id: string): boolean;
15
- getCurrentActiveItem(): {
16
- id: string;
17
- index: number;
18
- };
19
- useListenToCustomEvent: import("./types").UseListenToCustomEvent;
20
- getIsDragging(): boolean;
2
+ import { UseSpringCarouselProps, UseSpringDafaultTypeReturnProps, UseSpringFluidTypeReturnProps } from './types';
3
+ declare type ReturnHook<T> = T extends 'fluid' ? UseSpringFluidTypeReturnProps : UseSpringDafaultTypeReturnProps;
4
+ export default function useSpringCarousel<T>({ itemsPerSlide, items, withLoop, draggingSlideTreshold, springConfig, shouldResizeOnWindowResize, withThumbs, enableThumbsWrapperScroll, carouselSlideAxis, thumbsSlideAxis, prepareThumbsData, initialActiveItem, initialStartingPosition, disableGestures, gutter, startEndGutter, touchAction, slideAmount, freeScroll, CustomThumbsWrapperComponent, }: UseSpringCarouselProps): ReturnHook<T> & {
21
5
  carouselFragment: JSX.Element;
22
6
  thumbsFragment: JSX.Element;
23
7
  };
8
+ export declare function useSpringCarouselContext<T>(): ReturnHook<T>;
9
+ export {};
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { UseTransitionCarouselContextProps, UseTransitionCarouselProps } from './types';
3
3
  export declare function useTransitionCarouselContext(): UseTransitionCarouselContextProps;
4
- export default function useTransitionCarousel({ items, withLoop, withThumbs, springConfig, thumbsSlideAxis, enableThumbsWrapperScroll, draggingSlideTreshold, prepareThumbsData, toPrevItemSpringProps, toNextItemSpringProps, disableGestures, springAnimationProps, }: UseTransitionCarouselProps): {
4
+ export default function useTransitionCarousel({ items, withLoop, withThumbs, springConfig, thumbsSlideAxis, enableThumbsWrapperScroll, draggingSlideTreshold, prepareThumbsData, toPrevItemSpringProps, toNextItemSpringProps, disableGestures, CustomThumbsWrapperComponent, springAnimationProps, }: UseTransitionCarouselProps): {
5
+ useListenToCustomEvent: import("./types").UseListenToCustomEvent;
5
6
  getIsFullscreen(): boolean;
6
7
  getIsPrevItem(id: string): boolean;
7
8
  getIsNextItem(id: string): boolean;
@@ -16,7 +17,6 @@ export default function useTransitionCarousel({ items, withLoop, withThumbs, spr
16
17
  id: string;
17
18
  index: number;
18
19
  };
19
- useListenToCustomEvent: import("./types").UseListenToCustomEvent;
20
20
  activeItem: number;
21
21
  carouselFragment: JSX.Element;
22
22
  thumbsFragment: JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-spring-carousel",
3
- "version": "1.9.29-beta2",
3
+ "version": "1.9.29-beta3",
4
4
  "description": "A new Carousel experience for the web",
5
5
  "homepage": "https://react-spring-carousel-js.emilianobucci.com",
6
6
  "repository": "https://github.com/Emiliano-Bucci/react-spring-carousel-js",