@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.js CHANGED
@@ -305,7 +305,7 @@ class BuniChatWidget {
305
305
  };
306
306
  // Listen for trigger and connection events
307
307
  window.addEventListener("message", (event) => {
308
- var _a, _b, _c, _d, _e, _f;
308
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
309
309
  const payload = event.data;
310
310
  if (!payload || typeof payload !== "object")
311
311
  return;
@@ -317,26 +317,35 @@ class BuniChatWidget {
317
317
  if (event.source === ((_a = this.chatIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
318
318
  event.origin === this.getBaseUrl()) {
319
319
  this.syncServerBehaviorFromData(payload.data);
320
- // Connection is ready, show the trigger button
321
- if (container && !config.hideDefaultTrigger) {
320
+ 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";
321
+ const effectiveMinimalEnabled = this.isMinimalModeEnabled();
322
+ if (effectiveMinimalEnabled && effectiveDefaultMode === "minimal") {
323
+ // Auto-open in minimal card mode
324
+ void this.openChatInMinimalMode();
325
+ }
326
+ else if ((_e = this.options.config) === null || _e === void 0 ? void 0 : _e.autoOpen) {
327
+ void this.openChat();
328
+ }
329
+ else if (container && !config.hideDefaultTrigger) {
330
+ // Show the trigger button
322
331
  container.style.display = "block";
323
332
  }
324
333
  // Emit connection_ready event for consumers
325
334
  this.emit("connection_ready", {
326
335
  timestamp: Date.now(),
327
- behavior: (_b = payload.data) === null || _b === void 0 ? void 0 : _b.behavior,
336
+ behavior: (_f = payload.data) === null || _f === void 0 ? void 0 : _f.behavior,
328
337
  });
329
338
  if (this.options.onConnectionReady &&
330
339
  typeof this.options.onConnectionReady === "function") {
331
340
  this.options.onConnectionReady({
332
341
  timestamp: Date.now(),
333
- behavior: (_c = payload.data) === null || _c === void 0 ? void 0 : _c.behavior,
342
+ behavior: (_g = payload.data) === null || _g === void 0 ? void 0 : _g.behavior,
334
343
  });
335
344
  }
336
345
  }
337
346
  break;
338
347
  case "chatbot:close":
339
- if (event.source === ((_d = this.chatIframe) === null || _d === void 0 ? void 0 : _d.contentWindow) &&
348
+ if (event.source === ((_h = this.chatIframe) === null || _h === void 0 ? void 0 : _h.contentWindow) &&
340
349
  event.origin === this.getBaseUrl()) {
341
350
  this.closeChat();
342
351
  this.displayMode = "hidden";
@@ -344,7 +353,7 @@ class BuniChatWidget {
344
353
  }
345
354
  break;
346
355
  case "chatbot:minimize":
347
- if (event.source === ((_e = this.chatIframe) === null || _e === void 0 ? void 0 : _e.contentWindow) &&
356
+ if (event.source === ((_j = this.chatIframe) === null || _j === void 0 ? void 0 : _j.contentWindow) &&
348
357
  event.origin === this.getBaseUrl()) {
349
358
  if (this.isMinimalModeEnabled()) {
350
359
  if (!this.state.isOpen) {
@@ -362,7 +371,7 @@ class BuniChatWidget {
362
371
  }
363
372
  break;
364
373
  case "trigger_clicked":
365
- if (event.source === ((_f = this.triggerIframe) === null || _f === void 0 ? void 0 : _f.contentWindow) &&
374
+ if (event.source === ((_k = this.triggerIframe) === null || _k === void 0 ? void 0 : _k.contentWindow) &&
366
375
  event.origin === window.location.origin) {
367
376
  this.openChat();
368
377
  }
@@ -502,11 +511,65 @@ class BuniChatWidget {
502
511
  </body>
503
512
  </html>`;
504
513
  }
514
+ async openChatInMinimalMode() {
515
+ if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
516
+ return;
517
+ const config = this.options.config || {};
518
+ const isMobile = window.innerWidth <= 768;
519
+ const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
520
+ const ensureUnits = (value, defaultValue) => {
521
+ if (!value)
522
+ return defaultValue;
523
+ const str = String(value);
524
+ if (str.match(/^[\d.]+\s*(px|em|rem|%|vh|vw)$/))
525
+ return str;
526
+ if (str.match(/^[\d.]+$/))
527
+ return `${str}px`;
528
+ return str;
529
+ };
530
+ const widthValue = ensureUnits(config.width, "350px");
531
+ const heightValue = ensureUnits(config.height, "650px");
532
+ const chatWidth = isMobile
533
+ ? "100vw"
534
+ : isTablet
535
+ ? "min(calc(100vw - 3rem), 370px)"
536
+ : widthValue;
537
+ const chatHeight = isMobile
538
+ ? "100vh"
539
+ : isTablet
540
+ ? "min(calc(100vh - 3rem), 620px)"
541
+ : heightValue;
542
+ // Size container to full chat dimensions initially (iframe needs space to render)
543
+ this.widgetElement.style.cssText = `
544
+ position: fixed;
545
+ pointer-events: none;
546
+ z-index: 999999;
547
+ width: ${chatWidth};
548
+ height: ${chatHeight};
549
+ ${isMobile ? "max-width: 100vw; max-height: 100vh;" : ""}
550
+ transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
551
+ ${this.getPositionStyles(config.position || "bottom-right", false)}
552
+ display: block;
553
+ overflow: visible;
554
+ box-sizing: border-box;
555
+ `;
556
+ // Hide trigger, show chat iframe
557
+ this.triggerIframe.style.display = "none";
558
+ this.chatIframe.style.display = "block";
559
+ this.chatIframe.style.visibility = "visible";
560
+ this.state.isMinimized = false;
561
+ this.state.isOpen = true;
562
+ this.displayMode = "minimal";
563
+ this.state.displayMode = "minimal";
564
+ // Ask the iframe to enter minimal mode; it will reply with "minimized" when ready
565
+ this.postMessageToWidget("minimize");
566
+ this.emit("minimized", { timestamp: Date.now() });
567
+ }
505
568
  async openChat() {
506
569
  if (!this.chatIframe || !this.widgetElement || !this.triggerIframe)
507
570
  return;
508
- if (this.state.isOpen)
509
- return; // Already open
571
+ if (this.state.isOpen && this.displayMode !== "minimal")
572
+ return; // Already open in full mode
510
573
  const config = this.options.config || {};
511
574
  const isMobile = window.innerWidth <= 768;
512
575
  const isTablet = window.innerWidth > 768 && window.innerWidth <= 1024;
@@ -637,7 +700,7 @@ class BuniChatWidget {
637
700
  setupPostMessageAPI(iframe) {
638
701
  // Listen for messages from the iframe
639
702
  window.addEventListener("message", (event) => {
640
- var _a;
703
+ var _a, _b;
641
704
  if (event.source !== iframe.contentWindow) {
642
705
  return;
643
706
  }
@@ -682,11 +745,32 @@ class BuniChatWidget {
682
745
  case "minimized":
683
746
  this.syncServerBehaviorFromData(data);
684
747
  if (this.isMinimalModeEnabled()) {
685
- if (!this.state.isOpen) {
686
- void this.openChat();
687
- }
688
748
  this.displayMode = "minimal";
689
749
  this.state.displayMode = "minimal";
750
+ this.state.isOpen = true;
751
+ this.state.isMinimized = false;
752
+ // Apply a full minimal-mode frame update to avoid stale full-mode sizing/position.
753
+ if (this.widgetElement && this.chatIframe && this.triggerIframe) {
754
+ const position = ((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.position) || "bottom-right";
755
+ this.widgetElement.style.cssText = `
756
+ position: fixed;
757
+ pointer-events: none;
758
+ z-index: 999999;
759
+ width: min(calc(100vw - 1.5rem), 390px);
760
+ max-width: min(calc(100vw - 1.5rem), 390px);
761
+ height: auto;
762
+ transition: width 0.3s ease, height 0.3s ease, border-radius 0.3s ease;
763
+ ${this.getPositionStyles(position, true)}
764
+ display: block;
765
+ overflow: visible;
766
+ box-sizing: border-box;
767
+ `;
768
+ this.triggerIframe.style.display = "none";
769
+ this.chatIframe.style.display = "block";
770
+ this.chatIframe.style.visibility = "visible";
771
+ this.chatIframe.style.width = "100%";
772
+ this.chatIframe.style.height = "min(calc(100vh - 1.5rem), 520px)";
773
+ }
690
774
  }
691
775
  else {
692
776
  // Backward-compatible behavior.
@@ -696,7 +780,7 @@ class BuniChatWidget {
696
780
  case "new_unread_message":
697
781
  // Update unread count in trigger
698
782
  this.state.unreadCount++;
699
- if ((_a = this.triggerIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) {
783
+ if ((_b = this.triggerIframe) === null || _b === void 0 ? void 0 : _b.contentWindow) {
700
784
  this.triggerIframe.contentWindow.postMessage({ type: "updateUnreadCount", count: this.state.unreadCount }, window.location.origin);
701
785
  }
702
786
  break;