ui.shipaid.com 0.3.149 → 0.3.150
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
|
@@ -4775,6 +4775,33 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4775
4775
|
this._cachedCheckoutButtonClasses = button.className;
|
|
4776
4776
|
return button;
|
|
4777
4777
|
}
|
|
4778
|
+
/**
|
|
4779
|
+
* Restore the original checkout button styles/attributes if we modified them
|
|
4780
|
+
* @private
|
|
4781
|
+
*/
|
|
4782
|
+
_restoreCheckoutButtonState() {
|
|
4783
|
+
try {
|
|
4784
|
+
const buttons = [];
|
|
4785
|
+
if (this._cachedCheckoutButton && document.contains(this._cachedCheckoutButton)) {
|
|
4786
|
+
buttons.push(this._cachedCheckoutButton);
|
|
4787
|
+
} else if (this.dataSelector) {
|
|
4788
|
+
this.getElementsBySelector(this.dataSelector).forEach((button) => {
|
|
4789
|
+
buttons.push(button);
|
|
4790
|
+
});
|
|
4791
|
+
}
|
|
4792
|
+
buttons.forEach((button) => {
|
|
4793
|
+
button.removeAttribute("shipaid-hidden");
|
|
4794
|
+
if (button === this._cachedCheckoutButton && this._cachedCheckoutButtonClasses) {
|
|
4795
|
+
button.className = this._cachedCheckoutButtonClasses;
|
|
4796
|
+
}
|
|
4797
|
+
});
|
|
4798
|
+
} catch (error) {
|
|
4799
|
+
console.error("[ShipAid] Error restoring checkout button state:", error);
|
|
4800
|
+
} finally {
|
|
4801
|
+
this._cachedCheckoutButton = null;
|
|
4802
|
+
this._cachedCheckoutButtonClasses = "";
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4778
4805
|
/**
|
|
4779
4806
|
* Calculate cart totals for checkoutButtonTemplate
|
|
4780
4807
|
* @private
|
|
@@ -5505,6 +5532,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5505
5532
|
document.removeEventListener(SHIPAID_EVENTS.CART_UPDATED, this._onShipAidInternalCartUpdated);
|
|
5506
5533
|
} catch {
|
|
5507
5534
|
}
|
|
5535
|
+
this._restoreCheckoutButtonState();
|
|
5508
5536
|
}
|
|
5509
5537
|
updated(changedProperties) {
|
|
5510
5538
|
super.updated(changedProperties);
|
|
@@ -5527,6 +5555,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5527
5555
|
button.removeAttribute("shipaid-hidden");
|
|
5528
5556
|
});
|
|
5529
5557
|
}
|
|
5558
|
+
this._restoreCheckoutButtonState();
|
|
5530
5559
|
}
|
|
5531
5560
|
}
|
|
5532
5561
|
async updateProtection(force = false) {
|
|
@@ -5586,11 +5615,13 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5586
5615
|
}
|
|
5587
5616
|
if (!(protectionVariant == null ? void 0 : protectionVariant.id)) {
|
|
5588
5617
|
this._shouldShowWidget = false;
|
|
5618
|
+
this._restoreCheckoutButtonState();
|
|
5589
5619
|
logger.error("No matching protection variant found.");
|
|
5590
5620
|
return;
|
|
5591
5621
|
}
|
|
5592
5622
|
if (!((_c = this._protectionVariant) == null ? void 0 : _c.id)) {
|
|
5593
5623
|
this._shouldShowWidget = false;
|
|
5624
|
+
this._restoreCheckoutButtonState();
|
|
5594
5625
|
return;
|
|
5595
5626
|
}
|
|
5596
5627
|
if (this.useShipAidCheckout && this.supportSubscriptions) {
|
|
@@ -5701,18 +5732,21 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5701
5732
|
logger.error(error.message);
|
|
5702
5733
|
this._hasFinishedSetup = true;
|
|
5703
5734
|
this._shouldShowWidget = false;
|
|
5735
|
+
this._restoreCheckoutButtonState();
|
|
5704
5736
|
return;
|
|
5705
5737
|
}
|
|
5706
5738
|
if (!this.planActive) {
|
|
5707
5739
|
logger.warn("No plan is active for this store - skipping setup.");
|
|
5708
5740
|
this._hasFinishedSetup = true;
|
|
5709
5741
|
this._shouldShowWidget = false;
|
|
5742
|
+
this._restoreCheckoutButtonState();
|
|
5710
5743
|
return;
|
|
5711
5744
|
}
|
|
5712
5745
|
if (!((_b = (_a = this._store) == null ? void 0 : _a.protectionSettings) == null ? void 0 : _b.protectionType)) {
|
|
5713
5746
|
logger.warn("No protection settings for this store - skipping setup.");
|
|
5714
5747
|
this._hasFinishedSetup = true;
|
|
5715
5748
|
this._shouldShowWidget = false;
|
|
5749
|
+
this._restoreCheckoutButtonState();
|
|
5716
5750
|
return;
|
|
5717
5751
|
}
|
|
5718
5752
|
if (!this._protectionProduct) {
|
|
@@ -5721,6 +5755,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5721
5755
|
);
|
|
5722
5756
|
this._hasFinishedSetup = true;
|
|
5723
5757
|
this._shouldShowWidget = false;
|
|
5758
|
+
this._restoreCheckoutButtonState();
|
|
5724
5759
|
return;
|
|
5725
5760
|
}
|
|
5726
5761
|
this._hasFinishedSetup = true;
|
package/dist/widget.iife.js
CHANGED
|
@@ -1215,7 +1215,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
|
|
|
1215
1215
|
</ul>
|
|
1216
1216
|
</div>
|
|
1217
1217
|
</div>
|
|
1218
|
-
`}_injectCheckoutButtonGlobalStyles(){if(!this._checkoutButtonStylesInjected){if(!document.getElementById("shipaid-styles")){const A=document.createElement("style");A.id="shipaid-styles",A.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(A)}this._checkoutButtonStylesInjected=!0}}_findAndCacheCheckoutButton(){var A;if(this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton))return this._cachedCheckoutButton;if(!this.dataSelector)return we.warn("[shipaid-widget] Missing 'data-selector' attribute for checkout button"),null;let e=null;if(this.shadowRootSelector){const A=document.querySelector(this.shadowRootSelector);if(!(null==A?void 0:A.shadowRoot))return we.warn(`ShadowRoot not found for selector '${this.shadowRootSelector}'`),null;e=A.shadowRoot.querySelector(`${this.dataSelector}:not(#${this.buttonId||"shipaid-checkout-button"})`)}else e=null==(A=this.getElementsBySelector(this.dataSelector))?void 0:A[0];return e?(this._cachedCheckoutButton=e,this._cachedCheckoutButtonClasses=e.className,e):(we.warn(`Checkout button not found with selector '${this.dataSelector}'`),null)}_calculateCheckoutCartTotals(){var A,e;const t=Number(null==(A=this._protectionVariant)?void 0:A.price)||0,d=(Number(null==(e=this._cart)?void 0:e.total_price)||0)/100;return{protectionPrice:t,cartPrice:d,cartTotal:this._hasProtectionInCart?d:t+d}}_getCheckoutImpactFeatures(){var A,e,t,d;const n=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),r=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled);return{isGreenProtectionEnabled:n,isFreeGiftEnabled:r,impactActive:n||r}}_renderGetMechanismCheckoutButton(A,e,t,d,n,r){var a,o,g,v,u,f;return H`
|
|
1218
|
+
`}_injectCheckoutButtonGlobalStyles(){if(!this._checkoutButtonStylesInjected){if(!document.getElementById("shipaid-styles")){const A=document.createElement("style");A.id="shipaid-styles",A.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(A)}this._checkoutButtonStylesInjected=!0}}_findAndCacheCheckoutButton(){var A;if(this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton))return this._cachedCheckoutButton;if(!this.dataSelector)return we.warn("[shipaid-widget] Missing 'data-selector' attribute for checkout button"),null;let e=null;if(this.shadowRootSelector){const A=document.querySelector(this.shadowRootSelector);if(!(null==A?void 0:A.shadowRoot))return we.warn(`ShadowRoot not found for selector '${this.shadowRootSelector}'`),null;e=A.shadowRoot.querySelector(`${this.dataSelector}:not(#${this.buttonId||"shipaid-checkout-button"})`)}else e=null==(A=this.getElementsBySelector(this.dataSelector))?void 0:A[0];return e?(this._cachedCheckoutButton=e,this._cachedCheckoutButtonClasses=e.className,e):(we.warn(`Checkout button not found with selector '${this.dataSelector}'`),null)}_restoreCheckoutButtonState(){try{const A=[];this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton)?A.push(this._cachedCheckoutButton):this.dataSelector&&this.getElementsBySelector(this.dataSelector).forEach(e=>{A.push(e)}),A.forEach(A=>{A.removeAttribute("shipaid-hidden"),A===this._cachedCheckoutButton&&this._cachedCheckoutButtonClasses&&(A.className=this._cachedCheckoutButtonClasses)})}catch(A){console.error("[ShipAid] Error restoring checkout button state:",A)}finally{this._cachedCheckoutButton=null,this._cachedCheckoutButtonClasses=""}}_calculateCheckoutCartTotals(){var A,e;const t=Number(null==(A=this._protectionVariant)?void 0:A.price)||0,d=(Number(null==(e=this._cart)?void 0:e.total_price)||0)/100;return{protectionPrice:t,cartPrice:d,cartTotal:this._hasProtectionInCart?d:t+d}}_getCheckoutImpactFeatures(){var A,e,t,d;const n=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),r=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled);return{isGreenProtectionEnabled:n,isFreeGiftEnabled:r,impactActive:n||r}}_renderGetMechanismCheckoutButton(A,e,t,d,n,r){var a,o,g,v,u,f;return H`
|
|
1219
1219
|
<style>
|
|
1220
1220
|
:host {
|
|
1221
1221
|
display: inline-block;
|
|
@@ -1731,7 +1731,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
|
|
|
1731
1731
|
</div>
|
|
1732
1732
|
`)}
|
|
1733
1733
|
</div>
|
|
1734
|
-
`}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(A){const e=window.fetch;let t=!0;const d=async(d,n)=>{const r=e(d,n);if(t)try{await A([d,n],r)}catch(a){console.warn(a)}return await r};return window.fetch=d,()=>{window.fetch===d?window.fetch=e:t=!1}}(async(A,e)=>{var t,d;if(!(null==(d=null==(t=A[1])?void 0:t.headers)?void 0:d["X-ShipAid"])&&(A[0].startsWith("/cart/change")||A[0].startsWith("/cart/update"))&&!this._isUpdatingShipAid)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons(),await e,await this.updateCart(),await this.updateProtection(!0)}catch(n){console.error("[ShipAid] Interceptor error:",n)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}});try{document.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}disconnectedCallback(){var A;super.disconnectedCallback(),null==(A=this.fetchInterceptorCleanup)||A.call(this);try{document.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}updated(A){if(super.updated(A),!this._hasFinishedSetup)return;const e=this._getContactlessCheckoutSelector();if(!sessionStorage.getItem("shipaidWidgetTheme")&&e&&sessionStorage.setItem("shipaidWidgetTheme",e),!this.useShipAidCheckout&&e||sessionStorage.removeItem("shipaidWidgetTheme"),this.useShipAidCheckout||document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach(A=>A.remove()),!this._shouldShowWidgetContent()){const A=sessionStorage.getItem("shipaidWidgetTheme")||this.dataSelector;A&&this.getElementsBySelector(A).forEach(A=>{A.removeAttribute("shipaid-hidden")})}}async updateProtection(A=!1){var e,t,d;if(this._cartLastUpdated=new Date,!(null==(e=this._cart)?void 0:e.items))return;if(this._isUpdatingShipAid&&!A)return;const n=this._cart.items.filter(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)});if(n.length>1)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();for(let A=1;A<n.length;A++)await this.updateCartProtectionVariant(0,n[A]),await new Promise(A=>setTimeout(A,100));this._cart=await this._fetchCart()}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}const r=(null==(t=this._cart.items)?void 0:t.findIndex(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)}))??-1,a=r>=0&&this._cart.items?this._cart.items[r]:void 0;if(this._hasProtectionInCart=!!a,!this._store)return;const o=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&a&&(this._cart.total_price===(null==a?void 0:a.final_line_price)||!o)){const A=await this.updateCartProtectionVariant(0,a);return sessionStorage.removeItem(me),await this._handleRefresh(A)}const g=this._findProtectionVariant(o);if(o?(this._protectionVariant=g,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==g?void 0:g.id))return this._shouldShowWidget=!1,void we.error("No matching protection variant found.");if(null==(d=this._protectionVariant)?void 0:d.id)
|
|
1734
|
+
`}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(A){const e=window.fetch;let t=!0;const d=async(d,n)=>{const r=e(d,n);if(t)try{await A([d,n],r)}catch(a){console.warn(a)}return await r};return window.fetch=d,()=>{window.fetch===d?window.fetch=e:t=!1}}(async(A,e)=>{var t,d;if(!(null==(d=null==(t=A[1])?void 0:t.headers)?void 0:d["X-ShipAid"])&&(A[0].startsWith("/cart/change")||A[0].startsWith("/cart/update"))&&!this._isUpdatingShipAid)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons(),await e,await this.updateCart(),await this.updateProtection(!0)}catch(n){console.error("[ShipAid] Interceptor error:",n)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}});try{document.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}disconnectedCallback(){var A;super.disconnectedCallback(),null==(A=this.fetchInterceptorCleanup)||A.call(this);try{document.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}this._restoreCheckoutButtonState()}updated(A){if(super.updated(A),!this._hasFinishedSetup)return;const e=this._getContactlessCheckoutSelector();if(!sessionStorage.getItem("shipaidWidgetTheme")&&e&&sessionStorage.setItem("shipaidWidgetTheme",e),!this.useShipAidCheckout&&e||sessionStorage.removeItem("shipaidWidgetTheme"),this.useShipAidCheckout||document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach(A=>A.remove()),!this._shouldShowWidgetContent()){const A=sessionStorage.getItem("shipaidWidgetTheme")||this.dataSelector;A&&this.getElementsBySelector(A).forEach(A=>{A.removeAttribute("shipaid-hidden")}),this._restoreCheckoutButtonState()}}async updateProtection(A=!1){var e,t,d;if(this._cartLastUpdated=new Date,!(null==(e=this._cart)?void 0:e.items))return;if(this._isUpdatingShipAid&&!A)return;const n=this._cart.items.filter(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)});if(n.length>1)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();for(let A=1;A<n.length;A++)await this.updateCartProtectionVariant(0,n[A]),await new Promise(A=>setTimeout(A,100));this._cart=await this._fetchCart()}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}const r=(null==(t=this._cart.items)?void 0:t.findIndex(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)}))??-1,a=r>=0&&this._cart.items?this._cart.items[r]:void 0;if(this._hasProtectionInCart=!!a,!this._store)return;const o=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&a&&(this._cart.total_price===(null==a?void 0:a.final_line_price)||!o)){const A=await this.updateCartProtectionVariant(0,a);return sessionStorage.removeItem(me),await this._handleRefresh(A)}const g=this._findProtectionVariant(o);if(o?(this._protectionVariant=g,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==g?void 0:g.id))return this._shouldShowWidget=!1,this._restoreCheckoutButtonState(),void we.error("No matching protection variant found.");if(!(null==(d=this._protectionVariant)?void 0:d.id))return this._shouldShowWidget=!1,void this._restoreCheckoutButtonState();if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),a){if(this.supportSubscriptions&&!this.useShipAidCheckout&&this._cart.items){const A=this._cart.items.find(A=>{var e;return A.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==A?void 0:A.selling_plan_allocation)});let e=!0;if(!A&&(null==a?void 0:a.selling_plan_allocation)?this._sellingPlanId=null:A&&!(null==a?void 0:a.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A=await this.updateCartProtectionVariant(1,a);await this._handleRefresh(A)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}if(a&&g.id===a.variant_id){if(this._protectionCartItem={...a,index:r,position:r+1},1===a.quantity)return;try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A=await this.updateCartProtectionVariant(1,a);this._handleRefreshCart(),await this._handleRefresh(A)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}else try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A={updates:{[a.variant_id]:0,[g.id]:1}},e=await this._fetch.post("/cart/update.js",A);await this.updateCart(e,{dispatchExternalEvents:!0})}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}}render(){return yA(this,async()=>{var A,e,t,d,n,r;document.cookie.split(";").forEach(function(A){const e=A.split("=")[0].trim();e.endsWith("product_tags")&&(document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/",document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;")});const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[A,e,t]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=A,this._cart=e,this._protectionProduct=t}catch(o){return we.error(o.message),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()}return this.planActive?(null==(e=null==(A=this._store)?void 0:A.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,xe(this._store),this._dispatchEvent(ve.LOADED,this._store),setTimeout(async()=>{var A,e,t,d;(null==(A=this._store)?void 0:A.widgetAutoOptIn)&&!this.useShipAidCheckout&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(t=this._store.excludedCustomersIdsAutoOptIn)?void 0:t.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(me)||!this._hasProtectionInCart&&(null==(d=this._cart)?void 0:d.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(me,JSON.stringify({loaded:!0}))))},500),void(this.disablePolling||(setInterval(async()=>{const A=this._cartLastUpdated;A&&(new Date).getTime()-A.getTime()<this.pollingInterval||await this.updateCart()},this.pollingInterval),(null==(t=this._store)?void 0:t.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval(async()=>{await this.attemptAddProtection()},400),localStorage.setItem(`${Oe}_${this.intervalId}`,`${this.intervalId}`)),(null==(r=null==(n=null==(d=this._store)?void 0:d.widgetConfigurations)?void 0:n.widget)?void 0:r.pollVariantsCheck)&&setInterval(async()=>{await this.handleMultipleProtectionVariants()},400)))):(we.warn("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()):(we.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()):(we.warn("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState())},[]),yA(this,async()=>{await this.updateProtection()},[this._store,this._cart]),yA(this,()=>{K(this.renderPopups(),document.body)},[this._popup]),H`
|
|
1735
1735
|
<style>
|
|
1736
1736
|
:host {
|
|
1737
1737
|
--shipaid-primary: #002bd6;
|
package/dist/widget.umd.js
CHANGED
|
@@ -1215,7 +1215,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
|
|
|
1215
1215
|
</ul>
|
|
1216
1216
|
</div>
|
|
1217
1217
|
</div>
|
|
1218
|
-
`}_injectCheckoutButtonGlobalStyles(){if(!this._checkoutButtonStylesInjected){if(!document.getElementById("shipaid-styles")){const A=document.createElement("style");A.id="shipaid-styles",A.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(A)}this._checkoutButtonStylesInjected=!0}}_findAndCacheCheckoutButton(){var A;if(this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton))return this._cachedCheckoutButton;if(!this.dataSelector)return we.warn("[shipaid-widget] Missing 'data-selector' attribute for checkout button"),null;let e=null;if(this.shadowRootSelector){const A=document.querySelector(this.shadowRootSelector);if(!(null==A?void 0:A.shadowRoot))return we.warn(`ShadowRoot not found for selector '${this.shadowRootSelector}'`),null;e=A.shadowRoot.querySelector(`${this.dataSelector}:not(#${this.buttonId||"shipaid-checkout-button"})`)}else e=null==(A=this.getElementsBySelector(this.dataSelector))?void 0:A[0];return e?(this._cachedCheckoutButton=e,this._cachedCheckoutButtonClasses=e.className,e):(we.warn(`Checkout button not found with selector '${this.dataSelector}'`),null)}_calculateCheckoutCartTotals(){var A,e;const t=Number(null==(A=this._protectionVariant)?void 0:A.price)||0,d=(Number(null==(e=this._cart)?void 0:e.total_price)||0)/100;return{protectionPrice:t,cartPrice:d,cartTotal:this._hasProtectionInCart?d:t+d}}_getCheckoutImpactFeatures(){var A,e,t,d;const n=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),r=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled);return{isGreenProtectionEnabled:n,isFreeGiftEnabled:r,impactActive:n||r}}_renderGetMechanismCheckoutButton(A,e,t,d,n,r){var a,o,g,v,u,f;return H`
|
|
1218
|
+
`}_injectCheckoutButtonGlobalStyles(){if(!this._checkoutButtonStylesInjected){if(!document.getElementById("shipaid-styles")){const A=document.createElement("style");A.id="shipaid-styles",A.textContent="\n [shipaid-hidden] {\n display: none !important;\n }\n\n shipaid-widget {\n width: 100%;\n }\n ",document.head.appendChild(A)}this._checkoutButtonStylesInjected=!0}}_findAndCacheCheckoutButton(){var A;if(this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton))return this._cachedCheckoutButton;if(!this.dataSelector)return we.warn("[shipaid-widget] Missing 'data-selector' attribute for checkout button"),null;let e=null;if(this.shadowRootSelector){const A=document.querySelector(this.shadowRootSelector);if(!(null==A?void 0:A.shadowRoot))return we.warn(`ShadowRoot not found for selector '${this.shadowRootSelector}'`),null;e=A.shadowRoot.querySelector(`${this.dataSelector}:not(#${this.buttonId||"shipaid-checkout-button"})`)}else e=null==(A=this.getElementsBySelector(this.dataSelector))?void 0:A[0];return e?(this._cachedCheckoutButton=e,this._cachedCheckoutButtonClasses=e.className,e):(we.warn(`Checkout button not found with selector '${this.dataSelector}'`),null)}_restoreCheckoutButtonState(){try{const A=[];this._cachedCheckoutButton&&document.contains(this._cachedCheckoutButton)?A.push(this._cachedCheckoutButton):this.dataSelector&&this.getElementsBySelector(this.dataSelector).forEach(e=>{A.push(e)}),A.forEach(A=>{A.removeAttribute("shipaid-hidden"),A===this._cachedCheckoutButton&&this._cachedCheckoutButtonClasses&&(A.className=this._cachedCheckoutButtonClasses)})}catch(A){console.error("[ShipAid] Error restoring checkout button state:",A)}finally{this._cachedCheckoutButton=null,this._cachedCheckoutButtonClasses=""}}_calculateCheckoutCartTotals(){var A,e;const t=Number(null==(A=this._protectionVariant)?void 0:A.price)||0,d=(Number(null==(e=this._cart)?void 0:e.total_price)||0)/100;return{protectionPrice:t,cartPrice:d,cartTotal:this._hasProtectionInCart?d:t+d}}_getCheckoutImpactFeatures(){var A,e,t,d;const n=Boolean(null==(e=null==(A=this._store)?void 0:A.greenProtection)?void 0:e.enabled),r=Boolean(null==(d=null==(t=this._store)?void 0:t.freeGifts)?void 0:d.enabled);return{isGreenProtectionEnabled:n,isFreeGiftEnabled:r,impactActive:n||r}}_renderGetMechanismCheckoutButton(A,e,t,d,n,r){var a,o,g,v,u,f;return H`
|
|
1219
1219
|
<style>
|
|
1220
1220
|
:host {
|
|
1221
1221
|
display: inline-block;
|
|
@@ -1731,7 +1731,7 @@ function UA(A,e,t){return A?e():null==t?void 0:t()}const GA=rA`
|
|
|
1731
1731
|
</div>
|
|
1732
1732
|
`)}
|
|
1733
1733
|
</div>
|
|
1734
|
-
`}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(A){const e=window.fetch;let t=!0;const d=async(d,n)=>{const r=e(d,n);if(t)try{await A([d,n],r)}catch(a){console.warn(a)}return await r};return window.fetch=d,()=>{window.fetch===d?window.fetch=e:t=!1}}(async(A,e)=>{var t,d;if(!(null==(d=null==(t=A[1])?void 0:t.headers)?void 0:d["X-ShipAid"])&&(A[0].startsWith("/cart/change")||A[0].startsWith("/cart/update"))&&!this._isUpdatingShipAid)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons(),await e,await this.updateCart(),await this.updateProtection(!0)}catch(n){console.error("[ShipAid] Interceptor error:",n)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}});try{document.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}disconnectedCallback(){var A;super.disconnectedCallback(),null==(A=this.fetchInterceptorCleanup)||A.call(this);try{document.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}updated(A){if(super.updated(A),!this._hasFinishedSetup)return;const e=this._getContactlessCheckoutSelector();if(!sessionStorage.getItem("shipaidWidgetTheme")&&e&&sessionStorage.setItem("shipaidWidgetTheme",e),!this.useShipAidCheckout&&e||sessionStorage.removeItem("shipaidWidgetTheme"),this.useShipAidCheckout||document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach(A=>A.remove()),!this._shouldShowWidgetContent()){const A=sessionStorage.getItem("shipaidWidgetTheme")||this.dataSelector;A&&this.getElementsBySelector(A).forEach(A=>{A.removeAttribute("shipaid-hidden")})}}async updateProtection(A=!1){var e,t,d;if(this._cartLastUpdated=new Date,!(null==(e=this._cart)?void 0:e.items))return;if(this._isUpdatingShipAid&&!A)return;const n=this._cart.items.filter(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)});if(n.length>1)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();for(let A=1;A<n.length;A++)await this.updateCartProtectionVariant(0,n[A]),await new Promise(A=>setTimeout(A,100));this._cart=await this._fetchCart()}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}const r=(null==(t=this._cart.items)?void 0:t.findIndex(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)}))??-1,a=r>=0&&this._cart.items?this._cart.items[r]:void 0;if(this._hasProtectionInCart=!!a,!this._store)return;const o=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&a&&(this._cart.total_price===(null==a?void 0:a.final_line_price)||!o)){const A=await this.updateCartProtectionVariant(0,a);return sessionStorage.removeItem(me),await this._handleRefresh(A)}const g=this._findProtectionVariant(o);if(o?(this._protectionVariant=g,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==g?void 0:g.id))return this._shouldShowWidget=!1,void we.error("No matching protection variant found.");if(null==(d=this._protectionVariant)?void 0:d.id)
|
|
1734
|
+
`}async connectedCallback(){super.connectedCallback(),await OA(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(A){const e=window.fetch;let t=!0;const d=async(d,n)=>{const r=e(d,n);if(t)try{await A([d,n],r)}catch(a){console.warn(a)}return await r};return window.fetch=d,()=>{window.fetch===d?window.fetch=e:t=!1}}(async(A,e)=>{var t,d;if(!(null==(d=null==(t=A[1])?void 0:t.headers)?void 0:d["X-ShipAid"])&&(A[0].startsWith("/cart/change")||A[0].startsWith("/cart/update"))&&!this._isUpdatingShipAid)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons(),await e,await this.updateCart(),await this.updateProtection(!0)}catch(n){console.error("[ShipAid] Interceptor error:",n)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}});try{document.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.addEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.addEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}}disconnectedCallback(){var A;super.disconnectedCallback(),null==(A=this.fetchInterceptorCleanup)||A.call(this);try{document.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{window.removeEventListener(ue.CART_UPDATE,this._onShipAidCartEvent)}catch{}try{document.removeEventListener(ve.CART_UPDATED,this._onShipAidInternalCartUpdated)}catch{}this._restoreCheckoutButtonState()}updated(A){if(super.updated(A),!this._hasFinishedSetup)return;const e=this._getContactlessCheckoutSelector();if(!sessionStorage.getItem("shipaidWidgetTheme")&&e&&sessionStorage.setItem("shipaidWidgetTheme",e),!this.useShipAidCheckout&&e||sessionStorage.removeItem("shipaidWidgetTheme"),this.useShipAidCheckout||document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach(A=>A.remove()),!this._shouldShowWidgetContent()){const A=sessionStorage.getItem("shipaidWidgetTheme")||this.dataSelector;A&&this.getElementsBySelector(A).forEach(A=>{A.removeAttribute("shipaid-hidden")}),this._restoreCheckoutButtonState()}}async updateProtection(A=!1){var e,t,d;if(this._cartLastUpdated=new Date,!(null==(e=this._cart)?void 0:e.items))return;if(this._isUpdatingShipAid&&!A)return;const n=this._cart.items.filter(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)});if(n.length>1)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();for(let A=1;A<n.length;A++)await this.updateCartProtectionVariant(0,n[A]),await new Promise(A=>setTimeout(A,100));this._cart=await this._fetchCart()}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}const r=(null==(t=this._cart.items)?void 0:t.findIndex(A=>{var e,t;return null==(t=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:t.some(e=>e.id===A.variant_id)}))??-1,a=r>=0&&this._cart.items?this._cart.items[r]:void 0;if(this._hasProtectionInCart=!!a,!this._store)return;const o=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&a&&(this._cart.total_price===(null==a?void 0:a.final_line_price)||!o)){const A=await this.updateCartProtectionVariant(0,a);return sessionStorage.removeItem(me),await this._handleRefresh(A)}const g=this._findProtectionVariant(o);if(o?(this._protectionVariant=g,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==g?void 0:g.id))return this._shouldShowWidget=!1,this._restoreCheckoutButtonState(),void we.error("No matching protection variant found.");if(!(null==(d=this._protectionVariant)?void 0:d.id))return this._shouldShowWidget=!1,void this._restoreCheckoutButtonState();if(this.useShipAidCheckout&&this.supportSubscriptions&&(this._sellingPlanId=await this.getSubscription(this._cart)),a){if(this.supportSubscriptions&&!this.useShipAidCheckout&&this._cart.items){const A=this._cart.items.find(A=>{var e;return A.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==A?void 0:A.selling_plan_allocation)});let e=!0;if(!A&&(null==a?void 0:a.selling_plan_allocation)?this._sellingPlanId=null:A&&!(null==a?void 0:a.selling_plan_allocation)?this._sellingPlanId=await this.getSubscription(this._cart):e=!1,e)try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A=await this.updateCartProtectionVariant(1,a);await this._handleRefresh(A)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}if(a&&g.id===a.variant_id){if(this._protectionCartItem={...a,index:r,position:r+1},1===a.quantity)return;try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A=await this.updateCartProtectionVariant(1,a);this._handleRefreshCart(),await this._handleRefresh(A)}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}else try{this._isUpdatingShipAid=!0,this._disableCheckoutButtons();const A={updates:{[a.variant_id]:0,[g.id]:1}},e=await this._fetch.post("/cart/update.js",A);await this.updateCart(e,{dispatchExternalEvents:!0})}finally{this._isUpdatingShipAid=!1,this._enableCheckoutButtons()}}}render(){return yA(this,async()=>{var A,e,t,d,n,r;document.cookie.split(";").forEach(function(A){const e=A.split("=")[0].trim();e.endsWith("product_tags")&&(document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/",document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;")});const a=document.createElement("link");a.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),a.setAttribute("rel","stylesheet"),document.head.appendChild(a);try{const[A,e,t]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=A,this._cart=e,this._protectionProduct=t}catch(o){return we.error(o.message),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()}return this.planActive?(null==(e=null==(A=this._store)?void 0:A.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,xe(this._store),this._dispatchEvent(ve.LOADED,this._store),setTimeout(async()=>{var A,e,t,d;(null==(A=this._store)?void 0:A.widgetAutoOptIn)&&!this.useShipAidCheckout&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(t=this._store.excludedCustomersIdsAutoOptIn)?void 0:t.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(me)||!this._hasProtectionInCart&&(null==(d=this._cart)?void 0:d.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(me,JSON.stringify({loaded:!0}))))},500),void(this.disablePolling||(setInterval(async()=>{const A=this._cartLastUpdated;A&&(new Date).getTime()-A.getTime()<this.pollingInterval||await this.updateCart()},this.pollingInterval),(null==(t=this._store)?void 0:t.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval(async()=>{await this.attemptAddProtection()},400),localStorage.setItem(`${Oe}_${this.intervalId}`,`${this.intervalId}`)),(null==(r=null==(n=null==(d=this._store)?void 0:d.widgetConfigurations)?void 0:n.widget)?void 0:r.pollVariantsCheck)&&setInterval(async()=>{await this.handleMultipleProtectionVariants()},400)))):(we.warn("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()):(we.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState()):(we.warn("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1,void this._restoreCheckoutButtonState())},[]),yA(this,async()=>{await this.updateProtection()},[this._store,this._cart]),yA(this,()=>{K(this.renderPopups(),document.body)},[this._popup]),H`
|
|
1735
1735
|
<style>
|
|
1736
1736
|
:host {
|
|
1737
1737
|
--shipaid-primary: #002bd6;
|
|
@@ -194,6 +194,11 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
194
194
|
* @private
|
|
195
195
|
*/
|
|
196
196
|
private _findAndCacheCheckoutButton;
|
|
197
|
+
/**
|
|
198
|
+
* Restore the original checkout button styles/attributes if we modified them
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
private _restoreCheckoutButtonState;
|
|
197
202
|
/**
|
|
198
203
|
* Calculate cart totals for checkoutButtonTemplate
|
|
199
204
|
* @private
|