1/*! Copyright (c) Safe As Milk. All rights reserved. */class UtilityBar extends HTMLElement{connectedCallback(){this.id=this.getAttribute("id"),this.carouselContainer=this.querySelector(".utility-announcement"),this.carouselWrapper=this.querySelector(".utility-announcement__wrapper"),this.carouselSlides=this.querySelectorAll(".utility-announcement__slides"),this.carouselContainer!=null&&(this.interactions=!0,this.autoplay=this.carouselContainer.hasAttribute("autoplay"),this.autoplayDelay=Number(this.carouselContainer.getAttribute("autoplay-delay")||"5000"),this.currentSlide=0,this.autoplayInterval=null,this.carouselSlides.length>1&&this.#createNavigation(),this.intersectionObserver=new IntersectionObserver(this.handleIntersection.bind(this)),this.mutationObserver=new MutationObserver((()=>{this.handleWindowResize()})),this.handleWindowResize(),window.addEventListener("resize",(()=>{this.handleWindowResize()})),this.observeMutations(),this.carouselSlides[this.currentSlide].dataset.active=!0,this.autoplay&&(this.startAutoplay(),this.carouselContainer.addEventListener("mouseenter",(()=>this.stopAutoplay())),this.carouselContainer.addEventListener("mouseleave",(()=>{this.hasAttribute("popup-open")||this.startAutoplay()}))),this.observeSlides()),this.setAttribute("loaded","")}observeMutations(){this.mutationObserver.observe(this.carouselWrapper,{childList:!0,subtree:!0,characterData:!0})}observeSlides(){this.carouselSlides.forEach((slide=>{this.intersectionObserver.observe(slide)}))}handleWindowResize(){this.#calculateSlidesWidth()}handleScroll(){const slideWidth=this.carouselSlides[0].getBoundingClientRect().width;this.currentSlide=Math.round(this.carouselWrapper.scrollLeft/slideWidth),this.carouselSlides.forEach(((slide,index)=>{index===this.currentSlide?slide.setAttribute("data-active",""):slide.removeAttribute("data-active")}))}handleIntersection(entries){entries.forEach((entry=>{entry.isIntersecting?this.carouselWrapper.addEventListener("scroll",(()=>this.handleScroll())):this.carouselWrapper.removeEventListener("scroll",(()=>this.handleScroll()))}))}disconnectedCallback(){this.staticDisplay||(this.stopAutoplay(),this.carouselPrevBtn?.removeEventListener("click",this.showPrevSlide),this.carouselNextBtn?.removeEventListener("click",this.showNextSlide),this.carouselContainer.removeEventListener("mouseenter",this.stopAutoplay),this.carouselContainer.removeEventListener("mouseleave",this.startAutoplay),this.intersectionObserver.disconnect(),this.textSizeObserver.disconnect()),this.mutationObserver.disconnect(),window.removeEventListener("resize",this.handleWindowResize),this.removeAttribute("loaded")}showPrevSlide(){this.currentSlide===0?this.moveToSlide(this.carouselSlides.length-1):this.moveToSlide(this.currentSlide-1),this.dispatchEvent(new CustomEvent("on:announcement-bar:slide-change",{detail:{currentSlide:this.currentSlide}}))}showNextSlide(){this.currentSlide===this.carouselSlides.length-1?this.moveToSlide(0):this.moveToSlide(this.currentSlide+1),this.dispatchEvent(new CustomEvent("on:announcement-bar:slide-change",{detail:{currentSlide:this.currentSlide}}))}startAutoplay(){this.interactions&&this.autoplayInterval===null&&(this.setAttribute("scrolling",""),this.autoplayInterval=setInterval((()=>{this.showNextSlide()}),this.autoplayDelay))}stopAutoplay(){this.interactions&&this.autoplayInterval!==null&&(this.removeAttribute("scrolling"),clearInterval(this.autoplayInterval),this.autoplayInterval=null)}moveToSlide(slideIndex,behavior="smooth"){this.carouselWrapper.scrollTo({left:this.carouselSlides[slideIndex].offsetLeft,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":behavior}),this.currentSlide=slideIndex,this.carouselSlides.forEach(((slide,index)=>{index===this.currentSlide?slide.setAttribute("data-active",""):slide.removeAttribute("data-active")}))}stopInteractions(){this.interactions=!1}resumeInteractions(){this.interactions=!0}#calculateSlidesWidth(){this.slidesWidth=0,this.containerWidth=window.innerWidth*.89;const{carouselSlides}=this;carouselSlides.forEach((slide=>{const announcementMessage=slide.querySelector(".utility-announcement__message"),announcementText=slide.querySelector(".utility-announcement__text"),computedStyles=window.getComputedStyle(announcementMessage),textWidth=announcementText.offsetWidth+parseFloat(computedStyles.paddingLeft)+parseFloat(computedStyles.paddingRight);this.slidesWidth+=textWidth})),this.slidesWrap=this.slidesWidth>this.containerWidth}#createNavigation(){this.carouselPrevBtn=document.createElement("button"),this.carouselPrevBtn.classList.add("utility-announcement__carousel-button","carousel-prev"),this.carouselPrevBtn.setAttribute("aria-label","Previous Announcement");const arrowPreviousSVG=document.getElementById("template-icon-chevron").content.cloneNode(!0).firstElementChild;arrowPreviousSVG.classList.add("icon--left"),this.carouselPrevBtn.append(arrowPreviousSVG),this.carouselContainer.prepend(this.carouselPrevBtn),this.carouselNextBtn=document.createElement("button"),this.carouselNextBtn.classList.add("utility-announcement__carousel-button","carousel-next"),this.carouselNextBtn.setAttribute("aria-label","Next Announcement");const arrowNextSVG=document.getElementById("template-icon-chevron").content.cloneNode(!0).firstElementChild;this.carouselNextBtn.append(arrowNextSVG),this.carouselContainer.append(this.carouselNextBtn),this.carouselPrevBtn.addEventListener("click",(()=>this.showPrevSlide())),this.carouselNextBtn.addEventListener("click",(()=>this.showNextSlide()))}}customElements.define("utility-bar",UtilityBar); 2//# sourceMappingURL=/cdn/shop/t/20/assets/utility-bar.js.map?v=13894564120731815271771829294
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.