@streamoji/aitwin 0.1.5 → 0.1.7

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