1import{Component}from"@theme/component";import{ThemeEvents}from"@theme/events";import{formatCurrency}from"@theme/utilities";class ProgressBar extends Component{static get observedAttributes(){return["percent","label"]}#isReady=!1;connectedCallback(){super.connectedCallback(),this.#updateDisplay(),this.#isReady=!0,this.dispatchEvent(new CustomEvent("progress-bar-ready",{bubbles:!0,detail:{element:this}}))}attributeChangedCallback(){this.#isReady&&this.#updateDisplay()}#updateDisplay(){const percent=this.getAttribute("percent")||"0",label=this.getAttribute("label")||"",fill=this.querySelector(".progress-bar__fill");if(fill){const percentValue=Math.min(Math.max(parseFloat(percent),0),100);fill.style.setProperty("--percent",`${percentValue}%`)}const labelElement=this.querySelector(".progress-bar__label");labelElement&&label&&(labelElement.textContent=label)}update(percent,label=""){this.setAttribute("percent",percent.toString()),label&&this.setAttribute("label",label)}}export class FreeShippingGoal extends Component{#progressBarElement=null;connectedCallback(){super.connectedCallback(),document.addEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate),document.addEventListener("progress-bar-ready",this.#handleProgressBarReady),this.#initialize()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate),document.removeEventListener("progress-bar-ready",this.#handleProgressBarReady)}#handleProgressBarReady=event=>{event.detail.element.closest("free-shipping-goal")===this&&(this.#progressBarElement=event.detail.element)};#handleCartUpdate=event=>{const{data}=event.detail;data.sections&&(this.#updateCartTotalFromEvent(data),this.#setupCurrencyConversion(),this.#updateDisplay())};#initialize(){this.#setupCurrencyConversion(),this.#progressBarElement=this.querySelector("progress-bar"),requestAnimationFrame(()=>{this.#updateDisplay()})}#updateCartTotalFromEvent(cartData){if(!cartData.sections)return;const sectionId=this.closest("[data-section-id]")?.dataset.sectionId;if(!sectionId||!cartData.sections[sectionId])return;const newFreeShippingGoal=new DOMParser().parseFromString(cartData.sections[sectionId],"text/html").querySelector("free-shipping-goal");if(!newFreeShippingGoal)return;const newData={cartTotal:newFreeShippingGoal.dataset.cartTotal,currentCurrency:newFreeShippingGoal.dataset.currentCurrency,minimumAmount:newFreeShippingGoal.dataset.minimumAmount,isSingleCurrency:newFreeShippingGoal.dataset.isSingleCurrency,shopCurrency:newFreeShippingGoal.dataset.shopCurrency};let hasChanges=!1;for(const[key,value]of Object.entries(newData))this.dataset[key]!==value&&(this.dataset[key]=value,hasChanges=!0)}#setupCurrencyConversion(){const minimumAmount=parseFloat(this.dataset.minimumAmount),isSingleCurrency=this.dataset.isSingleCurrency==="true",shopCurrency=this.dataset.shopCurrency,currentCurrency=this.dataset.currentCurrency;
1if(isNaN(minimumAmount)||minimumAmount<=0){console.warn("FreeShippingGoal: Invalid minimum amount",this.dataset.minimumAmount),this.convertedAmountInCents=0;return}const cacheKey=`${minimumAmount}-${currentCurrency}-${window.Shopify?.currency?.rate||1}`;if(this.conversionCache?.key!==cacheKey){if(isSingleCurrency&¤tCurrency!==shopCurrency)if(window.Shopify?.currency?.rate){const rate=parseFloat(window.Shopify.currency.rate);!isNaN(rate)&&rate>0?(this.convertedAmount=minimumAmount*rate,this.convertedAmountInCents=Math.round(this.convertedAmount*100)):(console.warn("FreeShippingGoal: Invalid currency rate",window.Shopify.currency.rate),this.convertedAmountInCents=Math.round(minimumAmount*100))}else this.convertedAmountInCents=Math.round(minimumAmount*100);else this.convertedAmountInCents=Math.round(minimumAmount*100);this.conversionCache={key:cacheKey,convertedAmountInCents:this.convertedAmountInCents,minimumAmount,isSingleCurrency,shopCurrency,currentCurrency,rate:window.Shopify?.currency?.rate}}}#updateDisplay(){const cartTotal=parseInt(this.dataset.cartTotal);if(isNaN(cartTotal)||cartTotal<0){console.warn("FreeShippingGoal: Invalid cart total",this.dataset.cartTotal);return}if(this.convertedAmountInCents<=0)return;const isQualified=cartTotal>=this.convertedAmountInCents;this.#toggleStates(isQualified,cartTotal)}getDebugInfo(){return{cartTotal:parseInt(this.dataset.cartTotal),convertedAmountInCents:this.convertedAmountInCents,isQualified:parseInt(this.dataset.cartTotal)>=this.convertedAmountInCents,remainingAmount:this.convertedAmountInCents-parseInt(this.dataset.cartTotal),moneyFormat:window.FoxTheme?.moneyFormat||window.Shopify?.currency?.money_format,conversionInfo:this.conversionInfo}}#updateProgressBar(cartTotal){const progressBarElement=this.#progressBarElement||this.querySelector("progress-bar");if(!progressBarElement)return;const percent=Math.min(cartTotal/this.convertedAmountInCents*100,100);progressBarElement.setAttribute("percent",percent.toString())}#toggleStates(isQualified,cartTotal){const congratulations=this.querySelector(".free-shipping-goal__congratulations"),remaining=this.querySelector(".free-shipping-goal__remaining");if(this.#updateProgressBar(cartTotal),isQualified)congratulations?.classList.remove("hidden"),remaining?.classList.add("hidden");else{congratulations?.classList.add("hidden"),remaining?.classList.remove("hidden");const remainingAmount=this.convertedAmountInCents-cartTotal,remainingElement=this.querySelector(".free-shipping-goal__remaining-amount");if(remainingElement&&remainingAmount>0){const moneyFormat=window.FoxTheme?.moneyFormat||window.Shopify?.currency?.money_format;remainingElement.textContent=formatCurrency(remainingAmount,moneyFormat)}}}}customElements.define("progress-bar",ProgressBar),customElements.define("free-shipping-goal",FreeShippingGoal); 2//# sourceMappingURL=/cdn/shop/t/56/assets/free-shipping-goal.js.map?v=146366777537985313251790721935
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.