@crestapps/ai-chat-ui 2.0.0-preview.197 → 2.0.0-preview.203

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.
@@ -432,7 +432,11 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
432
432
  // at the first one, so the sentence is torn into fragments and the commas between the markers are
433
433
  // left stranded on their own lines. Inline-block keeps the figure looking exactly the same while
434
434
  // remaining something a paragraph can legally contain.
435
- return "<span class=\"generated-image-container\">\n <img src=\"".concat(src, "\" alt=\"").concat(alt, "\" class=\"img-thumbnail\" style=\"max-width: ").concat(maxWidth, "px; height: auto;\" />\n <span class=\"mt-2 d-block\">\n <a href=\"").concat(src, "\" target=\"_blank\" download=\"").concat(alt, "\" title=\"").concat(defaultConfig.downloadImageTitle, "\" class=\"btn btn-sm btn-outline-secondary ai-download-image\">\n <i class=\"fa-solid fa-download\"></i>\n </a>\n </span>\n </span>");
435
+ // The download sits over the picture's lower corner rather than on a line of its own beneath it.
436
+ // A row of its own cost a band of vertical space under every figure, which a conversation full of
437
+ // them pays for once per figure. The link itself is unchanged -- same address, same download
438
+ // attribute, same behaviour -- only where it is drawn.
439
+ return "<span class=\"generated-image-container\">\n <img src=\"".concat(src, "\" alt=\"").concat(alt, "\" class=\"img-thumbnail\" style=\"max-width: ").concat(maxWidth, "px; height: auto;\" />\n <a href=\"").concat(src, "\" target=\"_blank\" download=\"").concat(alt, "\" title=\"").concat(defaultConfig.downloadImageTitle, "\" class=\"btn btn-sm btn-outline-secondary ai-download-image\">\n <i class=\"fa-solid fa-download\"></i>\n </a>\n </span>");
436
440
  };
437
441
 
438
442
  // Chart counter for unique IDs
@@ -505,14 +509,50 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
505
509
  // Deferred for the same reason the charts below are: the render that produced these elements has
506
510
  // not necessarily been flushed to the DOM when this runs.
507
511
  requestAnimationFrame(wireBrokenImageHandlers);
512
+ requestAnimationFrame(wireImageZoom);
508
513
  }
509
- function wireBrokenImageHandlers() {
510
- var images = document.querySelectorAll('.generated-image-container img:not([data-broken-wired])');
514
+
515
+ // A picture arrives after the markdown is handed back -- the view writes it, and a streamed answer
516
+ // rewrites it on every chunk -- so zooming cannot be attached once at load. It is attached on the same
517
+ // pass as the broken-image handler above, and the attribute marks a picture already attached so a
518
+ // re-render does not bind it a second time.
519
+ function wireImageZoom() {
520
+ // The library is the host's to load. Without it the picture is still shown and still downloadable;
521
+ // only the enlarging is missing, so this is not worth failing a render over.
522
+ if (typeof mediumZoom !== 'function') {
523
+ return;
524
+ }
525
+ var images = document.querySelectorAll('.generated-image-container img:not([data-zoom-wired])');
526
+ if (images.length === 0) {
527
+ return;
528
+ }
511
529
  var _iterator6 = _createForOfIteratorHelper(images),
512
530
  _step6;
513
531
  try {
514
- var _loop = function _loop() {
532
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
515
533
  var image = _step6.value;
534
+ image.setAttribute('data-zoom-wired', 'true');
535
+ }
536
+ } catch (err) {
537
+ _iterator6.e(err);
538
+ } finally {
539
+ _iterator6.f();
540
+ }
541
+ mediumZoom(images, {
542
+ // The drawing is bounded by the window rather than by this margin, so the margin is kept
543
+ // small: an ingested figure is read detail by detail, and every pixel given away here comes
544
+ // off the size it is read at.
545
+ margin: 16,
546
+ background: 'rgba(15, 15, 15, 0.92)'
547
+ });
548
+ }
549
+ function wireBrokenImageHandlers() {
550
+ var images = document.querySelectorAll('.generated-image-container img:not([data-broken-wired])');
551
+ var _iterator7 = _createForOfIteratorHelper(images),
552
+ _step7;
553
+ try {
554
+ var _loop = function _loop() {
555
+ var image = _step7.value;
516
556
  image.setAttribute('data-broken-wired', 'true');
517
557
  image.addEventListener('error', function () {
518
558
  var container = image.closest('.generated-image-container');
@@ -529,13 +569,13 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
529
569
  once: true
530
570
  });
531
571
  };
532
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
572
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
533
573
  _loop();
534
574
  }
535
575
  } catch (err) {
536
- _iterator6.e(err);
576
+ _iterator7.e(err);
537
577
  } finally {
538
- _iterator6.f();
578
+ _iterator7.f();
539
579
  }
540
580
  }
541
581
  function renderMessageMedia(message) {
@@ -551,11 +591,11 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
551
591
  // Defer to requestAnimationFrame so the browser has fully laid out the
552
592
  // canvas elements before Chart.js reads their dimensions.
553
593
  requestAnimationFrame(function () {
554
- var _iterator7 = _createForOfIteratorHelper(charts),
555
- _step7;
594
+ var _iterator8 = _createForOfIteratorHelper(charts),
595
+ _step8;
556
596
  try {
557
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
558
- var c = _step7.value;
597
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
598
+ var c = _step8.value;
559
599
  var canvas = document.getElementById(c.chartId);
560
600
  if (!canvas) {
561
601
  continue;
@@ -588,9 +628,9 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
588
628
  }
589
629
  }
590
630
  } catch (err) {
591
- _iterator7.e(err);
631
+ _iterator8.e(err);
592
632
  } finally {
593
- _iterator7.f();
633
+ _iterator8.f();
594
634
  }
595
635
  });
596
636
  }
@@ -1405,18 +1445,18 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
1405
1445
  }, 0);
1406
1446
  var combined = new Uint8Array(totalLength);
1407
1447
  var offset = 0;
1408
- var _iterator8 = _createForOfIteratorHelper(this.audioChunks),
1409
- _step8;
1448
+ var _iterator9 = _createForOfIteratorHelper(this.audioChunks),
1449
+ _step9;
1410
1450
  try {
1411
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1412
- var chunk = _step8.value;
1451
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1452
+ var chunk = _step9.value;
1413
1453
  combined.set(chunk, offset);
1414
1454
  offset += chunk.length;
1415
1455
  }
1416
1456
  } catch (err) {
1417
- _iterator8.e(err);
1457
+ _iterator9.e(err);
1418
1458
  } finally {
1419
- _iterator8.f();
1459
+ _iterator9.f();
1420
1460
  }
1421
1461
  this.audioChunks = [];
1422
1462
  var blob = new Blob([combined], {
@@ -2328,7 +2368,7 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
2328
2368
  }
2329
2369
  function _loadVoices() {
2330
2370
  _loadVoices = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
2331
- var deploymentName, realtime, response, contentType, result, grouped, _iterator9, _step9, voice, groupName, _t2;
2371
+ var deploymentName, realtime, response, contentType, result, grouped, _iterator0, _step0, voice, groupName, _t2;
2332
2372
  return _regenerator().w(function (_context4) {
2333
2373
  while (1) switch (_context4.p = _context4.n) {
2334
2374
  case 0:
@@ -2376,10 +2416,10 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
2376
2416
  return _context4.a(2);
2377
2417
  case 6:
2378
2418
  grouped = new Map();
2379
- _iterator9 = _createForOfIteratorHelper(result.voices);
2419
+ _iterator0 = _createForOfIteratorHelper(result.voices);
2380
2420
  try {
2381
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
2382
- voice = _step9.value;
2421
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
2422
+ voice = _step0.value;
2383
2423
  groupName = voice.gender || 'Voices';
2384
2424
  if (!grouped.has(groupName)) {
2385
2425
  grouped.set(groupName, []);
@@ -2387,9 +2427,9 @@ window.chatInteractionManager = function (_window$CoreAIChatMar, _window$CoreAIC
2387
2427
  grouped.get(groupName).push(voice);
2388
2428
  }
2389
2429
  } catch (err) {
2390
- _iterator9.e(err);
2430
+ _iterator0.e(err);
2391
2431
  } finally {
2392
- _iterator9.f();
2432
+ _iterator0.f();
2393
2433
  }
2394
2434
  Array.from(grouped.keys()).sort(function (a, b) {
2395
2435
  return a.localeCompare(b);