@streamoji/aitwin 0.4.8 → 0.5.0

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,48 +1,48 @@
1
- import { jsxs as zn, jsx as Lr } from "react/jsx-runtime";
2
- import { forwardRef as jn, useRef as q, useState as ut, useEffect as Je, useCallback as Ce, useMemo as Or, useImperativeHandle as Yn } from "react";
3
- import { PipecatClient as Xn } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as Qn, DailyMediaManager as Jn, ProtobufFrameSerializer as Zn } from "@pipecat-ai/websocket-transport";
5
- import { Filter as es, GlProgram as ts, Application as rs, RendererType as ns, Sprite as kt, Texture as _e, VideoSource as ss, Rectangle as is } from "pixi.js";
6
- const as = "https://aitwin.bubu.social", ln = {
7
- publicBase: as
8
- }, os = "0.4.8", cs = {
9
- version: os
10
- }, us = {}, Pt = "https://ai.aitwin.me", wr = `${ln.publicBase}/custom-faces`, ls = `${ln.publicBase}/aitwin-workers/v${cs.version}/visemeDiffPreview.worker.js`;
11
- function fs(e) {
1
+ import { jsxs as Xn, jsx as Or } from "react/jsx-runtime";
2
+ import { forwardRef as Qn, useRef as q, useState as ut, useEffect as Je, useCallback as Ce, useMemo as Nr, useImperativeHandle as Jn } from "react";
3
+ import { PipecatClient as Zn } from "@pipecat-ai/client-js";
4
+ import { WebSocketTransport as es, DailyMediaManager as ts, ProtobufFrameSerializer as rs } from "@pipecat-ai/websocket-transport";
5
+ import { Filter as ns, GlProgram as ss, Application as is, RendererType as os, Sprite as kt, Texture as _e, VideoSource as as, Rectangle as cs } from "pixi.js";
6
+ const us = "https://aitwin.bubu.social", dn = {
7
+ publicBase: us
8
+ }, ls = "0.5.0", fs = {
9
+ version: ls
10
+ }, ds = {}, Pt = "https://ai.aitwin.me", wr = `${dn.publicBase}/custom-faces`, ms = `${dn.publicBase}/aitwin-workers/v${fs.version}/visemeDiffPreview.worker.js`;
11
+ function hs(e) {
12
12
  if (e) return e;
13
- const t = typeof import.meta < "u" ? us?.VITE_AITWIN_WORKER_URL : void 0;
14
- return t?.trim() ? t.trim() : ls;
13
+ const t = typeof import.meta < "u" ? ds?.VITE_AITWIN_WORKER_URL : void 0;
14
+ return t?.trim() ? t.trim() : ms;
15
15
  }
16
- const ds = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", rr = 3e3, Et = 16, Nr = 3e3, ms = 4e3, hs = 0.85, ps = 8, gr = 400, fn = "eng_a7f2b9c1", yr = "eng_d4e8f3a2", gt = "eng_c9b1e6d4", ft = gt, dn = /* @__PURE__ */ new Set([
16
+ const ps = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", rr = 3e3, Et = 16, Ur = 3e3, ws = 4e3, gs = 0.85, ys = 8, gr = 400, mn = "eng_a7f2b9c1", yr = "eng_d4e8f3a2", gt = "eng_c9b1e6d4", ft = gt, hn = /* @__PURE__ */ new Set([
17
17
  yr,
18
18
  gt
19
- ]), mn = {
20
- [fn]: "oculus_direct",
19
+ ]), pn = {
20
+ [mn]: "oculus_direct",
21
21
  [gt]: "oculus_direct",
22
22
  [yr]: "inworld_word"
23
- }, Ur = {
24
- google: fn,
23
+ }, Vr = {
24
+ google: mn,
25
25
  inworld: yr,
26
26
  cartesia: gt
27
27
  };
28
- function ws(e) {
29
- return mn[e];
28
+ function _s(e) {
29
+ return pn[e];
30
30
  }
31
- function gs(e) {
31
+ function Ss(e) {
32
32
  return e === gt;
33
33
  }
34
- function ys(e) {
35
- if (e.ttsEngineId && e.ttsEngineId in mn)
34
+ function vs(e) {
35
+ if (e.ttsEngineId && e.ttsEngineId in pn)
36
36
  return e.ttsEngineId;
37
37
  const t = e.tts?.toLowerCase();
38
- return t && t in Ur ? Ur[t] : ft;
38
+ return t && t in Vr ? Vr[t] : ft;
39
39
  }
40
40
  class ur extends Error {
41
41
  constructor(t = "AI twin not found") {
42
42
  super(t), this.name = "AiTwinNotFoundError";
43
43
  }
44
44
  }
45
- async function _s(e, t = ds) {
45
+ async function bs(e, t = ps) {
46
46
  const r = new URL(t);
47
47
  r.searchParams.set("id", e);
48
48
  const n = await fetch(r.toString());
@@ -53,25 +53,25 @@ async function _s(e, t = ds) {
53
53
  const s = await n.json();
54
54
  if (!s.success)
55
55
  throw new ur(s.error ?? "AI twin not found");
56
- const { tts: i, token: o, ...a } = s.data, l = String(a.authToken ?? o ?? "").trim() || void 0;
56
+ const { tts: i, token: a, ...o } = s.data, u = String(o.authToken ?? a ?? "").trim() || void 0;
57
57
  return {
58
- ...a,
59
- ttsEngineId: ys(s.data),
60
- authToken: l
58
+ ...o,
59
+ ttsEngineId: vs(s.data),
60
+ authToken: u
61
61
  };
62
62
  }
63
- const Ss = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", vs = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", bs = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", ks = "6TNvp3SCs4Og0a1ijm9TommXLql1", Ts = "Swaraj Mali";
63
+ const ks = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Ts = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Es = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Is = "6TNvp3SCs4Og0a1ijm9TommXLql1", As = "Swaraj Mali";
64
64
  async function nr() {
65
- const e = await fetch(Ss, {
65
+ const e = await fetch(ks, {
66
66
  method: "POST",
67
67
  headers: {
68
68
  "Content-Type": "application/json",
69
- "Client-Id": vs,
70
- "Client-Secret": bs
69
+ "Client-Id": Ts,
70
+ "Client-Secret": Es
71
71
  },
72
72
  body: JSON.stringify({
73
- userId: ks,
74
- userName: Ts
73
+ userId: Is,
74
+ userName: As
75
75
  })
76
76
  });
77
77
  if (!e.ok)
@@ -81,7 +81,7 @@ async function nr() {
81
81
  throw new Error("getAuthToken returned no token");
82
82
  return r;
83
83
  }
84
- async function Es(e, t = Pt) {
84
+ async function Ps(e, t = Pt) {
85
85
  const r = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
86
86
  headers: { Authorization: `Bearer ${e}` }
87
87
  });
@@ -91,7 +91,7 @@ async function Es(e, t = Pt) {
91
91
  if (!n.value) throw new Error("Session value response missing value");
92
92
  return n;
93
93
  }
94
- function Is(e) {
94
+ function xs(e) {
95
95
  const t = e.trim();
96
96
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
97
97
  const r = new Uint8Array(t.length / 2);
@@ -102,25 +102,25 @@ function Is(e) {
102
102
  function Ot(e) {
103
103
  return Uint8Array.from(e);
104
104
  }
105
- function As(e, t) {
105
+ function Ms(e, t) {
106
106
  const r = new Uint8Array(e.length + t.length);
107
107
  return r.set(e, 0), r.set(t, e.length), r;
108
108
  }
109
- async function Ps(e, t) {
109
+ async function Cs(e, t) {
110
110
  if (!t) throw new Error("Asset key is required for encrypted assets");
111
111
  if (e.byteLength < 28)
112
112
  throw new Error("Encrypted payload too small");
113
- const r = new Uint8Array(e), n = Ot(r.subarray(0, 12)), s = Ot(r.subarray(12, 28)), i = Ot(r.subarray(28)), o = Ot(As(i, s)), a = await crypto.subtle.importKey(
113
+ const r = new Uint8Array(e), n = Ot(r.subarray(0, 12)), s = Ot(r.subarray(12, 28)), i = Ot(r.subarray(28)), a = Ot(Ms(i, s)), o = await crypto.subtle.importKey(
114
114
  "raw",
115
- Is(t),
115
+ xs(t),
116
116
  { name: "AES-GCM" },
117
117
  !1,
118
118
  ["decrypt"]
119
119
  );
120
120
  return crypto.subtle.decrypt(
121
121
  { name: "AES-GCM", iv: n, tagLength: 128 },
122
- a,
123
- o
122
+ o,
123
+ a
124
124
  );
125
125
  }
126
126
  let lr = null;
@@ -138,18 +138,18 @@ function $t(e) {
138
138
  function tt(e) {
139
139
  return $t(e).encrypted;
140
140
  }
141
- function Vr(e, t = wr) {
141
+ function Wr(e, t = wr) {
142
142
  const r = `${t.replace(/\/$/, "")}/${e}`;
143
143
  return { twinBase: r, binBase: r, encrypted: !0 };
144
144
  }
145
- function xs(e, t) {
145
+ function Rs(e, t) {
146
146
  return (e ?? t)?.trim() || void 0;
147
147
  }
148
- function Ms(e) {
148
+ function Ds(e) {
149
149
  lr = $t(e);
150
150
  for (const t of fr) t();
151
151
  }
152
- function Cs(e, t) {
152
+ function Bs(e, t) {
153
153
  const r = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
154
154
  if (!r) return $t(e);
155
155
  const n = (s) => {
@@ -170,33 +170,33 @@ function rt() {
170
170
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
171
171
  return lr;
172
172
  }
173
- function hn(e) {
173
+ function wn(e) {
174
174
  return fr.add(e), () => fr.delete(e);
175
175
  }
176
176
  function Ht() {
177
177
  const e = rt();
178
178
  return tt(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
179
179
  }
180
- function Rs() {
180
+ function Fs() {
181
181
  const e = rt();
182
182
  return tt(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
183
183
  }
184
- function pn() {
184
+ function gn() {
185
185
  const e = rt();
186
186
  return tt(e) ? e.binBase : e.twinBase;
187
187
  }
188
188
  function xt() {
189
189
  return tt(rt());
190
190
  }
191
- function wn() {
191
+ function yn() {
192
192
  const e = rt();
193
193
  return tt(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
194
194
  }
195
- function gn() {
195
+ function _n() {
196
196
  const e = rt();
197
197
  return tt(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
198
198
  }
199
- function yn(e) {
199
+ function Sn(e) {
200
200
  const t = e.split(/\r?\n/);
201
201
  let r = "", n = "";
202
202
  for (const i of t)
@@ -211,7 +211,7 @@ function yn(e) {
211
211
  }
212
212
  return { event: r, data: s };
213
213
  }
214
- const Ds = [
214
+ const Ls = [
215
215
  "aa",
216
216
  "CH",
217
217
  "DD",
@@ -227,14 +227,14 @@ const Ds = [
227
227
  "kk",
228
228
  "nn",
229
229
  "sil"
230
- ], Bs = new Map(
231
- Ds.map((e) => [e.toLowerCase(), e])
230
+ ], Os = new Map(
231
+ Ls.map((e) => [e.toLowerCase(), e])
232
232
  );
233
- function Fs(e) {
233
+ function Ns(e) {
234
234
  const t = (e ?? "").trim();
235
- return t ? Bs.get(t.toLowerCase()) ?? "sil" : "sil";
235
+ return t ? Os.get(t.toLowerCase()) ?? "sil" : "sil";
236
236
  }
237
- const Ls = {
237
+ const Us = {
238
238
  aei: ["aa", "E", "I"],
239
239
  o: ["O", "U"],
240
240
  ee: ["I"],
@@ -246,12 +246,12 @@ const Ls = {
246
246
  qw: ["U", "O"],
247
247
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
248
248
  };
249
- function Os(e) {
249
+ function Vs(e) {
250
250
  if (!e) return ["sil"];
251
251
  const t = e.toLowerCase();
252
- return Ls[t] ?? ["sil"];
252
+ return Us[t] ?? ["sil"];
253
253
  }
254
- function Ns(e, t) {
254
+ function Ws(e, t) {
255
255
  const r = e.word.length;
256
256
  if (r <= 0) return 0;
257
257
  const n = e.wduration;
@@ -267,11 +267,11 @@ function _r(e, t) {
267
267
  const r = e.toLowerCase().replace(/[^a-z']/g, "");
268
268
  return !r || mt(r, t) !== "w" || t > 0 && mt(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
269
269
  }
270
- function Us(e, t) {
270
+ function $s(e, t) {
271
271
  const r = e.toLowerCase(), n = mt(r, t), s = r.slice(Math.max(0, t - 1), t + 2);
272
272
  return n === "i" || n === "y" ? "I" : s.includes("ee") || n === "e" || r.includes("ea") ? "E" : "aa";
273
273
  }
274
- function Vs(e, t) {
274
+ function Hs(e, t) {
275
275
  const r = e.toLowerCase(), n = r.slice(
276
276
  Math.max(0, t - 1),
277
277
  Math.min(r.length, t + 3)
@@ -281,7 +281,7 @@ function Vs(e, t) {
281
281
  const s = mt(r, t);
282
282
  return s === "u" || s === "w" ? "U" : "O";
283
283
  }
284
- function Ws(e, t) {
284
+ function Ks(e, t) {
285
285
  const r = e.toLowerCase();
286
286
  if (_r(r, t)) return "FF";
287
287
  const n = r.slice(Math.max(0, t - 2), t + 1);
@@ -304,7 +304,7 @@ const Ut = {
304
304
  x: "CH",
305
305
  j: "CH"
306
306
  };
307
- function $s(e, t) {
307
+ function qs(e, t) {
308
308
  const r = e.toLowerCase(), n = mt(r, t);
309
309
  if (Ut[n]) return Ut[n];
310
310
  for (let s = 0; s < r.length; s++) {
@@ -313,33 +313,79 @@ function $s(e, t) {
313
313
  }
314
314
  return "DD";
315
315
  }
316
- function Hs(e, t, r) {
317
- const n = Os(e);
316
+ function Gs(e, t, r) {
317
+ const n = Vs(e);
318
318
  if (n.length === 1) return n[0];
319
319
  const s = t.trim();
320
320
  if (!s) return n[0];
321
- const i = (e ?? "").toLowerCase(), o = Math.max(0, r);
321
+ const i = (e ?? "").toLowerCase(), a = Math.max(0, r);
322
322
  switch (i) {
323
323
  case "aei":
324
- return Us(s, o);
324
+ return $s(s, a);
325
325
  case "o":
326
- return Vs(s, o);
326
+ return Hs(s, a);
327
327
  case "qw":
328
- return Ws(s, o);
328
+ return Ks(s, a);
329
329
  case "cdgknstxyz":
330
- return $s(s, o);
330
+ return qs(s, a);
331
331
  default:
332
332
  return n[0];
333
333
  }
334
334
  }
335
- const Ks = 32, Wr = 48;
336
- function _n(e) {
335
+ const $r = 35, zs = /* @__PURE__ */ new Set(["aa", "E", "I"]), js = /* @__PURE__ */ new Set(["DD", "SS", "kk", "CH"]), Ys = [zs, js];
336
+ function Xs(e) {
337
+ for (const t of Ys)
338
+ if (t.has(e)) return t;
339
+ return null;
340
+ }
341
+ function Qs(e) {
342
+ return Xs(e) != null;
343
+ }
344
+ function vn(e) {
345
+ const t = /* @__PURE__ */ new Map();
346
+ for (const r of e)
347
+ t.has(r.vtime) || t.set(r.vtime, r);
348
+ return [...t.values()].sort((r, n) => r.vtime - n.vtime);
349
+ }
350
+ function bn(e) {
351
+ if (e.length <= 2) return [...e];
352
+ const t = [e[0]];
353
+ for (let r = 1; r < e.length - 1; r++) {
354
+ const n = e[r], s = e[r + 1], i = t[t.length - 1];
355
+ if (!Qs(n.viseme)) {
356
+ t.push(n);
357
+ continue;
358
+ }
359
+ const a = n.vtime - i.vtime, o = s.vtime - n.vtime;
360
+ a < $r || o < $r || t.push(n);
361
+ }
362
+ return t.push(e[e.length - 1]), t;
363
+ }
364
+ function Sr(e) {
365
+ return bn(vn(e));
366
+ }
367
+ function Js(e, t) {
368
+ let r = "sil";
369
+ for (const n of e) {
370
+ if (n.vtime > t) break;
371
+ n.viseme !== "sil" && (r = n.viseme);
372
+ }
373
+ return r;
374
+ }
375
+ function qo(e) {
376
+ const t = vn(e), r = bn(t), n = new Set(r.map((i) => i.vtime)), s = [];
377
+ for (const i of t)
378
+ n.has(i.vtime) || s.push(i.viseme);
379
+ return s;
380
+ }
381
+ const Zs = 32, Hr = 48;
382
+ function kn(e) {
337
383
  let t = 0;
338
384
  for (const r of e)
339
385
  t = Math.max(t, r.vtime + r.vduration);
340
386
  return t;
341
387
  }
342
- function Sn(e) {
388
+ function Tn(e) {
343
389
  let t = null, r = -1;
344
390
  for (const n of e) {
345
391
  if (n.viseme === "sil") continue;
@@ -348,22 +394,22 @@ function Sn(e) {
348
394
  }
349
395
  return t;
350
396
  }
351
- function qs(e) {
352
- return vn(e).find((r) => r.viseme !== "sil") ?? null;
397
+ function ei(e) {
398
+ return Sr(e).find((r) => r.viseme !== "sil") ?? null;
353
399
  }
354
400
  function Ze(e) {
355
- const t = _n(e);
356
- return Sn(e) ? t + gr : t;
401
+ const t = kn(e);
402
+ return Tn(e) ? t + gr : t;
357
403
  }
358
- function Gs(e) {
359
- const t = [], r = qs(e);
404
+ function ti(e) {
405
+ const t = [], r = ei(e);
360
406
  r && r.vtime > 0 && t.push({
361
407
  from: "sil",
362
408
  to: r.viseme,
363
409
  fromVtime: 0,
364
410
  toVtime: r.vtime
365
411
  });
366
- const n = Sn(e), s = _n(e);
412
+ const n = Tn(e), s = kn(e);
367
413
  return n && t.push({
368
414
  from: n.viseme,
369
415
  to: "sil",
@@ -371,30 +417,24 @@ function Gs(e) {
371
417
  toVtime: s + gr
372
418
  }), t;
373
419
  }
374
- function vn(e) {
375
- const t = /* @__PURE__ */ new Map();
376
- for (const r of e)
377
- t.has(r.vtime) || t.set(r.vtime, r);
378
- return [...t.values()].sort((r, n) => r.vtime - n.vtime);
379
- }
380
- function zs(e) {
381
- const t = vn(e), r = [];
420
+ function ri(e) {
421
+ const t = Sr(e), r = [];
382
422
  for (let n = 0; n < t.length - 1; n++) {
383
- const s = t[n].viseme, i = t[n + 1].viseme, o = t[n].vtime, a = t[n + 1].vtime;
384
- s === i || a <= o || r.push({ from: s, to: i, fromVtime: o, toVtime: a });
423
+ const s = t[n].viseme, i = t[n + 1].viseme, a = t[n].vtime, o = t[n + 1].vtime;
424
+ s === i || o <= a || r.push({ from: s, to: i, fromVtime: a, toVtime: o });
385
425
  }
386
426
  return r;
387
427
  }
388
- function js(e) {
428
+ function ni(e) {
389
429
  return e.length === 0 ? [] : [
390
- ...Gs(e),
391
- ...zs(e)
430
+ ...ti(e),
431
+ ...ri(e)
392
432
  ];
393
433
  }
394
- function Ys(e, t) {
434
+ function si(e, t) {
395
435
  let r = null;
396
436
  for (const n of e) {
397
- const { transStart: s, transEnd: i } = bn(
437
+ const { transStart: s, transEnd: i } = En(
398
438
  n.fromVtime,
399
439
  n.toVtime,
400
440
  n.from,
@@ -404,56 +444,56 @@ function Ys(e, t) {
404
444
  }
405
445
  return r;
406
446
  }
407
- function bn(e, t, r, n) {
447
+ function En(e, t, r, n) {
408
448
  const s = Math.max(0, t - e);
409
- if ((r === "PP" || n === "PP") && s > Wr) {
410
- const f = Wr, u = t, c = u - f;
449
+ if ((r === "PP" || n === "PP") && s > Hr) {
450
+ const f = Hr, l = t, c = l - f;
411
451
  return {
412
452
  gapMs: s,
413
453
  effectiveGapMs: f,
414
454
  holdEnd: c,
415
455
  transStart: c,
416
- transEnd: u
456
+ transEnd: l
417
457
  };
418
458
  }
419
- const o = s > 0 ? Math.max(s, Ks) : 0, a = e, l = e + o;
420
- return { gapMs: s, effectiveGapMs: o, holdEnd: e, transStart: a, transEnd: l };
459
+ const a = s > 0 ? Math.max(s, Zs) : 0, o = e, u = e + a;
460
+ return { gapMs: s, effectiveGapMs: a, holdEnd: e, transStart: o, transEnd: u };
421
461
  }
422
- const Sr = 16e3;
423
- function kn(e) {
462
+ const vr = 16e3;
463
+ function In(e) {
424
464
  const t = Number(e);
425
- return Number.isFinite(t) && t > 0 ? t : Sr;
465
+ return Number.isFinite(t) && t > 0 ? t : vr;
426
466
  }
427
- function Xs(e) {
467
+ function ii(e) {
428
468
  let t = e.trim();
429
469
  const r = t.indexOf(",");
430
470
  t.startsWith("data:") && r >= 0 && (t = t.slice(r + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
431
471
  const n = t.length % 4;
432
472
  return n !== 0 && (t += "=".repeat(4 - n)), t;
433
473
  }
434
- function Qs(e) {
474
+ function oi(e) {
435
475
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
436
476
  }
437
- function $r(e, t, r = Sr) {
477
+ function Kr(e, t, r = vr) {
438
478
  const n = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
439
479
  n.buffer,
440
480
  n.byteOffset,
441
481
  n.byteLength / 2
442
482
  ), i = new Float32Array(s.length);
443
- for (let a = 0; a < s.length; a++)
444
- i[a] = s[a] >= 32768 ? -(65536 - s[a]) / 32768 : s[a] / 32767;
445
- const o = e.createBuffer(1, i.length, r);
446
- return o.copyToChannel(i, 0), o;
483
+ for (let o = 0; o < s.length; o++)
484
+ i[o] = s[o] >= 32768 ? -(65536 - s[o]) / 32768 : s[o] / 32767;
485
+ const a = e.createBuffer(1, i.length, r);
486
+ return a.copyToChannel(i, 0), a;
447
487
  }
448
- function Js(e) {
449
- const t = Xs(e), r = window.atob(t), n = new Uint8Array(r.length);
488
+ function ai(e) {
489
+ const t = ii(e), r = window.atob(t), n = new Uint8Array(r.length);
450
490
  for (let s = 0; s < r.length; s++)
451
491
  n[s] = r.charCodeAt(s);
452
492
  return n;
453
493
  }
454
- async function Hr(e, t, r = Sr) {
455
- const n = Js(t), s = kn(r);
456
- if (Qs(n)) {
494
+ async function qr(e, t, r = vr) {
495
+ const n = ai(t), s = In(r);
496
+ if (oi(n)) {
457
497
  const i = n.buffer.slice(
458
498
  n.byteOffset,
459
499
  n.byteOffset + n.byteLength
@@ -461,7 +501,7 @@ async function Hr(e, t, r = Sr) {
461
501
  return e.decodeAudioData(i);
462
502
  }
463
503
  if (n.length >= 2 && n.length % 2 === 0)
464
- return $r(e, n, s);
504
+ return Kr(e, n, s);
465
505
  try {
466
506
  const i = n.buffer.slice(
467
507
  n.byteOffset,
@@ -469,18 +509,18 @@ async function Hr(e, t, r = Sr) {
469
509
  );
470
510
  return await e.decodeAudioData(i);
471
511
  } catch {
472
- return $r(e, n, s);
512
+ return Kr(e, n, s);
473
513
  }
474
514
  }
475
- function Zs(e, t) {
515
+ function ci(e, t) {
476
516
  for (const r of e)
477
517
  if (t >= r.wtime && t < r.wtime + r.wduration)
478
518
  return r;
479
519
  return null;
480
520
  }
481
- function Tn(e, t) {
521
+ function An(e, t) {
482
522
  const r = [], n = [];
483
- let s = null, i = !1, o = !1, a = !1, l = !1, f = 0, u = 0, c = 0, d = null, w = 1, b = t, h = !1, I = null, v = 0, x = !1, g = !1, k = 0, B = null, R = null, Y = null;
523
+ let s = null, i = !1, a = !1, o = !1, u = !1, f = 0, l = 0, c = 0, d = null, w = 1, b = t, h = !1, I = null, v = 0, x = !1, g = !1, k = 0, B = null, R = null, Y = null;
484
524
  const L = () => ({
485
525
  visemes: [],
486
526
  words: [],
@@ -505,19 +545,19 @@ function Tn(e, t) {
505
545
  for (const y of n)
506
546
  y.playbackRate.value = w;
507
547
  }, ee = () => {
508
- if (!(h || !l || i || g || n.length > 0 || r.length > 0)) {
509
- if (a && s && u > 0) {
510
- const y = (s.currentTime - u) * 1e3;
548
+ if (!(h || !u || i || g || n.length > 0 || r.length > 0)) {
549
+ if (o && s && l > 0) {
550
+ const y = (s.currentTime - l) * 1e3;
511
551
  if (y < v) {
512
552
  A();
513
553
  const E = w > 0 ? (v - y) / w : v - y;
514
554
  d = setTimeout(() => {
515
- h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
555
+ h || (a = !1, d = null, e.onSpeakingDone(), e.onNotify());
516
556
  }, Math.max(0, E));
517
557
  return;
518
558
  }
519
559
  }
520
- o = !1, A(), e.onSpeakingDone(), e.onNotify();
560
+ a = !1, A(), e.onSpeakingDone(), e.onNotify();
521
561
  }
522
562
  }, U = (y) => {
523
563
  const E = Ze(y);
@@ -525,10 +565,10 @@ function Tn(e, t) {
525
565
  e.onSpeakingDone(), e.onNotify();
526
566
  return;
527
567
  }
528
- o = !0, f = performance.now(), e.onSpeakingStart(), e.onNotify(), A();
568
+ a = !0, f = performance.now(), e.onSpeakingStart(), e.onNotify(), A();
529
569
  const N = w > 0 ? E / w : E;
530
570
  d = setTimeout(() => {
531
- h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
571
+ h || (a = !1, d = null, e.onSpeakingDone(), e.onNotify());
532
572
  }, N);
533
573
  }, te = (y, E, N, G) => {
534
574
  E.length !== 0 && (c = N, E.forEach((W) => {
@@ -548,16 +588,16 @@ function Tn(e, t) {
548
588
  N.length !== 0 && (c = G, N.forEach((p) => {
549
589
  const S = String(p.symbol ?? p.viseme ?? "").trim();
550
590
  if (!S) return;
551
- const C = Math.round((p.start ?? 0) * 1e3), ue = Math.max(1, Math.round((p.duration ?? 0) * 1e3)), ae = c + C, he = Zs(E, ae), ge = he ? Ns(he, ae) : 0;
591
+ const C = Math.round((p.start ?? 0) * 1e3), ue = Math.max(1, Math.round((p.duration ?? 0) * 1e3)), oe = c + C, he = ci(E, oe), ge = he ? Ws(he, oe) : 0;
552
592
  let ve;
553
- ws($) === "oculus_direct" ? (ve = Fs(S), ve === "U" && he && _r(he.word, ge) && (ve = "FF")) : ve = Hs(
593
+ _s($) === "oculus_direct" ? (ve = Ns(S), ve === "U" && he && _r(he.word, ge) && (ve = "FF")) : ve = Gs(
554
594
  S,
555
595
  he?.word ?? "",
556
596
  ge
557
597
  ), y.push({
558
598
  viseme: ve,
559
599
  weight: 1,
560
- vtime: ae,
600
+ vtime: oe,
561
601
  vduration: ue
562
602
  });
563
603
  }), e.onNotify());
@@ -579,13 +619,13 @@ function Tn(e, t) {
579
619
  if (!s) return 0;
580
620
  const N = s, G = N.currentTime, W = G + 0.02;
581
621
  if (E.isFirstAudio) {
582
- u <= 0 && (u = W);
622
+ l <= 0 && (l = W);
583
623
  const p = (W - G) * 1e3;
584
624
  f = performance.now() + p;
585
625
  }
586
626
  E.onBeforeStart?.(W);
587
627
  const $ = N.createBufferSource();
588
- return $.buffer = y, $.playbackRate.value = w, $.connect(N.destination), I && $.connect(I), n.push($), h ? (n.pop(), W) : (E.isFirstAudio && (o = !0, e.onSpeakingStart()), $.onended = () => {
628
+ return $.buffer = y, $.playbackRate.value = w, $.connect(N.destination), I && $.connect(I), n.push($), h ? (n.pop(), W) : (E.isFirstAudio && (a = !0, e.onSpeakingStart()), $.onended = () => {
589
629
  const p = n.indexOf($);
590
630
  p >= 0 && n.splice(p, 1), e.onNotify(), !h && (B && R ? fe(B, R) : ee());
591
631
  }, $.start(W), W);
@@ -602,16 +642,16 @@ function Tn(e, t) {
602
642
  if (h) return;
603
643
  const W = r[0];
604
644
  if (!W) return;
605
- const $ = !o;
645
+ const $ = !a;
606
646
  if (x && (e.shouldHoldForWarmup?.() ?? !1) && (g || $ && W.newStream) || g) {
607
647
  de(W.utterance, y, E);
608
648
  for (const C of r) {
609
649
  if (h) return;
610
- C.audioBuffer || (C.audioBuffer = await Hr(
650
+ C.audioBuffer || (C.audioBuffer = await qr(
611
651
  G,
612
652
  C.audio,
613
653
  C.sampleRate
614
- )), a = !0, g || (g = !0, k = 0, C.newStream && C.onNewStream?.()), C.visemesQueued || (z(
654
+ )), o = !0, g || (g = !0, k = 0, C.newStream && C.onNewStream?.()), C.visemesQueued || (z(
615
655
  y,
616
656
  E,
617
657
  C.visemes,
@@ -628,16 +668,16 @@ function Tn(e, t) {
628
668
  return;
629
669
  }
630
670
  const S = r.shift();
631
- if (!S || (S.audioBuffer || (S.audioBuffer = await Hr(
671
+ if (!S || (S.audioBuffer || (S.audioBuffer = await qr(
632
672
  G,
633
673
  S.audio,
634
674
  S.sampleRate
635
675
  )), h)) return;
636
- a = !0, A(), de(S.utterance, y, E), S.visemesQueued = !1, S.newStream && S.onNewStream?.(), J(S.audioBuffer, {
637
- isFirstAudio: !o,
676
+ o = !0, A(), de(S.utterance, y, E), S.visemesQueued = !1, S.newStream && S.onNewStream?.(), J(S.audioBuffer, {
677
+ isFirstAudio: !a,
638
678
  isFirstOfStream: !1,
639
679
  onBeforeStart: (C) => {
640
- u = C, c = 0, f = performance.now() + (C - G.currentTime) * 1e3, z(
680
+ l = C, c = 0, f = performance.now() + (C - G.currentTime) * 1e3, z(
641
681
  y,
642
682
  E,
643
683
  S.visemes,
@@ -682,11 +722,11 @@ function Tn(e, t) {
682
722
  }
683
723
  },
684
724
  resetForNewStream: (y) => {
685
- h = !1, l = !1, b = y, v = 0;
725
+ h = !1, u = !1, b = y, v = 0;
686
726
  },
687
727
  /** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
688
728
  resumeBotStream: () => {
689
- h = !1, l = !1;
729
+ h = !1, u = !1;
690
730
  },
691
731
  /** After interrupt — allow the next utterance to queue/play again. */
692
732
  clearAborted: () => {
@@ -698,10 +738,10 @@ function Tn(e, t) {
698
738
  s || (s = new y()), s.state === "suspended" && await s.resume(), s && !I && (I = s.createMediaStreamDestination());
699
739
  },
700
740
  stop: () => {
701
- h = !0, A(), M(), r.length = 0, i = !1, o = !1, a = !1, l = !1, c = 0, u = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
741
+ h = !0, A(), M(), r.length = 0, i = !1, a = !1, o = !1, u = !1, c = 0, l = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
702
742
  },
703
743
  markStreamComplete: (y) => {
704
- if (v = Math.max(v, Ze(y)), l = !0, !a && y.length > 0) {
744
+ if (v = Math.max(v, Ze(y)), u = !0, !o && y.length > 0) {
705
745
  U(y);
706
746
  return;
707
747
  }
@@ -710,7 +750,7 @@ function Tn(e, t) {
710
750
  playAudioChunk: async (y, E, N, G, W, $, p) => {
711
751
  if (h) return;
712
752
  B = y, R = E;
713
- const S = kn(p?.sampleRate), C = p?.newStream === !0, ue = L();
753
+ const S = In(p?.sampleRate), C = p?.newStream === !0, ue = L();
714
754
  if (!N?.trim()) {
715
755
  if (G.length === 0 && W.length === 0) return;
716
756
  de(ue, y, E), C && p?.onNewStream?.(), z(
@@ -721,7 +761,7 @@ function Tn(e, t) {
721
761
  0,
722
762
  !0,
723
763
  b
724
- ), v = Ze(y), !o && v > 0 && U(y), e.onNotify();
764
+ ), v = Ze(y), !a && v > 0 && U(y), e.onNotify();
725
765
  return;
726
766
  }
727
767
  r.push({
@@ -750,19 +790,19 @@ function Tn(e, t) {
750
790
  b
751
791
  ), $.segmentOffsetMs = 0, v = Ze(y);
752
792
  },
753
- getPlaybackElapsedMs: () => a && s && u > 0 ? Math.max(
793
+ getPlaybackElapsedMs: () => o && s && l > 0 ? Math.max(
754
794
  0,
755
- (s.currentTime - u) * 1e3
756
- ) : o ? Math.max(0, (performance.now() - f) * w) : 0,
757
- isSpeaking: () => o ? !0 : !a || !s || u <= 0 ? !1 : (s.currentTime - u) * 1e3 < v,
795
+ (s.currentTime - l) * 1e3
796
+ ) : a ? Math.max(0, (performance.now() - f) * w) : 0,
797
+ isSpeaking: () => a ? !0 : !o || !s || l <= 0 ? !1 : (s.currentTime - l) * 1e3 < v,
758
798
  getVoiceStream: () => I ? I.stream : null,
759
799
  getPlaybackStartPerf: () => f,
760
800
  /** User spoke over the bot — drop in-flight chunks until the next utterance. */
761
801
  bargeIn: () => {
762
- h = !0, l = !1, A(), M(), r.length = 0, i = !1, o = !1, a = !1, c = 0, u = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
802
+ h = !0, u = !1, A(), M(), r.length = 0, i = !1, a = !1, o = !1, c = 0, l = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
763
803
  },
764
804
  interrupt: () => {
765
- h = !0, l = !1, A(), M(), r.length = 0, i = !1, o = !1, a = !1, c = 0, u = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
805
+ h = !0, u = !1, A(), M(), r.length = 0, i = !1, a = !1, o = !1, c = 0, l = 0, f = 0, v = 0, B = null, R = null, Y = null, T();
766
806
  }
767
807
  };
768
808
  }
@@ -772,18 +812,18 @@ function jt(e, t) {
772
812
  t < n.vtime || t >= n.vtime + n.vduration || (!r || n.vtime >= r.vtime) && (r = n);
773
813
  return r ? r.viseme : "sil";
774
814
  }
775
- function En(e, t, r = 120) {
815
+ function Pn(e, t, r = 120) {
776
816
  const n = jt(e, t);
777
817
  if (n !== "sil") return n;
778
818
  let s = null;
779
819
  for (const i of e) {
780
820
  if (i.vtime > t) break;
781
- const o = i.vtime + i.vduration;
782
- o <= t && t - o <= r && (s = i);
821
+ const a = i.vtime + i.vduration;
822
+ a <= t && t - a <= r && (s = i);
783
823
  }
784
824
  return s?.viseme ?? "sil";
785
825
  }
786
- function ei(e, t, r = 400) {
826
+ function ui(e, t, r = 400) {
787
827
  const n = t - r;
788
828
  let s = 0;
789
829
  for (const i of e)
@@ -791,13 +831,13 @@ function ei(e, t, r = 400) {
791
831
  else break;
792
832
  s > 0 && e.splice(0, s);
793
833
  }
794
- function Fa(e, t) {
834
+ function Go(e, t) {
795
835
  for (const r of e)
796
836
  if (t >= r.wtime && t < r.wtime + r.wduration)
797
837
  return r;
798
838
  return null;
799
839
  }
800
- function ti(e, t) {
840
+ function li(e, t) {
801
841
  const r = e.trim();
802
842
  if (!r) return null;
803
843
  try {
@@ -807,15 +847,15 @@ function ti(e, t) {
807
847
  return null;
808
848
  }
809
849
  }
810
- const vr = 0.5, br = 1.5, In = "Olivia", An = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Yt = 0.85;
811
- function Kr(e, t = Pt, r = {}) {
812
- const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], o = [], a = [];
813
- let l = "", f = "neutral", u = "", c = ft;
850
+ const br = 0.5, kr = 1.5, xn = "Olivia", Mn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Yt = 0.85;
851
+ function Gr(e, t = Pt, r = {}) {
852
+ const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], a = [], o = [];
853
+ let u = "", f = "neutral", l = "", c = ft;
814
854
  const d = /* @__PURE__ */ new Set();
815
855
  let w = 0, b = null;
816
856
  const h = () => d.forEach((L) => L());
817
857
  let I = () => !1;
818
- const v = Tn(
858
+ const v = An(
819
859
  {
820
860
  onSpeakingStart: () => e("speaking"),
821
861
  onSpeakingDone: () => e("done"),
@@ -823,7 +863,7 @@ function Kr(e, t = Pt, r = {}) {
823
863
  shouldHoldForWarmup: () => I()
824
864
  },
825
865
  ft
826
- ), x = () => v.getPlaybackElapsedMs(), g = (L, T = l) => {
866
+ ), x = () => v.getPlaybackElapsedMs(), g = (L, T = u) => {
827
867
  if (!r.onLipsyncDebug) return;
828
868
  const A = x(), M = s;
829
869
  r.onLipsyncDebug({
@@ -834,7 +874,7 @@ function Kr(e, t = Pt, r = {}) {
834
874
  playbackElapsedMs: A,
835
875
  queueLength: M.length,
836
876
  activeViseme: jt(M, A),
837
- segments: a.map((D) => ({
877
+ segments: o.map((D) => ({
838
878
  ...D,
839
879
  visemes: [...D.visemes]
840
880
  }))
@@ -850,7 +890,7 @@ function Kr(e, t = Pt, r = {}) {
850
890
  const ee = s.slice(T), U = A.filter(
851
891
  (te) => String(te.symbol ?? te.viseme ?? "").trim()
852
892
  );
853
- a.push({
893
+ o.push({
854
894
  spokenText: L,
855
895
  audioOffsetMs: ee[0]?.vtime ?? 0,
856
896
  isNewSegment: M,
@@ -869,33 +909,33 @@ function Kr(e, t = Pt, r = {}) {
869
909
  })
870
910
  });
871
911
  }, R = () => {
872
- v.stop(), s.length = 0, i.length = 0, o.length = 0, f = "neutral", a.length = 0, l = "", e("idle"), k("reset"), h();
912
+ v.stop(), s.length = 0, i.length = 0, a.length = 0, f = "neutral", o.length = 0, u = "", e("idle"), k("reset"), h();
873
913
  };
874
914
  return {
875
915
  setDeveloperToken: (L) => {
876
- u = L;
916
+ l = L;
877
917
  },
878
918
  setTtsEngineId: (L) => {
879
919
  c = L;
880
920
  },
881
921
  getTtsEngineId: () => c,
882
922
  speak: async (L, T) => {
883
- R(), e("loading"), l = L, a.length = 0;
884
- const A = u.trim();
923
+ R(), e("loading"), u = L, o.length = 0;
924
+ const A = l.trim();
885
925
  if (!A)
886
926
  throw new Error("Developer token required for avatar_ttsWithPoses");
887
927
  const M = T?.ttsEngineId ?? c ?? ft;
888
928
  v.resetForNewStream(M), v.setStreamTtsEngineId(M);
889
- const D = T?.voiceId ?? In, ee = T?.speakingRate ?? Yt, U = Math.max(
890
- vr,
891
- Math.min(br, ee)
929
+ const D = T?.voiceId ?? xn, ee = T?.speakingRate ?? Yt, U = Math.max(
930
+ br,
931
+ Math.min(kr, ee)
892
932
  ), te = {
893
933
  user_query: L,
894
934
  ttsEngineId: M,
895
935
  speakingRate: U,
896
936
  tenant: "aiTwin"
897
937
  };
898
- dn.has(M) && (te.voice_id = D);
938
+ hn.has(M) && (te.voice_id = D);
899
939
  try {
900
940
  const X = await fetch(n, {
901
941
  method: "POST",
@@ -912,7 +952,7 @@ function Kr(e, t = Pt, r = {}) {
912
952
  const de = z.getReader(), ie = new TextDecoder();
913
953
  let J = "", fe = !0;
914
954
  const me = async (Se) => {
915
- const j = yn(Se);
955
+ const j = Sn(Se);
916
956
  if (j) {
917
957
  if (j.event === "audio") {
918
958
  const y = j.data.chunk, E = j.data.visemes ?? [], N = j.data.words ?? [], G = j.data.is_new_segment ?? !1, W = j.data.sample_rate, $ = s.length;
@@ -931,7 +971,7 @@ function Kr(e, t = Pt, r = {}) {
931
971
  $,
932
972
  E,
933
973
  G,
934
- ti(y, W)
974
+ li(y, W)
935
975
  ), k("audio_chunk", L);
936
976
  } else (E.length > 0 || N.length > 0) && (v.queueTimingsOnly(
937
977
  s,
@@ -951,11 +991,11 @@ function Kr(e, t = Pt, r = {}) {
951
991
  typeof y == "string" && y.trim() && (f = y.trim());
952
992
  const E = j.data.sentence_emotions;
953
993
  if (Array.isArray(E)) {
954
- o.length = 0;
994
+ a.length = 0;
955
995
  for (const N of E) {
956
996
  if (!N || typeof N != "object") continue;
957
997
  const G = N;
958
- o.push({
998
+ a.push({
959
999
  sentence_index: Number(G.sentence_index ?? 0),
960
1000
  text: String(G.text ?? ""),
961
1001
  sentiment: typeof G.sentiment == "string" ? G.sentiment : void 0,
@@ -992,7 +1032,7 @@ function Kr(e, t = Pt, r = {}) {
992
1032
  stop: R,
993
1033
  getVisemeQueue: () => s,
994
1034
  getWordQueue: () => i,
995
- getSentenceEmotions: () => o,
1035
+ getSentenceEmotions: () => a,
996
1036
  getStreamMood: () => f,
997
1037
  getPlaybackElapsedMs: () => v.getPlaybackElapsedMs(),
998
1038
  isSpeaking: () => v.isSpeaking(),
@@ -1009,8 +1049,8 @@ function Kr(e, t = Pt, r = {}) {
1009
1049
  subscribe: (L) => (d.add(L), () => d.delete(L))
1010
1050
  };
1011
1051
  }
1012
- const Pn = 16e3, xn = 16e3;
1013
- class ri extends Zn {
1052
+ const Cn = 16e3, Rn = 16e3;
1053
+ class fi extends rs {
1014
1054
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1015
1055
  async deserialize(t) {
1016
1056
  try {
@@ -1022,7 +1062,7 @@ class ri extends Zn {
1022
1062
  }
1023
1063
  }
1024
1064
  }
1025
- class ni extends Jn {
1065
+ class di extends ts {
1026
1066
  constructor() {
1027
1067
  super(
1028
1068
  !0,
@@ -1030,39 +1070,39 @@ class ni extends Jn {
1030
1070
  void 0,
1031
1071
  void 0,
1032
1072
  512,
1033
- Pn,
1034
- xn
1073
+ Cn,
1074
+ Rn
1035
1075
  );
1036
1076
  }
1037
1077
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
1038
1078
  bufferBotAudio(t, r) {
1039
1079
  }
1040
1080
  }
1041
- const si = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1042
- function ii(e) {
1043
- return si.test(e.trim());
1081
+ const mi = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1082
+ function hi(e) {
1083
+ return mi.test(e.trim());
1044
1084
  }
1045
- function ai(e) {
1085
+ function pi(e) {
1046
1086
  const t = e.replace(/\/$/, "");
1047
1087
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
1048
1088
  }
1049
- function oi(e) {
1089
+ function wi(e) {
1050
1090
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
1051
1091
  const t = e.authToken?.trim();
1052
1092
  if (!t)
1053
1093
  throw new Error(
1054
1094
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1055
1095
  );
1056
- const r = e.apiBase ?? Pt, n = new URL(`${ai(r)}/ws/voice`);
1096
+ const r = e.apiBase ?? Pt, n = new URL(`${pi(r)}/ws/voice`);
1057
1097
  n.searchParams.set("authToken", t), n.searchParams.set("tenant", "aiTwin");
1058
1098
  const s = e.voiceId?.trim();
1059
- s && ii(s) && n.searchParams.set("voiceId", s);
1099
+ s && hi(s) && n.searchParams.set("voiceId", s);
1060
1100
  const i = e.personaId?.trim();
1061
1101
  i && n.searchParams.set("personaId", i);
1062
- const o = e.speakingRate ?? Yt;
1102
+ const a = e.speakingRate ?? Yt;
1063
1103
  return n.searchParams.set(
1064
1104
  "speaking_rate",
1065
- String(Math.max(vr, Math.min(br, o)))
1105
+ String(Math.max(br, Math.min(kr, a)))
1066
1106
  ), e.ttsStream === !1 ? n.searchParams.set("tts_stream", "false") : n.searchParams.set("tts_stream", "true"), n.toString();
1067
1107
  }
1068
1108
  function sr(e, t) {
@@ -1079,7 +1119,7 @@ function sr(e, t) {
1079
1119
  });
1080
1120
  return r;
1081
1121
  }
1082
- function ci(e) {
1122
+ function gi(e) {
1083
1123
  if (!e || typeof e != "object") return null;
1084
1124
  const t = e, n = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
1085
1125
  return {
@@ -1090,12 +1130,12 @@ function ci(e) {
1090
1130
  function ir(e) {
1091
1131
  return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
1092
1132
  }
1093
- function ui(e) {
1133
+ function yi(e) {
1094
1134
  return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
1095
1135
  }
1096
- function li(e, t = {}) {
1136
+ function _i(e, t = {}) {
1097
1137
  const r = [], n = [], s = [], i = [];
1098
- let o = "", a = "neutral", l = gt, f = !1, u = null, c = null, d = { ...t }, w = 0, b = null;
1138
+ let a = "", o = "neutral", u = gt, f = !1, l = null, c = null, d = { ...t }, w = 0, b = null;
1099
1139
  const h = /* @__PURE__ */ new Set(), I = [];
1100
1140
  let v = !1, x = null, g = !0, k = "default";
1101
1141
  const B = /* @__PURE__ */ new Set();
@@ -1104,7 +1144,7 @@ function li(e, t = {}) {
1104
1144
  T != null && (clearTimeout(T), T = null);
1105
1145
  }, D = () => h.forEach((m) => m());
1106
1146
  let ee = () => !1;
1107
- const U = Tn(
1147
+ const U = An(
1108
1148
  {
1109
1149
  onSpeakingStart: () => e("speaking"),
1110
1150
  onSpeakingDone: () => {
@@ -1113,7 +1153,7 @@ function li(e, t = {}) {
1113
1153
  onNotify: D,
1114
1154
  shouldHoldForWarmup: () => ee()
1115
1155
  },
1116
- l
1156
+ u
1117
1157
  ), te = () => {
1118
1158
  if (x) return x;
1119
1159
  const m = new MessageChannel();
@@ -1123,13 +1163,13 @@ function li(e, t = {}) {
1123
1163
  }, x = m, m;
1124
1164
  }, X = (m) => {
1125
1165
  I.push(m), !v && (v = !0, te().port2.postMessage(null));
1126
- }, z = () => U.getPlaybackElapsedMs(), de = (m, P = o) => {
1166
+ }, z = () => U.getPlaybackElapsedMs(), de = (m, P = a) => {
1127
1167
  if (!d.onLipsyncDebug) return;
1128
1168
  const Q = z(), ce = r;
1129
1169
  d.onLipsyncDebug({
1130
1170
  event: m,
1131
1171
  spokenText: P,
1132
- mood: a,
1172
+ mood: o,
1133
1173
  playbackAnchorPerf: U.getPlaybackStartPerf(),
1134
1174
  playbackElapsedMs: Q,
1135
1175
  queueLength: ce.length,
@@ -1148,7 +1188,7 @@ function li(e, t = {}) {
1148
1188
  }, J = () => {
1149
1189
  g = !0, B.clear(), U.clearAborted();
1150
1190
  }, fe = () => {
1151
- const m = ui(u);
1191
+ const m = yi(l);
1152
1192
  if (m) {
1153
1193
  k = `bot-${Date.now()}`, m.interruptedTrackIds = { [k]: !0 };
1154
1194
  try {
@@ -1171,22 +1211,22 @@ function li(e, t = {}) {
1171
1211
  const P = m.context_id?.trim();
1172
1212
  P && B.add(P), M(), L = !1, I.length = 0, v = !1, R?.abort(), R = null, Y += 1, fe(), U.bargeIn(), j(), e("idle"), ie("interrupt"), D();
1173
1213
  }, j = () => {
1174
- r.length = 0, n.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
1214
+ r.length = 0, n.length = 0, i.length = 0, a = "", o = "neutral", s.length = 0;
1175
1215
  }, y = () => {
1176
1216
  U.stop(), j(), ie("reset"), D();
1177
1217
  }, E = () => {
1178
1218
  y(), e("idle"), D();
1179
1219
  }, N = (m, P) => {
1180
- typeof m.mood == "string" && m.mood.trim() && (a = m.mood.trim()), Array.isArray(m.sentence_emotions) && m.sentence_emotions.length > 0 && (P && (s.length = 0), s.push(
1181
- ...sr(m.sentence_emotions, a)
1220
+ typeof m.mood == "string" && m.mood.trim() && (o = m.mood.trim()), Array.isArray(m.sentence_emotions) && m.sentence_emotions.length > 0 && (P && (s.length = 0), s.push(
1221
+ ...sr(m.sentence_emotions, o)
1182
1222
  ));
1183
1223
  }, G = (m) => {
1184
1224
  if (me({ ...m, type: "avatar_metadata" }))
1185
1225
  return;
1186
1226
  J(), L = !0;
1187
1227
  const P = String(m.spoken_text ?? m.text ?? "").trim();
1188
- P && (o = P), U.resetForNewStream(l), typeof m.mood == "string" && m.mood.trim() && (a = m.mood.trim()), s.length = 0, s.push(
1189
- ...sr(m.sentence_emotions, a)
1228
+ P && (a = P), U.resetForNewStream(u), typeof m.mood == "string" && m.mood.trim() && (o = m.mood.trim()), s.length = 0, s.push(
1229
+ ...sr(m.sentence_emotions, o)
1190
1230
  ), Array.isArray(m.gestures) && m.gestures, ie("metadata", P), D();
1191
1231
  }, W = (m, P, Q, ce) => {
1192
1232
  if (!d.onLipsyncDebug) return;
@@ -1215,7 +1255,7 @@ function li(e, t = {}) {
1215
1255
  if (me(m)) return;
1216
1256
  M(), ir(m) && J();
1217
1257
  const P = String(m.spoken_text ?? m.text ?? "").trim(), Q = ir(m), ce = m.visemes ?? [], ye = m.words ?? [], Ge = String(m.chunk ?? "").trim(), le = L;
1218
- le && (L = !1), P && (o = P), N(m, Q), le ? U.resetForNewStream(l) : Q && U.resumeBotStream();
1258
+ le && (L = !1), P && (a = P), N(m, Q), le ? U.resetForNewStream(u) : Q && U.resumeBotStream();
1219
1259
  const Ee = r.length;
1220
1260
  U.playAudioChunk(
1221
1261
  r,
@@ -1240,7 +1280,7 @@ function li(e, t = {}) {
1240
1280
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
1241
1281
  );
1242
1282
  const P = String(m.spoken_text ?? m.text ?? "").trim();
1243
- P && (o = P), N(m, !!m.is_new_segment);
1283
+ P && (a = P), N(m, !!m.is_new_segment);
1244
1284
  const Q = r.length;
1245
1285
  U.queueTimingsOnly(
1246
1286
  r,
@@ -1266,17 +1306,17 @@ function li(e, t = {}) {
1266
1306
  const ce = new AbortController();
1267
1307
  R = ce;
1268
1308
  const ye = ++Y;
1269
- J(), U.resetForNewStream(l), o = P;
1270
- const le = `${(d.apiBase ?? Pt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Ee = d.voiceId?.trim() || An, De = d.speakingRate ?? Yt, be = Math.max(
1271
- vr,
1272
- Math.min(br, De)
1309
+ J(), U.resetForNewStream(u), a = P;
1310
+ const le = `${(d.apiBase ?? Pt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Ee = d.voiceId?.trim() || Mn, De = d.speakingRate ?? Yt, be = Math.max(
1311
+ br,
1312
+ Math.min(kr, De)
1273
1313
  ), Ue = {
1274
1314
  user_query: P,
1275
- ttsEngineId: l,
1315
+ ttsEngineId: u,
1276
1316
  speakingRate: be,
1277
1317
  tenant: "aiTwin"
1278
1318
  };
1279
- dn.has(l) && (Ue.voice_id = Ee);
1319
+ hn.has(u) && (Ue.voice_id = Ee);
1280
1320
  try {
1281
1321
  const Fe = await fetch(le, {
1282
1322
  method: "POST",
@@ -1293,10 +1333,10 @@ function li(e, t = {}) {
1293
1333
  if (!Ve) throw new Error("No response body");
1294
1334
  const Mt = Ve.getReader(), nt = new TextDecoder();
1295
1335
  let We = "", St = !0;
1296
- const oe = async (st) => {
1336
+ const ae = async (st) => {
1297
1337
  if (ye !== Y || ce.signal.aborted || !g)
1298
1338
  return;
1299
- const pe = yn(st);
1339
+ const pe = Sn(st);
1300
1340
  if (pe) {
1301
1341
  if (pe.event === "audio") {
1302
1342
  const Ae = pe.data.chunk, Ie = pe.data.visemes ?? [], it = pe.data.words ?? [], $e = pe.data.is_new_segment ?? !1, Ct = pe.data.sample_rate;
@@ -1320,10 +1360,10 @@ function li(e, t = {}) {
1320
1360
  );
1321
1361
  } else if (pe.event === "metadata") {
1322
1362
  const Ae = pe.data.mood;
1323
- typeof Ae == "string" && Ae.trim() && (a = Ae.trim());
1363
+ typeof Ae == "string" && Ae.trim() && (o = Ae.trim());
1324
1364
  const Ie = pe.data.sentence_emotions;
1325
1365
  Array.isArray(Ie) && (s.length = 0, s.push(
1326
- ...sr(Ie, a)
1366
+ ...sr(Ie, o)
1327
1367
  )), D();
1328
1368
  } else if (pe.event === "error")
1329
1369
  throw new Error(
@@ -1338,9 +1378,9 @@ function li(e, t = {}) {
1338
1378
 
1339
1379
  `);
1340
1380
  We = Ae.pop() ?? "";
1341
- for (const Ie of Ae) await oe(Ie);
1381
+ for (const Ie of Ae) await ae(Ie);
1342
1382
  if (st) {
1343
- We.trim() && await oe(We.trim()), ye === Y && !ce.signal.aborted && g && U.markStreamComplete(r);
1383
+ We.trim() && await ae(We.trim()), ye === Y && !ce.signal.aborted && g && U.markStreamComplete(r);
1344
1384
  break;
1345
1385
  }
1346
1386
  }
@@ -1351,7 +1391,7 @@ function li(e, t = {}) {
1351
1391
  R === ce && (R = null);
1352
1392
  }
1353
1393
  }, C = (m) => {
1354
- const P = ci(m);
1394
+ const P = gi(m);
1355
1395
  if (!P) {
1356
1396
  console.warn("[realtimeVoice] server message with no payload", m);
1357
1397
  return;
@@ -1379,12 +1419,12 @@ function li(e, t = {}) {
1379
1419
  S(P);
1380
1420
  break;
1381
1421
  }
1382
- }, ue = () => u || (c = new ni(), u = new Xn({
1383
- transport: new Qn({
1422
+ }, ue = () => l || (c = new di(), l = new Zn({
1423
+ transport: new es({
1384
1424
  mediaManager: c,
1385
- serializer: new ri(),
1386
- recorderSampleRate: Pn,
1387
- playerSampleRate: xn
1425
+ serializer: new fi(),
1426
+ recorderSampleRate: Cn,
1427
+ playerSampleRate: Rn
1388
1428
  }),
1389
1429
  enableCam: !1,
1390
1430
  enableMic: !0,
@@ -1422,22 +1462,22 @@ function li(e, t = {}) {
1422
1462
  d.onBotOutput?.(m.text);
1423
1463
  }
1424
1464
  }
1425
- }), u);
1465
+ }), l);
1426
1466
  return {
1427
1467
  setDeveloperToken: (m) => {
1428
1468
  },
1429
1469
  setTtsEngineId: (m) => {
1430
- l = m, U.setStreamTtsEngineId(m);
1470
+ u = m, U.setStreamTtsEngineId(m);
1431
1471
  },
1432
- getTtsEngineId: () => l,
1472
+ getTtsEngineId: () => u,
1433
1473
  speak: async (m, P) => {
1434
1474
  const Q = m.trim();
1435
1475
  if (Q) {
1436
- if (!u || !f)
1476
+ if (!l || !f)
1437
1477
  throw new Error(
1438
1478
  "Realtime voice is not connected. Call connect() first."
1439
1479
  );
1440
- y(), await u.sendText(Q);
1480
+ y(), await l.sendText(Q);
1441
1481
  }
1442
1482
  },
1443
1483
  stop: () => {
@@ -1451,7 +1491,7 @@ function li(e, t = {}) {
1451
1491
  e("loading");
1452
1492
  const P = ue();
1453
1493
  await P.initDevices();
1454
- const Q = oi(d);
1494
+ const Q = wi(d);
1455
1495
  console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", Q);
1456
1496
  try {
1457
1497
  await P.connect({ wsUrl: Q });
@@ -1463,9 +1503,9 @@ function li(e, t = {}) {
1463
1503
  f = !0, e("idle"), D();
1464
1504
  },
1465
1505
  disconnect: async () => {
1466
- if (M(), L = !1, I.length = 0, v = !1, R?.abort(), R = null, Y += 1, J(), u)
1506
+ if (M(), L = !1, I.length = 0, v = !1, R?.abort(), R = null, Y += 1, J(), l)
1467
1507
  try {
1468
- await u.disconnect();
1508
+ await l.disconnect();
1469
1509
  } catch (m) {
1470
1510
  console.error("[realtimeVoice] disconnect failed:", m);
1471
1511
  }
@@ -1478,7 +1518,7 @@ function li(e, t = {}) {
1478
1518
  getVisemeQueue: () => r,
1479
1519
  getWordQueue: () => n,
1480
1520
  getSentenceEmotions: () => s,
1481
- getStreamMood: () => a,
1521
+ getStreamMood: () => o,
1482
1522
  getPlaybackElapsedMs: z,
1483
1523
  isSpeaking: () => U.isSpeaking(),
1484
1524
  isWarmingUp: () => U.isWarmingUp(),
@@ -1494,13 +1534,13 @@ function li(e, t = {}) {
1494
1534
  subscribe: (m) => (h.add(m), () => h.delete(m))
1495
1535
  };
1496
1536
  }
1497
- function Mn(e, t, r) {
1537
+ function Dn(e, t, r) {
1498
1538
  return {
1499
1539
  width: e.crop?.source_width ?? t,
1500
1540
  height: e.crop?.source_height ?? r
1501
1541
  };
1502
1542
  }
1503
- function Cn(e, t) {
1543
+ function Bn(e, t) {
1504
1544
  const r = e.crop;
1505
1545
  return {
1506
1546
  x: t?.source_x ?? r?.x ?? 0,
@@ -1509,25 +1549,25 @@ function Cn(e, t) {
1509
1549
  height: t?.source_h ?? r?.height ?? e.frame_height ?? 0
1510
1550
  };
1511
1551
  }
1512
- function Rn(e) {
1552
+ function Fn(e) {
1513
1553
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1514
1554
  }
1515
1555
  async function yt(e, t) {
1516
1556
  const r = await fetch(e);
1517
1557
  if (!r.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1518
1558
  const n = await r.arrayBuffer();
1519
- return Ps(n, t);
1559
+ return Cs(n, t);
1520
1560
  }
1521
- async function Dn(e, t) {
1561
+ async function Ln(e, t) {
1522
1562
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1523
1563
  const r = await yt(e, t), n = new TextDecoder().decode(r);
1524
1564
  return JSON.parse(n);
1525
1565
  }
1526
- async function fi(e) {
1566
+ async function Si(e) {
1527
1567
  const t = new Blob([e], { type: "image/webp" });
1528
1568
  return createImageBitmap(t);
1529
1569
  }
1530
- async function di(e) {
1570
+ async function vi(e) {
1531
1571
  const t = new Blob([e], { type: "image/webp" }), r = URL.createObjectURL(t);
1532
1572
  return new Promise((n, s) => {
1533
1573
  const i = new Image();
@@ -1538,11 +1578,11 @@ async function di(e) {
1538
1578
  }, i.src = r;
1539
1579
  });
1540
1580
  }
1541
- async function mi(e) {
1581
+ async function bi(e) {
1542
1582
  const t = new Blob([e], { type: "image/png" });
1543
1583
  return createImageBitmap(t);
1544
1584
  }
1545
- async function hi(e) {
1585
+ async function ki(e) {
1546
1586
  const t = new Blob([e], { type: "image/png" }), r = URL.createObjectURL(t);
1547
1587
  return new Promise((n, s) => {
1548
1588
  const i = new Image();
@@ -1553,28 +1593,28 @@ async function hi(e) {
1553
1593
  }, i.src = r;
1554
1594
  });
1555
1595
  }
1556
- function pi(e) {
1596
+ function Ti(e) {
1557
1597
  const t = new Blob([e], { type: "video/mp4" });
1558
1598
  return URL.createObjectURL(t);
1559
1599
  }
1560
- async function wi(e) {
1561
- const t = Rs();
1600
+ async function Ei(e) {
1601
+ const t = Fs();
1562
1602
  if (!xt()) return t;
1563
1603
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1564
1604
  const r = await yt(t, e);
1565
- return pi(r);
1605
+ return Ti(r);
1566
1606
  }
1567
1607
  function dt(e, t) {
1568
1608
  return `${e}/${t}_minus_sil.png`;
1569
1609
  }
1570
- const Bn = 5;
1610
+ const On = 5;
1571
1611
  function Xt(e) {
1572
1612
  const t = e?.composite_threshold;
1573
1613
  if (typeof t == "number" && t > 0) return t;
1574
1614
  const r = e?.crop?.content_threshold;
1575
- return typeof r == "number" && r > 0 ? r : Bn;
1615
+ return typeof r == "number" && r > 0 ? r : On;
1576
1616
  }
1577
- const La = [
1617
+ const zo = [
1578
1618
  "aa",
1579
1619
  "E",
1580
1620
  "I",
@@ -1593,7 +1633,7 @@ const La = [
1593
1633
  "t01_0.25",
1594
1634
  "t02_0.50",
1595
1635
  "t03_0.75"
1596
- ], gi = dr.length, qr = /* @__PURE__ */ new Set([
1636
+ ], Ii = dr.length, zr = /* @__PURE__ */ new Set([
1597
1637
  "aa__kk",
1598
1638
  "aa__nn",
1599
1639
  "aa__sil",
@@ -1700,16 +1740,16 @@ const La = [
1700
1740
  "U__nn",
1701
1741
  "U__sil"
1702
1742
  ]);
1703
- function Gr(e, t) {
1743
+ function jr(e, t) {
1704
1744
  return `${e}__${t}`;
1705
1745
  }
1706
- function zr(e, t) {
1746
+ function Yr(e, t) {
1707
1747
  return `pairs/${e}/${t}_minus_sil.png`;
1708
1748
  }
1709
1749
  function It(e) {
1710
1750
  return `${e}_minus_sil.png`;
1711
1751
  }
1712
- function kr(e, t) {
1752
+ function Tr(e, t) {
1713
1753
  if (t.has(e)) return e;
1714
1754
  const r = /^pairs\/([^/]+)\//.exec(e);
1715
1755
  if (!r) return null;
@@ -1718,57 +1758,57 @@ function kr(e, t) {
1718
1758
  const s = It(n);
1719
1759
  return t.has(s) ? s : null;
1720
1760
  }
1721
- function Fn(e, t) {
1761
+ function Nn(e, t) {
1722
1762
  return e.filter((r) => t.has(r));
1723
1763
  }
1724
- function yi(e, t, r) {
1725
- const n = Tr(e, t);
1726
- return Fn(n, r).length > 0;
1764
+ function Ai(e, t, r) {
1765
+ const n = Er(e, t);
1766
+ return Nn(n, r).length > 0;
1727
1767
  }
1728
- function Tr(e, t) {
1768
+ function Er(e, t) {
1729
1769
  if (e === t) return [];
1730
- const r = [], n = Gr(e, t);
1731
- if (qr.has(n)) {
1770
+ const r = [], n = jr(e, t);
1771
+ if (zr.has(n)) {
1732
1772
  for (const i of dr)
1733
- r.push(zr(n, i));
1773
+ r.push(Yr(n, i));
1734
1774
  return r;
1735
1775
  }
1736
- const s = Gr(t, e);
1737
- if (qr.has(s)) {
1738
- for (let i = gi - 1; i >= 0; i--)
1739
- r.push(zr(s, dr[i]));
1776
+ const s = jr(t, e);
1777
+ if (zr.has(s)) {
1778
+ for (let i = Ii - 1; i >= 0; i--)
1779
+ r.push(Yr(s, dr[i]));
1740
1780
  return r;
1741
1781
  }
1742
1782
  return [];
1743
1783
  }
1744
- function _i(e) {
1784
+ function Pi(e) {
1745
1785
  return e < 16 ? [1] : e < 24 ? [1] : e < 35 ? [0, 1, 2] : [0, 1, 2];
1746
1786
  }
1747
- function Si(e, t) {
1748
- return _i(t).map((n) => e[n]).filter((n) => n != null);
1787
+ function xi(e, t) {
1788
+ return Pi(t).map((n) => e[n]).filter((n) => n != null);
1749
1789
  }
1750
- function vi(e, t, r, n) {
1790
+ function Mi(e, t, r, n) {
1751
1791
  if (n <= 0) return 0;
1752
- const i = Math.max(1, r - t) / n, o = e - t, a = Math.floor(o / i);
1753
- return Math.min(n - 1, Math.max(0, a));
1792
+ const i = Math.max(1, r - t) / n, a = e - t, o = Math.floor(a / i);
1793
+ return Math.min(n - 1, Math.max(0, o));
1754
1794
  }
1755
- function Ln(e, t, r) {
1795
+ function Un(e, t, r) {
1756
1796
  if (!r) return `${e}/${t}`;
1757
1797
  const n = t.split("/").pop() ?? t, s = n.includes(".") ? n.slice(0, n.lastIndexOf(".")) : n;
1758
1798
  return `${e}/${s}.bin`;
1759
1799
  }
1760
- const bi = [0.32, 0.24, 0.16, 0.08, 0], ki = bi.map(
1800
+ const Ci = [0.32, 0.24, 0.16, 0.08, 0], Ri = Ci.map(
1761
1801
  (e) => `eyes_${e.toFixed(2)}`
1762
- ), Ti = [
1802
+ ), Di = [
1763
1803
  "eyes_0.32",
1764
1804
  "eyes_0.16",
1765
1805
  "eyes_0.00"
1766
- ], Ei = [
1806
+ ], Bi = [
1767
1807
  "eyes_0.32",
1768
1808
  "eyes_0.16",
1769
1809
  "eyes_0.08",
1770
1810
  "eyes_0.00"
1771
- ], Be = 2, Ii = -30, Kt = 20, Ai = {
1811
+ ], Be = 2, Fi = -30, Kt = 20, Li = {
1772
1812
  fear: -20,
1773
1813
  anger: -20,
1774
1814
  sad: -10,
@@ -1781,38 +1821,38 @@ function At(e) {
1781
1821
  return `brow_${e}`;
1782
1822
  }
1783
1823
  function ht(e) {
1784
- return Ai[e];
1824
+ return Li[e];
1785
1825
  }
1786
1826
  function Ne(e) {
1787
- return Math.max(Ii, Math.min(Kt, e));
1827
+ return Math.max(Fi, Math.min(Kt, e));
1788
1828
  }
1789
- function Pi(e, t) {
1829
+ function Oi(e, t) {
1790
1830
  if (e === t) return [];
1791
1831
  const r = e < t, n = r ? Be : -Be, s = [];
1792
1832
  let i = e;
1793
1833
  if (i % Be !== 0) {
1794
- const o = r ? Math.ceil(i / Be) * Be : Math.floor(i / Be) * Be, a = Ne(o);
1795
- if (r ? a >= t : a <= t)
1834
+ const a = r ? Math.ceil(i / Be) * Be : Math.floor(i / Be) * Be, o = Ne(a);
1835
+ if (r ? o >= t : o <= t)
1796
1836
  return [t];
1797
- i = a, s.push(i);
1837
+ i = o, s.push(i);
1798
1838
  }
1799
1839
  for (; ; ) {
1800
- const o = i + n;
1801
- if (r ? o >= t : o <= t) {
1840
+ const a = i + n;
1841
+ if (r ? a >= t : a <= t) {
1802
1842
  t !== i && s.push(t);
1803
1843
  break;
1804
1844
  }
1805
- i = o, s.push(i);
1845
+ i = a, s.push(i);
1806
1846
  }
1807
1847
  return s;
1808
1848
  }
1809
- function jr(e) {
1849
+ function Xr(e) {
1810
1850
  const t = Ne(e);
1811
1851
  if (t % Be === 0) return [t];
1812
1852
  const r = Math.floor(t / Be) * Be, n = Math.min(Kt, r + Be), s = Ne(r);
1813
1853
  return t - s <= n - t ? s === n ? [s] : [s, n] : s === n ? [n] : [n, s];
1814
1854
  }
1815
- const Oa = [
1855
+ const jo = [
1816
1856
  "fear",
1817
1857
  "anger",
1818
1858
  "sad",
@@ -1820,7 +1860,7 @@ const Oa = [
1820
1860
  "love",
1821
1861
  "happy",
1822
1862
  "disgust"
1823
- ], xi = {
1863
+ ], Ni = {
1824
1864
  fear: "fear",
1825
1865
  afraid: "fear",
1826
1866
  anxiety: "fear",
@@ -1845,21 +1885,21 @@ const Oa = [
1845
1885
  };
1846
1886
  function Ye(e, t = "neutral") {
1847
1887
  const r = String(e ?? "").trim().toLowerCase();
1848
- return r ? xi[r] ?? t : t;
1888
+ return r ? Ni[r] ?? t : t;
1849
1889
  }
1850
- function On(e) {
1890
+ function Vn(e) {
1851
1891
  return e === 0 ? null : dt(At(e), "eyes_standard");
1852
1892
  }
1853
- function Nn(e) {
1854
- return On(ht(e));
1893
+ function Wn(e) {
1894
+ return Vn(ht(e));
1855
1895
  }
1856
- const Mi = {
1896
+ const Ui = {
1857
1897
  [-20]: "anger",
1858
1898
  [-10]: "sad",
1859
1899
  0: "neutral",
1860
1900
  10: "disgust"
1861
1901
  };
1862
- function Er(e, t) {
1902
+ function Ir(e, t) {
1863
1903
  if (!e) return null;
1864
1904
  if (t(e)) return e;
1865
1905
  const r = e.match(
@@ -1867,15 +1907,15 @@ function Er(e, t) {
1867
1907
  );
1868
1908
  if (r) {
1869
1909
  const s = Number(r[1]), i = r[2];
1870
- for (const a of jr(s)) {
1871
- if (a === s) continue;
1872
- const l = dt(At(a), i);
1873
- if (t(l)) return l;
1910
+ for (const o of Xr(s)) {
1911
+ if (o === s) continue;
1912
+ const u = dt(At(o), i);
1913
+ if (t(u)) return u;
1874
1914
  }
1875
- const o = Mi[s];
1876
- if (o) {
1877
- const a = dt(o, i);
1878
- if (t(a)) return a;
1915
+ const a = Ui[s];
1916
+ if (a) {
1917
+ const o = dt(a, i);
1918
+ if (t(o)) return o;
1879
1919
  }
1880
1920
  return null;
1881
1921
  }
@@ -1883,48 +1923,48 @@ function Er(e, t) {
1883
1923
  /^(fear|anger|sad|neutral|love|happy|disgust)\/(eyes_[^/]+)_minus_sil\.png$/
1884
1924
  );
1885
1925
  if (n) {
1886
- const s = n[1], i = n[2], o = ht(s);
1887
- for (const a of [o, ...jr(o)]) {
1888
- const l = dt(At(a), i);
1889
- if (t(l)) return l;
1926
+ const s = n[1], i = n[2], a = ht(s);
1927
+ for (const o of [a, ...Xr(a)]) {
1928
+ const u = dt(At(o), i);
1929
+ if (t(u)) return u;
1890
1930
  }
1891
1931
  }
1892
1932
  return null;
1893
1933
  }
1894
- function Yr(e, t) {
1934
+ function Qr(e, t) {
1895
1935
  const r = At(ht(e));
1896
- return !t || t === "eyes_standard" ? Nn(e) : e === "neutral" && t === "eyes_standard" ? null : dt(r, t);
1936
+ return !t || t === "eyes_standard" ? Wn(e) : e === "neutral" && t === "eyes_standard" ? null : dt(r, t);
1897
1937
  }
1898
- function Ci(e, t) {
1938
+ function Vi(e, t) {
1899
1939
  const r = [];
1900
1940
  for (const n of t)
1901
- r.push(Yr(e, n));
1941
+ r.push(Qr(e, n));
1902
1942
  for (let n = t.length - 2; n >= 0; n--)
1903
- r.push(Yr(e, t[n]));
1904
- return r.push(Nn(e)), r;
1943
+ r.push(Qr(e, t[n]));
1944
+ return r.push(Wn(e)), r;
1905
1945
  }
1906
- function Ri(e) {
1946
+ function Wi(e) {
1907
1947
  return dt(At(e), "eyes_standard");
1908
1948
  }
1909
- function Di(e, t) {
1910
- return Pi(e, t).map(Ri);
1949
+ function $i(e, t) {
1950
+ return Oi(e, t).map(Wi);
1911
1951
  }
1912
- const Bi = 6;
1913
- function Fi(e, t) {
1952
+ const Hi = 6;
1953
+ function Ki(e, t) {
1914
1954
  for (const r of e)
1915
1955
  if (t >= r.wtime && t < r.wtime + r.wduration)
1916
1956
  return r;
1917
1957
  return null;
1918
1958
  }
1919
- function Li(e) {
1959
+ function qi(e) {
1920
1960
  const t = Ne(e);
1921
- return t >= Kt ? Kt : Ne(t + Bi);
1961
+ return t >= Kt ? Kt : Ne(t + Hi);
1922
1962
  }
1923
- function Oi(e, t, r) {
1963
+ function Gi(e, t, r) {
1924
1964
  const n = Ne(r);
1925
- return Fi(t, e)?.emphasis ? Li(n) : n;
1965
+ return Ki(t, e)?.emphasis ? qi(n) : n;
1926
1966
  }
1927
- function Xr(e) {
1967
+ function Jr(e) {
1928
1968
  if (!e) return 0;
1929
1969
  const t = e.match(/^brow_(-?\d+)\//);
1930
1970
  if (!t?.[1]) return null;
@@ -1937,32 +1977,32 @@ function lt(e, t) {
1937
1977
  function Vt() {
1938
1978
  return lt(14, 32);
1939
1979
  }
1940
- function Ni(e = {}) {
1980
+ function zi(e = {}) {
1941
1981
  const {
1942
1982
  initialDelayMs: t = 800 + Math.random() * 1200,
1943
1983
  intervalMinMs: r = 2200,
1944
1984
  intervalMaxMs: n = 5800,
1945
1985
  doubleBlinkChance: s = 0.18,
1946
1986
  doubleBlinkGapMinMs: i = 120,
1947
- doubleBlinkGapMaxMs: o = 220,
1948
- fullBlinkChance: a = 0.75,
1949
- postEmotionChangeDelayMs: l = 380,
1987
+ doubleBlinkGapMaxMs: a = 220,
1988
+ fullBlinkChance: o = 0.75,
1989
+ postEmotionChangeDelayMs: u = 380,
1950
1990
  minDwellMs: f = 550
1951
1991
  } = e;
1952
- let u = "neutral", c = "neutral", d = 0, w = 0, b = 0, h = {
1992
+ let l = "neutral", c = "neutral", d = 0, w = 0, b = 0, h = {
1953
1993
  kind: "idle",
1954
1994
  nextBlinkAt: performance.now() + t
1955
1995
  }, I = null, v = "__eyes_open__|neutral|brow:0";
1956
- function x(T = u) {
1996
+ function x(T = l) {
1957
1997
  v = `${I ?? "__eyes_open__"}|${T}|brow:${w}`;
1958
1998
  }
1959
- function g(T, A = u) {
1999
+ function g(T, A = l) {
1960
2000
  I = T;
1961
- const M = Xr(T);
2001
+ const M = Jr(T);
1962
2002
  M != null ? w = M : T == null && (w = 0), x(A);
1963
2003
  }
1964
2004
  function k(T) {
1965
- return On(T);
2005
+ return Vn(T);
1966
2006
  }
1967
2007
  function B(T, A, M) {
1968
2008
  const D = Ne(A), ee = Ne(M);
@@ -1971,7 +2011,7 @@ function Ni(e = {}) {
1971
2011
  return;
1972
2012
  }
1973
2013
  const U = [
1974
- ...Di(D, ee),
2014
+ ...$i(D, ee),
1975
2015
  k(ee)
1976
2016
  ];
1977
2017
  h = {
@@ -1989,10 +2029,10 @@ function Ni(e = {}) {
1989
2029
  }, c = A, g(k(d), A);
1990
2030
  }
1991
2031
  function Y(T, A, M) {
1992
- const D = M ? Ti : Math.random() < a ? ki : Ei;
2032
+ const D = M ? Di : Math.random() < o ? Ri : Bi;
1993
2033
  h = {
1994
2034
  kind: "playing",
1995
- paths: Ci(A, D),
2035
+ paths: Vi(A, D),
1996
2036
  index: 0,
1997
2037
  holdUntil: T + Vt(),
1998
2038
  after: "idle",
@@ -2006,7 +2046,7 @@ function Ni(e = {}) {
2006
2046
  const A = h.paths[h.index] ?? null;
2007
2047
  g(A), T >= h.holdUntil && h.index >= h.paths.length - 1 && (w = h.targetBrow, d = h.targetBrow, g(k(h.targetBrow)), h = {
2008
2048
  kind: "idle",
2009
- nextBlinkAt: T + l
2049
+ nextBlinkAt: T + u
2010
2050
  });
2011
2051
  return;
2012
2052
  }
@@ -2023,13 +2063,13 @@ function Ni(e = {}) {
2023
2063
  h.index += 1, h.holdUntil = T + Vt();
2024
2064
  if (g(h.paths[h.index] ?? null, h.blinkEmotion), T >= h.holdUntil && h.index >= h.paths.length - 1) {
2025
2065
  if (h.after === "resumeIdle") {
2026
- R(T + l, u);
2066
+ R(T + u, l);
2027
2067
  return;
2028
2068
  }
2029
2069
  if (h.after === "doublePause") {
2030
2070
  h = {
2031
2071
  kind: "doublePause",
2032
- resumeAt: T + lt(i, o),
2072
+ resumeAt: T + lt(i, a),
2033
2073
  blinkEmotion: h.blinkEmotion
2034
2074
  }, g(k(d), h.blinkEmotion);
2035
2075
  return;
@@ -2037,7 +2077,7 @@ function Ni(e = {}) {
2037
2077
  if (h.after === "idle" && Math.random() < s) {
2038
2078
  h = {
2039
2079
  kind: "doublePause",
2040
- resumeAt: T + lt(i, o),
2080
+ resumeAt: T + lt(i, a),
2041
2081
  blinkEmotion: h.blinkEmotion
2042
2082
  }, g(k(d), h.blinkEmotion);
2043
2083
  return;
@@ -2049,37 +2089,37 @@ function Ni(e = {}) {
2049
2089
  return {
2050
2090
  advance: L,
2051
2091
  setTargetEmotion(T, A) {
2052
- const M = Ye(T, u);
2053
- if (M === u) return;
2092
+ const M = Ye(T, l);
2093
+ if (M === l) return;
2054
2094
  const D = performance.now();
2055
- !A?.force && f > 0 && !(u === "neutral" && M !== "neutral") && D - b < f || (u = M, c = M, b = D);
2095
+ !A?.force && f > 0 && !(l === "neutral" && M !== "neutral") && D - b < f || (l = M, c = M, b = D);
2056
2096
  },
2057
2097
  setTargetEyebrow(T) {
2058
2098
  const A = Ne(T);
2059
2099
  if (A === d) return;
2060
- const M = performance.now(), D = h.kind === "browBlend" ? Xr(I) ?? w : w;
2100
+ const M = performance.now(), D = h.kind === "browBlend" ? Jr(I) ?? w : w;
2061
2101
  d = A, !(A === D && h.kind !== "browBlend") && (h.kind === "playing" || h.kind === "doublePause" || B(M, D, A));
2062
2102
  },
2063
2103
  snapToEmotion(T) {
2064
2104
  const A = Ye(T), M = ht(A);
2065
- u = A, c = A, d = M, w = M, b = performance.now(), h = {
2105
+ l = A, c = A, d = M, w = M, b = performance.now(), h = {
2066
2106
  kind: "idle",
2067
2107
  nextBlinkAt: performance.now() + lt(4e3, 7e3)
2068
2108
  }, g(k(M), A);
2069
2109
  },
2070
- getTargetEmotion: () => u,
2110
+ getTargetEmotion: () => l,
2071
2111
  getTargetEyebrow: () => d,
2072
2112
  getExpressionPath: () => I,
2073
2113
  getDrawKey: () => v,
2074
2114
  reset() {
2075
- u = "neutral", c = "neutral", d = 0, w = 0, b = 0, R(
2115
+ l = "neutral", c = "neutral", d = 0, w = 0, b = 0, R(
2076
2116
  performance.now() + lt(r, n),
2077
2117
  "neutral"
2078
2118
  );
2079
2119
  }
2080
2120
  };
2081
2121
  }
2082
- function Ui() {
2122
+ function ji() {
2083
2123
  const e = document.createElement("video");
2084
2124
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
2085
2125
  let t = !1, r = null, n = "";
@@ -2088,18 +2128,18 @@ function Ui() {
2088
2128
  };
2089
2129
  return {
2090
2130
  async load(i) {
2091
- t && n === i || (s(), t = !1, n = i, i.startsWith("blob:") && (r = i), await new Promise((o, a) => {
2092
- const l = () => {
2131
+ t && n === i || (s(), t = !1, n = i, i.startsWith("blob:") && (r = i), await new Promise((a, o) => {
2132
+ const u = () => {
2093
2133
  const f = e.duration;
2094
2134
  if (!Number.isFinite(f) || f <= 0) {
2095
- a(new Error(`Idle video has invalid duration: ${i}`));
2135
+ o(new Error(`Idle video has invalid duration: ${i}`));
2096
2136
  return;
2097
2137
  }
2098
- t = !0, e.currentTime = 0, o();
2138
+ t = !0, e.currentTime = 0, a();
2099
2139
  };
2100
- e.addEventListener("loadeddata", l, { once: !0 }), e.addEventListener(
2140
+ e.addEventListener("loadeddata", u, { once: !0 }), e.addEventListener(
2101
2141
  "error",
2102
- () => a(new Error(`Failed to load idle video: ${i}`)),
2142
+ () => o(new Error(`Failed to load idle video: ${i}`)),
2103
2143
  { once: !0 }
2104
2144
  ), e.src = i, e.load();
2105
2145
  }));
@@ -2122,105 +2162,105 @@ function Ui() {
2122
2162
  }
2123
2163
  };
2124
2164
  }
2125
- const Vi = 50, Un = 400;
2126
- function Wi(e, t, r) {
2165
+ const Yi = 50, $n = 400;
2166
+ function Xi(e, t, r) {
2127
2167
  return e.filter((n) => {
2128
2168
  const s = n.queueIndex ?? -1;
2129
2169
  return s >= t && s <= r;
2130
2170
  });
2131
2171
  }
2132
- function $i(e, t) {
2172
+ function Qi(e, t) {
2133
2173
  const r = [];
2134
2174
  for (const n of e) {
2135
- const s = Wi(
2175
+ const s = Xi(
2136
2176
  t,
2137
2177
  n.start_word,
2138
2178
  n.end_word
2139
2179
  );
2140
2180
  if (s.length === 0) continue;
2141
- const i = s[0], o = s[s.length - 1];
2181
+ const i = s[0], a = s[s.length - 1];
2142
2182
  r.push({
2143
2183
  sentence: n,
2144
- startMs: Math.max(0, i.wtime - Vi),
2145
- endMs: o.wtime + o.wduration + Un
2184
+ startMs: Math.max(0, i.wtime - Yi),
2185
+ endMs: a.wtime + a.wduration + $n
2146
2186
  });
2147
2187
  }
2148
2188
  return r.sort((n, s) => n.startMs - s.startMs);
2149
2189
  }
2150
- function Hi(e, t, r, n = "neutral") {
2190
+ function Ji(e, t, r, n = "neutral") {
2151
2191
  const s = Ye(n);
2152
2192
  if (t.length === 0) return s;
2153
2193
  if (r.length === 0 || e < r[0].wtime)
2154
2194
  return Ye(t[0]?.emotion, s);
2155
- const i = $i(t, r);
2156
- let o = null;
2195
+ const i = Qi(t, r);
2196
+ let a = null;
2157
2197
  for (const f of i)
2158
- e >= f.startMs && e <= f.endMs && (o = f);
2159
- if (o)
2160
- return Ye(o.sentence.emotion, s);
2161
- const a = r[r.length - 1], l = a.wtime + a.wduration;
2162
- return e > l + Un ? Ye(
2198
+ e >= f.startMs && e <= f.endMs && (a = f);
2199
+ if (a)
2200
+ return Ye(a.sentence.emotion, s);
2201
+ const o = r[r.length - 1], u = o.wtime + o.wduration;
2202
+ return e > u + $n ? Ye(
2163
2203
  t[t.length - 1]?.emotion,
2164
2204
  s
2165
2205
  ) : s;
2166
2206
  }
2167
- function Ir(e, t, r, n, s = Bn) {
2168
- const i = new OffscreenCanvas(r, n), o = i.getContext("2d", { willReadFrequently: !0 });
2169
- o.drawImage(e, 0, 0, r, n);
2170
- const a = o.getImageData(0, 0, r, n), l = o.createImageData(r, n);
2171
- l.data.set(a.data);
2172
- const u = new OffscreenCanvas(r, n).getContext("2d", { willReadFrequently: !0 });
2207
+ function Ar(e, t, r, n, s = On) {
2208
+ const i = new OffscreenCanvas(r, n), a = i.getContext("2d", { willReadFrequently: !0 });
2209
+ a.drawImage(e, 0, 0, r, n);
2210
+ const o = a.getImageData(0, 0, r, n), u = a.createImageData(r, n);
2211
+ u.data.set(o.data);
2212
+ const l = new OffscreenCanvas(r, n).getContext("2d", { willReadFrequently: !0 });
2173
2213
  for (const c of t) {
2174
- u.clearRect(0, 0, r, n), u.drawImage(c, 0, 0, r, n);
2175
- const d = u.getImageData(0, 0, r, n);
2176
- for (let w = 0; w < l.data.length; w += 4) {
2214
+ l.clearRect(0, 0, r, n), l.drawImage(c, 0, 0, r, n);
2215
+ const d = l.getImageData(0, 0, r, n);
2216
+ for (let w = 0; w < u.data.length; w += 4) {
2177
2217
  const b = d.data[w], h = d.data[w + 1], I = d.data[w + 2];
2178
- Math.max(b, h, I) > s && (l.data[w] = b, l.data[w + 1] = h, l.data[w + 2] = I, l.data[w + 3] = 255);
2218
+ Math.max(b, h, I) > s && (u.data[w] = b, u.data[w + 1] = h, u.data[w + 2] = I, u.data[w + 3] = 255);
2179
2219
  }
2180
2220
  }
2181
- return o.putImageData(l, 0, 0), i;
2221
+ return a.putImageData(u, 0, 0), i;
2182
2222
  }
2183
2223
  let et = null, pt = null;
2184
2224
  const qt = /* @__PURE__ */ new Map();
2185
- function Ki() {
2225
+ function Zi() {
2186
2226
  et = null, pt = null, qt.clear();
2187
2227
  }
2188
- hn(Ki);
2189
- function qi(e) {
2228
+ wn(Zi);
2229
+ function eo(e) {
2190
2230
  return e ?? pt ?? void 0;
2191
2231
  }
2192
- function Ar(e) {
2232
+ function Pr(e) {
2193
2233
  return new Promise((t, r) => {
2194
2234
  const n = new Image();
2195
2235
  n.decoding = "async", n.onload = () => t(n), n.onerror = () => r(new Error(`Failed to load image: ${e}`)), n.src = e;
2196
2236
  });
2197
2237
  }
2198
- async function Gi(e) {
2199
- return xt() ? hi(
2238
+ async function to(e) {
2239
+ return xt() ? ki(
2200
2240
  await yt(Ht(), e ?? "")
2201
- ) : Ar(Ht());
2241
+ ) : Pr(Ht());
2202
2242
  }
2203
- async function Qr(e, t, r, n) {
2204
- const s = r ? await Dn(e, n) : await fetch(e).then((f) => {
2243
+ async function Zr(e, t, r, n) {
2244
+ const s = r ? await Ln(e, n) : await fetch(e).then((f) => {
2205
2245
  if (!f.ok) throw new Error(`Failed to load ${e}`);
2206
2246
  return f.json();
2207
2247
  }), i = s.sheets?.[0];
2208
2248
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
2209
- const o = r ? await di(
2249
+ const a = r ? await vi(
2210
2250
  await yt(
2211
- Ln(t, i.path, r),
2251
+ Un(t, i.path, r),
2212
2252
  n ?? ""
2213
2253
  )
2214
- ) : await Ar(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
2254
+ ) : await Pr(`${t}/${i.path}`), o = /* @__PURE__ */ new Map();
2215
2255
  for (const f of s.cells ?? [])
2216
- f.path && a.set(f.path, f);
2217
- const l = /* @__PURE__ */ new Map();
2256
+ f.path && o.set(f.path, f);
2257
+ const u = /* @__PURE__ */ new Map();
2218
2258
  for (const f of s.sheets ?? [])
2219
- l.set(f.index, f);
2220
- return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: l, diffBase: t };
2259
+ u.set(f.index, f);
2260
+ return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex: u, diffBase: t };
2221
2261
  }
2222
2262
  async function mr(e) {
2223
- const t = qi(e), r = xt();
2263
+ const t = eo(e), r = xt();
2224
2264
  if (r && !t)
2225
2265
  throw new Error("Encrypted assets enabled but no key provided");
2226
2266
  if (et && (!r || pt === (t ?? null))) {
@@ -2231,42 +2271,42 @@ async function mr(e) {
2231
2271
  };
2232
2272
  }
2233
2273
  pt = t ?? null, qt.clear();
2234
- const n = pn();
2274
+ const n = gn();
2235
2275
  et = (async () => {
2236
- const i = await Gi(t), o = await Qr(
2237
- wn(),
2276
+ const i = await to(t), a = await Zr(
2277
+ yn(),
2238
2278
  n,
2239
2279
  r,
2240
2280
  t
2241
2281
  );
2242
- let a = null;
2282
+ let o = null;
2243
2283
  try {
2244
- a = await Qr(
2245
- gn(),
2284
+ o = await Zr(
2285
+ _n(),
2246
2286
  n,
2247
2287
  r,
2248
2288
  t
2249
2289
  );
2250
2290
  } catch {
2251
- a = null;
2291
+ o = null;
2252
2292
  }
2253
- return { sil: i, viseme: o, expression: a };
2293
+ return { sil: i, viseme: a, expression: o };
2254
2294
  })();
2255
2295
  const s = await et;
2256
2296
  return { ...wt(s), visemePaths: [...s.viseme.cellByPath.keys()] };
2257
2297
  }
2258
- async function Pr(e) {
2298
+ async function xr(e) {
2259
2299
  if (await mr(e), !et) throw new Error("Assets not loaded");
2260
2300
  return et;
2261
2301
  }
2262
2302
  function wt(e) {
2263
- return Mn(
2303
+ return Dn(
2264
2304
  e.viseme.atlasMeta,
2265
2305
  e.sil.naturalWidth,
2266
2306
  e.sil.naturalHeight
2267
2307
  );
2268
2308
  }
2269
- function zi(e, t) {
2309
+ function ro(e, t) {
2270
2310
  const r = document.createElement("canvas");
2271
2311
  return r.width = t.w, r.height = t.h, r.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
2272
2312
  }
@@ -2274,23 +2314,23 @@ async function Gt(e, t, r) {
2274
2314
  const n = `${t.diffBase}::${r}`, s = qt.get(n);
2275
2315
  if (s) return s;
2276
2316
  const i = (async () => {
2277
- const o = t.cellByPath.get(r);
2278
- if (!o) throw new Error(`No atlas cell for path: ${r}`);
2279
- const a = Cn(t.atlasMeta, o), l = wt(e);
2280
- if (Rn(o)) {
2281
- const c = zi(t, o), d = document.createElement("canvas");
2282
- d.width = l.width, d.height = l.height;
2317
+ const a = t.cellByPath.get(r);
2318
+ if (!a) throw new Error(`No atlas cell for path: ${r}`);
2319
+ const o = Bn(t.atlasMeta, a), u = wt(e);
2320
+ if (Fn(a)) {
2321
+ const c = ro(t, a), d = document.createElement("canvas");
2322
+ d.width = u.width, d.height = u.height;
2283
2323
  const w = d.getContext("2d");
2284
- return w.fillStyle = "#000", w.fillRect(0, 0, l.width, l.height), w.drawImage(c, a.x, a.y), d;
2324
+ return w.fillStyle = "#000", w.fillRect(0, 0, u.width, u.height), w.drawImage(c, o.x, o.y), d;
2285
2325
  }
2286
- const f = `${t.diffBase}/${r}`, u = await Ar(f);
2287
- if (u.naturalWidth === l.width && u.naturalHeight === l.height)
2288
- return u;
2326
+ const f = `${t.diffBase}/${r}`, l = await Pr(f);
2327
+ if (l.naturalWidth === u.width && l.naturalHeight === u.height)
2328
+ return l;
2289
2329
  throw new Error(`Diff PNG wrong size for ${r}`);
2290
2330
  })();
2291
2331
  return qt.set(n, i), i;
2292
2332
  }
2293
- async function ar(e, t, r, n, s, i) {
2333
+ async function or(e, t, r, n, s, i) {
2294
2334
  if (s) {
2295
2335
  const { width: w, height: b } = s;
2296
2336
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
@@ -2304,93 +2344,93 @@ async function ar(e, t, r, n, s, i) {
2304
2344
  v.clearRect(0, 0, w, b), v.drawImage(h, 0, 0);
2305
2345
  return;
2306
2346
  }
2307
- const o = await Pr(), a = Xt(o.viseme.atlasMeta), { width: l, height: f } = wt(o);
2308
- (e.width !== l || e.height !== f) && (e.width = l, e.height = f);
2309
- const u = [], c = e.getContext("2d");
2310
- if (c.clearRect(0, 0, l, f), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
2311
- const w = o.sil;
2312
- c.drawImage(w, 0, 0, l, f);
2347
+ const a = await xr(), o = Xt(a.viseme.atlasMeta), { width: u, height: f } = wt(a);
2348
+ (e.width !== u || e.height !== f) && (e.width = u, e.height = f);
2349
+ const l = [], c = e.getContext("2d");
2350
+ if (c.clearRect(0, 0, u, f), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
2351
+ const w = a.sil;
2352
+ c.drawImage(w, 0, 0, u, f);
2313
2353
  return;
2314
2354
  }
2315
- if (u.length === 0) {
2316
- c.drawImage(t, 0, 0, l, f);
2355
+ if (l.length === 0) {
2356
+ c.drawImage(t, 0, 0, u, f);
2317
2357
  return;
2318
2358
  }
2319
- const d = Ir(t, u, l, f, a);
2359
+ const d = Ar(t, l, u, f, o);
2320
2360
  c.drawImage(d, 0, 0);
2321
2361
  }
2322
2362
  async function hr(e, t, r) {
2323
- const n = await Pr(pt ?? void 0), s = Xt(n.viseme.atlasMeta), { width: i, height: o } = wt(n);
2324
- (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
2325
- const a = [];
2363
+ const n = await xr(pt ?? void 0), s = Xt(n.viseme.atlasMeta), { width: i, height: a } = wt(n);
2364
+ (e.width !== i || e.height !== a) && (e.width = i, e.height = a);
2365
+ const o = [];
2326
2366
  if (t.mouthPath) {
2327
- const u = new Set(n.viseme.cellByPath.keys()), c = kr(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
2328
- c && a.push(await Gt(n, n.viseme, c));
2367
+ const l = new Set(n.viseme.cellByPath.keys()), c = Tr(t.mouthPath, l) ?? (l.has(t.mouthPath) ? t.mouthPath : null);
2368
+ c && o.push(await Gt(n, n.viseme, c));
2329
2369
  }
2330
2370
  if (t.expressionPath && n.expression) {
2331
- const u = Er(
2371
+ const l = Ir(
2332
2372
  t.expressionPath,
2333
2373
  (c) => n.expression.cellByPath.has(c)
2334
2374
  );
2335
- u && a.push(
2336
- await Gt(n, n.expression, u)
2375
+ l && o.push(
2376
+ await Gt(n, n.expression, l)
2337
2377
  );
2338
2378
  }
2339
- const l = e.getContext("2d");
2340
- if (l.clearRect(0, 0, i, o), a.length === 0) {
2341
- l.drawImage(n.sil, 0, 0, i, o);
2379
+ const u = e.getContext("2d");
2380
+ if (u.clearRect(0, 0, i, a), o.length === 0) {
2381
+ u.drawImage(n.sil, 0, 0, i, a);
2342
2382
  return;
2343
2383
  }
2344
- const f = Ir(
2384
+ const f = Ar(
2345
2385
  n.sil,
2346
- a,
2347
- i,
2348
2386
  o,
2387
+ i,
2388
+ a,
2349
2389
  s
2350
2390
  );
2351
- l.drawImage(f, 0, 0);
2391
+ u.drawImage(f, 0, 0);
2352
2392
  }
2353
- async function ji(e, t) {
2354
- const r = await Pr(pt ?? void 0), n = Xt(r.viseme.atlasMeta), { width: s, height: i } = wt(r), o = [];
2393
+ async function no(e, t) {
2394
+ const r = await xr(pt ?? void 0), n = Xt(r.viseme.atlasMeta), { width: s, height: i } = wt(r), a = [];
2355
2395
  if (e.mouthPath) {
2356
- const u = new Set(r.viseme.cellByPath.keys()), c = kr(e.mouthPath, u) ?? (u.has(e.mouthPath) ? e.mouthPath : null);
2357
- c && o.push(await Gt(r, r.viseme, c));
2396
+ const l = new Set(r.viseme.cellByPath.keys()), c = Tr(e.mouthPath, l) ?? (l.has(e.mouthPath) ? e.mouthPath : null);
2397
+ c && a.push(await Gt(r, r.viseme, c));
2358
2398
  }
2359
2399
  if (e.expressionPath && r.expression) {
2360
- const u = Er(
2400
+ const l = Ir(
2361
2401
  e.expressionPath,
2362
2402
  (c) => r.expression.cellByPath.has(c)
2363
2403
  );
2364
- u && o.push(
2365
- await Gt(r, r.expression, u)
2404
+ l && a.push(
2405
+ await Gt(r, r.expression, l)
2366
2406
  );
2367
2407
  }
2368
- const a = new OffscreenCanvas(s, i), l = a.getContext("2d");
2369
- if (o.length === 0)
2370
- return l.drawImage(r.sil, 0, 0, s, i), a.transferToImageBitmap();
2371
- const f = Ir(
2408
+ const o = new OffscreenCanvas(s, i), u = o.getContext("2d");
2409
+ if (a.length === 0)
2410
+ return u.drawImage(r.sil, 0, 0, s, i), o.transferToImageBitmap();
2411
+ const f = Ar(
2372
2412
  r.sil,
2373
- o,
2413
+ a,
2374
2414
  s,
2375
2415
  i,
2376
2416
  n
2377
2417
  );
2378
- return l.drawImage(f, 0, 0), a.transferToImageBitmap();
2418
+ return u.drawImage(f, 0, 0), o.transferToImageBitmap();
2379
2419
  }
2380
- async function Yi(e) {
2420
+ async function so(e) {
2381
2421
  await hr(e, { mouthPath: null, expressionPath: null });
2382
2422
  }
2383
- let Vn = null;
2384
- function Jr(e) {
2385
- Vn = e;
2423
+ let Hn = null;
2424
+ function en(e) {
2425
+ Hn = e;
2386
2426
  }
2387
2427
  function Xe() {
2388
- return Vn;
2428
+ return Hn;
2389
2429
  }
2390
- function Xi(e) {
2430
+ function io(e) {
2391
2431
  return `${e.from}→${e.to}@${e.fromVtime}`;
2392
2432
  }
2393
- function Zr() {
2433
+ function tn() {
2394
2434
  return {
2395
2435
  rafTicksSpeaking: 0,
2396
2436
  rafTicksDeduped: 0,
@@ -2408,19 +2448,19 @@ function Zr() {
2408
2448
  bufferPrefetched: 0
2409
2449
  };
2410
2450
  }
2411
- function Qi() {
2412
- let e = Zr();
2451
+ function oo() {
2452
+ let e = tn();
2413
2453
  const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
2414
- let s = "", i = -1, o = "";
2415
- const a = () => {
2416
- e = Zr(), t.clear(), r.clear(), n.clear(), s = "", i = -1, o = "";
2417
- }, l = (u) => {
2418
- t.add(u);
2419
- }, f = (u) => {
2420
- u && n.add(u);
2454
+ let s = "", i = -1, a = "";
2455
+ const o = () => {
2456
+ e = tn(), t.clear(), r.clear(), n.clear(), s = "", i = -1, a = "";
2457
+ }, u = (l) => {
2458
+ t.add(l);
2459
+ }, f = (l) => {
2460
+ l && n.add(l);
2421
2461
  };
2422
2462
  return {
2423
- reset: a,
2463
+ reset: o,
2424
2464
  onRafTickSpeaking() {
2425
2465
  e.rafTicksSpeaking += 1;
2426
2466
  },
@@ -2436,9 +2476,9 @@ function Qi() {
2436
2476
  onWorkerStale() {
2437
2477
  e.workerStale += 1;
2438
2478
  },
2439
- onTransitionSample(u, c) {
2440
- const d = Xi(u);
2441
- e.transitionFramesSampled += 1, d !== s && (s = d, i = -1, o !== d && (o = d, e.rifeFramesOmittedByGap += u.omittedByGap)), c && r.add(c), i >= 0 && u.frameIdx > i + 1 && (e.transitionFramesMissed += u.frameIdx - i - 1), i = u.frameIdx;
2479
+ onTransitionSample(l, c) {
2480
+ const d = io(l);
2481
+ e.transitionFramesSampled += 1, d !== s && (s = d, i = -1, a !== d && (a = d, e.rifeFramesOmittedByGap += l.omittedByGap)), c && r.add(c), i >= 0 && l.frameIdx > i + 1 && (e.transitionFramesMissed += l.frameIdx - i - 1), i = l.frameIdx;
2442
2482
  },
2443
2483
  onBufferTick() {
2444
2484
  e.bufferTicks += 1;
@@ -2454,29 +2494,29 @@ function Qi() {
2454
2494
  },
2455
2495
  onBufferReset() {
2456
2496
  },
2457
- onDrawDisplayed(u, c) {
2458
- if (e.drawsDisplayed += 1, u.transitionMeta) {
2497
+ onDrawDisplayed(l, c) {
2498
+ if (e.drawsDisplayed += 1, l.transitionMeta) {
2459
2499
  e.transitionFramesDisplayed += 1;
2460
- const w = u.transitionMeta;
2461
- l(w.fromVtime), l(w.toVtime), f(u.mouthPath);
2500
+ const w = l.transitionMeta;
2501
+ u(w.fromVtime), u(w.toVtime), f(l.mouthPath);
2462
2502
  return;
2463
2503
  }
2464
- if (u.label.includes("→")) {
2504
+ if (l.label.includes("→")) {
2465
2505
  e.transitionFramesDisplayed += 1;
2466
2506
  return;
2467
2507
  }
2468
- const d = u.label.trim();
2508
+ const d = l.label.trim();
2469
2509
  if (!(!d || d === "sil")) {
2470
2510
  for (const w of c)
2471
- if (w.viseme === d && u.elapsedMs >= w.vtime && u.elapsedMs < w.vtime + w.vduration) {
2472
- l(w.vtime);
2511
+ if (w.viseme === d && l.elapsedMs >= w.vtime && l.elapsedMs < w.vtime + w.vduration) {
2512
+ u(w.vtime);
2473
2513
  break;
2474
2514
  }
2475
2515
  }
2476
2516
  },
2477
- snapshot(u, c) {
2517
+ snapshot(l, c) {
2478
2518
  let d = 0, w = 0;
2479
- for (const x of u)
2519
+ for (const x of l)
2480
2520
  if (x.viseme !== "sil") {
2481
2521
  if (x.vtime >= c) break;
2482
2522
  d += 1, t.has(x.vtime) && (w += 1);
@@ -2500,135 +2540,136 @@ function Qi() {
2500
2540
  }
2501
2541
  };
2502
2542
  }
2503
- const Wn = gr, Ji = 200, en = 300, Zi = 100, ea = 600, $n = "__sil__";
2504
- function tn(e) {
2505
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === $n : !1;
2543
+ const Kn = gr, ao = 200, rn = 300, co = 100, uo = 600, qn = "__sil__";
2544
+ function nn(e) {
2545
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === qn : !1;
2506
2546
  }
2507
- function xr() {
2547
+ function Mr() {
2508
2548
  return { lastDrawnKey: "" };
2509
2549
  }
2510
2550
  function Re(e) {
2511
2551
  e.lastDrawnKey = "", e.transitionCache = void 0;
2512
2552
  }
2513
- function ta(e, t) {
2553
+ function lo(e, t) {
2514
2554
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
2515
2555
  return t.transitionCache.transitions;
2516
- const r = js(e);
2556
+ const r = ni(e);
2517
2557
  return t && (t.transitionCache = { queueLength: e.length, transitions: r }), r;
2518
2558
  }
2519
- function ra(e, t) {
2559
+ function fo(e, t) {
2520
2560
  let r = "sil";
2521
2561
  for (const n of e)
2522
2562
  n.viseme !== "sil" && (t != null && n.vtime > t || (r = n.viseme));
2523
2563
  return r;
2524
2564
  }
2525
- function na(e, t, r, n = 120) {
2565
+ function mo(e, t, r, n = 120) {
2526
2566
  if (r !== "sil")
2527
2567
  return r;
2528
- const s = En(e, t, n);
2529
- return s !== "sil" ? s : ra(e, t);
2568
+ const s = Pn(e, t, n);
2569
+ return s !== "sil" ? s : fo(e, t);
2530
2570
  }
2531
- function sa(e, t) {
2532
- return e === "sil" ? !1 : t ? yi(e, "sil", t) : Tr(e, "sil").length > 0;
2571
+ function ho(e, t) {
2572
+ return e === "sil" ? !1 : t ? Ai(e, "sil", t) : Er(e, "sil").length > 0;
2533
2573
  }
2534
- function ia() {
2535
- return Wn + ea;
2574
+ function po() {
2575
+ return Kn + uo;
2536
2576
  }
2537
2577
  function zt(e) {
2538
- return e ?? $n;
2578
+ return e ?? qn;
2539
2579
  }
2540
- function Mr(e, t, r, n, s = Zi) {
2580
+ function Cr(e, t, r, n, s = co) {
2541
2581
  if (e.length === 0)
2542
2582
  return { diffPath: null, label: "sil" };
2543
2583
  if (t >= Ze(e))
2544
2584
  return { diffPath: null, label: "sil" };
2545
- const i = ta(e, n), o = Ys(i, t);
2546
- if (o) {
2547
- const l = bn(
2548
- o.fromVtime,
2549
- o.toVtime,
2550
- o.from,
2551
- o.to
2585
+ const i = lo(e, n), a = si(i, t);
2586
+ if (a) {
2587
+ const f = En(
2588
+ a.fromVtime,
2589
+ a.toVtime,
2590
+ a.from,
2591
+ a.to
2552
2592
  );
2553
- if (t >= l.transStart && t < l.transEnd) {
2554
- let f = Tr(o.from, o.to);
2555
- r && (f = Fn(f, r));
2556
- const u = Si(f, l.effectiveGapMs);
2557
- if (u.length > 0) {
2558
- const c = vi(
2593
+ if (t >= f.transStart && t < f.transEnd) {
2594
+ let l = Er(a.from, a.to);
2595
+ r && (l = Nn(l, r));
2596
+ const c = xi(l, f.effectiveGapMs);
2597
+ if (c.length > 0) {
2598
+ const d = Mi(
2559
2599
  t,
2560
- l.transStart,
2561
- l.transEnd,
2562
- u.length
2600
+ f.transStart,
2601
+ f.transEnd,
2602
+ c.length
2563
2603
  );
2564
2604
  return {
2565
- diffPath: u[c] ?? u[u.length - 1],
2566
- label: `${o.from}→${o.to}`,
2605
+ diffPath: c[d] ?? c[c.length - 1],
2606
+ label: `${a.from}→${a.to}`,
2567
2607
  transitionMeta: {
2568
- from: o.from,
2569
- to: o.to,
2570
- fromVtime: o.fromVtime,
2571
- toVtime: o.toVtime,
2572
- frameIdx: c,
2573
- frameCount: u.length,
2574
- fullFrameCount: f.length,
2575
- omittedByGap: Math.max(0, f.length - u.length)
2608
+ from: a.from,
2609
+ to: a.to,
2610
+ fromVtime: a.fromVtime,
2611
+ toVtime: a.toVtime,
2612
+ frameIdx: d,
2613
+ frameCount: c.length,
2614
+ fullFrameCount: l.length,
2615
+ omittedByGap: Math.max(0, l.length - c.length)
2576
2616
  }
2577
2617
  };
2578
2618
  }
2579
- return { diffPath: It(o.to), label: o.to };
2619
+ return { diffPath: It(a.to), label: a.to };
2580
2620
  }
2581
2621
  }
2582
- const a = En(e, t, s);
2583
- return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: It(a), label: a };
2622
+ const o = Sr(e);
2623
+ let u = Js(o, t);
2624
+ return u === "sil" && (u = Pn(e, t, s)), u === "sil" ? { diffPath: null, label: "sil" } : { diffPath: It(u), label: u };
2584
2625
  }
2585
2626
  function Qt(e, t) {
2586
2627
  const r = t ?? zt(e.expressionPath);
2587
2628
  return `${zt(e.mouthPath)}|${r}`;
2588
2629
  }
2589
- function rn(e, t, r, n, s, i, o, a, l, f) {
2590
- const u = Mr(t, r, l, i), c = {
2591
- mouthPath: u.diffPath,
2630
+ function sn(e, t, r, n, s, i, a, o, u, f) {
2631
+ const l = Cr(t, r, u, i), c = {
2632
+ mouthPath: l.diffPath,
2592
2633
  expressionPath: n
2593
2634
  }, d = Qt(c, s), w = Xe();
2594
- if (u.transitionMeta && w?.onTransitionSample(u.transitionMeta, u.diffPath), d === i.lastDrawnKey) {
2635
+ if (l.transitionMeta && w?.onTransitionSample(l.transitionMeta, l.diffPath), d === i.lastDrawnKey) {
2595
2636
  w?.onDrawDeduped();
2596
2637
  return;
2597
2638
  }
2598
- w?.onDrawRequested(), a(u), i.lastDrawnKey = d, o(e, c, d, (b) => {
2639
+ w?.onDrawRequested(), o(l), i.lastDrawnKey = d, a(e, c, d, (b) => {
2599
2640
  b === d && (i.lastDrawnKey = d);
2600
2641
  });
2601
2642
  }
2602
- function or(e, t, r, n, s, i, o = null) {
2603
- const a = { mouthPath: null, expressionPath: t }, l = o != null ? `|idle@${Math.round(o * 1e3)}` : "", f = Qt(a, r) + l;
2604
- !(o != null) && f === n.lastDrawnKey || (i(
2605
- o != null ? t ? "idle · blink" : "idle" : t ? "blink" : "sil"
2606
- ), s(e, a, f, (c) => {
2643
+ function ar(e, t, r, n, s, i, a = null) {
2644
+ const o = { mouthPath: null, expressionPath: t }, u = a != null ? `|idle@${Math.round(a * 1e3)}` : "", f = Qt(o, r) + u;
2645
+ !(a != null) && f === n.lastDrawnKey || (i(
2646
+ a != null ? t ? "idle · blink" : "idle" : t ? "blink" : "sil"
2647
+ ), s(e, o, f, (c) => {
2607
2648
  c === f && (n.lastDrawnKey = f);
2608
2649
  }));
2609
2650
  }
2610
- function Hn(e, t, r, n, s = Et, i) {
2651
+ function Gn(e, t, r, n, s = Et, i) {
2611
2652
  if (r <= t || e.length === 0) return [];
2612
- const o = i ?? xr(), a = [];
2613
- let l = "";
2653
+ const a = i ?? Mr(), o = [];
2654
+ let u = "";
2614
2655
  for (let f = t; f < r; f += s) {
2615
- const u = Mr(
2656
+ const l = Cr(
2616
2657
  e,
2617
2658
  f,
2618
2659
  n,
2619
- o
2620
- ), c = zt(u.diffPath);
2621
- c !== l && (l = c, a.push({
2660
+ a
2661
+ ), c = zt(l.diffPath);
2662
+ c !== u && (u = c, o.push({
2622
2663
  displayAtMs: f,
2623
- mouthPath: u.diffPath,
2664
+ mouthPath: l.diffPath,
2624
2665
  mouthKey: c,
2625
- label: u.label
2666
+ label: l.label
2626
2667
  }));
2627
2668
  }
2628
- return a;
2669
+ return o;
2629
2670
  }
2630
- const aa = 3;
2631
- function Cr(e) {
2671
+ const wo = 3;
2672
+ function Rr(e) {
2632
2673
  let t = 0;
2633
2674
  const r = [];
2634
2675
  let n = !1, s = !1;
@@ -2637,77 +2678,77 @@ function Cr(e) {
2637
2678
  n = !0;
2638
2679
  try {
2639
2680
  for (; r.length > 0; ) {
2640
- const a = r.shift(), l = ++t;
2641
- await e(a.diffs, l, a) && l === t && a.onDisplayed?.(a.drawKey);
2681
+ const o = r.shift(), u = ++t;
2682
+ await e(o.diffs, u, o) && u === t && o.onDisplayed?.(o.drawKey);
2642
2683
  }
2643
2684
  } finally {
2644
2685
  n = !1, r.length > 0 && i();
2645
2686
  }
2646
2687
  }
2647
- }, o = () => {
2688
+ }, a = () => {
2648
2689
  s || (s = !0, queueMicrotask(() => {
2649
2690
  s = !1, i();
2650
2691
  }));
2651
2692
  };
2652
2693
  return {
2653
- enqueue(a, l, f) {
2654
- const u = r.findIndex((c) => c.drawKey === l);
2655
- u >= 0 ? r[u] = { diffs: a, drawKey: l, onDisplayed: f } : (r.length >= aa && (r.shift(), Xe()?.onQueueSuperseded()), r.push({ diffs: a, drawKey: l, onDisplayed: f })), o();
2694
+ enqueue(o, u, f) {
2695
+ const l = r.findIndex((c) => c.drawKey === u);
2696
+ l >= 0 ? r[l] = { diffs: o, drawKey: u, onDisplayed: f } : (r.length >= wo && (r.shift(), Xe()?.onQueueSuperseded()), r.push({ diffs: o, drawKey: u, onDisplayed: f })), a();
2656
2697
  },
2657
2698
  reset() {
2658
2699
  t += 1, r.length = 0;
2659
2700
  },
2660
- isLatestSeq(a) {
2661
- return a === t;
2701
+ isLatestSeq(o) {
2702
+ return o === t;
2662
2703
  },
2663
2704
  getLatestSeq() {
2664
2705
  return t;
2665
2706
  }
2666
2707
  };
2667
2708
  }
2668
- function oa(e, t = 2) {
2709
+ function go(e, t = 2) {
2669
2710
  const r = [], n = /* @__PURE__ */ new Set();
2670
- let s = 0, i = !1, o = 0;
2671
- const a = (f, u) => `${f}|${u}`, l = async () => {
2711
+ let s = 0, i = !1, a = 0;
2712
+ const o = (f, l) => `${f}|${l}`, u = async () => {
2672
2713
  if (!i) {
2673
2714
  i = !0;
2674
2715
  try {
2675
2716
  for (; s < t && r.length > 0; ) {
2676
- const f = r.shift(), u = a(f.displayAtMs, f.drawKey);
2677
- if (n.has(u)) continue;
2678
- n.add(u), s += 1;
2679
- const c = o;
2717
+ const f = r.shift(), l = o(f.displayAtMs, f.drawKey);
2718
+ if (n.has(l)) continue;
2719
+ n.add(l), s += 1;
2720
+ const c = a;
2680
2721
  try {
2681
2722
  await e(f);
2682
2723
  } finally {
2683
- if (n.delete(u), s -= 1, c !== o) return;
2724
+ if (n.delete(l), s -= 1, c !== a) return;
2684
2725
  }
2685
2726
  }
2686
2727
  } finally {
2687
- i = !1, r.length > 0 && s < t && l();
2728
+ i = !1, r.length > 0 && s < t && u();
2688
2729
  }
2689
2730
  }
2690
2731
  };
2691
2732
  return {
2692
2733
  enqueue(f) {
2693
- const u = a(f.displayAtMs, f.drawKey);
2694
- n.has(u) || r.some((c) => a(c.displayAtMs, c.drawKey) === u) || (r.push(f), l());
2734
+ const l = o(f.displayAtMs, f.drawKey);
2735
+ n.has(l) || r.some((c) => o(c.displayAtMs, c.drawKey) === l) || (r.push(f), u());
2695
2736
  },
2696
- isQueuedOrInflight(f, u) {
2697
- const c = a(f, u);
2737
+ isQueuedOrInflight(f, l) {
2738
+ const c = o(f, l);
2698
2739
  return n.has(c) ? !0 : r.some(
2699
- (d) => a(d.displayAtMs, d.drawKey) === c
2740
+ (d) => o(d.displayAtMs, d.drawKey) === c
2700
2741
  );
2701
2742
  },
2702
2743
  reset() {
2703
- o += 1, r.length = 0, n.clear(), s = 0;
2744
+ a += 1, r.length = 0, n.clear(), s = 0;
2704
2745
  },
2705
2746
  pendingCount() {
2706
2747
  return r.length + s;
2707
2748
  }
2708
2749
  };
2709
2750
  }
2710
- function ca() {
2751
+ function yo() {
2711
2752
  const e = /* @__PURE__ */ new Map(), t = (r) => {
2712
2753
  r.bitmap.close();
2713
2754
  };
@@ -2715,14 +2756,14 @@ function ca() {
2715
2756
  has(r, n) {
2716
2757
  return e.has(n);
2717
2758
  },
2718
- markRendered(r, n, s, i, o) {
2719
- const a = e.get(n);
2720
- a && t(a), e.set(n, {
2759
+ markRendered(r, n, s, i, a) {
2760
+ const o = e.get(n);
2761
+ o && t(o), e.set(n, {
2721
2762
  displayAtMs: r,
2722
2763
  mouthKey: n,
2723
2764
  label: s,
2724
2765
  mouthPath: i,
2725
- bitmap: o
2766
+ bitmap: a
2726
2767
  });
2727
2768
  },
2728
2769
  findForMouthKey(r) {
@@ -2742,8 +2783,8 @@ function ca() {
2742
2783
  }
2743
2784
  };
2744
2785
  }
2745
- function ua(e, t, r, n, s, i) {
2746
- const o = Hn(
2786
+ function _o(e, t, r, n, s, i) {
2787
+ const a = Gn(
2747
2788
  t,
2748
2789
  r,
2749
2790
  n,
@@ -2751,16 +2792,16 @@ function ua(e, t, r, n, s, i) {
2751
2792
  Et,
2752
2793
  i
2753
2794
  );
2754
- if (o.length === 0) return { ready: 0, total: 0 };
2755
- let a = 0;
2756
- for (const l of o)
2757
- e.has(l.displayAtMs, l.mouthKey) && (a += 1);
2758
- return { ready: a, total: o.length };
2759
- }
2760
- function la(e) {
2761
- const t = ca(), r = xr(), n = /* @__PURE__ */ new Set();
2795
+ if (a.length === 0) return { ready: 0, total: 0 };
2796
+ let o = 0;
2797
+ for (const u of a)
2798
+ e.has(u.displayAtMs, u.mouthKey) && (o += 1);
2799
+ return { ready: o, total: a.length };
2800
+ }
2801
+ function So(e) {
2802
+ const t = yo(), r = Mr(), n = /* @__PURE__ */ new Set();
2762
2803
  let s = "", i = null;
2763
- const o = oa(
2804
+ const a = go(
2764
2805
  async (c) => {
2765
2806
  try {
2766
2807
  if (!e.supportsBufferedPlayback) return;
@@ -2780,10 +2821,10 @@ function la(e) {
2780
2821
  n.delete(c.mouthKey);
2781
2822
  }
2782
2823
  },
2783
- ps
2784
- ), a = (c) => {
2824
+ ys
2825
+ ), o = (c) => {
2785
2826
  for (const d of c)
2786
- t.has(d.displayAtMs, d.mouthKey) || n.has(d.mouthKey) || o.isQueuedOrInflight(0, d.mouthKey) || (n.add(d.mouthKey), o.enqueue({
2827
+ t.has(d.displayAtMs, d.mouthKey) || n.has(d.mouthKey) || a.isQueuedOrInflight(0, d.mouthKey) || (n.add(d.mouthKey), a.enqueue({
2787
2828
  ...d,
2788
2829
  displayAtMs: 0,
2789
2830
  drawKey: d.mouthKey,
@@ -2792,9 +2833,9 @@ function la(e) {
2792
2833
  expressionPath: null
2793
2834
  }
2794
2835
  }));
2795
- }, l = (c, d, w, b = rr) => {
2836
+ }, u = (c, d, w, b = rr) => {
2796
2837
  if (!e.supportsBufferedPlayback) return;
2797
- const h = Math.max(0, d - Et * 4), I = Hn(
2838
+ const h = Math.max(0, d - Et * 4), I = Gn(
2798
2839
  c,
2799
2840
  h,
2800
2841
  d + b,
@@ -2802,28 +2843,28 @@ function la(e) {
2802
2843
  Et,
2803
2844
  r
2804
2845
  );
2805
- a(I);
2846
+ o(I);
2806
2847
  }, f = (c, d) => {
2807
2848
  s = c, i = d;
2808
- }, u = (c, d) => !(s !== c || i !== d);
2849
+ }, l = (c, d) => !(s !== c || i !== d);
2809
2850
  return {
2810
2851
  reset() {
2811
- t.reset(), o.reset(), n.clear(), Re(r), s = "", i = null, Xe()?.onBufferReset();
2852
+ t.reset(), a.reset(), n.clear(), Re(r), s = "", i = null, Xe()?.onBufferReset();
2812
2853
  },
2813
2854
  markExternallyDisplayed(c, d) {
2814
2855
  f(c.split("|")[0] ?? c, d);
2815
2856
  },
2816
2857
  warmupTick(c) {
2817
- e.supportsBufferedPlayback && l(
2858
+ e.supportsBufferedPlayback && u(
2818
2859
  c.queue,
2819
2860
  0,
2820
2861
  c.availablePaths,
2821
- Math.max(Nr, rr)
2862
+ Math.max(Ur, rr)
2822
2863
  );
2823
2864
  },
2824
- isWarmupReady(c, d = Nr) {
2865
+ isWarmupReady(c, d = Ur) {
2825
2866
  if (!e.supportsBufferedPlayback) return !0;
2826
- const { ready: w, total: b } = ua(
2867
+ const { ready: w, total: b } = _o(
2827
2868
  t,
2828
2869
  c.queue,
2829
2870
  0,
@@ -2831,17 +2872,17 @@ function la(e) {
2831
2872
  c.availablePaths,
2832
2873
  r
2833
2874
  );
2834
- return b === 0 ? !1 : w / b >= hs;
2875
+ return b === 0 ? !1 : w / b >= gs;
2835
2876
  },
2836
2877
  getBufferedFrameCount: () => t.size(),
2837
2878
  tick(c) {
2838
2879
  const d = Xe();
2839
- d?.onBufferTick(), l(
2880
+ d?.onBufferTick(), u(
2840
2881
  c.queue,
2841
2882
  c.elapsedMs,
2842
2883
  c.availablePaths
2843
2884
  ), t.pruneBefore(c.elapsedMs - rr);
2844
- const w = Mr(
2885
+ const w = Cr(
2845
2886
  c.queue,
2846
2887
  c.elapsedMs,
2847
2888
  c.availablePaths,
@@ -2850,7 +2891,7 @@ function la(e) {
2850
2891
  { mouthPath: w.diffPath, expressionPath: c.expressionPath },
2851
2892
  c.expressionDrawKey
2852
2893
  ), I = () => (f(b, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
2853
- if (u(b, c.expressionPath) || c.playbackState.lastDrawnKey === h)
2894
+ if (l(b, c.expressionPath) || c.playbackState.lastDrawnKey === h)
2854
2895
  return I();
2855
2896
  const v = t.findForMouthKey(
2856
2897
  b,
@@ -2864,7 +2905,7 @@ function la(e) {
2864
2905
  }
2865
2906
  };
2866
2907
  }
2867
- const fa = `
2908
+ const vo = `
2868
2909
  in vec2 aPosition;
2869
2910
  out vec2 vTextureCoord;
2870
2911
 
@@ -2892,7 +2933,7 @@ void main(void)
2892
2933
  gl_Position = filterVertexPosition();
2893
2934
  vTextureCoord = filterTextureCoord();
2894
2935
  }
2895
- `, da = `
2936
+ `, bo = `
2896
2937
  in vec2 vTextureCoord;
2897
2938
  out vec4 finalColor;
2898
2939
 
@@ -2907,11 +2948,11 @@ void main(void)
2907
2948
  finalColor = vec4(color.rgb, keep);
2908
2949
  }
2909
2950
  `;
2910
- function nn(e = 5) {
2911
- const t = new es({
2912
- glProgram: ts.from({
2913
- vertex: fa,
2914
- fragment: da,
2951
+ function on(e = 5) {
2952
+ const t = new ns({
2953
+ glProgram: ss.from({
2954
+ vertex: vo,
2955
+ fragment: bo,
2915
2956
  name: "threshold-key-filter"
2916
2957
  }),
2917
2958
  resources: {
@@ -2926,16 +2967,16 @@ function nn(e = 5) {
2926
2967
  t.resources.thresholdUniforms.uniforms.uThreshold * 255
2927
2968
  ), t;
2928
2969
  }
2929
- function ma(e, t, r) {
2970
+ function ko(e, t, r) {
2930
2971
  return e > r || t > r;
2931
2972
  }
2932
- function ha(e) {
2973
+ function To(e) {
2933
2974
  return e ? e.getParameter(e.MAX_TEXTURE_SIZE) : 4096;
2934
2975
  }
2935
- function pa(e, t) {
2936
- return t != null && t > 0 ? Math.floor(t) : ha(e);
2976
+ function Eo(e, t) {
2977
+ return t != null && t > 0 ? Math.floor(t) : To(e);
2937
2978
  }
2938
- function wa(e, t) {
2979
+ function Io(e, t) {
2939
2980
  const r = document.createElement("canvas");
2940
2981
  r.width = t.w, r.height = t.h;
2941
2982
  const n = r.getContext("2d");
@@ -2943,48 +2984,48 @@ function wa(e, t) {
2943
2984
  throw new Error("Failed to acquire 2d context for atlas cell crop");
2944
2985
  return n.drawImage(e, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
2945
2986
  }
2946
- function Kn(e) {
2987
+ function zn(e) {
2947
2988
  return fetch(e).then((t) => {
2948
2989
  if (!t.ok) throw new Error(`Failed to load image: ${e}`);
2949
2990
  return t.blob();
2950
2991
  }).then((t) => createImageBitmap(t));
2951
2992
  }
2952
- async function sn(e, t, r, n, s) {
2953
- const i = r ? await Dn(e, s) : await fetch(e).then((c) => {
2993
+ async function an(e, t, r, n, s) {
2994
+ const i = r ? await Ln(e, s) : await fetch(e).then((c) => {
2954
2995
  if (!c.ok) throw new Error(`Failed to load ${e}`);
2955
2996
  return c.json();
2956
- }), o = i.sheets?.[0];
2957
- if (!o?.path) throw new Error(`${e} has no sheets[0].path`);
2958
- const a = /* @__PURE__ */ new Map(), l = async (c, d) => {
2959
- const w = Ln(t, d, r), b = r ? await fi(
2997
+ }), a = i.sheets?.[0];
2998
+ if (!a?.path) throw new Error(`${e} has no sheets[0].path`);
2999
+ const o = /* @__PURE__ */ new Map(), u = async (c, d) => {
3000
+ const w = Un(t, d, r), b = r ? await Si(
2960
3001
  await yt(w, s ?? "")
2961
- ) : await Kn(w);
2962
- if (ma(b.width, b.height, n))
3002
+ ) : await zn(w);
3003
+ if (ko(b.width, b.height, n))
2963
3004
  return console.info(
2964
3005
  `[PixiVisemeCompositor] Sheet ${d} (${b.width}x${b.height}) exceeds MAX_TEXTURE_SIZE=${n}; using per-cell crops.`
2965
3006
  ), { mode: "cells", bitmap: b };
2966
3007
  const h = _e.from(b);
2967
3008
  return h.source.scaleMode = "nearest", { mode: "full", texture: h };
2968
3009
  };
2969
- a.set(o.index, await l(o.index, o.path));
3010
+ o.set(a.index, await u(a.index, a.path));
2970
3011
  for (const c of i.sheets ?? [])
2971
- c.index !== o.index && c.path && a.set(c.index, await l(c.index, c.path));
3012
+ c.index !== a.index && c.path && o.set(c.index, await u(c.index, c.path));
2972
3013
  const f = /* @__PURE__ */ new Map();
2973
3014
  for (const c of i.cells ?? [])
2974
3015
  c.path && f.set(c.path, c);
2975
- const u = /* @__PURE__ */ new Map();
3016
+ const l = /* @__PURE__ */ new Map();
2976
3017
  for (const c of i.sheets ?? [])
2977
- u.set(c.index, c);
3018
+ l.set(c.index, c);
2978
3019
  return {
2979
3020
  atlasMeta: i,
2980
3021
  cellByPath: f,
2981
- sheetByIndex: u,
3022
+ sheetByIndex: l,
2982
3023
  diffBase: t,
2983
- sheets: a
3024
+ sheets: o
2984
3025
  };
2985
3026
  }
2986
- async function ga(e, t = {}) {
2987
- const r = new rs();
3027
+ async function Ao(e, t = {}) {
3028
+ const r = new is();
2988
3029
  try {
2989
3030
  await r.init({
2990
3031
  canvas: e,
@@ -3002,44 +3043,44 @@ async function ga(e, t = {}) {
3002
3043
  } catch (p) {
3003
3044
  throw r.destroy({ removeView: !1 }), p;
3004
3045
  }
3005
- if (r.renderer.type !== ns.WEBGL)
3046
+ if (r.renderer.type !== os.WEBGL)
3006
3047
  throw r.destroy({ removeView: !1 }), new Error("Pixi did not initialize a WebGL renderer");
3007
- const n = pa(
3048
+ const n = Eo(
3008
3049
  r.renderer.gl,
3009
3050
  t.maxTextureSize
3010
3051
  );
3011
- let s = !1, i = !1, o = !1;
3012
- const a = r.canvas, l = () => {
3013
- s = !0, !i && !o && (i = !0, t.onWebGlContextLost?.());
3052
+ let s = !1, i = !1, a = !1;
3053
+ const o = r.canvas, u = () => {
3054
+ s = !0, !i && !a && (i = !0, t.onWebGlContextLost?.());
3014
3055
  };
3015
- a.addEventListener("webglcontextlost", l);
3016
- const f = new kt(_e.EMPTY), u = new kt(_e.EMPTY);
3017
- u.visible = !1, u.alpha = 0;
3056
+ o.addEventListener("webglcontextlost", u);
3057
+ const f = new kt(_e.EMPTY), l = new kt(_e.EMPTY);
3058
+ l.visible = !1, l.alpha = 0;
3018
3059
  const c = new kt(_e.EMPTY), d = new kt(_e.EMPTY), w = new kt(_e.EMPTY);
3019
3060
  w.visible = !1;
3020
- const b = nn(5), h = nn(5);
3021
- c.filters = [b], d.filters = [h], r.stage.addChild(f), r.stage.addChild(u), r.stage.addChild(c), r.stage.addChild(d), r.stage.addChild(w);
3061
+ const b = on(5), h = on(5);
3062
+ c.filters = [b], d.filters = [h], r.stage.addChild(f), r.stage.addChild(l), r.stage.addChild(c), r.stage.addChild(d), r.stage.addChild(w);
3022
3063
  let I = null, v = null, x = null, g = null, k = null, B = null, R = null, Y = 842, L = 1264, T = null, A = 5;
3023
3064
  const M = /* @__PURE__ */ new Map();
3024
3065
  let D = null, ee = null, U = null;
3025
- const te = hn(() => {
3066
+ const te = wn(() => {
3026
3067
  M.clear(), B = null, R = null, I = null, T = null;
3027
3068
  }), X = (p, S) => {
3028
3069
  Y = p, L = S, r.renderer.resize(p, S), (e.width !== p || e.height !== S) && (e.width = p, e.height = S);
3029
3070
  }, z = () => {
3030
3071
  c.visible = !1, d.visible = !1, c.texture = _e.EMPTY, d.texture = _e.EMPTY, D = null, ee = null;
3031
3072
  }, de = () => {
3032
- k = null, u.visible = !1, u.alpha = 0;
3073
+ k = null, l.visible = !1, l.alpha = 0;
3033
3074
  }, ie = () => {
3034
3075
  f.visible = !0, f.width = Y, f.height = L, f.x = 0, f.y = 0;
3035
3076
  }, J = () => {
3036
- u.width = Y, u.height = L, u.x = 0, u.y = 0;
3077
+ l.width = Y, l.height = L, l.x = 0, l.y = 0;
3037
3078
  }, fe = () => {
3038
3079
  w.visible = !1, de(), I && (f.texture = I, ie());
3039
3080
  }, me = () => {
3040
- !k && !u.visible || fe();
3081
+ !k && !l.visible || fe();
3041
3082
  }, Se = (p) => {
3042
- if (o || s || !I) {
3083
+ if (a || s || !I) {
3043
3084
  fe();
3044
3085
  return;
3045
3086
  }
@@ -3048,19 +3089,19 @@ async function ga(e, t = {}) {
3048
3089
  fe();
3049
3090
  return;
3050
3091
  }
3051
- z(), w.visible = !1, f.texture = v, ie(), u.texture = I, J(), u.alpha = 0, u.visible = !0, k = {
3092
+ z(), w.visible = !1, f.texture = v, ie(), l.texture = I, J(), l.alpha = 0, l.visible = !0, k = {
3052
3093
  startMs: performance.now(),
3053
3094
  durationMs: S
3054
3095
  }, $();
3055
3096
  }, j = (p = performance.now()) => {
3056
3097
  if (!k) return !1;
3057
- if (o || s)
3098
+ if (a || s)
3058
3099
  return me(), !1;
3059
3100
  const S = (p - k.startMs) / Math.max(1, k.durationMs);
3060
3101
  if (S >= 1)
3061
3102
  return fe(), $(), !1;
3062
3103
  const C = Math.min(1, Math.max(0, S)), ue = C * C * (3 - 2 * C);
3063
- return u.alpha = ue, u.visible = !0, $(), !0;
3104
+ return l.alpha = ue, l.visible = !0, $(), !0;
3064
3105
  }, y = () => {
3065
3106
  if (x) {
3066
3107
  try {
@@ -3072,40 +3113,40 @@ async function ga(e, t = {}) {
3072
3113
  v && (v.destroy(!1), v = null), g = null;
3073
3114
  }, E = (p, S) => {
3074
3115
  const C = p.cellByPath.get(S);
3075
- if (!C || !Rn(C)) return null;
3116
+ if (!C || !Fn(C)) return null;
3076
3117
  const ue = `${p.diffBase}::${S}`;
3077
- let ae = M.get(ue);
3078
- if (!ae) {
3118
+ let oe = M.get(ue);
3119
+ if (!oe) {
3079
3120
  const he = C.sheet ?? 0, ge = p.sheets.get(he);
3080
3121
  if (!ge) return null;
3081
3122
  let ve, _t = !1;
3082
3123
  if (ge.mode === "full")
3083
3124
  ve = new _e({
3084
3125
  source: ge.texture.source,
3085
- frame: new is(C.x, C.y, C.w, C.h)
3126
+ frame: new cs(C.x, C.y, C.w, C.h)
3086
3127
  });
3087
3128
  else {
3088
- const m = wa(ge.bitmap, C);
3129
+ const m = Io(ge.bitmap, C);
3089
3130
  ve = _e.from(m), ve.source.scaleMode = "nearest", _t = !0;
3090
3131
  }
3091
- ae = { texture: ve, ownsSource: _t }, M.set(ue, ae);
3132
+ oe = { texture: ve, ownsSource: _t }, M.set(ue, oe);
3092
3133
  }
3093
- return { texture: ae.texture, cell: C };
3134
+ return { texture: oe.texture, cell: C };
3094
3135
  }, N = (p, S, C, ue) => {
3095
3136
  if (!ue || !C)
3096
3137
  return p.visible = !1, p.texture = _e.EMPTY, !1;
3097
- const ae = E(C, ue);
3098
- if (!ae)
3138
+ const oe = E(C, ue);
3139
+ if (!oe)
3099
3140
  return p.visible = !1, p.texture = _e.EMPTY, !1;
3100
- const he = Cn(C.atlasMeta, ae.cell);
3101
- return S.setThreshold(A), p.texture = ae.texture, p.x = he.x, p.y = he.y, p.width = ae.cell.w, p.height = ae.cell.h, p.visible = !0, !0;
3141
+ const he = Bn(C.atlasMeta, oe.cell);
3142
+ return S.setThreshold(A), p.texture = oe.texture, p.x = he.x, p.y = he.y, p.width = oe.cell.w, p.height = oe.cell.h, p.visible = !0, !0;
3102
3143
  }, G = (p) => {
3103
3144
  if (!p || !B) return null;
3104
3145
  const S = T ?? new Set(B.cellByPath.keys());
3105
- return kr(p, S) ?? (S.has(p) ? p : null);
3146
+ return Tr(p, S) ?? (S.has(p) ? p : null);
3106
3147
  }, W = (p) => {
3107
3148
  w.visible = !1, fe();
3108
- const S = G(p.mouthPath), C = p.expressionPath && R ? Er(
3149
+ const S = G(p.mouthPath), C = p.expressionPath && R ? Ir(
3109
3150
  p.expressionPath,
3110
3151
  (ue) => R.cellByPath.has(ue)
3111
3152
  ) : null;
@@ -3116,7 +3157,7 @@ async function ga(e, t = {}) {
3116
3157
  C
3117
3158
  ), ee = C) : C ? d.visible = !0 : d.visible = !1;
3118
3159
  }, $ = () => {
3119
- if (!(o || s || document.hidden))
3160
+ if (!(a || s || document.hidden))
3120
3161
  try {
3121
3162
  r.render();
3122
3163
  } catch {
@@ -3124,25 +3165,25 @@ async function ga(e, t = {}) {
3124
3165
  };
3125
3166
  return {
3126
3167
  async loadAssets(p) {
3127
- if (o) return { width: Y, height: L, visemePaths: [] };
3168
+ if (a) return { width: Y, height: L, visemePaths: [] };
3128
3169
  const S = xt();
3129
3170
  if (S && !p)
3130
3171
  throw new Error("Encrypted assets enabled but no key provided");
3131
- const C = S ? await mi(
3172
+ const C = S ? await bi(
3132
3173
  await yt(Ht(), p ?? "")
3133
- ) : await Kn(Ht());
3174
+ ) : await zn(Ht());
3134
3175
  I && I.destroy(!0), I = _e.from(C), I.source.scaleMode = "linear";
3135
- const ue = pn();
3136
- B = await sn(
3137
- wn(),
3176
+ const ue = gn();
3177
+ B = await an(
3178
+ yn(),
3138
3179
  ue,
3139
3180
  S,
3140
3181
  n,
3141
3182
  p
3142
3183
  );
3143
3184
  try {
3144
- R = await sn(
3145
- gn(),
3185
+ R = await an(
3186
+ _n(),
3146
3187
  ue,
3147
3188
  S,
3148
3189
  n,
@@ -3154,14 +3195,14 @@ async function ga(e, t = {}) {
3154
3195
  he
3155
3196
  ), R = null;
3156
3197
  }
3157
- const ae = Mn(
3198
+ const oe = Dn(
3158
3199
  B.atlasMeta,
3159
3200
  C.width,
3160
3201
  C.height
3161
3202
  );
3162
- return X(ae.width, ae.height), A = Xt(B.atlasMeta), b.setThreshold(A), h.setThreshold(A), T = new Set(B.cellByPath.keys()), M.clear(), fe(), z(), $(), {
3163
- width: ae.width,
3164
- height: ae.height,
3203
+ return X(oe.width, oe.height), A = Xt(B.atlasMeta), b.setThreshold(A), h.setThreshold(A), T = new Set(B.cellByPath.keys()), M.clear(), fe(), z(), $(), {
3204
+ width: oe.width,
3205
+ height: oe.height,
3165
3206
  visemePaths: [...B.cellByPath.keys()]
3166
3207
  };
3167
3208
  },
@@ -3169,10 +3210,10 @@ async function ga(e, t = {}) {
3169
3210
  return T;
3170
3211
  },
3171
3212
  drawLiveFrame(p) {
3172
- o || s || !I || (me(), W(p), $());
3213
+ a || s || !I || (me(), W(p), $());
3173
3214
  },
3174
3215
  drawIdleVideo(p, S) {
3175
- o || s || document.hidden || S && !S() || p.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (de(), z(), w.visible = !1, !v || g !== p ? (y(), x = new ss({
3216
+ a || s || document.hidden || S && !S() || p.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (de(), z(), w.visible = !1, !v || g !== p ? (y(), x = new as({
3176
3217
  resource: p,
3177
3218
  autoPlay: !1,
3178
3219
  updateFPS: 0
@@ -3185,10 +3226,10 @@ async function ga(e, t = {}) {
3185
3226
  return k != null;
3186
3227
  },
3187
3228
  renderSilOnly() {
3188
- o || s || !I || (z(), fe(), $());
3229
+ a || s || !I || (z(), fe(), $());
3189
3230
  },
3190
3231
  blitBitmap(p) {
3191
- o || s || (me(), z(), U && (U.destroy(!0), U = null), U = _e.from(p), w.texture = U, w.visible = !0, w.x = 0, w.y = 0, w.width = Y, w.height = L, f.visible = !1, $());
3232
+ a || s || (me(), z(), U && (U.destroy(!0), U = null), U = _e.from(p), w.texture = U, w.visible = !0, w.x = 0, w.y = 0, w.width = Y, w.height = L, f.visible = !1, $());
3192
3233
  },
3193
3234
  async compositePrefetchFrame(p) {
3194
3235
  return null;
@@ -3198,8 +3239,8 @@ async function ga(e, t = {}) {
3198
3239
  return s;
3199
3240
  },
3200
3241
  dispose() {
3201
- if (o) return;
3202
- o = !0, a.removeEventListener("webglcontextlost", l), te(), y(), U && (U.destroy(!0), U = null);
3242
+ if (a) return;
3243
+ a = !0, o.removeEventListener("webglcontextlost", u), te(), y(), U && (U.destroy(!0), U = null);
3203
3244
  for (const { texture: S, ownsSource: C } of M.values())
3204
3245
  S.destroy(C);
3205
3246
  M.clear(), I && (I.destroy(!0), I = null);
@@ -3219,9 +3260,9 @@ async function ga(e, t = {}) {
3219
3260
  }
3220
3261
  };
3221
3262
  }
3222
- const an = -1, Wt = 1e5, on = /* @__PURE__ */ new Map();
3223
- async function ya(e) {
3224
- let t = on.get(e);
3263
+ const cn = -1, Wt = 1e5, un = /* @__PURE__ */ new Map();
3264
+ async function Po(e) {
3265
+ let t = un.get(e);
3225
3266
  if (!t) {
3226
3267
  const r = await fetch(e);
3227
3268
  if (!r.ok)
@@ -3229,11 +3270,11 @@ async function ya(e) {
3229
3270
  `Failed to fetch worker script (${r.status}): ${e}`
3230
3271
  );
3231
3272
  const n = await r.blob();
3232
- t = URL.createObjectURL(n), on.set(e, t);
3273
+ t = URL.createObjectURL(n), un.set(e, t);
3233
3274
  }
3234
3275
  return new Worker(t, { name: "visemeDiffPreview" });
3235
3276
  }
3236
- function _a() {
3277
+ function xo() {
3237
3278
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
3238
3279
  }
3239
3280
  function pr(e, t) {
@@ -3241,34 +3282,34 @@ function pr(e, t) {
3241
3282
  const r = e.getContext("2d");
3242
3283
  r && r.drawImage(t, 0, 0);
3243
3284
  }
3244
- function cn(e, t) {
3285
+ function ln(e, t) {
3245
3286
  let r = 0, n = null;
3246
- const s = Cr(async (i, o) => (await mr(), await hr(e, i), s.isLatestSeq(o)));
3287
+ const s = Rr(async (i, a) => (await mr(), await hr(e, i), s.isLatestSeq(a)));
3247
3288
  return {
3248
3289
  usesWorker: !1,
3249
3290
  usesPixi: !1,
3250
3291
  async loadAssets(i) {
3251
- const o = await mr(i);
3252
- return n = o.visemePaths ? new Set(o.visemePaths) : null, o;
3292
+ const a = await mr(i);
3293
+ return n = a.visemePaths ? new Set(a.visemePaths) : null, a;
3253
3294
  },
3254
3295
  getVisemeAtlasPaths() {
3255
3296
  return n;
3256
3297
  },
3257
3298
  async renderSilOnly() {
3258
- r += 1, s.reset(), await Yi(e);
3299
+ r += 1, s.reset(), await so(e);
3259
3300
  },
3260
- drawLiveFrame(i, o, a, l) {
3261
- s.enqueue(o, a, l);
3301
+ drawLiveFrame(i, a, o, u) {
3302
+ s.enqueue(a, o, u);
3262
3303
  },
3263
- async compositePrefetchFrame(i, o) {
3304
+ async compositePrefetchFrame(i, a) {
3264
3305
  try {
3265
- return await ji(i);
3306
+ return await no(i);
3266
3307
  } catch {
3267
3308
  return null;
3268
3309
  }
3269
3310
  },
3270
- blitBitmap(i, o) {
3271
- pr(i, o);
3311
+ blitBitmap(i, a) {
3312
+ pr(i, a);
3272
3313
  },
3273
3314
  drawIdleVideo() {
3274
3315
  },
@@ -3283,11 +3324,11 @@ function cn(e, t) {
3283
3324
  return !1;
3284
3325
  },
3285
3326
  supportsBufferedPlayback: !0,
3286
- async renderViseme(i, o) {
3327
+ async renderViseme(i, a) {
3287
3328
  r += 1;
3288
- const a = r;
3289
- t.onStatus?.(o), await hr(i, {
3290
- mouthPath: It(o),
3329
+ const o = r;
3330
+ t.onStatus?.(a), await hr(i, {
3331
+ mouthPath: It(a),
3291
3332
  expressionPath: null
3292
3333
  });
3293
3334
  },
@@ -3296,11 +3337,11 @@ function cn(e, t) {
3296
3337
  }
3297
3338
  };
3298
3339
  }
3299
- function Sa(e, t, r) {
3300
- let n = null, s = 1, i = 0, o = !1, a = !1, l = null;
3301
- const f = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
3340
+ function Mo(e, t, r) {
3341
+ let n = null, s = 1, i = 0, a = !1, o = !1, u = null;
3342
+ const f = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
3302
3343
  let c = Wt;
3303
- const d = Cr(async (x, g, k) => (f.set(g, {
3344
+ const d = Rr(async (x, g, k) => (f.set(g, {
3304
3345
  drawKey: k.drawKey,
3305
3346
  onDisplayed: k.onDisplayed
3306
3347
  }), await I(
@@ -3313,7 +3354,7 @@ function Sa(e, t, r) {
3313
3354
  void 0,
3314
3355
  !0
3315
3356
  ), !1)), w = (x) => {
3316
- if (x === an) {
3357
+ if (x === cn) {
3317
3358
  let B = -1, R;
3318
3359
  for (const [Y, L] of f)
3319
3360
  Y >= B && (B = Y, R = L);
@@ -3323,9 +3364,9 @@ function Sa(e, t, r) {
3323
3364
  const g = -x, k = f.get(g);
3324
3365
  f.delete(g), k?.onDisplayed?.(k.drawKey);
3325
3366
  }, b = /* @__PURE__ */ new Map(), h = (x, g) => {
3326
- a || !n || n.postMessage(x, []);
3367
+ o || !n || n.postMessage(x, []);
3327
3368
  }, I = (x, g, k = !1) => {
3328
- if (a) return Promise.resolve();
3369
+ if (o) return Promise.resolve();
3329
3370
  const B = s++;
3330
3371
  return new Promise((R, Y) => {
3331
3372
  b.set(B, {
@@ -3336,8 +3377,8 @@ function Sa(e, t, r) {
3336
3377
  }), h({ ...x, requestId: B });
3337
3378
  });
3338
3379
  }, v = (async () => {
3339
- n = await ya(r), n.onmessage = (x) => {
3340
- if (a) return;
3380
+ n = await Po(r), n.onmessage = (x) => {
3381
+ if (o) return;
3341
3382
  const g = x.data;
3342
3383
  if (g.type === "status") {
3343
3384
  t.onStatus?.(g.label);
@@ -3345,8 +3386,8 @@ function Sa(e, t, r) {
3345
3386
  }
3346
3387
  if (g.type === "frame") {
3347
3388
  if (g.generation <= -Wt) {
3348
- const R = -g.generation, Y = u.get(R);
3349
- u.delete(R), Y?.resolve(g.bitmap);
3389
+ const R = -g.generation, Y = l.get(R);
3390
+ l.delete(R), Y?.resolve(g.bitmap);
3350
3391
  return;
3351
3392
  }
3352
3393
  const B = g.generation < 0;
@@ -3354,7 +3395,7 @@ function Sa(e, t, r) {
3354
3395
  g.bitmap.close();
3355
3396
  return;
3356
3397
  }
3357
- if (B && !(g.generation === an)) {
3398
+ if (B && !(g.generation === cn)) {
3358
3399
  const Y = -g.generation;
3359
3400
  if (!d.isLatestSeq(Y)) {
3360
3401
  Xe()?.onWorkerStale(), g.bitmap.close();
@@ -3375,7 +3416,7 @@ function Sa(e, t, r) {
3375
3416
  b.delete(g.requestId), k.resolve();
3376
3417
  break;
3377
3418
  case "loadAssetsDone":
3378
- b.delete(g.requestId), l = g.visemePaths?.length ? new Set(g.visemePaths) : null, k.resolve({ width: g.width, height: g.height, visemePaths: g.visemePaths });
3419
+ b.delete(g.requestId), u = g.visemePaths?.length ? new Set(g.visemePaths) : null, k.resolve({ width: g.width, height: g.height, visemePaths: g.visemePaths });
3379
3420
  break;
3380
3421
  case "renderDone":
3381
3422
  if (k.expectRenderDone && k.generation != null && g.generation !== k.generation)
@@ -3390,33 +3431,33 @@ function Sa(e, t, r) {
3390
3431
  break;
3391
3432
  }
3392
3433
  }, n.onerror = (x) => {
3393
- if (a) return;
3434
+ if (o) return;
3394
3435
  const g = x.message || "Worker error";
3395
3436
  t.onError?.(g);
3396
3437
  for (const [, k] of b)
3397
3438
  k.reject(new Error(g));
3398
3439
  b.clear();
3399
- }, await I({ type: "init" }), o = !0;
3440
+ }, await I({ type: "init" }), a = !0;
3400
3441
  })();
3401
3442
  return {
3402
3443
  usesWorker: !0,
3403
3444
  usesPixi: !1,
3404
3445
  async loadAssets(x) {
3405
- if (a) return { width: 842, height: 1264 };
3406
- if (await v, a) return { width: 842, height: 1264 };
3407
- if (!o) throw new Error("Worker init failed");
3446
+ if (o) return { width: 842, height: 1264 };
3447
+ if (await v, o) return { width: 842, height: 1264 };
3448
+ if (!a) throw new Error("Worker init failed");
3408
3449
  return await I({
3409
3450
  type: "loadAssets",
3410
3451
  keyHex: x,
3411
- urls: Cs(rt())
3452
+ urls: Bs(rt())
3412
3453
  }) ?? { width: 842, height: 1264 };
3413
3454
  },
3414
3455
  getVisemeAtlasPaths() {
3415
- return l;
3456
+ return u;
3416
3457
  },
3417
3458
  async renderSilOnly() {
3418
- if (a || (await v, a)) return;
3419
- i += 1, d.reset(), f.clear(), u.forEach(({ resolve: g }) => g(null)), u.clear(), c = Wt;
3459
+ if (o || (await v, o)) return;
3460
+ i += 1, d.reset(), f.clear(), l.forEach(({ resolve: g }) => g(null)), l.clear(), c = Wt;
3420
3461
  const x = i;
3421
3462
  await I({ type: "cancelLiveDraws" }), await I(
3422
3463
  { type: "renderSil", generation: x },
@@ -3425,16 +3466,16 @@ function Sa(e, t, r) {
3425
3466
  );
3426
3467
  },
3427
3468
  drawLiveFrame(x, g, k, B) {
3428
- a || v.then(() => {
3429
- a || d.enqueue(g, k, B);
3469
+ o || v.then(() => {
3470
+ o || d.enqueue(g, k, B);
3430
3471
  });
3431
3472
  },
3432
3473
  compositePrefetchFrame(x, g) {
3433
- return a ? Promise.resolve(null) : v.then(() => {
3434
- if (a) return null;
3474
+ return o ? Promise.resolve(null) : v.then(() => {
3475
+ if (o) return null;
3435
3476
  const k = ++c;
3436
3477
  return new Promise((B) => {
3437
- u.set(k, { resolve: B }), I(
3478
+ l.set(k, { resolve: B }), I(
3438
3479
  {
3439
3480
  type: "drawFrame",
3440
3481
  diffPath: x.mouthPath,
@@ -3444,7 +3485,7 @@ function Sa(e, t, r) {
3444
3485
  void 0,
3445
3486
  !0
3446
3487
  ).catch(() => {
3447
- u.delete(k), B(null);
3488
+ l.delete(k), B(null);
3448
3489
  });
3449
3490
  });
3450
3491
  });
@@ -3466,7 +3507,7 @@ function Sa(e, t, r) {
3466
3507
  },
3467
3508
  supportsBufferedPlayback: !0,
3468
3509
  async renderViseme(x, g, k = {}) {
3469
- if (a || (await v, a)) return;
3510
+ if (o || (await v, o)) return;
3470
3511
  i += 1, d.reset(), f.clear();
3471
3512
  const B = i;
3472
3513
  try {
@@ -3489,8 +3530,8 @@ function Sa(e, t, r) {
3489
3530
  }
3490
3531
  },
3491
3532
  dispose() {
3492
- if (!a) {
3493
- a = !0, i += 1, d.reset(), f.clear(), u.forEach(({ resolve: x }) => x(null)), u.clear(), c = Wt;
3533
+ if (!o) {
3534
+ o = !0, i += 1, d.reset(), f.clear(), l.forEach(({ resolve: x }) => x(null)), l.clear(), c = Wt;
3494
3535
  for (const [, x] of b)
3495
3536
  x.resolve();
3496
3537
  b.clear(), n?.terminate(), n = null;
@@ -3498,49 +3539,49 @@ function Sa(e, t, r) {
3498
3539
  }
3499
3540
  };
3500
3541
  }
3501
- async function va(e, t) {
3502
- const r = await ga(e, {
3542
+ async function Co(e, t) {
3543
+ const r = await Ao(e, {
3503
3544
  onWebGlContextLost: t.onWebGlContextLost,
3504
3545
  maxTextureSize: t.pixiMaxTextureSize
3505
3546
  });
3506
3547
  let n = 0, s = null, i = !1;
3507
- const o = Cr(async (a, l) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (Xe()?.onWorkerStale(), !1) : (r.drawLiveFrame(a), o.isLatestSeq(l)));
3548
+ const a = Rr(async (o, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (Xe()?.onWorkerStale(), !1) : (r.drawLiveFrame(o), a.isLatestSeq(u)));
3508
3549
  return {
3509
3550
  usesWorker: !1,
3510
3551
  usesPixi: !0,
3511
- async loadAssets(a) {
3552
+ async loadAssets(o) {
3512
3553
  if (i) return { width: 842, height: 1264 };
3513
- const l = await r.loadAssets(a);
3514
- return s = l.visemePaths?.length ? new Set(l.visemePaths) : null, l;
3554
+ const u = await r.loadAssets(o);
3555
+ return s = u.visemePaths?.length ? new Set(u.visemePaths) : null, u;
3515
3556
  },
3516
3557
  getVisemeAtlasPaths() {
3517
3558
  return s;
3518
3559
  },
3519
3560
  async renderSilOnly() {
3520
- i || (n += 1, o.reset(), r.renderSilOnly());
3561
+ i || (n += 1, a.reset(), r.renderSilOnly());
3521
3562
  },
3522
- drawLiveFrame(a, l, f, u) {
3523
- i || o.enqueue(l, f, u);
3563
+ drawLiveFrame(o, u, f, l) {
3564
+ i || a.enqueue(u, f, l);
3524
3565
  },
3525
- async compositePrefetchFrame(a, l) {
3566
+ async compositePrefetchFrame(o, u) {
3526
3567
  if (i) return null;
3527
3568
  try {
3528
- return await r.compositePrefetchFrame(a);
3569
+ return await r.compositePrefetchFrame(o);
3529
3570
  } catch {
3530
3571
  return null;
3531
3572
  }
3532
3573
  },
3533
- blitBitmap(a, l) {
3534
- i || t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() || r.blitBitmap(l);
3574
+ blitBitmap(o, u) {
3575
+ i || t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() || r.blitBitmap(u);
3535
3576
  },
3536
- drawIdleVideo(a, l) {
3537
- i || r.drawIdleVideo(a, l);
3577
+ drawIdleVideo(o, u) {
3578
+ i || r.drawIdleVideo(o, u);
3538
3579
  },
3539
- beginIdleToSilCrossfade(a) {
3540
- i || r.beginIdleToSilCrossfade(a);
3580
+ beginIdleToSilCrossfade(o) {
3581
+ i || r.beginIdleToSilCrossfade(o);
3541
3582
  },
3542
- tickIdleToSilCrossfade(a) {
3543
- return i ? !1 : r.tickIdleToSilCrossfade(a);
3583
+ tickIdleToSilCrossfade(o) {
3584
+ return i ? !1 : r.tickIdleToSilCrossfade(o);
3544
3585
  },
3545
3586
  finishIdleToSilCrossfade() {
3546
3587
  i || r.finishIdleToSilCrossfade();
@@ -3551,47 +3592,47 @@ async function va(e, t) {
3551
3592
  // Pixi composites mouth/expression on the GPU every frame — ImageBitmap
3552
3593
  // prefetch via extract.canvas causes main-thread/GPU stalls and memory growth.
3553
3594
  supportsBufferedPlayback: !1,
3554
- async renderViseme(a, l) {
3595
+ async renderViseme(o, u) {
3555
3596
  if (i) return;
3556
3597
  n += 1;
3557
3598
  const f = n;
3558
- o.reset(), t.onStatus?.(l), r.drawLiveFrame({
3559
- mouthPath: It(l),
3599
+ a.reset(), t.onStatus?.(u), r.drawLiveFrame({
3600
+ mouthPath: It(u),
3560
3601
  expressionPath: null
3561
3602
  });
3562
3603
  },
3563
3604
  dispose() {
3564
- i || (i = !0, n += 1, o.reset(), r.dispose());
3605
+ i || (i = !0, n += 1, a.reset(), r.dispose());
3565
3606
  }
3566
3607
  };
3567
3608
  }
3568
- function un(e, t) {
3569
- if (!_a())
3570
- return cn(e, t);
3571
- const r = fs(t.workerScriptUrl);
3609
+ function fn(e, t) {
3610
+ if (!xo())
3611
+ return ln(e, t);
3612
+ const r = hs(t.workerScriptUrl);
3572
3613
  try {
3573
- return Sa(e, t, r);
3614
+ return Mo(e, t, r);
3574
3615
  } catch {
3575
- return cn(e, t);
3616
+ return ln(e, t);
3576
3617
  }
3577
3618
  }
3578
- function ba(e, t = {}) {
3619
+ function Ro(e, t = {}) {
3579
3620
  if (t.preferLegacyRenderer)
3580
- return un(e, t);
3621
+ return fn(e, t);
3581
3622
  let r = null, n = !1, s = null, i = !1;
3582
- const o = () => r ? Promise.resolve(r) : (s || (s = (async () => {
3623
+ const a = () => r ? Promise.resolve(r) : (s || (s = (async () => {
3583
3624
  try {
3584
- const a = await va(e, t);
3625
+ const o = await Co(e, t);
3585
3626
  if (i)
3586
- throw a.dispose(), new Error("Renderer disposed during Pixi init");
3587
- return n = !0, r = a, a;
3588
- } catch (a) {
3627
+ throw o.dispose(), new Error("Renderer disposed during Pixi init");
3628
+ return n = !0, r = o, o;
3629
+ } catch (o) {
3589
3630
  if (i)
3590
- throw a instanceof Error ? a : new Error(String(a));
3631
+ throw o instanceof Error ? o : new Error(String(o));
3591
3632
  return console.warn(
3592
3633
  "[AiTwin] Pixi WebGL renderer unavailable, using Canvas2D fallback:",
3593
- a
3594
- ), r = un(e, t), n = !1, r;
3634
+ o
3635
+ ), r = fn(e, t), n = !1, r;
3595
3636
  }
3596
3637
  })()), s);
3597
3638
  return {
@@ -3601,34 +3642,34 @@ function ba(e, t = {}) {
3601
3642
  get usesPixi() {
3602
3643
  return n;
3603
3644
  },
3604
- async loadAssets(a) {
3605
- return (await o()).loadAssets(a);
3645
+ async loadAssets(o) {
3646
+ return (await a()).loadAssets(o);
3606
3647
  },
3607
3648
  getVisemeAtlasPaths() {
3608
3649
  return r?.getVisemeAtlasPaths() ?? null;
3609
3650
  },
3610
3651
  async renderSilOnly() {
3611
- return (await o()).renderSilOnly();
3652
+ return (await a()).renderSilOnly();
3612
3653
  },
3613
- drawLiveFrame(a, l, f, u) {
3614
- o().then((c) => {
3615
- i || c.drawLiveFrame(a, l, f, u);
3654
+ drawLiveFrame(o, u, f, l) {
3655
+ a().then((c) => {
3656
+ i || c.drawLiveFrame(o, u, f, l);
3616
3657
  });
3617
3658
  },
3618
- async compositePrefetchFrame(a, l) {
3619
- return (await o()).compositePrefetchFrame(a, l);
3659
+ async compositePrefetchFrame(o, u) {
3660
+ return (await a()).compositePrefetchFrame(o, u);
3620
3661
  },
3621
- blitBitmap(a, l) {
3622
- r && r.blitBitmap(a, l);
3662
+ blitBitmap(o, u) {
3663
+ r && r.blitBitmap(o, u);
3623
3664
  },
3624
- drawIdleVideo(a, l) {
3625
- r?.usesPixi && r.drawIdleVideo(a, l);
3665
+ drawIdleVideo(o, u) {
3666
+ r?.usesPixi && r.drawIdleVideo(o, u);
3626
3667
  },
3627
- beginIdleToSilCrossfade(a) {
3628
- r?.beginIdleToSilCrossfade(a);
3668
+ beginIdleToSilCrossfade(o) {
3669
+ r?.beginIdleToSilCrossfade(o);
3629
3670
  },
3630
- tickIdleToSilCrossfade(a) {
3631
- return r?.tickIdleToSilCrossfade(a) ?? !1;
3671
+ tickIdleToSilCrossfade(o) {
3672
+ return r?.tickIdleToSilCrossfade(o) ?? !1;
3632
3673
  },
3633
3674
  finishIdleToSilCrossfade() {
3634
3675
  r?.finishIdleToSilCrossfade();
@@ -3639,15 +3680,15 @@ function ba(e, t = {}) {
3639
3680
  get supportsBufferedPlayback() {
3640
3681
  return r?.supportsBufferedPlayback ?? !1;
3641
3682
  },
3642
- async renderViseme(a, l, f) {
3643
- return (await o()).renderViseme(a, l, f);
3683
+ async renderViseme(o, u, f) {
3684
+ return (await a()).renderViseme(o, u, f);
3644
3685
  },
3645
3686
  dispose() {
3646
3687
  i = !0, s = null, r?.dispose(), r = null;
3647
3688
  }
3648
3689
  };
3649
3690
  }
3650
- class ka extends Error {
3691
+ class Do extends Error {
3651
3692
  constructor(t, r) {
3652
3693
  super(`${t} timed out after ${Math.round(r / 1e3)}s`), this.name = "LoadTimeoutError";
3653
3694
  }
@@ -3655,27 +3696,27 @@ class ka extends Error {
3655
3696
  function cr(e, t, r) {
3656
3697
  return new Promise((n, s) => {
3657
3698
  const i = globalThis.setTimeout(() => {
3658
- s(new ka(r, t));
3699
+ s(new Do(r, t));
3659
3700
  }, t);
3660
3701
  e.then(
3661
- (o) => {
3662
- globalThis.clearTimeout(i), n(o);
3702
+ (a) => {
3703
+ globalThis.clearTimeout(i), n(a);
3663
3704
  },
3664
- (o) => {
3665
- globalThis.clearTimeout(i), s(o);
3705
+ (a) => {
3706
+ globalThis.clearTimeout(i), s(a);
3666
3707
  }
3667
3708
  );
3668
3709
  });
3669
3710
  }
3670
- const Ta = {
3711
+ const Bo = {
3671
3712
  position: "relative",
3672
3713
  display: "inline-block",
3673
3714
  lineHeight: 0
3674
- }, Ea = {
3715
+ }, Fo = {
3675
3716
  display: "block",
3676
3717
  maxWidth: "100%",
3677
3718
  height: "auto"
3678
- }, Ia = {
3719
+ }, Lo = {
3679
3720
  position: "absolute",
3680
3721
  inset: 0,
3681
3722
  display: "flex",
@@ -3688,22 +3729,22 @@ const Ta = {
3688
3729
  textAlign: "center"
3689
3730
  };
3690
3731
  function Tt(e) {
3691
- return gs(e) ? An : In;
3732
+ return Ss(e) ? Mn : xn;
3692
3733
  }
3693
3734
  function qe(e, t) {
3694
3735
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
3695
3736
  }
3696
- const Na = jn(function({
3737
+ const Yo = Qn(function({
3697
3738
  id: t,
3698
3739
  avatarId: r,
3699
3740
  faceId: n,
3700
3741
  assets: s,
3701
3742
  authToken: i,
3702
- apiBase: o,
3703
- ttsEngineId: a = ft,
3704
- voiceId: l,
3743
+ apiBase: a,
3744
+ ttsEngineId: o = ft,
3745
+ voiceId: u,
3705
3746
  speakingRate: f = Yt,
3706
- className: u,
3747
+ className: l,
3707
3748
  style: c,
3708
3749
  canvasStyle: d,
3709
3750
  onStatusChange: w,
@@ -3723,19 +3764,19 @@ const Na = jn(function({
3723
3764
  ee.current = R;
3724
3765
  const U = q(Y);
3725
3766
  U.current = Y;
3726
- const te = q(0), X = q(xr()), z = q(Ni()), de = q(!1), ie = q(0), J = q(0), fe = q(0), me = q(null), Se = q(null), j = q(!1), y = q(!1), E = q(!1), N = q(!1), G = q("sil"), W = q(0), $ = q(!1), p = q(
3767
+ const te = q(0), X = q(Mr()), z = q(zi()), de = q(!1), ie = q(0), J = q(0), fe = q(0), me = q(null), Se = q(null), j = q(!1), y = q(!1), E = q(!1), N = q(!1), G = q("sil"), W = q(0), $ = q(!1), p = q(
3727
3768
  null
3728
- ), S = q(!1), [C, ue] = ut("idle"), [ae, he] = ut(null), [ge, ve] = ut(!1), [_t, m] = ut(!1), [P, Q] = ut({ width: 842, height: 1264 }), [ce, ye] = ut(0), Ge = q(!1), le = q(i ?? null), Ee = o?.trim() || Pt, De = q(null), be = q(null), Ue = q(!1), Fe = q({ width: 842, height: 1264 }), Ve = q(null), Mt = q("sil"), nt = q(void 0), We = q(/* @__PURE__ */ new Map()), St = q(I), oe = q(b), st = q(h), pe = q(x), Ae = q(g), Ie = q(k), it = q(B), $e = q(Qi());
3729
- St.current = I, oe.current = b, st.current = h, pe.current = x, Ae.current = g, Ie.current = k, it.current = B, Je(() => {
3769
+ ), S = q(!1), [C, ue] = ut("idle"), [oe, he] = ut(null), [ge, ve] = ut(!1), [_t, m] = ut(!1), [P, Q] = ut({ width: 842, height: 1264 }), [ce, ye] = ut(0), Ge = q(!1), le = q(i ?? null), Ee = a?.trim() || Pt, De = q(null), be = q(null), Ue = q(!1), Fe = q({ width: 842, height: 1264 }), Ve = q(null), Mt = q("sil"), nt = q(void 0), We = q(/* @__PURE__ */ new Map()), St = q(I), ae = q(b), st = q(h), pe = q(x), Ae = q(g), Ie = q(k), it = q(B), $e = q(oo());
3770
+ St.current = I, ae.current = b, st.current = h, pe.current = x, Ae.current = g, Ie.current = k, it.current = B, Je(() => {
3730
3771
  const _ = $e.current;
3731
- return Jr(_), () => Jr(null);
3772
+ return en(_), () => en(null);
3732
3773
  }, []);
3733
3774
  const Ct = Ce(
3734
3775
  (_) => {
3735
- const F = _?.ttsEngineId ?? a ?? be.current?.ttsEngineId ?? ft, V = _?.voiceId ?? l ?? be.current?.voiceId ?? Tt(F);
3776
+ const F = _?.ttsEngineId ?? o ?? be.current?.ttsEngineId ?? ft, V = _?.voiceId ?? u ?? be.current?.voiceId ?? Tt(F);
3736
3777
  return { ttsEngineId: F, voiceId: V };
3737
3778
  },
3738
- [a, l]
3779
+ [o, u]
3739
3780
  ), Le = Ce((_) => {
3740
3781
  he(_), st.current?.(_);
3741
3782
  }, []), vt = Ce(
@@ -3744,22 +3785,22 @@ const Na = jn(function({
3744
3785
  },
3745
3786
  [w]
3746
3787
  ), ne = q(
3747
- Kr(vt, Ee, {
3788
+ Gr(vt, Ee, {
3748
3789
  onLipsyncDebug: (_) => Ie.current?.(_)
3749
3790
  })
3750
3791
  ), se = q(null);
3751
- Je(() => (ne.current = Kr(
3792
+ Je(() => (ne.current = Gr(
3752
3793
  vt,
3753
3794
  Ee,
3754
3795
  {
3755
3796
  onLipsyncDebug: (_) => Ie.current?.(_)
3756
3797
  }
3757
- ), i && ne.current.setDeveloperToken(i), ne.current.setTtsEngineId(a), () => {
3798
+ ), i && ne.current.setDeveloperToken(i), ne.current.setTtsEngineId(o), () => {
3758
3799
  ne.current.stop();
3759
3800
  const _ = se.current;
3760
3801
  _ && (_.disconnect(), se.current = null);
3761
- }), [vt, i, a, Ee]);
3762
- const Rr = Ce(() => (se.current || (se.current = li(
3802
+ }), [vt, i, o, Ee]);
3803
+ const Dr = Ce(() => (se.current || (se.current = _i(
3763
3804
  vt,
3764
3805
  {
3765
3806
  speakingRate: f,
@@ -3767,7 +3808,7 @@ const Na = jn(function({
3767
3808
  onBotOutput: (_) => Ae.current?.(_),
3768
3809
  onLipsyncDebug: (_) => Ie.current?.(_)
3769
3810
  }
3770
- ), se.current.setTtsEngineId(a)), se.current), [vt, f, a]), Pe = Ce(() => {
3811
+ ), se.current.setTtsEngineId(o)), se.current), [vt, f, o]), Pe = Ce(() => {
3771
3812
  me.current != null && (clearTimeout(me.current), me.current = null);
3772
3813
  }, []), xe = Ce(() => {
3773
3814
  Se.current != null && (clearTimeout(Se.current), Se.current = null), E.current = !1;
@@ -3781,12 +3822,12 @@ const Na = jn(function({
3781
3822
  p.current.setActive(!1);
3782
3823
  const F = p.current.getVideo();
3783
3824
  if (_?.usesPixi) {
3784
- _.drawIdleVideo(F), _.beginIdleToSilCrossfade(en);
3825
+ _.drawIdleVideo(F), _.beginIdleToSilCrossfade(rn);
3785
3826
  return;
3786
3827
  }
3787
3828
  (async () => {
3788
3829
  const V = A.current;
3789
- V && await ar(
3830
+ V && await or(
3790
3831
  V,
3791
3832
  F,
3792
3833
  null,
@@ -3794,10 +3835,10 @@ const Na = jn(function({
3794
3835
  Fe.current
3795
3836
  ).catch(() => {
3796
3837
  }), await new Promise(
3797
- (O) => setTimeout(O, en)
3838
+ (O) => setTimeout(O, rn)
3798
3839
  ), N.current && await _?.renderSilOnly();
3799
3840
  })();
3800
- }, [xe]), Dr = Ce(() => {
3841
+ }, [xe]), Br = Ce(() => {
3801
3842
  !S.current || !p.current || (N.current = !1, M.current?.finishIdleToSilCrossfade(), xe(), E.current = !0, Se.current = setTimeout(() => {
3802
3843
  if (Se.current = null, qe(
3803
3844
  ne.current,
@@ -3828,14 +3869,14 @@ const Na = jn(function({
3828
3869
  return;
3829
3870
  }
3830
3871
  setTimeout(O, 300);
3831
- }, Ji));
3832
- }, [xe]), at = Ce(() => {
3833
- if (Pe(), oe.current?.("sil"), j.current = !1, N.current = !1, !S.current || !p.current) {
3872
+ }, ao));
3873
+ }, [xe]), ot = Ce(() => {
3874
+ if (Pe(), ae.current?.("sil"), j.current = !1, N.current = !1, !S.current || !p.current) {
3834
3875
  E.current = !1;
3835
3876
  return;
3836
3877
  }
3837
- Dr();
3838
- }, [Pe, Dr]), Jt = Ce(
3878
+ Br();
3879
+ }, [Pe, Br]), Jt = Ce(
3839
3880
  async (_) => {
3840
3881
  const F = J.current, V = M.current, O = A.current, K = () => {
3841
3882
  _?.fallbackOnly || (j.current = !1);
@@ -3857,11 +3898,11 @@ const Na = jn(function({
3857
3898
  se.current
3858
3899
  ).isSpeaking())
3859
3900
  return;
3860
- at();
3901
+ ot();
3861
3902
  return;
3862
3903
  }
3863
- if (tn(X.current)) {
3864
- Re(X.current), at();
3904
+ if (nn(X.current)) {
3905
+ Re(X.current), ot();
3865
3906
  return;
3866
3907
  }
3867
3908
  if (ee.current && V.supportsBufferedPlayback && !_?.fallbackOnly) {
@@ -3870,17 +3911,17 @@ const Na = jn(function({
3870
3911
  se.current
3871
3912
  ).isSpeaking())
3872
3913
  return;
3873
- at();
3914
+ ot();
3874
3915
  return;
3875
3916
  }
3876
- const Te = na(
3917
+ const Te = mo(
3877
3918
  qe(
3878
3919
  ne.current,
3879
3920
  se.current
3880
3921
  ).getVisemeQueue(),
3881
3922
  W.current,
3882
3923
  G.current
3883
- ), He = sa(
3924
+ ), He = ho(
3884
3925
  Te,
3885
3926
  Ve.current
3886
3927
  );
@@ -3890,13 +3931,13 @@ const Na = jn(function({
3890
3931
  se.current
3891
3932
  ).isSpeaking())
3892
3933
  return;
3893
- at();
3934
+ ot();
3894
3935
  return;
3895
3936
  }
3896
3937
  try {
3897
3938
  await V.renderViseme(O, "sil", {
3898
3939
  from: Te,
3899
- transitionDurationMs: Wn
3940
+ transitionDurationMs: Kn
3900
3941
  });
3901
3942
  } catch (Ke) {
3902
3943
  if (Ke?.name !== "AbortError")
@@ -3913,10 +3954,10 @@ const Na = jn(function({
3913
3954
  K();
3914
3955
  return;
3915
3956
  }
3916
- at();
3957
+ ot();
3917
3958
  },
3918
- [ge, at]
3919
- ), ot = Ce(() => {
3959
+ [ge, ot]
3960
+ ), at = Ce(() => {
3920
3961
  if (y.current || j.current) return;
3921
3962
  y.current = !0, j.current = !0, Pe();
3922
3963
  const _ = J.current;
@@ -3924,14 +3965,14 @@ const Na = jn(function({
3924
3965
  y.current = !1;
3925
3966
  }), me.current = setTimeout(() => {
3926
3967
  me.current = null, _ === J.current && Jt({ fallbackOnly: !0 });
3927
- }, ia());
3928
- }, [Pe, Jt]), Br = Ce(async () => {
3968
+ }, po());
3969
+ }, [Pe, Jt]), Fr = Ce(async () => {
3929
3970
  const _ = Math.floor(Date.now() / 1e3);
3930
3971
  if (De.current && _ < De.current.expiresAt - 60)
3931
3972
  return De.current.key;
3932
3973
  const F = le.current ?? await nr();
3933
3974
  le.current = F, ne.current.setDeveloperToken(F);
3934
- const V = await Es(F, Ee);
3975
+ const V = await Ps(F, Ee);
3935
3976
  return De.current = {
3936
3977
  key: V.value,
3937
3978
  expiresAt: V.expiresAt
@@ -3940,15 +3981,15 @@ const Na = jn(function({
3940
3981
  Je(() => {
3941
3982
  i && (le.current = i, ne.current.setDeveloperToken(i));
3942
3983
  }, [i]), Je(() => {
3943
- ne.current.setTtsEngineId(a), se.current?.setTtsEngineId(a), be.current && (be.current.ttsEngineId = a);
3944
- }, [a]), Je(() => {
3945
- const _ = l ?? Tt(a);
3984
+ ne.current.setTtsEngineId(o), se.current?.setTtsEngineId(o), be.current && (be.current.ttsEngineId = o);
3985
+ }, [o]), Je(() => {
3986
+ const _ = u ?? Tt(o);
3946
3987
  be.current && (be.current.voiceId = _);
3947
- }, [l, a]);
3948
- const Qe = Or(
3949
- () => xs(r, n),
3988
+ }, [u, o]);
3989
+ const Qe = Nr(
3990
+ () => Rs(r, n),
3950
3991
  [r, n]
3951
- ), qn = Or(() => s ? JSON.stringify(s) : Qe ? `face:${Qe}` : `id:${t ?? ""}`, [s, Qe, t]);
3992
+ ), jn = Nr(() => s ? JSON.stringify(s) : Qe ? `face:${Qe}` : `id:${t ?? ""}`, [s, Qe, t]);
3952
3993
  return Je(() => {
3953
3994
  if (!t && !s && !Qe) {
3954
3995
  Le("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
@@ -3963,28 +4004,28 @@ const Na = jn(function({
3963
4004
  try {
3964
4005
  let O, K, ke, Te;
3965
4006
  if (s)
3966
- O = s, K = a, ke = l ?? Tt(K);
4007
+ O = s, K = o, ke = u ?? Tt(K);
3967
4008
  else if (Qe)
3968
- oe.current?.("loadFace"), O = Vr(Qe), K = a, ke = l ?? Tt(K);
4009
+ ae.current?.("loadFace"), O = Wr(Qe), K = o, ke = u ?? Tt(K);
3969
4010
  else {
3970
- oe.current?.("getAiTwin");
4011
+ ae.current?.("getAiTwin");
3971
4012
  const H = await cr(
3972
- _s(t),
4013
+ bs(t),
3973
4014
  3e4,
3974
4015
  "getAiTwin"
3975
4016
  );
3976
4017
  if (_) return;
3977
4018
  if (!H.faceId?.trim())
3978
4019
  throw new Error("getAiTwin returned no faceId");
3979
- K = H.ttsEngineId, ke = l ?? H.voiceId ?? Tt(K), Te = H.knowledgeContextId?.trim() || void 0, O = Vr(H.faceId);
4020
+ K = H.ttsEngineId, ke = u ?? H.voiceId ?? Tt(K), Te = H.knowledgeContextId?.trim() || void 0, O = Wr(H.faceId);
3980
4021
  }
3981
- be.current = { ttsEngineId: K, voiceId: ke, personaId: Te }, Ms(O), p.current = Ui();
4022
+ be.current = { ttsEngineId: K, voiceId: ke, personaId: Te }, Ds(O), p.current = ji();
3982
4023
  const He = !!(s && !tt(s));
3983
- V = ba(F, {
4024
+ V = Ro(F, {
3984
4025
  preferLegacyRenderer: He,
3985
4026
  pixiMaxTextureSize: L,
3986
4027
  onStatus: (H) => {
3987
- _ || oe.current?.(H);
4028
+ _ || ae.current?.(H);
3988
4029
  },
3989
4030
  onError: (H) => {
3990
4031
  _ || Le(H);
@@ -4003,7 +4044,7 @@ const Na = jn(function({
4003
4044
  _ || ye((H) => H + 1);
4004
4045
  }));
4005
4046
  }
4006
- }), M.current = V, D.current = la(V), Ge.current = !1, ((H) => {
4047
+ }), M.current = V, D.current = So(V), Ge.current = !1, ((H) => {
4007
4048
  const Z = () => {
4008
4049
  if (!H || U.current <= 0)
4009
4050
  return !1;
@@ -4011,13 +4052,13 @@ const Na = jn(function({
4011
4052
  return we ? ee.current && we.supportsBufferedPlayback ? !0 : we.usesPixi : !1;
4012
4053
  };
4013
4054
  ne.current.setLipsyncWarmupHold(H, Z), se.current?.setLipsyncWarmupHold(H, Z);
4014
- })(!0), oe.current?.("auth");
4055
+ })(!0), ae.current?.("auth");
4015
4056
  const ze = le.current ?? i ?? await cr(nr(), 3e4, "getAuthToken");
4016
4057
  if (_) return;
4017
4058
  le.current = ze, ne.current.setDeveloperToken(ze), ne.current.setTtsEngineId(K);
4018
- const Dt = xt() ? await Br() : void 0;
4059
+ const Dt = xt() ? await Fr() : void 0;
4019
4060
  if (_) return;
4020
- oe.current?.("loadAssets");
4061
+ ae.current?.("loadAssets");
4021
4062
  const re = await cr(
4022
4063
  V.loadAssets(Dt),
4023
4064
  18e4,
@@ -4025,20 +4066,20 @@ const Na = jn(function({
4025
4066
  );
4026
4067
  if (!_ && re.width > 0 && re.height > 0 && (Fe.current = re, Q(re)), _) return;
4027
4068
  Ve.current = V.getVisemeAtlasPaths(), Ue.current = !0, ve(!0), St.current?.(), V.renderSilOnly().then(() => {
4028
- _ || oe.current?.("sil");
4069
+ _ || ae.current?.("sil");
4029
4070
  }), (async () => {
4030
4071
  try {
4031
- const H = await wi(Dt);
4072
+ const H = await Ei(Dt);
4032
4073
  if (await p.current.load(H), _) return;
4033
4074
  S.current = !0, m(!0), Re(X.current), p.current.setActive(!0);
4034
4075
  const Z = p.current.getVideo();
4035
- V.usesPixi ? V.drawIdleVideo(Z) : await ar(
4076
+ V.usesPixi ? V.drawIdleVideo(Z) : await or(
4036
4077
  F,
4037
4078
  Z,
4038
4079
  null,
4039
4080
  void 0,
4040
4081
  Fe.current
4041
- ), _ || oe.current?.("idle");
4082
+ ), _ || ae.current?.("idle");
4042
4083
  } catch (H) {
4043
4084
  if (_) return;
4044
4085
  S.current = !1, m(!1), console.warn("[AiTwin] Idle video unavailable:", H);
@@ -4055,7 +4096,7 @@ const Na = jn(function({
4055
4096
  })(), () => {
4056
4097
  _ = !0, p.current?.dispose(), V?.dispose(), M.current = null;
4057
4098
  };
4058
- }, [qn, s, Qe, t, a, l, i, L, Br, Le, ce]), Je(() => {
4099
+ }, [jn, s, Qe, t, o, u, i, L, Fr, Le, ce]), Je(() => {
4059
4100
  const _ = { current: !1 }, F = () => {
4060
4101
  const V = A.current, O = M.current, K = qe(
4061
4102
  ne.current,
@@ -4070,7 +4111,7 @@ const Na = jn(function({
4070
4111
  return;
4071
4112
  }
4072
4113
  const ke = K.isSpeaking(), Te = K.isWarmingUp(), He = ke && !$.current, Ke = $.current && !ke;
4073
- He && (Pe(), xe(), j.current = !1, y.current = !1, Re(X.current), D.current?.reset(), $e.current.reset(), nt.current = void 0, fe.current = 0, G.current = "sil", W.current = 0, Rt()), Ke && (z.current.reset(), p.current?.setActive(!1), D.current?.reset(), O.finishIdleToSilCrossfade(), ot());
4114
+ He && (Pe(), xe(), j.current = !1, y.current = !1, Re(X.current), D.current?.reset(), $e.current.reset(), nt.current = void 0, fe.current = 0, G.current = "sil", W.current = 0, Rt()), Ke && (z.current.reset(), p.current?.setActive(!1), D.current?.reset(), O.finishIdleToSilCrossfade(), at());
4074
4115
  const ze = Ke || j.current || E.current || N.current, Dt = R && O.supportsBufferedPlayback;
4075
4116
  if (Te) {
4076
4117
  if (Rt(), S.current && p.current?.setActive(!1), O.usesPixi && O.isIdleToSilCrossfading()) {
@@ -4090,7 +4131,7 @@ const Na = jn(function({
4090
4131
  Dt && D.current ? (D.current.warmupTick(we), Me = D.current.isWarmupReady(
4091
4132
  we,
4092
4133
  U.current
4093
- )) : O.usesPixi && rn(
4134
+ )) : O.usesPixi && sn(
4094
4135
  V,
4095
4136
  re,
4096
4137
  0,
@@ -4099,16 +4140,16 @@ const Na = jn(function({
4099
4140
  X.current,
4100
4141
  (ct, Bt, Zt, Ft) => {
4101
4142
  O.drawLiveFrame(ct, Bt, Zt, (Oe) => {
4102
- Ft?.(Oe), K.isWarmingUp() && Oe !== "" && !tn({ lastDrawnKey: Oe }) && (te.current = 0, K.releaseWarmupHold());
4143
+ Ft?.(Oe), K.isWarmingUp() && Oe !== "" && !nn({ lastDrawnKey: Oe }) && (te.current = 0, K.releaseWarmupHold());
4103
4144
  });
4104
4145
  },
4105
4146
  (ct) => {
4106
- oe.current?.(ct.label);
4147
+ ae.current?.(ct.label);
4107
4148
  },
4108
4149
  Ve.current
4109
4150
  );
4110
- const je = te.current > 0 && performance.now() - te.current > ms;
4111
- oe.current?.(
4151
+ const je = te.current > 0 && performance.now() - te.current > ws;
4152
+ ae.current?.(
4112
4153
  Me ? "buffer ready" : "buffering lipsync…"
4113
4154
  ), (Me || je) && (te.current = 0, K.releaseWarmupHold()), $.current = K.isSpeaking(), ie.current = requestAnimationFrame(F);
4114
4155
  return;
@@ -4116,36 +4157,36 @@ const Na = jn(function({
4116
4157
  if (ke) {
4117
4158
  Rt(), S.current && p.current?.setActive(!1), O.usesPixi && O.isIdleToSilCrossfading() && O.finishIdleToSilCrossfade();
4118
4159
  const re = K.getVisemeQueue(), H = K.getPlaybackElapsedMs();
4119
- ei(re, H), W.current = H;
4160
+ ui(re, H), W.current = H;
4120
4161
  const Z = re.length > 0 ? jt(re, H) : "sil";
4121
4162
  Z !== "sil" && (G.current = Z);
4122
- const we = Hi(
4163
+ const we = Ji(
4123
4164
  H,
4124
4165
  K.getSentenceEmotions(),
4125
4166
  K.getWordQueue(),
4126
4167
  K.getStreamMood()
4127
4168
  );
4128
4169
  z.current.setTargetEmotion(we), z.current.setTargetEyebrow(
4129
- Oi(
4170
+ Gi(
4130
4171
  H,
4131
4172
  K.getWordQueue(),
4132
4173
  ht(we)
4133
4174
  )
4134
4175
  ), z.current.advance(performance.now());
4135
4176
  const Me = z.current.getExpressionPath(), je = z.current.getDrawKey(), ct = (Oe, er, bt, tr) => {
4136
- const Fr = {
4177
+ const Lr = {
4137
4178
  label: Mt.current,
4138
4179
  elapsedMs: H,
4139
4180
  mouthPath: er.mouthPath,
4140
4181
  transitionMeta: nt.current
4141
4182
  };
4142
- We.current.set(bt, Fr), D.current?.markExternallyDisplayed(
4183
+ We.current.set(bt, Lr), D.current?.markExternallyDisplayed(
4143
4184
  bt,
4144
4185
  Me
4145
4186
  ), O.drawLiveFrame(Oe, er, bt, (Lt) => {
4146
- const Gn = We.current.get(Lt) ?? Fr;
4187
+ const Yn = We.current.get(Lt) ?? Lr;
4147
4188
  We.current.delete(Lt), $e.current.onDrawDisplayed(
4148
- Gn,
4189
+ Yn,
4149
4190
  re
4150
4191
  ), D.current?.markExternallyDisplayed(
4151
4192
  Lt,
@@ -4153,7 +4194,7 @@ const Na = jn(function({
4153
4194
  ), tr?.(Lt);
4154
4195
  });
4155
4196
  }, Bt = (Oe) => {
4156
- Mt.current = Oe.label, nt.current = Oe.transitionMeta, oe.current?.(Oe.label);
4197
+ Mt.current = Oe.label, nt.current = Oe.transitionMeta, ae.current?.(Oe.label);
4157
4198
  }, Zt = R && O.supportsBufferedPlayback;
4158
4199
  let Ft = !1;
4159
4200
  Zt && D.current && (Ft = D.current.tick({
@@ -4176,7 +4217,7 @@ const Na = jn(function({
4176
4217
  re
4177
4218
  );
4178
4219
  }
4179
- }).usedBuffer), Ft || rn(
4220
+ }).usedBuffer), Ft || sn(
4180
4221
  V,
4181
4222
  re,
4182
4223
  H,
@@ -4192,7 +4233,7 @@ const Na = jn(function({
4192
4233
  } else if (!ze && de.current) {
4193
4234
  p.current?.setActive(!1), z.current.advance(performance.now());
4194
4235
  const re = z.current.getExpressionPath(), H = z.current.getDrawKey();
4195
- or(
4236
+ ar(
4196
4237
  V,
4197
4238
  re,
4198
4239
  H,
@@ -4200,7 +4241,7 @@ const Na = jn(function({
4200
4241
  (Z, we, Me, je) => O.drawLiveFrame(Z, we, Me, je),
4201
4242
  (Z) => {
4202
4243
  const we = z.current.getTargetEmotion();
4203
- oe.current?.(
4244
+ ae.current?.(
4204
4245
  Z === "sil" || Z === "blink" ? `${we}${Z === "blink" ? " · blink" : ""}` : Z
4205
4246
  );
4206
4247
  }
@@ -4210,32 +4251,32 @@ const Na = jn(function({
4210
4251
  if (H.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
4211
4252
  re.setActive(!0);
4212
4253
  const Z = () => !K.isSpeaking() && !j.current && !E.current && !de.current;
4213
- O.usesPixi ? (O.drawIdleVideo(H, Z), Z() && oe.current?.("idle")) : _.current || (_.current = !0, ar(
4254
+ O.usesPixi ? (O.drawIdleVideo(H, Z), Z() && ae.current?.("idle")) : _.current || (_.current = !0, or(
4214
4255
  V,
4215
4256
  H,
4216
4257
  null,
4217
4258
  void 0,
4218
4259
  Fe.current,
4219
4260
  Z
4220
- ).then(() => oe.current?.("idle")).finally(() => {
4261
+ ).then(() => ae.current?.("idle")).finally(() => {
4221
4262
  _.current = !1;
4222
4263
  }));
4223
4264
  } else
4224
- or(
4265
+ ar(
4225
4266
  V,
4226
4267
  null,
4227
4268
  "__sil__",
4228
4269
  X.current,
4229
4270
  (Z, we, Me, je) => O.drawLiveFrame(Z, we, Me, je),
4230
- (Z) => oe.current?.(Z)
4271
+ (Z) => ae.current?.(Z)
4231
4272
  );
4232
- } else ze || or(
4273
+ } else ze || ar(
4233
4274
  V,
4234
4275
  null,
4235
4276
  "__sil__",
4236
4277
  X.current,
4237
4278
  (re, H, Z, we) => O.drawLiveFrame(re, H, Z, we),
4238
- (re) => oe.current?.(re)
4279
+ (re) => ae.current?.(re)
4239
4280
  );
4240
4281
  $.current = ke, ie.current = requestAnimationFrame(F);
4241
4282
  };
@@ -4245,11 +4286,11 @@ const Na = jn(function({
4245
4286
  }, [
4246
4287
  ge,
4247
4288
  _t,
4248
- ot,
4289
+ at,
4249
4290
  Pe,
4250
4291
  xe,
4251
4292
  Rt
4252
- ]), Yn(
4293
+ ]), Jn(
4253
4294
  T,
4254
4295
  () => ({
4255
4296
  speakText: async (_, F) => {
@@ -4267,11 +4308,11 @@ const Na = jn(function({
4267
4308
  ttsEngineId: K
4268
4309
  });
4269
4310
  } catch (Te) {
4270
- throw N.current = !1, O.finishIdleToSilCrossfade(), ot(), Le(Te instanceof Error ? Te.message : "TTS failed"), Te;
4311
+ throw N.current = !1, O.finishIdleToSilCrossfade(), at(), Le(Te instanceof Error ? Te.message : "TTS failed"), Te;
4271
4312
  }
4272
4313
  },
4273
4314
  stop: () => {
4274
- J.current += 1, Pe(), xe(), j.current = !1, y.current = !1, N.current = !1, M.current?.finishIdleToSilCrossfade(), ne.current.stop(), se.current?.stop(), Re(X.current), D.current?.reset(), te.current = 0, $.current = !1, ot();
4315
+ J.current += 1, Pe(), xe(), j.current = !1, y.current = !1, N.current = !1, M.current?.finishIdleToSilCrossfade(), ne.current.stop(), se.current?.stop(), Re(X.current), D.current?.reset(), te.current = 0, $.current = !1, at();
4275
4316
  },
4276
4317
  setTtsEngineId: (_) => {
4277
4318
  ne.current.setTtsEngineId(_), se.current?.setTtsEngineId(_), be.current && (be.current.ttsEngineId = _);
@@ -4284,7 +4325,7 @@ const Na = jn(function({
4284
4325
  from: F?.from,
4285
4326
  transitionDurationMs: F?.transitionDurationMs,
4286
4327
  gapMs: F?.gapMs,
4287
- onStatus: (K) => oe.current?.(K)
4328
+ onStatus: (K) => ae.current?.(K)
4288
4329
  });
4289
4330
  },
4290
4331
  setEmotion: (_) => {
@@ -4301,13 +4342,13 @@ const Na = jn(function({
4301
4342
  ze === He && (X.current.lastDrawnKey = He);
4302
4343
  });
4303
4344
  const Ke = ht(O);
4304
- oe.current?.(
4345
+ ae.current?.(
4305
4346
  K ? `${O} · brow ${Ke > 0 ? "+" : ""}${Ke}` : `${O} · brow 0 (sil base)`
4306
4347
  );
4307
4348
  },
4308
4349
  getEmotion: () => de.current ? z.current.getTargetEmotion() : null,
4309
4350
  clearEmotionPreview: () => {
4310
- de.current = !1, z.current.reset(), Re(X.current), oe.current?.("idle");
4351
+ de.current = !1, z.current.reset(), Re(X.current), ae.current?.("idle");
4311
4352
  },
4312
4353
  isReady: () => Ue.current,
4313
4354
  getStatus: () => C,
@@ -4316,7 +4357,7 @@ const Na = jn(function({
4316
4357
  try {
4317
4358
  let F = _.authToken?.trim();
4318
4359
  F || (F = le.current ?? i ?? await nr(), le.current = F);
4319
- const V = _.voiceId?.trim() ?? l ?? be.current?.voiceId, O = _.personaId?.trim() ?? be.current?.personaId, K = Rr();
4360
+ const V = _.voiceId?.trim() ?? u ?? be.current?.voiceId, O = _.personaId?.trim() ?? be.current?.personaId, K = Dr();
4320
4361
  await K.unlockAudio(), await K.connect({
4321
4362
  ..._,
4322
4363
  apiBase: _.apiBase?.trim() || Ee,
@@ -4333,7 +4374,7 @@ const Na = jn(function({
4333
4374
  },
4334
4375
  disconnect: async () => {
4335
4376
  const _ = se.current;
4336
- _ && (J.current += 1, Pe(), xe(), j.current = !1, y.current = !1, N.current = !1, M.current?.finishIdleToSilCrossfade(), Re(X.current), D.current?.reset(), te.current = 0, $.current = !1, await _.disconnect(), ot());
4377
+ _ && (J.current += 1, Pe(), xe(), j.current = !1, y.current = !1, N.current = !1, M.current?.finishIdleToSilCrossfade(), Re(X.current), D.current?.reset(), te.current = 0, $.current = !1, await _.disconnect(), at());
4337
4378
  },
4338
4379
  isConnected: () => se.current?.isConnected() ?? !1,
4339
4380
  getVoiceStream: () => se.current?.getVoiceStream() ?? ne.current?.getVoiceStream() ?? null
@@ -4342,80 +4383,89 @@ const Na = jn(function({
4342
4383
  ge,
4343
4384
  f,
4344
4385
  i,
4345
- l,
4386
+ u,
4346
4387
  Pe,
4347
4388
  xe,
4348
- ot,
4389
+ at,
4349
4390
  Le,
4350
4391
  Ct,
4351
- Rr,
4392
+ Dr,
4352
4393
  C,
4353
4394
  Ee
4354
4395
  ]
4355
- ), /* @__PURE__ */ zn("div", { className: u, style: { ...Ta, ...c }, children: [
4356
- /* @__PURE__ */ Lr(
4396
+ ), /* @__PURE__ */ Xn("div", { className: l, style: { ...Bo, ...c }, children: [
4397
+ /* @__PURE__ */ Or(
4357
4398
  "canvas",
4358
4399
  {
4359
4400
  ref: A,
4360
4401
  width: P.width,
4361
4402
  height: P.height,
4362
- style: { ...Ea, ...d },
4403
+ style: { ...Fo, ...d },
4363
4404
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
4364
4405
  }
4365
4406
  ),
4366
- v && ae ? /* @__PURE__ */ Lr("div", { style: Ia, children: ae }) : null
4407
+ v && oe ? /* @__PURE__ */ Or("div", { style: Lo, children: oe }) : null
4367
4408
  ] });
4368
- }), Aa = "thumbnail.webp";
4369
- function Ua(e, t = wr) {
4409
+ }), Oo = "thumbnail.webp";
4410
+ function Xo(e, t = wr) {
4370
4411
  const r = e.trim();
4371
4412
  if (!r)
4372
4413
  throw new Error("faceId is required");
4373
- return `${t.replace(/\/$/, "")}/${r}/${Aa}`;
4414
+ return `${t.replace(/\/$/, "")}/${r}/${Oo}`;
4374
4415
  }
4375
- const Pa = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
4376
- function xa(e = ".png") {
4416
+ const No = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
4417
+ function Uo(e = ".png") {
4377
4418
  const t = e.toLowerCase();
4378
- return Pa.has(t) ? `source${t}` : "source.png";
4419
+ return No.has(t) ? `source${t}` : "source.png";
4379
4420
  }
4380
- function Va(e, t = wr, r = ".png") {
4421
+ function Qo(e, t = wr, r = ".png") {
4381
4422
  const n = e.trim();
4382
4423
  if (!n)
4383
4424
  throw new Error("faceId is required");
4384
- return `${t.replace(/\/$/, "")}/${n}/${xa(r)}`;
4425
+ return `${t.replace(/\/$/, "")}/${n}/${Uo(r)}`;
4385
4426
  }
4386
4427
  export {
4387
- Aa as AI_TWIN_THUMBNAIL_FILENAME,
4388
- Na as AiTwin,
4428
+ Oo as AI_TWIN_THUMBNAIL_FILENAME,
4429
+ Yo as AiTwin,
4389
4430
  ur as AiTwinNotFoundError,
4431
+ js as CONSONANT_SKIP_GROUP,
4390
4432
  ft as DEFAULT_TTS_ENGINE_ID,
4391
- Ai as EMOTION_TO_EYEBROW,
4392
- Oa as EXPRESSION_ATLAS_EMOTIONS,
4393
- Pn as MIC_SAMPLE_RATE,
4394
- Ds as OCULUS_VISEME_IDS,
4395
- xn as PLAYBACK_SAMPLE_RATE,
4396
- br as SPEAKING_RATE_MAX,
4397
- vr as SPEAKING_RATE_MIN,
4433
+ Li as EMOTION_TO_EYEBROW,
4434
+ jo as EXPRESSION_ATLAS_EMOTIONS,
4435
+ Cn as MIC_SAMPLE_RATE,
4436
+ Ls as OCULUS_VISEME_IDS,
4437
+ Rn as PLAYBACK_SAMPLE_RATE,
4438
+ kr as SPEAKING_RATE_MAX,
4439
+ br as SPEAKING_RATE_MIN,
4398
4440
  gt as TTS_ENGINE_CARTESIA,
4399
- fn as TTS_ENGINE_GOOGLE,
4441
+ mn as TTS_ENGINE_GOOGLE,
4400
4442
  yr as TTS_ENGINE_INWORLD,
4401
- La as VISEME_IDS,
4402
- An as VISEME_TEST_CARTESIA_VOICE_ID,
4443
+ zo as VISEME_IDS,
4444
+ $r as VISEME_SKIP_GAP_MS,
4445
+ Mn as VISEME_TEST_CARTESIA_VOICE_ID,
4403
4446
  Yt as VISEME_TEST_SPEAKING_RATE,
4404
- In as VISEME_TEST_VOICE_ID,
4405
- xa as aiTwinSourceFilename,
4406
- oi as buildVoiceWebSocketUrl,
4407
- Kr as createAvatarTtsLipsyncController,
4408
- li as createRealtimeVoiceLipsyncController,
4447
+ xn as VISEME_TEST_VOICE_ID,
4448
+ zs as VOWEL_SKIP_GROUP,
4449
+ Uo as aiTwinSourceFilename,
4450
+ ni as buildPlaybackTransitions,
4451
+ Sr as buildPlaybackVisemeSeries,
4452
+ ri as buildRawVisemeTransitions,
4453
+ wi as buildVoiceWebSocketUrl,
4454
+ bn as compactSkippableVisemes,
4455
+ Gr as createAvatarTtsLipsyncController,
4456
+ _i as createRealtimeVoiceLipsyncController,
4409
4457
  ht as emotionToEyebrow,
4410
- Vr as faceAssetUrls,
4411
- _s as fetchAiTwin,
4458
+ Wr as faceAssetUrls,
4459
+ bs as fetchAiTwin,
4412
4460
  nr as fetchDevAuthToken,
4413
- Va as getAiTwinSourceUrl,
4414
- Ua as getAiTwinThumbnailUrl,
4415
- Fs as normalizeOculusViseme,
4461
+ Qo as getAiTwinSourceUrl,
4462
+ Xo as getAiTwinThumbnailUrl,
4463
+ qo as listSkippedVisemes,
4464
+ Ns as normalizeOculusViseme,
4416
4465
  Ye as normalizeStreamEmotion,
4417
- xs as resolveDirectFaceId,
4466
+ Rs as resolveDirectFaceId,
4418
4467
  jt as resolveVisemeAtTime,
4419
- Fa as resolveWordAtTime,
4420
- Ms as setActiveTwinAssets
4468
+ Js as resolveVisemeFromPlaybackSeries,
4469
+ Go as resolveWordAtTime,
4470
+ Ds as setActiveTwinAssets
4421
4471
  };