@buni.ai/chatbot-angular 1.0.25 → 1.0.26

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;
@@ -685,6 +748,18 @@ class BuniChatWidget {
685
748
  }
686
749
  this.displayMode = "minimal";
687
750
  this.state.displayMode = "minimal";
751
+ // Shrink container to actual minimal card size
752
+ if (this.widgetElement && this.chatIframe) {
753
+ const isMobile = window.innerWidth <= 768;
754
+ if (!isMobile) {
755
+ this.widgetElement.style.width =
756
+ "min(calc(100vw - 1.5rem), 390px)";
757
+ this.widgetElement.style.height = "auto";
758
+ this.widgetElement.style.overflow = "visible";
759
+ this.chatIframe.style.height = "520px";
760
+ this.chatIframe.style.width = "100%";
761
+ }
762
+ }
688
763
  }
689
764
  else {
690
765
  // Backward-compatible behavior.