@sage-rsc/talking-head-react 1.4.2 → 1.4.3
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.cjs +1 -1
- package/dist/index.js +3 -2
- package/package.json +1 -1
- package/src/lib/talkinghead.mjs +7 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=require("react/jsx-runtime"),x=require("react"),Ve=require("three"),Ze=require("three/addons/controls/OrbitControls.js"),Xe=require("three/addons/loaders/GLTFLoader.js"),je=require("three/addons/loaders/DRACOLoader.js"),Oe=require("three/addons/loaders/FBXLoader.js"),Ye=require("three/addons/environments/RoomEnvironment.js"),Qe=require("three/addons/libs/stats.module.js");var He=typeof document<"u"?document.currentScript:null;function qe(B){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(B){for(const e in B)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(B,e);Object.defineProperty(n,e,t.get?t:{enumerable:!0,get:()=>B[e]})}}return n.default=B,Object.freeze(n)}const g=qe(Ve);let c,re,he;const z=[0,0,0,0],F=new g.Vector3,ke=new g.Vector3,oe=new g.Vector3,Ce=new g.Vector3;new g.Plane;new g.Ray;new g.Euler;const se=new g.Quaternion,Ne=new g.Quaternion,pe=new g.Matrix4,ge=new g.Matrix4;new g.Vector3;const we=new g.Vector3(0,0,1),_e=new g.Vector3(1,0,0),Ke=new g.Vector3(0,1,0),Je=new g.Vector3(0,0,1);class $e{constructor(n=null){this.opt=Object.assign({warmupMs:2e3,sensitivityFactor:1,movementFactor:1,isExcludes:!0,isPivots:!0,isLimits:!0,helperBoneColor1:16711680,helperBoneColor2:16238028,helperLinkColor1:16711680,helperLinkColor2:255,helperExcludesColor:11184895},n||{}),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.helpers={isActive:!1,isShowAll:!1,points:{bones:[],pivots:[],object:null},lines:{bones:[],object:null},excludes:{bones:[],deltaLocals:[],radii:[],objects:[]}},this.running=!1,this.timerMs=0}getOptionValue(n){return this.opt[n]}setOptionValue(n,e){this.opt[n]=e,this.helpers.isActive&&this.showHelpers()}getBoneNames(){return this.data.map(n=>n.name)}getValue(n,e){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(n))throw new Error("Dynamic bone '"+n+"' not found.");const t=this.dict[n];let i;if(e==="type")i=t.type;else if(e==="stiffness")i=t.k.every(s=>s===t.k[0])?t.k[0]:[...t.k];else if(e==="damping")i=t.c.every(s=>s===t.c[0])?t.c[0]:[...t.c];else if(e==="external")i=t.ext<1?t.ext:null;else if(e==="limits")i=t.limits?.map(s=>s===null?null:[...s]);else if(e==="deltaLocal")i=t.dl?[...t.dl]:null;else if(e==="excludes")i=t.excludes?[...t.excludes.map(s=>{const o={bone:s.bone.name.slice(),radius:s.radius};return s.deltaLocal&&(o.deltaLocal=[...s.deltaLocal]),o})]:null;else if(e==="deltaWorld")i=t.dw?[...t.dw]:null;else if(e==="pivot")i=t.pivot;else if(e==="helper")i=t.helper;else throw new Error("Unsupported property '"+e+"'.");return i}setValue(n,e,t){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(n))throw new Error("Dynamic bone '"+n+"' not found.");const i=this.dict[n];if(e==="type"){if(!t)throw new Error("Parameter 'type' not set.");if(typeof t!="string")throw new Error("Type must be a string.");switch(t){case"point":i.isPoint=!0,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"link":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!1;break;case"mix1":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"mix2":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!0;break;case"full":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!0;break;default:throw new Error("Unknown type'"+t+"'.")}i.type=t.slice()}else if(e==="stiffness"){if(!t)throw new Error("Parameter 'stiffness' not set.");if(!Number.isNaN(t)&&t>=0)i.k=Array(4).fill(t);else if(Array.isArray(t)&&t.length===4&&t.every(s=>s>=0))i.k=[...t];else throw new Error("Stiffness must be a non-negative number or an array of four non-negative numbers.")}else if(e==="damping"){if(!t)throw new Error("Parameter 'damping' not set.");if(!Number.isNaN(t)&&t>=0)i.c=Array(4).fill(t);else if(Array.isArray(t)&&t.length===4&&t.every(s=>s>=0))i.c=[...t];else throw new Error("Damping must be a non-negative number or an array of four non-negative numbers.")}else if(e==="external")if(t==null)i.ext=1;else if(!Number.isNaN(t)&&t>=0&&t<=1)i.ext=t;else throw new Error("External (if set) must be a number between [0,1].");else if(e==="limits")if(t==null)i.limits=null;else{if(!Array.isArray(t)||t.length!==4)throw new Error("Limits (if set) must null, or an array of four arrays.");if(!t.every(s=>s===null||Array.isArray(s)&&s.length===2&&(s[0]===null||!Number.isNaN(s[0]))&&(s[1]===null||!Number.isNaN(s))))throw new Error("Limit values must be null or numbers.");i.limits=[t[0]?[...t[0]]:null,t[1]?[...t[1]]:null,t[2]?[...t[2]]:null,t[3]?[...t[3]]:null]}else if(e==="excludes"){if(t==null)i.excludes=null;else{if(!Array.isArray(t))throw new Error("Excludes (if set) must null, or an array.");i.excludes=[],t.forEach((s,o)=>{if(!s.bone)throw new Error("Bone not specified in #"+o+" exclude.");if(typeof s.bone!="string"||s.bone.length===0)throw new Error("Bone name must be a non-empty string in #"+o+" exclude.");const l=this.armature.getObjectByName(s.bone);if(!l)throw new Error("Bone '"+s.bone+"' not found in #"+o+" exclude.");if(Number.isNaN(s.radius)&&s.radius>=0)throw new Error("Radius must be a non-negative number in #"+o+" exclude.");const h={bone:l,radius:s.radius,radiusSq:s.radius*s.radius,deltaLocal:null};if(s.deltaLocal){if(!Array.isArray(s.deltaLocal)||s.deltaLocal.length!==3||s.deltaLocal.some(r=>Number.isNaN(r)))throw new Error("deltaLocal must be an array of three numbers in #"+o+" exclude.");h.deltaLocal=[...s.deltaLocal]}i.excludes.push(h)})}this.showHelpers()}else if(e==="helper"){if(t==null)i.helper=null;else{if(t!==!1&&t!==!0)throw new Error("Helper, if set, must be false or true.");i.helper=t}this.showHelpers()}else if(e==="pivot")if(t==null)i.pivot=null;else{if(t!==!1&&t!==!0)throw new Error("Pivot, if set, must be false or true.");if(t===!0&&i.type===0)throw new Error("Point type bone can't be a pivot.");i.pivot=t}else if(e==="deltaLocal")if(t==null)i.dl=null;else{if(!Array.isArray(t)||t.length!==3)throw new Error("deltaLocal, is set, must be an array of three numbers.");if(!t.every(s=>!Number.isNaN(s)))throw new Error("deltaLocal values must be numbers.");i.dl=[...t]}else if(e==="deltaWorld")if(t==null)i.dw=null;else{if(!Array.isArray(t)||t.length!==3)throw new Error("deltaWorld, is set, must be an array of three values.");if(!t.every(s=>!Number.isNaN(s)))throw new Error("deltaWorld values must be numbers.");i.dw=[...t]}else throw new Error("Unsupported property "+e)}getConfig(){return this.data.map(n=>{const e={bone:n.name.slice()};return["type","stiffness","damping","external","deltaLocal","deltaWorld","limits","excludes","pivot","helper"].forEach(t=>{c=this.getValue(n.name,t),c&&(e[t]=c)}),e})}sortBones(){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");let n=0;const e=new WeakMap;this.armature.traverse(o=>{e.has(o)||(e.set(o,n),n++)}),this.data.sort((o,l)=>e.get(o.bone)-e.get(l.bone)),this.data.forEach(o=>{c=this.dict[o.boneParent.name],c&&(c.children||(c.children=[]),c.children.push(o))}),this.objectsUpdate=[];const t=new WeakSet,i=o=>o.parent?.isBone?[o,...i(o.parent)]:[o],s=o=>{i(o).forEach(h=>{t.has(h)||(this.objectsUpdate.push(h),t.add(h))})};this.data.forEach(o=>{s(o.bone),o.excludes&&o.excludes.forEach(l=>{s(l.bone)})}),this.objectsUpdate.sort((o,l)=>e.get(o)-e.get(l))}setup(n,e,t){this.dispose();const i=(s,o)=>{if(!s)throw this.dispose(),new Error(o)};i(n?.isScene,"First parameter must be Scene."),this.scene=n,i(e?.isObject3D,"Second parameter must be the armature Object3D."),this.armature=e,i(Array.isArray(t),"Third parameter must be an array of bone configs."),this.config=t,this.config.forEach((s,o)=>{const l="Config item #"+o+": ";i(s.bone,l+"Bone not specified.");const h=s.bone;i(typeof h=="string"&&h.length>0,l+"Bone name must be a non-empty string.");const r=this.armature.getObjectByName(h);i(r,l+"Bone '"+h+"' not found."),i(r.parent?.isBone,l+"Bone must have a parent bone."),i(this.data.every(a=>a.bone!==r),l+"Bone '"+h+"' already exists."),r.updateMatrixWorld(!0);const u={name:h,bone:r,boneParent:r.parent,vBasis:r.position.clone(),vWorld:r.parent.getWorldPosition(F).clone(),qBasis:r.parent.quaternion.clone(),l:r.position.length(),p:[0,0,0,0],v:[0,0,0,0],a:[0,0,0,0],ev:[0,0,0,0],ea:[0,0,0,0]};u.boneParent.matrixWorld.decompose(F,se,oe),F.copy(we).applyQuaternion(se).setY(0).normalize(),se.premultiply(Ne.setFromUnitVectors(we,F).invert()).normalize(),u.qWorldInverseYaw=se.clone().normalize(),this.data.push(u),this.dict[h]=u;try{this.setValue(h,"type",s.type),this.setValue(h,"stiffness",s.stiffness),this.setValue(h,"damping",s.damping),this.setValue(h,"external",s.external),this.setValue(h,"limits",s.limits),this.setValue(h,"excludes",s.excludes),this.setValue(h,"deltaLocal",s.deltaLocal),this.setValue(h,"deltaWorld",s.deltaWorld),this.setValue(h,"pivot",s.pivot),this.setValue(h,"helper",s.helper)}catch(a){i(!1,l+a)}}),this.sortBones(),this.start()}update(n){if(!this.running)return;let e,t,i,s,o;for(this.timerMs+=n,n>1e3&&(this.timerMs=0),n/=1e3,e=0,i=this.objectsUpdate.length;e<i;e++)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;for(e=0,i=this.data.length;e<i;e++){if(o=this.data[e],F.copy(o.vWorld),pe.copy(o.boneParent.matrixWorld),ge.copy(pe).invert(),o.vWorld.setFromMatrixPosition(pe),F.applyMatrix4(ge),F.length()>.5&&(console.info("Info: Unrealistic jump of "+F.length().toFixed(2)+" meters."),F.setLength(.5)),F.applyQuaternion(o.bone.quaternion),z[0]=F.x,z[1]=F.y,z[2]=-F.z,z[3]=F.length()/3,o.children)for(t=0,s=o.children.length;t<s;t++)c=o.children[t],z[0]-=c.v[0]*n/3,z[1]-=c.v[1]*n/3,z[2]+=c.v[2]*n/3,z[3]-=c.v[3]*n/3;if(c=this.opt.sensitivityFactor,z[0]*=o.ext*c,z[1]*=o.ext*c,z[2]*=o.ext*c,z[3]*=o.ext*c,o.isX&&(c=z[0]/n,o.ea[0]=(c-o.ev[0])/n,o.ev[0]=c,o.a[0]=-o.k[0]*o.p[0]-o.c[0]*o.v[0]-o.ea[0],o.p[0]+=o.v[0]*n+o.a[0]*n*n/2+z[0],c=o.v[0]+o.a[0]*n/2,c=-o.k[0]*o.p[0]-o.c[0]*c-o.ea[0],o.v[0]=o.v[0]+(c+o.a[0])*n/2),o.isY&&(c=z[1]/n,o.ea[1]=(c-o.ev[1])/n,o.ev[1]=c,o.a[1]=-o.k[1]*o.p[1]-o.c[1]*o.v[1]-o.ea[1],o.p[1]+=o.v[1]*n+o.a[1]*n*n/2+z[1],c=o.v[1]+o.a[1]*n/2,c=-o.k[1]*o.p[1]-o.c[1]*c-o.ea[1],o.v[1]=o.v[1]+(c+o.a[1])*n/2),o.isZ&&(c=z[2]/n,o.ea[2]=(c-o.ev[2])/n,o.ev[2]=c,o.a[2]=-o.k[2]*o.p[2]-o.c[2]*o.v[2]-o.ea[2],o.p[2]+=o.v[2]*n+o.a[2]*n*n/2+z[2],c=o.v[2]+o.a[2]*n/2,c=-o.k[2]*o.p[2]-o.c[2]*c-o.ea[2],o.v[2]=o.v[2]+(c+o.a[2])*n/2),o.isT&&(c=z[3]/n,o.ea[3]=(c-o.ev[3])/n,o.ev[3]=c,o.a[3]=-o.k[3]*o.p[3]-o.c[3]*o.v[3]-o.ea[3],o.p[3]+=o.v[3]*n+o.a[3]*n*n/2+z[3],c=o.v[3]+o.a[3]*n/2,c=-o.k[3]*o.p[3]-o.c[3]*c-o.ea[3],o.v[3]=o.v[3]+(c+o.a[3])*n/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),z[0]=o.p[0],z[1]=o.p[1],z[2]=o.p[2],z[3]=o.p[3],c=this.opt.movementFactor,z[0]*=c,z[1]*=c,z[2]*=c,z[3]*=c,o.dl&&(c=o.dl,z[0]+=c[0],z[1]+=c[1],z[2]+=c[2]),o.dw&&(c=o.dw,F.set(o.vBasis.x+z[0],o.vBasis.y+z[1],o.vBasis.z+z[2]),F.applyMatrix4(pe),F.x+=c[0],F.y+=c[1],F.z+=c[2],F.applyMatrix4(ge),z[0]+=F.x-o.vBasis.x,z[1]+=F.y-o.vBasis.y,z[2]+=F.z-o.vBasis.z),o.limits&&this.opt.isLimits&&(c=o.limits,c[0]&&(c[0][0]!==null&&z[0]<c[0][0]&&(z[0]=c[0][0]),c[0][1]!==null&&z[0]>c[0][1]&&(z[0]=c[0][1])),c[1]&&(c[1][0]!==null&&z[1]<c[1][0]&&(z[1]=c[1][0]),c[1][1]!==null&&z[1]>c[1][1]&&(z[1]=c[1][1])),c[2]&&(c[2][0]!==null&&z[2]<c[2][0]&&(z[2]=c[2][0]),c[2][1]!==null&&z[2]>c[2][1]&&(z[2]=c[2][1])),c[3]&&(c[3][0]!==null&&z[3]<c[3][0]&&(z[3]=c[3][0]),c[3][1]!==null&&z[3]>c[3][1]&&(z[3]=c[3][1]))),o.isPoint)o.bone.position.set(o.vBasis.x+z[0],o.vBasis.y+z[1],o.vBasis.z-z[2]);else if(o.boneParent.quaternion.copy(o.qBasis),o.pivot&&this.opt.isPivots&&(o.boneParent.updateWorldMatrix(!1,!1),o.boneParent.matrixWorld.decompose(F,se,oe),F.copy(we).applyQuaternion(se).setY(0).normalize(),se.premultiply(Ne.setFromUnitVectors(we,F).invert()).normalize(),o.boneParent.quaternion.multiply(se.invert()),o.boneParent.quaternion.multiply(o.qWorldInverseYaw)),o.isZ&&(c=Math.atan(z[0]/o.l),se.setFromAxisAngle(Je,-c),o.boneParent.quaternion.multiply(se)),o.isY&&(c=o.l/3,c=c*Math.tanh(z[1]/c),o.bone.position.setLength(o.l+c)),o.isX&&(c=Math.atan(z[2]/o.l),se.setFromAxisAngle(_e,-c),o.boneParent.quaternion.multiply(se)),o.isT&&(c=1.5*Math.tanh(z[3]*1.5),se.setFromAxisAngle(Ke,-c),o.boneParent.quaternion.multiply(se)),o.boneParent.updateWorldMatrix(!1,!0),o.excludes&&this.opt.isExcludes)for(t=0,s=o.excludes.length;t<s;t++)c=o.excludes[t],oe.set(0,0,0),c.deltaLocal&&(oe.x+=c.deltaLocal[0],oe.y+=c.deltaLocal[1],oe.z+=c.deltaLocal[2]),oe.applyMatrix4(c.bone.matrixWorld),ge.copy(o.boneParent.matrixWorld).invert(),oe.applyMatrix4(ge),F.copy(o.bone.position),!(F.distanceToSquared(oe)>=c.radiusSq)&&(he=F.length(),re=oe.length(),!(re>c.radius+he)&&(re<Math.abs(c.radius-he)||(re=(re*re+he*he-c.radiusSq)/(2*re),oe.normalize(),Ce.copy(oe).multiplyScalar(re),re=Math.sqrt(he*he-re*re),F.subVectors(F,Ce).projectOnPlane(oe).normalize().multiplyScalar(re),ke.subVectors(o.vBasis,Ce).projectOnPlane(oe).normalize(),he=ke.dot(F),he<0&&(he=Math.sqrt(re*re-he*he),ke.multiplyScalar(he),F.add(ke)),F.add(Ce).normalize(),oe.copy(o.bone.position).normalize(),se.setFromUnitVectors(oe,F),o.boneParent.quaternion.premultiply(se),o.boneParent.updateWorldMatrix(!1,!0))))}this.helpers.isActive&&this.updateHelpers()}showHelpers(n){if(this.hideHelpers(),this.helpers.isShowAll=n===void 0?this.helpers.isShowAll:n===!0,c=this.helpers,this.data.forEach(e=>{(this.helpers.isShowAll||e.helper===!0)&&(c.points.bones.push(e.bone),c.points.pivots.push(e.pivot),e.type!==0&&c.lines.bones.push(e.bone),e.excludes&&e.excludes.forEach(t=>{let i=!1;for(let s=0;s<c.excludes.bones.length;s++)if(c.excludes.bones[s]===t.bone&&c.excludes.radii[s]===t.radius&&!(c.excludes.deltaLocals[s]===null&&t.deltaLocal!==null)&&!(c.excludes.deltaLocals[s]!==null&&t.deltaLocal===null)&&!(c.excludes.deltaLocals[s]!==null&&c.excludes.deltaLocals[s].some((o,l)=>o!==t.deltaLocal[l]))){i=!0;break}i||(c.excludes.bones.push(t.bone),c.excludes.radii.push(t.radius),c.excludes.deltaLocals.push(t.deltaLocal?[...t.deltaLocal]:null),c.excludes.objects.push(null))}))}),c=this.helpers.excludes,this.opt.isExcludes&&c.bones.length&&c.bones.forEach((e,t)=>{const i=new g.SphereGeometry(c.radii[t],6,6),s=new g.MeshBasicMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,wireframe:!0,color:this.opt.helperExcludesColor});c.objects[t]=new g.Mesh(i,s),c.objects[t].renderOrder=997,e.add(c.objects[t]),c.deltaLocals[t]&&c.objects[t].position.set(c.deltaLocals[t][0],c.deltaLocals[t][1],c.deltaLocals[t][2])}),c=this.helpers.points,c.bones.length){this.helpers.isActive=!0;const e=new g.BufferGeometry,t=c.bones.map(h=>[0,0,0]).flat();e.setAttribute("position",new g.Float32BufferAttribute(t,3));const i=new g.Color(this.opt.helperBoneColor1),s=new g.Color(this.opt.helperBoneColor2),o=c.pivots.map(h=>h&&this.opt.isPivots?[s.r,s.g,s.b]:[i.r,i.g,i.b]).flat();e.setAttribute("color",new g.Float32BufferAttribute(o,3));const l=new g.PointsMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,size:.2,vertexColors:!0});c.object=new g.Points(e,l),c.object.renderOrder=998,c.object.matrix=this.armature.matrixWorld,c.object.matrixAutoUpdate=!1,this.scene.add(c.object)}if(c=this.helpers.lines,c.bones.length){const e=new g.BufferGeometry,t=c.bones.map(h=>[0,0,0,0,0,0]).flat();e.setAttribute("position",new g.Float32BufferAttribute(t,3));const i=new g.Color(this.opt.helperLinkColor1),s=new g.Color(this.opt.helperLinkColor2),o=c.bones.map(h=>[i.r,i.g,i.b,s.r,s.g,s.b]).flat();e.setAttribute("color",new g.Float32BufferAttribute(o,3));const l=new g.LineBasicMaterial({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0});c.object=new g.LineSegments(e,l),c.object.renderOrder=999,c.object.matrix=this.armature.matrixWorld,c.object.matrixAutoUpdate=!1,this.scene.add(c.object)}}updateHelpers(){if(c=this.helpers.points,c.bones.length){ge.copy(this.armature.matrixWorld).invert();const n=c.object.geometry.getAttribute("position");for(let e=0,t=c.bones.length;e<t;e++)pe.multiplyMatrices(ge,c.bones[e].matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(e,F.x,F.y,F.z);n.needsUpdate=!0,c.object.updateMatrixWorld()}if(c=this.helpers.lines,c.bones.length){ge.copy(this.armature.matrixWorld).invert();const n=c.object.geometry.getAttribute("position");for(let e=0,t=0,i=c.bones.length;e<i;e++,t+=2)pe.multiplyMatrices(ge,c.bones[e].matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(t,F.x,F.y,F.z),pe.multiplyMatrices(ge,c.bones[e].parent.matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(t+1,F.x,F.y,F.z);n.needsUpdate=!0,c.object.updateMatrixWorld()}}hideHelpers(){[this.helpers.points,this.helpers.lines].forEach(n=>{n.bones=[],n.object&&(this.scene.remove(n.object),n.object.geometry.dispose(),n.object.material.dispose(),n.object=null)}),c=this.helpers.excludes,c.objects.forEach((n,e)=>{n&&(c.bones[e].remove(n),n.geometry.dispose(),n.material.dispose())}),c.bones=[],c.deltaLocals=[],c.radii=[],c.objects=[],this.helpers.isActive=!1}start(){this.data.length&&(this.running=!0,this.timerMs=0,this.showHelpers())}stop(){this.running=!1,this.hideHelpers();for(let n=0,e=this.data.length;n<e;n++){const t=this.data[n];t.bone.position.copy(t.vBasis),t.boneParent.quaternion.copy(t.qBasis)}}dispose(){this.stop(),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.timerMs=0}}class et{constructor(){this.rules={A:["[A] =aa"," [ARE] =aa RR"," [AR]O=aa RR","[AR]#=E RR"," ^[AS]#=E SS","[A]WA=aa","[AW]=aa"," :[ANY]=E nn I","[A]^+#=E","#:[ALLY]=aa nn I"," [AL]#=aa nn","[AGAIN]=aa kk E nn","#:[AG]E=I kk","[A]^+:#=aa",":[A]^+ =E","[A]^%=E"," [ARR]=aa RR","[ARR]=aa RR"," :[AR] =aa RR","[AR] =E","[AR]=aa RR","[AIR]=E RR","[AI]=E","[AY]=E","[AU]=aa","#:[AL] =aa nn","#:[ALS] =aa nn SS","[ALK]=aa kk","[AL]^=aa nn"," :[ABLE]=E PP aa nn","[ABLE]=aa PP aa nn","[ANG]+=E nn kk","[A]=aa"],B:[" [BE]^#=PP I","[BEING]=PP I I nn"," [BOTH] =PP O TH"," [BUS]#=PP I SS","[BUIL]=PP I nn","[B]=PP"],C:[" [CH]^=kk","^E[CH]=kk","[CH]=CH"," S[CI]#=SS aa","[CI]A=SS","[CI]O=SS","[CI]EN=SS","[C]+=SS","[CK]=kk","[COM]%=kk aa PP","[C]=kk"],D:["#:[DED] =DD I DD",".E[D] =DD","#^:E[D] =DD"," [DE]^#=DD I"," [DO] =DD U"," [DOES]=DD aa SS"," [DOING]=DD U I nn"," [DOW]=DD aa","[DU]A=kk U","[D]=DD"],E:["#:[E] =","'^:[E] ="," :[E] =I","#[ED] =DD","#:[E]D =","[EV]ER=E FF","[E]^%=I","[ERI]#=I RR I","[ERI]=E RR I","#:[ER]#=E","[ER]#=E RR","[ER]=E"," [EVEN]=I FF E nn","#:[E]W=","@[EW]=U","[EW]=I U","[E]O=I","#:&[ES] =I SS","#:[E]S =","#:[ELY] =nn I","#:[EMENT]=PP E nn DD","[EFUL]=FF U nn","[EE]=I","[EARN]=E nn"," [EAR]^=E","[EAD]=E DD","#:[EA] =I aa","[EA]SU=E","[EA]=I","[EIGH]=E","[EI]=I"," [EYE]=aa","[EY]=I","[EU]=I U","[E]=E"],F:["[FUL]=FF U nn","[F]=FF"],G:["[GIV]=kk I FF"," [G]I^=kk","[GE]T=kk E","SU[GGES]=kk kk E SS","[GG]=kk"," B#[G]=kk","[G]+=kk","[GREAT]=kk RR E DD","#[GH]=","[G]=kk"],H:[" [HAV]=I aa FF"," [HERE]=I I RR"," [HOUR]=aa EE","[HOW]=I aa","[H]#=I","[H]="],I:[" [IN]=I nn"," [I] =aa","[IN]D=aa nn","[IER]=I E","#:R[IED] =I DD","[IED] =aa DD","[IEN]=I E nn","[IE]T=aa E"," :[I]%=aa","[I]%=I","[IE]=I","[I]^+:#=I","[IR]#=aa RR","[IZ]%=aa SS","[IS]%=aa SS","[I]D%=aa","+^[I]^+=I","[I]T%=aa","#^:[I]^+=I","[I]^+=aa","[IR]=E","[IGH]=aa","[ILD]=aa nn DD","[IGN] =aa nn","[IGN]^=aa nn","[IGN]%=aa nn","[IQUE]=I kk","[I]=I"],J:["[J]=kk"],K:[" [K]N=","[K]=kk"],L:["[LO]C#=nn O","L[L]=","#^:[L]%=aa nn","[LEAD]=nn I DD","[L]=nn"],M:["[MOV]=PP U FF","[M]=PP"],N:["E[NG]+=nn kk","[NG]R=nn kk","[NG]#=nn kk","[NGL]%=nn kk aa nn","[NG]=nn","[NK]=nn kk"," [NOW] =nn aa","[N]=nn"],O:["[OF] =aa FF","[OROUGH]=E O","#:[OR] =E","#:[ORS] =E SS","[OR]=aa RR"," [ONE]=FF aa nn","[OW]=O"," [OVER]=O FF E","[OV]=aa FF","[O]^%=O","[O]^EN=O","[O]^I#=O","[OL]D=O nn","[OUGHT]=aa DD","[OUGH]=aa FF"," [OU]=aa","H[OU]S#=aa","[OUS]=aa SS","[OUR]=aa RR","[OULD]=U DD","^[OU]^L=aa","[OUP]=U OO","[OU]=aa","[OY]=O","[OING]=O I nn","[OI]=O","[OOR]=aa RR","[OOK]=U kk","[OOD]=U DD","[OO]=U","[O]E=O","[O] =O","[OA]=O"," [ONLY]=O nn nn I"," [ONCE]=FF aa nn SS","[ON'T]=O nn DD","C[O]N=aa","[O]NG=aa"," ^:[O]N=aa","I[ON]=aa nn","#:[ON] =aa nn","#^[ON]=aa nn","[O]ST =O","[OF]^=aa FF","[OTHER]=aa TH E","[OSS] =aa SS","#^:[OM]=aa PP","[O]=aa"],P:["[PH]=FF","[PEOP]=PP I PP","[POW]=PP aa","[PUT] =PP U DD","[P]=PP"],Q:["[QUAR]=kk FF aa RR","[QU]=kk FF","[Q]=kk"],R:[" [RE]^#=RR I","[R]=RR"],S:["[SH]=SS","#[SION]=SS aa nn","[SOME]=SS aa PP","#[SUR]#=SS E","[SUR]#=SS E","#[SU]#=SS U","#[SSU]#=SS U","#[SED] =SS DD","#[S]#=SS","[SAID]=SS E DD","^[SION]=SS aa nn","[S]S=",".[S] =SS","#:.E[S] =SS","#^:##[S] =SS","#^:#[S] =SS","U[S] =SS"," :#[S] =SS"," [SCH]=SS kk","[S]C+=","#[SM]=SS PP","#[SN]'=SS aa nn","[S]=SS"],T:[" [THE] =TH aa","[TO] =DD U","[THAT] =TH aa DD"," [THIS] =TH I SS"," [THEY]=TH E"," [THERE]=TH E RR","[THER]=TH E","[THEIR]=TH E RR"," [THAN] =TH aa nn"," [THEM] =TH E PP","[THESE] =TH I SS"," [THEN]=TH E nn","[THROUGH]=TH RR U","[THOSE]=TH O SS","[THOUGH] =TH O"," [THUS]=TH aa SS","[TH]=TH","#:[TED] =DD I DD","S[TI]#N=CH","[TI]O=SS","[TI]A=SS","[TIEN]=SS aa nn","[TUR]#=CH E","[TU]A=CH U"," [TWO]=DD U","[T]=DD"],U:[" [UN]I=I U nn"," [UN]=aa nn"," [UPON]=aa PP aa nn","@[UR]#=U RR","[UR]#=I U RR","[UR]=E","[U]^ =aa","[U]^^=aa","[UY]=aa"," G[U]#=","G[U]%=","G[U]#=FF","#N[U]=I U","@[U]=I","[U]=I U"],V:["[VIEW]=FF I U","[V]=FF"],W:[" [WERE]=FF E","[WA]S=FF aa","[WA]T=FF aa","[WHERE]=FF E RR","[WHAT]=FF aa DD","[WHOL]=I O nn","[WHO]=I U","[WH]=FF","[WAR]=FF aa RR","[WOR]^=FF E","[WR]=RR","[W]=FF"],X:[" [X]=SS","[X]=kk SS"],Y:["[YOUNG]=I aa nn"," [YOU]=I U"," [YES]=I E SS"," [Y]=I","#^:[Y] =I","#^:[Y]I=I"," :[Y] =aa"," :[Y]#=aa"," :[Y]^+:#=I"," :[Y]^#=I","[Y]=I"],Z:["[Z]=SS"]};const n={"#":"[AEIOUY]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY)","&":"(?:[SCGZXJ]|CH|SH)","@":"(?:[TSRDLZNJ]|TH|CH|SH)","^":"[BCDFGHJKLMNPQRSTVWXZ]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXZ]*"," ":"\\b"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d),u.length&&u.split(" ").forEach(y=>{a.visemes.push(y)}),a})}),this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,TH:1,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5},this.digits=["oh","one","two","three","four","five","six","seven","eight","nine"],this.ones=["","one","two","three","four","five","six","seven","eight","nine"],this.tens=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],this.teens=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],this.decades={20:"twenties",30:"thirties",40:"forties",50:"fifties",60:"sixties",70:"seventies",80:"eighties",90:"nineties"},this.ordinals={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",6:"sixth",7:"seventh",8:"eighth",9:"ninth",10:"tenth",11:"eleventh",12:"twelfth",13:"thirteenth",14:"fourteenth",15:"fifteenth",16:"sixteenth",17:"seventeeth",18:"eighteenth",19:"nineteenth",20:"twentieth",30:"thirtieth",40:"fortieth",50:"fiftieth",60:"sixtieth",70:"seventieth",80:"eightieth",90:"ninetieth"},this.symbols={"%":"percent","€":"euros","&":"and","+":"plus",$:"dollars"},this.symbolsReg=/[%€&\+\$]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_sets_of_two(n){let e=String(n).substring(0,2),t=String(n).substring(2,4),i=this.convert_tens(e);return i+=" "+this.convert_tens(t),i}convert_millions(n){return n>=1e6?this.convert_millions(Math.floor(n/1e6))+" million "+this.convert_thousands(n%1e6):this.convert_thousands(n)}convert_thousands(n){return n>=1e3?this.convert_hundreds(Math.floor(n/1e3))+" thousand "+this.convert_hundreds(n%1e3):this.convert_hundreds(n)}convert_hundreds(n){return n>99?this.ones[Math.floor(n/100)]+" hundred "+this.convert_tens(n%100):this.convert_tens(n)}convert_tens(n){return n<10?(Number(n)!=0&&n.toString().startsWith("0")?"oh ":"")+this.ones[Number(n)]:n>=10&&n<20?this.teens[n-10]:(this.tens[Math.floor(n/10)]+" "+this.ones[n%10]).trim()}convertNumberToWords(n,e=!1){const t=parseFloat(n);if(n=="0")return"zero";if(n<0)return" minus "+this.convertNumberToWords(Math.abs(n).toString(),e).trim();if(t&&!Number.isInteger(t)){const i=t.toString().split(".");return this.convertNumberToWords(i[0],e).trim()+" point "+this.convert_digit_by_digit(i[1]).trim()}else return n.toString().startsWith("0")?this.convert_digit_by_digit(n).trim():!e&&(n<1e3&&n>99&&n%100!==0||n>1e4&&n<1e6)?this.convert_digit_by_digit(n).trim():!e&&(n>1e3&&n<2e3||n>2009&&n<3e3)?n%100!=0?this.convert_sets_of_two(n).trim():this.convert_tens(n.toString().substring(0,2)).trim()+" hundred":this.convert_millions(n).trim()}convertDecade(n){const e=parseInt(n),t=!isNaN(e)&&n.length===2,i=!isNaN(e)&&n.length>2&&e>0&&e<=3e3,s=i&&e%1e3===0?Math.floor(e/1e3):null,o=i&&!s?Math.floor(e/100):null,l=t||i?Math.floor(e%100/10)*10:null;let h=[];return s?h.push(this.convertNumberToWords(s).trim(),"thousands"):(o&&h.push(this.convertNumberToWords(o).trim()),l?h.push(this.decades[l]||this.convertNumberToWords(l).trim()+"s"):o?h.push("hundreds"):h.push(n)),h.join(" ")}convertOrdinal(n){if(this.ordinals.hasOwnProperty(n))return this.ordinals[n];const e=Math.floor(n/100),t=Math.floor(n%100/10)*10,i=n%10;let s=[];return e&&(s.push(this.convertNumberToWords(e).trim()),t||i?s.push("hundred"):s.push("hundredth")),t&&(i?s.push(this.convertNumberToWords(t).trim()):s.push(this.ordinals[t])),i&&s.push(this.ordinals[i]),s.join(" ")}preProcessText(n){let e=n.replace('/[#_*":;]/g',"");return e=e.replace(this.symbolsReg,t=>" "+this.symbols[t]+" "),/\d/.test(e)&&(e=e.replace(/\b(\d{2,4})[''']?\s?[sS](?=\s|[.,!?;:]|$)/g,(t,i)=>{const s=this.convertDecade(i);return s===i?t:s}),e=e.replace(/\b(\d+)\s*(st|nd|rd|th)(?=\s|[.,!?;:]|$)/gi,(t,i)=>this.convertOrdinal(Number(i))),e=e.replace(/\b(\w*?)(\d+)([A-Za-z]+)\b/g,(t,i,s,o)=>{const l=this.convertNumberToWords(s);return`${i}${l} ${o}`}).replace(/\b([A-Za-z]+)(\d+)(\w*?)\b/g,(t,i,s,o)=>{const l=this.convertNumberToWords(s);return`${i} ${l}${o}`}),e=e.replace(/-?(?:\d{1,3}(?:,\d{3})+|\d+)(\.\d+)?/g,(t,i)=>{let s=t,o=!1;return/,/.test(s)&&(s=s.replace(/,/g,""),o=!0),i&&(o=!0),this.convertNumberToWords(s,o)})),e=e.replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC").trim(),e}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o)for(let l=0;l<o.length;l++){const h=o[l];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(h.regex)){h.visemes.forEach(a=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===a){const d=.7*(this.visemeDurations[a]||1);e.durations[e.durations.length-1]+=d,t+=d}else{const d=this.visemeDurations[a]||1;e.visemes.push(a),e.times.push(t),e.durations.push(d),t+=d}}),e.i+=h.move;break}}else e.i++,t+=this.specialDurations[s]||0}return e}}const tt=Object.freeze(Object.defineProperty({__proto__:null,LipsyncEn:et},Symbol.toStringTag,{value:"Module"}));class nt{constructor(){this.rules={A:["[AH]=aa","[AU]=aa U","[AI]=aa I","[AE]=E","[A]H=aa","[A]U=aa U","[A]I=aa I"," [AN] =aa nn"," [AM] =aa PP","[ARR]=aa RR","[AR]=aa RR"," [ALS]=aa nn SS","[AL]=aa nn","[AUCH]=aa U kk","[ABER]=aa PP E RR","[A]=aa"],Ä:["[Ä]H=E","[ÄU]=O","[Ä]=E"],B:["[B]=PP"],C:["[CH]S=kk SS","[CH]=kk"," [CH]=kk","#[CH]=kk","[CK]=kk","[C]H=kk","[C]=kk"],D:[" [DAS] =DD aa SS"," [DEN] =DD E nn"," [DER] =DD E RR"," [DIE] =DD I"," [DU] =DD U"," [DURCH]=DD U RR kk","[D]=DD"],E:["[EI]=aa I","[EU]=O","[EH]=E"," [ER] =E RR"," [ES] =E SS"," [EIN] =aa I nn"," [EINE]=aa I nn aa","[ER]#=E","[ER]=E RR","[EN]#=aa nn","[E]=E"],F:["[F]=FF"],G:["[G]=kk"],H:[" [HAT] =I aa DD"," [HABEN]=I aa PP aa nn"," [HIER]=I I RR"," [HEUTE]=I O DD aa","[H]="],I:[" [ICH] =I kk"," [IHR] =I RR"," [IN] =I nn"," [IST] =I SS DD"," [IM] =I PP","[IE]=I","[IH]=I","[I]=I"],J:["[J]=I"],K:["[K]=kk"],L:["[L]=nn"],M:[" [MIT] =PP I DD"," [MAN] =PP aa nn"," [MEHR]=PP E RR"," [MICH]=PP I kk","[M]=PP"],N:[" [NICHT]=nn I kk DD"," [NUR] =nn U RR"," [NACH]=nn aa kk"," [NOCH]=nn aa kk","[NG]=nn kk","[N]=nn"],O:["[OO]=U","[OH]=O","[OU]=aa U"," [ODER]=O DD E RR"," [OHNE]=O nn aa","[Ö]=E","[O]=aa"],Ö:["[ÖH]=E","[Ö]=E"],P:["[PF]=FF FF","[PH]=FF","[P]=PP"],Q:["[QU]=kk FF","[Q]=kk"],R:["[R]=RR"],S:["[SCH]=SS","[SP]=SS PP","[ST]=SS DD","[SS]=SS","[S]=SS"],ß:["[ß]=SS"],T:["[TZ]=DD SS","[TH]=DD","[T]=DD"],U:[" [UND] =U nn DD"," [UM] =U PP"," [UNTER]=U nn DD E RR"," [UNS] =U nn SS","[UH]=U","[ÜH]=I U","[Ü]=I U","[U]=U"],Ü:["[ÜH]=I U","[Ü]=I U"],V:[" [VON] =FF aa nn"," [VOR] =FF aa RR"," [VIEL]=FF I nn","[V]=FF"],W:[" [WAS] =FF aa SS"," [WIR] =FF I RR"," [WIE] =FF I"," [WENN]=FF E nn"," [WILL]=FF I nn"," [WO] =FF aa"," [WIEDER]=FF I DD E RR","[W]=FF"],X:["[X]=kk SS"],Y:["[Y]=I"],Z:[" [ZU] =DD SS U"," [ZUM] =DD SS U PP"," [ZUR] =DD SS U RR"," [ZEIT]=DD SS aa I DD","[Z]=DD SS"]};const n={"#":"[AEIOUÄÖÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY|EN|TE|ST)","&":"(?:[SCGZXJ]|CH|SCH|TZ)","@":"(?:[TSRDLZNJ]|TH|CH|SCH)","^":"[BCDFGHJKLMNPQRSTVWXYZß]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXYZß]*"," ":"\\b"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d),u.length&&u.split(" ").forEach(y=>{a.visemes.push(y)}),a})}),this.visemeDurations={aa:1,E:.85,I:.9,O:1.05,U:1,PP:1.15,SS:1.2,TH:1,DD:1.1,FF:1.05,kk:1.25,nn:.85,RR:.9,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5,".":4,"!":3,"?":3},this.digits=["null","eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.ones=["","ein","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.tens=["","","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"],this.teens=["zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn"],this.symbols={"%":"prozent","€":"euro","&":"und","+":"plus",$:"dollar","=":"gleich","@":"at","#":"hashtag"},this.symbolsReg=/[%€&\+\$=@#]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_millions(n){if(n>=1e6){const e=Math.floor(n/1e6),t=n%1e6;let i=this.convert_thousands(e);return i+=e===1?" million ":" millionen ",t>0&&(i+=this.convert_thousands(t)),i}else return this.convert_thousands(n)}convert_thousands(n){if(n>=1e3){const e=Math.floor(n/1e3),t=n%1e3;let i="";return e===1?i="eintausend":i=this.convert_hundreds(e)+"tausend",t>0&&(i+=this.convert_hundreds(t)),i}else return this.convert_hundreds(n)}convert_hundreds(n){if(n>99){const e=Math.floor(n/100),t=n%100;let i="";return e===1?i="einhundert":i=this.ones[e]+"hundert",t>0&&(i+=this.convert_tens(t)),i}else return this.convert_tens(n)}convert_tens(n){if(n<10)return this.ones[Number(n)]||"";if(n>=10&&n<20)return this.teens[n-10];{const e=Math.floor(n/10),t=n%10;return t===0?this.tens[e]:this.ones[t]+"und"+this.tens[e]}}convertNumberToWords(n){const e=String(n);return n=="0"?"null":e.startsWith("0")?this.convert_digit_by_digit(n):e.length===4&&(n<1e3||n>2100)?this.convert_digit_by_digit(n):this.convert_millions(Number(n))}preProcessText(n){return n.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)\.(\d)/g,"$1 komma $2").replace(/(\d),(\d)/g,"$1 komma $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").toLowerCase().trim()}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o){let l=!1;for(let h=0;h<o.length;h++){const r=o[h];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(r.regex)){r.visemes.forEach(d=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===d){const p=.7*(this.visemeDurations[d]||1);e.durations[e.durations.length-1]+=p,t+=p}else{const p=this.visemeDurations[d]||1;e.visemes.push(d),e.times.push(t),e.durations.push(p),t+=p}}),e.i+=r.move,l=!0;break}}l||(e.i++,t+=this.specialDurations[s]||0)}else e.i++,t+=this.specialDurations[s]||0}return e}}const it=Object.freeze(Object.defineProperty({__proto__:null,LipsyncDe:nt},Symbol.toStringTag,{value:"Module"}));class ot{constructor(){this.rules={A:["[AN]C=aa nn","[AN]G=aa nn","[AN]T=aa nn","[AN]D=aa nn","[AN] =aa nn","[AN]$=aa nn","[AM]P=aa nn","[AM]B=aa nn","[AM] =aa nn","[AM]$=aa nn","[AI]N=E nn","[AIM]=E nn","[AIN]=E nn","[AU]=O","[AUX]=O","[AUT]=O","[AI]=E","[AY]=E","[A]=aa"],À:["[À]=aa"],Â:["[Â]=aa"],B:[" [B] =PP","[BB]=PP","[B]=PP"],C:["[C]E=SS","[C]I=SS","[C]Y=SS","[C]È=SS","[C]É=SS","[C]Ê=SS","[CH]=SS","[C]A=kk","[C]O=kk","[C]U=kk","[C]L=kk","[C]R=kk","[CK]=kk","[C]=kk"],Ç:["[Ç]=SS"],D:["[D]=DD"],E:["[EN]C=aa nn","[EN]T=aa nn","[EN]D=aa nn","[EN] =aa nn","[EN]$=aa nn","[EM]P=aa nn","[EM]B=aa nn","[EM] =aa nn","[EM]$=aa nn","[EAU]=O","[EAU]X=O","[EU]=U","[EUX]=U","[EUR]=U RR","[EI]=E","[EIN]=E nn","[ER] =E","[ER]$=E","[EZ] =E","[EZ]$=E","[ED] =E","[ED]$=E"," [E] =","[E] =","[E]$=","[E]S =","[E]S$=","[E]NT =","[E]NT$=","[È]=E","[É]=E","[Ê]=E","[Ë]=E","[E]=E"],È:["[È]=E"],É:["[É]=E"],Ê:["[Ê]=E"],Ë:["[Ë]=E"],F:["[FF]=FF","[F]=FF","[PH]=FF"],G:["[G]E=SS","[G]I=SS","[G]Y=SS","[G]È=SS","[G]É=SS","[G]Ê=SS","[GN]=nn I","[GN]E=nn","[GN]A=nn aa","[GN]O=nn O","[GU]E=kk","[GU]I=kk","[GU]A=kk FF aa","[GU]O=kk FF O","[G]A=kk","[G]O=kk","[G]U=kk","[G]L=kk","[G]R=kk","[GG]=kk","[G]=kk"],H:["[H]="],I:["[IN]C=E nn","[IN]T=E nn","[IN]D=E nn","[IN] =E nn","[IN]$=E nn","[IM]P=E nn","[IM]B=E nn","[IM] =E nn","[IM]$=E nn","[IEN]=I E nn","[IER]=I E","[IEU]=I U","[IEZ]=I E","[ILL]E=I","[ILLE]=I","[ILL]=I","[Î]=I","[Ï]=I","[I]=I"],Î:["[Î]=I"],Ï:["[Ï]=I"],J:["[J]=SS"],K:["[K]=kk"],L:["[LL]E=","[LLE]=","[LL]A=I aa","[LL]O=I O","[LL]U=I U","[LL]I=I","[LL]=I","[L]=nn"],M:["[MM]=PP","[M]=PP"],N:["[NN]=nn","[N]=nn"],O:["[ON]C=O nn","[ON]T=O nn","[ON]D=O nn","[ON] =O nn","[ON]$=O nn","[OM]P=O nn","[OM]B=O nn","[OM] =O nn","[OM]$=O nn","[OI]N=FF E nn","[OI]G=FF aa","[OI]S=FF aa","[OI]T=FF aa","[OI]X=FF aa","[OI]=FF aa","[OU]=U","[OÙ]=U","[OÛ]=U","[OEU]=U","[OEUR]=U RR","[OUGH]=U FF","[OUGH]T=U","[Ô]=O","[O]=O"],Ô:["[Ô]=O"],Ù:["[Ù]=U"],Û:["[Û]=U"],P:["[PH]=FF","[PP]=PP","[P]=PP"],Q:["[QU]=kk","[Q]=kk"],R:["[RR]=RR","[R]=RR"],S:["#[S]#=SS"," [S]=SS","[SS]=SS","[S] =","[S]$=","[SC]E=SS","[SC]I=SS","[SC]Y=SS","[S]=SS"],T:["[TI]A=SS I aa","[TI]E=SS I E","[TI]O=SS I O","[TI]ON=SS I O nn","[TH]=DD","[TT]=DD","[T] =","[T]$=","[T]=DD"],U:["[UN]C=U nn","[UN]T=U nn","[UN]D=U nn","[UN] =U nn","[UN]$=U nn","[UM]=U nn","[UE]=I","[UEI]=I E","[UEIL]=I I","[UILL]=I","[Ù]=U","[Û]=U","[Ü]=I U","[U]=I U"],Ü:["[Ü]=I U"],V:["[V]=FF"],W:["[W]=FF"],X:["[X] =","[X]$=","#[X]#=kk SS"," [X]=kk SS","[X]=kk SS"],Y:["[Y]=I"," [Y]=I","[YE]=I E","[YA]=I aa","[YO]=I O","[YU]=I U"],Z:["[Z]=SS"]};const n={"#":"[AEIOUYÀÂÈÉÊËÎÏÔÙÛÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ÉS|ÈS|ÊS|ENT|MENT|TION|SION)","&":"(?:[SCGZXJ]|CH|SH|GN)","@":"(?:[TSRDLZNJ]|TH|CH|SH|GN)","^":"[BCDFGHJKLMNPQRSTVWXZÇ]+","+":"[EIYÈÉÊËÎÏ]",":":"[BCDFGHJKLMNPQRSTVWXZÇ]*"," ":"\\b",$:"$"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d,"i"),u.length&&u.split(" ").forEach(y=>{y&&a.visemes.push(y)}),a})}),this.visemeDurations={aa:1,E:.95,I:.9,O:1.05,U:.95,PP:1.1,SS:1.25,TH:1,DD:1.05,FF:1,kk:1.2,nn:.88,RR:1.15,sil:1},this.specialDurations={" ":1,",":2.5,".":3.5,";":2.8,":":2.2,"!":3.2,"?":3.2,"-":.8,"'":.3,'"':.3,"(":1.5,")":1.5},this.digits=["zéro","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.ones=["","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.teens=["dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf"],this.tens=["","dix","vingt","trente","quarante","cinquante","soixante","soixante-dix","quatre-vingts","quatre-vingt-dix"],this.symbols={"%":"pourcent","€":"euros","&":"et","+":"plus",$:"dollars","=":"égale","@":"arobase","#":"dièse","°":"degrés"},this.symbolsReg=/[%€&\+\$=@#°]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_tens(n){if(n<10)return this.ones[n]||"";if(n>=10&&n<20)return this.teens[n-10];if(n>=70&&n<80){const e=n-60;return e===11?"soixante et onze":"soixante-"+this.teens[e-10]}else if(n>=90){const e=n-80;return e===11?"quatre-vingt-onze":"quatre-vingt-"+this.teens[e-10]}else{const e=Math.floor(n/10),t=n%10;return e===8&&t===0?"quatre-vingts":e===8?"quatre-vingt-"+this.ones[t]:(e===2||e===3||e===4||e===5||e===6)&&t===1?this.tens[e]+" et un":t===0?this.tens[e]:this.tens[e]+"-"+this.ones[t]}}convert_hundreds(n){if(n>=100){const e=Math.floor(n/100),t=n%100;let i="";return e===1?i="cent":(i=this.ones[e]+" cent",t===0&&(i+="s")),t>0&&(i+=" "+this.convert_tens(t)),i}else return this.convert_tens(n)}convert_thousands(n){if(n>=1e3){const e=Math.floor(n/1e3),t=n%1e3;let i="";return e===1?i="mille":i=this.convert_hundreds(e)+" mille",t>0&&(i+=" "+this.convert_hundreds(t)),i}else return this.convert_hundreds(n)}convert_millions(n){if(n>=1e6){const e=Math.floor(n/1e6),t=n%1e6;let i="";return e===1?i="un million":i=this.convert_hundreds(e)+" millions",t>0&&(i+=" "+this.convert_thousands(t)),i}else return this.convert_thousands(n)}convertNumberToWords(n){const e=String(n);return n==="0"||n===0?"zéro":e.startsWith("0")?this.convert_digit_by_digit(n):this.convert_millions(Number(n))}preProcessText(n){return n.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)[,.](\d)/g,"$1 virgule $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").replace(/'/g,"'").trim()}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o){let l=!1;for(let h=0;h<o.length;h++){const r=o[h];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(r.regex)){r.visemes.forEach(d=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===d){const p=.7*(this.visemeDurations[d]||1);e.durations[e.durations.length-1]+=p,t+=p}else{const p=this.visemeDurations[d]||1;e.visemes.push(d),e.times.push(t),e.durations.push(p),t+=p}}),e.i+=r.move,l=!0;break}}l||(e.i++,t+=this.specialDurations[s]||0)}else e.i++,t+=this.specialDurations[s]||0}return e}}const st=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFr:ot},Symbol.toStringTag,{value:"Module"}));class at{constructor(){this.visemes={a:"aa",e:"E",i:"I",o:"O",u:"U",y:"U",ä:"aa",ö:"O",å:"O",b:"PP",c:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS"},this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5},this.numbers=["nolla","yksi","kaksi","kolme","neljä","viisi","kuusi","seitsemän","kahdeksan","yhdeksän","kymmenen","yksitoista","kaksitoista","kolmetoista","neljätoista","viisitoista","kuusitoista","seitsemäntoista","kahdeksantoista","yhdeksäntoista"],this.symbols={"%":"prosenttia","€":"euroa","&":"ja","+":"plus",$:"dollaria"},this.symbolsReg=/[%€&\+\$]/g}numberToFinnishWords(n){const e=[];let t=parseFloat(n);if(t===void 0)return n;let i=(s,o,l,h,r)=>{if(s<o)return s;const u=Math.floor(s/o);return e.push(l+(u===1?h:this.numberToFinnishWords(u.toString())+r)),s-u*o};if(t<0&&(e.push("miinus "),t=Math.abs(t)),t=i(t,1e9," ","miljardi"," miljardia"),t=i(t,1e6," ","miljoona"," miljoonaa"),t=i(t,1e3,"","tuhat","tuhatta"),t=i(t,100," ","sata","sataa"),t>20&&(t=i(t,10,"","","kymmentä")),t>=1){let s=Math.floor(t);e.push(this.numbers[s]),t-=s}if(t>=0&&Math.abs(parseFloat(n))<1&&e.push("nolla"),t>0){let s=n.split(".");if(s.length>1){e.push(" pilkku");let o=[...s[s.length-1]];for(let l=0;l<o.length;l++)e.push(" "+this.numbers[o[l]])}}return e.join("").trim()}preProcessText(n){return n.replace(/[#_*\'\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)\,(\d)/g,"$1 pilkku $2").replace(/\d+/g,this.numberToFinnishWords.bind(this)).replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0307\u0309\u030b-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(n){let e={words:n,visemes:[],times:[],durations:[]},t=0;const i=[...n];for(let s=0;s<i.length;s++){const o=this.visemes[i[s].toLowerCase()];if(o)if(e.visemes.length&&e.visemes[e.visemes.length-1]===o){const l=.7*(this.visemeDurations[o]||1);e.durations[e.durations.length-1]+=l,t+=l}else{const l=this.visemeDurations[o]||1;e.visemes.push(o),e.times.push(t),e.durations.push(l),t+=l}else t+=this.specialDurations[i[s]]||0}return e}}const rt=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFi:at},Symbol.toStringTag,{value:"Module"}));class lt{constructor(){this.visemes={a:"aa",ą:"O",e:"E",ę:"E",ė:"E",i:"I",į:"I",o:"O",u:"U",ū:"U",ų:"U",y:"I",b:"PP",c:"SS",č:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",š:"CH",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS",ž:"SS"},this.durations={a:.95,ą:1.5,e:.9,ę:1.5,ė:1.5,i:.92,į:1.5,o:.96,u:.95,ū:1.5,ų:1.5,y:1.5,b:1.08,c:1.23,d:1.05,f:1,g:1.21,h:1.21,j:.92,k:1.21,l:.88,m:1.08,n:.88,p:1.08,q:1.21,r:.88,s:1.23,š:1.23,t:1.05,v:1,w:1,x:1.23,z:1.23,ž:1.23},this.pauses={" ":1,",":3,"-":.5},this.numbers=["nulis","vienas","du","trys","keturi","penki","šeši","septyni","aštuoni","devyni","dešimt","vienuolika","dvylika","trylika","keturiolika","penkiolika","šešiolika","septyniolika","aštuoniolika","devyniolika"],this.tens=[this.numbers[0],this.numbers[10],"dvidešimt","trisdešimt","keturiasdešimt","penkiasdešimt","šešiasdešimt","septyniasdešimt","aštuoniasdešimt","devyniasdešimt"]}numberToLithuanianWords(n){const e=[];let t=parseFloat(n);if(t===void 0)return n;let i=(s,o,l,h,r)=>{if(s<o)return s;const u=Math.floor(s/o);return u===1?e.push(this.numbers[1]):e.push(this.numberToLithuanianWords(u.toString())),u%10===1?e.push(l):u%10===0||u%100>10&&u%100<20?e.push(r):e.push(h),s-u*o};t<0&&(e.push("minus"),t=Math.abs(t)),t=i(t,1e9,"milijardas","milijardai","milijardų"),t=i(t,1e6,"milijonas","milijonai","milijonų"),t=i(t,1e3,"tūkstantis","tūkstančiai","tūkstančių"),t=i(t,100,"šimtas","šimtai","šimtų");for(let s=this.tens.length-1;s>=1;s--)if(t>=10*s){e.push(this.tens[s]),t=t-10*s;break}if(t>=1){let s=Math.floor(t);e.push(this.numbers[s]),t-=s}if(t>=0&&Math.abs(parseFloat(n))<1&&e.push(this.numbers[0]),t>0){let s=n.split(".");if(s.length>1){e.push("kablelis");let o=[...s[s.length-1]];for(let l=0;l<o.length;l++)e.push(this.numbers[o[l]])}}return e.join(" ").trim()}preProcessText(n){return n.replace(`/[#_*'":;]/g`,"").replaceAll("0 %","0 procentų ").replaceAll("1 %","1 procentas ").replaceAll("%"," procentai ").replaceAll("0 €","0 eurų ").replaceAll("1 €","1 euras ").replaceAll("€"," eurai ").replaceAll("0 $","0 dolerių ").replaceAll("1 $","1 doleris ").replaceAll("$"," doleriai ").replaceAll("&"," ir ").replaceAll("+"," pliusas ").replace(/(\d)\,(\d)/g,"$1 kablelis $2").replace(/\d+/g,this.numberToLithuanianWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0303\u0305\u0306\u0308-\u0327\u0329-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(n){let e={words:n,visemes:[],times:[],durations:[]},t=0;const i=[...n];for(let s=0;s<i.length;s++){const o=i[s].toLowerCase(),l=this.visemes[o];if(l)if(e.visemes.length&&e.visemes[e.visemes.length-1]===l){const h=.7*(this.durations[o]||1);e.durations[e.durations.length-1]+=h,t+=h}else{const h=this.durations[o]||1;e.visemes.push(l),e.times.push(t),e.durations.push(h),t+=h}else t+=this.pauses[i[s]]||0}return e}}const ut=Object.freeze(Object.defineProperty({__proto__:null,LipsyncLt:lt},Symbol.toStringTag,{value:"Module"})),ht=new URL("data:text/javascript;base64,Y2xhc3MgUGxheWJhY2tXb3JrbGV0IGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBzdGF0aWMgRlNNID0gewogICAgSURMRTogMCwKICAgIFBMQVlJTkc6IDEsCiAgfTsKCiAgY29uc3RydWN0b3Iob3B0aW9ucykgewogICAgc3VwZXIoKTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSB0aGlzLmhhbmRsZU1lc3NhZ2UuYmluZCh0aGlzKTsKCiAgICB0aGlzLl9zYW1wbGVSYXRlID0gb3B0aW9ucz8ucHJvY2Vzc29yT3B0aW9ucz8uc2FtcGxlUmF0ZSB8fCBzYW1wbGVSYXRlOwogICAgdGhpcy5fc2NhbGUgPSAxIC8gMzI3Njg7IC8vIFBDTTE2IC0+IGZsb2F0CgogICAgLy8gU2lsZW5jZSBkZXRlY3Rpb24gdGhyZXNob2xkICgxIHNlY29uZCkgYXMgYSBmYWxsYmFjayBzYWZldHkgbmV0CiAgICBjb25zdCBzaWxlbmNlRHVyYXRpb25TZWNvbmRzID0gMS4wOwogICAgdGhpcy5fc2lsZW5jZVRocmVzaG9sZEJsb2NrcyA9IE1hdGguY2VpbCgodGhpcy5fc2FtcGxlUmF0ZSAqIHNpbGVuY2VEdXJhdGlvblNlY29uZHMpIC8gMTI4KTsKCiAgICAvLyBNZXRyaWNzIGNvbmZpZ3VyYXRpb24gdmlhIG9wdGlvbnMKICAgIGNvbnN0IG1ldHJpY3NDZmcgPSBvcHRpb25zPy5wcm9jZXNzb3JPcHRpb25zPy5tZXRyaWNzIHx8IHt9OwogICAgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSBtZXRyaWNzQ2ZnLmVuYWJsZWQgIT09IGZhbHNlOwogICAgY29uc3QgaW50ZXJ2YWxIeiA9ICh0eXBlb2YgbWV0cmljc0NmZy5pbnRlcnZhbEh6ID09PSAibnVtYmVyIiAmJiBtZXRyaWNzQ2ZnLmludGVydmFsSHogPiAwKQogICAgICA/IG1ldHJpY3NDZmcuaW50ZXJ2YWxIeiA6IDI7CiAgICAvLyBNZXRyaWNzIHN0YXRlIChsb3ctb3ZlcmhlYWQpCiAgICB0aGlzLl9mcmFtZXNQcm9jZXNzZWQgPSAwOwogICAgdGhpcy5fdW5kZXJydW5CbG9ja3MgPSAwOwogICAgdGhpcy5fbWF4UXVldWVTYW1wbGVzID0gMDsKICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSAwOwogICAgLy8gQ29udmVydCB0byBmcmFtZXMgYmV0d2VlbiByZXBvcnRzCiAgICB0aGlzLl9tZXRyaWNzSW50ZXJ2YWxGcmFtZXMgPSBNYXRoLm1heCgxMjgsIE1hdGgucm91bmQodGhpcy5fc2FtcGxlUmF0ZSAvIGludGVydmFsSHopKTsKCiAgICB0aGlzLnJlc2V0KCk7CiAgfQoKICAvKioKICAgKiBSZXNldHMgdGhlIHdvcmtsZXQgdG8gaXRzIGluaXRpYWwgSURMRSBzdGF0ZS4KICAgKi8KICByZXNldCgpIHsKICAgIHRoaXMuX2J1ZmZlclF1ZXVlID0gW107CiAgICB0aGlzLl9jdXJyZW50Q2h1bmsgPSBudWxsOwogICAgdGhpcy5fY3VycmVudENodW5rT2Zmc2V0ID0gMDsKICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFOwoKICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IGZhbHNlOwogICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsKICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IGZhbHNlOwogICAgLy8gUmVzZXQgbWF4IHF1ZXVlIHRyYWNrZXIgb25seSB3aGVuIGdvaW5nIGlkbGUKICAgIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IDA7CiAgfQoKICBoYW5kbGVNZXNzYWdlKGV2ZW50KSB7CiAgICBjb25zdCB7IHR5cGUsIGRhdGEgfSA9IGV2ZW50LmRhdGE7CgogICAgLy8gSU5URVJSVVBUOiBUaGUgbWFpbiB0aHJlYWQgd2FudHMgdG8gc3RvcCBpbW1lZGlhdGVseS4KICAgIGlmICh0eXBlID09PSAic3RvcCIpIHsKICAgICAgdGhpcy5yZXNldCgpOwogICAgICAvLyBTZW5kIGZpbmFsIG1ldHJpY3Mgc2hvd2luZyBjbGVhcmVkIHN0YXRlCiAgICAgIGlmICh0aGlzLl9tZXRyaWNzRW5hYmxlZCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICB0eXBlOiAibWV0cmljcyIsCiAgICAgICAgICAgIGRhdGE6IHsKICAgICAgICAgICAgICBzdGF0ZTogUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFLAogICAgICAgICAgICAgIHF1ZXVlZFNhbXBsZXM6IDAsCiAgICAgICAgICAgICAgcXVldWVkTXM6IDAsCiAgICAgICAgICAgICAgbWF4UXVldWVkTXM6IE1hdGgucm91bmQoKHRoaXMuX21heFF1ZXVlU2FtcGxlcyAvIHRoaXMuX3NhbXBsZVJhdGUpICogMTAwMCksCiAgICAgICAgICAgICAgdW5kZXJydW5CbG9ja3M6IHRoaXMuX3VuZGVycnVuQmxvY2tzLAogICAgICAgICAgICAgIGZyYW1lc1Byb2Nlc3NlZDogdGhpcy5fZnJhbWVzUHJvY2Vzc2VkCiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgIH0gY2F0Y2ggKF8pIHsgfQogICAgICB9CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBNYWluIHRocmVhZCBoYXMgc2lnbmFsZWQgdGhhdCBubyBtb3JlIGF1ZGlvIGNodW5rcyB3aWxsIGJlIHNlbnQgZm9yIHRoaXMgdXR0ZXJhbmNlLgogICAgaWYgKHR5cGUgPT09ICJuby1tb3JlLWRhdGEiKSB7CiAgICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IHRydWU7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBVcGRhdGUgbWV0cmljcyBjb25maWd1cmF0aW9uIGF0IHJ1bnRpbWUKICAgIGlmICh0eXBlID09PSAiY29uZmlnLW1ldHJpY3MiICYmIGRhdGEgJiYgdHlwZW9mIGRhdGEgPT09ICJvYmplY3QiKSB7CiAgICAgIGlmICgiZW5hYmxlZCIgaW4gZGF0YSkgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSAhIWRhdGEuZW5hYmxlZDsKICAgICAgaWYgKHR5cGVvZiBkYXRhLmludGVydmFsSHogPT09ICJudW1iZXIiICYmIGRhdGEuaW50ZXJ2YWxIeiA+IDApIHsKICAgICAgICBjb25zdCBpbnRlcnZhbEh6ID0gZGF0YS5pbnRlcnZhbEh6OwogICAgICAgIHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcyA9IE1hdGgubWF4KDEyOCwgTWF0aC5yb3VuZCh0aGlzLl9zYW1wbGVSYXRlIC8gaW50ZXJ2YWxIeikpOwogICAgICB9CiAgICAgIC8vIFJlc2V0IHBhY2luZyBzbyB0aGUgbmV4dCByZXBvcnQgYWxpZ25zIHdpdGggbmV3IGludGVydmFsCiAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBOZXcgYXVkaW8gZGF0YSBoYXMgYXJyaXZlZC4KICAgIGlmICh0eXBlID09PSAiYXVkaW9EYXRhIiAmJiBkYXRhIGluc3RhbmNlb2YgQXJyYXlCdWZmZXIpIHsKICAgICAgdGhpcy5fbm9Nb3JlRGF0YVJlY2VpdmVkID0gZmFsc2U7CiAgICAgIC8vIElmIHdlIHdlcmUgaWRsZSwgdGhpcyBuZXcgZGF0YSBraWNrcyBvZmYgdGhlIHBsYXliYWNrLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uSURMRSkgewogICAgICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HOwogICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7IHR5cGU6ICJwbGF5YmFjay1zdGFydGVkIiB9KTsKICAgICAgfQoKICAgICAgLy8gV2Ugb25seSBxdWV1ZSBkYXRhIGlmIHdlIGFyZSBpbiB0aGUgUExBWUlORyBzdGF0ZS4gVGhpcyBwcmV2ZW50cwogICAgICAvLyBkYXRhIGZyb20gYSBwcmV2aW91cywgaW50ZXJydXB0ZWQgc3RyZWFtIGZyb20gbGluZ2VyaW5nLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uUExBWUlORykgewogICAgICAgIC8vIFN0b3JlIGFzIEludDE2QXJyYXkgdmlldyB0byBhdm9pZCBjb25zdHJ1Y3RpbmcgaXQgaW4gcHJvY2VzcygpCiAgICAgICAgdGhpcy5fYnVmZmVyUXVldWUucHVzaChuZXcgSW50MTZBcnJheShkYXRhKSk7CiAgICAgICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsgLy8gUmVzZXQgc2lsZW5jZSBjb3VudGVyIG9uIG5ldyBkYXRhCiAgICAgIH0KICAgIH0KICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBvdXRwdXRDaGFubmVsID0gb3V0cHV0c1swXT8uWzBdOwogICAgaWYgKCFvdXRwdXRDaGFubmVsKSB7CiAgICAgIHJldHVybiB0cnVlOyAvLyBLZWVwIGFsaXZlIGV2ZW4gaWYgb3V0cHV0IGlzIHRlbXBvcmFyaWx5IGRpc2Nvbm5lY3RlZAogICAgfQoKICAgIC8vIElmIHdlIGFyZSBub3QgcGxheWluZywganVzdCBvdXRwdXQgc2lsZW5jZSBhbmQgd2FpdC4KICAgIGlmICh0aGlzLl9zdGF0ZSAhPT0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HKSB7CiAgICAgIG91dHB1dENoYW5uZWwuZmlsbCgwKTsKICAgICAgcmV0dXJuIHRydWU7IC8vIEFsd2F5cyByZXR1cm4gdHJ1ZSB0byBrZWVwIHRoZSBwcm9jZXNzb3IgYWxpdmUKICAgIH0KCiAgICAvLyBDb3JlIFBMQVlJTkcgTG9naWMKICAgIGNvbnN0IGJsb2NrU2l6ZSA9IG91dHB1dENoYW5uZWwubGVuZ3RoOwogICAgbGV0IHNhbXBsZXNDb3BpZWQgPSAwOwoKICAgIHdoaWxlIChzYW1wbGVzQ29waWVkIDwgYmxvY2tTaXplKSB7CiAgICAgIGlmICghdGhpcy5fY3VycmVudENodW5rIHx8IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCA+PSB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoKSB7CiAgICAgICAgaWYgKHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aCA+IDApIHsKICAgICAgICAgIHRoaXMuX2N1cnJlbnRDaHVuayA9IHRoaXMuX2J1ZmZlclF1ZXVlLnNoaWZ0KCk7CiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQgPSAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAvLyBCdWZmZXIgaXMgZW1wdHkuIENoZWNrIGZvciBlbmQgY29uZGl0aW9ucy4KICAgICAgICAgIGNvbnN0IGlzVGltZWRPdXQgPSB0aGlzLl9zaWxlbmNlRnJhbWVzQ291bnQgPiB0aGlzLl9zaWxlbmNlVGhyZXNob2xkQmxvY2tzOwoKICAgICAgICAgIGlmICh0aGlzLl9ub01vcmVEYXRhUmVjZWl2ZWQgfHwgaXNUaW1lZE91dCkgewogICAgICAgICAgICAvLyBFTkQgT0YgUExBWUJBQ0s6IEVpdGhlciBleHBsaWNpdGx5IHNpZ25hbGVkIG9yIHRpbWVkIG91dC4KICAgICAgICAgICAgaWYgKCF0aGlzLl9oYXNTZW50RW5kZWQpIHsKICAgICAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoeyB0eXBlOiAicGxheWJhY2stZW5kZWQiIH0pOwogICAgICAgICAgICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy8gU2VuZCBmaW5hbCBtZXRyaWNzIHNob3dpbmcgY2xlYXJlZCBzdGF0ZQogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgICAgdHlwZTogIm1ldHJpY3MiLAogICAgICAgICAgICAgICAgICBkYXRhOiB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGU6IFBsYXliYWNrV29ya2xldC5GU00uSURMRSwKICAgICAgICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzOiAwLAogICAgICAgICAgICAgICAgICAgIHF1ZXVlZE1zOiAwLAogICAgICAgICAgICAgICAgICAgIG1heFF1ZXVlZE1zOiBNYXRoLnJvdW5kKCh0aGlzLl9tYXhRdWV1ZVNhbXBsZXMgLyB0aGlzLl9zYW1wbGVSYXRlKSAqIDEwMDApLAogICAgICAgICAgICAgICAgICAgIHVuZGVycnVuQmxvY2tzOiB0aGlzLl91bmRlcnJ1bkJsb2NrcywKICAgICAgICAgICAgICAgICAgICBmcmFtZXNQcm9jZXNzZWQ6IHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZAogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICB9IGNhdGNoIChfKSB7IH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnJlc2V0KCk7IC8vIFJlc2V0IHRvIElETEUgc3RhdGUgZm9yIHJldXNlCiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIC8vIEJVRkZFUiBVTkRFUlJVTiAoTEFHKTogUGxheSBzaWxlbmNlIGFuZCB3YWl0IGZvciBtb3JlIGRhdGEuCiAgICAgICAgICAgIHRoaXMuX3NpbGVuY2VGcmFtZXNDb3VudCsrOwogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHRoaXMuX3VuZGVycnVuQmxvY2tzKys7CiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KCiAgICAgIC8vIElmIHdlIGhhdmUgYSBjaHVuayAoY291bGQgYmUgYSBuZXcgb25lIGZyb20gdGhlIGxvZ2ljIGFib3ZlKSwgcHJvY2VzcyBpdC4KICAgICAgaWYgKHRoaXMuX2N1cnJlbnRDaHVuaykgewogICAgICAgIGNvbnN0IHNhbXBsZXNUb0NvcHkgPSBNYXRoLm1pbigKICAgICAgICAgIGJsb2NrU2l6ZSAtIHNhbXBsZXNDb3BpZWQsCiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoIC0gdGhpcy5fY3VycmVudENodW5rT2Zmc2V0CiAgICAgICAgKTsKICAgICAgICAvLyBEaXJlY3RseSB3cml0ZSB0byBvdXRwdXRDaGFubmVsIHRvIGF2b2lkIGV4dHJhIGNvcHkKICAgICAgICBjb25zdCBzcmMgPSB0aGlzLl9jdXJyZW50Q2h1bms7CiAgICAgICAgY29uc3QgYmFzZVNyYyA9IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldDsKICAgICAgICBjb25zdCBiYXNlRHN0ID0gc2FtcGxlc0NvcGllZDsKICAgICAgICBjb25zdCBzY2FsZSA9IHRoaXMuX3NjYWxlOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc2FtcGxlc1RvQ29weTsgaSsrKSB7CiAgICAgICAgICBvdXRwdXRDaGFubmVsW2Jhc2VEc3QgKyBpXSA9IHNyY1tiYXNlU3JjICsgaV0gKiBzY2FsZTsKICAgICAgICB9CgogICAgICAgIHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCArPSBzYW1wbGVzVG9Db3B5OwogICAgICAgIHNhbXBsZXNDb3BpZWQgKz0gc2FtcGxlc1RvQ29weTsKICAgICAgfQogICAgfQoKICAgIC8vIFplcm8tZmlsbCB0aGUgcmVtYWluZGVyLCBpZiBhbnksIG9uY2UgcGVyIGJsb2NrCiAgICBpZiAoc2FtcGxlc0NvcGllZCA8IGJsb2NrU2l6ZSkgewogICAgICBvdXRwdXRDaGFubmVsLmZpbGwoMCwgc2FtcGxlc0NvcGllZCk7CiAgICB9CgogICAgLy8gVXBkYXRlIG1ldHJpY3MgKG9wdGlvbmFsKQogICAgaWYgKHRoaXMuX21ldHJpY3NFbmFibGVkKSB7CiAgICAgIHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZCArPSBibG9ja1NpemU7CgogICAgICAvLyBUcmFjayBxdWV1ZSBkZXB0aCBpbiBzYW1wbGVzIChhcHByb3hpbWF0ZSkKICAgICAgbGV0IHF1ZXVlZFNhbXBsZXMgPSAwOwogICAgICBpZiAodGhpcy5fY3VycmVudENodW5rKSBxdWV1ZWRTYW1wbGVzICs9IE1hdGgubWF4KDAsIHRoaXMuX2N1cnJlbnRDaHVuay5sZW5ndGggLSB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQpOwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aDsgaSsrKSBxdWV1ZWRTYW1wbGVzICs9IHRoaXMuX2J1ZmZlclF1ZXVlW2ldLmxlbmd0aDsKICAgICAgaWYgKHF1ZXVlZFNhbXBsZXMgPiB0aGlzLl9tYXhRdWV1ZVNhbXBsZXMpIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IHF1ZXVlZFNhbXBsZXM7CgogICAgICAvLyBQZXJpb2RpY2FsbHkgc2VuZCBtZXRyaWNzIHRvIG1haW4gdGhyZWFkCiAgICAgIGlmICh0aGlzLl9mcmFtZXNQcm9jZXNzZWQgLSB0aGlzLl9sYXN0TWV0cmljc1NlbnRBdEZyYW1lID49IHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcykgewogICAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgICAgdHJ5IHsKICAgICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgIHR5cGU6ICJtZXRyaWNzIiwKICAgICAgICAgICAgZGF0YTogewogICAgICAgICAgICAgIHN0YXRlOiB0aGlzLl9zdGF0ZSwKICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzLAogICAgICAgICAgICAgIHF1ZXVlZE1zOiBNYXRoLnJvdW5kKChxdWV1ZWRTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICBtYXhRdWV1ZWRNczogTWF0aC5yb3VuZCgodGhpcy5fbWF4UXVldWVTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICB1bmRlcnJ1bkJsb2NrczogdGhpcy5fdW5kZXJydW5CbG9ja3MsCiAgICAgICAgICAgICAgZnJhbWVzUHJvY2Vzc2VkOiB0aGlzLl9mcmFtZXNQcm9jZXNzZWQKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgfSBjYXRjaCAoXykgeyB9CiAgICAgICAgLy8gRG9uJ3QgcmVzZXQgbWF4IHRyYWNrZXIgLSBrZWVwIHNlc3Npb24gcGVhayB1bnRpbCBpZGxlCiAgICAgIH0KICAgIH0KCiAgICAvLyBBTFdBWVMgcmV0dXJuIHRydWUgdG8ga2VlcCB0aGUgcHJvY2Vzc29yIGFsaXZlIGZvciByZXVzZS4KICAgIHJldHVybiB0cnVlOwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoInBsYXliYWNrLXdvcmtsZXQiLCBQbGF5YmFja1dvcmtsZXQpOwo=",typeof document>"u"?require("url").pathToFileURL(__filename).href:He&&He.tagName.toUpperCase()==="SCRIPT"&&He.src||new URL("index.cjs",document.baseURI).href),Te={en:tt,de:it,fr:st,fi:rt,lt:ut},_=new g.Quaternion,G=new g.Euler,fe=new g.Vector3,xe=new g.Vector3,Be=new g.Box3;new g.Matrix4;new g.Matrix4;new g.Vector3;new g.Vector3(0,0,1);const ct=new g.Vector3(1,0,0);new g.Vector3(0,1,0);new g.Vector3(0,0,1);class Me{constructor(n,e=null){this.nodeAvatar=n,this.opt={jwtGet:null,ttsEndpoint:"",ttsApikey:null,ttsTrimStart:0,ttsTrimEnd:400,ttsLang:"fi-FI",ttsVoice:"fi-FI-Standard-A",ttsRate:1,ttsPitch:0,ttsVolume:.3,mixerGainSpeech:1.2,mixerGainBackground:null,lipsyncLang:"fi",lipsyncModules:["fi","en","lt"],pcmSampleRate:22050,modelRoot:"Armature",modelPixelRatio:1,modelFPS:30,modelMovementFactor:1,cameraView:"full",dracoEnabled:!1,dracoDecoderPath:"https://www.gstatic.com/draco/v1/decoders/",cameraDistance:0,cameraX:0,cameraY:0,cameraRotateX:0,cameraRotateY:0,cameraRotateEnable:!0,cameraPanEnable:!1,cameraZoomEnable:!1,lightAmbientColor:16777215,lightAmbientIntensity:1.25,lightDirectColor:8947882,lightDirectIntensity:12,lightDirectPhi:1,lightDirectTheta:2,lightSpotIntensity:0,lightSpotColor:3377407,lightSpotPhi:.1,lightSpotTheta:4,lightSpotDispersion:1,avatarMood:"neutral",avatarMute:!1,avatarIdleEyeContact:.6,avatarIdleHeadMove:.5,avatarSpeakingEyeContact:.8,avatarSpeakingHeadMove:.5,avatarIgnoreCamera:!1,listeningSilenceThresholdLevel:40,listeningSilenceThresholdMs:2e3,listeningSilenceDurationMax:1e4,listeningActiveThresholdLevel:75,listeningActiveThresholdMs:300,listeningActiveDurationMax:24e4,update:null,avatarOnly:!1,avatarOnlyScene:null,avatarOnlyCamera:null,statsNode:null,statsStyle:null},Object.assign(this.opt,e||{}),this.opt.statsNode&&(this.stats=new Qe,this.opt.statsStyle&&(this.stats.dom.style.cssText=this.opt.statsStyle),this.opt.statsNode.appendChild(this.stats.dom)),this.poseTemplates={side:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.003,y:-.017,z:.1},"Spine.rotation":{x:-.103,y:-.002,z:-.063},"Spine1.rotation":{x:.042,y:-.02,z:-.069},"Spine2.rotation":{x:.131,y:-.012,z:-.065},"Neck.rotation":{x:.027,y:.006,z:0},"Head.rotation":{x:.077,y:-.065,z:0},"LeftShoulder.rotation":{x:1.599,y:.084,z:-1.77},"LeftArm.rotation":{x:1.364,y:.052,z:-.044},"LeftForeArm.rotation":{x:.002,y:-.007,z:.331},"LeftHand.rotation":{x:.104,y:-.067,z:-.174},"LeftHandThumb1.rotation":{x:.231,y:.258,z:.355},"LeftHandThumb2.rotation":{x:-.106,y:-.339,z:-.454},"LeftHandThumb3.rotation":{x:-.02,y:-.142,z:-.004},"LeftHandIndex1.rotation":{x:.148,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.326,y:-.049,z:-.029},"LeftHandIndex3.rotation":{x:.247,y:-.053,z:-.073},"LeftHandMiddle1.rotation":{x:.238,y:-.057,z:-.089},"LeftHandMiddle2.rotation":{x:.469,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.206,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.187,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.579,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.272,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.405,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.613,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.268,y:.094,z:-.081},"RightShoulder.rotation":{x:1.541,y:.192,z:1.775},"RightArm.rotation":{x:1.273,y:-.352,z:-.067},"RightForeArm.rotation":{x:-.011,y:-.031,z:-.357},"RightHand.rotation":{x:-.008,y:.312,z:-.028},"RightHandThumb1.rotation":{x:.23,y:-.258,z:-.355},"RightHandThumb2.rotation":{x:-.107,y:.339,z:.454},"RightHandThumb3.rotation":{x:-.02,y:.142,z:.004},"RightHandIndex1.rotation":{x:.148,y:-.031,z:.069},"RightHandIndex2.rotation":{x:.326,y:.049,z:.029},"RightHandIndex3.rotation":{x:.247,y:.053,z:.073},"RightHandMiddle1.rotation":{x:.237,y:.057,z:.089},"RightHandMiddle2.rotation":{x:.469,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.206,y:.015,z:.017},"RightHandRing1.rotation":{x:.204,y:.086,z:.135},"RightHandRing2.rotation":{x:.579,y:-.02,z:.098},"RightHandRing3.rotation":{x:.272,y:-.021,z:.063},"RightHandPinky1.rotation":{x:.404,y:.182,z:.137},"RightHandPinky2.rotation":{x:.613,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.268,y:-.094,z:.081},"LeftUpLeg.rotation":{x:.096,y:.209,z:2.983},"LeftLeg.rotation":{x:-.053,y:.042,z:-.017},"LeftFoot.rotation":{x:1.091,y:.15,z:.026},"LeftToeBase.rotation":{x:.469,y:-.07,z:-.015},"RightUpLeg.rotation":{x:-.307,y:-.219,z:2.912},"RightLeg.rotation":{x:-.359,y:.164,z:.015},"RightFoot.rotation":{x:1.035,y:.11,z:.005},"RightToeBase.rotation":{x:.467,y:.07,z:.015}}},hip:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.036,y:.09,z:.135},"Spine.rotation":{x:.076,y:-.035,z:.01},"Spine1.rotation":{x:-.096,y:.013,z:-.094},"Spine2.rotation":{x:-.014,y:.002,z:-.097},"Neck.rotation":{x:.034,y:-.051,z:-.075},"Head.rotation":{x:.298,y:-.1,z:.154},"LeftShoulder.rotation":{x:1.694,y:.011,z:-1.68},"LeftArm.rotation":{x:1.343,y:.177,z:-.153},"LeftForeArm.rotation":{x:-.049,y:.134,z:.351},"LeftHand.rotation":{x:.057,y:-.189,z:-.026},"LeftHandThumb1.rotation":{x:.368,y:-.066,z:.438},"LeftHandThumb2.rotation":{x:-.156,y:.029,z:-.369},"LeftHandThumb3.rotation":{x:.034,y:-.009,z:.016},"LeftHandIndex1.rotation":{x:.157,y:-.002,z:-.171},"LeftHandIndex2.rotation":{x:.099,y:0,z:0},"LeftHandIndex3.rotation":{x:.1,y:0,z:0},"LeftHandMiddle1.rotation":{x:.222,y:-.019,z:-.16},"LeftHandMiddle2.rotation":{x:.142,y:0,z:0},"LeftHandMiddle3.rotation":{x:.141,y:0,z:0},"LeftHandRing1.rotation":{x:.333,y:-.039,z:-.174},"LeftHandRing2.rotation":{x:.214,y:0,z:0},"LeftHandRing3.rotation":{x:.213,y:0,z:0},"LeftHandPinky1.rotation":{x:.483,y:-.069,z:-.189},"LeftHandPinky2.rotation":{x:.312,y:0,z:0},"LeftHandPinky3.rotation":{x:.309,y:0,z:0},"RightShoulder.rotation":{x:1.597,y:.012,z:1.816},"RightArm.rotation":{x:.618,y:-1.274,z:-.266},"RightForeArm.rotation":{x:-.395,y:-.097,z:-1.342},"RightHand.rotation":{x:-.816,y:-.057,z:-.976},"RightHandThumb1.rotation":{x:.42,y:.23,z:-1.172},"RightHandThumb2.rotation":{x:-.027,y:.361,z:.122},"RightHandThumb3.rotation":{x:.076,y:.125,z:-.371},"RightHandIndex1.rotation":{x:-.158,y:-.045,z:.033},"RightHandIndex2.rotation":{x:.391,y:.051,z:.025},"RightHandIndex3.rotation":{x:.317,y:.058,z:.07},"RightHandMiddle1.rotation":{x:.486,y:.066,z:.014},"RightHandMiddle2.rotation":{x:.718,y:.055,z:.07},"RightHandMiddle3.rotation":{x:.453,y:.019,z:.013},"RightHandRing1.rotation":{x:.591,y:.241,z:.11},"RightHandRing2.rotation":{x:1.014,y:.023,z:.097},"RightHandRing3.rotation":{x:.708,y:.008,z:.066},"RightHandPinky1.rotation":{x:1.02,y:.305,z:.051},"RightHandPinky2.rotation":{x:1.187,y:-.028,z:.191},"RightHandPinky3.rotation":{x:.872,y:-.031,z:.121},"LeftUpLeg.rotation":{x:-.095,y:-.058,z:-3.338},"LeftLeg.rotation":{x:-.366,y:.287,z:-.021},"LeftFoot.rotation":{x:1.131,y:.21,z:.176},"LeftToeBase.rotation":{x:.739,y:-.068,z:-.001},"RightUpLeg.rotation":{x:-.502,y:.362,z:3.153},"RightLeg.rotation":{x:-1.002,y:.109,z:.008},"RightFoot.rotation":{x:.626,y:-.097,z:-.194},"RightToeBase.rotation":{x:1.33,y:.288,z:-.078}}},turn:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.07,y:-.604,z:-.004},"Spine.rotation":{x:-.007,y:.003,z:.071},"Spine1.rotation":{x:-.053,y:.024,z:-.06},"Spine2.rotation":{x:.074,y:.013,z:-.068},"Neck.rotation":{x:.03,y:.186,z:-.077},"Head.rotation":{x:.045,y:.243,z:-.086},"LeftShoulder.rotation":{x:1.717,y:-.085,z:-1.761},"LeftArm.rotation":{x:1.314,y:.07,z:-.057},"LeftForeArm.rotation":{x:-.151,y:.714,z:.302},"LeftHand.rotation":{x:-.069,y:.003,z:-.118},"LeftHandThumb1.rotation":{x:.23,y:.258,z:.354},"LeftHandThumb2.rotation":{x:-.107,y:-.338,z:-.455},"LeftHandThumb3.rotation":{x:-.015,y:-.142,z:.002},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.323,y:-.049,z:-.028},"LeftHandIndex3.rotation":{x:.249,y:-.053,z:-.074},"LeftHandMiddle1.rotation":{x:.235,y:-.057,z:-.088},"LeftHandMiddle2.rotation":{x:.468,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.203,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.185,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.578,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.27,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.404,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.612,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.267,y:.094,z:-.081},"RightShoulder.rotation":{x:1.605,y:.17,z:1.625},"RightArm.rotation":{x:1.574,y:-.655,z:.388},"RightForeArm.rotation":{x:-.36,y:-.849,z:-.465},"RightHand.rotation":{x:.114,y:.416,z:-.069},"RightHandThumb1.rotation":{x:.486,y:.009,z:-.492},"RightHandThumb2.rotation":{x:-.073,y:-.01,z:.284},"RightHandThumb3.rotation":{x:-.054,y:-.006,z:.209},"RightHandIndex1.rotation":{x:.245,y:-.014,z:.052},"RightHandIndex2.rotation":{x:.155,y:0,z:0},"RightHandIndex3.rotation":{x:.153,y:0,z:0},"RightHandMiddle1.rotation":{x:.238,y:.004,z:.028},"RightHandMiddle2.rotation":{x:.15,y:0,z:0},"RightHandMiddle3.rotation":{x:.149,y:0,z:0},"RightHandRing1.rotation":{x:.267,y:.012,z:.007},"RightHandRing2.rotation":{x:.169,y:0,z:0},"RightHandRing3.rotation":{x:.167,y:0,z:0},"RightHandPinky1.rotation":{x:.304,y:.018,z:-.021},"RightHandPinky2.rotation":{x:.192,y:0,z:0},"RightHandPinky3.rotation":{x:.19,y:0,z:0},"LeftUpLeg.rotation":{x:-.001,y:-.058,z:-3.238},"LeftLeg.rotation":{x:-.29,y:.058,z:-.021},"LeftFoot.rotation":{x:1.288,y:.168,z:.183},"LeftToeBase.rotation":{x:.363,y:-.09,z:-.01},"RightUpLeg.rotation":{x:-.1,y:.36,z:3.062},"RightLeg.rotation":{x:-.67,y:-.304,z:.043},"RightFoot.rotation":{x:1.195,y:-.159,z:-.294},"RightToeBase.rotation":{x:.737,y:.164,z:-.002}}},bend:{bend:!0,standing:!0,props:{"Hips.position":{x:-.007,y:.943,z:-.001},"Hips.rotation":{x:1.488,y:-.633,z:1.435},"Spine.rotation":{x:-.126,y:.007,z:-.057},"Spine1.rotation":{x:-.134,y:.009,z:.01},"Spine2.rotation":{x:-.019,y:0,z:-.002},"Neck.rotation":{x:-.159,y:.572,z:-.108},"Head.rotation":{x:-.064,y:.716,z:-.257},"RightShoulder.rotation":{x:1.625,y:-.043,z:1.382},"RightArm.rotation":{x:.746,y:-.96,z:-1.009},"RightForeArm.rotation":{x:-.199,y:-.528,z:-.38},"RightHand.rotation":{x:-.261,y:-.043,z:-.027},"RightHandThumb1.rotation":{x:.172,y:-.138,z:-.445},"RightHandThumb2.rotation":{x:-.158,y:.327,z:.545},"RightHandThumb3.rotation":{x:-.062,y:.138,z:.152},"RightHandIndex1.rotation":{x:.328,y:-.005,z:.132},"RightHandIndex2.rotation":{x:.303,y:.049,z:.028},"RightHandIndex3.rotation":{x:.241,y:.046,z:.077},"RightHandMiddle1.rotation":{x:.309,y:.074,z:.089},"RightHandMiddle2.rotation":{x:.392,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.199,y:.014,z:.019},"RightHandRing1.rotation":{x:.239,y:.143,z:.091},"RightHandRing2.rotation":{x:.275,y:-.02,z:.097},"RightHandRing3.rotation":{x:.248,y:-.023,z:.061},"RightHandPinky1.rotation":{x:.211,y:.154,z:.029},"RightHandPinky2.rotation":{x:.348,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.21,y:-.091,z:.065},"LeftShoulder.rotation":{x:1.626,y:-.027,z:-1.367},"LeftArm.rotation":{x:1.048,y:.737,z:.712},"LeftForeArm.rotation":{x:-.508,y:.879,z:.625},"LeftHand.rotation":{x:.06,y:-.243,z:-.079},"LeftHandThumb1.rotation":{x:.187,y:-.072,z:.346},"LeftHandThumb2.rotation":{x:-.066,y:.008,z:-.256},"LeftHandThumb3.rotation":{x:-.085,y:.014,z:-.334},"LeftHandIndex1.rotation":{x:-.1,y:.016,z:-.058},"LeftHandIndex2.rotation":{x:.334,y:0,z:0},"LeftHandIndex3.rotation":{x:.281,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.056,y:0,z:0},"LeftHandMiddle2.rotation":{x:.258,y:0,z:0},"LeftHandMiddle3.rotation":{x:.26,y:0,z:0},"LeftHandRing1.rotation":{x:-.067,y:-.002,z:.008},"LeftHandRing2.rotation":{x:.259,y:0,z:0},"LeftHandRing3.rotation":{x:.276,y:0,z:0},"LeftHandPinky1.rotation":{x:-.128,y:-.007,z:.042},"LeftHandPinky2.rotation":{x:.227,y:0,z:0},"LeftHandPinky3.rotation":{x:.145,y:0,z:0},"RightUpLeg.rotation":{x:-1.507,y:.2,z:-3.043},"RightLeg.rotation":{x:-.689,y:-.124,z:.017},"RightFoot.rotation":{x:.909,y:.008,z:-.093},"RightToeBase.rotation":{x:.842,y:.075,z:-.008},"LeftUpLeg.rotation":{x:-1.449,y:-.2,z:3.018},"LeftLeg.rotation":{x:-.74,y:-.115,z:-.008},"LeftFoot.rotation":{x:1.048,y:-.058,z:.117},"LeftToeBase.rotation":{x:.807,y:-.067,z:.003}}},back:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.732,y:-1.463,z:-.637},"Spine.rotation":{x:-.171,y:.106,z:.157},"Spine1.rotation":{x:-.044,y:.138,z:-.059},"Spine2.rotation":{x:.082,y:.133,z:-.074},"Neck.rotation":{x:.39,y:.591,z:-.248},"Head.rotation":{x:-.001,y:.596,z:-.057},"LeftShoulder.rotation":{x:1.676,y:.007,z:-1.892},"LeftArm.rotation":{x:-5.566,y:1.188,z:-.173},"LeftForeArm.rotation":{x:-.673,y:-.105,z:1.702},"LeftHand.rotation":{x:-.469,y:-.739,z:.003},"LeftHandThumb1.rotation":{x:.876,y:.274,z:.793},"LeftHandThumb2.rotation":{x:.161,y:-.23,z:-.172},"LeftHandThumb3.rotation":{x:.078,y:.027,z:.156},"LeftHandIndex1.rotation":{x:-.085,y:-.002,z:.009},"LeftHandIndex2.rotation":{x:.176,y:0,z:-.002},"LeftHandIndex3.rotation":{x:-.036,y:.001,z:-.035},"LeftHandMiddle1.rotation":{x:.015,y:.144,z:-.076},"LeftHandMiddle2.rotation":{x:.378,y:-.007,z:-.077},"LeftHandMiddle3.rotation":{x:-.141,y:-.001,z:.031},"LeftHandRing1.rotation":{x:.039,y:.02,z:-.2},"LeftHandRing2.rotation":{x:.25,y:-.002,z:-.073},"LeftHandRing3.rotation":{x:.236,y:.006,z:-.075},"LeftHandPinky1.rotation":{x:.172,y:-.033,z:-.275},"LeftHandPinky2.rotation":{x:.216,y:.043,z:-.054},"LeftHandPinky3.rotation":{x:.325,y:.078,z:-.13},"RightShoulder.rotation":{x:2.015,y:-.168,z:1.706},"RightArm.rotation":{x:.203,y:-1.258,z:-.782},"RightForeArm.rotation":{x:-.658,y:-.133,z:-1.401},"RightHand.rotation":{x:-1.504,y:.375,z:-.005},"RightHandThumb1.rotation":{x:.413,y:-.158,z:-1.121},"RightHandThumb2.rotation":{x:-.142,y:-.008,z:.209},"RightHandThumb3.rotation":{x:-.091,y:.021,z:.142},"RightHandIndex1.rotation":{x:-.167,y:.014,z:-.072},"RightHandIndex2.rotation":{x:.474,y:.009,z:.051},"RightHandIndex3.rotation":{x:.115,y:.006,z:.047},"RightHandMiddle1.rotation":{x:.385,y:.019,z:.144},"RightHandMiddle2.rotation":{x:.559,y:.035,z:.101},"RightHandMiddle3.rotation":{x:.229,y:0,z:.027},"RightHandRing1.rotation":{x:.48,y:.026,z:.23},"RightHandRing2.rotation":{x:.772,y:.038,z:.109},"RightHandRing3.rotation":{x:.622,y:.039,z:.106},"RightHandPinky1.rotation":{x:.767,y:.288,z:.353},"RightHandPinky2.rotation":{x:.886,y:.049,z:.122},"RightHandPinky3.rotation":{x:.662,y:.044,z:.113},"LeftUpLeg.rotation":{x:-.206,y:-.268,z:-3.343},"LeftLeg.rotation":{x:-.333,y:.757,z:-.043},"LeftFoot.rotation":{x:1.049,y:.167,z:.287},"LeftToeBase.rotation":{x:.672,y:-.069,z:-.004},"RightUpLeg.rotation":{x:.055,y:-.226,z:3.037},"RightLeg.rotation":{x:-.559,y:.39,z:-.001},"RightFoot.rotation":{x:1.2,y:.133,z:.085},"RightToeBase.rotation":{x:.92,y:.093,z:-.013}}},straight:{standing:!0,props:{"Hips.position":{x:0,y:.989,z:.001},"Hips.rotation":{x:.047,y:.007,z:-.007},"Spine.rotation":{x:-.143,y:-.007,z:.005},"Spine1.rotation":{x:-.043,y:-.014,z:.012},"Spine2.rotation":{x:.072,y:-.013,z:.013},"Neck.rotation":{x:.048,y:-.003,z:.012},"Head.rotation":{x:.05,y:-.02,z:-.017},"LeftShoulder.rotation":{x:1.62,y:-.166,z:-1.605},"LeftArm.rotation":{x:1.275,y:.544,z:-.092},"LeftForeArm.rotation":{x:0,y:0,z:.302},"LeftHand.rotation":{x:-.225,y:-.154,z:.11},"LeftHandThumb1.rotation":{x:.435,y:-.044,z:.457},"LeftHandThumb2.rotation":{x:-.028,y:.002,z:-.246},"LeftHandThumb3.rotation":{x:-.236,y:-.025,z:.113},"LeftHandIndex1.rotation":{x:.218,y:.008,z:-.081},"LeftHandIndex2.rotation":{x:.165,y:-.001,z:-.017},"LeftHandIndex3.rotation":{x:.165,y:-.001,z:-.017},"LeftHandMiddle1.rotation":{x:.235,y:-.011,z:-.065},"LeftHandMiddle2.rotation":{x:.182,y:-.002,z:-.019},"LeftHandMiddle3.rotation":{x:.182,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.316,y:-.017,z:.008},"LeftHandRing2.rotation":{x:.253,y:-.003,z:-.026},"LeftHandRing3.rotation":{x:.255,y:-.003,z:-.026},"LeftHandPinky1.rotation":{x:.336,y:-.062,z:.088},"LeftHandPinky2.rotation":{x:.276,y:-.004,z:-.028},"LeftHandPinky3.rotation":{x:.276,y:-.004,z:-.028},"RightShoulder.rotation":{x:1.615,y:.064,z:1.53},"RightArm.rotation":{x:1.313,y:-.424,z:.131},"RightForeArm.rotation":{x:0,y:0,z:-.317},"RightHand.rotation":{x:-.158,y:-.639,z:-.196},"RightHandThumb1.rotation":{x:.44,y:.048,z:-.549},"RightHandThumb2.rotation":{x:-.056,y:-.008,z:.274},"RightHandThumb3.rotation":{x:-.258,y:.031,z:-.095},"RightHandIndex1.rotation":{x:.169,y:-.011,z:.105},"RightHandIndex2.rotation":{x:.134,y:.001,z:.011},"RightHandIndex3.rotation":{x:.134,y:.001,z:.011},"RightHandMiddle1.rotation":{x:.288,y:.014,z:.092},"RightHandMiddle2.rotation":{x:.248,y:.003,z:.02},"RightHandMiddle3.rotation":{x:.249,y:.003,z:.02},"RightHandRing1.rotation":{x:.369,y:.019,z:.006},"RightHandRing2.rotation":{x:.321,y:.004,z:.026},"RightHandRing3.rotation":{x:.323,y:.004,z:.026},"RightHandPinky1.rotation":{x:.468,y:.085,z:-.03},"RightHandPinky2.rotation":{x:.427,y:.007,z:.034},"RightHandPinky3.rotation":{x:.142,y:.001,z:.012},"LeftUpLeg.rotation":{x:-.077,y:-.058,z:3.126},"LeftLeg.rotation":{x:-.252,y:.001,z:-.018},"LeftFoot.rotation":{x:1.315,y:-.064,z:.315},"LeftToeBase.rotation":{x:.577,y:-.07,z:-.009},"RightUpLeg.rotation":{x:-.083,y:-.032,z:3.124},"RightLeg.rotation":{x:-.272,y:-.003,z:.021},"RightFoot.rotation":{x:1.342,y:.076,z:-.222},"RightToeBase.rotation":{x:.44,y:.069,z:.016}}},wide:{standing:!0,props:{"Hips.position":{x:0,y:1.017,z:.016},"Hips.rotation":{x:.064,y:-.048,z:.059},"Spine.rotation":{x:-.123,y:0,z:-.018},"Spine1.rotation":{x:.014,y:.003,z:-.006},"Spine2.rotation":{x:.04,y:.003,z:-.007},"Neck.rotation":{x:.101,y:.007,z:-.035},"Head.rotation":{x:-.091,y:-.049,z:.105},"RightShoulder.rotation":{x:1.831,y:.017,z:1.731},"RightArm.rotation":{x:-1.673,y:-1.102,z:-3.132},"RightForeArm.rotation":{x:.265,y:.23,z:-.824},"RightHand.rotation":{x:-.52,y:.345,z:-.061},"RightHandThumb1.rotation":{x:.291,y:.056,z:-.428},"RightHandThumb2.rotation":{x:.025,y:.005,z:.166},"RightHandThumb3.rotation":{x:-.089,y:.009,z:.068},"RightHandIndex1.rotation":{x:.392,y:-.015,z:.11},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.068,z:.081},"RightHandMiddle2.rotation":{x:.519,y:.004,z:.011},"RightHandMiddle3.rotation":{x:.252,y:0,z:.001},"RightHandRing1.rotation":{x:.207,y:.133,z:.146},"RightHandRing2.rotation":{x:.597,y:.004,z:.004},"RightHandRing3.rotation":{x:.292,y:.002,z:.012},"RightHandPinky1.rotation":{x:.338,y:.182,z:.136},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftShoulder.rotation":{x:1.83,y:-.063,z:-1.808},"LeftArm.rotation":{x:-1.907,y:1.228,z:-2.959},"LeftForeArm.rotation":{x:-.159,y:.268,z:.572},"LeftHand.rotation":{x:.069,y:-.498,z:-.025},"LeftHandThumb1.rotation":{x:.738,y:.123,z:.178},"LeftHandThumb2.rotation":{x:-.26,y:.028,z:-.477},"LeftHandThumb3.rotation":{x:-.448,y:.093,z:-.661},"LeftHandIndex1.rotation":{x:1.064,y:.005,z:-.13},"LeftHandIndex2.rotation":{x:1.55,y:-.143,z:-.136},"LeftHandIndex3.rotation":{x:.722,y:-.076,z:-.127},"LeftHandMiddle1.rotation":{x:1.095,y:-.091,z:.006},"LeftHandMiddle2.rotation":{x:1.493,y:-.174,z:-.151},"LeftHandMiddle3.rotation":{x:.651,y:-.031,z:-.087},"LeftHandRing1.rotation":{x:1.083,y:-.224,z:.072},"LeftHandRing2.rotation":{x:1.145,y:-.107,z:-.195},"LeftHandRing3.rotation":{x:1.208,y:-.134,z:-.158},"LeftHandPinky1.rotation":{x:.964,y:-.383,z:.128},"LeftHandPinky2.rotation":{x:1.457,y:-.146,z:-.159},"LeftHandPinky3.rotation":{x:1.019,y:-.102,z:-.141},"RightUpLeg.rotation":{x:-.221,y:-.233,z:2.87},"RightLeg.rotation":{x:-.339,y:-.043,z:-.041},"RightFoot.rotation":{x:1.081,y:.177,z:.114},"RightToeBase.rotation":{x:.775,y:0,z:0},"LeftUpLeg.rotation":{x:-.185,y:.184,z:3.131},"LeftLeg.rotation":{x:-.408,y:.129,z:.02},"LeftFoot.rotation":{x:1.167,y:-.002,z:-.007},"LeftToeBase.rotation":{x:.723,y:0,z:0}}},oneknee:{kneeling:!0,props:{"Hips.position":{x:-.005,y:.415,z:-.017},"Hips.rotation":{x:-.25,y:.04,z:-.238},"Spine.rotation":{x:.037,y:.043,z:.047},"Spine1.rotation":{x:.317,y:.103,z:.066},"Spine2.rotation":{x:.433,y:.109,z:.054},"Neck.rotation":{x:-.156,y:-.092,z:.059},"Head.rotation":{x:-.398,y:-.032,z:.018},"RightShoulder.rotation":{x:1.546,y:.119,z:1.528},"RightArm.rotation":{x:.896,y:-.247,z:-.512},"RightForeArm.rotation":{x:.007,y:0,z:-1.622},"RightHand.rotation":{x:1.139,y:-.853,z:.874},"RightHandThumb1.rotation":{x:.176,y:.107,z:-.311},"RightHandThumb2.rotation":{x:-.047,y:-.003,z:.12},"RightHandThumb3.rotation":{x:0,y:0,z:0},"RightHandIndex1.rotation":{x:.186,y:.005,z:.125},"RightHandIndex2.rotation":{x:.454,y:.005,z:.015},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:.444,y:.035,z:.127},"RightHandMiddle2.rotation":{x:.403,y:-.006,z:-.04},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.543,y:.074,z:.121},"RightHandRing2.rotation":{x:.48,y:-.018,z:-.063},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.464,y:.086,z:.113},"RightHandPinky2.rotation":{x:.667,y:-.06,z:-.128},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.545,y:-.116,z:-1.529},"LeftArm.rotation":{x:.799,y:.631,z:.556},"LeftForeArm.rotation":{x:-.002,y:.007,z:.926},"LeftHand.rotation":{x:-.508,y:.439,z:.502},"LeftHandThumb1.rotation":{x:.651,y:-.035,z:.308},"LeftHandThumb2.rotation":{x:-.053,y:.008,z:-.11},"LeftHandThumb3.rotation":{x:0,y:0,z:0},"LeftHandIndex1.rotation":{x:.662,y:-.053,z:-.116},"LeftHandIndex2.rotation":{x:.309,y:-.004,z:-.02},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:.501,y:-.062,z:-.12},"LeftHandMiddle2.rotation":{x:.144,y:-.002,z:.016},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.397,y:-.029,z:-.143},"LeftHandRing2.rotation":{x:.328,y:.01,z:.059},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.194,y:.008,z:-.164},"LeftHandPinky2.rotation":{x:.38,y:.031,z:.128},"LeftHandPinky3.rotation":{x:0,y:0,z:0},"RightUpLeg.rotation":{x:-1.594,y:-.251,z:2.792},"RightLeg.rotation":{x:-2.301,y:-.073,z:.055},"RightFoot.rotation":{x:1.553,y:-.207,z:-.094},"RightToeBase.rotation":{x:.459,y:.069,z:.016},"LeftUpLeg.rotation":{x:-.788,y:-.236,z:-2.881},"LeftLeg.rotation":{x:-2.703,y:.012,z:-.047},"LeftFoot.rotation":{x:2.191,y:-.102,z:.019},"LeftToeBase.rotation":{x:1.215,y:-.027,z:.01}}},kneel:{kneeling:!0,lying:!0,props:{"Hips.position":{x:0,y:.532,z:-.002},"Hips.rotation":{x:.018,y:-.008,z:-.017},"Spine.rotation":{x:-.139,y:-.01,z:.002},"Spine1.rotation":{x:.002,y:-.002,z:.001},"Spine2.rotation":{x:.028,y:-.002,z:.001},"Neck.rotation":{x:-.007,y:0,z:-.002},"Head.rotation":{x:-.02,y:-.008,z:-.004},"LeftShoulder.rotation":{x:1.77,y:-.428,z:-1.588},"LeftArm.rotation":{x:.911,y:.343,z:.083},"LeftForeArm.rotation":{x:0,y:0,z:.347},"LeftHand.rotation":{x:.033,y:-.052,z:-.105},"LeftHandThumb1.rotation":{x:.508,y:-.22,z:.708},"LeftHandThumb2.rotation":{x:-.323,y:-.139,z:-.56},"LeftHandThumb3.rotation":{x:-.328,y:.16,z:-.301},"LeftHandIndex1.rotation":{x:.178,y:.248,z:.045},"LeftHandIndex2.rotation":{x:.236,y:-.002,z:-.019},"LeftHandIndex3.rotation":{x:-.062,y:0,z:.005},"LeftHandMiddle1.rotation":{x:.123,y:-.005,z:-.019},"LeftHandMiddle2.rotation":{x:.589,y:-.014,z:-.045},"LeftHandMiddle3.rotation":{x:.231,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.196,y:-.008,z:-.091},"LeftHandRing2.rotation":{x:.483,y:-.009,z:-.038},"LeftHandRing3.rotation":{x:.367,y:-.005,z:-.029},"LeftHandPinky1.rotation":{x:.191,y:-.269,z:-.246},"LeftHandPinky2.rotation":{x:.37,y:-.006,z:-.029},"LeftHandPinky3.rotation":{x:.368,y:-.005,z:-.029},"RightShoulder.rotation":{x:1.73,y:.434,z:1.715},"RightArm.rotation":{x:.841,y:-.508,z:-.155},"RightForeArm.rotation":{x:0,y:0,z:-.355},"RightHand.rotation":{x:.091,y:.137,z:.197},"RightHandThumb1.rotation":{x:.33,y:.051,z:-.753},"RightHandThumb2.rotation":{x:-.113,y:.075,z:.612},"RightHandThumb3.rotation":{x:-.271,y:-.166,z:.164},"RightHandIndex1.rotation":{x:.073,y:.001,z:-.093},"RightHandIndex2.rotation":{x:.338,y:.006,z:.034},"RightHandIndex3.rotation":{x:.131,y:.001,z:.013},"RightHandMiddle1.rotation":{x:.13,y:.005,z:-.017},"RightHandMiddle2.rotation":{x:.602,y:.018,z:.058},"RightHandMiddle3.rotation":{x:-.031,y:0,z:-.003},"RightHandRing1.rotation":{x:.351,y:.019,z:.045},"RightHandRing2.rotation":{x:.19,y:.002,z:.019},"RightHandRing3.rotation":{x:.21,y:.002,z:.021},"RightHandPinky1.rotation":{x:.256,y:.17,z:.118},"RightHandPinky2.rotation":{x:.451,y:.01,z:.045},"RightHandPinky3.rotation":{x:.346,y:.006,z:.035},"LeftUpLeg.rotation":{x:-.06,y:.1,z:-2.918},"LeftLeg.rotation":{x:-1.933,y:-.01,z:.011},"LeftFoot.rotation":{x:.774,y:-.162,z:-.144},"LeftToeBase.rotation":{x:1.188,y:0,z:0},"RightUpLeg.rotation":{x:-.099,y:-.057,z:2.922},"RightLeg.rotation":{x:-1.93,y:.172,z:-.02},"RightFoot.rotation":{x:.644,y:.251,z:.212},"RightToeBase.rotation":{x:.638,y:-.034,z:-.001}}},sitting:{sitting:!0,lying:!0,props:{"Hips.position":{x:0,y:.117,z:.005},"Hips.rotation":{x:-.411,y:-.049,z:.056},"Spine.rotation":{x:.45,y:-.039,z:-.116},"Spine1.rotation":{x:.092,y:-.076,z:.08},"Spine2.rotation":{x:.073,y:.035,z:.066},"Neck.rotation":{x:.051,y:.053,z:-.079},"Head.rotation":{x:-.169,y:.009,z:.034},"LeftShoulder.rotation":{x:1.756,y:-.037,z:-1.301},"LeftArm.rotation":{x:-.098,y:.016,z:1.006},"LeftForeArm.rotation":{x:-.089,y:.08,z:.837},"LeftHand.rotation":{x:.262,y:-.399,z:.3},"LeftHandThumb1.rotation":{x:.149,y:-.043,z:.452},"LeftHandThumb2.rotation":{x:.032,y:.006,z:-.162},"LeftHandThumb3.rotation":{x:-.086,y:-.005,z:-.069},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.325,y:-.001,z:-.004},"LeftHandIndex3.rotation":{x:.253,y:0,z:-.003},"LeftHandMiddle1.rotation":{x:.186,y:-.051,z:-.091},"LeftHandMiddle2.rotation":{x:.42,y:-.003,z:-.011},"LeftHandMiddle3.rotation":{x:.153,y:.001,z:-.001},"LeftHandRing1.rotation":{x:.087,y:-.19,z:-.078},"LeftHandRing2.rotation":{x:.488,y:-.004,z:-.005},"LeftHandRing3.rotation":{x:.183,y:-.001,z:-.012},"LeftHandPinky1.rotation":{x:.205,y:-.262,z:.051},"LeftHandPinky2.rotation":{x:.407,y:-.002,z:-.004},"LeftHandPinky3.rotation":{x:.068,y:0,z:-.002},"RightShoulder.rotation":{x:1.619,y:-.139,z:1.179},"RightArm.rotation":{x:.17,y:-.037,z:-1.07},"RightForeArm.rotation":{x:-.044,y:-.056,z:-.665},"RightHand.rotation":{x:.278,y:.454,z:-.253},"RightHandThumb1.rotation":{x:.173,y:.089,z:-.584},"RightHandThumb2.rotation":{x:-.003,y:-.004,z:.299},"RightHandThumb3.rotation":{x:-.133,y:-.002,z:.235},"RightHandIndex1.rotation":{x:.393,y:-.023,z:.108},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.062,z:.086},"RightHandMiddle2.rotation":{x:.519,y:.003,z:.011},"RightHandMiddle3.rotation":{x:.252,y:-.001,z:.001},"RightHandRing1.rotation":{x:.207,y:.122,z:.155},"RightHandRing2.rotation":{x:.597,y:.004,z:.005},"RightHandRing3.rotation":{x:.292,y:.001,z:.012},"RightHandPinky1.rotation":{x:.338,y:.171,z:.149},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftUpLeg.rotation":{x:-1.957,y:.083,z:-2.886},"LeftLeg.rotation":{x:-1.46,y:.123,z:.005},"LeftFoot.rotation":{x:-.013,y:.016,z:.09},"LeftToeBase.rotation":{x:.744,y:0,z:0},"RightUpLeg.rotation":{x:-1.994,y:.125,z:2.905},"RightLeg.rotation":{x:-1.5,y:-.202,z:-.006},"RightFoot.rotation":{x:-.012,y:-.065,z:.081},"RightToeBase.rotation":{x:.758,y:0,z:0}}}},this.gestureTemplates={handup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.529,y:-.2,z:.022},"LeftHandThumb1.rotation":{x:.745,y:-.526,z:.604},"LeftHandThumb2.rotation":{x:-.107,y:-.01,z:-.142},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.126,y:-.035,z:-.087},"LeftHandIndex2.rotation":{x:.255,y:.007,z:-.085},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},index:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.579,y:.228,z:.363},"LeftHandThumb2.rotation":{x:-.027,y:-.04,z:-.662},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:0,y:-.105,z:.225},"LeftHandIndex2.rotation":{x:.256,y:-.103,z:-.213},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:1.453,y:.07,z:.021},"LeftHandMiddle2.rotation":{x:1.599,y:.062,z:.07},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:1.528,y:-.073,z:.052},"LeftHandRing2.rotation":{x:1.386,y:.044,z:.053},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:1.65,y:-.204,z:.031},"LeftHandPinky2.rotation":{x:1.302,y:.071,z:.085},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},ok:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,1],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.476,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.703,y:.445,z:.899},"LeftHandThumb2.rotation":{x:-.312,y:-.04,z:-.938},"LeftHandThumb3.rotation":{x:-.37,y:.024,z:-.393},"LeftHandIndex1.rotation":{x:.8,y:-.086,z:-.091},"LeftHandIndex2.rotation":{x:1.123,y:-.046,z:-.074},"LeftHandIndex3.rotation":{x:.562,y:-.013,z:-.043},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},thumbup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:.206,z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},thumbdown:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-2.015,y:.406,z:1.575},"LeftHand.rotation":{x:-.176,y:-.206,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},side:{"LeftShoulder.rotation":{x:1.755,y:-.035,z:-1.63},"LeftArm.rotation":{x:1.263,y:-.955,z:1.024},"LeftForeArm.rotation":{x:0,y:0,z:.8},"LeftHand.rotation":{x:-.36,y:-1.353,z:-.184},"LeftHandThumb1.rotation":{x:.137,y:-.049,z:.863},"LeftHandThumb2.rotation":{x:-.293,y:.153,z:-.193},"LeftHandThumb3.rotation":{x:-.271,y:-.17,z:.18},"LeftHandIndex1.rotation":{x:-.018,y:.007,z:.28},"LeftHandIndex2.rotation":{x:.247,y:-.003,z:-.025},"LeftHandIndex3.rotation":{x:.13,y:-.001,z:-.013},"LeftHandMiddle1.rotation":{x:.333,y:-.015,z:.182},"LeftHandMiddle2.rotation":{x:.313,y:-.005,z:-.032},"LeftHandMiddle3.rotation":{x:.294,y:-.004,z:-.03},"LeftHandRing1.rotation":{x:.456,y:-.028,z:-.092},"LeftHandRing2.rotation":{x:.53,y:-.014,z:-.052},"LeftHandRing3.rotation":{x:.478,y:-.012,z:-.047},"LeftHandPinky1.rotation":{x:.647,y:-.049,z:-.184},"LeftHandPinky2.rotation":{x:.29,y:-.004,z:-.029},"LeftHandPinky3.rotation":{x:.501,y:-.013,z:-.049}},shrug:{"Neck.rotation":{x:[-.3,.3,1,2],y:[-.3,.3,1,2],z:[-.1,.1]},"Head.rotation":{x:[-.3,.3],y:[-.3,.3],z:[-.1,.1]},"RightShoulder.rotation":{x:1.732,y:-.058,z:1.407},"RightArm.rotation":{x:1.305,y:.46,z:.118},"RightForeArm.rotation":{x:[0,2],y:[-1,.2],z:-1.637},"RightHand.rotation":{x:-.048,y:.165,z:-.39},"RightHandThumb1.rotation":{x:1.467,y:.599,z:-1.315},"RightHandThumb2.rotation":{x:-.255,y:-.123,z:.119},"RightHandThumb3.rotation":{x:0,y:-.002,z:0},"RightHandIndex1.rotation":{x:-.293,y:-.066,z:-.112},"RightHandIndex2.rotation":{x:.181,y:.007,z:.069},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:-.063,y:-.041,z:.032},"RightHandMiddle2.rotation":{x:.149,y:.005,z:.05},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.152,y:-.03,z:.132},"RightHandRing2.rotation":{x:.194,y:.007,z:.058},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.306,y:-.015,z:.257},"RightHandPinky2.rotation":{x:.15,y:-.003,z:-.003},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.713,y:.141,z:-1.433},"LeftArm.rotation":{x:1.136,y:-.422,z:-.416},"LeftForeArm.rotation":{x:1.42,y:.123,z:1.506},"LeftHand.rotation":{x:.073,y:-.138,z:.064},"LeftHandThumb1.rotation":{x:1.467,y:-.599,z:1.314},"LeftHandThumb2.rotation":{x:-.255,y:.123,z:-.119},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.293,y:.066,z:.112},"LeftHandIndex2.rotation":{x:.181,y:-.007,z:-.069},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.062,y:.041,z:-.032},"LeftHandMiddle2.rotation":{x:.149,y:-.005,z:-.05},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.152,y:.03,z:-.132},"LeftHandRing2.rotation":{x:.194,y:-.007,z:-.058},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.306,y:.015,z:-.257},"LeftHandPinky2.rotation":{x:.15,y:.003,z:.003},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},namaste:{"RightShoulder.rotation":{x:1.758,y:.099,z:1.604},"RightArm.rotation":{x:.862,y:-.292,z:-.932},"RightForeArm.rotation":{x:.083,y:.066,z:-1.791},"RightHand.rotation":{x:-.52,y:-.001,z:-.176},"RightHandThumb1.rotation":{x:.227,y:.418,z:-.776},"RightHandThumb2.rotation":{x:-.011,y:-.003,z:.171},"RightHandThumb3.rotation":{x:-.041,y:-.001,z:-.013},"RightHandIndex1.rotation":{x:-.236,y:.003,z:-.028},"RightHandIndex2.rotation":{x:.004,y:0,z:.001},"RightHandIndex3.rotation":{x:.002,y:0,z:0},"RightHandMiddle1.rotation":{x:-.236,y:.003,z:-.028},"RightHandMiddle2.rotation":{x:.004,y:0,z:.001},"RightHandMiddle3.rotation":{x:.002,y:0,z:0},"RightHandRing1.rotation":{x:-.236,y:.003,z:-.028},"RightHandRing2.rotation":{x:.004,y:0,z:.001},"RightHandRing3.rotation":{x:.002,y:0,z:0},"RightHandPinky1.rotation":{x:-.236,y:.003,z:-.028},"RightHandPinky2.rotation":{x:.004,y:0,z:.001},"RightHandPinky3.rotation":{x:.002,y:0,z:0},"LeftShoulder.rotation":{x:1.711,y:-.002,z:-1.625},"LeftArm.rotation":{x:.683,y:.334,z:.977},"LeftForeArm.rotation":{x:.086,y:-.066,z:1.843},"LeftHand.rotation":{x:-.595,y:-.229,z:.096},"LeftHandThumb1.rotation":{x:.404,y:-.05,z:.537},"LeftHandThumb2.rotation":{x:-.02,y:.004,z:-.154},"LeftHandThumb3.rotation":{x:-.049,y:.002,z:-.019},"LeftHandIndex1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandIndex2.rotation":{x:.003,y:0,z:0},"LeftHandIndex3.rotation":{x:.002,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandMiddle2.rotation":{x:.004,y:0,z:0},"LeftHandMiddle3.rotation":{x:.002,y:0,z:0},"LeftHandRing1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandRing2.rotation":{x:.003,y:0,z:0},"LeftHandRing3.rotation":{x:.002,y:0,z:0},"LeftHandPinky1.rotation":{x:-.122,y:-.001,z:-.057},"LeftHandPinky2.rotation":{x:.012,y:.001,z:.07},"LeftHandPinky3.rotation":{x:.002,y:0,z:0}}},this.poseDelta={props:{"Hips.quaternion":{x:0,y:0,z:0},"Spine.quaternion":{x:0,y:0,z:0},"Spine1.quaternion":{x:0,y:0,z:0},"Neck.quaternion":{x:0,y:0,z:0},"Head.quaternion":{x:0,y:0,z:0},"Spine1.scale":{x:0,y:0,z:0},"Neck.scale":{x:0,y:0,z:0},"LeftArm.scale":{x:0,y:0,z:0},"RightArm.scale":{x:0,y:0,z:0}}},["Left","Right"].forEach(l=>{["Leg","UpLeg","Arm","ForeArm","Hand"].forEach(h=>{this.poseDelta.props[l+h+".quaternion"]={x:0,y:0,z:0}}),["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach(h=>{this.poseDelta.props[l+h+"1.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[l+h+"2.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[l+h+"3.quaternion"]={x:0,y:0,z:0}})});const t=new Set;Object.values(this.poseTemplates).forEach(l=>{Object.keys(this.propsToThreeObjects(l.props)).forEach(h=>t.add(h))}),Object.keys(this.poseDelta.props).forEach(l=>{t.add(l)}),this.posePropNames=[...t],this.poseName="side",this.poseWeightOnLeft=!0,this.gesture=null,this.poseCurrentTemplate=this.poseTemplates[this.poseName],this.poseStraight=this.propsToThreeObjects(this.poseTemplates.straight.props),this.poseBase=this.poseFactory(this.poseCurrentTemplate),this.poseTarget=this.poseFactory(this.poseCurrentTemplate),this.poseAvatar=null,this.avatarHeight=1.7,this.animTemplateEyes={name:"eyes",idle:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarIdleEyeContact")?this.avatar.avatarIdleEyeContact:this.opt.avatarIdleEyeContact,delay:[200,5e3],dt:[200,[2e3,5e3],[3e3,1e4,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]],eyeContact:[null,1]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]},speaking:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarSpeakingEyeContact")?this.avatar.avatarSpeakingEyeContact:this.opt.avatarSpeakingEyeContact,delay:[200,5e3],dt:[0,[3e3,1e4,1,2],[2e3,5e3]],vs:{eyeContact:[1,null],headMove:[null,this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[null,[-.6,.6]],eyesRotateX:[null,[-.2,.6]]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]}},this.animTemplateBlink={name:"blink",alt:[{p:.85,delay:[1e3,8e3,1,2],dt:[50,[100,300],100],vs:{eyeBlinkLeft:[1,1,0],eyeBlinkRight:[1,1,0]}},{delay:[1e3,4e3,1,2],dt:[50,[100,200],100,[10,400,0],50,[100,200],100],vs:{eyeBlinkLeft:[1,1,0,0,1,1,0],eyeBlinkRight:[1,1,0,0,1,1,0]}}]},this.animMoods={neutral:{baseline:{eyesLookDown:0},speech:{deltaRate:0,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{p:.5,delay:[5e3,3e4],vs:{pose:["side"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}},{p:.3,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}},{delay:[5e3,3e4],vs:{pose:["straight"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]},{name:"head",idle:{delay:[0,1e3],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},happy:{baseline:{mouthSmile:.2,eyesLookDown:.1},speech:{deltaRate:0,deltaPitch:.1,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",idle:{alt:[{p:.6,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{p:.1,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,1e4],vs:{pose:["wide"]}},{delay:[1e3,3e3],vs:{pose:["turn"]}}]},speaking:{alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]}},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthSmile:[[0,.2,3]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},angry:{baseline:{eyesLookDown:.1,browDownLeft:.6,browDownRight:.6,jawForward:.3,mouthFrownLeft:.7,mouthFrownRight:.7,mouthRollLower:.2,mouthShrugLower:.3,handFistLeft:1,handFistRight:1},speech:{deltaRate:-.2,deltaPitch:.2,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},sad:{baseline:{eyesLookDown:.2,browDownRight:.1,browInnerUp:.6,browOuterUpRight:.2,eyeSquintLeft:.7,eyeSquintRight:.7,mouthFrownLeft:.8,mouthFrownRight:.8,mouthLeft:.2,mouthPucker:.5,mouthRollLower:.2,mouthRollUpper:.2,mouthShrugLower:.2,mouthShrugUpper:.2,mouthStretchLeft:.4},speech:{deltaRate:-.2,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.3,.3,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},fear:{baseline:{browInnerUp:.7,eyeSquintLeft:.5,eyeSquintRight:.5,eyeWideLeft:.6,eyeWideRight:.6,mouthClose:.1,mouthFunnel:.3,mouthShrugLower:.5,mouthShrugUpper:.5},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.8,delay:[5e3,3e4],vs:{pose:["side"]}},{delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["wide"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,3e3]],vs:{bodyRotateX:[[-.06,.12]],bodyRotateY:[[-.7,.7]],bodyRotateZ:[[-.1,.1]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},disgust:{baseline:{browDownLeft:.7,browDownRight:.1,browInnerUp:.3,eyeSquintLeft:1,eyeSquintRight:1,eyeWideLeft:.5,eyeWideRight:.5,eyesRotateX:.05,mouthLeft:.4,mouthPressLeft:.3,mouthRollLower:.3,mouthShrugLower:.3,mouthShrugUpper:.8,mouthUpperUpLeft:.3,noseSneerLeft:1,noseSneerRight:.7},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},love:{baseline:{browInnerUp:.4,browOuterUpLeft:.2,browOuterUpRight:.2,mouthSmile:.2,eyeBlinkLeft:.6,eyeBlinkRight:.6,eyeWideLeft:.7,eyeWideRight:.7,bodyRotateX:.1,mouthDimpleLeft:.1,mouthDimpleRight:.1,mouthPressLeft:.2,mouthShrugUpper:.2,mouthUpperUpLeft:.1,mouthUpperUpRight:.1},speech:{deltaRate:-.1,deltaPitch:-.7,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1500,500,1500],vs:{chestInhale:[.8,.8,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{delay:[5e3,1e4],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["kneel"]}}},{delay:[1e3,3e3],vs:{pose:["turn"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[1e3,3e3],vs:{pose:["back"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[5e3,2e4],vs:{pose:["side"]},M:{delay:[5e3,2e4],vs:{pose:["side"]}},full:{delay:[5e3,2e4],vs:{pose:["bend"]}}},{delay:[1e3,3e3],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.deepCopy(this.animTemplateBlink,l=>{l.alt[0].delay[0]=l.alt[1].delay[0]=2e3}),{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[500,1e3],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[.3,.6,2]],browOuterUpLeft:[[.1,.3,2]],browOuterUpRight:[[.1,.3,2]]}}]},sleep:{baseline:{eyeBlinkLeft:1,eyeBlinkRight:1,eyesClosed:.6},speech:{deltaRate:0,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.6,.6,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",delay:[1e3,5e3],dt:[[2e3,1e4]],vs:{bodyRotateX:[[0,.4]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.04,.04]]}},{name:"eyes",delay:10010,dt:[],vs:{}},{name:"blink",delay:10020,dt:[],vs:{}},{name:"mouth",delay:10030,dt:[],vs:{}},{name:"misc",delay:10040,dt:[],vs:{}}]}},this.moodName=this.opt.avatarMood||"neutral",this.mood=this.animMoods[this.moodName],this.mood||(this.moodName="neutral",this.mood=this.animMoods.neutral),this.animEmojis={"😐":{dt:[300,2e3],rescale:[0,1],vs:{pose:["straight"],browInnerUp:[.4],eyeWideLeft:[.7],eyeWideRight:[.7],mouthPressLeft:[.6],mouthPressRight:[.6],mouthRollLower:[.3],mouthStretchLeft:[1],mouthStretchRight:[1]}},"😶":{link:"😐"},"😏":{dt:[300,2e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthLeft:[.4],mouthPucker:[.4],mouthShrugLower:[.3],mouthShrugUpper:[.2],mouthSmile:[.2],mouthSmileLeft:[.4],mouthSmileRight:[.2],mouthStretchLeft:[.5],mouthUpperUpLeft:[.6],noseSneerLeft:[.7]}},"🙂":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5]}},"🙃":{link:"🙂"},"😊":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😇":{link:"😊"},"😀":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😃":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeWideLeft:[.7],eyeWideRight:[.7],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😄":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.2],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😁":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😆":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😝":{dt:[300,100,1500,500,500],rescale:[0,0,1,0,0],vs:{browInnerUp:[.8],eyesClosed:[1],jawOpen:[.7],mouthFunnel:[.5],mouthSmile:[1],tongueOut:[0,1,1,0]}},"😋":{link:"😝"},"😛":{link:"😝"},"😛":{link:"😝"},"😜":{link:"😝"},"🤪":{link:"😝"},"😂":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤣":{link:"😂"},"😅":{link:"😂"},"😉":{dt:[500,200,500,500],rescale:[0,0,0,1],vs:{mouthSmile:[.5],mouthOpen:[.2],mouthSmileLeft:[0,.5,0],eyeBlinkLeft:[0,.7,0],eyeBlinkRight:[0,0,0],bodyRotateX:[.05,.05,.05,0],bodyRotateZ:[-.05,-.05,-.05,0],browDownLeft:[0,.7,0],cheekSquintLeft:[0,.7,0],eyeSquintLeft:[0,1,0],eyesClosed:[0]}},"😭":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.1],jawOpen:[0],mouthFrownLeft:[1],mouthFrownRight:[1],mouthOpen:[.5],mouthPucker:[.5],mouthUpperUpLeft:[.6],mouthUpperUpRight:[.6]}},"🥺":{dt:[1e3,1e3],rescale:[0,1],vs:{browDownLeft:[.2],browDownRight:[.2],browInnerUp:[1],eyeWideLeft:[.9],eyeWideRight:[.9],eyesClosed:[.1],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😞":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.7],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[1],mouthRollLower:[1],mouthShrugLower:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😔":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😳":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeWideLeft:[.5],eyeWideRight:[.5],eyesRotateY:[.05],eyesRotateX:[.05],mouthClose:[.2],mouthFunnel:[.5],mouthPucker:[.4],mouthRollLower:[.4],mouthRollUpper:[.4]}},"☹️":{dt:[500,1500],rescale:[0,1],vs:{mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[.1],mouthRollLower:[.8]}},"😚":{dt:[500,1e3,1e3],rescale:[0,1,0],vs:{browInnerUp:[.6],eyeBlinkLeft:[1],eyeBlinkRight:[1],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5],noseSneerLeft:[0,.7],noseSneerRight:[0,.7],viseme_U:[0,1]}},"😘":{dt:[500,500,200,500],rescale:[0,0,0,1],vs:{browInnerUp:[.6],eyeBlinkLeft:[0,0,1,0],eyeBlinkRight:[0],eyesRotateY:[0],bodyRotateY:[0],bodyRotateX:[0,.05,.05,0],bodyRotateZ:[0,-.05,-.05,0],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5,0],noseSneerLeft:[0,.7],noseSneerRight:[.7],viseme_U:[0,1]}},"🥰":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😍":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤩":{link:"😍"},"😡":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"😠":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"🤬":{link:"😠"},"😒":{dt:[1e3,1e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthFrownLeft:[1],mouthFrownRight:[1],mouthLeft:[.2],mouthPucker:[.5],mouthRollLower:[.2],mouthRollUpper:[.2],mouthShrugLower:[.2],mouthShrugUpper:[.2],mouthStretchLeft:[.5]}},"😱":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[.5],eyeWideRight:[.5],jawOpen:[.7],mouthFunnel:[.5]}},"😬":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],browInnerUp:[1],mouthDimpleLeft:[.5],mouthDimpleRight:[.5],mouthLowerDownLeft:[1],mouthLowerDownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[.5],mouthSmile:[.1],mouthSmileLeft:[.2],mouthSmileRight:[.2],mouthStretchLeft:[1],mouthStretchRight:[1],mouthUpperUpLeft:[1],mouthUpperUpRight:[1]}},"🙄":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[1],eyeWideRight:[1],eyesRotateX:[-.8],bodyRotateX:[.15],mouthPucker:[.5],mouthRollLower:[.6],mouthRollUpper:[.5],mouthShrugLower:[0],mouthSmile:[0]}},"🤔":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browOuterUpRight:[1],eyeSquintLeft:[.6],mouthFrownLeft:[.7],mouthFrownRight:[.7],mouthLowerDownLeft:[.3],mouthPressRight:[.4],mouthPucker:[.1],mouthRight:[.5],mouthRollLower:[.5],mouthRollUpper:[.2],handRight:[{x:.1,y:.1,z:.1,d:1e3},{d:1e3}],handFistRight:[.1]}},"👀":{dt:[500,1500],rescale:[0,1],vs:{eyesRotateY:[-.8]}},"😴":{dt:[5e3,5e3],rescale:[0,1],vs:{eyeBlinkLeft:[1],eyeBlinkRight:[1],bodyRotateX:[.2],bodyRotateZ:[.1]}},"✋":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2,!0],null]}},"🤚":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2],null]}},"👋":{link:"✋"},"👍":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["thumbup",2],null]}},"👎":{dt:[300,2e3],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15],gesture:[["thumbdown",2],null]}},"👌":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["ok",2],null]}},"🤷♂️":{dt:[1e3,1500],rescale:[0,1],vs:{gesture:[["shrug",2],null]}},"🤷♀️":{link:"🤷♂️"},"🤷":{link:"🤷♂️"},"🙏":{dt:[1500,300,1e3],rescale:[0,1,0],vs:{eyeBlinkLeft:[0,1],eyeBlinkRight:[0,1],bodyRotateX:[0],bodyRotateZ:[.1],gesture:[["namaste",2],null]}},yes:{dt:[[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateX:[[.1,.2],.1,[.1,.2],0],headRotateZ:[[-.2,.2]]}},no:{dt:[[200,500],[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateY:[[-.1,-.05],[.05,.1],[-.1,-.05],[.05,.1],0],headRotateZ:[[-.2,.2]]}}},this.mtAvatar={},this.mtCustoms=["handFistLeft","handFistRight","bodyRotateX","bodyRotateY","bodyRotateZ","headRotateX","headRotateY","headRotateZ","chestInhale"],this.mtEasingDefault=this.sigmoidFactory(5),this.mtAccDefault=.01,this.mtAccExceptions={eyeBlinkLeft:.1,eyeBlinkRight:.1,eyeLookOutLeft:.1,eyeLookInLeft:.1,eyeLookOutRight:.1,eyeLookInRight:.1},this.mtMaxVDefault=5,this.mtMaxVExceptions={bodyRotateX:1,bodyRotateY:1,bodyRotateZ:1},this.mtBaselineDefault=0,this.mtBaselineExceptions={bodyRotateX:null,bodyRotateY:null,bodyRotateZ:null,eyeLookOutLeft:null,eyeLookInLeft:null,eyeLookOutRight:null,eyeLookInRight:null,eyesLookDown:null,eyesLookUp:null},this.mtMinDefault=0,this.mtMinExceptions={bodyRotateX:-1,bodyRotateY:-1,bodyRotateZ:-1,headRotateX:-1,headRotateY:-1,headRotateZ:-1},this.mtMaxDefault=1,this.mtMaxExceptions={},this.mtLimits={eyeBlinkLeft:l=>Math.max(l,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownLeft.value)/2),eyeBlinkRight:l=>Math.max(l,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownRight.value)/2)},this.mtOnchange={eyesLookDown:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0,this.mtAvatar.eyeBlinkRight.needsUpdate=!0},browDownLeft:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0},browDownRight:()=>{this.mtAvatar.eyeBlinkRight.needsUpdate=!0}},this.mtRandomized=["mouthDimpleLeft","mouthDimpleRight","mouthLeft","mouthPressLeft","mouthPressRight","mouthStretchLeft","mouthStretchRight","mouthShrugLower","mouthShrugUpper","noseSneerLeft","noseSneerRight","mouthRollLower","mouthRollUpper","browDownLeft","browDownRight","browOuterUpLeft","browOuterUpRight","cheekPuff","cheekSquintLeft","cheekSquintRight"],this.mtExtras=[{key:"mouthOpen",mix:{jawOpen:.5}},{key:"mouthSmile",mix:{mouthSmileLeft:.8,mouthSmileRight:.8}},{key:"eyesClosed",mix:{eyeBlinkLeft:1,eyeBlinkRight:1}},{key:"eyesLookUp",mix:{eyeLookUpLeft:1,eyeLookUpRight:1}},{key:"eyesLookDown",mix:{eyeLookDownLeft:1,eyeLookDownRight:1}}],this.animQueue=[],this.animClips=[],this.animPoses=[],this.animate=this.animate.bind(this),this._raf=null,this.animFrameDur=1e3/this.opt.modelFPS,this.animClock=0,this.animSlowdownRate=1,this.animTimeLast=0,this.easing=this.sigmoidFactory(5),this.lipsync={},this.opt.lipsyncModules.forEach(l=>this.lipsyncGetProcessor(l)),this.visemeNames=["aa","E","I","O","U","PP","SS","TH","DD","FF","kk","nn","RR","CH","sil"],this.segmenter=new Intl.Segmenter("en",{granularity:"grapheme"}),this.initAudioGraph(),this.audioPlaylist=[],this.volumeFrequencyData=new Uint8Array(16),this.volumeMax=0,this.volumeHeadBase=0,this.volumeHeadTarget=0,this.volumeHeadCurrent=0,this.volumeHeadVelocity=.15,this.volumeHeadEasing=this.sigmoidFactory(3),this.isListening=!1,this.listeningAnalyzer=null,this.listeningActive=!1,this.listeningVolume=0,this.listeningSilenceThresholdLevel=this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=this.opt.listeningActiveDurationMax,this.listeningTimer=0,this.listeningTimerTotal=0,this.dracoEnabled=this.opt.dracoEnabled,this.dracoDecoderPath=this.opt.dracoDecoderPath;const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";this.b64Lookup=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let l=0;l<i.length;l++)this.b64Lookup[i.charCodeAt(l)]=l;if(this.stateName="idle",this.speechQueue=[],this.isSpeaking=!1,this.isListening=!1,this.opt.ttsEndpoint){let l=new Audio;if(l.canPlayType("audio/ogg"))this.ttsAudioEncoding="OGG-OPUS";else if(l.canPlayType("audio/mp3"))this.ttsAudioEncoding="MP3";else throw new Error("There was no support for either OGG or MP3 audio.")}if(this.isAvatarOnly=this.opt.avatarOnly,this.isAvatarOnly)this.scene=this.opt.avatarOnlyScene,this.camera=this.opt.avatarOnlyCamera;else{this.renderer=new g.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setPixelRatio(this.opt.modelPixelRatio*window.devicePixelRatio),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.renderer.outputColorSpace=g.SRGBColorSpace,this.renderer.toneMapping=g.ACESFilmicToneMapping,this.renderer.shadowMap.enabled=!1,this.nodeAvatar.appendChild(this.renderer.domElement),this.camera=new g.PerspectiveCamera(10,this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,.1,2e3),this.scene=new g.Scene,this.lightAmbient=new g.AmbientLight(new g.Color(this.opt.lightAmbientColor),this.opt.lightAmbientIntensity),this.lightDirect=new g.DirectionalLight(new g.Color(this.opt.lightDirectColor),this.opt.lightDirectIntensity),this.lightSpot=new g.SpotLight(new g.Color(this.opt.lightSpotColor),this.opt.lightSpotIntensity,0,this.opt.lightSpotDispersion),this.setLighting(this.opt);const l=new g.PMREMGenerator(this.renderer);l.compileEquirectangularShader(),this.scene.environment=l.fromScene(new Ye.RoomEnvironment).texture,this.resizeobserver=new ResizeObserver(this.onResize.bind(this)),this.resizeobserver.observe(this.nodeAvatar),this.controls=new Ze.OrbitControls(this.camera,this.renderer.domElement),this.controls.enableZoom=this.opt.cameraZoomEnable,this.controls.enableRotate=this.opt.cameraRotateEnable,this.controls.enablePan=this.opt.cameraPanEnable,this.controls.minDistance=2,this.controls.maxDistance=2e3,this.controls.autoRotateSpeed=0,this.controls.autoRotate=!1,this.controls.update(),this.cameraClock=null}this.ikMesh=new g.SkinnedMesh;const s={LeftShoulder:null,LeftArm:"LeftShoulder",LeftForeArm:"LeftArm",LeftHand:"LeftForeArm",LeftHandMiddle1:"LeftHand",RightShoulder:null,RightArm:"RightShoulder",RightForeArm:"RightArm",RightHand:"RightForeArm",RightHandMiddle1:"RightHand"},o=[];Object.entries(s).forEach((l,h)=>{const r=new g.Bone;r.name=l[0],l[1]?this.ikMesh.getObjectByName(l[1]).add(r):this.ikMesh.add(r),o.push(r)}),this.ikMesh.bind(new g.Skeleton(o)),this.dynamicbones=new $e,this.isStreaming=!1,this.streamWorkletNode=null,this.streamAudioStartTime=null,this.streamWaitForAudioChunks=!0,this.streamLipsyncLang=null,this.streamLipsyncType="visemes",this.streamLipsyncQueue=[]}initAudioGraph(n=null){if(this.audioCtx&&this.audioCtx.state!=="closed"&&this.audioCtx.close(),n?this.audioCtx=new AudioContext({sampleRate:n}):this.audioCtx=new AudioContext,this.audioSpeechSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundGainNode=this.audioCtx.createGain(),this.audioSpeechGainNode=this.audioCtx.createGain(),this.audioStreamGainNode=this.audioCtx.createGain(),this.audioAnalyzerNode=this.audioCtx.createAnalyser(),this.audioAnalyzerNode.fftSize=256,this.audioAnalyzerNode.smoothingTimeConstant=.1,this.audioAnalyzerNode.minDecibels=-70,this.audioAnalyzerNode.maxDecibels=-10,this.audioReverbNode=this.audioCtx.createConvolver(),this.audioBackgroundGainNode.connect(this.audioReverbNode),this.audioAnalyzerNode.connect(this.audioSpeechGainNode),this.audioSpeechGainNode.connect(this.audioReverbNode),this.audioStreamGainNode.connect(this.audioReverbNode),this.audioReverbNode.connect(this.audioCtx.destination),this.setReverb(this.currentReverb||null),this.setMixerGain(this.opt.mixerGainSpeech,this.opt.mixerGainBackground),this.workletLoaded=!1,this.streamWorkletNode){try{this.streamWorkletNode.port.postMessage({type:"stop"}),this.streamWorkletNode.disconnect(),this.isStreaming=!1}catch(e){console.error("Error disconnecting streamWorkletNode:",e)}this.streamWorkletNode=null}}valueFn(n){return typeof n=="function"?n():n}deepCopy(n,e=null){const t=JSON.parse(JSON.stringify(n));return e&&typeof e=="function"&&e(t),t}b64ToArrayBuffer(n){let e=3*n.length/4;n[n.length-1]==="="&&(e--,n[n.length-2]==="="&&e--);const t=new ArrayBuffer(e),i=new Uint8Array(t);let s,o=0,l,h,r,u;for(s=0;s<n.length;s+=4)l=this.b64Lookup[n.charCodeAt(s)],h=this.b64Lookup[n.charCodeAt(s+1)],r=this.b64Lookup[n.charCodeAt(s+2)],u=this.b64Lookup[n.charCodeAt(s+3)],i[o++]=l<<2|h>>4,i[o++]=(h&15)<<4|r>>2,i[o++]=(r&3)<<6|u&63;return t}concatArrayBuffers(n){if(n.length===1)return n[0];let e=0;for(let o=0;o<n.length;o++)e+=n[o].byteLength;let t=new ArrayBuffer(e),i=new Uint8Array(t),s=0;for(let o=0;o<n.length;o++)i.set(new Uint8Array(n[o]),s),s+=n[o].byteLength;return t}pcmToAudioBuffer(n){const e=new Int16Array(n),t=new Float32Array(e.length);for(let s=0;s<e.length;s++)t[s]=e[s]>=32768?-(65536-e[s])/32768:e[s]/32767;const i=this.audioCtx.createBuffer(1,t.length,this.opt.pcmSampleRate);return i.copyToChannel(t,0,0),i}propsToThreeObjects(n){const e={};for(let[t,i]of Object.entries(n)){const s=t.split(".");let o=Array.isArray(i.x)?this.gaussianRandom(...i.x):i.x,l=Array.isArray(i.y)?this.gaussianRandom(...i.y):i.y,h=Array.isArray(i.z)?this.gaussianRandom(...i.z):i.z;s[1]==="position"||s[1]==="scale"?e[t]=new g.Vector3(o,l,h):s[1]==="rotation"?(t=s[0]+".quaternion",e[t]=new g.Quaternion().setFromEuler(new g.Euler(o,l,h,"XYZ")).normalize()):s[1]==="quaternion"&&(e[t]=new g.Quaternion(o,l,h,i.w).normalize())}return e}clearThree(n){for(;n.children.length;)this.clearThree(n.children[0]),n.remove(n.children[0]);n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(e=>{e.map&&e.map.dispose(),e.dispose()}):(n.material.map&&n.material.map.dispose(),n.material.dispose()))}addMixedMorphTarget(n,e,t,i=!1){n.forEach(s=>{if(!i&&s.morphTargetDictionary.hasOwnProperty(e))return;const o=s.geometry;let l=null,h=null;for(const[r,u]of Object.entries(t))if(s.morphTargetDictionary.hasOwnProperty(r)){const a=s.morphTargetDictionary[r],d=o.morphAttributes.position[a],p=o.morphAttributes.normal?.[a];l||(l=new g.Float32BufferAttribute(d.count*3,3),p&&(h=new g.Float32BufferAttribute(d.count*3,3)));for(let y=0;y<d.count;y++){const A=l.getX(y)+d.getX(y)*u,v=l.getY(y)+d.getY(y)*u,T=l.getZ(y)+d.getZ(y)*u;l.setXYZ(y,A,v,T)}if(p)for(let y=0;y<d.count;y++){const A=h.getX(y)+p.getX(y)*u,v=h.getY(y)+p.getY(y)*u,T=h.getZ(y)+p.getZ(y)*u;h.setXYZ(y,A,v,T)}}if(l){o.morphAttributes.position.push(l),h&&o.morphAttributes.normal.push(h);const r=o.morphAttributes.position.length-1;s.morphTargetInfluences[r]=0,s.morphTargetDictionary[e]=r}})}async showAvatar(n,e=null){if(!n||!n.hasOwnProperty("url"))throw new Error("Invalid parameter. The avatar must have at least 'url' specified.");const t=new Xe.GLTFLoader;if(this.dracoEnabled){const r=new je.DRACOLoader;r.setDecoderPath(this.dracoDecoderPath),t.setDRACOLoader(r)}let i=await t.loadAsync(n.url,e);const s=[this.opt.modelRoot];if(this.posePropNames.forEach(r=>s.push(r.split(".")[0])),s.forEach(r=>{if(!i.scene.getObjectByName(r))throw new Error("Avatar object "+r+" not found")}),this.stop(),this.avatar=n,this.bodyMovement=n.bodyMovement||"idle",this.movementIntensity=n.movementIntensity||.5,this.lockedPosition=null,this.originalPosition=null,this.positionWasLocked=!1,this.fbxAnimationLoader=null,this.dynamicbones.dispose(),this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null),this.isAvatarOnly?this.armature&&this.clearThree(this.armature):this.armature&&this.clearThree(this.scene),this.armature=i.scene.getObjectByName(this.opt.modelRoot),this.armature.scale.setScalar(1),this.animations=i.animations,this.userData=i.userData,this.morphs=[],this.armature.traverse(r=>{r.morphTargetInfluences&&r.morphTargetInfluences.length&&r.morphTargetDictionary&&this.morphs.push(r),r.frustumCulled=!1}),this.morphs.length===0)throw new Error("Blend shapes not found");const o=new Set(this.mtCustoms);this.morphs.forEach(r=>{Object.keys(r.morphTargetDictionary).forEach(u=>o.add(u))}),this.mtExtras.forEach(r=>{o.has(r.key)||(this.addMixedMorphTarget(this.morphs,r.key,r.mix),o.add(r.key))});const l={};if(o.forEach(r=>{l[r]={fixed:null,realtime:null,system:null,systemd:null,newvalue:null,ref:null,min:this.mtMinExceptions.hasOwnProperty(r)?this.mtMinExceptions[r]:this.mtMinDefault,max:this.mtMaxExceptions.hasOwnProperty(r)?this.mtMaxExceptions[r]:this.mtMaxDefault,easing:this.mtEasingDefault,base:null,v:0,needsUpdate:!0,acc:(this.mtAccExceptions.hasOwnProperty(r)?this.mtAccExceptions[r]:this.mtAccDefault)/1e3,maxv:(this.mtMaxVExceptions.hasOwnProperty(r)?this.mtMaxVExceptions[r]:this.mtMaxVDefault)/1e3,limit:this.mtLimits.hasOwnProperty(r)?this.mtLimits[r]:null,onchange:this.mtOnchange.hasOwnProperty(r)?this.mtOnchange[r]:null,baseline:this.avatar.baseline?.hasOwnProperty(r)?this.avatar.baseline[r]:this.mtBaselineExceptions.hasOwnProperty(r)?this.mtBaselineExceptions[r]:this.mtBaselineDefault,ms:[],is:[]},l[r].value=l[r].baseline,l[r].applied=l[r].baseline;const u=this.mtAvatar[r];u&&["fixed","system","systemd","realtime","base","v","value","applied"].forEach(a=>{l[r][a]=u[a]}),this.morphs.forEach(a=>{const d=a.morphTargetDictionary[r];d!==void 0&&(l[r].ms.push(a.morphTargetInfluences),l[r].is.push(d),a.morphTargetInfluences[d]=l[r].applied)})}),this.mtAvatar=l,this.poseAvatar={props:{}},this.posePropNames.forEach(r=>{const u=r.split("."),a=this.armature.getObjectByName(u[0]);this.poseAvatar.props[r]=a[u[1]],this.poseBase.props.hasOwnProperty(r)?this.poseAvatar.props[r].copy(this.poseBase.props[r]):this.poseBase.props[r]=this.poseAvatar.props[r].clone(),this.poseDelta.props.hasOwnProperty(r)&&!this.poseTarget.props.hasOwnProperty(r)&&(this.poseTarget.props[r]=this.poseAvatar.props[r].clone()),this.poseTarget.props[r].t=this.animClock,this.poseTarget.props[r].d=2e3}),this.ikMesh.traverse(r=>{r.isBone&&r.position.copy(this.armature.getObjectByName(r.name).position)}),this.isAvatarOnly?this.scene&&this.scene.add(this.armature):(this.scene.add(i.scene),this.scene.add(this.lightAmbient),this.scene.add(this.lightDirect),this.scene.add(this.lightSpot),this.lightSpot.target=this.armature.getObjectByName("Head")),n.hasOwnProperty("modelDynamicBones"))try{this.dynamicbones.setup(this.scene,this.armature,n.modelDynamicBones)}catch(r){console.error("Dynamic bones setup failed: "+r)}this.objectLeftToeBase=this.armature.getObjectByName("LeftToeBase"),this.objectRightToeBase=this.armature.getObjectByName("RightToeBase"),this.objectLeftEye=this.armature.getObjectByName("LeftEye"),this.objectRightEye=this.armature.getObjectByName("RightEye"),this.objectLeftArm=this.armature.getObjectByName("LeftArm"),this.objectRightArm=this.armature.getObjectByName("RightArm"),this.objectHips=this.armature.getObjectByName("Hips"),this.objectHead=this.armature.getObjectByName("Head"),this.objectNeck=this.armature.getObjectByName("Neck");const h=new g.Vector3;this.objectLeftEye.getWorldPosition(h),this.avatarHeight=h.y+.2,this.viewName||this.setView(this.opt.cameraView),this.setMood(this.avatar.avatarMood||this.moodName||this.opt.avatarMood),this.avatar.body==="M"&&this.poseTemplates.wide&&(this.poseName="wide",this.setPoseFromTemplate(this.poseTemplates.wide,0),console.log("Set initial male-appropriate pose: wide")),this.initializeFBXAnimationLoader(),this.bodyMovement&&this.bodyMovement!=="idle"&&this.applyBodyMovementAnimation(),this.start()}getViewNames(){return["full","mid","upper","head"]}getView(){return this.viewName}setView(n,e=null){if(n=n||this.viewName,n!=="full"&&n!=="upper"&&n!=="head"&&n!=="mid")return;if(!this.armature){this.opt.cameraView=n;return}if(this.viewName=n||this.viewName,e=e||{},this.isAvatarOnly)return;const t=e.hasOwnProperty("cameraX")?e.cameraX:this.opt.cameraX,i=e.hasOwnProperty("cameraY")?e.cameraY:this.opt.cameraY,s=e.hasOwnProperty("cameraDistance")?e.cameraDistance:this.opt.cameraDistance,o=e.hasOwnProperty("cameraRotateX")?e.cameraRotateX:this.opt.cameraRotateX,l=e.hasOwnProperty("cameraRotateY")?e.cameraRotateY:this.opt.cameraRotateY,h=this.camera.fov*(Math.PI/180);let r=-t*Math.tan(h/2),u=(1-i)*Math.tan(h/2),a=s;switch(this.viewName){case"head":a+=2,u=u*a+4*this.avatarHeight/5;break;case"upper":a+=4.5,u=u*a+2*this.avatarHeight/3;break;case"mid":a+=8,u=u*a+this.avatarHeight/3;break;default:a+=12,u=u*a}r=r*a,this.controlsEnd=new g.Vector3(r,u,0),this.cameraEnd=new g.Vector3(r,u,a).applyEuler(new g.Euler(o,l,0)),this.controls&&(this.cameraClock===null&&(this.controls.target.copy(this.controlsEnd),this.camera.position.copy(this.cameraEnd)),this.controlsStart=this.controls.target.clone(),this.cameraStart=this.camera.position.clone(),this.cameraClock=0)}setLighting(n){this.isAvatarOnly||(n=n||{},n.hasOwnProperty("lightAmbientColor")&&this.lightAmbient.color.set(new g.Color(n.lightAmbientColor)),n.hasOwnProperty("lightAmbientIntensity")&&(this.lightAmbient.intensity=n.lightAmbientIntensity,this.lightAmbient.visible=n.lightAmbientIntensity!==0),n.hasOwnProperty("lightDirectColor")&&this.lightDirect.color.set(new g.Color(n.lightDirectColor)),n.hasOwnProperty("lightDirectIntensity")&&(this.lightDirect.intensity=n.lightDirectIntensity,this.lightDirect.visible=n.lightDirectIntensity!==0),n.hasOwnProperty("lightDirectPhi")&&n.hasOwnProperty("lightDirectTheta")&&this.lightDirect.position.setFromSphericalCoords(2,n.lightDirectPhi,n.lightDirectTheta),n.hasOwnProperty("lightSpotColor")&&this.lightSpot.color.set(new g.Color(n.lightSpotColor)),n.hasOwnProperty("lightSpotIntensity")&&(this.lightSpot.intensity=n.lightSpotIntensity,this.lightSpot.visible=n.lightSpotIntensity!==0),n.hasOwnProperty("lightSpotPhi")&&n.hasOwnProperty("lightSpotTheta")&&(this.lightSpot.position.setFromSphericalCoords(2,n.lightSpotPhi,n.lightSpotTheta),this.lightSpot.position.add(new g.Vector3(0,1.5,0))),n.hasOwnProperty("lightSpotDispersion")&&(this.lightSpot.angle=n.lightSpotDispersion))}render(){this.isRunning&&!this.isAvatarOnly&&this.renderer.render(this.scene,this.camera)}onResize(){this.isAvatarOnly||(this.camera.aspect=this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,this.camera.updateProjectionMatrix(),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.controls&&this.controls.update(),this.render())}updatePoseBase(n){for(const[e,t]of Object.entries(this.poseTarget.props)){const i=this.poseAvatar.props[e];if(i){let s=(n-t.t)/t.d;s>1||!this.poseBase.props.hasOwnProperty(e)?i.copy(t):i.isQuaternion?i.copy(this.poseBase.props[e].slerp(t,this.easing(s))):i.isVector3&&i.copy(this.poseBase.props[e].lerp(t,this.easing(s)))}}this.applyShoulderAdjustment()}updatePoseDelta(){for(const[n,e]of Object.entries(this.poseDelta.props)){if(e.x===0&&e.y===0&&e.z===0)continue;G.set(e.x,e.y,e.z);const t=this.poseAvatar.props[n];t.isQuaternion?(_.setFromEuler(G),t.multiply(_)):t.isVector3&&t.add(G)}}applyShoulderAdjustment(){const e=new g.Euler;if(this.poseAvatar.props["LeftShoulder.quaternion"]){const t=this.poseAvatar.props["LeftShoulder.quaternion"];e.setFromQuaternion(t,"XYZ"),e.x+=-.6,t.setFromEuler(e,"XYZ")}if(this.poseAvatar.props["RightShoulder.quaternion"]){const t=this.poseAvatar.props["RightShoulder.quaternion"];e.setFromQuaternion(t,"XYZ"),e.x+=-.6,t.setFromEuler(e,"XYZ")}}applyShoulderAdjustmentToBones(){if(!this.armature)return;const n=-.6,e=new g.Euler,t=new g.Quaternion,i=this.armature.getObjectByName("LeftShoulder"),s=this.armature.getObjectByName("RightShoulder");i&&i.quaternion&&(e.setFromQuaternion(i.quaternion,"XYZ"),e.x+=n,t.setFromEuler(e,"XYZ"),i.quaternion.copy(t),i.updateMatrixWorld(!0)),s&&s.quaternion&&(e.setFromQuaternion(s.quaternion,"XYZ"),e.x+=n,t.setFromEuler(e,"XYZ"),s.quaternion.copy(t),s.updateMatrixWorld(!0))}updateMorphTargets(n){for(let[e,t]of Object.entries(this.mtAvatar)){if(!t.needsUpdate)continue;let i=null,s=null;if(t.fixed!==null){if(i=t.fixed,t.system=null,t.systemd=null,t.newvalue=null,t.ref&&t.ref.hasOwnProperty(e)&&delete t.ref[e],t.ref=null,t.base=null,t.value===i){t.needsUpdate=!1;continue}}else t.realtime!==null?(t.ref=null,t.base=null,s=t.realtime):t.system!==null?(i=t.system,t.newvalue=null,t.ref&&t.ref.hasOwnProperty(e)&&delete t.ref[e],t.ref=null,t.base=null,t.systemd!==null?t.systemd===0?(i=null,t.system=null,t.systemd=null):(t.systemd-=n,t.systemd<0&&(t.systemd=0),t.value===i&&(i=null)):t.value===i&&(i=null,t.system=null)):t.newvalue!==null?(t.ref=null,t.base=null,s=t.newvalue,t.newvalue=null):t.base!==null?(i=t.base,t.ref=null,t.value===i&&(i=null,t.base=null,t.needsUpdate=!1)):(t.ref=null,t.baseline!==null&&t.value!==t.baseline?(i=t.baseline,t.base=t.baseline):t.needsUpdate=!1);if(i!==null){let o=i-t.value;o>=0?o<.005?(s=i,t.v=0):(t.v<t.maxv&&(t.v+=t.acc*n),t.v>=0?s=t.value+o*(1-Math.exp(-t.v*n)):s=t.value+t.v*n*(1-Math.exp(t.v*n))):o>-.005?(s=i,t.v=0):(t.v>-t.maxv&&(t.v-=t.acc*n),t.v>=0?s=t.value+t.v*n*(1-Math.exp(-t.v*n)):s=t.value+o*(1-Math.exp(t.v*n)))}if(t.limit!==null){if(s!==null&&s!==t.value&&(t.value=s,t.onchange!==null&&t.onchange(s)),s=t.limit(t.value),s===t.applied)continue}else{if(s===null||s===t.value)continue;t.value=s,t.onchange!==null&&t.onchange(s)}switch(t.applied=s,t.applied<t.min&&(t.applied=t.min),t.applied>t.max&&(t.applied=t.max),e){case"headRotateX":this.poseDelta.props["Head.quaternion"].x=t.applied+this.mtAvatar.bodyRotateX.applied;break;case"headRotateY":this.poseDelta.props["Head.quaternion"].y=t.applied+this.mtAvatar.bodyRotateY.applied;break;case"headRotateZ":this.poseDelta.props["Head.quaternion"].z=t.applied+this.mtAvatar.bodyRotateZ.applied;break;case"bodyRotateX":this.poseDelta.props["Head.quaternion"].x=t.applied+this.mtAvatar.headRotateX.applied,this.poseDelta.props["Spine1.quaternion"].x=t.applied/2,this.poseDelta.props["Spine.quaternion"].x=t.applied/8,this.poseDelta.props["Hips.quaternion"].x=t.applied/24;break;case"bodyRotateY":this.poseDelta.props["Head.quaternion"].y=t.applied+this.mtAvatar.headRotateY.applied,this.poseDelta.props["Spine1.quaternion"].y=t.applied/2,this.poseDelta.props["Spine.quaternion"].y=t.applied/2,this.poseDelta.props["Hips.quaternion"].y=t.applied/4,this.poseDelta.props["LeftUpLeg.quaternion"].y=t.applied/2,this.poseDelta.props["RightUpLeg.quaternion"].y=t.applied/2,this.poseDelta.props["LeftLeg.quaternion"].y=t.applied/4,this.poseDelta.props["RightLeg.quaternion"].y=t.applied/4;break;case"bodyRotateZ":this.poseDelta.props["Head.quaternion"].z=t.applied+this.mtAvatar.headRotateZ.applied,this.poseDelta.props["Spine1.quaternion"].z=t.applied/12,this.poseDelta.props["Spine.quaternion"].z=t.applied/12,this.poseDelta.props["Hips.quaternion"].z=t.applied/24;break;case"handFistLeft":case"handFistRight":const o=e.substring(8);["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach((u,a)=>{a===0?(this.poseDelta.props[o+u+"1.quaternion"].x=0,this.poseDelta.props[o+u+"2.quaternion"].z=(o==="Left"?-1:1)*t.applied,this.poseDelta.props[o+u+"3.quaternion"].z=(o==="Left"?-1:1)*t.applied):(this.poseDelta.props[o+u+"1.quaternion"].x=t.applied,this.poseDelta.props[o+u+"2.quaternion"].x=1.5*t.applied,this.poseDelta.props[o+u+"3.quaternion"].x=1.5*t.applied)});break;case"chestInhale":const l=t.applied/20,h={x:l,y:l/2,z:3*l},r={x:1/(1+l)-1,y:1/(1+l/2)-1,z:1/(1+3*l)-1};this.poseDelta.props["Spine1.scale"]=h,this.poseDelta.props["Neck.scale"]=r,this.poseDelta.props["LeftArm.scale"]=r,this.poseDelta.props["RightArm.scale"]=r;break;default:for(let u=0,a=t.ms.length;u<a;u++)t.ms[u][t.is[u]]=t.applied}}}getPoseString(n,e=1e3){let t="{";return Object.entries(n).forEach((i,s)=>{const o=i[0].split(".");if(o[1]==="position"||o[1]==="rotation"||o[1]==="quaternion"){const l=o[1]==="quaternion"?o[0]+".rotation":i[0],h=i[1].isQuaternion?new g.Euler().setFromQuaternion(i[1]):i[1];t+=(s?", ":"")+"'"+l+"':{",t+="x:"+Math.round(h.x*e)/e,t+=", y:"+Math.round(h.y*e)/e,t+=", z:"+Math.round(h.z*e)/e,t+="}"}}),t+="}",t}getPoseTemplateProp(n){const e=n.split(".");let t=e[0]+"."+(e[1]==="rotation"?"quaternion":e[1]);if(this.gesture&&this.gesture.hasOwnProperty(t))return this.gesture[t].clone();{let i=e[0]+"."+(e[1]==="quaternion"?"rotation":e[1]);this.poseWeightOnLeft||(i.startsWith("Left")?(i="Right"+i.substring(4),t="Right"+t.substring(4)):i.startsWith("Right")&&(i="Left"+i.substring(5),t="Left"+t.substring(5)));let s;if(this.poseTarget.template.props.hasOwnProperty(t)){const o={};o[t]=this.poseTarget.template.props[t],s=this.propsToThreeObjects(o)[t]}else if(this.poseTarget.template.props.hasOwnProperty(i)){const o={};o[i]=this.poseTarget.template.props[i],s=this.propsToThreeObjects(o)[t]}return s&&!this.poseWeightOnLeft&&s.isQuaternion&&(s.x*=-1,s.w*=-1),s}}mirrorPose(n){const e={};for(let[t,i]of Object.entries(n))i.isQuaternion&&(t.startsWith("Left")?t="Right"+t.substring(4):t.startsWith("Right")&&(t="Left"+t.substring(5)),i.x*=-1,i.w*=-1),e[t]=i.clone(),e[t].t=i.t,e[t].d=i.d;return e}poseFactory(n,e=2e3){const t={template:n,props:this.propsToThreeObjects(n.props)};for(const[i,s]of Object.entries(t.props)){if(this.opt.modelMovementFactor<1&&n.standing&&(i==="Hips.quaternion"||i==="Spine.quaternion"||i==="Spine1.quaternion"||i==="Spine2.quaternion"||i==="Neck.quaternion"||i==="LeftUpLeg.quaternion"||i==="LeftLeg.quaternion"||i==="RightUpLeg.quaternion"||i==="RightLeg.quaternion")){const o=this.poseStraight[i],l=s.angleTo(o);s.rotateTowards(o,(1-this.opt.modelMovementFactor)*l)}s.t=this.animClock,s.d=e}return t}setPoseFromTemplate(n,e=2e3){if(!this.poseFactory||!this.poseTemplates)return;const t=n&&this.poseTarget&&this.poseTarget.template&&(this.poseTarget.template.standing&&n.lying||this.poseTarget.template.lying&&n.standing),i=n&&n===this.poseCurrentTemplate,s=this.poseWeightOnLeft;let o=t?1e3:e;if(t?(this.poseCurrentTemplate=this.poseTemplates.oneknee,setTimeout(()=>{this.setPoseFromTemplate(n,e)},o)):this.poseCurrentTemplate=n||this.poseCurrentTemplate,this.poseTarget=this.poseFactory(this.poseCurrentTemplate,o),this.poseWeightOnLeft=!0,!(!this.poseTarget||!this.poseTarget.props)){if((!i&&!s||i&&s)&&(this.poseTarget.props=this.mirrorPose(this.poseTarget.props),this.poseWeightOnLeft=!this.poseWeightOnLeft),this.gesture)for(let[l,h]of Object.entries(this.gesture))this.poseTarget.props.hasOwnProperty(l)&&(this.poseTarget.props[l].copy(h),this.poseTarget.props[l].t=h.t,this.poseTarget.props[l].d=h.d);this.poseBase&&this.poseBase.props&&this.poseDelta&&this.poseDelta.props&&Object.keys(this.poseDelta.props).forEach(l=>{!this.poseTarget.props.hasOwnProperty(l)&&this.poseBase.props[l]&&(this.poseTarget.props[l]=this.poseBase.props[l].clone(),this.poseTarget.props[l].t=this.animClock,this.poseTarget.props[l].d=o)})}}getValue(n){return this.mtAvatar[n]?.value}setValue(n,e,t=null){this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{system:e,systemd:t,needsUpdate:!0})}getMoodNames(){return Object.keys(this.animMoods)}getMood(){return this.opt.avatarMood}setMood(n){if(n=(n||"").trim().toLowerCase(),!this.animMoods.hasOwnProperty(n))throw new Error("Unknown mood.");this.moodName=n,this.mood=this.animMoods[this.moodName];for(let e of Object.keys(this.mtAvatar)){let t=this.mtBaselineExceptions.hasOwnProperty(e)?this.mtBaselineExceptions[e]:this.mtBaselineDefault;this.mood.baseline.hasOwnProperty(e)?t=this.mood.baseline[e]:this.avatar.baseline?.hasOwnProperty(e)&&(t=this.avatar.baseline[e]),this.setBaselineValue(e,t)}this.mood.anims.forEach(e=>{let t=this.animQueue.findIndex(i=>i.template.name===e.name);t!==-1&&this.animQueue.splice(t,1),this.animQueue.push(this.animFactory(e,-1))})}getMorphTargetNames(){return["eyesRotateX","eyesRotateY",...Object.keys(this.mtAvatar)].sort()}getBaselineValue(n){if(n==="eyesRotateY"){const e=this.getBaselineValue("eyeLookOutLeft");if(e===void 0)return;const t=this.getBaselineValue("eyeLookInLeft");return t===void 0||this.getBaselineValue("eyeLookOutRight")===void 0||this.getBaselineValue("eyeLookInRight")===void 0?void 0:e-t}else if(n==="eyesRotateX"){const e=this.getBaselineValue("eyesLookDown");if(e===void 0)return;const t=this.getBaselineValue("eyesLookUp");return t===void 0?void 0:e-t}else return this.mtAvatar[n]?.baseline}setBaselineValue(n,e){n==="eyesRotateY"?(this.setBaselineValue("eyeLookOutLeft",e===null?null:e>0?e:0),this.setBaselineValue("eyeLookInLeft",e===null?null:e>0?0:-e),this.setBaselineValue("eyeLookOutRight",e===null?null:e>0?0:-e),this.setBaselineValue("eyeLookInRight",e===null?null:e>0?e:0)):n==="eyesRotateX"?(this.setBaselineValue("eyesLookDown",e===null?null:e>0?e:0),this.setBaselineValue("eyesLookUp",e===null?null:e>0?0:-e)):this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{base:null,baseline:e,needsUpdate:!0})}getFixedValue(n){if(n==="eyesRotateY"){const e=this.getFixedValue("eyeLookOutLeft");if(e===null)return null;const t=this.getFixedValue("eyeLookInLeft");return t===null||this.getFixedValue("eyeLookOutRight")===null||this.getFixedValue("eyeLookInRight")===null?null:e-t}else if(n==="eyesRotateX"){const e=this.getFixedValue("eyesLookDown");if(e===null)return null;const t=this.getFixedValue("eyesLookUp");return t===null?null:e-t}else return this.mtAvatar[n]?.fixed}setFixedValue(n,e,t=null){n==="eyesRotateY"?(this.setFixedValue("eyeLookOutLeft",e===null?null:e>0?e:0,t),this.setFixedValue("eyeLookInLeft",e===null?null:e>0?0:-e,t),this.setFixedValue("eyeLookOutRight",e===null?null:e>0?0:-e,t),this.setFixedValue("eyeLookInRight",e===null?null:e>0?e:0,t)):n==="eyesRotateX"?(this.setFixedValue("eyesLookDown",e===null?null:e>0?e:0,t),this.setFixedValue("eyesLookUp",e===null?null:e>0?0:-e,t)):this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{fixed:e,needsUpdate:!0})}animFactory(n,e=!1,t=1,i=1,s=!1){const o={template:n,ts:[0],vs:{}};let l=n;for(;;)if(l.hasOwnProperty(this.stateName))l=l[this.stateName];else if(l.hasOwnProperty(this.moodName))l=l[this.moodName];else if(l.hasOwnProperty(this.poseName))l=l[this.poseName];else if(l.hasOwnProperty(this.viewName))l=l[this.viewName];else if(this.avatar.body&&l.hasOwnProperty(this.avatar.body))l=l[this.avatar.body];else if(l.hasOwnProperty("alt")){let r=l.alt[0];if(l.alt.length>1){const u=Math.random();let a=0;for(let d=0;d<l.alt.length;d++){let p=this.valueFn(l.alt[d].p);if(a+=p===void 0?(1-a)/(l.alt.length-1-d):p,u<a){r=l.alt[d];break}}}l=r}else break;let h=this.valueFn(l.delay)||0;if(Array.isArray(h)&&(h=this.gaussianRandom(...h)),l.hasOwnProperty("dt"))l.dt.forEach((r,u)=>{let a=this.valueFn(r);Array.isArray(a)&&(a=this.gaussianRandom(...a)),o.ts[u+1]=o.ts[u]+a});else{let r=Object.values(l.vs).reduce((u,a)=>a.length>u?a.length:u,0);o.ts=Array(r+1).fill(0)}s?o.ts=o.ts.map(r=>h+r*t):o.ts=o.ts.map(r=>this.animClock+h+r*t);for(let[r,u]of Object.entries(l.vs)){const a=this.getBaselineValue(r),d=u.map(p=>(p=this.valueFn(p),p===null?null:typeof p=="function"?p:typeof p=="string"||p instanceof String?p.slice():Array.isArray(p)?r==="gesture"?p.slice():(a===void 0?0:a)+i*this.gaussianRandom(...p):typeof p=="boolean"?p:p instanceof Object&&p.constructor===Object?Object.assign({},p):(a===void 0?0:a)+i*p));r==="eyesRotateY"?(o.vs.eyeLookOutLeft=[null,...d.map(p=>p>0?p:0)],o.vs.eyeLookInLeft=[null,...d.map(p=>p>0?0:-p)],o.vs.eyeLookOutRight=[null,...d.map(p=>p>0?0:-p)],o.vs.eyeLookInRight=[null,...d.map(p=>p>0?p:0)]):r==="eyesRotateX"?(o.vs.eyesLookDown=[null,...d.map(p=>p>0?p:0)],o.vs.eyesLookUp=[null,...d.map(p=>p>0?0:-p)]):o.vs[r]=[null,...d]}for(let r of Object.keys(o.vs))for(;o.vs[r].length<=o.ts.length;)o.vs[r].push(o.vs[r][o.vs[r].length-1]);return n.hasOwnProperty("mood")&&(o.mood=this.valueFn(n.mood).slice()),e&&(o.loop=e),o}valueAnimationSeq(n,e,t,i,s,o=null){n=this.valueFn(n),e=this.valueFn(e),s<t&&(s=t),s>i&&(s=i);let l=(e-n)/(i-t);return o&&(l*=o((s-t)/(i-t))),l*s+(n-l*t)}gaussianRandom(n,e,t=1,i=5){let s=0;for(let o=0;o<i;o++)s+=Math.random();return n+Math.pow(s/i,t)*(e-n)}sigmoidFactory(n){function e(i){return 1/(1+Math.exp(-n*i))-.5}var t=.5/e(1);return function(i){return t*e(2*Math.max(Math.min(i,1),0)-1)+.5}}convertRange(n,e,t){return(n-e[0])*(t[1]-t[0])/(e[1]-e[0])+t[0]}animate(n){if(!this.isRunning)return;let e;if(this.isAvatarOnly)e=n;else{if(this._raf=requestAnimationFrame(this.animate),e=n-this.animTimeLast,e<this.animFrameDur)return;this.animTimeLast=n}e=e/this.animSlowdownRate,this.animClock+=e,this.maintainLockedPosition();let t,i,s,o,l=0;if(this.stats&&this.stats.begin(),this.isListening){for(this.listeningAnalyzer.getByteFrequencyData(this.volumeFrequencyData),t=2,s=10;t<s;t++)this.volumeFrequencyData[t]>l&&(l=this.volumeFrequencyData[t]);this.listeningVolume=(this.listeningVolume+l)/2,this.listeningActive?(this.listeningTimerTotal+=e,this.listeningVolume<this.listeningSilenceThresholdLevel?(this.listeningTimer+=e,this.listeningTimer>this.listeningSilenceThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("stop",this.listeningTimer),this.listeningActive=!1,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningActiveDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxactive"),this.listeningTimerTotal=0)):(this.listeningTimerTotal+=e,this.listeningVolume>this.listeningActiveThresholdLevel?(this.listeningTimer+=e,this.listeningTimer>this.listeningActiveThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("start"),this.listeningActive=!0,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningSilenceDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxsilence"),this.listeningTimerTotal=0))}if(this.isSpeaking)for(l=0,this.audioAnalyzerNode.getByteFrequencyData(this.volumeFrequencyData),t=2,s=10;t<s;t++)this.volumeFrequencyData[t]>l&&(l=this.volumeFrequencyData[t]);let h=null,r=null;const u=[];for(t=0,s=this.animQueue.length;t<s;t++){const a=this.animQueue[t];if(!(this.animClock<a.ts[0])){for(i=a.ndx||0,o=a.ts.length;i<o&&!(this.animClock<a.ts[i]);i++)for(let[d,p]of Object.entries(a.vs))if(this.mtAvatar.hasOwnProperty(d)){if(p[i+1]===null)continue;const y=this.mtAvatar[d];if(p[i]===null&&(p[i]=y.value),i===o-1)y.newvalue=p[i];else{y.newvalue=p[i+1];const A=a.ts[i+1]-a.ts[i];let v=1;A>1e-4&&(v=(this.animClock-a.ts[i])/A),v<1&&(y.easing&&(v=y.easing(v)),y.newvalue=(1-v)*p[i]+v*y.newvalue),y.ref&&y.ref!==a.vs&&y.ref.hasOwnProperty(d)&&delete y.ref[d],y.ref=a.vs}if(l)switch(d){case"viseme_aa":case"viseme_E":case"viseme_I":case"viseme_O":case"viseme_U":y.newvalue*=1+l/255-.5}y.needsUpdate=!0}else d==="eyeContact"&&p[i]!==null&&h!==!1?h=!!p[i]:d==="headMove"&&p[i]!==null&&r!==!1?p[i]===0?r=!1:(Math.random()<p[i]&&(r=!0),p[i]=null):p[i]!==null&&(u.push({mt:d,val:p[i]}),p[i]=null);i===o?(a.hasOwnProperty("mood")&&this.setMood(a.mood),a.loop?(o=this.isSpeaking&&(a.template.name==="head"||a.template.name==="eyes")?4:1,this.animQueue[t]=this.animFactory(a.template,a.loop>0?a.loop-1:a.loop,1,1/o)):(this.animQueue.splice(t--,1),s--)):a.ndx=i-1}}for(let a=0,d=u.length;a<d;a++)switch(i=u[a].val,u[a].mt){case"speak":this.speakText(i);break;case"subtitles":this.onSubtitles&&typeof this.onSubtitles=="function"&&this.onSubtitles(i);break;case"pose":this.poseName=i,this.setPoseFromTemplate(this.poseTemplates[this.poseName]);break;case"gesture":this.playGesture(...i);break;case"function":i&&typeof i=="function"&&i();break;case"moveto":Object.entries(i.props).forEach(p=>{p[1]?this.poseTarget.props[p[0]].copy(p[1]):this.poseTarget.props[p[0]].copy(this.getPoseTemplateProp(p[0])),this.poseTarget.props[p[0]].t=this.animClock,this.poseTarget.props[p[0]].d=p[1]&&p[1].d?p[1].d:p.duration||2e3});break;case"handLeft":this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new g.Vector3(i.x,i.y,i.z):null,!0,i.d);break;case"handRight":this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new g.Vector3(i.x,i.y,i.z):null,!0,i.d);break}if((h||r)&&(G.setFromQuaternion(this.poseAvatar.props["Head.quaternion"]),G.x=Math.max(-.9,Math.min(.9,2*G.x-.5)),G.y=Math.max(-.9,Math.min(.9,-2.5*G.y)),h?(Object.assign(this.mtAvatar.eyesLookDown,{system:G.x<0?-G.x:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyesLookUp,{system:G.x<0?0:G.x,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInLeft,{system:G.y<0?-G.y:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutLeft,{system:G.y<0?0:G.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInRight,{system:G.y<0?0:G.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutRight,{system:G.y<0?-G.y:0,needsUpdate:!0}),r&&(t=-this.mtAvatar.bodyRotateY.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[t,t,0],headRotateX:[i,i,0],headRotateZ:[-t/4,-t/4,0]}})))):(t=this.mtAvatar.eyeLookInLeft.value-this.mtAvatar.eyeLookOutLeft.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[null,t,t,0],headRotateX:[null,i,i,0],headRotateZ:[null,-t/4,-t/4,0],eyeLookInLeft:[null,0],eyeLookOutLeft:[null,0],eyeLookInRight:[null,0],eyeLookOutRight:[null,0],eyeContact:[0]}})))),e>2*this.animFrameDur&&(e=2*this.animFrameDur),(this.viewName!=="full"||this.isAvatarOnly)&&(t=this.mtRandomized[Math.floor(Math.random()*this.mtRandomized.length)],i=this.mtAvatar[t],i.needsUpdate||Object.assign(i,{base:(this.mood.baseline[t]||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)&&h?l>this.volumeMax?(this.volumeHeadBase=.05,Math.random()>.6&&(this.volumeHeadTarget=-.05-Math.random()/15),this.volumeMax=l):(this.volumeMax*=.92,this.volumeHeadTarget=this.volumeHeadBase-.9*(this.volumeHeadBase-this.volumeHeadTarget)):(this.volumeHeadTarget=0,this.volumeMax=0),t=this.volumeHeadTarget-this.volumeHeadCurrent,i=Math.abs(t),i>1e-4&&(o=i*(this.volumeHeadEasing(Math.min(1,this.volumeHeadVelocity*e/1e3/i)/2+.5)-.5),this.volumeHeadCurrent+=Math.sign(t)*Math.min(i,o)),Math.abs(this.volumeHeadCurrent)>1e-4&&(_.setFromAxisAngle(ct,this.volumeHeadCurrent),this.objectNeck.quaternion.multiply(_)),Be.setFromObject(this.armature),this.objectLeftToeBase.getWorldPosition(fe),fe.sub(this.armature.position),this.objectRightToeBase.getWorldPosition(xe),xe.sub(this.armature.position),this.objectHips.position.y-=Be.min.y/2,this.objectHips.position.x-=(fe.x+xe.x)/4,this.objectHips.position.z-=(fe.z+xe.z)/2,this.dynamicbones.update(e),this.fbxAnimationLoader&&this.fbxAnimationLoader.update(),this.applyShoulderAdjustmentToBones(),this.opt.update&&this.opt.update(e),this.updateMorphTargets(e),this.isAvatarOnly)this.stats&&this.stats.end();else{if(this.controls&&this.cameraClock!==null&&this.cameraClock<1e3){this.cameraClock+=e,this.cameraClock>1e3&&(this.cameraClock=1e3);let a=new g.Spherical().setFromVector3(this.cameraStart),d=new g.Spherical().setFromVector3(this.cameraEnd);a.phi+=this.easing(this.cameraClock/1e3)*(d.phi-a.phi),a.theta+=this.easing(this.cameraClock/1e3)*(d.theta-a.theta),a.radius+=this.easing(this.cameraClock/1e3)*(d.radius-a.radius),a.makeSafe(),this.camera.position.setFromSpherical(a),this.controlsStart.x!==this.controlsEnd.x?this.controls.target.copy(this.controlsStart.lerp(this.controlsEnd,this.easing(this.cameraClock/1e3))):(a.setFromVector3(this.controlsStart),d.setFromVector3(this.controlsEnd),a.phi+=this.easing(this.cameraClock/1e3)*(d.phi-a.phi),a.theta+=this.easing(this.cameraClock/1e3)*(d.theta-a.theta),a.radius+=this.easing(this.cameraClock/1e3)*(d.radius-a.radius),a.makeSafe(),this.controls.target.setFromSpherical(a)),this.controls.update()}this.controls&&this.controls.autoRotate&&this.controls.update(),this.stats&&this.stats.end(),this.render()}}resetLips(){this.visemeNames.forEach(n=>{this.morphs.forEach(e=>{const t=e.morphTargetDictionary["viseme_"+n];t!==void 0&&(e.morphTargetInfluences[t]=0)})})}lipsyncGetProcessor(n,e="./"){if(!this.lipsync.hasOwnProperty(n)){const t=n.toLowerCase();if(Te[t]){const i="Lipsync"+n.charAt(0).toUpperCase()+n.slice(1);Te[t][i]?this.lipsync[n]=new Te[t][i]:console.warn(`Lipsync class ${i} not found in module for language ${n}`)}else console.warn(`Lipsync module for language ${n} not found in static imports`)}}lipsyncPreProcessText(n,e){return(this.lipsync[e]||Object.values(this.lipsync)[0]).preProcessText(n)}lipsyncWordsToVisemes(n,e){return(this.lipsync[e]||Object.values(this.lipsync)[0]).wordsToVisemes(n)}speakText(n,e=null,t=null,i=null){e=e||{};const s=/[!\.\?\n\p{Extended_Pictographic}]/ug,o=/[ ]/ug,l=/[\p{L}\p{N},\.\p{Quotation_Mark}!€\$\+\p{Dash_Punctuation}%&\?]/ug,h=/[\p{Extended_Pictographic}]/ug,r=e.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang;let u="",a="",d=0,p=[],y=[];const A=Array.from(this.segmenter.segment(n),v=>v.segment);for(let v=0;v<A.length;v++){const T=v===A.length-1,C=A[v].match(l);let m=A[v].match(s);const L=A[v].match(h),E=A[v].match(o);if(m&&!T&&!L&&A[v+1].match(s)&&(m=!1),t&&(u+=A[v]),C&&(!i||i.every(R=>v<R[0]||v>R[1]))&&(a+=A[v]),(E||m||T)&&(a.length&&(a=this.lipsyncPreProcessText(a,r),a.length&&p.push({mark:d,word:a})),u.length&&(y.push({mark:d,template:{name:"subtitles"},ts:[0],vs:{subtitles:[u]}}),u=""),a.length)){const R=this.lipsyncWordsToVisemes(a,r);if(R&&R.visemes&&R.visemes.length){const M=R.times[R.visemes.length-1]+R.durations[R.visemes.length-1];for(let k=0;k<R.visemes.length;k++)y.push({mark:d,template:{name:"viseme"},ts:[(R.times[k]-.6)/M,(R.times[k]+.5)/M,(R.times[k]+R.durations[k]+.5)/M],vs:{["viseme_"+R.visemes[k]]:[null,R.visemes[k]==="PP"||R.visemes[k]==="FF"?.9:.6,0]}})}a="",d++}if(m||T){if(p.length||T&&y.length){const R={anim:y};t&&(R.onSubtitles=t),p.length&&!e.avatarMute&&(R.text=p,e.avatarMood&&(R.mood=e.avatarMood),e.ttsLang&&(R.lang=e.ttsLang),e.ttsVoice&&(R.voice=e.ttsVoice),e.ttsRate&&(R.rate=e.ttsRate),e.ttsVoice&&(R.pitch=e.ttsPitch),e.ttsVolume&&(R.volume=e.ttsVolume)),this.speechQueue.push(R),p=[],a="",d=0,y=[]}if(L){let R=this.animEmojis[A[v]];R&&R.link&&(R=this.animEmojis[R.link]),R&&this.speechQueue.push({emoji:R})}this.speechQueue.push({break:100})}}this.speechQueue.push({break:1e3}),this.startSpeaking()}async speakEmoji(n){let e=this.animEmojis[n];e&&e.link&&(e=this.animEmojis[e.link]),e&&this.speechQueue.push({emoji:e}),this.startSpeaking()}async speakBreak(n){this.speechQueue.push({break:n}),this.startSpeaking()}async speakMarker(n){this.speechQueue.push({marker:n}),this.startSpeaking()}async playBackgroundAudio(n){let t=await(await fetch(n)).arrayBuffer();this.stopBackgroundAudio(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource.loop=!0,this.audioBackgroundSource.buffer=await this.audioCtx.decodeAudioData(t),this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate,this.audioBackgroundSource.connect(this.audioBackgroundGainNode),this.audioBackgroundSource.start(0)}stopBackgroundAudio(){try{this.audioBackgroundSource.stop()}catch{}this.audioBackgroundSource.disconnect()}async setReverb(n=null){if(n){let t=await(await fetch(n)).arrayBuffer();this.audioReverbNode.buffer=await this.audioCtx.decodeAudioData(t)}else{const e=this.audioCtx.sampleRate,t=this.audioCtx.createBuffer(2,e,e);t.getChannelData(0)[0]=1,t.getChannelData(1)[0]=1,this.audioReverbNode.buffer=t}}setMixerGain(n,e=null,t=0){n!==null&&(this.audioSpeechGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),t?(this.audioSpeechGainNode.gain.setValueAtTime(Math.max(this.audioSpeechGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioSpeechGainNode.gain.exponentialRampToValueAtTime(Math.max(n,1e-4),this.audioCtx.currentTime+t)):this.audioSpeechGainNode.gain.setValueAtTime(n,this.audioCtx.currentTime)),e!==null&&(this.audioBackgroundGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),t?(this.audioBackgroundGainNode.gain.setValueAtTime(Math.max(this.audioBackgroundGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioBackgroundGainNode.gain.exponentialRampToValueAtTime(Math.max(e,1e-4),this.audioCtx.currentTime+t)):this.audioBackgroundGainNode.gain.setValueAtTime(e,this.audioCtx.currentTime))}speakAudio(n,e=null,t=null){e=e||{};const i=e.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,s={};if(n.words){let o=[];for(let l=0;l<n.words.length;l++){const h=n.words[l],r=n.wtimes[l];let u=n.wdurations[l];if(h.length&&(t&&o.push({template:{name:"subtitles"},ts:[r],vs:{subtitles:[" "+h]}}),!n.visemes)){const a=this.lipsyncPreProcessText(h,i),d=this.lipsyncWordsToVisemes(a,i);if(d&&d.visemes&&d.visemes.length){const p=d.times[d.visemes.length-1]+d.durations[d.visemes.length-1],y=Math.min(u,Math.max(0,u-d.visemes.length*150));let A=.6+this.convertRange(y,[0,u],[0,.4]);if(u=Math.min(u,d.visemes.length*200),p>0)for(let v=0;v<d.visemes.length;v++){const T=r+d.times[v]/p*u,C=d.durations[v]/p*u;o.push({template:{name:"viseme"},ts:[T-Math.min(60,2*C/3),T+Math.min(25,C/2),T+C+Math.min(60,C/2)],vs:{["viseme_"+d.visemes[v]]:[null,d.visemes[v]==="PP"||d.visemes[v]==="FF"?.9:A,0]}})}}}}if(n.visemes)for(let l=0;l<n.visemes.length;l++){const h=n.visemes[l],r=n.vtimes[l],u=n.vdurations[l];o.push({template:{name:"viseme"},ts:[r-2*u/3,r+u/2,r+u+u/2],vs:{["viseme_"+h]:[null,h==="PP"||h==="FF"?.9:.6,0]}})}if(n.markers)for(let l=0;l<n.markers.length;l++){const h=n.markers[l],r=n.mtimes[l];o.push({template:{name:"markers"},ts:[r],vs:{function:[h]}})}o.length&&(s.anim=o)}if(n.audio&&(s.audio=n.audio),n.anim?.name){let o=this.animFactory(n.anim,!1,1,1,!0);s.anim?s.anim.push(o):s.anim=[o]}t&&(s.onSubtitles=t),e.isRaw&&(s.isRaw=!0),Object.keys(s).length&&(this.speechQueue.push(s),s.isRaw||this.speechQueue.push({break:300}),this.startSpeaking())}async playAudio(n=!1){if(!(!this.armature||this.isAudioPlaying&&!n))if(this.isAudioPlaying=!0,this.audioPlaylist.length){const e=this.audioPlaylist.shift();if(this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const o=this.audioCtx.resume(),l=new Promise((h,r)=>setTimeout(()=>r("p2"),1e3));try{await Promise.race([o,l])}catch{console.log("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser."),this.playAudio(!0);return}}let t;if(Array.isArray(e.audio)){let o=this.concatArrayBuffers(e.audio);t=this.pcmToAudioBuffer(o)}else t=e.audio;if(this.audioSpeechSource){try{this.audioSpeechSource.stop?.()}catch{}this.audioSpeechSource.disconnect(),this.audioSpeechSource.onended=null,this.audioSpeechSource=null}const i=this.audioCtx.createBufferSource();this.audioSpeechSource=i,i.buffer=t,i.playbackRate.value=1/this.animSlowdownRate,i.connect(this.audioAnalyzerNode),i.onended=()=>{i.disconnect(),i.onended=null,this.audioSpeechSource===i&&(this.audioSpeechSource=null),this.playAudio(!0)};let s=0;e.anim&&(e.isRaw||(s=Math.abs(Math.min(0,...e.anim.map(o=>Math.min(...o.ts))))),e.anim.forEach(o=>{for(let l=0;l<o.ts.length;l++)o.ts[l]=this.animClock+o.ts[l]+s;this.animQueue.push(o)})),i.start(this.audioCtx.currentTime+s/1e3)}else this.isAudioPlaying=!1,this.startSpeaking(!0)}async startSpeaking(n=!1){if(!(!this.armature||this.isSpeaking&&!n))if(this.stateName="speaking",this.isSpeaking=!0,this.speechQueue.length){let e=this.speechQueue.shift();if(e.emoji){this.lookAtCamera(500);let t=e.emoji.dt.reduce((i,s)=>i+s,0);this.animQueue.push(this.animFactory(e.emoji)),setTimeout(this.startSpeaking.bind(this),t,!0)}else if(e.break)setTimeout(this.startSpeaking.bind(this),e.break,!0);else if(e.audio)e.isRaw||(this.lookAtCamera(500),this.speakWithHands(),this.resetLips()),this.audioPlaylist.push({anim:e.anim,audio:e.audio,isRaw:e.isRaw}),this.onSubtitles=e.onSubtitles||null,e.mood&&this.setMood(e.mood),this.playAudio();else if(e.text){this.lookAtCamera(500);try{let t="<speak>";e.text.forEach((l,h)=>{h>0&&(t+=" <mark name='"+l.mark+"'/>"),t+=l.word.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replace(new RegExp("^\\p{Dash_Punctuation}$","ug"),'<break time="750ms"/>')}),t+="</speak>";const i={method:"POST",headers:{"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify({input:{ssml:t},voice:{languageCode:e.lang||this.avatar.ttsLang||this.opt.ttsLang,name:e.voice||this.avatar.ttsVoice||this.opt.ttsVoice},audioConfig:{audioEncoding:this.ttsAudioEncoding,speakingRate:(e.rate||this.avatar.ttsRate||this.opt.ttsRate)+this.mood.speech.deltaRate,pitch:(e.pitch||this.avatar.ttsPitch||this.opt.ttsPitch)+this.mood.speech.deltaPitch,volumeGainDb:(e.volume||this.avatar.ttsVolume||this.opt.ttsVolume)+this.mood.speech.deltaVolume},enableTimePointing:[1]})};this.opt.jwtGet&&typeof this.opt.jwtGet=="function"&&(i.headers.Authorization="Bearer "+await this.opt.jwtGet());const s=await fetch(this.opt.ttsEndpoint+(this.opt.ttsApikey?"?key="+this.opt.ttsApikey:""),i),o=await s.json();if(s.status===200&&o&&o.audioContent){const l=this.b64ToArrayBuffer(o.audioContent),h=await this.audioCtx.decodeAudioData(l);this.speakWithHands();const r=[0];let u=0;e.text.forEach((p,y)=>{if(y>0){let A=r[r.length-1];o.timepoints[u]&&(A=o.timepoints[u].timeSeconds*1e3,o.timepoints[u].markName===""+p.mark&&u++),r.push(A)}});const a=[{mark:0,time:0}];r.forEach((p,y)=>{if(y>0){let A=p-r[y-1];A>150&&A-150,a[y-1].duration=A,a.push({mark:y,time:p})}});let d=1e3*h.duration;d>this.opt.ttsTrimEnd&&(d=d-this.opt.ttsTrimEnd),a[a.length-1].duration=d-a[a.length-1].time,e.anim.forEach(p=>{const y=a[p.mark];if(y)for(let A=0;A<p.ts.length;A++)p.ts[A]=y.time+p.ts[A]*y.duration+this.opt.ttsTrimStart}),this.audioPlaylist.push({anim:e.anim,audio:h}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio()}else this.startSpeaking(!0)}catch(t){console.error("Error:",t),this.startSpeaking(!0)}}else e.anim?(this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),e.anim.forEach((t,i)=>{for(let s=0;s<t.ts.length;s++)t.ts[s]=this.animClock+10*i;this.animQueue.push(t)}),setTimeout(this.startSpeaking.bind(this),10*e.anim.length,!0)):e.marker?(typeof e.marker=="function"&&e.marker(),this.startSpeaking(!0)):this.startSpeaking(!0)}else this.stateName="idle",this.isSpeaking=!1}pauseSpeaking(){try{this.audioSpeechSource?.stop()}catch{}this.audioPlaylist.length=0,this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.animQueue=this.animQueue.filter(n=>n.template.name!=="viseme"&&n.template.name!=="subtitles"&&n.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render())}stopSpeaking(){try{this.audioSpeechSource?.stop()}catch{}this.audioPlaylist.length=0,this.speechQueue.length=0,this.animQueue=this.animQueue.filter(n=>n.template.name!=="viseme"&&n.template.name!=="subtitles"&&n.template.name!=="blendshapes"),this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.armature&&(this.resetLips(),this.render())}async streamStart(n={},e=null,t=null,i=null,s=null){if(this.stopSpeaking(),this.isStreaming=!0,n.waitForAudioChunks!==void 0&&(this.streamWaitForAudioChunks=n.waitForAudioChunks),this.streamWaitForAudioChunks||(this.streamAudioStartTime=this.animClock),this.streamLipsyncQueue=[],this.streamLipsyncType=n.lipsyncType||this.streamLipsyncType||"visemes",this.streamLipsyncLang=n.lipsyncLang||this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,this.onAudioStart=e,this.onAudioEnd=t,this.onMetrics=s,n.sampleRate!==void 0){const l=n.sampleRate;typeof l=="number"&&l>=8e3&&l<=96e3?l!==this.audioCtx.sampleRate&&this.initAudioGraph(l):console.warn("Invalid sampleRate provided. It must be a number between 8000 and 96000 Hz.")}if(n.gain!==void 0&&(this.audioStreamGainNode.gain.value=n.gain),!this.streamWorkletNode||!this.streamWorkletNode.port||this.streamWorkletNode.numberOfOutputs===0||this.streamWorkletNode.context!==this.audioCtx){if(this.streamWorkletNode)try{this.streamWorkletNode.disconnect(),this.streamWorkletNode=null}catch{}if(!this.workletLoaded)try{const l=this.audioCtx.audioWorklet.addModule(ht.href),h=new Promise((r,u)=>setTimeout(()=>u(new Error("Worklet loading timed out")),5e3));await Promise.race([l,h]),this.workletLoaded=!0}catch(l){throw console.error("Failed to load audio worklet:",l),new Error("Failed to initialize streaming speech")}this.streamWorkletNode=new AudioWorkletNode(this.audioCtx,"playback-worklet",{processorOptions:{sampleRate:this.audioCtx.sampleRate,metrics:n.metrics||{enabled:!1}}}),this.streamWorkletNode.connect(this.audioStreamGainNode),this.streamWorkletNode.connect(this.audioAnalyzerNode),this.streamWorkletNode.port.onmessage=l=>{if(l.data.type==="playback-started"&&(this.isSpeaking=!0,this.stateName="speaking",this.streamWaitForAudioChunks&&(this.streamAudioStartTime=this.animClock),this._processStreamLipsyncQueue(),this.speakWithHands(),this.onAudioStart))try{this.onAudioStart?.()}catch(h){console.error(h)}if(l.data.type==="playback-ended"&&(this._streamPause(),this.onAudioEnd))try{this.onAudioEnd()}catch{}if(this.onMetrics&&l.data.type==="metrics")try{this.onMetrics(l.data)}catch{}}}if(n.metrics)try{this.streamWorkletNode.port.postMessage({type:"config-metrics",data:n.metrics})}catch{}if(this.resetLips(),this.lookAtCamera(500),n.mood&&this.setMood(n.mood),this.onSubtitles=i||null,this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const l=this.audioCtx.resume(),h=new Promise((r,u)=>setTimeout(()=>u("p2"),1e3));try{await Promise.race([l,h])}catch{console.warn("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser.");return}}}streamNotifyEnd(){!this.isStreaming||!this.streamWorkletNode||this.streamWorkletNode.port.postMessage({type:"no-more-data"})}streamInterrupt(){if(!this.isStreaming)return;const n=this.isSpeaking;if(this.streamWorkletNode)try{this.streamWorkletNode.port.postMessage({type:"stop"})}catch{}if(this._streamPause(!0),n&&this.onAudioEnd)try{this.onAudioEnd()}catch{}}streamStop(){if(this.isStreaming){if(this.streamInterrupt(),this.streamWorkletNode){try{this.streamWorkletNode.disconnect()}catch{}this.streamWorkletNode=null}this.isStreaming=!1}}_streamPause(n=!1){this.isSpeaking=!1,this.stateName="idle",n&&(this.streamWaitForAudioChunks&&(this.streamAudioStartTime=null),this.streamLipsyncQueue=[],this.animQueue=this.animQueue.filter(e=>e.template.name!=="viseme"&&e.template.name!=="subtitles"&&e.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render()))}_processStreamLipsyncQueue(){if(this.isStreaming)for(;this.streamLipsyncQueue.length>0;){const n=this.streamLipsyncQueue.shift();this._processLipsyncData(n,this.streamAudioStartTime)}}_processLipsyncData(n,e){if(this.isStreaming){if(n.visemes&&this.streamLipsyncType=="visemes")for(let t=0;t<n.visemes.length;t++){const i=n.visemes[t],s=e+n.vtimes[t],o=n.vdurations[t],l={template:{name:"viseme"},ts:[s-2*o/3,s+o/2,s+o+o/2],vs:{["viseme_"+i]:[null,i==="PP"||i==="FF"?.9:.6,0]}};this.animQueue.push(l)}if(n.words&&(this.onSubtitles||this.streamLipsyncType=="words"))for(let t=0;t<n.words.length;t++){const i=n.words[t],s=n.wtimes[t];let o=n.wdurations[t];if(i.length&&(this.onSubtitles&&this.animQueue.push({template:{name:"subtitles"},ts:[e+s],vs:{subtitles:[" "+i]}}),this.streamLipsyncType=="words")){const l=this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,h=this.lipsyncPreProcessText(i,l),r=this.lipsyncWordsToVisemes(h,l);if(r&&r.visemes&&r.visemes.length){const u=r.times[r.visemes.length-1]+r.durations[r.visemes.length-1],a=Math.min(o,Math.max(0,o-r.visemes.length*150));let d=.6+this.convertRange(a,[0,o],[0,.4]);if(o=Math.min(o,r.visemes.length*200),u>0)for(let p=0;p<r.visemes.length;p++){const y=e+s+r.times[p]/u*o,A=r.durations[p]/u*o;this.animQueue.push({template:{name:"viseme"},ts:[y-Math.min(60,2*A/3),y+Math.min(25,A/2),y+A+Math.min(60,A/2)],vs:{["viseme_"+r.visemes[p]]:[null,r.visemes[p]==="PP"||r.visemes[p]==="FF"?.9:d,0]}})}}}}if(n.anims&&this.streamLipsyncType=="blendshapes")for(let t=0;t<n.anims.length;t++){let i=n.anims[t];i.delay+=e;let s=this.animFactory(i,!1,1,1,!0);this.animQueue.push(s)}}}streamAudio(n){if(!(!this.isStreaming||!this.streamWorkletNode)){if(this.isSpeaking||(this.streamLipsyncQueue=[],this.streamAudioStartTime=null),this.isSpeaking=!0,this.stateName="speaking",n.audio!==void 0){const e={type:"audioData",data:null};if(n.audio instanceof ArrayBuffer)e.data=n.audio,this.streamWorkletNode.port.postMessage(e,[e.data]);else if(n.audio instanceof Int16Array||n.audio instanceof Uint8Array){const t=n.audio.buffer.slice(n.audio.byteOffset,n.audio.byteOffset+n.audio.byteLength);e.data=t,this.streamWorkletNode.port.postMessage(e,[e.data])}else if(n.audio instanceof Float32Array){const t=new Int16Array(n.audio.length);for(let i=0;i<n.audio.length;i++){let s=Math.max(-1,Math.min(1,n.audio[i]));t[i]=s<0?s*32768:s*32767}e.data=t.buffer,this.streamWorkletNode.port.postMessage(e,[e.data])}else console.error("r.audio is not a supported type. Must be ArrayBuffer, Int16Array, Uint8Array, or Float32Array:",n.audio)}if(n.visemes||n.anims||n.words){if(this.streamWaitForAudioChunks&&!this.streamAudioStartTime){this.streamLipsyncQueue.length>=200&&this.streamLipsyncQueue.shift(),this.streamLipsyncQueue.push(n);return}else!this.streamWaitForAudioChunks&&!this.streamAudioStartTime&&(this.streamAudioStartTime=this.animClock);this._processLipsyncData(n,this.streamAudioStartTime)}}}makeEyeContact(n){this.animQueue.push(this.animFactory({name:"eyecontact",dt:[0,n],vs:{eyeContact:[1]}}))}lookAhead(n){if(n){let e=(Math.random()-.5)/4,t=(Math.random()-.5)/4,i=this.animQueue.findIndex(o=>o.template.name==="lookat");i!==-1&&this.animQueue.splice(i,1);const s={name:"lookat",dt:[750,n],vs:{bodyRotateX:[e],bodyRotateY:[t],eyesRotateX:[-3*e+.1],eyesRotateY:[-5*t],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(s))}}lookAtCamera(n){let e;if(this.speakTo&&(e=new g.Vector3,this.speakTo.objectLeftEye?.isObject3D?(this.speakTo.armature.objectHead,this.speakTo.objectLeftEye.updateMatrixWorld(!0),this.speakTo.objectRightEye.updateMatrixWorld(!0),fe.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld),xe.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld),e.addVectors(fe,xe).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){if(this.avatar.hasOwnProperty("avatarIgnoreCamera")){if(this.avatar.avatarIgnoreCamera){this.lookAhead(n);return}}else if(this.opt.avatarIgnoreCamera){this.lookAhead(n);return}this.lookAt(null,null,n);return}this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0),fe.setFromMatrixPosition(this.objectLeftEye.matrixWorld),xe.setFromMatrixPosition(this.objectRightEye.matrixWorld),fe.add(xe).divideScalar(2),_.copy(this.armature.quaternion),_.multiply(this.poseTarget.props["Hips.quaternion"]),_.multiply(this.poseTarget.props["Spine.quaternion"]),_.multiply(this.poseTarget.props["Spine1.quaternion"]),_.multiply(this.poseTarget.props["Spine2.quaternion"]),_.multiply(this.poseTarget.props["Neck.quaternion"]),_.multiply(this.poseTarget.props["Head.quaternion"]);const t=new g.Vector3().subVectors(e,fe).normalize(),i=Math.atan2(t.x,t.z),s=Math.asin(-t.y);G.set(s,i,0,"YXZ");const l=new g.Quaternion().setFromEuler(G),h=new g.Quaternion().copy(l).multiply(_.clone().invert());G.setFromQuaternion(h,"YXZ");let r=G.x/(40/24)+.2,u=G.y/(9/4),a=Math.min(.6,Math.max(-.3,r)),d=Math.min(.8,Math.max(-.8,u)),p=(Math.random()-.5)/4,y=(Math.random()-.5)/4;if(n){let A=this.animQueue.findIndex(T=>T.template.name==="lookat");A!==-1&&this.animQueue.splice(A,1);const v={name:"lookat",dt:[750,n],vs:{bodyRotateX:[a+p],bodyRotateY:[d+y],eyesRotateX:[-3*p+.1],eyesRotateY:[-5*y],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(v))}}lookAt(n,e,t){if(!this.camera)return;const i=this.nodeAvatar.getBoundingClientRect();this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0);const s=new g.Vector3().setFromMatrixPosition(this.objectLeftEye.matrixWorld),o=new g.Vector3().setFromMatrixPosition(this.objectRightEye.matrixWorld),l=new g.Vector3().addVectors(s,o).divideScalar(2);l.project(this.camera);let h=(l.x+1)/2*i.width+i.left,r=-(l.y-1)/2*i.height+i.top;n===null&&(n=h),e===null&&(e=r),_.copy(this.armature.quaternion),_.multiply(this.poseTarget.props["Hips.quaternion"]),_.multiply(this.poseTarget.props["Spine.quaternion"]),_.multiply(this.poseTarget.props["Spine1.quaternion"]),_.multiply(this.poseTarget.props["Spine2.quaternion"]),_.multiply(this.poseTarget.props["Neck.quaternion"]),_.multiply(this.poseTarget.props["Head.quaternion"]),G.setFromQuaternion(_);let u=G.x/(40/24),a=G.y/(9/4),d=Math.min(.4,Math.max(-.4,this.camera.rotation.x)),p=Math.min(.4,Math.max(-.4,this.camera.rotation.y)),y=Math.max(window.innerWidth-h,h),A=Math.max(window.innerHeight-r,r),v=this.convertRange(e,[r-A,r+A],[-.3,.6])-u+d,T=this.convertRange(n,[h-y,h+y],[-.8,.8])-a+p;v=Math.min(.6,Math.max(-.3,v)),T=Math.min(.8,Math.max(-.8,T));let C=(Math.random()-.5)/4,m=(Math.random()-.5)/4;if(t){let L=this.animQueue.findIndex(R=>R.template.name==="lookat");L!==-1&&this.animQueue.splice(L,1);const E={name:"lookat",dt:[750,t],vs:{bodyRotateX:[v+C],bodyRotateY:[T+m],eyesRotateX:[-3*C+.1],eyesRotateY:[-5*m],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(E))}}touchAt(n,e){if(!this.camera)return;const t=this.nodeAvatar.getBoundingClientRect(),i=new g.Vector2((n-t.left)/t.width*2-1,-((e-t.top)/t.height)*2+1),s=new g.Raycaster;s.setFromCamera(i,this.camera);const o=s.intersectObject(this.armature);if(o.length>0){const l=o[0].point,h=new g.Vector3,r=new g.Vector3;this.objectLeftArm.getWorldPosition(h),this.objectRightArm.getWorldPosition(r);const u=h.distanceToSquared(l),a=r.distanceToSquared(l);u<a?(this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3,maxAngle:.2},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},l,!1,1e3),this.setValue("handFistLeft",0)):(this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},l,!1,1e3),this.setValue("handFistRight",0))}else["LeftArm","LeftForeArm","LeftHand","RightArm","RightForeArm","RightHand"].forEach(l=>{let h=l+".quaternion";this.poseTarget.props[h].copy(this.getPoseTemplateProp(h)),this.poseTarget.props[h].t=this.animClock,this.poseTarget.props[h].d=1e3});return o.length>0}speakWithHands(n=0,e=.5){if(this.mixer||this.gesture||!this.poseTarget.template.standing||this.poseTarget.template.bend||Math.random()>e)return;this.ikSolve({root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-1,maxz:3}]},new g.Vector3(this.gaussianRandom(0,.5),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0),this.ikSolve({root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5},{link:"RightArm"}]},new g.Vector3(this.gaussianRandom(-.5,0),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0);const t=[],i=[];t.push(100+Math.round(Math.random()*500)),i.push({duration:1e3,props:{"LeftHand.quaternion":new g.Quaternion().setFromEuler(new g.Euler(0,-1-Math.random(),0)),"RightHand.quaternion":new g.Quaternion().setFromEuler(new g.Euler(0,1+Math.random(),0))}}),["LeftArm","LeftForeArm","RightArm","RightForeArm"].forEach(o=>{i[0].props[o+".quaternion"]=this.ikMesh.getObjectByName(o).quaternion.clone()}),t.push(1e3+Math.round(Math.random()*500)),i.push({duration:2e3,props:{}}),["LeftArm","LeftForeArm","RightArm","RightForeArm","LeftHand","RightHand"].forEach(o=>{i[1].props[o+".quaternion"]=null});const s=this.animFactory({name:"talkinghands",delay:n,dt:t,vs:{moveto:i}});this.animQueue.push(s)}getSlowdownRate(n){return this.animSlowdownRate}setSlowdownRate(n){this.animSlowdownRate=n,this.audioSpeechSource&&(this.audioSpeechSource.playbackRate.value=1/this.animSlowdownRate),this.audioBackgroundSource&&(this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate)}getAutoRotateSpeed(n){return this.controls?this.controls.autoRotateSpeed:0}setAutoRotateSpeed(n){this.controls&&(this.controls.autoRotateSpeed=n,this.controls.autoRotate=n>0)}start(){this.armature&&this.isRunning===!1&&(this.audioCtx.resume(),this.animTimeLast=performance.now(),this.isRunning=!0,this.isAvatarOnly||(this._raf=requestAnimationFrame(this.animate)))}stop(){this.isRunning=!1,this.audioCtx.suspend()}startListening(n,e={},t=null){this.listeningAnalyzer=n,this.listeningAnalyzer.fftSize=256,this.listeningAnalyzer.smoothingTimeConstant=.1,this.listeningAnalyzer.minDecibels=-70,this.listeningAnalyzer.maxDecibels=-10,this.listeningOnchange=t&&typeof t=="function"?t:null,this.listeningSilenceThresholdLevel=e?.hasOwnProperty("listeningSilenceThresholdLevel")?e.listeningSilenceThresholdLevel:this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=e?.hasOwnProperty("listeningSilenceThresholdMs")?e.listeningSilenceThresholdMs:this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=e?.hasOwnProperty("listeningSilenceDurationMax")?e.listeningSilenceDurationMax:this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=e?.hasOwnProperty("listeningActiveThresholdLevel")?e.listeningActiveThresholdLevel:this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=e?.hasOwnProperty("listeningActiveThresholdMs")?e.listeningActiveThresholdMs:this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=e?.hasOwnProperty("listeningActiveDurationMax")?e.listeningActiveDurationMax:this.opt.listeningActiveDurationMax,this.listeningActive=!1,this.listeningVolume=0,this.listeningTimer=0,this.listeningTimerTotal=0,this.isListening=!0}stopListening(){this.isListening=!1}async playAnimation(n,e=null,t=10,i=0,s=.01,o=!1){if(!this.armature)return;this.positionWasLocked=!o,o?console.log("Position locking disabled for FBX animation:",n):(this.lockAvatarPosition(),console.log("Position locked immediately before FBX animation:",n));let l=this.animClips.find(h=>h.url===n+"-"+i);if(l){let h=this.animQueue.find(a=>a.template.name==="pose");h&&(h.ts[0]=1/0),Object.entries(l.pose.props).forEach(a=>{this.poseBase.props[a[0]]=a[1].clone(),this.poseTarget.props[a[0]]=a[1].clone(),this.poseTarget.props[a[0]].t=0,this.poseTarget.props[a[0]].d=1e3}),this.mixer?console.log("Using existing mixer for FBX animation, preserving morph targets"):(this.mixer=new g.AnimationMixer(this.armature),console.log("Created new mixer for FBX animation")),this.mixer.addEventListener("finished",this.stopAnimation.bind(this),{once:!0});const r=Math.ceil(t/l.clip.duration),u=this.mixer.clipAction(l.clip);u.setLoop(g.LoopRepeat,r),u.clampWhenFinished=!0,this.currentFBXAction=u;try{u.fadeIn(.5).play(),console.log("FBX animation started successfully:",n)}catch(a){console.warn("FBX animation failed to start:",a),this.stopAnimation();return}if(u.getClip().tracks.length===0){console.warn("FBX animation has no valid tracks, stopping"),this.stopAnimation();return}}else{let r=await new Oe.FBXLoader().loadAsync(n,e);if(r&&r.animations&&r.animations[i]){let u=r.animations[i];const a=new Set;this.armature&&this.armature.traverse(C=>{(C.isBone||C.type==="Bone")&&a.add(C.name)});const d=new Map,p=C=>{if(a.has(C))return C;let m=C.replace(/^mixamorig/i,"").replace(/^CC_Base_/i,"").replace(/^RPM_/i,"");if(a.has(m))return m;const L=m.toLowerCase();if(L.includes("left")&&L.includes("arm")){if(L.includes("fore")||L.includes("lower")){if(a.has("LeftForeArm"))return"LeftForeArm";if(a.has("LeftForearm"))return"LeftForearm"}else if(!L.includes("fore")&&!L.includes("hand")&&a.has("LeftArm"))return"LeftArm"}if(L.includes("right")&&L.includes("arm")){if(L.includes("fore")||L.includes("lower")){if(a.has("RightForeArm"))return"RightForeArm";if(a.has("RightForearm"))return"RightForearm"}else if(!L.includes("fore")&&!L.includes("hand")&&a.has("RightArm"))return"RightArm"}if(L.includes("left")&&L.includes("hand")&&!L.includes("index")&&!L.includes("thumb")&&!L.includes("middle")&&!L.includes("ring")&&!L.includes("pinky")&&a.has("LeftHand"))return"LeftHand";if(L.includes("right")&&L.includes("hand")&&!L.includes("index")&&!L.includes("thumb")&&!L.includes("middle")&&!L.includes("ring")&&!L.includes("pinky")&&a.has("RightHand"))return"RightHand";if(L.includes("left")&&(L.includes("shoulder")||L.includes("clavicle"))&&a.has("LeftShoulder"))return"LeftShoulder";if(L.includes("right")&&(L.includes("shoulder")||L.includes("clavicle"))&&a.has("RightShoulder"))return"RightShoulder";const E={LeftArm:"LeftArm",leftArm:"LeftArm",LEFTARM:"LeftArm",RightArm:"RightArm",rightArm:"RightArm",RIGHTARM:"RightArm",LeftForeArm:"LeftForeArm",leftForeArm:"LeftForeArm",leftForearm:"LeftForeArm",LeftForearm:"LeftForeArm",RightForeArm:"RightForeArm",rightForeArm:"RightForeArm",rightForearm:"RightForeArm",RightForearm:"RightForeArm",LeftHand:"LeftHand",leftHand:"LeftHand",RightHand:"RightHand",rightHand:"RightHand",LeftShoulder:"LeftShoulder",leftShoulder:"LeftShoulder",RightShoulder:"RightShoulder",rightShoulder:"RightShoulder",Spine:"Spine1",spine:"Spine1",Spine1:"Spine1",Spine2:"Spine2",Head:"Head",head:"Head",Neck:"Neck",neck:"Neck",Hips:"Hips",hips:"Hips",Root:"Hips",root:"Hips"};if(E[m]){const R=E[m];if(a.has(R))return R}for(const R of a)if(R.toLowerCase()===L)return R;for(const R of a){const M=R.toLowerCase();if((L.includes("left")&&M.includes("left")||L.includes("right")&&M.includes("right"))&&(L.includes("arm")&&M.includes("arm")&&!M.includes("fore")||L.includes("forearm")&&M.includes("forearm")||L.includes("hand")&&M.includes("hand")&&!M.includes("index")&&!M.includes("thumb")||L.includes("shoulder")&&M.includes("shoulder")))return R}return null},y=[],A=new Set;u.tracks.forEach(C=>{const L=C.name.replaceAll("mixamorig","").split("."),E=L[0],R=L[1],M=p(E);if(M&&R){const k=`${M}.${R}`,ie=C.clone();ie.name=k,y.push(ie),E!==M&&d.set(E,M)}else A.add(E)}),A.size>0&&console.warn(`⚠️ ${A.size} bone(s) could not be mapped:`,Array.from(A).sort().join(", ")),y.length>0&&(u=new g.AnimationClip(u.name,u.duration,y),console.log(`✓ Created animation with ${y.length} mapped tracks (from ${u.tracks.length} original tracks)`),d.size>0&&console.log(`✓ Mapped ${d.size} bone(s):`,Array.from(d.entries()).map(([C,m])=>`${C}→${m}`).join(", ")));const v={};u.tracks.forEach(C=>{const m=C.name.split(".");if(m[1]==="position"){for(let L=0;L<C.values.length;L++)C.values[L]=C.values[L]*s;v[C.name]=new g.Vector3(C.values[0],C.values[1],C.values[2])}else m[1]==="quaternion"?v[C.name]=new g.Quaternion(C.values[0],C.values[1],C.values[2],C.values[3]):m[1]==="rotation"&&(v[m[0]+".quaternion"]=new g.Quaternion().setFromEuler(new g.Euler(C.values[0],C.values[1],C.values[2],"XYZ")).normalize())});const T={props:v};v["Hips.position"]&&(v["Hips.position"].y<.5?T.lying=!0:T.standing=!0),this.animClips.push({url:n+"-"+i,clip:u,pose:T}),this.playAnimation(n,e,t,i,s)}else{const u="Animation "+n+" (ndx="+i+") not found";console.error(u)}}}stopAnimation(){if(this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null),this.positionWasLocked?(this.unlockAvatarPosition(),console.log("Position unlocked after FBX animation stopped")):console.log("Position was not locked, no unlock needed"),this.gesture&&this.poseTarget&&this.poseTarget.props)for(let[n,e]of Object.entries(this.gesture))e.t=this.animClock,e.d=1e3,this.poseTarget.props.hasOwnProperty(n)&&(this.poseTarget.props[n].copy(e),this.poseTarget.props[n].t=this.animClock,this.poseTarget.props[n].d=1e3);if(this.animQueue){let n=this.animQueue.find(e=>e.template.name==="pose");n&&(n.ts[0]=this.animClock)}this.poseFactory&&this.setPoseFromTemplate(null)}async playPose(n,e=null,t=5,i=0,s=.01){if(!this.armature)return;let o=this.poseTemplates[n];if(!o){const l=this.animPoses.find(h=>h.url===n+"-"+i);l&&(o=l.pose)}if(o){this.poseName=n,this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null);let l=this.animQueue.find(h=>h.template.name==="pose");l&&(l.ts[0]=this.animClock+t*1e3+2e3),this.setPoseFromTemplate(o)}else{let h=await new Oe.FBXLoader().loadAsync(n,e);if(h&&h.animations&&h.animations[i]){let r=h.animations[i];const u={};r.tracks.forEach(d=>{d.name=d.name.replaceAll("mixamorig","");const p=d.name.split(".");p[1]==="position"?u[d.name]=new g.Vector3(d.values[0]*s,d.values[1]*s,d.values[2]*s):p[1]==="quaternion"?u[d.name]=new g.Quaternion(d.values[0],d.values[1],d.values[2],d.values[3]):p[1]==="rotation"&&(u[p[0]+".quaternion"]=new g.Quaternion().setFromEuler(new g.Euler(d.values[0],d.values[1],d.values[2],"XYZ")).normalize())});const a={props:u};u["Hips.position"]&&(u["Hips.position"].y<.5?a.lying=!0:a.standing=!0),this.animPoses.push({url:n+"-"+i,pose:a}),this.playPose(n,e,t,i,s)}else{const r="Pose "+n+" (ndx="+i+") not found";console.error(r)}}}stopPose(){this.stopAnimation()}playGesture(n,e=3,t=!1,i=1e3){if(!this.armature)return;let s=this.gestureTemplates[n];if(s){this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null);let l=this.animQueue.findIndex(h=>h.template.name==="talkinghands");l!==-1&&(this.animQueue[l].ts=this.animQueue[l].ts.map(h=>0)),this.gesture=this.propsToThreeObjects(s),t&&(this.gesture=this.mirrorPose(this.gesture)),n==="namaste"&&this.avatar.body==="M"&&(this.gesture["RightArm.quaternion"].rotateTowards(new g.Quaternion(0,1,0,0),-.25),this.gesture["LeftArm.quaternion"].rotateTowards(new g.Quaternion(0,1,0,0),-.25));for(let[h,r]of Object.entries(this.gesture))r.t=this.animClock,r.d=i,this.poseTarget.props.hasOwnProperty(h)&&(this.poseTarget.props[h].copy(r),this.poseTarget.props[h].t=this.animClock,this.poseTarget.props[h].d=i);e&&Number.isFinite(e)&&(this.gestureTimeout=setTimeout(this.stopGesture.bind(this,i),1e3*e))}let o=this.animEmojis[n];if(o&&(o&&o.link&&(o=this.animEmojis[o.link]),o)){this.lookAtCamera(500);const l=this.animFactory(o);if(l.gesture=!0,e&&Number.isFinite(e)){const h=l.ts[0],u=l.ts[l.ts.length-1]-h;if(e*1e3-u>0){const d=[];for(let A=1;A<l.ts.length;A++)d.push(l.ts[A]-l.ts[A-1]);const p=o.template?.rescale||d.map(A=>A/u),y=e*1e3-u;l.ts=l.ts.map((A,v,T)=>v===0?h:T[v-1]+d[v-1]+p[v-1]*y)}else{const d=e*1e3/u;l.ts=l.ts.map(p=>h+d*(p-h))}}this.animQueue.push(l)}}stopGesture(n=1e3){if(this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null),this.gesture){const t=Object.entries(this.gesture);this.gesture=null;for(const[i,s]of t)this.poseTarget.props.hasOwnProperty(i)&&(this.poseTarget.props[i].copy(this.getPoseTemplateProp(i)),this.poseTarget.props[i].t=this.animClock,this.poseTarget.props[i].d=n)}let e=this.animQueue.findIndex(t=>t.gesture);e!==-1&&this.animQueue.splice(e,1)}ikSolve(n,e=null,t=!1,i=null){const s=new g.Vector3,o=new g.Vector3,l=new g.Vector3,h=new g.Vector3,r=new g.Quaternion,u=new g.Vector3,a=new g.Vector3,d=new g.Vector3,p=this.ikMesh.getObjectByName(n.root);p.position.setFromMatrixPosition(this.armature.getObjectByName(n.root).matrixWorld),p.quaternion.setFromRotationMatrix(this.armature.getObjectByName(n.root).matrixWorld),e&&t&&e.applyQuaternion(this.armature.quaternion).add(p.position);const y=this.ikMesh.getObjectByName(n.effector),A=n.links;A.forEach(T=>{T.bone=this.ikMesh.getObjectByName(T.link),T.bone.quaternion.copy(this.getPoseTemplateProp(T.link+".quaternion"))}),p.updateMatrixWorld(!0);const v=n.iterations||10;if(e)for(let T=0;T<v;T++){let C=!1;for(let m=0,L=A.length;m<L;m++){const E=A[m].bone;E.matrixWorld.decompose(h,r,u),r.invert(),o.setFromMatrixPosition(y.matrixWorld),l.subVectors(o,h),l.applyQuaternion(r),l.normalize(),s.subVectors(e,h),s.applyQuaternion(r),s.normalize();let R=s.dot(l);R>1?R=1:R<-1&&(R=-1),R=Math.acos(R),!(R<1e-5)&&(A[m].minAngle!==void 0&&R<A[m].minAngle&&(R=A[m].minAngle),A[m].maxAngle!==void 0&&R>A[m].maxAngle&&(R=A[m].maxAngle),a.crossVectors(l,s),a.normalize(),_.setFromAxisAngle(a,R),E.quaternion.multiply(_),E.rotation.setFromVector3(d.setFromEuler(E.rotation).clamp(new g.Vector3(A[m].minx!==void 0?A[m].minx:-1/0,A[m].miny!==void 0?A[m].miny:-1/0,A[m].minz!==void 0?A[m].minz:-1/0),new g.Vector3(A[m].maxx!==void 0?A[m].maxx:1/0,A[m].maxy!==void 0?A[m].maxy:1/0,A[m].maxz!==void 0?A[m].maxz:1/0))),E.updateMatrixWorld(!0),C=!0)}if(!C)break}i&&A.forEach(T=>{this.poseTarget.props[T.link+".quaternion"].copy(T.bone.quaternion),this.poseTarget.props[T.link+".quaternion"].t=this.animClock,this.poseTarget.props[T.link+".quaternion"].d=i})}async initializeFBXAnimationLoader(){try{const{FBXAnimationLoader:n}=await Promise.resolve().then(()=>require("./fbxAnimationLoader-CNrfhJRz.cjs"));this.fbxAnimationLoader=new n(this.armature),console.log("FBX Animation Loader initialized")}catch(n){console.warn("FBX Animation Loader not available:",n),this.fbxAnimationLoader=null}}setBodyMovement(n){this.bodyMovement=n,this.avatar&&(this.avatar.bodyMovement=n),console.log("Body movement set to:",n),n==="idle"&&this.unlockAvatarPosition(),this.applyBodyMovementAnimation()}async applyBodyMovementAnimation(){if(!this.armature||!this.animQueue){console.log("Avatar not ready for body movement animations");return}console.log("Avatar is running:",this.isRunning),console.log("Animation queue exists:",!!this.animQueue);const n=this.animQueue.length;this.animQueue=this.animQueue.filter(i=>!i.template.name.startsWith("bodyMovement"));const e=this.animQueue.length;if(console.log(`Filtered animation queue: ${n} -> ${e} animations`),this.bodyMovement==="idle"){this.fbxAnimationLoader&&this.fbxAnimationLoader.stopCurrentAnimation();return}if(this.fbxAnimationLoader)try{await this.fbxAnimationLoader.playGestureAnimation(this.bodyMovement,this.movementIntensity),console.log("Applied FBX body movement animation:",this.bodyMovement);return}catch(i){console.warn("FBX animation failed, falling back to code animation:",i)}const t=this.createBodyMovementAnimation(this.bodyMovement);if(console.log("Created movement animation:",t),t)try{const i=this.animFactory(t,!0);i&&i.ts&&i.ts.length>0?(this.animQueue.push(i),console.log("Applied code-based body movement animation:",this.bodyMovement),console.log("Animation queue length:",this.animQueue.length),console.log("Animation object:",i)):(console.error("Invalid animation object created for:",this.bodyMovement),console.error("Animation object:",i))}catch(i){console.error("Error creating body movement animation:",i)}}lockAvatarPosition(){if(!this.armature){console.warn("Cannot lock position: armature not available");return}this.originalPosition||(this.originalPosition={x:this.armature.position.x,y:this.armature.position.y,z:this.armature.position.z},console.log("Original position stored:",this.originalPosition)),this.lockedPosition={x:this.armature.position.x,y:this.armature.position.y,z:this.armature.position.z},console.log("Avatar position locked at current position:",this.lockedPosition)}unlockAvatarPosition(){this.armature&&this.originalPosition?(this.armature.position.set(this.originalPosition.x,this.originalPosition.y,this.originalPosition.z),console.log("Avatar position restored to original:",this.originalPosition)):this.armature&&(this.armature.position.set(0,0,0),console.log("Avatar position reset to center (0,0,0)")),this.lockedPosition=null,this.originalPosition=null,console.log("Avatar position unlocked")}maintainLockedPosition(){this.lockedPosition&&this.armature&&this.armature.position.set(this.lockedPosition.x,this.lockedPosition.y,this.lockedPosition.z)}createBodyMovementAnimation(n){const e=this.movementIntensity||.5,t={walking:{name:"bodyMovement_walking",delay:[500,2e3],dt:[800,1200],vs:{bodyRotateY:[-.1*e,.1*e,0],bodyRotateZ:[-.05*e,.05*e,0],bodyRotateX:[-.02*e,.02*e,0]}},prancing:{name:"bodyMovement_prancing",delay:[300,1e3],dt:[400,800],vs:{bodyRotateY:[-.15*e,.15*e,0],bodyRotateZ:[-.08*e,.08*e,0],bodyRotateX:[-.05*e,.05*e,0]}},gesturing:{name:"bodyMovement_gesturing",delay:[400,1500],dt:[600,1e3],vs:{bodyRotateY:[-.08*e,.08*e,0],bodyRotateZ:[-.03*e,.03*e,0]}},dancing:{name:"bodyMovement_dancing",delay:[200,600],dt:[400,800],vs:{bodyRotateY:[-.25*e,.25*e,0],bodyRotateZ:[-.15*e,.15*e,0],bodyRotateX:[-.1*e,.1*e,0]}},dancing2:{name:"bodyMovement_dancing2",delay:[150,500],dt:[300,700],vs:{bodyRotateY:[-.3*e,.3*e,0],bodyRotateZ:[-.2*e,.2*e,0],bodyRotateX:[-.12*e,.12*e,0]}},dancing3:{name:"bodyMovement_dancing3",delay:[100,400],dt:[200,600],vs:{bodyRotateY:[-.35*e,.35*e,0],bodyRotateZ:[-.25*e,.25*e,0],bodyRotateX:[-.15*e,.15*e,0]}},excited:{name:"bodyMovement_excited",delay:[200,600],dt:[300,700],vs:{bodyRotateY:[-.12*e,.12*e,0],bodyRotateZ:[-.06*e,.06*e,0],bodyRotateX:[-.04*e,.04*e,0]}},happy:{name:"bodyMovement_happy",delay:[300,800],dt:[500,1e3],vs:{bodyRotateY:[-.08*e,.08*e,0],bodyRotateZ:[-.04*e,.04*e,0],bodyRotateX:[-.02*e,.02*e,0]}},surprised:{name:"bodyMovement_surprised",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.05*e,.05*e,0],bodyRotateZ:[-.03*e,.03*e,0],bodyRotateX:[-.01*e,.01*e,0]}},thinking:{name:"bodyMovement_thinking",delay:[800,2e3],dt:[1e3,1500],vs:{bodyRotateY:[-.06*e,.06*e,0],bodyRotateZ:[-.03*e,.03*e,0],bodyRotateX:[-.02*e,.02*e,0]}},nodding:{name:"bodyMovement_nodding",delay:[400,800],dt:[300,600],vs:{bodyRotateX:[-.1*e,.1*e,0],bodyRotateY:[-.02*e,.02*e,0]}},shaking:{name:"bodyMovement_shaking",delay:[200,400],dt:[150,300],vs:{bodyRotateY:[-.15*e,.15*e,0],bodyRotateZ:[-.05*e,.05*e,0]}},celebration:{name:"bodyMovement_celebration",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.2*e,.2*e,0],bodyRotateZ:[-.1*e,.1*e,0],bodyRotateX:[-.08*e,.08*e,0]}},energetic:{name:"bodyMovement_energetic",delay:[150,400],dt:[250,500],vs:{bodyRotateY:[-.18*e,.18*e,0],bodyRotateZ:[-.12*e,.12*e,0],bodyRotateX:[-.08*e,.08*e,0]}},swaying:{name:"bodyMovement_swaying",delay:[600,1200],dt:[800,1e3],vs:{bodyRotateY:[-.1*e,.1*e,0],bodyRotateZ:[-.05*e,.05*e,0]}},bouncing:{name:"bodyMovement_bouncing",delay:[300,600],dt:[400,700],vs:{bodyRotateY:[-.05*e,.05*e,0]}}};if(n==="dancing"){const i=["dancing","dancing2","dancing3"],s=i[Math.floor(Math.random()*i.length)];return t[s]||t.dancing}return t[n]||null}setMovementIntensity(n){this.movementIntensity=Math.max(0,Math.min(1,n)),this.avatar&&(this.avatar.movementIntensity=this.movementIntensity),console.log("Movement intensity set to:",this.movementIntensity),this.fbxAnimationLoader&&this.fbxAnimationLoader.setIntensity(this.movementIntensity),this.bodyMovement&&this.bodyMovement!=="idle"&&this.applyBodyMovementAnimation()}dispose(){this.stop(),this.stopSpeaking(),this.streamStop(),this.stopAnimation(),this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null),["audioSpeechSource","audioBackgroundSource"].forEach(n=>{const e=this[n];if(e){try{e.stop?.()}catch{}e.disconnect(),e.onended=null}}),["audioBackgroundGainNode","audioSpeechGainNode","audioStreamGainNode","audioAnalyzerNode"].forEach(n=>{const e=this[n];e&&e.disconnect()}),this.isAvatarOnly?this.armature&&(this.armature.parent&&this.armature.parent.remove(this.armature),this.clearThree(this.armature)):(this.clearThree(this.scene),this.resizeobserver.disconnect(),this.resizeobserver=null,this.renderer&&(this.renderer.dispose(),this.renderer.getContext().getExtension("WEBGL_lose_context")?.loseContext(),this.renderer.domElement?.remove(),this.renderer.domElement=null,this.renderer=null),this.controls&&(this.controls.dispose(),this.controls=null)),this.clearThree(this.ikMesh),this.dynamicbones.dispose(),this.fbxAnimationLoader&&(this.fbxAnimationLoader.stopCurrentAnimation(),this.fbxAnimationLoader=null),this.nodeAvatar=null}}const be={apiKey:"sk_ace57ef3ef65a92b9d3bee2a00183b78ca790bc3e10964f2",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",defaultVoice:"21m00Tcm4TlvDq8ikWAM",voices:{rachel:"21m00Tcm4TlvDq8ikWAM",drew:"29vD33N1CtxCmqQRPOHJ",bella:"EXAVITQu4vr4xnSDxMaL",antoni:"ErXwobaYiN019PkySvjV",elli:"MF3mGyEYCl7XYWbV9V6O",josh:"VR6AewLTigWG4xSOukaG"}},ze={defaultVoice:"aura-2-thalia-en",voices:{thalia:"aura-2-thalia-en",asteria:"aura-2-asteria-en",orion:"aura-2-orion-en",stella:"aura-2-stella-en",athena:"aura-2-athena-en",hera:"aura-2-hera-en",zeus:"aura-2-zeus-en"}};function Se(){return{service:"elevenlabs",endpoint:be.endpoint,apiKey:be.apiKey,defaultVoice:be.defaultVoice,voices:be.voices}}function dt(){const B=Se(),n=[];return Object.entries(B.voices).forEach(([e,t])=>{n.push({value:t,label:`${e.charAt(0).toUpperCase()+e.slice(1)} (${B.service})`})}),n}const Ee=x.forwardRef(({avatarUrl:B="/avatars/brunette.glb",avatarBody:n="F",mood:e="neutral",ttsLang:t="en",ttsService:i=null,ttsVoice:s=null,ttsApiKey:o=null,bodyMovement:l="idle",movementIntensity:h=.5,showFullAvatar:r=!0,cameraView:u="upper",onReady:a=()=>{},onLoading:d=()=>{},onError:p=()=>{},className:y="",style:A={},animations:v={}},T)=>{const C=x.useRef(null),m=x.useRef(null),L=x.useRef(r),E=x.useRef(null),R=x.useRef(null),M=x.useRef(!1),k=x.useRef({remainingText:null,originalText:null,options:null}),ie=x.useRef([]),ue=x.useRef(0),[w,D]=x.useState(!0),[X,j]=x.useState(null),[te,ae]=x.useState(!1),[me,ce]=x.useState(!1);x.useEffect(()=>{M.current=me},[me]),x.useEffect(()=>{L.current=r},[r]);const K=Se(),ye=i||K.service;let V;ye==="browser"?V={service:"browser",endpoint:"",apiKey:null,defaultVoice:"Google US English"}:ye==="elevenlabs"?V={service:"elevenlabs",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",apiKey:o||K.apiKey,defaultVoice:s||K.defaultVoice||be.defaultVoice,voices:K.voices||be.voices}:ye==="deepgram"?V={service:"deepgram",endpoint:"https://api.deepgram.com/v1/speak",apiKey:o||K.apiKey,defaultVoice:s||K.defaultVoice||ze.defaultVoice,voices:K.voices||ze.voices}:V={...K,apiKey:o!==null?o:K.apiKey};const f={url:B,body:n,avatarMood:e,ttsLang:ye==="browser"?"en-US":t,ttsVoice:s||V.defaultVoice,lipsyncLang:"en",showFullAvatar:r,bodyMovement:l,movementIntensity:h},b={ttsEndpoint:V.endpoint,ttsApikey:V.apiKey,ttsService:ye,lipsyncModules:["en"],cameraView:u},P=x.useCallback(async()=>{if(!(!C.current||m.current))try{if(D(!0),j(null),m.current=new Me(C.current,b),m.current.controls&&(m.current.controls.enableRotate=!1,m.current.controls.enableZoom=!1,m.current.controls.enablePan=!1,m.current.controls.enableDamping=!1),v&&Object.keys(v).length>0&&(m.current.customAnimations=v),await m.current.showAvatar(f,Q=>{if(Q.lengthComputable){const $=Math.min(100,Math.round(Q.loaded/Q.total*100));d($)}}),await new Promise(Q=>{const $=()=>{m.current.lipsync&&Object.keys(m.current.lipsync).length>0?Q():setTimeout($,100)};$()}),m.current&&m.current.setShowFullAvatar)try{m.current.setShowFullAvatar(r)}catch(Q){console.warn("Error setting full body mode on initialization:",Q)}m.current&&m.current.controls&&(m.current.controls.enableRotate=!1,m.current.controls.enableZoom=!1,m.current.controls.enablePan=!1,m.current.controls.enableDamping=!1,m.current.controls.update()),D(!1),ae(!0),a(m.current);const U=()=>{document.visibilityState==="visible"?m.current?.start():m.current?.stop()};return document.addEventListener("visibilitychange",U),()=>{document.removeEventListener("visibilitychange",U)}}catch(S){console.error("Error initializing TalkingHead:",S),j(S.message||"Failed to initialize avatar"),D(!1),p(S)}},[B,n,e,t,i,s,o,r,l,h,u]);x.useEffect(()=>(P(),()=>{m.current&&(m.current.stop(),m.current.dispose(),m.current=null)}),[P]),x.useEffect(()=>{if(!C.current||!m.current)return;const S=new ResizeObserver(Q=>{for(const $ of Q)m.current&&m.current.onResize&&m.current.onResize()});S.observe(C.current);const U=()=>{m.current&&m.current.onResize&&m.current.onResize()};return window.addEventListener("resize",U),()=>{S.disconnect(),window.removeEventListener("resize",U)}},[te]);const O=x.useCallback(async()=>{if(m.current&&m.current.audioCtx)try{(m.current.audioCtx.state==="suspended"||m.current.audioCtx.state==="interrupted")&&(await m.current.audioCtx.resume(),console.log("Audio context resumed"))}catch(S){console.warn("Failed to resume audio context:",S)}},[]),N=x.useCallback(async(S,U={})=>{if(m.current&&te)try{R.current&&(clearInterval(R.current),R.current=null),E.current={text:S,options:U},k.current={remainingText:null,originalText:null,options:null};const Q=/[!\.\?\n\p{Extended_Pictographic}]/ug,$=S.split(Q).map(I=>I.trim()).filter(I=>I.length>0);ie.current=$,ue.current=0,ce(!1),M.current=!1,await O();const de={...U,lipsyncLang:U.lipsyncLang||f.lipsyncLang||"en"};if(U.onSpeechEnd&&m.current){const I=m.current;let H=null,W=0;const q=1200;let ee=!1;H=setInterval(()=>{if(W++,M.current)return;if(W>q){if(H&&(clearInterval(H),H=null,R.current=null),!ee&&!M.current){ee=!0;try{U.onSpeechEnd()}catch(Pe){console.error("Error in onSpeechEnd callback (timeout):",Pe)}}return}const ne=!I.speechQueue||I.speechQueue.length===0,ve=!I.audioPlaylist||I.audioPlaylist.length===0;I&&I.isSpeaking===!1&&ne&&ve&&I.isAudioPlaying===!1&&!ee&&!M.current&&setTimeout(()=>{if(I&&!M.current&&I.isSpeaking===!1&&(!I.speechQueue||I.speechQueue.length===0)&&(!I.audioPlaylist||I.audioPlaylist.length===0)&&I.isAudioPlaying===!1&&!ee&&!M.current){ee=!0,H&&(clearInterval(H),H=null,R.current=null);try{U.onSpeechEnd()}catch(Ge){console.error("Error in onSpeechEnd callback:",Ge)}}},100)},100),R.current=H}m.current.lipsync&&Object.keys(m.current.lipsync).length>0?(m.current.setSlowdownRate&&m.current.setSlowdownRate(1.05),m.current.speakText(S,de)):setTimeout(async()=>{await O(),m.current&&m.current.lipsync&&(m.current.setSlowdownRate&&m.current.setSlowdownRate(1.05),m.current.speakText(S,de))},100)}catch(Q){console.error("Error speaking text:",Q),j(Q.message||"Failed to speak text")}},[te,O,f.lipsyncLang]),J=x.useCallback(()=>{m.current&&(m.current.stopSpeaking(),m.current.setSlowdownRate&&m.current.setSlowdownRate(1),E.current=null,ce(!1))},[]),Z=x.useCallback(()=>{if(m.current&&m.current.pauseSpeaking){const S=m.current;if(S.isSpeaking||S.audioPlaylist&&S.audioPlaylist.length>0||S.speechQueue&&S.speechQueue.length>0){R.current&&(clearInterval(R.current),R.current=null);let Q="";if(E.current&&ie.current.length>0){const $=ie.current.length,de=S.speechQueue?S.speechQueue.filter(q=>q&&q.text&&Array.isArray(q.text)&&q.text.length>0).length:0,I=S.audioPlaylist&&S.audioPlaylist.length>0,H=de+(I?1:0),W=$-H;if(H>0&&W<$&&(Q=ie.current.slice(W).join(". ").trim(),!Q&&de>0&&S.speechQueue)){const ee=S.speechQueue.filter(ne=>ne&&ne.text&&Array.isArray(ne.text)&&ne.text.length>0).map(ne=>ne.text.map(ve=>ve.word||"").filter(ve=>ve.length>0).join(" ")).filter(ne=>ne.length>0).join(" ");ee&&ee.trim()&&(Q=ee.trim())}}E.current&&(k.current={remainingText:Q||null,originalText:E.current.text,options:E.current.options}),S.speechQueue&&(S.speechQueue.length=0),m.current.pauseSpeaking(),M.current=!0,ce(!0)}}},[]),Y=x.useCallback(async()=>{if(!m.current||!me)return;let S="",U={};if(k.current&&k.current.remainingText)S=k.current.remainingText,U=k.current.options||{},k.current={remainingText:null,originalText:null,options:null};else if(E.current&&E.current.text)S=E.current.text,U=E.current.options||{};else{console.warn("Resume called but no paused speech found"),ce(!1),M.current=!1;return}ce(!1),M.current=!1,await O();const Q={...U,lipsyncLang:U.lipsyncLang||f.lipsyncLang||"en"};try{await N(S,Q)}catch($){console.error("Error resuming speech:",$),ce(!1),M.current=!1}},[O,me,N,f]),Re=x.useCallback(S=>{m.current&&m.current.setMood(S)},[]),Ae=x.useCallback(S=>{m.current&&m.current.setSlowdownRate&&m.current.setSlowdownRate(S)},[]),Ie=x.useCallback((S,U=!1)=>{if(m.current&&m.current.playAnimation){if(v&&v[S]&&(S=v[S]),m.current.setShowFullAvatar)try{m.current.setShowFullAvatar(L.current)}catch($){console.warn("Error setting full body mode:",$)}if(S.includes("."))try{m.current.playAnimation(S,null,10,0,.01,U)}catch($){console.warn(`Failed to play ${S}:`,$);try{m.current.setBodyMovement("idle")}catch(de){console.warn("Fallback animation also failed:",de)}}else{const $=[".fbx",".glb",".gltf"];let de=!1;for(const I of $)try{m.current.playAnimation(S+I,null,10,0,.01,U),de=!0;break}catch{}if(!de){console.warn("Animation not found:",S);try{m.current.setBodyMovement("idle")}catch(I){console.warn("Fallback animation also failed:",I)}}}}},[v]),Le=x.useCallback(()=>{m.current&&m.current.onResize&&m.current.onResize()},[]);return x.useImperativeHandle(T,()=>({speakText:N,stopSpeaking:J,pauseSpeaking:Z,resumeSpeaking:Y,resumeAudioContext:O,setMood:Re,setTimingAdjustment:Ae,playAnimation:Ie,isReady:te,isPaused:me,talkingHead:m.current,handleResize:Le,setBodyMovement:S=>{if(m.current&&m.current.setShowFullAvatar&&m.current.setBodyMovement)try{m.current.setShowFullAvatar(L.current),m.current.setBodyMovement(S)}catch(U){console.warn("Error setting body movement:",U)}},setMovementIntensity:S=>m.current?.setMovementIntensity(S),playRandomDance:()=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playRandomDance)try{m.current.setShowFullAvatar(L.current),m.current.playRandomDance()}catch(S){console.warn("Error playing random dance:",S)}},playReaction:S=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playReaction)try{m.current.setShowFullAvatar(L.current),m.current.playReaction(S)}catch(U){console.warn("Error playing reaction:",U)}},playCelebration:()=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playCelebration)try{m.current.setShowFullAvatar(L.current),m.current.playCelebration()}catch(S){console.warn("Error playing celebration:",S)}},setShowFullAvatar:S=>{if(m.current&&m.current.setShowFullAvatar)try{L.current=S,m.current.setShowFullAvatar(S)}catch(U){console.warn("Error setting showFullAvatar:",U)}},lockAvatarPosition:()=>{if(m.current&&m.current.lockAvatarPosition)try{m.current.lockAvatarPosition()}catch(S){console.warn("Error locking avatar position:",S)}},unlockAvatarPosition:()=>{if(m.current&&m.current.unlockAvatarPosition)try{m.current.unlockAvatarPosition()}catch(S){console.warn("Error unlocking avatar position:",S)}}})),le.jsxs("div",{className:`talking-head-avatar ${y}`,style:{width:"100%",height:"100%",position:"relative",...A},children:[le.jsx("div",{ref:C,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),w&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),X&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:X})]})});Ee.displayName="TalkingHeadAvatar";const Ue=x.forwardRef(({text:B="Hello! I'm a talking avatar. How are you today?",onLoading:n=()=>{},onError:e=()=>{},onReady:t=()=>{},className:i="",style:s={},avatarConfig:o={}},l)=>{const h=x.useRef(null),r=x.useRef(null),[u,a]=x.useState(!0),[d,p]=x.useState(null),[y,A]=x.useState(!1),v=Se(),T=o.ttsService||v.service,C=T==="browser"?{endpoint:"",apiKey:null,defaultVoice:"Google US English"}:{...v,apiKey:o.ttsApiKey!==void 0&&o.ttsApiKey!==null?o.ttsApiKey:v.apiKey,endpoint:T==="elevenlabs"&&o.ttsApiKey?"https://api.elevenlabs.io/v1/text-to-speech":v.endpoint},m={url:"/avatars/brunette.glb",body:"F",avatarMood:"neutral",ttsLang:T==="browser"?"en-US":"en",ttsVoice:o.ttsVoice||C.defaultVoice,lipsyncLang:"en",showFullAvatar:!0,bodyMovement:"idle",movementIntensity:.5,...o},L={ttsEndpoint:C.endpoint,ttsApikey:C.apiKey,ttsService:T,lipsyncModules:["en"],cameraView:"upper"},E=x.useCallback(async()=>{if(!(!h.current||r.current))try{if(a(!0),p(null),r.current=new Me(h.current,L),await r.current.showAvatar(m,X=>{if(X.lengthComputable){const j=Math.min(100,Math.round(X.loaded/X.total*100));n(j)}}),r.current.morphs&&r.current.morphs.length>0){const X=r.current.morphs[0].morphTargetDictionary;console.log("Available morph targets:",Object.keys(X));const j=Object.keys(X).filter(te=>te.startsWith("viseme_"));console.log("Viseme morph targets found:",j),j.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"))}if(await new Promise(X=>{const j=()=>{r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),X()):(console.log("Waiting for lip-sync modules to load..."),setTimeout(j,100))};j()}),r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0),console.log("Avatar initialized in full body mode")}catch(X){console.warn("Error setting full body mode on initialization:",X)}a(!1),A(!0),t(r.current);const D=()=>{document.visibilityState==="visible"?r.current?.start():r.current?.stop()};return document.addEventListener("visibilitychange",D),()=>{document.removeEventListener("visibilitychange",D)}}catch(w){console.error("Error initializing TalkingHead:",w),p(w.message||"Failed to initialize avatar"),a(!1),e(w)}},[]);x.useEffect(()=>(E(),()=>{r.current&&(r.current.stop(),r.current.dispose(),r.current=null)}),[E]);const R=x.useCallback(w=>{if(r.current&&y)try{console.log("Speaking text:",w),console.log("Avatar config:",m),console.log("TalkingHead instance:",r.current),r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(w)):(console.warn("Lip-sync modules not ready, waiting..."),setTimeout(()=>{r.current&&r.current.lipsync?(console.log("Lip-sync now ready, speaking..."),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(w)):console.error("Lip-sync still not ready after waiting")},500))}catch(D){console.error("Error speaking text:",D),p(D.message||"Failed to speak text")}else console.warn("Avatar not ready for speaking. isReady:",y,"talkingHeadRef:",!!r.current)},[y,m]),M=x.useCallback(()=>{r.current&&(r.current.stopSpeaking(),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1),console.log("Reset timing to normal")))},[]),k=x.useCallback(w=>{r.current&&r.current.setMood(w)},[]),ie=x.useCallback(w=>{r.current&&r.current.setSlowdownRate&&(r.current.setSlowdownRate(w),console.log("Timing adjustment set to:",w))},[]),ue=x.useCallback((w,D=!1)=>{if(r.current&&r.current.playAnimation){if(r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0)}catch(j){console.warn("Error setting full body mode:",j)}if(w.includes("."))try{r.current.playAnimation(w,null,10,0,.01,D),console.log("Playing animation:",w)}catch(j){console.log(`Failed to play ${w}:`,j);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(te){console.warn("Fallback animation also failed:",te)}}else{const j=[".fbx",".glb",".gltf"];let te=!1;for(const ae of j)try{r.current.playAnimation(w+ae,null,10,0,.01,D),console.log("Playing animation:",w+ae),te=!0;break}catch{console.log(`Failed to play ${w}${ae}, trying next format...`)}if(!te){console.warn("Animation system not available or animation not found:",w);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(ae){console.warn("Fallback animation also failed:",ae)}}}}else console.warn("Animation system not available or animation not found:",w)},[]);return x.useImperativeHandle(l,()=>({speakText:R,stopSpeaking:M,setMood:k,setTimingAdjustment:ie,playAnimation:ue,isReady:y,talkingHead:r.current,setBodyMovement:w=>{if(r.current&&r.current.setShowFullAvatar&&r.current.setBodyMovement)try{r.current.setShowFullAvatar(!0),r.current.setBodyMovement(w),console.log("Body movement set with full body mode:",w)}catch(D){console.warn("Error setting body movement:",D)}},setMovementIntensity:w=>r.current?.setMovementIntensity(w),playRandomDance:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playRandomDance)try{r.current.setShowFullAvatar(!0),r.current.playRandomDance(),console.log("Random dance played with full body mode")}catch(w){console.warn("Error playing random dance:",w)}},playReaction:w=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playReaction)try{r.current.setShowFullAvatar(!0),r.current.playReaction(w),console.log("Reaction played with full body mode:",w)}catch(D){console.warn("Error playing reaction:",D)}},playCelebration:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playCelebration)try{r.current.setShowFullAvatar(!0),r.current.playCelebration(),console.log("Celebration played with full body mode")}catch(w){console.warn("Error playing celebration:",w)}},setShowFullAvatar:w=>{if(r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(w),console.log("Show full avatar set to:",w)}catch(D){console.warn("Error setting showFullAvatar:",D)}},lockAvatarPosition:()=>{if(r.current&&r.current.lockAvatarPosition)try{r.current.lockAvatarPosition()}catch(w){console.warn("Error locking avatar position:",w)}},unlockAvatarPosition:()=>{if(r.current&&r.current.unlockAvatarPosition)try{r.current.unlockAvatarPosition()}catch(w){console.warn("Error unlocking avatar position:",w)}}})),le.jsxs("div",{className:`talking-head-container ${i}`,style:s,children:[le.jsx("div",{ref:h,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),u&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),d&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:d})]})});Ue.displayName="TalkingHeadComponent";async function mt(B){try{console.log(`📥 Loading animation manifest from: ${B}`);const n=await fetch(B);if(!n.ok)throw new Error(`Failed to fetch manifest: ${n.status} ${n.statusText}`);const e=await n.json();console.log("📦 Raw manifest loaded:",e);const t=e.animations||{};return console.log("✅ Processed animations object:",t),t._genderSpecific&&console.log("👥 Gender-specific structure detected:",{male:Object.keys(t._genderSpecific.male||{}),female:Object.keys(t._genderSpecific.female||{}),shared:Object.keys(t._genderSpecific.shared||{})}),t}catch(n){return console.error("❌ Failed to load animation manifest:",n),{}}}const De=x.forwardRef(({text:B=null,avatarUrl:n="/avatars/brunette.glb",avatarBody:e="F",mood:t="neutral",ttsLang:i="en",ttsService:s=null,ttsVoice:o=null,ttsApiKey:l=null,bodyMovement:h="idle",movementIntensity:r=.5,showFullAvatar:u=!1,cameraView:a="upper",onReady:d=()=>{},onLoading:p=()=>{},onError:y=()=>{},onSpeechEnd:A=()=>{},className:v="",style:T={},animations:C={},autoAnimationGroup:m=null,autoIdleGroup:L=null,autoSpeak:E=!1},R)=>{const M=x.useRef(null),k=x.useRef(null),ie=x.useRef(u),ue=x.useRef(null),w=x.useRef(null),D=x.useRef(!1),X=x.useRef({remainingText:null,originalText:null,options:null}),j=x.useRef([]),[te,ae]=x.useState(!0),[me,ce]=x.useState(null),[K,ye]=x.useState(!1),[V,f]=x.useState(!1),[b,P]=x.useState(C),O=x.useRef(null);x.useEffect(()=>{D.current=V},[V]),x.useEffect(()=>{(async()=>{if(C.manifest)try{console.log("🔄 Loading animations from manifest:",C.manifest);const H=await mt(C.manifest);P(H),console.log("✅ Animations loaded and set:",H),H._genderSpecific?console.log("👥 Gender-specific animations detected:",{male:Object.keys(H._genderSpecific.male||{}),female:Object.keys(H._genderSpecific.female||{}),shared:Object.keys(H._genderSpecific.shared||{})}):console.log("⚠️ No gender-specific animations found in manifest")}catch(H){console.error("❌ Failed to load animation manifest:",H),P(C)}else console.log("📝 Using animations from props (no manifest):",C),P(C)})()},[C]),x.useEffect(()=>{ie.current=u},[u]);const N=Se(),J=s||N.service;let Z;J==="browser"?Z={service:"browser",endpoint:"",apiKey:null,defaultVoice:"Google US English"}:J==="elevenlabs"?Z={service:"elevenlabs",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",apiKey:l||N.apiKey,defaultVoice:o||N.defaultVoice||be.defaultVoice,voices:N.voices||be.voices}:J==="deepgram"?Z={service:"deepgram",endpoint:"https://api.deepgram.com/v1/speak",apiKey:l||N.apiKey,defaultVoice:o||N.defaultVoice||ze.defaultVoice,voices:N.voices||ze.voices}:Z={...N,apiKey:l!==null?l:N.apiKey};const Y={url:n,body:e,avatarMood:t,ttsLang:J==="browser"?"en-US":i,ttsVoice:o||Z.defaultVoice,lipsyncLang:"en",showFullAvatar:u,bodyMovement:h,movementIntensity:r},Re={ttsEndpoint:Z.endpoint,ttsApikey:Z.apiKey,ttsService:J,lipsyncModules:["en"],cameraView:a},Ae=x.useCallback(async()=>{if(!(!M.current||k.current))try{ae(!0),ce(null),k.current=new Me(M.current,Re),console.log("Avatar config being passed:",{url:Y.url,body:Y.body,avatarMood:Y.avatarMood}),await k.current.showAvatar(Y,H=>{if(H.lengthComputable){const W=Math.min(100,Math.round(H.loaded/H.total*100));p(W)}}),k.current?.avatar&&console.log("Avatar body after initialization:",k.current.avatar.body),ae(!1),ye(!0),d(k.current);const I=()=>{document.visibilityState==="visible"?k.current?.start():k.current?.stop()};return document.addEventListener("visibilitychange",I),()=>{document.removeEventListener("visibilitychange",I)}}catch(I){console.error("Error initializing TalkingHead:",I),ce(I.message||"Failed to initialize avatar"),ae(!1),y(I)}},[]);x.useEffect(()=>(Ae(),()=>{k.current&&(k.current.stop(),k.current.dispose(),k.current=null)}),[Ae]);const Ie=x.useCallback(async()=>{if(k.current)try{const I=k.current.audioCtx||k.current.audioContext;I&&(I.state==="suspended"||I.state==="interrupted")&&(await I.resume(),console.log("Audio context resumed"))}catch(I){console.warn("Failed to resume audio context:",I)}},[]),Le=x.useCallback(I=>{if(!b)return console.warn("No animations loaded"),null;let H=null;if(b._genderSpecific){const q=(e?.toUpperCase()||"F")==="M"?"male":"female",ee=b._genderSpecific[q];ee&&ee[I]?(H=ee[I],console.log(`Using ${q} animations for "${I}":`,H)):b._genderSpecific.shared&&b._genderSpecific.shared[I]&&(H=b._genderSpecific.shared[I],console.log(`Using shared animations for "${I}":`,H))}if(!H&&b[I]&&(H=b[I],console.log(`Using root-level animations for "${I}":`,H)),!H){if(console.warn(`Animation group "${I}" not found. Available groups:`,Object.keys(b).filter(W=>W!=="_genderSpecific")),b._genderSpecific){const q=(e?.toUpperCase()||"F")==="M"?"male":"female";console.warn(`Gender-specific groups (${q}):`,Object.keys(b._genderSpecific[q]||{}))}return null}if(Array.isArray(H)&&H.length>0){const W=Math.floor(Math.random()*H.length);return H[W]}return typeof H=="string"?H:(console.warn(`Animation group "${I}" is not a valid format (expected array or string):`,H),null)},[b,e]),S=x.useCallback((I,H=!1)=>{if(!k.current)return console.warn("TalkingHead not initialized yet"),null;const W=Le(I);if(W)try{return k.current.playAnimation(W,null,10,0,.01,H),console.log(`✅ Playing random animation from "${I}" group:`,W),W}catch(q){return console.error(`❌ Failed to play random animation from "${I}" group:`,q),null}else console.warn(`⚠️ No animation found for group "${I}"`);return null},[Le]),U=x.useCallback(async(I,H={})=>{if(!k.current||!K){console.warn("Avatar not ready for speaking");return}if(!I||I.trim()===""){console.warn("No text provided to speak");return}await Ie();const W=H.animationGroup||m;W&&!H.skipAnimation?(console.log(`🎬 Attempting to play animation from group: "${W}"`),console.log(`📊 Current avatarBody: "${e}", loadedAnimations:`,b),S(W)):console.log(`⏭️ Skipping animation (group: ${W}, skipAnimation: ${H.skipAnimation})`),X.current={remainingText:null,originalText:null,options:null},j.current=[],ue.current={text:I,options:H},w.current&&(clearInterval(w.current),w.current=null),f(!1),D.current=!1;const q=I.split(/[.!?]+/).filter(ne=>ne.trim().length>0);j.current=q;const ee={lipsyncLang:H.lipsyncLang||"en",onSpeechEnd:()=>{w.current&&(clearInterval(w.current),w.current=null),H.onSpeechEnd&&H.onSpeechEnd(),A()}};try{k.current.speakText(I,ee)}catch(ne){console.error("Error speaking text:",ne),ce(ne.message||"Failed to speak text")}},[K,A,Ie,m,S]);x.useEffect(()=>{if(!K||!L||!k.current)return;O.current&&clearInterval(O.current);const I=()=>{k.current&&!D.current&&S(L)};return I(),O.current=setInterval(()=>{I()},12e3+Math.random()*3e3),()=>{O.current&&(clearInterval(O.current),O.current=null)}},[K,L,S]),x.useEffect(()=>{K&&B&&E&&k.current&&U(B)},[K,B,E,U]);const Q=x.useCallback(()=>{if(k.current)try{const I=k.current.isSpeaking||!1,H=k.current.audioPlaylist||[],W=k.current.speechQueue||[];if(I||H.length>0||W.length>0){w.current&&(clearInterval(w.current),w.current=null);let q="";W.length>0&&(q=W.map(ee=>ee.text&&Array.isArray(ee.text)?ee.text.map(ne=>ne.word).join(" "):ee.text||"").join(" ")),X.current={remainingText:q||null,originalText:ue.current?.text||null,options:ue.current?.options||null},k.current.speechQueue.length=0,k.current.pauseSpeaking(),f(!0),D.current=!0}}catch(I){console.warn("Error pausing speech:",I)}},[]),$=x.useCallback(async()=>{if(!(!k.current||!V))try{await Ie(),f(!1),D.current=!1;const I=X.current?.remainingText,H=X.current?.originalText||ue.current?.text,W=X.current?.options||ue.current?.options||{},q=I||H;q&&U(q,W)}catch(I){console.warn("Error resuming speech:",I),f(!1),D.current=!1}},[V,U,Ie]),de=x.useCallback(()=>{k.current&&(k.current.stopSpeaking(),w.current&&(clearInterval(w.current),w.current=null),f(!1),D.current=!1)},[]);return x.useImperativeHandle(R,()=>({speakText:U,pauseSpeaking:Q,resumeSpeaking:$,stopSpeaking:de,resumeAudioContext:Ie,isPaused:()=>V,setMood:I=>k.current?.setMood(I),setBodyMovement:I=>{k.current&&k.current.setBodyMovement(I)},playAnimation:(I,H=!1)=>{k.current&&k.current.playAnimation&&k.current.playAnimation(I,null,10,0,.01,H)},playRandomAnimation:(I,H=!1)=>S(I,H),getRandomAnimation:I=>Le(I),playReaction:I=>k.current?.playReaction(I),playCelebration:()=>k.current?.playCelebration(),setShowFullAvatar:I=>{k.current&&(ie.current=I,k.current.setShowFullAvatar(I))},isReady:K,talkingHead:k.current})),le.jsxs("div",{className:`simple-talking-avatar-container ${v}`,style:T,children:[le.jsx("div",{ref:M,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),te&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),me&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:me})]})});De.displayName="SimpleTalkingAvatar";const We=x.forwardRef(({curriculumData:B=null,avatarConfig:n={},animations:e={},onLessonStart:t=()=>{},onLessonComplete:i=()=>{},onQuestionAnswer:s=()=>{},onCurriculumComplete:o=()=>{},onCustomAction:l=()=>{},autoStart:h=!1},r)=>{const u=x.useRef(null),a=x.useRef({currentModuleIndex:0,currentLessonIndex:0,currentQuestionIndex:0,isTeaching:!1,isQuestionMode:!1,lessonCompleted:!1,curriculumCompleted:!1,score:0,totalQuestions:0}),d=x.useRef({onLessonStart:t,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:l}),p=x.useRef(null),y=x.useRef(null),A=x.useRef(null),v=x.useRef(null),T=x.useRef(null),C=x.useRef(null),m=x.useRef(null),L=x.useRef(B?.curriculum||{title:"Default Curriculum",description:"No curriculum data provided",language:"en",modules:[]}),E=x.useRef({avatarUrl:n.avatarUrl||"/avatars/brunette.glb",avatarBody:n.avatarBody||"F",mood:n.mood||"happy",ttsLang:n.ttsLang||"en",ttsService:n.ttsService||null,ttsVoice:n.ttsVoice||null,ttsApiKey:n.ttsApiKey||null,bodyMovement:n.bodyMovement||"gesturing",movementIntensity:n.movementIntensity||.7,showFullAvatar:n.showFullAvatar!==void 0?n.showFullAvatar:!1,animations:e,lipsyncLang:"en"});x.useEffect(()=>{d.current={onLessonStart:t,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:l}},[t,i,s,o,l]),x.useEffect(()=>{L.current=B?.curriculum||{title:"Default Curriculum",description:"No curriculum data provided",language:"en",modules:[]},E.current={avatarUrl:n.avatarUrl||"/avatars/brunette.glb",avatarBody:n.avatarBody||"F",mood:n.mood||"happy",ttsLang:n.ttsLang||"en",ttsService:n.ttsService||null,ttsVoice:n.ttsVoice||null,ttsApiKey:n.ttsApiKey||null,bodyMovement:n.bodyMovement||"gesturing",movementIntensity:n.movementIntensity||.7,showFullAvatar:n.showFullAvatar!==void 0?n.showFullAvatar:!1,animations:e,lipsyncLang:"en"}},[B,n,e]);const R=x.useCallback(()=>(L.current||{modules:[]}).modules[a.current.currentModuleIndex]?.lessons[a.current.currentLessonIndex],[]),M=x.useCallback(()=>R()?.questions[a.current.currentQuestionIndex],[R]),k=x.useCallback((f,b)=>b.type==="multiple_choice"||b.type==="true_false"?f===b.answer:b.type==="code_test"&&typeof f=="object"&&f!==null?f.passed===!0:!1,[]),ie=x.useCallback(()=>{a.current.lessonCompleted=!0,a.current.isQuestionMode=!1;const f=a.current.totalQuestions>0?Math.round(a.current.score/a.current.totalQuestions*100):100;let b="Congratulations! You've completed this lesson";if(a.current.totalQuestions>0?b+=` You got ${a.current.score} correct out of ${a.current.totalQuestions} question${a.current.totalQuestions===1?"":"s"}, achieving a score of ${f} percent. `:b+="! ",f>=80?b+="Excellent work! You have a great understanding of this topic.":f>=60?b+="Good job! You understand most of the concepts.":b+="Keep practicing! You're making progress.",d.current.onLessonComplete({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f}),d.current.onCustomAction({type:"lessonComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f}),u.current){if(u.current.setMood("happy"),e.lessonComplete)try{u.current.playAnimation(e.lessonComplete,!0)}catch{u.current.playCelebration()}const P=L.current||{modules:[]},O=P.modules[a.current.currentModuleIndex],N=a.current.currentLessonIndex<(O?.lessons?.length||0)-1,J=a.current.currentModuleIndex<(P.modules?.length||0)-1,Z=N||J,Y=E.current||{lipsyncLang:"en"};u.current.speakText(b,{lipsyncLang:Y.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"lessonCompleteFeedbackDone",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f,hasNextLesson:Z})}})}},[e.lessonComplete]),ue=x.useCallback(()=>{a.current.curriculumCompleted=!0;const f=L.current||{modules:[]};if(d.current.onCurriculumComplete({modules:f.modules.length,totalLessons:f.modules.reduce((b,P)=>b+P.lessons.length,0)}),u.current){if(u.current.setMood("celebrating"),e.curriculumComplete)try{u.current.playAnimation(e.curriculumComplete,!0)}catch{u.current.playCelebration()}const b=E.current||{lipsyncLang:"en"};u.current.speakText("Amazing! You've completed the entire curriculum! You're now ready to move on to more advanced topics. Well done!",{lipsyncLang:b.lipsyncLang})}},[e.curriculumComplete]),w=x.useCallback(()=>{const f=R();a.current.isQuestionMode=!0,a.current.currentQuestionIndex=0,a.current.totalQuestions=f?.questions?.length||0,a.current.score=0;const b=M();b&&d.current.onCustomAction({type:"questionStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:b,score:a.current.score});const P=()=>{if(!u.current||!b)return;if(u.current.setMood("happy"),e.questionStart)try{u.current.playAnimation(e.questionStart,!0)}catch(N){console.warn("Failed to play questionStart animation:",N)}const O=E.current||{lipsyncLang:"en"};b.type==="code_test"?u.current.speakText(`Let's test your coding skills! Here's your first challenge: ${b.question}`,{lipsyncLang:O.lipsyncLang}):b.type==="multiple_choice"?u.current.speakText(`Now let me ask you some questions. Here's the first one: ${b.question}`,{lipsyncLang:O.lipsyncLang}):b.type==="true_false"?u.current.speakText(`Let's start with some true or false questions. First question: ${b.question}`,{lipsyncLang:O.lipsyncLang}):u.current.speakText(`Now let me ask you some questions. Here's the first one: ${b.question}`,{lipsyncLang:O.lipsyncLang})};if(u.current&&u.current.isReady&&b)P();else if(u.current&&u.current.isReady){const O=E.current||{lipsyncLang:"en"};u.current.speakText("Now let me ask you some questions to test your understanding.",{lipsyncLang:O.lipsyncLang})}else{const O=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(O),b&&P())},100);setTimeout(()=>{clearInterval(O)},5e3)}},[e.questionStart,R,M]),D=x.useCallback(()=>{const f=R();if(a.current.currentQuestionIndex<(f?.questions?.length||0)-1){u.current&&u.current.stopSpeaking&&u.current.stopSpeaking(),a.current.currentQuestionIndex+=1;const b=M();b&&d.current.onCustomAction({type:"nextQuestion",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:b,score:a.current.score});const P=()=>{if(!u.current||!b)return;if(u.current.setMood("happy"),u.current.setBodyMovement("idle"),e.nextQuestion)try{u.current.playAnimation(e.nextQuestion,!0)}catch(Y){console.warn("Failed to play nextQuestion animation:",Y)}const O=E.current||{lipsyncLang:"en"},J=R()?.questions?.length||0,Z=a.current.currentQuestionIndex>=J-1;if(b.type==="code_test"){const Y=Z?`Great! Here's your final coding challenge: ${b.question}`:`Great! Now let's move on to your next coding challenge: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else if(b.type==="multiple_choice"){const Y=Z?`Alright! Here's your final question: ${b.question}`:`Alright! Here's your next question: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else if(b.type==="true_false"){const Y=Z?`Now let's try this final one: ${b.question}`:`Now let's try this one: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else{const Y=Z?`Here's your final question: ${b.question}`:`Here's the next question: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}};if(u.current&&u.current.isReady&&b)P();else if(b){const O=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(O),P())},100);setTimeout(()=>{clearInterval(O)},5e3)}}else d.current.onCustomAction({type:"allQuestionsComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,totalQuestions:a.current.totalQuestions,score:a.current.score})},[e.nextQuestion,R,M]),X=x.useCallback(()=>{const f=L.current||{modules:[]},b=f.modules[a.current.currentModuleIndex];if(a.current.currentLessonIndex<(b?.lessons?.length||0)-1){a.current.currentLessonIndex+=1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0;const O=f.modules[a.current.currentModuleIndex],N=a.current.currentLessonIndex<(O?.lessons?.length||0)-1,J=a.current.currentModuleIndex<(f.modules?.length||0)-1,Z=N||J;d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,hasNextLesson:Z}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}else if(a.current.currentModuleIndex<(f.modules?.length||0)-1){a.current.currentModuleIndex+=1,a.current.currentLessonIndex=0,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0;const N=f.modules[a.current.currentModuleIndex],J=a.current.currentLessonIndex<(N?.lessons?.length||0)-1,Z=a.current.currentModuleIndex<(f.modules?.length||0)-1,Y=J||Z;d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,hasNextLesson:Y}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}else T.current&&T.current()},[]),j=x.useCallback(()=>{const f=R();let b=null;if(f?.avatar_script&&f?.body){const P=f.avatar_script.trim(),O=f.body.trim(),N=P.match(/[.!?]$/)?" ":". ";b=`${P}${N}${O}`}else b=f?.avatar_script||f?.body||null;if(u.current&&u.current.isReady&&b){a.current.isTeaching=!0,a.current.isQuestionMode=!1,a.current.score=0,a.current.totalQuestions=0,u.current.setMood("happy");let P=!1;if(e.teaching)try{u.current.playAnimation(e.teaching,!0),P=!0}catch(N){console.warn("Failed to play teaching animation:",N)}P||u.current.setBodyMovement("gesturing");const O=E.current||{lipsyncLang:"en"};d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f}),d.current.onCustomAction({type:"teachingStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f}),u.current.speakText(b,{lipsyncLang:O.lipsyncLang,onSpeechEnd:()=>{a.current.isTeaching=!1,d.current.onCustomAction({type:"teachingComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f,hasQuestions:f.questions&&f.questions.length>0}),f?.code_example&&d.current.onCustomAction({type:"codeExampleReady",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f,codeExample:f.code_example})}})}},[e.teaching,R]),te=x.useCallback(f=>{const b=M(),P=k(f,b);if(P&&(a.current.score+=1),d.current.onQuestionAnswer({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,answer:f,isCorrect:P,question:b}),u.current)if(P){if(u.current.setMood("happy"),e.correct)try{u.current.playReaction("happy")}catch{u.current.setBodyMovement("happy")}u.current.setBodyMovement("gesturing");const N=R()?.questions?.length||0;a.current.currentQuestionIndex>=N-1;const J=a.current.currentQuestionIndex<N-1;console.log("[CurriculumLearning] Answer feedback - questionIndex:",a.current.currentQuestionIndex,"totalQuestions:",N,"hasNextQuestion:",J);const Z=b.type==="code_test"?`Great job! Your code passed all the tests! ${b.explanation||""}`:`Excellent! That's correct! ${b.explanation||""}`,Y=E.current||{lipsyncLang:"en"};u.current.speakText(Z,{lipsyncLang:Y.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:!0,hasNextQuestion:J,score:a.current.score,totalQuestions:a.current.totalQuestions})}})}else{if(u.current.setMood("sad"),e.incorrect)try{u.current.playAnimation(e.incorrect,!0)}catch{u.current.setBodyMovement("idle")}u.current.setBodyMovement("gesturing");const N=R()?.questions?.length||0,J=a.current.currentQuestionIndex>=N-1,Z=a.current.currentQuestionIndex<N-1;console.log("[CurriculumLearning] Answer feedback (incorrect) - questionIndex:",a.current.currentQuestionIndex,"totalQuestions:",N,"hasNextQuestion:",Z);const Y=b.type==="code_test"?`Your code didn't pass all the tests. ${b.explanation||"Try again!"}`:`Not quite right, but don't worry! ${b.explanation||""}${J?"":" Let's move on to the next question."}`,Re=E.current||{lipsyncLang:"en"};u.current.speakText(Y,{lipsyncLang:Re.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:!1,hasNextQuestion:Z,score:a.current.score,totalQuestions:a.current.totalQuestions})}})}else{const N=R()?.questions?.length||0;d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:P,hasNextQuestion:a.current.currentQuestionIndex<N-1,score:a.current.score,totalQuestions:a.current.totalQuestions,avatarNotReady:!0})}},[e.correct,e.incorrect,M,R,k]),ae=x.useCallback(f=>{const b=M();if(!f||typeof f!="object"){console.error("Invalid code test result format. Expected object with {passed: boolean, ...}");return}if(b?.type!=="code_test"){console.warn("Current question is not a code test. Use handleAnswerSelect for other question types.");return}const P={passed:f.passed===!0,results:f.results||[],output:f.output||"",error:f.error||null,executionTime:f.executionTime||null,testCount:f.testCount||0,passedCount:f.passedCount||0,failedCount:f.failedCount||0};d.current.onCustomAction({type:"codeTestSubmitted",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,testResult:P,question:b}),m.current&&m.current(P)},[M,k]),me=x.useCallback(()=>{if(a.current.currentQuestionIndex>0){a.current.currentQuestionIndex-=1;const f=M();f&&d.current.onCustomAction({type:"questionStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:f,score:a.current.score});const b=()=>{if(!u.current||!f)return;u.current.setMood("happy"),u.current.setBodyMovement("idle");const P=E.current||{lipsyncLang:"en"};f.type==="code_test"?u.current.speakText(`Let's go back to this coding challenge: ${f.question}`,{lipsyncLang:P.lipsyncLang}):u.current.speakText(`Going back to: ${f.question}`,{lipsyncLang:P.lipsyncLang})};if(u.current&&u.current.isReady&&f)b();else if(f){const P=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(P),b())},100);setTimeout(()=>{clearInterval(P)},5e3)}}},[M]),ce=x.useCallback(()=>{const f=L.current||{modules:[]};if(f.modules[a.current.currentModuleIndex],a.current.currentLessonIndex>0)a.current.currentLessonIndex-=1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0,d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"));else if(a.current.currentModuleIndex>0){const O=f.modules[a.current.currentModuleIndex-1];a.current.currentModuleIndex-=1,a.current.currentLessonIndex=(O?.lessons?.length||1)-1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0,d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}},[R]),K=x.useCallback(()=>{a.current.currentModuleIndex=0,a.current.currentLessonIndex=0,a.current.currentQuestionIndex=0,a.current.isTeaching=!1,a.current.isQuestionMode=!1,a.current.lessonCompleted=!1,a.current.curriculumCompleted=!1,a.current.score=0,a.current.totalQuestions=0},[]),ye=x.useCallback(f=>{console.log("Avatar is ready!",f);const b=R(),P=b?.avatar_script||b?.body;h&&P&&setTimeout(()=>{p.current&&p.current()},10)},[h,R]);x.useLayoutEffect(()=>{p.current=j,y.current=X,A.current=ie,v.current=D,T.current=ue,C.current=w,m.current=te}),x.useImperativeHandle(r,()=>({startTeaching:j,startQuestions:w,handleAnswerSelect:te,handleCodeTestResult:ae,nextQuestion:D,previousQuestion:me,nextLesson:X,previousLesson:ce,completeLesson:ie,completeCurriculum:ue,resetCurriculum:K,getState:()=>({...a.current}),getCurrentQuestion:()=>M(),getCurrentLesson:()=>R(),getAvatarRef:()=>u.current,speakText:async(f,b={})=>{await u.current?.resumeAudioContext?.();const P=E.current||{lipsyncLang:"en"};u.current?.speakText(f,{...b,lipsyncLang:b.lipsyncLang||P.lipsyncLang})},resumeAudioContext:async()=>{if(u.current?.resumeAudioContext)return await u.current.resumeAudioContext();const f=u.current?.talkingHead;if(f?.audioCtx){const b=f.audioCtx;if(b.state==="suspended"||b.state==="interrupted")try{await b.resume(),console.log("Audio context resumed via talkingHead")}catch(P){console.warn("Failed to resume audio context:",P)}}else console.warn("Audio context not available yet")},stopSpeaking:()=>u.current?.stopSpeaking(),pauseSpeaking:()=>u.current?.pauseSpeaking(),resumeSpeaking:async()=>await u.current?.resumeSpeaking(),isPaused:()=>u.current&&typeof u.current.isPaused<"u"?u.current.isPaused:!1,setMood:f=>u.current?.setMood(f),playAnimation:(f,b)=>u.current?.playAnimation(f,b),setBodyMovement:f=>u.current?.setBodyMovement(f),setMovementIntensity:f=>u.current?.setMovementIntensity(f),playRandomDance:()=>u.current?.playRandomDance(),playReaction:f=>u.current?.playReaction(f),playCelebration:()=>u.current?.playCelebration(),setShowFullAvatar:f=>u.current?.setShowFullAvatar(f),setTimingAdjustment:f=>u.current?.setTimingAdjustment(f),lockAvatarPosition:()=>u.current?.lockAvatarPosition(),unlockAvatarPosition:()=>u.current?.unlockAvatarPosition(),triggerCustomAction:(f,b)=>{d.current.onCustomAction({type:f,...b,state:{...a.current}})},handleResize:()=>u.current?.handleResize(),isAvatarReady:()=>u.current?.isReady||!1}),[j,w,te,ae,D,X,ie,ue,K,M,R]);const V=E.current||{avatarUrl:"/avatars/brunette.glb",avatarBody:"F",mood:"happy",ttsLang:"en",ttsService:null,ttsVoice:null,ttsApiKey:null,bodyMovement:"gesturing",movementIntensity:.7,showFullAvatar:!1,animations:e};return le.jsx("div",{style:{width:"100%",height:"100%"},children:le.jsx(Ee,{ref:u,avatarUrl:V.avatarUrl,avatarBody:V.avatarBody,mood:V.mood,ttsLang:V.ttsLang,ttsService:V.ttsService,ttsVoice:V.ttsVoice,ttsApiKey:V.ttsApiKey,bodyMovement:V.bodyMovement,movementIntensity:V.movementIntensity,showFullAvatar:V.showFullAvatar,cameraView:"upper",animations:V.animations,onReady:ye,onLoading:()=>{},onError:f=>{console.error("Avatar error:",f)}})})});We.displayName="CurriculumLearning";const Fe={dance:{name:"dance",type:"code-based",variations:["dancing","dancing2","dancing3"],loop:!0,duration:1e4,description:"Celebration dance animation with multiple variations"},happy:{name:"happy",type:"code-based",loop:!0,duration:5e3,description:"Happy, upbeat body movement"},surprised:{name:"surprised",type:"code-based",loop:!1,duration:3e3,description:"Surprised reaction with quick movements"},thinking:{name:"thinking",type:"code-based",loop:!0,duration:8e3,description:"Thoughtful, contemplative movement"},nodding:{name:"nodding",type:"code-based",loop:!1,duration:2e3,description:"Nodding agreement gesture"},shaking:{name:"shaking",type:"code-based",loop:!1,duration:2e3,description:"Shaking head disagreement gesture"},celebration:{name:"celebration",type:"code-based",loop:!1,duration:3e3,description:"Celebration animation for achievements"},energetic:{name:"energetic",type:"code-based",loop:!0,duration:6e3,description:"High-energy, enthusiastic movement"},swaying:{name:"swaying",type:"code-based",loop:!0,duration:8e3,description:"Gentle swaying motion"},bouncing:{name:"bouncing",type:"code-based",loop:!0,duration:4e3,description:"Bouncy, playful movement"},gesturing:{name:"gesturing",type:"code-based",loop:!0,duration:5e3,description:"Teaching gesture animation"},walking:{name:"walking",type:"code-based",loop:!0,duration:6e3,description:"Walking motion"},prancing:{name:"prancing",type:"code-based",loop:!0,duration:4e3,description:"Playful prancing movement"},excited:{name:"excited",type:"code-based",loop:!0,duration:5e3,description:"Excited, energetic movement"}},pt=B=>Fe[B]||null,gt=B=>Fe.hasOwnProperty(B);exports.CurriculumLearning=We;exports.SimpleTalkingAvatar=De;exports.TalkingHeadAvatar=Ee;exports.TalkingHeadComponent=Ue;exports.animations=Fe;exports.getActiveTTSConfig=Se;exports.getAnimation=pt;exports.getVoiceOptions=dt;exports.hasAnimation=gt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=require("react/jsx-runtime"),x=require("react"),Ve=require("three"),Ze=require("three/addons/controls/OrbitControls.js"),Xe=require("three/addons/loaders/GLTFLoader.js"),je=require("three/addons/loaders/DRACOLoader.js"),Oe=require("three/addons/loaders/FBXLoader.js"),Ye=require("three/addons/environments/RoomEnvironment.js"),Qe=require("three/addons/libs/stats.module.js");var He=typeof document<"u"?document.currentScript:null;function qe(B){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(B){for(const e in B)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(B,e);Object.defineProperty(n,e,t.get?t:{enumerable:!0,get:()=>B[e]})}}return n.default=B,Object.freeze(n)}const g=qe(Ve);let c,re,he;const z=[0,0,0,0],F=new g.Vector3,ke=new g.Vector3,oe=new g.Vector3,Ce=new g.Vector3;new g.Plane;new g.Ray;new g.Euler;const se=new g.Quaternion,Ne=new g.Quaternion,pe=new g.Matrix4,ge=new g.Matrix4;new g.Vector3;const we=new g.Vector3(0,0,1),_e=new g.Vector3(1,0,0),Ke=new g.Vector3(0,1,0),Je=new g.Vector3(0,0,1);class $e{constructor(n=null){this.opt=Object.assign({warmupMs:2e3,sensitivityFactor:1,movementFactor:1,isExcludes:!0,isPivots:!0,isLimits:!0,helperBoneColor1:16711680,helperBoneColor2:16238028,helperLinkColor1:16711680,helperLinkColor2:255,helperExcludesColor:11184895},n||{}),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.helpers={isActive:!1,isShowAll:!1,points:{bones:[],pivots:[],object:null},lines:{bones:[],object:null},excludes:{bones:[],deltaLocals:[],radii:[],objects:[]}},this.running=!1,this.timerMs=0}getOptionValue(n){return this.opt[n]}setOptionValue(n,e){this.opt[n]=e,this.helpers.isActive&&this.showHelpers()}getBoneNames(){return this.data.map(n=>n.name)}getValue(n,e){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(n))throw new Error("Dynamic bone '"+n+"' not found.");const t=this.dict[n];let i;if(e==="type")i=t.type;else if(e==="stiffness")i=t.k.every(s=>s===t.k[0])?t.k[0]:[...t.k];else if(e==="damping")i=t.c.every(s=>s===t.c[0])?t.c[0]:[...t.c];else if(e==="external")i=t.ext<1?t.ext:null;else if(e==="limits")i=t.limits?.map(s=>s===null?null:[...s]);else if(e==="deltaLocal")i=t.dl?[...t.dl]:null;else if(e==="excludes")i=t.excludes?[...t.excludes.map(s=>{const o={bone:s.bone.name.slice(),radius:s.radius};return s.deltaLocal&&(o.deltaLocal=[...s.deltaLocal]),o})]:null;else if(e==="deltaWorld")i=t.dw?[...t.dw]:null;else if(e==="pivot")i=t.pivot;else if(e==="helper")i=t.helper;else throw new Error("Unsupported property '"+e+"'.");return i}setValue(n,e,t){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(n))throw new Error("Dynamic bone '"+n+"' not found.");const i=this.dict[n];if(e==="type"){if(!t)throw new Error("Parameter 'type' not set.");if(typeof t!="string")throw new Error("Type must be a string.");switch(t){case"point":i.isPoint=!0,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"link":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!1;break;case"mix1":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"mix2":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!0;break;case"full":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!0;break;default:throw new Error("Unknown type'"+t+"'.")}i.type=t.slice()}else if(e==="stiffness"){if(!t)throw new Error("Parameter 'stiffness' not set.");if(!Number.isNaN(t)&&t>=0)i.k=Array(4).fill(t);else if(Array.isArray(t)&&t.length===4&&t.every(s=>s>=0))i.k=[...t];else throw new Error("Stiffness must be a non-negative number or an array of four non-negative numbers.")}else if(e==="damping"){if(!t)throw new Error("Parameter 'damping' not set.");if(!Number.isNaN(t)&&t>=0)i.c=Array(4).fill(t);else if(Array.isArray(t)&&t.length===4&&t.every(s=>s>=0))i.c=[...t];else throw new Error("Damping must be a non-negative number or an array of four non-negative numbers.")}else if(e==="external")if(t==null)i.ext=1;else if(!Number.isNaN(t)&&t>=0&&t<=1)i.ext=t;else throw new Error("External (if set) must be a number between [0,1].");else if(e==="limits")if(t==null)i.limits=null;else{if(!Array.isArray(t)||t.length!==4)throw new Error("Limits (if set) must null, or an array of four arrays.");if(!t.every(s=>s===null||Array.isArray(s)&&s.length===2&&(s[0]===null||!Number.isNaN(s[0]))&&(s[1]===null||!Number.isNaN(s))))throw new Error("Limit values must be null or numbers.");i.limits=[t[0]?[...t[0]]:null,t[1]?[...t[1]]:null,t[2]?[...t[2]]:null,t[3]?[...t[3]]:null]}else if(e==="excludes"){if(t==null)i.excludes=null;else{if(!Array.isArray(t))throw new Error("Excludes (if set) must null, or an array.");i.excludes=[],t.forEach((s,o)=>{if(!s.bone)throw new Error("Bone not specified in #"+o+" exclude.");if(typeof s.bone!="string"||s.bone.length===0)throw new Error("Bone name must be a non-empty string in #"+o+" exclude.");const l=this.armature.getObjectByName(s.bone);if(!l)throw new Error("Bone '"+s.bone+"' not found in #"+o+" exclude.");if(Number.isNaN(s.radius)&&s.radius>=0)throw new Error("Radius must be a non-negative number in #"+o+" exclude.");const h={bone:l,radius:s.radius,radiusSq:s.radius*s.radius,deltaLocal:null};if(s.deltaLocal){if(!Array.isArray(s.deltaLocal)||s.deltaLocal.length!==3||s.deltaLocal.some(r=>Number.isNaN(r)))throw new Error("deltaLocal must be an array of three numbers in #"+o+" exclude.");h.deltaLocal=[...s.deltaLocal]}i.excludes.push(h)})}this.showHelpers()}else if(e==="helper"){if(t==null)i.helper=null;else{if(t!==!1&&t!==!0)throw new Error("Helper, if set, must be false or true.");i.helper=t}this.showHelpers()}else if(e==="pivot")if(t==null)i.pivot=null;else{if(t!==!1&&t!==!0)throw new Error("Pivot, if set, must be false or true.");if(t===!0&&i.type===0)throw new Error("Point type bone can't be a pivot.");i.pivot=t}else if(e==="deltaLocal")if(t==null)i.dl=null;else{if(!Array.isArray(t)||t.length!==3)throw new Error("deltaLocal, is set, must be an array of three numbers.");if(!t.every(s=>!Number.isNaN(s)))throw new Error("deltaLocal values must be numbers.");i.dl=[...t]}else if(e==="deltaWorld")if(t==null)i.dw=null;else{if(!Array.isArray(t)||t.length!==3)throw new Error("deltaWorld, is set, must be an array of three values.");if(!t.every(s=>!Number.isNaN(s)))throw new Error("deltaWorld values must be numbers.");i.dw=[...t]}else throw new Error("Unsupported property "+e)}getConfig(){return this.data.map(n=>{const e={bone:n.name.slice()};return["type","stiffness","damping","external","deltaLocal","deltaWorld","limits","excludes","pivot","helper"].forEach(t=>{c=this.getValue(n.name,t),c&&(e[t]=c)}),e})}sortBones(){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");let n=0;const e=new WeakMap;this.armature.traverse(o=>{e.has(o)||(e.set(o,n),n++)}),this.data.sort((o,l)=>e.get(o.bone)-e.get(l.bone)),this.data.forEach(o=>{c=this.dict[o.boneParent.name],c&&(c.children||(c.children=[]),c.children.push(o))}),this.objectsUpdate=[];const t=new WeakSet,i=o=>o.parent?.isBone?[o,...i(o.parent)]:[o],s=o=>{i(o).forEach(h=>{t.has(h)||(this.objectsUpdate.push(h),t.add(h))})};this.data.forEach(o=>{s(o.bone),o.excludes&&o.excludes.forEach(l=>{s(l.bone)})}),this.objectsUpdate.sort((o,l)=>e.get(o)-e.get(l))}setup(n,e,t){this.dispose();const i=(s,o)=>{if(!s)throw this.dispose(),new Error(o)};i(n?.isScene,"First parameter must be Scene."),this.scene=n,i(e?.isObject3D,"Second parameter must be the armature Object3D."),this.armature=e,i(Array.isArray(t),"Third parameter must be an array of bone configs."),this.config=t,this.config.forEach((s,o)=>{const l="Config item #"+o+": ";i(s.bone,l+"Bone not specified.");const h=s.bone;i(typeof h=="string"&&h.length>0,l+"Bone name must be a non-empty string.");const r=this.armature.getObjectByName(h);i(r,l+"Bone '"+h+"' not found."),i(r.parent?.isBone,l+"Bone must have a parent bone."),i(this.data.every(a=>a.bone!==r),l+"Bone '"+h+"' already exists."),r.updateMatrixWorld(!0);const u={name:h,bone:r,boneParent:r.parent,vBasis:r.position.clone(),vWorld:r.parent.getWorldPosition(F).clone(),qBasis:r.parent.quaternion.clone(),l:r.position.length(),p:[0,0,0,0],v:[0,0,0,0],a:[0,0,0,0],ev:[0,0,0,0],ea:[0,0,0,0]};u.boneParent.matrixWorld.decompose(F,se,oe),F.copy(we).applyQuaternion(se).setY(0).normalize(),se.premultiply(Ne.setFromUnitVectors(we,F).invert()).normalize(),u.qWorldInverseYaw=se.clone().normalize(),this.data.push(u),this.dict[h]=u;try{this.setValue(h,"type",s.type),this.setValue(h,"stiffness",s.stiffness),this.setValue(h,"damping",s.damping),this.setValue(h,"external",s.external),this.setValue(h,"limits",s.limits),this.setValue(h,"excludes",s.excludes),this.setValue(h,"deltaLocal",s.deltaLocal),this.setValue(h,"deltaWorld",s.deltaWorld),this.setValue(h,"pivot",s.pivot),this.setValue(h,"helper",s.helper)}catch(a){i(!1,l+a)}}),this.sortBones(),this.start()}update(n){if(!this.running)return;let e,t,i,s,o;for(this.timerMs+=n,n>1e3&&(this.timerMs=0),n/=1e3,e=0,i=this.objectsUpdate.length;e<i;e++)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;for(e=0,i=this.data.length;e<i;e++){if(o=this.data[e],F.copy(o.vWorld),pe.copy(o.boneParent.matrixWorld),ge.copy(pe).invert(),o.vWorld.setFromMatrixPosition(pe),F.applyMatrix4(ge),F.length()>.5&&(console.info("Info: Unrealistic jump of "+F.length().toFixed(2)+" meters."),F.setLength(.5)),F.applyQuaternion(o.bone.quaternion),z[0]=F.x,z[1]=F.y,z[2]=-F.z,z[3]=F.length()/3,o.children)for(t=0,s=o.children.length;t<s;t++)c=o.children[t],z[0]-=c.v[0]*n/3,z[1]-=c.v[1]*n/3,z[2]+=c.v[2]*n/3,z[3]-=c.v[3]*n/3;if(c=this.opt.sensitivityFactor,z[0]*=o.ext*c,z[1]*=o.ext*c,z[2]*=o.ext*c,z[3]*=o.ext*c,o.isX&&(c=z[0]/n,o.ea[0]=(c-o.ev[0])/n,o.ev[0]=c,o.a[0]=-o.k[0]*o.p[0]-o.c[0]*o.v[0]-o.ea[0],o.p[0]+=o.v[0]*n+o.a[0]*n*n/2+z[0],c=o.v[0]+o.a[0]*n/2,c=-o.k[0]*o.p[0]-o.c[0]*c-o.ea[0],o.v[0]=o.v[0]+(c+o.a[0])*n/2),o.isY&&(c=z[1]/n,o.ea[1]=(c-o.ev[1])/n,o.ev[1]=c,o.a[1]=-o.k[1]*o.p[1]-o.c[1]*o.v[1]-o.ea[1],o.p[1]+=o.v[1]*n+o.a[1]*n*n/2+z[1],c=o.v[1]+o.a[1]*n/2,c=-o.k[1]*o.p[1]-o.c[1]*c-o.ea[1],o.v[1]=o.v[1]+(c+o.a[1])*n/2),o.isZ&&(c=z[2]/n,o.ea[2]=(c-o.ev[2])/n,o.ev[2]=c,o.a[2]=-o.k[2]*o.p[2]-o.c[2]*o.v[2]-o.ea[2],o.p[2]+=o.v[2]*n+o.a[2]*n*n/2+z[2],c=o.v[2]+o.a[2]*n/2,c=-o.k[2]*o.p[2]-o.c[2]*c-o.ea[2],o.v[2]=o.v[2]+(c+o.a[2])*n/2),o.isT&&(c=z[3]/n,o.ea[3]=(c-o.ev[3])/n,o.ev[3]=c,o.a[3]=-o.k[3]*o.p[3]-o.c[3]*o.v[3]-o.ea[3],o.p[3]+=o.v[3]*n+o.a[3]*n*n/2+z[3],c=o.v[3]+o.a[3]*n/2,c=-o.k[3]*o.p[3]-o.c[3]*c-o.ea[3],o.v[3]=o.v[3]+(c+o.a[3])*n/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),z[0]=o.p[0],z[1]=o.p[1],z[2]=o.p[2],z[3]=o.p[3],c=this.opt.movementFactor,z[0]*=c,z[1]*=c,z[2]*=c,z[3]*=c,o.dl&&(c=o.dl,z[0]+=c[0],z[1]+=c[1],z[2]+=c[2]),o.dw&&(c=o.dw,F.set(o.vBasis.x+z[0],o.vBasis.y+z[1],o.vBasis.z+z[2]),F.applyMatrix4(pe),F.x+=c[0],F.y+=c[1],F.z+=c[2],F.applyMatrix4(ge),z[0]+=F.x-o.vBasis.x,z[1]+=F.y-o.vBasis.y,z[2]+=F.z-o.vBasis.z),o.limits&&this.opt.isLimits&&(c=o.limits,c[0]&&(c[0][0]!==null&&z[0]<c[0][0]&&(z[0]=c[0][0]),c[0][1]!==null&&z[0]>c[0][1]&&(z[0]=c[0][1])),c[1]&&(c[1][0]!==null&&z[1]<c[1][0]&&(z[1]=c[1][0]),c[1][1]!==null&&z[1]>c[1][1]&&(z[1]=c[1][1])),c[2]&&(c[2][0]!==null&&z[2]<c[2][0]&&(z[2]=c[2][0]),c[2][1]!==null&&z[2]>c[2][1]&&(z[2]=c[2][1])),c[3]&&(c[3][0]!==null&&z[3]<c[3][0]&&(z[3]=c[3][0]),c[3][1]!==null&&z[3]>c[3][1]&&(z[3]=c[3][1]))),o.isPoint)o.bone.position.set(o.vBasis.x+z[0],o.vBasis.y+z[1],o.vBasis.z-z[2]);else if(o.boneParent.quaternion.copy(o.qBasis),o.pivot&&this.opt.isPivots&&(o.boneParent.updateWorldMatrix(!1,!1),o.boneParent.matrixWorld.decompose(F,se,oe),F.copy(we).applyQuaternion(se).setY(0).normalize(),se.premultiply(Ne.setFromUnitVectors(we,F).invert()).normalize(),o.boneParent.quaternion.multiply(se.invert()),o.boneParent.quaternion.multiply(o.qWorldInverseYaw)),o.isZ&&(c=Math.atan(z[0]/o.l),se.setFromAxisAngle(Je,-c),o.boneParent.quaternion.multiply(se)),o.isY&&(c=o.l/3,c=c*Math.tanh(z[1]/c),o.bone.position.setLength(o.l+c)),o.isX&&(c=Math.atan(z[2]/o.l),se.setFromAxisAngle(_e,-c),o.boneParent.quaternion.multiply(se)),o.isT&&(c=1.5*Math.tanh(z[3]*1.5),se.setFromAxisAngle(Ke,-c),o.boneParent.quaternion.multiply(se)),o.boneParent.updateWorldMatrix(!1,!0),o.excludes&&this.opt.isExcludes)for(t=0,s=o.excludes.length;t<s;t++)c=o.excludes[t],oe.set(0,0,0),c.deltaLocal&&(oe.x+=c.deltaLocal[0],oe.y+=c.deltaLocal[1],oe.z+=c.deltaLocal[2]),oe.applyMatrix4(c.bone.matrixWorld),ge.copy(o.boneParent.matrixWorld).invert(),oe.applyMatrix4(ge),F.copy(o.bone.position),!(F.distanceToSquared(oe)>=c.radiusSq)&&(he=F.length(),re=oe.length(),!(re>c.radius+he)&&(re<Math.abs(c.radius-he)||(re=(re*re+he*he-c.radiusSq)/(2*re),oe.normalize(),Ce.copy(oe).multiplyScalar(re),re=Math.sqrt(he*he-re*re),F.subVectors(F,Ce).projectOnPlane(oe).normalize().multiplyScalar(re),ke.subVectors(o.vBasis,Ce).projectOnPlane(oe).normalize(),he=ke.dot(F),he<0&&(he=Math.sqrt(re*re-he*he),ke.multiplyScalar(he),F.add(ke)),F.add(Ce).normalize(),oe.copy(o.bone.position).normalize(),se.setFromUnitVectors(oe,F),o.boneParent.quaternion.premultiply(se),o.boneParent.updateWorldMatrix(!1,!0))))}this.helpers.isActive&&this.updateHelpers()}showHelpers(n){if(this.hideHelpers(),this.helpers.isShowAll=n===void 0?this.helpers.isShowAll:n===!0,c=this.helpers,this.data.forEach(e=>{(this.helpers.isShowAll||e.helper===!0)&&(c.points.bones.push(e.bone),c.points.pivots.push(e.pivot),e.type!==0&&c.lines.bones.push(e.bone),e.excludes&&e.excludes.forEach(t=>{let i=!1;for(let s=0;s<c.excludes.bones.length;s++)if(c.excludes.bones[s]===t.bone&&c.excludes.radii[s]===t.radius&&!(c.excludes.deltaLocals[s]===null&&t.deltaLocal!==null)&&!(c.excludes.deltaLocals[s]!==null&&t.deltaLocal===null)&&!(c.excludes.deltaLocals[s]!==null&&c.excludes.deltaLocals[s].some((o,l)=>o!==t.deltaLocal[l]))){i=!0;break}i||(c.excludes.bones.push(t.bone),c.excludes.radii.push(t.radius),c.excludes.deltaLocals.push(t.deltaLocal?[...t.deltaLocal]:null),c.excludes.objects.push(null))}))}),c=this.helpers.excludes,this.opt.isExcludes&&c.bones.length&&c.bones.forEach((e,t)=>{const i=new g.SphereGeometry(c.radii[t],6,6),s=new g.MeshBasicMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,wireframe:!0,color:this.opt.helperExcludesColor});c.objects[t]=new g.Mesh(i,s),c.objects[t].renderOrder=997,e.add(c.objects[t]),c.deltaLocals[t]&&c.objects[t].position.set(c.deltaLocals[t][0],c.deltaLocals[t][1],c.deltaLocals[t][2])}),c=this.helpers.points,c.bones.length){this.helpers.isActive=!0;const e=new g.BufferGeometry,t=c.bones.map(h=>[0,0,0]).flat();e.setAttribute("position",new g.Float32BufferAttribute(t,3));const i=new g.Color(this.opt.helperBoneColor1),s=new g.Color(this.opt.helperBoneColor2),o=c.pivots.map(h=>h&&this.opt.isPivots?[s.r,s.g,s.b]:[i.r,i.g,i.b]).flat();e.setAttribute("color",new g.Float32BufferAttribute(o,3));const l=new g.PointsMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,size:.2,vertexColors:!0});c.object=new g.Points(e,l),c.object.renderOrder=998,c.object.matrix=this.armature.matrixWorld,c.object.matrixAutoUpdate=!1,this.scene.add(c.object)}if(c=this.helpers.lines,c.bones.length){const e=new g.BufferGeometry,t=c.bones.map(h=>[0,0,0,0,0,0]).flat();e.setAttribute("position",new g.Float32BufferAttribute(t,3));const i=new g.Color(this.opt.helperLinkColor1),s=new g.Color(this.opt.helperLinkColor2),o=c.bones.map(h=>[i.r,i.g,i.b,s.r,s.g,s.b]).flat();e.setAttribute("color",new g.Float32BufferAttribute(o,3));const l=new g.LineBasicMaterial({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0});c.object=new g.LineSegments(e,l),c.object.renderOrder=999,c.object.matrix=this.armature.matrixWorld,c.object.matrixAutoUpdate=!1,this.scene.add(c.object)}}updateHelpers(){if(c=this.helpers.points,c.bones.length){ge.copy(this.armature.matrixWorld).invert();const n=c.object.geometry.getAttribute("position");for(let e=0,t=c.bones.length;e<t;e++)pe.multiplyMatrices(ge,c.bones[e].matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(e,F.x,F.y,F.z);n.needsUpdate=!0,c.object.updateMatrixWorld()}if(c=this.helpers.lines,c.bones.length){ge.copy(this.armature.matrixWorld).invert();const n=c.object.geometry.getAttribute("position");for(let e=0,t=0,i=c.bones.length;e<i;e++,t+=2)pe.multiplyMatrices(ge,c.bones[e].matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(t,F.x,F.y,F.z),pe.multiplyMatrices(ge,c.bones[e].parent.matrixWorld),F.setFromMatrixPosition(pe),n.setXYZ(t+1,F.x,F.y,F.z);n.needsUpdate=!0,c.object.updateMatrixWorld()}}hideHelpers(){[this.helpers.points,this.helpers.lines].forEach(n=>{n.bones=[],n.object&&(this.scene.remove(n.object),n.object.geometry.dispose(),n.object.material.dispose(),n.object=null)}),c=this.helpers.excludes,c.objects.forEach((n,e)=>{n&&(c.bones[e].remove(n),n.geometry.dispose(),n.material.dispose())}),c.bones=[],c.deltaLocals=[],c.radii=[],c.objects=[],this.helpers.isActive=!1}start(){this.data.length&&(this.running=!0,this.timerMs=0,this.showHelpers())}stop(){this.running=!1,this.hideHelpers();for(let n=0,e=this.data.length;n<e;n++){const t=this.data[n];t.bone.position.copy(t.vBasis),t.boneParent.quaternion.copy(t.qBasis)}}dispose(){this.stop(),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.timerMs=0}}class et{constructor(){this.rules={A:["[A] =aa"," [ARE] =aa RR"," [AR]O=aa RR","[AR]#=E RR"," ^[AS]#=E SS","[A]WA=aa","[AW]=aa"," :[ANY]=E nn I","[A]^+#=E","#:[ALLY]=aa nn I"," [AL]#=aa nn","[AGAIN]=aa kk E nn","#:[AG]E=I kk","[A]^+:#=aa",":[A]^+ =E","[A]^%=E"," [ARR]=aa RR","[ARR]=aa RR"," :[AR] =aa RR","[AR] =E","[AR]=aa RR","[AIR]=E RR","[AI]=E","[AY]=E","[AU]=aa","#:[AL] =aa nn","#:[ALS] =aa nn SS","[ALK]=aa kk","[AL]^=aa nn"," :[ABLE]=E PP aa nn","[ABLE]=aa PP aa nn","[ANG]+=E nn kk","[A]=aa"],B:[" [BE]^#=PP I","[BEING]=PP I I nn"," [BOTH] =PP O TH"," [BUS]#=PP I SS","[BUIL]=PP I nn","[B]=PP"],C:[" [CH]^=kk","^E[CH]=kk","[CH]=CH"," S[CI]#=SS aa","[CI]A=SS","[CI]O=SS","[CI]EN=SS","[C]+=SS","[CK]=kk","[COM]%=kk aa PP","[C]=kk"],D:["#:[DED] =DD I DD",".E[D] =DD","#^:E[D] =DD"," [DE]^#=DD I"," [DO] =DD U"," [DOES]=DD aa SS"," [DOING]=DD U I nn"," [DOW]=DD aa","[DU]A=kk U","[D]=DD"],E:["#:[E] =","'^:[E] ="," :[E] =I","#[ED] =DD","#:[E]D =","[EV]ER=E FF","[E]^%=I","[ERI]#=I RR I","[ERI]=E RR I","#:[ER]#=E","[ER]#=E RR","[ER]=E"," [EVEN]=I FF E nn","#:[E]W=","@[EW]=U","[EW]=I U","[E]O=I","#:&[ES] =I SS","#:[E]S =","#:[ELY] =nn I","#:[EMENT]=PP E nn DD","[EFUL]=FF U nn","[EE]=I","[EARN]=E nn"," [EAR]^=E","[EAD]=E DD","#:[EA] =I aa","[EA]SU=E","[EA]=I","[EIGH]=E","[EI]=I"," [EYE]=aa","[EY]=I","[EU]=I U","[E]=E"],F:["[FUL]=FF U nn","[F]=FF"],G:["[GIV]=kk I FF"," [G]I^=kk","[GE]T=kk E","SU[GGES]=kk kk E SS","[GG]=kk"," B#[G]=kk","[G]+=kk","[GREAT]=kk RR E DD","#[GH]=","[G]=kk"],H:[" [HAV]=I aa FF"," [HERE]=I I RR"," [HOUR]=aa EE","[HOW]=I aa","[H]#=I","[H]="],I:[" [IN]=I nn"," [I] =aa","[IN]D=aa nn","[IER]=I E","#:R[IED] =I DD","[IED] =aa DD","[IEN]=I E nn","[IE]T=aa E"," :[I]%=aa","[I]%=I","[IE]=I","[I]^+:#=I","[IR]#=aa RR","[IZ]%=aa SS","[IS]%=aa SS","[I]D%=aa","+^[I]^+=I","[I]T%=aa","#^:[I]^+=I","[I]^+=aa","[IR]=E","[IGH]=aa","[ILD]=aa nn DD","[IGN] =aa nn","[IGN]^=aa nn","[IGN]%=aa nn","[IQUE]=I kk","[I]=I"],J:["[J]=kk"],K:[" [K]N=","[K]=kk"],L:["[LO]C#=nn O","L[L]=","#^:[L]%=aa nn","[LEAD]=nn I DD","[L]=nn"],M:["[MOV]=PP U FF","[M]=PP"],N:["E[NG]+=nn kk","[NG]R=nn kk","[NG]#=nn kk","[NGL]%=nn kk aa nn","[NG]=nn","[NK]=nn kk"," [NOW] =nn aa","[N]=nn"],O:["[OF] =aa FF","[OROUGH]=E O","#:[OR] =E","#:[ORS] =E SS","[OR]=aa RR"," [ONE]=FF aa nn","[OW]=O"," [OVER]=O FF E","[OV]=aa FF","[O]^%=O","[O]^EN=O","[O]^I#=O","[OL]D=O nn","[OUGHT]=aa DD","[OUGH]=aa FF"," [OU]=aa","H[OU]S#=aa","[OUS]=aa SS","[OUR]=aa RR","[OULD]=U DD","^[OU]^L=aa","[OUP]=U OO","[OU]=aa","[OY]=O","[OING]=O I nn","[OI]=O","[OOR]=aa RR","[OOK]=U kk","[OOD]=U DD","[OO]=U","[O]E=O","[O] =O","[OA]=O"," [ONLY]=O nn nn I"," [ONCE]=FF aa nn SS","[ON'T]=O nn DD","C[O]N=aa","[O]NG=aa"," ^:[O]N=aa","I[ON]=aa nn","#:[ON] =aa nn","#^[ON]=aa nn","[O]ST =O","[OF]^=aa FF","[OTHER]=aa TH E","[OSS] =aa SS","#^:[OM]=aa PP","[O]=aa"],P:["[PH]=FF","[PEOP]=PP I PP","[POW]=PP aa","[PUT] =PP U DD","[P]=PP"],Q:["[QUAR]=kk FF aa RR","[QU]=kk FF","[Q]=kk"],R:[" [RE]^#=RR I","[R]=RR"],S:["[SH]=SS","#[SION]=SS aa nn","[SOME]=SS aa PP","#[SUR]#=SS E","[SUR]#=SS E","#[SU]#=SS U","#[SSU]#=SS U","#[SED] =SS DD","#[S]#=SS","[SAID]=SS E DD","^[SION]=SS aa nn","[S]S=",".[S] =SS","#:.E[S] =SS","#^:##[S] =SS","#^:#[S] =SS","U[S] =SS"," :#[S] =SS"," [SCH]=SS kk","[S]C+=","#[SM]=SS PP","#[SN]'=SS aa nn","[S]=SS"],T:[" [THE] =TH aa","[TO] =DD U","[THAT] =TH aa DD"," [THIS] =TH I SS"," [THEY]=TH E"," [THERE]=TH E RR","[THER]=TH E","[THEIR]=TH E RR"," [THAN] =TH aa nn"," [THEM] =TH E PP","[THESE] =TH I SS"," [THEN]=TH E nn","[THROUGH]=TH RR U","[THOSE]=TH O SS","[THOUGH] =TH O"," [THUS]=TH aa SS","[TH]=TH","#:[TED] =DD I DD","S[TI]#N=CH","[TI]O=SS","[TI]A=SS","[TIEN]=SS aa nn","[TUR]#=CH E","[TU]A=CH U"," [TWO]=DD U","[T]=DD"],U:[" [UN]I=I U nn"," [UN]=aa nn"," [UPON]=aa PP aa nn","@[UR]#=U RR","[UR]#=I U RR","[UR]=E","[U]^ =aa","[U]^^=aa","[UY]=aa"," G[U]#=","G[U]%=","G[U]#=FF","#N[U]=I U","@[U]=I","[U]=I U"],V:["[VIEW]=FF I U","[V]=FF"],W:[" [WERE]=FF E","[WA]S=FF aa","[WA]T=FF aa","[WHERE]=FF E RR","[WHAT]=FF aa DD","[WHOL]=I O nn","[WHO]=I U","[WH]=FF","[WAR]=FF aa RR","[WOR]^=FF E","[WR]=RR","[W]=FF"],X:[" [X]=SS","[X]=kk SS"],Y:["[YOUNG]=I aa nn"," [YOU]=I U"," [YES]=I E SS"," [Y]=I","#^:[Y] =I","#^:[Y]I=I"," :[Y] =aa"," :[Y]#=aa"," :[Y]^+:#=I"," :[Y]^#=I","[Y]=I"],Z:["[Z]=SS"]};const n={"#":"[AEIOUY]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY)","&":"(?:[SCGZXJ]|CH|SH)","@":"(?:[TSRDLZNJ]|TH|CH|SH)","^":"[BCDFGHJKLMNPQRSTVWXZ]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXZ]*"," ":"\\b"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d),u.length&&u.split(" ").forEach(y=>{a.visemes.push(y)}),a})}),this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,TH:1,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5},this.digits=["oh","one","two","three","four","five","six","seven","eight","nine"],this.ones=["","one","two","three","four","five","six","seven","eight","nine"],this.tens=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],this.teens=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],this.decades={20:"twenties",30:"thirties",40:"forties",50:"fifties",60:"sixties",70:"seventies",80:"eighties",90:"nineties"},this.ordinals={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",6:"sixth",7:"seventh",8:"eighth",9:"ninth",10:"tenth",11:"eleventh",12:"twelfth",13:"thirteenth",14:"fourteenth",15:"fifteenth",16:"sixteenth",17:"seventeeth",18:"eighteenth",19:"nineteenth",20:"twentieth",30:"thirtieth",40:"fortieth",50:"fiftieth",60:"sixtieth",70:"seventieth",80:"eightieth",90:"ninetieth"},this.symbols={"%":"percent","€":"euros","&":"and","+":"plus",$:"dollars"},this.symbolsReg=/[%€&\+\$]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_sets_of_two(n){let e=String(n).substring(0,2),t=String(n).substring(2,4),i=this.convert_tens(e);return i+=" "+this.convert_tens(t),i}convert_millions(n){return n>=1e6?this.convert_millions(Math.floor(n/1e6))+" million "+this.convert_thousands(n%1e6):this.convert_thousands(n)}convert_thousands(n){return n>=1e3?this.convert_hundreds(Math.floor(n/1e3))+" thousand "+this.convert_hundreds(n%1e3):this.convert_hundreds(n)}convert_hundreds(n){return n>99?this.ones[Math.floor(n/100)]+" hundred "+this.convert_tens(n%100):this.convert_tens(n)}convert_tens(n){return n<10?(Number(n)!=0&&n.toString().startsWith("0")?"oh ":"")+this.ones[Number(n)]:n>=10&&n<20?this.teens[n-10]:(this.tens[Math.floor(n/10)]+" "+this.ones[n%10]).trim()}convertNumberToWords(n,e=!1){const t=parseFloat(n);if(n=="0")return"zero";if(n<0)return" minus "+this.convertNumberToWords(Math.abs(n).toString(),e).trim();if(t&&!Number.isInteger(t)){const i=t.toString().split(".");return this.convertNumberToWords(i[0],e).trim()+" point "+this.convert_digit_by_digit(i[1]).trim()}else return n.toString().startsWith("0")?this.convert_digit_by_digit(n).trim():!e&&(n<1e3&&n>99&&n%100!==0||n>1e4&&n<1e6)?this.convert_digit_by_digit(n).trim():!e&&(n>1e3&&n<2e3||n>2009&&n<3e3)?n%100!=0?this.convert_sets_of_two(n).trim():this.convert_tens(n.toString().substring(0,2)).trim()+" hundred":this.convert_millions(n).trim()}convertDecade(n){const e=parseInt(n),t=!isNaN(e)&&n.length===2,i=!isNaN(e)&&n.length>2&&e>0&&e<=3e3,s=i&&e%1e3===0?Math.floor(e/1e3):null,o=i&&!s?Math.floor(e/100):null,l=t||i?Math.floor(e%100/10)*10:null;let h=[];return s?h.push(this.convertNumberToWords(s).trim(),"thousands"):(o&&h.push(this.convertNumberToWords(o).trim()),l?h.push(this.decades[l]||this.convertNumberToWords(l).trim()+"s"):o?h.push("hundreds"):h.push(n)),h.join(" ")}convertOrdinal(n){if(this.ordinals.hasOwnProperty(n))return this.ordinals[n];const e=Math.floor(n/100),t=Math.floor(n%100/10)*10,i=n%10;let s=[];return e&&(s.push(this.convertNumberToWords(e).trim()),t||i?s.push("hundred"):s.push("hundredth")),t&&(i?s.push(this.convertNumberToWords(t).trim()):s.push(this.ordinals[t])),i&&s.push(this.ordinals[i]),s.join(" ")}preProcessText(n){let e=n.replace('/[#_*":;]/g',"");return e=e.replace(this.symbolsReg,t=>" "+this.symbols[t]+" "),/\d/.test(e)&&(e=e.replace(/\b(\d{2,4})[''']?\s?[sS](?=\s|[.,!?;:]|$)/g,(t,i)=>{const s=this.convertDecade(i);return s===i?t:s}),e=e.replace(/\b(\d+)\s*(st|nd|rd|th)(?=\s|[.,!?;:]|$)/gi,(t,i)=>this.convertOrdinal(Number(i))),e=e.replace(/\b(\w*?)(\d+)([A-Za-z]+)\b/g,(t,i,s,o)=>{const l=this.convertNumberToWords(s);return`${i}${l} ${o}`}).replace(/\b([A-Za-z]+)(\d+)(\w*?)\b/g,(t,i,s,o)=>{const l=this.convertNumberToWords(s);return`${i} ${l}${o}`}),e=e.replace(/-?(?:\d{1,3}(?:,\d{3})+|\d+)(\.\d+)?/g,(t,i)=>{let s=t,o=!1;return/,/.test(s)&&(s=s.replace(/,/g,""),o=!0),i&&(o=!0),this.convertNumberToWords(s,o)})),e=e.replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC").trim(),e}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o)for(let l=0;l<o.length;l++){const h=o[l];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(h.regex)){h.visemes.forEach(a=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===a){const d=.7*(this.visemeDurations[a]||1);e.durations[e.durations.length-1]+=d,t+=d}else{const d=this.visemeDurations[a]||1;e.visemes.push(a),e.times.push(t),e.durations.push(d),t+=d}}),e.i+=h.move;break}}else e.i++,t+=this.specialDurations[s]||0}return e}}const tt=Object.freeze(Object.defineProperty({__proto__:null,LipsyncEn:et},Symbol.toStringTag,{value:"Module"}));class nt{constructor(){this.rules={A:["[AH]=aa","[AU]=aa U","[AI]=aa I","[AE]=E","[A]H=aa","[A]U=aa U","[A]I=aa I"," [AN] =aa nn"," [AM] =aa PP","[ARR]=aa RR","[AR]=aa RR"," [ALS]=aa nn SS","[AL]=aa nn","[AUCH]=aa U kk","[ABER]=aa PP E RR","[A]=aa"],Ä:["[Ä]H=E","[ÄU]=O","[Ä]=E"],B:["[B]=PP"],C:["[CH]S=kk SS","[CH]=kk"," [CH]=kk","#[CH]=kk","[CK]=kk","[C]H=kk","[C]=kk"],D:[" [DAS] =DD aa SS"," [DEN] =DD E nn"," [DER] =DD E RR"," [DIE] =DD I"," [DU] =DD U"," [DURCH]=DD U RR kk","[D]=DD"],E:["[EI]=aa I","[EU]=O","[EH]=E"," [ER] =E RR"," [ES] =E SS"," [EIN] =aa I nn"," [EINE]=aa I nn aa","[ER]#=E","[ER]=E RR","[EN]#=aa nn","[E]=E"],F:["[F]=FF"],G:["[G]=kk"],H:[" [HAT] =I aa DD"," [HABEN]=I aa PP aa nn"," [HIER]=I I RR"," [HEUTE]=I O DD aa","[H]="],I:[" [ICH] =I kk"," [IHR] =I RR"," [IN] =I nn"," [IST] =I SS DD"," [IM] =I PP","[IE]=I","[IH]=I","[I]=I"],J:["[J]=I"],K:["[K]=kk"],L:["[L]=nn"],M:[" [MIT] =PP I DD"," [MAN] =PP aa nn"," [MEHR]=PP E RR"," [MICH]=PP I kk","[M]=PP"],N:[" [NICHT]=nn I kk DD"," [NUR] =nn U RR"," [NACH]=nn aa kk"," [NOCH]=nn aa kk","[NG]=nn kk","[N]=nn"],O:["[OO]=U","[OH]=O","[OU]=aa U"," [ODER]=O DD E RR"," [OHNE]=O nn aa","[Ö]=E","[O]=aa"],Ö:["[ÖH]=E","[Ö]=E"],P:["[PF]=FF FF","[PH]=FF","[P]=PP"],Q:["[QU]=kk FF","[Q]=kk"],R:["[R]=RR"],S:["[SCH]=SS","[SP]=SS PP","[ST]=SS DD","[SS]=SS","[S]=SS"],ß:["[ß]=SS"],T:["[TZ]=DD SS","[TH]=DD","[T]=DD"],U:[" [UND] =U nn DD"," [UM] =U PP"," [UNTER]=U nn DD E RR"," [UNS] =U nn SS","[UH]=U","[ÜH]=I U","[Ü]=I U","[U]=U"],Ü:["[ÜH]=I U","[Ü]=I U"],V:[" [VON] =FF aa nn"," [VOR] =FF aa RR"," [VIEL]=FF I nn","[V]=FF"],W:[" [WAS] =FF aa SS"," [WIR] =FF I RR"," [WIE] =FF I"," [WENN]=FF E nn"," [WILL]=FF I nn"," [WO] =FF aa"," [WIEDER]=FF I DD E RR","[W]=FF"],X:["[X]=kk SS"],Y:["[Y]=I"],Z:[" [ZU] =DD SS U"," [ZUM] =DD SS U PP"," [ZUR] =DD SS U RR"," [ZEIT]=DD SS aa I DD","[Z]=DD SS"]};const n={"#":"[AEIOUÄÖÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY|EN|TE|ST)","&":"(?:[SCGZXJ]|CH|SCH|TZ)","@":"(?:[TSRDLZNJ]|TH|CH|SCH)","^":"[BCDFGHJKLMNPQRSTVWXYZß]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXYZß]*"," ":"\\b"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d),u.length&&u.split(" ").forEach(y=>{a.visemes.push(y)}),a})}),this.visemeDurations={aa:1,E:.85,I:.9,O:1.05,U:1,PP:1.15,SS:1.2,TH:1,DD:1.1,FF:1.05,kk:1.25,nn:.85,RR:.9,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5,".":4,"!":3,"?":3},this.digits=["null","eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.ones=["","ein","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.tens=["","","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"],this.teens=["zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn"],this.symbols={"%":"prozent","€":"euro","&":"und","+":"plus",$:"dollar","=":"gleich","@":"at","#":"hashtag"},this.symbolsReg=/[%€&\+\$=@#]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_millions(n){if(n>=1e6){const e=Math.floor(n/1e6),t=n%1e6;let i=this.convert_thousands(e);return i+=e===1?" million ":" millionen ",t>0&&(i+=this.convert_thousands(t)),i}else return this.convert_thousands(n)}convert_thousands(n){if(n>=1e3){const e=Math.floor(n/1e3),t=n%1e3;let i="";return e===1?i="eintausend":i=this.convert_hundreds(e)+"tausend",t>0&&(i+=this.convert_hundreds(t)),i}else return this.convert_hundreds(n)}convert_hundreds(n){if(n>99){const e=Math.floor(n/100),t=n%100;let i="";return e===1?i="einhundert":i=this.ones[e]+"hundert",t>0&&(i+=this.convert_tens(t)),i}else return this.convert_tens(n)}convert_tens(n){if(n<10)return this.ones[Number(n)]||"";if(n>=10&&n<20)return this.teens[n-10];{const e=Math.floor(n/10),t=n%10;return t===0?this.tens[e]:this.ones[t]+"und"+this.tens[e]}}convertNumberToWords(n){const e=String(n);return n=="0"?"null":e.startsWith("0")?this.convert_digit_by_digit(n):e.length===4&&(n<1e3||n>2100)?this.convert_digit_by_digit(n):this.convert_millions(Number(n))}preProcessText(n){return n.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)\.(\d)/g,"$1 komma $2").replace(/(\d),(\d)/g,"$1 komma $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").toLowerCase().trim()}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o){let l=!1;for(let h=0;h<o.length;h++){const r=o[h];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(r.regex)){r.visemes.forEach(d=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===d){const p=.7*(this.visemeDurations[d]||1);e.durations[e.durations.length-1]+=p,t+=p}else{const p=this.visemeDurations[d]||1;e.visemes.push(d),e.times.push(t),e.durations.push(p),t+=p}}),e.i+=r.move,l=!0;break}}l||(e.i++,t+=this.specialDurations[s]||0)}else e.i++,t+=this.specialDurations[s]||0}return e}}const it=Object.freeze(Object.defineProperty({__proto__:null,LipsyncDe:nt},Symbol.toStringTag,{value:"Module"}));class ot{constructor(){this.rules={A:["[AN]C=aa nn","[AN]G=aa nn","[AN]T=aa nn","[AN]D=aa nn","[AN] =aa nn","[AN]$=aa nn","[AM]P=aa nn","[AM]B=aa nn","[AM] =aa nn","[AM]$=aa nn","[AI]N=E nn","[AIM]=E nn","[AIN]=E nn","[AU]=O","[AUX]=O","[AUT]=O","[AI]=E","[AY]=E","[A]=aa"],À:["[À]=aa"],Â:["[Â]=aa"],B:[" [B] =PP","[BB]=PP","[B]=PP"],C:["[C]E=SS","[C]I=SS","[C]Y=SS","[C]È=SS","[C]É=SS","[C]Ê=SS","[CH]=SS","[C]A=kk","[C]O=kk","[C]U=kk","[C]L=kk","[C]R=kk","[CK]=kk","[C]=kk"],Ç:["[Ç]=SS"],D:["[D]=DD"],E:["[EN]C=aa nn","[EN]T=aa nn","[EN]D=aa nn","[EN] =aa nn","[EN]$=aa nn","[EM]P=aa nn","[EM]B=aa nn","[EM] =aa nn","[EM]$=aa nn","[EAU]=O","[EAU]X=O","[EU]=U","[EUX]=U","[EUR]=U RR","[EI]=E","[EIN]=E nn","[ER] =E","[ER]$=E","[EZ] =E","[EZ]$=E","[ED] =E","[ED]$=E"," [E] =","[E] =","[E]$=","[E]S =","[E]S$=","[E]NT =","[E]NT$=","[È]=E","[É]=E","[Ê]=E","[Ë]=E","[E]=E"],È:["[È]=E"],É:["[É]=E"],Ê:["[Ê]=E"],Ë:["[Ë]=E"],F:["[FF]=FF","[F]=FF","[PH]=FF"],G:["[G]E=SS","[G]I=SS","[G]Y=SS","[G]È=SS","[G]É=SS","[G]Ê=SS","[GN]=nn I","[GN]E=nn","[GN]A=nn aa","[GN]O=nn O","[GU]E=kk","[GU]I=kk","[GU]A=kk FF aa","[GU]O=kk FF O","[G]A=kk","[G]O=kk","[G]U=kk","[G]L=kk","[G]R=kk","[GG]=kk","[G]=kk"],H:["[H]="],I:["[IN]C=E nn","[IN]T=E nn","[IN]D=E nn","[IN] =E nn","[IN]$=E nn","[IM]P=E nn","[IM]B=E nn","[IM] =E nn","[IM]$=E nn","[IEN]=I E nn","[IER]=I E","[IEU]=I U","[IEZ]=I E","[ILL]E=I","[ILLE]=I","[ILL]=I","[Î]=I","[Ï]=I","[I]=I"],Î:["[Î]=I"],Ï:["[Ï]=I"],J:["[J]=SS"],K:["[K]=kk"],L:["[LL]E=","[LLE]=","[LL]A=I aa","[LL]O=I O","[LL]U=I U","[LL]I=I","[LL]=I","[L]=nn"],M:["[MM]=PP","[M]=PP"],N:["[NN]=nn","[N]=nn"],O:["[ON]C=O nn","[ON]T=O nn","[ON]D=O nn","[ON] =O nn","[ON]$=O nn","[OM]P=O nn","[OM]B=O nn","[OM] =O nn","[OM]$=O nn","[OI]N=FF E nn","[OI]G=FF aa","[OI]S=FF aa","[OI]T=FF aa","[OI]X=FF aa","[OI]=FF aa","[OU]=U","[OÙ]=U","[OÛ]=U","[OEU]=U","[OEUR]=U RR","[OUGH]=U FF","[OUGH]T=U","[Ô]=O","[O]=O"],Ô:["[Ô]=O"],Ù:["[Ù]=U"],Û:["[Û]=U"],P:["[PH]=FF","[PP]=PP","[P]=PP"],Q:["[QU]=kk","[Q]=kk"],R:["[RR]=RR","[R]=RR"],S:["#[S]#=SS"," [S]=SS","[SS]=SS","[S] =","[S]$=","[SC]E=SS","[SC]I=SS","[SC]Y=SS","[S]=SS"],T:["[TI]A=SS I aa","[TI]E=SS I E","[TI]O=SS I O","[TI]ON=SS I O nn","[TH]=DD","[TT]=DD","[T] =","[T]$=","[T]=DD"],U:["[UN]C=U nn","[UN]T=U nn","[UN]D=U nn","[UN] =U nn","[UN]$=U nn","[UM]=U nn","[UE]=I","[UEI]=I E","[UEIL]=I I","[UILL]=I","[Ù]=U","[Û]=U","[Ü]=I U","[U]=I U"],Ü:["[Ü]=I U"],V:["[V]=FF"],W:["[W]=FF"],X:["[X] =","[X]$=","#[X]#=kk SS"," [X]=kk SS","[X]=kk SS"],Y:["[Y]=I"," [Y]=I","[YE]=I E","[YA]=I aa","[YO]=I O","[YU]=I U"],Z:["[Z]=SS"]};const n={"#":"[AEIOUYÀÂÈÉÊËÎÏÔÙÛÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ÉS|ÈS|ÊS|ENT|MENT|TION|SION)","&":"(?:[SCGZXJ]|CH|SH|GN)","@":"(?:[TSRDLZNJ]|TH|CH|SH|GN)","^":"[BCDFGHJKLMNPQRSTVWXZÇ]+","+":"[EIYÈÉÊËÎÏ]",":":"[BCDFGHJKLMNPQRSTVWXZÇ]*"," ":"\\b",$:"$"};Object.keys(this.rules).forEach(e=>{this.rules[e]=this.rules[e].map(t=>{const i=t.indexOf("["),s=t.indexOf("]"),o=t.indexOf("="),l=t.substring(0,i),h=t.substring(i+1,s),r=t.substring(s+1,o),u=t.substring(o+1),a={regex:"",move:0,visemes:[]};let d="";d+=[...l].map(y=>n[y]||y).join("");const p=[...h];return p[0]=p[0].toLowerCase(),d+=p.join(""),a.move=p.length,d+=[...r].map(y=>n[y]||y).join(""),a.regex=new RegExp(d,"i"),u.length&&u.split(" ").forEach(y=>{y&&a.visemes.push(y)}),a})}),this.visemeDurations={aa:1,E:.95,I:.9,O:1.05,U:.95,PP:1.1,SS:1.25,TH:1,DD:1.05,FF:1,kk:1.2,nn:.88,RR:1.15,sil:1},this.specialDurations={" ":1,",":2.5,".":3.5,";":2.8,":":2.2,"!":3.2,"?":3.2,"-":.8,"'":.3,'"':.3,"(":1.5,")":1.5},this.digits=["zéro","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.ones=["","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.teens=["dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf"],this.tens=["","dix","vingt","trente","quarante","cinquante","soixante","soixante-dix","quatre-vingts","quatre-vingt-dix"],this.symbols={"%":"pourcent","€":"euros","&":"et","+":"plus",$:"dollars","=":"égale","@":"arobase","#":"dièse","°":"degrés"},this.symbolsReg=/[%€&\+\$=@#°]/g}convert_digit_by_digit(n){n=String(n).split("");let e="";for(let t=0;t<n.length;t++)e+=this.digits[n[t]]+" ";return e=e.substring(0,e.length-1),e}convert_tens(n){if(n<10)return this.ones[n]||"";if(n>=10&&n<20)return this.teens[n-10];if(n>=70&&n<80){const e=n-60;return e===11?"soixante et onze":"soixante-"+this.teens[e-10]}else if(n>=90){const e=n-80;return e===11?"quatre-vingt-onze":"quatre-vingt-"+this.teens[e-10]}else{const e=Math.floor(n/10),t=n%10;return e===8&&t===0?"quatre-vingts":e===8?"quatre-vingt-"+this.ones[t]:(e===2||e===3||e===4||e===5||e===6)&&t===1?this.tens[e]+" et un":t===0?this.tens[e]:this.tens[e]+"-"+this.ones[t]}}convert_hundreds(n){if(n>=100){const e=Math.floor(n/100),t=n%100;let i="";return e===1?i="cent":(i=this.ones[e]+" cent",t===0&&(i+="s")),t>0&&(i+=" "+this.convert_tens(t)),i}else return this.convert_tens(n)}convert_thousands(n){if(n>=1e3){const e=Math.floor(n/1e3),t=n%1e3;let i="";return e===1?i="mille":i=this.convert_hundreds(e)+" mille",t>0&&(i+=" "+this.convert_hundreds(t)),i}else return this.convert_hundreds(n)}convert_millions(n){if(n>=1e6){const e=Math.floor(n/1e6),t=n%1e6;let i="";return e===1?i="un million":i=this.convert_hundreds(e)+" millions",t>0&&(i+=" "+this.convert_thousands(t)),i}else return this.convert_thousands(n)}convertNumberToWords(n){const e=String(n);return n==="0"||n===0?"zéro":e.startsWith("0")?this.convert_digit_by_digit(n):this.convert_millions(Number(n))}preProcessText(n){return n.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)[,.](\d)/g,"$1 virgule $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").replace(/'/g,"'").trim()}wordsToVisemes(n){let e={words:n.toUpperCase(),visemes:[],times:[],durations:[],i:0},t=0;const i=[...e.words];for(;e.i<i.length;){const s=i[e.i],o=this.rules[s];if(o){let l=!1;for(let h=0;h<o.length;h++){const r=o[h];if((e.words.substring(0,e.i)+s.toLowerCase()+e.words.substring(e.i+1)).match(r.regex)){r.visemes.forEach(d=>{if(e.visemes.length&&e.visemes[e.visemes.length-1]===d){const p=.7*(this.visemeDurations[d]||1);e.durations[e.durations.length-1]+=p,t+=p}else{const p=this.visemeDurations[d]||1;e.visemes.push(d),e.times.push(t),e.durations.push(p),t+=p}}),e.i+=r.move,l=!0;break}}l||(e.i++,t+=this.specialDurations[s]||0)}else e.i++,t+=this.specialDurations[s]||0}return e}}const st=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFr:ot},Symbol.toStringTag,{value:"Module"}));class at{constructor(){this.visemes={a:"aa",e:"E",i:"I",o:"O",u:"U",y:"U",ä:"aa",ö:"O",å:"O",b:"PP",c:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS"},this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5},this.numbers=["nolla","yksi","kaksi","kolme","neljä","viisi","kuusi","seitsemän","kahdeksan","yhdeksän","kymmenen","yksitoista","kaksitoista","kolmetoista","neljätoista","viisitoista","kuusitoista","seitsemäntoista","kahdeksantoista","yhdeksäntoista"],this.symbols={"%":"prosenttia","€":"euroa","&":"ja","+":"plus",$:"dollaria"},this.symbolsReg=/[%€&\+\$]/g}numberToFinnishWords(n){const e=[];let t=parseFloat(n);if(t===void 0)return n;let i=(s,o,l,h,r)=>{if(s<o)return s;const u=Math.floor(s/o);return e.push(l+(u===1?h:this.numberToFinnishWords(u.toString())+r)),s-u*o};if(t<0&&(e.push("miinus "),t=Math.abs(t)),t=i(t,1e9," ","miljardi"," miljardia"),t=i(t,1e6," ","miljoona"," miljoonaa"),t=i(t,1e3,"","tuhat","tuhatta"),t=i(t,100," ","sata","sataa"),t>20&&(t=i(t,10,"","","kymmentä")),t>=1){let s=Math.floor(t);e.push(this.numbers[s]),t-=s}if(t>=0&&Math.abs(parseFloat(n))<1&&e.push("nolla"),t>0){let s=n.split(".");if(s.length>1){e.push(" pilkku");let o=[...s[s.length-1]];for(let l=0;l<o.length;l++)e.push(" "+this.numbers[o[l]])}}return e.join("").trim()}preProcessText(n){return n.replace(/[#_*\'\":;]/g,"").replace(this.symbolsReg,e=>" "+this.symbols[e]+" ").replace(/(\d)\,(\d)/g,"$1 pilkku $2").replace(/\d+/g,this.numberToFinnishWords.bind(this)).replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0307\u0309\u030b-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(n){let e={words:n,visemes:[],times:[],durations:[]},t=0;const i=[...n];for(let s=0;s<i.length;s++){const o=this.visemes[i[s].toLowerCase()];if(o)if(e.visemes.length&&e.visemes[e.visemes.length-1]===o){const l=.7*(this.visemeDurations[o]||1);e.durations[e.durations.length-1]+=l,t+=l}else{const l=this.visemeDurations[o]||1;e.visemes.push(o),e.times.push(t),e.durations.push(l),t+=l}else t+=this.specialDurations[i[s]]||0}return e}}const rt=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFi:at},Symbol.toStringTag,{value:"Module"}));class lt{constructor(){this.visemes={a:"aa",ą:"O",e:"E",ę:"E",ė:"E",i:"I",į:"I",o:"O",u:"U",ū:"U",ų:"U",y:"I",b:"PP",c:"SS",č:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",š:"CH",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS",ž:"SS"},this.durations={a:.95,ą:1.5,e:.9,ę:1.5,ė:1.5,i:.92,į:1.5,o:.96,u:.95,ū:1.5,ų:1.5,y:1.5,b:1.08,c:1.23,d:1.05,f:1,g:1.21,h:1.21,j:.92,k:1.21,l:.88,m:1.08,n:.88,p:1.08,q:1.21,r:.88,s:1.23,š:1.23,t:1.05,v:1,w:1,x:1.23,z:1.23,ž:1.23},this.pauses={" ":1,",":3,"-":.5},this.numbers=["nulis","vienas","du","trys","keturi","penki","šeši","septyni","aštuoni","devyni","dešimt","vienuolika","dvylika","trylika","keturiolika","penkiolika","šešiolika","septyniolika","aštuoniolika","devyniolika"],this.tens=[this.numbers[0],this.numbers[10],"dvidešimt","trisdešimt","keturiasdešimt","penkiasdešimt","šešiasdešimt","septyniasdešimt","aštuoniasdešimt","devyniasdešimt"]}numberToLithuanianWords(n){const e=[];let t=parseFloat(n);if(t===void 0)return n;let i=(s,o,l,h,r)=>{if(s<o)return s;const u=Math.floor(s/o);return u===1?e.push(this.numbers[1]):e.push(this.numberToLithuanianWords(u.toString())),u%10===1?e.push(l):u%10===0||u%100>10&&u%100<20?e.push(r):e.push(h),s-u*o};t<0&&(e.push("minus"),t=Math.abs(t)),t=i(t,1e9,"milijardas","milijardai","milijardų"),t=i(t,1e6,"milijonas","milijonai","milijonų"),t=i(t,1e3,"tūkstantis","tūkstančiai","tūkstančių"),t=i(t,100,"šimtas","šimtai","šimtų");for(let s=this.tens.length-1;s>=1;s--)if(t>=10*s){e.push(this.tens[s]),t=t-10*s;break}if(t>=1){let s=Math.floor(t);e.push(this.numbers[s]),t-=s}if(t>=0&&Math.abs(parseFloat(n))<1&&e.push(this.numbers[0]),t>0){let s=n.split(".");if(s.length>1){e.push("kablelis");let o=[...s[s.length-1]];for(let l=0;l<o.length;l++)e.push(this.numbers[o[l]])}}return e.join(" ").trim()}preProcessText(n){return n.replace(`/[#_*'":;]/g`,"").replaceAll("0 %","0 procentų ").replaceAll("1 %","1 procentas ").replaceAll("%"," procentai ").replaceAll("0 €","0 eurų ").replaceAll("1 €","1 euras ").replaceAll("€"," eurai ").replaceAll("0 $","0 dolerių ").replaceAll("1 $","1 doleris ").replaceAll("$"," doleriai ").replaceAll("&"," ir ").replaceAll("+"," pliusas ").replace(/(\d)\,(\d)/g,"$1 kablelis $2").replace(/\d+/g,this.numberToLithuanianWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0303\u0305\u0306\u0308-\u0327\u0329-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(n){let e={words:n,visemes:[],times:[],durations:[]},t=0;const i=[...n];for(let s=0;s<i.length;s++){const o=i[s].toLowerCase(),l=this.visemes[o];if(l)if(e.visemes.length&&e.visemes[e.visemes.length-1]===l){const h=.7*(this.durations[o]||1);e.durations[e.durations.length-1]+=h,t+=h}else{const h=this.durations[o]||1;e.visemes.push(l),e.times.push(t),e.durations.push(h),t+=h}else t+=this.pauses[i[s]]||0}return e}}const ut=Object.freeze(Object.defineProperty({__proto__:null,LipsyncLt:lt},Symbol.toStringTag,{value:"Module"})),ht=new URL("data:text/javascript;base64,Y2xhc3MgUGxheWJhY2tXb3JrbGV0IGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBzdGF0aWMgRlNNID0gewogICAgSURMRTogMCwKICAgIFBMQVlJTkc6IDEsCiAgfTsKCiAgY29uc3RydWN0b3Iob3B0aW9ucykgewogICAgc3VwZXIoKTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSB0aGlzLmhhbmRsZU1lc3NhZ2UuYmluZCh0aGlzKTsKCiAgICB0aGlzLl9zYW1wbGVSYXRlID0gb3B0aW9ucz8ucHJvY2Vzc29yT3B0aW9ucz8uc2FtcGxlUmF0ZSB8fCBzYW1wbGVSYXRlOwogICAgdGhpcy5fc2NhbGUgPSAxIC8gMzI3Njg7IC8vIFBDTTE2IC0+IGZsb2F0CgogICAgLy8gU2lsZW5jZSBkZXRlY3Rpb24gdGhyZXNob2xkICgxIHNlY29uZCkgYXMgYSBmYWxsYmFjayBzYWZldHkgbmV0CiAgICBjb25zdCBzaWxlbmNlRHVyYXRpb25TZWNvbmRzID0gMS4wOwogICAgdGhpcy5fc2lsZW5jZVRocmVzaG9sZEJsb2NrcyA9IE1hdGguY2VpbCgodGhpcy5fc2FtcGxlUmF0ZSAqIHNpbGVuY2VEdXJhdGlvblNlY29uZHMpIC8gMTI4KTsKCiAgICAvLyBNZXRyaWNzIGNvbmZpZ3VyYXRpb24gdmlhIG9wdGlvbnMKICAgIGNvbnN0IG1ldHJpY3NDZmcgPSBvcHRpb25zPy5wcm9jZXNzb3JPcHRpb25zPy5tZXRyaWNzIHx8IHt9OwogICAgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSBtZXRyaWNzQ2ZnLmVuYWJsZWQgIT09IGZhbHNlOwogICAgY29uc3QgaW50ZXJ2YWxIeiA9ICh0eXBlb2YgbWV0cmljc0NmZy5pbnRlcnZhbEh6ID09PSAibnVtYmVyIiAmJiBtZXRyaWNzQ2ZnLmludGVydmFsSHogPiAwKQogICAgICA/IG1ldHJpY3NDZmcuaW50ZXJ2YWxIeiA6IDI7CiAgICAvLyBNZXRyaWNzIHN0YXRlIChsb3ctb3ZlcmhlYWQpCiAgICB0aGlzLl9mcmFtZXNQcm9jZXNzZWQgPSAwOwogICAgdGhpcy5fdW5kZXJydW5CbG9ja3MgPSAwOwogICAgdGhpcy5fbWF4UXVldWVTYW1wbGVzID0gMDsKICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSAwOwogICAgLy8gQ29udmVydCB0byBmcmFtZXMgYmV0d2VlbiByZXBvcnRzCiAgICB0aGlzLl9tZXRyaWNzSW50ZXJ2YWxGcmFtZXMgPSBNYXRoLm1heCgxMjgsIE1hdGgucm91bmQodGhpcy5fc2FtcGxlUmF0ZSAvIGludGVydmFsSHopKTsKCiAgICB0aGlzLnJlc2V0KCk7CiAgfQoKICAvKioKICAgKiBSZXNldHMgdGhlIHdvcmtsZXQgdG8gaXRzIGluaXRpYWwgSURMRSBzdGF0ZS4KICAgKi8KICByZXNldCgpIHsKICAgIHRoaXMuX2J1ZmZlclF1ZXVlID0gW107CiAgICB0aGlzLl9jdXJyZW50Q2h1bmsgPSBudWxsOwogICAgdGhpcy5fY3VycmVudENodW5rT2Zmc2V0ID0gMDsKICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFOwoKICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IGZhbHNlOwogICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsKICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IGZhbHNlOwogICAgLy8gUmVzZXQgbWF4IHF1ZXVlIHRyYWNrZXIgb25seSB3aGVuIGdvaW5nIGlkbGUKICAgIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IDA7CiAgfQoKICBoYW5kbGVNZXNzYWdlKGV2ZW50KSB7CiAgICBjb25zdCB7IHR5cGUsIGRhdGEgfSA9IGV2ZW50LmRhdGE7CgogICAgLy8gSU5URVJSVVBUOiBUaGUgbWFpbiB0aHJlYWQgd2FudHMgdG8gc3RvcCBpbW1lZGlhdGVseS4KICAgIGlmICh0eXBlID09PSAic3RvcCIpIHsKICAgICAgdGhpcy5yZXNldCgpOwogICAgICAvLyBTZW5kIGZpbmFsIG1ldHJpY3Mgc2hvd2luZyBjbGVhcmVkIHN0YXRlCiAgICAgIGlmICh0aGlzLl9tZXRyaWNzRW5hYmxlZCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICB0eXBlOiAibWV0cmljcyIsCiAgICAgICAgICAgIGRhdGE6IHsKICAgICAgICAgICAgICBzdGF0ZTogUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFLAogICAgICAgICAgICAgIHF1ZXVlZFNhbXBsZXM6IDAsCiAgICAgICAgICAgICAgcXVldWVkTXM6IDAsCiAgICAgICAgICAgICAgbWF4UXVldWVkTXM6IE1hdGgucm91bmQoKHRoaXMuX21heFF1ZXVlU2FtcGxlcyAvIHRoaXMuX3NhbXBsZVJhdGUpICogMTAwMCksCiAgICAgICAgICAgICAgdW5kZXJydW5CbG9ja3M6IHRoaXMuX3VuZGVycnVuQmxvY2tzLAogICAgICAgICAgICAgIGZyYW1lc1Byb2Nlc3NlZDogdGhpcy5fZnJhbWVzUHJvY2Vzc2VkCiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgIH0gY2F0Y2ggKF8pIHsgfQogICAgICB9CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBNYWluIHRocmVhZCBoYXMgc2lnbmFsZWQgdGhhdCBubyBtb3JlIGF1ZGlvIGNodW5rcyB3aWxsIGJlIHNlbnQgZm9yIHRoaXMgdXR0ZXJhbmNlLgogICAgaWYgKHR5cGUgPT09ICJuby1tb3JlLWRhdGEiKSB7CiAgICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IHRydWU7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBVcGRhdGUgbWV0cmljcyBjb25maWd1cmF0aW9uIGF0IHJ1bnRpbWUKICAgIGlmICh0eXBlID09PSAiY29uZmlnLW1ldHJpY3MiICYmIGRhdGEgJiYgdHlwZW9mIGRhdGEgPT09ICJvYmplY3QiKSB7CiAgICAgIGlmICgiZW5hYmxlZCIgaW4gZGF0YSkgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSAhIWRhdGEuZW5hYmxlZDsKICAgICAgaWYgKHR5cGVvZiBkYXRhLmludGVydmFsSHogPT09ICJudW1iZXIiICYmIGRhdGEuaW50ZXJ2YWxIeiA+IDApIHsKICAgICAgICBjb25zdCBpbnRlcnZhbEh6ID0gZGF0YS5pbnRlcnZhbEh6OwogICAgICAgIHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcyA9IE1hdGgubWF4KDEyOCwgTWF0aC5yb3VuZCh0aGlzLl9zYW1wbGVSYXRlIC8gaW50ZXJ2YWxIeikpOwogICAgICB9CiAgICAgIC8vIFJlc2V0IHBhY2luZyBzbyB0aGUgbmV4dCByZXBvcnQgYWxpZ25zIHdpdGggbmV3IGludGVydmFsCiAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBOZXcgYXVkaW8gZGF0YSBoYXMgYXJyaXZlZC4KICAgIGlmICh0eXBlID09PSAiYXVkaW9EYXRhIiAmJiBkYXRhIGluc3RhbmNlb2YgQXJyYXlCdWZmZXIpIHsKICAgICAgdGhpcy5fbm9Nb3JlRGF0YVJlY2VpdmVkID0gZmFsc2U7CiAgICAgIC8vIElmIHdlIHdlcmUgaWRsZSwgdGhpcyBuZXcgZGF0YSBraWNrcyBvZmYgdGhlIHBsYXliYWNrLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uSURMRSkgewogICAgICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HOwogICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7IHR5cGU6ICJwbGF5YmFjay1zdGFydGVkIiB9KTsKICAgICAgfQoKICAgICAgLy8gV2Ugb25seSBxdWV1ZSBkYXRhIGlmIHdlIGFyZSBpbiB0aGUgUExBWUlORyBzdGF0ZS4gVGhpcyBwcmV2ZW50cwogICAgICAvLyBkYXRhIGZyb20gYSBwcmV2aW91cywgaW50ZXJydXB0ZWQgc3RyZWFtIGZyb20gbGluZ2VyaW5nLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uUExBWUlORykgewogICAgICAgIC8vIFN0b3JlIGFzIEludDE2QXJyYXkgdmlldyB0byBhdm9pZCBjb25zdHJ1Y3RpbmcgaXQgaW4gcHJvY2VzcygpCiAgICAgICAgdGhpcy5fYnVmZmVyUXVldWUucHVzaChuZXcgSW50MTZBcnJheShkYXRhKSk7CiAgICAgICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsgLy8gUmVzZXQgc2lsZW5jZSBjb3VudGVyIG9uIG5ldyBkYXRhCiAgICAgIH0KICAgIH0KICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBvdXRwdXRDaGFubmVsID0gb3V0cHV0c1swXT8uWzBdOwogICAgaWYgKCFvdXRwdXRDaGFubmVsKSB7CiAgICAgIHJldHVybiB0cnVlOyAvLyBLZWVwIGFsaXZlIGV2ZW4gaWYgb3V0cHV0IGlzIHRlbXBvcmFyaWx5IGRpc2Nvbm5lY3RlZAogICAgfQoKICAgIC8vIElmIHdlIGFyZSBub3QgcGxheWluZywganVzdCBvdXRwdXQgc2lsZW5jZSBhbmQgd2FpdC4KICAgIGlmICh0aGlzLl9zdGF0ZSAhPT0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HKSB7CiAgICAgIG91dHB1dENoYW5uZWwuZmlsbCgwKTsKICAgICAgcmV0dXJuIHRydWU7IC8vIEFsd2F5cyByZXR1cm4gdHJ1ZSB0byBrZWVwIHRoZSBwcm9jZXNzb3IgYWxpdmUKICAgIH0KCiAgICAvLyBDb3JlIFBMQVlJTkcgTG9naWMKICAgIGNvbnN0IGJsb2NrU2l6ZSA9IG91dHB1dENoYW5uZWwubGVuZ3RoOwogICAgbGV0IHNhbXBsZXNDb3BpZWQgPSAwOwoKICAgIHdoaWxlIChzYW1wbGVzQ29waWVkIDwgYmxvY2tTaXplKSB7CiAgICAgIGlmICghdGhpcy5fY3VycmVudENodW5rIHx8IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCA+PSB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoKSB7CiAgICAgICAgaWYgKHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aCA+IDApIHsKICAgICAgICAgIHRoaXMuX2N1cnJlbnRDaHVuayA9IHRoaXMuX2J1ZmZlclF1ZXVlLnNoaWZ0KCk7CiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQgPSAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAvLyBCdWZmZXIgaXMgZW1wdHkuIENoZWNrIGZvciBlbmQgY29uZGl0aW9ucy4KICAgICAgICAgIGNvbnN0IGlzVGltZWRPdXQgPSB0aGlzLl9zaWxlbmNlRnJhbWVzQ291bnQgPiB0aGlzLl9zaWxlbmNlVGhyZXNob2xkQmxvY2tzOwoKICAgICAgICAgIGlmICh0aGlzLl9ub01vcmVEYXRhUmVjZWl2ZWQgfHwgaXNUaW1lZE91dCkgewogICAgICAgICAgICAvLyBFTkQgT0YgUExBWUJBQ0s6IEVpdGhlciBleHBsaWNpdGx5IHNpZ25hbGVkIG9yIHRpbWVkIG91dC4KICAgICAgICAgICAgaWYgKCF0aGlzLl9oYXNTZW50RW5kZWQpIHsKICAgICAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoeyB0eXBlOiAicGxheWJhY2stZW5kZWQiIH0pOwogICAgICAgICAgICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy8gU2VuZCBmaW5hbCBtZXRyaWNzIHNob3dpbmcgY2xlYXJlZCBzdGF0ZQogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgICAgdHlwZTogIm1ldHJpY3MiLAogICAgICAgICAgICAgICAgICBkYXRhOiB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGU6IFBsYXliYWNrV29ya2xldC5GU00uSURMRSwKICAgICAgICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzOiAwLAogICAgICAgICAgICAgICAgICAgIHF1ZXVlZE1zOiAwLAogICAgICAgICAgICAgICAgICAgIG1heFF1ZXVlZE1zOiBNYXRoLnJvdW5kKCh0aGlzLl9tYXhRdWV1ZVNhbXBsZXMgLyB0aGlzLl9zYW1wbGVSYXRlKSAqIDEwMDApLAogICAgICAgICAgICAgICAgICAgIHVuZGVycnVuQmxvY2tzOiB0aGlzLl91bmRlcnJ1bkJsb2NrcywKICAgICAgICAgICAgICAgICAgICBmcmFtZXNQcm9jZXNzZWQ6IHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZAogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICB9IGNhdGNoIChfKSB7IH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnJlc2V0KCk7IC8vIFJlc2V0IHRvIElETEUgc3RhdGUgZm9yIHJldXNlCiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIC8vIEJVRkZFUiBVTkRFUlJVTiAoTEFHKTogUGxheSBzaWxlbmNlIGFuZCB3YWl0IGZvciBtb3JlIGRhdGEuCiAgICAgICAgICAgIHRoaXMuX3NpbGVuY2VGcmFtZXNDb3VudCsrOwogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHRoaXMuX3VuZGVycnVuQmxvY2tzKys7CiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KCiAgICAgIC8vIElmIHdlIGhhdmUgYSBjaHVuayAoY291bGQgYmUgYSBuZXcgb25lIGZyb20gdGhlIGxvZ2ljIGFib3ZlKSwgcHJvY2VzcyBpdC4KICAgICAgaWYgKHRoaXMuX2N1cnJlbnRDaHVuaykgewogICAgICAgIGNvbnN0IHNhbXBsZXNUb0NvcHkgPSBNYXRoLm1pbigKICAgICAgICAgIGJsb2NrU2l6ZSAtIHNhbXBsZXNDb3BpZWQsCiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoIC0gdGhpcy5fY3VycmVudENodW5rT2Zmc2V0CiAgICAgICAgKTsKICAgICAgICAvLyBEaXJlY3RseSB3cml0ZSB0byBvdXRwdXRDaGFubmVsIHRvIGF2b2lkIGV4dHJhIGNvcHkKICAgICAgICBjb25zdCBzcmMgPSB0aGlzLl9jdXJyZW50Q2h1bms7CiAgICAgICAgY29uc3QgYmFzZVNyYyA9IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldDsKICAgICAgICBjb25zdCBiYXNlRHN0ID0gc2FtcGxlc0NvcGllZDsKICAgICAgICBjb25zdCBzY2FsZSA9IHRoaXMuX3NjYWxlOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc2FtcGxlc1RvQ29weTsgaSsrKSB7CiAgICAgICAgICBvdXRwdXRDaGFubmVsW2Jhc2VEc3QgKyBpXSA9IHNyY1tiYXNlU3JjICsgaV0gKiBzY2FsZTsKICAgICAgICB9CgogICAgICAgIHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCArPSBzYW1wbGVzVG9Db3B5OwogICAgICAgIHNhbXBsZXNDb3BpZWQgKz0gc2FtcGxlc1RvQ29weTsKICAgICAgfQogICAgfQoKICAgIC8vIFplcm8tZmlsbCB0aGUgcmVtYWluZGVyLCBpZiBhbnksIG9uY2UgcGVyIGJsb2NrCiAgICBpZiAoc2FtcGxlc0NvcGllZCA8IGJsb2NrU2l6ZSkgewogICAgICBvdXRwdXRDaGFubmVsLmZpbGwoMCwgc2FtcGxlc0NvcGllZCk7CiAgICB9CgogICAgLy8gVXBkYXRlIG1ldHJpY3MgKG9wdGlvbmFsKQogICAgaWYgKHRoaXMuX21ldHJpY3NFbmFibGVkKSB7CiAgICAgIHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZCArPSBibG9ja1NpemU7CgogICAgICAvLyBUcmFjayBxdWV1ZSBkZXB0aCBpbiBzYW1wbGVzIChhcHByb3hpbWF0ZSkKICAgICAgbGV0IHF1ZXVlZFNhbXBsZXMgPSAwOwogICAgICBpZiAodGhpcy5fY3VycmVudENodW5rKSBxdWV1ZWRTYW1wbGVzICs9IE1hdGgubWF4KDAsIHRoaXMuX2N1cnJlbnRDaHVuay5sZW5ndGggLSB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQpOwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aDsgaSsrKSBxdWV1ZWRTYW1wbGVzICs9IHRoaXMuX2J1ZmZlclF1ZXVlW2ldLmxlbmd0aDsKICAgICAgaWYgKHF1ZXVlZFNhbXBsZXMgPiB0aGlzLl9tYXhRdWV1ZVNhbXBsZXMpIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IHF1ZXVlZFNhbXBsZXM7CgogICAgICAvLyBQZXJpb2RpY2FsbHkgc2VuZCBtZXRyaWNzIHRvIG1haW4gdGhyZWFkCiAgICAgIGlmICh0aGlzLl9mcmFtZXNQcm9jZXNzZWQgLSB0aGlzLl9sYXN0TWV0cmljc1NlbnRBdEZyYW1lID49IHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcykgewogICAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgICAgdHJ5IHsKICAgICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgIHR5cGU6ICJtZXRyaWNzIiwKICAgICAgICAgICAgZGF0YTogewogICAgICAgICAgICAgIHN0YXRlOiB0aGlzLl9zdGF0ZSwKICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzLAogICAgICAgICAgICAgIHF1ZXVlZE1zOiBNYXRoLnJvdW5kKChxdWV1ZWRTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICBtYXhRdWV1ZWRNczogTWF0aC5yb3VuZCgodGhpcy5fbWF4UXVldWVTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICB1bmRlcnJ1bkJsb2NrczogdGhpcy5fdW5kZXJydW5CbG9ja3MsCiAgICAgICAgICAgICAgZnJhbWVzUHJvY2Vzc2VkOiB0aGlzLl9mcmFtZXNQcm9jZXNzZWQKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgfSBjYXRjaCAoXykgeyB9CiAgICAgICAgLy8gRG9uJ3QgcmVzZXQgbWF4IHRyYWNrZXIgLSBrZWVwIHNlc3Npb24gcGVhayB1bnRpbCBpZGxlCiAgICAgIH0KICAgIH0KCiAgICAvLyBBTFdBWVMgcmV0dXJuIHRydWUgdG8ga2VlcCB0aGUgcHJvY2Vzc29yIGFsaXZlIGZvciByZXVzZS4KICAgIHJldHVybiB0cnVlOwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoInBsYXliYWNrLXdvcmtsZXQiLCBQbGF5YmFja1dvcmtsZXQpOwo=",typeof document>"u"?require("url").pathToFileURL(__filename).href:He&&He.tagName.toUpperCase()==="SCRIPT"&&He.src||new URL("index.cjs",document.baseURI).href),Te={en:tt,de:it,fr:st,fi:rt,lt:ut},_=new g.Quaternion,G=new g.Euler,fe=new g.Vector3,xe=new g.Vector3,Be=new g.Box3;new g.Matrix4;new g.Matrix4;new g.Vector3;new g.Vector3(0,0,1);const ct=new g.Vector3(1,0,0);new g.Vector3(0,1,0);new g.Vector3(0,0,1);class Me{constructor(n,e=null){this.nodeAvatar=n,this.opt={jwtGet:null,ttsEndpoint:"",ttsApikey:null,ttsTrimStart:0,ttsTrimEnd:400,ttsLang:"fi-FI",ttsVoice:"fi-FI-Standard-A",ttsRate:1,ttsPitch:0,ttsVolume:.3,mixerGainSpeech:1.2,mixerGainBackground:null,lipsyncLang:"fi",lipsyncModules:["fi","en","lt"],pcmSampleRate:22050,modelRoot:"Armature",modelPixelRatio:1,modelFPS:30,modelMovementFactor:1,cameraView:"full",dracoEnabled:!1,dracoDecoderPath:"https://www.gstatic.com/draco/v1/decoders/",cameraDistance:0,cameraX:0,cameraY:0,cameraRotateX:0,cameraRotateY:0,cameraRotateEnable:!0,cameraPanEnable:!1,cameraZoomEnable:!1,lightAmbientColor:16777215,lightAmbientIntensity:1.25,lightDirectColor:8947882,lightDirectIntensity:12,lightDirectPhi:1,lightDirectTheta:2,lightSpotIntensity:0,lightSpotColor:3377407,lightSpotPhi:.1,lightSpotTheta:4,lightSpotDispersion:1,avatarMood:"neutral",avatarMute:!1,avatarIdleEyeContact:.6,avatarIdleHeadMove:.5,avatarSpeakingEyeContact:.8,avatarSpeakingHeadMove:.5,avatarIgnoreCamera:!1,listeningSilenceThresholdLevel:40,listeningSilenceThresholdMs:2e3,listeningSilenceDurationMax:1e4,listeningActiveThresholdLevel:75,listeningActiveThresholdMs:300,listeningActiveDurationMax:24e4,update:null,avatarOnly:!1,avatarOnlyScene:null,avatarOnlyCamera:null,statsNode:null,statsStyle:null},Object.assign(this.opt,e||{}),this.opt.statsNode&&(this.stats=new Qe,this.opt.statsStyle&&(this.stats.dom.style.cssText=this.opt.statsStyle),this.opt.statsNode.appendChild(this.stats.dom)),this.poseTemplates={side:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.003,y:-.017,z:.1},"Spine.rotation":{x:-.103,y:-.002,z:-.063},"Spine1.rotation":{x:.042,y:-.02,z:-.069},"Spine2.rotation":{x:.131,y:-.012,z:-.065},"Neck.rotation":{x:.027,y:.006,z:0},"Head.rotation":{x:.077,y:-.065,z:0},"LeftShoulder.rotation":{x:1.599,y:.084,z:-1.77},"LeftArm.rotation":{x:1.364,y:.052,z:-.044},"LeftForeArm.rotation":{x:.002,y:-.007,z:.331},"LeftHand.rotation":{x:.104,y:-.067,z:-.174},"LeftHandThumb1.rotation":{x:.231,y:.258,z:.355},"LeftHandThumb2.rotation":{x:-.106,y:-.339,z:-.454},"LeftHandThumb3.rotation":{x:-.02,y:-.142,z:-.004},"LeftHandIndex1.rotation":{x:.148,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.326,y:-.049,z:-.029},"LeftHandIndex3.rotation":{x:.247,y:-.053,z:-.073},"LeftHandMiddle1.rotation":{x:.238,y:-.057,z:-.089},"LeftHandMiddle2.rotation":{x:.469,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.206,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.187,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.579,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.272,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.405,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.613,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.268,y:.094,z:-.081},"RightShoulder.rotation":{x:1.541,y:.192,z:1.775},"RightArm.rotation":{x:1.273,y:-.352,z:-.067},"RightForeArm.rotation":{x:-.011,y:-.031,z:-.357},"RightHand.rotation":{x:-.008,y:.312,z:-.028},"RightHandThumb1.rotation":{x:.23,y:-.258,z:-.355},"RightHandThumb2.rotation":{x:-.107,y:.339,z:.454},"RightHandThumb3.rotation":{x:-.02,y:.142,z:.004},"RightHandIndex1.rotation":{x:.148,y:-.031,z:.069},"RightHandIndex2.rotation":{x:.326,y:.049,z:.029},"RightHandIndex3.rotation":{x:.247,y:.053,z:.073},"RightHandMiddle1.rotation":{x:.237,y:.057,z:.089},"RightHandMiddle2.rotation":{x:.469,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.206,y:.015,z:.017},"RightHandRing1.rotation":{x:.204,y:.086,z:.135},"RightHandRing2.rotation":{x:.579,y:-.02,z:.098},"RightHandRing3.rotation":{x:.272,y:-.021,z:.063},"RightHandPinky1.rotation":{x:.404,y:.182,z:.137},"RightHandPinky2.rotation":{x:.613,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.268,y:-.094,z:.081},"LeftUpLeg.rotation":{x:.096,y:.209,z:2.983},"LeftLeg.rotation":{x:-.053,y:.042,z:-.017},"LeftFoot.rotation":{x:1.091,y:.15,z:.026},"LeftToeBase.rotation":{x:.469,y:-.07,z:-.015},"RightUpLeg.rotation":{x:-.307,y:-.219,z:2.912},"RightLeg.rotation":{x:-.359,y:.164,z:.015},"RightFoot.rotation":{x:1.035,y:.11,z:.005},"RightToeBase.rotation":{x:.467,y:.07,z:.015}}},hip:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.036,y:.09,z:.135},"Spine.rotation":{x:.076,y:-.035,z:.01},"Spine1.rotation":{x:-.096,y:.013,z:-.094},"Spine2.rotation":{x:-.014,y:.002,z:-.097},"Neck.rotation":{x:.034,y:-.051,z:-.075},"Head.rotation":{x:.298,y:-.1,z:.154},"LeftShoulder.rotation":{x:1.694,y:.011,z:-1.68},"LeftArm.rotation":{x:1.343,y:.177,z:-.153},"LeftForeArm.rotation":{x:-.049,y:.134,z:.351},"LeftHand.rotation":{x:.057,y:-.189,z:-.026},"LeftHandThumb1.rotation":{x:.368,y:-.066,z:.438},"LeftHandThumb2.rotation":{x:-.156,y:.029,z:-.369},"LeftHandThumb3.rotation":{x:.034,y:-.009,z:.016},"LeftHandIndex1.rotation":{x:.157,y:-.002,z:-.171},"LeftHandIndex2.rotation":{x:.099,y:0,z:0},"LeftHandIndex3.rotation":{x:.1,y:0,z:0},"LeftHandMiddle1.rotation":{x:.222,y:-.019,z:-.16},"LeftHandMiddle2.rotation":{x:.142,y:0,z:0},"LeftHandMiddle3.rotation":{x:.141,y:0,z:0},"LeftHandRing1.rotation":{x:.333,y:-.039,z:-.174},"LeftHandRing2.rotation":{x:.214,y:0,z:0},"LeftHandRing3.rotation":{x:.213,y:0,z:0},"LeftHandPinky1.rotation":{x:.483,y:-.069,z:-.189},"LeftHandPinky2.rotation":{x:.312,y:0,z:0},"LeftHandPinky3.rotation":{x:.309,y:0,z:0},"RightShoulder.rotation":{x:1.597,y:.012,z:1.816},"RightArm.rotation":{x:.618,y:-1.274,z:-.266},"RightForeArm.rotation":{x:-.395,y:-.097,z:-1.342},"RightHand.rotation":{x:-.816,y:-.057,z:-.976},"RightHandThumb1.rotation":{x:.42,y:.23,z:-1.172},"RightHandThumb2.rotation":{x:-.027,y:.361,z:.122},"RightHandThumb3.rotation":{x:.076,y:.125,z:-.371},"RightHandIndex1.rotation":{x:-.158,y:-.045,z:.033},"RightHandIndex2.rotation":{x:.391,y:.051,z:.025},"RightHandIndex3.rotation":{x:.317,y:.058,z:.07},"RightHandMiddle1.rotation":{x:.486,y:.066,z:.014},"RightHandMiddle2.rotation":{x:.718,y:.055,z:.07},"RightHandMiddle3.rotation":{x:.453,y:.019,z:.013},"RightHandRing1.rotation":{x:.591,y:.241,z:.11},"RightHandRing2.rotation":{x:1.014,y:.023,z:.097},"RightHandRing3.rotation":{x:.708,y:.008,z:.066},"RightHandPinky1.rotation":{x:1.02,y:.305,z:.051},"RightHandPinky2.rotation":{x:1.187,y:-.028,z:.191},"RightHandPinky3.rotation":{x:.872,y:-.031,z:.121},"LeftUpLeg.rotation":{x:-.095,y:-.058,z:-3.338},"LeftLeg.rotation":{x:-.366,y:.287,z:-.021},"LeftFoot.rotation":{x:1.131,y:.21,z:.176},"LeftToeBase.rotation":{x:.739,y:-.068,z:-.001},"RightUpLeg.rotation":{x:-.502,y:.362,z:3.153},"RightLeg.rotation":{x:-1.002,y:.109,z:.008},"RightFoot.rotation":{x:.626,y:-.097,z:-.194},"RightToeBase.rotation":{x:1.33,y:.288,z:-.078}}},turn:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.07,y:-.604,z:-.004},"Spine.rotation":{x:-.007,y:.003,z:.071},"Spine1.rotation":{x:-.053,y:.024,z:-.06},"Spine2.rotation":{x:.074,y:.013,z:-.068},"Neck.rotation":{x:.03,y:.186,z:-.077},"Head.rotation":{x:.045,y:.243,z:-.086},"LeftShoulder.rotation":{x:1.717,y:-.085,z:-1.761},"LeftArm.rotation":{x:1.314,y:.07,z:-.057},"LeftForeArm.rotation":{x:-.151,y:.714,z:.302},"LeftHand.rotation":{x:-.069,y:.003,z:-.118},"LeftHandThumb1.rotation":{x:.23,y:.258,z:.354},"LeftHandThumb2.rotation":{x:-.107,y:-.338,z:-.455},"LeftHandThumb3.rotation":{x:-.015,y:-.142,z:.002},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.323,y:-.049,z:-.028},"LeftHandIndex3.rotation":{x:.249,y:-.053,z:-.074},"LeftHandMiddle1.rotation":{x:.235,y:-.057,z:-.088},"LeftHandMiddle2.rotation":{x:.468,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.203,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.185,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.578,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.27,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.404,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.612,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.267,y:.094,z:-.081},"RightShoulder.rotation":{x:1.605,y:.17,z:1.625},"RightArm.rotation":{x:1.574,y:-.655,z:.388},"RightForeArm.rotation":{x:-.36,y:-.849,z:-.465},"RightHand.rotation":{x:.114,y:.416,z:-.069},"RightHandThumb1.rotation":{x:.486,y:.009,z:-.492},"RightHandThumb2.rotation":{x:-.073,y:-.01,z:.284},"RightHandThumb3.rotation":{x:-.054,y:-.006,z:.209},"RightHandIndex1.rotation":{x:.245,y:-.014,z:.052},"RightHandIndex2.rotation":{x:.155,y:0,z:0},"RightHandIndex3.rotation":{x:.153,y:0,z:0},"RightHandMiddle1.rotation":{x:.238,y:.004,z:.028},"RightHandMiddle2.rotation":{x:.15,y:0,z:0},"RightHandMiddle3.rotation":{x:.149,y:0,z:0},"RightHandRing1.rotation":{x:.267,y:.012,z:.007},"RightHandRing2.rotation":{x:.169,y:0,z:0},"RightHandRing3.rotation":{x:.167,y:0,z:0},"RightHandPinky1.rotation":{x:.304,y:.018,z:-.021},"RightHandPinky2.rotation":{x:.192,y:0,z:0},"RightHandPinky3.rotation":{x:.19,y:0,z:0},"LeftUpLeg.rotation":{x:-.001,y:-.058,z:-3.238},"LeftLeg.rotation":{x:-.29,y:.058,z:-.021},"LeftFoot.rotation":{x:1.288,y:.168,z:.183},"LeftToeBase.rotation":{x:.363,y:-.09,z:-.01},"RightUpLeg.rotation":{x:-.1,y:.36,z:3.062},"RightLeg.rotation":{x:-.67,y:-.304,z:.043},"RightFoot.rotation":{x:1.195,y:-.159,z:-.294},"RightToeBase.rotation":{x:.737,y:.164,z:-.002}}},bend:{bend:!0,standing:!0,props:{"Hips.position":{x:-.007,y:.943,z:-.001},"Hips.rotation":{x:1.488,y:-.633,z:1.435},"Spine.rotation":{x:-.126,y:.007,z:-.057},"Spine1.rotation":{x:-.134,y:.009,z:.01},"Spine2.rotation":{x:-.019,y:0,z:-.002},"Neck.rotation":{x:-.159,y:.572,z:-.108},"Head.rotation":{x:-.064,y:.716,z:-.257},"RightShoulder.rotation":{x:1.625,y:-.043,z:1.382},"RightArm.rotation":{x:.746,y:-.96,z:-1.009},"RightForeArm.rotation":{x:-.199,y:-.528,z:-.38},"RightHand.rotation":{x:-.261,y:-.043,z:-.027},"RightHandThumb1.rotation":{x:.172,y:-.138,z:-.445},"RightHandThumb2.rotation":{x:-.158,y:.327,z:.545},"RightHandThumb3.rotation":{x:-.062,y:.138,z:.152},"RightHandIndex1.rotation":{x:.328,y:-.005,z:.132},"RightHandIndex2.rotation":{x:.303,y:.049,z:.028},"RightHandIndex3.rotation":{x:.241,y:.046,z:.077},"RightHandMiddle1.rotation":{x:.309,y:.074,z:.089},"RightHandMiddle2.rotation":{x:.392,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.199,y:.014,z:.019},"RightHandRing1.rotation":{x:.239,y:.143,z:.091},"RightHandRing2.rotation":{x:.275,y:-.02,z:.097},"RightHandRing3.rotation":{x:.248,y:-.023,z:.061},"RightHandPinky1.rotation":{x:.211,y:.154,z:.029},"RightHandPinky2.rotation":{x:.348,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.21,y:-.091,z:.065},"LeftShoulder.rotation":{x:1.626,y:-.027,z:-1.367},"LeftArm.rotation":{x:1.048,y:.737,z:.712},"LeftForeArm.rotation":{x:-.508,y:.879,z:.625},"LeftHand.rotation":{x:.06,y:-.243,z:-.079},"LeftHandThumb1.rotation":{x:.187,y:-.072,z:.346},"LeftHandThumb2.rotation":{x:-.066,y:.008,z:-.256},"LeftHandThumb3.rotation":{x:-.085,y:.014,z:-.334},"LeftHandIndex1.rotation":{x:-.1,y:.016,z:-.058},"LeftHandIndex2.rotation":{x:.334,y:0,z:0},"LeftHandIndex3.rotation":{x:.281,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.056,y:0,z:0},"LeftHandMiddle2.rotation":{x:.258,y:0,z:0},"LeftHandMiddle3.rotation":{x:.26,y:0,z:0},"LeftHandRing1.rotation":{x:-.067,y:-.002,z:.008},"LeftHandRing2.rotation":{x:.259,y:0,z:0},"LeftHandRing3.rotation":{x:.276,y:0,z:0},"LeftHandPinky1.rotation":{x:-.128,y:-.007,z:.042},"LeftHandPinky2.rotation":{x:.227,y:0,z:0},"LeftHandPinky3.rotation":{x:.145,y:0,z:0},"RightUpLeg.rotation":{x:-1.507,y:.2,z:-3.043},"RightLeg.rotation":{x:-.689,y:-.124,z:.017},"RightFoot.rotation":{x:.909,y:.008,z:-.093},"RightToeBase.rotation":{x:.842,y:.075,z:-.008},"LeftUpLeg.rotation":{x:-1.449,y:-.2,z:3.018},"LeftLeg.rotation":{x:-.74,y:-.115,z:-.008},"LeftFoot.rotation":{x:1.048,y:-.058,z:.117},"LeftToeBase.rotation":{x:.807,y:-.067,z:.003}}},back:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.732,y:-1.463,z:-.637},"Spine.rotation":{x:-.171,y:.106,z:.157},"Spine1.rotation":{x:-.044,y:.138,z:-.059},"Spine2.rotation":{x:.082,y:.133,z:-.074},"Neck.rotation":{x:.39,y:.591,z:-.248},"Head.rotation":{x:-.001,y:.596,z:-.057},"LeftShoulder.rotation":{x:1.676,y:.007,z:-1.892},"LeftArm.rotation":{x:-5.566,y:1.188,z:-.173},"LeftForeArm.rotation":{x:-.673,y:-.105,z:1.702},"LeftHand.rotation":{x:-.469,y:-.739,z:.003},"LeftHandThumb1.rotation":{x:.876,y:.274,z:.793},"LeftHandThumb2.rotation":{x:.161,y:-.23,z:-.172},"LeftHandThumb3.rotation":{x:.078,y:.027,z:.156},"LeftHandIndex1.rotation":{x:-.085,y:-.002,z:.009},"LeftHandIndex2.rotation":{x:.176,y:0,z:-.002},"LeftHandIndex3.rotation":{x:-.036,y:.001,z:-.035},"LeftHandMiddle1.rotation":{x:.015,y:.144,z:-.076},"LeftHandMiddle2.rotation":{x:.378,y:-.007,z:-.077},"LeftHandMiddle3.rotation":{x:-.141,y:-.001,z:.031},"LeftHandRing1.rotation":{x:.039,y:.02,z:-.2},"LeftHandRing2.rotation":{x:.25,y:-.002,z:-.073},"LeftHandRing3.rotation":{x:.236,y:.006,z:-.075},"LeftHandPinky1.rotation":{x:.172,y:-.033,z:-.275},"LeftHandPinky2.rotation":{x:.216,y:.043,z:-.054},"LeftHandPinky3.rotation":{x:.325,y:.078,z:-.13},"RightShoulder.rotation":{x:2.015,y:-.168,z:1.706},"RightArm.rotation":{x:.203,y:-1.258,z:-.782},"RightForeArm.rotation":{x:-.658,y:-.133,z:-1.401},"RightHand.rotation":{x:-1.504,y:.375,z:-.005},"RightHandThumb1.rotation":{x:.413,y:-.158,z:-1.121},"RightHandThumb2.rotation":{x:-.142,y:-.008,z:.209},"RightHandThumb3.rotation":{x:-.091,y:.021,z:.142},"RightHandIndex1.rotation":{x:-.167,y:.014,z:-.072},"RightHandIndex2.rotation":{x:.474,y:.009,z:.051},"RightHandIndex3.rotation":{x:.115,y:.006,z:.047},"RightHandMiddle1.rotation":{x:.385,y:.019,z:.144},"RightHandMiddle2.rotation":{x:.559,y:.035,z:.101},"RightHandMiddle3.rotation":{x:.229,y:0,z:.027},"RightHandRing1.rotation":{x:.48,y:.026,z:.23},"RightHandRing2.rotation":{x:.772,y:.038,z:.109},"RightHandRing3.rotation":{x:.622,y:.039,z:.106},"RightHandPinky1.rotation":{x:.767,y:.288,z:.353},"RightHandPinky2.rotation":{x:.886,y:.049,z:.122},"RightHandPinky3.rotation":{x:.662,y:.044,z:.113},"LeftUpLeg.rotation":{x:-.206,y:-.268,z:-3.343},"LeftLeg.rotation":{x:-.333,y:.757,z:-.043},"LeftFoot.rotation":{x:1.049,y:.167,z:.287},"LeftToeBase.rotation":{x:.672,y:-.069,z:-.004},"RightUpLeg.rotation":{x:.055,y:-.226,z:3.037},"RightLeg.rotation":{x:-.559,y:.39,z:-.001},"RightFoot.rotation":{x:1.2,y:.133,z:.085},"RightToeBase.rotation":{x:.92,y:.093,z:-.013}}},straight:{standing:!0,props:{"Hips.position":{x:0,y:.989,z:.001},"Hips.rotation":{x:.047,y:.007,z:-.007},"Spine.rotation":{x:-.143,y:-.007,z:.005},"Spine1.rotation":{x:-.043,y:-.014,z:.012},"Spine2.rotation":{x:.072,y:-.013,z:.013},"Neck.rotation":{x:.048,y:-.003,z:.012},"Head.rotation":{x:.05,y:-.02,z:-.017},"LeftShoulder.rotation":{x:1.62,y:-.166,z:-1.605},"LeftArm.rotation":{x:1.275,y:.544,z:-.092},"LeftForeArm.rotation":{x:0,y:0,z:.302},"LeftHand.rotation":{x:-.225,y:-.154,z:.11},"LeftHandThumb1.rotation":{x:.435,y:-.044,z:.457},"LeftHandThumb2.rotation":{x:-.028,y:.002,z:-.246},"LeftHandThumb3.rotation":{x:-.236,y:-.025,z:.113},"LeftHandIndex1.rotation":{x:.218,y:.008,z:-.081},"LeftHandIndex2.rotation":{x:.165,y:-.001,z:-.017},"LeftHandIndex3.rotation":{x:.165,y:-.001,z:-.017},"LeftHandMiddle1.rotation":{x:.235,y:-.011,z:-.065},"LeftHandMiddle2.rotation":{x:.182,y:-.002,z:-.019},"LeftHandMiddle3.rotation":{x:.182,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.316,y:-.017,z:.008},"LeftHandRing2.rotation":{x:.253,y:-.003,z:-.026},"LeftHandRing3.rotation":{x:.255,y:-.003,z:-.026},"LeftHandPinky1.rotation":{x:.336,y:-.062,z:.088},"LeftHandPinky2.rotation":{x:.276,y:-.004,z:-.028},"LeftHandPinky3.rotation":{x:.276,y:-.004,z:-.028},"RightShoulder.rotation":{x:1.615,y:.064,z:1.53},"RightArm.rotation":{x:1.313,y:-.424,z:.131},"RightForeArm.rotation":{x:0,y:0,z:-.317},"RightHand.rotation":{x:-.158,y:-.639,z:-.196},"RightHandThumb1.rotation":{x:.44,y:.048,z:-.549},"RightHandThumb2.rotation":{x:-.056,y:-.008,z:.274},"RightHandThumb3.rotation":{x:-.258,y:.031,z:-.095},"RightHandIndex1.rotation":{x:.169,y:-.011,z:.105},"RightHandIndex2.rotation":{x:.134,y:.001,z:.011},"RightHandIndex3.rotation":{x:.134,y:.001,z:.011},"RightHandMiddle1.rotation":{x:.288,y:.014,z:.092},"RightHandMiddle2.rotation":{x:.248,y:.003,z:.02},"RightHandMiddle3.rotation":{x:.249,y:.003,z:.02},"RightHandRing1.rotation":{x:.369,y:.019,z:.006},"RightHandRing2.rotation":{x:.321,y:.004,z:.026},"RightHandRing3.rotation":{x:.323,y:.004,z:.026},"RightHandPinky1.rotation":{x:.468,y:.085,z:-.03},"RightHandPinky2.rotation":{x:.427,y:.007,z:.034},"RightHandPinky3.rotation":{x:.142,y:.001,z:.012},"LeftUpLeg.rotation":{x:-.077,y:-.058,z:3.126},"LeftLeg.rotation":{x:-.252,y:.001,z:-.018},"LeftFoot.rotation":{x:1.315,y:-.064,z:.315},"LeftToeBase.rotation":{x:.577,y:-.07,z:-.009},"RightUpLeg.rotation":{x:-.083,y:-.032,z:3.124},"RightLeg.rotation":{x:-.272,y:-.003,z:.021},"RightFoot.rotation":{x:1.342,y:.076,z:-.222},"RightToeBase.rotation":{x:.44,y:.069,z:.016}}},wide:{standing:!0,props:{"Hips.position":{x:0,y:1.017,z:.016},"Hips.rotation":{x:.064,y:-.048,z:.059},"Spine.rotation":{x:-.123,y:0,z:-.018},"Spine1.rotation":{x:.014,y:.003,z:-.006},"Spine2.rotation":{x:.04,y:.003,z:-.007},"Neck.rotation":{x:.101,y:.007,z:-.035},"Head.rotation":{x:-.091,y:-.049,z:.105},"RightShoulder.rotation":{x:1.831,y:.017,z:1.731},"RightArm.rotation":{x:-1.673,y:-1.102,z:-3.132},"RightForeArm.rotation":{x:.265,y:.23,z:-.824},"RightHand.rotation":{x:-.52,y:.345,z:-.061},"RightHandThumb1.rotation":{x:.291,y:.056,z:-.428},"RightHandThumb2.rotation":{x:.025,y:.005,z:.166},"RightHandThumb3.rotation":{x:-.089,y:.009,z:.068},"RightHandIndex1.rotation":{x:.392,y:-.015,z:.11},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.068,z:.081},"RightHandMiddle2.rotation":{x:.519,y:.004,z:.011},"RightHandMiddle3.rotation":{x:.252,y:0,z:.001},"RightHandRing1.rotation":{x:.207,y:.133,z:.146},"RightHandRing2.rotation":{x:.597,y:.004,z:.004},"RightHandRing3.rotation":{x:.292,y:.002,z:.012},"RightHandPinky1.rotation":{x:.338,y:.182,z:.136},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftShoulder.rotation":{x:1.83,y:-.063,z:-1.808},"LeftArm.rotation":{x:-1.907,y:1.228,z:-2.959},"LeftForeArm.rotation":{x:-.159,y:.268,z:.572},"LeftHand.rotation":{x:.069,y:-.498,z:-.025},"LeftHandThumb1.rotation":{x:.738,y:.123,z:.178},"LeftHandThumb2.rotation":{x:-.26,y:.028,z:-.477},"LeftHandThumb3.rotation":{x:-.448,y:.093,z:-.661},"LeftHandIndex1.rotation":{x:1.064,y:.005,z:-.13},"LeftHandIndex2.rotation":{x:1.55,y:-.143,z:-.136},"LeftHandIndex3.rotation":{x:.722,y:-.076,z:-.127},"LeftHandMiddle1.rotation":{x:1.095,y:-.091,z:.006},"LeftHandMiddle2.rotation":{x:1.493,y:-.174,z:-.151},"LeftHandMiddle3.rotation":{x:.651,y:-.031,z:-.087},"LeftHandRing1.rotation":{x:1.083,y:-.224,z:.072},"LeftHandRing2.rotation":{x:1.145,y:-.107,z:-.195},"LeftHandRing3.rotation":{x:1.208,y:-.134,z:-.158},"LeftHandPinky1.rotation":{x:.964,y:-.383,z:.128},"LeftHandPinky2.rotation":{x:1.457,y:-.146,z:-.159},"LeftHandPinky3.rotation":{x:1.019,y:-.102,z:-.141},"RightUpLeg.rotation":{x:-.221,y:-.233,z:2.87},"RightLeg.rotation":{x:-.339,y:-.043,z:-.041},"RightFoot.rotation":{x:1.081,y:.177,z:.114},"RightToeBase.rotation":{x:.775,y:0,z:0},"LeftUpLeg.rotation":{x:-.185,y:.184,z:3.131},"LeftLeg.rotation":{x:-.408,y:.129,z:.02},"LeftFoot.rotation":{x:1.167,y:-.002,z:-.007},"LeftToeBase.rotation":{x:.723,y:0,z:0}}},oneknee:{kneeling:!0,props:{"Hips.position":{x:-.005,y:.415,z:-.017},"Hips.rotation":{x:-.25,y:.04,z:-.238},"Spine.rotation":{x:.037,y:.043,z:.047},"Spine1.rotation":{x:.317,y:.103,z:.066},"Spine2.rotation":{x:.433,y:.109,z:.054},"Neck.rotation":{x:-.156,y:-.092,z:.059},"Head.rotation":{x:-.398,y:-.032,z:.018},"RightShoulder.rotation":{x:1.546,y:.119,z:1.528},"RightArm.rotation":{x:.896,y:-.247,z:-.512},"RightForeArm.rotation":{x:.007,y:0,z:-1.622},"RightHand.rotation":{x:1.139,y:-.853,z:.874},"RightHandThumb1.rotation":{x:.176,y:.107,z:-.311},"RightHandThumb2.rotation":{x:-.047,y:-.003,z:.12},"RightHandThumb3.rotation":{x:0,y:0,z:0},"RightHandIndex1.rotation":{x:.186,y:.005,z:.125},"RightHandIndex2.rotation":{x:.454,y:.005,z:.015},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:.444,y:.035,z:.127},"RightHandMiddle2.rotation":{x:.403,y:-.006,z:-.04},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.543,y:.074,z:.121},"RightHandRing2.rotation":{x:.48,y:-.018,z:-.063},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.464,y:.086,z:.113},"RightHandPinky2.rotation":{x:.667,y:-.06,z:-.128},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.545,y:-.116,z:-1.529},"LeftArm.rotation":{x:.799,y:.631,z:.556},"LeftForeArm.rotation":{x:-.002,y:.007,z:.926},"LeftHand.rotation":{x:-.508,y:.439,z:.502},"LeftHandThumb1.rotation":{x:.651,y:-.035,z:.308},"LeftHandThumb2.rotation":{x:-.053,y:.008,z:-.11},"LeftHandThumb3.rotation":{x:0,y:0,z:0},"LeftHandIndex1.rotation":{x:.662,y:-.053,z:-.116},"LeftHandIndex2.rotation":{x:.309,y:-.004,z:-.02},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:.501,y:-.062,z:-.12},"LeftHandMiddle2.rotation":{x:.144,y:-.002,z:.016},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.397,y:-.029,z:-.143},"LeftHandRing2.rotation":{x:.328,y:.01,z:.059},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.194,y:.008,z:-.164},"LeftHandPinky2.rotation":{x:.38,y:.031,z:.128},"LeftHandPinky3.rotation":{x:0,y:0,z:0},"RightUpLeg.rotation":{x:-1.594,y:-.251,z:2.792},"RightLeg.rotation":{x:-2.301,y:-.073,z:.055},"RightFoot.rotation":{x:1.553,y:-.207,z:-.094},"RightToeBase.rotation":{x:.459,y:.069,z:.016},"LeftUpLeg.rotation":{x:-.788,y:-.236,z:-2.881},"LeftLeg.rotation":{x:-2.703,y:.012,z:-.047},"LeftFoot.rotation":{x:2.191,y:-.102,z:.019},"LeftToeBase.rotation":{x:1.215,y:-.027,z:.01}}},kneel:{kneeling:!0,lying:!0,props:{"Hips.position":{x:0,y:.532,z:-.002},"Hips.rotation":{x:.018,y:-.008,z:-.017},"Spine.rotation":{x:-.139,y:-.01,z:.002},"Spine1.rotation":{x:.002,y:-.002,z:.001},"Spine2.rotation":{x:.028,y:-.002,z:.001},"Neck.rotation":{x:-.007,y:0,z:-.002},"Head.rotation":{x:-.02,y:-.008,z:-.004},"LeftShoulder.rotation":{x:1.77,y:-.428,z:-1.588},"LeftArm.rotation":{x:.911,y:.343,z:.083},"LeftForeArm.rotation":{x:0,y:0,z:.347},"LeftHand.rotation":{x:.033,y:-.052,z:-.105},"LeftHandThumb1.rotation":{x:.508,y:-.22,z:.708},"LeftHandThumb2.rotation":{x:-.323,y:-.139,z:-.56},"LeftHandThumb3.rotation":{x:-.328,y:.16,z:-.301},"LeftHandIndex1.rotation":{x:.178,y:.248,z:.045},"LeftHandIndex2.rotation":{x:.236,y:-.002,z:-.019},"LeftHandIndex3.rotation":{x:-.062,y:0,z:.005},"LeftHandMiddle1.rotation":{x:.123,y:-.005,z:-.019},"LeftHandMiddle2.rotation":{x:.589,y:-.014,z:-.045},"LeftHandMiddle3.rotation":{x:.231,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.196,y:-.008,z:-.091},"LeftHandRing2.rotation":{x:.483,y:-.009,z:-.038},"LeftHandRing3.rotation":{x:.367,y:-.005,z:-.029},"LeftHandPinky1.rotation":{x:.191,y:-.269,z:-.246},"LeftHandPinky2.rotation":{x:.37,y:-.006,z:-.029},"LeftHandPinky3.rotation":{x:.368,y:-.005,z:-.029},"RightShoulder.rotation":{x:1.73,y:.434,z:1.715},"RightArm.rotation":{x:.841,y:-.508,z:-.155},"RightForeArm.rotation":{x:0,y:0,z:-.355},"RightHand.rotation":{x:.091,y:.137,z:.197},"RightHandThumb1.rotation":{x:.33,y:.051,z:-.753},"RightHandThumb2.rotation":{x:-.113,y:.075,z:.612},"RightHandThumb3.rotation":{x:-.271,y:-.166,z:.164},"RightHandIndex1.rotation":{x:.073,y:.001,z:-.093},"RightHandIndex2.rotation":{x:.338,y:.006,z:.034},"RightHandIndex3.rotation":{x:.131,y:.001,z:.013},"RightHandMiddle1.rotation":{x:.13,y:.005,z:-.017},"RightHandMiddle2.rotation":{x:.602,y:.018,z:.058},"RightHandMiddle3.rotation":{x:-.031,y:0,z:-.003},"RightHandRing1.rotation":{x:.351,y:.019,z:.045},"RightHandRing2.rotation":{x:.19,y:.002,z:.019},"RightHandRing3.rotation":{x:.21,y:.002,z:.021},"RightHandPinky1.rotation":{x:.256,y:.17,z:.118},"RightHandPinky2.rotation":{x:.451,y:.01,z:.045},"RightHandPinky3.rotation":{x:.346,y:.006,z:.035},"LeftUpLeg.rotation":{x:-.06,y:.1,z:-2.918},"LeftLeg.rotation":{x:-1.933,y:-.01,z:.011},"LeftFoot.rotation":{x:.774,y:-.162,z:-.144},"LeftToeBase.rotation":{x:1.188,y:0,z:0},"RightUpLeg.rotation":{x:-.099,y:-.057,z:2.922},"RightLeg.rotation":{x:-1.93,y:.172,z:-.02},"RightFoot.rotation":{x:.644,y:.251,z:.212},"RightToeBase.rotation":{x:.638,y:-.034,z:-.001}}},sitting:{sitting:!0,lying:!0,props:{"Hips.position":{x:0,y:.117,z:.005},"Hips.rotation":{x:-.411,y:-.049,z:.056},"Spine.rotation":{x:.45,y:-.039,z:-.116},"Spine1.rotation":{x:.092,y:-.076,z:.08},"Spine2.rotation":{x:.073,y:.035,z:.066},"Neck.rotation":{x:.051,y:.053,z:-.079},"Head.rotation":{x:-.169,y:.009,z:.034},"LeftShoulder.rotation":{x:1.756,y:-.037,z:-1.301},"LeftArm.rotation":{x:-.098,y:.016,z:1.006},"LeftForeArm.rotation":{x:-.089,y:.08,z:.837},"LeftHand.rotation":{x:.262,y:-.399,z:.3},"LeftHandThumb1.rotation":{x:.149,y:-.043,z:.452},"LeftHandThumb2.rotation":{x:.032,y:.006,z:-.162},"LeftHandThumb3.rotation":{x:-.086,y:-.005,z:-.069},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.325,y:-.001,z:-.004},"LeftHandIndex3.rotation":{x:.253,y:0,z:-.003},"LeftHandMiddle1.rotation":{x:.186,y:-.051,z:-.091},"LeftHandMiddle2.rotation":{x:.42,y:-.003,z:-.011},"LeftHandMiddle3.rotation":{x:.153,y:.001,z:-.001},"LeftHandRing1.rotation":{x:.087,y:-.19,z:-.078},"LeftHandRing2.rotation":{x:.488,y:-.004,z:-.005},"LeftHandRing3.rotation":{x:.183,y:-.001,z:-.012},"LeftHandPinky1.rotation":{x:.205,y:-.262,z:.051},"LeftHandPinky2.rotation":{x:.407,y:-.002,z:-.004},"LeftHandPinky3.rotation":{x:.068,y:0,z:-.002},"RightShoulder.rotation":{x:1.619,y:-.139,z:1.179},"RightArm.rotation":{x:.17,y:-.037,z:-1.07},"RightForeArm.rotation":{x:-.044,y:-.056,z:-.665},"RightHand.rotation":{x:.278,y:.454,z:-.253},"RightHandThumb1.rotation":{x:.173,y:.089,z:-.584},"RightHandThumb2.rotation":{x:-.003,y:-.004,z:.299},"RightHandThumb3.rotation":{x:-.133,y:-.002,z:.235},"RightHandIndex1.rotation":{x:.393,y:-.023,z:.108},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.062,z:.086},"RightHandMiddle2.rotation":{x:.519,y:.003,z:.011},"RightHandMiddle3.rotation":{x:.252,y:-.001,z:.001},"RightHandRing1.rotation":{x:.207,y:.122,z:.155},"RightHandRing2.rotation":{x:.597,y:.004,z:.005},"RightHandRing3.rotation":{x:.292,y:.001,z:.012},"RightHandPinky1.rotation":{x:.338,y:.171,z:.149},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftUpLeg.rotation":{x:-1.957,y:.083,z:-2.886},"LeftLeg.rotation":{x:-1.46,y:.123,z:.005},"LeftFoot.rotation":{x:-.013,y:.016,z:.09},"LeftToeBase.rotation":{x:.744,y:0,z:0},"RightUpLeg.rotation":{x:-1.994,y:.125,z:2.905},"RightLeg.rotation":{x:-1.5,y:-.202,z:-.006},"RightFoot.rotation":{x:-.012,y:-.065,z:.081},"RightToeBase.rotation":{x:.758,y:0,z:0}}}},this.gestureTemplates={handup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.529,y:-.2,z:.022},"LeftHandThumb1.rotation":{x:.745,y:-.526,z:.604},"LeftHandThumb2.rotation":{x:-.107,y:-.01,z:-.142},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.126,y:-.035,z:-.087},"LeftHandIndex2.rotation":{x:.255,y:.007,z:-.085},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},index:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.579,y:.228,z:.363},"LeftHandThumb2.rotation":{x:-.027,y:-.04,z:-.662},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:0,y:-.105,z:.225},"LeftHandIndex2.rotation":{x:.256,y:-.103,z:-.213},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:1.453,y:.07,z:.021},"LeftHandMiddle2.rotation":{x:1.599,y:.062,z:.07},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:1.528,y:-.073,z:.052},"LeftHandRing2.rotation":{x:1.386,y:.044,z:.053},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:1.65,y:-.204,z:.031},"LeftHandPinky2.rotation":{x:1.302,y:.071,z:.085},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},ok:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,1],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.476,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.703,y:.445,z:.899},"LeftHandThumb2.rotation":{x:-.312,y:-.04,z:-.938},"LeftHandThumb3.rotation":{x:-.37,y:.024,z:-.393},"LeftHandIndex1.rotation":{x:.8,y:-.086,z:-.091},"LeftHandIndex2.rotation":{x:1.123,y:-.046,z:-.074},"LeftHandIndex3.rotation":{x:.562,y:-.013,z:-.043},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},thumbup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:.206,z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},thumbdown:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-2.015,y:.406,z:1.575},"LeftHand.rotation":{x:-.176,y:-.206,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},side:{"LeftShoulder.rotation":{x:1.755,y:-.035,z:-1.63},"LeftArm.rotation":{x:1.263,y:-.955,z:1.024},"LeftForeArm.rotation":{x:0,y:0,z:.8},"LeftHand.rotation":{x:-.36,y:-1.353,z:-.184},"LeftHandThumb1.rotation":{x:.137,y:-.049,z:.863},"LeftHandThumb2.rotation":{x:-.293,y:.153,z:-.193},"LeftHandThumb3.rotation":{x:-.271,y:-.17,z:.18},"LeftHandIndex1.rotation":{x:-.018,y:.007,z:.28},"LeftHandIndex2.rotation":{x:.247,y:-.003,z:-.025},"LeftHandIndex3.rotation":{x:.13,y:-.001,z:-.013},"LeftHandMiddle1.rotation":{x:.333,y:-.015,z:.182},"LeftHandMiddle2.rotation":{x:.313,y:-.005,z:-.032},"LeftHandMiddle3.rotation":{x:.294,y:-.004,z:-.03},"LeftHandRing1.rotation":{x:.456,y:-.028,z:-.092},"LeftHandRing2.rotation":{x:.53,y:-.014,z:-.052},"LeftHandRing3.rotation":{x:.478,y:-.012,z:-.047},"LeftHandPinky1.rotation":{x:.647,y:-.049,z:-.184},"LeftHandPinky2.rotation":{x:.29,y:-.004,z:-.029},"LeftHandPinky3.rotation":{x:.501,y:-.013,z:-.049}},shrug:{"Neck.rotation":{x:[-.3,.3,1,2],y:[-.3,.3,1,2],z:[-.1,.1]},"Head.rotation":{x:[-.3,.3],y:[-.3,.3],z:[-.1,.1]},"RightShoulder.rotation":{x:1.732,y:-.058,z:1.407},"RightArm.rotation":{x:1.305,y:.46,z:.118},"RightForeArm.rotation":{x:[0,2],y:[-1,.2],z:-1.637},"RightHand.rotation":{x:-.048,y:.165,z:-.39},"RightHandThumb1.rotation":{x:1.467,y:.599,z:-1.315},"RightHandThumb2.rotation":{x:-.255,y:-.123,z:.119},"RightHandThumb3.rotation":{x:0,y:-.002,z:0},"RightHandIndex1.rotation":{x:-.293,y:-.066,z:-.112},"RightHandIndex2.rotation":{x:.181,y:.007,z:.069},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:-.063,y:-.041,z:.032},"RightHandMiddle2.rotation":{x:.149,y:.005,z:.05},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.152,y:-.03,z:.132},"RightHandRing2.rotation":{x:.194,y:.007,z:.058},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.306,y:-.015,z:.257},"RightHandPinky2.rotation":{x:.15,y:-.003,z:-.003},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.713,y:.141,z:-1.433},"LeftArm.rotation":{x:1.136,y:-.422,z:-.416},"LeftForeArm.rotation":{x:1.42,y:.123,z:1.506},"LeftHand.rotation":{x:.073,y:-.138,z:.064},"LeftHandThumb1.rotation":{x:1.467,y:-.599,z:1.314},"LeftHandThumb2.rotation":{x:-.255,y:.123,z:-.119},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.293,y:.066,z:.112},"LeftHandIndex2.rotation":{x:.181,y:-.007,z:-.069},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.062,y:.041,z:-.032},"LeftHandMiddle2.rotation":{x:.149,y:-.005,z:-.05},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.152,y:.03,z:-.132},"LeftHandRing2.rotation":{x:.194,y:-.007,z:-.058},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.306,y:.015,z:-.257},"LeftHandPinky2.rotation":{x:.15,y:.003,z:.003},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},namaste:{"RightShoulder.rotation":{x:1.758,y:.099,z:1.604},"RightArm.rotation":{x:.862,y:-.292,z:-.932},"RightForeArm.rotation":{x:.083,y:.066,z:-1.791},"RightHand.rotation":{x:-.52,y:-.001,z:-.176},"RightHandThumb1.rotation":{x:.227,y:.418,z:-.776},"RightHandThumb2.rotation":{x:-.011,y:-.003,z:.171},"RightHandThumb3.rotation":{x:-.041,y:-.001,z:-.013},"RightHandIndex1.rotation":{x:-.236,y:.003,z:-.028},"RightHandIndex2.rotation":{x:.004,y:0,z:.001},"RightHandIndex3.rotation":{x:.002,y:0,z:0},"RightHandMiddle1.rotation":{x:-.236,y:.003,z:-.028},"RightHandMiddle2.rotation":{x:.004,y:0,z:.001},"RightHandMiddle3.rotation":{x:.002,y:0,z:0},"RightHandRing1.rotation":{x:-.236,y:.003,z:-.028},"RightHandRing2.rotation":{x:.004,y:0,z:.001},"RightHandRing3.rotation":{x:.002,y:0,z:0},"RightHandPinky1.rotation":{x:-.236,y:.003,z:-.028},"RightHandPinky2.rotation":{x:.004,y:0,z:.001},"RightHandPinky3.rotation":{x:.002,y:0,z:0},"LeftShoulder.rotation":{x:1.711,y:-.002,z:-1.625},"LeftArm.rotation":{x:.683,y:.334,z:.977},"LeftForeArm.rotation":{x:.086,y:-.066,z:1.843},"LeftHand.rotation":{x:-.595,y:-.229,z:.096},"LeftHandThumb1.rotation":{x:.404,y:-.05,z:.537},"LeftHandThumb2.rotation":{x:-.02,y:.004,z:-.154},"LeftHandThumb3.rotation":{x:-.049,y:.002,z:-.019},"LeftHandIndex1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandIndex2.rotation":{x:.003,y:0,z:0},"LeftHandIndex3.rotation":{x:.002,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandMiddle2.rotation":{x:.004,y:0,z:0},"LeftHandMiddle3.rotation":{x:.002,y:0,z:0},"LeftHandRing1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandRing2.rotation":{x:.003,y:0,z:0},"LeftHandRing3.rotation":{x:.002,y:0,z:0},"LeftHandPinky1.rotation":{x:-.122,y:-.001,z:-.057},"LeftHandPinky2.rotation":{x:.012,y:.001,z:.07},"LeftHandPinky3.rotation":{x:.002,y:0,z:0}}},this.poseDelta={props:{"Hips.quaternion":{x:0,y:0,z:0},"Spine.quaternion":{x:0,y:0,z:0},"Spine1.quaternion":{x:0,y:0,z:0},"Neck.quaternion":{x:0,y:0,z:0},"Head.quaternion":{x:0,y:0,z:0},"Spine1.scale":{x:0,y:0,z:0},"Neck.scale":{x:0,y:0,z:0},"LeftArm.scale":{x:0,y:0,z:0},"RightArm.scale":{x:0,y:0,z:0}}},["Left","Right"].forEach(l=>{["Leg","UpLeg","Arm","ForeArm","Hand"].forEach(h=>{this.poseDelta.props[l+h+".quaternion"]={x:0,y:0,z:0}}),["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach(h=>{this.poseDelta.props[l+h+"1.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[l+h+"2.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[l+h+"3.quaternion"]={x:0,y:0,z:0}})});const t=new Set;Object.values(this.poseTemplates).forEach(l=>{Object.keys(this.propsToThreeObjects(l.props)).forEach(h=>t.add(h))}),Object.keys(this.poseDelta.props).forEach(l=>{t.add(l)}),this.posePropNames=[...t],this.poseName="side",this.poseWeightOnLeft=!0,this.gesture=null,this.poseCurrentTemplate=this.poseTemplates[this.poseName],this.poseStraight=this.propsToThreeObjects(this.poseTemplates.straight.props),this.poseBase=this.poseFactory(this.poseCurrentTemplate),this.poseTarget=this.poseFactory(this.poseCurrentTemplate),this.poseAvatar=null,this.avatarHeight=1.7,this.animTemplateEyes={name:"eyes",idle:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarIdleEyeContact")?this.avatar.avatarIdleEyeContact:this.opt.avatarIdleEyeContact,delay:[200,5e3],dt:[200,[2e3,5e3],[3e3,1e4,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]],eyeContact:[null,1]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]},speaking:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarSpeakingEyeContact")?this.avatar.avatarSpeakingEyeContact:this.opt.avatarSpeakingEyeContact,delay:[200,5e3],dt:[0,[3e3,1e4,1,2],[2e3,5e3]],vs:{eyeContact:[1,null],headMove:[null,this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[null,[-.6,.6]],eyesRotateX:[null,[-.2,.6]]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]}},this.animTemplateBlink={name:"blink",alt:[{p:.85,delay:[1e3,8e3,1,2],dt:[50,[100,300],100],vs:{eyeBlinkLeft:[1,1,0],eyeBlinkRight:[1,1,0]}},{delay:[1e3,4e3,1,2],dt:[50,[100,200],100,[10,400,0],50,[100,200],100],vs:{eyeBlinkLeft:[1,1,0,0,1,1,0],eyeBlinkRight:[1,1,0,0,1,1,0]}}]},this.animMoods={neutral:{baseline:{eyesLookDown:0},speech:{deltaRate:0,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{p:.5,delay:[5e3,3e4],vs:{pose:["side"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}},{p:.3,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}},{delay:[5e3,3e4],vs:{pose:["straight"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]},{name:"head",idle:{delay:[0,1e3],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},happy:{baseline:{mouthSmile:.2,eyesLookDown:.1},speech:{deltaRate:0,deltaPitch:.1,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",idle:{alt:[{p:.6,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{p:.1,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,1e4],vs:{pose:["wide"]}},{delay:[1e3,3e3],vs:{pose:["turn"]}}]},speaking:{alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]}},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthSmile:[[0,.2,3]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},angry:{baseline:{eyesLookDown:.1,browDownLeft:.6,browDownRight:.6,jawForward:.3,mouthFrownLeft:.7,mouthFrownRight:.7,mouthRollLower:.2,mouthShrugLower:.3,handFistLeft:1,handFistRight:1},speech:{deltaRate:-.2,deltaPitch:.2,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},sad:{baseline:{eyesLookDown:.2,browDownRight:.1,browInnerUp:.6,browOuterUpRight:.2,eyeSquintLeft:.7,eyeSquintRight:.7,mouthFrownLeft:.8,mouthFrownRight:.8,mouthLeft:.2,mouthPucker:.5,mouthRollLower:.2,mouthRollUpper:.2,mouthShrugLower:.2,mouthShrugUpper:.2,mouthStretchLeft:.4},speech:{deltaRate:-.2,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.3,.3,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},fear:{baseline:{browInnerUp:.7,eyeSquintLeft:.5,eyeSquintRight:.5,eyeWideLeft:.6,eyeWideRight:.6,mouthClose:.1,mouthFunnel:.3,mouthShrugLower:.5,mouthShrugUpper:.5},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.8,delay:[5e3,3e4],vs:{pose:["side"]}},{delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["wide"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,3e3]],vs:{bodyRotateX:[[-.06,.12]],bodyRotateY:[[-.7,.7]],bodyRotateZ:[[-.1,.1]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},disgust:{baseline:{browDownLeft:.7,browDownRight:.1,browInnerUp:.3,eyeSquintLeft:1,eyeSquintRight:1,eyeWideLeft:.5,eyeWideRight:.5,eyesRotateX:.05,mouthLeft:.4,mouthPressLeft:.3,mouthRollLower:.3,mouthShrugLower:.3,mouthShrugUpper:.8,mouthUpperUpLeft:.3,noseSneerLeft:1,noseSneerRight:.7},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},love:{baseline:{browInnerUp:.4,browOuterUpLeft:.2,browOuterUpRight:.2,mouthSmile:.2,eyeBlinkLeft:.6,eyeBlinkRight:.6,eyeWideLeft:.7,eyeWideRight:.7,bodyRotateX:.1,mouthDimpleLeft:.1,mouthDimpleRight:.1,mouthPressLeft:.2,mouthShrugUpper:.2,mouthUpperUpLeft:.1,mouthUpperUpRight:.1},speech:{deltaRate:-.1,deltaPitch:-.7,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1500,500,1500],vs:{chestInhale:[.8,.8,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{delay:[5e3,1e4],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["kneel"]}}},{delay:[1e3,3e3],vs:{pose:["turn"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[1e3,3e3],vs:{pose:["back"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[5e3,2e4],vs:{pose:["side"]},M:{delay:[5e3,2e4],vs:{pose:["side"]}},full:{delay:[5e3,2e4],vs:{pose:["bend"]}}},{delay:[1e3,3e3],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.deepCopy(this.animTemplateBlink,l=>{l.alt[0].delay[0]=l.alt[1].delay[0]=2e3}),{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[500,1e3],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[.3,.6,2]],browOuterUpLeft:[[.1,.3,2]],browOuterUpRight:[[.1,.3,2]]}}]},sleep:{baseline:{eyeBlinkLeft:1,eyeBlinkRight:1,eyesClosed:.6},speech:{deltaRate:0,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.6,.6,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",delay:[1e3,5e3],dt:[[2e3,1e4]],vs:{bodyRotateX:[[0,.4]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.04,.04]]}},{name:"eyes",delay:10010,dt:[],vs:{}},{name:"blink",delay:10020,dt:[],vs:{}},{name:"mouth",delay:10030,dt:[],vs:{}},{name:"misc",delay:10040,dt:[],vs:{}}]}},this.moodName=this.opt.avatarMood||"neutral",this.mood=this.animMoods[this.moodName],this.mood||(this.moodName="neutral",this.mood=this.animMoods.neutral),this.animEmojis={"😐":{dt:[300,2e3],rescale:[0,1],vs:{pose:["straight"],browInnerUp:[.4],eyeWideLeft:[.7],eyeWideRight:[.7],mouthPressLeft:[.6],mouthPressRight:[.6],mouthRollLower:[.3],mouthStretchLeft:[1],mouthStretchRight:[1]}},"😶":{link:"😐"},"😏":{dt:[300,2e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthLeft:[.4],mouthPucker:[.4],mouthShrugLower:[.3],mouthShrugUpper:[.2],mouthSmile:[.2],mouthSmileLeft:[.4],mouthSmileRight:[.2],mouthStretchLeft:[.5],mouthUpperUpLeft:[.6],noseSneerLeft:[.7]}},"🙂":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5]}},"🙃":{link:"🙂"},"😊":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😇":{link:"😊"},"😀":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😃":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeWideLeft:[.7],eyeWideRight:[.7],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😄":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.2],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😁":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😆":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😝":{dt:[300,100,1500,500,500],rescale:[0,0,1,0,0],vs:{browInnerUp:[.8],eyesClosed:[1],jawOpen:[.7],mouthFunnel:[.5],mouthSmile:[1],tongueOut:[0,1,1,0]}},"😋":{link:"😝"},"😛":{link:"😝"},"😛":{link:"😝"},"😜":{link:"😝"},"🤪":{link:"😝"},"😂":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤣":{link:"😂"},"😅":{link:"😂"},"😉":{dt:[500,200,500,500],rescale:[0,0,0,1],vs:{mouthSmile:[.5],mouthOpen:[.2],mouthSmileLeft:[0,.5,0],eyeBlinkLeft:[0,.7,0],eyeBlinkRight:[0,0,0],bodyRotateX:[.05,.05,.05,0],bodyRotateZ:[-.05,-.05,-.05,0],browDownLeft:[0,.7,0],cheekSquintLeft:[0,.7,0],eyeSquintLeft:[0,1,0],eyesClosed:[0]}},"😭":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.1],jawOpen:[0],mouthFrownLeft:[1],mouthFrownRight:[1],mouthOpen:[.5],mouthPucker:[.5],mouthUpperUpLeft:[.6],mouthUpperUpRight:[.6]}},"🥺":{dt:[1e3,1e3],rescale:[0,1],vs:{browDownLeft:[.2],browDownRight:[.2],browInnerUp:[1],eyeWideLeft:[.9],eyeWideRight:[.9],eyesClosed:[.1],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😞":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.7],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[1],mouthRollLower:[1],mouthShrugLower:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😔":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😳":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeWideLeft:[.5],eyeWideRight:[.5],eyesRotateY:[.05],eyesRotateX:[.05],mouthClose:[.2],mouthFunnel:[.5],mouthPucker:[.4],mouthRollLower:[.4],mouthRollUpper:[.4]}},"☹️":{dt:[500,1500],rescale:[0,1],vs:{mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[.1],mouthRollLower:[.8]}},"😚":{dt:[500,1e3,1e3],rescale:[0,1,0],vs:{browInnerUp:[.6],eyeBlinkLeft:[1],eyeBlinkRight:[1],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5],noseSneerLeft:[0,.7],noseSneerRight:[0,.7],viseme_U:[0,1]}},"😘":{dt:[500,500,200,500],rescale:[0,0,0,1],vs:{browInnerUp:[.6],eyeBlinkLeft:[0,0,1,0],eyeBlinkRight:[0],eyesRotateY:[0],bodyRotateY:[0],bodyRotateX:[0,.05,.05,0],bodyRotateZ:[0,-.05,-.05,0],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5,0],noseSneerLeft:[0,.7],noseSneerRight:[.7],viseme_U:[0,1]}},"🥰":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😍":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤩":{link:"😍"},"😡":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"😠":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"🤬":{link:"😠"},"😒":{dt:[1e3,1e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthFrownLeft:[1],mouthFrownRight:[1],mouthLeft:[.2],mouthPucker:[.5],mouthRollLower:[.2],mouthRollUpper:[.2],mouthShrugLower:[.2],mouthShrugUpper:[.2],mouthStretchLeft:[.5]}},"😱":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[.5],eyeWideRight:[.5],jawOpen:[.7],mouthFunnel:[.5]}},"😬":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],browInnerUp:[1],mouthDimpleLeft:[.5],mouthDimpleRight:[.5],mouthLowerDownLeft:[1],mouthLowerDownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[.5],mouthSmile:[.1],mouthSmileLeft:[.2],mouthSmileRight:[.2],mouthStretchLeft:[1],mouthStretchRight:[1],mouthUpperUpLeft:[1],mouthUpperUpRight:[1]}},"🙄":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[1],eyeWideRight:[1],eyesRotateX:[-.8],bodyRotateX:[.15],mouthPucker:[.5],mouthRollLower:[.6],mouthRollUpper:[.5],mouthShrugLower:[0],mouthSmile:[0]}},"🤔":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browOuterUpRight:[1],eyeSquintLeft:[.6],mouthFrownLeft:[.7],mouthFrownRight:[.7],mouthLowerDownLeft:[.3],mouthPressRight:[.4],mouthPucker:[.1],mouthRight:[.5],mouthRollLower:[.5],mouthRollUpper:[.2],handRight:[{x:.1,y:.1,z:.1,d:1e3},{d:1e3}],handFistRight:[.1]}},"👀":{dt:[500,1500],rescale:[0,1],vs:{eyesRotateY:[-.8]}},"😴":{dt:[5e3,5e3],rescale:[0,1],vs:{eyeBlinkLeft:[1],eyeBlinkRight:[1],bodyRotateX:[.2],bodyRotateZ:[.1]}},"✋":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2,!0],null]}},"🤚":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2],null]}},"👋":{link:"✋"},"👍":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["thumbup",2],null]}},"👎":{dt:[300,2e3],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15],gesture:[["thumbdown",2],null]}},"👌":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["ok",2],null]}},"🤷♂️":{dt:[1e3,1500],rescale:[0,1],vs:{gesture:[["shrug",2],null]}},"🤷♀️":{link:"🤷♂️"},"🤷":{link:"🤷♂️"},"🙏":{dt:[1500,300,1e3],rescale:[0,1,0],vs:{eyeBlinkLeft:[0,1],eyeBlinkRight:[0,1],bodyRotateX:[0],bodyRotateZ:[.1],gesture:[["namaste",2],null]}},yes:{dt:[[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateX:[[.1,.2],.1,[.1,.2],0],headRotateZ:[[-.2,.2]]}},no:{dt:[[200,500],[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateY:[[-.1,-.05],[.05,.1],[-.1,-.05],[.05,.1],0],headRotateZ:[[-.2,.2]]}}},this.mtAvatar={},this.mtCustoms=["handFistLeft","handFistRight","bodyRotateX","bodyRotateY","bodyRotateZ","headRotateX","headRotateY","headRotateZ","chestInhale"],this.mtEasingDefault=this.sigmoidFactory(5),this.mtAccDefault=.01,this.mtAccExceptions={eyeBlinkLeft:.1,eyeBlinkRight:.1,eyeLookOutLeft:.1,eyeLookInLeft:.1,eyeLookOutRight:.1,eyeLookInRight:.1},this.mtMaxVDefault=5,this.mtMaxVExceptions={bodyRotateX:1,bodyRotateY:1,bodyRotateZ:1},this.mtBaselineDefault=0,this.mtBaselineExceptions={bodyRotateX:null,bodyRotateY:null,bodyRotateZ:null,eyeLookOutLeft:null,eyeLookInLeft:null,eyeLookOutRight:null,eyeLookInRight:null,eyesLookDown:null,eyesLookUp:null},this.mtMinDefault=0,this.mtMinExceptions={bodyRotateX:-1,bodyRotateY:-1,bodyRotateZ:-1,headRotateX:-1,headRotateY:-1,headRotateZ:-1},this.mtMaxDefault=1,this.mtMaxExceptions={},this.mtLimits={eyeBlinkLeft:l=>Math.max(l,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownLeft.value)/2),eyeBlinkRight:l=>Math.max(l,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownRight.value)/2)},this.mtOnchange={eyesLookDown:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0,this.mtAvatar.eyeBlinkRight.needsUpdate=!0},browDownLeft:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0},browDownRight:()=>{this.mtAvatar.eyeBlinkRight.needsUpdate=!0}},this.mtRandomized=["mouthDimpleLeft","mouthDimpleRight","mouthLeft","mouthPressLeft","mouthPressRight","mouthStretchLeft","mouthStretchRight","mouthShrugLower","mouthShrugUpper","noseSneerLeft","noseSneerRight","mouthRollLower","mouthRollUpper","browDownLeft","browDownRight","browOuterUpLeft","browOuterUpRight","cheekPuff","cheekSquintLeft","cheekSquintRight"],this.mtExtras=[{key:"mouthOpen",mix:{jawOpen:.5}},{key:"mouthSmile",mix:{mouthSmileLeft:.8,mouthSmileRight:.8}},{key:"eyesClosed",mix:{eyeBlinkLeft:1,eyeBlinkRight:1}},{key:"eyesLookUp",mix:{eyeLookUpLeft:1,eyeLookUpRight:1}},{key:"eyesLookDown",mix:{eyeLookDownLeft:1,eyeLookDownRight:1}}],this.animQueue=[],this.animClips=[],this.animPoses=[],this.animate=this.animate.bind(this),this._raf=null,this.animFrameDur=1e3/this.opt.modelFPS,this.animClock=0,this.animSlowdownRate=1,this.animTimeLast=0,this.easing=this.sigmoidFactory(5),this.lipsync={},this.opt.lipsyncModules.forEach(l=>this.lipsyncGetProcessor(l)),this.visemeNames=["aa","E","I","O","U","PP","SS","TH","DD","FF","kk","nn","RR","CH","sil"],this.segmenter=new Intl.Segmenter("en",{granularity:"grapheme"}),this.initAudioGraph(),this.audioPlaylist=[],this.volumeFrequencyData=new Uint8Array(16),this.volumeMax=0,this.volumeHeadBase=0,this.volumeHeadTarget=0,this.volumeHeadCurrent=0,this.volumeHeadVelocity=.15,this.volumeHeadEasing=this.sigmoidFactory(3),this.isListening=!1,this.listeningAnalyzer=null,this.listeningActive=!1,this.listeningVolume=0,this.listeningSilenceThresholdLevel=this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=this.opt.listeningActiveDurationMax,this.listeningTimer=0,this.listeningTimerTotal=0,this.dracoEnabled=this.opt.dracoEnabled,this.dracoDecoderPath=this.opt.dracoDecoderPath;const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";this.b64Lookup=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let l=0;l<i.length;l++)this.b64Lookup[i.charCodeAt(l)]=l;if(this.stateName="idle",this.speechQueue=[],this.isSpeaking=!1,this.isListening=!1,this.opt.ttsEndpoint){let l=new Audio;if(l.canPlayType("audio/ogg"))this.ttsAudioEncoding="OGG-OPUS";else if(l.canPlayType("audio/mp3"))this.ttsAudioEncoding="MP3";else throw new Error("There was no support for either OGG or MP3 audio.")}if(this.isAvatarOnly=this.opt.avatarOnly,this.isAvatarOnly)this.scene=this.opt.avatarOnlyScene,this.camera=this.opt.avatarOnlyCamera;else{this.renderer=new g.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setPixelRatio(this.opt.modelPixelRatio*window.devicePixelRatio),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.renderer.outputColorSpace=g.SRGBColorSpace,this.renderer.toneMapping=g.ACESFilmicToneMapping,this.renderer.shadowMap.enabled=!1,this.nodeAvatar.appendChild(this.renderer.domElement),this.camera=new g.PerspectiveCamera(10,this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,.1,2e3),this.scene=new g.Scene,this.lightAmbient=new g.AmbientLight(new g.Color(this.opt.lightAmbientColor),this.opt.lightAmbientIntensity),this.lightDirect=new g.DirectionalLight(new g.Color(this.opt.lightDirectColor),this.opt.lightDirectIntensity),this.lightSpot=new g.SpotLight(new g.Color(this.opt.lightSpotColor),this.opt.lightSpotIntensity,0,this.opt.lightSpotDispersion),this.setLighting(this.opt);const l=new g.PMREMGenerator(this.renderer);l.compileEquirectangularShader(),this.scene.environment=l.fromScene(new Ye.RoomEnvironment).texture,this.resizeobserver=new ResizeObserver(this.onResize.bind(this)),this.resizeobserver.observe(this.nodeAvatar),this.controls=new Ze.OrbitControls(this.camera,this.renderer.domElement),this.controls.enableZoom=this.opt.cameraZoomEnable,this.controls.enableRotate=this.opt.cameraRotateEnable,this.controls.enablePan=this.opt.cameraPanEnable,this.controls.minDistance=2,this.controls.maxDistance=2e3,this.controls.autoRotateSpeed=0,this.controls.autoRotate=!1,this.controls.update(),this.cameraClock=null}this.ikMesh=new g.SkinnedMesh;const s={LeftShoulder:null,LeftArm:"LeftShoulder",LeftForeArm:"LeftArm",LeftHand:"LeftForeArm",LeftHandMiddle1:"LeftHand",RightShoulder:null,RightArm:"RightShoulder",RightForeArm:"RightArm",RightHand:"RightForeArm",RightHandMiddle1:"RightHand"},o=[];Object.entries(s).forEach((l,h)=>{const r=new g.Bone;r.name=l[0],l[1]?this.ikMesh.getObjectByName(l[1]).add(r):this.ikMesh.add(r),o.push(r)}),this.ikMesh.bind(new g.Skeleton(o)),this.dynamicbones=new $e,this.isStreaming=!1,this.streamWorkletNode=null,this.streamAudioStartTime=null,this.streamWaitForAudioChunks=!0,this.streamLipsyncLang=null,this.streamLipsyncType="visemes",this.streamLipsyncQueue=[]}initAudioGraph(n=null){if(this.audioCtx&&this.audioCtx.state!=="closed"&&this.audioCtx.close(),n?this.audioCtx=new AudioContext({sampleRate:n}):this.audioCtx=new AudioContext,this.audioSpeechSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundGainNode=this.audioCtx.createGain(),this.audioSpeechGainNode=this.audioCtx.createGain(),this.audioStreamGainNode=this.audioCtx.createGain(),this.audioAnalyzerNode=this.audioCtx.createAnalyser(),this.audioAnalyzerNode.fftSize=256,this.audioAnalyzerNode.smoothingTimeConstant=.1,this.audioAnalyzerNode.minDecibels=-70,this.audioAnalyzerNode.maxDecibels=-10,this.audioReverbNode=this.audioCtx.createConvolver(),this.audioBackgroundGainNode.connect(this.audioReverbNode),this.audioAnalyzerNode.connect(this.audioSpeechGainNode),this.audioSpeechGainNode.connect(this.audioReverbNode),this.audioStreamGainNode.connect(this.audioReverbNode),this.audioReverbNode.connect(this.audioCtx.destination),this.setReverb(this.currentReverb||null),this.setMixerGain(this.opt.mixerGainSpeech,this.opt.mixerGainBackground),this.workletLoaded=!1,this.streamWorkletNode){try{this.streamWorkletNode.port.postMessage({type:"stop"}),this.streamWorkletNode.disconnect(),this.isStreaming=!1}catch(e){console.error("Error disconnecting streamWorkletNode:",e)}this.streamWorkletNode=null}}valueFn(n){return typeof n=="function"?n():n}deepCopy(n,e=null){const t=JSON.parse(JSON.stringify(n));return e&&typeof e=="function"&&e(t),t}b64ToArrayBuffer(n){let e=3*n.length/4;n[n.length-1]==="="&&(e--,n[n.length-2]==="="&&e--);const t=new ArrayBuffer(e),i=new Uint8Array(t);let s,o=0,l,h,r,u;for(s=0;s<n.length;s+=4)l=this.b64Lookup[n.charCodeAt(s)],h=this.b64Lookup[n.charCodeAt(s+1)],r=this.b64Lookup[n.charCodeAt(s+2)],u=this.b64Lookup[n.charCodeAt(s+3)],i[o++]=l<<2|h>>4,i[o++]=(h&15)<<4|r>>2,i[o++]=(r&3)<<6|u&63;return t}concatArrayBuffers(n){if(n.length===1)return n[0];let e=0;for(let o=0;o<n.length;o++)e+=n[o].byteLength;let t=new ArrayBuffer(e),i=new Uint8Array(t),s=0;for(let o=0;o<n.length;o++)i.set(new Uint8Array(n[o]),s),s+=n[o].byteLength;return t}pcmToAudioBuffer(n){const e=new Int16Array(n),t=new Float32Array(e.length);for(let s=0;s<e.length;s++)t[s]=e[s]>=32768?-(65536-e[s])/32768:e[s]/32767;const i=this.audioCtx.createBuffer(1,t.length,this.opt.pcmSampleRate);return i.copyToChannel(t,0,0),i}propsToThreeObjects(n){const e={};for(let[t,i]of Object.entries(n)){const s=t.split(".");let o=Array.isArray(i.x)?this.gaussianRandom(...i.x):i.x,l=Array.isArray(i.y)?this.gaussianRandom(...i.y):i.y,h=Array.isArray(i.z)?this.gaussianRandom(...i.z):i.z;s[1]==="position"||s[1]==="scale"?e[t]=new g.Vector3(o,l,h):s[1]==="rotation"?(t=s[0]+".quaternion",e[t]=new g.Quaternion().setFromEuler(new g.Euler(o,l,h,"XYZ")).normalize()):s[1]==="quaternion"&&(e[t]=new g.Quaternion(o,l,h,i.w).normalize())}return e}clearThree(n){for(;n.children.length;)this.clearThree(n.children[0]),n.remove(n.children[0]);n.geometry&&n.geometry.dispose(),n.material&&(Array.isArray(n.material)?n.material.forEach(e=>{e.map&&e.map.dispose(),e.dispose()}):(n.material.map&&n.material.map.dispose(),n.material.dispose()))}addMixedMorphTarget(n,e,t,i=!1){n.forEach(s=>{if(!i&&s.morphTargetDictionary.hasOwnProperty(e))return;const o=s.geometry;let l=null,h=null;for(const[r,u]of Object.entries(t))if(s.morphTargetDictionary.hasOwnProperty(r)){const a=s.morphTargetDictionary[r],d=o.morphAttributes.position[a],p=o.morphAttributes.normal?.[a];l||(l=new g.Float32BufferAttribute(d.count*3,3),p&&(h=new g.Float32BufferAttribute(d.count*3,3)));for(let y=0;y<d.count;y++){const A=l.getX(y)+d.getX(y)*u,v=l.getY(y)+d.getY(y)*u,T=l.getZ(y)+d.getZ(y)*u;l.setXYZ(y,A,v,T)}if(p)for(let y=0;y<d.count;y++){const A=h.getX(y)+p.getX(y)*u,v=h.getY(y)+p.getY(y)*u,T=h.getZ(y)+p.getZ(y)*u;h.setXYZ(y,A,v,T)}}if(l){o.morphAttributes.position.push(l),h&&o.morphAttributes.normal.push(h);const r=o.morphAttributes.position.length-1;s.morphTargetInfluences[r]=0,s.morphTargetDictionary[e]=r}})}async showAvatar(n,e=null){if(!n||!n.hasOwnProperty("url"))throw new Error("Invalid parameter. The avatar must have at least 'url' specified.");const t=new Xe.GLTFLoader;if(this.dracoEnabled){const r=new je.DRACOLoader;r.setDecoderPath(this.dracoDecoderPath),t.setDRACOLoader(r)}let i=await t.loadAsync(n.url,e);const s=[this.opt.modelRoot];if(this.posePropNames.forEach(r=>s.push(r.split(".")[0])),s.forEach(r=>{if(!i.scene.getObjectByName(r))throw new Error("Avatar object "+r+" not found")}),this.stop(),this.avatar=n,this.bodyMovement=n.bodyMovement||"idle",this.movementIntensity=n.movementIntensity||.5,this.lockedPosition=null,this.originalPosition=null,this.positionWasLocked=!1,this.fbxAnimationLoader=null,this.dynamicbones.dispose(),this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null),this.isAvatarOnly?this.armature&&this.clearThree(this.armature):this.armature&&this.clearThree(this.scene),this.armature=i.scene.getObjectByName(this.opt.modelRoot),this.armature.scale.setScalar(1),this.animations=i.animations,this.userData=i.userData,this.morphs=[],this.armature.traverse(r=>{r.morphTargetInfluences&&r.morphTargetInfluences.length&&r.morphTargetDictionary&&this.morphs.push(r),r.frustumCulled=!1}),this.morphs.length===0)throw new Error("Blend shapes not found");const o=new Set(this.mtCustoms);this.morphs.forEach(r=>{Object.keys(r.morphTargetDictionary).forEach(u=>o.add(u))}),this.mtExtras.forEach(r=>{o.has(r.key)||(this.addMixedMorphTarget(this.morphs,r.key,r.mix),o.add(r.key))});const l={};if(o.forEach(r=>{l[r]={fixed:null,realtime:null,system:null,systemd:null,newvalue:null,ref:null,min:this.mtMinExceptions.hasOwnProperty(r)?this.mtMinExceptions[r]:this.mtMinDefault,max:this.mtMaxExceptions.hasOwnProperty(r)?this.mtMaxExceptions[r]:this.mtMaxDefault,easing:this.mtEasingDefault,base:null,v:0,needsUpdate:!0,acc:(this.mtAccExceptions.hasOwnProperty(r)?this.mtAccExceptions[r]:this.mtAccDefault)/1e3,maxv:(this.mtMaxVExceptions.hasOwnProperty(r)?this.mtMaxVExceptions[r]:this.mtMaxVDefault)/1e3,limit:this.mtLimits.hasOwnProperty(r)?this.mtLimits[r]:null,onchange:this.mtOnchange.hasOwnProperty(r)?this.mtOnchange[r]:null,baseline:this.avatar.baseline?.hasOwnProperty(r)?this.avatar.baseline[r]:this.mtBaselineExceptions.hasOwnProperty(r)?this.mtBaselineExceptions[r]:this.mtBaselineDefault,ms:[],is:[]},l[r].value=l[r].baseline,l[r].applied=l[r].baseline;const u=this.mtAvatar[r];u&&["fixed","system","systemd","realtime","base","v","value","applied"].forEach(a=>{l[r][a]=u[a]}),this.morphs.forEach(a=>{const d=a.morphTargetDictionary[r];d!==void 0&&(l[r].ms.push(a.morphTargetInfluences),l[r].is.push(d),a.morphTargetInfluences[d]=l[r].applied)})}),this.mtAvatar=l,this.poseAvatar={props:{}},this.posePropNames.forEach(r=>{const u=r.split("."),a=this.armature.getObjectByName(u[0]);this.poseAvatar.props[r]=a[u[1]],this.poseBase.props.hasOwnProperty(r)?this.poseAvatar.props[r].copy(this.poseBase.props[r]):this.poseBase.props[r]=this.poseAvatar.props[r].clone(),this.poseDelta.props.hasOwnProperty(r)&&!this.poseTarget.props.hasOwnProperty(r)&&(this.poseTarget.props[r]=this.poseAvatar.props[r].clone()),this.poseTarget.props[r].t=this.animClock,this.poseTarget.props[r].d=2e3}),this.ikMesh.traverse(r=>{r.isBone&&r.position.copy(this.armature.getObjectByName(r.name).position)}),this.isAvatarOnly?this.scene&&this.scene.add(this.armature):(this.scene.add(i.scene),this.scene.add(this.lightAmbient),this.scene.add(this.lightDirect),this.scene.add(this.lightSpot),this.lightSpot.target=this.armature.getObjectByName("Head")),n.hasOwnProperty("modelDynamicBones"))try{this.dynamicbones.setup(this.scene,this.armature,n.modelDynamicBones)}catch(r){console.error("Dynamic bones setup failed: "+r)}this.objectLeftToeBase=this.armature.getObjectByName("LeftToeBase"),this.objectRightToeBase=this.armature.getObjectByName("RightToeBase"),this.objectLeftEye=this.armature.getObjectByName("LeftEye"),this.objectRightEye=this.armature.getObjectByName("RightEye"),this.objectLeftArm=this.armature.getObjectByName("LeftArm"),this.objectRightArm=this.armature.getObjectByName("RightArm"),this.objectHips=this.armature.getObjectByName("Hips"),this.objectHead=this.armature.getObjectByName("Head"),this.objectNeck=this.armature.getObjectByName("Neck");const h=new g.Vector3;this.objectLeftEye.getWorldPosition(h),this.avatarHeight=h.y+.2,this.viewName||this.setView(this.opt.cameraView),this.setMood(this.avatar.avatarMood||this.moodName||this.opt.avatarMood),this.avatar.body==="M"&&this.poseTemplates.wide&&(this.poseName="wide",this.setPoseFromTemplate(this.poseTemplates.wide,0),console.log("Set initial male-appropriate pose: wide")),this.initializeFBXAnimationLoader(),this.bodyMovement&&this.bodyMovement!=="idle"&&this.applyBodyMovementAnimation(),this.start()}getViewNames(){return["full","mid","upper","head"]}getView(){return this.viewName}setView(n,e=null){if(n=n||this.viewName,n!=="full"&&n!=="upper"&&n!=="head"&&n!=="mid")return;if(!this.armature){this.opt.cameraView=n;return}if(this.viewName=n||this.viewName,e=e||{},this.isAvatarOnly)return;const t=e.hasOwnProperty("cameraX")?e.cameraX:this.opt.cameraX,i=e.hasOwnProperty("cameraY")?e.cameraY:this.opt.cameraY,s=e.hasOwnProperty("cameraDistance")?e.cameraDistance:this.opt.cameraDistance,o=e.hasOwnProperty("cameraRotateX")?e.cameraRotateX:this.opt.cameraRotateX,l=e.hasOwnProperty("cameraRotateY")?e.cameraRotateY:this.opt.cameraRotateY,h=this.camera.fov*(Math.PI/180);let r=-t*Math.tan(h/2),u=(1-i)*Math.tan(h/2),a=s;switch(this.viewName){case"head":a+=2,u=u*a+4*this.avatarHeight/5;break;case"upper":a+=4.5,u=u*a+2*this.avatarHeight/3;break;case"mid":a+=8,u=u*a+this.avatarHeight/3;break;default:a+=12,u=u*a}r=r*a,this.controlsEnd=new g.Vector3(r,u,0),this.cameraEnd=new g.Vector3(r,u,a).applyEuler(new g.Euler(o,l,0)),this.controls&&(this.cameraClock===null&&(this.controls.target.copy(this.controlsEnd),this.camera.position.copy(this.cameraEnd)),this.controlsStart=this.controls.target.clone(),this.cameraStart=this.camera.position.clone(),this.cameraClock=0)}setLighting(n){this.isAvatarOnly||(n=n||{},n.hasOwnProperty("lightAmbientColor")&&this.lightAmbient.color.set(new g.Color(n.lightAmbientColor)),n.hasOwnProperty("lightAmbientIntensity")&&(this.lightAmbient.intensity=n.lightAmbientIntensity,this.lightAmbient.visible=n.lightAmbientIntensity!==0),n.hasOwnProperty("lightDirectColor")&&this.lightDirect.color.set(new g.Color(n.lightDirectColor)),n.hasOwnProperty("lightDirectIntensity")&&(this.lightDirect.intensity=n.lightDirectIntensity,this.lightDirect.visible=n.lightDirectIntensity!==0),n.hasOwnProperty("lightDirectPhi")&&n.hasOwnProperty("lightDirectTheta")&&this.lightDirect.position.setFromSphericalCoords(2,n.lightDirectPhi,n.lightDirectTheta),n.hasOwnProperty("lightSpotColor")&&this.lightSpot.color.set(new g.Color(n.lightSpotColor)),n.hasOwnProperty("lightSpotIntensity")&&(this.lightSpot.intensity=n.lightSpotIntensity,this.lightSpot.visible=n.lightSpotIntensity!==0),n.hasOwnProperty("lightSpotPhi")&&n.hasOwnProperty("lightSpotTheta")&&(this.lightSpot.position.setFromSphericalCoords(2,n.lightSpotPhi,n.lightSpotTheta),this.lightSpot.position.add(new g.Vector3(0,1.5,0))),n.hasOwnProperty("lightSpotDispersion")&&(this.lightSpot.angle=n.lightSpotDispersion))}render(){this.isRunning&&!this.isAvatarOnly&&this.renderer.render(this.scene,this.camera)}onResize(){this.isAvatarOnly||(this.camera.aspect=this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,this.camera.updateProjectionMatrix(),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.controls&&this.controls.update(),this.render())}updatePoseBase(n){for(const[e,t]of Object.entries(this.poseTarget.props)){const i=this.poseAvatar.props[e];if(i){let s=(n-t.t)/t.d;s>1||!this.poseBase.props.hasOwnProperty(e)?i.copy(t):i.isQuaternion?i.copy(this.poseBase.props[e].slerp(t,this.easing(s))):i.isVector3&&i.copy(this.poseBase.props[e].lerp(t,this.easing(s)))}}this.applyShoulderAdjustment()}updatePoseDelta(){for(const[n,e]of Object.entries(this.poseDelta.props)){if(e.x===0&&e.y===0&&e.z===0)continue;G.set(e.x,e.y,e.z);const t=this.poseAvatar.props[n];t.isQuaternion?(_.setFromEuler(G),t.multiply(_)):t.isVector3&&t.add(G)}}applyShoulderAdjustment(){const e=new g.Euler;if(this.poseAvatar.props["LeftShoulder.quaternion"]){const t=this.poseAvatar.props["LeftShoulder.quaternion"];e.setFromQuaternion(t,"XYZ"),e.x+=-.6,t.setFromEuler(e,"XYZ")}if(this.poseAvatar.props["RightShoulder.quaternion"]){const t=this.poseAvatar.props["RightShoulder.quaternion"];e.setFromQuaternion(t,"XYZ"),e.x+=-.6,t.setFromEuler(e,"XYZ")}}applyShoulderAdjustmentToBones(){if(!this.armature)return;const n=-.6,e=new g.Euler,t=new g.Quaternion,i=this.armature.getObjectByName("LeftShoulder"),s=this.armature.getObjectByName("RightShoulder");i&&i.quaternion&&(e.setFromQuaternion(i.quaternion,"XYZ"),e.x+=n,t.setFromEuler(e,"XYZ"),i.quaternion.copy(t),i.updateMatrixWorld(!0)),s&&s.quaternion&&(e.setFromQuaternion(s.quaternion,"XYZ"),e.x+=n,t.setFromEuler(e,"XYZ"),s.quaternion.copy(t),s.updateMatrixWorld(!0))}updateMorphTargets(n){for(let[e,t]of Object.entries(this.mtAvatar)){if(!t.needsUpdate)continue;let i=null,s=null;if(t.fixed!==null){if(i=t.fixed,t.system=null,t.systemd=null,t.newvalue=null,t.ref&&t.ref.hasOwnProperty(e)&&delete t.ref[e],t.ref=null,t.base=null,t.value===i){t.needsUpdate=!1;continue}}else t.realtime!==null?(t.ref=null,t.base=null,s=t.realtime):t.system!==null?(i=t.system,t.newvalue=null,t.ref&&t.ref.hasOwnProperty(e)&&delete t.ref[e],t.ref=null,t.base=null,t.systemd!==null?t.systemd===0?(i=null,t.system=null,t.systemd=null):(t.systemd-=n,t.systemd<0&&(t.systemd=0),t.value===i&&(i=null)):t.value===i&&(i=null,t.system=null)):t.newvalue!==null?(t.ref=null,t.base=null,s=t.newvalue,t.newvalue=null):t.base!==null?(i=t.base,t.ref=null,t.value===i&&(i=null,t.base=null,t.needsUpdate=!1)):(t.ref=null,t.baseline!==null&&t.value!==t.baseline?(i=t.baseline,t.base=t.baseline):t.needsUpdate=!1);if(i!==null){let o=i-t.value;o>=0?o<.005?(s=i,t.v=0):(t.v<t.maxv&&(t.v+=t.acc*n),t.v>=0?s=t.value+o*(1-Math.exp(-t.v*n)):s=t.value+t.v*n*(1-Math.exp(t.v*n))):o>-.005?(s=i,t.v=0):(t.v>-t.maxv&&(t.v-=t.acc*n),t.v>=0?s=t.value+t.v*n*(1-Math.exp(-t.v*n)):s=t.value+o*(1-Math.exp(t.v*n)))}if(t.limit!==null){if(s!==null&&s!==t.value&&(t.value=s,t.onchange!==null&&t.onchange(s)),s=t.limit(t.value),s===t.applied)continue}else{if(s===null||s===t.value)continue;t.value=s,t.onchange!==null&&t.onchange(s)}switch(t.applied=s,t.applied<t.min&&(t.applied=t.min),t.applied>t.max&&(t.applied=t.max),e){case"headRotateX":this.poseDelta.props["Head.quaternion"].x=t.applied+this.mtAvatar.bodyRotateX.applied;break;case"headRotateY":this.poseDelta.props["Head.quaternion"].y=t.applied+this.mtAvatar.bodyRotateY.applied;break;case"headRotateZ":this.poseDelta.props["Head.quaternion"].z=t.applied+this.mtAvatar.bodyRotateZ.applied;break;case"bodyRotateX":this.poseDelta.props["Head.quaternion"].x=t.applied+this.mtAvatar.headRotateX.applied,this.poseDelta.props["Spine1.quaternion"].x=t.applied/2,this.poseDelta.props["Spine.quaternion"].x=t.applied/8,this.poseDelta.props["Hips.quaternion"].x=t.applied/24;break;case"bodyRotateY":this.poseDelta.props["Head.quaternion"].y=t.applied+this.mtAvatar.headRotateY.applied,this.poseDelta.props["Spine1.quaternion"].y=t.applied/2,this.poseDelta.props["Spine.quaternion"].y=t.applied/2,this.poseDelta.props["Hips.quaternion"].y=t.applied/4,this.poseDelta.props["LeftUpLeg.quaternion"].y=t.applied/2,this.poseDelta.props["RightUpLeg.quaternion"].y=t.applied/2,this.poseDelta.props["LeftLeg.quaternion"].y=t.applied/4,this.poseDelta.props["RightLeg.quaternion"].y=t.applied/4;break;case"bodyRotateZ":this.poseDelta.props["Head.quaternion"].z=t.applied+this.mtAvatar.headRotateZ.applied,this.poseDelta.props["Spine1.quaternion"].z=t.applied/12,this.poseDelta.props["Spine.quaternion"].z=t.applied/12,this.poseDelta.props["Hips.quaternion"].z=t.applied/24;break;case"handFistLeft":case"handFistRight":const o=e.substring(8);["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach((u,a)=>{a===0?(this.poseDelta.props[o+u+"1.quaternion"].x=0,this.poseDelta.props[o+u+"2.quaternion"].z=(o==="Left"?-1:1)*t.applied,this.poseDelta.props[o+u+"3.quaternion"].z=(o==="Left"?-1:1)*t.applied):(this.poseDelta.props[o+u+"1.quaternion"].x=t.applied,this.poseDelta.props[o+u+"2.quaternion"].x=1.5*t.applied,this.poseDelta.props[o+u+"3.quaternion"].x=1.5*t.applied)});break;case"chestInhale":const l=t.applied/20,h={x:l,y:l/2,z:3*l},r={x:1/(1+l)-1,y:1/(1+l/2)-1,z:1/(1+3*l)-1};this.poseDelta.props["Spine1.scale"]=h,this.poseDelta.props["Neck.scale"]=r,this.poseDelta.props["LeftArm.scale"]=r,this.poseDelta.props["RightArm.scale"]=r;break;default:for(let u=0,a=t.ms.length;u<a;u++)t.ms[u][t.is[u]]=t.applied}}}getPoseString(n,e=1e3){let t="{";return Object.entries(n).forEach((i,s)=>{const o=i[0].split(".");if(o[1]==="position"||o[1]==="rotation"||o[1]==="quaternion"){const l=o[1]==="quaternion"?o[0]+".rotation":i[0],h=i[1].isQuaternion?new g.Euler().setFromQuaternion(i[1]):i[1];t+=(s?", ":"")+"'"+l+"':{",t+="x:"+Math.round(h.x*e)/e,t+=", y:"+Math.round(h.y*e)/e,t+=", z:"+Math.round(h.z*e)/e,t+="}"}}),t+="}",t}getPoseTemplateProp(n){const e=n.split(".");let t=e[0]+"."+(e[1]==="rotation"?"quaternion":e[1]);if(this.gesture&&this.gesture.hasOwnProperty(t))return this.gesture[t].clone();{let i=e[0]+"."+(e[1]==="quaternion"?"rotation":e[1]);this.poseWeightOnLeft||(i.startsWith("Left")?(i="Right"+i.substring(4),t="Right"+t.substring(4)):i.startsWith("Right")&&(i="Left"+i.substring(5),t="Left"+t.substring(5)));let s;if(this.poseTarget.template.props.hasOwnProperty(t)){const o={};o[t]=this.poseTarget.template.props[t],s=this.propsToThreeObjects(o)[t]}else if(this.poseTarget.template.props.hasOwnProperty(i)){const o={};o[i]=this.poseTarget.template.props[i],s=this.propsToThreeObjects(o)[t]}return s&&!this.poseWeightOnLeft&&s.isQuaternion&&(s.x*=-1,s.w*=-1),s}}mirrorPose(n){const e={};for(let[t,i]of Object.entries(n))i.isQuaternion&&(t.startsWith("Left")?t="Right"+t.substring(4):t.startsWith("Right")&&(t="Left"+t.substring(5)),i.x*=-1,i.w*=-1),e[t]=i.clone(),e[t].t=i.t,e[t].d=i.d;return e}poseFactory(n,e=2e3){const t={template:n,props:this.propsToThreeObjects(n.props)};for(const[i,s]of Object.entries(t.props)){if(this.opt.modelMovementFactor<1&&n.standing&&(i==="Hips.quaternion"||i==="Spine.quaternion"||i==="Spine1.quaternion"||i==="Spine2.quaternion"||i==="Neck.quaternion"||i==="LeftUpLeg.quaternion"||i==="LeftLeg.quaternion"||i==="RightUpLeg.quaternion"||i==="RightLeg.quaternion")){const o=this.poseStraight[i],l=s.angleTo(o);s.rotateTowards(o,(1-this.opt.modelMovementFactor)*l)}s.t=this.animClock,s.d=e}return t}setPoseFromTemplate(n,e=2e3){if(!this.poseFactory||!this.poseTemplates)return;const t=n&&this.poseTarget&&this.poseTarget.template&&(this.poseTarget.template.standing&&n.lying||this.poseTarget.template.lying&&n.standing),i=n&&n===this.poseCurrentTemplate,s=this.poseWeightOnLeft;let o=t?1e3:e;if(t?(this.poseCurrentTemplate=this.poseTemplates.oneknee,setTimeout(()=>{this.setPoseFromTemplate(n,e)},o)):this.poseCurrentTemplate=n||this.poseCurrentTemplate,this.poseTarget=this.poseFactory(this.poseCurrentTemplate,o),this.poseWeightOnLeft=!0,!(!this.poseTarget||!this.poseTarget.props)){if((!i&&!s||i&&s)&&(this.poseTarget.props=this.mirrorPose(this.poseTarget.props),this.poseWeightOnLeft=!this.poseWeightOnLeft),this.gesture)for(let[l,h]of Object.entries(this.gesture))this.poseTarget.props.hasOwnProperty(l)&&(this.poseTarget.props[l].copy(h),this.poseTarget.props[l].t=h.t,this.poseTarget.props[l].d=h.d);this.poseBase&&this.poseBase.props&&this.poseDelta&&this.poseDelta.props&&this.poseTarget&&this.poseTarget.props&&Object.keys(this.poseDelta.props).forEach(l=>{const h=this.poseBase.props[l];!this.poseTarget.props.hasOwnProperty(l)&&h&&typeof h=="object"&&typeof h.clone=="function"&&(this.poseTarget.props[l]=h.clone(),this.poseTarget.props[l].t=this.animClock,this.poseTarget.props[l].d=o)})}}getValue(n){return this.mtAvatar[n]?.value}setValue(n,e,t=null){this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{system:e,systemd:t,needsUpdate:!0})}getMoodNames(){return Object.keys(this.animMoods)}getMood(){return this.opt.avatarMood}setMood(n){if(n=(n||"").trim().toLowerCase(),!this.animMoods.hasOwnProperty(n))throw new Error("Unknown mood.");this.moodName=n,this.mood=this.animMoods[this.moodName];for(let e of Object.keys(this.mtAvatar)){let t=this.mtBaselineExceptions.hasOwnProperty(e)?this.mtBaselineExceptions[e]:this.mtBaselineDefault;this.mood.baseline.hasOwnProperty(e)?t=this.mood.baseline[e]:this.avatar.baseline?.hasOwnProperty(e)&&(t=this.avatar.baseline[e]),this.setBaselineValue(e,t)}this.mood.anims.forEach(e=>{let t=this.animQueue.findIndex(i=>i.template.name===e.name);t!==-1&&this.animQueue.splice(t,1),this.animQueue.push(this.animFactory(e,-1))})}getMorphTargetNames(){return["eyesRotateX","eyesRotateY",...Object.keys(this.mtAvatar)].sort()}getBaselineValue(n){if(n==="eyesRotateY"){const e=this.getBaselineValue("eyeLookOutLeft");if(e===void 0)return;const t=this.getBaselineValue("eyeLookInLeft");return t===void 0||this.getBaselineValue("eyeLookOutRight")===void 0||this.getBaselineValue("eyeLookInRight")===void 0?void 0:e-t}else if(n==="eyesRotateX"){const e=this.getBaselineValue("eyesLookDown");if(e===void 0)return;const t=this.getBaselineValue("eyesLookUp");return t===void 0?void 0:e-t}else return this.mtAvatar[n]?.baseline}setBaselineValue(n,e){n==="eyesRotateY"?(this.setBaselineValue("eyeLookOutLeft",e===null?null:e>0?e:0),this.setBaselineValue("eyeLookInLeft",e===null?null:e>0?0:-e),this.setBaselineValue("eyeLookOutRight",e===null?null:e>0?0:-e),this.setBaselineValue("eyeLookInRight",e===null?null:e>0?e:0)):n==="eyesRotateX"?(this.setBaselineValue("eyesLookDown",e===null?null:e>0?e:0),this.setBaselineValue("eyesLookUp",e===null?null:e>0?0:-e)):this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{base:null,baseline:e,needsUpdate:!0})}getFixedValue(n){if(n==="eyesRotateY"){const e=this.getFixedValue("eyeLookOutLeft");if(e===null)return null;const t=this.getFixedValue("eyeLookInLeft");return t===null||this.getFixedValue("eyeLookOutRight")===null||this.getFixedValue("eyeLookInRight")===null?null:e-t}else if(n==="eyesRotateX"){const e=this.getFixedValue("eyesLookDown");if(e===null)return null;const t=this.getFixedValue("eyesLookUp");return t===null?null:e-t}else return this.mtAvatar[n]?.fixed}setFixedValue(n,e,t=null){n==="eyesRotateY"?(this.setFixedValue("eyeLookOutLeft",e===null?null:e>0?e:0,t),this.setFixedValue("eyeLookInLeft",e===null?null:e>0?0:-e,t),this.setFixedValue("eyeLookOutRight",e===null?null:e>0?0:-e,t),this.setFixedValue("eyeLookInRight",e===null?null:e>0?e:0,t)):n==="eyesRotateX"?(this.setFixedValue("eyesLookDown",e===null?null:e>0?e:0,t),this.setFixedValue("eyesLookUp",e===null?null:e>0?0:-e,t)):this.mtAvatar.hasOwnProperty(n)&&Object.assign(this.mtAvatar[n],{fixed:e,needsUpdate:!0})}animFactory(n,e=!1,t=1,i=1,s=!1){const o={template:n,ts:[0],vs:{}};let l=n;for(;;)if(l.hasOwnProperty(this.stateName))l=l[this.stateName];else if(l.hasOwnProperty(this.moodName))l=l[this.moodName];else if(l.hasOwnProperty(this.poseName))l=l[this.poseName];else if(l.hasOwnProperty(this.viewName))l=l[this.viewName];else if(this.avatar.body&&l.hasOwnProperty(this.avatar.body))l=l[this.avatar.body];else if(l.hasOwnProperty("alt")){let r=l.alt[0];if(l.alt.length>1){const u=Math.random();let a=0;for(let d=0;d<l.alt.length;d++){let p=this.valueFn(l.alt[d].p);if(a+=p===void 0?(1-a)/(l.alt.length-1-d):p,u<a){r=l.alt[d];break}}}l=r}else break;let h=this.valueFn(l.delay)||0;if(Array.isArray(h)&&(h=this.gaussianRandom(...h)),l.hasOwnProperty("dt"))l.dt.forEach((r,u)=>{let a=this.valueFn(r);Array.isArray(a)&&(a=this.gaussianRandom(...a)),o.ts[u+1]=o.ts[u]+a});else{let r=Object.values(l.vs).reduce((u,a)=>a.length>u?a.length:u,0);o.ts=Array(r+1).fill(0)}s?o.ts=o.ts.map(r=>h+r*t):o.ts=o.ts.map(r=>this.animClock+h+r*t);for(let[r,u]of Object.entries(l.vs)){const a=this.getBaselineValue(r),d=u.map(p=>(p=this.valueFn(p),p===null?null:typeof p=="function"?p:typeof p=="string"||p instanceof String?p.slice():Array.isArray(p)?r==="gesture"?p.slice():(a===void 0?0:a)+i*this.gaussianRandom(...p):typeof p=="boolean"?p:p instanceof Object&&p.constructor===Object?Object.assign({},p):(a===void 0?0:a)+i*p));r==="eyesRotateY"?(o.vs.eyeLookOutLeft=[null,...d.map(p=>p>0?p:0)],o.vs.eyeLookInLeft=[null,...d.map(p=>p>0?0:-p)],o.vs.eyeLookOutRight=[null,...d.map(p=>p>0?0:-p)],o.vs.eyeLookInRight=[null,...d.map(p=>p>0?p:0)]):r==="eyesRotateX"?(o.vs.eyesLookDown=[null,...d.map(p=>p>0?p:0)],o.vs.eyesLookUp=[null,...d.map(p=>p>0?0:-p)]):o.vs[r]=[null,...d]}for(let r of Object.keys(o.vs))for(;o.vs[r].length<=o.ts.length;)o.vs[r].push(o.vs[r][o.vs[r].length-1]);return n.hasOwnProperty("mood")&&(o.mood=this.valueFn(n.mood).slice()),e&&(o.loop=e),o}valueAnimationSeq(n,e,t,i,s,o=null){n=this.valueFn(n),e=this.valueFn(e),s<t&&(s=t),s>i&&(s=i);let l=(e-n)/(i-t);return o&&(l*=o((s-t)/(i-t))),l*s+(n-l*t)}gaussianRandom(n,e,t=1,i=5){let s=0;for(let o=0;o<i;o++)s+=Math.random();return n+Math.pow(s/i,t)*(e-n)}sigmoidFactory(n){function e(i){return 1/(1+Math.exp(-n*i))-.5}var t=.5/e(1);return function(i){return t*e(2*Math.max(Math.min(i,1),0)-1)+.5}}convertRange(n,e,t){return(n-e[0])*(t[1]-t[0])/(e[1]-e[0])+t[0]}animate(n){if(!this.isRunning)return;let e;if(this.isAvatarOnly)e=n;else{if(this._raf=requestAnimationFrame(this.animate),e=n-this.animTimeLast,e<this.animFrameDur)return;this.animTimeLast=n}e=e/this.animSlowdownRate,this.animClock+=e,this.maintainLockedPosition();let t,i,s,o,l=0;if(this.stats&&this.stats.begin(),this.isListening){for(this.listeningAnalyzer.getByteFrequencyData(this.volumeFrequencyData),t=2,s=10;t<s;t++)this.volumeFrequencyData[t]>l&&(l=this.volumeFrequencyData[t]);this.listeningVolume=(this.listeningVolume+l)/2,this.listeningActive?(this.listeningTimerTotal+=e,this.listeningVolume<this.listeningSilenceThresholdLevel?(this.listeningTimer+=e,this.listeningTimer>this.listeningSilenceThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("stop",this.listeningTimer),this.listeningActive=!1,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningActiveDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxactive"),this.listeningTimerTotal=0)):(this.listeningTimerTotal+=e,this.listeningVolume>this.listeningActiveThresholdLevel?(this.listeningTimer+=e,this.listeningTimer>this.listeningActiveThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("start"),this.listeningActive=!0,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningSilenceDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxsilence"),this.listeningTimerTotal=0))}if(this.isSpeaking)for(l=0,this.audioAnalyzerNode.getByteFrequencyData(this.volumeFrequencyData),t=2,s=10;t<s;t++)this.volumeFrequencyData[t]>l&&(l=this.volumeFrequencyData[t]);let h=null,r=null;const u=[];for(t=0,s=this.animQueue.length;t<s;t++){const a=this.animQueue[t];if(!(this.animClock<a.ts[0])){for(i=a.ndx||0,o=a.ts.length;i<o&&!(this.animClock<a.ts[i]);i++)for(let[d,p]of Object.entries(a.vs))if(this.mtAvatar.hasOwnProperty(d)){if(p[i+1]===null)continue;const y=this.mtAvatar[d];if(p[i]===null&&(p[i]=y.value),i===o-1)y.newvalue=p[i];else{y.newvalue=p[i+1];const A=a.ts[i+1]-a.ts[i];let v=1;A>1e-4&&(v=(this.animClock-a.ts[i])/A),v<1&&(y.easing&&(v=y.easing(v)),y.newvalue=(1-v)*p[i]+v*y.newvalue),y.ref&&y.ref!==a.vs&&y.ref.hasOwnProperty(d)&&delete y.ref[d],y.ref=a.vs}if(l)switch(d){case"viseme_aa":case"viseme_E":case"viseme_I":case"viseme_O":case"viseme_U":y.newvalue*=1+l/255-.5}y.needsUpdate=!0}else d==="eyeContact"&&p[i]!==null&&h!==!1?h=!!p[i]:d==="headMove"&&p[i]!==null&&r!==!1?p[i]===0?r=!1:(Math.random()<p[i]&&(r=!0),p[i]=null):p[i]!==null&&(u.push({mt:d,val:p[i]}),p[i]=null);i===o?(a.hasOwnProperty("mood")&&this.setMood(a.mood),a.loop?(o=this.isSpeaking&&(a.template.name==="head"||a.template.name==="eyes")?4:1,this.animQueue[t]=this.animFactory(a.template,a.loop>0?a.loop-1:a.loop,1,1/o)):(this.animQueue.splice(t--,1),s--)):a.ndx=i-1}}for(let a=0,d=u.length;a<d;a++)switch(i=u[a].val,u[a].mt){case"speak":this.speakText(i);break;case"subtitles":this.onSubtitles&&typeof this.onSubtitles=="function"&&this.onSubtitles(i);break;case"pose":this.poseName=i,this.setPoseFromTemplate(this.poseTemplates[this.poseName]);break;case"gesture":this.playGesture(...i);break;case"function":i&&typeof i=="function"&&i();break;case"moveto":Object.entries(i.props).forEach(p=>{p[1]?this.poseTarget.props[p[0]].copy(p[1]):this.poseTarget.props[p[0]].copy(this.getPoseTemplateProp(p[0])),this.poseTarget.props[p[0]].t=this.animClock,this.poseTarget.props[p[0]].d=p[1]&&p[1].d?p[1].d:p.duration||2e3});break;case"handLeft":this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new g.Vector3(i.x,i.y,i.z):null,!0,i.d);break;case"handRight":this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new g.Vector3(i.x,i.y,i.z):null,!0,i.d);break}if((h||r)&&(G.setFromQuaternion(this.poseAvatar.props["Head.quaternion"]),G.x=Math.max(-.9,Math.min(.9,2*G.x-.5)),G.y=Math.max(-.9,Math.min(.9,-2.5*G.y)),h?(Object.assign(this.mtAvatar.eyesLookDown,{system:G.x<0?-G.x:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyesLookUp,{system:G.x<0?0:G.x,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInLeft,{system:G.y<0?-G.y:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutLeft,{system:G.y<0?0:G.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInRight,{system:G.y<0?0:G.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutRight,{system:G.y<0?-G.y:0,needsUpdate:!0}),r&&(t=-this.mtAvatar.bodyRotateY.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[t,t,0],headRotateX:[i,i,0],headRotateZ:[-t/4,-t/4,0]}})))):(t=this.mtAvatar.eyeLookInLeft.value-this.mtAvatar.eyeLookOutLeft.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[null,t,t,0],headRotateX:[null,i,i,0],headRotateZ:[null,-t/4,-t/4,0],eyeLookInLeft:[null,0],eyeLookOutLeft:[null,0],eyeLookInRight:[null,0],eyeLookOutRight:[null,0],eyeContact:[0]}})))),e>2*this.animFrameDur&&(e=2*this.animFrameDur),(this.viewName!=="full"||this.isAvatarOnly)&&(t=this.mtRandomized[Math.floor(Math.random()*this.mtRandomized.length)],i=this.mtAvatar[t],i.needsUpdate||Object.assign(i,{base:(this.mood.baseline[t]||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)&&h?l>this.volumeMax?(this.volumeHeadBase=.05,Math.random()>.6&&(this.volumeHeadTarget=-.05-Math.random()/15),this.volumeMax=l):(this.volumeMax*=.92,this.volumeHeadTarget=this.volumeHeadBase-.9*(this.volumeHeadBase-this.volumeHeadTarget)):(this.volumeHeadTarget=0,this.volumeMax=0),t=this.volumeHeadTarget-this.volumeHeadCurrent,i=Math.abs(t),i>1e-4&&(o=i*(this.volumeHeadEasing(Math.min(1,this.volumeHeadVelocity*e/1e3/i)/2+.5)-.5),this.volumeHeadCurrent+=Math.sign(t)*Math.min(i,o)),Math.abs(this.volumeHeadCurrent)>1e-4&&(_.setFromAxisAngle(ct,this.volumeHeadCurrent),this.objectNeck.quaternion.multiply(_)),Be.setFromObject(this.armature),this.objectLeftToeBase.getWorldPosition(fe),fe.sub(this.armature.position),this.objectRightToeBase.getWorldPosition(xe),xe.sub(this.armature.position),this.objectHips.position.y-=Be.min.y/2,this.objectHips.position.x-=(fe.x+xe.x)/4,this.objectHips.position.z-=(fe.z+xe.z)/2,this.dynamicbones.update(e),this.fbxAnimationLoader&&this.fbxAnimationLoader.update(),this.applyShoulderAdjustmentToBones(),this.opt.update&&this.opt.update(e),this.updateMorphTargets(e),this.isAvatarOnly)this.stats&&this.stats.end();else{if(this.controls&&this.cameraClock!==null&&this.cameraClock<1e3){this.cameraClock+=e,this.cameraClock>1e3&&(this.cameraClock=1e3);let a=new g.Spherical().setFromVector3(this.cameraStart),d=new g.Spherical().setFromVector3(this.cameraEnd);a.phi+=this.easing(this.cameraClock/1e3)*(d.phi-a.phi),a.theta+=this.easing(this.cameraClock/1e3)*(d.theta-a.theta),a.radius+=this.easing(this.cameraClock/1e3)*(d.radius-a.radius),a.makeSafe(),this.camera.position.setFromSpherical(a),this.controlsStart.x!==this.controlsEnd.x?this.controls.target.copy(this.controlsStart.lerp(this.controlsEnd,this.easing(this.cameraClock/1e3))):(a.setFromVector3(this.controlsStart),d.setFromVector3(this.controlsEnd),a.phi+=this.easing(this.cameraClock/1e3)*(d.phi-a.phi),a.theta+=this.easing(this.cameraClock/1e3)*(d.theta-a.theta),a.radius+=this.easing(this.cameraClock/1e3)*(d.radius-a.radius),a.makeSafe(),this.controls.target.setFromSpherical(a)),this.controls.update()}this.controls&&this.controls.autoRotate&&this.controls.update(),this.stats&&this.stats.end(),this.render()}}resetLips(){this.visemeNames.forEach(n=>{this.morphs.forEach(e=>{const t=e.morphTargetDictionary["viseme_"+n];t!==void 0&&(e.morphTargetInfluences[t]=0)})})}lipsyncGetProcessor(n,e="./"){if(!this.lipsync.hasOwnProperty(n)){const t=n.toLowerCase();if(Te[t]){const i="Lipsync"+n.charAt(0).toUpperCase()+n.slice(1);Te[t][i]?this.lipsync[n]=new Te[t][i]:console.warn(`Lipsync class ${i} not found in module for language ${n}`)}else console.warn(`Lipsync module for language ${n} not found in static imports`)}}lipsyncPreProcessText(n,e){return(this.lipsync[e]||Object.values(this.lipsync)[0]).preProcessText(n)}lipsyncWordsToVisemes(n,e){return(this.lipsync[e]||Object.values(this.lipsync)[0]).wordsToVisemes(n)}speakText(n,e=null,t=null,i=null){e=e||{};const s=/[!\.\?\n\p{Extended_Pictographic}]/ug,o=/[ ]/ug,l=/[\p{L}\p{N},\.\p{Quotation_Mark}!€\$\+\p{Dash_Punctuation}%&\?]/ug,h=/[\p{Extended_Pictographic}]/ug,r=e.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang;let u="",a="",d=0,p=[],y=[];const A=Array.from(this.segmenter.segment(n),v=>v.segment);for(let v=0;v<A.length;v++){const T=v===A.length-1,C=A[v].match(l);let m=A[v].match(s);const L=A[v].match(h),E=A[v].match(o);if(m&&!T&&!L&&A[v+1].match(s)&&(m=!1),t&&(u+=A[v]),C&&(!i||i.every(R=>v<R[0]||v>R[1]))&&(a+=A[v]),(E||m||T)&&(a.length&&(a=this.lipsyncPreProcessText(a,r),a.length&&p.push({mark:d,word:a})),u.length&&(y.push({mark:d,template:{name:"subtitles"},ts:[0],vs:{subtitles:[u]}}),u=""),a.length)){const R=this.lipsyncWordsToVisemes(a,r);if(R&&R.visemes&&R.visemes.length){const M=R.times[R.visemes.length-1]+R.durations[R.visemes.length-1];for(let k=0;k<R.visemes.length;k++)y.push({mark:d,template:{name:"viseme"},ts:[(R.times[k]-.6)/M,(R.times[k]+.5)/M,(R.times[k]+R.durations[k]+.5)/M],vs:{["viseme_"+R.visemes[k]]:[null,R.visemes[k]==="PP"||R.visemes[k]==="FF"?.9:.6,0]}})}a="",d++}if(m||T){if(p.length||T&&y.length){const R={anim:y};t&&(R.onSubtitles=t),p.length&&!e.avatarMute&&(R.text=p,e.avatarMood&&(R.mood=e.avatarMood),e.ttsLang&&(R.lang=e.ttsLang),e.ttsVoice&&(R.voice=e.ttsVoice),e.ttsRate&&(R.rate=e.ttsRate),e.ttsVoice&&(R.pitch=e.ttsPitch),e.ttsVolume&&(R.volume=e.ttsVolume)),this.speechQueue.push(R),p=[],a="",d=0,y=[]}if(L){let R=this.animEmojis[A[v]];R&&R.link&&(R=this.animEmojis[R.link]),R&&this.speechQueue.push({emoji:R})}this.speechQueue.push({break:100})}}this.speechQueue.push({break:1e3}),this.startSpeaking()}async speakEmoji(n){let e=this.animEmojis[n];e&&e.link&&(e=this.animEmojis[e.link]),e&&this.speechQueue.push({emoji:e}),this.startSpeaking()}async speakBreak(n){this.speechQueue.push({break:n}),this.startSpeaking()}async speakMarker(n){this.speechQueue.push({marker:n}),this.startSpeaking()}async playBackgroundAudio(n){let t=await(await fetch(n)).arrayBuffer();this.stopBackgroundAudio(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource.loop=!0,this.audioBackgroundSource.buffer=await this.audioCtx.decodeAudioData(t),this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate,this.audioBackgroundSource.connect(this.audioBackgroundGainNode),this.audioBackgroundSource.start(0)}stopBackgroundAudio(){try{this.audioBackgroundSource.stop()}catch{}this.audioBackgroundSource.disconnect()}async setReverb(n=null){if(n){let t=await(await fetch(n)).arrayBuffer();this.audioReverbNode.buffer=await this.audioCtx.decodeAudioData(t)}else{const e=this.audioCtx.sampleRate,t=this.audioCtx.createBuffer(2,e,e);t.getChannelData(0)[0]=1,t.getChannelData(1)[0]=1,this.audioReverbNode.buffer=t}}setMixerGain(n,e=null,t=0){n!==null&&(this.audioSpeechGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),t?(this.audioSpeechGainNode.gain.setValueAtTime(Math.max(this.audioSpeechGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioSpeechGainNode.gain.exponentialRampToValueAtTime(Math.max(n,1e-4),this.audioCtx.currentTime+t)):this.audioSpeechGainNode.gain.setValueAtTime(n,this.audioCtx.currentTime)),e!==null&&(this.audioBackgroundGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),t?(this.audioBackgroundGainNode.gain.setValueAtTime(Math.max(this.audioBackgroundGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioBackgroundGainNode.gain.exponentialRampToValueAtTime(Math.max(e,1e-4),this.audioCtx.currentTime+t)):this.audioBackgroundGainNode.gain.setValueAtTime(e,this.audioCtx.currentTime))}speakAudio(n,e=null,t=null){e=e||{};const i=e.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,s={};if(n.words){let o=[];for(let l=0;l<n.words.length;l++){const h=n.words[l],r=n.wtimes[l];let u=n.wdurations[l];if(h.length&&(t&&o.push({template:{name:"subtitles"},ts:[r],vs:{subtitles:[" "+h]}}),!n.visemes)){const a=this.lipsyncPreProcessText(h,i),d=this.lipsyncWordsToVisemes(a,i);if(d&&d.visemes&&d.visemes.length){const p=d.times[d.visemes.length-1]+d.durations[d.visemes.length-1],y=Math.min(u,Math.max(0,u-d.visemes.length*150));let A=.6+this.convertRange(y,[0,u],[0,.4]);if(u=Math.min(u,d.visemes.length*200),p>0)for(let v=0;v<d.visemes.length;v++){const T=r+d.times[v]/p*u,C=d.durations[v]/p*u;o.push({template:{name:"viseme"},ts:[T-Math.min(60,2*C/3),T+Math.min(25,C/2),T+C+Math.min(60,C/2)],vs:{["viseme_"+d.visemes[v]]:[null,d.visemes[v]==="PP"||d.visemes[v]==="FF"?.9:A,0]}})}}}}if(n.visemes)for(let l=0;l<n.visemes.length;l++){const h=n.visemes[l],r=n.vtimes[l],u=n.vdurations[l];o.push({template:{name:"viseme"},ts:[r-2*u/3,r+u/2,r+u+u/2],vs:{["viseme_"+h]:[null,h==="PP"||h==="FF"?.9:.6,0]}})}if(n.markers)for(let l=0;l<n.markers.length;l++){const h=n.markers[l],r=n.mtimes[l];o.push({template:{name:"markers"},ts:[r],vs:{function:[h]}})}o.length&&(s.anim=o)}if(n.audio&&(s.audio=n.audio),n.anim?.name){let o=this.animFactory(n.anim,!1,1,1,!0);s.anim?s.anim.push(o):s.anim=[o]}t&&(s.onSubtitles=t),e.isRaw&&(s.isRaw=!0),Object.keys(s).length&&(this.speechQueue.push(s),s.isRaw||this.speechQueue.push({break:300}),this.startSpeaking())}async playAudio(n=!1){if(!(!this.armature||this.isAudioPlaying&&!n))if(this.isAudioPlaying=!0,this.audioPlaylist.length){const e=this.audioPlaylist.shift();if(this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const o=this.audioCtx.resume(),l=new Promise((h,r)=>setTimeout(()=>r("p2"),1e3));try{await Promise.race([o,l])}catch{console.log("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser."),this.playAudio(!0);return}}let t;if(Array.isArray(e.audio)){let o=this.concatArrayBuffers(e.audio);t=this.pcmToAudioBuffer(o)}else t=e.audio;if(this.audioSpeechSource){try{this.audioSpeechSource.stop?.()}catch{}this.audioSpeechSource.disconnect(),this.audioSpeechSource.onended=null,this.audioSpeechSource=null}const i=this.audioCtx.createBufferSource();this.audioSpeechSource=i,i.buffer=t,i.playbackRate.value=1/this.animSlowdownRate,i.connect(this.audioAnalyzerNode),i.onended=()=>{i.disconnect(),i.onended=null,this.audioSpeechSource===i&&(this.audioSpeechSource=null),this.playAudio(!0)};let s=0;e.anim&&(e.isRaw||(s=Math.abs(Math.min(0,...e.anim.map(o=>Math.min(...o.ts))))),e.anim.forEach(o=>{for(let l=0;l<o.ts.length;l++)o.ts[l]=this.animClock+o.ts[l]+s;this.animQueue.push(o)})),i.start(this.audioCtx.currentTime+s/1e3)}else this.isAudioPlaying=!1,this.startSpeaking(!0)}async startSpeaking(n=!1){if(!(!this.armature||this.isSpeaking&&!n))if(this.stateName="speaking",this.isSpeaking=!0,this.speechQueue.length){let e=this.speechQueue.shift();if(e.emoji){this.lookAtCamera(500);let t=e.emoji.dt.reduce((i,s)=>i+s,0);this.animQueue.push(this.animFactory(e.emoji)),setTimeout(this.startSpeaking.bind(this),t,!0)}else if(e.break)setTimeout(this.startSpeaking.bind(this),e.break,!0);else if(e.audio)e.isRaw||(this.lookAtCamera(500),this.speakWithHands(),this.resetLips()),this.audioPlaylist.push({anim:e.anim,audio:e.audio,isRaw:e.isRaw}),this.onSubtitles=e.onSubtitles||null,e.mood&&this.setMood(e.mood),this.playAudio();else if(e.text){this.lookAtCamera(500);try{let t="<speak>";e.text.forEach((l,h)=>{h>0&&(t+=" <mark name='"+l.mark+"'/>"),t+=l.word.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replace(new RegExp("^\\p{Dash_Punctuation}$","ug"),'<break time="750ms"/>')}),t+="</speak>";const i={method:"POST",headers:{"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify({input:{ssml:t},voice:{languageCode:e.lang||this.avatar.ttsLang||this.opt.ttsLang,name:e.voice||this.avatar.ttsVoice||this.opt.ttsVoice},audioConfig:{audioEncoding:this.ttsAudioEncoding,speakingRate:(e.rate||this.avatar.ttsRate||this.opt.ttsRate)+this.mood.speech.deltaRate,pitch:(e.pitch||this.avatar.ttsPitch||this.opt.ttsPitch)+this.mood.speech.deltaPitch,volumeGainDb:(e.volume||this.avatar.ttsVolume||this.opt.ttsVolume)+this.mood.speech.deltaVolume},enableTimePointing:[1]})};this.opt.jwtGet&&typeof this.opt.jwtGet=="function"&&(i.headers.Authorization="Bearer "+await this.opt.jwtGet());const s=await fetch(this.opt.ttsEndpoint+(this.opt.ttsApikey?"?key="+this.opt.ttsApikey:""),i),o=await s.json();if(s.status===200&&o&&o.audioContent){const l=this.b64ToArrayBuffer(o.audioContent),h=await this.audioCtx.decodeAudioData(l);this.speakWithHands();const r=[0];let u=0;e.text.forEach((p,y)=>{if(y>0){let A=r[r.length-1];o.timepoints[u]&&(A=o.timepoints[u].timeSeconds*1e3,o.timepoints[u].markName===""+p.mark&&u++),r.push(A)}});const a=[{mark:0,time:0}];r.forEach((p,y)=>{if(y>0){let A=p-r[y-1];A>150&&A-150,a[y-1].duration=A,a.push({mark:y,time:p})}});let d=1e3*h.duration;d>this.opt.ttsTrimEnd&&(d=d-this.opt.ttsTrimEnd),a[a.length-1].duration=d-a[a.length-1].time,e.anim.forEach(p=>{const y=a[p.mark];if(y)for(let A=0;A<p.ts.length;A++)p.ts[A]=y.time+p.ts[A]*y.duration+this.opt.ttsTrimStart}),this.audioPlaylist.push({anim:e.anim,audio:h}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio()}else this.startSpeaking(!0)}catch(t){console.error("Error:",t),this.startSpeaking(!0)}}else e.anim?(this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),e.anim.forEach((t,i)=>{for(let s=0;s<t.ts.length;s++)t.ts[s]=this.animClock+10*i;this.animQueue.push(t)}),setTimeout(this.startSpeaking.bind(this),10*e.anim.length,!0)):e.marker?(typeof e.marker=="function"&&e.marker(),this.startSpeaking(!0)):this.startSpeaking(!0)}else this.stateName="idle",this.isSpeaking=!1}pauseSpeaking(){try{this.audioSpeechSource?.stop()}catch{}this.audioPlaylist.length=0,this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.animQueue=this.animQueue.filter(n=>n.template.name!=="viseme"&&n.template.name!=="subtitles"&&n.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render())}stopSpeaking(){try{this.audioSpeechSource?.stop()}catch{}this.audioPlaylist.length=0,this.speechQueue.length=0,this.animQueue=this.animQueue.filter(n=>n.template.name!=="viseme"&&n.template.name!=="subtitles"&&n.template.name!=="blendshapes"),this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.armature&&(this.resetLips(),this.render())}async streamStart(n={},e=null,t=null,i=null,s=null){if(this.stopSpeaking(),this.isStreaming=!0,n.waitForAudioChunks!==void 0&&(this.streamWaitForAudioChunks=n.waitForAudioChunks),this.streamWaitForAudioChunks||(this.streamAudioStartTime=this.animClock),this.streamLipsyncQueue=[],this.streamLipsyncType=n.lipsyncType||this.streamLipsyncType||"visemes",this.streamLipsyncLang=n.lipsyncLang||this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,this.onAudioStart=e,this.onAudioEnd=t,this.onMetrics=s,n.sampleRate!==void 0){const l=n.sampleRate;typeof l=="number"&&l>=8e3&&l<=96e3?l!==this.audioCtx.sampleRate&&this.initAudioGraph(l):console.warn("Invalid sampleRate provided. It must be a number between 8000 and 96000 Hz.")}if(n.gain!==void 0&&(this.audioStreamGainNode.gain.value=n.gain),!this.streamWorkletNode||!this.streamWorkletNode.port||this.streamWorkletNode.numberOfOutputs===0||this.streamWorkletNode.context!==this.audioCtx){if(this.streamWorkletNode)try{this.streamWorkletNode.disconnect(),this.streamWorkletNode=null}catch{}if(!this.workletLoaded)try{const l=this.audioCtx.audioWorklet.addModule(ht.href),h=new Promise((r,u)=>setTimeout(()=>u(new Error("Worklet loading timed out")),5e3));await Promise.race([l,h]),this.workletLoaded=!0}catch(l){throw console.error("Failed to load audio worklet:",l),new Error("Failed to initialize streaming speech")}this.streamWorkletNode=new AudioWorkletNode(this.audioCtx,"playback-worklet",{processorOptions:{sampleRate:this.audioCtx.sampleRate,metrics:n.metrics||{enabled:!1}}}),this.streamWorkletNode.connect(this.audioStreamGainNode),this.streamWorkletNode.connect(this.audioAnalyzerNode),this.streamWorkletNode.port.onmessage=l=>{if(l.data.type==="playback-started"&&(this.isSpeaking=!0,this.stateName="speaking",this.streamWaitForAudioChunks&&(this.streamAudioStartTime=this.animClock),this._processStreamLipsyncQueue(),this.speakWithHands(),this.onAudioStart))try{this.onAudioStart?.()}catch(h){console.error(h)}if(l.data.type==="playback-ended"&&(this._streamPause(),this.onAudioEnd))try{this.onAudioEnd()}catch{}if(this.onMetrics&&l.data.type==="metrics")try{this.onMetrics(l.data)}catch{}}}if(n.metrics)try{this.streamWorkletNode.port.postMessage({type:"config-metrics",data:n.metrics})}catch{}if(this.resetLips(),this.lookAtCamera(500),n.mood&&this.setMood(n.mood),this.onSubtitles=i||null,this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const l=this.audioCtx.resume(),h=new Promise((r,u)=>setTimeout(()=>u("p2"),1e3));try{await Promise.race([l,h])}catch{console.warn("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser.");return}}}streamNotifyEnd(){!this.isStreaming||!this.streamWorkletNode||this.streamWorkletNode.port.postMessage({type:"no-more-data"})}streamInterrupt(){if(!this.isStreaming)return;const n=this.isSpeaking;if(this.streamWorkletNode)try{this.streamWorkletNode.port.postMessage({type:"stop"})}catch{}if(this._streamPause(!0),n&&this.onAudioEnd)try{this.onAudioEnd()}catch{}}streamStop(){if(this.isStreaming){if(this.streamInterrupt(),this.streamWorkletNode){try{this.streamWorkletNode.disconnect()}catch{}this.streamWorkletNode=null}this.isStreaming=!1}}_streamPause(n=!1){this.isSpeaking=!1,this.stateName="idle",n&&(this.streamWaitForAudioChunks&&(this.streamAudioStartTime=null),this.streamLipsyncQueue=[],this.animQueue=this.animQueue.filter(e=>e.template.name!=="viseme"&&e.template.name!=="subtitles"&&e.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render()))}_processStreamLipsyncQueue(){if(this.isStreaming)for(;this.streamLipsyncQueue.length>0;){const n=this.streamLipsyncQueue.shift();this._processLipsyncData(n,this.streamAudioStartTime)}}_processLipsyncData(n,e){if(this.isStreaming){if(n.visemes&&this.streamLipsyncType=="visemes")for(let t=0;t<n.visemes.length;t++){const i=n.visemes[t],s=e+n.vtimes[t],o=n.vdurations[t],l={template:{name:"viseme"},ts:[s-2*o/3,s+o/2,s+o+o/2],vs:{["viseme_"+i]:[null,i==="PP"||i==="FF"?.9:.6,0]}};this.animQueue.push(l)}if(n.words&&(this.onSubtitles||this.streamLipsyncType=="words"))for(let t=0;t<n.words.length;t++){const i=n.words[t],s=n.wtimes[t];let o=n.wdurations[t];if(i.length&&(this.onSubtitles&&this.animQueue.push({template:{name:"subtitles"},ts:[e+s],vs:{subtitles:[" "+i]}}),this.streamLipsyncType=="words")){const l=this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,h=this.lipsyncPreProcessText(i,l),r=this.lipsyncWordsToVisemes(h,l);if(r&&r.visemes&&r.visemes.length){const u=r.times[r.visemes.length-1]+r.durations[r.visemes.length-1],a=Math.min(o,Math.max(0,o-r.visemes.length*150));let d=.6+this.convertRange(a,[0,o],[0,.4]);if(o=Math.min(o,r.visemes.length*200),u>0)for(let p=0;p<r.visemes.length;p++){const y=e+s+r.times[p]/u*o,A=r.durations[p]/u*o;this.animQueue.push({template:{name:"viseme"},ts:[y-Math.min(60,2*A/3),y+Math.min(25,A/2),y+A+Math.min(60,A/2)],vs:{["viseme_"+r.visemes[p]]:[null,r.visemes[p]==="PP"||r.visemes[p]==="FF"?.9:d,0]}})}}}}if(n.anims&&this.streamLipsyncType=="blendshapes")for(let t=0;t<n.anims.length;t++){let i=n.anims[t];i.delay+=e;let s=this.animFactory(i,!1,1,1,!0);this.animQueue.push(s)}}}streamAudio(n){if(!(!this.isStreaming||!this.streamWorkletNode)){if(this.isSpeaking||(this.streamLipsyncQueue=[],this.streamAudioStartTime=null),this.isSpeaking=!0,this.stateName="speaking",n.audio!==void 0){const e={type:"audioData",data:null};if(n.audio instanceof ArrayBuffer)e.data=n.audio,this.streamWorkletNode.port.postMessage(e,[e.data]);else if(n.audio instanceof Int16Array||n.audio instanceof Uint8Array){const t=n.audio.buffer.slice(n.audio.byteOffset,n.audio.byteOffset+n.audio.byteLength);e.data=t,this.streamWorkletNode.port.postMessage(e,[e.data])}else if(n.audio instanceof Float32Array){const t=new Int16Array(n.audio.length);for(let i=0;i<n.audio.length;i++){let s=Math.max(-1,Math.min(1,n.audio[i]));t[i]=s<0?s*32768:s*32767}e.data=t.buffer,this.streamWorkletNode.port.postMessage(e,[e.data])}else console.error("r.audio is not a supported type. Must be ArrayBuffer, Int16Array, Uint8Array, or Float32Array:",n.audio)}if(n.visemes||n.anims||n.words){if(this.streamWaitForAudioChunks&&!this.streamAudioStartTime){this.streamLipsyncQueue.length>=200&&this.streamLipsyncQueue.shift(),this.streamLipsyncQueue.push(n);return}else!this.streamWaitForAudioChunks&&!this.streamAudioStartTime&&(this.streamAudioStartTime=this.animClock);this._processLipsyncData(n,this.streamAudioStartTime)}}}makeEyeContact(n){this.animQueue.push(this.animFactory({name:"eyecontact",dt:[0,n],vs:{eyeContact:[1]}}))}lookAhead(n){if(n){let e=(Math.random()-.5)/4,t=(Math.random()-.5)/4,i=this.animQueue.findIndex(o=>o.template.name==="lookat");i!==-1&&this.animQueue.splice(i,1);const s={name:"lookat",dt:[750,n],vs:{bodyRotateX:[e],bodyRotateY:[t],eyesRotateX:[-3*e+.1],eyesRotateY:[-5*t],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(s))}}lookAtCamera(n){let e;if(this.speakTo&&(e=new g.Vector3,this.speakTo.objectLeftEye?.isObject3D?(this.speakTo.armature.objectHead,this.speakTo.objectLeftEye.updateMatrixWorld(!0),this.speakTo.objectRightEye.updateMatrixWorld(!0),fe.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld),xe.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld),e.addVectors(fe,xe).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){if(this.avatar.hasOwnProperty("avatarIgnoreCamera")){if(this.avatar.avatarIgnoreCamera){this.lookAhead(n);return}}else if(this.opt.avatarIgnoreCamera){this.lookAhead(n);return}this.lookAt(null,null,n);return}this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0),fe.setFromMatrixPosition(this.objectLeftEye.matrixWorld),xe.setFromMatrixPosition(this.objectRightEye.matrixWorld),fe.add(xe).divideScalar(2),_.copy(this.armature.quaternion),_.multiply(this.poseTarget.props["Hips.quaternion"]),_.multiply(this.poseTarget.props["Spine.quaternion"]),_.multiply(this.poseTarget.props["Spine1.quaternion"]),_.multiply(this.poseTarget.props["Spine2.quaternion"]),_.multiply(this.poseTarget.props["Neck.quaternion"]),_.multiply(this.poseTarget.props["Head.quaternion"]);const t=new g.Vector3().subVectors(e,fe).normalize(),i=Math.atan2(t.x,t.z),s=Math.asin(-t.y);G.set(s,i,0,"YXZ");const l=new g.Quaternion().setFromEuler(G),h=new g.Quaternion().copy(l).multiply(_.clone().invert());G.setFromQuaternion(h,"YXZ");let r=G.x/(40/24)+.2,u=G.y/(9/4),a=Math.min(.6,Math.max(-.3,r)),d=Math.min(.8,Math.max(-.8,u)),p=(Math.random()-.5)/4,y=(Math.random()-.5)/4;if(n){let A=this.animQueue.findIndex(T=>T.template.name==="lookat");A!==-1&&this.animQueue.splice(A,1);const v={name:"lookat",dt:[750,n],vs:{bodyRotateX:[a+p],bodyRotateY:[d+y],eyesRotateX:[-3*p+.1],eyesRotateY:[-5*y],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(v))}}lookAt(n,e,t){if(!this.camera)return;const i=this.nodeAvatar.getBoundingClientRect();this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0);const s=new g.Vector3().setFromMatrixPosition(this.objectLeftEye.matrixWorld),o=new g.Vector3().setFromMatrixPosition(this.objectRightEye.matrixWorld),l=new g.Vector3().addVectors(s,o).divideScalar(2);l.project(this.camera);let h=(l.x+1)/2*i.width+i.left,r=-(l.y-1)/2*i.height+i.top;n===null&&(n=h),e===null&&(e=r),_.copy(this.armature.quaternion),_.multiply(this.poseTarget.props["Hips.quaternion"]),_.multiply(this.poseTarget.props["Spine.quaternion"]),_.multiply(this.poseTarget.props["Spine1.quaternion"]),_.multiply(this.poseTarget.props["Spine2.quaternion"]),_.multiply(this.poseTarget.props["Neck.quaternion"]),_.multiply(this.poseTarget.props["Head.quaternion"]),G.setFromQuaternion(_);let u=G.x/(40/24),a=G.y/(9/4),d=Math.min(.4,Math.max(-.4,this.camera.rotation.x)),p=Math.min(.4,Math.max(-.4,this.camera.rotation.y)),y=Math.max(window.innerWidth-h,h),A=Math.max(window.innerHeight-r,r),v=this.convertRange(e,[r-A,r+A],[-.3,.6])-u+d,T=this.convertRange(n,[h-y,h+y],[-.8,.8])-a+p;v=Math.min(.6,Math.max(-.3,v)),T=Math.min(.8,Math.max(-.8,T));let C=(Math.random()-.5)/4,m=(Math.random()-.5)/4;if(t){let L=this.animQueue.findIndex(R=>R.template.name==="lookat");L!==-1&&this.animQueue.splice(L,1);const E={name:"lookat",dt:[750,t],vs:{bodyRotateX:[v+C],bodyRotateY:[T+m],eyesRotateX:[-3*C+.1],eyesRotateY:[-5*m],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(E))}}touchAt(n,e){if(!this.camera)return;const t=this.nodeAvatar.getBoundingClientRect(),i=new g.Vector2((n-t.left)/t.width*2-1,-((e-t.top)/t.height)*2+1),s=new g.Raycaster;s.setFromCamera(i,this.camera);const o=s.intersectObject(this.armature);if(o.length>0){const l=o[0].point,h=new g.Vector3,r=new g.Vector3;this.objectLeftArm.getWorldPosition(h),this.objectRightArm.getWorldPosition(r);const u=h.distanceToSquared(l),a=r.distanceToSquared(l);u<a?(this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3,maxAngle:.2},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},l,!1,1e3),this.setValue("handFistLeft",0)):(this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},l,!1,1e3),this.setValue("handFistRight",0))}else["LeftArm","LeftForeArm","LeftHand","RightArm","RightForeArm","RightHand"].forEach(l=>{let h=l+".quaternion";this.poseTarget.props[h].copy(this.getPoseTemplateProp(h)),this.poseTarget.props[h].t=this.animClock,this.poseTarget.props[h].d=1e3});return o.length>0}speakWithHands(n=0,e=.5){if(this.mixer||this.gesture||!this.poseTarget.template.standing||this.poseTarget.template.bend||Math.random()>e)return;this.ikSolve({root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-1,maxz:3}]},new g.Vector3(this.gaussianRandom(0,.5),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0),this.ikSolve({root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5},{link:"RightArm"}]},new g.Vector3(this.gaussianRandom(-.5,0),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0);const t=[],i=[];t.push(100+Math.round(Math.random()*500)),i.push({duration:1e3,props:{"LeftHand.quaternion":new g.Quaternion().setFromEuler(new g.Euler(0,-1-Math.random(),0)),"RightHand.quaternion":new g.Quaternion().setFromEuler(new g.Euler(0,1+Math.random(),0))}}),["LeftArm","LeftForeArm","RightArm","RightForeArm"].forEach(o=>{i[0].props[o+".quaternion"]=this.ikMesh.getObjectByName(o).quaternion.clone()}),t.push(1e3+Math.round(Math.random()*500)),i.push({duration:2e3,props:{}}),["LeftArm","LeftForeArm","RightArm","RightForeArm","LeftHand","RightHand"].forEach(o=>{i[1].props[o+".quaternion"]=null});const s=this.animFactory({name:"talkinghands",delay:n,dt:t,vs:{moveto:i}});this.animQueue.push(s)}getSlowdownRate(n){return this.animSlowdownRate}setSlowdownRate(n){this.animSlowdownRate=n,this.audioSpeechSource&&(this.audioSpeechSource.playbackRate.value=1/this.animSlowdownRate),this.audioBackgroundSource&&(this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate)}getAutoRotateSpeed(n){return this.controls?this.controls.autoRotateSpeed:0}setAutoRotateSpeed(n){this.controls&&(this.controls.autoRotateSpeed=n,this.controls.autoRotate=n>0)}start(){this.armature&&this.isRunning===!1&&(this.audioCtx.resume(),this.animTimeLast=performance.now(),this.isRunning=!0,this.isAvatarOnly||(this._raf=requestAnimationFrame(this.animate)))}stop(){this.isRunning=!1,this.audioCtx.suspend()}startListening(n,e={},t=null){this.listeningAnalyzer=n,this.listeningAnalyzer.fftSize=256,this.listeningAnalyzer.smoothingTimeConstant=.1,this.listeningAnalyzer.minDecibels=-70,this.listeningAnalyzer.maxDecibels=-10,this.listeningOnchange=t&&typeof t=="function"?t:null,this.listeningSilenceThresholdLevel=e?.hasOwnProperty("listeningSilenceThresholdLevel")?e.listeningSilenceThresholdLevel:this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=e?.hasOwnProperty("listeningSilenceThresholdMs")?e.listeningSilenceThresholdMs:this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=e?.hasOwnProperty("listeningSilenceDurationMax")?e.listeningSilenceDurationMax:this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=e?.hasOwnProperty("listeningActiveThresholdLevel")?e.listeningActiveThresholdLevel:this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=e?.hasOwnProperty("listeningActiveThresholdMs")?e.listeningActiveThresholdMs:this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=e?.hasOwnProperty("listeningActiveDurationMax")?e.listeningActiveDurationMax:this.opt.listeningActiveDurationMax,this.listeningActive=!1,this.listeningVolume=0,this.listeningTimer=0,this.listeningTimerTotal=0,this.isListening=!0}stopListening(){this.isListening=!1}async playAnimation(n,e=null,t=10,i=0,s=.01,o=!1){if(!this.armature)return;this.positionWasLocked=!o,o?console.log("Position locking disabled for FBX animation:",n):(this.lockAvatarPosition(),console.log("Position locked immediately before FBX animation:",n));let l=this.animClips.find(h=>h.url===n+"-"+i);if(l){let h=this.animQueue.find(a=>a.template.name==="pose");h&&(h.ts[0]=1/0),Object.entries(l.pose.props).forEach(a=>{this.poseBase.props[a[0]]=a[1].clone(),this.poseTarget.props[a[0]]=a[1].clone(),this.poseTarget.props[a[0]].t=0,this.poseTarget.props[a[0]].d=1e3}),this.mixer?console.log("Using existing mixer for FBX animation, preserving morph targets"):(this.mixer=new g.AnimationMixer(this.armature),console.log("Created new mixer for FBX animation")),this.mixer.addEventListener("finished",this.stopAnimation.bind(this),{once:!0});const r=Math.ceil(t/l.clip.duration),u=this.mixer.clipAction(l.clip);u.setLoop(g.LoopRepeat,r),u.clampWhenFinished=!0,this.currentFBXAction=u;try{u.fadeIn(.5).play(),console.log("FBX animation started successfully:",n)}catch(a){console.warn("FBX animation failed to start:",a),this.stopAnimation();return}if(u.getClip().tracks.length===0){console.warn("FBX animation has no valid tracks, stopping"),this.stopAnimation();return}}else{let r=await new Oe.FBXLoader().loadAsync(n,e);if(r&&r.animations&&r.animations[i]){let u=r.animations[i];const a=new Set;this.armature&&this.armature.traverse(C=>{(C.isBone||C.type==="Bone")&&a.add(C.name)});const d=new Map,p=C=>{if(a.has(C))return C;let m=C.replace(/^mixamorig/i,"").replace(/^CC_Base_/i,"").replace(/^RPM_/i,"");if(a.has(m))return m;const L=m.toLowerCase();if(L.includes("left")&&L.includes("arm")){if(L.includes("fore")||L.includes("lower")){if(a.has("LeftForeArm"))return"LeftForeArm";if(a.has("LeftForearm"))return"LeftForearm"}else if(!L.includes("fore")&&!L.includes("hand")&&a.has("LeftArm"))return"LeftArm"}if(L.includes("right")&&L.includes("arm")){if(L.includes("fore")||L.includes("lower")){if(a.has("RightForeArm"))return"RightForeArm";if(a.has("RightForearm"))return"RightForearm"}else if(!L.includes("fore")&&!L.includes("hand")&&a.has("RightArm"))return"RightArm"}if(L.includes("left")&&L.includes("hand")&&!L.includes("index")&&!L.includes("thumb")&&!L.includes("middle")&&!L.includes("ring")&&!L.includes("pinky")&&a.has("LeftHand"))return"LeftHand";if(L.includes("right")&&L.includes("hand")&&!L.includes("index")&&!L.includes("thumb")&&!L.includes("middle")&&!L.includes("ring")&&!L.includes("pinky")&&a.has("RightHand"))return"RightHand";if(L.includes("left")&&(L.includes("shoulder")||L.includes("clavicle"))&&a.has("LeftShoulder"))return"LeftShoulder";if(L.includes("right")&&(L.includes("shoulder")||L.includes("clavicle"))&&a.has("RightShoulder"))return"RightShoulder";const E={LeftArm:"LeftArm",leftArm:"LeftArm",LEFTARM:"LeftArm",RightArm:"RightArm",rightArm:"RightArm",RIGHTARM:"RightArm",LeftForeArm:"LeftForeArm",leftForeArm:"LeftForeArm",leftForearm:"LeftForeArm",LeftForearm:"LeftForeArm",RightForeArm:"RightForeArm",rightForeArm:"RightForeArm",rightForearm:"RightForeArm",RightForearm:"RightForeArm",LeftHand:"LeftHand",leftHand:"LeftHand",RightHand:"RightHand",rightHand:"RightHand",LeftShoulder:"LeftShoulder",leftShoulder:"LeftShoulder",RightShoulder:"RightShoulder",rightShoulder:"RightShoulder",Spine:"Spine1",spine:"Spine1",Spine1:"Spine1",Spine2:"Spine2",Head:"Head",head:"Head",Neck:"Neck",neck:"Neck",Hips:"Hips",hips:"Hips",Root:"Hips",root:"Hips"};if(E[m]){const R=E[m];if(a.has(R))return R}for(const R of a)if(R.toLowerCase()===L)return R;for(const R of a){const M=R.toLowerCase();if((L.includes("left")&&M.includes("left")||L.includes("right")&&M.includes("right"))&&(L.includes("arm")&&M.includes("arm")&&!M.includes("fore")||L.includes("forearm")&&M.includes("forearm")||L.includes("hand")&&M.includes("hand")&&!M.includes("index")&&!M.includes("thumb")||L.includes("shoulder")&&M.includes("shoulder")))return R}return null},y=[],A=new Set;u.tracks.forEach(C=>{const L=C.name.replaceAll("mixamorig","").split("."),E=L[0],R=L[1],M=p(E);if(M&&R){const k=`${M}.${R}`,ie=C.clone();ie.name=k,y.push(ie),E!==M&&d.set(E,M)}else A.add(E)}),A.size>0&&console.warn(`⚠️ ${A.size} bone(s) could not be mapped:`,Array.from(A).sort().join(", ")),y.length>0&&(u=new g.AnimationClip(u.name,u.duration,y),console.log(`✓ Created animation with ${y.length} mapped tracks (from ${u.tracks.length} original tracks)`),d.size>0&&console.log(`✓ Mapped ${d.size} bone(s):`,Array.from(d.entries()).map(([C,m])=>`${C}→${m}`).join(", ")));const v={};u.tracks.forEach(C=>{const m=C.name.split(".");if(m[1]==="position"){for(let L=0;L<C.values.length;L++)C.values[L]=C.values[L]*s;v[C.name]=new g.Vector3(C.values[0],C.values[1],C.values[2])}else m[1]==="quaternion"?v[C.name]=new g.Quaternion(C.values[0],C.values[1],C.values[2],C.values[3]):m[1]==="rotation"&&(v[m[0]+".quaternion"]=new g.Quaternion().setFromEuler(new g.Euler(C.values[0],C.values[1],C.values[2],"XYZ")).normalize())});const T={props:v};v["Hips.position"]&&(v["Hips.position"].y<.5?T.lying=!0:T.standing=!0),this.animClips.push({url:n+"-"+i,clip:u,pose:T}),this.playAnimation(n,e,t,i,s)}else{const u="Animation "+n+" (ndx="+i+") not found";console.error(u)}}}stopAnimation(){if(this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null),this.positionWasLocked?(this.unlockAvatarPosition(),console.log("Position unlocked after FBX animation stopped")):console.log("Position was not locked, no unlock needed"),this.gesture&&this.poseTarget&&this.poseTarget.props)for(let[n,e]of Object.entries(this.gesture))e.t=this.animClock,e.d=1e3,this.poseTarget.props.hasOwnProperty(n)&&(this.poseTarget.props[n].copy(e),this.poseTarget.props[n].t=this.animClock,this.poseTarget.props[n].d=1e3);if(this.animQueue){let n=this.animQueue.find(e=>e.template.name==="pose");n&&(n.ts[0]=this.animClock)}this.poseFactory&&this.setPoseFromTemplate(null)}async playPose(n,e=null,t=5,i=0,s=.01){if(!this.armature)return;let o=this.poseTemplates[n];if(!o){const l=this.animPoses.find(h=>h.url===n+"-"+i);l&&(o=l.pose)}if(o){this.poseName=n,this.mixer&&(this.mixer.removeEventListener("finished",this._mixerHandler),this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.armature),this.mixer=null,this._mixerHandler=null);let l=this.animQueue.find(h=>h.template.name==="pose");l&&(l.ts[0]=this.animClock+t*1e3+2e3),this.setPoseFromTemplate(o)}else{let h=await new Oe.FBXLoader().loadAsync(n,e);if(h&&h.animations&&h.animations[i]){let r=h.animations[i];const u={};r.tracks.forEach(d=>{d.name=d.name.replaceAll("mixamorig","");const p=d.name.split(".");p[1]==="position"?u[d.name]=new g.Vector3(d.values[0]*s,d.values[1]*s,d.values[2]*s):p[1]==="quaternion"?u[d.name]=new g.Quaternion(d.values[0],d.values[1],d.values[2],d.values[3]):p[1]==="rotation"&&(u[p[0]+".quaternion"]=new g.Quaternion().setFromEuler(new g.Euler(d.values[0],d.values[1],d.values[2],"XYZ")).normalize())});const a={props:u};u["Hips.position"]&&(u["Hips.position"].y<.5?a.lying=!0:a.standing=!0),this.animPoses.push({url:n+"-"+i,pose:a}),this.playPose(n,e,t,i,s)}else{const r="Pose "+n+" (ndx="+i+") not found";console.error(r)}}}stopPose(){this.stopAnimation()}playGesture(n,e=3,t=!1,i=1e3){if(!this.armature)return;let s=this.gestureTemplates[n];if(s){this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null);let l=this.animQueue.findIndex(h=>h.template.name==="talkinghands");l!==-1&&(this.animQueue[l].ts=this.animQueue[l].ts.map(h=>0)),this.gesture=this.propsToThreeObjects(s),t&&(this.gesture=this.mirrorPose(this.gesture)),n==="namaste"&&this.avatar.body==="M"&&(this.gesture["RightArm.quaternion"].rotateTowards(new g.Quaternion(0,1,0,0),-.25),this.gesture["LeftArm.quaternion"].rotateTowards(new g.Quaternion(0,1,0,0),-.25));for(let[h,r]of Object.entries(this.gesture))r.t=this.animClock,r.d=i,this.poseTarget.props.hasOwnProperty(h)&&(this.poseTarget.props[h].copy(r),this.poseTarget.props[h].t=this.animClock,this.poseTarget.props[h].d=i);e&&Number.isFinite(e)&&(this.gestureTimeout=setTimeout(this.stopGesture.bind(this,i),1e3*e))}let o=this.animEmojis[n];if(o&&(o&&o.link&&(o=this.animEmojis[o.link]),o)){this.lookAtCamera(500);const l=this.animFactory(o);if(l.gesture=!0,e&&Number.isFinite(e)){const h=l.ts[0],u=l.ts[l.ts.length-1]-h;if(e*1e3-u>0){const d=[];for(let A=1;A<l.ts.length;A++)d.push(l.ts[A]-l.ts[A-1]);const p=o.template?.rescale||d.map(A=>A/u),y=e*1e3-u;l.ts=l.ts.map((A,v,T)=>v===0?h:T[v-1]+d[v-1]+p[v-1]*y)}else{const d=e*1e3/u;l.ts=l.ts.map(p=>h+d*(p-h))}}this.animQueue.push(l)}}stopGesture(n=1e3){if(this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null),this.gesture){const t=Object.entries(this.gesture);this.gesture=null;for(const[i,s]of t)this.poseTarget.props.hasOwnProperty(i)&&(this.poseTarget.props[i].copy(this.getPoseTemplateProp(i)),this.poseTarget.props[i].t=this.animClock,this.poseTarget.props[i].d=n)}let e=this.animQueue.findIndex(t=>t.gesture);e!==-1&&this.animQueue.splice(e,1)}ikSolve(n,e=null,t=!1,i=null){const s=new g.Vector3,o=new g.Vector3,l=new g.Vector3,h=new g.Vector3,r=new g.Quaternion,u=new g.Vector3,a=new g.Vector3,d=new g.Vector3,p=this.ikMesh.getObjectByName(n.root);p.position.setFromMatrixPosition(this.armature.getObjectByName(n.root).matrixWorld),p.quaternion.setFromRotationMatrix(this.armature.getObjectByName(n.root).matrixWorld),e&&t&&e.applyQuaternion(this.armature.quaternion).add(p.position);const y=this.ikMesh.getObjectByName(n.effector),A=n.links;A.forEach(T=>{T.bone=this.ikMesh.getObjectByName(T.link),T.bone.quaternion.copy(this.getPoseTemplateProp(T.link+".quaternion"))}),p.updateMatrixWorld(!0);const v=n.iterations||10;if(e)for(let T=0;T<v;T++){let C=!1;for(let m=0,L=A.length;m<L;m++){const E=A[m].bone;E.matrixWorld.decompose(h,r,u),r.invert(),o.setFromMatrixPosition(y.matrixWorld),l.subVectors(o,h),l.applyQuaternion(r),l.normalize(),s.subVectors(e,h),s.applyQuaternion(r),s.normalize();let R=s.dot(l);R>1?R=1:R<-1&&(R=-1),R=Math.acos(R),!(R<1e-5)&&(A[m].minAngle!==void 0&&R<A[m].minAngle&&(R=A[m].minAngle),A[m].maxAngle!==void 0&&R>A[m].maxAngle&&(R=A[m].maxAngle),a.crossVectors(l,s),a.normalize(),_.setFromAxisAngle(a,R),E.quaternion.multiply(_),E.rotation.setFromVector3(d.setFromEuler(E.rotation).clamp(new g.Vector3(A[m].minx!==void 0?A[m].minx:-1/0,A[m].miny!==void 0?A[m].miny:-1/0,A[m].minz!==void 0?A[m].minz:-1/0),new g.Vector3(A[m].maxx!==void 0?A[m].maxx:1/0,A[m].maxy!==void 0?A[m].maxy:1/0,A[m].maxz!==void 0?A[m].maxz:1/0))),E.updateMatrixWorld(!0),C=!0)}if(!C)break}i&&A.forEach(T=>{this.poseTarget.props[T.link+".quaternion"].copy(T.bone.quaternion),this.poseTarget.props[T.link+".quaternion"].t=this.animClock,this.poseTarget.props[T.link+".quaternion"].d=i})}async initializeFBXAnimationLoader(){try{const{FBXAnimationLoader:n}=await Promise.resolve().then(()=>require("./fbxAnimationLoader-CNrfhJRz.cjs"));this.fbxAnimationLoader=new n(this.armature),console.log("FBX Animation Loader initialized")}catch(n){console.warn("FBX Animation Loader not available:",n),this.fbxAnimationLoader=null}}setBodyMovement(n){this.bodyMovement=n,this.avatar&&(this.avatar.bodyMovement=n),console.log("Body movement set to:",n),n==="idle"&&this.unlockAvatarPosition(),this.applyBodyMovementAnimation()}async applyBodyMovementAnimation(){if(!this.armature||!this.animQueue){console.log("Avatar not ready for body movement animations");return}console.log("Avatar is running:",this.isRunning),console.log("Animation queue exists:",!!this.animQueue);const n=this.animQueue.length;this.animQueue=this.animQueue.filter(i=>!i.template.name.startsWith("bodyMovement"));const e=this.animQueue.length;if(console.log(`Filtered animation queue: ${n} -> ${e} animations`),this.bodyMovement==="idle"){this.fbxAnimationLoader&&this.fbxAnimationLoader.stopCurrentAnimation();return}if(this.fbxAnimationLoader)try{await this.fbxAnimationLoader.playGestureAnimation(this.bodyMovement,this.movementIntensity),console.log("Applied FBX body movement animation:",this.bodyMovement);return}catch(i){console.warn("FBX animation failed, falling back to code animation:",i)}const t=this.createBodyMovementAnimation(this.bodyMovement);if(console.log("Created movement animation:",t),t)try{const i=this.animFactory(t,!0);i&&i.ts&&i.ts.length>0?(this.animQueue.push(i),console.log("Applied code-based body movement animation:",this.bodyMovement),console.log("Animation queue length:",this.animQueue.length),console.log("Animation object:",i)):(console.error("Invalid animation object created for:",this.bodyMovement),console.error("Animation object:",i))}catch(i){console.error("Error creating body movement animation:",i)}}lockAvatarPosition(){if(!this.armature){console.warn("Cannot lock position: armature not available");return}this.originalPosition||(this.originalPosition={x:this.armature.position.x,y:this.armature.position.y,z:this.armature.position.z},console.log("Original position stored:",this.originalPosition)),this.lockedPosition={x:this.armature.position.x,y:this.armature.position.y,z:this.armature.position.z},console.log("Avatar position locked at current position:",this.lockedPosition)}unlockAvatarPosition(){this.armature&&this.originalPosition?(this.armature.position.set(this.originalPosition.x,this.originalPosition.y,this.originalPosition.z),console.log("Avatar position restored to original:",this.originalPosition)):this.armature&&(this.armature.position.set(0,0,0),console.log("Avatar position reset to center (0,0,0)")),this.lockedPosition=null,this.originalPosition=null,console.log("Avatar position unlocked")}maintainLockedPosition(){this.lockedPosition&&this.armature&&this.armature.position.set(this.lockedPosition.x,this.lockedPosition.y,this.lockedPosition.z)}createBodyMovementAnimation(n){const e=this.movementIntensity||.5,t={walking:{name:"bodyMovement_walking",delay:[500,2e3],dt:[800,1200],vs:{bodyRotateY:[-.1*e,.1*e,0],bodyRotateZ:[-.05*e,.05*e,0],bodyRotateX:[-.02*e,.02*e,0]}},prancing:{name:"bodyMovement_prancing",delay:[300,1e3],dt:[400,800],vs:{bodyRotateY:[-.15*e,.15*e,0],bodyRotateZ:[-.08*e,.08*e,0],bodyRotateX:[-.05*e,.05*e,0]}},gesturing:{name:"bodyMovement_gesturing",delay:[400,1500],dt:[600,1e3],vs:{bodyRotateY:[-.08*e,.08*e,0],bodyRotateZ:[-.03*e,.03*e,0]}},dancing:{name:"bodyMovement_dancing",delay:[200,600],dt:[400,800],vs:{bodyRotateY:[-.25*e,.25*e,0],bodyRotateZ:[-.15*e,.15*e,0],bodyRotateX:[-.1*e,.1*e,0]}},dancing2:{name:"bodyMovement_dancing2",delay:[150,500],dt:[300,700],vs:{bodyRotateY:[-.3*e,.3*e,0],bodyRotateZ:[-.2*e,.2*e,0],bodyRotateX:[-.12*e,.12*e,0]}},dancing3:{name:"bodyMovement_dancing3",delay:[100,400],dt:[200,600],vs:{bodyRotateY:[-.35*e,.35*e,0],bodyRotateZ:[-.25*e,.25*e,0],bodyRotateX:[-.15*e,.15*e,0]}},excited:{name:"bodyMovement_excited",delay:[200,600],dt:[300,700],vs:{bodyRotateY:[-.12*e,.12*e,0],bodyRotateZ:[-.06*e,.06*e,0],bodyRotateX:[-.04*e,.04*e,0]}},happy:{name:"bodyMovement_happy",delay:[300,800],dt:[500,1e3],vs:{bodyRotateY:[-.08*e,.08*e,0],bodyRotateZ:[-.04*e,.04*e,0],bodyRotateX:[-.02*e,.02*e,0]}},surprised:{name:"bodyMovement_surprised",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.05*e,.05*e,0],bodyRotateZ:[-.03*e,.03*e,0],bodyRotateX:[-.01*e,.01*e,0]}},thinking:{name:"bodyMovement_thinking",delay:[800,2e3],dt:[1e3,1500],vs:{bodyRotateY:[-.06*e,.06*e,0],bodyRotateZ:[-.03*e,.03*e,0],bodyRotateX:[-.02*e,.02*e,0]}},nodding:{name:"bodyMovement_nodding",delay:[400,800],dt:[300,600],vs:{bodyRotateX:[-.1*e,.1*e,0],bodyRotateY:[-.02*e,.02*e,0]}},shaking:{name:"bodyMovement_shaking",delay:[200,400],dt:[150,300],vs:{bodyRotateY:[-.15*e,.15*e,0],bodyRotateZ:[-.05*e,.05*e,0]}},celebration:{name:"bodyMovement_celebration",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.2*e,.2*e,0],bodyRotateZ:[-.1*e,.1*e,0],bodyRotateX:[-.08*e,.08*e,0]}},energetic:{name:"bodyMovement_energetic",delay:[150,400],dt:[250,500],vs:{bodyRotateY:[-.18*e,.18*e,0],bodyRotateZ:[-.12*e,.12*e,0],bodyRotateX:[-.08*e,.08*e,0]}},swaying:{name:"bodyMovement_swaying",delay:[600,1200],dt:[800,1e3],vs:{bodyRotateY:[-.1*e,.1*e,0],bodyRotateZ:[-.05*e,.05*e,0]}},bouncing:{name:"bodyMovement_bouncing",delay:[300,600],dt:[400,700],vs:{bodyRotateY:[-.05*e,.05*e,0]}}};if(n==="dancing"){const i=["dancing","dancing2","dancing3"],s=i[Math.floor(Math.random()*i.length)];return t[s]||t.dancing}return t[n]||null}setMovementIntensity(n){this.movementIntensity=Math.max(0,Math.min(1,n)),this.avatar&&(this.avatar.movementIntensity=this.movementIntensity),console.log("Movement intensity set to:",this.movementIntensity),this.fbxAnimationLoader&&this.fbxAnimationLoader.setIntensity(this.movementIntensity),this.bodyMovement&&this.bodyMovement!=="idle"&&this.applyBodyMovementAnimation()}dispose(){this.stop(),this.stopSpeaking(),this.streamStop(),this.stopAnimation(),this._raf!==null&&(cancelAnimationFrame(this._raf),this._raf=null),["audioSpeechSource","audioBackgroundSource"].forEach(n=>{const e=this[n];if(e){try{e.stop?.()}catch{}e.disconnect(),e.onended=null}}),["audioBackgroundGainNode","audioSpeechGainNode","audioStreamGainNode","audioAnalyzerNode"].forEach(n=>{const e=this[n];e&&e.disconnect()}),this.isAvatarOnly?this.armature&&(this.armature.parent&&this.armature.parent.remove(this.armature),this.clearThree(this.armature)):(this.clearThree(this.scene),this.resizeobserver.disconnect(),this.resizeobserver=null,this.renderer&&(this.renderer.dispose(),this.renderer.getContext().getExtension("WEBGL_lose_context")?.loseContext(),this.renderer.domElement?.remove(),this.renderer.domElement=null,this.renderer=null),this.controls&&(this.controls.dispose(),this.controls=null)),this.clearThree(this.ikMesh),this.dynamicbones.dispose(),this.fbxAnimationLoader&&(this.fbxAnimationLoader.stopCurrentAnimation(),this.fbxAnimationLoader=null),this.nodeAvatar=null}}const be={apiKey:"sk_ace57ef3ef65a92b9d3bee2a00183b78ca790bc3e10964f2",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",defaultVoice:"21m00Tcm4TlvDq8ikWAM",voices:{rachel:"21m00Tcm4TlvDq8ikWAM",drew:"29vD33N1CtxCmqQRPOHJ",bella:"EXAVITQu4vr4xnSDxMaL",antoni:"ErXwobaYiN019PkySvjV",elli:"MF3mGyEYCl7XYWbV9V6O",josh:"VR6AewLTigWG4xSOukaG"}},ze={defaultVoice:"aura-2-thalia-en",voices:{thalia:"aura-2-thalia-en",asteria:"aura-2-asteria-en",orion:"aura-2-orion-en",stella:"aura-2-stella-en",athena:"aura-2-athena-en",hera:"aura-2-hera-en",zeus:"aura-2-zeus-en"}};function Se(){return{service:"elevenlabs",endpoint:be.endpoint,apiKey:be.apiKey,defaultVoice:be.defaultVoice,voices:be.voices}}function dt(){const B=Se(),n=[];return Object.entries(B.voices).forEach(([e,t])=>{n.push({value:t,label:`${e.charAt(0).toUpperCase()+e.slice(1)} (${B.service})`})}),n}const Ee=x.forwardRef(({avatarUrl:B="/avatars/brunette.glb",avatarBody:n="F",mood:e="neutral",ttsLang:t="en",ttsService:i=null,ttsVoice:s=null,ttsApiKey:o=null,bodyMovement:l="idle",movementIntensity:h=.5,showFullAvatar:r=!0,cameraView:u="upper",onReady:a=()=>{},onLoading:d=()=>{},onError:p=()=>{},className:y="",style:A={},animations:v={}},T)=>{const C=x.useRef(null),m=x.useRef(null),L=x.useRef(r),E=x.useRef(null),R=x.useRef(null),M=x.useRef(!1),k=x.useRef({remainingText:null,originalText:null,options:null}),ie=x.useRef([]),ue=x.useRef(0),[w,D]=x.useState(!0),[X,j]=x.useState(null),[te,ae]=x.useState(!1),[me,ce]=x.useState(!1);x.useEffect(()=>{M.current=me},[me]),x.useEffect(()=>{L.current=r},[r]);const K=Se(),ye=i||K.service;let V;ye==="browser"?V={service:"browser",endpoint:"",apiKey:null,defaultVoice:"Google US English"}:ye==="elevenlabs"?V={service:"elevenlabs",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",apiKey:o||K.apiKey,defaultVoice:s||K.defaultVoice||be.defaultVoice,voices:K.voices||be.voices}:ye==="deepgram"?V={service:"deepgram",endpoint:"https://api.deepgram.com/v1/speak",apiKey:o||K.apiKey,defaultVoice:s||K.defaultVoice||ze.defaultVoice,voices:K.voices||ze.voices}:V={...K,apiKey:o!==null?o:K.apiKey};const f={url:B,body:n,avatarMood:e,ttsLang:ye==="browser"?"en-US":t,ttsVoice:s||V.defaultVoice,lipsyncLang:"en",showFullAvatar:r,bodyMovement:l,movementIntensity:h},b={ttsEndpoint:V.endpoint,ttsApikey:V.apiKey,ttsService:ye,lipsyncModules:["en"],cameraView:u},P=x.useCallback(async()=>{if(!(!C.current||m.current))try{if(D(!0),j(null),m.current=new Me(C.current,b),m.current.controls&&(m.current.controls.enableRotate=!1,m.current.controls.enableZoom=!1,m.current.controls.enablePan=!1,m.current.controls.enableDamping=!1),v&&Object.keys(v).length>0&&(m.current.customAnimations=v),await m.current.showAvatar(f,Q=>{if(Q.lengthComputable){const $=Math.min(100,Math.round(Q.loaded/Q.total*100));d($)}}),await new Promise(Q=>{const $=()=>{m.current.lipsync&&Object.keys(m.current.lipsync).length>0?Q():setTimeout($,100)};$()}),m.current&&m.current.setShowFullAvatar)try{m.current.setShowFullAvatar(r)}catch(Q){console.warn("Error setting full body mode on initialization:",Q)}m.current&&m.current.controls&&(m.current.controls.enableRotate=!1,m.current.controls.enableZoom=!1,m.current.controls.enablePan=!1,m.current.controls.enableDamping=!1,m.current.controls.update()),D(!1),ae(!0),a(m.current);const U=()=>{document.visibilityState==="visible"?m.current?.start():m.current?.stop()};return document.addEventListener("visibilitychange",U),()=>{document.removeEventListener("visibilitychange",U)}}catch(S){console.error("Error initializing TalkingHead:",S),j(S.message||"Failed to initialize avatar"),D(!1),p(S)}},[B,n,e,t,i,s,o,r,l,h,u]);x.useEffect(()=>(P(),()=>{m.current&&(m.current.stop(),m.current.dispose(),m.current=null)}),[P]),x.useEffect(()=>{if(!C.current||!m.current)return;const S=new ResizeObserver(Q=>{for(const $ of Q)m.current&&m.current.onResize&&m.current.onResize()});S.observe(C.current);const U=()=>{m.current&&m.current.onResize&&m.current.onResize()};return window.addEventListener("resize",U),()=>{S.disconnect(),window.removeEventListener("resize",U)}},[te]);const O=x.useCallback(async()=>{if(m.current&&m.current.audioCtx)try{(m.current.audioCtx.state==="suspended"||m.current.audioCtx.state==="interrupted")&&(await m.current.audioCtx.resume(),console.log("Audio context resumed"))}catch(S){console.warn("Failed to resume audio context:",S)}},[]),N=x.useCallback(async(S,U={})=>{if(m.current&&te)try{R.current&&(clearInterval(R.current),R.current=null),E.current={text:S,options:U},k.current={remainingText:null,originalText:null,options:null};const Q=/[!\.\?\n\p{Extended_Pictographic}]/ug,$=S.split(Q).map(I=>I.trim()).filter(I=>I.length>0);ie.current=$,ue.current=0,ce(!1),M.current=!1,await O();const de={...U,lipsyncLang:U.lipsyncLang||f.lipsyncLang||"en"};if(U.onSpeechEnd&&m.current){const I=m.current;let H=null,W=0;const q=1200;let ee=!1;H=setInterval(()=>{if(W++,M.current)return;if(W>q){if(H&&(clearInterval(H),H=null,R.current=null),!ee&&!M.current){ee=!0;try{U.onSpeechEnd()}catch(Pe){console.error("Error in onSpeechEnd callback (timeout):",Pe)}}return}const ne=!I.speechQueue||I.speechQueue.length===0,ve=!I.audioPlaylist||I.audioPlaylist.length===0;I&&I.isSpeaking===!1&&ne&&ve&&I.isAudioPlaying===!1&&!ee&&!M.current&&setTimeout(()=>{if(I&&!M.current&&I.isSpeaking===!1&&(!I.speechQueue||I.speechQueue.length===0)&&(!I.audioPlaylist||I.audioPlaylist.length===0)&&I.isAudioPlaying===!1&&!ee&&!M.current){ee=!0,H&&(clearInterval(H),H=null,R.current=null);try{U.onSpeechEnd()}catch(Ge){console.error("Error in onSpeechEnd callback:",Ge)}}},100)},100),R.current=H}m.current.lipsync&&Object.keys(m.current.lipsync).length>0?(m.current.setSlowdownRate&&m.current.setSlowdownRate(1.05),m.current.speakText(S,de)):setTimeout(async()=>{await O(),m.current&&m.current.lipsync&&(m.current.setSlowdownRate&&m.current.setSlowdownRate(1.05),m.current.speakText(S,de))},100)}catch(Q){console.error("Error speaking text:",Q),j(Q.message||"Failed to speak text")}},[te,O,f.lipsyncLang]),J=x.useCallback(()=>{m.current&&(m.current.stopSpeaking(),m.current.setSlowdownRate&&m.current.setSlowdownRate(1),E.current=null,ce(!1))},[]),Z=x.useCallback(()=>{if(m.current&&m.current.pauseSpeaking){const S=m.current;if(S.isSpeaking||S.audioPlaylist&&S.audioPlaylist.length>0||S.speechQueue&&S.speechQueue.length>0){R.current&&(clearInterval(R.current),R.current=null);let Q="";if(E.current&&ie.current.length>0){const $=ie.current.length,de=S.speechQueue?S.speechQueue.filter(q=>q&&q.text&&Array.isArray(q.text)&&q.text.length>0).length:0,I=S.audioPlaylist&&S.audioPlaylist.length>0,H=de+(I?1:0),W=$-H;if(H>0&&W<$&&(Q=ie.current.slice(W).join(". ").trim(),!Q&&de>0&&S.speechQueue)){const ee=S.speechQueue.filter(ne=>ne&&ne.text&&Array.isArray(ne.text)&&ne.text.length>0).map(ne=>ne.text.map(ve=>ve.word||"").filter(ve=>ve.length>0).join(" ")).filter(ne=>ne.length>0).join(" ");ee&&ee.trim()&&(Q=ee.trim())}}E.current&&(k.current={remainingText:Q||null,originalText:E.current.text,options:E.current.options}),S.speechQueue&&(S.speechQueue.length=0),m.current.pauseSpeaking(),M.current=!0,ce(!0)}}},[]),Y=x.useCallback(async()=>{if(!m.current||!me)return;let S="",U={};if(k.current&&k.current.remainingText)S=k.current.remainingText,U=k.current.options||{},k.current={remainingText:null,originalText:null,options:null};else if(E.current&&E.current.text)S=E.current.text,U=E.current.options||{};else{console.warn("Resume called but no paused speech found"),ce(!1),M.current=!1;return}ce(!1),M.current=!1,await O();const Q={...U,lipsyncLang:U.lipsyncLang||f.lipsyncLang||"en"};try{await N(S,Q)}catch($){console.error("Error resuming speech:",$),ce(!1),M.current=!1}},[O,me,N,f]),Re=x.useCallback(S=>{m.current&&m.current.setMood(S)},[]),Ae=x.useCallback(S=>{m.current&&m.current.setSlowdownRate&&m.current.setSlowdownRate(S)},[]),Ie=x.useCallback((S,U=!1)=>{if(m.current&&m.current.playAnimation){if(v&&v[S]&&(S=v[S]),m.current.setShowFullAvatar)try{m.current.setShowFullAvatar(L.current)}catch($){console.warn("Error setting full body mode:",$)}if(S.includes("."))try{m.current.playAnimation(S,null,10,0,.01,U)}catch($){console.warn(`Failed to play ${S}:`,$);try{m.current.setBodyMovement("idle")}catch(de){console.warn("Fallback animation also failed:",de)}}else{const $=[".fbx",".glb",".gltf"];let de=!1;for(const I of $)try{m.current.playAnimation(S+I,null,10,0,.01,U),de=!0;break}catch{}if(!de){console.warn("Animation not found:",S);try{m.current.setBodyMovement("idle")}catch(I){console.warn("Fallback animation also failed:",I)}}}}},[v]),Le=x.useCallback(()=>{m.current&&m.current.onResize&&m.current.onResize()},[]);return x.useImperativeHandle(T,()=>({speakText:N,stopSpeaking:J,pauseSpeaking:Z,resumeSpeaking:Y,resumeAudioContext:O,setMood:Re,setTimingAdjustment:Ae,playAnimation:Ie,isReady:te,isPaused:me,talkingHead:m.current,handleResize:Le,setBodyMovement:S=>{if(m.current&&m.current.setShowFullAvatar&&m.current.setBodyMovement)try{m.current.setShowFullAvatar(L.current),m.current.setBodyMovement(S)}catch(U){console.warn("Error setting body movement:",U)}},setMovementIntensity:S=>m.current?.setMovementIntensity(S),playRandomDance:()=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playRandomDance)try{m.current.setShowFullAvatar(L.current),m.current.playRandomDance()}catch(S){console.warn("Error playing random dance:",S)}},playReaction:S=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playReaction)try{m.current.setShowFullAvatar(L.current),m.current.playReaction(S)}catch(U){console.warn("Error playing reaction:",U)}},playCelebration:()=>{if(m.current&&m.current.setShowFullAvatar&&m.current.playCelebration)try{m.current.setShowFullAvatar(L.current),m.current.playCelebration()}catch(S){console.warn("Error playing celebration:",S)}},setShowFullAvatar:S=>{if(m.current&&m.current.setShowFullAvatar)try{L.current=S,m.current.setShowFullAvatar(S)}catch(U){console.warn("Error setting showFullAvatar:",U)}},lockAvatarPosition:()=>{if(m.current&&m.current.lockAvatarPosition)try{m.current.lockAvatarPosition()}catch(S){console.warn("Error locking avatar position:",S)}},unlockAvatarPosition:()=>{if(m.current&&m.current.unlockAvatarPosition)try{m.current.unlockAvatarPosition()}catch(S){console.warn("Error unlocking avatar position:",S)}}})),le.jsxs("div",{className:`talking-head-avatar ${y}`,style:{width:"100%",height:"100%",position:"relative",...A},children:[le.jsx("div",{ref:C,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),w&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),X&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:X})]})});Ee.displayName="TalkingHeadAvatar";const Ue=x.forwardRef(({text:B="Hello! I'm a talking avatar. How are you today?",onLoading:n=()=>{},onError:e=()=>{},onReady:t=()=>{},className:i="",style:s={},avatarConfig:o={}},l)=>{const h=x.useRef(null),r=x.useRef(null),[u,a]=x.useState(!0),[d,p]=x.useState(null),[y,A]=x.useState(!1),v=Se(),T=o.ttsService||v.service,C=T==="browser"?{endpoint:"",apiKey:null,defaultVoice:"Google US English"}:{...v,apiKey:o.ttsApiKey!==void 0&&o.ttsApiKey!==null?o.ttsApiKey:v.apiKey,endpoint:T==="elevenlabs"&&o.ttsApiKey?"https://api.elevenlabs.io/v1/text-to-speech":v.endpoint},m={url:"/avatars/brunette.glb",body:"F",avatarMood:"neutral",ttsLang:T==="browser"?"en-US":"en",ttsVoice:o.ttsVoice||C.defaultVoice,lipsyncLang:"en",showFullAvatar:!0,bodyMovement:"idle",movementIntensity:.5,...o},L={ttsEndpoint:C.endpoint,ttsApikey:C.apiKey,ttsService:T,lipsyncModules:["en"],cameraView:"upper"},E=x.useCallback(async()=>{if(!(!h.current||r.current))try{if(a(!0),p(null),r.current=new Me(h.current,L),await r.current.showAvatar(m,X=>{if(X.lengthComputable){const j=Math.min(100,Math.round(X.loaded/X.total*100));n(j)}}),r.current.morphs&&r.current.morphs.length>0){const X=r.current.morphs[0].morphTargetDictionary;console.log("Available morph targets:",Object.keys(X));const j=Object.keys(X).filter(te=>te.startsWith("viseme_"));console.log("Viseme morph targets found:",j),j.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"))}if(await new Promise(X=>{const j=()=>{r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),X()):(console.log("Waiting for lip-sync modules to load..."),setTimeout(j,100))};j()}),r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0),console.log("Avatar initialized in full body mode")}catch(X){console.warn("Error setting full body mode on initialization:",X)}a(!1),A(!0),t(r.current);const D=()=>{document.visibilityState==="visible"?r.current?.start():r.current?.stop()};return document.addEventListener("visibilitychange",D),()=>{document.removeEventListener("visibilitychange",D)}}catch(w){console.error("Error initializing TalkingHead:",w),p(w.message||"Failed to initialize avatar"),a(!1),e(w)}},[]);x.useEffect(()=>(E(),()=>{r.current&&(r.current.stop(),r.current.dispose(),r.current=null)}),[E]);const R=x.useCallback(w=>{if(r.current&&y)try{console.log("Speaking text:",w),console.log("Avatar config:",m),console.log("TalkingHead instance:",r.current),r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(w)):(console.warn("Lip-sync modules not ready, waiting..."),setTimeout(()=>{r.current&&r.current.lipsync?(console.log("Lip-sync now ready, speaking..."),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(w)):console.error("Lip-sync still not ready after waiting")},500))}catch(D){console.error("Error speaking text:",D),p(D.message||"Failed to speak text")}else console.warn("Avatar not ready for speaking. isReady:",y,"talkingHeadRef:",!!r.current)},[y,m]),M=x.useCallback(()=>{r.current&&(r.current.stopSpeaking(),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1),console.log("Reset timing to normal")))},[]),k=x.useCallback(w=>{r.current&&r.current.setMood(w)},[]),ie=x.useCallback(w=>{r.current&&r.current.setSlowdownRate&&(r.current.setSlowdownRate(w),console.log("Timing adjustment set to:",w))},[]),ue=x.useCallback((w,D=!1)=>{if(r.current&&r.current.playAnimation){if(r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0)}catch(j){console.warn("Error setting full body mode:",j)}if(w.includes("."))try{r.current.playAnimation(w,null,10,0,.01,D),console.log("Playing animation:",w)}catch(j){console.log(`Failed to play ${w}:`,j);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(te){console.warn("Fallback animation also failed:",te)}}else{const j=[".fbx",".glb",".gltf"];let te=!1;for(const ae of j)try{r.current.playAnimation(w+ae,null,10,0,.01,D),console.log("Playing animation:",w+ae),te=!0;break}catch{console.log(`Failed to play ${w}${ae}, trying next format...`)}if(!te){console.warn("Animation system not available or animation not found:",w);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(ae){console.warn("Fallback animation also failed:",ae)}}}}else console.warn("Animation system not available or animation not found:",w)},[]);return x.useImperativeHandle(l,()=>({speakText:R,stopSpeaking:M,setMood:k,setTimingAdjustment:ie,playAnimation:ue,isReady:y,talkingHead:r.current,setBodyMovement:w=>{if(r.current&&r.current.setShowFullAvatar&&r.current.setBodyMovement)try{r.current.setShowFullAvatar(!0),r.current.setBodyMovement(w),console.log("Body movement set with full body mode:",w)}catch(D){console.warn("Error setting body movement:",D)}},setMovementIntensity:w=>r.current?.setMovementIntensity(w),playRandomDance:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playRandomDance)try{r.current.setShowFullAvatar(!0),r.current.playRandomDance(),console.log("Random dance played with full body mode")}catch(w){console.warn("Error playing random dance:",w)}},playReaction:w=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playReaction)try{r.current.setShowFullAvatar(!0),r.current.playReaction(w),console.log("Reaction played with full body mode:",w)}catch(D){console.warn("Error playing reaction:",D)}},playCelebration:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playCelebration)try{r.current.setShowFullAvatar(!0),r.current.playCelebration(),console.log("Celebration played with full body mode")}catch(w){console.warn("Error playing celebration:",w)}},setShowFullAvatar:w=>{if(r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(w),console.log("Show full avatar set to:",w)}catch(D){console.warn("Error setting showFullAvatar:",D)}},lockAvatarPosition:()=>{if(r.current&&r.current.lockAvatarPosition)try{r.current.lockAvatarPosition()}catch(w){console.warn("Error locking avatar position:",w)}},unlockAvatarPosition:()=>{if(r.current&&r.current.unlockAvatarPosition)try{r.current.unlockAvatarPosition()}catch(w){console.warn("Error unlocking avatar position:",w)}}})),le.jsxs("div",{className:`talking-head-container ${i}`,style:s,children:[le.jsx("div",{ref:h,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),u&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),d&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:d})]})});Ue.displayName="TalkingHeadComponent";async function mt(B){try{console.log(`📥 Loading animation manifest from: ${B}`);const n=await fetch(B);if(!n.ok)throw new Error(`Failed to fetch manifest: ${n.status} ${n.statusText}`);const e=await n.json();console.log("📦 Raw manifest loaded:",e);const t=e.animations||{};return console.log("✅ Processed animations object:",t),t._genderSpecific&&console.log("👥 Gender-specific structure detected:",{male:Object.keys(t._genderSpecific.male||{}),female:Object.keys(t._genderSpecific.female||{}),shared:Object.keys(t._genderSpecific.shared||{})}),t}catch(n){return console.error("❌ Failed to load animation manifest:",n),{}}}const De=x.forwardRef(({text:B=null,avatarUrl:n="/avatars/brunette.glb",avatarBody:e="F",mood:t="neutral",ttsLang:i="en",ttsService:s=null,ttsVoice:o=null,ttsApiKey:l=null,bodyMovement:h="idle",movementIntensity:r=.5,showFullAvatar:u=!1,cameraView:a="upper",onReady:d=()=>{},onLoading:p=()=>{},onError:y=()=>{},onSpeechEnd:A=()=>{},className:v="",style:T={},animations:C={},autoAnimationGroup:m=null,autoIdleGroup:L=null,autoSpeak:E=!1},R)=>{const M=x.useRef(null),k=x.useRef(null),ie=x.useRef(u),ue=x.useRef(null),w=x.useRef(null),D=x.useRef(!1),X=x.useRef({remainingText:null,originalText:null,options:null}),j=x.useRef([]),[te,ae]=x.useState(!0),[me,ce]=x.useState(null),[K,ye]=x.useState(!1),[V,f]=x.useState(!1),[b,P]=x.useState(C),O=x.useRef(null);x.useEffect(()=>{D.current=V},[V]),x.useEffect(()=>{(async()=>{if(C.manifest)try{console.log("🔄 Loading animations from manifest:",C.manifest);const H=await mt(C.manifest);P(H),console.log("✅ Animations loaded and set:",H),H._genderSpecific?console.log("👥 Gender-specific animations detected:",{male:Object.keys(H._genderSpecific.male||{}),female:Object.keys(H._genderSpecific.female||{}),shared:Object.keys(H._genderSpecific.shared||{})}):console.log("⚠️ No gender-specific animations found in manifest")}catch(H){console.error("❌ Failed to load animation manifest:",H),P(C)}else console.log("📝 Using animations from props (no manifest):",C),P(C)})()},[C]),x.useEffect(()=>{ie.current=u},[u]);const N=Se(),J=s||N.service;let Z;J==="browser"?Z={service:"browser",endpoint:"",apiKey:null,defaultVoice:"Google US English"}:J==="elevenlabs"?Z={service:"elevenlabs",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",apiKey:l||N.apiKey,defaultVoice:o||N.defaultVoice||be.defaultVoice,voices:N.voices||be.voices}:J==="deepgram"?Z={service:"deepgram",endpoint:"https://api.deepgram.com/v1/speak",apiKey:l||N.apiKey,defaultVoice:o||N.defaultVoice||ze.defaultVoice,voices:N.voices||ze.voices}:Z={...N,apiKey:l!==null?l:N.apiKey};const Y={url:n,body:e,avatarMood:t,ttsLang:J==="browser"?"en-US":i,ttsVoice:o||Z.defaultVoice,lipsyncLang:"en",showFullAvatar:u,bodyMovement:h,movementIntensity:r},Re={ttsEndpoint:Z.endpoint,ttsApikey:Z.apiKey,ttsService:J,lipsyncModules:["en"],cameraView:a},Ae=x.useCallback(async()=>{if(!(!M.current||k.current))try{ae(!0),ce(null),k.current=new Me(M.current,Re),console.log("Avatar config being passed:",{url:Y.url,body:Y.body,avatarMood:Y.avatarMood}),await k.current.showAvatar(Y,H=>{if(H.lengthComputable){const W=Math.min(100,Math.round(H.loaded/H.total*100));p(W)}}),k.current?.avatar&&console.log("Avatar body after initialization:",k.current.avatar.body),ae(!1),ye(!0),d(k.current);const I=()=>{document.visibilityState==="visible"?k.current?.start():k.current?.stop()};return document.addEventListener("visibilitychange",I),()=>{document.removeEventListener("visibilitychange",I)}}catch(I){console.error("Error initializing TalkingHead:",I),ce(I.message||"Failed to initialize avatar"),ae(!1),y(I)}},[]);x.useEffect(()=>(Ae(),()=>{k.current&&(k.current.stop(),k.current.dispose(),k.current=null)}),[Ae]);const Ie=x.useCallback(async()=>{if(k.current)try{const I=k.current.audioCtx||k.current.audioContext;I&&(I.state==="suspended"||I.state==="interrupted")&&(await I.resume(),console.log("Audio context resumed"))}catch(I){console.warn("Failed to resume audio context:",I)}},[]),Le=x.useCallback(I=>{if(!b)return console.warn("No animations loaded"),null;let H=null;if(b._genderSpecific){const q=(e?.toUpperCase()||"F")==="M"?"male":"female",ee=b._genderSpecific[q];ee&&ee[I]?(H=ee[I],console.log(`Using ${q} animations for "${I}":`,H)):b._genderSpecific.shared&&b._genderSpecific.shared[I]&&(H=b._genderSpecific.shared[I],console.log(`Using shared animations for "${I}":`,H))}if(!H&&b[I]&&(H=b[I],console.log(`Using root-level animations for "${I}":`,H)),!H){if(console.warn(`Animation group "${I}" not found. Available groups:`,Object.keys(b).filter(W=>W!=="_genderSpecific")),b._genderSpecific){const q=(e?.toUpperCase()||"F")==="M"?"male":"female";console.warn(`Gender-specific groups (${q}):`,Object.keys(b._genderSpecific[q]||{}))}return null}if(Array.isArray(H)&&H.length>0){const W=Math.floor(Math.random()*H.length);return H[W]}return typeof H=="string"?H:(console.warn(`Animation group "${I}" is not a valid format (expected array or string):`,H),null)},[b,e]),S=x.useCallback((I,H=!1)=>{if(!k.current)return console.warn("TalkingHead not initialized yet"),null;const W=Le(I);if(W)try{return k.current.playAnimation(W,null,10,0,.01,H),console.log(`✅ Playing random animation from "${I}" group:`,W),W}catch(q){return console.error(`❌ Failed to play random animation from "${I}" group:`,q),null}else console.warn(`⚠️ No animation found for group "${I}"`);return null},[Le]),U=x.useCallback(async(I,H={})=>{if(!k.current||!K){console.warn("Avatar not ready for speaking");return}if(!I||I.trim()===""){console.warn("No text provided to speak");return}await Ie();const W=H.animationGroup||m;W&&!H.skipAnimation?(console.log(`🎬 Attempting to play animation from group: "${W}"`),console.log(`📊 Current avatarBody: "${e}", loadedAnimations:`,b),S(W)):console.log(`⏭️ Skipping animation (group: ${W}, skipAnimation: ${H.skipAnimation})`),X.current={remainingText:null,originalText:null,options:null},j.current=[],ue.current={text:I,options:H},w.current&&(clearInterval(w.current),w.current=null),f(!1),D.current=!1;const q=I.split(/[.!?]+/).filter(ne=>ne.trim().length>0);j.current=q;const ee={lipsyncLang:H.lipsyncLang||"en",onSpeechEnd:()=>{w.current&&(clearInterval(w.current),w.current=null),H.onSpeechEnd&&H.onSpeechEnd(),A()}};try{k.current.speakText(I,ee)}catch(ne){console.error("Error speaking text:",ne),ce(ne.message||"Failed to speak text")}},[K,A,Ie,m,S]);x.useEffect(()=>{if(!K||!L||!k.current)return;O.current&&clearInterval(O.current);const I=()=>{k.current&&!D.current&&S(L)};return I(),O.current=setInterval(()=>{I()},12e3+Math.random()*3e3),()=>{O.current&&(clearInterval(O.current),O.current=null)}},[K,L,S]),x.useEffect(()=>{K&&B&&E&&k.current&&U(B)},[K,B,E,U]);const Q=x.useCallback(()=>{if(k.current)try{const I=k.current.isSpeaking||!1,H=k.current.audioPlaylist||[],W=k.current.speechQueue||[];if(I||H.length>0||W.length>0){w.current&&(clearInterval(w.current),w.current=null);let q="";W.length>0&&(q=W.map(ee=>ee.text&&Array.isArray(ee.text)?ee.text.map(ne=>ne.word).join(" "):ee.text||"").join(" ")),X.current={remainingText:q||null,originalText:ue.current?.text||null,options:ue.current?.options||null},k.current.speechQueue.length=0,k.current.pauseSpeaking(),f(!0),D.current=!0}}catch(I){console.warn("Error pausing speech:",I)}},[]),$=x.useCallback(async()=>{if(!(!k.current||!V))try{await Ie(),f(!1),D.current=!1;const I=X.current?.remainingText,H=X.current?.originalText||ue.current?.text,W=X.current?.options||ue.current?.options||{},q=I||H;q&&U(q,W)}catch(I){console.warn("Error resuming speech:",I),f(!1),D.current=!1}},[V,U,Ie]),de=x.useCallback(()=>{k.current&&(k.current.stopSpeaking(),w.current&&(clearInterval(w.current),w.current=null),f(!1),D.current=!1)},[]);return x.useImperativeHandle(R,()=>({speakText:U,pauseSpeaking:Q,resumeSpeaking:$,stopSpeaking:de,resumeAudioContext:Ie,isPaused:()=>V,setMood:I=>k.current?.setMood(I),setBodyMovement:I=>{k.current&&k.current.setBodyMovement(I)},playAnimation:(I,H=!1)=>{k.current&&k.current.playAnimation&&k.current.playAnimation(I,null,10,0,.01,H)},playRandomAnimation:(I,H=!1)=>S(I,H),getRandomAnimation:I=>Le(I),playReaction:I=>k.current?.playReaction(I),playCelebration:()=>k.current?.playCelebration(),setShowFullAvatar:I=>{k.current&&(ie.current=I,k.current.setShowFullAvatar(I))},isReady:K,talkingHead:k.current})),le.jsxs("div",{className:`simple-talking-avatar-container ${v}`,style:T,children:[le.jsx("div",{ref:M,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),te&&le.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),me&&le.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:me})]})});De.displayName="SimpleTalkingAvatar";const We=x.forwardRef(({curriculumData:B=null,avatarConfig:n={},animations:e={},onLessonStart:t=()=>{},onLessonComplete:i=()=>{},onQuestionAnswer:s=()=>{},onCurriculumComplete:o=()=>{},onCustomAction:l=()=>{},autoStart:h=!1},r)=>{const u=x.useRef(null),a=x.useRef({currentModuleIndex:0,currentLessonIndex:0,currentQuestionIndex:0,isTeaching:!1,isQuestionMode:!1,lessonCompleted:!1,curriculumCompleted:!1,score:0,totalQuestions:0}),d=x.useRef({onLessonStart:t,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:l}),p=x.useRef(null),y=x.useRef(null),A=x.useRef(null),v=x.useRef(null),T=x.useRef(null),C=x.useRef(null),m=x.useRef(null),L=x.useRef(B?.curriculum||{title:"Default Curriculum",description:"No curriculum data provided",language:"en",modules:[]}),E=x.useRef({avatarUrl:n.avatarUrl||"/avatars/brunette.glb",avatarBody:n.avatarBody||"F",mood:n.mood||"happy",ttsLang:n.ttsLang||"en",ttsService:n.ttsService||null,ttsVoice:n.ttsVoice||null,ttsApiKey:n.ttsApiKey||null,bodyMovement:n.bodyMovement||"gesturing",movementIntensity:n.movementIntensity||.7,showFullAvatar:n.showFullAvatar!==void 0?n.showFullAvatar:!1,animations:e,lipsyncLang:"en"});x.useEffect(()=>{d.current={onLessonStart:t,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:l}},[t,i,s,o,l]),x.useEffect(()=>{L.current=B?.curriculum||{title:"Default Curriculum",description:"No curriculum data provided",language:"en",modules:[]},E.current={avatarUrl:n.avatarUrl||"/avatars/brunette.glb",avatarBody:n.avatarBody||"F",mood:n.mood||"happy",ttsLang:n.ttsLang||"en",ttsService:n.ttsService||null,ttsVoice:n.ttsVoice||null,ttsApiKey:n.ttsApiKey||null,bodyMovement:n.bodyMovement||"gesturing",movementIntensity:n.movementIntensity||.7,showFullAvatar:n.showFullAvatar!==void 0?n.showFullAvatar:!1,animations:e,lipsyncLang:"en"}},[B,n,e]);const R=x.useCallback(()=>(L.current||{modules:[]}).modules[a.current.currentModuleIndex]?.lessons[a.current.currentLessonIndex],[]),M=x.useCallback(()=>R()?.questions[a.current.currentQuestionIndex],[R]),k=x.useCallback((f,b)=>b.type==="multiple_choice"||b.type==="true_false"?f===b.answer:b.type==="code_test"&&typeof f=="object"&&f!==null?f.passed===!0:!1,[]),ie=x.useCallback(()=>{a.current.lessonCompleted=!0,a.current.isQuestionMode=!1;const f=a.current.totalQuestions>0?Math.round(a.current.score/a.current.totalQuestions*100):100;let b="Congratulations! You've completed this lesson";if(a.current.totalQuestions>0?b+=` You got ${a.current.score} correct out of ${a.current.totalQuestions} question${a.current.totalQuestions===1?"":"s"}, achieving a score of ${f} percent. `:b+="! ",f>=80?b+="Excellent work! You have a great understanding of this topic.":f>=60?b+="Good job! You understand most of the concepts.":b+="Keep practicing! You're making progress.",d.current.onLessonComplete({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f}),d.current.onCustomAction({type:"lessonComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f}),u.current){if(u.current.setMood("happy"),e.lessonComplete)try{u.current.playAnimation(e.lessonComplete,!0)}catch{u.current.playCelebration()}const P=L.current||{modules:[]},O=P.modules[a.current.currentModuleIndex],N=a.current.currentLessonIndex<(O?.lessons?.length||0)-1,J=a.current.currentModuleIndex<(P.modules?.length||0)-1,Z=N||J,Y=E.current||{lipsyncLang:"en"};u.current.speakText(b,{lipsyncLang:Y.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"lessonCompleteFeedbackDone",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,score:a.current.score,totalQuestions:a.current.totalQuestions,percentage:f,hasNextLesson:Z})}})}},[e.lessonComplete]),ue=x.useCallback(()=>{a.current.curriculumCompleted=!0;const f=L.current||{modules:[]};if(d.current.onCurriculumComplete({modules:f.modules.length,totalLessons:f.modules.reduce((b,P)=>b+P.lessons.length,0)}),u.current){if(u.current.setMood("celebrating"),e.curriculumComplete)try{u.current.playAnimation(e.curriculumComplete,!0)}catch{u.current.playCelebration()}const b=E.current||{lipsyncLang:"en"};u.current.speakText("Amazing! You've completed the entire curriculum! You're now ready to move on to more advanced topics. Well done!",{lipsyncLang:b.lipsyncLang})}},[e.curriculumComplete]),w=x.useCallback(()=>{const f=R();a.current.isQuestionMode=!0,a.current.currentQuestionIndex=0,a.current.totalQuestions=f?.questions?.length||0,a.current.score=0;const b=M();b&&d.current.onCustomAction({type:"questionStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:b,score:a.current.score});const P=()=>{if(!u.current||!b)return;if(u.current.setMood("happy"),e.questionStart)try{u.current.playAnimation(e.questionStart,!0)}catch(N){console.warn("Failed to play questionStart animation:",N)}const O=E.current||{lipsyncLang:"en"};b.type==="code_test"?u.current.speakText(`Let's test your coding skills! Here's your first challenge: ${b.question}`,{lipsyncLang:O.lipsyncLang}):b.type==="multiple_choice"?u.current.speakText(`Now let me ask you some questions. Here's the first one: ${b.question}`,{lipsyncLang:O.lipsyncLang}):b.type==="true_false"?u.current.speakText(`Let's start with some true or false questions. First question: ${b.question}`,{lipsyncLang:O.lipsyncLang}):u.current.speakText(`Now let me ask you some questions. Here's the first one: ${b.question}`,{lipsyncLang:O.lipsyncLang})};if(u.current&&u.current.isReady&&b)P();else if(u.current&&u.current.isReady){const O=E.current||{lipsyncLang:"en"};u.current.speakText("Now let me ask you some questions to test your understanding.",{lipsyncLang:O.lipsyncLang})}else{const O=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(O),b&&P())},100);setTimeout(()=>{clearInterval(O)},5e3)}},[e.questionStart,R,M]),D=x.useCallback(()=>{const f=R();if(a.current.currentQuestionIndex<(f?.questions?.length||0)-1){u.current&&u.current.stopSpeaking&&u.current.stopSpeaking(),a.current.currentQuestionIndex+=1;const b=M();b&&d.current.onCustomAction({type:"nextQuestion",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:b,score:a.current.score});const P=()=>{if(!u.current||!b)return;if(u.current.setMood("happy"),u.current.setBodyMovement("idle"),e.nextQuestion)try{u.current.playAnimation(e.nextQuestion,!0)}catch(Y){console.warn("Failed to play nextQuestion animation:",Y)}const O=E.current||{lipsyncLang:"en"},J=R()?.questions?.length||0,Z=a.current.currentQuestionIndex>=J-1;if(b.type==="code_test"){const Y=Z?`Great! Here's your final coding challenge: ${b.question}`:`Great! Now let's move on to your next coding challenge: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else if(b.type==="multiple_choice"){const Y=Z?`Alright! Here's your final question: ${b.question}`:`Alright! Here's your next question: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else if(b.type==="true_false"){const Y=Z?`Now let's try this final one: ${b.question}`:`Now let's try this one: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}else{const Y=Z?`Here's your final question: ${b.question}`:`Here's the next question: ${b.question}`;u.current.speakText(Y,{lipsyncLang:O.lipsyncLang})}};if(u.current&&u.current.isReady&&b)P();else if(b){const O=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(O),P())},100);setTimeout(()=>{clearInterval(O)},5e3)}}else d.current.onCustomAction({type:"allQuestionsComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,totalQuestions:a.current.totalQuestions,score:a.current.score})},[e.nextQuestion,R,M]),X=x.useCallback(()=>{const f=L.current||{modules:[]},b=f.modules[a.current.currentModuleIndex];if(a.current.currentLessonIndex<(b?.lessons?.length||0)-1){a.current.currentLessonIndex+=1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0;const O=f.modules[a.current.currentModuleIndex],N=a.current.currentLessonIndex<(O?.lessons?.length||0)-1,J=a.current.currentModuleIndex<(f.modules?.length||0)-1,Z=N||J;d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,hasNextLesson:Z}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}else if(a.current.currentModuleIndex<(f.modules?.length||0)-1){a.current.currentModuleIndex+=1,a.current.currentLessonIndex=0,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0;const N=f.modules[a.current.currentModuleIndex],J=a.current.currentLessonIndex<(N?.lessons?.length||0)-1,Z=a.current.currentModuleIndex<(f.modules?.length||0)-1,Y=J||Z;d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,hasNextLesson:Y}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}else T.current&&T.current()},[]),j=x.useCallback(()=>{const f=R();let b=null;if(f?.avatar_script&&f?.body){const P=f.avatar_script.trim(),O=f.body.trim(),N=P.match(/[.!?]$/)?" ":". ";b=`${P}${N}${O}`}else b=f?.avatar_script||f?.body||null;if(u.current&&u.current.isReady&&b){a.current.isTeaching=!0,a.current.isQuestionMode=!1,a.current.score=0,a.current.totalQuestions=0,u.current.setMood("happy");let P=!1;if(e.teaching)try{u.current.playAnimation(e.teaching,!0),P=!0}catch(N){console.warn("Failed to play teaching animation:",N)}P||u.current.setBodyMovement("gesturing");const O=E.current||{lipsyncLang:"en"};d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f}),d.current.onCustomAction({type:"teachingStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f}),u.current.speakText(b,{lipsyncLang:O.lipsyncLang,onSpeechEnd:()=>{a.current.isTeaching=!1,d.current.onCustomAction({type:"teachingComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f,hasQuestions:f.questions&&f.questions.length>0}),f?.code_example&&d.current.onCustomAction({type:"codeExampleReady",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:f,codeExample:f.code_example})}})}},[e.teaching,R]),te=x.useCallback(f=>{const b=M(),P=k(f,b);if(P&&(a.current.score+=1),d.current.onQuestionAnswer({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,answer:f,isCorrect:P,question:b}),u.current)if(P){if(u.current.setMood("happy"),e.correct)try{u.current.playReaction("happy")}catch{u.current.setBodyMovement("happy")}u.current.setBodyMovement("gesturing");const N=R()?.questions?.length||0;a.current.currentQuestionIndex>=N-1;const J=a.current.currentQuestionIndex<N-1;console.log("[CurriculumLearning] Answer feedback - questionIndex:",a.current.currentQuestionIndex,"totalQuestions:",N,"hasNextQuestion:",J);const Z=b.type==="code_test"?`Great job! Your code passed all the tests! ${b.explanation||""}`:`Excellent! That's correct! ${b.explanation||""}`,Y=E.current||{lipsyncLang:"en"};u.current.speakText(Z,{lipsyncLang:Y.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:!0,hasNextQuestion:J,score:a.current.score,totalQuestions:a.current.totalQuestions})}})}else{if(u.current.setMood("sad"),e.incorrect)try{u.current.playAnimation(e.incorrect,!0)}catch{u.current.setBodyMovement("idle")}u.current.setBodyMovement("gesturing");const N=R()?.questions?.length||0,J=a.current.currentQuestionIndex>=N-1,Z=a.current.currentQuestionIndex<N-1;console.log("[CurriculumLearning] Answer feedback (incorrect) - questionIndex:",a.current.currentQuestionIndex,"totalQuestions:",N,"hasNextQuestion:",Z);const Y=b.type==="code_test"?`Your code didn't pass all the tests. ${b.explanation||"Try again!"}`:`Not quite right, but don't worry! ${b.explanation||""}${J?"":" Let's move on to the next question."}`,Re=E.current||{lipsyncLang:"en"};u.current.speakText(Y,{lipsyncLang:Re.lipsyncLang,onSpeechEnd:()=>{d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:!1,hasNextQuestion:Z,score:a.current.score,totalQuestions:a.current.totalQuestions})}})}else{const N=R()?.questions?.length||0;d.current.onCustomAction({type:"answerFeedbackComplete",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,isCorrect:P,hasNextQuestion:a.current.currentQuestionIndex<N-1,score:a.current.score,totalQuestions:a.current.totalQuestions,avatarNotReady:!0})}},[e.correct,e.incorrect,M,R,k]),ae=x.useCallback(f=>{const b=M();if(!f||typeof f!="object"){console.error("Invalid code test result format. Expected object with {passed: boolean, ...}");return}if(b?.type!=="code_test"){console.warn("Current question is not a code test. Use handleAnswerSelect for other question types.");return}const P={passed:f.passed===!0,results:f.results||[],output:f.output||"",error:f.error||null,executionTime:f.executionTime||null,testCount:f.testCount||0,passedCount:f.passedCount||0,failedCount:f.failedCount||0};d.current.onCustomAction({type:"codeTestSubmitted",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,testResult:P,question:b}),m.current&&m.current(P)},[M,k]),me=x.useCallback(()=>{if(a.current.currentQuestionIndex>0){a.current.currentQuestionIndex-=1;const f=M();f&&d.current.onCustomAction({type:"questionStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,questionIndex:a.current.currentQuestionIndex,totalQuestions:a.current.totalQuestions,question:f,score:a.current.score});const b=()=>{if(!u.current||!f)return;u.current.setMood("happy"),u.current.setBodyMovement("idle");const P=E.current||{lipsyncLang:"en"};f.type==="code_test"?u.current.speakText(`Let's go back to this coding challenge: ${f.question}`,{lipsyncLang:P.lipsyncLang}):u.current.speakText(`Going back to: ${f.question}`,{lipsyncLang:P.lipsyncLang})};if(u.current&&u.current.isReady&&f)b();else if(f){const P=setInterval(()=>{u.current&&u.current.isReady&&(clearInterval(P),b())},100);setTimeout(()=>{clearInterval(P)},5e3)}}},[M]),ce=x.useCallback(()=>{const f=L.current||{modules:[]};if(f.modules[a.current.currentModuleIndex],a.current.currentLessonIndex>0)a.current.currentLessonIndex-=1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0,d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"));else if(a.current.currentModuleIndex>0){const O=f.modules[a.current.currentModuleIndex-1];a.current.currentModuleIndex-=1,a.current.currentLessonIndex=(O?.lessons?.length||1)-1,a.current.currentQuestionIndex=0,a.current.lessonCompleted=!1,a.current.isQuestionMode=!1,a.current.isTeaching=!1,a.current.score=0,a.current.totalQuestions=0,d.current.onCustomAction({type:"lessonStart",moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex}),d.current.onLessonStart({moduleIndex:a.current.currentModuleIndex,lessonIndex:a.current.currentLessonIndex,lesson:R()}),u.current&&(u.current.setMood("happy"),u.current.setBodyMovement("idle"))}},[R]),K=x.useCallback(()=>{a.current.currentModuleIndex=0,a.current.currentLessonIndex=0,a.current.currentQuestionIndex=0,a.current.isTeaching=!1,a.current.isQuestionMode=!1,a.current.lessonCompleted=!1,a.current.curriculumCompleted=!1,a.current.score=0,a.current.totalQuestions=0},[]),ye=x.useCallback(f=>{console.log("Avatar is ready!",f);const b=R(),P=b?.avatar_script||b?.body;h&&P&&setTimeout(()=>{p.current&&p.current()},10)},[h,R]);x.useLayoutEffect(()=>{p.current=j,y.current=X,A.current=ie,v.current=D,T.current=ue,C.current=w,m.current=te}),x.useImperativeHandle(r,()=>({startTeaching:j,startQuestions:w,handleAnswerSelect:te,handleCodeTestResult:ae,nextQuestion:D,previousQuestion:me,nextLesson:X,previousLesson:ce,completeLesson:ie,completeCurriculum:ue,resetCurriculum:K,getState:()=>({...a.current}),getCurrentQuestion:()=>M(),getCurrentLesson:()=>R(),getAvatarRef:()=>u.current,speakText:async(f,b={})=>{await u.current?.resumeAudioContext?.();const P=E.current||{lipsyncLang:"en"};u.current?.speakText(f,{...b,lipsyncLang:b.lipsyncLang||P.lipsyncLang})},resumeAudioContext:async()=>{if(u.current?.resumeAudioContext)return await u.current.resumeAudioContext();const f=u.current?.talkingHead;if(f?.audioCtx){const b=f.audioCtx;if(b.state==="suspended"||b.state==="interrupted")try{await b.resume(),console.log("Audio context resumed via talkingHead")}catch(P){console.warn("Failed to resume audio context:",P)}}else console.warn("Audio context not available yet")},stopSpeaking:()=>u.current?.stopSpeaking(),pauseSpeaking:()=>u.current?.pauseSpeaking(),resumeSpeaking:async()=>await u.current?.resumeSpeaking(),isPaused:()=>u.current&&typeof u.current.isPaused<"u"?u.current.isPaused:!1,setMood:f=>u.current?.setMood(f),playAnimation:(f,b)=>u.current?.playAnimation(f,b),setBodyMovement:f=>u.current?.setBodyMovement(f),setMovementIntensity:f=>u.current?.setMovementIntensity(f),playRandomDance:()=>u.current?.playRandomDance(),playReaction:f=>u.current?.playReaction(f),playCelebration:()=>u.current?.playCelebration(),setShowFullAvatar:f=>u.current?.setShowFullAvatar(f),setTimingAdjustment:f=>u.current?.setTimingAdjustment(f),lockAvatarPosition:()=>u.current?.lockAvatarPosition(),unlockAvatarPosition:()=>u.current?.unlockAvatarPosition(),triggerCustomAction:(f,b)=>{d.current.onCustomAction({type:f,...b,state:{...a.current}})},handleResize:()=>u.current?.handleResize(),isAvatarReady:()=>u.current?.isReady||!1}),[j,w,te,ae,D,X,ie,ue,K,M,R]);const V=E.current||{avatarUrl:"/avatars/brunette.glb",avatarBody:"F",mood:"happy",ttsLang:"en",ttsService:null,ttsVoice:null,ttsApiKey:null,bodyMovement:"gesturing",movementIntensity:.7,showFullAvatar:!1,animations:e};return le.jsx("div",{style:{width:"100%",height:"100%"},children:le.jsx(Ee,{ref:u,avatarUrl:V.avatarUrl,avatarBody:V.avatarBody,mood:V.mood,ttsLang:V.ttsLang,ttsService:V.ttsService,ttsVoice:V.ttsVoice,ttsApiKey:V.ttsApiKey,bodyMovement:V.bodyMovement,movementIntensity:V.movementIntensity,showFullAvatar:V.showFullAvatar,cameraView:"upper",animations:V.animations,onReady:ye,onLoading:()=>{},onError:f=>{console.error("Avatar error:",f)}})})});We.displayName="CurriculumLearning";const Fe={dance:{name:"dance",type:"code-based",variations:["dancing","dancing2","dancing3"],loop:!0,duration:1e4,description:"Celebration dance animation with multiple variations"},happy:{name:"happy",type:"code-based",loop:!0,duration:5e3,description:"Happy, upbeat body movement"},surprised:{name:"surprised",type:"code-based",loop:!1,duration:3e3,description:"Surprised reaction with quick movements"},thinking:{name:"thinking",type:"code-based",loop:!0,duration:8e3,description:"Thoughtful, contemplative movement"},nodding:{name:"nodding",type:"code-based",loop:!1,duration:2e3,description:"Nodding agreement gesture"},shaking:{name:"shaking",type:"code-based",loop:!1,duration:2e3,description:"Shaking head disagreement gesture"},celebration:{name:"celebration",type:"code-based",loop:!1,duration:3e3,description:"Celebration animation for achievements"},energetic:{name:"energetic",type:"code-based",loop:!0,duration:6e3,description:"High-energy, enthusiastic movement"},swaying:{name:"swaying",type:"code-based",loop:!0,duration:8e3,description:"Gentle swaying motion"},bouncing:{name:"bouncing",type:"code-based",loop:!0,duration:4e3,description:"Bouncy, playful movement"},gesturing:{name:"gesturing",type:"code-based",loop:!0,duration:5e3,description:"Teaching gesture animation"},walking:{name:"walking",type:"code-based",loop:!0,duration:6e3,description:"Walking motion"},prancing:{name:"prancing",type:"code-based",loop:!0,duration:4e3,description:"Playful prancing movement"},excited:{name:"excited",type:"code-based",loop:!0,duration:5e3,description:"Excited, energetic movement"}},pt=B=>Fe[B]||null,gt=B=>Fe.hasOwnProperty(B);exports.CurriculumLearning=We;exports.SimpleTalkingAvatar=De;exports.TalkingHeadAvatar=Ee;exports.TalkingHeadComponent=Ue;exports.animations=Fe;exports.getActiveTTSConfig=Se;exports.getAnimation=pt;exports.getVoiceOptions=dt;exports.hasAnimation=gt;
|