ui.shipaid.com 0.3.154 → 0.3.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.es.js CHANGED
@@ -6173,7 +6173,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
6173
6173
  margin-left: 3px;
6174
6174
  }
6175
6175
  </style>
6176
- <div class="shipaid-container">
6176
+ <div class="shipaid-widget-container">
6177
6177
  ${this._getTemplateToRender()}
6178
6178
  </div>
6179
6179
  `;
@@ -2088,7 +2088,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
2088
2088
  margin-left: 3px;
2089
2089
  }
2090
2090
  </style>
2091
- <div class="shipaid-container">
2091
+ <div class="shipaid-widget-container">
2092
2092
  ${this._getTemplateToRender()}
2093
2093
  </div>
2094
2094
  `}};Ke.styles=$A;let he=Ke;We([o({type:String,attribute:!0})],he.prototype,"env"),We([o({type:Boolean,attribute:!0})],he.prototype,"useCustomStoreFront"),We([o({type:String,attribute:!0})],he.prototype,"storeDomain"),We([o({type:String,attribute:!0})],he.prototype,"storeAccessToken"),We([o({type:String,attribute:!0})],he.prototype,"cartId"),We([o({type:Boolean,attribute:!0})],he.prototype,"disablePolling"),We([o({type:Boolean,attribute:!0})],he.prototype,"disableActions"),We([o({type:Number,attribute:!0})],he.prototype,"pollingInterval"),We([o({type:Boolean,attribute:!0})],he.prototype,"disableRefresh"),We([o({type:Boolean,attribute:!0})],he.prototype,"refreshCart"),We([o({type:Boolean,attribute:!0})],he.prototype,"persistPopup"),We([o({type:Boolean,attribute:!0})],he.prototype,"defaultToggleButton"),We([o({type:String,attribute:!0})],he.prototype,"lang"),We([o({type:String,attribute:!0})],he.prototype,"currency"),We([o({type:String,attribute:!0})],he.prototype,"customerId"),We([o({type:Boolean,attribute:!0})],he.prototype,"supportSubscriptions"),We([o({type:String,attribute:"data-selector"})],he.prototype,"dataSelector"),We([o({type:String,attribute:"button-id"})],he.prototype,"buttonId"),We([o({type:String,attribute:"button-title"})],he.prototype,"buttonTitle"),We([o({type:String,attribute:"widget-title"})],he.prototype,"widgetTitle"),We([o({type:String,attribute:"button-classes"})],he.prototype,"buttonClasses"),We([o({type:String,attribute:"shadow-root-selector"})],he.prototype,"shadowRootSelector"),We([o({type:Boolean,attribute:"use-shipaid-checkout"})],he.prototype,"useShipAidCheckout"),We([o({type:Boolean,attribute:"preview-green-shipaid"})],he.prototype,"previewGreenShipAid"),We([g()],he.prototype,"_storeDomain"),We([g()],he.prototype,"_store"),We([g()],he.prototype,"_cart"),We([g()],he.prototype,"_protectionProduct"),We([g()],he.prototype,"_cartLastUpdated"),We([g()],he.prototype,"_hasFinishedSetup"),We([g()],he.prototype,"_shouldShowWidget"),We([g()],he.prototype,"_hasProtectionInCart"),We([g()],he.prototype,"_protectionCartItem"),We([g()],he.prototype,"_protectionVariant"),We([g()],he.prototype,"_isBenefitsOpen"),We([g()],he.prototype,"hasLoadedStrings"),We([g()],he.prototype,"fetchInterceptorCleanup"),We([g()],he.prototype,"intervalId"),We([g()],he.prototype,"_sellingPlanId"),We([g()],he.prototype,"_state"),We([g()],he.prototype,"_popup");var Ye=Object.defineProperty,Fe=(A,e,t,d)=>{for(var n,r=void 0,a=A.length-1;a>=0;a--)(n=A[a])&&(r=n(e,t,r)||r);return r&&Ye(e,t,r),r};class _e extends iA{constructor(){super(...arguments),this.env="prod",this.lang="en",this.currency=void 0,this.dataSelector="",this.isClone=!1,this._hasFinishedSetup=!1,this._hasProtectionInCart=!1,this._originalCheckoutButton=null,this._toggleLoading=!1,this._desiredProtection=!1,this.isDetailsOpen=!1,this._uiMode="legacy",this._hasCheckoutButtons=!0,this._toggleId=`shipaid-cp-toggle-${Math.random().toString(36).slice(2,8)}`,this._hasRenderedLegacyOnce=!1,this._observer=null,this._remountTimer=null,this._aboutToUnload=!1,this._isReplacingCartSections=!1,this.itemsSelector="",this._itemsObserver=null,this._itemsTargetEl=null,this._itemsDebounceTimer=null,this._cartFetchPromise=null,this._cartFetchLastAt=0,this._cartCache=null,this._updateCartInFlight=null,this._lastCartEventAt=0,this._lastEnsureVariantAt=0,this._onShipAidCartEvent=A=>{var e,t;if("shipaid-widget"===(null==(t=null==(e=null==A?void 0:A.detail)?void 0:e.data)?void 0:t.source))return;const d=Date.now();if(!(d-this._lastCartEventAt<500)){this._lastCartEventAt=d;try{this.updateCart().catch(()=>{})}catch{}}},this._onShipAidInternalCartUpdated=A=>{var e,t,d,n;if("shipaid-widget"===((null==(t=null==(e=null==A?void 0:A.detail)?void 0:e.data)?void 0:t.source)||(null==(d=null==A?void 0:A.detail)?void 0:d.source)))return;const r=null==(n=null==A?void 0:A.detail)?void 0:n.cart;try{r?this.updateCart(r,{forceFetch:!1}).catch(()=>{}):this.updateCart().catch(()=>{})}catch{}},this._apiEndpoint="/apps/shipaid",this._fetch={get:A=>ze(A),post:(A,e)=>ze(A,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},this.proceedToCheckout=()=>{try{window.location.assign("/checkout")}catch{}},this.toggleDetails=()=>{this.isDetailsOpen=!this.isDetailsOpen},this.handleLegacySecondaryClick=()=>{if(!this._toggleLoading){this._toggleLoading=!0;try{this.proceedToCheckout()}finally{this._toggleLoading=!1}}},this.handleLegacyPrimaryClick=async()=>{if(!this._toggleLoading){this._toggleLoading=!0;try{try{this._hasProtectionInCart||(await this.addProtection(),this._enterToggleMode("checked"))}catch{}this.proceedToCheckout()}finally{this._toggleLoading=!1}}}}async _refreshShopifyCartUI(){try{this._isReplacingCartSections=!0,await(async()=>{try{const A=`/?sections=${encodeURIComponent(["cart-drawer","cart-icon-bubble","main-cart-items"].join(","))}`,e=await fetch(A,{credentials:"same-origin"});if(!e.ok)return;const t=await e.json().catch(()=>null);if(!t||"object"!=typeof t)return;for(const d of Object.keys(t)){const A=t[d];if("string"!=typeof A)continue;const e=document.createElement("div");if(e.innerHTML=A,"cart-drawer"===d){try{const A=e.querySelector("cart-drawer"),t=document.querySelector("cart-drawer");A&&t&&(A.classList.contains("is-empty")?t.classList.add("is-empty"):t.classList.remove("is-empty"))}catch{}try{const A=e.querySelector("cart-drawer-items"),t=document.querySelector("cart-drawer cart-drawer-items, .cart-drawer cart-drawer-items");A&&t&&(t.outerHTML=A.outerHTML)}catch{}const A=e.querySelector("#CartDrawer-CartItems"),t=document.getElementById("CartDrawer-CartItems");A&&t&&(t.outerHTML=A.outerHTML);const d=e.querySelector(".cart-drawer__footer"),n=document.querySelector(".cart-drawer .cart-drawer__footer");d&&n&&(n.outerHTML=d.outerHTML);const r=e.querySelector(".cart__ctas"),a=document.querySelector(".cart-drawer .cart__ctas");r&&a&&(a.outerHTML=r.outerHTML);continue}if("main-cart-items"===d){const t=e.querySelector("#main-cart-items"),d=document.getElementById("main-cart-items");if(t&&d)d.outerHTML=t.outerHTML;else{const e=document.getElementById("shopify-section-main-cart-items");e&&(e.outerHTML=A)}continue}if("cart-icon-bubble"===d){const A=e.querySelector("#cart-icon-bubble, [data-cart-count-bubble]"),t=document.querySelector("#cart-icon-bubble, [data-cart-count-bubble]");A&&t&&t.replaceWith(A);continue}}}catch{}})()}catch{}finally{this._isReplacingCartSections=!1}}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this._removeLegacyV1();try{window.addEventListener("beforeunload",()=>{this._aboutToUnload=!0})}catch{}try{const[A,e,t]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=A,this._cart=e,this._protectionProduct=t,await this.updateProtection(),this._desiredProtection=this._hasProtectionInCart,this._hasFinishedSetup=!0,this._shouldShowWidget()&&this._ensureLearnMoreCarousel();const d={bubbles:!0,composed:!0,detail:this._store};this.dispatchEvent(new CustomEvent(ge.LOADED,d))}catch(A){this._hasFinishedSetup=!0}this._startObserver();try{"/cart"===window.location.pathname.replace(/\/$/,"")&&this._observeCartItems()}catch{}try{await this.ensureProtectionVariantForCheckout()}catch{}try{document.addEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ge.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}_ensureLearnMoreCarousel(){Ve(this._store)}_shouldShowWidget(){var A;return!!this._store&&(!0!==this._store.planActive?(console.warn("[ShipAid] Plan is not active, skipping widget mount"),!1):!0===(null==(A=this._store.checkoutPlus)?void 0:A.enabled))}updated(A){if(A.has("dataSelector")||A.has("_hasFinishedSetup")){if(!this._shouldShowWidget())return;this._mountNearCheckoutButton()}A.has("itemsSelector")&&this._observeCartItems(!0)}_removeLegacyV1(){try{document.querySelectorAll("shipaid-widget").forEach(A=>{var e;try{null==(e=A.parentNode)||e.removeChild(A)}catch{}})}catch{}}_getConfiguredShadowRoots(){var A,e;const t=[];try{const d=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.shadowRootSelector,n=Array.isArray(d)?d.filter(Boolean):"string"==typeof d&&d.trim()?[d.trim()]:[];for(const A of n){const e=document.querySelector(A);(null==e?void 0:e.shadowRoot)&&t.push(e.shadowRoot)}}catch{}return t}_prepareParentContainer(A){if(A)try{const e=A.parentElement;if(!e)return;const t=window.getComputedStyle(e),d=(t.display||"").toLowerCase(),n="grid"===d||"inline-grid"===d;(("flex"===d||"inline-flex"===d)&&"column"!==t.flexDirection||n)&&e.setAttribute("shipaid-parent-container","")}catch{}}_applyButtonStylesFrom(A,e={}){if(A)try{const t=window.getComputedStyle(A),d=t.color,n=t.backgroundColor,r=t.borderTopStyle,a=t.borderTopColor,o=t.borderTopWidth;this.style.setProperty("--cp-primary-color",d||""),this.style.setProperty("--cp-primary-bg",n||""),this.style.setProperty("--cp-primary-border-style",r||""),this.style.setProperty("--cp-primary-border-color",a||""),this.style.setProperty("--cp-primary-border-width",o||""),Object.entries(e).forEach(([A,e])=>{this.style.setProperty(A,e)})}catch{}}_enterToggleMode(A){const e="toggle"!==this._uiMode;this._uiMode="toggle",A&&(this._persistTogglePreference(A),this._desiredProtection="checked"===A),e&&this.requestUpdate()}_maybeRevertToLegacy(){"toggle"===this._uiMode&&(this._hasProtectionInCart||this._readTogglePreference()||(this._uiMode="legacy",this._desiredProtection=!1,this._hasRenderedLegacyOnce=!1,this.isDetailsOpen=!1,this.requestUpdate()))}_persistTogglePreference(A){try{sessionStorage.setItem(le,A)}catch{}}_removeTogglePreference(){try{sessionStorage.removeItem(le)}catch{}}_readTogglePreference(){try{const A=sessionStorage.getItem(le);return"checked"===A||"unchecked"===A?A:null}catch{return null}}_normalizeVariantId(A){if(!A)return null;if("number"==typeof A)return String(Math.trunc(A));if("string"==typeof A){const e=A.trim();if(!e)return null;if(/^\d+$/.test(e))return e;const t=e.match(/\d+/g);if(null==t?void 0:t.length)return t[t.length-1]}if("object"==typeof A){if("id"in A)return this._normalizeVariantId(A.id);if("variant_id"in A)return this._normalizeVariantId(A.variant_id)}return null}_applyCachedUiPreference(){if(!this._cart||!Array.isArray(this._cart.items)||0===this._cart.items.length)return this._removeTogglePreference(),this._uiMode="legacy",this._desiredProtection=!1,void(this._hasRenderedLegacyOnce=!1);const A=this._readTogglePreference();A?(this._uiMode="toggle",this._desiredProtection="checked"===A):this._hasProtectionInCart||(this._uiMode="legacy",this._desiredProtection=!1,this._hasRenderedLegacyOnce=!1)}_mountNearCheckoutButton(){var A,e,t,d,n,r;if(this.isConnected&&this._shouldShowWidget()){this._removeLegacyV1();try{const a=(null==(t=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.selectors)?void 0:t.join(","))||"",o=(null==(n=null==(d=this._store)?void 0:d.checkoutPlus)?void 0:n.styles)||{},g=(a||this.dataSelector||"").trim(),v=g?g.split(",").map(A=>A.trim()).filter(Boolean):Te,u=this.getRootNode()||document,f=new Set([document]);u&&f.add(u);for(const A of this._getConfiguredShadowRoots())f.add(A);for(const A of Array.from(f))if(A.host)try{const e="shipaid-styles";if(!(null==(r=A.querySelector)?void 0:r.call(A,`#${e}`))){const t=document.createElement("style");t.id=e,t.textContent="\n [shipaid-hidden] { display: none !important; }\n [shipaid-parent-container] { flex-wrap: wrap !important; }\n [shipaid-parent-container] > shipaid-widget-v2,\n [shipaid-parent-container] > shipaid-checkout-plus { flex: 1 0 100% !important; max-width: 100% !important; grid-column: 1 / -1 !important; }\n ",A.appendChild(t)}}catch{}const D=[];for(const A of Array.from(f))try{const e=Array.from(A.querySelectorAll(v.join(", ")));D.push(...e)}catch{}if(!D.length)return void(this._hasCheckoutButtons=!1);if(this._hasCheckoutButtons=!0,this.isClone){const A=D[0];return this._originalCheckoutButton=A,this._applyButtonStylesFrom(A,o||{}),A.setAttribute("data-shipaid-replaced","true"),A.hasAttribute("shipaid-hidden")||A.setAttribute("shipaid-hidden",""),this._prepareParentContainer(A),void(this.previousElementSibling!==A&&this.nextElementSibling!==A&&A.insertAdjacentElement("beforebegin",this))}const[B,...p]=D;B&&(this._originalCheckoutButton=B,this._applyButtonStylesFrom(B,o||{}),B.setAttribute("data-shipaid-replaced","true"),B.hasAttribute("shipaid-hidden")||B.setAttribute("shipaid-hidden",""),this._prepareParentContainer(B),this.previousElementSibling!==B&&this.nextElementSibling!==B&&B.insertAdjacentElement("beforebegin",this));for(const A of p){if("true"===A.getAttribute("data-shipaid-replaced"))continue;const e=`shipaid-anchor-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;A.setAttribute("data-shipaid-anchor",e),A.setAttribute("data-shipaid-replaced","true"),A.hasAttribute("shipaid-hidden")||A.setAttribute("shipaid-hidden","");const t=document.createElement("shipaid-widget-v2");t.setAttribute("data-clone","true"),t.setAttribute("data-selector",`[data-shipaid-anchor='${e}']`);try{t.setAttribute("env",this.env)}catch{}try{t.setAttribute("lang",this.lang)}catch{}this._prepareParentContainer(A),A.insertAdjacentElement("beforebegin",t)}}catch{}}}_startObserver(){var A;try{null==(A=this._observer)||A.disconnect()}catch{}try{if(!this._shouldShowWidget())return;const A=()=>{if(this._remountTimer)try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=window.setTimeout(()=>{var A,e,t,d,n;const r=!(!this._originalCheckoutButton||!document.contains(this._originalCheckoutButton)),a=(null==(t=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.selectors)?void 0:t.join(","))||"",o=(null==(n=null==(d=this._store)?void 0:d.checkoutPlus)?void 0:n.styles)||{},g=(a||this.dataSelector||"").trim(),v=g?g.split(",").map(A=>A.trim()).filter(Boolean):Te,u=document.querySelectorAll(v.join(", "));let f=null;u.forEach((A,e)=>{const t=A;0===e&&(f=t),t.setAttribute("data-shipaid-replaced","true"),t.setAttribute("shipaid-hidden","")}),!this._originalCheckoutButton&&f&&this._applyButtonStylesFrom(f,o||{}),f&&this._prepareParentContainer(f);const D=u.length>0;r&&!D||this._mountNearCheckoutButton(),this._itemsTargetEl&&!document.contains(this._itemsTargetEl)&&this._observeCartItems(!0)},150)};this._observer=new MutationObserver(A),this._observer.observe(document.body,{childList:!0,subtree:!0});try{const A=[];for(const e of this._getConfiguredShadowRoots()){const t=new MutationObserver(()=>{if(this._remountTimer)try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=window.setTimeout(()=>{this._mountNearCheckoutButton()},150)});t.observe(e,{childList:!0,subtree:!0}),A.push(t)}this._shadowObservers=A}catch{}}catch{}}disconnectedCallback(){var A,e,t;super.disconnectedCallback();try{null==(A=this._originalCheckoutButton)||A.removeAttribute("shipaid-hidden")}catch{}try{null==(e=this._observer)||e.disconnect()}catch{}try{const A=this._shadowObservers;Array.isArray(A)&&A.forEach(A=>{try{A.disconnect()}catch{}}),this._shadowObservers=[]}catch{}if(this._remountTimer){try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=null}try{null==(t=this._itemsObserver)||t.disconnect()}catch{}if(this._itemsObserver=null,this._itemsDebounceTimer){try{clearTimeout(this._itemsDebounceTimer)}catch{}this._itemsDebounceTimer=null}if(!this._aboutToUnload)try{document.contains(this)||(document.body.appendChild(this),setTimeout(()=>this._mountNearCheckoutButton(),0))}catch{}try{document.removeEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ge.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}_observeCartItems(A=!1){var e;try{A&&(null==(e=this._itemsObserver)||e.disconnect())}catch{}if(A&&(this._itemsTargetEl=null),!this._hasFinishedSetup)return;const t=(()=>{const A=(this.itemsSelector||"").trim();if(A)return document.querySelector(A);const e=['form[action*="/cart"] .cart__items',"#CartItems",".cart__items",".cart-items","[data-cart-items]"];for(const t of e){const A=document.querySelector(t);if(A)return A}return null})();if(t){this._itemsTargetEl=t;try{this._itemsObserver=new MutationObserver(()=>{if(!this._isReplacingCartSections){if(this._itemsDebounceTimer)try{clearTimeout(this._itemsDebounceTimer)}catch{}this._itemsDebounceTimer=window.setTimeout(()=>{this._updateCartInFlight||this.updateCart().catch(()=>{})},500)}}),this._itemsObserver.observe(t,{childList:!0,subtree:!0})}catch{}}}async _fetchShipAidData(){var A,e,t,d,n;const r=(null==(A=window.Shopify)?void 0:A.shop)??(null==(t=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:t.apiHost);if(!r)throw new Error("No shop found in Shopify object.");const a=new URL(window.location.href);a.pathname=this._apiEndpoint;const o={query:Me,variables:{store:r}},g=await this._fetch.post(a.toString(),o);if(null==(d=null==g?void 0:g.errors)?void 0:d.length)throw new Error(g.errors[0].message);const v=null==(n=null==g?void 0:g.data)?void 0:n.store;if(!v)throw new Error("Missing store from store query response.");return v}async _fetchCart(){return await this._fetch.get("/cart.js")}async _fetchProduct(){return(await this._fetch.get(`/products/${Ce}.json`)).product}hasProtection(){return!!this._hasProtectionInCart}async updateCart(A,e){if(this._updateCartInFlight&&!A&&!(null==e?void 0:e.forceFetch))return this._updateCartInFlight;return this._updateCartInFlight=(async()=>{var t,d;A||(A=await this._fetchCartThrottled((null==e?void 0:e.forceFetch)?0:1e3)),this._cart=A,await this.updateProtection();const n=Date.now();if(n-this._lastEnsureVariantAt>2e3&&(await this.ensureProtectionVariantForCheckout(),this._lastEnsureVariantAt=n),null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled)try{await this._fetch.post("/cart/update.js",{attributes:{_inspired_external_action_triggered:!!this._hasProtectionInCart||""}})}catch(r){}document.dispatchEvent(new CustomEvent(ve.CART_UPDATE,{detail:{data:{source:"shipaid-widget"},cart:A}}));try{await this._refreshShopifyCartUI()}catch{}try{setTimeout(()=>this._mountNearCheckoutButton(),0)}catch{}})().finally(()=>{this._updateCartInFlight=null}),this._updateCartInFlight}async _fetchCartThrottled(A=1e3){const e=Date.now();return A>0&&this._cartCache&&e-this._cartFetchLastAt<A?this._cartCache:(this._cartFetchPromise||(this._cartFetchPromise=this._fetchCart().then(A=>(this._cartCache=A,this._cartFetchLastAt=Date.now(),A)).finally(()=>{this._cartFetchPromise=null})),this._cartFetchPromise)}async calculateProtectionTotal(A){if(A||(A=await this._fetchCartThrottled(1e3)),!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return r.calculateProtectionTotal(this._store,this._protectionProduct,A)}getProtectionVariantForFee(A){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return r.findProtectionVariant(this._store,this._protectionProduct,A)}async calculateProtectionFeeForCartPlusAmountCents(A){if(!Number.isFinite(A)||A<=0)return{fee:0,variant:void 0};const e={total_price:Number(A),item_count:1,items:[{variant_id:0,sku:"",tags:[],final_line_price:Number(A),quantity:1,isVirtualProduct:!1}]},t=await this.calculateProtectionTotal(e);return{fee:t,variant:this._store&&this._protectionProduct?r.findProtectionVariant(this._store,this._protectionProduct,t):void 0}}async addProtection(){var A;if(!(null==(A=this._protectionVariant)?void 0:A.id))throw new Error("No protection variant found.");const e={quantity:1,id:String(this._protectionVariant.id)};await this._fetch.post("/cart/add.js",e),await this.updateCart(void 0,{forceFetch:!0})}async removeProtection(){var A;if(!(null==(A=this._cart)?void 0:A.items))return;const e=this._cart.items.find(A=>(null==A?void 0:A.handle)===Ce);if(!e)return;const t={updates:{[String(e.id)]:0}},d=await this._fetch.post("/cart/update.js",t);await this.updateCart(d,{forceFetch:!1})}_currencyFormat(A){var e,t,d;const n=this.currency||(null==(e=this._store)?void 0:e.currency)||(null==(d=null==(t=window.Shopify)?void 0:t.currency)?void 0:d.active)||"USD";return new Intl.NumberFormat(void 0,{currency:n,style:"currency"}).format(Number(A))}async updateProtection(){var A;if(!(null==(A=this._cart)?void 0:A.items))return;const e=this._cart.items.find(A=>(null==A?void 0:A.handle)===Ce);if(1===this._cart.items.length&&e)return await this.removeProtection(),this._removeTogglePreference(),this._uiMode="legacy",this._desiredProtection=!1,void(this._hasRenderedLegacyOnce=!1);if(this._hasProtectionInCart=Boolean(e),this._desiredProtection=this._hasProtectionInCart,this._hasProtectionInCart){this._uiMode="toggle";this._readTogglePreference()||this._persistTogglePreference("checked")}else this._maybeRevertToLegacy();const t=await this.calculateProtectionTotal(this._cart),d=this._store&&this._protectionProduct?r.findProtectionVariant(this._store,this._protectionProduct,t):void 0;this._protectionVariant=d,this._applyCachedUiPreference();const n={bubbles:!0,composed:!0,detail:{protection:this._hasProtectionInCart,cart:this._cart,lineItem:e??null,data:{source:"shipaid-widget"}}};this.dispatchEvent(new CustomEvent(ge.CART_UPDATED,n))}render(){var A,e,t,d,n;if(!this._hasFinishedSetup||!this._shouldShowWidget()||!this._hasCheckoutButtons)return M;const r=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),a=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled),o=r||a?ae:oe,g=(null==(n=this._protectionVariant)?void 0:n.price)?this._currencyFormat(this._protectionVariant.price):null,v=H`<style>
@@ -2088,7 +2088,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
2088
2088
  margin-left: 3px;
2089
2089
  }
2090
2090
  </style>
2091
- <div class="shipaid-container">
2091
+ <div class="shipaid-widget-container">
2092
2092
  ${this._getTemplateToRender()}
2093
2093
  </div>
2094
2094
  `}};Ke.styles=$A;let he=Ke;We([o({type:String,attribute:!0})],he.prototype,"env"),We([o({type:Boolean,attribute:!0})],he.prototype,"useCustomStoreFront"),We([o({type:String,attribute:!0})],he.prototype,"storeDomain"),We([o({type:String,attribute:!0})],he.prototype,"storeAccessToken"),We([o({type:String,attribute:!0})],he.prototype,"cartId"),We([o({type:Boolean,attribute:!0})],he.prototype,"disablePolling"),We([o({type:Boolean,attribute:!0})],he.prototype,"disableActions"),We([o({type:Number,attribute:!0})],he.prototype,"pollingInterval"),We([o({type:Boolean,attribute:!0})],he.prototype,"disableRefresh"),We([o({type:Boolean,attribute:!0})],he.prototype,"refreshCart"),We([o({type:Boolean,attribute:!0})],he.prototype,"persistPopup"),We([o({type:Boolean,attribute:!0})],he.prototype,"defaultToggleButton"),We([o({type:String,attribute:!0})],he.prototype,"lang"),We([o({type:String,attribute:!0})],he.prototype,"currency"),We([o({type:String,attribute:!0})],he.prototype,"customerId"),We([o({type:Boolean,attribute:!0})],he.prototype,"supportSubscriptions"),We([o({type:String,attribute:"data-selector"})],he.prototype,"dataSelector"),We([o({type:String,attribute:"button-id"})],he.prototype,"buttonId"),We([o({type:String,attribute:"button-title"})],he.prototype,"buttonTitle"),We([o({type:String,attribute:"widget-title"})],he.prototype,"widgetTitle"),We([o({type:String,attribute:"button-classes"})],he.prototype,"buttonClasses"),We([o({type:String,attribute:"shadow-root-selector"})],he.prototype,"shadowRootSelector"),We([o({type:Boolean,attribute:"use-shipaid-checkout"})],he.prototype,"useShipAidCheckout"),We([o({type:Boolean,attribute:"preview-green-shipaid"})],he.prototype,"previewGreenShipAid"),We([g()],he.prototype,"_storeDomain"),We([g()],he.prototype,"_store"),We([g()],he.prototype,"_cart"),We([g()],he.prototype,"_protectionProduct"),We([g()],he.prototype,"_cartLastUpdated"),We([g()],he.prototype,"_hasFinishedSetup"),We([g()],he.prototype,"_shouldShowWidget"),We([g()],he.prototype,"_hasProtectionInCart"),We([g()],he.prototype,"_protectionCartItem"),We([g()],he.prototype,"_protectionVariant"),We([g()],he.prototype,"_isBenefitsOpen"),We([g()],he.prototype,"hasLoadedStrings"),We([g()],he.prototype,"fetchInterceptorCleanup"),We([g()],he.prototype,"intervalId"),We([g()],he.prototype,"_sellingPlanId"),We([g()],he.prototype,"_state"),We([g()],he.prototype,"_popup");var Ye=Object.defineProperty,Fe=(A,e,t,d)=>{for(var n,r=void 0,a=A.length-1;a>=0;a--)(n=A[a])&&(r=n(e,t,r)||r);return r&&Ye(e,t,r),r};class _e extends iA{constructor(){super(...arguments),this.env="prod",this.lang="en",this.currency=void 0,this.dataSelector="",this.isClone=!1,this._hasFinishedSetup=!1,this._hasProtectionInCart=!1,this._originalCheckoutButton=null,this._toggleLoading=!1,this._desiredProtection=!1,this.isDetailsOpen=!1,this._uiMode="legacy",this._hasCheckoutButtons=!0,this._toggleId=`shipaid-cp-toggle-${Math.random().toString(36).slice(2,8)}`,this._hasRenderedLegacyOnce=!1,this._observer=null,this._remountTimer=null,this._aboutToUnload=!1,this._isReplacingCartSections=!1,this.itemsSelector="",this._itemsObserver=null,this._itemsTargetEl=null,this._itemsDebounceTimer=null,this._cartFetchPromise=null,this._cartFetchLastAt=0,this._cartCache=null,this._updateCartInFlight=null,this._lastCartEventAt=0,this._lastEnsureVariantAt=0,this._onShipAidCartEvent=A=>{var e,t;if("shipaid-widget"===(null==(t=null==(e=null==A?void 0:A.detail)?void 0:e.data)?void 0:t.source))return;const d=Date.now();if(!(d-this._lastCartEventAt<500)){this._lastCartEventAt=d;try{this.updateCart().catch(()=>{})}catch{}}},this._onShipAidInternalCartUpdated=A=>{var e,t,d,n;if("shipaid-widget"===((null==(t=null==(e=null==A?void 0:A.detail)?void 0:e.data)?void 0:t.source)||(null==(d=null==A?void 0:A.detail)?void 0:d.source)))return;const r=null==(n=null==A?void 0:A.detail)?void 0:n.cart;try{r?this.updateCart(r,{forceFetch:!1}).catch(()=>{}):this.updateCart().catch(()=>{})}catch{}},this._apiEndpoint="/apps/shipaid",this._fetch={get:A=>ze(A),post:(A,e)=>ze(A,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},this.proceedToCheckout=()=>{try{window.location.assign("/checkout")}catch{}},this.toggleDetails=()=>{this.isDetailsOpen=!this.isDetailsOpen},this.handleLegacySecondaryClick=()=>{if(!this._toggleLoading){this._toggleLoading=!0;try{this.proceedToCheckout()}finally{this._toggleLoading=!1}}},this.handleLegacyPrimaryClick=async()=>{if(!this._toggleLoading){this._toggleLoading=!0;try{try{this._hasProtectionInCart||(await this.addProtection(),this._enterToggleMode("checked"))}catch{}this.proceedToCheckout()}finally{this._toggleLoading=!1}}}}async _refreshShopifyCartUI(){try{this._isReplacingCartSections=!0,await(async()=>{try{const A=`/?sections=${encodeURIComponent(["cart-drawer","cart-icon-bubble","main-cart-items"].join(","))}`,e=await fetch(A,{credentials:"same-origin"});if(!e.ok)return;const t=await e.json().catch(()=>null);if(!t||"object"!=typeof t)return;for(const d of Object.keys(t)){const A=t[d];if("string"!=typeof A)continue;const e=document.createElement("div");if(e.innerHTML=A,"cart-drawer"===d){try{const A=e.querySelector("cart-drawer"),t=document.querySelector("cart-drawer");A&&t&&(A.classList.contains("is-empty")?t.classList.add("is-empty"):t.classList.remove("is-empty"))}catch{}try{const A=e.querySelector("cart-drawer-items"),t=document.querySelector("cart-drawer cart-drawer-items, .cart-drawer cart-drawer-items");A&&t&&(t.outerHTML=A.outerHTML)}catch{}const A=e.querySelector("#CartDrawer-CartItems"),t=document.getElementById("CartDrawer-CartItems");A&&t&&(t.outerHTML=A.outerHTML);const d=e.querySelector(".cart-drawer__footer"),n=document.querySelector(".cart-drawer .cart-drawer__footer");d&&n&&(n.outerHTML=d.outerHTML);const r=e.querySelector(".cart__ctas"),a=document.querySelector(".cart-drawer .cart__ctas");r&&a&&(a.outerHTML=r.outerHTML);continue}if("main-cart-items"===d){const t=e.querySelector("#main-cart-items"),d=document.getElementById("main-cart-items");if(t&&d)d.outerHTML=t.outerHTML;else{const e=document.getElementById("shopify-section-main-cart-items");e&&(e.outerHTML=A)}continue}if("cart-icon-bubble"===d){const A=e.querySelector("#cart-icon-bubble, [data-cart-count-bubble]"),t=document.querySelector("#cart-icon-bubble, [data-cart-count-bubble]");A&&t&&t.replaceWith(A);continue}}}catch{}})()}catch{}finally{this._isReplacingCartSections=!1}}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this._removeLegacyV1();try{window.addEventListener("beforeunload",()=>{this._aboutToUnload=!0})}catch{}try{const[A,e,t]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=A,this._cart=e,this._protectionProduct=t,await this.updateProtection(),this._desiredProtection=this._hasProtectionInCart,this._hasFinishedSetup=!0,this._shouldShowWidget()&&this._ensureLearnMoreCarousel();const d={bubbles:!0,composed:!0,detail:this._store};this.dispatchEvent(new CustomEvent(ge.LOADED,d))}catch(A){this._hasFinishedSetup=!0}this._startObserver();try{"/cart"===window.location.pathname.replace(/\/$/,"")&&this._observeCartItems()}catch{}try{await this.ensureProtectionVariantForCheckout()}catch{}try{document.addEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ge.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}_ensureLearnMoreCarousel(){Ve(this._store)}_shouldShowWidget(){var A;return!!this._store&&(!0!==this._store.planActive?(console.warn("[ShipAid] Plan is not active, skipping widget mount"),!1):!0===(null==(A=this._store.checkoutPlus)?void 0:A.enabled))}updated(A){if(A.has("dataSelector")||A.has("_hasFinishedSetup")){if(!this._shouldShowWidget())return;this._mountNearCheckoutButton()}A.has("itemsSelector")&&this._observeCartItems(!0)}_removeLegacyV1(){try{document.querySelectorAll("shipaid-widget").forEach(A=>{var e;try{null==(e=A.parentNode)||e.removeChild(A)}catch{}})}catch{}}_getConfiguredShadowRoots(){var A,e;const t=[];try{const d=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.shadowRootSelector,n=Array.isArray(d)?d.filter(Boolean):"string"==typeof d&&d.trim()?[d.trim()]:[];for(const A of n){const e=document.querySelector(A);(null==e?void 0:e.shadowRoot)&&t.push(e.shadowRoot)}}catch{}return t}_prepareParentContainer(A){if(A)try{const e=A.parentElement;if(!e)return;const t=window.getComputedStyle(e),d=(t.display||"").toLowerCase(),n="grid"===d||"inline-grid"===d;(("flex"===d||"inline-flex"===d)&&"column"!==t.flexDirection||n)&&e.setAttribute("shipaid-parent-container","")}catch{}}_applyButtonStylesFrom(A,e={}){if(A)try{const t=window.getComputedStyle(A),d=t.color,n=t.backgroundColor,r=t.borderTopStyle,a=t.borderTopColor,o=t.borderTopWidth;this.style.setProperty("--cp-primary-color",d||""),this.style.setProperty("--cp-primary-bg",n||""),this.style.setProperty("--cp-primary-border-style",r||""),this.style.setProperty("--cp-primary-border-color",a||""),this.style.setProperty("--cp-primary-border-width",o||""),Object.entries(e).forEach(([A,e])=>{this.style.setProperty(A,e)})}catch{}}_enterToggleMode(A){const e="toggle"!==this._uiMode;this._uiMode="toggle",A&&(this._persistTogglePreference(A),this._desiredProtection="checked"===A),e&&this.requestUpdate()}_maybeRevertToLegacy(){"toggle"===this._uiMode&&(this._hasProtectionInCart||this._readTogglePreference()||(this._uiMode="legacy",this._desiredProtection=!1,this._hasRenderedLegacyOnce=!1,this.isDetailsOpen=!1,this.requestUpdate()))}_persistTogglePreference(A){try{sessionStorage.setItem(le,A)}catch{}}_removeTogglePreference(){try{sessionStorage.removeItem(le)}catch{}}_readTogglePreference(){try{const A=sessionStorage.getItem(le);return"checked"===A||"unchecked"===A?A:null}catch{return null}}_normalizeVariantId(A){if(!A)return null;if("number"==typeof A)return String(Math.trunc(A));if("string"==typeof A){const e=A.trim();if(!e)return null;if(/^\d+$/.test(e))return e;const t=e.match(/\d+/g);if(null==t?void 0:t.length)return t[t.length-1]}if("object"==typeof A){if("id"in A)return this._normalizeVariantId(A.id);if("variant_id"in A)return this._normalizeVariantId(A.variant_id)}return null}_applyCachedUiPreference(){if(!this._cart||!Array.isArray(this._cart.items)||0===this._cart.items.length)return this._removeTogglePreference(),this._uiMode="legacy",this._desiredProtection=!1,void(this._hasRenderedLegacyOnce=!1);const A=this._readTogglePreference();A?(this._uiMode="toggle",this._desiredProtection="checked"===A):this._hasProtectionInCart||(this._uiMode="legacy",this._desiredProtection=!1,this._hasRenderedLegacyOnce=!1)}_mountNearCheckoutButton(){var A,e,t,d,n,r;if(this.isConnected&&this._shouldShowWidget()){this._removeLegacyV1();try{const a=(null==(t=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.selectors)?void 0:t.join(","))||"",o=(null==(n=null==(d=this._store)?void 0:d.checkoutPlus)?void 0:n.styles)||{},g=(a||this.dataSelector||"").trim(),v=g?g.split(",").map(A=>A.trim()).filter(Boolean):Te,u=this.getRootNode()||document,f=new Set([document]);u&&f.add(u);for(const A of this._getConfiguredShadowRoots())f.add(A);for(const A of Array.from(f))if(A.host)try{const e="shipaid-styles";if(!(null==(r=A.querySelector)?void 0:r.call(A,`#${e}`))){const t=document.createElement("style");t.id=e,t.textContent="\n [shipaid-hidden] { display: none !important; }\n [shipaid-parent-container] { flex-wrap: wrap !important; }\n [shipaid-parent-container] > shipaid-widget-v2,\n [shipaid-parent-container] > shipaid-checkout-plus { flex: 1 0 100% !important; max-width: 100% !important; grid-column: 1 / -1 !important; }\n ",A.appendChild(t)}}catch{}const D=[];for(const A of Array.from(f))try{const e=Array.from(A.querySelectorAll(v.join(", ")));D.push(...e)}catch{}if(!D.length)return void(this._hasCheckoutButtons=!1);if(this._hasCheckoutButtons=!0,this.isClone){const A=D[0];return this._originalCheckoutButton=A,this._applyButtonStylesFrom(A,o||{}),A.setAttribute("data-shipaid-replaced","true"),A.hasAttribute("shipaid-hidden")||A.setAttribute("shipaid-hidden",""),this._prepareParentContainer(A),void(this.previousElementSibling!==A&&this.nextElementSibling!==A&&A.insertAdjacentElement("beforebegin",this))}const[B,...p]=D;B&&(this._originalCheckoutButton=B,this._applyButtonStylesFrom(B,o||{}),B.setAttribute("data-shipaid-replaced","true"),B.hasAttribute("shipaid-hidden")||B.setAttribute("shipaid-hidden",""),this._prepareParentContainer(B),this.previousElementSibling!==B&&this.nextElementSibling!==B&&B.insertAdjacentElement("beforebegin",this));for(const A of p){if("true"===A.getAttribute("data-shipaid-replaced"))continue;const e=`shipaid-anchor-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;A.setAttribute("data-shipaid-anchor",e),A.setAttribute("data-shipaid-replaced","true"),A.hasAttribute("shipaid-hidden")||A.setAttribute("shipaid-hidden","");const t=document.createElement("shipaid-widget-v2");t.setAttribute("data-clone","true"),t.setAttribute("data-selector",`[data-shipaid-anchor='${e}']`);try{t.setAttribute("env",this.env)}catch{}try{t.setAttribute("lang",this.lang)}catch{}this._prepareParentContainer(A),A.insertAdjacentElement("beforebegin",t)}}catch{}}}_startObserver(){var A;try{null==(A=this._observer)||A.disconnect()}catch{}try{if(!this._shouldShowWidget())return;const A=()=>{if(this._remountTimer)try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=window.setTimeout(()=>{var A,e,t,d,n;const r=!(!this._originalCheckoutButton||!document.contains(this._originalCheckoutButton)),a=(null==(t=null==(e=null==(A=this._store)?void 0:A.checkoutPlus)?void 0:e.selectors)?void 0:t.join(","))||"",o=(null==(n=null==(d=this._store)?void 0:d.checkoutPlus)?void 0:n.styles)||{},g=(a||this.dataSelector||"").trim(),v=g?g.split(",").map(A=>A.trim()).filter(Boolean):Te,u=document.querySelectorAll(v.join(", "));let f=null;u.forEach((A,e)=>{const t=A;0===e&&(f=t),t.setAttribute("data-shipaid-replaced","true"),t.setAttribute("shipaid-hidden","")}),!this._originalCheckoutButton&&f&&this._applyButtonStylesFrom(f,o||{}),f&&this._prepareParentContainer(f);const D=u.length>0;r&&!D||this._mountNearCheckoutButton(),this._itemsTargetEl&&!document.contains(this._itemsTargetEl)&&this._observeCartItems(!0)},150)};this._observer=new MutationObserver(A),this._observer.observe(document.body,{childList:!0,subtree:!0});try{const A=[];for(const e of this._getConfiguredShadowRoots()){const t=new MutationObserver(()=>{if(this._remountTimer)try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=window.setTimeout(()=>{this._mountNearCheckoutButton()},150)});t.observe(e,{childList:!0,subtree:!0}),A.push(t)}this._shadowObservers=A}catch{}}catch{}}disconnectedCallback(){var A,e,t;super.disconnectedCallback();try{null==(A=this._originalCheckoutButton)||A.removeAttribute("shipaid-hidden")}catch{}try{null==(e=this._observer)||e.disconnect()}catch{}try{const A=this._shadowObservers;Array.isArray(A)&&A.forEach(A=>{try{A.disconnect()}catch{}}),this._shadowObservers=[]}catch{}if(this._remountTimer){try{clearTimeout(this._remountTimer)}catch{}this._remountTimer=null}try{null==(t=this._itemsObserver)||t.disconnect()}catch{}if(this._itemsObserver=null,this._itemsDebounceTimer){try{clearTimeout(this._itemsDebounceTimer)}catch{}this._itemsDebounceTimer=null}if(!this._aboutToUnload)try{document.contains(this)||(document.body.appendChild(this),setTimeout(()=>this._mountNearCheckoutButton(),0))}catch{}try{document.removeEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ve.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ge.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}_observeCartItems(A=!1){var e;try{A&&(null==(e=this._itemsObserver)||e.disconnect())}catch{}if(A&&(this._itemsTargetEl=null),!this._hasFinishedSetup)return;const t=(()=>{const A=(this.itemsSelector||"").trim();if(A)return document.querySelector(A);const e=['form[action*="/cart"] .cart__items',"#CartItems",".cart__items",".cart-items","[data-cart-items]"];for(const t of e){const A=document.querySelector(t);if(A)return A}return null})();if(t){this._itemsTargetEl=t;try{this._itemsObserver=new MutationObserver(()=>{if(!this._isReplacingCartSections){if(this._itemsDebounceTimer)try{clearTimeout(this._itemsDebounceTimer)}catch{}this._itemsDebounceTimer=window.setTimeout(()=>{this._updateCartInFlight||this.updateCart().catch(()=>{})},500)}}),this._itemsObserver.observe(t,{childList:!0,subtree:!0})}catch{}}}async _fetchShipAidData(){var A,e,t,d,n;const r=(null==(A=window.Shopify)?void 0:A.shop)??(null==(t=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:t.apiHost);if(!r)throw new Error("No shop found in Shopify object.");const a=new URL(window.location.href);a.pathname=this._apiEndpoint;const o={query:Me,variables:{store:r}},g=await this._fetch.post(a.toString(),o);if(null==(d=null==g?void 0:g.errors)?void 0:d.length)throw new Error(g.errors[0].message);const v=null==(n=null==g?void 0:g.data)?void 0:n.store;if(!v)throw new Error("Missing store from store query response.");return v}async _fetchCart(){return await this._fetch.get("/cart.js")}async _fetchProduct(){return(await this._fetch.get(`/products/${Ce}.json`)).product}hasProtection(){return!!this._hasProtectionInCart}async updateCart(A,e){if(this._updateCartInFlight&&!A&&!(null==e?void 0:e.forceFetch))return this._updateCartInFlight;return this._updateCartInFlight=(async()=>{var t,d;A||(A=await this._fetchCartThrottled((null==e?void 0:e.forceFetch)?0:1e3)),this._cart=A,await this.updateProtection();const n=Date.now();if(n-this._lastEnsureVariantAt>2e3&&(await this.ensureProtectionVariantForCheckout(),this._lastEnsureVariantAt=n),null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled)try{await this._fetch.post("/cart/update.js",{attributes:{_inspired_external_action_triggered:!!this._hasProtectionInCart||""}})}catch(r){}document.dispatchEvent(new CustomEvent(ve.CART_UPDATE,{detail:{data:{source:"shipaid-widget"},cart:A}}));try{await this._refreshShopifyCartUI()}catch{}try{setTimeout(()=>this._mountNearCheckoutButton(),0)}catch{}})().finally(()=>{this._updateCartInFlight=null}),this._updateCartInFlight}async _fetchCartThrottled(A=1e3){const e=Date.now();return A>0&&this._cartCache&&e-this._cartFetchLastAt<A?this._cartCache:(this._cartFetchPromise||(this._cartFetchPromise=this._fetchCart().then(A=>(this._cartCache=A,this._cartFetchLastAt=Date.now(),A)).finally(()=>{this._cartFetchPromise=null})),this._cartFetchPromise)}async calculateProtectionTotal(A){if(A||(A=await this._fetchCartThrottled(1e3)),!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return r.calculateProtectionTotal(this._store,this._protectionProduct,A)}getProtectionVariantForFee(A){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return r.findProtectionVariant(this._store,this._protectionProduct,A)}async calculateProtectionFeeForCartPlusAmountCents(A){if(!Number.isFinite(A)||A<=0)return{fee:0,variant:void 0};const e={total_price:Number(A),item_count:1,items:[{variant_id:0,sku:"",tags:[],final_line_price:Number(A),quantity:1,isVirtualProduct:!1}]},t=await this.calculateProtectionTotal(e);return{fee:t,variant:this._store&&this._protectionProduct?r.findProtectionVariant(this._store,this._protectionProduct,t):void 0}}async addProtection(){var A;if(!(null==(A=this._protectionVariant)?void 0:A.id))throw new Error("No protection variant found.");const e={quantity:1,id:String(this._protectionVariant.id)};await this._fetch.post("/cart/add.js",e),await this.updateCart(void 0,{forceFetch:!0})}async removeProtection(){var A;if(!(null==(A=this._cart)?void 0:A.items))return;const e=this._cart.items.find(A=>(null==A?void 0:A.handle)===Ce);if(!e)return;const t={updates:{[String(e.id)]:0}},d=await this._fetch.post("/cart/update.js",t);await this.updateCart(d,{forceFetch:!1})}_currencyFormat(A){var e,t,d;const n=this.currency||(null==(e=this._store)?void 0:e.currency)||(null==(d=null==(t=window.Shopify)?void 0:t.currency)?void 0:d.active)||"USD";return new Intl.NumberFormat(void 0,{currency:n,style:"currency"}).format(Number(A))}async updateProtection(){var A;if(!(null==(A=this._cart)?void 0:A.items))return;const e=this._cart.items.find(A=>(null==A?void 0:A.handle)===Ce);if(1===this._cart.items.length&&e)return await this.removeProtection(),this._removeTogglePreference(),this._uiMode="legacy",this._desiredProtection=!1,void(this._hasRenderedLegacyOnce=!1);if(this._hasProtectionInCart=Boolean(e),this._desiredProtection=this._hasProtectionInCart,this._hasProtectionInCart){this._uiMode="toggle";this._readTogglePreference()||this._persistTogglePreference("checked")}else this._maybeRevertToLegacy();const t=await this.calculateProtectionTotal(this._cart),d=this._store&&this._protectionProduct?r.findProtectionVariant(this._store,this._protectionProduct,t):void 0;this._protectionVariant=d,this._applyCachedUiPreference();const n={bubbles:!0,composed:!0,detail:{protection:this._hasProtectionInCart,cart:this._cart,lineItem:e??null,data:{source:"shipaid-widget"}}};this.dispatchEvent(new CustomEvent(ge.CART_UPDATED,n))}render(){var A,e,t,d,n;if(!this._hasFinishedSetup||!this._shouldShowWidget()||!this._hasCheckoutButtons)return M;const r=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),a=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled),o=r||a?ae:oe,g=(null==(n=this._protectionVariant)?void 0:n.price)?this._currencyFormat(this._protectionVariant.price):null,v=H`<style>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ui.shipaid.com",
3
3
  "private": false,
4
- "version": "0.3.154",
4
+ "version": "0.3.155",
5
5
  "type": "module",
6
6
  "main": "dist/widget.umd.js",
7
7
  "unpkg": "dist/widget.iife.js",