@crestapps/ai-chat-ui 2.0.0-preview.215 → 2.0.0-preview.223
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/dist/ai-chat-widget.js +762 -964
- package/dist/ai-chat-widget.js.map +1 -1
- package/dist/ai-chat-widget.min.js +1 -1
- package/dist/ai-chat-widget.min.js.map +1 -1
- package/dist/ai-chat.css +0 -2
- package/dist/ai-chat.js +2380 -3698
- package/dist/ai-chat.js.map +1 -1
- package/dist/ai-chat.min.css +1 -1
- package/dist/ai-chat.min.js +78 -1
- package/dist/ai-chat.min.js.map +1 -1
- package/dist/chat-image-carousel.css +0 -2
- package/dist/chat-image-carousel.js +306 -482
- package/dist/chat-image-carousel.js.map +1 -1
- package/dist/chat-image-carousel.min.css +1 -1
- package/dist/chat-image-carousel.min.js +1 -1
- package/dist/chat-image-carousel.min.js.map +1 -1
- package/dist/chat-interaction-settings.js +221 -293
- package/dist/chat-interaction-settings.js.map +1 -1
- package/dist/chat-interaction-settings.min.js +1 -1
- package/dist/chat-interaction-settings.min.js.map +1 -1
- package/dist/chat-interaction.js +2330 -3557
- package/dist/chat-interaction.js.map +1 -1
- package/dist/chat-interaction.min.js +62 -1
- package/dist/chat-interaction.min.js.map +1 -1
- package/dist/chat-markers.js +193 -485
- package/dist/chat-markers.js.map +1 -1
- package/dist/chat-markers.min.js +2 -1
- package/dist/chat-markers.min.js.map +1 -1
- package/dist/chat-widget.css +0 -2
- package/dist/chat-widget.min.css +1 -1
- package/dist/document-drop-zone.css +0 -2
- package/dist/document-drop-zone.js +127 -153
- package/dist/document-drop-zone.js.map +1 -1
- package/dist/document-drop-zone.min.css +1 -1
- package/dist/document-drop-zone.min.js +1 -1
- package/dist/document-drop-zone.min.js.map +1 -1
- package/dist/realtime-audio.js +1639 -2504
- package/dist/realtime-audio.js.map +1 -1
- package/dist/realtime-audio.min.js +3 -1
- package/dist/realtime-audio.min.js.map +1 -1
- package/dist/technical-name-generator.js +58 -80
- package/dist/technical-name-generator.js.map +1 -1
- package/dist/technical-name-generator.min.js +1 -1
- package/dist/technical-name-generator.min.js.map +1 -1
- package/package.json +1 -5
- package/dist/ai-chat.css.map +0 -1
- package/dist/chat-image-carousel.css.map +0 -1
- package/dist/chat-widget.css.map +0 -1
- package/dist/document-drop-zone.css.map +0 -1
package/dist/ai-chat-widget.js
CHANGED
|
@@ -1,967 +1,765 @@
|
|
|
1
1
|
/*
|
|
2
|
-
** NOTE: This file is generated by
|
|
3
|
-
**
|
|
2
|
+
** NOTE: This file is generated by the assets build (npm run build) and should not be edited directly!
|
|
3
|
+
** Edit its sources under Assets/ and rebuild; see Assets.json for the files it is built from.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
widgetContainer.style.display = 'none';
|
|
766
|
-
widgetContainer.setAttribute('aria-hidden', 'true');
|
|
767
|
-
}
|
|
768
|
-
if (toggleButton) {
|
|
769
|
-
toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;
|
|
770
|
-
}
|
|
771
|
-
} catch (error) {
|
|
772
|
-
console.warn('Failed to restore widget layout before initialization.', error);
|
|
773
|
-
} finally {
|
|
774
|
-
if (shell && shell.dataset.deferReveal !== 'true') {
|
|
775
|
-
shell.style.visibility = '';
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
var widgetApp = window.coreAIChatManager.initialize(chatConfig);
|
|
779
|
-
if (options.applySessionProfilePatch !== false && window.crestAppsAIChat && window.crestAppsAIChat.patchSessionProfileSync) {
|
|
780
|
-
window.crestAppsAIChat.patchSessionProfileSync(widgetApp);
|
|
781
|
-
}
|
|
782
|
-
function revealShell() {
|
|
783
|
-
if (!shell) {
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
shell.style.visibility = '';
|
|
787
|
-
shell.dataset.deferReveal = 'false';
|
|
788
|
-
}
|
|
789
|
-
function syncOpenPanelPosition() {
|
|
790
|
-
if (!widgetApp || typeof widgetApp.syncPanelPositionToToggle !== 'function') {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
widgetApp.syncPanelPositionToToggle(false);
|
|
794
|
-
}
|
|
795
|
-
function updateTtsPlaybackButtons() {
|
|
796
|
-
if (!widgetContainer) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
var buttons = widgetContainer.querySelectorAll('[data-tts-message-index]');
|
|
800
|
-
buttons.forEach(function (button) {
|
|
801
|
-
var buttonIndex = Number(button.getAttribute('data-tts-message-index'));
|
|
802
|
-
var isPlaying = buttonIndex === widgetApp.ttsPlayingMessageIndex;
|
|
803
|
-
button.classList.toggle('tts-playing', isPlaying);
|
|
804
|
-
button.setAttribute('title', isPlaying ? 'Pause audio' : 'Read aloud');
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
function queueTtsPlaybackButtonUpdate() {
|
|
808
|
-
requestAnimationFrame(updateTtsPlaybackButtons);
|
|
809
|
-
}
|
|
810
|
-
function revealShellWhenStable(initialOpen) {
|
|
811
|
-
if (!shell || shell.dataset.deferReveal !== 'true' || !initialOpen) {
|
|
812
|
-
revealShell();
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
var hasRevealed = false;
|
|
816
|
-
var resizeObserver = null;
|
|
817
|
-
function finalizeReveal() {
|
|
818
|
-
if (hasRevealed) {
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
hasRevealed = true;
|
|
822
|
-
if (resizeObserver) {
|
|
823
|
-
resizeObserver.disconnect();
|
|
824
|
-
}
|
|
825
|
-
requestAnimationFrame(function () {
|
|
826
|
-
syncOpenPanelPosition();
|
|
827
|
-
requestAnimationFrame(function () {
|
|
828
|
-
revealShell();
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
if (typeof ResizeObserver === 'undefined') {
|
|
833
|
-
window.setTimeout(finalizeReveal, 0);
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
var lastWidth = 0;
|
|
837
|
-
var lastHeight = 0;
|
|
838
|
-
var stablePasses = 0;
|
|
839
|
-
resizeObserver = new ResizeObserver(function (entries) {
|
|
840
|
-
var entry = entries && entries[0];
|
|
841
|
-
if (!entry) {
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
var width = Math.round(entry.contentRect.width);
|
|
845
|
-
var height = Math.round(entry.contentRect.height);
|
|
846
|
-
if (!width || !height) {
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
syncOpenPanelPosition();
|
|
850
|
-
if (width === lastWidth && height === lastHeight) {
|
|
851
|
-
stablePasses++;
|
|
852
|
-
} else {
|
|
853
|
-
lastWidth = width;
|
|
854
|
-
lastHeight = height;
|
|
855
|
-
stablePasses = 0;
|
|
856
|
-
}
|
|
857
|
-
if (stablePasses >= 1) {
|
|
858
|
-
finalizeReveal();
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
resizeObserver.observe(widgetContainer);
|
|
862
|
-
window.setTimeout(finalizeReveal, 150);
|
|
863
|
-
}
|
|
864
|
-
function setWidgetOpen(isOpen) {
|
|
865
|
-
if (widgetApp) {
|
|
866
|
-
var isCurrentlyOpen = widgetContainer.classList.contains('open');
|
|
867
|
-
if (isOpen && !isCurrentlyOpen && typeof widgetApp.syncPanelPositionToToggle === 'function') {
|
|
868
|
-
widgetApp.syncPanelPositionToToggle();
|
|
869
|
-
} else if (!isOpen && isCurrentlyOpen && typeof widgetApp.syncTogglePositionToPanel === 'function') {
|
|
870
|
-
widgetApp.syncTogglePositionToPanel();
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
widgetContainer.classList.toggle('open', isOpen);
|
|
874
|
-
widgetContainer.style.display = isOpen ? 'flex' : 'none';
|
|
875
|
-
widgetContainer.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
|
|
876
|
-
toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;
|
|
877
|
-
localStorage.setItem(widgetOpenStateKey, isOpen ? openStateValue : closedStateValue);
|
|
878
|
-
if (isOpen && typeof window.renderPendingCharts === 'function') {
|
|
879
|
-
setTimeout(function () {
|
|
880
|
-
window.renderPendingCharts();
|
|
881
|
-
}, 100);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
var initialOpen = shell && shell.dataset.initialOpen === 'true';
|
|
885
|
-
setWidgetOpen(initialOpen);
|
|
886
|
-
revealShellWhenStable(initialOpen);
|
|
887
|
-
if (widgetApp && typeof widgetApp.$watch === 'function') {
|
|
888
|
-
widgetApp.$watch('ttsPlayingMessageIndex', function () {
|
|
889
|
-
queueTtsPlaybackButtonUpdate();
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
queueTtsPlaybackButtonUpdate();
|
|
893
|
-
if (toggleButton) {
|
|
894
|
-
toggleButton.addEventListener('click', function () {
|
|
895
|
-
if (toggleButton.dataset.dragSuppressClick === 'true') {
|
|
896
|
-
toggleButton.dataset.dragSuppressClick = 'false';
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
setWidgetOpen(!widgetContainer.classList.contains('open'));
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
if (closeButton) {
|
|
903
|
-
closeButton.addEventListener('click', function () {
|
|
904
|
-
setWidgetOpen(false);
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
return widgetApp;
|
|
908
|
-
}
|
|
909
|
-
function initializeFromElement(element) {
|
|
910
|
-
if (!element || element.dataset.coreAiChatWidgetInitialized === 'true') {
|
|
911
|
-
return element ? element.__coreAIChatWidgetApp || null : null;
|
|
912
|
-
}
|
|
913
|
-
var jsonOptions = parseJsonAttribute(element, 'data-coreai-chat-widget-config', 'CoreAI chat widget config');
|
|
914
|
-
var attributeOptions = buildOptionsFromDataAttributes(element);
|
|
915
|
-
if (!jsonOptions && !attributeOptions) {
|
|
916
|
-
return null;
|
|
917
|
-
}
|
|
918
|
-
var options = Object.assign({}, jsonOptions || {}, attributeOptions || {});
|
|
919
|
-
var widgetApp = initialize(options);
|
|
920
|
-
if (!widgetApp) {
|
|
921
|
-
return null;
|
|
922
|
-
}
|
|
923
|
-
element.dataset.coreAiChatWidgetInitialized = 'true';
|
|
924
|
-
element.__coreAIChatWidgetApp = widgetApp;
|
|
925
|
-
return widgetApp;
|
|
926
|
-
}
|
|
927
|
-
function scanForAutoInitialization(root) {
|
|
928
|
-
if (!root || typeof root.querySelectorAll !== 'function') {
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
if (typeof root.matches === 'function' && root.matches('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]')) {
|
|
932
|
-
initializeFromElement(root);
|
|
933
|
-
}
|
|
934
|
-
root.querySelectorAll('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]').forEach(initializeFromElement);
|
|
935
|
-
}
|
|
936
|
-
function startAutoInitialization() {
|
|
937
|
-
scanForAutoInitialization(document);
|
|
938
|
-
if (typeof MutationObserver === 'undefined') {
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
var observer = new MutationObserver(function (mutations) {
|
|
942
|
-
mutations.forEach(function (mutation) {
|
|
943
|
-
mutation.addedNodes.forEach(function (node) {
|
|
944
|
-
if (node && node.nodeType === 1) {
|
|
945
|
-
scanForAutoInitialization(node);
|
|
946
|
-
}
|
|
947
|
-
});
|
|
948
|
-
});
|
|
949
|
-
});
|
|
950
|
-
observer.observe(document.body, {
|
|
951
|
-
childList: true,
|
|
952
|
-
subtree: true
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
if (document.readyState === 'loading') {
|
|
956
|
-
document.addEventListener('DOMContentLoaded', startAutoInitialization, {
|
|
957
|
-
once: true
|
|
958
|
-
});
|
|
959
|
-
} else {
|
|
960
|
-
startAutoInitialization();
|
|
961
|
-
}
|
|
962
|
-
return {
|
|
963
|
-
initialize: initialize,
|
|
964
|
-
initializeFromElement: initializeFromElement
|
|
965
|
-
};
|
|
966
|
-
}();
|
|
5
|
+
(function() {
|
|
6
|
+
//#region src/Resources/CrestApps.AI.Resources/Assets/js/ai-chat-widget.js
|
|
7
|
+
function clampWidgetValue(value, min, max) {
|
|
8
|
+
return Math.min(Math.max(value, min), max);
|
|
9
|
+
}
|
|
10
|
+
window.coreAIChatWidgetBehavior = window.coreAIChatWidgetBehavior || function() {
|
|
11
|
+
function parsePixelValue(value) {
|
|
12
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
13
|
+
if (typeof value !== "string") return null;
|
|
14
|
+
var parsed = parseFloat(value);
|
|
15
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
16
|
+
}
|
|
17
|
+
function attach(app, config) {
|
|
18
|
+
if (!app || app.__aiChatWidgetAttached) return;
|
|
19
|
+
app.__aiChatWidgetAttached = true;
|
|
20
|
+
app.chatWidgetStateName = null;
|
|
21
|
+
app.chatWidgetStateSession = null;
|
|
22
|
+
app.chatWidgetStateDocuments = null;
|
|
23
|
+
app.chatWidgetLayoutKey = null;
|
|
24
|
+
app.chatHistorySection = null;
|
|
25
|
+
app.widgetContainerElement = null;
|
|
26
|
+
app.widgetToggleButtonElement = null;
|
|
27
|
+
app.widgetResetSizeButtonElement = null;
|
|
28
|
+
app.widgetResizeObserver = null;
|
|
29
|
+
app.widgetViewportResizeHandler = null;
|
|
30
|
+
app.widgetDefaultWidth = null;
|
|
31
|
+
app.widgetDefaultHeight = null;
|
|
32
|
+
app.widgetIsInitialized = false;
|
|
33
|
+
app.getStoredWidgetLayout = function() {
|
|
34
|
+
if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) return {};
|
|
35
|
+
try {
|
|
36
|
+
var storedLayout = localStorage.getItem(this.chatWidgetLayoutKey);
|
|
37
|
+
return storedLayout ? JSON.parse(storedLayout) || {} : {};
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.warn("Failed to read widget layout state.", error);
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
app.saveStoredWidgetLayout = function(partialLayout) {
|
|
44
|
+
if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) return;
|
|
45
|
+
var currentLayout = this.getStoredWidgetLayout();
|
|
46
|
+
var nextLayout = Object.assign({}, currentLayout);
|
|
47
|
+
if (partialLayout.panel !== void 0) nextLayout.panel = Object.assign({}, currentLayout.panel || {}, partialLayout.panel || {});
|
|
48
|
+
if (partialLayout.position !== void 0) nextLayout.position = Object.assign({}, currentLayout.position || {}, partialLayout.position || {});
|
|
49
|
+
localStorage.setItem(this.chatWidgetLayoutKey, JSON.stringify(nextLayout));
|
|
50
|
+
};
|
|
51
|
+
app.getElementSize = function(element, fallbackWidth, fallbackHeight) {
|
|
52
|
+
if (!element) return {
|
|
53
|
+
width: fallbackWidth || 0,
|
|
54
|
+
height: fallbackHeight || 0
|
|
55
|
+
};
|
|
56
|
+
var rect = element.getBoundingClientRect();
|
|
57
|
+
var computed = window.getComputedStyle(element);
|
|
58
|
+
return {
|
|
59
|
+
width: Math.round(rect.width || parsePixelValue(computed.width) || fallbackWidth || 0),
|
|
60
|
+
height: Math.round(rect.height || parsePixelValue(computed.height) || fallbackHeight || 0)
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
app.getElementPosition = function(element) {
|
|
64
|
+
if (!element) return {
|
|
65
|
+
left: 0,
|
|
66
|
+
top: 0
|
|
67
|
+
};
|
|
68
|
+
var rect = element.getBoundingClientRect();
|
|
69
|
+
var computed = window.getComputedStyle(element);
|
|
70
|
+
var inlineLeft = parsePixelValue(element.style.left);
|
|
71
|
+
var inlineTop = parsePixelValue(element.style.top);
|
|
72
|
+
var computedLeft = parsePixelValue(computed.left);
|
|
73
|
+
var computedTop = parsePixelValue(computed.top);
|
|
74
|
+
var isHidden = computed.display === "none";
|
|
75
|
+
return {
|
|
76
|
+
left: Math.round(isHidden && Number.isFinite(inlineLeft) ? inlineLeft : rect.left || inlineLeft || computedLeft || 0),
|
|
77
|
+
top: Math.round(isHidden && Number.isFinite(inlineTop) ? inlineTop : rect.top || inlineTop || computedTop || 0)
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
app.getAvailableWidgetPositionRange = function(width, height) {
|
|
81
|
+
var viewportPadding = 8;
|
|
82
|
+
return {
|
|
83
|
+
padding: viewportPadding,
|
|
84
|
+
maxLeft: Math.max(viewportPadding, window.innerWidth - width - viewportPadding),
|
|
85
|
+
maxTop: Math.max(viewportPadding, window.innerHeight - height - viewportPadding)
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
app.createStoredPosition = function(left, top, width, height) {
|
|
89
|
+
var range = this.getAvailableWidgetPositionRange(width, height);
|
|
90
|
+
var leftSpan = Math.max(0, range.maxLeft - range.padding);
|
|
91
|
+
var topSpan = Math.max(0, range.maxTop - range.padding);
|
|
92
|
+
return {
|
|
93
|
+
left: Math.round(left),
|
|
94
|
+
top: Math.round(top),
|
|
95
|
+
leftRatio: leftSpan === 0 ? 0 : (left - range.padding) / leftSpan,
|
|
96
|
+
topRatio: topSpan === 0 ? 0 : (top - range.padding) / topSpan
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
app.resolveStoredPosition = function(storedPosition, width, height) {
|
|
100
|
+
if (!storedPosition) return null;
|
|
101
|
+
var range = this.getAvailableWidgetPositionRange(width, height);
|
|
102
|
+
var left = Number(storedPosition.left);
|
|
103
|
+
var top = Number(storedPosition.top);
|
|
104
|
+
var leftRatio = Number(storedPosition.leftRatio);
|
|
105
|
+
var topRatio = Number(storedPosition.topRatio);
|
|
106
|
+
if (Number.isFinite(leftRatio)) left = range.padding + Math.max(0, range.maxLeft - range.padding) * leftRatio;
|
|
107
|
+
if (Number.isFinite(topRatio)) top = range.padding + Math.max(0, range.maxTop - range.padding) * topRatio;
|
|
108
|
+
if (!Number.isFinite(left) || !Number.isFinite(top)) return null;
|
|
109
|
+
return this.clampWidgetPosition(left, top, width, height);
|
|
110
|
+
};
|
|
111
|
+
app.clampWidgetPosition = function(left, top, width, height) {
|
|
112
|
+
var range = this.getAvailableWidgetPositionRange(width, height);
|
|
113
|
+
return {
|
|
114
|
+
left: Math.round(clampWidgetValue(left, range.padding, range.maxLeft)),
|
|
115
|
+
top: Math.round(clampWidgetValue(top, range.padding, range.maxTop))
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
app.getStoredWidgetDocuments = function() {
|
|
119
|
+
this.clearStoredWidgetDocuments();
|
|
120
|
+
return [];
|
|
121
|
+
};
|
|
122
|
+
app.saveStoredWidgetDocuments = function() {
|
|
123
|
+
this.clearStoredWidgetDocuments();
|
|
124
|
+
};
|
|
125
|
+
app.clearStoredWidgetDocuments = function() {
|
|
126
|
+
if (!this.chatWidgetStateDocuments) return;
|
|
127
|
+
localStorage.removeItem(this.chatWidgetStateDocuments);
|
|
128
|
+
};
|
|
129
|
+
app.applyAbsolutePosition = function(element, left, top) {
|
|
130
|
+
if (!element) return;
|
|
131
|
+
element.style.left = left + "px";
|
|
132
|
+
element.style.top = top + "px";
|
|
133
|
+
element.style.right = "auto";
|
|
134
|
+
element.style.bottom = "auto";
|
|
135
|
+
};
|
|
136
|
+
app.getWidgetDefaultSize = function() {
|
|
137
|
+
return {
|
|
138
|
+
width: this.widgetDefaultWidth || parsePixelValue(config.widget.defaultWidth) || 380,
|
|
139
|
+
height: this.widgetDefaultHeight || parsePixelValue(config.widget.defaultHeight) || 520
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
app.getWidgetToggleGap = function() {
|
|
143
|
+
return 8;
|
|
144
|
+
};
|
|
145
|
+
app.isWidgetPanelVisible = function() {
|
|
146
|
+
if (!this.widgetContainerElement) return false;
|
|
147
|
+
var computed = window.getComputedStyle(this.widgetContainerElement);
|
|
148
|
+
return this.widgetContainerElement.classList.contains("open") && computed.display !== "none";
|
|
149
|
+
};
|
|
150
|
+
app.persistWidgetPanelPosition = function() {
|
|
151
|
+
if (!this.widgetContainerElement || !config.widget.persistLayout) return;
|
|
152
|
+
var panelDefaultSize = this.getWidgetDefaultSize();
|
|
153
|
+
var panelPosition = this.getElementPosition(this.widgetContainerElement);
|
|
154
|
+
var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);
|
|
155
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
156
|
+
var linkedPosition = this.clampWidgetPosition(panelPosition.left + panelSize.width - toggleSize.width, panelPosition.top + panelSize.height + this.getWidgetToggleGap(), toggleSize.width, toggleSize.height);
|
|
157
|
+
this.saveStoredWidgetLayout({ position: this.createStoredPosition(linkedPosition.left, linkedPosition.top, toggleSize.width, toggleSize.height) });
|
|
158
|
+
};
|
|
159
|
+
app.persistWidgetTogglePosition = function() {
|
|
160
|
+
if (!this.widgetToggleButtonElement || !config.widget.persistLayout) return;
|
|
161
|
+
var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);
|
|
162
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
163
|
+
this.saveStoredWidgetLayout({ position: this.createStoredPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height) });
|
|
164
|
+
};
|
|
165
|
+
app.persistWidgetPanelSize = function() {
|
|
166
|
+
if (!this.widgetContainerElement || !config.widget.enableResizing || !config.widget.persistLayout) return;
|
|
167
|
+
var defaultSize = this.getWidgetDefaultSize();
|
|
168
|
+
var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);
|
|
169
|
+
this.saveStoredWidgetLayout({ panel: {
|
|
170
|
+
width: Math.abs(currentSize.width - defaultSize.width) <= 1 ? null : currentSize.width,
|
|
171
|
+
height: Math.abs(currentSize.height - defaultSize.height) <= 1 ? null : currentSize.height
|
|
172
|
+
} });
|
|
173
|
+
};
|
|
174
|
+
app.syncTogglePositionToPanel = function(persistLayout) {
|
|
175
|
+
if (persistLayout === void 0) persistLayout = true;
|
|
176
|
+
if (!this.widgetContainerElement || !this.widgetToggleButtonElement) return;
|
|
177
|
+
var panelDefaultSize = this.getWidgetDefaultSize();
|
|
178
|
+
var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);
|
|
179
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
180
|
+
var panelPosition = this.getElementPosition(this.widgetContainerElement);
|
|
181
|
+
var linkedPosition = this.clampWidgetPosition(panelPosition.left + panelSize.width - toggleSize.width, panelPosition.top + panelSize.height + this.getWidgetToggleGap(), toggleSize.width, toggleSize.height);
|
|
182
|
+
this.applyAbsolutePosition(this.widgetToggleButtonElement, linkedPosition.left, linkedPosition.top);
|
|
183
|
+
if (persistLayout && config.widget.persistLayout) this.persistWidgetTogglePosition();
|
|
184
|
+
};
|
|
185
|
+
app.syncPanelPositionToToggle = function(persistLayout) {
|
|
186
|
+
if (persistLayout === void 0) persistLayout = true;
|
|
187
|
+
if (!this.widgetContainerElement || !this.widgetToggleButtonElement) return;
|
|
188
|
+
var panelDefaultSize = this.getWidgetDefaultSize();
|
|
189
|
+
var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);
|
|
190
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
191
|
+
var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);
|
|
192
|
+
var linkedPosition = this.clampWidgetPosition(togglePosition.left + toggleSize.width - panelSize.width, togglePosition.top - panelSize.height - this.getWidgetToggleGap(), panelSize.width, panelSize.height);
|
|
193
|
+
this.applyAbsolutePosition(this.widgetContainerElement, linkedPosition.left, linkedPosition.top);
|
|
194
|
+
if (persistLayout && config.widget.persistLayout) this.persistWidgetPanelPosition();
|
|
195
|
+
};
|
|
196
|
+
app.updateWidgetResetSizeButtonVisibility = function() {
|
|
197
|
+
if (!this.widgetResetSizeButtonElement) return;
|
|
198
|
+
if (!config.widget.enableResizing || !this.widgetContainerElement) {
|
|
199
|
+
this.widgetResetSizeButtonElement.classList.add("d-none");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
var defaultSize = this.getWidgetDefaultSize();
|
|
203
|
+
var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);
|
|
204
|
+
var isResized = Math.abs(currentSize.width - defaultSize.width) > 1 || Math.abs(currentSize.height - defaultSize.height) > 1 || !!this.widgetContainerElement.style.width || !!this.widgetContainerElement.style.height;
|
|
205
|
+
this.widgetResetSizeButtonElement.classList.toggle("d-none", !isResized);
|
|
206
|
+
};
|
|
207
|
+
app.resetWidgetSize = function() {
|
|
208
|
+
if (!this.widgetContainerElement || !config.widget.enableResizing) return;
|
|
209
|
+
this.widgetContainerElement.style.removeProperty("width");
|
|
210
|
+
this.widgetContainerElement.style.removeProperty("height");
|
|
211
|
+
this.persistWidgetPanelSize();
|
|
212
|
+
this.constrainWidgetElementsToViewport();
|
|
213
|
+
this.updateWidgetResetSizeButtonVisibility();
|
|
214
|
+
};
|
|
215
|
+
app.restoreWidgetLayout = function() {
|
|
216
|
+
var storedLayout = this.getStoredWidgetLayout();
|
|
217
|
+
if (this.widgetContainerElement && config.widget.enableResizing) {
|
|
218
|
+
if (Number.isFinite(storedLayout.panel && storedLayout.panel.width)) this.widgetContainerElement.style.width = storedLayout.panel.width + "px";
|
|
219
|
+
else this.widgetContainerElement.style.removeProperty("width");
|
|
220
|
+
if (Number.isFinite(storedLayout.panel && storedLayout.panel.height)) this.widgetContainerElement.style.height = storedLayout.panel.height + "px";
|
|
221
|
+
else this.widgetContainerElement.style.removeProperty("height");
|
|
222
|
+
}
|
|
223
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
224
|
+
var storedTogglePosition = this.resolveStoredPosition(storedLayout.position, toggleSize.width, toggleSize.height);
|
|
225
|
+
if (this.widgetToggleButtonElement && config.widget.enableDragging && storedTogglePosition) {
|
|
226
|
+
this.applyAbsolutePosition(this.widgetToggleButtonElement, storedTogglePosition.left, storedTogglePosition.top);
|
|
227
|
+
this.syncPanelPositionToToggle(false);
|
|
228
|
+
} else if (this.widgetToggleButtonElement && config.widget.enableDragging && Number.isFinite(storedLayout.toggle && storedLayout.toggle.left) && Number.isFinite(storedLayout.toggle && storedLayout.toggle.top)) {
|
|
229
|
+
this.applyAbsolutePosition(this.widgetToggleButtonElement, storedLayout.toggle.left, storedLayout.toggle.top);
|
|
230
|
+
this.syncPanelPositionToToggle(false);
|
|
231
|
+
} else if (this.widgetContainerElement && config.widget.enableDragging && Number.isFinite(storedLayout.panel && storedLayout.panel.left) && Number.isFinite(storedLayout.panel && storedLayout.panel.top)) {
|
|
232
|
+
this.applyAbsolutePosition(this.widgetContainerElement, storedLayout.panel.left, storedLayout.panel.top);
|
|
233
|
+
this.syncTogglePositionToPanel(false);
|
|
234
|
+
}
|
|
235
|
+
this.constrainWidgetElementsToViewport();
|
|
236
|
+
this.updateWidgetResetSizeButtonVisibility();
|
|
237
|
+
};
|
|
238
|
+
app.attachDraggableWidgetElement = function(element, handle, layoutKey, suppressClickOnDrag) {
|
|
239
|
+
if (!element || !handle || !config.widget.enableDragging) return;
|
|
240
|
+
var activePointerId = null;
|
|
241
|
+
var startX = 0;
|
|
242
|
+
var startY = 0;
|
|
243
|
+
var startLeft = 0;
|
|
244
|
+
var startTop = 0;
|
|
245
|
+
var dragged = false;
|
|
246
|
+
var dragThreshold = 4;
|
|
247
|
+
var interactiveSelector = "button, a, input, textarea, select, option, label";
|
|
248
|
+
var self = this;
|
|
249
|
+
function stopDragging(event) {
|
|
250
|
+
if (activePointerId === null) return;
|
|
251
|
+
if (event && event.pointerId !== void 0 && event.pointerId !== activePointerId) return;
|
|
252
|
+
document.removeEventListener("pointermove", onPointerMove);
|
|
253
|
+
document.removeEventListener("pointerup", stopDragging);
|
|
254
|
+
document.removeEventListener("pointercancel", stopDragging);
|
|
255
|
+
element.classList.remove("ai-chat-widget-dragging");
|
|
256
|
+
activePointerId = null;
|
|
257
|
+
if (!dragged) return;
|
|
258
|
+
if (layoutKey === "panel") {
|
|
259
|
+
self.syncTogglePositionToPanel(false);
|
|
260
|
+
self.persistWidgetPanelPosition();
|
|
261
|
+
} else if (layoutKey === "toggle") {
|
|
262
|
+
self.syncPanelPositionToToggle(false);
|
|
263
|
+
self.persistWidgetTogglePosition();
|
|
264
|
+
}
|
|
265
|
+
if (config.widget.persistLayout) {
|
|
266
|
+
self.persistWidgetPanelPosition();
|
|
267
|
+
self.persistWidgetTogglePosition();
|
|
268
|
+
}
|
|
269
|
+
if (suppressClickOnDrag) {
|
|
270
|
+
element.dataset.dragSuppressClick = "true";
|
|
271
|
+
window.setTimeout(function() {
|
|
272
|
+
if (element.dataset.dragSuppressClick === "true") element.dataset.dragSuppressClick = "false";
|
|
273
|
+
}, 0);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function onPointerMove(event) {
|
|
277
|
+
if (activePointerId === null || event.pointerId !== activePointerId) return;
|
|
278
|
+
var deltaX = event.clientX - startX;
|
|
279
|
+
var deltaY = event.clientY - startY;
|
|
280
|
+
if (!dragged && Math.hypot(deltaX, deltaY) < dragThreshold) return;
|
|
281
|
+
dragged = true;
|
|
282
|
+
var defaultSize = self.getWidgetDefaultSize();
|
|
283
|
+
var currentSize = self.getElementSize(element, layoutKey === "panel" ? defaultSize.width : 52, layoutKey === "panel" ? defaultSize.height : 52);
|
|
284
|
+
var nextPosition = self.clampWidgetPosition(startLeft + deltaX, startTop + deltaY, currentSize.width, currentSize.height);
|
|
285
|
+
self.applyAbsolutePosition(element, nextPosition.left, nextPosition.top);
|
|
286
|
+
if (layoutKey === "panel") self.syncTogglePositionToPanel(false);
|
|
287
|
+
else if (layoutKey === "toggle") self.syncPanelPositionToToggle(false);
|
|
288
|
+
}
|
|
289
|
+
handle.addEventListener("pointerdown", function(event) {
|
|
290
|
+
if (event.button !== 0) return;
|
|
291
|
+
if (layoutKey === "panel" && event.target.closest(interactiveSelector)) return;
|
|
292
|
+
var rect = element.getBoundingClientRect();
|
|
293
|
+
startX = event.clientX;
|
|
294
|
+
startY = event.clientY;
|
|
295
|
+
startLeft = rect.left;
|
|
296
|
+
startTop = rect.top;
|
|
297
|
+
dragged = false;
|
|
298
|
+
activePointerId = event.pointerId;
|
|
299
|
+
element.classList.add("ai-chat-widget-dragging");
|
|
300
|
+
if (handle.setPointerCapture) handle.setPointerCapture(event.pointerId);
|
|
301
|
+
document.addEventListener("pointermove", onPointerMove);
|
|
302
|
+
document.addEventListener("pointerup", stopDragging);
|
|
303
|
+
document.addEventListener("pointercancel", stopDragging);
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
app.constrainWidgetElementsToViewport = function() {
|
|
308
|
+
if (this.widgetContainerElement && this.widgetContainerElement.style.left && this.isWidgetPanelVisible()) {
|
|
309
|
+
var panelDefaultSize = this.getWidgetDefaultSize();
|
|
310
|
+
var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);
|
|
311
|
+
var panelPosition = this.getElementPosition(this.widgetContainerElement);
|
|
312
|
+
var clampedPanel = this.clampWidgetPosition(panelPosition.left, panelPosition.top, panelSize.width, panelSize.height);
|
|
313
|
+
this.applyAbsolutePosition(this.widgetContainerElement, clampedPanel.left, clampedPanel.top);
|
|
314
|
+
this.syncTogglePositionToPanel(false);
|
|
315
|
+
if (config.widget.persistLayout) {
|
|
316
|
+
this.persistWidgetPanelPosition();
|
|
317
|
+
this.persistWidgetTogglePosition();
|
|
318
|
+
}
|
|
319
|
+
} else if (this.widgetToggleButtonElement && this.widgetToggleButtonElement.style.left) {
|
|
320
|
+
var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);
|
|
321
|
+
var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);
|
|
322
|
+
var clampedToggle = this.clampWidgetPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height);
|
|
323
|
+
this.applyAbsolutePosition(this.widgetToggleButtonElement, clampedToggle.left, clampedToggle.top);
|
|
324
|
+
this.syncPanelPositionToToggle(false);
|
|
325
|
+
if (config.widget.persistLayout) {
|
|
326
|
+
this.persistWidgetTogglePosition();
|
|
327
|
+
this.persistWidgetPanelPosition();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
app.showChatScreen = function() {
|
|
332
|
+
if (!this.chatHistorySection) return;
|
|
333
|
+
this.chatHistorySection.classList.remove("show");
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function initialize(app, config) {
|
|
337
|
+
if (!app || app.widgetIsInitialized) return;
|
|
338
|
+
if (!config.widget.chatWidgetContainer) {
|
|
339
|
+
console.error("The widget chatWidgetContainer is required.");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (!config.widget.chatWidgetStateName) {
|
|
343
|
+
console.error("The widget chatWidgetStateName is required.");
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
var chatWidgetContainer = document.querySelector(config.widget.chatWidgetContainer);
|
|
347
|
+
if (!chatWidgetContainer) return;
|
|
348
|
+
if (config.widget.chatHistorySection) app.chatHistorySection = document.querySelector(config.widget.chatHistorySection);
|
|
349
|
+
app.chatWidgetStateName = config.widget.chatWidgetStateName;
|
|
350
|
+
app.chatWidgetStateSession = config.widget.chatWidgetStateName + "Session";
|
|
351
|
+
app.chatWidgetStateDocuments = config.widget.chatWidgetStateName + "Documents";
|
|
352
|
+
app.chatWidgetLayoutKey = config.widget.chatWidgetStateName + "Layout";
|
|
353
|
+
app.widgetContainerElement = chatWidgetContainer;
|
|
354
|
+
app.widgetToggleButtonElement = config.widget.toggleButtonSelector ? document.querySelector(config.widget.toggleButtonSelector) : null;
|
|
355
|
+
app.widgetResetSizeButtonElement = config.widget.resetSizeButtonSelector ? document.querySelector(config.widget.resetSizeButtonSelector) : null;
|
|
356
|
+
app.widgetDefaultWidth = parsePixelValue(config.widget.defaultWidth) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).width) || 380;
|
|
357
|
+
app.widgetDefaultHeight = parsePixelValue(config.widget.defaultHeight) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).height) || 520;
|
|
358
|
+
app.widgetIsInitialized = true;
|
|
359
|
+
app.clearStoredWidgetDocuments();
|
|
360
|
+
app.documents = [];
|
|
361
|
+
if (config.widget.enableResizing) {
|
|
362
|
+
chatWidgetContainer.classList.add("ai-chat-widget-resizable");
|
|
363
|
+
chatWidgetContainer.style.minWidth = (parsePixelValue(config.widget.minWidth) || 320) + "px";
|
|
364
|
+
chatWidgetContainer.style.minHeight = (parsePixelValue(config.widget.minHeight) || 420) + "px";
|
|
365
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
366
|
+
app.widgetResizeObserver = new ResizeObserver(function() {
|
|
367
|
+
app.persistWidgetPanelSize();
|
|
368
|
+
app.constrainWidgetElementsToViewport();
|
|
369
|
+
app.updateWidgetResetSizeButtonVisibility();
|
|
370
|
+
});
|
|
371
|
+
app.widgetResizeObserver.observe(chatWidgetContainer);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
var dragHandleSelector = config.widget.dragHandleSelector || ".ai-chat-widget-header";
|
|
375
|
+
var dragHandle = chatWidgetContainer.querySelector(dragHandleSelector);
|
|
376
|
+
if (config.widget.enableDragging && dragHandle) {
|
|
377
|
+
dragHandle.classList.add("ai-chat-widget-drag-handle");
|
|
378
|
+
chatWidgetContainer.classList.add("ai-chat-widget-draggable");
|
|
379
|
+
app.attachDraggableWidgetElement(chatWidgetContainer, dragHandle, "panel", false);
|
|
380
|
+
}
|
|
381
|
+
if (config.widget.enableDragging && app.widgetToggleButtonElement) {
|
|
382
|
+
app.widgetToggleButtonElement.classList.add("ai-chat-widget-draggable");
|
|
383
|
+
app.attachDraggableWidgetElement(app.widgetToggleButtonElement, app.widgetToggleButtonElement, "toggle", true);
|
|
384
|
+
}
|
|
385
|
+
if (app.widgetResetSizeButtonElement) app.widgetResetSizeButtonElement.addEventListener("click", function(event) {
|
|
386
|
+
event.preventDefault();
|
|
387
|
+
app.resetWidgetSize();
|
|
388
|
+
});
|
|
389
|
+
app.restoreWidgetLayout();
|
|
390
|
+
if (!app.widgetViewportResizeHandler) {
|
|
391
|
+
app.widgetViewportResizeHandler = function() {
|
|
392
|
+
if (config.widget.persistLayout) app.restoreWidgetLayout();
|
|
393
|
+
else app.constrainWidgetElementsToViewport();
|
|
394
|
+
app.updateWidgetResetSizeButtonVisibility();
|
|
395
|
+
};
|
|
396
|
+
window.addEventListener("resize", app.widgetViewportResizeHandler);
|
|
397
|
+
}
|
|
398
|
+
app.reloadCurrentSession();
|
|
399
|
+
if (config.widget.showHistoryButton && app.chatHistorySection) {
|
|
400
|
+
var showHistoryButton = document.querySelector(config.widget.showHistoryButton);
|
|
401
|
+
if (showHistoryButton) showHistoryButton.addEventListener("click", function() {
|
|
402
|
+
app.chatHistorySection.classList.toggle("show");
|
|
403
|
+
});
|
|
404
|
+
if (config.widget.closeHistoryButton) {
|
|
405
|
+
var closeHistoryButton = document.querySelector(config.widget.closeHistoryButton);
|
|
406
|
+
if (closeHistoryButton) closeHistoryButton.addEventListener("click", function() {
|
|
407
|
+
app.showChatScreen();
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (config.widget.newChatButton) {
|
|
412
|
+
var newChatButton = document.querySelector(config.widget.newChatButton);
|
|
413
|
+
if (newChatButton) newChatButton.addEventListener("click", function() {
|
|
414
|
+
app.resetSession();
|
|
415
|
+
app.showChatScreen();
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function resolveSessionId(app) {
|
|
420
|
+
if (!app || !app.widgetIsInitialized) return null;
|
|
421
|
+
return localStorage.getItem(app.chatWidgetStateSession);
|
|
422
|
+
}
|
|
423
|
+
function onSessionInitialized(app, sessionId) {
|
|
424
|
+
if (app && app.widgetIsInitialized) localStorage.setItem(app.chatWidgetStateSession, sessionId);
|
|
425
|
+
}
|
|
426
|
+
function onSessionReset(app) {
|
|
427
|
+
if (app && app.widgetIsInitialized) {
|
|
428
|
+
localStorage.removeItem(app.chatWidgetStateSession);
|
|
429
|
+
app.clearStoredWidgetDocuments();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function onDocumentsChanged(app, documents) {
|
|
433
|
+
if (app && app.widgetIsInitialized) app.saveStoredWidgetDocuments(documents);
|
|
434
|
+
}
|
|
435
|
+
function handleReceiveError(app) {
|
|
436
|
+
if (app && app.widgetIsInitialized && !app.isSessionStarted && !app._attemptedSessionRecovery) {
|
|
437
|
+
app._attemptedSessionRecovery = true;
|
|
438
|
+
localStorage.removeItem(app.chatWidgetStateSession);
|
|
439
|
+
app.clearStoredWidgetDocuments();
|
|
440
|
+
app.startNewSession();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function dispose(app) {
|
|
444
|
+
if (!app) return;
|
|
445
|
+
if (app.widgetResizeObserver) {
|
|
446
|
+
app.widgetResizeObserver.disconnect();
|
|
447
|
+
app.widgetResizeObserver = null;
|
|
448
|
+
}
|
|
449
|
+
if (app.widgetViewportResizeHandler) {
|
|
450
|
+
window.removeEventListener("resize", app.widgetViewportResizeHandler);
|
|
451
|
+
app.widgetViewportResizeHandler = null;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
attach,
|
|
456
|
+
initialize,
|
|
457
|
+
onMounted: initialize,
|
|
458
|
+
resolveSessionId,
|
|
459
|
+
onSessionInitialized,
|
|
460
|
+
onSessionReset,
|
|
461
|
+
onDocumentsChanged,
|
|
462
|
+
handleReceiveError,
|
|
463
|
+
dispose,
|
|
464
|
+
onBeforeUnmount: dispose
|
|
465
|
+
};
|
|
466
|
+
}();
|
|
467
|
+
window.coreAIChatWidgetManager = window.coreAIChatWidgetManager || function() {
|
|
468
|
+
function getAttributeValue(element, attributeName) {
|
|
469
|
+
var value = element.getAttribute(attributeName);
|
|
470
|
+
return value === null || value === "" ? null : value;
|
|
471
|
+
}
|
|
472
|
+
function parseBooleanAttributeValue(value) {
|
|
473
|
+
if (value === null || value === void 0) return null;
|
|
474
|
+
if (typeof value === "boolean") return value;
|
|
475
|
+
var normalized = String(value).trim().toLowerCase();
|
|
476
|
+
if (normalized === "true") return true;
|
|
477
|
+
if (normalized === "false") return false;
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
function parseJsonAttribute(element, attributeName, description) {
|
|
481
|
+
var rawValue = getAttributeValue(element, attributeName);
|
|
482
|
+
if (!rawValue) return null;
|
|
483
|
+
try {
|
|
484
|
+
return JSON.parse(rawValue);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
console.error("Failed to parse " + description + " JSON.", error);
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function buildOptionsFromDataAttributes(element) {
|
|
491
|
+
var widgetContainerSelector = getAttributeValue(element, "data-coreai-chat-widget-container-selector");
|
|
492
|
+
if (!widgetContainerSelector) return null;
|
|
493
|
+
var chatConfig = null;
|
|
494
|
+
if (window.coreAIChatManager && typeof window.coreAIChatManager.buildConfigFromElement === "function") chatConfig = window.coreAIChatManager.buildConfigFromElement(element, { allowWidgetHost: true });
|
|
495
|
+
var profileId = getAttributeValue(element, "data-coreai-chat-widget-profile-id");
|
|
496
|
+
var profileName = getAttributeValue(element, "data-coreai-chat-widget-profile-name");
|
|
497
|
+
var profileDisplayText = getAttributeValue(element, "data-coreai-chat-widget-profile-display-text");
|
|
498
|
+
var profileWelcomeMessage = getAttributeValue(element, "data-coreai-chat-widget-profile-welcome-message");
|
|
499
|
+
var profileInitialPrompt = getAttributeValue(element, "data-coreai-chat-widget-profile-initial-prompt");
|
|
500
|
+
var profileChatMode = getAttributeValue(element, "data-coreai-chat-widget-profile-chat-mode");
|
|
501
|
+
var profileTtsVoiceName = getAttributeValue(element, "data-coreai-chat-widget-profile-tts-voice-name");
|
|
502
|
+
var profileRealtimeVoiceName = getAttributeValue(element, "data-coreai-chat-widget-profile-realtime-voice-name");
|
|
503
|
+
var profileMetricsEnabled = parseBooleanAttributeValue(getAttributeValue(element, "data-coreai-chat-widget-profile-enable-session-metrics"));
|
|
504
|
+
var profileSessionDocuments = parseBooleanAttributeValue(getAttributeValue(element, "data-coreai-chat-widget-profile-allow-session-documents"));
|
|
505
|
+
var profile = null;
|
|
506
|
+
if (profileId || profileName || profileDisplayText || profileWelcomeMessage || profileChatMode || profileTtsVoiceName || profileRealtimeVoiceName || profileMetricsEnabled !== null || profileSessionDocuments !== null) profile = {
|
|
507
|
+
id: profileId,
|
|
508
|
+
name: profileName,
|
|
509
|
+
displayText: profileDisplayText,
|
|
510
|
+
welcomeMessage: profileWelcomeMessage,
|
|
511
|
+
initialPrompt: profileInitialPrompt,
|
|
512
|
+
chatMode: profileChatMode,
|
|
513
|
+
ttsVoiceName: profileTtsVoiceName,
|
|
514
|
+
realtimeVoiceName: profileRealtimeVoiceName,
|
|
515
|
+
enableSessionMetrics: profileMetricsEnabled === true,
|
|
516
|
+
allowSessionDocuments: profileSessionDocuments === true
|
|
517
|
+
};
|
|
518
|
+
var enableDragging = parseBooleanAttributeValue(getAttributeValue(element, "data-coreai-chat-widget-enable-dragging"));
|
|
519
|
+
var enableResizing = parseBooleanAttributeValue(getAttributeValue(element, "data-coreai-chat-widget-enable-resizing"));
|
|
520
|
+
var persistLayout = parseBooleanAttributeValue(getAttributeValue(element, "data-coreai-chat-widget-persist-layout"));
|
|
521
|
+
return {
|
|
522
|
+
shellSelector: getAttributeValue(element, "data-coreai-chat-widget-shell-selector"),
|
|
523
|
+
widgetContainerSelector,
|
|
524
|
+
toggleButtonSelector: getAttributeValue(element, "data-coreai-chat-widget-toggle-button-selector"),
|
|
525
|
+
closeButtonSelector: getAttributeValue(element, "data-coreai-chat-widget-close-button-selector"),
|
|
526
|
+
inputSelector: getAttributeValue(element, "data-coreai-chat-widget-input-selector"),
|
|
527
|
+
messageTemplateSelector: getAttributeValue(element, "data-coreai-chat-widget-message-template-selector"),
|
|
528
|
+
indicatorTemplateSelector: getAttributeValue(element, "data-coreai-chat-widget-indicator-template-selector"),
|
|
529
|
+
profile,
|
|
530
|
+
widgetStateName: getAttributeValue(element, "data-coreai-chat-widget-state-name"),
|
|
531
|
+
openStateValue: getAttributeValue(element, "data-coreai-chat-widget-open-state-value"),
|
|
532
|
+
closedStateValue: getAttributeValue(element, "data-coreai-chat-widget-closed-state-value"),
|
|
533
|
+
openIconHtml: getAttributeValue(element, "data-coreai-chat-widget-open-icon-html"),
|
|
534
|
+
closedIconHtml: getAttributeValue(element, "data-coreai-chat-widget-closed-icon-html"),
|
|
535
|
+
chatConfig: chatConfig ? Object.assign({}, chatConfig, {
|
|
536
|
+
initialPrompt: profileInitialPrompt || chatConfig.initialPrompt,
|
|
537
|
+
realtimeVoiceName: profileRealtimeVoiceName || chatConfig.realtimeVoiceName,
|
|
538
|
+
widget: Object.assign({}, chatConfig.widget || {}, {
|
|
539
|
+
chatWidgetContainer: widgetContainerSelector,
|
|
540
|
+
chatWidgetStateName: getAttributeValue(element, "data-coreai-chat-widget-state-name"),
|
|
541
|
+
newChatButton: getAttributeValue(element, "data-coreai-chat-widget-new-chat-button-selector"),
|
|
542
|
+
toggleButtonSelector: getAttributeValue(element, "data-coreai-chat-widget-toggle-button-selector"),
|
|
543
|
+
resetSizeButtonSelector: getAttributeValue(element, "data-coreai-chat-widget-reset-size-button-selector"),
|
|
544
|
+
dragHandleSelector: getAttributeValue(element, "data-coreai-chat-widget-drag-handle-selector"),
|
|
545
|
+
enableDragging: enableDragging === null ? void 0 : enableDragging,
|
|
546
|
+
enableResizing: enableResizing === null ? void 0 : enableResizing,
|
|
547
|
+
persistLayout: persistLayout === null ? void 0 : persistLayout
|
|
548
|
+
})
|
|
549
|
+
}) : null
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function initialize(options) {
|
|
553
|
+
if (!options) return null;
|
|
554
|
+
var chatConfig = options.chatConfig;
|
|
555
|
+
if (!chatConfig && options.configElementSelector) {
|
|
556
|
+
var configElement = document.querySelector(options.configElementSelector);
|
|
557
|
+
chatConfig = configElement ? parseJsonAttribute(configElement, "data-config", "AI chat widget config") : null;
|
|
558
|
+
}
|
|
559
|
+
if (!chatConfig) return null;
|
|
560
|
+
if (options.messageTemplateSelector) {
|
|
561
|
+
var messageTemplate = document.querySelector(options.messageTemplateSelector);
|
|
562
|
+
if (messageTemplate) chatConfig.messageTemplate = messageTemplate.innerHTML;
|
|
563
|
+
}
|
|
564
|
+
if (options.indicatorTemplateSelector) {
|
|
565
|
+
var indicatorTemplate = document.querySelector(options.indicatorTemplateSelector);
|
|
566
|
+
if (indicatorTemplate) chatConfig.indicatorTemplate = indicatorTemplate.innerHTML;
|
|
567
|
+
}
|
|
568
|
+
var shell = document.querySelector(options.shellSelector);
|
|
569
|
+
var widgetContainer = document.querySelector(options.widgetContainerSelector);
|
|
570
|
+
var toggleButton = document.querySelector(options.toggleButtonSelector);
|
|
571
|
+
var closeButton = document.querySelector(options.closeButtonSelector);
|
|
572
|
+
var profileInput = options.inputSelector ? document.querySelector(options.inputSelector) : null;
|
|
573
|
+
var widgetStateName = options.widgetStateName || chatConfig.widget.chatWidgetStateName;
|
|
574
|
+
var widgetOpenStateKey = options.widgetOpenStateKey || widgetStateName + "Open";
|
|
575
|
+
var widgetLayoutKey = widgetStateName + "Layout";
|
|
576
|
+
var openStateValue = options.openStateValue || "open";
|
|
577
|
+
var closedStateValue = options.closedStateValue || "closed";
|
|
578
|
+
if (profileInput && options.profile && options.profile.id) profileInput.setAttribute("data-profile-id", options.profile.id);
|
|
579
|
+
try {
|
|
580
|
+
var storedLayout = localStorage.getItem(widgetLayoutKey);
|
|
581
|
+
var layout = storedLayout ? JSON.parse(storedLayout) || {} : {};
|
|
582
|
+
var position = layout.position || {};
|
|
583
|
+
var panelLayout = layout.panel || {};
|
|
584
|
+
var toggleLeft = Number(position.left);
|
|
585
|
+
var toggleTop = Number(position.top);
|
|
586
|
+
var isOpen = localStorage.getItem(widgetOpenStateKey) === openStateValue;
|
|
587
|
+
var viewportPadding = 8;
|
|
588
|
+
if (shell) {
|
|
589
|
+
shell.dataset.deferReveal = isOpen ? "true" : "false";
|
|
590
|
+
shell.dataset.initialOpen = isOpen ? "true" : "false";
|
|
591
|
+
}
|
|
592
|
+
if (widgetContainer && toggleButton) {
|
|
593
|
+
var toggleSize = 52;
|
|
594
|
+
var panelWidth = Number.isFinite(Number(panelLayout.width)) ? Number(panelLayout.width) : Math.round(parseFloat(window.getComputedStyle(widgetContainer).width) || 380);
|
|
595
|
+
var panelHeight = Number.isFinite(Number(panelLayout.height)) ? Number(panelLayout.height) : Math.round(parseFloat(window.getComputedStyle(widgetContainer).height) || 520);
|
|
596
|
+
var maxLeft = Math.max(viewportPadding, window.innerWidth - toggleSize - viewportPadding);
|
|
597
|
+
var maxTop = Math.max(viewportPadding, window.innerHeight - toggleSize - viewportPadding);
|
|
598
|
+
if (Number.isFinite(Number(position.leftRatio))) toggleLeft = viewportPadding + Math.max(0, maxLeft - viewportPadding) * Number(position.leftRatio);
|
|
599
|
+
if (Number.isFinite(Number(position.topRatio))) toggleTop = viewportPadding + Math.max(0, maxTop - viewportPadding) * Number(position.topRatio);
|
|
600
|
+
if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {
|
|
601
|
+
toggleLeft = Math.round(clampWidgetValue(toggleLeft, viewportPadding, maxLeft));
|
|
602
|
+
toggleTop = Math.round(clampWidgetValue(toggleTop, viewportPadding, maxTop));
|
|
603
|
+
}
|
|
604
|
+
if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {
|
|
605
|
+
toggleButton.style.left = toggleLeft + "px";
|
|
606
|
+
toggleButton.style.top = toggleTop + "px";
|
|
607
|
+
toggleButton.style.right = "auto";
|
|
608
|
+
toggleButton.style.bottom = "auto";
|
|
609
|
+
var toggleGap = 8;
|
|
610
|
+
widgetContainer.style.left = toggleLeft + toggleSize - panelWidth + "px";
|
|
611
|
+
widgetContainer.style.top = toggleTop - panelHeight - toggleGap + "px";
|
|
612
|
+
widgetContainer.style.right = "auto";
|
|
613
|
+
widgetContainer.style.bottom = "auto";
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (widgetContainer) {
|
|
617
|
+
widgetContainer.classList.remove("open");
|
|
618
|
+
widgetContainer.style.display = "none";
|
|
619
|
+
widgetContainer.setAttribute("aria-hidden", "true");
|
|
620
|
+
}
|
|
621
|
+
if (toggleButton) toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.warn("Failed to restore widget layout before initialization.", error);
|
|
624
|
+
} finally {
|
|
625
|
+
if (shell && shell.dataset.deferReveal !== "true") shell.style.visibility = "";
|
|
626
|
+
}
|
|
627
|
+
var widgetApp = window.coreAIChatManager.initialize(chatConfig);
|
|
628
|
+
if (options.applySessionProfilePatch !== false && window.crestAppsAIChat && window.crestAppsAIChat.patchSessionProfileSync) window.crestAppsAIChat.patchSessionProfileSync(widgetApp);
|
|
629
|
+
function revealShell() {
|
|
630
|
+
if (!shell) return;
|
|
631
|
+
shell.style.visibility = "";
|
|
632
|
+
shell.dataset.deferReveal = "false";
|
|
633
|
+
}
|
|
634
|
+
function syncOpenPanelPosition() {
|
|
635
|
+
if (!widgetApp || typeof widgetApp.syncPanelPositionToToggle !== "function") return;
|
|
636
|
+
widgetApp.syncPanelPositionToToggle(false);
|
|
637
|
+
}
|
|
638
|
+
function updateTtsPlaybackButtons() {
|
|
639
|
+
if (!widgetContainer) return;
|
|
640
|
+
widgetContainer.querySelectorAll("[data-tts-message-index]").forEach(function(button) {
|
|
641
|
+
var isPlaying = Number(button.getAttribute("data-tts-message-index")) === widgetApp.ttsPlayingMessageIndex;
|
|
642
|
+
button.classList.toggle("tts-playing", isPlaying);
|
|
643
|
+
button.setAttribute("title", isPlaying ? "Pause audio" : "Read aloud");
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function queueTtsPlaybackButtonUpdate() {
|
|
647
|
+
requestAnimationFrame(updateTtsPlaybackButtons);
|
|
648
|
+
}
|
|
649
|
+
function revealShellWhenStable(initialOpen) {
|
|
650
|
+
if (!shell || shell.dataset.deferReveal !== "true" || !initialOpen) {
|
|
651
|
+
revealShell();
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
var hasRevealed = false;
|
|
655
|
+
var resizeObserver = null;
|
|
656
|
+
function finalizeReveal() {
|
|
657
|
+
if (hasRevealed) return;
|
|
658
|
+
hasRevealed = true;
|
|
659
|
+
if (resizeObserver) resizeObserver.disconnect();
|
|
660
|
+
requestAnimationFrame(function() {
|
|
661
|
+
syncOpenPanelPosition();
|
|
662
|
+
requestAnimationFrame(function() {
|
|
663
|
+
revealShell();
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
if (typeof ResizeObserver === "undefined") {
|
|
668
|
+
window.setTimeout(finalizeReveal, 0);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
var lastWidth = 0;
|
|
672
|
+
var lastHeight = 0;
|
|
673
|
+
var stablePasses = 0;
|
|
674
|
+
resizeObserver = new ResizeObserver(function(entries) {
|
|
675
|
+
var entry = entries && entries[0];
|
|
676
|
+
if (!entry) return;
|
|
677
|
+
var width = Math.round(entry.contentRect.width);
|
|
678
|
+
var height = Math.round(entry.contentRect.height);
|
|
679
|
+
if (!width || !height) return;
|
|
680
|
+
syncOpenPanelPosition();
|
|
681
|
+
if (width === lastWidth && height === lastHeight) stablePasses++;
|
|
682
|
+
else {
|
|
683
|
+
lastWidth = width;
|
|
684
|
+
lastHeight = height;
|
|
685
|
+
stablePasses = 0;
|
|
686
|
+
}
|
|
687
|
+
if (stablePasses >= 1) finalizeReveal();
|
|
688
|
+
});
|
|
689
|
+
resizeObserver.observe(widgetContainer);
|
|
690
|
+
window.setTimeout(finalizeReveal, 150);
|
|
691
|
+
}
|
|
692
|
+
function setWidgetOpen(isOpen) {
|
|
693
|
+
if (widgetApp) {
|
|
694
|
+
var isCurrentlyOpen = widgetContainer.classList.contains("open");
|
|
695
|
+
if (isOpen && !isCurrentlyOpen && typeof widgetApp.syncPanelPositionToToggle === "function") widgetApp.syncPanelPositionToToggle();
|
|
696
|
+
else if (!isOpen && isCurrentlyOpen && typeof widgetApp.syncTogglePositionToPanel === "function") widgetApp.syncTogglePositionToPanel();
|
|
697
|
+
}
|
|
698
|
+
widgetContainer.classList.toggle("open", isOpen);
|
|
699
|
+
widgetContainer.style.display = isOpen ? "flex" : "none";
|
|
700
|
+
widgetContainer.setAttribute("aria-hidden", isOpen ? "false" : "true");
|
|
701
|
+
toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;
|
|
702
|
+
localStorage.setItem(widgetOpenStateKey, isOpen ? openStateValue : closedStateValue);
|
|
703
|
+
if (isOpen && typeof window.renderPendingCharts === "function") setTimeout(function() {
|
|
704
|
+
window.renderPendingCharts();
|
|
705
|
+
}, 100);
|
|
706
|
+
}
|
|
707
|
+
var initialOpen = shell && shell.dataset.initialOpen === "true";
|
|
708
|
+
setWidgetOpen(initialOpen);
|
|
709
|
+
revealShellWhenStable(initialOpen);
|
|
710
|
+
if (widgetApp && typeof widgetApp.$watch === "function") widgetApp.$watch("ttsPlayingMessageIndex", function() {
|
|
711
|
+
queueTtsPlaybackButtonUpdate();
|
|
712
|
+
});
|
|
713
|
+
queueTtsPlaybackButtonUpdate();
|
|
714
|
+
if (toggleButton) toggleButton.addEventListener("click", function() {
|
|
715
|
+
if (toggleButton.dataset.dragSuppressClick === "true") {
|
|
716
|
+
toggleButton.dataset.dragSuppressClick = "false";
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
setWidgetOpen(!widgetContainer.classList.contains("open"));
|
|
720
|
+
});
|
|
721
|
+
if (closeButton) closeButton.addEventListener("click", function() {
|
|
722
|
+
setWidgetOpen(false);
|
|
723
|
+
});
|
|
724
|
+
return widgetApp;
|
|
725
|
+
}
|
|
726
|
+
function initializeFromElement(element) {
|
|
727
|
+
if (!element || element.dataset.coreAiChatWidgetInitialized === "true") return element ? element.__coreAIChatWidgetApp || null : null;
|
|
728
|
+
var jsonOptions = parseJsonAttribute(element, "data-coreai-chat-widget-config", "CoreAI chat widget config");
|
|
729
|
+
var attributeOptions = buildOptionsFromDataAttributes(element);
|
|
730
|
+
if (!jsonOptions && !attributeOptions) return null;
|
|
731
|
+
var widgetApp = initialize(Object.assign({}, jsonOptions || {}, attributeOptions || {}));
|
|
732
|
+
if (!widgetApp) return null;
|
|
733
|
+
element.dataset.coreAiChatWidgetInitialized = "true";
|
|
734
|
+
element.__coreAIChatWidgetApp = widgetApp;
|
|
735
|
+
return widgetApp;
|
|
736
|
+
}
|
|
737
|
+
function scanForAutoInitialization(root) {
|
|
738
|
+
if (!root || typeof root.querySelectorAll !== "function") return;
|
|
739
|
+
if (typeof root.matches === "function" && root.matches("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]")) initializeFromElement(root);
|
|
740
|
+
root.querySelectorAll("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]").forEach(initializeFromElement);
|
|
741
|
+
}
|
|
742
|
+
function startAutoInitialization() {
|
|
743
|
+
scanForAutoInitialization(document);
|
|
744
|
+
if (typeof MutationObserver === "undefined") return;
|
|
745
|
+
new MutationObserver(function(mutations) {
|
|
746
|
+
mutations.forEach(function(mutation) {
|
|
747
|
+
mutation.addedNodes.forEach(function(node) {
|
|
748
|
+
if (node && node.nodeType === 1) scanForAutoInitialization(node);
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
}).observe(document.body, {
|
|
752
|
+
childList: true,
|
|
753
|
+
subtree: true
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", startAutoInitialization, { once: true });
|
|
757
|
+
else startAutoInitialization();
|
|
758
|
+
return {
|
|
759
|
+
initialize,
|
|
760
|
+
initializeFromElement
|
|
761
|
+
};
|
|
762
|
+
}();
|
|
763
|
+
//#endregion
|
|
764
|
+
})();
|
|
967
765
|
//# sourceMappingURL=ai-chat-widget.js.map
|