/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/hxy-ai-chat-lit@1.2.7/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var lit=require("lit"),marked=require("marked");function __decorate(t,e,o,s){var i,r=arguments.length,a=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,o,s);else for(var n=t.length-1;n>=0;n--)(i=t[n])&&(a=(r<3?i(a):r>3?i(e,o,a):i(e,o))||a);return r>3&&a&&Object.defineProperty(e,o,a),a}function __metadata(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const t$1=t=>(e,o)=>{void 0!==o?o.addInitializer((()=>{customElements.define(t,e)})):customElements.define(t,e)}
/**
 * @license
 * Copyright 2019 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */,t=globalThis,e$1=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),o$2=new WeakMap;let n$2=class{constructor(t,e,o){if(this._$cssResult$=!0,o!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(e$1&&void 0===t){const o=void 0!==e&&1===e.length;o&&(t=o$2.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),o&&o$2.set(e,t))}return t}toString(){return this.cssText}};const r$3=t=>new n$2("string"==typeof t?t:t+"",void 0,s),S=(e,o)=>{if(e$1)e.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const s of o){const o=document.createElement("style"),i=t.litNonce;void 0!==i&&o.setAttribute("nonce",i),o.textContent=s.cssText,e.appendChild(o)}},c$1=e$1?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const o of t.cssRules)e+=o.cssText;return r$3(e)})(t):t
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */,{is:i,defineProperty:e,getOwnPropertyDescriptor:h,getOwnPropertyNames:r$2,getOwnPropertySymbols:o$1,getPrototypeOf:n$1}=Object,a=globalThis,c=a.trustedTypes,l=c?c.emptyScript:"",p=a.reactiveElementPolyfillSupport,d=(t,e)=>t,u={toAttribute(t,e){switch(e){case Boolean:t=t?l:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let o=t;switch(e){case Boolean:o=null!==t;break;case Number:o=null===t?null:Number(t);break;case Object:case Array:try{o=JSON.parse(t)}catch(t){o=null}}return o}},f=(t,e)=>!i(t,e),b={attribute:!0,type:String,converter:u,reflect:!1,useDefault:!1,hasChanged:f};Symbol.metadata??=Symbol("metadata"),a.litPropertyMetadata??=new WeakMap;class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,o=b){if(o.state&&(o.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((o=Object.create(o)).wrapped=!0),this.elementProperties.set(t,o),!o.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,o);void 0!==i&&e(this.prototype,t,i)}}static getPropertyDescriptor(t,e,o){const{get:s,set:i}=h(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:s,set(e){const r=s?.call(this);i?.call(this,e),this.requestUpdate(t,r,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(d("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d("properties"))){const t=this.properties,e=[...r$2(t),...o$1(t)];for(const o of e)this.createProperty(o,t[o])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,o]of e)this.elementProperties.set(t,o)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const o=this._$Eu(t,e);void 0!==o&&this._$Eh.set(o,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const o=new Set(t.flat(1/0).reverse());for(const t of o)e.unshift(c$1(t))}else void 0!==t&&e.push(c$1(t));return e}static _$Eu(t,e){const o=e.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const o of e.keys())this.hasOwnProperty(o)&&(t.set(o,this[o]),delete this[o]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,e,o){this._$AK(t,o)}_$ET(t,e){const o=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,o);if(void 0!==s&&!0===o.reflect){const i=(void 0!==o.converter?.toAttribute?o.converter:u).toAttribute(e,o.type);this._$Em=t,null==i?this.removeAttribute(s):this.setAttribute(s,i),this._$Em=null}}_$AK(t,e){const o=this.constructor,s=o._$Eh.get(t);if(void 0!==s&&this._$Em!==s){const t=o.getPropertyOptions(s),i="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u;this._$Em=s;const r=i.fromAttribute(e,t.type);this[s]=r??this._$Ej?.get(s)??r,this._$Em=null}}requestUpdate(t,e,o){if(void 0!==t){const s=this.constructor,i=this[t];if(o??=s.getPropertyOptions(t),!((o.hasChanged??f)(i,e)||o.useDefault&&o.reflect&&i===this._$Ej?.get(t)&&!this.hasAttribute(s._$Eu(t,o))))return;this.C(t,e,o)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:o,reflect:s,wrapped:i},r){o&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??e??this[t]),!0!==i||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||o||(e=void 0),this._$AL.set(t,e)),!0===s&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,o]of t){const{wrapped:t}=o,s=this[e];!0!==t||this._$AL.has(e)||void 0===s||this.C(e,void 0,o,s)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM()}updated(t){}firstUpdated(t){}}y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[d("elementProperties")]=new Map,y[d("finalized")]=new Map,p?.({ReactiveElement:y}),(a.reactiveElementVersions??=[]).push("2.1.1");
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const o={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:f},r$1=(t=o,e,s)=>{const{kind:i,metadata:r}=s;let a=globalThis.litPropertyMetadata.get(r);if(void 0===a&&globalThis.litPropertyMetadata.set(r,a=new Map),"setter"===i&&((t=Object.create(t)).wrapped=!0),a.set(s.name,t),"accessor"===i){const{name:o}=s;return{set(s){const i=e.get.call(this);e.set.call(this,s),this.requestUpdate(o,i,t)},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===i){const{name:o}=s;return function(s){const i=this[o];e.call(this,s),this.requestUpdate(o,i,t)}}throw Error("Unsupported decorator location: "+i)};function n(t){return(e,o)=>"object"==typeof o?r$1(t,e,o):((t,e,o)=>{const s=e.hasOwnProperty(o);return e.constructor.createProperty(o,t),s?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */}function r(t){return n({...t,state:!0,attribute:!1})}exports.AiChat=class extends lit.LitElement{constructor(){super(...arguments),this.messages=[],this.loading=!1,this.placeholder="Type a message...",this.maxHeight="400px",this.theme="light",this.showTimestamp=!0,this.enableMarkdown=!0,this.inputValue=""}connectedCallback(){super.connectedCallback(),this.style.setProperty("--max-height",this.maxHeight)}updated(t){t.has("maxHeight")&&this.style.setProperty("--max-height",this.maxHeight),t.has("messages")&&this.scrollToBottom()}scrollToBottom(){const t=this.shadowRoot?.querySelector(".messages-container");t&&(t.scrollTop=t.scrollHeight)}formatTimestamp(t){if(!t)return"";return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}renderMessageContent(t){if("markdown"===t.type&&this.enableMarkdown){const e=marked.marked(t.content);return lit.html`<div class="markdown-content" .innerHTML="${e}"></div>`}return lit.html`<div>${t.content}</div>`}handleInput(t){const e=t.target;this.inputValue=e.value,e.style.height="auto",e.style.height=Math.min(e.scrollHeight,100)+"px"}handleKeyDown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.sendMessage())}sendMessage(){if(!this.inputValue.trim()||this.loading)return;const t={id:Date.now().toString(),type:"text",content:this.inputValue.trim(),timestamp:Date.now(),sender:"user"};this.dispatchEvent(new CustomEvent("message-sent",{detail:{type:"message",data:t,messageId:t.id}})),this.inputValue="";const e=this.shadowRoot?.querySelector(".input-field");e&&(e.style.height="auto")}renderMessages(){return this.messages.map((t=>{const e=t.sender||"assistant";return lit.html`
        <div class="message ${e}">
          <div class="message-content">
            ${this.renderMessageContent(t)}
          </div>
          ${this.showTimestamp&&t.timestamp?lit.html`
            <div class="message-timestamp">
              ${this.formatTimestamp(t.timestamp)}
            </div>
          `:""}
        </div>
      `}))}renderLoadingIndicator(){return this.loading?lit.html`
      <div class="message assistant">
        <div class="message-content">
          <div class="loading-indicator">
            <span>AI is typing</span>
            <div class="loading-dots">
              <div class="loading-dot"></div>
              <div class="loading-dot"></div>
              <div class="loading-dot"></div>
            </div>
          </div>
        </div>
      </div>
    `:""}render(){return lit.html`
      <div class="chat-container">
        <div class="messages-container">
          ${this.renderMessages()}
          ${this.renderLoadingIndicator()}
        </div>
        <div class="input-container">
          <textarea
            class="input-field"
            .value="${this.inputValue}"
            .placeholder="${this.placeholder}"
            ?disabled="${this.loading}"
            @input="${this.handleInput}"
            @keydown="${this.handleKeyDown}"
            rows="1"
          ></textarea>
          <button
            class="send-button"
            ?disabled="${!this.inputValue.trim()||this.loading}"
            @click="${this.sendMessage}"
          >
            Send
          </button>
        </div>
      </div>
    `}},exports.AiChat.styles=lit.css`
    :host {
      display: block;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      --primary-color: #007AFF;
      --background-color: #FFFFFF;
      --text-color: #000000;
      --border-color: #E5E5E7;
      --user-message-bg: #007AFF;
      --assistant-message-bg: #F2F2F7;
      --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    :host([theme="dark"]) {
      --background-color: #1C1C1E;
      --text-color: #FFFFFF;
      --border-color: #38383A;
      --user-message-bg: #007AFF;
      --assistant-message-bg: #2C2C2E;
    }

    .chat-container {
      display: flex;
      flex-direction: column;
      height: 100%;
      max-height: var(--max-height, 400px);
      background-color: var(--background-color);
      border: 1px solid var(--border-color);
      border-radius: 12px;
      overflow: hidden;
      box-shadow: var(--shadow);
    }

    .messages-container {
      flex: 1;
      overflow-y: auto;
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      -webkit-overflow-scrolling: touch;
    }

    .message {
      display: flex;
      flex-direction: column;
      max-width: 85%;
      word-wrap: break-word;
    }

    .message.user {
      align-self: flex-end;
    }

    .message.assistant {
      align-self: flex-start;
    }

    .message-content {
      padding: 12px 16px;
      border-radius: 18px;
      font-size: 16px;
      line-height: 1.4;
      word-wrap: break-word;
      overflow-wrap: break-word;
    }

    .message.user .message-content {
      background-color: var(--user-message-bg);
      color: white;
      border-bottom-right-radius: 4px;
    }

    .message.assistant .message-content {
      background-color: var(--assistant-message-bg);
      color: var(--text-color);
      border-bottom-left-radius: 4px;
    }

    .message-timestamp {
      font-size: 12px;
      color: #8E8E93;
      margin-top: 4px;
      text-align: right;
    }

    .message.assistant .message-timestamp {
      text-align: left;
    }

    .input-container {
      display: flex;
      padding: 16px;
      background-color: var(--background-color);
      border-top: 1px solid var(--border-color);
      gap: 8px;
    }

    .input-field {
      flex: 1;
      padding: 12px 16px;
      border: 1px solid var(--border-color);
      border-radius: 20px;
      font-size: 16px;
      background-color: var(--background-color);
      color: var(--text-color);
      outline: none;
      resize: none;
      min-height: 20px;
      max-height: 100px;
      font-family: inherit;
    }

    .input-field:focus {
      border-color: var(--primary-color);
    }

    .input-field::placeholder {
      color: #8E8E93;
    }

    .send-button {
      padding: 12px 20px;
      background-color: var(--primary-color);
      color: white;
      border: none;
      border-radius: 20px;
      font-size: 16px;
      font-weight: 600;
      cursor: pointer;
      transition: opacity 0.2s;
      min-width: 60px;
    }

    .send-button:hover:not(:disabled) {
      opacity: 0.8;
    }

    .send-button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .loading-indicator {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 16px;
      color: #8E8E93;
      font-size: 14px;
    }

    .loading-dots {
      display: flex;
      gap: 4px;
    }

    .loading-dot {
      width: 6px;
      height: 6px;
      background-color: #8E8E93;
      border-radius: 50%;
      animation: loading 1.4s infinite ease-in-out;
    }

    .loading-dot:nth-child(1) { animation-delay: -0.32s; }
    .loading-dot:nth-child(2) { animation-delay: -0.16s; }

    @keyframes loading {
      0%, 80%, 100% {
        transform: scale(0);
      }
      40% {
        transform: scale(1);
      }
    }

    .markdown-content {
      line-height: 1.6;
    }

    .markdown-content h1,
    .markdown-content h2,
    .markdown-content h3,
    .markdown-content h4,
    .markdown-content h5,
    .markdown-content h6 {
      margin: 16px 0 8px 0;
      font-weight: 600;
    }

    .markdown-content p {
      margin: 8px 0;
    }

    .markdown-content code {
      background-color: rgba(0, 0, 0, 0.1);
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
      font-size: 14px;
    }

    .markdown-content pre {
      background-color: rgba(0, 0, 0, 0.05);
      padding: 12px;
      border-radius: 8px;
      overflow-x: auto;
      margin: 12px 0;
    }

    .markdown-content pre code {
      background: none;
      padding: 0;
    }

    .markdown-content ul,
    .markdown-content ol {
      margin: 8px 0;
      padding-left: 20px;
    }

    .markdown-content li {
      margin: 4px 0;
    }

    .markdown-content blockquote {
      border-left: 4px solid var(--primary-color);
      margin: 12px 0;
      padding-left: 16px;
      color: #8E8E93;
    }

    .markdown-content a {
      color: var(--primary-color);
      text-decoration: none;
    }

    .markdown-content a:hover {
      text-decoration: underline;
    }

    /* Mobile optimizations */
    @media (max-width: 768px) {
      .message {
        max-width: 90%;
      }

      .message-content {
        font-size: 15px;
        padding: 10px 14px;
      }

      .input-container {
        padding: 12px;
      }

      .input-field {
        font-size: 16px; /* Prevents zoom on iOS */
      }

      .messages-container {
        padding: 12px;
      }
    }

    @media (max-width: 480px) {
      .message {
        max-width: 95%;
      }

      .message-content {
        font-size: 14px;
        padding: 8px 12px;
      }
    }
  `,__decorate([n({type:Array}),__metadata("design:type",Array)],exports.AiChat.prototype,"messages",void 0),__decorate([n({type:Boolean}),__metadata("design:type",Object)],exports.AiChat.prototype,"loading",void 0),__decorate([n({type:String}),__metadata("design:type",Object)],exports.AiChat.prototype,"placeholder",void 0),__decorate([n({type:String}),__metadata("design:type",Object)],exports.AiChat.prototype,"maxHeight",void 0),__decorate([n({type:String}),__metadata("design:type",String)],exports.AiChat.prototype,"theme",void 0),__decorate([n({type:Boolean}),__metadata("design:type",Object)],exports.AiChat.prototype,"showTimestamp",void 0),__decorate([n({type:Boolean}),__metadata("design:type",Object)],exports.AiChat.prototype,"enableMarkdown",void 0),__decorate([r(),__metadata("design:type",Object)],exports.AiChat.prototype,"inputValue",void 0),exports.AiChat=__decorate([t$1("ai-chat")],exports.AiChat);
//# sourceMappingURL=/sm/b486709a642ec3d35fcb5c13ff24272a9d65ec46944a7a748fdd2fb199a83d85.map