function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i{function i(e){var t=this;if(_classCallCheck(this,i),this.config=i.mergeSettings(e),this.parentSelector="string"==typeof this.config.parentSelector?document.querySelector(this.config.parentSelector):this.config.parentSelector,this.selector="string"==typeof this.config.selector?document.querySelector(this.config.selector):this.config.selector,this.parentSelector&&(this.selector=this.parentSelector.querySelector(".botiga-carousel-stage")),null===this.selector)throw new Error("Something wrong with your selector 😭");if("true"===this.parentSelector.getAttribute("data-initialized"))return!1;this.resolveSlidesNumber(),this.selectorWidth=this.selector.offsetWidth,this.innerElements=[].slice.call(this.selector.children),this.currentSlide=this.config.loop?this.config.startIndex%this.innerElements.length:Math.max(0,Math.min(this.config.startIndex,this.innerElements.length-this.perPage)),this.transformProperty=i.webkitOrNot(),["resizeHandler","touchstartHandler","touchendHandler","touchmoveHandler","mousedownHandler","mouseupHandler","mouseleaveHandler","mousemoveHandler","clickHandler","navNextHandler","navPrevHandler"].forEach(function(e){t[e]=t[e].bind(t)}),this.init()}return _createClass(i,[{key:"attachEvents",value:function(){window.addEventListener("resize",this.resizeHandler),this.config.draggable&&(this.pointerDown=!1,this.drag={startX:0,endX:0,startY:0,letItGo:null,preventClick:!1},this.selector.addEventListener("touchstart",this.touchstartHandler),this.selector.addEventListener("touchend",this.touchendHandler),this.selector.addEventListener("touchmove",this.touchmoveHandler),this.selector.addEventListener("mousedown",this.mousedownHandler),this.selector.addEventListener("mouseup",this.mouseupHandler),this.selector.addEventListener("mouseleave",this.mouseleaveHandler),this.selector.addEventListener("mousemove",this.mousemoveHandler),this.selector.addEventListener("click",this.clickHandler),this.parentSelector.querySelector(".botiga-carousel-nav-next").addEventListener("click",this.navNextHandler),this.parentSelector.querySelector(".botiga-carousel-nav-prev").addEventListener("click",this.navPrevHandler))}},{key:"detachEvents",value:function(){window.removeEventListener("resize",this.resizeHandler),this.selector.removeEventListener("touchstart",this.touchstartHandler),this.selector.removeEventListener("touchend",this.touchendHandler),this.selector.removeEventListener("touchmove",this.touchmoveHandler),this.selector.removeEventListener("mousedown",this.mousedownHandler),this.selector.removeEventListener("mouseup",this.mouseupHandler),this.selector.removeEventListener("mouseleave",this.mouseleaveHandler),this.selector.removeEventListener("mousemove",this.mousemoveHandler),this.selector.removeEventListener("click",this.clickHandler),this.parentSelector.querySelector(".botiga-carousel-nav-next").removeEventListener("click",this.navNextHandler),this.parentSelector.querySelector(".botiga-carousel-nav-prev").removeEventListener("click",this.navPrevHandler)}},{key:"init",value:function(){this.buildNavigation(),this.attachEvents(),this.selector.style.overflow="hidden",this.selector.style.direction=this.config.rtl?"rtl":"ltr",this.buildSliderFrame(),this.config.onInit.call(this),this.parentSelector.querySelector(".botiga-carousel-stage").classList.add("show"),null!==this.parentSelector&&this.parentSelector.setAttribute("data-initialized",!0)}},{key:"buildNavigation",value:function(){var e=document.createElement("a"),t=document.createElementNS("http://www.w3.org/2000/svg","svg"),i=document.createElement("a"),r=document.createElementNS("http://www.w3.org/2000/svg","svg");e.role="button",e.href="#",e.className="botiga-carousel-nav botiga-carousel-nav-next",t.setAttribute("width",18),t.setAttribute("height",18),t.setAttribute("viewBox","0 0 10 16"),t.setAttribute("fill","none"),t.setAttribute("xmlns","http://www.w3.org/2000/svg"),t.setAttribute("class","stroke-based"),t.innerHTML='',e.append(t),this.parentSelector.querySelector(".botiga-carousel-wrapper").append(e),i.role="button",i.href="#",i.className="botiga-carousel-nav botiga-carousel-nav-prev",r.setAttribute("width",18),r.setAttribute("height",18),r.setAttribute("viewBox","0 0 10 16"),r.setAttribute("fill","none"),r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r.setAttribute("class","stroke-based"),r.innerHTML='',i.append(r),this.parentSelector.querySelector(".botiga-carousel-wrapper").append(i)}},{key:"buildSliderFrame",value:function(){if(null!==this.parentSelector.querySelector(".botiga-carousel-nav-next")&&this.innerElements.length<=this.perPage)return this.parentSelector.querySelector(".botiga-carousel-nav-next").remove(),this.parentSelector.querySelector(".botiga-carousel-nav-prev").remove(),!1;var e=(this.selectorWidth+this.config.margin)/this.perPage,t=this.config.loop?this.innerElements.length+2*this.perPage:this.innerElements.length,i=(this.sliderFrame=document.createElement("div"),this.sliderFrame.style.width=e*t+"px",this.enableTransition(),this.config.draggable&&(this.selector.style.cursor="-webkit-grab"),document.createDocumentFragment());if(this.config.loop)for(var r=this.innerElements.length-this.perPage;r=e&&(this.perPage=this.config.perPage[e])}},{key:"prev",value:function(){var e,t,i,r,n=0this.innerElements.length-this.perPage?(this.disableTransition(),t=this.currentSlide-this.innerElements.length,i=this.perPage,i=(this.config.rtl?1:-1)*(t+i)*(this.selectorWidth/this.perPage),r=this.config.draggable?this.drag.endX-this.drag.startX:0,this.sliderFrame.style[this.transformProperty]="translate3d(".concat(i+r,"px, 0, 0)"),this.currentSlide=t+n):this.currentSlide=this.currentSlide+n:this.currentSlide=Math.min(this.currentSlide+n,this.innerElements.length-this.perPage),e!==this.currentSlide&&(this.slideToCurrent(this.config.loop),this.config.onChange.call(this),s)&&s.call(this))}},{key:"disableTransition",value:function(){this.sliderFrame.style.webkitTransition="all 0ms ".concat(this.config.easing),this.sliderFrame.style.transition="all 0ms ".concat(this.config.easing)}},{key:"enableTransition",value:function(){if(void 0===this.sliderFrame)return!1;this.sliderFrame.style.webkitTransition="all ".concat(this.config.duration,"ms ").concat(this.config.easing),this.sliderFrame.style.transition="all ".concat(this.config.duration,"ms ").concat(this.config.easing)}},{key:"goTo",value:function(e,t){var i;this.innerElements.length<=this.perPage||(i=this.currentSlide,this.currentSlide=this.config.loop?e%this.innerElements.length:Math.min(Math.max(e,0),this.innerElements.length-this.perPage),i!==this.currentSlide&&(this.slideToCurrent(),this.config.onChange.call(this),t)&&t.call(this))}},{key:"slideToCurrent",value:function(e){var t=this,i=this.config.loop?this.currentSlide+this.perPage:this.currentSlide,r=(this.config.rtl?1:-1)*i*((this.selectorWidth+this.config.margin)/this.perPage);if(void 0===this.sliderFrame)return!1;e?requestAnimationFrame(function(){requestAnimationFrame(function(){t.enableTransition(),t.sliderFrame.style[t.transformProperty]="translate3d("+r+"px, 0, 0)"})}):(this.enableTransition(),this.sliderFrame.style[this.transformProperty]="translate3d("+r+"px, 0, 0)")}},{key:"updateAfterDrag",value:function(){var e=(this.config.rtl?-1:1)*(this.drag.endX-this.drag.startX),t=Math.abs(e),i=this.config.multipleDrag?Math.ceil(t/(this.selectorWidth/this.perPage)):1,r=0this.innerElements.length-this.perPage;0this.config.threshold&&this.innerElements.length>this.perPage?this.prev(i):e<0&&t>this.config.threshold&&this.innerElements.length>this.perPage&&this.next(i),this.slideToCurrent(r||n)}},{key:"resizeHandler",value:function(){this.resolveSlidesNumber(),this.currentSlide+this.perPage>this.innerElements.length&&(this.currentSlide=this.innerElements.length<=this.perPage?0:this.innerElements.length-this.perPage),this.selectorWidth=this.selector.offsetWidth,this.buildSliderFrame()}},{key:"clearDrag",value:function(){this.drag={startX:0,endX:0,startY:0,letItGo:null,preventClick:this.drag.preventClick}}},{key:"touchstartHandler",value:function(e){-1===["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.target.nodeName)&&(e.stopPropagation(),this.pointerDown=!0,this.drag.startX=e.touches[0].pageX,this.drag.startY=e.touches[0].pageY)}},{key:"touchendHandler",value:function(e){e.stopPropagation(),this.pointerDown=!1,this.enableTransition(),this.drag.endX&&this.updateAfterDrag(),this.clearDrag()}},{key:"touchmoveHandler",value:function(e){var t;e.stopPropagation(),null===this.drag.letItGo&&(this.drag.letItGo=Math.abs(this.drag.startY-e.touches[0].pageY)=this.innerElements.length)throw new Error("Item to remove doesn't exist 😭");var i=ethis.innerElements.length+1)throw new Error("Unable to inset it at this index 😭");if(-1!==this.innerElements.indexOf(e))throw new Error("The same item in a carousel? Really? Nope 😭");var r=0<(t<=this.currentSlide)&&this.innerElements.length;this.currentSlide=r?this.currentSlide+1:this.currentSlide,this.innerElements.splice(t,0,e),this.buildSliderFrame(),i&&i.call(this)}},{key:"prepend",value:function(e,t){this.insert(e,0),t&&t.call(this)}},{key:"append",value:function(e,t){this.insert(e,this.innerElements.length+1),t&&t.call(this)}},{key:"destroy",value:function(){var e=0