@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},m=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}},v=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 g(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 v(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}))?v(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)}}),[])};i(".styles-module_item-click-provider__2h2tS {\n\twidth: 100%;\n\theight: 100%;\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n}\n");var y=function(e){var t=e.index,r=e.current,i=e.slideToDirection,o=e.itemsRef;return n.createElement("div",{className:"styles-module_item-click-provider__2h2tS",onClick:function(){t!==r&&(i(t>r?c.Right:c.Left),setTimeout((function(){o&&o.current&&o.current[t].firstChild.click()}),750))},"data-testid":"placeholder"})},_=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],m=d[1],v=function(t){t.persist(),m(r(r({},h),{isDown:!0,start:g(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),m({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});e.slideCallback(h.drag>0?c.Right:c.Left),m(r(r({},h),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},_=function(t){if(t.persist(),h.isDown){var n=g(t);m(r(r({},h),{drag:h.start-n,pointers:Math.abs(h.start-n)<e.triggerClickOn}))}},k=e.swiping?{onTouchCancel:p,onTouchEnd:p,onTouchMove:_,onTouchStart:v,onMouseDown:v,onMouseLeave:p,onMouseUp:p,onMouseMove:_}:{},b=t.useRef([]);return n.createElement("div",{ref:f,className:s},n.createElement("div",r({"data-testid":"trackList"},k,{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(t,r){return n.createElement("div",{key:r,style:{width:o,pointerEvents:h.pointers?"all":"none",position:"relative"},className:a,ref:function(t){e.moveToFirstPositionThanClickItem&&(b.current[r]=t)}},t,e.moveToFirstPositionThanClickItem&&null!==e.current&&r!==e.current&&null!==e.slideToDirection&&n.createElement(y,{current:e.current,index:r,slideToDirection:e.slideToDirection,itemsRef:b}))}))))},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,autoSwipe:null,navigation:null,triggerClickOn:Number.MIN_SAFE_INTEGER,moveToFirstPositionThanClickItem:!1,hideArrows:!1},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 C=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))})))},E="styles-module_sliderBase__swkx1",L="styles-module_slider__o0fqa",T="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");exports.Carousel=function(e){var i,s,a,l,u=r(r({},k),e),g=v(u.children,u.navigation?u.children.length-1:u.slide,u.infinite),w=t.useState(g),y=w[0],b=w[1],E=t.useRef(g),L=t.useState(0),T=L[0],R=L[1],S=t.useState({transform:0,transition:0,isSliding:!1}),x=S[0],M=S[1],A=t.useState(0),I=A[0],N=A[1],D=t.useState(m({itemCount:u.children.length,itemsToShow:u.show,infinite:u.infinite,current:I,hideArrows:u.hideArrows})),O=D[0],W=D[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],P=t.useRef(!1),j=t.useRef(null),F=t.useRef(),K="function"==typeof u.navigation;t.useEffect((function(){if(u.dynamic){var e=p(E.current,u.children,z,u.slide,u.infinite);b(e),E.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(){Y()}),[]);var Y=function(){clearTimeout(F.current),j&&"number"==typeof u.autoSwipe&&u.autoSwipe>u.transition&&(F.current=setTimeout((function(){j.current&&j.current.click()}),u.autoSwipe))},U=function(e,t){if(!(x.isSliding||e===c.Right&&!O.right||e===c.Left&&!O.left)){if(u.paginationCallback&&e===c.Right&&q<u.pageCount-1&&!P.current)return P.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}(I,u.slide,n.length,e),i="number"==typeof t?t-I:-1*e,o=u.infinite?K?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,y,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,y,r,u.show,u.slide,e):y;u.infinite&&e===c.Right&&(b(o),E.current=o),M({transform:x.transform+Math.abs(i)*h(T,u.slide,e),transition:u.transition,isSliding:!0}),N(K&&"number"==typeof t?t:r),W(m({itemCount:n.length,itemsToShow:u.show,infinite:u.infinite,current:r,hideArrows:u.hideArrows})),setTimeout((function(){if(u.infinite){var n=K?function(e,t,n){return n===c.Left?e.slice(0,t):e.slice(t)}(e===c.Right?E.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?E.current:o,u.slide,e);b(n),E.current=n}M({transform:u.infinite?h(T,u.navigation?u.children.length-1:u.slide,c.Right):x.transform+h(T,u.slide,e),transition:0,isSliding:!1}),Y()}),1e3*u.transition),P.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}),O.left&&n.createElement("div",{onClick:function(){return U(c.Left)}},null!==(i=u.leftArrow)&&void 0!==i?i:n.createElement(f,{direction:"left"})),n.createElement(_,r({},u,{transition:x.transition,items:E.current,transform:x.transform,slideCallback:function(e){U(e)},dragCallback:function(e){M({transform:e,transition:u.transition,isSliding:!1}),setTimeout((function(){return M(r(r({},x),{transition:0}))}),1e3*u.transition)},widthCallBack:function(e){R(e),M({transform:u.infinite?h(e,u.navigation?u.children.length-1:u.slide,c.Right):0,transition:0,isSliding:!1})},slideToDirection:U,current:I})),O.right&&n.createElement("div",{onClick:function(){return U(c.Right)},ref:j},null!==(s=u.rightArrow)&&void 0!==s?s:n.createElement(f,{direction:"right"})),K&&n.createElement(C,{factory:u.navigation,items:u.children,current:I,onClick:function(e){I!==e&&U(e>I?c.Right:c.Left,e)}}))},exports.ScrollingCarousel=function(e){var r=e.children,i=e.className,o=e.leftIcon,s=e.rightIcon,a=t.useRef(null),l=t.useState(!1),u=l[0],f=l[1],d=t.useState({startX:0,scrollLeft:0}),h=d[0],m=d[1],v=function(){var e=a.current;return{left:!!e&&e.scrollLeft>0,right:!!e&&e.scrollWidth>e.scrollLeft+e.offsetWidth}},g=t.useState(v()),p=g[0],w=g[1],y=function(e){w(v())},_=t.useCallback((function(e){null!==e&&(Object.defineProperty(a,"current",{value:e}),w(v()),e.addEventListener("scroll",y))}),[a,r]),k=function(e){f(!1),w(v()),a.current.classList.remove(T)},b=function(e){var t=function(e){for(var t,n,r=a.current,i=e===c.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,l=Array.from(r.children);s<l.length;s++){var u=l[s],f=(t=u,n=void 0,n=getComputedStyle(t),t.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=f)>=i){var d=e===c.Left?o-i:f;return(r.offsetWidth-d)*e}}return r.offsetWidth}(e),n=a.current.scrollLeft;C(500,t,n)},C=function(e,t,n){for(var r=0,i=0;r<=e;i++)window.setTimeout(R,r,i*t/100+n),r+=e/100},R=function(e){a.current.scrollLeft=e},S=function(e,t,r){return n.createElement("div",{"data-arrow":t,onClick:function(){return b(e)}},null!=r?r:n.createElement("button",null))};return n.createElement("div",{className:E+" "+i,"data-testid":"carousel"},p.left&&S(c.Right,"left",o),p.right&&S(c.Left,"right",s),n.createElement("div",{ref:_,onMouseDown:function(e){f(!0),m({startX:e.pageX-a.current.offsetLeft,scrollLeft:a.current.scrollLeft})},onMouseLeave:k,onMouseUp:k,onMouseMove:function(e){if(u){e.preventDefault(),a.current.classList.add(T);var t=e.pageX-a.current.offsetLeft-h.startX;a.current.scrollLeft=h.scrollLeft-t}},className:L},r))}; | ||
"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},m=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}},v=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 g(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 v(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}))?v(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],m=d[1],v=function(t){t.persist(),m(r(r({},h),{isDown:!0,start:g(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),m({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});e.slideCallback(h.drag>0?c.Right:c.Left),m(r(r({},h),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},y=function(t){if(t.persist(),h.isDown){var n=g(t);m(r(r({},h),{drag:h.start-n,pointers:Math.abs(h.start-n)<e.triggerClickOn}))}},_=e.swiping?{onTouchCancel:p,onTouchEnd:p,onTouchMove:y,onTouchStart:v,onMouseDown:v,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},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 k=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))})))},E="styles-module_sliderBase__swkx1",C="styles-module_slider__o0fqa",L="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");exports.Carousel=function(e){var i,s,a,l,u=r(r({},_),e),g=v(u.children,u.navigation?u.children.length-1:u.slide,u.infinite),w=t.useState(g),b=w[0],E=w[1],C=t.useRef(g),L=t.useState(0),S=L[0],x=L[1],R=t.useState({transform:0,transition:0,isSliding:!1}),M=R[0],T=R[1],A=t.useState(0),N=A[0],I=A[1],D=t.useState(m({itemCount:u.children.length,itemsToShow:u.show,infinite:u.infinite,current:N,hideArrows:u.hideArrows})),O=D[0],W=D[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(C.current,u.children,z,u.slide,u.infinite);E(e),C.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(!(M.isSliding||e===c.Right&&!O.right||e===c.Left&&!O.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,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&&(E(o),C.current=o),T({transform:M.transform+Math.abs(i)*h(S,u.slide,e),transition:u.transition,isSliding:!0}),I(P&&"number"==typeof t?t:r),W(m({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?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);E(n),C.current=n}T({transform:u.infinite?h(S,u.navigation?u.children.length-1:u.slide,c.Right):M.transform+h(S,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}),O.left&&n.createElement("div",{onClick:function(){return U(c.Left)}},null!==(i=u.leftArrow)&&void 0!==i?i:n.createElement(f,{direction:"left"})),n.createElement(y,r({},u,{transition:M.transition,items:C.current,transform:M.transform,slideCallback:function(e){U(e)},dragCallback:function(e){T({transform:e,transition:u.transition,isSliding:!1}),setTimeout((function(){return T(r(r({},M),{transition:0}))}),1e3*u.transition)},widthCallBack:function(e){x(e),T({transform:u.infinite?h(e,u.navigation?u.children.length-1:u.slide,c.Right):0,transition:0,isSliding:!1})}})),O.right&&n.createElement("div",{onClick:function(){return U(c.Right)},ref:K},null!==(s=u.rightArrow)&&void 0!==s?s:n.createElement(f,{direction:"right"})),P&&n.createElement(k,{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 r=e.children,i=e.className,o=e.leftIcon,s=e.rightIcon,a=t.useRef(null),l=t.useState(!1),u=l[0],f=l[1],d=t.useState({startX:0,scrollLeft:0}),h=d[0],m=d[1],v=function(){var e=a.current;return{left:!!e&&e.scrollLeft>0,right:!!e&&e.scrollWidth>e.scrollLeft+e.offsetWidth}},g=t.useState(v()),p=g[0],w=g[1],y=function(e){w(v())},_=t.useCallback((function(e){null!==e&&(Object.defineProperty(a,"current",{value:e}),w(v()),e.addEventListener("scroll",y))}),[a,r]),b=function(e){f(!1),w(v()),a.current.classList.remove(L)},k=function(e){var t=function(e){for(var t,n,r=a.current,i=e===c.Left?r.scrollLeft+r.offsetWidth:r.scrollLeft,o=0,s=0,l=Array.from(r.children);s<l.length;s++){var u=l[s],f=(t=u,n=void 0,n=getComputedStyle(t),t.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=f)>=i){var d=e===c.Left?o-i:f;return(r.offsetWidth-d)*e}}return r.offsetWidth}(e),n=a.current.scrollLeft;S(500,t,n)},S=function(e,t,n){for(var r=0,i=0;r<=e;i++)window.setTimeout(x,r,i*t/100+n),r+=e/100},x=function(e){a.current.scrollLeft=e},R=function(e,t,r){return n.createElement("div",{"data-arrow":t,onClick:function(){return k(e)}},null!=r?r:n.createElement("button",null))};return n.createElement("div",{className:E+" "+i,"data-testid":"carousel"},p.left&&R(c.Right,"left",o),p.right&&R(c.Left,"right",s),n.createElement("div",{ref:_,onMouseDown:function(e){f(!0),m({startX:e.pageX-a.current.offsetLeft,scrollLeft:a.current.scrollLeft})},onMouseLeave:b,onMouseUp:b,onMouseMove:function(e){if(u){e.preventDefault(),a.current.classList.add(L);var t=e.pageX-a.current.offsetLeft-h.startX;a.current.scrollLeft=h.scrollLeft-t}},className:C},r))}; |
@@ -1,1 +0,1 @@ | ||
import t,{useRef as e,useEffect as n,useState as r,useLayoutEffect as i,useCallback as o}from"react";var s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function a(t,e){void 0===e&&(e={});var n=e.insertAt;if(t&&"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=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,m=function(e){return t.createElement("button",{className:d,onClick:e.onClick,"data-direction":e.direction})};!function(t){t[t.Right=-1]="Right",t[t.Left=1]="Left"}(h||(h={}));var v=function(){function t(t,e){this.arr=t,this.currentIndex=e}return t.prototype.next=function(){var t=this.currentIndex,e=this.arr;return this.currentIndex=t<e.length-1?t+1:0,this.current()},t.prototype.prev=function(){var t=this.currentIndex,e=this.arr;return this.currentIndex=t>0&&t<e.length?t-1:e.length-1,this.current()},t.prototype.current=function(){return this.arr[this.currentIndex]},t}(),g=function(t,e,n){return n*t*e},p=function(t){var e=t.itemCount,n=t.itemsToShow,r=t.infinite,i=t.current,o=t.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=e>n;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+n<e}},w=function(t,e,n){if(!n)return t;for(var r=Array.from(t),i=new v(t,0),o=0;o<e;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,e,n,r,i){if(n&&n.length<e.length)return w(e,r,i);var o=t.map((function(t){return e.find((function(e){return t.key===e.key}))}));return o.some((function(t){return void 0===t}))?w(e,r,i):o}var k=function(t){var e=r("undefined"==typeof window?0:window.innerWidth),n=e[0],o=e[1];i((function(){var e=function(){var e=n-window.innerWidth;o(window.innerWidth),t(e)};return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[])};a(".styles-module_item-click-provider__2h2tS {\n\twidth: 100%;\n\theight: 100%;\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n}\n");var b=function(e){var n=e.index,r=e.current,i=e.slideToDirection,o=e.itemsRef;return t.createElement("div",{className:"styles-module_item-click-provider__2h2tS",onClick:function(){n!==r&&(i(n>r?h.Right:h.Left),setTimeout((function(){o&&o.current&&o.current[n].firstChild.click()}),750))},"data-testid":"placeholder"})},C=function(n){var i=r(200),a=i[0],l=i[1],d=o((function(t){if(null!==t){var e=t.getBoundingClientRect().width/n.show;l(e),n.widthCallBack(e)}}),[a]);n.responsive&&k((function(t){l(a-t)}));var m=r({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),v=m[0],g=m[1],p=function(t){t.persist(),g(s(s({},v),{isDown:!0,start:y(t),initial:n.transform,finished:!1}))},w=function(t){if(t.persist(),!v.finished){if(Math.abs(v.drag)<a*n.swipeOn)return n.dragCallback(n.transform),g({initial:n.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});n.slideCallback(v.drag>0?h.Right:h.Left),g(s(s({},v),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},_=function(t){if(t.persist(),v.isDown){var e=y(t);g(s(s({},v),{drag:v.start-e,pointers:Math.abs(v.start-e)<n.triggerClickOn}))}},C=n.swiping?{onTouchCancel:w,onTouchEnd:w,onTouchMove:_,onTouchStart:p,onMouseDown:p,onMouseLeave:w,onMouseUp:w,onMouseMove:_}:{},L=e([]);return t.createElement("div",{ref:d,className:c},t.createElement("div",s({"data-testid":"trackList"},C,{className:f,style:{transform:"translateX("+(n.transform-v.drag)+"px)",transition:"transform "+n.transition+"s ease 0s",width:a*n.items.length}}),n.items.map((function(e,r){return t.createElement("div",{key:r,style:{width:a,pointerEvents:v.pointers?"all":"none",position:"relative"},className:u,ref:function(t){n.moveToFirstPositionThanClickItem&&(L.current[r]=t)}},e,n.moveToFirstPositionThanClickItem&&null!==n.current&&r!==n.current&&null!==n.slideToDirection&&t.createElement(b,{current:n.current,index:r,slideToDirection:n.slideToDirection,itemsRef:L}))}))))},L={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,moveToFirstPositionThanClickItem:!1,hideArrows:!1},E="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 T=function(e){var n=e.items,r=e.current,i=e.onClick,o=e.factory;return t.createElement("div",{className:E},n.map((function(e,n){return t.createElement("div",{onMouseOver:function(){return i(n)},key:n},o(r===n))})))},x=function(i){var o,a,c,u,f=s(s({},L),i),d=w(f.children,f.navigation?f.children.length-1:f.slide,f.infinite),y=r(d),k=y[0],b=y[1],E=e(d),x=r(0),R=x[0],M=x[1],S=r({transform:0,transition:0,isSliding:!1}),A=S[0],I=S[1],N=r(0),D=N[0],W=N[1],O=r(p({itemCount:f.children.length,itemsToShow:f.show,infinite:f.infinite,current:D,hideArrows:f.hideArrows})),z=O[0],X=O[1],B=(c=i.children,u=e(),n((function(){u.current=c})),u.current),q=r(0),F=q[0],P=q[1],K=e(!1),Y=e(null),j=e(),U="function"==typeof f.navigation;n((function(){if(f.dynamic){var t=_(E.current,f.children,B,f.slide,f.infinite);b(t),E.current=t,F<f.pageCount&&B&&(null==B?void 0:B.length)<f.children.length&&(H(h.Right),P(F+1))}}),[f.children]),n((function(){G()}),[]);var G=function(){clearTimeout(j.current),Y&&"number"==typeof f.autoSwipe&&f.autoSwipe>f.transition&&(j.current=setTimeout((function(){Y.current&&Y.current.click()}),f.autoSwipe))},H=function(t,e){if(!(A.isSliding||t===h.Right&&!z.right||t===h.Left&&!z.left)){if(f.paginationCallback&&t===h.Right&&F<f.pageCount-1&&!K.current)return K.current=!0,void f.paginationCallback(t);var n=f.children,r=function(t,e,n,r){var i=t-r*e;return i<0?n+i:n<=i?i-n:i}(D,f.slide,n.length,t),i="number"==typeof e?e-D:-1*t,o=f.infinite?U?function(t,e,n,r,i,o){var s=function(t,e,n){var r=t+e>=n.length?t+e-n.length:t+e;return r<0?n.length+r:r}(n,i,t),a=Math.floor(e.length/2),l=new v(t,s),c=Array.from(e);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}(n,k,r,f.show,i,t):function(t,e,n,r,i,o){var s=new v(t,n),a=Array.from(e);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}(n,k,r,f.show,f.slide,t):k;f.infinite&&t===h.Right&&(b(o),E.current=o),I({transform:A.transform+Math.abs(i)*g(R,f.slide,t),transition:f.transition,isSliding:!0}),W(U&&"number"==typeof e?e:r),X(p({itemCount:n.length,itemsToShow:f.show,infinite:f.infinite,current:r,hideArrows:f.hideArrows})),setTimeout((function(){if(f.infinite){var n=U?function(t,e,n){return n===h.Left?t.slice(0,e):t.slice(e)}(t===h.Right?E.current:o,function(t,e,n,r){return"number"==typeof t?r===h.Right?t-e+1:n:-1*r}(e,r,i,t),t):function(t,e,n){return n===h.Left?t.slice(0,-1*e):t.slice(e)}(t===h.Right?E.current:o,f.slide,t);b(n),E.current=n}I({transform:f.infinite?g(R,f.navigation?f.children.length-1:f.slide,h.Right):A.transform+g(R,f.slide,t),transition:0,isSliding:!1}),G()}),1e3*f.transition),K.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(){return H(h.Left)}},null!==(o=f.leftArrow)&&void 0!==o?o:t.createElement(m,{direction:"left"})),t.createElement(C,s({},f,{transition:A.transition,items:E.current,transform:A.transform,slideCallback:function(t){H(t)},dragCallback:function(t){I({transform:t,transition:f.transition,isSliding:!1}),setTimeout((function(){return I(s(s({},A),{transition:0}))}),1e3*f.transition)},widthCallBack:function(t){M(t),I({transform:f.infinite?g(t,f.navigation?f.children.length-1:f.slide,h.Right):0,transition:0,isSliding:!1})},slideToDirection:H,current:D})),z.right&&t.createElement("div",{onClick:function(){return H(h.Right)},ref:Y},null!==(a=f.rightArrow)&&void 0!==a?a:t.createElement(m,{direction:"right"})),U&&t.createElement(T,{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",M="styles-module_slider__o0fqa",S="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 A=function(n){var i=n.children,s=n.className,a=n.leftIcon,l=n.rightIcon,c=e(null),u=r(!1),f=u[0],d=u[1],m=r({startX:0,scrollLeft:0}),v=m[0],g=m[1],p=function(){var t=c.current;return{left:!!t&&t.scrollLeft>0,right:!!t&&t.scrollWidth>t.scrollLeft+t.offsetWidth}},w=r(p()),y=w[0],_=w[1],k=function(t){_(p())},b=o((function(t){null!==t&&(Object.defineProperty(c,"current",{value:t}),_(p()),t.addEventListener("scroll",k))}),[c,i]),C=function(t){d(!1),_(p()),c.current.classList.remove(S)},L=function(t){var e=function(t){for(var e,n,r=c.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=(e=l,n=void 0,n=getComputedStyle(e),e.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=u)>=i){var f=t===h.Left?o-i:u;return(r.offsetWidth-f)*t}}return r.offsetWidth}(t),n=c.current.scrollLeft;E(500,e,n)},E=function(t,e,n){for(var r=0,i=0;r<=t;i++)window.setTimeout(T,r,i*e/100+n),r+=t/100},T=function(t){c.current.scrollLeft=t},x=function(e,n,r){return t.createElement("div",{"data-arrow":n,onClick:function(){return L(e)}},null!=r?r:t.createElement("button",null))};return t.createElement("div",{className:R+" "+s,"data-testid":"carousel"},y.left&&x(h.Right,"left",a),y.right&&x(h.Left,"right",l),t.createElement("div",{ref:b,onMouseDown:function(t){d(!0),g({startX:t.pageX-c.current.offsetLeft,scrollLeft:c.current.scrollLeft})},onMouseLeave:C,onMouseUp:C,onMouseMove:function(t){if(f){t.preventDefault(),c.current.classList.add(S);var e=t.pageX-c.current.offsetLeft-v.startX;c.current.scrollLeft=v.scrollLeft-e}},className:M},i))};export{x as Carousel,A as ScrollingCarousel}; | ||
import t,{useRef as e,useEffect as n,useState as r,useLayoutEffect as i,useCallback as o}from"react";var s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function a(t,e){void 0===e&&(e={});var n=e.insertAt;if(t&&"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=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(e){return t.createElement("button",{className:d,onClick:e.onClick,"data-direction":e.direction})};!function(t){t[t.Right=-1]="Right",t[t.Left=1]="Left"}(h||(h={}));var v=function(){function t(t,e){this.arr=t,this.currentIndex=e}return t.prototype.next=function(){var t=this.currentIndex,e=this.arr;return this.currentIndex=t<e.length-1?t+1:0,this.current()},t.prototype.prev=function(){var t=this.currentIndex,e=this.arr;return this.currentIndex=t>0&&t<e.length?t-1:e.length-1,this.current()},t.prototype.current=function(){return this.arr[this.currentIndex]},t}(),g=function(t,e,n){return n*t*e},p=function(t){var e=t.itemCount,n=t.itemsToShow,r=t.infinite,i=t.current,o=t.hideArrows;if(void 0!==o&&o)return{left:!1,right:!1};var s=e>n;return r?{left:s,right:s}:{left:s&&0!==i,right:s&&i+n<e}},w=function(t,e,n){if(!n)return t;for(var r=Array.from(t),i=new v(t,0),o=0;o<e;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,e,n,r,i){if(n&&n.length<e.length)return w(e,r,i);var o=t.map((function(t){return e.find((function(e){return t.key===e.key}))}));return o.some((function(t){return void 0===t}))?w(e,r,i):o}var b=function(t){var e=r("undefined"==typeof window?0:window.innerWidth),n=e[0],o=e[1];i((function(){var e=function(){var e=n-window.innerWidth;o(window.innerWidth),t(e)};return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[])},k=function(e){var n=r(200),i=n[0],a=n[1],l=o((function(t){if(null!==t){var n=t.getBoundingClientRect().width/e.show;a(n),e.widthCallBack(n)}}),[i]);e.responsive&&b((function(t){a(i-t)}));var d=r({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0}),m=d[0],v=d[1],g=function(t){t.persist(),v(s(s({},m),{isDown:!0,start:y(t),initial:e.transform,finished:!1}))},p=function(t){if(t.persist(),!m.finished){if(Math.abs(m.drag)<i*e.swipeOn)return e.dragCallback(e.transform),v({initial:e.transform,start:0,isDown:!1,drag:0,finished:!0,pointers:!0});e.slideCallback(m.drag>0?h.Right:h.Left),v(s(s({},m),{drag:0,isDown:!1,finished:!0,pointers:!0}))}},w=function(t){if(t.persist(),m.isDown){var n=y(t);v(s(s({},m),{drag:m.start-n,pointers:Math.abs(m.start-n)<e.triggerClickOn}))}},_=e.swiping?{onTouchCancel:p,onTouchEnd:p,onTouchMove:w,onTouchStart:g,onMouseDown:g,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("+(e.transform-m.drag)+"px)",transition:"transform "+e.transition+"s ease 0s",width:i*e.items.length}}),e.items.map((function(e,n){return t.createElement("div",{key:n,style:{width:i,pointerEvents:m.pointers?"all":"none"},className:c},e)}))))},L={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},E="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 C=function(e){var n=e.items,r=e.current,i=e.onClick,o=e.factory;return t.createElement("div",{className:E},n.map((function(e,n){return t.createElement("div",{onMouseOver:function(){return i(n)},key:n},o(r===n))})))},x=function(i){var o,a,u,c,f=s(s({},L),i),d=w(f.children,f.navigation?f.children.length-1:f.slide,f.infinite),y=r(d),b=y[0],E=y[1],x=e(d),R=r(0),T=R[0],M=R[1],A=r({transform:0,transition:0,isSliding:!1}),S=A[0],N=A[1],I=r(0),D=I[0],W=I[1],O=r(p({itemCount:f.children.length,itemsToShow:f.show,infinite:f.infinite,current:D,hideArrows:f.hideArrows})),z=O[0],X=O[1],B=(u=i.children,c=e(),n((function(){c.current=u})),c.current),q=r(0),K=q[0],Y=q[1],j=e(!1),F=e(null),P=e(),U="function"==typeof f.navigation;f.dynamic&&n((function(){var t=_(x.current,f.children,B,f.slide,f.infinite);E(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]),n((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,e){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 n=f.children,r=function(t,e,n,r){var i=t-r*e;return i<0?n+i:n<=i?i-n:i}(D,f.slide,n.length,t),i="number"==typeof e?e-D:-1*t,o=f.infinite?U?function(t,e,n,r,i,o){var s=function(t,e,n){var r=t+e>=n.length?t+e-n.length:t+e;return r<0?n.length+r:r}(n,i,t),a=Math.floor(e.length/2),l=new v(t,s),u=Array.from(e);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}(n,b,r,f.show,i,t):function(t,e,n,r,i,o){var s=new v(t,n),a=Array.from(e);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}(n,b,r,f.show,f.slide,t):b;f.infinite&&t===h.Right&&(E(o),x.current=o),N({transform:S.transform+Math.abs(i)*g(T,f.slide,t),transition:f.transition,isSliding:!0}),W(U&&"number"==typeof e?e:r),X(p({itemCount:n.length,itemsToShow:f.show,infinite:f.infinite,current:r,hideArrows:f.hideArrows})),setTimeout((function(){if(f.infinite){var n=U?function(t,e,n){return n===h.Left?t.slice(0,e):t.slice(e)}(t===h.Right?x.current:o,function(t,e,n,r){return"number"==typeof t?r===h.Right?t-e+1:n:-1*r}(e,r,i,t),t):function(t,e,n){return n===h.Left?t.slice(0,-1*e):t.slice(e)}(t===h.Right?x.current:o,f.slide,t);E(n),x.current=n}N({transform:f.infinite?g(T,f.navigation?f.children.length-1:f.slide,h.Right):S.transform+g(T,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(){return H(h.Left)}},null!==(o=f.leftArrow)&&void 0!==o?o:t.createElement(m,{direction:"left"})),t.createElement(k,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?g(t,f.navigation?f.children.length-1:f.slide,h.Right):0,transition:0,isSliding:!1})}})),z.right&&t.createElement("div",{onClick:function(){return H(h.Right)},ref:F},null!==(a=f.rightArrow)&&void 0!==a?a:t.createElement(m,{direction:"right"})),U&&t.createElement(C,{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",T="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 A=function(n){var i=n.children,s=n.className,a=n.leftIcon,l=n.rightIcon,u=e(null),c=r(!1),f=c[0],d=c[1],m=r({startX:0,scrollLeft:0}),v=m[0],g=m[1],p=function(){var t=u.current;return{left:!!t&&t.scrollLeft>0,right:!!t&&t.scrollWidth>t.scrollLeft+t.offsetWidth}},w=r(p()),y=w[0],_=w[1],b=function(t){_(p())},k=o((function(t){null!==t&&(Object.defineProperty(u,"current",{value:t}),_(p()),t.addEventListener("scroll",b))}),[u,i]),L=function(t){d(!1),_(p()),u.current.classList.remove(M)},E=function(t){var e=function(t){for(var e,n,r=u.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=(e=l,n=void 0,n=getComputedStyle(e),e.offsetWidth+(parseInt(n.marginLeft,10)||0)+(parseInt(n.marginRight,10)||0));if((o+=c)>=i){var f=t===h.Left?o-i:c;return(r.offsetWidth-f)*t}}return r.offsetWidth}(t),n=u.current.scrollLeft;C(500,e,n)},C=function(t,e,n){for(var r=0,i=0;r<=t;i++)window.setTimeout(x,r,i*e/100+n),r+=t/100},x=function(t){u.current.scrollLeft=t},A=function(e,n,r){return t.createElement("div",{"data-arrow":n,onClick:function(){return E(e)}},null!=r?r:t.createElement("button",null))};return t.createElement("div",{className:R+" "+s,"data-testid":"carousel"},y.left&&A(h.Right,"left",a),y.right&&A(h.Left,"right",l),t.createElement("div",{ref:k,onMouseDown:function(t){d(!0),g({startX:t.pageX-u.current.offsetLeft,scrollLeft:u.current.scrollLeft})},onMouseLeave:L,onMouseUp:L,onMouseMove:function(t){if(f){t.preventDefault(),u.current.classList.add(M);var e=t.pageX-u.current.offsetLeft-v.startX;u.current.scrollLeft=v.scrollLeft-e}},className:T},i))};export{x as Carousel,A as ScrollingCarousel}; |
@@ -27,3 +27,2 @@ import { FunctionComponent, ReactElement } from 'react'; | ||
triggerClickOn?: number; | ||
moveToFirstPositionThanClickItem?: boolean; | ||
} | ||
@@ -30,0 +29,0 @@ export interface CarouselState { |
@@ -18,5 +18,2 @@ import { FunctionComponent } from 'react'; | ||
triggerClickOn: number; | ||
current?: number; | ||
slideToDirection?: (direction: SlideDirection, target?: number) => void; | ||
moveToFirstPositionThanClickItem?: boolean; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { FC, ReactElement } from 'react'; | ||
import { FunctionComponent, ReactElement } from 'react'; | ||
import { Item } from '../../types/carousel'; | ||
export declare const ScrollingCarousel: FC<SliderProps>; | ||
export declare const ScrollingCarousel: FunctionComponent<SliderProps>; | ||
export interface SliderProps { | ||
@@ -9,3 +9,2 @@ children: Item[]; | ||
rightIcon?: ReactElement; | ||
moveToFirstPositionThanClickItem?: boolean; | ||
} | ||
@@ -12,0 +11,0 @@ export declare type Arrows = { |
@@ -14,3 +14,2 @@ module.exports = { | ||
testPathIgnorePatterns: ['<rootDir>/__tests__/__fixtures__/'], | ||
modulePathIgnorePatterns: ['<rootDir>/src/styles/'], | ||
transform: { | ||
@@ -17,0 +16,0 @@ '^.+\\.tsx?$': 'ts-jest', |
{ | ||
"name": "@trendyol-js/react-carousel", | ||
"version": "3.0.0-beta.61", | ||
"version": "3.0.0", | ||
"description": "Lightweight carousel component for react", | ||
@@ -41,2 +41,5 @@ "main": "dist/cjs/index.js", | ||
"peerDependencies": { | ||
"react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" | ||
}, | ||
"dependencies": { | ||
"react": "^16.13.1" | ||
@@ -60,3 +63,2 @@ }, | ||
"pretty-quick": "^2.0.1", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
@@ -63,0 +65,0 @@ "rollup": "^2.3.3", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26
-3.7%1
-50%73323
-6.08%2
100%46
-4.17%1126
-8.97%+ Added