@buni.ai/chatbot-angular 1.0.27 → 1.0.28

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/index.esm.js CHANGED
@@ -354,12 +354,12 @@ class BuniChatWidget {
354
354
  if (event.source === ((_j = this.chatIframe) === null || _j === void 0 ? void 0 : _j.contentWindow) &&
355
355
  event.origin === this.getBaseUrl()) {
356
356
  if (this.isMinimalModeEnabled()) {
357
- if (!this.state.isOpen) {
358
- void this.openChat();
359
- }
360
357
  this.postMessageToWidget("minimize");
358
+ this.applyMinimalContainerFrame();
361
359
  this.displayMode = "minimal";
362
360
  this.state.displayMode = "minimal";
361
+ this.state.isOpen = true;
362
+ this.state.isMinimized = false;
363
363
  }
364
364
  else {
365
365
  this.closeChat();
@@ -512,56 +512,41 @@ class BuniChatWidget {
512
512
  async openChatInMinimalMode() {
513
513
  if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
514
514
  return;
515
- const config = this.options.config || {};
516
- const isMobile = window.innerWidth <= 768;
517
- const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
518
- const ensureUnits = (value, defaultValue) => {
519
- if (!value)
520
- return defaultValue;
521
- const str = String(value);
522
- if (str.match(/^[\d.]+\s*(px|em|rem|%|vh|vw)$/))
523
- return str;
524
- if (str.match(/^[\d.]+$/))
525
- return `${str}px`;
526
- return str;
527
- };
528
- const widthValue = ensureUnits(config.width, "350px");
529
- const heightValue = ensureUnits(config.height, "650px");
530
- const chatWidth = isMobile
531
- ? "100vw"
532
- : isTablet
533
- ? "min(calc(100vw - 3rem), 370px)"
534
- : widthValue;
535
- const chatHeight = isMobile
536
- ? "100vh"
537
- : isTablet
538
- ? "min(calc(100vh - 3rem), 620px)"
539
- : heightValue;
540
- // Size container to full chat dimensions initially (iframe needs space to render)
515
+ this.applyMinimalContainerFrame();
516
+ this.state.isMinimized = false;
517
+ this.state.isOpen = true;
518
+ this.displayMode = "minimal";
519
+ this.state.displayMode = "minimal";
520
+ // Ask the iframe to enter minimal mode; it will reply with "minimized" when ready
521
+ this.postMessageToWidget("minimize");
522
+ this.emit("minimized", { timestamp: Date.now() });
523
+ }
524
+ applyMinimalContainerFrame() {
525
+ var _a;
526
+ if (!this.widgetElement || !this.chatIframe || !this.triggerIframe)
527
+ return;
528
+ const position = ((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.position) || "bottom-right";
541
529
  this.widgetElement.style.cssText = `
542
530
  position: fixed;
543
531
  pointer-events: none;
544
532
  z-index: 999999;
545
- width: ${chatWidth};
546
- height: ${chatHeight};
547
- ${isMobile ? "max-width: 100vw; max-height: 100vh;" : ""}
533
+ width: min(calc(100vw - 1.5rem), 390px);
534
+ max-width: min(calc(100vw - 1.5rem), 390px);
535
+ height: auto;
536
+ max-height: none;
537
+ min-height: 0;
548
538
  transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
549
- ${this.getPositionStyles(config.position || "bottom-right", false)}
539
+ ${this.getPositionStyles(position, true)}
550
540
  display: block;
551
541
  overflow: visible;
552
542
  box-sizing: border-box;
553
543
  `;
554
- // Hide trigger, show chat iframe
555
544
  this.triggerIframe.style.display = "none";
556
545
  this.chatIframe.style.display = "block";
557
546
  this.chatIframe.style.visibility = "visible";
558
- this.state.isMinimized = false;
559
- this.state.isOpen = true;
560
- this.displayMode = "minimal";
561
- this.state.displayMode = "minimal";
562
- // Ask the iframe to enter minimal mode; it will reply with "minimized" when ready
563
- this.postMessageToWidget("minimize");
564
- this.emit("minimized", { timestamp: Date.now() });
547
+ this.chatIframe.style.width = "100%";
548
+ this.chatIframe.style.height = "min(calc(100vh - 1.5rem), 520px)";
549
+ this.chatIframe.style.maxHeight = "min(calc(100vh - 1.5rem), 520px)";
565
550
  }
566
551
  async openChat() {
567
552
  if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
@@ -698,7 +683,7 @@ class BuniChatWidget {
698
683
  setupPostMessageAPI(iframe) {
699
684
  // Listen for messages from the iframe
700
685
  window.addEventListener("message", (event) => {
701
- var _a, _b;
686
+ var _a;
702
687
  if (event.source !== iframe.contentWindow) {
703
688
  return;
704
689
  }
@@ -747,28 +732,7 @@ class BuniChatWidget {
747
732
  this.state.displayMode = "minimal";
748
733
  this.state.isOpen = true;
749
734
  this.state.isMinimized = false;
750
- // Apply a full minimal-mode frame update to avoid stale full-mode sizing/position.
751
- if (this.widgetElement && this.chatIframe && this.triggerIframe) {
752
- const position = ((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.position) || "bottom-right";
753
- this.widgetElement.style.cssText = `
754
- position: fixed;
755
- pointer-events: none;
756
- z-index: 999999;
757
- width: min(calc(100vw - 1.5rem), 390px);
758
- max-width: min(calc(100vw - 1.5rem), 390px);
759
- height: auto;
760
- transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
761
- ${this.getPositionStyles(position, true)}
762
- display: block;
763
- overflow: visible;
764
- box-sizing: border-box;
765
- `;
766
- this.triggerIframe.style.display = "none";
767
- this.chatIframe.style.display = "block";
768
- this.chatIframe.style.visibility = "visible";
769
- this.chatIframe.style.width = "100%";
770
- this.chatIframe.style.height = "min(calc(100vh - 1.5rem), 520px)";
771
- }
735
+ this.applyMinimalContainerFrame();
772
736
  }
773
737
  else {
774
738
  // Backward-compatible behavior.
@@ -778,7 +742,7 @@ class BuniChatWidget {
778
742
  case "new_unread_message":
779
743
  // Update unread count in trigger
780
744
  this.state.unreadCount++;
781
- if ((_b = this.triggerIframe) === null || _b === void 0 ? void 0 : _b.contentWindow) {
745
+ if ((_a = this.triggerIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) {
782
746
  this.triggerIframe.contentWindow.postMessage({ type: "updateUnreadCount", count: this.state.unreadCount }, window.location.origin);
783
747
  }
784
748
  break;