@hidemikimura/chit-ui 0.3.0 → 0.3.2
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/CHANGELOG.md +39 -0
- package/README.md +53 -3
- package/dist/chit-ui.iife.min.js +44 -20
- package/dist/chit-ui.iife.min.js.map +1 -1
- package/dist/chit-ui.min.js +44 -20
- package/dist/chit-ui.min.js.map +1 -1
- package/dist/types/controllers/scroll-lock-controller.d.ts +37 -0
- package/dist/types/controllers/viewport-controller.d.ts +38 -0
- package/dist/types/index.d.ts +162 -0
- package/package.json +2 -1
- package/skills/README.md +34 -0
- package/skills/chit-ui/SKILL.md +148 -0
- package/skills/chit-ui/references/api.md +189 -0
- package/skills/chit-ui/references/recipes.md +204 -0
- package/src/chit-ui.js +6 -0
- package/src/controllers/scroll-controller.js +21 -1
- package/src/controllers/scroll-lock-controller.js +185 -0
- package/src/controllers/viewport-controller.js +102 -0
- package/src/index.js +34 -0
- package/src/styles/composer.css.js +18 -0
- package/src/styles/panel.css.js +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,45 @@
|
|
|
4
4
|
バージョンは [Semantic Versioning](https://semver.org/lang/ja/) に従いますが、0.x の間は
|
|
5
5
|
マイナー更新に破壊的変更が入ることがあります。
|
|
6
6
|
|
|
7
|
+
## 0.3.2 — 2026-09-20
|
|
8
|
+
|
|
9
|
+
### 追加
|
|
10
|
+
|
|
11
|
+
- **AI コーディング支援向けの説明書を同梱しました**(`skills/chit-ui/`)。Claude Code などに
|
|
12
|
+
読ませると、`messages` の所有者が利用者側であること、`push` では描画されないこと、
|
|
13
|
+
`text` と `html` の使い分けといった、このライブラリの癖を踏まえたコードになります。
|
|
14
|
+
npm パッケージにも入っているので、`node_modules/@hidemikimura/chit-ui/skills/chit-ui/` から
|
|
15
|
+
そのまま参照できます。
|
|
16
|
+
- **ドキュメントサイトを用意しました**(`site/`)。ビルド工程のない素の HTML/CSS/JS で、
|
|
17
|
+
ページの上で本物のウィジェットが動きます。GitHub Pages へ上げるワークフローも
|
|
18
|
+
同梱しています(npm パッケージには含めていません)。
|
|
19
|
+
|
|
20
|
+
## 0.3.1 — 2026-09-20
|
|
21
|
+
|
|
22
|
+
### 追加
|
|
23
|
+
|
|
24
|
+
- 公開している型をパッケージのルートからも読めるようにしました。
|
|
25
|
+
`import type { Message, Theme } from '@hidemikimura/chit-ui'` のように書けます
|
|
26
|
+
(これまでは `dist/types/` を直接指す必要がありました)。
|
|
27
|
+
|
|
28
|
+
### 修正
|
|
29
|
+
|
|
30
|
+
- **スマホで入力欄にフォーカスしても画面が拡大されなくなりました。** iOS Safari は
|
|
31
|
+
16px 未満の入力欄にフォーカスするとページを拡大し、離れても元に戻しません。タッチ端末
|
|
32
|
+
(`pointer: coarse`)では入力欄を 16px 以上にして、拡大そのものが起きないようにしました。
|
|
33
|
+
ウィジェット全体の文字サイズは変わりません。テーマの文字が 16px より大きい場合はそちらが
|
|
34
|
+
優先されます。
|
|
35
|
+
- **キーボードが出ている間、全画面のパネルが見えている範囲に収まるようになりました。**
|
|
36
|
+
`visualViewport` を見て、パネルの上端と高さを実際に見えている箱に合わせます。入力欄と
|
|
37
|
+
直前の発言がキーボードの下に隠れなくなり、送信したあともそのまま見えています。
|
|
38
|
+
ピンチで拡大しているときは何もしません(拡大は読み手のものなので、勝手に組み直さない)。
|
|
39
|
+
- **パネルの上をなぞっても後ろのページが動かなくなりました。** 会話が画面に収まっていて
|
|
40
|
+
発言一覧がスクロールしないとき、タイトルバーや入力欄をなぞったときに、指の動きがそのまま
|
|
41
|
+
ページに渡っていました(iPhone で顕著)。`overscroll-behavior: contain` が効くのは
|
|
42
|
+
スクロールできる箱を端まで引っぱったときだけで、そもそも箱になっていない場合は素通しに
|
|
43
|
+
なるためです。パネルの中に進める入れ子があるかを見て、なければその指の動きを取り消します。
|
|
44
|
+
ピンチ(2 本指)はそのままなので、拡大は変わりません。
|
|
45
|
+
|
|
7
46
|
## 0.3.0 — 2026-09-20
|
|
8
47
|
|
|
9
48
|
### 追加
|
package/README.md
CHANGED
|
@@ -8,7 +8,11 @@ JavaScript ライブラリです。通信も会話ロジックも、発言の中
|
|
|
8
8
|
- 閉じた状態(ランチャー)・開いた状態(パネル)・非表示の 3 状態
|
|
9
9
|
- 状態ごとのテーマ。閉じた状態は PC とスマホで別々に指定できます
|
|
10
10
|
- 発言の中身は HTML 文字列でも Lit テンプレートでも `LitElement` を継承したコンポーネントでも可
|
|
11
|
-
- 依存は Lit のみ。単一バンドルは gzip 約
|
|
11
|
+
- 依存は Lit のみ。単一バンドルは gzip 約 26 KB
|
|
12
|
+
|
|
13
|
+
ドキュメントサイト(人間向け)は [`site/`](site/) にあります。`npm run dev` のあと
|
|
14
|
+
`/site/` を開くとその場で読めます。AI コーディング支援向けの説明書は
|
|
15
|
+
[`skills/chit-ui/`](skills/chit-ui/) にあり、npm パッケージにも同梱しています。
|
|
12
16
|
|
|
13
17
|
## はじめに
|
|
14
18
|
|
|
@@ -69,6 +73,17 @@ customElements.define('my-chat', ChitUI);
|
|
|
69
73
|
`window.ChitUI` を作る IIFE 版(`dist/chit-ui.iife.min.js`)もあります。npm 版と
|
|
70
74
|
単一バンドル版を同じページで混ぜると Lit が二重に読み込まれるので、どちらか一方にしてください。
|
|
71
75
|
|
|
76
|
+
### TypeScript
|
|
77
|
+
|
|
78
|
+
型はパッケージのルートから読めます。
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import type { Message, Theme, Position } from '@hidemikimura/chit-ui';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`chit-ui` 要素と `chat-*` イベントの型も一緒に入るので、`document.querySelector('chit-ui')`
|
|
85
|
+
の戻り値や `addEventListener('chat-submit', ...)` の `detail` に型が付きます。
|
|
86
|
+
|
|
72
87
|
## 発言の中身
|
|
73
88
|
|
|
74
89
|
1 つの発言には、次の 5 つのうち **ちょうど 1 つ** を指定します。
|
|
@@ -551,6 +566,31 @@ chat.theme = { open: { animation: { scroll: 'instant' } } };
|
|
|
551
566
|
スクロール位置が「最下部にいない」と読めてしまい、追従そのものが止まるためです。
|
|
552
567
|
`prefers-reduced-motion` が有効な環境でも即時になります。
|
|
553
568
|
|
|
569
|
+
### スマホのキーボードと拡大
|
|
570
|
+
|
|
571
|
+
入力欄の文字は、タッチ端末では 16px を下回りません。iOS Safari はそれより小さい欄に
|
|
572
|
+
フォーカスするとページを拡大し、離れても元に戻さないためです。ウィジェット全体の文字サイズ
|
|
573
|
+
(`--chit-font-size`)は変わりません。テーマの文字が 16px より大きければそちらが使われます。
|
|
574
|
+
|
|
575
|
+
全画面表示のとき、キーボードが出ている間はパネルが見えている範囲(`visualViewport`)に
|
|
576
|
+
収まります。入力欄と直前の発言がキーボードの下に隠れず、送信後もそのまま見えます。
|
|
577
|
+
`100dvh` はブラウザの上下のバーが縮むぶんは見てくれますが、キーボードのことは知りません。
|
|
578
|
+
|
|
579
|
+
ピンチで拡大しているときは何もしません。拡大は読み手のものなので、そこで組み直して
|
|
580
|
+
文字を元の大きさに戻してしまうのは余計なお世話です。
|
|
581
|
+
|
|
582
|
+
### 後ろのページは動きません
|
|
583
|
+
|
|
584
|
+
パネルの上を指でなぞっても、後ろのページはスクロールしません。会話が画面に収まっていて
|
|
585
|
+
スクロールするものが何もないときも、タイトルバーや入力欄をなぞったときも同じです。
|
|
586
|
+
スクロールできるものがパネルの中にあれば、そちらは普段どおり動きます。
|
|
587
|
+
|
|
588
|
+
`overscroll-behavior: contain` だけでは足りません。あれが効くのは「スクロールできる箱を
|
|
589
|
+
端まで引っぱったとき」で、会話が短くて発言一覧がそもそもスクロールしない場合は箱ですらなく、
|
|
590
|
+
指の動きはそのままページに渡ってしまいます。iPhone で「チャットの後ろが動く」のはこれです。
|
|
591
|
+
そこで、指が最初に動いた向きに進める入れ子がパネルの中にあるかを見て、なければその指の動きを
|
|
592
|
+
取り消しています。2 本指(ピンチ)はそのままで、拡大は読み手のものです。
|
|
593
|
+
|
|
554
594
|
テーマの値は CSS カスタムプロパティになるので、ページ側の CSS からも上書きできます。
|
|
555
595
|
こちらが優先されます。
|
|
556
596
|
|
|
@@ -695,7 +735,7 @@ chat.addEventListener('chat-message-click', (event) => {
|
|
|
695
735
|
- ストリーミング中の発言は `aria-busy="true"` なので、1 文字ずつ読み上げられません
|
|
696
736
|
- `prefers-reduced-motion` を尊重します
|
|
697
737
|
- 既定テーマの文字色と背景色の組み合わせはすべて WCAG AA(4.5:1)以上です
|
|
698
|
-
- `npm run audit:a11y` で axe-core による監査を実行できます(
|
|
738
|
+
- `npm run audit:a11y` で axe-core による監査を実行できます(10 状態、違反 0 を維持)
|
|
699
739
|
|
|
700
740
|
## ブラウザ
|
|
701
741
|
|
|
@@ -716,12 +756,22 @@ npm run build # 型定義と単一バンドルを dist/ に出力
|
|
|
716
756
|
npm run check # 上記をまとめて
|
|
717
757
|
```
|
|
718
758
|
|
|
759
|
+
### ドキュメントと skill
|
|
760
|
+
|
|
761
|
+
API を変えたら、`README.md`・`site/`(ドキュメントサイト)・`skills/`(AI 向け)の 3 つを
|
|
762
|
+
一緒に更新します。サイトはビルド工程を持たないので、`site/` の HTML を直せばそれで終わりです。
|
|
763
|
+
公開は `.github/workflows/pages.yml` が `site/` を GitHub Pages へ上げます
|
|
764
|
+
(Settings → Pages → Source を「GitHub Actions」にしておく)。
|
|
765
|
+
|
|
719
766
|
### リリース前の手動チェック
|
|
720
767
|
|
|
721
768
|
IME の実挙動は合成イベントでは再現しきれないため、リリース前に実機で確認します。
|
|
722
769
|
|
|
723
770
|
- macOS Safari + 日本語 IME: 変換確定の Enter で誤送信しないこと
|
|
724
|
-
- iOS Safari:
|
|
771
|
+
- iOS Safari: パネルが全画面になり、キーボード表示中も入力欄が隠れないこと。
|
|
772
|
+
入力欄にフォーカスしてもページが拡大しないこと(送信後も拡大したままにならないこと)
|
|
773
|
+
- iOS Safari: パネルの上を指でなぞっても後ろのページが動かないこと。会話が短くて
|
|
774
|
+
スクロールするものが無いときも同じであること
|
|
725
775
|
- Android Chrome: 変換中の Enter で誤送信しないこと
|
|
726
776
|
- iOS Safari / Android Chrome: 添付ボタンからカメラとフォトライブラリが開けること
|
|
727
777
|
(`accept` はブラウザによって扱いが違うため)
|
package/dist/chit-ui.iife.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),n=new WeakMap;let o=class{constructor(t,e,i){if(this._$cssResult$=!0,i!==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(i&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=n.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&n.set(e,t))}return t}toString(){return this.cssText}};const r=(t,...e)=>{const i=1===t.length?t[0]:e.reduce((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1],t[0]);return new o(i,t,s)},a=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new o("string"==typeof t?t:t+"",void 0,s))(e)})(t):t,{is:h,defineProperty:l,getOwnPropertyDescriptor:c,getOwnPropertyNames:d,getOwnPropertySymbols:p,getPrototypeOf:u}=Object,m=globalThis,f=m.trustedTypes,g=f?f.emptyScript:"",b=m.reactiveElementPolyfillSupport,v=(t,e)=>t,y={toAttribute(t,e){switch(e){case Boolean:t=t?g:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},w=(t,e)=>!h(t,e),x={attribute:!0,type:String,converter:y,reflect:!1,useDefault:!1,hasChanged:w};Symbol.metadata??=Symbol("metadata"),m.litPropertyMetadata??=new WeakMap;let $=class 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,e=x){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const i=Symbol(),s=this.getPropertyDescriptor(t,i,e);void 0!==s&&l(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){const{get:s,set:n}=c(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:s,set(e){const o=s?.call(this);n?.call(this,e),this.requestUpdate(t,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??x}static _$Ei(){if(this.hasOwnProperty(v("elementProperties")))return;const t=u(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(v("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(v("properties"))){const t=this.properties,e=[...d(t),...p(t)];for(const i of e)this.createProperty(i,t[i])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const i=this._$Eu(t,e);void 0!==i&&this._$Eh.set(i,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}static _$Eu(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"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 i of e.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,s)=>{if(i)t.adoptedStyleSheets=s.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const i of s){const s=document.createElement("style"),n=e.litNonce;void 0!==n&&s.setAttribute("nonce",n),s.textContent=i.cssText,t.appendChild(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,i){this._$AK(t,i)}_$ET(t,e){const i=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,i);if(void 0!==s&&!0===i.reflect){const n=(void 0!==i.converter?.toAttribute?i.converter:y).toAttribute(e,i.type);this._$Em=t,null==n?this.removeAttribute(s):this.setAttribute(s,n),this._$Em=null}}_$AK(t,e){const i=this.constructor,s=i._$Eh.get(t);if(void 0!==s&&this._$Em!==s){const t=i.getPropertyOptions(s),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:y;this._$Em=s;const o=n.fromAttribute(e,t.type);this[s]=o??this._$Ej?.get(s)??o,this._$Em=null}}requestUpdate(t,e,i,s=!1,n){if(void 0!==t){const o=this.constructor;if(!1===s&&(n=this[t]),i??=o.getPropertyOptions(t),!((i.hasChanged??w)(n,e)||i.useDefault&&i.reflect&&n===this._$Ej?.get(t)&&!this.hasAttribute(o._$Eu(t,i))))return;this.C(t,e,i)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:i,reflect:s,wrapped:n},o){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),!0!==n||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||i||(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,i]of t){const{wrapped:t}=i,s=this[e];!0!==t||this._$AL.has(e)||void 0===s||this.C(e,void 0,i,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){}};$.elementStyles=[],$.shadowRootOptions={mode:"open"},$[v("elementProperties")]=new Map,$[v("finalized")]=new Map,b?.({ReactiveElement:$}),(m.reactiveElementVersions??=[]).push("2.1.2");const _=globalThis,A=t=>t,S=_.trustedTypes,E=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,k="$lit$",T=`lit$${Math.random().toFixed(9).slice(2)}$`,C="?"+T,O=`<${C}>`,P=document,M=()=>P.createComment(""),L=t=>null===t||"object"!=typeof t&&"function"!=typeof t,U=Array.isArray,z="[ \t\n\f\r]",R=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,B=/-->/g,D=/>/g,H=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),I=/'/g,N=/"/g,j=/^(?:script|style|textarea|title)$/i,q=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),W=q(1),F=q(2),K=Symbol.for("lit-noChange"),V=Symbol.for("lit-nothing"),Y=new WeakMap,G=P.createTreeWalker(P,129);function J(t,e){if(!U(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==E?E.createHTML(e):e}class Z{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let n=0,o=0;const r=t.length-1,a=this.parts,[h,l]=((t,e)=>{const i=t.length-1,s=[];let n,o=2===e?"<svg>":3===e?"<math>":"",r=R;for(let e=0;e<i;e++){const i=t[e];let a,h,l=-1,c=0;for(;c<i.length&&(r.lastIndex=c,h=r.exec(i),null!==h);)c=r.lastIndex,r===R?"!--"===h[1]?r=B:void 0!==h[1]?r=D:void 0!==h[2]?(j.test(h[2])&&(n=RegExp("</"+h[2],"g")),r=H):void 0!==h[3]&&(r=H):r===H?">"===h[0]?(r=n??R,l=-1):void 0===h[1]?l=-2:(l=r.lastIndex-h[2].length,a=h[1],r=void 0===h[3]?H:'"'===h[3]?N:I):r===N||r===I?r=H:r===B||r===D?r=R:(r=H,n=void 0);const d=r===H&&t[e+1].startsWith("/>")?" ":"";o+=r===R?i+O:l>=0?(s.push(a),i.slice(0,l)+k+i.slice(l)+T+d):i+T+(-2===l?e:d)}return[J(t,o+(t[i]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),s]})(t,e);if(this.el=Z.createElement(h,i),G.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=G.nextNode())&&a.length<r;){if(1===s.nodeType){if(s.hasAttributes())for(const t of s.getAttributeNames())if(t.endsWith(k)){const e=l[o++],i=s.getAttribute(t).split(T),r=/([.?@])?(.*)/.exec(e);a.push({type:1,index:n,name:r[2],strings:i,ctor:"."===r[1]?it:"?"===r[1]?st:"@"===r[1]?nt:et}),s.removeAttribute(t)}else t.startsWith(T)&&(a.push({type:6,index:n}),s.removeAttribute(t));if(j.test(s.tagName)){const t=s.textContent.split(T),e=t.length-1;if(e>0){s.textContent=S?S.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],M()),G.nextNode(),a.push({type:2,index:++n});s.append(t[e],M())}}}else if(8===s.nodeType)if(s.data===C)a.push({type:2,index:n});else{let t=-1;for(;-1!==(t=s.data.indexOf(T,t+1));)a.push({type:7,index:n}),t+=T.length-1}n++}}static createElement(t,e){const i=P.createElement("template");return i.innerHTML=t,i}}function Q(t,e,i=t,s){if(e===K)return e;let n=void 0!==s?i._$Co?.[s]:i._$Cl;const o=L(e)?void 0:e._$litDirective$;return n?.constructor!==o&&(n?._$AO?.(!1),void 0===o?n=void 0:(n=new o(t),n._$AT(t,i,s)),void 0!==s?(i._$Co??=[])[s]=n:i._$Cl=n),void 0!==n&&(e=Q(t,n._$AS(t,e.values),n,s)),e}class X{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:i}=this._$AD,s=(t?.creationScope??P).importNode(e,!0);G.currentNode=s;let n=G.nextNode(),o=0,r=0,a=i[0];for(;void 0!==a;){if(o===a.index){let e;2===a.type?e=new tt(n,n.nextSibling,this,t):1===a.type?e=new a.ctor(n,a.name,a.strings,this,t):6===a.type&&(e=new ot(n,this,t)),this._$AV.push(e),a=i[++r]}o!==a?.index&&(n=G.nextNode(),o++)}return G.currentNode=P,s}p(t){let e=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class tt{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,i,s){this.type=2,this._$AH=V,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Q(this,t,e),L(t)?t===V||null==t||""===t?(this._$AH!==V&&this._$AR(),this._$AH=V):t!==this._$AH&&t!==K&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>U(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==V&&L(this._$AH)?this._$AA.nextSibling.data=t:this.T(P.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=Z.createElement(J(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new X(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=Y.get(t.strings);return void 0===e&&Y.set(t.strings,e=new Z(t)),e}k(t){U(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const n of t)s===e.length?e.push(i=new tt(this.O(M()),this.O(M()),this,this.options)):i=e[s],i._$AI(n),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){const e=A(t).nextSibling;A(t).remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class et{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,i,s,n){this.type=1,this._$AH=V,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=n,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=V}_$AI(t,e=this,i,s){const n=this.strings;let o=!1;if(void 0===n)t=Q(this,t,e,0),o=!L(t)||t!==this._$AH&&t!==K,o&&(this._$AH=t);else{const s=t;let r,a;for(t=n[0],r=0;r<n.length-1;r++)a=Q(this,s[i+r],e,r),a===K&&(a=this._$AH[r]),o||=!L(a)||a!==this._$AH[r],a===V?t=V:t!==V&&(t+=(a??"")+n[r+1]),this._$AH[r]=a}o&&!s&&this.j(t)}j(t){t===V?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class it extends et{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===V?void 0:t}}class st extends et{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==V)}}class nt extends et{constructor(t,e,i,s,n){super(t,e,i,s,n),this.type=5}_$AI(t,e=this){if((t=Q(this,t,e,0)??V)===K)return;const i=this._$AH,s=t===V&&i!==V||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,n=t!==V&&(i===V||s);s&&this.element.removeEventListener(this.name,this,i),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class ot{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Q(this,t)}}const rt={I:tt},at=_.litHtmlPolyfillSupport;at?.(Z,tt),(_.litHtmlVersions??=[]).push("3.3.3");const ht=(t,e,i)=>{const s=i?.renderBefore??e;let n=s._$litPart$;if(void 0===n){const t=i?.renderBefore??null;s._$litPart$=n=new tt(e.insertBefore(M(),t),t,void 0,i??{})}return n._$AI(t),n},lt=globalThis;let ct=class extends ${constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=ht(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return K}};ct._$litElement$=!0,ct.finalized=!0,lt.litElementHydrateSupport?.({LitElement:ct});const dt=lt.litElementPolyfillSupport;dt?.({LitElement:ct}),(lt.litElementVersions??=[]).push("4.2.2");const pt=1,ut=2,mt=3,ft=4,gt=t=>(...e)=>({_$litDirective$:t,values:e});let bt=class{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}},vt=class extends bt{constructor(t){if(super(t),this.it=V,t.type!==ut)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===V||null==t)return this._t=void 0,this.it=t;if(t===K)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const e=[t];return e.raw=e,this._t={_$litType$:this.constructor.resultType,strings:e,values:[]}}};vt.directiveName="unsafeHTML",vt.resultType=1;const yt=gt(vt),wt=Object.freeze({SUBMIT:"chat-submit",BEFORE_OPEN:"chat-before-open",OPEN:"chat-open",BEFORE_CLOSE:"chat-before-close",CLOSE:"chat-close",HIDE:"chat-hide",SHOW:"chat-show",STATE_CHANGE:"chat-state-change",INPUT:"chat-input",MESSAGE_RENDER:"chat-message-render",MESSAGE_CLICK:"chat-message-click",SCROLL_TOP:"chat-scroll-top",BREAKPOINT_CHANGE:"chat-breakpoint-change",HOME:"chat-home",ATTACH:"chat-attach",MOVE:"chat-move"});function xt(t,e,i,{cancelable:s=!1}={}){return t.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0,cancelable:s}))}const $t={closed:"launcher",open:"panel",hidden:null};class _t{#t;#e;#i;#s;#n="closed";#o="closed";#r=!1;#a=0;#h=null;#l=null;#c=!1;constructor(t,{animation:e,keepsLauncher:i,onOpened:s}){this.#t=t,this.#e=e,this.#i=i,this.#s=s,t.addController(this)}get renderedState(){return this.#o}get applying(){return this.#r}hostConnected(){this.#n=this.#t.state,this.#o=this.#t.state,this.#t.dataset.renderedState=this.#o}hostDisconnected(){this.#l?.(),this.#l=null,this.#h?.(!1),this.#h=null}hostUpdated(){this.#t.dataset.renderedState=this.#o}request(t,e){const i=this.#n;return t===i?Promise.resolve(!0):this.#d(i,t,e)?(this.#p(),this.#n=t,this.#u(t),xt(this.#t,wt.STATE_CHANGE,{from:i,to:t,trigger:e}),this.#m(i,t,e)):(this.#u(i),Promise.resolve(!1))}#d(t,e,i){return"open"===e?xt(this.#t,wt.BEFORE_OPEN,{from:t,trigger:i},{cancelable:!0}):"closed"!==e||"open"!==t||xt(this.#t,wt.BEFORE_CLOSE,{from:t,trigger:i},{cancelable:!0})}#p(){this.#a+=1,this.#l?.(),this.#l=null,this.#h?.(!1),this.#h=null,this.#o!==this.#n&&(this.#o=this.#n,this.#t.requestUpdate())}#m(t,e,i){const s=this.#a,n=new Promise(t=>{this.#h=t});return(async()=>{if(this.#c=this.#f(),await this.#t.updateComplete,s!==this.#a)return;const n=this.#g(t);if(n&&!this.#b(t,e)&&(await this.#v(n,"exit",this.#e(t,e,"exit")),s!==this.#a))return;if(this.#o=e,this.#t.requestUpdate(),await this.#t.updateComplete,s!==this.#a)return;const o=this.#g(e);o&&(await this.#v(o,"enter",this.#e(t,e,"enter")),s!==this.#a)||(this.#y(t,e,i),this.#w(e),this.#h?.(!0),this.#h=null)})(),n}#b(t,e){return"closed"===t&&"open"===e&&this.#i()}#y(t,e,i){"hidden"===t&&xt(this.#t,wt.SHOW,{from:t,to:e}),"hidden"!==e?"open"===e?xt(this.#t,wt.OPEN,{from:t,trigger:i}):"closed"===e&&"open"===t&&xt(this.#t,wt.CLOSE,{from:t,trigger:i}):xt(this.#t,wt.HIDE,{from:t,to:e})}#w(t){"open"!==t?("closed"===t&&this.#c&&this.#g("closed")?.focus(),this.#c=!1):this.#s()}#f(){const t=this.#t.renderRoot instanceof ShadowRoot?this.#t.renderRoot.activeElement:null,e=this.#g("open");return!(!t||!e||t!==e&&!e.contains(t))}#g(t){const e=$t[t];return e?this.#t.renderRoot.querySelector(`[part~="${e}"]`):null}#u(t){this.#t.state!==t&&(this.#r=!0,this.#t.state=t,this.#r=!1)}#v(t,e,i){const{effect:s,duration:n}=i;return"none"===s||n<=0||window.matchMedia("(prefers-reduced-motion: reduce)").matches?Promise.resolve():new Promise(i=>{let o=!1;const r=e=>{e&&e.target!==t||o||(o=!0,clearTimeout(a),t.removeEventListener("animationend",r),t.removeAttribute("data-anim"),t.style.removeProperty("--_chit-anim-duration"),this.#l===r&&(this.#l=null),i())};t.dataset.effect=s,t.dataset.anim=e,t.style.setProperty("--_chit-anim-duration",`${n}ms`),t.addEventListener("animationend",r);const a=setTimeout(r,n+50);this.#l=r})}}class At{#t;#x=null;#$=0;#_="pc";#A=!1;constructor(t){this.#t=t,t.addController(this)}get device(){return this.#_}hostDisconnected(){this.#x?.removeEventListener("change",this.#S),this.#x=null}observe(t){t===this.#$&&this.#x||(this.#$=t,this.#x?.removeEventListener("change",this.#S),this.#x=window.matchMedia(`(max-width: ${t-1}px)`),this.#x.addEventListener("change",this.#S),this.#E(this.#x.matches?"mobile":"pc"))}#S=t=>{this.#E(t.matches?"mobile":"pc")};#E(t){t===this.#_&&this.#t.dataset.device||(this.#_=t,this.#t.dataset.device=t,this.#t.requestUpdate(),this.#A&&xt(this.#t,wt.BREAKPOINT_CHANGE,{device:t}),this.#A=!0)}}const St="#2563eb",Et="#1f2328",kt="#5c6370",Tt="#ffffff",Ct="#f1f3f5",Ot="#e4e4e7",Pt="#ffffff",Mt={size:60,position:"bottom-right",offset:{x:24,y:24},radius:30,draggable:!1,image:null,label:null,component:null,props:{},colors:{background:St,text:Pt,shadow:"0 4px 12px rgba(0, 0, 0, 0.2)"},animation:{enter:"scale",exit:"scale",duration:200,idle:"none"}},Lt={size:56,offset:{x:16,y:16},radius:28},Ut={breakpoint:768,zIndex:2147483e3,font:{family:"system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif",size:14},closed:{pc:Mt,mobile:{...Mt,...Lt}},open:{width:380,height:600,position:"bottom-right",offset:{x:24,y:24},radius:16,launcher:"hidden",draggable:!1,header:{visible:!0,title:null,logo:null,home:!1},background:{image:null},colors:{background:Tt,text:Et,accent:St,border:Ot,shadow:"0 8px 32px rgba(0, 0, 0, 0.24)",headerBackground:Tt,headerText:Et,userBubble:St,userText:Pt,assistantBubble:Ct,assistantText:Et,systemText:kt,inputBackground:Tt,inputText:Et,inputPlaceholder:kt},bubble:{radius:14,tail:"none"},loading:{auto:!1,style:"spinner",text:null,timeout:0},speaker:{assistant:{name:null,avatar:null},user:{name:null,avatar:null}},animation:{enter:"scale",exit:"fade",duration:150,scroll:"smooth"},input:{maxRows:5,placeholder:null,attach:!1,accept:"image/*,video/*",multiple:!1}},hidden:{animation:{exit:"fade",duration:150}}},zt=Lt;function Rt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function Bt(t,e){if(!Rt(e))return t;const i={...t};for(const[t,s]of Object.entries(e)){if(void 0===s)continue;const e=i[t];i[t]=Rt(s)&&Rt(e)?Bt(e,s):s}return i}function Dt(t,e){const i=t??{},s=function(t,e){const i=t??{};if(!("pc"in i)&&!("mobile"in i)){const i=t??{};return Bt(Ut.closed[e],i)}const s=Bt(Ut.closed.pc,i.pc);return"pc"===e?s:i.mobile?Bt(Ut.closed.mobile,i.mobile):Bt(s,zt)}(i.closed,e);return{breakpoint:i.breakpoint??Ut.breakpoint,zIndex:i.zIndex??Ut.zIndex,font:Bt(Ut.font,i.font),closed:Bt(Ut.closed[e],s),open:Bt(Ut.open,i.open),hidden:Bt(Ut.hidden,i.hidden),device:e}}const Ht=t=>`${t}px`;function It(t){return t?`url("${t.replace(/[\\"]/g,"\\$&")}")`:"none"}function Nt(t){const e=Object.entries(function(t){const{closed:e,open:i}=t,s=i.colors;return{"--chit-z-index":String(t.zIndex),"--chit-font-family":t.font.family,"--chit-font-size":Ht(t.font.size),"--chit-launcher-size":"auto"===e.size?"auto":Ht(e.size),"--chit-launcher-offset-x":Ht(e.offset.x),"--chit-launcher-offset-y":Ht(e.offset.y),"--chit-launcher-radius":Ht(e.radius),"--chit-launcher-image":It(e.image),"--chit-launcher-bg":e.colors.background,"--chit-launcher-text":e.colors.text,"--chit-launcher-shadow":e.colors.shadow,"--chit-panel-width":Ht(i.width),"--chit-panel-height":Ht(i.height),"--chit-panel-offset-x":Ht(i.offset.x),"--chit-panel-offset-y":Ht(i.offset.y),"--chit-panel-radius":Ht(i.radius),"--chit-panel-bg-image":It(i.background.image),"--chit-panel-shadow":s.shadow,"--chit-color-bg":s.background,"--chit-color-text":s.text,"--chit-color-accent":s.accent,"--chit-color-border":s.border,"--chit-color-header-bg":s.headerBackground,"--chit-color-header-text":s.headerText,"--chit-color-user-bg":s.userBubble,"--chit-color-user-text":s.userText,"--chit-color-assistant-bg":s.assistantBubble,"--chit-color-assistant-text":s.assistantText,"--chit-color-system-text":s.systemText,"--chit-color-input-bg":s.inputBackground,"--chit-color-input-text":s.inputText,"--chit-color-input-placeholder":s.inputPlaceholder,"--chit-bubble-radius":Ht(i.bubble.radius),"--_chit-input-max-rows":String(i.input.maxRows),"--_chit-speaker-gutter":i.speaker.assistant.avatar?"2.5em":"0px"}}(t)).map(([t,e])=>` ${t}: ${e};`).join("\n");return`:host {\n${e}\n}\n`}const jt="undefined"!=typeof ShadowRoot&&"adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype;class qt{#k=null;#T=null;#C="";#O;constructor(t){this.#O=t}attach(t){if(t instanceof ShadowRoot){if(jt)return this.#k||(this.#k=new CSSStyleSheet),void(t.adoptedStyleSheets.includes(this.#k)||(t.adoptedStyleSheets=[...t.adoptedStyleSheets,this.#k]));this.#T||(this.#T=document.createElement("style"),this.#T.setAttribute(this.#O,"")),this.#T.parentNode!==t&&t.append(this.#T)}}write(t,e){if(t!==this.#C){if(this.attach(e),this.#k)this.#k.replaceSync(t);else{if(!this.#T)return;this.#T.textContent=t}this.#C=t}}detach(){this.#T?.remove(),this.#T=null}}class Wt{#t;#k=new qt("data-chit-theme");#P;constructor(t,{device:e}){this.#t=t,this.#P=Dt(void 0,e())}get current(){return this.#P}hostConnected(){this.#M()}hostDisconnected(){this.#k.detach()}static breakpointOf(t){return function(t){return t?.breakpoint??Ut.breakpoint}(t)}apply(t,e){this.#P=Dt(t,e),this.#M()}#M(){this.#k.write(Nt(this.#P),this.#t.renderRoot)}}class Ft{#t;#L;#U=null;#z=null;#R=!0;#B=!1;#D=!1;#H=!0;#I=!1;#N;#j=!0;#q;#W=0;constructor(t,{behavior:e}){this.#t=t,this.#L=e,t.addController(this)}get hasUnseen(){return this.#B}get atBottom(){return this.#R}hostDisconnected(){this.#F(),clearTimeout(this.#N)}hostUpdate(){const t=this.#t.messages,e=t[t.length-1],i=t.length>this.#W,s=e?.id!==this.#q;this.#q=e?.id,this.#W=t.length,(i||s)&&(this.#R||"user"===e?.role?this.#H=!0:this.#B=!0)}hostUpdated(){const t=this.#t.renderRoot.querySelector('[part~="messages"]');if(t!==this.#U&&(this.#F(),this.#U=t,this.#K(),t&&(this.#R=!0,this.#B=!1,this.#H=!0,this.#j=!0)),this.#H){const t=this.#V;this.#H=!1,this.#Y({behavior:t})}}#K(){if(!this.#U)return;this.#U.addEventListener("scroll",this.#G,{passive:!0}),this.#U.addEventListener("scrollend",this.#J);const t=this.#U.firstElementChild;t&&"undefined"!=typeof ResizeObserver&&(this.#z=new ResizeObserver(()=>{this.#R&&this.#Y({behavior:this.#I?"smooth":"instant"})}),this.#z.observe(t))}#F(){this.#U?.removeEventListener("scroll",this.#G),this.#U?.removeEventListener("scrollend",this.#J),this.#z?.disconnect(),this.#z=null,this.#U=null}#J=()=>{this.#Z()};#G=()=>{const t=this.#U;if(!t)return;const e=t.scrollHeight-t.scrollTop-t.clientHeight<=24;if(this.#I)return void(e&&this.#Z());e!==this.#R&&(this.#R=e,e&&this.#B&&(this.#B=!1,this.#t.requestUpdate()));const i=t.scrollTop<=0;i&&!this.#D&&xt(this.#t,wt.SCROLL_TOP,{}),this.#D=i};scrollToBottom({smooth:t}={}){const e=void 0===t?this.#V:t?"smooth":"instant";this.#Y({behavior:e}),this.#B&&(this.#B=!1,this.#t.requestUpdate())}get#V(){return this.#j||window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":this.#L()}#Y({behavior:t="instant"}={}){const e=this.#U;e&&(this.#j=!1,"smooth"===t&&this.#Q(),e.scrollTo({top:e.scrollHeight,behavior:t}),this.#R=!0,this.#D=!1,this.#B=!1)}#Q(){this.#I=!0,clearTimeout(this.#N),this.#N=setTimeout(()=>this.#Z(),700)}#Z(){if(!this.#I)return;this.#I=!1,clearTimeout(this.#N);const t=this.#U;if(!t)return;const e=t.scrollHeight-t.scrollTop-t.clientHeight;this.#R=e<=24}}const Kt="undefined"!=typeof CSS&&CSS.supports?.("field-sizing","content");class Vt{#t;#X="";#tt=!1;#et=!1;#it;constructor(t){this.#t=t,t.addController(this)}get value(){return this.#X}set value(t){this.#X=t??"";const e=this.#st;e&&e.value!==this.#X&&(e.value=this.#X),this.#nt(),this.#ot()}get composing(){return this.#tt}get length(){return Array.from(this.#X).length}get canSend(){if(this.#t.busy||this.#t.inputDisabled)return!1;if(""===this.#X.trim())return!1;const t=this.#t.maxLength;return void 0===t||this.length<=t}hostDisconnected(){clearTimeout(this.#it)}hostUpdated(){const t=this.#st;t&&t.value!==this.#X&&(t.value=this.#X),this.#nt(),this.#ot()}get#st(){return this.#t.renderRoot.querySelector('[part~="input"]')}onInput(t){this.#X=t.target.value,this.#nt(),this.#ot(),xt(this.#t,wt.INPUT,{value:this.#X})}onCompositionStart(){this.#tt=!0}onCompositionEnd(){this.#tt=!1,this.#et=!0,clearTimeout(this.#it),this.#it=setTimeout(()=>{this.#et=!1},0)}onKeydown(t){"Enter"===t.key&&this.#t.sendOnEnter&&(t.shiftKey||t.altKey||t.ctrlKey||t.metaKey||t.isComposing||229===t.keyCode||this.#tt||this.#et||(t.preventDefault(),this.submit()))}submit(t){const e=t??this.#X;if(void 0===t&&!this.canSend)return!1;if(void 0!==t&&(this.#t.busy||this.#t.inputDisabled))return!1;if(""===e.trim())return!1;return!!xt(this.#t,wt.SUBMIT,{text:e},{cancelable:!0})&&(this.clear(),this.#t.handleSubmitted(),!0)}clear(){this.value="",this.focus()}focus(){this.#st?.focus()}#nt(){if(Kt)return;const t=this.#st;t&&(t.style.height="auto",t.style.height=`${t.scrollHeight}px`)}#ot(){const t=this.#t.renderRoot,e=t.querySelector('[part~="send-button"]');e&&(e.disabled=!this.canSend);const i=this.#st,s=t.querySelector('[part~="counter"]'),n=this.#t.maxLength;if(void 0===n)return;const o=n-this.length,r=o<0;if(i?.setAttribute("aria-invalid",r?"true":"false"),!s)return;s.textContent=String(o),s.toggleAttribute("data-over",r);const a=this.#t.currentLabels,h=r?a.overLimit:a.charactersLeft;s.setAttribute("aria-label",h.replace("{n}",String(Math.abs(o)))),s.hidden=this.length<=.8*n}}class Yt{#t;#rt;#at;#ht=!1;constructor(t,e){this.#t=t,this.#rt=e,t.addController(this)}hostConnected(){this.#lt=()=>{const t=this.#rt.current();t&&this.#rt.onMove(t)},window.addEventListener("resize",this.#lt)}hostDisconnected(){this.#lt&&window.removeEventListener("resize",this.#lt),this.#lt=void 0}#lt;consumeDrag(){const t=this.#ht;return this.#ht=!1,t}place(t){if(!t){for(const t of[this.#rt.vars.x,this.#rt.vars.y])this.#t.style.removeProperty(t);return}const e=this.#rt.element(),i=this.#ct(t),s=e?this.#dt(i,this.#rt.size()):i;return this.#t.style.setProperty(this.#rt.vars.x,`${s.x}px`),this.#t.style.setProperty(this.#rt.vars.y,`${s.y}px`),e?s:void 0}start(t){if(!this.#rt.enabled()||0!==t.button)return;if(this.#rt.element()){this.#at={pointer:{x:t.clientX,y:t.clientY},displacement:this.#rt.current()??{x:0,y:0},size:this.#rt.size(),corner:this.#rt.corner(),base:this.#rt.base(),moved:!1,pointerId:t.pointerId,target:t.currentTarget};try{this.#at.target.setPointerCapture(t.pointerId)}catch{}this.#at.target.addEventListener("pointermove",this.#pt),this.#at.target.addEventListener("pointerup",this.#ut),this.#at.target.addEventListener("pointercancel",this.#ut)}}#pt=t=>{const e=this.#at;if(!e||t.pointerId!==e.pointerId)return;const i=t.clientX-e.pointer.x,s=t.clientY-e.pointer.y;!e.moved&&Math.hypot(i,s)<4||(e.moved=!0,t.preventDefault(),this.#rt.onMove(this.#mt({x:e.displacement.x+i,y:e.displacement.y+s},e.base,e.corner,e.size)))};#ut=t=>{const e=this.#at;if(e&&t.pointerId===e.pointerId){e.target.removeEventListener("pointermove",this.#pt),e.target.removeEventListener("pointerup",this.#ut),e.target.removeEventListener("pointercancel",this.#ut);try{e.target.hasPointerCapture(t.pointerId)&&e.target.releasePointerCapture(t.pointerId)}catch{}this.#at=void 0,e.moved&&(this.#ht=!0,this.#rt.onSettle(this.#rt.name))}};nudge(t){if(!this.#rt.enabled())return!1;if(t.altKey||t.ctrlKey||t.metaKey)return!1;const e={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[t.key];if(!e)return!1;if(!this.#rt.element())return!1;const i=t.shiftKey?32:8,s=this.#rt.current()??{x:0,y:0};return t.preventDefault(),this.#rt.onMove(this.#mt({x:s.x+e[0]*i,y:s.y+e[1]*i},this.#rt.base(),this.#rt.corner(),this.#rt.size())),this.#rt.onSettle(this.#rt.name),!0}#ct(t,e=this.#rt.base(),i=this.#rt.corner()){return{x:e.x+(i.endsWith("right")?-t.x:t.x),y:e.y+(i.startsWith("bottom")?-t.y:t.y)}}#mt(t,e,i,s){const n=this.#dt(this.#ct(t,e,i),s);return{x:i.endsWith("right")?e.x-n.x:n.x-e.x,y:i.startsWith("bottom")?e.y-n.y:n.y-e.y}}#dt(t,e){return{x:Gt(t.x,window.innerWidth-e.width),y:Gt(t.y,window.innerHeight-e.height)}}}function Gt(t,e){return Math.round(Math.min(Math.max(t,8),Math.max(8,e-8)))}const Jt=new WeakMap,Zt=t=>`msg:${t}`,Qt=["text","html","template","element","component"];function Xt(t){const e=Qt.filter(e=>e in t);if(1===e.length)return e[0];if(0===e.length)throw new Error(`ChitUI: message "${t.id}" has no content. Give it one of html, template, element or component.`);throw new Error(`ChitUI: message "${t.id}" has ${e.join(" and ")}. Give it exactly one.`)}function te(t){return t[Xt(t)]}function ee(t,e,i,s={}){let n=Jt.get(t);n||(n=new Map,Jt.set(t,n));const o=n.get(e);if(o&&o.source===i){for(const[t,e]of Object.entries(s))Object.is(o.props[t],e)||(o.element[t]=e);return o.props={...s},o.element}const r=document.createElement(function(t){if("string"==typeof t)return t;const e=customElements,i=e.getName?.(t);if(i)return i;const s=t.tagName;if("string"==typeof s&&s)return s;throw new Error("ChitUI: component is not registered in customElements. Call customElements.define() for it, or pass its tag name as a string.")}(i));for(const[t,e]of Object.entries(s))r[t]=e;return n.set(e,{source:i,element:r,props:{...s}}),r}function ie(t,e){return Jt.get(t)?.get(Zt(e))?.element}function se(t,e){switch(Xt(e)){case"text":return e.text;case"template":return e.template;case"element":return e.element;case"component":{const i=e;return ee(t,Zt(e.id),i.component,i.props)}default:{const i=e.html;return yt(t.sanitize?t.sanitize(i):i)}}}function ne(t){const e=t.currentTheme.closed,i=t.currentLabels,s=e.component?ee(t,"launcher",e.component,e.props):null;return W`
|
|
1
|
+
var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),n=new WeakMap;let o=class{constructor(t,e,i){if(this._$cssResult$=!0,i!==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(i&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=n.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&n.set(e,t))}return t}toString(){return this.cssText}};const r=(t,...e)=>{const i=1===t.length?t[0]:e.reduce((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1],t[0]);return new o(i,t,s)},a=i?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new o("string"==typeof t?t:t+"",void 0,s))(e)})(t):t,{is:h,defineProperty:l,getOwnPropertyDescriptor:c,getOwnPropertyNames:d,getOwnPropertySymbols:p,getPrototypeOf:u}=Object,m=globalThis,f=m.trustedTypes,g=f?f.emptyScript:"",b=m.reactiveElementPolyfillSupport,v=(t,e)=>t,y={toAttribute(t,e){switch(e){case Boolean:t=t?g:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},w=(t,e)=>!h(t,e),x={attribute:!0,type:String,converter:y,reflect:!1,useDefault:!1,hasChanged:w};Symbol.metadata??=Symbol("metadata"),m.litPropertyMetadata??=new WeakMap;let $=class 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,e=x){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const i=Symbol(),s=this.getPropertyDescriptor(t,i,e);void 0!==s&&l(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){const{get:s,set:n}=c(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:s,set(e){const o=s?.call(this);n?.call(this,e),this.requestUpdate(t,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??x}static _$Ei(){if(this.hasOwnProperty(v("elementProperties")))return;const t=u(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(v("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(v("properties"))){const t=this.properties,e=[...d(t),...p(t)];for(const i of e)this.createProperty(i,t[i])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const i=this._$Eu(t,e);void 0!==i&&this._$Eh.set(i,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}static _$Eu(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"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 i of e.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,s)=>{if(i)t.adoptedStyleSheets=s.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const i of s){const s=document.createElement("style"),n=e.litNonce;void 0!==n&&s.setAttribute("nonce",n),s.textContent=i.cssText,t.appendChild(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,i){this._$AK(t,i)}_$ET(t,e){const i=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,i);if(void 0!==s&&!0===i.reflect){const n=(void 0!==i.converter?.toAttribute?i.converter:y).toAttribute(e,i.type);this._$Em=t,null==n?this.removeAttribute(s):this.setAttribute(s,n),this._$Em=null}}_$AK(t,e){const i=this.constructor,s=i._$Eh.get(t);if(void 0!==s&&this._$Em!==s){const t=i.getPropertyOptions(s),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:y;this._$Em=s;const o=n.fromAttribute(e,t.type);this[s]=o??this._$Ej?.get(s)??o,this._$Em=null}}requestUpdate(t,e,i,s=!1,n){if(void 0!==t){const o=this.constructor;if(!1===s&&(n=this[t]),i??=o.getPropertyOptions(t),!((i.hasChanged??w)(n,e)||i.useDefault&&i.reflect&&n===this._$Ej?.get(t)&&!this.hasAttribute(o._$Eu(t,i))))return;this.C(t,e,i)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:i,reflect:s,wrapped:n},o){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),!0!==n||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||i||(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,i]of t){const{wrapped:t}=i,s=this[e];!0!==t||this._$AL.has(e)||void 0===s||this.C(e,void 0,i,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){}};$.elementStyles=[],$.shadowRootOptions={mode:"open"},$[v("elementProperties")]=new Map,$[v("finalized")]=new Map,b?.({ReactiveElement:$}),(m.reactiveElementVersions??=[]).push("2.1.2");const _=globalThis,S=t=>t,A=_.trustedTypes,E=A?A.createPolicy("lit-html",{createHTML:t=>t}):void 0,k="$lit$",T=`lit$${Math.random().toFixed(9).slice(2)}$`,C="?"+T,O=`<${C}>`,L=document,M=()=>L.createComment(""),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,z=Array.isArray,U="[ \t\n\f\r]",R=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,H=/-->/g,D=/>/g,B=RegExp(`>|${U}(?:([^\\s"'>=/]+)(${U}*=${U}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),I=/'/g,N=/"/g,j=/^(?:script|style|textarea|title)$/i,q=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),W=q(1),F=q(2),K=Symbol.for("lit-noChange"),V=Symbol.for("lit-nothing"),Y=new WeakMap,G=L.createTreeWalker(L,129);function J(t,e){if(!z(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==E?E.createHTML(e):e}class X{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let n=0,o=0;const r=t.length-1,a=this.parts,[h,l]=((t,e)=>{const i=t.length-1,s=[];let n,o=2===e?"<svg>":3===e?"<math>":"",r=R;for(let e=0;e<i;e++){const i=t[e];let a,h,l=-1,c=0;for(;c<i.length&&(r.lastIndex=c,h=r.exec(i),null!==h);)c=r.lastIndex,r===R?"!--"===h[1]?r=H:void 0!==h[1]?r=D:void 0!==h[2]?(j.test(h[2])&&(n=RegExp("</"+h[2],"g")),r=B):void 0!==h[3]&&(r=B):r===B?">"===h[0]?(r=n??R,l=-1):void 0===h[1]?l=-2:(l=r.lastIndex-h[2].length,a=h[1],r=void 0===h[3]?B:'"'===h[3]?N:I):r===N||r===I?r=B:r===H||r===D?r=R:(r=B,n=void 0);const d=r===B&&t[e+1].startsWith("/>")?" ":"";o+=r===R?i+O:l>=0?(s.push(a),i.slice(0,l)+k+i.slice(l)+T+d):i+T+(-2===l?e:d)}return[J(t,o+(t[i]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),s]})(t,e);if(this.el=X.createElement(h,i),G.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=G.nextNode())&&a.length<r;){if(1===s.nodeType){if(s.hasAttributes())for(const t of s.getAttributeNames())if(t.endsWith(k)){const e=l[o++],i=s.getAttribute(t).split(T),r=/([.?@])?(.*)/.exec(e);a.push({type:1,index:n,name:r[2],strings:i,ctor:"."===r[1]?it:"?"===r[1]?st:"@"===r[1]?nt:et}),s.removeAttribute(t)}else t.startsWith(T)&&(a.push({type:6,index:n}),s.removeAttribute(t));if(j.test(s.tagName)){const t=s.textContent.split(T),e=t.length-1;if(e>0){s.textContent=A?A.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],M()),G.nextNode(),a.push({type:2,index:++n});s.append(t[e],M())}}}else if(8===s.nodeType)if(s.data===C)a.push({type:2,index:n});else{let t=-1;for(;-1!==(t=s.data.indexOf(T,t+1));)a.push({type:7,index:n}),t+=T.length-1}n++}}static createElement(t,e){const i=L.createElement("template");return i.innerHTML=t,i}}function Z(t,e,i=t,s){if(e===K)return e;let n=void 0!==s?i._$Co?.[s]:i._$Cl;const o=P(e)?void 0:e._$litDirective$;return n?.constructor!==o&&(n?._$AO?.(!1),void 0===o?n=void 0:(n=new o(t),n._$AT(t,i,s)),void 0!==s?(i._$Co??=[])[s]=n:i._$Cl=n),void 0!==n&&(e=Z(t,n._$AS(t,e.values),n,s)),e}class Q{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:i}=this._$AD,s=(t?.creationScope??L).importNode(e,!0);G.currentNode=s;let n=G.nextNode(),o=0,r=0,a=i[0];for(;void 0!==a;){if(o===a.index){let e;2===a.type?e=new tt(n,n.nextSibling,this,t):1===a.type?e=new a.ctor(n,a.name,a.strings,this,t):6===a.type&&(e=new ot(n,this,t)),this._$AV.push(e),a=i[++r]}o!==a?.index&&(n=G.nextNode(),o++)}return G.currentNode=L,s}p(t){let e=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class tt{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,i,s){this.type=2,this._$AH=V,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Z(this,t,e),P(t)?t===V||null==t||""===t?(this._$AH!==V&&this._$AR(),this._$AH=V):t!==this._$AH&&t!==K&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>z(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==V&&P(this._$AH)?this._$AA.nextSibling.data=t:this.T(L.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=X.createElement(J(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new Q(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=Y.get(t.strings);return void 0===e&&Y.set(t.strings,e=new X(t)),e}k(t){z(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const n of t)s===e.length?e.push(i=new tt(this.O(M()),this.O(M()),this,this.options)):i=e[s],i._$AI(n),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){const e=S(t).nextSibling;S(t).remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class et{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,i,s,n){this.type=1,this._$AH=V,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=n,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=V}_$AI(t,e=this,i,s){const n=this.strings;let o=!1;if(void 0===n)t=Z(this,t,e,0),o=!P(t)||t!==this._$AH&&t!==K,o&&(this._$AH=t);else{const s=t;let r,a;for(t=n[0],r=0;r<n.length-1;r++)a=Z(this,s[i+r],e,r),a===K&&(a=this._$AH[r]),o||=!P(a)||a!==this._$AH[r],a===V?t=V:t!==V&&(t+=(a??"")+n[r+1]),this._$AH[r]=a}o&&!s&&this.j(t)}j(t){t===V?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class it extends et{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===V?void 0:t}}class st extends et{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==V)}}class nt extends et{constructor(t,e,i,s,n){super(t,e,i,s,n),this.type=5}_$AI(t,e=this){if((t=Z(this,t,e,0)??V)===K)return;const i=this._$AH,s=t===V&&i!==V||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,n=t!==V&&(i===V||s);s&&this.element.removeEventListener(this.name,this,i),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class ot{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Z(this,t)}}const rt={I:tt},at=_.litHtmlPolyfillSupport;at?.(X,tt),(_.litHtmlVersions??=[]).push("3.3.3");const ht=(t,e,i)=>{const s=i?.renderBefore??e;let n=s._$litPart$;if(void 0===n){const t=i?.renderBefore??null;s._$litPart$=n=new tt(e.insertBefore(M(),t),t,void 0,i??{})}return n._$AI(t),n},lt=globalThis;let ct=class extends ${constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=ht(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return K}};ct._$litElement$=!0,ct.finalized=!0,lt.litElementHydrateSupport?.({LitElement:ct});const dt=lt.litElementPolyfillSupport;dt?.({LitElement:ct}),(lt.litElementVersions??=[]).push("4.2.2");const pt=1,ut=2,mt=3,ft=4,gt=t=>(...e)=>({_$litDirective$:t,values:e});let bt=class{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}},vt=class extends bt{constructor(t){if(super(t),this.it=V,t.type!==ut)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===V||null==t)return this._t=void 0,this.it=t;if(t===K)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const e=[t];return e.raw=e,this._t={_$litType$:this.constructor.resultType,strings:e,values:[]}}};vt.directiveName="unsafeHTML",vt.resultType=1;const yt=gt(vt),wt=Object.freeze({SUBMIT:"chat-submit",BEFORE_OPEN:"chat-before-open",OPEN:"chat-open",BEFORE_CLOSE:"chat-before-close",CLOSE:"chat-close",HIDE:"chat-hide",SHOW:"chat-show",STATE_CHANGE:"chat-state-change",INPUT:"chat-input",MESSAGE_RENDER:"chat-message-render",MESSAGE_CLICK:"chat-message-click",SCROLL_TOP:"chat-scroll-top",BREAKPOINT_CHANGE:"chat-breakpoint-change",HOME:"chat-home",ATTACH:"chat-attach",MOVE:"chat-move"});function xt(t,e,i,{cancelable:s=!1}={}){return t.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,composed:!0,cancelable:s}))}const $t={closed:"launcher",open:"panel",hidden:null};class _t{#t;#e;#i;#s;#n="closed";#o="closed";#r=!1;#a=0;#h=null;#l=null;#c=!1;constructor(t,{animation:e,keepsLauncher:i,onOpened:s}){this.#t=t,this.#e=e,this.#i=i,this.#s=s,t.addController(this)}get renderedState(){return this.#o}get applying(){return this.#r}hostConnected(){this.#n=this.#t.state,this.#o=this.#t.state,this.#t.dataset.renderedState=this.#o}hostDisconnected(){this.#l?.(),this.#l=null,this.#h?.(!1),this.#h=null}hostUpdated(){this.#t.dataset.renderedState=this.#o}request(t,e){const i=this.#n;return t===i?Promise.resolve(!0):this.#d(i,t,e)?(this.#p(),this.#n=t,this.#u(t),xt(this.#t,wt.STATE_CHANGE,{from:i,to:t,trigger:e}),this.#m(i,t,e)):(this.#u(i),Promise.resolve(!1))}#d(t,e,i){return"open"===e?xt(this.#t,wt.BEFORE_OPEN,{from:t,trigger:i},{cancelable:!0}):"closed"!==e||"open"!==t||xt(this.#t,wt.BEFORE_CLOSE,{from:t,trigger:i},{cancelable:!0})}#p(){this.#a+=1,this.#l?.(),this.#l=null,this.#h?.(!1),this.#h=null,this.#o!==this.#n&&(this.#o=this.#n,this.#t.requestUpdate())}#m(t,e,i){const s=this.#a,n=new Promise(t=>{this.#h=t});return(async()=>{if(this.#c=this.#f(),await this.#t.updateComplete,s!==this.#a)return;const n=this.#g(t);if(n&&!this.#b(t,e)&&(await this.#v(n,"exit",this.#e(t,e,"exit")),s!==this.#a))return;if(this.#o=e,this.#t.requestUpdate(),await this.#t.updateComplete,s!==this.#a)return;const o=this.#g(e);o&&(await this.#v(o,"enter",this.#e(t,e,"enter")),s!==this.#a)||(this.#y(t,e,i),this.#w(e),this.#h?.(!0),this.#h=null)})(),n}#b(t,e){return"closed"===t&&"open"===e&&this.#i()}#y(t,e,i){"hidden"===t&&xt(this.#t,wt.SHOW,{from:t,to:e}),"hidden"!==e?"open"===e?xt(this.#t,wt.OPEN,{from:t,trigger:i}):"closed"===e&&"open"===t&&xt(this.#t,wt.CLOSE,{from:t,trigger:i}):xt(this.#t,wt.HIDE,{from:t,to:e})}#w(t){"open"!==t?("closed"===t&&this.#c&&this.#g("closed")?.focus(),this.#c=!1):this.#s()}#f(){const t=this.#t.renderRoot instanceof ShadowRoot?this.#t.renderRoot.activeElement:null,e=this.#g("open");return!(!t||!e||t!==e&&!e.contains(t))}#g(t){const e=$t[t];return e?this.#t.renderRoot.querySelector(`[part~="${e}"]`):null}#u(t){this.#t.state!==t&&(this.#r=!0,this.#t.state=t,this.#r=!1)}#v(t,e,i){const{effect:s,duration:n}=i;return"none"===s||n<=0||window.matchMedia("(prefers-reduced-motion: reduce)").matches?Promise.resolve():new Promise(i=>{let o=!1;const r=e=>{e&&e.target!==t||o||(o=!0,clearTimeout(a),t.removeEventListener("animationend",r),t.removeAttribute("data-anim"),t.style.removeProperty("--_chit-anim-duration"),this.#l===r&&(this.#l=null),i())};t.dataset.effect=s,t.dataset.anim=e,t.style.setProperty("--_chit-anim-duration",`${n}ms`),t.addEventListener("animationend",r);const a=setTimeout(r,n+50);this.#l=r})}}class St{#t;#x=null;#$=0;#_="pc";#S=!1;constructor(t){this.#t=t,t.addController(this)}get device(){return this.#_}hostDisconnected(){this.#x?.removeEventListener("change",this.#A),this.#x=null}observe(t){t===this.#$&&this.#x||(this.#$=t,this.#x?.removeEventListener("change",this.#A),this.#x=window.matchMedia(`(max-width: ${t-1}px)`),this.#x.addEventListener("change",this.#A),this.#E(this.#x.matches?"mobile":"pc"))}#A=t=>{this.#E(t.matches?"mobile":"pc")};#E(t){t===this.#_&&this.#t.dataset.device||(this.#_=t,this.#t.dataset.device=t,this.#t.requestUpdate(),this.#S&&xt(this.#t,wt.BREAKPOINT_CHANGE,{device:t}),this.#S=!0)}}const At="#2563eb",Et="#1f2328",kt="#5c6370",Tt="#ffffff",Ct="#f1f3f5",Ot="#e4e4e7",Lt="#ffffff",Mt={size:60,position:"bottom-right",offset:{x:24,y:24},radius:30,draggable:!1,image:null,label:null,component:null,props:{},colors:{background:At,text:Lt,shadow:"0 4px 12px rgba(0, 0, 0, 0.2)"},animation:{enter:"scale",exit:"scale",duration:200,idle:"none"}},Pt={size:56,offset:{x:16,y:16},radius:28},zt={breakpoint:768,zIndex:2147483e3,font:{family:"system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif",size:14},closed:{pc:Mt,mobile:{...Mt,...Pt}},open:{width:380,height:600,position:"bottom-right",offset:{x:24,y:24},radius:16,launcher:"hidden",draggable:!1,header:{visible:!0,title:null,logo:null,home:!1},background:{image:null},colors:{background:Tt,text:Et,accent:At,border:Ot,shadow:"0 8px 32px rgba(0, 0, 0, 0.24)",headerBackground:Tt,headerText:Et,userBubble:At,userText:Lt,assistantBubble:Ct,assistantText:Et,systemText:kt,inputBackground:Tt,inputText:Et,inputPlaceholder:kt},bubble:{radius:14,tail:"none"},loading:{auto:!1,style:"spinner",text:null,timeout:0},speaker:{assistant:{name:null,avatar:null},user:{name:null,avatar:null}},animation:{enter:"scale",exit:"fade",duration:150,scroll:"smooth"},input:{maxRows:5,placeholder:null,attach:!1,accept:"image/*,video/*",multiple:!1}},hidden:{animation:{exit:"fade",duration:150}}},Ut=Pt;function Rt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function Ht(t,e){if(!Rt(e))return t;const i={...t};for(const[t,s]of Object.entries(e)){if(void 0===s)continue;const e=i[t];i[t]=Rt(s)&&Rt(e)?Ht(e,s):s}return i}function Dt(t,e){const i=t??{},s=function(t,e){const i=t??{};if(!("pc"in i)&&!("mobile"in i)){const i=t??{};return Ht(zt.closed[e],i)}const s=Ht(zt.closed.pc,i.pc);return"pc"===e?s:i.mobile?Ht(zt.closed.mobile,i.mobile):Ht(s,Ut)}(i.closed,e);return{breakpoint:i.breakpoint??zt.breakpoint,zIndex:i.zIndex??zt.zIndex,font:Ht(zt.font,i.font),closed:Ht(zt.closed[e],s),open:Ht(zt.open,i.open),hidden:Ht(zt.hidden,i.hidden),device:e}}const Bt=t=>`${t}px`;function It(t){return t?`url("${t.replace(/[\\"]/g,"\\$&")}")`:"none"}function Nt(t){const e=Object.entries(function(t){const{closed:e,open:i}=t,s=i.colors;return{"--chit-z-index":String(t.zIndex),"--chit-font-family":t.font.family,"--chit-font-size":Bt(t.font.size),"--chit-launcher-size":"auto"===e.size?"auto":Bt(e.size),"--chit-launcher-offset-x":Bt(e.offset.x),"--chit-launcher-offset-y":Bt(e.offset.y),"--chit-launcher-radius":Bt(e.radius),"--chit-launcher-image":It(e.image),"--chit-launcher-bg":e.colors.background,"--chit-launcher-text":e.colors.text,"--chit-launcher-shadow":e.colors.shadow,"--chit-panel-width":Bt(i.width),"--chit-panel-height":Bt(i.height),"--chit-panel-offset-x":Bt(i.offset.x),"--chit-panel-offset-y":Bt(i.offset.y),"--chit-panel-radius":Bt(i.radius),"--chit-panel-bg-image":It(i.background.image),"--chit-panel-shadow":s.shadow,"--chit-color-bg":s.background,"--chit-color-text":s.text,"--chit-color-accent":s.accent,"--chit-color-border":s.border,"--chit-color-header-bg":s.headerBackground,"--chit-color-header-text":s.headerText,"--chit-color-user-bg":s.userBubble,"--chit-color-user-text":s.userText,"--chit-color-assistant-bg":s.assistantBubble,"--chit-color-assistant-text":s.assistantText,"--chit-color-system-text":s.systemText,"--chit-color-input-bg":s.inputBackground,"--chit-color-input-text":s.inputText,"--chit-color-input-placeholder":s.inputPlaceholder,"--chit-bubble-radius":Bt(i.bubble.radius),"--_chit-input-max-rows":String(i.input.maxRows),"--_chit-speaker-gutter":i.speaker.assistant.avatar?"2.5em":"0px"}}(t)).map(([t,e])=>` ${t}: ${e};`).join("\n");return`:host {\n${e}\n}\n`}const jt="undefined"!=typeof ShadowRoot&&"adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype;class qt{#k=null;#T=null;#C="";#O;constructor(t){this.#O=t}attach(t){if(t instanceof ShadowRoot){if(jt)return this.#k||(this.#k=new CSSStyleSheet),void(t.adoptedStyleSheets.includes(this.#k)||(t.adoptedStyleSheets=[...t.adoptedStyleSheets,this.#k]));this.#T||(this.#T=document.createElement("style"),this.#T.setAttribute(this.#O,"")),this.#T.parentNode!==t&&t.append(this.#T)}}write(t,e){if(t!==this.#C){if(this.attach(e),this.#k)this.#k.replaceSync(t);else{if(!this.#T)return;this.#T.textContent=t}this.#C=t}}detach(){this.#T?.remove(),this.#T=null}}class Wt{#t;#k=new qt("data-chit-theme");#L;constructor(t,{device:e}){this.#t=t,this.#L=Dt(void 0,e())}get current(){return this.#L}hostConnected(){this.#M()}hostDisconnected(){this.#k.detach()}static breakpointOf(t){return function(t){return t?.breakpoint??zt.breakpoint}(t)}apply(t,e){this.#L=Dt(t,e),this.#M()}#M(){this.#k.write(Nt(this.#L),this.#t.renderRoot)}}class Ft{#t;#P;#z=null;#U=null;#R=!0;#H=!1;#D=!1;#B=!0;#I=!1;#N;#j=!0;#q=0;#W;#F=0;constructor(t,{behavior:e}){this.#t=t,this.#P=e,t.addController(this)}get hasUnseen(){return this.#H}get atBottom(){return this.#R}hostDisconnected(){this.#K(),clearTimeout(this.#N)}hostUpdate(){const t=this.#t.messages,e=t[t.length-1],i=t.length>this.#F,s=e?.id!==this.#W;this.#W=e?.id,this.#F=t.length,(i||s)&&(this.#R||"user"===e?.role?this.#B=!0:this.#H=!0)}hostUpdated(){const t=this.#t.renderRoot.querySelector('[part~="messages"]');if(t!==this.#z&&(this.#K(),this.#z=t,this.#V(),t&&(this.#R=!0,this.#H=!1,this.#B=!0,this.#j=!0)),this.#B){const t=this.#Y;this.#B=!1,this.#G({behavior:t})}}#V(){if(!this.#z)return;this.#q=this.#z.clientHeight,this.#z.addEventListener("scroll",this.#J,{passive:!0}),this.#z.addEventListener("scrollend",this.#X);const t=this.#z.firstElementChild;t&&"undefined"!=typeof ResizeObserver&&(this.#U=new ResizeObserver(()=>{this.#q=this.#z?.clientHeight??0,this.#R&&this.#G({behavior:this.#I?"smooth":"instant"})}),this.#U.observe(t),this.#U.observe(this.#z))}#K(){this.#z?.removeEventListener("scroll",this.#J),this.#z?.removeEventListener("scrollend",this.#X),this.#U?.disconnect(),this.#U=null,this.#z=null}#X=()=>{this.#Z()};#J=()=>{const t=this.#z;if(!t)return;if(t.clientHeight!==this.#q)return void(this.#q=t.clientHeight);const e=t.scrollHeight-t.scrollTop-t.clientHeight<=24;if(this.#I)return void(e&&this.#Z());e!==this.#R&&(this.#R=e,e&&this.#H&&(this.#H=!1,this.#t.requestUpdate()));const i=t.scrollTop<=0;i&&!this.#D&&xt(this.#t,wt.SCROLL_TOP,{}),this.#D=i};scrollToBottom({smooth:t}={}){const e=void 0===t?this.#Y:t?"smooth":"instant";this.#G({behavior:e}),this.#H&&(this.#H=!1,this.#t.requestUpdate())}get#Y(){return this.#j||window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":this.#P()}#G({behavior:t="instant"}={}){const e=this.#z;e&&(this.#j=!1,"smooth"===t&&this.#Q(),e.scrollTo({top:e.scrollHeight,behavior:t}),this.#R=!0,this.#D=!1,this.#H=!1)}#Q(){this.#I=!0,clearTimeout(this.#N),this.#N=setTimeout(()=>this.#Z(),700)}#Z(){if(!this.#I)return;this.#I=!1,clearTimeout(this.#N);const t=this.#z;if(!t)return;const e=t.scrollHeight-t.scrollTop-t.clientHeight;this.#R=e<=24}}const Kt="undefined"!=typeof CSS&&CSS.supports?.("field-sizing","content");class Vt{#t;#tt="";#et=!1;#it=!1;#st;constructor(t){this.#t=t,t.addController(this)}get value(){return this.#tt}set value(t){this.#tt=t??"";const e=this.#nt;e&&e.value!==this.#tt&&(e.value=this.#tt),this.#ot(),this.#rt()}get composing(){return this.#et}get length(){return Array.from(this.#tt).length}get canSend(){if(this.#t.busy||this.#t.inputDisabled)return!1;if(""===this.#tt.trim())return!1;const t=this.#t.maxLength;return void 0===t||this.length<=t}hostDisconnected(){clearTimeout(this.#st)}hostUpdated(){const t=this.#nt;t&&t.value!==this.#tt&&(t.value=this.#tt),this.#ot(),this.#rt()}get#nt(){return this.#t.renderRoot.querySelector('[part~="input"]')}onInput(t){this.#tt=t.target.value,this.#ot(),this.#rt(),xt(this.#t,wt.INPUT,{value:this.#tt})}onCompositionStart(){this.#et=!0}onCompositionEnd(){this.#et=!1,this.#it=!0,clearTimeout(this.#st),this.#st=setTimeout(()=>{this.#it=!1},0)}onKeydown(t){"Enter"===t.key&&this.#t.sendOnEnter&&(t.shiftKey||t.altKey||t.ctrlKey||t.metaKey||t.isComposing||229===t.keyCode||this.#et||this.#it||(t.preventDefault(),this.submit()))}submit(t){const e=t??this.#tt;if(void 0===t&&!this.canSend)return!1;if(void 0!==t&&(this.#t.busy||this.#t.inputDisabled))return!1;if(""===e.trim())return!1;return!!xt(this.#t,wt.SUBMIT,{text:e},{cancelable:!0})&&(this.clear(),this.#t.handleSubmitted(),!0)}clear(){this.value="",this.focus()}focus(){this.#nt?.focus()}#ot(){if(Kt)return;const t=this.#nt;t&&(t.style.height="auto",t.style.height=`${t.scrollHeight}px`)}#rt(){const t=this.#t.renderRoot,e=t.querySelector('[part~="send-button"]');e&&(e.disabled=!this.canSend);const i=this.#nt,s=t.querySelector('[part~="counter"]'),n=this.#t.maxLength;if(void 0===n)return;const o=n-this.length,r=o<0;if(i?.setAttribute("aria-invalid",r?"true":"false"),!s)return;s.textContent=String(o),s.toggleAttribute("data-over",r);const a=this.#t.currentLabels,h=r?a.overLimit:a.charactersLeft;s.setAttribute("aria-label",h.replace("{n}",String(Math.abs(o)))),s.hidden=this.length<=.8*n}}class Yt{#t;#at;#ht;#lt=!1;constructor(t,e){this.#t=t,this.#at=e,t.addController(this)}hostConnected(){this.#ct=()=>{const t=this.#at.current();t&&this.#at.onMove(t)},window.addEventListener("resize",this.#ct)}hostDisconnected(){this.#ct&&window.removeEventListener("resize",this.#ct),this.#ct=void 0}#ct;consumeDrag(){const t=this.#lt;return this.#lt=!1,t}place(t){if(!t){for(const t of[this.#at.vars.x,this.#at.vars.y])this.#t.style.removeProperty(t);return}const e=this.#at.element(),i=this.#dt(t),s=e?this.#pt(i,this.#at.size()):i;return this.#t.style.setProperty(this.#at.vars.x,`${s.x}px`),this.#t.style.setProperty(this.#at.vars.y,`${s.y}px`),e?s:void 0}start(t){if(!this.#at.enabled()||0!==t.button)return;if(this.#at.element()){this.#ht={pointer:{x:t.clientX,y:t.clientY},displacement:this.#at.current()??{x:0,y:0},size:this.#at.size(),corner:this.#at.corner(),base:this.#at.base(),moved:!1,pointerId:t.pointerId,target:t.currentTarget};try{this.#ht.target.setPointerCapture(t.pointerId)}catch{}this.#ht.target.addEventListener("pointermove",this.#ut),this.#ht.target.addEventListener("pointerup",this.#mt),this.#ht.target.addEventListener("pointercancel",this.#mt)}}#ut=t=>{const e=this.#ht;if(!e||t.pointerId!==e.pointerId)return;const i=t.clientX-e.pointer.x,s=t.clientY-e.pointer.y;!e.moved&&Math.hypot(i,s)<4||(e.moved=!0,t.preventDefault(),this.#at.onMove(this.#ft({x:e.displacement.x+i,y:e.displacement.y+s},e.base,e.corner,e.size)))};#mt=t=>{const e=this.#ht;if(e&&t.pointerId===e.pointerId){e.target.removeEventListener("pointermove",this.#ut),e.target.removeEventListener("pointerup",this.#mt),e.target.removeEventListener("pointercancel",this.#mt);try{e.target.hasPointerCapture(t.pointerId)&&e.target.releasePointerCapture(t.pointerId)}catch{}this.#ht=void 0,e.moved&&(this.#lt=!0,this.#at.onSettle(this.#at.name))}};nudge(t){if(!this.#at.enabled())return!1;if(t.altKey||t.ctrlKey||t.metaKey)return!1;const e={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[t.key];if(!e)return!1;if(!this.#at.element())return!1;const i=t.shiftKey?32:8,s=this.#at.current()??{x:0,y:0};return t.preventDefault(),this.#at.onMove(this.#ft({x:s.x+e[0]*i,y:s.y+e[1]*i},this.#at.base(),this.#at.corner(),this.#at.size())),this.#at.onSettle(this.#at.name),!0}#dt(t,e=this.#at.base(),i=this.#at.corner()){return{x:e.x+(i.endsWith("right")?-t.x:t.x),y:e.y+(i.startsWith("bottom")?-t.y:t.y)}}#ft(t,e,i,s){const n=this.#pt(this.#dt(t,e,i),s);return{x:i.endsWith("right")?e.x-n.x:n.x-e.x,y:i.startsWith("bottom")?e.y-n.y:n.y-e.y}}#pt(t,e){return{x:Gt(t.x,window.innerWidth-e.width),y:Gt(t.y,window.innerHeight-e.height)}}}function Gt(t,e){return Math.round(Math.min(Math.max(t,8),Math.max(8,e-8)))}const Jt=/^(auto|scroll|overlay)$/;class Xt{#t;#gt=null;#bt;constructor(t){this.#t=t,t.addController(this)}hostUpdated(){const t=this.#t.renderRoot?.querySelector('[part~="panel"]')??null;t!==this.#gt&&(this.#K(),this.#gt=t,this.#V())}hostDisconnected(){this.#K()}#V(){const t=this.#gt;t&&(t.addEventListener("touchstart",this.#vt,{passive:!0}),t.addEventListener("touchmove",this.#yt,{passive:!1}),t.addEventListener("touchend",this.#wt,{passive:!0}),t.addEventListener("touchcancel",this.#wt,{passive:!0}))}#K(){const t=this.#gt;t&&(t.removeEventListener("touchstart",this.#vt),t.removeEventListener("touchmove",this.#yt),t.removeEventListener("touchend",this.#wt),t.removeEventListener("touchcancel",this.#wt),this.#gt=null,this.#bt=void 0)}#vt=t=>{if(1!==t.touches.length)return void(this.#bt=void 0);const e=t.touches[0];this.#bt={x:e.clientX,y:e.clientY,verdict:"undecided"}};#wt=()=>{this.#bt=void 0};#yt=t=>{const e=this.#bt;if(!e)return;if(t.touches.length>1)return void(this.#bt=void 0);if("block"===e.verdict)return void(t.cancelable&&t.preventDefault());if("allow"===e.verdict)return;const i=t.touches[0],s=i.clientX-e.x,n=i.clientY-e.y;if(Math.abs(s)<3&&Math.abs(n)<3)return;const o=Math.abs(n)>=Math.abs(s),r=this.#xt(t,o,o?n:s);e.verdict=r?"allow":"block",!r&&t.cancelable&&t.preventDefault()};#xt(t,e,i){const s=this.#gt;if(!s)return!0;for(const n of t.composedPath())if(n instanceof HTMLElement){if(this.#$t(n,e,i))return!0;if(n===s)break}return!1}#$t(t,e,i){const s=getComputedStyle(t),n=e?s.overflowY:s.overflowX;if(!Jt.test(n))return!1;const o=e?t.scrollTop:t.scrollLeft,r=e?t.clientHeight:t.clientWidth,a=e?t.scrollHeight:t.scrollWidth;return!(a<=r+1)&&(i>0?o>1:o<a-r-1)}}class Zt{#t;#_t;#A;#St=!1;constructor(t,{enabled:e}){this.#t=t,this.#_t=e,t.addController(this)}hostConnected(){const t=window.visualViewport;t&&(this.#A=()=>this.#E(),t.addEventListener("resize",this.#A),t.addEventListener("scroll",this.#A))}hostDisconnected(){const t=window.visualViewport;t&&this.#A&&(t.removeEventListener("resize",this.#A),t.removeEventListener("scroll",this.#A)),this.#A=void 0,this.#At()}hostUpdated(){this.#E()}#E(){const t=window.visualViewport,e=this.#t.renderRoot?.querySelector('[part~="panel"]');t&&e&&this.#_t()&&!(t.scale>1.01)?(this.#t.style.setProperty("--_chit-vv-top",`${Math.round(t.offsetTop)}px`),this.#t.style.setProperty("--_chit-vv-height",`${Math.round(t.height)}px`),this.#St=!0):this.#At()}#At(){this.#St&&(this.#t.style.removeProperty("--_chit-vv-top"),this.#t.style.removeProperty("--_chit-vv-height"),this.#St=!1)}}const Qt=new WeakMap,te=t=>`msg:${t}`,ee=["text","html","template","element","component"];function ie(t){const e=ee.filter(e=>e in t);if(1===e.length)return e[0];if(0===e.length)throw new Error(`ChitUI: message "${t.id}" has no content. Give it one of html, template, element or component.`);throw new Error(`ChitUI: message "${t.id}" has ${e.join(" and ")}. Give it exactly one.`)}function se(t){return t[ie(t)]}function ne(t,e,i,s={}){let n=Qt.get(t);n||(n=new Map,Qt.set(t,n));const o=n.get(e);if(o&&o.source===i){for(const[t,e]of Object.entries(s))Object.is(o.props[t],e)||(o.element[t]=e);return o.props={...s},o.element}const r=document.createElement(function(t){if("string"==typeof t)return t;const e=customElements,i=e.getName?.(t);if(i)return i;const s=t.tagName;if("string"==typeof s&&s)return s;throw new Error("ChitUI: component is not registered in customElements. Call customElements.define() for it, or pass its tag name as a string.")}(i));for(const[t,e]of Object.entries(s))r[t]=e;return n.set(e,{source:i,element:r,props:{...s}}),r}function oe(t,e){return Qt.get(t)?.get(te(e))?.element}function re(t,e){switch(ie(e)){case"text":return e.text;case"template":return e.template;case"element":return e.element;case"component":{const i=e;return ne(t,te(e.id),i.component,i.props)}default:{const i=e.html;return yt(t.sanitize?t.sanitize(i):i)}}}function ae(t){const e=t.currentTheme.closed,i=t.currentLabels,s=e.component?ne(t,"launcher",e.component,e.props):null;return W`
|
|
2
2
|
<button
|
|
3
3
|
part="launcher"
|
|
4
4
|
type="button"
|
|
@@ -20,9 +20,9 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
20
20
|
</svg>
|
|
21
21
|
`}()}(e)}</slot>`}
|
|
22
22
|
</button>
|
|
23
|
-
`}const{I:
|
|
23
|
+
`}const{I:he}=rt,le=t=>t,ce=()=>document.createComment(""),de=(t,e,i)=>{const s=t._$AA.parentNode,n=void 0===e?t._$AB:e._$AA;if(void 0===i){const e=s.insertBefore(ce(),n),o=s.insertBefore(ce(),n);i=new he(e,o,t,t.options)}else{const e=i._$AB.nextSibling,o=i._$AM,r=o!==t;if(r){let e;i._$AQ?.(t),i._$AM=t,void 0!==i._$AP&&(e=t._$AU)!==o._$AU&&i._$AP(e)}if(e!==n||r){let t=i._$AA;for(;t!==e;){const e=le(t).nextSibling;le(s).insertBefore(t,n),t=e}}}return i},pe=(t,e,i=t)=>(t._$AI(e,i),t),ue={},me=(t,e=ue)=>t._$AH=e,fe=t=>{t._$AR(),t._$AA.remove()},ge=(t,e,i)=>{const s=new Map;for(let n=e;n<=i;n++)s.set(t[n],n);return s},be=gt(class extends bt{constructor(t){if(super(t),t.type!==ut)throw Error("repeat() can only be used in text expressions")}dt(t,e,i){let s;void 0===i?i=e:void 0!==e&&(s=e);const n=[],o=[];let r=0;for(const e of t)n[r]=s?s(e,r):r,o[r]=i(e,r),r++;return{values:o,keys:n}}render(t,e,i){return this.dt(t,e,i).values}update(t,[e,i,s]){const n=(t=>t._$AH)(t),{values:o,keys:r}=this.dt(e,i,s);if(!Array.isArray(n))return this.ut=r,o;const a=this.ut??=[],h=[];let l,c,d=0,p=n.length-1,u=0,m=o.length-1;for(;d<=p&&u<=m;)if(null===n[d])d++;else if(null===n[p])p--;else if(a[d]===r[u])h[u]=pe(n[d],o[u]),d++,u++;else if(a[p]===r[m])h[m]=pe(n[p],o[m]),p--,m--;else if(a[d]===r[m])h[m]=pe(n[d],o[m]),de(t,h[m+1],n[d]),d++,m--;else if(a[p]===r[u])h[u]=pe(n[p],o[u]),de(t,n[d],n[p]),p--,u++;else if(void 0===l&&(l=ge(r,u,m),c=ge(a,d,p)),l.has(a[d]))if(l.has(a[p])){const e=c.get(r[u]),i=void 0!==e?n[e]:null;if(null===i){const e=de(t,n[d]);pe(e,o[u]),h[u]=e}else h[u]=pe(i,o[u]),de(t,n[d],i),n[e]=null;u++}else fe(n[p]),p--;else fe(n[d]),d++;for(;u<=m;){const e=de(t,h[m+1]);pe(e,o[u]),h[u++]=e}for(;d<=p;){const t=n[d++];null!==t&&fe(t)}return this.ut=r,me(t,h),K}});function ve(t,e){if("system"===e.role)return W`
|
|
24
24
|
<article part="message message-system" data-role="system" data-id=${e.id}>
|
|
25
|
-
<div part="message-content" data-content=${
|
|
25
|
+
<div part="message-content" data-content=${ie(e)}>${re(t,e)}</div>
|
|
26
26
|
</article>
|
|
27
27
|
`;const i=e.time||e.status,s=t.currentTheme.open.speaker[e.role],n=void 0===e.avatar?s.avatar:e.avatar,o=void 0===e.name?s.name:e.name;return W`
|
|
28
28
|
<article
|
|
@@ -36,7 +36,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
36
36
|
<div class="body">
|
|
37
37
|
${o?W`<span part="name">${o}</span>`:V}
|
|
38
38
|
<div part="bubble">
|
|
39
|
-
<div part="message-content" data-content=${
|
|
39
|
+
<div part="message-content" data-content=${ie(e)}>${re(t,e)}</div>
|
|
40
40
|
${e.streaming?W`<span part="cursor" aria-hidden="true"></span>`:V}
|
|
41
41
|
</div>
|
|
42
42
|
${i?W`
|
|
@@ -49,7 +49,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
49
49
|
`:V}
|
|
50
50
|
</div>
|
|
51
51
|
</article>
|
|
52
|
-
`}function
|
|
52
|
+
`}function ye(t){const e=t.currentLabels,i=t.typing,s=0===t.messages.length&&!i&&!t.loading;return W`
|
|
53
53
|
<div
|
|
54
54
|
part="messages"
|
|
55
55
|
role="log"
|
|
@@ -60,7 +60,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
60
60
|
>
|
|
61
61
|
<div part="messages-inner" class="inner">
|
|
62
62
|
${s?W`<slot name="empty"></slot>`:V}
|
|
63
|
-
${
|
|
63
|
+
${be(t.messages,t=>t.id,e=>ve(t,e))}
|
|
64
64
|
${t.loading?function(t){const{style:e,text:i}=t.currentTheme.open.loading,s=i??t.currentLabels.loading;return W`
|
|
65
65
|
<div part="loading" data-style=${e} role="status" aria-label=${s}>
|
|
66
66
|
${"dots"===e?W`<span class="dots" aria-hidden="true"><i></i><i></i><i></i></span>`:V}
|
|
@@ -84,7 +84,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
84
84
|
${e.toLatest}
|
|
85
85
|
</button>
|
|
86
86
|
`:V}
|
|
87
|
-
`}const
|
|
87
|
+
`}const we=gt(class extends bt{constructor(t){if(super(t),t.type!==mt&&t.type!==pt&&t.type!==ft)throw Error("The `live` directive is not allowed on child or event bindings");if(!(t=>void 0===t.strings)(t))throw Error("`live` bindings can only contain a single expression")}render(t){return t}update(t,[e]){if(e===K||e===V)return e;const i=t.element,s=t.name;if(t.type===mt){if(e===i[s])return K}else if(t.type===ft){if(!!e===i.hasAttribute(s))return K}else if(t.type===pt&&i.getAttribute(s)===e+"")return K;return me(t),e}});function xe(t){if(t.inputHidden)return V;const e=t.currentLabels,i=t.currentTheme.open,s=t.busy||t.inputDisabled,n=t.placeholder??i.input.placeholder??e.input;return W`
|
|
88
88
|
<form
|
|
89
89
|
part="composer"
|
|
90
90
|
@submit=${e=>{e.preventDefault(),t.submit()}}
|
|
@@ -126,7 +126,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
126
126
|
<textarea
|
|
127
127
|
part="input"
|
|
128
128
|
rows="1"
|
|
129
|
-
.value=${
|
|
129
|
+
.value=${we(t.value)}
|
|
130
130
|
placeholder=${n}
|
|
131
131
|
aria-label=${e.input}
|
|
132
132
|
?disabled=${s}
|
|
@@ -153,7 +153,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
153
153
|
</button>
|
|
154
154
|
</slot>
|
|
155
155
|
</form>
|
|
156
|
-
`}function
|
|
156
|
+
`}function $e(t){const e=t.currentTheme.open,i=t.currentLabels,s=e.header.title??i.panel;return W`
|
|
157
157
|
<section
|
|
158
158
|
part="panel"
|
|
159
159
|
role="dialog"
|
|
@@ -219,11 +219,11 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
219
219
|
</header>
|
|
220
220
|
`}(t,s):V}
|
|
221
221
|
|
|
222
|
-
${
|
|
222
|
+
${ye(t)} ${xe(t)}
|
|
223
223
|
|
|
224
224
|
<slot name="footer"></slot>
|
|
225
225
|
</section>
|
|
226
|
-
`}const
|
|
226
|
+
`}const _e={ja:{launcher:"チャットを開く",panel:"チャット",conversation:"会話",close:"チャットを閉じる",home:"最初に戻る",send:"送信",attach:"画像や動画を添付",input:"メッセージを入力",typing:"入力中",loading:"応答を待っています",move:"チャットの位置を移動(矢印キー)",toLatest:"最新へ",status:{sending:"送信中",sent:"送信済み",error:"送信できませんでした"},charactersLeft:"残り {n} 文字",overLimit:"{n} 文字超過しています"},en:{launcher:"Open chat",panel:"Chat",conversation:"Conversation",close:"Close chat",home:"Back to the start",send:"Send",attach:"Attach an image or video",input:"Type a message",typing:"Typing",loading:"Waiting for a reply",move:"Move the chat (arrow keys)",toLatest:"Jump to latest",status:{sending:"Sending",sent:"Sent",error:"Not delivered"},charactersLeft:"{n} characters left",overLimit:"{n} characters over the limit"}};function Se(t){return t||document.documentElement.lang||void 0}const Ae=r`
|
|
227
227
|
:host {
|
|
228
228
|
--chit-z-index: 2147483000;
|
|
229
229
|
--chit-font-family: system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
|
|
@@ -373,7 +373,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
373
373
|
animation: none !important;
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
`,
|
|
376
|
+
`,Ee=r`
|
|
377
377
|
[part~='launcher'] {
|
|
378
378
|
position: absolute;
|
|
379
379
|
display: grid;
|
|
@@ -521,7 +521,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
521
521
|
animation: none;
|
|
522
522
|
}
|
|
523
523
|
}
|
|
524
|
-
`,
|
|
524
|
+
`,ke=r`
|
|
525
525
|
[part~='panel'] {
|
|
526
526
|
position: absolute;
|
|
527
527
|
display: flex;
|
|
@@ -576,12 +576,18 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
576
576
|
* A phone gets the whole screen. dvh rather than vh so the browser chrome
|
|
577
577
|
* collapsing does not leave a gap, and the safe-area insets keep the header
|
|
578
578
|
* clear of the notch.
|
|
579
|
+
*
|
|
580
|
+
* While a keyboard is up, the two --_chit-vv-* properties carry what is
|
|
581
|
+
* actually on screen (ViewportController fills them in from
|
|
582
|
+
* visualViewport); dvh knows nothing about a keyboard and would leave the
|
|
583
|
+
* composer behind it.
|
|
579
584
|
*/
|
|
580
585
|
:host([data-device='mobile']) [part~='panel'],
|
|
581
586
|
:host([data-device='mobile'][data-panel-position]) [part~='panel'] {
|
|
582
587
|
inset: 0;
|
|
588
|
+
top: var(--_chit-vv-top, 0px);
|
|
583
589
|
width: 100vw;
|
|
584
|
-
height: 100dvh;
|
|
590
|
+
height: var(--_chit-vv-height, 100dvh);
|
|
585
591
|
max-width: none;
|
|
586
592
|
max-height: none;
|
|
587
593
|
border-radius: 0;
|
|
@@ -683,7 +689,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
683
689
|
height: 1.1em;
|
|
684
690
|
}
|
|
685
691
|
|
|
686
|
-
`,
|
|
692
|
+
`,Te=r`
|
|
687
693
|
:host {
|
|
688
694
|
/* Internal: the box the tail's path is drawn in. The path is written in
|
|
689
695
|
these units, so the two move together. */
|
|
@@ -1030,7 +1036,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
1030
1036
|
animation: none;
|
|
1031
1037
|
}
|
|
1032
1038
|
}
|
|
1033
|
-
`,
|
|
1039
|
+
`,Ce=r`
|
|
1034
1040
|
[part~='message-content'] {
|
|
1035
1041
|
min-width: 0;
|
|
1036
1042
|
max-width: 100%;
|
|
@@ -1137,7 +1143,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
1137
1143
|
border: 0;
|
|
1138
1144
|
border-top: 1px solid var(--chit-color-border);
|
|
1139
1145
|
}
|
|
1140
|
-
`,
|
|
1146
|
+
`,Oe=r`
|
|
1141
1147
|
[part~='composer'] {
|
|
1142
1148
|
display: flex;
|
|
1143
1149
|
flex: none;
|
|
@@ -1165,6 +1171,24 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
1165
1171
|
overflow-y: auto;
|
|
1166
1172
|
}
|
|
1167
1173
|
|
|
1174
|
+
/*
|
|
1175
|
+
* iOS Safari zooms the page in whenever a field smaller than 16px takes
|
|
1176
|
+
* focus, and it does not zoom back out when the field is done with — the
|
|
1177
|
+
* reader is left with a widget wider than the screen and no obvious way
|
|
1178
|
+
* back. Nothing in the page can undo that zoom short of pinning the
|
|
1179
|
+
* viewport's scale, which would also take pinch-zoom away from everyone.
|
|
1180
|
+
* So the field is kept at the size that never triggers it, and larger
|
|
1181
|
+
* still if the theme's font is larger.
|
|
1182
|
+
*
|
|
1183
|
+
* Coarse pointers only: on a desktop the same rule would make the field
|
|
1184
|
+
* stand out from the rest of the widget for no reason.
|
|
1185
|
+
*/
|
|
1186
|
+
@media (pointer: coarse) {
|
|
1187
|
+
[part~='input'] {
|
|
1188
|
+
font-size: max(16px, 1em);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1168
1192
|
[part~='input']::placeholder {
|
|
1169
1193
|
color: var(--chit-color-input-placeholder);
|
|
1170
1194
|
}
|
|
@@ -1280,7 +1304,7 @@ var ChitUI=function(t){"use strict";const e=globalThis,i=e.ShadowRoot&&(void 0==
|
|
|
1280
1304
|
animation-duration: 2s;
|
|
1281
1305
|
}
|
|
1282
1306
|
}
|
|
1283
|
-
`;class
|
|
1284
|
-
${e?
|
|
1285
|
-
`}}customElements.get("chit-ui")||customElements.define("chit-ui",
|
|
1307
|
+
`;class Le extends ct{static styles=[Ae,Ee,ke,Te,Ce,Oe];static properties={state:{type:String,reflect:!0,noAccessor:!0},theme:{type:Object},messages:{type:Array},typing:{type:Object,noAccessor:!0},loading:{type:Boolean,reflect:!0,noAccessor:!0},busy:{type:Boolean,reflect:!0},inputDisabled:{type:Boolean,reflect:!0,attribute:"input-disabled"},inputHidden:{type:Boolean,reflect:!0,attribute:"input-hidden"},placeholder:{type:String,reflect:!0},sendOnEnter:{type:Boolean,reflect:!0,attribute:"send-on-enter"},maxLength:{type:Number,reflect:!0,attribute:"max-length"},focusOnOpen:{type:String,reflect:!0,attribute:"focus-on-open"},locale:{type:String,reflect:!0},labels:{type:Object},messageStyles:{type:String}};#Et="closed";#kt=!1;#Tt=!1;#Ct="api";#Ot;#$;#Lt;#Mt;#Pt;#zt=new qt("data-chit-message-styles");#Ut=new Map;#Rt=null;constructor(){super(),this.theme={},this.messages=[],this.busy=!1,this.inputDisabled=!1,this.inputHidden=!1,this.placeholder=void 0,this.sendOnEnter=!0,this.maxLength=void 0,this.focusOnOpen="auto",this.locale=void 0,this.labels=void 0,this.messageStyles="",this.sanitize=void 0,this.formatTime=void 0,this.#Ot=new _t(this,{animation:(t,e,i)=>this.#Ht(t,e,i),keepsLauncher:()=>"visible"===this.currentTheme.open.launcher,onOpened:()=>this.#Dt()}),this.#$=new St(this),this.#Lt=new Wt(this,{device:()=>this.#$.device}),this.addController(this.#Lt),this.#Mt=new Ft(this,{behavior:()=>this.currentTheme.open.animation.scroll}),this.#Pt=new Vt(this),new Xt(this),new Zt(this,{enabled:()=>"mobile"===this.device}),this.#Bt=new Yt(this,{name:"launcher",enabled:()=>this.currentTheme.closed.draggable,element:()=>this.#It("launcher"),size:()=>function(t){if(!t)return{width:0,height:0};const e=t.getBoundingClientRect();return{width:e.width,height:e.height}}(this.#It("launcher")),corner:()=>this.currentTheme.closed.position,base:()=>this.currentTheme.closed.offset,current:()=>this.#Nt,onMove:t=>this.#jt(t),onSettle:t=>this.#qt(t),vars:{x:"--chit-launcher-offset-x",y:"--chit-launcher-offset-y"}}),this.#Wt=new Yt(this,{name:"panel",enabled:()=>this.currentTheme.open.draggable&&"pc"===this.device,element:()=>this.#It("panel"),size:()=>{const t=this.currentTheme.open;return{width:Math.min(t.width,window.innerWidth-16),height:Math.min(t.height,window.innerHeight-16)}},corner:()=>this.currentTheme.open.position,base:()=>this.currentTheme.open.offset,current:()=>this.#Nt,onMove:t=>this.#jt(t),onSettle:t=>this.#qt(t),vars:{x:"--chit-panel-offset-x",y:"--chit-panel-offset-y"}})}#Bt;#Wt;#It(t){return this.renderRoot?.querySelector(`[part~="${t}"]`)??null}get launcherDrag(){return this.#Bt}get panelDrag(){return this.#Wt}get dragOffset(){return this.#Nt}set dragOffset(t){this.#Nt=t?{x:t.x,y:t.y}:null,this.#Ft()}resetPosition(){this.dragOffset=null}#Nt=null;#jt(t){this.#Nt=t,this.#Ft()}#Ft(){this.#Bt.place(this.#Nt),this.#Wt.place(this.#Nt)}#qt(t){if(!this.#Nt)return;const e=this.currentTheme,i="launcher"===t?e.closed:e.open,s="launcher"===t?this.#Bt:this.#Wt;xt(this,wt.MOVE,{target:t,position:i.position,offset:s.place(this.#Nt)??i.offset,displacement:{...this.#Nt}})}#Kt;#Vt;handleSubmitted(){this.#Yt()}#Yt(){const t=this.currentTheme.open.loading;t.auto&&(this.#Vt=new Set(this.messages.map(t=>t.id)),this.loading=!0,this.#Gt(),t.timeout>0&&(this.#Kt=setTimeout(()=>{this.#Kt=void 0,this.#l()},t.timeout)))}#l(){this.#Gt(),this.#Vt=void 0,this.loading=!1}#Gt(){void 0!==this.#Kt&&clearTimeout(this.#Kt),this.#Kt=void 0}get typing(){return this.#kt}set typing(t){const e=this.#kt;t!==e&&(this.#kt=t,this.requestUpdate("typing",e),t&&(this.loading=!1))}get loading(){return this.#Tt}set loading(t){const e=this.#Tt;t!==e&&(this.#Tt=t,this.requestUpdate("loading",e),t&&(this.typing=!1))}get state(){return this.#Et}set state(t){const e=this.#Et;if(t===e)return;if(this.#Et=t,this.requestUpdate("state",e),!this.#Ot||this.#Ot.applying)return;const i=this.#Ct;this.#Ct="api";const s=this.#Ot.request(t,i);this.#Rt=s,s.then(()=>{this.#Rt===s&&(this.#Rt=null)})}get device(){return this.#$.device}get currentTheme(){return this.#Lt.current}get currentLabels(){return function(t,e){const i=(Se(t)||"en").toLowerCase(),s=_e[i]??_e[i.split("-")[0]]??_e.en;return e?{...s,...e}:s}(this.locale,this.labels)}get resolvedLocale(){return Se(this.locale)}get renderedState(){return this.#Ot.renderedState}get hasUnseen(){return this.#Mt.hasUnseen}get value(){return this.#Pt.value}set value(t){this.#Pt.value=t}get canSend(){return this.#Pt.canSend}open(){return this.#Jt("open","api")}close(){return this.#Jt("closed","api")}hide(){return this.#Jt("hidden","api")}show(){return"hidden"===this.#Et?this.#Jt("closed","api"):Promise.resolve(!0)}toggle(){return this.#Jt("open"===this.state?"closed":"open","api")}submit(t){return this.#Pt.submit(t)}clearInput(){this.#Pt.clear()}scrollToBottom(t){this.#Mt.scrollToBottom(t)}getMessageElement(t){return this.renderRoot.querySelector(`[part~="message"][data-id="${CSS.escape(t)}"] [part~="message-content"]`)}focusInput(){const t=this.renderRoot.querySelector('[part~="input"]');return!!t&&(t.focus(),!0)}#Dt(){if("never"===this.focusOnOpen)return;if("auto"===this.focusOnOpen&&"mobile"===this.device)return;if(this.focusInput())return;const t=this.renderRoot.querySelector('[part~="panel"]');t?.focus()}handleInput(t){this.#Pt.onInput(t)}handleKeydown(t){this.#Pt.onKeydown(t)}handleComposition(t){t?this.#Pt.onCompositionStart():this.#Pt.onCompositionEnd()}handleAttach(t){xt(this,wt.ATTACH,{files:t})}openAttach(){const t=this.renderRoot.querySelector('[part~="attach-input"]');t?.click()}renderTypingHtml(t){return yt(this.sanitize?this.sanitize(t):t)}handleMessageClick(t){const e=t.composedPath(),i=e.find(t=>t instanceof HTMLElement&&t.getAttribute("part")?.split(/\s+/).includes("message"));if(!i)return;const s=i.dataset.id,n=this.messages.find(t=>t.id===s);if(!n)return;const o=e[0];xt(this,wt.MESSAGE_CLICK,{message:n,target:o,originalEvent:t},{cancelable:!0})||t.preventDefault()}toggleFromUser(){return this.#Jt("open"===this.state?"closed":"open","user")}closeFromUser(){return this.#Jt("closed","user")}home(t="api"){xt(this,wt.HOME,{trigger:t})}#Jt(t,e){return t!==this.#Et&&(this.#Ct=e,this.state=t),this.#Rt??Promise.resolve(!0)}#Ht(t,e,i){const s=this.currentTheme;if("exit"===i&&"hidden"===e)return{effect:s.hidden.animation.exit,duration:s.hidden.animation.duration};const n="open"===("exit"===i?t:e)?s.open:s.closed;return{effect:"exit"===i?n.animation.exit:n.animation.enter,duration:n.animation.duration}}willUpdate(){this.#$.observe(Wt.breakpointOf(this.theme)),this.#Lt.apply(this.theme,this.#$.device),this.#zt.write(this.messageStyles??"",this.renderRoot);const t=this.currentTheme;this.dataset.launcherPosition=t.closed.position,this.dataset.panelPosition=t.open.position,this.dataset.idle=t.closed.animation.idle,this.dataset.bubbleTail=t.open.bubble.tail}updated(){const t=new Set(this.messages.map(t=>t.id));if(function(t,e){const i=Qt.get(t);if(i)for(const t of i.keys())t.startsWith("msg:")&&(e.has(t.slice(4))||i.delete(t))}(this,t),this.#Xt(t),this.#Nt&&this.#Ft(),this.#Vt){this.messages.some(t=>"user"!==t.role&&!this.#Vt.has(t.id))&&this.#l()}}disconnectedCallback(){super.disconnectedCallback(),this.#Gt()}#Xt(t){for(const e of this.#Ut.keys())t.has(e)||this.#Ut.delete(e);for(const t of this.messages){const e=se(t);if(this.#Ut.has(t.id)&&Object.is(this.#Ut.get(t.id),e))continue;this.#Ut.set(t.id,e);const i=this.getMessageElement(t.id);i&&xt(this,wt.MESSAGE_RENDER,{message:t,element:i,instance:oe(this,t.id)})}}render(){const t=this.renderedState,e="closed"===t||"open"===t&&"visible"===this.currentTheme.open.launcher,i="open"===t;return W`
|
|
1308
|
+
${e?ae(this):V} ${i?$e(this):V}
|
|
1309
|
+
`}}customElements.get("chit-ui")||customElements.define("chit-ui",Le);const Me=gt(class extends bt{constructor(t){if(super(t),t.type!==pt||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return" "+Object.keys(t).filter(e=>t[e]).join(" ")+" "}update(t,[e]){if(void 0===this.st){this.st=new Set,void 0!==t.strings&&(this.nt=new Set(t.strings.join(" ").split(/\s/).filter(t=>""!==t)));for(const t in e)e[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(e)}const i=t.element.classList;for(const t of this.st)t in e||(i.remove(t),this.st.delete(t));for(const t in e){const s=!!e[t];s===this.st.has(t)||this.nt?.has(t)||(s?(i.add(t),this.st.add(t)):(i.remove(t),this.st.delete(t)))}return K}}),Pe="important",ze=" !"+Pe,Ue=gt(class extends bt{constructor(t){if(super(t),t.type!==pt||"style"!==t.name||t.strings?.length>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce((e,i)=>{const s=t[i];return null==s?e:e+`${i=i.includes("-")?i:i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`},"")}update(t,[e]){const{style:i}=t.element;if(void 0===this.ft)return this.ft=new Set(Object.keys(e)),this.render(e);for(const t of this.ft)null==e[t]&&(this.ft.delete(t),t.includes("-")?i.removeProperty(t):i[t]=null);for(const t in e){const s=e[t];if(null!=s){this.ft.add(t);const e="string"==typeof s&&s.endsWith(ze);t.includes("-")||e?i.setProperty(t,e?s.slice(0,-11):s,e?Pe:""):i[t]=s}}return K}});return t.ChitUI=Le,t.Events=wt,t.LitElement=ct,t.classMap=Me,t.css=r,t.greenTheme={closed:{colors:{background:"#0a6b36",text:"#ffffff",shadow:"0 4px 12px rgba(16, 42, 26, 0.32)"}},open:{radius:12,colors:{background:"#d3ddea",text:"#16212c",accent:"#0a6b36",border:"#b6c5d6",shadow:"0 8px 32px rgba(16, 32, 48, 0.28)",headerBackground:"#ffffff",headerText:"#16212c",userBubble:"#9ce26c",userText:"#14240c",assistantBubble:"#ffffff",assistantText:"#16212c",systemText:"#37475a",inputBackground:"#ffffff",inputText:"#16212c",inputPlaceholder:"#5c6370"},bubble:{radius:18,tail:"top"}}},t.html=W,t.live=we,t.nothing=V,t.render=ht,t.repeat=be,t.styleMap=Ue,t.svg=F,t.unsafeHTML=yt,t}({});
|
|
1286
1310
|
//# sourceMappingURL=chit-ui.iife.min.js.map
|