@blotoutio/providers-shop-gpt-sdk 0.68.1

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 ADDED
@@ -0,0 +1,1423 @@
1
+ const expand = (str) => str.split(',').flatMap((entry) => {
2
+ if (!entry.includes('-')) {
3
+ return entry;
4
+ }
5
+ const result = [];
6
+ const [start, end] = entry.split('-').map(Number);
7
+ for (let i = start; i <= end; i++) {
8
+ result.push(i.toString());
9
+ }
10
+ return result;
11
+ });
12
+ /**
13
+ * Exported from https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes
14
+ *
15
+ * In Dev Tools, select the `tbody` element containing the area codes and run the following code,
16
+ * replacing the emdash character with a simple endash:
17
+ *
18
+ * ```ts
19
+ * [...$0.querySelectorAll('td:first-child')]
20
+ * .filter(cell => cell.firstChild.nodeName != 'A')
21
+ * .map(cell => cell.textContent.trim()).join(',')
22
+ * ```
23
+ */
24
+ new Set([
25
+ ...expand('200,211,221,222,230,232,233,235,237-238,241,243,244,245,247,255,257,258-259,261,265,266,271,273,274,275,277,278,280,282,283,285-287,288,290-299'),
26
+ ...expand('300,311,322,324,327,328,333,335,338,342,344,348-349,353,355,356,357-359,362,366,369,370-379,381,382,383-384,387,388,389,390-399'),
27
+ ...expand('400,411,420,421-422,426-427,428,429,433,439,444,446,449,451-454,455,456,457,459,460,461-462,465,466,467,471,476,477,481-483,485-486,487,488,489,490-499'),
28
+ ...expand('511,532,535,536,537,538,542-543,545-547,549-550,552-554,555,556,558,560,565,568,569,576,578,583,589,590-599'),
29
+ ...expand('611,621,624,625,627,632,633,634-635,637-638,642-643,644,648,652-654,655,663,665,666,668,673-676,677,679,685,686,687,688,690-699'),
30
+ ...expand('711,722,723,729,733,735-736,739,741,744,745-746,748,749-751,752,755,756,759,761,764,766,768,776,777,783,788,789,790-799'),
31
+ ...expand('811,821,822,823-824,827,834,836,841-842,846,851,852-853,871,874-875,879,880-887,889,890-899'),
32
+ ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
33
+ ]);
34
+
35
+ const packageName = 'shopGPT';
36
+
37
+ var _a$1;
38
+ const registryKey = Symbol.for('shop-gpt');
39
+ if (typeof window != 'undefined') {
40
+ (_a$1 = window[registryKey]) !== null && _a$1 !== void 0 ? _a$1 : (window[registryKey] = {});
41
+ }
42
+
43
+ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, storeAPI, }) => {
44
+ if (!baseURL) {
45
+ throw new Error(`baseURL missing`);
46
+ }
47
+ if (!userId) {
48
+ throw new Error(`userId missing`);
49
+ }
50
+ if (!storeAPI) {
51
+ throw new Error(`store API implementation missing`);
52
+ }
53
+ const getHeaders = (json = false) => {
54
+ const headers = new Headers({ EdgeTagUserId: userId });
55
+ if (json) {
56
+ headers.set('Content-type', 'application/json; charset=utf-8');
57
+ }
58
+ return headers;
59
+ };
60
+ const getURL = (path) => {
61
+ const url = new URL(`/providers/shopGPT${path}`, baseURL);
62
+ return url;
63
+ };
64
+ const processQuery = async (query) => {
65
+ const response = await fetchImpl(getURL('/query'), {
66
+ method: 'POST',
67
+ headers: getHeaders(),
68
+ body: JSON.stringify({ query, timestamp: Date.now() }),
69
+ credentials: 'include',
70
+ });
71
+ if (!response.ok) {
72
+ throw new Error(`Failed to process the query - ${response.status}: ${await response.text()}`);
73
+ }
74
+ const data = (await response.json());
75
+ return {
76
+ message: data.message,
77
+ products: data.products.map((item) => ({ ...item, quantity: 1 })),
78
+ };
79
+ };
80
+ const queryPrompts = async () => {
81
+ const response = await fetchImpl(getURL('/query-prompts'), {
82
+ method: 'GET',
83
+ headers: getHeaders(),
84
+ credentials: 'include',
85
+ });
86
+ if (!response.ok) {
87
+ throw new Error(`Could not fetch query Prompts - ${response.status}: ${await response.text()}`);
88
+ }
89
+ const data = (await response.json());
90
+ return data.prompts;
91
+ };
92
+ const initialPrompt = async (productId) => {
93
+ const response = await fetchImpl(getURL('/query-initial-prompt'), {
94
+ method: 'POST',
95
+ headers: getHeaders(),
96
+ body: JSON.stringify({ productId }),
97
+ credentials: 'include',
98
+ });
99
+ if (!response.ok) {
100
+ throw new Error(`Could not fetch query Prompts - ${response.status}: ${await response.text()}`);
101
+ }
102
+ const data = (await response.json());
103
+ return data.prompt;
104
+ };
105
+ const fetchChatHistory = async () => {
106
+ const response = await fetchImpl(getURL('/query-history'), {
107
+ method: 'GET',
108
+ headers: getHeaders(),
109
+ credentials: 'include',
110
+ });
111
+ if (!response.ok) {
112
+ throw new Error(`Could not fetch query history - ${response.status}: ${await response.text()}`);
113
+ }
114
+ const data = (await response.json());
115
+ return data.history;
116
+ };
117
+ return {
118
+ processQuery,
119
+ queryPrompts,
120
+ initialPrompt,
121
+ fetchChatHistory,
122
+ };
123
+ };
124
+
125
+ const error = (message) => console.error(message);
126
+ const init = (params) => {
127
+ var _a, _b, _c;
128
+ if (typeof window == 'undefined' || typeof document == 'undefined') {
129
+ // if loaded in non-browser SDKs, return early
130
+ return;
131
+ }
132
+ let storeAPI = window[registryKey].storeAPI;
133
+ if (!storeAPI) {
134
+ storeAPI = window[registryKey].storeAPI =
135
+ (_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a);
136
+ }
137
+ if (!storeAPI) {
138
+ error('Implementation for store API missing!');
139
+ return;
140
+ }
141
+ if (window.top !== window) {
142
+ // exit if not in top window
143
+ return;
144
+ }
145
+ const { enabled } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
146
+ if (enabled) {
147
+ const uiImplementation = window[registryKey].ui;
148
+ if (!uiImplementation) {
149
+ error('UI implementation is missing');
150
+ return;
151
+ }
152
+ const shopGPTAPI = createShopGPTAPI({
153
+ baseURL: params.baseUrl,
154
+ storeAPI,
155
+ userId: params.userId,
156
+ });
157
+ uiImplementation.init({
158
+ storeAPI,
159
+ shopGPTAPI,
160
+ });
161
+ }
162
+ };
163
+
164
+ // eslint-disable-next-line @nx/enforce-module-boundaries
165
+ const data = {
166
+ name: packageName,
167
+ init,
168
+ };
169
+ try {
170
+ if (typeof window !== 'undefined') {
171
+ window.edgetagProviders = window.edgetagProviders || [];
172
+ window.edgetagProviders.push(data);
173
+ }
174
+ }
175
+ catch {
176
+ // no window
177
+ }
178
+
179
+ /******************************************************************************
180
+ Copyright (c) Microsoft Corporation.
181
+
182
+ Permission to use, copy, modify, and/or distribute this software for any
183
+ purpose with or without fee is hereby granted.
184
+
185
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
186
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
187
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
188
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
189
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
190
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
191
+ PERFORMANCE OF THIS SOFTWARE.
192
+ ***************************************************************************** */
193
+ /* global Reflect, Promise, SuppressedError, Symbol */
194
+
195
+
196
+ function __decorate(decorators, target, key, desc) {
197
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
198
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
199
+ 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;
200
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
201
+ }
202
+
203
+ function __metadata(metadataKey, metadataValue) {
204
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
205
+ }
206
+
207
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
208
+ var e = new Error(message);
209
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
210
+ };
211
+
212
+ /**
213
+ * @license
214
+ * Copyright 2019 Google LLC
215
+ * SPDX-License-Identifier: BSD-3-Clause
216
+ */
217
+ const t$2=globalThis,e$4=t$2.ShadowRoot&&(void 0===t$2.ShadyCSS||t$2.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$3 = 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$4&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$2=(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$3(o,t,s$2)},S$1=(s,o)=>{if(e$4)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$2.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$4?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
218
+
219
+ /**
220
+ * @license
221
+ * Copyright 2017 Google LLC
222
+ * SPDX-License-Identifier: BSD-3-Clause
223
+ */const{is:i$1,defineProperty:e$3,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=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$1(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$3(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$2(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$2(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");
224
+
225
+ /**
226
+ * @license
227
+ * Copyright 2017 Google LLC
228
+ * SPDX-License-Identifier: BSD-3-Clause
229
+ */
230
+ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$2="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,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$1:d>=0?(o.push(a),s.slice(0,d)+e$2+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$2)){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?i.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$1)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$1.litHtmlPolyfillSupport;Z?.(V,M),(t$1.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};
231
+
232
+ /**
233
+ * @license
234
+ * Copyright 2017 Google LLC
235
+ * SPDX-License-Identifier: BSD-3-Clause
236
+ */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");
237
+
238
+ /**
239
+ * @license
240
+ * Copyright 2017 Google LLC
241
+ * SPDX-License-Identifier: BSD-3-Clause
242
+ */
243
+ const t=t=>(e,o)=>{void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
244
+
245
+ /**
246
+ * @license
247
+ * Copyright 2017 Google LLC
248
+ * SPDX-License-Identifier: BSD-3-Clause
249
+ */const o={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1},r$1=(t=o,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(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)}
250
+
251
+ /**
252
+ * @license
253
+ * Copyright 2017 Google LLC
254
+ * SPDX-License-Identifier: BSD-3-Clause
255
+ */function r(r){return n({...r,state:!0,attribute:!1})}
256
+
257
+ /**
258
+ * @license
259
+ * Copyright 2017 Google LLC
260
+ * SPDX-License-Identifier: BSD-3-Clause
261
+ */
262
+ const e$1=(e,t,c)=>(c.configurable=!0,c.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
263
+
264
+ /**
265
+ * @license
266
+ * Copyright 2017 Google LLC
267
+ * SPDX-License-Identifier: BSD-3-Clause
268
+ */function e(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$1(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$1(n,s,{get(){return o(this)}})}}
269
+
270
+ const canLog = () => {
271
+ try {
272
+ return localStorage.getItem('edgeTagDebug') === '1';
273
+ }
274
+ catch {
275
+ return false;
276
+ }
277
+ };
278
+ const logger = {
279
+ log: (...args) => {
280
+ if (canLog()) {
281
+ console.log(...args);
282
+ }
283
+ },
284
+ error: (...args) => {
285
+ if (canLog()) {
286
+ console.error(...args);
287
+ }
288
+ },
289
+ info: (...args) => {
290
+ if (canLog()) {
291
+ console.info(...args);
292
+ }
293
+ },
294
+ trace: (...args) => {
295
+ if (canLog()) {
296
+ console.trace(...args);
297
+ }
298
+ },
299
+ table: (...args) => {
300
+ if (canLog()) {
301
+ console.table(...args);
302
+ }
303
+ },
304
+ dir: (...args) => {
305
+ if (canLog()) {
306
+ console.dir(...args);
307
+ }
308
+ },
309
+ };
310
+
311
+ const shopGPTStyles = () => i$2 `
312
+ :host {
313
+ position: fixed;
314
+ top: 0;
315
+ left: 0;
316
+ height: 100%;
317
+ width: 100%;
318
+ }
319
+
320
+ ::-webkit-scrollbar {
321
+ width: 20px;
322
+ }
323
+
324
+ ::-webkit-scrollbar-track {
325
+ background-color: transparent;
326
+ }
327
+
328
+ ::-webkit-scrollbar-thumb {
329
+ background-color: #d6dee1;
330
+ border-radius: 20px;
331
+ border: 6px solid transparent;
332
+ background-clip: content-box;
333
+ }
334
+
335
+ ::-webkit-scrollbar-thumb:hover {
336
+ background-color: #a8bbbf;
337
+ }
338
+
339
+ * {
340
+ box-sizing: border-box;
341
+ }
342
+
343
+ body {
344
+ font-family: Inter;
345
+ margin: 0;
346
+ padding: 0;
347
+ }
348
+
349
+ .container {
350
+ display: flex;
351
+ flex-direction: column;
352
+ overflow: hidden;
353
+ height: 100%;
354
+ background: #ffffff;
355
+ font-size: 16px;
356
+ font-style: normal;
357
+ font-weight: 400;
358
+ line-height: 21px;
359
+ }
360
+
361
+ .header {
362
+ display: flex;
363
+ justify-content: space-between;
364
+ align-items: center;
365
+ padding: 24px;
366
+ text-align: center;
367
+ border-bottom: 1px solid #d4d4d8;
368
+ height: 114px;
369
+
370
+ @media screen and (max-width: 430px) {
371
+ height: 68px;
372
+ padding: 16px;
373
+ }
374
+ }
375
+
376
+ .header-title,
377
+ .chat-header-title {
378
+ color: #000;
379
+ font-size: 20px;
380
+ font-weight: 700;
381
+ font-style: normal;
382
+ line-height: 28px;
383
+ text-align: left;
384
+ text-underline-position: from-font;
385
+ text-decoration-skip-ink: none;
386
+ margin: 0;
387
+ }
388
+
389
+ @media screen and (max-width: 430px) {
390
+ .header-title {
391
+ font-size: 16px;
392
+ line-height: 24px;
393
+ }
394
+
395
+ .product-content {
396
+ max-width: calc(100vw - 150px);
397
+ }
398
+ }
399
+
400
+ .loader {
401
+ display: flex;
402
+ flex: 1;
403
+ width: 100%;
404
+ height: 100%;
405
+ align-items: center;
406
+ justify-content: center;
407
+ z-index: 5000;
408
+
409
+ .spinner {
410
+ /* --webkit-animation: spin 1s linear infinite; */
411
+ animation: 1s linear infinite spin;
412
+ border-radius: 50%;
413
+ border: 5px solid #f9d5ba;
414
+ border-top: 5px solid #555;
415
+ width: 30px;
416
+ height: 30px;
417
+ margin: 10px;
418
+ }
419
+ }
420
+
421
+ @keyframes spin {
422
+ 0% {
423
+ transform: rotate(0deg);
424
+ }
425
+ 100% {
426
+ transform: rotate(360deg);
427
+ }
428
+ }
429
+
430
+ .header-sub-title,
431
+ .chat-header-sub-title {
432
+ color: #000;
433
+ font-size: 12px;
434
+ font-weight: 400;
435
+ font-style: normal;
436
+ line-height: 12px;
437
+ text-align: left;
438
+ text-underline-position: from-font;
439
+ text-decoration-skip-ink: none;
440
+ margin: 0;
441
+ }
442
+
443
+ .header-pre-alpha {
444
+ @media screen and (max-width: 768px) {
445
+ display: none;
446
+ }
447
+ }
448
+
449
+ .body {
450
+ display: flex;
451
+ flex: 1;
452
+
453
+ @media screen and (max-width: 430px) {
454
+ flex-direction: column;
455
+ justify-content: flex-end;
456
+ }
457
+ }
458
+
459
+ .products-section {
460
+ flex: 1 0 0;
461
+ display: flex;
462
+ flex-direction: column;
463
+ justify-content: center;
464
+ align-items: center;
465
+ gap: 1px;
466
+ border-right: 1px solid #d4d4d8;
467
+ background: #f5f3ee;
468
+
469
+ .product-section {
470
+ flex: 1;
471
+ padding: 24px;
472
+ width: 100%;
473
+
474
+ h2 {
475
+ color: #a49b94;
476
+ font-size: 18px;
477
+ font-weight: 700;
478
+ line-height: 24px;
479
+ text-transform: uppercase;
480
+ margin: 0 0 24px;
481
+ }
482
+
483
+ p.no-product-text {
484
+ color: #000;
485
+ font-size: 18px;
486
+ line-height: 24px;
487
+ opacity: 0.6;
488
+ }
489
+ }
490
+
491
+ .hidden {
492
+ display: none;
493
+ }
494
+
495
+ .show-more,
496
+ .show-less {
497
+ display: none;
498
+ margin: 16px 0;
499
+ color: #a49b94;
500
+ text-align: center;
501
+ font-size: 14px;
502
+ font-weight: 700;
503
+ line-height: 12px;
504
+ letter-spacing: -0.28px;
505
+ text-transform: uppercase;
506
+ }
507
+
508
+ @media screen and (max-width: 430px) {
509
+ flex: 0;
510
+ box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1),
511
+ 0px 2px 4px -1px rgba(0, 0, 0, 0.06);
512
+ z-index: 1;
513
+
514
+ .product-section {
515
+ padding: 16px 16px 0;
516
+
517
+ h2 {
518
+ display: flex;
519
+ font-size: 12px;
520
+ font-weight: 700;
521
+ line-height: 18px;
522
+ letter-spacing: -0.36px;
523
+ margin: 0 0 16px;
524
+ color: #53433a;
525
+ align-items: center;
526
+ gap: 16px;
527
+
528
+ &::after {
529
+ content: '';
530
+ flex-grow: 1;
531
+ height: 1px;
532
+ background: #a49b94;
533
+ }
534
+ }
535
+
536
+ .no-products {
537
+ display: none;
538
+ }
539
+ }
540
+
541
+ .product-section.recommended-product h2 {
542
+ display: none;
543
+ }
544
+
545
+ .show-more,
546
+ .show-less {
547
+ display: block;
548
+ }
549
+ }
550
+ }
551
+
552
+ @media screen and (max-width: 430px) {
553
+ .no-recommended-product {
554
+ display: none;
555
+ }
556
+ }
557
+
558
+ .recommended-product {
559
+ border-bottom: 1px solid #d4d4d8;
560
+
561
+ .product {
562
+ display: flex;
563
+ gap: 12px;
564
+
565
+ /* .buy-now-btn {
566
+ cursor: pointer;
567
+ padding: 7px 37px;
568
+ background: #971b1b;
569
+ border-radius: 5px;
570
+ margin-top: 12px;
571
+ color: #ffffff;
572
+ font-size: 18px;
573
+ line-height: 24px;
574
+ letter-spacing: -0.35px;
575
+ border: 0;
576
+ } */
577
+
578
+ /* Replica of TrueClassic */
579
+ .buy-now-btn {
580
+ cursor: pointer;
581
+ padding: 7px 37px;
582
+ background: #53433a;
583
+ border-radius: 5px;
584
+ margin-top: 12px;
585
+ color: #ffffff;
586
+ font-size: 18px;
587
+ line-height: 24px;
588
+ letter-spacing: -0.35px;
589
+ border: 0;
590
+ text-transform: uppercase;
591
+
592
+ :hover {
593
+ background-color: #2e2520;
594
+ }
595
+
596
+ :active {
597
+ background-color: #0c0a09;
598
+ }
599
+ }
600
+
601
+ p {
602
+ margin: 0;
603
+ }
604
+
605
+ img {
606
+ cursor: pointer;
607
+ width: 170px;
608
+ height: 213px;
609
+ }
610
+
611
+ .product-name,
612
+ .product-variation-details {
613
+ cursor: pointer;
614
+ font-size: 16px;
615
+ line-height: 24px;
616
+ color: #3f3f46;
617
+ white-space: nowrap;
618
+ overflow: hidden;
619
+ text-overflow: ellipsis;
620
+ margin-bottom: 12px;
621
+ }
622
+ }
623
+
624
+ @media screen and (max-width: 430px) {
625
+ border-bottom: unset;
626
+
627
+ .product {
628
+ img {
629
+ height: 132px;
630
+ width: 106px;
631
+ }
632
+
633
+ .product-name,
634
+ .product-variation-details {
635
+ margin: 0;
636
+ }
637
+ }
638
+ }
639
+ }
640
+
641
+ .more-recommendations {
642
+ padding: 15px;
643
+
644
+ .products {
645
+ display: flex;
646
+ overflow: hidden;
647
+ justify-content: space-between;
648
+ align-items: center;
649
+ padding: 0 16px;
650
+ }
651
+
652
+ .product {
653
+ max-width: 140px;
654
+
655
+ p {
656
+ margin: 0;
657
+ }
658
+
659
+ .product-name,
660
+ .product-variation-details {
661
+ cursor: pointer;
662
+ color: #3f3f46;
663
+ font-size: 16px;
664
+ line-height: 24px;
665
+ white-space: nowrap;
666
+ overflow: hidden;
667
+ text-overflow: ellipsis;
668
+ }
669
+
670
+ img {
671
+ cursor: pointer;
672
+ width: 140px;
673
+ height: 175px;
674
+ }
675
+ }
676
+
677
+ @media screen and (max-width: 430px) {
678
+ display: none;
679
+
680
+ .products {
681
+ padding: 0px;
682
+ }
683
+
684
+ .product {
685
+ max-width: 108px;
686
+
687
+ .product-name,
688
+ .product-variation-details {
689
+ font-size: 12px;
690
+ line-height: 18px;
691
+ letter-spacing: -0.36px;
692
+ margin: 0;
693
+ }
694
+
695
+ img {
696
+ height: 133px;
697
+ width: 108px;
698
+ }
699
+ }
700
+ }
701
+ }
702
+
703
+ @media screen and (max-width: 430px) {
704
+ .show-more-sml {
705
+ display: block;
706
+ }
707
+ }
708
+
709
+ .product-prices {
710
+ display: flex;
711
+ gap: 0 8px;
712
+ line-height: 24px;
713
+ font-weight: 700;
714
+ font-size: 18px;
715
+ color: #000000;
716
+
717
+ .compared-at-price {
718
+ color: #a1a1aa;
719
+ text-decoration: line-through;
720
+ }
721
+
722
+ @media screen and (max-width: 430px) {
723
+ font-size: 14px;
724
+ line-height: 21px;
725
+ }
726
+ }
727
+
728
+ .chatbot-section {
729
+ flex: 1;
730
+ flex-direction: column;
731
+ padding: 10px 24px 24px;
732
+ background: #fff;
733
+ display: flex;
734
+ gap: 25px;
735
+ align-self: stretch;
736
+
737
+ @media screen and (max-width: 430px) {
738
+ padding: 10px 16px 16px;
739
+ gap: 16px;
740
+ }
741
+ }
742
+
743
+ .chat-header {
744
+ flex: 1;
745
+ display: flex;
746
+ flex-direction: column;
747
+ overflow-y: auto;
748
+ justify-content: flex-end;
749
+ }
750
+
751
+ .chat-window {
752
+ flex: 1;
753
+ display: flex;
754
+ flex-direction: column-reverse;
755
+ overflow-y: auto;
756
+ gap: 28px;
757
+ max-height: calc(100vh - 211px);
758
+
759
+ @media screen and (max-width: 430px) {
760
+ max-height: unset;
761
+ gap: 24px;
762
+ }
763
+ }
764
+
765
+ .chat-header {
766
+ align-items: center;
767
+
768
+ .chat-header-sub-title {
769
+ margin-bottom: 16px;
770
+ }
771
+
772
+ .chat-header-description {
773
+ text-align: center;
774
+ line-height: 24px;
775
+ }
776
+ }
777
+
778
+ .bot-message-container {
779
+ display: flex;
780
+ gap: 0 16px;
781
+ }
782
+
783
+ .message {
784
+ color: #18181b;
785
+ font-size: 16px;
786
+ }
787
+
788
+ .message.user {
789
+ padding: 8px 14px;
790
+ background: #f1f1f1;
791
+ align-self: flex-end;
792
+ max-width: 45%;
793
+ border-radius: 17.5px;
794
+ text-align: right;
795
+ letter-spacing: -0.32px;
796
+
797
+ @media screen and (max-width: 430px) {
798
+ max-width: 70%;
799
+ }
800
+ }
801
+
802
+ .message.bot {
803
+ align-self: flex-start;
804
+ max-width: 70%;
805
+
806
+ p {
807
+ margin: 0;
808
+ }
809
+
810
+ .product {
811
+ margin-top: 16px;
812
+ display: flex;
813
+ gap: 12px;
814
+
815
+ .product-name,
816
+ .product-variation-details {
817
+ cursor: pointer;
818
+ margin-bottom: 8px;
819
+ }
820
+
821
+ img {
822
+ cursor: pointer;
823
+ width: 75px;
824
+ height: 93px;
825
+ }
826
+
827
+ @media screen and (max-width: 430px) {
828
+ display: none;
829
+
830
+ .product-name,
831
+ .product-variation-details {
832
+ margin: 0;
833
+ }
834
+ }
835
+ }
836
+ }
837
+
838
+ .predefined-prompts {
839
+ margin: 24px 0;
840
+ display: flex;
841
+ align-items: start;
842
+ flex-wrap: wrap;
843
+ gap: 16px 8px;
844
+
845
+ button {
846
+ padding: 10px 16px;
847
+ cursor: pointer;
848
+ border-radius: 21px;
849
+ border: 1px solid #d4d4d8;
850
+ color: #8b2822;
851
+ background: #fff;
852
+ }
853
+ }
854
+
855
+ .chat-input {
856
+ display: flex;
857
+ align-items: center;
858
+
859
+ input {
860
+ flex: 1;
861
+ height: 48px;
862
+ padding: 11px 50px 11px 16px;
863
+ border-radius: 24px;
864
+ background: #f1f1f1;
865
+ border-style: none;
866
+ border: 0px;
867
+ font-size: 16px;
868
+
869
+ &:focus {
870
+ outline-width: 0;
871
+ box-shadow: 0 0 4px rgba(57, 123, 244, 0.5);
872
+ }
873
+
874
+ &::placeholder {
875
+ color: #52525b;
876
+ }
877
+ }
878
+
879
+ button {
880
+ cursor: pointer;
881
+ position: absolute;
882
+ right: 36px;
883
+ width: 30px;
884
+ height: 30px;
885
+ display: flex;
886
+ justify-content: center;
887
+ align-items: center;
888
+ border: 0px solid;
889
+ border-radius: 50%;
890
+ background: #8b2822;
891
+
892
+ &:disabled {
893
+ background: #808080;
894
+ }
895
+ }
896
+ }
897
+
898
+ input {
899
+ &:focus {
900
+ outline-width: 0;
901
+ }
902
+ }
903
+
904
+ button {
905
+ &:focus {
906
+ outline-style: none;
907
+ }
908
+
909
+ &:focus-visible {
910
+ outline-style: none;
911
+ }
912
+ }
913
+ `;
914
+
915
+ const sendFilledIcon = () => b `
916
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
917
+ <g id="send--filled 1" clip-path="url(#clip0_11627_1046)">
918
+ <path id="Vector" d="M18.1564 9.44101L4.40636 2.56601C4.29859 2.51211 4.17754 2.49052 4.05778 2.50382C3.93803 2.51713 3.82467 2.56477 3.73136 2.64101C3.64225 2.71569 3.57574 2.81375 3.5393 2.92416C3.50287 3.03457 3.49795 3.15296 3.52511 3.26601L5.18136 9.37226H12.2501V10.6223H5.18136L3.50011 16.7098C3.47463 16.8042 3.47165 16.9032 3.49143 16.999C3.5112 17.0948 3.55317 17.1846 3.61396 17.2612C3.67475 17.3378 3.75267 17.399 3.84144 17.44C3.93022 17.481 4.02738 17.5006 4.12511 17.4973C4.22295 17.4967 4.31928 17.4731 4.40636 17.4285L18.1564 10.5535C18.2587 10.5011 18.3447 10.4214 18.4046 10.3232C18.4646 10.2251 18.4964 10.1123 18.4964 9.99726C18.4964 9.88223 18.4646 9.76943 18.4046 9.67129C18.3447 9.57314 18.2587 9.49346 18.1564 9.44101Z" fill="white"/>
919
+ </g>
920
+ <defs>
921
+ <clip-path id="clip0_11627_1046">
922
+ <rect width="20" height="20" fill="white"/>
923
+ </clip-path>
924
+ </defs>
925
+ </svg>
926
+ `;
927
+ const botIcon = () => b `
928
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
929
+ <circle cx="12" cy="12" r="12" fill="black"/>
930
+ <path d="M10.6465 7.71833L11.048 8.83333C11.494 10.0708 12.4685 11.0453 13.706 11.4913L14.821 11.8928C14.9215 11.9293 14.9215 12.0718 14.821 12.1078L13.706 12.5093C12.4685 12.9553 11.494 13.9298 11.048 15.1673L10.6465 16.2823C10.61 16.3828 10.4675 16.3828 10.4315 16.2823L10.03 15.1673C9.58402 13.9298 8.60952 12.9553 7.37202 12.5093L6.25702 12.1078C6.15652 12.0713 6.15652 11.9288 6.25702 11.8928L7.37202 11.4913C8.60952 11.0453 9.58402 10.0708 10.03 8.83333L10.4315 7.71833C10.4675 7.61733 10.61 7.61733 10.6465 7.71833Z" fill="white"/>
931
+ <path d="M15.6655 5.03863L15.869 5.60313C16.095 6.22963 16.5885 6.72313 17.215 6.94913L17.7795 7.15263C17.8305 7.17113 17.8305 7.24312 17.7795 7.26163L17.215 7.46513C16.5885 7.69113 16.095 8.18463 15.869 8.81113L15.6655 9.37563C15.647 9.42663 15.575 9.42663 15.5565 9.37563L15.353 8.81113C15.127 8.18463 14.6335 7.69113 14.007 7.46513L13.4425 7.26163C13.3915 7.24312 13.3915 7.17113 13.4425 7.15263L14.007 6.94913C14.6335 6.72313 15.127 6.22963 15.353 5.60313L15.5565 5.03863C15.575 4.98712 15.6475 4.98712 15.6655 5.03863Z" fill="white"/>
932
+ <path d="M15.6655 14.6242L15.869 15.1887C16.095 15.8152 16.5885 16.3087 17.215 16.5347L17.7795 16.7382C17.8305 16.7567 17.8305 16.8287 17.7795 16.8472L17.215 17.0507C16.5885 17.2767 16.095 17.7702 15.869 18.3967L15.6655 18.9612C15.647 19.0122 15.575 19.0122 15.5565 18.9612L15.353 18.3967C15.127 17.7702 14.6335 17.2767 14.007 17.0507L13.4425 16.8472C13.3915 16.8287 13.3915 16.7567 13.4425 16.7382L14.007 16.5347C14.6335 16.3087 15.127 15.8152 15.353 15.1887L15.5565 14.6242C15.575 14.5732 15.6475 14.5732 15.6655 14.6242Z" fill="white"/>
933
+ </svg>
934
+ `;
935
+
936
+ const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
937
+ const getImageProperties = (src) => {
938
+ const image = new URL(src);
939
+ const srcSet = IMAGE_WIDTHS.map((width) => {
940
+ image.searchParams.set('width', width.toString());
941
+ return `${image.toString()} ${width}w`;
942
+ });
943
+ return {
944
+ srcset: srcSet.join(', '),
945
+ sizes: '(min-width: 1200px) 140px, (min-width: 990px) 33%',
946
+ };
947
+ };
948
+ let ShopGPT = class ShopGPT extends s {
949
+ constructor() {
950
+ super(...arguments);
951
+ this.recommendedProduct = null;
952
+ this.moreRecommendations = [];
953
+ this.chatbotMessages = [];
954
+ this.userMessage = '';
955
+ this.isLoadingHistory = false;
956
+ this.isTyping = false;
957
+ this.isFailed = false;
958
+ this.showMore = false;
959
+ this.promptSuggestions = [];
960
+ this.submitQuery = (message) => {
961
+ if (!message) {
962
+ return;
963
+ }
964
+ this.isFailed = false;
965
+ return this.shopGPTAPI.processQuery(message);
966
+ };
967
+ this.onAddToCart = async (ev) => {
968
+ ev.preventDefault();
969
+ ev.stopPropagation();
970
+ await this.storeAPI
971
+ .addToCart({
972
+ quantity: 1,
973
+ productId: this.productId.value,
974
+ variantId: this.variantId.value,
975
+ })
976
+ .catch(logger.error);
977
+ };
978
+ }
979
+ connectedCallback() {
980
+ super.connectedCallback();
981
+ window.addEventListener('edgetag-initialized', async () => {
982
+ if (!this.shopGPTAPI) {
983
+ return;
984
+ }
985
+ await this.loadHistory();
986
+ });
987
+ }
988
+ async loadHistory() {
989
+ var _a, _b, _c;
990
+ try {
991
+ this.isLoadingHistory = true;
992
+ const data = await this.shopGPTAPI.fetchChatHistory();
993
+ this.chatbotMessages = data.map((message) => {
994
+ var _a;
995
+ return ({
996
+ message: message.message,
997
+ sender: message.sender,
998
+ quantity: 1,
999
+ product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
1000
+ });
1001
+ });
1002
+ if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length) > 0) {
1003
+ const products = data[0].products.map((product) => ({
1004
+ ...product,
1005
+ quantity: 1,
1006
+ }));
1007
+ this.recommendedProduct = products[0];
1008
+ this.moreRecommendations = products.slice(1, 4);
1009
+ }
1010
+ }
1011
+ catch (e) {
1012
+ logger.error(e);
1013
+ }
1014
+ finally {
1015
+ this.isLoadingHistory = false;
1016
+ }
1017
+ }
1018
+ redirect(url) {
1019
+ var _a;
1020
+ if (!url) {
1021
+ return;
1022
+ }
1023
+ (_a = open(url, '_blank')) === null || _a === void 0 ? void 0 : _a.focus();
1024
+ }
1025
+ scrollToBottom() {
1026
+ if (!this.chatWindowElement) {
1027
+ return;
1028
+ }
1029
+ this.chatWindowElement.scrollTo({
1030
+ top: this.chatWindowElement.scrollHeight,
1031
+ behavior: 'smooth',
1032
+ });
1033
+ }
1034
+ resetProductRecommendations() {
1035
+ this.recommendedProduct = null;
1036
+ this.moreRecommendations = [];
1037
+ }
1038
+ async sendMessageToServer(e, message) {
1039
+ e.preventDefault();
1040
+ e.stopPropagation();
1041
+ if (!message || this.isTyping || this.isLoadingHistory) {
1042
+ return;
1043
+ }
1044
+ try {
1045
+ this.chatbotMessages = [
1046
+ { sender: 'user', message: message },
1047
+ ...this.chatbotMessages,
1048
+ ];
1049
+ this.isTyping = true;
1050
+ this.userMessage = '';
1051
+ this.scrollToBottom();
1052
+ const reply = await this.submitQuery(message);
1053
+ if (!reply) {
1054
+ return;
1055
+ }
1056
+ this.chatbotMessages = [
1057
+ { sender: 'bot', message: reply.message, product: reply.products[0] },
1058
+ ...this.chatbotMessages,
1059
+ ];
1060
+ this.recommendedProduct = reply.products[0];
1061
+ this.moreRecommendations = reply.products.slice(1, 4);
1062
+ this.setChatWindowHeight();
1063
+ }
1064
+ catch (e) {
1065
+ logger.error(e);
1066
+ this.resetProductRecommendations();
1067
+ this.isFailed = true;
1068
+ }
1069
+ finally {
1070
+ this.isTyping = false;
1071
+ }
1072
+ }
1073
+ // TODO: ShopGPT - This needs to come from StoreAPI and should utilize Store SDK to figure out the currency
1074
+ getCurrencySymbol() {
1075
+ return '$';
1076
+ }
1077
+ handleShowMore(value) {
1078
+ if (!this.chatWindowElement) {
1079
+ return;
1080
+ }
1081
+ this.showMore = value;
1082
+ // dynamically add the maximum height when more products are shown
1083
+ const height = value ? 'calc(100vh - 580px' : 'calc(100vh - 351px)';
1084
+ this.chatWindowElement.style.maxHeight = height;
1085
+ }
1086
+ setChatWindowHeight() {
1087
+ if (!this.chatWindowElement) {
1088
+ return;
1089
+ }
1090
+ if (window.innerWidth < 430) {
1091
+ this.chatWindowElement.style.maxHeight = 'calc(100vh - 351px)';
1092
+ }
1093
+ else {
1094
+ this.chatWindowElement.style.maxHeight = 'calc(100vh - 221px)';
1095
+ }
1096
+ }
1097
+ render() {
1098
+ return x `
1099
+ <div class="container">
1100
+ <div class="header">
1101
+ <div>
1102
+ <h1 class="header-title">ShopGPT</h1>
1103
+ <p class="header-sub-title">powered by Blotout</p>
1104
+ </div>
1105
+ <div class="header-pre-alpha">Pre-Alpha Release v0.1</div>
1106
+ </div>
1107
+
1108
+ <div class="body">${this.productSection()} ${this.chatSection()}</div>
1109
+ </div>
1110
+ `;
1111
+ }
1112
+ productSection() {
1113
+ var _a;
1114
+ return x `
1115
+ <div
1116
+ class="products-section ${!this.recommendedProduct
1117
+ ? 'no-recommended-product'
1118
+ : ''}"
1119
+ >
1120
+ <div class="product-section recommended-product">
1121
+ <h2>Recommended product</h2>
1122
+ ${!((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.id)
1123
+ ? x `
1124
+ <p class="no-product-text">
1125
+ Enter what you’re looking for in the chat to get product
1126
+ results.
1127
+ </p>
1128
+ `
1129
+ : x `
1130
+ <div class="product">
1131
+ <img
1132
+ src=${this.recommendedProduct.image.url}
1133
+ alt=${this.recommendedProduct.image.alt}
1134
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1135
+ />
1136
+ <div class="product-content">
1137
+ <p
1138
+ class="product-name"
1139
+ title=${this.recommendedProduct.title}
1140
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1141
+ >
1142
+ ${this.recommendedProduct.title}
1143
+ </p>
1144
+ ${this.recommendedProduct.variants[0].selectedOptions.map((option) => x `
1145
+ <p class="product-variation-details">
1146
+ ${option.name}: ${option.value}
1147
+ </p>
1148
+ `)}
1149
+ <div class="product-prices">
1150
+ ${this.recommendedProduct.variants[0].comparedAtPrice &&
1151
+ this.recommendedProduct.variants[0].comparedAtPrice !==
1152
+ this.recommendedProduct.variants[0].price
1153
+ ? x `<p class="compared-at-price">
1154
+ ${this.getCurrencySymbol()}${this.recommendedProduct
1155
+ .variants[0].comparedAtPrice}
1156
+ </p>`
1157
+ : T}
1158
+ <p class="price">
1159
+ ${this.getCurrencySymbol()}${this.recommendedProduct
1160
+ .variants[0].price}
1161
+ </p>
1162
+ </div>
1163
+ <button
1164
+ class="buy-now-btn"
1165
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1166
+ >
1167
+ Add To Cart
1168
+ </button>
1169
+ </div>
1170
+ </div>
1171
+ `}
1172
+ </div>
1173
+
1174
+ <div
1175
+ class="product-section more-recommendations ${this.showMore
1176
+ ? 'show-more-sml'
1177
+ : ''}"
1178
+ >
1179
+ <h2>More Recommendations</h2>
1180
+ ${this.moreRecommendations.length === 0
1181
+ ? x `
1182
+ <p class="no-product-text">
1183
+ Enter what you’re looking for in the chat to get product
1184
+ results.
1185
+ </p>
1186
+ `
1187
+ : x `<div class="products">
1188
+ ${this.moreRecommendations.map((product) => {
1189
+ const imageProperties = getImageProperties(product.image.url);
1190
+ return x `
1191
+ <div class="product">
1192
+ <img
1193
+ srcset=${imageProperties.srcset}
1194
+ sizes=${imageProperties.sizes}
1195
+ src=${product.image.url}
1196
+ alt=${product.image.alt}
1197
+ @click=${() => this.redirect(product.url)}
1198
+ />
1199
+ <p
1200
+ class="product-name"
1201
+ title=${product.title}
1202
+ @click=${() => this.redirect(product.url)}
1203
+ >
1204
+ ${product.title}
1205
+ </p>
1206
+ <div class="product-prices">
1207
+ ${product.variants[0].comparedAtPrice &&
1208
+ product.variants[0].comparedAtPrice !==
1209
+ product.variants[0].price
1210
+ ? x `<p class="compared-at-price">
1211
+ ${this.getCurrencySymbol()}${product.variants[0]
1212
+ .comparedAtPrice}
1213
+ </p>`
1214
+ : T}
1215
+ <p class="price">
1216
+ ${this.getCurrencySymbol()}${product.variants[0]
1217
+ .price}
1218
+ </p>
1219
+ </div>
1220
+ </div>
1221
+ `;
1222
+ })}
1223
+ </div>`}
1224
+ </div>
1225
+
1226
+ ${this.showMore
1227
+ ? x `
1228
+ <div class="show-less" @click=${() => this.handleShowMore(false)}>
1229
+ Show less
1230
+ </div>
1231
+ `
1232
+ : x `
1233
+ <div class="show-more" @click=${() => this.handleShowMore(true)}>
1234
+ Show more
1235
+ </div>
1236
+ `}
1237
+ </div>
1238
+ `;
1239
+ }
1240
+ chatWindow() {
1241
+ if (this.isLoadingHistory) {
1242
+ return x ` <div class="loader"><div class="spinner"></div></div> `;
1243
+ }
1244
+ if (this.chatbotMessages.length === 0) {
1245
+ return x `
1246
+ <div class="chat-header">
1247
+ <div class="chat-header-title">ShopGPT</div>
1248
+ <div class="chat-header-sub-title">powered by Blotout</div>
1249
+ <div class="chat-header-description">
1250
+ Hi, type a message to get started!
1251
+ </div>
1252
+ </div>
1253
+ `;
1254
+ }
1255
+ return x `
1256
+ <div class="chat-window">
1257
+ ${this.isTyping
1258
+ ? x `<div class="bot-message-container">
1259
+ ${botIcon()}
1260
+ <div class="message bot">Typing...</div>
1261
+ </div>`
1262
+ : ''}
1263
+ ${this.isFailed
1264
+ ? x `<div class="bot-message-container">
1265
+ ${botIcon()}
1266
+ <div class="message bot">
1267
+ Something went wrong please try again!
1268
+ </div>
1269
+ </div>`
1270
+ : ''}
1271
+ ${this.chatbotMessages.map((message) => {
1272
+ if (message.sender === 'bot') {
1273
+ return x `
1274
+ <div class="bot-message-container">
1275
+ ${botIcon()}
1276
+ <div class="message bot">
1277
+ <p>${message.message}</p>
1278
+ ${message.product
1279
+ ? x `<div class="product">
1280
+ <img
1281
+ src=${message.product.image.url}
1282
+ alt=${message.product.image.alt}
1283
+ @click=${() => { var _a; return this.redirect((_a = message.product) === null || _a === void 0 ? void 0 : _a.url); }}
1284
+ />
1285
+ <div>
1286
+ <p
1287
+ class="product-name"
1288
+ title=${message.product.title}
1289
+ @click=${() => { var _a; return this.redirect((_a = message.product) === null || _a === void 0 ? void 0 : _a.url); }}
1290
+ >
1291
+ ${message.product.title}
1292
+ </p>
1293
+ <div class="product-prices">
1294
+ ${message.product.variants[0].comparedAtPrice &&
1295
+ message.product.variants[0].comparedAtPrice !==
1296
+ message.product.variants[0].comparedAtPrice
1297
+ ? x `<p class="compared-at-price">
1298
+ ${this.getCurrencySymbol()}${message.product
1299
+ .variants[0].comparedAtPrice}
1300
+ </p>`
1301
+ : T}
1302
+ <p class="price">
1303
+ ${this.getCurrencySymbol()}${message.product
1304
+ .variants[0].price}
1305
+ </p>
1306
+ </div>
1307
+ </div>
1308
+ </div>`
1309
+ : T}
1310
+ </div>
1311
+ </div>
1312
+ `;
1313
+ }
1314
+ return x ` <div class="message user">${message.message}</div> `;
1315
+ })}
1316
+ </div>
1317
+ `;
1318
+ }
1319
+ predefinedPrompts() {
1320
+ // TODO: ShopGPT - Handle prompt clicks, should enable this when LLM supports it.
1321
+ return x `
1322
+ <div class="predefined-prompts" style="display:none;">
1323
+ ${this.promptSuggestions.map((prompt) => x ` <button>${prompt}</button> `)}
1324
+ </div>
1325
+ `;
1326
+ }
1327
+ chatSection() {
1328
+ return x `
1329
+ <div class="chatbot-section">
1330
+ ${this.chatWindow()} ${this.predefinedPrompts()}
1331
+ <form
1332
+ class="chat-input"
1333
+ @submit=${async (e) => { var _a; return await this.sendMessageToServer(e, (_a = this.userMessage) === null || _a === void 0 ? void 0 : _a.trim()); }}
1334
+ >
1335
+ <input
1336
+ type="text"
1337
+ .value=${this.userMessage}
1338
+ @input=${(e) => (this.userMessage = e.target.value)}
1339
+ placeholder="Type your message here"
1340
+ />
1341
+ <button
1342
+ type="submit"
1343
+ ?disabled=${this.isTyping || this.isLoadingHistory}
1344
+ >
1345
+ ${sendFilledIcon()}
1346
+ </button>
1347
+ </form>
1348
+ </div>
1349
+ `;
1350
+ }
1351
+ };
1352
+ ShopGPT.styles = [shopGPTStyles()];
1353
+ __decorate([
1354
+ n({ type: Object }),
1355
+ __metadata("design:type", Object)
1356
+ ], ShopGPT.prototype, "recommendedProduct", void 0);
1357
+ __decorate([
1358
+ n({ type: Array }),
1359
+ __metadata("design:type", Array)
1360
+ ], ShopGPT.prototype, "moreRecommendations", void 0);
1361
+ __decorate([
1362
+ r(),
1363
+ __metadata("design:type", Array)
1364
+ ], ShopGPT.prototype, "chatbotMessages", void 0);
1365
+ __decorate([
1366
+ r(),
1367
+ __metadata("design:type", Object)
1368
+ ], ShopGPT.prototype, "userMessage", void 0);
1369
+ __decorate([
1370
+ e('input[name=productId]'),
1371
+ __metadata("design:type", HTMLInputElement)
1372
+ ], ShopGPT.prototype, "productId", void 0);
1373
+ __decorate([
1374
+ e('input[name=variantId]'),
1375
+ __metadata("design:type", HTMLInputElement)
1376
+ ], ShopGPT.prototype, "variantId", void 0);
1377
+ __decorate([
1378
+ e('.chat-window'),
1379
+ __metadata("design:type", Object)
1380
+ ], ShopGPT.prototype, "chatWindowElement", void 0);
1381
+ __decorate([
1382
+ n({ type: Boolean }),
1383
+ __metadata("design:type", Boolean)
1384
+ ], ShopGPT.prototype, "isLoadingHistory", void 0);
1385
+ __decorate([
1386
+ n({ type: Boolean }),
1387
+ __metadata("design:type", Boolean)
1388
+ ], ShopGPT.prototype, "isTyping", void 0);
1389
+ __decorate([
1390
+ n({ type: Boolean }),
1391
+ __metadata("design:type", Boolean)
1392
+ ], ShopGPT.prototype, "isFailed", void 0);
1393
+ __decorate([
1394
+ n({ type: Boolean }),
1395
+ __metadata("design:type", Boolean)
1396
+ ], ShopGPT.prototype, "showMore", void 0);
1397
+ __decorate([
1398
+ r(),
1399
+ __metadata("design:type", Array)
1400
+ ], ShopGPT.prototype, "promptSuggestions", void 0);
1401
+ ShopGPT = __decorate([
1402
+ t('shop-gpt')
1403
+ ], ShopGPT);
1404
+
1405
+ var _a, _b;
1406
+ var _c;
1407
+ let shopGPT;
1408
+ if (typeof window != 'undefined' && typeof document != 'undefined') {
1409
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
1410
+ (_b = (_c = window[registryKey]).ui) !== null && _b !== void 0 ? _b : (_c.ui = {
1411
+ init(params) {
1412
+ if (shopGPT) {
1413
+ return;
1414
+ }
1415
+ shopGPT = document.createElement('shop-gpt');
1416
+ shopGPT.storeAPI = params.storeAPI;
1417
+ shopGPT.shopGPTAPI = params.shopGPTAPI;
1418
+ document.body.append(shopGPT);
1419
+ },
1420
+ });
1421
+ }
1422
+
1423
+ export { data as default };