@streamoji/aitwin 0.4.5 → 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,77 +1,77 @@
1
- import { jsxs as Hn, jsx as Ir } from "react/jsx-runtime";
2
- import { forwardRef as $n, useRef as $, useState as Ze, useEffect as $e, useCallback as Ae, useMemo as Mr, useImperativeHandle as qn } from "react";
3
- import { PipecatClient as Kn } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as Gn, DailyMediaManager as zn, ProtobufFrameSerializer as jn } from "@pipecat-ai/websocket-transport";
5
- import { Filter as Yn, GlProgram as Xn, Application as Jn, RendererType as Qn, Sprite as Pt, Texture as we, VideoSource as Zn, Rectangle as es } from "pixi.js";
6
- const ts = "https://aitwin.bubu.social", sn = {
7
- publicBase: ts
8
- }, rs = "0.4.5", ns = {
9
- version: rs
10
- }, ss = {}, vt = "https://ai.aitwin.me", ir = `${sn.publicBase}/custom-faces`, is = `${sn.publicBase}/aitwin-workers/v${ns.version}/visemeDiffPreview.worker.js`;
11
- function as(e) {
1
+ import { jsxs as Wn, jsx as Ir } from "react/jsx-runtime";
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
+ import { PipecatClient as qn } from "@pipecat-ai/client-js";
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 xt, Texture as ge, VideoSource as Qn, Rectangle as Zn } from "pixi.js";
6
+ const es = "https://aitwin.bubu.social", nn = {
7
+ publicBase: es
8
+ }, ts = "0.4.6", rs = {
9
+ version: ts
10
+ }, ns = {}, St = "https://ai.aitwin.me", ar = `${nn.publicBase}/custom-faces`, ss = `${nn.publicBase}/aitwin-workers/v${rs.version}/visemeDiffPreview.worker.js`;
11
+ function is(e) {
12
12
  if (e) return e;
13
- const t = typeof import.meta < "u" ? ss?.VITE_AITWIN_WORKER_URL : void 0;
14
- return t?.trim() ? t.trim() : is;
13
+ const t = typeof import.meta < "u" ? ns?.VITE_AITWIN_WORKER_URL : void 0;
14
+ return t?.trim() ? t.trim() : ss;
15
15
  }
16
- const os = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Gt = 3e3, yt = 16, Rr = 3e3, cs = 4e3, us = 0.85, ls = 8, ar = 400, an = "eng_a7f2b9c1", or = "eng_d4e8f3a2", it = "eng_c9b1e6d4", tt = it, on = /* @__PURE__ */ new Set([
17
- or,
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
+ cr,
18
18
  it
19
- ]), cn = {
20
- [an]: "oculus_direct",
19
+ ]), on = {
20
+ [sn]: "oculus_direct",
21
21
  [it]: "oculus_direct",
22
- [or]: "inworld_word"
22
+ [cr]: "inworld_word"
23
23
  }, Dr = {
24
- google: an,
25
- inworld: or,
24
+ google: sn,
25
+ inworld: cr,
26
26
  cartesia: it
27
27
  };
28
- function fs(e) {
29
- return cn[e];
28
+ function ls(e) {
29
+ return on[e];
30
30
  }
31
- function ds(e) {
31
+ function fs(e) {
32
32
  return e === it;
33
33
  }
34
- function ms(e) {
35
- if (e.ttsEngineId && e.ttsEngineId in cn)
34
+ function ds(e) {
35
+ if (e.ttsEngineId && e.ttsEngineId in on)
36
36
  return e.ttsEngineId;
37
37
  const t = e.tts?.toLowerCase();
38
38
  return t && t in Dr ? Dr[t] : tt;
39
39
  }
40
- class Jt extends Error {
40
+ class Qt extends Error {
41
41
  constructor(t = "AI twin not found") {
42
42
  super(t), this.name = "AiTwinNotFoundError";
43
43
  }
44
44
  }
45
- async function hs(e, t = os) {
45
+ async function ms(e, t = as) {
46
46
  const r = new URL(t);
47
47
  r.searchParams.set("id", e);
48
48
  const n = await fetch(r.toString());
49
49
  if (n.status === 404)
50
- throw new Jt();
50
+ throw new Qt();
51
51
  if (!n.ok)
52
52
  throw new Error(`getAiTwin failed (${n.status})`);
53
53
  const s = await n.json();
54
54
  if (!s.success)
55
- throw new Jt(s.error ?? "AI twin not found");
55
+ throw new Qt(s.error ?? "AI twin not found");
56
56
  const { tts: i, token: o, ...a } = s.data, u = String(a.authToken ?? o ?? "").trim() || void 0;
57
57
  return {
58
58
  ...a,
59
- ttsEngineId: ms(s.data),
59
+ ttsEngineId: ds(s.data),
60
60
  authToken: u
61
61
  };
62
62
  }
63
- const ps = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", ws = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", gs = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", ys = "6TNvp3SCs4Og0a1ijm9TommXLql1", _s = "Swaraj Mali";
64
- async function zt() {
65
- const e = await fetch(ps, {
63
+ const hs = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", ps = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", ws = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", gs = "6TNvp3SCs4Og0a1ijm9TommXLql1", ys = "Swaraj Mali";
64
+ async function jt() {
65
+ const e = await fetch(hs, {
66
66
  method: "POST",
67
67
  headers: {
68
68
  "Content-Type": "application/json",
69
- "Client-Id": ws,
70
- "Client-Secret": gs
69
+ "Client-Id": ps,
70
+ "Client-Secret": ws
71
71
  },
72
72
  body: JSON.stringify({
73
- userId: ys,
74
- userName: _s
73
+ userId: gs,
74
+ userName: ys
75
75
  })
76
76
  });
77
77
  if (!e.ok)
@@ -81,7 +81,7 @@ async function zt() {
81
81
  throw new Error("getAuthToken returned no token");
82
82
  return r;
83
83
  }
84
- async function vs(e, t = vt) {
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
  });
@@ -91,7 +91,7 @@ async function vs(e, t = vt) {
91
91
  if (!n.value) throw new Error("Session value response missing value");
92
92
  return n;
93
93
  }
94
- function Ss(e) {
94
+ function vs(e) {
95
95
  const t = e.trim();
96
96
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
97
97
  const r = new Uint8Array(t.length / 2);
@@ -99,20 +99,20 @@ function Ss(e) {
99
99
  r[n / 2] = Number.parseInt(t.slice(n, n + 2), 16);
100
100
  return r;
101
101
  }
102
- function xt(e) {
102
+ function It(e) {
103
103
  return Uint8Array.from(e);
104
104
  }
105
- function bs(e, t) {
105
+ function Ss(e, t) {
106
106
  const r = new Uint8Array(e.length + t.length);
107
107
  return r.set(e, 0), r.set(t, e.length), r;
108
108
  }
109
- async function ks(e, t) {
109
+ 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 = xt(r.subarray(0, 12)), s = xt(r.subarray(12, 28)), i = xt(r.subarray(28)), o = xt(bs(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
- Ss(t),
115
+ vs(t),
116
116
  { name: "AES-GCM" },
117
117
  !1,
118
118
  ["decrypt"]
@@ -123,35 +123,35 @@ async function ks(e, t) {
123
123
  o
124
124
  );
125
125
  }
126
- let Qt = null;
127
- const Zt = /* @__PURE__ */ new Set();
128
- function It(e) {
126
+ let Zt = null;
127
+ const er = /* @__PURE__ */ new Set();
128
+ function Mt(e) {
129
129
  return e.includes("/custom-faces/");
130
130
  }
131
- function Bt(e) {
131
+ function Ct(e) {
132
132
  const t = e.binBase.trim().replace(/\/$/, ""), r = e.twinBase.trim().replace(/\/$/, "");
133
- if (!(e.encrypted || It(t) || It(r)))
133
+ if (!(e.encrypted || Mt(t) || Mt(r)))
134
134
  return { twinBase: r, binBase: t, encrypted: !1 };
135
- const s = It(t) ? t : It(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 Bt(e).encrypted;
138
+ function Ge(e) {
139
+ return Ct(e).encrypted;
140
140
  }
141
- function Br(e, t = ir) {
141
+ function Br(e, t = ar) {
142
142
  const r = `${t.replace(/\/$/, "")}/${e}`;
143
143
  return { twinBase: r, binBase: r, encrypted: !0 };
144
144
  }
145
- function Ts(e, t) {
145
+ function ks(e, t) {
146
146
  return (e ?? t)?.trim() || void 0;
147
147
  }
148
- function Es(e) {
149
- Qt = Bt(e);
150
- for (const t of Zt) t();
148
+ function Ts(e) {
149
+ Zt = Ct(e);
150
+ for (const t of er) t();
151
151
  }
152
- function As(e, t) {
152
+ function Es(e, t) {
153
153
  const r = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
154
- if (!r) return Bt(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,44 +159,44 @@ function As(e, t) {
159
159
  return s;
160
160
  }
161
161
  };
162
- return Bt({
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() {
169
- if (!Qt)
168
+ function ze() {
169
+ if (!Zt)
170
170
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
171
- return Qt;
171
+ return Zt;
172
172
  }
173
- function un(e) {
174
- return Zt.add(e), () => Zt.delete(e);
173
+ function cn(e) {
174
+ return er.add(e), () => er.delete(e);
175
175
  }
176
- function Ct() {
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
- function Ps() {
181
- const e = je();
182
- return ze(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
180
+ function As() {
181
+ const e = ze();
182
+ return Ge(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
183
183
  }
184
- function ln() {
185
- const e = je();
186
- return ze(e) ? e.binBase : e.twinBase;
184
+ function un() {
185
+ const e = ze();
186
+ return Ge(e) ? e.binBase : e.twinBase;
187
187
  }
188
- function St() {
189
- return ze(je());
188
+ function bt() {
189
+ return Ge(ze());
190
190
  }
191
- function fn() {
192
- const e = je();
193
- return ze(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
191
+ function ln() {
192
+ const e = ze();
193
+ return Ge(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
194
194
  }
195
- function dn() {
196
- const e = je();
197
- return ze(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
195
+ function fn() {
196
+ const e = ze();
197
+ return Ge(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
198
198
  }
199
- function mn(e) {
199
+ function dn(e) {
200
200
  const t = e.split(/\r?\n/);
201
201
  let r = "", n = "";
202
202
  for (const i of t)
@@ -211,7 +211,7 @@ function mn(e) {
211
211
  }
212
212
  return { event: r, data: s };
213
213
  }
214
- const xs = [
214
+ const Ps = [
215
215
  "aa",
216
216
  "CH",
217
217
  "DD",
@@ -227,14 +227,14 @@ const xs = [
227
227
  "kk",
228
228
  "nn",
229
229
  "sil"
230
- ], Is = new Map(
231
- xs.map((e) => [e.toLowerCase(), e])
230
+ ], xs = new Map(
231
+ Ps.map((e) => [e.toLowerCase(), e])
232
232
  );
233
- function Ms(e) {
233
+ function Is(e) {
234
234
  const t = (e ?? "").trim();
235
- return t ? Is.get(t.toLowerCase()) ?? "sil" : "sil";
235
+ return t ? xs.get(t.toLowerCase()) ?? "sil" : "sil";
236
236
  }
237
- const Rs = {
237
+ const Ms = {
238
238
  aei: ["aa", "E", "I"],
239
239
  o: ["O", "U"],
240
240
  ee: ["I"],
@@ -246,12 +246,12 @@ const Rs = {
246
246
  qw: ["U", "O"],
247
247
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
248
248
  };
249
- function Ds(e) {
249
+ function Rs(e) {
250
250
  if (!e) return ["sil"];
251
251
  const t = e.toLowerCase();
252
- return Rs[t] ?? ["sil"];
252
+ return Ms[t] ?? ["sil"];
253
253
  }
254
- function Bs(e, t) {
254
+ function Ds(e, t) {
255
255
  const r = e.word.length;
256
256
  if (r <= 0) return 0;
257
257
  const n = e.wduration;
@@ -263,27 +263,27 @@ 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
- function cr(e, t) {
266
+ function ur(e, t) {
267
267
  const r = e.toLowerCase().replace(/[^a-z']/g, "");
268
268
  return !r || rt(r, t) !== "w" || t > 0 && rt(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
269
269
  }
270
- function Cs(e, t) {
270
+ function Bs(e, t) {
271
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
- function Fs(e, t) {
274
+ function Cs(e, t) {
275
275
  const r = e.toLowerCase(), n = r.slice(
276
276
  Math.max(0, t - 1),
277
277
  Math.min(r.length, t + 3)
278
278
  );
279
279
  if (/oo|ou|uw/.test(n)) return "U";
280
- if (cr(r, t)) return "FF";
280
+ if (ur(r, t)) return "FF";
281
281
  const s = rt(r, t);
282
282
  return s === "u" || s === "w" ? "U" : "O";
283
283
  }
284
- function Ls(e, t) {
284
+ function Fs(e, t) {
285
285
  const r = e.toLowerCase();
286
- if (cr(r, t)) return "FF";
286
+ if (ur(r, t)) return "FF";
287
287
  const n = r.slice(Math.max(0, t - 2), t + 1);
288
288
  if (/qu/.test(n)) return "U";
289
289
  const s = r.slice(
@@ -292,7 +292,7 @@ function Ls(e, t) {
292
292
  );
293
293
  return /wo|wh/.test(s) || rt(r, t) === "o" ? "O" : "U";
294
294
  }
295
- const Mt = {
295
+ const Rt = {
296
296
  d: "DD",
297
297
  t: "DD",
298
298
  n: "DD",
@@ -304,42 +304,42 @@ const Mt = {
304
304
  x: "CH",
305
305
  j: "CH"
306
306
  };
307
- function Os(e, t) {
307
+ function Ls(e, t) {
308
308
  const r = e.toLowerCase(), n = rt(r, t);
309
- if (Mt[n]) return Mt[n];
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 (Mt[i]) return Mt[i];
312
+ if (Rt[i]) return Rt[i];
313
313
  }
314
314
  return "DD";
315
315
  }
316
- function Ns(e, t, r) {
317
- const n = Ds(e);
316
+ function Os(e, t, r) {
317
+ const n = Rs(e);
318
318
  if (n.length === 1) return n[0];
319
319
  const s = t.trim();
320
320
  if (!s) return n[0];
321
321
  const i = (e ?? "").toLowerCase(), o = Math.max(0, r);
322
322
  switch (i) {
323
323
  case "aei":
324
- return Cs(s, o);
324
+ return Bs(s, o);
325
325
  case "o":
326
- return Fs(s, o);
326
+ return Cs(s, o);
327
327
  case "qw":
328
- return Ls(s, o);
328
+ return Fs(s, o);
329
329
  case "cdgknstxyz":
330
- return Os(s, o);
330
+ return Ls(s, o);
331
331
  default:
332
332
  return n[0];
333
333
  }
334
334
  }
335
- const Us = 32, Cr = 48;
336
- function hn(e) {
335
+ const Ns = 32, Cr = 48;
336
+ function mn(e) {
337
337
  let t = 0;
338
338
  for (const r of e)
339
339
  t = Math.max(t, r.vtime + r.vduration);
340
340
  return t;
341
341
  }
342
- function pn(e) {
342
+ function hn(e) {
343
343
  let t = null, r = -1;
344
344
  for (const n of e) {
345
345
  if (n.viseme === "sil") continue;
@@ -348,53 +348,53 @@ function pn(e) {
348
348
  }
349
349
  return t;
350
350
  }
351
- function Vs(e) {
352
- return wn(e).find((r) => r.viseme !== "sil") ?? null;
351
+ function Us(e) {
352
+ return pn(e).find((r) => r.viseme !== "sil") ?? null;
353
353
  }
354
- function qe(e) {
355
- const t = hn(e);
356
- return pn(e) ? t + ar : t;
354
+ function $e(e) {
355
+ const t = mn(e);
356
+ return hn(e) ? t + or : t;
357
357
  }
358
- function Ws(e) {
359
- const t = [], r = Vs(e);
358
+ function Vs(e) {
359
+ const t = [], r = Us(e);
360
360
  r && r.vtime > 0 && t.push({
361
361
  from: "sil",
362
362
  to: r.viseme,
363
363
  fromVtime: 0,
364
364
  toVtime: r.vtime
365
365
  });
366
- const n = pn(e), s = hn(e);
366
+ const n = hn(e), s = mn(e);
367
367
  return n && t.push({
368
368
  from: n.viseme,
369
369
  to: "sil",
370
370
  fromVtime: s,
371
- toVtime: s + ar
371
+ toVtime: s + or
372
372
  }), t;
373
373
  }
374
- function wn(e) {
374
+ function pn(e) {
375
375
  const t = /* @__PURE__ */ new Map();
376
376
  for (const r of e)
377
377
  t.has(r.vtime) || t.set(r.vtime, r);
378
378
  return [...t.values()].sort((r, n) => r.vtime - n.vtime);
379
379
  }
380
- function Hs(e) {
381
- const t = wn(e), r = [];
380
+ function Ws(e) {
381
+ const t = pn(e), r = [];
382
382
  for (let n = 0; n < t.length - 1; n++) {
383
383
  const s = t[n].viseme, i = t[n + 1].viseme, o = t[n].vtime, a = t[n + 1].vtime;
384
384
  s === i || a <= o || r.push({ from: s, to: i, fromVtime: o, toVtime: a });
385
385
  }
386
386
  return r;
387
387
  }
388
- function $s(e) {
388
+ function Hs(e) {
389
389
  return e.length === 0 ? [] : [
390
- ...Ws(e),
391
- ...Hs(e)
390
+ ...Vs(e),
391
+ ...Ws(e)
392
392
  ];
393
393
  }
394
- function qs(e, t) {
394
+ function $s(e, t) {
395
395
  let r = null;
396
396
  for (const n of e) {
397
- const { transStart: s, transEnd: i } = gn(
397
+ const { transStart: s, transEnd: i } = wn(
398
398
  n.fromVtime,
399
399
  n.toVtime,
400
400
  n.from,
@@ -404,7 +404,7 @@ function qs(e, t) {
404
404
  }
405
405
  return r;
406
406
  }
407
- function gn(e, t, r, n) {
407
+ function wn(e, t, r, n) {
408
408
  const s = Math.max(0, t - e);
409
409
  if ((r === "PP" || n === "PP") && s > Cr) {
410
410
  const l = Cr, f = t, c = f - l;
@@ -416,25 +416,25 @@ function gn(e, t, r, n) {
416
416
  transEnd: f
417
417
  };
418
418
  }
419
- const o = s > 0 ? Math.max(s, Us) : 0, a = e, u = e + o;
419
+ const o = s > 0 ? Math.max(s, Ns) : 0, a = e, u = e + o;
420
420
  return { gapMs: s, effectiveGapMs: o, holdEnd: e, transStart: a, transEnd: u };
421
421
  }
422
- const ur = 16e3;
423
- function yn(e) {
422
+ const lr = 16e3;
423
+ function gn(e) {
424
424
  const t = Number(e);
425
- return Number.isFinite(t) && t > 0 ? t : ur;
425
+ return Number.isFinite(t) && t > 0 ? t : lr;
426
426
  }
427
- function Ks(e) {
427
+ function qs(e) {
428
428
  let t = e.trim();
429
429
  const r = t.indexOf(",");
430
430
  t.startsWith("data:") && r >= 0 && (t = t.slice(r + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
431
431
  const n = t.length % 4;
432
432
  return n !== 0 && (t += "=".repeat(4 - n)), t;
433
433
  }
434
- function Gs(e) {
434
+ function Ks(e) {
435
435
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
436
436
  }
437
- function Fr(e, t, r = ur) {
437
+ function Fr(e, t, r = lr) {
438
438
  const n = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
439
439
  n.buffer,
440
440
  n.byteOffset,
@@ -445,15 +445,15 @@ function Fr(e, t, r = ur) {
445
445
  const o = e.createBuffer(1, i.length, r);
446
446
  return o.copyToChannel(i, 0), o;
447
447
  }
448
- function zs(e) {
449
- const t = Ks(e), r = window.atob(t), n = new Uint8Array(r.length);
448
+ function Gs(e) {
449
+ const t = qs(e), r = window.atob(t), n = new Uint8Array(r.length);
450
450
  for (let s = 0; s < r.length; s++)
451
451
  n[s] = r.charCodeAt(s);
452
452
  return n;
453
453
  }
454
- async function Lr(e, t, r = ur) {
455
- const n = zs(t), s = yn(r);
456
- if (Gs(n)) {
454
+ async function Lr(e, t, r = lr) {
455
+ const n = Gs(t), s = gn(r);
456
+ if (Ks(n)) {
457
457
  const i = n.buffer.slice(
458
458
  n.byteOffset,
459
459
  n.byteOffset + n.byteLength
@@ -472,15 +472,15 @@ async function Lr(e, t, r = ur) {
472
472
  return Fr(e, n, s);
473
473
  }
474
474
  }
475
- function js(e, t) {
475
+ function zs(e, t) {
476
476
  for (const r of e)
477
477
  if (t >= r.wtime && t < r.wtime + r.wduration)
478
478
  return r;
479
479
  return null;
480
480
  }
481
- function _n(e, t) {
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, j = 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,291 +489,291 @@ function _n(e, t) {
489
489
  w = !1, b = 0;
490
490
  }, P = () => {
491
491
  d != null && (clearTimeout(d), d = null);
492
- }, U = () => {
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
- }, O = () => {
505
- for (const h of n)
506
- h.playbackRate.value = g;
507
- }, q = () => {
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 T = 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());
515
+ h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
516
516
  }, Math.max(0, T));
517
517
  return;
518
518
  }
519
519
  }
520
520
  o = !1, P(), e.onSpeakingDone(), e.onNotify();
521
521
  }
522
- }, fe = (h) => {
523
- const T = qe(h);
522
+ }, V = (m) => {
523
+ const T = $e(m);
524
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 ? T / g : T;
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
- }, D = (h, T, M, F) => {
534
- T.length !== 0 && (c = M, T.forEach((A) => {
535
- const J = String(A.word ?? "").trim();
536
- if (!J) return;
537
- const Z = Math.round((A.start ?? 0) * 1e3), ee = 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({
539
- word: J,
540
- wtime: c + Z,
541
- wduration: ee,
542
- queueIndex: h.length,
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
+ const Y = String(A.word ?? "").trim();
536
+ if (!Y) return;
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
+ m.push({
539
+ word: Y,
540
+ wtime: c + Q,
541
+ wduration: Z,
542
+ queueIndex: m.length,
543
543
  gesture: A.gesture ?? null,
544
544
  emphasis: A.emphasis === !0
545
545
  });
546
546
  }));
547
- }, Y = (h, T, M, F, A, W) => {
548
- M.length !== 0 && (c = F, M.forEach((J) => {
549
- const Z = String(J.symbol ?? J.viseme ?? "").trim();
550
- if (!Z) return;
551
- const ee = Math.round((J.start ?? 0) * 1e3), Se = Math.max(1, Math.round((J.duration ?? 0) * 1e3)), ye = c + ee, Be = js(T, ye), ot = Be ? Bs(Be, ye) : 0;
552
- let xe;
553
- fs(W) === "oculus_direct" ? (xe = Ms(Z), xe === "U" && Be && cr(Be.word, ot) && (xe = "FF")) : xe = Ns(
554
- Z,
547
+ }, j = (m, T, R, F, A, $) => {
548
+ R.length !== 0 && (c = F, R.forEach((Y) => {
549
+ const Q = String(Y.symbol ?? Y.viseme ?? "").trim();
550
+ if (!Q) return;
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
+ Q,
555
555
  Be?.word ?? "",
556
556
  ot
557
- ), h.push({
558
- viseme: xe,
557
+ ), m.push({
558
+ viseme: Me,
559
559
  weight: 1,
560
- vtime: ye,
561
- vduration: Se
560
+ vtime: ke,
561
+ vduration: be
562
562
  });
563
563
  }), e.onNotify());
564
- }, Q = (h, T, M, F, A, W, J) => {
565
- D(T, F, A), Y(
566
- h,
564
+ }, X = (m, T, R, F, A, $, Y) => {
565
+ J(T, F, A), j(
566
+ m,
567
567
  T,
568
- M,
568
+ R,
569
569
  A,
570
- W,
571
- J
570
+ $,
571
+ Y
572
572
  );
573
- }, de = (h, T, M) => {
574
- j === h && h.visemes === T || (T.length = 0, M.length = 0, h.visemes = T, h.words = M, h.segmentOffsetMs = 0, j = h, c = 0, _ = 0);
575
- }, ce = 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
- }, ue = (h, T) => {
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;
580
+ const R = s, F = R.currentTime, A = F + 0.02;
581
581
  if (T.isFirstAudio) {
582
582
  f <= 0 && (f = A);
583
- const J = (A - F) * 1e3;
584
- l = performance.now() + J;
583
+ const Y = (A - F) * 1e3;
584
+ l = performance.now() + Y;
585
585
  }
586
586
  T.onBeforeStart?.(A);
587
- const W = M.createBufferSource();
588
- return W.buffer = h, W.playbackRate.value = g, W.connect(M.destination), I && W.connect(I), n.push(W), m ? (n.pop(), A) : (T.isFirstAudio && (o = !0, e.onSpeakingStart()), W.onended = () => {
589
- const J = n.indexOf(W);
590
- J >= 0 && n.splice(J, 1), e.onNotify(), !m && (L && B ? se(L, B) : q());
591
- }, W.start(A), A);
592
- }, se = async (h, T) => {
593
- if (m || i || n.length > 0) return;
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
+ const Y = n.indexOf($);
590
+ Y >= 0 && n.splice(Y, 1), e.onNotify(), !h && (L && B ? de(L, B) : te());
591
+ }, $.start(A), A);
592
+ }, de = async (m, T) => {
593
+ if (h || i || n.length > 0) return;
594
594
  if (r.length === 0) {
595
- q();
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 ce();
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
- const W = !o;
606
- if (R && (e.shouldHoldForWarmup?.() ?? !1) && (w || W && A.newStream) || w) {
607
- de(A.utterance, h, T);
608
- for (const ee of r) {
609
- if (m) return;
610
- ee.audioBuffer || (ee.audioBuffer = await Lr(
605
+ const $ = !o;
606
+ if (D && (e.shouldHoldForWarmup?.() ?? !1) && (w || $ && A.newStream) || w) {
607
+ pe(A.utterance, m, T);
608
+ for (const Z of r) {
609
+ if (h) return;
610
+ Z.audioBuffer || (Z.audioBuffer = await Lr(
611
611
  F,
612
- ee.audio,
613
- ee.sampleRate
614
- )), a = !0, w || (w = !0, b = 0, ee.newStream && ee.onNewStream?.()), ee.visemesQueued || (Q(
615
- h,
612
+ Z.audio,
613
+ Z.sampleRate
614
+ )), a = !0, w || (w = !0, b = 0, Z.newStream && Z.onNewStream?.()), Z.visemesQueued || (X(
615
+ m,
616
616
  T,
617
- ee.visemes,
618
- ee.words,
617
+ Z.visemes,
618
+ Z.words,
619
619
  b,
620
620
  !0,
621
621
  S
622
- ), ee.visemesQueued = !0, b += Math.round(ee.audioBuffer.duration * 1e3), _ = Math.max(
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();
628
628
  return;
629
629
  }
630
- const Z = r.shift();
631
- if (!Z || (Z.audioBuffer || (Z.audioBuffer = await Lr(
630
+ const Q = r.shift();
631
+ if (!Q || (Q.audioBuffer || (Q.audioBuffer = await Lr(
632
632
  F,
633
- Z.audio,
634
- Z.sampleRate
635
- )), m)) return;
636
- a = !0, P(), de(Z.utterance, h, T), Z.visemesQueued = !1, Z.newStream && Z.onNewStream?.(), ue(Z.audioBuffer, {
633
+ Q.audio,
634
+ Q.sampleRate
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
- onBeforeStart: (ee) => {
640
- f = ee, c = 0, l = performance.now() + (ee - F.currentTime) * 1e3, Q(
641
- h,
639
+ onBeforeStart: (Z) => {
640
+ f = Z, c = 0, l = performance.now() + (Z - F.currentTime) * 1e3, X(
641
+ m,
642
642
  T,
643
- Z.visemes,
644
- Z.words,
643
+ Q.visemes,
644
+ Q.words,
645
645
  0,
646
646
  !0,
647
647
  S
648
- ), Z.visemesQueued = !0, Z.utterance.segmentOffsetMs = 0;
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
- ) && se(h, T);
658
+ ) && de(m, T);
659
659
  return;
660
660
  }
661
- !M && n.length === 0 && r.length > 0 ? se(h, T) : n.length === 0 && r.length === 0 && q();
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)), O();
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 && se(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(), U(), r.length = 0, i = !1, o = !1, a = !1, u = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = 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
- fe(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
- q();
708
+ te();
709
709
  },
710
- playAudioChunk: async (h, T, M, F, A, W, J) => {
711
- if (m) return;
712
- L = h, B = T;
713
- const Z = yn(J?.sampleRate), ee = J?.newStream === !0, Se = 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
- de(Se, h, T), ee && J?.onNewStream?.(), Q(
717
- h,
716
+ pe(be, m, T), Z && Y?.onNewStream?.(), X(
717
+ m,
718
718
  T,
719
719
  F,
720
720
  A,
721
721
  0,
722
722
  !0,
723
723
  S
724
- ), _ = qe(h), !o && _ > 0 && fe(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: Se,
730
+ utterance: be,
731
731
  visemes: F,
732
732
  words: A,
733
- isNewSegment: W,
734
- sampleRate: Z,
735
- newStream: ee,
736
- onNewStream: J?.onNewStream,
733
+ isNewSegment: $,
734
+ sampleRate: Q,
735
+ newStream: Z,
736
+ onNewStream: Y?.onNewStream,
737
737
  visemesQueued: !1
738
- }), await se(h, T);
738
+ }), await de(m, T);
739
739
  },
740
- queueTimingsOnly: (h, T, M, F, A) => {
741
- if (m) return;
742
- const W = C();
743
- de(W, h, T), Q(
744
- h,
740
+ queueTimingsOnly: (m, T, R, F, A) => {
741
+ if (h) return;
742
+ const $ = C();
743
+ pe($, m, T), X(
744
+ m,
745
745
  T,
746
- M,
746
+ R,
747
747
  F,
748
748
  0,
749
749
  !0,
750
750
  S
751
- ), W.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(), U(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = 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(), U(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = 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 Nt(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
- function vn(e, t, r = 120) {
776
- const n = Nt(e, t);
775
+ function _n(e, t, r = 120) {
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) {
@@ -783,7 +783,7 @@ function vn(e, t, r = 120) {
783
783
  }
784
784
  return s?.viseme ?? "sil";
785
785
  }
786
- function Ys(e, t, r = 400) {
786
+ function js(e, t, r = 400) {
787
787
  const n = t - r;
788
788
  let s = 0;
789
789
  for (const i of e)
@@ -791,13 +791,13 @@ function Ys(e, t, r = 400) {
791
791
  else break;
792
792
  s > 0 && e.splice(0, s);
793
793
  }
794
- function Ma(e, t) {
794
+ function xa(e, t) {
795
795
  for (const r of e)
796
796
  if (t >= r.wtime && t < r.wtime + r.wduration)
797
797
  return r;
798
798
  return null;
799
799
  }
800
- function Xs(e, t) {
800
+ function Ys(e, t) {
801
801
  const r = e.trim();
802
802
  if (!r) return null;
803
803
  try {
@@ -807,36 +807,36 @@ function Xs(e, t) {
807
807
  return null;
808
808
  }
809
809
  }
810
- const lr = 0.5, fr = 1.5, Sn = "Olivia", bn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Ut = 0.85;
811
- function Or(e, t = vt, 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
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;
818
- const _ = _n(
816
+ const h = () => d.forEach((C) => C());
817
+ let M = () => !1;
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
825
  tt
826
- ), R = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
826
+ ), D = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
827
827
  if (!r.onLipsyncDebug) return;
828
- const P = R(), U = 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: U.length,
836
- activeViseme: Nt(U, P),
837
- segments: a.map((O) => ({
838
- ...O,
839
- visemes: [...O.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 = vt, r = {}) {
845
845
  const P = S;
846
846
  S = null, P && w(P.event, P.spokenText);
847
847
  })));
848
- }, L = (C, k, P, U, O) => {
848
+ }, L = (C, k, P, N, I) => {
849
849
  if (!r.onLipsyncDebug) return;
850
- const q = s.slice(k), fe = P.filter(
851
- (D) => String(D.symbol ?? D.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: q[0]?.vtime ?? 0,
856
- isNewSegment: U,
857
- chunkDurationMs: O,
855
+ audioOffsetMs: te[0]?.vtime ?? 0,
856
+ isNewSegment: N,
857
+ chunkDurationMs: I,
858
858
  receivedAtMs: performance.now(),
859
- visemes: q.map((D, Y) => {
860
- const Q = fe[Y];
859
+ visemes: te.map((J, j) => {
860
+ const X = V[j];
861
861
  return {
862
- rawSymbol: String(Q?.symbol ?? Q?.viseme ?? D.viseme).trim(),
863
- viseme: D.viseme,
864
- startSec: Number(Q?.start ?? 0),
865
- durationSec: Number(Q?.duration ?? 0),
866
- vtimeMs: D.vtime,
867
- vdurationMs: D.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 = vt, r = {}) {
884
884
  const P = f.trim();
885
885
  if (!P)
886
886
  throw new Error("Developer token required for avatar_ttsWithPoses");
887
- const U = k?.ttsEngineId ?? c ?? tt;
888
- _.resetForNewStream(U), _.setStreamTtsEngineId(U);
889
- const O = k?.voiceId ?? Sn, q = k?.speakingRate ?? Ut, fe = Math.max(
890
- lr,
891
- Math.min(fr, q)
892
- ), D = {
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
+ fr,
891
+ Math.min(dr, te)
892
+ ), J = {
893
893
  user_query: C,
894
- ttsEngineId: U,
895
- speakingRate: fe,
894
+ ttsEngineId: N,
895
+ speakingRate: V,
896
896
  tenant: "aiTwin"
897
897
  };
898
- on.has(U) && (D.voice_id = O);
898
+ an.has(N) && (J.voice_id = I);
899
899
  try {
900
- const Y = 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(D)
906
+ body: JSON.stringify(J)
907
907
  });
908
- if (!Y.ok)
909
- throw new Error(`avatar_ttsWithPoses failed (${Y.status})`);
910
- const Q = Y.body;
911
- if (!Q) throw new Error("No response body");
912
- const de = Q.getReader(), ce = new TextDecoder();
913
- let ue = "", se = !0;
914
- const me = async (v) => {
915
- const E = mn(v);
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
916
  if (E) {
917
917
  if (E.event === "audio") {
918
- const h = E.data.chunk, T = E.data.visemes ?? [], M = E.data.words ?? [], F = E.data.is_new_segment ?? !1, A = E.data.sample_rate, W = s.length;
919
- if (h) {
920
- const J = se;
921
- se = !1, await _.playAudioChunk(
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,
924
+ m,
925
925
  T,
926
- M,
926
+ R,
927
927
  F,
928
- { sampleRate: A, newStream: J }
928
+ { sampleRate: A, newStream: Y }
929
929
  ), L(
930
930
  C,
931
- W,
931
+ $,
932
932
  T,
933
933
  F,
934
- Xs(h, A)
934
+ Ys(m, A)
935
935
  ), b("audio_chunk", C);
936
- } else (T.length > 0 || M.length > 0) && (_.queueTimingsOnly(
936
+ } else (T.length > 0 || R.length > 0) && (_.queueTimingsOnly(
937
937
  s,
938
938
  i,
939
939
  T,
940
- M,
940
+ R,
941
941
  F
942
942
  ), L(
943
943
  C,
944
- W,
944
+ $,
945
945
  T,
946
946
  F,
947
947
  null
948
948
  ), b("audio_chunk", C));
949
949
  } else if (E.event === "metadata") {
950
- const h = E.data.mood;
951
- typeof h == "string" && h.trim() && (l = h.trim());
950
+ const m = E.data.mood;
951
+ typeof m == "string" && m.trim() && (l = m.trim());
952
952
  const T = E.data.sentence_emotions;
953
953
  if (Array.isArray(T)) {
954
954
  o.length = 0;
955
- for (const M of T) {
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,7 +965,7 @@ function Or(e, t = vt, r = {}) {
965
965
  });
966
966
  }
967
967
  }
968
- m(), b("metadata", C);
968
+ h(), b("metadata", C);
969
969
  } else if (E.event === "error")
970
970
  throw new Error(
971
971
  String(E.data.message ?? "avatar_ttsWithPoses stream error")
@@ -973,20 +973,20 @@ function Or(e, t = vt, r = {}) {
973
973
  }
974
974
  };
975
975
  for (; ; ) {
976
- const { done: v, value: E } = await de.read();
977
- E && (ue += ce.decode(E, { stream: !0 }));
978
- const h = ue.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
- ue = h.pop() ?? "";
982
- for (const T of h) await me(T);
981
+ fe = m.pop() ?? "";
982
+ for (const T of m) await ue(T);
983
983
  if (v) {
984
- ue.trim() && await me(ue.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 (Y) {
989
- throw console.error("[avatarTtsLipsync]", Y), B(), e("error"), Y;
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 = vt, 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) => {
@@ -1009,12 +1009,8 @@ function Or(e, t = vt, r = {}) {
1009
1009
  subscribe: (C) => (d.add(C), () => d.delete(C))
1010
1010
  };
1011
1011
  }
1012
- const kn = 16e3, Tn = 16e3, Nr = 4;
1013
- function Js(e) {
1014
- const t = e.trim();
1015
- return t ? t.split(/\s+/).filter(Boolean).length : 0;
1016
- }
1017
- class Qs extends jn {
1012
+ const bn = 16e3, kn = 16e3;
1013
+ class Xs extends zn {
1018
1014
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1019
1015
  async deserialize(t) {
1020
1016
  try {
@@ -1026,7 +1022,7 @@ class Qs extends jn {
1026
1022
  }
1027
1023
  }
1028
1024
  }
1029
- class Zs extends zn {
1025
+ class Js extends Gn {
1030
1026
  constructor() {
1031
1027
  super(
1032
1028
  !0,
@@ -1034,42 +1030,42 @@ class Zs extends zn {
1034
1030
  void 0,
1035
1031
  void 0,
1036
1032
  512,
1037
- kn,
1038
- Tn
1033
+ bn,
1034
+ kn
1039
1035
  );
1040
1036
  }
1041
1037
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
1042
1038
  bufferBotAudio(t, r) {
1043
1039
  }
1044
1040
  }
1045
- const ei = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1046
- function ti(e) {
1047
- return ei.test(e.trim());
1041
+ const Qs = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1042
+ function Zs(e) {
1043
+ return Qs.test(e.trim());
1048
1044
  }
1049
- function ri(e) {
1045
+ function ei(e) {
1050
1046
  const t = e.replace(/\/$/, "");
1051
1047
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
1052
1048
  }
1053
- function ni(e) {
1049
+ function ti(e) {
1054
1050
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
1055
1051
  const t = e.authToken?.trim();
1056
1052
  if (!t)
1057
1053
  throw new Error(
1058
1054
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1059
1055
  );
1060
- const r = e.apiBase ?? vt, n = new URL(`${ri(r)}/ws/voice`);
1056
+ const r = e.apiBase ?? St, n = new URL(`${ei(r)}/ws/voice`);
1061
1057
  n.searchParams.set("authToken", t), n.searchParams.set("tenant", "aiTwin");
1062
1058
  const s = e.voiceId?.trim();
1063
- s && ti(s) && n.searchParams.set("voiceId", s);
1059
+ s && Zs(s) && n.searchParams.set("voiceId", s);
1064
1060
  const i = e.personaId?.trim();
1065
1061
  i && n.searchParams.set("personaId", i);
1066
- const o = e.speakingRate ?? Ut;
1062
+ const o = e.speakingRate ?? Vt;
1067
1063
  return n.searchParams.set(
1068
1064
  "speaking_rate",
1069
- String(Math.max(lr, Math.min(fr, o)))
1065
+ String(Math.max(fr, Math.min(dr, o)))
1070
1066
  ), e.ttsStream === !1 ? n.searchParams.set("tts_stream", "false") : n.searchParams.set("tts_stream", "true"), n.toString();
1071
1067
  }
1072
- function jt(e, t) {
1068
+ function Yt(e, t) {
1073
1069
  if (!Array.isArray(e)) return [];
1074
1070
  const r = [];
1075
1071
  for (const n of e)
@@ -1083,7 +1079,7 @@ function jt(e, t) {
1083
1079
  });
1084
1080
  return r;
1085
1081
  }
1086
- function si(e) {
1082
+ function ri(e) {
1087
1083
  if (!e || typeof e != "object") return null;
1088
1084
  const t = e, n = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
1089
1085
  return {
@@ -1091,68 +1087,68 @@ function si(e) {
1091
1087
  type: String(n.type ?? t.type ?? "server-message")
1092
1088
  };
1093
1089
  }
1094
- function Yt(e) {
1090
+ function Xt(e) {
1095
1091
  return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
1096
1092
  }
1097
- function ii(e) {
1093
+ function ni(e) {
1098
1094
  return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
1099
1095
  }
1100
- function ai(e, t = {}) {
1096
+ function si(e, t = {}) {
1101
1097
  const r = [], n = [], s = [], i = [];
1102
1098
  let o = "", a = "neutral", u = it, l = !1, f = null, c = null, d = { ...t }, g = 0, S = null;
1103
- const m = /* @__PURE__ */ new Set(), I = [];
1104
- let _ = !1, R = null, w = !0, b = "default";
1099
+ const h = /* @__PURE__ */ new Set(), M = [];
1100
+ let _ = !1, D = null, w = !0, b = "default";
1105
1101
  const L = /* @__PURE__ */ new Set();
1106
- let B = null, j = 0, C = !1, k = null, P = "", U = !1;
1107
- const O = () => {
1102
+ let B = null, G = 0, C = !1, k = null, P = !1;
1103
+ const N = () => {
1108
1104
  k != null && (clearTimeout(k), k = null);
1109
- }, q = () => m.forEach((p) => p());
1110
- let fe = () => !1;
1111
- const D = _n(
1105
+ }, I = () => h.forEach((p) => p());
1106
+ let te = () => !1;
1107
+ const V = yn(
1112
1108
  {
1113
1109
  onSpeakingStart: () => e("speaking"),
1114
1110
  onSpeakingDone: () => {
1115
- U = !1, e("done");
1111
+ P = !1, e("done");
1116
1112
  },
1117
- onNotify: q,
1118
- shouldHoldForWarmup: () => fe()
1113
+ onNotify: I,
1114
+ shouldHoldForWarmup: () => te()
1119
1115
  },
1120
1116
  u
1121
- ), Y = () => {
1122
- if (R) return R;
1117
+ ), J = () => {
1118
+ if (D) return D;
1123
1119
  const p = new MessageChannel();
1124
1120
  return p.port1.onmessage = () => {
1125
- const x = I.shift();
1126
- x !== void 0 && Se(x), I.length > 0 ? p.port2.postMessage(null) : _ = !1;
1127
- }, R = p, p;
1128
- }, Q = (p) => {
1129
- I.push(p), !_ && (_ = !0, Y().port2.postMessage(null));
1130
- }, de = () => D.getPlaybackElapsedMs(), ce = (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) => {
1131
1127
  if (!d.onLipsyncDebug) return;
1132
- const G = de(), X = r;
1128
+ const z = X(), ne = r;
1133
1129
  d.onLipsyncDebug({
1134
1130
  event: p,
1135
1131
  spokenText: x,
1136
1132
  mood: a,
1137
- playbackAnchorPerf: D.getPlaybackStartPerf(),
1138
- playbackElapsedMs: G,
1139
- queueLength: X.length,
1140
- activeViseme: Nt(X, G),
1141
- segments: i.map((oe) => ({
1142
- ...oe,
1143
- visemes: [...oe.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]
1144
1140
  }))
1145
1141
  });
1146
- }, ue = (p, x) => {
1142
+ }, re = (p, x) => {
1147
1143
  d.onLipsyncDebug && (S = { event: p, spokenText: x }, g === 0 && (g = requestAnimationFrame(() => {
1148
1144
  g = 0;
1149
- const G = S;
1150
- S = null, G && ce(G.event, G.spokenText);
1145
+ const z = S;
1146
+ S = null, z && pe(z.event, z.spokenText);
1151
1147
  })));
1152
- }, se = () => {
1153
- w = !0, L.clear(), D.clearAborted();
1154
- }, me = () => {
1155
- const p = ii(f);
1148
+ }, fe = () => {
1149
+ w = !0, L.clear(), V.clearAborted();
1150
+ }, de = () => {
1151
+ const p = ni(f);
1156
1152
  if (p) {
1157
1153
  b = `bot-${Date.now()}`, p.interruptedTrackIds = { [b]: !0 };
1158
1154
  try {
@@ -1165,270 +1161,262 @@ function ai(e, t = {}) {
1165
1161
  x?.interrupt?.();
1166
1162
  } catch {
1167
1163
  }
1168
- }, v = (p) => {
1169
- if (U && D.isSpeaking())
1164
+ }, ue = (p) => {
1165
+ if (P && V.isSpeaking())
1170
1166
  return !0;
1171
1167
  const x = p.context_id?.trim();
1172
- return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" || Yt(p));
1173
- }, E = (p) => {
1174
- const x = Js(P);
1175
- if (D.isSpeaking() && x < Nr) {
1176
- console.debug(
1177
- "[realtimeVoice] ignoring interrupt — backchannel below barge-in threshold",
1178
- { wordCount: x, minWords: Nr, source: p.source }
1179
- ), U = !0;
1180
- return;
1181
- }
1182
- w = !1, U = !1;
1183
- const X = p.context_id?.trim();
1184
- X && L.add(X), O(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, j += 1, me(), D.bargeIn(), h(), e("idle"), ue("interrupt"), q();
1185
- }, h = () => {
1168
+ return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" || Xt(p));
1169
+ }, v = (p) => {
1170
+ w = !1, P = !1;
1171
+ const x = p.context_id?.trim();
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 = () => {
1186
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();
1187
1177
  }, T = () => {
1188
- D.stop(), h(), ue("reset"), q();
1189
- }, M = () => {
1190
- T(), e("idle"), q();
1191
- }, F = (p, x) => {
1178
+ m(), e("idle"), I();
1179
+ }, R = (p, x) => {
1192
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(
1193
- ...jt(p.sentence_emotions, a)
1181
+ ...Yt(p.sentence_emotions, a)
1194
1182
  ));
1195
- }, A = (p) => {
1196
- if (v({ ...p, type: "avatar_metadata" }))
1183
+ }, F = (p) => {
1184
+ if (ue({ ...p, type: "avatar_metadata" }))
1197
1185
  return;
1198
- se(), C = !0;
1186
+ fe(), C = !0;
1199
1187
  const x = String(p.spoken_text ?? p.text ?? "").trim();
1200
- x && (o = x), D.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
1201
- ...jt(p.sentence_emotions, a)
1202
- ), Array.isArray(p.gestures) && p.gestures, ue("metadata", x), q();
1203
- }, W = (p, x, G, X) => {
1188
+ x && (o = x), V.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
1189
+ ...Yt(p.sentence_emotions, a)
1190
+ ), Array.isArray(p.gestures) && p.gestures, re("metadata", x), I();
1191
+ }, A = (p, x, z, ne) => {
1204
1192
  if (!d.onLipsyncDebug) return;
1205
- const oe = r.slice(G), Ce = X.filter(
1206
- (te) => String(te.symbol ?? te.viseme ?? "").trim()
1193
+ const ce = r.slice(z), Te = ne.filter(
1194
+ (me) => String(me.symbol ?? me.viseme ?? "").trim()
1207
1195
  );
1208
1196
  i.push({
1209
1197
  spokenText: x,
1210
- audioOffsetMs: oe[0]?.vtime ?? 0,
1198
+ audioOffsetMs: ce[0]?.vtime ?? 0,
1211
1199
  isNewSegment: !!p.is_new_segment,
1212
1200
  chunkDurationMs: p.chunk_duration_ms != null ? Number(p.chunk_duration_ms) : null,
1213
1201
  receivedAtMs: performance.now(),
1214
- visemes: oe.map((te, be) => {
1215
- const Ie = Ce[be];
1202
+ visemes: ce.map((me, he) => {
1203
+ const _e = Te[he];
1216
1204
  return {
1217
- rawSymbol: String(Ie?.symbol ?? Ie?.viseme ?? te.viseme).trim(),
1218
- viseme: te.viseme,
1219
- startSec: Number(Ie?.start ?? 0),
1220
- durationSec: Number(Ie?.duration ?? 0),
1221
- vtimeMs: te.vtime,
1222
- vdurationMs: te.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
1223
1211
  };
1224
1212
  })
1225
1213
  });
1226
- }, J = (p) => {
1227
- if (v(p)) return;
1228
- O(), Yt(p) && se();
1229
- const x = String(p.spoken_text ?? p.text ?? "").trim(), G = Yt(p), X = p.visemes ?? [], oe = p.words ?? [], Ce = String(p.chunk ?? "").trim(), te = C;
1230
- te && (C = !1), x && (o = x), F(p, G), te ? D.resetForNewStream(u) : G && D.resumeBotStream();
1231
- const be = r.length;
1232
- D.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(
1233
1221
  r,
1234
1222
  n,
1235
- Ce,
1236
- X,
1237
- oe,
1238
- G,
1223
+ Te,
1224
+ ne,
1225
+ ce,
1226
+ z,
1239
1227
  {
1240
1228
  sampleRate: p.sample_rate,
1241
- newStream: te,
1229
+ newStream: me,
1242
1230
  onNewStream: () => {
1243
1231
  i.length = 0;
1244
1232
  }
1245
1233
  }
1246
1234
  ).then(() => {
1247
- W(p, x, be, X), ue("audio_chunk", x);
1235
+ A(p, x, he, ne), re("audio_chunk", x);
1248
1236
  });
1249
- }, Z = (p) => {
1250
- if (v(p)) return;
1251
- (p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) && se(), 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(
1252
1240
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
1253
1241
  );
1254
1242
  const x = String(p.spoken_text ?? p.text ?? "").trim();
1255
- x && (o = x), F(p, !!p.is_new_segment);
1256
- const G = r.length;
1257
- D.queueTimingsOnly(
1243
+ x && (o = x), R(p, !!p.is_new_segment);
1244
+ const z = r.length;
1245
+ V.queueTimingsOnly(
1258
1246
  r,
1259
1247
  n,
1260
1248
  p.visemes ?? [],
1261
1249
  p.words ?? [],
1262
1250
  !!p.is_new_segment
1263
- ), W(
1251
+ ), A(
1264
1252
  p,
1265
1253
  x,
1266
- G,
1254
+ z,
1267
1255
  p.visemes ?? []
1268
- ), ue("lipsync", x), q();
1269
- }, ee = async (p) => {
1256
+ ), re("lipsync", x), I();
1257
+ }, Q = async (p) => {
1270
1258
  const x = String(p.text ?? "").trim();
1271
1259
  if (!x) return;
1272
- const G = d.authToken?.trim();
1273
- if (!G) {
1260
+ const z = d.authToken?.trim();
1261
+ if (!z) {
1274
1262
  console.error("[realtimeVoice] avatar_speak requires authToken");
1275
1263
  return;
1276
1264
  }
1277
1265
  B?.abort();
1278
- const X = new AbortController();
1279
- B = X;
1280
- const oe = ++j;
1281
- se(), D.resetForNewStream(u), o = x;
1282
- const te = `${(d.apiBase ?? vt).replace(/\/$/, "")}/avatar_ttsWithPoses`, be = d.voiceId?.trim() || bn, Ie = d.speakingRate ?? Ut, Oe = Math.max(
1283
- lr,
1284
- Math.min(fr, Ie)
1285
- ), ct = {
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(
1271
+ fr,
1272
+ Math.min(dr, _e)
1273
+ ), Ce = {
1286
1274
  user_query: x,
1287
1275
  ttsEngineId: u,
1288
- speakingRate: Oe,
1276
+ speakingRate: ct,
1289
1277
  tenant: "aiTwin"
1290
1278
  };
1291
- on.has(u) && (ct.voice_id = be);
1279
+ an.has(u) && (Ce.voice_id = he);
1292
1280
  try {
1293
- const Me = await fetch(te, {
1281
+ const Oe = await fetch(me, {
1294
1282
  method: "POST",
1295
1283
  headers: {
1296
1284
  "Content-Type": "application/json",
1297
- Authorization: `Bearer ${G}`
1285
+ Authorization: `Bearer ${z}`
1298
1286
  },
1299
- body: JSON.stringify(ct),
1300
- signal: X.signal
1287
+ body: JSON.stringify(Ce),
1288
+ signal: ne.signal
1301
1289
  });
1302
- if (!Me.ok)
1303
- throw new Error(`avatar_ttsWithPoses failed (${Me.status})`);
1304
- const Ye = Me.body;
1305
- if (!Ye) throw new Error("No response body");
1306
- const bt = Ye.getReader(), le = new TextDecoder();
1307
- let Ne = "", ut = !0;
1308
- const lt = async (Ue) => {
1309
- if (oe !== j || X.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)
1310
1298
  return;
1311
- const he = mn(Ue);
1312
- if (he) {
1313
- if (he.event === "audio") {
1314
- const pe = he.data.chunk, ke = he.data.visemes ?? [], _e = he.data.words ?? [], Ve = he.data.is_new_segment ?? !1, re = he.data.sample_rate;
1315
- if (pe) {
1316
- const ne = ut;
1317
- ut = !1, await D.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(
1318
1306
  r,
1319
1307
  n,
1320
- pe,
1321
- ke,
1322
- _e,
1323
- Ve,
1324
- { sampleRate: re, newStream: ne }
1308
+ ve,
1309
+ we,
1310
+ Ye,
1311
+ Ee,
1312
+ { sampleRate: Ve, newStream: ee }
1325
1313
  );
1326
- } else (ke.length > 0 || _e.length > 0) && D.queueTimingsOnly(
1314
+ } else (we.length > 0 || Ye.length > 0) && V.queueTimingsOnly(
1327
1315
  r,
1328
1316
  n,
1329
- ke,
1330
- _e,
1331
- Ve
1317
+ we,
1318
+ Ye,
1319
+ Ee
1332
1320
  );
1333
- } else if (he.event === "metadata") {
1334
- const pe = he.data.mood;
1335
- typeof pe == "string" && pe.trim() && (a = pe.trim());
1336
- const ke = he.data.sentence_emotions;
1337
- Array.isArray(ke) && (s.length = 0, s.push(
1338
- ...jt(ke, a)
1339
- )), q();
1340
- } else if (he.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")
1341
1329
  throw new Error(
1342
- String(he.data.message ?? "avatar_ttsWithPoses stream error")
1330
+ String(le.data.message ?? "avatar_ttsWithPoses stream error")
1343
1331
  );
1344
1332
  }
1345
1333
  };
1346
- for (; !(oe !== j || X.signal.aborted || !w); ) {
1347
- const { done: Ue, value: he } = await bt.read();
1348
- he && (Ne += le.decode(he, { stream: !0 }));
1349
- 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(`
1350
1338
 
1351
1339
  `);
1352
- Ne = pe.pop() ?? "";
1353
- for (const ke of pe) await lt(ke);
1354
- if (Ue) {
1355
- Ne.trim() && await lt(Ne.trim()), oe === j && !X.signal.aborted && w && D.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);
1356
1344
  break;
1357
1345
  }
1358
1346
  }
1359
- } catch (Me) {
1360
- if (X.signal.aborted || !w) return;
1361
- console.error("[realtimeVoice] avatar_speak failed:", Me), e("error"), q();
1347
+ } catch (Oe) {
1348
+ if (ne.signal.aborted || !w) return;
1349
+ console.error("[realtimeVoice] avatar_speak failed:", Oe), e("error"), I();
1362
1350
  } finally {
1363
- B === X && (B = null);
1351
+ B === ne && (B = null);
1364
1352
  }
1365
- }, Se = (p) => {
1366
- const x = si(p);
1353
+ }, Z = (p) => {
1354
+ const x = ri(p);
1367
1355
  if (!x) {
1368
1356
  console.warn("[realtimeVoice] server message with no payload", p);
1369
1357
  return;
1370
1358
  }
1371
- const G = String(x.type ?? "unknown");
1372
- switch (G !== "avatar_metadata" && G !== "avatar_audio_chunk" && G !== "avatar_lipsync" && G !== "avatar_interrupt" && G !== "error" && console.debug("[realtimeVoice] server message", G, x), G) {
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) {
1373
1361
  case "avatar_metadata":
1374
- A(x);
1362
+ F(x);
1375
1363
  break;
1376
1364
  case "avatar_audio_chunk":
1377
- J(x);
1365
+ $(x);
1378
1366
  break;
1379
1367
  case "avatar_lipsync":
1380
- Z(x);
1368
+ Y(x);
1381
1369
  break;
1382
1370
  case "avatar_interrupt":
1383
- E(x);
1371
+ v(x);
1384
1372
  break;
1385
1373
  case "error": {
1386
- const X = String(x.message ?? "Voice session error");
1387
- console.error("[realtimeVoice] server error:", X), e("error"), q();
1374
+ const ne = String(x.message ?? "Voice session error");
1375
+ console.error("[realtimeVoice] server error:", ne), e("error"), I();
1388
1376
  break;
1389
1377
  }
1390
1378
  case "avatar_speak":
1391
- ee(x);
1379
+ Q(x);
1392
1380
  break;
1393
1381
  }
1394
- }, ye = () => f || (c = new Zs(), f = new Kn({
1395
- transport: new Gn({
1382
+ }, be = () => f || (c = new Js(), f = new qn({
1383
+ transport: new Kn({
1396
1384
  mediaManager: c,
1397
- serializer: new Qs(),
1398
- recorderSampleRate: kn,
1399
- playerSampleRate: Tn
1385
+ serializer: new Xs(),
1386
+ recorderSampleRate: bn,
1387
+ playerSampleRate: kn
1400
1388
  }),
1401
1389
  enableCam: !1,
1402
1390
  enableMic: !0,
1403
1391
  callbacks: {
1404
1392
  onBotReady: () => {
1405
- l = !0, e("idle"), q();
1393
+ l = !0, e("idle"), I();
1406
1394
  },
1407
1395
  onDisconnected: () => {
1408
- l = !1, M();
1396
+ l = !1, T();
1409
1397
  },
1410
1398
  onError: (p) => {
1411
1399
  const x = typeof p == "object" && p !== null && "data" in p ? String(p.data ?? p) : String(p);
1412
- console.error("[realtimeVoice]", x, p), e("error"), q();
1400
+ console.error("[realtimeVoice]", x, p), e("error"), I();
1413
1401
  },
1414
1402
  onTransportStateChanged: (p) => {
1415
- p === "error" && (e("error"), q());
1403
+ p === "error" && (e("error"), I());
1416
1404
  },
1417
1405
  onServerMessage: (p) => {
1418
- Q(p);
1406
+ j(p);
1419
1407
  },
1420
1408
  onUserStartedSpeaking: () => {
1421
1409
  },
1422
1410
  onBotStartedSpeaking: () => {
1423
- se(), ue("bot_started");
1411
+ fe(), re("bot_started");
1424
1412
  },
1425
1413
  onBotStoppedSpeaking: () => {
1426
- w && (O(), k = setTimeout(() => {
1427
- k = null, w && (D.markStreamComplete(r), ue("bot_stopped"));
1414
+ w && (N(), k = setTimeout(() => {
1415
+ k = null, w && (V.markStreamComplete(r), re("bot_stopped"));
1428
1416
  }, 450));
1429
1417
  },
1430
1418
  onUserTranscript: (p) => {
1431
- P = String(p.text ?? ""), d.onUserTranscript?.(p.text, !!p.final);
1419
+ String(p.text ?? ""), d.onUserTranscript?.(p.text, !!p.final);
1432
1420
  },
1433
1421
  onBotOutput: (p) => {
1434
1422
  d.onBotOutput?.(p.text);
@@ -1439,21 +1427,21 @@ function ai(e, t = {}) {
1439
1427
  setDeveloperToken: (p) => {
1440
1428
  },
1441
1429
  setTtsEngineId: (p) => {
1442
- u = p, D.setStreamTtsEngineId(p);
1430
+ u = p, V.setStreamTtsEngineId(p);
1443
1431
  },
1444
1432
  getTtsEngineId: () => u,
1445
1433
  speak: async (p, x) => {
1446
- const G = p.trim();
1447
- if (G) {
1434
+ const z = p.trim();
1435
+ if (z) {
1448
1436
  if (!f || !l)
1449
1437
  throw new Error(
1450
1438
  "Realtime voice is not connected. Call connect() first."
1451
1439
  );
1452
- T(), await f.sendText(G);
1440
+ m(), await f.sendText(z);
1453
1441
  }
1454
1442
  },
1455
1443
  stop: () => {
1456
- B?.abort(), B = null, j += 1, se(), T(), e("idle"), q();
1444
+ B?.abort(), B = null, G += 1, fe(), m(), e("idle"), I();
1457
1445
  },
1458
1446
  connect: async (p) => {
1459
1447
  if (p && (d = { ...d, ...p }), !d.authToken?.trim())
@@ -1461,58 +1449,58 @@ function ai(e, t = {}) {
1461
1449
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1462
1450
  );
1463
1451
  e("loading");
1464
- const x = ye();
1452
+ const x = be();
1465
1453
  await x.initDevices();
1466
- const G = ni(d);
1467
- console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", G);
1454
+ const z = ti(d);
1455
+ console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", z);
1468
1456
  try {
1469
- await x.connect({ wsUrl: G });
1470
- } catch (X) {
1471
- l = !1, e("error"), q();
1472
- const oe = X instanceof Error ? X.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1473
- throw new Error(`${oe} — ${G}`);
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}`);
1474
1462
  }
1475
- l = !0, e("idle"), q();
1463
+ l = !0, e("idle"), I();
1476
1464
  },
1477
1465
  disconnect: async () => {
1478
- if (O(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, j += 1, se(), f)
1466
+ if (N(), C = !1, M.length = 0, _ = !1, B?.abort(), B = null, G += 1, fe(), f)
1479
1467
  try {
1480
1468
  await f.disconnect();
1481
1469
  } catch (p) {
1482
1470
  console.error("[realtimeVoice] disconnect failed:", p);
1483
1471
  }
1484
- l = !1, M();
1472
+ l = !1, T();
1485
1473
  },
1486
1474
  isConnected: () => l,
1487
1475
  unlockAudio: async () => {
1488
- await D.primeAudioContext();
1476
+ await V.primeAudioContext();
1489
1477
  },
1490
1478
  getVisemeQueue: () => r,
1491
1479
  getWordQueue: () => n,
1492
1480
  getSentenceEmotions: () => s,
1493
1481
  getStreamMood: () => a,
1494
- getPlaybackElapsedMs: de,
1495
- isSpeaking: () => D.isSpeaking(),
1496
- isWarmingUp: () => D.isWarmingUp(),
1497
- releaseWarmupHold: () => D.releaseWarmupHold(),
1482
+ getPlaybackElapsedMs: X,
1483
+ isSpeaking: () => V.isSpeaking(),
1484
+ isWarmingUp: () => V.isWarmingUp(),
1485
+ releaseWarmupHold: () => V.releaseWarmupHold(),
1498
1486
  setLipsyncWarmupHold: (p, x) => {
1499
- x && (fe = x), D.setLipsyncWarmupHoldEnabled(p);
1487
+ x && (te = x), V.setLipsyncWarmupHoldEnabled(p);
1500
1488
  },
1501
- getVoiceStream: () => D.getVoiceStream(),
1489
+ getVoiceStream: () => V.getVoiceStream(),
1502
1490
  setPlaybackSpeed: (p) => {
1503
- D.setPlaybackSpeed(p);
1491
+ V.setPlaybackSpeed(p);
1504
1492
  },
1505
- getPlaybackSpeed: () => D.getPlaybackSpeed(),
1506
- subscribe: (p) => (m.add(p), () => m.delete(p))
1493
+ getPlaybackSpeed: () => V.getPlaybackSpeed(),
1494
+ subscribe: (p) => (h.add(p), () => h.delete(p))
1507
1495
  };
1508
1496
  }
1509
- function En(e, t, r) {
1497
+ function Tn(e, t, r) {
1510
1498
  return {
1511
1499
  width: e.crop?.source_width ?? t,
1512
1500
  height: e.crop?.source_height ?? r
1513
1501
  };
1514
1502
  }
1515
- function An(e, t) {
1503
+ function En(e, t) {
1516
1504
  const r = e.crop;
1517
1505
  return {
1518
1506
  x: t?.source_x ?? r?.x ?? 0,
@@ -1521,25 +1509,25 @@ function An(e, t) {
1521
1509
  height: t?.source_h ?? r?.height ?? e.frame_height ?? 0
1522
1510
  };
1523
1511
  }
1524
- function Pn(e) {
1512
+ function An(e) {
1525
1513
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1526
1514
  }
1527
1515
  async function at(e, t) {
1528
1516
  const r = await fetch(e);
1529
1517
  if (!r.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1530
1518
  const n = await r.arrayBuffer();
1531
- return ks(n, t);
1519
+ return bs(n, t);
1532
1520
  }
1533
- async function xn(e, t) {
1521
+ async function Pn(e, t) {
1534
1522
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1535
1523
  const r = await at(e, t), n = new TextDecoder().decode(r);
1536
1524
  return JSON.parse(n);
1537
1525
  }
1538
- async function oi(e) {
1526
+ async function ii(e) {
1539
1527
  const t = new Blob([e], { type: "image/webp" });
1540
1528
  return createImageBitmap(t);
1541
1529
  }
1542
- async function ci(e) {
1530
+ async function ai(e) {
1543
1531
  const t = new Blob([e], { type: "image/webp" }), r = URL.createObjectURL(t);
1544
1532
  return new Promise((n, s) => {
1545
1533
  const i = new Image();
@@ -1550,11 +1538,11 @@ async function ci(e) {
1550
1538
  }, i.src = r;
1551
1539
  });
1552
1540
  }
1553
- async function ui(e) {
1541
+ async function oi(e) {
1554
1542
  const t = new Blob([e], { type: "image/png" });
1555
1543
  return createImageBitmap(t);
1556
1544
  }
1557
- async function li(e) {
1545
+ async function ci(e) {
1558
1546
  const t = new Blob([e], { type: "image/png" }), r = URL.createObjectURL(t);
1559
1547
  return new Promise((n, s) => {
1560
1548
  const i = new Image();
@@ -1565,28 +1553,28 @@ async function li(e) {
1565
1553
  }, i.src = r;
1566
1554
  });
1567
1555
  }
1568
- function fi(e) {
1556
+ function ui(e) {
1569
1557
  const t = new Blob([e], { type: "video/mp4" });
1570
1558
  return URL.createObjectURL(t);
1571
1559
  }
1572
- async function di(e) {
1573
- const t = Ps();
1574
- if (!St()) return t;
1560
+ async function li(e) {
1561
+ const t = As();
1562
+ if (!bt()) return t;
1575
1563
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1576
1564
  const r = await at(t, e);
1577
- return fi(r);
1565
+ return ui(r);
1578
1566
  }
1579
- function dr(e, t) {
1567
+ function mr(e, t) {
1580
1568
  return `${e}/${t}_minus_sil.png`;
1581
1569
  }
1582
- const In = 5;
1583
- function Vt(e) {
1570
+ const xn = 5;
1571
+ function Wt(e) {
1584
1572
  const t = e?.composite_threshold;
1585
1573
  if (typeof t == "number" && t > 0) return t;
1586
1574
  const r = e?.crop?.content_threshold;
1587
- return typeof r == "number" && r > 0 ? r : In;
1575
+ return typeof r == "number" && r > 0 ? r : xn;
1588
1576
  }
1589
- const Ra = [
1577
+ const Ia = [
1590
1578
  "aa",
1591
1579
  "E",
1592
1580
  "I",
@@ -1601,11 +1589,11 @@ const Ra = [
1601
1589
  "RR",
1602
1590
  "kk",
1603
1591
  "nn"
1604
- ], er = [
1592
+ ], tr = [
1605
1593
  "t01_0.25",
1606
1594
  "t02_0.50",
1607
1595
  "t03_0.75"
1608
- ], mi = er.length, Ur = /* @__PURE__ */ new Set([
1596
+ ], fi = tr.length, Nr = /* @__PURE__ */ new Set([
1609
1597
  "aa__kk",
1610
1598
  "aa__nn",
1611
1599
  "aa__sil",
@@ -1712,75 +1700,75 @@ const Ra = [
1712
1700
  "U__nn",
1713
1701
  "U__sil"
1714
1702
  ]);
1715
- function Vr(e, t) {
1703
+ function Ur(e, t) {
1716
1704
  return `${e}__${t}`;
1717
1705
  }
1718
- function Wr(e, t) {
1706
+ function Vr(e, t) {
1719
1707
  return `pairs/${e}/${t}_minus_sil.png`;
1720
1708
  }
1721
- function _t(e) {
1709
+ function vt(e) {
1722
1710
  return `${e}_minus_sil.png`;
1723
1711
  }
1724
- function mr(e, t) {
1712
+ function hr(e, t) {
1725
1713
  if (t.has(e)) return e;
1726
1714
  const r = /^pairs\/([^/]+)\//.exec(e);
1727
1715
  if (!r) return null;
1728
1716
  const n = r[1].split("__")[1];
1729
1717
  if (!n || n === "sil") return null;
1730
- const s = _t(n);
1718
+ const s = vt(n);
1731
1719
  return t.has(s) ? s : null;
1732
1720
  }
1733
- function Mn(e, t) {
1721
+ function In(e, t) {
1734
1722
  return e.filter((r) => t.has(r));
1735
1723
  }
1736
- function hi(e, t, r) {
1737
- const n = hr(e, t);
1738
- return Mn(n, r).length > 0;
1724
+ function di(e, t, r) {
1725
+ const n = pr(e, t);
1726
+ return In(n, r).length > 0;
1739
1727
  }
1740
- function hr(e, t) {
1728
+ function pr(e, t) {
1741
1729
  if (e === t) return [];
1742
- const r = [], n = Vr(e, t);
1743
- if (Ur.has(n)) {
1744
- for (const i of er)
1745
- r.push(Wr(n, i));
1730
+ const r = [], n = Ur(e, t);
1731
+ if (Nr.has(n)) {
1732
+ for (const i of tr)
1733
+ r.push(Vr(n, i));
1746
1734
  return r;
1747
1735
  }
1748
- const s = Vr(t, e);
1749
- if (Ur.has(s)) {
1750
- for (let i = mi - 1; i >= 0; i--)
1751
- r.push(Wr(s, er[i]));
1736
+ const s = Ur(t, e);
1737
+ if (Nr.has(s)) {
1738
+ for (let i = fi - 1; i >= 0; i--)
1739
+ r.push(Vr(s, tr[i]));
1752
1740
  return r;
1753
1741
  }
1754
1742
  return [];
1755
1743
  }
1756
- function pi(e) {
1744
+ function mi(e) {
1757
1745
  return e < 16 ? [1] : e < 24 ? [1] : e < 35 ? [0, 1, 2] : [0, 1, 2];
1758
1746
  }
1759
- function wi(e, t) {
1760
- return pi(t).map((n) => e[n]).filter((n) => n != null);
1747
+ function hi(e, t) {
1748
+ return mi(t).map((n) => e[n]).filter((n) => n != null);
1761
1749
  }
1762
- function gi(e, t, r, n) {
1750
+ function pi(e, t, r, n) {
1763
1751
  if (n <= 0) return 0;
1764
1752
  const i = Math.max(1, r - t) / n, o = e - t, a = Math.floor(o / i);
1765
1753
  return Math.min(n - 1, Math.max(0, a));
1766
1754
  }
1767
- function Rn(e, t, r) {
1755
+ function Mn(e, t, r) {
1768
1756
  if (!r) return `${e}/${t}`;
1769
1757
  const n = t.split("/").pop() ?? t, s = n.includes(".") ? n.slice(0, n.lastIndexOf(".")) : n;
1770
1758
  return `${e}/${s}.bin`;
1771
1759
  }
1772
- const yi = [0.32, 0.24, 0.16, 0.08, 0], _i = yi.map(
1760
+ const wi = [0.32, 0.24, 0.16, 0.08, 0], gi = wi.map(
1773
1761
  (e) => `eyes_${e.toFixed(2)}`
1774
- ), vi = [
1762
+ ), yi = [
1775
1763
  "eyes_0.32",
1776
1764
  "eyes_0.16",
1777
1765
  "eyes_0.00"
1778
- ], Si = [
1766
+ ], _i = [
1779
1767
  "eyes_0.32",
1780
1768
  "eyes_0.16",
1781
1769
  "eyes_0.08",
1782
1770
  "eyes_0.00"
1783
- ], Hr = 2, bi = -30, tr = 20, ki = {
1771
+ ], Wr = 2, vi = -30, rr = 20, Si = {
1784
1772
  fear: -30,
1785
1773
  anger: -20,
1786
1774
  sad: -10,
@@ -1789,24 +1777,24 @@ const yi = [0.32, 0.24, 0.16, 0.08, 0], _i = yi.map(
1789
1777
  happy: 0,
1790
1778
  disgust: 20
1791
1779
  };
1792
- function pr(e) {
1780
+ function wr(e) {
1793
1781
  return `brow_${e}`;
1794
1782
  }
1795
- function wr(e) {
1796
- return ki[e];
1783
+ function gr(e) {
1784
+ return Si[e];
1797
1785
  }
1798
- function Ge(e) {
1799
- return Math.max(bi, Math.min(tr, e));
1786
+ function Ke(e) {
1787
+ return Math.max(vi, Math.min(rr, e));
1800
1788
  }
1801
- function Ti(e, t) {
1789
+ function bi(e, t) {
1802
1790
  if (e === t) return [];
1803
- const r = e < t ? Hr : -Hr, n = [];
1791
+ const r = e < t ? Wr : -Wr, n = [];
1804
1792
  let s = e;
1805
1793
  for (; s !== t; )
1806
1794
  s += r, n.push(s);
1807
1795
  return n;
1808
1796
  }
1809
- const Ei = {
1797
+ const ki = {
1810
1798
  fear: "fear",
1811
1799
  afraid: "fear",
1812
1800
  anxiety: "fear",
@@ -1831,61 +1819,61 @@ const Ei = {
1831
1819
  };
1832
1820
  function et(e, t = "neutral") {
1833
1821
  const r = String(e ?? "").trim().toLowerCase();
1834
- return r ? Ei[r] ?? t : t;
1822
+ return r ? ki[r] ?? t : t;
1835
1823
  }
1836
- function Dn(e) {
1837
- return e === 0 ? null : dr(pr(e), "eyes_standard");
1824
+ function Rn(e) {
1825
+ return e === 0 ? null : mr(wr(e), "eyes_standard");
1838
1826
  }
1839
- function Bn(e) {
1840
- return Dn(wr(e));
1827
+ function Dn(e) {
1828
+ return Rn(gr(e));
1841
1829
  }
1842
- function $r(e, t) {
1843
- const r = pr(wr(e));
1844
- return !t || t === "eyes_standard" ? Bn(e) : e === "neutral" && t === "eyes_standard" ? null : dr(r, t);
1830
+ function Hr(e, t) {
1831
+ const r = wr(gr(e));
1832
+ return !t || t === "eyes_standard" ? Dn(e) : e === "neutral" && t === "eyes_standard" ? null : mr(r, t);
1845
1833
  }
1846
- function Ai(e, t) {
1834
+ function Ti(e, t) {
1847
1835
  const r = [];
1848
1836
  for (const n of t)
1849
- r.push($r(e, n));
1837
+ r.push(Hr(e, n));
1850
1838
  for (let n = t.length - 2; n >= 0; n--)
1851
- r.push($r(e, t[n]));
1852
- return r.push(Bn(e)), r;
1839
+ r.push(Hr(e, t[n]));
1840
+ return r.push(Dn(e)), r;
1853
1841
  }
1854
- function Pi(e) {
1855
- return dr(pr(e), "eyes_standard");
1842
+ function Ei(e) {
1843
+ return mr(wr(e), "eyes_standard");
1856
1844
  }
1857
- function xi(e, t) {
1858
- return Ti(e, t).map(Pi);
1845
+ function Ai(e, t) {
1846
+ return bi(e, t).map(Ei);
1859
1847
  }
1860
- const Ii = 6;
1861
- function Mi(e, t) {
1848
+ const Pi = 6;
1849
+ function xi(e, t) {
1862
1850
  for (const r of e)
1863
1851
  if (t >= r.wtime && t < r.wtime + r.wduration)
1864
1852
  return r;
1865
1853
  return null;
1866
1854
  }
1867
- function Ri(e) {
1868
- const t = Ge(e);
1869
- return t >= tr ? tr : Ge(t + Ii);
1855
+ function Ii(e) {
1856
+ const t = Ke(e);
1857
+ return t >= rr ? rr : Ke(t + Pi);
1870
1858
  }
1871
- function Di(e, t, r) {
1872
- const n = Ge(r);
1873
- return Mi(t, e)?.emphasis ? Ri(n) : n;
1859
+ function Mi(e, t, r) {
1860
+ const n = Ke(r);
1861
+ return xi(t, e)?.emphasis ? Ii(n) : n;
1874
1862
  }
1875
- function qr(e) {
1863
+ function $r(e) {
1876
1864
  if (!e) return 0;
1877
1865
  const t = e.match(/^brow_(-?\d+)\//);
1878
1866
  if (!t?.[1]) return null;
1879
1867
  const r = Number.parseInt(t[1], 10);
1880
- return Number.isFinite(r) ? Ge(r) : null;
1868
+ return Number.isFinite(r) ? Ke(r) : null;
1881
1869
  }
1882
- function gt(e, t) {
1870
+ function yt(e, t) {
1883
1871
  return e + Math.random() * (t - e);
1884
1872
  }
1885
- function Rt() {
1886
- return gt(14, 32);
1873
+ function Dt() {
1874
+ return yt(14, 32);
1887
1875
  }
1888
- function Bi(e = {}) {
1876
+ function Ri(e = {}) {
1889
1877
  const {
1890
1878
  initialDelayMs: t = 800 + Math.random() * 1200,
1891
1879
  intervalMinMs: r = 2200,
@@ -1897,100 +1885,100 @@ function Bi(e = {}) {
1897
1885
  postEmotionChangeDelayMs: u = 380,
1898
1886
  minDwellMs: l = 550
1899
1887
  } = e;
1900
- 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 = {
1901
1889
  kind: "idle",
1902
1890
  nextBlinkAt: performance.now() + t
1903
- }, I = null, _ = "__eyes_open__|neutral|brow:0";
1904
- function R(k = f) {
1905
- _ = `${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}`;
1906
1894
  }
1907
1895
  function w(k, P = f) {
1908
- I = k;
1909
- const U = qr(k);
1910
- U != null ? g = U : 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);
1911
1899
  }
1912
1900
  function b(k) {
1913
- return Dn(k);
1901
+ return Rn(k);
1914
1902
  }
1915
- function L(k, P, U) {
1916
- const O = Ge(P), q = Ge(U);
1917
- if (d = q, O === q) {
1918
- w(b(q));
1903
+ function L(k, P, N) {
1904
+ const I = Ke(P), te = Ke(N);
1905
+ if (d = te, I === te) {
1906
+ w(b(te));
1919
1907
  return;
1920
1908
  }
1921
- const fe = [
1922
- ...xi(O, q),
1923
- b(q)
1909
+ const V = [
1910
+ ...Ai(I, te),
1911
+ b(te)
1924
1912
  ];
1925
- m = {
1913
+ h = {
1926
1914
  kind: "browBlend",
1927
- paths: fe,
1915
+ paths: V,
1928
1916
  index: 0,
1929
- holdUntil: k + Rt(),
1930
- targetBrow: q
1931
- }, w(fe[0] ?? null);
1917
+ holdUntil: k + Dt(),
1918
+ targetBrow: te
1919
+ }, w(V[0] ?? null);
1932
1920
  }
1933
1921
  function B(k, P) {
1934
- m = {
1922
+ h = {
1935
1923
  kind: "idle",
1936
- nextBlinkAt: k + gt(r, n)
1924
+ nextBlinkAt: k + yt(r, n)
1937
1925
  }, c = P, w(b(d), P);
1938
1926
  }
1939
- function j(k, P, U) {
1940
- const O = U ? vi : Math.random() < a ? _i : Si;
1941
- m = {
1927
+ function G(k, P, N) {
1928
+ const I = N ? yi : Math.random() < a ? gi : _i;
1929
+ h = {
1942
1930
  kind: "playing",
1943
- paths: Ai(P, O),
1931
+ paths: Ti(P, I),
1944
1932
  index: 0,
1945
- holdUntil: k + Rt(),
1933
+ holdUntil: k + Dt(),
1946
1934
  after: "idle",
1947
1935
  blinkEmotion: P
1948
- }, c = P, w(m.paths[0] ?? null, P);
1936
+ }, c = P, w(h.paths[0] ?? null, P);
1949
1937
  }
1950
1938
  function C(k) {
1951
- if (m.kind === "browBlend") {
1952
- for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
1953
- m.index += 1, m.holdUntil = k + Rt();
1954
- const P = m.paths[m.index] ?? null;
1955
- 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 = {
1956
1944
  kind: "idle",
1957
1945
  nextBlinkAt: k + u
1958
1946
  });
1959
1947
  return;
1960
1948
  }
1961
- if (m.kind === "idle") {
1962
- w(b(d), c), k >= m.nextBlinkAt && j(k, c, !1);
1949
+ if (h.kind === "idle") {
1950
+ w(b(d), c), k >= h.nextBlinkAt && G(k, c, !1);
1963
1951
  return;
1964
1952
  }
1965
- if (m.kind === "doublePause") {
1966
- w(b(d), m.blinkEmotion), k >= m.resumeAt && j(k, m.blinkEmotion, !0);
1953
+ if (h.kind === "doublePause") {
1954
+ w(b(d), h.blinkEmotion), k >= h.resumeAt && G(k, h.blinkEmotion, !0);
1967
1955
  return;
1968
1956
  }
1969
- if (m.kind === "playing") {
1970
- for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
1971
- m.index += 1, m.holdUntil = k + Rt();
1972
- if (w(m.paths[m.index] ?? null, m.blinkEmotion), k >= m.holdUntil && m.index >= m.paths.length - 1) {
1973
- 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") {
1974
1962
  B(k + u, f);
1975
1963
  return;
1976
1964
  }
1977
- if (m.after === "doublePause") {
1978
- m = {
1965
+ if (h.after === "doublePause") {
1966
+ h = {
1979
1967
  kind: "doublePause",
1980
- resumeAt: k + gt(i, o),
1981
- blinkEmotion: m.blinkEmotion
1982
- }, w(b(d), m.blinkEmotion);
1968
+ resumeAt: k + yt(i, o),
1969
+ blinkEmotion: h.blinkEmotion
1970
+ }, w(b(d), h.blinkEmotion);
1983
1971
  return;
1984
1972
  }
1985
- if (m.after === "idle" && Math.random() < s) {
1986
- m = {
1973
+ if (h.after === "idle" && Math.random() < s) {
1974
+ h = {
1987
1975
  kind: "doublePause",
1988
- resumeAt: k + gt(i, o),
1989
- blinkEmotion: m.blinkEmotion
1990
- }, w(b(d), m.blinkEmotion);
1976
+ resumeAt: k + yt(i, o),
1977
+ blinkEmotion: h.blinkEmotion
1978
+ }, w(b(d), h.blinkEmotion);
1991
1979
  return;
1992
1980
  }
1993
- B(k, m.blinkEmotion);
1981
+ B(k, h.blinkEmotion);
1994
1982
  }
1995
1983
  }
1996
1984
  }
@@ -1999,28 +1987,28 @@ function Bi(e = {}) {
1999
1987
  setTargetEmotion(k) {
2000
1988
  const P = et(k, f);
2001
1989
  if (P === f) return;
2002
- const U = performance.now();
2003
- l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && U - S < l || (f = P, c = P, S = U);
1990
+ const N = performance.now();
1991
+ l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && N - S < l || (f = P, c = P, S = N);
2004
1992
  },
2005
1993
  setTargetEyebrow(k) {
2006
- const P = Ge(k);
1994
+ const P = Ke(k);
2007
1995
  if (P === d) return;
2008
- const U = performance.now(), O = m.kind === "browBlend" ? qr(I) ?? g : g;
2009
- d = P, !(P === O && m.kind !== "browBlend") && (m.kind === "playing" || m.kind === "doublePause" || L(U, O, 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));
2010
1998
  },
2011
1999
  getTargetEmotion: () => f,
2012
2000
  getTargetEyebrow: () => d,
2013
- getExpressionPath: () => I,
2001
+ getExpressionPath: () => M,
2014
2002
  getDrawKey: () => _,
2015
2003
  reset() {
2016
2004
  f = "neutral", c = "neutral", d = 0, g = 0, S = 0, B(
2017
- performance.now() + gt(r, n),
2005
+ performance.now() + yt(r, n),
2018
2006
  "neutral"
2019
2007
  );
2020
2008
  }
2021
2009
  };
2022
2010
  }
2023
- function Ci() {
2011
+ function Di() {
2024
2012
  const e = document.createElement("video");
2025
2013
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
2026
2014
  let t = !1, r = null, n = "";
@@ -2063,17 +2051,17 @@ function Ci() {
2063
2051
  }
2064
2052
  };
2065
2053
  }
2066
- const Fi = 50, Cn = 400;
2067
- function Li(e, t, r) {
2054
+ const Bi = 50, Bn = 400;
2055
+ function Ci(e, t, r) {
2068
2056
  return e.filter((n) => {
2069
2057
  const s = n.queueIndex ?? -1;
2070
2058
  return s >= t && s <= r;
2071
2059
  });
2072
2060
  }
2073
- function Oi(e, t) {
2061
+ function Fi(e, t) {
2074
2062
  const r = [];
2075
2063
  for (const n of e) {
2076
- const s = Li(
2064
+ const s = Ci(
2077
2065
  t,
2078
2066
  n.start_word,
2079
2067
  n.end_word
@@ -2082,30 +2070,30 @@ function Oi(e, t) {
2082
2070
  const i = s[0], o = s[s.length - 1];
2083
2071
  r.push({
2084
2072
  sentence: n,
2085
- startMs: Math.max(0, i.wtime - Fi),
2086
- endMs: o.wtime + o.wduration + Cn
2073
+ startMs: Math.max(0, i.wtime - Bi),
2074
+ endMs: o.wtime + o.wduration + Bn
2087
2075
  });
2088
2076
  }
2089
2077
  return r.sort((n, s) => n.startMs - s.startMs);
2090
2078
  }
2091
- function Ni(e, t, r, n = "neutral") {
2079
+ function Li(e, t, r, n = "neutral") {
2092
2080
  const s = et(n);
2093
2081
  if (t.length === 0) return s;
2094
2082
  if (r.length === 0 || e < r[0].wtime)
2095
2083
  return et(t[0]?.emotion, s);
2096
- const i = Oi(t, r);
2084
+ const i = Fi(t, r);
2097
2085
  let o = null;
2098
2086
  for (const l of i)
2099
2087
  e >= l.startMs && e <= l.endMs && (o = l);
2100
2088
  if (o)
2101
2089
  return et(o.sentence.emotion, s);
2102
2090
  const a = r[r.length - 1], u = a.wtime + a.wduration;
2103
- return e > u + Cn ? et(
2091
+ return e > u + Bn ? et(
2104
2092
  t[t.length - 1]?.emotion,
2105
2093
  s
2106
2094
  ) : s;
2107
2095
  }
2108
- function gr(e, t, r, n, s = In) {
2096
+ function yr(e, t, r, n, s = xn) {
2109
2097
  const i = new OffscreenCanvas(r, n), o = i.getContext("2d", { willReadFrequently: !0 });
2110
2098
  o.drawImage(e, 0, 0, r, n);
2111
2099
  const a = o.getImageData(0, 0, r, n), u = o.createImageData(r, n);
@@ -2115,44 +2103,44 @@ function gr(e, t, r, n, s = In) {
2115
2103
  f.clearRect(0, 0, r, n), f.drawImage(c, 0, 0, r, n);
2116
2104
  const d = f.getImageData(0, 0, r, n);
2117
2105
  for (let g = 0; g < u.data.length; g += 4) {
2118
- const S = d.data[g], m = d.data[g + 1], I = d.data[g + 2];
2119
- 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);
2120
2108
  }
2121
2109
  }
2122
2110
  return o.putImageData(u, 0, 0), i;
2123
2111
  }
2124
- let Ke = null, nt = null;
2125
- const Ft = /* @__PURE__ */ new Map();
2126
- function Ui() {
2127
- Ke = null, nt = null, Ft.clear();
2112
+ let qe = null, nt = null;
2113
+ const Lt = /* @__PURE__ */ new Map();
2114
+ function Oi() {
2115
+ qe = null, nt = null, Lt.clear();
2128
2116
  }
2129
- un(Ui);
2130
- function Vi(e) {
2117
+ cn(Oi);
2118
+ function Ni(e) {
2131
2119
  return e ?? nt ?? void 0;
2132
2120
  }
2133
- function yr(e) {
2121
+ function _r(e) {
2134
2122
  return new Promise((t, r) => {
2135
2123
  const n = new Image();
2136
2124
  n.decoding = "async", n.onload = () => t(n), n.onerror = () => r(new Error(`Failed to load image: ${e}`)), n.src = e;
2137
2125
  });
2138
2126
  }
2139
- async function Wi(e) {
2140
- return St() ? li(
2141
- await at(Ct(), e ?? "")
2142
- ) : yr(Ct());
2127
+ async function Ui(e) {
2128
+ return bt() ? ci(
2129
+ await at(Ft(), e ?? "")
2130
+ ) : _r(Ft());
2143
2131
  }
2144
- async function Kr(e, t, r, n) {
2145
- const s = r ? await xn(e, n) : await fetch(e).then((l) => {
2132
+ async function qr(e, t, r, n) {
2133
+ const s = r ? await Pn(e, n) : await fetch(e).then((l) => {
2146
2134
  if (!l.ok) throw new Error(`Failed to load ${e}`);
2147
2135
  return l.json();
2148
2136
  }), i = s.sheets?.[0];
2149
2137
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
2150
- const o = r ? await ci(
2138
+ const o = r ? await ai(
2151
2139
  await at(
2152
- Rn(t, i.path, r),
2140
+ Mn(t, i.path, r),
2153
2141
  n ?? ""
2154
2142
  )
2155
- ) : await yr(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
2143
+ ) : await _r(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
2156
2144
  for (const l of s.cells ?? [])
2157
2145
  l.path && a.set(l.path, l);
2158
2146
  const u = /* @__PURE__ */ new Map();
@@ -2160,30 +2148,30 @@ async function Kr(e, t, r, n) {
2160
2148
  u.set(l.index, l);
2161
2149
  return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: u, diffBase: t };
2162
2150
  }
2163
- async function rr(e) {
2164
- const t = Vi(e), r = St();
2151
+ async function nr(e) {
2152
+ const t = Ni(e), r = bt();
2165
2153
  if (r && !t)
2166
2154
  throw new Error("Encrypted assets enabled but no key provided");
2167
- if (Ke && (!r || nt === (t ?? null))) {
2168
- const i = await Ke;
2155
+ if (qe && (!r || nt === (t ?? null))) {
2156
+ const i = await qe;
2169
2157
  return {
2170
2158
  ...st(i),
2171
2159
  visemePaths: [...i.viseme.cellByPath.keys()]
2172
2160
  };
2173
2161
  }
2174
- nt = t ?? null, Ft.clear();
2175
- const n = ln();
2176
- Ke = (async () => {
2177
- const i = await Wi(t), o = await Kr(
2178
- fn(),
2162
+ nt = t ?? null, Lt.clear();
2163
+ const n = un();
2164
+ qe = (async () => {
2165
+ const i = await Ui(t), o = await qr(
2166
+ ln(),
2179
2167
  n,
2180
2168
  r,
2181
2169
  t
2182
2170
  );
2183
2171
  let a = null;
2184
2172
  try {
2185
- a = await Kr(
2186
- dn(),
2173
+ a = await qr(
2174
+ fn(),
2187
2175
  n,
2188
2176
  r,
2189
2177
  t
@@ -2193,59 +2181,59 @@ async function rr(e) {
2193
2181
  }
2194
2182
  return { sil: i, viseme: o, expression: a };
2195
2183
  })();
2196
- const s = await Ke;
2184
+ const s = await qe;
2197
2185
  return { ...st(s), visemePaths: [...s.viseme.cellByPath.keys()] };
2198
2186
  }
2199
- async function _r(e) {
2200
- if (await rr(e), !Ke) throw new Error("Assets not loaded");
2201
- return Ke;
2187
+ async function vr(e) {
2188
+ if (await nr(e), !qe) throw new Error("Assets not loaded");
2189
+ return qe;
2202
2190
  }
2203
2191
  function st(e) {
2204
- return En(
2192
+ return Tn(
2205
2193
  e.viseme.atlasMeta,
2206
2194
  e.sil.naturalWidth,
2207
2195
  e.sil.naturalHeight
2208
2196
  );
2209
2197
  }
2210
- function Hi(e, t) {
2198
+ function Vi(e, t) {
2211
2199
  const r = document.createElement("canvas");
2212
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;
2213
2201
  }
2214
- async function Lt(e, t, r) {
2215
- const n = `${t.diffBase}::${r}`, s = Ft.get(n);
2202
+ async function Ot(e, t, r) {
2203
+ const n = `${t.diffBase}::${r}`, s = Lt.get(n);
2216
2204
  if (s) return s;
2217
2205
  const i = (async () => {
2218
2206
  const o = t.cellByPath.get(r);
2219
2207
  if (!o) throw new Error(`No atlas cell for path: ${r}`);
2220
- const a = An(t.atlasMeta, o), u = st(e);
2221
- if (Pn(o)) {
2222
- const c = Hi(t, o), d = document.createElement("canvas");
2208
+ const a = En(t.atlasMeta, o), u = st(e);
2209
+ if (An(o)) {
2210
+ const c = Vi(t, o), d = document.createElement("canvas");
2223
2211
  d.width = u.width, d.height = u.height;
2224
2212
  const g = d.getContext("2d");
2225
2213
  return g.fillStyle = "#000", g.fillRect(0, 0, u.width, u.height), g.drawImage(c, a.x, a.y), d;
2226
2214
  }
2227
- const l = `${t.diffBase}/${r}`, f = await yr(l);
2215
+ const l = `${t.diffBase}/${r}`, f = await _r(l);
2228
2216
  if (f.naturalWidth === u.width && f.naturalHeight === u.height)
2229
2217
  return f;
2230
2218
  throw new Error(`Diff PNG wrong size for ${r}`);
2231
2219
  })();
2232
- return Ft.set(n, i), i;
2220
+ return Lt.set(n, i), i;
2233
2221
  }
2234
- async function Gr(e, t, r, n, s, i) {
2222
+ async function Kr(e, t, r, n, s, i) {
2235
2223
  if (s) {
2236
2224
  const { width: g, height: S } = s;
2237
2225
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
2238
2226
  return;
2239
- const m = document.createElement("canvas");
2240
- m.width = g, m.height = S;
2241
- const I = m.getContext("2d");
2242
- 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;
2243
2231
  (e.width !== g || e.height !== S) && (e.width = g, e.height = S);
2244
2232
  const _ = e.getContext("2d");
2245
- _.clearRect(0, 0, g, S), _.drawImage(m, 0, 0);
2233
+ _.clearRect(0, 0, g, S), _.drawImage(h, 0, 0);
2246
2234
  return;
2247
2235
  }
2248
- const o = await _r(), a = Vt(o.viseme.atlasMeta), { width: u, height: l } = st(o);
2236
+ const o = await vr(), a = Wt(o.viseme.atlasMeta), { width: u, height: l } = st(o);
2249
2237
  (e.width !== u || e.height !== l) && (e.width = u, e.height = l);
2250
2238
  const f = [], c = e.getContext("2d");
2251
2239
  if (c.clearRect(0, 0, u, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
@@ -2257,26 +2245,26 @@ async function Gr(e, t, r, n, s, i) {
2257
2245
  c.drawImage(t, 0, 0, u, l);
2258
2246
  return;
2259
2247
  }
2260
- const d = gr(t, f, u, l, a);
2248
+ const d = yr(t, f, u, l, a);
2261
2249
  c.drawImage(d, 0, 0);
2262
2250
  }
2263
- async function nr(e, t, r) {
2264
- const n = await _r(nt ?? void 0), s = Vt(n.viseme.atlasMeta), { width: i, height: o } = st(n);
2251
+ async function sr(e, t, r) {
2252
+ const n = await vr(nt ?? void 0), s = Wt(n.viseme.atlasMeta), { width: i, height: o } = st(n);
2265
2253
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
2266
2254
  const a = [];
2267
2255
  if (t.mouthPath) {
2268
- const f = new Set(n.viseme.cellByPath.keys()), c = mr(t.mouthPath, f) ?? (f.has(t.mouthPath) ? t.mouthPath : null);
2269
- c && a.push(await Lt(n, n.viseme, c));
2256
+ const f = new Set(n.viseme.cellByPath.keys()), c = hr(t.mouthPath, f) ?? (f.has(t.mouthPath) ? t.mouthPath : null);
2257
+ c && a.push(await Ot(n, n.viseme, c));
2270
2258
  }
2271
2259
  t.expressionPath && n.expression && a.push(
2272
- await Lt(n, n.expression, t.expressionPath)
2260
+ await Ot(n, n.expression, t.expressionPath)
2273
2261
  );
2274
2262
  const u = e.getContext("2d");
2275
2263
  if (u.clearRect(0, 0, i, o), a.length === 0) {
2276
2264
  u.drawImage(n.sil, 0, 0, i, o);
2277
2265
  return;
2278
2266
  }
2279
- const l = gr(
2267
+ const l = yr(
2280
2268
  n.sil,
2281
2269
  a,
2282
2270
  i,
@@ -2285,19 +2273,19 @@ async function nr(e, t, r) {
2285
2273
  );
2286
2274
  u.drawImage(l, 0, 0);
2287
2275
  }
2288
- async function $i(e, t) {
2289
- const r = await _r(nt ?? void 0), n = Vt(r.viseme.atlasMeta), { width: s, height: i } = st(r), o = [];
2276
+ async function Wi(e, t) {
2277
+ const r = await vr(nt ?? void 0), n = Wt(r.viseme.atlasMeta), { width: s, height: i } = st(r), o = [];
2290
2278
  if (e.mouthPath) {
2291
- const f = new Set(r.viseme.cellByPath.keys()), c = mr(e.mouthPath, f) ?? (f.has(e.mouthPath) ? e.mouthPath : null);
2292
- c && o.push(await Lt(r, r.viseme, c));
2279
+ const f = new Set(r.viseme.cellByPath.keys()), c = hr(e.mouthPath, f) ?? (f.has(e.mouthPath) ? e.mouthPath : null);
2280
+ c && o.push(await Ot(r, r.viseme, c));
2293
2281
  }
2294
2282
  e.expressionPath && r.expression && o.push(
2295
- await Lt(r, r.expression, e.expressionPath)
2283
+ await Ot(r, r.expression, e.expressionPath)
2296
2284
  );
2297
2285
  const a = new OffscreenCanvas(s, i), u = a.getContext("2d");
2298
2286
  if (o.length === 0)
2299
2287
  return u.drawImage(r.sil, 0, 0, s, i), a.transferToImageBitmap();
2300
- const l = gr(
2288
+ const l = yr(
2301
2289
  r.sil,
2302
2290
  o,
2303
2291
  s,
@@ -2306,20 +2294,20 @@ async function $i(e, t) {
2306
2294
  );
2307
2295
  return u.drawImage(l, 0, 0), a.transferToImageBitmap();
2308
2296
  }
2309
- async function qi(e) {
2310
- await nr(e, { mouthPath: null, expressionPath: null });
2297
+ async function Hi(e) {
2298
+ await sr(e, { mouthPath: null, expressionPath: null });
2311
2299
  }
2312
- let Fn = null;
2313
- function zr(e) {
2314
- Fn = e;
2300
+ let Cn = null;
2301
+ function Gr(e) {
2302
+ Cn = e;
2315
2303
  }
2316
- function We() {
2317
- return Fn;
2304
+ function Ne() {
2305
+ return Cn;
2318
2306
  }
2319
- function Ki(e) {
2307
+ function $i(e) {
2320
2308
  return `${e.from}→${e.to}@${e.fromVtime}`;
2321
2309
  }
2322
- function jr() {
2310
+ function zr() {
2323
2311
  return {
2324
2312
  rafTicksSpeaking: 0,
2325
2313
  rafTicksDeduped: 0,
@@ -2337,12 +2325,12 @@ function jr() {
2337
2325
  bufferPrefetched: 0
2338
2326
  };
2339
2327
  }
2340
- function Gi() {
2341
- let e = jr();
2328
+ function qi() {
2329
+ let e = zr();
2342
2330
  const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
2343
2331
  let s = "", i = -1, o = "";
2344
2332
  const a = () => {
2345
- e = jr(), t.clear(), r.clear(), n.clear(), s = "", i = -1, o = "";
2333
+ e = zr(), t.clear(), r.clear(), n.clear(), s = "", i = -1, o = "";
2346
2334
  }, u = (f) => {
2347
2335
  t.add(f);
2348
2336
  }, l = (f) => {
@@ -2366,7 +2354,7 @@ function Gi() {
2366
2354
  e.workerStale += 1;
2367
2355
  },
2368
2356
  onTransitionSample(f, c) {
2369
- const d = Ki(f);
2357
+ const d = $i(f);
2370
2358
  e.transitionFramesSampled += 1, d !== s && (s = d, i = -1, o !== d && (o = d, e.rifeFramesOmittedByGap += f.omittedByGap)), c && r.add(c), i >= 0 && f.frameIdx > i + 1 && (e.transitionFramesMissed += f.frameIdx - i - 1), i = f.frameIdx;
2371
2359
  },
2372
2360
  onBufferTick() {
@@ -2405,86 +2393,86 @@ function Gi() {
2405
2393
  },
2406
2394
  snapshot(f, c) {
2407
2395
  let d = 0, g = 0;
2408
- for (const R of f)
2409
- if (R.viseme !== "sil") {
2410
- if (R.vtime >= c) break;
2411
- 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);
2412
2400
  }
2413
- 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;
2414
2402
  return {
2415
2403
  ...e,
2416
2404
  bufferHitRate: _,
2417
- renderLoss: m,
2405
+ renderLoss: h,
2418
2406
  visemeSlotsTotal: d,
2419
2407
  visemeSlotsCovered: g,
2420
2408
  visemeCoveragePct: S,
2421
2409
  transitionFramesUniqueSampled: r.size,
2422
2410
  transitionFramesUniquePainted: n.size,
2423
2411
  drawsDeduped: e.rafTicksDeduped,
2424
- renderSkips: e.rafTicksDeduped + m,
2412
+ renderSkips: e.rafTicksDeduped + h,
2425
2413
  visemesShown: g,
2426
- visemesSkipped: I,
2414
+ visemesSkipped: M,
2427
2415
  rifeTransitionFramesSkipped: e.transitionFramesMissed
2428
2416
  };
2429
2417
  }
2430
2418
  };
2431
2419
  }
2432
- const Ln = ar, zi = 200, ji = 100, Yi = 600, On = "__sil__";
2433
- function Yr(e) {
2434
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === On : !1;
2420
+ const Fn = or, Ki = 200, Gi = 100, zi = 600, Ln = "__sil__";
2421
+ function jr(e) {
2422
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === Ln : !1;
2435
2423
  }
2436
- function vr() {
2424
+ function Sr() {
2437
2425
  return { lastDrawnKey: "" };
2438
2426
  }
2439
- function Pe(e) {
2427
+ function Ie(e) {
2440
2428
  e.lastDrawnKey = "", e.transitionCache = void 0;
2441
2429
  }
2442
- function Xi(e, t) {
2430
+ function ji(e, t) {
2443
2431
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
2444
2432
  return t.transitionCache.transitions;
2445
- const r = $s(e);
2433
+ const r = Hs(e);
2446
2434
  return t && (t.transitionCache = { queueLength: e.length, transitions: r }), r;
2447
2435
  }
2448
- function Ji(e, t) {
2436
+ function Yi(e, t) {
2449
2437
  let r = "sil";
2450
2438
  for (const n of e)
2451
2439
  n.viseme !== "sil" && (t != null && n.vtime > t || (r = n.viseme));
2452
2440
  return r;
2453
2441
  }
2454
- function Qi(e, t, r, n = 120) {
2442
+ function Xi(e, t, r, n = 120) {
2455
2443
  if (r !== "sil")
2456
2444
  return r;
2457
- const s = vn(e, t, n);
2458
- return s !== "sil" ? s : Ji(e, t);
2445
+ const s = _n(e, t, n);
2446
+ return s !== "sil" ? s : Yi(e, t);
2459
2447
  }
2460
- function Zi(e, t) {
2461
- return e === "sil" ? !1 : t ? hi(e, "sil", t) : hr(e, "sil").length > 0;
2448
+ function Ji(e, t) {
2449
+ return e === "sil" ? !1 : t ? di(e, "sil", t) : pr(e, "sil").length > 0;
2462
2450
  }
2463
- function ea() {
2464
- return Ln + Yi;
2451
+ function Qi() {
2452
+ return Fn + zi;
2465
2453
  }
2466
- function Ot(e) {
2467
- return e ?? On;
2454
+ function Nt(e) {
2455
+ return e ?? Ln;
2468
2456
  }
2469
- function Sr(e, t, r, n, s = ji) {
2457
+ function br(e, t, r, n, s = Gi) {
2470
2458
  if (e.length === 0)
2471
2459
  return { diffPath: null, label: "sil" };
2472
- if (t >= qe(e))
2460
+ if (t >= $e(e))
2473
2461
  return { diffPath: null, label: "sil" };
2474
- const i = Xi(e, n), o = qs(i, t);
2462
+ const i = ji(e, n), o = $s(i, t);
2475
2463
  if (o) {
2476
- const u = gn(
2464
+ const u = wn(
2477
2465
  o.fromVtime,
2478
2466
  o.toVtime,
2479
2467
  o.from,
2480
2468
  o.to
2481
2469
  );
2482
2470
  if (t >= u.transStart && t < u.transEnd) {
2483
- let l = hr(o.from, o.to);
2484
- r && (l = Mn(l, r));
2485
- const f = wi(l, u.effectiveGapMs);
2471
+ let l = pr(o.from, o.to);
2472
+ r && (l = In(l, r));
2473
+ const f = hi(l, u.effectiveGapMs);
2486
2474
  if (f.length > 0) {
2487
- const c = gi(
2475
+ const c = pi(
2488
2476
  t,
2489
2477
  u.transStart,
2490
2478
  u.transEnd,
@@ -2505,21 +2493,21 @@ function Sr(e, t, r, n, s = ji) {
2505
2493
  }
2506
2494
  };
2507
2495
  }
2508
- return { diffPath: _t(o.to), label: o.to };
2496
+ return { diffPath: vt(o.to), label: o.to };
2509
2497
  }
2510
2498
  }
2511
- const a = vn(e, t, s);
2512
- return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: _t(a), label: a };
2499
+ const a = _n(e, t, s);
2500
+ return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: vt(a), label: a };
2513
2501
  }
2514
- function br(e, t) {
2515
- const r = t ?? Ot(e.expressionPath);
2516
- return `${Ot(e.mouthPath)}|${r}`;
2502
+ function kr(e, t) {
2503
+ const r = t ?? Nt(e.expressionPath);
2504
+ return `${Nt(e.mouthPath)}|${r}`;
2517
2505
  }
2518
- function Xr(e, t, r, n, s, i, o, a, u, l) {
2519
- const f = Sr(t, r, u, i), c = {
2506
+ function Yr(e, t, r, n, s, i, o, a, u, l) {
2507
+ const f = br(t, r, u, i), c = {
2520
2508
  mouthPath: f.diffPath,
2521
2509
  expressionPath: n
2522
- }, d = br(c, s), g = We();
2510
+ }, d = kr(c, s), g = Ne();
2523
2511
  if (f.transitionMeta && g?.onTransitionSample(f.transitionMeta, f.diffPath), d === i.lastDrawnKey) {
2524
2512
  g?.onDrawDeduped();
2525
2513
  return;
@@ -2528,25 +2516,25 @@ function Xr(e, t, r, n, s, i, o, a, u, l) {
2528
2516
  S === d && (i.lastDrawnKey = d);
2529
2517
  });
2530
2518
  }
2531
- function Jr(e, t, r, n, s, i, o = null) {
2532
- const a = { mouthPath: null, expressionPath: t }, u = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = br(a, r) + u;
2519
+ function Xr(e, t, r, n, s, i, o = null) {
2520
+ const a = { mouthPath: null, expressionPath: t }, u = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = kr(a, r) + u;
2533
2521
  !(o != null) && l === n.lastDrawnKey || (i(
2534
2522
  o != null ? "idle" : "sil"
2535
2523
  ), s(e, a, l, (c) => {
2536
2524
  c === l && (n.lastDrawnKey = l);
2537
2525
  }));
2538
2526
  }
2539
- function Nn(e, t, r, n, s = yt, i) {
2527
+ function On(e, t, r, n, s = _t, i) {
2540
2528
  if (r <= t || e.length === 0) return [];
2541
- const o = i ?? vr(), a = [];
2529
+ const o = i ?? Sr(), a = [];
2542
2530
  let u = "";
2543
2531
  for (let l = t; l < r; l += s) {
2544
- const f = Sr(
2532
+ const f = br(
2545
2533
  e,
2546
2534
  l,
2547
2535
  n,
2548
2536
  o
2549
- ), c = Ot(f.diffPath);
2537
+ ), c = Nt(f.diffPath);
2550
2538
  c !== u && (u = c, a.push({
2551
2539
  displayAtMs: l,
2552
2540
  mouthPath: f.diffPath,
@@ -2556,8 +2544,8 @@ function Nn(e, t, r, n, s = yt, i) {
2556
2544
  }
2557
2545
  return a;
2558
2546
  }
2559
- const ta = 3;
2560
- function kr(e) {
2547
+ const Zi = 3;
2548
+ function Tr(e) {
2561
2549
  let t = 0;
2562
2550
  const r = [];
2563
2551
  let n = !1, s = !1;
@@ -2581,7 +2569,7 @@ function kr(e) {
2581
2569
  return {
2582
2570
  enqueue(a, u, l) {
2583
2571
  const f = r.findIndex((c) => c.drawKey === u);
2584
- f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= ta && (r.shift(), We()?.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();
2585
2573
  },
2586
2574
  reset() {
2587
2575
  t += 1, r.length = 0;
@@ -2594,7 +2582,7 @@ function kr(e) {
2594
2582
  }
2595
2583
  };
2596
2584
  }
2597
- function ra(e, t = 2) {
2585
+ function ea(e, t = 2) {
2598
2586
  const r = [], n = /* @__PURE__ */ new Set();
2599
2587
  let s = 0, i = !1, o = 0;
2600
2588
  const a = (l, f) => `${l}|${f}`, u = async () => {
@@ -2636,7 +2624,7 @@ function ra(e, t = 2) {
2636
2624
  }
2637
2625
  };
2638
2626
  }
2639
- function na() {
2627
+ function ta() {
2640
2628
  const e = /* @__PURE__ */ new Map(), t = (r) => {
2641
2629
  r.bitmap.close();
2642
2630
  };
@@ -2671,13 +2659,13 @@ function na() {
2671
2659
  }
2672
2660
  };
2673
2661
  }
2674
- function sa(e, t, r, n, s, i) {
2675
- const o = Nn(
2662
+ function ra(e, t, r, n, s, i) {
2663
+ const o = On(
2676
2664
  t,
2677
2665
  r,
2678
2666
  n,
2679
2667
  s,
2680
- yt,
2668
+ _t,
2681
2669
  i
2682
2670
  );
2683
2671
  if (o.length === 0) return { ready: 0, total: 0 };
@@ -2686,10 +2674,10 @@ function sa(e, t, r, n, s, i) {
2686
2674
  e.has(u.displayAtMs, u.mouthKey) && (a += 1);
2687
2675
  return { ready: a, total: o.length };
2688
2676
  }
2689
- function ia(e) {
2690
- const t = na(), r = vr(), n = /* @__PURE__ */ new Set();
2677
+ function na(e) {
2678
+ const t = ta(), r = Sr(), n = /* @__PURE__ */ new Set();
2691
2679
  let s = "", i = null;
2692
- const o = ra(
2680
+ const o = ea(
2693
2681
  async (c) => {
2694
2682
  try {
2695
2683
  if (!e.supportsBufferedPlayback) return;
@@ -2704,12 +2692,12 @@ function ia(e) {
2704
2692
  c.label,
2705
2693
  c.mouthPath,
2706
2694
  d
2707
- ), We()?.onBufferPrefetched();
2695
+ ), Ne()?.onBufferPrefetched();
2708
2696
  } finally {
2709
2697
  n.delete(c.mouthKey);
2710
2698
  }
2711
2699
  },
2712
- ls
2700
+ us
2713
2701
  ), a = (c) => {
2714
2702
  for (const d of c)
2715
2703
  t.has(d.displayAtMs, d.mouthKey) || n.has(d.mouthKey) || o.isQueuedOrInflight(0, d.mouthKey) || (n.add(d.mouthKey), o.enqueue({
@@ -2721,23 +2709,23 @@ function ia(e) {
2721
2709
  expressionPath: null
2722
2710
  }
2723
2711
  }));
2724
- }, u = (c, d, g, S = Gt) => {
2712
+ }, u = (c, d, g, S = zt) => {
2725
2713
  if (!e.supportsBufferedPlayback) return;
2726
- const m = Math.max(0, d - yt * 4), I = Nn(
2714
+ const h = Math.max(0, d - _t * 4), M = On(
2727
2715
  c,
2728
- m,
2716
+ h,
2729
2717
  d + S,
2730
2718
  g,
2731
- yt,
2719
+ _t,
2732
2720
  r
2733
2721
  );
2734
- a(I);
2722
+ a(M);
2735
2723
  }, l = (c, d) => {
2736
2724
  s = c, i = d;
2737
2725
  }, f = (c, d) => !(s !== c || i !== d);
2738
2726
  return {
2739
2727
  reset() {
2740
- t.reset(), o.reset(), n.clear(), Pe(r), s = "", i = null, We()?.onBufferReset();
2728
+ t.reset(), o.reset(), n.clear(), Ie(r), s = "", i = null, Ne()?.onBufferReset();
2741
2729
  },
2742
2730
  markExternallyDisplayed(c, d) {
2743
2731
  l(c.split("|")[0] ?? c, d);
@@ -2747,12 +2735,12 @@ function ia(e) {
2747
2735
  c.queue,
2748
2736
  0,
2749
2737
  c.availablePaths,
2750
- Math.max(Rr, Gt)
2738
+ Math.max(Rr, zt)
2751
2739
  );
2752
2740
  },
2753
2741
  isWarmupReady(c, d = Rr) {
2754
2742
  if (!e.supportsBufferedPlayback) return !0;
2755
- const { ready: g, total: S } = sa(
2743
+ const { ready: g, total: S } = ra(
2756
2744
  t,
2757
2745
  c.queue,
2758
2746
  0,
@@ -2760,40 +2748,40 @@ function ia(e) {
2760
2748
  c.availablePaths,
2761
2749
  r
2762
2750
  );
2763
- return S === 0 ? !1 : g / S >= us;
2751
+ return S === 0 ? !1 : g / S >= cs;
2764
2752
  },
2765
2753
  getBufferedFrameCount: () => t.size(),
2766
2754
  tick(c) {
2767
- const d = We();
2755
+ const d = Ne();
2768
2756
  d?.onBufferTick(), u(
2769
2757
  c.queue,
2770
2758
  c.elapsedMs,
2771
2759
  c.availablePaths
2772
- ), t.pruneBefore(c.elapsedMs - Gt);
2773
- const g = Sr(
2760
+ ), t.pruneBefore(c.elapsedMs - zt);
2761
+ const g = br(
2774
2762
  c.queue,
2775
2763
  c.elapsedMs,
2776
2764
  c.availablePaths,
2777
2765
  r
2778
- ), S = Ot(g.diffPath), m = br(
2766
+ ), S = Nt(g.diffPath), h = kr(
2779
2767
  { mouthPath: g.diffPath, expressionPath: c.expressionPath },
2780
2768
  c.expressionDrawKey
2781
- ), I = () => (l(S, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2782
- if (f(S, c.expressionPath) || c.playbackState.lastDrawnKey === m)
2783
- 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();
2784
2772
  const _ = t.findForMouthKey(
2785
2773
  S,
2786
2774
  c.elapsedMs,
2787
- yt
2775
+ _t
2788
2776
  );
2789
- 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({
2790
2778
  diffPath: _.mouthPath,
2791
2779
  label: _.label
2792
- }), 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 });
2793
2781
  }
2794
2782
  };
2795
2783
  }
2796
- const aa = `
2784
+ const sa = `
2797
2785
  in vec2 aPosition;
2798
2786
  out vec2 vTextureCoord;
2799
2787
 
@@ -2821,7 +2809,7 @@ void main(void)
2821
2809
  gl_Position = filterVertexPosition();
2822
2810
  vTextureCoord = filterTextureCoord();
2823
2811
  }
2824
- `, oa = `
2812
+ `, ia = `
2825
2813
  in vec2 vTextureCoord;
2826
2814
  out vec4 finalColor;
2827
2815
 
@@ -2836,11 +2824,11 @@ void main(void)
2836
2824
  finalColor = vec4(color.rgb, keep);
2837
2825
  }
2838
2826
  `;
2839
- function Qr(e = 5) {
2840
- const t = new Yn({
2841
- glProgram: Xn.from({
2842
- vertex: aa,
2843
- fragment: oa,
2827
+ function Jr(e = 5) {
2828
+ const t = new jn({
2829
+ glProgram: Yn.from({
2830
+ vertex: sa,
2831
+ fragment: ia,
2844
2832
  name: "threshold-key-filter"
2845
2833
  }),
2846
2834
  resources: {
@@ -2855,16 +2843,16 @@ function Qr(e = 5) {
2855
2843
  t.resources.thresholdUniforms.uniforms.uThreshold * 255
2856
2844
  ), t;
2857
2845
  }
2858
- function ca(e, t, r) {
2846
+ function aa(e, t, r) {
2859
2847
  return e > r || t > r;
2860
2848
  }
2861
- function ua(e) {
2849
+ function oa(e) {
2862
2850
  return e ? e.getParameter(e.MAX_TEXTURE_SIZE) : 4096;
2863
2851
  }
2864
- function la(e, t) {
2865
- return t != null && t > 0 ? Math.floor(t) : ua(e);
2852
+ function ca(e, t) {
2853
+ return t != null && t > 0 ? Math.floor(t) : oa(e);
2866
2854
  }
2867
- function fa(e, t) {
2855
+ function ua(e, t) {
2868
2856
  const r = document.createElement("canvas");
2869
2857
  r.width = t.w, r.height = t.h;
2870
2858
  const n = r.getContext("2d");
@@ -2872,28 +2860,28 @@ function fa(e, t) {
2872
2860
  throw new Error("Failed to acquire 2d context for atlas cell crop");
2873
2861
  return n.drawImage(e, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
2874
2862
  }
2875
- function Un(e) {
2863
+ function Nn(e) {
2876
2864
  return fetch(e).then((t) => {
2877
2865
  if (!t.ok) throw new Error(`Failed to load image: ${e}`);
2878
2866
  return t.blob();
2879
2867
  }).then((t) => createImageBitmap(t));
2880
2868
  }
2881
- async function Zr(e, t, r, n, s) {
2882
- const i = r ? await xn(e, s) : await fetch(e).then((c) => {
2869
+ async function Qr(e, t, r, n, s) {
2870
+ const i = r ? await Pn(e, s) : await fetch(e).then((c) => {
2883
2871
  if (!c.ok) throw new Error(`Failed to load ${e}`);
2884
2872
  return c.json();
2885
2873
  }), o = i.sheets?.[0];
2886
2874
  if (!o?.path) throw new Error(`${e} has no sheets[0].path`);
2887
2875
  const a = /* @__PURE__ */ new Map(), u = async (c, d) => {
2888
- const g = Rn(t, d, r), S = r ? await oi(
2876
+ const g = Mn(t, d, r), S = r ? await ii(
2889
2877
  await at(g, s ?? "")
2890
- ) : await Un(g);
2891
- if (ca(S.width, S.height, n))
2878
+ ) : await Nn(g);
2879
+ if (aa(S.width, S.height, n))
2892
2880
  return console.info(
2893
2881
  `[PixiVisemeCompositor] Sheet ${d} (${S.width}x${S.height}) exceeds MAX_TEXTURE_SIZE=${n}; using per-cell crops.`
2894
2882
  ), { mode: "cells", bitmap: S };
2895
- const m = we.from(S);
2896
- 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 };
2897
2885
  };
2898
2886
  a.set(o.index, await u(o.index, o.path));
2899
2887
  for (const c of i.sheets ?? [])
@@ -2912,8 +2900,8 @@ async function Zr(e, t, r, n, s) {
2912
2900
  sheets: a
2913
2901
  };
2914
2902
  }
2915
- async function da(e, t = {}) {
2916
- const r = new Jn();
2903
+ async function la(e, t = {}) {
2904
+ const r = new Xn();
2917
2905
  try {
2918
2906
  await r.init({
2919
2907
  canvas: e,
@@ -2931,9 +2919,9 @@ async function da(e, t = {}) {
2931
2919
  } catch (v) {
2932
2920
  throw r.destroy({ removeView: !1 }), v;
2933
2921
  }
2934
- if (r.renderer.type !== Qn.WEBGL)
2922
+ if (r.renderer.type !== Jn.WEBGL)
2935
2923
  throw r.destroy({ removeView: !1 }), new Error("Pixi did not initialize a WebGL renderer");
2936
- const n = la(
2924
+ const n = ca(
2937
2925
  r.renderer.gl,
2938
2926
  t.maxTextureSize
2939
2927
  );
@@ -2942,22 +2930,22 @@ async function da(e, t = {}) {
2942
2930
  s = !0, !i && !o && (i = !0, t.onWebGlContextLost?.());
2943
2931
  };
2944
2932
  a.addEventListener("webglcontextlost", u);
2945
- const l = new Pt(we.EMPTY), f = new Pt(we.EMPTY), c = new Pt(we.EMPTY), d = new Pt(we.EMPTY);
2933
+ const l = new xt(ge.EMPTY), f = new xt(ge.EMPTY), c = new xt(ge.EMPTY), d = new xt(ge.EMPTY);
2946
2934
  d.visible = !1;
2947
- const g = Qr(5), S = Qr(5);
2935
+ const g = Jr(5), S = Jr(5);
2948
2936
  f.filters = [g], c.filters = [S], r.stage.addChild(l), r.stage.addChild(f), r.stage.addChild(c), r.stage.addChild(d);
2949
- let m = null, I = null, _ = null, R = null, w = null, b = null, L = 842, B = 1264, j = null, C = 5;
2937
+ let h = null, M = null, _ = null, D = null, w = null, b = null, L = 842, B = 1264, G = null, C = 5;
2950
2938
  const k = /* @__PURE__ */ new Map();
2951
- let P = null, U = null, O = null;
2952
- const q = un(() => {
2953
- k.clear(), w = null, b = null, m = null, j = null;
2954
- }), fe = (v, E) => {
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) => {
2955
2943
  L = v, B = E, r.renderer.resize(v, E), (e.width !== v || e.height !== E) && (e.width = v, e.height = E);
2956
- }, D = () => {
2957
- f.visible = !1, c.visible = !1, f.texture = we.EMPTY, c.texture = we.EMPTY, P = null, U = null;
2958
- }, Y = () => {
2959
- d.visible = !1, m && (l.texture = m, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
2960
- }, Q = () => {
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 = () => {
2961
2949
  if (_) {
2962
2950
  try {
2963
2951
  _.resource = null;
@@ -2965,50 +2953,50 @@ async function da(e, t = {}) {
2965
2953
  }
2966
2954
  _.destroy(), _ = null;
2967
2955
  }
2968
- I && (I.destroy(!1), I = null), R = null;
2969
- }, de = (v, E) => {
2970
- const h = v.cellByPath.get(E);
2971
- if (!h || !Pn(h)) return null;
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;
2972
2960
  const T = `${v.diffBase}::${E}`;
2973
- let M = k.get(T);
2974
- if (!M) {
2975
- const F = h.sheet ?? 0, A = v.sheets.get(F);
2961
+ let R = k.get(T);
2962
+ if (!R) {
2963
+ const F = m.sheet ?? 0, A = v.sheets.get(F);
2976
2964
  if (!A) return null;
2977
- let W, J = !1;
2965
+ let $, Y = !1;
2978
2966
  if (A.mode === "full")
2979
- W = new we({
2967
+ $ = new ge({
2980
2968
  source: A.texture.source,
2981
- frame: new es(h.x, h.y, h.w, h.h)
2969
+ frame: new Zn(m.x, m.y, m.w, m.h)
2982
2970
  });
2983
2971
  else {
2984
- const Z = fa(A.bitmap, h);
2985
- W = we.from(Z), W.source.scaleMode = "nearest", J = !0;
2972
+ const Q = ua(A.bitmap, m);
2973
+ $ = ge.from(Q), $.source.scaleMode = "nearest", Y = !0;
2986
2974
  }
2987
- M = { texture: W, ownsSource: J }, k.set(T, M);
2975
+ R = { texture: $, ownsSource: Y }, k.set(T, R);
2988
2976
  }
2989
- return { texture: M.texture, cell: h };
2990
- }, ce = (v, E, h, T) => {
2991
- if (!T || !h)
2992
- return v.visible = !1, v.texture = we.EMPTY, !1;
2993
- const M = de(h, T);
2994
- if (!M)
2995
- return v.visible = !1, v.texture = we.EMPTY, !1;
2996
- const F = An(h.atlasMeta, M.cell);
2997
- return E.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;
2998
- }, ue = (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) => {
2999
2987
  if (!v || !w) return null;
3000
- const E = j ?? new Set(w.cellByPath.keys());
3001
- return mr(v, E) ?? (E.has(v) ? v : null);
3002
- }, se = (v) => {
3003
- d.visible = !1, Y();
3004
- const E = ue(v.mouthPath), h = v.expressionPath && b && b.cellByPath.has(v.expressionPath) ? v.expressionPath : null;
3005
- E !== P ? (ce(f, g, w, E), P = E) : E ? f.visible = !0 : f.visible = !1, h !== U ? (ce(
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(
3006
2994
  c,
3007
2995
  S,
3008
2996
  b,
3009
- h
3010
- ), U = h) : h ? c.visible = !0 : c.visible = !1;
3011
- }, me = () => {
2997
+ m
2998
+ ), N = m) : m ? c.visible = !0 : c.visible = !1;
2999
+ }, ue = () => {
3012
3000
  if (!(o || s || document.hidden))
3013
3001
  try {
3014
3002
  r.render();
@@ -3018,24 +3006,24 @@ async function da(e, t = {}) {
3018
3006
  return {
3019
3007
  async loadAssets(v) {
3020
3008
  if (o) return { width: L, height: B, visemePaths: [] };
3021
- const E = St();
3009
+ const E = bt();
3022
3010
  if (E && !v)
3023
3011
  throw new Error("Encrypted assets enabled but no key provided");
3024
- const h = E ? await ui(
3025
- await at(Ct(), v ?? "")
3026
- ) : await Un(Ct());
3027
- m && m.destroy(!0), m = we.from(h), m.source.scaleMode = "linear";
3028
- const T = ln();
3029
- w = await Zr(
3030
- fn(),
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();
3017
+ w = await Qr(
3018
+ ln(),
3031
3019
  T,
3032
3020
  E,
3033
3021
  n,
3034
3022
  v
3035
3023
  );
3036
3024
  try {
3037
- b = await Zr(
3038
- dn(),
3025
+ b = await Qr(
3026
+ fn(),
3039
3027
  T,
3040
3028
  E,
3041
3029
  n,
@@ -3044,49 +3032,49 @@ async function da(e, t = {}) {
3044
3032
  } catch {
3045
3033
  b = null;
3046
3034
  }
3047
- const M = En(
3035
+ const R = Tn(
3048
3036
  w.atlasMeta,
3049
- h.width,
3050
- h.height
3037
+ m.width,
3038
+ m.height
3051
3039
  );
3052
- return fe(M.width, M.height), C = Vt(w.atlasMeta), g.setThreshold(C), S.setThreshold(C), j = new Set(w.cellByPath.keys()), k.clear(), Y(), D(), me(), {
3053
- width: M.width,
3054
- 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,
3055
3043
  visemePaths: [...w.cellByPath.keys()]
3056
3044
  };
3057
3045
  },
3058
3046
  getVisemeAtlasPaths() {
3059
- return j;
3047
+ return G;
3060
3048
  },
3061
3049
  drawLiveFrame(v) {
3062
- o || s || !m || (se(v), me());
3050
+ o || s || !h || (de(v), ue());
3063
3051
  },
3064
3052
  drawIdleVideo(v, E) {
3065
- o || s || document.hidden || E && !E() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (D(), d.visible = !1, !I || R !== v ? (Q(), _ = new Zn({
3053
+ o || s || document.hidden || E && !E() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (J(), d.visible = !1, !M || D !== v ? (X(), _ = new Qn({
3066
3054
  resource: v,
3067
3055
  autoPlay: !1,
3068
3056
  updateFPS: 0
3069
- }), _.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, me());
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());
3070
3058
  },
3071
3059
  renderSilOnly() {
3072
- o || s || !m || (D(), Y(), me());
3060
+ o || s || !h || (J(), j(), ue());
3073
3061
  },
3074
3062
  blitBitmap(v) {
3075
- o || s || (D(), O && (O.destroy(!0), O = null), O = we.from(v), d.texture = O, d.visible = !0, d.x = 0, d.y = 0, d.width = L, d.height = B, l.visible = !1, me());
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());
3076
3064
  },
3077
3065
  async compositePrefetchFrame(v) {
3078
3066
  return null;
3079
3067
  },
3080
- renderFrame: me,
3068
+ renderFrame: ue,
3081
3069
  isContextLost() {
3082
3070
  return s;
3083
3071
  },
3084
3072
  dispose() {
3085
3073
  if (o) return;
3086
- o = !0, a.removeEventListener("webglcontextlost", u), q(), Q(), O && (O.destroy(!0), O = null);
3087
- for (const { texture: E, ownsSource: h } of k.values())
3088
- E.destroy(h);
3089
- k.clear(), m && (m.destroy(!0), m = null);
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);
3090
3078
  const v = (E) => {
3091
3079
  E.mode === "full" ? E.texture.destroy(!0) : E.bitmap.close();
3092
3080
  };
@@ -3103,9 +3091,9 @@ async function da(e, t = {}) {
3103
3091
  }
3104
3092
  };
3105
3093
  }
3106
- const en = -1, Dt = 1e5, tn = /* @__PURE__ */ new Map();
3107
- async function ma(e) {
3108
- let t = tn.get(e);
3094
+ const Zr = -1, Bt = 1e5, en = /* @__PURE__ */ new Map();
3095
+ async function fa(e) {
3096
+ let t = en.get(e);
3109
3097
  if (!t) {
3110
3098
  const r = await fetch(e);
3111
3099
  if (!r.ok)
@@ -3113,46 +3101,46 @@ async function ma(e) {
3113
3101
  `Failed to fetch worker script (${r.status}): ${e}`
3114
3102
  );
3115
3103
  const n = await r.blob();
3116
- t = URL.createObjectURL(n), tn.set(e, t);
3104
+ t = URL.createObjectURL(n), en.set(e, t);
3117
3105
  }
3118
3106
  return new Worker(t, { name: "visemeDiffPreview" });
3119
3107
  }
3120
- function ha() {
3108
+ function da() {
3121
3109
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
3122
3110
  }
3123
- function sr(e, t) {
3111
+ function ir(e, t) {
3124
3112
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
3125
3113
  const r = e.getContext("2d");
3126
3114
  r && r.drawImage(t, 0, 0);
3127
3115
  }
3128
- function rn(e, t) {
3116
+ function tn(e, t) {
3129
3117
  let r = 0, n = null;
3130
- const s = kr(async (i, o) => (await rr(), await nr(e, i), s.isLatestSeq(o)));
3118
+ const s = Tr(async (i, o) => (await nr(), await sr(e, i), s.isLatestSeq(o)));
3131
3119
  return {
3132
3120
  usesWorker: !1,
3133
3121
  usesPixi: !1,
3134
3122
  async loadAssets(i) {
3135
- const o = await rr(i);
3123
+ const o = await nr(i);
3136
3124
  return n = o.visemePaths ? new Set(o.visemePaths) : null, o;
3137
3125
  },
3138
3126
  getVisemeAtlasPaths() {
3139
3127
  return n;
3140
3128
  },
3141
3129
  async renderSilOnly() {
3142
- r += 1, s.reset(), await qi(e);
3130
+ r += 1, s.reset(), await Hi(e);
3143
3131
  },
3144
3132
  drawLiveFrame(i, o, a, u) {
3145
3133
  s.enqueue(o, a, u);
3146
3134
  },
3147
3135
  async compositePrefetchFrame(i, o) {
3148
3136
  try {
3149
- return await $i(i);
3137
+ return await Wi(i);
3150
3138
  } catch {
3151
3139
  return null;
3152
3140
  }
3153
3141
  },
3154
3142
  blitBitmap(i, o) {
3155
- sr(i, o);
3143
+ ir(i, o);
3156
3144
  },
3157
3145
  drawIdleVideo() {
3158
3146
  },
@@ -3160,8 +3148,8 @@ function rn(e, t) {
3160
3148
  async renderViseme(i, o) {
3161
3149
  r += 1;
3162
3150
  const a = r;
3163
- t.onStatus?.(o), await nr(i, {
3164
- mouthPath: _t(o),
3151
+ t.onStatus?.(o), await sr(i, {
3152
+ mouthPath: vt(o),
3165
3153
  expressionPath: null
3166
3154
  });
3167
3155
  },
@@ -3170,57 +3158,57 @@ function rn(e, t) {
3170
3158
  }
3171
3159
  };
3172
3160
  }
3173
- function pa(e, t, r) {
3161
+ function ma(e, t, r) {
3174
3162
  let n = null, s = 1, i = 0, o = !1, a = !1, u = null;
3175
3163
  const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
3176
- let c = Dt;
3177
- const d = kr(async (R, w, b) => (l.set(w, {
3164
+ let c = Bt;
3165
+ const d = Tr(async (D, w, b) => (l.set(w, {
3178
3166
  drawKey: b.drawKey,
3179
3167
  onDisplayed: b.onDisplayed
3180
- }), await I(
3168
+ }), await M(
3181
3169
  {
3182
3170
  type: "drawFrame",
3183
- diffPath: R.mouthPath,
3184
- expressionDiffPath: R.expressionPath,
3171
+ diffPath: D.mouthPath,
3172
+ expressionDiffPath: D.expressionPath,
3185
3173
  liveSeq: w
3186
3174
  },
3187
3175
  void 0,
3188
3176
  !0
3189
- ), !1)), g = (R) => {
3190
- if (R === en) {
3177
+ ), !1)), g = (D) => {
3178
+ if (D === Zr) {
3191
3179
  let L = -1, B;
3192
- for (const [j, C] of l)
3193
- j >= L && (L = j, B = C);
3180
+ for (const [G, C] of l)
3181
+ G >= L && (L = G, B = C);
3194
3182
  L >= 0 && l.delete(L), B?.onDisplayed?.(B.drawKey);
3195
3183
  return;
3196
3184
  }
3197
- const w = -R, b = l.get(w);
3185
+ const w = -D, b = l.get(w);
3198
3186
  l.delete(w), b?.onDisplayed?.(b.drawKey);
3199
- }, S = /* @__PURE__ */ new Map(), m = (R, w) => {
3200
- a || !n || n.postMessage(R, []);
3201
- }, 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) => {
3202
3190
  if (a) return Promise.resolve();
3203
3191
  const L = s++;
3204
- return new Promise((B, j) => {
3192
+ return new Promise((B, G) => {
3205
3193
  S.set(L, {
3206
3194
  resolve: (C) => B(C),
3207
- reject: j,
3208
- generation: typeof R.generation == "number" ? R.generation : void 0,
3195
+ reject: G,
3196
+ generation: typeof D.generation == "number" ? D.generation : void 0,
3209
3197
  expectRenderDone: b
3210
- }), m({ ...R, requestId: L });
3198
+ }), h({ ...D, requestId: L });
3211
3199
  });
3212
3200
  }, _ = (async () => {
3213
- n = await ma(r), n.onmessage = (R) => {
3201
+ n = await fa(r), n.onmessage = (D) => {
3214
3202
  if (a) return;
3215
- const w = R.data;
3203
+ const w = D.data;
3216
3204
  if (w.type === "status") {
3217
3205
  t.onStatus?.(w.label);
3218
3206
  return;
3219
3207
  }
3220
3208
  if (w.type === "frame") {
3221
- if (w.generation <= -Dt) {
3222
- const B = -w.generation, j = f.get(B);
3223
- f.delete(B), j?.resolve(w.bitmap);
3209
+ if (w.generation <= -Bt) {
3210
+ const B = -w.generation, G = f.get(B);
3211
+ f.delete(B), G?.resolve(w.bitmap);
3224
3212
  return;
3225
3213
  }
3226
3214
  const L = w.generation < 0;
@@ -3228,18 +3216,18 @@ function pa(e, t, r) {
3228
3216
  w.bitmap.close();
3229
3217
  return;
3230
3218
  }
3231
- if (L && !(w.generation === en)) {
3232
- const j = -w.generation;
3233
- if (!d.isLatestSeq(j)) {
3234
- We()?.onWorkerStale(), w.bitmap.close();
3219
+ if (L && !(w.generation === Zr)) {
3220
+ const G = -w.generation;
3221
+ if (!d.isLatestSeq(G)) {
3222
+ Ne()?.onWorkerStale(), w.bitmap.close();
3235
3223
  return;
3236
3224
  }
3237
3225
  }
3238
3226
  if (L && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
3239
- We()?.onWorkerStale(), w.bitmap.close();
3227
+ Ne()?.onWorkerStale(), w.bitmap.close();
3240
3228
  return;
3241
3229
  }
3242
- sr(e, w.bitmap), w.bitmap.close(), L && g(w.generation);
3230
+ ir(e, w.bitmap), w.bitmap.close(), L && g(w.generation);
3243
3231
  return;
3244
3232
  }
3245
3233
  const b = S.get(w.requestId);
@@ -3263,26 +3251,26 @@ function pa(e, t, r) {
3263
3251
  S.delete(w.requestId), t.onError?.(w.message), b.reject(new Error(w.message));
3264
3252
  break;
3265
3253
  }
3266
- }, n.onerror = (R) => {
3254
+ }, n.onerror = (D) => {
3267
3255
  if (a) return;
3268
- const w = R.message || "Worker error";
3256
+ const w = D.message || "Worker error";
3269
3257
  t.onError?.(w);
3270
3258
  for (const [, b] of S)
3271
3259
  b.reject(new Error(w));
3272
3260
  S.clear();
3273
- }, await I({ type: "init" }), o = !0;
3261
+ }, await M({ type: "init" }), o = !0;
3274
3262
  })();
3275
3263
  return {
3276
3264
  usesWorker: !0,
3277
3265
  usesPixi: !1,
3278
- async loadAssets(R) {
3266
+ async loadAssets(D) {
3279
3267
  if (a) return { width: 842, height: 1264 };
3280
3268
  if (await _, a) return { width: 842, height: 1264 };
3281
3269
  if (!o) throw new Error("Worker init failed");
3282
- return await I({
3270
+ return await M({
3283
3271
  type: "loadAssets",
3284
- keyHex: R,
3285
- urls: As(je())
3272
+ keyHex: D,
3273
+ urls: Es(ze())
3286
3274
  }) ?? { width: 842, height: 1264 };
3287
3275
  },
3288
3276
  getVisemeAtlasPaths() {
@@ -3290,29 +3278,29 @@ function pa(e, t, r) {
3290
3278
  },
3291
3279
  async renderSilOnly() {
3292
3280
  if (a || (await _, a)) return;
3293
- i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c = Dt;
3294
- const R = i;
3295
- await I({ type: "cancelLiveDraws" }), await I(
3296
- { 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 },
3297
3285
  void 0,
3298
3286
  !0
3299
3287
  );
3300
3288
  },
3301
- drawLiveFrame(R, w, b, L) {
3289
+ drawLiveFrame(D, w, b, L) {
3302
3290
  a || _.then(() => {
3303
3291
  a || d.enqueue(w, b, L);
3304
3292
  });
3305
3293
  },
3306
- compositePrefetchFrame(R, w) {
3294
+ compositePrefetchFrame(D, w) {
3307
3295
  return a ? Promise.resolve(null) : _.then(() => {
3308
3296
  if (a) return null;
3309
3297
  const b = ++c;
3310
3298
  return new Promise((L) => {
3311
- f.set(b, { resolve: L }), I(
3299
+ f.set(b, { resolve: L }), M(
3312
3300
  {
3313
3301
  type: "drawFrame",
3314
- diffPath: R.mouthPath,
3315
- expressionDiffPath: R.expressionPath,
3302
+ diffPath: D.mouthPath,
3303
+ expressionDiffPath: D.expressionPath,
3316
3304
  liveSeq: b
3317
3305
  },
3318
3306
  void 0,
@@ -3323,18 +3311,18 @@ function pa(e, t, r) {
3323
3311
  });
3324
3312
  });
3325
3313
  },
3326
- blitBitmap(R, w) {
3327
- sr(R, w);
3314
+ blitBitmap(D, w) {
3315
+ ir(D, w);
3328
3316
  },
3329
3317
  drawIdleVideo() {
3330
3318
  },
3331
3319
  supportsBufferedPlayback: !0,
3332
- async renderViseme(R, w, b = {}) {
3320
+ async renderViseme(D, w, b = {}) {
3333
3321
  if (a || (await _, a)) return;
3334
3322
  i += 1, d.reset(), l.clear();
3335
3323
  const L = i;
3336
3324
  try {
3337
- await I({ type: "cancelLiveDraws" }), await I(
3325
+ await M({ type: "cancelLiveDraws" }), await M(
3338
3326
  {
3339
3327
  type: "renderViseme",
3340
3328
  generation: L,
@@ -3354,21 +3342,21 @@ function pa(e, t, r) {
3354
3342
  },
3355
3343
  dispose() {
3356
3344
  if (!a) {
3357
- a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: R }) => R(null)), f.clear(), c = Dt;
3358
- for (const [, R] of S)
3359
- 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();
3360
3348
  S.clear(), n?.terminate(), n = null;
3361
3349
  }
3362
3350
  }
3363
3351
  };
3364
3352
  }
3365
- async function wa(e, t) {
3366
- const r = await da(e, {
3353
+ async function ha(e, t) {
3354
+ const r = await la(e, {
3367
3355
  onWebGlContextLost: t.onWebGlContextLost,
3368
3356
  maxTextureSize: t.pixiMaxTextureSize
3369
3357
  });
3370
3358
  let n = 0, s = null, i = !1;
3371
- const o = kr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (We()?.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)));
3372
3360
  return {
3373
3361
  usesWorker: !1,
3374
3362
  usesPixi: !0,
@@ -3408,7 +3396,7 @@ async function wa(e, t) {
3408
3396
  n += 1;
3409
3397
  const l = n;
3410
3398
  o.reset(), t.onStatus?.(u), r.drawLiveFrame({
3411
- mouthPath: _t(u),
3399
+ mouthPath: vt(u),
3412
3400
  expressionPath: null
3413
3401
  });
3414
3402
  },
@@ -3417,23 +3405,23 @@ async function wa(e, t) {
3417
3405
  }
3418
3406
  };
3419
3407
  }
3420
- function nn(e, t) {
3421
- if (!ha())
3422
- return rn(e, t);
3423
- const r = as(t.workerScriptUrl);
3408
+ function rn(e, t) {
3409
+ if (!da())
3410
+ return tn(e, t);
3411
+ const r = is(t.workerScriptUrl);
3424
3412
  try {
3425
- return pa(e, t, r);
3413
+ return ma(e, t, r);
3426
3414
  } catch {
3427
- return rn(e, t);
3415
+ return tn(e, t);
3428
3416
  }
3429
3417
  }
3430
- function ga(e, t = {}) {
3418
+ function pa(e, t = {}) {
3431
3419
  if (t.preferLegacyRenderer)
3432
- return nn(e, t);
3420
+ return rn(e, t);
3433
3421
  let r = null, n = !1, s = null, i = !1;
3434
3422
  const o = () => r ? Promise.resolve(r) : (s || (s = (async () => {
3435
3423
  try {
3436
- const a = await wa(e, t);
3424
+ const a = await ha(e, t);
3437
3425
  if (i)
3438
3426
  throw a.dispose(), new Error("Renderer disposed during Pixi init");
3439
3427
  return n = !0, r = a, a;
@@ -3443,7 +3431,7 @@ function ga(e, t = {}) {
3443
3431
  return console.warn(
3444
3432
  "[AiTwin] Pixi WebGL renderer unavailable, using Canvas2D fallback:",
3445
3433
  a
3446
- ), r = nn(e, t), n = !1, r;
3434
+ ), r = rn(e, t), n = !1, r;
3447
3435
  }
3448
3436
  })()), s);
3449
3437
  return {
@@ -3487,15 +3475,15 @@ function ga(e, t = {}) {
3487
3475
  }
3488
3476
  };
3489
3477
  }
3490
- class ya extends Error {
3478
+ class wa extends Error {
3491
3479
  constructor(t, r) {
3492
3480
  super(`${t} timed out after ${Math.round(r / 1e3)}s`), this.name = "LoadTimeoutError";
3493
3481
  }
3494
3482
  }
3495
- function Xt(e, t, r) {
3483
+ function Jt(e, t, r) {
3496
3484
  return new Promise((n, s) => {
3497
3485
  const i = globalThis.setTimeout(() => {
3498
- s(new ya(r, t));
3486
+ s(new wa(r, t));
3499
3487
  }, t);
3500
3488
  e.then(
3501
3489
  (o) => {
@@ -3507,15 +3495,15 @@ function Xt(e, t, r) {
3507
3495
  );
3508
3496
  });
3509
3497
  }
3510
- const _a = {
3498
+ const ga = {
3511
3499
  position: "relative",
3512
3500
  display: "inline-block",
3513
3501
  lineHeight: 0
3514
- }, va = {
3502
+ }, ya = {
3515
3503
  display: "block",
3516
3504
  maxWidth: "100%",
3517
3505
  height: "auto"
3518
- }, Sa = {
3506
+ }, _a = {
3519
3507
  position: "absolute",
3520
3508
  inset: 0,
3521
3509
  display: "flex",
@@ -3527,13 +3515,13 @@ const _a = {
3527
3515
  fontSize: "0.875rem",
3528
3516
  textAlign: "center"
3529
3517
  };
3530
- function wt(e) {
3531
- return ds(e) ? bn : Sn;
3518
+ function gt(e) {
3519
+ return fs(e) ? Sn : vn;
3532
3520
  }
3533
3521
  function Le(e, t) {
3534
3522
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
3535
3523
  }
3536
- const Da = $n(function({
3524
+ const Ma = Hn(function({
3537
3525
  id: t,
3538
3526
  avatarId: r,
3539
3527
  faceId: n,
@@ -3542,645 +3530,645 @@ const Da = $n(function({
3542
3530
  apiBase: o,
3543
3531
  ttsEngineId: a = tt,
3544
3532
  voiceId: u,
3545
- speakingRate: l = Ut,
3533
+ speakingRate: l = Vt,
3546
3534
  className: f,
3547
3535
  style: c,
3548
3536
  canvasStyle: d,
3549
3537
  onStatusChange: g,
3550
3538
  onDisplayStatus: S,
3551
- onError: m,
3552
- onReady: I,
3539
+ onError: h,
3540
+ onReady: M,
3553
3541
  showErrorOverlay: _ = !0,
3554
- onUserTranscript: R,
3542
+ onUserTranscript: D,
3555
3543
  onBotOutput: w,
3556
3544
  onRealtimeLipsyncDebug: b,
3557
3545
  onFrameRenderStats: L,
3558
3546
  lipsyncBufferedPlayback: B = !0,
3559
- lipsyncPlaybackWarmupMs: j = 1500,
3547
+ lipsyncPlaybackWarmupMs: G = 1500,
3560
3548
  pixiMaxTextureSize: C
3561
3549
  }, k) {
3562
- const P = $(null), U = $(null), O = $(null), q = $(B);
3563
- q.current = B;
3564
- const fe = $(j);
3565
- fe.current = j;
3566
- const D = $(0), Y = $(vr()), Q = $(Bi()), de = $(0), ce = $(0), ue = $(0), se = $(null), me = $(null), v = $(!1), E = $(!1), h = $(!1), T = $("sil"), M = $(0), F = $(!1), A = $(
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(
3567
3555
  null
3568
- ), W = $(!1), [J, Z] = Ze("idle"), [ee, Se] = Ze(null), [ye, Be] = Ze(!1), [ot, xe] = Ze(!1), [Wt, Tr] = Ze({ width: 842, height: 1264 }), [p, x] = Ze(0), G = $(!1), X = $(i ?? null), oe = o?.trim() || vt, Ce = $(null), te = $(null), be = $(!1), Ie = $({ width: 842, height: 1264 }), Oe = $(null), ct = $("sil"), Me = $(void 0), Ye = $(/* @__PURE__ */ new Map()), bt = $(I), le = $(S), Ne = $(m), ut = $(R), lt = $(w), Ue = $(b), he = $(L), pe = $(Gi());
3569
- bt.current = I, le.current = S, Ne.current = m, ut.current = R, lt.current = w, Ue.current = b, he.current = L, $e(() => {
3570
- const y = pe.current;
3571
- return zr(y), () => zr(null);
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;
3559
+ return Gr(y), () => Gr(null);
3572
3560
  }, []);
3573
- const ke = Ae(
3561
+ const Ye = xe(
3574
3562
  (y) => {
3575
- const N = y?.ttsEngineId ?? a ?? te.current?.ttsEngineId ?? tt, H = y?.voiceId ?? u ?? te.current?.voiceId ?? wt(N);
3576
- return { ttsEngineId: N, voiceId: H };
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 };
3577
3565
  },
3578
3566
  [a, u]
3579
- ), _e = Ae((y) => {
3580
- Se(y), Ne.current?.(y);
3581
- }, []), Ve = Ae(
3567
+ ), Ee = xe((y) => {
3568
+ be(y), lt.current?.(y);
3569
+ }, []), Ve = xe(
3582
3570
  (y) => {
3583
- Z(y), g?.(y);
3571
+ Q(y), g?.(y);
3584
3572
  },
3585
3573
  [g]
3586
- ), re = $(
3587
- Or(Ve, oe, {
3588
- onLipsyncDebug: (y) => Ue.current?.(y)
3574
+ ), ee = H(
3575
+ Or(Ve, Te, {
3576
+ onLipsyncDebug: (y) => le.current?.(y)
3589
3577
  })
3590
- ), ne = $(null);
3591
- $e(() => (re.current = Or(
3578
+ ), ae = H(null);
3579
+ He(() => (ee.current = Or(
3592
3580
  Ve,
3593
- oe,
3581
+ Te,
3594
3582
  {
3595
- onLipsyncDebug: (y) => Ue.current?.(y)
3583
+ onLipsyncDebug: (y) => le.current?.(y)
3596
3584
  }
3597
- ), i && re.current.setDeveloperToken(i), re.current.setTtsEngineId(a), () => {
3598
- re.current.stop();
3599
- const y = ne.current;
3600
- y && (y.disconnect(), ne.current = null);
3601
- }), [Ve, i, a, oe]);
3602
- const Er = Ae(() => (ne.current || (ne.current = ai(
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(
3603
3591
  Ve,
3604
3592
  {
3605
3593
  speakingRate: l,
3606
- onUserTranscript: (y, N) => ut.current?.(y, N),
3607
- onBotOutput: (y) => lt.current?.(y),
3608
- onLipsyncDebug: (y) => Ue.current?.(y)
3594
+ onUserTranscript: (y, O) => ft.current?.(y, O),
3595
+ onBotOutput: (y) => je.current?.(y),
3596
+ onLipsyncDebug: (y) => le.current?.(y)
3609
3597
  }
3610
- ), ne.current.setTtsEngineId(a)), ne.current), [Ve, l, a]), Te = Ae(() => {
3611
- se.current != null && (clearTimeout(se.current), se.current = null);
3612
- }, []), Fe = Ae(() => {
3613
- me.current != null && (clearTimeout(me.current), me.current = null), h.current = !1;
3614
- }, []), Ar = Ae(() => {
3615
- !W.current || !A.current || (Fe(), h.current = !0, me.current = setTimeout(() => {
3616
- if (me.current = null, Le(
3617
- re.current,
3618
- ne.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
3619
3607
  ).isSpeaking()) {
3620
- h.current = !1;
3608
+ m.current = !1;
3621
3609
  return;
3622
3610
  }
3623
3611
  if (v.current) {
3624
- h.current = !1;
3612
+ m.current = !1;
3625
3613
  return;
3626
3614
  }
3627
3615
  const y = A.current;
3628
3616
  if (!y) {
3629
- h.current = !1;
3617
+ m.current = !1;
3630
3618
  return;
3631
3619
  }
3632
3620
  y.restart(), y.setActive(!0);
3633
- const N = y.getVideo();
3634
- let H = !1;
3635
- const z = () => {
3636
- H || (H = !0, N.removeEventListener("playing", K), h.current = !1);
3637
- }, K = () => {
3638
- z();
3621
+ const O = y.getVideo();
3622
+ let W = !1;
3623
+ const K = () => {
3624
+ W || (W = !0, O.removeEventListener("playing", q), m.current = !1);
3625
+ }, q = () => {
3626
+ K();
3639
3627
  };
3640
- if (N.addEventListener("playing", K, { once: !0 }), N.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !N.paused) {
3641
- z();
3628
+ if (O.addEventListener("playing", q, { once: !0 }), O.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !O.paused) {
3629
+ K();
3642
3630
  return;
3643
3631
  }
3644
- setTimeout(z, 300);
3645
- }, zi));
3646
- }, [Fe]), Xe = Ae(() => {
3647
- if (Te(), le.current?.("sil"), v.current = !1, !W.current || !A.current) {
3648
- h.current = !1;
3632
+ setTimeout(K, 300);
3633
+ }, Ki));
3634
+ }, [Fe]), Xe = xe(() => {
3635
+ if (Ae(), ie.current?.("sil"), v.current = !1, !$.current || !A.current) {
3636
+ m.current = !1;
3649
3637
  return;
3650
3638
  }
3651
3639
  Ar();
3652
- }, [Te, Ar]), Ht = Ae(
3640
+ }, [Ae, Ar]), $t = xe(
3653
3641
  async (y) => {
3654
- const N = ce.current, H = U.current, z = P.current, K = () => {
3642
+ const O = re.current, W = N.current, K = P.current, q = () => {
3655
3643
  y?.fallbackOnly || (v.current = !1);
3656
3644
  };
3657
- if (!H || !z || !ye) {
3658
- K();
3645
+ if (!W || !K || !ke) {
3646
+ q();
3659
3647
  return;
3660
3648
  }
3661
3649
  if (Le(
3662
- re.current,
3663
- ne.current
3650
+ ee.current,
3651
+ ae.current
3664
3652
  ).isSpeaking()) {
3665
- K();
3653
+ q();
3666
3654
  return;
3667
3655
  }
3668
3656
  if (y?.fallbackOnly) {
3669
- if (!v.current || (Pe(Y.current), await H.renderSilOnly(), N !== ce.current) || Le(
3670
- re.current,
3671
- ne.current
3657
+ if (!v.current || (Ie(j.current), await W.renderSilOnly(), O !== re.current) || Le(
3658
+ ee.current,
3659
+ ae.current
3672
3660
  ).isSpeaking())
3673
3661
  return;
3674
3662
  Xe();
3675
3663
  return;
3676
3664
  }
3677
- if (Yr(Y.current)) {
3678
- Pe(Y.current), Xe();
3665
+ if (jr(j.current)) {
3666
+ Ie(j.current), Xe();
3679
3667
  return;
3680
3668
  }
3681
- if (q.current && H.supportsBufferedPlayback && !y?.fallbackOnly) {
3682
- if (Pe(Y.current), O.current?.reset(), await H.renderSilOnly(), N !== ce.current || Le(
3683
- re.current,
3684
- ne.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
3685
3673
  ).isSpeaking())
3686
3674
  return;
3687
3675
  Xe();
3688
3676
  return;
3689
3677
  }
3690
- const Ee = Qi(
3678
+ const Pe = Xi(
3691
3679
  Le(
3692
- re.current,
3693
- ne.current
3680
+ ee.current,
3681
+ ae.current
3694
3682
  ).getVisemeQueue(),
3695
- M.current,
3683
+ R.current,
3696
3684
  T.current
3697
- ), dt = Zi(
3698
- Ee,
3699
- Oe.current
3685
+ ), mt = Ji(
3686
+ Pe,
3687
+ Ce.current
3700
3688
  );
3701
- if (Pe(Y.current), !dt) {
3702
- if (await H.renderSilOnly(), N !== ce.current || Le(
3703
- re.current,
3704
- ne.current
3689
+ if (Ie(j.current), !mt) {
3690
+ if (await W.renderSilOnly(), O !== re.current || Le(
3691
+ ee.current,
3692
+ ae.current
3705
3693
  ).isSpeaking())
3706
3694
  return;
3707
3695
  Xe();
3708
3696
  return;
3709
3697
  }
3710
3698
  try {
3711
- await H.renderViseme(z, "sil", {
3712
- from: Ee,
3713
- transitionDurationMs: Ln
3699
+ await W.renderViseme(K, "sil", {
3700
+ from: Pe,
3701
+ transitionDurationMs: Fn
3714
3702
  });
3715
3703
  } catch (Je) {
3716
3704
  if (Je?.name !== "AbortError")
3717
3705
  throw Je;
3718
3706
  }
3719
- if (N !== ce.current) {
3720
- K();
3707
+ if (O !== re.current) {
3708
+ q();
3721
3709
  return;
3722
3710
  }
3723
3711
  if (Le(
3724
- re.current,
3725
- ne.current
3712
+ ee.current,
3713
+ ae.current
3726
3714
  ).isSpeaking()) {
3727
- K();
3715
+ q();
3728
3716
  return;
3729
3717
  }
3730
3718
  Xe();
3731
3719
  },
3732
- [ye, Xe]
3733
- ), ft = Ae(() => {
3720
+ [ke, Xe]
3721
+ ), dt = xe(() => {
3734
3722
  if (E.current || v.current) return;
3735
- E.current = !0, v.current = !0, Te();
3736
- const y = ce.current;
3737
- Ht().finally(() => {
3723
+ E.current = !0, v.current = !0, Ae();
3724
+ const y = re.current;
3725
+ $t().finally(() => {
3738
3726
  E.current = !1;
3739
- }), se.current = setTimeout(() => {
3740
- se.current = null, y === ce.current && Ht({ fallbackOnly: !0 });
3741
- }, ea());
3742
- }, [Te, Ht]), Pr = Ae(async () => {
3727
+ }), de.current = setTimeout(() => {
3728
+ de.current = null, y === re.current && $t({ fallbackOnly: !0 });
3729
+ }, Qi());
3730
+ }, [Ae, $t]), Pr = xe(async () => {
3743
3731
  const y = Math.floor(Date.now() / 1e3);
3744
- if (Ce.current && y < Ce.current.expiresAt - 60)
3745
- return Ce.current.key;
3746
- const N = X.current ?? await zt();
3747
- X.current = N, re.current.setDeveloperToken(N);
3748
- const H = await vs(N, oe);
3749
- return Ce.current = {
3750
- key: H.value,
3751
- expiresAt: H.expiresAt
3752
- }, H.value;
3753
- }, [oe]);
3754
- $e(() => {
3755
- i && (X.current = i, re.current.setDeveloperToken(i));
3756
- }, [i]), $e(() => {
3757
- re.current.setTtsEngineId(a), ne.current?.setTtsEngineId(a), te.current && (te.current.ttsEngineId = a);
3758
- }, [a]), $e(() => {
3759
- const y = u ?? wt(a);
3760
- te.current && (te.current.voiceId = y);
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 = {
3738
+ key: W.value,
3739
+ expiresAt: W.expiresAt
3740
+ }, W.value;
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);
3761
3749
  }, [u, a]);
3762
- const He = Mr(
3763
- () => Ts(r, n),
3750
+ const We = Mr(
3751
+ () => ks(r, n),
3764
3752
  [r, n]
3765
- ), Vn = Mr(() => s ? JSON.stringify(s) : He ? `face:${He}` : `id:${t ?? ""}`, [s, He, t]);
3766
- return $e(() => {
3767
- if (!t && !s && !He) {
3768
- _e("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`");
3769
3757
  return;
3770
3758
  }
3771
3759
  let y = !1;
3772
- be.current = !1, Be(!1), xe(!1), Se(null), te.current = null, A.current = null, W.current = !1;
3773
- const N = P.current;
3774
- if (!N) return;
3775
- let H = null;
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;
3763
+ let W = null;
3776
3764
  return (async () => {
3777
3765
  try {
3778
- let z, K, ve, Ee;
3766
+ let K, q, Se, Pe;
3779
3767
  if (s)
3780
- z = s, K = a, ve = u ?? wt(K);
3781
- else if (He)
3782
- le.current?.("loadFace"), z = Br(He), K = a, ve = u ?? wt(K);
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);
3783
3771
  else {
3784
- le.current?.("getAiTwin");
3785
- const V = await Xt(
3786
- hs(t),
3772
+ ie.current?.("getAiTwin");
3773
+ const U = await Jt(
3774
+ ms(t),
3787
3775
  3e4,
3788
3776
  "getAiTwin"
3789
3777
  );
3790
3778
  if (y) return;
3791
- if (!V.faceId?.trim())
3779
+ if (!U.faceId?.trim())
3792
3780
  throw new Error("getAiTwin returned no faceId");
3793
- K = V.ttsEngineId, ve = u ?? V.voiceId ?? wt(K), Ee = V.knowledgeContextId?.trim() || void 0, z = Br(V.faceId);
3781
+ q = U.ttsEngineId, Se = u ?? U.voiceId ?? gt(q), Pe = U.knowledgeContextId?.trim() || void 0, K = Br(U.faceId);
3794
3782
  }
3795
- te.current = { ttsEngineId: K, voiceId: ve, personaId: Ee }, Es(z), A.current = Ci();
3796
- const dt = !!(s && !ze(s));
3797
- H = ga(N, {
3798
- preferLegacyRenderer: dt,
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,
3799
3787
  pixiMaxTextureSize: C,
3800
- onStatus: (V) => {
3801
- y || le.current?.(V);
3788
+ onStatus: (U) => {
3789
+ y || ie.current?.(U);
3802
3790
  },
3803
- onError: (V) => {
3804
- y || _e(V);
3791
+ onError: (U) => {
3792
+ y || Ee(U);
3805
3793
  },
3806
3794
  shouldAcceptLiveFrame: () => {
3807
- const V = Le(
3808
- re.current,
3809
- ne.current
3795
+ const U = Le(
3796
+ ee.current,
3797
+ ae.current
3810
3798
  );
3811
- return (V.isSpeaking() || V.isWarmingUp()) && !v.current;
3799
+ return (U.isSpeaking() || U.isWarmingUp()) && !v.current;
3812
3800
  },
3813
3801
  onWebGlContextLost: () => {
3814
- y || G.current || (G.current = !0, queueMicrotask(() => {
3815
- y || x((V) => V + 1);
3802
+ y || ne.current || (ne.current = !0, queueMicrotask(() => {
3803
+ y || z((U) => U + 1);
3816
3804
  }));
3817
3805
  }
3818
- }), U.current = H, O.current = ia(H), G.current = !1, ((V) => {
3819
- const ae = () => {
3820
- if (!V || fe.current <= 0)
3806
+ }), N.current = W, I.current = na(W), ne.current = !1, ((U) => {
3807
+ const oe = () => {
3808
+ if (!U || V.current <= 0)
3821
3809
  return !1;
3822
- const ge = U.current;
3823
- return ge ? q.current && ge.supportsBufferedPlayback ? !0 : ge.usesPixi : !1;
3810
+ const ye = N.current;
3811
+ return ye ? te.current && ye.supportsBufferedPlayback ? !0 : ye.usesPixi : !1;
3824
3812
  };
3825
- re.current.setLipsyncWarmupHold(V, ae), ne.current?.setLipsyncWarmupHold(V, ae);
3826
- })(!0), le.current?.("auth");
3827
- const mt = X.current ?? i ?? await Xt(zt(), 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");
3828
3816
  if (y) return;
3829
- X.current = mt, re.current.setDeveloperToken(mt), re.current.setTtsEngineId(K);
3830
- const kt = St() ? await Pr() : void 0;
3817
+ ce.current = ht, ee.current.setDeveloperToken(ht), ee.current.setTtsEngineId(q);
3818
+ const Tt = bt() ? await Pr() : void 0;
3831
3819
  if (y) return;
3832
- le.current?.("loadAssets");
3833
- const ie = await Xt(
3834
- H.loadAssets(kt),
3820
+ ie.current?.("loadAssets");
3821
+ const se = await Jt(
3822
+ W.loadAssets(Tt),
3835
3823
  18e4,
3836
3824
  "load face assets"
3837
3825
  );
3838
- if (!y && ie.width > 0 && ie.height > 0 && (Ie.current = ie, Tr(ie)), y) return;
3839
- Oe.current = H.getVisemeAtlasPaths(), be.current = !0, Be(!0), bt.current?.(), H.renderSilOnly().then(() => {
3840
- y || le.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");
3841
3829
  }), (async () => {
3842
3830
  try {
3843
- const V = await di(kt);
3844
- if (await A.current.load(V), y) return;
3845
- W.current = !0, xe(!0), Pe(Y.current), A.current.setActive(!0);
3846
- const ae = A.current.getVideo();
3847
- H.usesPixi ? H.drawIdleVideo(ae) : await Gr(
3848
- N,
3849
- 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,
3850
3838
  null,
3851
3839
  void 0,
3852
- Ie.current
3853
- ), y || le.current?.("idle");
3854
- } catch (V) {
3840
+ ct.current
3841
+ ), y || ie.current?.("idle");
3842
+ } catch (U) {
3855
3843
  if (y) return;
3856
- W.current = !1, xe(!1), console.warn("[AiTwin] Idle video unavailable:", V);
3844
+ $.current = !1, Me(!1), console.warn("[AiTwin] Idle video unavailable:", U);
3857
3845
  }
3858
3846
  })();
3859
- } catch (z) {
3847
+ } catch (K) {
3860
3848
  if (y) return;
3861
- if (z instanceof Jt) {
3862
- _e(z.message);
3849
+ if (K instanceof Qt) {
3850
+ Ee(K.message);
3863
3851
  return;
3864
3852
  }
3865
- _e(z instanceof Error ? z.message : "Failed to load AI twin");
3853
+ Ee(K instanceof Error ? K.message : "Failed to load AI twin");
3866
3854
  }
3867
3855
  })(), () => {
3868
- y = !0, A.current?.dispose(), H?.dispose(), U.current = null;
3856
+ y = !0, A.current?.dispose(), W?.dispose(), N.current = null;
3869
3857
  };
3870
- }, [Vn, s, He, t, a, u, i, C, Pr, _e, p]), $e(() => {
3871
- const y = { current: !1 }, N = () => {
3872
- const H = P.current, z = U.current, K = Le(
3873
- re.current,
3874
- ne.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
3875
3863
  );
3876
- if (!H || !z || !ye) {
3877
- de.current = requestAnimationFrame(N);
3864
+ if (!W || !K || !ke) {
3865
+ pe.current = requestAnimationFrame(O);
3878
3866
  return;
3879
3867
  }
3880
3868
  if (document.hidden) {
3881
- A.current?.setActive(!1), de.current = requestAnimationFrame(N);
3869
+ A.current?.setActive(!1), pe.current = requestAnimationFrame(O);
3882
3870
  return;
3883
3871
  }
3884
- const ve = K.isSpeaking(), Ee = K.isWarmingUp(), dt = ve && !F.current, Je = F.current && !ve;
3885
- dt && (Te(), Fe(), v.current = !1, E.current = !1, Pe(Y.current), O.current?.reset(), pe.current.reset(), Me.current = void 0, ue.current = 0, T.current = "sil", M.current = 0, A.current?.setActive(!1)), Je && (Q.current.reset(), A.current?.setActive(!1), O.current?.reset(), ft());
3886
- const mt = Je || v.current || h.current, kt = B && z.supportsBufferedPlayback;
3887
- if (Ee) {
3888
- W.current && A.current?.setActive(!1);
3889
- const ie = K.getVisemeQueue();
3890
- ie.length > 0 && D.current === 0 && (D.current = performance.now()), Q.current.advance(performance.now());
3891
- const V = Q.current.getExpressionPath(), ae = Q.current.getDrawKey(), ge = {
3892
- queue: ie,
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) {
3876
+ $.current && A.current?.setActive(!1);
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,
3893
3881
  elapsedMs: 0,
3894
- expressionPath: V,
3895
- expressionDrawKey: ae,
3896
- availablePaths: Oe.current
3882
+ expressionPath: U,
3883
+ expressionDrawKey: oe,
3884
+ availablePaths: Ce.current
3897
3885
  };
3898
3886
  let Re = !1;
3899
- kt && O.current ? (O.current.warmupTick(ge), Re = O.current.isWarmupReady(
3900
- ge,
3901
- fe.current
3902
- )) : z.usesPixi && Xr(
3903
- H,
3904
- ie,
3887
+ Tt && I.current ? (I.current.warmupTick(ye), Re = I.current.isWarmupReady(
3888
+ ye,
3889
+ V.current
3890
+ )) : K.usesPixi && Yr(
3891
+ W,
3892
+ se,
3905
3893
  0,
3906
- V,
3907
- ae,
3908
- Y.current,
3909
- (ht, Tt, $t, Et) => {
3910
- z.drawLiveFrame(ht, Tt, $t, (De) => {
3911
- Et?.(De), K.isWarmingUp() && De !== "" && !Yr({ lastDrawnKey: De }) && (D.current = 0, K.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());
3912
3900
  });
3913
3901
  },
3914
- (ht) => {
3915
- le.current?.(ht.label);
3902
+ (pt) => {
3903
+ ie.current?.(pt.label);
3916
3904
  },
3917
- Oe.current
3905
+ Ce.current
3918
3906
  );
3919
- const Qe = D.current > 0 && performance.now() - D.current > cs;
3920
- le.current?.(
3907
+ const Qe = J.current > 0 && performance.now() - J.current > os;
3908
+ ie.current?.(
3921
3909
  Re ? "buffer ready" : "buffering lipsync…"
3922
- ), (Re || Qe) && (D.current = 0, K.releaseWarmupHold()), F.current = K.isSpeaking(), de.current = requestAnimationFrame(N);
3910
+ ), (Re || Qe) && (J.current = 0, q.releaseWarmupHold()), F.current = q.isSpeaking(), pe.current = requestAnimationFrame(O);
3923
3911
  return;
3924
3912
  }
3925
- if (ve) {
3926
- W.current && A.current?.setActive(!1);
3927
- const ie = K.getVisemeQueue(), V = K.getPlaybackElapsedMs();
3928
- Ys(ie, V), M.current = V;
3929
- const ae = ie.length > 0 ? Nt(ie, V) : "sil";
3930
- ae !== "sil" && (T.current = ae);
3931
- const ge = Ni(
3932
- V,
3933
- K.getSentenceEmotions(),
3934
- K.getWordQueue(),
3935
- K.getStreamMood()
3913
+ if (Se) {
3914
+ $.current && A.current?.setActive(!1);
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);
3919
+ const ye = Li(
3920
+ U,
3921
+ q.getSentenceEmotions(),
3922
+ q.getWordQueue(),
3923
+ q.getStreamMood()
3936
3924
  );
3937
- Q.current.setTargetEmotion(ge), Q.current.setTargetEyebrow(
3938
- Di(
3939
- V,
3940
- K.getWordQueue(),
3941
- wr(ge)
3925
+ X.current.setTargetEmotion(ye), X.current.setTargetEyebrow(
3926
+ Mi(
3927
+ U,
3928
+ q.getWordQueue(),
3929
+ gr(ye)
3942
3930
  )
3943
- ), Q.current.advance(performance.now());
3944
- const Re = Q.current.getExpressionPath(), Qe = Q.current.getDrawKey(), ht = (De, qt, pt, Kt) => {
3931
+ ), X.current.advance(performance.now());
3932
+ const Re = X.current.getExpressionPath(), Qe = X.current.getDrawKey(), pt = (De, Kt, wt, Gt) => {
3945
3933
  const xr = {
3946
- label: ct.current,
3947
- elapsedMs: V,
3948
- mouthPath: qt.mouthPath,
3949
- transitionMeta: Me.current
3934
+ label: Oe.current,
3935
+ elapsedMs: U,
3936
+ mouthPath: Kt.mouthPath,
3937
+ transitionMeta: Ue.current
3950
3938
  };
3951
- Ye.current.set(pt, xr), O.current?.markExternallyDisplayed(
3952
- pt,
3939
+ ut.current.set(wt, xr), I.current?.markExternallyDisplayed(
3940
+ wt,
3953
3941
  Re
3954
- ), z.drawLiveFrame(De, qt, pt, (At) => {
3955
- const Wn = Ye.current.get(At) ?? xr;
3956
- Ye.current.delete(At), pe.current.onDrawDisplayed(
3957
- Wn,
3958
- ie
3959
- ), O.current?.markExternallyDisplayed(
3960
- At,
3942
+ ), K.drawLiveFrame(De, Kt, wt, (Pt) => {
3943
+ const Vn = ut.current.get(Pt) ?? xr;
3944
+ ut.current.delete(Pt), we.current.onDrawDisplayed(
3945
+ Vn,
3946
+ se
3947
+ ), I.current?.markExternallyDisplayed(
3948
+ Pt,
3961
3949
  Re
3962
- ), Kt?.(At);
3950
+ ), Gt?.(Pt);
3963
3951
  });
3964
- }, Tt = (De) => {
3965
- ct.current = De.label, Me.current = De.transitionMeta, le.current?.(De.label);
3966
- }, $t = B && z.supportsBufferedPlayback;
3967
- let Et = !1;
3968
- $t && O.current && (Et = O.current.tick({
3969
- canvas: H,
3970
- queue: ie,
3971
- elapsedMs: V,
3952
+ }, Et = (De) => {
3953
+ Oe.current = De.label, Ue.current = De.transitionMeta, ie.current?.(De.label);
3954
+ }, qt = B && K.supportsBufferedPlayback;
3955
+ let At = !1;
3956
+ qt && I.current && (At = I.current.tick({
3957
+ canvas: W,
3958
+ queue: se,
3959
+ elapsedMs: U,
3972
3960
  expressionPath: Re,
3973
3961
  expressionDrawKey: Qe,
3974
- playbackState: Y.current,
3975
- availablePaths: Oe.current,
3976
- onStatus: Tt,
3977
- onDisplayed: (qt, pt, Kt) => {
3978
- pe.current.onDrawDisplayed(
3962
+ playbackState: j.current,
3963
+ availablePaths: Ce.current,
3964
+ onStatus: Et,
3965
+ onDisplayed: (Kt, wt, Gt) => {
3966
+ we.current.onDrawDisplayed(
3979
3967
  {
3980
- label: Kt,
3981
- elapsedMs: V,
3982
- mouthPath: pt,
3983
- transitionMeta: Me.current
3968
+ label: Gt,
3969
+ elapsedMs: U,
3970
+ mouthPath: wt,
3971
+ transitionMeta: Ue.current
3984
3972
  },
3985
- ie
3973
+ se
3986
3974
  );
3987
3975
  }
3988
- }).usedBuffer), Et || Xr(
3989
- H,
3990
- ie,
3991
- V,
3976
+ }).usedBuffer), At || Yr(
3977
+ W,
3978
+ se,
3979
+ U,
3992
3980
  Re,
3993
3981
  Qe,
3994
- Y.current,
3995
- ht,
3996
- Tt,
3997
- Oe.current
3998
- ), pe.current.onRafTickSpeaking(), he.current?.(
3999
- pe.current.snapshot(ie, V)
3982
+ j.current,
3983
+ pt,
3984
+ Et,
3985
+ Ce.current
3986
+ ), we.current.onRafTickSpeaking(), ve.current?.(
3987
+ we.current.snapshot(se, U)
4000
3988
  );
4001
- } else if (!mt && W.current && A.current) {
4002
- const ie = A.current, V = ie.getVideo();
4003
- if (V.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
4004
- ie.setActive(!0);
4005
- const ae = () => !K.isSpeaking() && !v.current && !h.current;
4006
- z.usesPixi ? (z.drawIdleVideo(V, ae), ae() && le.current?.("idle")) : y.current || (y.current = !0, Gr(
4007
- H,
4008
- V,
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(
3995
+ W,
3996
+ U,
4009
3997
  null,
4010
3998
  void 0,
4011
- Ie.current,
4012
- ae
4013
- ).then(() => le.current?.("idle")).finally(() => {
3999
+ ct.current,
4000
+ oe
4001
+ ).then(() => ie.current?.("idle")).finally(() => {
4014
4002
  y.current = !1;
4015
4003
  }));
4016
4004
  } else
4017
- Jr(
4018
- H,
4005
+ Xr(
4006
+ W,
4019
4007
  null,
4020
4008
  "__sil__",
4021
- Y.current,
4022
- (ae, ge, Re, Qe) => z.drawLiveFrame(ae, ge, Re, Qe),
4023
- (ae) => le.current?.(ae)
4009
+ j.current,
4010
+ (oe, ye, Re, Qe) => K.drawLiveFrame(oe, ye, Re, Qe),
4011
+ (oe) => ie.current?.(oe)
4024
4012
  );
4025
- } else mt || Jr(
4026
- H,
4013
+ } else ht || Xr(
4014
+ W,
4027
4015
  null,
4028
4016
  "__sil__",
4029
- Y.current,
4030
- (ie, V, ae, ge) => z.drawLiveFrame(ie, V, ae, ge),
4031
- (ie) => le.current?.(ie)
4017
+ j.current,
4018
+ (se, U, oe, ye) => K.drawLiveFrame(se, U, oe, ye),
4019
+ (se) => ie.current?.(se)
4032
4020
  );
4033
- F.current = ve, de.current = requestAnimationFrame(N);
4021
+ F.current = Se, pe.current = requestAnimationFrame(O);
4034
4022
  };
4035
- return de.current = requestAnimationFrame(N), () => {
4036
- cancelAnimationFrame(de.current), Te(), Fe(), re.current.stop(), ne.current?.stop();
4023
+ return pe.current = requestAnimationFrame(O), () => {
4024
+ cancelAnimationFrame(pe.current), Ae(), Fe(), ee.current.stop(), ae.current?.stop();
4037
4025
  };
4038
4026
  }, [
4039
- ye,
4027
+ ke,
4040
4028
  ot,
4041
- ft,
4042
- Te,
4029
+ dt,
4030
+ Ae,
4043
4031
  Fe
4044
- ]), qn(
4032
+ ]), $n(
4045
4033
  k,
4046
4034
  () => ({
4047
- speakText: async (y, N) => {
4048
- const H = y.trim();
4049
- if (!H) return;
4050
- const z = U.current;
4051
- if (!z || !be.current && !ye)
4035
+ speakText: async (y, O) => {
4036
+ const W = y.trim();
4037
+ if (!W) return;
4038
+ const K = N.current;
4039
+ if (!K || !_e.current && !ke)
4052
4040
  throw new Error("AI twin is not ready");
4053
- const { ttsEngineId: K, voiceId: ve } = ke(N);
4054
- Se(null), ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, T.current = "sil", M.current = 0, Pe(Y.current), Q.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;
4055
4043
  try {
4056
- W.current ? (A.current?.setActive(!1), A.current?.restart(), Pe(Y.current)) : await z.renderSilOnly(), await re.current.speak(H, {
4057
- voiceId: ve,
4058
- speakingRate: N?.speakingRate ?? l,
4059
- ttsEngineId: K
4044
+ $.current ? (A.current?.setActive(!1), A.current?.restart(), Ie(j.current)) : await K.renderSilOnly(), await ee.current.speak(W, {
4045
+ voiceId: Se,
4046
+ speakingRate: O?.speakingRate ?? l,
4047
+ ttsEngineId: q
4060
4048
  });
4061
- } catch (Ee) {
4062
- throw _e(Ee instanceof Error ? Ee.message : "TTS failed"), Ee;
4049
+ } catch (Pe) {
4050
+ throw Ee(Pe instanceof Error ? Pe.message : "TTS failed"), Pe;
4063
4051
  }
4064
4052
  },
4065
4053
  stop: () => {
4066
- ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, re.current.stop(), ne.current?.stop(), Pe(Y.current), O.current?.reset(), D.current = 0, F.current = !1, ft();
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();
4067
4055
  },
4068
4056
  setTtsEngineId: (y) => {
4069
- re.current.setTtsEngineId(y), ne.current?.setTtsEngineId(y), te.current && (te.current.ttsEngineId = y);
4057
+ ee.current.setTtsEngineId(y), ae.current?.setTtsEngineId(y), he.current && (he.current.ttsEngineId = y);
4070
4058
  },
4071
- renderViseme: async (y, N) => {
4072
- const H = U.current, z = P.current;
4073
- if (!H || !z || !be.current)
4059
+ renderViseme: async (y, O) => {
4060
+ const W = N.current, K = P.current;
4061
+ if (!W || !K || !_e.current)
4074
4062
  throw new Error("AI twin is not ready");
4075
- await H.renderViseme(z, y, {
4076
- from: N?.from,
4077
- transitionDurationMs: N?.transitionDurationMs,
4078
- gapMs: N?.gapMs,
4079
- onStatus: (K) => le.current?.(K)
4063
+ await W.renderViseme(K, y, {
4064
+ from: O?.from,
4065
+ transitionDurationMs: O?.transitionDurationMs,
4066
+ gapMs: O?.gapMs,
4067
+ onStatus: (q) => ie.current?.(q)
4080
4068
  });
4081
4069
  },
4082
- isReady: () => be.current,
4083
- getStatus: () => J,
4070
+ isReady: () => _e.current,
4071
+ getStatus: () => Y,
4084
4072
  connect: async (y = {}) => {
4085
- Se(null);
4073
+ be(null);
4086
4074
  try {
4087
- let N = y.authToken?.trim();
4088
- N || (N = X.current ?? i ?? await zt(), X.current = N);
4089
- const H = y.voiceId?.trim() ?? u ?? te.current?.voiceId, z = y.personaId?.trim() ?? te.current?.personaId, K = Er();
4090
- await K.unlockAudio(), await K.connect({
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();
4078
+ await q.unlockAudio(), await q.connect({
4091
4079
  ...y,
4092
- apiBase: y.apiBase?.trim() || oe,
4093
- authToken: N,
4094
- voiceId: H,
4095
- personaId: z,
4080
+ apiBase: y.apiBase?.trim() || Te,
4081
+ authToken: O,
4082
+ voiceId: W,
4083
+ personaId: K,
4096
4084
  speakingRate: y.speakingRate ?? l
4097
4085
  });
4098
- } catch (N) {
4099
- throw _e(
4100
- N instanceof Error ? N.message : "Voice connect failed"
4101
- ), N;
4086
+ } catch (O) {
4087
+ throw Ee(
4088
+ O instanceof Error ? O.message : "Voice connect failed"
4089
+ ), O;
4102
4090
  }
4103
4091
  },
4104
4092
  disconnect: async () => {
4105
- const y = ne.current;
4106
- y && (ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, Pe(Y.current), O.current?.reset(), D.current = 0, F.current = !1, await y.disconnect(), ft());
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());
4107
4095
  },
4108
- isConnected: () => ne.current?.isConnected() ?? !1,
4109
- getVoiceStream: () => ne.current?.getVoiceStream() ?? re.current?.getVoiceStream() ?? null
4096
+ isConnected: () => ae.current?.isConnected() ?? !1,
4097
+ getVoiceStream: () => ae.current?.getVoiceStream() ?? ee.current?.getVoiceStream() ?? null
4110
4098
  }),
4111
4099
  [
4112
- ye,
4100
+ ke,
4113
4101
  l,
4114
4102
  i,
4115
4103
  u,
4116
- Te,
4104
+ Ae,
4117
4105
  Fe,
4118
- ft,
4119
- _e,
4120
- ke,
4106
+ dt,
4107
+ Ee,
4108
+ Ye,
4121
4109
  Er,
4122
- J
4110
+ Y
4123
4111
  ]
4124
- ), /* @__PURE__ */ Hn("div", { className: f, style: { ..._a, ...c }, children: [
4112
+ ), /* @__PURE__ */ Wn("div", { className: f, style: { ...ga, ...c }, children: [
4125
4113
  /* @__PURE__ */ Ir(
4126
4114
  "canvas",
4127
4115
  {
4128
4116
  ref: P,
4129
- width: Wt.width,
4130
- height: Wt.height,
4131
- style: { ...va, ...d },
4117
+ width: Ht.width,
4118
+ height: Ht.height,
4119
+ style: { ...ya, ...d },
4132
4120
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
4133
4121
  }
4134
4122
  ),
4135
- _ && ee ? /* @__PURE__ */ Ir("div", { style: Sa, children: ee }) : null
4123
+ _ && Z ? /* @__PURE__ */ Ir("div", { style: _a, children: Z }) : null
4136
4124
  ] });
4137
- }), ba = "thumbnail.webp";
4138
- function Ba(e, t = ir) {
4125
+ }), va = "thumbnail.webp";
4126
+ function Ra(e, t = ar) {
4139
4127
  const r = e.trim();
4140
4128
  if (!r)
4141
4129
  throw new Error("faceId is required");
4142
- return `${t.replace(/\/$/, "")}/${r}/${ba}`;
4130
+ return `${t.replace(/\/$/, "")}/${r}/${va}`;
4143
4131
  }
4144
- const ka = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
4145
- function Ta(e = ".png") {
4132
+ const Sa = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
4133
+ function ba(e = ".png") {
4146
4134
  const t = e.toLowerCase();
4147
- return ka.has(t) ? `source${t}` : "source.png";
4135
+ return Sa.has(t) ? `source${t}` : "source.png";
4148
4136
  }
4149
- function Ca(e, t = ir, r = ".png") {
4137
+ function Da(e, t = ar, r = ".png") {
4150
4138
  const n = e.trim();
4151
4139
  if (!n)
4152
4140
  throw new Error("faceId is required");
4153
- return `${t.replace(/\/$/, "")}/${n}/${Ta(r)}`;
4141
+ return `${t.replace(/\/$/, "")}/${n}/${ba(r)}`;
4154
4142
  }
4155
4143
  export {
4156
- ba as AI_TWIN_THUMBNAIL_FILENAME,
4157
- Da as AiTwin,
4158
- Jt as AiTwinNotFoundError,
4144
+ va as AI_TWIN_THUMBNAIL_FILENAME,
4145
+ Ma as AiTwin,
4146
+ Qt as AiTwinNotFoundError,
4159
4147
  tt as DEFAULT_TTS_ENGINE_ID,
4160
- kn as MIC_SAMPLE_RATE,
4161
- xs as OCULUS_VISEME_IDS,
4162
- Tn as PLAYBACK_SAMPLE_RATE,
4163
- fr as SPEAKING_RATE_MAX,
4164
- lr as SPEAKING_RATE_MIN,
4148
+ bn as MIC_SAMPLE_RATE,
4149
+ Ps as OCULUS_VISEME_IDS,
4150
+ kn as PLAYBACK_SAMPLE_RATE,
4151
+ dr as SPEAKING_RATE_MAX,
4152
+ fr as SPEAKING_RATE_MIN,
4165
4153
  it as TTS_ENGINE_CARTESIA,
4166
- an as TTS_ENGINE_GOOGLE,
4167
- or as TTS_ENGINE_INWORLD,
4168
- Ra as VISEME_IDS,
4169
- bn as VISEME_TEST_CARTESIA_VOICE_ID,
4170
- Ut as VISEME_TEST_SPEAKING_RATE,
4171
- Sn as VISEME_TEST_VOICE_ID,
4172
- Ta as aiTwinSourceFilename,
4173
- ni as buildVoiceWebSocketUrl,
4154
+ sn as TTS_ENGINE_GOOGLE,
4155
+ cr as TTS_ENGINE_INWORLD,
4156
+ Ia as VISEME_IDS,
4157
+ Sn as VISEME_TEST_CARTESIA_VOICE_ID,
4158
+ Vt as VISEME_TEST_SPEAKING_RATE,
4159
+ vn as VISEME_TEST_VOICE_ID,
4160
+ ba as aiTwinSourceFilename,
4161
+ ti as buildVoiceWebSocketUrl,
4174
4162
  Or as createAvatarTtsLipsyncController,
4175
- ai as createRealtimeVoiceLipsyncController,
4163
+ si as createRealtimeVoiceLipsyncController,
4176
4164
  Br as faceAssetUrls,
4177
- hs as fetchAiTwin,
4178
- zt as fetchDevAuthToken,
4179
- Ca as getAiTwinSourceUrl,
4180
- Ba as getAiTwinThumbnailUrl,
4181
- Ms as normalizeOculusViseme,
4182
- Ts as resolveDirectFaceId,
4183
- Nt as resolveVisemeAtTime,
4184
- Ma as resolveWordAtTime,
4185
- Es as setActiveTwinAssets
4165
+ ms as fetchAiTwin,
4166
+ jt as fetchDevAuthToken,
4167
+ Da as getAiTwinSourceUrl,
4168
+ Ra as getAiTwinThumbnailUrl,
4169
+ Is as normalizeOculusViseme,
4170
+ ks as resolveDirectFaceId,
4171
+ Ut as resolveVisemeAtTime,
4172
+ xa as resolveWordAtTime,
4173
+ Ts as setActiveTwinAssets
4186
4174
  };