1const DEBOUNCE_MS=200,CURRENCY_FMT=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}),CURRENCY_FMT_SHORT=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0});let _giftManagementLock=!1;class CartProgressBar extends HTMLElement{#tiers=[];#lastTotal=null;#debounceTimer=null;#isRefreshing=!1;_externalSwapInProgress=!1;connectedCallback(){this.#lastTotal=null,this.#parseTiers(),this.#bindEvents(),this.#scheduleRefresh()}disconnectedCallback(){document.removeEventListener("cart:update",this.#onCartUpdate),document.removeEventListener("cart:synced",this.#onCartGeneric),document.removeEventListener("cart:refresh",this.#onCartGeneric),document.removeEventListener("quantity-selector:update",this.#onCartGeneric),document.removeEventListener("cart-drawer:open",this.#onCartGeneric),this.#debounceTimer&&clearTimeout(this.#debounceTimer)}#parseTiers(){const raw=this.dataset.tiers||"";raw&&(this.#tiers=raw.split(",").map(pair=>{const[name,value]=pair.split(":");return{name:name.trim(),threshold:parseFloat(value)||0}}).filter(t=>t.threshold>0),this.#tiers.sort((a,b)=>a.threshold-b.threshold))}#bindEvents(){document.addEventListener("cart:update",this.#onCartUpdate),document.addEventListener("cart:synced",this.#onCartGeneric),document.addEventListener("cart:refresh",this.#onCartGeneric),document.addEventListener("quantity-selector:update",this.#onCartGeneric),document.addEventListener("cart-drawer:open",this.#onCartGeneric)}#onCartUpdate=e=>{const detail=e.detail,source=detail?.data?.source||detail?.sourceId;source==="cart-progress-bar"||source==="free-gift-variant-selector"||this.#scheduleRefresh()};#onCartGeneric=()=>{this.#scheduleRefresh()};#scheduleRefresh(){this.#debounceTimer&&clearTimeout(this.#debounceTimer),this.#debounceTimer=setTimeout(()=>this.#refresh(),200)}async#refresh(){if(!(this.#isRefreshing||!this.#tiers.length)){this.#isRefreshing=!0;try{const cart=await this.#fetchCart();if(!cart)return;const total=this.#computeEligibleTotal(cart);if(this.#hasOnlyGiftCards(cart)){this.style.display="none",this.#lastTotal=null,this.#handleFreeGift(cart,total);return}if(this.style.display="",this.#lastTotal!==null&&Math.abs(total-this.#lastTotal)<.01)return;this.#lastTotal=total,this.#render(total),this.#handleFreeGift(cart,total)}catch{}finally{this.#isRefreshing=!1}}}async#fetchCart(){const res=await fetch("/cart.js",{credentials:"same-origin",cache:"no-store"});return res.ok?res.json():null}#computeEligibleTotal(cart){const includeGiftCards=this.dataset.includeGiftCards!=="false",includeDigital=this.dataset.includeDigital==="true",includeSecureShield=!0;let total=0;for(const item of cart.items){let itemPrice=item.line_price;document.querySelector(`.bv-cart-item[data-variant-id="${item.variant_id}"]`)&&document.querySelector(`.bv-cart-item[data-variant-id="${item.variant_id}"]`).dataset.itemPrice&&(itemPrice=document.querySelector(`.bv-cart-item[data-variant-id="${item.variant_id}"]`).dataset.itemPrice),includeSecureShield&&item.product_type==="secure-shield"&&(total+=item.line_price||0),!this.#isFreeGiftItem(item)&&(!includeGiftCards&&this.#isGiftCard(item)||!includeDigital&&this.#isDigital(item)||!includeSecureShield&&item.product_type==="secure-shield"||(total+=Number(itemPrice)||0))}return total/100}#isFreeGiftItem(item){return item.properties?._free_gift==="true"||item.properties?._free_gift==="true"}#isGiftCard(item){if(item.gift_card===!0)return!0;const pt=(item.product_type||"").toLowerCase();return pt==="gift card"||pt==="gift cards"}#isDigital(item){return item.requires_shipping===!1}#hasOnlyGiftCards(cart){return cart.items.filter(item=>!this.#isFreeGiftItem(item)&&!this.#isGiftCard(item)).length===0}#hasCampaignSession(){const config=window.SocialCampaignConfig||{};if(!config.freeShippingEnabled||config.sessionEnabled===!1)return!1;const allowedParams=(config.freeShippingParams||"").split(",").map(val=>val.toLowerCase().trim()).filter(val=>val!==""),paramName=config.paramName||"utm_source";let campaignValue="";const cookieName=`shoplc_campaign_${paramName}=`,cookies=document.cookie.split(";");for(let i=0;i<cookies.length;
1i++){const cookie=cookies[i].trim();if(cookie.indexOf(cookieName)===0){campaignValue=decodeURIComponent(cookie.substring(cookieName.length));break}}if(!campaignValue)try{campaignValue=new URLSearchParams(window.location.search).get(paramName)||""}catch{}return campaignValue?allowedParams.length?allowedParams.includes(campaignValue.toLowerCase().trim()):!0:!1}#render(cartTotal){const campaignShippingBoost=this.#hasCampaignSession();this.classList.toggle("cart-progress-bar--campaign-session",campaignShippingBoost);const tierStates=this.#tiers.map(tier=>{const unlocked=campaignShippingBoost&&tier.name==="shipping"||cartTotal>=tier.threshold;return{...tier,unlocked,remaining:unlocked?0:Math.max(0,tier.threshold-cartTotal)}}),barTiers=this.#tiers.filter(t=>t.name!=="expedited"),maxThreshold=barTiers[barTiers.length-1]?.threshold||1;let fillTotal=cartTotal;if(campaignShippingBoost){const shippingTier=this.#tiers.find(t=>t.name==="shipping");shippingTier&&(fillTotal=Math.max(cartTotal,shippingTier.threshold))}const percent=Math.min(100,Math.max(0,fillTotal/maxThreshold*100));this.#renderFill(percent),this.#renderIcons(tierStates.filter(t=>t.name!=="expedited"),maxThreshold),this.#renderMessage(tierStates)}#renderFill(percent){const fill=this.querySelector('[ref="fill"]'),track=this.querySelector('[ref="track"]');fill instanceof HTMLElement&&(fill.style.width=`${percent}%`),track instanceof HTMLElement&&track.setAttribute("aria-valuenow",String(Math.round(percent)))}#renderIcons(tierStates,maxThreshold){for(const tier of tierStates){const refName=`icon${tier.name.charAt(0).toUpperCase()}${tier.name.slice(1)}`,el=this.querySelector(`[ref="${refName}"]`);if(!(el instanceof HTMLElement))continue;const posPercent=Math.max(2,Math.min(100,tier.threshold/maxThreshold*100));el.style.left=`${posPercent}%`,el.style.transform=`translateX(-${posPercent}%)`,el.classList.toggle("cart-progress-bar__icon-wrap--unlocked",tier.unlocked);const label=el.querySelector(".cart-progress-bar__icon-label");label instanceof HTMLElement&&(label.textContent=CURRENCY_FMT_SHORT.format(tier.threshold))}}#renderMessage(tierStates){const msgEl=this.querySelector('[ref="message"]');if(!(msgEl instanceof HTMLElement))return;const firstLocked=tierStates.find(t=>!t.unlocked),allUnlocked=tierStates.every(t=>t.unlocked),unlockedNames=tierStates.filter(t=>t.unlocked).map(t=>t.name);let html="";if(allUnlocked)unlockedNames.length===1?unlockedNames[0]==="expedited"?html=this.#getMessage("expedited-locked"):unlockedNames[0]==="shipping"?html=this.#getMessage("shipping-unlocked"):html=this.#getMessage(unlockedNames[0]):unlockedNames.length==2?html=this.#getMessage(unlockedNames.join("-")):html=this.#getMessage("all-unlocked");else if(!firstLocked)html=this.#getMessage("all-unlocked");else if(firstLocked.name==="shipping")html=this.#fillAmount(this.#getMessage("shipping"),firstLocked.remaining);else if(firstLocked.name==="gift"&&unlockedNames.includes("shipping"))html=this.#fillAmount(this.#getMessage("gift"),firstLocked.remaining);else if(firstLocked.name==="expedited")if(unlockedNames.length===0){const shippingTier=tierStates.find(t=>t.name==="shipping");shippingTier&&!shippingTier.unlocked?html=this.#fillAmount(this.#getMessage("shipping"),shippingTier.remaining):html=this.#fillAmount(this.#getMessage("expedited-unlocked"),firstLocked.remaining)}else unlockedNames.includes("shipping")&&unlockedNames.includes("gift")?html=this.#fillAmount(this.#getMessage("expedited"),firstLocked.remaining):unlockedNames.includes("shipping")?this.#hasCampaignSession()?html=this.#getMessage("shipping-unlocked"):html=this.#fillAmount(this.#getMessage("shipping-expedited-locked"),firstLocked.remaining):html=this.#fillAmount(this.#getMessage("expedited-unlocked"),firstLocked.remaining);else unlockedNames.length>0&&!firstLocked?html=this.#buildUnlockedMessage(unlockedNames):unlockedNames.length>0?html=this.#fillAmount(this.#getMessageForTier(firstLocked.name),firstLocked.remaining):html=this.#fillAmount(this.#getMessage("shipping"),firstLocked.remaining);html.trim()||(html=this.#getMessage("all-unlocked")),msgEl.innerHTML=this.#sanitizeMessage(html)}#getMessage(key){return{shipping:this.dataset.msgShipping||"Spend ${{amount}} more for Free Delivery!",gift:this.dataset.msgGift||"Spend ${{amount}} more to unlock a Free Gift!",expedited:this.dataset.msgExpedited||"Spend ${{amount}} more for Expedited Shipping!","shipping-unlocked":this.dataset.msgShippingUnlocked||"Hooray! You've unlocked <strong>Free Delivery!</strong>","expedited-unlocked":this.dataset.msgExpeditedUnlocked||"Spend ${{amount}} more for <strong>Expedited Shipping!</strong>","expedited-locked":this.dataset.msgExpeditedLocked||"\u{1F389} Hooray! You've unlocked <strong>Expedited Shipping!</strong>","shipping-gift":this.dataset.msgShippingGiftUnlocked||"\u{1F389} Hooray! You've unlocked <strong>Free Delivery & Free Gift!</strong>","shipping-expedited":this.dataset.msgShippingExpeditedUnlocked||"\u{1F389} Hooray! You've unlocked <strong>
1Free Delivery & Expedited Shipping!</strong>","shipping-expedited-locked":this.dataset.msgShippingExpeditedLocked||"\u{1F389} Hooray! You've unlocked <strong>Free Delivery!</strong> Spend <strong>${{amount}}</strong> more for <strong>Expedited Shipping!</strong>","gift-expedited":this.dataset.msgGiftExpeditedUnlocked||"\u{1F389} Hooray! You've unlocked <strong>Free Gift & Expedited Shipping!</strong>","all-unlocked":this.dataset.msgAllUnlocked||"You've unlocked all rewards!"}[key].replace("{{TRUCK_ICON}}",'<svg width="24" height="16" viewBox="0 0 24 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20.4894 3.91379C20.3526 3.74211 20.146 3.6053 19.9394 3.6053H15.5109V0.686723C15.5109 0.308476 15.2024 0 14.8242 0H1.67336C1.29513 0 0.986656 0.30849 0.986656 0.686723C0.986656 1.06497 1.29514 1.37345 1.67336 1.37345H14.1375V13.2544L6.58367 13.2531C6.30872 12.4631 5.55361 11.8797 4.66034 11.8797C3.76707 11.8797 3.01196 12.4631 2.73701 13.2531H1.67206C1.29382 13.2531 0.985352 13.5616 0.985352 13.9398C0.985352 14.3181 1.29383 14.6266 1.67206 14.6266H2.73701C3.01196 15.4166 3.76707 16 4.66034 16C5.55361 16 6.30871 15.4166 6.58367 14.6266H16.816C17.0909 15.4166 17.846 16 18.7393 16C19.6326 16 20.3877 15.4166 20.6626 14.6266H22.7214C23.0996 14.6266 23.4081 14.3181 23.4081 13.9398V8.30939C23.4081 8.17258 23.3732 8.03443 23.2713 7.93114L20.4894 3.91379ZM19.5626 4.97876L21.3826 7.62237H15.5106V4.97876H19.5626ZM20.7294 13.2531C20.4545 12.4631 19.6994 11.8796 18.8061 11.8796C17.9128 11.8796 17.1577 12.4631 16.8828 13.2531H15.5107V8.99609H22.0344V13.2531H20.7294Z" fill="black"/><path d="M6.34867 9.03047C6.34867 8.65223 6.04019 8.34375 5.66196 8.34375H1.06171C0.683469 8.34375 0.375 8.65224 0.375 9.03047C0.375 9.40872 0.683483 9.7172 1.06171 9.7172H5.66196C6.0402 9.7172 6.34867 9.40737 6.34867 9.03047Z" fill="black"/><path d="M0.686708 5.5629H5.28696C5.6652 5.5629 5.97367 5.25441 5.97367 4.87618C5.97367 4.49794 5.66519 4.18945 5.28696 4.18945H0.686708C0.308469 4.18945 0 4.49794 0 4.87618C0 5.25441 0.308483 5.5629 0.686708 5.5629Z" fill="black"/></svg>')||""}#getMessageForTier(tierName){return this.#getMessage(tierName)}#fillAmount(template,amount){return template.replace(/\{\{amount\}\}/g,CURRENCY_FMT.format(amount).replace("$",""))}#buildUnlockedMessage(names){return`Hooray! You've unlocked <strong>${names.map(n=>n==="shipping"?"Free Delivery":n==="gift"?"Free Gift":n==="expedited"?"Free Expedited Shipping":n).join(" & ")}</strong>!`}#sanitizeMessage(html){const tmp=document.createElement("div");return tmp.innerHTML=html,tmp.innerHTML}async#handleFreeGift(cart,cartTotal){const variantId=this.dataset.giftVariantId,giftTier=this.#tiers.find(t=>t.name==="gift");if(!giftTier){await this.#removeFreeGift(cart,variantId),this.#dispatchCartUpdate();return}if(!variantId||!giftTier||_giftManagementLock||this._externalSwapInProgress)return;const eligible=cartTotal>=giftTier.threshold,inCart=this.#isGiftVariantInCart(cart,variantId);if(eligible&&!inCart)await this.#addFreeGift(variantId,giftTier.threshold);else if(!eligible&&inCart)await this.#removeFreeGift(cart,variantId);else if(eligible&&inCart){const configuredId=parseInt(variantId,10);cart.items.some(item=>this.#isFreeGiftItem(item)&&item.variant_id!==configuredId)?await this.#swapFreeGift(cart,variantId,giftTier.threshold):await this.#enforceGiftQuantity(cart)}}#isGiftVariantInCart(cart,_variantId){return cart.items.some(item=>this.#isFreeGiftItem(item))}async#addFreeGift(variantId,threshold){if(!_giftManagementLock){_giftManagementLock=!0;try{const cart=await this.#fetchCart();if(!cart)return;const existingGifts=cart.items.filter(item=>this.#isFreeGiftItem(item));if(existingGifts.length>0){const updates={};for(const item of existingGifts)item.key&&(updates[item.key]=0);await fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates})})}await fetch("/cart/add.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:parseInt(variantId,10),quantity:1,properties:{_free_gift:"true",_gift_message:"Free Gift - Thank you for your purchase!"}})}),this.#dispatchCartUpdate()}catch{}finally{setTimeout(()=>{_giftManagementLock=!1},400)}}}async#swapFreeGift(cart,variantId,threshold){if(!_giftManagementLock){_giftManagementLock=!0;try{const giftItems=cart.items.filter(item=>this.#isFreeGiftItem(item));if(giftItems.length){const updates={};for(const item of giftItems)item.key&&(updates[item.key]=0);await fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates})})}await fetch("/cart/add.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:parseInt(variantId,10),quantity:1,properties:{_free_gift:"true",_gift_message:"Free Gift - Thank you for your purchase!"}})}),this.#dispatchCartUpdate()}catch{}finally{setTimeout(()=>{_giftManagementLock=!1},400)}}}async#removeFreeGift(cart,_variantId){if(!_giftManagementLock){_giftManagementLock=!0;try{const giftItems=cart.items.filter(item=>this.#isFreeGiftItem(item));if(!giftItems.length)return;const updates={};for(const item of giftItems)item.key&&(updates[item.key]=0);await fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates})}),this.#dispatchCartUpdate()}catch{}finally{setTimeout(()=>{_giftManagementLock=!1},400)}}}async#enforceGiftQuantity(cart){const giftItems=cart.items.filter(item=>this.#isFreeGiftItem(item));if(!(!(giftItems.length>1||giftItems.some(item=>(item.quantity||1)>1))||_giftManagementLock)){_giftManagementLock=!0;try{const keepItem=giftItems[0],updates={};for(const item of giftItems)item.key===keepItem.key?updates[item.key]=1:item.key&&(updates[item.key]=0);await fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates})}),this.#dispatchCartUpdate()}catch{}finally{setTimeout(()=>{_giftManagementLock=!1},400)}}}#dispatchCartUpdate(){document.dispatchEvent(new CustomEvent("cart:synced",{bubbles:!0,detail:{source:"cart-progress-bar"}}))}}customElements.get("cart-progress-bar")||customElements.define("cart-progress-bar",CartProgressBar); 2//# sourceMappingURL=/cdn/shop/t/82/assets/cart-progress-bar.js.map?v=164196870720311396171789147585
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.