1function showCartRemovalToast(removeButton){const toast=document.getElementById("toast-container");if(!toast)return;const applyAndShow=()=>{typeof toast.render=="function"&&!toast.querySelector(".toast-wrapper")&&toast.render();const name=removeButton.closest(".cart-item__holder")?.querySelector(".cart-item__name")?.textContent?.trim(),toastTextElement=toast.querySelector(".toast-copy .fixed-body-s")||toast.querySelector(".toast-copy > span"),messageTemplate=toast.getAttribute("data-message-template");if(!(!name||!messageTemplate)){if(toastTextElement&&(toastTextElement.textContent=messageTemplate.replace(/\{\{\s*product_name\s*\}\}/g,name)),typeof toast.show=="function"){toast.show();return}toast.classList.add("show"),toast.style.display="block"}};customElements.whenDefined("toast-notification").then(applyAndShow)}const getCartFetchConfig=(type="json")=>typeof fetchConfig=="function"?fetchConfig(type):{method:"POST",headers:{"Content-Type":"application/json",Accept:`application/${type}`}};class CartRemoveButton extends HTMLElement{constructor(){super(),this.addEventListener("click",function(event){event.preventDefault();const cartItems=this.closest("cart-items")||this.closest("cart-drawer-items"),lineItem=this.closest(".cart-item__holder")||this.closest(".cart-item"),selectedLineItem=lineItem?.querySelector(".cart-item__quantity-select[data-quantity-variant-id]"),editCartElement=lineItem?.querySelector("[data-variant-id]"),removedVariantId=selectedLineItem?.dataset?.quantityVariantId||editCartElement?.dataset?.variantId||void 0;cartItems&&(showCartRemovalToast(this),cartItems.updateQuantity(this.dataset.index,0)),typeof publish=="function"&&typeof PUB_SUB_EVENTS<"u"&&publish(PUB_SUB_EVENTS.cartRemove,{source:"cart-remove-button",line:this.dataset.index,removedVariantId})},!0)}}customElements.define("cart-remove-button",CartRemoveButton);class CartItems extends HTMLElement{constructor(){super(),this.lineItemStatusElement=document.getElementById("shopping-cart-line-item-status")||document.getElementById("CartDrawer-LineItemStatus");const debouncedOnChange=debounce(event=>{this.onChange(event)},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener("change",debouncedOnChange.bind(this)),this.bindCustom()}cartUpdateUnsubscriber=void 0;connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{event.source==="cart-items"||event.source==="product-form"||event.source==="quick-add-tile"||this.onCartUpdate()})}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}resetQuantityInput(id){const input=this.querySelector(`#Quantity-${id}`);input.value=input.getAttribute("value"),this.isEnterPressed=!1}setValidity(event,index,message){event.target.setCustomValidity(message),event.target.reportValidity(),this.resetQuantityInput(index),event.target.select()}validateQuantity(event){const inputValue=parseInt(event.target.value),index=event.target.dataset.index;let message="";inputValue<event.target.dataset.min?message=window.quickOrderListStrings.min_error.replace("[min]",event.target.dataset.min):inputValue>parseInt(event.target.max)&&(message=window.quickOrderListStrings.max_error.replace("[max]",event.target.max)),message?this.setValidity(event,index,message):(event.target.setCustomValidity(""),event.target.reportValidity(),this.updateQuantity(index,inputValue,document.activeElement.getAttribute("name"),event.target.dataset.quantityVariantId))}onChange(event){event.target.classList.contains("grid-selector__input")||event.target.classList.contains("color-selector__radio")||this.validateQuantity(event)}onCartUpdate(){this.tagName==="CART-DRAWER-ITEMS"?fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{this.removeBuyStackModals();const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=["cart-drawer-items",".cart-drawer__footer"];for(const selector of selectors){const targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&targetElement.replaceWith(sourceElement)}}).catch(e=>{console.error(e)}):fetch(`${routes.cart_url}?section_id=main-cart-items`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("cart-items");this.innerHTML=sourceQty.innerHTML}).catch(e=>{console.error(e)})}getSectionsToRender(){return[{id:"main-cart-items",section:document.getElementById("main-cart-items").dataset.id,selector:".js-contents"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"},{id:"cart-live-region-text",section:"cart-live-region-text",selector:".shopify-section"},{id:"main-cart-totals",section:document.getElementById("main-cart-totals").dataset.id,selector:".totals__holder"},{id:"main-cart-totals",section:document.getElementById("main-cart-totals").dataset.id,selector:".cart__ctas"},{id:"MainContent",section:document.getElementById("main-cart-items").dataset.id,selector:".cart__cards-mobile"},{id:"MainContent",section:document.getElementById("main-cart-items").dataset.id,selector:".cart__cards-desktop"}]}restoreLastRemovedItem(){const items=[window.lastRemovedItem];fetch(`${routes.cart_add_url}`,{...getCartFetchConfig(),body:JSON.stringify({items,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname})}).then(response=>response.json()).then(async partialCartState=>{const cartContext=await fetch(`${routes.cart_url}`,{...getCartFetchConfig()}).then(resp=>resp.json()),line=window.lastRemovedItem.line,name=window.lastRemovedItem.name,variantId=window.lastRemovedItem.id,parsedState={...partialCartState,...cartContext};this.renderCartFromParsedState(parsedState,line,name,variantId)}).catch(()=>{this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors&&(errors.textContent=window.cartStrings.error)}).finally(()=>{const line=window.lastRemovedItem.line;this.disableLoading(line)})}updateQuantity(line,quantity,name,variantId){if(this.enableLoading(line),quantity===0){const lineItem=document.getElementById(`CartItem-${line}`)||document.getElementById(`CartDrawer-Item-${line}`);if(lineItem){const selectedLineItem=lineItem.querySelector(".cart-item__quantity-select"),variantIdNum=selectedLineItem!==null?parseInt(selectedLineItem.getAttribute("data-quantity-variant-id")||"",10):"",name2=lineItem.querySelector(".cart-item__name").innerText,qty=selectedLineItem!==null?parseInt(selectedLineItem.value||"1",10):1;window.lastRemovedItem={line,name:name2,id:variantIdNum,quantity:qty}}}const body=JSON.stringify({line,quantity,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname});
1fetch(`${routes.cart_change_url}`,{...getCartFetchConfig(),body}).then(response=>response.text()).then(state=>{const parsedState=JSON.parse(state);this.renderCartFromParsedState(parsedState,line,name,variantId)}).catch(()=>{this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors&&(errors.textContent=window.cartStrings.error)}).finally(()=>{this.disableLoading(line)}),publish(PUB_SUB_EVENTS.cartQtyUpdate,void 0)}removeBuyStackModals(){document.querySelectorAll('modal-slideout[id^="edit-cart-modal-size-"], modal-slideout[id^="edit-cart-modal-color-"]').forEach(modal=>modal.remove()),document.querySelectorAll("edit-cart-size, edit-cart-color").forEach(element=>{element._unwire?.()}),typeof ModalSlideout<"u"&&ModalSlideout.syncOverlayVisibility&&ModalSlideout.syncOverlayVisibility()}renderCartFromParsedState(parsedState,line,name,variantId,originalVariantId){const quantityElement=document.getElementById(`Quantity-${line}`)||document.getElementById(`Drawer-quantity-${line}`),items=document.querySelectorAll(".cart-item");if(this.removeBuyStackModals(),parsedState.errors&&quantityElement){quantityElement.value=quantityElement.getAttribute("value"),this.updateLiveRegions(line,parsedState.errors);return}this.classList.toggle("is-empty",parsedState.item_count===0);const cartTitle=document.querySelector(".cart-title-holder span"),cartDrawerWrapper=document.querySelector("cart-drawer"),cartSectionWrapper=document.querySelector(".cart-holder"),stickySectionWrapper=document.querySelector(".cart-sticky-checkout"),cartFooter=document.getElementById("main-cart-footer");if(cartFooter&&cartFooter.classList.toggle("is-empty",parsedState.item_count===0),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",parsedState.item_count===0),cartSectionWrapper&&cartSectionWrapper.classList.toggle("is-empty",parsedState.item_count===0),stickySectionWrapper&&stickySectionWrapper.classList.toggle("is-empty",parsedState.item_count===0),cartTitle&&parsedState.item_count!=null){const numberRegEx=/\d+/,titleText=cartTitle.innerHTML;cartTitle.innerHTML=titleText.replace(numberRegEx,parsedState.item_count)}this.getSectionsToRender().forEach(section=>{const elementToReplace=document.getElementById(section.id).querySelector(section.selector)||document.getElementById(section.id);let newInnerHtml=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector);if(newInnerHtml)elementToReplace.innerHTML=newInnerHtml;else{const targetedElementToReplace=document.getElementById(section.id).querySelector(section.selector);targetedElementToReplace.innerHTML=null}}),variantId&&line?this.restoreCartOrderAfterVariantReplace(line,originalVariantId,variantId):this.restoreCartDOMOrder();const updatedValue=parsedState?.items?.[line-1]?parsedState.items[line-1].quantity:void 0;let message="";items.length===parsedState?.items?.length&&updatedValue!==parseInt(quantityElement?.value)&&(typeof updatedValue>"u"?message=window.cartStrings.error:message=window.cartStrings.quantityError.replace("[quantity]",updatedValue)),this.updateLiveRegions(line,message);const lineItem=document.getElementById(`CartItem-${line}`)||document.getElementById(`CartDrawer-Item-${line}`);if(lineItem&&lineItem.querySelector(`[name="${name}"]`)?cartDrawerWrapper?trapFocus(cartDrawerWrapper,lineItem.querySelector(`[name="${name}"]`)):lineItem.querySelector(`[name="${name}"]`).focus():parsedState.item_count===0&&cartDrawerWrapper?trapFocus(cartDrawerWrapper.querySelector(".drawer__inner-empty"),cartDrawerWrapper.querySelector("a")):document.querySelector(".cart-item")&&cartDrawerWrapper&&trapFocus(cartDrawerWrapper,document.querySelector(".cart-item__name")),stickySectionWrapper){const subtotalEl=document.querySelector(".price-line.totals__subtotal .price-line__amount"),targetEl=stickySectionWrapper.querySelector(".cart-sticky-checkout__total .price-line__value span");subtotalEl&&targetEl&&(targetEl.innerHTML=subtotalEl.innerHTML)}this.setCartID(),this.setOriginalCartOrder(),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-items",cartData:parsedState,variantId})}bindCustom(){this.setOriginalCartOrder()}getHolderVariantId(holder){if(!holder)return null;
1const qtySelect=holder.querySelector("[data-quantity-variant-id]");if(qtySelect?.dataset?.quantityVariantId)return qtySelect.dataset.quantityVariantId;const editCartEl=holder.querySelector("[data-variant-id]");return editCartEl?.dataset?.variantId?editCartEl.dataset.variantId:null}async itemReplace({lineIndex,originalVariantId,newVariantId,quantity,bottomSheetModal}){this.setOriginalCartOrder(),this.setCartUpdating(!0);const bodyConfig={sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname},clearEditCartSubmitLoading=()=>{bottomSheetModal?.querySelector("[data-cart-edit-color-done], [data-cart-edit-size-done]")?.classList.remove("is-loading")};try{await fetch(routes.cart_change_url,{...getCartFetchConfig(),body:JSON.stringify({line:lineIndex,quantity:0,...bodyConfig})});const parsedState=await(await fetch(routes.cart_add_url,{...getCartFetchConfig(),body:JSON.stringify({id:newVariantId,quantity,...bodyConfig})})).json();clearEditCartSubmitLoading(),bottomSheetModal.close(),this.updateItemsOrderState(originalVariantId,newVariantId);const focusedElement=document.activeElement?.getAttribute?.("name")??null;this.renderCartFromParsedState(parsedState,lineIndex,focusedElement,newVariantId,originalVariantId)}catch(err){throw clearEditCartSubmitLoading(),err}finally{this.setCartUpdating(!1)}}setCartUpdating(isUpdating){document.querySelectorAll(".cart__items").forEach(wrapper=>{wrapper.classList.toggle("cart__items--updating",isUpdating)}),document.querySelectorAll("edit-cart-size, edit-cart-color").forEach(editTrigger=>{const button=editTrigger.querySelector("button");button&&(isUpdating?(editTrigger.setAttribute("aria-busy","true"),button.setAttribute("disabled","true")):editTrigger.hasAttribute("disabled")||(editTrigger.removeAttribute("aria-busy"),button.removeAttribute("disabled")))})}restoreCartDOMOrder(){const parent=this.querySelector(".cart-items")||document.querySelector(".cart-items");!window.originalCartOrder?.length||!parent||this.applyCartHolderOrder(parent,window.originalCartOrder)}restoreCartOrderAfterVariantReplace(lineIndex,originalVariantId,newVariantId){const parent=this.querySelector(".cart-items")||document.querySelector(".cart-items");if(!parent)return;const desiredOrder=window.originalCartOrder?.length?window.originalCartOrder.map(id=>String(id)):[];if(desiredOrder.length){this.applyCartHolderOrder(parent,desiredOrder);return}const holders=[...parent.querySelectorAll(".cart-item__holder")],targetId=String(newVariantId),insertAt=Math.max(0,Number(lineIndex)-1),fromIndex=holders.findIndex(holder=>this.getHolderVariantId(holder)===targetId);if(fromIndex<0||fromIndex===insertAt)return;const[moved]=holders.splice(fromIndex,1);holders.splice(insertAt,0,moved),holders.forEach(holder=>parent.appendChild(holder)),this.setOriginalCartOrder()}applyCartHolderOrder(parent,desiredVariantOrder){const holders=[...parent.querySelectorAll(".cart-item__holder")],queues=new Map;holders.forEach(holder=>{const variantId=this.getHolderVariantId(holder);if(!variantId)return;const key=String(variantId);queues.has(key)||queues.set(key,[]),queues.get(key).push(holder)});const ordered=[];desiredVariantOrder.forEach(variantId=>{const queue=queues.get(String(variantId));queue?.length&&ordered.push(queue.shift())}),holders.forEach(holder=>{ordered.includes(holder)||ordered.push(holder)}),ordered.forEach(holder=>parent.appendChild(holder))}setOriginalCartOrder(){const parent=this.querySelector(".cart-items")||document.querySelector(".cart-items");parent&&(window.originalCartOrder=[...parent.querySelectorAll(".cart-item__holder")].map(holder=>this.getHolderVariantId(holder)).filter(Boolean).map(String))}updateItemsOrderState(originalVariantId,newVariantId){const original=String(originalVariantId),next=String(newVariantId);window.originalCartOrder?.length&&(window.originalCartOrder=window.originalCartOrder.map(variantId=>String(variantId)===original?next:String(variantId)))}updateLiveRegions(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);lineItemError&&(lineItemError.querySelector(".cart-item__error-text").textContent=message),this.lineItemStatusElement.setAttribute("aria-hidden",!0);const cartStatus=document.getElementById("cart-live-region-text")||document.getElementById("CartDrawer-LiveRegionText");cartStatus.setAttribute("aria-hidden",!1),setTimeout(()=>{cartStatus.setAttribute("aria-hidden",!0)},1e3)}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector)?.innerHTML}enableLoading(line){this.setCartUpdating(!0),(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);
1[...cartItemElements,...cartDrawerItemElements].forEach(overlay=>overlay.classList.remove("hidden")),document.activeElement.blur(),this.lineItemStatusElement.setAttribute("aria-hidden",!1)}disableLoading(line){this.setCartUpdating(!1),(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.remove("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);cartItemElements.forEach(overlay=>overlay.classList.add("hidden")),cartDrawerItemElements.forEach(overlay=>overlay.classList.add("hidden"))}}customElements.define("cart-items",CartItems),customElements.get("cart-note")||customElements.define("cart-note",class extends HTMLElement{constructor(){super(),this.addEventListener("input",debounce(event=>{const body=JSON.stringify({note:event.target.value});fetch(`${routes.cart_update_url}`,{...getCartFetchConfig(),body})},ON_CHANGE_DEBOUNCE_TIMER))}}),document.addEventListener("click",event=>{if(!event.target.closest("#toast-container .toast-content-body button"))return;const toast=document.querySelector("#toast-container.cart-confirmation-toast"),cartItems=document.querySelector("cart-items")||document.querySelector("cart-drawer-items");!toast||!cartItems||typeof toast.hide!="function"||(event.preventDefault(),cartItems.restoreLastRemovedItem(),toast.hide())}); 2//# sourceMappingURL=/cdn/shop/t/84/assets/cart.js.map?v=41207992777421707651790617209
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.