@sage-rsc/talking-head-react 1.9.1 → 1.9.2

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs as Be, jsx as le } from "react/jsx-runtime";
2
- import { forwardRef as $e, useRef as V, useState as pe, useEffect as ke, useCallback as W, useImperativeHandle as Je, useLayoutEffect as xt } from "react";
2
+ import { forwardRef as Je, useRef as V, useState as pe, useEffect as ke, useCallback as W, useImperativeHandle as et, useLayoutEffect as xt } from "react";
3
3
  import * as A from "three";
4
4
  import { OrbitControls as bt } from "three/addons/controls/OrbitControls.js";
5
5
  import { GLTFLoader as At } from "three/addons/loaders/GLTFLoader.js";
@@ -8,13 +8,13 @@ import { FBXLoader as st } from "three/addons/loaders/FBXLoader.js";
8
8
  import { RoomEnvironment as vt } from "three/addons/environments/RoomEnvironment.js";
9
9
  import It from "three/addons/libs/stats.module.js";
10
10
  let m, we, He;
11
- const T = [0, 0, 0, 0], U = new A.Vector3(), Ye = new A.Vector3(), Re = new A.Vector3(), qe = new A.Vector3();
11
+ const T = [0, 0, 0, 0], U = new A.Vector3(), qe = new A.Vector3(), Re = new A.Vector3(), _e = new A.Vector3();
12
12
  new A.Plane();
13
13
  new A.Ray();
14
14
  new A.Euler();
15
15
  const ve = new A.Quaternion(), rt = new A.Quaternion(), Oe = new A.Matrix4(), De = new A.Matrix4();
16
16
  new A.Vector3();
17
- const _e = new A.Vector3(0, 0, 1), Lt = new A.Vector3(1, 0, 0), St = new A.Vector3(0, 1, 0), kt = new A.Vector3(0, 0, 1);
17
+ const Ke = new A.Vector3(0, 0, 1), Lt = new A.Vector3(1, 0, 0), St = new A.Vector3(0, 1, 0), kt = new A.Vector3(0, 0, 1);
18
18
  class wt {
19
19
  constructor(n = null) {
20
20
  this.opt = Object.assign({
@@ -338,7 +338,7 @@ class wt {
338
338
  ea: [0, 0, 0, 0]
339
339
  // External acceleration [m/s^2]
340
340
  };
341
- c.boneParent.matrixWorld.decompose(U, ve, Re), U.copy(_e).applyQuaternion(ve).setY(0).normalize(), ve.premultiply(rt.setFromUnitVectors(_e, U).invert()).normalize(), c.qWorldInverseYaw = ve.clone().normalize(), this.data.push(c), this.dict[u] = c;
341
+ c.boneParent.matrixWorld.decompose(U, ve, Re), U.copy(Ke).applyQuaternion(ve).setY(0).normalize(), ve.premultiply(rt.setFromUnitVectors(Ke, U).invert()).normalize(), c.qWorldInverseYaw = ve.clone().normalize(), this.data.push(c), this.dict[u] = c;
342
342
  try {
343
343
  this.setValue(u, "type", s.type), this.setValue(u, "stiffness", s.stiffness), this.setValue(u, "damping", s.damping), this.setValue(u, "external", s.external), this.setValue(u, "limits", s.limits), this.setValue(u, "excludes", s.excludes), this.setValue(u, "deltaLocal", s.deltaLocal), this.setValue(u, "deltaWorld", s.deltaWorld), this.setValue(u, "pivot", s.pivot), this.setValue(u, "helper", s.helper);
344
344
  } catch (r) {
@@ -369,9 +369,9 @@ class wt {
369
369
  i.vBasis.y + T[1],
370
370
  i.vBasis.z - T[2]
371
371
  );
372
- else if (i.boneParent.quaternion.copy(i.qBasis), i.pivot && this.opt.isPivots && (i.boneParent.updateWorldMatrix(!1, !1), i.boneParent.matrixWorld.decompose(U, ve, Re), U.copy(_e).applyQuaternion(ve).setY(0).normalize(), ve.premultiply(rt.setFromUnitVectors(_e, U).invert()).normalize(), i.boneParent.quaternion.multiply(ve.invert()), i.boneParent.quaternion.multiply(i.qWorldInverseYaw)), i.isZ && (m = Math.atan(T[0] / i.l), ve.setFromAxisAngle(kt, -m), i.boneParent.quaternion.multiply(ve)), i.isY && (m = i.l / 3, m = m * Math.tanh(T[1] / m), i.bone.position.setLength(i.l + m)), i.isX && (m = Math.atan(T[2] / i.l), ve.setFromAxisAngle(Lt, -m), i.boneParent.quaternion.multiply(ve)), i.isT && (m = 1.5 * Math.tanh(T[3] * 1.5), ve.setFromAxisAngle(St, -m), i.boneParent.quaternion.multiply(ve)), i.boneParent.updateWorldMatrix(!1, !0), i.excludes && this.opt.isExcludes)
372
+ else if (i.boneParent.quaternion.copy(i.qBasis), i.pivot && this.opt.isPivots && (i.boneParent.updateWorldMatrix(!1, !1), i.boneParent.matrixWorld.decompose(U, ve, Re), U.copy(Ke).applyQuaternion(ve).setY(0).normalize(), ve.premultiply(rt.setFromUnitVectors(Ke, U).invert()).normalize(), i.boneParent.quaternion.multiply(ve.invert()), i.boneParent.quaternion.multiply(i.qWorldInverseYaw)), i.isZ && (m = Math.atan(T[0] / i.l), ve.setFromAxisAngle(kt, -m), i.boneParent.quaternion.multiply(ve)), i.isY && (m = i.l / 3, m = m * Math.tanh(T[1] / m), i.bone.position.setLength(i.l + m)), i.isX && (m = Math.atan(T[2] / i.l), ve.setFromAxisAngle(Lt, -m), i.boneParent.quaternion.multiply(ve)), i.isT && (m = 1.5 * Math.tanh(T[3] * 1.5), ve.setFromAxisAngle(St, -m), i.boneParent.quaternion.multiply(ve)), i.boneParent.updateWorldMatrix(!1, !0), i.excludes && this.opt.isExcludes)
373
373
  for (t = 0, s = i.excludes.length; t < s; t++)
374
- m = i.excludes[t], Re.set(0, 0, 0), m.deltaLocal && (Re.x += m.deltaLocal[0], Re.y += m.deltaLocal[1], Re.z += m.deltaLocal[2]), Re.applyMatrix4(m.bone.matrixWorld), De.copy(i.boneParent.matrixWorld).invert(), Re.applyMatrix4(De), U.copy(i.bone.position), !(U.distanceToSquared(Re) >= m.radiusSq) && (He = U.length(), we = Re.length(), !(we > m.radius + He) && (we < Math.abs(m.radius - He) || (we = (we * we + He * He - m.radiusSq) / (2 * we), Re.normalize(), qe.copy(Re).multiplyScalar(we), we = Math.sqrt(He * He - we * we), U.subVectors(U, qe).projectOnPlane(Re).normalize().multiplyScalar(we), Ye.subVectors(i.vBasis, qe).projectOnPlane(Re).normalize(), He = Ye.dot(U), He < 0 && (He = Math.sqrt(we * we - He * He), Ye.multiplyScalar(He), U.add(Ye)), U.add(qe).normalize(), Re.copy(i.bone.position).normalize(), ve.setFromUnitVectors(Re, U), i.boneParent.quaternion.premultiply(ve), i.boneParent.updateWorldMatrix(!1, !0))));
374
+ m = i.excludes[t], Re.set(0, 0, 0), m.deltaLocal && (Re.x += m.deltaLocal[0], Re.y += m.deltaLocal[1], Re.z += m.deltaLocal[2]), Re.applyMatrix4(m.bone.matrixWorld), De.copy(i.boneParent.matrixWorld).invert(), Re.applyMatrix4(De), U.copy(i.bone.position), !(U.distanceToSquared(Re) >= m.radiusSq) && (He = U.length(), we = Re.length(), !(we > m.radius + He) && (we < Math.abs(m.radius - He) || (we = (we * we + He * He - m.radiusSq) / (2 * we), Re.normalize(), _e.copy(Re).multiplyScalar(we), we = Math.sqrt(He * He - we * we), U.subVectors(U, _e).projectOnPlane(Re).normalize().multiplyScalar(we), qe.subVectors(i.vBasis, _e).projectOnPlane(Re).normalize(), He = qe.dot(U), He < 0 && (He = Math.sqrt(we * we - He * He), qe.multiplyScalar(He), U.add(qe)), U.add(_e).normalize(), Re.copy(i.bone.position).normalize(), ve.setFromUnitVectors(Re, U), i.boneParent.quaternion.premultiply(ve), i.boneParent.updateWorldMatrix(!1, !0))));
375
375
  }
376
376
  this.helpers.isActive && this.updateHelpers();
377
377
  }
@@ -5296,13 +5296,13 @@ class ot {
5296
5296
  const y = this.lipsyncWordsToVisemes(r, l);
5297
5297
  if (y && y.visemes && y.visemes.length) {
5298
5298
  const E = y.times[y.visemes.length - 1] + y.durations[y.visemes.length - 1];
5299
- for (let S = 0; S < y.visemes.length; S++)
5299
+ for (let k = 0; k < y.visemes.length; k++)
5300
5300
  p.push({
5301
5301
  mark: h,
5302
5302
  template: { name: "viseme" },
5303
- ts: [(y.times[S] - 0.6) / E, (y.times[S] + 0.5) / E, (y.times[S] + y.durations[S] + 0.5) / E],
5303
+ ts: [(y.times[k] - 0.6) / E, (y.times[k] + 0.5) / E, (y.times[k] + y.durations[k] + 0.5) / E],
5304
5304
  vs: {
5305
- ["viseme_" + y.visemes[S]]: [null, y.visemes[S] === "PP" || y.visemes[S] === "FF" ? 0.9 : 0.6, 0]
5305
+ ["viseme_" + y.visemes[k]]: [null, y.visemes[k] === "PP" || y.visemes[k] === "FF" ? 0.9 : 0.6, 0]
5306
5306
  }
5307
5307
  });
5308
5308
  }
@@ -5558,10 +5558,10 @@ class ot {
5558
5558
  if (f && f.visemes && f.visemes.length > 0) {
5559
5559
  const g = f.times[f.visemes.length - 1] + f.durations[f.visemes.length - 1];
5560
5560
  for (let H = 0; H < f.visemes.length; H++) {
5561
- const M = f.visemes[H], y = f.times[H] / g, E = f.durations[H] / g, S = y * h, C = E * h;
5561
+ const M = f.visemes[H], y = f.times[H] / g, E = f.durations[H] / g, k = y * h, C = E * h;
5562
5562
  L.push({
5563
5563
  template: { name: "viseme" },
5564
- ts: [S - Math.min(60, 2 * C / 3), S + Math.min(25, C / 2), S + C + Math.min(60, C / 2)],
5564
+ ts: [k - Math.min(60, 2 * C / 3), k + Math.min(25, C / 2), k + C + Math.min(60, C / 2)],
5565
5565
  vs: {
5566
5566
  ["viseme_" + M]: [null, M === "PP" || M === "FF" ? 0.9 : 0.6, 0]
5567
5567
  }
@@ -6553,28 +6553,28 @@ class ot {
6553
6553
  let E = y.replace(/^mixamorig/i, "").replace(/^CC_Base_/i, "").replace(/^RPM_/i, "");
6554
6554
  if (p.has(E))
6555
6555
  return E;
6556
- const S = E.toLowerCase();
6557
- if (S.includes("left") && S.includes("arm")) {
6558
- if (S.includes("fore") || S.includes("lower")) {
6556
+ const k = E.toLowerCase();
6557
+ if (k.includes("left") && k.includes("arm")) {
6558
+ if (k.includes("fore") || k.includes("lower")) {
6559
6559
  if (p.has("LeftForeArm")) return "LeftForeArm";
6560
6560
  if (p.has("LeftForearm")) return "LeftForearm";
6561
- } else if (!S.includes("fore") && !S.includes("hand") && p.has("LeftArm"))
6561
+ } else if (!k.includes("fore") && !k.includes("hand") && p.has("LeftArm"))
6562
6562
  return "LeftArm";
6563
6563
  }
6564
- if (S.includes("right") && S.includes("arm")) {
6565
- if (S.includes("fore") || S.includes("lower")) {
6564
+ if (k.includes("right") && k.includes("arm")) {
6565
+ if (k.includes("fore") || k.includes("lower")) {
6566
6566
  if (p.has("RightForeArm")) return "RightForeArm";
6567
6567
  if (p.has("RightForearm")) return "RightForearm";
6568
- } else if (!S.includes("fore") && !S.includes("hand") && p.has("RightArm"))
6568
+ } else if (!k.includes("fore") && !k.includes("hand") && p.has("RightArm"))
6569
6569
  return "RightArm";
6570
6570
  }
6571
- if (S.includes("left") && S.includes("hand") && !S.includes("index") && !S.includes("thumb") && !S.includes("middle") && !S.includes("ring") && !S.includes("pinky") && p.has("LeftHand"))
6571
+ if (k.includes("left") && k.includes("hand") && !k.includes("index") && !k.includes("thumb") && !k.includes("middle") && !k.includes("ring") && !k.includes("pinky") && p.has("LeftHand"))
6572
6572
  return "LeftHand";
6573
- if (S.includes("right") && S.includes("hand") && !S.includes("index") && !S.includes("thumb") && !S.includes("middle") && !S.includes("ring") && !S.includes("pinky") && p.has("RightHand"))
6573
+ if (k.includes("right") && k.includes("hand") && !k.includes("index") && !k.includes("thumb") && !k.includes("middle") && !k.includes("ring") && !k.includes("pinky") && p.has("RightHand"))
6574
6574
  return "RightHand";
6575
- if (S.includes("left") && (S.includes("shoulder") || S.includes("clavicle")) && p.has("LeftShoulder"))
6575
+ if (k.includes("left") && (k.includes("shoulder") || k.includes("clavicle")) && p.has("LeftShoulder"))
6576
6576
  return "LeftShoulder";
6577
- if (S.includes("right") && (S.includes("shoulder") || S.includes("clavicle")) && p.has("RightShoulder"))
6577
+ if (k.includes("right") && (k.includes("shoulder") || k.includes("clavicle")) && p.has("RightShoulder"))
6578
6578
  return "RightShoulder";
6579
6579
  const C = {
6580
6580
  // Arm bones - exact matches
@@ -6622,11 +6622,11 @@ class ot {
6622
6622
  return x;
6623
6623
  }
6624
6624
  for (const x of p)
6625
- if (x.toLowerCase() === S)
6625
+ if (x.toLowerCase() === k)
6626
6626
  return x;
6627
6627
  for (const x of p) {
6628
6628
  const I = x.toLowerCase();
6629
- if ((S.includes("left") && I.includes("left") || S.includes("right") && I.includes("right")) && (S.includes("arm") && I.includes("arm") && !I.includes("fore") || S.includes("forearm") && I.includes("forearm") || S.includes("hand") && I.includes("hand") && !I.includes("index") && !I.includes("thumb") || S.includes("shoulder") && I.includes("shoulder")))
6629
+ if ((k.includes("left") && I.includes("left") || k.includes("right") && I.includes("right")) && (k.includes("arm") && I.includes("arm") && !I.includes("fore") || k.includes("forearm") && I.includes("forearm") || k.includes("hand") && I.includes("hand") && !I.includes("index") && !I.includes("thumb") || k.includes("shoulder") && I.includes("shoulder")))
6630
6630
  return x;
6631
6631
  }
6632
6632
  return null;
@@ -6641,7 +6641,7 @@ class ot {
6641
6641
  );
6642
6642
  const Q = [], g = /* @__PURE__ */ new Set();
6643
6643
  d.tracks.forEach((y) => {
6644
- const S = y.name.replaceAll("mixamorig", "").split("."), C = S[0], x = S[1], I = f(C);
6644
+ const k = y.name.replaceAll("mixamorig", "").split("."), C = k[0], x = k[1], I = f(C);
6645
6645
  if (!(I && (I === "LeftShoulder" || I === "RightShoulder") && (x === "quaternion" || x === "rotation")))
6646
6646
  if (I && x) {
6647
6647
  const G = `${I}.${x}`, P = y.clone();
@@ -6654,8 +6654,8 @@ class ot {
6654
6654
  y.name = y.name.replaceAll("mixamorig", "");
6655
6655
  const E = y.name.split(".");
6656
6656
  if (E[1] === "position") {
6657
- for (let S = 0; S < y.values.length; S++)
6658
- y.values[S] = y.values[S] * s;
6657
+ for (let k = 0; k < y.values.length; k++)
6658
+ y.values[k] = y.values[k] * s;
6659
6659
  H[y.name] = new A.Vector3(y.values[0], y.values[1], y.values[2]);
6660
6660
  } else E[1] === "quaternion" ? H[y.name] = new A.Quaternion(y.values[0], y.values[1], y.values[2], y.values[3]) : E[1] === "rotation" && (H[E[0] + ".quaternion"] = new A.Quaternion().setFromEuler(new A.Euler(y.values[0], y.values[1], y.values[2], "XYZ")).normalize());
6661
6661
  });
@@ -6846,7 +6846,7 @@ const Xe = {
6846
6846
  josh: "VR6AewLTigWG4xSOukaG"
6847
6847
  // Male, American
6848
6848
  }
6849
- }, Ke = {
6849
+ }, $e = {
6850
6850
  defaultVoice: "aura-2-thalia-en",
6851
6851
  // Thalia (Female, English)
6852
6852
  voices: {
@@ -6866,7 +6866,7 @@ const Xe = {
6866
6866
  // Male, English - Powerful
6867
6867
  }
6868
6868
  };
6869
- function et() {
6869
+ function tt() {
6870
6870
  return {
6871
6871
  service: "elevenlabs",
6872
6872
  endpoint: Xe.endpoint,
@@ -6876,7 +6876,7 @@ function et() {
6876
6876
  };
6877
6877
  }
6878
6878
  function Jt() {
6879
- const Y = et(), n = [];
6879
+ const Y = tt(), n = [];
6880
6880
  return Object.entries(Y.voices).forEach(([e, t]) => {
6881
6881
  n.push({
6882
6882
  value: t,
@@ -6884,7 +6884,7 @@ function Jt() {
6884
6884
  });
6885
6885
  }), n;
6886
6886
  }
6887
- const ut = $e(({
6887
+ const ut = Je(({
6888
6888
  avatarUrl: Y = "/avatars/brunette.glb",
6889
6889
  avatarBody: n = "F",
6890
6890
  mood: e = "neutral",
@@ -6906,13 +6906,13 @@ const ut = $e(({
6906
6906
  style: b = {},
6907
6907
  animations: f = {}
6908
6908
  }, L) => {
6909
- const Q = V(null), g = V(null), H = V(l), M = V(null), y = V(null), E = V(!1), S = V({ remainingText: null, originalText: null, options: null }), C = V([]), x = V(0), [I, G] = pe(!0), [P, D] = pe(null), [$, ye] = pe(!1), [fe, Te] = pe(!1);
6909
+ const Q = V(null), g = V(null), H = V(l), M = V(null), y = V(null), E = V(!1), k = V({ remainingText: null, originalText: null, options: null }), C = V([]), x = V(0), [I, G] = pe(!0), [P, D] = pe(null), [$, ye] = pe(!1), [fe, Te] = pe(!1);
6910
6910
  ke(() => {
6911
6911
  E.current = fe;
6912
6912
  }, [fe]), ke(() => {
6913
6913
  H.current = l;
6914
6914
  }, [l]);
6915
- const Ie = et(), Me = o || Ie.service;
6915
+ const Ie = tt(), Me = o || Ie.service;
6916
6916
  let re;
6917
6917
  Me === "browser" ? re = {
6918
6918
  service: "browser",
@@ -6929,8 +6929,8 @@ const ut = $e(({
6929
6929
  service: "deepgram",
6930
6930
  endpoint: "https://api.deepgram.com/v1/speak",
6931
6931
  apiKey: i || Ie.apiKey,
6932
- defaultVoice: s || Ie.defaultVoice || Ke.defaultVoice,
6933
- voices: Ie.voices || Ke.voices
6932
+ defaultVoice: s || Ie.defaultVoice || $e.defaultVoice,
6933
+ voices: Ie.voices || $e.voices
6934
6934
  } : re = {
6935
6935
  ...Ie,
6936
6936
  // Override API key if provided via props
@@ -7008,7 +7008,7 @@ const ut = $e(({
7008
7008
  }, []), j = W(async (w, K = {}) => {
7009
7009
  if (g.current && $)
7010
7010
  try {
7011
- y.current && (clearInterval(y.current), y.current = null), M.current = { text: w, options: K }, S.current = { remainingText: null, originalText: null, options: null };
7011
+ y.current && (clearInterval(y.current), y.current = null), M.current = { text: w, options: K }, k.current = { remainingText: null, originalText: null, options: null };
7012
7012
  const ce = /[!\.\?\n\p{Extended_Pictographic}]/ug, ae = w.split(ce).map((J) => J.trim()).filter((J) => J.length > 0);
7013
7013
  C.current = ae, x.current = 0, Te(!1), E.current = !1, await B();
7014
7014
  const Ae = {
@@ -7028,8 +7028,8 @@ const ut = $e(({
7028
7028
  Ee = !0;
7029
7029
  try {
7030
7030
  K.onSpeechEnd();
7031
- } catch (Ge) {
7032
- console.error("Error in onSpeechEnd callback (timeout):", Ge);
7031
+ } catch (Ze) {
7032
+ console.error("Error in onSpeechEnd callback (timeout):", Ze);
7033
7033
  }
7034
7034
  }
7035
7035
  return;
@@ -7040,8 +7040,8 @@ const ut = $e(({
7040
7040
  Ee = !0, me && (clearInterval(me), me = null, y.current = null);
7041
7041
  try {
7042
7042
  K.onSpeechEnd();
7043
- } catch (Qe) {
7044
- console.error("Error in onSpeechEnd callback:", Qe);
7043
+ } catch (Ye) {
7044
+ console.error("Error in onSpeechEnd callback:", Ye);
7045
7045
  }
7046
7046
  }
7047
7047
  }, 100);
@@ -7068,19 +7068,19 @@ const ut = $e(({
7068
7068
  Ee && Ee.trim() && (ce = Ee.trim());
7069
7069
  }
7070
7070
  }
7071
- M.current && (S.current = {
7071
+ M.current && (k.current = {
7072
7072
  remainingText: ce || null,
7073
7073
  originalText: M.current.text,
7074
7074
  options: M.current.options
7075
7075
  }), w.speechQueue && (w.speechQueue.length = 0), g.current.pauseSpeaking(), E.current = !0, Te(!0);
7076
7076
  }
7077
7077
  }
7078
- }, []), _ = W(async () => {
7078
+ }, []), q = W(async () => {
7079
7079
  if (!g.current || !fe)
7080
7080
  return;
7081
7081
  let w = "", K = {};
7082
- if (S.current && S.current.remainingText)
7083
- w = S.current.remainingText, K = S.current.options || {}, S.current = { remainingText: null, originalText: null, options: null };
7082
+ if (k.current && k.current.remainingText)
7083
+ w = k.current.remainingText, K = k.current.options || {}, k.current = { remainingText: null, originalText: null, options: null };
7084
7084
  else if (M.current && M.current.text)
7085
7085
  w = M.current.text, K = M.current.options || {};
7086
7086
  else {
@@ -7139,14 +7139,14 @@ const ut = $e(({
7139
7139
  }
7140
7140
  }
7141
7141
  }
7142
- }, [f]), tt = W(() => {
7142
+ }, [f]), nt = W(() => {
7143
7143
  g.current && g.current.onResize && g.current.onResize();
7144
7144
  }, []);
7145
- return Je(L, () => ({
7145
+ return et(L, () => ({
7146
7146
  speakText: j,
7147
7147
  stopSpeaking: ie,
7148
7148
  pauseSpeaking: X,
7149
- resumeSpeaking: _,
7149
+ resumeSpeaking: q,
7150
7150
  resumeAudioContext: B,
7151
7151
  setMood: Le,
7152
7152
  setTimingAdjustment: xe,
@@ -7154,7 +7154,7 @@ const ut = $e(({
7154
7154
  isReady: $,
7155
7155
  isPaused: fe,
7156
7156
  talkingHead: g.current,
7157
- handleResize: tt,
7157
+ handleResize: nt,
7158
7158
  setBodyMovement: (w) => {
7159
7159
  if (g.current && g.current.setShowFullAvatar && g.current.setBodyMovement)
7160
7160
  try {
@@ -7261,7 +7261,7 @@ const ut = $e(({
7261
7261
  );
7262
7262
  });
7263
7263
  ut.displayName = "TalkingHeadAvatar";
7264
- const Wt = $e(({
7264
+ const Wt = Je(({
7265
7265
  text: Y = "Hello! I'm a talking avatar. How are you today?",
7266
7266
  onLoading: n = () => {
7267
7267
  },
@@ -7273,7 +7273,7 @@ const Wt = $e(({
7273
7273
  style: s = {},
7274
7274
  avatarConfig: i = {}
7275
7275
  }, a) => {
7276
- const u = V(null), l = V(null), [c, r] = pe(!0), [h, d] = pe(null), [p, b] = pe(!1), f = et(), L = i.ttsService || f.service, Q = L === "browser" ? {
7276
+ const u = V(null), l = V(null), [c, r] = pe(!0), [h, d] = pe(null), [p, b] = pe(!1), f = tt(), L = i.ttsService || f.service, Q = L === "browser" ? {
7277
7277
  endpoint: "",
7278
7278
  apiKey: null,
7279
7279
  defaultVoice: "Google US English"
@@ -7355,7 +7355,7 @@ const Wt = $e(({
7355
7355
  console.warn("Avatar not ready for speaking. isReady:", p, "talkingHeadRef:", !!l.current);
7356
7356
  }, [p, g]), E = W(() => {
7357
7357
  l.current && (l.current.stopSpeaking(), l.current.setSlowdownRate && (l.current.setSlowdownRate(1), console.log("Reset timing to normal")));
7358
- }, []), S = W((I) => {
7358
+ }, []), k = W((I) => {
7359
7359
  l.current && l.current.setMood(I);
7360
7360
  }, []), C = W((I) => {
7361
7361
  l.current && l.current.setSlowdownRate && (l.current.setSlowdownRate(I), console.log("Timing adjustment set to:", I));
@@ -7400,10 +7400,10 @@ const Wt = $e(({
7400
7400
  } else
7401
7401
  console.warn("Animation system not available or animation not found:", I);
7402
7402
  }, []);
7403
- return Je(a, () => ({
7403
+ return et(a, () => ({
7404
7404
  speakText: y,
7405
7405
  stopSpeaking: E,
7406
- setMood: S,
7406
+ setMood: k,
7407
7407
  setTimingAdjustment: C,
7408
7408
  playAnimation: x,
7409
7409
  isReady: p,
@@ -7502,7 +7502,7 @@ const Wt = $e(({
7502
7502
  ] });
7503
7503
  });
7504
7504
  Wt.displayName = "TalkingHeadComponent";
7505
- async function je(Y) {
7505
+ async function Qe(Y) {
7506
7506
  try {
7507
7507
  const n = await fetch(Y);
7508
7508
  if (!n.ok) {
@@ -7574,7 +7574,7 @@ async function ct(Y, n = "F") {
7574
7574
  }
7575
7575
  return e;
7576
7576
  }
7577
- const Xt = $e(({
7577
+ const Xt = Je(({
7578
7578
  text: Y = null,
7579
7579
  avatarUrl: n = "/avatars/brunette.glb",
7580
7580
  avatarBody: e = "F",
@@ -7606,17 +7606,17 @@ const Xt = $e(({
7606
7606
  autoIdleGroup: y = null,
7607
7607
  // e.g., "idle" - will select from this group in order when idle
7608
7608
  autoSpeak: E = !1
7609
- }, S) => {
7610
- const C = V(null), x = V(null), I = V(c), G = V(null), P = V(null), D = V(!1), $ = V({ remainingText: null, originalText: null, options: null }), ye = V([]), [fe, Te] = pe(!0), [Ie, Me] = pe(null), [re, R] = pe(!1), [v, N] = pe(!1), [B, j] = pe(H), ie = V(null), X = V(!1), _ = V(null), Le = V(!1), xe = V([]), be = V([]), tt = V(0), w = V(null), K = V(null), ce = V(L), ae = V("");
7609
+ }, k) => {
7610
+ const C = V(null), x = V(null), I = V(c), G = V(null), P = V(null), D = V(!1), $ = V({ remainingText: null, originalText: null, options: null }), ye = V([]), [fe, Te] = pe(!0), [Ie, Me] = pe(null), [re, R] = pe(!1), [v, N] = pe(!1), [B, j] = pe(H), ie = V(null), X = V(!1), q = V(null), Le = V(!1), xe = V([]), be = V([]), nt = V(0), w = V(null), K = V(null), ce = V(L), ae = V("");
7611
7611
  ke(() => {
7612
7612
  D.current = v;
7613
7613
  }, [v]), ke(() => {
7614
7614
  ce.current = L;
7615
7615
  }, [L]);
7616
- const Ae = W((k) => {
7616
+ const Ae = W((S) => {
7617
7617
  let z = "F";
7618
- if (k) {
7619
- const F = k.toString().toUpperCase().trim();
7618
+ if (S) {
7619
+ const F = S.toString().toUpperCase().trim();
7620
7620
  F === "M" || F === "MALE" ? z = "M" : (F === "F" || F === "FEMALE") && (z = "F");
7621
7621
  }
7622
7622
  return z === "M" ? "male" : "female";
@@ -7625,20 +7625,20 @@ const Xt = $e(({
7625
7625
  (async () => {
7626
7626
  if (H.manifest && H.auto)
7627
7627
  try {
7628
- const z = await je(H.manifest);
7628
+ const z = await Qe(H.manifest);
7629
7629
  j(z);
7630
7630
  return;
7631
7631
  } catch {
7632
7632
  }
7633
7633
  if (H.manifest && !H.auto) {
7634
- const z = await je(H.manifest), F = Object.keys(z).length > 0;
7634
+ const z = await Qe(H.manifest), F = Object.keys(z).length > 0;
7635
7635
  j(F ? z : H);
7636
7636
  } else if (H.auto)
7637
7637
  try {
7638
7638
  let z = null;
7639
7639
  if (H.manifest)
7640
7640
  try {
7641
- z = await je(H.manifest);
7641
+ z = await Qe(H.manifest);
7642
7642
  } catch {
7643
7643
  }
7644
7644
  if (typeof H.auto == "string") {
@@ -7648,7 +7648,7 @@ const Xt = $e(({
7648
7648
  }, Z = Ae(e);
7649
7649
  oe[`${Z}_talking`] = `${F}/${Z}/talking`, oe[`${Z}_idle`] = `${F}/${Z}/idle`, oe.shared_talking = `${F}/shared/talking`, oe.shared_idle = `${F}/shared/idle`;
7650
7650
  const Se = await ct(oe, e);
7651
- if (!Object.values(Se).some((q) => Array.isArray(q) && q.length > 0) && z) {
7651
+ if (!Object.values(Se).some((_) => Array.isArray(_) && _.length > 0) && z) {
7652
7652
  j(z);
7653
7653
  return;
7654
7654
  }
@@ -7658,18 +7658,18 @@ const Xt = $e(({
7658
7658
  shared: {}
7659
7659
  }
7660
7660
  };
7661
- Object.entries(Se).forEach(([q, ne]) => {
7662
- if (q.includes("_")) {
7663
- const [ee, ...ge] = q.split("_"), de = ge.join("_");
7661
+ Object.entries(Se).forEach(([_, ne]) => {
7662
+ if (_.includes("_")) {
7663
+ const [ee, ...ge] = _.split("_"), de = ge.join("_");
7664
7664
  ee === "shared" ? (te._genderSpecific.shared[de] || (te._genderSpecific.shared[de] = []), te._genderSpecific.shared[de].push(...ne)) : ee === Z && (te._genderSpecific[Z][de] || (te._genderSpecific[Z][de] = []), te._genderSpecific[Z][de].push(...ne));
7665
7665
  } else
7666
- te[q] = ne;
7667
- }), z && (z._genderSpecific && Object.keys(z._genderSpecific).forEach((q) => {
7668
- te._genderSpecific[q] || (te._genderSpecific[q] = {}), Object.entries(z._genderSpecific[q]).forEach(([ne, ee]) => {
7669
- te._genderSpecific[q][ne] || (te._genderSpecific[q][ne] = ee);
7666
+ te[_] = ne;
7667
+ }), z && (z._genderSpecific && Object.keys(z._genderSpecific).forEach((_) => {
7668
+ te._genderSpecific[_] || (te._genderSpecific[_] = {}), Object.entries(z._genderSpecific[_]).forEach(([ne, ee]) => {
7669
+ te._genderSpecific[_][ne] || (te._genderSpecific[_][ne] = ee);
7670
7670
  });
7671
- }), Object.entries(z).forEach(([q, ne]) => {
7672
- q !== "_genderSpecific" && !te[q] && (te[q] = ne);
7671
+ }), Object.entries(z).forEach(([_, ne]) => {
7672
+ _ !== "_genderSpecific" && !te[_] && (te[_] = ne);
7673
7673
  })), j(te);
7674
7674
  } else if (typeof H.auto == "object") {
7675
7675
  const F = await ct(H.auto, e), oe = Object.values(F).some((Z) => Array.isArray(Z) && Z.length > 0);
@@ -7678,7 +7678,7 @@ const Xt = $e(({
7678
7678
  } catch (z) {
7679
7679
  if (console.error("Failed to auto-discover animations:", z), H.manifest)
7680
7680
  try {
7681
- const F = await je(H.manifest);
7681
+ const F = await Qe(H.manifest);
7682
7682
  j(F);
7683
7683
  } catch {
7684
7684
  j(H);
@@ -7692,7 +7692,7 @@ const Xt = $e(({
7692
7692
  }, [H, e, Ae]), ke(() => {
7693
7693
  I.current = c;
7694
7694
  }, [c]);
7695
- const J = et(), me = s || J.service;
7695
+ const J = tt(), me = s || J.service;
7696
7696
  let Ce;
7697
7697
  me === "browser" ? Ce = {
7698
7698
  service: "browser",
@@ -7709,8 +7709,8 @@ const Xt = $e(({
7709
7709
  service: "deepgram",
7710
7710
  endpoint: "https://api.deepgram.com/v1/speak",
7711
7711
  apiKey: a || J.apiKey,
7712
- defaultVoice: i || J.defaultVoice || Ke.defaultVoice,
7713
- voices: J.voices || Ke.voices
7712
+ defaultVoice: i || J.defaultVoice || $e.defaultVoice,
7713
+ voices: J.voices || $e.voices
7714
7714
  } : Ce = {
7715
7715
  ...J,
7716
7716
  apiKey: a !== null ? a : J.apiKey
@@ -7740,14 +7740,14 @@ const Xt = $e(({
7740
7740
  d(F);
7741
7741
  }
7742
7742
  }), Te(!1), R(!0), h(x.current);
7743
- const k = () => {
7743
+ const S = () => {
7744
7744
  document.visibilityState === "visible" ? x.current?.start() : x.current?.stop();
7745
7745
  };
7746
- return document.addEventListener("visibilitychange", k), () => {
7747
- document.removeEventListener("visibilitychange", k);
7746
+ return document.addEventListener("visibilitychange", S), () => {
7747
+ document.removeEventListener("visibilitychange", S);
7748
7748
  };
7749
- } catch (k) {
7750
- console.error("Error initializing TalkingHead:", k), Me(k.message || "Failed to initialize avatar"), Te(!1), p(k);
7749
+ } catch (S) {
7750
+ console.error("Error initializing TalkingHead:", S), Me(S.message || "Failed to initialize avatar"), Te(!1), p(S);
7751
7751
  }
7752
7752
  }, []);
7753
7753
  ke(() => (ze(), () => {
@@ -7756,43 +7756,43 @@ const Xt = $e(({
7756
7756
  const Pe = W(async () => {
7757
7757
  if (x.current)
7758
7758
  try {
7759
- const k = x.current.audioCtx || x.current.audioContext;
7760
- k && (k.state === "suspended" || k.state === "interrupted") && await k.resume();
7761
- } catch (k) {
7762
- console.warn("Failed to resume audio context:", k);
7759
+ const S = x.current.audioCtx || x.current.audioContext;
7760
+ S && (S.state === "suspended" || S.state === "interrupted") && await S.resume();
7761
+ } catch (S) {
7762
+ console.warn("Failed to resume audio context:", S);
7763
7763
  }
7764
- }, []), nt = W((k) => {
7764
+ }, []), Ge = W((S) => {
7765
7765
  if (!B)
7766
7766
  return [];
7767
7767
  let z = null;
7768
7768
  if (B._genderSpecific) {
7769
7769
  const F = Ae(e), oe = B._genderSpecific[F];
7770
- if (oe && oe[k] && Array.isArray(oe[k]) && oe[k].length > 0 && (z = oe[k]), !z && B._genderSpecific.shared && B._genderSpecific.shared[k]) {
7771
- const Z = B._genderSpecific.shared[k];
7770
+ if (oe && oe[S] && Array.isArray(oe[S]) && oe[S].length > 0 && (z = oe[S]), !z && B._genderSpecific.shared && B._genderSpecific.shared[S]) {
7771
+ const Z = B._genderSpecific.shared[S];
7772
7772
  Array.isArray(Z) && Z.length > 0 && (z = Z);
7773
7773
  }
7774
7774
  }
7775
- if (!z && B[k]) {
7776
- const F = B[k];
7775
+ if (!z && B[S]) {
7776
+ const F = B[S];
7777
7777
  Array.isArray(F) && F.length > 0 ? z = F : typeof F == "string" && (z = [F]);
7778
7778
  }
7779
- return !z || Array.isArray(z) && z.length === 0 ? ((Object.keys(B).length > 0 || B._genderSpecific && Object.keys(B._genderSpecific).length > 0) && console.warn(`⚠️ No animations found for group "${k}" (gender: ${Ae(e)}). Make sure animations are configured correctly.`), []) : Array.isArray(z) ? [...z] : typeof z == "string" ? [z] : [];
7780
- }, [B, e, Ae]), Ge = W((k) => {
7779
+ return !z || Array.isArray(z) && z.length === 0 ? ((Object.keys(B).length > 0 || B._genderSpecific && Object.keys(B._genderSpecific).length > 0) && console.warn(`⚠️ No animations found for group "${S}" (gender: ${Ae(e)}). Make sure animations are configured correctly.`), []) : Array.isArray(z) ? [...z] : typeof z == "string" ? [z] : [];
7780
+ }, [B, e, Ae]), Ze = W((S) => {
7781
7781
  if (be.current.length === 0) {
7782
- const F = nt(k);
7782
+ const F = Ge(S);
7783
7783
  if (F.length === 0)
7784
7784
  return null;
7785
7785
  be.current = [...F], xe.current = [];
7786
7786
  }
7787
7787
  const z = be.current.shift();
7788
7788
  return z && xe.current.push(z), z;
7789
- }, [nt]), Qe = W((k) => k ? k.split("/").pop().replace(".fbx", "").replace(/[-_]/g, " ") : "Unknown", []), Fe = W((k, z = !1, F = null) => {
7790
- if (!x.current || !X.current || _.current !== k)
7789
+ }, [Ge]), Ye = W((S) => S ? S.split("/").pop().replace(".fbx", "").replace(/[-_]/g, " ") : "Unknown", []), Fe = W((S, z = !1, F = null) => {
7790
+ if (!x.current || !X.current || q.current !== S)
7791
7791
  return null;
7792
- const oe = Ge(k);
7792
+ const oe = Ze(S);
7793
7793
  if (oe)
7794
7794
  try {
7795
- const Z = Qe(oe);
7795
+ const Z = Ye(oe);
7796
7796
  console.log(`🎬 Playing animation: "${Z}"`);
7797
7797
  const Se = () => {
7798
7798
  console.log("🎬 Animation finished, checking if should continue...");
@@ -7801,9 +7801,9 @@ const Xt = $e(({
7801
7801
  return console.log("🎬 No talkingHeadRef, stopping animations"), !1;
7802
7802
  if (!X.current)
7803
7803
  return console.log("🎬 isSpeakingRef is false, stopping animations"), !1;
7804
- if (_.current !== k)
7805
- return console.log(`🎬 Animation group mismatch (${_.current} !== ${k}), stopping animations`), !1;
7806
- const q = x.current, ne = q.isAudioPlaying === !0, ee = q.audioPlaylist && q.audioPlaylist.length > 0, ge = q.speechQueue && q.speechQueue.length > 0, de = q.isSpeaking === !0, Ue = de || ne || ee || ge;
7804
+ if (q.current !== S)
7805
+ return console.log(`🎬 Animation group mismatch (${q.current} !== ${S}), stopping animations`), !1;
7806
+ const _ = x.current, ne = _.isAudioPlaying === !0, ee = _.audioPlaylist && _.audioPlaylist.length > 0, ge = _.speechQueue && _.speechQueue.length > 0, de = _.isSpeaking === !0, Ue = de || ne || ee || ge;
7807
7807
  return console.log("🎬 Still speaking check:", {
7808
7808
  isSpeakingRef: X.current,
7809
7809
  isTalkingHeadSpeaking: de,
@@ -7814,8 +7814,8 @@ const Xt = $e(({
7814
7814
  }), Ue;
7815
7815
  };
7816
7816
  O() ? (console.log("🎬 Still speaking, continuing to next animation..."), requestAnimationFrame(() => {
7817
- O() ? (console.log("🎬 Playing next animation..."), Fe(k, z, F)) : (console.log("🎬 Speech ended, stopping animations"), X.current = !1, _.current = null, x.current && x.current.stopAnimation(), F && F());
7818
- })) : (console.log("🎬 Speech has ended, stopping animations"), X.current = !1, _.current = null, x.current && x.current.stopAnimation(), F && F());
7817
+ O() ? (console.log("🎬 Playing next animation..."), Fe(S, z, F)) : (console.log("🎬 Speech ended, stopping animations"), X.current = !1, q.current = null, x.current && x.current.stopAnimation(), F && F());
7818
+ })) : (console.log("🎬 Speech has ended, stopping animations"), X.current = !1, q.current = null, x.current && x.current.stopAnimation(), F && F());
7819
7819
  };
7820
7820
  return x.current.playAnimation(oe, null, 0, 0, 0.01, z, Se), oe;
7821
7821
  } catch (Z) {
@@ -7823,43 +7823,43 @@ const Xt = $e(({
7823
7823
  }
7824
7824
  else {
7825
7825
  const Z = () => {
7826
- if (!x.current || !X.current || _.current !== k)
7826
+ if (!x.current || !X.current || q.current !== S)
7827
7827
  return !1;
7828
- const O = x.current, te = O.isAudioPlaying === !0, q = O.audioPlaylist && O.audioPlaylist.length > 0, ne = O.speechQueue && O.speechQueue.length > 0;
7829
- return O.isSpeaking === !0 || te || q || ne;
7828
+ const O = x.current, te = O.isAudioPlaying === !0, _ = O.audioPlaylist && O.audioPlaylist.length > 0, ne = O.speechQueue && O.speechQueue.length > 0;
7829
+ return O.isSpeaking === !0 || te || _ || ne;
7830
7830
  };
7831
- Z() && (be.current = [], xe.current = [], Z() ? Fe(k, z, F) : (X.current = !1, _.current = null, x.current && x.current.stopAnimation()));
7831
+ Z() && (Ge(S).length > 0 ? (be.current = [], xe.current = [], Z() ? Fe(S, z, F) : (X.current = !1, q.current = null, x.current && x.current.stopAnimation())) : (console.log(`🎬 No animations available for group "${S}", stopping animations`), X.current = !1, q.current = null, x.current && x.current.stopAnimation(), F && F()));
7832
7832
  }
7833
7833
  return null;
7834
- }, [Ge, Qe]), dt = W(() => {
7834
+ }, [Ze, Ye, Ge]), dt = W(() => {
7835
7835
  y && x.current && !X.current && (ie.current && (clearInterval(ie.current), ie.current = null), be.current = [], xe.current = [], Fe(y, !1, null), ie.current = setInterval(() => {
7836
7836
  !X.current && !D.current && y && (be.current = [], xe.current = [], Fe(y, !1, null));
7837
7837
  }, 12e3 + Math.random() * 3e3));
7838
7838
  }, [y, Fe]);
7839
7839
  K.current = dt;
7840
- const Ze = W(async (k, z = {}) => {
7841
- if (!x.current || !re || !k || k.trim() === "")
7840
+ const je = W(async (S, z = {}) => {
7841
+ if (!x.current || !re || !S || S.trim() === "")
7842
7842
  return;
7843
7843
  await Pe(), ie.current && (clearInterval(ie.current), ie.current = null);
7844
7844
  const F = z.animationGroup || M;
7845
- F && !z.skipAnimation && (X.current = !0, _.current = F, be.current = [], xe.current = [], Fe(F));
7845
+ F && !z.skipAnimation && (X.current = !0, q.current = F, be.current = [], xe.current = [], Fe(F));
7846
7846
  try {
7847
- b(k), z.onSpeechStart && z.onSpeechStart(k);
7847
+ b(S), z.onSpeechStart && z.onSpeechStart(S);
7848
7848
  } catch (O) {
7849
7849
  console.warn("Error in onSpeechStart callback:", O);
7850
7850
  }
7851
- $.current = { remainingText: null, originalText: null, options: null }, ye.current = [], G.current = { text: k, options: z }, P.current && (clearInterval(P.current), P.current = null), N(!1), D.current = !1, Le.current = !1;
7852
- const oe = k.split(/[.!?]+/).filter((O) => O.trim().length > 0);
7853
- ye.current = oe, tt.current = 0, ae.current = "";
7851
+ $.current = { remainingText: null, originalText: null, options: null }, ye.current = [], G.current = { text: S, options: z }, P.current && (clearInterval(P.current), P.current = null), N(!1), D.current = !1, Le.current = !1;
7852
+ const oe = S.split(/[.!?]+/).filter((O) => O.trim().length > 0);
7853
+ ye.current = oe, nt.current = 0, ae.current = "";
7854
7854
  const Z = (O) => {
7855
7855
  let te = "";
7856
7856
  if (O && (O.text ? te = O.text : O.vs && O.vs.subtitles ? Array.isArray(O.vs.subtitles) ? te = O.vs.subtitles.join("") : typeof O.vs.subtitles == "string" && (te = O.vs.subtitles) : O.subtitles && (Array.isArray(O.subtitles) ? te = O.subtitles.join("") : typeof O.subtitles == "string" && (te = O.subtitles))), te.trim()) {
7857
7857
  ae.current += te;
7858
- const q = ce.current;
7859
- if (q && typeof q == "function")
7858
+ const _ = ce.current;
7859
+ if (_ && typeof _ == "function")
7860
7860
  try {
7861
7861
  setTimeout(() => {
7862
- q(ae.current.trim());
7862
+ _(ae.current.trim());
7863
7863
  }, 0);
7864
7864
  } catch (ne) {
7865
7865
  console.warn("Error in onSubtitle callback:", ne);
@@ -7872,14 +7872,14 @@ const Xt = $e(({
7872
7872
  if (x.current) {
7873
7873
  const O = x.current;
7874
7874
  let te = 0;
7875
- const q = 1200;
7875
+ const _ = 1200;
7876
7876
  P.current && (clearInterval(P.current), P.current = null);
7877
7877
  const ne = { current: !1 }, ee = setInterval(() => {
7878
7878
  if (te++, D.current)
7879
7879
  return;
7880
- if (te > q) {
7880
+ if (te > _) {
7881
7881
  if (ee && (clearInterval(ee), P.current = null), !ne.current && !D.current) {
7882
- ne.current = !0, X.current = !1, _.current = null, be.current = [], xe.current = [], x.current && (x.current.stopAnimation(), x.current.isSpeaking = !1);
7882
+ ne.current = !0, X.current = !1, q.current = null, be.current = [], xe.current = [], x.current && (x.current.stopAnimation(), x.current.isSpeaking = !1);
7883
7883
  try {
7884
7884
  z.onSpeechEnd && z.onSpeechEnd(), f();
7885
7885
  } catch (ue) {
@@ -7893,7 +7893,7 @@ const Xt = $e(({
7893
7893
  const ue = x.current;
7894
7894
  if (!ue)
7895
7895
  return;
7896
- !D.current && (!ue.speechQueue || ue.speechQueue.length === 0) && (!ue.audioPlaylist || ue.audioPlaylist.length === 0) && ue.isAudioPlaying === !1 && ue.isSpeaking === !1 && !ne.current && !D.current && (ne.current = !0, ee && (clearInterval(ee), P.current = null), X.current = !1, _.current = null, be.current = [], xe.current = [], ae.current = "", ue && (ue.stopAnimation(), ue.isSpeaking = !1), Le.current = !0, setTimeout(() => {
7896
+ !D.current && (!ue.speechQueue || ue.speechQueue.length === 0) && (!ue.audioPlaylist || ue.audioPlaylist.length === 0) && ue.isAudioPlaying === !1 && ue.isSpeaking === !1 && !ne.current && !D.current && (ne.current = !0, ee && (clearInterval(ee), P.current = null), X.current = !1, q.current = null, be.current = [], xe.current = [], ae.current = "", ue && (ue.stopAnimation(), ue.isSpeaking = !1), Le.current = !0, setTimeout(() => {
7897
7897
  K.current && K.current();
7898
7898
  }, 500), setTimeout(() => {
7899
7899
  try {
@@ -7909,7 +7909,7 @@ const Xt = $e(({
7909
7909
  P.current = ee;
7910
7910
  }
7911
7911
  try {
7912
- x.current.speakText(k, Se);
7912
+ x.current.speakText(S, Se);
7913
7913
  } catch (O) {
7914
7914
  console.error("Error speaking text:", O), Me(O.message || "Failed to speak text");
7915
7915
  }
@@ -7918,22 +7918,22 @@ const Xt = $e(({
7918
7918
  if (!re || !y || !x.current)
7919
7919
  return;
7920
7920
  ie.current && (clearInterval(ie.current), ie.current = null);
7921
- const k = () => {
7921
+ const S = () => {
7922
7922
  x.current && !D.current && !X.current && (be.current = [], xe.current = [], Fe(y, !1, null));
7923
7923
  };
7924
- return X.current || k(), ie.current = setInterval(() => {
7925
- X.current || k();
7924
+ return X.current || S(), ie.current = setInterval(() => {
7925
+ X.current || S();
7926
7926
  }, 12e3 + Math.random() * 3e3), () => {
7927
7927
  ie.current && (clearInterval(ie.current), ie.current = null);
7928
7928
  };
7929
- }, [re, y, Fe, X]), ke(() => {
7930
- re && Y && E && x.current && !X.current && !D.current && !Le.current && Ze(Y);
7931
- }, [re, Y, E, Ze]);
7929
+ }, [re, y, Fe]), ke(() => {
7930
+ re && Y && E && x.current && !X.current && !D.current && !Le.current && je(Y);
7931
+ }, [re, Y, E, je]);
7932
7932
  const mt = W(() => {
7933
7933
  if (x.current)
7934
7934
  try {
7935
- const k = x.current.isSpeaking || !1, z = [...x.current.audioPlaylist || []], F = [...x.current.speechQueue || []];
7936
- if (k || z.length > 0 || F.length > 0) {
7935
+ const S = x.current.isSpeaking || !1, z = [...x.current.audioPlaylist || []], F = [...x.current.speechQueue || []];
7936
+ if (S || z.length > 0 || F.length > 0) {
7937
7937
  P.current && (clearInterval(P.current), P.current = null);
7938
7938
  const oe = ye.current;
7939
7939
  let Z = [];
@@ -7963,13 +7963,13 @@ const Xt = $e(({
7963
7963
  // Track if we're pausing mid-sentence (has currently playing audio)
7964
7964
  isMidSentence: z.length > 0
7965
7965
  };
7966
- const q = x.current.isAudioPlaying || !1 ? [...x.current.speechQueue || []] : null;
7966
+ const _ = x.current.isAudioPlaying || !1 ? [...x.current.speechQueue || []] : null;
7967
7967
  x.current.speechQueue.length = 0;
7968
7968
  const ne = x.current.pauseSpeaking();
7969
- x.current.isSpeaking = !1, X.current = !1, _.current = null, ne && ne.audio && q ? (w.current = ne, w.current.savedSpeechQueue = q) : w.current = ne, N(!0), D.current = !0;
7969
+ x.current.isSpeaking = !1, X.current = !1, q.current = null, ne && ne.audio && _ ? (w.current = ne, w.current.savedSpeechQueue = _) : w.current = ne, N(!0), D.current = !0;
7970
7970
  }
7971
- } catch (k) {
7972
- console.warn("Error pausing speech:", k);
7971
+ } catch (S) {
7972
+ console.warn("Error pausing speech:", S);
7973
7973
  }
7974
7974
  }, []), pt = W(async () => {
7975
7975
  if (!(!x.current || !v))
@@ -7977,17 +7977,17 @@ const Xt = $e(({
7977
7977
  if (await Pe(), N(!1), D.current = !1, w.current && w.current.audio) {
7978
7978
  X.current = !0;
7979
7979
  const Z = $.current?.options || G.current?.options || {}, Se = Z.animationGroup || M;
7980
- if (Se && (_.current = Se), w.current.savedSpeechQueue && (x.current.speechQueue.length = 0, x.current.speechQueue.push(...w.current.savedSpeechQueue)), x.current.isSpeaking = !0, x.current) {
7980
+ if (Se && (q.current = Se), w.current.savedSpeechQueue && (x.current.speechQueue.length = 0, x.current.speechQueue.push(...w.current.savedSpeechQueue)), x.current.isSpeaking = !0, x.current) {
7981
7981
  const O = x.current;
7982
7982
  let te = 0;
7983
- const q = 1200, ne = { current: !1 };
7983
+ const _ = 1200, ne = { current: !1 };
7984
7984
  P.current && (clearInterval(P.current), P.current = null);
7985
7985
  const ee = setInterval(() => {
7986
7986
  if (te++, D.current)
7987
7987
  return;
7988
- if (te > q) {
7988
+ if (te > _) {
7989
7989
  if (ee && (clearInterval(ee), P.current = null), !ne.current && !D.current) {
7990
- ne.current = !0, X.current = !1, _.current = null, be.current = [], xe.current = [], x.current && (x.current.stopAnimation(), x.current.isSpeaking = !1);
7990
+ ne.current = !0, X.current = !1, q.current = null, be.current = [], xe.current = [], x.current && (x.current.stopAnimation(), x.current.isSpeaking = !1);
7991
7991
  try {
7992
7992
  Z.onSpeechEnd && Z.onSpeechEnd(), f();
7993
7993
  } catch (ue) {
@@ -8000,7 +8000,7 @@ const Xt = $e(({
8000
8000
  O && !D.current && ge && de && Ue && O.isSpeaking === !1 && !ne.current && !D.current && setTimeout(() => {
8001
8001
  const ue = x.current;
8002
8002
  if (!ue) return;
8003
- !D.current && (!ue.speechQueue || ue.speechQueue.length === 0) && (!ue.audioPlaylist || ue.audioPlaylist.length === 0) && ue.isAudioPlaying === !1 && ue.isSpeaking === !1 && !ne.current && !D.current && (ne.current = !0, ee && (clearInterval(ee), P.current = null), X.current = !1, _.current = null, be.current = [], xe.current = [], ae.current = "", ue && (ue.stopAnimation(), ue.isSpeaking = !1), Le.current = !0, setTimeout(() => {
8003
+ !D.current && (!ue.speechQueue || ue.speechQueue.length === 0) && (!ue.audioPlaylist || ue.audioPlaylist.length === 0) && ue.isAudioPlaying === !1 && ue.isSpeaking === !1 && !ne.current && !D.current && (ne.current = !0, ee && (clearInterval(ee), P.current = null), X.current = !1, q.current = null, be.current = [], xe.current = [], ae.current = "", ue && (ue.stopAnimation(), ue.isSpeaking = !1), Le.current = !0, setTimeout(() => {
8004
8004
  K.current && K.current();
8005
8005
  }, 500), setTimeout(() => {
8006
8006
  try {
@@ -8018,25 +8018,25 @@ const Xt = $e(({
8018
8018
  await x.current.playAudio(!1, w.current), Se && !Z.skipAnimation && (be.current = [], xe.current = [], Fe(Se)), w.current = null;
8019
8019
  return;
8020
8020
  }
8021
- const k = $.current?.remainingText, z = $.current?.originalText || G.current?.text, F = $.current?.options || G.current?.options || {}, oe = k || z;
8022
- oe && Ze(oe, F), w.current = null;
8023
- } catch (k) {
8024
- console.warn("Error resuming speech:", k), N(!1), D.current = !1, w.current = null;
8021
+ const S = $.current?.remainingText, z = $.current?.originalText || G.current?.text, F = $.current?.options || G.current?.options || {}, oe = S || z;
8022
+ oe && je(oe, F), w.current = null;
8023
+ } catch (S) {
8024
+ console.warn("Error resuming speech:", S), N(!1), D.current = !1, w.current = null;
8025
8025
  }
8026
- }, [v, Ze, Pe, M, Fe]), gt = W(() => {
8026
+ }, [v, je, Pe, M, Fe]), gt = W(() => {
8027
8027
  if (x.current) {
8028
- x.current.stopAnimation(), x.current.stopSpeaking(), P.current && (clearInterval(P.current), P.current = null), X.current = !1, _.current = null, be.current = [], xe.current = [], ae.current = "", N(!1), D.current = !1, w.current = null, Le.current = !1, setTimeout(() => {
8028
+ x.current.stopAnimation(), x.current.stopSpeaking(), P.current && (clearInterval(P.current), P.current = null), X.current = !1, q.current = null, be.current = [], xe.current = [], ae.current = "", N(!1), D.current = !1, w.current = null, Le.current = !1, setTimeout(() => {
8029
8029
  K.current && K.current();
8030
8030
  }, 500);
8031
8031
  try {
8032
8032
  f();
8033
- } catch (k) {
8034
- console.warn("Error in onSpeechEnd callback (stopSpeaking):", k);
8033
+ } catch (S) {
8034
+ console.warn("Error in onSpeechEnd callback (stopSpeaking):", S);
8035
8035
  }
8036
8036
  }
8037
8037
  }, [f]);
8038
- return Je(S, () => ({
8039
- speakText: Ze,
8038
+ return et(k, () => ({
8039
+ speakText: je,
8040
8040
  pauseSpeaking: mt,
8041
8041
  resumeSpeaking: pt,
8042
8042
  stopSpeaking: gt,
@@ -8044,19 +8044,19 @@ const Xt = $e(({
8044
8044
  isPaused: () => v,
8045
8045
  getCurrentSubtitle: () => ae.current,
8046
8046
  // Get current subtitle text
8047
- setMood: (k) => x.current?.setMood(k),
8048
- setBodyMovement: (k) => {
8049
- x.current && x.current.setBodyMovement(k);
8047
+ setMood: (S) => x.current?.setMood(S),
8048
+ setBodyMovement: (S) => {
8049
+ x.current && x.current.setBodyMovement(S);
8050
8050
  },
8051
- playAnimation: (k, z = !1) => {
8052
- x.current && x.current.playAnimation && x.current.playAnimation(k, null, 10, 0, 0.01, z);
8051
+ playAnimation: (S, z = !1) => {
8052
+ x.current && x.current.playAnimation && x.current.playAnimation(S, null, 10, 0, 0.01, z);
8053
8053
  },
8054
- playRandomAnimation: (k, z = !1) => Fe(k, z),
8055
- getRandomAnimation: (k) => getRandomAnimation(k),
8056
- playReaction: (k) => x.current?.playReaction(k),
8054
+ playRandomAnimation: (S, z = !1) => Fe(S, z),
8055
+ getRandomAnimation: (S) => getRandomAnimation(S),
8056
+ playReaction: (S) => x.current?.playReaction(S),
8057
8057
  playCelebration: () => x.current?.playCelebration(),
8058
- setShowFullAvatar: (k) => {
8059
- x.current && (I.current = k, x.current.setShowFullAvatar(k));
8058
+ setShowFullAvatar: (S) => {
8059
+ x.current && (I.current = S, x.current.setShowFullAvatar(S));
8060
8060
  },
8061
8061
  isReady: re,
8062
8062
  talkingHead: x.current
@@ -8097,7 +8097,7 @@ const Xt = $e(({
8097
8097
  ] });
8098
8098
  });
8099
8099
  Xt.displayName = "SimpleTalkingAvatar";
8100
- const Gt = $e(({
8100
+ const Gt = Je(({
8101
8101
  curriculumData: Y = null,
8102
8102
  avatarConfig: n = {},
8103
8103
  animations: e = {},
@@ -8177,7 +8177,7 @@ const Gt = $e(({
8177
8177
  lipsyncLang: "en"
8178
8178
  };
8179
8179
  }, [Y, n, e]);
8180
- const y = W(() => (H.current || { modules: [] }).modules[r.current.currentModuleIndex]?.lessons[r.current.currentLessonIndex], []), E = W(() => y()?.questions[r.current.currentQuestionIndex], [y]), S = W((R, v) => v.type === "multiple_choice" || v.type === "true_false" ? R === v.answer : v.type === "code_test" && typeof R == "object" && R !== null ? R.passed === !0 : !1, []), C = W(() => {
8180
+ const y = W(() => (H.current || { modules: [] }).modules[r.current.currentModuleIndex]?.lessons[r.current.currentLessonIndex], []), E = W(() => y()?.questions[r.current.currentQuestionIndex], [y]), k = W((R, v) => v.type === "multiple_choice" || v.type === "true_false" ? R === v.answer : v.type === "code_test" && typeof R == "object" && R !== null ? R.passed === !0 : !1, []), C = W(() => {
8181
8181
  r.current.lessonCompleted = !0, r.current.isQuestionMode = !1;
8182
8182
  const R = r.current.totalQuestions > 0 ? Math.round(r.current.score / r.current.totalQuestions * 100) : 100;
8183
8183
  let v = "Congratulations! You've completed this lesson";
@@ -8201,9 +8201,9 @@ const Gt = $e(({
8201
8201
  } catch {
8202
8202
  c.current.playCelebration();
8203
8203
  }
8204
- const N = H.current || { modules: [] }, B = N.modules[r.current.currentModuleIndex], j = r.current.currentLessonIndex < (B?.lessons?.length || 0) - 1, ie = r.current.currentModuleIndex < (N.modules?.length || 0) - 1, X = j || ie, _ = M.current || { lipsyncLang: "en" };
8204
+ const N = H.current || { modules: [] }, B = N.modules[r.current.currentModuleIndex], j = r.current.currentLessonIndex < (B?.lessons?.length || 0) - 1, ie = r.current.currentModuleIndex < (N.modules?.length || 0) - 1, X = j || ie, q = M.current || { lipsyncLang: "en" };
8205
8205
  c.current.speakText(v, {
8206
- lipsyncLang: _.lipsyncLang,
8206
+ lipsyncLang: q.lipsyncLang,
8207
8207
  onSpeechEnd: () => {
8208
8208
  h.current.onCustomAction({
8209
8209
  type: "lessonCompleteFeedbackDone",
@@ -8289,28 +8289,28 @@ const Gt = $e(({
8289
8289
  if (c.current.setMood("happy"), c.current.setBodyMovement("idle"), e.nextQuestion)
8290
8290
  try {
8291
8291
  c.current.playAnimation(e.nextQuestion, !0);
8292
- } catch (_) {
8293
- console.warn("Failed to play nextQuestion animation:", _);
8292
+ } catch (q) {
8293
+ console.warn("Failed to play nextQuestion animation:", q);
8294
8294
  }
8295
8295
  const B = M.current || { lipsyncLang: "en" }, ie = y()?.questions?.length || 0, X = r.current.currentQuestionIndex >= ie - 1;
8296
8296
  if (v.type === "code_test") {
8297
- const _ = X ? `Great! Here's your final coding challenge: ${v.question}` : `Great! Now let's move on to your next coding challenge: ${v.question}`;
8298
- c.current.speakText(_, {
8297
+ const q = X ? `Great! Here's your final coding challenge: ${v.question}` : `Great! Now let's move on to your next coding challenge: ${v.question}`;
8298
+ c.current.speakText(q, {
8299
8299
  lipsyncLang: B.lipsyncLang
8300
8300
  });
8301
8301
  } else if (v.type === "multiple_choice") {
8302
- const _ = X ? `Alright! Here's your final question: ${v.question}` : `Alright! Here's your next question: ${v.question}`;
8303
- c.current.speakText(_, {
8302
+ const q = X ? `Alright! Here's your final question: ${v.question}` : `Alright! Here's your next question: ${v.question}`;
8303
+ c.current.speakText(q, {
8304
8304
  lipsyncLang: B.lipsyncLang
8305
8305
  });
8306
8306
  } else if (v.type === "true_false") {
8307
- const _ = X ? `Now let's try this final one: ${v.question}` : `Now let's try this one: ${v.question}`;
8308
- c.current.speakText(_, {
8307
+ const q = X ? `Now let's try this final one: ${v.question}` : `Now let's try this one: ${v.question}`;
8308
+ c.current.speakText(q, {
8309
8309
  lipsyncLang: B.lipsyncLang
8310
8310
  });
8311
8311
  } else {
8312
- const _ = X ? `Here's your final question: ${v.question}` : `Here's the next question: ${v.question}`;
8313
- c.current.speakText(_, {
8312
+ const q = X ? `Here's your final question: ${v.question}` : `Here's the next question: ${v.question}`;
8313
+ c.current.speakText(q, {
8314
8314
  lipsyncLang: B.lipsyncLang
8315
8315
  });
8316
8316
  }
@@ -8350,12 +8350,12 @@ const Gt = $e(({
8350
8350
  }), c.current && (c.current.setMood("happy"), c.current.setBodyMovement("idle"));
8351
8351
  } else if (r.current.currentModuleIndex < (R.modules?.length || 0) - 1) {
8352
8352
  r.current.currentModuleIndex += 1, r.current.currentLessonIndex = 0, r.current.currentQuestionIndex = 0, r.current.lessonCompleted = !1, r.current.isQuestionMode = !1, r.current.isTeaching = !1, r.current.score = 0, r.current.totalQuestions = 0;
8353
- const j = R.modules[r.current.currentModuleIndex], ie = r.current.currentLessonIndex < (j?.lessons?.length || 0) - 1, X = r.current.currentModuleIndex < (R.modules?.length || 0) - 1, _ = ie || X;
8353
+ const j = R.modules[r.current.currentModuleIndex], ie = r.current.currentLessonIndex < (j?.lessons?.length || 0) - 1, X = r.current.currentModuleIndex < (R.modules?.length || 0) - 1, q = ie || X;
8354
8354
  h.current.onCustomAction({
8355
8355
  type: "lessonStart",
8356
8356
  moduleIndex: r.current.currentModuleIndex,
8357
8357
  lessonIndex: r.current.currentLessonIndex,
8358
- hasNextLesson: _
8358
+ hasNextLesson: q
8359
8359
  }), h.current.onLessonStart({
8360
8360
  moduleIndex: r.current.currentModuleIndex,
8361
8361
  lessonIndex: r.current.currentLessonIndex,
@@ -8411,7 +8411,7 @@ const Gt = $e(({
8411
8411
  });
8412
8412
  }
8413
8413
  }, [e.teaching, y]), $ = W((R) => {
8414
- const v = E(), N = S(R, v);
8414
+ const v = E(), N = k(R, v);
8415
8415
  if (N && (r.current.score += 1), h.current.onQuestionAnswer({
8416
8416
  moduleIndex: r.current.currentModuleIndex,
8417
8417
  lessonIndex: r.current.currentLessonIndex,
@@ -8432,9 +8432,9 @@ const Gt = $e(({
8432
8432
  r.current.currentQuestionIndex >= j - 1;
8433
8433
  const ie = r.current.currentQuestionIndex < j - 1;
8434
8434
  console.log("[CurriculumLearning] Answer feedback - questionIndex:", r.current.currentQuestionIndex, "totalQuestions:", j, "hasNextQuestion:", ie);
8435
- const X = v.type === "code_test" ? `Great job! Your code passed all the tests! ${v.explanation || ""}` : `Excellent! That's correct! ${v.explanation || ""}`, _ = M.current || { lipsyncLang: "en" };
8435
+ const X = v.type === "code_test" ? `Great job! Your code passed all the tests! ${v.explanation || ""}` : `Excellent! That's correct! ${v.explanation || ""}`, q = M.current || { lipsyncLang: "en" };
8436
8436
  c.current.speakText(X, {
8437
- lipsyncLang: _.lipsyncLang,
8437
+ lipsyncLang: q.lipsyncLang,
8438
8438
  onSpeechEnd: () => {
8439
8439
  h.current.onCustomAction({
8440
8440
  type: "answerFeedbackComplete",
@@ -8458,8 +8458,8 @@ const Gt = $e(({
8458
8458
  c.current.setBodyMovement("gesturing");
8459
8459
  const j = y()?.questions?.length || 0, ie = r.current.currentQuestionIndex >= j - 1, X = r.current.currentQuestionIndex < j - 1;
8460
8460
  console.log("[CurriculumLearning] Answer feedback (incorrect) - questionIndex:", r.current.currentQuestionIndex, "totalQuestions:", j, "hasNextQuestion:", X);
8461
- const _ = v.type === "code_test" ? `Your code didn't pass all the tests. ${v.explanation || "Try again!"}` : `Not quite right, but don't worry! ${v.explanation || ""}${ie ? "" : " Let's move on to the next question."}`, Le = M.current || { lipsyncLang: "en" };
8462
- c.current.speakText(_, {
8461
+ const q = v.type === "code_test" ? `Your code didn't pass all the tests. ${v.explanation || "Try again!"}` : `Not quite right, but don't worry! ${v.explanation || ""}${ie ? "" : " Let's move on to the next question."}`, Le = M.current || { lipsyncLang: "en" };
8462
+ c.current.speakText(q, {
8463
8463
  lipsyncLang: Le.lipsyncLang,
8464
8464
  onSpeechEnd: () => {
8465
8465
  h.current.onCustomAction({
@@ -8489,7 +8489,7 @@ const Gt = $e(({
8489
8489
  avatarNotReady: !0
8490
8490
  });
8491
8491
  }
8492
- }, [e.correct, e.incorrect, E, y, S]), ye = W((R) => {
8492
+ }, [e.correct, e.incorrect, E, y, k]), ye = W((R) => {
8493
8493
  const v = E();
8494
8494
  if (!R || typeof R != "object") {
8495
8495
  console.error("Invalid code test result format. Expected object with {passed: boolean, ...}");
@@ -8517,7 +8517,7 @@ const Gt = $e(({
8517
8517
  testResult: N,
8518
8518
  question: v
8519
8519
  }), g.current && g.current(N);
8520
- }, [E, S]), fe = W(() => {
8520
+ }, [E, k]), fe = W(() => {
8521
8521
  if (r.current.currentQuestionIndex > 0) {
8522
8522
  r.current.currentQuestionIndex -= 1;
8523
8523
  const R = E();
@@ -8586,7 +8586,7 @@ const Gt = $e(({
8586
8586
  }, [u, y]);
8587
8587
  xt(() => {
8588
8588
  d.current = D, p.current = P, b.current = C, f.current = G, L.current = x, Q.current = I, g.current = $;
8589
- }), Je(l, () => ({
8589
+ }), et(l, () => ({
8590
8590
  // Curriculum control methods
8591
8591
  startTeaching: D,
8592
8592
  startQuestions: I,
@@ -8705,7 +8705,7 @@ function en({
8705
8705
  (async () => {
8706
8706
  r(!0), d(null);
8707
8707
  try {
8708
- const x = await je(Y), I = [];
8708
+ const x = await Qe(Y), I = [];
8709
8709
  if (x._genderSpecific) {
8710
8710
  const P = (n?.toUpperCase() || "F") === "M" ? "male" : "female";
8711
8711
  x._genderSpecific[P] && Object.entries(x._genderSpecific[P]).forEach(([D, $]) => {
@@ -8771,7 +8771,7 @@ This will delete:
8771
8771
  ${x.slice(0, 5).join(`
8772
8772
  `)}${x.length > 5 ? `
8773
8773
  ...` : ""}`) && (o && o(x), a(i.filter((I) => u.has(I.path))), l(/* @__PURE__ */ new Set()));
8774
- }, S = (C) => {
8774
+ }, k = (C) => {
8775
8775
  e && e(C);
8776
8776
  };
8777
8777
  return c ? /* @__PURE__ */ le("div", { style: { padding: "20px", textAlign: "center", ...s }, children: /* @__PURE__ */ le("p", { children: "Loading animations..." }) }) : h ? /* @__PURE__ */ le("div", { style: { padding: "20px", color: "red", ...s }, children: /* @__PURE__ */ Be("p", { children: [
@@ -8948,7 +8948,7 @@ ${x.slice(0, 5).join(`
8948
8948
  "button",
8949
8949
  {
8950
8950
  onClick: (G) => {
8951
- G.stopPropagation(), S(C.path);
8951
+ G.stopPropagation(), k(C.path);
8952
8952
  },
8953
8953
  style: {
8954
8954
  width: "100%",
@@ -9086,7 +9086,7 @@ export {
9086
9086
  ut as TalkingHeadAvatar,
9087
9087
  Wt as TalkingHeadComponent,
9088
9088
  ht as animations,
9089
- et as getActiveTTSConfig,
9089
+ tt as getActiveTTSConfig,
9090
9090
  tn as getAnimation,
9091
9091
  Jt as getVoiceOptions,
9092
9092
  nn as hasAnimation