ui.shipaid.com 0.0.5 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1 @@
1
+ VITE_APP_SHIPAID_API=http://localhost:9228
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # ShipAid Shopify Widget
2
+
3
+ This is the repository for the ShipAid Shopify (and possibly others in future) widget. It uses the [Lit](https://lit.dev/) web components library, so it is recommended to become familiar with it before contributing to this repository.
4
+
5
+ Using Lit provides a framework that allows us to build a reactive UI, using JSX-like syntax - no need to use JQuery etc. And it can easily be installed in a page by using the custom web component name:
6
+ ```html
7
+ <shipaid-widget>Fallback Content</shipaid-widget>
8
+ ```
9
+
10
+ ## Overview
11
+
12
+ This widget provides an interface where a user can choose to add or remove ShipAid protection - this is actually a product in their store that can be added to cart. When the component is loaded, we immediately run a request to fetch the ShipAid protection product details from our API, as well as the customers current cart from the [Shopify AJAX API](https://shopify.dev/api/ajax/reference/cart).
13
+ Once we have this data, we can check whether the customer currently has the ShipAid product in their cart, and show either the add/remove product buttons based on this.
14
+
15
+ We also emit various [custom events](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events#adding_custom_data_%E2%80%93_customevent) when we add or remove the ShipAid product from the cart, so other developers can listen to these events, and update AJAX carts.
16
+
17
+ ### Events
18
+
19
+ This is a list of the events emitted by the widget:
20
+
21
+ | Event | Description | Payload |
22
+ |-------|-------------|---------|
23
+ | `shipaid-loaded` | Dispatched when the widget has finished fetching data from the API, and has successfully rendered. | Contains the data from the ShipAid API: [`ShipAidStore`](/types/shipaid.ts) |
24
+ | `shipaid-protection-status` | Dispatched a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
25
+
26
+
27
+ ## Contributing
28
+
29
+ ### Requirements
30
+
31
+ - Node v16+
32
+ - PNPM
33
+ - Development Shopify store (with the ShipAid app installed)
34
+ - ShipAid API development/staging instance
35
+
36
+ ### Development
37
+
38
+ Make sure to copy `.env.example` to `.env.local`, and add the ShipAid API endpoint:
39
+
40
+ ```env
41
+ # Can be either the URL of a local dev instance, or the Nhost staging URL
42
+ VITE_APP_SHIPAID_API=http://localhost:1337/v1/graphql
43
+ ```
44
+ You will need to make sure your development store has the ShipAid app installed, so the store and its protection product is added to the DB.
45
+
46
+ ```sh
47
+ pnpm install
48
+ pnpm run develop
49
+ ```
50
+
51
+ Once the project is running, add the below to your development Shopify store `theme.liquid`:
52
+
53
+ ```html
54
+ <!-- Dev -->
55
+ <script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
56
+ <!-- Prod -->
57
+ <script src="https://unpkg.com/ui.shipaid.com?module" type="module"></script>
58
+ ```
59
+ And add the widget element in your cart (likely `/sections/main-cart-items.liquid`):
60
+
61
+ ```html
62
+ <shipaid-widget>
63
+ <p>Loading ShipAid Protection</p>
64
+ </shipaid-widget>
65
+ ```
66
+
67
+ ### Build
68
+
69
+ Create an `.env.production` file, and add the URL to the ShipAid production API.
70
+
71
+ Once the project has been built, you can publish the project to NPM, and users can add the script to their store using a package CDN (I.e. [Unpkg](https://unpkg.com/)).
72
+
73
+ ```sh
74
+ pnpm install
75
+ pnpm run lint
76
+ pnpm run build
77
+ pnpm publish
78
+ ```
@@ -1,16 +1,16 @@
1
- var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var Z=(s,t,e)=>t in s?ft(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,C=(s,t)=>{for(var e in t||(t={}))mt.call(t,e)&&Z(s,e,t[e]);if(K)for(var e of K(t))gt.call(t,e)&&Z(s,e,t[e]);return s},P=(s,t)=>_t(s,$t(t));/**
1
+ var vt=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,yt=Object.prototype.propertyIsEnumerable;var Y=(o,t,e)=>t in o?vt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,C=(o,t)=>{for(var e in t||(t={}))gt.call(t,e)&&Y(o,e,t[e]);if(K)for(var e of K(t))yt.call(t,e)&&Y(o,e,t[e]);return o},P=(o,t)=>_t(o,$t(t));/**
2
2
  * @license
3
3
  * Copyright 2017 Google LLC
4
4
  * SPDX-License-Identifier: BSD-3-Clause
5
- */const yt=s=>t=>typeof t=="function"?((e,i)=>(window.customElements.define(e,i),i))(s,t):((e,i)=>{const{kind:r,elements:o}=i;return{kind:r,elements:o,finisher(n){window.customElements.define(e,n)}}})(s,t);/**
5
+ */const wt=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 At=(s,t)=>t.kind==="method"&&t.descriptor&&!("value"in t.descriptor)?P(C({},t),{finisher(e){e.createProperty(t.key,s)}}):{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,s)}};function wt(s){return(t,e)=>e!==void 0?((i,r,o)=>{r.constructor.createProperty(o,i)})(s,t,e):At(s,t)}/**
9
+ */const At=(o,t)=>t.kind==="method"&&t.descriptor&&!("value"in t.descriptor)?P(C({},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 bt(o){return(t,e)=>e!==void 0?((i,s,r)=>{s.constructor.createProperty(r,i)})(o,t,e):At(o,t)}/**
10
10
  * @license
11
11
  * Copyright 2017 Google LLC
12
12
  * SPDX-License-Identifier: BSD-3-Clause
13
- */function g(s){return wt(P(C({},s),{state:!0}))}/**
13
+ */function $(o){return bt(P(C({},o),{state:!0}))}/**
14
14
  * @license
15
15
  * Copyright 2021 Google LLC
16
16
  * SPDX-License-Identifier: BSD-3-Clause
@@ -18,26 +18,27 @@ var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnProp
18
18
  * @license
19
19
  * Copyright 2019 Google LLC
20
20
  * SPDX-License-Identifier: BSD-3-Clause
21
- */const z=window.ShadowRoot&&(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,L=Symbol(),G=new Map;class Q{constructor(t,e){if(this._$cssResult$=!0,e!==L)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=G.get(this.cssText);return z&&t===void 0&&(G.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const Et=s=>new Q(typeof s=="string"?s:s+"",L),bt=(s,...t)=>{const e=s.length===1?s[0]:t.reduce((i,r,o)=>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)+s[o+1],s[0]);return new Q(e,L)},St=(s,t)=>{z?s.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,s.appendChild(i)})},X=z?s=>s:s=>s instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return Et(e)})(s):s;/**
21
+ */const L=window.ShadowRoot&&(window.ShadyCSS===void 0||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,j=Symbol(),Z=new Map;class G{constructor(t,e){if(this._$cssResult$=!0,e!==j)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let t=Z.get(this.cssText);return L&&t===void 0&&(Z.set(this.cssText,t=new CSSStyleSheet),t.replaceSync(this.cssText)),t}toString(){return this.cssText}}const Et=o=>new G(typeof o=="string"?o:o+"",j),xt=(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 G(e,j)},St=(o,t)=>{L?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)})},Q=L?o=>o:o=>o instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return Et(e)})(o):o;/**
22
22
  * @license
23
23
  * Copyright 2017 Google LLC
24
24
  * SPDX-License-Identifier: BSD-3-Clause
25
- */var j;const Y=window.trustedTypes,xt=Y?Y.emptyScript:"",tt=window.reactiveElementPolyfillSupport,V={toAttribute(s,t){switch(t){case Boolean:s=s?xt:null;break;case Object:case Array:s=s==null?s:JSON.stringify(s)}return s},fromAttribute(s,t){let e=s;switch(t){case Boolean:e=s!==null;break;case Number:e=s===null?null:Number(s);break;case Object:case Array:try{e=JSON.parse(s)}catch{e=null}}return e}},et=(s,t)=>t!==s&&(t==t||s==s),B={attribute:!0,type:String,converter:V,reflect:!1,hasChanged:et};class A 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 r=this._$Eh(i,e);r!==void 0&&(this._$Eu.set(r,i),t.push(r))}),t}static createProperty(t,e=B){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,r=this.getPropertyDescriptor(t,i,e);r!==void 0&&Object.defineProperty(this.prototype,t,r)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(r){const o=this[t];this[e]=r,this.requestUpdate(t,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||B}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 r of i)this.createProperty(r,e[r])}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 r of i)e.unshift(X(r))}else t!==void 0&&e.push(X(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 St(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=B){var r,o;const n=this.constructor._$Eh(t,i);if(n!==void 0&&i.reflect===!0){const l=((o=(r=i.converter)===null||r===void 0?void 0:r.toAttribute)!==null&&o!==void 0?o:V.toAttribute)(e,i.type);this._$Ei=t,l==null?this.removeAttribute(n):this.setAttribute(n,l),this._$Ei=null}}_$AK(t,e){var i,r,o;const n=this.constructor,l=n._$Eu.get(t);if(l!==void 0&&this._$Ei!==l){const a=n.getPropertyOptions(l),h=a.converter,u=(o=(r=(i=h)===null||i===void 0?void 0:i.fromAttribute)!==null&&r!==void 0?r:typeof h=="function"?h:null)!==null&&o!==void 0?o:V.fromAttribute;this._$Ei=l,this[l]=u(e,a.type),this._$Ei=null}}requestUpdate(t,e,i){let r=!0;t!==void 0&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||et)(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))):r=!1),!this.isUpdatePending&&r&&(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((r,o)=>this[o]=r),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(r=>{var o;return(o=r.hostUpdate)===null||o===void 0?void 0:o.call(r)}),this.update(i)):this._$EU()}catch(r){throw e=!1,this._$EU(),r}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;(e=this._$Eg)===null||e===void 0||e.forEach(i=>{var r;return(r=i.hostUpdated)===null||r===void 0?void 0:r.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){}}A.finalized=!0,A.elementProperties=new Map,A.elementStyles=[],A.shadowRootOptions={mode:"open"},tt==null||tt({ReactiveElement:A}),((j=globalThis.reactiveElementVersions)!==null&&j!==void 0?j:globalThis.reactiveElementVersions=[]).push("1.3.0");/**
25
+ */var B;const X=window.trustedTypes,Ct=X?X.emptyScript:"",tt=window.reactiveElementPolyfillSupport,V={toAttribute(o,t){switch(t){case Boolean:o=o?Ct: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}},et=(o,t)=>t!==o&&(t==t||o==o),F={attribute:!0,type:String,converter:V,reflect:!1,hasChanged:et};class w 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=F){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)||F}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(Q(s))}else t!==void 0&&e.push(Q(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 St(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=F){var s,r;const n=this.constructor._$Eh(t,i);if(n!==void 0&&i.reflect===!0){const h=((r=(s=i.converter)===null||s===void 0?void 0:s.toAttribute)!==null&&r!==void 0?r:V.toAttribute)(e,i.type);this._$Ei=t,h==null?this.removeAttribute(n):this.setAttribute(n,h),this._$Ei=null}}_$AK(t,e){var i,s,r;const n=this.constructor,h=n._$Eu.get(t);if(h!==void 0&&this._$Ei!==h){const a=n.getPropertyOptions(h),p=a.converter,u=(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:V.fromAttribute;this._$Ei=h,this[h]=u(e,a.type),this._$Ei=null}}requestUpdate(t,e,i){let s=!0;t!==void 0&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||et)(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){}}w.finalized=!0,w.elementProperties=new Map,w.elementStyles=[],w.shadowRootOptions={mode:"open"},tt==null||tt({ReactiveElement:w}),((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 q;const w=globalThis.trustedTypes,it=w?w.createPolicy("lit-html",{createHTML:s=>s}):void 0,$=`lit$${(Math.random()+"").slice(9)}$`,st="?"+$,Ct=`<${st}>`,E=document,U=(s="")=>E.createComment(s),T=s=>s===null||typeof s!="object"&&typeof s!="function",rt=Array.isArray,Pt=s=>{var t;return rt(s)||typeof((t=s)===null||t===void 0?void 0:t[Symbol.iterator])=="function"},N=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ot=/-->/g,nt=/>/g,y=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,at=/'/g,ht=/"/g,lt=/^(?:script|style|textarea|title)$/i,Ut=s=>(t,...e)=>({_$litType$:s,strings:t,values:e}),F=Ut(1),b=Symbol.for("lit-noChange"),p=Symbol.for("lit-nothing"),ct=new WeakMap,Tt=(s,t,e)=>{var i,r;const o=(i=e==null?void 0:e.renderBefore)!==null&&i!==void 0?i:t;let n=o._$litPart$;if(n===void 0){const l=(r=e==null?void 0:e.renderBefore)!==null&&r!==void 0?r:null;o._$litPart$=n=new O(t.insertBefore(U(),l),l,void 0,e!=null?e:{})}return n._$AI(s),n},S=E.createTreeWalker(E,129,null,!1),Nt=(s,t)=>{const e=s.length-1,i=[];let r,o=t===2?"<svg>":"",n=N;for(let a=0;a<e;a++){const h=s[a];let u,c,d=-1,v=0;for(;v<h.length&&(n.lastIndex=v,c=n.exec(h),c!==null);)v=n.lastIndex,n===N?c[1]==="!--"?n=ot:c[1]!==void 0?n=nt:c[2]!==void 0?(lt.test(c[2])&&(r=RegExp("</"+c[2],"g")),n=y):c[3]!==void 0&&(n=y):n===y?c[0]===">"?(n=r!=null?r:N,d=-1):c[1]===void 0?d=-2:(d=n.lastIndex-c[2].length,u=c[1],n=c[3]===void 0?y:c[3]==='"'?ht:at):n===ht||n===at?n=y:n===ot||n===nt?n=N:(n=y,r=void 0);const k=n===y&&s[a+1].startsWith("/>")?" ":"";o+=n===N?h+Ct:d>=0?(i.push(u),h.slice(0,d)+"$lit$"+h.slice(d)+$+k):h+$+(d===-2?(i.push(void 0),a):k)}const l=o+(s[e]||"<?>")+(t===2?"</svg>":"");if(!Array.isArray(s)||!s.hasOwnProperty("raw"))throw Error("invalid template strings array");return[it!==void 0?it.createHTML(l):l,i]};class I{constructor({strings:t,_$litType$:e},i){let r;this.parts=[];let o=0,n=0;const l=t.length-1,a=this.parts,[h,u]=Nt(t,e);if(this.el=I.createElement(h,i),S.currentNode=this.el.content,e===2){const c=this.el.content,d=c.firstChild;d.remove(),c.append(...d.childNodes)}for(;(r=S.nextNode())!==null&&a.length<l;){if(r.nodeType===1){if(r.hasAttributes()){const c=[];for(const d of r.getAttributeNames())if(d.endsWith("$lit$")||d.startsWith($)){const v=u[n++];if(c.push(d),v!==void 0){const k=r.getAttribute(v.toLowerCase()+"$lit$").split($),M=/([.?@])?(.*)/.exec(v);a.push({type:1,index:o,name:M[2],strings:k,ctor:M[1]==="."?It:M[1]==="?"?kt:M[1]==="@"?Mt:R})}else a.push({type:6,index:o})}for(const d of c)r.removeAttribute(d)}if(lt.test(r.tagName)){const c=r.textContent.split($),d=c.length-1;if(d>0){r.textContent=w?w.emptyScript:"";for(let v=0;v<d;v++)r.append(c[v],U()),S.nextNode(),a.push({type:2,index:++o});r.append(c[d],U())}}}else if(r.nodeType===8)if(r.data===st)a.push({type:2,index:o});else{let c=-1;for(;(c=r.data.indexOf($,c+1))!==-1;)a.push({type:7,index:o}),c+=$.length-1}o++}}static createElement(t,e){const i=E.createElement("template");return i.innerHTML=t,i}}function x(s,t,e=s,i){var r,o,n,l;if(t===b)return t;let a=i!==void 0?(r=e._$Cl)===null||r===void 0?void 0:r[i]:e._$Cu;const h=T(t)?void 0:t._$litDirective$;return(a==null?void 0:a.constructor)!==h&&((o=a==null?void 0:a._$AO)===null||o===void 0||o.call(a,!1),h===void 0?a=void 0:(a=new h(s),a._$AT(s,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=x(s,a._$AS(s,t.values),a,i)),t}class Ht{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,o=((e=t==null?void 0:t.creationScope)!==null&&e!==void 0?e:E).importNode(i,!0);S.currentNode=o;let n=S.nextNode(),l=0,a=0,h=r[0];for(;h!==void 0;){if(l===h.index){let u;h.type===2?u=new O(n,n.nextSibling,this,t):h.type===1?u=new h.ctor(n,h.name,h.strings,this,t):h.type===6&&(u=new Rt(n,this,t)),this.v.push(u),h=r[++a]}l!==(h==null?void 0:h.index)&&(n=S.nextNode(),l++)}return o}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 O{constructor(t,e,i,r){var o;this.type=2,this._$AH=p,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=r,this._$Cg=(o=r==null?void 0:r.isConnected)===null||o===void 0||o}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=x(this,t,e),T(t)?t===p||t==null||t===""?(this._$AH!==p&&this._$AR(),this._$AH=p):t!==this._$AH&&t!==b&&this.$(t):t._$litType$!==void 0?this.T(t):t.nodeType!==void 0?this.k(t):Pt(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!==p&&T(this._$AH)?this._$AA.nextSibling.data=t:this.k(E.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:r}=t,o=typeof r=="number"?this._$AC(t):(r.el===void 0&&(r.el=I.createElement(r.h,this.options)),r);if(((e=this._$AH)===null||e===void 0?void 0:e._$AD)===o)this._$AH.m(i);else{const n=new Ht(o,this),l=n.p(this.options);n.m(i),this.k(l),this._$AH=n}}_$AC(t){let e=ct.get(t.strings);return e===void 0&&ct.set(t.strings,e=new I(t)),e}S(t){rt(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,r=0;for(const o of t)r===e.length?e.push(i=new O(this.A(U()),this.A(U()),this,this.options)):i=e[r],i._$AI(o),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 R{constructor(t,e,i,r,o){this.type=1,this._$AH=p,this._$AN=void 0,this.element=t,this.name=e,this._$AM=r,this.options=o,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=p}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,r){const o=this.strings;let n=!1;if(o===void 0)t=x(this,t,e,0),n=!T(t)||t!==this._$AH&&t!==b,n&&(this._$AH=t);else{const l=t;let a,h;for(t=o[0],a=0;a<o.length-1;a++)h=x(this,l[i+a],e,a),h===b&&(h=this._$AH[a]),n||(n=!T(h)||h!==this._$AH[a]),h===p?t=p:t!==p&&(t+=(h!=null?h:"")+o[a+1]),this._$AH[a]=h}n&&!r&&this.C(t)}C(t){t===p?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t!=null?t:"")}}class It extends R{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===p?void 0:t}}const Ot=w?w.emptyScript:"";class kt extends R{constructor(){super(...arguments),this.type=4}C(t){t&&t!==p?this.element.setAttribute(this.name,Ot):this.element.removeAttribute(this.name)}}class Mt extends R{constructor(t,e,i,r,o){super(t,e,i,r,o),this.type=5}_$AI(t,e=this){var i;if((t=(i=x(this,t,e,0))!==null&&i!==void 0?i:p)===b)return;const r=this._$AH,o=t===p&&r!==p||t.capture!==r.capture||t.once!==r.once||t.passive!==r.passive,n=t!==p&&(r===p||o);o&&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 Rt{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){x(this,t)}}const dt=window.litHtmlPolyfillSupport;dt==null||dt(I,O),((q=globalThis.litHtmlVersions)!==null&&q!==void 0?q:globalThis.litHtmlVersions=[]).push("2.2.0");/**
29
+ */var W;const A=globalThis.trustedTypes,it=A?A.createPolicy("lit-html",{createHTML:o=>o}):void 0,g=`lit$${(Math.random()+"").slice(9)}$`,ot="?"+g,Pt=`<${ot}>`,b=document,T=(o="")=>b.createComment(o),U=o=>o===null||typeof o!="object"&&typeof o!="function",st=Array.isArray,Tt=o=>{var t;return st(o)||typeof((t=o)===null||t===void 0?void 0:t[Symbol.iterator])=="function"},k=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,rt=/-->/g,nt=/>/g,y=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,at=/'/g,pt=/"/g,ht=/^(?:script|style|textarea|title)$/i,Ut=o=>(t,...e)=>({_$litType$:o,strings:t,values:e}),N=Ut(1),E=Symbol.for("lit-noChange"),c=Symbol.for("lit-nothing"),dt=new WeakMap,kt=(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 h=(s=e==null?void 0:e.renderBefore)!==null&&s!==void 0?s:null;r._$litPart$=n=new I(t.insertBefore(T(),h),h,void 0,e!=null?e:{})}return n._$AI(o),n},x=b.createTreeWalker(b,129,null,!1),Nt=(o,t)=>{const e=o.length-1,i=[];let s,r=t===2?"<svg>":"",n=k;for(let a=0;a<e;a++){const p=o[a];let u,d,l=-1,m=0;for(;m<p.length&&(n.lastIndex=m,d=n.exec(p),d!==null);)m=n.lastIndex,n===k?d[1]==="!--"?n=rt:d[1]!==void 0?n=nt:d[2]!==void 0?(ht.test(d[2])&&(s=RegExp("</"+d[2],"g")),n=y):d[3]!==void 0&&(n=y):n===y?d[0]===">"?(n=s!=null?s:k,l=-1):d[1]===void 0?l=-2:(l=n.lastIndex-d[2].length,u=d[1],n=d[3]===void 0?y:d[3]==='"'?pt:at):n===pt||n===at?n=y:n===rt||n===nt?n=k:(n=y,s=void 0);const z=n===y&&o[a+1].startsWith("/>")?" ":"";r+=n===k?p+Pt:l>=0?(i.push(u),p.slice(0,l)+"$lit$"+p.slice(l)+g+z):p+g+(l===-2?(i.push(void 0),a):z)}const h=r+(o[e]||"<?>")+(t===2?"</svg>":"");if(!Array.isArray(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return[it!==void 0?it.createHTML(h):h,i]};class O{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let r=0,n=0;const h=t.length-1,a=this.parts,[p,u]=Nt(t,e);if(this.el=O.createElement(p,i),x.currentNode=this.el.content,e===2){const d=this.el.content,l=d.firstChild;l.remove(),d.append(...l.childNodes)}for(;(s=x.nextNode())!==null&&a.length<h;){if(s.nodeType===1){if(s.hasAttributes()){const d=[];for(const l of s.getAttributeNames())if(l.endsWith("$lit$")||l.startsWith(g)){const m=u[n++];if(d.push(l),m!==void 0){const z=s.getAttribute(m.toLowerCase()+"$lit$").split(g),M=/([.?@])?(.*)/.exec(m);a.push({type:1,index:r,name:M[2],strings:z,ctor:M[1]==="."?Ot:M[1]==="?"?zt:M[1]==="@"?Mt:R})}else a.push({type:6,index:r})}for(const l of d)s.removeAttribute(l)}if(ht.test(s.tagName)){const d=s.textContent.split(g),l=d.length-1;if(l>0){s.textContent=A?A.emptyScript:"";for(let m=0;m<l;m++)s.append(d[m],T()),x.nextNode(),a.push({type:2,index:++r});s.append(d[l],T())}}}else if(s.nodeType===8)if(s.data===ot)a.push({type:2,index:r});else{let d=-1;for(;(d=s.data.indexOf(g,d+1))!==-1;)a.push({type:7,index:r}),d+=g.length-1}r++}}static createElement(t,e){const i=b.createElement("template");return i.innerHTML=t,i}}function S(o,t,e=o,i){var s,r,n,h;if(t===E)return t;let a=i!==void 0?(s=e._$Cl)===null||s===void 0?void 0:s[i]:e._$Cu;const p=U(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=(h=e)._$Cl)!==null&&n!==void 0?n:h._$Cl=[])[i]=a:e._$Cu=a),a!==void 0&&(t=S(o,a._$AS(o,t.values),a,i)),t}class Ht{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:b).importNode(i,!0);x.currentNode=r;let n=x.nextNode(),h=0,a=0,p=s[0];for(;p!==void 0;){if(h===p.index){let u;p.type===2?u=new I(n,n.nextSibling,this,t):p.type===1?u=new p.ctor(n,p.name,p.strings,this,t):p.type===6&&(u=new Rt(n,this,t)),this.v.push(u),p=s[++a]}h!==(p==null?void 0:p.index)&&(n=x.nextNode(),h++)}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 I{constructor(t,e,i,s){var r;this.type=2,this._$AH=c,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=S(this,t,e),U(t)?t===c||t==null||t===""?(this._$AH!==c&&this._$AR(),this._$AH=c):t!==this._$AH&&t!==E&&this.$(t):t._$litType$!==void 0?this.T(t):t.nodeType!==void 0?this.k(t):Tt(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!==c&&U(this._$AH)?this._$AA.nextSibling.data=t:this.k(b.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=O.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 Ht(r,this),h=n.p(this.options);n.m(i),this.k(h),this._$AH=n}}_$AC(t){let e=dt.get(t.strings);return e===void 0&&dt.set(t.strings,e=new O(t)),e}S(t){st(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 I(this.A(T()),this.A(T()),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 R{constructor(t,e,i,s,r){this.type=1,this._$AH=c,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=c}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=S(this,t,e,0),n=!U(t)||t!==this._$AH&&t!==E,n&&(this._$AH=t);else{const h=t;let a,p;for(t=r[0],a=0;a<r.length-1;a++)p=S(this,h[i+a],e,a),p===E&&(p=this._$AH[a]),n||(n=!U(p)||p!==this._$AH[a]),p===c?t=c:t!==c&&(t+=(p!=null?p:"")+r[a+1]),this._$AH[a]=p}n&&!s&&this.C(t)}C(t){t===c?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t!=null?t:"")}}class Ot extends R{constructor(){super(...arguments),this.type=3}C(t){this.element[this.name]=t===c?void 0:t}}const It=A?A.emptyScript:"";class zt extends R{constructor(){super(...arguments),this.type=4}C(t){t&&t!==c?this.element.setAttribute(this.name,It):this.element.removeAttribute(this.name)}}class Mt extends R{constructor(t,e,i,s,r){super(t,e,i,s,r),this.type=5}_$AI(t,e=this){var i;if((t=(i=S(this,t,e,0))!==null&&i!==void 0?i:c)===E)return;const s=this._$AH,r=t===c&&s!==c||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==c&&(s===c||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 Rt{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){S(this,t)}}const lt=window.litHtmlPolyfillSupport;lt==null||lt(O,I),((W=globalThis.litHtmlVersions)!==null&&W!==void 0?W: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 W,J;class H extends A{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=Tt(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 b}}H.finalized=!0,H._$litElement$=!0,(W=globalThis.litElementHydrateSupport)===null||W===void 0||W.call(globalThis,{LitElement:H});const pt=globalThis.litElementPolyfillSupport;pt==null||pt({LitElement:H}),((J=globalThis.litElementVersions)!==null&&J!==void 0?J:globalThis.litElementVersions=[]).push("3.2.0");function Dt(s){if(!s.dispatchEvent||!s.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return s}const _="__registered_effects";function zt(s){const t=s;if(t[_])return t;const e=Dt(s),i=e.updated;return t[_]={index:0,count:0,effects:[]},e.updated=r=>(t[_].index=0,i(r)),t}function Lt(s,t){const e=zt(s),{index:i,count:r}=e[_];return i===r?(e[_].index++,e[_].count++,e[_].effects.push(t),t):(e[_].index++,e[_].effects[i])}function ut(s,t,e){const i=Lt(s,{on:t,observe:["__initial__dirty"]});i.observe.some((r,o)=>e[o]!==r)&&i.on(),i.observe=e}const jt=(s,t)=>ut(s,t,[]);/**
33
+ */var q,J;class H extends w{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=kt(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 E}}H.finalized=!0,H._$litElement$=!0,(q=globalThis.litElementHydrateSupport)===null||q===void 0||q.call(globalThis,{LitElement:H});const ct=globalThis.litElementPolyfillSupport;ct==null||ct({LitElement:H}),((J=globalThis.litElementVersions)!==null&&J!==void 0?J:globalThis.litElementVersions=[]).push("3.2.0");function Dt(o){if(!o.dispatchEvent||!o.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return o}const v="__registered_effects";function Lt(o){const t=o;if(t[v])return t;const e=Dt(o),i=e.updated;return t[v]={index:0,count:0,effects:[]},e.updated=s=>(t[v].index=0,i(s)),t}function jt(o,t){const e=Lt(o),{index:i,count:s}=e[v];return i===s?(e[v].index++,e[v].count++,e[v].effects.push(t),t):(e[v].index++,e[v].effects[i])}function ut(o,t,e){const i=jt(o,{on:t,observe:["__initial__dirty"]});i.observe.some((s,r)=>e[r]!==s)&&i.on(),i.observe=e}const Bt=(o,t)=>ut(o,t,[]);/**
34
34
  * @license
35
35
  * Copyright 2021 Google LLC
36
36
  * SPDX-License-Identifier: BSD-3-Clause
37
- */function Vt(s,t,e){return s?t():e==null?void 0:e()}var Bt=bt`
38
- .shipaid-prompt {
37
+ */function ft(o,t,e){return o?t():e==null?void 0:e()}var Vt=xt`
38
+ :host {
39
39
  --shipaid-primary: #002bd6;
40
40
  --shipaid-secondary: #0076ff;
41
+ --shipaid-danger: #f44336;
41
42
  --shipaid-text: #000000;
42
43
  --shipaid-text-muted: #cccccc;
43
44
  --shipaid-text-grey: #aaaaaa;
@@ -48,7 +49,127 @@ var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnProp
48
49
  --shipaid-font-lg: 18px;
49
50
  --shipaid-font-regular: 400;
50
51
  --shipaid-font-heavy: 700;
52
+ }
53
+
54
+ * {
55
+ font-family: var(--shipaid-font);
56
+ }
57
+
58
+ .error {
59
+ color: var(--shipaid-danger);
60
+ font-size: var(--shipaid-font-sm);
61
+ }
62
+
63
+ /* Popups */
64
+
65
+ .shipaid-popup {
66
+ position: fixed;
67
+ top: 0;
68
+ bottom: 0;
69
+ left: 0;
70
+ right: 0;
71
+ margin: auto;
72
+ max-width: 500px;
73
+ max-height: 100vh;
74
+ height: fit-content;
75
+ border: var(--shipaid-light-grey) 1px solid;
76
+ background-color: #fff;
77
+ z-index: 10000;
78
+ overflow: auto;
79
+ visibility: hidden;
80
+ opacity: 0;
81
+ transition: all 250ms ease-in-out;
82
+ }
83
+
84
+ .shipaid-popup.active {
85
+ visibility: visible;
86
+ opacity: 1;
87
+ }
88
+
89
+ @media (max-width: 600px) {
90
+ .shipaid-popup {
91
+ width: 100vw;
92
+ height: 100vh;
93
+ }
94
+ }
95
+
96
+ .shipaid-popup .popup {
97
+ display: inline-flex;
98
+ flex-direction: column;
99
+ gap: 1rem;
100
+ padding: 5rem;
101
+ height: fit-content;
102
+ }
103
+
104
+ @media (max-width: 600px) {
105
+ .shipaid-popup .popup {
106
+ padding: 3rem;
107
+ }
108
+ }
109
+
110
+ .popup .popup-close {
111
+ width: fit-content;
112
+ margin-left: auto;
113
+ background-color: transparent;
114
+ cursor: pointer;
115
+ border: none;
116
+ font-family: var(--shipaid-font);
117
+ font-weight: var(--shipaid-font-heavy);
118
+ text-transform: uppercase;
119
+ }
120
+
121
+ .popup .popup-title {
122
+ font-size: clamp(1.8rem, 2vw + 1rem, 2.8rem);;
123
+ letter-spacing: 1px;
124
+ }
125
+
126
+ .popup p {
127
+ font-size: clamp(1.125rem, 1vw + 1rem, 1.6rem);
128
+ margin: 0;
129
+ }
130
+
131
+ .popup .popup-disclaimer {
132
+ font-size: 10px;
133
+ color: var(--shipaid-text-muted);
134
+ }
135
+
136
+ .popup .popup-footer {
137
+ display: flex;
138
+ flex-direction: row;
139
+ justify-content: space-between;
140
+ align-items: flex-start;
141
+ margin-top: 2rem;
142
+ }
143
+
144
+ @media (max-width: 600px) {
145
+ .popup .popup-footer {
146
+ flex-direction: column;
147
+ }
148
+ }
149
+
150
+ .popup .popup-footer .footer-links {
151
+ display: flex;
152
+ flex-direction: row;
153
+ gap: 2rem;
154
+ }
51
155
 
156
+ .popup .popup-footer .footer-links a {
157
+ font-family: var(--shipaid-font);
158
+ font-size: var(--shipaid-font-sm);
159
+ color: var(--shipaid-text-muted);
160
+ }
161
+
162
+ .popup .popup-footer .footer-date p {
163
+ font-family: var(--shipaid-font);
164
+ font-weight: var(--shipaid-font-heavy);
165
+ font-size: var(--shipaid-font-sm);
166
+ color: var(--shipaid-text);
167
+ }
168
+
169
+
170
+ /* Widget */
171
+
172
+ .shipaid-prompt {
52
173
  width: 400px;
53
174
  font-family: var(--shipaid-font);
54
175
  font-size: var(--shipaid-font-base);
@@ -57,98 +178,113 @@ var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnProp
57
178
  flex-direction: column;
58
179
  gap: 1rem;
59
180
  margin: 2rem 0 2rem auto;
181
+ }
60
182
 
61
- p, a {
62
- margin: 0;
63
- line-height: 1;
64
- }
65
-
66
- .prompt-title {
67
- text-align: center;
68
- font-size: var(--shipaid-font-lg);
69
- font-weight: var(--shipaid-font-heavy);
70
- }
71
-
72
- .prompt-product {
73
- display: flex;
74
- flex-direction: row;
75
- gap: 2rem;
76
- height: 55px;
77
- margin-top: 1rem;
78
-
79
- .prompt-product-details {
80
- .prompt-product-details-title {
81
- font-size: var(--shipaid-font-base);
82
- font-weight: var(--shipaid-font-heavy);
83
- }
84
-
85
- .prompt-product-details-description {
86
- font-size: var(--shipaid-font-sm);
87
- margin-top: 1rem;
88
- }
89
- }
90
-
91
- .prompt-product-actions {
92
- margin-left: auto;
93
- display: flex;
94
- flex-direction: column;
95
- justify-content: space-between;
96
- text-align: right;
97
-
98
- .prompt-product-actions-price {
99
- color: var(--shipaid-text-muted);
100
- font-size: var(--shipaid-font-base);
101
- }
102
-
103
- .prompt-product-actions-button {
104
- background-color: transparent;
105
- border: none;
106
- color: var(--shipaid-primary);
107
- text-transform: uppercase;
108
- font-weight: var(--shipaid-font-heavy);
109
- cursor: pointer;
110
- }
111
- }
183
+ @media (max-width: 600px) {
184
+ .shipaid-prompt {
185
+ width: 100%;
112
186
  }
187
+ }
113
188
 
114
- .prompt-footer {
115
- display: flex;
116
- flex-direction: row;
117
- justify-content: space-between;
118
- align-items: center;
119
- margin-top: 1rem;
120
-
121
- .prompt-footer-about {
122
- color: var(--shipaid-text-grey);
123
- cursor: pointer;
124
- text-decoration: underline;
125
- font-size: var(--shipaid-font-sm);
126
- }
127
-
128
- .prompt-footer-badge {
129
- background-color: var(--shipaid-light-grey);
130
- color: var(--shipaid-text);
131
- padding: 0.5rem 1.5rem;
132
- border-radius: 30px;
133
- cursor: pointer;
134
- text-decoration: none;
135
- font-size: var(--shipaid-font-sm);
136
-
137
- .ship {
138
- text-transform: uppercase;
139
- color: var(--shipaid-secondary);
140
- font-weight: var(--shipaid-font-heavy);
141
- }
142
-
143
- .aid {
144
- text-transform: uppercase;
145
- color: var(--shipaid-text-grey);
146
- font-weight: var(--shipaid-font-heavy);
147
- }
148
- }
149
- }
189
+ .shipaid-prompt p, .shipaid-prompt a {
190
+ margin: 0;
191
+ line-height: 1;
192
+ }
193
+ .shipaid-prompt .prompt-title {
194
+ text-align: center;
195
+ font-size: var(--shipaid-font-lg);
196
+ font-weight: var(--shipaid-font-heavy);
197
+ }
198
+ .shipaid-prompt .prompt-product {
199
+ display: flex;
200
+ flex-direction: row;
201
+ gap: 2rem;
202
+ height: 55px;
203
+ margin-top: 1rem;
150
204
  }
151
- `,qt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,m=(s,t,e,i)=>{for(var r=i>1?void 0:i?Ft(t,e):t,o=s.length-1,n;o>=0;o--)(n=s[o])&&(r=(i?n(t,e,r):n(r))||r);return i&&r&&qt(t,e,r),r},Wt=(s=>(s.LOADED="shipaid-loaded",s.STATUS_UPDATE="shipaid-protection-status",s))(Wt||{});const Jt=s=>{var t,e,i,r,o;return new Intl.NumberFormat((e=(t=window.Shopify)==null?void 0:t.locale)!=null?e:void 0,{currency:(o=(r=(i=window.Shopify)==null?void 0:i.currency)==null?void 0:r.active)!=null?o:"USD",style:"currency"}).format(s)},vt=async(s,t)=>{try{const e=await fetch(s,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.")}};let f=class extends H{constructor(){super(...arguments);var s;this._storeDomain=(s=window.Shopify)==null?void 0:s.shop,this._hasFinishedSetup=!1,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._fetch={get:t=>vt(t),post:(t,e)=>vt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var t,e;jt(this,async()=>{var n,l;const[i,r]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=i,this._cart=r;const o=(l=(n=r.items)==null?void 0:n.some(a=>a.variant_id===i.productVariantNumericId))!=null?l:!1;this._hasProtectionInCart=o,this._hasFinishedSetup=!0,this._dispatchEvent("shipaid-loaded",i)}),ut(this,()=>{var o,n,l,a;if(!((o=this._cart)!=null&&o.items))return;const i=(l=(n=this._cart)==null?void 0:n.items)==null?void 0:l.findIndex(h=>{var u;return h.variant_id===((u=this._store)==null?void 0:u.productVariantNumericId)}),r=(a=this._cart)==null?void 0:a.items[i];this._hasProtectionInCart=!!r,r&&(this._protectionProduct=P(C({},r),{index:i,position:i+1}))},[this._store,this._cart]);const s=F`
205
+ .shipaid-prompt .prompt-product .prompt-product-details .prompt-product-details-title {
206
+ font-size: var(--shipaid-font-base);
207
+ font-weight: var(--shipaid-font-heavy);
208
+ }
209
+ .shipaid-prompt .prompt-product .prompt-product-details .prompt-product-details-description {
210
+ font-size: var(--shipaid-font-sm);
211
+ margin-top: 1rem;
212
+ }
213
+ .shipaid-prompt .prompt-product .prompt-product-actions {
214
+ margin-left: auto;
215
+ display: flex;
216
+ flex-direction: column;
217
+ justify-content: space-between;
218
+ text-align: right;
219
+ }
220
+ .shipaid-prompt .prompt-product .prompt-product-actions .prompt-product-actions-price {
221
+ color: var(--shipaid-text-muted);
222
+ font-size: var(--shipaid-font-base);
223
+ }
224
+ .shipaid-prompt .prompt-product .prompt-product-actions .prompt-product-actions-button {
225
+ background-color: transparent;
226
+ border: none;
227
+ color: var(--shipaid-primary);
228
+ text-transform: uppercase;
229
+ font-weight: var(--shipaid-font-heavy);
230
+ cursor: pointer;
231
+ }
232
+ .shipaid-prompt .prompt-footer {
233
+ display: flex;
234
+ flex-direction: row;
235
+ justify-content: space-between;
236
+ align-items: center;
237
+ margin-top: 1rem;
238
+ }
239
+ .shipaid-prompt .prompt-footer .prompt-footer-about {
240
+ color: var(--shipaid-text-grey);
241
+ cursor: pointer;
242
+ text-decoration: underline;
243
+ font-size: var(--shipaid-font-sm);
244
+ background-color: transparent;
245
+ cursor: pointer;
246
+ border: none;
247
+ }
248
+ .shipaid-prompt .prompt-footer .prompt-footer-badge {
249
+ background-color: var(--shipaid-light-grey);
250
+ color: var(--shipaid-text);
251
+ padding: 0.5rem 1.5rem;
252
+ border-radius: 30px;
253
+ cursor: pointer;
254
+ text-decoration: none;
255
+ font-size: var(--shipaid-font-sm);
256
+ }
257
+ .shipaid-prompt .prompt-footer .prompt-footer-badge .ship {
258
+ text-transform: uppercase;
259
+ color: var(--shipaid-secondary);
260
+ font-weight: var(--shipaid-font-heavy);
261
+ }
262
+ .shipaid-prompt .prompt-footer .prompt-footer-badge .aid {
263
+ text-transform: uppercase;
264
+ color: var(--shipaid-text-grey);
265
+ font-weight: var(--shipaid-font-heavy);
266
+ }
267
+ `,Ft=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,_=(o,t,e,i)=>{for(var s=i>1?void 0:i?Wt(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&&Ft(t,e,s),s},qt=(o=>(o.LOADED="shipaid-loaded",o.STATUS_UPDATE="shipaid-protection-status",o))(qt||{});const mt=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.")}};let f=class extends H{constructor(){super(...arguments);var o;this._storeDomain=(o=window.Shopify)==null?void 0:o.shop,this._hasFinishedSetup=!1,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>mt(t),post:(t,e)=>mt(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}render(){var e,i;Bt(this,async()=>{var a,p;const s=document.createElement("link");s.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),s.setAttribute("rel","stylesheet"),document.head.appendChild(s);const[r,n]=await Promise.all([this._fetchShipAidData(),this._fetchCart()]);this._store=r,this._cart=n;const h=(p=(a=n.items)==null?void 0:a.some(u=>u.variant_id===r.productVariantNumericId))!=null?p:!1;this._hasProtectionInCart=h,this._hasFinishedSetup=!0,this._dispatchEvent("shipaid-loaded",r)}),ut(this,()=>{var n,h,a,p;if(!((n=this._cart)!=null&&n.items))return;const s=(a=(h=this._cart)==null?void 0:h.items)==null?void 0:a.findIndex(u=>{var d;return u.variant_id===((d=this._store)==null?void 0:d.productVariantNumericId)}),r=(p=this._cart)==null?void 0:p.items[s];this._hasProtectionInCart=!!r,r&&(this._protectionProduct=P(C({},r),{index:s,position:s+1}))},[this._store,this._cart]);const o=N`
268
+ <div class=${`shipaid-popup ${this._popup==="learn-more"&&"active"}`}>
269
+ <div class="popup">
270
+ <button class="popup-close" @click=${()=>{this._popup=null}}>Close</button>
271
+ <p class="popup-title">Instant Package Protection</p>
272
+ <p>We empower your favorite brands to protect their packages, because every order is precious!</p>
273
+ <p class="popup-title">Shop Care-Free With ShipAid</p>
274
+ <p>Brands and shipment carriers cannot always guarantee your order will arrive at your doorstep safely. Things happen! We allow the brand you are purchasing from to protect your order in the chance of an issue in transit. If you encounter an issue, simply reach out to the brand and they will handle your claim as soon as possible</p>
275
+ <p class="popup-disclaimer">By purchasing this protection, you are agreeing to our Terms Of Service and Privacy Policy. You are not obligated to purchase this protection. This protection is NOT insurance. Purchasing this protection does not guarantee you will be reimbursed for any product or shipping costs. The claim process and decision for compensation is strictly decided by the brand you a purchasing from.</p>
276
+ <div class="popup-footer">
277
+ <div class="footer-links">
278
+ <a>Terms of Service</a>
279
+ <a>Privacy Policy</a>
280
+ </div>
281
+ <div class="footer-date">
282
+ <p>ShipAid &copy; ${new Date().getFullYear()}</p>
283
+ </div>
284
+ </div>
285
+ </div>
286
+ </div>
287
+ `,t=N`
152
288
  <div class="shipaid-prompt">
153
289
  <p class="prompt-title">${this._hasProtectionInCart?"Active":"Inactive"}</p>
154
290
  <div class="prompt-product">
@@ -160,14 +296,15 @@ var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnProp
160
296
  <p class="prompt-product-details-description">Resolve shipping issues care-free</p>
161
297
  </div>
162
298
  <div class="prompt-product-actions">
163
- <p class="prompt-product-actions-price">${Jt((e=(t=this._store)==null?void 0:t.productPrice)!=null?e:0)}</p>
299
+ <p class="prompt-product-actions-price">${this._currencyFormat((i=(e=this._store)==null?void 0:e.productPrice)!=null?i:0)}</p>
164
300
  <button class="prompt-product-actions-button" @click=${this._updateProtection} ?disabled=${this._state.loading}>
165
301
  ${this._state.loading?"Loading...":this._hasProtectionInCart?"Remove":"+ Add"}
166
302
  </button>
167
303
  </div>
168
304
  </div>
305
+ ${ft(this._state.error,()=>N`<p class="error">${this._state.error}</p>`)}
169
306
  <div class="prompt-footer">
170
- <b class="prompt-footer-about" href="/">Learn More</b>
307
+ <button class="prompt-footer-about" @click=${()=>{this._popup="learn-more"}}>Learn More</button>
171
308
  <a class="prompt-footer-badge" href="/">
172
309
  <span>Powered by</span>
173
310
  <span class="ship">Ship</span>
@@ -175,14 +312,8 @@ var ft=Object.defineProperty,_t=Object.defineProperties;var $t=Object.getOwnProp
175
312
  </a>
176
313
  </div>
177
314
  </div>
178
- `;return F`
179
- ${Vt(this._hasFinishedSetup&&this._store,()=>s,()=>F`<p>Loading...</p>`)}
180
- `}_dispatchEvent(s,t={}){this.dispatchEvent(new CustomEvent(s,{bubbles:!0,composed:!0,detail:t}))}_setState(s,t){this._state={loading:s==="loading",success:s==="success",error:s==="error"?t||!0:!1}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){try{if(!this._storeDomain)throw new Error("Missing store domain - cannot continue.");const s={store:this._storeDomain},t=`query StoreByDomain($store: String!) {
181
- store(store: $store) {
182
- store
183
- productId
184
- productVariantId
185
- productVariantNumericId
186
- productPrice
187
- }
188
- }`,{data:e}=await this._fetch.post("http://localhost:1337/v1/graphql",{query:t,variables:s});if(!e.store)throw new Error(`Could not find a store for ${this._storeDomain}`);if(!e.store.productVariantNumericId)throw new Error("Missing variant ID for ShipAid product.");return e.store}catch(s){throw console.error(s),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(s){throw console.error(s),new Error("Could not fetch cart for current domain.")}}hasProtection(){return this._hasProtectionInCart}async addProtection(){var s,t;try{if(!((s=this._store)!=null&&s.productVariantNumericId))throw new Error("Store has not been loaded.");if(!((t=this._cart)!=null&&t.items))throw new Error("Cart has not been loaded.");this._setState("loading");const e={id:this._store.productVariantNumericId,quantity:1},i=await this._fetch.post("/cart/add.js",e),r=P(C({},this._cart),{items:[i,...this._cart.items]});this._cart=r,this._setState("success"),this._dispatchEvent("shipaid-protection-status",{protection:!0,cart:r,lineItem:i})}catch(e){console.error(e),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var s;try{if(!((s=this._store)!=null&&s.productVariantNumericId))throw new Error("Store has not been loaded.");if(!this._protectionProduct)throw new Error("Protection product not found.");this._setState("loading");const t={id:this._protectionProduct.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);this._dispatchEvent("shipaid-protection-status",{protection:!1,cart:e,lineItem:this._protectionProduct}),this._cart=e,this._setState("success")}catch(t){console.error(t),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}};f.styles=Bt,m([g()],f.prototype,"_storeDomain",2),m([g()],f.prototype,"_store",2),m([g()],f.prototype,"_cart",2),m([g()],f.prototype,"_hasFinishedSetup",2),m([g()],f.prototype,"_hasProtectionInCart",2),m([g()],f.prototype,"_protectionProduct",2),m([g()],f.prototype,"_state",2),f=m([yt("shipaid-widget")],f);export{f as ShipAidWidget};
315
+ `;return N`
316
+ <div class="shipaid">
317
+ ${ft(this._hasFinishedSetup&&this._store,()=>[o,t],()=>N`<p>Loading...</p>`)}
318
+ </div>
319
+ `}_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(o)}_dispatchEvent(o,t={}){this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:t}))}_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=this._storeDomain||window.location.hostname;if(!o)throw new Error("Missing store domain - cannot continue.");const t=new URL("https://xfnjpunvafvudwuzwjlm.nhost.run");t.pathname=`/api/rest/store/${o}/properties`;const e=await this._fetch.get(t.toString());if(!e.store)throw new Error(`Could not find a store for ${o}`);if(!e.store.productVariantNumericId)throw new Error("Missing variant ID for ShipAid product.");return e.store}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 addProtection(){var o,t;try{if(!((o=this._store)!=null&&o.productVariantNumericId))throw new Error("Store has not been loaded.");if(!((t=this._cart)!=null&&t.items))throw new Error("Cart has not been loaded.");this._setState("loading");const e={id:this._store.productVariantNumericId,quantity:1},i=await this._fetch.post("/cart/add.js",e),s=P(C({},this._cart),{items:[i,...this._cart.items]});this._cart=s,this._setState("success"),this._dispatchEvent("shipaid-protection-status",{protection:!0,cart:s,lineItem:i})}catch(e){console.error(e),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){var o;try{if(!((o=this._store)!=null&&o.productVariantNumericId))throw new Error("Store has not been loaded.");if(!this._protectionProduct)throw new Error("Protection product not found.");this._setState("loading");const t={id:this._protectionProduct.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);this._dispatchEvent("shipaid-protection-status",{protection:!1,cart:e,lineItem:this._protectionProduct}),this._cart=e,this._setState("success")}catch(t){console.error(t),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}};f.styles=Vt,_([$()],f.prototype,"_storeDomain",2),_([$()],f.prototype,"_store",2),_([$()],f.prototype,"_cart",2),_([$()],f.prototype,"_hasFinishedSetup",2),_([$()],f.prototype,"_hasProtectionInCart",2),_([$()],f.prototype,"_protectionProduct",2),_([$()],f.prototype,"_state",2),_([$()],f.prototype,"_popup",2),f=_([wt("shipaid-widget")],f);export{f as ShipAidWidget};