1if(!customElements.get("swatch-manager")){class SwatchManager extends HTMLElement{constructor(){super(),this.desktopCount=parseInt(this.dataset.desktopCount||0),this.mobileCount=parseInt(this.dataset.mobileCount||0),this.mediumCount=4,this.mediaQuery=window.matchMedia("(max-width: 1100px)"),this.mediumQuery=window.matchMedia("(min-width: 1100px) and (max-width: 1520px)"),this.swatchContainers=Array.from(this.querySelectorAll(".card__swatches")),this.resizeTimeout=null}connectedCallback(){this.mediaQuery.addEventListener("change",this.debounceResizeHandler.bind(this),{passive:!0}),this.mediumQuery.addEventListener("change",this.debounceResizeHandler.bind(this),{passive:!0}),this.setupMoreOptionsHandler(),this.handleScreenChange(this.mediaQuery)}disonnectedCallback(){this.mediaQuery.removeEventListener("change",this.debounceResizeHandler.bind(this)),this.mediumQuery.removeEventListener("change",this.debounceResizeHandler.bind(this))}getAvailableSwatchCount(container){const swatchCountScript=container.querySelector("script[data-swatch-count]");if(swatchCountScript)try{return parseInt(swatchCountScript.textContent)||0}catch(e){console.warn("Failed to parse swatch count from Liquid data:",e)}return container.querySelectorAll(".opt-label:not(.color-opt-more)").length}setupMoreOptionsHandler(){document.addEventListener("click",event=>{const moreLabel=event.target.closest(".color-opt-more");if(!moreLabel)return;const targetId=moreLabel.getAttribute("for");if(!targetId)return;const targetInput=document.getElementById(targetId);if(!targetInput||!targetInput.dataset.variantId)return;const productLink=moreLabel.closest(".card").querySelector(".card-link");if(!productLink)return;const url=new URL(productLink.href);url.searchParams.set("variant",targetInput.dataset.variantId),window.location.href=url.toString()})}debounceResizeHandler(event){clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout(()=>this.handleScreenChange(event),100)}calculateConsistentSize(container){const containerWidth=container.offsetWidth;let maxElements;this.mediaQuery.matches?maxElements=this.mobileCount:this.mediumQuery.matches?maxElements=this.mediumCount:maxElements=this.desktopCount;const gapSpace=(maxElements-1)*6,availableSpace=containerWidth-gapSpace-10,calculatedSize=Math.floor(availableSpace/maxElements);return Math.max(24,Math.min(48,calculatedSize))}applyConsistentSize(container){const consistentSize=this.calculateConsistentSize(container);container.style.setProperty("--consistent-swatch-size",consistentSize+"px")}updateAllContainerSizes(){this.swatchContainers.forEach(container=>{this.applyConsistentSize(container)})}handleScreenChange(e){let currentCount;this.mediaQuery.matches?currentCount=this.mobileCount:this.mediumQuery.matches?currentCount=this.mediumCount:currentCount=this.desktopCount,this.swatchContainers.forEach(container=>{this.updateSwatchContainer(container,currentCount)})}updateSwatchContainer(container,currentCount){const totalAvailableSwatches=this.getAvailableSwatchCount(container),availableSwatches=container.querySelectorAll(".opt-label:not(.color-opt-more)");let moreLabel=container.querySelector(".color-opt-more");if(totalAvailableSwatches>currentCount){const remainingCount=totalAvailableSwatches-currentCount;availableSwatches.forEach((swatch,index)=>{index<currentCount?swatch.style.display="":swatch.style.display="none"}),moreLabel?(this.updateMoreLabel(moreLabel,remainingCount,container,currentCount),moreLabel.style.display=""):this.createMoreLabel(container,remainingCount,currentCount)}else availableSwatches.forEach(swatch=>{swatch.style.display=""}),moreLabel&&(moreLabel.style.display="none")}updateMoreLabel(moreLabel,remainingCount,container,currentCount){const countSpan=moreLabel.querySelector("span:not(.visually-hidden)"),hiddenSpan=moreLabel.querySelector("span.visually-hidden");countSpan&&(countSpan.textContent=`+ ${remainingCount}`),hiddenSpan&&(hiddenSpan.textContent=`+ ${remainingCount}`);const firstHiddenInput=container.querySelectorAll('input[type="radio"]')[currentCount];firstHiddenInput&&moreLabel.setAttribute("for",firstHiddenInput.id)}createMoreLabel(container,remainingCount,currentCount){const firstHiddenInput=container.querySelectorAll('input[type="radio"]')[currentCount];if(!firstHiddenInput)return;const moreLabel=document.createElement("label");moreLabel.className="link-hover-color color-opt-more cursor-pointer",moreLabel.setAttribute("for",firstHiddenInput.id),moreLabel.innerHTML=`
2 <span>+ ${remainingCount}</span> 3 <span class="visually-hidden js-value">+ ${remainingCount}</span> 4 `,container.appendChild(moreLabel)}reinitialize(){this.swatchContainers=Array.from(document.querySelectorAll(".card__swatches")),this.handleScreenChange(this.mediaQuery)}debug(containerId=null){(containerId?[document.getElementById(containerId)]:this.swatchContainers).forEach((container,index)=>{if(!container)return;const totalCount=this.getAvailableSwatchCount(container),visibleCount=container.querySelectorAll(".opt-label:not(.color-opt-more)").length;let currentLimit;this.mediaQuery.matches?currentLimit=this.mobileCount:this.mediumQuery.matches?currentLimit=this.mediumCount:currentLimit=this.desktopCount,console.log(`Swatch Container ${index+1}:`,{totalAvailable:totalCount,visibleInDOM:visibleCount,currentLimit,shouldShowMore:totalCount>currentLimit})})}}customElements.define("swatch-manager",SwatchManager)} 5//# sourceMappingURL=/cdn/shop/t/5/assets/swatch-manager.js.map?v=165285660948244838151757509714
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.