1import{morph}from"@theme/morph";import{Component}from"@theme/component";import{ThemeEvents,CartAddEvent}from"@theme/events";import{formatCurrency}from"@theme/utilities";class PricePerItem extends HTMLElement{#abort;connectedCallback(){this.#abort=new AbortController;const{signal}=this.#abort,section=this.closest(".shopify-section, dialog"),form=this.closest("product-form-component");section?.addEventListener(ThemeEvents.variantUpdate,this.#onVariantUpdate,{signal}),form?.addEventListener(ThemeEvents.quantitySelectorUpdate,this.#onQuantityChange,{signal}),document.addEventListener(ThemeEvents.cartUpdate,this.#onCartUpdate,{signal});const input=this.#getQuantityInput();input?.addEventListener("input",this.#sync,{signal}),input?.addEventListener("change",this.#sync,{signal}),this.#sync()}disconnectedCallback(){this.#abort?.abort(),this.#abort=void 0}#onQuantityChange=e=>{this.closest("product-form-component")?.contains(e.target)&&this.#sync()};#onVariantUpdate=e=>{if(e.type!==ThemeEvents.variantUpdate)return;const detail=e.detail,isProductSwitch=!!detail.data?.newProduct,productId=this.closest("product-form-component")?.dataset.productId;if(!isProductSwitch&&detail.data?.productId&&productId&&String(detail.data.productId)!==String(productId))return;const htmlDoc=detail.data?.html,sectionId=this.dataset.sectionId;if(htmlDoc&§ionId){const newRules=htmlDoc.getElementById(`QuantityRules-${sectionId}`),newVol=htmlDoc.getElementById(`Volume-${sectionId}`),curRules=document.getElementById(`QuantityRules-${sectionId}`),curVol=document.getElementById(`Volume-${sectionId}`);newRules&&curRules&&morph(curRules,newRules,{childrenOnly:!0}),newVol&&curVol&&morph(curVol,newVol,{childrenOnly:!0})}const variant=detail.resource;if(!variant?.id){htmlDoc&&this.#sync();return}this.dataset.variantId=String(variant.id);const price=variant.price;price!=null&&(this.dataset.variantPriceCents=String(price)),this.#syncQuantityInput(variant),htmlDoc&&this.#sync()};#syncQuantityInput(variant){const input=this.#getQuantityInput(),rule=variant.quantity_rule;if(!(input instanceof HTMLInputElement)||!rule)return;input.min=String(rule.min??1),input.step=String(rule.increment??1),rule.max!=null?input.max=String(rule.max):input.removeAttribute("max");const min=rule.min??1;let v=parseInt(input.value,10);(Number.isNaN(v)||v<min)&&(v=min),rule.max!=null&&v>rule.max&&(v=rule.max),input.value=String(v)}#onCartUpdate=e=>{const form=this.closest("product-form-component"),productId=form?.dataset.productId,vid=this.dataset.variantId||form?.querySelector('[ref="variantId"]')?.value||form?.querySelector('input[name="id"]')?.value;if(!productId||!vid)return;const d=e.detail;if(!d||e instanceof CartAddEvent&&d.data?.productId&&String(d.data.productId)!==String(productId))return;const cartQty=qtyForVariantFromCartResource(d.resource,vid),input=this.#getQuantityInput();input instanceof HTMLInputElement&&(input.dataset.cartQuantity=String(cartQty)),this.#sync()};#sync=()=>{const sectionId=this.dataset.sectionId,root=document.getElementById(`Volume-${sectionId}`),pairs=[];root&&(root.querySelectorAll("li[data-volume-tier]").forEach(li=>{const qty=parseInt(li.getAttribute("data-volume-tier")||"0",10),text=li.querySelector("[data-text]")?.getAttribute("data-text")||"";qty>0&&text&&pairs.push([qty,text])}),pairs.sort((a,b)=>b[0]-a[0]));const input=this.#getQuantityInput(),out=this.querySelector(".price-per-item__current");if(!(input instanceof HTMLInputElement)||!out)return;const enteredQty=parseInt(input.value,10)||0,totalForTier=parseInt(input.dataset.cartQuantity||"0",10)+enteredQty;if(pairs.length>0){for(const pair of pairs)if(totalForTier>=pair[0]){out.innerHTML=pair[1];return}}const template=this.dataset.priceEachTemplate,centsRaw=this.dataset.variantPriceCents,cents=parseInt(String(centsRaw??""),10);if(template&&Number.isFinite(cents)){const moneyFormat=window.FoxTheme?.moneyFormat||"${{amount}}";out.innerHTML=template.replace(/@@PRICE@@/g,formatCurrency(cents,moneyFormat));return}out.innerHTML=""};#getQuantityInput(){const sid=this.dataset.sectionId,byId=sid?document.getElementById(`Quantity-${sid}-pdp`):null;if(byId instanceof HTMLInputElement)return byId;const form=this.closest("product-form-component"),q=form?.querySelector('quantity-selector-component input[ref="quantityInput"]'),q2=form?.querySelector('input[name="quantity"]');return q instanceof HTMLInputElement?q:q2 instanceof HTMLInputElement?q2:null}}function qtyForVariantInCart(cart,variantId){return cart?.items?.length?cart.items.filter(it=>String(it.variant_id)===String(variantId)).reduce((sum,it)=>sum+it.quantity,0):0}function qtyForVariantFromCartResource(resource,variantId){if(!resource||typeof resource!="object")return 0;const r=resource;if(Array.isArray(r.items))return qtyForVariantInCart(r,variantId);const vid=r.variant_id??r.variantId;if(vid!=null&&String(vid)===String(variantId)){const q=r.quantity,n=typeof q=="number"?q:parseInt(String(q??""),10);return Number.isFinite(n)?n:0}return 0}class VolumePricing extends Component{connectedCallback(){super.connectedCallback(),this.#resetCollapsed()}#isExpanded(){return this.dataset.expanded==="true"}#resetCollapsed(){this.dataset.expanded="false";const btn=this.refs.button;btn instanceof HTMLButtonElement&&btn.setAttribute("aria-expanded","fal
1se")}toggle=event=>{event.preventDefault();const btn=this.refs.button;if(!(btn instanceof HTMLButtonElement))return;const expanded=!this.#isExpanded();this.dataset.expanded=expanded?"true":"false",btn.setAttribute("aria-expanded",String(expanded))}}class VariantCartQty extends Component{requiredRefs=["cartLabel"];#abort;connectedCallback(){super.connectedCallback(),this.#abort=new AbortController;const{signal}=this.#abort;document.addEventListener(ThemeEvents.cartUpdate,this.#onCartUpdate,{signal}),this.section?.addEventListener(ThemeEvents.variantUpdate,this.#onVariantUpdate,{signal})}disconnectedCallback(){this.#abort?.abort(),this.#abort=void 0,super.disconnectedCallback()}get section(){return this.closest(".shopify-section, dialog")}#onCartUpdate=e=>{this.#syncFromCart(e)};#onVariantUpdate=e=>{if(e.type!==ThemeEvents.variantUpdate)return;const detail=e.detail,productId=this.closest("product-form-component")?.dataset.productId;if(detail.data?.productId&&productId&&String(detail.data.productId)!==String(productId))return;const variant=detail.resource;if(!variant?.id)return;this.dataset.variantId=String(variant.id);const htmlDoc=detail.data?.html,sectionId=this.dataset.sectionId;if(htmlDoc&§ionId){const newEl=htmlDoc.getElementById(`QuantityRulesCart-${sectionId}`);if(newEl){morph(this,newEl,{childrenOnly:!0}),this.className=newEl.className;const vid=newEl.getAttribute("data-variant-id");vid&&(this.dataset.variantId=vid);return}}};#syncFromCart(cartEvent){const variantId=this.dataset.variantId,label=this.refs.cartLabel;if(!variantId||!label)return;const qty=qtyForVariantFromCartResource(cartEvent?.detail?.resource,variantId),qtyEl=label.querySelector(".count");qtyEl&&(qtyEl.textContent=String(qty)),this.classList.toggle("hidden",qty===0)}}customElements.get("price-per-item")||customElements.define("price-per-item",PricePerItem),customElements.get("volume-pricing")||customElements.define("volume-pricing",VolumePricing),customElements.get("variant-cart-qty")||customElements.define("variant-cart-qty",VariantCartQty); 2//# sourceMappingURL=/cdn/shop/t/271/assets/price-per-item.js.map?v=27441323952974484901788975975
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.