@gengage/assistant-fe 0.4.21 → 0.5.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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/{api-paths-Bg6iwO5w.js → api-paths-XNsAaP_N.js} +1 -1
  3. package/dist/chat-runtime.js +1 -1
  4. package/dist/chat.iife.js +43 -43
  5. package/dist/chat.js +1 -1
  6. package/dist/common-Cb5WKXue.js +324 -0
  7. package/dist/common.js +64 -81
  8. package/dist/{connection-warning-BeD-B0Ec.js → connection-warning-BjfQKyV7.js} +1 -1
  9. package/dist/{fastIntent-BeeDIwd2.js → fastIntent-DxSSvrgK.js} +2 -2
  10. package/dist/index.js +49 -52
  11. package/dist/{native-webview-Bbcvvi_5.js → native-webview-BQPhKMli.js} +1 -1
  12. package/dist/native.iife.js +23 -23
  13. package/dist/native.js +1 -1
  14. package/dist/{overlay-O4nlUrzw.js → overlay-C0NSAZoL.js} +3 -6
  15. package/dist/overlay.js +2 -2
  16. package/dist/qna-runtime.js +1 -1
  17. package/dist/qna.iife.js +36 -36
  18. package/dist/qna.js +1 -1
  19. package/dist/{runtime-C8ZBidd2.js → runtime-B8Y5j1Xu.js} +176 -196
  20. package/dist/runtime-Bso-rbzX.js +654 -0
  21. package/dist/{runtime-Ct1qOl8V.js → runtime-CatBpqEd.js} +2194 -2225
  22. package/dist/{simbut-BrAeZ6SH.js → simbut-D2WpS0Y8.js} +7 -7
  23. package/dist/simbut.iife.js +12 -12
  24. package/dist/simbut.js +1 -1
  25. package/dist/{simrel-Cha5de6P.js → simrel-CNfVfah6.js} +2 -2
  26. package/dist/simrel-runtime.js +1 -1
  27. package/dist/simrel.iife.js +35 -35
  28. package/dist/simrel.js +2 -2
  29. package/dist/widget-base-CcNNPfdn.js +362 -0
  30. package/package.json +1 -2
  31. package/dist/common-DDJSeQhg.js +0 -491
  32. package/dist/runtime-CRSFPLku.js +0 -688
  33. package/dist/widget-base-BtBl_PCR.js +0 -589
  34. /package/dist/{context-DGz5F81j.js → context-BBuSsXZ9.js} +0 -0
@@ -1,589 +0,0 @@
1
- import { o as h, r as y } from "./context-DGz5F81j.js";
2
- function W(e, i) {
3
- const t = {
4
- event_name: "stream.start",
5
- account_id: e.account_id,
6
- session_id: e.session_id,
7
- correlation_id: e.correlation_id,
8
- payload: {
9
- endpoint: i.endpoint,
10
- request_id: i.request_id
11
- }
12
- };
13
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), i.widget !== void 0 && (t.widget = i.widget), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
14
- }
15
- function z(e, i) {
16
- const t = {
17
- request_id: i.request_id,
18
- chunk_index: i.chunk_index
19
- };
20
- i.latency_ms !== void 0 && (t.latency_ms = i.latency_ms);
21
- const n = {
22
- event_name: "stream.chunk",
23
- account_id: e.account_id,
24
- session_id: e.session_id,
25
- correlation_id: e.correlation_id,
26
- payload: t
27
- };
28
- return e.view_id !== void 0 && (n.view_id = e.view_id), e.user_id !== void 0 && (n.user_id = e.user_id), i.widget !== void 0 && (n.widget = i.widget), e.page_type !== void 0 && (n.page_type = e.page_type), e.sku !== void 0 && (n.sku = e.sku), n;
29
- }
30
- function Y(e, i) {
31
- const t = {
32
- event_name: "stream.ui_spec",
33
- account_id: e.account_id,
34
- session_id: e.session_id,
35
- correlation_id: e.correlation_id,
36
- payload: {
37
- request_id: i.request_id,
38
- chunk_index: i.chunk_index,
39
- component_type: i.component_type
40
- }
41
- };
42
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), i.widget !== void 0 && (t.widget = i.widget), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
43
- }
44
- function J(e, i) {
45
- const t = {
46
- event_name: "stream.done",
47
- account_id: e.account_id,
48
- session_id: e.session_id,
49
- correlation_id: e.correlation_id,
50
- payload: {
51
- request_id: i.request_id,
52
- latency_ms: i.latency_ms,
53
- chunk_count: i.chunk_count
54
- }
55
- };
56
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), i.widget !== void 0 && (t.widget = i.widget), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
57
- }
58
- function K(e, i) {
59
- const t = {
60
- event_name: "stream.error",
61
- account_id: e.account_id,
62
- session_id: e.session_id,
63
- correlation_id: e.correlation_id,
64
- payload: {
65
- request_id: i.request_id,
66
- error_code: i.error_code,
67
- error_message: i.error_message
68
- }
69
- };
70
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), i.widget !== void 0 && (t.widget = i.widget), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
71
- }
72
- function j(e, i) {
73
- const t = {
74
- model: i.model,
75
- prompt_tokens: i.prompt_tokens,
76
- completion_tokens: i.completion_tokens,
77
- total_tokens: i.total_tokens
78
- };
79
- i.provider !== void 0 && (t.provider = i.provider);
80
- const n = {
81
- event_name: "llm.usage",
82
- account_id: e.account_id,
83
- session_id: e.session_id,
84
- correlation_id: e.correlation_id,
85
- payload: t
86
- };
87
- return e.view_id !== void 0 && (n.view_id = e.view_id), e.user_id !== void 0 && (n.user_id = e.user_id), e.page_type !== void 0 && (n.page_type = e.page_type), e.sku !== void 0 && (n.sku = e.sku), n;
88
- }
89
- function Q(e, i) {
90
- const t = {
91
- event_name: "metering.increment",
92
- account_id: e.account_id,
93
- session_id: e.session_id,
94
- correlation_id: e.correlation_id,
95
- payload: {
96
- meter_key: i.meter_key,
97
- quantity: i.quantity,
98
- unit: i.unit
99
- }
100
- };
101
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
102
- }
103
- function w(e, i) {
104
- const t = {
105
- event_name: "metering.summary",
106
- account_id: e.account_id,
107
- session_id: e.session_id,
108
- correlation_id: e.correlation_id,
109
- payload: {
110
- meter_key: i.meter_key,
111
- quantity: i.quantity,
112
- unit: i.unit
113
- }
114
- };
115
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
116
- }
117
- function X(e, i) {
118
- const t = {
119
- event_name: "chat.history.snapshot",
120
- account_id: e.account_id,
121
- session_id: e.session_id,
122
- correlation_id: e.correlation_id,
123
- payload: {
124
- message_count: i.message_count,
125
- history_ref: i.history_ref,
126
- redaction_level: i.redaction_level
127
- }
128
- };
129
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
130
- }
131
- function Z(e, i) {
132
- const t = {
133
- event_name: "widget.history.snapshot",
134
- account_id: e.account_id,
135
- session_id: e.session_id,
136
- correlation_id: e.correlation_id,
137
- widget: i.widget,
138
- payload: {
139
- message_count: i.message_count,
140
- history_ref: i.history_ref,
141
- redaction_level: i.redaction_level
142
- }
143
- };
144
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
145
- }
146
- function x(e, i) {
147
- const t = {
148
- event_name: "basket.add",
149
- account_id: e.account_id,
150
- session_id: e.session_id,
151
- correlation_id: e.correlation_id,
152
- widget: i.attribution_source,
153
- payload: {
154
- attribution_source: i.attribution_source,
155
- attribution_action_id: i.attribution_action_id,
156
- cart_value: i.cart_value,
157
- currency: i.currency,
158
- line_items: i.line_items,
159
- sku: i.sku
160
- }
161
- };
162
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
163
- }
164
- function b(e, i) {
165
- const t = {
166
- event_name: "checkout.start",
167
- account_id: e.account_id,
168
- session_id: e.session_id,
169
- correlation_id: e.correlation_id,
170
- widget: i.attribution_source,
171
- payload: {
172
- attribution_source: i.attribution_source,
173
- attribution_action_id: i.attribution_action_id,
174
- cart_value: i.cart_value,
175
- currency: i.currency,
176
- line_items: i.line_items
177
- }
178
- };
179
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
180
- }
181
- function k(e, i) {
182
- const t = {
183
- event_name: "checkout.complete",
184
- account_id: e.account_id,
185
- session_id: e.session_id,
186
- correlation_id: e.correlation_id,
187
- widget: i.attribution_source,
188
- payload: {
189
- attribution_source: i.attribution_source,
190
- attribution_action_id: i.attribution_action_id,
191
- cart_value: i.cart_value,
192
- currency: i.currency,
193
- line_items: i.line_items
194
- }
195
- };
196
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
197
- }
198
- var _ = {
199
- "--gengage-chat-offset": "20px",
200
- "--gengage-chat-launcher-width": "56px",
201
- "--gengage-chat-launcher-height": "56px",
202
- "--gengage-chat-width": "400px",
203
- "--gengage-chat-shell-radius": "1rem",
204
- "--gengage-chat-header-height": "72px",
205
- "--gengage-chat-conversation-width": "396px",
206
- "--gengage-chat-panel-min-width": "320px",
207
- "--gengage-chat-panel-max-width": "1200px",
208
- "--gengage-chat-input-height": "48px",
209
- "--gengage-qna-pill-radius": "999px",
210
- "--gengage-qna-input-radius": "12px",
211
- "--gengage-simrel-card-radius": "0.75rem",
212
- "--radius-control": "12px",
213
- "--radius-card": "16px",
214
- "--radius-panel": "24px",
215
- "--radius-pill": "999px",
216
- "--surface-card-muted": "#f8fafc",
217
- "--text-secondary": "#4b5563",
218
- "--text-muted": "#6b7280",
219
- "--border-default": "rgba(17, 24, 39, 0.10)"
220
- };
221
- function E(e) {
222
- if (!e) return { ..._ };
223
- const i = {
224
- ..._,
225
- ...e
226
- }, t = e["--gengage-chat-launcher-size"];
227
- return t !== void 0 && (e["--gengage-chat-launcher-width"] === void 0 && (i["--gengage-chat-launcher-width"] = t), e["--gengage-chat-launcher-height"] === void 0 && (i["--gengage-chat-launcher-height"] = t)), i;
228
- }
229
- var s = {
230
- primaryColor: "#b7102a",
231
- primaryForeground: "#ffffff",
232
- backgroundColor: "#ffffff",
233
- foregroundColor: "#111827",
234
- borderRadius: "0.75rem",
235
- fontFamily: '"Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
236
- fontSize: "14px",
237
- zIndex: "1000",
238
- "--glov-chatbot-width": "420px",
239
- "--glov-left-spacing": "260px",
240
- "--chatbot-padding": "16px",
241
- "--root-wrapper-background-color": "#f8f9fa",
242
- "--root-wrapper-border-color": "#edeeef",
243
- "--gengage-chat-width": "400px",
244
- "--gengage-chat-shell-radius": "1rem",
245
- "--gengage-chat-header-height": "72px",
246
- "--gengage-chat-conversation-width": "396px",
247
- "--gengage-chat-panel-min-width": "320px",
248
- "--gengage-chat-panel-max-width": "1200px",
249
- "--gengage-chat-input-height": "48px",
250
- "--gengage-qna-pill-radius": "999px",
251
- "--gengage-qna-input-radius": "0.75rem",
252
- "--gengage-simrel-card-radius": "0.75rem",
253
- "--client-primary": "#b7102a",
254
- "--client-primary-hover": "color-mix(in srgb, #b7102a 88%, black 12%)",
255
- "--client-primary-active": "color-mix(in srgb, #b7102a 78%, black 22%)",
256
- "--client-primary-subtle": "color-mix(in srgb, #b7102a 12%, white)",
257
- "--client-primary-soft": "color-mix(in srgb, #b7102a 20%, white)",
258
- "--client-on-primary": "#ffffff",
259
- "--client-focus-ring": "color-mix(in srgb, #b7102a 32%, transparent)",
260
- "--surface-page": "#f6f7fb",
261
- "--surface-shell": "#10131a",
262
- "--surface-card": "#ffffff",
263
- "--surface-card-muted": "#f8fafc",
264
- "--surface-card-soft": "#f8fafc",
265
- "--surface-elevated": "#ffffff",
266
- "--surface-input": "#ffffff",
267
- "--surface-overlay": "rgba(16, 19, 26, 0.52)",
268
- "--text-primary": "#111827",
269
- "--text-secondary": "#4b5563",
270
- "--text-muted": "#6b7280",
271
- "--text-inverse": "#f9fafb",
272
- "--border-subtle": "rgba(17, 24, 39, 0.06)",
273
- "--border-default": "rgba(17, 24, 39, 0.10)",
274
- "--border-strong": "rgba(17, 24, 39, 0.18)",
275
- "--shadow-1": "0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06)",
276
- "--shadow-2": "0 4px 12px rgba(16, 24, 40, 0.08)",
277
- "--shadow-3": "0 10px 24px rgba(16, 24, 40, 0.12)",
278
- "--radius-control": "12px",
279
- "--radius-card": "16px",
280
- "--radius-panel": "24px",
281
- "--radius-pill": "999px",
282
- "--success": "#16a34a",
283
- "--warning": "#d97706",
284
- "--error": "#dc2626",
285
- "--info": "#2563eb",
286
- "--rating": "#f5b301",
287
- "--ai-accent-start": "#0b24d6",
288
- "--ai-accent-end": "#f768f2",
289
- "--ai-accent-soft": "linear-gradient(135deg, rgba(11, 36, 214, 0.08), rgba(247, 104, 242, 0.08))"
290
- };
291
- function ee(e) {
292
- return {
293
- ...s,
294
- ...e
295
- };
296
- }
297
- var o = "gengage-global-toast-root", c = "gengage-global-toast-style", g = "gengage-global-toast-root--visible", C = 4200, T = 1500, I = 15e3, S = [
298
- "--gengage-font-family",
299
- "--surface-card",
300
- "--text-primary",
301
- "--text-muted",
302
- "--border-default",
303
- "--radius-card",
304
- "--shadow-3",
305
- "--error",
306
- "--ds-toast-error-bg",
307
- "--ds-toast-error-border",
308
- "--ds-toast-error-accent",
309
- "--ds-toast-error-fg",
310
- "--ds-toast-error-shadow"
311
- ], f = !1, a = null, L = [
312
- /failed to fetch/i,
313
- /networkerror/i,
314
- /network request failed/i,
315
- /load failed/i,
316
- /err_network/i,
317
- /fetch failed/i,
318
- /network error/i
319
- ];
320
- function l(e) {
321
- return typeof e == "string" && e.toLowerCase().startsWith("tr");
322
- }
323
- function R(e) {
324
- if (typeof navigator < "u" && navigator.onLine === !1) return !0;
325
- const i = e instanceof Error ? e.message.trim() : "";
326
- return i ? L.some((t) => t.test(i)) : !1;
327
- }
328
- function ie(e, i) {
329
- return R(i) ? l(e) ? "Bağlantı sorunu oluştu. Lütfen tekrar deneyin." : "Connection issue. Please try again." : l(e) ? "Bir hata oluştu. Lütfen tekrar deneyin." : "Something went wrong. Please try again.";
330
- }
331
- function $() {
332
- f || typeof window > "u" || typeof document > "u" || (f = !0, h("gengage:global:error", (e) => {
333
- M(e);
334
- }));
335
- }
336
- function M(e) {
337
- if (typeof document > "u") return;
338
- const i = e.message.trim();
339
- if (!i) return;
340
- V();
341
- const t = N();
342
- D(t), t.innerHTML = "";
343
- const n = document.createElement("section");
344
- n.className = "gengage-global-toast gengage-global-toast--error", n.setAttribute("role", "status"), n.setAttribute("aria-live", "polite");
345
- const r = document.createElement("div");
346
- r.className = "gengage-global-toast-title", r.textContent = A(e.source);
347
- const d = document.createElement("div");
348
- d.className = "gengage-global-toast-message", d.textContent = i, n.appendChild(r), n.appendChild(d), t.appendChild(n), t.classList.add(g), a && (clearTimeout(a), a = null), e.sticky !== !0 && (a = setTimeout(() => {
349
- q();
350
- }, O(e.durationMs)));
351
- }
352
- function q() {
353
- if (typeof document > "u") return;
354
- const e = document.getElementById(o);
355
- e && (e.classList.remove(g), e.innerHTML = "", a && (clearTimeout(a), a = null));
356
- }
357
- function A(e) {
358
- switch (e) {
359
- case "chat":
360
- return "Chat warning";
361
- case "qna":
362
- return "QnA warning";
363
- case "simrel":
364
- return "Widget warning";
365
- default:
366
- return "Connection warning";
367
- }
368
- }
369
- function N() {
370
- const e = document.getElementById(o);
371
- if (e instanceof HTMLElement) return e;
372
- const i = document.createElement("div");
373
- return i.id = o, i.className = "gengage-global-toast-root", document.body.appendChild(i), i;
374
- }
375
- function D(e) {
376
- if (typeof document > "u" || typeof window > "u") return;
377
- const i = document.querySelector(".gengage-chat-root, .gengage-qna-container, .gengage-simrel-container, .gengage-simbut-root");
378
- if (!i) return;
379
- const t = window.getComputedStyle(i);
380
- for (const n of S) {
381
- const r = t.getPropertyValue(n).trim();
382
- r ? e.style.setProperty(n, r) : e.style.removeProperty(n);
383
- }
384
- }
385
- function O(e) {
386
- return typeof e != "number" || !Number.isFinite(e) ? C : Math.min(I, Math.max(T, Math.round(e)));
387
- }
388
- function V() {
389
- if (document.getElementById(c)) return;
390
- const e = document.createElement("style");
391
- e.id = c;
392
- const i = s["--surface-card"] ?? s.backgroundColor ?? "#ffffff", t = s["--text-primary"] ?? s.foregroundColor ?? "#111827", n = s["--border-default"] ?? "rgba(17, 24, 39, 0.10)", r = s["--error"] ?? "#dc2626", d = s["--shadow-3"] ?? "0 10px 24px rgba(16, 24, 40, 0.12)", v = s["--radius-card"] ?? "16px", m = s["--text-muted"] ?? "#6b7280";
393
- e.textContent = `
394
- #${o} {
395
- position: fixed;
396
- top: 16px;
397
- right: 16px;
398
- z-index: 2147483646;
399
- pointer-events: none;
400
- }
401
- #${o}.${g} {
402
- pointer-events: auto;
403
- }
404
- #${o} .gengage-global-toast {
405
- min-width: 260px;
406
- max-width: min(92vw, 420px);
407
- border-radius: var(--radius-card, ${v});
408
- border: 1px solid var(--ds-toast-error-border, color-mix(in srgb, var(--error, ${r}) 18%, var(--border-default, ${n})));
409
- border-left: 4px solid var(--ds-toast-error-accent, var(--error, ${r}));
410
- background: var(--ds-toast-error-bg, color-mix(in srgb, var(--error, ${r}) 5%, var(--surface-card, ${i})));
411
- color: var(--ds-toast-error-fg, color-mix(in srgb, var(--error, ${r}) 22%, var(--text-primary, ${t})));
412
- box-shadow: var(--ds-toast-error-shadow, var(--shadow-3, ${d}));
413
- padding: 10px 12px;
414
- font-family: var(--gengage-font-family, ${JSON.stringify(s.fontFamily ?? '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif')});
415
- font-size: 13px;
416
- line-height: 1.4;
417
- animation: gengage-global-toast-in 180ms ease-out forwards;
418
- }
419
- #${o} .gengage-global-toast-title {
420
- margin: 0 0 4px;
421
- font-size: 12px;
422
- font-weight: 700;
423
- color: var(--text-muted, ${m});
424
- }
425
- #${o} .gengage-global-toast-message {
426
- margin: 0;
427
- font-weight: 500;
428
- }
429
- @keyframes gengage-global-toast-in {
430
- from {
431
- opacity: 0;
432
- transform: translateY(-8px);
433
- }
434
- to {
435
- opacity: 1;
436
- transform: translateY(0);
437
- }
438
- }
439
- `, document.head.appendChild(e);
440
- }
441
- var u = null;
442
- function B() {
443
- if (u !== null) return u;
444
- try {
445
- u = localStorage.getItem("gengage:debug") === "1";
446
- } catch {
447
- u = !1;
448
- }
449
- return u;
450
- }
451
- function p(e, i, t) {
452
- if (!B()) return;
453
- const n = [`[gengage:${e}]`, i];
454
- t !== void 0 && n.push(t), console.debug(...n);
455
- }
456
- var G = ("0.4.21".trim(), "0.4.21".trim()), H = ("package-build".trim(), "package-build".trim());
457
- function P() {
458
- if (typeof window > "u") return;
459
- const e = window;
460
- e.__gengageSdkRuntimeInfoLogged || (e.__gengageSdkRuntimeInfoLogged = !0, console.info(`[gengage] @gengage/assistant-fe v${G} (${H})`));
461
- }
462
- var te = class {
463
- constructor() {
464
- this.isVisible = !1, this.isInitialised = !1, this._handlers = /* @__PURE__ */ new Map(), this._cleanups = [], this._ownsRoot = !1, this._destroying = !1;
465
- }
466
- async init(e) {
467
- if (this.isInitialised) {
468
- console.warn("[gengage] Widget already initialised. Call update() instead.");
469
- return;
470
- }
471
- const i = E(e.theme);
472
- P(), this.config = {
473
- ...e,
474
- theme: i,
475
- session: y(e.session)
476
- }, this.root = this._resolveMount(e.mountTarget), this._applyTheme(i), $();
477
- const t = h("gengage:context:update", (n) => this.update(n));
478
- this._cleanups.push(t), p("lifecycle", `${this.constructor.name}.init`, {
479
- accountId: e.accountId,
480
- sku: e.pageContext?.sku
481
- });
482
- try {
483
- await this.onInit(this.config);
484
- } catch (n) {
485
- throw this.destroy(), n;
486
- }
487
- this._destroying || (this.isInitialised = !0, p("lifecycle", `${this.constructor.name} ready`), this.emit("ready"));
488
- }
489
- update(e) {
490
- this.isInitialised && (this.config.pageContext ? this.config = {
491
- ...this.config,
492
- pageContext: {
493
- ...this.config.pageContext,
494
- ...e
495
- }
496
- } : e.pageType !== void 0 && (this.config = {
497
- ...this.config,
498
- pageContext: e
499
- }), this.onUpdate(e), this.emit("context-update", this.config.pageContext));
500
- }
501
- show() {
502
- this.isVisible || (this.isVisible = !0, this.root.style.display = "", this.onShow(), this.emit("show"));
503
- }
504
- hide() {
505
- this.isVisible && (this.isVisible = !1, this.root.style.display = "none", this.onHide(), this.emit("hide"));
506
- }
507
- destroy() {
508
- this._destroying || (this._destroying = !0, this.emit("destroy"), this._cleanups.forEach((e) => e()), this._cleanups.length = 0, this._handlers.clear(), this.onDestroy(), this.config.analyticsClient?.destroy(), this._cleanupRoot(), this.isInitialised = !1);
509
- }
510
- _cleanupRoot() {
511
- this._ownsRoot ? this.root.remove() : this.root.innerHTML = "";
512
- }
513
- on(e, i) {
514
- return this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(i), () => this._handlers.get(e)?.delete(i);
515
- }
516
- trackCheckout(e, i) {
517
- const t = e === "start" ? b : k;
518
- this.track(t(this.analyticsContext(), i));
519
- }
520
- flushMeteringSummary(e) {
521
- this.track(w(this.analyticsContext(), e));
522
- }
523
- emit(e, ...i) {
524
- this._handlers.get(e)?.forEach((t) => t(...i));
525
- }
526
- addCleanup(e) {
527
- this._cleanups.push(e);
528
- }
529
- track(e) {
530
- this.config.analyticsClient?.track(e);
531
- }
532
- analyticsContext() {
533
- const e = {
534
- account_id: this.config.accountId,
535
- session_id: this.config.session?.sessionId ?? "",
536
- correlation_id: this.config.session?.sessionId ?? ""
537
- };
538
- return this.config.session?.viewId !== void 0 && (e.view_id = this.config.session.viewId), this.config.session?.userId !== void 0 && (e.user_id = this.config.session.userId), this.config.pageContext?.pageType !== void 0 && (e.page_type = this.config.pageContext.pageType), this.config.pageContext?.sku !== void 0 && (e.sku = this.config.pageContext.sku), this.config.session?.abTestVariant !== void 0 && (e.ab_test_variant = this.config.session.abTestVariant), this.config.session?.abTestExperimentId !== void 0 && (e.ab_test_experiment_id = this.config.session.abTestExperimentId), e;
539
- }
540
- _resolveMount(e) {
541
- if (e instanceof HTMLElement) return e;
542
- if (typeof e == "string") {
543
- const t = document.querySelector(e);
544
- if (!t) throw new Error(`[gengage] Mount target not found: "${e}"`);
545
- return t;
546
- }
547
- const i = document.createElement("div");
548
- return i.dataset.gengageWidget = this.constructor.name.toLowerCase(), document.body.insertBefore(i, document.body.firstChild), this._ownsRoot = !0, i;
549
- }
550
- _applyTheme(e) {
551
- if (e) {
552
- for (const [i, t] of Object.entries(e)) if (t !== void 0) {
553
- const n = i.startsWith("--") ? i : `--gengage-${U(i)}`;
554
- this.root.style.setProperty(n, t);
555
- }
556
- }
557
- }
558
- };
559
- function U(e) {
560
- return e.replace(/([A-Z])/g, "-$1").toLowerCase();
561
- }
562
- export {
563
- K as C,
564
- Z as E,
565
- J as S,
566
- Y as T,
567
- b as _,
568
- q as a,
569
- w as b,
570
- $ as c,
571
- ee as d,
572
- _ as f,
573
- k as g,
574
- X as h,
575
- p as i,
576
- M as l,
577
- x as m,
578
- H as n,
579
- ie as o,
580
- E as p,
581
- G as r,
582
- R as s,
583
- te as t,
584
- s as u,
585
- j as v,
586
- W as w,
587
- z as x,
588
- Q as y
589
- };