{"version":3,"file":"imagesCarousel-CcOr907e.js","sources":["../../src/scripts/modules/imagesCarousel.ts"],"sourcesContent":["import { Component } from '@verndale/core';\r\nimport Swiper from 'swiper';\r\nimport { Navigation, Keyboard, Pagination, Controller, A11y } from 'swiper/modules';\r\nimport 'swiper/css/bundle';\r\n\r\nclass ImagesCarousel extends Component {\r\n  private separator: string;\r\n  public imagesCarousel: Swiper | null;\r\n\r\n  constructor(el: HTMLElement) {\r\n    super(el);\r\n    this.imagesCarousel = null;\r\n    this.separator = this.el.dataset.separator || '';\r\n    Swiper.use([Navigation, Keyboard, Pagination, Controller, A11y]);\r\n    this.initSwiper();\r\n  }\r\n\r\n  setupDefaults() {\r\n    this.dom = {\r\n      el: this.el,\r\n      swiperContainer: this.el.querySelector<HTMLElement>('.swiper'),\r\n      swiperWrapper: this.el.querySelector<HTMLElement>('.swiper-wrapper'),\r\n      swiperItems: this.el.querySelectorAll<HTMLElement>('.swiper-slide'),\r\n      pagination: this.el.querySelector<HTMLElement>('.images-carousel__slider-pagination'),\r\n      prevButton: this.el.querySelector<HTMLElement>('.btn-previous-slide'),\r\n      nextButton: this.el.querySelector<HTMLElement>('.btn-next-slide'),\r\n      controlsContainer: this.el.querySelector<HTMLElement>(\r\n        '.images-carousel__slider-controls-container'\r\n      ),\r\n      captions: this.el.querySelectorAll<HTMLElement>('.images-carousel__slide-caption')\r\n    };\r\n  }\r\n\r\n  addListeners() {\r\n    window.addEventListener('resize', this.initSwiper.bind(this));\r\n  }\r\n\r\n  initSwiper() {\r\n    if (\r\n      this.imagesCarousel &&\r\n      this.imagesCarousel.destroy &&\r\n      typeof this.imagesCarousel.destroy === 'function'\r\n    )\r\n      this.imagesCarousel.destroy();\r\n\r\n    this.imagesCarousel = new Swiper(this.dom.swiperContainer as HTMLElement, {\r\n      pagination: {\r\n        el: this.dom.pagination as HTMLElement,\r\n        type: 'custom',\r\n        renderCustom: (_self, current, total) => {\r\n          return `${current} ${this.separator} ${total}`;\r\n        }\r\n      },\r\n      on: {\r\n        init: () => {\r\n          if ((this.dom.captions as NodeList).length > 0) {\r\n            let maxCaptionHeight = 0;\r\n            (this.dom.captions as NodeList).forEach(caption => {\r\n              const captionHeight = (caption as HTMLElement).offsetHeight;\r\n              if (captionHeight > maxCaptionHeight) {\r\n                maxCaptionHeight = captionHeight;\r\n              }\r\n            });\r\n            (this.dom.controlsContainer as HTMLElement).style.setProperty(\r\n              '--caption-height',\r\n              `${maxCaptionHeight - 1}px`\r\n            );\r\n            (this.dom.swiperWrapper as HTMLElement).style.height = 'fit-content';\r\n          } else {\r\n            (this.dom.controlsContainer as HTMLElement).style.setProperty('--caption-height', '0');\r\n          }\r\n        }\r\n      },\r\n      a11y: {\r\n        enabled: true,\r\n        prevSlideMessage: 'Previous slide',\r\n        nextSlideMessage: 'Next slide'\r\n      },\r\n      navigation: {\r\n        nextEl: this.dom.nextButton as HTMLElement,\r\n        prevEl: this.dom.prevButton as HTMLElement\r\n      },\r\n      autoHeight: true,\r\n      slidesPerView: 1,\r\n      loop: true\r\n    });\r\n  }\r\n}\r\n\r\nexport default ImagesCarousel;\r\n"],"names":["ImagesCarousel","Component","el","__publicField","Swiper","Navigation","Keyboard","Pagination","Controller","A11y","_self","current","total","maxCaptionHeight","caption","captionHeight"],"mappings":"gZAKA,MAAMA,UAAuBC,CAAU,CAIrC,YAAYC,EAAiB,CAC3B,MAAMA,CAAE,EAJFC,EAAA,kBACDA,EAAA,uBAIL,KAAK,eAAiB,KACtB,KAAK,UAAY,KAAK,GAAG,QAAQ,WAAa,GAC9CC,EAAO,IAAI,CAACC,EAAYC,EAAUC,EAAYC,EAAYC,CAAI,CAAC,EAC/D,KAAK,WAAW,CAAA,CAGlB,eAAgB,CACd,KAAK,IAAM,CACT,GAAI,KAAK,GACT,gBAAiB,KAAK,GAAG,cAA2B,SAAS,EAC7D,cAAe,KAAK,GAAG,cAA2B,iBAAiB,EACnE,YAAa,KAAK,GAAG,iBAA8B,eAAe,EAClE,WAAY,KAAK,GAA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