PageSourceSearch

https://www.constantlyvariedgear.com/cdn/shop/t/549/assets/td-cart-widgets.js?v=3715410603258381221787254021

js constantlyvariedgear.com collected 2026-09-25 18:42:20 UTC 25,917 bytes, 2 lines download raw bytes

1import{Cart}from"@troop-themes/main";(()=>{function themeOn(eventName,handler,namespace){const key=`${eventName}.${namespace}`;return window.on(key,handler),()=>window.off(key,handler)}function themeOnCartUpdated(cartRoot,handler,namespace){return themeOn("theme:cart:updated",event=>{event.detail!=null&&event.detail!==cartRoot||handler(event)},namespace)}function cartPostItems(items,openDrawer=null){return Cart.addItems({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items,sections:Cart.sections})},openDrawer)}if(!customElements.get("td-cart-cross-sell")){let productIdsKeyFromApiRoot=function(root){return root&&(root.getAttribute("data-td-product-ids")||root.querySelector(crossSellSelectors.productIdsMarker)?.getAttribute("data-td-product-ids"))||""},parseCrossSellSectionDocument=function(htmlText){const root=new DOMParser().parseFromString(htmlText,"text/html").querySelector(crossSellSelectors.apiRoot);return root?{slides:[...root.querySelectorAll(crossSellSelectors.slide)].map(node=>node.cloneNode(!0)),productIdsKey:productIdsKeyFromApiRoot(root)}:{slides:[],productIdsKey:""}};const crossSellSelectors={addButton:"[data-td-add-button]",addButtonText:"[data-td-add-button-text]",apiRoot:"[data-td-cross-sell-api-root]",cartLineItem:"[data-td-cart-item][data-product-id]",productCard:"[data-td-cross-sell-card]",productIdsMarker:"template[data-td-product-ids]",navWrapper:"[data-td-swiper-nav]",comparePrice:"[data-td-price-compare]",currentPrice:"[data-td-price-current]",swiperViewport:"[data-swiper]",slidesTrack:"[data-td-cross-sell-track]",cartBody:".cart--body",slide:"[data-swiper-slide]",swiperComponent:"swiper-slider",titleDefault:"[data-td-title-default]",titleEmptyCart:"[data-td-title-empty]",variantSelect:"[data-td-variant-select]"},crossSellRecommendationsSectionId="td-cart-cross-sell-recommendations";class TDCartCrossSell extends HTMLElement{static index=0;constructor(){super(),this.instanceId=TDCartCrossSell.index+=1,this._onProductAdded=event=>{event.detail!=null&&(this.lastAddedVariantId=String(event.detail))},this._onClick=event=>this.onAddClick(event),this._onVariantChange=event=>this.onVariantChange(event)}connectedCallback(){if(this.cartRoot=this.closest("cart-element"),this.slider=this.querySelector(crossSellSelectors.swiperViewport),this.sliderTrack=this.querySelector(crossSellSelectors.slidesTrack),this.swiperSlider=this.querySelector(crossSellSelectors.swiperComponent),this.nav=this.querySelector(crossSellSelectors.navWrapper),this.titleDefaultNode=this.querySelector(crossSellSelectors.titleDefault),this.titleEmptyNode=this.querySelector(crossSellSelectors.titleEmptyCart),!this.cartRoot||!this.slider||!this.sliderTrack||!this.swiperSlider)return;this.source=this.dataset.tdSource||"manual",this.maxProducts=Number.parseInt(this.dataset.tdMaxProducts,10)||6,this.showOnEmptyCart=this.dataset.tdShowOnEmpty==="true",this.lastAddedVariantId="",this.lastRenderedKey="",this.lastCartCrossSellFingerprint="",this.crossSellSectionId=this.dataset.tdCrossSellSectionId||crossSellRecommendationsSectionId,this._crossSellUpdateRunning=!1,this._crossSellUpdateQueued=!1,this.stampedRefreshTimer=null,this.sliderTrack.addEventListener("click",this._onClick),this.sliderTrack.addEventListener("change",this._onVariantChange);const namespace=`TDCartCrossSell${this.instanceId}`;this._unsubs=[themeOn("theme:cart:productAdded",this._onProductAdded,namespace),themeOnCartUpdated(this.cartRoot,()=>this.onCartSectionUpdated(),namespace)],this.lastCartCrossSellFingerprint=this.cartCrossSellFingerprint(),this.hydrateFromSSR(),this.source==="search_discovery"&&!this.sliderTrack.querySelector(crossSellSelectors.slide)&&this.queueCrossSellUpdate()}disconnectedCallback(){this.sliderTrack?.removeEventListener("click",this._onClick),this.sliderTrack?.removeEventListener("change",this._onVariantChange),this._unsubs?.forEach(unsubscribe=>unsubscribe()),this.stampedRefreshTimer&&window.clearTimeout(this.stampedRefreshTimer)}queueCrossSellUpdate(){if(this._crossSellUpdateRunning){this._crossSellUpdateQueued=!0;return}let snapshot=null;if(this.source!=="search_discovery"&&(snapshot=this.cartCrossSellFingerprint(),snapshot===this.lastCartCrossSellFingerprint))return;this._crossSellUpdateRunning=!0,(this.source==="search_discovery"?this.refresh():this.applyCrossSellFragment(snapshot)).catch(err=>console.error(this.source==="search_discovery"?"Cart cross-sell refresh failed":"Cart cross-sell fragment refresh failed",err)).finally(()=>{this._crossSellUpdateRunning=!1,this._crossSellUpdateQueued&&(this._crossSellUpdateQueued=!1,this.queueCrossSellUpdate())})}onCartSectionUpdated(){this.queueCrossSellUpdate()}cartCrossSellFingerprint(){const body=this.cartRoot.querySelector(crossSellSelectors.cartBody);if(body?.hasAttribute("data-td-cart-product-ids")){const empty=body.getAttribute("data-td-cart-empty")==="true",ids=body.getAttribute("data-td-cart-product-ids")??"";return`${empty?"e":"n"}:${ids}`}return""}async applyCrossSellFragment(snapshot){const empty=this.isCartEmptyForCrossSell();if(this.swapTitles(empty),empty&&!this.showOnEmptyCart){this.hide(),this.lastCartCrossSellFingerprint=snapsh
1ot;return}const res=await this.fetchStorefrontCrossSellSectionResponse();if(!res.ok)throw new Error(res.statusText);if(this.cartCrossSellFingerprint()!==snapshot)return;const{slides,productIdsKey}=parseCrossSellSectionDocument(await res.text());this.renderSlideElements(slides,productIdsKey),this.lastCartCrossSellFingerprint=snapshot}fetchStorefrontCrossSellSectionResponse(){const rootPath=window.Shopify?.routes?.root??"/",url=new URL(rootPath,window.location.href);return url.searchParams.set("section_id",this.crossSellSectionId),fetch(url.toString())}hydrateFromSSR(){if(this.isCartEmptyForCrossSell()&&!this.showOnEmptyCart){this.hide();return}const slides=[...this.sliderTrack.querySelectorAll(crossSellSelectors.slide)];this.renderSlideElements(slides,this.readProductIdsKeyFromTrack())}async refresh(){const empty=this.isCartEmptyForCrossSell();if(this.swapTitles(empty),empty&&!this.showOnEmptyCart){this.hide();return}if(empty&&this.showOnEmptyCart){try{const res=await this.fetchStorefrontCrossSellSectionResponse();if(!res.ok)throw new Error(res.statusText);const{slides:slides2,productIdsKey:productIdsKey2}=parseCrossSellSectionDocument(await res.text());this.renderSlideElements(slides2,productIdsKey2)}catch(err){console.error("Cart cross-sell empty-cart section fetch failed",err),this.hydrateFromSSR()}return}const cartItems=this.getCartItems(),{slides,productIdsKey}=await this.fetchRecommendationSlides(cartItems);this.renderSlideElements(slides,productIdsKey)}isCartEmptyForCrossSell(){const empty_attr=document.querySelector("[data-cart-empty]")?.getAttribute("data-cart-empty");return empty_attr?empty_attr==="true":!1}hide(){this.setAttribute("aria-hidden","true"),this.slider?.setAttribute("aria-hidden","true"),this.nav?.setAttribute("aria-hidden","true"),this.lastRenderedKey=""}show(){this.setAttribute("aria-hidden","false"),this.slider?.setAttribute("aria-hidden","false"),this.nav?.removeAttribute("aria-hidden")}swapTitles(isEmpty){const defaultTitle=this.titleDefaultNode,emptyTitle=this.titleEmptyNode;!defaultTitle||!emptyTitle||(isEmpty?(defaultTitle.setAttribute("hidden","hidden"),emptyTitle.removeAttribute("hidden")):(emptyTitle.setAttribute("hidden","hidden"),defaultTitle.removeAttribute("hidden")))}getCartItems(){return[...this.cartRoot.querySelectorAll(crossSellSelectors.cartLineItem)].map(line=>({productId:Number.parseInt(line.getAttribute("data-product-id"),10),variantId:String(line.getAttribute("data-variant-id")||"")})).filter(line=>!Number.isNaN(line.productId))}readProductIdsKeyFromTrack(){return this.sliderTrack?.querySelector(crossSellSelectors.productIdsMarker)?.getAttribute("data-td-product-ids")??""}async fetchRecommendationSlides(cartItems){const empty={slides:[],productIdsKey:""},seed=this.seedId(cartItems);if(!seed)return empty;const res=await fetch(`${Shopify.routes.product_recommendations}?section_id=${crossSellRecommendationsSectionId}&product_id=${seed}&limit=${this.maxProducts}`);return res.ok?parseCrossSellSectionDocument(await res.text()):empty}seedId(items){if(this.lastAddedVariantId){const match=items.find(line=>line.variantId===this.lastAddedVariantId);if(match)return match.productId}return items.length?items[items.length-1].productId:null}renderSlideElements(slides,productIdsKey=""){if(!slides.length){this.hide(),this.lastRenderedKey="";return}if(this.show(),productIdsKey&&productIdsKey===this.lastRenderedKey){this.syncSwiper();return}this.sliderTrack.replaceChildren(...slides),this.lastRenderedKey=productIdsKey,this.stampedSoon(),this.syncSwiper()}syncSwiper(){const swiperInstance=this.swiperSlider.slider;!swiperInstance||!this.sliderTrack.querySelector(crossSellSelectors.slide)||(swiperInstance.update(),swiperInstance.slideTo(0,0,!1))}stampedSoon(){this.querySelector(".stamped-product-reviews-badge")&&(this.stampedRefreshTimer&&window.clearTimeout(this.stampedRefreshTimer),this.stampedRefreshTimer=window.setTimeout(()=>{!this.isConnected||typeof window.StampedFn?.loadBadges!="function"||window.StampedFn.loadBadges()},0))}onVariantChange(event){const target=event.target;if(!(target instanceof Element))return;const select=target.closest(crossSellSelectors.variantSelect);if(!select||!(select instanceof HTMLSelectElement))return;const card=select.closest(crossSellSelectors.productCard);if(!card)return;const addButton=card.querySelector(crossSellSelectors.addButton),addLabel=card.querySelector(crossSellSelectors.addButtonText),priceEl=card.querySelector(crossSellSelectors.currentPrice),compareEl=card.querySelector(crossSellSelectors.comparePrice),selectedOption=select.options[select.selectedIndex];if(!(!addButton||!addLabel||!priceEl||!compareEl)){if(!select.value){addButton.setAttribute("disabled","disabled"),addButton.dataset.tdSelectedVariantId="",addLabel.textContent=addButton.dataset.tdChooseSizeText||"Choose size";return}addButton.dataset.tdSelectedVariantId=select.value,addButton.removeAttribute("disabled"),addLabel.textContent=addButton.dataset.tdAddText||"Add to cart",priceEl.innerHTML=selectedOption.dataset.tdPrice||"",selectedOption.dataset.tdComparePrice?
1(compareEl.hidden=!1,compareEl.innerHTML=selectedOption.dataset.tdComparePrice):(compareEl.hidden=!0,compareEl.innerHTML="")}}async onAddClick(event){const target=event.target;if(!(target instanceof Element))return;const addButton=target.closest(crossSellSelectors.addButton);if(!addButton||(event.preventDefault(),addButton.hasAttribute("disabled")||addButton.getAttribute("aria-busy")==="true"))return;const variantId=Number.parseInt(addButton.dataset.tdSelectedVariantId,10);if(!Number.isNaN(variantId)){addButton.setAttribute("aria-busy","true"),addButton.setAttribute("disabled","disabled");try{await cartPostItems([{id:variantId,quantity:1}],null)}catch(err){console.error("Cart cross-sell add to cart failed",err)}finally{addButton.setAttribute("aria-busy","false"),addButton.dataset.tdSelectedVariantId&&addButton.removeAttribute("disabled")}}}}customElements.define("td-cart-cross-sell",TDCartCrossSell)}if(!customElements.get("td-cart-progress")){const progressSelectors={cartBody:".cart--body",gwpActions:"[data-td-gwp-actions]",gwpAddButton:"[data-td-gwp-add]",gwpCard:"[data-td-gwp-card]",gwpLineItem:'[data-td-cart-item][data-td-gwp-line="true"]',gwpVariantSelect:"[data-td-gwp-variant-select]",gwpWrap:"[data-td-gwp-wrap]",progressFill:"[data-td-progress-fill]",progressMessage:"[data-td-progress-message]",tierIcon:"[data-td-tier-icon]"};class TDCartProgress extends HTMLElement{static index=0;constructor(){super(),this.instanceId=TDCartProgress.index+=1,this._progressRafId=null,this._gwpMutationInFlight=!1,this._gwpMutationQueued=!1,this.busy=!1,this._autoAddPending=!1,this._onClick=event=>this.onClick(event),this._onChange=event=>this.onChange(event)}scheduleProgressUpdate(){this._progressRafId==null&&(this._progressRafId=requestAnimationFrame(()=>{if(this._progressRafId=null,!this.isConnected)return;const state=this.getState();this.render(state),this.runGwpMutations(state)}))}runGwpMutations(state){if(!(!this.gwpActive||!this.isConnected)){if(this._gwpMutationInFlight){this._gwpMutationQueued=!0;return}this._gwpMutationInFlight=!0,this.syncMutations(state).catch(error=>console.error("Cart GWP mutation failed",error)).finally(()=>{if(this._gwpMutationInFlight=!1,!this.isConnected){this._gwpMutationQueued=!1;return}this._gwpMutationQueued&&(this._gwpMutationQueued=!1,this.runGwpMutations(this.getState()))})}}getState(){const cartTotalCents=this.readCartTotalCents(),giftLine=this.giftLineItems()[0]||null,parsedLine=Number.parseInt(giftLine?.getAttribute("data-line-num")||"",10),giftLineNumber=Number.isFinite(parsedLine)&&parsedLine>=1?parsedLine:0;return{cartTotalCents,giftLineNumber,giftInCart:giftLine!=null,shippingReached:this.shippingActive&&this.shippingThreshold>0&&cartTotalCents>=this.shippingThreshold,gwpReached:this.gwpActive&&this.gwpThreshold>0&&cartTotalCents>=this.gwpThreshold,singleAutoVariantId:this.normalizeVariantId(this.singleProductAutoVariantId),busy:this.busy}}render(state){if(this.syncPrimaryMessage(state.cartTotalCents,state.shippingReached,state.gwpReached),this.syncProgressFill(state.cartTotalCents),this.syncTierIcons(state.shippingReached,state.gwpReached),this.gwpWrap&&(state.gwpReached&&!state.giftInCart?(this.gwpWrap.removeAttribute("hidden"),this.gwpWrap.removeAttribute("inert"),this.gwpWrap.setAttribute("aria-hidden","false")):(this.gwpWrap.setAttribute("aria-hidden","true"),this.gwpWrap.setAttribute("hidden",""),this.gwpWrap.setAttribute("inert",""))),this.gwpPreview){const hidePreviewStrip=state.giftInCart||!this.gwpActive||state.gwpReached;this.gwpPreview.toggleAttribute("hidden",hidePreviewStrip)}if(this.gwpActive)for(const card of this.querySelectorAll(progressSelectors.gwpCard)){const actions=card.querySelector(progressSelectors.gwpActions);actions&&(actions.hidden=state.giftInCart);const addButton=card.querySelector(progressSelectors.gwpAddButton);if(!addButton)continue;const hasVariant=!!addButton.dataset.tdSelectedVariantId,canAdd=state.gwpReached&&!state.giftInCart&&hasVariant;addButton.toggleAttribute("disabled",!canAdd||state.busy);const variantSelect=card.querySelector(progressSelectors.gwpVariantSelect);variantSelect instanceof HTMLSelectElement&&variantSelect.toggleAttribute("disabled",state.busy)}}async syncMutations(state){if(!this.gwpActive||!this.isMutationOwner()||!this.isConnected)return;if(!state.gwpReached){this._autoAddPending=!1,state.giftInCart&&await this.removeGiftLines(state);return}if(state.giftInCart)return;const autoId=state.singleAutoVariantId;this.gwpProductsCount===1&&autoId>0&&!this._autoAddPending&&(this._autoAddPending=!0,await this.addGiftVariant(autoId
1))}connectedCallback(){if(this.cartRoot=this.closest("cart-element"),!this.cartRoot)return;this.progressMessageNode=this.querySelector(progressSelectors.progressMessage),this.progressFill=this.querySelector(progressSelectors.progressFill),this.gwpWrap=this.querySelector(progressSelectors.gwpWrap),this.gwpPreview=this.querySelector("[data-td-gwp-preview]");const cfg=JSON.parse(this.getAttribute("data-td-config")||"{}"),ship=cfg.shipping||{},gwp=cfg.gwp||{};this.moneyFormat=cfg.moneyFormat||"${{amount}}",this.shippingActive=ship.active===!0,this.shippingThreshold=ship.threshold||0,this.shippingBeforeTemplate=ship.beforeTemplate||"",this.shippingAfterTemplate=ship.afterTemplate||"",this.gwpActive=gwp.active===!0,this.gwpThreshold=gwp.threshold||0,this.gwpBeforeTemplate=gwp.beforeTemplate||"",this.gwpAfterTemplate=gwp.afterTemplate||"",this.gwpProductsCount=gwp.productsCount||0,this.singleProductAutoVariantId=Number.parseInt(String(gwp.singleAutoVariantId??""),10)||0,this.applyLayoutFromConfig(),this.gwpActive&&(this.addEventListener("click",this._onClick),this.addEventListener("change",this._onChange)),this._unsub=themeOnCartUpdated(this.cartRoot,()=>this.scheduleProgressUpdate(),`TDCartProgress${this.instanceId}`),this.scheduleProgressUpdate()}applyLayoutFromConfig(){const shippingTierCents=this.shippingActive&&this.shippingThreshold>0?this.shippingThreshold:0,gwpTierCents=this.gwpActive&&this.gwpThreshold>0?this.gwpThreshold:0;this.dualBar=this.shippingActive&&this.gwpActive&&shippingTierCents>0&&gwpTierCents>0,this.dualBar?(this.dualTierLowCents=Math.min(shippingTierCents,gwpTierCents),this.dualTierHighCents=Math.max(shippingTierCents,gwpTierCents)):(this.dualTierLowCents=0,this.dualTierHighCents=0),this.maxThreshold=Math.max(shippingTierCents,gwpTierCents)}disconnectedCallback(){this._progressRafId!=null&&(cancelAnimationFrame(this._progressRafId),this._progressRafId=null),this.removeEventListener("click",this._onClick),this.removeEventListener("change",this._onChange),this._unsub?.()}readCartTotalCents(){const cartBody=this.cartRoot.querySelector(progressSelectors.cartBody);if(!cartBody)return 0;const raw=Number.parseInt(cartBody.getAttribute("data-td-cart-total-cents")||"0",10);return Number.isNaN(raw)?0:raw}giftLineItems(){return[...this.cartRoot.querySelectorAll(progressSelectors.gwpLineItem)]}formatMoney(cents){const normalized=Math.max(0,Number.isFinite(cents)?cents:0);if(typeof window.Shopify?.formatMoney=="function")try{return window.Shopify.formatMoney(normalized,this.moneyFormat)}catch{}return`$${(normalized/100).toFixed(2)}`}resolveMessage(beforeTemplate,afterTemplate,goalReached,thresholdCents,cartTotalCents){if(goalReached)return afterTemplate;const remainingCents=Math.max(thresholdCents-cartTotalCents,0);return beforeTemplate.replace("[$]",this.formatMoney(remainingCents))}syncPrimaryMessage(cartTotalCents,shippingReached,gwpReached){if(this.progressMessageNode){if(!this.shippingActive&&!this.gwpActive){this.progressMessageNode.textContent="";return}if(this.shippingActive&&!this.gwpActive){this.progressMessageNode.textContent=this.resolveMessage(this.shippingBeforeTemplate,this.shippingAfterTemplate,shippingReached,this.shippingThreshold,cartTotalCents);return}if(this.gwpActive&&!this.shippingActive){this.progressMessageNode.textContent=this.resolveMessage(this.gwpBeforeTemplate,this.gwpAfterTemplate,gwpReached,this.gwpThreshold,cartTotalCents);return}this.progressMessageNode.textContent=this.dualPrimaryMessageText(cartTotalCents,shippingReached,gwpReached)}}dualPrimaryMessageText(cartTotalCents,shippingReached,gwpReached){const shippingLimitCents=this.shippingThreshold,gwpLimitCents=this.gwpThreshold,buildShippingMessage=()=>this.resolveMessage(this.shippingBeforeTemplate,this.shippingAfterTemplate,shippingReached,shippingLimitCents,cartTotalCents),buildGwpMessage=()=>this.resolveMessage(this.gwpBeforeTemplate,this.gwpAfterTemplate,gwpReached,gwpLimitCents,cartTotalCents);return gwpLimitCents<shippingLimitCents?gwpReached?shippingReached?this.shippingAfterTemplate:buildShippingMessage():buildGwpMessage():shippingLimitCents<gwpLimitCents?shippingReached?gwpReached?this.gwpAfterTemplate:buildGwpMessage():buildShippingMessage():shippingReached?gwpReached?this.shippingAfterTemplate:buildGwpMessage():buildShippingMessage()}
1syncProgressFill(cartTotalCents){if(!this.progressFill)return;let percent=0;if(this.dualBar&&this.dualTierHighCents>0&&this.dualTierLowCents>=0){const lowerTierCents=this.dualTierLowCents,upperTierCents=this.dualTierHighCents;if(cartTotalCents<=lowerTierCents)percent=lowerTierCents>0?Math.min(50,cartTotalCents*50/lowerTierCents):0;else{const spanBetweenTiersCents=Math.max(upperTierCents-lowerTierCents,1);percent=50+Math.min(50,(cartTotalCents-lowerTierCents)*50/spanBetweenTiersCents)}percent=Math.min(100,percent)}else this.maxThreshold>0&&(percent=Math.min(100,cartTotalCents*100/this.maxThreshold));this.progressFill.style.setProperty("--progress-percent",`${percent}%`)}syncTierIcons(shippingReached,gwpReached){if(!(!this.dualBar||!this.shippingActive||!this.gwpActive))for(const icon of this.querySelectorAll(progressSelectors.tierIcon)){const tier=icon.getAttribute("data-td-tier"),filled=tier==="shipping"&&shippingReached||tier==="gwp"&&gwpReached;icon.setAttribute("data-td-filled",filled?"true":"false")}}async removeGiftLines(state){const line=state.giftLineNumber;if(line<1){state.giftInCart&&console.error("TDCartProgress: gift rows had no valid data-line-num for removal"),state.gwpReached=!1,state.giftInCart=!1;return}const response=await fetch(`${Shopify.routes.cart_change}.js`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({line,quantity:0,sections:Cart.sections})});if(!response.ok)throw new Error(response.statusText);state.gwpReached=!1,state.giftInCart=!1;const payload=await response.json();Cart.fillBasket(payload.items),Cart.updateTotals(payload.item_count),Cart.updateAllHtml(payload.sections,!0)}normalizeVariantId(variantId){const n=typeof variantId=="number"&&Number.isFinite(variantId)?Math.trunc(variantId):Number.parseInt(String(variantId),10);return Number.isFinite(n)&&n>0?n:0}async addGiftVariant(variantId){const id=this.normalizeVariantId(variantId);if(!(this.busy||id<=0)){this.setBusy(!0);try{await cartPostItems([{id,quantity:1,properties:{_td_gwp:"true"}}],null)}catch(error){console.error("GWP add to cart failed",error)}finally{this.setBusy(!1)}}}setBusy(isBusy){this.busy=isBusy,this.setAttribute("aria-busy",isBusy?"true":"false");for(const button of this.querySelectorAll(progressSelectors.gwpAddButton))button.toggleAttribute("disabled",isBusy);for(const select of this.querySelectorAll(progressSelectors.gwpVariantSelect))select instanceof HTMLSelectElement&&select.toggleAttribute("disabled",isBusy)}isMutationOwner(){return this.cartRoot?.dataset.view==="drawer"?!0:this.offsetParent!==null}async onClick(event){const target=event.target;if(!(target instanceof Element))return;const addButton=target.closest(progressSelectors.gwpAddButton);if(!addButton)return;event.preventDefault();const state=this.getState();if(addButton.hasAttribute("disabled")||addButton.getAttribute("aria-busy")==="true"||state.busy||state.giftInCart||this.gwpActive&&this.gwpThreshold>0&&state.cartTotalCents<this.gwpThreshold)return;const variantId=this.normalizeVariantId(addButton.dataset.tdSelectedVariantId||"");variantId<=0||await this.addGiftVariant(variantId)}onChange(event){const target=event.target;if(!(target instanceof Element))return;const select=target.closest(progressSelectors.gwpVariantSelect);if(!select||!(select instanceof HTMLSelectElement))return;const card=select.closest(progressSelectors.gwpCard);if(!card)return;const addButton=card.querySelector(progressSelectors.gwpAddButton);if(!addButton)return;const addLabel=addButton.querySelector("[data-td-add-button-text]"),addText=addButton.dataset.tdAddText||"Add to cart",chooseText=addButton.dataset.tdChooseText||addButton.dataset.tdChooseSizeText||"Choose options";select.value?(addButton.dataset.tdSelectedVariantId=select.value,addLabel&&(addLabel.textContent=addText)):(addButton.dataset.tdSelectedVariantId="",addLabel&&(addLabel.textContent=chooseText)),this.render(this.getState())}}customElements.define("td-cart-progress",TDCartProgress)}if(!customElements.get("td-cart-shipping-protection")){const shippingSelectors={cartLineItem:"[data-td-cart-item]",protectionToggle:"[data-td-shipping-protection-toggle]"};class TDCartShippingProtection extends HTMLElement{static index=0;constructor(){super(),this.instanceId=TDCartShippingProtection.index+=1,this.busy=!1,this._onToggle=event=>this.toggleLine(event)}connectedCallback(){this.cartRoot=this.closest("cart-element"),this.toggle=this.querySelector(shippingSelectors.protectionToggle),this.variantId=Number.parseInt(this.dataset.tdVariantId,10),!(!this.cartRoot||!this.toggle||Number.isNaN(this.variantId))&&(this.toggle.addEventListener("change",this._onToggle),this._unsub=themeOnCartUpdated(this.cartRoot,()=>this.syncState(),`TDCartShippingProtection${this.instanceId}`),this.syncState())}disconnectedCallback(){this.toggle?.removeEventListener("change",this._onToggle),this._unsub?.()}lineCount(){return this.cartRoot.querySelectorAll(shippingSelectors.cartLineItem).length}syncDrawerSummarySpacer(){this.cartRoot?.dataset.view==="drawer"&&typeof this.cartRoot.updateSummaryHeight=="function"&&window.requestAnimationFrame(()=>{this.isConnected&&this.cartRoot.updateSummaryHeight()})}inCart(){if(this.cartRoot.querySelector(`${shippingSelectors.cartLineItem}[data-variant-id="${this.variantId}"]`))return!0;
1const qty=Cart.basket.get(this.variantId);return typeof qty=="number"&&qty>0}setBusy(isBusy){this.busy=isBusy,this.setAttribute("aria-busy",isBusy?"true":"false"),this.toggle?.toggleAttribute("disabled",isBusy)}syncState(){const protectionInCart=this.inCart();this.dataset.tdInCart=protectionInCart?"true":"false",this.setAttribute("aria-hidden",this.lineCount()>0?"false":"true"),this.toggle.checked=protectionInCart,this.syncDrawerSummarySpacer()}async toggleLine(event){const input=event.target;if(input instanceof HTMLInputElement){if(this.busy){event.preventDefault();return}this.setBusy(!0);try{if(input.checked)await cartPostItems([{id:this.variantId,quantity:1,properties:{_td_shipping_protection:"true"}}],null);else{const response=await fetch(`${Shopify.routes.cart_update}.js`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:{[this.variantId]:0},sections:Cart.sections})});if(!response.ok)throw new Error(response.statusText);const payload=await response.json();Cart.fillBasket(payload.items),Cart.updateTotals(payload.item_count),Cart.updateAllHtml(payload.sections,!0)}}catch(err){console.error("Shipping protection update failed",err)}finally{this.setBusy(!1),this.syncState()}}}}customElements.define("td-cart-shipping-protection",TDCartShippingProtection)}})();
2//# sourceMappingURL=/cdn/shop/t/549/assets/td-cart-widgets.js.map?v=3715410603258381221787254021

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.