@telia-ace/widget-conversational-hub 1.1.2

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,3961 @@
1
+ const Pt = (n, t, e, ...s) => {
2
+ const i = `[${n.get("$environment").name || "webprovisions"}] ${e}`;
3
+ switch (t) {
4
+ case "info":
5
+ console.info(i, ...s);
6
+ break;
7
+ case "warning":
8
+ console.warn(i, ...s);
9
+ break;
10
+ case "error":
11
+ console.error(i, ...s);
12
+ break;
13
+ }
14
+ }, bs = (n) => {
15
+ const t = n.container || n;
16
+ return {
17
+ info: (e, ...s) => Pt(t, "info", e, ...s),
18
+ warn: (e, ...s) => Pt(t, "warning", e, ...s),
19
+ error: (e, ...s) => Pt(t, "error", e, ...s)
20
+ };
21
+ };
22
+ var X = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(X || {}), T = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(T || {});
23
+ const $s = (n, t, e, s) => {
24
+ try {
25
+ const i = new t(e, s);
26
+ return {
27
+ name: n,
28
+ invoke: (r, o) => {
29
+ let a;
30
+ return i[r] && (a = i[r].call(i, o)), Promise.resolve(a);
31
+ },
32
+ getInstance: () => i
33
+ };
34
+ } catch (i) {
35
+ if (i.message && i.message.indexOf("is not a constructor") >= 0)
36
+ return {
37
+ name: n,
38
+ invoke: (r) => {
39
+ let o;
40
+ return r === "initialize" && (o = t(e, s)), Promise.resolve(o);
41
+ },
42
+ getInstance: () => t
43
+ };
44
+ throw i;
45
+ }
46
+ };
47
+ function fe(n, t) {
48
+ return typeof n > "u" ? t : n;
49
+ }
50
+ let ws = class {
51
+ constructor(t = {}) {
52
+ this.part = t;
53
+ }
54
+ createCommand(t, e, s) {
55
+ let i;
56
+ typeof e == "function" ? i = {
57
+ scope: X.Widget,
58
+ stage: T.Post,
59
+ defaultArgs: void 0,
60
+ handlerResolver: e
61
+ } : i = {
62
+ scope: fe(e.scope, X.Widget),
63
+ stage: fe(e.stage, T.Post),
64
+ defaultArgs: e.defaultArgs,
65
+ handlerResolver: s
66
+ };
67
+ let r = this.part;
68
+ const o = t.split(".");
69
+ return o.forEach((a, c) => {
70
+ c === o.length - 1 ? r[a] || (r[a] = () => i) : r = this.part[a] = this.part[a] || {};
71
+ }), this;
72
+ }
73
+ get() {
74
+ return this.part;
75
+ }
76
+ };
77
+ const Qe = (n) => {
78
+ const t = new ws({});
79
+ return n(t), t.get();
80
+ };
81
+ Qe((n) => {
82
+ n.createCommand(
83
+ "types.register",
84
+ { scope: X.Implementation, stage: T.Pre },
85
+ (t) => (e, s) => {
86
+ t.container.get("$types")[e] = s;
87
+ }
88
+ ).createCommand(
89
+ "type",
90
+ { stage: T.Pre },
91
+ (t) => (e) => {
92
+ t.container.register("$type", e);
93
+ }
94
+ ).createCommand(
95
+ "settings",
96
+ { stage: T.Pre, defaultArgs: [null] },
97
+ (t) => (e) => {
98
+ t.events.dispatch(
99
+ "settings:change",
100
+ e,
101
+ { bubbles: !0 }
102
+ ), t.container.register("$settings", e);
103
+ }
104
+ ).createCommand(
105
+ "plugin",
106
+ { stage: T.Pre },
107
+ (t) => (e, s, i) => {
108
+ const { container: r } = t;
109
+ let o = null, a = e, c = s;
110
+ typeof e == "string" && (o = e, a = s, c = i);
111
+ const h = (l) => {
112
+ const { transformPluginSettings: d } = t.container.get("$environmentOptions"), u = d ? d(
113
+ c || {},
114
+ o,
115
+ t.container,
116
+ a
117
+ ) : s;
118
+ try {
119
+ const p = $s(
120
+ o,
121
+ a,
122
+ r,
123
+ u
124
+ );
125
+ r.get("$plugins").push(p), l && p.invoke("initialize", null);
126
+ } catch (p) {
127
+ bs(t).warn("Error when initializing plugin", p);
128
+ }
129
+ };
130
+ t.container.get("$instance") ? h(!0) : t.events.subscribeOnce("widget:instance-created", () => h(!1));
131
+ }
132
+ ).createCommand(
133
+ "container.register",
134
+ (t) => (e, s) => {
135
+ t.container.register(e, s);
136
+ }
137
+ ).createCommand(
138
+ "container.registerAsync",
139
+ (t) => (e, s) => {
140
+ t.container.registerAsync(e, s);
141
+ }
142
+ ).createCommand(
143
+ "container.registerFactory",
144
+ (t) => (e, s) => {
145
+ t.container.registerFactory(e, s);
146
+ }
147
+ ).createCommand(
148
+ "container.touch",
149
+ (t) => (e, s) => {
150
+ t.container.touch(e, s);
151
+ }
152
+ ).createCommand(
153
+ "csp",
154
+ {},
155
+ (t) => (e) => {
156
+ t.container.register("csp", e);
157
+ }
158
+ );
159
+ });
160
+ const _s = Qe((n) => {
161
+ n.createCommand(
162
+ "ready",
163
+ { scope: X.Implementation, stage: T.Pre },
164
+ (t) => (e) => {
165
+ const { container: s } = t, i = s.owner;
166
+ s.get("bootstrapping").ready ? e(i) : i.events.subscribeOnce("bootstrap:ready", () => {
167
+ e(i);
168
+ });
169
+ }
170
+ );
171
+ }), kt = /* @__PURE__ */ new WeakMap();
172
+ function J() {
173
+ return (n) => (kt.has(n) || kt.set(n, {}), kt.get(n));
174
+ }
175
+ const St = (n, t, e, ...s) => {
176
+ const i = `[${n.get("$environment").name || "webprovisions"}] ${e}`;
177
+ switch (t) {
178
+ case "info":
179
+ console.info(i, ...s);
180
+ break;
181
+ case "warning":
182
+ console.warn(i, ...s);
183
+ break;
184
+ case "error":
185
+ console.error(i, ...s);
186
+ break;
187
+ }
188
+ }, $ = (n) => {
189
+ const t = n.container || n;
190
+ return {
191
+ info: (e, ...s) => St(t, "info", e, ...s),
192
+ warn: (e, ...s) => St(t, "warning", e, ...s),
193
+ error: (e, ...s) => St(t, "error", e, ...s)
194
+ };
195
+ }, g = J(), Gt = (() => {
196
+ let n = 0;
197
+ return () => ++n;
198
+ })(), Xt = (n, t, e) => {
199
+ const s = g(n).touchQueue.get(t);
200
+ s && s.forEach((i) => {
201
+ i(e, n);
202
+ });
203
+ };
204
+ let As = class {
205
+ constructor(t, e, s, i) {
206
+ this.key = t, this.factory = e, this.parent = s, this.container = i, this.id = Gt(), this.resolved = !1, this.constructed = !1, this.async = !0;
207
+ }
208
+ resolve() {
209
+ if (!this.constructed) {
210
+ const t = this.factory(this.parent, this.container);
211
+ return this.constructed = !0, this.value = Promise.resolve(t).then((e) => (this.resolved = !0, Xt(this.container, this.key, e), e));
212
+ }
213
+ return this.value;
214
+ }
215
+ }, Es = class {
216
+ constructor(t, e, s, i) {
217
+ this.key = t, this.value = e, this.parent = s, this.container = i, this.id = Gt(), this.async = !1, this.resolved = !1, this.constructed = !0, this.resolve = () => (this.resolved = !0, Xt(this.container, this.key, this.value), this.value);
218
+ }
219
+ }, xs = class {
220
+ constructor(t, e, s, i) {
221
+ this.key = t, this.value = e, this.parent = s, this.container = i, this.id = Gt(), this.async = !1, this.resolved = !1, this.constructed = !1, this.resolve = () => {
222
+ this.resolved = !0, this.constructed = !0;
223
+ const r = this.value(this.parent, this.container);
224
+ return Xt(this.container, this.key, this.value), r;
225
+ };
226
+ }
227
+ }, Cs = class Ye {
228
+ /**
229
+ * Creates a new instance of `Container`.
230
+ * @param owner The object owning this inctance.
231
+ * @param name Optional name for the container.
232
+ * @param parent Parent container this should be a child of.
233
+ */
234
+ constructor(t, e, s) {
235
+ this.owner = t, this.name = e, this.parent = s, g(this).resolvers = /* @__PURE__ */ new Map(), g(this).touchQueue = /* @__PURE__ */ new Map(), g(this).children = [];
236
+ }
237
+ /**
238
+ * Deletes an existing resolver by its unique id.
239
+ * @param id Resolver id.
240
+ */
241
+ delete(t) {
242
+ const e = g(this).resolvers, s = Array.from(e.values()).find((i) => i.id === t);
243
+ return s ? (g(this).touchQueue.delete(s.key), Promise.resolve(e.delete(s.key))) : this.parent ? this.parent.delete(t) : Promise.resolve(!1);
244
+ }
245
+ /**
246
+ * Clears the `Container` and any child containers by deleteing all registered resolvers.
247
+ */
248
+ clear() {
249
+ const t = g(this).resolvers, e = Array.from(t.values());
250
+ return Promise.all(e.map((s) => {
251
+ if (s.constructed)
252
+ return Promise.resolve(s.resolve()).then((i) => {
253
+ if (i !== null && typeof i == "object" && typeof i.dispose == "function")
254
+ return i.dispose.call(i, this, s);
255
+ });
256
+ })).then(() => {
257
+ e.forEach((s) => this.delete(s.id)), g(this).children.forEach((s) => s.clear());
258
+ });
259
+ }
260
+ /**
261
+ * Detaches this `Container` instance from its parent, allowing it to be garbage-collected.
262
+ */
263
+ detach() {
264
+ if (this.parent) {
265
+ const t = g(this.parent).children, e = t.indexOf(this);
266
+ e > -1 && (t.splice(e, 1), delete this.parent);
267
+ }
268
+ }
269
+ /**
270
+ * Provides a way of touching a value in the `Container` without forcing it to be resolved.
271
+ * @param key Key of the resolved value to touch.
272
+ * @param handler Handler function for touching the resolved value.
273
+ */
274
+ touch(t, e) {
275
+ const s = g(this).resolvers.get(t);
276
+ if (s && s.constructed)
277
+ Promise.resolve(s.resolve()).then((i) => {
278
+ e(i, this);
279
+ });
280
+ else {
281
+ const i = g(this).touchQueue;
282
+ let r = i.get(t);
283
+ r || (r = [], i.set(t, r)), r.push(e);
284
+ }
285
+ return this.parent && !s ? this.parent.touch(t, e) : Promise.resolve();
286
+ }
287
+ /**
288
+ * Registers an asynchronous resolver.
289
+ * @param key Key of the resolver.
290
+ * @param factory Value factory.
291
+ */
292
+ registerAsync(t, e) {
293
+ const s = g(this).resolvers.get(t);
294
+ s && !s.async && process.env.NODE_ENV !== "production" && $(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${t}') previously used by a non-async resolver.`);
295
+ const i = new As(t, e, s, this);
296
+ return g(this).resolvers.set(t, i), i.id;
297
+ }
298
+ /**
299
+ * Registers a factory resolver for constructing the value to be resolved.
300
+ * @param key Key of the resolver.
301
+ * @param factory Value factory.
302
+ */
303
+ registerFactory(t, e) {
304
+ const s = g(this).resolvers.get(t);
305
+ s && s.async && process.env.NODE_ENV !== "production" && $(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);
306
+ const i = new xs(t, e, s, this);
307
+ return g(this).resolvers.set(t, i), i.id;
308
+ }
309
+ /**
310
+ * Registers an synchronous resolver.
311
+ * @param key Key of the resolver.
312
+ * @param value Value.
313
+ */
314
+ register(t, e) {
315
+ const s = g(this).resolvers.get(t);
316
+ s && s.async && process.env.NODE_ENV !== "production" && $(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);
317
+ const i = new Es(t, e, s, this);
318
+ return g(this).resolvers.set(t, i), i.id;
319
+ }
320
+ /**
321
+ * Gets the value for a synchronous resolver.
322
+ * @param key Key of resolver to get.
323
+ */
324
+ get(t) {
325
+ const e = g(this).resolvers.get(t);
326
+ if (e)
327
+ return e.async && process.env.NODE_ENV !== "production" && $(this).warn(`You are retrieving an async value (with key '${t}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`), e.resolve();
328
+ if (this.parent)
329
+ return this.parent.get(t);
330
+ }
331
+ /**
332
+ * Gets the value for a asynchronous resolver.
333
+ * @param key Key of resolver to get.
334
+ */
335
+ getAsync(t) {
336
+ const e = g(this).resolvers.get(t);
337
+ if (e) {
338
+ if (!e.async)
339
+ throw process.env.NODE_ENV !== "production" && $(this).warn(`You are retrieving a non-async value (with key '${t}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`), "Mismatching resolver type";
340
+ return e.resolve();
341
+ }
342
+ return this.parent ? this.parent.getAsync(t) : Promise.resolve(void 0);
343
+ }
344
+ getMany(...t) {
345
+ const e = {};
346
+ return t.forEach((s) => e[s] = this.get(s)), e;
347
+ }
348
+ getManyAsync(...t) {
349
+ const e = {};
350
+ return Promise.all(t.map((s) => this.getAsync(s).then((i) => e[s] = i))).then(() => e);
351
+ }
352
+ createChild(t, e) {
353
+ const s = new Ye(t, e, this);
354
+ return g(this).children.push(s), s;
355
+ }
356
+ }, ye = class {
357
+ /**
358
+ *
359
+ * @param type Type of event.
360
+ * @param target The target of the event, which will handle the default behavour.
361
+ * @param cancelable Whether the event is cancelable by calling preventDefault().
362
+ * @param bubbles Whether the event will bubble up the parent hierarchy.
363
+ */
364
+ constructor(t, e, s = !1, i = !1) {
365
+ this.type = t, this.target = e, this.cancelable = !!s, this.bubbles = !!i, this.defaultPrevented = !1;
366
+ }
367
+ /**
368
+ * Cancels the default behaviour (if the event is cancelable).
369
+ */
370
+ preventDefault() {
371
+ this.cancelable && (this.defaultPrevented = !0);
372
+ }
373
+ };
374
+ const x = J(), be = (n, t) => [].concat(
375
+ x(n).listenerLookup.get(t.toLowerCase()) || [],
376
+ x(n).listenerLookup.get("*") || []
377
+ ), $e = (n, t, e, s) => {
378
+ let i, r;
379
+ return t instanceof ye ? (i = t, r = t.type) : (i = new ye(t, n.target, !!e.cancelable, !!e.bubbles), r = t), { event: i, type: r, async: s };
380
+ };
381
+ let Ps = class Ze {
382
+ /**
383
+ * Creates a new Event Manager instance.
384
+ * @param target The target of events dispatched from this Event Manager instance.
385
+ * @param parent Parent Event Manager instance.
386
+ */
387
+ constructor(t, e) {
388
+ this.target = t, this.parent = e, x(this).listenerLookup = /* @__PURE__ */ new Map(), x(this).children = [];
389
+ }
390
+ /**
391
+ * Clears registered event listeners in this `EventManager` as well as in any children.
392
+ */
393
+ clear() {
394
+ x(this).listenerLookup.clear(), x(this).children.forEach((t) => t.clear());
395
+ }
396
+ /**
397
+ * Detaches this `EventManager` instance from its parent, allowing it to be garbage-collected.
398
+ */
399
+ detach() {
400
+ if (this.parent) {
401
+ const t = x(this.parent).children, e = t.indexOf(this);
402
+ e > -1 && t.splice(e, 1);
403
+ }
404
+ }
405
+ /**
406
+ * Creates an event subscription by registering an listener for an event type.
407
+ * @param type Event type to subscribe to.
408
+ * @param listener Listener for the event.
409
+ */
410
+ subscribe(t, e, s) {
411
+ const i = x(this).listenerLookup, r = t.toLowerCase();
412
+ return i.has(r) || i.set(r, []), i.get(r).push(e), () => this.unsubscribe(t, e);
413
+ }
414
+ /**
415
+ * Similar to `subscribe()` but immediately removes the subscription after the first call.
416
+ * @param type Event type to subscribe to.
417
+ * @param listener Listener for the event.
418
+ */
419
+ subscribeOnce(t, e) {
420
+ const s = this.subscribe(t, (i, r) => (s(), e(i, r)));
421
+ }
422
+ /**
423
+ * Removes a listener for the specified event type.
424
+ * @param type Event type to remove subscription for.
425
+ * @param listener Event listener to remove.
426
+ */
427
+ unsubscribe(t, e) {
428
+ const s = x(this).listenerLookup.get(t.toLowerCase());
429
+ if (s) {
430
+ const i = s.indexOf(e);
431
+ i > -1 && s.splice(i, 1);
432
+ }
433
+ }
434
+ /**
435
+ * Dispatches an asynchonous event to registered event listeners.
436
+ * @param eventOrType Event type or Event object to dispatch.
437
+ * @param data Optional data to be passed to event listeners.
438
+ * @param options Optional event options used if first parameter is an event type.
439
+ */
440
+ dispatchAsync(t, e, s = {}) {
441
+ const { event: i, type: r } = $e(this, t, s, !0), o = be(this, r);
442
+ let a = 0;
443
+ const c = o.length;
444
+ let h = Promise.resolve();
445
+ for (a = 0; a < c; a++)
446
+ ((l) => {
447
+ h = h.then((d) => d ? Promise.resolve(!0) : Promise.resolve(l(i, e)).then(() => i.defaultPrevented));
448
+ })(o[a]);
449
+ return h.then((l) => !l && i.bubbles && this.parent ? this.parent.dispatchAsync(i, e) : l);
450
+ }
451
+ /**
452
+ * Dispatches an event to registered event listeners.
453
+ * @param eventOrType Event type or Event object to dispatch.
454
+ * @param data Optional data to be passed to event listeners.
455
+ * @param options Optional event options used if first parameter is an event type.
456
+ */
457
+ dispatch(t, e, s = {}) {
458
+ const { event: i, type: r } = $e(this, t, s, !1), o = be(this, r);
459
+ let a = 0;
460
+ const c = o.length;
461
+ let h = !1;
462
+ for (a = 0; a < c; a++)
463
+ if (o[a](i, e), i.defaultPrevented) {
464
+ h = !0;
465
+ break;
466
+ }
467
+ return !h && i.bubbles && this.parent && (h = this.parent.dispatch(i, e)), h;
468
+ }
469
+ /**
470
+ * Creates a child instance to the current Event manager.
471
+ */
472
+ createChild(t) {
473
+ const e = new Ze(t, this);
474
+ return x(this).children.push(e), e;
475
+ }
476
+ };
477
+ const ot = (n, t, e) => {
478
+ const s = n.get("$plugins").map((i) => {
479
+ try {
480
+ return i.invoke(t, e);
481
+ } catch (r) {
482
+ $(n).error("An error occured when invoking a plugin.", i, r);
483
+ }
484
+ });
485
+ return Promise.all(s);
486
+ };
487
+ let ks = class {
488
+ constructor(t) {
489
+ this.widget = t.get("$widget"), this.events = this.widget.events, this.container = this.widget.container, this.initialized = null, this.activated = null, this.initialize = this.initialize.bind(this), this.activate = this.activate.bind(this), this.deactivate = this.deactivate.bind(this), this.invoke = this.invoke.bind(this), this.createInstance();
490
+ }
491
+ createInstance() {
492
+ if (!this.widget.container.get("$instance")) {
493
+ const t = this.widget.container.get("$types"), e = this.widget.container.get("$type");
494
+ !e && $(this).error("Unable to create widget. No type is specified.");
495
+ const s = t[e];
496
+ !s && $(this).error(`Unable to create widget. Type '${e}' is not registered.`), this.widget.events.dispatch("widget:create-instance", {}, { bubbles: !0 });
497
+ try {
498
+ this.widget.container.register(
499
+ "$instance",
500
+ new s(this.container)
501
+ );
502
+ } catch (i) {
503
+ $(this).error("Unable to create widget type.", i);
504
+ }
505
+ this.widget.events.dispatch("widget:instance-created", {}, { bubbles: !0 });
506
+ }
507
+ }
508
+ /**
509
+ * The initialization is performed before the widget is activated but after it's configured
510
+ * and thus all required services are available. This hook is a good place to bind events that
511
+ * should trigger activation (e.g. click on "trigger links" or routing events)
512
+ * @param {object} data Custom initialization data passed to the widget.
513
+ */
514
+ initialize(t) {
515
+ return this.initialized = this.initialized || (() => {
516
+ const e = this.container.get("$instance"), s = e.initialize || (() => {
517
+ });
518
+ return this.initialized = Promise.resolve(s.call(e, t)).then(() => ot(this.container, "initialize", t)).then(() => {
519
+ });
520
+ })();
521
+ }
522
+ /**
523
+ * The activation is where the widget is actually created and rendered.
524
+ * Activation can be initialized from the outside or from an event originated
525
+ * in the "initialize" hook.
526
+ * @param {object} data Custom activation data passed to the widget.
527
+ */
528
+ activate(t) {
529
+ return (this.initialized || this.initialize()).then(() => {
530
+ this.activated = this.activated || (() => ot(this.container, "activate").then(() => {
531
+ const e = this.container.get("$instance");
532
+ return this.activated = e.activate(t);
533
+ }))();
534
+ });
535
+ }
536
+ deactivate() {
537
+ const t = this.container.get("$instance"), e = t.deactivate || (() => {
538
+ });
539
+ return ot(this.container, "deactivate").then(() => Promise.resolve(e.call(t))).then(() => {
540
+ this.initialized = null, this.activated = null;
541
+ }).then(() => {
542
+ });
543
+ }
544
+ /**
545
+ * Invokes a command on the widget component.
546
+ * @param command Name of command
547
+ * @param args Command arguments
548
+ */
549
+ invoke(t, ...e) {
550
+ return ot(this.container, "invoke", { command: t, args: e }).then(() => {
551
+ const s = this.container.get("$instance");
552
+ if (s[t])
553
+ return s[t].apply(s, e);
554
+ const i = s.invoke;
555
+ if (i)
556
+ return i.call(s, t, ...e);
557
+ });
558
+ }
559
+ };
560
+ const z = (n, t) => {
561
+ if (!t)
562
+ return !0;
563
+ if (typeof t == "string") {
564
+ const e = t.split(",");
565
+ for (let s = 0, i = e.length; s < i; s++) {
566
+ const r = e[s].trim();
567
+ if (r === n || r === "*")
568
+ return !0;
569
+ }
570
+ }
571
+ return t instanceof Array ? t.indexOf(n) > -1 : !1;
572
+ }, Ss = (n, t) => {
573
+ if (typeof t == "function")
574
+ return t(n);
575
+ const e = typeof t == "string" ? Ts(t) : t;
576
+ return !(!z(n.implementation.tenant || "", e.tenant || "") || !z(n.implementation.name, e.implementation || "") || !z(n.name, e.widget || "") || !z(n.container.get("$type"), e.type || ""));
577
+ }, Os = (n, t) => {
578
+ if (typeof t == "function")
579
+ return t(n);
580
+ const e = typeof t == "string" ? Ms(t) : t;
581
+ return !(!z(n.tenant || "", e.tenant || "") || !z(n.name, e.implementation || ""));
582
+ }, Ge = (n) => (t) => Ss(t, n), Ns = (n) => (t) => Os(t, n), k = (n) => n instanceof Array && n.length === 1 ? n[0] : n, Ts = (n) => {
583
+ const t = {}, e = n.split(":");
584
+ return e.length === 1 ? t.widget = k(e[0].split(",")) : e.length === 2 ? (t.implementation = k(e[0].split(",")), t.widget = k(e[1].split(","))) : (t.tenant = k(e[0].split(",")), t.implementation = k(e[1].split(",")), t.widget = k(e[2].split(","))), t;
585
+ }, Ms = (n) => {
586
+ const t = {}, e = n.split(":");
587
+ return e.length === 1 ? t.implementation = k(e[0].split(",")) : (t.tenant = k(e[0].split(",")), t.implementation = k(e[1].split(","))), t;
588
+ }, ut = J(), we = (n, t, e) => n.filter((s) => s.stage === t && Ge(s.selector)(e));
589
+ function Is(n) {
590
+ const t = n.container.get("$environment");
591
+ let e = ut(t).configurationCache;
592
+ e && (e = e.filter((s) => s[0] !== n), ut(t).configurationCache = e);
593
+ }
594
+ var pt = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(pt || {}), S = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(S || {});
595
+ const Xe = (n, t, e) => (Object.keys(t).forEach((s) => {
596
+ const i = t[s];
597
+ if (typeof i == "function") {
598
+ const r = i();
599
+ typeof r.defaultArgs < "u" && e(r, ...r.defaultArgs), n[s] = (...o) => {
600
+ const a = Object.assign(
601
+ {},
602
+ r,
603
+ { handlerResolver: r.handlerResolver.bind({}) }
604
+ );
605
+ return e(a, ...o), n;
606
+ };
607
+ } else
608
+ n[s] = Xe(
609
+ {},
610
+ i,
611
+ e
612
+ );
613
+ }), n), Ds = (n, t) => {
614
+ switch (t) {
615
+ case "implementation":
616
+ return n.implementation;
617
+ case "widget":
618
+ return n;
619
+ }
620
+ }, _e = (n, t, e, s) => (s.forEach((i) => {
621
+ Xe(
622
+ n,
623
+ i,
624
+ (r, ...o) => {
625
+ const a = {
626
+ selector: t,
627
+ stage: r.stage,
628
+ handler: (c) => {
629
+ const h = Ds(c, r.scope), l = { container: h.container, events: h.events }, d = r.handlerResolver, u = d(l);
630
+ let p = ut(e.environment).configurationCache;
631
+ return p || (p = ut(e.environment).configurationCache = []), p.find((b) => b.indexOf(h) > -1 && b.indexOf(d) > -1) ? Promise.resolve() : (p.push([h, d]), Promise.resolve(u(...o)));
632
+ }
633
+ };
634
+ e.instructions.push(a);
635
+ }
636
+ );
637
+ }), n);
638
+ function Us(n, t) {
639
+ function e(s) {
640
+ return _e(
641
+ {},
642
+ s,
643
+ n,
644
+ t
645
+ );
646
+ }
647
+ return _e(
648
+ e,
649
+ "*",
650
+ n,
651
+ t
652
+ );
653
+ }
654
+ const Hs = (n, t, e, s) => {
655
+ try {
656
+ const i = new t(e, s);
657
+ return {
658
+ name: n,
659
+ invoke: (r, o) => {
660
+ let a;
661
+ return i[r] && (a = i[r].call(i, o)), Promise.resolve(a);
662
+ },
663
+ getInstance: () => i
664
+ };
665
+ } catch (i) {
666
+ if (i.message && i.message.indexOf("is not a constructor") >= 0)
667
+ return {
668
+ name: n,
669
+ invoke: (r) => {
670
+ let o;
671
+ return r === "initialize" && (o = t(e, s)), Promise.resolve(o);
672
+ },
673
+ getInstance: () => t
674
+ };
675
+ throw i;
676
+ }
677
+ };
678
+ function Ae(n, t) {
679
+ return typeof n > "u" ? t : n;
680
+ }
681
+ let js = class {
682
+ constructor(t = {}) {
683
+ this.part = t;
684
+ }
685
+ createCommand(t, e, s) {
686
+ let i;
687
+ typeof e == "function" ? i = {
688
+ scope: pt.Widget,
689
+ stage: S.Post,
690
+ defaultArgs: void 0,
691
+ handlerResolver: e
692
+ } : i = {
693
+ scope: Ae(e.scope, pt.Widget),
694
+ stage: Ae(e.stage, S.Post),
695
+ defaultArgs: e.defaultArgs,
696
+ handlerResolver: s
697
+ };
698
+ let r = this.part;
699
+ const o = t.split(".");
700
+ return o.forEach((a, c) => {
701
+ c === o.length - 1 ? r[a] || (r[a] = () => i) : r = this.part[a] = this.part[a] || {};
702
+ }), this;
703
+ }
704
+ get() {
705
+ return this.part;
706
+ }
707
+ };
708
+ const ts = (n) => {
709
+ const t = new js({});
710
+ return n(t), t.get();
711
+ }, Ls = ts((n) => {
712
+ n.createCommand(
713
+ "types.register",
714
+ { scope: pt.Implementation, stage: S.Pre },
715
+ (t) => (e, s) => {
716
+ t.container.get("$types")[e] = s;
717
+ }
718
+ ).createCommand(
719
+ "type",
720
+ { stage: S.Pre },
721
+ (t) => (e) => {
722
+ t.container.register("$type", e);
723
+ }
724
+ ).createCommand(
725
+ "settings",
726
+ { stage: S.Pre, defaultArgs: [null] },
727
+ (t) => (e) => {
728
+ t.events.dispatch(
729
+ "settings:change",
730
+ e,
731
+ { bubbles: !0 }
732
+ ), t.container.register("$settings", e);
733
+ }
734
+ ).createCommand(
735
+ "plugin",
736
+ { stage: S.Pre },
737
+ (t) => (e, s, i) => {
738
+ const { container: r } = t;
739
+ let o = null, a = e, c = s;
740
+ typeof e == "string" && (o = e, a = s, c = i);
741
+ const h = (l) => {
742
+ const { transformPluginSettings: d } = t.container.get("$environmentOptions"), u = d ? d(
743
+ c || {},
744
+ o,
745
+ t.container,
746
+ a
747
+ ) : s;
748
+ try {
749
+ const p = Hs(
750
+ o,
751
+ a,
752
+ r,
753
+ u
754
+ );
755
+ r.get("$plugins").push(p), l && p.invoke("initialize", null);
756
+ } catch (p) {
757
+ $(t).warn("Error when initializing plugin", p);
758
+ }
759
+ };
760
+ t.container.get("$instance") ? h(!0) : t.events.subscribeOnce("widget:instance-created", () => h(!1));
761
+ }
762
+ ).createCommand(
763
+ "container.register",
764
+ (t) => (e, s) => {
765
+ t.container.register(e, s);
766
+ }
767
+ ).createCommand(
768
+ "container.registerAsync",
769
+ (t) => (e, s) => {
770
+ t.container.registerAsync(e, s);
771
+ }
772
+ ).createCommand(
773
+ "container.registerFactory",
774
+ (t) => (e, s) => {
775
+ t.container.registerFactory(e, s);
776
+ }
777
+ ).createCommand(
778
+ "container.touch",
779
+ (t) => (e, s) => {
780
+ t.container.touch(e, s);
781
+ }
782
+ ).createCommand(
783
+ "csp",
784
+ {},
785
+ (t) => (e) => {
786
+ t.container.register("csp", e);
787
+ }
788
+ );
789
+ }), Rs = Ls;
790
+ function zs(n, t, e = []) {
791
+ const s = [Rs].concat(e), i = Us(
792
+ t,
793
+ s
794
+ );
795
+ n(i, t);
796
+ }
797
+ let Ws = class {
798
+ constructor() {
799
+ this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
800
+ }
801
+ add(t, e, s, i) {
802
+ this.tasks.push({ task: t, resolve: e, reject: s, done: i }), this.next();
803
+ }
804
+ next() {
805
+ this.current = this.current.then(() => {
806
+ const t = this.tasks.shift();
807
+ if (t) {
808
+ const e = Promise.resolve(t.task());
809
+ return Promise.resolve(e).then(this.next).then(() => e.then((s) => {
810
+ t.done(), t.resolve(s);
811
+ })).catch((s) => (t.done(), t.reject(s), this.next()));
812
+ }
813
+ return Promise.resolve();
814
+ });
815
+ }
816
+ };
817
+ const at = /* @__PURE__ */ new WeakMap();
818
+ function Bs(n) {
819
+ return at.has(n) || at.set(n, new Ws()), (t) => new Promise((e, s) => {
820
+ const i = at.get(n);
821
+ i.add(t, e, s, () => {
822
+ i.tasks.length || at.delete(n);
823
+ });
824
+ });
825
+ }
826
+ const Ee = (n) => typeof n < "u", K = (n, t) => {
827
+ n.events.dispatch("widget:state-change", { state: t }, { bubbles: !0 }), n.state = t, n.events.dispatch("widget:state-changed", {}, { bubbles: !0 });
828
+ }, E = J(), qs = (n) => {
829
+ const { container: t, events: e } = n;
830
+ t.get("$controller") || (t.register("$controller", new ks(t)), e.dispatch("widget:controller-created", {}, { bubbles: !0 }));
831
+ };
832
+ class Vs {
833
+ /**
834
+ * Creates a new `Widget` instance.
835
+ * @param name Name of widget.
836
+ * @param implementation The implementation this instance belongs to.
837
+ * @param configuration Configuration for the widget.
838
+ */
839
+ constructor(t, e, s) {
840
+ this.state = "deactivated", this.name = t, this.implementation = e, this.container = e.container.createChild(this, t), this.events = e.events.createChild(this), E(this).subscriptions = [], s && e.configure((i) => {
841
+ const r = i(t);
842
+ Ee(s.type) && r.type(s.type), Ee(s.settings) && r.settings(s.settings), s.plugins && Object.keys(s.plugins).forEach((o) => {
843
+ var a;
844
+ const c = (a = s.plugins) == null ? void 0 : a[o];
845
+ r.plugin(o, c);
846
+ });
847
+ }), this.load = this.load.bind(this), this.activate = this.activate.bind(this), this.invoke = this.invoke.bind(this), this.deactivate = this.deactivate.bind(this);
848
+ }
849
+ /**
850
+ * Initializes the widget, if not already initialized, and applies any
851
+ * pending configuration.
852
+ */
853
+ load() {
854
+ return Bs(this)(() => {
855
+ E(this).deactivatedPromise = null;
856
+ const t = this.state === "deactivated";
857
+ t && (K(
858
+ this,
859
+ "activating"
860
+ /* Activating */
861
+ ), this.container.register("$widget", this), this.container.register("$controller", null), this.container.register("$plugins", []), this.container.register("$type", null), this.container.register("$instance", null)), K(
862
+ this,
863
+ "loading"
864
+ /* Loading */
865
+ );
866
+ const e = this.implementation.instructions, s = we(e, S.Pre, this);
867
+ return Promise.all(s.map((i) => i.handler(this))).then(() => {
868
+ qs(this);
869
+ const i = we(e, S.Post, this);
870
+ return Promise.all(i.map((r) => r.handler(this))).then(() => {
871
+ t && this.container.get("$controller").initialize();
872
+ });
873
+ }).then(() => (K(
874
+ this,
875
+ "activated"
876
+ /* Activated */
877
+ ), this));
878
+ });
879
+ }
880
+ /**
881
+ * Activates the widget and makes it ready for receiving commands.
882
+ * @param data Activation data
883
+ */
884
+ activate(t) {
885
+ E(this).subscriptions.push(
886
+ this.implementation.events.subscribe("implementation:configured", () => {
887
+ [
888
+ "activated",
889
+ "activating",
890
+ "loading"
891
+ /* Loading */
892
+ ].indexOf(this.state) > -1 && this.load();
893
+ })
894
+ );
895
+ const e = E(this).activatedPromise;
896
+ return e ? (process.env.NODE_ENV !== "production" && $(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`, t), e) : E(this).activatedPromise = this.load().then(() => this.container.get("$controller").activate(t));
897
+ }
898
+ /**
899
+ * Invokes a command on a widget. If the widget isn't activate the invocation
900
+ * will be suspended until activation.
901
+ * @param command Command to invoke.
902
+ * @param args Command arguments.
903
+ */
904
+ invoke(t, ...e) {
905
+ const s = E(this).activatedPromise, i = (r, ...o) => s.then(this.load).then(() => this.container.get("$controller").invoke(r, ...o));
906
+ return s ? i(t, ...e) : (process.env.NODE_ENV !== "production" && $(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.", this), new Promise((r) => {
907
+ const o = this.events.subscribe("widget:state-changed", () => {
908
+ this.state === "activated" && (o(), r(i(t, ...e)));
909
+ });
910
+ }));
911
+ }
912
+ /**
913
+ * Deactivates the widget by clearing the `Container` and removing any event subscriptions in the
914
+ * `EventManager`.
915
+ */
916
+ deactivate() {
917
+ return E(this).deactivatedPromise || (this.state === "deactivated" ? Promise.resolve() : (K(
918
+ this,
919
+ "deactivating"
920
+ /* Deactivating */
921
+ ), E(this).deactivatedPromise = this.container.get("$controller").deactivate().then(() => (E(this).activatedPromise = null, E(this).subscriptions.forEach((e) => e()), E(this).subscriptions = [], this.container.clear().then(() => {
922
+ this.events.clear(), Is(this), K(
923
+ this,
924
+ "deactivated"
925
+ /* Deactivated */
926
+ );
927
+ })))));
928
+ }
929
+ }
930
+ const xe = J();
931
+ class Js {
932
+ /**
933
+ * Creates a new Implementation instance.
934
+ * @param configuration Configuration for the implementation.
935
+ * @param environment The parent environment.
936
+ * @param configurationApiExtensions Optional configuration API extensions.
937
+ */
938
+ constructor(t, e, s = []) {
939
+ this.instructions = [], this.widgets = /* @__PURE__ */ new Map(), this.name = t.name, this.tenant = t.tenant, this.environment = e, this.container = e.container.createChild(this, this.name), this.events = e.events.createChild(this), this.container.register("$types", {}), xe(this).configurationApiExtensions = s;
940
+ }
941
+ /**
942
+ * Loads all widgets in the implementation.
943
+ */
944
+ load() {
945
+ const t = Array.from(this.widgets.values());
946
+ return Promise.all(t.map((e) => e.load())).then(() => t);
947
+ }
948
+ /**
949
+ * Configures the implementation by adding a configuration callback.
950
+ * @param configFn Callback function for configuration.
951
+ */
952
+ configure(t) {
953
+ return zs(t, this, xe(this).configurationApiExtensions), this.events.dispatch(
954
+ "implementation:configured",
955
+ { implementation: this },
956
+ { bubbles: !0 }
957
+ ), this;
958
+ }
959
+ /**
960
+ * Creates a widget on the implementation and returns its `WidgetData`.
961
+ * @param name Widget name.
962
+ * @param configuration Widget configuration.
963
+ */
964
+ createWidget(t, e) {
965
+ const s = new Vs(t, this, e);
966
+ return this.widgets.set(s.name, s), s;
967
+ }
968
+ }
969
+ function Fs(n, t, e) {
970
+ const s = new Js(n, t, e);
971
+ return n.widgets && Object.keys(n.widgets).forEach((i) => {
972
+ var r;
973
+ const o = (r = n.widgets) == null ? void 0 : r[i];
974
+ s.createWidget(i, o);
975
+ }), s;
976
+ }
977
+ let Ce = class es {
978
+ constructor(t, e) {
979
+ this.selectorFactory = e, typeof t == "function" ? this.resolver = t : this.resolver = () => t;
980
+ }
981
+ append(t) {
982
+ const e = typeof t == "function" ? t : () => t;
983
+ return new es(
984
+ () => this.all().concat(e()),
985
+ this.selectorFactory
986
+ );
987
+ }
988
+ all() {
989
+ return this.resolver().concat([]);
990
+ }
991
+ query(t) {
992
+ return this.all().filter(this.selectorFactory(t));
993
+ }
994
+ find(t) {
995
+ const e = this.query(t);
996
+ if (e.length)
997
+ return e[0];
998
+ }
999
+ };
1000
+ const te = "#____version____#", Ot = J(), Ks = (n) => n.tenant ? `${n.name}:${n.tenant}` : n.name, ss = class {
1001
+ constructor(t, e = [], s = {}) {
1002
+ this.widgets = new Ce(
1003
+ () => {
1004
+ let i = [];
1005
+ return this.implementations.all().forEach((r) => {
1006
+ i = i.concat(Array.from(r.widgets.values()));
1007
+ }), i;
1008
+ },
1009
+ Ge
1010
+ ), this.implementations = new Ce([], Ns), this.name = t, this.container = new Cs(this, t), this.events = new Ps(this), this.container.register("$version", te), this.container.register("$environment", this), this.container.register("$environmentOptions", s), Ot(this).configurationApiExtensions = e;
1011
+ }
1012
+ /**
1013
+ * Creates an implementation based on the provided configuration.
1014
+ * @param config Implementation configuration.
1015
+ */
1016
+ createImplementation(t) {
1017
+ const e = Ks(t);
1018
+ let s = this.implementations.find(e);
1019
+ if (s)
1020
+ return process.env.NODE_ENV !== "production" && $(s).warn(`Implementation "${e}" already exist on current environment.`), s;
1021
+ const i = Ot(this).configurationApiExtensions;
1022
+ return s = Fs(
1023
+ t,
1024
+ this,
1025
+ i
1026
+ ), this.implementations = this.implementations.append([s]), this.events.dispatch("implementation:created", { implementation: s }), s;
1027
+ }
1028
+ /**
1029
+ * Patches the Environment instance configuration.
1030
+ * @param configuration Environment configuration.
1031
+ */
1032
+ patch(t = {}) {
1033
+ const { name: e, configurationApiExtensions: s } = t;
1034
+ typeof e < "u" && e !== null && (this.name = e), s && s.forEach(
1035
+ (i) => {
1036
+ Ot(this).configurationApiExtensions.push(i);
1037
+ }
1038
+ );
1039
+ }
1040
+ /**
1041
+ * Creates a new Environment instance based on the provided configuration.
1042
+ * @param configuration Environment configuration.
1043
+ */
1044
+ static create(t = {}) {
1045
+ return new ss(
1046
+ t.name || "",
1047
+ t.configurationApiExtensions,
1048
+ t.options
1049
+ );
1050
+ }
1051
+ };
1052
+ let ns = ss;
1053
+ ns.version = te;
1054
+ const yt = (n, t, ...e) => typeof t == "string" ? n(`[humany] ${t}`, ...e) : n(t, ...e), Y = class {
1055
+ constructor() {
1056
+ this.keys = [], this.log = (t, ...e) => this.lookup(t, () => Y.log(...e)), this.warn = (t, ...e) => this.lookup(t, () => Y.warn(...e)), this.error = (t, ...e) => this.lookup(t, () => Y.error(...e)), this.info = (t, ...e) => this.lookup(t, () => Y.info(...e));
1057
+ }
1058
+ lookup(t, e) {
1059
+ this.keys.indexOf(t) === -1 && (this.keys.push(t), e());
1060
+ }
1061
+ };
1062
+ let _ = Y;
1063
+ _.log = (...n) => yt(console.log, ...n);
1064
+ _.warn = (...n) => yt(console.warn, ...n);
1065
+ _.error = (...n) => yt(console.error, ...n);
1066
+ _.info = (...n) => yt(console.info, ...n);
1067
+ const is = (n) => {
1068
+ let t = {}, e, s;
1069
+ if (typeof n != "object" || n === null)
1070
+ return n;
1071
+ t = Array.isArray(n) ? [] : {};
1072
+ for (s in n)
1073
+ e = n[s], t[s] = typeof e == "object" && e !== null ? is(e) : e;
1074
+ return t;
1075
+ }, Qs = is;
1076
+ function Pe(n) {
1077
+ let t = 0;
1078
+ if (n.length === 0)
1079
+ return t.toString();
1080
+ for (let e = 0; e < n.length; e++) {
1081
+ const s = n.charCodeAt(e);
1082
+ t = (t << 5) - t + s, t = t & t;
1083
+ }
1084
+ return t.toString();
1085
+ }
1086
+ let Ys = class {
1087
+ constructor(t, e) {
1088
+ this.lockWarningTime = t, this.lockErrorTime = e, this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
1089
+ }
1090
+ add(t, e, s, i) {
1091
+ this.tasks.push({ task: t, resolve: e, reject: s, done: i }), this.next();
1092
+ }
1093
+ next() {
1094
+ this.current = this.current.then(() => {
1095
+ const t = this.tasks.shift();
1096
+ if (t) {
1097
+ let e;
1098
+ const s = setTimeout(() => {
1099
+ process.env.NODE_ENV !== "production" && _.warn(
1100
+ `A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,
1101
+ t
1102
+ ), e = setTimeout(() => {
1103
+ t.reject("lock timeout exceeded");
1104
+ }, this.lockErrorTime);
1105
+ }, this.lockWarningTime), i = Promise.resolve(t.task()).then((r) => (clearTimeout(s), clearTimeout(e), r));
1106
+ return Promise.resolve(i).then(this.next).then(
1107
+ () => i.then((r) => {
1108
+ t.done(), t.resolve(r);
1109
+ })
1110
+ ).catch((r) => (t.done(), t.reject(r), this.next()));
1111
+ }
1112
+ return Promise.resolve();
1113
+ });
1114
+ }
1115
+ };
1116
+ const ct = /* @__PURE__ */ new WeakMap();
1117
+ function nt(n, t = 5e3, e = 1e3) {
1118
+ return ct.has(n) || ct.set(n, new Ys(t, e)), (s) => new Promise((i, r) => {
1119
+ const o = ct.get(n);
1120
+ o.add(s, i, r, () => {
1121
+ o.tasks.length || ct.delete(n);
1122
+ });
1123
+ });
1124
+ }
1125
+ const O = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
1126
+ function M() {
1127
+ return O() + O() + "-" + O() + "-" + O() + "-" + O() + "-" + O() + O() + O();
1128
+ }
1129
+ var Zs = Object.defineProperty, Gs = Object.defineProperties, Xs = Object.getOwnPropertyDescriptors, ke = Object.getOwnPropertySymbols, tn = Object.prototype.hasOwnProperty, en = Object.prototype.propertyIsEnumerable, Se = (n, t, e) => t in n ? Zs(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, qt = (n, t) => {
1130
+ for (var e in t || (t = {}))
1131
+ tn.call(t, e) && Se(n, e, t[e]);
1132
+ if (ke)
1133
+ for (var e of ke(t))
1134
+ en.call(t, e) && Se(n, e, t[e]);
1135
+ return n;
1136
+ }, sn = (n, t) => Gs(n, Xs(t));
1137
+ const nn = (n) => {
1138
+ const t = [];
1139
+ return [
1140
+ (e, s) => {
1141
+ t.push(n.subscribe(e, s));
1142
+ },
1143
+ () => {
1144
+ t.forEach((e) => {
1145
+ e();
1146
+ });
1147
+ }
1148
+ ];
1149
+ };
1150
+ let rs = class {
1151
+ constructor(t, e = []) {
1152
+ this.platform = t, this.rules = e;
1153
+ }
1154
+ match(t) {
1155
+ return this.rules.every((e) => !(e.id && e.id !== t.id || e.type && e.type !== t.type));
1156
+ }
1157
+ ofType(t) {
1158
+ return this.rules.push({ type: t }), this;
1159
+ }
1160
+ withId(t) {
1161
+ return this.rules.push({ id: t }), this;
1162
+ }
1163
+ select() {
1164
+ return new on(this.platform, this);
1165
+ }
1166
+ }, rn = class {
1167
+ constructor(t, e, s) {
1168
+ this.platform = t, this.node = e, this.actions = new ee(
1169
+ t,
1170
+ new rs(t).withId(e.id),
1171
+ s
1172
+ );
1173
+ const [i, r] = nn(this.platform.events);
1174
+ this.subscribe = i, this.unsubscribe = r;
1175
+ }
1176
+ properties(t) {
1177
+ return t && this.node.touchProperties((e) => t(e)), this.node.attributes.properties;
1178
+ }
1179
+ context(t) {
1180
+ return t && this.subscribe("components:context-changed", (e, { node: s }) => {
1181
+ s === this.node && t(this.node.attributes.context);
1182
+ }), this.node.attributes.context;
1183
+ }
1184
+ layout(t) {
1185
+ return t && this.subscribe("components:layout-changed", (e, { node: s }) => {
1186
+ s === this.node && t(this.node.attributes.layout);
1187
+ }), this.node.attributes.layout;
1188
+ }
1189
+ writeProperties(t, e) {
1190
+ this.node.writeProperties(t, e);
1191
+ }
1192
+ writeContext(t, e) {
1193
+ this.node.writeProperties(t, e);
1194
+ }
1195
+ writeLayout(t, e) {
1196
+ this.node.writeLayout(t, e);
1197
+ }
1198
+ dispose() {
1199
+ this.unsubscribe(), this.actions.dispose();
1200
+ }
1201
+ };
1202
+ class on {
1203
+ constructor(t, e, s = !0) {
1204
+ this.platform = t, this.target = e, this.clearOnDispose = s, this.removes = [], this.actions = new ee(this.platform, this.target);
1205
+ }
1206
+ writeProperties(t, e) {
1207
+ this.removes.push(
1208
+ this.platform.write({
1209
+ options: e,
1210
+ attributes: { properties: t },
1211
+ target: this.target,
1212
+ removable: this.clearOnDispose
1213
+ })
1214
+ );
1215
+ }
1216
+ writeContext(t, e) {
1217
+ this.removes.push(
1218
+ this.platform.write({
1219
+ options: e,
1220
+ attributes: { context: t },
1221
+ target: this.target,
1222
+ removable: this.clearOnDispose
1223
+ })
1224
+ );
1225
+ }
1226
+ writeLayout(t, e) {
1227
+ this.removes.push(
1228
+ this.platform.write({
1229
+ options: e,
1230
+ attributes: { layout: t },
1231
+ target: this.target,
1232
+ removable: this.clearOnDispose
1233
+ })
1234
+ );
1235
+ }
1236
+ dispose() {
1237
+ this.removes.forEach((t) => {
1238
+ t();
1239
+ }), this.actions.dispose();
1240
+ }
1241
+ }
1242
+ const an = (n, t, e) => {
1243
+ const s = n.concat(), i = (r, o, a) => {
1244
+ let c = !0;
1245
+ if (s.length) {
1246
+ const h = s.shift(), l = (d, u) => (c = !1, i(d, Object.assign({}, o, u), a));
1247
+ return Promise.resolve(h(r, l, a)).then((d) => sn(qt({}, d), {
1248
+ cancelled: c
1249
+ }));
1250
+ }
1251
+ return Promise.resolve({ data: r, cancelled: !1, options: o });
1252
+ };
1253
+ return i(t, {}, e);
1254
+ };
1255
+ let ee = class {
1256
+ constructor(t, e, s) {
1257
+ this.platform = t, this.target = e, this.ns = s, this.subscriptions = [], this.create = this.create.bind(this);
1258
+ }
1259
+ create(t, e = () => {
1260
+ }) {
1261
+ const s = {
1262
+ key: t,
1263
+ fn: e,
1264
+ target: this.target,
1265
+ ns: this.ns
1266
+ };
1267
+ this.platform.actionsState.handlers.push(s);
1268
+ const i = () => {
1269
+ const r = this.platform.actionsState.handlers.indexOf(s);
1270
+ r > -1 && this.platform.actionsState.handlers.splice(r, 1);
1271
+ };
1272
+ return this.subscriptions.push(i), i;
1273
+ }
1274
+ dispatch(t, e) {
1275
+ const s = this.platform.nodes.all.concat(
1276
+ this.platform.nodes.detached
1277
+ ), i = {}, r = this.platform.actionsState.handlers.filter(
1278
+ (o) => o.key === t && (!o.ns || !this.ns || o.ns === this.ns)
1279
+ );
1280
+ return Promise.all(
1281
+ r.map((o) => {
1282
+ const a = s.filter(
1283
+ (h) => o.target.match(h) && this.target.match(h)
1284
+ ), c = this.platform.actionsState.watchers.filter((h) => h.key === t && (!h.ns || !this.ns || h.ns === this.ns) && a.some((l) => h.target.match(l))).map((h) => h.fn);
1285
+ return Promise.all(
1286
+ a.map((h) => {
1287
+ const l = new rn(
1288
+ this.platform,
1289
+ h,
1290
+ this.ns
1291
+ );
1292
+ return an(c, e, l).then((d) => {
1293
+ const { data: u = {}, options: p, cancelled: b } = d;
1294
+ return Promise.resolve(
1295
+ b ? {} : o.fn(u, p, l)
1296
+ ).then((w) => {
1297
+ i[h.id] = w;
1298
+ });
1299
+ });
1300
+ })
1301
+ );
1302
+ })
1303
+ ).then(() => i);
1304
+ }
1305
+ watch(t, e) {
1306
+ let s = t, i = this.ns;
1307
+ const r = t.split(".");
1308
+ r.length > 1 && (i = r[0], s = r.splice(1).join("."));
1309
+ const o = {
1310
+ fn: e,
1311
+ target: this.target,
1312
+ key: s,
1313
+ ns: i
1314
+ };
1315
+ this.platform.actionsState.watchers.push(o);
1316
+ const a = () => {
1317
+ const c = this.platform.actionsState.watchers.indexOf(o);
1318
+ c > -1 && this.platform.actionsState.watchers.splice(c, 1);
1319
+ };
1320
+ return this.subscriptions.push(a), a;
1321
+ }
1322
+ dispose() {
1323
+ this.subscriptions.forEach((t) => t());
1324
+ }
1325
+ };
1326
+ ts((n) => {
1327
+ n.createCommand("components", (t) => (e) => {
1328
+ t.events.subscribeOnce("components:platform-created", (s, { platform: i }) => {
1329
+ e.handlers && e.handlers.forEach(([r, o]) => {
1330
+ i.addComponentHandler(r, o);
1331
+ });
1332
+ });
1333
+ });
1334
+ });
1335
+ let Oe = class {
1336
+ constructor(t, e) {
1337
+ this.events = t, this.tags = [], this.children = {}, this.changesets = [], this.mountCount = 0, this.id = M(), this.type = e, this.attributes = {
1338
+ context: {},
1339
+ properties: {},
1340
+ layout: {},
1341
+ tags: []
1342
+ }, this.writeLayout({ size: "full", indent: 0 });
1343
+ }
1344
+ mount(t, e) {
1345
+ let s = t.get("mounted-nodes");
1346
+ return s || (s = /* @__PURE__ */ new Map(), t.register("mounted-nodes", s)), s.has(this) ? (process.env.NODE_ENV !== "production" && _.error("Trying to mount an already mounted component node.", this), () => {
1347
+ }) : (this.events.dispatch("components:node-mounted", { node: this }), this.mountCount === 0 && (this.mountCount = this.mountCount + 1, this.events.dispatch("components:node-enter", { node: this })), () => {
1348
+ s.delete(this), this.events.dispatch("components:node-unmounted", { node: this }), this.mountCount = this.mountCount - 1, this.mountCount === 0 && this.events.dispatch("components:node-exit", { node: this });
1349
+ });
1350
+ }
1351
+ appendChild(t, e = "default") {
1352
+ if (t.parent) {
1353
+ if (t.parent === this)
1354
+ return;
1355
+ t.parent.removeChild(t);
1356
+ }
1357
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].push(t), this.events.dispatch("components:node-appended", { node: t });
1358
+ }
1359
+ prependChild(t, e = "default") {
1360
+ if (t.parent) {
1361
+ if (t.parent === this)
1362
+ return;
1363
+ t.parent.removeChild(t);
1364
+ }
1365
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].unshift(t), this.events.dispatch("components:node-appended", { node: t });
1366
+ }
1367
+ touchProperties(t, e = {}, s) {
1368
+ const i = [{ properties: t }, e];
1369
+ return this.changesets.push(i), this.events.dispatch("components:set-properties", { node: this }), () => {
1370
+ if (s) {
1371
+ const r = this.changesets.indexOf(i);
1372
+ r > -1 && (this.changesets.splice(r, 1), this.events.dispatch("components:set-properties", { node: this }));
1373
+ }
1374
+ };
1375
+ }
1376
+ writeProperties(t, e = {}, s) {
1377
+ const i = [{ properties: t }, e];
1378
+ return this.changesets.push(i), this.events.dispatch("components:set-properties", { node: this }), () => {
1379
+ if (s) {
1380
+ const r = this.changesets.indexOf(i);
1381
+ r > -1 && (this.changesets.splice(r, 1), this.events.dispatch("components:set-properties", { node: this }));
1382
+ }
1383
+ };
1384
+ }
1385
+ writeLayout(t, e = {}, s) {
1386
+ const i = [{ layout: t }, e];
1387
+ return this.changesets.push(i), this.events.dispatch("components:set-layout", { node: this }), () => {
1388
+ if (!s)
1389
+ return;
1390
+ const r = this.changesets.indexOf(i);
1391
+ r > -1 && (this.changesets.splice(r, 1), this.events.dispatch("components:set-layout", { node: this }));
1392
+ };
1393
+ }
1394
+ writeContext(t, e = {}, s) {
1395
+ const i = [{ context: t }, e];
1396
+ return this.changesets.push(i), this.events.dispatch("components:set-context", { node: this }), () => {
1397
+ if (!s)
1398
+ return;
1399
+ const r = this.changesets.indexOf(i);
1400
+ r > -1 && (this.changesets.splice(r, 1), this.events.dispatch("components:set-context", { node: this }));
1401
+ };
1402
+ }
1403
+ getChildren(t = "default") {
1404
+ const e = this.children[t] || [];
1405
+ return e.reduce((s, i, r) => {
1406
+ const { order: o = r } = i.attributes.layout;
1407
+ return s[o] ? s.splice(o, 0, i) : s[o] = i, s;
1408
+ }, Array(e.length));
1409
+ }
1410
+ remove() {
1411
+ this.parent && this.parent.removeChild(this);
1412
+ }
1413
+ removeChild(t) {
1414
+ Object.keys(this.children).forEach((e) => {
1415
+ const s = this.children[e], i = s.indexOf(t);
1416
+ i > -1 && (s.splice(i, 1), this.events.dispatch("components:node-removed", { node: t, parentNode: this }));
1417
+ }), delete t.parent;
1418
+ }
1419
+ };
1420
+ const os = (n, t, e) => {
1421
+ for (let s = 0, i = n.length; s < i && e(n[s]) !== !0; s++) {
1422
+ const r = t[n[s].id] || "default", o = n[s].getChildren(r);
1423
+ os(o, t, e);
1424
+ }
1425
+ }, se = (n, t, e) => {
1426
+ if (e(n) !== !0) {
1427
+ const s = t[n.id] || "default", i = n.children[s];
1428
+ os(i, t, e);
1429
+ }
1430
+ }, Nt = (n, t) => {
1431
+ const e = [];
1432
+ return se(n, t, (s) => {
1433
+ e.push(s);
1434
+ }), e;
1435
+ }, cn = (n, t, e) => {
1436
+ let s;
1437
+ return se(n, t, (i) => {
1438
+ if (e(i))
1439
+ return s = i, !0;
1440
+ }), s;
1441
+ };
1442
+ class hn {
1443
+ constructor(t, e, s) {
1444
+ this.root = t, this.switches = e, this.all = [], this.visible = [], this.detached = [], s.subscribe("components:node-appended", (i, r) => {
1445
+ this.all.push(r.node), this.visible = Nt(t, e);
1446
+ }), s.subscribe("components:node-removed", (i, r) => {
1447
+ let o = this.all.indexOf(r.node);
1448
+ o > -1 && this.all.splice(o, 1), o = this.visible.indexOf(r.node), o > -1 && this.visible.splice(o, 1), this.visible = Nt(t, e);
1449
+ }), s.subscribe("components:node-switched", (i, r) => {
1450
+ this.visible = Nt(t, e);
1451
+ });
1452
+ }
1453
+ query(t = {}) {
1454
+ const e = [];
1455
+ return se(this.root, this.switches, (s) => {
1456
+ Object.keys(t).every((i) => t[i] === s[i]) && e.push(s);
1457
+ }), e;
1458
+ }
1459
+ get(t) {
1460
+ return cn(this.root, this.switches, (e) => e.id === t) || this.detached.find((e) => e.id === t);
1461
+ }
1462
+ }
1463
+ class ln {
1464
+ constructor() {
1465
+ this.handlers = /* @__PURE__ */ new Map();
1466
+ }
1467
+ add(t, e) {
1468
+ this.handlers.set(t, e);
1469
+ }
1470
+ get(t) {
1471
+ return this.handlers.get(t);
1472
+ }
1473
+ }
1474
+ const dn = (n) => {
1475
+ let t = n, e = 0;
1476
+ for (; t.parent; )
1477
+ e = e + 1, t = t.parent;
1478
+ return e;
1479
+ }, un = (n) => n.map(([t, e]) => [dn(t), t, e]).sort(([t], [e]) => t - e).map(([, t, e]) => [t, e]), Tt = (n) => n instanceof Date ? !1 : n && typeof n == "object" && !Array.isArray(n), P = (n, ...t) => {
1480
+ if (!t.length)
1481
+ return n;
1482
+ const e = t.shift();
1483
+ if (Tt(n) && Tt(e))
1484
+ for (const s in e)
1485
+ Tt(e[s]) ? (n[s] || Object.assign(n, { [s]: {} }), P(n[s], e[s])) : Object.assign(n, { [s]: e[s] });
1486
+ return P(n, ...t);
1487
+ }, pn = (n, t) => !n || n === "all" ? !0 : n.some((e) => t.indexOf(e) > -1), gn = (n, t) => {
1488
+ let e = [], s = [], i;
1489
+ const r = () => {
1490
+ process.env.NODE_ENV !== "production" && console.time("state-processor.flush");
1491
+ const a = /* @__PURE__ */ new Map(), c = un(e.map((l, d) => [l, s[d]])), h = (l, d) => {
1492
+ var u;
1493
+ const p = a.get(l) || {}, b = d.context && !p.context, w = d.properties && !p.properties, xt = d.layout && !p.layout;
1494
+ a.set(l, {
1495
+ context: p.context || b,
1496
+ properties: p.properties || w,
1497
+ layout: p.layout || xt
1498
+ }), w && (l.attributes.properties = {}), xt && (l.attributes.layout = {}), b && (l.attributes.context = P({}, (u = l.parent) == null ? void 0 : u.attributes.context));
1499
+ const ge = [], me = [], ve = [];
1500
+ if (l.changesets.forEach((C) => {
1501
+ const [A, Ct] = C;
1502
+ pn(Ct.breakpoints, n.breakpoints) && (w && (typeof A.properties == "function" ? ge.push(
1503
+ A.properties
1504
+ ) : P(l.attributes.properties, A.properties)), xt && (typeof A.layout == "function" ? me.push(A.layout) : P(l.attributes.layout, A.layout)), b && (typeof A.context == "function" ? ve.push(A.context) : P(l.attributes.context, A.context)));
1505
+ }), ge.forEach((C) => {
1506
+ P(l.attributes.properties, C(l.attributes.properties));
1507
+ }), me.forEach((C) => {
1508
+ P(l.attributes.layout, C(l.attributes.layout));
1509
+ }), ve.forEach((C) => {
1510
+ P(l.attributes.context, C(l.attributes.context));
1511
+ }), b || d.recursive) {
1512
+ const C = n.getBranch(l), A = d.recursive ? d : {
1513
+ context: !!b
1514
+ };
1515
+ l.getChildren(C).forEach((Ct) => {
1516
+ h(Ct, A);
1517
+ });
1518
+ }
1519
+ };
1520
+ process.env.NODE_ENV !== "production" && console.timeEnd("state-processor.flush"), c.forEach(([l, d]) => {
1521
+ h(l, d);
1522
+ }), e = [], s = [], t(a);
1523
+ }, o = () => {
1524
+ clearTimeout(i), i = setTimeout(r, 0);
1525
+ };
1526
+ return (a, c) => {
1527
+ const h = e.indexOf(a);
1528
+ if (h > -1) {
1529
+ const l = s[h];
1530
+ return c.context && (l.context = !0), c.properties && (l.properties = !0), c.layout && (l.layout = !0), c.recursive && (l.recursive = !0), o();
1531
+ }
1532
+ return e.push(a), s.push(c), o();
1533
+ };
1534
+ };
1535
+ class mn {
1536
+ constructor(t, e = {}) {
1537
+ this.providers = e, this.breakpoints = [], this.actionsState = { handlers: [], watchers: [] }, this.switches = {}, this.changesets = [], this.subscriptions = [], this.customComponentHandler = new ln(), this.events = t.events.createChild(this);
1538
+ const s = new Oe(this.events, "root");
1539
+ s.name = `root-${t.name}`, this.nodes = new hn(s, this.switches, this.events);
1540
+ const i = this.processNode = gn(this, (r) => {
1541
+ const o = Array.from(r.keys());
1542
+ process.env.NODE_ENV !== "production" && console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
1543
+ ${o.map(
1544
+ (a) => `${a.name || "<no name>"} (${a.id})
1545
+ `
1546
+ )}`), o.forEach((a) => {
1547
+ const c = r.get(a);
1548
+ a.parent && a.parent.type === "root" && this.events.dispatch("components:root-children-changed", { node: a }), c != null && c.context && this.events.dispatch("components:context-changed", { node: a }), c != null && c.properties && this.events.dispatch("components:properties-changed", { node: a }), c != null && c.layout && this.events.dispatch("components:layout-changed", { node: a });
1549
+ }), this.events.dispatch("components:component-model-initialized", {}, { bubbles: !0 });
1550
+ });
1551
+ Promise.all(
1552
+ Object.keys(e).map((r) => e[r].load(this))
1553
+ ), this.subscriptions.push(
1554
+ this.events.subscribe(
1555
+ "components:node-appended",
1556
+ (r, o) => {
1557
+ const { node: a } = o;
1558
+ this.changesets.forEach((c) => {
1559
+ const { changeset: h, target: l, removes: d } = c, [u, p] = h;
1560
+ l.match(o.node) && (u.properties && d.push(a.writeProperties(u.properties, p)), u.context && d.push(a.writeContext(u.context, p)), u.layout && d.push(a.writeLayout(u.layout, p)));
1561
+ });
1562
+ }
1563
+ )
1564
+ ), this.subscriptions.push(
1565
+ this.events.subscribe(
1566
+ "components:node-appended",
1567
+ (r, o) => {
1568
+ i(o.node, { properties: !0, context: !0 });
1569
+ }
1570
+ )
1571
+ ), this.subscriptions.push(
1572
+ this.events.subscribe(
1573
+ "components:set-properties",
1574
+ (r, o) => {
1575
+ i(o.node, { properties: !0 });
1576
+ }
1577
+ )
1578
+ ), this.subscriptions.push(
1579
+ this.events.subscribe(
1580
+ "components:set-context",
1581
+ (r, o) => {
1582
+ i(o.node, { properties: !0, context: !0 });
1583
+ }
1584
+ )
1585
+ ), this.subscriptions.push(
1586
+ this.events.subscribe(
1587
+ "components:set-indent",
1588
+ (r, o) => {
1589
+ i(o.node, { layout: !0 });
1590
+ }
1591
+ )
1592
+ ), this.subscriptions.push(
1593
+ this.events.subscribe(
1594
+ "components:set-layout",
1595
+ (r, o) => {
1596
+ i(o.node, { layout: !0 });
1597
+ }
1598
+ )
1599
+ ), this.subscriptions.push(
1600
+ this.events.subscribe("components:node-switched", (r, { node: o, branch: a }) => {
1601
+ i(o, {
1602
+ layout: !0,
1603
+ recursive: !0,
1604
+ properties: !0,
1605
+ context: !0
1606
+ });
1607
+ })
1608
+ ), this.subscriptions.push(
1609
+ this.events.subscribe("components:node-removed", (r, { parentNode: o }) => {
1610
+ i(o, { properties: !0 });
1611
+ })
1612
+ ), this.events.parent && this.events.parent.dispatch("components:platform-created", { platform: this });
1613
+ }
1614
+ static getInstance(t) {
1615
+ return t.getAsync("components");
1616
+ }
1617
+ addBreakpoint(t) {
1618
+ this.breakpoints.indexOf(t) === -1 && (this.breakpoints.push(t), this.processNode(this.nodes.root, {
1619
+ context: !0,
1620
+ properties: !0,
1621
+ layout: !0,
1622
+ recursive: !0
1623
+ }));
1624
+ }
1625
+ removeBreakpoint(t) {
1626
+ const e = this.breakpoints.indexOf(t);
1627
+ e > -1 && (this.breakpoints.splice(e, 1), this.processNode(this.nodes.root, {
1628
+ context: !0,
1629
+ properties: !0,
1630
+ layout: !0,
1631
+ recursive: !0
1632
+ }));
1633
+ }
1634
+ setSwitch(t, e) {
1635
+ this.switches[t.id] = e, this.events.dispatch("components:node-switched", { node: t, branch: e });
1636
+ }
1637
+ getBranch(t) {
1638
+ return this.switches[t.id];
1639
+ }
1640
+ /**
1641
+ * Creates a `ComponentNode` of the specified type.
1642
+ * @param type Type of node.
1643
+ */
1644
+ createNode(t, e = {}) {
1645
+ const s = new Oe(this.events, t);
1646
+ return e.detached && this.nodes.detached.push(s), s;
1647
+ }
1648
+ components() {
1649
+ return new rs(this);
1650
+ }
1651
+ actions(t, e) {
1652
+ return new ee(this, t, e);
1653
+ }
1654
+ write(t) {
1655
+ const { provider: e, target: s, attributes: i, options: r = {}, removable: o } = t, a = t.key || M(), c = { changeset: [i, r], target: s, removes: [] };
1656
+ if (e) {
1657
+ const h = this.providers[e];
1658
+ h.write(a, s, i, r), c.removes.push(() => {
1659
+ h.remove(a);
1660
+ });
1661
+ }
1662
+ return this.changesets.push(c), this.nodes.all.forEach((h) => {
1663
+ if (s.match(h)) {
1664
+ let l = () => {
1665
+ };
1666
+ i.properties && (l = h.writeProperties(i.properties, r, o)), i.context && (l = h.writeContext(i.context, r, o)), i.layout && (l = h.writeContext(i.layout, r, o)), c.removes.push(l);
1667
+ }
1668
+ }), () => {
1669
+ if (o) {
1670
+ c.removes.forEach((l) => l());
1671
+ const h = this.changesets.indexOf(c);
1672
+ h > -1 && this.changesets.splice(h, 1);
1673
+ }
1674
+ };
1675
+ }
1676
+ addComponentHandler(t, e) {
1677
+ this.customComponentHandler.add(t, e);
1678
+ }
1679
+ getComponentHandler(t) {
1680
+ return this.customComponentHandler.get(t);
1681
+ }
1682
+ dispose() {
1683
+ this.subscriptions.forEach((t) => t());
1684
+ }
1685
+ }
1686
+ const vn = "#____version____#", as = class extends ns {
1687
+ constructor(t, e = []) {
1688
+ super(t, e, {
1689
+ transformPluginSettings: (s, i, r) => {
1690
+ const o = r.get("$settings"), a = o.plugins && i ? o.plugins[i] || {} : {};
1691
+ return qt(qt({}, a), s);
1692
+ }
1693
+ });
1694
+ }
1695
+ createImplementation(t) {
1696
+ const e = super.createImplementation(t);
1697
+ return e.bindings = t.bindings, e;
1698
+ }
1699
+ /**
1700
+ * Performs navigation for widgets matching the specified selector by invoking a
1701
+ * 'navigate' command.
1702
+ * @param selector Widget selector matching the widget(s) to perform navigation on.
1703
+ * @param route Route name.
1704
+ * @param params Route params.
1705
+ */
1706
+ navigate(t, e, s) {
1707
+ this.widgets.query(t).forEach((i) => i.invoke("navigate", { route: e, params: s }));
1708
+ }
1709
+ /**
1710
+ * Creates a runtime based on provided configuration.
1711
+ * @param configuration Runtime configuration.
1712
+ */
1713
+ static create(t = {}) {
1714
+ const e = [_s].concat(
1715
+ t.configurationApiExtensions || []
1716
+ );
1717
+ return new as("humany", e);
1718
+ }
1719
+ /**
1720
+ * Creates a widget runtime based on provided configuration and retains configuration handlers
1721
+ * registered on global context. Use this factory to fully support the default embed script.
1722
+ * Will return any existing widget runtime if available.
1723
+ * @param configuration Runtime configuration.
1724
+ * @param global Object to read configuration handlers from (default: window).
1725
+ */
1726
+ static createFromGlobal(t, e = {}) {
1727
+ if (this.isRuntime(t))
1728
+ return t.patch(e), t;
1729
+ const s = [], i = t && t._c;
1730
+ i && i.forEach((o) => s.push(o));
1731
+ const r = this.create(e);
1732
+ return r.container.register("$runtimecfg", s), r;
1733
+ }
1734
+ /**
1735
+ * Determines whether the specified object is a valid widget runtime.
1736
+ * @param obj Object to compare.
1737
+ */
1738
+ static isRuntime(t) {
1739
+ return !!(t && typeof t == "object" && t.container && typeof t.container.get == "function" && t.container.get("$environment") === t && t.container.owner === t);
1740
+ }
1741
+ };
1742
+ let fn = as;
1743
+ fn.version = `${vn} (${te})`;
1744
+ var yn = Object.defineProperty, Ne = Object.getOwnPropertySymbols, bn = Object.prototype.hasOwnProperty, $n = Object.prototype.propertyIsEnumerable, Te = (n, t, e) => t in n ? yn(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, L = (n, t) => {
1745
+ for (var e in t || (t = {}))
1746
+ bn.call(t, e) && Te(n, e, t[e]);
1747
+ if (Ne)
1748
+ for (var e of Ne(t))
1749
+ $n.call(t, e) && Te(n, e, t[e]);
1750
+ return n;
1751
+ }, y = /* @__PURE__ */ ((n) => (n.Cookie = "cookie", n.Local = "local", n.Session = "session", n))(y || {}), bt = /* @__PURE__ */ ((n) => (n.Tenant = "tenant", n.Implementation = "implementation", n.Widget = "widget", n))(bt || {}), f = /* @__PURE__ */ ((n) => (n.Necessary = "necessary", n.Functional = "functional", n.Analytical = "analytical", n.Marketing = "marketing", n))(f || {});
1752
+ const $t = (n, t, e, s = {}) => Me(n, e).then((i) => (process.env.NODE_ENV !== "production" && i && _.warn(
1753
+ `createStorageWriter: Attempted to create storage writer using unallowed category.
1754
+ Key: ${t}
1755
+ Category: ${JSON.stringify(e)}
1756
+ Options: ${JSON.stringify(s)}`
1757
+ ), (r) => (ie(n), Me(n, e).then((o) => {
1758
+ if (o) {
1759
+ process.env.NODE_ENV !== "production" && _.warn(
1760
+ `storageWriter: Attempted to write to storage using unallowed category.
1761
+ Key: ${t}
1762
+ Category: ${JSON.stringify(e)}
1763
+ Value: ${JSON.stringify(r)}
1764
+ Options: ${JSON.stringify(s)}`
1765
+ );
1766
+ return;
1767
+ }
1768
+ const {
1769
+ scope: a = bt.Widget,
1770
+ medium: c = y.Session,
1771
+ duration: h
1772
+ } = s, l = _n();
1773
+ return l[a][t] = ls(r, e, h), c === y.Cookie ? Pn(n, l) : Sn(n, c, l);
1774
+ })))), W = (n, t, e = y.Session) => (ie(n), typeof t > "u" ? (process.env.NODE_ENV !== "production" && _.warn("readStorage: Undefined key passed when reading storage. ", t, e), Promise.resolve(void 0)) : e === y.Cookie ? Cn(n).then((s) => Jt(s, t)) : kn(n, e).then((s) => Jt(s, t))), B = (n) => !!Object.entries(n).filter(([t, e]) => typeof e < "u").length, Mt = (n) => Object.entries(n).filter(([t, e]) => typeof e < "u").forEach(([t, { value: e }]) => {
1775
+ typeof e > "u" && delete n[t];
1776
+ }), cs = (n, t) => {
1777
+ const e = {
1778
+ tenant: L(L({}, n.tenant), t.tenant),
1779
+ implementation: L(L({}, n.implementation), t.implementation),
1780
+ widget: L(L({}, n.widget), t.widget)
1781
+ };
1782
+ return Mt(e.tenant), Mt(e.implementation), Mt(e.widget), e;
1783
+ }, wn = (n) => Object.entries(n).reduce((t, e) => {
1784
+ const [s, i] = e;
1785
+ return Object.entries(i).forEach((r) => {
1786
+ const [o, { expiration: a }] = r;
1787
+ a && t.push(a);
1788
+ }), t;
1789
+ }, []).slice().sort((t, e) => new Date(e).valueOf() - new Date(t).valueOf()).shift() || re(), wt = (n) => {
1790
+ const {
1791
+ name: t,
1792
+ implementation: { name: e, tenant: s }
1793
+ } = n.get("$widget");
1794
+ return [
1795
+ `humany_${s}`,
1796
+ `humany_${Pe(s + e)}`,
1797
+ `humany_${Pe(s + e + t)}`
1798
+ ];
1799
+ }, It = (n) => {
1800
+ const t = new RegExp(`(?:^|;)\\s?${n}=(.*?)(?:;|$)`, "i"), e = document.cookie.match(t);
1801
+ return e && e[1] && JSON.parse(e[1]) || void 0;
1802
+ }, Dt = (n, t, e) => {
1803
+ const s = `${n}=${JSON.stringify(t).trim()}`, i = `expires=${new Date(e).toUTCString()}`, r = "path=/", o = "SameSite=None;Secure";
1804
+ return document.cookie = `${s}; ${i}; ${r}; ${o}`;
1805
+ }, ne = (n) => {
1806
+ const [t, e, s] = wt(n), i = It(t) || {}, r = It(e) || {}, o = It(s) || {};
1807
+ return {
1808
+ tenant: i,
1809
+ implementation: r,
1810
+ widget: o
1811
+ };
1812
+ }, hs = (n, t) => {
1813
+ const e = ne(n), s = cs(e, t), [i, r, o] = wt(n), { tenant: a, implementation: c, widget: h } = s, l = wn(t), d = re({ days: -1 });
1814
+ Dt(i, a, B(a) ? l : d), Dt(
1815
+ r,
1816
+ c,
1817
+ B(c) ? l : d
1818
+ ), Dt(o, h, B(h) ? l : d);
1819
+ }, gt = (n, t) => {
1820
+ const [e, s, i] = wt(n), r = t.getItem(e) || "{}", o = t.getItem(s) || "{}", a = t.getItem(i) || "{}";
1821
+ return {
1822
+ tenant: JSON.parse(r),
1823
+ implementation: JSON.parse(o),
1824
+ widget: JSON.parse(a)
1825
+ };
1826
+ }, Vt = (n, t, e) => {
1827
+ const s = gt(n, t), i = cs(s, e), [r, o, a] = wt(n), { tenant: c, implementation: h, widget: l } = i;
1828
+ B(c) ? t.setItem(r, JSON.stringify(c)) : t.removeItem(r), B(h) ? t.setItem(o, JSON.stringify(h)) : t.removeItem(o), B(l) ? t.setItem(a, JSON.stringify(l)) : t.removeItem(a);
1829
+ }, _n = () => ({ tenant: {}, implementation: {}, widget: {} }), An = (n) => n ? !!n && /* @__PURE__ */ new Date() > new Date(n) : !1, Jt = (n, t) => {
1830
+ const e = n.widget[t] || n.implementation[t] || n.tenant[t];
1831
+ return e == null ? void 0 : e.value;
1832
+ }, ls = (n, t, e) => e ? {
1833
+ value: n,
1834
+ category: t,
1835
+ expiration: typeof e == "object" ? re(e) : e
1836
+ } : {
1837
+ value: n,
1838
+ category: t
1839
+ }, En = (n, t) => {
1840
+ const e = Qs(n);
1841
+ return Object.entries(e).forEach(([s, i]) => {
1842
+ Object.entries(i).forEach(([r, o]) => {
1843
+ const { expiration: a, category: c } = o;
1844
+ (An(a) || xn(t, c)) && (i[r] = ls(void 0, c, a));
1845
+ });
1846
+ }), e;
1847
+ }, Me = (n, t) => W(n, "storagePolicy", y.Cookie).then(
1848
+ (e = [f.Necessary]) => !!t && e.indexOf(t) === -1
1849
+ ), xn = (n = [f.Necessary], t) => !!t && n.indexOf(t) === -1, ie = (n) => {
1850
+ const t = ne(n), e = gt(n, window.localStorage), s = gt(n, sessionStorage), i = Jt(t, "storagePolicy"), [r, o, a] = [
1851
+ t,
1852
+ e,
1853
+ s
1854
+ ].map((c) => En(c, i));
1855
+ hs(n, r), Vt(n, window.localStorage, o), Vt(n, window.sessionStorage, a);
1856
+ }, re = (n = { days: 30 }) => {
1857
+ const { days: t = 0, hours: e = 0, minutes: s = 0, seconds: i = 0 } = n, r = /* @__PURE__ */ new Date();
1858
+ return r.setTime(r.getTime() + e * 60 * 60 * 1e3), r.setTime(r.getTime() + t * 24 * 60 * 60 * 1e3), r.setTime(r.getTime() + s * 60 * 1e3), r.setTime(r.getTime() + i * 1e3), r.toISOString();
1859
+ }, Cn = (n) => nt(document)(() => ne(n)), Pn = (n, t) => nt(document)(() => hs(n, t)), kn = (n, t) => {
1860
+ const e = t === y.Local ? window.localStorage : window.sessionStorage;
1861
+ return nt(e)(() => gt(n, e));
1862
+ }, Sn = (n, t, e) => {
1863
+ const s = t === y.Local ? window.localStorage : window.sessionStorage;
1864
+ return nt(s)(() => Vt(n, s, e));
1865
+ }, Ut = (n, t, e, ...s) => {
1866
+ const i = `[${n.get("$environment").name || "webprovisions"}] ${e}`;
1867
+ switch (t) {
1868
+ case "info":
1869
+ console.info(i, ...s);
1870
+ break;
1871
+ case "warning":
1872
+ console.warn(i, ...s);
1873
+ break;
1874
+ case "error":
1875
+ console.error(i, ...s);
1876
+ break;
1877
+ }
1878
+ }, On = (n) => {
1879
+ const t = n.container || n;
1880
+ return {
1881
+ info: (e, ...s) => Ut(t, "info", e, ...s),
1882
+ warn: (e, ...s) => Ut(t, "warning", e, ...s),
1883
+ error: (e, ...s) => Ut(t, "error", e, ...s)
1884
+ };
1885
+ };
1886
+ var mt = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(mt || {}), D = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(D || {});
1887
+ const Nn = (n, t, e, s) => {
1888
+ try {
1889
+ const i = new t(e, s);
1890
+ return {
1891
+ name: n,
1892
+ invoke: (r, o) => {
1893
+ let a;
1894
+ return i[r] && (a = i[r].call(i, o)), Promise.resolve(a);
1895
+ },
1896
+ getInstance: () => i
1897
+ };
1898
+ } catch (i) {
1899
+ if (i.message && i.message.indexOf("is not a constructor") >= 0)
1900
+ return {
1901
+ name: n,
1902
+ invoke: (r) => {
1903
+ let o;
1904
+ return r === "initialize" && (o = t(e, s)), Promise.resolve(o);
1905
+ },
1906
+ getInstance: () => t
1907
+ };
1908
+ throw i;
1909
+ }
1910
+ };
1911
+ function Ie(n, t) {
1912
+ return typeof n > "u" ? t : n;
1913
+ }
1914
+ class Tn {
1915
+ constructor(t = {}) {
1916
+ this.part = t;
1917
+ }
1918
+ createCommand(t, e, s) {
1919
+ let i;
1920
+ typeof e == "function" ? i = {
1921
+ scope: mt.Widget,
1922
+ stage: D.Post,
1923
+ defaultArgs: void 0,
1924
+ handlerResolver: e
1925
+ } : i = {
1926
+ scope: Ie(e.scope, mt.Widget),
1927
+ stage: Ie(e.stage, D.Post),
1928
+ defaultArgs: e.defaultArgs,
1929
+ handlerResolver: s
1930
+ };
1931
+ let r = this.part;
1932
+ const o = t.split(".");
1933
+ return o.forEach((a, c) => {
1934
+ c === o.length - 1 ? r[a] || (r[a] = () => i) : r = this.part[a] = this.part[a] || {};
1935
+ }), this;
1936
+ }
1937
+ get() {
1938
+ return this.part;
1939
+ }
1940
+ }
1941
+ const ds = (n) => {
1942
+ const t = new Tn({});
1943
+ return n(t), t.get();
1944
+ };
1945
+ ds((n) => {
1946
+ n.createCommand(
1947
+ "types.register",
1948
+ { scope: mt.Implementation, stage: D.Pre },
1949
+ (t) => (e, s) => {
1950
+ t.container.get("$types")[e] = s;
1951
+ }
1952
+ ).createCommand(
1953
+ "type",
1954
+ { stage: D.Pre },
1955
+ (t) => (e) => {
1956
+ t.container.register("$type", e);
1957
+ }
1958
+ ).createCommand(
1959
+ "settings",
1960
+ { stage: D.Pre, defaultArgs: [null] },
1961
+ (t) => (e) => {
1962
+ t.events.dispatch(
1963
+ "settings:change",
1964
+ e,
1965
+ { bubbles: !0 }
1966
+ ), t.container.register("$settings", e);
1967
+ }
1968
+ ).createCommand(
1969
+ "plugin",
1970
+ { stage: D.Pre },
1971
+ (t) => (e, s, i) => {
1972
+ const { container: r } = t;
1973
+ let o = null, a = e, c = s;
1974
+ typeof e == "string" && (o = e, a = s, c = i);
1975
+ const h = (l) => {
1976
+ const { transformPluginSettings: d } = t.container.get("$environmentOptions"), u = d ? d(
1977
+ c || {},
1978
+ o,
1979
+ t.container,
1980
+ a
1981
+ ) : s;
1982
+ try {
1983
+ const p = Nn(
1984
+ o,
1985
+ a,
1986
+ r,
1987
+ u
1988
+ );
1989
+ r.get("$plugins").push(p), l && p.invoke("initialize", null);
1990
+ } catch (p) {
1991
+ On(t).warn("Error when initializing plugin", p);
1992
+ }
1993
+ };
1994
+ t.container.get("$instance") ? h(!0) : t.events.subscribeOnce("widget:instance-created", () => h(!1));
1995
+ }
1996
+ ).createCommand(
1997
+ "container.register",
1998
+ (t) => (e, s) => {
1999
+ t.container.register(e, s);
2000
+ }
2001
+ ).createCommand(
2002
+ "container.registerAsync",
2003
+ (t) => (e, s) => {
2004
+ t.container.registerAsync(e, s);
2005
+ }
2006
+ ).createCommand(
2007
+ "container.registerFactory",
2008
+ (t) => (e, s) => {
2009
+ t.container.registerFactory(e, s);
2010
+ }
2011
+ ).createCommand(
2012
+ "container.touch",
2013
+ (t) => (e, s) => {
2014
+ t.container.touch(e, s);
2015
+ }
2016
+ ).createCommand(
2017
+ "csp",
2018
+ {},
2019
+ (t) => (e) => {
2020
+ t.container.register("csp", e);
2021
+ }
2022
+ );
2023
+ });
2024
+ ds((n) => {
2025
+ n.createCommand("storage", (t) => (e = {}) => {
2026
+ const { consent: s } = e;
2027
+ if (typeof s < "u") {
2028
+ if (typeof s != "number" && typeof s != "string" && !Array.isArray(s)) {
2029
+ process.env.NODE_ENV !== "production" && _.warn(
2030
+ `storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
2031
+ Passed consent: ${JSON.stringify(s)}`
2032
+ );
2033
+ return;
2034
+ }
2035
+ if (Array.isArray(s) && !s.every(
2036
+ (r) => typeof r == "number" || typeof r == "string"
2037
+ )) {
2038
+ process.env.NODE_ENV !== "production" && _.warn(
2039
+ `storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
2040
+ Passed consent: ${JSON.stringify(s)}`
2041
+ );
2042
+ return;
2043
+ }
2044
+ const i = [
2045
+ f.Necessary,
2046
+ f.Functional,
2047
+ f.Analytical,
2048
+ f.Marketing
2049
+ ].filter((r, o, a) => typeof s == "number" ? s > o : typeof s == "string" ? a.indexOf(s) + 1 > o : Array.isArray(s) ? s.findIndex((c) => c === o + 1 || c === r) > -1 : !0);
2050
+ return i.indexOf(f.Necessary) === -1 && (process.env.NODE_ENV !== "production" && _.warn(
2051
+ `storagePolicyConfigurationApi: passed consent does not include category: '${f.Necessary}'. Consent has to atleast include the '${f.Necessary}' category.
2052
+ Passed consent: ${JSON.stringify(s)}`
2053
+ ), i.unshift(f.Necessary)), $t(
2054
+ t.container,
2055
+ "storagePolicy",
2056
+ f.Necessary,
2057
+ {
2058
+ medium: y.Cookie,
2059
+ scope: bt.Tenant,
2060
+ duration: { days: 365 }
2061
+ }
2062
+ ).then((r) => r(i)).then(() => {
2063
+ ie(t.container), t.events.dispatch("storage:policy-changed", i);
2064
+ });
2065
+ }
2066
+ });
2067
+ });
2068
+ class Mn {
2069
+ constructor(t) {
2070
+ this.controller = t, this.cache = /* @__PURE__ */ new Map(), this.subscriptions = [];
2071
+ const { events: e } = t.container.get("$widget"), s = e.subscribe("data-client:fetched", (i, r) => {
2072
+ r.type === "contact-method" && this.cache.set(r.response.id, r.response);
2073
+ });
2074
+ this.subscriptions.push(s);
2075
+ }
2076
+ getConversationLogs() {
2077
+ return this.controller.messages.reduce(
2078
+ (e, s) => {
2079
+ const i = At(s), { content: r, type: o, sender: a, timestamp: c } = i.content, h = this.parseEntry(r, o, a, c);
2080
+ return h && e.push(h), e;
2081
+ },
2082
+ []
2083
+ );
2084
+ }
2085
+ parseEntry(t, e, s, i) {
2086
+ const r = (h) => {
2087
+ let l = [], d = [], u;
2088
+ if (Array.isArray(h)) {
2089
+ const [b, w] = h;
2090
+ u = w;
2091
+ } else
2092
+ u = h;
2093
+ return this.createMessageContent(u).length && (d = [
2094
+ ...d,
2095
+ this.createMessageContent(u)
2096
+ ]), l = [...l, ...this.createMessageOptions(u)], {
2097
+ messagesAsList: d,
2098
+ options: l
2099
+ };
2100
+ };
2101
+ let o = [], a = [];
2102
+ if (Array.isArray(t.items)) {
2103
+ const { items: h } = t;
2104
+ h.forEach((l) => {
2105
+ const d = r(l);
2106
+ o = [...o, ...d.options], a = [...a, ...d.messagesAsList];
2107
+ });
2108
+ } else {
2109
+ const h = r(t);
2110
+ o = [...o, ...h.options], a = [...a, ...h.messagesAsList];
2111
+ }
2112
+ return {
2113
+ options: o,
2114
+ message: a.length ? a.join(`
2115
+ `) : void 0,
2116
+ source: this.createMessageSource(e),
2117
+ alias: this.createAlias(e, s),
2118
+ timestamp: i
2119
+ };
2120
+ }
2121
+ createMessageSource(t) {
2122
+ return t;
2123
+ }
2124
+ createAlias(t, e) {
2125
+ return t === _t.System ? "system" : (e == null ? void 0 : e.name) || "Me";
2126
+ }
2127
+ handleContactMethod(t) {
2128
+ if (!this.cache.has(t))
2129
+ return;
2130
+ const e = this.cache.get(t);
2131
+ let s = "";
2132
+ return s = this.appendText(s, `${e.clientName}:`), s = this.appendText(s, e.title), e.description && (s = this.appendText(s, e.title)), s;
2133
+ }
2134
+ getDetails(t, e = !0) {
2135
+ if (!t)
2136
+ return "";
2137
+ const {
2138
+ header: s,
2139
+ title: i,
2140
+ label: r,
2141
+ description: o,
2142
+ text: a,
2143
+ html: c,
2144
+ body: h,
2145
+ contactMethodId: l
2146
+ } = t;
2147
+ let d = "";
2148
+ if (l) {
2149
+ const u = this.handleContactMethod(l.toString());
2150
+ u && (d = this.appendText(d, u, e));
2151
+ }
2152
+ return s && (d = this.appendText(d, s, e)), i && (d = this.appendText(d, i, e)), o && (d = this.appendText(d, o, e)), a && (d = this.appendText(d, a, e)), r && (d = this.appendText(d, r, e)), c && (d = this.appendText(d, c, e)), h && typeof h == "string" && (d = this.appendText(d, h, e)), d;
2153
+ }
2154
+ createMessageContent(t) {
2155
+ let e = "";
2156
+ return e = this.getDetails(t), e;
2157
+ }
2158
+ createMessageOptions(t) {
2159
+ let e = [], s = [];
2160
+ return Array.isArray(t == null ? void 0 : t.actions) ? s = t.actions : typeof (t == null ? void 0 : t.actions) == "object" && (s = Object.entries(t.actions).map(([i, r]) => ({
2161
+ actionKey: i,
2162
+ label: r
2163
+ }))), s.length && (e = s.map((i) => this.getDetails(i, !1))), e;
2164
+ }
2165
+ appendText(t, e, s = !0) {
2166
+ return s && t.length ? `${t}
2167
+ ${e}` : t.length ? `${t} ${e}` : e;
2168
+ }
2169
+ dispose() {
2170
+ this.subscriptions.forEach((t) => {
2171
+ t();
2172
+ });
2173
+ }
2174
+ }
2175
+ class Ft {
2176
+ constructor(t, e) {
2177
+ this.provider = t, this.print = (s, i) => {
2178
+ const r = {
2179
+ name: this.name,
2180
+ avatar: this.avatar,
2181
+ id: this.id
2182
+ }, o = At(s, i);
2183
+ return this.provider.createEntry(
2184
+ o.key,
2185
+ o.content,
2186
+ _t.Agent,
2187
+ r,
2188
+ o.timestamp
2189
+ );
2190
+ }, this.typing = () => this.provider.setTypingState({
2191
+ name: this.name,
2192
+ avatar: this.avatar
2193
+ }), this.id = e.id || M(), this.name = e.name, this.avatar = e.avatar;
2194
+ }
2195
+ update(t) {
2196
+ var i;
2197
+ const { name: e, avatar: s } = t;
2198
+ s === null ? this.avatar = void 0 : s && (this.avatar = s), e === null ? this.name = void 0 : e && (this.name = e), (i = this.provider.controller) == null || i.events.dispatch("conversation:agent-updated", {
2199
+ agent: this
2200
+ });
2201
+ }
2202
+ }
2203
+ class oe {
2204
+ constructor(t, e, s) {
2205
+ this.name = t, this.controller = s, this.subscriptions = [], this.user = s == null ? void 0 : s.user, this.options = {
2206
+ silent: !1
2207
+ };
2208
+ }
2209
+ static create(t, e, s) {
2210
+ return new oe(t, e, s);
2211
+ }
2212
+ createAgent(t = {}) {
2213
+ var e;
2214
+ if (this.controller) {
2215
+ const s = this.controller.getAgentById(t.id), i = s ? new Ft(this, { ...s, ...t }) : new Ft(this, t);
2216
+ return s || (e = this.controller) == null || e.events.dispatch("conversation:agent-created", {
2217
+ agent: i
2218
+ }), i;
2219
+ }
2220
+ }
2221
+ print(t) {
2222
+ var e;
2223
+ return (e = this.controller) == null ? void 0 : e.print(t);
2224
+ }
2225
+ setTypingState(t, e) {
2226
+ var s;
2227
+ return (s = this.controller) == null ? void 0 : s.setTypingState(t, e);
2228
+ }
2229
+ loading() {
2230
+ return this.controller ? this.controller.loader() : () => () => {
2231
+ };
2232
+ }
2233
+ createEntry(t, e, s, i, r) {
2234
+ var o;
2235
+ return (o = this.controller) == null ? void 0 : o.createEntry(t, e, s, i, r);
2236
+ }
2237
+ dispose() {
2238
+ var t;
2239
+ process.env.NODE_ENV !== "production" && console.log(`conversation-provider: dispose (${this.name})`), (t = this.controller) == null || t.disposeProvider(this), this.controller = null, this.subscriptions.forEach((e) => e());
2240
+ }
2241
+ isRehydrated() {
2242
+ var t;
2243
+ return ((t = this.controller) == null ? void 0 : t.isRehydrated()) || Promise.resolve(!1);
2244
+ }
2245
+ getHistory() {
2246
+ var t;
2247
+ return ((t = this.controller) == null ? void 0 : t.getHistory()) || [];
2248
+ }
2249
+ complete() {
2250
+ var t;
2251
+ (t = this.controller) == null || t.onCompleteProvider();
2252
+ }
2253
+ setOptions(t = { silent: !1 }) {
2254
+ this.options = t;
2255
+ }
2256
+ onUnreadMessage(t) {
2257
+ var e;
2258
+ if (this.controller) {
2259
+ const s = (e = this.controller) == null ? void 0 : e.onUnreadMessage(t);
2260
+ return this.subscriptions.push(s), () => {
2261
+ s();
2262
+ };
2263
+ }
2264
+ }
2265
+ onMounted(t) {
2266
+ var e;
2267
+ if (this.controller) {
2268
+ const s = (e = this.controller) == null ? void 0 : e.events.subscribe(
2269
+ "conversation:component-mount-changed",
2270
+ t
2271
+ );
2272
+ return this.subscriptions.push(s), t({}, this.controller.getComponentMountedState()), () => {
2273
+ s();
2274
+ };
2275
+ }
2276
+ }
2277
+ }
2278
+ const us = (n) => `conversation-${n}`;
2279
+ class In {
2280
+ constructor() {
2281
+ this._locking = Promise.resolve(), this._locks = 0;
2282
+ }
2283
+ isLocked() {
2284
+ return this._locks > 0;
2285
+ }
2286
+ lock() {
2287
+ this._locks += 1;
2288
+ let t;
2289
+ const e = new Promise(
2290
+ (i) => t = () => {
2291
+ this._locks -= 1, i();
2292
+ }
2293
+ ), s = this._locking.then(() => t);
2294
+ return this._locking = this._locking.then(() => e), s;
2295
+ }
2296
+ }
2297
+ class Dn {
2298
+ constructor(t, e, s) {
2299
+ this.container = t, this.enabled = s, this.locker = new In(), this.initialStoredAgents = [], this.sessionStorageKey = us(e.id), e.onStarted(async () => {
2300
+ if (e.messages.length > 0)
2301
+ return;
2302
+ const { agents: i } = await this.read(), r = [];
2303
+ i && i.forEach((a) => {
2304
+ const c = e.providerIndex(a.providerName), h = c > -1 ? e.registeredProviders[c] : e.createProvider(a.providerName), l = new Ft(h, {
2305
+ name: a.name,
2306
+ avatar: a.avatar,
2307
+ id: a.id
2308
+ });
2309
+ r.push(l);
2310
+ });
2311
+ const { messages: o } = await this.read();
2312
+ o.forEach((a) => {
2313
+ switch (a.type) {
2314
+ case "agent": {
2315
+ const c = r.find((h) => {
2316
+ var l;
2317
+ return h.id === ((l = a.sender) == null ? void 0 : l.id);
2318
+ });
2319
+ c && c.print(a.content.items || a.content, {
2320
+ key: a.key
2321
+ });
2322
+ return;
2323
+ }
2324
+ case "user": {
2325
+ e.user.print(a.content.items || a.content, {
2326
+ key: a.key
2327
+ });
2328
+ return;
2329
+ }
2330
+ case "system":
2331
+ default:
2332
+ e.print(a.content.items || a.content);
2333
+ }
2334
+ });
2335
+ }), e.onMessageCreated(async (i, r) => {
2336
+ this.write(r.message, "messages");
2337
+ }), e.events.subscribe(
2338
+ "conversation:agent-created",
2339
+ async (i, r) => {
2340
+ const o = {
2341
+ id: r.agent.id,
2342
+ name: r.agent.name,
2343
+ avatar: r.agent.avatar,
2344
+ providerName: r.agent.provider.name
2345
+ };
2346
+ await this.write(o, "agents");
2347
+ }
2348
+ ), e.events.subscribe(
2349
+ "conversation:agent-updated",
2350
+ async (i, r) => {
2351
+ const { agents: o } = await this.read();
2352
+ await this.write(
2353
+ [
2354
+ ...o.map((a) => a.id === r.agent.id ? {
2355
+ ...a,
2356
+ name: r.agent.name,
2357
+ avatar: r.agent.avatar
2358
+ } : a)
2359
+ ],
2360
+ "agents",
2361
+ "update"
2362
+ );
2363
+ }
2364
+ );
2365
+ }
2366
+ setInitialData(t) {
2367
+ this.initialStoredAgents = t.agents;
2368
+ }
2369
+ async isRehydrated() {
2370
+ const { messages: t } = await this.read();
2371
+ return t.length > 0;
2372
+ }
2373
+ getStoredAgent(t) {
2374
+ if (this.enabled)
2375
+ return this.initialStoredAgents.find((e) => e.id === t);
2376
+ }
2377
+ async write(t, e, s = "add") {
2378
+ if (!this.enabled)
2379
+ return;
2380
+ const i = await this.locker.lock();
2381
+ return $t(
2382
+ this.container,
2383
+ this.sessionStorageKey,
2384
+ f.Necessary
2385
+ ).then(async (r) => {
2386
+ if (s === "add") {
2387
+ const o = await this.read();
2388
+ if (e === "messages" && o.messages.findIndex((c) => c.key === t.key) > -1) {
2389
+ i();
2390
+ return;
2391
+ }
2392
+ const a = {
2393
+ ...o
2394
+ };
2395
+ return e === "messages" ? a.messages = [...a.messages, t] : e === "agents" && (a.agents = [...a.agents, t]), r({
2396
+ ...o,
2397
+ ...a
2398
+ }).then(() => {
2399
+ i();
2400
+ });
2401
+ }
2402
+ if (s === "update" && e === "agents") {
2403
+ const o = await this.read();
2404
+ return r({
2405
+ ...o,
2406
+ agents: t
2407
+ }).then(() => {
2408
+ i();
2409
+ });
2410
+ }
2411
+ return r(t).then(() => {
2412
+ i();
2413
+ });
2414
+ });
2415
+ }
2416
+ async read() {
2417
+ return W(this.container, this.sessionStorageKey).then((t) => t || {
2418
+ messages: [],
2419
+ agents: []
2420
+ });
2421
+ }
2422
+ }
2423
+ class Un {
2424
+ constructor(t) {
2425
+ this.controller = t, this.print = (e, s) => {
2426
+ const i = At(e, s);
2427
+ return this.controller.createEntry(
2428
+ i.key,
2429
+ i.content,
2430
+ _t.User,
2431
+ void 0,
2432
+ i.timestamp
2433
+ );
2434
+ };
2435
+ }
2436
+ }
2437
+ const Kt = async (n, t, e) => {
2438
+ const s = await n.getAsync(
2439
+ "conversation"
2440
+ ), i = await n.getAsync("components"), r = s.controllers.find((o) => o.conversation.id === t);
2441
+ if (r) {
2442
+ const o = [...r.conversation.providers];
2443
+ o.forEach((c) => {
2444
+ r.conversation.setProviderOptions(c, { silent: !0 });
2445
+ }), r.conversation.queueProviders(o), r.conversation.setProviders([e]);
2446
+ const a = i.components().ofType("conversation");
2447
+ i.write({
2448
+ key: "setConversationProvider",
2449
+ attributes: {
2450
+ properties: { providers: [e] }
2451
+ },
2452
+ target: a,
2453
+ provider: "localStorage"
2454
+ });
2455
+ }
2456
+ };
2457
+ class Hn {
2458
+ constructor(t) {
2459
+ this.writer = t, this.entryId = M();
2460
+ }
2461
+ update(t) {
2462
+ const e = this.getNormalizedSettings(t);
2463
+ this.writer(e);
2464
+ }
2465
+ remove() {
2466
+ this.writer(null);
2467
+ }
2468
+ getNormalizedSettings(t) {
2469
+ return typeof t == "string" ? { body: t } : t.length > -1 && typeof t == "object" ? { items: t } : t;
2470
+ }
2471
+ }
2472
+ var _t = /* @__PURE__ */ ((n) => (n.User = "user", n.Agent = "agent", n.System = "system", n))(_t || {});
2473
+ const At = (n, t) => {
2474
+ let e, s = (t == null ? void 0 : t.key) || M(), i = Date.now();
2475
+ return Array.isArray(n) && n.length > -1 ? typeof n[0] == "string" ? e = { items: [n] } : e = { items: n } : typeof n == "string" ? e = { body: n } : (n = n || {}, n.type ? e = {
2476
+ ...n
2477
+ } : (e = {
2478
+ body: n.body,
2479
+ actions: n.actions,
2480
+ title: n.title
2481
+ }, n.key && (s = n.key), n.timestamp && (i = n.timestamp), n.form, n.timestamp === null && (i = null))), { content: e, key: s, timestamp: i };
2482
+ }, De = (n, t) => {
2483
+ if (!t)
2484
+ return;
2485
+ const e = JSON.stringify(t), s = n.findIndex((i) => e === JSON.stringify(i));
2486
+ if (s > -1)
2487
+ return n.splice(s, 1);
2488
+ };
2489
+ class jn {
2490
+ constructor(t, e, s) {
2491
+ this.container = t, this.id = e, this.formHandlers = {}, this.user = new Un(this), this.providers = [], this.active = !1, this.queuedProviders = [], this.registeredProviders = [], this.loaders = 0, this.componentMounted = !1, this.messages = [], this.typingActors = [], this.print = (r) => {
2492
+ const o = At(r);
2493
+ return this.createEntry(
2494
+ o.key,
2495
+ o.content,
2496
+ "system",
2497
+ void 0,
2498
+ o.timestamp
2499
+ );
2500
+ };
2501
+ const i = t.get("$widget");
2502
+ this.events = i.events.createChild(this), this.store = new Dn(t, this, s.rehydrate), this.conversationHistory = new Mn(this);
2503
+ }
2504
+ setInitialStorage(t) {
2505
+ this.store.setInitialData(t);
2506
+ }
2507
+ setProviders(t) {
2508
+ const e = [], s = [];
2509
+ this.providers.reduce((i, r) => (t.indexOf(r) === -1 && i.push(r), i), []).forEach((i) => {
2510
+ const r = this.providers.indexOf(i);
2511
+ r > -1 && (e.push(i), this.providers.splice(r, 1));
2512
+ }), t.forEach((i) => {
2513
+ this.providers.indexOf(i) === -1 && (s.push(i), this.providers.push(i));
2514
+ }), (s.length || e.length) && this.events.dispatch("conversation:providers-changed", {
2515
+ added: s,
2516
+ removed: e
2517
+ });
2518
+ }
2519
+ createProvider(t) {
2520
+ const e = this.providerIndex(t);
2521
+ if (e > -1)
2522
+ return this.registeredProviders[e];
2523
+ const s = oe.create(t, this.container, this);
2524
+ return this.registeredProviders.push(s), s;
2525
+ }
2526
+ providerIndex(t) {
2527
+ return this.registeredProviders.findIndex((e) => e.name === t);
2528
+ }
2529
+ getAgentById(t) {
2530
+ if (t)
2531
+ return this.store.getStoredAgent(t);
2532
+ }
2533
+ dispose() {
2534
+ this.conversationHistory.dispose(), this.registeredProviders.forEach((t) => t.dispose()), this.messages = [], this.events.dispatch("conversation:controller-disposed", this), this.active = !1;
2535
+ }
2536
+ onDispose(t) {
2537
+ return this.events.subscribe("conversation:controller-disposed", t);
2538
+ }
2539
+ onStarted(t) {
2540
+ return this.events.subscribe("conversation:started", t);
2541
+ }
2542
+ onMessageCreated(t) {
2543
+ return this.events.subscribe("conversation:message-created", t);
2544
+ }
2545
+ isRehydrated() {
2546
+ return this.store.isRehydrated();
2547
+ }
2548
+ disposeProvider(t) {
2549
+ const e = this.providerIndex(t.name);
2550
+ e > -1 && this.registeredProviders.splice(e, 1), this.events.dispatch("conversation:providers-changed", {
2551
+ removed: [t.name]
2552
+ }), this.registeredProviders.length || this.dispose();
2553
+ }
2554
+ onProvidersChange(t) {
2555
+ return this.events.subscribe("conversation:providers-changed", t);
2556
+ }
2557
+ setComponentMountedState(t) {
2558
+ this.componentMounted !== t && (this.componentMounted = t, t && (this.events.dispatch("conversation:unread-message", !1), this.events.dispatch("conversation:started", !0), this.active = !0), this.events.dispatch("conversation:component-mount-changed", t));
2559
+ }
2560
+ setProviderOptions(t, e) {
2561
+ const s = this.providerIndex(t);
2562
+ s > -1 && this.registeredProviders[s].setOptions(e);
2563
+ }
2564
+ changeProvider(t) {
2565
+ this.registeredProviders.find(
2566
+ (s) => s.name === t
2567
+ ) && Kt(this.container, this.id, t);
2568
+ }
2569
+ queueProviders(t) {
2570
+ this.queuedProviders = t;
2571
+ }
2572
+ onCompleteProvider() {
2573
+ const t = this.queuedProviders.pop();
2574
+ t && Kt(this.container, this.id, t);
2575
+ }
2576
+ getComponentMountedState() {
2577
+ return this.componentMounted;
2578
+ }
2579
+ onUnreadMessage(t) {
2580
+ return this.events.subscribe("conversation:unread-message", t);
2581
+ }
2582
+ createEntry(t, e, s, i, r) {
2583
+ const o = {
2584
+ key: t,
2585
+ content: e,
2586
+ type: s,
2587
+ sender: i || null,
2588
+ timestamp: r || r === null ? r : Date.now()
2589
+ };
2590
+ this.messages.push(o), o.type === "agent" && De(this.typingActors, i);
2591
+ const a = new Hn((c) => {
2592
+ if (c !== null) {
2593
+ const { timestamp: h = void 0, ...l } = c;
2594
+ o.content = l, h && (o.timestamp = h);
2595
+ } else {
2596
+ const h = this.messages.indexOf(o);
2597
+ o.content = null, h > -1 && this.messages.splice(h, 1);
2598
+ }
2599
+ this.events.dispatch("conversation:message-updated", { message: o }), this.update();
2600
+ });
2601
+ return this.events.dispatch("conversation:message-created", { message: o }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), a;
2602
+ }
2603
+ update() {
2604
+ this.events.dispatch("conversation:updated", {
2605
+ messages: this.messages,
2606
+ loading: this.loaders > 0,
2607
+ typingActors: this.typingActors
2608
+ });
2609
+ }
2610
+ getMessageStream() {
2611
+ return {
2612
+ messages: this.messages,
2613
+ loading: this.loaders > 0,
2614
+ typingActors: this.typingActors
2615
+ };
2616
+ }
2617
+ setTypingState(t, e) {
2618
+ return this.typingActors.indexOf(t) === -1 && (this.typingActors.push(t), this.update()), () => {
2619
+ De(this.typingActors, t), this.update();
2620
+ };
2621
+ }
2622
+ /**
2623
+ * Displays a loader in the conversation.
2624
+ */
2625
+ loader() {
2626
+ this.loaders = this.loaders + 1;
2627
+ let t = !1;
2628
+ return this.loaders === 1 && this.update(), () => {
2629
+ t || (t = !0, this.loaders = this.loaders - 1, this.loaders === 0 && this.update());
2630
+ };
2631
+ }
2632
+ submitForm(t, e) {
2633
+ this.formHandlers[t] = { ...this.formHandlers[t], submit: e };
2634
+ }
2635
+ validateForm(t, e) {
2636
+ this.formHandlers[t] = { ...this.formHandlers[t], validate: e };
2637
+ }
2638
+ getHistory() {
2639
+ return this.conversationHistory.getConversationLogs();
2640
+ }
2641
+ }
2642
+ const Ln = (n, t) => {
2643
+ const e = n.split("_contact");
2644
+ return t.widgets.get(e[0]);
2645
+ }, ae = (n) => {
2646
+ const t = n.get("$widget"), { name: e, implementation: s } = n.get("$widget"), i = e.indexOf("_contact") > -1 ? Ln(e, s) : t, { data: r } = n.get("$settings"), { trigger: o } = i.container.get("$settings"), a = `${e.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(a);
2647
+ return c && !o ? { chatWidget: c, mainWidget: i, data: r } : { mainWidget: i, data: r };
2648
+ }, Rn = (n) => {
2649
+ const { chatWidget: t } = ae(n);
2650
+ return !!t;
2651
+ }, Ue = (n, t, e) => {
2652
+ const {
2653
+ mainWidget: s,
2654
+ data: i,
2655
+ chatWidget: r
2656
+ } = ae(n);
2657
+ return r ? r.state === "activated" ? r.invoke("open").then(() => {
2658
+ r.container.getAsync("conversation").then((o) => {
2659
+ o.navigateToConversationIfActive(t.id);
2660
+ });
2661
+ }) : r.activate().then(() => {
2662
+ const { trigger: o } = r.container.get("$settings");
2663
+ return o.action = "hide", r.invoke("setSettings", () => ({
2664
+ data: i,
2665
+ trigger: o,
2666
+ activate: !0
2667
+ })).then(() => r.container.getAsync("components").then((a) => {
2668
+ const c = a.components().ofType("contact-method");
2669
+ a.write({
2670
+ key: "setContactMethodId",
2671
+ attributes: {
2672
+ properties: {
2673
+ id: t.id,
2674
+ guideId: t.guideId
2675
+ }
2676
+ },
2677
+ target: c,
2678
+ provider: "localStorage"
2679
+ });
2680
+ const h = a.components().ofType("conversation");
2681
+ a.write({
2682
+ key: "setConversationProvider",
2683
+ attributes: {
2684
+ properties: { providers: [t.clientName] }
2685
+ },
2686
+ target: h,
2687
+ provider: "localStorage"
2688
+ });
2689
+ }));
2690
+ }).then(() => r.invoke("attach", {
2691
+ key: "contact-method",
2692
+ triggerDOMElement: e,
2693
+ withRenderState: "open"
2694
+ })).then(() => ($t(
2695
+ r.container,
2696
+ "activeStickyWidget",
2697
+ f.Necessary,
2698
+ {
2699
+ medium: y.Local,
2700
+ scope: bt.Implementation
2701
+ }
2702
+ ).then((o) => o(r.name)), r.container.getAsync("conversation").then((o) => {
2703
+ o.setConversationEndedBehavior(
2704
+ ce.Deactivate
2705
+ );
2706
+ }).then(() => !1))) : !r;
2707
+ }, zn = (n, t, e = "conversation") => {
2708
+ const { mainWidget: s, chatWidget: i } = ae(n);
2709
+ return s.container.getAsync("conversation").then((r) => {
2710
+ var o;
2711
+ (o = r.setConversationEndedBehavior(ce.Navigate)) == null || o.then(() => {
2712
+ s.container.getAsync("components").then((a) => {
2713
+ const c = a.components().ofType("conversation");
2714
+ a.write({
2715
+ key: "setConversationProvider",
2716
+ attributes: {
2717
+ properties: { providers: [t.clientName] }
2718
+ },
2719
+ target: c,
2720
+ provider: "localStorage"
2721
+ });
2722
+ });
2723
+ });
2724
+ });
2725
+ }, ht = "conversations";
2726
+ var ce = /* @__PURE__ */ ((n) => (n.Deactivate = "deactivate", n.Navigate = "navigate", n.None = "none", n))(ce || {});
2727
+ class he {
2728
+ constructor(t, e) {
2729
+ this.container = t, this.components = e, this.controllers = [], this.providers = [], this.disposeProviders = {}, this.subscriptions = [], this.storageWriter = null, this.buttonQuery = null, this.sessionInfo = null;
2730
+ const s = t.get("$widget");
2731
+ this.events = s.events.createChild(this);
2732
+ }
2733
+ initialize() {
2734
+ $t(
2735
+ this.container,
2736
+ ht,
2737
+ f.Necessary,
2738
+ {
2739
+ medium: y.Local
2740
+ }
2741
+ ).then((t) => this.storageWriter = t), W(
2742
+ this.container,
2743
+ ht,
2744
+ y.Local
2745
+ ).then((t) => {
2746
+ this.buttonQuery = this.components.components().ofType("conversation-return-button"), t && (this.sessionInfo = t, t.id && t.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
2747
+ }), this.events.subscribe("conversation:ended", (t, e) => {
2748
+ var s;
2749
+ switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
2750
+ case "deactivate":
2751
+ this.container.get("$widget").deactivate();
2752
+ break;
2753
+ }
2754
+ this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
2755
+ });
2756
+ }
2757
+ addSubscription(t) {
2758
+ this.subscriptions.push(t);
2759
+ }
2760
+ static getInstance(t, e = "conversation") {
2761
+ return nt(t)(() => t.getAsync(e).then((s) => {
2762
+ let i = s;
2763
+ return i || mn.getInstance(t).then((r) => (i = new he(t, r), i.initialize(), t.registerAsync(e, () => i), i));
2764
+ }));
2765
+ }
2766
+ // navigateToConversationIfActive(id: string): Promise<void> {
2767
+ // return readStorage<SessionInfo>(
2768
+ // this.container,
2769
+ // STORAGE_KEY,
2770
+ // StorageMedium.Local
2771
+ // ).then((storedSession) => {
2772
+ // if (storedSession && storedSession.id === id) {
2773
+ // if (storedSession.route) {
2774
+ // const { name, params } = storedSession.route;
2775
+ // this.router?.navigate(name, params);
2776
+ // }
2777
+ // }
2778
+ // });
2779
+ // }
2780
+ setConversationEndedBehavior(t) {
2781
+ return W(
2782
+ this.container,
2783
+ ht,
2784
+ y.Local
2785
+ ).then((e) => {
2786
+ let s = e;
2787
+ return s ? s.conversationEndedBehavior = t : s = { conversationEndedBehavior: t }, this.sessionInfo = s, this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
2788
+ });
2789
+ }
2790
+ async createController(t, e) {
2791
+ const s = us(t), { agents: i } = await W(this.container, s) || { agents: [] }, r = this.controllers.findIndex((a) => a.conversation.id === t);
2792
+ let o;
2793
+ return r > -1 ? o = this.controllers[r].conversation : o = new jn(this.container, t, e), o.setInitialStorage({ agents: i || [] }), o;
2794
+ }
2795
+ registerProvider(t, e) {
2796
+ const s = {
2797
+ name: t,
2798
+ handler: e
2799
+ };
2800
+ this.providers.push(s), this.controllers.filter(
2801
+ (i) => i.conversation.providers.indexOf(t) > -1
2802
+ ).forEach((i) => {
2803
+ this.invokeHandler(s, i);
2804
+ });
2805
+ }
2806
+ registerController(t, e) {
2807
+ const s = this.controllers.findIndex(
2808
+ (r) => r.conversation.id === t.id
2809
+ );
2810
+ let i;
2811
+ if (s < 0) {
2812
+ i = { conversation: t, component: e }, this.controllers.push(i);
2813
+ const r = (o) => {
2814
+ o && this.providers.filter((a) => o.indexOf(a.name) > -1).forEach((a) => {
2815
+ this.invokeHandler(a, i);
2816
+ });
2817
+ };
2818
+ return this.subscriptions.push(
2819
+ t.onDispose((o, a) => {
2820
+ const c = this.controllers.findIndex(
2821
+ (h) => h.conversation === a
2822
+ );
2823
+ c > -1 && this.controllers.splice(c, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
2824
+ })
2825
+ ), this.subscriptions.push(
2826
+ t.onProvidersChange((o, a) => {
2827
+ const {
2828
+ added: c,
2829
+ removed: h = []
2830
+ } = a;
2831
+ h.forEach((l) => {
2832
+ (this.disposeProviders[l] || []).forEach(
2833
+ (d) => {
2834
+ d();
2835
+ }
2836
+ );
2837
+ }), r(c);
2838
+ })
2839
+ ), this.subscriptions.push(
2840
+ t.onStarted((o, a) => {
2841
+ var h;
2842
+ const c = {
2843
+ id: t.id,
2844
+ // route: this.router?.getRouteData(),
2845
+ conversationEndedBehavior: (h = this.sessionInfo) == null ? void 0 : h.conversationEndedBehavior
2846
+ };
2847
+ this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: a });
2848
+ })
2849
+ ), this.subscriptions.push(
2850
+ t.onUnreadMessage((o, a) => {
2851
+ this.events.dispatch("conversation:unread-message", a), this.writeToComponents({ alert: { show: a } });
2852
+ })
2853
+ ), r(t.providers), !0;
2854
+ }
2855
+ return i = this.controllers[s], !1;
2856
+ }
2857
+ writeToComponents(t, e = "conversationReturnButtonState") {
2858
+ this.buttonQuery && this.components.write({
2859
+ key: "conversationReturnButtonState",
2860
+ attributes: { properties: t },
2861
+ target: this.buttonQuery,
2862
+ provider: "localStorage"
2863
+ });
2864
+ }
2865
+ invokeHandler(t, e) {
2866
+ const s = t.handler(
2867
+ e.conversation.createProvider(t.name),
2868
+ e.component
2869
+ );
2870
+ s && (this.disposeProviders[t.name] || (this.disposeProviders[t.name] = []), this.disposeProviders[t.name].push(s));
2871
+ }
2872
+ getComponentRoute() {
2873
+ return W(
2874
+ this.container,
2875
+ ht,
2876
+ y.Local
2877
+ ).then((t) => t == null ? void 0 : t.route);
2878
+ }
2879
+ dispose() {
2880
+ Object.keys(this.disposeProviders).forEach((t) => {
2881
+ this.disposeProviders[t].forEach((e) => {
2882
+ e();
2883
+ });
2884
+ }), this.subscriptions.forEach((t) => {
2885
+ t();
2886
+ }), this.controllers = [], this.providers = [];
2887
+ }
2888
+ static async handleContactMethodClick(t, e, s, i) {
2889
+ if (Rn(e)) {
2890
+ t.preventDefault();
2891
+ let r = document.getElementById("humany-dynamic-anchor");
2892
+ r || (r = document.createElement("a"), r.setAttribute("href", "#"), r.id = "humany-dynamic-anchor", document.body.appendChild(r)), Ue(e, s, r);
2893
+ }
2894
+ Ue(e, s);
2895
+ }
2896
+ static async handleContactMethodSubmit(t, e) {
2897
+ var s, i;
2898
+ return (i = (s = e == null ? void 0 : e.body.form.meta) == null ? void 0 : s.conversation) != null && i.id ? Kt(
2899
+ t,
2900
+ e.body.form.meta.conversation.id,
2901
+ e.clientName
2902
+ ) : zn(t, e);
2903
+ }
2904
+ }
2905
+ /**
2906
+ * @license
2907
+ * Copyright 2019 Google LLC
2908
+ * SPDX-License-Identifier: BSD-3-Clause
2909
+ */
2910
+ const dt = window, le = dt.ShadowRoot && (dt.ShadyCSS === void 0 || dt.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, de = Symbol(), He = /* @__PURE__ */ new WeakMap();
2911
+ let ps = class {
2912
+ constructor(t, e, s) {
2913
+ if (this._$cssResult$ = !0, s !== de)
2914
+ throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
2915
+ this.cssText = t, this.t = e;
2916
+ }
2917
+ get styleSheet() {
2918
+ let t = this.o;
2919
+ const e = this.t;
2920
+ if (le && t === void 0) {
2921
+ const s = e !== void 0 && e.length === 1;
2922
+ s && (t = He.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && He.set(e, t));
2923
+ }
2924
+ return t;
2925
+ }
2926
+ toString() {
2927
+ return this.cssText;
2928
+ }
2929
+ };
2930
+ const Wn = (n) => new ps(typeof n == "string" ? n : n + "", void 0, de), Bn = (n, ...t) => {
2931
+ const e = n.length === 1 ? n[0] : t.reduce((s, i, r) => s + ((o) => {
2932
+ if (o._$cssResult$ === !0)
2933
+ return o.cssText;
2934
+ if (typeof o == "number")
2935
+ return o;
2936
+ throw Error("Value passed to 'css' function must be a 'css' function result: " + o + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
2937
+ })(i) + n[r + 1], n[0]);
2938
+ return new ps(e, n, de);
2939
+ }, qn = (n, t) => {
2940
+ le ? n.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet) : t.forEach((e) => {
2941
+ const s = document.createElement("style"), i = dt.litNonce;
2942
+ i !== void 0 && s.setAttribute("nonce", i), s.textContent = e.cssText, n.appendChild(s);
2943
+ });
2944
+ }, je = le ? (n) => n : (n) => n instanceof CSSStyleSheet ? ((t) => {
2945
+ let e = "";
2946
+ for (const s of t.cssRules)
2947
+ e += s.cssText;
2948
+ return Wn(e);
2949
+ })(n) : n;
2950
+ /**
2951
+ * @license
2952
+ * Copyright 2017 Google LLC
2953
+ * SPDX-License-Identifier: BSD-3-Clause
2954
+ */
2955
+ var Ht;
2956
+ const vt = window, Le = vt.trustedTypes, Vn = Le ? Le.emptyScript : "", Re = vt.reactiveElementPolyfillSupport, Qt = { toAttribute(n, t) {
2957
+ switch (t) {
2958
+ case Boolean:
2959
+ n = n ? Vn : null;
2960
+ break;
2961
+ case Object:
2962
+ case Array:
2963
+ n = n == null ? n : JSON.stringify(n);
2964
+ }
2965
+ return n;
2966
+ }, fromAttribute(n, t) {
2967
+ let e = n;
2968
+ switch (t) {
2969
+ case Boolean:
2970
+ e = n !== null;
2971
+ break;
2972
+ case Number:
2973
+ e = n === null ? null : Number(n);
2974
+ break;
2975
+ case Object:
2976
+ case Array:
2977
+ try {
2978
+ e = JSON.parse(n);
2979
+ } catch {
2980
+ e = null;
2981
+ }
2982
+ }
2983
+ return e;
2984
+ } }, gs = (n, t) => t !== n && (t == t || n == n), jt = { attribute: !0, type: String, converter: Qt, reflect: !1, hasChanged: gs }, Yt = "finalized";
2985
+ let R = class extends HTMLElement {
2986
+ constructor() {
2987
+ super(), this._$Ei = /* @__PURE__ */ new Map(), this.isUpdatePending = !1, this.hasUpdated = !1, this._$El = null, this._$Eu();
2988
+ }
2989
+ static addInitializer(t) {
2990
+ var e;
2991
+ this.finalize(), ((e = this.h) !== null && e !== void 0 ? e : this.h = []).push(t);
2992
+ }
2993
+ static get observedAttributes() {
2994
+ this.finalize();
2995
+ const t = [];
2996
+ return this.elementProperties.forEach((e, s) => {
2997
+ const i = this._$Ep(s, e);
2998
+ i !== void 0 && (this._$Ev.set(i, s), t.push(i));
2999
+ }), t;
3000
+ }
3001
+ static createProperty(t, e = jt) {
3002
+ if (e.state && (e.attribute = !1), this.finalize(), this.elementProperties.set(t, e), !e.noAccessor && !this.prototype.hasOwnProperty(t)) {
3003
+ const s = typeof t == "symbol" ? Symbol() : "__" + t, i = this.getPropertyDescriptor(t, s, e);
3004
+ i !== void 0 && Object.defineProperty(this.prototype, t, i);
3005
+ }
3006
+ }
3007
+ static getPropertyDescriptor(t, e, s) {
3008
+ return { get() {
3009
+ return this[e];
3010
+ }, set(i) {
3011
+ const r = this[t];
3012
+ this[e] = i, this.requestUpdate(t, r, s);
3013
+ }, configurable: !0, enumerable: !0 };
3014
+ }
3015
+ static getPropertyOptions(t) {
3016
+ return this.elementProperties.get(t) || jt;
3017
+ }
3018
+ static finalize() {
3019
+ if (this.hasOwnProperty(Yt))
3020
+ return !1;
3021
+ this[Yt] = !0;
3022
+ const t = Object.getPrototypeOf(this);
3023
+ if (t.finalize(), t.h !== void 0 && (this.h = [...t.h]), this.elementProperties = new Map(t.elementProperties), this._$Ev = /* @__PURE__ */ new Map(), this.hasOwnProperty("properties")) {
3024
+ const e = this.properties, s = [...Object.getOwnPropertyNames(e), ...Object.getOwnPropertySymbols(e)];
3025
+ for (const i of s)
3026
+ this.createProperty(i, e[i]);
3027
+ }
3028
+ return this.elementStyles = this.finalizeStyles(this.styles), !0;
3029
+ }
3030
+ static finalizeStyles(t) {
3031
+ const e = [];
3032
+ if (Array.isArray(t)) {
3033
+ const s = new Set(t.flat(1 / 0).reverse());
3034
+ for (const i of s)
3035
+ e.unshift(je(i));
3036
+ } else
3037
+ t !== void 0 && e.push(je(t));
3038
+ return e;
3039
+ }
3040
+ static _$Ep(t, e) {
3041
+ const s = e.attribute;
3042
+ return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
3043
+ }
3044
+ _$Eu() {
3045
+ var t;
3046
+ this._$E_ = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$Eg(), this.requestUpdate(), (t = this.constructor.h) === null || t === void 0 || t.forEach((e) => e(this));
3047
+ }
3048
+ addController(t) {
3049
+ var e, s;
3050
+ ((e = this._$ES) !== null && e !== void 0 ? e : this._$ES = []).push(t), this.renderRoot !== void 0 && this.isConnected && ((s = t.hostConnected) === null || s === void 0 || s.call(t));
3051
+ }
3052
+ removeController(t) {
3053
+ var e;
3054
+ (e = this._$ES) === null || e === void 0 || e.splice(this._$ES.indexOf(t) >>> 0, 1);
3055
+ }
3056
+ _$Eg() {
3057
+ this.constructor.elementProperties.forEach((t, e) => {
3058
+ this.hasOwnProperty(e) && (this._$Ei.set(e, this[e]), delete this[e]);
3059
+ });
3060
+ }
3061
+ createRenderRoot() {
3062
+ var t;
3063
+ const e = (t = this.shadowRoot) !== null && t !== void 0 ? t : this.attachShadow(this.constructor.shadowRootOptions);
3064
+ return qn(e, this.constructor.elementStyles), e;
3065
+ }
3066
+ connectedCallback() {
3067
+ var t;
3068
+ this.renderRoot === void 0 && (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$ES) === null || t === void 0 || t.forEach((e) => {
3069
+ var s;
3070
+ return (s = e.hostConnected) === null || s === void 0 ? void 0 : s.call(e);
3071
+ });
3072
+ }
3073
+ enableUpdating(t) {
3074
+ }
3075
+ disconnectedCallback() {
3076
+ var t;
3077
+ (t = this._$ES) === null || t === void 0 || t.forEach((e) => {
3078
+ var s;
3079
+ return (s = e.hostDisconnected) === null || s === void 0 ? void 0 : s.call(e);
3080
+ });
3081
+ }
3082
+ attributeChangedCallback(t, e, s) {
3083
+ this._$AK(t, s);
3084
+ }
3085
+ _$EO(t, e, s = jt) {
3086
+ var i;
3087
+ const r = this.constructor._$Ep(t, s);
3088
+ if (r !== void 0 && s.reflect === !0) {
3089
+ const o = (((i = s.converter) === null || i === void 0 ? void 0 : i.toAttribute) !== void 0 ? s.converter : Qt).toAttribute(e, s.type);
3090
+ this._$El = t, o == null ? this.removeAttribute(r) : this.setAttribute(r, o), this._$El = null;
3091
+ }
3092
+ }
3093
+ _$AK(t, e) {
3094
+ var s;
3095
+ const i = this.constructor, r = i._$Ev.get(t);
3096
+ if (r !== void 0 && this._$El !== r) {
3097
+ const o = i.getPropertyOptions(r), a = typeof o.converter == "function" ? { fromAttribute: o.converter } : ((s = o.converter) === null || s === void 0 ? void 0 : s.fromAttribute) !== void 0 ? o.converter : Qt;
3098
+ this._$El = r, this[r] = a.fromAttribute(e, o.type), this._$El = null;
3099
+ }
3100
+ }
3101
+ requestUpdate(t, e, s) {
3102
+ let i = !0;
3103
+ t !== void 0 && (((s = s || this.constructor.getPropertyOptions(t)).hasChanged || gs)(this[t], e) ? (this._$AL.has(t) || this._$AL.set(t, e), s.reflect === !0 && this._$El !== t && (this._$EC === void 0 && (this._$EC = /* @__PURE__ */ new Map()), this._$EC.set(t, s))) : i = !1), !this.isUpdatePending && i && (this._$E_ = this._$Ej());
3104
+ }
3105
+ async _$Ej() {
3106
+ this.isUpdatePending = !0;
3107
+ try {
3108
+ await this._$E_;
3109
+ } catch (e) {
3110
+ Promise.reject(e);
3111
+ }
3112
+ const t = this.scheduleUpdate();
3113
+ return t != null && await t, !this.isUpdatePending;
3114
+ }
3115
+ scheduleUpdate() {
3116
+ return this.performUpdate();
3117
+ }
3118
+ performUpdate() {
3119
+ var t;
3120
+ if (!this.isUpdatePending)
3121
+ return;
3122
+ this.hasUpdated, this._$Ei && (this._$Ei.forEach((i, r) => this[r] = i), this._$Ei = void 0);
3123
+ let e = !1;
3124
+ const s = this._$AL;
3125
+ try {
3126
+ e = this.shouldUpdate(s), e ? (this.willUpdate(s), (t = this._$ES) === null || t === void 0 || t.forEach((i) => {
3127
+ var r;
3128
+ return (r = i.hostUpdate) === null || r === void 0 ? void 0 : r.call(i);
3129
+ }), this.update(s)) : this._$Ek();
3130
+ } catch (i) {
3131
+ throw e = !1, this._$Ek(), i;
3132
+ }
3133
+ e && this._$AE(s);
3134
+ }
3135
+ willUpdate(t) {
3136
+ }
3137
+ _$AE(t) {
3138
+ var e;
3139
+ (e = this._$ES) === null || e === void 0 || e.forEach((s) => {
3140
+ var i;
3141
+ return (i = s.hostUpdated) === null || i === void 0 ? void 0 : i.call(s);
3142
+ }), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
3143
+ }
3144
+ _$Ek() {
3145
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
3146
+ }
3147
+ get updateComplete() {
3148
+ return this.getUpdateComplete();
3149
+ }
3150
+ getUpdateComplete() {
3151
+ return this._$E_;
3152
+ }
3153
+ shouldUpdate(t) {
3154
+ return !0;
3155
+ }
3156
+ update(t) {
3157
+ this._$EC !== void 0 && (this._$EC.forEach((e, s) => this._$EO(s, this[s], e)), this._$EC = void 0), this._$Ek();
3158
+ }
3159
+ updated(t) {
3160
+ }
3161
+ firstUpdated(t) {
3162
+ }
3163
+ };
3164
+ R[Yt] = !0, R.elementProperties = /* @__PURE__ */ new Map(), R.elementStyles = [], R.shadowRootOptions = { mode: "open" }, Re == null || Re({ ReactiveElement: R }), ((Ht = vt.reactiveElementVersions) !== null && Ht !== void 0 ? Ht : vt.reactiveElementVersions = []).push("1.6.3");
3165
+ /**
3166
+ * @license
3167
+ * Copyright 2017 Google LLC
3168
+ * SPDX-License-Identifier: BSD-3-Clause
3169
+ */
3170
+ var Lt;
3171
+ const ft = window, q = ft.trustedTypes, ze = q ? q.createPolicy("lit-html", { createHTML: (n) => n }) : void 0, Zt = "$lit$", N = `lit$${(Math.random() + "").slice(9)}$`, ms = "?" + N, Jn = `<${ms}>`, H = document, tt = () => H.createComment(""), et = (n) => n === null || typeof n != "object" && typeof n != "function", vs = Array.isArray, Fn = (n) => vs(n) || typeof (n == null ? void 0 : n[Symbol.iterator]) == "function", Rt = `[
3172
+ \f\r]`, Q = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, We = /-->/g, Be = />/g, I = RegExp(`>|${Rt}(?:([^\\s"'>=/]+)(${Rt}*=${Rt}*(?:[^
3173
+ \f\r"'\`<>=]|("|')|))|$)`, "g"), qe = /'/g, Ve = /"/g, fs = /^(?:script|style|textarea|title)$/i, Kn = (n) => (t, ...e) => ({ _$litType$: n, strings: t, values: e }), lt = Kn(1), j = Symbol.for("lit-noChange"), m = Symbol.for("lit-nothing"), Je = /* @__PURE__ */ new WeakMap(), U = H.createTreeWalker(H, 129, null, !1);
3174
+ function ys(n, t) {
3175
+ if (!Array.isArray(n) || !n.hasOwnProperty("raw"))
3176
+ throw Error("invalid template strings array");
3177
+ return ze !== void 0 ? ze.createHTML(t) : t;
3178
+ }
3179
+ const Qn = (n, t) => {
3180
+ const e = n.length - 1, s = [];
3181
+ let i, r = t === 2 ? "<svg>" : "", o = Q;
3182
+ for (let a = 0; a < e; a++) {
3183
+ const c = n[a];
3184
+ let h, l, d = -1, u = 0;
3185
+ for (; u < c.length && (o.lastIndex = u, l = o.exec(c), l !== null); )
3186
+ u = o.lastIndex, o === Q ? l[1] === "!--" ? o = We : l[1] !== void 0 ? o = Be : l[2] !== void 0 ? (fs.test(l[2]) && (i = RegExp("</" + l[2], "g")), o = I) : l[3] !== void 0 && (o = I) : o === I ? l[0] === ">" ? (o = i ?? Q, d = -1) : l[1] === void 0 ? d = -2 : (d = o.lastIndex - l[2].length, h = l[1], o = l[3] === void 0 ? I : l[3] === '"' ? Ve : qe) : o === Ve || o === qe ? o = I : o === We || o === Be ? o = Q : (o = I, i = void 0);
3187
+ const p = o === I && n[a + 1].startsWith("/>") ? " " : "";
3188
+ r += o === Q ? c + Jn : d >= 0 ? (s.push(h), c.slice(0, d) + Zt + c.slice(d) + N + p) : c + N + (d === -2 ? (s.push(void 0), a) : p);
3189
+ }
3190
+ return [ys(n, r + (n[e] || "<?>") + (t === 2 ? "</svg>" : "")), s];
3191
+ };
3192
+ class st {
3193
+ constructor({ strings: t, _$litType$: e }, s) {
3194
+ let i;
3195
+ this.parts = [];
3196
+ let r = 0, o = 0;
3197
+ const a = t.length - 1, c = this.parts, [h, l] = Qn(t, e);
3198
+ if (this.el = st.createElement(h, s), U.currentNode = this.el.content, e === 2) {
3199
+ const d = this.el.content, u = d.firstChild;
3200
+ u.remove(), d.append(...u.childNodes);
3201
+ }
3202
+ for (; (i = U.nextNode()) !== null && c.length < a; ) {
3203
+ if (i.nodeType === 1) {
3204
+ if (i.hasAttributes()) {
3205
+ const d = [];
3206
+ for (const u of i.getAttributeNames())
3207
+ if (u.endsWith(Zt) || u.startsWith(N)) {
3208
+ const p = l[o++];
3209
+ if (d.push(u), p !== void 0) {
3210
+ const b = i.getAttribute(p.toLowerCase() + Zt).split(N), w = /([.?@])?(.*)/.exec(p);
3211
+ c.push({ type: 1, index: r, name: w[2], strings: b, ctor: w[1] === "." ? Zn : w[1] === "?" ? Xn : w[1] === "@" ? ti : Et });
3212
+ } else
3213
+ c.push({ type: 6, index: r });
3214
+ }
3215
+ for (const u of d)
3216
+ i.removeAttribute(u);
3217
+ }
3218
+ if (fs.test(i.tagName)) {
3219
+ const d = i.textContent.split(N), u = d.length - 1;
3220
+ if (u > 0) {
3221
+ i.textContent = q ? q.emptyScript : "";
3222
+ for (let p = 0; p < u; p++)
3223
+ i.append(d[p], tt()), U.nextNode(), c.push({ type: 2, index: ++r });
3224
+ i.append(d[u], tt());
3225
+ }
3226
+ }
3227
+ } else if (i.nodeType === 8)
3228
+ if (i.data === ms)
3229
+ c.push({ type: 2, index: r });
3230
+ else {
3231
+ let d = -1;
3232
+ for (; (d = i.data.indexOf(N, d + 1)) !== -1; )
3233
+ c.push({ type: 7, index: r }), d += N.length - 1;
3234
+ }
3235
+ r++;
3236
+ }
3237
+ }
3238
+ static createElement(t, e) {
3239
+ const s = H.createElement("template");
3240
+ return s.innerHTML = t, s;
3241
+ }
3242
+ }
3243
+ function V(n, t, e = n, s) {
3244
+ var i, r, o, a;
3245
+ if (t === j)
3246
+ return t;
3247
+ let c = s !== void 0 ? (i = e._$Co) === null || i === void 0 ? void 0 : i[s] : e._$Cl;
3248
+ const h = et(t) ? void 0 : t._$litDirective$;
3249
+ return (c == null ? void 0 : c.constructor) !== h && ((r = c == null ? void 0 : c._$AO) === null || r === void 0 || r.call(c, !1), h === void 0 ? c = void 0 : (c = new h(n), c._$AT(n, e, s)), s !== void 0 ? ((o = (a = e)._$Co) !== null && o !== void 0 ? o : a._$Co = [])[s] = c : e._$Cl = c), c !== void 0 && (t = V(n, c._$AS(n, t.values), c, s)), t;
3250
+ }
3251
+ class Yn {
3252
+ constructor(t, e) {
3253
+ this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e;
3254
+ }
3255
+ get parentNode() {
3256
+ return this._$AM.parentNode;
3257
+ }
3258
+ get _$AU() {
3259
+ return this._$AM._$AU;
3260
+ }
3261
+ u(t) {
3262
+ var e;
3263
+ const { el: { content: s }, parts: i } = this._$AD, r = ((e = t == null ? void 0 : t.creationScope) !== null && e !== void 0 ? e : H).importNode(s, !0);
3264
+ U.currentNode = r;
3265
+ let o = U.nextNode(), a = 0, c = 0, h = i[0];
3266
+ for (; h !== void 0; ) {
3267
+ if (a === h.index) {
3268
+ let l;
3269
+ h.type === 2 ? l = new it(o, o.nextSibling, this, t) : h.type === 1 ? l = new h.ctor(o, h.name, h.strings, this, t) : h.type === 6 && (l = new ei(o, this, t)), this._$AV.push(l), h = i[++c];
3270
+ }
3271
+ a !== (h == null ? void 0 : h.index) && (o = U.nextNode(), a++);
3272
+ }
3273
+ return U.currentNode = H, r;
3274
+ }
3275
+ v(t) {
3276
+ let e = 0;
3277
+ for (const s of this._$AV)
3278
+ s !== void 0 && (s.strings !== void 0 ? (s._$AI(t, s, e), e += s.strings.length - 2) : s._$AI(t[e])), e++;
3279
+ }
3280
+ }
3281
+ class it {
3282
+ constructor(t, e, s, i) {
3283
+ var r;
3284
+ this.type = 2, this._$AH = m, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = s, this.options = i, this._$Cp = (r = i == null ? void 0 : i.isConnected) === null || r === void 0 || r;
3285
+ }
3286
+ get _$AU() {
3287
+ var t, e;
3288
+ return (e = (t = this._$AM) === null || t === void 0 ? void 0 : t._$AU) !== null && e !== void 0 ? e : this._$Cp;
3289
+ }
3290
+ get parentNode() {
3291
+ let t = this._$AA.parentNode;
3292
+ const e = this._$AM;
3293
+ return e !== void 0 && (t == null ? void 0 : t.nodeType) === 11 && (t = e.parentNode), t;
3294
+ }
3295
+ get startNode() {
3296
+ return this._$AA;
3297
+ }
3298
+ get endNode() {
3299
+ return this._$AB;
3300
+ }
3301
+ _$AI(t, e = this) {
3302
+ t = V(this, t, e), et(t) ? t === m || t == null || t === "" ? (this._$AH !== m && this._$AR(), this._$AH = m) : t !== this._$AH && t !== j && this._(t) : t._$litType$ !== void 0 ? this.g(t) : t.nodeType !== void 0 ? this.$(t) : Fn(t) ? this.T(t) : this._(t);
3303
+ }
3304
+ k(t) {
3305
+ return this._$AA.parentNode.insertBefore(t, this._$AB);
3306
+ }
3307
+ $(t) {
3308
+ this._$AH !== t && (this._$AR(), this._$AH = this.k(t));
3309
+ }
3310
+ _(t) {
3311
+ this._$AH !== m && et(this._$AH) ? this._$AA.nextSibling.data = t : this.$(H.createTextNode(t)), this._$AH = t;
3312
+ }
3313
+ g(t) {
3314
+ var e;
3315
+ const { values: s, _$litType$: i } = t, r = typeof i == "number" ? this._$AC(t) : (i.el === void 0 && (i.el = st.createElement(ys(i.h, i.h[0]), this.options)), i);
3316
+ if (((e = this._$AH) === null || e === void 0 ? void 0 : e._$AD) === r)
3317
+ this._$AH.v(s);
3318
+ else {
3319
+ const o = new Yn(r, this), a = o.u(this.options);
3320
+ o.v(s), this.$(a), this._$AH = o;
3321
+ }
3322
+ }
3323
+ _$AC(t) {
3324
+ let e = Je.get(t.strings);
3325
+ return e === void 0 && Je.set(t.strings, e = new st(t)), e;
3326
+ }
3327
+ T(t) {
3328
+ vs(this._$AH) || (this._$AH = [], this._$AR());
3329
+ const e = this._$AH;
3330
+ let s, i = 0;
3331
+ for (const r of t)
3332
+ i === e.length ? e.push(s = new it(this.k(tt()), this.k(tt()), this, this.options)) : s = e[i], s._$AI(r), i++;
3333
+ i < e.length && (this._$AR(s && s._$AB.nextSibling, i), e.length = i);
3334
+ }
3335
+ _$AR(t = this._$AA.nextSibling, e) {
3336
+ var s;
3337
+ for ((s = this._$AP) === null || s === void 0 || s.call(this, !1, !0, e); t && t !== this._$AB; ) {
3338
+ const i = t.nextSibling;
3339
+ t.remove(), t = i;
3340
+ }
3341
+ }
3342
+ setConnected(t) {
3343
+ var e;
3344
+ this._$AM === void 0 && (this._$Cp = t, (e = this._$AP) === null || e === void 0 || e.call(this, t));
3345
+ }
3346
+ }
3347
+ class Et {
3348
+ constructor(t, e, s, i, r) {
3349
+ this.type = 1, this._$AH = m, this._$AN = void 0, this.element = t, this.name = e, this._$AM = i, this.options = r, s.length > 2 || s[0] !== "" || s[1] !== "" ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = m;
3350
+ }
3351
+ get tagName() {
3352
+ return this.element.tagName;
3353
+ }
3354
+ get _$AU() {
3355
+ return this._$AM._$AU;
3356
+ }
3357
+ _$AI(t, e = this, s, i) {
3358
+ const r = this.strings;
3359
+ let o = !1;
3360
+ if (r === void 0)
3361
+ t = V(this, t, e, 0), o = !et(t) || t !== this._$AH && t !== j, o && (this._$AH = t);
3362
+ else {
3363
+ const a = t;
3364
+ let c, h;
3365
+ for (t = r[0], c = 0; c < r.length - 1; c++)
3366
+ h = V(this, a[s + c], e, c), h === j && (h = this._$AH[c]), o || (o = !et(h) || h !== this._$AH[c]), h === m ? t = m : t !== m && (t += (h ?? "") + r[c + 1]), this._$AH[c] = h;
3367
+ }
3368
+ o && !i && this.j(t);
3369
+ }
3370
+ j(t) {
3371
+ t === m ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
3372
+ }
3373
+ }
3374
+ class Zn extends Et {
3375
+ constructor() {
3376
+ super(...arguments), this.type = 3;
3377
+ }
3378
+ j(t) {
3379
+ this.element[this.name] = t === m ? void 0 : t;
3380
+ }
3381
+ }
3382
+ const Gn = q ? q.emptyScript : "";
3383
+ class Xn extends Et {
3384
+ constructor() {
3385
+ super(...arguments), this.type = 4;
3386
+ }
3387
+ j(t) {
3388
+ t && t !== m ? this.element.setAttribute(this.name, Gn) : this.element.removeAttribute(this.name);
3389
+ }
3390
+ }
3391
+ class ti extends Et {
3392
+ constructor(t, e, s, i, r) {
3393
+ super(t, e, s, i, r), this.type = 5;
3394
+ }
3395
+ _$AI(t, e = this) {
3396
+ var s;
3397
+ if ((t = (s = V(this, t, e, 0)) !== null && s !== void 0 ? s : m) === j)
3398
+ return;
3399
+ const i = this._$AH, r = t === m && i !== m || t.capture !== i.capture || t.once !== i.once || t.passive !== i.passive, o = t !== m && (i === m || r);
3400
+ r && this.element.removeEventListener(this.name, this, i), o && this.element.addEventListener(this.name, this, t), this._$AH = t;
3401
+ }
3402
+ handleEvent(t) {
3403
+ var e, s;
3404
+ typeof this._$AH == "function" ? this._$AH.call((s = (e = this.options) === null || e === void 0 ? void 0 : e.host) !== null && s !== void 0 ? s : this.element, t) : this._$AH.handleEvent(t);
3405
+ }
3406
+ }
3407
+ class ei {
3408
+ constructor(t, e, s) {
3409
+ this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = s;
3410
+ }
3411
+ get _$AU() {
3412
+ return this._$AM._$AU;
3413
+ }
3414
+ _$AI(t) {
3415
+ V(this, t);
3416
+ }
3417
+ }
3418
+ const Fe = ft.litHtmlPolyfillSupport;
3419
+ Fe == null || Fe(st, it), ((Lt = ft.litHtmlVersions) !== null && Lt !== void 0 ? Lt : ft.litHtmlVersions = []).push("2.8.0");
3420
+ const si = (n, t, e) => {
3421
+ var s, i;
3422
+ const r = (s = e == null ? void 0 : e.renderBefore) !== null && s !== void 0 ? s : t;
3423
+ let o = r._$litPart$;
3424
+ if (o === void 0) {
3425
+ const a = (i = e == null ? void 0 : e.renderBefore) !== null && i !== void 0 ? i : null;
3426
+ r._$litPart$ = o = new it(t.insertBefore(tt(), a), a, void 0, e ?? {});
3427
+ }
3428
+ return o._$AI(n), o;
3429
+ };
3430
+ /**
3431
+ * @license
3432
+ * Copyright 2017 Google LLC
3433
+ * SPDX-License-Identifier: BSD-3-Clause
3434
+ */
3435
+ var zt, Wt;
3436
+ class Z extends R {
3437
+ constructor() {
3438
+ super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
3439
+ }
3440
+ createRenderRoot() {
3441
+ var t, e;
3442
+ const s = super.createRenderRoot();
3443
+ return (t = (e = this.renderOptions).renderBefore) !== null && t !== void 0 || (e.renderBefore = s.firstChild), s;
3444
+ }
3445
+ update(t) {
3446
+ const e = this.render();
3447
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = si(e, this.renderRoot, this.renderOptions);
3448
+ }
3449
+ connectedCallback() {
3450
+ var t;
3451
+ super.connectedCallback(), (t = this._$Do) === null || t === void 0 || t.setConnected(!0);
3452
+ }
3453
+ disconnectedCallback() {
3454
+ var t;
3455
+ super.disconnectedCallback(), (t = this._$Do) === null || t === void 0 || t.setConnected(!1);
3456
+ }
3457
+ render() {
3458
+ return j;
3459
+ }
3460
+ }
3461
+ Z.finalized = !0, Z._$litElement$ = !0, (zt = globalThis.litElementHydrateSupport) === null || zt === void 0 || zt.call(globalThis, { LitElement: Z });
3462
+ const Ke = globalThis.litElementPolyfillSupport;
3463
+ Ke == null || Ke({ LitElement: Z });
3464
+ ((Wt = globalThis.litElementVersions) !== null && Wt !== void 0 ? Wt : globalThis.litElementVersions = []).push("3.3.3");
3465
+ /**
3466
+ * @license
3467
+ * Copyright 2017 Google LLC
3468
+ * SPDX-License-Identifier: BSD-3-Clause
3469
+ */
3470
+ const ni = (n, t) => t.kind === "method" && t.descriptor && !("value" in t.descriptor) ? { ...t, finisher(e) {
3471
+ e.createProperty(t.key, n);
3472
+ } } : { kind: "field", key: Symbol(), placement: "own", descriptor: {}, originalKey: t.key, initializer() {
3473
+ typeof t.initializer == "function" && (this[t.key] = t.initializer.call(this));
3474
+ }, finisher(e) {
3475
+ e.createProperty(t.key, n);
3476
+ } }, ii = (n, t, e) => {
3477
+ t.constructor.createProperty(e, n);
3478
+ };
3479
+ function ue(n) {
3480
+ return (t, e) => e !== void 0 ? ii(n, t, e) : ni(n, t);
3481
+ }
3482
+ /**
3483
+ * @license
3484
+ * Copyright 2017 Google LLC
3485
+ * SPDX-License-Identifier: BSD-3-Clause
3486
+ */
3487
+ function pe(n) {
3488
+ return ue({ ...n, state: !0 });
3489
+ }
3490
+ /**
3491
+ * @license
3492
+ * Copyright 2021 Google LLC
3493
+ * SPDX-License-Identifier: BSD-3-Clause
3494
+ */
3495
+ var Bt;
3496
+ ((Bt = window.HTMLSlotElement) === null || Bt === void 0 ? void 0 : Bt.prototype.assignedElements) != null;
3497
+ /**
3498
+ * @license
3499
+ * Copyright 2017 Google LLC
3500
+ * SPDX-License-Identifier: BSD-3-Clause
3501
+ */
3502
+ const ri = { ATTRIBUTE: 1, CHILD: 2, PROPERTY: 3, BOOLEAN_ATTRIBUTE: 4, EVENT: 5, ELEMENT: 6 }, oi = (n) => (...t) => ({ _$litDirective$: n, values: t });
3503
+ class ai {
3504
+ constructor(t) {
3505
+ }
3506
+ get _$AU() {
3507
+ return this._$AM._$AU;
3508
+ }
3509
+ _$AT(t, e, s) {
3510
+ this._$Ct = t, this._$AM = e, this._$Ci = s;
3511
+ }
3512
+ _$AS(t, e) {
3513
+ return this.update(t, e);
3514
+ }
3515
+ update(t, e) {
3516
+ return this.render(...e);
3517
+ }
3518
+ }
3519
+ /**
3520
+ * @license
3521
+ * Copyright 2018 Google LLC
3522
+ * SPDX-License-Identifier: BSD-3-Clause
3523
+ */
3524
+ const ci = oi(class extends ai {
3525
+ constructor(n) {
3526
+ var t;
3527
+ if (super(n), n.type !== ri.ATTRIBUTE || n.name !== "class" || ((t = n.strings) === null || t === void 0 ? void 0 : t.length) > 2)
3528
+ throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.");
3529
+ }
3530
+ render(n) {
3531
+ return " " + Object.keys(n).filter((t) => n[t]).join(" ") + " ";
3532
+ }
3533
+ update(n, [t]) {
3534
+ var e, s;
3535
+ if (this.it === void 0) {
3536
+ this.it = /* @__PURE__ */ new Set(), n.strings !== void 0 && (this.nt = new Set(n.strings.join(" ").split(/\s/).filter((r) => r !== "")));
3537
+ for (const r in t)
3538
+ t[r] && !(!((e = this.nt) === null || e === void 0) && e.has(r)) && this.it.add(r);
3539
+ return this.render(t);
3540
+ }
3541
+ const i = n.element.classList;
3542
+ this.it.forEach((r) => {
3543
+ r in t || (i.remove(r), this.it.delete(r));
3544
+ });
3545
+ for (const r in t) {
3546
+ const o = !!t[r];
3547
+ o === this.it.has(r) || !((s = this.nt) === null || s === void 0) && s.has(r) || (o ? (i.add(r), this.it.add(r)) : (i.remove(r), this.it.delete(r)));
3548
+ }
3549
+ return j;
3550
+ }
3551
+ }), v = (n, t, e) => {
3552
+ n && e.style.setProperty(t, n);
3553
+ }, hi = (n, t) => {
3554
+ var e, s, i, r, o, a, c, h, l, d, u;
3555
+ v((e = n.colors) == null ? void 0 : e.primary, "--primary-color", t), v((s = n.colors) == null ? void 0 : s.secondary, "--secondary-color", t), v((i = n.colors) == null ? void 0 : i.text, "--text-color", t), v((r = n.colors) == null ? void 0 : r.link, "--link-color", t), v((o = n.colors) == null ? void 0 : o.gray, "--gray-color", t), v((a = n.colors) == null ? void 0 : a.grayDark, "--gray-dark-color", t), v((c = n.spacing) == null ? void 0 : c.xs, "--spacing-xs", t), v((h = n.spacing) == null ? void 0 : h.sm, "--spacing-sm", t), v((l = n.spacing) == null ? void 0 : l.md, "--spacing-md", t), v((d = n.spacing) == null ? void 0 : d.lg, "--spacing-lg", t), v((u = n.spacing) == null ? void 0 : u.xl, "--spacing-xl", t), v(n.boxShadow, "--box-shadow", t), v(n.borderRadius, "--border-radius", t), v(n.borderRadiusSm, "--border-radius-sm", t), v(n.fontFamily, "--font-family", t);
3556
+ };
3557
+ var li = Object.defineProperty, di = Object.getOwnPropertyDescriptor, rt = (n, t, e, s) => {
3558
+ for (var i = s > 1 ? void 0 : s ? di(t, e) : t, r = n.length - 1, o; r >= 0; r--)
3559
+ (o = n[r]) && (i = (s ? o(t, e, i) : o(i)) || i);
3560
+ return s && i && li(t, e, i), i;
3561
+ };
3562
+ class F extends Z {
3563
+ constructor() {
3564
+ super(...arguments), this.active = !1, this.loaded = !1;
3565
+ }
3566
+ async connectedCallback() {
3567
+ super.connectedCallback(), this.icon = await this._renderSymbol(this.symbol), this.loaded = !0, this._applyBranding();
3568
+ }
3569
+ _toggleActive() {
3570
+ this.active = !this.active;
3571
+ }
3572
+ _applyBranding() {
3573
+ var s;
3574
+ const t = ((s = this.container) == null ? void 0 : s.get("$settings")) ?? {}, e = t == null ? void 0 : t.components[t == null ? void 0 : t.entry];
3575
+ e && hi(e.context, this);
3576
+ }
3577
+ async _renderSymbol(t) {
3578
+ const e = async (s) => await import("./index-5087564d.mjs").then(
3579
+ (r) => r[s]
3580
+ );
3581
+ if (t) {
3582
+ const { type: s, content: i } = t;
3583
+ switch (s) {
3584
+ case "Telia": {
3585
+ const r = await e(i);
3586
+ return r ? lt`<telia-icon
3587
+ class="trigger-icon"
3588
+ svg=${r.svg}
3589
+ size="lg"
3590
+ ></telia-icon>` : m;
3591
+ }
3592
+ case "FontAwesome":
3593
+ return lt`<i class="trigger-fa-icon fa fa-${i}"></i>`;
3594
+ case "Uri":
3595
+ return lt`<i
3596
+ class="trigger-custom-icon"
3597
+ style="background: url(${i}) no-repeat center center;background-size: contain;"
3598
+ ></i>`;
3599
+ default:
3600
+ return m;
3601
+ }
3602
+ }
3603
+ }
3604
+ render() {
3605
+ return lt`<button
3606
+ class=${ci({
3607
+ trigger: !0,
3608
+ active: this.active,
3609
+ rendered: this.loaded
3610
+ })}
3611
+ @click=${this._toggleActive}
3612
+ >
3613
+ ${this.icon}
3614
+ <span class="trigger-close">
3615
+ <svg
3616
+ width="18"
3617
+ height="9"
3618
+ viewBox="0 0 18 9"
3619
+ fill="none"
3620
+ xmlns="http://www.w3.org/2000/svg"
3621
+ >
3622
+ <path
3623
+ d="M9 9C8.81794 9.00045 8.63759 8.96634 8.46939 8.89965C8.3012 8.83295 8.14851 8.735 8.02015 8.61145L0.194523 1.12367C0.068294 0.99862 -0.00155266 0.831133 2.61958e-05 0.657285C0.00160506 0.483436 0.0744832 0.317136 0.202964 0.194202C0.331445 0.0712675 0.505249 0.00153576 0.686941 2.50649e-05C0.868634 -0.00148563 1.04368 0.0653456 1.17437 0.186125L9 7.6739L16.8256 0.186125C16.9563 0.0653456 17.1314 -0.00148563 17.3131 2.50649e-05C17.4948 0.00153576 17.6686 0.0712675 17.797 0.194202C17.9255 0.317136 17.9984 0.483436 18 0.657285C18.0016 0.831133 17.9317 0.99862 17.8055 1.12367L9.97985 8.61145C9.85149 8.735 9.6988 8.83295 9.53061 8.89965C9.36241 8.96634 9.18206 9.00045 9 9Z"
3624
+ fill="white"
3625
+ />
3626
+ </svg>
3627
+ </span>
3628
+ <span class="trigger-loader">
3629
+ <svg viewBox="25 25 50 50">
3630
+ <circle
3631
+ cx="50"
3632
+ cy="50"
3633
+ r="20"
3634
+ fill="none"
3635
+ stroke="#000"
3636
+ stroke-width="2"
3637
+ stroke-miterlimit="10"
3638
+ />
3639
+ </svg>
3640
+ </span>
3641
+ </button>`;
3642
+ }
3643
+ }
3644
+ F.styles = [
3645
+ Bn`
3646
+ :host {
3647
+ --voca-rem-multiplier: 0.625;
3648
+ display: block;
3649
+ box-sizing: border-box;
3650
+ }
3651
+
3652
+ .trigger {
3653
+ position: fixed;
3654
+ transform: scale(0);
3655
+ box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
3656
+ bottom: 20px;
3657
+ right: 20px;
3658
+ z-index: 5;
3659
+ display: flex;
3660
+ align-items: center;
3661
+ justify-content: center;
3662
+ border: none;
3663
+ line-height: 55px;
3664
+ height: 55px;
3665
+ width: 55px;
3666
+ border-radius: 55px;
3667
+ cursor: pointer;
3668
+ background-color: var(--trigger-bg, var(--primary-color));
3669
+ font-family: Lato;
3670
+ text-decoration: none;
3671
+ border: 3px dashed transparent;
3672
+ box-sizing: border-box;
3673
+ transition: transform 200ms ease-out;
3674
+ }
3675
+ .trigger:hover {
3676
+ transform: scale(1.1) !important;
3677
+ }
3678
+ .trigger.rendered {
3679
+ transform: scale(1);
3680
+ }
3681
+ .trigger.active .trigger-icon {
3682
+ opacity: 0;
3683
+ transform: rotate(-180deg) scale(0);
3684
+ }
3685
+ .trigger.active .trigger-close {
3686
+ opacity: 1;
3687
+ transform: rotate(0deg) scale(1);
3688
+ }
3689
+
3690
+ .trigger-icon {
3691
+ display: inline-block;
3692
+ line-height: inherit;
3693
+ text-align: center;
3694
+ opacity: 1;
3695
+ transform: rotate(0deg) scale(1);
3696
+ transition: opacity 200ms ease-out, transform 200ms ease-out;
3697
+ color: var(--trigger-text-color, #fff);
3698
+ }
3699
+ .trigger-close {
3700
+ opacity: 0;
3701
+ transition: transform 200ms ease-out;
3702
+ transform: rotate(180deg) scale(0);
3703
+ position: absolute;
3704
+ top: 0;
3705
+ bottom: 0;
3706
+ left: 0;
3707
+ right: 0;
3708
+ display: flex;
3709
+ justify-content: center;
3710
+ align-items: center;
3711
+ fill: var(--trigger-text-color, #fff);
3712
+ }
3713
+ `
3714
+ ];
3715
+ rt([
3716
+ ue({ attribute: !1 })
3717
+ ], F.prototype, "symbol", 2);
3718
+ rt([
3719
+ ue({ attribute: !1 })
3720
+ ], F.prototype, "container", 2);
3721
+ rt([
3722
+ pe()
3723
+ ], F.prototype, "active", 2);
3724
+ rt([
3725
+ pe()
3726
+ ], F.prototype, "loaded", 2);
3727
+ rt([
3728
+ pe()
3729
+ ], F.prototype, "icon", 2);
3730
+ var G = /* @__PURE__ */ ((n) => (n.LinkList = "link-list", n.Separator = "separator", n.ButtonList = "button-list", n.ItemList = "item-list", n.Text = "text", n.HTML = "html", n.VideoRequest = "video-request", n))(G || {});
3731
+ const ui = ({
3732
+ isUser: n,
3733
+ items: t = [],
3734
+ meta: e = {}
3735
+ }) => {
3736
+ const s = M();
3737
+ return {
3738
+ id: s,
3739
+ isUser: n,
3740
+ items: t.map((r) => ({
3741
+ id: r.id || M(),
3742
+ isUser: n,
3743
+ groupId: s,
3744
+ message: r.message || []
3745
+ })),
3746
+ meta: e
3747
+ };
3748
+ }, pi = (n) => {
3749
+ var t, e;
3750
+ return !!((t = n == null ? void 0 : n.outputPayload) != null && t.textOutputContent) && ((e = n == null ? void 0 : n.outputPayload) == null ? void 0 : e.isFinal);
3751
+ }, gi = (n) => {
3752
+ var t, e;
3753
+ return !!((t = n == null ? void 0 : n.outputPayload) != null && t.textOutputContent) && !((e = n == null ? void 0 : n.outputPayload) != null && e.isFinal);
3754
+ };
3755
+ class mi {
3756
+ constructor(t) {
3757
+ this.isConnected = !1, this.ws = new WebSocket(t), this.ws.onopen = (e) => {
3758
+ this.onConnected();
3759
+ }, this.ws.onmessage = (e) => {
3760
+ this.onMessage(e);
3761
+ }, this.ws.onerror = (e) => {
3762
+ this.onError(e);
3763
+ }, this.ws.onclose = (e) => {
3764
+ this.onClose(e);
3765
+ };
3766
+ }
3767
+ onConnected() {
3768
+ console.log("Connection established."), this.isConnected = !0;
3769
+ const t = {
3770
+ sequenceNumber: 1,
3771
+ initializeRequestPayload: {
3772
+ extension: "webconv2"
3773
+ }
3774
+ };
3775
+ this.sendMessage(t);
3776
+ }
3777
+ onMessage(t) {
3778
+ if (!this.messageDelegate) {
3779
+ console.warn("Not subscribed to message handler");
3780
+ return;
3781
+ }
3782
+ const e = JSON.parse(t.data);
3783
+ pi(e) ? this.messageDelegate({
3784
+ text: e.outputPayload.textOutputContent.text,
3785
+ isComplete: !0,
3786
+ sequenceNumber: e.sequenceNumber
3787
+ }) : gi(e) ? this.messageDelegate({
3788
+ text: e.outputPayload.textOutputContent.textPart,
3789
+ isComplete: !1,
3790
+ sequenceNumber: e.sequenceNumber
3791
+ }) : this.unknownMessageDelegate && this.unknownMessageDelegate(e);
3792
+ }
3793
+ onError(t) {
3794
+ console.error("Connection error:", t);
3795
+ }
3796
+ onClose(t) {
3797
+ console.log("Connection closed", t), this.isConnected = !1;
3798
+ }
3799
+ sendMessage(t) {
3800
+ if (!this.isConnected) {
3801
+ console.warn("Message could not be sent, you are not connected.");
3802
+ return;
3803
+ }
3804
+ this.ws.send(JSON.stringify(t));
3805
+ }
3806
+ subscribe(t) {
3807
+ this.messageDelegate = t;
3808
+ }
3809
+ subscribeUnknown(t) {
3810
+ this.unknownMessageDelegate = t;
3811
+ }
3812
+ }
3813
+ class vi {
3814
+ constructor() {
3815
+ this.store = /* @__PURE__ */ new Map();
3816
+ }
3817
+ get(t) {
3818
+ return this.store.get(t);
3819
+ }
3820
+ getCompleteMessage(t) {
3821
+ const e = this.get(t);
3822
+ return e != null && e.entry ? {
3823
+ message: e.messages.map((s) => s.text).join(""),
3824
+ entry: e.entry
3825
+ } : null;
3826
+ }
3827
+ put(t, e) {
3828
+ const s = this.get(t);
3829
+ let i = [];
3830
+ const r = s == null ? void 0 : s.entry;
3831
+ s && (i = s.messages), this.store.set(t, {
3832
+ entry: e.entry || r,
3833
+ messages: [...i, e.message]
3834
+ });
3835
+ }
3836
+ }
3837
+ class fi {
3838
+ constructor(t) {
3839
+ this.settings = t, this.bucket = new vi(), this.currentSequenceNumber = 1, this.onMessage = (e) => {
3840
+ if (this.handleIncomingSequenceNumber(e), this.messageSubscription) {
3841
+ const s = this.bucket.getCompleteMessage(e.sequenceNumber);
3842
+ if (console.log(s), s != null && s.entry) {
3843
+ const i = s.message + e.text;
3844
+ s.entry.update([
3845
+ [
3846
+ G.HTML,
3847
+ { body: i }
3848
+ ]
3849
+ ]), this.bucket.put(e.sequenceNumber, {
3850
+ message: e,
3851
+ entry: s.entry
3852
+ });
3853
+ } else {
3854
+ const i = this.messageSubscription(e);
3855
+ i && this.bucket.put(e.sequenceNumber, {
3856
+ message: e,
3857
+ entry: i
3858
+ });
3859
+ }
3860
+ }
3861
+ }, this.onUnknown = (e) => {
3862
+ this.handleIncomingSequenceNumber(e);
3863
+ }, this.connection = new mi(t.connectionUri), this.connection.subscribe(this.onMessage), this.connection.subscribeUnknown(this.onUnknown);
3864
+ }
3865
+ sendMessage(t) {
3866
+ this.connection.sendMessage({
3867
+ sequenceNumber: this.currentSequenceNumber,
3868
+ inputPayload: {
3869
+ textInputContent: {
3870
+ text: t.text
3871
+ }
3872
+ }
3873
+ }), this.incrementSequenceNumber();
3874
+ }
3875
+ isConnected() {
3876
+ return this.connection.isConnected;
3877
+ }
3878
+ subscribe(t) {
3879
+ this.messageSubscription = t;
3880
+ }
3881
+ handleIncomingSequenceNumber(t) {
3882
+ t.sequenceNumber > this.currentSequenceNumber && (this.currentSequenceNumber = t.sequenceNumber);
3883
+ }
3884
+ incrementSequenceNumber() {
3885
+ this.currentSequenceNumber = this.currentSequenceNumber + 1;
3886
+ }
3887
+ }
3888
+ class yi {
3889
+ constructor(t, e, s) {
3890
+ this.container = t, this.conversation = e, this.groups = [], this.convOpen = !1, this.dialog = new fi({
3891
+ connectionUri: "wss://cso-ccs.labbn.se/convhub/webconnector/v2/dialog"
3892
+ }), this.onDialogMessage = (i) => i.text && this.agent.print([
3893
+ [G.HTML, { body: i.text }]
3894
+ ]) || null, this.agent = e.createAgent({
3895
+ id: "conversational-hub-bot-agent",
3896
+ // we need to specify an ID here to allow rehydration to work
3897
+ name: "",
3898
+ avatar: void 0
3899
+ }), this.agent.print([
3900
+ [G.HTML, { body: "Hello worlds" }]
3901
+ ]), this.user = e.user, this.dialog.subscribe(this.onDialogMessage);
3902
+ }
3903
+ async onInput(t) {
3904
+ switch (typeof t == "string" ? t : t.actionKey) {
3905
+ default:
3906
+ typeof t != "string" && t.label && this.printUserMessage(t.label);
3907
+ break;
3908
+ }
3909
+ }
3910
+ printUserMessage(t) {
3911
+ const e = ui({
3912
+ isUser: !0,
3913
+ items: [
3914
+ {
3915
+ id: M(),
3916
+ isUser: !0,
3917
+ message: [G.HTML, { body: t }]
3918
+ }
3919
+ ]
3920
+ });
3921
+ return this.onMessagesReceived([e]), e;
3922
+ }
3923
+ async onMessagesReceived(t) {
3924
+ this.groups = this.groups.concat(t), t.forEach((e) => {
3925
+ const s = e.items.map((i) => i.message);
3926
+ e.isUser ? e.writer = this.user.print(s) : e.writer = this.agent.print(s);
3927
+ });
3928
+ }
3929
+ async onMessageSend(t) {
3930
+ this.dialog.isConnected() && (this.dialog.sendMessage({ text: t }), this.printUserMessage(t));
3931
+ }
3932
+ }
3933
+ const Hi = async (n) => {
3934
+ setTimeout(async () => {
3935
+ (await he.getInstance(n)).registerProvider(
3936
+ "ace-conversational-hub-provider",
3937
+ (e, s) => {
3938
+ const i = new yi(
3939
+ n,
3940
+ e,
3941
+ s
3942
+ ), r = [];
3943
+ return r.push(
3944
+ s.actions.watch(
3945
+ "conversation.user-submit",
3946
+ (o, a) => {
3947
+ i.onMessageSend(o.text);
3948
+ }
3949
+ )
3950
+ ), () => {
3951
+ r.forEach((o) => {
3952
+ o();
3953
+ });
3954
+ };
3955
+ }
3956
+ );
3957
+ }, 0);
3958
+ };
3959
+ export {
3960
+ Hi as ConversationalHubProviderPlugin
3961
+ };