{"version":3,"file":"scroll-image-grid-Bi3gf88n.js","sources":["../../../../src/scripts/modules/scroll-image-grid.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport Swiper from 'swiper';\nimport { Navigation, Pagination, A11y, Keyboard } from 'swiper/modules';\nimport '../../scss/modules/full-height-carousel.scss';\nimport 'swiper/css';\nimport { BREAKPOINTS } from '../helpers/helpers';\nimport { eventBus, initialBreakpoint } from '../helpers/resize';\n\nclass ScrollImageGrid extends Component {\n private swiper: Swiper | null = null;\n private isMobile = false;\n\n constructor(el: HTMLElement) {\n super(el);\n\n this.handleBreakpointChange(initialBreakpoint());\n }\n\n setupDefaults() {\n this.dom = {\n swiper: this.el.querySelector('.swiper'),\n slides: this.el.querySelectorAll('.swiper-slide'),\n pagination: this.el.querySelector('.swiper-pagination'),\n next: this.el.querySelector('.swiper-button-next'),\n prev: this.el.querySelector('.swiper-button-prev'),\n stickyContainer: this.el.querySelector('.scroll-image-grid__static-card'),\n stickyCard: this.el.querySelector('.scroll-image-grid__static-card .card')\n };\n }\n\n addListeners(): void {\n eventBus.subscribe('breakpointChange', this.handleBreakpointChange.bind(this));\n window.addEventListener('scroll', this.handleScroll.bind(this));\n }\n\n handleScroll() {\n const tabletLandscapeBreakpoint = 1024; // Define the breakpoint for tablet landscape\n\n // If the window's width is less than or equal to the breakpoint, return immediately\n if (window.innerWidth <= tabletLandscapeBreakpoint) {\n this.stickyCardCleanup();\n return;\n }\n\n const stickyCard = this.dom.stickyCard as HTMLElement;\n const parentContainer = this.dom.stickyContainer as HTMLElement;\n\n stickyCard.style.width = `${parentContainer.offsetWidth}px`;\n\n // Calculate the initial top position of the sticky card relative to the document\n let offsetParent = stickyCard.offsetParent as HTMLElement;\n while (offsetParent != null) {\n offsetParent = offsetParent.offsetParent as HTMLElement;\n }\n\n // Calculate the top and bottom boundaries of the parent container relative to the document\n let parentContainerTop = parentContainer.offsetTop;\n let parentContainerBottom = parentContainerTop + parentContainer.offsetHeight;\n offsetParent = parentContainer.offsetParent as HTMLElement;\n while (offsetParent != null) {\n parentContainerTop += offsetParent.offsetTop;\n parentContainerBottom += offsetParent.offsetTop;\n offsetParent = offsetParent.offsetParent as HTMLElement;\n }\n\n const scrollY = window.scrollY;\n const bottomParent = parentContainerBottom - stickyCard.offsetHeight;\n\n if (scrollY > parentContainerTop && scrollY < bottomParent) {\n stickyCard.style.position = 'fixed';\n stickyCard.style.top = '100px'; // Stick to the top of the viewport\n } else if (scrollY >= bottomParent) {\n stickyCard.style.position = 'absolute';\n stickyCard.style.top = 'auto'; // Reset to the initial position\n stickyCard.style.bottom = '0'; // Stick to the bottom of the parent container\n } else if (scrollY < parentContainerTop) {\n stickyCard.style.position = 'relative';\n stickyCard.style.top = 'auto'; // Reset to the initial position\n }\n }\n\n initSwiper() {\n this.stickyCardCleanup();\n if (\n (this.isMobile && (this.dom.slides as NodeList).length < 2) ||\n (!this.isMobile && (this.dom.slides as NodeList).length < 3)\n ) {\n this.el.classList.add('scroll-image-grid--single-slide');\n return;\n } else {\n this.el.classList.remove('scroll-image-grid--single-slide');\n }\n\n if (!this.swiper) {\n this.swiper = new Swiper(this.dom.swiper as HTMLElement, {\n modules: [Navigation, Pagination, A11y, Keyboard],\n slidesPerView: 1,\n spaceBetween: 16,\n loop: true,\n breakpoints: {\n [BREAKPOINTS.tablet]: {\n slidesPerView: 2,\n spaceBetween: 16\n },\n [BREAKPOINTS.tabletLandscape]: {\n slidesPerView: 2,\n spaceBetween: 16\n }\n },\n pagination: {\n el: this.dom.pagination as HTMLElement,\n type: 'fraction',\n renderFraction: (currentClass: string, totalClass: string) => {\n return `${currentClass}/${totalClass}`;\n }\n },\n keyboard: {\n enabled: true,\n onlyInViewport: true\n },\n navigation: {\n nextEl: this.dom.next as HTMLElement,\n prevEl: this.dom.prev as HTMLElement\n }\n });\n }\n }\n\n stickyCardCleanup() {\n const stickyCard = this.dom.stickyCard as HTMLElement;\n stickyCard.style.position = 'relative';\n stickyCard.style.top = 'auto';\n stickyCard.style.bottom = 'auto';\n stickyCard.style.width = '100%';\n }\n\n handleBreakpointChange(breakpoint: string) {\n if (breakpoint === 'mobile' || breakpoint === 'tablet') {\n this.isMobile = breakpoint === 'mobile';\n if (this.swiper) {\n this.swiper.destroy(true, true);\n this.swiper = null;\n }\n this.initSwiper();\n } else {\n if (this.swiper) {\n this.swiper.destroy(true, true);\n this.swiper = null;\n }\n }\n }\n}\n\nexport default ScrollImageGrid;\n"],"names":["ScrollImageGrid","Component","el","__publicField","initialBreakpoint","eventBus","stickyCard","parentContainer","offsetParent","parentContainerTop","parentContainerBottom","scrollY","bottomParent","Swiper","Navigation","Pagination","A11y","Keyboard","BREAKPOINTS","currentClass","totalClass","breakpoint"],"mappings":"+YAQA,MAAMA,UAAwBC,CAAU,CAItC,YAAYC,EAAiB,CAC3B,MAAMA,CAAE,EAJFC,EAAA,cAAwB,MACxBA,EAAA,gBAAW,IAKZ,KAAA,uBAAuBC,GAAmB,CAAA,CAGjD,eAAgB,CACd,KAAK,IAAM,CACT,OAAQ,KAAK,GAAG,cAA8B,SAAS,EACvD,OAAQ,KAAK,GAAG,iBAAiC,eAAe,EAChE,WAAY,KAAK,GAAG,cAA8B,oBAAoB,EACtE,KAAM,KAAK,GAAG,cAA8B,qBAAqB,EACjE,KAAM,KAAK,GAAG,cAA8B,qBAAqB,EACjE,gBAAiB,KAAK,GAAG,cAA2B,iCAAiC,EACrF,WAAY,KAAK,GAAG,cAA2B,uCAAuC,CACxF,CAAA,CAGF,cAAqB,CACnBC,EAAS,UAAU,mBAAoB,KAAK,uBAAuB,KAAK,IAAI,CAAC,EAC7E,OAAO,iBAAiB,SAAU,KAAK,aAAa,KAAK,IAAI,CAAC,CAAA,CAGhE,cAAe,CAIT,GAAA,OAAO,YAAc,KAA2B,CAClD,KAAK,kBAAkB,EACvB,MAAA,CAGI,MAAAC,EAAa,KAAK,IAAI,WACtBC,EAAkB,KAAK,IAAI,gBAEjCD,EAAW,MAAM,MAAQ,GAAGC,EAAgB,WAAW,K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