1customElements.get("variant-selects")||customElements.define("variant-selects",class extends HTMLElement{constructor(){super()}get selectedOptionValues(){return Array.from(this.querySelectorAll("select option[selected], fieldset input:checked")).map(({dataset})=>dataset.optionValueId)}getInputForEventTarget(target){return target.tagName==="SELECT"?target.selectedOptions[0]:target}get currentOptionValuesByPosition(){const positions=Array.from(this.querySelectorAll("[data-option-position]")).map(el=>parseInt(el.dataset.optionPosition,10)).filter(position=>!Number.isNaN(position)).sort((a,b)=>a-b);return[...new Set(positions)].map(position=>{const fieldset=this.querySelector(`[data-option-position="${position}"]`),select=fieldset?.querySelector("select"),checkedInput=fieldset?.querySelector("input:checked"),value=select?select.value:checkedInput?checkedInput.value:null;return{position,value}})}get variantsData(){if(this._variantsData)return this._variantsData;const script=this.querySelector("[data-product-variants]");try{this._variantsData=script?JSON.parse(script.textContent):[]}catch{this._variantsData=[]}return this._variantsData}resolveVariantForChange(changedPosition){const variants=this.variantsData;if(!variants||!variants.length)return null;const desired=this.currentOptionValuesByPosition;if(!desired.length)return null;const optionKey=position=>`option${position}`,matchesAll=variant=>desired.every(({position,value})=>variant[optionKey(position)]===value),exactMatch=variants.find(variant=>variant.available&&matchesAll(variant));if(exactMatch)return exactMatch;const changedValue=desired.find(({position})=>position===changedPosition)?.value;if(changedValue==null)return null;const matchesChanged=variant=>variant[optionKey(changedPosition)]===changedValue,scoreVariant=variant=>desired.filter(({position,value})=>position!==changedPosition&&variant[optionKey(position)]===value).length,candidates=variants.filter(matchesChanged),availableCandidates=candidates.filter(variant=>variant.available),pool=availableCandidates.length?availableCandidates:candidates;return pool.length?pool.reduce((best,variant)=>scoreVariant(variant)>scoreVariant(best)?variant:best,pool[0]):null}connectedCallback(){this.addEventListener("change",event=>{const target=this.getInputForEventTarget(event.target);this.updateSelectedSwatchValue(event);const changedFieldset=event.target.closest("[data-option-position]"),changedPosition=changedFieldset?parseInt(changedFieldset.dataset.optionPosition,10):null,resolvedVariant=changedPosition?this.resolveVariantForChange(changedPosition):null;FoxTheme.pubsub.publish(FoxTheme.pubsub.PUB_SUB_EVENTS.optionValueSelectionChange,{data:{event,target,selectedOptionValues:this.selectedOptionValues,resolvedVariantId:resolvedVariant?.id??null}})})}updateSelectedSwatchValue({target}){const{value,tagName}=target;if(tagName==="SELECT"&&target.selectedOptions.length){Array.from(target.options).find(option=>option.getAttribute("selected")).removeAttribute("selected"),target.selectedOptions[0].setAttribute("selected","selected");const swatchValue=target.selectedOptions[0].dataset.optionSwatchValue,selectedDropdownSwatchValue=target.closest(".product-form__input").querySelector("[data-selected-value] > .swatch");if(!selectedDropdownSwatchValue)return;swatchValue?(selectedDropdownSwatchValue.style.setProperty("--swatch--background",swatchValue),selectedDropdownSwatchValue.classList.remove("swatch--unavailable")):(selectedDropdownSwatchValue.style.setProperty("--swatch--background","unset"),selectedDropdownSwatchValue.classList.add("swatch--unavailable")),selectedDropdownSwatchValue.style.setProperty("--swatch-focal-point",target.selectedOptions[0].dataset.optionSwatchFocalPoint||"unset")}else if(tagName==="INPUT"&&target.type==="radio"){const selectedSwatchValue=target.closest(".product-form__input").querySelector("[data-selected-value]");selectedSwatchValue&&(selectedSwatchValue.innerHTML=value)}}}); 2//# sourceMappingURL=/cdn/shop/t/3/assets/variant-selects.js.map?v=132484936383033937531784033903
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.