1import{Component}from"@theme/component";import{QuantitySelectorUpdateEvent}from"@theme/events";import{parseIntOrDefault}from"@theme/utilities";export class QuantitySelectorComponent extends Component{requiredRefs=["quantityInput","minusButton","plusButton"];serverDisabledMinus=!1;serverDisabledPlus=!1;initialized=!1;connectedCallback(){super.connectedCallback();const{minusButton,plusButton}=this.refs;minusButton.disabled&&(this.serverDisabledMinus=!0),plusButton.disabled&&(this.serverDisabledPlus=!0),this.initialized=!0,this.updateButtonStates()}disconnectedCallback(){super.disconnectedCallback()}setCartQuantity(cartQty){this.refs.quantityInput.setAttribute("data-cart-quantity",cartQty.toString()),this.updateCartQuantity()}canAddToCart(){const{max,cartQuantity,value}=this.getCurrentValues(),quantityToAdd=value;return{canAdd:!(max!==null&&cartQuantity+quantityToAdd>max),maxQuantity:max,cartQuantity,quantityToAdd}}getValue(){return this.refs.quantityInput.value}setValue(value){this.refs.quantityInput.value=value}updateConstraints(min,max,step){const{quantityInput}=this.refs,currentValue=parseInt(quantityInput.value)||0;quantityInput.min=min,max?quantityInput.max=max:quantityInput.removeAttribute("max"),quantityInput.step=step;const newMin=parseIntOrDefault(min,1),newStep=parseIntOrDefault(step,1),effectiveMax=this.getEffectiveMax();let newValue=currentValue;(currentValue-newMin)%newStep!==0&&(newValue=newMin+Math.floor((currentValue-newMin)/newStep)*newStep),newValue=Math.max(newMin,Math.min(effectiveMax??1/0,newValue)),newValue!==currentValue&&(quantityInput.value=newValue.toString()),this.updateButtonStates()}getCurrentValues(){const{quantityInput}=this.refs;return{min:parseIntOrDefault(quantityInput.min,1),max:parseIntOrDefault(quantityInput.max,null),step:parseIntOrDefault(quantityInput.step,1),value:parseIntOrDefault(quantityInput.value,0),cartQuantity:parseIntOrDefault(quantityInput.getAttribute("data-cart-quantity"),0)}}getEffectiveMax(){const{max,cartQuantity,min}=this.getCurrentValues();return max===null?null:Math.max(max-cartQuantity,min)}updateButtonStates(){const{minusButton,plusButton}=this.refs,{min,value}=this.getCurrentValues(),effectiveMax=this.getEffectiveMax();this.serverDisabledMinus||(minusButton.disabled=value<=min),this.serverDisabledPlus||(plusButton.disabled=effectiveMax!==null&&value>=effectiveMax)}updateQuantity(stepMultiplier){const{quantityInput}=this.refs,{min,step,value}=this.getCurrentValues(),effectiveMax=this.getEffectiveMax(),newValue=Math.min(effectiveMax??1/0,Math.max(min,value+step*stepMultiplier));quantityInput.value=newValue.toString(),this.onQuantityChange(),this.updateButtonStates()}increaseQuantity(event){event.target instanceof HTMLElement&&(event.preventDefault(),this.updateQuantity(1))}decreaseQuantity(event){event.target instanceof HTMLElement&&(event.preventDefault(),this.updateQuantity(-1))}selectInputValue(event){const{quantityInput}=this.refs;!(event.target instanceof HTMLInputElement)||document.activeElement!==quantityInput||quantityInput.select()}setQuantity(event){if(!(event.target instanceof HTMLInputElement))return;event.preventDefault();const{quantityInput}=this.refs,{min,step}=this.getCurrentValues(),effectiveMax=this.getEffectiveMax(),quantity=Math.min(effectiveMax??1/0,Math.max(min,parseInt(event.target.value)||0));if((quantity-min)%step!==0){quantityInput.value=quantity.toString(),quantityInput.reportValidity();return}quantityInput.value=quantity.toString(),this.onQuantityChange(),this.updateButtonStates()}onQuantityChange(){const{quantityInput}=this.refs,newValue=parseInt(quantityInput.value);this.dispatchEvent(new QuantitySelectorUpdateEvent(newValue,Number(quantityInput.dataset.cartLine)||void 0))}updateCartQuantity(){const{quantityInput}=this.refs,{min,value}=this.getCurrentValues(),effectiveMax=this.getEffectiveMax(),clampedValue=Math.min(effectiveMax??1/0,Math.max(min,value));clampedValue!==value&&(quantityInput.value=clampedValue.toString()),this.updateButtonStates()}get quantityInput(){if(!this.refs.quantityInput)throw new Error('Missing <input ref="quantityInput" /> inside <quantity-selector-component />');return this.refs.quantityInput}}customElements.get("quantity-selector-component")||customElements.define("quantity-selector-component",QuantitySelectorComponent); 2//# sourceMappingURL=/cdn/shop/t/1429/assets/component-quantity-selector.js.map?v=67906657287482036641790022699
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.