@streamoji/aitwin 0.4.4 → 0.4.6

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,41 +1,41 @@
1
1
  import { jsxs as Wn, jsx as Ir } from "react/jsx-runtime";
2
- import { forwardRef as Hn, useRef as H, useState as tt, useEffect as $e, useCallback as Ae, useMemo as Mr, useImperativeHandle as $n } from "react";
2
+ import { forwardRef as Hn, useRef as H, useState as Ze, useEffect as He, useCallback as xe, useMemo as Mr, useImperativeHandle as $n } from "react";
3
3
  import { PipecatClient as qn } from "@pipecat-ai/client-js";
4
4
  import { WebSocketTransport as Kn, DailyMediaManager as Gn, ProtobufFrameSerializer as zn } from "@pipecat-ai/websocket-transport";
5
- import { Filter as jn, GlProgram as Yn, Application as Xn, RendererType as Jn, Sprite as It, Texture as we, VideoSource as Qn, Rectangle as Zn } from "pixi.js";
5
+ import { Filter as jn, GlProgram as Yn, Application as Xn, RendererType as Jn, Sprite as xt, Texture as ge, VideoSource as Qn, Rectangle as Zn } from "pixi.js";
6
6
  const es = "https://aitwin.bubu.social", nn = {
7
7
  publicBase: es
8
- }, ts = "0.4.4", rs = {
8
+ }, ts = "0.4.6", rs = {
9
9
  version: ts
10
- }, ns = {}, kt = "https://ai.aitwin.me", ar = `${nn.publicBase}/custom-faces`, ss = `${nn.publicBase}/aitwin-workers/v${rs.version}/visemeDiffPreview.worker.js`;
10
+ }, ns = {}, St = "https://ai.aitwin.me", ar = `${nn.publicBase}/custom-faces`, ss = `${nn.publicBase}/aitwin-workers/v${rs.version}/visemeDiffPreview.worker.js`;
11
11
  function is(e) {
12
12
  if (e) return e;
13
13
  const t = typeof import.meta < "u" ? ns?.VITE_AITWIN_WORKER_URL : void 0;
14
14
  return t?.trim() ? t.trim() : ss;
15
15
  }
16
- const as = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", zt = 3e3, St = 16, Rr = 3e3, os = 4e3, cs = 0.85, us = 8, or = 400, sn = "eng_a7f2b9c1", cr = "eng_d4e8f3a2", ot = "eng_c9b1e6d4", nt = ot, an = /* @__PURE__ */ new Set([
16
+ const as = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", zt = 3e3, _t = 16, Rr = 3e3, os = 4e3, cs = 0.85, us = 8, or = 400, sn = "eng_a7f2b9c1", cr = "eng_d4e8f3a2", it = "eng_c9b1e6d4", tt = it, an = /* @__PURE__ */ new Set([
17
17
  cr,
18
- ot
18
+ it
19
19
  ]), on = {
20
20
  [sn]: "oculus_direct",
21
- [ot]: "oculus_direct",
21
+ [it]: "oculus_direct",
22
22
  [cr]: "inworld_word"
23
23
  }, Dr = {
24
24
  google: sn,
25
25
  inworld: cr,
26
- cartesia: ot
26
+ cartesia: it
27
27
  };
28
28
  function ls(e) {
29
29
  return on[e];
30
30
  }
31
31
  function fs(e) {
32
- return e === ot;
32
+ return e === it;
33
33
  }
34
34
  function ds(e) {
35
35
  if (e.ttsEngineId && e.ttsEngineId in on)
36
36
  return e.ttsEngineId;
37
37
  const t = e.tts?.toLowerCase();
38
- return t && t in Dr ? Dr[t] : nt;
38
+ return t && t in Dr ? Dr[t] : tt;
39
39
  }
40
40
  class Qt extends Error {
41
41
  constructor(t = "AI twin not found") {
@@ -81,7 +81,7 @@ async function jt() {
81
81
  throw new Error("getAuthToken returned no token");
82
82
  return r;
83
83
  }
84
- async function _s(e, t = kt) {
84
+ async function _s(e, t = St) {
85
85
  const r = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
86
86
  headers: { Authorization: `Bearer ${e}` }
87
87
  });
@@ -99,7 +99,7 @@ function vs(e) {
99
99
  r[n / 2] = Number.parseInt(t.slice(n, n + 2), 16);
100
100
  return r;
101
101
  }
102
- function Mt(e) {
102
+ function It(e) {
103
103
  return Uint8Array.from(e);
104
104
  }
105
105
  function Ss(e, t) {
@@ -110,7 +110,7 @@ async function bs(e, t) {
110
110
  if (!t) throw new Error("Asset key is required for encrypted assets");
111
111
  if (e.byteLength < 28)
112
112
  throw new Error("Encrypted payload too small");
113
- const r = new Uint8Array(e), n = Mt(r.subarray(0, 12)), s = Mt(r.subarray(12, 28)), i = Mt(r.subarray(28)), o = Mt(Ss(i, s)), a = await crypto.subtle.importKey(
113
+ const r = new Uint8Array(e), n = It(r.subarray(0, 12)), s = It(r.subarray(12, 28)), i = It(r.subarray(28)), o = It(Ss(i, s)), a = await crypto.subtle.importKey(
114
114
  "raw",
115
115
  vs(t),
116
116
  { name: "AES-GCM" },
@@ -125,18 +125,18 @@ async function bs(e, t) {
125
125
  }
126
126
  let Zt = null;
127
127
  const er = /* @__PURE__ */ new Set();
128
- function Rt(e) {
128
+ function Mt(e) {
129
129
  return e.includes("/custom-faces/");
130
130
  }
131
- function Ft(e) {
131
+ function Ct(e) {
132
132
  const t = e.binBase.trim().replace(/\/$/, ""), r = e.twinBase.trim().replace(/\/$/, "");
133
- if (!(e.encrypted || Rt(t) || Rt(r)))
133
+ if (!(e.encrypted || Mt(t) || Mt(r)))
134
134
  return { twinBase: r, binBase: t, encrypted: !1 };
135
- const s = Rt(t) ? t : Rt(r) ? r : t;
135
+ const s = Mt(t) ? t : Mt(r) ? r : t;
136
136
  return { twinBase: s, binBase: s, encrypted: !0 };
137
137
  }
138
- function ze(e) {
139
- return Ft(e).encrypted;
138
+ function Ge(e) {
139
+ return Ct(e).encrypted;
140
140
  }
141
141
  function Br(e, t = ar) {
142
142
  const r = `${t.replace(/\/$/, "")}/${e}`;
@@ -146,12 +146,12 @@ function ks(e, t) {
146
146
  return (e ?? t)?.trim() || void 0;
147
147
  }
148
148
  function Ts(e) {
149
- Zt = Ft(e);
149
+ Zt = Ct(e);
150
150
  for (const t of er) t();
151
151
  }
152
152
  function Es(e, t) {
153
153
  const r = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
154
- if (!r) return Ft(e);
154
+ if (!r) return Ct(e);
155
155
  const n = (s) => {
156
156
  try {
157
157
  return new URL(s, r).href.replace(/\/$/, "");
@@ -159,13 +159,13 @@ function Es(e, t) {
159
159
  return s;
160
160
  }
161
161
  };
162
- return Ft({
162
+ return Ct({
163
163
  twinBase: n(e.twinBase),
164
164
  binBase: n(e.binBase),
165
165
  encrypted: e.encrypted
166
166
  });
167
167
  }
168
- function je() {
168
+ function ze() {
169
169
  if (!Zt)
170
170
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
171
171
  return Zt;
@@ -173,28 +173,28 @@ function je() {
173
173
  function cn(e) {
174
174
  return er.add(e), () => er.delete(e);
175
175
  }
176
- function Lt() {
177
- const e = je();
178
- return ze(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
176
+ function Ft() {
177
+ const e = ze();
178
+ return Ge(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
179
179
  }
180
180
  function As() {
181
- const e = je();
182
- return ze(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
181
+ const e = ze();
182
+ return Ge(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
183
183
  }
184
184
  function un() {
185
- const e = je();
186
- return ze(e) ? e.binBase : e.twinBase;
185
+ const e = ze();
186
+ return Ge(e) ? e.binBase : e.twinBase;
187
187
  }
188
- function Tt() {
189
- return ze(je());
188
+ function bt() {
189
+ return Ge(ze());
190
190
  }
191
191
  function ln() {
192
- const e = je();
193
- return ze(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
192
+ const e = ze();
193
+ return Ge(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
194
194
  }
195
195
  function fn() {
196
- const e = je();
197
- return ze(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
196
+ const e = ze();
197
+ return Ge(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
198
198
  }
199
199
  function dn(e) {
200
200
  const t = e.split(/\r?\n/);
@@ -259,16 +259,16 @@ function Ds(e, t) {
259
259
  const s = Math.max(0, Math.min(1, (t - e.wtime) / n));
260
260
  return Math.min(r - 1, Math.floor(s * r));
261
261
  }
262
- function st(e, t) {
262
+ function rt(e, t) {
263
263
  const r = Math.max(0, Math.min(e.length - 1, t));
264
264
  return e[r] ?? "";
265
265
  }
266
266
  function ur(e, t) {
267
267
  const r = e.toLowerCase().replace(/[^a-z']/g, "");
268
- return !r || st(r, t) !== "w" || t > 0 && st(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
268
+ return !r || rt(r, t) !== "w" || t > 0 && rt(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
269
269
  }
270
270
  function Bs(e, t) {
271
- const r = e.toLowerCase(), n = st(r, t), s = r.slice(Math.max(0, t - 1), t + 2);
271
+ const r = e.toLowerCase(), n = rt(r, t), s = r.slice(Math.max(0, t - 1), t + 2);
272
272
  return n === "i" || n === "y" ? "I" : s.includes("ee") || n === "e" || r.includes("ea") ? "E" : "aa";
273
273
  }
274
274
  function Cs(e, t) {
@@ -278,7 +278,7 @@ function Cs(e, t) {
278
278
  );
279
279
  if (/oo|ou|uw/.test(n)) return "U";
280
280
  if (ur(r, t)) return "FF";
281
- const s = st(r, t);
281
+ const s = rt(r, t);
282
282
  return s === "u" || s === "w" ? "U" : "O";
283
283
  }
284
284
  function Fs(e, t) {
@@ -290,9 +290,9 @@ function Fs(e, t) {
290
290
  Math.max(0, t - 1),
291
291
  Math.min(r.length, t + 3)
292
292
  );
293
- return /wo|wh/.test(s) || st(r, t) === "o" ? "O" : "U";
293
+ return /wo|wh/.test(s) || rt(r, t) === "o" ? "O" : "U";
294
294
  }
295
- const Dt = {
295
+ const Rt = {
296
296
  d: "DD",
297
297
  t: "DD",
298
298
  n: "DD",
@@ -305,11 +305,11 @@ const Dt = {
305
305
  j: "CH"
306
306
  };
307
307
  function Ls(e, t) {
308
- const r = e.toLowerCase(), n = st(r, t);
309
- if (Dt[n]) return Dt[n];
308
+ const r = e.toLowerCase(), n = rt(r, t);
309
+ if (Rt[n]) return Rt[n];
310
310
  for (let s = 0; s < r.length; s++) {
311
311
  const i = r[s];
312
- if (Dt[i]) return Dt[i];
312
+ if (Rt[i]) return Rt[i];
313
313
  }
314
314
  return "DD";
315
315
  }
@@ -351,7 +351,7 @@ function hn(e) {
351
351
  function Us(e) {
352
352
  return pn(e).find((r) => r.viseme !== "sil") ?? null;
353
353
  }
354
- function qe(e) {
354
+ function $e(e) {
355
355
  const t = mn(e);
356
356
  return hn(e) ? t + or : t;
357
357
  }
@@ -480,7 +480,7 @@ function zs(e, t) {
480
480
  }
481
481
  function yn(e, t) {
482
482
  const r = [], n = [];
483
- let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t, m = !1, I = null, _ = 0, R = !1, w = !1, b = 0, L = null, B = null, G = null;
483
+ let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t, h = !1, M = null, _ = 0, D = !1, w = !1, b = 0, L = null, B = null, G = null;
484
484
  const C = () => ({
485
485
  visemes: [],
486
486
  words: [],
@@ -489,131 +489,131 @@ function yn(e, t) {
489
489
  w = !1, b = 0;
490
490
  }, P = () => {
491
491
  d != null && (clearTimeout(d), d = null);
492
- }, D = () => {
493
- for (const h of n) {
492
+ }, N = () => {
493
+ for (const m of n) {
494
494
  try {
495
- h.onended = null, h.stop(0);
495
+ m.onended = null, m.stop(0);
496
496
  } catch {
497
497
  }
498
498
  try {
499
- h.disconnect();
499
+ m.disconnect();
500
500
  } catch {
501
501
  }
502
502
  }
503
503
  n.length = 0;
504
- }, U = () => {
505
- for (const h of n)
506
- h.playbackRate.value = g;
507
- }, O = () => {
508
- if (!(m || !u || i || w || n.length > 0 || r.length > 0)) {
504
+ }, I = () => {
505
+ for (const m of n)
506
+ m.playbackRate.value = g;
507
+ }, te = () => {
508
+ if (!(h || !u || i || w || n.length > 0 || r.length > 0)) {
509
509
  if (a && s && f > 0) {
510
- const h = (s.currentTime - f) * 1e3;
511
- if (h < _) {
510
+ const m = (s.currentTime - f) * 1e3;
511
+ if (m < _) {
512
512
  P();
513
- const E = g > 0 ? (_ - h) / g : _ - h;
513
+ const T = g > 0 ? (_ - m) / g : _ - m;
514
514
  d = setTimeout(() => {
515
- m || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
516
- }, Math.max(0, E));
515
+ h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
516
+ }, Math.max(0, T));
517
517
  return;
518
518
  }
519
519
  }
520
520
  o = !1, P(), e.onSpeakingDone(), e.onNotify();
521
521
  }
522
- }, me = (h) => {
523
- const E = qe(h);
524
- if (E <= 0) {
522
+ }, V = (m) => {
523
+ const T = $e(m);
524
+ if (T <= 0) {
525
525
  e.onSpeakingDone(), e.onNotify();
526
526
  return;
527
527
  }
528
528
  o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), P();
529
- const M = g > 0 ? E / g : E;
529
+ const R = g > 0 ? T / g : T;
530
530
  d = setTimeout(() => {
531
- m || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
532
- }, M);
533
- }, X = (h, E, M, F) => {
534
- E.length !== 0 && (c = M, E.forEach((A) => {
531
+ h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
532
+ }, R);
533
+ }, J = (m, T, R, F) => {
534
+ T.length !== 0 && (c = R, T.forEach((A) => {
535
535
  const Y = String(A.word ?? "").trim();
536
536
  if (!Y) return;
537
537
  const Q = Math.round((A.start ?? 0) * 1e3), Z = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
538
- h.push({
538
+ m.push({
539
539
  word: Y,
540
540
  wtime: c + Q,
541
541
  wduration: Z,
542
- queueIndex: h.length,
542
+ queueIndex: m.length,
543
543
  gesture: A.gesture ?? null,
544
544
  emphasis: A.emphasis === !0
545
545
  });
546
546
  }));
547
- }, z = (h, E, M, F, A, $) => {
548
- M.length !== 0 && (c = F, M.forEach((Y) => {
547
+ }, j = (m, T, R, F, A, $) => {
548
+ R.length !== 0 && (c = F, R.forEach((Y) => {
549
549
  const Q = String(Y.symbol ?? Y.viseme ?? "").trim();
550
550
  if (!Q) return;
551
- const Z = Math.round((Y.start ?? 0) * 1e3), xe = Math.max(1, Math.round((Y.duration ?? 0) * 1e3)), be = c + Z, Fe = zs(E, be), ut = Fe ? Ds(Fe, be) : 0;
552
- let Ie;
553
- ls($) === "oculus_direct" ? (Ie = Is(Q), Ie === "U" && Fe && ur(Fe.word, ut) && (Ie = "FF")) : Ie = Os(
551
+ const Z = Math.round((Y.start ?? 0) * 1e3), be = Math.max(1, Math.round((Y.duration ?? 0) * 1e3)), ke = c + Z, Be = zs(T, ke), ot = Be ? Ds(Be, ke) : 0;
552
+ let Me;
553
+ ls($) === "oculus_direct" ? (Me = Is(Q), Me === "U" && Be && ur(Be.word, ot) && (Me = "FF")) : Me = Os(
554
554
  Q,
555
- Fe?.word ?? "",
556
- ut
557
- ), h.push({
558
- viseme: Ie,
555
+ Be?.word ?? "",
556
+ ot
557
+ ), m.push({
558
+ viseme: Me,
559
559
  weight: 1,
560
- vtime: be,
561
- vduration: xe
560
+ vtime: ke,
561
+ vduration: be
562
562
  });
563
563
  }), e.onNotify());
564
- }, J = (h, E, M, F, A, $, Y) => {
565
- X(E, F, A), z(
566
- h,
567
- E,
568
- M,
564
+ }, X = (m, T, R, F, A, $, Y) => {
565
+ J(T, F, A), j(
566
+ m,
567
+ T,
568
+ R,
569
569
  A,
570
570
  $,
571
571
  Y
572
572
  );
573
- }, ne = (h, E, M) => {
574
- G === h && h.visemes === E || (E.length = 0, M.length = 0, h.visemes = E, h.words = M, h.segmentOffsetMs = 0, G = h, c = 0, _ = 0);
575
- }, ee = async () => {
576
- const h = window.AudioContext || window.webkitAudioContext;
577
- return s || (s = new h()), s.state === "suspended" && await s.resume(), I || (I = s.createMediaStreamDestination()), s;
578
- }, ge = (h, E) => {
573
+ }, pe = (m, T, R) => {
574
+ G === m && m.visemes === T || (T.length = 0, R.length = 0, m.visemes = T, m.words = R, m.segmentOffsetMs = 0, G = m, c = 0, _ = 0);
575
+ }, re = async () => {
576
+ const m = window.AudioContext || window.webkitAudioContext;
577
+ return s || (s = new m()), s.state === "suspended" && await s.resume(), M || (M = s.createMediaStreamDestination()), s;
578
+ }, fe = (m, T) => {
579
579
  if (!s) return 0;
580
- const M = s, F = M.currentTime, A = F + 0.02;
581
- if (E.isFirstAudio) {
580
+ const R = s, F = R.currentTime, A = F + 0.02;
581
+ if (T.isFirstAudio) {
582
582
  f <= 0 && (f = A);
583
583
  const Y = (A - F) * 1e3;
584
584
  l = performance.now() + Y;
585
585
  }
586
- E.onBeforeStart?.(A);
587
- const $ = M.createBufferSource();
588
- return $.buffer = h, $.playbackRate.value = g, $.connect(M.destination), I && $.connect(I), n.push($), m ? (n.pop(), A) : (E.isFirstAudio && (o = !0, e.onSpeakingStart()), $.onended = () => {
586
+ T.onBeforeStart?.(A);
587
+ const $ = R.createBufferSource();
588
+ return $.buffer = m, $.playbackRate.value = g, $.connect(R.destination), M && $.connect(M), n.push($), h ? (n.pop(), A) : (T.isFirstAudio && (o = !0, e.onSpeakingStart()), $.onended = () => {
589
589
  const Y = n.indexOf($);
590
- Y >= 0 && n.splice(Y, 1), e.onNotify(), !m && (L && B ? oe(L, B) : O());
590
+ Y >= 0 && n.splice(Y, 1), e.onNotify(), !h && (L && B ? de(L, B) : te());
591
591
  }, $.start(A), A);
592
- }, oe = async (h, E) => {
593
- if (m || i || n.length > 0) return;
592
+ }, de = async (m, T) => {
593
+ if (h || i || n.length > 0) return;
594
594
  if (r.length === 0) {
595
- O();
595
+ te();
596
596
  return;
597
597
  }
598
598
  i = !0;
599
- let M = !1;
599
+ let R = !1;
600
600
  try {
601
- const F = await ee();
602
- if (m) return;
601
+ const F = await re();
602
+ if (h) return;
603
603
  const A = r[0];
604
604
  if (!A) return;
605
605
  const $ = !o;
606
- if (R && (e.shouldHoldForWarmup?.() ?? !1) && (w || $ && A.newStream) || w) {
607
- ne(A.utterance, h, E);
606
+ if (D && (e.shouldHoldForWarmup?.() ?? !1) && (w || $ && A.newStream) || w) {
607
+ pe(A.utterance, m, T);
608
608
  for (const Z of r) {
609
- if (m) return;
609
+ if (h) return;
610
610
  Z.audioBuffer || (Z.audioBuffer = await Lr(
611
611
  F,
612
612
  Z.audio,
613
613
  Z.sampleRate
614
- )), a = !0, w || (w = !0, b = 0, Z.newStream && Z.onNewStream?.()), Z.visemesQueued || (J(
615
- h,
616
- E,
614
+ )), a = !0, w || (w = !0, b = 0, Z.newStream && Z.onNewStream?.()), Z.visemesQueued || (X(
615
+ m,
616
+ T,
617
617
  Z.visemes,
618
618
  Z.words,
619
619
  b,
@@ -621,7 +621,7 @@ function yn(e, t) {
621
621
  S
622
622
  ), Z.visemesQueued = !0, b += Math.round(Z.audioBuffer.duration * 1e3), _ = Math.max(
623
623
  _,
624
- qe(h)
624
+ $e(m)
625
625
  ));
626
626
  }
627
627
  e.onNotify();
@@ -632,14 +632,14 @@ function yn(e, t) {
632
632
  F,
633
633
  Q.audio,
634
634
  Q.sampleRate
635
- )), m)) return;
636
- a = !0, P(), ne(Q.utterance, h, E), Q.visemesQueued = !1, Q.newStream && Q.onNewStream?.(), ge(Q.audioBuffer, {
635
+ )), h)) return;
636
+ a = !0, P(), pe(Q.utterance, m, T), Q.visemesQueued = !1, Q.newStream && Q.onNewStream?.(), fe(Q.audioBuffer, {
637
637
  isFirstAudio: !o,
638
638
  isFirstOfStream: !1,
639
639
  onBeforeStart: (Z) => {
640
- f = Z, c = 0, l = performance.now() + (Z - F.currentTime) * 1e3, J(
641
- h,
642
- E,
640
+ f = Z, c = 0, l = performance.now() + (Z - F.currentTime) * 1e3, X(
641
+ m,
642
+ T,
643
643
  Q.visemes,
644
644
  Q.words,
645
645
  0,
@@ -647,87 +647,87 @@ function yn(e, t) {
647
647
  S
648
648
  ), Q.visemesQueued = !0, Q.utterance.segmentOffsetMs = 0;
649
649
  }
650
- }), M = n.length > 0, _ = qe(h), e.onNotify();
650
+ }), R = n.length > 0, _ = $e(m), e.onNotify();
651
651
  } catch (F) {
652
652
  console.error("[avatarChunkPlayback] audio chunk failed:", F);
653
653
  } finally {
654
- if (i = !1, m) return;
654
+ if (i = !1, h) return;
655
655
  if (w) {
656
656
  r.some(
657
657
  (A) => !A.audioBuffer || !A.visemesQueued
658
- ) && oe(h, E);
658
+ ) && de(m, T);
659
659
  return;
660
660
  }
661
- !M && n.length === 0 && r.length > 0 ? oe(h, E) : n.length === 0 && r.length === 0 && O();
661
+ !R && n.length === 0 && r.length > 0 ? de(m, T) : n.length === 0 && r.length === 0 && te();
662
662
  }
663
663
  };
664
664
  return {
665
- setStreamTtsEngineId: (h) => {
666
- S = h;
665
+ setStreamTtsEngineId: (m) => {
666
+ S = m;
667
667
  },
668
- setPlaybackSpeed: (h) => {
669
- g = Math.max(0.1, Math.min(1, h)), U();
668
+ setPlaybackSpeed: (m) => {
669
+ g = Math.max(0.1, Math.min(1, m)), I();
670
670
  },
671
671
  getPlaybackSpeed: () => g,
672
- setLipsyncWarmupHoldEnabled: (h) => {
673
- R = h, h || k();
672
+ setLipsyncWarmupHoldEnabled: (m) => {
673
+ D = m, m || k();
674
674
  },
675
675
  isWarmingUp: () => w,
676
676
  releaseWarmupHold: () => {
677
677
  if (w) {
678
678
  w = !1, b = 0;
679
- for (const h of r)
680
- h.newStream = !1;
681
- L && B && oe(L, B), e.onNotify();
679
+ for (const m of r)
680
+ m.newStream = !1;
681
+ L && B && de(L, B), e.onNotify();
682
682
  }
683
683
  },
684
- resetForNewStream: (h) => {
685
- m = !1, u = !1, S = h, _ = 0;
684
+ resetForNewStream: (m) => {
685
+ h = !1, u = !1, S = m, _ = 0;
686
686
  },
687
687
  /** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
688
688
  resumeBotStream: () => {
689
- m = !1, u = !1;
689
+ h = !1, u = !1;
690
690
  },
691
691
  /** After interrupt — allow the next utterance to queue/play again. */
692
692
  clearAborted: () => {
693
- m = !1;
693
+ h = !1;
694
694
  },
695
695
  /** Call from a user gesture before bot audio (connect / unlock). */
696
696
  primeAudioContext: async () => {
697
- const h = window.AudioContext || window.webkitAudioContext;
698
- s || (s = new h()), s.state === "suspended" && await s.resume(), s && !I && (I = s.createMediaStreamDestination());
697
+ const m = window.AudioContext || window.webkitAudioContext;
698
+ s || (s = new m()), s.state === "suspended" && await s.resume(), s && !M && (M = s.createMediaStreamDestination());
699
699
  },
700
700
  stop: () => {
701
- m = !0, P(), D(), r.length = 0, i = !1, o = !1, a = !1, u = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
701
+ h = !0, P(), N(), r.length = 0, i = !1, o = !1, a = !1, u = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
702
702
  },
703
- markStreamComplete: (h) => {
704
- if (_ = Math.max(_, qe(h)), u = !0, !a && h.length > 0) {
705
- me(h);
703
+ markStreamComplete: (m) => {
704
+ if (_ = Math.max(_, $e(m)), u = !0, !a && m.length > 0) {
705
+ V(m);
706
706
  return;
707
707
  }
708
- O();
708
+ te();
709
709
  },
710
- playAudioChunk: async (h, E, M, F, A, $, Y) => {
711
- if (m) return;
712
- L = h, B = E;
713
- const Q = gn(Y?.sampleRate), Z = Y?.newStream === !0, xe = C();
714
- if (!M?.trim()) {
710
+ playAudioChunk: async (m, T, R, F, A, $, Y) => {
711
+ if (h) return;
712
+ L = m, B = T;
713
+ const Q = gn(Y?.sampleRate), Z = Y?.newStream === !0, be = C();
714
+ if (!R?.trim()) {
715
715
  if (F.length === 0 && A.length === 0) return;
716
- ne(xe, h, E), Z && Y?.onNewStream?.(), J(
717
- h,
718
- E,
716
+ pe(be, m, T), Z && Y?.onNewStream?.(), X(
717
+ m,
718
+ T,
719
719
  F,
720
720
  A,
721
721
  0,
722
722
  !0,
723
723
  S
724
- ), _ = qe(h), !o && _ > 0 && me(h), e.onNotify();
724
+ ), _ = $e(m), !o && _ > 0 && V(m), e.onNotify();
725
725
  return;
726
726
  }
727
727
  r.push({
728
- audio: M,
728
+ audio: R,
729
729
  audioBuffer: null,
730
- utterance: xe,
730
+ utterance: be,
731
731
  visemes: F,
732
732
  words: A,
733
733
  isNewSegment: $,
@@ -735,45 +735,45 @@ function yn(e, t) {
735
735
  newStream: Z,
736
736
  onNewStream: Y?.onNewStream,
737
737
  visemesQueued: !1
738
- }), await oe(h, E);
738
+ }), await de(m, T);
739
739
  },
740
- queueTimingsOnly: (h, E, M, F, A) => {
741
- if (m) return;
740
+ queueTimingsOnly: (m, T, R, F, A) => {
741
+ if (h) return;
742
742
  const $ = C();
743
- ne($, h, E), J(
744
- h,
745
- E,
746
- M,
743
+ pe($, m, T), X(
744
+ m,
745
+ T,
746
+ R,
747
747
  F,
748
748
  0,
749
749
  !0,
750
750
  S
751
- ), $.segmentOffsetMs = 0, _ = qe(h);
751
+ ), $.segmentOffsetMs = 0, _ = $e(m);
752
752
  },
753
753
  getPlaybackElapsedMs: () => a && s && f > 0 ? Math.max(
754
754
  0,
755
755
  (s.currentTime - f) * 1e3
756
756
  ) : o ? Math.max(0, (performance.now() - l) * g) : 0,
757
757
  isSpeaking: () => o ? !0 : !a || !s || f <= 0 ? !1 : (s.currentTime - f) * 1e3 < _,
758
- getVoiceStream: () => I ? I.stream : null,
758
+ getVoiceStream: () => M ? M.stream : null,
759
759
  getPlaybackStartPerf: () => l,
760
760
  /** User spoke over the bot — drop in-flight chunks until the next utterance. */
761
761
  bargeIn: () => {
762
- m = !0, u = !1, P(), D(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
762
+ h = !0, u = !1, P(), N(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
763
763
  },
764
764
  interrupt: () => {
765
- m = !0, u = !1, P(), D(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
765
+ h = !0, u = !1, P(), N(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
766
766
  }
767
767
  };
768
768
  }
769
- function Vt(e, t) {
769
+ function Ut(e, t) {
770
770
  let r = null;
771
771
  for (const n of e)
772
772
  t < n.vtime || t >= n.vtime + n.vduration || (!r || n.vtime >= r.vtime) && (r = n);
773
773
  return r ? r.viseme : "sil";
774
774
  }
775
775
  function _n(e, t, r = 120) {
776
- const n = Vt(e, t);
776
+ const n = Ut(e, t);
777
777
  if (n !== "sil") return n;
778
778
  let s = null;
779
779
  for (const i of e) {
@@ -807,36 +807,36 @@ function Ys(e, t) {
807
807
  return null;
808
808
  }
809
809
  }
810
- const fr = 0.5, dr = 1.5, vn = "Olivia", Sn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Wt = 0.85;
811
- function Or(e, t = kt, r = {}) {
810
+ const fr = 0.5, dr = 1.5, vn = "Olivia", Sn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Vt = 0.85;
811
+ function Or(e, t = St, r = {}) {
812
812
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], o = [], a = [];
813
- let u = "", l = "neutral", f = "", c = nt;
813
+ let u = "", l = "neutral", f = "", c = tt;
814
814
  const d = /* @__PURE__ */ new Set();
815
815
  let g = 0, S = null;
816
- const m = () => d.forEach((C) => C());
817
- let I = () => !1;
816
+ const h = () => d.forEach((C) => C());
817
+ let M = () => !1;
818
818
  const _ = yn(
819
819
  {
820
820
  onSpeakingStart: () => e("speaking"),
821
821
  onSpeakingDone: () => e("done"),
822
- onNotify: m,
823
- shouldHoldForWarmup: () => I()
822
+ onNotify: h,
823
+ shouldHoldForWarmup: () => M()
824
824
  },
825
- nt
826
- ), R = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
825
+ tt
826
+ ), D = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
827
827
  if (!r.onLipsyncDebug) return;
828
- const P = R(), D = s;
828
+ const P = D(), N = s;
829
829
  r.onLipsyncDebug({
830
830
  event: C,
831
831
  spokenText: k,
832
832
  mood: l,
833
833
  playbackAnchorPerf: _.getPlaybackStartPerf(),
834
834
  playbackElapsedMs: P,
835
- queueLength: D.length,
836
- activeViseme: Vt(D, P),
837
- segments: a.map((U) => ({
838
- ...U,
839
- visemes: [...U.visemes]
835
+ queueLength: N.length,
836
+ activeViseme: Ut(N, P),
837
+ segments: a.map((I) => ({
838
+ ...I,
839
+ visemes: [...I.visemes]
840
840
  }))
841
841
  });
842
842
  }, b = (C, k) => {
@@ -845,31 +845,31 @@ function Or(e, t = kt, r = {}) {
845
845
  const P = S;
846
846
  S = null, P && w(P.event, P.spokenText);
847
847
  })));
848
- }, L = (C, k, P, D, U) => {
848
+ }, L = (C, k, P, N, I) => {
849
849
  if (!r.onLipsyncDebug) return;
850
- const O = s.slice(k), me = P.filter(
851
- (X) => String(X.symbol ?? X.viseme ?? "").trim()
850
+ const te = s.slice(k), V = P.filter(
851
+ (J) => String(J.symbol ?? J.viseme ?? "").trim()
852
852
  );
853
853
  a.push({
854
854
  spokenText: C,
855
- audioOffsetMs: O[0]?.vtime ?? 0,
856
- isNewSegment: D,
857
- chunkDurationMs: U,
855
+ audioOffsetMs: te[0]?.vtime ?? 0,
856
+ isNewSegment: N,
857
+ chunkDurationMs: I,
858
858
  receivedAtMs: performance.now(),
859
- visemes: O.map((X, z) => {
860
- const J = me[z];
859
+ visemes: te.map((J, j) => {
860
+ const X = V[j];
861
861
  return {
862
- rawSymbol: String(J?.symbol ?? J?.viseme ?? X.viseme).trim(),
863
- viseme: X.viseme,
864
- startSec: Number(J?.start ?? 0),
865
- durationSec: Number(J?.duration ?? 0),
866
- vtimeMs: X.vtime,
867
- vdurationMs: X.vduration
862
+ rawSymbol: String(X?.symbol ?? X?.viseme ?? J.viseme).trim(),
863
+ viseme: J.viseme,
864
+ startSec: Number(X?.start ?? 0),
865
+ durationSec: Number(X?.duration ?? 0),
866
+ vtimeMs: J.vtime,
867
+ vdurationMs: J.vduration
868
868
  };
869
869
  })
870
870
  });
871
871
  }, B = () => {
872
- _.stop(), s.length = 0, i.length = 0, o.length = 0, l = "neutral", a.length = 0, u = "", e("idle"), b("reset"), m();
872
+ _.stop(), s.length = 0, i.length = 0, o.length = 0, l = "neutral", a.length = 0, u = "", e("idle"), b("reset"), h();
873
873
  };
874
874
  return {
875
875
  setDeveloperToken: (C) => {
@@ -884,77 +884,77 @@ function Or(e, t = kt, r = {}) {
884
884
  const P = f.trim();
885
885
  if (!P)
886
886
  throw new Error("Developer token required for avatar_ttsWithPoses");
887
- const D = k?.ttsEngineId ?? c ?? nt;
888
- _.resetForNewStream(D), _.setStreamTtsEngineId(D);
889
- const U = k?.voiceId ?? vn, O = k?.speakingRate ?? Wt, me = Math.max(
887
+ const N = k?.ttsEngineId ?? c ?? tt;
888
+ _.resetForNewStream(N), _.setStreamTtsEngineId(N);
889
+ const I = k?.voiceId ?? vn, te = k?.speakingRate ?? Vt, V = Math.max(
890
890
  fr,
891
- Math.min(dr, O)
892
- ), X = {
891
+ Math.min(dr, te)
892
+ ), J = {
893
893
  user_query: C,
894
- ttsEngineId: D,
895
- speakingRate: me,
894
+ ttsEngineId: N,
895
+ speakingRate: V,
896
896
  tenant: "aiTwin"
897
897
  };
898
- an.has(D) && (X.voice_id = U);
898
+ an.has(N) && (J.voice_id = I);
899
899
  try {
900
- const z = await fetch(n, {
900
+ const j = await fetch(n, {
901
901
  method: "POST",
902
902
  headers: {
903
903
  "Content-Type": "application/json",
904
904
  Authorization: `Bearer ${P}`
905
905
  },
906
- body: JSON.stringify(X)
906
+ body: JSON.stringify(J)
907
907
  });
908
- if (!z.ok)
909
- throw new Error(`avatar_ttsWithPoses failed (${z.status})`);
910
- const J = z.body;
911
- if (!J) throw new Error("No response body");
912
- const ne = J.getReader(), ee = new TextDecoder();
913
- let ge = "", oe = !0;
914
- const le = async (v) => {
915
- const T = dn(v);
916
- if (T) {
917
- if (T.event === "audio") {
918
- const h = T.data.chunk, E = T.data.visemes ?? [], M = T.data.words ?? [], F = T.data.is_new_segment ?? !1, A = T.data.sample_rate, $ = s.length;
919
- if (h) {
920
- const Y = oe;
921
- oe = !1, await _.playAudioChunk(
908
+ if (!j.ok)
909
+ throw new Error(`avatar_ttsWithPoses failed (${j.status})`);
910
+ const X = j.body;
911
+ if (!X) throw new Error("No response body");
912
+ const pe = X.getReader(), re = new TextDecoder();
913
+ let fe = "", de = !0;
914
+ const ue = async (v) => {
915
+ const E = dn(v);
916
+ if (E) {
917
+ if (E.event === "audio") {
918
+ const m = E.data.chunk, T = E.data.visemes ?? [], R = E.data.words ?? [], F = E.data.is_new_segment ?? !1, A = E.data.sample_rate, $ = s.length;
919
+ if (m) {
920
+ const Y = de;
921
+ de = !1, await _.playAudioChunk(
922
922
  s,
923
923
  i,
924
- h,
925
- E,
926
- M,
924
+ m,
925
+ T,
926
+ R,
927
927
  F,
928
928
  { sampleRate: A, newStream: Y }
929
929
  ), L(
930
930
  C,
931
931
  $,
932
- E,
932
+ T,
933
933
  F,
934
- Ys(h, A)
934
+ Ys(m, A)
935
935
  ), b("audio_chunk", C);
936
- } else (E.length > 0 || M.length > 0) && (_.queueTimingsOnly(
936
+ } else (T.length > 0 || R.length > 0) && (_.queueTimingsOnly(
937
937
  s,
938
938
  i,
939
- E,
940
- M,
939
+ T,
940
+ R,
941
941
  F
942
942
  ), L(
943
943
  C,
944
944
  $,
945
- E,
945
+ T,
946
946
  F,
947
947
  null
948
948
  ), b("audio_chunk", C));
949
- } else if (T.event === "metadata") {
950
- const h = T.data.mood;
951
- typeof h == "string" && h.trim() && (l = h.trim());
952
- const E = T.data.sentence_emotions;
953
- if (Array.isArray(E)) {
949
+ } else if (E.event === "metadata") {
950
+ const m = E.data.mood;
951
+ typeof m == "string" && m.trim() && (l = m.trim());
952
+ const T = E.data.sentence_emotions;
953
+ if (Array.isArray(T)) {
954
954
  o.length = 0;
955
- for (const M of E) {
956
- if (!M || typeof M != "object") continue;
957
- const F = M;
955
+ for (const R of T) {
956
+ if (!R || typeof R != "object") continue;
957
+ const F = R;
958
958
  o.push({
959
959
  sentence_index: Number(F.sentence_index ?? 0),
960
960
  text: String(F.text ?? ""),
@@ -965,28 +965,28 @@ function Or(e, t = kt, r = {}) {
965
965
  });
966
966
  }
967
967
  }
968
- m(), b("metadata", C);
969
- } else if (T.event === "error")
968
+ h(), b("metadata", C);
969
+ } else if (E.event === "error")
970
970
  throw new Error(
971
- String(T.data.message ?? "avatar_ttsWithPoses stream error")
971
+ String(E.data.message ?? "avatar_ttsWithPoses stream error")
972
972
  );
973
973
  }
974
974
  };
975
975
  for (; ; ) {
976
- const { done: v, value: T } = await ne.read();
977
- T && (ge += ee.decode(T, { stream: !0 }));
978
- const h = ge.split(`
976
+ const { done: v, value: E } = await pe.read();
977
+ E && (fe += re.decode(E, { stream: !0 }));
978
+ const m = fe.split(`
979
979
 
980
980
  `);
981
- ge = h.pop() ?? "";
982
- for (const E of h) await le(E);
981
+ fe = m.pop() ?? "";
982
+ for (const T of m) await ue(T);
983
983
  if (v) {
984
- ge.trim() && await le(ge.trim()), _.markStreamComplete(s), b("bot_stopped", C);
984
+ fe.trim() && await ue(fe.trim()), _.markStreamComplete(s), b("bot_stopped", C);
985
985
  break;
986
986
  }
987
987
  }
988
- } catch (z) {
989
- throw console.error("[avatarTtsLipsync]", z), B(), e("error"), z;
988
+ } catch (j) {
989
+ throw console.error("[avatarTtsLipsync]", j), B(), e("error"), j;
990
990
  }
991
991
  },
992
992
  stop: B,
@@ -999,7 +999,7 @@ function Or(e, t = kt, r = {}) {
999
999
  isWarmingUp: () => _.isWarmingUp(),
1000
1000
  releaseWarmupHold: () => _.releaseWarmupHold(),
1001
1001
  setLipsyncWarmupHold: (C, k) => {
1002
- k && (I = k), _.setLipsyncWarmupHoldEnabled(C);
1002
+ k && (M = k), _.setLipsyncWarmupHoldEnabled(C);
1003
1003
  },
1004
1004
  getVoiceStream: () => _.getVoiceStream(),
1005
1005
  setPlaybackSpeed: (C) => {
@@ -1053,13 +1053,13 @@ function ti(e) {
1053
1053
  throw new Error(
1054
1054
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1055
1055
  );
1056
- const r = e.apiBase ?? kt, n = new URL(`${ei(r)}/ws/voice`);
1056
+ const r = e.apiBase ?? St, n = new URL(`${ei(r)}/ws/voice`);
1057
1057
  n.searchParams.set("authToken", t), n.searchParams.set("tenant", "aiTwin");
1058
1058
  const s = e.voiceId?.trim();
1059
1059
  s && Zs(s) && n.searchParams.set("voiceId", s);
1060
1060
  const i = e.personaId?.trim();
1061
1061
  i && n.searchParams.set("personaId", i);
1062
- const o = e.speakingRate ?? Wt;
1062
+ const o = e.speakingRate ?? Vt;
1063
1063
  return n.searchParams.set(
1064
1064
  "speaking_rate",
1065
1065
  String(Math.max(fr, Math.min(dr, o)))
@@ -1095,57 +1095,59 @@ function ni(e) {
1095
1095
  }
1096
1096
  function si(e, t = {}) {
1097
1097
  const r = [], n = [], s = [], i = [];
1098
- let o = "", a = "neutral", u = ot, l = !1, f = null, c = null, d = { ...t }, g = 0, S = null;
1099
- const m = /* @__PURE__ */ new Set(), I = [];
1100
- let _ = !1, R = null, w = !0, b = "default";
1098
+ let o = "", a = "neutral", u = it, l = !1, f = null, c = null, d = { ...t }, g = 0, S = null;
1099
+ const h = /* @__PURE__ */ new Set(), M = [];
1100
+ let _ = !1, D = null, w = !0, b = "default";
1101
1101
  const L = /* @__PURE__ */ new Set();
1102
- let B = null, G = 0, C = !1, k = null;
1103
- const P = () => {
1102
+ let B = null, G = 0, C = !1, k = null, P = !1;
1103
+ const N = () => {
1104
1104
  k != null && (clearTimeout(k), k = null);
1105
- }, D = () => m.forEach((p) => p());
1106
- let U = () => !1;
1107
- const O = yn(
1105
+ }, I = () => h.forEach((p) => p());
1106
+ let te = () => !1;
1107
+ const V = yn(
1108
1108
  {
1109
1109
  onSpeakingStart: () => e("speaking"),
1110
- onSpeakingDone: () => e("done"),
1111
- onNotify: D,
1112
- shouldHoldForWarmup: () => U()
1110
+ onSpeakingDone: () => {
1111
+ P = !1, e("done");
1112
+ },
1113
+ onNotify: I,
1114
+ shouldHoldForWarmup: () => te()
1113
1115
  },
1114
1116
  u
1115
- ), me = () => {
1116
- if (R) return R;
1117
+ ), J = () => {
1118
+ if (D) return D;
1117
1119
  const p = new MessageChannel();
1118
1120
  return p.port1.onmessage = () => {
1119
- const x = I.shift();
1120
- x !== void 0 && Q(x), I.length > 0 ? p.port2.postMessage(null) : _ = !1;
1121
- }, R = p, p;
1122
- }, X = (p) => {
1123
- I.push(p), !_ && (_ = !0, me().port2.postMessage(null));
1124
- }, z = () => O.getPlaybackElapsedMs(), J = (p, x = o) => {
1121
+ const x = M.shift();
1122
+ x !== void 0 && Z(x), M.length > 0 ? p.port2.postMessage(null) : _ = !1;
1123
+ }, D = p, p;
1124
+ }, j = (p) => {
1125
+ M.push(p), !_ && (_ = !0, J().port2.postMessage(null));
1126
+ }, X = () => V.getPlaybackElapsedMs(), pe = (p, x = o) => {
1125
1127
  if (!d.onLipsyncDebug) return;
1126
- const j = z(), ie = r;
1128
+ const z = X(), ne = r;
1127
1129
  d.onLipsyncDebug({
1128
1130
  event: p,
1129
1131
  spokenText: x,
1130
1132
  mood: a,
1131
- playbackAnchorPerf: O.getPlaybackStartPerf(),
1132
- playbackElapsedMs: j,
1133
- queueLength: ie.length,
1134
- activeViseme: Vt(ie, j),
1135
- segments: i.map((he) => ({
1136
- ...he,
1137
- visemes: [...he.visemes]
1133
+ playbackAnchorPerf: V.getPlaybackStartPerf(),
1134
+ playbackElapsedMs: z,
1135
+ queueLength: ne.length,
1136
+ activeViseme: Ut(ne, z),
1137
+ segments: i.map((ce) => ({
1138
+ ...ce,
1139
+ visemes: [...ce.visemes]
1138
1140
  }))
1139
1141
  });
1140
- }, ne = (p, x) => {
1142
+ }, re = (p, x) => {
1141
1143
  d.onLipsyncDebug && (S = { event: p, spokenText: x }, g === 0 && (g = requestAnimationFrame(() => {
1142
1144
  g = 0;
1143
- const j = S;
1144
- S = null, j && J(j.event, j.spokenText);
1145
+ const z = S;
1146
+ S = null, z && pe(z.event, z.spokenText);
1145
1147
  })));
1146
- }, ee = () => {
1147
- w = !0, L.clear(), O.clearAborted();
1148
- }, ge = () => {
1148
+ }, fe = () => {
1149
+ w = !0, L.clear(), V.clearAborted();
1150
+ }, de = () => {
1149
1151
  const p = ni(f);
1150
1152
  if (p) {
1151
1153
  b = `bot-${Date.now()}`, p.interruptedTrackIds = { [b]: !0 };
@@ -1159,223 +1161,225 @@ function si(e, t = {}) {
1159
1161
  x?.interrupt?.();
1160
1162
  } catch {
1161
1163
  }
1162
- }, oe = (p) => {
1164
+ }, ue = (p) => {
1165
+ if (P && V.isSpeaking())
1166
+ return !0;
1163
1167
  const x = p.context_id?.trim();
1164
1168
  return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" || Xt(p));
1165
- }, le = (p) => {
1166
- w = !1;
1169
+ }, v = (p) => {
1170
+ w = !1, P = !1;
1167
1171
  const x = p.context_id?.trim();
1168
- x && L.add(x), P(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, G += 1, ge(), O.bargeIn(), v(), e("idle"), ne("interrupt"), D();
1169
- }, v = () => {
1172
+ x && L.add(x), N(), C = !1, M.length = 0, _ = !1, B?.abort(), B = null, G += 1, de(), V.bargeIn(), E(), e("idle"), re("interrupt"), I();
1173
+ }, E = () => {
1170
1174
  r.length = 0, n.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
1175
+ }, m = () => {
1176
+ V.stop(), E(), re("reset"), I();
1171
1177
  }, T = () => {
1172
- O.stop(), v(), ne("reset"), D();
1173
- }, h = () => {
1174
- T(), e("idle"), D();
1175
- }, E = (p, x) => {
1178
+ m(), e("idle"), I();
1179
+ }, R = (p, x) => {
1176
1180
  typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), Array.isArray(p.sentence_emotions) && p.sentence_emotions.length > 0 && (x && (s.length = 0), s.push(
1177
1181
  ...Yt(p.sentence_emotions, a)
1178
1182
  ));
1179
- }, M = (p) => {
1180
- if (oe({ ...p, type: "avatar_metadata" }))
1183
+ }, F = (p) => {
1184
+ if (ue({ ...p, type: "avatar_metadata" }))
1181
1185
  return;
1182
- ee(), C = !0;
1186
+ fe(), C = !0;
1183
1187
  const x = String(p.spoken_text ?? p.text ?? "").trim();
1184
- x && (o = x), O.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
1188
+ x && (o = x), V.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
1185
1189
  ...Yt(p.sentence_emotions, a)
1186
- ), Array.isArray(p.gestures) && p.gestures, ne("metadata", x), D();
1187
- }, F = (p, x, j, ie) => {
1190
+ ), Array.isArray(p.gestures) && p.gestures, re("metadata", x), I();
1191
+ }, A = (p, x, z, ne) => {
1188
1192
  if (!d.onLipsyncDebug) return;
1189
- const he = r.slice(j), _e = ie.filter(
1190
- (ce) => String(ce.symbol ?? ce.viseme ?? "").trim()
1193
+ const ce = r.slice(z), Te = ne.filter(
1194
+ (me) => String(me.symbol ?? me.viseme ?? "").trim()
1191
1195
  );
1192
1196
  i.push({
1193
1197
  spokenText: x,
1194
- audioOffsetMs: he[0]?.vtime ?? 0,
1198
+ audioOffsetMs: ce[0]?.vtime ?? 0,
1195
1199
  isNewSegment: !!p.is_new_segment,
1196
1200
  chunkDurationMs: p.chunk_duration_ms != null ? Number(p.chunk_duration_ms) : null,
1197
1201
  receivedAtMs: performance.now(),
1198
- visemes: he.map((ce, Me) => {
1199
- const fe = _e[Me];
1202
+ visemes: ce.map((me, he) => {
1203
+ const _e = Te[he];
1200
1204
  return {
1201
- rawSymbol: String(fe?.symbol ?? fe?.viseme ?? ce.viseme).trim(),
1202
- viseme: ce.viseme,
1203
- startSec: Number(fe?.start ?? 0),
1204
- durationSec: Number(fe?.duration ?? 0),
1205
- vtimeMs: ce.vtime,
1206
- vdurationMs: ce.vduration
1205
+ rawSymbol: String(_e?.symbol ?? _e?.viseme ?? me.viseme).trim(),
1206
+ viseme: me.viseme,
1207
+ startSec: Number(_e?.start ?? 0),
1208
+ durationSec: Number(_e?.duration ?? 0),
1209
+ vtimeMs: me.vtime,
1210
+ vdurationMs: me.vduration
1207
1211
  };
1208
1212
  })
1209
1213
  });
1210
- }, A = (p) => {
1211
- if (oe(p)) return;
1212
- P(), Xt(p) && ee();
1213
- const x = String(p.spoken_text ?? p.text ?? "").trim(), j = Xt(p), ie = p.visemes ?? [], he = p.words ?? [], _e = String(p.chunk ?? "").trim(), ce = C;
1214
- ce && (C = !1), x && (o = x), E(p, j), ce ? O.resetForNewStream(u) : j && O.resumeBotStream();
1215
- const Me = r.length;
1216
- O.playAudioChunk(
1214
+ }, $ = (p) => {
1215
+ if (ue(p)) return;
1216
+ N(), Xt(p) && fe();
1217
+ const x = String(p.spoken_text ?? p.text ?? "").trim(), z = Xt(p), ne = p.visemes ?? [], ce = p.words ?? [], Te = String(p.chunk ?? "").trim(), me = C;
1218
+ me && (C = !1), x && (o = x), R(p, z), me ? V.resetForNewStream(u) : z && V.resumeBotStream();
1219
+ const he = r.length;
1220
+ V.playAudioChunk(
1217
1221
  r,
1218
1222
  n,
1219
- _e,
1220
- ie,
1221
- he,
1222
- j,
1223
+ Te,
1224
+ ne,
1225
+ ce,
1226
+ z,
1223
1227
  {
1224
1228
  sampleRate: p.sample_rate,
1225
- newStream: ce,
1229
+ newStream: me,
1226
1230
  onNewStream: () => {
1227
1231
  i.length = 0;
1228
1232
  }
1229
1233
  }
1230
1234
  ).then(() => {
1231
- F(p, x, Me, ie), ne("audio_chunk", x);
1235
+ A(p, x, he, ne), re("audio_chunk", x);
1232
1236
  });
1233
- }, $ = (p) => {
1234
- if (oe(p)) return;
1235
- (p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) && ee(), console.warn(
1237
+ }, Y = (p) => {
1238
+ if (ue(p)) return;
1239
+ (p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) && fe(), console.warn(
1236
1240
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
1237
1241
  );
1238
1242
  const x = String(p.spoken_text ?? p.text ?? "").trim();
1239
- x && (o = x), E(p, !!p.is_new_segment);
1240
- const j = r.length;
1241
- O.queueTimingsOnly(
1243
+ x && (o = x), R(p, !!p.is_new_segment);
1244
+ const z = r.length;
1245
+ V.queueTimingsOnly(
1242
1246
  r,
1243
1247
  n,
1244
1248
  p.visemes ?? [],
1245
1249
  p.words ?? [],
1246
1250
  !!p.is_new_segment
1247
- ), F(
1251
+ ), A(
1248
1252
  p,
1249
1253
  x,
1250
- j,
1254
+ z,
1251
1255
  p.visemes ?? []
1252
- ), ne("lipsync", x), D();
1253
- }, Y = async (p) => {
1256
+ ), re("lipsync", x), I();
1257
+ }, Q = async (p) => {
1254
1258
  const x = String(p.text ?? "").trim();
1255
1259
  if (!x) return;
1256
- const j = d.authToken?.trim();
1257
- if (!j) {
1260
+ const z = d.authToken?.trim();
1261
+ if (!z) {
1258
1262
  console.error("[realtimeVoice] avatar_speak requires authToken");
1259
1263
  return;
1260
1264
  }
1261
1265
  B?.abort();
1262
- const ie = new AbortController();
1263
- B = ie;
1264
- const he = ++G;
1265
- ee(), O.resetForNewStream(u), o = x;
1266
- const ce = `${(d.apiBase ?? kt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Me = d.voiceId?.trim() || Sn, fe = d.speakingRate ?? Wt, Ve = Math.max(
1266
+ const ne = new AbortController();
1267
+ B = ne;
1268
+ const ce = ++G;
1269
+ fe(), V.resetForNewStream(u), o = x;
1270
+ const me = `${(d.apiBase ?? St).replace(/\/$/, "")}/avatar_ttsWithPoses`, he = d.voiceId?.trim() || Sn, _e = d.speakingRate ?? Vt, ct = Math.max(
1267
1271
  fr,
1268
- Math.min(dr, fe)
1269
- ), Ye = {
1272
+ Math.min(dr, _e)
1273
+ ), Ce = {
1270
1274
  user_query: x,
1271
1275
  ttsEngineId: u,
1272
- speakingRate: Ve,
1276
+ speakingRate: ct,
1273
1277
  tenant: "aiTwin"
1274
1278
  };
1275
- an.has(u) && (Ye.voice_id = Me);
1279
+ an.has(u) && (Ce.voice_id = he);
1276
1280
  try {
1277
- const ve = await fetch(ce, {
1281
+ const Oe = await fetch(me, {
1278
1282
  method: "POST",
1279
1283
  headers: {
1280
1284
  "Content-Type": "application/json",
1281
- Authorization: `Bearer ${j}`
1285
+ Authorization: `Bearer ${z}`
1282
1286
  },
1283
- body: JSON.stringify(Ye),
1284
- signal: ie.signal
1287
+ body: JSON.stringify(Ce),
1288
+ signal: ne.signal
1285
1289
  });
1286
- if (!ve.ok)
1287
- throw new Error(`avatar_ttsWithPoses failed (${ve.status})`);
1288
- const lt = ve.body;
1289
- if (!lt) throw new Error("No response body");
1290
- const Xe = lt.getReader(), ft = new TextDecoder();
1291
- let Ne = "", ue = !0;
1292
- const dt = async (Je) => {
1293
- if (he !== G || ie.signal.aborted || !w)
1290
+ if (!Oe.ok)
1291
+ throw new Error(`avatar_ttsWithPoses failed (${Oe.status})`);
1292
+ const Ue = Oe.body;
1293
+ if (!Ue) throw new Error("No response body");
1294
+ const ut = Ue.getReader(), kt = new TextDecoder();
1295
+ let ie = "", lt = !0;
1296
+ const ft = async (je) => {
1297
+ if (ce !== G || ne.signal.aborted || !w)
1294
1298
  return;
1295
- const de = dn(Je);
1296
- if (de) {
1297
- if (de.event === "audio") {
1298
- const pe = de.data.chunk, ke = de.data.visemes ?? [], Re = de.data.words ?? [], mt = de.data.is_new_segment ?? !1, De = de.data.sample_rate;
1299
- if (pe) {
1300
- const We = ue;
1301
- ue = !1, await O.playAudioChunk(
1299
+ const le = dn(je);
1300
+ if (le) {
1301
+ if (le.event === "audio") {
1302
+ const ve = le.data.chunk, we = le.data.visemes ?? [], Ye = le.data.words ?? [], Ee = le.data.is_new_segment ?? !1, Ve = le.data.sample_rate;
1303
+ if (ve) {
1304
+ const ee = lt;
1305
+ lt = !1, await V.playAudioChunk(
1302
1306
  r,
1303
1307
  n,
1304
- pe,
1305
- ke,
1306
- Re,
1307
- mt,
1308
- { sampleRate: De, newStream: We }
1308
+ ve,
1309
+ we,
1310
+ Ye,
1311
+ Ee,
1312
+ { sampleRate: Ve, newStream: ee }
1309
1313
  );
1310
- } else (ke.length > 0 || Re.length > 0) && O.queueTimingsOnly(
1314
+ } else (we.length > 0 || Ye.length > 0) && V.queueTimingsOnly(
1311
1315
  r,
1312
1316
  n,
1313
- ke,
1314
- Re,
1315
- mt
1317
+ we,
1318
+ Ye,
1319
+ Ee
1316
1320
  );
1317
- } else if (de.event === "metadata") {
1318
- const pe = de.data.mood;
1319
- typeof pe == "string" && pe.trim() && (a = pe.trim());
1320
- const ke = de.data.sentence_emotions;
1321
- Array.isArray(ke) && (s.length = 0, s.push(
1322
- ...Yt(ke, a)
1323
- )), D();
1324
- } else if (de.event === "error")
1321
+ } else if (le.event === "metadata") {
1322
+ const ve = le.data.mood;
1323
+ typeof ve == "string" && ve.trim() && (a = ve.trim());
1324
+ const we = le.data.sentence_emotions;
1325
+ Array.isArray(we) && (s.length = 0, s.push(
1326
+ ...Yt(we, a)
1327
+ )), I();
1328
+ } else if (le.event === "error")
1325
1329
  throw new Error(
1326
- String(de.data.message ?? "avatar_ttsWithPoses stream error")
1330
+ String(le.data.message ?? "avatar_ttsWithPoses stream error")
1327
1331
  );
1328
1332
  }
1329
1333
  };
1330
- for (; !(he !== G || ie.signal.aborted || !w); ) {
1331
- const { done: Je, value: de } = await Xe.read();
1332
- de && (Ne += ft.decode(de, { stream: !0 }));
1333
- const pe = Ne.split(`
1334
+ for (; !(ce !== G || ne.signal.aborted || !w); ) {
1335
+ const { done: je, value: le } = await ut.read();
1336
+ le && (ie += kt.decode(le, { stream: !0 }));
1337
+ const ve = ie.split(`
1334
1338
 
1335
1339
  `);
1336
- Ne = pe.pop() ?? "";
1337
- for (const ke of pe) await dt(ke);
1338
- if (Je) {
1339
- Ne.trim() && await dt(Ne.trim()), he === G && !ie.signal.aborted && w && O.markStreamComplete(r);
1340
+ ie = ve.pop() ?? "";
1341
+ for (const we of ve) await ft(we);
1342
+ if (je) {
1343
+ ie.trim() && await ft(ie.trim()), ce === G && !ne.signal.aborted && w && V.markStreamComplete(r);
1340
1344
  break;
1341
1345
  }
1342
1346
  }
1343
- } catch (ve) {
1344
- if (ie.signal.aborted || !w) return;
1345
- console.error("[realtimeVoice] avatar_speak failed:", ve), e("error"), D();
1347
+ } catch (Oe) {
1348
+ if (ne.signal.aborted || !w) return;
1349
+ console.error("[realtimeVoice] avatar_speak failed:", Oe), e("error"), I();
1346
1350
  } finally {
1347
- B === ie && (B = null);
1351
+ B === ne && (B = null);
1348
1352
  }
1349
- }, Q = (p) => {
1353
+ }, Z = (p) => {
1350
1354
  const x = ri(p);
1351
1355
  if (!x) {
1352
1356
  console.warn("[realtimeVoice] server message with no payload", p);
1353
1357
  return;
1354
1358
  }
1355
- const j = String(x.type ?? "unknown");
1356
- switch (j !== "avatar_metadata" && j !== "avatar_audio_chunk" && j !== "avatar_lipsync" && j !== "avatar_interrupt" && j !== "error" && console.debug("[realtimeVoice] server message", j, x), j) {
1359
+ const z = String(x.type ?? "unknown");
1360
+ switch (z !== "avatar_metadata" && z !== "avatar_audio_chunk" && z !== "avatar_lipsync" && z !== "avatar_interrupt" && z !== "error" && console.debug("[realtimeVoice] server message", z, x), z) {
1357
1361
  case "avatar_metadata":
1358
- M(x);
1362
+ F(x);
1359
1363
  break;
1360
1364
  case "avatar_audio_chunk":
1361
- A(x);
1365
+ $(x);
1362
1366
  break;
1363
1367
  case "avatar_lipsync":
1364
- $(x);
1368
+ Y(x);
1365
1369
  break;
1366
1370
  case "avatar_interrupt":
1367
- le(x);
1371
+ v(x);
1368
1372
  break;
1369
1373
  case "error": {
1370
- const ie = String(x.message ?? "Voice session error");
1371
- console.error("[realtimeVoice] server error:", ie), e("error"), D();
1374
+ const ne = String(x.message ?? "Voice session error");
1375
+ console.error("[realtimeVoice] server error:", ne), e("error"), I();
1372
1376
  break;
1373
1377
  }
1374
1378
  case "avatar_speak":
1375
- Y(x);
1379
+ Q(x);
1376
1380
  break;
1377
1381
  }
1378
- }, Z = () => f || (c = new Js(), f = new qn({
1382
+ }, be = () => f || (c = new Js(), f = new qn({
1379
1383
  transport: new Kn({
1380
1384
  mediaManager: c,
1381
1385
  serializer: new Xs(),
@@ -1386,34 +1390,33 @@ function si(e, t = {}) {
1386
1390
  enableMic: !0,
1387
1391
  callbacks: {
1388
1392
  onBotReady: () => {
1389
- l = !0, e("idle"), D();
1393
+ l = !0, e("idle"), I();
1390
1394
  },
1391
1395
  onDisconnected: () => {
1392
- l = !1, h();
1396
+ l = !1, T();
1393
1397
  },
1394
1398
  onError: (p) => {
1395
1399
  const x = typeof p == "object" && p !== null && "data" in p ? String(p.data ?? p) : String(p);
1396
- console.error("[realtimeVoice]", x, p), e("error"), D();
1400
+ console.error("[realtimeVoice]", x, p), e("error"), I();
1397
1401
  },
1398
1402
  onTransportStateChanged: (p) => {
1399
- p === "error" && (e("error"), D());
1403
+ p === "error" && (e("error"), I());
1400
1404
  },
1401
1405
  onServerMessage: (p) => {
1402
- X(p);
1406
+ j(p);
1403
1407
  },
1404
1408
  onUserStartedSpeaking: () => {
1405
- le({});
1406
1409
  },
1407
1410
  onBotStartedSpeaking: () => {
1408
- ee(), ne("bot_started");
1411
+ fe(), re("bot_started");
1409
1412
  },
1410
1413
  onBotStoppedSpeaking: () => {
1411
- w && (P(), k = setTimeout(() => {
1412
- k = null, w && (O.markStreamComplete(r), ne("bot_stopped"));
1414
+ w && (N(), k = setTimeout(() => {
1415
+ k = null, w && (V.markStreamComplete(r), re("bot_stopped"));
1413
1416
  }, 450));
1414
1417
  },
1415
1418
  onUserTranscript: (p) => {
1416
- d.onUserTranscript?.(p.text, !!p.final);
1419
+ String(p.text ?? ""), d.onUserTranscript?.(p.text, !!p.final);
1417
1420
  },
1418
1421
  onBotOutput: (p) => {
1419
1422
  d.onBotOutput?.(p.text);
@@ -1424,21 +1427,21 @@ function si(e, t = {}) {
1424
1427
  setDeveloperToken: (p) => {
1425
1428
  },
1426
1429
  setTtsEngineId: (p) => {
1427
- u = p, O.setStreamTtsEngineId(p);
1430
+ u = p, V.setStreamTtsEngineId(p);
1428
1431
  },
1429
1432
  getTtsEngineId: () => u,
1430
1433
  speak: async (p, x) => {
1431
- const j = p.trim();
1432
- if (j) {
1434
+ const z = p.trim();
1435
+ if (z) {
1433
1436
  if (!f || !l)
1434
1437
  throw new Error(
1435
1438
  "Realtime voice is not connected. Call connect() first."
1436
1439
  );
1437
- T(), await f.sendText(j);
1440
+ m(), await f.sendText(z);
1438
1441
  }
1439
1442
  },
1440
1443
  stop: () => {
1441
- B?.abort(), B = null, G += 1, ee(), T(), e("idle"), D();
1444
+ B?.abort(), B = null, G += 1, fe(), m(), e("idle"), I();
1442
1445
  },
1443
1446
  connect: async (p) => {
1444
1447
  if (p && (d = { ...d, ...p }), !d.authToken?.trim())
@@ -1446,49 +1449,49 @@ function si(e, t = {}) {
1446
1449
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1447
1450
  );
1448
1451
  e("loading");
1449
- const x = Z();
1452
+ const x = be();
1450
1453
  await x.initDevices();
1451
- const j = ti(d);
1452
- console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", j);
1454
+ const z = ti(d);
1455
+ console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", z);
1453
1456
  try {
1454
- await x.connect({ wsUrl: j });
1455
- } catch (ie) {
1456
- l = !1, e("error"), D();
1457
- const he = ie instanceof Error ? ie.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1458
- throw new Error(`${he} — ${j}`);
1457
+ await x.connect({ wsUrl: z });
1458
+ } catch (ne) {
1459
+ l = !1, e("error"), I();
1460
+ const ce = ne instanceof Error ? ne.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1461
+ throw new Error(`${ce} — ${z}`);
1459
1462
  }
1460
- l = !0, e("idle"), D();
1463
+ l = !0, e("idle"), I();
1461
1464
  },
1462
1465
  disconnect: async () => {
1463
- if (P(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, G += 1, ee(), f)
1466
+ if (N(), C = !1, M.length = 0, _ = !1, B?.abort(), B = null, G += 1, fe(), f)
1464
1467
  try {
1465
1468
  await f.disconnect();
1466
1469
  } catch (p) {
1467
1470
  console.error("[realtimeVoice] disconnect failed:", p);
1468
1471
  }
1469
- l = !1, h();
1472
+ l = !1, T();
1470
1473
  },
1471
1474
  isConnected: () => l,
1472
1475
  unlockAudio: async () => {
1473
- await O.primeAudioContext();
1476
+ await V.primeAudioContext();
1474
1477
  },
1475
1478
  getVisemeQueue: () => r,
1476
1479
  getWordQueue: () => n,
1477
1480
  getSentenceEmotions: () => s,
1478
1481
  getStreamMood: () => a,
1479
- getPlaybackElapsedMs: z,
1480
- isSpeaking: () => O.isSpeaking(),
1481
- isWarmingUp: () => O.isWarmingUp(),
1482
- releaseWarmupHold: () => O.releaseWarmupHold(),
1482
+ getPlaybackElapsedMs: X,
1483
+ isSpeaking: () => V.isSpeaking(),
1484
+ isWarmingUp: () => V.isWarmingUp(),
1485
+ releaseWarmupHold: () => V.releaseWarmupHold(),
1483
1486
  setLipsyncWarmupHold: (p, x) => {
1484
- x && (U = x), O.setLipsyncWarmupHoldEnabled(p);
1487
+ x && (te = x), V.setLipsyncWarmupHoldEnabled(p);
1485
1488
  },
1486
- getVoiceStream: () => O.getVoiceStream(),
1489
+ getVoiceStream: () => V.getVoiceStream(),
1487
1490
  setPlaybackSpeed: (p) => {
1488
- O.setPlaybackSpeed(p);
1491
+ V.setPlaybackSpeed(p);
1489
1492
  },
1490
- getPlaybackSpeed: () => O.getPlaybackSpeed(),
1491
- subscribe: (p) => (m.add(p), () => m.delete(p))
1493
+ getPlaybackSpeed: () => V.getPlaybackSpeed(),
1494
+ subscribe: (p) => (h.add(p), () => h.delete(p))
1492
1495
  };
1493
1496
  }
1494
1497
  function Tn(e, t, r) {
@@ -1509,7 +1512,7 @@ function En(e, t) {
1509
1512
  function An(e) {
1510
1513
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1511
1514
  }
1512
- async function ct(e, t) {
1515
+ async function at(e, t) {
1513
1516
  const r = await fetch(e);
1514
1517
  if (!r.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1515
1518
  const n = await r.arrayBuffer();
@@ -1517,7 +1520,7 @@ async function ct(e, t) {
1517
1520
  }
1518
1521
  async function Pn(e, t) {
1519
1522
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1520
- const r = await ct(e, t), n = new TextDecoder().decode(r);
1523
+ const r = await at(e, t), n = new TextDecoder().decode(r);
1521
1524
  return JSON.parse(n);
1522
1525
  }
1523
1526
  async function ii(e) {
@@ -1556,16 +1559,16 @@ function ui(e) {
1556
1559
  }
1557
1560
  async function li(e) {
1558
1561
  const t = As();
1559
- if (!Tt()) return t;
1562
+ if (!bt()) return t;
1560
1563
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1561
- const r = await ct(t, e);
1564
+ const r = await at(t, e);
1562
1565
  return ui(r);
1563
1566
  }
1564
1567
  function mr(e, t) {
1565
1568
  return `${e}/${t}_minus_sil.png`;
1566
1569
  }
1567
1570
  const xn = 5;
1568
- function Ht(e) {
1571
+ function Wt(e) {
1569
1572
  const t = e?.composite_threshold;
1570
1573
  if (typeof t == "number" && t > 0) return t;
1571
1574
  const r = e?.crop?.content_threshold;
@@ -1703,7 +1706,7 @@ function Ur(e, t) {
1703
1706
  function Vr(e, t) {
1704
1707
  return `pairs/${e}/${t}_minus_sil.png`;
1705
1708
  }
1706
- function bt(e) {
1709
+ function vt(e) {
1707
1710
  return `${e}_minus_sil.png`;
1708
1711
  }
1709
1712
  function hr(e, t) {
@@ -1712,7 +1715,7 @@ function hr(e, t) {
1712
1715
  if (!r) return null;
1713
1716
  const n = r[1].split("__")[1];
1714
1717
  if (!n || n === "sil") return null;
1715
- const s = bt(n);
1718
+ const s = vt(n);
1716
1719
  return t.has(s) ? s : null;
1717
1720
  }
1718
1721
  function In(e, t) {
@@ -1780,7 +1783,7 @@ function wr(e) {
1780
1783
  function gr(e) {
1781
1784
  return Si[e];
1782
1785
  }
1783
- function Ge(e) {
1786
+ function Ke(e) {
1784
1787
  return Math.max(vi, Math.min(rr, e));
1785
1788
  }
1786
1789
  function bi(e, t) {
@@ -1814,7 +1817,7 @@ const ki = {
1814
1817
  disgust: "disgust",
1815
1818
  disgusted: "disgust"
1816
1819
  };
1817
- function rt(e, t = "neutral") {
1820
+ function et(e, t = "neutral") {
1818
1821
  const r = String(e ?? "").trim().toLowerCase();
1819
1822
  return r ? ki[r] ?? t : t;
1820
1823
  }
@@ -1850,11 +1853,11 @@ function xi(e, t) {
1850
1853
  return null;
1851
1854
  }
1852
1855
  function Ii(e) {
1853
- const t = Ge(e);
1854
- return t >= rr ? rr : Ge(t + Pi);
1856
+ const t = Ke(e);
1857
+ return t >= rr ? rr : Ke(t + Pi);
1855
1858
  }
1856
1859
  function Mi(e, t, r) {
1857
- const n = Ge(r);
1860
+ const n = Ke(r);
1858
1861
  return xi(t, e)?.emphasis ? Ii(n) : n;
1859
1862
  }
1860
1863
  function $r(e) {
@@ -1862,13 +1865,13 @@ function $r(e) {
1862
1865
  const t = e.match(/^brow_(-?\d+)\//);
1863
1866
  if (!t?.[1]) return null;
1864
1867
  const r = Number.parseInt(t[1], 10);
1865
- return Number.isFinite(r) ? Ge(r) : null;
1868
+ return Number.isFinite(r) ? Ke(r) : null;
1866
1869
  }
1867
- function vt(e, t) {
1870
+ function yt(e, t) {
1868
1871
  return e + Math.random() * (t - e);
1869
1872
  }
1870
- function Bt() {
1871
- return vt(14, 32);
1873
+ function Dt() {
1874
+ return yt(14, 32);
1872
1875
  }
1873
1876
  function Ri(e = {}) {
1874
1877
  const {
@@ -1882,124 +1885,124 @@ function Ri(e = {}) {
1882
1885
  postEmotionChangeDelayMs: u = 380,
1883
1886
  minDwellMs: l = 550
1884
1887
  } = e;
1885
- let f = "neutral", c = "neutral", d = 0, g = 0, S = 0, m = {
1888
+ let f = "neutral", c = "neutral", d = 0, g = 0, S = 0, h = {
1886
1889
  kind: "idle",
1887
1890
  nextBlinkAt: performance.now() + t
1888
- }, I = null, _ = "__eyes_open__|neutral|brow:0";
1889
- function R(k = f) {
1890
- _ = `${I ?? "__eyes_open__"}|${k}|brow:${g}`;
1891
+ }, M = null, _ = "__eyes_open__|neutral|brow:0";
1892
+ function D(k = f) {
1893
+ _ = `${M ?? "__eyes_open__"}|${k}|brow:${g}`;
1891
1894
  }
1892
1895
  function w(k, P = f) {
1893
- I = k;
1894
- const D = $r(k);
1895
- D != null ? g = D : k == null && (g = 0), R(P);
1896
+ M = k;
1897
+ const N = $r(k);
1898
+ N != null ? g = N : k == null && (g = 0), D(P);
1896
1899
  }
1897
1900
  function b(k) {
1898
1901
  return Rn(k);
1899
1902
  }
1900
- function L(k, P, D) {
1901
- const U = Ge(P), O = Ge(D);
1902
- if (d = O, U === O) {
1903
- w(b(O));
1903
+ function L(k, P, N) {
1904
+ const I = Ke(P), te = Ke(N);
1905
+ if (d = te, I === te) {
1906
+ w(b(te));
1904
1907
  return;
1905
1908
  }
1906
- const me = [
1907
- ...Ai(U, O),
1908
- b(O)
1909
+ const V = [
1910
+ ...Ai(I, te),
1911
+ b(te)
1909
1912
  ];
1910
- m = {
1913
+ h = {
1911
1914
  kind: "browBlend",
1912
- paths: me,
1915
+ paths: V,
1913
1916
  index: 0,
1914
- holdUntil: k + Bt(),
1915
- targetBrow: O
1916
- }, w(me[0] ?? null);
1917
+ holdUntil: k + Dt(),
1918
+ targetBrow: te
1919
+ }, w(V[0] ?? null);
1917
1920
  }
1918
1921
  function B(k, P) {
1919
- m = {
1922
+ h = {
1920
1923
  kind: "idle",
1921
- nextBlinkAt: k + vt(r, n)
1924
+ nextBlinkAt: k + yt(r, n)
1922
1925
  }, c = P, w(b(d), P);
1923
1926
  }
1924
- function G(k, P, D) {
1925
- const U = D ? yi : Math.random() < a ? gi : _i;
1926
- m = {
1927
+ function G(k, P, N) {
1928
+ const I = N ? yi : Math.random() < a ? gi : _i;
1929
+ h = {
1927
1930
  kind: "playing",
1928
- paths: Ti(P, U),
1931
+ paths: Ti(P, I),
1929
1932
  index: 0,
1930
- holdUntil: k + Bt(),
1933
+ holdUntil: k + Dt(),
1931
1934
  after: "idle",
1932
1935
  blinkEmotion: P
1933
- }, c = P, w(m.paths[0] ?? null, P);
1936
+ }, c = P, w(h.paths[0] ?? null, P);
1934
1937
  }
1935
1938
  function C(k) {
1936
- if (m.kind === "browBlend") {
1937
- for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
1938
- m.index += 1, m.holdUntil = k + Bt();
1939
- const P = m.paths[m.index] ?? null;
1940
- w(P), k >= m.holdUntil && m.index >= m.paths.length - 1 && (g = m.targetBrow, d = m.targetBrow, w(b(m.targetBrow)), m = {
1939
+ if (h.kind === "browBlend") {
1940
+ for (; k >= h.holdUntil && h.index < h.paths.length - 1; )
1941
+ h.index += 1, h.holdUntil = k + Dt();
1942
+ const P = h.paths[h.index] ?? null;
1943
+ w(P), k >= h.holdUntil && h.index >= h.paths.length - 1 && (g = h.targetBrow, d = h.targetBrow, w(b(h.targetBrow)), h = {
1941
1944
  kind: "idle",
1942
1945
  nextBlinkAt: k + u
1943
1946
  });
1944
1947
  return;
1945
1948
  }
1946
- if (m.kind === "idle") {
1947
- w(b(d), c), k >= m.nextBlinkAt && G(k, c, !1);
1949
+ if (h.kind === "idle") {
1950
+ w(b(d), c), k >= h.nextBlinkAt && G(k, c, !1);
1948
1951
  return;
1949
1952
  }
1950
- if (m.kind === "doublePause") {
1951
- w(b(d), m.blinkEmotion), k >= m.resumeAt && G(k, m.blinkEmotion, !0);
1953
+ if (h.kind === "doublePause") {
1954
+ w(b(d), h.blinkEmotion), k >= h.resumeAt && G(k, h.blinkEmotion, !0);
1952
1955
  return;
1953
1956
  }
1954
- if (m.kind === "playing") {
1955
- for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
1956
- m.index += 1, m.holdUntil = k + Bt();
1957
- if (w(m.paths[m.index] ?? null, m.blinkEmotion), k >= m.holdUntil && m.index >= m.paths.length - 1) {
1958
- if (m.after === "resumeIdle") {
1957
+ if (h.kind === "playing") {
1958
+ for (; k >= h.holdUntil && h.index < h.paths.length - 1; )
1959
+ h.index += 1, h.holdUntil = k + Dt();
1960
+ if (w(h.paths[h.index] ?? null, h.blinkEmotion), k >= h.holdUntil && h.index >= h.paths.length - 1) {
1961
+ if (h.after === "resumeIdle") {
1959
1962
  B(k + u, f);
1960
1963
  return;
1961
1964
  }
1962
- if (m.after === "doublePause") {
1963
- m = {
1965
+ if (h.after === "doublePause") {
1966
+ h = {
1964
1967
  kind: "doublePause",
1965
- resumeAt: k + vt(i, o),
1966
- blinkEmotion: m.blinkEmotion
1967
- }, w(b(d), m.blinkEmotion);
1968
+ resumeAt: k + yt(i, o),
1969
+ blinkEmotion: h.blinkEmotion
1970
+ }, w(b(d), h.blinkEmotion);
1968
1971
  return;
1969
1972
  }
1970
- if (m.after === "idle" && Math.random() < s) {
1971
- m = {
1973
+ if (h.after === "idle" && Math.random() < s) {
1974
+ h = {
1972
1975
  kind: "doublePause",
1973
- resumeAt: k + vt(i, o),
1974
- blinkEmotion: m.blinkEmotion
1975
- }, w(b(d), m.blinkEmotion);
1976
+ resumeAt: k + yt(i, o),
1977
+ blinkEmotion: h.blinkEmotion
1978
+ }, w(b(d), h.blinkEmotion);
1976
1979
  return;
1977
1980
  }
1978
- B(k, m.blinkEmotion);
1981
+ B(k, h.blinkEmotion);
1979
1982
  }
1980
1983
  }
1981
1984
  }
1982
1985
  return {
1983
1986
  advance: C,
1984
1987
  setTargetEmotion(k) {
1985
- const P = rt(k, f);
1988
+ const P = et(k, f);
1986
1989
  if (P === f) return;
1987
- const D = performance.now();
1988
- l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && D - S < l || (f = P, c = P, S = D);
1990
+ const N = performance.now();
1991
+ l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && N - S < l || (f = P, c = P, S = N);
1989
1992
  },
1990
1993
  setTargetEyebrow(k) {
1991
- const P = Ge(k);
1994
+ const P = Ke(k);
1992
1995
  if (P === d) return;
1993
- const D = performance.now(), U = m.kind === "browBlend" ? $r(I) ?? g : g;
1994
- d = P, !(P === U && m.kind !== "browBlend") && (m.kind === "playing" || m.kind === "doublePause" || L(D, U, P));
1996
+ const N = performance.now(), I = h.kind === "browBlend" ? $r(M) ?? g : g;
1997
+ d = P, !(P === I && h.kind !== "browBlend") && (h.kind === "playing" || h.kind === "doublePause" || L(N, I, P));
1995
1998
  },
1996
1999
  getTargetEmotion: () => f,
1997
2000
  getTargetEyebrow: () => d,
1998
- getExpressionPath: () => I,
2001
+ getExpressionPath: () => M,
1999
2002
  getDrawKey: () => _,
2000
2003
  reset() {
2001
2004
  f = "neutral", c = "neutral", d = 0, g = 0, S = 0, B(
2002
- performance.now() + vt(r, n),
2005
+ performance.now() + yt(r, n),
2003
2006
  "neutral"
2004
2007
  );
2005
2008
  }
@@ -2074,18 +2077,18 @@ function Fi(e, t) {
2074
2077
  return r.sort((n, s) => n.startMs - s.startMs);
2075
2078
  }
2076
2079
  function Li(e, t, r, n = "neutral") {
2077
- const s = rt(n);
2080
+ const s = et(n);
2078
2081
  if (t.length === 0) return s;
2079
2082
  if (r.length === 0 || e < r[0].wtime)
2080
- return rt(t[0]?.emotion, s);
2083
+ return et(t[0]?.emotion, s);
2081
2084
  const i = Fi(t, r);
2082
2085
  let o = null;
2083
2086
  for (const l of i)
2084
2087
  e >= l.startMs && e <= l.endMs && (o = l);
2085
2088
  if (o)
2086
- return rt(o.sentence.emotion, s);
2089
+ return et(o.sentence.emotion, s);
2087
2090
  const a = r[r.length - 1], u = a.wtime + a.wduration;
2088
- return e > u + Bn ? rt(
2091
+ return e > u + Bn ? et(
2089
2092
  t[t.length - 1]?.emotion,
2090
2093
  s
2091
2094
  ) : s;
@@ -2100,20 +2103,20 @@ function yr(e, t, r, n, s = xn) {
2100
2103
  f.clearRect(0, 0, r, n), f.drawImage(c, 0, 0, r, n);
2101
2104
  const d = f.getImageData(0, 0, r, n);
2102
2105
  for (let g = 0; g < u.data.length; g += 4) {
2103
- const S = d.data[g], m = d.data[g + 1], I = d.data[g + 2];
2104
- Math.max(S, m, I) > s && (u.data[g] = S, u.data[g + 1] = m, u.data[g + 2] = I, u.data[g + 3] = 255);
2106
+ const S = d.data[g], h = d.data[g + 1], M = d.data[g + 2];
2107
+ Math.max(S, h, M) > s && (u.data[g] = S, u.data[g + 1] = h, u.data[g + 2] = M, u.data[g + 3] = 255);
2105
2108
  }
2106
2109
  }
2107
2110
  return o.putImageData(u, 0, 0), i;
2108
2111
  }
2109
- let Ke = null, it = null;
2110
- const Ot = /* @__PURE__ */ new Map();
2112
+ let qe = null, nt = null;
2113
+ const Lt = /* @__PURE__ */ new Map();
2111
2114
  function Oi() {
2112
- Ke = null, it = null, Ot.clear();
2115
+ qe = null, nt = null, Lt.clear();
2113
2116
  }
2114
2117
  cn(Oi);
2115
2118
  function Ni(e) {
2116
- return e ?? it ?? void 0;
2119
+ return e ?? nt ?? void 0;
2117
2120
  }
2118
2121
  function _r(e) {
2119
2122
  return new Promise((t, r) => {
@@ -2122,9 +2125,9 @@ function _r(e) {
2122
2125
  });
2123
2126
  }
2124
2127
  async function Ui(e) {
2125
- return Tt() ? ci(
2126
- await ct(Lt(), e ?? "")
2127
- ) : _r(Lt());
2128
+ return bt() ? ci(
2129
+ await at(Ft(), e ?? "")
2130
+ ) : _r(Ft());
2128
2131
  }
2129
2132
  async function qr(e, t, r, n) {
2130
2133
  const s = r ? await Pn(e, n) : await fetch(e).then((l) => {
@@ -2133,7 +2136,7 @@ async function qr(e, t, r, n) {
2133
2136
  }), i = s.sheets?.[0];
2134
2137
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
2135
2138
  const o = r ? await ai(
2136
- await ct(
2139
+ await at(
2137
2140
  Mn(t, i.path, r),
2138
2141
  n ?? ""
2139
2142
  )
@@ -2146,19 +2149,19 @@ async function qr(e, t, r, n) {
2146
2149
  return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: u, diffBase: t };
2147
2150
  }
2148
2151
  async function nr(e) {
2149
- const t = Ni(e), r = Tt();
2152
+ const t = Ni(e), r = bt();
2150
2153
  if (r && !t)
2151
2154
  throw new Error("Encrypted assets enabled but no key provided");
2152
- if (Ke && (!r || it === (t ?? null))) {
2153
- const i = await Ke;
2155
+ if (qe && (!r || nt === (t ?? null))) {
2156
+ const i = await qe;
2154
2157
  return {
2155
- ...at(i),
2158
+ ...st(i),
2156
2159
  visemePaths: [...i.viseme.cellByPath.keys()]
2157
2160
  };
2158
2161
  }
2159
- it = t ?? null, Ot.clear();
2162
+ nt = t ?? null, Lt.clear();
2160
2163
  const n = un();
2161
- Ke = (async () => {
2164
+ qe = (async () => {
2162
2165
  const i = await Ui(t), o = await qr(
2163
2166
  ln(),
2164
2167
  n,
@@ -2178,14 +2181,14 @@ async function nr(e) {
2178
2181
  }
2179
2182
  return { sil: i, viseme: o, expression: a };
2180
2183
  })();
2181
- const s = await Ke;
2182
- return { ...at(s), visemePaths: [...s.viseme.cellByPath.keys()] };
2184
+ const s = await qe;
2185
+ return { ...st(s), visemePaths: [...s.viseme.cellByPath.keys()] };
2183
2186
  }
2184
2187
  async function vr(e) {
2185
- if (await nr(e), !Ke) throw new Error("Assets not loaded");
2186
- return Ke;
2188
+ if (await nr(e), !qe) throw new Error("Assets not loaded");
2189
+ return qe;
2187
2190
  }
2188
- function at(e) {
2191
+ function st(e) {
2189
2192
  return Tn(
2190
2193
  e.viseme.atlasMeta,
2191
2194
  e.sil.naturalWidth,
@@ -2196,13 +2199,13 @@ function Vi(e, t) {
2196
2199
  const r = document.createElement("canvas");
2197
2200
  return r.width = t.w, r.height = t.h, r.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
2198
2201
  }
2199
- async function Nt(e, t, r) {
2200
- const n = `${t.diffBase}::${r}`, s = Ot.get(n);
2202
+ async function Ot(e, t, r) {
2203
+ const n = `${t.diffBase}::${r}`, s = Lt.get(n);
2201
2204
  if (s) return s;
2202
2205
  const i = (async () => {
2203
2206
  const o = t.cellByPath.get(r);
2204
2207
  if (!o) throw new Error(`No atlas cell for path: ${r}`);
2205
- const a = En(t.atlasMeta, o), u = at(e);
2208
+ const a = En(t.atlasMeta, o), u = st(e);
2206
2209
  if (An(o)) {
2207
2210
  const c = Vi(t, o), d = document.createElement("canvas");
2208
2211
  d.width = u.width, d.height = u.height;
@@ -2214,23 +2217,23 @@ async function Nt(e, t, r) {
2214
2217
  return f;
2215
2218
  throw new Error(`Diff PNG wrong size for ${r}`);
2216
2219
  })();
2217
- return Ot.set(n, i), i;
2220
+ return Lt.set(n, i), i;
2218
2221
  }
2219
2222
  async function Kr(e, t, r, n, s, i) {
2220
2223
  if (s) {
2221
2224
  const { width: g, height: S } = s;
2222
2225
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
2223
2226
  return;
2224
- const m = document.createElement("canvas");
2225
- m.width = g, m.height = S;
2226
- const I = m.getContext("2d");
2227
- if (I.clearRect(0, 0, g, S), I.drawImage(t, 0, 0, g, S), i && !i()) return;
2227
+ const h = document.createElement("canvas");
2228
+ h.width = g, h.height = S;
2229
+ const M = h.getContext("2d");
2230
+ if (M.clearRect(0, 0, g, S), M.drawImage(t, 0, 0, g, S), i && !i()) return;
2228
2231
  (e.width !== g || e.height !== S) && (e.width = g, e.height = S);
2229
2232
  const _ = e.getContext("2d");
2230
- _.clearRect(0, 0, g, S), _.drawImage(m, 0, 0);
2233
+ _.clearRect(0, 0, g, S), _.drawImage(h, 0, 0);
2231
2234
  return;
2232
2235
  }
2233
- const o = await vr(), a = Ht(o.viseme.atlasMeta), { width: u, height: l } = at(o);
2236
+ const o = await vr(), a = Wt(o.viseme.atlasMeta), { width: u, height: l } = st(o);
2234
2237
  (e.width !== u || e.height !== l) && (e.width = u, e.height = l);
2235
2238
  const f = [], c = e.getContext("2d");
2236
2239
  if (c.clearRect(0, 0, u, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
@@ -2246,15 +2249,15 @@ async function Kr(e, t, r, n, s, i) {
2246
2249
  c.drawImage(d, 0, 0);
2247
2250
  }
2248
2251
  async function sr(e, t, r) {
2249
- const n = await vr(it ?? void 0), s = Ht(n.viseme.atlasMeta), { width: i, height: o } = at(n);
2252
+ const n = await vr(nt ?? void 0), s = Wt(n.viseme.atlasMeta), { width: i, height: o } = st(n);
2250
2253
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
2251
2254
  const a = [];
2252
2255
  if (t.mouthPath) {
2253
2256
  const f = new Set(n.viseme.cellByPath.keys()), c = hr(t.mouthPath, f) ?? (f.has(t.mouthPath) ? t.mouthPath : null);
2254
- c && a.push(await Nt(n, n.viseme, c));
2257
+ c && a.push(await Ot(n, n.viseme, c));
2255
2258
  }
2256
2259
  t.expressionPath && n.expression && a.push(
2257
- await Nt(n, n.expression, t.expressionPath)
2260
+ await Ot(n, n.expression, t.expressionPath)
2258
2261
  );
2259
2262
  const u = e.getContext("2d");
2260
2263
  if (u.clearRect(0, 0, i, o), a.length === 0) {
@@ -2271,13 +2274,13 @@ async function sr(e, t, r) {
2271
2274
  u.drawImage(l, 0, 0);
2272
2275
  }
2273
2276
  async function Wi(e, t) {
2274
- const r = await vr(it ?? void 0), n = Ht(r.viseme.atlasMeta), { width: s, height: i } = at(r), o = [];
2277
+ const r = await vr(nt ?? void 0), n = Wt(r.viseme.atlasMeta), { width: s, height: i } = st(r), o = [];
2275
2278
  if (e.mouthPath) {
2276
2279
  const f = new Set(r.viseme.cellByPath.keys()), c = hr(e.mouthPath, f) ?? (f.has(e.mouthPath) ? e.mouthPath : null);
2277
- c && o.push(await Nt(r, r.viseme, c));
2280
+ c && o.push(await Ot(r, r.viseme, c));
2278
2281
  }
2279
2282
  e.expressionPath && r.expression && o.push(
2280
- await Nt(r, r.expression, e.expressionPath)
2283
+ await Ot(r, r.expression, e.expressionPath)
2281
2284
  );
2282
2285
  const a = new OffscreenCanvas(s, i), u = a.getContext("2d");
2283
2286
  if (o.length === 0)
@@ -2298,7 +2301,7 @@ let Cn = null;
2298
2301
  function Gr(e) {
2299
2302
  Cn = e;
2300
2303
  }
2301
- function Ue() {
2304
+ function Ne() {
2302
2305
  return Cn;
2303
2306
  }
2304
2307
  function $i(e) {
@@ -2390,25 +2393,25 @@ function qi() {
2390
2393
  },
2391
2394
  snapshot(f, c) {
2392
2395
  let d = 0, g = 0;
2393
- for (const R of f)
2394
- if (R.viseme !== "sil") {
2395
- if (R.vtime >= c) break;
2396
- d += 1, t.has(R.vtime) && (g += 1);
2396
+ for (const D of f)
2397
+ if (D.viseme !== "sil") {
2398
+ if (D.vtime >= c) break;
2399
+ d += 1, t.has(D.vtime) && (g += 1);
2397
2400
  }
2398
- const S = d > 0 ? Math.round(g / d * 100) : 100, m = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), I = d - g, _ = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
2401
+ const S = d > 0 ? Math.round(g / d * 100) : 100, h = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), M = d - g, _ = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
2399
2402
  return {
2400
2403
  ...e,
2401
2404
  bufferHitRate: _,
2402
- renderLoss: m,
2405
+ renderLoss: h,
2403
2406
  visemeSlotsTotal: d,
2404
2407
  visemeSlotsCovered: g,
2405
2408
  visemeCoveragePct: S,
2406
2409
  transitionFramesUniqueSampled: r.size,
2407
2410
  transitionFramesUniquePainted: n.size,
2408
2411
  drawsDeduped: e.rafTicksDeduped,
2409
- renderSkips: e.rafTicksDeduped + m,
2412
+ renderSkips: e.rafTicksDeduped + h,
2410
2413
  visemesShown: g,
2411
- visemesSkipped: I,
2414
+ visemesSkipped: M,
2412
2415
  rifeTransitionFramesSkipped: e.transitionFramesMissed
2413
2416
  };
2414
2417
  }
@@ -2421,7 +2424,7 @@ function jr(e) {
2421
2424
  function Sr() {
2422
2425
  return { lastDrawnKey: "" };
2423
2426
  }
2424
- function Pe(e) {
2427
+ function Ie(e) {
2425
2428
  e.lastDrawnKey = "", e.transitionCache = void 0;
2426
2429
  }
2427
2430
  function ji(e, t) {
@@ -2448,13 +2451,13 @@ function Ji(e, t) {
2448
2451
  function Qi() {
2449
2452
  return Fn + zi;
2450
2453
  }
2451
- function Ut(e) {
2454
+ function Nt(e) {
2452
2455
  return e ?? Ln;
2453
2456
  }
2454
2457
  function br(e, t, r, n, s = Gi) {
2455
2458
  if (e.length === 0)
2456
2459
  return { diffPath: null, label: "sil" };
2457
- if (t >= qe(e))
2460
+ if (t >= $e(e))
2458
2461
  return { diffPath: null, label: "sil" };
2459
2462
  const i = ji(e, n), o = $s(i, t);
2460
2463
  if (o) {
@@ -2490,21 +2493,21 @@ function br(e, t, r, n, s = Gi) {
2490
2493
  }
2491
2494
  };
2492
2495
  }
2493
- return { diffPath: bt(o.to), label: o.to };
2496
+ return { diffPath: vt(o.to), label: o.to };
2494
2497
  }
2495
2498
  }
2496
2499
  const a = _n(e, t, s);
2497
- return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: bt(a), label: a };
2500
+ return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: vt(a), label: a };
2498
2501
  }
2499
2502
  function kr(e, t) {
2500
- const r = t ?? Ut(e.expressionPath);
2501
- return `${Ut(e.mouthPath)}|${r}`;
2503
+ const r = t ?? Nt(e.expressionPath);
2504
+ return `${Nt(e.mouthPath)}|${r}`;
2502
2505
  }
2503
2506
  function Yr(e, t, r, n, s, i, o, a, u, l) {
2504
2507
  const f = br(t, r, u, i), c = {
2505
2508
  mouthPath: f.diffPath,
2506
2509
  expressionPath: n
2507
- }, d = kr(c, s), g = Ue();
2510
+ }, d = kr(c, s), g = Ne();
2508
2511
  if (f.transitionMeta && g?.onTransitionSample(f.transitionMeta, f.diffPath), d === i.lastDrawnKey) {
2509
2512
  g?.onDrawDeduped();
2510
2513
  return;
@@ -2521,7 +2524,7 @@ function Xr(e, t, r, n, s, i, o = null) {
2521
2524
  c === l && (n.lastDrawnKey = l);
2522
2525
  }));
2523
2526
  }
2524
- function On(e, t, r, n, s = St, i) {
2527
+ function On(e, t, r, n, s = _t, i) {
2525
2528
  if (r <= t || e.length === 0) return [];
2526
2529
  const o = i ?? Sr(), a = [];
2527
2530
  let u = "";
@@ -2531,7 +2534,7 @@ function On(e, t, r, n, s = St, i) {
2531
2534
  l,
2532
2535
  n,
2533
2536
  o
2534
- ), c = Ut(f.diffPath);
2537
+ ), c = Nt(f.diffPath);
2535
2538
  c !== u && (u = c, a.push({
2536
2539
  displayAtMs: l,
2537
2540
  mouthPath: f.diffPath,
@@ -2566,7 +2569,7 @@ function Tr(e) {
2566
2569
  return {
2567
2570
  enqueue(a, u, l) {
2568
2571
  const f = r.findIndex((c) => c.drawKey === u);
2569
- f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= Zi && (r.shift(), Ue()?.onQueueSuperseded()), r.push({ diffs: a, drawKey: u, onDisplayed: l })), o();
2572
+ f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= Zi && (r.shift(), Ne()?.onQueueSuperseded()), r.push({ diffs: a, drawKey: u, onDisplayed: l })), o();
2570
2573
  },
2571
2574
  reset() {
2572
2575
  t += 1, r.length = 0;
@@ -2662,7 +2665,7 @@ function ra(e, t, r, n, s, i) {
2662
2665
  r,
2663
2666
  n,
2664
2667
  s,
2665
- St,
2668
+ _t,
2666
2669
  i
2667
2670
  );
2668
2671
  if (o.length === 0) return { ready: 0, total: 0 };
@@ -2689,7 +2692,7 @@ function na(e) {
2689
2692
  c.label,
2690
2693
  c.mouthPath,
2691
2694
  d
2692
- ), Ue()?.onBufferPrefetched();
2695
+ ), Ne()?.onBufferPrefetched();
2693
2696
  } finally {
2694
2697
  n.delete(c.mouthKey);
2695
2698
  }
@@ -2708,21 +2711,21 @@ function na(e) {
2708
2711
  }));
2709
2712
  }, u = (c, d, g, S = zt) => {
2710
2713
  if (!e.supportsBufferedPlayback) return;
2711
- const m = Math.max(0, d - St * 4), I = On(
2714
+ const h = Math.max(0, d - _t * 4), M = On(
2712
2715
  c,
2713
- m,
2716
+ h,
2714
2717
  d + S,
2715
2718
  g,
2716
- St,
2719
+ _t,
2717
2720
  r
2718
2721
  );
2719
- a(I);
2722
+ a(M);
2720
2723
  }, l = (c, d) => {
2721
2724
  s = c, i = d;
2722
2725
  }, f = (c, d) => !(s !== c || i !== d);
2723
2726
  return {
2724
2727
  reset() {
2725
- t.reset(), o.reset(), n.clear(), Pe(r), s = "", i = null, Ue()?.onBufferReset();
2728
+ t.reset(), o.reset(), n.clear(), Ie(r), s = "", i = null, Ne()?.onBufferReset();
2726
2729
  },
2727
2730
  markExternallyDisplayed(c, d) {
2728
2731
  l(c.split("|")[0] ?? c, d);
@@ -2749,7 +2752,7 @@ function na(e) {
2749
2752
  },
2750
2753
  getBufferedFrameCount: () => t.size(),
2751
2754
  tick(c) {
2752
- const d = Ue();
2755
+ const d = Ne();
2753
2756
  d?.onBufferTick(), u(
2754
2757
  c.queue,
2755
2758
  c.elapsedMs,
@@ -2760,21 +2763,21 @@ function na(e) {
2760
2763
  c.elapsedMs,
2761
2764
  c.availablePaths,
2762
2765
  r
2763
- ), S = Ut(g.diffPath), m = kr(
2766
+ ), S = Nt(g.diffPath), h = kr(
2764
2767
  { mouthPath: g.diffPath, expressionPath: c.expressionPath },
2765
2768
  c.expressionDrawKey
2766
- ), I = () => (l(S, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2767
- if (f(S, c.expressionPath) || c.playbackState.lastDrawnKey === m)
2768
- return I();
2769
+ ), M = () => (l(S, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2770
+ if (f(S, c.expressionPath) || c.playbackState.lastDrawnKey === h)
2771
+ return M();
2769
2772
  const _ = t.findForMouthKey(
2770
2773
  S,
2771
2774
  c.elapsedMs,
2772
- St
2775
+ _t
2773
2776
  );
2774
- return _ && c.expressionPath != null ? (d?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : _ ? (e.blitBitmap(c.canvas, _.bitmap), l(_.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = m, c.onStatus({
2777
+ return _ && c.expressionPath != null ? (d?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : _ ? (e.blitBitmap(c.canvas, _.bitmap), l(_.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = h, c.onStatus({
2775
2778
  diffPath: _.mouthPath,
2776
2779
  label: _.label
2777
- }), c.onDisplayed(m, _.mouthPath, _.label), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !1 }) : (d?.onBufferUnderrun(), { usedBuffer: !1, underrun: !0, held: !1 });
2780
+ }), c.onDisplayed(h, _.mouthPath, _.label), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !1 }) : (d?.onBufferUnderrun(), { usedBuffer: !1, underrun: !0, held: !1 });
2778
2781
  }
2779
2782
  };
2780
2783
  }
@@ -2871,14 +2874,14 @@ async function Qr(e, t, r, n, s) {
2871
2874
  if (!o?.path) throw new Error(`${e} has no sheets[0].path`);
2872
2875
  const a = /* @__PURE__ */ new Map(), u = async (c, d) => {
2873
2876
  const g = Mn(t, d, r), S = r ? await ii(
2874
- await ct(g, s ?? "")
2877
+ await at(g, s ?? "")
2875
2878
  ) : await Nn(g);
2876
2879
  if (aa(S.width, S.height, n))
2877
2880
  return console.info(
2878
2881
  `[PixiVisemeCompositor] Sheet ${d} (${S.width}x${S.height}) exceeds MAX_TEXTURE_SIZE=${n}; using per-cell crops.`
2879
2882
  ), { mode: "cells", bitmap: S };
2880
- const m = we.from(S);
2881
- return m.source.scaleMode = "nearest", { mode: "full", texture: m };
2883
+ const h = ge.from(S);
2884
+ return h.source.scaleMode = "nearest", { mode: "full", texture: h };
2882
2885
  };
2883
2886
  a.set(o.index, await u(o.index, o.path));
2884
2887
  for (const c of i.sheets ?? [])
@@ -2927,22 +2930,22 @@ async function la(e, t = {}) {
2927
2930
  s = !0, !i && !o && (i = !0, t.onWebGlContextLost?.());
2928
2931
  };
2929
2932
  a.addEventListener("webglcontextlost", u);
2930
- const l = new It(we.EMPTY), f = new It(we.EMPTY), c = new It(we.EMPTY), d = new It(we.EMPTY);
2933
+ const l = new xt(ge.EMPTY), f = new xt(ge.EMPTY), c = new xt(ge.EMPTY), d = new xt(ge.EMPTY);
2931
2934
  d.visible = !1;
2932
2935
  const g = Jr(5), S = Jr(5);
2933
2936
  f.filters = [g], c.filters = [S], r.stage.addChild(l), r.stage.addChild(f), r.stage.addChild(c), r.stage.addChild(d);
2934
- let m = null, I = null, _ = null, R = null, w = null, b = null, L = 842, B = 1264, G = null, C = 5;
2937
+ let h = null, M = null, _ = null, D = null, w = null, b = null, L = 842, B = 1264, G = null, C = 5;
2935
2938
  const k = /* @__PURE__ */ new Map();
2936
- let P = null, D = null, U = null;
2937
- const O = cn(() => {
2938
- k.clear(), w = null, b = null, m = null, G = null;
2939
- }), me = (v, T) => {
2940
- L = v, B = T, r.renderer.resize(v, T), (e.width !== v || e.height !== T) && (e.width = v, e.height = T);
2941
- }, X = () => {
2942
- f.visible = !1, c.visible = !1, f.texture = we.EMPTY, c.texture = we.EMPTY, P = null, D = null;
2943
- }, z = () => {
2944
- d.visible = !1, m && (l.texture = m, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
2939
+ let P = null, N = null, I = null;
2940
+ const te = cn(() => {
2941
+ k.clear(), w = null, b = null, h = null, G = null;
2942
+ }), V = (v, E) => {
2943
+ L = v, B = E, r.renderer.resize(v, E), (e.width !== v || e.height !== E) && (e.width = v, e.height = E);
2945
2944
  }, J = () => {
2945
+ f.visible = !1, c.visible = !1, f.texture = ge.EMPTY, c.texture = ge.EMPTY, P = null, N = null;
2946
+ }, j = () => {
2947
+ d.visible = !1, h && (l.texture = h, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
2948
+ }, X = () => {
2946
2949
  if (_) {
2947
2950
  try {
2948
2951
  _.resource = null;
@@ -2950,50 +2953,50 @@ async function la(e, t = {}) {
2950
2953
  }
2951
2954
  _.destroy(), _ = null;
2952
2955
  }
2953
- I && (I.destroy(!1), I = null), R = null;
2954
- }, ne = (v, T) => {
2955
- const h = v.cellByPath.get(T);
2956
- if (!h || !An(h)) return null;
2957
- const E = `${v.diffBase}::${T}`;
2958
- let M = k.get(E);
2959
- if (!M) {
2960
- const F = h.sheet ?? 0, A = v.sheets.get(F);
2956
+ M && (M.destroy(!1), M = null), D = null;
2957
+ }, pe = (v, E) => {
2958
+ const m = v.cellByPath.get(E);
2959
+ if (!m || !An(m)) return null;
2960
+ const T = `${v.diffBase}::${E}`;
2961
+ let R = k.get(T);
2962
+ if (!R) {
2963
+ const F = m.sheet ?? 0, A = v.sheets.get(F);
2961
2964
  if (!A) return null;
2962
2965
  let $, Y = !1;
2963
2966
  if (A.mode === "full")
2964
- $ = new we({
2967
+ $ = new ge({
2965
2968
  source: A.texture.source,
2966
- frame: new Zn(h.x, h.y, h.w, h.h)
2969
+ frame: new Zn(m.x, m.y, m.w, m.h)
2967
2970
  });
2968
2971
  else {
2969
- const Q = ua(A.bitmap, h);
2970
- $ = we.from(Q), $.source.scaleMode = "nearest", Y = !0;
2972
+ const Q = ua(A.bitmap, m);
2973
+ $ = ge.from(Q), $.source.scaleMode = "nearest", Y = !0;
2971
2974
  }
2972
- M = { texture: $, ownsSource: Y }, k.set(E, M);
2975
+ R = { texture: $, ownsSource: Y }, k.set(T, R);
2973
2976
  }
2974
- return { texture: M.texture, cell: h };
2975
- }, ee = (v, T, h, E) => {
2976
- if (!E || !h)
2977
- return v.visible = !1, v.texture = we.EMPTY, !1;
2978
- const M = ne(h, E);
2979
- if (!M)
2980
- return v.visible = !1, v.texture = we.EMPTY, !1;
2981
- const F = En(h.atlasMeta, M.cell);
2982
- return T.setThreshold(C), v.texture = M.texture, v.x = F.x, v.y = F.y, v.width = M.cell.w, v.height = M.cell.h, v.visible = !0, !0;
2983
- }, ge = (v) => {
2977
+ return { texture: R.texture, cell: m };
2978
+ }, re = (v, E, m, T) => {
2979
+ if (!T || !m)
2980
+ return v.visible = !1, v.texture = ge.EMPTY, !1;
2981
+ const R = pe(m, T);
2982
+ if (!R)
2983
+ return v.visible = !1, v.texture = ge.EMPTY, !1;
2984
+ const F = En(m.atlasMeta, R.cell);
2985
+ return E.setThreshold(C), v.texture = R.texture, v.x = F.x, v.y = F.y, v.width = R.cell.w, v.height = R.cell.h, v.visible = !0, !0;
2986
+ }, fe = (v) => {
2984
2987
  if (!v || !w) return null;
2985
- const T = G ?? new Set(w.cellByPath.keys());
2986
- return hr(v, T) ?? (T.has(v) ? v : null);
2987
- }, oe = (v) => {
2988
- d.visible = !1, z();
2989
- const T = ge(v.mouthPath), h = v.expressionPath && b && b.cellByPath.has(v.expressionPath) ? v.expressionPath : null;
2990
- T !== P ? (ee(f, g, w, T), P = T) : T ? f.visible = !0 : f.visible = !1, h !== D ? (ee(
2988
+ const E = G ?? new Set(w.cellByPath.keys());
2989
+ return hr(v, E) ?? (E.has(v) ? v : null);
2990
+ }, de = (v) => {
2991
+ d.visible = !1, j();
2992
+ const E = fe(v.mouthPath), m = v.expressionPath && b && b.cellByPath.has(v.expressionPath) ? v.expressionPath : null;
2993
+ E !== P ? (re(f, g, w, E), P = E) : E ? f.visible = !0 : f.visible = !1, m !== N ? (re(
2991
2994
  c,
2992
2995
  S,
2993
2996
  b,
2994
- h
2995
- ), D = h) : h ? c.visible = !0 : c.visible = !1;
2996
- }, le = () => {
2997
+ m
2998
+ ), N = m) : m ? c.visible = !0 : c.visible = !1;
2999
+ }, ue = () => {
2997
3000
  if (!(o || s || document.hidden))
2998
3001
  try {
2999
3002
  r.render();
@@ -3003,40 +3006,40 @@ async function la(e, t = {}) {
3003
3006
  return {
3004
3007
  async loadAssets(v) {
3005
3008
  if (o) return { width: L, height: B, visemePaths: [] };
3006
- const T = Tt();
3007
- if (T && !v)
3009
+ const E = bt();
3010
+ if (E && !v)
3008
3011
  throw new Error("Encrypted assets enabled but no key provided");
3009
- const h = T ? await oi(
3010
- await ct(Lt(), v ?? "")
3011
- ) : await Nn(Lt());
3012
- m && m.destroy(!0), m = we.from(h), m.source.scaleMode = "linear";
3013
- const E = un();
3012
+ const m = E ? await oi(
3013
+ await at(Ft(), v ?? "")
3014
+ ) : await Nn(Ft());
3015
+ h && h.destroy(!0), h = ge.from(m), h.source.scaleMode = "linear";
3016
+ const T = un();
3014
3017
  w = await Qr(
3015
3018
  ln(),
3016
- E,
3017
3019
  T,
3020
+ E,
3018
3021
  n,
3019
3022
  v
3020
3023
  );
3021
3024
  try {
3022
3025
  b = await Qr(
3023
3026
  fn(),
3024
- E,
3025
3027
  T,
3028
+ E,
3026
3029
  n,
3027
3030
  v
3028
3031
  );
3029
3032
  } catch {
3030
3033
  b = null;
3031
3034
  }
3032
- const M = Tn(
3035
+ const R = Tn(
3033
3036
  w.atlasMeta,
3034
- h.width,
3035
- h.height
3037
+ m.width,
3038
+ m.height
3036
3039
  );
3037
- return me(M.width, M.height), C = Ht(w.atlasMeta), g.setThreshold(C), S.setThreshold(C), G = new Set(w.cellByPath.keys()), k.clear(), z(), X(), le(), {
3038
- width: M.width,
3039
- height: M.height,
3040
+ return V(R.width, R.height), C = Wt(w.atlasMeta), g.setThreshold(C), S.setThreshold(C), G = new Set(w.cellByPath.keys()), k.clear(), j(), J(), ue(), {
3041
+ width: R.width,
3042
+ height: R.height,
3040
3043
  visemePaths: [...w.cellByPath.keys()]
3041
3044
  };
3042
3045
  },
@@ -3044,43 +3047,43 @@ async function la(e, t = {}) {
3044
3047
  return G;
3045
3048
  },
3046
3049
  drawLiveFrame(v) {
3047
- o || s || !m || (oe(v), le());
3050
+ o || s || !h || (de(v), ue());
3048
3051
  },
3049
- drawIdleVideo(v, T) {
3050
- o || s || document.hidden || T && !T() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (X(), d.visible = !1, !I || R !== v ? (J(), _ = new Qn({
3052
+ drawIdleVideo(v, E) {
3053
+ o || s || document.hidden || E && !E() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (J(), d.visible = !1, !M || D !== v ? (X(), _ = new Qn({
3051
3054
  resource: v,
3052
3055
  autoPlay: !1,
3053
3056
  updateFPS: 0
3054
- }), _.autoUpdate = !1, I = new we({ source: _ }), R = v) : I.source.update(), l.texture = I, l.visible = !0, l.x = 0, l.y = 0, l.width = L, l.height = B, le());
3057
+ }), _.autoUpdate = !1, M = new ge({ source: _ }), D = v) : M.source.update(), l.texture = M, l.visible = !0, l.x = 0, l.y = 0, l.width = L, l.height = B, ue());
3055
3058
  },
3056
3059
  renderSilOnly() {
3057
- o || s || !m || (X(), z(), le());
3060
+ o || s || !h || (J(), j(), ue());
3058
3061
  },
3059
3062
  blitBitmap(v) {
3060
- o || s || (X(), U && (U.destroy(!0), U = null), U = we.from(v), d.texture = U, d.visible = !0, d.x = 0, d.y = 0, d.width = L, d.height = B, l.visible = !1, le());
3063
+ o || s || (J(), I && (I.destroy(!0), I = null), I = ge.from(v), d.texture = I, d.visible = !0, d.x = 0, d.y = 0, d.width = L, d.height = B, l.visible = !1, ue());
3061
3064
  },
3062
3065
  async compositePrefetchFrame(v) {
3063
3066
  return null;
3064
3067
  },
3065
- renderFrame: le,
3068
+ renderFrame: ue,
3066
3069
  isContextLost() {
3067
3070
  return s;
3068
3071
  },
3069
3072
  dispose() {
3070
3073
  if (o) return;
3071
- o = !0, a.removeEventListener("webglcontextlost", u), O(), J(), U && (U.destroy(!0), U = null);
3072
- for (const { texture: T, ownsSource: h } of k.values())
3073
- T.destroy(h);
3074
- k.clear(), m && (m.destroy(!0), m = null);
3075
- const v = (T) => {
3076
- T.mode === "full" ? T.texture.destroy(!0) : T.bitmap.close();
3074
+ o = !0, a.removeEventListener("webglcontextlost", u), te(), X(), I && (I.destroy(!0), I = null);
3075
+ for (const { texture: E, ownsSource: m } of k.values())
3076
+ E.destroy(m);
3077
+ k.clear(), h && (h.destroy(!0), h = null);
3078
+ const v = (E) => {
3079
+ E.mode === "full" ? E.texture.destroy(!0) : E.bitmap.close();
3077
3080
  };
3078
3081
  if (w)
3079
- for (const T of w.sheets.values())
3080
- v(T);
3082
+ for (const E of w.sheets.values())
3083
+ v(E);
3081
3084
  if (b)
3082
- for (const T of b.sheets.values())
3083
- v(T);
3085
+ for (const E of b.sheets.values())
3086
+ v(E);
3084
3087
  g.destroy(!0), S.destroy(!0), r.destroy(
3085
3088
  { removeView: !1 },
3086
3089
  { children: !0, texture: !0 }
@@ -3088,7 +3091,7 @@ async function la(e, t = {}) {
3088
3091
  }
3089
3092
  };
3090
3093
  }
3091
- const Zr = -1, Ct = 1e5, en = /* @__PURE__ */ new Map();
3094
+ const Zr = -1, Bt = 1e5, en = /* @__PURE__ */ new Map();
3092
3095
  async function fa(e) {
3093
3096
  let t = en.get(e);
3094
3097
  if (!t) {
@@ -3146,7 +3149,7 @@ function tn(e, t) {
3146
3149
  r += 1;
3147
3150
  const a = r;
3148
3151
  t.onStatus?.(o), await sr(i, {
3149
- mouthPath: bt(o),
3152
+ mouthPath: vt(o),
3150
3153
  expressionPath: null
3151
3154
  });
3152
3155
  },
@@ -3158,52 +3161,52 @@ function tn(e, t) {
3158
3161
  function ma(e, t, r) {
3159
3162
  let n = null, s = 1, i = 0, o = !1, a = !1, u = null;
3160
3163
  const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
3161
- let c = Ct;
3162
- const d = Tr(async (R, w, b) => (l.set(w, {
3164
+ let c = Bt;
3165
+ const d = Tr(async (D, w, b) => (l.set(w, {
3163
3166
  drawKey: b.drawKey,
3164
3167
  onDisplayed: b.onDisplayed
3165
- }), await I(
3168
+ }), await M(
3166
3169
  {
3167
3170
  type: "drawFrame",
3168
- diffPath: R.mouthPath,
3169
- expressionDiffPath: R.expressionPath,
3171
+ diffPath: D.mouthPath,
3172
+ expressionDiffPath: D.expressionPath,
3170
3173
  liveSeq: w
3171
3174
  },
3172
3175
  void 0,
3173
3176
  !0
3174
- ), !1)), g = (R) => {
3175
- if (R === Zr) {
3177
+ ), !1)), g = (D) => {
3178
+ if (D === Zr) {
3176
3179
  let L = -1, B;
3177
3180
  for (const [G, C] of l)
3178
3181
  G >= L && (L = G, B = C);
3179
3182
  L >= 0 && l.delete(L), B?.onDisplayed?.(B.drawKey);
3180
3183
  return;
3181
3184
  }
3182
- const w = -R, b = l.get(w);
3185
+ const w = -D, b = l.get(w);
3183
3186
  l.delete(w), b?.onDisplayed?.(b.drawKey);
3184
- }, S = /* @__PURE__ */ new Map(), m = (R, w) => {
3185
- a || !n || n.postMessage(R, []);
3186
- }, I = (R, w, b = !1) => {
3187
+ }, S = /* @__PURE__ */ new Map(), h = (D, w) => {
3188
+ a || !n || n.postMessage(D, []);
3189
+ }, M = (D, w, b = !1) => {
3187
3190
  if (a) return Promise.resolve();
3188
3191
  const L = s++;
3189
3192
  return new Promise((B, G) => {
3190
3193
  S.set(L, {
3191
3194
  resolve: (C) => B(C),
3192
3195
  reject: G,
3193
- generation: typeof R.generation == "number" ? R.generation : void 0,
3196
+ generation: typeof D.generation == "number" ? D.generation : void 0,
3194
3197
  expectRenderDone: b
3195
- }), m({ ...R, requestId: L });
3198
+ }), h({ ...D, requestId: L });
3196
3199
  });
3197
3200
  }, _ = (async () => {
3198
- n = await fa(r), n.onmessage = (R) => {
3201
+ n = await fa(r), n.onmessage = (D) => {
3199
3202
  if (a) return;
3200
- const w = R.data;
3203
+ const w = D.data;
3201
3204
  if (w.type === "status") {
3202
3205
  t.onStatus?.(w.label);
3203
3206
  return;
3204
3207
  }
3205
3208
  if (w.type === "frame") {
3206
- if (w.generation <= -Ct) {
3209
+ if (w.generation <= -Bt) {
3207
3210
  const B = -w.generation, G = f.get(B);
3208
3211
  f.delete(B), G?.resolve(w.bitmap);
3209
3212
  return;
@@ -3216,12 +3219,12 @@ function ma(e, t, r) {
3216
3219
  if (L && !(w.generation === Zr)) {
3217
3220
  const G = -w.generation;
3218
3221
  if (!d.isLatestSeq(G)) {
3219
- Ue()?.onWorkerStale(), w.bitmap.close();
3222
+ Ne()?.onWorkerStale(), w.bitmap.close();
3220
3223
  return;
3221
3224
  }
3222
3225
  }
3223
3226
  if (L && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
3224
- Ue()?.onWorkerStale(), w.bitmap.close();
3227
+ Ne()?.onWorkerStale(), w.bitmap.close();
3225
3228
  return;
3226
3229
  }
3227
3230
  ir(e, w.bitmap), w.bitmap.close(), L && g(w.generation);
@@ -3248,26 +3251,26 @@ function ma(e, t, r) {
3248
3251
  S.delete(w.requestId), t.onError?.(w.message), b.reject(new Error(w.message));
3249
3252
  break;
3250
3253
  }
3251
- }, n.onerror = (R) => {
3254
+ }, n.onerror = (D) => {
3252
3255
  if (a) return;
3253
- const w = R.message || "Worker error";
3256
+ const w = D.message || "Worker error";
3254
3257
  t.onError?.(w);
3255
3258
  for (const [, b] of S)
3256
3259
  b.reject(new Error(w));
3257
3260
  S.clear();
3258
- }, await I({ type: "init" }), o = !0;
3261
+ }, await M({ type: "init" }), o = !0;
3259
3262
  })();
3260
3263
  return {
3261
3264
  usesWorker: !0,
3262
3265
  usesPixi: !1,
3263
- async loadAssets(R) {
3266
+ async loadAssets(D) {
3264
3267
  if (a) return { width: 842, height: 1264 };
3265
3268
  if (await _, a) return { width: 842, height: 1264 };
3266
3269
  if (!o) throw new Error("Worker init failed");
3267
- return await I({
3270
+ return await M({
3268
3271
  type: "loadAssets",
3269
- keyHex: R,
3270
- urls: Es(je())
3272
+ keyHex: D,
3273
+ urls: Es(ze())
3271
3274
  }) ?? { width: 842, height: 1264 };
3272
3275
  },
3273
3276
  getVisemeAtlasPaths() {
@@ -3275,29 +3278,29 @@ function ma(e, t, r) {
3275
3278
  },
3276
3279
  async renderSilOnly() {
3277
3280
  if (a || (await _, a)) return;
3278
- i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c = Ct;
3279
- const R = i;
3280
- await I({ type: "cancelLiveDraws" }), await I(
3281
- { type: "renderSil", generation: R },
3281
+ i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c = Bt;
3282
+ const D = i;
3283
+ await M({ type: "cancelLiveDraws" }), await M(
3284
+ { type: "renderSil", generation: D },
3282
3285
  void 0,
3283
3286
  !0
3284
3287
  );
3285
3288
  },
3286
- drawLiveFrame(R, w, b, L) {
3289
+ drawLiveFrame(D, w, b, L) {
3287
3290
  a || _.then(() => {
3288
3291
  a || d.enqueue(w, b, L);
3289
3292
  });
3290
3293
  },
3291
- compositePrefetchFrame(R, w) {
3294
+ compositePrefetchFrame(D, w) {
3292
3295
  return a ? Promise.resolve(null) : _.then(() => {
3293
3296
  if (a) return null;
3294
3297
  const b = ++c;
3295
3298
  return new Promise((L) => {
3296
- f.set(b, { resolve: L }), I(
3299
+ f.set(b, { resolve: L }), M(
3297
3300
  {
3298
3301
  type: "drawFrame",
3299
- diffPath: R.mouthPath,
3300
- expressionDiffPath: R.expressionPath,
3302
+ diffPath: D.mouthPath,
3303
+ expressionDiffPath: D.expressionPath,
3301
3304
  liveSeq: b
3302
3305
  },
3303
3306
  void 0,
@@ -3308,18 +3311,18 @@ function ma(e, t, r) {
3308
3311
  });
3309
3312
  });
3310
3313
  },
3311
- blitBitmap(R, w) {
3312
- ir(R, w);
3314
+ blitBitmap(D, w) {
3315
+ ir(D, w);
3313
3316
  },
3314
3317
  drawIdleVideo() {
3315
3318
  },
3316
3319
  supportsBufferedPlayback: !0,
3317
- async renderViseme(R, w, b = {}) {
3320
+ async renderViseme(D, w, b = {}) {
3318
3321
  if (a || (await _, a)) return;
3319
3322
  i += 1, d.reset(), l.clear();
3320
3323
  const L = i;
3321
3324
  try {
3322
- await I({ type: "cancelLiveDraws" }), await I(
3325
+ await M({ type: "cancelLiveDraws" }), await M(
3323
3326
  {
3324
3327
  type: "renderViseme",
3325
3328
  generation: L,
@@ -3339,9 +3342,9 @@ function ma(e, t, r) {
3339
3342
  },
3340
3343
  dispose() {
3341
3344
  if (!a) {
3342
- a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: R }) => R(null)), f.clear(), c = Ct;
3343
- for (const [, R] of S)
3344
- R.resolve();
3345
+ a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: D }) => D(null)), f.clear(), c = Bt;
3346
+ for (const [, D] of S)
3347
+ D.resolve();
3345
3348
  S.clear(), n?.terminate(), n = null;
3346
3349
  }
3347
3350
  }
@@ -3353,7 +3356,7 @@ async function ha(e, t) {
3353
3356
  maxTextureSize: t.pixiMaxTextureSize
3354
3357
  });
3355
3358
  let n = 0, s = null, i = !1;
3356
- const o = Tr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (Ue()?.onWorkerStale(), !1) : (r.drawLiveFrame(a), o.isLatestSeq(u)));
3359
+ const o = Tr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (Ne()?.onWorkerStale(), !1) : (r.drawLiveFrame(a), o.isLatestSeq(u)));
3357
3360
  return {
3358
3361
  usesWorker: !1,
3359
3362
  usesPixi: !0,
@@ -3393,7 +3396,7 @@ async function ha(e, t) {
3393
3396
  n += 1;
3394
3397
  const l = n;
3395
3398
  o.reset(), t.onStatus?.(u), r.drawLiveFrame({
3396
- mouthPath: bt(u),
3399
+ mouthPath: vt(u),
3397
3400
  expressionPath: null
3398
3401
  });
3399
3402
  },
@@ -3512,10 +3515,10 @@ const ga = {
3512
3515
  fontSize: "0.875rem",
3513
3516
  textAlign: "center"
3514
3517
  };
3515
- function _t(e) {
3518
+ function gt(e) {
3516
3519
  return fs(e) ? Sn : vn;
3517
3520
  }
3518
- function Oe(e, t) {
3521
+ function Le(e, t) {
3519
3522
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
3520
3523
  }
3521
3524
  const Ma = Hn(function({
@@ -3525,18 +3528,18 @@ const Ma = Hn(function({
3525
3528
  assets: s,
3526
3529
  authToken: i,
3527
3530
  apiBase: o,
3528
- ttsEngineId: a = nt,
3531
+ ttsEngineId: a = tt,
3529
3532
  voiceId: u,
3530
- speakingRate: l = Wt,
3533
+ speakingRate: l = Vt,
3531
3534
  className: f,
3532
3535
  style: c,
3533
3536
  canvasStyle: d,
3534
3537
  onStatusChange: g,
3535
3538
  onDisplayStatus: S,
3536
- onError: m,
3537
- onReady: I,
3539
+ onError: h,
3540
+ onReady: M,
3538
3541
  showErrorOverlay: _ = !0,
3539
- onUserTranscript: R,
3542
+ onUserTranscript: D,
3540
3543
  onBotOutput: w,
3541
3544
  onRealtimeLipsyncDebug: b,
3542
3545
  onFrameRenderStats: L,
@@ -3544,458 +3547,458 @@ const Ma = Hn(function({
3544
3547
  lipsyncPlaybackWarmupMs: G = 1500,
3545
3548
  pixiMaxTextureSize: C
3546
3549
  }, k) {
3547
- const P = H(null), D = H(null), U = H(null), O = H(B);
3548
- O.current = B;
3549
- const me = H(G);
3550
- me.current = G;
3551
- const X = H(0), z = H(Sr()), J = H(Ri()), ne = H(0), ee = H(0), ge = H(0), oe = H(null), le = H(null), v = H(!1), T = H(!1), h = H(!1), E = H("sil"), M = H(0), F = H(!1), A = H(
3550
+ const P = H(null), N = H(null), I = H(null), te = H(B);
3551
+ te.current = B;
3552
+ const V = H(G);
3553
+ V.current = G;
3554
+ const J = H(0), j = H(Sr()), X = H(Ri()), pe = H(0), re = H(0), fe = H(0), de = H(null), ue = H(null), v = H(!1), E = H(!1), m = H(!1), T = H("sil"), R = H(0), F = H(!1), A = H(
3552
3555
  null
3553
- ), $ = H(!1), [Y, Q] = tt("idle"), [Z, xe] = tt(null), [be, Fe] = tt(!1), [ut, Ie] = tt(!1), [p, x] = tt({ width: 842, height: 1264 }), [j, ie] = tt(0), he = H(!1), _e = H(i ?? null), ce = o?.trim() || kt, Me = H(null), fe = H(null), Ve = H(!1), Ye = H({ width: 842, height: 1264 }), ve = H(null), lt = H("sil"), Xe = H(void 0), ft = H(/* @__PURE__ */ new Map()), Ne = H(I), ue = H(S), dt = H(m), Je = H(R), de = H(w), pe = H(b), ke = H(L), Re = H(qi());
3554
- Ne.current = I, ue.current = S, dt.current = m, Je.current = R, de.current = w, pe.current = b, ke.current = L, $e(() => {
3555
- const y = Re.current;
3556
+ ), $ = H(!1), [Y, Q] = Ze("idle"), [Z, be] = Ze(null), [ke, Be] = Ze(!1), [ot, Me] = Ze(!1), [Ht, p] = Ze({ width: 842, height: 1264 }), [x, z] = Ze(0), ne = H(!1), ce = H(i ?? null), Te = o?.trim() || St, me = H(null), he = H(null), _e = H(!1), ct = H({ width: 842, height: 1264 }), Ce = H(null), Oe = H("sil"), Ue = H(void 0), ut = H(/* @__PURE__ */ new Map()), kt = H(M), ie = H(S), lt = H(h), ft = H(D), je = H(w), le = H(b), ve = H(L), we = H(qi());
3557
+ kt.current = M, ie.current = S, lt.current = h, ft.current = D, je.current = w, le.current = b, ve.current = L, He(() => {
3558
+ const y = we.current;
3556
3559
  return Gr(y), () => Gr(null);
3557
3560
  }, []);
3558
- const mt = Ae(
3561
+ const Ye = xe(
3559
3562
  (y) => {
3560
- const N = y?.ttsEngineId ?? a ?? fe.current?.ttsEngineId ?? nt, W = y?.voiceId ?? u ?? fe.current?.voiceId ?? _t(N);
3561
- return { ttsEngineId: N, voiceId: W };
3563
+ const O = y?.ttsEngineId ?? a ?? he.current?.ttsEngineId ?? tt, W = y?.voiceId ?? u ?? he.current?.voiceId ?? gt(O);
3564
+ return { ttsEngineId: O, voiceId: W };
3562
3565
  },
3563
3566
  [a, u]
3564
- ), De = Ae((y) => {
3565
- xe(y), dt.current?.(y);
3566
- }, []), We = Ae(
3567
+ ), Ee = xe((y) => {
3568
+ be(y), lt.current?.(y);
3569
+ }, []), Ve = xe(
3567
3570
  (y) => {
3568
3571
  Q(y), g?.(y);
3569
3572
  },
3570
3573
  [g]
3571
- ), te = H(
3572
- Or(We, ce, {
3573
- onLipsyncDebug: (y) => pe.current?.(y)
3574
+ ), ee = H(
3575
+ Or(Ve, Te, {
3576
+ onLipsyncDebug: (y) => le.current?.(y)
3574
3577
  })
3575
- ), se = H(null);
3576
- $e(() => (te.current = Or(
3577
- We,
3578
- ce,
3578
+ ), ae = H(null);
3579
+ He(() => (ee.current = Or(
3580
+ Ve,
3581
+ Te,
3579
3582
  {
3580
- onLipsyncDebug: (y) => pe.current?.(y)
3583
+ onLipsyncDebug: (y) => le.current?.(y)
3581
3584
  }
3582
- ), i && te.current.setDeveloperToken(i), te.current.setTtsEngineId(a), () => {
3583
- te.current.stop();
3584
- const y = se.current;
3585
- y && (y.disconnect(), se.current = null);
3586
- }), [We, i, a, ce]);
3587
- const Er = Ae(() => (se.current || (se.current = si(
3588
- We,
3585
+ ), i && ee.current.setDeveloperToken(i), ee.current.setTtsEngineId(a), () => {
3586
+ ee.current.stop();
3587
+ const y = ae.current;
3588
+ y && (y.disconnect(), ae.current = null);
3589
+ }), [Ve, i, a, Te]);
3590
+ const Er = xe(() => (ae.current || (ae.current = si(
3591
+ Ve,
3589
3592
  {
3590
3593
  speakingRate: l,
3591
- onUserTranscript: (y, N) => Je.current?.(y, N),
3592
- onBotOutput: (y) => de.current?.(y),
3593
- onLipsyncDebug: (y) => pe.current?.(y)
3594
+ onUserTranscript: (y, O) => ft.current?.(y, O),
3595
+ onBotOutput: (y) => je.current?.(y),
3596
+ onLipsyncDebug: (y) => le.current?.(y)
3594
3597
  }
3595
- ), se.current.setTtsEngineId(a)), se.current), [We, l, a]), Te = Ae(() => {
3596
- oe.current != null && (clearTimeout(oe.current), oe.current = null);
3597
- }, []), Le = Ae(() => {
3598
- le.current != null && (clearTimeout(le.current), le.current = null), h.current = !1;
3599
- }, []), Ar = Ae(() => {
3600
- !$.current || !A.current || (Le(), h.current = !0, le.current = setTimeout(() => {
3601
- if (le.current = null, Oe(
3602
- te.current,
3603
- se.current
3598
+ ), ae.current.setTtsEngineId(a)), ae.current), [Ve, l, a]), Ae = xe(() => {
3599
+ de.current != null && (clearTimeout(de.current), de.current = null);
3600
+ }, []), Fe = xe(() => {
3601
+ ue.current != null && (clearTimeout(ue.current), ue.current = null), m.current = !1;
3602
+ }, []), Ar = xe(() => {
3603
+ !$.current || !A.current || (Fe(), m.current = !0, ue.current = setTimeout(() => {
3604
+ if (ue.current = null, Le(
3605
+ ee.current,
3606
+ ae.current
3604
3607
  ).isSpeaking()) {
3605
- h.current = !1;
3608
+ m.current = !1;
3606
3609
  return;
3607
3610
  }
3608
3611
  if (v.current) {
3609
- h.current = !1;
3612
+ m.current = !1;
3610
3613
  return;
3611
3614
  }
3612
3615
  const y = A.current;
3613
3616
  if (!y) {
3614
- h.current = !1;
3617
+ m.current = !1;
3615
3618
  return;
3616
3619
  }
3617
3620
  y.restart(), y.setActive(!0);
3618
- const N = y.getVideo();
3621
+ const O = y.getVideo();
3619
3622
  let W = !1;
3620
3623
  const K = () => {
3621
- W || (W = !0, N.removeEventListener("playing", q), h.current = !1);
3624
+ W || (W = !0, O.removeEventListener("playing", q), m.current = !1);
3622
3625
  }, q = () => {
3623
3626
  K();
3624
3627
  };
3625
- if (N.addEventListener("playing", q, { once: !0 }), N.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !N.paused) {
3628
+ if (O.addEventListener("playing", q, { once: !0 }), O.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !O.paused) {
3626
3629
  K();
3627
3630
  return;
3628
3631
  }
3629
3632
  setTimeout(K, 300);
3630
3633
  }, Ki));
3631
- }, [Le]), Qe = Ae(() => {
3632
- if (Te(), ue.current?.("sil"), v.current = !1, !$.current || !A.current) {
3633
- h.current = !1;
3634
+ }, [Fe]), Xe = xe(() => {
3635
+ if (Ae(), ie.current?.("sil"), v.current = !1, !$.current || !A.current) {
3636
+ m.current = !1;
3634
3637
  return;
3635
3638
  }
3636
3639
  Ar();
3637
- }, [Te, Ar]), $t = Ae(
3640
+ }, [Ae, Ar]), $t = xe(
3638
3641
  async (y) => {
3639
- const N = ee.current, W = D.current, K = P.current, q = () => {
3642
+ const O = re.current, W = N.current, K = P.current, q = () => {
3640
3643
  y?.fallbackOnly || (v.current = !1);
3641
3644
  };
3642
- if (!W || !K || !be) {
3645
+ if (!W || !K || !ke) {
3643
3646
  q();
3644
3647
  return;
3645
3648
  }
3646
- if (Oe(
3647
- te.current,
3648
- se.current
3649
+ if (Le(
3650
+ ee.current,
3651
+ ae.current
3649
3652
  ).isSpeaking()) {
3650
3653
  q();
3651
3654
  return;
3652
3655
  }
3653
3656
  if (y?.fallbackOnly) {
3654
- if (!v.current || (Pe(z.current), await W.renderSilOnly(), N !== ee.current) || Oe(
3655
- te.current,
3656
- se.current
3657
+ if (!v.current || (Ie(j.current), await W.renderSilOnly(), O !== re.current) || Le(
3658
+ ee.current,
3659
+ ae.current
3657
3660
  ).isSpeaking())
3658
3661
  return;
3659
- Qe();
3662
+ Xe();
3660
3663
  return;
3661
3664
  }
3662
- if (jr(z.current)) {
3663
- Pe(z.current), Qe();
3665
+ if (jr(j.current)) {
3666
+ Ie(j.current), Xe();
3664
3667
  return;
3665
3668
  }
3666
- if (O.current && W.supportsBufferedPlayback && !y?.fallbackOnly) {
3667
- if (Pe(z.current), U.current?.reset(), await W.renderSilOnly(), N !== ee.current || Oe(
3668
- te.current,
3669
- se.current
3669
+ if (te.current && W.supportsBufferedPlayback && !y?.fallbackOnly) {
3670
+ if (Ie(j.current), I.current?.reset(), await W.renderSilOnly(), O !== re.current || Le(
3671
+ ee.current,
3672
+ ae.current
3670
3673
  ).isSpeaking())
3671
3674
  return;
3672
- Qe();
3675
+ Xe();
3673
3676
  return;
3674
3677
  }
3675
- const Ee = Xi(
3676
- Oe(
3677
- te.current,
3678
- se.current
3678
+ const Pe = Xi(
3679
+ Le(
3680
+ ee.current,
3681
+ ae.current
3679
3682
  ).getVisemeQueue(),
3680
- M.current,
3681
- E.current
3682
- ), pt = Ji(
3683
- Ee,
3684
- ve.current
3683
+ R.current,
3684
+ T.current
3685
+ ), mt = Ji(
3686
+ Pe,
3687
+ Ce.current
3685
3688
  );
3686
- if (Pe(z.current), !pt) {
3687
- if (await W.renderSilOnly(), N !== ee.current || Oe(
3688
- te.current,
3689
- se.current
3689
+ if (Ie(j.current), !mt) {
3690
+ if (await W.renderSilOnly(), O !== re.current || Le(
3691
+ ee.current,
3692
+ ae.current
3690
3693
  ).isSpeaking())
3691
3694
  return;
3692
- Qe();
3695
+ Xe();
3693
3696
  return;
3694
3697
  }
3695
3698
  try {
3696
3699
  await W.renderViseme(K, "sil", {
3697
- from: Ee,
3700
+ from: Pe,
3698
3701
  transitionDurationMs: Fn
3699
3702
  });
3700
- } catch (Ze) {
3701
- if (Ze?.name !== "AbortError")
3702
- throw Ze;
3703
+ } catch (Je) {
3704
+ if (Je?.name !== "AbortError")
3705
+ throw Je;
3703
3706
  }
3704
- if (N !== ee.current) {
3707
+ if (O !== re.current) {
3705
3708
  q();
3706
3709
  return;
3707
3710
  }
3708
- if (Oe(
3709
- te.current,
3710
- se.current
3711
+ if (Le(
3712
+ ee.current,
3713
+ ae.current
3711
3714
  ).isSpeaking()) {
3712
3715
  q();
3713
3716
  return;
3714
3717
  }
3715
- Qe();
3718
+ Xe();
3716
3719
  },
3717
- [be, Qe]
3718
- ), ht = Ae(() => {
3719
- if (T.current || v.current) return;
3720
- T.current = !0, v.current = !0, Te();
3721
- const y = ee.current;
3720
+ [ke, Xe]
3721
+ ), dt = xe(() => {
3722
+ if (E.current || v.current) return;
3723
+ E.current = !0, v.current = !0, Ae();
3724
+ const y = re.current;
3722
3725
  $t().finally(() => {
3723
- T.current = !1;
3724
- }), oe.current = setTimeout(() => {
3725
- oe.current = null, y === ee.current && $t({ fallbackOnly: !0 });
3726
+ E.current = !1;
3727
+ }), de.current = setTimeout(() => {
3728
+ de.current = null, y === re.current && $t({ fallbackOnly: !0 });
3726
3729
  }, Qi());
3727
- }, [Te, $t]), Pr = Ae(async () => {
3730
+ }, [Ae, $t]), Pr = xe(async () => {
3728
3731
  const y = Math.floor(Date.now() / 1e3);
3729
- if (Me.current && y < Me.current.expiresAt - 60)
3730
- return Me.current.key;
3731
- const N = _e.current ?? await jt();
3732
- _e.current = N, te.current.setDeveloperToken(N);
3733
- const W = await _s(N, ce);
3734
- return Me.current = {
3732
+ if (me.current && y < me.current.expiresAt - 60)
3733
+ return me.current.key;
3734
+ const O = ce.current ?? await jt();
3735
+ ce.current = O, ee.current.setDeveloperToken(O);
3736
+ const W = await _s(O, Te);
3737
+ return me.current = {
3735
3738
  key: W.value,
3736
3739
  expiresAt: W.expiresAt
3737
3740
  }, W.value;
3738
- }, [ce]);
3739
- $e(() => {
3740
- i && (_e.current = i, te.current.setDeveloperToken(i));
3741
- }, [i]), $e(() => {
3742
- te.current.setTtsEngineId(a), se.current?.setTtsEngineId(a), fe.current && (fe.current.ttsEngineId = a);
3743
- }, [a]), $e(() => {
3744
- const y = u ?? _t(a);
3745
- fe.current && (fe.current.voiceId = y);
3741
+ }, [Te]);
3742
+ He(() => {
3743
+ i && (ce.current = i, ee.current.setDeveloperToken(i));
3744
+ }, [i]), He(() => {
3745
+ ee.current.setTtsEngineId(a), ae.current?.setTtsEngineId(a), he.current && (he.current.ttsEngineId = a);
3746
+ }, [a]), He(() => {
3747
+ const y = u ?? gt(a);
3748
+ he.current && (he.current.voiceId = y);
3746
3749
  }, [u, a]);
3747
- const He = Mr(
3750
+ const We = Mr(
3748
3751
  () => ks(r, n),
3749
3752
  [r, n]
3750
- ), Un = Mr(() => s ? JSON.stringify(s) : He ? `face:${He}` : `id:${t ?? ""}`, [s, He, t]);
3751
- return $e(() => {
3752
- if (!t && !s && !He) {
3753
- De("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
3753
+ ), Un = Mr(() => s ? JSON.stringify(s) : We ? `face:${We}` : `id:${t ?? ""}`, [s, We, t]);
3754
+ return He(() => {
3755
+ if (!t && !s && !We) {
3756
+ Ee("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
3754
3757
  return;
3755
3758
  }
3756
3759
  let y = !1;
3757
- Ve.current = !1, Fe(!1), Ie(!1), xe(null), fe.current = null, A.current = null, $.current = !1;
3758
- const N = P.current;
3759
- if (!N) return;
3760
+ _e.current = !1, Be(!1), Me(!1), be(null), he.current = null, A.current = null, $.current = !1;
3761
+ const O = P.current;
3762
+ if (!O) return;
3760
3763
  let W = null;
3761
3764
  return (async () => {
3762
3765
  try {
3763
- let K, q, Se, Ee;
3766
+ let K, q, Se, Pe;
3764
3767
  if (s)
3765
- K = s, q = a, Se = u ?? _t(q);
3766
- else if (He)
3767
- ue.current?.("loadFace"), K = Br(He), q = a, Se = u ?? _t(q);
3768
+ K = s, q = a, Se = u ?? gt(q);
3769
+ else if (We)
3770
+ ie.current?.("loadFace"), K = Br(We), q = a, Se = u ?? gt(q);
3768
3771
  else {
3769
- ue.current?.("getAiTwin");
3770
- const V = await Jt(
3772
+ ie.current?.("getAiTwin");
3773
+ const U = await Jt(
3771
3774
  ms(t),
3772
3775
  3e4,
3773
3776
  "getAiTwin"
3774
3777
  );
3775
3778
  if (y) return;
3776
- if (!V.faceId?.trim())
3779
+ if (!U.faceId?.trim())
3777
3780
  throw new Error("getAiTwin returned no faceId");
3778
- q = V.ttsEngineId, Se = u ?? V.voiceId ?? _t(q), Ee = V.knowledgeContextId?.trim() || void 0, K = Br(V.faceId);
3781
+ q = U.ttsEngineId, Se = u ?? U.voiceId ?? gt(q), Pe = U.knowledgeContextId?.trim() || void 0, K = Br(U.faceId);
3779
3782
  }
3780
- fe.current = { ttsEngineId: q, voiceId: Se, personaId: Ee }, Ts(K), A.current = Di();
3781
- const pt = !!(s && !ze(s));
3782
- W = pa(N, {
3783
- preferLegacyRenderer: pt,
3783
+ he.current = { ttsEngineId: q, voiceId: Se, personaId: Pe }, Ts(K), A.current = Di();
3784
+ const mt = !!(s && !Ge(s));
3785
+ W = pa(O, {
3786
+ preferLegacyRenderer: mt,
3784
3787
  pixiMaxTextureSize: C,
3785
- onStatus: (V) => {
3786
- y || ue.current?.(V);
3788
+ onStatus: (U) => {
3789
+ y || ie.current?.(U);
3787
3790
  },
3788
- onError: (V) => {
3789
- y || De(V);
3791
+ onError: (U) => {
3792
+ y || Ee(U);
3790
3793
  },
3791
3794
  shouldAcceptLiveFrame: () => {
3792
- const V = Oe(
3793
- te.current,
3794
- se.current
3795
+ const U = Le(
3796
+ ee.current,
3797
+ ae.current
3795
3798
  );
3796
- return (V.isSpeaking() || V.isWarmingUp()) && !v.current;
3799
+ return (U.isSpeaking() || U.isWarmingUp()) && !v.current;
3797
3800
  },
3798
3801
  onWebGlContextLost: () => {
3799
- y || he.current || (he.current = !0, queueMicrotask(() => {
3800
- y || ie((V) => V + 1);
3802
+ y || ne.current || (ne.current = !0, queueMicrotask(() => {
3803
+ y || z((U) => U + 1);
3801
3804
  }));
3802
3805
  }
3803
- }), D.current = W, U.current = na(W), he.current = !1, ((V) => {
3804
- const ae = () => {
3805
- if (!V || me.current <= 0)
3806
+ }), N.current = W, I.current = na(W), ne.current = !1, ((U) => {
3807
+ const oe = () => {
3808
+ if (!U || V.current <= 0)
3806
3809
  return !1;
3807
- const ye = D.current;
3808
- return ye ? O.current && ye.supportsBufferedPlayback ? !0 : ye.usesPixi : !1;
3810
+ const ye = N.current;
3811
+ return ye ? te.current && ye.supportsBufferedPlayback ? !0 : ye.usesPixi : !1;
3809
3812
  };
3810
- te.current.setLipsyncWarmupHold(V, ae), se.current?.setLipsyncWarmupHold(V, ae);
3811
- })(!0), ue.current?.("auth");
3812
- const wt = _e.current ?? i ?? await Jt(jt(), 3e4, "getAuthToken");
3813
+ ee.current.setLipsyncWarmupHold(U, oe), ae.current?.setLipsyncWarmupHold(U, oe);
3814
+ })(!0), ie.current?.("auth");
3815
+ const ht = ce.current ?? i ?? await Jt(jt(), 3e4, "getAuthToken");
3813
3816
  if (y) return;
3814
- _e.current = wt, te.current.setDeveloperToken(wt), te.current.setTtsEngineId(q);
3815
- const Et = Tt() ? await Pr() : void 0;
3817
+ ce.current = ht, ee.current.setDeveloperToken(ht), ee.current.setTtsEngineId(q);
3818
+ const Tt = bt() ? await Pr() : void 0;
3816
3819
  if (y) return;
3817
- ue.current?.("loadAssets");
3818
- const re = await Jt(
3819
- W.loadAssets(Et),
3820
+ ie.current?.("loadAssets");
3821
+ const se = await Jt(
3822
+ W.loadAssets(Tt),
3820
3823
  18e4,
3821
3824
  "load face assets"
3822
3825
  );
3823
- if (!y && re.width > 0 && re.height > 0 && (Ye.current = re, x(re)), y) return;
3824
- ve.current = W.getVisemeAtlasPaths(), Ve.current = !0, Fe(!0), Ne.current?.(), W.renderSilOnly().then(() => {
3825
- y || ue.current?.("sil");
3826
+ if (!y && se.width > 0 && se.height > 0 && (ct.current = se, p(se)), y) return;
3827
+ Ce.current = W.getVisemeAtlasPaths(), _e.current = !0, Be(!0), kt.current?.(), W.renderSilOnly().then(() => {
3828
+ y || ie.current?.("sil");
3826
3829
  }), (async () => {
3827
3830
  try {
3828
- const V = await li(Et);
3829
- if (await A.current.load(V), y) return;
3830
- $.current = !0, Ie(!0), Pe(z.current), A.current.setActive(!0);
3831
- const ae = A.current.getVideo();
3832
- W.usesPixi ? W.drawIdleVideo(ae) : await Kr(
3833
- N,
3834
- ae,
3831
+ const U = await li(Tt);
3832
+ if (await A.current.load(U), y) return;
3833
+ $.current = !0, Me(!0), Ie(j.current), A.current.setActive(!0);
3834
+ const oe = A.current.getVideo();
3835
+ W.usesPixi ? W.drawIdleVideo(oe) : await Kr(
3836
+ O,
3837
+ oe,
3835
3838
  null,
3836
3839
  void 0,
3837
- Ye.current
3838
- ), y || ue.current?.("idle");
3839
- } catch (V) {
3840
+ ct.current
3841
+ ), y || ie.current?.("idle");
3842
+ } catch (U) {
3840
3843
  if (y) return;
3841
- $.current = !1, Ie(!1), console.warn("[AiTwin] Idle video unavailable:", V);
3844
+ $.current = !1, Me(!1), console.warn("[AiTwin] Idle video unavailable:", U);
3842
3845
  }
3843
3846
  })();
3844
3847
  } catch (K) {
3845
3848
  if (y) return;
3846
3849
  if (K instanceof Qt) {
3847
- De(K.message);
3850
+ Ee(K.message);
3848
3851
  return;
3849
3852
  }
3850
- De(K instanceof Error ? K.message : "Failed to load AI twin");
3853
+ Ee(K instanceof Error ? K.message : "Failed to load AI twin");
3851
3854
  }
3852
3855
  })(), () => {
3853
- y = !0, A.current?.dispose(), W?.dispose(), D.current = null;
3856
+ y = !0, A.current?.dispose(), W?.dispose(), N.current = null;
3854
3857
  };
3855
- }, [Un, s, He, t, a, u, i, C, Pr, De, j]), $e(() => {
3856
- const y = { current: !1 }, N = () => {
3857
- const W = P.current, K = D.current, q = Oe(
3858
- te.current,
3859
- se.current
3858
+ }, [Un, s, We, t, a, u, i, C, Pr, Ee, x]), He(() => {
3859
+ const y = { current: !1 }, O = () => {
3860
+ const W = P.current, K = N.current, q = Le(
3861
+ ee.current,
3862
+ ae.current
3860
3863
  );
3861
- if (!W || !K || !be) {
3862
- ne.current = requestAnimationFrame(N);
3864
+ if (!W || !K || !ke) {
3865
+ pe.current = requestAnimationFrame(O);
3863
3866
  return;
3864
3867
  }
3865
3868
  if (document.hidden) {
3866
- A.current?.setActive(!1), ne.current = requestAnimationFrame(N);
3869
+ A.current?.setActive(!1), pe.current = requestAnimationFrame(O);
3867
3870
  return;
3868
3871
  }
3869
- const Se = q.isSpeaking(), Ee = q.isWarmingUp(), pt = Se && !F.current, Ze = F.current && !Se;
3870
- pt && (Te(), Le(), v.current = !1, T.current = !1, Pe(z.current), U.current?.reset(), Re.current.reset(), Xe.current = void 0, ge.current = 0, E.current = "sil", M.current = 0, A.current?.setActive(!1)), Ze && (J.current.reset(), A.current?.setActive(!1), U.current?.reset(), ht());
3871
- const wt = Ze || v.current || h.current, Et = B && K.supportsBufferedPlayback;
3872
- if (Ee) {
3872
+ const Se = q.isSpeaking(), Pe = q.isWarmingUp(), mt = Se && !F.current, Je = F.current && !Se;
3873
+ mt && (Ae(), Fe(), v.current = !1, E.current = !1, Ie(j.current), I.current?.reset(), we.current.reset(), Ue.current = void 0, fe.current = 0, T.current = "sil", R.current = 0, A.current?.setActive(!1)), Je && (X.current.reset(), A.current?.setActive(!1), I.current?.reset(), dt());
3874
+ const ht = Je || v.current || m.current, Tt = B && K.supportsBufferedPlayback;
3875
+ if (Pe) {
3873
3876
  $.current && A.current?.setActive(!1);
3874
- const re = q.getVisemeQueue();
3875
- re.length > 0 && X.current === 0 && (X.current = performance.now()), J.current.advance(performance.now());
3876
- const V = J.current.getExpressionPath(), ae = J.current.getDrawKey(), ye = {
3877
- queue: re,
3877
+ const se = q.getVisemeQueue();
3878
+ se.length > 0 && J.current === 0 && (J.current = performance.now()), X.current.advance(performance.now());
3879
+ const U = X.current.getExpressionPath(), oe = X.current.getDrawKey(), ye = {
3880
+ queue: se,
3878
3881
  elapsedMs: 0,
3879
- expressionPath: V,
3880
- expressionDrawKey: ae,
3881
- availablePaths: ve.current
3882
+ expressionPath: U,
3883
+ expressionDrawKey: oe,
3884
+ availablePaths: Ce.current
3882
3885
  };
3883
- let Be = !1;
3884
- Et && U.current ? (U.current.warmupTick(ye), Be = U.current.isWarmupReady(
3886
+ let Re = !1;
3887
+ Tt && I.current ? (I.current.warmupTick(ye), Re = I.current.isWarmupReady(
3885
3888
  ye,
3886
- me.current
3889
+ V.current
3887
3890
  )) : K.usesPixi && Yr(
3888
3891
  W,
3889
- re,
3892
+ se,
3890
3893
  0,
3891
- V,
3892
- ae,
3893
- z.current,
3894
- (gt, At, qt, Pt) => {
3895
- K.drawLiveFrame(gt, At, qt, (Ce) => {
3896
- Pt?.(Ce), q.isWarmingUp() && Ce !== "" && !jr({ lastDrawnKey: Ce }) && (X.current = 0, q.releaseWarmupHold());
3894
+ U,
3895
+ oe,
3896
+ j.current,
3897
+ (pt, Et, qt, At) => {
3898
+ K.drawLiveFrame(pt, Et, qt, (De) => {
3899
+ At?.(De), q.isWarmingUp() && De !== "" && !jr({ lastDrawnKey: De }) && (J.current = 0, q.releaseWarmupHold());
3897
3900
  });
3898
3901
  },
3899
- (gt) => {
3900
- ue.current?.(gt.label);
3902
+ (pt) => {
3903
+ ie.current?.(pt.label);
3901
3904
  },
3902
- ve.current
3905
+ Ce.current
3903
3906
  );
3904
- const et = X.current > 0 && performance.now() - X.current > os;
3905
- ue.current?.(
3906
- Be ? "buffer ready" : "buffering lipsync…"
3907
- ), (Be || et) && (X.current = 0, q.releaseWarmupHold()), F.current = q.isSpeaking(), ne.current = requestAnimationFrame(N);
3907
+ const Qe = J.current > 0 && performance.now() - J.current > os;
3908
+ ie.current?.(
3909
+ Re ? "buffer ready" : "buffering lipsync…"
3910
+ ), (Re || Qe) && (J.current = 0, q.releaseWarmupHold()), F.current = q.isSpeaking(), pe.current = requestAnimationFrame(O);
3908
3911
  return;
3909
3912
  }
3910
3913
  if (Se) {
3911
3914
  $.current && A.current?.setActive(!1);
3912
- const re = q.getVisemeQueue(), V = q.getPlaybackElapsedMs();
3913
- js(re, V), M.current = V;
3914
- const ae = re.length > 0 ? Vt(re, V) : "sil";
3915
- ae !== "sil" && (E.current = ae);
3915
+ const se = q.getVisemeQueue(), U = q.getPlaybackElapsedMs();
3916
+ js(se, U), R.current = U;
3917
+ const oe = se.length > 0 ? Ut(se, U) : "sil";
3918
+ oe !== "sil" && (T.current = oe);
3916
3919
  const ye = Li(
3917
- V,
3920
+ U,
3918
3921
  q.getSentenceEmotions(),
3919
3922
  q.getWordQueue(),
3920
3923
  q.getStreamMood()
3921
3924
  );
3922
- J.current.setTargetEmotion(ye), J.current.setTargetEyebrow(
3925
+ X.current.setTargetEmotion(ye), X.current.setTargetEyebrow(
3923
3926
  Mi(
3924
- V,
3927
+ U,
3925
3928
  q.getWordQueue(),
3926
3929
  gr(ye)
3927
3930
  )
3928
- ), J.current.advance(performance.now());
3929
- const Be = J.current.getExpressionPath(), et = J.current.getDrawKey(), gt = (Ce, Kt, yt, Gt) => {
3931
+ ), X.current.advance(performance.now());
3932
+ const Re = X.current.getExpressionPath(), Qe = X.current.getDrawKey(), pt = (De, Kt, wt, Gt) => {
3930
3933
  const xr = {
3931
- label: lt.current,
3932
- elapsedMs: V,
3934
+ label: Oe.current,
3935
+ elapsedMs: U,
3933
3936
  mouthPath: Kt.mouthPath,
3934
- transitionMeta: Xe.current
3937
+ transitionMeta: Ue.current
3935
3938
  };
3936
- ft.current.set(yt, xr), U.current?.markExternallyDisplayed(
3937
- yt,
3938
- Be
3939
- ), K.drawLiveFrame(Ce, Kt, yt, (xt) => {
3940
- const Vn = ft.current.get(xt) ?? xr;
3941
- ft.current.delete(xt), Re.current.onDrawDisplayed(
3939
+ ut.current.set(wt, xr), I.current?.markExternallyDisplayed(
3940
+ wt,
3941
+ Re
3942
+ ), K.drawLiveFrame(De, Kt, wt, (Pt) => {
3943
+ const Vn = ut.current.get(Pt) ?? xr;
3944
+ ut.current.delete(Pt), we.current.onDrawDisplayed(
3942
3945
  Vn,
3943
- re
3944
- ), U.current?.markExternallyDisplayed(
3945
- xt,
3946
- Be
3947
- ), Gt?.(xt);
3946
+ se
3947
+ ), I.current?.markExternallyDisplayed(
3948
+ Pt,
3949
+ Re
3950
+ ), Gt?.(Pt);
3948
3951
  });
3949
- }, At = (Ce) => {
3950
- lt.current = Ce.label, Xe.current = Ce.transitionMeta, ue.current?.(Ce.label);
3952
+ }, Et = (De) => {
3953
+ Oe.current = De.label, Ue.current = De.transitionMeta, ie.current?.(De.label);
3951
3954
  }, qt = B && K.supportsBufferedPlayback;
3952
- let Pt = !1;
3953
- qt && U.current && (Pt = U.current.tick({
3955
+ let At = !1;
3956
+ qt && I.current && (At = I.current.tick({
3954
3957
  canvas: W,
3955
- queue: re,
3956
- elapsedMs: V,
3957
- expressionPath: Be,
3958
- expressionDrawKey: et,
3959
- playbackState: z.current,
3960
- availablePaths: ve.current,
3961
- onStatus: At,
3962
- onDisplayed: (Kt, yt, Gt) => {
3963
- Re.current.onDrawDisplayed(
3958
+ queue: se,
3959
+ elapsedMs: U,
3960
+ expressionPath: Re,
3961
+ expressionDrawKey: Qe,
3962
+ playbackState: j.current,
3963
+ availablePaths: Ce.current,
3964
+ onStatus: Et,
3965
+ onDisplayed: (Kt, wt, Gt) => {
3966
+ we.current.onDrawDisplayed(
3964
3967
  {
3965
3968
  label: Gt,
3966
- elapsedMs: V,
3967
- mouthPath: yt,
3968
- transitionMeta: Xe.current
3969
+ elapsedMs: U,
3970
+ mouthPath: wt,
3971
+ transitionMeta: Ue.current
3969
3972
  },
3970
- re
3973
+ se
3971
3974
  );
3972
3975
  }
3973
- }).usedBuffer), Pt || Yr(
3976
+ }).usedBuffer), At || Yr(
3974
3977
  W,
3975
- re,
3976
- V,
3977
- Be,
3978
- et,
3979
- z.current,
3980
- gt,
3981
- At,
3982
- ve.current
3983
- ), Re.current.onRafTickSpeaking(), ke.current?.(
3984
- Re.current.snapshot(re, V)
3978
+ se,
3979
+ U,
3980
+ Re,
3981
+ Qe,
3982
+ j.current,
3983
+ pt,
3984
+ Et,
3985
+ Ce.current
3986
+ ), we.current.onRafTickSpeaking(), ve.current?.(
3987
+ we.current.snapshot(se, U)
3985
3988
  );
3986
- } else if (!wt && $.current && A.current) {
3987
- const re = A.current, V = re.getVideo();
3988
- if (V.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
3989
- re.setActive(!0);
3990
- const ae = () => !q.isSpeaking() && !v.current && !h.current;
3991
- K.usesPixi ? (K.drawIdleVideo(V, ae), ae() && ue.current?.("idle")) : y.current || (y.current = !0, Kr(
3989
+ } else if (!ht && $.current && A.current) {
3990
+ const se = A.current, U = se.getVideo();
3991
+ if (U.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
3992
+ se.setActive(!0);
3993
+ const oe = () => !q.isSpeaking() && !v.current && !m.current;
3994
+ K.usesPixi ? (K.drawIdleVideo(U, oe), oe() && ie.current?.("idle")) : y.current || (y.current = !0, Kr(
3992
3995
  W,
3993
- V,
3996
+ U,
3994
3997
  null,
3995
3998
  void 0,
3996
- Ye.current,
3997
- ae
3998
- ).then(() => ue.current?.("idle")).finally(() => {
3999
+ ct.current,
4000
+ oe
4001
+ ).then(() => ie.current?.("idle")).finally(() => {
3999
4002
  y.current = !1;
4000
4003
  }));
4001
4004
  } else
@@ -4003,106 +4006,106 @@ const Ma = Hn(function({
4003
4006
  W,
4004
4007
  null,
4005
4008
  "__sil__",
4006
- z.current,
4007
- (ae, ye, Be, et) => K.drawLiveFrame(ae, ye, Be, et),
4008
- (ae) => ue.current?.(ae)
4009
+ j.current,
4010
+ (oe, ye, Re, Qe) => K.drawLiveFrame(oe, ye, Re, Qe),
4011
+ (oe) => ie.current?.(oe)
4009
4012
  );
4010
- } else wt || Xr(
4013
+ } else ht || Xr(
4011
4014
  W,
4012
4015
  null,
4013
4016
  "__sil__",
4014
- z.current,
4015
- (re, V, ae, ye) => K.drawLiveFrame(re, V, ae, ye),
4016
- (re) => ue.current?.(re)
4017
+ j.current,
4018
+ (se, U, oe, ye) => K.drawLiveFrame(se, U, oe, ye),
4019
+ (se) => ie.current?.(se)
4017
4020
  );
4018
- F.current = Se, ne.current = requestAnimationFrame(N);
4021
+ F.current = Se, pe.current = requestAnimationFrame(O);
4019
4022
  };
4020
- return ne.current = requestAnimationFrame(N), () => {
4021
- cancelAnimationFrame(ne.current), Te(), Le(), te.current.stop(), se.current?.stop();
4023
+ return pe.current = requestAnimationFrame(O), () => {
4024
+ cancelAnimationFrame(pe.current), Ae(), Fe(), ee.current.stop(), ae.current?.stop();
4022
4025
  };
4023
4026
  }, [
4024
- be,
4025
- ut,
4026
- ht,
4027
- Te,
4028
- Le
4027
+ ke,
4028
+ ot,
4029
+ dt,
4030
+ Ae,
4031
+ Fe
4029
4032
  ]), $n(
4030
4033
  k,
4031
4034
  () => ({
4032
- speakText: async (y, N) => {
4035
+ speakText: async (y, O) => {
4033
4036
  const W = y.trim();
4034
4037
  if (!W) return;
4035
- const K = D.current;
4036
- if (!K || !Ve.current && !be)
4038
+ const K = N.current;
4039
+ if (!K || !_e.current && !ke)
4037
4040
  throw new Error("AI twin is not ready");
4038
- const { ttsEngineId: q, voiceId: Se } = mt(N);
4039
- xe(null), ee.current += 1, Te(), Le(), v.current = !1, T.current = !1, E.current = "sil", M.current = 0, Pe(z.current), J.current.reset(), F.current = !1;
4041
+ const { ttsEngineId: q, voiceId: Se } = Ye(O);
4042
+ be(null), re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, T.current = "sil", R.current = 0, Ie(j.current), X.current.reset(), F.current = !1;
4040
4043
  try {
4041
- $.current ? (A.current?.setActive(!1), A.current?.restart(), Pe(z.current)) : await K.renderSilOnly(), await te.current.speak(W, {
4044
+ $.current ? (A.current?.setActive(!1), A.current?.restart(), Ie(j.current)) : await K.renderSilOnly(), await ee.current.speak(W, {
4042
4045
  voiceId: Se,
4043
- speakingRate: N?.speakingRate ?? l,
4046
+ speakingRate: O?.speakingRate ?? l,
4044
4047
  ttsEngineId: q
4045
4048
  });
4046
- } catch (Ee) {
4047
- throw De(Ee instanceof Error ? Ee.message : "TTS failed"), Ee;
4049
+ } catch (Pe) {
4050
+ throw Ee(Pe instanceof Error ? Pe.message : "TTS failed"), Pe;
4048
4051
  }
4049
4052
  },
4050
4053
  stop: () => {
4051
- ee.current += 1, Te(), Le(), v.current = !1, T.current = !1, te.current.stop(), se.current?.stop(), Pe(z.current), U.current?.reset(), X.current = 0, F.current = !1, ht();
4054
+ re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, ee.current.stop(), ae.current?.stop(), Ie(j.current), I.current?.reset(), J.current = 0, F.current = !1, dt();
4052
4055
  },
4053
4056
  setTtsEngineId: (y) => {
4054
- te.current.setTtsEngineId(y), se.current?.setTtsEngineId(y), fe.current && (fe.current.ttsEngineId = y);
4057
+ ee.current.setTtsEngineId(y), ae.current?.setTtsEngineId(y), he.current && (he.current.ttsEngineId = y);
4055
4058
  },
4056
- renderViseme: async (y, N) => {
4057
- const W = D.current, K = P.current;
4058
- if (!W || !K || !Ve.current)
4059
+ renderViseme: async (y, O) => {
4060
+ const W = N.current, K = P.current;
4061
+ if (!W || !K || !_e.current)
4059
4062
  throw new Error("AI twin is not ready");
4060
4063
  await W.renderViseme(K, y, {
4061
- from: N?.from,
4062
- transitionDurationMs: N?.transitionDurationMs,
4063
- gapMs: N?.gapMs,
4064
- onStatus: (q) => ue.current?.(q)
4064
+ from: O?.from,
4065
+ transitionDurationMs: O?.transitionDurationMs,
4066
+ gapMs: O?.gapMs,
4067
+ onStatus: (q) => ie.current?.(q)
4065
4068
  });
4066
4069
  },
4067
- isReady: () => Ve.current,
4070
+ isReady: () => _e.current,
4068
4071
  getStatus: () => Y,
4069
4072
  connect: async (y = {}) => {
4070
- xe(null);
4073
+ be(null);
4071
4074
  try {
4072
- let N = y.authToken?.trim();
4073
- N || (N = _e.current ?? i ?? await jt(), _e.current = N);
4074
- const W = y.voiceId?.trim() ?? u ?? fe.current?.voiceId, K = y.personaId?.trim() ?? fe.current?.personaId, q = Er();
4075
+ let O = y.authToken?.trim();
4076
+ O || (O = ce.current ?? i ?? await jt(), ce.current = O);
4077
+ const W = y.voiceId?.trim() ?? u ?? he.current?.voiceId, K = y.personaId?.trim() ?? he.current?.personaId, q = Er();
4075
4078
  await q.unlockAudio(), await q.connect({
4076
4079
  ...y,
4077
- apiBase: y.apiBase?.trim() || ce,
4078
- authToken: N,
4080
+ apiBase: y.apiBase?.trim() || Te,
4081
+ authToken: O,
4079
4082
  voiceId: W,
4080
4083
  personaId: K,
4081
4084
  speakingRate: y.speakingRate ?? l
4082
4085
  });
4083
- } catch (N) {
4084
- throw De(
4085
- N instanceof Error ? N.message : "Voice connect failed"
4086
- ), N;
4086
+ } catch (O) {
4087
+ throw Ee(
4088
+ O instanceof Error ? O.message : "Voice connect failed"
4089
+ ), O;
4087
4090
  }
4088
4091
  },
4089
4092
  disconnect: async () => {
4090
- const y = se.current;
4091
- y && (ee.current += 1, Te(), Le(), v.current = !1, T.current = !1, Pe(z.current), U.current?.reset(), X.current = 0, F.current = !1, await y.disconnect(), ht());
4093
+ const y = ae.current;
4094
+ y && (re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, Ie(j.current), I.current?.reset(), J.current = 0, F.current = !1, await y.disconnect(), dt());
4092
4095
  },
4093
- isConnected: () => se.current?.isConnected() ?? !1,
4094
- getVoiceStream: () => se.current?.getVoiceStream() ?? te.current?.getVoiceStream() ?? null
4096
+ isConnected: () => ae.current?.isConnected() ?? !1,
4097
+ getVoiceStream: () => ae.current?.getVoiceStream() ?? ee.current?.getVoiceStream() ?? null
4095
4098
  }),
4096
4099
  [
4097
- be,
4100
+ ke,
4098
4101
  l,
4099
4102
  i,
4100
4103
  u,
4101
- Te,
4102
- Le,
4103
- ht,
4104
- De,
4105
- mt,
4104
+ Ae,
4105
+ Fe,
4106
+ dt,
4107
+ Ee,
4108
+ Ye,
4106
4109
  Er,
4107
4110
  Y
4108
4111
  ]
@@ -4111,8 +4114,8 @@ const Ma = Hn(function({
4111
4114
  "canvas",
4112
4115
  {
4113
4116
  ref: P,
4114
- width: p.width,
4115
- height: p.height,
4117
+ width: Ht.width,
4118
+ height: Ht.height,
4116
4119
  style: { ...ya, ...d },
4117
4120
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
4118
4121
  }
@@ -4141,18 +4144,18 @@ export {
4141
4144
  va as AI_TWIN_THUMBNAIL_FILENAME,
4142
4145
  Ma as AiTwin,
4143
4146
  Qt as AiTwinNotFoundError,
4144
- nt as DEFAULT_TTS_ENGINE_ID,
4147
+ tt as DEFAULT_TTS_ENGINE_ID,
4145
4148
  bn as MIC_SAMPLE_RATE,
4146
4149
  Ps as OCULUS_VISEME_IDS,
4147
4150
  kn as PLAYBACK_SAMPLE_RATE,
4148
4151
  dr as SPEAKING_RATE_MAX,
4149
4152
  fr as SPEAKING_RATE_MIN,
4150
- ot as TTS_ENGINE_CARTESIA,
4153
+ it as TTS_ENGINE_CARTESIA,
4151
4154
  sn as TTS_ENGINE_GOOGLE,
4152
4155
  cr as TTS_ENGINE_INWORLD,
4153
4156
  Ia as VISEME_IDS,
4154
4157
  Sn as VISEME_TEST_CARTESIA_VOICE_ID,
4155
- Wt as VISEME_TEST_SPEAKING_RATE,
4158
+ Vt as VISEME_TEST_SPEAKING_RATE,
4156
4159
  vn as VISEME_TEST_VOICE_ID,
4157
4160
  ba as aiTwinSourceFilename,
4158
4161
  ti as buildVoiceWebSocketUrl,
@@ -4165,7 +4168,7 @@ export {
4165
4168
  Ra as getAiTwinThumbnailUrl,
4166
4169
  Is as normalizeOculusViseme,
4167
4170
  ks as resolveDirectFaceId,
4168
- Vt as resolveVisemeAtTime,
4171
+ Ut as resolveVisemeAtTime,
4169
4172
  xa as resolveWordAtTime,
4170
4173
  Ts as setActiveTwinAssets
4171
4174
  };