1import{Component}from"@theme/component";import{ThemeEvents}from"@theme/events";import{StandardEvents}from"@shopify/events";class PricePerItemComponent extends Component{#priceBreaks=[];#abortController=new AbortController;connectedCallback(){super.connectedCallback(),this.#parsePriceBreaks(),this.#attachEventListeners(),this.#updatePriceDisplay()}disconnectedCallback(){super.disconnectedCallback(),this.#abortController.abort()}#parsePriceBreaks(){const minQuantity=parseInt(this.dataset.minQuantity||"")||1,{variantPrice,priceBreaks:priceBreaksData}=this.dataset;if(variantPrice&&this.#priceBreaks.push({quantity:minQuantity,price:variantPrice}),priceBreaksData){const breaks=JSON.parse(priceBreaksData);for(const{quantity,price}of breaks)quantity&&price&&this.#priceBreaks.push({quantity:parseInt(quantity),price})}this.#priceBreaks.sort((a,b)=>b.quantity-a.quantity)}#attachEventListeners(){const{signal}=this.#abortController;document.addEventListener(ThemeEvents.quantitySelectorUpdate,this.#handleQuantityUpdate,{signal}),document.addEventListener(StandardEvents.cartLinesUpdate,this.#handleCartUpdate,{signal})}#handleQuantityUpdate=event=>{const form=this.closest("product-form-component");!form||!(event.target instanceof Node)||!form.contains(event.target)||this.#updatePriceDisplay()};#handleCartUpdate=event=>{event.promise?.then(()=>this.#updatePriceDisplay()).catch(error=>{error?.name!=="AbortError"&&console.warn("[price-per-item] Cart update promise rejected:",error)})};#getCurrentQuantity(){const quantityInput=this.closest("product-form-component")?.querySelector('input[name="quantity"]');if(!quantityInput)return 1;const cartQty=parseInt(quantityInput.getAttribute("data-cart-quantity")||"0")||0,inputQty=parseInt(quantityInput.value)||1;return cartQty+inputQty}updatePriceDisplay(){if(!this.#priceBreaks.length||!this.refs.pricePerItemText)return;const quantity=this.#getCurrentQuantity(),priceBreak=this.#priceBreaks.find(pb=>quantity>=pb.quantity)??this.#priceBreaks[this.#priceBreaks.length-1];priceBreak&&(this.refs.pricePerItemText.innerHTML=`${this.dataset.atText} ${priceBreak.price}/${this.dataset.eachText}`)}#updatePriceDisplay=()=>{this.updatePriceDisplay()}}customElements.get("price-per-item")||customElements.define("price-per-item",PricePerItemComponent); 2//# sourceMappingURL=/cdn/shop/t/3/assets/price-per-item.js.map?v=115937180292451397851782122108
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.