{"version":3,"file":"full-height-carousel-BRJsgCKh.js","sources":["../../../../src/scripts/modules/full-height-carousel.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport '../../scss/modules/full-height-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 FullHeightCarousel 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: 3,\n desktop: 3,\n wide: 4\n };\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 = 'fh-carousel__pagination';\n this.spanPagination.textContent = `${this.index.toString()}/${this.of.toString()}`;\n\n this.initSwiper(initialBreakpoint());\n }\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: string) => {\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('fh-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('fh-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: '0',\n pagination: false,\n breakpoints: {\n [BREAKPOINTS.tablet - 1]: {\n perPage: 1,\n gap: '16px',\n padding: '40px',\n type: 'loop'\n },\n [BREAKPOINTS.tabletLandscape - 1]: {\n perPage: 2,\n gap: '16px'\n },\n [BREAKPOINTS.wide - 1]: {\n perPage: 3,\n gap: '24px'\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 FullHeightCarousel;\n"],"names":["FullHeightCarousel","Component","el","__publicField","_a","initialBreakpoint","eventBus","breakpoint","_b","Splide","BREAKPOINTS","index"],"mappings":"yXAQA,MAAMA,UAA2BC,CAAU,CAOzC,YAAYC,EAAiB,OAC3B,MAAMA,CAAE,EAPFC,EAAA,cAAwB,MACxBA,EAAA,aAAQ,GACRA,EAAA,UAAK,GACLA,EAAA,sBAAyC,MACzCA,EAAA,4BA6CRA,EAAA,yBAAoB,IAAM,OACpB,KAAK,kBACPC,EAAA,KAAK,GACF,cAAc,sBAAsB,IADvC,MAAAA,EAEI,sBAAsB,WAAY,KAAK,gBAE/C,GA9CE,KAAK,oBAAsB,CACzB,OAAQ,EACR,OAAQ,EACR,gBAAiB,EACjB,QAAS,EACT,KAAM,CACR,EAEA,KAAK,MAAQ,EACb,KAAK,KAAMA,EAAA,KAAK,IAAI,SAAT,YAAAA,EAA8B,SAAU,EAC9C,KAAA,eAAiB,SAAS,cAAc,GAAG,EAChD,KAAK,eAAe,UAAY,0BAC3B,KAAA,eAAe,YAAc,GAAG,KAAK,MAAM,SAAU,CAAA,IAAI,KAAK,GAAG,SAAU,CAAA,GAE3E,KAAA,WAAWC,GAAmB,CAAA,CAGrC,eAAgB,CACd,KAAK,IAAM,CACT,OAAQ,KAAK,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