1import{Component as b}from"@theme/component";import{fetchConfig as f,debounce as w,onAnimationEnd as L,prefersReducedMotion as q,shimmer as h,resetShimmer as y,asyncScopeUrl as m}from"@theme/utilities";import{morphSection as p,sectionRenderer as g}from"@theme/section-renderer";import{ThemeEvents as d,CartUpdateEvent as S,DiscountUpdateEvent as T}from"@theme/events";import{cartPerformance as u}from"@theme/performance";const C=new Set;class _ extends b{#a=w(this.#h,300).bind(this);connectedCallback(){super.connectedCallback(),document.addEventListener(d.cartUpdate,this.#i),document.addEventListener(d.discountUpdate,this.handleDiscountUpdate),document.addEventListener(d.quantitySelectorUpdate,this.#c),document.addEventListener(d.quantitySelectorUpdate,this.#a),this.#S()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(d.cartUpdate,this.#i),document.removeEventListener(d.quantitySelectorUpdate,this.#c),document.removeEventListener(d.quantitySelectorUpdate,this.#a)}#c=t=>{t.detail.cartLine&&this.#t()};#h(t){const{quantity:e,cartLine:n}=t.detail;if(!n)return;if(e===0)return this.onLineItemRemove(n);this.updateQuantity({line:n,quantity:e,action:"change"});const s=this.#d(n);s&&h(s.querySelector("text-component"))}onLineItemRemove(t,e){e?.stopPropagation();const n=this.#y(e)??this.#d(t),s=Number(n?.dataset.line)||t;if(n?.dataset.linkedKeys?this.#l(this.#u(n)):this.updateQuantity({line:s,quantity:0,action:"clear"}),!n)return;const o=this.#f(n);if((this.refs.cartItemRows?.length??0)<=1+o.length){const r=this.querySelector("[data-optimistic-empty]");r instanceof HTMLElement&&(this.classList.add("cart-items-component--optimistic-empty"),r.hidden=!1,this.#I(r.dataset))}for(const r of[n,...o])this.#p(r)}#p(t){const e=()=>t.remove();if(q()){e();return}t.style.setProperty("--row-height",`${t.clientHeight}px`),t.classList.add("removing"),L(t,e)}#f(t){const{key:e,linkedKeys:n}=t.dataset;return n?n.split(",").flatMap(s=>{const o=s.trim();if(!o||o===e)return[];const r=this.querySelector(`.cart-item[data-key="${o}"]`);return r instanceof HTMLElement&&r!==t?[r]:[]}):[]}#y(t){const e=t?.target;if(!(e instanceof Element))return null;const n=e.closest(".cart-item");return n instanceof HTMLElement&&this.contains(n)?n:null}#d(t){if(!Number.isInteger(t))return null;const e=this.querySelector(`.cart-item[data-line="${t}"]`);return e instanceof HTMLElement?e:null}#u(t){const{key:e,linkedKeys:n}=t.dataset;return[e,...n?.split(",")??[]].flatMap(s=>{const o=s?.trim();return o?[o]:[]})}#S(){if(window.Shopify?.designMode||!this.dataset.sectionId)return;const t=this.querySelector(".cart-items__wrapper[data-orphan-keys]");if(!(t instanceof HTMLElement))return;const e=(t.dataset.orphanKeys??"").split(",").flatMap(n=>{const s=n.trim();return s&&!C.has(s)?[s]:[]});if(e.length!==0){for(const n of e)C.add(n);try{this.#l(e)}catch{this.#e()}}}#I(t){const e=this.querySelector("[data-cart-summary]");if(!e)return;const n=e.querySelector("[data-cart-subtotal]");n&&t.emptyTotal&&(n.textContent=t.emptyTotal,n.setAttribute("value",t.emptyTotal));const s=e.querySelector(".cart-summary__row:not(.cart-summary__row--total) .cart-summary__value");s&&t.emptyShippingLabel&&(s.textContent=t.emptyShippingLabel,s.classList.remove("cart-summary__value--success")),e.querySelector(".cart-summary__checkout")?.setAttribute("disabled","")}updateQuantity(t){const e=u.createStartingMarker(`${t.action}:user-action`);this.#t();const{line:n,quantity:s}=t,{cartTotal:o}=this.refs,r=document.querySelectorAll("cart-items-component"),i=new Set([this.sectionId]);r.forEach(c=>{c instanceof HTMLElement&&c.dataset.sectionId&&i.add(c.dataset.sectionId)});const a=m(this.#n),I=JSON.stringify({line:n,quantity:s,sections:Array.from(i).join(","),sections_url:a.pathname+a.search});h(o),fetch(`${Theme.routes.cart_change_url}`,f("json",{body:I})).then(c=>c.text()).then(c=>{const l=JSON.parse(c);if(y(this),l.errors){this.#E(n,l);return}const E=new DOMParser().parseFromString(l.sections[this.sectionId],"text/html").querySelector('[ref="cartItemCount"]')?.textContent,v=E?parseInt(E,10):0;this.#m(l),this.dispatchEvent(new S({},this.sectionId,{itemCount:v,source:"cart-items-component",action:t.action,sections:l.sections})),p(this.sectionId,l.sections[this.sectionId]),this.#s()}).catch(c=>{}).finally(()=>{this.#e(),u.measureFromMarker(e)})}onRemoveUnavailable(t){t?.stopPropagation();const e=Array.from(this.querySelectorAll(".cart-group--sold-out .cart-item[data-key]")).flatMap(i=>i instanceof HTMLElement?this.#u(i):[]);if(e.length===0)return;const n=u.createStartingMarker("clear-unavailable:user-action");this.#t(),h(this.refs.cartTotal);const s=Object.fromEntries(e.map(i=>[i,0])),o=m(this.#n),r=JSON.stringify({updates:s,sections:this.#r().join(","),sections_url:o.pathname+o.search});fetch(Theme.routes.cart_update_url,f("json",{body:r})).then(i=>i.json()).then(i=>{if(y(this),i.status)return;const a=this.#o(i.sections?.[this.sectionId]);this.dispatchEvent(new S({},this.sectionId,{itemCount:a,source:"cart-items-component",action:"clear",sections:i.sections})),p(this.sectionId,i.sections[this.sectionId]),this.#s()}).catch(i=>{}).finally(()=>{this.#e(),u.measureFromMarker(n)})}onAddonAdd(t,e){if(e?.stopPropagation(),!t)return;const n=e?.target instanceof Element?e.target.closest(".cart-addon__button"):null;n&&(n.classList.add("cart-addon__button--added"),n.setAttribute("disabled",""));const s=()=>{n&&(n.classList.remove("cart-addon__button--added"),n.removeAttribute("disabled"))},o=u.createStartingMarker("add:user-action");this.#t(),h(this.refs.cartTotal);const r=m(this.#n),i=JSON.stringify({items:[{id:t,quantity:1}],sections:this.#r().join(","),sections_url:r.pathname+r.search});fetch(Theme.routes.cart_add_url,f("json",{body:i})).then(a=>a.json()).then(a=>{if(y(this),a.status){s();return}const I=this.#o(a.sections?.[this.sectionId]),c=n?.closest(".cart-addon");c&&(c.classList.add("cart-addon--leaving"),setTimeout(()=>c.remove(),300)),this.dispatchEvent(new S({},this.sectionId,{itemCount:I,source:"cart-items-component",action:"add",sections:a.sections})),p(this.sectionId,a.sections[this.sectionId]),this.#s()}).catch(a=>{s()}).finally(()=>{this.#e(),u.measureFromMarker(o)})}#l(t){if(t.length===0)return;const e=u.createStartingMarker("clear:user-action");this.#t(),h(this.refs.cartTotal);const n=Object.fromEntries(t.map(r=>[r,0])),s=m(this.#n),o=JSON.stringify({updates:n,sections:this.#r().join(","),sections_url:s.pathname+s.search});fetch(Theme.routes.cart_update_url,f("json",{body:o})).then(r=>r.json()).then(r=>{if(y(this),r.status)return;const i=this.#o(r.sections?.[this.sectionId]);this.#m(r),this.dispatchEvent(new S({},this.sectionId,{itemCount:i,source:"cart-items-component",action:"clear",sections:r.sections})),p(this.sectionId,r.sections[this.sectionId]),this.#s()}).catch(r=>{}).finally(()=>{this.#e(),u.measureFromMarker(e)})}get#n(){return this.dataset.sectionsScope||"cart-drawer"}#r(){const t=new Set([this.sectionId]);return document.querySelectorAll("cart-items-component").forEach(e
1=>{e instanceof HTMLElement&&e.dataset.sectionId&&t.add(e.dataset.sectionId)}),Array.from(t)}#o(t){if(!t)return 0;const e=new DOMParser().parseFromString(t,"text/html");return parseInt(e.querySelector('[ref="cartItemCount"]')?.textContent??"0",10)||0}handleDiscountUpdate=t=>{this.#i(t)};#E=(t,e)=>{const n=this.querySelector(`input[data-cart-line="${t}"]`);n instanceof HTMLInputElement&&(n.value=n.defaultValue);const s=this.refs[`cartItemError-${t}`],o=this.refs[`cartItemErrorContainer-${t}`];!(s instanceof HTMLElement)||!(o instanceof HTMLElement)||(s.textContent=e.errors,o.classList.remove("hidden"))};#i=t=>{if(t instanceof T){this.#t(),g.renderSection(this.sectionId,{cache:!1,url:m(this.#n)}).finally(()=>this.#e());return}if(t.target===this)return;const e=t.detail.data.sections?.[this.sectionId];e?(p(this.sectionId,e),this.#s()):(this.#t(),g.renderSection(this.sectionId,{cache:!1,url:m(this.#n)}).finally(()=>this.#e()))};#t(){this.dispatchEvent(new CustomEvent(d.loadingStart,{bubbles:!0,detail:{scope:"cart"}}))}#e(){this.dispatchEvent(new CustomEvent(d.loadingEnd,{bubbles:!0,detail:{scope:"cart"}}))}#m(t){if(t.items)for(const e of t.items){const n=e.variant_id.toString(),s=document.querySelectorAll(`quantity-selector-component[data-variant-id="${n}"], cart-quantity-selector-component[data-variant-id="${n}"]`);for(const o of s){const r=o.querySelector("input[data-cart-quantity]");r&&(r.setAttribute("data-cart-quantity",e.quantity.toString()),"updateCartQuantity"in o&&typeof o.updateCartQuantity=="function"&&o.updateCartQuantity())}}}#s(){const t=document.querySelectorAll("cart-quantity-selector-component");for(const e of t)"updateButtonStates"in e&&typeof e.updateButtonStates=="function"&&e.updateButtonStates()}get sectionId(){const{sectionId:t}=this.dataset;if(!t)throw new Error("Section id missing");return t}}customElements.get("cart-items-component")||customElements.define("cart-items-component",_);
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.