@a.izzuddin/ai-chat 0.2.25 → 0.2.27-beta.1

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.mjs CHANGED
@@ -5371,7 +5371,7 @@ MarkdownIt.prototype.renderInline = function(src, env) {
5371
5371
  var lib_default = MarkdownIt;
5372
5372
 
5373
5373
  // src/components/ai-chat.ts
5374
- console.log("Chatbot Ver = 0.2.24-beta.0");
5374
+ console.log("Chatbot Ver = 0.2.27-beta.1");
5375
5375
  var md = new lib_default({
5376
5376
  html: false,
5377
5377
  // Disable HTML tags in source for security
@@ -5383,6 +5383,13 @@ var md = new lib_default({
5383
5383
  var AIChat = class extends LitElement {
5384
5384
  constructor() {
5385
5385
  super();
5386
+ this._viewportResizeHandler = () => {
5387
+ const vv = window.visualViewport;
5388
+ if (vv) {
5389
+ this.style.setProperty("--viewport-height", `${vv.height}px`);
5390
+ this.style.setProperty("--viewport-offset-top", `${vv.offsetTop}px`);
5391
+ }
5392
+ };
5386
5393
  this.apiUrl = "";
5387
5394
  this.sessionId = "default-session";
5388
5395
  this.chatTitle = "My AI Agent";
@@ -5526,6 +5533,11 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5526
5533
  }
5527
5534
  async connectedCallback() {
5528
5535
  super.connectedCallback();
5536
+ if (window.visualViewport) {
5537
+ window.visualViewport.addEventListener("resize", this._viewportResizeHandler);
5538
+ window.visualViewport.addEventListener("scroll", this._viewportResizeHandler);
5539
+ this._viewportResizeHandler();
5540
+ }
5529
5541
  const savedMessages = this.loadMessagesFromStorage();
5530
5542
  if (this.initialMessages && this.initialMessages.length > 0) {
5531
5543
  this.messages = [...this.initialMessages];
@@ -5596,6 +5608,13 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5596
5608
  }, 500);
5597
5609
  }
5598
5610
  }
5611
+ disconnectedCallback() {
5612
+ super.disconnectedCallback();
5613
+ if (window.visualViewport) {
5614
+ window.visualViewport.removeEventListener("resize", this._viewportResizeHandler);
5615
+ window.visualViewport.removeEventListener("scroll", this._viewportResizeHandler);
5616
+ }
5617
+ }
5599
5618
  updated(changedProperties) {
5600
5619
  super.updated(changedProperties);
5601
5620
  if (changedProperties.has("messages")) {
@@ -5789,7 +5808,8 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5789
5808
  id: (Date.now() + 1).toString(),
5790
5809
  role: "assistant",
5791
5810
  content: responseText,
5792
- suggestedQuestions
5811
+ suggestedQuestions,
5812
+ language: this.language
5793
5813
  };
5794
5814
  this.messages = [...this.messages, assistantMessage];
5795
5815
  this.clearPendingRequest();
@@ -5938,7 +5958,8 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5938
5958
  content: responseText,
5939
5959
  faqs,
5940
5960
  suggestedQuestions,
5941
- confidence
5961
+ confidence,
5962
+ language: this.language
5942
5963
  };
5943
5964
  this.messages = [...this.messages, assistantMessage];
5944
5965
  this.clearPendingRequest();
@@ -6025,7 +6046,8 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
6025
6046
  id: (Date.now() + 1).toString(),
6026
6047
  role: "assistant",
6027
6048
  content: responseText,
6028
- suggestedQuestions
6049
+ suggestedQuestions,
6050
+ language: this.language
6029
6051
  };
6030
6052
  this.messages = [...this.messages, assistantMessage];
6031
6053
  this.clearPendingRequest();
@@ -6194,7 +6216,8 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
6194
6216
  content: responseText,
6195
6217
  faqs,
6196
6218
  suggestedQuestions,
6197
- confidence
6219
+ confidence,
6220
+ language: this.language
6198
6221
  };
6199
6222
  this.messages = [...this.messages, assistantMessage];
6200
6223
  this.clearPendingRequest();
@@ -6226,6 +6249,13 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
6226
6249
  <!-- Header -->
6227
6250
  <div class="header" style="--primary-color: ${this.primaryColor}; --primary-color-light: ${primaryColorLight}; --primary-color-hover: ${this.primaryColorHover};">
6228
6251
  <div class="header-content">
6252
+ ${this.mode === "widget" ? html`
6253
+ <button class="header-back-button" @click=${this.toggleWidget} aria-label="Back">
6254
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
6255
+ <polyline points="15 18 9 12 15 6"></polyline>
6256
+ </svg>
6257
+ </button>
6258
+ ` : ""}
6229
6259
  <div class="header-avatar">
6230
6260
  ${this.botAvatarUrl ? html`<img src="${this.botAvatarUrl}" alt="Bot" class="header-avatar-image" />` : html`<svg viewBox="0 0 24 24" fill="none" stroke="${this.primaryColor}" stroke-width="2" style="width: 1.5rem; height: 1.5rem;">
6231
6261
  <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
@@ -6276,7 +6306,7 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
6276
6306
  ` : ""}
6277
6307
  ${msg.role === "assistant" && msg.suggestedQuestions && msg.suggestedQuestions.length > 0 ? html`
6278
6308
  <div class="faq-section">
6279
- <p class="faq-title">${this.language === "ms" || this.language === "my" ? "Cadangan Soalan:" : "Suggested Questions:"}</p>
6309
+ <p class="faq-title">${msg.language === "ms" || msg.language === "my" ? "Cadangan Soalan:" : "Suggested Questions:"}</p>
6280
6310
  <ul class="faq-list">
6281
6311
  ${msg.suggestedQuestions.map((question) => html`
6282
6312
  <li class="faq-item" @click=${(e) => this.handleFAQClick(question, e)}>
@@ -6368,14 +6398,18 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
6368
6398
  <button
6369
6399
  class=${classMap({
6370
6400
  "widget-button": true,
6371
- "widget-button-no-bg": !!this.widgetIconUrl,
6372
- "widget-button-hidden": this.isOpen
6401
+ "widget-button-no-bg": !this.isOpen && !!this.widgetIconUrl,
6402
+ "widget-button-close": this.isOpen
6373
6403
  })}
6374
6404
  style="--primary-color: ${this.primaryColor}; --primary-color-light: ${primaryColorLight};"
6375
6405
  @click=${this.toggleWidget}
6376
6406
  aria-label=${this.isOpen ? "Close chat" : "Open chat"}
6377
6407
  >
6378
- ${this.widgetIconUrl ? html`
6408
+ ${this.isOpen ? html`
6409
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
6410
+ <polyline points="6 9 12 15 18 9"></polyline>
6411
+ </svg>
6412
+ ` : this.widgetIconUrl ? html`
6379
6413
  <img src="${this.widgetIconUrl}" alt="Chat" class="widget-button-icon" />
6380
6414
  ` : html`
6381
6415
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -6400,6 +6434,7 @@ AIChat.styles = css`
6400
6434
  display: flex;
6401
6435
  flex-direction: column;
6402
6436
  height: 100vh;
6437
+ height: var(--viewport-height, 100dvh);
6403
6438
  background: #ffffff;
6404
6439
  }
6405
6440
 
@@ -6451,8 +6486,19 @@ AIChat.styles = css`
6451
6486
  transform: scale(1.1);
6452
6487
  }
6453
6488
 
6454
- .widget-button-hidden {
6455
- display: none;
6489
+ .widget-button-close {
6490
+ background: var(--primary-color, #3681D3);
6491
+ box-shadow: 0 4px 16px rgba(54, 129, 211, 0.3);
6492
+ }
6493
+
6494
+ .widget-button-close:hover {
6495
+ background: var(--primary-color, #3681D3);
6496
+ box-shadow: 0 6px 20px rgba(54, 129, 211, 0.4);
6497
+ transform: scale(1.05);
6498
+ }
6499
+
6500
+ .widget-button-close svg {
6501
+ color: #ffffff;
6456
6502
  }
6457
6503
 
6458
6504
  .widget-speech-bubble {
@@ -6503,7 +6549,7 @@ AIChat.styles = css`
6503
6549
 
6504
6550
  .widget-window {
6505
6551
  position: absolute;
6506
- bottom: 0;
6552
+ bottom: 90px;
6507
6553
  right: 0;
6508
6554
  width: var(--widget-width, 380px);
6509
6555
  height: var(--widget-height, 600px);
@@ -6549,10 +6595,14 @@ AIChat.styles = css`
6549
6595
  /* Mobile portrait */
6550
6596
  @media (max-width: 480px) and (orientation: portrait) {
6551
6597
  .widget-window {
6552
- width: calc(100vw - 40px);
6553
- height: 70vh;
6554
- bottom: 0;
6598
+ position: fixed;
6599
+ top: var(--viewport-offset-top, 0px);
6600
+ left: 0;
6555
6601
  right: 0;
6602
+ width: 100vw;
6603
+ height: 100vh;
6604
+ height: var(--viewport-height, 100dvh);
6605
+ border-radius: 0;
6556
6606
  }
6557
6607
 
6558
6608
  .widget-button {
@@ -6569,10 +6619,14 @@ AIChat.styles = css`
6569
6619
  /* Mobile landscape */
6570
6620
  @media (max-width: 900px) and (orientation: landscape) {
6571
6621
  .widget-window {
6572
- width: var(--widget-width, 500px);
6573
- height: calc(100vh - 100px);
6574
- bottom: 0;
6622
+ position: fixed;
6623
+ top: var(--viewport-offset-top, 0px);
6624
+ left: 0;
6575
6625
  right: 0;
6626
+ width: 100vw;
6627
+ height: 100vh;
6628
+ height: var(--viewport-height, 100dvh);
6629
+ border-radius: 0;
6576
6630
  }
6577
6631
 
6578
6632
  .widget-button {
@@ -6833,6 +6887,41 @@ AIChat.styles = css`
6833
6887
  height: 1.25rem;
6834
6888
  }
6835
6889
 
6890
+ .header-back-button {
6891
+ display: none;
6892
+ background: none;
6893
+ border: none;
6894
+ cursor: pointer;
6895
+ color: #fff;
6896
+ padding: 0.3rem;
6897
+ align-items: center;
6898
+ justify-content: center;
6899
+ border-radius: 50%;
6900
+ transition: background 0.2s;
6901
+ flex-shrink: 0;
6902
+ }
6903
+
6904
+ .header-back-button:hover {
6905
+ background: rgba(255, 255, 255, 0.2);
6906
+ }
6907
+
6908
+ .header-back-button svg {
6909
+ width: 1.25rem;
6910
+ height: 1.25rem;
6911
+ }
6912
+
6913
+ @media (max-width: 480px) {
6914
+ .header-back-button {
6915
+ display: flex;
6916
+ }
6917
+ }
6918
+
6919
+ @media (max-width: 900px) and (orientation: landscape) {
6920
+ .header-back-button {
6921
+ display: flex;
6922
+ }
6923
+ }
6924
+
6836
6925
  .messages-area {
6837
6926
  flex: 1;
6838
6927
  overflow-y: auto;