1import{Component}from"@theme/component";import{formatMoney}from"@theme/money-formatting";export default class QuantitySelectorCustom extends Component{#variantPrice=0;#moneyFormat="{{amount}}";#currency="USD";#selectedQuantity=1;#selectedDiscount=0;#subscriptionActive=!1;#subscriptionDiscount=0;#boundSubscriptionHandler=null;#sectionElement=null;#quantityInput=null;connectedCallback(){super.connectedCallback(),this.#variantPrice=parseInt(this.dataset.variantPrice,10)||0,this.#moneyFormat=this.dataset.moneyFormat||"{{amount}}",this.#currency=this.dataset.currency||"USD",this.#sectionElement=this.closest(".shopify-section"),this.#sectionElement&&(this.#boundSubscriptionHandler=event=>this.#subscriptionHandler(event),this.#sectionElement.addEventListener("subscription:changed",this.#boundSubscriptionHandler)),this.#initFromState()}updatedCallback(){super.updatedCallback(),this.#variantPrice=parseInt(this.dataset.variantPrice,10)||0,this.#quantityInput=null;const buttons=this.refs.quantityButtons||[];let restoredButton=buttons.find(btn=>btn.classList.contains("is-active"));if(restoredButton||(restoredButton=buttons.find(btn=>parseInt(btn.dataset.quantity,10)===this.#selectedQuantity)),restoredButton||(restoredButton=buttons[0]||null),restoredButton){for(const btn of buttons)btn.classList.remove("is-active"),btn.setAttribute("aria-checked","false");restoredButton.classList.add("is-active"),restoredButton.setAttribute("aria-checked","true"),this.#updateSelectedLabel(restoredButton);const quantity=parseInt(restoredButton.dataset.quantity,10)||1,discount=parseFloat(restoredButton.dataset.discount)||0,subscribable=restoredButton.dataset.subscribable!=="false";this.#selectedQuantity=quantity,this.#selectedDiscount=discount,this.#updateQuantityInput(String(quantity)),this.#syncSubscribableProperty(subscribable),this.dispatchEvent(new CustomEvent("quantity:changed",{detail:{quantity,discount,subscribable},bubbles:!0}))}this.#updateAtcPrice()}disconnectedCallback(){this.#sectionElement&&this.#boundSubscriptionHandler&&(this.#sectionElement.removeEventListener("subscription:changed",this.#boundSubscriptionHandler),this.#boundSubscriptionHandler=null,this.#sectionElement=null)}#readInitialSubscriptionState(){const toggle=this.closest(".shopify-section")?.querySelector("subscription-toggle")??null;!toggle||toggle.hidden||toggle.querySelector(".subscription-toggle__option.is-active")?.getAttribute("ref")!=="subscribeButton"||(this.#subscriptionActive=!0,this.#subscriptionDiscount=parseFloat(toggle.dataset.subscriptionDiscount)||0)}#initFromState(){this.#readInitialSubscriptionState();const activeButton=(this.refs.quantityButtons||[]).find(btn=>btn.classList.contains("is-active"));if(activeButton){this.#updateQuantityInput(activeButton.dataset.quantity||"1"),this.#updateSelectedLabel(activeButton),this.#selectedQuantity=parseInt(activeButton.dataset.quantity,10)||1,this.#selectedDiscount=parseFloat(activeButton.dataset.discount)||0;const subscribable=activeButton.dataset.subscribable!=="false";this.#syncSubscribableProperty(subscribable),this.#updateAtcPrice(),requestAnimationFrame(()=>{this.dispatchEvent(new CustomEvent("quantity:changed",{detail:{quantity:this.#selectedQuantity,discount:this.#selectedDiscount,subscribable},bubbles:!0}))})}}#subscriptionHandler(event){const detail=event.detail;this.#subscriptionActive=detail.active,this.#subscriptionDiscount=detail.discountPercentage,this.#updateAtcPrice()}#updateSelectedLabel(button){const{selectedLabel}=this.refs;!selectedLabel||!button||(selectedLabel.textContent=button.dataset.label||"")}handleQuantitySelect(event){const target=event.target;if(!target)return;const button=target.closest(".quantity-selector-custom__option");if(!button)return;const quantity=button.dataset.quantity;if(!quantity)return;const buttons=this.refs.quantityButtons||[];for(const btn of buttons)btn.classList.remove("is-active"),btn.setAttribute("aria-checked","false");button.classList.add("is-active"),button.setAttribute("aria-checked","true"),this.#updateSelectedLabel(button),this.#updateQuantityInput(quantity),this.#selectedQuantity=parseInt(quantity,10)||1,this.#selectedDiscount=parseFloat(button.dataset.discount)||0;const subscribable=button.dataset.subscribable!=="false";this.#syncSubscribableProperty(subscribable),this.dispatchEvent(new CustomEvent("quantity:changed",{detail:{quantity:parseInt(quantity,10),discount:this.#selectedDiscount,subscribable},bubbles:!0})),this.#updateAtcPrice()}#updateAtcPrice(){if(!this.#variantPrice)return;const afterQtyDiscount=this.#variantPrice*this.#selectedQuantity*(1-this.#selectedDiscount/100),finalPrice=this.#subscriptionActive?afterQtyDiscount*(1-this.#subscriptionDiscount/100):afterQtyDiscount,roundedPrice=Math.round(finalPrice),formattedPrice=formatMoney(roundedPrice,this.#moneyFormat,this.#currency),section=this.closest(".shopify-section");if(!section)return;const priceSpan=section.querySelector(".buy-buttons-block .add-to-cart-price")??section.querySelector(".add-to-cart-price");if(priceSpan){const button=priceSpan.closest("button");priceSpan.textContent=button?.disabled?"":` | ${formattedPrice}`}this.dispatchEvent(new CustomEvent("price:updated",{detail:{formattedPrice,total:roundedPrice,quantity:this.#selectedQuantity,discount:this.#selectedDiscount,subscriptionActive:this.#subscriptionActive},bubbles:!0}))}refreshPrice(){this.#updateAtcPrice()}#syncSubscribableProperty(subscribable){const form=this.#getBuyBoxForm();if(!form)return;const inputName="properties[_subscribable]";let input=form.querySelector(`input[name="${inputName}"]`);input||(input=document.createElement("input"),input.type="hidden",input.name=inputName,form.appendChild(input)),input.value=subscribable?"true":"false"}#getBuyBoxForm(){const section=this.closest(".shopify-section");return section?section.querySelector('.buy-buttons-block form[data-type="add-to-cart-form"]')??section.querySelector('form[data-type="add-to-cart-form"]'):null}#updateQuantityInput(quantity){const form=this.#getBuyBoxForm();if(!form)return;if(this.#quantityInput&&this.#quantityInput.isConnected){this.#quantityInput.value=quantity,this.#quantityInput.dispatchEvent(new Event("input",{bubbles:!0}));return}let quantityInput=form.querySelector('input[name="quantity"]');quantityInput||(quantityInput=document.createElement("input"),quantityInput.type="hidden",quantityInput.name="quantity",form.appendChild(quantityInput)),this.#quantityInput=quantityInput,quantityInput.value=quantity,quantityInput.dispatchEvent(new Event("input",{bubbles:!0}))}}customElements.define("quantity-selector-custom",QuantitySelectorCustom); 2//# sourceMappingURL=/cdn/shop/t/2043/assets/quantity-selector-custom.js.map?v=169233394701217807081790589465
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.