{"version":3,"file":"img-carousel-BCmro9wF.js","sources":["../../../../src/scripts/modules/img-carousel.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport '../../scss/modules/img-carousel.scss';\nimport 'swiper/css';\nimport { BREAKPOINTS } from '../helpers/helpers';\nimport { eventBus, initialBreakpoint } from '../helpers/resize';\nimport Splide from '@splidejs/splide';\nimport '@splidejs/splide/css';\n\nclass ImageCarousel extends Component {\n private swiper: Splide | null = null;\n private index = 1;\n private of = 0;\n private spanPagination: HTMLSpanElement | null = null;\n private slidesPerBreakpoint: { [key: string]: number };\n\n constructor(el: HTMLElement) {\n super(el);\n\n this.slidesPerBreakpoint = {\n mobile: 1,\n tablet: 2,\n tabletLandscape: 2,\n desktop: 3,\n wide: 4\n };\n this.index = 1;\n this.of = (this.dom.slides as NodeList)?.length || 0;\n this.spanPagination = document.createElement('p');\n this.spanPagination.className = 'img-carousel__pagination';\n this.spanPagination.textContent = `${this.index.toString()}/${this.of.toString()}`;\n\n this.initSwiper(initialBreakpoint());\n }\n setupDefaults() {\n this.dom = {\n swiper: this.el.querySelector('.splide'),\n slides: this.el.querySelectorAll('.splide__slide')\n };\n }\n\n addListeners(): void {\n eventBus.subscribe('breakpointChange', breakpoint => {\n this.initSwiper(breakpoint);\n });\n }\n\n checkIfCarouselNeeded(breakpoint: string) {\n if (this.of <= this.slidesPerBreakpoint[breakpoint]) {\n if (this.swiper) {\n this.swiper.destroy();\n this.swiper = null;\n }\n this.el?.classList.add('img-carousel__no-carousel');\n }\n }\n\n onMountPagination = () => {\n if (this.spanPagination) {\n this.el\n .querySelector('.splide__arrow--prev')\n ?.insertAdjacentElement('afterend', this.spanPagination);\n }\n };\n\n initSwiper(breakpoint: string) {\n this.el?.classList.remove('img-carousel__no-carousel');\n this.swiper?.destroy();\n this.swiper = null;\n if (!this.swiper) {\n this.swiper = new Splide(this.dom.swiper as HTMLElement, {\n type: 'loop',\n rewind: false,\n perMove: 1,\n perPage: 4,\n gap: '24px',\n padding: '120px',\n pagination: false,\n breakpoints: {\n [BREAKPOINTS.tablet - 1]: {\n perPage: 1,\n gap: '16px',\n padding: '40px'\n },\n [BREAKPOINTS.tabletLandscape - 1]: {\n perPage: 2,\n gap: '16px',\n padding: '60px'\n },\n [BREAKPOINTS.wide - 1]: {\n perPage: 3,\n gap: '24px',\n padding: '120px'\n }\n }\n }).mount();\n\n this.swiper.on('resized', () => {\n this.onMountPagination();\n });\n this.onMountPagination();\n this.swiper.on('move', index => {\n if (this.spanPagination) {\n this.index = index + 1;\n this.spanPagination.textContent = `${this.index.toString()}/${this.of.toString()}`;\n }\n });\n }\n\n this.checkIfCarouselNeeded(breakpoint);\n }\n}\n\nexport default ImageCarousel;\n"],"names":["ImageCarousel","Component","el","__publicField","_a","initialBreakpoint","eventBus","breakpoint","_b","Splide","BREAKPOINTS","index"],"mappings":"8UAQA,MAAMA,UAAsBC,CAAU,CAOpC,YAAYC,EAAiB,OAC3B,MAAMA,CAAE,EAPFC,EAAA,cAAwB,MACxBA,EAAA,aAAQ,GACRA,EAAA,UAAK,GACLA,EAAA,sBAAyC,MACzCA,EAAA,4BA2CRA,EAAA,yBAAoB,IAAM,OACpB,KAAK,kBACPC,EAAA,KAAK,GACF,cAAc,sBAAsB,IADvC,MAAAA,EAEI,sBAAsB,WAAY,KAAK,gBAC7C,GA3CA,KAAK,oBAAsB,CACzB,OAAQ,EACR,OAAQ,EACR,gBAAiB,EACjB,QAAS,EACT,KAAM,CAAA,EAER,KAAK,MAAQ,EACb,KAAK,KAAMA,EAAA,KAAK,IAAI,SAAT,YAAAA,EAA8B,SAAU,EAC9C,KAAA,eAAiB,SAAS,cAAc,GAAG,EAChD,KAAK,eAAe,UAAY,2BAC3B,KAAA,eAAe,YAAc,GAAG,KAAK,MAAM,SAAU,CAAA,IAAI,KAAK,GAAG,SAAA,CAAU,GAE3E,KAAA,WAAWC,GAAmB,CACrC,CACA,eAAgB,CACd,KAAK,IAAM,CACT,OAAQ,KAAK,GAAG,cAA8B,SAAS,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