luzia-widget 0.1.2 → 0.1.3

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.
@@ -1,4 +1,4 @@
1
- var k="conversation_limit_reached",E="message_too_long";function p(i){return i.code===k?"limit":i.code===E?"too-long":"unavailable"}var T={limit:"You've reached the message limit for this conversation.","too-long":"That message is too long. Please shorten it and try again.",unavailable:"luzIA is unavailable right now. Please try again later."};function f(i,e,t){if(i.hidden=e===null,i.replaceChildren(),e===null)return;i.append(T[e]);let s=t.trim();e==="too-long"||!s||i.append(" You can get in touch directly: ",A(s),".")}function A(i){let e=/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(i)?`mailto:${i}`:/^https?:\/\/\S+$/i.test(i)?i:null;if(!e)return document.createTextNode(i);let t=document.createElement("a");return t.href=e,t.textContent=i,e.startsWith("mailto:")||(t.target="_blank",t.rel="noopener noreferrer"),t}var l=class extends Error{code;status;constructor(e,t,s){super(t),this.name="LuziaRequestError",this.code=e,this.status=s}};async function*v(i,e,t){let s;try{s=await fetch(i,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({messages:e}),signal:t})}catch(r){if(t?.aborted)return;throw new l("network_error",b(r))}if(!s.ok)throw await M(s);if(!s.body)throw new l("network_error","The reply had no body.",s.status);let n=s.body.pipeThrough(new TextDecoderStream).getReader();try{for(;;){let{done:r,value:o}=await n.read();if(r)return;o&&(yield o)}}catch(r){if(t?.aborted)return;throw new l("network_error",b(r),s.status)}finally{n.releaseLock()}}async function M(i){let t=(await i.json().catch(()=>{}))?.error;return new l(typeof t?.code=="string"?t.code:"http_error",typeof t?.message=="string"?t.message:`The server answered ${i.status}.`,i.status)}function b(i){return i instanceof Error?i.message:String(i)}var d=class{#e;#r=new Set;#c;#t=null;constructor(e){this.#c=e,this.#e={messages:e.messages??[],status:"idle",error:null,unsent:null}}get state(){return this.#e}subscribe(e){return this.#r.add(e),()=>this.#r.delete(e)}send(e){let t=e.trim();return!t||this.#e.status==="streaming"?!1:(this.#g([...this.#e.messages,{role:"user",content:t}]),!0)}abort(){this.#t?.abort()}reset(e=[]){let t=this.#t;this.#t=null,t?.abort(),this.#i({messages:e,status:"idle",error:null,unsent:null})}async#g(e){let t=new AbortController;this.#t=t;let s="";this.#i({messages:[...e,{role:"assistant",content:s}],status:"streaming",error:null,unsent:null});try{for await(let n of v(this.#c.endpoint(),e,t.signal)){if(this.#t!==t)return;s+=n,this.#i({...this.#e,messages:[...e,{role:"assistant",content:s}]})}if(this.#t!==t)return;this.#i({messages:y(e,s),status:"idle",error:null,unsent:null})}catch(n){if(this.#t!==t)return;let r=n instanceof l?n:new l("network_error",String(n));s?this.#i({messages:y(e,s),status:"error",error:r,unsent:null}):this.#i({messages:e.slice(0,-1),status:"error",error:r,unsent:e.at(-1)?.content??null})}finally{this.#t===t&&(this.#t=null)}}#i(e){this.#e=e;for(let t of this.#r)t(e)}};function y(i,e){return e?[...i,{role:"assistant",content:e}]:i}function z(i){let e=i;try{e=new URL(i,document.baseURI).href}catch{}return`luzia:conversation:${e}`}function L(i,e){let t=_();if(!t)return()=>{};let s=I(t,e);s&&i.state.messages.length===0&&i.reset(s);let n=x(w(i.state));return i.subscribe(r=>{let o=w(r),u=x(o);if(u!==n){n=u;try{o.length===0?t.removeItem(e):t.setItem(e,u)}catch{}}})}function w(i){return i.status==="streaming"?i.messages.slice(0,-1):i.messages}function x(i){let e={v:1,messages:[...i]};return JSON.stringify(e)}function I(i,e){try{let t=i.getItem(e);if(t===null)return null;let s=JSON.parse(t);return O(s)?s.messages.map(({role:n,content:r})=>({role:n,content:r})):null}catch{return null}}function O(i){if(typeof i!="object"||i===null)return!1;let{v:e,messages:t}=i;return e===1&&Array.isArray(t)&&t.every(H)}function H(i){if(typeof i!="object"||i===null)return!1;let{role:e,content:t}=i;return(e==="user"||e==="assistant")&&typeof t=="string"}function _(){try{return typeof sessionStorage>"u"?null:sessionStorage}catch{return null}}var C=`
1
+ var N="conversation_limit_reached",$="message_too_long";function E(r){return r.code===N?"limit":r.code===$?"too-long":"unavailable"}var P={limit:"You've reached the message limit for this conversation.","too-long":"That message is too long. Please shorten it and try again.",unavailable:"luzIA is unavailable right now. Please try again later."};function S(r,e,t){if(r.hidden=e===null,r.replaceChildren(),e===null)return;r.append(P[e]);let i=t.trim();e==="too-long"||!i||r.append(" You can get in touch directly: ",V(i),".")}function V(r){let e=/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(r)?`mailto:${r}`:/^https?:\/\/\S+$/i.test(r)?r:null;if(!e)return document.createTextNode(r);let t=document.createElement("a");return t.href=e,t.textContent=r,e.startsWith("mailto:")||(t.target="_blank",t.rel="noopener noreferrer"),t}var u=class extends Error{code;status;constructor(e,t,i){super(t),this.name="LuziaRequestError",this.code=e,this.status=i}};async function*T(r,e,t){let i;try{i=await fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({messages:e}),signal:t})}catch(s){if(t?.aborted)return;throw new u("network_error",A(s))}if(!i.ok)throw await B(i);if(!i.body)throw new u("network_error","The reply had no body.",i.status);let n=i.body.pipeThrough(new TextDecoderStream).getReader();try{for(;;){let{done:s,value:o}=await n.read();if(s)return;o&&(yield o)}}catch(s){if(t?.aborted)return;throw new u("network_error",A(s),i.status)}finally{n.releaseLock()}}async function B(r){let t=(await r.json().catch(()=>{}))?.error;return new u(typeof t?.code=="string"?t.code:"http_error",typeof t?.message=="string"?t.message:`The server answered ${r.status}.`,r.status)}function A(r){return r instanceof Error?r.message:String(r)}var h=class{#e;#n=new Set;#g;#t=null;constructor(e){this.#g=e,this.#e={messages:e.messages??[],status:"idle",error:null,unsent:null}}get state(){return this.#e}subscribe(e){return this.#n.add(e),()=>this.#n.delete(e)}send(e){let t=e.trim();return!t||this.#e.status==="streaming"?!1:(this.#m([...this.#e.messages,{role:"user",content:t}]),!0)}abort(){this.#t?.abort()}reset(e=[]){let t=this.#t;this.#t=null,t?.abort(),this.#r({messages:e,status:"idle",error:null,unsent:null})}async#m(e){let t=new AbortController;this.#t=t;let i="";this.#r({messages:[...e,{role:"assistant",content:i}],status:"streaming",error:null,unsent:null});try{for await(let n of T(this.#g.endpoint(),e,t.signal)){if(this.#t!==t)return;i+=n,this.#r({...this.#e,messages:[...e,{role:"assistant",content:i}]})}if(this.#t!==t)return;this.#r({messages:C(e,i),status:"idle",error:null,unsent:null})}catch(n){if(this.#t!==t)return;let s=n instanceof u?n:new u("network_error",String(n));i?this.#r({messages:C(e,i),status:"error",error:s,unsent:null}):this.#r({messages:e.slice(0,-1),status:"error",error:s,unsent:e.at(-1)?.content??null})}finally{this.#t===t&&(this.#t=null)}}#r(e){this.#e=e;for(let t of this.#n)t(e)}};function C(r,e){return e?[...r,{role:"assistant",content:e}]:r}var j=String.raw`\[([^\]\n]+)\]\(\s*((?:https?:\/\/|mailto:|www\.)[^\s)]+)\s*\)`,F=String.raw`(?:https?:\/\/|www\.)[^\s<>"'\x60]+`,D=String.raw`[\w.+-]+@[\w-]+(?:\.[\w-]+)*\.[a-z]{2,}`,K=new RegExp(`${j}|(${F})|(${D})`,"gi"),G=/[.,;:!?'"»”’]+$/;function U(r){let e=r;for(;;){let t=e;e=e.replace(G,"");for(let[i,n]of[["(",")"],["[","]"]])e.endsWith(n)&&M(e,n)>M(e,i)&&(e=e.slice(0,-1));if(e===t)return e}}function M(r,e){return r.split(e).length-1}function I(r){let e=/^www\./i.test(r)?`https://${r}`:r;try{let t=new URL(e);return["http:","https:","mailto:"].includes(t.protocol)?t.href:null}catch{return null}}function f(r,e,t){let i=document.createElement("a");return i.href=e,i.textContent=r,e.startsWith("mailto:")||(i.target="_blank",i.rel="noopener noreferrer"),t||(i.tabIndex=-1),i}function v(r,e,{focusable:t=!0}={}){let i=[],n=0;for(let s of e.matchAll(K)){let[o,l,a,L,p]=s,b=s.index,g=o,d=null;if(l!==void 0&&a!==void 0){let c=I(a);c&&(d=f(l,c,t))}else if(L!==void 0){g=U(L);let c=I(g);c&&(d=f(g,c,t))}else p!==void 0&&(d=f(p,`mailto:${p}`,t));d&&(b>n&&i.push(document.createTextNode(e.slice(n,b))),i.push(d),n=b+g.length)}n<e.length&&i.push(document.createTextNode(e.slice(n))),r.replaceChildren(...i)}function W(r){let e=r;try{e=new URL(r,document.baseURI).href}catch{}return`luzia:conversation:${e}`}function O(r,e){let t=Z();if(!t)return()=>{};let i=Q(t,e);i&&r.state.messages.length===0&&r.reset(i);let n=H(R(r.state));return r.subscribe(s=>{let o=R(s),l=H(o);if(l!==n){n=l;try{o.length===0?t.removeItem(e):t.setItem(e,l)}catch{}}})}function R(r){return r.status==="streaming"?r.messages.slice(0,-1):r.messages}function H(r){let e={v:1,messages:[...r]};return JSON.stringify(e)}function Q(r,e){try{let t=r.getItem(e);if(t===null)return null;let i=JSON.parse(t);return Y(i)?i.messages.map(({role:n,content:s})=>({role:n,content:s})):null}catch{return null}}function Y(r){if(typeof r!="object"||r===null)return!1;let{v:e,messages:t}=r;return e===1&&Array.isArray(t)&&t.every(J)}function J(r){if(typeof r!="object"||r===null)return!1;let{role:e,content:t}=r;return(e==="user"||e==="assistant")&&typeof t=="string"}function Z(){try{return typeof sessionStorage>"u"?null:sessionStorage}catch{return null}}var _=`
2
2
  :host {
3
3
  --luzia-accent: #4f46e5;
4
4
  --luzia-accent-contrast: #ffffff;
@@ -8,6 +8,9 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
8
8
  --luzia-font: system-ui, -apple-system, 'Segoe UI', sans-serif;
9
9
  --luzia-border: #d4d4d8;
10
10
  --luzia-inline-height: 38rem;
11
+ --luzia-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
12
+ /* How strongly the accent lights the top of the chat, behind luzIA. */
13
+ --luzia-glow-strength: 22%;
11
14
  position: fixed;
12
15
  right: 1.25rem;
13
16
  bottom: 1.25rem;
@@ -16,6 +19,7 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
16
19
  color: var(--luzia-text);
17
20
  }
18
21
  :host([theme='dark']) {
22
+ --luzia-glow-strength: 30%;
19
23
  --luzia-surface: #18181b;
20
24
  --luzia-text: #f4f4f5;
21
25
  --luzia-muted: #27272a;
@@ -23,6 +27,7 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
23
27
  }
24
28
  @media (prefers-color-scheme: dark) {
25
29
  :host([theme='auto']) {
30
+ --luzia-glow-strength: 30%;
26
31
  --luzia-surface: #18181b;
27
32
  --luzia-text: #f4f4f5;
28
33
  --luzia-muted: #27272a;
@@ -36,8 +41,10 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
36
41
  outline: 2px solid var(--luzia-accent);
37
42
  outline-offset: 2px;
38
43
  }
39
- /* The header is accent-coloured, so its focus ring takes the text colour. */
40
- .header button:focus-visible { outline-color: currentColor; outline-offset: -4px; }
44
+ /* The message box shows focus on its whole field (see .composer:focus-within). */
45
+ .composer textarea:focus-visible { outline: none; }
46
+ ::selection { background: color-mix(in srgb, var(--luzia-accent) 28%, transparent); }
47
+ .message[data-role='user']::selection { background: color-mix(in srgb, var(--luzia-accent-contrast) 35%, transparent); }
41
48
  /* Read by screen readers only: each finished reply (see the element's View). */
42
49
  .announcer {
43
50
  position: absolute;
@@ -50,19 +57,67 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
50
57
  white-space: nowrap;
51
58
  border: 0;
52
59
  }
60
+ /*
61
+ * The launcher: a pill with luzIA's icon and an invitation to ask. With the
62
+ * chat open it folds into just the icon: the text fades and blurs out first,
63
+ * then the pill narrows (unfolding, the pill widens first, then the text comes in).
64
+ */
53
65
  .bubble {
54
- display: grid;
55
- place-items: center;
56
- width: 3.5rem;
57
- height: 3.5rem;
66
+ display: flex;
67
+ align-items: center;
68
+ height: 3.25rem;
58
69
  margin-left: auto;
70
+ padding: 0 0.45rem;
59
71
  border: none;
60
- border-radius: 50%;
72
+ border-radius: 999px;
61
73
  background: var(--luzia-accent);
62
74
  color: var(--luzia-accent-contrast);
63
- font: 600 0.8rem var(--luzia-font);
75
+ font: 600 0.95rem var(--luzia-font);
64
76
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
65
77
  cursor: pointer;
78
+ transition: transform 160ms ease-out, box-shadow 160ms ease-out;
79
+ }
80
+ @media (hover: hover) and (pointer: fine) {
81
+ .bubble:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgb(0 0 0 / 0.25); }
82
+ }
83
+ .bubble:active { transform: scale(0.97); }
84
+ .bubble-icon { display: block; width: 2.35rem; height: 2.35rem; flex: none; }
85
+ .bubble-icon svg { display: block; }
86
+ /* The star turns a little as the pill folds and unfolds. */
87
+ .bubble-icon path {
88
+ transform-box: fill-box;
89
+ transform-origin: center;
90
+ transition: transform 400ms var(--luzia-ease-out);
91
+ }
92
+ .bubble[aria-expanded='true'] .bubble-icon path { transform: rotate(90deg); }
93
+ .bubble-label {
94
+ display: block;
95
+ overflow: hidden;
96
+ max-width: 14rem;
97
+ transition: max-width 320ms var(--luzia-ease-out);
98
+ }
99
+ .bubble-text {
100
+ display: block;
101
+ padding: 0 0.95rem 0 0.6rem;
102
+ white-space: nowrap;
103
+ transition: opacity 200ms ease 90ms, filter 200ms ease 90ms, transform 200ms ease-out 90ms;
104
+ }
105
+ .bubble[aria-expanded='true'] .bubble-label {
106
+ max-width: 0;
107
+ transition-delay: 60ms;
108
+ }
109
+ .bubble[aria-expanded='true'] .bubble-text {
110
+ opacity: 0;
111
+ filter: blur(3px);
112
+ transform: translateX(-0.4rem);
113
+ transition-duration: 140ms;
114
+ transition-delay: 0ms;
115
+ }
116
+ /* Less motion: the text still fades, but nothing moves or turns. */
117
+ @media (prefers-reduced-motion: reduce) {
118
+ .bubble, .bubble-label, .bubble-icon path { transition: none; }
119
+ .bubble:hover, .bubble:active, .bubble-text, .bubble[aria-expanded='true'] .bubble-text { transform: none; }
120
+ .bubble-text, .bubble[aria-expanded='true'] .bubble-text { filter: none; transition: opacity 150ms ease; }
66
121
  }
67
122
  .panel {
68
123
  display: flex;
@@ -70,11 +125,30 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
70
125
  width: min(24rem, calc(100vw - 2.5rem));
71
126
  height: min(40rem, calc(100vh - 7rem));
72
127
  margin-bottom: 0.75rem;
73
- background: var(--luzia-surface);
74
- border-radius: 1rem;
75
- box-shadow: 0 12px 40px rgb(0 0 0 / 0.2);
128
+ /* luzIA stands in a soft light of the accent colour; it fades out before the conversation. */
129
+ background-color: var(--luzia-surface);
130
+ background-image: radial-gradient(19rem 12rem at 6.5rem 8rem, color-mix(in srgb, var(--luzia-accent) var(--luzia-glow-strength), transparent), transparent 70%);
131
+ background-repeat: no-repeat;
132
+ border: 1px solid color-mix(in srgb, var(--luzia-border) 70%, transparent);
133
+ border-radius: 1.25rem;
134
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 24px 48px -12px rgb(0 0 0 / 0.3);
76
135
  overflow: hidden;
77
136
  }
137
+ /* Opening grows the chat out of the launcher below it; closing is instant. */
138
+ :host(:not([mode='inline'])) .panel {
139
+ transform-origin: bottom right;
140
+ transition: opacity 200ms ease-out, transform 240ms var(--luzia-ease-out);
141
+ @starting-style {
142
+ opacity: 0;
143
+ transform: translateY(8px) scale(0.97);
144
+ }
145
+ }
146
+ @media (prefers-reduced-motion: reduce) {
147
+ :host(:not([mode='inline'])) .panel {
148
+ transition: opacity 150ms ease;
149
+ @starting-style { transform: none; }
150
+ }
151
+ }
78
152
  :host([mode='inline']) {
79
153
  position: static;
80
154
  display: block;
@@ -85,25 +159,28 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
85
159
  width: 100%;
86
160
  height: var(--luzia-inline-height);
87
161
  margin: 0;
88
- border: 1px solid var(--luzia-border);
89
- box-shadow: none;
162
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
90
163
  }
164
+ /* Quiet: luzIA's mark and name, then two icon buttons. The light below carries the colour. */
91
165
  .header {
92
166
  display: flex;
93
167
  align-items: center;
94
- justify-content: space-between;
95
- padding: 0.25rem 0.5rem 0.25rem 1rem;
96
- background: var(--luzia-accent);
97
- color: var(--luzia-accent-contrast);
168
+ gap: 0.5rem;
169
+ padding: 0.375rem 0.375rem 0 0.875rem;
170
+ color: var(--luzia-text);
98
171
  }
172
+ .header-icon { display: block; width: 1.5rem; height: 1.5rem; flex: none; }
173
+ .header-icon svg { display: block; }
174
+ .header-icon circle { fill: var(--luzia-accent); }
175
+ .header-icon path { fill: var(--luzia-accent-contrast); }
99
176
  /* Like a video call: luzIA's whole picture large and centred at the top, the conversation below it. */
100
177
  .stage {
101
178
  flex: none;
102
179
  display: flex;
103
180
  justify-content: flex-start;
104
181
  gap: 0.75rem;
105
- padding: 0.75rem 1rem 0;
106
- border-bottom: 1px solid var(--luzia-border);
182
+ padding: 0.25rem 1rem 0;
183
+ border-bottom: 1px solid color-mix(in srgb, var(--luzia-border) 75%, transparent);
107
184
  }
108
185
  /* The picture is shown whole, in its own shape (a cut-out stands on the divider line). */
109
186
  .avatar {
@@ -120,6 +197,8 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
120
197
  transition: filter 0.2s ease;
121
198
  }
122
199
  .avatar svg { aspect-ratio: 1; margin-bottom: 0.75rem; height: calc(100% - 0.75rem); }
200
+ /* luzIA's own icon: the star on a disc lit by the accent, not a flat white circle. */
201
+ .avatar svg circle { fill: color-mix(in srgb, var(--luzia-accent) 12%, var(--luzia-surface)); }
123
202
  /* luzIA stays on the left; her speech bubble appears on the right without moving her. */
124
203
  .speech {
125
204
  position: relative;
@@ -127,14 +206,14 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
127
206
  align-self: flex-start;
128
207
  min-width: 0;
129
208
  margin: 0.75rem 0 0;
130
- padding: 0.55rem 0.75rem;
209
+ padding: 0.6rem 0.8rem;
131
210
  border: 1px solid var(--luzia-border);
132
- border-radius: 0.9rem;
211
+ border-radius: 1rem;
133
212
  background: var(--luzia-surface);
134
213
  color: var(--luzia-text);
135
- box-shadow: 0 6px 18px rgb(0 0 0 / 0.18);
214
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 10px 24px -10px rgb(0 0 0 / 0.25);
136
215
  font-size: 0.875rem;
137
- line-height: 1.4;
216
+ line-height: 1.45;
138
217
  opacity: 1;
139
218
  transition: opacity 0.4s ease;
140
219
  }
@@ -144,7 +223,6 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
144
223
  /* Long replies scroll inside the bubble, so their beginning can be read. */
145
224
  overflow-y: auto;
146
225
  overscroll-behavior: contain;
147
- scrollbar-width: thin;
148
226
  padding-inline-end: 0.25rem;
149
227
  white-space: pre-wrap;
150
228
  overflow-wrap: anywhere;
@@ -189,44 +267,126 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
189
267
  .stage[data-speaking] .avatar img,
190
268
  .stage[data-speaking] .avatar svg { animation: none; }
191
269
  }
192
- .title { margin: 0; font-size: 1rem; }
270
+ .title { margin: 0; font-size: 0.95rem; font-weight: 650; letter-spacing: -0.01em; }
271
+ .new-conversation,
272
+ .close {
273
+ color: color-mix(in srgb, var(--luzia-text) 65%, transparent);
274
+ }
275
+ /* Restart: a circular arrow, named by a tooltip on hover or keyboard focus. */
193
276
  .new-conversation {
194
- margin-inline: auto 0.5rem;
195
- padding: 0.25rem 0.5rem;
196
- border: 1px solid currentColor;
197
- border-radius: 0.375rem;
277
+ position: relative;
278
+ display: grid;
279
+ place-items: center;
280
+ margin-inline: auto 0.25rem;
281
+ padding: 0;
282
+ border: none;
283
+ border-radius: 0.75rem;
198
284
  background: transparent;
199
- color: inherit;
200
- font: inherit;
201
- font-size: 0.8rem;
202
285
  cursor: pointer;
286
+ transition: background-color 150ms ease, color 150ms ease, transform 160ms ease-out;
287
+ }
288
+ .new-conversation svg { display: block; transition: transform 300ms cubic-bezier(0.23, 1, 0.32, 1); }
289
+ .new-conversation:active { transform: scale(0.94); }
290
+ .tooltip {
291
+ position: absolute;
292
+ top: calc(100% + 0.4rem);
293
+ right: 0;
294
+ z-index: 1;
295
+ padding: 0.35rem 0.6rem;
296
+ border-radius: 0.375rem;
297
+ background: var(--luzia-text);
298
+ color: var(--luzia-surface);
299
+ font: 500 0.75rem var(--luzia-font);
300
+ white-space: nowrap;
301
+ box-shadow: 0 4px 12px rgb(0 0 0 / 0.18);
302
+ pointer-events: none;
303
+ opacity: 0;
304
+ transform: translateY(-2px) scale(0.97);
305
+ transform-origin: top right;
306
+ /* Leaving: quick, with no wait. */
307
+ transition: opacity 100ms ease-out, transform 100ms ease-out;
308
+ }
309
+ /* Appearing: after a short pause, so passing over the button does not flash it. */
310
+ .new-conversation:focus-visible .tooltip {
311
+ opacity: 1;
312
+ transform: none;
313
+ transition: opacity 125ms ease-out, transform 125ms ease-out;
314
+ }
315
+ @media (hover: hover) and (pointer: fine) {
316
+ .new-conversation:hover,
317
+ .close:hover { background-color: color-mix(in srgb, var(--luzia-text) 8%, transparent); color: var(--luzia-text); }
318
+ /* The arrow winds back a little, hinting at what it does. */
319
+ .new-conversation:hover svg { transform: rotate(-45deg); }
320
+ .new-conversation:hover .tooltip {
321
+ opacity: 1;
322
+ transform: none;
323
+ transition: opacity 125ms ease-out 350ms, transform 125ms ease-out 350ms;
324
+ }
325
+ }
326
+ @media (prefers-reduced-motion: reduce) {
327
+ .tooltip, .new-conversation:active, .new-conversation svg { transform: none !important; }
203
328
  }
204
329
  .close {
330
+ display: grid;
331
+ place-items: center;
332
+ padding: 0;
205
333
  border: none;
334
+ border-radius: 0.75rem;
206
335
  background: transparent;
207
- color: inherit;
208
- font-size: 1.4rem;
209
- line-height: 1;
210
336
  cursor: pointer;
337
+ transition: background-color 150ms ease, color 150ms ease, transform 160ms ease-out;
338
+ }
339
+ .close svg { display: block; }
340
+ .close:active { transform: scale(0.94); }
341
+ @media (prefers-reduced-motion: reduce) {
342
+ .close:active { transform: none; }
211
343
  }
212
344
  .body {
213
345
  flex: 1;
214
346
  display: flex;
215
347
  flex-direction: column;
216
- gap: 0.5rem;
217
- padding: 1rem;
348
+ gap: 0.375rem;
349
+ padding: 1rem 1rem 0.75rem;
218
350
  overflow-y: auto;
219
351
  }
220
- .greeting {
221
- align-self: flex-start;
352
+ .body,
353
+ .speech-text {
354
+ scrollbar-width: thin;
355
+ scrollbar-color: color-mix(in srgb, var(--luzia-text) 22%, transparent) transparent;
356
+ }
357
+ /* Messages: soft, with the corner nearest the speaker drawn in, like a tail. */
358
+ .greeting,
359
+ .message {
222
360
  max-width: 85%;
223
361
  margin: 0;
224
- padding: 0.5rem 0.75rem;
225
- border-radius: 0.75rem;
226
- background: var(--luzia-muted);
362
+ padding: 0.55rem 0.875rem;
363
+ border-radius: 1.125rem;
364
+ font-size: 0.9375rem;
365
+ line-height: 1.45;
227
366
  white-space: pre-wrap;
228
367
  overflow-wrap: anywhere;
229
- line-height: 1.4;
368
+ }
369
+ .greeting,
370
+ .message[data-role='assistant'] {
371
+ align-self: flex-start;
372
+ border-bottom-left-radius: 0.375rem;
373
+ background: var(--luzia-muted);
374
+ transform-origin: bottom left;
375
+ }
376
+ /* Links in luzIA's replies: underlined in the text's own colour, so they read as links on any theme. */
377
+ .message a,
378
+ .speech-text a {
379
+ color: inherit;
380
+ text-decoration: underline;
381
+ text-decoration-thickness: 1px;
382
+ text-underline-offset: 0.15em;
383
+ border-radius: 0.125rem;
384
+ }
385
+ .message a:hover,
386
+ .speech-text a:hover { text-decoration-thickness: 2px; }
387
+ .message a:focus-visible {
388
+ outline: 2px solid var(--luzia-accent);
389
+ outline-offset: 1px;
230
390
  }
231
391
  .messages {
232
392
  margin: 0;
@@ -234,24 +394,27 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
234
394
  list-style: none;
235
395
  display: flex;
236
396
  flex-direction: column;
237
- gap: 0.5rem;
238
- }
239
- .message {
240
- max-width: 85%;
241
- padding: 0.5rem 0.75rem;
242
- border-radius: 0.75rem;
243
- white-space: pre-wrap;
244
- overflow-wrap: anywhere;
245
- line-height: 1.4;
397
+ gap: 0.375rem;
246
398
  }
247
399
  .message[data-role='user'] {
248
400
  align-self: flex-end;
401
+ border-bottom-right-radius: 0.375rem;
249
402
  background: var(--luzia-accent);
250
403
  color: var(--luzia-accent-contrast);
404
+ box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--luzia-accent) 80%, transparent);
405
+ transform-origin: bottom right;
251
406
  }
252
- .message[data-role='assistant'] {
253
- align-self: flex-start;
254
- background: var(--luzia-muted);
407
+ /* A little more room where the speaker changes. */
408
+ .message[data-role='assistant'] + .message[data-role='user'],
409
+ .message[data-role='user'] + .message[data-role='assistant'] { margin-top: 0.375rem; }
410
+ .greeting:not([hidden]) + .messages:not(:empty) { margin-top: 0.375rem; }
411
+ /* Each new message rises into place once. */
412
+ .message { animation: luzia-rise 260ms var(--luzia-ease-out); }
413
+ @keyframes luzia-rise {
414
+ from { opacity: 0; transform: translateY(6px) scale(0.98); }
415
+ }
416
+ @keyframes luzia-fade {
417
+ from { opacity: 0; }
255
418
  }
256
419
  .suggestions {
257
420
  display: flex;
@@ -262,17 +425,33 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
262
425
  padding: 0;
263
426
  list-style: none;
264
427
  }
428
+ /* Questions the Visitor could ask, tinted with the accent; they arrive one after another. */
429
+ .suggestions li { animation: luzia-rise 320ms var(--luzia-ease-out) both; transform-origin: bottom right; }
430
+ .suggestions li:nth-child(2) { animation-delay: 50ms; }
431
+ .suggestions li:nth-child(3) { animation-delay: 100ms; }
432
+ .suggestions li:nth-child(n + 4) { animation-delay: 150ms; }
265
433
  .suggestion {
266
- padding: 0.4rem 0.75rem;
267
- border: 1px solid var(--luzia-accent);
434
+ padding: 0.5rem 0.9rem;
435
+ border: 1px solid color-mix(in srgb, var(--luzia-accent) 24%, transparent);
268
436
  border-radius: 999px;
269
- background: var(--luzia-surface);
270
- color: var(--luzia-text);
271
- font: 0.875rem var(--luzia-font);
437
+ background: color-mix(in srgb, var(--luzia-accent) 7%, var(--luzia-surface));
438
+ color: color-mix(in srgb, var(--luzia-accent) 60%, var(--luzia-text));
439
+ font: 500 0.875rem/1.3 var(--luzia-font);
272
440
  text-align: left;
273
441
  cursor: pointer;
442
+ transition: background-color 150ms ease, border-color 150ms ease, transform 160ms ease-out;
443
+ }
444
+ @media (hover: hover) and (pointer: fine) {
445
+ .suggestion:hover {
446
+ border-color: color-mix(in srgb, var(--luzia-accent) 45%, transparent);
447
+ background: color-mix(in srgb, var(--luzia-accent) 13%, var(--luzia-surface));
448
+ }
449
+ }
450
+ .suggestion:active { transform: scale(0.97); }
451
+ @media (prefers-reduced-motion: reduce) {
452
+ .message, .suggestions li { animation-name: luzia-fade; }
453
+ .suggestion:active { transform: none; }
274
454
  }
275
- .suggestion:hover { background: var(--luzia-muted); }
276
455
  .alert {
277
456
  margin: 0 1rem 0.5rem;
278
457
  font-size: 0.875rem;
@@ -281,32 +460,65 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
281
460
  .alert a {
282
461
  color: inherit;
283
462
  }
463
+ /* One rounded field: the message box with a round Send button inside it. */
284
464
  .composer {
285
465
  display: flex;
286
- gap: 0.5rem;
287
- padding: 0.75rem;
288
- border-top: 1px solid var(--luzia-muted);
466
+ align-items: flex-end;
467
+ gap: 0.375rem;
468
+ margin: 0 0.75rem 0.75rem;
469
+ padding: 0.25rem 0.25rem 0.25rem 1rem;
470
+ border: 1px solid var(--luzia-border);
471
+ border-radius: 1.5rem;
472
+ background: var(--luzia-surface);
473
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
474
+ transition: border-color 150ms ease, box-shadow 150ms ease;
475
+ }
476
+ .composer:focus-within {
477
+ border-color: color-mix(in srgb, var(--luzia-accent) 60%, var(--luzia-border));
478
+ box-shadow: 0 0 0 4px color-mix(in srgb, var(--luzia-accent) 16%, transparent);
289
479
  }
290
480
  .composer textarea {
291
481
  flex: 1;
482
+ box-sizing: border-box;
483
+ min-height: 2.75rem;
484
+ max-height: 8rem;
292
485
  resize: none;
293
- padding: 0.5rem;
294
- border: 1px solid var(--luzia-border);
295
- border-radius: 0.5rem;
296
- background: var(--luzia-surface);
486
+ padding: 0.7rem 0;
487
+ border: none;
488
+ background: transparent;
297
489
  color: var(--luzia-text);
490
+ caret-color: var(--luzia-accent);
298
491
  font: inherit;
492
+ font-size: 0.9375rem;
493
+ line-height: 1.4;
494
+ /* Grows with what is typed, where supported. */
495
+ field-sizing: content;
299
496
  }
300
- .composer button {
301
- padding: 0 1rem;
497
+ .composer textarea::placeholder { color: color-mix(in srgb, var(--luzia-text) 55%, transparent); }
498
+ .composer textarea:disabled { cursor: not-allowed; }
499
+ .send {
500
+ display: grid;
501
+ place-items: center;
502
+ flex: none;
503
+ width: 44px;
504
+ height: 44px;
505
+ padding: 0;
302
506
  border: none;
303
- border-radius: 0.5rem;
507
+ border-radius: 50%;
304
508
  background: var(--luzia-accent);
305
509
  color: var(--luzia-accent-contrast);
306
- font: 600 0.875rem var(--luzia-font);
307
510
  cursor: pointer;
511
+ transition: background-color 150ms ease, opacity 150ms ease, transform 160ms ease-out;
512
+ }
513
+ .send svg { display: block; }
514
+ @media (hover: hover) and (pointer: fine) {
515
+ .send:not(:disabled):hover { background: color-mix(in srgb, var(--luzia-accent) 86%, #000); }
516
+ }
517
+ .send:not(:disabled):active { transform: scale(0.94); }
518
+ .send:disabled { opacity: 0.35; cursor: default; }
519
+ @media (prefers-reduced-motion: reduce) {
520
+ .send:not(:disabled):active { transform: none; }
308
521
  }
309
- .composer button:disabled { opacity: 0.5; cursor: default; }
310
522
  @media (max-width: 480px) {
311
523
  /* The whole visible screen: above the on-screen keyboard when it is open (set by the element from visualViewport). */
312
524
  .panel {
@@ -316,6 +528,7 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
316
528
  width: 100vw;
317
529
  height: var(--luzia-viewport-height, 100vh);
318
530
  margin: 0;
531
+ border: none;
319
532
  border-radius: 0;
320
533
  }
321
534
  @supports (height: 100dvh) {
@@ -326,19 +539,31 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
326
539
  :host([data-keyboard]) .speech-text { max-height: 4.5rem; }
327
540
  /* Inline, the chat stays in the page but never taller than the screen. */
328
541
  :host([mode='inline']) .panel { height: min(var(--luzia-inline-height), 85vh); }
329
- .composer { padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
542
+ .composer { margin-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
543
+ :host(:not([mode='inline'])) .panel { transform-origin: bottom center; }
330
544
  /* Below 16px, mobile browsers zoom the page when the text box gets focus. */
331
545
  .composer textarea { font-size: 16px; }
332
546
  }
333
- `;var m="luzia-widget",q=typeof HTMLElement>"u"?class{}:HTMLElement;function c(i=null){return(document.documentElement.lang||navigator.language||"en").toLowerCase().startsWith("es")?`\xA1Hola! Soy luzIA, una IA que responde preguntas sobre ${i??"la persona de este portfolio"}: su experiencia, sus proyectos y lo que busca. \xBFQu\xE9 te gustar\xEDa saber?`:`Hi! I\u2019m luzIA, an AI agent that answers questions about ${i??"the person behind this portfolio"}: their experience, their projects and what they\u2019re looking for. What would you like to know?`}var R=1500;function W(i){return fetch(i,{headers:{accept:"application/json"}}).then(async e=>{if(!e.ok)return null;let t=await e.json();return typeof t.owner?.name=="string"&&t.owner.name.trim()?t.owner.name.trim():null}).catch(()=>null)}var N=2e3,P=`<svg viewBox="0 0 32 32" width="100%" height="100%" focusable="false">
547
+ `;var k="luzia-widget",X=typeof HTMLElement>"u"?class{}:HTMLElement;function y(r=null){return(document.documentElement.lang||navigator.language||"en").toLowerCase().startsWith("es")?`\xA1Hola! Soy luzIA, una IA que responde preguntas sobre ${r??"la persona de este portfolio"}: su experiencia, sus proyectos y lo que busca. \xBFQu\xE9 te gustar\xEDa saber?`:`Hi! I\u2019m luzIA, an AI agent that answers questions about ${r??"the person behind this portfolio"}: their experience, their projects and what they\u2019re looking for. What would you like to know?`}var ee=1500;function te(r){return fetch(r,{headers:{accept:"application/json"}}).then(async e=>{if(!e.ok)return null;let t=await e.json();return typeof t.owner?.name=="string"&&t.owner.name.trim()?t.owner.name.trim():null}).catch(()=>null)}var re=500,w="Ask luzIA about me",x=`<svg viewBox="0 0 32 32" width="100%" height="100%" focusable="false">
334
548
  <circle cx="16" cy="16" r="16" fill="var(--luzia-accent-contrast)" />
335
549
  <path d="M16 6l2.6 6.4L25 15l-6.4 2.6L16 24l-2.6-6.4L7 15l6.4-2.6z" fill="var(--luzia-accent)" />
336
- </svg>`,V=`
550
+ </svg>`,ie=`
337
551
  <section class="panel" role="dialog" aria-label="luzIA" hidden>
338
552
  <header class="header">
553
+ <span class="header-icon" aria-hidden="true">${x}</span>
339
554
  <h2 class="title">luzIA</h2>
340
- <button type="button" class="new-conversation">New conversation</button>
341
- <button type="button" class="close" aria-label="Close luzIA chat">&times;</button>
555
+ <button type="button" class="new-conversation" aria-label="Restart conversation">
556
+ <svg viewBox="0 0 24 24" width="20" height="20" focusable="false" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
557
+ <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
558
+ <path d="M3 3v5h5" />
559
+ </svg>
560
+ <span class="tooltip" aria-hidden="true">Restart conversation</span>
561
+ </button>
562
+ <button type="button" class="close" aria-label="Close luzIA chat">
563
+ <svg viewBox="0 0 24 24" width="20" height="20" focusable="false" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
564
+ <path d="M18 6 6 18M6 6l12 12" />
565
+ </svg>
566
+ </button>
342
567
  </header>
343
568
  <div class="stage">
344
569
  <span class="avatar" aria-hidden="true"></span>
@@ -353,10 +578,15 @@ var k="conversation_limit_reached",E="message_too_long";function p(i){return i.c
353
578
  <p class="alert" role="alert" hidden></p>
354
579
  <form class="composer">
355
580
  <textarea name="message" rows="2" aria-label="Message luzIA" placeholder="Ask a question\u2026"></textarea>
356
- <button type="submit">Send</button>
581
+ <button type="submit" class="send" aria-label="Send">
582
+ <svg viewBox="0 0 24 24" width="18" height="18" focusable="false" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round">
583
+ <path d="M12 19V5M5 12l7-7 7 7" />
584
+ </svg>
585
+ </button>
357
586
  </form>
358
587
  </section>
359
- <button type="button" class="bubble" aria-label="luzIA chat" aria-expanded="false">
360
- <span aria-hidden="true">luzIA</span>
588
+ <button type="button" class="bubble" aria-label="${w}" aria-expanded="false">
589
+ <span class="bubble-icon" aria-hidden="true">${x}</span>
590
+ <span class="bubble-label" aria-hidden="true"><span class="bubble-text">${w}</span></span>
361
591
  </button>
362
- `,h=class extends q{conversation=new d({endpoint:()=>this.endpoint});#e=null;get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get contact(){return this.getAttribute("contact")??""}set contact(e){this.setAttribute("contact",e)}get greeting(){return this.getAttribute("greeting")??c()}set greeting(e){this.setAttribute("greeting",e)}get suggestedQuestions(){return j(this.getAttribute("suggested-questions"))}set suggestedQuestions(e){this.setAttribute("suggested-questions",JSON.stringify(e))}get mode(){return this.getAttribute("mode")==="inline"?"inline":"bubble"}set mode(e){this.setAttribute("mode",e)}get theme(){let e=this.getAttribute("theme");return e==="dark"||e==="auto"?e:"light"}set theme(e){this.setAttribute("theme",e)}get avatar(){return this.getAttribute("avatar")??""}set avatar(e){this.setAttribute("avatar",e)}static get observedAttributes(){return["greeting","suggested-questions","mode","avatar"]}connectedCallback(){if(this.#e)return;let e=this.attachShadow({mode:"open"});e.innerHTML=`<style>${C}</style>${V}`,L(this.conversation,z(this.endpoint));let t=null,s=()=>this.hasAttribute("greeting")||!this.endpoint?null:(t??=W(this.endpoint),t);this.#e=new g(e,this.conversation,()=>this.contact,s),this.#e.configure(this),s()}attributeChangedCallback(){this.#e?.configure(this)}};function j(i){if(!i)return[];let e;try{e=JSON.parse(i)}catch{return[]}return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(Boolean):[]}var g=class{#e;#r;#c;#t;#g;#i;#f;#n;#p;#a=null;#o="";#d;#T=null;#z=!1;#l;#b=!1;#L=!1;#h;#C;#v;#A;#y;#s;#M;#u;#I;#w="bubble";#O=!1;#S;#k=null;constructor(e,t,s,n=()=>null){this.#S=n,this.#u=t,this.#d=e.host,this.#I=s,this.#e=e.querySelector(".bubble"),this.#r=e.querySelector(".panel"),this.#c=e.querySelector(".close"),this.#t=e.querySelector(".body"),this.#g=e.querySelector(".greeting"),this.#i=e.querySelector(".avatar"),this.#f=e.querySelector(".stage"),this.#n=e.querySelector(".speech"),this.#p=e.querySelector(".speech-text"),this.#n.addEventListener("mouseenter",()=>{this.#b=!0,this.#L=!0,clearTimeout(this.#l),this.#l=void 0,this.#n.classList.remove("leaving")}),this.#n.addEventListener("mouseleave",()=>{this.#b=!1,this.#m(this.#u.state)}),this.#h=e.querySelector(".messages"),this.#C=e.querySelector(".announcer"),this.#v=e.querySelector(".suggestions"),this.#A=e.querySelector(".alert"),this.#y=e.querySelector(".composer"),this.#s=this.#y.querySelector("textarea"),this.#M=this.#y.querySelector("button"),this.#e.addEventListener("click",()=>this.#E(this.#e.getAttribute("aria-expanded")!=="true")),this.#c.addEventListener("click",()=>this.#E(!1)),this.#r.addEventListener("keydown",r=>{r.key==="Escape"&&this.#w==="bubble"&&!r.isComposing&&(r.preventDefault(),this.#E(!1))}),e.querySelector(".new-conversation").addEventListener("click",()=>{t.reset(),this.#z=!1,this.#q(),this.#s.focus()}),this.#y.addEventListener("submit",r=>{r.preventDefault(),this.#R()}),this.#s.addEventListener("keydown",r=>{r.key==="Enter"&&!r.shiftKey&&!r.isComposing&&(r.preventDefault(),this.#R())}),t.subscribe(r=>this.#m(r)),this.#m(t.state)}configure(e){this.#V(e.avatar.trim()),this.#o=this.#k&&this.#S()?c(this.#k):e.greeting.trim(),this.#g.textContent=this.#o,this.#v.replaceChildren(...e.suggestedQuestions.map(t=>{let s=document.createElement("button");s.type="button",s.className="suggestion",s.textContent=t,s.addEventListener("click",()=>{this.#u.send(t)&&this.#s.focus()});let n=document.createElement("li");return n.append(s),n})),this.#m(this.#u.state),e.mode!==this.#w&&this.#N(e.mode)}#N(e){this.#w=e;let t=e==="inline";this.#r.setAttribute("role",t?"region":"dialog"),this.#e.hidden=t,this.#c.hidden=t,this.#H(t)}#E(e){this.#H(e),(e?this.#s:this.#e).focus()}#H(e){this.#r.hidden=!e,this.#e.setAttribute("aria-expanded",String(e)),e&&this.#q(),this.#T?.(),this.#T=e?this.#P():null}#P(){let e=window.visualViewport;if(!e)return null;let t=()=>{if(!(this.#w==="bubble"&&window.matchMedia("(max-width: 480px)").matches))return this.#_();this.#d.style.setProperty("--luzia-viewport-height",`${e.height}px`),this.#d.style.setProperty("--luzia-viewport-top",`${e.offsetTop}px`),this.#d.toggleAttribute("data-keyboard",e.height<window.innerHeight*.75)};return t(),e.addEventListener("resize",t),e.addEventListener("scroll",t),()=>{e.removeEventListener("resize",t),e.removeEventListener("scroll",t),this.#_()}}#_(){this.#d.style.removeProperty("--luzia-viewport-height"),this.#d.style.removeProperty("--luzia-viewport-top"),this.#d.removeAttribute("data-keyboard")}#q(){if(this.#z||this.#r.hidden)return;this.#z=!0;let e=()=>{!this.#o||this.#r.hidden||this.#u.state.messages.length>0||(this.#x(),this.#a="greeting",this.#W(this.#o),this.#m(this.#u.state))},t=this.#S();if(!t)return e();let s=new Promise(n=>setTimeout(()=>n(null),R));Promise.race([t,s]).then(n=>{n&&(this.#k=n,this.#o=c(n),this.#g.textContent=this.#o),e()})}#V(e){let t=this.#i.querySelector("img")?.getAttribute("src")??null;if(!(e&&t===e)&&!(!e&&t===null&&this.#i.firstChild))if(e){let s=document.createElement("img");s.src=e,s.alt="",this.#i.replaceChildren(s)}else this.#i.innerHTML=P}#R(){let e=this.#s.value;this.#u.send(e)&&(this.#s.value="",this.#s.focus())}#j(e,t){let s=this.#O&&!t;if(this.#O=t,(t||e.messages.length===0)&&(this.#C.textContent=""),!s)return;let n=e.messages.at(-1);this.#C.textContent=e.status==="idle"&&n?.role==="assistant"?n.content:""}#F(e,t){let s=e.messages.length-1,n=e.messages[s]?.role==="assistant";if(t&&n)this.#a!==s&&this.#x(),this.#a=s,clearTimeout(this.#l),this.#W(e.messages[s].content);else if(this.#a!==null){let r=this.#a==="greeting";if(!(r?e.messages.length===0:this.#a===s&&e.status==="idle"))this.#x();else if(this.#l===void 0&&!this.#b){let u=r?this.#o:e.messages[s].content,a=this.#L?N:Math.min(1e4,4e3+u.length*40);this.#l=setTimeout(()=>this.#$(),a)}}[...this.#h.children].forEach((r,o)=>{r.hidden=o===this.#a}),this.#g.hidden=!this.#o||this.#a==="greeting"}#W(e){this.#n.classList.remove("leaving"),this.#n.hidden=e==="",this.#f.toggleAttribute("data-saying",!this.#n.hidden),this.#p.textContent!==e&&(this.#p.textContent=e)}#$(){this.#n.classList.add("leaving"),this.#l=setTimeout(()=>{this.#x(),this.#m(this.#u.state)},400)}#x(){clearTimeout(this.#l),this.#l=void 0,this.#a=null,this.#n.hidden=!0,this.#b=!1,this.#L=!1,this.#f.removeAttribute("data-saying"),this.#p.scrollTop=0,this.#n.classList.remove("leaving"),this.#p.textContent=""}#m(e){for(e.messages.forEach((r,o)=>{let u=this.#h.children[o],a=u;(!a||a.dataset.role!==r.role)&&(a=document.createElement("li"),a.className="message",a.dataset.role=r.role,u?u.replaceWith(a):this.#h.append(a)),a.textContent!==r.content&&(a.textContent=r.content)});this.#h.children.length>e.messages.length;)this.#h.lastElementChild?.remove();this.#v.hidden=e.messages.length>0||this.#v.children.length===0;let t=e.status==="streaming";this.#F(e,t),this.#t.scrollTop=this.#t.scrollHeight,this.#f.toggleAttribute("data-speaking",t),this.#h.setAttribute("aria-busy",String(t)),this.#j(e,t);let s=e.status==="error"&&e.error?p(e.error):null;f(this.#A,s,this.#I());let n=s==="limit";this.#s.disabled=n,this.#M.disabled=t||n,e.unsent!==null&&!n&&!this.#s.value&&(this.#s.value=e.unsent)}};function S(){customElements.get(m)||customElements.define(m,h)}S();export{d as Conversation,m as LUZIA_WIDGET_TAG,l as LuziaRequestError,h as LuziaWidgetElement,S as defineLuziaWidget};
592
+ `,m=class extends X{conversation=new h({endpoint:()=>this.endpoint});#e=null;get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get contact(){return this.getAttribute("contact")??""}set contact(e){this.setAttribute("contact",e)}get greeting(){return this.getAttribute("greeting")??y()}set greeting(e){this.setAttribute("greeting",e)}get suggestedQuestions(){return ne(this.getAttribute("suggested-questions"))}set suggestedQuestions(e){this.setAttribute("suggested-questions",JSON.stringify(e))}get mode(){return this.getAttribute("mode")==="inline"?"inline":"bubble"}set mode(e){this.setAttribute("mode",e)}get theme(){let e=this.getAttribute("theme");return e==="dark"||e==="auto"?e:"light"}set theme(e){this.setAttribute("theme",e)}get avatar(){return this.getAttribute("avatar")??""}set avatar(e){this.setAttribute("avatar",e)}get bubbleLabel(){return this.getAttribute("bubble-label")?.trim()||w}set bubbleLabel(e){this.setAttribute("bubble-label",e)}static get observedAttributes(){return["greeting","suggested-questions","mode","avatar","bubble-label"]}connectedCallback(){if(this.#e)return;let e=this.attachShadow({mode:"open"});e.innerHTML=`<style>${_}</style>${ie}`,O(this.conversation,W(this.endpoint));let t=null,i=()=>this.hasAttribute("greeting")||!this.endpoint?null:(t??=te(this.endpoint),t);this.#e=new z(e,this.conversation,()=>this.contact,i),this.#e.configure(this),i()}attributeChangedCallback(){this.#e?.configure(this)}};function ne(r){if(!r)return[];let e;try{e=JSON.parse(r)}catch{return[]}return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(Boolean):[]}var z=class{#e;#n;#g;#t;#m;#r;#f;#s;#d;#a=null;#o="";#c;#C=null;#k=!1;#l;#v=!1;#L=!1;#h;#E;#y;#M;#w;#i;#I;#u;#R;#x="bubble";#b=new WeakMap;#H=!1;#S;#A=null;constructor(e,t,i,n=()=>null){this.#S=n,this.#u=t,this.#c=e.host,this.#R=i,this.#e=e.querySelector(".bubble"),this.#n=e.querySelector(".panel"),this.#g=e.querySelector(".close"),this.#t=e.querySelector(".body"),this.#m=e.querySelector(".greeting"),this.#r=e.querySelector(".avatar"),this.#f=e.querySelector(".stage"),this.#s=e.querySelector(".speech"),this.#d=e.querySelector(".speech-text"),this.#s.addEventListener("mouseenter",()=>{this.#v=!0,this.#L=!0,clearTimeout(this.#l),this.#l=void 0,this.#s.classList.remove("leaving")}),this.#s.addEventListener("mouseleave",()=>{this.#v=!1,this.#p(this.#u.state)}),this.#h=e.querySelector(".messages"),this.#E=e.querySelector(".announcer"),this.#y=e.querySelector(".suggestions"),this.#M=e.querySelector(".alert"),this.#w=e.querySelector(".composer"),this.#i=this.#w.querySelector("textarea"),this.#I=this.#w.querySelector("button"),this.#e.addEventListener("click",()=>this.#T(this.#e.getAttribute("aria-expanded")!=="true")),this.#g.addEventListener("click",()=>this.#T(!1)),this.#n.addEventListener("keydown",s=>{s.key==="Escape"&&this.#x==="bubble"&&!s.isComposing&&(s.preventDefault(),this.#T(!1))}),e.querySelector(".new-conversation").addEventListener("click",()=>{t.reset(),this.#k=!1,this.#_(),this.#i.focus()}),this.#w.addEventListener("submit",s=>{s.preventDefault(),this.#q()}),this.#i.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&!s.isComposing&&(s.preventDefault(),this.#q())}),t.subscribe(s=>this.#p(s)),this.#p(t.state)}configure(e){this.#V(e.avatar.trim()),this.#e.setAttribute("aria-label",e.bubbleLabel),this.#e.querySelector(".bubble-text").textContent=e.bubbleLabel,this.#o=this.#A&&this.#S()?y(this.#A):e.greeting.trim(),this.#m.textContent=this.#o,this.#y.replaceChildren(...e.suggestedQuestions.map(t=>{let i=document.createElement("button");i.type="button",i.className="suggestion",i.textContent=t,i.addEventListener("click",()=>{this.#u.send(t)&&this.#i.focus()});let n=document.createElement("li");return n.append(i),n})),this.#p(this.#u.state),e.mode!==this.#x&&this.#$(e.mode)}#$(e){this.#x=e;let t=e==="inline";this.#n.setAttribute("role",t?"region":"dialog"),this.#e.hidden=t,this.#g.hidden=t,this.#W(t)}#T(e){this.#W(e),(e?this.#i:this.#e).focus()}#W(e){this.#n.hidden=!e,this.#e.setAttribute("aria-expanded",String(e)),e&&this.#_(),this.#C?.(),this.#C=e?this.#P():null}#P(){let e=window.visualViewport;if(!e)return null;let t=()=>{if(!(this.#x==="bubble"&&window.matchMedia("(max-width: 480px)").matches))return this.#O();this.#c.style.setProperty("--luzia-viewport-height",`${e.height}px`),this.#c.style.setProperty("--luzia-viewport-top",`${e.offsetTop}px`),this.#c.toggleAttribute("data-keyboard",e.height<window.innerHeight*.75)};return t(),e.addEventListener("resize",t),e.addEventListener("scroll",t),()=>{e.removeEventListener("resize",t),e.removeEventListener("scroll",t),this.#O()}}#O(){this.#c.style.removeProperty("--luzia-viewport-height"),this.#c.style.removeProperty("--luzia-viewport-top"),this.#c.removeAttribute("data-keyboard")}#_(){if(this.#k||this.#n.hidden)return;this.#k=!0;let e=()=>{!this.#o||this.#n.hidden||this.#u.state.messages.length>0||(this.#z(),this.#a="greeting",this.#N(this.#o),this.#p(this.#u.state))},t=this.#S();if(!t)return e();let i=new Promise(n=>setTimeout(()=>n(null),ee));Promise.race([t,i]).then(n=>{n&&(this.#A=n,this.#o=y(n),this.#m.textContent=this.#o),e()})}#V(e){let t=this.#r.querySelector("img")?.getAttribute("src")??null;if(!(e&&t===e)&&!(!e&&t===null&&this.#r.firstChild))if(e){let i=document.createElement("img");i.src=e,i.alt="",this.#r.replaceChildren(i)}else this.#r.innerHTML=x}#q(){let e=this.#i.value;this.#u.send(e)&&(this.#i.value="",this.#i.focus())}#B(e,t){let i=this.#H&&!t;if(this.#H=t,(t||e.messages.length===0)&&(this.#E.textContent=""),!i)return;let n=e.messages.at(-1);this.#E.textContent=e.status==="idle"&&n?.role==="assistant"?n.content:""}#j(e,t){let i=e.messages.length-1,n=e.messages[i]?.role==="assistant";if(t&&n)this.#a!==i&&this.#z(),this.#a=i,clearTimeout(this.#l),this.#N(e.messages[i].content);else if(this.#a!==null){let s=this.#a==="greeting";if(!(s?e.messages.length===0:this.#a===i&&e.status==="idle"))this.#z();else if(this.#l===void 0&&!this.#v){let l=s?this.#o:e.messages[i].content,a=this.#L?re:Math.min(1e4,4e3+l.length*40);this.#l=setTimeout(()=>this.#F(),a)}}[...this.#h.children].forEach((s,o)=>{s.hidden=o===this.#a}),this.#m.hidden=!this.#o||this.#a==="greeting"}#N(e){this.#s.classList.remove("leaving"),this.#s.hidden=e==="",this.#f.toggleAttribute("data-saying",!this.#s.hidden),this.#b.get(this.#d)!==e&&(this.#b.set(this.#d,e),v(this.#d,e,{focusable:!1}))}#F(){this.#s.classList.add("leaving"),this.#l=setTimeout(()=>{this.#z(),this.#p(this.#u.state)},400)}#z(){clearTimeout(this.#l),this.#l=void 0,this.#a=null,this.#s.hidden=!0,this.#v=!1,this.#L=!1,this.#f.removeAttribute("data-saying"),this.#d.scrollTop=0,this.#s.classList.remove("leaving"),this.#d.textContent="",this.#b.delete(this.#d)}#p(e){for(e.messages.forEach((s,o)=>{let l=this.#h.children[o],a=l;(!a||a.dataset.role!==s.role)&&(a=document.createElement("li"),a.className="message",a.dataset.role=s.role,l?l.replaceWith(a):this.#h.append(a)),this.#b.get(a)!==s.content&&(this.#b.set(a,s.content),s.role==="assistant"?v(a,s.content):a.textContent=s.content)});this.#h.children.length>e.messages.length;)this.#h.lastElementChild?.remove();this.#y.hidden=e.messages.length>0||this.#y.children.length===0;let t=e.status==="streaming";this.#j(e,t),this.#t.scrollTop=this.#t.scrollHeight,this.#f.toggleAttribute("data-speaking",t),this.#h.setAttribute("aria-busy",String(t)),this.#B(e,t);let i=e.status==="error"&&e.error?E(e.error):null;S(this.#M,i,this.#R());let n=i==="limit";this.#i.disabled=n,this.#I.disabled=t||n,e.unsent!==null&&!n&&!this.#i.value&&(this.#i.value=e.unsent)}};function q(){customElements.get(k)||customElements.define(k,m)}q();export{h as Conversation,k as LUZIA_WIDGET_TAG,u as LuziaRequestError,m as LuziaWidgetElement,q as defineLuziaWidget};