react-simply-carousel
Advanced tools
Comparing version 9.1.1 to 9.1.2
@@ -1,1 +0,1 @@ | ||
import e,{memo as t,useState as n,useRef as i,Children as r,useCallback as o,useEffect as d}from"react";var l=function(){return l=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},l.apply(this,arguments)};function c(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,o=n.call(e),d=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)d.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return d}function a(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;r<o;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var u=t((function(t){var u,v,m=t.responsiveProps,f=void 0===m?[]:m,h=c(t,["responsiveProps"]),p=s(n(0),2),b=p[0],w=p[1],y=s(n(h.activeSlideIndex),2),x=y[0],S=y[1],E=i(null),g=i(null),L=i(null),T=i(!1),I=i(0),k=i(!1),C=i(""),M=i(null),W=i(null),P=i(0),O=i(x),X=f.reduce((function(e,t){void 0===t&&(t={});var n=t.minWidth,i=void 0===n?0:n,r=t.maxWidth,o=void 0===r?null:r,d=c(t,["minWidth","maxWidth"]);return b>i&&(!o||b<=o)?l(l({},e),d):e}),h),A=r.toArray(X.children),N=b?l(l({},X),{activeSlideIndex:Math.max(0,Math.min(X.activeSlideIndex,A.length-1)),itemsToShow:Math.min(A.length,X.itemsToShow||0),itemsToScroll:Math.min(A.length,X.itemsToScroll||1)}):h,F=N.containerProps,V=void 0===F?{}:F,j=V.style,z=void 0===j?{}:j,B=c(V,["style"]),R=N.innerProps,D=void 0===R?{}:R,q=D.style,H=void 0===q?{}:q,G=c(D,["style"]),J=N.itemsListProps,K=void 0===J?{}:J,Q=K.style,U=void 0===Q?{}:Q,Y=K.onTransitionEnd,Z=void 0===Y?void 0:Y,$=c(K,["style","onTransitionEnd"]),_=N.backwardBtnProps,ee=void 0===_?{}:_,te=ee.children,ne=void 0===te?null:te,ie=ee.show,re=void 0===ie||ie,oe=c(ee,["children","show"]),de=N.forwardBtnProps,le=void 0===de?{}:de,ce=le.children,se=void 0===ce?null:ce,ae=le.show,ue=void 0===ae||ae,ve=c(le,["children","show"]),me=N.activeSlideProps,fe=void 0===me?{}:me,he=fe.className,pe=void 0===he?"":he,be=fe.style,we=void 0===be?{}:be,ye=c(fe,["className","style"]),xe=N.visibleSlideProps,Se=void 0===xe?{}:xe,Ee=Se.className,ge=void 0===Ee?"":Ee,Le=Se.style,Te=void 0===Le?{}:Le,Ie=c(Se,["className","style"]),ke=N.updateOnItemClick,Ce=void 0!==ke&&ke,Me=N.activeSlideIndex,We=N.onRequestChange,Pe=N.speed,Oe=void 0===Pe?0:Pe,Xe=N.delay,Ae=void 0===Xe?0:Xe,Ne=N.easing,Fe=void 0===Ne?"linear":Ne,Ve=N.itemsToShow,je=void 0===Ve?0:Ve,ze=N.itemsToScroll,Be=void 0===ze?1:ze,Re=N.children,De=N.onAfterChange,qe=N.autoplay,He=void 0!==qe&&qe,Ge=N.autoplayDirection,Je=void 0===Ge?"forward":Ge,Ke=N.disableNavIfAllVisible,Qe=void 0===Ke||Ke,Ue=N.hideNavIfAllVisible,Ye=void 0===Ue||Ue,Ze=N.centerMode,$e=void 0!==Ze&&Ze,_e=N.infinite,et=void 0===_e||_e,tt=N.disableNavIfEdgeVisible,nt=void 0===tt||tt,it=N.disableNavIfEdgeActive,rt=void 0===it||it,ot=N.dotsNav,dt=void 0===ot?{}:ot,lt=N.persistentChangeCallbacks,ct=void 0!==lt&<,st=N.autoplayDelay,at=void 0===st?0:st,ut=N.preventScrollOnSwipe,vt=void 0!==ut&&ut,mt=N.disableSwipeByMouse,ft=void 0!==mt&&mt,ht=N.disableSwipeByTouch,pt=void 0!==ht&&ht,bt=N.touchSwipeTreshold,wt=N.mouseSwipeTreshold,yt=N.swipeTreshold,xt=N.touchSwipeRatio,St=N.mouseSwipeRatio,Et=N.swipeRatio,gt=void 0===Et?1:Et,Lt=N.dirRTL,Tt=void 0!==Lt&&Lt,It=dt||{},kt=It.show,Ct=void 0!==kt&&kt,Mt=It.containerProps,Wt=void 0===Mt?{}:Mt,Pt=It.itemBtnProps,Ot=void 0===Pt?{}:Pt,Xt=It.activeItemBtnProps,At=void 0===Xt?{}:Xt,Nt=r.count(Re)-1,Ft=!!b&&(null===(u=g.current)||void 0===u?void 0:u.offsetWidth)>=(null===(v=L.current)||void 0===v?void 0:v.offsetWidth),Vt=Ye&&Ft,jt=Qe&&Ft,zt=Me-x==0||!Oe&&!Ae?"none":"transform ".concat(Oe,"ms ").concat(Fe," ").concat(Ae,"ms"),Bt=o((function(e){var t,n=e.correctionSlideIndex,i=e.prevCorrectionSlideIndex,r=e.curActiveSlideIndex,o=L.current.offsetWidth,d=L.current.children,l=d.length,c=et?a([],s(d),!1).slice(l/3-i,l/3-i+l/3):a([],s(d),!1),u=null===(t=c[r])||void 0===t?void 0:t.offsetWidth,v=je?c.reduce((function(e,t,n){return n>=r&&n<r+je||n<r&&n<r+je-c.length?e+t.offsetWidth:e}),0):g.current.offsetWidth,m=Math.min(v,g.current.offsetWidth),f=o-m,h=$e&&et?-(m-u)/2:0,p=et?o/3:0,b=n-r==0?0:"forward"===C.current&&r<n?p:"backward"===C.current&&r>n?-p:0,w=r-n!=0,y=function(e){var t=c.reduce((function(t,n,i){return i>=e?t:t+(n.offsetWidth||0)}),0);return et?t:Math.min(f,t)},x=w&&et?y(n):0,S=w||!et?y(r):0,E=jt?0:S-x+h+b+p,T="translateX(".concat(Tt?"":"-").concat(E,"px)"),I=et?p+h:Math.min(f,c.reduce((function(e,t,n){return n<r?e+t.offsetWidth:e}),0)),k=I+m,M=c.map((function(e,t){return{slideIndex:t,htmlElement:e}})),W=et?a(a(a(a([],s(c.slice(r).map((function(e,t){return{slideIndex:t+r,htmlElement:e}}))),!1),s(M),!1),s(M),!1),s(c.slice(0,r).map((function(e,t){return{slideIndex:t,htmlElement:e}}))),!1):M,P=W.reduce((function(e,t){var n=t.slideIndex,i=t.htmlElement.offsetWidth;return(e.summ>=I&&e.summ<k||e.summ+i>I&&e.summ+i<=k)&&e.items.push({slideIndex:n,isFullyVisible:e.summ+i<=k&&e.summ>=I}),e.summ+=i,e}),{summ:0,items:[]}),O=!!P.items.find((function(e){return 0===e.slideIndex})),X=!!P.items.find((function(e){return e.slideIndex===c.length-1}));return{slidesHTMLElements:c,innerMaxWidth:v,itemsListMaxTranslateX:f,activeSlideWidth:u,offsetCorrectionForCenterMode:h,offsetCorrectionForInfiniteMode:p,itemsListTranslateX:E,itemsListTransform:T,visibleSlides:P.items,isFirstSlideVisible:O,isLastSlideVisible:X}}),[$e,jt,et,je,Tt]),Rt=b?Bt({prevCorrectionSlideIndex:O.current,curActiveSlideIndex:Me,correctionSlideIndex:x}):{},Dt=Rt.innerMaxWidth,qt=void 0===Dt?0:Dt,Ht=Rt.itemsListMaxTranslateX,Gt=void 0===Ht?0:Ht,Jt=Rt.activeSlideWidth,Kt=void 0===Jt?0:Jt,Qt=Rt.offsetCorrectionForCenterMode,Ut=void 0===Qt?0:Qt,Yt=Rt.offsetCorrectionForInfiniteMode,Zt=void 0===Yt?0:Yt,$t=Rt.itemsListTranslateX,_t=void 0===$t?0:$t,en=Rt.itemsListTransform,tn=void 0===en?"none":en,nn=Rt.visibleSlides,rn=void 0===nn?[]:nn,on=o((function(e){var t;return"forward"===e?(t=Me+Be)>Nt?et?t-Nt-1:Nt:t:"backward"===e?(t=Me-Be)<0?et?Nt+1+t:0:t:Me}),[Me,Be,Nt,et]),dn=o((function(e,t){var n;if(C.current=t,L.current.style.transition=Oe||Ae?"transform ".concat(Oe,"ms ").concat(Fe," ").concat(Ae,"ms"):"none",e!==Me||ct){clearTimeout(M.current);var i=Bt({correctionSlideIndex:x,prevCorrectionSlideIndex:x,curActiveSlideIndex:e}),r=i.visibleSlides,o=i.isFirstSlideVisible,d=i.isLastSlideVisible,l=i.itemsListTransform;e!==Me&&(null===(n=L.current)||void 0===n?void 0:n.style.transform)===l&&(T.current=!0),L.current.style.transform=l,We(e,{visibleSlides:r,isFirstSlideVisible:o,isLastSlideVisible:d})}else L.current.style.transform="translateX(".concat(Tt?"":"-").concat(Ut+Zt+(et?0:_t),"px)")}),[ct,Me,Ut,Ae,Fe,Oe,We,Zt,et,_t,x,Bt,Tt]),ln=o((function(){He&&(clearTimeout(M.current),M.current=setTimeout((function(){dn(on(Je),Je)}),at||Ae))}),[He,Je,at,dn,on,Ae]),cn=o((function(){dn(on("backward"),"backward")}),[dn,on]),sn=o((function(e){S(Me),Z&&Z(e)}),[Me,Z]),an=o((function(){dn(on("forward"),"forward")}),[dn,on]),un=function(e,t,n){return e.map((function(e,i){var r=e.props,o=void 0===r?{}:r,d=o.className,s=void 0===d?"":d,a=o.onClick,u=void 0===a?null:a,v=o.style,m=void 0===v?{}:v,f=c(o,["className","onClick","style"]),h=c(e,["props"]),p=et?P.current>=A.length?"forward":"backward":i>=Me?"forward":"backward",b=i+t===Me,w=rn.find((function(e){return e.slideIndex===i+t})),y="".concat(s," ").concat(b?pe:""," ").concat(w?ge:"").trim()||void 0,x=l(l(l(l({},m),w?Te:{}),b?we:{}),{boxSizing:"border-box",margin:0}),S=!n&&Ce?function(e){var t=e.direction,n=e.index,i=e.onClick;return function(e){dn(n,t||(Me<n?"forward":"")||(Me>n?"backward":"")),i&&i(e)}}({direction:p,index:i+t,onClick:u}):u,E=l(l(l({role:"tabpanel",className:y,style:x,onClick:S},f),w?Ie:{}),b?ye:{});return P.current+=1,l({props:E},h)}))};return d((function(){var e=L.current;function t(e){e.preventDefault(),e.stopPropagation()}function n(e){var t,n;k.current=!0;var i=!!(null===(t=e.touches)||void 0===t?void 0:t[0]),r=i?null===(n=e.touches)||void 0===n?void 0:n[0].clientX:e.clientX,o=(I.current-r)*((i?xt:St)||gt)+Ut+Zt+(et?0:_t),d=L.current.offsetWidth,l=Math.max(-o,-d);L.current.style.transition="none",L.current.style.transform="translateX(".concat((Tt?-1:1)*l,"px)")}function i(e){var r,o,d;if(document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i),k.current){null===(r=e.target)||void 0===r||r.addEventListener("click",t);var l=!!(null===(o=e.changedTouches)||void 0===o?void 0:o[0]),c=l?e.changedTouches[e.changedTouches.length-1].clientX:e.clientX,s=(I.current-c)*((l?xt:St)||gt),a=(l?bt:wt)||yt||Kt/2,u=s>a?{index:on("forward"),direction:"forward"}:s<-a?{index:on("backward"),direction:"backward"}:{index:Me,direction:"forward"};dn(u.index,u.direction)}else null===(d=e.target)||void 0===d||d.removeEventListener("click",t);I.current=0,k.current=!1}function r(e){var t,r;clearTimeout(M.current);var o=!!(null===(t=e.touches)||void 0===t?void 0:t[0]);I.current=o?null===(r=e.touches)||void 0===r?void 0:r[0].clientX:e.clientX,o?(document.addEventListener("touchmove",n),document.addEventListener("touchend",i)):(document.addEventListener("mousemove",n),document.addEventListener("mouseup",i))}return jt||(ft||null==e||e.addEventListener("mousedown",r),pt||null==e||e.addEventListener("touchstart",r,{passive:!0}),ft&&pt||null==e||e.addEventListener("dragstart",i)),function(){k.current=!1,I.current=0,null==e||e.removeEventListener("mousedown",r),null==e||e.removeEventListener("touchstart",r),null==e||e.removeEventListener("dragstart",i),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i)}}),[et,_t,tn,Ut,Zt,Me,Kt,on,dn,jt,ft,pt,bt,wt,yt,xt,St,gt,Tt]),d((function(){return Me!==x?(!Oe&&!Ae||T.current)&&(T.current=!1,S(Me)):(De&&De(Me,x),(et||"forward"===Je&&Me!==Nt||"backward"===Je&&0!==Me)&&ln()),function(){clearTimeout(M.current)}}),[x,Me,De,Oe,Ae,ln,et,Nt,Je]),d((function(){return b&&ln(),function(){clearTimeout(M.current)}}),[b]),d((function(){function e(){clearTimeout(W.current),clearTimeout(M.current),W.current=setTimeout((function(){b!==window.innerWidth&&w(0)}),400)}return b!==window.innerWidth&&w(window.innerWidth),window.addEventListener("resize",e),function(){clearTimeout(W.current),window.removeEventListener("resize",e)}}),[b]),P.current=0,O.current=x,e.createElement("div",l({style:l({display:"flex",flexFlow:"row wrap",boxSizing:"border-box",justifyContent:"center",width:"100%"},z)},B,{ref:E}),re&&!Vt&&e.createElement("button",l({},oe,{type:"button",onClick:(0===_t&&nt||0===Me&&rt)&&!et?void 0:cn,disabled:"boolean"==typeof oe.disabled?oe.disabled:!(!(0===_t&&nt||0===Me&&rt)||et)}),ne),e.createElement("div",l({},G,{style:l(l({width:"100%"},H),{display:"flex",boxSizing:"border-box",flexFlow:"row wrap",padding:"0",overflow:"hidden",maxWidth:qt?"".concat(qt,"px"):void 0,flex:qt?void 0:"1 0 auto"}),ref:g}),e.createElement("div",l({},$,{style:l(l({},U),{display:"flex",boxSizing:"border-box",outline:"none",transition:zt,transform:tn,touchAction:vt?"none":"auto"}),onTransitionEnd:Oe||Ae?sn:Z,tabIndex:-1,role:"presentation",ref:L}),et&&un(A.slice(x),x,jt),un(A,0,jt),et&&un(A,0,jt),et&&un(A.slice(0,x),0,jt))),ue&&!Vt&&e.createElement("button",l({},ve,{type:"button",onClick:(_t===Gt&&nt||Me===Nt&&rt)&&!et?void 0:an,disabled:"boolean"==typeof ve.disabled?ve.disabled:!(!(_t===Gt&&nt||Me===Nt&&rt)||et)}),se),!!Ct&&e.createElement("div",l({style:{width:"100%",display:"flex",justifyContent:"center"}},Wt),Array.from({length:Math.ceil(A.length/Be)}).map((function(t,n){return e.createElement("button",l({type:"button",key:n,title:"".concat(n)},Ot,Me>=n*Be&&Me<Math.min(Be*(n+1),Nt+1)?At:{},{onClick:function(){dn(Math.min(n*Be,A.length-1),Math.min(n*Be,A.length-1)>Me?"forward":"backward")}}))}))))}));export{u as default}; | ||
import e,{memo as t,useState as n,useRef as i,Children as r,useCallback as o,useEffect as d}from"react";var l=function(){return l=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},l.apply(this,arguments)};function c(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,o=n.call(e),d=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)d.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return d}function a(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;r<o;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var u=t((function(t){var u,v,m=t.responsiveProps,f=void 0===m?[]:m,h=c(t,["responsiveProps"]),p=s(n(0),2),b=p[0],w=p[1],y=s(n(h.activeSlideIndex),2),x=y[0],S=y[1],E=i(null),g=i(null),L=i(null),T=i(!1),I=i(0),k=i(!1),C=i(""),M=i(null),W=i(null),P=i(0),O=i(x),X=f.reduce((function(e,t){void 0===t&&(t={});var n=t.minWidth,i=void 0===n?0:n,r=t.maxWidth,o=void 0===r?null:r,d=c(t,["minWidth","maxWidth"]);return b>i&&(!o||b<=o)?l(l({},e),d):e}),h),A=r.toArray(X.children),N=b?l(l({},X),{activeSlideIndex:Math.max(0,Math.min(X.activeSlideIndex,A.length-1)),itemsToShow:Math.min(A.length,X.itemsToShow||0),itemsToScroll:Math.min(A.length,X.itemsToScroll||1)}):h,F=N.containerProps,V=void 0===F?{}:F,j=V.style,z=void 0===j?{}:j,B=c(V,["style"]),R=N.innerProps,D=void 0===R?{}:R,q=D.style,H=void 0===q?{}:q,G=c(D,["style"]),J=N.itemsListProps,K=void 0===J?{}:J,Q=K.style,U=void 0===Q?{}:Q,Y=K.onTransitionEnd,Z=void 0===Y?void 0:Y,$=c(K,["style","onTransitionEnd"]),_=N.backwardBtnProps,ee=void 0===_?{}:_,te=ee.children,ne=void 0===te?null:te,ie=ee.show,re=void 0===ie||ie,oe=c(ee,["children","show"]),de=N.forwardBtnProps,le=void 0===de?{}:de,ce=le.children,se=void 0===ce?null:ce,ae=le.show,ue=void 0===ae||ae,ve=c(le,["children","show"]),me=N.activeSlideProps,fe=void 0===me?{}:me,he=fe.className,pe=void 0===he?"":he,be=fe.style,we=void 0===be?{}:be,ye=c(fe,["className","style"]),xe=N.visibleSlideProps,Se=void 0===xe?{}:xe,Ee=Se.className,ge=void 0===Ee?"":Ee,Le=Se.style,Te=void 0===Le?{}:Le,Ie=c(Se,["className","style"]),ke=N.updateOnItemClick,Ce=void 0!==ke&&ke,Me=N.activeSlideIndex,We=N.onRequestChange,Pe=N.speed,Oe=void 0===Pe?0:Pe,Xe=N.delay,Ae=void 0===Xe?0:Xe,Ne=N.easing,Fe=void 0===Ne?"linear":Ne,Ve=N.itemsToShow,je=void 0===Ve?0:Ve,ze=N.itemsToScroll,Be=void 0===ze?1:ze,Re=N.children,De=N.onAfterChange,qe=N.autoplay,He=void 0!==qe&&qe,Ge=N.autoplayDirection,Je=void 0===Ge?"forward":Ge,Ke=N.disableNavIfAllVisible,Qe=void 0===Ke||Ke,Ue=N.hideNavIfAllVisible,Ye=void 0===Ue||Ue,Ze=N.centerMode,$e=void 0!==Ze&&Ze,_e=N.infinite,et=void 0===_e||_e,tt=N.disableNavIfEdgeVisible,nt=void 0===tt||tt,it=N.disableNavIfEdgeActive,rt=void 0===it||it,ot=N.dotsNav,dt=void 0===ot?{}:ot,lt=N.persistentChangeCallbacks,ct=void 0!==lt&<,st=N.autoplayDelay,at=void 0===st?0:st,ut=N.preventScrollOnSwipe,vt=void 0!==ut&&ut,mt=N.disableSwipeByMouse,ft=void 0!==mt&&mt,ht=N.disableSwipeByTouch,pt=void 0!==ht&&ht,bt=N.touchSwipeTreshold,wt=N.mouseSwipeTreshold,yt=N.swipeTreshold,xt=N.touchSwipeRatio,St=N.mouseSwipeRatio,Et=N.swipeRatio,gt=void 0===Et?1:Et,Lt=N.dirRTL,Tt=void 0!==Lt&&Lt,It=dt||{},kt=It.show,Ct=void 0!==kt&&kt,Mt=It.containerProps,Wt=void 0===Mt?{}:Mt,Pt=It.itemBtnProps,Ot=void 0===Pt?{}:Pt,Xt=It.activeItemBtnProps,At=void 0===Xt?{}:Xt,Nt=r.count(Re)-1,Ft=!!b&&(null===(u=g.current)||void 0===u?void 0:u.offsetWidth)>=(null===(v=L.current)||void 0===v?void 0:v.offsetWidth),Vt=Ye&&Ft,jt=Qe&&Ft,zt=Me-x==0||!Oe&&!Ae?"none":"transform ".concat(Oe,"ms ").concat(Fe," ").concat(Ae,"ms"),Bt=o((function(e){var t,n=e.correctionSlideIndex,i=e.prevCorrectionSlideIndex,r=e.curActiveSlideIndex,o=L.current.offsetWidth,d=L.current.children,l=d.length,c=et?a([],s(d),!1).slice(l/3-i,l/3-i+l/3):a([],s(d),!1),u=null===(t=c[r])||void 0===t?void 0:t.offsetWidth,v=je?c.reduce((function(e,t,n){return n>=r&&n<r+je||n<r&&n<r+je-c.length?e+t.offsetWidth:e}),0):g.current.offsetWidth,m=Math.min(v,g.current.offsetWidth),f=o-m,h=$e&&et?-(m-u)/2:0,p=et?o/3:0,b=n-r==0?0:"forward"===C.current&&r<n?p:"backward"===C.current&&r>n?-p:0,w=r-n!=0,y=function(e){var t=c.reduce((function(t,n,i){return i>=e?t:t+(n.offsetWidth||0)}),0);return et?t:Math.min(f,t)},x=w&&et?y(n):0,S=w||!et?y(r):0,E=jt?0:S-x+h+b+p,T="translateX(".concat(Tt?"":"-").concat(E,"px)"),I=et?p+h:Math.min(f,c.reduce((function(e,t,n){return n<r?e+t.offsetWidth:e}),0)),k=I+m,M=c.map((function(e,t){return{slideIndex:t,htmlElement:e}})),W=et?a(a(a(a([],s(c.slice(r).map((function(e,t){return{slideIndex:t+r,htmlElement:e}}))),!1),s(M),!1),s(M),!1),s(c.slice(0,r).map((function(e,t){return{slideIndex:t,htmlElement:e}}))),!1):M,P=W.reduce((function(e,t){var n=t.slideIndex,i=t.htmlElement.offsetWidth;return(e.summ>=I&&e.summ<k||e.summ+i>I&&e.summ+i<=k)&&e.items.push({slideIndex:n,isFullyVisible:e.summ+i<=k&&e.summ>=I}),e.summ+=i,e}),{summ:0,items:[]}),O=!!P.items.find((function(e){return 0===e.slideIndex})),X=!!P.items.find((function(e){return e.slideIndex===c.length-1}));return{slidesHTMLElements:c,innerMaxWidth:v,itemsListMaxTranslateX:f,activeSlideWidth:u,offsetCorrectionForCenterMode:h,offsetCorrectionForInfiniteMode:p,itemsListTranslateX:E,itemsListTransform:T,visibleSlides:P.items,isFirstSlideVisible:O,isLastSlideVisible:X}}),[$e,jt,et,je,Tt]),Rt=b?Bt({prevCorrectionSlideIndex:O.current,curActiveSlideIndex:Me,correctionSlideIndex:x}):{},Dt=Rt.innerMaxWidth,qt=void 0===Dt?0:Dt,Ht=Rt.itemsListMaxTranslateX,Gt=void 0===Ht?0:Ht,Jt=Rt.activeSlideWidth,Kt=void 0===Jt?0:Jt,Qt=Rt.offsetCorrectionForCenterMode,Ut=void 0===Qt?0:Qt,Yt=Rt.offsetCorrectionForInfiniteMode,Zt=void 0===Yt?0:Yt,$t=Rt.itemsListTranslateX,_t=void 0===$t?0:$t,en=Rt.itemsListTransform,tn=void 0===en?"none":en,nn=Rt.visibleSlides,rn=void 0===nn?[]:nn,on=o((function(e){var t;return"forward"===e?(t=Me+Be)>Nt?et?t-Nt-1:Nt:t:"backward"===e?(t=Me-Be)<0?et?Nt+1+t:0:t:Me}),[Me,Be,Nt,et]),dn=o((function(e,t){var n;if(C.current=t,L.current.style.transition=Oe||Ae?"transform ".concat(Oe,"ms ").concat(Fe," ").concat(Ae,"ms"):"none",e!==Me||ct){clearTimeout(M.current);var i=Bt({correctionSlideIndex:x,prevCorrectionSlideIndex:x,curActiveSlideIndex:e}),r=i.visibleSlides,o=i.isFirstSlideVisible,d=i.isLastSlideVisible,l=i.itemsListTransform;e!==Me&&(null===(n=L.current)||void 0===n?void 0:n.style.transform)===l&&(T.current=!0),L.current.style.transform=l,We(e,{visibleSlides:r,isFirstSlideVisible:o,isLastSlideVisible:d})}else L.current.style.transform="translateX(".concat(Tt?"":"-").concat(Ut+Zt+(et?0:_t),"px)")}),[ct,Me,Ut,Ae,Fe,Oe,We,Zt,et,_t,x,Bt,Tt]),ln=o((function(){He&&(clearTimeout(M.current),M.current=setTimeout((function(){dn(on(Je),Je)}),at||Ae))}),[He,Je,at,dn,on,Ae]),cn=o((function(){dn(on("backward"),"backward")}),[dn,on]),sn=o((function(e){S(Me),Z&&Z(e)}),[Me,Z]),an=o((function(){dn(on("forward"),"forward")}),[dn,on]),un=function(e,t,n){return e.map((function(e,i){var r=e.props,o=void 0===r?{}:r,d=o.className,s=void 0===d?"":d,a=o.onClick,u=void 0===a?null:a,v=o.style,m=void 0===v?{}:v,f=c(o,["className","onClick","style"]),h=c(e,["props"]),p=et?P.current>=A.length?"forward":"backward":i>=Me?"forward":"backward",b=i+t===Me,w=rn.find((function(e){return e.slideIndex===i+t})),y="".concat(s," ").concat(b?pe:""," ").concat(w?ge:"").trim()||void 0,x=l(l(l(l({},m),w?Te:{}),b?we:{}),{boxSizing:"border-box",margin:0}),S=!n&&Ce?function(e){var t=e.direction,n=e.index,i=e.onClick;return function(e){dn(n,t||(Me<n?"forward":"")||(Me>n?"backward":"")),i&&i(e)}}({direction:p,index:i+t,onClick:u}):u,E=l(l(l({role:"tabpanel",className:y,style:x,onClick:S},f),w?Ie:{}),b?ye:{});return P.current+=1,l({props:E},h)}))};return d((function(){var e=L.current;function t(e){var n;e.preventDefault(),e.stopPropagation(),null===(n=e.target)||void 0===n||n.removeEventListener("click",t)}function n(e){var t,n;k.current=!0;var i=!!(null===(t=e.touches)||void 0===t?void 0:t[0]),r=i?null===(n=e.touches)||void 0===n?void 0:n[0].clientX:e.clientX,o=(I.current-r)*((i?xt:St)||gt)+Ut+Zt+(et?0:_t),d=L.current.offsetWidth,l=Math.max(-o,-d);L.current.style.transition="none",L.current.style.transform="translateX(".concat((Tt?-1:1)*l,"px)")}function i(e){var r,o,d;if(document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i),k.current){null===(r=e.target)||void 0===r||r.addEventListener("click",t);var l=!!(null===(o=e.changedTouches)||void 0===o?void 0:o[0]),c=l?e.changedTouches[e.changedTouches.length-1].clientX:e.clientX,s=(I.current-c)*((l?xt:St)||gt),a=(l?bt:wt)||yt||Kt/2,u=s>a?{index:on("forward"),direction:"forward"}:s<-a?{index:on("backward"),direction:"backward"}:{index:Me,direction:"forward"};dn(u.index,u.direction)}else null===(d=e.target)||void 0===d||d.removeEventListener("click",t);I.current=0,k.current=!1}function r(e){var t,r;clearTimeout(M.current);var o=!!(null===(t=e.touches)||void 0===t?void 0:t[0]);I.current=o?null===(r=e.touches)||void 0===r?void 0:r[0].clientX:e.clientX,o?(document.addEventListener("touchmove",n),document.addEventListener("touchend",i)):(document.addEventListener("mousemove",n),document.addEventListener("mouseup",i))}return jt||(ft||null==e||e.addEventListener("mousedown",r),pt||null==e||e.addEventListener("touchstart",r,{passive:!0}),ft&&pt||null==e||e.addEventListener("dragstart",i)),function(){k.current=!1,I.current=0,null==e||e.removeEventListener("mousedown",r),null==e||e.removeEventListener("touchstart",r),null==e||e.removeEventListener("dragstart",i),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i)}}),[et,_t,tn,Ut,Zt,Me,Kt,on,dn,jt,ft,pt,bt,wt,yt,xt,St,gt,Tt]),d((function(){return Me!==x?(!Oe&&!Ae||T.current)&&(T.current=!1,S(Me)):(De&&De(Me,x),(et||"forward"===Je&&Me!==Nt||"backward"===Je&&0!==Me)&&ln()),function(){clearTimeout(M.current)}}),[x,Me,De,Oe,Ae,ln,et,Nt,Je]),d((function(){return b&&ln(),function(){clearTimeout(M.current)}}),[b]),d((function(){function e(){clearTimeout(W.current),clearTimeout(M.current),W.current=setTimeout((function(){b!==window.innerWidth&&w(0)}),400)}return b!==window.innerWidth&&w(window.innerWidth),window.addEventListener("resize",e),function(){clearTimeout(W.current),window.removeEventListener("resize",e)}}),[b]),P.current=0,O.current=x,e.createElement("div",l({style:l({display:"flex",flexFlow:"row wrap",boxSizing:"border-box",justifyContent:"center",width:"100%"},z)},B,{ref:E}),re&&!Vt&&e.createElement("button",l({},oe,{type:"button",onClick:(0===_t&&nt||0===Me&&rt)&&!et?void 0:cn,disabled:"boolean"==typeof oe.disabled?oe.disabled:!(!(0===_t&&nt||0===Me&&rt)||et)}),ne),e.createElement("div",l({},G,{style:l(l({width:"100%"},H),{display:"flex",boxSizing:"border-box",flexFlow:"row wrap",padding:"0",overflow:"hidden",maxWidth:qt?"".concat(qt,"px"):void 0,flex:qt?void 0:"1 0 auto"}),ref:g}),e.createElement("div",l({},$,{style:l(l({},U),{display:"flex",boxSizing:"border-box",outline:"none",transition:zt,transform:tn,touchAction:vt?"none":"auto"}),onTransitionEnd:Oe||Ae?sn:Z,tabIndex:-1,role:"presentation",ref:L}),et&&un(A.slice(x),x,jt),un(A,0,jt),et&&un(A,0,jt),et&&un(A.slice(0,x),0,jt))),ue&&!Vt&&e.createElement("button",l({},ve,{type:"button",onClick:(_t===Gt&&nt||Me===Nt&&rt)&&!et?void 0:an,disabled:"boolean"==typeof ve.disabled?ve.disabled:!(!(_t===Gt&&nt||Me===Nt&&rt)||et)}),se),!!Ct&&e.createElement("div",l({style:{width:"100%",display:"flex",justifyContent:"center"}},Wt),Array.from({length:Math.ceil(A.length/Be)}).map((function(t,n){return e.createElement("button",l({type:"button",key:n,title:"".concat(n)},Ot,Me>=n*Be&&Me<Math.min(Be*(n+1),Nt+1)?At:{},{onClick:function(){dn(Math.min(n*Be,A.length-1),Math.min(n*Be,A.length-1)>Me?"forward":"backward")}}))}))))}));export{u as default}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).ReactSimplyCarousel=t(e.React)}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},t.apply(this,arguments)};function n(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,o=n.call(e),d=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)d.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return d}function r(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;r<o;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}return"function"==typeof SuppressedError&&SuppressedError,e.memo((function(o){var d,l,s=o.responsiveProps,c=void 0===s?[]:s,a=n(o,["responsiveProps"]),u=i(e.useState(0),2),v=u[0],f=u[1],m=i(e.useState(a.activeSlideIndex),2),h=m[0],p=m[1],b=e.useRef(null),y=e.useRef(null),w=e.useRef(null),x=e.useRef(!1),S=e.useRef(0),E=e.useRef(!1),g=e.useRef(""),T=e.useRef(null),L=e.useRef(null),C=e.useRef(0),k=e.useRef(h),I=c.reduce((function(e,i){void 0===i&&(i={});var r=i.minWidth,o=void 0===r?0:r,d=i.maxWidth,l=void 0===d?null:d,s=n(i,["minWidth","maxWidth"]);return v>o&&(!l||v<=l)?t(t({},e),s):e}),a),M=e.Children.toArray(I.children),W=v?t(t({},I),{activeSlideIndex:Math.max(0,Math.min(I.activeSlideIndex,M.length-1)),itemsToShow:Math.min(M.length,I.itemsToShow||0),itemsToScroll:Math.min(M.length,I.itemsToScroll||1)}):a,R=W.containerProps,P=void 0===R?{}:R,O=P.style,X=void 0===O?{}:O,A=n(P,["style"]),N=W.innerProps,F=void 0===N?{}:N,V=F.style,j=void 0===V?{}:V,z=n(F,["style"]),B=W.itemsListProps,D=void 0===B?{}:B,q=D.style,H=void 0===q?{}:q,G=D.onTransitionEnd,J=void 0===G?void 0:G,K=n(D,["style","onTransitionEnd"]),Q=W.backwardBtnProps,U=void 0===Q?{}:Q,Y=U.children,Z=void 0===Y?null:Y,$=U.show,_=void 0===$||$,ee=n(U,["children","show"]),te=W.forwardBtnProps,ne=void 0===te?{}:te,ie=ne.children,re=void 0===ie?null:ie,oe=ne.show,de=void 0===oe||oe,le=n(ne,["children","show"]),se=W.activeSlideProps,ce=void 0===se?{}:se,ae=ce.className,ue=void 0===ae?"":ae,ve=ce.style,fe=void 0===ve?{}:ve,me=n(ce,["className","style"]),he=W.visibleSlideProps,pe=void 0===he?{}:he,be=pe.className,ye=void 0===be?"":be,we=pe.style,xe=void 0===we?{}:we,Se=n(pe,["className","style"]),Ee=W.updateOnItemClick,ge=void 0!==Ee&&Ee,Te=W.activeSlideIndex,Le=W.onRequestChange,Ce=W.speed,ke=void 0===Ce?0:Ce,Ie=W.delay,Me=void 0===Ie?0:Ie,We=W.easing,Re=void 0===We?"linear":We,Pe=W.itemsToShow,Oe=void 0===Pe?0:Pe,Xe=W.itemsToScroll,Ae=void 0===Xe?1:Xe,Ne=W.children,Fe=W.onAfterChange,Ve=W.autoplay,je=void 0!==Ve&&Ve,ze=W.autoplayDirection,Be=void 0===ze?"forward":ze,De=W.disableNavIfAllVisible,qe=void 0===De||De,He=W.hideNavIfAllVisible,Ge=void 0===He||He,Je=W.centerMode,Ke=void 0!==Je&&Je,Qe=W.infinite,Ue=void 0===Qe||Qe,Ye=W.disableNavIfEdgeVisible,Ze=void 0===Ye||Ye,$e=W.disableNavIfEdgeActive,_e=void 0===$e||$e,et=W.dotsNav,tt=void 0===et?{}:et,nt=W.persistentChangeCallbacks,it=void 0!==nt&&nt,rt=W.autoplayDelay,ot=void 0===rt?0:rt,dt=W.preventScrollOnSwipe,lt=void 0!==dt&&dt,st=W.disableSwipeByMouse,ct=void 0!==st&&st,at=W.disableSwipeByTouch,ut=void 0!==at&&at,vt=W.touchSwipeTreshold,ft=W.mouseSwipeTreshold,mt=W.swipeTreshold,ht=W.touchSwipeRatio,pt=W.mouseSwipeRatio,bt=W.swipeRatio,yt=void 0===bt?1:bt,wt=W.dirRTL,xt=void 0!==wt&&wt,St=tt||{},Et=St.show,gt=void 0!==Et&&Et,Tt=St.containerProps,Lt=void 0===Tt?{}:Tt,Ct=St.itemBtnProps,kt=void 0===Ct?{}:Ct,It=St.activeItemBtnProps,Mt=void 0===It?{}:It,Wt=e.Children.count(Ne)-1,Rt=!!v&&(null===(d=y.current)||void 0===d?void 0:d.offsetWidth)>=(null===(l=w.current)||void 0===l?void 0:l.offsetWidth),Pt=Ge&&Rt,Ot=qe&&Rt,Xt=Te-h==0||!ke&&!Me?"none":"transform ".concat(ke,"ms ").concat(Re," ").concat(Me,"ms"),At=e.useCallback((function(e){var t,n=e.correctionSlideIndex,o=e.prevCorrectionSlideIndex,d=e.curActiveSlideIndex,l=w.current.offsetWidth,s=w.current.children,c=s.length,a=Ue?r([],i(s),!1).slice(c/3-o,c/3-o+c/3):r([],i(s),!1),u=null===(t=a[d])||void 0===t?void 0:t.offsetWidth,v=Oe?a.reduce((function(e,t,n){return n>=d&&n<d+Oe||n<d&&n<d+Oe-a.length?e+t.offsetWidth:e}),0):y.current.offsetWidth,f=Math.min(v,y.current.offsetWidth),m=l-f,h=Ke&&Ue?-(f-u)/2:0,p=Ue?l/3:0,b=n-d==0?0:"forward"===g.current&&d<n?p:"backward"===g.current&&d>n?-p:0,x=d-n!=0,S=function(e){var t=a.reduce((function(t,n,i){return i>=e?t:t+(n.offsetWidth||0)}),0);return Ue?t:Math.min(m,t)},E=x&&Ue?S(n):0,T=x||!Ue?S(d):0,L=Ot?0:T-E+h+b+p,C="translateX(".concat(xt?"":"-").concat(L,"px)"),k=Ue?p+h:Math.min(m,a.reduce((function(e,t,n){return n<d?e+t.offsetWidth:e}),0)),I=k+f,M=a.map((function(e,t){return{slideIndex:t,htmlElement:e}})),W=Ue?r(r(r(r([],i(a.slice(d).map((function(e,t){return{slideIndex:t+d,htmlElement:e}}))),!1),i(M),!1),i(M),!1),i(a.slice(0,d).map((function(e,t){return{slideIndex:t,htmlElement:e}}))),!1):M,R=W.reduce((function(e,t){var n=t.slideIndex,i=t.htmlElement.offsetWidth;return(e.summ>=k&&e.summ<I||e.summ+i>k&&e.summ+i<=I)&&e.items.push({slideIndex:n,isFullyVisible:e.summ+i<=I&&e.summ>=k}),e.summ+=i,e}),{summ:0,items:[]}),P=!!R.items.find((function(e){return 0===e.slideIndex})),O=!!R.items.find((function(e){return e.slideIndex===a.length-1}));return{slidesHTMLElements:a,innerMaxWidth:v,itemsListMaxTranslateX:m,activeSlideWidth:u,offsetCorrectionForCenterMode:h,offsetCorrectionForInfiniteMode:p,itemsListTranslateX:L,itemsListTransform:C,visibleSlides:R.items,isFirstSlideVisible:P,isLastSlideVisible:O}}),[Ke,Ot,Ue,Oe,xt]),Nt=v?At({prevCorrectionSlideIndex:k.current,curActiveSlideIndex:Te,correctionSlideIndex:h}):{},Ft=Nt.innerMaxWidth,Vt=void 0===Ft?0:Ft,jt=Nt.itemsListMaxTranslateX,zt=void 0===jt?0:jt,Bt=Nt.activeSlideWidth,Dt=void 0===Bt?0:Bt,qt=Nt.offsetCorrectionForCenterMode,Ht=void 0===qt?0:qt,Gt=Nt.offsetCorrectionForInfiniteMode,Jt=void 0===Gt?0:Gt,Kt=Nt.itemsListTranslateX,Qt=void 0===Kt?0:Kt,Ut=Nt.itemsListTransform,Yt=void 0===Ut?"none":Ut,Zt=Nt.visibleSlides,$t=void 0===Zt?[]:Zt,_t=e.useCallback((function(e){var t;return"forward"===e?(t=Te+Ae)>Wt?Ue?t-Wt-1:Wt:t:"backward"===e?(t=Te-Ae)<0?Ue?Wt+1+t:0:t:Te}),[Te,Ae,Wt,Ue]),en=e.useCallback((function(e,t){var n;if(g.current=t,w.current.style.transition=ke||Me?"transform ".concat(ke,"ms ").concat(Re," ").concat(Me,"ms"):"none",e!==Te||it){clearTimeout(T.current);var i=At({correctionSlideIndex:h,prevCorrectionSlideIndex:h,curActiveSlideIndex:e}),r=i.visibleSlides,o=i.isFirstSlideVisible,d=i.isLastSlideVisible,l=i.itemsListTransform;e!==Te&&(null===(n=w.current)||void 0===n?void 0:n.style.transform)===l&&(x.current=!0),w.current.style.transform=l,Le(e,{visibleSlides:r,isFirstSlideVisible:o,isLastSlideVisible:d})}else w.current.style.transform="translateX(".concat(xt?"":"-").concat(Ht+Jt+(Ue?0:Qt),"px)")}),[it,Te,Ht,Me,Re,ke,Le,Jt,Ue,Qt,h,At,xt]),tn=e.useCallback((function(){je&&(clearTimeout(T.current),T.current=setTimeout((function(){en(_t(Be),Be)}),ot||Me))}),[je,Be,ot,en,_t,Me]),nn=e.useCallback((function(){en(_t("backward"),"backward")}),[en,_t]),rn=e.useCallback((function(e){p(Te),J&&J(e)}),[Te,J]),on=e.useCallback((function(){en(_t("forward"),"forward")}),[en,_t]),dn=function(e,i,r){return e.map((function(e,o){var d=e.props,l=void 0===d?{}:d,s=l.className,c=void 0===s?"":s,a=l.onClick,u=void 0===a?null:a,v=l.style,f=void 0===v?{}:v,m=n(l,["className","onClick","style"]),h=n(e,["props"]),p=Ue?C.current>=M.length?"forward":"backward":o>=Te?"forward":"backward",b=o+i===Te,y=$t.find((function(e){return e.slideIndex===o+i})),w="".concat(c," ").concat(b?ue:""," ").concat(y?ye:"").trim()||void 0,x=t(t(t(t({},f),y?xe:{}),b?fe:{}),{boxSizing:"border-box",margin:0}),S=!r&&ge?function(e){var t=e.direction,n=e.index,i=e.onClick;return function(e){en(n,t||(Te<n?"forward":"")||(Te>n?"backward":"")),i&&i(e)}}({direction:p,index:o+i,onClick:u}):u,E=t(t(t({role:"tabpanel",className:w,style:x,onClick:S},m),y?Se:{}),b?me:{});return C.current+=1,t({props:E},h)}))};return e.useEffect((function(){var e=w.current;function t(e){e.preventDefault(),e.stopPropagation()}function n(e){var t,n;E.current=!0;var i=!!(null===(t=e.touches)||void 0===t?void 0:t[0]),r=i?null===(n=e.touches)||void 0===n?void 0:n[0].clientX:e.clientX,o=(S.current-r)*((i?ht:pt)||yt)+Ht+Jt+(Ue?0:Qt),d=w.current.offsetWidth,l=Math.max(-o,-d);w.current.style.transition="none",w.current.style.transform="translateX(".concat((xt?-1:1)*l,"px)")}function i(e){var r,o,d;if(document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i),E.current){null===(r=e.target)||void 0===r||r.addEventListener("click",t);var l=!!(null===(o=e.changedTouches)||void 0===o?void 0:o[0]),s=l?e.changedTouches[e.changedTouches.length-1].clientX:e.clientX,c=(S.current-s)*((l?ht:pt)||yt),a=(l?vt:ft)||mt||Dt/2,u=c>a?{index:_t("forward"),direction:"forward"}:c<-a?{index:_t("backward"),direction:"backward"}:{index:Te,direction:"forward"};en(u.index,u.direction)}else null===(d=e.target)||void 0===d||d.removeEventListener("click",t);S.current=0,E.current=!1}function r(e){var t,r;clearTimeout(T.current);var o=!!(null===(t=e.touches)||void 0===t?void 0:t[0]);S.current=o?null===(r=e.touches)||void 0===r?void 0:r[0].clientX:e.clientX,o?(document.addEventListener("touchmove",n),document.addEventListener("touchend",i)):(document.addEventListener("mousemove",n),document.addEventListener("mouseup",i))}return Ot||(ct||null==e||e.addEventListener("mousedown",r),ut||null==e||e.addEventListener("touchstart",r,{passive:!0}),ct&&ut||null==e||e.addEventListener("dragstart",i)),function(){E.current=!1,S.current=0,null==e||e.removeEventListener("mousedown",r),null==e||e.removeEventListener("touchstart",r),null==e||e.removeEventListener("dragstart",i),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i)}}),[Ue,Qt,Yt,Ht,Jt,Te,Dt,_t,en,Ot,ct,ut,vt,ft,mt,ht,pt,yt,xt]),e.useEffect((function(){return Te!==h?(!ke&&!Me||x.current)&&(x.current=!1,p(Te)):(Fe&&Fe(Te,h),(Ue||"forward"===Be&&Te!==Wt||"backward"===Be&&0!==Te)&&tn()),function(){clearTimeout(T.current)}}),[h,Te,Fe,ke,Me,tn,Ue,Wt,Be]),e.useEffect((function(){return v&&tn(),function(){clearTimeout(T.current)}}),[v]),e.useEffect((function(){function e(){clearTimeout(L.current),clearTimeout(T.current),L.current=setTimeout((function(){v!==window.innerWidth&&f(0)}),400)}return v!==window.innerWidth&&f(window.innerWidth),window.addEventListener("resize",e),function(){clearTimeout(L.current),window.removeEventListener("resize",e)}}),[v]),C.current=0,k.current=h,e.createElement("div",t({style:t({display:"flex",flexFlow:"row wrap",boxSizing:"border-box",justifyContent:"center",width:"100%"},X)},A,{ref:b}),_&&!Pt&&e.createElement("button",t({},ee,{type:"button",onClick:(0===Qt&&Ze||0===Te&&_e)&&!Ue?void 0:nn,disabled:"boolean"==typeof ee.disabled?ee.disabled:!(!(0===Qt&&Ze||0===Te&&_e)||Ue)}),Z),e.createElement("div",t({},z,{style:t(t({width:"100%"},j),{display:"flex",boxSizing:"border-box",flexFlow:"row wrap",padding:"0",overflow:"hidden",maxWidth:Vt?"".concat(Vt,"px"):void 0,flex:Vt?void 0:"1 0 auto"}),ref:y}),e.createElement("div",t({},K,{style:t(t({},H),{display:"flex",boxSizing:"border-box",outline:"none",transition:Xt,transform:Yt,touchAction:lt?"none":"auto"}),onTransitionEnd:ke||Me?rn:J,tabIndex:-1,role:"presentation",ref:w}),Ue&&dn(M.slice(h),h,Ot),dn(M,0,Ot),Ue&&dn(M,0,Ot),Ue&&dn(M.slice(0,h),0,Ot))),de&&!Pt&&e.createElement("button",t({},le,{type:"button",onClick:(Qt===zt&&Ze||Te===Wt&&_e)&&!Ue?void 0:on,disabled:"boolean"==typeof le.disabled?le.disabled:!(!(Qt===zt&&Ze||Te===Wt&&_e)||Ue)}),re),!!gt&&e.createElement("div",t({style:{width:"100%",display:"flex",justifyContent:"center"}},Lt),Array.from({length:Math.ceil(M.length/Ae)}).map((function(n,i){return e.createElement("button",t({type:"button",key:i,title:"".concat(i)},kt,Te>=i*Ae&&Te<Math.min(Ae*(i+1),Wt+1)?Mt:{},{onClick:function(){en(Math.min(i*Ae,M.length-1),Math.min(i*Ae,M.length-1)>Te?"forward":"backward")}}))}))))}))})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).ReactSimplyCarousel=t(e.React)}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},t.apply(this,arguments)};function n(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,o=n.call(e),d=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)d.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return d}function r(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;r<o;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}return"function"==typeof SuppressedError&&SuppressedError,e.memo((function(o){var d,l,s=o.responsiveProps,c=void 0===s?[]:s,a=n(o,["responsiveProps"]),u=i(e.useState(0),2),v=u[0],f=u[1],m=i(e.useState(a.activeSlideIndex),2),h=m[0],p=m[1],b=e.useRef(null),y=e.useRef(null),w=e.useRef(null),x=e.useRef(!1),S=e.useRef(0),E=e.useRef(!1),g=e.useRef(""),T=e.useRef(null),L=e.useRef(null),C=e.useRef(0),k=e.useRef(h),I=c.reduce((function(e,i){void 0===i&&(i={});var r=i.minWidth,o=void 0===r?0:r,d=i.maxWidth,l=void 0===d?null:d,s=n(i,["minWidth","maxWidth"]);return v>o&&(!l||v<=l)?t(t({},e),s):e}),a),M=e.Children.toArray(I.children),W=v?t(t({},I),{activeSlideIndex:Math.max(0,Math.min(I.activeSlideIndex,M.length-1)),itemsToShow:Math.min(M.length,I.itemsToShow||0),itemsToScroll:Math.min(M.length,I.itemsToScroll||1)}):a,R=W.containerProps,P=void 0===R?{}:R,O=P.style,X=void 0===O?{}:O,A=n(P,["style"]),N=W.innerProps,F=void 0===N?{}:N,V=F.style,j=void 0===V?{}:V,z=n(F,["style"]),B=W.itemsListProps,D=void 0===B?{}:B,q=D.style,H=void 0===q?{}:q,G=D.onTransitionEnd,J=void 0===G?void 0:G,K=n(D,["style","onTransitionEnd"]),Q=W.backwardBtnProps,U=void 0===Q?{}:Q,Y=U.children,Z=void 0===Y?null:Y,$=U.show,_=void 0===$||$,ee=n(U,["children","show"]),te=W.forwardBtnProps,ne=void 0===te?{}:te,ie=ne.children,re=void 0===ie?null:ie,oe=ne.show,de=void 0===oe||oe,le=n(ne,["children","show"]),se=W.activeSlideProps,ce=void 0===se?{}:se,ae=ce.className,ue=void 0===ae?"":ae,ve=ce.style,fe=void 0===ve?{}:ve,me=n(ce,["className","style"]),he=W.visibleSlideProps,pe=void 0===he?{}:he,be=pe.className,ye=void 0===be?"":be,we=pe.style,xe=void 0===we?{}:we,Se=n(pe,["className","style"]),Ee=W.updateOnItemClick,ge=void 0!==Ee&&Ee,Te=W.activeSlideIndex,Le=W.onRequestChange,Ce=W.speed,ke=void 0===Ce?0:Ce,Ie=W.delay,Me=void 0===Ie?0:Ie,We=W.easing,Re=void 0===We?"linear":We,Pe=W.itemsToShow,Oe=void 0===Pe?0:Pe,Xe=W.itemsToScroll,Ae=void 0===Xe?1:Xe,Ne=W.children,Fe=W.onAfterChange,Ve=W.autoplay,je=void 0!==Ve&&Ve,ze=W.autoplayDirection,Be=void 0===ze?"forward":ze,De=W.disableNavIfAllVisible,qe=void 0===De||De,He=W.hideNavIfAllVisible,Ge=void 0===He||He,Je=W.centerMode,Ke=void 0!==Je&&Je,Qe=W.infinite,Ue=void 0===Qe||Qe,Ye=W.disableNavIfEdgeVisible,Ze=void 0===Ye||Ye,$e=W.disableNavIfEdgeActive,_e=void 0===$e||$e,et=W.dotsNav,tt=void 0===et?{}:et,nt=W.persistentChangeCallbacks,it=void 0!==nt&&nt,rt=W.autoplayDelay,ot=void 0===rt?0:rt,dt=W.preventScrollOnSwipe,lt=void 0!==dt&&dt,st=W.disableSwipeByMouse,ct=void 0!==st&&st,at=W.disableSwipeByTouch,ut=void 0!==at&&at,vt=W.touchSwipeTreshold,ft=W.mouseSwipeTreshold,mt=W.swipeTreshold,ht=W.touchSwipeRatio,pt=W.mouseSwipeRatio,bt=W.swipeRatio,yt=void 0===bt?1:bt,wt=W.dirRTL,xt=void 0!==wt&&wt,St=tt||{},Et=St.show,gt=void 0!==Et&&Et,Tt=St.containerProps,Lt=void 0===Tt?{}:Tt,Ct=St.itemBtnProps,kt=void 0===Ct?{}:Ct,It=St.activeItemBtnProps,Mt=void 0===It?{}:It,Wt=e.Children.count(Ne)-1,Rt=!!v&&(null===(d=y.current)||void 0===d?void 0:d.offsetWidth)>=(null===(l=w.current)||void 0===l?void 0:l.offsetWidth),Pt=Ge&&Rt,Ot=qe&&Rt,Xt=Te-h==0||!ke&&!Me?"none":"transform ".concat(ke,"ms ").concat(Re," ").concat(Me,"ms"),At=e.useCallback((function(e){var t,n=e.correctionSlideIndex,o=e.prevCorrectionSlideIndex,d=e.curActiveSlideIndex,l=w.current.offsetWidth,s=w.current.children,c=s.length,a=Ue?r([],i(s),!1).slice(c/3-o,c/3-o+c/3):r([],i(s),!1),u=null===(t=a[d])||void 0===t?void 0:t.offsetWidth,v=Oe?a.reduce((function(e,t,n){return n>=d&&n<d+Oe||n<d&&n<d+Oe-a.length?e+t.offsetWidth:e}),0):y.current.offsetWidth,f=Math.min(v,y.current.offsetWidth),m=l-f,h=Ke&&Ue?-(f-u)/2:0,p=Ue?l/3:0,b=n-d==0?0:"forward"===g.current&&d<n?p:"backward"===g.current&&d>n?-p:0,x=d-n!=0,S=function(e){var t=a.reduce((function(t,n,i){return i>=e?t:t+(n.offsetWidth||0)}),0);return Ue?t:Math.min(m,t)},E=x&&Ue?S(n):0,T=x||!Ue?S(d):0,L=Ot?0:T-E+h+b+p,C="translateX(".concat(xt?"":"-").concat(L,"px)"),k=Ue?p+h:Math.min(m,a.reduce((function(e,t,n){return n<d?e+t.offsetWidth:e}),0)),I=k+f,M=a.map((function(e,t){return{slideIndex:t,htmlElement:e}})),W=Ue?r(r(r(r([],i(a.slice(d).map((function(e,t){return{slideIndex:t+d,htmlElement:e}}))),!1),i(M),!1),i(M),!1),i(a.slice(0,d).map((function(e,t){return{slideIndex:t,htmlElement:e}}))),!1):M,R=W.reduce((function(e,t){var n=t.slideIndex,i=t.htmlElement.offsetWidth;return(e.summ>=k&&e.summ<I||e.summ+i>k&&e.summ+i<=I)&&e.items.push({slideIndex:n,isFullyVisible:e.summ+i<=I&&e.summ>=k}),e.summ+=i,e}),{summ:0,items:[]}),P=!!R.items.find((function(e){return 0===e.slideIndex})),O=!!R.items.find((function(e){return e.slideIndex===a.length-1}));return{slidesHTMLElements:a,innerMaxWidth:v,itemsListMaxTranslateX:m,activeSlideWidth:u,offsetCorrectionForCenterMode:h,offsetCorrectionForInfiniteMode:p,itemsListTranslateX:L,itemsListTransform:C,visibleSlides:R.items,isFirstSlideVisible:P,isLastSlideVisible:O}}),[Ke,Ot,Ue,Oe,xt]),Nt=v?At({prevCorrectionSlideIndex:k.current,curActiveSlideIndex:Te,correctionSlideIndex:h}):{},Ft=Nt.innerMaxWidth,Vt=void 0===Ft?0:Ft,jt=Nt.itemsListMaxTranslateX,zt=void 0===jt?0:jt,Bt=Nt.activeSlideWidth,Dt=void 0===Bt?0:Bt,qt=Nt.offsetCorrectionForCenterMode,Ht=void 0===qt?0:qt,Gt=Nt.offsetCorrectionForInfiniteMode,Jt=void 0===Gt?0:Gt,Kt=Nt.itemsListTranslateX,Qt=void 0===Kt?0:Kt,Ut=Nt.itemsListTransform,Yt=void 0===Ut?"none":Ut,Zt=Nt.visibleSlides,$t=void 0===Zt?[]:Zt,_t=e.useCallback((function(e){var t;return"forward"===e?(t=Te+Ae)>Wt?Ue?t-Wt-1:Wt:t:"backward"===e?(t=Te-Ae)<0?Ue?Wt+1+t:0:t:Te}),[Te,Ae,Wt,Ue]),en=e.useCallback((function(e,t){var n;if(g.current=t,w.current.style.transition=ke||Me?"transform ".concat(ke,"ms ").concat(Re," ").concat(Me,"ms"):"none",e!==Te||it){clearTimeout(T.current);var i=At({correctionSlideIndex:h,prevCorrectionSlideIndex:h,curActiveSlideIndex:e}),r=i.visibleSlides,o=i.isFirstSlideVisible,d=i.isLastSlideVisible,l=i.itemsListTransform;e!==Te&&(null===(n=w.current)||void 0===n?void 0:n.style.transform)===l&&(x.current=!0),w.current.style.transform=l,Le(e,{visibleSlides:r,isFirstSlideVisible:o,isLastSlideVisible:d})}else w.current.style.transform="translateX(".concat(xt?"":"-").concat(Ht+Jt+(Ue?0:Qt),"px)")}),[it,Te,Ht,Me,Re,ke,Le,Jt,Ue,Qt,h,At,xt]),tn=e.useCallback((function(){je&&(clearTimeout(T.current),T.current=setTimeout((function(){en(_t(Be),Be)}),ot||Me))}),[je,Be,ot,en,_t,Me]),nn=e.useCallback((function(){en(_t("backward"),"backward")}),[en,_t]),rn=e.useCallback((function(e){p(Te),J&&J(e)}),[Te,J]),on=e.useCallback((function(){en(_t("forward"),"forward")}),[en,_t]),dn=function(e,i,r){return e.map((function(e,o){var d=e.props,l=void 0===d?{}:d,s=l.className,c=void 0===s?"":s,a=l.onClick,u=void 0===a?null:a,v=l.style,f=void 0===v?{}:v,m=n(l,["className","onClick","style"]),h=n(e,["props"]),p=Ue?C.current>=M.length?"forward":"backward":o>=Te?"forward":"backward",b=o+i===Te,y=$t.find((function(e){return e.slideIndex===o+i})),w="".concat(c," ").concat(b?ue:""," ").concat(y?ye:"").trim()||void 0,x=t(t(t(t({},f),y?xe:{}),b?fe:{}),{boxSizing:"border-box",margin:0}),S=!r&&ge?function(e){var t=e.direction,n=e.index,i=e.onClick;return function(e){en(n,t||(Te<n?"forward":"")||(Te>n?"backward":"")),i&&i(e)}}({direction:p,index:o+i,onClick:u}):u,E=t(t(t({role:"tabpanel",className:w,style:x,onClick:S},m),y?Se:{}),b?me:{});return C.current+=1,t({props:E},h)}))};return e.useEffect((function(){var e=w.current;function t(e){var n;e.preventDefault(),e.stopPropagation(),null===(n=e.target)||void 0===n||n.removeEventListener("click",t)}function n(e){var t,n;E.current=!0;var i=!!(null===(t=e.touches)||void 0===t?void 0:t[0]),r=i?null===(n=e.touches)||void 0===n?void 0:n[0].clientX:e.clientX,o=(S.current-r)*((i?ht:pt)||yt)+Ht+Jt+(Ue?0:Qt),d=w.current.offsetWidth,l=Math.max(-o,-d);w.current.style.transition="none",w.current.style.transform="translateX(".concat((xt?-1:1)*l,"px)")}function i(e){var r,o,d;if(document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i),E.current){null===(r=e.target)||void 0===r||r.addEventListener("click",t);var l=!!(null===(o=e.changedTouches)||void 0===o?void 0:o[0]),s=l?e.changedTouches[e.changedTouches.length-1].clientX:e.clientX,c=(S.current-s)*((l?ht:pt)||yt),a=(l?vt:ft)||mt||Dt/2,u=c>a?{index:_t("forward"),direction:"forward"}:c<-a?{index:_t("backward"),direction:"backward"}:{index:Te,direction:"forward"};en(u.index,u.direction)}else null===(d=e.target)||void 0===d||d.removeEventListener("click",t);S.current=0,E.current=!1}function r(e){var t,r;clearTimeout(T.current);var o=!!(null===(t=e.touches)||void 0===t?void 0:t[0]);S.current=o?null===(r=e.touches)||void 0===r?void 0:r[0].clientX:e.clientX,o?(document.addEventListener("touchmove",n),document.addEventListener("touchend",i)):(document.addEventListener("mousemove",n),document.addEventListener("mouseup",i))}return Ot||(ct||null==e||e.addEventListener("mousedown",r),ut||null==e||e.addEventListener("touchstart",r,{passive:!0}),ct&&ut||null==e||e.addEventListener("dragstart",i)),function(){E.current=!1,S.current=0,null==e||e.removeEventListener("mousedown",r),null==e||e.removeEventListener("touchstart",r),null==e||e.removeEventListener("dragstart",i),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",i)}}),[Ue,Qt,Yt,Ht,Jt,Te,Dt,_t,en,Ot,ct,ut,vt,ft,mt,ht,pt,yt,xt]),e.useEffect((function(){return Te!==h?(!ke&&!Me||x.current)&&(x.current=!1,p(Te)):(Fe&&Fe(Te,h),(Ue||"forward"===Be&&Te!==Wt||"backward"===Be&&0!==Te)&&tn()),function(){clearTimeout(T.current)}}),[h,Te,Fe,ke,Me,tn,Ue,Wt,Be]),e.useEffect((function(){return v&&tn(),function(){clearTimeout(T.current)}}),[v]),e.useEffect((function(){function e(){clearTimeout(L.current),clearTimeout(T.current),L.current=setTimeout((function(){v!==window.innerWidth&&f(0)}),400)}return v!==window.innerWidth&&f(window.innerWidth),window.addEventListener("resize",e),function(){clearTimeout(L.current),window.removeEventListener("resize",e)}}),[v]),C.current=0,k.current=h,e.createElement("div",t({style:t({display:"flex",flexFlow:"row wrap",boxSizing:"border-box",justifyContent:"center",width:"100%"},X)},A,{ref:b}),_&&!Pt&&e.createElement("button",t({},ee,{type:"button",onClick:(0===Qt&&Ze||0===Te&&_e)&&!Ue?void 0:nn,disabled:"boolean"==typeof ee.disabled?ee.disabled:!(!(0===Qt&&Ze||0===Te&&_e)||Ue)}),Z),e.createElement("div",t({},z,{style:t(t({width:"100%"},j),{display:"flex",boxSizing:"border-box",flexFlow:"row wrap",padding:"0",overflow:"hidden",maxWidth:Vt?"".concat(Vt,"px"):void 0,flex:Vt?void 0:"1 0 auto"}),ref:y}),e.createElement("div",t({},K,{style:t(t({},H),{display:"flex",boxSizing:"border-box",outline:"none",transition:Xt,transform:Yt,touchAction:lt?"none":"auto"}),onTransitionEnd:ke||Me?rn:J,tabIndex:-1,role:"presentation",ref:w}),Ue&&dn(M.slice(h),h,Ot),dn(M,0,Ot),Ue&&dn(M,0,Ot),Ue&&dn(M.slice(0,h),0,Ot))),de&&!Pt&&e.createElement("button",t({},le,{type:"button",onClick:(Qt===zt&&Ze||Te===Wt&&_e)&&!Ue?void 0:on,disabled:"boolean"==typeof le.disabled?le.disabled:!(!(Qt===zt&&Ze||Te===Wt&&_e)||Ue)}),re),!!gt&&e.createElement("div",t({style:{width:"100%",display:"flex",justifyContent:"center"}},Lt),Array.from({length:Math.ceil(M.length/Ae)}).map((function(n,i){return e.createElement("button",t({type:"button",key:i,title:"".concat(i)},kt,Te>=i*Ae&&Te<Math.min(Ae*(i+1),Wt+1)?Mt:{},{onClick:function(){en(Math.min(i*Ae,M.length-1),Math.min(i*Ae,M.length-1)>Te?"forward":"backward")}}))}))))}))})); |
{ | ||
"name": "react-simply-carousel", | ||
"version": "9.1.1", | ||
"version": "9.1.2", | ||
"description": "A simple, lightweight, fully controlled isomorphic (with SSR support) React.js carousel component. Touch enabled and responsive. With support for autoplay and infinity options. Fully customizable", | ||
@@ -62,3 +62,3 @@ "files": [ | ||
"lint-staged": ">=13.1.0", | ||
"prettier": "3.0.3", | ||
"prettier": "3.2.5", | ||
"react": "^18.2.0", | ||
@@ -68,3 +68,3 @@ "react-dom": "^18.2.0", | ||
"tslib": "^2.5.0", | ||
"typescript": "5.0.2" | ||
"typescript": "5.3.3" | ||
}, | ||
@@ -71,0 +71,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54645
169
1