@sage-rsc/talking-head-react 1.0.64 → 1.0.65

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
- import { jsxs as Ee, jsx as ue } from "react/jsx-runtime";
2
- import { forwardRef as Ie, useRef as G, useState as me, useEffect as pe, useCallback as E, useImperativeHandle as Le, useLayoutEffect as We } from "react";
1
+ import { jsxs as Ee, jsx as ce } from "react/jsx-runtime";
2
+ import { forwardRef as Ie, useRef as Z, useState as pe, useEffect as ge, useCallback as E, useImperativeHandle as Le, useLayoutEffect as We } from "react";
3
3
  import * as f from "three";
4
4
  import { OrbitControls as Ve } from "three/addons/controls/OrbitControls.js";
5
5
  import { GLTFLoader as Ge } from "three/addons/loaders/GLTFLoader.js";
@@ -12,7 +12,7 @@ const A = [0, 0, 0, 0], k = new f.Vector3(), be = new f.Vector3(), Q = new f.Vec
12
12
  new f.Plane();
13
13
  new f.Ray();
14
14
  new f.Euler();
15
- const q = new f.Quaternion(), Ce = new f.Quaternion(), se = new f.Matrix4(), ae = new f.Matrix4();
15
+ const q = new f.Quaternion(), Ce = new f.Quaternion(), ae = new f.Matrix4(), re = new f.Matrix4();
16
16
  new f.Vector3();
17
17
  const Re = new f.Vector3(0, 0, 1), je = new f.Vector3(1, 0, 0), Qe = new f.Vector3(0, 1, 0), qe = new f.Vector3(0, 0, 1);
18
18
  class _e {
@@ -356,14 +356,14 @@ class _e {
356
356
  for (this.timerMs += t, t > 1e3 && (this.timerMs = 0), t /= 1e3, e = 0, i = this.objectsUpdate.length; e < i; e++)
357
357
  o = this.objectsUpdate[e], o.updateMatrix(), o.parent === null ? o.matrixWorld.copy(o.matrix) : o.matrixWorld.multiplyMatrices(o.parent.matrixWorld, o.matrix), o.matrixWorldNeedsUpdate = !1;
358
358
  for (e = 0, i = this.data.length; e < i; e++) {
359
- if (o = this.data[e], k.copy(o.vWorld), se.copy(o.boneParent.matrixWorld), ae.copy(se).invert(), o.vWorld.setFromMatrixPosition(se), k.applyMatrix4(ae), k.length() > 0.5 && (console.info("Info: Unrealistic jump of " + k.length().toFixed(2) + " meters."), k.setLength(0.5)), k.applyQuaternion(o.bone.quaternion), A[0] = k.x, A[1] = k.y, A[2] = -k.z, A[3] = k.length() / 3, o.children)
359
+ if (o = this.data[e], k.copy(o.vWorld), ae.copy(o.boneParent.matrixWorld), re.copy(ae).invert(), o.vWorld.setFromMatrixPosition(ae), k.applyMatrix4(re), k.length() > 0.5 && (console.info("Info: Unrealistic jump of " + k.length().toFixed(2) + " meters."), k.setLength(0.5)), k.applyQuaternion(o.bone.quaternion), A[0] = k.x, A[1] = k.y, A[2] = -k.z, A[3] = k.length() / 3, o.children)
360
360
  for (n = 0, s = o.children.length; n < s; n++)
361
361
  m = o.children[n], A[0] -= m.v[0] * t / 3, A[1] -= m.v[1] * t / 3, A[2] += m.v[2] * t / 3, A[3] -= m.v[3] * t / 3;
362
362
  if (m = this.opt.sensitivityFactor, A[0] *= o.ext * m, A[1] *= o.ext * m, A[2] *= o.ext * m, A[3] *= o.ext * m, o.isX && (m = A[0] / t, o.ea[0] = (m - o.ev[0]) / t, o.ev[0] = m, o.a[0] = -o.k[0] * o.p[0] - o.c[0] * o.v[0] - o.ea[0], o.p[0] += o.v[0] * t + o.a[0] * t * t / 2 + A[0], m = o.v[0] + o.a[0] * t / 2, m = -o.k[0] * o.p[0] - o.c[0] * m - o.ea[0], o.v[0] = o.v[0] + (m + o.a[0]) * t / 2), o.isY && (m = A[1] / t, o.ea[1] = (m - o.ev[1]) / t, o.ev[1] = m, o.a[1] = -o.k[1] * o.p[1] - o.c[1] * o.v[1] - o.ea[1], o.p[1] += o.v[1] * t + o.a[1] * t * t / 2 + A[1], m = o.v[1] + o.a[1] * t / 2, m = -o.k[1] * o.p[1] - o.c[1] * m - o.ea[1], o.v[1] = o.v[1] + (m + o.a[1]) * t / 2), o.isZ && (m = A[2] / t, o.ea[2] = (m - o.ev[2]) / t, o.ev[2] = m, o.a[2] = -o.k[2] * o.p[2] - o.c[2] * o.v[2] - o.ea[2], o.p[2] += o.v[2] * t + o.a[2] * t * t / 2 + A[2], m = o.v[2] + o.a[2] * t / 2, m = -o.k[2] * o.p[2] - o.c[2] * m - o.ea[2], o.v[2] = o.v[2] + (m + o.a[2]) * t / 2), o.isT && (m = A[3] / t, o.ea[3] = (m - o.ev[3]) / t, o.ev[3] = m, o.a[3] = -o.k[3] * o.p[3] - o.c[3] * o.v[3] - o.ea[3], o.p[3] += o.v[3] * t + o.a[3] * t * t / 2 + A[3], m = o.v[3] + o.a[3] * t / 2, m = -o.k[3] * o.p[3] - o.c[3] * m - o.ea[3], o.v[3] = o.v[3] + (m + o.a[3]) * t / 2), this.timerMs < this.opt.warmupMs && (o.v[0] *= 1e-4, o.p[0] *= 1e-4, o.v[1] *= 1e-4, o.p[1] *= 1e-4, o.v[2] *= 1e-4, o.p[2] *= 1e-4, o.v[3] *= 1e-4, o.p[3] *= 1e-4), A[0] = o.p[0], A[1] = o.p[1], A[2] = o.p[2], A[3] = o.p[3], m = this.opt.movementFactor, A[0] *= m, A[1] *= m, A[2] *= m, A[3] *= m, o.dl && (m = o.dl, A[0] += m[0], A[1] += m[1], A[2] += m[2]), o.dw && (m = o.dw, k.set(
363
363
  o.vBasis.x + A[0],
364
364
  o.vBasis.y + A[1],
365
365
  o.vBasis.z + A[2]
366
- ), k.applyMatrix4(se), k.x += m[0], k.y += m[1], k.z += m[2], k.applyMatrix4(ae), A[0] += k.x - o.vBasis.x, A[1] += k.y - o.vBasis.y, A[2] += k.z - o.vBasis.z), o.limits && this.opt.isLimits && (m = o.limits, m[0] && (m[0][0] !== null && A[0] < m[0][0] && (A[0] = m[0][0]), m[0][1] !== null && A[0] > m[0][1] && (A[0] = m[0][1])), m[1] && (m[1][0] !== null && A[1] < m[1][0] && (A[1] = m[1][0]), m[1][1] !== null && A[1] > m[1][1] && (A[1] = m[1][1])), m[2] && (m[2][0] !== null && A[2] < m[2][0] && (A[2] = m[2][0]), m[2][1] !== null && A[2] > m[2][1] && (A[2] = m[2][1])), m[3] && (m[3][0] !== null && A[3] < m[3][0] && (A[3] = m[3][0]), m[3][1] !== null && A[3] > m[3][1] && (A[3] = m[3][1]))), o.isPoint)
366
+ ), k.applyMatrix4(ae), k.x += m[0], k.y += m[1], k.z += m[2], k.applyMatrix4(re), A[0] += k.x - o.vBasis.x, A[1] += k.y - o.vBasis.y, A[2] += k.z - o.vBasis.z), o.limits && this.opt.isLimits && (m = o.limits, m[0] && (m[0][0] !== null && A[0] < m[0][0] && (A[0] = m[0][0]), m[0][1] !== null && A[0] > m[0][1] && (A[0] = m[0][1])), m[1] && (m[1][0] !== null && A[1] < m[1][0] && (A[1] = m[1][0]), m[1][1] !== null && A[1] > m[1][1] && (A[1] = m[1][1])), m[2] && (m[2][0] !== null && A[2] < m[2][0] && (A[2] = m[2][0]), m[2][1] !== null && A[2] > m[2][1] && (A[2] = m[2][1])), m[3] && (m[3][0] !== null && A[3] < m[3][0] && (A[3] = m[3][0]), m[3][1] !== null && A[3] > m[3][1] && (A[3] = m[3][1]))), o.isPoint)
367
367
  o.bone.position.set(
368
368
  o.vBasis.x + A[0],
369
369
  o.vBasis.y + A[1],
@@ -371,7 +371,7 @@ class _e {
371
371
  );
372
372
  else if (o.boneParent.quaternion.copy(o.qBasis), o.pivot && this.opt.isPivots && (o.boneParent.updateWorldMatrix(!1, !1), o.boneParent.matrixWorld.decompose(k, q, Q), k.copy(Re).applyQuaternion(q).setY(0).normalize(), q.premultiply(Ce.setFromUnitVectors(Re, k).invert()).normalize(), o.boneParent.quaternion.multiply(q.invert()), o.boneParent.quaternion.multiply(o.qWorldInverseYaw)), o.isZ && (m = Math.atan(A[0] / o.l), q.setFromAxisAngle(qe, -m), o.boneParent.quaternion.multiply(q)), o.isY && (m = o.l / 3, m = m * Math.tanh(A[1] / m), o.bone.position.setLength(o.l + m)), o.isX && (m = Math.atan(A[2] / o.l), q.setFromAxisAngle(je, -m), o.boneParent.quaternion.multiply(q)), o.isT && (m = 1.5 * Math.tanh(A[3] * 1.5), q.setFromAxisAngle(Qe, -m), o.boneParent.quaternion.multiply(q)), o.boneParent.updateWorldMatrix(!1, !0), o.excludes && this.opt.isExcludes)
373
373
  for (n = 0, s = o.excludes.length; n < s; n++)
374
- m = o.excludes[n], Q.set(0, 0, 0), m.deltaLocal && (Q.x += m.deltaLocal[0], Q.y += m.deltaLocal[1], Q.z += m.deltaLocal[2]), Q.applyMatrix4(m.bone.matrixWorld), ae.copy(o.boneParent.matrixWorld).invert(), Q.applyMatrix4(ae), k.copy(o.bone.position), !(k.distanceToSquared(Q) >= m.radiusSq) && ($ = k.length(), K = Q.length(), !(K > m.radius + $) && (K < Math.abs(m.radius - $) || (K = (K * K + $ * $ - m.radiusSq) / (2 * K), Q.normalize(), ve.copy(Q).multiplyScalar(K), K = Math.sqrt($ * $ - K * K), k.subVectors(k, ve).projectOnPlane(Q).normalize().multiplyScalar(K), be.subVectors(o.vBasis, ve).projectOnPlane(Q).normalize(), $ = be.dot(k), $ < 0 && ($ = Math.sqrt(K * K - $ * $), be.multiplyScalar($), k.add(be)), k.add(ve).normalize(), Q.copy(o.bone.position).normalize(), q.setFromUnitVectors(Q, k), o.boneParent.quaternion.premultiply(q), o.boneParent.updateWorldMatrix(!1, !0))));
374
+ m = o.excludes[n], Q.set(0, 0, 0), m.deltaLocal && (Q.x += m.deltaLocal[0], Q.y += m.deltaLocal[1], Q.z += m.deltaLocal[2]), Q.applyMatrix4(m.bone.matrixWorld), re.copy(o.boneParent.matrixWorld).invert(), Q.applyMatrix4(re), k.copy(o.bone.position), !(k.distanceToSquared(Q) >= m.radiusSq) && ($ = k.length(), K = Q.length(), !(K > m.radius + $) && (K < Math.abs(m.radius - $) || (K = (K * K + $ * $ - m.radiusSq) / (2 * K), Q.normalize(), ve.copy(Q).multiplyScalar(K), K = Math.sqrt($ * $ - K * K), k.subVectors(k, ve).projectOnPlane(Q).normalize().multiplyScalar(K), be.subVectors(o.vBasis, ve).projectOnPlane(Q).normalize(), $ = be.dot(k), $ < 0 && ($ = Math.sqrt(K * K - $ * $), be.multiplyScalar($), k.add(be)), k.add(ve).normalize(), Q.copy(o.bone.position).normalize(), q.setFromUnitVectors(Q, k), o.boneParent.quaternion.premultiply(q), o.boneParent.updateWorldMatrix(!1, !0))));
375
375
  }
376
376
  this.helpers.isActive && this.updateHelpers();
377
377
  }
@@ -442,17 +442,17 @@ class _e {
442
442
  */
443
443
  updateHelpers() {
444
444
  if (m = this.helpers.points, m.bones.length) {
445
- ae.copy(this.armature.matrixWorld).invert();
445
+ re.copy(this.armature.matrixWorld).invert();
446
446
  const t = m.object.geometry.getAttribute("position");
447
447
  for (let e = 0, n = m.bones.length; e < n; e++)
448
- se.multiplyMatrices(ae, m.bones[e].matrixWorld), k.setFromMatrixPosition(se), t.setXYZ(e, k.x, k.y, k.z);
448
+ ae.multiplyMatrices(re, m.bones[e].matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(e, k.x, k.y, k.z);
449
449
  t.needsUpdate = !0, m.object.updateMatrixWorld();
450
450
  }
451
451
  if (m = this.helpers.lines, m.bones.length) {
452
- ae.copy(this.armature.matrixWorld).invert();
452
+ re.copy(this.armature.matrixWorld).invert();
453
453
  const t = m.object.geometry.getAttribute("position");
454
454
  for (let e = 0, n = 0, i = m.bones.length; e < i; e++, n += 2)
455
- se.multiplyMatrices(ae, m.bones[e].matrixWorld), k.setFromMatrixPosition(se), t.setXYZ(n, k.x, k.y, k.z), se.multiplyMatrices(ae, m.bones[e].parent.matrixWorld), k.setFromMatrixPosition(se), t.setXYZ(n + 1, k.x, k.y, k.z);
455
+ ae.multiplyMatrices(re, m.bones[e].matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(n, k.x, k.y, k.z), ae.multiplyMatrices(re, m.bones[e].parent.matrixWorld), k.setFromMatrixPosition(ae), t.setXYZ(n + 1, k.x, k.y, k.z);
456
456
  t.needsUpdate = !0, m.object.updateMatrixWorld();
457
457
  }
458
458
  }
@@ -2629,7 +2629,7 @@ const rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2629
2629
  fr: it,
2630
2630
  fi: st,
2631
2631
  lt: rt
2632
- }, U = new f.Quaternion(), F = new f.Euler(), le = new f.Vector3(), he = new f.Vector3(), Te = new f.Box3();
2632
+ }, W = new f.Quaternion(), F = new f.Euler(), he = new f.Vector3(), ue = new f.Vector3(), Te = new f.Box3();
2633
2633
  new f.Matrix4();
2634
2634
  new f.Matrix4();
2635
2635
  new f.Vector3();
@@ -4376,7 +4376,7 @@ class Fe {
4376
4376
  if (e.x === 0 && e.y === 0 && e.z === 0) continue;
4377
4377
  F.set(e.x, e.y, e.z);
4378
4378
  const n = this.poseAvatar.props[t];
4379
- n.isQuaternion ? (U.setFromEuler(F), n.multiply(U)) : n.isVector3 && n.add(F);
4379
+ n.isQuaternion ? (W.setFromEuler(F), n.multiply(W)) : n.isVector3 && n.add(F);
4380
4380
  }
4381
4381
  }
4382
4382
  /**
@@ -5180,7 +5180,7 @@ class Fe {
5180
5180
  eyeLookOutRight: [null, 0],
5181
5181
  eyeContact: [0]
5182
5182
  }
5183
- })))), e > 2 * this.animFrameDur && (e = 2 * this.animFrameDur), (this.viewName !== "full" || this.isAvatarOnly) && (n = this.mtRandomized[Math.floor(Math.random() * this.mtRandomized.length)], i = this.mtAvatar[n], i.needsUpdate || Object.assign(i, { base: (this.mood.baseline[n] || 0) + (1 + l / 255) * Math.random() / 5, needsUpdate: !0 })), this.updatePoseBase(this.animClock), this.mixer && this.mixer.update(e / 1e3 * this.mixer.timeScale), this.updatePoseDelta(), (this.isSpeaking || this.isListening) && u ? l > this.volumeMax ? (this.volumeHeadBase = 0.05, Math.random() > 0.6 && (this.volumeHeadTarget = -0.05 - Math.random() / 15), this.volumeMax = l) : (this.volumeMax *= 0.92, this.volumeHeadTarget = this.volumeHeadBase - 0.9 * (this.volumeHeadBase - this.volumeHeadTarget)) : (this.volumeHeadTarget = 0, this.volumeMax = 0), n = this.volumeHeadTarget - this.volumeHeadCurrent, i = Math.abs(n), i > 1e-4 && (o = i * (this.volumeHeadEasing(Math.min(1, this.volumeHeadVelocity * e / 1e3 / i) / 2 + 0.5) - 0.5), this.volumeHeadCurrent += Math.sign(n) * Math.min(i, o)), Math.abs(this.volumeHeadCurrent) > 1e-4 && (U.setFromAxisAngle(ht, this.volumeHeadCurrent), this.objectNeck.quaternion.multiply(U)), Te.setFromObject(this.armature), this.objectLeftToeBase.getWorldPosition(le), le.sub(this.armature.position), this.objectRightToeBase.getWorldPosition(he), he.sub(this.armature.position), this.objectHips.position.y -= Te.min.y / 2, this.objectHips.position.x -= (le.x + he.x) / 4, this.objectHips.position.z -= (le.z + he.z) / 2, this.dynamicbones.update(e), this.fbxAnimationLoader && this.fbxAnimationLoader.update(), this.opt.update && this.opt.update(e), this.updateMorphTargets(e), this.isAvatarOnly)
5183
+ })))), e > 2 * this.animFrameDur && (e = 2 * this.animFrameDur), (this.viewName !== "full" || this.isAvatarOnly) && (n = this.mtRandomized[Math.floor(Math.random() * this.mtRandomized.length)], i = this.mtAvatar[n], i.needsUpdate || Object.assign(i, { base: (this.mood.baseline[n] || 0) + (1 + l / 255) * Math.random() / 5, needsUpdate: !0 })), this.updatePoseBase(this.animClock), this.mixer && this.mixer.update(e / 1e3 * this.mixer.timeScale), this.updatePoseDelta(), (this.isSpeaking || this.isListening) && u ? l > this.volumeMax ? (this.volumeHeadBase = 0.05, Math.random() > 0.6 && (this.volumeHeadTarget = -0.05 - Math.random() / 15), this.volumeMax = l) : (this.volumeMax *= 0.92, this.volumeHeadTarget = this.volumeHeadBase - 0.9 * (this.volumeHeadBase - this.volumeHeadTarget)) : (this.volumeHeadTarget = 0, this.volumeMax = 0), n = this.volumeHeadTarget - this.volumeHeadCurrent, i = Math.abs(n), i > 1e-4 && (o = i * (this.volumeHeadEasing(Math.min(1, this.volumeHeadVelocity * e / 1e3 / i) / 2 + 0.5) - 0.5), this.volumeHeadCurrent += Math.sign(n) * Math.min(i, o)), Math.abs(this.volumeHeadCurrent) > 1e-4 && (W.setFromAxisAngle(ht, this.volumeHeadCurrent), this.objectNeck.quaternion.multiply(W)), Te.setFromObject(this.armature), this.objectLeftToeBase.getWorldPosition(he), he.sub(this.armature.position), this.objectRightToeBase.getWorldPosition(ue), ue.sub(this.armature.position), this.objectHips.position.y -= Te.min.y / 2, this.objectHips.position.x -= (he.x + ue.x) / 4, this.objectHips.position.z -= (he.z + ue.z) / 2, this.dynamicbones.update(e), this.fbxAnimationLoader && this.fbxAnimationLoader.update(), this.opt.update && this.opt.update(e), this.updateMorphTargets(e), this.isAvatarOnly)
5184
5184
  this.stats && this.stats.end();
5185
5185
  else {
5186
5186
  if (this.cameraClock !== null && this.cameraClock < 1e3) {
@@ -6133,7 +6133,7 @@ class Fe {
6133
6133
  */
6134
6134
  lookAtCamera(t) {
6135
6135
  let e;
6136
- if (this.speakTo && (e = new f.Vector3(), this.speakTo.objectLeftEye?.isObject3D ? (this.speakTo.armature.objectHead, this.speakTo.objectLeftEye.updateMatrixWorld(!0), this.speakTo.objectRightEye.updateMatrixWorld(!0), le.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld), he.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld), e.addVectors(le, he).divideScalar(2)) : this.speakTo.isObject3D ? this.speakTo.getWorldPosition(e) : this.speakTo.isVector3 ? e.set(this.speakTo) : this.speakTo.x && this.speakTo.y && this.speakTo.z && e.set(this.speakTo.x, this.speakTo.y, this.speakTo.z)), !e) {
6136
+ if (this.speakTo && (e = new f.Vector3(), this.speakTo.objectLeftEye?.isObject3D ? (this.speakTo.armature.objectHead, this.speakTo.objectLeftEye.updateMatrixWorld(!0), this.speakTo.objectRightEye.updateMatrixWorld(!0), he.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld), ue.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld), e.addVectors(he, ue).divideScalar(2)) : this.speakTo.isObject3D ? this.speakTo.getWorldPosition(e) : this.speakTo.isVector3 ? e.set(this.speakTo) : this.speakTo.x && this.speakTo.y && this.speakTo.z && e.set(this.speakTo.x, this.speakTo.y, this.speakTo.z)), !e) {
6137
6137
  if (this.avatar.hasOwnProperty("avatarIgnoreCamera")) {
6138
6138
  if (this.avatar.avatarIgnoreCamera) {
6139
6139
  this.lookAhead(t);
@@ -6146,10 +6146,10 @@ class Fe {
6146
6146
  this.lookAt(null, null, t);
6147
6147
  return;
6148
6148
  }
6149
- this.objectLeftEye.updateMatrixWorld(!0), this.objectRightEye.updateMatrixWorld(!0), le.setFromMatrixPosition(this.objectLeftEye.matrixWorld), he.setFromMatrixPosition(this.objectRightEye.matrixWorld), le.add(he).divideScalar(2), U.copy(this.armature.quaternion), U.multiply(this.poseTarget.props["Hips.quaternion"]), U.multiply(this.poseTarget.props["Spine.quaternion"]), U.multiply(this.poseTarget.props["Spine1.quaternion"]), U.multiply(this.poseTarget.props["Spine2.quaternion"]), U.multiply(this.poseTarget.props["Neck.quaternion"]), U.multiply(this.poseTarget.props["Head.quaternion"]);
6150
- const n = new f.Vector3().subVectors(e, le).normalize(), i = Math.atan2(n.x, n.z), s = Math.asin(-n.y);
6149
+ this.objectLeftEye.updateMatrixWorld(!0), this.objectRightEye.updateMatrixWorld(!0), he.setFromMatrixPosition(this.objectLeftEye.matrixWorld), ue.setFromMatrixPosition(this.objectRightEye.matrixWorld), he.add(ue).divideScalar(2), W.copy(this.armature.quaternion), W.multiply(this.poseTarget.props["Hips.quaternion"]), W.multiply(this.poseTarget.props["Spine.quaternion"]), W.multiply(this.poseTarget.props["Spine1.quaternion"]), W.multiply(this.poseTarget.props["Spine2.quaternion"]), W.multiply(this.poseTarget.props["Neck.quaternion"]), W.multiply(this.poseTarget.props["Head.quaternion"]);
6150
+ const n = new f.Vector3().subVectors(e, he).normalize(), i = Math.atan2(n.x, n.z), s = Math.asin(-n.y);
6151
6151
  F.set(s, i, 0, "YXZ");
6152
- const l = new f.Quaternion().setFromEuler(F), u = new f.Quaternion().copy(l).multiply(U.clone().invert());
6152
+ const l = new f.Quaternion().setFromEuler(F), u = new f.Quaternion().copy(l).multiply(W.clone().invert());
6153
6153
  F.setFromQuaternion(u, "YXZ");
6154
6154
  let a = F.x / (40 / 24) + 0.2, h = F.y / (9 / 4), r = Math.min(0.6, Math.max(-0.3, a)), c = Math.min(0.8, Math.max(-0.8, h)), d = (Math.random() - 0.5) / 4, g = (Math.random() - 0.5) / 4;
6155
6155
  if (t) {
@@ -6186,7 +6186,7 @@ class Fe {
6186
6186
  const s = new f.Vector3().setFromMatrixPosition(this.objectLeftEye.matrixWorld), o = new f.Vector3().setFromMatrixPosition(this.objectRightEye.matrixWorld), l = new f.Vector3().addVectors(s, o).divideScalar(2);
6187
6187
  l.project(this.camera);
6188
6188
  let u = (l.x + 1) / 2 * i.width + i.left, a = -(l.y - 1) / 2 * i.height + i.top;
6189
- t === null && (t = u), e === null && (e = a), U.copy(this.armature.quaternion), U.multiply(this.poseTarget.props["Hips.quaternion"]), U.multiply(this.poseTarget.props["Spine.quaternion"]), U.multiply(this.poseTarget.props["Spine1.quaternion"]), U.multiply(this.poseTarget.props["Spine2.quaternion"]), U.multiply(this.poseTarget.props["Neck.quaternion"]), U.multiply(this.poseTarget.props["Head.quaternion"]), F.setFromQuaternion(U);
6189
+ t === null && (t = u), e === null && (e = a), W.copy(this.armature.quaternion), W.multiply(this.poseTarget.props["Hips.quaternion"]), W.multiply(this.poseTarget.props["Spine.quaternion"]), W.multiply(this.poseTarget.props["Spine1.quaternion"]), W.multiply(this.poseTarget.props["Spine2.quaternion"]), W.multiply(this.poseTarget.props["Neck.quaternion"]), W.multiply(this.poseTarget.props["Head.quaternion"]), F.setFromQuaternion(W);
6190
6190
  let h = F.x / (40 / 24), r = F.y / (9 / 4), c = Math.min(0.4, Math.max(-0.4, this.camera.rotation.x)), d = Math.min(0.4, Math.max(-0.4, this.camera.rotation.y)), g = Math.max(window.innerWidth - u, u), y = Math.max(window.innerHeight - a, a), x = this.convertRange(e, [a - y, a + y], [-0.3, 0.6]) - h + c, I = this.convertRange(t, [u - g, u + g], [-0.8, 0.8]) - r + d;
6191
6191
  x = Math.min(0.6, Math.max(-0.3, x)), I = Math.min(0.8, Math.max(-0.8, I));
6192
6192
  let D = (Math.random() - 0.5) / 4, p = (Math.random() - 0.5) / 4;
@@ -6582,7 +6582,7 @@ class Fe {
6582
6582
  const z = y[p].bone;
6583
6583
  z.matrixWorld.decompose(u, a, h), a.invert(), o.setFromMatrixPosition(g.matrixWorld), l.subVectors(o, u), l.applyQuaternion(a), l.normalize(), s.subVectors(e, u), s.applyQuaternion(a), s.normalize();
6584
6584
  let R = s.dot(l);
6585
- R > 1 ? R = 1 : R < -1 && (R = -1), R = Math.acos(R), !(R < 1e-5) && (y[p].minAngle !== void 0 && R < y[p].minAngle && (R = y[p].minAngle), y[p].maxAngle !== void 0 && R > y[p].maxAngle && (R = y[p].maxAngle), r.crossVectors(l, s), r.normalize(), U.setFromAxisAngle(r, R), z.quaternion.multiply(U), z.rotation.setFromVector3(c.setFromEuler(z.rotation).clamp(new f.Vector3(
6585
+ R > 1 ? R = 1 : R < -1 && (R = -1), R = Math.acos(R), !(R < 1e-5) && (y[p].minAngle !== void 0 && R < y[p].minAngle && (R = y[p].minAngle), y[p].maxAngle !== void 0 && R > y[p].maxAngle && (R = y[p].maxAngle), r.crossVectors(l, s), r.normalize(), W.setFromAxisAngle(r, R), z.quaternion.multiply(W), z.rotation.setFromVector3(c.setFromEuler(z.rotation).clamp(new f.Vector3(
6586
6586
  y[p].minx !== void 0 ? y[p].minx : -1 / 0,
6587
6587
  y[p].miny !== void 0 ? y[p].miny : -1 / 0,
6588
6588
  y[p].minz !== void 0 ? y[p].minz : -1 / 0
@@ -6685,26 +6685,26 @@ const Pe = Ie(({
6685
6685
  style: y = {},
6686
6686
  animations: x = {}
6687
6687
  }, I) => {
6688
- const D = G(null), p = G(null), H = G(a), z = G(null), R = G(null), T = G(!1), P = G({ remainingText: null, originalText: null, options: null }), [ee, re] = me(!0), [S, N] = me(null), [Z, X] = me(!1), [j, _] = me(!1);
6689
- pe(() => {
6688
+ const D = Z(null), p = Z(null), H = Z(a), z = Z(null), R = Z(null), T = Z(!1), P = Z({ remainingText: null, originalText: null, options: null }), [ee, le] = pe(!0), [S, N] = pe(null), [X, Y] = pe(!1), [j, _] = pe(!1);
6689
+ ge(() => {
6690
6690
  T.current = j;
6691
- }, [j]), pe(() => {
6691
+ }, [j]), ge(() => {
6692
6692
  H.current = a;
6693
6693
  }, [a]);
6694
- const te = Ae(), ce = i || te.service;
6694
+ const te = Ae(), de = i || te.service;
6695
6695
  let oe;
6696
- ce === "browser" ? oe = {
6696
+ de === "browser" ? oe = {
6697
6697
  service: "browser",
6698
6698
  endpoint: "",
6699
6699
  apiKey: null,
6700
6700
  defaultVoice: "Google US English"
6701
- } : ce === "elevenlabs" ? oe = {
6701
+ } : de === "elevenlabs" ? oe = {
6702
6702
  service: "elevenlabs",
6703
6703
  endpoint: "https://api.elevenlabs.io/v1/text-to-speech",
6704
6704
  apiKey: o || te.apiKey,
6705
6705
  defaultVoice: s || te.defaultVoice || ye.defaultVoice,
6706
6706
  voices: te.voices || ye.voices
6707
- } : ce === "deepgram" ? oe = {
6707
+ } : de === "deepgram" ? oe = {
6708
6708
  service: "deepgram",
6709
6709
  endpoint: "https://api.deepgram.com/v1/speak",
6710
6710
  apiKey: o || te.apiKey,
@@ -6715,11 +6715,11 @@ const Pe = Ie(({
6715
6715
  // Override API key if provided via props
6716
6716
  apiKey: o !== null ? o : te.apiKey
6717
6717
  };
6718
- const de = {
6718
+ const me = {
6719
6719
  url: O,
6720
6720
  body: t,
6721
6721
  avatarMood: e,
6722
- ttsLang: ce === "browser" ? "en-US" : n,
6722
+ ttsLang: de === "browser" ? "en-US" : n,
6723
6723
  ttsVoice: s || oe.defaultVoice,
6724
6724
  lipsyncLang: "en",
6725
6725
  showFullAvatar: a,
@@ -6728,29 +6728,29 @@ const Pe = Ie(({
6728
6728
  }, J = {
6729
6729
  ttsEndpoint: oe.endpoint,
6730
6730
  ttsApikey: oe.apiKey,
6731
- ttsService: ce,
6731
+ ttsService: de,
6732
6732
  lipsyncModules: ["en"],
6733
6733
  cameraView: h
6734
6734
  }, b = E(async () => {
6735
6735
  if (!(!D.current || p.current))
6736
6736
  try {
6737
- if (re(!0), N(null), p.current = new Fe(D.current, J), p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1), x && Object.keys(x).length > 0 && (p.current.customAnimations = x), await p.current.showAvatar(de, (V) => {
6738
- if (V.lengthComputable) {
6739
- const M = Math.min(100, Math.round(V.loaded / V.total * 100));
6737
+ if (le(!0), N(null), p.current = new Fe(D.current, J), p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1), x && Object.keys(x).length > 0 && (p.current.customAnimations = x), await p.current.showAvatar(me, (G) => {
6738
+ if (G.lengthComputable) {
6739
+ const M = Math.min(100, Math.round(G.loaded / G.total * 100));
6740
6740
  c(M);
6741
6741
  }
6742
- }), await new Promise((V) => {
6742
+ }), await new Promise((G) => {
6743
6743
  const M = () => {
6744
- p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? V() : setTimeout(M, 100);
6744
+ p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? G() : setTimeout(M, 100);
6745
6745
  };
6746
6746
  M();
6747
6747
  }), p.current && p.current.setShowFullAvatar)
6748
6748
  try {
6749
6749
  p.current.setShowFullAvatar(a);
6750
- } catch (V) {
6751
- console.warn("Error setting full body mode on initialization:", V);
6750
+ } catch (G) {
6751
+ console.warn("Error setting full body mode on initialization:", G);
6752
6752
  }
6753
- p.current && p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1, p.current.controls.update()), re(!1), X(!0), r(p.current);
6753
+ p.current && p.current.controls && (p.current.controls.enableRotate = !1, p.current.controls.enableZoom = !1, p.current.controls.enablePan = !1, p.current.controls.enableDamping = !1, p.current.controls.update()), le(!1), Y(!0), r(p.current);
6754
6754
  const B = () => {
6755
6755
  document.visibilityState === "visible" ? p.current?.start() : p.current?.stop();
6756
6756
  };
@@ -6758,15 +6758,15 @@ const Pe = Ie(({
6758
6758
  document.removeEventListener("visibilitychange", B);
6759
6759
  };
6760
6760
  } catch (L) {
6761
- console.error("Error initializing TalkingHead:", L), N(L.message || "Failed to initialize avatar"), re(!1), d(L);
6761
+ console.error("Error initializing TalkingHead:", L), N(L.message || "Failed to initialize avatar"), le(!1), d(L);
6762
6762
  }
6763
6763
  }, [O, t, e, n, i, s, o, a, l, u, h]);
6764
- pe(() => (b(), () => {
6764
+ ge(() => (b(), () => {
6765
6765
  p.current && (p.current.stop(), p.current.dispose(), p.current = null);
6766
- }), [b]), pe(() => {
6766
+ }), [b]), ge(() => {
6767
6767
  if (!D.current || !p.current) return;
6768
- const L = new ResizeObserver((V) => {
6769
- for (const M of V)
6768
+ const L = new ResizeObserver((G) => {
6769
+ for (const M of G)
6770
6770
  p.current && p.current.onResize && p.current.onResize();
6771
6771
  });
6772
6772
  L.observe(D.current);
@@ -6776,7 +6776,7 @@ const Pe = Ie(({
6776
6776
  return window.addEventListener("resize", B), () => {
6777
6777
  L.disconnect(), window.removeEventListener("resize", B);
6778
6778
  };
6779
- }, [Z]);
6779
+ }, [X]);
6780
6780
  const v = E(async () => {
6781
6781
  if (p.current && p.current.audioCtx)
6782
6782
  try {
@@ -6785,23 +6785,23 @@ const Pe = Ie(({
6785
6785
  console.warn("Failed to resume audio context:", L);
6786
6786
  }
6787
6787
  }, []), w = E(async (L, B = {}) => {
6788
- if (p.current && Z)
6788
+ if (p.current && X)
6789
6789
  try {
6790
6790
  R.current && (clearInterval(R.current), R.current = null), z.current = { text: L, options: B }, P.current = { remainingText: null, originalText: null, options: null }, _(!1), T.current = !1, await v();
6791
- const V = {
6791
+ const G = {
6792
6792
  ...B,
6793
- lipsyncLang: B.lipsyncLang || de.lipsyncLang || "en"
6793
+ lipsyncLang: B.lipsyncLang || me.lipsyncLang || "en"
6794
6794
  };
6795
6795
  if (B.onSpeechEnd && p.current) {
6796
6796
  const M = p.current;
6797
- let Y = null, ge = 0;
6797
+ let U = null, se = 0;
6798
6798
  const ke = 1200;
6799
6799
  let xe = !1;
6800
- Y = setInterval(() => {
6801
- if (ge++, T.current)
6800
+ U = setInterval(() => {
6801
+ if (se++, T.current)
6802
6802
  return;
6803
- if (ge > ke) {
6804
- if (Y && (clearInterval(Y), Y = null, R.current = null), !xe && !T.current) {
6803
+ if (se > ke) {
6804
+ if (U && (clearInterval(U), U = null, R.current = null), !xe && !T.current) {
6805
6805
  xe = !0;
6806
6806
  try {
6807
6807
  B.onSpeechEnd();
@@ -6814,7 +6814,7 @@ const Pe = Ie(({
6814
6814
  const Oe = !M.speechQueue || M.speechQueue.length === 0, Ne = !M.audioPlaylist || M.audioPlaylist.length === 0;
6815
6815
  M && M.isSpeaking === !1 && Oe && Ne && M.isAudioPlaying === !1 && !xe && !T.current && setTimeout(() => {
6816
6816
  if (M && !T.current && M.isSpeaking === !1 && (!M.speechQueue || M.speechQueue.length === 0) && (!M.audioPlaylist || M.audioPlaylist.length === 0) && M.isAudioPlaying === !1 && !xe && !T.current) {
6817
- xe = !0, Y && (clearInterval(Y), Y = null, R.current = null);
6817
+ xe = !0, U && (clearInterval(U), U = null, R.current = null);
6818
6818
  try {
6819
6819
  B.onSpeechEnd();
6820
6820
  } catch (Ue) {
@@ -6822,28 +6822,28 @@ const Pe = Ie(({
6822
6822
  }
6823
6823
  }
6824
6824
  }, 100);
6825
- }, 100), R.current = Y;
6825
+ }, 100), R.current = U;
6826
6826
  }
6827
- p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, V)) : setTimeout(async () => {
6828
- await v(), p.current && p.current.lipsync && (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, V));
6827
+ p.current.lipsync && Object.keys(p.current.lipsync).length > 0 ? (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, G)) : setTimeout(async () => {
6828
+ await v(), p.current && p.current.lipsync && (p.current.setSlowdownRate && p.current.setSlowdownRate(1.05), p.current.speakText(L, G));
6829
6829
  }, 100);
6830
- } catch (V) {
6831
- console.error("Error speaking text:", V), N(V.message || "Failed to speak text");
6830
+ } catch (G) {
6831
+ console.error("Error speaking text:", G), N(G.message || "Failed to speak text");
6832
6832
  }
6833
- }, [Z, v, de.lipsyncLang]), C = E(() => {
6833
+ }, [X, v, me.lipsyncLang]), C = E(() => {
6834
6834
  p.current && (p.current.stopSpeaking(), p.current.setSlowdownRate && p.current.setSlowdownRate(1), z.current = null, _(!1));
6835
- }, []), W = E(() => {
6835
+ }, []), V = E(() => {
6836
6836
  if (p.current && p.current.pauseSpeaking) {
6837
6837
  const L = p.current;
6838
6838
  if (L.isSpeaking || L.audioPlaylist && L.audioPlaylist.length > 0 || L.speechQueue && L.speechQueue.length > 0) {
6839
6839
  R.current && (clearInterval(R.current), R.current = null);
6840
- let V = "";
6840
+ let G = "";
6841
6841
  if (L.speechQueue && L.speechQueue.length > 0 && z.current) {
6842
- const M = L.speechQueue.filter((Y) => Y && Y.text).map((Y) => Y.text).join(" ");
6843
- M && M.trim() && (V = M.trim());
6842
+ const M = L.speechQueue.filter((U) => U && U.text && Array.isArray(U.text) && U.text.length > 0).map((U) => U.text.map((se) => se.word || "").filter((se) => se.length > 0).join(" ")).filter((U) => U.length > 0).join(" ");
6843
+ M && M.trim() && (G = M.trim());
6844
6844
  }
6845
6845
  z.current && (P.current = {
6846
- remainingText: V || null,
6846
+ remainingText: G || null,
6847
6847
  originalText: z.current.text,
6848
6848
  options: z.current.options
6849
6849
  }), L.speechQueue && (L.speechQueue.length = 0), p.current.pauseSpeaking(), T.current = !0, _(!0);
@@ -6862,16 +6862,16 @@ const Pe = Ie(({
6862
6862
  return;
6863
6863
  }
6864
6864
  _(!1), T.current = !1, await v();
6865
- const V = {
6865
+ const G = {
6866
6866
  ...B,
6867
- lipsyncLang: B.lipsyncLang || de.lipsyncLang || "en"
6867
+ lipsyncLang: B.lipsyncLang || me.lipsyncLang || "en"
6868
6868
  };
6869
6869
  try {
6870
- await w(L, V);
6870
+ await w(L, G);
6871
6871
  } catch (M) {
6872
6872
  console.error("Error resuming speech:", M), _(!1), T.current = !1;
6873
6873
  }
6874
- }, [v, j, w, de]), ie = E((L) => {
6874
+ }, [v, j, w, me]), ie = E((L) => {
6875
6875
  p.current && p.current.setMood(L);
6876
6876
  }, []), fe = E((L) => {
6877
6877
  p.current && p.current.setSlowdownRate && p.current.setSlowdownRate(L);
@@ -6890,25 +6890,25 @@ const Pe = Ie(({
6890
6890
  console.warn(`Failed to play ${L}:`, M);
6891
6891
  try {
6892
6892
  p.current.setBodyMovement("idle");
6893
- } catch (Y) {
6894
- console.warn("Fallback animation also failed:", Y);
6893
+ } catch (U) {
6894
+ console.warn("Fallback animation also failed:", U);
6895
6895
  }
6896
6896
  }
6897
6897
  else {
6898
6898
  const M = [".fbx", ".glb", ".gltf"];
6899
- let Y = !1;
6900
- for (const ge of M)
6899
+ let U = !1;
6900
+ for (const se of M)
6901
6901
  try {
6902
- p.current.playAnimation(L + ge, null, 10, 0, 0.01, B), Y = !0;
6902
+ p.current.playAnimation(L + se, null, 10, 0, 0.01, B), U = !0;
6903
6903
  break;
6904
6904
  } catch {
6905
6905
  }
6906
- if (!Y) {
6906
+ if (!U) {
6907
6907
  console.warn("Animation not found:", L);
6908
6908
  try {
6909
6909
  p.current.setBodyMovement("idle");
6910
- } catch (ge) {
6911
- console.warn("Fallback animation also failed:", ge);
6910
+ } catch (se) {
6911
+ console.warn("Fallback animation also failed:", se);
6912
6912
  }
6913
6913
  }
6914
6914
  }
@@ -6919,13 +6919,13 @@ const Pe = Ie(({
6919
6919
  return Le(I, () => ({
6920
6920
  speakText: w,
6921
6921
  stopSpeaking: C,
6922
- pauseSpeaking: W,
6922
+ pauseSpeaking: V,
6923
6923
  resumeSpeaking: ne,
6924
6924
  resumeAudioContext: v,
6925
6925
  setMood: ie,
6926
6926
  setTimingAdjustment: fe,
6927
6927
  playAnimation: Se,
6928
- isReady: Z,
6928
+ isReady: X,
6929
6929
  isPaused: j,
6930
6930
  talkingHead: p.current,
6931
6931
  handleResize: De,
@@ -6997,7 +6997,7 @@ const Pe = Ie(({
6997
6997
  ...y
6998
6998
  },
6999
6999
  children: [
7000
- /* @__PURE__ */ ue(
7000
+ /* @__PURE__ */ ce(
7001
7001
  "div",
7002
7002
  {
7003
7003
  ref: D,
@@ -7009,7 +7009,7 @@ const Pe = Ie(({
7009
7009
  }
7010
7010
  }
7011
7011
  ),
7012
- ee && /* @__PURE__ */ ue("div", { className: "loading-overlay", style: {
7012
+ ee && /* @__PURE__ */ ce("div", { className: "loading-overlay", style: {
7013
7013
  position: "absolute",
7014
7014
  top: "50%",
7015
7015
  left: "50%",
@@ -7018,7 +7018,7 @@ const Pe = Ie(({
7018
7018
  fontSize: "18px",
7019
7019
  zIndex: 10
7020
7020
  }, children: "Loading avatar..." }),
7021
- S && /* @__PURE__ */ ue("div", { className: "error-overlay", style: {
7021
+ S && /* @__PURE__ */ ce("div", { className: "error-overlay", style: {
7022
7022
  position: "absolute",
7023
7023
  top: "50%",
7024
7024
  left: "50%",
@@ -7047,7 +7047,7 @@ const ut = Ie(({
7047
7047
  style: s = {},
7048
7048
  avatarConfig: o = {}
7049
7049
  }, l) => {
7050
- const u = G(null), a = G(null), [h, r] = me(!0), [c, d] = me(null), [g, y] = me(!1), x = Ae(), I = o.ttsService || x.service, D = I === "browser" ? {
7050
+ const u = Z(null), a = Z(null), [h, r] = pe(!0), [c, d] = pe(null), [g, y] = pe(!1), x = Ae(), I = o.ttsService || x.service, D = I === "browser" ? {
7051
7051
  endpoint: "",
7052
7052
  apiKey: null,
7053
7053
  defaultVoice: "Google US English"
@@ -7080,27 +7080,27 @@ const ut = Ie(({
7080
7080
  }, z = E(async () => {
7081
7081
  if (!(!u.current || a.current))
7082
7082
  try {
7083
- if (r(!0), d(null), a.current = new Fe(u.current, H), await a.current.showAvatar(p, (Z) => {
7084
- if (Z.lengthComputable) {
7085
- const X = Math.min(100, Math.round(Z.loaded / Z.total * 100));
7086
- t(X);
7083
+ if (r(!0), d(null), a.current = new Fe(u.current, H), await a.current.showAvatar(p, (X) => {
7084
+ if (X.lengthComputable) {
7085
+ const Y = Math.min(100, Math.round(X.loaded / X.total * 100));
7086
+ t(Y);
7087
7087
  }
7088
7088
  }), a.current.morphs && a.current.morphs.length > 0) {
7089
- const Z = a.current.morphs[0].morphTargetDictionary;
7090
- console.log("Available morph targets:", Object.keys(Z));
7091
- const X = Object.keys(Z).filter((j) => j.startsWith("viseme_"));
7092
- console.log("Viseme morph targets found:", X), X.length === 0 && (console.warn("No viseme morph targets found! Lip-sync will not work properly."), console.log("Expected viseme targets: viseme_aa, viseme_E, viseme_I, viseme_O, viseme_U, viseme_PP, viseme_SS, viseme_TH, viseme_DD, viseme_FF, viseme_kk, viseme_nn, viseme_RR, viseme_CH, viseme_sil"));
7089
+ const X = a.current.morphs[0].morphTargetDictionary;
7090
+ console.log("Available morph targets:", Object.keys(X));
7091
+ const Y = Object.keys(X).filter((j) => j.startsWith("viseme_"));
7092
+ console.log("Viseme morph targets found:", Y), Y.length === 0 && (console.warn("No viseme morph targets found! Lip-sync will not work properly."), console.log("Expected viseme targets: viseme_aa, viseme_E, viseme_I, viseme_O, viseme_U, viseme_PP, viseme_SS, viseme_TH, viseme_DD, viseme_FF, viseme_kk, viseme_nn, viseme_RR, viseme_CH, viseme_sil"));
7093
7093
  }
7094
- if (await new Promise((Z) => {
7095
- const X = () => {
7096
- a.current.lipsync && Object.keys(a.current.lipsync).length > 0 ? (console.log("Lip-sync modules loaded:", Object.keys(a.current.lipsync)), Z()) : (console.log("Waiting for lip-sync modules to load..."), setTimeout(X, 100));
7094
+ if (await new Promise((X) => {
7095
+ const Y = () => {
7096
+ a.current.lipsync && Object.keys(a.current.lipsync).length > 0 ? (console.log("Lip-sync modules loaded:", Object.keys(a.current.lipsync)), X()) : (console.log("Waiting for lip-sync modules to load..."), setTimeout(Y, 100));
7097
7097
  };
7098
- X();
7098
+ Y();
7099
7099
  }), a.current && a.current.setShowFullAvatar)
7100
7100
  try {
7101
7101
  a.current.setShowFullAvatar(!0), console.log("Avatar initialized in full body mode");
7102
- } catch (Z) {
7103
- console.warn("Error setting full body mode on initialization:", Z);
7102
+ } catch (X) {
7103
+ console.warn("Error setting full body mode on initialization:", X);
7104
7104
  }
7105
7105
  r(!1), y(!0), n(a.current);
7106
7106
  const N = () => {
@@ -7113,7 +7113,7 @@ const ut = Ie(({
7113
7113
  console.error("Error initializing TalkingHead:", S), d(S.message || "Failed to initialize avatar"), r(!1), e(S);
7114
7114
  }
7115
7115
  }, []);
7116
- pe(() => (z(), () => {
7116
+ ge(() => (z(), () => {
7117
7117
  a.current && (a.current.stop(), a.current.dispose(), a.current = null);
7118
7118
  }), [z]);
7119
7119
  const R = E((S) => {
@@ -7133,19 +7133,19 @@ const ut = Ie(({
7133
7133
  a.current && a.current.setMood(S);
7134
7134
  }, []), ee = E((S) => {
7135
7135
  a.current && a.current.setSlowdownRate && (a.current.setSlowdownRate(S), console.log("Timing adjustment set to:", S));
7136
- }, []), re = E((S, N = !1) => {
7136
+ }, []), le = E((S, N = !1) => {
7137
7137
  if (a.current && a.current.playAnimation) {
7138
7138
  if (a.current.setShowFullAvatar)
7139
7139
  try {
7140
7140
  a.current.setShowFullAvatar(!0);
7141
- } catch (X) {
7142
- console.warn("Error setting full body mode:", X);
7141
+ } catch (Y) {
7142
+ console.warn("Error setting full body mode:", Y);
7143
7143
  }
7144
7144
  if (S.includes("."))
7145
7145
  try {
7146
7146
  a.current.playAnimation(S, null, 10, 0, 0.01, N), console.log("Playing animation:", S);
7147
- } catch (X) {
7148
- console.log(`Failed to play ${S}:`, X);
7147
+ } catch (Y) {
7148
+ console.log(`Failed to play ${S}:`, Y);
7149
7149
  try {
7150
7150
  a.current.setBodyMovement("idle"), console.log("Fallback to idle animation");
7151
7151
  } catch (j) {
@@ -7153,9 +7153,9 @@ const ut = Ie(({
7153
7153
  }
7154
7154
  }
7155
7155
  else {
7156
- const X = [".fbx", ".glb", ".gltf"];
7156
+ const Y = [".fbx", ".glb", ".gltf"];
7157
7157
  let j = !1;
7158
- for (const _ of X)
7158
+ for (const _ of Y)
7159
7159
  try {
7160
7160
  a.current.playAnimation(S + _, null, 10, 0, 0.01, N), console.log("Playing animation:", S + _), j = !0;
7161
7161
  break;
@@ -7179,7 +7179,7 @@ const ut = Ie(({
7179
7179
  stopSpeaking: T,
7180
7180
  setMood: P,
7181
7181
  setTimingAdjustment: ee,
7182
- playAnimation: re,
7182
+ playAnimation: le,
7183
7183
  isReady: g,
7184
7184
  talkingHead: a.current,
7185
7185
  setBodyMovement: (S) => {
@@ -7240,7 +7240,7 @@ const ut = Ie(({
7240
7240
  }
7241
7241
  }
7242
7242
  })), /* @__PURE__ */ Ee("div", { className: `talking-head-container ${i}`, style: s, children: [
7243
- /* @__PURE__ */ ue(
7243
+ /* @__PURE__ */ ce(
7244
7244
  "div",
7245
7245
  {
7246
7246
  ref: u,
@@ -7252,7 +7252,7 @@ const ut = Ie(({
7252
7252
  }
7253
7253
  }
7254
7254
  ),
7255
- h && /* @__PURE__ */ ue("div", { className: "loading-overlay", style: {
7255
+ h && /* @__PURE__ */ ce("div", { className: "loading-overlay", style: {
7256
7256
  position: "absolute",
7257
7257
  top: "50%",
7258
7258
  left: "50%",
@@ -7261,7 +7261,7 @@ const ut = Ie(({
7261
7261
  fontSize: "18px",
7262
7262
  zIndex: 10
7263
7263
  }, children: "Loading avatar..." }),
7264
- c && /* @__PURE__ */ ue("div", { className: "error-overlay", style: {
7264
+ c && /* @__PURE__ */ ce("div", { className: "error-overlay", style: {
7265
7265
  position: "absolute",
7266
7266
  top: "50%",
7267
7267
  left: "50%",
@@ -7292,7 +7292,7 @@ const ct = Ie(({
7292
7292
  },
7293
7293
  autoStart: u = !1
7294
7294
  }, a) => {
7295
- const h = G(null), r = G({
7295
+ const h = Z(null), r = Z({
7296
7296
  currentModuleIndex: 0,
7297
7297
  currentLessonIndex: 0,
7298
7298
  currentQuestionIndex: 0,
@@ -7302,18 +7302,18 @@ const ct = Ie(({
7302
7302
  curriculumCompleted: !1,
7303
7303
  score: 0,
7304
7304
  totalQuestions: 0
7305
- }), c = G({
7305
+ }), c = Z({
7306
7306
  onLessonStart: n,
7307
7307
  onLessonComplete: i,
7308
7308
  onQuestionAnswer: s,
7309
7309
  onCurriculumComplete: o,
7310
7310
  onCustomAction: l
7311
- }), d = G(null), g = G(null), y = G(null), x = G(null), I = G(null), D = G(null), p = G(null), H = G(O?.curriculum || {
7311
+ }), d = Z(null), g = Z(null), y = Z(null), x = Z(null), I = Z(null), D = Z(null), p = Z(null), H = Z(O?.curriculum || {
7312
7312
  title: "Default Curriculum",
7313
7313
  description: "No curriculum data provided",
7314
7314
  language: "en",
7315
7315
  modules: []
7316
- }), z = G({
7316
+ }), z = Z({
7317
7317
  avatarUrl: t.avatarUrl || "/avatars/brunette.glb",
7318
7318
  avatarBody: t.avatarBody || "F",
7319
7319
  mood: t.mood || "happy",
@@ -7327,7 +7327,7 @@ const ct = Ie(({
7327
7327
  animations: e,
7328
7328
  lipsyncLang: "en"
7329
7329
  });
7330
- pe(() => {
7330
+ ge(() => {
7331
7331
  c.current = {
7332
7332
  onLessonStart: n,
7333
7333
  onLessonComplete: i,
@@ -7335,7 +7335,7 @@ const ct = Ie(({
7335
7335
  onCurriculumComplete: o,
7336
7336
  onCustomAction: l
7337
7337
  };
7338
- }, [n, i, s, o, l]), pe(() => {
7338
+ }, [n, i, s, o, l]), ge(() => {
7339
7339
  H.current = O?.curriculum || {
7340
7340
  title: "Default Curriculum",
7341
7341
  description: "No curriculum data provided",
@@ -7380,7 +7380,7 @@ const ct = Ie(({
7380
7380
  } catch {
7381
7381
  h.current.playCelebration();
7382
7382
  }
7383
- const w = H.current || { modules: [] }, C = w.modules[r.current.currentModuleIndex], W = r.current.currentLessonIndex < (C?.lessons?.length || 0) - 1, ne = r.current.currentModuleIndex < (w.modules?.length || 0) - 1, ie = W || ne, fe = z.current || { lipsyncLang: "en" };
7383
+ const w = H.current || { modules: [] }, C = w.modules[r.current.currentModuleIndex], V = r.current.currentLessonIndex < (C?.lessons?.length || 0) - 1, ne = r.current.currentModuleIndex < (w.modules?.length || 0) - 1, ie = V || ne, fe = z.current || { lipsyncLang: "en" };
7384
7384
  h.current.speakText(v, {
7385
7385
  lipsyncLang: fe.lipsyncLang,
7386
7386
  onSpeechEnd: () => {
@@ -7396,7 +7396,7 @@ const ct = Ie(({
7396
7396
  }
7397
7397
  });
7398
7398
  }
7399
- }, [e.lessonComplete]), re = E(() => {
7399
+ }, [e.lessonComplete]), le = E(() => {
7400
7400
  r.current.curriculumCompleted = !0;
7401
7401
  const b = H.current || { modules: [] };
7402
7402
  if (c.current.onCurriculumComplete({
@@ -7430,8 +7430,8 @@ const ct = Ie(({
7430
7430
  if (h.current.setMood("happy"), e.questionStart)
7431
7431
  try {
7432
7432
  h.current.playAnimation(e.questionStart, !0);
7433
- } catch (W) {
7434
- console.warn("Failed to play questionStart animation:", W);
7433
+ } catch (V) {
7434
+ console.warn("Failed to play questionStart animation:", V);
7435
7435
  }
7436
7436
  const C = z.current || { lipsyncLang: "en" };
7437
7437
  v.type === "code_test" ? h.current.speakText(`Let's test your coding skills! Here's your first challenge: ${v.question}`, { lipsyncLang: C.lipsyncLang }) : v.type === "multiple_choice" ? h.current.speakText(`Now let me ask you some questions. Here's the first one: ${v.question}`, { lipsyncLang: C.lipsyncLang }) : v.type === "true_false" ? h.current.speakText(`Let's start with some true or false questions. First question: ${v.question}`, { lipsyncLang: C.lipsyncLang }) : h.current.speakText(`Now let me ask you some questions. Here's the first one: ${v.question}`, { lipsyncLang: C.lipsyncLang });
@@ -7468,8 +7468,8 @@ const ct = Ie(({
7468
7468
  if (h.current.setMood("happy"), h.current.setBodyMovement("idle"), e.nextQuestion)
7469
7469
  try {
7470
7470
  h.current.playAnimation(e.nextQuestion, !0);
7471
- } catch (W) {
7472
- console.warn("Failed to play nextQuestion animation:", W);
7471
+ } catch (V) {
7472
+ console.warn("Failed to play nextQuestion animation:", V);
7473
7473
  }
7474
7474
  const C = z.current || { lipsyncLang: "en" };
7475
7475
  v.type === "code_test" ? h.current.speakText(`Great! Now let's move on to your next coding challenge: ${v.question}`, {
@@ -7500,11 +7500,11 @@ const ct = Ie(({
7500
7500
  totalQuestions: r.current.totalQuestions,
7501
7501
  score: r.current.score
7502
7502
  });
7503
- }, [e.nextQuestion, R, T]), Z = E(() => {
7503
+ }, [e.nextQuestion, R, T]), X = E(() => {
7504
7504
  const b = H.current || { modules: [] }, v = b.modules[r.current.currentModuleIndex];
7505
7505
  if (r.current.currentLessonIndex < (v?.lessons?.length || 0) - 1) {
7506
7506
  r.current.currentLessonIndex += 1, r.current.currentQuestionIndex = 0, r.current.lessonCompleted = !1, r.current.isQuestionMode = !1, r.current.isTeaching = !1, r.current.score = 0, r.current.totalQuestions = 0;
7507
- const C = b.modules[r.current.currentModuleIndex], W = r.current.currentLessonIndex < (C?.lessons?.length || 0) - 1, ne = r.current.currentModuleIndex < (b.modules?.length || 0) - 1, ie = W || ne;
7507
+ const C = b.modules[r.current.currentModuleIndex], V = r.current.currentLessonIndex < (C?.lessons?.length || 0) - 1, ne = r.current.currentModuleIndex < (b.modules?.length || 0) - 1, ie = V || ne;
7508
7508
  c.current.onCustomAction({
7509
7509
  type: "lessonStart",
7510
7510
  moduleIndex: r.current.currentModuleIndex,
@@ -7517,7 +7517,7 @@ const ct = Ie(({
7517
7517
  }), h.current && (h.current.setMood("happy"), h.current.setBodyMovement("idle"));
7518
7518
  } else if (r.current.currentModuleIndex < (b.modules?.length || 0) - 1) {
7519
7519
  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;
7520
- const W = b.modules[r.current.currentModuleIndex], ne = r.current.currentLessonIndex < (W?.lessons?.length || 0) - 1, ie = r.current.currentModuleIndex < (b.modules?.length || 0) - 1, fe = ne || ie;
7520
+ const V = b.modules[r.current.currentModuleIndex], ne = r.current.currentLessonIndex < (V?.lessons?.length || 0) - 1, ie = r.current.currentModuleIndex < (b.modules?.length || 0) - 1, fe = ne || ie;
7521
7521
  c.current.onCustomAction({
7522
7522
  type: "lessonStart",
7523
7523
  moduleIndex: r.current.currentModuleIndex,
@@ -7530,12 +7530,12 @@ const ct = Ie(({
7530
7530
  }), h.current && (h.current.setMood("happy"), h.current.setBodyMovement("idle"));
7531
7531
  } else
7532
7532
  I.current && I.current();
7533
- }, []), X = E(() => {
7533
+ }, []), Y = E(() => {
7534
7534
  const b = R();
7535
7535
  let v = null;
7536
7536
  if (b?.avatar_script && b?.body) {
7537
- const w = b.avatar_script.trim(), C = b.body.trim(), W = w.match(/[.!?]$/) ? " " : ". ";
7538
- v = `${w}${W}${C}`;
7537
+ const w = b.avatar_script.trim(), C = b.body.trim(), V = w.match(/[.!?]$/) ? " " : ". ";
7538
+ v = `${w}${V}${C}`;
7539
7539
  } else
7540
7540
  v = b?.avatar_script || b?.body || null;
7541
7541
  if (h.current && h.current.isReady && v) {
@@ -7544,8 +7544,8 @@ const ct = Ie(({
7544
7544
  if (e.teaching)
7545
7545
  try {
7546
7546
  h.current.playAnimation(e.teaching, !0), w = !0;
7547
- } catch (W) {
7548
- console.warn("Failed to play teaching animation:", W);
7547
+ } catch (V) {
7548
+ console.warn("Failed to play teaching animation:", V);
7549
7549
  }
7550
7550
  w || h.current.setBodyMovement("gesturing");
7551
7551
  const C = z.current || { lipsyncLang: "en" };
@@ -7589,9 +7589,9 @@ const ct = Ie(({
7589
7589
  h.current.setBodyMovement("happy");
7590
7590
  }
7591
7591
  h.current.setBodyMovement("gesturing");
7592
- const C = v.type === "code_test" ? `Great job! Your code passed all the tests! ${v.explanation || ""}` : `Excellent! That's correct! ${v.explanation || ""}`, W = z.current || { lipsyncLang: "en" };
7592
+ const C = v.type === "code_test" ? `Great job! Your code passed all the tests! ${v.explanation || ""}` : `Excellent! That's correct! ${v.explanation || ""}`, V = z.current || { lipsyncLang: "en" };
7593
7593
  h.current.speakText(C, {
7594
- lipsyncLang: W.lipsyncLang,
7594
+ lipsyncLang: V.lipsyncLang,
7595
7595
  onSpeechEnd: () => {
7596
7596
  const ie = R()?.questions?.length || 0;
7597
7597
  c.current.onCustomAction({
@@ -7614,9 +7614,9 @@ const ct = Ie(({
7614
7614
  h.current.setBodyMovement("idle");
7615
7615
  }
7616
7616
  h.current.setBodyMovement("gesturing");
7617
- const C = 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 || ""} Let's move on to the next question.`, W = z.current || { lipsyncLang: "en" };
7617
+ const C = 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 || ""} Let's move on to the next question.`, V = z.current || { lipsyncLang: "en" };
7618
7618
  h.current.speakText(C, {
7619
- lipsyncLang: W.lipsyncLang,
7619
+ lipsyncLang: V.lipsyncLang,
7620
7620
  onSpeechEnd: () => {
7621
7621
  const ie = R()?.questions?.length || 0;
7622
7622
  c.current.onCustomAction({
@@ -7633,14 +7633,14 @@ const ct = Ie(({
7633
7633
  });
7634
7634
  }
7635
7635
  else {
7636
- const W = R()?.questions?.length || 0;
7636
+ const V = R()?.questions?.length || 0;
7637
7637
  c.current.onCustomAction({
7638
7638
  type: "answerFeedbackComplete",
7639
7639
  moduleIndex: r.current.currentModuleIndex,
7640
7640
  lessonIndex: r.current.currentLessonIndex,
7641
7641
  questionIndex: r.current.currentQuestionIndex,
7642
7642
  isCorrect: w,
7643
- hasNextQuestion: r.current.currentQuestionIndex < W - 1,
7643
+ hasNextQuestion: r.current.currentQuestionIndex < V - 1,
7644
7644
  score: r.current.score,
7645
7645
  totalQuestions: r.current.totalQuestions,
7646
7646
  avatarNotReady: !0
@@ -7708,7 +7708,7 @@ const ct = Ie(({
7708
7708
  }, 5e3);
7709
7709
  }
7710
7710
  }
7711
- }, [T]), ce = E(() => {
7711
+ }, [T]), de = E(() => {
7712
7712
  const b = H.current || { modules: [] };
7713
7713
  if (b.modules[r.current.currentModuleIndex], r.current.currentLessonIndex > 0)
7714
7714
  r.current.currentLessonIndex -= 1, r.current.currentQuestionIndex = 0, r.current.lessonCompleted = !1, r.current.isQuestionMode = !1, r.current.isTeaching = !1, r.current.score = 0, r.current.totalQuestions = 0, c.current.onCustomAction({
@@ -7734,7 +7734,7 @@ const ct = Ie(({
7734
7734
  }
7735
7735
  }, [R]), oe = E(() => {
7736
7736
  r.current.currentModuleIndex = 0, r.current.currentLessonIndex = 0, r.current.currentQuestionIndex = 0, r.current.isTeaching = !1, r.current.isQuestionMode = !1, r.current.lessonCompleted = !1, r.current.curriculumCompleted = !1, r.current.score = 0, r.current.totalQuestions = 0;
7737
- }, []), de = E((b) => {
7737
+ }, []), me = E((b) => {
7738
7738
  console.log("Avatar is ready!", b);
7739
7739
  const v = R(), w = v?.avatar_script || v?.body;
7740
7740
  u && w && setTimeout(() => {
@@ -7742,19 +7742,19 @@ const ct = Ie(({
7742
7742
  }, 10);
7743
7743
  }, [u, R]);
7744
7744
  We(() => {
7745
- d.current = X, g.current = Z, y.current = ee, x.current = N, I.current = re, D.current = S, p.current = j;
7745
+ d.current = Y, g.current = X, y.current = ee, x.current = N, I.current = le, D.current = S, p.current = j;
7746
7746
  }), Le(a, () => ({
7747
7747
  // Curriculum control methods
7748
- startTeaching: X,
7748
+ startTeaching: Y,
7749
7749
  startQuestions: S,
7750
7750
  handleAnswerSelect: j,
7751
7751
  handleCodeTestResult: _,
7752
7752
  nextQuestion: N,
7753
7753
  previousQuestion: te,
7754
- nextLesson: Z,
7755
- previousLesson: ce,
7754
+ nextLesson: X,
7755
+ previousLesson: de,
7756
7756
  completeLesson: ee,
7757
- completeCurriculum: re,
7757
+ completeCurriculum: le,
7758
7758
  resetCurriculum: oe,
7759
7759
  getState: () => ({ ...r.current }),
7760
7760
  getCurrentQuestion: () => T(),
@@ -7809,7 +7809,7 @@ const ct = Ie(({
7809
7809
  handleResize: () => h.current?.handleResize(),
7810
7810
  // Avatar readiness check (always returns current value)
7811
7811
  isAvatarReady: () => h.current?.isReady || !1
7812
- }), [X, S, j, _, N, Z, ee, re, oe, T, R]);
7812
+ }), [Y, S, j, _, N, X, ee, le, oe, T, R]);
7813
7813
  const J = z.current || {
7814
7814
  avatarUrl: "/avatars/brunette.glb",
7815
7815
  avatarBody: "F",
@@ -7823,7 +7823,7 @@ const ct = Ie(({
7823
7823
  showFullAvatar: !1,
7824
7824
  animations: e
7825
7825
  };
7826
- return /* @__PURE__ */ ue("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ ue(
7826
+ return /* @__PURE__ */ ce("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ ce(
7827
7827
  Pe,
7828
7828
  {
7829
7829
  ref: h,
@@ -7839,7 +7839,7 @@ const ct = Ie(({
7839
7839
  showFullAvatar: J.showFullAvatar,
7840
7840
  cameraView: "upper",
7841
7841
  animations: J.animations,
7842
- onReady: de,
7842
+ onReady: me,
7843
7843
  onLoading: () => {
7844
7844
  },
7845
7845
  onError: (b) => {