@buni.ai/chatbot-angular 1.0.25 → 1.0.27

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
@@ -303,7 +303,7 @@ class BuniChatWidget {
303
303
  };
304
304
  // Listen for trigger and connection events
305
305
  window.addEventListener("message", (event) => {
306
- var _a, _b, _c, _d, _e, _f;
306
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
307
307
  const payload = event.data;
308
308
  if (!payload || typeof payload !== "object")
309
309
  return;
@@ -315,26 +315,35 @@ class BuniChatWidget {
315
315
  if (event.source === ((_a = this.chatIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
316
316
  event.origin === this.getBaseUrl()) {
317
317
  this.syncServerBehaviorFromData(payload.data);
318
- // Connection is ready, show the trigger button
319
- if (container && !config.hideDefaultTrigger) {
318
+ const effectiveDefaultMode = (_d = (_c = (_b = this.options.config) === null || _b === void 0 ? void 0 : _b.defaultMode) !== null && _c !== void 0 ? _c : this.serverBehavior.defaultMode) !== null && _d !== void 0 ? _d : "full";
319
+ const effectiveMinimalEnabled = this.isMinimalModeEnabled();
320
+ if (effectiveMinimalEnabled && effectiveDefaultMode === "minimal") {
321
+ // Auto-open in minimal card mode
322
+ void this.openChatInMinimalMode();
323
+ }
324
+ else if ((_e = this.options.config) === null || _e === void 0 ? void 0 : _e.autoOpen) {
325
+ void this.openChat();
326
+ }
327
+ else if (container && !config.hideDefaultTrigger) {
328
+ // Show the trigger button
320
329
  container.style.display = "block";
321
330
  }
322
331
  // Emit connection_ready event for consumers
323
332
  this.emit("connection_ready", {
324
333
  timestamp: Date.now(),
325
- behavior: (_b = payload.data) === null || _b === void 0 ? void 0 : _b.behavior,
334
+ behavior: (_f = payload.data) === null || _f === void 0 ? void 0 : _f.behavior,
326
335
  });
327
336
  if (this.options.onConnectionReady &&
328
337
  typeof this.options.onConnectionReady === "function") {
329
338
  this.options.onConnectionReady({
330
339
  timestamp: Date.now(),
331
- behavior: (_c = payload.data) === null || _c === void 0 ? void 0 : _c.behavior,
340
+ behavior: (_g = payload.data) === null || _g === void 0 ? void 0 : _g.behavior,
332
341
  });
333
342
  }
334
343
  }
335
344
  break;
336
345
  case "chatbot:close":
337
- if (event.source === ((_d = this.chatIframe) === null || _d === void 0 ? void 0 : _d.contentWindow) &&
346
+ if (event.source === ((_h = this.chatIframe) === null || _h === void 0 ? void 0 : _h.contentWindow) &&
338
347
  event.origin === this.getBaseUrl()) {
339
348
  this.closeChat();
340
349
  this.displayMode = "hidden";
@@ -342,7 +351,7 @@ class BuniChatWidget {
342
351
  }
343
352
  break;
344
353
  case "chatbot:minimize":
345
- if (event.source === ((_e = this.chatIframe) === null || _e === void 0 ? void 0 : _e.contentWindow) &&
354
+ if (event.source === ((_j = this.chatIframe) === null || _j === void 0 ? void 0 : _j.contentWindow) &&
346
355
  event.origin === this.getBaseUrl()) {
347
356
  if (this.isMinimalModeEnabled()) {
348
357
  if (!this.state.isOpen) {
@@ -360,7 +369,7 @@ class BuniChatWidget {
360
369
  }
361
370
  break;
362
371
  case "trigger_clicked":
363
- if (event.source === ((_f = this.triggerIframe) === null || _f === void 0 ? void 0 : _f.contentWindow) &&
372
+ if (event.source === ((_k = this.triggerIframe) === null || _k === void 0 ? void 0 : _k.contentWindow) &&
364
373
  event.origin === window.location.origin) {
365
374
  this.openChat();
366
375
  }
@@ -500,11 +509,65 @@ class BuniChatWidget {
500
509
  </body>
501
510
  </html>`;
502
511
  }
512
+ async openChatInMinimalMode() {
513
+ if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
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)
541
+ this.widgetElement.style.cssText = `
542
+ position: fixed;
543
+ pointer-events: none;
544
+ z-index: 999999;
545
+ width: ${chatWidth};
546
+ height: ${chatHeight};
547
+ ${isMobile ? "max-width: 100vw; max-height: 100vh;" : ""}
548
+ transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
549
+ ${this.getPositionStyles(config.position || "bottom-right", false)}
550
+ display: block;
551
+ overflow: visible;
552
+ box-sizing: border-box;
553
+ `;
554
+ // Hide trigger, show chat iframe
555
+ this.triggerIframe.style.display = "none";
556
+ this.chatIframe.style.display = "block";
557
+ 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() });
565
+ }
503
566
  async openChat() {
504
567
  if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
505
568
  return;
506
- if (this.state.isOpen)
507
- return; // Already open
569
+ if (this.state.isOpen && this.displayMode !== "minimal")
570
+ return; // Already open in full mode
508
571
  const config = this.options.config || {};
509
572
  const isMobile = window.innerWidth <= 768;
510
573
  const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
@@ -635,7 +698,7 @@ class BuniChatWidget {
635
698
  setupPostMessageAPI(iframe) {
636
699
  // Listen for messages from the iframe
637
700
  window.addEventListener("message", (event) => {
638
- var _a;
701
+ var _a, _b;
639
702
  if (event.source !== iframe.contentWindow) {
640
703
  return;
641
704
  }
@@ -680,11 +743,32 @@ class BuniChatWidget {
680
743
  case "minimized":
681
744
  this.syncServerBehaviorFromData(data);
682
745
  if (this.isMinimalModeEnabled()) {
683
- if (!this.state.isOpen) {
684
- void this.openChat();
685
- }
686
746
  this.displayMode = "minimal";
687
747
  this.state.displayMode = "minimal";
748
+ this.state.isOpen = true;
749
+ 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
+ }
688
772
  }
689
773
  else {
690
774
  // Backward-compatible behavior.
@@ -694,7 +778,7 @@ class BuniChatWidget {
694
778
  case "new_unread_message":
695
779
  // Update unread count in trigger
696
780
  this.state.unreadCount++;
697
- if ((_a = this.triggerIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) {
781
+ if ((_b = this.triggerIframe) === null || _b === void 0 ? void 0 : _b.contentWindow) {
698
782
  this.triggerIframe.contentWindow.postMessage({ type: "updateUnreadCount", count: this.state.unreadCount }, window.location.origin);
699
783
  }
700
784
  break;