ui.shipaid.com 0.1.6 → 0.1.7
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.
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var xt=Object.defineProperty,Ct=Object.defineProperties;var Pt=Object.getOwnPropertyDescriptors;var
|
|
1
|
+
var xt=Object.defineProperty,Ct=Object.defineProperties;var Pt=Object.getOwnPropertyDescriptors;var st=Object.getOwnPropertySymbols;var Tt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var rt=(o,t,e)=>t in o?xt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,b=(o,t)=>{for(var e in t||(t={}))Tt.call(t,e)&&rt(o,e,t[e]);if(st)for(var e of st(t))Ut.call(t,e)&&rt(o,e,t[e]);return o},A=(o,t)=>Ct(o,Pt(t));/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2017 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/const kt=o=>t=>typeof t=="function"?((e,i)=>(window.customElements.define(e,i),i))(o,t):((e,i)=>{const{kind:
|
|
5
|
+
*/const kt=o=>t=>typeof t=="function"?((e,i)=>(window.customElements.define(e,i),i))(o,t):((e,i)=>{const{kind:s,elements:r}=i;return{kind:s,elements:r,finisher(n){window.customElements.define(e,n)}}})(o,t);/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const Nt=(o,t)=>t.kind==="method"&&t.descriptor&&!("value"in t.descriptor)?A(b({},t),{finisher(e){e.createProperty(t.key,o)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:t.key,initializer(){typeof t.initializer=="function"&&(this[t.key]=t.initializer.call(this))},finisher(e){e.createProperty(t.key,o)}};function
|
|
9
|
+
*/const Nt=(o,t)=>t.kind==="method"&&t.descriptor&&!("value"in t.descriptor)?A(b({},t),{finisher(e){e.createProperty(t.key,o)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:t.key,initializer(){typeof t.initializer=="function"&&(this[t.key]=t.initializer.call(this))},finisher(e){e.createProperty(t.key,o)}};function F(o){return(t,e)=>e!==void 0?((i,s,r)=>{s.constructor.createProperty(r,i)})(o,t,e):Nt(o,t)}/**
|
|
10
10
|
* @license
|
|
11
11
|
* Copyright 2017 Google LLC
|
|
12
12
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
13
|
-
*/function
|
|
13
|
+
*/function g(o){return F(A(b({},o),{state:!0}))}/**
|
|
14
14
|
* @license
|
|
15
15
|
* Copyright 2021 Google LLC
|
|
16
16
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
17
|
-
*/var
|
|
17
|
+
*/var j;((j=window.HTMLSlotElement)===null||j===void 0?void 0:j.prototype.assignedElements)!=null;/**
|
|
18
18
|
* @license
|
|
19
19
|
* Copyright 2019 Google LLC
|
|
20
20
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
21
|
-
*/const
|
|
21
|
+
*/const W=window.ShadowRoot&&(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,V=Symbol(),nt=new Map;class at{constructor(t,e){if(this._$cssResult$=!0,e!==V)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=nt.get(this.cssText);return W&&t===void 0&&(nt.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const It=o=>new at(typeof o=="string"?o:o+"",V),Ot=(o,...t)=>{const e=o.length===1?o[0]:t.reduce((i,s,r)=>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.")})(s)+o[r+1],o[0]);return new at(e,V)},Ht=(o,t)=>{W?o.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet):t.forEach(e=>{const i=document.createElement("style"),s=window.litNonce;s!==void 0&&i.setAttribute("nonce",s),i.textContent=e.cssText,o.appendChild(i)})},pt=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
|
|
25
|
-
*/var
|
|
25
|
+
*/var B;const ht=window.trustedTypes,Lt=ht?ht.emptyScript:"",dt=window.reactiveElementPolyfillSupport,q={toAttribute(o,t){switch(t){case Boolean:o=o?Lt:null;break;case Object:case Array:o=o==null?o:JSON.stringify(o)}return o},fromAttribute(o,t){let e=o;switch(t){case Boolean:e=o!==null;break;case Number:e=o===null?null:Number(o);break;case Object:case Array:try{e=JSON.parse(o)}catch{e=null}}return e}},lt=(o,t)=>t!==o&&(t==t||o==o),J={attribute:!0,type:String,converter:q,reflect:!1,hasChanged:lt};class E extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;(e=this.l)!==null&&e!==void 0||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach((e,i)=>{const s=this._$Eh(i,e);s!==void 0&&(this._$Eu.set(s,i),t.push(s))}),t}static createProperty(t,e=J){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i=typeof t=="symbol"?Symbol():"__"+t,s=this.getPropertyDescriptor(t,i,e);s!==void 0&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(s){const r=this[t];this[e]=s,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||J}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const e=this.properties,i=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const s of i)this.createProperty(s,e[s])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const s of i)e.unshift(pt(s))}else t!==void 0&&e.push(pt(t));return e}static _$Eh(t,e){const i=e.attribute;return i===!1?void 0:typeof i=="string"?i:typeof t=="string"?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$Em(),this.requestUpdate(),(t=this.constructor.l)===null||t===void 0||t.forEach(e=>e(this))}addController(t){var e,i;((e=this._$Eg)!==null&&e!==void 0?e:this._$Eg=[]).push(t),this.renderRoot!==void 0&&this.isConnected&&((i=t.hostConnected)===null||i===void 0||i.call(t))}removeController(t){var e;(e=this._$Eg)===null||e===void 0||e.splice(this._$Eg.indexOf(t)>>>0,1)}_$Em(){this.constructor.elementProperties.forEach((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])})}createRenderRoot(){var t;const e=(t=this.shadowRoot)!==null&&t!==void 0?t:this.attachShadow(this.constructor.shadowRootOptions);return Ht(e,this.constructor.elementStyles),e}connectedCallback(){var t;this.renderRoot===void 0&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$Eg)===null||t===void 0||t.forEach(e=>{var i;return(i=e.hostConnected)===null||i===void 0?void 0:i.call(e)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$Eg)===null||t===void 0||t.forEach(e=>{var i;return(i=e.hostDisconnected)===null||i===void 0?void 0:i.call(e)})}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$ES(t,e,i=J){var s,r;const n=this.constructor._$Eh(t,i);if(n!==void 0&&i.reflect===!0){const l=((r=(s=i.converter)===null||s===void 0?void 0:s.toAttribute)!==null&&r!==void 0?r:q.toAttribute)(e,i.type);this._$Ei=t,l==null?this.removeAttribute(n):this.setAttribute(n,l),this._$Ei=null}}_$AK(t,e){var i,s,r;const n=this.constructor,l=n._$Eu.get(t);if(l!==void 0&&this._$Ei!==l){const a=n.getPropertyOptions(l),p=a.converter,c=(r=(s=(i=p)===null||i===void 0?void 0:i.fromAttribute)!==null&&s!==void 0?s:typeof p=="function"?p:null)!==null&&r!==void 0?r:q.fromAttribute;this._$Ei=l,this[l]=c(e,a.type),this._$Ei=null}}requestUpdate(t,e,i){let s=!0;t!==void 0&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||lt)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),i.reflect===!0&&this._$Ei!==t&&(this._$EC===void 0&&(this._$EC=new Map),this._$EC.set(t,i))):s=!1),!this.isUpdatePending&&s&&(this._$Ep=this._$E_())}async _$E_(){this.isUpdatePending=!0;try{await this._$Ep}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach((s,r)=>this[r]=s),this._$Et=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),(t=this._$Eg)===null||t===void 0||t.forEach(s=>{var r;return(r=s.hostUpdate)===null||r===void 0?void 0:r.call(s)}),this.update(i)):this._$EU()}catch(s){throw e=!1,this._$EU(),s}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;(e=this._$Eg)===null||e===void 0||e.forEach(i=>{var s;return(s=i.hostUpdated)===null||s===void 0?void 0:s.call(i)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return!0}update(t){this._$EC!==void 0&&(this._$EC.forEach((e,i)=>this._$ES(i,this[i],e)),this._$EC=void 0),this._$EU()}updated(t){}firstUpdated(t){}}E.finalized=!0,E.elementProperties=new Map,E.elementStyles=[],E.shadowRootOptions={mode:"open"},dt==null||dt({ReactiveElement:E}),((B=globalThis.reactiveElementVersions)!==null&&B!==void 0?B:globalThis.reactiveElementVersions=[]).push("1.3.0");/**
|
|
26
26
|
* @license
|
|
27
27
|
* Copyright 2017 Google LLC
|
|
28
28
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
29
|
-
*/var K;const x=globalThis.trustedTypes,
|
|
29
|
+
*/var K;const x=globalThis.trustedTypes,ct=x?x.createPolicy("lit-html",{createHTML:o=>o}):void 0,w=`lit$${(Math.random()+"").slice(9)}$`,ut="?"+w,Mt=`<${ut}>`,C=document,N=(o="")=>C.createComment(o),I=o=>o===null||typeof o!="object"&&typeof o!="function",ft=Array.isArray,zt=o=>{var t;return ft(o)||typeof((t=o)===null||t===void 0?void 0:t[Symbol.iterator])=="function"},O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,mt=/-->/g,vt=/>/g,S=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,_t=/'/g,gt=/"/g,yt=/^(?:script|style|textarea|title)$/i,Dt=o=>(t,...e)=>({_$litType$:o,strings:t,values:e}),P=Dt(1),T=Symbol.for("lit-noChange"),f=Symbol.for("lit-nothing"),$t=new WeakMap,Rt=(o,t,e)=>{var i,s;const r=(i=e==null?void 0:e.renderBefore)!==null&&i!==void 0?i:t;let n=r._$litPart$;if(n===void 0){const l=(s=e==null?void 0:e.renderBefore)!==null&&s!==void 0?s:null;r._$litPart$=n=new z(t.insertBefore(N(),l),l,void 0,e!=null?e:{})}return n._$AI(o),n},U=C.createTreeWalker(C,129,null,!1),Ft=(o,t)=>{const e=o.length-1,i=[];let s,r=t===2?"<svg>":"",n=O;for(let a=0;a<e;a++){const p=o[a];let c,h,d=-1,u=0;for(;u<p.length&&(n.lastIndex=u,h=n.exec(p),h!==null);)u=n.lastIndex,n===O?h[1]==="!--"?n=mt:h[1]!==void 0?n=vt:h[2]!==void 0?(yt.test(h[2])&&(s=RegExp("</"+h[2],"g")),n=S):h[3]!==void 0&&(n=S):n===S?h[0]===">"?(n=s!=null?s:O,d=-1):h[1]===void 0?d=-2:(d=n.lastIndex-h[2].length,c=h[1],n=h[3]===void 0?S:h[3]==='"'?gt:_t):n===gt||n===_t?n=S:n===mt||n===vt?n=O:(n=S,s=void 0);const _=n===S&&o[a+1].startsWith("/>")?" ":"";r+=n===O?p+Mt:d>=0?(i.push(c),p.slice(0,d)+"$lit$"+p.slice(d)+w+_):p+w+(d===-2?(i.push(void 0),a):_)}const l=r+(o[e]||"<?>")+(t===2?"</svg>":"");if(!Array.isArray(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return[ct!==void 0?ct.createHTML(l):l,i]};class M{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let r=0,n=0;const l=t.length-1,a=this.parts,[p,c]=Ft(t,e);if(this.el=M.createElement(p,i),U.currentNode=this.el.content,e===2){const h=this.el.content,d=h.firstChild;d.remove(),h.append(...d.childNodes)}for(;(s=U.nextNode())!==null&&a.length<l;){if(s.nodeType===1){if(s.hasAttributes()){const h=[];for(const d of s.getAttributeNames())if(d.endsWith("$lit$")||d.startsWith(w)){const u=c[n++];if(h.push(d),u!==void 0){const _=s.getAttribute(u.toLowerCase()+"$lit$").split(w),y=/([.?@])?(.*)/.exec(u);a.push({type:1,index:r,name:y[2],strings:_,ctor:y[1]==="."?Wt:y[1]==="?"?Bt:y[1]==="@"?qt:D})}else a.push({type:6,index:r})}for(const d of h)s.removeAttribute(d)}if(yt.test(s.tagName)){const h=s.textContent.split(w),d=h.length-1;if(d>0){s.textContent=x?x.emptyScript:"";for(let u=0;u<d;u++)s.append(h[u],N()),U.nextNode(),a.push({type:2,index:++r});s.append(h[d],N())}}}else if(s.nodeType===8)if(s.data===ut)a.push({type:2,index:r});else{let h=-1;for(;(h=s.data.indexOf(w,h+1))!==-1;)a.push({type:7,index:r}),h+=w.length-1}r++}}static createElement(t,e){const i=C.createElement("template");return i.innerHTML=t,i}}function k(o,t,e=o,i){var s,r,n,l;if(t===T)return t;let a=i!==void 0?(s=e._$Cl)===null||s===void 0?void 0:s[i]:e._$Cu;const p=I(t)?void 0:t._$litDirective$;return(a==null?void 0:a.constructor)!==p&&((r=a==null?void 0:a._$AO)===null||r===void 0||r.call(a,!1),p===void 0?a=void 0:(a=new p(o),a._$AT(o,e,i)),i!==void 0?((n=(l=e)._$Cl)!==null&&n!==void 0?n:l._$Cl=[])[i]=a:e._$Cu=a),a!==void 0&&(t=k(o,a._$AS(o,t.values),a,i)),t}class jt{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:s}=this._$AD,r=((e=t==null?void 0:t.creationScope)!==null&&e!==void 0?e:C).importNode(i,!0);U.currentNode=r;let n=U.nextNode(),l=0,a=0,p=s[0];for(;p!==void 0;){if(l===p.index){let c;p.type===2?c=new z(n,n.nextSibling,this,t):p.type===1?c=new p.ctor(n,p.name,p.strings,this,t):p.type===6&&(c=new Jt(n,this,t)),this.v.push(c),p=s[++a]}l!==(p==null?void 0:p.index)&&(n=U.nextNode(),l++)}return r}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 z{constructor(t,e,i,s){var r;this.type=2,this._$AH=f,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cg=(r=s==null?void 0:s.isConnected)===null||r===void 0||r}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),I(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):zt(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&&I(this._$AH)?this._$AA.nextSibling.data=t:this.k(C.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:s}=t,r=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=M.createElement(s.h,this.options)),s);if(((e=this._$AH)===null||e===void 0?void 0:e._$AD)===r)this._$AH.m(i);else{const n=new jt(r,this),l=n.p(this.options);n.m(i),this.k(l),this._$AH=n}}_$AC(t){let e=$t.get(t.strings);return e===void 0&&$t.set(t.strings,e=new M(t)),e}S(t){ft(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const r of t)s===e.length?e.push(i=new z(this.A(N()),this.A(N()),this,this.options)):i=e[s],i._$AI(r),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$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 s=t.nextSibling;t.remove(),t=s}}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,s,r){this.type=1,this._$AH=f,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=r,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,s){const r=this.strings;let n=!1;if(r===void 0)t=k(this,t,e,0),n=!I(t)||t!==this._$AH&&t!==T,n&&(this._$AH=t);else{const l=t;let a,p;for(t=r[0],a=0;a<r.length-1;a++)p=k(this,l[i+a],e,a),p===T&&(p=this._$AH[a]),n||(n=!I(p)||p!==this._$AH[a]),p===f?t=f:t!==f&&(t+=(p!=null?p:"")+r[a+1]),this._$AH[a]=p}n&&!s&&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 Vt=x?x.emptyScript:"";class Bt extends D{constructor(){super(...arguments),this.type=4}C(t){t&&t!==f?this.element.setAttribute(this.name,Vt):this.element.removeAttribute(this.name)}}class qt extends D{constructor(t,e,i,s,r){super(t,e,i,s,r),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 s=this._$AH,r=t===f&&s!==f||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==f&&(s===f||r);r&&this.element.removeEventListener(this.name,this,s),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 Jt{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 wt=window.litHtmlPolyfillSupport;wt==null||wt(M,z),((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
|
|
33
|
-
*/var Y,Z;class H extends
|
|
33
|
+
*/var Y,Z;class H extends E{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return(t=(e=this.renderOptions).renderBefore)!==null&&t!==void 0||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=Rt(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),(t=this._$Dt)===null||t===void 0||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),(t=this._$Dt)===null||t===void 0||t.setConnected(!1)}render(){return T}}H.finalized=!0,H._$litElement$=!0,(Y=globalThis.litElementHydrateSupport)===null||Y===void 0||Y.call(globalThis,{LitElement:H});const bt=globalThis.litElementPolyfillSupport;bt==null||bt({LitElement:H}),((Z=globalThis.litElementVersions)!==null&&Z!==void 0?Z:globalThis.litElementVersions=[]).push("3.2.0");function Kt(o){if(!o.dispatchEvent||!o.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return o}const $="__registered_effects";function Yt(o){const t=o;if(t[$])return t;const e=Kt(o),i=e.updated;return t[$]={index:0,count:0,effects:[]},e.updated=s=>(t[$].index=0,i(s)),t}function Zt(o,t){const e=Yt(o),{index:i,count:s}=e[$];return i===s?(e[$].index++,e[$].count++,e[$].effects.push(t),t):(e[$].index++,e[$].effects[i])}function At(o,t,e){const i=Zt(o,{on:t,observe:["__initial__dirty"]});i.observe.some((s,r)=>e[r]!==s)&&i.on(),i.observe=e}const Gt=(o,t)=>At(o,t,[]);/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2021 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -272,7 +272,7 @@ var xt=Object.defineProperty,Ct=Object.defineProperties;var Pt=Object.getOwnProp
|
|
|
272
272
|
color: var(--shipaid-text-grey);
|
|
273
273
|
font-weight: var(--shipaid-font-heavy);
|
|
274
274
|
}
|
|
275
|
-
`,L=(o=>(o.LOADED="shipaid-loaded",o.STATUS_UPDATE="shipaid-protection-status",o))(L||{}),Qt=Object.defineProperty,te=Object.getOwnPropertyDescriptor,v=(o,t,e,i)=>{for(var
|
|
275
|
+
`,L=(o=>(o.LOADED="shipaid-loaded",o.STATUS_UPDATE="shipaid-protection-status",o))(L||{}),Qt=Object.defineProperty,te=Object.getOwnPropertyDescriptor,v=(o,t,e,i)=>{for(var s=i>1?void 0:i?te(t,e):t,r=o.length-1,n;r>=0;r--)(n=o[r])&&(s=(i?n(t,e,s):n(s))||s);return i&&s&&Qt(t,e,s),s};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.")}},ee=2500;let m=class extends H{constructor(){super(...arguments);var o;this.disablePolling=!1,this.pollingInterval=ee,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;Gt(this,async()=>{var s,r,n,l;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,p]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=a,this._cart=p}catch{this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((r=(s=this._store)==null?void 0:s.plan)!=null&&r.active)){console.warn("No ShipAid plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}if(!((l=(n=this._store)==null?void 0:n.protectionSettings)!=null&&l.protectionType)){console.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,this._shouldShowWidget=!1;return}this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(L.LOADED,this._store),setTimeout(async()=>{var a;!this._hasProtectionInCart&&((a=this._store)==null?void 0:a.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)}),At(this,async()=>{var h,d,u,_,y;if(this._cartLastUpdated=new Date,!((h=this._cart)!=null&&h.items))return;const i=await this.calculateProtectionTotal(this._cart),s=this._findProtectionVariant(i);if(this._protectionVariant=s,!(s!=null&&s.id)){this._shouldShowWidget=!1,console.error("No matching protection variant found.");return}const r=(u=(d=this._cart.items)==null?void 0:d.findIndex(Et=>{var X,Q,tt,et,it;return(it=(et=(tt=(Q=(X=this._store)==null?void 0:X.protectionSettings)==null?void 0:Q.product)==null?void 0:tt.variants)==null?void 0:et.edges)==null?void 0:it.some(({node:R})=>{var ot;return(ot=R==null?void 0:R.id)==null?void 0:ot.includes(Et.variant_id.toString())})}))!=null?u:[],n=(_=this._cart)==null?void 0:_.items[r];if(this._hasProtectionInCart=!!n,!n)return;if((y=s.id)!=null&&y.includes(n.id.toString())){this._protectionCartItem=A(b({},n),{index:r,position:r+1});return}const l={id:n.key,quantity:0};await this._fetch.post("/cart/change.js",l);const a={id:s.id.replace("gid://shopify/ProductVariant/",""),quantity:1},p=await this._fetch.post("/cart/add.js",a),c=A(b({},this._cart),{items:[p,...this._cart.items]});this._cart=c,this._dispatchEvent(L.STATUS_UPDATE,{protection:!0,cart:c,lineItem:p}),this.disablePolling||window.location.reload()},[this._store,this._cart]);const o=P`
|
|
276
276
|
<div class=${`shipaid-popup ${this._popup==="learn-more"&&"active"}`}>
|
|
277
277
|
<div class="popup">
|
|
278
278
|
<button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
|
|
@@ -325,6 +325,6 @@ var xt=Object.defineProperty,Ct=Object.defineProperties;var Pt=Object.getOwnProp
|
|
|
325
325
|
</div>
|
|
326
326
|
`;return P`
|
|
327
327
|
<div class="shipaid">
|
|
328
|
-
${G(this._hasFinishedSetup,()=>{var i,
|
|
328
|
+
${G(this._hasFinishedSetup,()=>{var i,s;return G(this._shouldShowWidget&&((s=(i=this._store)==null?void 0:i.plan)==null?void 0:s.active)&&this._store.widgetShowCart,()=>[o,t],()=>P``)},()=>P`<p><slot>Loading ShipAid Widget...</slot></p>`)}
|
|
329
329
|
</div>
|
|
330
|
-
`}_currencyFormat(o){var t,e,i,r
|
|
330
|
+
`}_currencyFormat(o){var t,e,i,s,r;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)||((r=(s=window.Shopify)==null?void 0:s.currency)==null?void 0:r.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 r,n,l,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=(r=this._store)==null?void 0:r.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,h)=>h.sku&&this._store.excludedProductSkus.find(d=>d===h.sku)?c-h.final_price:c,o.total_price):o.total_price,i=((a=(l=o.items)==null?void 0:l.filter(c=>{var h,d,u;return(u=(d=(h=t.product)==null?void 0:h.variants)==null?void 0:d.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,h)=>c+=h.final_line_price,0),s=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=s/100,h=t.rules.sort((d,u)=>!d.rangeLower||!u.rangeLower?0:d.rangeLower-u.rangeLower).find(d=>{const u=Boolean(d.rangeLower&&d.rangeLower<c);return d.rangeUpper?u&&d.rangeUpper>=c:u});return typeof(h==null?void 0:h.fee)=="number"?h.fee:t.defaultFee}if(t.protectionType==="PERCENTAGE"){const c=s*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,s;const t=(e=this._store)==null?void 0:e.protectionSettings;if(!t||!((s=(i=t.product)==null?void 0:i.variants)!=null&&s.edges))throw new Error("Missing product and variants from protection settings.");return t.product.variants.edges.flatMap(({node:r})=>{if(!r||!r.price)return[];const n=Number(r.price);return[A(b({},r),{formattedPrice:n})]}).sort((r,n)=>r.formattedPrice-n.formattedPrice).find(r=>r.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){throw console.error(o),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},s=await this._fetch.post("/cart/add.js",i),r=A(b({},this._cart),{items:[s,...this._cart.items]});this._cart=r,this._setState("success"),this._dispatchEvent(L.STATUS_UPDATE,{protection:!0,cart:r,lineItem:s}),(((e=window.Shopify)==null?void 0:e.Checkout)||!this.disablePolling)&&window.location.reload()}catch(i){console.error(i),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._dispatchEvent(L.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){console.error(t),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}};m.styles=Xt,v([F({type:Boolean,attribute:!0})],m.prototype,"disablePolling",2),v([F({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,"_protectionCartItem",2),v([g()],m.prototype,"_protectionVariant",2),v([g()],m.prototype,"_state",2),v([g()],m.prototype,"_popup",2),m=v([kt("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 P;x.finalized=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions={mode:"open"},null==A||A({ReactiveElement:x}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const C=globalThis.trustedTypes,T=C?C.createPolicy("lit-html",{createHTML:t=>t}):void 0,U=`lit$${(Math.random()+"").slice(9)}$`,k="?"+U,O=`<${k}>`,N=document,I=(t="")=>N.createComment(t),H=t=>null===t||"object"!=typeof t&&"function"!=typeof t,
|
|
38
|
+
var P;x.finalized=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions={mode:"open"},null==A||A({ReactiveElement:x}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const C=globalThis.trustedTypes,T=C?C.createPolicy("lit-html",{createHTML:t=>t}):void 0,U=`lit$${(Math.random()+"").slice(9)}$`,k="?"+U,O=`<${k}>`,N=document,I=(t="")=>N.createComment(t),H=t=>null===t||"object"!=typeof t&&"function"!=typeof t,W=Array.isArray,L=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,M=/-->/g,D=/>/g,R=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,z=/'/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"),J=new WeakMap,K=N.createTreeWalker(N,129,null,!1);var Y;class Z{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=L;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===L?"!--"===a[1]?n=M:void 0!==a[1]?n=D: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:L,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:z):n===j||n===z?n=R:n===M||n===D?n=L:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===L?e+O:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+U+h):e+U+(-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!==T?T.createHTML(a):a,o]})(t,e);if(this.el=Z.createElement(p,i),K.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=K.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(U)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(U),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(U),e=t.length-1;if(e>0){o.textContent=C?C.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],I()),K.nextNode(),a.push({type:2,index:++r});o.append(t[e],I())}}}else if(8===o.nodeType)if(o.data===k)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(U,t+1));)a.push({type:7,index:r}),t+=U.length-1}r++}}static createElement(t,e){const i=N.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=H(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:N).importNode(i,!0);K.currentNode=r;let s=K.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=K.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),H(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 W(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&&H(this._$AH)?this._$AA.nextSibling.data=t:this.k(N.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=Z.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=J.get(t.strings);return void 0===e&&J.set(t.strings,e=new Z(t)),e}S(t){W(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(I()),this.A(I()),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=!H(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=!H(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=C?C.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
|
|
@@ -285,7 +285,7 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
|
|
|
285
285
|
color: var(--shipaid-text-grey);
|
|
286
286
|
font-weight: var(--shipaid-font-heavy);
|
|
287
287
|
}
|
|
288
|
-
`,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&>(e,i,s),s};const wt=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.")}};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._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>wt(t),post:(t,e)=>wt(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,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return void(this.
|
|
288
|
+
`,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&>(e,i,s),s};const wt=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.")}};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=>wt(t),post:(t,e)=>wt(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,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;!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))):(console.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(console.warn("No ShipAid plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),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 console.error("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`
|
|
289
289
|
<div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
|
|
290
290
|
<div class="popup">
|
|
291
291
|
<button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
|
|
@@ -338,6 +338,6 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
|
|
|
338
338
|
</div>
|
|
339
339
|
`;return B`
|
|
340
340
|
<div class="shipaid">
|
|
341
|
-
${ft(this._hasFinishedSetup,(()=>{var t,o;return ft((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>`))}
|
|
341
|
+
${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>`))}
|
|
342
342
|
</div>
|
|
343
|
-
`}_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 console.error(Y),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._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){console.error(o),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._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){console.error(e),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,"_hasProtectionInCart",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}({});
|
|
343
|
+
`}_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 console.error(Y),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._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){console.error(o),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._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){console.error(e),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,"_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}({});
|
|
@@ -29,13 +29,13 @@ const f=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShad
|
|
|
29
29
|
* @license
|
|
30
30
|
* Copyright 2017 Google LLC
|
|
31
31
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
32
|
-
*/;var y;const w=window.trustedTypes,$=w?w.emptyScript:"",
|
|
32
|
+
*/;var y;const w=window.trustedTypes,$=w?w.emptyScript:"",A=window.reactiveElementPolyfillSupport,b={toAttribute(t,e){switch(e){case Boolean:t=t?$:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch{i=null}}return i}},S=(t,e)=>e!==t&&(e==e||t==t),E={attribute:!0,type:String,converter:b,reflect:!1,hasChanged:S};class x extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;null!==(e=this.l)&&void 0!==e||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Eh(i,e);void 0!==o&&(this._$Eu.set(o,i),t.push(o))})),t}static createProperty(t,e=E){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||E}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(_(t))}else void 0!==t&&e.push(_(t));return e}static _$Eh(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$Eg)&&void 0!==e?e:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$Eg)||void 0===e||e.splice(this._$Eg.indexOf(t)>>>0,1)}_$Em(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{f?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=window.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$ES(t,e,i=E){var o,r;const s=this.constructor._$Eh(t,i);if(void 0!==s&&!0===i.reflect){const n=(null!==(r=null===(o=i.converter)||void 0===o?void 0:o.toAttribute)&&void 0!==r?r:b.toAttribute)(e,i.type);this._$Ei=t,null==n?this.removeAttribute(s):this.setAttribute(s,n),this._$Ei=null}}_$AK(t,e){var i,o,r;const s=this.constructor,n=s._$Eu.get(t);if(void 0!==n&&this._$Ei!==n){const t=s.getPropertyOptions(n),a=t.converter,p=null!==(r=null!==(o=null===(i=a)||void 0===i?void 0:i.fromAttribute)&&void 0!==o?o:"function"==typeof a?a:null)&&void 0!==r?r:b.fromAttribute;this._$Ei=n,this[n]=p(e,t.type),this._$Ei=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||S)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$Ei!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$Ep=this._$E_())}async _$E_(){this.isUpdatePending=!0;try{await this._$Ep}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,e)=>this[e]=t)),this._$Et=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$EU()}catch(o){throw e=!1,this._$EU(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$Eg)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$ES(e,this[e],t))),this._$EC=void 0),this._$EU()}updated(t){}firstUpdated(t){}}
|
|
33
33
|
/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
37
|
*/
|
|
38
|
-
var P;x.finalized=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions={mode:"open"},null==
|
|
38
|
+
var P;x.finalized=!0,x.elementProperties=new Map,x.elementStyles=[],x.shadowRootOptions={mode:"open"},null==A||A({ReactiveElement:x}),(null!==(y=globalThis.reactiveElementVersions)&&void 0!==y?y:globalThis.reactiveElementVersions=[]).push("1.3.0");const C=globalThis.trustedTypes,T=C?C.createPolicy("lit-html",{createHTML:t=>t}):void 0,U=`lit$${(Math.random()+"").slice(9)}$`,k="?"+U,O=`<${k}>`,N=document,I=(t="")=>N.createComment(t),H=t=>null===t||"object"!=typeof t&&"function"!=typeof t,W=Array.isArray,L=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,M=/-->/g,D=/>/g,R=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,z=/'/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"),J=new WeakMap,K=N.createTreeWalker(N,129,null,!1);var Y;class Z{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=L;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===L?"!--"===a[1]?n=M:void 0!==a[1]?n=D: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:L,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:z):n===j||n===z?n=R:n===M||n===D?n=L:(n=R,r=void 0);const h=n===R&&t[p+1].startsWith("/>")?" ":"";s+=n===L?e+O:l>=0?(o.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+U+h):e+U+(-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!==T?T.createHTML(a):a,o]})(t,e);if(this.el=Z.createElement(p,i),K.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(o=K.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(U)){const i=l[s++];if(t.push(e),void 0!==i){const t=o.getAttribute(i.toLowerCase()+"$lit$").split(U),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(U),e=t.length-1;if(e>0){o.textContent=C?C.emptyScript:"";for(let i=0;i<e;i++)o.append(t[i],I()),K.nextNode(),a.push({type:2,index:++r});o.append(t[e],I())}}}else if(8===o.nodeType)if(o.data===k)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(U,t+1));)a.push({type:7,index:r}),t+=U.length-1}r++}}static createElement(t,e){const i=N.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=H(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:N).importNode(i,!0);K.currentNode=r;let s=K.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=K.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),H(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 W(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&&H(this._$AH)?this._$AA.nextSibling.data=t:this.k(N.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=Z.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=J.get(t.strings);return void 0===e&&J.set(t.strings,e=new Z(t)),e}S(t){W(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(I()),this.A(I()),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=!H(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=!H(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=C?C.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
|
|
@@ -285,7 +285,7 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
|
|
|
285
285
|
color: var(--shipaid-text-grey);
|
|
286
286
|
font-weight: var(--shipaid-font-heavy);
|
|
287
287
|
}
|
|
288
|
-
`,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&>(e,i,s),s};const wt=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.")}};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._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>wt(t),post:(t,e)=>wt(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,e]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=t,this._cart=e}catch{return void(this.
|
|
288
|
+
`,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&>(e,i,s),s};const wt=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.")}};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=>wt(t),post:(t,e)=>wt(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,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;!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))):(console.warn("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(console.warn("No ShipAid plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))})),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 console.error("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`
|
|
289
289
|
<div class=${`shipaid-popup ${"learn-more"===this._popup&&"active"}`}>
|
|
290
290
|
<div class="popup">
|
|
291
291
|
<button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
|
|
@@ -338,6 +338,6 @@ function ft(t,e,i){return t?e():null==i?void 0:i()}var vt=((t,...e)=>{const i=1=
|
|
|
338
338
|
</div>
|
|
339
339
|
`;return B`
|
|
340
340
|
<div class="shipaid">
|
|
341
|
-
${ft(this._hasFinishedSetup,(()=>{var t,o;return ft((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>`))}
|
|
341
|
+
${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>`))}
|
|
342
342
|
</div>
|
|
343
|
-
`}_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 console.error(Y),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._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){console.error(o),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._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){console.error(e),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,"_hasProtectionInCart",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"}})}));
|
|
343
|
+
`}_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 console.error(Y),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._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){console.error(o),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._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){console.error(e),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,"_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"}})}));
|