@streamoji/aitwin 0.3.7 → 0.3.9

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,37 +1,37 @@
1
- import { jsxs as yr, jsx as yn } from "react/jsx-runtime";
2
- import { forwardRef as _r, useRef as O, useState as at, useEffect as Ce, useCallback as Se, useMemo as _n, useImperativeHandle as Sr } from "react";
3
- import { PipecatClient as kr } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as br, DailyMediaManager as vr, ProtobufFrameSerializer as Er } from "@pipecat-ai/websocket-transport";
5
- const Tr = "https://aitwin.bubu.social", Wn = {
6
- publicBase: Tr
7
- }, Ar = "0.3.7", Ir = {
8
- version: Ar
9
- }, Mr = {}, lt = "https://ai.aitwin.me", jt = `${Wn.publicBase}/custom-faces`, Pr = `${Wn.publicBase}/aitwin-workers/v${Ir.version}/visemeDiffPreview.worker.js`;
10
- function Rr(e) {
1
+ import { jsxs as _r, jsx as yn } from "react/jsx-runtime";
2
+ import { forwardRef as Sr, useRef as O, useState as at, useEffect as Ce, useCallback as Se, useMemo as _n, useImperativeHandle as kr } from "react";
3
+ import { PipecatClient as vr } from "@pipecat-ai/client-js";
4
+ import { WebSocketTransport as br, DailyMediaManager as Er, ProtobufFrameSerializer as Tr } from "@pipecat-ai/websocket-transport";
5
+ const Ar = "https://aitwin.bubu.social", Hn = {
6
+ publicBase: Ar
7
+ }, Ir = "0.3.9", Mr = {
8
+ version: Ir
9
+ }, Pr = {}, lt = "https://ai.aitwin.me", jt = `${Hn.publicBase}/custom-faces`, Rr = `${Hn.publicBase}/aitwin-workers/v${Mr.version}/visemeDiffPreview.worker.js`;
10
+ function Dr(e) {
11
11
  if (e) return e;
12
- const t = typeof import.meta < "u" ? Mr?.VITE_AITWIN_WORKER_URL : void 0;
13
- return t?.trim() ? t.trim() : Pr;
12
+ const t = typeof import.meta < "u" ? Pr?.VITE_AITWIN_WORKER_URL : void 0;
13
+ return t?.trim() ? t.trim() : Rr;
14
14
  }
15
- const Dr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Ct = 3e3, ut = 16, Sn = 3e3, xr = 4e3, Br = 0.85, Cr = 8, zt = 400, Hn = "eng_a7f2b9c1", Yt = "eng_d4e8f3a2", Xe = "eng_c9b1e6d4", je = Xe, $n = /* @__PURE__ */ new Set([
15
+ const xr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Ct = 3e3, ut = 16, Sn = 3e3, Br = 4e3, Cr = 0.85, Fr = 8, zt = 400, $n = "eng_a7f2b9c1", Yt = "eng_d4e8f3a2", Xe = "eng_c9b1e6d4", je = Xe, qn = /* @__PURE__ */ new Set([
16
16
  Yt,
17
17
  Xe
18
- ]), qn = {
19
- [Hn]: "oculus_direct",
18
+ ]), Kn = {
19
+ [$n]: "oculus_direct",
20
20
  [Xe]: "oculus_direct",
21
21
  [Yt]: "inworld_word"
22
22
  }, kn = {
23
- google: Hn,
23
+ google: $n,
24
24
  inworld: Yt,
25
25
  cartesia: Xe
26
26
  };
27
- function Fr(e) {
28
- return qn[e];
29
- }
30
27
  function Lr(e) {
31
- return e === Xe;
28
+ return Kn[e];
32
29
  }
33
30
  function Or(e) {
34
- if (e.ttsEngineId && e.ttsEngineId in qn)
31
+ return e === Xe;
32
+ }
33
+ function Nr(e) {
34
+ if (e.ttsEngineId && e.ttsEngineId in Kn)
35
35
  return e.ttsEngineId;
36
36
  const t = e.tts?.toLowerCase();
37
37
  return t && t in kn ? kn[t] : je;
@@ -41,7 +41,7 @@ class Ut extends Error {
41
41
  super(t), this.name = "AiTwinNotFoundError";
42
42
  }
43
43
  }
44
- async function Nr(e, t = Dr) {
44
+ async function Ur(e, t = xr) {
45
45
  const n = new URL(t);
46
46
  n.searchParams.set("id", e);
47
47
  const r = await fetch(n.toString());
@@ -52,25 +52,25 @@ async function Nr(e, t = Dr) {
52
52
  const s = await r.json();
53
53
  if (!s.success)
54
54
  throw new Ut(s.error ?? "AI twin not found");
55
- const { tts: i, token: a, ...o } = s.data, f = String(o.authToken ?? a ?? "").trim() || void 0;
55
+ const { tts: i, token: a, ...o } = s.data, d = String(o.authToken ?? a ?? "").trim() || void 0;
56
56
  return {
57
57
  ...o,
58
- ttsEngineId: Or(s.data),
59
- authToken: f
58
+ ttsEngineId: Nr(s.data),
59
+ authToken: d
60
60
  };
61
61
  }
62
- const Ur = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Vr = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hr = "6TNvp3SCs4Og0a1ijm9TommXLql1", $r = "Swaraj Mali";
62
+ const Vr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Wr = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Hr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", $r = "6TNvp3SCs4Og0a1ijm9TommXLql1", qr = "Swaraj Mali";
63
63
  async function Ft() {
64
- const e = await fetch(Ur, {
64
+ const e = await fetch(Vr, {
65
65
  method: "POST",
66
66
  headers: {
67
67
  "Content-Type": "application/json",
68
- "Client-Id": Vr,
69
- "Client-Secret": Wr
68
+ "Client-Id": Wr,
69
+ "Client-Secret": Hr
70
70
  },
71
71
  body: JSON.stringify({
72
- userId: Hr,
73
- userName: $r
72
+ userId: $r,
73
+ userName: qr
74
74
  })
75
75
  });
76
76
  if (!e.ok)
@@ -80,7 +80,7 @@ async function Ft() {
80
80
  throw new Error("getAuthToken returned no token");
81
81
  return n;
82
82
  }
83
- async function qr(e, t = lt) {
83
+ async function Kr(e, t = lt) {
84
84
  const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
85
85
  headers: { Authorization: `Bearer ${e}` }
86
86
  });
@@ -90,7 +90,7 @@ async function qr(e, t = lt) {
90
90
  if (!r.value) throw new Error("Session value response missing value");
91
91
  return r;
92
92
  }
93
- function Kr(e) {
93
+ function Gr(e) {
94
94
  const t = e.trim();
95
95
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
96
96
  const n = new Uint8Array(t.length / 2);
@@ -101,17 +101,17 @@ function Kr(e) {
101
101
  function gt(e) {
102
102
  return Uint8Array.from(e);
103
103
  }
104
- function Gr(e, t) {
104
+ function jr(e, t) {
105
105
  const n = new Uint8Array(e.length + t.length);
106
106
  return n.set(e, 0), n.set(t, e.length), n;
107
107
  }
108
- async function jr(e, t) {
108
+ async function zr(e, t) {
109
109
  if (!t) throw new Error("Asset key is required for encrypted assets");
110
110
  if (e.byteLength < 28)
111
111
  throw new Error("Encrypted payload too small");
112
- const n = new Uint8Array(e), r = gt(n.subarray(0, 12)), s = gt(n.subarray(12, 28)), i = gt(n.subarray(28)), a = gt(Gr(i, s)), o = await crypto.subtle.importKey(
112
+ const n = new Uint8Array(e), r = gt(n.subarray(0, 12)), s = gt(n.subarray(12, 28)), i = gt(n.subarray(28)), a = gt(jr(i, s)), o = await crypto.subtle.importKey(
113
113
  "raw",
114
- Kr(t),
114
+ Gr(t),
115
115
  { name: "AES-GCM" },
116
116
  !1,
117
117
  ["decrypt"]
@@ -127,7 +127,7 @@ const Wt = /* @__PURE__ */ new Set();
127
127
  function yt(e) {
128
128
  return e.includes("/custom-faces/");
129
129
  }
130
- function bt(e) {
130
+ function vt(e) {
131
131
  const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
132
132
  if (!(e.encrypted || yt(t) || yt(n)))
133
133
  return { twinBase: n, binBase: t, encrypted: !1 };
@@ -135,22 +135,22 @@ function bt(e) {
135
135
  return { twinBase: s, binBase: s, encrypted: !0 };
136
136
  }
137
137
  function Qe(e) {
138
- return bt(e).encrypted;
138
+ return vt(e).encrypted;
139
139
  }
140
- function bn(e, t = jt) {
140
+ function vn(e, t = jt) {
141
141
  const n = `${t.replace(/\/$/, "")}/${e}`;
142
142
  return { twinBase: n, binBase: n, encrypted: !0 };
143
143
  }
144
- function zr(e, t) {
144
+ function Yr(e, t) {
145
145
  return (e ?? t)?.trim() || void 0;
146
146
  }
147
- function Yr(e) {
148
- Vt = bt(e);
147
+ function Jr(e) {
148
+ Vt = vt(e);
149
149
  for (const t of Wt) t();
150
150
  }
151
- function Jr(e, t) {
151
+ function Xr(e, t) {
152
152
  const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
153
- if (!n) return bt(e);
153
+ if (!n) return vt(e);
154
154
  const r = (s) => {
155
155
  try {
156
156
  return new URL(s, n).href.replace(/\/$/, "");
@@ -158,7 +158,7 @@ function Jr(e, t) {
158
158
  return s;
159
159
  }
160
160
  };
161
- return bt({
161
+ return vt({
162
162
  twinBase: r(e.twinBase),
163
163
  binBase: r(e.binBase),
164
164
  encrypted: e.encrypted
@@ -169,33 +169,33 @@ function Ue() {
169
169
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
170
170
  return Vt;
171
171
  }
172
- function Xr(e) {
172
+ function Qr(e) {
173
173
  return Wt.add(e), () => Wt.delete(e);
174
174
  }
175
- function vn() {
175
+ function bn() {
176
176
  const e = Ue();
177
177
  return Qe(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
178
178
  }
179
- function Qr() {
179
+ function Zr() {
180
180
  const e = Ue();
181
181
  return Qe(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
182
182
  }
183
- function Zr() {
183
+ function es() {
184
184
  const e = Ue();
185
185
  return Qe(e) ? e.binBase : e.twinBase;
186
186
  }
187
187
  function It() {
188
188
  return Qe(Ue());
189
189
  }
190
- function es() {
190
+ function ts() {
191
191
  const e = Ue();
192
192
  return Qe(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
193
193
  }
194
- function ts() {
194
+ function ns() {
195
195
  const e = Ue();
196
196
  return Qe(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
197
197
  }
198
- function Kn(e) {
198
+ function Gn(e) {
199
199
  const t = e.split(/\r?\n/);
200
200
  let n = "", r = "";
201
201
  for (const i of t)
@@ -210,7 +210,7 @@ function Kn(e) {
210
210
  }
211
211
  return { event: n, data: s };
212
212
  }
213
- const ns = [
213
+ const rs = [
214
214
  "aa",
215
215
  "CH",
216
216
  "DD",
@@ -226,14 +226,14 @@ const ns = [
226
226
  "kk",
227
227
  "nn",
228
228
  "sil"
229
- ], rs = new Map(
230
- ns.map((e) => [e.toLowerCase(), e])
229
+ ], ss = new Map(
230
+ rs.map((e) => [e.toLowerCase(), e])
231
231
  );
232
- function ss(e) {
232
+ function is(e) {
233
233
  const t = (e ?? "").trim();
234
- return t ? rs.get(t.toLowerCase()) ?? "sil" : "sil";
234
+ return t ? ss.get(t.toLowerCase()) ?? "sil" : "sil";
235
235
  }
236
- const is = {
236
+ const as = {
237
237
  aei: ["aa", "E", "I"],
238
238
  o: ["O", "U"],
239
239
  ee: ["I"],
@@ -245,12 +245,12 @@ const is = {
245
245
  qw: ["U", "O"],
246
246
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
247
247
  };
248
- function as(e) {
248
+ function os(e) {
249
249
  if (!e) return ["sil"];
250
250
  const t = e.toLowerCase();
251
- return is[t] ?? ["sil"];
251
+ return as[t] ?? ["sil"];
252
252
  }
253
- function os(e, t) {
253
+ function cs(e, t) {
254
254
  const n = e.word.length;
255
255
  if (n <= 0) return 0;
256
256
  const r = e.wduration;
@@ -266,11 +266,11 @@ function Jt(e, t) {
266
266
  const n = e.toLowerCase().replace(/[^a-z']/g, "");
267
267
  return !n || ze(n, t) !== "w" || t > 0 && ze(n, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(n);
268
268
  }
269
- function cs(e, t) {
269
+ function us(e, t) {
270
270
  const n = e.toLowerCase(), r = ze(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
271
271
  return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
272
272
  }
273
- function us(e, t) {
273
+ function ls(e, t) {
274
274
  const n = e.toLowerCase(), r = n.slice(
275
275
  Math.max(0, t - 1),
276
276
  Math.min(n.length, t + 3)
@@ -280,7 +280,7 @@ function us(e, t) {
280
280
  const s = ze(n, t);
281
281
  return s === "u" || s === "w" ? "U" : "O";
282
282
  }
283
- function ls(e, t) {
283
+ function fs(e, t) {
284
284
  const n = e.toLowerCase();
285
285
  if (Jt(n, t)) return "FF";
286
286
  const r = n.slice(Math.max(0, t - 2), t + 1);
@@ -303,7 +303,7 @@ const _t = {
303
303
  x: "CH",
304
304
  j: "CH"
305
305
  };
306
- function fs(e, t) {
306
+ function ds(e, t) {
307
307
  const n = e.toLowerCase(), r = ze(n, t);
308
308
  if (_t[r]) return _t[r];
309
309
  for (let s = 0; s < n.length; s++) {
@@ -312,33 +312,33 @@ function fs(e, t) {
312
312
  }
313
313
  return "DD";
314
314
  }
315
- function ds(e, t, n) {
316
- const r = as(e);
315
+ function ms(e, t, n) {
316
+ const r = os(e);
317
317
  if (r.length === 1) return r[0];
318
318
  const s = t.trim();
319
319
  if (!s) return r[0];
320
320
  const i = (e ?? "").toLowerCase(), a = Math.max(0, n);
321
321
  switch (i) {
322
322
  case "aei":
323
- return cs(s, a);
324
- case "o":
325
323
  return us(s, a);
326
- case "qw":
324
+ case "o":
327
325
  return ls(s, a);
328
- case "cdgknstxyz":
326
+ case "qw":
329
327
  return fs(s, a);
328
+ case "cdgknstxyz":
329
+ return ds(s, a);
330
330
  default:
331
331
  return r[0];
332
332
  }
333
333
  }
334
- const ms = 32;
335
- function Gn(e) {
334
+ const hs = 32, En = 48;
335
+ function jn(e) {
336
336
  let t = 0;
337
337
  for (const n of e)
338
338
  t = Math.max(t, n.vtime + n.vduration);
339
339
  return t;
340
340
  }
341
- function jn(e) {
341
+ function zn(e) {
342
342
  let t = null, n = -1;
343
343
  for (const r of e) {
344
344
  if (r.viseme === "sil") continue;
@@ -347,22 +347,22 @@ function jn(e) {
347
347
  }
348
348
  return t;
349
349
  }
350
- function hs(e) {
351
- return zn(e).find((n) => n.viseme !== "sil") ?? null;
350
+ function ps(e) {
351
+ return Yn(e).find((n) => n.viseme !== "sil") ?? null;
352
352
  }
353
353
  function Fe(e) {
354
- const t = Gn(e);
355
- return jn(e) ? t + zt : t;
354
+ const t = jn(e);
355
+ return zn(e) ? t + zt : t;
356
356
  }
357
- function ps(e) {
358
- const t = [], n = hs(e);
357
+ function ws(e) {
358
+ const t = [], n = ps(e);
359
359
  n && n.vtime > 0 && t.push({
360
360
  from: "sil",
361
361
  to: n.viseme,
362
362
  fromVtime: 0,
363
363
  toVtime: n.vtime
364
364
  });
365
- const r = jn(e), s = Gn(e);
365
+ const r = zn(e), s = jn(e);
366
366
  return r && t.push({
367
367
  from: r.viseme,
368
368
  to: "sil",
@@ -370,54 +370,70 @@ function ps(e) {
370
370
  toVtime: s + zt
371
371
  }), t;
372
372
  }
373
- function zn(e) {
373
+ function Yn(e) {
374
374
  const t = /* @__PURE__ */ new Map();
375
375
  for (const n of e)
376
376
  t.has(n.vtime) || t.set(n.vtime, n);
377
377
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
378
378
  }
379
- function ws(e) {
380
- const t = zn(e), n = [];
379
+ function gs(e) {
380
+ const t = Yn(e), n = [];
381
381
  for (let r = 0; r < t.length - 1; r++) {
382
382
  const s = t[r].viseme, i = t[r + 1].viseme, a = t[r].vtime, o = t[r + 1].vtime;
383
383
  s === i || o <= a || n.push({ from: s, to: i, fromVtime: a, toVtime: o });
384
384
  }
385
385
  return n;
386
386
  }
387
- function gs(e) {
387
+ function ys(e) {
388
388
  return e.length === 0 ? [] : [
389
- ...ps(e),
390
- ...ws(e)
389
+ ...ws(e),
390
+ ...gs(e)
391
391
  ];
392
392
  }
393
- function ys(e, t) {
393
+ function _s(e, t) {
394
394
  let n = null;
395
395
  for (const r of e) {
396
- const { transEnd: s } = Yn(r.fromVtime, r.toVtime);
397
- t >= r.fromVtime && t < s && (n = r);
396
+ const { transStart: s, transEnd: i } = Jn(
397
+ r.fromVtime,
398
+ r.toVtime,
399
+ r.from,
400
+ r.to
401
+ );
402
+ t >= s && t < i && (n = r);
398
403
  }
399
404
  return n;
400
405
  }
401
- function Yn(e, t) {
402
- const n = Math.max(0, t - e), r = n > 0 ? Math.max(n, ms) : 0, s = e, i = e + r;
403
- return { gapMs: n, effectiveGapMs: r, holdEnd: e, transStart: s, transEnd: i };
406
+ function Jn(e, t, n, r) {
407
+ const s = Math.max(0, t - e);
408
+ if ((n === "PP" || r === "PP") && s > En) {
409
+ const f = En, u = t, c = u - f;
410
+ return {
411
+ gapMs: s,
412
+ effectiveGapMs: f,
413
+ holdEnd: c,
414
+ transStart: c,
415
+ transEnd: u
416
+ };
417
+ }
418
+ const a = s > 0 ? Math.max(s, hs) : 0, o = e, d = e + a;
419
+ return { gapMs: s, effectiveGapMs: a, holdEnd: e, transStart: o, transEnd: d };
404
420
  }
405
421
  const Xt = 16e3;
406
- function Jn(e) {
422
+ function Xn(e) {
407
423
  const t = Number(e);
408
424
  return Number.isFinite(t) && t > 0 ? t : Xt;
409
425
  }
410
- function _s(e) {
426
+ function Ss(e) {
411
427
  let t = e.trim();
412
428
  const n = t.indexOf(",");
413
429
  t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
414
430
  const r = t.length % 4;
415
431
  return r !== 0 && (t += "=".repeat(4 - r)), t;
416
432
  }
417
- function Ss(e) {
433
+ function ks(e) {
418
434
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
419
435
  }
420
- function En(e, t, n = Xt) {
436
+ function Tn(e, t, n = Xt) {
421
437
  const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
422
438
  r.buffer,
423
439
  r.byteOffset,
@@ -428,15 +444,15 @@ function En(e, t, n = Xt) {
428
444
  const a = e.createBuffer(1, i.length, n);
429
445
  return a.copyToChannel(i, 0), a;
430
446
  }
431
- function ks(e) {
432
- const t = _s(e), n = window.atob(t), r = new Uint8Array(n.length);
447
+ function vs(e) {
448
+ const t = Ss(e), n = window.atob(t), r = new Uint8Array(n.length);
433
449
  for (let s = 0; s < n.length; s++)
434
450
  r[s] = n.charCodeAt(s);
435
451
  return r;
436
452
  }
437
453
  async function bs(e, t, n = Xt) {
438
- const r = ks(t), s = Jn(n);
439
- if (Ss(r)) {
454
+ const r = vs(t), s = Xn(n);
455
+ if (ks(r)) {
440
456
  const i = r.buffer.slice(
441
457
  r.byteOffset,
442
458
  r.byteOffset + r.byteLength
@@ -444,7 +460,7 @@ async function bs(e, t, n = Xt) {
444
460
  return e.decodeAudioData(i);
445
461
  }
446
462
  if (r.length >= 2 && r.length % 2 === 0)
447
- return En(e, r, s);
463
+ return Tn(e, r, s);
448
464
  try {
449
465
  const i = r.buffer.slice(
450
466
  r.byteOffset,
@@ -452,26 +468,26 @@ async function bs(e, t, n = Xt) {
452
468
  );
453
469
  return await e.decodeAudioData(i);
454
470
  } catch {
455
- return En(e, r, s);
471
+ return Tn(e, r, s);
456
472
  }
457
473
  }
458
- function Tn(e) {
474
+ function An(e) {
459
475
  let t = 0;
460
476
  for (const n of e)
461
477
  t = Math.max(t, n.vtime + n.vduration);
462
478
  return t;
463
479
  }
464
- function vs(e, t) {
480
+ function Es(e, t) {
465
481
  for (const n of e)
466
482
  if (t >= n.wtime && t < n.wtime + n.wduration)
467
483
  return n;
468
484
  return null;
469
485
  }
470
- function Xn(e, t) {
486
+ function Qn(e, t) {
471
487
  const n = [], r = [];
472
- let s = null, i = !1, a = !1, o = !1, f = !1, d = 0, u = 0, c = 0, m = 0, w = null, b = 1, h = t, I = !1, E = null, _ = 0, p = !1, v = !1, N = 0;
488
+ let s = null, i = !1, a = !1, o = !1, d = !1, f = 0, u = 0, c = 0, m = 0, w = null, v = 1, h = t, I = !1, E = null, _ = 0, p = !1, b = !1, N = 0;
473
489
  const F = [], j = () => {
474
- v = !1, N = 0, F.length = 0;
490
+ b = !1, N = 0, F.length = 0;
475
491
  }, R = () => {
476
492
  w != null && (clearTimeout(w), w = null);
477
493
  }, S = () => {
@@ -488,14 +504,14 @@ function Xn(e, t) {
488
504
  r.length = 0;
489
505
  }, M = () => {
490
506
  for (const y of r)
491
- y.playbackRate.value = b;
507
+ y.playbackRate.value = v;
492
508
  }, T = () => {
493
- if (!(I || !f || i || r.length > 0 || n.length > 0)) {
509
+ if (!(I || !d || i || r.length > 0 || n.length > 0)) {
494
510
  if (o && s && u > 0) {
495
511
  const y = (s.currentTime - u) * 1e3;
496
512
  if (y < _) {
497
513
  R();
498
- const A = b > 0 ? (_ - y) / b : _ - y;
514
+ const A = v > 0 ? (_ - y) / v : _ - y;
499
515
  w = setTimeout(() => {
500
516
  I || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
501
517
  }, Math.max(0, A));
@@ -510,8 +526,8 @@ function Xn(e, t) {
510
526
  e.onSpeakingDone(), e.onNotify();
511
527
  return;
512
528
  }
513
- a = !0, d = performance.now(), e.onSpeakingStart(), e.onNotify(), R();
514
- const q = b > 0 ? A / b : A;
529
+ a = !0, f = performance.now(), e.onSpeakingStart(), e.onNotify(), R();
530
+ const q = v > 0 ? A / v : A;
515
531
  w = setTimeout(() => {
516
532
  I || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
517
533
  }, q);
@@ -533,9 +549,9 @@ function Xn(e, t) {
533
549
  q.length !== 0 && (P && (c = x), q.forEach((C) => {
534
550
  const B = String(C.symbol ?? C.viseme ?? "").trim();
535
551
  if (!B) return;
536
- const Y = Math.round((C.start ?? 0) * 1e3), ee = Math.max(1, Math.round((C.duration ?? 0) * 1e3)), pe = c + Y, me = vs(A, pe), le = me ? os(me, pe) : 0;
552
+ const Y = Math.round((C.start ?? 0) * 1e3), ee = Math.max(1, Math.round((C.duration ?? 0) * 1e3)), pe = c + Y, me = Es(A, pe), le = me ? cs(me, pe) : 0;
537
553
  let fe;
538
- Fr($) === "oculus_direct" ? (fe = ss(B), fe === "U" && me && Jt(me.word, le) && (fe = "FF")) : fe = ds(
554
+ Lr($) === "oculus_direct" ? (fe = is(B), fe === "U" && me && Jt(me.word, le) && (fe = "FF")) : fe = ms(
539
555
  B,
540
556
  me?.word ?? "",
541
557
  le
@@ -562,22 +578,22 @@ function Xn(e, t) {
562
578
  const $ = A?.isFirstAudio ?? !a;
563
579
  P < x && (P = x + 0.1), m = P + y.duration;
564
580
  const C = q.createBufferSource();
565
- if (C.buffer = y, C.playbackRate.value = b, C.connect(q.destination), E && C.connect(E), r.push(C), I) {
581
+ if (C.buffer = y, C.playbackRate.value = v, C.connect(q.destination), E && C.connect(E), r.push(C), I) {
566
582
  r.pop();
567
583
  return;
568
584
  }
569
585
  if ($) {
570
586
  a = !0, e.onSpeakingStart(), A?.isFirstOfStream ? (u = P, c = 0, A.onNewStream?.()) : u <= 0 && (u = P);
571
587
  const B = (P - x) * 1e3;
572
- d = performance.now() + B;
588
+ f = performance.now() + B;
573
589
  }
574
590
  C.onended = () => {
575
591
  const B = r.indexOf(C);
576
592
  B >= 0 && r.splice(B, 1), T(), e.onNotify();
577
593
  }, C.start(P);
578
594
  }, ne = () => {
579
- if (!v || F.length === 0) return;
580
- v = !1;
595
+ if (!b || F.length === 0) return;
596
+ b = !1;
581
597
  const y = F.splice(0);
582
598
  N = 0;
583
599
  for (let A = 0; A < y.length; A++)
@@ -588,12 +604,12 @@ function Xn(e, t) {
588
604
  e.onNotify();
589
605
  }, de = async (y, A, q, x, P, $, C) => {
590
606
  if (I) return;
591
- const B = Jn(C?.sampleRate), Y = C?.newStream === !0;
607
+ const B = Xn(C?.sampleRate), Y = C?.newStream === !0;
592
608
  if (!q?.trim()) {
593
609
  if (x.length === 0 && P.length === 0) return;
594
610
  Y && (c = 0, _ = 0, y.length = 0, A.length = 0, C?.onNewStream?.());
595
611
  let ee = c;
596
- $ && y.length > 0 && !Y && (ee = Tn(y)), z(
612
+ $ && y.length > 0 && !Y && (ee = An(y)), z(
597
613
  y,
598
614
  A,
599
615
  x,
@@ -628,8 +644,8 @@ function Xn(e, t) {
628
644
  );
629
645
  o = !0;
630
646
  const le = !a;
631
- if (p && (e.shouldHoldForWarmup?.() ?? !1) && (v || le && Y)) {
632
- v || (v = !0, N = 0, F.length = 0, Y && (c = 0, _ = 0, y.length = 0, A.length = 0, C?.onNewStream?.())), z(
647
+ if (p && (e.shouldHoldForWarmup?.() ?? !1) && (b || le && Y)) {
648
+ b || (b = !0, N = 0, F.length = 0, Y && (c = 0, _ = 0, y.length = 0, A.length = 0, C?.onNewStream?.())), z(
633
649
  y,
634
650
  A,
635
651
  x,
@@ -683,20 +699,20 @@ function Xn(e, t) {
683
699
  h = y;
684
700
  },
685
701
  setPlaybackSpeed: (y) => {
686
- b = Math.max(0.1, Math.min(1, y)), M();
702
+ v = Math.max(0.1, Math.min(1, y)), M();
687
703
  },
688
- getPlaybackSpeed: () => b,
704
+ getPlaybackSpeed: () => v,
689
705
  setLipsyncWarmupHoldEnabled: (y) => {
690
706
  p = y, y || j();
691
707
  },
692
- isWarmingUp: () => v,
708
+ isWarmingUp: () => b,
693
709
  releaseWarmupHold: ne,
694
710
  resetForNewStream: (y) => {
695
- I = !1, f = !1, h = y, _ = 0;
711
+ I = !1, d = !1, h = y, _ = 0;
696
712
  },
697
713
  /** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
698
714
  resumeBotStream: () => {
699
- I = !1, f = !1;
715
+ I = !1, d = !1;
700
716
  },
701
717
  /** After interrupt — allow the next utterance to queue/play again. */
702
718
  clearAborted: () => {
@@ -708,10 +724,10 @@ function Xn(e, t) {
708
724
  s || (s = new y()), s.state === "suspended" && await s.resume(), s && !E && (E = s.createMediaStreamDestination());
709
725
  },
710
726
  stop: () => {
711
- I = !0, R(), S(), n.length = 0, i = !1, a = !1, o = !1, f = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
727
+ I = !0, R(), S(), n.length = 0, i = !1, a = !1, o = !1, d = !1, c = 0, m = 0, u = 0, f = 0, _ = 0, j();
712
728
  },
713
729
  markStreamComplete: (y) => {
714
- if (_ = Math.max(_, Fe(y)), f = !0, !o && y.length > 0) {
730
+ if (_ = Math.max(_, Fe(y)), d = !0, !o && y.length > 0) {
715
731
  Z(y);
716
732
  return;
717
733
  }
@@ -721,7 +737,7 @@ function Xn(e, t) {
721
737
  queueTimingsOnly: (y, A, q, x, P) => {
722
738
  if (I) return;
723
739
  let $ = c;
724
- P && y.length > 0 && ($ = Tn(y)), z(
740
+ P && y.length > 0 && ($ = An(y)), z(
725
741
  y,
726
742
  A,
727
743
  q,
@@ -734,16 +750,16 @@ function Xn(e, t) {
734
750
  getPlaybackElapsedMs: () => o && s && u > 0 ? Math.max(
735
751
  0,
736
752
  (s.currentTime - u) * 1e3
737
- ) : a ? Math.max(0, (performance.now() - d) * b) : 0,
753
+ ) : a ? Math.max(0, (performance.now() - f) * v) : 0,
738
754
  isSpeaking: () => a ? !0 : !o || !s || u <= 0 ? !1 : (s.currentTime - u) * 1e3 < _,
739
755
  getVoiceStream: () => E ? E.stream : null,
740
- getPlaybackStartPerf: () => d,
756
+ getPlaybackStartPerf: () => f,
741
757
  /** User spoke over the bot — drop in-flight chunks until the next utterance. */
742
758
  bargeIn: () => {
743
- I = !0, f = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
759
+ I = !0, d = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, f = 0, _ = 0, j();
744
760
  },
745
761
  interrupt: () => {
746
- I = !0, f = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
762
+ I = !0, d = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, f = 0, _ = 0, j();
747
763
  }
748
764
  };
749
765
  }
@@ -753,7 +769,7 @@ function Mt(e, t) {
753
769
  t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
754
770
  return n ? n.viseme : "sil";
755
771
  }
756
- function Qn(e, t, n = 120) {
772
+ function Zn(e, t, n = 120) {
757
773
  const r = Mt(e, t);
758
774
  if (r !== "sil") return r;
759
775
  let s = null;
@@ -764,7 +780,7 @@ function Qn(e, t, n = 120) {
764
780
  }
765
781
  return s?.viseme ?? "sil";
766
782
  }
767
- function Es(e, t, n = 400) {
783
+ function Ts(e, t, n = 400) {
768
784
  const r = t - n;
769
785
  let s = 0;
770
786
  for (const i of e)
@@ -772,13 +788,13 @@ function Es(e, t, n = 400) {
772
788
  else break;
773
789
  s > 0 && e.splice(0, s);
774
790
  }
775
- function ea(e, t) {
791
+ function ta(e, t) {
776
792
  for (const n of e)
777
793
  if (t >= n.wtime && t < n.wtime + n.wduration)
778
794
  return n;
779
795
  return null;
780
796
  }
781
- function Ts(e, t) {
797
+ function As(e, t) {
782
798
  const n = e.trim();
783
799
  if (!n) return null;
784
800
  try {
@@ -788,15 +804,15 @@ function Ts(e, t) {
788
804
  return null;
789
805
  }
790
806
  }
791
- const Qt = 0.5, Zt = 1.5, Zn = "Olivia", er = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Pt = 0.85;
792
- function An(e, t = lt, n = {}) {
807
+ const Qt = 0.5, Zt = 1.5, er = "Olivia", tr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Pt = 0.85;
808
+ function In(e, t = lt, n = {}) {
793
809
  const r = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], a = [], o = [];
794
- let f = "", d = "neutral", u = "", c = je;
810
+ let d = "", f = "neutral", u = "", c = je;
795
811
  const m = /* @__PURE__ */ new Set();
796
- let w = 0, b = null;
812
+ let w = 0, v = null;
797
813
  const h = () => m.forEach((R) => R());
798
814
  let I = () => !1;
799
- const E = Xn(
815
+ const E = Qn(
800
816
  {
801
817
  onSpeakingStart: () => e("speaking"),
802
818
  onSpeakingDone: () => e("done"),
@@ -804,13 +820,13 @@ function An(e, t = lt, n = {}) {
804
820
  shouldHoldForWarmup: () => I()
805
821
  },
806
822
  je
807
- ), _ = () => E.getPlaybackElapsedMs(), p = (R, S = f) => {
823
+ ), _ = () => E.getPlaybackElapsedMs(), p = (R, S = d) => {
808
824
  if (!n.onLipsyncDebug) return;
809
825
  const M = _(), T = s;
810
826
  n.onLipsyncDebug({
811
827
  event: R,
812
828
  spokenText: S,
813
- mood: d,
829
+ mood: f,
814
830
  playbackAnchorPerf: E.getPlaybackStartPerf(),
815
831
  playbackElapsedMs: M,
816
832
  queueLength: T.length,
@@ -820,11 +836,11 @@ function An(e, t = lt, n = {}) {
820
836
  visemes: [...Z.visemes]
821
837
  }))
822
838
  });
823
- }, v = (R, S) => {
824
- n.onLipsyncDebug && (b = { event: R, spokenText: S }, w === 0 && (w = requestAnimationFrame(() => {
839
+ }, b = (R, S) => {
840
+ n.onLipsyncDebug && (v = { event: R, spokenText: S }, w === 0 && (w = requestAnimationFrame(() => {
825
841
  w = 0;
826
- const M = b;
827
- b = null, M && p(M.event, M.spokenText);
842
+ const M = v;
843
+ v = null, M && p(M.event, M.spokenText);
828
844
  })));
829
845
  }, N = (R, S, M, T, Z) => {
830
846
  if (!n.onLipsyncDebug) return;
@@ -850,7 +866,7 @@ function An(e, t = lt, n = {}) {
850
866
  })
851
867
  });
852
868
  }, F = () => {
853
- E.stop(), s.length = 0, i.length = 0, a.length = 0, d = "neutral", o.length = 0, f = "", e("idle"), v("reset"), h();
869
+ E.stop(), s.length = 0, i.length = 0, a.length = 0, f = "neutral", o.length = 0, d = "", e("idle"), b("reset"), h();
854
870
  };
855
871
  return {
856
872
  setDeveloperToken: (R) => {
@@ -861,13 +877,13 @@ function An(e, t = lt, n = {}) {
861
877
  },
862
878
  getTtsEngineId: () => c,
863
879
  speak: async (R, S) => {
864
- F(), e("loading"), f = R, o.length = 0;
880
+ F(), e("loading"), d = R, o.length = 0;
865
881
  const M = u.trim();
866
882
  if (!M)
867
883
  throw new Error("Developer token required for avatar_ttsWithPoses");
868
884
  const T = S?.ttsEngineId ?? c ?? je;
869
885
  E.resetForNewStream(T), E.setStreamTtsEngineId(T);
870
- const Z = S?.voiceId ?? Zn, D = S?.speakingRate ?? Pt, X = Math.max(
886
+ const Z = S?.voiceId ?? er, D = S?.speakingRate ?? Pt, X = Math.max(
871
887
  Qt,
872
888
  Math.min(Zt, D)
873
889
  ), z = {
@@ -876,7 +892,7 @@ function An(e, t = lt, n = {}) {
876
892
  speakingRate: X,
877
893
  tenant: "aiTwin"
878
894
  };
879
- $n.has(T) && (z.voice_id = Z);
895
+ qn.has(T) && (z.voice_id = Z);
880
896
  try {
881
897
  const se = await fetch(r, {
882
898
  method: "POST",
@@ -893,7 +909,7 @@ function An(e, t = lt, n = {}) {
893
909
  const de = ne.getReader(), ue = new TextDecoder();
894
910
  let y = "";
895
911
  const A = async (q) => {
896
- const x = Kn(q);
912
+ const x = Gn(q);
897
913
  if (x) {
898
914
  if (x.event === "audio") {
899
915
  const P = x.data.chunk, $ = x.data.visemes ?? [], C = x.data.words ?? [], B = x.data.is_new_segment ?? !1, Y = x.data.sample_rate, ee = s.length;
@@ -910,8 +926,8 @@ function An(e, t = lt, n = {}) {
910
926
  ee,
911
927
  $,
912
928
  B,
913
- Ts(P, Y)
914
- ), v("audio_chunk", R)) : ($.length > 0 || C.length > 0) && (E.queueTimingsOnly(
929
+ As(P, Y)
930
+ ), b("audio_chunk", R)) : ($.length > 0 || C.length > 0) && (E.queueTimingsOnly(
915
931
  s,
916
932
  i,
917
933
  $,
@@ -923,10 +939,10 @@ function An(e, t = lt, n = {}) {
923
939
  $,
924
940
  B,
925
941
  null
926
- ), v("audio_chunk", R));
942
+ ), b("audio_chunk", R));
927
943
  } else if (x.event === "metadata") {
928
944
  const P = x.data.mood;
929
- typeof P == "string" && P.trim() && (d = P.trim());
945
+ typeof P == "string" && P.trim() && (f = P.trim());
930
946
  const $ = x.data.sentence_emotions;
931
947
  if (Array.isArray($)) {
932
948
  a.length = 0;
@@ -937,13 +953,13 @@ function An(e, t = lt, n = {}) {
937
953
  sentence_index: Number(B.sentence_index ?? 0),
938
954
  text: String(B.text ?? ""),
939
955
  sentiment: typeof B.sentiment == "string" ? B.sentiment : void 0,
940
- emotion: String(B.emotion ?? d),
956
+ emotion: String(B.emotion ?? f),
941
957
  start_word: Number(B.start_word ?? 0),
942
958
  end_word: Number(B.end_word ?? 0)
943
959
  });
944
960
  }
945
961
  }
946
- h(), v("metadata", R);
962
+ h(), b("metadata", R);
947
963
  } else if (x.event === "error")
948
964
  throw new Error(
949
965
  String(x.data.message ?? "avatar_ttsWithPoses stream error")
@@ -959,7 +975,7 @@ function An(e, t = lt, n = {}) {
959
975
  y = P.pop() ?? "";
960
976
  for (const $ of P) await A($);
961
977
  if (q) {
962
- y.trim() && await A(y.trim()), E.markStreamComplete(s), v("bot_stopped", R);
978
+ y.trim() && await A(y.trim()), E.markStreamComplete(s), b("bot_stopped", R);
963
979
  break;
964
980
  }
965
981
  }
@@ -971,7 +987,7 @@ function An(e, t = lt, n = {}) {
971
987
  getVisemeQueue: () => s,
972
988
  getWordQueue: () => i,
973
989
  getSentenceEmotions: () => a,
974
- getStreamMood: () => d,
990
+ getStreamMood: () => f,
975
991
  getPlaybackElapsedMs: () => E.getPlaybackElapsedMs(),
976
992
  isSpeaking: () => E.isSpeaking(),
977
993
  isWarmingUp: () => E.isWarmingUp(),
@@ -987,8 +1003,8 @@ function An(e, t = lt, n = {}) {
987
1003
  subscribe: (R) => (m.add(R), () => m.delete(R))
988
1004
  };
989
1005
  }
990
- const tr = 16e3, nr = 16e3;
991
- class As extends Er {
1006
+ const nr = 16e3, rr = 16e3;
1007
+ class Is extends Tr {
992
1008
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
993
1009
  async deserialize(t) {
994
1010
  try {
@@ -1000,7 +1016,7 @@ class As extends Er {
1000
1016
  }
1001
1017
  }
1002
1018
  }
1003
- class Is extends vr {
1019
+ class Ms extends Er {
1004
1020
  constructor() {
1005
1021
  super(
1006
1022
  !0,
@@ -1008,33 +1024,33 @@ class Is extends vr {
1008
1024
  void 0,
1009
1025
  void 0,
1010
1026
  512,
1011
- tr,
1012
- nr
1027
+ nr,
1028
+ rr
1013
1029
  );
1014
1030
  }
1015
1031
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
1016
1032
  bufferBotAudio(t, n) {
1017
1033
  }
1018
1034
  }
1019
- const Ms = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1020
- function Ps(e) {
1021
- return Ms.test(e.trim());
1022
- }
1035
+ const Ps = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1023
1036
  function Rs(e) {
1037
+ return Ps.test(e.trim());
1038
+ }
1039
+ function Ds(e) {
1024
1040
  const t = e.replace(/\/$/, "");
1025
1041
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
1026
1042
  }
1027
- function Ds(e) {
1043
+ function xs(e) {
1028
1044
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
1029
1045
  const t = e.authToken?.trim();
1030
1046
  if (!t)
1031
1047
  throw new Error(
1032
1048
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1033
1049
  );
1034
- const n = e.apiBase ?? lt, r = new URL(`${Rs(n)}/ws/voice`);
1050
+ const n = e.apiBase ?? lt, r = new URL(`${Ds(n)}/ws/voice`);
1035
1051
  r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
1036
1052
  const s = e.voiceId?.trim();
1037
- s && Ps(s) && r.searchParams.set("voiceId", s);
1053
+ s && Rs(s) && r.searchParams.set("voiceId", s);
1038
1054
  const i = e.personaId?.trim();
1039
1055
  i && r.searchParams.set("personaId", i);
1040
1056
  const a = e.speakingRate ?? Pt;
@@ -1057,7 +1073,7 @@ function Lt(e, t) {
1057
1073
  });
1058
1074
  return n;
1059
1075
  }
1060
- function xs(e) {
1076
+ function Bs(e) {
1061
1077
  if (!e || typeof e != "object") return null;
1062
1078
  const t = e, r = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
1063
1079
  return {
@@ -1068,28 +1084,28 @@ function xs(e) {
1068
1084
  function Ot(e) {
1069
1085
  return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
1070
1086
  }
1071
- function Bs(e) {
1087
+ function Cs(e) {
1072
1088
  return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
1073
1089
  }
1074
- function Cs(e, t = {}) {
1090
+ function Fs(e, t = {}) {
1075
1091
  const n = [], r = [], s = [], i = [];
1076
- let a = "", o = "neutral", f = Xe, d = !1, u = null, c = null, m = { ...t }, w = 0, b = null;
1092
+ let a = "", o = "neutral", d = Xe, f = !1, u = null, c = null, m = { ...t }, w = 0, v = null;
1077
1093
  const h = /* @__PURE__ */ new Set(), I = [];
1078
- let E = !1, _ = null, p = !0, v = "default";
1094
+ let E = !1, _ = null, p = !0, b = "default";
1079
1095
  const N = /* @__PURE__ */ new Set();
1080
1096
  let F = null, j = 0, R = !1, S = null;
1081
1097
  const M = () => {
1082
1098
  S != null && (clearTimeout(S), S = null);
1083
1099
  }, T = () => h.forEach((l) => l());
1084
1100
  let Z = () => !1;
1085
- const D = Xn(
1101
+ const D = Qn(
1086
1102
  {
1087
1103
  onSpeakingStart: () => e("speaking"),
1088
1104
  onSpeakingDone: () => e("done"),
1089
1105
  onNotify: T,
1090
1106
  shouldHoldForWarmup: () => Z()
1091
1107
  },
1092
- f
1108
+ d
1093
1109
  ), X = () => {
1094
1110
  if (_) return _;
1095
1111
  const l = new MessageChannel();
@@ -1116,17 +1132,17 @@ function Cs(e, t = {}) {
1116
1132
  }))
1117
1133
  });
1118
1134
  }, de = (l, k) => {
1119
- m.onLipsyncDebug && (b = { event: l, spokenText: k }, w === 0 && (w = requestAnimationFrame(() => {
1135
+ m.onLipsyncDebug && (v = { event: l, spokenText: k }, w === 0 && (w = requestAnimationFrame(() => {
1120
1136
  w = 0;
1121
- const V = b;
1122
- b = null, V && ne(V.event, V.spokenText);
1137
+ const V = v;
1138
+ v = null, V && ne(V.event, V.spokenText);
1123
1139
  })));
1124
1140
  }, ue = () => {
1125
1141
  p = !0, N.clear(), D.clearAborted();
1126
1142
  }, y = () => {
1127
- const l = Bs(u);
1143
+ const l = Cs(u);
1128
1144
  if (l) {
1129
- v = `bot-${Date.now()}`, l.interruptedTrackIds = { [v]: !0 };
1145
+ b = `bot-${Date.now()}`, l.interruptedTrackIds = { [b]: !0 };
1130
1146
  try {
1131
1147
  l.interrupt?.();
1132
1148
  } catch {
@@ -1159,7 +1175,7 @@ function Cs(e, t = {}) {
1159
1175
  return;
1160
1176
  ue(), R = !0;
1161
1177
  const k = String(l.spoken_text ?? l.text ?? "").trim();
1162
- k && (a = k), D.resetForNewStream(f), typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), s.length = 0, s.push(
1178
+ k && (a = k), D.resetForNewStream(d), typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), s.length = 0, s.push(
1163
1179
  ...Lt(l.sentence_emotions, o)
1164
1180
  ), Array.isArray(l.gestures) && l.gestures, de("metadata", k), T();
1165
1181
  }, Y = (l, k, V, K) => {
@@ -1189,7 +1205,7 @@ function Cs(e, t = {}) {
1189
1205
  if (A(l)) return;
1190
1206
  M(), Ot(l) && ue();
1191
1207
  const k = String(l.spoken_text ?? l.text ?? "").trim(), V = Ot(l), K = l.visemes ?? [], ie = l.words ?? [], Pe = String(l.chunk ?? "").trim(), ae = R;
1192
- ae && (R = !1), k && (a = k), C(l, V), ae ? D.resetForNewStream(f) : V && D.resumeBotStream();
1208
+ ae && (R = !1), k && (a = k), C(l, V), ae ? D.resetForNewStream(d) : V && D.resumeBotStream();
1193
1209
  const Re = n.length;
1194
1210
  D.playAudioChunk(
1195
1211
  n,
@@ -1240,17 +1256,17 @@ function Cs(e, t = {}) {
1240
1256
  const K = new AbortController();
1241
1257
  F = K;
1242
1258
  const ie = ++j;
1243
- ue(), D.resetForNewStream(f), a = k;
1244
- const ae = `${(m.apiBase ?? lt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Re = m.voiceId?.trim() || er, ge = m.speakingRate ?? Pt, Ze = Math.max(
1259
+ ue(), D.resetForNewStream(d), a = k;
1260
+ const ae = `${(m.apiBase ?? lt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Re = m.voiceId?.trim() || tr, ge = m.speakingRate ?? Pt, Ze = Math.max(
1245
1261
  Qt,
1246
1262
  Math.min(Zt, ge)
1247
1263
  ), et = {
1248
1264
  user_query: k,
1249
- ttsEngineId: f,
1265
+ ttsEngineId: d,
1250
1266
  speakingRate: Ze,
1251
1267
  tenant: "aiTwin"
1252
1268
  };
1253
- $n.has(f) && (et.voice_id = Re);
1269
+ qn.has(d) && (et.voice_id = Re);
1254
1270
  try {
1255
1271
  const re = await fetch(ae, {
1256
1272
  method: "POST",
@@ -1266,11 +1282,11 @@ function Cs(e, t = {}) {
1266
1282
  const tt = re.body;
1267
1283
  if (!tt) throw new Error("No response body");
1268
1284
  const dt = tt.getReader(), mt = new TextDecoder();
1269
- let be = "";
1270
- const nt = async (ve) => {
1285
+ let ve = "";
1286
+ const nt = async (be) => {
1271
1287
  if (ie !== j || K.signal.aborted || !p)
1272
1288
  return;
1273
- const oe = Kn(ve);
1289
+ const oe = Gn(be);
1274
1290
  if (oe) {
1275
1291
  if (oe.event === "audio") {
1276
1292
  const ce = oe.data.chunk, he = oe.data.visemes ?? [], J = oe.data.words ?? [], Q = oe.data.is_new_segment ?? !1, ht = oe.data.sample_rate;
@@ -1303,15 +1319,15 @@ function Cs(e, t = {}) {
1303
1319
  }
1304
1320
  };
1305
1321
  for (; !(ie !== j || K.signal.aborted || !p); ) {
1306
- const { done: ve, value: oe } = await dt.read();
1307
- oe && (be += mt.decode(oe, { stream: !0 }));
1308
- const ce = be.split(`
1322
+ const { done: be, value: oe } = await dt.read();
1323
+ oe && (ve += mt.decode(oe, { stream: !0 }));
1324
+ const ce = ve.split(`
1309
1325
 
1310
1326
  `);
1311
- be = ce.pop() ?? "";
1327
+ ve = ce.pop() ?? "";
1312
1328
  for (const he of ce) await nt(he);
1313
- if (ve) {
1314
- be.trim() && await nt(be.trim()), ie === j && !K.signal.aborted && p && D.markStreamComplete(n);
1329
+ if (be) {
1330
+ ve.trim() && await nt(ve.trim()), ie === j && !K.signal.aborted && p && D.markStreamComplete(n);
1315
1331
  break;
1316
1332
  }
1317
1333
  }
@@ -1322,7 +1338,7 @@ function Cs(e, t = {}) {
1322
1338
  F === K && (F = null);
1323
1339
  }
1324
1340
  }, le = (l) => {
1325
- const k = xs(l);
1341
+ const k = Bs(l);
1326
1342
  if (!k) {
1327
1343
  console.warn("[realtimeVoice] server message with no payload", l);
1328
1344
  return;
@@ -1350,21 +1366,21 @@ function Cs(e, t = {}) {
1350
1366
  me(k);
1351
1367
  break;
1352
1368
  }
1353
- }, fe = () => u || (c = new Is(), u = new kr({
1369
+ }, fe = () => u || (c = new Ms(), u = new vr({
1354
1370
  transport: new br({
1355
1371
  mediaManager: c,
1356
- serializer: new As(),
1357
- recorderSampleRate: tr,
1358
- playerSampleRate: nr
1372
+ serializer: new Is(),
1373
+ recorderSampleRate: nr,
1374
+ playerSampleRate: rr
1359
1375
  }),
1360
1376
  enableCam: !1,
1361
1377
  enableMic: !0,
1362
1378
  callbacks: {
1363
1379
  onBotReady: () => {
1364
- d = !0, e("idle"), T();
1380
+ f = !0, e("idle"), T();
1365
1381
  },
1366
1382
  onDisconnected: () => {
1367
- d = !1, $();
1383
+ f = !1, $();
1368
1384
  },
1369
1385
  onError: (l) => {
1370
1386
  const k = typeof l == "object" && l !== null && "data" in l ? String(l.data ?? l) : String(l);
@@ -1399,13 +1415,13 @@ function Cs(e, t = {}) {
1399
1415
  setDeveloperToken: (l) => {
1400
1416
  },
1401
1417
  setTtsEngineId: (l) => {
1402
- f = l, D.setStreamTtsEngineId(l);
1418
+ d = l, D.setStreamTtsEngineId(l);
1403
1419
  },
1404
- getTtsEngineId: () => f,
1420
+ getTtsEngineId: () => d,
1405
1421
  speak: async (l, k) => {
1406
1422
  const V = l.trim();
1407
1423
  if (V) {
1408
- if (!u || !d)
1424
+ if (!u || !f)
1409
1425
  throw new Error(
1410
1426
  "Realtime voice is not connected. Call connect() first."
1411
1427
  );
@@ -1423,16 +1439,16 @@ function Cs(e, t = {}) {
1423
1439
  e("loading");
1424
1440
  const k = fe();
1425
1441
  await k.initDevices();
1426
- const V = Ds(m);
1442
+ const V = xs(m);
1427
1443
  console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", V);
1428
1444
  try {
1429
1445
  await k.connect({ wsUrl: V });
1430
1446
  } catch (K) {
1431
- d = !1, e("error"), T();
1447
+ f = !1, e("error"), T();
1432
1448
  const ie = K instanceof Error ? K.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1433
1449
  throw new Error(`${ie} — ${V}`);
1434
1450
  }
1435
- d = !0, e("idle"), T();
1451
+ f = !0, e("idle"), T();
1436
1452
  },
1437
1453
  disconnect: async () => {
1438
1454
  if (M(), R = !1, I.length = 0, E = !1, F?.abort(), F = null, j += 1, ue(), u)
@@ -1441,9 +1457,9 @@ function Cs(e, t = {}) {
1441
1457
  } catch (l) {
1442
1458
  console.error("[realtimeVoice] disconnect failed:", l);
1443
1459
  }
1444
- d = !1, $();
1460
+ f = !1, $();
1445
1461
  },
1446
- isConnected: () => d,
1462
+ isConnected: () => f,
1447
1463
  unlockAudio: async () => {
1448
1464
  await D.primeAudioContext();
1449
1465
  },
@@ -1466,13 +1482,13 @@ function Cs(e, t = {}) {
1466
1482
  subscribe: (l) => (h.add(l), () => h.delete(l))
1467
1483
  };
1468
1484
  }
1469
- function Fs(e, t, n) {
1485
+ function Ls(e, t, n) {
1470
1486
  return {
1471
1487
  width: e.crop?.source_width ?? t,
1472
1488
  height: e.crop?.source_height ?? n
1473
1489
  };
1474
1490
  }
1475
- function Ls(e, t) {
1491
+ function Os(e, t) {
1476
1492
  const n = e.crop;
1477
1493
  return {
1478
1494
  x: t?.source_x ?? n?.x ?? 0,
@@ -1481,21 +1497,21 @@ function Ls(e, t) {
1481
1497
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
1482
1498
  };
1483
1499
  }
1484
- function Os(e) {
1500
+ function Ns(e) {
1485
1501
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1486
1502
  }
1487
1503
  async function Rt(e, t) {
1488
1504
  const n = await fetch(e);
1489
1505
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1490
1506
  const r = await n.arrayBuffer();
1491
- return jr(r, t);
1507
+ return zr(r, t);
1492
1508
  }
1493
- async function Ns(e, t) {
1509
+ async function Us(e, t) {
1494
1510
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1495
1511
  const n = await Rt(e, t), r = new TextDecoder().decode(n);
1496
1512
  return JSON.parse(r);
1497
1513
  }
1498
- async function Us(e) {
1514
+ async function Vs(e) {
1499
1515
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
1500
1516
  return new Promise((r, s) => {
1501
1517
  const i = new Image();
@@ -1506,7 +1522,7 @@ async function Us(e) {
1506
1522
  }, i.src = n;
1507
1523
  });
1508
1524
  }
1509
- async function Vs(e) {
1525
+ async function Ws(e) {
1510
1526
  const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
1511
1527
  return new Promise((r, s) => {
1512
1528
  const i = new Image();
@@ -1517,28 +1533,28 @@ async function Vs(e) {
1517
1533
  }, i.src = n;
1518
1534
  });
1519
1535
  }
1520
- function Ws(e) {
1536
+ function Hs(e) {
1521
1537
  const t = new Blob([e], { type: "video/mp4" });
1522
1538
  return URL.createObjectURL(t);
1523
1539
  }
1524
- async function Hs(e) {
1525
- const t = Qr();
1540
+ async function $s(e) {
1541
+ const t = Zr();
1526
1542
  if (!It()) return t;
1527
1543
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1528
1544
  const n = await Rt(t, e);
1529
- return Ws(n);
1545
+ return Hs(n);
1530
1546
  }
1531
1547
  function en(e, t) {
1532
1548
  return `${e}/${t}_minus_sil.png`;
1533
1549
  }
1534
- const rr = 5;
1550
+ const sr = 5;
1535
1551
  function tn(e) {
1536
1552
  const t = e?.composite_threshold;
1537
1553
  if (typeof t == "number" && t > 0) return t;
1538
1554
  const n = e?.crop?.content_threshold;
1539
- return typeof n == "number" && n > 0 ? n : rr;
1555
+ return typeof n == "number" && n > 0 ? n : sr;
1540
1556
  }
1541
- const ta = [
1557
+ const na = [
1542
1558
  "aa",
1543
1559
  "E",
1544
1560
  "I",
@@ -1557,7 +1573,7 @@ const ta = [
1557
1573
  "t01_0.25",
1558
1574
  "t02_0.50",
1559
1575
  "t03_0.75"
1560
- ], $s = Ht.length, In = /* @__PURE__ */ new Set([
1576
+ ], qs = Ht.length, Mn = /* @__PURE__ */ new Set([
1561
1577
  "aa__kk",
1562
1578
  "aa__nn",
1563
1579
  "aa__sil",
@@ -1664,75 +1680,75 @@ const ta = [
1664
1680
  "U__nn",
1665
1681
  "U__sil"
1666
1682
  ]);
1667
- function Mn(e, t) {
1683
+ function Pn(e, t) {
1668
1684
  return `${e}__${t}`;
1669
1685
  }
1670
- function Pn(e, t) {
1686
+ function Rn(e, t) {
1671
1687
  return `pairs/${e}/${t}_minus_sil.png`;
1672
1688
  }
1673
- function vt(e) {
1689
+ function bt(e) {
1674
1690
  return `${e}_minus_sil.png`;
1675
1691
  }
1676
- function sr(e, t) {
1692
+ function ir(e, t) {
1677
1693
  if (t.has(e)) return e;
1678
1694
  const n = /^pairs\/([^/]+)\//.exec(e);
1679
1695
  if (!n) return null;
1680
1696
  const r = n[1].split("__")[1];
1681
1697
  if (!r || r === "sil") return null;
1682
- const s = vt(r);
1698
+ const s = bt(r);
1683
1699
  return t.has(s) ? s : null;
1684
1700
  }
1685
- function ir(e, t) {
1701
+ function ar(e, t) {
1686
1702
  return e.filter((n) => t.has(n));
1687
1703
  }
1688
- function qs(e, t, n) {
1704
+ function Ks(e, t, n) {
1689
1705
  const r = nn(e, t);
1690
- return ir(r, n).length > 0;
1706
+ return ar(r, n).length > 0;
1691
1707
  }
1692
1708
  function nn(e, t) {
1693
1709
  if (e === t) return [];
1694
- const n = [], r = Mn(e, t);
1695
- if (In.has(r)) {
1710
+ const n = [], r = Pn(e, t);
1711
+ if (Mn.has(r)) {
1696
1712
  for (const i of Ht)
1697
- n.push(Pn(r, i));
1713
+ n.push(Rn(r, i));
1698
1714
  return n;
1699
1715
  }
1700
- const s = Mn(t, e);
1701
- if (In.has(s)) {
1702
- for (let i = $s - 1; i >= 0; i--)
1703
- n.push(Pn(s, Ht[i]));
1716
+ const s = Pn(t, e);
1717
+ if (Mn.has(s)) {
1718
+ for (let i = qs - 1; i >= 0; i--)
1719
+ n.push(Rn(s, Ht[i]));
1704
1720
  return n;
1705
1721
  }
1706
1722
  return [];
1707
1723
  }
1708
- function Ks(e) {
1724
+ function Gs(e) {
1709
1725
  return e < 16 ? [1] : e < 24 ? [1] : e < 35 ? [0, 1, 2] : [0, 1, 2];
1710
1726
  }
1711
- function Gs(e, t) {
1712
- return Ks(t).map((r) => e[r]).filter((r) => r != null);
1727
+ function js(e, t) {
1728
+ return Gs(t).map((r) => e[r]).filter((r) => r != null);
1713
1729
  }
1714
- function js(e, t, n, r) {
1730
+ function zs(e, t, n, r) {
1715
1731
  if (r <= 0) return 0;
1716
1732
  const i = Math.max(1, n - t) / r, a = e - t, o = Math.floor(a / i);
1717
1733
  return Math.min(r - 1, Math.max(0, o));
1718
1734
  }
1719
- function zs(e, t, n) {
1735
+ function Ys(e, t, n) {
1720
1736
  if (!n) return `${e}/${t}`;
1721
1737
  const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
1722
1738
  return `${e}/${s}.bin`;
1723
1739
  }
1724
- const Ys = [0.32, 0.24, 0.16, 0.08, 0], Js = Ys.map(
1740
+ const Js = [0.32, 0.24, 0.16, 0.08, 0], Xs = Js.map(
1725
1741
  (e) => `eyes_${e.toFixed(2)}`
1726
- ), Xs = [
1742
+ ), Qs = [
1727
1743
  "eyes_0.32",
1728
1744
  "eyes_0.16",
1729
1745
  "eyes_0.00"
1730
- ], Qs = [
1746
+ ], Zs = [
1731
1747
  "eyes_0.32",
1732
1748
  "eyes_0.16",
1733
1749
  "eyes_0.08",
1734
1750
  "eyes_0.00"
1735
- ], Rn = 2, Zs = -30, $t = 20, ei = {
1751
+ ], Dn = 2, ei = -30, $t = 20, ti = {
1736
1752
  fear: -30,
1737
1753
  anger: -20,
1738
1754
  sad: -10,
@@ -1745,20 +1761,20 @@ function rn(e) {
1745
1761
  return `brow_${e}`;
1746
1762
  }
1747
1763
  function sn(e) {
1748
- return ei[e];
1764
+ return ti[e];
1749
1765
  }
1750
1766
  function Oe(e) {
1751
- return Math.max(Zs, Math.min($t, e));
1767
+ return Math.max(ei, Math.min($t, e));
1752
1768
  }
1753
- function ti(e, t) {
1769
+ function ni(e, t) {
1754
1770
  if (e === t) return [];
1755
- const n = e < t ? Rn : -Rn, r = [];
1771
+ const n = e < t ? Dn : -Dn, r = [];
1756
1772
  let s = e;
1757
1773
  for (; s !== t; )
1758
1774
  s += n, r.push(s);
1759
1775
  return r;
1760
1776
  }
1761
- const ni = {
1777
+ const ri = {
1762
1778
  fear: "fear",
1763
1779
  afraid: "fear",
1764
1780
  anxiety: "fear",
@@ -1783,48 +1799,48 @@ const ni = {
1783
1799
  };
1784
1800
  function Ge(e, t = "neutral") {
1785
1801
  const n = String(e ?? "").trim().toLowerCase();
1786
- return n ? ni[n] ?? t : t;
1802
+ return n ? ri[n] ?? t : t;
1787
1803
  }
1788
- function ar(e) {
1804
+ function or(e) {
1789
1805
  return e === 0 ? null : en(rn(e), "eyes_standard");
1790
1806
  }
1791
- function or(e) {
1792
- return ar(sn(e));
1807
+ function cr(e) {
1808
+ return or(sn(e));
1793
1809
  }
1794
- function Dn(e, t) {
1810
+ function xn(e, t) {
1795
1811
  const n = rn(sn(e));
1796
- return !t || t === "eyes_standard" ? or(e) : e === "neutral" && t === "eyes_standard" ? null : en(n, t);
1812
+ return !t || t === "eyes_standard" ? cr(e) : e === "neutral" && t === "eyes_standard" ? null : en(n, t);
1797
1813
  }
1798
- function ri(e, t) {
1814
+ function si(e, t) {
1799
1815
  const n = [];
1800
1816
  for (const r of t)
1801
- n.push(Dn(e, r));
1817
+ n.push(xn(e, r));
1802
1818
  for (let r = t.length - 2; r >= 0; r--)
1803
- n.push(Dn(e, t[r]));
1804
- return n.push(or(e)), n;
1819
+ n.push(xn(e, t[r]));
1820
+ return n.push(cr(e)), n;
1805
1821
  }
1806
- function si(e) {
1822
+ function ii(e) {
1807
1823
  return e === 0 ? null : en(rn(e), "eyes_standard");
1808
1824
  }
1809
- function ii(e, t) {
1810
- return ti(e, t).map(si).filter((n) => n != null);
1825
+ function ai(e, t) {
1826
+ return ni(e, t).map(ii).filter((n) => n != null);
1811
1827
  }
1812
- const ai = 6;
1813
- function oi(e, t) {
1828
+ const oi = 6;
1829
+ function ci(e, t) {
1814
1830
  for (const n of e)
1815
1831
  if (t >= n.wtime && t < n.wtime + n.wduration)
1816
1832
  return n;
1817
1833
  return null;
1818
1834
  }
1819
- function ci(e) {
1835
+ function ui(e) {
1820
1836
  const t = Oe(e);
1821
- return t >= $t ? $t : Oe(t + ai);
1837
+ return t >= $t ? $t : Oe(t + oi);
1822
1838
  }
1823
- function ui(e, t, n) {
1839
+ function li(e, t, n) {
1824
1840
  const r = Oe(n);
1825
- return oi(t, e)?.emphasis ? ci(r) : r;
1841
+ return ci(t, e)?.emphasis ? ui(r) : r;
1826
1842
  }
1827
- function xn(e) {
1843
+ function Bn(e) {
1828
1844
  if (!e) return 0;
1829
1845
  const t = e.match(/^brow_(-?\d+)\//);
1830
1846
  if (!t?.[1]) return null;
@@ -1837,7 +1853,7 @@ function ct(e, t) {
1837
1853
  function St() {
1838
1854
  return ct(14, 32);
1839
1855
  }
1840
- function li(e = {}) {
1856
+ function fi(e = {}) {
1841
1857
  const {
1842
1858
  initialDelayMs: t = 800 + Math.random() * 1200,
1843
1859
  intervalMinMs: n = 2200,
@@ -1846,10 +1862,10 @@ function li(e = {}) {
1846
1862
  doubleBlinkGapMinMs: i = 120,
1847
1863
  doubleBlinkGapMaxMs: a = 220,
1848
1864
  fullBlinkChance: o = 0.75,
1849
- postEmotionChangeDelayMs: f = 380,
1850
- minDwellMs: d = 550
1865
+ postEmotionChangeDelayMs: d = 380,
1866
+ minDwellMs: f = 550
1851
1867
  } = e;
1852
- let u = "neutral", c = "neutral", m = 0, w = 0, b = 0, h = {
1868
+ let u = "neutral", c = "neutral", m = 0, w = 0, v = 0, h = {
1853
1869
  kind: "idle",
1854
1870
  nextBlinkAt: performance.now() + t
1855
1871
  }, I = null, E = "__eyes_open__|neutral|brow:0";
@@ -1858,21 +1874,21 @@ function li(e = {}) {
1858
1874
  }
1859
1875
  function p(S, M = u) {
1860
1876
  I = S;
1861
- const T = xn(S);
1877
+ const T = Bn(S);
1862
1878
  T != null ? w = T : S == null && (w = 0), _(M);
1863
1879
  }
1864
- function v(S) {
1865
- return ar(S);
1880
+ function b(S) {
1881
+ return or(S);
1866
1882
  }
1867
1883
  function N(S, M, T) {
1868
1884
  const Z = Oe(M), D = Oe(T);
1869
1885
  if (m = D, Z === D) {
1870
- p(v(D));
1886
+ p(b(D));
1871
1887
  return;
1872
1888
  }
1873
1889
  const X = [
1874
- ...ii(Z, D),
1875
- v(D)
1890
+ ...ai(Z, D),
1891
+ b(D)
1876
1892
  ];
1877
1893
  h = {
1878
1894
  kind: "browBlend",
@@ -1886,13 +1902,13 @@ function li(e = {}) {
1886
1902
  h = {
1887
1903
  kind: "idle",
1888
1904
  nextBlinkAt: S + ct(n, r)
1889
- }, c = M, p(v(m), M);
1905
+ }, c = M, p(b(m), M);
1890
1906
  }
1891
1907
  function j(S, M, T) {
1892
- const Z = T ? Xs : Math.random() < o ? Js : Qs;
1908
+ const Z = T ? Qs : Math.random() < o ? Xs : Zs;
1893
1909
  h = {
1894
1910
  kind: "playing",
1895
- paths: ri(M, Z),
1911
+ paths: si(M, Z),
1896
1912
  index: 0,
1897
1913
  holdUntil: S + St(),
1898
1914
  after: "idle",
@@ -1904,18 +1920,18 @@ function li(e = {}) {
1904
1920
  for (; S >= h.holdUntil && h.index < h.paths.length - 1; )
1905
1921
  h.index += 1, h.holdUntil = S + St();
1906
1922
  const M = h.paths[h.index] ?? null;
1907
- p(M), S >= h.holdUntil && h.index >= h.paths.length - 1 && (w = h.targetBrow, m = h.targetBrow, p(v(h.targetBrow)), h = {
1923
+ p(M), S >= h.holdUntil && h.index >= h.paths.length - 1 && (w = h.targetBrow, m = h.targetBrow, p(b(h.targetBrow)), h = {
1908
1924
  kind: "idle",
1909
- nextBlinkAt: S + f
1925
+ nextBlinkAt: S + d
1910
1926
  });
1911
1927
  return;
1912
1928
  }
1913
1929
  if (h.kind === "idle") {
1914
- p(v(m), c), S >= h.nextBlinkAt && j(S, c, !1);
1930
+ p(b(m), c), S >= h.nextBlinkAt && j(S, c, !1);
1915
1931
  return;
1916
1932
  }
1917
1933
  if (h.kind === "doublePause") {
1918
- p(v(m), h.blinkEmotion), S >= h.resumeAt && j(S, h.blinkEmotion, !0);
1934
+ p(b(m), h.blinkEmotion), S >= h.resumeAt && j(S, h.blinkEmotion, !0);
1919
1935
  return;
1920
1936
  }
1921
1937
  if (h.kind === "playing") {
@@ -1923,7 +1939,7 @@ function li(e = {}) {
1923
1939
  h.index += 1, h.holdUntil = S + St();
1924
1940
  if (p(h.paths[h.index] ?? null, h.blinkEmotion), S >= h.holdUntil && h.index >= h.paths.length - 1) {
1925
1941
  if (h.after === "resumeIdle") {
1926
- F(S + f, u);
1942
+ F(S + d, u);
1927
1943
  return;
1928
1944
  }
1929
1945
  if (h.after === "doublePause") {
@@ -1931,7 +1947,7 @@ function li(e = {}) {
1931
1947
  kind: "doublePause",
1932
1948
  resumeAt: S + ct(i, a),
1933
1949
  blinkEmotion: h.blinkEmotion
1934
- }, p(v(m), h.blinkEmotion);
1950
+ }, p(b(m), h.blinkEmotion);
1935
1951
  return;
1936
1952
  }
1937
1953
  if (h.after === "idle" && Math.random() < s) {
@@ -1939,7 +1955,7 @@ function li(e = {}) {
1939
1955
  kind: "doublePause",
1940
1956
  resumeAt: S + ct(i, a),
1941
1957
  blinkEmotion: h.blinkEmotion
1942
- }, p(v(m), h.blinkEmotion);
1958
+ }, p(b(m), h.blinkEmotion);
1943
1959
  return;
1944
1960
  }
1945
1961
  F(S, h.blinkEmotion);
@@ -1952,12 +1968,12 @@ function li(e = {}) {
1952
1968
  const M = Ge(S, u);
1953
1969
  if (M === u) return;
1954
1970
  const T = performance.now();
1955
- d > 0 && M !== u && !(u === "neutral" && M !== "neutral") && T - b < d || (u = M, c = M, b = T);
1971
+ f > 0 && M !== u && !(u === "neutral" && M !== "neutral") && T - v < f || (u = M, c = M, v = T);
1956
1972
  },
1957
1973
  setTargetEyebrow(S) {
1958
1974
  const M = Oe(S);
1959
1975
  if (M === m) return;
1960
- const T = performance.now(), Z = h.kind === "browBlend" ? xn(I) ?? w : w;
1976
+ const T = performance.now(), Z = h.kind === "browBlend" ? Bn(I) ?? w : w;
1961
1977
  m = M, !(M === Z && h.kind !== "browBlend") && (h.kind === "playing" || h.kind === "doublePause" || N(T, Z, M));
1962
1978
  },
1963
1979
  getTargetEmotion: () => u,
@@ -1965,14 +1981,14 @@ function li(e = {}) {
1965
1981
  getExpressionPath: () => I,
1966
1982
  getDrawKey: () => E,
1967
1983
  reset() {
1968
- u = "neutral", c = "neutral", m = 0, w = 0, b = 0, F(
1984
+ u = "neutral", c = "neutral", m = 0, w = 0, v = 0, F(
1969
1985
  performance.now() + ct(n, r),
1970
1986
  "neutral"
1971
1987
  );
1972
1988
  }
1973
1989
  };
1974
1990
  }
1975
- function fi() {
1991
+ function di() {
1976
1992
  const e = document.createElement("video");
1977
1993
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1978
1994
  let t = !1, n = null, r = "";
@@ -1982,15 +1998,15 @@ function fi() {
1982
1998
  return {
1983
1999
  async load(i) {
1984
2000
  t && r === i || (s(), t = !1, r = i, i.startsWith("blob:") && (n = i), await new Promise((a, o) => {
1985
- const f = () => {
1986
- const d = e.duration;
1987
- if (!Number.isFinite(d) || d <= 0) {
2001
+ const d = () => {
2002
+ const f = e.duration;
2003
+ if (!Number.isFinite(f) || f <= 0) {
1988
2004
  o(new Error(`Idle video has invalid duration: ${i}`));
1989
2005
  return;
1990
2006
  }
1991
2007
  t = !0, e.currentTime = 0, a();
1992
2008
  };
1993
- e.addEventListener("loadeddata", f, { once: !0 }), e.addEventListener(
2009
+ e.addEventListener("loadeddata", d, { once: !0 }), e.addEventListener(
1994
2010
  "error",
1995
2011
  () => o(new Error(`Failed to load idle video: ${i}`)),
1996
2012
  { once: !0 }
@@ -2015,17 +2031,17 @@ function fi() {
2015
2031
  }
2016
2032
  };
2017
2033
  }
2018
- const di = 50, cr = 400;
2019
- function mi(e, t, n) {
2034
+ const mi = 50, ur = 400;
2035
+ function hi(e, t, n) {
2020
2036
  return e.filter((r) => {
2021
2037
  const s = r.queueIndex ?? -1;
2022
2038
  return s >= t && s <= n;
2023
2039
  });
2024
2040
  }
2025
- function hi(e, t) {
2041
+ function pi(e, t) {
2026
2042
  const n = [];
2027
2043
  for (const r of e) {
2028
- const s = mi(
2044
+ const s = hi(
2029
2045
  t,
2030
2046
  r.start_word,
2031
2047
  r.end_word
@@ -2034,52 +2050,52 @@ function hi(e, t) {
2034
2050
  const i = s[0], a = s[s.length - 1];
2035
2051
  n.push({
2036
2052
  sentence: r,
2037
- startMs: Math.max(0, i.wtime - di),
2038
- endMs: a.wtime + a.wduration + cr
2053
+ startMs: Math.max(0, i.wtime - mi),
2054
+ endMs: a.wtime + a.wduration + ur
2039
2055
  });
2040
2056
  }
2041
2057
  return n.sort((r, s) => r.startMs - s.startMs);
2042
2058
  }
2043
- function pi(e, t, n, r = "neutral") {
2059
+ function wi(e, t, n, r = "neutral") {
2044
2060
  const s = Ge(r);
2045
2061
  if (t.length === 0) return s;
2046
2062
  if (n.length === 0 || e < n[0].wtime)
2047
2063
  return Ge(t[0]?.emotion, s);
2048
- const i = hi(t, n);
2064
+ const i = pi(t, n);
2049
2065
  let a = null;
2050
- for (const d of i)
2051
- e >= d.startMs && e <= d.endMs && (a = d);
2066
+ for (const f of i)
2067
+ e >= f.startMs && e <= f.endMs && (a = f);
2052
2068
  if (a)
2053
2069
  return Ge(a.sentence.emotion, s);
2054
- const o = n[n.length - 1], f = o.wtime + o.wduration;
2055
- return e > f + cr ? Ge(
2070
+ const o = n[n.length - 1], d = o.wtime + o.wduration;
2071
+ return e > d + ur ? Ge(
2056
2072
  t[t.length - 1]?.emotion,
2057
2073
  s
2058
2074
  ) : s;
2059
2075
  }
2060
- function an(e, t, n, r, s = rr) {
2076
+ function an(e, t, n, r, s = sr) {
2061
2077
  const i = new OffscreenCanvas(n, r), a = i.getContext("2d", { willReadFrequently: !0 });
2062
2078
  a.drawImage(e, 0, 0, n, r);
2063
- const o = a.getImageData(0, 0, n, r), f = a.createImageData(n, r);
2064
- f.data.set(o.data);
2079
+ const o = a.getImageData(0, 0, n, r), d = a.createImageData(n, r);
2080
+ d.data.set(o.data);
2065
2081
  const u = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
2066
2082
  for (const c of t) {
2067
2083
  u.clearRect(0, 0, n, r), u.drawImage(c, 0, 0, n, r);
2068
2084
  const m = u.getImageData(0, 0, n, r);
2069
- for (let w = 0; w < f.data.length; w += 4) {
2070
- const b = m.data[w], h = m.data[w + 1], I = m.data[w + 2];
2071
- Math.max(b, h, I) > s && (f.data[w] = b, f.data[w + 1] = h, f.data[w + 2] = I, f.data[w + 3] = 255);
2085
+ for (let w = 0; w < d.data.length; w += 4) {
2086
+ const v = m.data[w], h = m.data[w + 1], I = m.data[w + 2];
2087
+ Math.max(v, h, I) > s && (d.data[w] = v, d.data[w + 1] = h, d.data[w + 2] = I, d.data[w + 3] = 255);
2072
2088
  }
2073
2089
  }
2074
- return a.putImageData(f, 0, 0), i;
2090
+ return a.putImageData(d, 0, 0), i;
2075
2091
  }
2076
2092
  let Le = null, Ye = null;
2077
2093
  const Et = /* @__PURE__ */ new Map();
2078
- function wi() {
2094
+ function gi() {
2079
2095
  Le = null, Ye = null, Et.clear();
2080
2096
  }
2081
- Xr(wi);
2082
- function gi(e) {
2097
+ Qr(gi);
2098
+ function yi(e) {
2083
2099
  return e ?? Ye ?? void 0;
2084
2100
  }
2085
2101
  function on(e) {
@@ -2088,32 +2104,32 @@ function on(e) {
2088
2104
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
2089
2105
  });
2090
2106
  }
2091
- async function yi(e) {
2092
- return It() ? Vs(
2093
- await Rt(vn(), e ?? "")
2094
- ) : on(vn());
2107
+ async function _i(e) {
2108
+ return It() ? Ws(
2109
+ await Rt(bn(), e ?? "")
2110
+ ) : on(bn());
2095
2111
  }
2096
- async function Bn(e, t, n, r) {
2097
- const s = n ? await Ns(e, r) : await fetch(e).then((d) => {
2098
- if (!d.ok) throw new Error(`Failed to load ${e}`);
2099
- return d.json();
2112
+ async function Cn(e, t, n, r) {
2113
+ const s = n ? await Us(e, r) : await fetch(e).then((f) => {
2114
+ if (!f.ok) throw new Error(`Failed to load ${e}`);
2115
+ return f.json();
2100
2116
  }), i = s.sheets?.[0];
2101
2117
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
2102
- const a = n ? await Us(
2118
+ const a = n ? await Vs(
2103
2119
  await Rt(
2104
- zs(t, i.path, n),
2120
+ Ys(t, i.path, n),
2105
2121
  r ?? ""
2106
2122
  )
2107
2123
  ) : await on(`${t}/${i.path}`), o = /* @__PURE__ */ new Map();
2108
- for (const d of s.cells ?? [])
2109
- d.path && o.set(d.path, d);
2110
- const f = /* @__PURE__ */ new Map();
2111
- for (const d of s.sheets ?? [])
2112
- f.set(d.index, d);
2113
- return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex: f, diffBase: t };
2124
+ for (const f of s.cells ?? [])
2125
+ f.path && o.set(f.path, f);
2126
+ const d = /* @__PURE__ */ new Map();
2127
+ for (const f of s.sheets ?? [])
2128
+ d.set(f.index, f);
2129
+ return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex: d, diffBase: t };
2114
2130
  }
2115
2131
  async function qt(e) {
2116
- const t = gi(e), n = It();
2132
+ const t = yi(e), n = It();
2117
2133
  if (n && !t)
2118
2134
  throw new Error("Encrypted assets enabled but no key provided");
2119
2135
  if (Le && (!n || Ye === (t ?? null))) {
@@ -2124,18 +2140,18 @@ async function qt(e) {
2124
2140
  };
2125
2141
  }
2126
2142
  Ye = t ?? null, Et.clear();
2127
- const r = Zr();
2143
+ const r = es();
2128
2144
  Le = (async () => {
2129
- const i = await yi(t), a = await Bn(
2130
- es(),
2145
+ const i = await _i(t), a = await Cn(
2146
+ ts(),
2131
2147
  r,
2132
2148
  n,
2133
2149
  t
2134
2150
  );
2135
2151
  let o = null;
2136
2152
  try {
2137
- o = await Bn(
2138
- ts(),
2153
+ o = await Cn(
2154
+ ns(),
2139
2155
  r,
2140
2156
  n,
2141
2157
  t
@@ -2153,13 +2169,13 @@ async function cn(e) {
2153
2169
  return Le;
2154
2170
  }
2155
2171
  function Je(e) {
2156
- return Fs(
2172
+ return Ls(
2157
2173
  e.viseme.atlasMeta,
2158
2174
  e.sil.naturalWidth,
2159
2175
  e.sil.naturalHeight
2160
2176
  );
2161
2177
  }
2162
- function _i(e, t) {
2178
+ function Si(e, t) {
2163
2179
  const n = document.createElement("canvas");
2164
2180
  return n.width = t.w, n.height = t.h, n.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), n;
2165
2181
  }
@@ -2169,47 +2185,47 @@ async function Tt(e, t, n) {
2169
2185
  const i = (async () => {
2170
2186
  const a = t.cellByPath.get(n);
2171
2187
  if (!a) throw new Error(`No atlas cell for path: ${n}`);
2172
- const o = Ls(t.atlasMeta, a), f = Je(e);
2173
- if (Os(a)) {
2174
- const c = _i(t, a), m = document.createElement("canvas");
2175
- m.width = f.width, m.height = f.height;
2188
+ const o = Os(t.atlasMeta, a), d = Je(e);
2189
+ if (Ns(a)) {
2190
+ const c = Si(t, a), m = document.createElement("canvas");
2191
+ m.width = d.width, m.height = d.height;
2176
2192
  const w = m.getContext("2d");
2177
- return w.fillStyle = "#000", w.fillRect(0, 0, f.width, f.height), w.drawImage(c, o.x, o.y), m;
2193
+ return w.fillStyle = "#000", w.fillRect(0, 0, d.width, d.height), w.drawImage(c, o.x, o.y), m;
2178
2194
  }
2179
- const d = `${t.diffBase}/${n}`, u = await on(d);
2180
- if (u.naturalWidth === f.width && u.naturalHeight === f.height)
2195
+ const f = `${t.diffBase}/${n}`, u = await on(f);
2196
+ if (u.naturalWidth === d.width && u.naturalHeight === d.height)
2181
2197
  return u;
2182
2198
  throw new Error(`Diff PNG wrong size for ${n}`);
2183
2199
  })();
2184
2200
  return Et.set(r, i), i;
2185
2201
  }
2186
- async function Cn(e, t, n, r, s, i) {
2202
+ async function Fn(e, t, n, r, s, i) {
2187
2203
  if (s) {
2188
- const { width: w, height: b } = s;
2204
+ const { width: w, height: v } = s;
2189
2205
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
2190
2206
  return;
2191
2207
  const h = document.createElement("canvas");
2192
- h.width = w, h.height = b;
2208
+ h.width = w, h.height = v;
2193
2209
  const I = h.getContext("2d");
2194
- if (I.clearRect(0, 0, w, b), I.drawImage(t, 0, 0, w, b), i && !i()) return;
2195
- (e.width !== w || e.height !== b) && (e.width = w, e.height = b);
2210
+ if (I.clearRect(0, 0, w, v), I.drawImage(t, 0, 0, w, v), i && !i()) return;
2211
+ (e.width !== w || e.height !== v) && (e.width = w, e.height = v);
2196
2212
  const E = e.getContext("2d");
2197
- E.clearRect(0, 0, w, b), E.drawImage(h, 0, 0);
2213
+ E.clearRect(0, 0, w, v), E.drawImage(h, 0, 0);
2198
2214
  return;
2199
2215
  }
2200
- const a = await cn(), o = tn(a.viseme.atlasMeta), { width: f, height: d } = Je(a);
2201
- (e.width !== f || e.height !== d) && (e.width = f, e.height = d);
2216
+ const a = await cn(), o = tn(a.viseme.atlasMeta), { width: d, height: f } = Je(a);
2217
+ (e.width !== d || e.height !== f) && (e.width = d, e.height = f);
2202
2218
  const u = [], c = e.getContext("2d");
2203
- if (c.clearRect(0, 0, f, d), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
2219
+ if (c.clearRect(0, 0, d, f), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
2204
2220
  const w = a.sil;
2205
- c.drawImage(w, 0, 0, f, d);
2221
+ c.drawImage(w, 0, 0, d, f);
2206
2222
  return;
2207
2223
  }
2208
2224
  if (u.length === 0) {
2209
- c.drawImage(t, 0, 0, f, d);
2225
+ c.drawImage(t, 0, 0, d, f);
2210
2226
  return;
2211
2227
  }
2212
- const m = an(t, u, f, d, o);
2228
+ const m = an(t, u, d, f, o);
2213
2229
  c.drawImage(m, 0, 0);
2214
2230
  }
2215
2231
  async function Kt(e, t, n) {
@@ -2217,61 +2233,61 @@ async function Kt(e, t, n) {
2217
2233
  (e.width !== i || e.height !== a) && (e.width = i, e.height = a);
2218
2234
  const o = [];
2219
2235
  if (t.mouthPath) {
2220
- const u = new Set(r.viseme.cellByPath.keys()), c = sr(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
2236
+ const u = new Set(r.viseme.cellByPath.keys()), c = ir(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
2221
2237
  c && o.push(await Tt(r, r.viseme, c));
2222
2238
  }
2223
2239
  t.expressionPath && r.expression && o.push(
2224
2240
  await Tt(r, r.expression, t.expressionPath)
2225
2241
  );
2226
- const f = e.getContext("2d");
2227
- if (f.clearRect(0, 0, i, a), o.length === 0) {
2228
- f.drawImage(r.sil, 0, 0, i, a);
2242
+ const d = e.getContext("2d");
2243
+ if (d.clearRect(0, 0, i, a), o.length === 0) {
2244
+ d.drawImage(r.sil, 0, 0, i, a);
2229
2245
  return;
2230
2246
  }
2231
- const d = an(
2247
+ const f = an(
2232
2248
  r.sil,
2233
2249
  o,
2234
2250
  i,
2235
2251
  a,
2236
2252
  s
2237
2253
  );
2238
- f.drawImage(d, 0, 0);
2254
+ d.drawImage(f, 0, 0);
2239
2255
  }
2240
- async function Si(e, t) {
2256
+ async function ki(e, t) {
2241
2257
  const n = await cn(Ye ?? void 0), r = tn(n.viseme.atlasMeta), { width: s, height: i } = Je(n), a = [];
2242
2258
  if (e.mouthPath) {
2243
- const u = new Set(n.viseme.cellByPath.keys()), c = sr(e.mouthPath, u) ?? (u.has(e.mouthPath) ? e.mouthPath : null);
2259
+ const u = new Set(n.viseme.cellByPath.keys()), c = ir(e.mouthPath, u) ?? (u.has(e.mouthPath) ? e.mouthPath : null);
2244
2260
  c && a.push(await Tt(n, n.viseme, c));
2245
2261
  }
2246
2262
  e.expressionPath && n.expression && a.push(
2247
2263
  await Tt(n, n.expression, e.expressionPath)
2248
2264
  );
2249
- const o = new OffscreenCanvas(s, i), f = o.getContext("2d");
2265
+ const o = new OffscreenCanvas(s, i), d = o.getContext("2d");
2250
2266
  if (a.length === 0)
2251
- return f.drawImage(n.sil, 0, 0, s, i), o.transferToImageBitmap();
2252
- const d = an(
2267
+ return d.drawImage(n.sil, 0, 0, s, i), o.transferToImageBitmap();
2268
+ const f = an(
2253
2269
  n.sil,
2254
2270
  a,
2255
2271
  s,
2256
2272
  i,
2257
2273
  r
2258
2274
  );
2259
- return f.drawImage(d, 0, 0), o.transferToImageBitmap();
2275
+ return d.drawImage(f, 0, 0), o.transferToImageBitmap();
2260
2276
  }
2261
- async function ki(e) {
2277
+ async function vi(e) {
2262
2278
  await Kt(e, { mouthPath: null, expressionPath: null });
2263
2279
  }
2264
- let ur = null;
2265
- function Fn(e) {
2266
- ur = e;
2280
+ let lr = null;
2281
+ function Ln(e) {
2282
+ lr = e;
2267
2283
  }
2268
2284
  function Ne() {
2269
- return ur;
2285
+ return lr;
2270
2286
  }
2271
2287
  function bi(e) {
2272
2288
  return `${e.from}→${e.to}@${e.fromVtime}`;
2273
2289
  }
2274
- function Ln() {
2290
+ function On() {
2275
2291
  return {
2276
2292
  rafTicksSpeaking: 0,
2277
2293
  rafTicksDeduped: 0,
@@ -2289,15 +2305,15 @@ function Ln() {
2289
2305
  bufferPrefetched: 0
2290
2306
  };
2291
2307
  }
2292
- function vi() {
2293
- let e = Ln();
2308
+ function Ei() {
2309
+ let e = On();
2294
2310
  const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
2295
2311
  let s = "", i = -1, a = "";
2296
2312
  const o = () => {
2297
- e = Ln(), t.clear(), n.clear(), r.clear(), s = "", i = -1, a = "";
2298
- }, f = (u) => {
2299
- t.add(u);
2313
+ e = On(), t.clear(), n.clear(), r.clear(), s = "", i = -1, a = "";
2300
2314
  }, d = (u) => {
2315
+ t.add(u);
2316
+ }, f = (u) => {
2301
2317
  u && r.add(u);
2302
2318
  };
2303
2319
  return {
@@ -2339,7 +2355,7 @@ function vi() {
2339
2355
  if (e.drawsDisplayed += 1, u.transitionMeta) {
2340
2356
  e.transitionFramesDisplayed += 1;
2341
2357
  const w = u.transitionMeta;
2342
- f(w.fromVtime), f(w.toVtime), d(u.mouthPath);
2358
+ d(w.fromVtime), d(w.toVtime), f(u.mouthPath);
2343
2359
  return;
2344
2360
  }
2345
2361
  if (u.label.includes("→")) {
@@ -2350,7 +2366,7 @@ function vi() {
2350
2366
  if (!(!m || m === "sil")) {
2351
2367
  for (const w of c)
2352
2368
  if (w.viseme === m && u.elapsedMs >= w.vtime && u.elapsedMs < w.vtime + w.vduration) {
2353
- f(w.vtime);
2369
+ d(w.vtime);
2354
2370
  break;
2355
2371
  }
2356
2372
  }
@@ -2362,14 +2378,14 @@ function vi() {
2362
2378
  if (_.vtime >= c) break;
2363
2379
  m += 1, t.has(_.vtime) && (w += 1);
2364
2380
  }
2365
- const b = m > 0 ? Math.round(w / m * 100) : 100, h = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), I = m - w, E = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
2381
+ const v = m > 0 ? Math.round(w / m * 100) : 100, h = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), I = m - w, E = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
2366
2382
  return {
2367
2383
  ...e,
2368
2384
  bufferHitRate: E,
2369
2385
  renderLoss: h,
2370
2386
  visemeSlotsTotal: m,
2371
2387
  visemeSlotsCovered: w,
2372
- visemeCoveragePct: b,
2388
+ visemeCoveragePct: v,
2373
2389
  transitionFramesUniqueSampled: n.size,
2374
2390
  transitionFramesUniquePainted: r.size,
2375
2391
  drawsDeduped: e.rafTicksDeduped,
@@ -2381,9 +2397,9 @@ function vi() {
2381
2397
  }
2382
2398
  };
2383
2399
  }
2384
- const lr = zt, Ei = 200, Ti = 100, Ai = 600, fr = "__sil__";
2385
- function Ii(e) {
2386
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === fr : !1;
2400
+ const fr = zt, Ti = 200, Ai = 100, Ii = 600, dr = "__sil__";
2401
+ function Mi(e) {
2402
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === dr : !1;
2387
2403
  }
2388
2404
  function un() {
2389
2405
  return { lastDrawnKey: "" };
@@ -2391,50 +2407,55 @@ function un() {
2391
2407
  function ke(e) {
2392
2408
  e.lastDrawnKey = "", e.transitionCache = void 0;
2393
2409
  }
2394
- function Mi(e, t) {
2410
+ function Pi(e, t) {
2395
2411
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
2396
2412
  return t.transitionCache.transitions;
2397
- const n = gs(e);
2413
+ const n = ys(e);
2398
2414
  return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
2399
2415
  }
2400
- function Pi(e, t) {
2416
+ function Ri(e, t) {
2401
2417
  let n = "sil";
2402
2418
  for (const r of e)
2403
2419
  r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
2404
2420
  return n;
2405
2421
  }
2406
- function Ri(e, t, n, r = 120) {
2422
+ function Di(e, t, n, r = 120) {
2407
2423
  if (n !== "sil")
2408
2424
  return n;
2409
- const s = Qn(e, t, r);
2410
- return s !== "sil" ? s : Pi(e, t);
2425
+ const s = Zn(e, t, r);
2426
+ return s !== "sil" ? s : Ri(e, t);
2411
2427
  }
2412
- function Di(e, t) {
2413
- return e === "sil" ? !1 : t ? qs(e, "sil", t) : nn(e, "sil").length > 0;
2428
+ function xi(e, t) {
2429
+ return e === "sil" ? !1 : t ? Ks(e, "sil", t) : nn(e, "sil").length > 0;
2414
2430
  }
2415
- function xi() {
2416
- return lr + Ai;
2431
+ function Bi() {
2432
+ return fr + Ii;
2417
2433
  }
2418
2434
  function At(e) {
2419
- return e ?? fr;
2435
+ return e ?? dr;
2420
2436
  }
2421
- function ln(e, t, n, r, s = Ti) {
2437
+ function ln(e, t, n, r, s = Ai) {
2422
2438
  if (e.length === 0)
2423
2439
  return { diffPath: null, label: "sil" };
2424
2440
  if (t >= Fe(e))
2425
2441
  return { diffPath: null, label: "sil" };
2426
- const i = Mi(e, r), a = ys(i, t);
2442
+ const i = Pi(e, r), a = _s(i, t);
2427
2443
  if (a) {
2428
- const f = Yn(a.fromVtime, a.toVtime);
2429
- if (t >= f.transStart && t < f.transEnd) {
2430
- let d = nn(a.from, a.to);
2431
- n && (d = ir(d, n));
2432
- const u = Gs(d, f.effectiveGapMs);
2444
+ const d = Jn(
2445
+ a.fromVtime,
2446
+ a.toVtime,
2447
+ a.from,
2448
+ a.to
2449
+ );
2450
+ if (t >= d.transStart && t < d.transEnd) {
2451
+ let f = nn(a.from, a.to);
2452
+ n && (f = ar(f, n));
2453
+ const u = js(f, d.effectiveGapMs);
2433
2454
  if (u.length > 0) {
2434
- const c = js(
2455
+ const c = zs(
2435
2456
  t,
2436
- f.transStart,
2437
- f.transEnd,
2457
+ d.transStart,
2458
+ d.transEnd,
2438
2459
  u.length
2439
2460
  );
2440
2461
  return {
@@ -2447,23 +2468,23 @@ function ln(e, t, n, r, s = Ti) {
2447
2468
  toVtime: a.toVtime,
2448
2469
  frameIdx: c,
2449
2470
  frameCount: u.length,
2450
- fullFrameCount: d.length,
2451
- omittedByGap: Math.max(0, d.length - u.length)
2471
+ fullFrameCount: f.length,
2472
+ omittedByGap: Math.max(0, f.length - u.length)
2452
2473
  }
2453
2474
  };
2454
2475
  }
2455
- return { diffPath: vt(a.to), label: a.to };
2476
+ return { diffPath: bt(a.to), label: a.to };
2456
2477
  }
2457
2478
  }
2458
- const o = Qn(e, t, s);
2459
- return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: vt(o), label: o };
2479
+ const o = Zn(e, t, s);
2480
+ return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: bt(o), label: o };
2460
2481
  }
2461
2482
  function fn(e, t) {
2462
2483
  const n = t ?? At(e.expressionPath);
2463
2484
  return `${At(e.mouthPath)}|${n}`;
2464
2485
  }
2465
- function Bi(e, t, n, r, s, i, a, o, f, d) {
2466
- const u = ln(t, n, f, i), c = {
2486
+ function Ci(e, t, n, r, s, i, a, o, d, f) {
2487
+ const u = ln(t, n, d, i), c = {
2467
2488
  mouthPath: u.diffPath,
2468
2489
  expressionPath: r
2469
2490
  }, m = fn(c, s), w = Ne();
@@ -2471,31 +2492,31 @@ function Bi(e, t, n, r, s, i, a, o, f, d) {
2471
2492
  w?.onDrawDeduped();
2472
2493
  return;
2473
2494
  }
2474
- w?.onDrawRequested(), o(u), i.lastDrawnKey = m, a(e, c, m, (b) => {
2475
- b === m && (i.lastDrawnKey = m);
2495
+ w?.onDrawRequested(), o(u), i.lastDrawnKey = m, a(e, c, m, (v) => {
2496
+ v === m && (i.lastDrawnKey = m);
2476
2497
  });
2477
2498
  }
2478
- function On(e, t, n, r, s, i, a = null) {
2479
- const o = { mouthPath: null, expressionPath: t }, f = a != null ? `|idle@${Math.round(a * 1e3)}` : "", d = fn(o, n) + f;
2480
- !(a != null) && d === r.lastDrawnKey || (i(
2499
+ function Nn(e, t, n, r, s, i, a = null) {
2500
+ const o = { mouthPath: null, expressionPath: t }, d = a != null ? `|idle@${Math.round(a * 1e3)}` : "", f = fn(o, n) + d;
2501
+ !(a != null) && f === r.lastDrawnKey || (i(
2481
2502
  a != null ? "idle" : "sil"
2482
- ), s(e, o, d, (c) => {
2483
- c === d && (r.lastDrawnKey = d);
2503
+ ), s(e, o, f, (c) => {
2504
+ c === f && (r.lastDrawnKey = f);
2484
2505
  }));
2485
2506
  }
2486
- function dr(e, t, n, r, s = ut, i) {
2507
+ function mr(e, t, n, r, s = ut, i) {
2487
2508
  if (n <= t || e.length === 0) return [];
2488
2509
  const a = i ?? un(), o = [];
2489
- let f = "";
2490
- for (let d = t; d < n; d += s) {
2510
+ let d = "";
2511
+ for (let f = t; f < n; f += s) {
2491
2512
  const u = ln(
2492
2513
  e,
2493
- d,
2514
+ f,
2494
2515
  r,
2495
2516
  a
2496
2517
  ), c = At(u.diffPath);
2497
- c !== f && (f = c, o.push({
2498
- displayAtMs: d,
2518
+ c !== d && (d = c, o.push({
2519
+ displayAtMs: f,
2499
2520
  mouthPath: u.diffPath,
2500
2521
  mouthKey: c,
2501
2522
  label: u.label
@@ -2503,8 +2524,8 @@ function dr(e, t, n, r, s = ut, i) {
2503
2524
  }
2504
2525
  return o;
2505
2526
  }
2506
- const Ci = 3;
2507
- function mr(e) {
2527
+ const Fi = 3;
2528
+ function hr(e) {
2508
2529
  let t = 0;
2509
2530
  const n = [];
2510
2531
  let r = !1, s = !1;
@@ -2513,8 +2534,8 @@ function mr(e) {
2513
2534
  r = !0;
2514
2535
  try {
2515
2536
  for (; n.length > 0; ) {
2516
- const o = n.shift(), f = ++t;
2517
- await e(o.diffs, f, o) && f === t && o.onDisplayed?.(o.drawKey);
2537
+ const o = n.shift(), d = ++t;
2538
+ await e(o.diffs, d, o) && d === t && o.onDisplayed?.(o.drawKey);
2518
2539
  }
2519
2540
  } finally {
2520
2541
  r = !1, n.length > 0 && i();
@@ -2526,9 +2547,9 @@ function mr(e) {
2526
2547
  }));
2527
2548
  };
2528
2549
  return {
2529
- enqueue(o, f, d) {
2530
- const u = n.findIndex((c) => c.drawKey === f);
2531
- u >= 0 ? n[u] = { diffs: o, drawKey: f, onDisplayed: d } : (n.length >= Ci && (n.shift(), Ne()?.onQueueSuperseded()), n.push({ diffs: o, drawKey: f, onDisplayed: d })), a();
2550
+ enqueue(o, d, f) {
2551
+ const u = n.findIndex((c) => c.drawKey === d);
2552
+ u >= 0 ? n[u] = { diffs: o, drawKey: d, onDisplayed: f } : (n.length >= Fi && (n.shift(), Ne()?.onQueueSuperseded()), n.push({ diffs: o, drawKey: d, onDisplayed: f })), a();
2532
2553
  },
2533
2554
  reset() {
2534
2555
  t += 1, n.length = 0;
@@ -2541,36 +2562,36 @@ function mr(e) {
2541
2562
  }
2542
2563
  };
2543
2564
  }
2544
- function Fi(e, t = 2) {
2565
+ function Li(e, t = 2) {
2545
2566
  const n = [], r = /* @__PURE__ */ new Set();
2546
2567
  let s = 0, i = !1, a = 0;
2547
- const o = (d, u) => `${d}|${u}`, f = async () => {
2568
+ const o = (f, u) => `${f}|${u}`, d = async () => {
2548
2569
  if (!i) {
2549
2570
  i = !0;
2550
2571
  try {
2551
2572
  for (; s < t && n.length > 0; ) {
2552
- const d = n.shift(), u = o(d.displayAtMs, d.drawKey);
2573
+ const f = n.shift(), u = o(f.displayAtMs, f.drawKey);
2553
2574
  if (r.has(u)) continue;
2554
2575
  r.add(u), s += 1;
2555
2576
  const c = a;
2556
2577
  try {
2557
- await e(d);
2578
+ await e(f);
2558
2579
  } finally {
2559
2580
  if (r.delete(u), s -= 1, c !== a) return;
2560
2581
  }
2561
2582
  }
2562
2583
  } finally {
2563
- i = !1, n.length > 0 && s < t && f();
2584
+ i = !1, n.length > 0 && s < t && d();
2564
2585
  }
2565
2586
  }
2566
2587
  };
2567
2588
  return {
2568
- enqueue(d) {
2569
- const u = o(d.displayAtMs, d.drawKey);
2570
- r.has(u) || n.some((c) => o(c.displayAtMs, c.drawKey) === u) || (n.push(d), f());
2589
+ enqueue(f) {
2590
+ const u = o(f.displayAtMs, f.drawKey);
2591
+ r.has(u) || n.some((c) => o(c.displayAtMs, c.drawKey) === u) || (n.push(f), d());
2571
2592
  },
2572
- isQueuedOrInflight(d, u) {
2573
- const c = o(d, u);
2593
+ isQueuedOrInflight(f, u) {
2594
+ const c = o(f, u);
2574
2595
  return r.has(c) ? !0 : n.some(
2575
2596
  (m) => o(m.displayAtMs, m.drawKey) === c
2576
2597
  );
@@ -2583,7 +2604,7 @@ function Fi(e, t = 2) {
2583
2604
  }
2584
2605
  };
2585
2606
  }
2586
- function Li() {
2607
+ function Oi() {
2587
2608
  const e = /* @__PURE__ */ new Map(), t = (n) => {
2588
2609
  n.bitmap.close();
2589
2610
  };
@@ -2618,8 +2639,8 @@ function Li() {
2618
2639
  }
2619
2640
  };
2620
2641
  }
2621
- function Oi(e, t, n, r, s, i) {
2622
- const a = dr(
2642
+ function Ni(e, t, n, r, s, i) {
2643
+ const a = mr(
2623
2644
  t,
2624
2645
  n,
2625
2646
  r,
@@ -2629,14 +2650,14 @@ function Oi(e, t, n, r, s, i) {
2629
2650
  );
2630
2651
  if (a.length === 0) return { ready: 0, total: 0 };
2631
2652
  let o = 0;
2632
- for (const f of a)
2633
- e.has(f.displayAtMs, f.mouthKey) && (o += 1);
2653
+ for (const d of a)
2654
+ e.has(d.displayAtMs, d.mouthKey) && (o += 1);
2634
2655
  return { ready: o, total: a.length };
2635
2656
  }
2636
- function Ni(e) {
2637
- const t = Li(), n = un(), r = /* @__PURE__ */ new Set();
2657
+ function Ui(e) {
2658
+ const t = Oi(), n = un(), r = /* @__PURE__ */ new Set();
2638
2659
  let s = "", i = null;
2639
- const a = Fi(
2660
+ const a = Li(
2640
2661
  async (c) => {
2641
2662
  try {
2642
2663
  if (!e.supportsBufferedPlayback) return;
@@ -2656,7 +2677,7 @@ function Ni(e) {
2656
2677
  r.delete(c.mouthKey);
2657
2678
  }
2658
2679
  },
2659
- Cr
2680
+ Fr
2660
2681
  ), o = (c) => {
2661
2682
  for (const m of c)
2662
2683
  t.has(m.displayAtMs, m.mouthKey) || r.has(m.mouthKey) || a.isQueuedOrInflight(0, m.mouthKey) || (r.add(m.mouthKey), a.enqueue({
@@ -2668,18 +2689,18 @@ function Ni(e) {
2668
2689
  expressionPath: null
2669
2690
  }
2670
2691
  }));
2671
- }, f = (c, m, w, b = Ct) => {
2692
+ }, d = (c, m, w, v = Ct) => {
2672
2693
  if (!e.supportsBufferedPlayback) return;
2673
- const h = Math.max(0, m - ut * 4), I = dr(
2694
+ const h = Math.max(0, m - ut * 4), I = mr(
2674
2695
  c,
2675
2696
  h,
2676
- m + b,
2697
+ m + v,
2677
2698
  w,
2678
2699
  ut,
2679
2700
  n
2680
2701
  );
2681
2702
  o(I);
2682
- }, d = (c, m) => {
2703
+ }, f = (c, m) => {
2683
2704
  s = c, i = m;
2684
2705
  }, u = (c, m) => !(s !== c || i !== m);
2685
2706
  return {
@@ -2687,10 +2708,10 @@ function Ni(e) {
2687
2708
  t.reset(), a.reset(), r.clear(), ke(n), s = "", i = null, Ne()?.onBufferReset();
2688
2709
  },
2689
2710
  markExternallyDisplayed(c, m) {
2690
- d(c.split("|")[0] ?? c, m);
2711
+ f(c.split("|")[0] ?? c, m);
2691
2712
  },
2692
2713
  warmupTick(c) {
2693
- e.supportsBufferedPlayback && f(
2714
+ e.supportsBufferedPlayback && d(
2694
2715
  c.queue,
2695
2716
  0,
2696
2717
  c.availablePaths,
@@ -2699,7 +2720,7 @@ function Ni(e) {
2699
2720
  },
2700
2721
  isWarmupReady(c, m = Sn) {
2701
2722
  if (!e.supportsBufferedPlayback) return !0;
2702
- const { ready: w, total: b } = Oi(
2723
+ const { ready: w, total: v } = Ni(
2703
2724
  t,
2704
2725
  c.queue,
2705
2726
  0,
@@ -2707,12 +2728,12 @@ function Ni(e) {
2707
2728
  c.availablePaths,
2708
2729
  n
2709
2730
  );
2710
- return b === 0 ? !1 : w / b >= Br;
2731
+ return v === 0 ? !1 : w / v >= Cr;
2711
2732
  },
2712
2733
  getBufferedFrameCount: () => t.size(),
2713
2734
  tick(c) {
2714
2735
  const m = Ne();
2715
- m?.onBufferTick(), f(
2736
+ m?.onBufferTick(), d(
2716
2737
  c.queue,
2717
2738
  c.elapsedMs,
2718
2739
  c.availablePaths
@@ -2722,27 +2743,27 @@ function Ni(e) {
2722
2743
  c.elapsedMs,
2723
2744
  c.availablePaths,
2724
2745
  n
2725
- ), b = At(w.diffPath), h = fn(
2746
+ ), v = At(w.diffPath), h = fn(
2726
2747
  { mouthPath: w.diffPath, expressionPath: c.expressionPath },
2727
2748
  c.expressionDrawKey
2728
- ), I = () => (d(b, c.expressionPath), m?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2729
- if (u(b, c.expressionPath) || c.playbackState.lastDrawnKey === h)
2749
+ ), I = () => (f(v, c.expressionPath), m?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2750
+ if (u(v, c.expressionPath) || c.playbackState.lastDrawnKey === h)
2730
2751
  return I();
2731
2752
  const E = t.findForMouthKey(
2732
- b,
2753
+ v,
2733
2754
  c.elapsedMs,
2734
2755
  ut
2735
2756
  );
2736
- return E && c.expressionPath != null ? (m?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : E ? (e.blitBitmap(c.canvas, E.bitmap), d(E.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = h, c.onStatus({
2757
+ return E && c.expressionPath != null ? (m?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : E ? (e.blitBitmap(c.canvas, E.bitmap), f(E.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = h, c.onStatus({
2737
2758
  diffPath: E.mouthPath,
2738
2759
  label: E.label
2739
2760
  }), c.onDisplayed(h, E.mouthPath, E.label), m?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !1 }) : (m?.onBufferUnderrun(), { usedBuffer: !1, underrun: !0, held: !1 });
2740
2761
  }
2741
2762
  };
2742
2763
  }
2743
- const Nn = -1, kt = 1e5, Un = /* @__PURE__ */ new Map();
2744
- async function Ui(e) {
2745
- let t = Un.get(e);
2764
+ const Un = -1, kt = 1e5, Vn = /* @__PURE__ */ new Map();
2765
+ async function Vi(e) {
2766
+ let t = Vn.get(e);
2746
2767
  if (!t) {
2747
2768
  const n = await fetch(e);
2748
2769
  if (!n.ok)
@@ -2750,11 +2771,11 @@ async function Ui(e) {
2750
2771
  `Failed to fetch worker script (${n.status}): ${e}`
2751
2772
  );
2752
2773
  const r = await n.blob();
2753
- t = URL.createObjectURL(r), Un.set(e, t);
2774
+ t = URL.createObjectURL(r), Vn.set(e, t);
2754
2775
  }
2755
2776
  return new Worker(t, { name: "visemeDiffPreview" });
2756
2777
  }
2757
- function Vi() {
2778
+ function Wi() {
2758
2779
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
2759
2780
  }
2760
2781
  function Gt(e, t) {
@@ -2762,9 +2783,9 @@ function Gt(e, t) {
2762
2783
  const n = e.getContext("2d");
2763
2784
  n && n.drawImage(t, 0, 0);
2764
2785
  }
2765
- function Vn(e, t) {
2786
+ function Wn(e, t) {
2766
2787
  let n = 0, r = null;
2767
- const s = mr(async (i, a) => (await qt(), await Kt(e, i), s.isLatestSeq(a)));
2788
+ const s = hr(async (i, a) => (await qt(), await Kt(e, i), s.isLatestSeq(a)));
2768
2789
  return {
2769
2790
  usesWorker: !1,
2770
2791
  async loadAssets(i) {
@@ -2775,14 +2796,14 @@ function Vn(e, t) {
2775
2796
  return r;
2776
2797
  },
2777
2798
  async renderSilOnly() {
2778
- n += 1, s.reset(), await ki(e);
2799
+ n += 1, s.reset(), await vi(e);
2779
2800
  },
2780
- drawLiveFrame(i, a, o, f) {
2781
- s.enqueue(a, o, f);
2801
+ drawLiveFrame(i, a, o, d) {
2802
+ s.enqueue(a, o, d);
2782
2803
  },
2783
2804
  async compositePrefetchFrame(i, a) {
2784
2805
  try {
2785
- return await Si(i);
2806
+ return await ki(i);
2786
2807
  } catch {
2787
2808
  return null;
2788
2809
  }
@@ -2795,7 +2816,7 @@ function Vn(e, t) {
2795
2816
  n += 1;
2796
2817
  const o = n;
2797
2818
  t.onStatus?.(a), await Kt(i, {
2798
- mouthPath: vt(a),
2819
+ mouthPath: bt(a),
2799
2820
  expressionPath: null
2800
2821
  });
2801
2822
  },
@@ -2804,13 +2825,13 @@ function Vn(e, t) {
2804
2825
  }
2805
2826
  };
2806
2827
  }
2807
- function Wi(e, t, n) {
2808
- let r = null, s = 1, i = 0, a = !1, o = !1, f = null;
2809
- const d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2828
+ function Hi(e, t, n) {
2829
+ let r = null, s = 1, i = 0, a = !1, o = !1, d = null;
2830
+ const f = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2810
2831
  let c = kt;
2811
- const m = mr(async (_, p, v) => (d.set(p, {
2812
- drawKey: v.drawKey,
2813
- onDisplayed: v.onDisplayed
2832
+ const m = hr(async (_, p, b) => (f.set(p, {
2833
+ drawKey: b.drawKey,
2834
+ onDisplayed: b.onDisplayed
2814
2835
  }), await I(
2815
2836
  {
2816
2837
  type: "drawFrame",
@@ -2821,30 +2842,30 @@ function Wi(e, t, n) {
2821
2842
  void 0,
2822
2843
  !0
2823
2844
  ), !1)), w = (_) => {
2824
- if (_ === Nn) {
2845
+ if (_ === Un) {
2825
2846
  let N = -1, F;
2826
- for (const [j, R] of d)
2847
+ for (const [j, R] of f)
2827
2848
  j >= N && (N = j, F = R);
2828
- N >= 0 && d.delete(N), F?.onDisplayed?.(F.drawKey);
2849
+ N >= 0 && f.delete(N), F?.onDisplayed?.(F.drawKey);
2829
2850
  return;
2830
2851
  }
2831
- const p = -_, v = d.get(p);
2832
- d.delete(p), v?.onDisplayed?.(v.drawKey);
2833
- }, b = /* @__PURE__ */ new Map(), h = (_, p) => {
2852
+ const p = -_, b = f.get(p);
2853
+ f.delete(p), b?.onDisplayed?.(b.drawKey);
2854
+ }, v = /* @__PURE__ */ new Map(), h = (_, p) => {
2834
2855
  o || !r || r.postMessage(_, []);
2835
- }, I = (_, p, v = !1) => {
2856
+ }, I = (_, p, b = !1) => {
2836
2857
  if (o) return Promise.resolve();
2837
2858
  const N = s++;
2838
2859
  return new Promise((F, j) => {
2839
- b.set(N, {
2860
+ v.set(N, {
2840
2861
  resolve: (R) => F(R),
2841
2862
  reject: j,
2842
2863
  generation: typeof _.generation == "number" ? _.generation : void 0,
2843
- expectRenderDone: v
2864
+ expectRenderDone: b
2844
2865
  }), h({ ..._, requestId: N });
2845
2866
  });
2846
2867
  }, E = (async () => {
2847
- r = await Ui(n), r.onmessage = (_) => {
2868
+ r = await Vi(n), r.onmessage = (_) => {
2848
2869
  if (o) return;
2849
2870
  const p = _.data;
2850
2871
  if (p.type === "status") {
@@ -2862,7 +2883,7 @@ function Wi(e, t, n) {
2862
2883
  p.bitmap.close();
2863
2884
  return;
2864
2885
  }
2865
- if (N && !(p.generation === Nn)) {
2886
+ if (N && !(p.generation === Un)) {
2866
2887
  const j = -p.generation;
2867
2888
  if (!m.isLatestSeq(j)) {
2868
2889
  Ne()?.onWorkerStale(), p.bitmap.close();
@@ -2876,34 +2897,34 @@ function Wi(e, t, n) {
2876
2897
  Gt(e, p.bitmap), p.bitmap.close(), N && w(p.generation);
2877
2898
  return;
2878
2899
  }
2879
- const v = b.get(p.requestId);
2880
- if (v)
2900
+ const b = v.get(p.requestId);
2901
+ if (b)
2881
2902
  switch (p.type) {
2882
2903
  case "ready":
2883
- b.delete(p.requestId), v.resolve();
2904
+ v.delete(p.requestId), b.resolve();
2884
2905
  break;
2885
2906
  case "loadAssetsDone":
2886
- b.delete(p.requestId), f = p.visemePaths?.length ? new Set(p.visemePaths) : null, v.resolve({ width: p.width, height: p.height, visemePaths: p.visemePaths });
2907
+ v.delete(p.requestId), d = p.visemePaths?.length ? new Set(p.visemePaths) : null, b.resolve({ width: p.width, height: p.height, visemePaths: p.visemePaths });
2887
2908
  break;
2888
2909
  case "renderDone":
2889
- if (v.expectRenderDone && v.generation != null && p.generation !== v.generation)
2910
+ if (b.expectRenderDone && b.generation != null && p.generation !== b.generation)
2890
2911
  return;
2891
- b.delete(p.requestId), v.resolve();
2912
+ v.delete(p.requestId), b.resolve();
2892
2913
  break;
2893
2914
  case "renderAborted":
2894
- b.delete(p.requestId), v.resolve();
2915
+ v.delete(p.requestId), b.resolve();
2895
2916
  break;
2896
2917
  case "error":
2897
- b.delete(p.requestId), t.onError?.(p.message), v.reject(new Error(p.message));
2918
+ v.delete(p.requestId), t.onError?.(p.message), b.reject(new Error(p.message));
2898
2919
  break;
2899
2920
  }
2900
2921
  }, r.onerror = (_) => {
2901
2922
  if (o) return;
2902
2923
  const p = _.message || "Worker error";
2903
2924
  t.onError?.(p);
2904
- for (const [, v] of b)
2905
- v.reject(new Error(p));
2906
- b.clear();
2925
+ for (const [, b] of v)
2926
+ b.reject(new Error(p));
2927
+ v.clear();
2907
2928
  }, await I({ type: "init" }), a = !0;
2908
2929
  })();
2909
2930
  return {
@@ -2915,15 +2936,15 @@ function Wi(e, t, n) {
2915
2936
  return await I({
2916
2937
  type: "loadAssets",
2917
2938
  keyHex: _,
2918
- urls: Jr(Ue())
2939
+ urls: Xr(Ue())
2919
2940
  }) ?? { width: 842, height: 1264 };
2920
2941
  },
2921
2942
  getVisemeAtlasPaths() {
2922
- return f;
2943
+ return d;
2923
2944
  },
2924
2945
  async renderSilOnly() {
2925
2946
  if (o || (await E, o)) return;
2926
- i += 1, m.reset(), d.clear(), u.forEach(({ resolve: p }) => p(null)), u.clear(), c = kt;
2947
+ i += 1, m.reset(), f.clear(), u.forEach(({ resolve: p }) => p(null)), u.clear(), c = kt;
2927
2948
  const _ = i;
2928
2949
  await I({ type: "cancelLiveDraws" }), await I(
2929
2950
  { type: "renderSil", generation: _ },
@@ -2931,27 +2952,27 @@ function Wi(e, t, n) {
2931
2952
  !0
2932
2953
  );
2933
2954
  },
2934
- drawLiveFrame(_, p, v, N) {
2955
+ drawLiveFrame(_, p, b, N) {
2935
2956
  o || E.then(() => {
2936
- o || m.enqueue(p, v, N);
2957
+ o || m.enqueue(p, b, N);
2937
2958
  });
2938
2959
  },
2939
2960
  compositePrefetchFrame(_, p) {
2940
2961
  return o ? Promise.resolve(null) : E.then(() => {
2941
2962
  if (o) return null;
2942
- const v = ++c;
2963
+ const b = ++c;
2943
2964
  return new Promise((N) => {
2944
- u.set(v, { resolve: N }), I(
2965
+ u.set(b, { resolve: N }), I(
2945
2966
  {
2946
2967
  type: "drawFrame",
2947
2968
  diffPath: _.mouthPath,
2948
2969
  expressionDiffPath: _.expressionPath,
2949
- liveSeq: v
2970
+ liveSeq: b
2950
2971
  },
2951
2972
  void 0,
2952
2973
  !0
2953
2974
  ).catch(() => {
2954
- u.delete(v), N(null);
2975
+ u.delete(b), N(null);
2955
2976
  });
2956
2977
  });
2957
2978
  });
@@ -2960,9 +2981,9 @@ function Wi(e, t, n) {
2960
2981
  Gt(_, p);
2961
2982
  },
2962
2983
  supportsBufferedPlayback: !0,
2963
- async renderViseme(_, p, v = {}) {
2984
+ async renderViseme(_, p, b = {}) {
2964
2985
  if (o || (await E, o)) return;
2965
- i += 1, m.reset(), d.clear();
2986
+ i += 1, m.reset(), f.clear();
2966
2987
  const N = i;
2967
2988
  try {
2968
2989
  await I({ type: "cancelLiveDraws" }), await I(
@@ -2970,10 +2991,10 @@ function Wi(e, t, n) {
2970
2991
  type: "renderViseme",
2971
2992
  generation: N,
2972
2993
  to: p,
2973
- from: v.from,
2974
- transitionDurationMs: v.transitionDurationMs,
2975
- gapMs: v.gapMs,
2976
- threshold: v.threshold
2994
+ from: b.from,
2995
+ transitionDurationMs: b.transitionDurationMs,
2996
+ gapMs: b.gapMs,
2997
+ threshold: b.threshold
2977
2998
  },
2978
2999
  void 0,
2979
3000
  !0
@@ -2985,25 +3006,25 @@ function Wi(e, t, n) {
2985
3006
  },
2986
3007
  dispose() {
2987
3008
  if (!o) {
2988
- o = !0, i += 1, m.reset(), d.clear(), u.forEach(({ resolve: _ }) => _(null)), u.clear(), c = kt;
2989
- for (const [, _] of b)
3009
+ o = !0, i += 1, m.reset(), f.clear(), u.forEach(({ resolve: _ }) => _(null)), u.clear(), c = kt;
3010
+ for (const [, _] of v)
2990
3011
  _.resolve();
2991
- b.clear(), r?.terminate(), r = null;
3012
+ v.clear(), r?.terminate(), r = null;
2992
3013
  }
2993
3014
  }
2994
3015
  };
2995
3016
  }
2996
- function Hi(e, t = {}) {
2997
- if (!Vi())
2998
- return Vn(e, t);
2999
- const n = Rr(t.workerScriptUrl);
3017
+ function $i(e, t = {}) {
3018
+ if (!Wi())
3019
+ return Wn(e, t);
3020
+ const n = Dr(t.workerScriptUrl);
3000
3021
  try {
3001
- return Wi(e, t, n);
3022
+ return Hi(e, t, n);
3002
3023
  } catch {
3003
- return Vn(e, t);
3024
+ return Wn(e, t);
3004
3025
  }
3005
3026
  }
3006
- class $i extends Error {
3027
+ class qi extends Error {
3007
3028
  constructor(t, n) {
3008
3029
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
3009
3030
  }
@@ -3011,7 +3032,7 @@ class $i extends Error {
3011
3032
  function Nt(e, t, n) {
3012
3033
  return new Promise((r, s) => {
3013
3034
  const i = globalThis.setTimeout(() => {
3014
- s(new $i(n, t));
3035
+ s(new qi(n, t));
3015
3036
  }, t);
3016
3037
  e.then(
3017
3038
  (a) => {
@@ -3023,15 +3044,15 @@ function Nt(e, t, n) {
3023
3044
  );
3024
3045
  });
3025
3046
  }
3026
- const qi = {
3047
+ const Ki = {
3027
3048
  position: "relative",
3028
3049
  display: "inline-block",
3029
3050
  lineHeight: 0
3030
- }, Ki = {
3051
+ }, Gi = {
3031
3052
  display: "block",
3032
3053
  maxWidth: "100%",
3033
3054
  height: "auto"
3034
- }, Gi = {
3055
+ }, ji = {
3035
3056
  position: "absolute",
3036
3057
  inset: 0,
3037
3058
  display: "flex",
@@ -3044,12 +3065,12 @@ const qi = {
3044
3065
  textAlign: "center"
3045
3066
  };
3046
3067
  function ot(e) {
3047
- return Lr(e) ? er : Zn;
3068
+ return Or(e) ? tr : er;
3048
3069
  }
3049
3070
  function Me(e, t) {
3050
3071
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
3051
3072
  }
3052
- const na = _r(function({
3073
+ const ra = Sr(function({
3053
3074
  id: t,
3054
3075
  avatarId: n,
3055
3076
  faceId: r,
@@ -3057,38 +3078,38 @@ const na = _r(function({
3057
3078
  authToken: i,
3058
3079
  apiBase: a,
3059
3080
  ttsEngineId: o = je,
3060
- voiceId: f,
3061
- speakingRate: d = Pt,
3081
+ voiceId: d,
3082
+ speakingRate: f = Pt,
3062
3083
  className: u,
3063
3084
  style: c,
3064
3085
  canvasStyle: m,
3065
3086
  onStatusChange: w,
3066
- onDisplayStatus: b,
3087
+ onDisplayStatus: v,
3067
3088
  onError: h,
3068
3089
  onReady: I,
3069
3090
  showErrorOverlay: E = !0,
3070
3091
  onUserTranscript: _,
3071
3092
  onBotOutput: p,
3072
- onRealtimeLipsyncDebug: v,
3093
+ onRealtimeLipsyncDebug: b,
3073
3094
  onFrameRenderStats: N,
3074
3095
  lipsyncBufferedPlayback: F = !0,
3075
3096
  lipsyncPlaybackWarmupMs: j = 1500
3076
3097
  }, R) {
3077
3098
  const S = O(null), M = O(null), T = O(null), Z = O(F);
3078
3099
  Z.current = F;
3079
- const D = O(0), X = O(un()), z = O(li()), se = O(0), ne = O(0), de = O(0), ue = O(null), y = O(null), A = O(!1), q = O(!1), x = O(!1), P = O("sil"), $ = O(0), C = O(!1), B = O(
3100
+ const D = O(0), X = O(un()), z = O(fi()), se = O(0), ne = O(0), de = O(0), ue = O(null), y = O(null), A = O(!1), q = O(!1), x = O(!1), P = O("sil"), $ = O(0), C = O(!1), B = O(
3080
3101
  null
3081
- ), Y = O(!1), [ee, pe] = at("idle"), [me, le] = at(null), [fe, Ve] = at(!1), [xe, We] = at(!1), [ft, dn] = at({ width: 842, height: 1264 }), l = O(i ?? null), k = a?.trim() || lt, V = O(null), K = O(null), ie = O(!1), Pe = O({ width: 842, height: 1264 }), ae = O(null), Re = O("sil"), ge = O(void 0), Ze = O(/* @__PURE__ */ new Map()), et = O(I), re = O(b), tt = O(h), dt = O(_), mt = O(p), be = O(v), nt = O(N), ve = O(vi());
3082
- et.current = I, re.current = b, tt.current = h, dt.current = _, mt.current = p, be.current = v, nt.current = N, Ce(() => {
3083
- const g = ve.current;
3084
- return Fn(g), () => Fn(null);
3102
+ ), Y = O(!1), [ee, pe] = at("idle"), [me, le] = at(null), [fe, Ve] = at(!1), [xe, We] = at(!1), [ft, dn] = at({ width: 842, height: 1264 }), l = O(i ?? null), k = a?.trim() || lt, V = O(null), K = O(null), ie = O(!1), Pe = O({ width: 842, height: 1264 }), ae = O(null), Re = O("sil"), ge = O(void 0), Ze = O(/* @__PURE__ */ new Map()), et = O(I), re = O(v), tt = O(h), dt = O(_), mt = O(p), ve = O(b), nt = O(N), be = O(Ei());
3103
+ et.current = I, re.current = v, tt.current = h, dt.current = _, mt.current = p, ve.current = b, nt.current = N, Ce(() => {
3104
+ const g = be.current;
3105
+ return Ln(g), () => Ln(null);
3085
3106
  }, []);
3086
3107
  const oe = Se(
3087
3108
  (g) => {
3088
- const L = g?.ttsEngineId ?? o ?? K.current?.ttsEngineId ?? je, U = g?.voiceId ?? f ?? K.current?.voiceId ?? ot(L);
3109
+ const L = g?.ttsEngineId ?? o ?? K.current?.ttsEngineId ?? je, U = g?.voiceId ?? d ?? K.current?.voiceId ?? ot(L);
3089
3110
  return { ttsEngineId: L, voiceId: U };
3090
3111
  },
3091
- [o, f]
3112
+ [o, d]
3092
3113
  ), ce = Se((g) => {
3093
3114
  le(g), tt.current?.(g);
3094
3115
  }, []), he = Se(
@@ -3097,30 +3118,30 @@ const na = _r(function({
3097
3118
  },
3098
3119
  [w]
3099
3120
  ), J = O(
3100
- An(he, k, {
3101
- onLipsyncDebug: (g) => be.current?.(g)
3121
+ In(he, k, {
3122
+ onLipsyncDebug: (g) => ve.current?.(g)
3102
3123
  })
3103
3124
  ), Q = O(null);
3104
- Ce(() => (J.current = An(
3125
+ Ce(() => (J.current = In(
3105
3126
  he,
3106
3127
  k,
3107
3128
  {
3108
- onLipsyncDebug: (g) => be.current?.(g)
3129
+ onLipsyncDebug: (g) => ve.current?.(g)
3109
3130
  }
3110
3131
  ), i && J.current.setDeveloperToken(i), J.current.setTtsEngineId(o), () => {
3111
3132
  J.current.stop();
3112
3133
  const g = Q.current;
3113
3134
  g && (g.disconnect(), Q.current = null);
3114
3135
  }), [he, i, o, k]);
3115
- const ht = Se(() => (Q.current || (Q.current = Cs(
3136
+ const ht = Se(() => (Q.current || (Q.current = Fs(
3116
3137
  he,
3117
3138
  {
3118
- speakingRate: d,
3139
+ speakingRate: f,
3119
3140
  onUserTranscript: (g, L) => dt.current?.(g, L),
3120
3141
  onBotOutput: (g) => mt.current?.(g),
3121
- onLipsyncDebug: (g) => be.current?.(g)
3142
+ onLipsyncDebug: (g) => ve.current?.(g)
3122
3143
  }
3123
- ), Q.current.setTtsEngineId(o)), Q.current), [he, d, o]), ye = Se(() => {
3144
+ ), Q.current.setTtsEngineId(o)), Q.current), [he, f, o]), ye = Se(() => {
3124
3145
  ue.current != null && (clearTimeout(ue.current), ue.current = null);
3125
3146
  }, []), Te = Se(() => {
3126
3147
  y.current != null && (clearTimeout(y.current), y.current = null), x.current = !1;
@@ -3155,7 +3176,7 @@ const na = _r(function({
3155
3176
  return;
3156
3177
  }
3157
3178
  setTimeout(G, 300);
3158
- }, Ei));
3179
+ }, Ti));
3159
3180
  }, [Te]), He = Se(() => {
3160
3181
  if (ye(), re.current?.("sil"), A.current = !1, !Y.current || !B.current) {
3161
3182
  x.current = !1;
@@ -3187,7 +3208,7 @@ const na = _r(function({
3187
3208
  He();
3188
3209
  return;
3189
3210
  }
3190
- if (Ii(X.current)) {
3211
+ if (Mi(X.current)) {
3191
3212
  ke(X.current), He();
3192
3213
  return;
3193
3214
  }
@@ -3200,14 +3221,14 @@ const na = _r(function({
3200
3221
  He();
3201
3222
  return;
3202
3223
  }
3203
- const _e = Ri(
3224
+ const _e = Di(
3204
3225
  Me(
3205
3226
  J.current,
3206
3227
  Q.current
3207
3228
  ).getVisemeQueue(),
3208
3229
  $.current,
3209
3230
  P.current
3210
- ), pt = Di(
3231
+ ), pt = xi(
3211
3232
  _e,
3212
3233
  ae.current
3213
3234
  );
@@ -3223,7 +3244,7 @@ const na = _r(function({
3223
3244
  try {
3224
3245
  await U.renderViseme(G, "sil", {
3225
3246
  from: _e,
3226
- transitionDurationMs: lr
3247
+ transitionDurationMs: fr
3227
3248
  });
3228
3249
  } catch (De) {
3229
3250
  if (De?.name !== "AbortError")
@@ -3251,14 +3272,14 @@ const na = _r(function({
3251
3272
  q.current = !1;
3252
3273
  }), ue.current = setTimeout(() => {
3253
3274
  ue.current = null, g === ne.current && Dt({ fallbackOnly: !0 });
3254
- }, xi());
3275
+ }, Bi());
3255
3276
  }, [ye, Dt]), hn = Se(async () => {
3256
3277
  const g = Math.floor(Date.now() / 1e3);
3257
3278
  if (V.current && g < V.current.expiresAt - 60)
3258
3279
  return V.current.key;
3259
3280
  const L = l.current ?? await Ft();
3260
3281
  l.current = L, J.current.setDeveloperToken(L);
3261
- const U = await qr(L, k);
3282
+ const U = await Kr(L, k);
3262
3283
  return V.current = {
3263
3284
  key: U.value,
3264
3285
  expiresAt: U.expiresAt
@@ -3269,13 +3290,13 @@ const na = _r(function({
3269
3290
  }, [i]), Ce(() => {
3270
3291
  J.current.setTtsEngineId(o), Q.current?.setTtsEngineId(o), K.current && (K.current.ttsEngineId = o);
3271
3292
  }, [o]), Ce(() => {
3272
- const g = f ?? ot(o);
3293
+ const g = d ?? ot(o);
3273
3294
  K.current && (K.current.voiceId = g);
3274
- }, [f, o]);
3295
+ }, [d, o]);
3275
3296
  const Be = _n(
3276
- () => zr(n, r),
3297
+ () => Yr(n, r),
3277
3298
  [n, r]
3278
- ), hr = _n(() => s ? JSON.stringify(s) : Be ? `face:${Be}` : `id:${t ?? ""}`, [s, Be, t]);
3299
+ ), pr = _n(() => s ? JSON.stringify(s) : Be ? `face:${Be}` : `id:${t ?? ""}`, [s, Be, t]);
3279
3300
  return Ce(() => {
3280
3301
  if (!t && !s && !Be) {
3281
3302
  ce("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
@@ -3290,22 +3311,22 @@ const na = _r(function({
3290
3311
  try {
3291
3312
  let G, W, we, _e;
3292
3313
  if (s)
3293
- G = s, W = o, we = f ?? ot(W);
3314
+ G = s, W = o, we = d ?? ot(W);
3294
3315
  else if (Be)
3295
- re.current?.("loadFace"), G = bn(Be), W = o, we = f ?? ot(W);
3316
+ re.current?.("loadFace"), G = vn(Be), W = o, we = d ?? ot(W);
3296
3317
  else {
3297
3318
  re.current?.("getAiTwin");
3298
3319
  const H = await Nt(
3299
- Nr(t),
3320
+ Ur(t),
3300
3321
  3e4,
3301
3322
  "getAiTwin"
3302
3323
  );
3303
3324
  if (g) return;
3304
3325
  if (!H.faceId?.trim())
3305
3326
  throw new Error("getAiTwin returned no faceId");
3306
- W = H.ttsEngineId, we = f ?? H.voiceId ?? ot(W), _e = H.knowledgeContextId?.trim() || void 0, G = bn(H.faceId);
3327
+ W = H.ttsEngineId, we = d ?? H.voiceId ?? ot(W), _e = H.knowledgeContextId?.trim() || void 0, G = vn(H.faceId);
3307
3328
  }
3308
- K.current = { ttsEngineId: W, voiceId: we, personaId: _e }, Yr(G), B.current = fi(), U = Hi(L, {
3329
+ K.current = { ttsEngineId: W, voiceId: we, personaId: _e }, Jr(G), B.current = di(), U = $i(L, {
3309
3330
  onStatus: (H) => {
3310
3331
  g || re.current?.(H);
3311
3332
  },
@@ -3316,7 +3337,7 @@ const na = _r(function({
3316
3337
  J.current,
3317
3338
  Q.current
3318
3339
  ).isSpeaking() && !A.current
3319
- }), M.current = U, T.current = Ni(U), ((H) => {
3340
+ }), M.current = U, T.current = Ui(U), ((H) => {
3320
3341
  const te = () => H && F && (M.current?.supportsBufferedPlayback ?? !1) && j > 0;
3321
3342
  J.current.setLipsyncWarmupHold(H, te), Q.current?.setLipsyncWarmupHold(H, te);
3322
3343
  })(!0), re.current?.("auth");
@@ -3336,11 +3357,11 @@ const na = _r(function({
3336
3357
  g || re.current?.("sil");
3337
3358
  }), (async () => {
3338
3359
  try {
3339
- const H = await Hs(st);
3360
+ const H = await $s(st);
3340
3361
  if (await B.current.load(H), g) return;
3341
3362
  Y.current = !0, We(!0), ke(X.current), B.current.setActive(!0);
3342
3363
  const te = B.current.getVideo();
3343
- await Cn(
3364
+ await Fn(
3344
3365
  L,
3345
3366
  te,
3346
3367
  null,
@@ -3363,7 +3384,7 @@ const na = _r(function({
3363
3384
  })(), () => {
3364
3385
  g = !0, B.current?.dispose(), U?.dispose(), M.current = null;
3365
3386
  };
3366
- }, [hr, s, Be, t, o, f, i, hn, ce]), Ce(() => {
3387
+ }, [pr, s, Be, t, o, d, i, hn, ce]), Ce(() => {
3367
3388
  const g = { current: !1 }, L = () => {
3368
3389
  const U = S.current, G = M.current, W = Me(
3369
3390
  J.current,
@@ -3374,7 +3395,7 @@ const na = _r(function({
3374
3395
  return;
3375
3396
  }
3376
3397
  const we = W.isSpeaking(), _e = W.isWarmingUp(), pt = we && !C.current, De = C.current && !we;
3377
- pt && (ye(), Te(), A.current = !1, q.current = !1, ke(X.current), (T.current?.getBufferedFrameCount() ?? 0) === 0 && T.current?.reset(), ve.current.reset(), ge.current = void 0, de.current = 0, P.current = "sil", $.current = 0, B.current?.setActive(!1)), De && (z.current.reset(), B.current?.setActive(!1), rt());
3398
+ pt && (ye(), Te(), A.current = !1, q.current = !1, ke(X.current), (T.current?.getBufferedFrameCount() ?? 0) === 0 && T.current?.reset(), be.current.reset(), ge.current = void 0, de.current = 0, P.current = "sil", $.current = 0, B.current?.setActive(!1)), De && (z.current.reset(), B.current?.setActive(!1), rt());
3378
3399
  const st = De || A.current || x.current, $e = F && G.supportsBufferedPlayback;
3379
3400
  if (_e && $e && T.current) {
3380
3401
  Y.current && B.current?.setActive(!1);
@@ -3391,7 +3412,7 @@ const na = _r(function({
3391
3412
  const Ie = T.current.isWarmupReady(
3392
3413
  Ae,
3393
3414
  j
3394
- ), qe = D.current > 0 && performance.now() - D.current > xr;
3415
+ ), qe = D.current > 0 && performance.now() - D.current > Br;
3395
3416
  re.current?.(
3396
3417
  Ie ? "buffer ready" : "buffering lipsync…"
3397
3418
  ), (Ie || qe) && (D.current = 0, W.releaseWarmupHold()), C.current = W.isSpeaking(), se.current = requestAnimationFrame(L);
@@ -3400,23 +3421,23 @@ const na = _r(function({
3400
3421
  if (we) {
3401
3422
  Y.current && B.current?.setActive(!1);
3402
3423
  const H = W.getVisemeQueue(), te = W.getPlaybackElapsedMs();
3403
- Es(H, te), $.current = te;
3424
+ Ts(H, te), $.current = te;
3404
3425
  const Ee = H.length > 0 ? Mt(H, te) : "sil";
3405
3426
  Ee !== "sil" && (P.current = Ee);
3406
- const Ae = pi(
3427
+ const Ae = wi(
3407
3428
  te,
3408
3429
  W.getSentenceEmotions(),
3409
3430
  W.getWordQueue(),
3410
3431
  W.getStreamMood()
3411
3432
  );
3412
3433
  z.current.setTargetEmotion(Ae), z.current.setTargetEyebrow(
3413
- ui(
3434
+ li(
3414
3435
  te,
3415
3436
  W.getWordQueue(),
3416
3437
  sn(Ae)
3417
3438
  )
3418
3439
  ), z.current.advance(performance.now());
3419
- const Ie = z.current.getExpressionPath(), qe = z.current.getDrawKey(), pr = (Ke, xt, it, Bt) => {
3440
+ const Ie = z.current.getExpressionPath(), qe = z.current.getDrawKey(), wr = (Ke, xt, it, Bt) => {
3420
3441
  const gn = {
3421
3442
  label: Re.current,
3422
3443
  elapsedMs: te,
@@ -3427,9 +3448,9 @@ const na = _r(function({
3427
3448
  it,
3428
3449
  Ie
3429
3450
  ), G.drawLiveFrame(Ke, xt, it, (wt) => {
3430
- const gr = Ze.current.get(wt) ?? gn;
3431
- Ze.current.delete(wt), ve.current.onDrawDisplayed(
3432
- gr,
3451
+ const yr = Ze.current.get(wt) ?? gn;
3452
+ Ze.current.delete(wt), be.current.onDrawDisplayed(
3453
+ yr,
3433
3454
  H
3434
3455
  ), T.current?.markExternallyDisplayed(
3435
3456
  wt,
@@ -3438,9 +3459,9 @@ const na = _r(function({
3438
3459
  });
3439
3460
  }, pn = (Ke) => {
3440
3461
  Re.current = Ke.label, ge.current = Ke.transitionMeta, re.current?.(Ke.label);
3441
- }, wr = F && G.supportsBufferedPlayback;
3462
+ }, gr = F && G.supportsBufferedPlayback;
3442
3463
  let wn = !1;
3443
- wr && T.current && (wn = T.current.tick({
3464
+ gr && T.current && (wn = T.current.tick({
3444
3465
  canvas: U,
3445
3466
  queue: H,
3446
3467
  elapsedMs: te,
@@ -3450,7 +3471,7 @@ const na = _r(function({
3450
3471
  availablePaths: ae.current,
3451
3472
  onStatus: pn,
3452
3473
  onDisplayed: (xt, it, Bt) => {
3453
- ve.current.onDrawDisplayed(
3474
+ be.current.onDrawDisplayed(
3454
3475
  {
3455
3476
  label: Bt,
3456
3477
  elapsedMs: te,
@@ -3460,22 +3481,22 @@ const na = _r(function({
3460
3481
  H
3461
3482
  );
3462
3483
  }
3463
- }).usedBuffer), wn || Bi(
3484
+ }).usedBuffer), wn || Ci(
3464
3485
  U,
3465
3486
  H,
3466
3487
  te,
3467
3488
  Ie,
3468
3489
  qe,
3469
3490
  X.current,
3470
- pr,
3491
+ wr,
3471
3492
  pn,
3472
3493
  ae.current
3473
- ), ve.current.onRafTickSpeaking(), nt.current?.(
3474
- ve.current.snapshot(H, te)
3494
+ ), be.current.onRafTickSpeaking(), nt.current?.(
3495
+ be.current.snapshot(H, te)
3475
3496
  );
3476
3497
  } else if (!st && Y.current && B.current) {
3477
3498
  const H = B.current, te = H.getVideo();
3478
- te.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (H.setActive(!0), g.current || (g.current = !0, Cn(
3499
+ te.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (H.setActive(!0), g.current || (g.current = !0, Fn(
3479
3500
  U,
3480
3501
  te,
3481
3502
  null,
@@ -3484,7 +3505,7 @@ const na = _r(function({
3484
3505
  () => !W.isSpeaking() && !A.current && !x.current
3485
3506
  ).then(() => re.current?.("idle")).finally(() => {
3486
3507
  g.current = !1;
3487
- }))) : On(
3508
+ }))) : Nn(
3488
3509
  U,
3489
3510
  null,
3490
3511
  "__sil__",
@@ -3492,7 +3513,7 @@ const na = _r(function({
3492
3513
  (Ee, Ae, Ie, qe) => G.drawLiveFrame(Ee, Ae, Ie, qe),
3493
3514
  (Ee) => re.current?.(Ee)
3494
3515
  );
3495
- } else st || On(
3516
+ } else st || Nn(
3496
3517
  U,
3497
3518
  null,
3498
3519
  "__sil__",
@@ -3511,7 +3532,7 @@ const na = _r(function({
3511
3532
  rt,
3512
3533
  ye,
3513
3534
  Te
3514
- ]), Sr(
3535
+ ]), kr(
3515
3536
  R,
3516
3537
  () => ({
3517
3538
  speakText: async (g, L) => {
@@ -3525,7 +3546,7 @@ const na = _r(function({
3525
3546
  try {
3526
3547
  Y.current ? (B.current?.setActive(!1), B.current?.restart(), ke(X.current)) : await G.renderSilOnly(), await J.current.speak(U, {
3527
3548
  voiceId: we,
3528
- speakingRate: L?.speakingRate ?? d,
3549
+ speakingRate: L?.speakingRate ?? f,
3529
3550
  ttsEngineId: W
3530
3551
  });
3531
3552
  } catch (_e) {
@@ -3556,14 +3577,14 @@ const na = _r(function({
3556
3577
  try {
3557
3578
  let L = g.authToken?.trim();
3558
3579
  L || (L = l.current ?? i ?? await Ft(), l.current = L);
3559
- const U = g.voiceId?.trim() ?? f ?? K.current?.voiceId, G = g.personaId?.trim() ?? K.current?.personaId, W = ht();
3580
+ const U = g.voiceId?.trim() ?? d ?? K.current?.voiceId, G = g.personaId?.trim() ?? K.current?.personaId, W = ht();
3560
3581
  await W.unlockAudio(), await W.connect({
3561
3582
  ...g,
3562
3583
  apiBase: g.apiBase?.trim() || k,
3563
3584
  authToken: L,
3564
3585
  voiceId: U,
3565
3586
  personaId: G,
3566
- speakingRate: g.speakingRate ?? d
3587
+ speakingRate: g.speakingRate ?? f
3567
3588
  });
3568
3589
  } catch (L) {
3569
3590
  throw ce(
@@ -3580,9 +3601,9 @@ const na = _r(function({
3580
3601
  }),
3581
3602
  [
3582
3603
  fe,
3583
- d,
3584
- i,
3585
3604
  f,
3605
+ i,
3606
+ d,
3586
3607
  ye,
3587
3608
  Te,
3588
3609
  rt,
@@ -3591,66 +3612,66 @@ const na = _r(function({
3591
3612
  ht,
3592
3613
  ee
3593
3614
  ]
3594
- ), /* @__PURE__ */ yr("div", { className: u, style: { ...qi, ...c }, children: [
3615
+ ), /* @__PURE__ */ _r("div", { className: u, style: { ...Ki, ...c }, children: [
3595
3616
  /* @__PURE__ */ yn(
3596
3617
  "canvas",
3597
3618
  {
3598
3619
  ref: S,
3599
3620
  width: ft.width,
3600
3621
  height: ft.height,
3601
- style: { ...Ki, ...m },
3622
+ style: { ...Gi, ...m },
3602
3623
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
3603
3624
  }
3604
3625
  ),
3605
- E && me ? /* @__PURE__ */ yn("div", { style: Gi, children: me }) : null
3626
+ E && me ? /* @__PURE__ */ yn("div", { style: ji, children: me }) : null
3606
3627
  ] });
3607
- }), ji = "thumbnail.webp";
3608
- function ra(e, t = jt) {
3628
+ }), zi = "thumbnail.webp";
3629
+ function sa(e, t = jt) {
3609
3630
  const n = e.trim();
3610
3631
  if (!n)
3611
3632
  throw new Error("faceId is required");
3612
- return `${t.replace(/\/$/, "")}/${n}/${ji}`;
3633
+ return `${t.replace(/\/$/, "")}/${n}/${zi}`;
3613
3634
  }
3614
- const zi = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
3615
- function Yi(e = ".png") {
3635
+ const Yi = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
3636
+ function Ji(e = ".png") {
3616
3637
  const t = e.toLowerCase();
3617
- return zi.has(t) ? `source${t}` : "source.png";
3638
+ return Yi.has(t) ? `source${t}` : "source.png";
3618
3639
  }
3619
- function sa(e, t = jt, n = ".png") {
3640
+ function ia(e, t = jt, n = ".png") {
3620
3641
  const r = e.trim();
3621
3642
  if (!r)
3622
3643
  throw new Error("faceId is required");
3623
- return `${t.replace(/\/$/, "")}/${r}/${Yi(n)}`;
3644
+ return `${t.replace(/\/$/, "")}/${r}/${Ji(n)}`;
3624
3645
  }
3625
3646
  export {
3626
- ji as AI_TWIN_THUMBNAIL_FILENAME,
3627
- na as AiTwin,
3647
+ zi as AI_TWIN_THUMBNAIL_FILENAME,
3648
+ ra as AiTwin,
3628
3649
  Ut as AiTwinNotFoundError,
3629
3650
  je as DEFAULT_TTS_ENGINE_ID,
3630
- tr as MIC_SAMPLE_RATE,
3631
- ns as OCULUS_VISEME_IDS,
3632
- nr as PLAYBACK_SAMPLE_RATE,
3651
+ nr as MIC_SAMPLE_RATE,
3652
+ rs as OCULUS_VISEME_IDS,
3653
+ rr as PLAYBACK_SAMPLE_RATE,
3633
3654
  Zt as SPEAKING_RATE_MAX,
3634
3655
  Qt as SPEAKING_RATE_MIN,
3635
3656
  Xe as TTS_ENGINE_CARTESIA,
3636
- Hn as TTS_ENGINE_GOOGLE,
3657
+ $n as TTS_ENGINE_GOOGLE,
3637
3658
  Yt as TTS_ENGINE_INWORLD,
3638
- ta as VISEME_IDS,
3639
- er as VISEME_TEST_CARTESIA_VOICE_ID,
3659
+ na as VISEME_IDS,
3660
+ tr as VISEME_TEST_CARTESIA_VOICE_ID,
3640
3661
  Pt as VISEME_TEST_SPEAKING_RATE,
3641
- Zn as VISEME_TEST_VOICE_ID,
3642
- Yi as aiTwinSourceFilename,
3643
- Ds as buildVoiceWebSocketUrl,
3644
- An as createAvatarTtsLipsyncController,
3645
- Cs as createRealtimeVoiceLipsyncController,
3646
- bn as faceAssetUrls,
3647
- Nr as fetchAiTwin,
3662
+ er as VISEME_TEST_VOICE_ID,
3663
+ Ji as aiTwinSourceFilename,
3664
+ xs as buildVoiceWebSocketUrl,
3665
+ In as createAvatarTtsLipsyncController,
3666
+ Fs as createRealtimeVoiceLipsyncController,
3667
+ vn as faceAssetUrls,
3668
+ Ur as fetchAiTwin,
3648
3669
  Ft as fetchDevAuthToken,
3649
- sa as getAiTwinSourceUrl,
3650
- ra as getAiTwinThumbnailUrl,
3651
- ss as normalizeOculusViseme,
3652
- zr as resolveDirectFaceId,
3670
+ ia as getAiTwinSourceUrl,
3671
+ sa as getAiTwinThumbnailUrl,
3672
+ is as normalizeOculusViseme,
3673
+ Yr as resolveDirectFaceId,
3653
3674
  Mt as resolveVisemeAtTime,
3654
- ea as resolveWordAtTime,
3655
- Yr as setActiveTwinAssets
3675
+ ta as resolveWordAtTime,
3676
+ Jr as setActiveTwinAssets
3656
3677
  };