class CartDrawer extends HTMLElement{constructor(){super(),this.addEventListener("keyup",evt=>evt.code==="Escape"&&this.close()),this.querySelector("#CartDrawer-Overlay").addEventListener("click",this.close.bind(this)),this.setHeaderCartIconAccessibility(),this.setfocusableAccessibility(),this.initDrawerContentHeight()}initDrawerContentHeight(){let drawerHeader=this.querySelector(".drawer__header"),cartFSG=drawerHeader?.querySelector(".cart-fsg"),drawerContent=this.querySelector(".drawer__conent");if(drawerHeader&&drawerContent&&cartFSG){let drawerHeight=drawerHeader.clientHeight+15;drawerContent.style.maxHeight=`calc(100vh - ${drawerHeight}px)`}}setfocusableAccessibility(){this.querySelector(".last-focusable-element").addEventListener("keydown",event=>{if(event.key==="Tab"){event.preventDefault();const firstFocusableElement=this.querySelector(".first-focusable-element");firstFocusableElement&&firstFocusableElement.focus()}})}setHeaderCartIconAccessibility(){const cartLink=document.querySelector("#cart-icon-bubble");cartLink.setAttribute("role","button"),cartLink.addEventListener("click",event=>{event.preventDefault(),this.updateDrawer(),this.open(cartLink)}),cartLink.addEventListener("keydown",event=>{event.code.toUpperCase()==="SPACE"&&(event.preventDefault(),this.updateDrawer(),this.open(cartLink))})}updateDrawer(){fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=["cart-drawer-items",".cart-drawer__footer",".drawer__header",".item-count"];for(const selector of selectors){const targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&targetElement.replaceWith(sourceElement)}}).catch(e=>{console.error(e)}),window.cart_proxy.isActive=!0}open(triggeredBy){triggeredBy&&this.setActiveElement(triggeredBy);const cartDrawerNote=this.querySelector('[id^="Details-"] summary');cartDrawerNote&&!cartDrawerNote.hasAttribute("role")&&this.setSummaryAccessibility(cartDrawerNote),setTimeout(()=>{this.classList.add("animate","active")}),this.addEventListener("transitionend",()=>{const containerToTrapFocusOn=this.classList.contains("is-empty")?this.querySelector(".drawer__inner-empty"):document.getElementById("CartDrawer"),focusElement=this.querySelector(".drawer__inner")||this.querySelector(".drawer__close");trapFocus(containerToTrapFocusOn,focusElement)},{once:!0})}close(){this.classList.remove("active"),removeTrapFocus(this.activeElement||document.querySelector("#cart-icon-bubble"))}setSummaryAccessibility(cartDrawerNote){cartDrawerNote.setAttribute("role","button"),cartDrawerNote.setAttribute("aria-expanded","false"),cartDrawerNote.nextElementSibling.getAttribute("id")&&cartDrawerNote.setAttribute("aria-controls",cartDrawerNote.nextElementSibling.id),cartDrawerNote.addEventListener("click",event=>{event.currentTarget.setAttribute("aria-expanded",!event.currentTarget.closest("details").hasAttribute("open"))}),cartDrawerNote.parentElement.addEventListener("keyup",onKeyUpEscape)}renderContents(parsedState){this.querySelector(".drawer__inner").classList.contains("is-empty")&&this.querySelector(".drawer__inner").classList.remove("is-empty"),this.productId=parsedState.id,this.getSectionsToRender().forEach(section=>{const sectionElement=section.selector?document.querySelector(section.selector):document.getElementById(section.id);sectionElement.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.id],section.selector)}),setTimeout(()=>{this.querySelector("#CartDrawer-Overlay").addEventListener("click",this.close.bind(this)),this.open(),this.addEventListener("keyup",evt=>evt.code==="Escape"&&this.close()),this.setHeaderCartIconAccessibility(),this.setfocusableAccessibility()})}getSectionInnerHTML(html,selector=".shopify-section"){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}getSectionsToRender(){return[{id:"cart-drawer",selector:"#CartDrawer"},{id:"cart-icon-bubble"}]}getSectionDOM(html,selector=".shopify-section"){return new DOMParser().parseFromString(html,"text/html").querySelector(selector)}setActiveElement(element){this.activeElement=element}}customElements.define("cart-drawer",CartDrawer);class CartDrawerItems extends CartItems{getSectionsToRender(){return[{id:"CartDrawer",section:"cart-drawer",selector:".drawer__inner"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"}]}}customElements.define("cart-drawer-items",CartDrawerItems); //# sourceMappingURL=/cdn/shop/t/106/assets/cart-drawer.js.map?v=132408005692884126121755659348