1class Cart{constructor(){if(Cart.instance)return Cart.instance;this.container=document.getElementById("Cart"),this.container&&(Cart.instance=this,this.setupEventListeners())}onChange(event){if(event.target.type=="number"){const input=event.target,id=input.closest("quantity-selector")?.dataset.id,raw=String(input.value).trim(),previous=Number(input.dataset.previousQty);if(raw===""||!Number.isFinite(Number(raw))){Number.isFinite(previous)&&previous>0&&(input.value=previous);return}const qty=Number(raw);if(qty<=0){this.updateQuantity(input.dataset.index,0,id);return}this.updateQuantity(input.dataset.index,qty,id)}else event.target.getAttribute("id")=="CartSpecialInstructions"&&this.saveNotes()}saveNotes(){fetch(`${theme.routes.cart_update_url}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({note:document.getElementById("CartSpecialInstructions").value})})}setupEventListeners(){this.debouncedOnChange=debounce(event=>{this.onChange(event)},300),document.addEventListener("cart:refresh",event=>{this.refresh()}),document.addEventListener("cart:remove",event=>{this.updateQuantity(event.detail.index,"0",event.detail.id)}),this.container.addEventListener("click",event=>{const remove=event.target.closest("cart-remove");!remove||!this.container.contains(remove)||(event.preventDefault(),this.updateQuantity(remove.dataset.index,"0",remove.dataset.id))}),this.container.addEventListener("change",this.debouncedOnChange.bind(this)),this.termsCheckbox()}getSectionsToRender(){return[{id:"Cart",section:"main-cart",selector:".thb-cart-form"},{id:"cart-drawer-toggle",section:"cart-bubble",selector:".thb-item-count"}]}displayErrors(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);if(lineItemError){lineItemError.removeAttribute("hidden");const errorText=lineItemError.querySelector(".cart-item__error-text");errorText&&(errorText.innerHTML=message),this.container.querySelector(`#CartItem-${line}`)?.classList.remove("loading")}}parseJson(text){if(typeof window.parseShopifyJson=="function")return window.parseShopifyJson(text);if(typeof text!="string")return null;const trimmed=text.trim();if(!trimmed||trimmed[0]!=="{"&&trimmed[0]!=="[")return null;try{return JSON.parse(trimmed)}catch{return null}}getSectionInnerHTML(html,selector){if(!html)return"";const doc=new DOMParser().parseFromString(html,"text/html"),el=doc.querySelector(selector)||doc.body.firstElementChild;return el?el.innerHTML:""}updateQuantity(line,quantity,id){if(!this.container)return;const qty=Number(quantity);if(!Number.isFinite(qty))return;if(this._updating){qty===0&&id&&this._inflightId===id&&this._inflightQty===0||(this._queuedChange={line,quantity:qty,id});return}this._updating=!0,this._inflightId=id,this._inflightQty=qty,this.container.classList.add("cart-disabled");const lineEl=line?this.container.querySelector(`#CartItem-${line}`):null,qtyInput=lineEl?.querySelector(".qty"),previousQty=Number(qtyInput?.dataset.previousQty),revertQty=Number.isFinite(previousQty)&&previousQty>0?previousQty:null;lineEl?.classList.add("loading");const payload={quantity:qty,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname};id?payload.id=id:payload.line=line;const body=JSON.stringify(payload);dispatchCustomEvent("line-item:change:start",{quantity}),(typeof window.fetchCartJson=="function"?window.fetchCartJson(`${theme.routes.cart_change_url}`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body}):fetch(`${theme.routes.cart_change_url}`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body}).then(response=>response.text()).then(state=>{const parsed=this.parseJson(state);if(!parsed)throw new Error("cart-json");return parsed})).then(parsedState=>{if(parsedState.errors){qtyInput&&revertQty&&(qtyInput.value=revertQty),this.displayErrors(line,parsedState.errors),this.container.classList.remove("cart-disabled");return}this.renderContents(parsedState,line,!1),this.container.classList.remove("cart-disabled"),dispatchCustomEvent("line-item:change:end",{quantity,cart:parsedState})}).catch(()=>{qtyInput&&revertQty&&(qtyInput.value=revertQty),this.container.classList.remove("cart-disabled"),this.refresh()}).finally(()=>{this._updating=!1,this._inflightId=null,this._inflightQty=null;const queued=this._queuedChange;this._queuedChange=null,queued&&this.updateQuantity(queued.line,queued.quantity,queued.id)})}refresh(){this.container.classList.add("cart-disabled"),(typeof window.fetchCartJson=="function"?window.fetchCartJson(`${window.location.pathname}?sections=main-cart`):fetch(`${window.location.pathname}?sections=main-cart`).then(response=>response.text()).then(state=>{const parsed=this.parseJson(state);if(!parsed)throw new Error("cart-json");return parsed})).then(parsedState=>{if(parsedState.errors){this.container.classList.remove("cart-disabled");return}this.renderContents(parsedState,!1,!0),this.container.classList.remove("cart-disabled")}
1).catch(()=>{this.container.classList.remove("cart-disabled")})}termsCheckbox(){if(!this.container)return;let terms_checkbox=this.container.querySelector("#CartTerms"),checkout_button=this.container.querySelector(".button.checkout-button");terms_checkbox&&checkout_button&&(terms_checkbox.setCustomValidity(theme.strings.requiresTerms),checkout_button.addEventListener("click",function(e){terms_checkbox.checked||(terms_checkbox.reportValidity(),terms_checkbox.focus(),e.preventDefault())}))}renderContents(parsedState,line,refresh){parsedState&&(this.getSectionsToRender().forEach((section=>{const root=document.getElementById(section.id);if(!root)return;const elementToReplace=root.querySelector(section.selector)||root,html=refresh?this.getSectionInnerHTML(parsedState[section.section],section.selector):this.getSectionInnerHTML(parsedState.sections?.[section.section],section.selector);html&&(elementToReplace.innerHTML=html,line&&this.container.querySelector(`#CartItem-${line}`)&&this.container.querySelector(`#CartItem-${line}`).classList.remove("loading"),this.termsCheckbox())})),this.container?.querySelectorAll(".thb-cart-form .qty").forEach(input=>{String(input.value).trim()==="0"&&input.closest("tr, .cart-item, .product-cart-item")?.remove()}))}}window.addEventListener("load",()=>{typeof Cart<"u"&&new Cart}); 2//# sourceMappingURL=/cdn/shop/t/147/assets/cart.js.map?v=150598484691404445781790487129
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.