!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Spider=e()}(this,(function(){"use strict";function t(t,i,n){return i=s(i),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,e()?Reflect.construct(i,n||[],s(t).constructor):i.apply(t,n))}function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(e=function(){return!!t})()}function i(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;nt.length)&&(e=t.length);for(var i=0,n=new Array(e);i2&&void 0!==arguments[2]?arguments[2]:{},r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];try{i=new CustomEvent(e,{bubbles:r,cancelable:o,detail:n})}catch(t){(i=document.createEvent("CustomEvent")).initCustomEvent(e,r,o,n)}t.dispatchEvent(i)}function f(t){var e=this;t&&(this.dom=t,this.getId=function(){return Number(t.getAttribute("data-id"))},this.top=function(){return e.dom.getBoundingClientRect().top},this.left=function(){return e.dom.getBoundingClientRect().left},this.right=function(){return e.left()+e.offsetWidth()},this.offsetWidth=function(){return e.dom.offsetWidth},this.style=function(t,i){e.dom.style[t]=i},this.active=function(){e.dom.setAttribute("data-active","true")},this.inactive=function(){e.dom.removeAttribute("data-active")},this.visible=function(){e.dom.setAttribute("data-visible","true")},this.invisible=function(){e.dom.removeAttribute("data-visible")},this.isActive=function(){return"true"===e.dom.getAttribute("data-active")},this.isVisible=function(){return"true"===e.dom.getAttribute("data-visible")})}var h=function(t){throw new Error("".concat(t," is abstract method. Override it with the child class."))},v=function(){return o((function t(e,i){var r=this;n(this,t),this.dom=e,this.args=i,this.slides=[].slice.call(this.dom.querySelectorAll(this.args.slide)).map((function(t){return new f(t)})),this.historyActiveSlideIds=[],this.dragStartX=void 0,this.dragStartScrollLeft=void 0,this.dragStartTime=void 0,this.isDrag=!1;var o=10,a=void 0,s=function t(){clearTimeout(a);var e,i=(e=r.slides.map((function(t){return t.top()}))).filter((function(t,i){return i===e.lastIndexOf(t)}));if(1i.length||1>n.length)return this.getSlide(0);if((null==i||null===(t=i[i.length-1])||void 0===t?void 0:t.getId())===(null==n||null===(e=n[n.length-1])||void 0===e?void 0:e.getId()))return this.getSlide(0);var r=this.getCurrent(),o=this.getSlide(i.findIndex((function(t){return r===t.getId()}))+1);return o||this.getSlide(0)}},{key:"getActiveSlides",value:function(){return this.getSlides().filter((function(t){return t.isActive()}))}},{key:"getVisibleSlides",value:function(){return this.getSlides().filter((function(t){return t.isVisible()}))}},{key:"setCurrentForWheel",value:function(){h("abstractCanvas.setCurrentForWheel")}},{key:"moveTo",value:function(t){h("abstractCanvas.moveTo")}},{key:"beforeInit",value:function(){}},{key:"afterInit",value:function(){}}])}(),g=function(e){function i(e,r){var o;if(n(this,i),(o=t(this,i,[e,r])).smoothScrollToTimerId=void 0,o.canvasScrollTimerId=void 0,o.setScrollLeft=function(t){return o.dom.scrollLeft=t},o.setScrollLeft(0),o.handleScroll=o.handleScroll.bind(o),o.dom.addEventListener("scroll",o.handleScroll,!1),"undefined"!=typeof IntersectionObserver){var a=new IntersectionObserver((function(t){t.forEach((function(t){var e=new f(t.target);t.isIntersecting?e.active():e.inactive()}))}),{root:o.dom,rootMargin:"0px",threshold:[.5,1]}),s=new IntersectionObserver((function(t){t.forEach((function(t){var e=new f(t.target);t.isIntersecting?e.visible():e.invisible()}))}),{root:o.dom,rootMargin:"0px -1px",threshold:[0]});o.getSlides().forEach((function(t){a.observe(t.dom),s.observe(t.dom)}))}return o}return a(i,e),o(i,[{key:"afterInit",value:function(){this.dom.classList.remove("is-scrolling")}},{key:"handleScroll",value:function(){var t=this;clearTimeout(this.canvasScrollTimerId),this.isDrag||(this.dom.classList.add("is-scrolling"),this.canvasScrollTimerId=setTimeout((function(){var e=t.left(),i=t.getCurrentSlide().left();1e){var n=this.scrollLeft()-i/e*100;this.moveToLeft(n)}}},{key:"afterHandleMouseup",value:function(){this.handleScroll()}},{key:"setCurrentForWheel",value:function(){var t=this,e=this.getSlides().reduce((function(e,i){var n=e.offsetWidth()-Math.abs(t.left()-e.left());return i.offsetWidth()-Math.abs(t.left()-i.left())>n?i:e}));this.setCurrent(e.getId()),d(this.dom,"setCurrentForWheel")}},{key:"moveTo",value:function(t){var e=this.scrollLeft()+(t.left()-this.left());this.moveToLeft(e)}},{key:"moveToLeft",value:function(t){var e=this,i=this.scrollLeft();clearInterval(this.smoothScrollToTimerId);var n=0=c||"prev"===n&&r>=t&&r<=c?(e.setScrollLeft(r),c=r):(clearInterval(e.smoothScrollToTimerId),e.setScrollLeft(t))}),r)}}}}])}(v),m=function(e){function i(e,r){var o;return n(this,i),o=t(this,i,[e,r]),e.addEventListener("updateCurrent",(function(){o.getSlides().forEach((function(t){o.getCurrent()===t.getId()?t.active():t.inactive()}))}),!1),o}return a(i,e),o(i,[{key:"afterInit",value:function(){this.dom.classList.remove("is-fading"),this.slides.forEach((function(t,e){0!==e?(t.style("left","".concat(-1*e*100,"%")),t.inactive()):t.active()}))}},{key:"handleMouseup",value:function(t){var e=t.clientX-this.dragStartX;if(0e){var n=this.getNextSlide();n&&this.setCurrent(n.getId())}}},{key:"moveTo",value:function(t){var e=this;if(t.isActive()){this.dom.classList.add("is-fading"),[].slice.call(this.dom.querySelectorAll('[data-active="false"]')).map((function(t){return new f(t)})).forEach((function(t){return t.inactive()})),t.active();t.dom.addEventListener("transitionend",(function i(){t.dom.removeEventListener("transitionend",i,!1),d(e.dom,"fadeEnd"),e.dom.classList.remove("is-fading")}),!1)}}}])}(v);function p(t,e){return t.addEventListener("click",(function(){return e.handleClick()}),!1),this}function y(t,e){return t.addEventListener("click",(function(){return e.handleClick()}),!1),this}function b(t,e){return t.addEventListener("click",(function(){return e.handleClick()}),!1),this}function S(t,e){return t.addEventListener("click",(function(){return e.handleClick()}),!1),this}function w(t,e){var i=this;return this.active=function(){t.setAttribute("aria-current","true")},this.inactive=function(){t.removeAttribute("aria-current")},e.initial?this.active():this.inactive(),t.addEventListener("click",(function(t){return e.handleClick(t)}),!1),new MutationObserver((function(t){t.forEach((function(t){new f(t.target).isActive()?i.active():i.inactive()}))})).observe(e.relatedSlide.dom,{attributes:!0,attributeFilter:["data-active"]}),this}function k(t){var e=this;t&&(this.dom=t,this.getInterval=function(){return Number(e.dom.getAttribute("data-interval"))},this.getDuration=function(){return Number(e.dom.getAttribute("data-duration"))},this.getFade=function(){return"true"===e.dom.getAttribute("data-fade")},this.getShuffle=function(){return"true"===e.dom.getAttribute("data-shuffle")},this.setInitialized=function(t){return t&&d(e.dom,"initialized"),e.dom.setAttribute("data-initialized",t?"true":"false")},this.setProperty=function(t,i){e.dom.style.setProperty(t,i)})}var A=function(t,e){var i=[];return[].slice.call(t).forEach((function(t){var n=t.getAttribute("data-initialized");if("false"===n||!n){var r=new I(t,e);r.initialized&&i.push(r)}})),i},L=function(t,e){return new function(){var i=this,n=t.cloneNode(!0),r=void 0,o=void 0;this.stopAutoPlay=function(){clearInterval(o),t.classList.remove("is-auto-playing")},this.startAutoPlay=function(e){i.stopAutoPlay(),o=setInterval((function(){i.next()}),e),t.classList.add("is-auto-playing")},this.initialized=!1,this.destroy=function(){var e=n.cloneNode(!0);t.parentNode.insertBefore(e,t),t.remove(),t=e,i.initialized=!1},this.init=function(){if(!i.initialized){var n=new k(t),o=t.querySelector(e.root);if(o){var a=n.getDuration();a&&n.setProperty("--spider--transition-duration","".concat(a/1e3,"s"));var s=t.querySelector(e.canvas);if(s){var u=t.querySelector(e.reference)||o;if(u){var c=t.querySelector(e.prevArrow),d=t.querySelector(e.nextArrow),f=t.querySelector(e.startButton),h=t.querySelector(e.stopButton),v=t.querySelector(e.dots);if(n.getShuffle()){var A=[].slice.call(s.querySelectorAll(e.slide)),L=[].slice.call(v.querySelectorAll(":scope > ".concat(e.dot)));(function(t){for(var e=l(t),i=e.length-1;i>0;i--){var n=Math.floor(Math.random()*(i+1)),r=[e[n],e[i]];e[i]=r[0],e[n]=r[1]}return e})(A.keys()).forEach((function(t){s.appendChild(s.removeChild(A[t])),v.appendChild(v.removeChild(L[t]))}))}var I=n.getFade()?m:g;r=new I(s,{slide:e.slide,reference:u,container:n});var C=n.getInterval();01&&void 0!==arguments[1]?arguments[1]:{},i={root:".spider",reference:".spider__reference",canvas:".spider__canvas",slide:".spider__slide",prevArrow:'.spider__arrow[data-direction="prev"]',nextArrow:'.spider__arrow[data-direction="next"]',startButton:".spider__start",stopButton:".spider__stop",dots:".spider__dots",dot:".spider__dot"},n={};for(var r in i)n[r]=void 0!==e[r]?e[r]:i[r];if("string"==typeof t){if(t.match(/^#/)){var o=document.querySelector(t);if(!o)return;return L(o,n)}var a=document.querySelectorAll(t);if(1>a.length)return;return A(a,n)}return!0==t instanceof NodeList?A(t,n):!0==t instanceof HTMLElement?L(t,n):void 0}return I}));