@trendyol-js/react-carousel
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function i(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var o="styles-module_carousel-base__3keqD",s="styles-module_item-provider__YgMwz",a="styles-module_item-container__a8zaY",l="styles-module_item-tracker__3bypy",u="styles-module_carousel-arrow__26sRw";i(".styles-module_carousel-base__3keqD {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\toutline: none;\n\tposition: relative;\n}\n\n.styles-module_item-provider__YgMwz {\n\toverflow: hidden;\n\twidth: 100%;\n\tcursor: pointer;\n}\n\n.styles-module_item-container__a8zaY img {\n\t-webkit-user-select: none;\n\t user-select: none;\n\t-webkit-user-drag: none;\n}\n\n.styles-module_item-tracker__3bypy {\n\theight: 100%;\n\tdisplay: flex;\n}\n\n.styles-module_carousel-arrow__26sRw {\n\tz-index: 1;\n}\n");var c,f=function(e){return n.createElement("button",{className:u,onClick:e.onClick,"data-direction":e.direction})};!function(e){e[e.Right=-1]="Right",e[e.Left=1]="Left"}(c||(c={}));var d=function(){function e(e,t){this.arr=e,this.currentIndex=t}return e.prototype.next=function(){var e=this.currentIndex,t=this.arr;return this.currentIndex=e<t.length-1?e+1:0,this.current()},e.prototype.prev=function(){var e=this.currentIndex,t=this.arr;return this.currentIndex=e>0&&e<t.length?e-1:t.length-1,this.current()},e.prototype.current=function(){return this.arr[this.currentIndex]},e}(),h=function(e,t,n){return n*e*t},g=function(e){var t=e.itemCount,n=e.itemsToShow,r=e.infinite,i=e.current,o=e.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=t>n;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+n<t}},m=function(e,t,n){if(!n)return e;for(var r=Array.from(e),i=new d(e,0),o=0;o<t;o++)r.unshift(i.prev());return r};function v(e){return e.nativeEvent instanceof MouseEvent?e.nativeEvent.pageX:e.nativeEvent instanceof TouchEvent?e.nativeEvent.changedTouches[0].pageX:0}function p(e,t,n,r,i){if(n&&n.length<t.length)return m(t,r,i);var o=e.map((function(e){return t.find((function(t){return e.key===t.key}))}));return o.some((function(e){return void 0===e}))?m(t,r,i):o}var w=function(e){var n=t.useState("undefined"==typeof window?0:window.innerWidth),r=n[0],i=n[1];t.useLayoutEffect((function(){var t=function(){var t=r-window.innerWidth;i(window.innerWidth),e(t)};return window.addEventListener("resize",t),function(){return window.removeEventListener("resize",t)}}),[])},y=function(e){var i=t.useState(200),o=i[0],u=i[1],f=t.useCallback((function(t){if(null!==t){var n=t.getBoundingClientRect().width/e.show;u(n),e.widthCallBack(n)}}),[o]);e.responsive&&w((function(e){u(o-e)}));var d=t.useState({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),h=d[0],g=d[1],m=function(t){t.persist(),g(r(r({},h),{isDown:!0,start:v(t),initial:e.transform,finished:!1}))},p=function(t){if(t.persist(),!h.finished){if(Math.abs(h.drag)<o*e.swipeOn)return e.dragCallback(e.transform),g({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});e.slideCallback(h.drag>0?c.Right:c.Left),g(r(r({},h),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},y=function(t){if(t.persist(),h.isDown){var n=v(t);g(r(r({},h),{drag:h.start-n,pointers:Math.abs(h.start-n)<e.triggerClickOn}))}},_=e.swiping?{onTouchCancel:p,onTouchEnd:p,onTouchMove:y,onTouchStart:m,onMouseDown:m,onMouseLeave:p,onMouseUp:p,onMouseMove:y}:{};return n.createElement("div",{ref:f,className:s},n.createElement("div",r({"data-testid":"trackList"},_,{className:l,style:{transform:"translateX("+(e.transform-h.drag)+"px)",transition:"transform "+e.transition+"s ease 0s",width:o*e.items.length}}),e.items.map((function(e,t){return n.createElement("div",{key:t,style:{width:o,pointerEvents:h.pointers?"all":"none"},className:a},e)}))))},_={children:[],show:1,slide:1,transition:.5,swiping:!1,swipeOn:1,responsive:!1,infinite:!0,className:"",useArrowKeys:!1,a11y:{},dynamic:!1,paginationCallback:null,pageCount:0,rightArrow:null,leftArrow:null,autoSwipe:null,navigation:null,triggerClickOn:Number.MIN_SAFE_INTEGER,hideArrows:!1,onLeftArrowClick:function(){return null},onRightArrowClick:function(){return null}},k="styles-module_carousel-navigation__1g_vs";i(".styles-module_carousel-navigation__1g_vs {\n\tdisplay: flex;\n\tposition: absolute;\n\tbottom: 0;\n}\n");var C=function(e){var t=e.items,r=e.current,i=e.onClick,o=e.factory;return n.createElement("div",{className:k},t.map((function(e,t){return n.createElement("div",{onMouseOver:function(){return i(t)},key:t},o(r===t))})))},b="styles-module_sliderBase__swkx1",L="styles-module_slider__o0fqa",E="styles-module_sliding__3T6T6";i(".styles-module_sliderBase__swkx1 {\n\twidth: 100%;\n\tposition: relative;\n}\n\n.styles-module_slider__o0fqa {\n\tdisplay: flex;\n\toverflow-x: auto;\n\tscrollbar-width: none; /* Firefox 64 */\n\t-ms-overflow-style: none; /* Internet Explorer 11 */\n}\n\n.styles-module_slider__o0fqa::-webkit-scrollbar {\n\t/** WebKit */\n\tdisplay: none;\n}\n\n.styles-module_slider__o0fqa > * {\n\tflex: 0 0 auto;\n}\n\n.styles-module_sliding__3T6T6 > * {\n\tpointer-events: none;\n}\n");var R={children:[],className:"",leftIcon:null,rightIcon:null,triggerClickOn:3};exports.Carousel=function(e){var i,s,a,l,u=r(r({},_),e),v=m(u.children,u.navigation?u.children.length-1:u.slide,u.infinite),w=t.useState(v),k=w[0],b=w[1],L=t.useRef(v),E=t.useState(0),R=E[0],S=E[1],x=t.useState({transform:0,transition:0,isSliding:!1}),A=x[0],M=x[1],T=t.useState(0),N=T[0],I=T[1],O=t.useState(g({itemCount:u.children.length,itemsToShow:u.show,infinite:u.infinite,current:N,hideArrows:u.hideArrows})),D=O[0],W=O[1],z=(a=e.children,l=t.useRef(),t.useEffect((function(){l.current=a})),l.current),X=t.useState(0),q=X[0],B=X[1],j=t.useRef(!1),K=t.useRef(null),Y=t.useRef(),P="function"==typeof u.navigation;u.dynamic&&t.useEffect((function(){var e=p(L.current,u.children,z,u.slide,u.infinite);b(e),L.current=e,q<u.pageCount&&z&&(null==z?void 0:z.length)<u.children.length&&(U(c.Right),B(q+1))}),[u.children]),t.useEffect((function(){F()}),[]);var F=function(){clearTimeout(Y.current),K&&"number"==typeof u.autoSwipe&&u.autoSwipe>u.transition&&(Y.current=setTimeout((function(){K.current&&K.current.click()}),u.autoSwipe))},U=function(e,t){if(!(A.isSliding||e===c.Right&&!D.right||e===c.Left&&!D.left)){if(u.paginationCallback&&e===c.Right&&q<u.pageCount-1&&!j.current)return j.current=!0,void u.paginationCallback(e);var n=u.children,r=function(e,t,n,r){var i=e-r*t;return i<0?n+i:n<=i?i-n:i}(N,u.slide,n.length,e),i="number"==typeof t?t-N:-1*e,o=u.infinite?P?function(e,t,n,r,i,o){var s=function(e,t,n){var r=e+t>=n.length?e+t-n.length:e+t;return r<0?n.length+r:r}(n,i,e),a=Math.floor(t.length/2),l=new d(e,s),u=Array.from(t);switch(+o){case c.Left:for(var f=0;f<a;f++){var h=a-(Math.abs(i)+f)-r;(h<0||!u[h])&&u.unshift(l.current()),l.prev()}break;case c.Right:for(f=0;f<a;f++)u[a+i+f+r]||u.push(l.current()),l.next()}return u}(n,k,r,u.show,i,e):function(e,t,n,r,i,o){var s=new d(e,n),a=Array.from(t);switch(+o){case c.Left:for(var l=i;l>=0;l--)(i-l<0||!a[l-i])&&a.unshift(s.current()),s.prev();break;case c.Right:for(l=0;l<r+i;l++)a[2*i+l]||a.push(s.current()),s.next()}return a}(n,k,r,u.show,u.slide,e):k;u.infinite&&e===c.Right&&(b(o),L.current=o),M({transform:A.transform+Math.abs(i)*h(R,u.slide,e),transition:u.transition,isSliding:!0}),I(P&&"number"==typeof t?t:r),W(g({itemCount:n.length,itemsToShow:u.show,infinite:u.infinite,current:r,hideArrows:u.hideArrows})),setTimeout((function(){if(u.infinite){var n=P?function(e,t,n){return n===c.Left?e.slice(0,t):e.slice(t)}(e===c.Right?L.current:o,function(e,t,n,r){return"number"==typeof e?r===c.Right?e-t+1:n:-1*r}(t,r,i,e),e):function(e,t,n){return n===c.Left?e.slice(0,-1*t):e.slice(t)}(e===c.Right?L.current:o,u.slide,e);b(n),L.current=n}M({transform:u.infinite?h(R,u.navigation?u.children.length-1:u.slide,c.Right):A.transform+h(R,u.slide,e),transition:0,isSliding:!1}),F()}),1e3*u.transition),j.current=!1}};return n.createElement("div",r({},u.a11y,{"data-testid":"carousel",tabIndex:0},u.useArrowKeys?{onKeyDown:function(e){37===e.keyCode?U(c.Left):39===e.keyCode&&U(c.Right)}}:{},{className:o+" "+u.className}),D.left&&n.createElement("div",{onClick:function(){U(c.Left),u.onLeftArrowClick&&u.onLeftArrowClick()}},null!==(i=u.leftArrow)&&void 0!==i?i:n.createElement(f,{direction:"left"})),n.createElement(y,r({},u,{transition:A.transition,items:L.current,transform:A.transform,slideCallback:function(e){U(e)},dragCallback:function(e){M({transform:e,transition:u.transition,isSliding:!1}),setTimeout((function(){return M(r(r({},A),{transition:0}))}),1e3*u.transition)},widthCallBack:function(e){S(e),M({transform:u.infinite?h(e,u.navigation?u.children.length-1:u.slide,c.Right):0,transition:0,isSliding:!1})}})),D.right&&n.createElement("div",{onClick:function(){U(c.Right),u.onRightArrowClick&&u.onRightArrowClick()},ref:K},null!==(s=u.rightArrow)&&void 0!==s?s:n.createElement(f,{direction:"right"})),P&&n.createElement(C,{factory:u.navigation,items:u.children,current:N,onClick:function(e){N!==e&&U(e>N?c.Right:c.Left,e)}}))},exports.ScrollingCarousel=function(e){var i=r(r({},R),e),o=i.children,s=i.className,a=i.leftIcon,l=i.rightIcon,u=i.triggerClickOn,f=t.useRef(null),d=t.useState(!1),h=d[0],g=d[1],m=t.useState({startX:0,scrollLeft:0}),v=m[0],p=m[1],w=function(){var e=f.current;return{left:!!e&&e.scrollLeft>0,right:!!e&&e.scrollWidth>e.scrollLeft+e.offsetWidth}},y=t.useState(w()),_=y[0],k=y[1],C=function(e){k(w())},S=t.useCallback((function(e){null!==e&&(Object.defineProperty(f,"current",{value:e}),k(w()),e.addEventListener("scroll",C))}),[f,o]),x=function(e){g(!1),k(w()),f.current.classList.remove(E)},A=function(e){var t=function(e){for(var t,n,r=f.current,i=e===c.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,a=Array.from(r.children);s<a.length;s++){var l=a[s],u=(t=l,n=void 0,n=getComputedStyle(t),t.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=u)>=i){var d=e===c.Left?o-i:u;return(r.offsetWidth-d)*e}}return r.offsetWidth}(e),n=f.current.scrollLeft;M(500,t,n)},M=function(e,t,n){for(var r=0,i=0;r<=e;i++)window.setTimeout(T,r,i*t/100+n),r+=e/100},T=function(e){f.current.scrollLeft=e},N=function(e,t,r){return n.createElement("div",{"data-arrow":t,onClick:function(){return A(e)}},null!=r?r:n.createElement("button",null))};return n.createElement("div",{className:b+" "+s,"data-testid":"carousel"},_.left&&a&&N(c.Right,"left",a),_.right&&l&&N(c.Left,"right",l),n.createElement("div",{"data-testid":"sliderList",ref:S,onMouseDown:function(e){g(!0),p({startX:e.pageX-f.current.offsetLeft,scrollLeft:f.current.scrollLeft})},onMouseLeave:x,onMouseUp:x,onMouseMove:function(e){if(h){e.preventDefault();var t=e.pageX-f.current.offsetLeft-v.startX;Math.abs(t)>u&&f.current.classList.add(E),f.current.scrollLeft=v.scrollLeft-t}},className:L},o))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function i(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var o="styles-module_carousel-base__3keqD",s="styles-module_item-provider__YgMwz",a="styles-module_item-container__a8zaY",l="styles-module_item-tracker__3bypy",u="styles-module_carousel-arrow__26sRw";i(".styles-module_carousel-base__3keqD {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\toutline: none;\n\tposition: relative;\n}\n\n.styles-module_item-provider__YgMwz {\n\toverflow: hidden;\n\twidth: 100%;\n\tcursor: pointer;\n}\n\n.styles-module_item-container__a8zaY img {\n\t-webkit-user-select: none;\n\t user-select: none;\n\t-webkit-user-drag: none;\n}\n\n.styles-module_item-tracker__3bypy {\n\theight: 100%;\n\tdisplay: flex;\n}\n\n.styles-module_carousel-arrow__26sRw {\n\tz-index: 1;\n}\n");var c,f=function(e){return n.createElement("button",{className:u,onClick:e.onClick,"data-direction":e.direction})};!function(e){e[e.Right=-1]="Right",e[e.Left=1]="Left"}(c||(c={}));var d=function(){function e(e,t){this.arr=e,this.currentIndex=t}return e.prototype.next=function(){var e=this.currentIndex,t=this.arr;return this.currentIndex=e<t.length-1?e+1:0,this.current()},e.prototype.prev=function(){var e=this.currentIndex,t=this.arr;return this.currentIndex=e>0&&e<t.length?e-1:t.length-1,this.current()},e.prototype.current=function(){return this.arr[this.currentIndex]},e}(),h=function(e,t,n){return n*e*t},g=function(e){var t=e.itemCount,n=e.itemsToShow,r=e.infinite,i=e.current,o=e.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=t>n;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+n<t}},m=function(e,t,n){if(!n)return e;for(var r=Array.from(e),i=new d(e,0),o=0;o<t;o++)r.unshift(i.prev());return r};function v(e){return e.nativeEvent instanceof MouseEvent?e.nativeEvent.pageX:e.nativeEvent instanceof TouchEvent?e.nativeEvent.changedTouches[0].pageX:0}function w(e,t,n,r,i){if(n&&n.length<t.length)return m(t,r,i);var o=e.map((function(e){return t.find((function(t){return e.key===t.key}))}));return o.some((function(e){return void 0===e}))?m(t,r,i):o}var p=function(e){var n=t.useState("undefined"==typeof window?0:window.innerWidth),r=n[0],i=n[1];t.useLayoutEffect((function(){var t=function(){var t=r-window.innerWidth;i(window.innerWidth),e(t)};return window.addEventListener("resize",t),function(){return window.removeEventListener("resize",t)}}),[])},y=function(e){var i=t.useState(200),o=i[0],u=i[1],f=t.useCallback((function(t){if(null!==t){var n=t.getBoundingClientRect().width/e.show;u(n),e.widthCallBack(n)}}),[o]);e.responsive&&p((function(e){u(o-e)}));var d=t.useState({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),h=d[0],g=d[1],m=function(t){t.persist(),g(r(r({},h),{isDown:!0,start:v(t),initial:e.transform,finished:!1}))},w=function(t){if(t.persist(),!h.finished){if(Math.abs(h.drag)<o*e.swipeOn)return e.dragCallback(e.transform),g({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});e.slideCallback(h.drag>0?c.Right:c.Left),g(r(r({},h),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},y=function(t){if(t.persist(),h.isDown){var n=v(t);g(r(r({},h),{drag:h.start-n,pointers:Math.abs(h.start-n)<e.triggerClickOn}))}},_=e.swiping?{onTouchCancel:w,onTouchEnd:w,onTouchMove:y,onTouchStart:m,onMouseDown:m,onMouseLeave:w,onMouseUp:w,onMouseMove:y}:{};return n.createElement("div",{ref:f,className:s},n.createElement("div",r({"data-testid":"trackList"},_,{className:l,style:{transform:"translateX("+(e.transform-h.drag)+"px)",transition:"transform "+e.transition+"s ease 0s",width:o*e.items.length}}),e.items.map((function(e,t){return n.createElement("div",{key:t,style:{width:o,pointerEvents:h.pointers?"all":"none"},className:a},e)}))))},_={children:[],show:1,slide:1,transition:.5,swiping:!1,swipeOn:1,responsive:!1,infinite:!0,className:"",useArrowKeys:!1,a11y:{},dynamic:!1,paginationCallback:null,pageCount:0,rightArrow:null,leftArrow:null,arrowLogicOnEndOfPage:"hide",autoSwipe:null,navigation:null,triggerClickOn:Number.MIN_SAFE_INTEGER,hideArrows:!1,onLeftArrowClick:function(){return null},onRightArrowClick:function(){return null}},b="styles-module_carousel-navigation__1g_vs";i(".styles-module_carousel-navigation__1g_vs {\n\tdisplay: flex;\n\tposition: absolute;\n\tbottom: 0;\n}\n");var L=function(e){var t=e.items,r=e.current,i=e.onClick,o=e.factory;return n.createElement("div",{className:b},t.map((function(e,t){return n.createElement("div",{onMouseOver:function(){return i(t)},key:t},o(r===t))})))},k="styles-module_sliderBase__swkx1",C="styles-module_slider__o0fqa",E="styles-module_sliding__3T6T6";i(".styles-module_sliderBase__swkx1 {\n\twidth: 100%;\n\tposition: relative;\n}\n\n.styles-module_slider__o0fqa {\n\tdisplay: flex;\n\toverflow-x: auto;\n\tscrollbar-width: none; /* Firefox 64 */\n\t-ms-overflow-style: none; /* Internet Explorer 11 */\n}\n\n.styles-module_slider__o0fqa::-webkit-scrollbar {\n\t/** WebKit */\n\tdisplay: none;\n}\n\n.styles-module_slider__o0fqa > * {\n\tflex: 0 0 auto;\n}\n\n.styles-module_sliding__3T6T6 > * {\n\tpointer-events: none;\n}\n");var R={children:[],className:"",leftIcon:null,rightIcon:null,triggerClickOn:3};exports.Carousel=function(e){var i,s,a,l,u=r(r({},_),e),v=m(u.children,u.navigation?u.children.length-1:u.slide,u.infinite),p=t.useState(v),b=p[0],k=p[1],C=t.useRef(v),E=t.useState(0),R=E[0],S=E[1],x=t.useState({transform:0,transition:0,isSliding:!1}),O=x[0],A=x[1],M=t.useState(0),T=M[0],N=M[1],I=t.useState(g({itemCount:u.children.length,itemsToShow:u.show,infinite:u.infinite,current:T,hideArrows:u.hideArrows})),D=I[0],P=I[1],W=(a=e.children,l=t.useRef(),t.useEffect((function(){l.current=a})),l.current),z=t.useState(0),X=z[0],q=z[1],B=t.useRef(!1),j=t.useRef(null),K=t.useRef(),Y="function"==typeof u.navigation;u.dynamic&&t.useEffect((function(){var e=w(C.current,u.children,W,u.slide,u.infinite);k(e),C.current=e,X<u.pageCount&&W&&(null==W?void 0:W.length)<u.children.length&&(U(c.Right),q(X+1))}),[u.children]),t.useEffect((function(){F()}),[]);var F=function(){clearTimeout(K.current),j&&"number"==typeof u.autoSwipe&&u.autoSwipe>u.transition&&(K.current=setTimeout((function(){j.current&&j.current.click()}),u.autoSwipe))},U=function(e,t){if(!(O.isSliding||e===c.Right&&!D.right||e===c.Left&&!D.left)){if(u.paginationCallback&&e===c.Right&&X<u.pageCount-1&&!B.current)return B.current=!0,void u.paginationCallback(e);var n=u.children,r=function(e,t,n,r){var i=e-r*t;return i<0?n+i:n<=i?i-n:i}(T,u.slide,n.length,e),i="number"==typeof t?t-T:-1*e,o=u.infinite?Y?function(e,t,n,r,i,o){var s=function(e,t,n){var r=e+t>=n.length?e+t-n.length:e+t;return r<0?n.length+r:r}(n,i,e),a=Math.floor(t.length/2),l=new d(e,s),u=Array.from(t);switch(+o){case c.Left:for(var f=0;f<a;f++){var h=a-(Math.abs(i)+f)-r;(h<0||!u[h])&&u.unshift(l.current()),l.prev()}break;case c.Right:for(f=0;f<a;f++)u[a+i+f+r]||u.push(l.current()),l.next()}return u}(n,b,r,u.show,i,e):function(e,t,n,r,i,o){var s=new d(e,n),a=Array.from(t);switch(+o){case c.Left:for(var l=i;l>=0;l--)(i-l<0||!a[l-i])&&a.unshift(s.current()),s.prev();break;case c.Right:for(l=0;l<r+i;l++)a[2*i+l]||a.push(s.current()),s.next()}return a}(n,b,r,u.show,u.slide,e):b;u.infinite&&e===c.Right&&(k(o),C.current=o),A({transform:O.transform+Math.abs(i)*h(R,u.slide,e),transition:u.transition,isSliding:!0}),N(Y&&"number"==typeof t?t:r),P(g({itemCount:n.length,itemsToShow:u.show,infinite:u.infinite,current:r,hideArrows:u.hideArrows})),setTimeout((function(){if(u.infinite){var n=Y?function(e,t,n){return n===c.Left?e.slice(0,t):e.slice(t)}(e===c.Right?C.current:o,function(e,t,n,r){return"number"==typeof e?r===c.Right?e-t+1:n:-1*r}(t,r,i,e),e):function(e,t,n){return n===c.Left?e.slice(0,-1*t):e.slice(t)}(e===c.Right?C.current:o,u.slide,e);k(n),C.current=n}A({transform:u.infinite?h(R,u.navigation?u.children.length-1:u.slide,c.Right):O.transform+h(R,u.slide,e),transition:0,isSliding:!1}),F()}),1e3*u.transition),B.current=!1}},G="disable"===u.arrowLogicOnEndOfPage||"hide"===u.arrowLogicOnEndOfPage&&D.left,H="disable"===u.arrowLogicOnEndOfPage||"hide"===u.arrowLogicOnEndOfPage&&D.right,J="disable"!==u.arrowLogicOnEndOfPage||D.left?"":"disabled",Q="disable"!==u.arrowLogicOnEndOfPage||D.right?"":"disabled";return n.createElement("div",r({},u.a11y,{"data-testid":"carousel",tabIndex:0},u.useArrowKeys?{onKeyDown:function(e){37===e.keyCode?U(c.Left):39===e.keyCode&&U(c.Right)}}:{},{className:o+" "+u.className}),!!G&&n.createElement("div",{className:J,onClick:function(){U(c.Left),u.onLeftArrowClick&&u.onLeftArrowClick()}},null!==(i=u.leftArrow)&&void 0!==i?i:n.createElement(f,{direction:"left"})),n.createElement(y,r({},u,{transition:O.transition,items:C.current,transform:O.transform,slideCallback:function(e){U(e)},dragCallback:function(e){A({transform:e,transition:u.transition,isSliding:!1}),setTimeout((function(){return A(r(r({},O),{transition:0}))}),1e3*u.transition)},widthCallBack:function(e){S(e),A({transform:u.infinite?h(e,u.navigation?u.children.length-1:u.slide,c.Right):0,transition:0,isSliding:!1})}})),!!H&&n.createElement("div",{className:Q,onClick:function(){U(c.Right),u.onRightArrowClick&&u.onRightArrowClick()},ref:j},null!==(s=u.rightArrow)&&void 0!==s?s:n.createElement(f,{direction:"right"})),Y&&n.createElement(L,{factory:u.navigation,items:u.children,current:T,onClick:function(e){T!==e&&U(e>T?c.Right:c.Left,e)}}))},exports.ScrollingCarousel=function(e){var i=r(r({},R),e),o=i.children,s=i.className,a=i.leftIcon,l=i.rightIcon,u=i.triggerClickOn,f=t.useRef(null),d=t.useState(!1),h=d[0],g=d[1],m=t.useState({startX:0,scrollLeft:0}),v=m[0],w=m[1],p=function(){var e=f.current;return{left:!!e&&e.scrollLeft>0,right:!!e&&e.scrollWidth>e.scrollLeft+e.offsetWidth}},y=t.useState(p()),_=y[0],b=y[1],L=function(e){b(p())},S=t.useCallback((function(e){null!==e&&(Object.defineProperty(f,"current",{value:e}),b(p()),e.addEventListener("scroll",L))}),[f,o]),x=function(e){g(!1),b(p()),f.current.classList.remove(E)},O=function(e){var t=function(e){for(var t,n,r=f.current,i=e===c.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,a=Array.from(r.children);s<a.length;s++){var l=a[s],u=(t=l,n=void 0,n=getComputedStyle(t),t.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=u)>=i){var d=e===c.Left?o-i:u;return(r.offsetWidth-d)*e}}return r.offsetWidth}(e),n=f.current.scrollLeft;A(500,t,n)},A=function(e,t,n){for(var r=0,i=0;r<=e;i++)window.setTimeout(M,r,i*t/100+n),r+=e/100},M=function(e){f.current.scrollLeft=e},T=function(e,t,r){return n.createElement("div",{"data-arrow":t,onClick:function(){return O(e)}},null!=r?r:n.createElement("button",null))};return n.createElement("div",{className:k+" "+s,"data-testid":"carousel"},_.left&&a&&T(c.Right,"left",a),_.right&&l&&T(c.Left,"right",l),n.createElement("div",{"data-testid":"sliderList",ref:S,onMouseDown:function(e){g(!0),w({startX:e.pageX-f.current.offsetLeft,scrollLeft:f.current.scrollLeft})},onMouseLeave:x,onMouseUp:x,onMouseMove:function(e){if(h){e.preventDefault();var t=e.pageX-f.current.offsetLeft-v.startX;Math.abs(t)>u&&f.current.classList.add(E),f.current.scrollLeft=v.scrollLeft-t}},className:C},o))}; |
@@ -1,1 +0,1 @@ | ||
import t,{useRef as n,useEffect as e,useState as r,useLayoutEffect as i,useCallback as o}from"react";var s=function(){return(s=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)};function a(t,n){void 0===n&&(n={});var e=n.insertAt;if(t&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===e&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t))}}var l="styles-module_carousel-base__3keqD",u="styles-module_item-provider__YgMwz",c="styles-module_item-container__a8zaY",f="styles-module_item-tracker__3bypy",d="styles-module_carousel-arrow__26sRw";a(".styles-module_carousel-base__3keqD {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\toutline: none;\n\tposition: relative;\n}\n\n.styles-module_item-provider__YgMwz {\n\toverflow: hidden;\n\twidth: 100%;\n\tcursor: pointer;\n}\n\n.styles-module_item-container__a8zaY img {\n\t-webkit-user-select: none;\n\t user-select: none;\n\t-webkit-user-drag: none;\n}\n\n.styles-module_item-tracker__3bypy {\n\theight: 100%;\n\tdisplay: flex;\n}\n\n.styles-module_carousel-arrow__26sRw {\n\tz-index: 1;\n}\n");var h,m=function(n){return t.createElement("button",{className:d,onClick:n.onClick,"data-direction":n.direction})};!function(t){t[t.Right=-1]="Right",t[t.Left=1]="Left"}(h||(h={}));var g=function(){function t(t,n){this.arr=t,this.currentIndex=n}return t.prototype.next=function(){var t=this.currentIndex,n=this.arr;return this.currentIndex=t<n.length-1?t+1:0,this.current()},t.prototype.prev=function(){var t=this.currentIndex,n=this.arr;return this.currentIndex=t>0&&t<n.length?t-1:n.length-1,this.current()},t.prototype.current=function(){return this.arr[this.currentIndex]},t}(),v=function(t,n,e){return e*t*n},p=function(t){var n=t.itemCount,e=t.itemsToShow,r=t.infinite,i=t.current,o=t.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=n>e;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+e<n}},w=function(t,n,e){if(!e)return t;for(var r=Array.from(t),i=new g(t,0),o=0;o<n;o++)r.unshift(i.prev());return r};function y(t){return t.nativeEvent instanceof MouseEvent?t.nativeEvent.pageX:t.nativeEvent instanceof TouchEvent?t.nativeEvent.changedTouches[0].pageX:0}function _(t,n,e,r,i){if(e&&e.length<n.length)return w(n,r,i);var o=t.map((function(t){return n.find((function(n){return t.key===n.key}))}));return o.some((function(t){return void 0===t}))?w(n,r,i):o}var k=function(t){var n=r("undefined"==typeof window?0:window.innerWidth),e=n[0],o=n[1];i((function(){var n=function(){var n=e-window.innerWidth;o(window.innerWidth),t(n)};return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[])},C=function(n){var e=r(200),i=e[0],a=e[1],l=o((function(t){if(null!==t){var e=t.getBoundingClientRect().width/n.show;a(e),n.widthCallBack(e)}}),[i]);n.responsive&&k((function(t){a(i-t)}));var d=r({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),m=d[0],g=d[1],v=function(t){t.persist(),g(s(s({},m),{isDown:!0,start:y(t),initial:n.transform,finished:!1}))},p=function(t){if(t.persist(),!m.finished){if(Math.abs(m.drag)<i*n.swipeOn)return n.dragCallback(n.transform),g({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});n.slideCallback(m.drag>0?h.Right:h.Left),g(s(s({},m),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},w=function(t){if(t.persist(),m.isDown){var e=y(t);g(s(s({},m),{drag:m.start-e,pointers:Math.abs(m.start-e)<n.triggerClickOn}))}},_=n.swiping?{onTouchCancel:p,onTouchEnd:p,onTouchMove:w,onTouchStart:v,onMouseDown:v,onMouseLeave:p,onMouseUp:p,onMouseMove:w}:{};return t.createElement("div",{ref:l,className:u},t.createElement("div",s({"data-testid":"trackList"},_,{className:f,style:{transform:"translateX("+(n.transform-m.drag)+"px)",transition:"transform "+n.transition+"s ease 0s",width:i*n.items.length}}),n.items.map((function(n,e){return t.createElement("div",{key:e,style:{width:i,pointerEvents:m.pointers?"all":"none"},className:c},n)}))))},b={children:[],show:1,slide:1,transition:.5,swiping:!1,swipeOn:1,responsive:!1,infinite:!0,className:"",useArrowKeys:!1,a11y:{},dynamic:!1,paginationCallback:null,pageCount:0,rightArrow:null,leftArrow:null,autoSwipe:null,navigation:null,triggerClickOn:Number.MIN_SAFE_INTEGER,hideArrows:!1,onLeftArrowClick:function(){return null},onRightArrowClick:function(){return null}},L="styles-module_carousel-navigation__1g_vs";a(".styles-module_carousel-navigation__1g_vs {\n\tdisplay: flex;\n\tposition: absolute;\n\tbottom: 0;\n}\n");var E=function(n){var e=n.items,r=n.current,i=n.onClick,o=n.factory;return t.createElement("div",{className:L},e.map((function(n,e){return t.createElement("div",{onMouseOver:function(){return i(e)},key:e},o(r===e))})))},x=function(i){var o,a,u,c,f=s(s({},b),i),d=w(f.children,f.navigation?f.children.length-1:f.slide,f.infinite),y=r(d),k=y[0],L=y[1],x=n(d),R=r(0),A=R[0],M=R[1],T=r({transform:0,transition:0,isSliding:!1}),S=T[0],N=T[1],I=r(0),D=I[0],O=I[1],W=r(p({itemCount:f.children.length,itemsToShow:f.show,infinite:f.infinite,current:D,hideArrows:f.hideArrows})),z=W[0],X=W[1],B=(u=i.children,c=n(),e((function(){c.current=u})),c.current),q=r(0),K=q[0],Y=q[1],j=n(!1),F=n(null),P=n(),U="function"==typeof f.navigation;f.dynamic&&e((function(){var t=_(x.current,f.children,B,f.slide,f.infinite);L(t),x.current=t,K<f.pageCount&&B&&(null==B?void 0:B.length)<f.children.length&&(H(h.Right),Y(K+1))}),[f.children]),e((function(){G()}),[]);var G=function(){clearTimeout(P.current),F&&"number"==typeof f.autoSwipe&&f.autoSwipe>f.transition&&(P.current=setTimeout((function(){F.current&&F.current.click()}),f.autoSwipe))},H=function(t,n){if(!(S.isSliding||t===h.Right&&!z.right||t===h.Left&&!z.left)){if(f.paginationCallback&&t===h.Right&&K<f.pageCount-1&&!j.current)return j.current=!0,void f.paginationCallback(t);var e=f.children,r=function(t,n,e,r){var i=t-r*n;return i<0?e+i:e<=i?i-e:i}(D,f.slide,e.length,t),i="number"==typeof n?n-D:-1*t,o=f.infinite?U?function(t,n,e,r,i,o){var s=function(t,n,e){var r=t+n>=e.length?t+n-e.length:t+n;return r<0?e.length+r:r}(e,i,t),a=Math.floor(n.length/2),l=new g(t,s),u=Array.from(n);switch(+o){case h.Left:for(var c=0;c<a;c++){var f=a-(Math.abs(i)+c)-r;(f<0||!u[f])&&u.unshift(l.current()),l.prev()}break;case h.Right:for(c=0;c<a;c++)u[a+i+c+r]||u.push(l.current()),l.next()}return u}(e,k,r,f.show,i,t):function(t,n,e,r,i,o){var s=new g(t,e),a=Array.from(n);switch(+o){case h.Left:for(var l=i;l>=0;l--)(i-l<0||!a[l-i])&&a.unshift(s.current()),s.prev();break;case h.Right:for(l=0;l<r+i;l++)a[2*i+l]||a.push(s.current()),s.next()}return a}(e,k,r,f.show,f.slide,t):k;f.infinite&&t===h.Right&&(L(o),x.current=o),N({transform:S.transform+Math.abs(i)*v(A,f.slide,t),transition:f.transition,isSliding:!0}),O(U&&"number"==typeof n?n:r),X(p({itemCount:e.length,itemsToShow:f.show,infinite:f.infinite,current:r,hideArrows:f.hideArrows})),setTimeout((function(){if(f.infinite){var e=U?function(t,n,e){return e===h.Left?t.slice(0,n):t.slice(n)}(t===h.Right?x.current:o,function(t,n,e,r){return"number"==typeof t?r===h.Right?t-n+1:e:-1*r}(n,r,i,t),t):function(t,n,e){return e===h.Left?t.slice(0,-1*n):t.slice(n)}(t===h.Right?x.current:o,f.slide,t);L(e),x.current=e}N({transform:f.infinite?v(A,f.navigation?f.children.length-1:f.slide,h.Right):S.transform+v(A,f.slide,t),transition:0,isSliding:!1}),G()}),1e3*f.transition),j.current=!1}};return t.createElement("div",s({},f.a11y,{"data-testid":"carousel",tabIndex:0},f.useArrowKeys?{onKeyDown:function(t){37===t.keyCode?H(h.Left):39===t.keyCode&&H(h.Right)}}:{},{className:l+" "+f.className}),z.left&&t.createElement("div",{onClick:function(){H(h.Left),f.onLeftArrowClick&&f.onLeftArrowClick()}},null!==(o=f.leftArrow)&&void 0!==o?o:t.createElement(m,{direction:"left"})),t.createElement(C,s({},f,{transition:S.transition,items:x.current,transform:S.transform,slideCallback:function(t){H(t)},dragCallback:function(t){N({transform:t,transition:f.transition,isSliding:!1}),setTimeout((function(){return N(s(s({},S),{transition:0}))}),1e3*f.transition)},widthCallBack:function(t){M(t),N({transform:f.infinite?v(t,f.navigation?f.children.length-1:f.slide,h.Right):0,transition:0,isSliding:!1})}})),z.right&&t.createElement("div",{onClick:function(){H(h.Right),f.onRightArrowClick&&f.onRightArrowClick()},ref:F},null!==(a=f.rightArrow)&&void 0!==a?a:t.createElement(m,{direction:"right"})),U&&t.createElement(E,{factory:f.navigation,items:f.children,current:D,onClick:function(t){D!==t&&H(t>D?h.Right:h.Left,t)}}))},R="styles-module_sliderBase__swkx1",A="styles-module_slider__o0fqa",M="styles-module_sliding__3T6T6";a(".styles-module_sliderBase__swkx1 {\n\twidth: 100%;\n\tposition: relative;\n}\n\n.styles-module_slider__o0fqa {\n\tdisplay: flex;\n\toverflow-x: auto;\n\tscrollbar-width: none; /* Firefox 64 */\n\t-ms-overflow-style: none; /* Internet Explorer 11 */\n}\n\n.styles-module_slider__o0fqa::-webkit-scrollbar {\n\t/** WebKit */\n\tdisplay: none;\n}\n\n.styles-module_slider__o0fqa > * {\n\tflex: 0 0 auto;\n}\n\n.styles-module_sliding__3T6T6 > * {\n\tpointer-events: none;\n}\n");var T={children:[],className:"",leftIcon:null,rightIcon:null,triggerClickOn:3},S=function(e){var i=s(s({},T),e),a=i.children,l=i.className,u=i.leftIcon,c=i.rightIcon,f=i.triggerClickOn,d=n(null),m=r(!1),g=m[0],v=m[1],p=r({startX:0,scrollLeft:0}),w=p[0],y=p[1],_=function(){var t=d.current;return{left:!!t&&t.scrollLeft>0,right:!!t&&t.scrollWidth>t.scrollLeft+t.offsetWidth}},k=r(_()),C=k[0],b=k[1],L=function(t){b(_())},E=o((function(t){null!==t&&(Object.defineProperty(d,"current",{value:t}),b(_()),t.addEventListener("scroll",L))}),[d,a]),x=function(t){v(!1),b(_()),d.current.classList.remove(M)},S=function(t){var n=function(t){for(var n,e,r=d.current,i=t===h.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,a=Array.from(r.children);s<a.length;s++){var l=a[s],u=(n=l,e=void 0,e=getComputedStyle(n),n.offsetWidth+(parseInt(e.marginLeft,10)||0)+(parseInt(e.marginRight,10)||0));if((o+=u)>=i){var c=t===h.Left?o-i:u;return(r.offsetWidth-c)*t}}return r.offsetWidth}(t),e=d.current.scrollLeft;N(500,n,e)},N=function(t,n,e){for(var r=0,i=0;r<=t;i++)window.setTimeout(I,r,i*n/100+e),r+=t/100},I=function(t){d.current.scrollLeft=t},D=function(n,e,r){return t.createElement("div",{"data-arrow":e,onClick:function(){return S(n)}},null!=r?r:t.createElement("button",null))};return t.createElement("div",{className:R+" "+l,"data-testid":"carousel"},C.left&&u&&D(h.Right,"left",u),C.right&&c&&D(h.Left,"right",c),t.createElement("div",{"data-testid":"sliderList",ref:E,onMouseDown:function(t){v(!0),y({startX:t.pageX-d.current.offsetLeft,scrollLeft:d.current.scrollLeft})},onMouseLeave:x,onMouseUp:x,onMouseMove:function(t){if(g){t.preventDefault();var n=t.pageX-d.current.offsetLeft-w.startX;Math.abs(n)>f&&d.current.classList.add(M),d.current.scrollLeft=w.scrollLeft-n}},className:A},a))};export{x as Carousel,S as ScrollingCarousel}; | ||
import t,{useRef as n,useEffect as e,useState as r,useLayoutEffect as i,useCallback as o}from"react";var s=function(){return(s=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)};function a(t,n){void 0===n&&(n={});var e=n.insertAt;if(t&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===e&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t))}}var l="styles-module_carousel-base__3keqD",c="styles-module_item-provider__YgMwz",u="styles-module_item-container__a8zaY",f="styles-module_item-tracker__3bypy",d="styles-module_carousel-arrow__26sRw";a(".styles-module_carousel-base__3keqD {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\toutline: none;\n\tposition: relative;\n}\n\n.styles-module_item-provider__YgMwz {\n\toverflow: hidden;\n\twidth: 100%;\n\tcursor: pointer;\n}\n\n.styles-module_item-container__a8zaY img {\n\t-webkit-user-select: none;\n\t user-select: none;\n\t-webkit-user-drag: none;\n}\n\n.styles-module_item-tracker__3bypy {\n\theight: 100%;\n\tdisplay: flex;\n}\n\n.styles-module_carousel-arrow__26sRw {\n\tz-index: 1;\n}\n");var h,g=function(n){return t.createElement("button",{className:d,onClick:n.onClick,"data-direction":n.direction})};!function(t){t[t.Right=-1]="Right",t[t.Left=1]="Left"}(h||(h={}));var m=function(){function t(t,n){this.arr=t,this.currentIndex=n}return t.prototype.next=function(){var t=this.currentIndex,n=this.arr;return this.currentIndex=t<n.length-1?t+1:0,this.current()},t.prototype.prev=function(){var t=this.currentIndex,n=this.arr;return this.currentIndex=t>0&&t<n.length?t-1:n.length-1,this.current()},t.prototype.current=function(){return this.arr[this.currentIndex]},t}(),v=function(t,n,e){return e*t*n},w=function(t){var n=t.itemCount,e=t.itemsToShow,r=t.infinite,i=t.current,o=t.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=n>e;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+e<n}},p=function(t,n,e){if(!e)return t;for(var r=Array.from(t),i=new m(t,0),o=0;o<n;o++)r.unshift(i.prev());return r};function y(t){return t.nativeEvent instanceof MouseEvent?t.nativeEvent.pageX:t.nativeEvent instanceof TouchEvent?t.nativeEvent.changedTouches[0].pageX:0}function _(t,n,e,r,i){if(e&&e.length<n.length)return p(n,r,i);var o=t.map((function(t){return n.find((function(n){return t.key===n.key}))}));return o.some((function(t){return void 0===t}))?p(n,r,i):o}var L=function(t){var n=r("undefined"==typeof window?0:window.innerWidth),e=n[0],o=n[1];i((function(){var n=function(){var n=e-window.innerWidth;o(window.innerWidth),t(n)};return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[])},b=function(n){var e=r(200),i=e[0],a=e[1],l=o((function(t){if(null!==t){var e=t.getBoundingClientRect().width/n.show;a(e),n.widthCallBack(e)}}),[i]);n.responsive&&L((function(t){a(i-t)}));var d=r({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),g=d[0],m=d[1],v=function(t){t.persist(),m(s(s({},g),{isDown:!0,start:y(t),initial:n.transform,finished:!1}))},w=function(t){if(t.persist(),!g.finished){if(Math.abs(g.drag)<i*n.swipeOn)return n.dragCallback(n.transform),m({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});n.slideCallback(g.drag>0?h.Right:h.Left),m(s(s({},g),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},p=function(t){if(t.persist(),g.isDown){var e=y(t);m(s(s({},g),{drag:g.start-e,pointers:Math.abs(g.start-e)<n.triggerClickOn}))}},_=n.swiping?{onTouchCancel:w,onTouchEnd:w,onTouchMove:p,onTouchStart:v,onMouseDown:v,onMouseLeave:w,onMouseUp:w,onMouseMove:p}:{};return t.createElement("div",{ref:l,className:c},t.createElement("div",s({"data-testid":"trackList"},_,{className:f,style:{transform:"translateX("+(n.transform-g.drag)+"px)",transition:"transform "+n.transition+"s ease 0s",width:i*n.items.length}}),n.items.map((function(n,e){return t.createElement("div",{key:e,style:{width:i,pointerEvents:g.pointers?"all":"none"},className:u},n)}))))},k={children:[],show:1,slide:1,transition:.5,swiping:!1,swipeOn:1,responsive:!1,infinite:!0,className:"",useArrowKeys:!1,a11y:{},dynamic:!1,paginationCallback:null,pageCount:0,rightArrow:null,leftArrow:null,arrowLogicOnEndOfPage:"hide",autoSwipe:null,navigation:null,triggerClickOn:Number.MIN_SAFE_INTEGER,hideArrows:!1,onLeftArrowClick:function(){return null},onRightArrowClick:function(){return null}},C="styles-module_carousel-navigation__1g_vs";a(".styles-module_carousel-navigation__1g_vs {\n\tdisplay: flex;\n\tposition: absolute;\n\tbottom: 0;\n}\n");var E=function(n){var e=n.items,r=n.current,i=n.onClick,o=n.factory;return t.createElement("div",{className:C},e.map((function(n,e){return t.createElement("div",{onMouseOver:function(){return i(e)},key:e},o(r===e))})))},x=function(i){var o,a,c,u,f=s(s({},k),i),d=p(f.children,f.navigation?f.children.length-1:f.slide,f.infinite),y=r(d),L=y[0],C=y[1],x=n(d),R=r(0),O=R[0],A=R[1],M=r({transform:0,transition:0,isSliding:!1}),T=M[0],N=M[1],S=r(0),I=S[0],D=S[1],W=r(w({itemCount:f.children.length,itemsToShow:f.show,infinite:f.infinite,current:I,hideArrows:f.hideArrows})),P=W[0],z=W[1],X=(c=i.children,u=n(),e((function(){u.current=c})),u.current),B=r(0),q=B[0],K=B[1],Y=n(!1),j=n(null),F=n(),U="function"==typeof f.navigation;f.dynamic&&e((function(){var t=_(x.current,f.children,X,f.slide,f.infinite);C(t),x.current=t,q<f.pageCount&&X&&(null==X?void 0:X.length)<f.children.length&&(H(h.Right),K(q+1))}),[f.children]),e((function(){G()}),[]);var G=function(){clearTimeout(F.current),j&&"number"==typeof f.autoSwipe&&f.autoSwipe>f.transition&&(F.current=setTimeout((function(){j.current&&j.current.click()}),f.autoSwipe))},H=function(t,n){if(!(T.isSliding||t===h.Right&&!P.right||t===h.Left&&!P.left)){if(f.paginationCallback&&t===h.Right&&q<f.pageCount-1&&!Y.current)return Y.current=!0,void f.paginationCallback(t);var e=f.children,r=function(t,n,e,r){var i=t-r*n;return i<0?e+i:e<=i?i-e:i}(I,f.slide,e.length,t),i="number"==typeof n?n-I:-1*t,o=f.infinite?U?function(t,n,e,r,i,o){var s=function(t,n,e){var r=t+n>=e.length?t+n-e.length:t+n;return r<0?e.length+r:r}(e,i,t),a=Math.floor(n.length/2),l=new m(t,s),c=Array.from(n);switch(+o){case h.Left:for(var u=0;u<a;u++){var f=a-(Math.abs(i)+u)-r;(f<0||!c[f])&&c.unshift(l.current()),l.prev()}break;case h.Right:for(u=0;u<a;u++)c[a+i+u+r]||c.push(l.current()),l.next()}return c}(e,L,r,f.show,i,t):function(t,n,e,r,i,o){var s=new m(t,e),a=Array.from(n);switch(+o){case h.Left:for(var l=i;l>=0;l--)(i-l<0||!a[l-i])&&a.unshift(s.current()),s.prev();break;case h.Right:for(l=0;l<r+i;l++)a[2*i+l]||a.push(s.current()),s.next()}return a}(e,L,r,f.show,f.slide,t):L;f.infinite&&t===h.Right&&(C(o),x.current=o),N({transform:T.transform+Math.abs(i)*v(O,f.slide,t),transition:f.transition,isSliding:!0}),D(U&&"number"==typeof n?n:r),z(w({itemCount:e.length,itemsToShow:f.show,infinite:f.infinite,current:r,hideArrows:f.hideArrows})),setTimeout((function(){if(f.infinite){var e=U?function(t,n,e){return e===h.Left?t.slice(0,n):t.slice(n)}(t===h.Right?x.current:o,function(t,n,e,r){return"number"==typeof t?r===h.Right?t-n+1:e:-1*r}(n,r,i,t),t):function(t,n,e){return e===h.Left?t.slice(0,-1*n):t.slice(n)}(t===h.Right?x.current:o,f.slide,t);C(e),x.current=e}N({transform:f.infinite?v(O,f.navigation?f.children.length-1:f.slide,h.Right):T.transform+v(O,f.slide,t),transition:0,isSliding:!1}),G()}),1e3*f.transition),Y.current=!1}},J="disable"===f.arrowLogicOnEndOfPage||"hide"===f.arrowLogicOnEndOfPage&&P.left,Q="disable"===f.arrowLogicOnEndOfPage||"hide"===f.arrowLogicOnEndOfPage&&P.right,V="disable"!==f.arrowLogicOnEndOfPage||P.left?"":"disabled",Z="disable"!==f.arrowLogicOnEndOfPage||P.right?"":"disabled";return t.createElement("div",s({},f.a11y,{"data-testid":"carousel",tabIndex:0},f.useArrowKeys?{onKeyDown:function(t){37===t.keyCode?H(h.Left):39===t.keyCode&&H(h.Right)}}:{},{className:l+" "+f.className}),!!J&&t.createElement("div",{className:V,onClick:function(){H(h.Left),f.onLeftArrowClick&&f.onLeftArrowClick()}},null!==(o=f.leftArrow)&&void 0!==o?o:t.createElement(g,{direction:"left"})),t.createElement(b,s({},f,{transition:T.transition,items:x.current,transform:T.transform,slideCallback:function(t){H(t)},dragCallback:function(t){N({transform:t,transition:f.transition,isSliding:!1}),setTimeout((function(){return N(s(s({},T),{transition:0}))}),1e3*f.transition)},widthCallBack:function(t){A(t),N({transform:f.infinite?v(t,f.navigation?f.children.length-1:f.slide,h.Right):0,transition:0,isSliding:!1})}})),!!Q&&t.createElement("div",{className:Z,onClick:function(){H(h.Right),f.onRightArrowClick&&f.onRightArrowClick()},ref:j},null!==(a=f.rightArrow)&&void 0!==a?a:t.createElement(g,{direction:"right"})),U&&t.createElement(E,{factory:f.navigation,items:f.children,current:I,onClick:function(t){I!==t&&H(t>I?h.Right:h.Left,t)}}))},R="styles-module_sliderBase__swkx1",O="styles-module_slider__o0fqa",A="styles-module_sliding__3T6T6";a(".styles-module_sliderBase__swkx1 {\n\twidth: 100%;\n\tposition: relative;\n}\n\n.styles-module_slider__o0fqa {\n\tdisplay: flex;\n\toverflow-x: auto;\n\tscrollbar-width: none; /* Firefox 64 */\n\t-ms-overflow-style: none; /* Internet Explorer 11 */\n}\n\n.styles-module_slider__o0fqa::-webkit-scrollbar {\n\t/** WebKit */\n\tdisplay: none;\n}\n\n.styles-module_slider__o0fqa > * {\n\tflex: 0 0 auto;\n}\n\n.styles-module_sliding__3T6T6 > * {\n\tpointer-events: none;\n}\n");var M={children:[],className:"",leftIcon:null,rightIcon:null,triggerClickOn:3},T=function(e){var i=s(s({},M),e),a=i.children,l=i.className,c=i.leftIcon,u=i.rightIcon,f=i.triggerClickOn,d=n(null),g=r(!1),m=g[0],v=g[1],w=r({startX:0,scrollLeft:0}),p=w[0],y=w[1],_=function(){var t=d.current;return{left:!!t&&t.scrollLeft>0,right:!!t&&t.scrollWidth>t.scrollLeft+t.offsetWidth}},L=r(_()),b=L[0],k=L[1],C=function(t){k(_())},E=o((function(t){null!==t&&(Object.defineProperty(d,"current",{value:t}),k(_()),t.addEventListener("scroll",C))}),[d,a]),x=function(t){v(!1),k(_()),d.current.classList.remove(A)},T=function(t){var n=function(t){for(var n,e,r=d.current,i=t===h.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,a=Array.from(r.children);s<a.length;s++){var l=a[s],c=(n=l,e=void 0,e=getComputedStyle(n),n.offsetWidth+(parseInt(e.marginLeft,10)||0)+(parseInt(e.marginRight,10)||0));if((o+=c)>=i){var u=t===h.Left?o-i:c;return(r.offsetWidth-u)*t}}return r.offsetWidth}(t),e=d.current.scrollLeft;N(500,n,e)},N=function(t,n,e){for(var r=0,i=0;r<=t;i++)window.setTimeout(S,r,i*n/100+e),r+=t/100},S=function(t){d.current.scrollLeft=t},I=function(n,e,r){return t.createElement("div",{"data-arrow":e,onClick:function(){return T(n)}},null!=r?r:t.createElement("button",null))};return t.createElement("div",{className:R+" "+l,"data-testid":"carousel"},b.left&&c&&I(h.Right,"left",c),b.right&&u&&I(h.Left,"right",u),t.createElement("div",{"data-testid":"sliderList",ref:E,onMouseDown:function(t){v(!0),y({startX:t.pageX-d.current.offsetLeft,scrollLeft:d.current.scrollLeft})},onMouseLeave:x,onMouseUp:x,onMouseMove:function(t){if(m){t.preventDefault();var n=t.pageX-d.current.offsetLeft-p.startX;Math.abs(n)>f&&d.current.classList.add(A),d.current.scrollLeft=p.scrollLeft-n}},className:O},a))};export{x as Carousel,T as ScrollingCarousel}; |
@@ -24,2 +24,3 @@ import { FunctionComponent, ReactElement } from 'react'; | ||
rightArrow?: ReactElement | null; | ||
arrowLogicOnEndOfPage?: 'hide' | 'disable'; | ||
autoSwipe?: number | null; | ||
@@ -26,0 +27,0 @@ navigation?: null | ((selected: boolean) => ReactElement); |
@@ -7,3 +7,3 @@ module.exports = { | ||
global: { | ||
branches: 83, | ||
branches: 82, | ||
functions: 83, | ||
@@ -10,0 +10,0 @@ lines: 83, |
{ | ||
"name": "@trendyol-js/react-carousel", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Lightweight carousel component for react", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
77575
1.47%1210
0.41%