@blotoutio/providers-blotout-wallet-sdk 0.41.0 → 0.42.0

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/index.mjs CHANGED
@@ -1,46 +1,5 @@
1
1
  const packageName = 'blotoutWallet';
2
2
 
3
- const canLog = () => {
4
- try {
5
- return localStorage.getItem('edgeTagDebug') === '1';
6
- }
7
- catch {
8
- return false;
9
- }
10
- };
11
- const logger = {
12
- log: (...args) => {
13
- if (canLog()) {
14
- console.log(...args);
15
- }
16
- },
17
- error: (...args) => {
18
- if (canLog()) {
19
- console.error(...args);
20
- }
21
- },
22
- info: (...args) => {
23
- if (canLog()) {
24
- console.info(...args);
25
- }
26
- },
27
- trace: (...args) => {
28
- if (canLog()) {
29
- console.trace(...args);
30
- }
31
- },
32
- table: (...args) => {
33
- if (canLog()) {
34
- console.table(...args);
35
- }
36
- },
37
- dir: (...args) => {
38
- if (canLog()) {
39
- console.dir(...args);
40
- }
41
- },
42
- };
43
-
44
3
  class APIError extends Error {
45
4
  constructor(...args) {
46
5
  super(...args);
@@ -49,7 +8,7 @@ class APIError extends Error {
49
8
  class WalletAPI {
50
9
  constructor({ baseUrl, userId }) {
51
10
  this.listeners = new Set();
52
- this._cart = null;
11
+ this._cart = { cartId: null, items: [], email: false };
53
12
  this.baseUrl = baseUrl;
54
13
  this.userId = userId;
55
14
  }
@@ -79,10 +38,8 @@ class WalletAPI {
79
38
  return this._cart;
80
39
  }
81
40
  set cart(value) {
82
- if (this._cart !== value) {
83
- this._cart = value;
84
- this.notify();
85
- }
41
+ this._cart = value;
42
+ this.notify();
86
43
  }
87
44
  subscribe(listener) {
88
45
  this.listeners.add(listener);
@@ -96,9 +53,6 @@ class WalletAPI {
96
53
  headers: this.getHeaders(),
97
54
  }).then(async (response) => {
98
55
  if (!response.ok) {
99
- if (response.status == 404) {
100
- return (this.cart = null);
101
- }
102
56
  throw new APIError(`Could not fetch cart contents`, {
103
57
  cause: response,
104
58
  });
@@ -167,34 +121,400 @@ class WalletAPI {
167
121
  if (!response.ok) {
168
122
  throw new APIError(`Could not mark purchase`, { cause: response });
169
123
  }
124
+ this.cart = { cartId: null, email: this.cart.email, items: [] };
125
+ this.notify();
126
+ });
127
+ }
128
+ saveEmail(email) {
129
+ return fetch(this.getUrl('/cart/email'), {
130
+ method: 'POST',
131
+ body: JSON.stringify({ email }),
132
+ headers: this.getHeaders(true),
133
+ }).then((response) => {
134
+ if (!response.ok) {
135
+ throw new APIError('Could not save email', { cause: response });
136
+ }
137
+ this.cart.email = true;
138
+ this.notify();
139
+ });
140
+ }
141
+ restore() {
142
+ return fetch(this.getUrl('/cart/restore'), {
143
+ method: 'POST',
144
+ headers: this.getHeaders(),
145
+ }).then((response) => {
146
+ if (!response.ok) {
147
+ throw new APIError('Could not mark cart as restored', {
148
+ cause: response,
149
+ });
150
+ }
170
151
  });
171
152
  }
172
153
  }
173
154
 
174
- let api;
175
- let component;
176
- const setComponent = (_component) => {
177
- component = _component;
178
- };
179
- const setAPI = (_api) => {
180
- api = _api;
155
+ var _a;
156
+ const registryKey = Symbol.for('blotout-wallet');
157
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
158
+
159
+ /******************************************************************************
160
+ Copyright (c) Microsoft Corporation.
161
+
162
+ Permission to use, copy, modify, and/or distribute this software for any
163
+ purpose with or without fee is hereby granted.
164
+
165
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
166
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
167
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
168
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
169
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
170
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
171
+ PERFORMANCE OF THIS SOFTWARE.
172
+ ***************************************************************************** */
173
+ /* global Reflect, Promise, SuppressedError, Symbol */
174
+
175
+
176
+ function __decorate(decorators, target, key, desc) {
177
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
178
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
179
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
180
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
181
+ }
182
+
183
+ function __metadata(metadataKey, metadataValue) {
184
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
185
+ }
186
+
187
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
188
+ var e = new Error(message);
189
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
181
190
  };
182
- const getAPI = () => api;
183
- const getComponent = () => component;
184
191
 
185
- const symbol = Symbol.for('blotout-store-implementation');
192
+ /**
193
+ * @license
194
+ * Copyright 2019 Google LLC
195
+ * SPDX-License-Identifier: BSD-3-Clause
196
+ */
197
+ const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$4=new WeakMap;let n$4 = class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$4.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$4.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$4("string"==typeof t?t:t+"",void 0,s$2),i$4=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$4(o,t,s$2)},S$1=(s,o)=>{if(e$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
198
+
199
+ /**
200
+ * @license
201
+ * Copyright 2017 Google LLC
202
+ * SPDX-License-Identifier: BSD-3-Clause
203
+ */const{is:i$3,defineProperty:e$5,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$3,getPrototypeOf:n$3}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){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(t){i=null;}}return i}},f$1=(t,s)=>!i$3(t,s),y$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let b$1 = class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$5(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$4(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$3(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$3(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return !1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);}!1===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),!0===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=!0;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t)!0!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=!1;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EU();}catch(s){throw t=!1,this._$EU(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),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._$ES}shouldUpdate(t){return !0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EC(t,this[t]))),this._$EU();}updated(t){}firstUpdated(t){}};b$1.elementStyles=[],b$1.shadowRootOptions={mode:"open"},b$1[d$1("elementProperties")]=new Map,b$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:b$1}),(a$1.reactiveElementVersions??=[]).push("2.0.4");
204
+
205
+ /**
206
+ * @license
207
+ * Copyright 2017 Google LLC
208
+ * SPDX-License-Identifier: BSD-3-Clause
209
+ */
210
+ const t$2=globalThis,i$2=t$2.trustedTypes,s$1=i$2?i$2.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$2="?"+h,n$2=`<${o$2}>`,r$3=document,l=()=>r$3.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),b=y(2),w=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),A=new WeakMap,E=r$3.createTreeWalker(r$3,129);function C(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const P=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$2:d>=0?(o.push(a),s.slice(0,d)+e$4+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [C(t,l+(t[s]||"<?>")+(2===i?"</svg>":"")),o]};class V{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=P(t,s);if(this.el=V.createElement(f,n),E.currentNode=this.el.content,2===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=E.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e$4)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?k:"?"===e[1]?H:"@"===e[1]?I:R}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$2?i$2.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),E.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$2)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$3.createElement("template");return s.innerHTML=t,s}}function N(t,i,s=t,e){if(i===w)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(!1),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=N(t,h._$AS(t,i.values),h,e)),i}class S{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$3).importNode(i,!0);E.currentNode=e;let h=E.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new M(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new L(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=E.nextNode(),o++);}return E.currentNode=r$3,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class M{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=T,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=N(this,t,i),c(t)?t===T||null==t||""===t?(this._$AH!==T&&this._$AR(),this._$AH=T):t!==this._$AH&&t!==w&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t));}_(t){this._$AH!==T&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$3.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=V.createElement(C(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new S(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new V(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new M(this.S(l()),this.S(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=T,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=T;}_$AI(t,i=this,s,e){const h=this.strings;let o=!1;if(void 0===h)t=N(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=N(this,e[s+n],i,n),r===w&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===T?t=T:t!==T&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===T?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class k extends R{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===T?void 0:t;}}class H extends R{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==T);}}class I extends R{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=N(this,t,i,0)??T)===w)return;const s=this._$AH,e=t===T&&s!==T||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==T&&(s===T||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class L{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){N(this,t);}}const Z=t$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.litHtmlVersions??=[]).push("3.1.3");const j=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new M(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
211
+
212
+ /**
213
+ * @license
214
+ * Copyright 2017 Google LLC
215
+ * SPDX-License-Identifier: BSD-3-Clause
216
+ */class s extends b$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=j(i,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1);}render(){return w}}s._$litElement$=!0,s[("finalized")]=!0,globalThis.litElementHydrateSupport?.({LitElement:s});const r$2=globalThis.litElementPolyfillSupport;r$2?.({LitElement:s});(globalThis.litElementVersions??=[]).push("4.0.5");
217
+
218
+ /**
219
+ * @license
220
+ * Copyright 2017 Google LLC
221
+ * SPDX-License-Identifier: BSD-3-Clause
222
+ */
223
+ const t$1=t=>(e,o)=>{void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
224
+
225
+ /**
226
+ * @license
227
+ * Copyright 2017 Google LLC
228
+ * SPDX-License-Identifier: BSD-3-Clause
229
+ */const o$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1},r$1=(t=o$1,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.P(o,void 0,t),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n$1(t){return (e,o)=>"object"==typeof o?r$1(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,r?{...t,wrapped:!0}:t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
230
+
231
+ /**
232
+ * @license
233
+ * Copyright 2017 Google LLC
234
+ * SPDX-License-Identifier: BSD-3-Clause
235
+ */function r(r){return n$1({...r,state:!0,attribute:!1})}
236
+
237
+ /**
238
+ * @license
239
+ * Copyright 2017 Google LLC
240
+ * SPDX-License-Identifier: BSD-3-Clause
241
+ */
242
+ const e$3=(e,t,c)=>(c.configurable=!0,c.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
243
+
244
+ /**
245
+ * @license
246
+ * Copyright 2017 Google LLC
247
+ * SPDX-License-Identifier: BSD-3-Clause
248
+ */function e$2(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;if(r){const{get:e,set:r}="object"==typeof s?n:i??(()=>{const t=Symbol();return {get(){return this[t]},set(e){this[t]=e;}}})();return e$3(n,s,{get(){let t=e.call(this);return void 0===t&&(t=o(this),(null!==t||this.hasUpdated)&&r.call(this,t)),t}})}return e$3(n,s,{get(){return o(this)}})}}
186
249
 
250
+ /**
251
+ * @license
252
+ * Copyright 2017 Google LLC
253
+ * SPDX-License-Identifier: BSD-3-Clause
254
+ */
255
+ const t={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$1=t=>(...e)=>({_$litDirective$:t,values:e});let i$1 = class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}};
256
+
257
+ /**
258
+ * @license
259
+ * Copyright 2018 Google LLC
260
+ * SPDX-License-Identifier: BSD-3-Clause
261
+ */const e=e$1(class extends i$1{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"class"!==t$1.name||t$1.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
262
+
263
+ /**
264
+ * @license
265
+ * Copyright 2018 Google LLC
266
+ * SPDX-License-Identifier: BSD-3-Clause
267
+ */const n="important",i=" !"+n,o=e$1(class extends i$1{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"style"!==t$1.name||t$1.strings?.length>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,r)=>{const s=t[r];return null==s?e:e+`${r=r.includes("-")?r:r.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(e,[r]){const{style:s}=e.element;if(void 0===this.ft)return this.ft=new Set(Object.keys(r)),this.render(r);for(const t of this.ft)null==r[t]&&(this.ft.delete(t),t.includes("-")?s.removeProperty(t):s[t]=null);for(const t in r){const e=r[t];if(null!=e){this.ft.add(t);const r="string"==typeof e&&e.endsWith(i);t.includes("-")||r?s.setProperty(t,r?e.slice(0,-11):e,r?n:""):s[t]=e;}}return w}});
268
+
269
+ const bounce = 'linear(0, 0.004, 0.016, 0.035, 0.063, 0.098, 0.141 13.6%, 0.25, 0.391, 0.563, 0.765, 1, 0.891 40.9%, 0.848, 0.813, 0.785, 0.766, 0.754, 0.75, 0.754, 0.766, 0.785, 0.813, 0.848, 0.891 68.2%, 1 72.7%, 0.973, 0.953, 0.941, 0.938, 0.941, 0.953, 0.973, 1, 0.988, 0.984, 0.988, 1)';
270
+ const spring = 'linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1)';
271
+
272
+ const cssVars = i$4 `
273
+ :host {
274
+ --primary: var(--bw-primary, #f25c2b);
275
+ --secondary: var(--bw-secondary, #172a41);
276
+ --button: var(--bw-primary, #da2e3a);
277
+ --foreground: var(--bw-foreground, white);
278
+ --input-border: var(--bw-input-border, #dbe2eb);
279
+ --input-foreground: var(--wb-input-foreground, var(--secondary));
280
+ --input-background: var(--wb-input-background, white);
281
+ --backdrop: var(--wb-backdrop, #00000077);
282
+ --z-index: var(--wb-z-index, 9999);
283
+
284
+ --spring-easing: ${r$5(spring)};
285
+
286
+ --bounce-easing: ${r$5(bounce)};
287
+ }
288
+ `;
289
+
290
+ const wallet = (attrs) => b `<svg
291
+ width="32"
292
+ height="22"
293
+ viewBox="0 0 32 22"
294
+ fill="none"
295
+ xmlns="http://www.w3.org/2000/svg"
296
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
297
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
298
+ >
299
+ <g>
300
+ <path
301
+ fill-rule="evenodd"
302
+ clip-rule="evenodd"
303
+ d="M29.2312 0H2.7688C1.24278 0 0 1.24278 0 2.7688V18.7688C0 20.2959 1.24278 21.5376 2.7688 21.5376H29.2301C30.7572 21.5376 31.9989 20.2948 31.9989 18.7688V14.7691H22.1525C21.6431 14.7691 21.2296 14.3555 21.2296 13.8461V7.69254C21.2296 7.18315 21.6431 6.7696 22.1525 6.7696H31.9989V2.7688C31.9989 1.2417 30.7561 0 29.2301 0H29.2312ZM8.92347 18.1582C7.76038 18.1582 6.69206 17.7532 5.85098 17.0769V17.554C5.85098 17.7037 5.85098 17.778 5.8219 17.8351C5.79606 17.8857 5.75513 17.9266 5.70559 17.9514C5.64852 17.9805 5.57421 17.9805 5.42451 17.9805H4.43266C4.28404 17.9805 4.20866 17.9805 4.15158 17.9514C4.10096 17.9256 4.06112 17.8846 4.03527 17.8351C4.00619 17.778 4.00619 17.7037 4.00619 17.554V4.02558C4.00619 3.87588 4.00619 3.80158 4.03527 3.7445C4.06112 3.69388 4.10204 3.65296 4.15158 3.62819C4.20866 3.59911 4.28296 3.59911 4.43266 3.59911H5.42451C5.57313 3.59911 5.64852 3.59911 5.70559 3.62819C5.75621 3.65404 5.79606 3.69496 5.8219 3.7445C5.85098 3.80158 5.85098 3.87696 5.85098 4.02558V9.37686C6.69314 8.70055 7.76146 8.29562 8.92347 8.29562C11.6384 8.29562 13.8397 10.5033 13.8397 13.2269C13.8397 15.9505 11.6384 18.1582 8.92347 18.1582Z"
304
+ fill="currentColor"
305
+ />
306
+ <path
307
+ d="M8.92308 16.3091C10.62 16.3091 11.9956 14.9292 11.9956 13.227C11.9956 11.5247 10.62 10.1448 8.92308 10.1448C7.22619 10.1448 5.85059 11.5247 5.85059 13.227C5.85059 14.9292 7.22619 16.3091 8.92308 16.3091Z"
308
+ fill="currentColor"
309
+ />
310
+ <path
311
+ fill-rule="evenodd"
312
+ clip-rule="evenodd"
313
+ d="M23.0771 12.9232H32.0006V8.61548H23.0771V12.9232ZM24.615 9.84641H25.8459C26.3553 9.84641 26.7689 10.26 26.7689 10.7693C26.7689 11.2787 26.3553 11.6923 25.8459 11.6923H24.615C24.1056 11.6923 23.6921 11.2787 23.6921 10.7693C23.6921 10.26 24.1056 9.84641 24.615 9.84641Z"
314
+ fill="currentColor"
315
+ />
316
+ </g>
317
+ </svg>`;
318
+ const blotout = (attrs) => b `<svg
319
+ width="26"
320
+ height="36"
321
+ viewBox="0 0 26 36"
322
+ fill="none"
323
+ xmlns="http://www.w3.org/2000/svg"
324
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
325
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
326
+ >
327
+ <path
328
+ fill-rule="evenodd"
329
+ clip-rule="evenodd"
330
+ d="M0.830995 0.42104C0.75879 0.56208 0.758789 0.746712 0.758789 1.11598V34.5089C0.758789 34.8782 0.75879 35.0628 0.830995 35.2038C0.894508 35.3279 0.995851 35.4288 1.1205 35.4921C1.26221 35.5638 1.44772 35.5638 1.81874 35.5638H4.28515C4.65617 35.5638 4.84167 35.5638 4.98338 35.4921C5.10803 35.4288 5.20938 35.3279 5.27289 35.2038C5.3451 35.0628 5.3451 34.8782 5.3451 34.5089V33.3303C7.4389 35.0007 10.0967 36 12.9889 36C19.7435 36 25.2191 30.5502 25.2191 23.8275C25.2191 17.1049 19.7435 11.6552 12.9889 11.6552C10.0967 11.6552 7.4389 12.6544 5.3451 14.3249V1.11598C5.3451 0.746712 5.3451 0.56208 5.27289 0.42104C5.20938 0.296978 5.10803 0.196112 4.98338 0.132899C4.84167 0.0610352 4.65617 0.0610352 4.28515 0.0610352H1.81874C1.44772 0.0610352 1.26221 0.0610352 1.1205 0.132899C0.995851 0.196112 0.894508 0.296978 0.830995 0.42104ZM5.3451 23.8275C5.3451 28.0292 8.76736 31.4353 12.9889 31.4353C17.2105 31.4353 20.6328 28.0292 20.6328 23.8275C20.6328 19.626 17.2105 16.2198 12.9889 16.2198C8.76736 16.2198 5.3451 19.626 5.3451 23.8275Z"
331
+ fill="currentColor"
332
+ />
333
+ </svg>`;
334
+ const wink = (attrs) => b `<svg
335
+ width="18"
336
+ height="18"
337
+ viewBox="0 0 18 18"
338
+ fill="none"
339
+ xmlns="http://www.w3.org/2000/svg"
340
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
341
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
342
+ >
343
+ <g>
344
+ <path
345
+ d="M9.5 1.125C7.94248 1.125 6.41992 1.58686 5.12489 2.45218C3.82985 3.31749 2.82049 4.5474 2.22445 5.98637C1.62841 7.42534 1.47246 9.00874 1.77632 10.5363C2.08018 12.0639 2.8302 13.4671 3.93154 14.5685C5.03288 15.6698 6.43607 16.4198 7.96367 16.7237C9.49127 17.0275 11.0747 16.8716 12.5136 16.2756C13.9526 15.6795 15.1825 14.6702 16.0478 13.3751C16.9131 12.0801 17.375 10.5575 17.375 9C17.375 6.91142 16.5453 4.90838 15.0685 3.43153C13.5916 1.95469 11.5886 1.125 9.5 1.125ZM9.5 15.75C8.16498 15.75 6.85994 15.3541 5.7499 14.6124C4.63987 13.8707 3.77471 12.8165 3.26382 11.5831C2.75293 10.3497 2.61925 8.99251 2.8797 7.68314C3.14015 6.37377 3.78303 5.17103 4.72703 4.22703C5.67104 3.28302 6.87377 2.64015 8.18314 2.3797C9.49252 2.11925 10.8497 2.25292 12.0831 2.76381C13.3165 3.2747 14.3707 4.13987 15.1124 5.2499C15.8541 6.35993 16.25 7.66498 16.25 9C16.25 10.7902 15.5388 12.5071 14.273 13.773C13.0071 15.0388 11.2902 15.75 9.5 15.75Z"
346
+ fill="currentColor"
347
+ />
348
+ <path
349
+ d="M12.0313 6.1875C11.7531 6.1875 11.4812 6.26997 11.25 6.4245C11.0187 6.57902 10.8385 6.79864 10.732 7.0556C10.6256 7.31256 10.5978 7.59531 10.652 7.8681C10.7063 8.14088 10.8402 8.39145 11.0369 8.58812C11.2335 8.78479 11.4841 8.91872 11.7569 8.97298C12.0297 9.02724 12.3124 8.99939 12.5694 8.89296C12.8264 8.78652 13.046 8.60628 13.2005 8.37502C13.355 8.14376 13.4375 7.87188 13.4375 7.59375C13.4375 7.22079 13.2893 6.8631 13.0256 6.59938C12.7619 6.33566 12.4042 6.1875 12.0313 6.1875Z"
350
+ fill="currentColor"
351
+ />
352
+ <path d="M8.375 7.3125H5V8.4375H8.375V7.3125Z" fill="white" />
353
+ <path
354
+ d="M9.49961 13.5001C10.2761 13.4988 11.039 13.2966 11.7142 12.9132C12.3893 12.5298 12.9538 11.9782 13.3527 11.312L12.3909 10.7495C12.0907 11.248 11.6667 11.6604 11.1601 11.9467C10.6535 12.233 10.0815 12.3834 9.49961 12.3834C8.91771 12.3834 8.3457 12.233 7.83911 11.9467C7.33251 11.6604 6.90854 11.248 6.60836 10.7495L5.64648 11.312C6.04539 11.9782 6.60987 12.5298 7.28506 12.9132C7.96024 13.2966 8.72315 13.4988 9.49961 13.5001Z"
355
+ fill="currentColor"
356
+ />
357
+ </g>
358
+ </svg> `;
359
+ const cross = (attrs) => b `<svg
360
+ width="32"
361
+ height="32"
362
+ viewBox="0 0 32 32"
363
+ fill="none"
364
+ xmlns="http://www.w3.org/2000/svg"
365
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
366
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
367
+ >
368
+ <g>
369
+ <path
370
+ d="M17.4141 16L24 9.4141L22.5859 8L16 14.5859L9.4143 8L8 9.4141L14.5859 16L8 22.5859L9.4143 24L16 17.4141L22.5859 24L24 22.5859L17.4141 16Z"
371
+ fill="currentColor"
372
+ />
373
+ </g>
374
+ </svg> `;
375
+
376
+ const fadeInDialog = (element) => {
377
+ const dialogAnimation = element.animate([
378
+ { transform: 'translateY(-20px)', opacity: 0 },
379
+ { transform: 'translateY(0)', opacity: 1 },
380
+ ], { duration: 600, easing: spring, composite: 'add' });
381
+ const backdropAnimation = element.animate([{ opacity: 0 }, { opacity: 1 }], {
382
+ duration: 300,
383
+ easing: 'ease-out',
384
+ pseudoElement: '::backdrop',
385
+ fill: 'forwards',
386
+ });
387
+ return Promise.all([dialogAnimation.finished, backdropAnimation.finished]);
388
+ };
389
+ const fadeOutToBottom = (element) => {
390
+ const dialogAnimation = element.animate([
391
+ { transform: 'translateY(0)', opacity: 1 },
392
+ { transform: 'translateY(20px)', opacity: 0 },
393
+ ], { duration: 600, easing: spring });
394
+ const backdropAnimation = element.animate([{ opacity: 1 }, { opacity: 0 }], {
395
+ duration: 300,
396
+ easing: 'ease-out',
397
+ pseudoElement: '::backdrop',
398
+ fill: 'forwards',
399
+ });
400
+ return Promise.all([dialogAnimation.finished, backdropAnimation.finished]);
401
+ };
402
+ const springInFromLeft = (element, offset = '100%') => element.animate([{ transform: `translateX(-${offset})` }, { transform: 'translateX(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
403
+ const springInFromRight = (element, offset = '100%') => element.animate([{ transform: `translateX(${offset})` }, { transform: 'translateX(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
404
+ const springInFromTop = (element, offset = '100%') => element.animate([{ transform: `translateY(-${offset})` }, { transform: 'translateY(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
405
+ const springInFromBottom = (element, offset = '100%') => element.animate([{ transform: `translateY(${offset})` }, { transform: 'translateY(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
406
+ const springOutToLeft = (element, offset = '100%') => element.animate([{ transform: 'translateX(0)' }, { transform: `translateX(-${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
407
+ const springOutToRight = (element, offset = '100%') => element.animate([{ transform: 'translateX(0)' }, { transform: `translateX(${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
408
+ const springOutToTop = (element, offset = '100%') => element.animate([{ transform: 'translateY(0)' }, { transform: `translateY(-${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
409
+ const springOutToBottom = (element, offset = '100%') => element.animate([{ transform: 'translateY(0)' }, { transform: `translateY(${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
410
+
411
+ const validPositions = new Set([
412
+ 'bottom',
413
+ 'bottom-left',
414
+ 'bottom-right',
415
+ 'left',
416
+ 'right',
417
+ 'top',
418
+ 'top-left',
419
+ 'top-right',
420
+ ]);
187
421
  const getItemKey = (item) => `${item.productId}-${item.variantId}`;
188
- const syncCartItems = async (api, storeApi) => {
189
- try {
190
- const [wallet, shopItems] = await Promise.all([
191
- api.getCart(),
192
- storeApi.getCart(),
422
+ const wait = (timeout) => new Promise((res) => setTimeout(res, timeout));
423
+ let BlotoutWallet = class BlotoutWallet extends s {
424
+ constructor() {
425
+ super(...arguments);
426
+ this._buttonVisible = false;
427
+ this._bannerVisible = false;
428
+ this._hasItemsInWallet = false;
429
+ this._hasEmail = false;
430
+ this.onWalletUpdated = () => {
431
+ const cart = this._walletApi.cart;
432
+ this._hasItemsInWallet = cart.items.length > 0;
433
+ if (this._hasItemsInWallet || !this._hasEmail) {
434
+ this.showButton();
435
+ }
436
+ else if (!this._hasItemsInWallet && this._hasEmail) {
437
+ this.hideButton();
438
+ }
439
+ };
440
+ this.onSubmit = (ev) => {
441
+ var _a;
442
+ ev.preventDefault();
443
+ ev.stopPropagation();
444
+ const modalAnimation = this.hideModal();
445
+ const email = (_a = this._email) === null || _a === void 0 ? void 0 : _a.value.trim();
446
+ if (email) {
447
+ this._walletApi.saveEmail(email)
448
+ .then(() => {
449
+ this._email.value = '';
450
+ this._hasEmail = true;
451
+ this.dispatchEvent(new CustomEvent('blotout-wallet-email-saved', { bubbles: true }));
452
+ })
453
+ .catch((err) => console.error(err));
454
+ }
455
+ if (this._hasItemsInWallet) {
456
+ this._storeApi.clearCart()
457
+ .then(() => this._storeApi.addItems(this._walletApi.cart.items))
458
+ .then(() => this._walletApi.restore())
459
+ .then(() => {
460
+ this.dispatchEvent(new CustomEvent('blotout-wallet-restored', { bubbles: true }));
461
+ return modalAnimation.then(() => this.showRestorationBanner());
462
+ })
463
+ .catch((err) => console.error(err));
464
+ }
465
+ };
466
+ this.showRestorationBanner = async () => {
467
+ this._bannerVisible = true;
468
+ await new Promise(requestAnimationFrame);
469
+ await springInFromBottom(this._banner, '120%');
470
+ await wait(5000);
471
+ await springOutToBottom(this._banner, '120%');
472
+ this._bannerVisible = false;
473
+ };
474
+ }
475
+ get _storeApi() {
476
+ var _a;
477
+ return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.storeAPI;
478
+ }
479
+ get _walletApi() {
480
+ var _a;
481
+ return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.walletAPI;
482
+ }
483
+ get _position() {
484
+ return validPositions.has(this.position) ? this.position : 'bottom-left';
485
+ }
486
+ connectedCallback() {
487
+ var _a;
488
+ super.connectedCallback();
489
+ this._unsubscribe = (_a = this._walletApi) === null || _a === void 0 ? void 0 : _a.subscribe(this.onWalletUpdated);
490
+ this.syncItems().then((hasItemsSaved) => {
491
+ this.dispatchEvent(new CustomEvent('blotout-wallet-loaded', { bubbles: true }));
492
+ this._hasItemsInWallet = hasItemsSaved;
493
+ if (this._hasItemsInWallet) {
494
+ this.showButton();
495
+ }
496
+ });
497
+ }
498
+ disconnectedCallback() {
499
+ var _a;
500
+ super.disconnectedCallback();
501
+ (_a = this._unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
502
+ this._unsubscribe = undefined;
503
+ }
504
+ async syncItems() {
505
+ if (!this._walletApi || !this._storeApi) {
506
+ console.error('The required APIs are not available');
507
+ return false;
508
+ }
509
+ const [savedCart, shopItems] = await Promise.all([
510
+ this._walletApi.getCart(),
511
+ this._storeApi.getCart(),
193
512
  ]);
194
- const lookup = new Map(wallet === null || wallet === void 0 ? void 0 : wallet.items.map((item) => [getItemKey(item), item]));
513
+ this._hasEmail = savedCart.email;
514
+ const savedItemsLookup = new Map(savedCart.items.map((item) => [getItemKey(item), item]));
195
515
  const missingItems = [];
196
516
  for (const item of shopItems) {
197
- const walletItem = lookup.get(getItemKey(item));
517
+ const walletItem = savedItemsLookup.get(getItemKey(item));
198
518
  if (!walletItem) {
199
519
  missingItems.push(item);
200
520
  }
@@ -206,63 +526,442 @@ const syncCartItems = async (api, storeApi) => {
206
526
  }
207
527
  }
208
528
  if (missingItems.length > 0) {
209
- await api.addItems(missingItems);
529
+ await this._walletApi.addItems(missingItems);
530
+ }
531
+ return savedCart.items.length > 0;
532
+ }
533
+ async showButton() {
534
+ if (this._buttonVisible) {
535
+ return;
536
+ }
537
+ this._buttonVisible = true;
538
+ await new Promise(requestAnimationFrame).then(() => {
539
+ switch (this._position) {
540
+ case 'top-left':
541
+ case 'left':
542
+ case 'bottom-left': {
543
+ return springInFromLeft(this._button);
544
+ }
545
+ case 'top-right':
546
+ case 'right':
547
+ case 'bottom-right': {
548
+ return springInFromRight(this._button);
549
+ }
550
+ case 'bottom': {
551
+ return springInFromBottom(this._button);
552
+ }
553
+ case 'top': {
554
+ return springInFromTop(this._button);
555
+ }
556
+ default: {
557
+ return springInFromLeft(this._button);
558
+ }
559
+ }
560
+ });
561
+ this.dispatchEvent(new CustomEvent('blotout-wallet-shown', { bubbles: true }));
562
+ }
563
+ async hideButton() {
564
+ if (!this._buttonVisible) {
565
+ return;
566
+ }
567
+ switch (this._position) {
568
+ case 'top-left':
569
+ case 'left':
570
+ case 'bottom-left': {
571
+ await springOutToLeft(this._button);
572
+ break;
573
+ }
574
+ case 'top-right':
575
+ case 'right':
576
+ case 'bottom-right': {
577
+ await springOutToRight(this._button);
578
+ break;
579
+ }
580
+ case 'bottom': {
581
+ await springOutToBottom(this._button);
582
+ break;
583
+ }
584
+ case 'top': {
585
+ await springOutToTop(this._button);
586
+ break;
587
+ }
588
+ default: {
589
+ await springOutToLeft(this._button);
590
+ }
210
591
  }
592
+ this._buttonVisible = false;
593
+ this.dispatchEvent(new CustomEvent('blotout-wallet-hidden', { bubbles: true }));
594
+ }
595
+ async showModal() {
596
+ this._dialog.showModal();
597
+ await new Promise(requestAnimationFrame);
598
+ await fadeInDialog(this._dialog);
211
599
  }
212
- catch (err) {
213
- logger.error(err);
600
+ async hideModal() {
601
+ await fadeOutToBottom(this._dialog);
602
+ this._dialog.close();
603
+ }
604
+ render() {
605
+ return x `
606
+ <button
607
+ class="${e({
608
+ cta: true,
609
+ [this._position]: true,
610
+ hidden: !this._buttonVisible,
611
+ })}"
612
+ @click=${this.showModal}
613
+ >
614
+ ${wallet({ class: 'icon' })}
615
+ </button>
616
+
617
+ <dialog>
618
+ <button class="dismiss" @click=${this.hideModal}>${cross()}</button>
619
+ ${blotout({ class: 'logo' })}
620
+ <form method="dialog" @submit=${this.onSubmit}>
621
+ ${this._hasItemsInWallet
622
+ ? x `<p>
623
+ Hey! Your <strong>cart has expired!</strong><br />But we've got
624
+ you covered. ${wink({ style: 'vertical-align:middle' })}
625
+ </p>`
626
+ : x `<p>
627
+ Carts expire in 7 days.<br />But we can save your carts for life
628
+ ${wink({ style: 'vertical-align:middle' })}
629
+ </p>`}
630
+
631
+ <p>
632
+ <input
633
+ type="email"
634
+ name="email"
635
+ placeholder="Enter your email ID"
636
+ ?required=${!this._hasEmail}
637
+ style=${o({
638
+ display: this._hasEmail ? 'none' : 'block',
639
+ })}
640
+ />
641
+ </p>
642
+ <p>
643
+ <button class="restore" type="submit">
644
+ ${this._hasItemsInWallet ? 'Restore Cart' : 'Save Cart'}
645
+ </button>
646
+ </p>
647
+ </form>
648
+ </dialog>
649
+
650
+ <div
651
+ class="banner"
652
+ style=${o({ display: this._bannerVisible ? '' : 'none' })}
653
+ >
654
+ ${blotout({
655
+ class: 'logo',
656
+ style: 'height: 18px',
657
+ })}
658
+ <div>Cart restored!</div>
659
+ </div>
660
+ `;
214
661
  }
215
662
  };
663
+ BlotoutWallet.styles = [
664
+ cssVars,
665
+ i$4 `
666
+ * {
667
+ box-sizing: border-box;
668
+ font-family: inherit;
669
+ font-size: 16px;
670
+ line-height: 24px;
671
+ }
672
+
673
+ strong {
674
+ font-weight: bold;
675
+ }
676
+
677
+ button {
678
+ cursor: pointer;
679
+ }
680
+
681
+ .cta {
682
+ position: fixed;
683
+ z-index: var(--z-index);
684
+ background: var(--button);
685
+ color: var(--foreground);
686
+ padding: 8px;
687
+ border: none;
688
+ }
689
+
690
+ .top-left {
691
+ border-radius: 0 4px 4px 0;
692
+ left: 0;
693
+ top: 4px;
694
+ }
695
+
696
+ .top {
697
+ border-radius: 0 0 4px 4px;
698
+ left: 50%;
699
+ top: 0;
700
+ transform: translateX(-50%);
701
+ }
702
+
703
+ .top-right {
704
+ border-radius: 4px 0 0 4px;
705
+ right: 0;
706
+ top: 4px;
707
+ }
708
+
709
+ .left {
710
+ border-radius: 0 4px 4px 0;
711
+ left: 0;
712
+ top: 50%;
713
+ transform: translateY(-50%);
714
+ }
715
+
716
+ .right {
717
+ border-radius: 4px 0 0 4px;
718
+ right: 0;
719
+ top: 50%;
720
+ transform: translateY(-50%);
721
+ }
722
+
723
+ .bottom-left {
724
+ border-radius: 0 4px 4px 0;
725
+ left: 0;
726
+ bottom: 4px;
727
+ }
728
+
729
+ .bottom {
730
+ border-radius: 4px 4px 0 0;
731
+ left: 50%;
732
+ bottom: 0;
733
+ transform: translateX(-50%);
734
+ }
735
+
736
+ .bottom-right {
737
+ border-radius: 4px 0 0 4px;
738
+ right: 0;
739
+ bottom: 4px;
740
+ }
741
+
742
+ .hidden {
743
+ display: none;
744
+ }
745
+
746
+ .icon {
747
+ display: block;
748
+ }
749
+
750
+ .logo {
751
+ color: var(--primary);
752
+ }
753
+
754
+ dialog {
755
+ position: relative;
756
+ width: 430px;
757
+ max-width: 100vw;
758
+ background: var(--secondary);
759
+ color: var(--foreground);
760
+ border: 0 solid transparent;
761
+ border-top: 4px solid var(--primary);
762
+ border-radius: 20px;
763
+ padding: 24px;
764
+ text-align: center;
765
+ }
766
+
767
+ dialog::backdrop {
768
+ background: var(--backdrop);
769
+ backdrop-filter: blur(4px);
770
+ }
771
+
772
+ .dismiss {
773
+ position: absolute;
774
+ right: 20px;
775
+ top: 20px;
776
+ padding: 0;
777
+ border: 0;
778
+ border: 0;
779
+ background: transparent;
780
+ color: var(--foreground);
781
+ cursor: pointer;
782
+ }
783
+
784
+ .dismiss > svg {
785
+ display: block;
786
+ width: 32px;
787
+ height: 32px;
788
+ }
789
+
790
+ input[name='email'] {
791
+ box-sizing: border-box;
792
+ width: 100%;
793
+ border: 1px solid var(--input-border);
794
+ color: var(--input-foreground);
795
+ background: var(--input-background);
796
+ padding: 10px 16px;
797
+ border-radius: 5px;
798
+ }
799
+
800
+ input[name='email']::placeholder {
801
+ color: var(--input-foreground);
802
+ }
803
+
804
+ .restore {
805
+ width: 100%;
806
+ border: none;
807
+ color: var(--foreground);
808
+ background: var(--primary);
809
+ border-radius: 5px;
810
+ padding: 10px 16px;
811
+ }
812
+
813
+ .banner {
814
+ position: fixed;
815
+ z-index: var(--z-index);
816
+ bottom: 8px;
817
+ left: 50%;
818
+ padding: 12px 32px;
819
+ border-radius: 32px;
820
+ transform: translateX(-50%);
821
+ color: var(--foreground);
822
+ background: var(--secondary);
823
+ border: none;
824
+ border-bottom: 3px solid var(--primary);
825
+ display: flex;
826
+ gap: 8px;
827
+ align-items: center;
828
+ pointer-events: none;
829
+ }
830
+ `,
831
+ ];
832
+ __decorate([
833
+ n$1({ type: String }),
834
+ __metadata("design:type", Object)
835
+ ], BlotoutWallet.prototype, "position", void 0);
836
+ __decorate([
837
+ e$2('dialog'),
838
+ __metadata("design:type", HTMLDialogElement)
839
+ ], BlotoutWallet.prototype, "_dialog", void 0);
840
+ __decorate([
841
+ e$2('button.cta'),
842
+ __metadata("design:type", HTMLButtonElement)
843
+ ], BlotoutWallet.prototype, "_button", void 0);
844
+ __decorate([
845
+ e$2('input[name=email]'),
846
+ __metadata("design:type", HTMLInputElement)
847
+ ], BlotoutWallet.prototype, "_email", void 0);
848
+ __decorate([
849
+ e$2('.banner'),
850
+ __metadata("design:type", HTMLDivElement)
851
+ ], BlotoutWallet.prototype, "_banner", void 0);
852
+ __decorate([
853
+ r(),
854
+ __metadata("design:type", Boolean)
855
+ ], BlotoutWallet.prototype, "_buttonVisible", void 0);
856
+ __decorate([
857
+ r(),
858
+ __metadata("design:type", Boolean)
859
+ ], BlotoutWallet.prototype, "_bannerVisible", void 0);
860
+ __decorate([
861
+ r(),
862
+ __metadata("design:type", Boolean)
863
+ ], BlotoutWallet.prototype, "_hasItemsInWallet", void 0);
864
+ __decorate([
865
+ r(),
866
+ __metadata("design:type", Boolean)
867
+ ], BlotoutWallet.prototype, "_hasEmail", void 0);
868
+ BlotoutWallet = __decorate([
869
+ t$1('blotout-wallet')
870
+ ], BlotoutWallet);
871
+
216
872
  const init = (params) => {
217
- var _a;
218
- if (window && document && !getComponent()) {
219
- const element = document.createElement('blotout-wallet');
220
- element.setAttribute('tag-name', params.manifest.tagName);
221
- setComponent(element);
222
- const api = new WalletAPI({
873
+ var _a, _b;
874
+ if (window && document && !window[registryKey].wallet) {
875
+ window[registryKey].walletAPI = new WalletAPI({
223
876
  baseUrl: params.baseUrl,
224
877
  userId: params.userId,
225
878
  });
226
- setAPI(api);
227
- const store = (_a = window[symbol]) === null || _a === void 0 ? void 0 : _a.call(window);
879
+ const store = (window[registryKey].storeAPI =
880
+ (_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a));
228
881
  if (!store) {
229
882
  throw new Error('Implementation for store API missing!');
230
883
  }
884
+ const element = (window[registryKey].wallet =
885
+ document.createElement('blotout-wallet'));
886
+ element.setAttribute('tag-name', params.manifest.tagName);
231
887
  document.body.append(element);
232
- syncCartItems(api, store);
233
888
  }
234
889
  };
235
890
 
891
+ const canLog = () => {
892
+ try {
893
+ return localStorage.getItem('edgeTagDebug') === '1';
894
+ }
895
+ catch {
896
+ return false;
897
+ }
898
+ };
899
+ const logger = {
900
+ log: (...args) => {
901
+ if (canLog()) {
902
+ console.log(...args);
903
+ }
904
+ },
905
+ error: (...args) => {
906
+ if (canLog()) {
907
+ console.error(...args);
908
+ }
909
+ },
910
+ info: (...args) => {
911
+ if (canLog()) {
912
+ console.info(...args);
913
+ }
914
+ },
915
+ trace: (...args) => {
916
+ if (canLog()) {
917
+ console.trace(...args);
918
+ }
919
+ },
920
+ table: (...args) => {
921
+ if (canLog()) {
922
+ console.table(...args);
923
+ }
924
+ },
925
+ dir: (...args) => {
926
+ if (canLog()) {
927
+ console.dir(...args);
928
+ }
929
+ },
930
+ };
931
+
236
932
  const transformItems = (data) => {
237
933
  var _a;
238
934
  return (_a = data.contents) === null || _a === void 0 ? void 0 : _a.map((item) => ({
239
935
  productId: item.id,
240
936
  variantId: item.variantId || null,
241
- name: item.description || '',
937
+ name: item.title || item.description || '',
242
938
  amount: parseInt(item.quantity.toString()),
243
939
  value: parseFloat(item.item_price.toString()),
244
940
  }));
245
941
  };
246
942
  const tag = (params) => {
247
- const api = getAPI();
943
+ const wallet = window[registryKey].walletAPI;
944
+ if (!wallet) {
945
+ return;
946
+ }
248
947
  switch (params.eventName) {
249
948
  case 'AddToCart': {
250
949
  const items = transformItems(params.data);
251
950
  if (items) {
252
- api.addItems(items).catch(logger.error);
951
+ wallet.addItems(items).catch(logger.error);
253
952
  }
254
953
  return;
255
954
  }
256
955
  case 'InitiateCheckout': {
257
956
  const items = transformItems(params.data);
258
957
  if (items) {
259
- api.setItems(items).catch(logger.error);
958
+ wallet.setItems(items).catch(logger.error);
260
959
  }
261
960
  return;
262
961
  }
263
962
  case 'Purchase': {
264
963
  const { orderId } = params.data;
265
- api.purchase(orderId).catch(logger.error);
964
+ wallet.purchase(orderId).catch(logger.error);
266
965
  return;
267
966
  }
268
967
  }