ui.shipaid.com 0.2.1 → 0.2.2

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.
@@ -10,15 +10,15 @@ var xt=Object.defineProperty,Pt=Object.defineProperties;var Tt=Object.getOwnProp
10
10
  * @license
11
11
  * Copyright 2017 Google LLC
12
12
  * SPDX-License-Identifier: BSD-3-Clause
13
- */function g(o){return B(b(A({},o),{state:!0}))}/**
13
+ */function v(o){return B(b(A({},o),{state:!0}))}/**
14
14
  * @license
15
15
  * Copyright 2021 Google LLC
16
16
  * SPDX-License-Identifier: BSD-3-Clause
17
- */var W;((W=window.HTMLSlotElement)===null||W===void 0?void 0:W.prototype.assignedElements)!=null;/**
17
+ */var V;((V=window.HTMLSlotElement)===null||V===void 0?void 0:V.prototype.assignedElements)!=null;/**
18
18
  * @license
19
19
  * Copyright 2019 Google LLC
20
20
  * SPDX-License-Identifier: BSD-3-Clause
21
- */const V=window.ShadowRoot&&(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,q=Symbol(),lt=new Map;class ht{constructor(t,e){if(this._$cssResult$=!0,e!==q)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=lt.get(this.cssText);return V&&t===void 0&&(lt.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const It=o=>new ht(typeof o=="string"?o:o+"",q),Ot=(o,...t)=>{const e=o.length===1?o[0]:t.reduce((i,r,s)=>i+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+o[s+1],o[0]);return new ht(e,q)},zt=(o,t)=>{V?o.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet):t.forEach(e=>{const i=document.createElement("style"),r=window.litNonce;r!==void 0&&i.setAttribute("nonce",r),i.textContent=e.cssText,o.appendChild(i)})},dt=V?o=>o:o=>o instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return It(e)})(o):o;/**
21
+ */const W=window.ShadowRoot&&(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,q=Symbol(),lt=new Map;class ht{constructor(t,e){if(this._$cssResult$=!0,e!==q)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=lt.get(this.cssText);return W&&t===void 0&&(lt.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const It=o=>new ht(typeof o=="string"?o:o+"",q),Ot=(o,...t)=>{const e=o.length===1?o[0]:t.reduce((i,r,s)=>i+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+o[s+1],o[0]);return new ht(e,q)},zt=(o,t)=>{W?o.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet):t.forEach(e=>{const i=document.createElement("style"),r=window.litNonce;r!==void 0&&i.setAttribute("nonce",r),i.textContent=e.cssText,o.appendChild(i)})},dt=W?o=>o:o=>o instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return It(e)})(o):o;/**
22
22
  * @license
23
23
  * Copyright 2017 Google LLC
24
24
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,7 +26,7 @@ var xt=Object.defineProperty,Pt=Object.defineProperties;var Tt=Object.getOwnProp
26
26
  * @license
27
27
  * Copyright 2017 Google LLC
28
28
  * SPDX-License-Identifier: BSD-3-Clause
29
- */var K;const x=globalThis.trustedTypes,mt=x?x.createPolicy("lit-html",{createHTML:o=>o}):void 0,$=`lit$${(Math.random()+"").slice(9)}$`,vt="?"+$,Rt=`<${vt}>`,P=document,M=(o="")=>P.createComment(o),N=o=>o===null||typeof o!="object"&&typeof o!="function",gt=Array.isArray,Dt=o=>{var t;return gt(o)||typeof((t=o)===null||t===void 0?void 0:t[Symbol.iterator])=="function"},I=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_t=/-->/g,yt=/>/g,L=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,Ct=/'/g,$t=/"/g,wt=/^(?:script|style|textarea|title)$/i,Ft=o=>(t,...e)=>({_$litType$:o,strings:t,values:e}),w=Ft(1),T=Symbol.for("lit-noChange"),f=Symbol.for("lit-nothing"),At=new WeakMap,jt=(o,t,e)=>{var i,r;const s=(i=e==null?void 0:e.renderBefore)!==null&&i!==void 0?i:t;let n=s._$litPart$;if(n===void 0){const d=(r=e==null?void 0:e.renderBefore)!==null&&r!==void 0?r:null;s._$litPart$=n=new R(t.insertBefore(M(),d),d,void 0,e!=null?e:{})}return n._$AI(o),n},U=P.createTreeWalker(P,129,null,!1),Bt=(o,t)=>{const e=o.length-1,i=[];let r,s=t===2?"<svg>":"",n=I;for(let a=0;a<e;a++){const p=o[a];let c,l,h=-1,u=0;for(;u<p.length&&(n.lastIndex=u,l=n.exec(p),l!==null);)u=n.lastIndex,n===I?l[1]==="!--"?n=_t:l[1]!==void 0?n=yt:l[2]!==void 0?(wt.test(l[2])&&(r=RegExp("</"+l[2],"g")),n=L):l[3]!==void 0&&(n=L):n===L?l[0]===">"?(n=r!=null?r:I,h=-1):l[1]===void 0?h=-2:(h=n.lastIndex-l[2].length,c=l[1],n=l[3]===void 0?L:l[3]==='"'?$t:Ct):n===$t||n===Ct?n=L:n===_t||n===yt?n=I:(n=L,r=void 0);const _=n===L&&o[a+1].startsWith("/>")?" ":"";s+=n===I?p+Rt:h>=0?(i.push(c),p.slice(0,h)+"$lit$"+p.slice(h)+$+_):p+$+(h===-2?(i.push(void 0),a):_)}const d=s+(o[e]||"<?>")+(t===2?"</svg>":"");if(!Array.isArray(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return[mt!==void 0?mt.createHTML(d):d,i]};class H{constructor({strings:t,_$litType$:e},i){let r;this.parts=[];let s=0,n=0;const d=t.length-1,a=this.parts,[p,c]=Bt(t,e);if(this.el=H.createElement(p,i),U.currentNode=this.el.content,e===2){const l=this.el.content,h=l.firstChild;h.remove(),l.append(...h.childNodes)}for(;(r=U.nextNode())!==null&&a.length<d;){if(r.nodeType===1){if(r.hasAttributes()){const l=[];for(const h of r.getAttributeNames())if(h.endsWith("$lit$")||h.startsWith($)){const u=c[n++];if(l.push(h),u!==void 0){const _=r.getAttribute(u.toLowerCase()+"$lit$").split($),y=/([.?@])?(.*)/.exec(u);a.push({type:1,index:s,name:y[2],strings:_,ctor:y[1]==="."?Vt:y[1]==="?"?Zt:y[1]==="@"?Jt:D})}else a.push({type:6,index:s})}for(const h of l)r.removeAttribute(h)}if(wt.test(r.tagName)){const l=r.textContent.split($),h=l.length-1;if(h>0){r.textContent=x?x.emptyScript:"";for(let u=0;u<h;u++)r.append(l[u],M()),U.nextNode(),a.push({type:2,index:++s});r.append(l[h],M())}}}else if(r.nodeType===8)if(r.data===vt)a.push({type:2,index:s});else{let l=-1;for(;(l=r.data.indexOf($,l+1))!==-1;)a.push({type:7,index:s}),l+=$.length-1}s++}}static createElement(t,e){const i=P.createElement("template");return i.innerHTML=t,i}}function k(o,t,e=o,i){var r,s,n,d;if(t===T)return t;let a=i!==void 0?(r=e._$Cl)===null||r===void 0?void 0:r[i]:e._$Cu;const p=N(t)?void 0:t._$litDirective$;return(a==null?void 0:a.constructor)!==p&&((s=a==null?void 0:a._$AO)===null||s===void 0||s.call(a,!1),p===void 0?a=void 0:(a=new p(o),a._$AT(o,e,i)),i!==void 0?((n=(d=e)._$Cl)!==null&&n!==void 0?n:d._$Cl=[])[i]=a:e._$Cu=a),a!==void 0&&(t=k(o,a._$AS(o,t.values),a,i)),t}class Wt{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:r}=this._$AD,s=((e=t==null?void 0:t.creationScope)!==null&&e!==void 0?e:P).importNode(i,!0);U.currentNode=s;let n=U.nextNode(),d=0,a=0,p=r[0];for(;p!==void 0;){if(d===p.index){let c;p.type===2?c=new R(n,n.nextSibling,this,t):p.type===1?c=new p.ctor(n,p.name,p.strings,this,t):p.type===6&&(c=new Yt(n,this,t)),this.v.push(c),p=r[++a]}d!==(p==null?void 0:p.index)&&(n=U.nextNode(),d++)}return s}m(t){let e=0;for(const i of this.v)i!==void 0&&(i.strings!==void 0?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class R{constructor(t,e,i,r){var s;this.type=2,this._$AH=f,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=r,this._$Cg=(s=r==null?void 0:r.isConnected)===null||s===void 0||s}get _$AU(){var t,e;return(e=(t=this._$AM)===null||t===void 0?void 0:t._$AU)!==null&&e!==void 0?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&t.nodeType===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=k(this,t,e),N(t)?t===f||t==null||t===""?(this._$AH!==f&&this._$AR(),this._$AH=f):t!==this._$AH&&t!==T&&this.$(t):t._$litType$!==void 0?this.T(t):t.nodeType!==void 0?this.k(t):Dt(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==f&&N(this._$AH)?this._$AA.nextSibling.data=t:this.k(P.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:r}=t,s=typeof r=="number"?this._$AC(t):(r.el===void 0&&(r.el=H.createElement(r.h,this.options)),r);if(((e=this._$AH)===null||e===void 0?void 0:e._$AD)===s)this._$AH.m(i);else{const n=new Wt(s,this),d=n.p(this.options);n.m(i),this.k(d),this._$AH=n}}_$AC(t){let e=At.get(t.strings);return e===void 0&&At.set(t.strings,e=new H(t)),e}S(t){gt(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,r=0;for(const s of t)r===e.length?e.push(i=new R(this.A(M()),this.A(M()),this,this.options)):i=e[r],i._$AI(s),r++;r<e.length&&(this._$AR(i&&i._$AB.nextSibling,r),e.length=r)}_$AR(t=this._$AA.nextSibling,e){var i;for((i=this._$AP)===null||i===void 0||i.call(this,!1,!0,e);t&&t!==this._$AB;){const r=t.nextSibling;t.remove(),t=r}}setConnected(t){var e;this._$AM===void 0&&(this._$Cg=t,(e=this._$AP)===null||e===void 0||e.call(this,t))}}class D{constructor(t,e,i,r,s){this.type=1,this._$AH=f,this._$AN=void 0,this.element=t,this.name=e,this._$AM=r,this.options=s,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=f}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,r){const s=this.strings;let n=!1;if(s===void 0)t=k(this,t,e,0),n=!N(t)||t!==this._$AH&&t!==T,n&&(this._$AH=t);else{const d=t;let a,p;for(t=s[0],a=0;a<s.length-1;a++)p=k(this,d[i+a],e,a),p===T&&(p=this._$AH[a]),n||(n=!N(p)||p!==this._$AH[a]),p===f?t=f:t!==f&&(t+=(p!=null?p:"")+s[a+1]),this._$AH[a]=p}n&&!r&&this.C(t)}C(t){t===f?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t!=null?t:"")}}class Vt extends D{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===f?void 0:t}}const qt=x?x.emptyScript:"";class Zt extends D{constructor(){super(...arguments),this.type=4}C(t){t&&t!==f?this.element.setAttribute(this.name,qt):this.element.removeAttribute(this.name)}}class Jt extends D{constructor(t,e,i,r,s){super(t,e,i,r,s),this.type=5}_$AI(t,e=this){var i;if((t=(i=k(this,t,e,0))!==null&&i!==void 0?i:f)===T)return;const r=this._$AH,s=t===f&&r!==f||t.capture!==r.capture||t.once!==r.once||t.passive!==r.passive,n=t!==f&&(r===f||s);s&&this.element.removeEventListener(this.name,this,r),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;typeof this._$AH=="function"?this._$AH.call((i=(e=this.options)===null||e===void 0?void 0:e.host)!==null&&i!==void 0?i:this.element,t):this._$AH.handleEvent(t)}}class Yt{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){k(this,t)}}const bt=window.litHtmlPolyfillSupport;bt==null||bt(H,R),((K=globalThis.litHtmlVersions)!==null&&K!==void 0?K:globalThis.litHtmlVersions=[]).push("2.2.0");/**
29
+ */var K;const x=globalThis.trustedTypes,mt=x?x.createPolicy("lit-html",{createHTML:o=>o}):void 0,$=`lit$${(Math.random()+"").slice(9)}$`,gt="?"+$,Rt=`<${gt}>`,P=document,M=(o="")=>P.createComment(o),N=o=>o===null||typeof o!="object"&&typeof o!="function",vt=Array.isArray,Dt=o=>{var t;return vt(o)||typeof((t=o)===null||t===void 0?void 0:t[Symbol.iterator])=="function"},I=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_t=/-->/g,yt=/>/g,L=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,Ct=/'/g,$t=/"/g,wt=/^(?:script|style|textarea|title)$/i,Ft=o=>(t,...e)=>({_$litType$:o,strings:t,values:e}),w=Ft(1),T=Symbol.for("lit-noChange"),f=Symbol.for("lit-nothing"),At=new WeakMap,jt=(o,t,e)=>{var i,r;const s=(i=e==null?void 0:e.renderBefore)!==null&&i!==void 0?i:t;let n=s._$litPart$;if(n===void 0){const d=(r=e==null?void 0:e.renderBefore)!==null&&r!==void 0?r:null;s._$litPart$=n=new R(t.insertBefore(M(),d),d,void 0,e!=null?e:{})}return n._$AI(o),n},U=P.createTreeWalker(P,129,null,!1),Bt=(o,t)=>{const e=o.length-1,i=[];let r,s=t===2?"<svg>":"",n=I;for(let a=0;a<e;a++){const p=o[a];let c,l,h=-1,u=0;for(;u<p.length&&(n.lastIndex=u,l=n.exec(p),l!==null);)u=n.lastIndex,n===I?l[1]==="!--"?n=_t:l[1]!==void 0?n=yt:l[2]!==void 0?(wt.test(l[2])&&(r=RegExp("</"+l[2],"g")),n=L):l[3]!==void 0&&(n=L):n===L?l[0]===">"?(n=r!=null?r:I,h=-1):l[1]===void 0?h=-2:(h=n.lastIndex-l[2].length,c=l[1],n=l[3]===void 0?L:l[3]==='"'?$t:Ct):n===$t||n===Ct?n=L:n===_t||n===yt?n=I:(n=L,r=void 0);const _=n===L&&o[a+1].startsWith("/>")?" ":"";s+=n===I?p+Rt:h>=0?(i.push(c),p.slice(0,h)+"$lit$"+p.slice(h)+$+_):p+$+(h===-2?(i.push(void 0),a):_)}const d=s+(o[e]||"<?>")+(t===2?"</svg>":"");if(!Array.isArray(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return[mt!==void 0?mt.createHTML(d):d,i]};class H{constructor({strings:t,_$litType$:e},i){let r;this.parts=[];let s=0,n=0;const d=t.length-1,a=this.parts,[p,c]=Bt(t,e);if(this.el=H.createElement(p,i),U.currentNode=this.el.content,e===2){const l=this.el.content,h=l.firstChild;h.remove(),l.append(...h.childNodes)}for(;(r=U.nextNode())!==null&&a.length<d;){if(r.nodeType===1){if(r.hasAttributes()){const l=[];for(const h of r.getAttributeNames())if(h.endsWith("$lit$")||h.startsWith($)){const u=c[n++];if(l.push(h),u!==void 0){const _=r.getAttribute(u.toLowerCase()+"$lit$").split($),y=/([.?@])?(.*)/.exec(u);a.push({type:1,index:s,name:y[2],strings:_,ctor:y[1]==="."?Wt:y[1]==="?"?Zt:y[1]==="@"?Jt:D})}else a.push({type:6,index:s})}for(const h of l)r.removeAttribute(h)}if(wt.test(r.tagName)){const l=r.textContent.split($),h=l.length-1;if(h>0){r.textContent=x?x.emptyScript:"";for(let u=0;u<h;u++)r.append(l[u],M()),U.nextNode(),a.push({type:2,index:++s});r.append(l[h],M())}}}else if(r.nodeType===8)if(r.data===gt)a.push({type:2,index:s});else{let l=-1;for(;(l=r.data.indexOf($,l+1))!==-1;)a.push({type:7,index:s}),l+=$.length-1}s++}}static createElement(t,e){const i=P.createElement("template");return i.innerHTML=t,i}}function k(o,t,e=o,i){var r,s,n,d;if(t===T)return t;let a=i!==void 0?(r=e._$Cl)===null||r===void 0?void 0:r[i]:e._$Cu;const p=N(t)?void 0:t._$litDirective$;return(a==null?void 0:a.constructor)!==p&&((s=a==null?void 0:a._$AO)===null||s===void 0||s.call(a,!1),p===void 0?a=void 0:(a=new p(o),a._$AT(o,e,i)),i!==void 0?((n=(d=e)._$Cl)!==null&&n!==void 0?n:d._$Cl=[])[i]=a:e._$Cu=a),a!==void 0&&(t=k(o,a._$AS(o,t.values),a,i)),t}class Vt{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:r}=this._$AD,s=((e=t==null?void 0:t.creationScope)!==null&&e!==void 0?e:P).importNode(i,!0);U.currentNode=s;let n=U.nextNode(),d=0,a=0,p=r[0];for(;p!==void 0;){if(d===p.index){let c;p.type===2?c=new R(n,n.nextSibling,this,t):p.type===1?c=new p.ctor(n,p.name,p.strings,this,t):p.type===6&&(c=new Yt(n,this,t)),this.v.push(c),p=r[++a]}d!==(p==null?void 0:p.index)&&(n=U.nextNode(),d++)}return s}m(t){let e=0;for(const i of this.v)i!==void 0&&(i.strings!==void 0?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class R{constructor(t,e,i,r){var s;this.type=2,this._$AH=f,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=r,this._$Cg=(s=r==null?void 0:r.isConnected)===null||s===void 0||s}get _$AU(){var t,e;return(e=(t=this._$AM)===null||t===void 0?void 0:t._$AU)!==null&&e!==void 0?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&t.nodeType===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=k(this,t,e),N(t)?t===f||t==null||t===""?(this._$AH!==f&&this._$AR(),this._$AH=f):t!==this._$AH&&t!==T&&this.$(t):t._$litType$!==void 0?this.T(t):t.nodeType!==void 0?this.k(t):Dt(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==f&&N(this._$AH)?this._$AA.nextSibling.data=t:this.k(P.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:r}=t,s=typeof r=="number"?this._$AC(t):(r.el===void 0&&(r.el=H.createElement(r.h,this.options)),r);if(((e=this._$AH)===null||e===void 0?void 0:e._$AD)===s)this._$AH.m(i);else{const n=new Vt(s,this),d=n.p(this.options);n.m(i),this.k(d),this._$AH=n}}_$AC(t){let e=At.get(t.strings);return e===void 0&&At.set(t.strings,e=new H(t)),e}S(t){vt(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,r=0;for(const s of t)r===e.length?e.push(i=new R(this.A(M()),this.A(M()),this,this.options)):i=e[r],i._$AI(s),r++;r<e.length&&(this._$AR(i&&i._$AB.nextSibling,r),e.length=r)}_$AR(t=this._$AA.nextSibling,e){var i;for((i=this._$AP)===null||i===void 0||i.call(this,!1,!0,e);t&&t!==this._$AB;){const r=t.nextSibling;t.remove(),t=r}}setConnected(t){var e;this._$AM===void 0&&(this._$Cg=t,(e=this._$AP)===null||e===void 0||e.call(this,t))}}class D{constructor(t,e,i,r,s){this.type=1,this._$AH=f,this._$AN=void 0,this.element=t,this.name=e,this._$AM=r,this.options=s,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=f}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,r){const s=this.strings;let n=!1;if(s===void 0)t=k(this,t,e,0),n=!N(t)||t!==this._$AH&&t!==T,n&&(this._$AH=t);else{const d=t;let a,p;for(t=s[0],a=0;a<s.length-1;a++)p=k(this,d[i+a],e,a),p===T&&(p=this._$AH[a]),n||(n=!N(p)||p!==this._$AH[a]),p===f?t=f:t!==f&&(t+=(p!=null?p:"")+s[a+1]),this._$AH[a]=p}n&&!r&&this.C(t)}C(t){t===f?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t!=null?t:"")}}class Wt extends D{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===f?void 0:t}}const qt=x?x.emptyScript:"";class Zt extends D{constructor(){super(...arguments),this.type=4}C(t){t&&t!==f?this.element.setAttribute(this.name,qt):this.element.removeAttribute(this.name)}}class Jt extends D{constructor(t,e,i,r,s){super(t,e,i,r,s),this.type=5}_$AI(t,e=this){var i;if((t=(i=k(this,t,e,0))!==null&&i!==void 0?i:f)===T)return;const r=this._$AH,s=t===f&&r!==f||t.capture!==r.capture||t.once!==r.once||t.passive!==r.passive,n=t!==f&&(r===f||s);s&&this.element.removeEventListener(this.name,this,r),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;typeof this._$AH=="function"?this._$AH.call((i=(e=this.options)===null||e===void 0?void 0:e.host)!==null&&i!==void 0?i:this.element,t):this._$AH.handleEvent(t)}}class Yt{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){k(this,t)}}const bt=window.litHtmlPolyfillSupport;bt==null||bt(H,R),((K=globalThis.litHtmlVersions)!==null&&K!==void 0?K:globalThis.litHtmlVersions=[]).push("2.2.0");/**
30
30
  * @license
31
31
  * Copyright 2017 Google LLC
32
32
  * SPDX-License-Identifier: BSD-3-Clause
@@ -271,7 +271,7 @@ var xt=Object.defineProperty,Pt=Object.defineProperties;var Tt=Object.getOwnProp
271
271
  color: var(--shipaid-text-grey);
272
272
  font-weight: var(--shipaid-font-heavy);
273
273
  }
274
- `,z=(o=>(o.LOADED="shipaid-loaded",o.STATUS_UPDATE="shipaid-protection-status",o))(z||{}),ee=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,v=(o,t,e,i)=>{for(var r=i>1?void 0:i?ie(t,e):t,s=o.length-1,n;s>=0;s--)(n=o[s])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&ee(t,e,r),r};const St=async(o,t)=>{try{const e=await fetch(o,t);if(!e.ok)throw new Error(await e.text());return await e.json()}catch(e){throw console.error(e),new Error("Failed to complete fetch request.")}},S={warn:o=>console.warn(`[ShipAid] ${o}`),error:o=>console.error(`[ShipAid] ${o}`)},oe=2500,tt="shipaid-protection";let m=class extends O{constructor(){super(...arguments);var o;this.disablePolling=!1,this.pollingInterval=oe,this._apiEndpoint="/apps/shipaid",this._storeDomain=(o=window.Shopify)==null?void 0:o.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>St(t),post:(t,e)=>St(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var e;Qt(this,async()=>{var r,s,n,d;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const a=localStorage.getItem(tt),{lastAction:p}=a?JSON.parse(a):{};p&&(this._lastAction=p)}catch{S.warn("Failed to parse local storage.")}try{const[a,p]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=a,this._cart=p}catch{this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((s=(r=this._store)==null?void 0:r.plan)!=null&&s.active)){S.warn("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((d=(n=this._store)==null?void 0:n.protectionSettings)!=null&&d.protectionType)){S.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(z.LOADED,this._store),setTimeout(async()=>{var c;const a=localStorage.getItem(tt),{lastAction:p}=a?JSON.parse(a):{};p!=="removed"&&!this._hasProtectionInCart&&((c=this._store)==null?void 0:c.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()},500),!this.disablePolling&&setInterval(async()=>{const a=this._cartLastUpdated;a&&new Date().getTime()-a.getTime()<this.pollingInterval||await this.updateCart()},this.pollingInterval)}),Q(this,()=>{const i={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(tt,JSON.stringify(i))},[this._lastAction]),Q(this,async()=>{var l,h,u,_,y;if(this._cartLastUpdated=new Date,!((l=this._cart)!=null&&l.items))return;const i=await this.calculateProtectionTotal(this._cart),r=this._findProtectionVariant(i);if(this._protectionVariant=r,!(r!=null&&r.id)){this._shouldShowWidget=!1,S.error("No matching protection variant found.");return}const s=(u=(h=this._cart.items)==null?void 0:h.findIndex(Et=>{var et,it,ot,rt,st;return(st=(rt=(ot=(it=(et=this._store)==null?void 0:et.protectionSettings)==null?void 0:it.product)==null?void 0:ot.variants)==null?void 0:rt.edges)==null?void 0:st.some(({node:j})=>{var nt;return(nt=j==null?void 0:j.id)==null?void 0:nt.includes(Et.variant_id.toString())})}))!=null?u:[],n=(_=this._cart)==null?void 0:_.items[s];if(this._hasProtectionInCart=!!n,!n)return;if((y=r.id)!=null&&y.includes(n.id.toString())){this._protectionCartItem=b(A({},n),{index:s,position:s+1});return}const d={id:n.key,quantity:0};await this._fetch.post("/cart/change.js",d);const a={id:r.id.replace("gid://shopify/ProductVariant/",""),quantity:1},p=await this._fetch.post("/cart/add.js",a),c=b(A({},this._cart),{items:[p,...this._cart.items]});this._cart=c,this._dispatchEvent(z.STATUS_UPDATE,{protection:!0,cart:c,lineItem:p}),this.disablePolling||window.location.reload()},[this._store,this._cart]);const o=w`
274
+ `,z=(o=>(o.LOADED="shipaid-loaded",o.STATUS_UPDATE="shipaid-protection-status",o))(z||{}),ee=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,g=(o,t,e,i)=>{for(var r=i>1?void 0:i?ie(t,e):t,s=o.length-1,n;s>=0;s--)(n=o[s])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&ee(t,e,r),r};const St=async(o,t)=>{try{const e=await fetch(o,t);if(!e.ok)throw new Error(await e.text());return await e.json()}catch(e){throw console.error(e),new Error("Failed to complete fetch request.")}},S={warn:o=>console.warn(`[ShipAid] ${o}`),error:o=>console.error(`[ShipAid] ${o}`)},oe=2500,tt="shipaid-protection";let m=class extends O{constructor(){super(...arguments);var o;this.disablePolling=!1,this.pollingInterval=oe,this._apiEndpoint="/apps/shipaid",this._storeDomain=(o=window.Shopify)==null?void 0:o.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>St(t),post:(t,e)=>St(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var e;Qt(this,async()=>{var r,s,n,d;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const a=localStorage.getItem(tt),{lastAction:p}=a?JSON.parse(a):{};p&&(this._lastAction=p)}catch{S.warn("Failed to parse local storage.")}try{const[a,p]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=a,this._cart=p}catch{this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((s=(r=this._store)==null?void 0:r.plan)!=null&&s.active)){S.warn("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((d=(n=this._store)==null?void 0:n.protectionSettings)!=null&&d.protectionType)){S.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(z.LOADED,this._store),setTimeout(async()=>{var c;const a=localStorage.getItem(tt),{lastAction:p}=a?JSON.parse(a):{};p!=="removed"&&!this._hasProtectionInCart&&((c=this._store)==null?void 0:c.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()},500),!this.disablePolling&&setInterval(async()=>{const a=this._cartLastUpdated;a&&new Date().getTime()-a.getTime()<this.pollingInterval||await this.updateCart()},this.pollingInterval)}),Q(this,()=>{const i={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(tt,JSON.stringify(i))},[this._lastAction]),Q(this,async()=>{var l,h,u,_,y;if(this._cartLastUpdated=new Date,!((l=this._cart)!=null&&l.items))return;const i=await this.calculateProtectionTotal(this._cart),r=this._findProtectionVariant(i);if(this._protectionVariant=r,!(r!=null&&r.id)){this._shouldShowWidget=!1,S.error("No matching protection variant found.");return}const s=(u=(h=this._cart.items)==null?void 0:h.findIndex(Et=>{var et,it,ot,rt,st;return(st=(rt=(ot=(it=(et=this._store)==null?void 0:et.protectionSettings)==null?void 0:it.product)==null?void 0:ot.variants)==null?void 0:rt.edges)==null?void 0:st.some(({node:j})=>{var nt;return(nt=j==null?void 0:j.id)==null?void 0:nt.includes(Et.variant_id.toString())})}))!=null?u:[],n=(_=this._cart)==null?void 0:_.items[s];if(this._hasProtectionInCart=!!n,!n)return;if(console.log({protectionVariant:r,protectionCartItem:n}),(y=r.id)==null?void 0:y.includes(n.id.toString())){this._protectionCartItem=b(A({},n),{index:s,position:s+1});return}console.log("running update checks");const d={id:n.key,quantity:0};await this._fetch.post("/cart/change.js",d);const a={id:r.id.replace("gid://shopify/ProductVariant/",""),quantity:1},p=await this._fetch.post("/cart/add.js",a),c=b(A({},this._cart),{items:[p,...this._cart.items]});this._cart=c,this._dispatchEvent(z.STATUS_UPDATE,{protection:!0,cart:c,lineItem:p}),this.disablePolling||window.location.reload()},[this._store,this._cart]);const o=w`
275
275
  <div class=${`shipaid-popup ${this._popup==="learn-more"&&"active"}`}>
276
276
  <div class="popup">
277
277
  <button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
@@ -322,4 +322,4 @@ var xt=Object.defineProperty,Pt=Object.defineProperties;var Tt=Object.getOwnProp
322
322
  <div class="shipaid">
323
323
  ${F(this._hasFinishedSetup,()=>{var i,r;return F(this._shouldShowWidget&&((r=(i=this._store)==null?void 0:i.plan)==null?void 0:r.active)&&this._store.widgetShowCart,()=>[o,t],()=>w``)},()=>w`<p><slot>Loading ShipAid Widget...</slot></p>`)}
324
324
  </div>
325
- `}_currencyFormat(o){var t,e,i,r,s;return new Intl.NumberFormat((e=(t=window.Shopify)==null?void 0:t.locale)!=null?e:void 0,{currency:((i=this._store)==null?void 0:i.currency)||((s=(r=window.Shopify)==null?void 0:r.currency)==null?void 0:s.active)||"USD",style:"currency"}).format(Number(o))}_dispatchEvent(o,t={}){this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:t}))}async calculateProtectionTotal(o){var s,n,d,a,p;if(o||(o=await this._fetchCart()),!o)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const t=(s=this._store)==null?void 0:s.protectionSettings;if(!t||!t.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const e=((n=this._store)==null?void 0:n.excludedProductSkus)&&o.items?o.items.reduce((c,l)=>l.sku&&this._store.excludedProductSkus.find(h=>h===l.sku)?c-l.final_price:c,o.total_price):o.total_price,i=((a=(d=o.items)==null?void 0:d.filter(c=>{var l,h,u;return(u=(h=(l=t.product)==null?void 0:l.variants)==null?void 0:h.edges)==null?void 0:u.some(({node:_})=>{var y;return(y=_==null?void 0:_.id)==null?void 0:y.includes(c.variant_id.toString())})}))!=null?a:[]).reduce((c,l)=>c+=l.final_line_price,0),r=e-i;if(t.protectionType==="FIXED"){if(!t.defaultFee)throw new Error("Missing default fee amount.");if(!((p=t.rules)!=null&&p.length))return t.defaultFee;const c=r/100,l=t.rules.sort((h,u)=>!h.rangeLower||!u.rangeLower?0:h.rangeLower-u.rangeLower).find(h=>{const u=Boolean(h.rangeLower&&h.rangeLower<c);return h.rangeUpper?u&&h.rangeUpper>=c:u});return typeof(l==null?void 0:l.fee)=="number"?l.fee:t.defaultFee}if(t.protectionType==="PERCENTAGE"){const c=r*t.percentage/100;return c>=t.minimumFee?c:t.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(o){var e,i,r;const t=(e=this._store)==null?void 0:e.protectionSettings;if(!t||!((r=(i=t.product)==null?void 0:i.variants)!=null&&r.edges))throw new Error("Missing product and variants from protection settings.");return t.product.variants.edges.flatMap(({node:s})=>{if(!s||!s.price)return[];const n=Number(s.price);return[b(A({},s),{formattedPrice:n})]}).sort((s,n)=>s.formattedPrice-n.formattedPrice).find(s=>s.formattedPrice>=o)}_setState(o,t){this._state={loading:o==="loading",success:o==="success",error:o==="error"?t||!0:!1}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const o=new URL(window.location.href);o.pathname=this._apiEndpoint;const t=await this._fetch.get(o.toString());if(!t)throw new Error(`Failed to fetch store data for ${o.toString()}`);const[e]=t.stores;if(!e)throw new Error(`Could not find a store for this URL ${o.toString()}.`);return e}catch(o){throw console.error(o),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(o){const t=o;throw S.error(t.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(o){o||(o=await this._fetchCart()),this._cart=o}async addProtection(){var o,t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!((o=this._cart)!=null&&o.items))throw new Error("Cart has not been loaded.");if(!((t=this._protectionVariant)!=null&&t.id))throw new Error("No protection variant found.");this._setState("loading");const i={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",i),s=b(A({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(z.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),(((e=window.Shopify)==null?void 0:e.Checkout)||!this.disablePolling)&&window.location.reload()}catch(i){const r=i;S.error(r.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var o;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={id:this._protectionCartItem.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);this._lastAction="removed",this._dispatchEvent(z.STATUS_UPDATE,{protection:!1,cart:e,lineItem:this._protectionCartItem}),this._cart=e,this._setState("success"),(((o=window.Shopify)==null?void 0:o.Checkout)||!this.disablePolling)&&window.location.reload()}catch(t){const e=t;S.error(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}};m.styles=te,v([B({type:Boolean,attribute:!0})],m.prototype,"disablePolling",2),v([B({type:Number,attribute:!0})],m.prototype,"pollingInterval",2),v([g()],m.prototype,"_storeDomain",2),v([g()],m.prototype,"_store",2),v([g()],m.prototype,"_cart",2),v([g()],m.prototype,"_cartLastUpdated",2),v([g()],m.prototype,"_hasFinishedSetup",2),v([g()],m.prototype,"_shouldShowWidget",2),v([g()],m.prototype,"_hasProtectionInCart",2),v([g()],m.prototype,"_lastAction",2),v([g()],m.prototype,"_protectionCartItem",2),v([g()],m.prototype,"_protectionVariant",2),v([g()],m.prototype,"_state",2),v([g()],m.prototype,"_popup",2),m=v([Mt("shipaid-widget")],m);export{m as ShipAidWidget};
325
+ `}_currencyFormat(o){var t,e,i,r,s;return new Intl.NumberFormat((e=(t=window.Shopify)==null?void 0:t.locale)!=null?e:void 0,{currency:((i=this._store)==null?void 0:i.currency)||((s=(r=window.Shopify)==null?void 0:r.currency)==null?void 0:s.active)||"USD",style:"currency"}).format(Number(o))}_dispatchEvent(o,t={}){this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:t}))}async calculateProtectionTotal(o){var s,n,d,a,p;if(o||(o=await this._fetchCart()),!o)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const t=(s=this._store)==null?void 0:s.protectionSettings;if(!t||!t.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const e=((n=this._store)==null?void 0:n.excludedProductSkus)&&o.items?o.items.reduce((c,l)=>l.sku&&this._store.excludedProductSkus.find(h=>h===l.sku)?c-l.final_price:c,o.total_price):o.total_price,i=((a=(d=o.items)==null?void 0:d.filter(c=>{var l,h,u;return(u=(h=(l=t.product)==null?void 0:l.variants)==null?void 0:h.edges)==null?void 0:u.some(({node:_})=>{var y;return(y=_==null?void 0:_.id)==null?void 0:y.includes(c.variant_id.toString())})}))!=null?a:[]).reduce((c,l)=>c+=l.final_line_price,0),r=e-i;if(t.protectionType==="FIXED"){if(!t.defaultFee)throw new Error("Missing default fee amount.");if(!((p=t.rules)!=null&&p.length))return t.defaultFee;const c=r/100,l=t.rules.sort((h,u)=>!h.rangeLower||!u.rangeLower?0:h.rangeLower-u.rangeLower).find(h=>{const u=Boolean(h.rangeLower&&h.rangeLower<c);return h.rangeUpper?u&&h.rangeUpper>=c:u});return typeof(l==null?void 0:l.fee)=="number"?l.fee:t.defaultFee}if(t.protectionType==="PERCENTAGE"){const c=r*t.percentage/100;return c>=t.minimumFee?c:t.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(o){var e,i,r;const t=(e=this._store)==null?void 0:e.protectionSettings;if(!t||!((r=(i=t.product)==null?void 0:i.variants)!=null&&r.edges))throw new Error("Missing product and variants from protection settings.");return t.product.variants.edges.flatMap(({node:s})=>{if(!s||!s.price)return[];const n=Number(s.price);return[b(A({},s),{formattedPrice:n})]}).sort((s,n)=>s.formattedPrice-n.formattedPrice).find(s=>s.formattedPrice>=o)}_setState(o,t){this._state={loading:o==="loading",success:o==="success",error:o==="error"?t||!0:!1}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const o=new URL(window.location.href);o.pathname=this._apiEndpoint;const t=await this._fetch.get(o.toString());if(!t)throw new Error(`Failed to fetch store data for ${o.toString()}`);const[e]=t.stores;if(!e)throw new Error(`Could not find a store for this URL ${o.toString()}.`);return e}catch(o){throw console.error(o),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(o){const t=o;throw S.error(t.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(o){o||(o=await this._fetchCart()),this._cart=o}async addProtection(){var o,t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!((o=this._cart)!=null&&o.items))throw new Error("Cart has not been loaded.");if(!((t=this._protectionVariant)!=null&&t.id))throw new Error("No protection variant found.");this._setState("loading");const i={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",i),s=b(A({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(z.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),(((e=window.Shopify)==null?void 0:e.Checkout)||!this.disablePolling)&&window.location.reload()}catch(i){const r=i;S.error(r.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var o;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={id:this._protectionCartItem.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);this._lastAction="removed",this._dispatchEvent(z.STATUS_UPDATE,{protection:!1,cart:e,lineItem:this._protectionCartItem}),console.log("updating state"),this._cart=e,this._setState("success"),(((o=window.Shopify)==null?void 0:o.Checkout)||!this.disablePolling)&&(console.log("reloading"),window.location.reload())}catch(t){const e=t;S.error(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}};m.styles=te,g([B({type:Boolean,attribute:!0})],m.prototype,"disablePolling",2),g([B({type:Number,attribute:!0})],m.prototype,"pollingInterval",2),g([v()],m.prototype,"_storeDomain",2),g([v()],m.prototype,"_store",2),g([v()],m.prototype,"_cart",2),g([v()],m.prototype,"_cartLastUpdated",2),g([v()],m.prototype,"_hasFinishedSetup",2),g([v()],m.prototype,"_shouldShowWidget",2),g([v()],m.prototype,"_hasProtectionInCart",2),g([v()],m.prototype,"_lastAction",2),g([v()],m.prototype,"_protectionCartItem",2),g([v()],m.prototype,"_protectionVariant",2),g([v()],m.prototype,"_state",2),g([v()],m.prototype,"_popup",2),m=g([Mt("shipaid-widget")],m);export{m as ShipAidWidget};
@@ -35,7 +35,7 @@ const f=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShad
35
35
  * Copyright 2017 Google LLC
36
36
  * SPDX-License-Identifier: BSD-3-Clause
37
37
  */
38
- var E;L.finalized=!0,L.elementProperties=new Map,L.elementStyles=[],L.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:L}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const x=globalThis.trustedTypes,P=x?x.createPolicy("lit-html",{createHTML:t=>t}):void 0,T=`lit$${(Math.random()+"").slice(9)}$`,U="?"+T,M=`<${U}>`,k=document,O=(t="")=>k.createComment(t),N=t=>null===t||"object"!=typeof t&&"function"!=typeof t,I=Array.isArray,z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,W=/>/g,R=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,D=/'/g,j=/"/g,F=/^(?:script|style|textarea|title)$/i,B=(Y=1,(t,...e)=>({_$litType$:Y,strings:t,values:e})),V=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),Z=new WeakMap,J=k.createTreeWalker(k,129,null,!1);var Y;class K{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=z;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===z?"!--"===a[1]?n=H:void 0!==a[1]?n=W:void 0!==a[2]?(F.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=R):void 0!==a[3]&&(n=R):n===R?">"===a[0]?(n=null!=r?r:z,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?R:'"'===a[3]?j:D):n===j||n===D?n=R:n===H||n===W?n=z:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===z?e+M:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+T+h):e+T+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==P?P.createHTML(a):a,o]})(t,e);if(this.el=K.createElement(p,i),J.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=J.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(T)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(T),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?et:"?"===e[1]?ot:"@"===e[1]?rt:tt})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(F.test(o.tagName)){const t=o.textContent.split(T),e=t.length-1;if(e>0){o.textContent=x?x.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],O()),J.nextNode(),a.push({type:2,index:++r});o.append(t[e],O())}}}else if(8===o.nodeType)if(o.data===U)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(T,t+1));)a.push({type:7,index:r}),t+=T.length-1}r++}}static createElement(t,e){const i=k.createElement("template");return i.innerHTML=t,i}}function G(t,e,i=t,o){var r,s,n,a;if(e===V)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=N(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=G(t,p._$AS(t,e.values),p,o)),e}class X{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:k).importNode(i,!0);J.currentNode=r;let s=J.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new Q(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new st(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=J.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class Q{constructor(t,e,i,o){var r;this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$Cg=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=G(this,t,e),N(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==V&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>{var e;return I(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==q&&N(this._$AH)?this._$AA.nextSibling.data=t:this.k(k.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=K.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new X(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new K(t)),e}S(t){I(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new Q(this.A(O()),this.A(O()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class tt{constructor(t,e,i,o,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=G(this,t,e,0),s=!N(t)||t!==this._$AH&&t!==V,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=G(this,o[i+n],e,n),a===V&&(a=this._$AH[n]),s||(s=!N(a)||a!==this._$AH[n]),a===q?t=q:t!==q&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.C(t)}C(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class et extends tt{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===q?void 0:t}}const it=x?x.emptyScript:"";class ot extends tt{constructor(){super(...arguments),this.type=4}C(t){t&&t!==q?this.element.setAttribute(this.name,it):this.element.removeAttribute(this.name)}}class rt extends tt{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=G(this,t,e,0))&&void 0!==i?i:q)===V)return;const o=this._$AH,r=t===q&&o!==q||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==q&&(o===q||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class st{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){G(this,t)}}const nt=window.litHtmlPolyfillSupport;
38
+ var E;L.finalized=!0,L.elementProperties=new Map,L.elementStyles=[],L.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:L}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const x=globalThis.trustedTypes,P=x?x.createPolicy("lit-html",{createHTML:t=>t}):void 0,T=`lit$${(Math.random()+"").slice(9)}$`,U="?"+T,k=`<${U}>`,M=document,O=(t="")=>M.createComment(t),I=t=>null===t||"object"!=typeof t&&"function"!=typeof t,N=Array.isArray,z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,W=/>/g,R=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,D=/'/g,j=/"/g,F=/^(?:script|style|textarea|title)$/i,B=(Y=1,(t,...e)=>({_$litType$:Y,strings:t,values:e})),V=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),Z=new WeakMap,J=M.createTreeWalker(M,129,null,!1);var Y;class K{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=z;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===z?"!--"===a[1]?n=H:void 0!==a[1]?n=W:void 0!==a[2]?(F.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=R):void 0!==a[3]&&(n=R):n===R?">"===a[0]?(n=null!=r?r:z,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?R:'"'===a[3]?j:D):n===j||n===D?n=R:n===H||n===W?n=z:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===z?e+k:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+T+h):e+T+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==P?P.createHTML(a):a,o]})(t,e);if(this.el=K.createElement(p,i),J.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=J.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(T)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(T),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?et:"?"===e[1]?ot:"@"===e[1]?rt:tt})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(F.test(o.tagName)){const t=o.textContent.split(T),e=t.length-1;if(e>0){o.textContent=x?x.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],O()),J.nextNode(),a.push({type:2,index:++r});o.append(t[e],O())}}}else if(8===o.nodeType)if(o.data===U)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(T,t+1));)a.push({type:7,index:r}),t+=T.length-1}r++}}static createElement(t,e){const i=M.createElement("template");return i.innerHTML=t,i}}function G(t,e,i=t,o){var r,s,n,a;if(e===V)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=I(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=G(t,p._$AS(t,e.values),p,o)),e}class X{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:M).importNode(i,!0);J.currentNode=r;let s=J.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new Q(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new st(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=J.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class Q{constructor(t,e,i,o){var r;this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$Cg=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=G(this,t,e),I(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==V&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>{var e;return N(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==q&&I(this._$AH)?this._$AA.nextSibling.data=t:this.k(M.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=K.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new X(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new K(t)),e}S(t){N(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new Q(this.A(O()),this.A(O()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class tt{constructor(t,e,i,o,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=G(this,t,e,0),s=!I(t)||t!==this._$AH&&t!==V,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=G(this,o[i+n],e,n),a===V&&(a=this._$AH[n]),s||(s=!I(a)||a!==this._$AH[n]),a===q?t=q:t!==q&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.C(t)}C(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class et extends tt{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===q?void 0:t}}const it=x?x.emptyScript:"";class ot extends tt{constructor(){super(...arguments),this.type=4}C(t){t&&t!==q?this.element.setAttribute(this.name,it):this.element.removeAttribute(this.name)}}class rt extends tt{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=G(this,t,e,0))&&void 0!==i?i:q)===V)return;const o=this._$AH,r=t===q&&o!==q||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==q&&(o===q||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class st{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){G(this,t)}}const nt=window.litHtmlPolyfillSupport;
39
39
  /**
40
40
  * @license
41
41
  * Copyright 2017 Google LLC
@@ -284,7 +284,7 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
284
284
  color: var(--shipaid-text-grey);
285
285
  font-weight: var(--shipaid-font-heavy);
286
286
  }
287
- `,mt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(mt||{}),gt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?_t(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&gt(e,i,s),s};const Ct=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},wt=t=>console.warn(`[ShipAid] ${t}`),$t=t=>console.error(`[ShipAid] ${t}`),At="shipaid-protection";return t.ShipAidWidget=class extends lt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>Ct(t),post:(t,e)=>Ct(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var t;((t,e)=>{ut(t,e,[])})(this,(async()=>{var t,e,i,o;const r=document.createElement("link");r.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),r.setAttribute("rel","stylesheet"),document.head.appendChild(r);try{const t=localStorage.getItem(At),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch{wt("Failed to parse local storage.")}try{const[t,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return null!=(e=null==(t=this._store)?void 0:t.plan)&&e.active?null!=(o=null==(i=this._store)?void 0:i.protectionSettings)&&o.protectionType?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(mt.LOADED,this._store),setTimeout((async()=>{var t;const e=localStorage.getItem(At),{lastAction:i}=e?JSON.parse(e):{};"removed"!==i&&!this._hasProtectionInCart&&(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(!this.disablePolling&&setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(wt("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(wt("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),ut(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(At,JSON.stringify(t))}),[this._lastAction]),ut(this,(async()=>{var t,e,i,o,r;if(this._cartLastUpdated=new Date,null==(t=this._cart)||!t.items)return;const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,null==n||!n.id)return this._shouldShowWidget=!1,void $t("No matching protection variant found.");const a=null!=(i=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i,o,r,s;return null==(s=null==(r=null==(o=null==(i=null==(e=this._store)?void 0:e.protectionSettings)?void 0:i.product)?void 0:o.variants)?void 0:r.edges)?void 0:s.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?i:[],d=null==(o=this._cart)?void 0:o.items[a];if(this._hasProtectionInCart=!!d,!d)return;if(null!=(r=n.id)&&r.includes(d.id.toString()))return void(this._protectionCartItem=l(p({},d),{index:a,position:a+1}));const h={id:d.key,quantity:0};await this._fetch.post("/cart/change.js",h);const c={id:n.id.replace("gid://shopify/ProductVariant/",""),quantity:1},u=await this._fetch.post("/cart/add.js",c),f=l(p({},this._cart),{items:[u,...this._cart.items]});this._cart=f,this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:f,lineItem:u}),this.disablePolling||window.location.reload()}),[this._store,this._cart]);const e=B`
287
+ `,mt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(mt||{}),gt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?_t(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&gt(e,i,s),s};const Ct=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},wt=t=>console.warn(`[ShipAid] ${t}`),$t=t=>console.error(`[ShipAid] ${t}`),At="shipaid-protection";return t.ShipAidWidget=class extends lt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>Ct(t),post:(t,e)=>Ct(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var t;((t,e)=>{ut(t,e,[])})(this,(async()=>{var t,e,i,o;const r=document.createElement("link");r.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),r.setAttribute("rel","stylesheet"),document.head.appendChild(r);try{const t=localStorage.getItem(At),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch{wt("Failed to parse local storage.")}try{const[t,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return null!=(e=null==(t=this._store)?void 0:t.plan)&&e.active?null!=(o=null==(i=this._store)?void 0:i.protectionSettings)&&o.protectionType?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(mt.LOADED,this._store),setTimeout((async()=>{var t;const e=localStorage.getItem(At),{lastAction:i}=e?JSON.parse(e):{};"removed"!==i&&!this._hasProtectionInCart&&(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(!this.disablePolling&&setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(wt("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(wt("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),ut(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(At,JSON.stringify(t))}),[this._lastAction]),ut(this,(async()=>{var t,e,i,o,r;if(this._cartLastUpdated=new Date,null==(t=this._cart)||!t.items)return;const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,null==n||!n.id)return this._shouldShowWidget=!1,void $t("No matching protection variant found.");const a=null!=(i=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i,o,r,s;return null==(s=null==(r=null==(o=null==(i=null==(e=this._store)?void 0:e.protectionSettings)?void 0:i.product)?void 0:o.variants)?void 0:r.edges)?void 0:s.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?i:[],d=null==(o=this._cart)?void 0:o.items[a];if(this._hasProtectionInCart=!!d,!d)return;if(console.log({protectionVariant:n,protectionCartItem:d}),null==(r=n.id)?void 0:r.includes(d.id.toString()))return void(this._protectionCartItem=l(p({},d),{index:a,position:a+1}));console.log("running update checks");const h={id:d.key,quantity:0};await this._fetch.post("/cart/change.js",h);const c={id:n.id.replace("gid://shopify/ProductVariant/",""),quantity:1},u=await this._fetch.post("/cart/add.js",c),f=l(p({},this._cart),{items:[u,...this._cart.items]});this._cart=f,this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:f,lineItem:u}),this.disablePolling||window.location.reload()}),[this._store,this._cart]);const e=B`
288
288
  <div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
289
289
  <div class="popup">
290
290
  <button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
@@ -335,4 +335,4 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
335
335
  <div class="shipaid">
336
336
  ${ft(this._hasFinishedSetup,(()=>{var t,o;return ft(this._shouldShowWidget&&(null==(o=null==(t=this._store)?void 0:t.plan)?void 0:o.active)&&this._store.widgetShowCart,(()=>[e,i]),(()=>B``))}),(()=>B`<p><slot>Loading ShipAid Widget...</slot></p>`))}
337
337
  </div>
338
- `}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!n.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>e.sku&&this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i,o;return null==(o=null==(i=null==(e=n.product)?void 0:e.variants)?void 0:i.edges)?void 0:o.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?r:[]).reduce(((t,e)=>t+e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(null==(s=n.rules)||!s.length)return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o;const r=null==(e=this._store)?void 0:e.protectionSettings;if(!r||null==(o=null==(i=r.product)?void 0:i.variants)||!o.edges)throw new Error("Missing product and variants from protection settings.");return r.product.variants.edges.flatMap((({node:t})=>{if(!t||!t.price)return[];const e=Number(t.price);return[l(p({},t),{formattedPrice:e})]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)).find((e=>e.formattedPrice>=t))}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const e=await this._fetch.get(t.toString());if(!e)throw new Error(`Failed to fetch store data for ${t.toString()}`);const[i]=e.stores;if(!i)throw new Error(`Could not find a store for this URL ${t.toString()}.`);return i}catch(Y){throw console.error(Y),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(Y){throw $t(Y.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e,i;try{if(!this._store)throw new Error("Store has not been loaded.");if(null==(t=this._cart)||!t.items)throw new Error("Cart has not been loaded.");if(null==(e=this._protectionVariant)||!e.id)throw new Error("No protection variant found.");this._setState("loading");const o={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",o),s=l(p({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),((null==(i=window.Shopify)?void 0:i.Checkout)||!this.disablePolling)&&window.location.reload()}catch(o){$t(o.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var t;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const e={id:this._protectionCartItem.key,quantity:0},i=await this._fetch.post("/cart/change.js",e);this._lastAction="removed",this._dispatchEvent(mt.STATUS_UPDATE,{protection:!1,cart:i,lineItem:this._protectionCartItem}),this._cart=i,this._setState("success"),((null==(t=window.Shopify)?void 0:t.Checkout)||!this.disablePolling)&&window.location.reload()}catch(e){$t(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}},t.ShipAidWidget.styles=vt,yt([h({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),yt([h({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),yt([c()],t.ShipAidWidget.prototype,"_storeDomain",2),yt([c()],t.ShipAidWidget.prototype,"_store",2),yt([c()],t.ShipAidWidget.prototype,"_cart",2),yt([c()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),yt([c()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),yt([c()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),yt([c()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),yt([c()],t.ShipAidWidget.prototype,"_lastAction",2),yt([c()],t.ShipAidWidget.prototype,"_protectionCartItem",2),yt([c()],t.ShipAidWidget.prototype,"_protectionVariant",2),yt([c()],t.ShipAidWidget.prototype,"_state",2),yt([c()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=yt([(t=>e=>{return"function"==typeof e?(i=t,o=e,window.customElements.define(i,o),o):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){window.customElements.define(t,e)}}})(t,e);var i,o})("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({});
338
+ `}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!n.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>e.sku&&this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i,o;return null==(o=null==(i=null==(e=n.product)?void 0:e.variants)?void 0:i.edges)?void 0:o.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?r:[]).reduce(((t,e)=>t+e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(null==(s=n.rules)||!s.length)return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o;const r=null==(e=this._store)?void 0:e.protectionSettings;if(!r||null==(o=null==(i=r.product)?void 0:i.variants)||!o.edges)throw new Error("Missing product and variants from protection settings.");return r.product.variants.edges.flatMap((({node:t})=>{if(!t||!t.price)return[];const e=Number(t.price);return[l(p({},t),{formattedPrice:e})]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)).find((e=>e.formattedPrice>=t))}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const e=await this._fetch.get(t.toString());if(!e)throw new Error(`Failed to fetch store data for ${t.toString()}`);const[i]=e.stores;if(!i)throw new Error(`Could not find a store for this URL ${t.toString()}.`);return i}catch(Y){throw console.error(Y),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(Y){throw $t(Y.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e,i;try{if(!this._store)throw new Error("Store has not been loaded.");if(null==(t=this._cart)||!t.items)throw new Error("Cart has not been loaded.");if(null==(e=this._protectionVariant)||!e.id)throw new Error("No protection variant found.");this._setState("loading");const o={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",o),s=l(p({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),((null==(i=window.Shopify)?void 0:i.Checkout)||!this.disablePolling)&&window.location.reload()}catch(o){$t(o.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var t;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const e={id:this._protectionCartItem.key,quantity:0},i=await this._fetch.post("/cart/change.js",e);this._lastAction="removed",this._dispatchEvent(mt.STATUS_UPDATE,{protection:!1,cart:i,lineItem:this._protectionCartItem}),console.log("updating state"),this._cart=i,this._setState("success"),((null==(t=window.Shopify)?void 0:t.Checkout)||!this.disablePolling)&&(console.log("reloading"),window.location.reload())}catch(e){$t(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}},t.ShipAidWidget.styles=vt,yt([h({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),yt([h({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),yt([c()],t.ShipAidWidget.prototype,"_storeDomain",2),yt([c()],t.ShipAidWidget.prototype,"_store",2),yt([c()],t.ShipAidWidget.prototype,"_cart",2),yt([c()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),yt([c()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),yt([c()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),yt([c()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),yt([c()],t.ShipAidWidget.prototype,"_lastAction",2),yt([c()],t.ShipAidWidget.prototype,"_protectionCartItem",2),yt([c()],t.ShipAidWidget.prototype,"_protectionVariant",2),yt([c()],t.ShipAidWidget.prototype,"_state",2),yt([c()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=yt([(t=>e=>{return"function"==typeof e?(i=t,o=e,window.customElements.define(i,o),o):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){window.customElements.define(t,e)}}})(t,e);var i,o})("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({});
@@ -35,7 +35,7 @@ const f=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShad
35
35
  * Copyright 2017 Google LLC
36
36
  * SPDX-License-Identifier: BSD-3-Clause
37
37
  */
38
- var E;L.finalized=!0,L.elementProperties=new Map,L.elementStyles=[],L.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:L}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const x=globalThis.trustedTypes,P=x?x.createPolicy("lit-html",{createHTML:t=>t}):void 0,T=`lit$${(Math.random()+"").slice(9)}$`,U="?"+T,M=`<${U}>`,k=document,O=(t="")=>k.createComment(t),N=t=>null===t||"object"!=typeof t&&"function"!=typeof t,I=Array.isArray,z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,W=/>/g,R=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,D=/'/g,j=/"/g,F=/^(?:script|style|textarea|title)$/i,B=(Y=1,(t,...e)=>({_$litType$:Y,strings:t,values:e})),V=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),Z=new WeakMap,J=k.createTreeWalker(k,129,null,!1);var Y;class K{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=z;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===z?"!--"===a[1]?n=H:void 0!==a[1]?n=W:void 0!==a[2]?(F.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=R):void 0!==a[3]&&(n=R):n===R?">"===a[0]?(n=null!=r?r:z,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?R:'"'===a[3]?j:D):n===j||n===D?n=R:n===H||n===W?n=z:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===z?e+M:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+T+h):e+T+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==P?P.createHTML(a):a,o]})(t,e);if(this.el=K.createElement(p,i),J.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=J.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(T)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(T),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?et:"?"===e[1]?ot:"@"===e[1]?rt:tt})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(F.test(o.tagName)){const t=o.textContent.split(T),e=t.length-1;if(e>0){o.textContent=x?x.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],O()),J.nextNode(),a.push({type:2,index:++r});o.append(t[e],O())}}}else if(8===o.nodeType)if(o.data===U)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(T,t+1));)a.push({type:7,index:r}),t+=T.length-1}r++}}static createElement(t,e){const i=k.createElement("template");return i.innerHTML=t,i}}function G(t,e,i=t,o){var r,s,n,a;if(e===V)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=N(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=G(t,p._$AS(t,e.values),p,o)),e}class X{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:k).importNode(i,!0);J.currentNode=r;let s=J.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new Q(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new st(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=J.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class Q{constructor(t,e,i,o){var r;this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$Cg=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=G(this,t,e),N(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==V&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>{var e;return I(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==q&&N(this._$AH)?this._$AA.nextSibling.data=t:this.k(k.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=K.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new X(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new K(t)),e}S(t){I(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new Q(this.A(O()),this.A(O()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class tt{constructor(t,e,i,o,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=G(this,t,e,0),s=!N(t)||t!==this._$AH&&t!==V,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=G(this,o[i+n],e,n),a===V&&(a=this._$AH[n]),s||(s=!N(a)||a!==this._$AH[n]),a===q?t=q:t!==q&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.C(t)}C(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class et extends tt{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===q?void 0:t}}const it=x?x.emptyScript:"";class ot extends tt{constructor(){super(...arguments),this.type=4}C(t){t&&t!==q?this.element.setAttribute(this.name,it):this.element.removeAttribute(this.name)}}class rt extends tt{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=G(this,t,e,0))&&void 0!==i?i:q)===V)return;const o=this._$AH,r=t===q&&o!==q||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==q&&(o===q||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class st{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){G(this,t)}}const nt=window.litHtmlPolyfillSupport;
38
+ var E;L.finalized=!0,L.elementProperties=new Map,L.elementStyles=[],L.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:L}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const x=globalThis.trustedTypes,P=x?x.createPolicy("lit-html",{createHTML:t=>t}):void 0,T=`lit$${(Math.random()+"").slice(9)}$`,U="?"+T,k=`<${U}>`,M=document,O=(t="")=>M.createComment(t),I=t=>null===t||"object"!=typeof t&&"function"!=typeof t,N=Array.isArray,z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,W=/>/g,R=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,D=/'/g,j=/"/g,F=/^(?:script|style|textarea|title)$/i,B=(Y=1,(t,...e)=>({_$litType$:Y,strings:t,values:e})),V=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),Z=new WeakMap,J=M.createTreeWalker(M,129,null,!1);var Y;class K{constructor({strings:t,_$litType$:e},i){let o;this.parts=[];let r=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,o=[];let r,s=2===e?"<svg>":"",n=z;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===z?"!--"===a[1]?n=H:void 0!==a[1]?n=W:void 0!==a[2]?(F.test(a[2])&&(r=RegExp("</"+a[2],"g")),n=R):void 0!==a[3]&&(n=R):n===R?">"===a[0]?(n=null!=r?r:z,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?R:'"'===a[3]?j:D):n===j||n===D?n=R:n===H||n===W?n=z:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===z?e+k:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+T+h):e+T+(-2===l?(o.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==P?P.createHTML(a):a,o]})(t,e);if(this.el=K.createElement(p,i),J.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=J.nextNode())&&a.length<n;){if(1===o.nodeType){if(o.hasAttributes()){const t=[];for(const e of o.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(T)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(T),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:r,name:e[2],strings:t,ctor:"."===e[1]?et:"?"===e[1]?ot:"@"===e[1]?rt:tt})}else a.push({type:6,index:r})}for(const e of t)o.removeAttribute(e)}if(F.test(o.tagName)){const t=o.textContent.split(T),e=t.length-1;if(e>0){o.textContent=x?x.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],O()),J.nextNode(),a.push({type:2,index:++r});o.append(t[e],O())}}}else if(8===o.nodeType)if(o.data===U)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(T,t+1));)a.push({type:7,index:r}),t+=T.length-1}r++}}static createElement(t,e){const i=M.createElement("template");return i.innerHTML=t,i}}function G(t,e,i=t,o){var r,s,n,a;if(e===V)return e;let p=void 0!==o?null===(r=i._$Cl)||void 0===r?void 0:r[o]:i._$Cu;const l=I(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,o)),void 0!==o?(null!==(n=(a=i)._$Cl)&&void 0!==n?n:a._$Cl=[])[o]=p:i._$Cu=p),void 0!==p&&(e=G(t,p._$AS(t,e.values),p,o)),e}class X{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:o}=this._$AD,r=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:M).importNode(i,!0);J.currentNode=r;let s=J.nextNode(),n=0,a=0,p=o[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new Q(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new st(s,this,t)),this.v.push(e),p=o[++a]}n!==(null==p?void 0:p.index)&&(s=J.nextNode(),n++)}return r}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class Q{constructor(t,e,i,o){var r;this.type=2,this._$AH=q,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=o,this._$Cg=null===(r=null==o?void 0:o.isConnected)||void 0===r||r}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=G(this,t,e),I(t)?t===q||null==t||""===t?(this._$AH!==q&&this._$AR(),this._$AH=q):t!==this._$AH&&t!==V&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):(t=>{var e;return N(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==q&&I(this._$AH)?this._$AA.nextSibling.data=t:this.k(M.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:o}=t,r="number"==typeof o?this._$AC(t):(void 0===o.el&&(o.el=K.createElement(o.h,this.options)),o);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new X(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new K(t)),e}S(t){N(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,o=0;for(const r of t)o===e.length?e.push(i=new Q(this.A(O()),this.A(O()),this,this.options)):i=e[o],i._$AI(r),o++;o<e.length&&(this._$AR(i&&i._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class tt{constructor(t,e,i,o,r){this.type=1,this._$AH=q,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,o){const r=this.strings;let s=!1;if(void 0===r)t=G(this,t,e,0),s=!I(t)||t!==this._$AH&&t!==V,s&&(this._$AH=t);else{const o=t;let n,a;for(t=r[0],n=0;n<r.length-1;n++)a=G(this,o[i+n],e,n),a===V&&(a=this._$AH[n]),s||(s=!I(a)||a!==this._$AH[n]),a===q?t=q:t!==q&&(t+=(null!=a?a:"")+r[n+1]),this._$AH[n]=a}s&&!o&&this.C(t)}C(t){t===q?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class et extends tt{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===q?void 0:t}}const it=x?x.emptyScript:"";class ot extends tt{constructor(){super(...arguments),this.type=4}C(t){t&&t!==q?this.element.setAttribute(this.name,it):this.element.removeAttribute(this.name)}}class rt extends tt{constructor(t,e,i,o,r){super(t,e,i,o,r),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=G(this,t,e,0))&&void 0!==i?i:q)===V)return;const o=this._$AH,r=t===q&&o!==q||t.capture!==o.capture||t.once!==o.once||t.passive!==o.passive,s=t!==q&&(o===q||r);r&&this.element.removeEventListener(this.name,this,o),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class st{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){G(this,t)}}const nt=window.litHtmlPolyfillSupport;
39
39
  /**
40
40
  * @license
41
41
  * Copyright 2017 Google LLC
@@ -284,7 +284,7 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
284
284
  color: var(--shipaid-text-grey);
285
285
  font-weight: var(--shipaid-font-heavy);
286
286
  }
287
- `,mt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(mt||{}),gt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?_t(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&gt(e,i,s),s};const Ct=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},wt=t=>console.warn(`[ShipAid] ${t}`),$t=t=>console.error(`[ShipAid] ${t}`),At="shipaid-protection";t.ShipAidWidget=class extends lt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>Ct(t),post:(t,e)=>Ct(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var t;((t,e)=>{ut(t,e,[])})(this,(async()=>{var t,e,i,o;const r=document.createElement("link");r.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),r.setAttribute("rel","stylesheet"),document.head.appendChild(r);try{const t=localStorage.getItem(At),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch{wt("Failed to parse local storage.")}try{const[t,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return null!=(e=null==(t=this._store)?void 0:t.plan)&&e.active?null!=(o=null==(i=this._store)?void 0:i.protectionSettings)&&o.protectionType?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(mt.LOADED,this._store),setTimeout((async()=>{var t;const e=localStorage.getItem(At),{lastAction:i}=e?JSON.parse(e):{};"removed"!==i&&!this._hasProtectionInCart&&(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(!this.disablePolling&&setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(wt("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(wt("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),ut(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(At,JSON.stringify(t))}),[this._lastAction]),ut(this,(async()=>{var t,e,i,o,r;if(this._cartLastUpdated=new Date,null==(t=this._cart)||!t.items)return;const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,null==n||!n.id)return this._shouldShowWidget=!1,void $t("No matching protection variant found.");const a=null!=(i=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i,o,r,s;return null==(s=null==(r=null==(o=null==(i=null==(e=this._store)?void 0:e.protectionSettings)?void 0:i.product)?void 0:o.variants)?void 0:r.edges)?void 0:s.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?i:[],d=null==(o=this._cart)?void 0:o.items[a];if(this._hasProtectionInCart=!!d,!d)return;if(null!=(r=n.id)&&r.includes(d.id.toString()))return void(this._protectionCartItem=l(p({},d),{index:a,position:a+1}));const h={id:d.key,quantity:0};await this._fetch.post("/cart/change.js",h);const c={id:n.id.replace("gid://shopify/ProductVariant/",""),quantity:1},u=await this._fetch.post("/cart/add.js",c),f=l(p({},this._cart),{items:[u,...this._cart.items]});this._cart=f,this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:f,lineItem:u}),this.disablePolling||window.location.reload()}),[this._store,this._cart]);const e=B`
287
+ `,mt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(mt||{}),gt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,yt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?_t(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&gt(e,i,s),s};const Ct=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},wt=t=>console.warn(`[ShipAid] ${t}`),$t=t=>console.error(`[ShipAid] ${t}`),At="shipaid-protection";t.ShipAidWidget=class extends lt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>Ct(t),post:(t,e)=>Ct(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var t;((t,e)=>{ut(t,e,[])})(this,(async()=>{var t,e,i,o;const r=document.createElement("link");r.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),r.setAttribute("rel","stylesheet"),document.head.appendChild(r);try{const t=localStorage.getItem(At),{lastAction:e}=t?JSON.parse(t):{};e&&(this._lastAction=e)}catch{wt("Failed to parse local storage.")}try{const[t,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return null!=(e=null==(t=this._store)?void 0:t.plan)&&e.active?null!=(o=null==(i=this._store)?void 0:i.protectionSettings)&&o.protectionType?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(mt.LOADED,this._store),setTimeout((async()=>{var t;const e=localStorage.getItem(At),{lastAction:i}=e?JSON.parse(e):{};"removed"!==i&&!this._hasProtectionInCart&&(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&this._store.widgetShowCart&&await this.addProtection()}),500),void(!this.disablePolling&&setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(wt("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(wt("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),ut(this,(()=>{const t={hasProtection:this._hasProtectionInCart,lastAction:this._lastAction};localStorage.setItem(At,JSON.stringify(t))}),[this._lastAction]),ut(this,(async()=>{var t,e,i,o,r;if(this._cartLastUpdated=new Date,null==(t=this._cart)||!t.items)return;const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,null==n||!n.id)return this._shouldShowWidget=!1,void $t("No matching protection variant found.");const a=null!=(i=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i,o,r,s;return null==(s=null==(r=null==(o=null==(i=null==(e=this._store)?void 0:e.protectionSettings)?void 0:i.product)?void 0:o.variants)?void 0:r.edges)?void 0:s.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?i:[],d=null==(o=this._cart)?void 0:o.items[a];if(this._hasProtectionInCart=!!d,!d)return;if(console.log({protectionVariant:n,protectionCartItem:d}),null==(r=n.id)?void 0:r.includes(d.id.toString()))return void(this._protectionCartItem=l(p({},d),{index:a,position:a+1}));console.log("running update checks");const h={id:d.key,quantity:0};await this._fetch.post("/cart/change.js",h);const c={id:n.id.replace("gid://shopify/ProductVariant/",""),quantity:1},u=await this._fetch.post("/cart/add.js",c),f=l(p({},this._cart),{items:[u,...this._cart.items]});this._cart=f,this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:f,lineItem:u}),this.disablePolling||window.location.reload()}),[this._store,this._cart]);const e=B`
288
288
  <div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
289
289
  <div class="popup">
290
290
  <button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
@@ -335,4 +335,4 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
335
335
  <div class="shipaid">
336
336
  ${ft(this._hasFinishedSetup,(()=>{var t,o;return ft(this._shouldShowWidget&&(null==(o=null==(t=this._store)?void 0:t.plan)?void 0:o.active)&&this._store.widgetShowCart,(()=>[e,i]),(()=>B``))}),(()=>B`<p><slot>Loading ShipAid Widget...</slot></p>`))}
337
337
  </div>
338
- `}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!n.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>e.sku&&this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i,o;return null==(o=null==(i=null==(e=n.product)?void 0:e.variants)?void 0:i.edges)?void 0:o.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?r:[]).reduce(((t,e)=>t+e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(null==(s=n.rules)||!s.length)return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o;const r=null==(e=this._store)?void 0:e.protectionSettings;if(!r||null==(o=null==(i=r.product)?void 0:i.variants)||!o.edges)throw new Error("Missing product and variants from protection settings.");return r.product.variants.edges.flatMap((({node:t})=>{if(!t||!t.price)return[];const e=Number(t.price);return[l(p({},t),{formattedPrice:e})]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)).find((e=>e.formattedPrice>=t))}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const e=await this._fetch.get(t.toString());if(!e)throw new Error(`Failed to fetch store data for ${t.toString()}`);const[i]=e.stores;if(!i)throw new Error(`Could not find a store for this URL ${t.toString()}.`);return i}catch(Y){throw console.error(Y),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(Y){throw $t(Y.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e,i;try{if(!this._store)throw new Error("Store has not been loaded.");if(null==(t=this._cart)||!t.items)throw new Error("Cart has not been loaded.");if(null==(e=this._protectionVariant)||!e.id)throw new Error("No protection variant found.");this._setState("loading");const o={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",o),s=l(p({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),((null==(i=window.Shopify)?void 0:i.Checkout)||!this.disablePolling)&&window.location.reload()}catch(o){$t(o.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var t;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const e={id:this._protectionCartItem.key,quantity:0},i=await this._fetch.post("/cart/change.js",e);this._lastAction="removed",this._dispatchEvent(mt.STATUS_UPDATE,{protection:!1,cart:i,lineItem:this._protectionCartItem}),this._cart=i,this._setState("success"),((null==(t=window.Shopify)?void 0:t.Checkout)||!this.disablePolling)&&window.location.reload()}catch(e){$t(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}},t.ShipAidWidget.styles=vt,yt([h({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),yt([h({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),yt([c()],t.ShipAidWidget.prototype,"_storeDomain",2),yt([c()],t.ShipAidWidget.prototype,"_store",2),yt([c()],t.ShipAidWidget.prototype,"_cart",2),yt([c()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),yt([c()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),yt([c()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),yt([c()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),yt([c()],t.ShipAidWidget.prototype,"_lastAction",2),yt([c()],t.ShipAidWidget.prototype,"_protectionCartItem",2),yt([c()],t.ShipAidWidget.prototype,"_protectionVariant",2),yt([c()],t.ShipAidWidget.prototype,"_state",2),yt([c()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=yt([(t=>e=>{return"function"==typeof e?(i=t,o=e,window.customElements.define(i,o),o):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){window.customElements.define(t,e)}}})(t,e);var i,o})("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
338
+ `}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!n.product)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>e.sku&&this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i,o;return null==(o=null==(i=null==(e=n.product)?void 0:e.variants)?void 0:i.edges)?void 0:o.some((({node:e})=>{var i;return null==(i=null==e?void 0:e.id)?void 0:i.includes(t.variant_id.toString())}))})))?r:[]).reduce(((t,e)=>t+e.final_line_price),0);if("FIXED"===n.protectionType){if(!n.defaultFee)throw new Error("Missing default fee amount.");if(null==(s=n.rules)||!s.length)return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o;const r=null==(e=this._store)?void 0:e.protectionSettings;if(!r||null==(o=null==(i=r.product)?void 0:i.variants)||!o.edges)throw new Error("Missing product and variants from protection settings.");return r.product.variants.edges.flatMap((({node:t})=>{if(!t||!t.price)return[];const e=Number(t.price);return[l(p({},t),{formattedPrice:e})]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)).find((e=>e.formattedPrice>=t))}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const e=await this._fetch.get(t.toString());if(!e)throw new Error(`Failed to fetch store data for ${t.toString()}`);const[i]=e.stores;if(!i)throw new Error(`Could not find a store for this URL ${t.toString()}.`);return i}catch(Y){throw console.error(Y),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(Y){throw $t(Y.message),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e,i;try{if(!this._store)throw new Error("Store has not been loaded.");if(null==(t=this._cart)||!t.items)throw new Error("Cart has not been loaded.");if(null==(e=this._protectionVariant)||!e.id)throw new Error("No protection variant found.");this._setState("loading");const o={id:this._protectionVariant.id.replace("gid://shopify/ProductVariant/",""),quantity:1},r=await this._fetch.post("/cart/add.js",o),s=l(p({},this._cart),{items:[r,...this._cart.items]});this._cart=s,this._lastAction="added",this._setState("success"),this._dispatchEvent(mt.STATUS_UPDATE,{protection:!0,cart:s,lineItem:r}),((null==(i=window.Shopify)?void 0:i.Checkout)||!this.disablePolling)&&window.location.reload()}catch(o){$t(o.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var t;try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const e={id:this._protectionCartItem.key,quantity:0},i=await this._fetch.post("/cart/change.js",e);this._lastAction="removed",this._dispatchEvent(mt.STATUS_UPDATE,{protection:!1,cart:i,lineItem:this._protectionCartItem}),console.log("updating state"),this._cart=i,this._setState("success"),((null==(t=window.Shopify)?void 0:t.Checkout)||!this.disablePolling)&&(console.log("reloading"),window.location.reload())}catch(e){$t(e.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}},t.ShipAidWidget.styles=vt,yt([h({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),yt([h({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),yt([c()],t.ShipAidWidget.prototype,"_storeDomain",2),yt([c()],t.ShipAidWidget.prototype,"_store",2),yt([c()],t.ShipAidWidget.prototype,"_cart",2),yt([c()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),yt([c()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),yt([c()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),yt([c()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),yt([c()],t.ShipAidWidget.prototype,"_lastAction",2),yt([c()],t.ShipAidWidget.prototype,"_protectionCartItem",2),yt([c()],t.ShipAidWidget.prototype,"_protectionVariant",2),yt([c()],t.ShipAidWidget.prototype,"_state",2),yt([c()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=yt([(t=>e=>{return"function"==typeof e?(i=t,o=e,window.customElements.define(i,o),o):((t,e)=>{const{kind:i,elements:o}=e;return{kind:i,elements:o,finisher(e){window.customElements.define(t,e)}}})(t,e);var i,o})("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ui.shipaid.com",
3
3
  "private": false,
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "main": "dist/ui.shipaid.com.umd.js",
6
6
  "unpkg": "dist/ui.shipaid.com.iife.js",
7
7
  "module": "dist/ui.shipaid.com.es.js",