@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.js CHANGED
@@ -3,47 +3,6 @@ var ProvidersBlotoutWalletSdk = (function () {
3
3
 
4
4
  const packageName = 'blotoutWallet';
5
5
 
6
- const canLog = () => {
7
- try {
8
- return localStorage.getItem('edgeTagDebug') === '1';
9
- }
10
- catch {
11
- return false;
12
- }
13
- };
14
- const logger = {
15
- log: (...args) => {
16
- if (canLog()) {
17
- console.log(...args);
18
- }
19
- },
20
- error: (...args) => {
21
- if (canLog()) {
22
- console.error(...args);
23
- }
24
- },
25
- info: (...args) => {
26
- if (canLog()) {
27
- console.info(...args);
28
- }
29
- },
30
- trace: (...args) => {
31
- if (canLog()) {
32
- console.trace(...args);
33
- }
34
- },
35
- table: (...args) => {
36
- if (canLog()) {
37
- console.table(...args);
38
- }
39
- },
40
- dir: (...args) => {
41
- if (canLog()) {
42
- console.dir(...args);
43
- }
44
- },
45
- };
46
-
47
6
  class APIError extends Error {
48
7
  constructor(...args) {
49
8
  super(...args);
@@ -52,7 +11,7 @@ var ProvidersBlotoutWalletSdk = (function () {
52
11
  class WalletAPI {
53
12
  constructor({ baseUrl, userId }) {
54
13
  this.listeners = new Set();
55
- this._cart = null;
14
+ this._cart = { cartId: null, items: [], email: false };
56
15
  this.baseUrl = baseUrl;
57
16
  this.userId = userId;
58
17
  }
@@ -82,10 +41,8 @@ var ProvidersBlotoutWalletSdk = (function () {
82
41
  return this._cart;
83
42
  }
84
43
  set cart(value) {
85
- if (this._cart !== value) {
86
- this._cart = value;
87
- this.notify();
88
- }
44
+ this._cart = value;
45
+ this.notify();
89
46
  }
90
47
  subscribe(listener) {
91
48
  this.listeners.add(listener);
@@ -99,9 +56,6 @@ var ProvidersBlotoutWalletSdk = (function () {
99
56
  headers: this.getHeaders(),
100
57
  }).then(async (response) => {
101
58
  if (!response.ok) {
102
- if (response.status == 404) {
103
- return (this.cart = null);
104
- }
105
59
  throw new APIError(`Could not fetch cart contents`, {
106
60
  cause: response,
107
61
  });
@@ -170,34 +124,400 @@ var ProvidersBlotoutWalletSdk = (function () {
170
124
  if (!response.ok) {
171
125
  throw new APIError(`Could not mark purchase`, { cause: response });
172
126
  }
127
+ this.cart = { cartId: null, email: this.cart.email, items: [] };
128
+ this.notify();
129
+ });
130
+ }
131
+ saveEmail(email) {
132
+ return fetch(this.getUrl('/cart/email'), {
133
+ method: 'POST',
134
+ body: JSON.stringify({ email }),
135
+ headers: this.getHeaders(true),
136
+ }).then((response) => {
137
+ if (!response.ok) {
138
+ throw new APIError('Could not save email', { cause: response });
139
+ }
140
+ this.cart.email = true;
141
+ this.notify();
142
+ });
143
+ }
144
+ restore() {
145
+ return fetch(this.getUrl('/cart/restore'), {
146
+ method: 'POST',
147
+ headers: this.getHeaders(),
148
+ }).then((response) => {
149
+ if (!response.ok) {
150
+ throw new APIError('Could not mark cart as restored', {
151
+ cause: response,
152
+ });
153
+ }
173
154
  });
174
155
  }
175
156
  }
176
157
 
177
- let api;
178
- let component;
179
- const setComponent = (_component) => {
180
- component = _component;
181
- };
182
- const setAPI = (_api) => {
183
- api = _api;
158
+ var _a;
159
+ const registryKey = Symbol.for('blotout-wallet');
160
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
161
+
162
+ /******************************************************************************
163
+ Copyright (c) Microsoft Corporation.
164
+
165
+ Permission to use, copy, modify, and/or distribute this software for any
166
+ purpose with or without fee is hereby granted.
167
+
168
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
169
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
170
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
171
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
172
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
173
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
174
+ PERFORMANCE OF THIS SOFTWARE.
175
+ ***************************************************************************** */
176
+ /* global Reflect, Promise, SuppressedError, Symbol */
177
+
178
+
179
+ function __decorate(decorators, target, key, desc) {
180
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
181
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
182
+ 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;
183
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
184
+ }
185
+
186
+ function __metadata(metadataKey, metadataValue) {
187
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
188
+ }
189
+
190
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
191
+ var e = new Error(message);
192
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
184
193
  };
185
- const getAPI = () => api;
186
- const getComponent = () => component;
187
194
 
188
- const symbol = Symbol.for('blotout-store-implementation');
195
+ /**
196
+ * @license
197
+ * Copyright 2019 Google LLC
198
+ * SPDX-License-Identifier: BSD-3-Clause
199
+ */
200
+ 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;
201
+
202
+ /**
203
+ * @license
204
+ * Copyright 2017 Google LLC
205
+ * SPDX-License-Identifier: BSD-3-Clause
206
+ */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");
207
+
208
+ /**
209
+ * @license
210
+ * Copyright 2017 Google LLC
211
+ * SPDX-License-Identifier: BSD-3-Clause
212
+ */
213
+ 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};
214
+
215
+ /**
216
+ * @license
217
+ * Copyright 2017 Google LLC
218
+ * SPDX-License-Identifier: BSD-3-Clause
219
+ */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");
220
+
221
+ /**
222
+ * @license
223
+ * Copyright 2017 Google LLC
224
+ * SPDX-License-Identifier: BSD-3-Clause
225
+ */
226
+ const t$1=t=>(e,o)=>{void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
227
+
228
+ /**
229
+ * @license
230
+ * Copyright 2017 Google LLC
231
+ * SPDX-License-Identifier: BSD-3-Clause
232
+ */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)}
233
+
234
+ /**
235
+ * @license
236
+ * Copyright 2017 Google LLC
237
+ * SPDX-License-Identifier: BSD-3-Clause
238
+ */function r(r){return n$1({...r,state:!0,attribute:!1})}
239
+
240
+ /**
241
+ * @license
242
+ * Copyright 2017 Google LLC
243
+ * SPDX-License-Identifier: BSD-3-Clause
244
+ */
245
+ const e$3=(e,t,c)=>(c.configurable=!0,c.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
246
+
247
+ /**
248
+ * @license
249
+ * Copyright 2017 Google LLC
250
+ * SPDX-License-Identifier: BSD-3-Clause
251
+ */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)}})}}
189
252
 
253
+ /**
254
+ * @license
255
+ * Copyright 2017 Google LLC
256
+ * SPDX-License-Identifier: BSD-3-Clause
257
+ */
258
+ 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)}};
259
+
260
+ /**
261
+ * @license
262
+ * Copyright 2018 Google LLC
263
+ * SPDX-License-Identifier: BSD-3-Clause
264
+ */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}});
265
+
266
+ /**
267
+ * @license
268
+ * Copyright 2018 Google LLC
269
+ * SPDX-License-Identifier: BSD-3-Clause
270
+ */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}});
271
+
272
+ 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)';
273
+ 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)';
274
+
275
+ const cssVars = i$4 `
276
+ :host {
277
+ --primary: var(--bw-primary, #f25c2b);
278
+ --secondary: var(--bw-secondary, #172a41);
279
+ --button: var(--bw-primary, #da2e3a);
280
+ --foreground: var(--bw-foreground, white);
281
+ --input-border: var(--bw-input-border, #dbe2eb);
282
+ --input-foreground: var(--wb-input-foreground, var(--secondary));
283
+ --input-background: var(--wb-input-background, white);
284
+ --backdrop: var(--wb-backdrop, #00000077);
285
+ --z-index: var(--wb-z-index, 9999);
286
+
287
+ --spring-easing: ${r$5(spring)};
288
+
289
+ --bounce-easing: ${r$5(bounce)};
290
+ }
291
+ `;
292
+
293
+ const wallet = (attrs) => b `<svg
294
+ width="32"
295
+ height="22"
296
+ viewBox="0 0 32 22"
297
+ fill="none"
298
+ xmlns="http://www.w3.org/2000/svg"
299
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
300
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
301
+ >
302
+ <g>
303
+ <path
304
+ fill-rule="evenodd"
305
+ clip-rule="evenodd"
306
+ 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"
307
+ fill="currentColor"
308
+ />
309
+ <path
310
+ 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"
311
+ fill="currentColor"
312
+ />
313
+ <path
314
+ fill-rule="evenodd"
315
+ clip-rule="evenodd"
316
+ 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"
317
+ fill="currentColor"
318
+ />
319
+ </g>
320
+ </svg>`;
321
+ const blotout = (attrs) => b `<svg
322
+ width="26"
323
+ height="36"
324
+ viewBox="0 0 26 36"
325
+ fill="none"
326
+ xmlns="http://www.w3.org/2000/svg"
327
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
328
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
329
+ >
330
+ <path
331
+ fill-rule="evenodd"
332
+ clip-rule="evenodd"
333
+ 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"
334
+ fill="currentColor"
335
+ />
336
+ </svg>`;
337
+ const wink = (attrs) => b `<svg
338
+ width="18"
339
+ height="18"
340
+ viewBox="0 0 18 18"
341
+ fill="none"
342
+ xmlns="http://www.w3.org/2000/svg"
343
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
344
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
345
+ >
346
+ <g>
347
+ <path
348
+ 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"
349
+ fill="currentColor"
350
+ />
351
+ <path
352
+ 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"
353
+ fill="currentColor"
354
+ />
355
+ <path d="M8.375 7.3125H5V8.4375H8.375V7.3125Z" fill="white" />
356
+ <path
357
+ 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"
358
+ fill="currentColor"
359
+ />
360
+ </g>
361
+ </svg> `;
362
+ const cross = (attrs) => b `<svg
363
+ width="32"
364
+ height="32"
365
+ viewBox="0 0 32 32"
366
+ fill="none"
367
+ xmlns="http://www.w3.org/2000/svg"
368
+ class=${attrs === null || attrs === void 0 ? void 0 : attrs.class}
369
+ style=${attrs === null || attrs === void 0 ? void 0 : attrs.style}
370
+ >
371
+ <g>
372
+ <path
373
+ 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"
374
+ fill="currentColor"
375
+ />
376
+ </g>
377
+ </svg> `;
378
+
379
+ const fadeInDialog = (element) => {
380
+ const dialogAnimation = element.animate([
381
+ { transform: 'translateY(-20px)', opacity: 0 },
382
+ { transform: 'translateY(0)', opacity: 1 },
383
+ ], { duration: 600, easing: spring, composite: 'add' });
384
+ const backdropAnimation = element.animate([{ opacity: 0 }, { opacity: 1 }], {
385
+ duration: 300,
386
+ easing: 'ease-out',
387
+ pseudoElement: '::backdrop',
388
+ fill: 'forwards',
389
+ });
390
+ return Promise.all([dialogAnimation.finished, backdropAnimation.finished]);
391
+ };
392
+ const fadeOutToBottom = (element) => {
393
+ const dialogAnimation = element.animate([
394
+ { transform: 'translateY(0)', opacity: 1 },
395
+ { transform: 'translateY(20px)', opacity: 0 },
396
+ ], { duration: 600, easing: spring });
397
+ const backdropAnimation = element.animate([{ opacity: 1 }, { opacity: 0 }], {
398
+ duration: 300,
399
+ easing: 'ease-out',
400
+ pseudoElement: '::backdrop',
401
+ fill: 'forwards',
402
+ });
403
+ return Promise.all([dialogAnimation.finished, backdropAnimation.finished]);
404
+ };
405
+ const springInFromLeft = (element, offset = '100%') => element.animate([{ transform: `translateX(-${offset})` }, { transform: 'translateX(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
406
+ const springInFromRight = (element, offset = '100%') => element.animate([{ transform: `translateX(${offset})` }, { transform: 'translateX(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
407
+ const springInFromTop = (element, offset = '100%') => element.animate([{ transform: `translateY(-${offset})` }, { transform: 'translateY(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
408
+ const springInFromBottom = (element, offset = '100%') => element.animate([{ transform: `translateY(${offset})` }, { transform: 'translateY(0)' }], { duration: 600, easing: bounce, composite: 'add' }).finished;
409
+ const springOutToLeft = (element, offset = '100%') => element.animate([{ transform: 'translateX(0)' }, { transform: `translateX(-${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
410
+ const springOutToRight = (element, offset = '100%') => element.animate([{ transform: 'translateX(0)' }, { transform: `translateX(${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
411
+ const springOutToTop = (element, offset = '100%') => element.animate([{ transform: 'translateY(0)' }, { transform: `translateY(-${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
412
+ const springOutToBottom = (element, offset = '100%') => element.animate([{ transform: 'translateY(0)' }, { transform: `translateY(${offset})` }], { duration: 600, easing: bounce, composite: 'add' }).finished;
413
+
414
+ const validPositions = new Set([
415
+ 'bottom',
416
+ 'bottom-left',
417
+ 'bottom-right',
418
+ 'left',
419
+ 'right',
420
+ 'top',
421
+ 'top-left',
422
+ 'top-right',
423
+ ]);
190
424
  const getItemKey = (item) => `${item.productId}-${item.variantId}`;
191
- const syncCartItems = async (api, storeApi) => {
192
- try {
193
- const [wallet, shopItems] = await Promise.all([
194
- api.getCart(),
195
- storeApi.getCart(),
425
+ const wait = (timeout) => new Promise((res) => setTimeout(res, timeout));
426
+ let BlotoutWallet = class BlotoutWallet extends s {
427
+ constructor() {
428
+ super(...arguments);
429
+ this._buttonVisible = false;
430
+ this._bannerVisible = false;
431
+ this._hasItemsInWallet = false;
432
+ this._hasEmail = false;
433
+ this.onWalletUpdated = () => {
434
+ const cart = this._walletApi.cart;
435
+ this._hasItemsInWallet = cart.items.length > 0;
436
+ if (this._hasItemsInWallet || !this._hasEmail) {
437
+ this.showButton();
438
+ }
439
+ else if (!this._hasItemsInWallet && this._hasEmail) {
440
+ this.hideButton();
441
+ }
442
+ };
443
+ this.onSubmit = (ev) => {
444
+ var _a;
445
+ ev.preventDefault();
446
+ ev.stopPropagation();
447
+ const modalAnimation = this.hideModal();
448
+ const email = (_a = this._email) === null || _a === void 0 ? void 0 : _a.value.trim();
449
+ if (email) {
450
+ this._walletApi.saveEmail(email)
451
+ .then(() => {
452
+ this._email.value = '';
453
+ this._hasEmail = true;
454
+ this.dispatchEvent(new CustomEvent('blotout-wallet-email-saved', { bubbles: true }));
455
+ })
456
+ .catch((err) => console.error(err));
457
+ }
458
+ if (this._hasItemsInWallet) {
459
+ this._storeApi.clearCart()
460
+ .then(() => this._storeApi.addItems(this._walletApi.cart.items))
461
+ .then(() => this._walletApi.restore())
462
+ .then(() => {
463
+ this.dispatchEvent(new CustomEvent('blotout-wallet-restored', { bubbles: true }));
464
+ return modalAnimation.then(() => this.showRestorationBanner());
465
+ })
466
+ .catch((err) => console.error(err));
467
+ }
468
+ };
469
+ this.showRestorationBanner = async () => {
470
+ this._bannerVisible = true;
471
+ await new Promise(requestAnimationFrame);
472
+ await springInFromBottom(this._banner, '120%');
473
+ await wait(5000);
474
+ await springOutToBottom(this._banner, '120%');
475
+ this._bannerVisible = false;
476
+ };
477
+ }
478
+ get _storeApi() {
479
+ var _a;
480
+ return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.storeAPI;
481
+ }
482
+ get _walletApi() {
483
+ var _a;
484
+ return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.walletAPI;
485
+ }
486
+ get _position() {
487
+ return validPositions.has(this.position) ? this.position : 'bottom-left';
488
+ }
489
+ connectedCallback() {
490
+ var _a;
491
+ super.connectedCallback();
492
+ this._unsubscribe = (_a = this._walletApi) === null || _a === void 0 ? void 0 : _a.subscribe(this.onWalletUpdated);
493
+ this.syncItems().then((hasItemsSaved) => {
494
+ this.dispatchEvent(new CustomEvent('blotout-wallet-loaded', { bubbles: true }));
495
+ this._hasItemsInWallet = hasItemsSaved;
496
+ if (this._hasItemsInWallet) {
497
+ this.showButton();
498
+ }
499
+ });
500
+ }
501
+ disconnectedCallback() {
502
+ var _a;
503
+ super.disconnectedCallback();
504
+ (_a = this._unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
505
+ this._unsubscribe = undefined;
506
+ }
507
+ async syncItems() {
508
+ if (!this._walletApi || !this._storeApi) {
509
+ console.error('The required APIs are not available');
510
+ return false;
511
+ }
512
+ const [savedCart, shopItems] = await Promise.all([
513
+ this._walletApi.getCart(),
514
+ this._storeApi.getCart(),
196
515
  ]);
197
- const lookup = new Map(wallet === null || wallet === void 0 ? void 0 : wallet.items.map((item) => [getItemKey(item), item]));
516
+ this._hasEmail = savedCart.email;
517
+ const savedItemsLookup = new Map(savedCart.items.map((item) => [getItemKey(item), item]));
198
518
  const missingItems = [];
199
519
  for (const item of shopItems) {
200
- const walletItem = lookup.get(getItemKey(item));
520
+ const walletItem = savedItemsLookup.get(getItemKey(item));
201
521
  if (!walletItem) {
202
522
  missingItems.push(item);
203
523
  }
@@ -209,63 +529,442 @@ var ProvidersBlotoutWalletSdk = (function () {
209
529
  }
210
530
  }
211
531
  if (missingItems.length > 0) {
212
- await api.addItems(missingItems);
532
+ await this._walletApi.addItems(missingItems);
533
+ }
534
+ return savedCart.items.length > 0;
535
+ }
536
+ async showButton() {
537
+ if (this._buttonVisible) {
538
+ return;
539
+ }
540
+ this._buttonVisible = true;
541
+ await new Promise(requestAnimationFrame).then(() => {
542
+ switch (this._position) {
543
+ case 'top-left':
544
+ case 'left':
545
+ case 'bottom-left': {
546
+ return springInFromLeft(this._button);
547
+ }
548
+ case 'top-right':
549
+ case 'right':
550
+ case 'bottom-right': {
551
+ return springInFromRight(this._button);
552
+ }
553
+ case 'bottom': {
554
+ return springInFromBottom(this._button);
555
+ }
556
+ case 'top': {
557
+ return springInFromTop(this._button);
558
+ }
559
+ default: {
560
+ return springInFromLeft(this._button);
561
+ }
562
+ }
563
+ });
564
+ this.dispatchEvent(new CustomEvent('blotout-wallet-shown', { bubbles: true }));
565
+ }
566
+ async hideButton() {
567
+ if (!this._buttonVisible) {
568
+ return;
569
+ }
570
+ switch (this._position) {
571
+ case 'top-left':
572
+ case 'left':
573
+ case 'bottom-left': {
574
+ await springOutToLeft(this._button);
575
+ break;
576
+ }
577
+ case 'top-right':
578
+ case 'right':
579
+ case 'bottom-right': {
580
+ await springOutToRight(this._button);
581
+ break;
582
+ }
583
+ case 'bottom': {
584
+ await springOutToBottom(this._button);
585
+ break;
586
+ }
587
+ case 'top': {
588
+ await springOutToTop(this._button);
589
+ break;
590
+ }
591
+ default: {
592
+ await springOutToLeft(this._button);
593
+ }
213
594
  }
595
+ this._buttonVisible = false;
596
+ this.dispatchEvent(new CustomEvent('blotout-wallet-hidden', { bubbles: true }));
597
+ }
598
+ async showModal() {
599
+ this._dialog.showModal();
600
+ await new Promise(requestAnimationFrame);
601
+ await fadeInDialog(this._dialog);
214
602
  }
215
- catch (err) {
216
- logger.error(err);
603
+ async hideModal() {
604
+ await fadeOutToBottom(this._dialog);
605
+ this._dialog.close();
606
+ }
607
+ render() {
608
+ return x `
609
+ <button
610
+ class="${e({
611
+ cta: true,
612
+ [this._position]: true,
613
+ hidden: !this._buttonVisible,
614
+ })}"
615
+ @click=${this.showModal}
616
+ >
617
+ ${wallet({ class: 'icon' })}
618
+ </button>
619
+
620
+ <dialog>
621
+ <button class="dismiss" @click=${this.hideModal}>${cross()}</button>
622
+ ${blotout({ class: 'logo' })}
623
+ <form method="dialog" @submit=${this.onSubmit}>
624
+ ${this._hasItemsInWallet
625
+ ? x `<p>
626
+ Hey! Your <strong>cart has expired!</strong><br />But we've got
627
+ you covered. ${wink({ style: 'vertical-align:middle' })}
628
+ </p>`
629
+ : x `<p>
630
+ Carts expire in 7 days.<br />But we can save your carts for life
631
+ ${wink({ style: 'vertical-align:middle' })}
632
+ </p>`}
633
+
634
+ <p>
635
+ <input
636
+ type="email"
637
+ name="email"
638
+ placeholder="Enter your email ID"
639
+ ?required=${!this._hasEmail}
640
+ style=${o({
641
+ display: this._hasEmail ? 'none' : 'block',
642
+ })}
643
+ />
644
+ </p>
645
+ <p>
646
+ <button class="restore" type="submit">
647
+ ${this._hasItemsInWallet ? 'Restore Cart' : 'Save Cart'}
648
+ </button>
649
+ </p>
650
+ </form>
651
+ </dialog>
652
+
653
+ <div
654
+ class="banner"
655
+ style=${o({ display: this._bannerVisible ? '' : 'none' })}
656
+ >
657
+ ${blotout({
658
+ class: 'logo',
659
+ style: 'height: 18px',
660
+ })}
661
+ <div>Cart restored!</div>
662
+ </div>
663
+ `;
217
664
  }
218
665
  };
666
+ BlotoutWallet.styles = [
667
+ cssVars,
668
+ i$4 `
669
+ * {
670
+ box-sizing: border-box;
671
+ font-family: inherit;
672
+ font-size: 16px;
673
+ line-height: 24px;
674
+ }
675
+
676
+ strong {
677
+ font-weight: bold;
678
+ }
679
+
680
+ button {
681
+ cursor: pointer;
682
+ }
683
+
684
+ .cta {
685
+ position: fixed;
686
+ z-index: var(--z-index);
687
+ background: var(--button);
688
+ color: var(--foreground);
689
+ padding: 8px;
690
+ border: none;
691
+ }
692
+
693
+ .top-left {
694
+ border-radius: 0 4px 4px 0;
695
+ left: 0;
696
+ top: 4px;
697
+ }
698
+
699
+ .top {
700
+ border-radius: 0 0 4px 4px;
701
+ left: 50%;
702
+ top: 0;
703
+ transform: translateX(-50%);
704
+ }
705
+
706
+ .top-right {
707
+ border-radius: 4px 0 0 4px;
708
+ right: 0;
709
+ top: 4px;
710
+ }
711
+
712
+ .left {
713
+ border-radius: 0 4px 4px 0;
714
+ left: 0;
715
+ top: 50%;
716
+ transform: translateY(-50%);
717
+ }
718
+
719
+ .right {
720
+ border-radius: 4px 0 0 4px;
721
+ right: 0;
722
+ top: 50%;
723
+ transform: translateY(-50%);
724
+ }
725
+
726
+ .bottom-left {
727
+ border-radius: 0 4px 4px 0;
728
+ left: 0;
729
+ bottom: 4px;
730
+ }
731
+
732
+ .bottom {
733
+ border-radius: 4px 4px 0 0;
734
+ left: 50%;
735
+ bottom: 0;
736
+ transform: translateX(-50%);
737
+ }
738
+
739
+ .bottom-right {
740
+ border-radius: 4px 0 0 4px;
741
+ right: 0;
742
+ bottom: 4px;
743
+ }
744
+
745
+ .hidden {
746
+ display: none;
747
+ }
748
+
749
+ .icon {
750
+ display: block;
751
+ }
752
+
753
+ .logo {
754
+ color: var(--primary);
755
+ }
756
+
757
+ dialog {
758
+ position: relative;
759
+ width: 430px;
760
+ max-width: 100vw;
761
+ background: var(--secondary);
762
+ color: var(--foreground);
763
+ border: 0 solid transparent;
764
+ border-top: 4px solid var(--primary);
765
+ border-radius: 20px;
766
+ padding: 24px;
767
+ text-align: center;
768
+ }
769
+
770
+ dialog::backdrop {
771
+ background: var(--backdrop);
772
+ backdrop-filter: blur(4px);
773
+ }
774
+
775
+ .dismiss {
776
+ position: absolute;
777
+ right: 20px;
778
+ top: 20px;
779
+ padding: 0;
780
+ border: 0;
781
+ border: 0;
782
+ background: transparent;
783
+ color: var(--foreground);
784
+ cursor: pointer;
785
+ }
786
+
787
+ .dismiss > svg {
788
+ display: block;
789
+ width: 32px;
790
+ height: 32px;
791
+ }
792
+
793
+ input[name='email'] {
794
+ box-sizing: border-box;
795
+ width: 100%;
796
+ border: 1px solid var(--input-border);
797
+ color: var(--input-foreground);
798
+ background: var(--input-background);
799
+ padding: 10px 16px;
800
+ border-radius: 5px;
801
+ }
802
+
803
+ input[name='email']::placeholder {
804
+ color: var(--input-foreground);
805
+ }
806
+
807
+ .restore {
808
+ width: 100%;
809
+ border: none;
810
+ color: var(--foreground);
811
+ background: var(--primary);
812
+ border-radius: 5px;
813
+ padding: 10px 16px;
814
+ }
815
+
816
+ .banner {
817
+ position: fixed;
818
+ z-index: var(--z-index);
819
+ bottom: 8px;
820
+ left: 50%;
821
+ padding: 12px 32px;
822
+ border-radius: 32px;
823
+ transform: translateX(-50%);
824
+ color: var(--foreground);
825
+ background: var(--secondary);
826
+ border: none;
827
+ border-bottom: 3px solid var(--primary);
828
+ display: flex;
829
+ gap: 8px;
830
+ align-items: center;
831
+ pointer-events: none;
832
+ }
833
+ `,
834
+ ];
835
+ __decorate([
836
+ n$1({ type: String }),
837
+ __metadata("design:type", Object)
838
+ ], BlotoutWallet.prototype, "position", void 0);
839
+ __decorate([
840
+ e$2('dialog'),
841
+ __metadata("design:type", HTMLDialogElement)
842
+ ], BlotoutWallet.prototype, "_dialog", void 0);
843
+ __decorate([
844
+ e$2('button.cta'),
845
+ __metadata("design:type", HTMLButtonElement)
846
+ ], BlotoutWallet.prototype, "_button", void 0);
847
+ __decorate([
848
+ e$2('input[name=email]'),
849
+ __metadata("design:type", HTMLInputElement)
850
+ ], BlotoutWallet.prototype, "_email", void 0);
851
+ __decorate([
852
+ e$2('.banner'),
853
+ __metadata("design:type", HTMLDivElement)
854
+ ], BlotoutWallet.prototype, "_banner", void 0);
855
+ __decorate([
856
+ r(),
857
+ __metadata("design:type", Boolean)
858
+ ], BlotoutWallet.prototype, "_buttonVisible", void 0);
859
+ __decorate([
860
+ r(),
861
+ __metadata("design:type", Boolean)
862
+ ], BlotoutWallet.prototype, "_bannerVisible", void 0);
863
+ __decorate([
864
+ r(),
865
+ __metadata("design:type", Boolean)
866
+ ], BlotoutWallet.prototype, "_hasItemsInWallet", void 0);
867
+ __decorate([
868
+ r(),
869
+ __metadata("design:type", Boolean)
870
+ ], BlotoutWallet.prototype, "_hasEmail", void 0);
871
+ BlotoutWallet = __decorate([
872
+ t$1('blotout-wallet')
873
+ ], BlotoutWallet);
874
+
219
875
  const init = (params) => {
220
- var _a;
221
- if (window && document && !getComponent()) {
222
- const element = document.createElement('blotout-wallet');
223
- element.setAttribute('tag-name', params.manifest.tagName);
224
- setComponent(element);
225
- const api = new WalletAPI({
876
+ var _a, _b;
877
+ if (window && document && !window[registryKey].wallet) {
878
+ window[registryKey].walletAPI = new WalletAPI({
226
879
  baseUrl: params.baseUrl,
227
880
  userId: params.userId,
228
881
  });
229
- setAPI(api);
230
- const store = (_a = window[symbol]) === null || _a === void 0 ? void 0 : _a.call(window);
882
+ const store = (window[registryKey].storeAPI =
883
+ (_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a));
231
884
  if (!store) {
232
885
  throw new Error('Implementation for store API missing!');
233
886
  }
887
+ const element = (window[registryKey].wallet =
888
+ document.createElement('blotout-wallet'));
889
+ element.setAttribute('tag-name', params.manifest.tagName);
234
890
  document.body.append(element);
235
- syncCartItems(api, store);
236
891
  }
237
892
  };
238
893
 
894
+ const canLog = () => {
895
+ try {
896
+ return localStorage.getItem('edgeTagDebug') === '1';
897
+ }
898
+ catch {
899
+ return false;
900
+ }
901
+ };
902
+ const logger = {
903
+ log: (...args) => {
904
+ if (canLog()) {
905
+ console.log(...args);
906
+ }
907
+ },
908
+ error: (...args) => {
909
+ if (canLog()) {
910
+ console.error(...args);
911
+ }
912
+ },
913
+ info: (...args) => {
914
+ if (canLog()) {
915
+ console.info(...args);
916
+ }
917
+ },
918
+ trace: (...args) => {
919
+ if (canLog()) {
920
+ console.trace(...args);
921
+ }
922
+ },
923
+ table: (...args) => {
924
+ if (canLog()) {
925
+ console.table(...args);
926
+ }
927
+ },
928
+ dir: (...args) => {
929
+ if (canLog()) {
930
+ console.dir(...args);
931
+ }
932
+ },
933
+ };
934
+
239
935
  const transformItems = (data) => {
240
936
  var _a;
241
937
  return (_a = data.contents) === null || _a === void 0 ? void 0 : _a.map((item) => ({
242
938
  productId: item.id,
243
939
  variantId: item.variantId || null,
244
- name: item.description || '',
940
+ name: item.title || item.description || '',
245
941
  amount: parseInt(item.quantity.toString()),
246
942
  value: parseFloat(item.item_price.toString()),
247
943
  }));
248
944
  };
249
945
  const tag = (params) => {
250
- const api = getAPI();
946
+ const wallet = window[registryKey].walletAPI;
947
+ if (!wallet) {
948
+ return;
949
+ }
251
950
  switch (params.eventName) {
252
951
  case 'AddToCart': {
253
952
  const items = transformItems(params.data);
254
953
  if (items) {
255
- api.addItems(items).catch(logger.error);
954
+ wallet.addItems(items).catch(logger.error);
256
955
  }
257
956
  return;
258
957
  }
259
958
  case 'InitiateCheckout': {
260
959
  const items = transformItems(params.data);
261
960
  if (items) {
262
- api.setItems(items).catch(logger.error);
961
+ wallet.setItems(items).catch(logger.error);
263
962
  }
264
963
  return;
265
964
  }
266
965
  case 'Purchase': {
267
966
  const { orderId } = params.data;
268
- api.purchase(orderId).catch(logger.error);
967
+ wallet.purchase(orderId).catch(logger.error);
269
968
  return;
270
969
  }
271
970
  }