@streamoji/aitwin 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aitwin.js CHANGED
@@ -1,73 +1,73 @@
1
- import { jsxs as Tt, jsx as je } from "react/jsx-runtime";
2
- import { forwardRef as vt, useRef as B, useState as _e, useCallback as ne, useEffect as oe, useMemo as It, useImperativeHandle as At } from "react";
3
- const Rt = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", ut = {
4
- publicBase: Rt
5
- }, bt = "0.1.6", Dt = {
6
- version: bt
7
- }, xt = {}, Re = "https://ai.streamoji.com", Ct = `${ut.publicBase}/custom-faces`, Mt = `${ut.publicBase}/aitwin-workers/v${Dt.version}/visemeDiffPreview.worker.js`;
8
- function Ft(e) {
1
+ import { jsxs as Bt, jsx as it } from "react/jsx-runtime";
2
+ import { forwardRef as Nt, useRef as R, useState as ke, useCallback as ie, useEffect as Te, useMemo as Vt, useImperativeHandle as $t } from "react";
3
+ const Ht = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", St = {
4
+ publicBase: Ht
5
+ }, Wt = "0.1.8", qt = {
6
+ version: Wt
7
+ }, Kt = {}, Pe = "https://ai.streamoji.com", jt = `${St.publicBase}/custom-faces`, Gt = `${St.publicBase}/aitwin-workers/v${qt.version}/visemeDiffPreview.worker.js`;
8
+ function zt(e) {
9
9
  if (e) return e;
10
- const t = typeof import.meta < "u" ? xt?.VITE_AITWIN_WORKER_URL : void 0;
11
- return t?.trim() ? t.trim() : Mt;
12
- }
13
- const Pt = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", lt = "eng_a7f2b9c1", qe = "eng_d4e8f3a2", pe = "eng_c9b1e6d4", ce = pe, Ot = /* @__PURE__ */ new Set([
14
- qe,
15
- pe
16
- ]), ft = {
17
- [lt]: "oculus_direct",
18
- [pe]: "oculus_direct",
19
- [qe]: "inworld_word"
20
- }, ze = {
21
- google: lt,
22
- inworld: qe,
23
- cartesia: pe
10
+ const t = typeof import.meta < "u" ? Kt?.VITE_AITWIN_WORKER_URL : void 0;
11
+ return t?.trim() ? t.trim() : Gt;
12
+ }
13
+ const Qt = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", kt = "eng_a7f2b9c1", Ze = "eng_d4e8f3a2", be = "eng_c9b1e6d4", pe = be, Jt = /* @__PURE__ */ new Set([
14
+ Ze,
15
+ be
16
+ ]), Tt = {
17
+ [kt]: "oculus_direct",
18
+ [be]: "oculus_direct",
19
+ [Ze]: "inworld_word"
20
+ }, st = {
21
+ google: kt,
22
+ inworld: Ze,
23
+ cartesia: be
24
24
  };
25
- function Lt(e) {
26
- return ft[e];
25
+ function Yt(e) {
26
+ return Tt[e];
27
27
  }
28
- function Ut(e) {
29
- return e === pe;
28
+ function Xt(e) {
29
+ return e === be;
30
30
  }
31
- function Bt(e) {
32
- if (e.ttsEngineId && e.ttsEngineId in ft)
31
+ function Zt(e) {
32
+ if (e.ttsEngineId && e.ttsEngineId in Tt)
33
33
  return e.ttsEngineId;
34
34
  const t = e.tts?.toLowerCase();
35
- return t && t in ze ? ze[t] : ce;
35
+ return t && t in st ? st[t] : pe;
36
36
  }
37
- class Le extends Error {
37
+ class Ke extends Error {
38
38
  constructor(t = "AI twin not found") {
39
39
  super(t), this.name = "AiTwinNotFoundError";
40
40
  }
41
41
  }
42
- async function Nt(e, t = Pt) {
42
+ async function en(e, t = Qt) {
43
43
  const n = new URL(t);
44
44
  n.searchParams.set("id", e);
45
45
  const r = await fetch(n.toString());
46
46
  if (r.status === 404)
47
- throw new Le();
47
+ throw new Ke();
48
48
  if (!r.ok)
49
49
  throw new Error(`getAiTwin failed (${r.status})`);
50
50
  const i = await r.json();
51
51
  if (!i.success)
52
- throw new Le(i.error ?? "AI twin not found");
53
- const { tts: s, ...a } = i.data;
52
+ throw new Ke(i.error ?? "AI twin not found");
53
+ const { tts: s, ...c } = i.data;
54
54
  return {
55
- ...a,
56
- ttsEngineId: Bt(i.data)
55
+ ...c,
56
+ ttsEngineId: Zt(i.data)
57
57
  };
58
58
  }
59
- const $t = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Vt = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Ht = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Wt = "6TNvp3SCs4Og0a1ijm9TommXLql1", qt = "Swaraj Mali";
60
- async function Qe() {
61
- const e = await fetch($t, {
59
+ const tn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", nn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", rn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", sn = "6TNvp3SCs4Og0a1ijm9TommXLql1", on = "Swaraj Mali";
60
+ async function ot() {
61
+ const e = await fetch(tn, {
62
62
  method: "POST",
63
63
  headers: {
64
64
  "Content-Type": "application/json",
65
- "Client-Id": Vt,
66
- "Client-Secret": Ht
65
+ "Client-Id": nn,
66
+ "Client-Secret": rn
67
67
  },
68
68
  body: JSON.stringify({
69
- userId: Wt,
70
- userName: qt
69
+ userId: sn,
70
+ userName: on
71
71
  })
72
72
  });
73
73
  if (!e.ok)
@@ -77,7 +77,7 @@ async function Qe() {
77
77
  throw new Error("getAuthToken returned no token");
78
78
  return n;
79
79
  }
80
- async function Kt(e, t = Re) {
80
+ async function an(e, t = Pe) {
81
81
  const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
82
82
  headers: { Authorization: `Bearer ${e}` }
83
83
  });
@@ -87,7 +87,7 @@ async function Kt(e, t = Re) {
87
87
  if (!r.value) throw new Error("Session value response missing value");
88
88
  return r;
89
89
  }
90
- function Gt(e) {
90
+ function cn(e) {
91
91
  const t = e.trim();
92
92
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
93
93
  const n = new Uint8Array(t.length / 2);
@@ -95,41 +95,41 @@ function Gt(e) {
95
95
  n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
96
96
  return n;
97
97
  }
98
- function Te(e) {
98
+ function Ce(e) {
99
99
  return Uint8Array.from(e);
100
100
  }
101
- function jt(e, t) {
101
+ function un(e, t) {
102
102
  const n = new Uint8Array(e.length + t.length);
103
103
  return n.set(e, 0), n.set(t, e.length), n;
104
104
  }
105
- async function zt(e, t) {
105
+ async function ln(e, t) {
106
106
  if (!t) throw new Error("Asset key is required for encrypted assets");
107
107
  if (e.byteLength < 28)
108
108
  throw new Error("Encrypted payload too small");
109
- const n = new Uint8Array(e), r = Te(n.subarray(0, 12)), i = Te(n.subarray(12, 28)), s = Te(n.subarray(28)), a = Te(jt(s, i)), c = await crypto.subtle.importKey(
109
+ const n = new Uint8Array(e), r = Ce(n.subarray(0, 12)), i = Ce(n.subarray(12, 28)), s = Ce(n.subarray(28)), c = Ce(un(s, i)), a = await crypto.subtle.importKey(
110
110
  "raw",
111
- Gt(t),
111
+ cn(t),
112
112
  { name: "AES-GCM" },
113
113
  !1,
114
114
  ["decrypt"]
115
115
  );
116
116
  return crypto.subtle.decrypt(
117
117
  { name: "AES-GCM", iv: r, tagLength: 128 },
118
- c,
119
- a
118
+ a,
119
+ c
120
120
  );
121
121
  }
122
- let Ue = null;
123
- const Be = /* @__PURE__ */ new Set();
124
- function Qt(e, t = Ct) {
122
+ let je = null;
123
+ const Ge = /* @__PURE__ */ new Set();
124
+ function fn(e, t = jt) {
125
125
  const n = `${t.replace(/\/$/, "")}/${e}`;
126
126
  return { twinBase: n, binBase: n, encrypted: !0 };
127
127
  }
128
- function Jt(e) {
129
- Ue = e;
130
- for (const t of Be) t();
128
+ function dn(e) {
129
+ je = e;
130
+ for (const t of Ge) t();
131
131
  }
132
- function Yt(e, t) {
132
+ function hn(e, t) {
133
133
  const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
134
134
  if (!n) return e;
135
135
  const r = (i) => {
@@ -145,36 +145,38 @@ function Yt(e, t) {
145
145
  encrypted: e.encrypted
146
146
  };
147
147
  }
148
- function ie() {
149
- if (!Ue)
148
+ function he() {
149
+ if (!je)
150
150
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
151
- return Ue;
151
+ return je;
152
152
  }
153
- function Xt(e) {
154
- return Be.add(e), () => Be.delete(e);
153
+ function mn(e) {
154
+ return Ge.add(e), () => Ge.delete(e);
155
155
  }
156
- function Zt() {
157
- return `${ie().twinBase}/sil.png`;
156
+ function at() {
157
+ const { encrypted: e, binBase: t, twinBase: n } = he();
158
+ return e ? `${t}/sil.bin` : `${n}/sil.png`;
158
159
  }
159
- function en() {
160
- return `${ie().twinBase}/idle.mp4`;
160
+ function _n() {
161
+ const { encrypted: e, binBase: t, twinBase: n } = he();
162
+ return e ? `${t}/idle.bin` : `${n}/idle.mp4`;
161
163
  }
162
- function tn() {
163
- const { encrypted: e, binBase: t, twinBase: n } = ie();
164
+ function wn() {
165
+ const { encrypted: e, binBase: t, twinBase: n } = he();
164
166
  return e ? t : n;
165
167
  }
166
- function dt() {
167
- return ie().encrypted;
168
+ function Be() {
169
+ return he().encrypted;
168
170
  }
169
- function nn() {
170
- const { binBase: e, twinBase: t, encrypted: n } = ie();
171
+ function gn() {
172
+ const { binBase: e, twinBase: t, encrypted: n } = he();
171
173
  return n ? `${e}/atlas.bin` : `${t}/atlas.json`;
172
174
  }
173
- function rn() {
174
- const { binBase: e, twinBase: t, encrypted: n } = ie();
175
+ function yn() {
176
+ const { binBase: e, twinBase: t, encrypted: n } = he();
175
177
  return n ? `${e}/expression_atlas.bin` : `${t}/expression_atlas.json`;
176
178
  }
177
- function sn(e) {
179
+ function pn(e) {
178
180
  const t = e.split(/\r?\n/);
179
181
  let n = "", r = "";
180
182
  for (const s of t)
@@ -189,7 +191,7 @@ function sn(e) {
189
191
  }
190
192
  return { event: n, data: i };
191
193
  }
192
- const on = [
194
+ const En = [
193
195
  "aa",
194
196
  "CH",
195
197
  "DD",
@@ -205,14 +207,14 @@ const on = [
205
207
  "kk",
206
208
  "nn",
207
209
  "sil"
208
- ], an = new Map(
209
- on.map((e) => [e.toLowerCase(), e])
210
+ ], Sn = new Map(
211
+ En.map((e) => [e.toLowerCase(), e])
210
212
  );
211
- function cn(e) {
213
+ function kn(e) {
212
214
  const t = (e ?? "").trim();
213
- return t ? an.get(t.toLowerCase()) ?? "sil" : "sil";
215
+ return t ? Sn.get(t.toLowerCase()) ?? "sil" : "sil";
214
216
  }
215
- const un = {
217
+ const Tn = {
216
218
  aei: ["aa", "E", "I"],
217
219
  o: ["O", "U"],
218
220
  ee: ["I"],
@@ -224,12 +226,12 @@ const un = {
224
226
  qw: ["U", "O"],
225
227
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
226
228
  };
227
- function ln(e) {
229
+ function vn(e) {
228
230
  if (!e) return ["sil"];
229
231
  const t = e.toLowerCase();
230
- return un[t] ?? ["sil"];
232
+ return Tn[t] ?? ["sil"];
231
233
  }
232
- function fn(e, t) {
234
+ function In(e, t) {
233
235
  const n = e.word.length;
234
236
  if (n <= 0) return 0;
235
237
  const r = e.wduration;
@@ -237,33 +239,33 @@ function fn(e, t) {
237
239
  const i = Math.max(0, Math.min(1, (t - e.wtime) / r));
238
240
  return Math.min(n - 1, Math.floor(i * n));
239
241
  }
240
- function De(e, t) {
242
+ function Ne(e, t) {
241
243
  const n = Math.max(0, Math.min(e.length - 1, t));
242
244
  return e[n] ?? "";
243
245
  }
244
- function dn(e, t) {
245
- const n = e.toLowerCase(), r = De(n, t), i = n.slice(Math.max(0, t - 1), t + 2);
246
+ function An(e, t) {
247
+ const n = e.toLowerCase(), r = Ne(n, t), i = n.slice(Math.max(0, t - 1), t + 2);
246
248
  return r === "i" || r === "y" ? "I" : i.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
247
249
  }
248
- function hn(e, t) {
250
+ function bn(e, t) {
249
251
  const n = e.toLowerCase(), r = n.slice(
250
252
  Math.max(0, t - 1),
251
253
  Math.min(n.length, t + 3)
252
254
  );
253
255
  if (/oo|ou|uw/.test(r)) return "U";
254
- const i = De(n, t);
256
+ const i = Ne(n, t);
255
257
  return i === "u" || i === "w" ? "U" : "O";
256
258
  }
257
- function _n(e, t) {
259
+ function Rn(e, t) {
258
260
  const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
259
261
  if (/qu/.test(r)) return "U";
260
262
  const i = n.slice(
261
263
  Math.max(0, t - 1),
262
264
  Math.min(n.length, t + 3)
263
265
  );
264
- return /wo|wh/.test(i) || De(n, t) === "o" ? "O" : "U";
266
+ return /wo|wh/.test(i) || Ne(n, t) === "o" ? "O" : "U";
265
267
  }
266
- const ve = {
268
+ const Fe = {
267
269
  d: "DD",
268
270
  t: "DD",
269
271
  n: "DD",
@@ -275,65 +277,65 @@ const ve = {
275
277
  x: "CH",
276
278
  j: "CH"
277
279
  };
278
- function mn(e, t) {
279
- const n = e.toLowerCase(), r = De(n, t);
280
- if (ve[r]) return ve[r];
280
+ function Dn(e, t) {
281
+ const n = e.toLowerCase(), r = Ne(n, t);
282
+ if (Fe[r]) return Fe[r];
281
283
  for (let i = 0; i < n.length; i++) {
282
284
  const s = n[i];
283
- if (ve[s]) return ve[s];
285
+ if (Fe[s]) return Fe[s];
284
286
  }
285
287
  return "DD";
286
288
  }
287
- function wn(e, t, n) {
288
- const r = ln(e);
289
+ function xn(e, t, n) {
290
+ const r = vn(e);
289
291
  if (r.length === 1) return r[0];
290
292
  const i = t.trim();
291
293
  if (!i) return r[0];
292
- const s = (e ?? "").toLowerCase(), a = Math.max(0, n);
294
+ const s = (e ?? "").toLowerCase(), c = Math.max(0, n);
293
295
  switch (s) {
294
296
  case "aei":
295
- return dn(i, a);
297
+ return An(i, c);
296
298
  case "o":
297
- return hn(i, a);
299
+ return bn(i, c);
298
300
  case "qw":
299
- return _n(i, a);
301
+ return Rn(i, c);
300
302
  case "cdgknstxyz":
301
- return mn(i, a);
303
+ return Dn(i, c);
302
304
  default:
303
305
  return r[0];
304
306
  }
305
307
  }
306
- function gn(e) {
308
+ function Mn(e) {
307
309
  let t = e.trim();
308
310
  const n = t.indexOf(",");
309
311
  t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
310
312
  const r = t.length % 4;
311
313
  return r !== 0 && (t += "=".repeat(4 - r)), t;
312
314
  }
313
- const yn = 24e3;
314
- function pn(e) {
315
+ const Cn = 24e3;
316
+ function Fn(e) {
315
317
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
316
318
  }
317
- function Je(e, t, n = yn) {
319
+ function ct(e, t, n = Cn) {
318
320
  const r = t.byteOffset % 2 === 0 ? t : t.slice(), i = new Int16Array(
319
321
  r.buffer,
320
322
  r.byteOffset,
321
323
  r.byteLength / 2
322
324
  ), s = new Float32Array(i.length);
323
- for (let c = 0; c < i.length; c++)
324
- s[c] = i[c] >= 32768 ? -(65536 - i[c]) / 32768 : i[c] / 32767;
325
- const a = e.createBuffer(1, s.length, n);
326
- return a.copyToChannel(s, 0), a;
325
+ for (let a = 0; a < i.length; a++)
326
+ s[a] = i[a] >= 32768 ? -(65536 - i[a]) / 32768 : i[a] / 32767;
327
+ const c = e.createBuffer(1, s.length, n);
328
+ return c.copyToChannel(s, 0), c;
327
329
  }
328
- function En(e) {
329
- const t = gn(e), n = window.atob(t), r = new Uint8Array(n.length);
330
+ function Ln(e) {
331
+ const t = Mn(e), n = window.atob(t), r = new Uint8Array(n.length);
330
332
  for (let i = 0; i < n.length; i++)
331
333
  r[i] = n.charCodeAt(i);
332
334
  return r;
333
335
  }
334
- async function kn(e, t) {
335
- const n = En(t);
336
- if (pn(n)) {
336
+ async function On(e, t) {
337
+ const n = Ln(t);
338
+ if (Fn(n)) {
337
339
  const r = n.buffer.slice(
338
340
  n.byteOffset,
339
341
  n.byteOffset + n.byteLength
@@ -341,7 +343,7 @@ async function kn(e, t) {
341
343
  return e.decodeAudioData(r);
342
344
  }
343
345
  if (n.length >= 2 && n.length % 2 === 0)
344
- return Je(e, n);
346
+ return ct(e, n);
345
347
  try {
346
348
  const r = n.buffer.slice(
347
349
  n.byteOffset,
@@ -349,288 +351,288 @@ async function kn(e, t) {
349
351
  );
350
352
  return await e.decodeAudioData(r);
351
353
  } catch {
352
- return Je(e, n);
354
+ return ct(e, n);
353
355
  }
354
356
  }
355
- function Sn(e, t) {
357
+ function vt(e, t) {
356
358
  let n = null;
357
359
  for (const r of e)
358
360
  t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
359
361
  return n ? n.viseme : "sil";
360
362
  }
361
- function Tn(e, t) {
363
+ function Pn(e, t) {
362
364
  for (const n of e)
363
365
  if (t >= n.wtime && t < n.wtime + n.wduration)
364
366
  return n;
365
367
  return null;
366
368
  }
367
- function Ye(e) {
369
+ function ut(e) {
368
370
  let t = 0;
369
371
  for (const n of e)
370
372
  t = Math.max(t, n.vtime + n.vduration);
371
373
  return t;
372
374
  }
373
- const vn = 0.5, In = 1.5, ht = "Olivia", An = "f786b574-daa5-4673-aa0c-cbe3e8534c02", _t = 0.85;
374
- function Rn(e, t = Re) {
375
+ const Un = 0.5, Bn = 1.5, It = "Olivia", Nn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", At = 0.85;
376
+ function Vn(e, t = Pe) {
375
377
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], i = [], s = [];
376
- let a = "neutral";
377
- const c = [], l = [];
378
- let d = null, m = !1, _ = !1, S = !1, o = !1, D = 0, w = 0, u = 0, g = 0, p = null, A = 1, V = "", y = ce, E = ce, x = !1;
379
- const b = /* @__PURE__ */ new Set(), W = () => {
380
- for (const h of l)
381
- h.playbackRate.value = A;
382
- }, q = () => b.forEach((h) => h()), ue = () => {
383
- p != null && (clearTimeout(p), p = null);
384
- }, Ee = () => {
385
- for (const h of l)
378
+ let c = "neutral";
379
+ const a = [], l = [];
380
+ let d = null, _ = !1, m = !1, S = !1, o = !1, F = 0, w = 0, u = 0, g = 0, y = null, v = 1, H = "", h = pe, E = pe, D = !1;
381
+ const L = /* @__PURE__ */ new Set(), z = () => {
382
+ for (const p of l)
383
+ p.playbackRate.value = v;
384
+ }, U = () => L.forEach((p) => p()), ae = () => {
385
+ y != null && (clearTimeout(y), y = null);
386
+ }, me = () => {
387
+ for (const p of l)
386
388
  try {
387
- h.stop();
389
+ p.stop();
388
390
  } catch {
389
391
  }
390
392
  l.length = 0;
393
+ }, N = () => {
394
+ D = !0, ae(), me(), a.length = 0, _ = !1, m = !1, S = !1, o = !1, r.length = 0, i.length = 0, s.length = 0, c = "neutral", u = 0, g = 0, w = 0, e("idle"), U();
391
395
  }, X = () => {
392
- x = !0, ue(), Ee(), c.length = 0, m = !1, _ = !1, S = !1, o = !1, r.length = 0, i.length = 0, s.length = 0, a = "neutral", u = 0, g = 0, w = 0, e("idle"), q();
393
- }, K = () => {
394
- !o || m || l.length > 0 || c.length > 0 || (_ = !1, ue(), e("done"), q());
395
- }, ke = () => {
396
- const h = Ye(r);
397
- if (h <= 0) {
398
- e("done"), q();
396
+ !o || _ || l.length > 0 || a.length > 0 || (m = !1, ae(), e("done"), U());
397
+ }, Re = () => {
398
+ const p = ut(r);
399
+ if (p <= 0) {
400
+ e("done"), U();
399
401
  return;
400
402
  }
401
- _ = !0, D = performance.now(), e("speaking"), q(), ue();
402
- const C = A > 0 ? h / A : h;
403
- p = setTimeout(() => {
404
- x || (_ = !1, p = null, e("done"), q());
405
- }, C);
406
- }, Ce = (h, C, N) => {
407
- h.length !== 0 && (N && (u = C), h.forEach((P) => {
408
- const L = String(P.word ?? "").trim();
409
- if (!L) return;
410
- const Q = Math.round((P.start ?? 0) * 1e3), $ = Math.round((P.duration ?? 0) * 1e3);
403
+ m = !0, F = performance.now(), e("speaking"), U(), ae();
404
+ const V = v > 0 ? p / v : p;
405
+ y = setTimeout(() => {
406
+ D || (m = !1, y = null, e("done"), U());
407
+ }, V);
408
+ }, He = (p, V, W) => {
409
+ p.length !== 0 && (W && (u = V), p.forEach((x) => {
410
+ const I = String(x.word ?? "").trim();
411
+ if (!I) return;
412
+ const Q = Math.round((x.start ?? 0) * 1e3), J = Math.round((x.duration ?? 0) * 1e3);
411
413
  i.push({
412
- word: L,
414
+ word: I,
413
415
  wtime: u + Q,
414
- wduration: $,
416
+ wduration: J,
415
417
  queueIndex: i.length
416
418
  });
417
419
  }));
418
- }, le = (h, C, N, P) => {
419
- h.length !== 0 && (N && (u = C), h.forEach((T) => {
420
- const L = String(T.symbol ?? "").trim();
421
- if (!L) return;
422
- const Q = Math.round((T.start ?? 0) * 1e3), $ = Math.max(
420
+ }, De = (p, V, W, x) => {
421
+ p.length !== 0 && (W && (u = V), p.forEach((M) => {
422
+ const I = String(M.symbol ?? "").trim();
423
+ if (!I) return;
424
+ const Q = Math.round((M.start ?? 0) * 1e3), J = Math.max(
423
425
  1,
424
- Math.round((T.duration ?? 0) * 1e3)
425
- ), O = u + Q;
426
- let M;
427
- if (Lt(P) === "oculus_direct")
428
- M = cn(L);
426
+ Math.round((M.duration ?? 0) * 1e3)
427
+ ), P = u + Q;
428
+ let O;
429
+ if (Yt(x) === "oculus_direct")
430
+ O = kn(I);
429
431
  else {
430
- const F = Tn(i, O), J = F ? fn(F, O) : 0;
431
- M = wn(
432
- L,
433
- F?.word ?? "",
434
- J
432
+ const q = Pn(i, P), ce = q ? In(q, P) : 0;
433
+ O = xn(
434
+ I,
435
+ q?.word ?? "",
436
+ ce
435
437
  );
436
438
  }
437
439
  r.push({
438
- viseme: M,
440
+ viseme: O,
439
441
  weight: 1,
440
- vtime: O,
441
- vduration: $
442
+ vtime: P,
443
+ vduration: J
442
444
  });
443
- }), q());
444
- }, se = (h, C, N, P, T) => {
445
- Ce(C, N, P), le(h, N, P, T);
446
- }, Se = async (h, C, N, P) => {
447
- if (x || !h?.trim()) {
448
- (C.length > 0 || N.length > 0) && !S && se(
449
- C,
450
- N,
445
+ }), U());
446
+ }, ue = (p, V, W, x, M) => {
447
+ He(V, W, x), De(p, W, x, M);
448
+ }, se = async (p, V, W, x) => {
449
+ if (D || !p?.trim()) {
450
+ (V.length > 0 || W.length > 0) && !S && ue(
451
+ V,
452
+ W,
451
453
  u,
452
- P,
454
+ x,
453
455
  E
454
456
  );
455
457
  return;
456
458
  }
457
- if (m) {
458
- c.push({
459
- audio: h,
460
- visemes: C,
461
- words: N,
462
- isNewSegment: P
459
+ if (_) {
460
+ a.push({
461
+ audio: p,
462
+ visemes: V,
463
+ words: W,
464
+ isNewSegment: x
463
465
  });
464
466
  return;
465
467
  }
466
- m = !0;
468
+ _ = !0;
467
469
  try {
468
- const T = window.AudioContext || window.webkitAudioContext, L = d ?? new T();
469
- L.state === "suspended" && await L.resume(), d = L;
470
- const Q = await kn(L, h);
470
+ const M = window.AudioContext || window.webkitAudioContext, I = d ?? new M();
471
+ I.state === "suspended" && await I.resume(), d = I;
472
+ const Q = await On(I, p);
471
473
  S = !0;
472
- const $ = L.currentTime;
473
- let O = g;
474
- const M = !_;
475
- O < $ && (O = $ + 0.1), g = O + Q.duration;
476
- const F = L.createBufferSource();
477
- if (F.buffer = Q, F.playbackRate.value = A, F.connect(L.destination), l.push(F), x) {
474
+ const J = I.currentTime;
475
+ let P = g;
476
+ const O = !m;
477
+ P < J && (P = J + 0.1), g = P + Q.duration;
478
+ const q = I.createBufferSource();
479
+ if (q.buffer = Q, q.playbackRate.value = v, q.connect(I.destination), l.push(q), D) {
478
480
  l.pop();
479
481
  return;
480
482
  }
481
- if (M) {
482
- _ = !0, e("speaking"), w = O, u = 0, r.length = 0, i.length = 0;
483
- const H = (O - $) * 1e3;
484
- D = performance.now() + H;
483
+ if (O) {
484
+ m = !0, e("speaking"), w = P, u = 0, r.length = 0, i.length = 0;
485
+ const $ = (P - J) * 1e3;
486
+ F = performance.now() + $;
485
487
  }
486
- F.onended = () => {
487
- const H = l.indexOf(F);
488
- H >= 0 && l.splice(H, 1), K(), q();
489
- }, F.start(O);
490
- const J = (O - w) * 1e3;
491
- se(
492
- C,
493
- N,
494
- J,
495
- P,
488
+ q.onended = () => {
489
+ const $ = l.indexOf(q);
490
+ $ >= 0 && l.splice($, 1), X(), U();
491
+ }, q.start(P);
492
+ const ce = (P - w) * 1e3;
493
+ ue(
494
+ V,
495
+ W,
496
+ ce,
497
+ x,
496
498
  E
497
499
  );
498
- } catch (T) {
499
- console.error("[avatarTtsLipsync] audio chunk failed:", T);
500
+ } catch (M) {
501
+ console.error("[avatarTtsLipsync] audio chunk failed:", M);
500
502
  } finally {
501
- m = !1;
502
- const T = c.shift();
503
- T ? await Se(
504
- T.audio,
505
- T.visemes,
506
- T.words,
507
- T.isNewSegment
508
- ) : K();
503
+ _ = !1;
504
+ const M = a.shift();
505
+ M ? await se(
506
+ M.audio,
507
+ M.visemes,
508
+ M.words,
509
+ M.isNewSegment
510
+ ) : X();
509
511
  }
510
- }, Z = () => {
512
+ }, xe = () => {
511
513
  if (o = !0, !S && r.length > 0) {
512
- ke();
514
+ Re();
513
515
  return;
514
516
  }
515
- K();
517
+ X();
516
518
  };
517
519
  return {
518
- setDeveloperToken: (h) => {
519
- V = h;
520
+ setDeveloperToken: (p) => {
521
+ H = p;
520
522
  },
521
- setTtsEngineId: (h) => {
522
- y = h;
523
+ setTtsEngineId: (p) => {
524
+ h = p;
523
525
  },
524
- getTtsEngineId: () => y,
525
- speak: async (h, C) => {
526
- X(), x = !1, e("loading");
527
- const N = V.trim();
528
- if (!N)
526
+ getTtsEngineId: () => h,
527
+ speak: async (p, V) => {
528
+ N(), D = !1, e("loading");
529
+ const W = H.trim();
530
+ if (!W)
529
531
  throw new Error("Developer token required for avatar_ttsWithPoses");
530
- const P = C?.ttsEngineId ?? y ?? ce;
531
- E = P;
532
- const T = C?.voiceId ?? ht, L = C?.speakingRate ?? _t, Q = Math.max(
533
- vn,
534
- Math.min(In, L)
535
- ), $ = {
536
- user_query: h,
537
- ttsEngineId: P,
532
+ const x = V?.ttsEngineId ?? h ?? pe;
533
+ E = x;
534
+ const M = V?.voiceId ?? It, I = V?.speakingRate ?? At, Q = Math.max(
535
+ Un,
536
+ Math.min(Bn, I)
537
+ ), J = {
538
+ user_query: p,
539
+ ttsEngineId: x,
538
540
  speakingRate: Q
539
541
  };
540
- Ot.has(P) && ($.voice_id = T);
542
+ Jt.has(x) && (J.voice_id = M);
541
543
  try {
542
- const O = await fetch(n, {
544
+ const P = await fetch(n, {
543
545
  method: "POST",
544
546
  headers: {
545
547
  "Content-Type": "application/json",
546
- Authorization: `Bearer ${N}`
548
+ Authorization: `Bearer ${W}`
547
549
  },
548
- body: JSON.stringify($)
550
+ body: JSON.stringify(J)
549
551
  });
550
- if (!O.ok)
551
- throw new Error(`avatar_ttsWithPoses failed (${O.status})`);
552
- const M = O.body;
553
- if (!M) throw new Error("No response body");
554
- const F = M.getReader(), J = new TextDecoder();
555
- let H = "";
556
- const de = async (he) => {
557
- const f = sn(he);
558
- if (f) {
559
- if (f.event === "audio") {
560
- const k = f.data.chunk, v = f.data.visemes ?? [], I = f.data.words ?? [], R = f.data.is_new_segment ?? !1;
561
- if (k)
562
- await Se(k, v, I, R);
563
- else if (v.length > 0 || I.length > 0) {
564
- const G = R && r.length > 0 ? Ye(r) : u;
565
- se(v, I, G, R, P);
552
+ if (!P.ok)
553
+ throw new Error(`avatar_ttsWithPoses failed (${P.status})`);
554
+ const O = P.body;
555
+ if (!O) throw new Error("No response body");
556
+ const q = O.getReader(), ce = new TextDecoder();
557
+ let $ = "";
558
+ const Me = async (B) => {
559
+ const b = pn(B);
560
+ if (b) {
561
+ if (b.event === "audio") {
562
+ const K = b.data.chunk, te = b.data.visemes ?? [], Z = b.data.words ?? [], j = b.data.is_new_segment ?? !1;
563
+ if (K)
564
+ await se(K, te, Z, j);
565
+ else if (te.length > 0 || Z.length > 0) {
566
+ const _e = j && r.length > 0 ? ut(r) : u;
567
+ ue(te, Z, _e, j, x);
566
568
  }
567
- } else if (f.event === "metadata") {
568
- const k = f.data.mood;
569
- typeof k == "string" && k.trim() && (a = k.trim());
570
- const v = f.data.sentence_emotions;
571
- if (Array.isArray(v)) {
569
+ } else if (b.event === "metadata") {
570
+ const K = b.data.mood;
571
+ typeof K == "string" && K.trim() && (c = K.trim());
572
+ const te = b.data.sentence_emotions;
573
+ if (Array.isArray(te)) {
572
574
  s.length = 0;
573
- for (const I of v) {
574
- if (!I || typeof I != "object") continue;
575
- const R = I;
575
+ for (const Z of te) {
576
+ if (!Z || typeof Z != "object") continue;
577
+ const j = Z;
576
578
  s.push({
577
- sentence_index: Number(R.sentence_index ?? 0),
578
- text: String(R.text ?? ""),
579
- sentiment: typeof R.sentiment == "string" ? R.sentiment : void 0,
580
- emotion: String(R.emotion ?? a),
581
- start_word: Number(R.start_word ?? 0),
582
- end_word: Number(R.end_word ?? 0)
579
+ sentence_index: Number(j.sentence_index ?? 0),
580
+ text: String(j.text ?? ""),
581
+ sentiment: typeof j.sentiment == "string" ? j.sentiment : void 0,
582
+ emotion: String(j.emotion ?? c),
583
+ start_word: Number(j.start_word ?? 0),
584
+ end_word: Number(j.end_word ?? 0)
583
585
  });
584
586
  }
585
587
  }
586
- q();
587
- } else if (f.event === "error")
588
+ U();
589
+ } else if (b.event === "error")
588
590
  throw new Error(
589
- String(f.data.message ?? "avatar_ttsWithPoses stream error")
591
+ String(b.data.message ?? "avatar_ttsWithPoses stream error")
590
592
  );
591
593
  }
592
594
  };
593
595
  for (; ; ) {
594
- const { done: he, value: f } = await F.read();
595
- f && (H += J.decode(f, { stream: !0 }));
596
- const k = H.split(`
596
+ const { done: B, value: b } = await q.read();
597
+ b && ($ += ce.decode(b, { stream: !0 }));
598
+ const K = $.split(`
597
599
 
598
600
  `);
599
- H = k.pop() ?? "";
600
- for (const v of k) await de(v);
601
- if (he) {
602
- H.trim() && await de(H.trim()), x || Z();
601
+ $ = K.pop() ?? "";
602
+ for (const te of K) await Me(te);
603
+ if (B) {
604
+ $.trim() && await Me($.trim()), D || xe();
603
605
  break;
604
606
  }
605
607
  }
606
- } catch (O) {
607
- throw console.error("[avatarTtsLipsync]", O), X(), e("error"), O;
608
+ } catch (P) {
609
+ throw console.error("[avatarTtsLipsync]", P), N(), e("error"), P;
608
610
  }
609
611
  },
610
- stop: X,
612
+ stop: N,
611
613
  getVisemeQueue: () => r,
612
614
  getWordQueue: () => i,
613
615
  getSentenceEmotions: () => s,
614
- getStreamMood: () => a,
615
- getPlaybackElapsedMs: () => _ ? S && d && w > 0 ? Math.max(
616
+ getStreamMood: () => c,
617
+ getPlaybackElapsedMs: () => m ? S && d && w > 0 ? Math.max(
616
618
  0,
617
619
  (d.currentTime - w) * 1e3
618
- ) : Math.max(0, (performance.now() - D) * A) : 0,
619
- isSpeaking: () => _,
620
- setPlaybackSpeed: (h) => {
621
- A = Math.max(0.1, Math.min(1, h)), W();
620
+ ) : Math.max(0, (performance.now() - F) * v) : 0,
621
+ isSpeaking: () => m,
622
+ setPlaybackSpeed: (p) => {
623
+ v = Math.max(0.1, Math.min(1, p)), z();
622
624
  },
623
- getPlaybackSpeed: () => A,
624
- subscribe: (h) => (b.add(h), () => b.delete(h))
625
+ getPlaybackSpeed: () => v,
626
+ subscribe: (p) => (L.add(p), () => L.delete(p))
625
627
  };
626
628
  }
627
- function bn(e, t, n) {
629
+ function $n(e, t, n) {
628
630
  return {
629
631
  width: e.crop?.source_width ?? t,
630
632
  height: e.crop?.source_height ?? n
631
633
  };
632
634
  }
633
- function Dn(e, t) {
635
+ function Hn(e, t) {
634
636
  const n = e.crop;
635
637
  return {
636
638
  x: t?.source_x ?? n?.x ?? 0,
@@ -639,21 +641,21 @@ function Dn(e, t) {
639
641
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
640
642
  };
641
643
  }
642
- function xn(e) {
644
+ function Wn(e) {
643
645
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
644
646
  }
645
- async function mt(e, t) {
647
+ async function Ve(e, t) {
646
648
  const n = await fetch(e);
647
649
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
648
650
  const r = await n.arrayBuffer();
649
- return zt(r, t);
651
+ return ln(r, t);
650
652
  }
651
- async function Cn(e, t) {
653
+ async function qn(e, t) {
652
654
  if (!t) throw new Error("Missing asset key for encrypted JSON");
653
- const n = await mt(e, t), r = new TextDecoder().decode(n);
655
+ const n = await Ve(e, t), r = new TextDecoder().decode(n);
654
656
  return JSON.parse(r);
655
657
  }
656
- async function Mn(e) {
658
+ async function Kn(e) {
657
659
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
658
660
  return new Promise((r, i) => {
659
661
  const s = new Image();
@@ -664,10 +666,32 @@ async function Mn(e) {
664
666
  }, s.src = n;
665
667
  });
666
668
  }
667
- function wt(e, t) {
669
+ async function jn(e) {
670
+ const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
671
+ return new Promise((r, i) => {
672
+ const s = new Image();
673
+ s.decoding = "async", s.onload = () => {
674
+ URL.revokeObjectURL(n), r(s);
675
+ }, s.onerror = () => {
676
+ URL.revokeObjectURL(n), i(new Error("Failed to decode decrypted PNG"));
677
+ }, s.src = n;
678
+ });
679
+ }
680
+ function Gn(e) {
681
+ const t = new Blob([e], { type: "video/mp4" });
682
+ return URL.createObjectURL(t);
683
+ }
684
+ async function zn(e) {
685
+ const t = _n();
686
+ if (!Be()) return t;
687
+ if (!e) throw new Error("Missing asset key for encrypted idle video");
688
+ const n = await Ve(t, e);
689
+ return Gn(n);
690
+ }
691
+ function bt(e, t) {
668
692
  return `${e}/${t}_minus_sil.png`;
669
693
  }
670
- const Ke = 15, Rr = [
694
+ const et = 15, Gr = [
671
695
  "aa",
672
696
  "E",
673
697
  "I",
@@ -682,13 +706,13 @@ const Ke = 15, Rr = [
682
706
  "RR",
683
707
  "kk",
684
708
  "nn"
685
- ], Ne = [
709
+ ], ze = [
686
710
  "t01_0.17",
687
711
  "t02_0.33",
688
712
  "t03_0.50",
689
713
  "t04_0.67",
690
714
  "t05_0.83"
691
- ], Fn = Ne.length, Xe = /* @__PURE__ */ new Set([
715
+ ], Qn = ze.length, lt = /* @__PURE__ */ new Set([
692
716
  "aa__kk",
693
717
  "aa__nn",
694
718
  "aa__sil",
@@ -795,59 +819,59 @@ const Ke = 15, Rr = [
795
819
  "U__nn",
796
820
  "U__sil"
797
821
  ]);
798
- function Ze(e, t) {
822
+ function ft(e, t) {
799
823
  return `${e}__${t}`;
800
824
  }
801
- function et(e, t) {
825
+ function dt(e, t) {
802
826
  return `pairs/${e}/${t}_minus_sil.png`;
803
827
  }
804
- function $e(e) {
828
+ function Qe(e) {
805
829
  return `${e}_minus_sil.png`;
806
830
  }
807
- function Pn(e, t) {
831
+ function Rt(e, t) {
808
832
  if (e === t) return [];
809
- const n = [], r = Ze(e, t);
810
- if (Xe.has(r)) {
811
- for (const s of Ne)
812
- n.push(et(r, s));
833
+ const n = [], r = ft(e, t);
834
+ if (lt.has(r)) {
835
+ for (const s of ze)
836
+ n.push(dt(r, s));
813
837
  return n;
814
838
  }
815
- const i = Ze(t, e);
816
- if (Xe.has(i)) {
817
- for (let s = Fn - 1; s >= 0; s--)
818
- n.push(et(i, Ne[s]));
839
+ const i = ft(t, e);
840
+ if (lt.has(i)) {
841
+ for (let s = Qn - 1; s >= 0; s--)
842
+ n.push(dt(i, ze[s]));
819
843
  return n;
820
844
  }
821
845
  return [];
822
846
  }
823
- function On(e) {
847
+ function Jn(e) {
824
848
  return e < 16 ? [] : e < 35 ? [2] : e < 51 ? [0, 4] : e < 67 ? [0, 2, 4] : e < 83 ? [0, 1, 2, 3] : [0, 1, 2, 3, 4];
825
849
  }
826
- function Ln(e, t) {
827
- return On(t).map((r) => e[r]).filter((r) => r != null);
850
+ function Yn(e, t) {
851
+ return Jn(t).map((r) => e[r]).filter((r) => r != null);
828
852
  }
829
- function Un(e, t, n, r) {
853
+ function Xn(e, t, n, r) {
830
854
  if (r <= 0) return 0;
831
- const s = Math.max(1, n - t) / r, a = e - t, c = Math.floor(a / s);
832
- return Math.min(r - 1, Math.max(0, c));
855
+ const s = Math.max(1, n - t) / r, c = e - t, a = Math.floor(c / s);
856
+ return Math.min(r - 1, Math.max(0, a));
833
857
  }
834
- function Bn(e, t, n) {
858
+ function Zn(e, t, n) {
835
859
  if (!n) return `${e}/${t}`;
836
860
  const r = t.split("/").pop() ?? t, i = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
837
861
  return `${e}/${i}.bin`;
838
862
  }
839
- const Nn = [0.32, 0.24, 0.16, 0.08, 0], xe = Nn.map(
863
+ const er = [0.32, 0.24, 0.16, 0.08, 0], $e = er.map(
840
864
  (e) => `eyes_${e.toFixed(2)}`
841
- ), $n = [
865
+ ), tr = [
842
866
  "eyes_0.32",
843
867
  "eyes_0.16",
844
868
  "eyes_0.00"
845
- ], Vn = [
869
+ ], nr = [
846
870
  "eyes_0.32",
847
871
  "eyes_0.16",
848
872
  "eyes_0.08",
849
873
  "eyes_0.00"
850
- ], Hn = {
874
+ ], rr = {
851
875
  fear: "fear",
852
876
  afraid: "fear",
853
877
  anxiety: "fear",
@@ -870,174 +894,174 @@ const Nn = [0.32, 0.24, 0.16, 0.08, 0], xe = Nn.map(
870
894
  disgust: "disgust",
871
895
  disgusted: "disgust"
872
896
  };
873
- function ae(e, t = "neutral") {
897
+ function ye(e, t = "neutral") {
874
898
  const n = String(e ?? "").trim().toLowerCase();
875
- return n ? Hn[n] ?? t : t;
899
+ return n ? rr[n] ?? t : t;
876
900
  }
877
- function z(e) {
878
- return e === "neutral" ? null : wt(e, "eyes_standard");
901
+ function ee(e) {
902
+ return e === "neutral" ? null : bt(e, "eyes_standard");
879
903
  }
880
- function Ve(e, t) {
881
- return !t || t === "eyes_standard" ? z(e) : e === "neutral" && t === "eyes_standard" ? null : wt(e, t);
904
+ function Je(e, t) {
905
+ return !t || t === "eyes_standard" ? ee(e) : e === "neutral" && t === "eyes_standard" ? null : bt(e, t);
882
906
  }
883
- function Wn(e) {
907
+ function ir(e) {
884
908
  if (!e) return "open";
885
909
  const t = e.match(/\/(eyes_[^/]+)_minus_sil\.png$/);
886
910
  if (!t?.[1]) return "open";
887
911
  const n = t[1];
888
- return xe.includes(n) ? n : "open";
912
+ return $e.includes(n) ? n : "open";
889
913
  }
890
- function qn(e) {
891
- return e === "open" ? -1 : xe.indexOf(e);
914
+ function sr(e) {
915
+ return e === "open" ? -1 : $e.indexOf(e);
892
916
  }
893
- function Kn(e, t) {
917
+ function or(e, t) {
894
918
  const n = [];
895
919
  for (const r of t)
896
- n.push(Ve(e, r));
920
+ n.push(Je(e, r));
897
921
  for (let r = t.length - 2; r >= 0; r--)
898
- n.push(Ve(e, t[r]));
899
- return n.push(z(e)), n;
922
+ n.push(Je(e, t[r]));
923
+ return n.push(ee(e)), n;
900
924
  }
901
- function Gn(e, t) {
902
- if (t === "open") return [z(e)];
903
- const n = qn(t);
904
- if (n < 0) return [z(e)];
925
+ function ar(e, t) {
926
+ if (t === "open") return [ee(e)];
927
+ const n = sr(t);
928
+ if (n < 0) return [ee(e)];
905
929
  const r = [];
906
930
  for (let i = n; i >= 0; i--)
907
- r.push(Ve(e, xe[i]));
908
- return r.push(z(e)), r;
931
+ r.push(Je(e, $e[i]));
932
+ return r.push(ee(e)), r;
909
933
  }
910
- const jn = [
934
+ const cr = [
911
935
  "t01_0.20",
912
936
  "t02_0.40",
913
937
  "t03_0.60",
914
938
  "t04_0.80"
915
939
  ];
916
- function zn(e, t) {
940
+ function ur(e, t) {
917
941
  return `${e}__${t}`;
918
942
  }
919
- function Qn(e, t, n) {
920
- return `pairs/${zn(e, t)}/${n}_minus_sil.png`;
943
+ function lr(e, t, n) {
944
+ return `pairs/${ur(e, t)}/${n}_minus_sil.png`;
921
945
  }
922
- function Jn(e, t) {
923
- return jn.map(
924
- (n) => Qn(e, t, n)
946
+ function fr(e, t) {
947
+ return cr.map(
948
+ (n) => lr(e, t, n)
925
949
  );
926
950
  }
927
- function we(e, t) {
951
+ function ve(e, t) {
928
952
  return e + Math.random() * (t - e);
929
953
  }
930
- function Ie() {
931
- return we(14, 32);
954
+ function Le() {
955
+ return ve(14, 32);
932
956
  }
933
- function Yn(e = {}) {
957
+ function dr(e = {}) {
934
958
  const {
935
959
  initialDelayMs: t = 800 + Math.random() * 1200,
936
960
  intervalMinMs: n = 2200,
937
961
  intervalMaxMs: r = 5800,
938
962
  doubleBlinkChance: i = 0.18,
939
963
  doubleBlinkGapMinMs: s = 120,
940
- doubleBlinkGapMaxMs: a = 220,
941
- fullBlinkChance: c = 0.75,
964
+ doubleBlinkGapMaxMs: c = 220,
965
+ fullBlinkChance: a = 0.75,
942
966
  postEmotionChangeDelayMs: l = 380,
943
967
  minDwellMs: d = 550
944
968
  } = e;
945
- let m = "neutral", _ = "neutral", S = 0, o = {
969
+ let _ = "neutral", m = "neutral", S = 0, o = {
946
970
  kind: "idle",
947
971
  nextBlinkAt: performance.now() + t
948
- }, D = null, w = "__eyes_open__|neutral";
949
- function u(y, E) {
950
- D = y, w = `${y ?? "__eyes_open__"}|${E}`;
972
+ }, F = null, w = "__eyes_open__|neutral";
973
+ function u(h, E) {
974
+ F = h, w = `${h ?? "__eyes_open__"}|${E}`;
951
975
  }
952
- function g(y, E) {
976
+ function g(h, E) {
953
977
  o = {
954
978
  kind: "idle",
955
- nextBlinkAt: y + we(n, r)
956
- }, _ = E, u(z(E), E);
979
+ nextBlinkAt: h + ve(n, r)
980
+ }, m = E, u(ee(E), E);
957
981
  }
958
- function p(y, E, x) {
959
- const b = x ? $n : Math.random() < c ? xe : Vn;
982
+ function y(h, E, D) {
983
+ const L = D ? tr : Math.random() < a ? $e : nr;
960
984
  o = {
961
985
  kind: "playing",
962
- paths: Kn(E, b),
986
+ paths: or(E, L),
963
987
  index: 0,
964
- holdUntil: y + Ie(),
988
+ holdUntil: h + Le(),
965
989
  after: "idle",
966
990
  blinkEmotion: E
967
- }, _ = E, u(o.paths[0] ?? null, E);
991
+ }, m = E, u(o.paths[0] ?? null, E);
968
992
  }
969
- function A(y, E, x) {
970
- const b = Wn(D), W = [];
971
- if (b !== "open") {
972
- const q = Gn(E, b);
973
- W.push(...q.slice(0, -1));
993
+ function v(h, E, D) {
994
+ const L = ir(F), z = [];
995
+ if (L !== "open") {
996
+ const U = ar(E, L);
997
+ z.push(...U.slice(0, -1));
974
998
  }
975
- W.push(...Jn(E, x)), W.push(z(x)), o = {
999
+ z.push(...fr(E, D)), z.push(ee(D)), o = {
976
1000
  kind: "emotionBlend",
977
- paths: W,
1001
+ paths: z,
978
1002
  index: 0,
979
- holdUntil: y + Ie(),
980
- thenEmotion: x
981
- }, u(W[0] ?? null, E);
1003
+ holdUntil: h + Le(),
1004
+ thenEmotion: D
1005
+ }, u(z[0] ?? null, E);
982
1006
  }
983
- function V(y) {
1007
+ function H(h) {
984
1008
  if (o.kind === "emotionBlend") {
985
- for (; y >= o.holdUntil && o.index < o.paths.length - 1; )
986
- o.index += 1, o.holdUntil = y + Ie();
1009
+ for (; h >= o.holdUntil && o.index < o.paths.length - 1; )
1010
+ o.index += 1, o.holdUntil = h + Le();
987
1011
  const E = o.paths[o.index] ?? null;
988
- u(E, o.thenEmotion), y >= o.holdUntil && o.index >= o.paths.length - 1 && (m = o.thenEmotion, _ = o.thenEmotion, u(z(o.thenEmotion), o.thenEmotion), o = {
1012
+ u(E, o.thenEmotion), h >= o.holdUntil && o.index >= o.paths.length - 1 && (_ = o.thenEmotion, m = o.thenEmotion, u(ee(o.thenEmotion), o.thenEmotion), o = {
989
1013
  kind: "idle",
990
- nextBlinkAt: y + l
1014
+ nextBlinkAt: h + l
991
1015
  });
992
1016
  return;
993
1017
  }
994
1018
  if (o.kind === "idle") {
995
- u(z(_), _), y >= o.nextBlinkAt && p(y, _, !1);
1019
+ u(ee(m), m), h >= o.nextBlinkAt && y(h, m, !1);
996
1020
  return;
997
1021
  }
998
1022
  if (o.kind === "doublePause") {
999
- u(z(o.blinkEmotion), o.blinkEmotion), y >= o.resumeAt && p(y, o.blinkEmotion, !0);
1023
+ u(ee(o.blinkEmotion), o.blinkEmotion), h >= o.resumeAt && y(h, o.blinkEmotion, !0);
1000
1024
  return;
1001
1025
  }
1002
1026
  if (o.kind === "playing") {
1003
- for (; y >= o.holdUntil && o.index < o.paths.length - 1; )
1004
- o.index += 1, o.holdUntil = y + Ie();
1005
- if (u(o.paths[o.index] ?? null, o.blinkEmotion), y >= o.holdUntil && o.index >= o.paths.length - 1) {
1027
+ for (; h >= o.holdUntil && o.index < o.paths.length - 1; )
1028
+ o.index += 1, o.holdUntil = h + Le();
1029
+ if (u(o.paths[o.index] ?? null, o.blinkEmotion), h >= o.holdUntil && o.index >= o.paths.length - 1) {
1006
1030
  if (o.after === "resumeIdle") {
1007
- g(y + l, m);
1031
+ g(h + l, _);
1008
1032
  return;
1009
1033
  }
1010
1034
  if (o.after === "doublePause") {
1011
1035
  o = {
1012
1036
  kind: "doublePause",
1013
- resumeAt: y + we(s, a),
1037
+ resumeAt: h + ve(s, c),
1014
1038
  blinkEmotion: o.blinkEmotion
1015
- }, u(z(o.blinkEmotion), o.blinkEmotion);
1039
+ }, u(ee(o.blinkEmotion), o.blinkEmotion);
1016
1040
  return;
1017
1041
  }
1018
1042
  if (o.after === "idle" && Math.random() < i) {
1019
1043
  o = {
1020
1044
  kind: "doublePause",
1021
- resumeAt: y + we(s, a),
1045
+ resumeAt: h + ve(s, c),
1022
1046
  blinkEmotion: o.blinkEmotion
1023
- }, u(z(o.blinkEmotion), o.blinkEmotion);
1047
+ }, u(ee(o.blinkEmotion), o.blinkEmotion);
1024
1048
  return;
1025
1049
  }
1026
- g(y, o.blinkEmotion);
1050
+ g(h, o.blinkEmotion);
1027
1051
  }
1028
1052
  }
1029
1053
  }
1030
1054
  return {
1031
- advance: V,
1032
- setTargetEmotion(y) {
1033
- const E = ae(y, m);
1034
- if (E === m && o.kind !== "emotionBlend") return;
1035
- const x = performance.now();
1036
- if (d > 0 && E !== m && o.kind !== "emotionBlend" && !(m === "neutral" && E !== "neutral") && x - S < d)
1055
+ advance: H,
1056
+ setTargetEmotion(h) {
1057
+ const E = ye(h, _);
1058
+ if (E === _ && o.kind !== "emotionBlend") return;
1059
+ const D = performance.now();
1060
+ if (d > 0 && E !== _ && o.kind !== "emotionBlend" && !(_ === "neutral" && E !== "neutral") && D - S < d)
1037
1061
  return;
1038
- const b = m;
1039
- if (m = E, S = x, o.kind === "playing") {
1040
- A(x, _, E);
1062
+ const L = _;
1063
+ if (_ = E, S = D, o.kind === "playing") {
1064
+ v(D, m, E);
1041
1065
  return;
1042
1066
  }
1043
1067
  if (o.kind === "emotionBlend") {
@@ -1047,385 +1071,408 @@ function Yn(e = {}) {
1047
1071
  };
1048
1072
  return;
1049
1073
  }
1050
- A(x, b, E);
1074
+ v(D, L, E);
1051
1075
  },
1052
- getTargetEmotion: () => m,
1053
- getExpressionPath: () => D,
1076
+ getTargetEmotion: () => _,
1077
+ getExpressionPath: () => F,
1054
1078
  getDrawKey: () => w,
1055
1079
  reset() {
1056
- m = "neutral", _ = "neutral", S = 0, g(
1057
- performance.now() + we(n, r),
1080
+ _ = "neutral", m = "neutral", S = 0, g(
1081
+ performance.now() + ve(n, r),
1058
1082
  "neutral"
1059
1083
  );
1060
1084
  }
1061
1085
  };
1062
1086
  }
1063
- function Xn(e) {
1064
- const t = document.createElement("video");
1065
- t.muted = !0, t.playsInline = !0, t.preload = "auto", t.setAttribute("playsinline", ""), t.loop = !0;
1066
- let n = !1;
1087
+ function hr() {
1088
+ const e = document.createElement("video");
1089
+ e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1090
+ let t = !1, n = null, r = "";
1091
+ const i = () => {
1092
+ n && (URL.revokeObjectURL(n), n = null);
1093
+ };
1067
1094
  return {
1068
- async load() {
1069
- n || await new Promise((r, i) => {
1070
- const s = () => {
1071
- const a = t.duration;
1072
- if (!Number.isFinite(a) || a <= 0) {
1073
- i(new Error(`Idle video has invalid duration: ${e}`));
1095
+ async load(s) {
1096
+ t && r === s || (i(), t = !1, r = s, s.startsWith("blob:") && (n = s), await new Promise((c, a) => {
1097
+ const l = () => {
1098
+ const d = e.duration;
1099
+ if (!Number.isFinite(d) || d <= 0) {
1100
+ a(new Error(`Idle video has invalid duration: ${s}`));
1074
1101
  return;
1075
1102
  }
1076
- n = !0, t.currentTime = 0, r();
1103
+ t = !0, e.currentTime = 0, c();
1077
1104
  };
1078
- t.addEventListener("loadeddata", s, { once: !0 }), t.addEventListener(
1105
+ e.addEventListener("loadeddata", l, { once: !0 }), e.addEventListener(
1079
1106
  "error",
1080
- () => i(new Error(`Failed to load idle video: ${e}`)),
1107
+ () => a(new Error(`Failed to load idle video: ${s}`)),
1081
1108
  { once: !0 }
1082
- ), t.src = e, t.load();
1083
- });
1109
+ ), e.src = s, e.load();
1110
+ }));
1084
1111
  },
1085
1112
  isReady() {
1086
- return n;
1113
+ return t;
1087
1114
  },
1088
1115
  getVideo() {
1089
- return t;
1116
+ return e;
1090
1117
  },
1091
- setActive(r) {
1092
- n && (r ? t.paused && t.play().catch(() => {
1093
- }) : t.paused || t.pause());
1118
+ setActive(s) {
1119
+ t && (s ? e.paused && e.play().catch(() => {
1120
+ }) : e.paused || e.pause());
1094
1121
  },
1095
1122
  restart() {
1096
- n && (t.currentTime = 0);
1123
+ t && (e.currentTime = 0);
1124
+ },
1125
+ dispose() {
1126
+ e.pause(), e.removeAttribute("src"), e.load(), i(), t = !1, r = "";
1097
1127
  }
1098
1128
  };
1099
1129
  }
1100
- const Zn = 50, gt = 400;
1101
- function er(e, t, n) {
1130
+ const mr = 50, Dt = 400;
1131
+ function _r(e, t, n) {
1102
1132
  return e.filter((r) => {
1103
1133
  const i = r.queueIndex ?? -1;
1104
1134
  return i >= t && i <= n;
1105
1135
  });
1106
1136
  }
1107
- function tr(e, t) {
1137
+ function wr(e, t) {
1108
1138
  const n = [];
1109
1139
  for (const r of e) {
1110
- const i = er(
1140
+ const i = _r(
1111
1141
  t,
1112
1142
  r.start_word,
1113
1143
  r.end_word
1114
1144
  );
1115
1145
  if (i.length === 0) continue;
1116
- const s = i[0], a = i[i.length - 1];
1146
+ const s = i[0], c = i[i.length - 1];
1117
1147
  n.push({
1118
1148
  sentence: r,
1119
- startMs: Math.max(0, s.wtime - Zn),
1120
- endMs: a.wtime + a.wduration + gt
1149
+ startMs: Math.max(0, s.wtime - mr),
1150
+ endMs: c.wtime + c.wduration + Dt
1121
1151
  });
1122
1152
  }
1123
1153
  return n.sort((r, i) => r.startMs - i.startMs);
1124
1154
  }
1125
- function nr(e, t, n, r = "neutral") {
1126
- const i = ae(r);
1155
+ function gr(e, t, n, r = "neutral") {
1156
+ const i = ye(r);
1127
1157
  if (t.length === 0) return i;
1128
1158
  if (n.length === 0 || e < n[0].wtime)
1129
- return ae(t[0]?.emotion, i);
1130
- const s = tr(t, n);
1131
- let a = null;
1159
+ return ye(t[0]?.emotion, i);
1160
+ const s = wr(t, n);
1161
+ let c = null;
1132
1162
  for (const d of s)
1133
- e >= d.startMs && e <= d.endMs && (a = d);
1134
- if (a)
1135
- return ae(a.sentence.emotion, i);
1136
- const c = n[n.length - 1], l = c.wtime + c.wduration;
1137
- return e > l + gt ? ae(
1163
+ e >= d.startMs && e <= d.endMs && (c = d);
1164
+ if (c)
1165
+ return ye(c.sentence.emotion, i);
1166
+ const a = n[n.length - 1], l = a.wtime + a.wduration;
1167
+ return e > l + Dt ? ye(
1138
1168
  t[t.length - 1]?.emotion,
1139
1169
  i
1140
1170
  ) : i;
1141
1171
  }
1142
- function yt(e, t, n, r, i = Ke) {
1143
- const s = new OffscreenCanvas(n, r), a = s.getContext("2d", { willReadFrequently: !0 });
1144
- a.drawImage(e, 0, 0, n, r);
1145
- const c = a.getImageData(0, 0, n, r), l = a.createImageData(n, r);
1146
- l.data.set(c.data);
1147
- const m = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
1148
- for (const _ of t) {
1149
- m.clearRect(0, 0, n, r), m.drawImage(_, 0, 0, n, r);
1150
- const S = m.getImageData(0, 0, n, r);
1172
+ function xt(e, t, n, r, i = et) {
1173
+ const s = new OffscreenCanvas(n, r), c = s.getContext("2d", { willReadFrequently: !0 });
1174
+ c.drawImage(e, 0, 0, n, r);
1175
+ const a = c.getImageData(0, 0, n, r), l = c.createImageData(n, r);
1176
+ l.data.set(a.data);
1177
+ const _ = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
1178
+ for (const m of t) {
1179
+ _.clearRect(0, 0, n, r), _.drawImage(m, 0, 0, n, r);
1180
+ const S = _.getImageData(0, 0, n, r);
1151
1181
  for (let o = 0; o < l.data.length; o += 4) {
1152
- const D = S.data[o], w = S.data[o + 1], u = S.data[o + 2];
1153
- Math.max(D, w, u) > i && (l.data[o] = D, l.data[o + 1] = w, l.data[o + 2] = u, l.data[o + 3] = 255);
1182
+ const F = S.data[o], w = S.data[o + 1], u = S.data[o + 2];
1183
+ Math.max(F, w, u) > i && (l.data[o] = F, l.data[o + 1] = w, l.data[o + 2] = u, l.data[o + 3] = 255);
1154
1184
  }
1155
1185
  }
1156
- return a.putImageData(l, 0, 0), s;
1186
+ return c.putImageData(l, 0, 0), s;
1157
1187
  }
1158
- let re = null, ge = null;
1159
- const be = /* @__PURE__ */ new Map();
1160
- function rr() {
1161
- re = null, ge = null, be.clear();
1188
+ let de = null, Ie = null;
1189
+ const Ue = /* @__PURE__ */ new Map();
1190
+ function yr() {
1191
+ de = null, Ie = null, Ue.clear();
1162
1192
  }
1163
- Xt(rr);
1164
- function ir(e) {
1165
- return e ?? ge ?? void 0;
1193
+ mn(yr);
1194
+ function pr(e) {
1195
+ return e ?? Ie ?? void 0;
1166
1196
  }
1167
- function Ge(e) {
1197
+ function tt(e) {
1168
1198
  return new Promise((t, n) => {
1169
1199
  const r = new Image();
1170
1200
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
1171
1201
  });
1172
1202
  }
1173
- async function tt(e, t, n, r) {
1174
- const i = n ? await Cn(e, r) : await fetch(e).then((d) => {
1203
+ async function Er(e) {
1204
+ return Be() ? jn(
1205
+ await Ve(at(), e ?? "")
1206
+ ) : tt(at());
1207
+ }
1208
+ async function ht(e, t, n, r) {
1209
+ const i = n ? await qn(e, r) : await fetch(e).then((d) => {
1175
1210
  if (!d.ok) throw new Error(`Failed to load ${e}`);
1176
1211
  return d.json();
1177
1212
  }), s = i.sheets?.[0];
1178
1213
  if (!s?.path) throw new Error(`${e} has no sheets[0].path`);
1179
- const a = n ? await Mn(
1180
- await mt(
1181
- Bn(t, s.path, n),
1214
+ const c = n ? await Kn(
1215
+ await Ve(
1216
+ Zn(t, s.path, n),
1182
1217
  r ?? ""
1183
1218
  )
1184
- ) : await Ge(`${t}/${s.path}`), c = /* @__PURE__ */ new Map();
1219
+ ) : await tt(`${t}/${s.path}`), a = /* @__PURE__ */ new Map();
1185
1220
  for (const d of i.cells ?? [])
1186
- d.path && c.set(d.path, d);
1221
+ d.path && a.set(d.path, d);
1187
1222
  const l = /* @__PURE__ */ new Map();
1188
1223
  for (const d of i.sheets ?? [])
1189
1224
  l.set(d.index, d);
1190
- return { atlas: a, atlasMeta: i, cellByPath: c, sheetByIndex: l, diffBase: t };
1225
+ return { atlas: c, atlasMeta: i, cellByPath: a, sheetByIndex: l, diffBase: t };
1191
1226
  }
1192
- async function He(e) {
1193
- const t = ir(e), n = dt();
1227
+ async function Ye(e) {
1228
+ const t = pr(e), n = Be();
1194
1229
  if (n && !t)
1195
1230
  throw new Error("Encrypted assets enabled but no key provided");
1196
- if (re && (!n || ge === (t ?? null))) {
1197
- const s = await re;
1198
- return ye(s);
1231
+ if (de && (!n || Ie === (t ?? null))) {
1232
+ const s = await de;
1233
+ return Ae(s);
1199
1234
  }
1200
- ge = t ?? null, be.clear();
1201
- const r = tn();
1202
- re = (async () => {
1203
- const s = await Ge(Zt()), a = await tt(
1204
- nn(),
1235
+ Ie = t ?? null, Ue.clear();
1236
+ const r = wn();
1237
+ de = (async () => {
1238
+ const s = await Er(t), c = await ht(
1239
+ gn(),
1205
1240
  r,
1206
1241
  n,
1207
1242
  t
1208
1243
  );
1209
- let c = null;
1244
+ let a = null;
1210
1245
  try {
1211
- c = await tt(
1212
- rn(),
1246
+ a = await ht(
1247
+ yn(),
1213
1248
  r,
1214
1249
  n,
1215
1250
  t
1216
1251
  );
1217
1252
  } catch {
1218
- c = null;
1253
+ a = null;
1219
1254
  }
1220
- return { sil: s, viseme: a, expression: c };
1255
+ return { sil: s, viseme: c, expression: a };
1221
1256
  })();
1222
- const i = await re;
1223
- return ye(i);
1257
+ const i = await de;
1258
+ return Ae(i);
1224
1259
  }
1225
- async function pt(e) {
1226
- if (await He(e), !re) throw new Error("Assets not loaded");
1227
- return re;
1260
+ async function Mt(e) {
1261
+ if (await Ye(e), !de) throw new Error("Assets not loaded");
1262
+ return de;
1228
1263
  }
1229
- function ye(e) {
1230
- return bn(
1264
+ function Ae(e) {
1265
+ return $n(
1231
1266
  e.viseme.atlasMeta,
1232
1267
  e.sil.naturalWidth,
1233
1268
  e.sil.naturalHeight
1234
1269
  );
1235
1270
  }
1236
- function sr(e, t) {
1271
+ function Sr(e, t) {
1237
1272
  const n = document.createElement("canvas");
1238
1273
  return n.width = t.w, n.height = t.h, n.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), n;
1239
1274
  }
1240
- async function nt(e, t, n) {
1241
- const r = `${t.diffBase}::${n}`, i = be.get(r);
1275
+ async function mt(e, t, n) {
1276
+ const r = `${t.diffBase}::${n}`, i = Ue.get(r);
1242
1277
  if (i) return i;
1243
1278
  const s = (async () => {
1244
- const a = t.cellByPath.get(n);
1245
- if (!a) throw new Error(`No atlas cell for path: ${n}`);
1246
- const c = Dn(t.atlasMeta, a), l = ye(e);
1247
- if (xn(a)) {
1248
- const _ = sr(t, a), S = document.createElement("canvas");
1279
+ const c = t.cellByPath.get(n);
1280
+ if (!c) throw new Error(`No atlas cell for path: ${n}`);
1281
+ const a = Hn(t.atlasMeta, c), l = Ae(e);
1282
+ if (Wn(c)) {
1283
+ const m = Sr(t, c), S = document.createElement("canvas");
1249
1284
  S.width = l.width, S.height = l.height;
1250
1285
  const o = S.getContext("2d");
1251
- return o.fillStyle = "#000", o.fillRect(0, 0, l.width, l.height), o.drawImage(_, c.x, c.y), S;
1286
+ return o.fillStyle = "#000", o.fillRect(0, 0, l.width, l.height), o.drawImage(m, a.x, a.y), S;
1252
1287
  }
1253
- const d = `${t.diffBase}/${n}`, m = await Ge(d);
1254
- if (m.naturalWidth === l.width && m.naturalHeight === l.height)
1255
- return m;
1288
+ const d = `${t.diffBase}/${n}`, _ = await tt(d);
1289
+ if (_.naturalWidth === l.width && _.naturalHeight === l.height)
1290
+ return _;
1256
1291
  throw new Error(`Diff PNG wrong size for ${n}`);
1257
1292
  })();
1258
- return be.set(r, s), s;
1293
+ return Ue.set(r, s), s;
1259
1294
  }
1260
- async function rt(e, t, n, r = Ke, i, s) {
1295
+ async function _t(e, t, n, r = et, i, s) {
1261
1296
  if (i) {
1262
1297
  const { width: S, height: o } = i;
1263
1298
  if (s && !s() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
1264
1299
  return;
1265
- const D = document.createElement("canvas");
1266
- D.width = S, D.height = o;
1267
- const w = D.getContext("2d");
1300
+ const F = document.createElement("canvas");
1301
+ F.width = S, F.height = o;
1302
+ const w = F.getContext("2d");
1268
1303
  if (w.clearRect(0, 0, S, o), w.drawImage(t, 0, 0, S, o), s && !s()) return;
1269
1304
  (e.width !== S || e.height !== o) && (e.width = S, e.height = o);
1270
1305
  const u = e.getContext("2d");
1271
- u.clearRect(0, 0, S, o), u.drawImage(D, 0, 0);
1306
+ u.clearRect(0, 0, S, o), u.drawImage(F, 0, 0);
1272
1307
  return;
1273
1308
  }
1274
- const a = await pt(), { width: c, height: l } = ye(a);
1275
- (e.width !== c || e.height !== l) && (e.width = c, e.height = l);
1276
- const d = [], m = e.getContext("2d");
1277
- if (m.clearRect(0, 0, c, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
1278
- const S = a.sil;
1279
- m.drawImage(S, 0, 0, c, l);
1309
+ const c = await Mt(), { width: a, height: l } = Ae(c);
1310
+ (e.width !== a || e.height !== l) && (e.width = a, e.height = l);
1311
+ const d = [], _ = e.getContext("2d");
1312
+ if (_.clearRect(0, 0, a, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
1313
+ const S = c.sil;
1314
+ _.drawImage(S, 0, 0, a, l);
1280
1315
  return;
1281
1316
  }
1282
1317
  if (d.length === 0) {
1283
- m.drawImage(t, 0, 0, c, l);
1318
+ _.drawImage(t, 0, 0, a, l);
1284
1319
  return;
1285
1320
  }
1286
- const _ = yt(t, d, c, l, r);
1287
- m.drawImage(_, 0, 0);
1321
+ const m = xt(t, d, a, l, r);
1322
+ _.drawImage(m, 0, 0);
1288
1323
  }
1289
- async function We(e, t, n = Ke) {
1290
- const r = await pt(ge ?? void 0), { width: i, height: s } = ye(r);
1324
+ async function Xe(e, t, n = et) {
1325
+ const r = await Mt(Ie ?? void 0), { width: i, height: s } = Ae(r);
1291
1326
  (e.width !== i || e.height !== s) && (e.width = i, e.height = s);
1292
- const a = [];
1293
- t.mouthPath && a.push(await nt(r, r.viseme, t.mouthPath)), t.expressionPath && r.expression && a.push(
1294
- await nt(r, r.expression, t.expressionPath)
1327
+ const c = [];
1328
+ t.mouthPath && c.push(await mt(r, r.viseme, t.mouthPath)), t.expressionPath && r.expression && c.push(
1329
+ await mt(r, r.expression, t.expressionPath)
1295
1330
  );
1296
- const c = e.getContext("2d");
1297
- if (c.clearRect(0, 0, i, s), a.length === 0) {
1298
- c.drawImage(r.sil, 0, 0, i, s);
1331
+ const a = e.getContext("2d");
1332
+ if (a.clearRect(0, 0, i, s), c.length === 0) {
1333
+ a.drawImage(r.sil, 0, 0, i, s);
1299
1334
  return;
1300
1335
  }
1301
- const l = yt(
1336
+ const l = xt(
1302
1337
  r.sil,
1303
- a,
1338
+ c,
1304
1339
  i,
1305
1340
  s,
1306
1341
  n
1307
1342
  );
1308
- c.drawImage(l, 0, 0);
1343
+ a.drawImage(l, 0, 0);
1309
1344
  }
1310
- async function or(e) {
1311
- await We(e, { mouthPath: null, expressionPath: null });
1345
+ async function kr(e) {
1346
+ await Xe(e, { mouthPath: null, expressionPath: null });
1312
1347
  }
1313
- function ar(e) {
1348
+ function Tr(e) {
1314
1349
  const t = /* @__PURE__ */ new Map();
1315
1350
  for (const n of e)
1316
1351
  t.has(n.vtime) || t.set(n.vtime, n);
1317
1352
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
1318
1353
  }
1319
- function cr(e) {
1320
- const t = ar(e), n = [];
1354
+ function vr(e) {
1355
+ const t = Tr(e), n = [];
1321
1356
  for (let r = 0; r < t.length - 1; r++) {
1322
- const i = t[r].viseme, s = t[r + 1].viseme, a = t[r].vtime, c = t[r + 1].vtime;
1323
- i === s || c <= a || n.push({ from: i, to: s, fromVtime: a, toVtime: c });
1357
+ const i = t[r].viseme, s = t[r + 1].viseme, c = t[r].vtime, a = t[r + 1].vtime;
1358
+ i === s || a <= c || n.push({ from: i, to: s, fromVtime: c, toVtime: a });
1324
1359
  }
1325
1360
  return n;
1326
1361
  }
1327
- function ur(e, t) {
1362
+ function Ir(e, t) {
1328
1363
  let n = null;
1329
1364
  for (const r of e)
1330
1365
  t >= r.fromVtime && t < r.toVtime && (n = r);
1331
1366
  return n;
1332
1367
  }
1333
- function lr(e, t) {
1368
+ function Ar(e, t) {
1334
1369
  return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
1335
1370
  }
1336
- const fr = 500, dr = "__sil__";
1337
- function hr() {
1371
+ const Ct = 400, br = 200, Rr = 600, Dr = "__sil__";
1372
+ function xr() {
1338
1373
  return { lastDrawnKey: "" };
1339
1374
  }
1340
- function me(e) {
1375
+ function ge(e) {
1341
1376
  e.lastDrawnKey = "";
1342
1377
  }
1343
- function it(e) {
1344
- return e ?? dr;
1378
+ function Mr(e) {
1379
+ let t = "sil";
1380
+ for (const n of e)
1381
+ n.viseme !== "sil" && (t = n.viseme);
1382
+ return t;
1345
1383
  }
1346
- function _r(e, t) {
1384
+ function Cr(e) {
1385
+ return e === "sil" ? !1 : Rt(e, "sil").length > 0;
1386
+ }
1387
+ function Fr() {
1388
+ return Ct + Rr;
1389
+ }
1390
+ function wt(e) {
1391
+ return e ?? Dr;
1392
+ }
1393
+ function Lr(e, t) {
1347
1394
  if (e.length === 0)
1348
1395
  return { diffPath: null, label: "sil" };
1349
- const n = cr(e), r = ur(n, t);
1396
+ const n = vr(e), r = Ir(n, t);
1350
1397
  if (r) {
1351
- const s = r.toVtime - r.fromVtime, a = lr(r.fromVtime, r.toVtime);
1352
- if (t >= a.transStart && t < r.toVtime) {
1353
- const c = Pn(r.from, r.to), l = Ln(c, s);
1398
+ const s = r.toVtime - r.fromVtime, c = Ar(r.fromVtime, r.toVtime);
1399
+ if (t >= c.transStart && t < r.toVtime) {
1400
+ const a = Rt(r.from, r.to), l = Yn(a, s);
1354
1401
  if (l.length > 0) {
1355
- const d = Un(
1402
+ const d = Xn(
1356
1403
  t,
1357
- a.transStart,
1404
+ c.transStart,
1358
1405
  r.toVtime,
1359
1406
  l.length
1360
1407
  );
1361
1408
  return { diffPath: l[d] ?? l[l.length - 1], label: `${r.from}→${r.to}` };
1362
1409
  }
1363
- return { diffPath: $e(r.to), label: r.to };
1410
+ return { diffPath: Qe(r.to), label: r.to };
1364
1411
  }
1365
1412
  }
1366
- const i = Sn(e, t);
1367
- return i === "sil" ? { diffPath: null, label: "sil" } : { diffPath: $e(i), label: i };
1413
+ const i = vt(e, t);
1414
+ return i === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Qe(i), label: i };
1368
1415
  }
1369
- function Et(e, t) {
1370
- const n = t ?? it(e.expressionPath);
1371
- return `${it(e.mouthPath)}|${n}`;
1416
+ function Ft(e, t) {
1417
+ const n = t ?? wt(e.expressionPath);
1418
+ return `${wt(e.mouthPath)}|${n}`;
1372
1419
  }
1373
- function mr(e, t, n, r, i, s, a, c) {
1374
- const l = _r(t, n), d = {
1420
+ function Or(e, t, n, r, i, s, c, a) {
1421
+ const l = Lr(t, n), d = {
1375
1422
  mouthPath: l.diffPath,
1376
1423
  expressionPath: r
1377
- }, m = Et(d, i);
1378
- m !== s.lastDrawnKey && (c(l.label), a(e, d, m, (_) => {
1379
- _ === m && (s.lastDrawnKey = m);
1424
+ }, _ = Ft(d, i);
1425
+ _ !== s.lastDrawnKey && (a(l.label), c(e, d, _, (m) => {
1426
+ m === _ && (s.lastDrawnKey = _);
1380
1427
  }));
1381
1428
  }
1382
- function st(e, t, n, r, i, s, a = null) {
1383
- const c = { mouthPath: null, expressionPath: t }, l = a != null ? `|idle@${Math.round(a * 1e3)}` : "", d = Et(c, n) + l;
1384
- !(a != null) && d === r.lastDrawnKey || (s(
1385
- a != null ? "idle" : "sil"
1386
- ), i(e, c, d, (_) => {
1387
- _ === d && (r.lastDrawnKey = d);
1429
+ function gt(e, t, n, r, i, s, c = null) {
1430
+ const a = { mouthPath: null, expressionPath: t }, l = c != null ? `|idle@${Math.round(c * 1e3)}` : "", d = Ft(a, n) + l;
1431
+ !(c != null) && d === r.lastDrawnKey || (s(
1432
+ c != null ? "idle" : "sil"
1433
+ ), i(e, a, d, (m) => {
1434
+ m === d && (r.lastDrawnKey = d);
1388
1435
  }));
1389
1436
  }
1390
- function kt(e) {
1437
+ function Lt(e) {
1391
1438
  let t = 0, n = null, r = !1, i = !1;
1392
1439
  const s = async () => {
1393
1440
  if (!r) {
1394
1441
  r = !0;
1395
1442
  try {
1396
1443
  for (; n; ) {
1397
- const c = n;
1444
+ const a = n;
1398
1445
  n = null;
1399
- const l = ++t, d = await e(c.diffs, l, c);
1400
- n || d && l === t && c.onDisplayed?.(c.drawKey);
1446
+ const l = ++t, d = await e(a.diffs, l, a);
1447
+ n || d && l === t && a.onDisplayed?.(a.drawKey);
1401
1448
  }
1402
1449
  } finally {
1403
1450
  r = !1, n && s();
1404
1451
  }
1405
1452
  }
1406
- }, a = () => {
1453
+ }, c = () => {
1407
1454
  i || (i = !0, queueMicrotask(() => {
1408
1455
  i = !1, s();
1409
1456
  }));
1410
1457
  };
1411
1458
  return {
1412
- enqueue(c, l, d) {
1413
- n = { diffs: c, drawKey: l, onDisplayed: d }, a();
1459
+ enqueue(a, l, d) {
1460
+ n = { diffs: a, drawKey: l, onDisplayed: d }, c();
1414
1461
  },
1415
1462
  reset() {
1416
1463
  t += 1, n = null;
1417
1464
  },
1418
- isLatestSeq(c) {
1419
- return c === t;
1465
+ isLatestSeq(a) {
1466
+ return a === t;
1420
1467
  },
1421
1468
  getLatestSeq() {
1422
1469
  return t;
1423
1470
  }
1424
1471
  };
1425
1472
  }
1426
- const ot = -1, at = /* @__PURE__ */ new Map();
1427
- async function wr(e) {
1428
- let t = at.get(e);
1473
+ const yt = -1, pt = /* @__PURE__ */ new Map();
1474
+ async function Pr(e) {
1475
+ let t = pt.get(e);
1429
1476
  if (!t) {
1430
1477
  const n = await fetch(e);
1431
1478
  if (!n.ok)
@@ -1433,37 +1480,37 @@ async function wr(e) {
1433
1480
  `Failed to fetch worker script (${n.status}): ${e}`
1434
1481
  );
1435
1482
  const r = await n.blob();
1436
- t = URL.createObjectURL(r), at.set(e, t);
1483
+ t = URL.createObjectURL(r), pt.set(e, t);
1437
1484
  }
1438
1485
  return new Worker(t, { name: "visemeDiffPreview" });
1439
1486
  }
1440
- function gr() {
1487
+ function Ur() {
1441
1488
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
1442
1489
  }
1443
- function yr(e, t) {
1490
+ function Br(e, t) {
1444
1491
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
1445
1492
  const n = e.getContext("2d");
1446
1493
  n && n.drawImage(t, 0, 0);
1447
1494
  }
1448
- function ct(e, t) {
1495
+ function Et(e, t) {
1449
1496
  let n = 0;
1450
- const r = kt(async (i, s) => (await He(), await We(e, i), r.isLatestSeq(s)));
1497
+ const r = Lt(async (i, s) => (await Ye(), await Xe(e, i), r.isLatestSeq(s)));
1451
1498
  return {
1452
1499
  usesWorker: !1,
1453
1500
  async loadAssets(i) {
1454
- return await He(i);
1501
+ return await Ye(i);
1455
1502
  },
1456
1503
  async renderSilOnly() {
1457
- n += 1, r.reset(), await or(e);
1504
+ n += 1, r.reset(), await kr(e);
1458
1505
  },
1459
- drawLiveFrame(i, s, a, c) {
1460
- r.enqueue(s, a, c);
1506
+ drawLiveFrame(i, s, c, a) {
1507
+ r.enqueue(s, c, a);
1461
1508
  },
1462
1509
  async renderViseme(i, s) {
1463
1510
  n += 1;
1464
- const a = n;
1465
- t.onStatus?.(s), await We(i, {
1466
- mouthPath: $e(s),
1511
+ const c = n;
1512
+ t.onStatus?.(s), await Xe(i, {
1513
+ mouthPath: Qe(s),
1467
1514
  expressionPath: null
1468
1515
  });
1469
1516
  },
@@ -1472,9 +1519,9 @@ function ct(e, t) {
1472
1519
  }
1473
1520
  };
1474
1521
  }
1475
- function pr(e, t, n) {
1476
- let r = null, i = 1, s = 0, a = !1, c = !1;
1477
- const l = /* @__PURE__ */ new Map(), d = kt(async (w, u, g) => (l.set(u, {
1522
+ function Nr(e, t, n) {
1523
+ let r = null, i = 1, s = 0, c = !1, a = !1;
1524
+ const l = /* @__PURE__ */ new Map(), d = Lt(async (w, u, g) => (l.set(u, {
1478
1525
  drawKey: g.drawKey,
1479
1526
  onDisplayed: g.onDisplayed
1480
1527
  }), await o(
@@ -1486,123 +1533,123 @@ function pr(e, t, n) {
1486
1533
  },
1487
1534
  void 0,
1488
1535
  !0
1489
- ), !1)), m = (w) => {
1490
- if (w === ot) {
1491
- let p = -1, A;
1492
- for (const [V, y] of l)
1493
- V >= p && (p = V, A = y);
1494
- p >= 0 && l.delete(p), A?.onDisplayed?.(A.drawKey);
1536
+ ), !1)), _ = (w) => {
1537
+ if (w === yt) {
1538
+ let y = -1, v;
1539
+ for (const [H, h] of l)
1540
+ H >= y && (y = H, v = h);
1541
+ y >= 0 && l.delete(y), v?.onDisplayed?.(v.drawKey);
1495
1542
  return;
1496
1543
  }
1497
1544
  const u = -w, g = l.get(u);
1498
1545
  l.delete(u), g?.onDisplayed?.(g.drawKey);
1499
- }, _ = /* @__PURE__ */ new Map(), S = (w, u) => {
1500
- c || !r || r.postMessage(w, []);
1546
+ }, m = /* @__PURE__ */ new Map(), S = (w, u) => {
1547
+ a || !r || r.postMessage(w, []);
1501
1548
  }, o = (w, u, g = !1) => {
1502
- if (c) return Promise.resolve();
1503
- const p = i++;
1504
- return new Promise((A, V) => {
1505
- _.set(p, {
1506
- resolve: (y) => A(y),
1507
- reject: V,
1549
+ if (a) return Promise.resolve();
1550
+ const y = i++;
1551
+ return new Promise((v, H) => {
1552
+ m.set(y, {
1553
+ resolve: (h) => v(h),
1554
+ reject: H,
1508
1555
  generation: typeof w.generation == "number" ? w.generation : void 0,
1509
1556
  expectRenderDone: g
1510
- }), S({ ...w, requestId: p });
1557
+ }), S({ ...w, requestId: y });
1511
1558
  });
1512
- }, D = (async () => {
1513
- r = await wr(n), r.onmessage = (w) => {
1514
- if (c) return;
1559
+ }, F = (async () => {
1560
+ r = await Pr(n), r.onmessage = (w) => {
1561
+ if (a) return;
1515
1562
  const u = w.data;
1516
1563
  if (u.type === "status") {
1517
1564
  t.onStatus?.(u.label);
1518
1565
  return;
1519
1566
  }
1520
1567
  if (u.type === "frame") {
1521
- const p = u.generation < 0;
1522
- if (!p && u.generation !== s) {
1568
+ const y = u.generation < 0;
1569
+ if (!y && u.generation !== s) {
1523
1570
  u.bitmap.close();
1524
1571
  return;
1525
1572
  }
1526
- if (p && !(u.generation === ot)) {
1527
- const V = -u.generation;
1528
- if (!d.isLatestSeq(V)) {
1573
+ if (y && !(u.generation === yt)) {
1574
+ const H = -u.generation;
1575
+ if (!d.isLatestSeq(H)) {
1529
1576
  u.bitmap.close();
1530
1577
  return;
1531
1578
  }
1532
1579
  }
1533
- if (p && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
1580
+ if (y && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
1534
1581
  u.bitmap.close();
1535
1582
  return;
1536
1583
  }
1537
- yr(e, u.bitmap), u.bitmap.close(), p && m(u.generation);
1584
+ Br(e, u.bitmap), u.bitmap.close(), y && _(u.generation);
1538
1585
  return;
1539
1586
  }
1540
- const g = _.get(u.requestId);
1587
+ const g = m.get(u.requestId);
1541
1588
  if (g)
1542
1589
  switch (u.type) {
1543
1590
  case "ready":
1544
- _.delete(u.requestId), g.resolve();
1591
+ m.delete(u.requestId), g.resolve();
1545
1592
  break;
1546
1593
  case "loadAssetsDone":
1547
- _.delete(u.requestId), g.resolve({ width: u.width, height: u.height });
1594
+ m.delete(u.requestId), g.resolve({ width: u.width, height: u.height });
1548
1595
  break;
1549
1596
  case "renderDone":
1550
1597
  if (g.expectRenderDone && g.generation != null && u.generation !== g.generation)
1551
1598
  return;
1552
- _.delete(u.requestId), g.resolve();
1599
+ m.delete(u.requestId), g.resolve();
1553
1600
  break;
1554
1601
  case "renderAborted":
1555
- _.delete(u.requestId), g.resolve();
1602
+ m.delete(u.requestId), g.resolve();
1556
1603
  break;
1557
1604
  case "error":
1558
- _.delete(u.requestId), t.onError?.(u.message), g.reject(new Error(u.message));
1605
+ m.delete(u.requestId), t.onError?.(u.message), g.reject(new Error(u.message));
1559
1606
  break;
1560
1607
  }
1561
1608
  }, r.onerror = (w) => {
1562
- if (c) return;
1609
+ if (a) return;
1563
1610
  const u = w.message || "Worker error";
1564
1611
  t.onError?.(u);
1565
- for (const [, g] of _)
1612
+ for (const [, g] of m)
1566
1613
  g.reject(new Error(u));
1567
- _.clear();
1568
- }, await o({ type: "init" }), a = !0;
1614
+ m.clear();
1615
+ }, await o({ type: "init" }), c = !0;
1569
1616
  })();
1570
1617
  return {
1571
1618
  usesWorker: !0,
1572
1619
  async loadAssets(w) {
1573
- if (c) return { width: 842, height: 1264 };
1574
- if (await D, c) return { width: 842, height: 1264 };
1575
- if (!a) throw new Error("Worker init failed");
1620
+ if (a) return { width: 842, height: 1264 };
1621
+ if (await F, a) return { width: 842, height: 1264 };
1622
+ if (!c) throw new Error("Worker init failed");
1576
1623
  return await o({
1577
1624
  type: "loadAssets",
1578
1625
  keyHex: w,
1579
- urls: Yt(ie())
1626
+ urls: hn(he())
1580
1627
  }) ?? { width: 842, height: 1264 };
1581
1628
  },
1582
1629
  async renderSilOnly() {
1583
- if (c || (await D, c)) return;
1630
+ if (a || (await F, a)) return;
1584
1631
  s += 1, d.reset(), l.clear();
1585
1632
  const w = s;
1586
- await o(
1633
+ await o({ type: "cancelLiveDraws" }), await o(
1587
1634
  { type: "renderSil", generation: w },
1588
1635
  void 0,
1589
1636
  !0
1590
1637
  );
1591
1638
  },
1592
- drawLiveFrame(w, u, g, p) {
1593
- c || D.then(() => {
1594
- c || d.enqueue(u, g, p);
1639
+ drawLiveFrame(w, u, g, y) {
1640
+ a || F.then(() => {
1641
+ a || d.enqueue(u, g, y);
1595
1642
  });
1596
1643
  },
1597
1644
  async renderViseme(w, u, g = {}) {
1598
- if (c || (await D, c)) return;
1599
- s += 1;
1600
- const p = s;
1645
+ if (a || (await F, a)) return;
1646
+ s += 1, d.reset(), l.clear();
1647
+ const y = s;
1601
1648
  try {
1602
- await o(
1649
+ await o({ type: "cancelLiveDraws" }), await o(
1603
1650
  {
1604
1651
  type: "renderViseme",
1605
- generation: p,
1652
+ generation: y,
1606
1653
  to: u,
1607
1654
  from: g.from,
1608
1655
  transitionDurationMs: g.transitionDurationMs,
@@ -1612,60 +1659,60 @@ function pr(e, t, n) {
1612
1659
  void 0,
1613
1660
  !0
1614
1661
  );
1615
- } catch (A) {
1616
- if (A?.name === "AbortError") return;
1617
- throw A;
1662
+ } catch (v) {
1663
+ if (v?.name === "AbortError") return;
1664
+ throw v;
1618
1665
  }
1619
1666
  },
1620
1667
  dispose() {
1621
- if (!c) {
1622
- c = !0, s += 1, d.reset(), l.clear();
1623
- for (const [, w] of _)
1668
+ if (!a) {
1669
+ a = !0, s += 1, d.reset(), l.clear();
1670
+ for (const [, w] of m)
1624
1671
  w.resolve();
1625
- _.clear(), r?.terminate(), r = null;
1672
+ m.clear(), r?.terminate(), r = null;
1626
1673
  }
1627
1674
  }
1628
1675
  };
1629
1676
  }
1630
- function Er(e, t = {}) {
1631
- if (!gr())
1632
- return ct(e, t);
1633
- const n = Ft(t.workerScriptUrl);
1677
+ function Vr(e, t = {}) {
1678
+ if (!Ur())
1679
+ return Et(e, t);
1680
+ const n = zt(t.workerScriptUrl);
1634
1681
  try {
1635
- return pr(e, t, n);
1682
+ return Nr(e, t, n);
1636
1683
  } catch {
1637
- return ct(e, t);
1684
+ return Et(e, t);
1638
1685
  }
1639
1686
  }
1640
- class kr extends Error {
1687
+ class $r extends Error {
1641
1688
  constructor(t, n) {
1642
1689
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
1643
1690
  }
1644
1691
  }
1645
- function Oe(e, t, n) {
1692
+ function qe(e, t, n) {
1646
1693
  return new Promise((r, i) => {
1647
1694
  const s = globalThis.setTimeout(() => {
1648
- i(new kr(n, t));
1695
+ i(new $r(n, t));
1649
1696
  }, t);
1650
1697
  e.then(
1651
- (a) => {
1652
- globalThis.clearTimeout(s), r(a);
1698
+ (c) => {
1699
+ globalThis.clearTimeout(s), r(c);
1653
1700
  },
1654
- (a) => {
1655
- globalThis.clearTimeout(s), i(a);
1701
+ (c) => {
1702
+ globalThis.clearTimeout(s), i(c);
1656
1703
  }
1657
1704
  );
1658
1705
  });
1659
1706
  }
1660
- const Sr = {
1707
+ const Hr = {
1661
1708
  position: "relative",
1662
1709
  display: "inline-block",
1663
1710
  lineHeight: 0
1664
- }, Tr = {
1711
+ }, Wr = {
1665
1712
  display: "block",
1666
1713
  maxWidth: "100%",
1667
1714
  height: "auto"
1668
- }, vr = {
1715
+ }, qr = {
1669
1716
  position: "absolute",
1670
1717
  inset: 0,
1671
1718
  display: "flex",
@@ -1677,304 +1724,394 @@ const Sr = {
1677
1724
  fontSize: "0.875rem",
1678
1725
  textAlign: "center"
1679
1726
  };
1680
- function Ae(e) {
1681
- return Ut(e) ? An : ht;
1727
+ function Oe(e) {
1728
+ return Xt(e) ? Nn : It;
1682
1729
  }
1683
- const br = vt(function({
1730
+ const zr = Nt(function({
1684
1731
  id: t,
1685
1732
  assets: n,
1686
1733
  authToken: r,
1687
- ttsEngineId: i = ce,
1734
+ ttsEngineId: i = pe,
1688
1735
  voiceId: s,
1689
- speakingRate: a = _t,
1690
- className: c,
1736
+ speakingRate: c = At,
1737
+ className: a,
1691
1738
  style: l,
1692
1739
  canvasStyle: d,
1693
- onStatusChange: m,
1694
- onDisplayStatus: _,
1740
+ onStatusChange: _,
1741
+ onDisplayStatus: m,
1695
1742
  onError: S,
1696
1743
  onReady: o,
1697
- showErrorOverlay: D = !0
1744
+ showErrorOverlay: F = !0
1698
1745
  }, w) {
1699
- const u = B(null), g = B(null), p = B(hr()), A = B(Yn()), V = B(0), y = B(0), E = B(null), x = B(!1), b = B(
1746
+ const u = R(null), g = R(null), y = R(xr()), v = R(dr()), H = R(0), h = R(0), E = R(null), D = R(null), L = R(!1), z = R(!1), U = R(!1), ae = R("sil"), me = R(!1), N = R(
1700
1747
  null
1701
- ), W = B(!1), [q, ue] = _e("idle"), [Ee, X] = _e(null), [K, ke] = _e(!1), [Ce, le] = _e(!1), [se, Se] = _e({ width: 842, height: 1264 }), Z = B(r ?? null), fe = B(null), h = B(null), C = B(!1), N = B({ width: 842, height: 1264 }), P = B(o), T = B(_), L = B(S);
1702
- P.current = o, T.current = _, L.current = S;
1703
- const Q = ne(
1748
+ ), X = R(!1), [Re, He] = ke("idle"), [De, ue] = ke(null), [se, xe] = ke(!1), [nt, p] = ke(!1), [V, W] = ke({ width: 842, height: 1264 }), x = R(r ?? null), M = R(null), I = R(null), Q = R(!1), J = R({ width: 842, height: 1264 }), P = R(o), O = R(m), q = R(S);
1749
+ P.current = o, O.current = m, q.current = S;
1750
+ const ce = ie(
1704
1751
  (f) => {
1705
- const k = f?.ttsEngineId ?? i ?? h.current?.ttsEngineId ?? ce, v = f?.voiceId ?? s ?? h.current?.voiceId ?? Ae(k);
1706
- return { ttsEngineId: k, voiceId: v };
1752
+ const k = f?.ttsEngineId ?? i ?? I.current?.ttsEngineId ?? pe, T = f?.voiceId ?? s ?? I.current?.voiceId ?? Oe(k);
1753
+ return { ttsEngineId: k, voiceId: T };
1707
1754
  },
1708
1755
  [i, s]
1709
- ), $ = ne((f) => {
1710
- X(f), L.current?.(f);
1711
- }, []), O = ne(
1756
+ ), $ = ie((f) => {
1757
+ ue(f), q.current?.(f);
1758
+ }, []), Me = ie(
1712
1759
  (f) => {
1713
- ue(f), m?.(f);
1760
+ He(f), _?.(f);
1714
1761
  },
1715
- [m]
1716
- ), M = B(
1717
- Rn(O, Re)
1718
- ), F = ne(() => {
1762
+ [_]
1763
+ ), B = R(
1764
+ Vn(Me, Pe)
1765
+ ), b = ie(() => {
1719
1766
  E.current != null && (clearTimeout(E.current), E.current = null);
1720
- }, []), J = ne(async () => {
1721
- const f = y.current, k = g.current;
1722
- !k || !K || M.current.isSpeaking() || (me(p.current), await k.renderSilOnly(), f === y.current && (M.current.isSpeaking() || (T.current?.("sil"), W.current && b.current && (b.current.restart(), b.current.setActive(!0)))));
1723
- }, [K]), H = ne(() => {
1724
- F();
1725
- const f = y.current;
1726
- J(), E.current = setTimeout(() => {
1727
- E.current = null, f === y.current && J();
1728
- }, fr);
1729
- }, [F, J]), de = ne(async () => {
1767
+ }, []), K = ie(() => {
1768
+ D.current != null && (clearTimeout(D.current), D.current = null), U.current = !1;
1769
+ }, []), te = ie(() => {
1770
+ !X.current || !N.current || (K(), U.current = !0, D.current = setTimeout(() => {
1771
+ if (D.current = null, B.current.isSpeaking()) {
1772
+ U.current = !1;
1773
+ return;
1774
+ }
1775
+ if (L.current) {
1776
+ U.current = !1;
1777
+ return;
1778
+ }
1779
+ const f = N.current;
1780
+ if (!f) {
1781
+ U.current = !1;
1782
+ return;
1783
+ }
1784
+ f.restart(), f.setActive(!0);
1785
+ const k = f.getVideo();
1786
+ let T = !1;
1787
+ const A = () => {
1788
+ T || (T = !0, k.removeEventListener("playing", C), U.current = !1);
1789
+ }, C = () => {
1790
+ A();
1791
+ };
1792
+ if (k.addEventListener("playing", C, { once: !0 }), k.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !k.paused) {
1793
+ A();
1794
+ return;
1795
+ }
1796
+ setTimeout(A, 300);
1797
+ }, br));
1798
+ }, [K]), Z = ie(() => {
1799
+ if (b(), O.current?.("sil"), L.current = !1, !X.current || !N.current) {
1800
+ U.current = !1;
1801
+ return;
1802
+ }
1803
+ te();
1804
+ }, [b, te]), j = ie(
1805
+ async (f) => {
1806
+ const k = h.current, T = g.current, A = u.current, C = () => {
1807
+ f?.fallbackOnly || (L.current = !1);
1808
+ };
1809
+ if (!T || !A || !se) {
1810
+ C();
1811
+ return;
1812
+ }
1813
+ if (B.current.isSpeaking()) {
1814
+ C();
1815
+ return;
1816
+ }
1817
+ if (f?.fallbackOnly) {
1818
+ if (!L.current || (ge(y.current), await T.renderSilOnly(), k !== h.current) || B.current.isSpeaking()) return;
1819
+ Z();
1820
+ return;
1821
+ }
1822
+ const Y = ae.current !== "sil" ? ae.current : Mr(B.current.getVisemeQueue()), ne = Cr(Y);
1823
+ if (ge(y.current), !ne) {
1824
+ if (await T.renderSilOnly(), k !== h.current || B.current.isSpeaking()) return;
1825
+ Z();
1826
+ return;
1827
+ }
1828
+ try {
1829
+ await T.renderViseme(A, "sil", {
1830
+ from: Y,
1831
+ transitionDurationMs: Ct
1832
+ });
1833
+ } catch (oe) {
1834
+ if (oe?.name !== "AbortError")
1835
+ throw oe;
1836
+ }
1837
+ if (k !== h.current) {
1838
+ C();
1839
+ return;
1840
+ }
1841
+ if (B.current.isSpeaking()) {
1842
+ C();
1843
+ return;
1844
+ }
1845
+ Z();
1846
+ },
1847
+ [se, Z]
1848
+ ), _e = ie(() => {
1849
+ if (z.current || L.current) return;
1850
+ z.current = !0, L.current = !0, b();
1851
+ const f = h.current;
1852
+ j().finally(() => {
1853
+ z.current = !1;
1854
+ }), E.current = setTimeout(() => {
1855
+ E.current = null, f === h.current && j({ fallbackOnly: !0 });
1856
+ }, Fr());
1857
+ }, [b, j]), rt = ie(async () => {
1730
1858
  const f = Math.floor(Date.now() / 1e3);
1731
- if (fe.current && f < fe.current.expiresAt - 60)
1732
- return fe.current.key;
1733
- const k = Z.current ?? await Qe();
1734
- Z.current = k, M.current.setDeveloperToken(k);
1735
- const v = await Kt(k, Re);
1736
- return fe.current = {
1737
- key: v.value,
1738
- expiresAt: v.expiresAt
1739
- }, v.value;
1859
+ if (M.current && f < M.current.expiresAt - 60)
1860
+ return M.current.key;
1861
+ const k = x.current ?? await ot();
1862
+ x.current = k, B.current.setDeveloperToken(k);
1863
+ const T = await an(k, Pe);
1864
+ return M.current = {
1865
+ key: T.value,
1866
+ expiresAt: T.expiresAt
1867
+ }, T.value;
1740
1868
  }, []);
1741
- oe(() => {
1742
- r && (Z.current = r, M.current.setDeveloperToken(r));
1743
- }, [r]), oe(() => {
1744
- M.current.setTtsEngineId(i), h.current && (h.current.ttsEngineId = i);
1745
- }, [i]), oe(() => {
1746
- const f = s ?? Ae(i);
1747
- h.current && (h.current.voiceId = f);
1869
+ Te(() => {
1870
+ r && (x.current = r, B.current.setDeveloperToken(r));
1871
+ }, [r]), Te(() => {
1872
+ B.current.setTtsEngineId(i), I.current && (I.current.ttsEngineId = i);
1873
+ }, [i]), Te(() => {
1874
+ const f = s ?? Oe(i);
1875
+ I.current && (I.current.voiceId = f);
1748
1876
  }, [s, i]);
1749
- const he = It(
1877
+ const Ot = Vt(
1750
1878
  () => n ? JSON.stringify(n) : `id:${t ?? ""}`,
1751
1879
  [n, t]
1752
1880
  );
1753
- return oe(() => {
1881
+ return Te(() => {
1754
1882
  if (!t && !n) {
1755
1883
  $("AiTwin requires either `id` or `assets`");
1756
1884
  return;
1757
1885
  }
1758
1886
  let f = !1;
1759
- C.current = !1, ke(!1), le(!1), X(null), h.current = null, b.current = null, W.current = !1;
1887
+ Q.current = !1, xe(!1), p(!1), ue(null), I.current = null, N.current = null, X.current = !1;
1760
1888
  const k = u.current;
1761
1889
  if (!k) return;
1762
- let v = null;
1890
+ let T = null;
1763
1891
  return (async () => {
1764
1892
  try {
1765
- let I, R, G;
1893
+ let A, C, Y;
1766
1894
  if (n)
1767
- I = n, R = i, G = s ?? Ae(R);
1895
+ A = n, C = i, Y = s ?? Oe(C);
1768
1896
  else {
1769
- T.current?.("getAiTwin");
1770
- const U = await Oe(
1771
- Nt(t),
1897
+ O.current?.("getAiTwin");
1898
+ const G = await qe(
1899
+ en(t),
1772
1900
  3e4,
1773
1901
  "getAiTwin"
1774
1902
  );
1775
1903
  if (f) return;
1776
- if (!U.faceId?.trim())
1904
+ if (!G.faceId?.trim())
1777
1905
  throw new Error("getAiTwin returned no faceId");
1778
- R = U.ttsEngineId, G = s ?? U.voiceId ?? Ae(R), I = Qt(U.faceId);
1906
+ C = G.ttsEngineId, Y = s ?? G.voiceId ?? Oe(C), A = fn(G.faceId);
1779
1907
  }
1780
- h.current = { ttsEngineId: R, voiceId: G }, Jt(I), b.current = Xn(en()), v = Er(k, {
1781
- onStatus: (U) => {
1782
- f || T.current?.(U);
1908
+ I.current = { ttsEngineId: C, voiceId: Y }, dn(A), N.current = hr(), T = Vr(k, {
1909
+ onStatus: (G) => {
1910
+ f || O.current?.(G);
1783
1911
  },
1784
- onError: (U) => {
1785
- f || $(U);
1912
+ onError: (G) => {
1913
+ f || $(G);
1786
1914
  },
1787
- shouldAcceptLiveFrame: () => M.current.isSpeaking()
1788
- }), g.current = v, T.current?.("auth");
1789
- const Y = Z.current ?? r ?? await Oe(Qe(), 3e4, "getAuthToken");
1915
+ shouldAcceptLiveFrame: () => B.current.isSpeaking() && !L.current
1916
+ }), g.current = T, O.current?.("auth");
1917
+ const ne = x.current ?? r ?? await qe(ot(), 3e4, "getAuthToken");
1790
1918
  if (f) return;
1791
- Z.current = Y, M.current.setDeveloperToken(Y), M.current.setTtsEngineId(R);
1792
- const Me = dt() ? await de() : void 0;
1919
+ x.current = ne, B.current.setDeveloperToken(ne), B.current.setTtsEngineId(C);
1920
+ const oe = Be() ? await rt() : void 0;
1793
1921
  if (f) return;
1794
- T.current?.("loadAssets");
1795
- const j = await Oe(
1796
- v.loadAssets(Me),
1922
+ O.current?.("loadAssets");
1923
+ const we = await qe(
1924
+ T.loadAssets(oe),
1797
1925
  18e4,
1798
1926
  "load face assets"
1799
1927
  );
1800
- if (!f && j.width > 0 && j.height > 0 && (N.current = j, Se(j)), f) return;
1801
- C.current = !0, ke(!0), P.current?.(), v.renderSilOnly().then(() => {
1802
- f || T.current?.("sil");
1928
+ if (!f && we.width > 0 && we.height > 0 && (J.current = we, W(we)), f) return;
1929
+ Q.current = !0, xe(!0), P.current?.(), T.renderSilOnly().then(() => {
1930
+ f || O.current?.("sil");
1803
1931
  }), (async () => {
1804
1932
  try {
1805
- if (await b.current.load(), f) return;
1806
- W.current = !0, le(!0), me(p.current), b.current.setActive(!0);
1807
- const U = b.current.getVideo();
1808
- await rt(
1933
+ const G = await zn(oe);
1934
+ if (await N.current.load(G), f) return;
1935
+ X.current = !0, p(!0), ge(y.current), N.current.setActive(!0);
1936
+ const re = N.current.getVideo();
1937
+ await _t(
1809
1938
  k,
1810
- U,
1939
+ re,
1811
1940
  null,
1812
1941
  void 0,
1813
- N.current
1814
- ), f || T.current?.("idle");
1815
- } catch (U) {
1942
+ J.current
1943
+ ), f || O.current?.("idle");
1944
+ } catch (G) {
1816
1945
  if (f) return;
1817
- W.current = !1, le(!1), console.warn("[AiTwin] Idle video unavailable:", U);
1946
+ X.current = !1, p(!1), console.warn("[AiTwin] Idle video unavailable:", G);
1818
1947
  }
1819
1948
  })();
1820
- } catch (I) {
1949
+ } catch (A) {
1821
1950
  if (f) return;
1822
- if (I instanceof Le) {
1823
- $(I.message);
1951
+ if (A instanceof Ke) {
1952
+ $(A.message);
1824
1953
  return;
1825
1954
  }
1826
- $(I instanceof Error ? I.message : "Failed to load AI twin");
1955
+ $(A instanceof Error ? A.message : "Failed to load AI twin");
1827
1956
  }
1828
1957
  })(), () => {
1829
- f = !0, v?.dispose(), g.current = null;
1958
+ f = !0, N.current?.dispose(), T?.dispose(), g.current = null;
1830
1959
  };
1831
- }, [he, n, i, s, r, de, $]), oe(() => {
1832
- q === "done" && K && !M.current.isSpeaking() && H();
1833
- }, [q, K, H]), oe(() => {
1834
- const f = M.current, k = { current: !1 }, v = () => {
1835
- const I = u.current, R = g.current;
1836
- if (!I || !R || !K) {
1837
- V.current = requestAnimationFrame(v);
1960
+ }, [Ot, n, i, s, r, rt, $]), Te(() => {
1961
+ const f = B.current, k = { current: !1 }, T = () => {
1962
+ const A = u.current, C = g.current;
1963
+ if (!A || !C || !se) {
1964
+ H.current = requestAnimationFrame(T);
1838
1965
  return;
1839
1966
  }
1840
- const G = f.isSpeaking(), Y = f.getPlaybackElapsedMs(), Me = G ? nr(
1841
- Y,
1967
+ const Y = f.isSpeaking(), ne = me.current && !Y;
1968
+ ne && (v.current.reset(), N.current?.setActive(!1), _e());
1969
+ const oe = f.getPlaybackElapsedMs(), we = Y ? gr(
1970
+ oe,
1842
1971
  f.getSentenceEmotions(),
1843
1972
  f.getWordQueue(),
1844
1973
  f.getStreamMood()
1845
- ) : f.getStreamMood();
1846
- if (G) {
1847
- if (W.current && b.current?.setActive(!1), f.getVisemeQueue().length === 0) {
1848
- V.current = requestAnimationFrame(v);
1974
+ ) : f.getStreamMood(), G = ne || L.current || U.current;
1975
+ if (Y) {
1976
+ X.current && N.current?.setActive(!1);
1977
+ const re = f.getVisemeQueue();
1978
+ if (re.length === 0) {
1979
+ H.current = requestAnimationFrame(T);
1849
1980
  return;
1850
1981
  }
1851
- A.current.setTargetEmotion(Me), A.current.advance(performance.now());
1852
- const U = A.current.getExpressionPath(), ee = A.current.getDrawKey();
1853
- mr(
1854
- I,
1982
+ const le = vt(re, oe);
1983
+ le !== "sil" && (ae.current = le), v.current.setTargetEmotion(we), v.current.advance(performance.now());
1984
+ const fe = v.current.getExpressionPath(), Ee = v.current.getDrawKey();
1985
+ Or(
1986
+ A,
1855
1987
  f.getVisemeQueue(),
1856
- Y,
1857
- U,
1858
- ee,
1859
- p.current,
1860
- (te, Fe, Pe, St) => R.drawLiveFrame(te, Fe, Pe, St),
1861
- (te) => T.current?.(te)
1988
+ oe,
1989
+ fe,
1990
+ Ee,
1991
+ y.current,
1992
+ (Se, We, Pt, Ut) => C.drawLiveFrame(Se, We, Pt, Ut),
1993
+ (Se) => O.current?.(Se)
1862
1994
  );
1863
- } else if (W.current && b.current) {
1864
- const j = b.current, U = j.getVideo();
1865
- U.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (j.setActive(!0), k.current || (k.current = !0, rt(
1866
- I,
1867
- U,
1995
+ } else if (!G && X.current && N.current) {
1996
+ const re = N.current, le = re.getVideo();
1997
+ le.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), k.current || (k.current = !0, _t(
1998
+ A,
1999
+ le,
1868
2000
  null,
1869
2001
  void 0,
1870
- N.current,
1871
- () => !f.isSpeaking()
1872
- ).then(() => T.current?.("idle")).finally(() => {
2002
+ J.current,
2003
+ () => !f.isSpeaking() && !L.current && !U.current
2004
+ ).then(() => O.current?.("idle")).finally(() => {
1873
2005
  k.current = !1;
1874
- }))) : st(
1875
- I,
2006
+ }))) : gt(
2007
+ A,
1876
2008
  null,
1877
2009
  "__sil__",
1878
- p.current,
1879
- (ee, te, Fe, Pe) => R.drawLiveFrame(ee, te, Fe, Pe),
1880
- (ee) => T.current?.(ee)
2010
+ y.current,
2011
+ (fe, Ee, Se, We) => C.drawLiveFrame(fe, Ee, Se, We),
2012
+ (fe) => O.current?.(fe)
1881
2013
  );
1882
- } else
1883
- st(
1884
- I,
1885
- null,
1886
- "__sil__",
1887
- p.current,
1888
- (j, U, ee, te) => R.drawLiveFrame(j, U, ee, te),
1889
- (j) => T.current?.(j)
1890
- );
1891
- x.current && !G && (A.current.reset(), b.current?.setActive(!1), H()), x.current = G, V.current = requestAnimationFrame(v);
2014
+ } else G || gt(
2015
+ A,
2016
+ null,
2017
+ "__sil__",
2018
+ y.current,
2019
+ (re, le, fe, Ee) => C.drawLiveFrame(re, le, fe, Ee),
2020
+ (re) => O.current?.(re)
2021
+ );
2022
+ me.current = Y, H.current = requestAnimationFrame(T);
1892
2023
  };
1893
- return V.current = requestAnimationFrame(v), () => {
1894
- cancelAnimationFrame(V.current), F(), f.stop();
2024
+ return H.current = requestAnimationFrame(T), () => {
2025
+ cancelAnimationFrame(H.current), b(), K(), f.stop();
1895
2026
  };
1896
- }, [K, Ce, H, F]), At(
2027
+ }, [
2028
+ se,
2029
+ nt,
2030
+ _e,
2031
+ b,
2032
+ K
2033
+ ]), $t(
1897
2034
  w,
1898
2035
  () => ({
1899
2036
  speakText: async (f, k) => {
1900
- const v = f.trim();
1901
- if (!v) return;
1902
- const I = g.current;
1903
- if (!I || !C.current && !K)
2037
+ const T = f.trim();
2038
+ if (!T) return;
2039
+ const A = g.current;
2040
+ if (!A || !Q.current && !se)
1904
2041
  throw new Error("AI twin is not ready");
1905
- const { ttsEngineId: R, voiceId: G } = Q(k);
1906
- X(null), y.current += 1, F(), me(p.current), A.current.reset(), x.current = !1;
2042
+ const { ttsEngineId: C, voiceId: Y } = ce(k);
2043
+ ue(null), h.current += 1, b(), K(), L.current = !1, z.current = !1, ae.current = "sil", ge(y.current), v.current.reset(), me.current = !1;
1907
2044
  try {
1908
- W.current ? (b.current?.setActive(!1), b.current?.restart(), me(p.current)) : await I.renderSilOnly(), await M.current.speak(v, {
1909
- voiceId: G,
1910
- speakingRate: k?.speakingRate ?? a,
1911
- ttsEngineId: R
2045
+ X.current ? (N.current?.setActive(!1), N.current?.restart(), ge(y.current)) : await A.renderSilOnly(), await B.current.speak(T, {
2046
+ voiceId: Y,
2047
+ speakingRate: k?.speakingRate ?? c,
2048
+ ttsEngineId: C
1912
2049
  });
1913
- } catch (Y) {
1914
- throw $(Y instanceof Error ? Y.message : "TTS failed"), Y;
2050
+ } catch (ne) {
2051
+ throw $(ne instanceof Error ? ne.message : "TTS failed"), ne;
1915
2052
  }
1916
2053
  },
1917
2054
  stop: () => {
1918
- y.current += 1, F(), M.current.stop(), me(p.current), x.current = !1, H();
2055
+ h.current += 1, b(), K(), L.current = !1, z.current = !1, B.current.stop(), ge(y.current), me.current = !1, _e();
1919
2056
  },
1920
2057
  setTtsEngineId: (f) => {
1921
- M.current.setTtsEngineId(f), h.current && (h.current.ttsEngineId = f);
2058
+ B.current.setTtsEngineId(f), I.current && (I.current.ttsEngineId = f);
1922
2059
  },
1923
2060
  renderViseme: async (f, k) => {
1924
- const v = g.current, I = u.current;
1925
- if (!v || !I || !C.current)
2061
+ const T = g.current, A = u.current;
2062
+ if (!T || !A || !Q.current)
1926
2063
  throw new Error("AI twin is not ready");
1927
- await v.renderViseme(I, f, {
2064
+ await T.renderViseme(A, f, {
1928
2065
  from: k?.from,
1929
2066
  transitionDurationMs: k?.transitionDurationMs,
1930
2067
  gapMs: k?.gapMs,
1931
- onStatus: (R) => T.current?.(R)
2068
+ onStatus: (C) => O.current?.(C)
1932
2069
  });
1933
2070
  },
1934
- isReady: () => C.current,
1935
- getStatus: () => q
2071
+ isReady: () => Q.current,
2072
+ getStatus: () => Re
1936
2073
  }),
1937
2074
  [
1938
- K,
1939
- a,
1940
- F,
1941
- H,
2075
+ se,
2076
+ c,
2077
+ b,
2078
+ _e,
1942
2079
  $,
1943
- Q,
1944
- q
2080
+ ce,
2081
+ Re
1945
2082
  ]
1946
- ), /* @__PURE__ */ Tt("div", { className: c, style: { ...Sr, ...l }, children: [
1947
- /* @__PURE__ */ je(
2083
+ ), /* @__PURE__ */ Bt("div", { className: a, style: { ...Hr, ...l }, children: [
2084
+ /* @__PURE__ */ it(
1948
2085
  "canvas",
1949
2086
  {
1950
2087
  ref: u,
1951
- width: se.width,
1952
- height: se.height,
1953
- style: { ...Tr, ...d },
2088
+ width: V.width,
2089
+ height: V.height,
2090
+ style: { ...Wr, ...d },
1954
2091
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
1955
2092
  }
1956
2093
  ),
1957
- D && Ee ? /* @__PURE__ */ je("div", { style: vr, children: Ee }) : null
2094
+ F && De ? /* @__PURE__ */ it("div", { style: qr, children: De }) : null
1958
2095
  ] });
1959
2096
  });
1960
2097
  export {
1961
- br as AiTwin,
1962
- Le as AiTwinNotFoundError,
1963
- ce as DEFAULT_TTS_ENGINE_ID,
1964
- on as OCULUS_VISEME_IDS,
1965
- In as SPEAKING_RATE_MAX,
1966
- vn as SPEAKING_RATE_MIN,
1967
- pe as TTS_ENGINE_CARTESIA,
1968
- lt as TTS_ENGINE_GOOGLE,
1969
- qe as TTS_ENGINE_INWORLD,
1970
- Rr as VISEME_IDS,
1971
- An as VISEME_TEST_CARTESIA_VOICE_ID,
1972
- _t as VISEME_TEST_SPEAKING_RATE,
1973
- ht as VISEME_TEST_VOICE_ID,
1974
- Rn as createAvatarTtsLipsyncController,
1975
- Nt as fetchAiTwin,
1976
- Qe as fetchDevAuthToken,
1977
- cn as normalizeOculusViseme,
1978
- Sn as resolveVisemeAtTime,
1979
- Tn as resolveWordAtTime
2098
+ zr as AiTwin,
2099
+ Ke as AiTwinNotFoundError,
2100
+ pe as DEFAULT_TTS_ENGINE_ID,
2101
+ En as OCULUS_VISEME_IDS,
2102
+ Bn as SPEAKING_RATE_MAX,
2103
+ Un as SPEAKING_RATE_MIN,
2104
+ be as TTS_ENGINE_CARTESIA,
2105
+ kt as TTS_ENGINE_GOOGLE,
2106
+ Ze as TTS_ENGINE_INWORLD,
2107
+ Gr as VISEME_IDS,
2108
+ Nn as VISEME_TEST_CARTESIA_VOICE_ID,
2109
+ At as VISEME_TEST_SPEAKING_RATE,
2110
+ It as VISEME_TEST_VOICE_ID,
2111
+ Vn as createAvatarTtsLipsyncController,
2112
+ en as fetchAiTwin,
2113
+ ot as fetchDevAuthToken,
2114
+ kn as normalizeOculusViseme,
2115
+ vt as resolveVisemeAtTime,
2116
+ Pn as resolveWordAtTime
1980
2117
  };