@gui-chat-plugin/avatar 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("./three-vrm.module-FTOSkzpf.cjs"),B=require("./core.cjs"),a=require("react");var X={exports:{}},Y={};var K;function ie(){if(K)return Y;K=1;var d=Symbol.for("react.transitional.element"),b=Symbol.for("react.fragment");function l(z,u,g){var M=null;if(g!==void 0&&(M=""+g),u.key!==void 0&&(M=""+u.key),"key"in u){g={};for(var E in u)E!=="key"&&(g[E]=u[E])}else g=u;return u=g.ref,{$$typeof:d,type:z,key:M,ref:u!==void 0?u:null,props:g}}return Y.Fragment=b,Y.jsx=l,Y.jsxs=l,Y}var $={};var ee;function se(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&(function(){function d(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case j:return"Fragment";case q:return"Profiler";case U:return"StrictMode";case h:return"Suspense";case L:return"SuspenseList";case n:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case W:return"Portal";case c:return e.displayName||"Context";case G:return(e._context.displayName||"Context")+".Consumer";case m:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case t:return r=e.displayName||null,r!==null?r:d(e.type)||"Memo";case y:r=e._payload,e=e._init;try{return d(e(r))}catch{}}return null}function b(e){return""+e}function l(e){try{b(e);var r=!1}catch{r=!0}if(r){r=console;var o=r.error,i=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",i),b(e)}}function z(e){if(e===j)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===y)return"<...>";try{var r=d(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function u(){var e=O.A;return e===null?null:e.getOwner()}function g(){return Error("react-stack-top-frame")}function M(e){if(R.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function E(e,r){function o(){_||(_=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}o.isReactWarning=!0,Object.defineProperty(e,"key",{get:o,configurable:!0})}function x(){var e=d(this.type);return w[e]||(w[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function f(e,r,o,i,J,H){var s=o.ref;return e={$$typeof:I,type:e,key:r,props:o,_owner:i},(s!==void 0?s:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:x}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:H}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function k(e,r,o,i,J,H){var s=r.children;if(s!==void 0)if(i)if(P(s)){for(i=0;i<s.length;i++)D(s[i]);Object.freeze&&Object.freeze(s)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else D(s);if(R.call(r,"key")){s=d(e);var F=Object.keys(r).filter(function(ae){return ae!=="key"});i=0<F.length?"{key: someKey, "+F.join(": ..., ")+": ...}":"{key: someKey}",V[s+i]||(F=0<F.length?"{"+F.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("./three-vrm.module-FTOSkzpf.cjs"),B=require("./core.cjs"),a=require("react");var X={exports:{}},Y={};var K;function ie(){if(K)return Y;K=1;var d=Symbol.for("react.transitional.element"),R=Symbol.for("react.fragment");function l(P,u,g){var S=null;if(g!==void 0&&(S=""+g),u.key!==void 0&&(S=""+u.key),"key"in u){g={};for(var E in u)E!=="key"&&(g[E]=u[E])}else g=u;return u=g.ref,{$$typeof:d,type:P,key:S,ref:u!==void 0?u:null,props:g}}return Y.Fragment=R,Y.jsx=l,Y.jsxs=l,Y}var $={};var ee;function se(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&(function(){function d(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case q:return"Profiler";case U:return"StrictMode";case h:return"Suspense";case C:return"SuspenseList";case o:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case W:return"Portal";case c:return e.displayName||"Context";case G:return(e._context.displayName||"Context")+".Consumer";case m:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case t:return r=e.displayName||null,r!==null?r:d(e.type)||"Memo";case j:r=e._payload,e=e._init;try{return d(e(r))}catch{}}return null}function R(e){return""+e}function l(e){try{R(e);var r=!1}catch{r=!0}if(r){r=console;var n=r.error,i=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",i),R(e)}}function P(e){if(e===y)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===j)return"<...>";try{var r=d(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function u(){var e=M.A;return e===null?null:e.getOwner()}function g(){return Error("react-stack-top-frame")}function S(e){if(b.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function E(e,r){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function x(){var e=d(this.type);return _[e]||(_[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function f(e,r,n,i,J,H){var s=n.ref;return e={$$typeof:I,type:e,key:r,props:n,_owner:i},(s!==void 0?s:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:x}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:H}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function A(e,r,n,i,J,H){var s=r.children;if(s!==void 0)if(i)if(L(s)){for(i=0;i<s.length;i++)V(s[i]);Object.freeze&&Object.freeze(s)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else V(s);if(b.call(r,"key")){s=d(e);var D=Object.keys(r).filter(function(ae){return ae!=="key"});i=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",F[s+i]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,i,s,F,s),V[s+i]=!0)}if(s=null,o!==void 0&&(l(o),s=""+o),M(r)&&(l(r.key),s=""+r.key),"key"in r){o={};for(var Z in r)Z!=="key"&&(o[Z]=r[Z])}else o=r;return s&&E(o,typeof e=="function"?e.displayName||e.name||"Unknown":e),f(e,s,o,u(),J,H)}function D(e){C(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===y&&(e._payload.status==="fulfilled"?C(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function C(e){return typeof e=="object"&&e!==null&&e.$$typeof===I}var S=a,I=Symbol.for("react.transitional.element"),W=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),U=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),c=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),t=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),n=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),O=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R=Object.prototype.hasOwnProperty,P=Array.isArray,N=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(e){return e()}};var _,w={},A=S.react_stack_bottom_frame.bind(S,g)(),T=N(z(g)),V={};$.Fragment=j,$.jsx=function(e,r,o){var i=1e4>O.recentlyCreatedOwnerStacks++;return k(e,r,o,!1,i?Error("react-stack-top-frame"):A,i?N(z(e)):T)},$.jsxs=function(e,r,o){var i=1e4>O.recentlyCreatedOwnerStacks++;return k(e,r,o,!0,i?Error("react-stack-top-frame"):A,i?N(z(e)):T)}})()),$}var re;function le(){return re||(re=1,process.env.NODE_ENV==="production"?X.exports=ie():X.exports=se()),X.exports}var p=le();function te({selectedResult:d,isAudioPlaying:b}){const l=a.useRef(null),[z,u]=a.useState(!1),[g,M]=a.useState(null),E=a.useRef(null),x=a.useRef(null),f=a.useRef(null),k=a.useRef(null),D=a.useRef(null),C=a.useRef(null),S=a.useRef(0),I=a.useRef(b);a.useEffect(()=>{I.current=b},[b]);const W=a.useCallback(()=>{if(!l.current)return;const c=l.current,m=c.clientWidth,h=c.clientHeight;E.current=new v.Scene,x.current=new v.PerspectiveCamera(30,m/h,.1,100),x.current.position.set(0,1.3,1.5),x.current.lookAt(0,1.2,0),f.current=new v.WebGLRenderer({antialias:!0,alpha:!0}),f.current.setSize(m,h),f.current.setPixelRatio(window.devicePixelRatio),f.current.outputColorSpace=v.SRGBColorSpace,c.appendChild(f.current.domElement);const L=new v.AmbientLight(16777215,.6);E.current.add(L);const t=new v.DirectionalLight(16777215,.8);t.position.set(1,1,1),E.current.add(t),D.current=new v.Clock},[]),j=a.useCallback(()=>{if(!l.current||!x.current||!f.current)return;const c=l.current.clientWidth,m=l.current.clientHeight;x.current.aspect=c/m,x.current.updateProjectionMatrix(),f.current.setSize(c,m)},[]),U=a.useCallback(()=>{C.current=requestAnimationFrame(U);const c=D.current,m=f.current,h=E.current,L=x.current,t=k.current;if(!c||!m||!h||!L)return;const y=c.getDelta(),n=c.getElapsedTime();if(t){if(t.update(y),I.current){S.current+=y*10;const O=(Math.sin(S.current)+1)*.3;t.expressionManager?.setValue(v.VRMExpressionPresetName.Aa,O);const R=t.humanoid?.getNormalizedBoneNode("head"),P=t.humanoid?.getNormalizedBoneNode("neck"),N=t.humanoid?.getNormalizedBoneNode("spine");S.current<.2&&console.log("[Avatar Debug] Body animation - Bones found:",{head:!!R,neck:!!P,spine:!!N,humanoid:!!t.humanoid}),R&&(R.rotation.x=Math.sin(n*2)*.08,R.rotation.z=Math.sin(n*1.5)*.05),P&&(P.rotation.y=Math.sin(n*.8)*.05),N&&(N.rotation.z=Math.sin(n*.5)*.03);const _=t.humanoid?.getNormalizedBoneNode("leftShoulder"),w=t.humanoid?.getNormalizedBoneNode("rightShoulder"),A=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),T=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),V=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),e=t.humanoid?.getNormalizedBoneNode("rightLowerArm");_&&(_.rotation.z=.1),w&&(w.rotation.z=-.1),A&&(A.rotation.z=-.8+Math.sin(n*1.2)*.1,A.rotation.x=.4+Math.sin(n*.9)*.15,A.rotation.y=Math.sin(n*.7)*.1),T&&(T.rotation.z=.8+Math.sin(n*1.3)*.1,T.rotation.x=.4+Math.sin(n*1)*.15,T.rotation.y=Math.sin(n*.8)*.1),V&&(V.rotation.y=-1-Math.sin(n*1.5)*.2,V.rotation.z=Math.sin(n*1.1)*.1),e&&(e.rotation.y=1+Math.sin(n*1.4)*.2,e.rotation.z=Math.sin(n*1.2)*.1)}else{S.current=0,t.expressionManager?.setValue(v.VRMExpressionPresetName.Aa,0);const O=t.humanoid?.getNormalizedBoneNode("spine"),R=t.humanoid?.getNormalizedBoneNode("head");Math.floor(n)%5===0&&n-Math.floor(n)<y&&console.log("[Avatar Debug] Idle animation - Bones found:",{head:!!R,neck:!!t.humanoid?.getNormalizedBoneNode("neck"),spine:!!O}),O&&(O.rotation.x=Math.sin(n*.8)*.02),R&&(R.rotation.x=Math.sin(n*.3)*.03,R.rotation.z=Math.sin(n*.2)*.02);const P=t.humanoid?.getNormalizedBoneNode("leftShoulder"),N=t.humanoid?.getNormalizedBoneNode("rightShoulder"),_=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),w=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),A=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),T=t.humanoid?.getNormalizedBoneNode("rightLowerArm");P&&(P.rotation.z=.1),N&&(N.rotation.z=-.1),_&&(_.rotation.z=-.9,_.rotation.x=.2,_.rotation.y=0),w&&(w.rotation.z=.9,w.rotation.x=.2,w.rotation.y=0),A&&(A.rotation.y=-.8),T&&(T.rotation.y=.8)}n%4<.1?t.expressionManager?.setValue(v.VRMExpressionPresetName.Blink,1):t.expressionManager?.setValue(v.VRMExpressionPresetName.Blink,0)}m.render(h,L)},[]),q=a.useCallback(async c=>{const m=E.current;if(m){u(!0),M(null),k.current&&(m.remove(k.current.scene),k.current=null);try{const h=new v.GLTFLoader;h.register(y=>new v.VRMLoaderPlugin(y));const t=(await h.loadAsync(c)).userData.vrm;if(!t)throw new Error("Failed to load VRM data");m.add(t.scene),k.current=t,u(!1)}catch(h){console.error("Failed to load VRM:",h),M(`Failed to load avatar: ${h instanceof Error?h.message:"Unknown error"}`),u(!1)}}},[]),G=a.useCallback(()=>{C.current!==null&&(cancelAnimationFrame(C.current),C.current=null),window.removeEventListener("resize",j),f.current&&l.current&&(l.current.removeChild(f.current.domElement),f.current.dispose(),f.current=null),k.current=null,E.current=null,x.current=null,D.current=null},[j]);return a.useEffect(()=>(W(),window.addEventListener("resize",j),U(),()=>{G()}),[W,j,U,G]),a.useEffect(()=>{if(d?.toolName===B.TOOL_NAME&&d.data){const c=d.data;c.avatarUrl&&q(c.avatarUrl)}},[d,q]),p.jsxs("div",{className:"w-full h-full bg-gradient-to-b from-slate-800 to-slate-900 relative",children:[p.jsx("div",{ref:l,className:"w-full h-full"}),z&&p.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-900/80",children:p.jsx("div",{className:"text-white text-lg",children:"Loading Avatar..."})}),g&&p.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-900/80",children:p.jsx("div",{className:"text-red-400 text-lg text-center p-4",children:g})}),b&&p.jsx("div",{className:"absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full",children:"Speaking..."})]})}function ne({result:d}){const l=d.data?.emotion||"neutral";return p.jsx("div",{className:"p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md",children:p.jsxs("div",{className:"flex flex-col items-center gap-2",children:[p.jsx("div",{className:"w-12 h-12 bg-slate-600 rounded-full flex items-center justify-center",children:p.jsx("svg",{className:"w-8 h-8 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})})}),p.jsx("div",{className:"text-sm font-semibold text-white text-center",children:"3D Avatar"}),l!=="neutral"&&p.jsx("div",{className:"text-xs px-2 py-0.5 bg-blue-500 text-white rounded-full",children:l})]})})}const oe={...B.pluginCore,ViewComponent:te,PreviewComponent:ne},ce={plugin:oe};exports.SAMPLES=B.SAMPLES;exports.TOOL_DEFINITION=B.TOOL_DEFINITION;exports.TOOL_NAME=B.TOOL_NAME;exports.executeAvatar=B.executeAvatar;exports.pluginCore=B.pluginCore;exports.Preview=ne;exports.View=te;exports.default=ce;exports.plugin=oe;
6
+ <%s key={someKey} {...props} />`,i,s,D,s),F[s+i]=!0)}if(s=null,n!==void 0&&(l(n),s=""+n),S(r)&&(l(r.key),s=""+r.key),"key"in r){n={};for(var Z in r)Z!=="key"&&(n[Z]=r[Z])}else n=r;return s&&E(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),f(e,s,n,u(),J,H)}function V(e){z(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===j&&(e._payload.status==="fulfilled"?z(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function z(e){return typeof e=="object"&&e!==null&&e.$$typeof===I}var O=a,I=Symbol.for("react.transitional.element"),W=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),U=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),c=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),C=Symbol.for("react.suspense_list"),t=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),o=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),M=O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,b=Object.prototype.hasOwnProperty,L=Array.isArray,k=console.createTask?console.createTask:function(){return null};O={react_stack_bottom_frame:function(e){return e()}};var N,_={},w=O.react_stack_bottom_frame.bind(O,g)(),T=k(P(g)),F={};$.Fragment=y,$.jsx=function(e,r,n){var i=1e4>M.recentlyCreatedOwnerStacks++;return A(e,r,n,!1,i?Error("react-stack-top-frame"):w,i?k(P(e)):T)},$.jsxs=function(e,r,n){var i=1e4>M.recentlyCreatedOwnerStacks++;return A(e,r,n,!0,i?Error("react-stack-top-frame"):w,i?k(P(e)):T)}})()),$}var re;function le(){return re||(re=1,process.env.NODE_ENV==="production"?X.exports=ie():X.exports=se()),X.exports}var p=le();function te({selectedResult:d,isAudioPlaying:R}){const l=a.useRef(null),[P,u]=a.useState(!1),[g,S]=a.useState(null),E=a.useRef(null),x=a.useRef(null),f=a.useRef(null),A=a.useRef(null),V=a.useRef(null),z=a.useRef(null),O=a.useRef(0),I=a.useRef(R);a.useEffect(()=>{I.current=R},[R]);const W=a.useCallback(()=>{if(!l.current)return;const c=l.current,m=c.clientWidth,h=c.clientHeight;E.current=new v.Scene,x.current=new v.PerspectiveCamera(30,m/h,.1,100),x.current.position.set(0,1.3,1.5),x.current.lookAt(0,1.2,0),f.current=new v.WebGLRenderer({antialias:!0,alpha:!0}),f.current.setSize(m,h),f.current.setPixelRatio(window.devicePixelRatio),f.current.outputColorSpace=v.SRGBColorSpace,c.appendChild(f.current.domElement);const C=new v.AmbientLight(16777215,.6);E.current.add(C);const t=new v.DirectionalLight(16777215,.8);t.position.set(1,1,1),E.current.add(t),V.current=new v.Clock},[]),y=a.useCallback(()=>{if(!l.current||!x.current||!f.current)return;const c=l.current.clientWidth,m=l.current.clientHeight;x.current.aspect=c/m,x.current.updateProjectionMatrix(),f.current.setSize(c,m)},[]),U=a.useCallback(()=>{z.current=requestAnimationFrame(U);const c=V.current,m=f.current,h=E.current,C=x.current,t=A.current;if(!c||!m||!h||!C)return;const j=c.getDelta(),o=c.getElapsedTime();if(t){if(t.update(j),I.current){O.current+=j*10;const M=(Math.sin(O.current)+1)*.3;t.expressionManager?.setValue(v.VRMExpressionPresetName.Aa,M);const b=t.humanoid?.getNormalizedBoneNode("head"),L=t.humanoid?.getNormalizedBoneNode("neck"),k=t.humanoid?.getNormalizedBoneNode("spine");b&&(b.rotation.x=Math.sin(o*2)*.08,b.rotation.z=Math.sin(o*1.5)*.05),L&&(L.rotation.y=Math.sin(o*.8)*.05),k&&(k.rotation.z=Math.sin(o*.5)*.03);const N=t.humanoid?.getNormalizedBoneNode("leftShoulder"),_=t.humanoid?.getNormalizedBoneNode("rightShoulder"),w=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),T=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),F=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),e=t.humanoid?.getNormalizedBoneNode("rightLowerArm");N&&(N.rotation.z=.1),_&&(_.rotation.z=-.1),w&&(w.rotation.z=-.8+Math.sin(o*1.2)*.1,w.rotation.x=.4+Math.sin(o*.9)*.15,w.rotation.y=Math.sin(o*.7)*.1),T&&(T.rotation.z=.8+Math.sin(o*1.3)*.1,T.rotation.x=.4+Math.sin(o*1)*.15,T.rotation.y=Math.sin(o*.8)*.1),F&&(F.rotation.y=-1-Math.sin(o*1.5)*.2,F.rotation.z=Math.sin(o*1.1)*.1),e&&(e.rotation.y=1+Math.sin(o*1.4)*.2,e.rotation.z=Math.sin(o*1.2)*.1)}else{O.current=0,t.expressionManager?.setValue(v.VRMExpressionPresetName.Aa,0);const M=t.humanoid?.getNormalizedBoneNode("spine"),b=t.humanoid?.getNormalizedBoneNode("head");M&&(M.rotation.x=Math.sin(o*.8)*.02),b&&(b.rotation.x=Math.sin(o*.3)*.03,b.rotation.z=Math.sin(o*.2)*.02);const L=t.humanoid?.getNormalizedBoneNode("leftShoulder"),k=t.humanoid?.getNormalizedBoneNode("rightShoulder"),N=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),_=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),w=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),T=t.humanoid?.getNormalizedBoneNode("rightLowerArm");L&&(L.rotation.z=.1),k&&(k.rotation.z=-.1),N&&(N.rotation.z=-.9,N.rotation.x=.2,N.rotation.y=0),_&&(_.rotation.z=.9,_.rotation.x=.2,_.rotation.y=0),w&&(w.rotation.y=-.8),T&&(T.rotation.y=.8)}o%4<.1?t.expressionManager?.setValue(v.VRMExpressionPresetName.Blink,1):t.expressionManager?.setValue(v.VRMExpressionPresetName.Blink,0)}m.render(h,C)},[]),q=a.useCallback(async c=>{const m=E.current;if(m){u(!0),S(null),A.current&&(m.remove(A.current.scene),A.current=null);try{const h=new v.GLTFLoader;h.register(j=>new v.VRMLoaderPlugin(j));const t=(await h.loadAsync(c)).userData.vrm;if(!t)throw new Error("Failed to load VRM data");m.add(t.scene),A.current=t,u(!1)}catch(h){console.error("Failed to load VRM:",h),S(`Failed to load avatar: ${h instanceof Error?h.message:"Unknown error"}`),u(!1)}}},[]),G=a.useCallback(()=>{z.current!==null&&(cancelAnimationFrame(z.current),z.current=null),window.removeEventListener("resize",y),f.current&&l.current&&(l.current.removeChild(f.current.domElement),f.current.dispose(),f.current=null),A.current=null,E.current=null,x.current=null,V.current=null},[y]);return a.useEffect(()=>(W(),window.addEventListener("resize",y),U(),()=>{G()}),[W,y,U,G]),a.useEffect(()=>{if(d?.toolName===B.TOOL_NAME&&d.data){const c=d.data;c.avatarUrl&&q(c.avatarUrl)}},[d,q]),p.jsxs("div",{className:"w-full h-full bg-gradient-to-b from-slate-800 to-slate-900 relative",children:[p.jsx("div",{ref:l,className:"w-full h-full"}),P&&p.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-900/80",children:p.jsx("div",{className:"text-white text-lg",children:"Loading Avatar..."})}),g&&p.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-900/80",children:p.jsx("div",{className:"text-red-400 text-lg text-center p-4",children:g})}),R&&p.jsx("div",{className:"absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full",children:"Speaking..."})]})}function ne({result:d}){const l=d.data?.emotion||"neutral";return p.jsx("div",{className:"p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md",children:p.jsxs("div",{className:"flex flex-col items-center gap-2",children:[p.jsx("div",{className:"w-12 h-12 bg-slate-600 rounded-full flex items-center justify-center",children:p.jsx("svg",{className:"w-8 h-8 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})})}),p.jsx("div",{className:"text-sm font-semibold text-white text-center",children:"3D Avatar"}),l!=="neutral"&&p.jsx("div",{className:"text-xs px-2 py-0.5 bg-blue-500 text-white rounded-full",children:l})]})})}const oe={...B.pluginCore,ViewComponent:te,PreviewComponent:ne},ce={plugin:oe};exports.SAMPLES=B.SAMPLES;exports.TOOL_DEFINITION=B.TOOL_DEFINITION;exports.TOOL_NAME=B.TOOL_NAME;exports.executeAvatar=B.executeAvatar;exports.pluginCore=B.pluginCore;exports.Preview=ne;exports.View=te;exports.default=ce;exports.plugin=oe;
package/dist/react.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { S as ae, P as ie, W as se, a as le, A as ce, D as ue, C as de, b as J, G as fe, V as me } from "./three-vrm.module-DJ7DURJm.js";
2
2
  import { TOOL_NAME as he, pluginCore as pe } from "./core.js";
3
3
  import { SAMPLES as ye, TOOL_DEFINITION as je, executeAvatar as Oe } from "./core.js";
4
- import ge, { useRef as y, useState as ee, useEffect as Q, useCallback as I } from "react";
5
- var X = { exports: {} }, V = {};
4
+ import ge, { useRef as T, useState as ee, useEffect as Q, useCallback as V } from "react";
5
+ var X = { exports: {} }, Y = {};
6
6
  var re;
7
7
  function ve() {
8
- if (re) return V;
8
+ if (re) return Y;
9
9
  re = 1;
10
- var u = /* @__PURE__ */ Symbol.for("react.transitional.element"), x = /* @__PURE__ */ Symbol.for("react.fragment");
10
+ var u = /* @__PURE__ */ Symbol.for("react.transitional.element"), v = /* @__PURE__ */ Symbol.for("react.fragment");
11
11
  function s(P, c, p) {
12
- var j = null;
13
- if (p !== void 0 && (j = "" + p), c.key !== void 0 && (j = "" + c.key), "key" in c) {
12
+ var k = null;
13
+ if (p !== void 0 && (k = "" + p), c.key !== void 0 && (k = "" + c.key), "key" in c) {
14
14
  p = {};
15
15
  for (var g in c)
16
16
  g !== "key" && (p[g] = c[g]);
@@ -18,14 +18,14 @@ function ve() {
18
18
  return c = p.ref, {
19
19
  $$typeof: u,
20
20
  type: P,
21
- key: j,
21
+ key: k,
22
22
  ref: c !== void 0 ? c : null,
23
23
  props: p
24
24
  };
25
25
  }
26
- return V.Fragment = x, V.jsx = s, V.jsxs = s, V;
26
+ return Y.Fragment = v, Y.jsx = s, Y.jsxs = s, Y;
27
27
  }
28
- var Y = {};
28
+ var I = {};
29
29
  var te;
30
30
  function xe() {
31
31
  return te || (te = 1, process.env.NODE_ENV !== "production" && (function() {
@@ -35,7 +35,7 @@ function xe() {
35
35
  return e.$$typeof === K ? null : e.displayName || e.name || null;
36
36
  if (typeof e == "string") return e;
37
37
  switch (e) {
38
- case O:
38
+ case y:
39
39
  return "Fragment";
40
40
  case W:
41
41
  return "Profiler";
@@ -43,9 +43,9 @@ function xe() {
43
43
  return "StrictMode";
44
44
  case m:
45
45
  return "Suspense";
46
- case C:
46
+ case z:
47
47
  return "SuspenseList";
48
- case n:
48
+ case o:
49
49
  return "Activity";
50
50
  }
51
51
  if (typeof e == "object")
@@ -63,7 +63,7 @@ function xe() {
63
63
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
64
64
  case t:
65
65
  return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
66
- case T:
66
+ case j:
67
67
  r = e._payload, e = e._init;
68
68
  try {
69
69
  return u(e(r));
@@ -72,29 +72,29 @@ function xe() {
72
72
  }
73
73
  return null;
74
74
  }
75
- function x(e) {
75
+ function v(e) {
76
76
  return "" + e;
77
77
  }
78
78
  function s(e) {
79
79
  try {
80
- x(e);
80
+ v(e);
81
81
  var r = !1;
82
82
  } catch {
83
83
  r = !0;
84
84
  }
85
85
  if (r) {
86
86
  r = console;
87
- var o = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
88
- return o.call(
87
+ var n = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
88
+ return n.call(
89
89
  r,
90
90
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
91
91
  a
92
- ), x(e);
92
+ ), v(e);
93
93
  }
94
94
  }
95
95
  function P(e) {
96
- if (e === O) return "<>";
97
- if (typeof e == "object" && e !== null && e.$$typeof === T)
96
+ if (e === y) return "<>";
97
+ if (typeof e == "object" && e !== null && e.$$typeof === j)
98
98
  return "<...>";
99
99
  try {
100
100
  var r = u(e);
@@ -104,48 +104,48 @@ function xe() {
104
104
  }
105
105
  }
106
106
  function c() {
107
- var e = S.A;
107
+ var e = O.A;
108
108
  return e === null ? null : e.getOwner();
109
109
  }
110
110
  function p() {
111
111
  return Error("react-stack-top-frame");
112
112
  }
113
- function j(e) {
114
- if (v.call(e, "key")) {
113
+ function k(e) {
114
+ if (E.call(e, "key")) {
115
115
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
116
116
  if (r && r.isReactWarning) return !1;
117
117
  }
118
118
  return e.key !== void 0;
119
119
  }
120
120
  function g(e, r) {
121
- function o() {
122
- R || (R = !0, console.error(
121
+ function n() {
122
+ b || (b = !0, console.error(
123
123
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
124
124
  r
125
125
  ));
126
126
  }
127
- o.isReactWarning = !0, Object.defineProperty(e, "key", {
128
- get: o,
127
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
128
+ get: n,
129
129
  configurable: !0
130
130
  });
131
131
  }
132
- function E() {
132
+ function x() {
133
133
  var e = u(this.type);
134
- return N[e] || (N[e] = !0, console.error(
134
+ return R[e] || (R[e] = !0, console.error(
135
135
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
136
136
  )), e = this.props.ref, e !== void 0 ? e : null;
137
137
  }
138
- function d(e, r, o, a, q, H) {
139
- var i = o.ref;
138
+ function d(e, r, n, a, q, H) {
139
+ var i = n.ref;
140
140
  return e = {
141
141
  $$typeof: F,
142
142
  type: e,
143
143
  key: r,
144
- props: o,
144
+ props: n,
145
145
  _owner: a
146
146
  }, (i !== void 0 ? i : null) !== null ? Object.defineProperty(e, "ref", {
147
147
  enumerable: !1,
148
- get: E
148
+ get: x
149
149
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
150
150
  configurable: !1,
151
151
  enumerable: !1,
@@ -168,11 +168,11 @@ function xe() {
168
168
  value: H
169
169
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
170
170
  }
171
- function A(e, r, o, a, q, H) {
171
+ function w(e, r, n, a, q, H) {
172
172
  var i = r.children;
173
173
  if (i !== void 0)
174
174
  if (a)
175
- if (M(i)) {
175
+ if (C(i)) {
176
176
  for (a = 0; a < i.length; a++)
177
177
  L(i[a]);
178
178
  Object.freeze && Object.freeze(i);
@@ -181,7 +181,7 @@ function xe() {
181
181
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
182
182
  );
183
183
  else L(i);
184
- if (v.call(r, "key")) {
184
+ if (E.call(r, "key")) {
185
185
  i = u(e);
186
186
  var D = Object.keys(r).filter(function(oe) {
187
187
  return oe !== "key";
@@ -199,140 +199,131 @@ React keys must be passed directly to JSX without using spread:
199
199
  i
200
200
  ), B[i + a] = !0);
201
201
  }
202
- if (i = null, o !== void 0 && (s(o), i = "" + o), j(r) && (s(r.key), i = "" + r.key), "key" in r) {
203
- o = {};
202
+ if (i = null, n !== void 0 && (s(n), i = "" + n), k(r) && (s(r.key), i = "" + r.key), "key" in r) {
203
+ n = {};
204
204
  for (var Z in r)
205
- Z !== "key" && (o[Z] = r[Z]);
206
- } else o = r;
205
+ Z !== "key" && (n[Z] = r[Z]);
206
+ } else n = r;
207
207
  return i && g(
208
- o,
208
+ n,
209
209
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
210
210
  ), d(
211
211
  e,
212
212
  i,
213
- o,
213
+ n,
214
214
  c(),
215
215
  q,
216
216
  H
217
217
  );
218
218
  }
219
219
  function L(e) {
220
- z(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === T && (e._payload.status === "fulfilled" ? z(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
220
+ M(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === j && (e._payload.status === "fulfilled" ? M(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
221
221
  }
222
- function z(e) {
222
+ function M(e) {
223
223
  return typeof e == "object" && e !== null && e.$$typeof === F;
224
224
  }
225
- var k = ge, F = /* @__PURE__ */ Symbol.for("react.transitional.element"), $ = /* @__PURE__ */ Symbol.for("react.portal"), O = /* @__PURE__ */ Symbol.for("react.fragment"), U = /* @__PURE__ */ Symbol.for("react.strict_mode"), W = /* @__PURE__ */ Symbol.for("react.profiler"), G = /* @__PURE__ */ Symbol.for("react.consumer"), l = /* @__PURE__ */ Symbol.for("react.context"), f = /* @__PURE__ */ Symbol.for("react.forward_ref"), m = /* @__PURE__ */ Symbol.for("react.suspense"), C = /* @__PURE__ */ Symbol.for("react.suspense_list"), t = /* @__PURE__ */ Symbol.for("react.memo"), T = /* @__PURE__ */ Symbol.for("react.lazy"), n = /* @__PURE__ */ Symbol.for("react.activity"), K = /* @__PURE__ */ Symbol.for("react.client.reference"), S = k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, v = Object.prototype.hasOwnProperty, M = Array.isArray, b = console.createTask ? console.createTask : function() {
225
+ var S = ge, F = /* @__PURE__ */ Symbol.for("react.transitional.element"), $ = /* @__PURE__ */ Symbol.for("react.portal"), y = /* @__PURE__ */ Symbol.for("react.fragment"), U = /* @__PURE__ */ Symbol.for("react.strict_mode"), W = /* @__PURE__ */ Symbol.for("react.profiler"), G = /* @__PURE__ */ Symbol.for("react.consumer"), l = /* @__PURE__ */ Symbol.for("react.context"), f = /* @__PURE__ */ Symbol.for("react.forward_ref"), m = /* @__PURE__ */ Symbol.for("react.suspense"), z = /* @__PURE__ */ Symbol.for("react.suspense_list"), t = /* @__PURE__ */ Symbol.for("react.memo"), j = /* @__PURE__ */ Symbol.for("react.lazy"), o = /* @__PURE__ */ Symbol.for("react.activity"), K = /* @__PURE__ */ Symbol.for("react.client.reference"), O = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, E = Object.prototype.hasOwnProperty, C = Array.isArray, A = console.createTask ? console.createTask : function() {
226
226
  return null;
227
227
  };
228
- k = {
228
+ S = {
229
229
  react_stack_bottom_frame: function(e) {
230
230
  return e();
231
231
  }
232
232
  };
233
- var R, N = {}, _ = k.react_stack_bottom_frame.bind(
234
- k,
233
+ var b, R = {}, N = S.react_stack_bottom_frame.bind(
234
+ S,
235
235
  p
236
- )(), w = b(P(p)), B = {};
237
- Y.Fragment = O, Y.jsx = function(e, r, o) {
238
- var a = 1e4 > S.recentlyCreatedOwnerStacks++;
239
- return A(
236
+ )(), _ = A(P(p)), B = {};
237
+ I.Fragment = y, I.jsx = function(e, r, n) {
238
+ var a = 1e4 > O.recentlyCreatedOwnerStacks++;
239
+ return w(
240
240
  e,
241
241
  r,
242
- o,
242
+ n,
243
243
  !1,
244
- a ? Error("react-stack-top-frame") : _,
245
- a ? b(P(e)) : w
244
+ a ? Error("react-stack-top-frame") : N,
245
+ a ? A(P(e)) : _
246
246
  );
247
- }, Y.jsxs = function(e, r, o) {
248
- var a = 1e4 > S.recentlyCreatedOwnerStacks++;
249
- return A(
247
+ }, I.jsxs = function(e, r, n) {
248
+ var a = 1e4 > O.recentlyCreatedOwnerStacks++;
249
+ return w(
250
250
  e,
251
251
  r,
252
- o,
252
+ n,
253
253
  !0,
254
- a ? Error("react-stack-top-frame") : _,
255
- a ? b(P(e)) : w
254
+ a ? Error("react-stack-top-frame") : N,
255
+ a ? A(P(e)) : _
256
256
  );
257
257
  };
258
- })()), Y;
258
+ })()), I;
259
259
  }
260
260
  var ne;
261
261
  function Ee() {
262
262
  return ne || (ne = 1, process.env.NODE_ENV === "production" ? X.exports = ve() : X.exports = xe()), X.exports;
263
263
  }
264
264
  var h = Ee();
265
- function be({ selectedResult: u, isAudioPlaying: x }) {
266
- const s = y(null), [P, c] = ee(!1), [p, j] = ee(null), g = y(null), E = y(null), d = y(null), A = y(null), L = y(null), z = y(null), k = y(0), F = y(x);
265
+ function be({ selectedResult: u, isAudioPlaying: v }) {
266
+ const s = T(null), [P, c] = ee(!1), [p, k] = ee(null), g = T(null), x = T(null), d = T(null), w = T(null), L = T(null), M = T(null), S = T(0), F = T(v);
267
267
  Q(() => {
268
- F.current = x;
269
- }, [x]);
270
- const $ = I(() => {
268
+ F.current = v;
269
+ }, [v]);
270
+ const $ = V(() => {
271
271
  if (!s.current) return;
272
272
  const l = s.current, f = l.clientWidth, m = l.clientHeight;
273
- g.current = new ae(), E.current = new ie(30, f / m, 0.1, 100), E.current.position.set(0, 1.3, 1.5), E.current.lookAt(0, 1.2, 0), d.current = new se({ antialias: !0, alpha: !0 }), d.current.setSize(f, m), d.current.setPixelRatio(window.devicePixelRatio), d.current.outputColorSpace = le, l.appendChild(d.current.domElement);
274
- const C = new ce(16777215, 0.6);
275
- g.current.add(C);
273
+ g.current = new ae(), x.current = new ie(30, f / m, 0.1, 100), x.current.position.set(0, 1.3, 1.5), x.current.lookAt(0, 1.2, 0), d.current = new se({ antialias: !0, alpha: !0 }), d.current.setSize(f, m), d.current.setPixelRatio(window.devicePixelRatio), d.current.outputColorSpace = le, l.appendChild(d.current.domElement);
274
+ const z = new ce(16777215, 0.6);
275
+ g.current.add(z);
276
276
  const t = new ue(16777215, 0.8);
277
277
  t.position.set(1, 1, 1), g.current.add(t), L.current = new de();
278
- }, []), O = I(() => {
279
- if (!s.current || !E.current || !d.current) return;
278
+ }, []), y = V(() => {
279
+ if (!s.current || !x.current || !d.current) return;
280
280
  const l = s.current.clientWidth, f = s.current.clientHeight;
281
- E.current.aspect = l / f, E.current.updateProjectionMatrix(), d.current.setSize(l, f);
282
- }, []), U = I(() => {
283
- z.current = requestAnimationFrame(U);
284
- const l = L.current, f = d.current, m = g.current, C = E.current, t = A.current;
285
- if (!l || !f || !m || !C) return;
286
- const T = l.getDelta(), n = l.getElapsedTime();
281
+ x.current.aspect = l / f, x.current.updateProjectionMatrix(), d.current.setSize(l, f);
282
+ }, []), U = V(() => {
283
+ M.current = requestAnimationFrame(U);
284
+ const l = L.current, f = d.current, m = g.current, z = x.current, t = w.current;
285
+ if (!l || !f || !m || !z) return;
286
+ const j = l.getDelta(), o = l.getElapsedTime();
287
287
  if (t) {
288
- if (t.update(T), F.current) {
289
- k.current += T * 10;
290
- const S = (Math.sin(k.current) + 1) * 0.3;
291
- t.expressionManager?.setValue(J.Aa, S);
292
- const v = t.humanoid?.getNormalizedBoneNode("head"), M = t.humanoid?.getNormalizedBoneNode("neck"), b = t.humanoid?.getNormalizedBoneNode("spine");
293
- k.current < 0.2 && console.log("[Avatar Debug] Body animation - Bones found:", {
294
- head: !!v,
295
- neck: !!M,
296
- spine: !!b,
297
- humanoid: !!t.humanoid
298
- }), v && (v.rotation.x = Math.sin(n * 2) * 0.08, v.rotation.z = Math.sin(n * 1.5) * 0.05), M && (M.rotation.y = Math.sin(n * 0.8) * 0.05), b && (b.rotation.z = Math.sin(n * 0.5) * 0.03);
299
- const R = t.humanoid?.getNormalizedBoneNode("leftShoulder"), N = t.humanoid?.getNormalizedBoneNode("rightShoulder"), _ = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), w = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), B = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), e = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
300
- R && (R.rotation.z = 0.1), N && (N.rotation.z = -0.1), _ && (_.rotation.z = -0.8 + Math.sin(n * 1.2) * 0.1, _.rotation.x = 0.4 + Math.sin(n * 0.9) * 0.15, _.rotation.y = Math.sin(n * 0.7) * 0.1), w && (w.rotation.z = 0.8 + Math.sin(n * 1.3) * 0.1, w.rotation.x = 0.4 + Math.sin(n * 1) * 0.15, w.rotation.y = Math.sin(n * 0.8) * 0.1), B && (B.rotation.y = -1 - Math.sin(n * 1.5) * 0.2, B.rotation.z = Math.sin(n * 1.1) * 0.1), e && (e.rotation.y = 1 + Math.sin(n * 1.4) * 0.2, e.rotation.z = Math.sin(n * 1.2) * 0.1);
288
+ if (t.update(j), F.current) {
289
+ S.current += j * 10;
290
+ const O = (Math.sin(S.current) + 1) * 0.3;
291
+ t.expressionManager?.setValue(J.Aa, O);
292
+ const E = t.humanoid?.getNormalizedBoneNode("head"), C = t.humanoid?.getNormalizedBoneNode("neck"), A = t.humanoid?.getNormalizedBoneNode("spine");
293
+ E && (E.rotation.x = Math.sin(o * 2) * 0.08, E.rotation.z = Math.sin(o * 1.5) * 0.05), C && (C.rotation.y = Math.sin(o * 0.8) * 0.05), A && (A.rotation.z = Math.sin(o * 0.5) * 0.03);
294
+ const b = t.humanoid?.getNormalizedBoneNode("leftShoulder"), R = t.humanoid?.getNormalizedBoneNode("rightShoulder"), N = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), _ = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), B = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), e = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
295
+ b && (b.rotation.z = 0.1), R && (R.rotation.z = -0.1), N && (N.rotation.z = -0.8 + Math.sin(o * 1.2) * 0.1, N.rotation.x = 0.4 + Math.sin(o * 0.9) * 0.15, N.rotation.y = Math.sin(o * 0.7) * 0.1), _ && (_.rotation.z = 0.8 + Math.sin(o * 1.3) * 0.1, _.rotation.x = 0.4 + Math.sin(o * 1) * 0.15, _.rotation.y = Math.sin(o * 0.8) * 0.1), B && (B.rotation.y = -1 - Math.sin(o * 1.5) * 0.2, B.rotation.z = Math.sin(o * 1.1) * 0.1), e && (e.rotation.y = 1 + Math.sin(o * 1.4) * 0.2, e.rotation.z = Math.sin(o * 1.2) * 0.1);
301
296
  } else {
302
- k.current = 0, t.expressionManager?.setValue(J.Aa, 0);
303
- const S = t.humanoid?.getNormalizedBoneNode("spine"), v = t.humanoid?.getNormalizedBoneNode("head");
304
- Math.floor(n) % 5 === 0 && n - Math.floor(n) < T && console.log("[Avatar Debug] Idle animation - Bones found:", {
305
- head: !!v,
306
- neck: !!t.humanoid?.getNormalizedBoneNode("neck"),
307
- spine: !!S
308
- }), S && (S.rotation.x = Math.sin(n * 0.8) * 0.02), v && (v.rotation.x = Math.sin(n * 0.3) * 0.03, v.rotation.z = Math.sin(n * 0.2) * 0.02);
309
- const M = t.humanoid?.getNormalizedBoneNode("leftShoulder"), b = t.humanoid?.getNormalizedBoneNode("rightShoulder"), R = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), N = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), _ = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), w = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
310
- M && (M.rotation.z = 0.1), b && (b.rotation.z = -0.1), R && (R.rotation.z = -0.9, R.rotation.x = 0.2, R.rotation.y = 0), N && (N.rotation.z = 0.9, N.rotation.x = 0.2, N.rotation.y = 0), _ && (_.rotation.y = -0.8), w && (w.rotation.y = 0.8);
297
+ S.current = 0, t.expressionManager?.setValue(J.Aa, 0);
298
+ const O = t.humanoid?.getNormalizedBoneNode("spine"), E = t.humanoid?.getNormalizedBoneNode("head");
299
+ O && (O.rotation.x = Math.sin(o * 0.8) * 0.02), E && (E.rotation.x = Math.sin(o * 0.3) * 0.03, E.rotation.z = Math.sin(o * 0.2) * 0.02);
300
+ const C = t.humanoid?.getNormalizedBoneNode("leftShoulder"), A = t.humanoid?.getNormalizedBoneNode("rightShoulder"), b = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), R = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), N = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), _ = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
301
+ C && (C.rotation.z = 0.1), A && (A.rotation.z = -0.1), b && (b.rotation.z = -0.9, b.rotation.x = 0.2, b.rotation.y = 0), R && (R.rotation.z = 0.9, R.rotation.x = 0.2, R.rotation.y = 0), N && (N.rotation.y = -0.8), _ && (_.rotation.y = 0.8);
311
302
  }
312
- n % 4 < 0.1 ? t.expressionManager?.setValue(J.Blink, 1) : t.expressionManager?.setValue(J.Blink, 0);
303
+ o % 4 < 0.1 ? t.expressionManager?.setValue(J.Blink, 1) : t.expressionManager?.setValue(J.Blink, 0);
313
304
  }
314
- f.render(m, C);
315
- }, []), W = I(async (l) => {
305
+ f.render(m, z);
306
+ }, []), W = V(async (l) => {
316
307
  const f = g.current;
317
308
  if (f) {
318
- c(!0), j(null), A.current && (f.remove(A.current.scene), A.current = null);
309
+ c(!0), k(null), w.current && (f.remove(w.current.scene), w.current = null);
319
310
  try {
320
311
  const m = new fe();
321
- m.register((T) => new me(T));
312
+ m.register((j) => new me(j));
322
313
  const t = (await m.loadAsync(l)).userData.vrm;
323
314
  if (!t)
324
315
  throw new Error("Failed to load VRM data");
325
- f.add(t.scene), A.current = t, c(!1);
316
+ f.add(t.scene), w.current = t, c(!1);
326
317
  } catch (m) {
327
- console.error("Failed to load VRM:", m), j(`Failed to load avatar: ${m instanceof Error ? m.message : "Unknown error"}`), c(!1);
318
+ console.error("Failed to load VRM:", m), k(`Failed to load avatar: ${m instanceof Error ? m.message : "Unknown error"}`), c(!1);
328
319
  }
329
320
  }
330
- }, []), G = I(() => {
331
- z.current !== null && (cancelAnimationFrame(z.current), z.current = null), window.removeEventListener("resize", O), d.current && s.current && (s.current.removeChild(d.current.domElement), d.current.dispose(), d.current = null), A.current = null, g.current = null, E.current = null, L.current = null;
332
- }, [O]);
333
- return Q(() => ($(), window.addEventListener("resize", O), U(), () => {
321
+ }, []), G = V(() => {
322
+ M.current !== null && (cancelAnimationFrame(M.current), M.current = null), window.removeEventListener("resize", y), d.current && s.current && (s.current.removeChild(d.current.domElement), d.current.dispose(), d.current = null), w.current = null, g.current = null, x.current = null, L.current = null;
323
+ }, [y]);
324
+ return Q(() => ($(), window.addEventListener("resize", y), U(), () => {
334
325
  G();
335
- }), [$, O, U, G]), Q(() => {
326
+ }), [$, y, U, G]), Q(() => {
336
327
  if (u?.toolName === he && u.data) {
337
328
  const l = u.data;
338
329
  l.avatarUrl && W(l.avatarUrl);
@@ -341,7 +332,7 @@ function be({ selectedResult: u, isAudioPlaying: x }) {
341
332
  /* @__PURE__ */ h.jsx("div", { ref: s, className: "w-full h-full" }),
342
333
  P && /* @__PURE__ */ h.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-slate-900/80", children: /* @__PURE__ */ h.jsx("div", { className: "text-white text-lg", children: "Loading Avatar..." }) }),
343
334
  p && /* @__PURE__ */ h.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-slate-900/80", children: /* @__PURE__ */ h.jsx("div", { className: "text-red-400 text-lg text-center p-4", children: p }) }),
344
- x && /* @__PURE__ */ h.jsx("div", { className: "absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full", children: "Speaking..." })
335
+ v && /* @__PURE__ */ h.jsx("div", { className: "absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full", children: "Speaking..." })
345
336
  ] });
346
337
  }
347
338
  function Re({ result: u }) {
@@ -373,14 +364,14 @@ const Ne = {
373
364
  ...pe,
374
365
  ViewComponent: be,
375
366
  PreviewComponent: Re
376
- }, ke = { plugin: Ne };
367
+ }, Te = { plugin: Ne };
377
368
  export {
378
369
  Re as Preview,
379
370
  ye as SAMPLES,
380
371
  je as TOOL_DEFINITION,
381
372
  he as TOOL_NAME,
382
373
  be as View,
383
- ke as default,
374
+ Te as default,
384
375
  Oe as executeAvatar,
385
376
  Ne as plugin,
386
377
  pe as pluginCore
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("./three-vrm.module-FTOSkzpf.cjs"),z=require("./core.cjs"),o=require("vue"),q={class:"size-full bg-gradient-to-b from-slate-800 to-slate-900 relative"},H={key:0,class:"absolute inset-0 flex items-center justify-center bg-slate-900/80"},G={key:1,class:"absolute inset-0 flex items-center justify-center bg-slate-900/80"},W={class:"text-red-400 text-lg text-center p-4"},J={key:2,class:"absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full"},T=o.defineComponent({__name:"View",props:{selectedResult:{},sendTextMessage:{type:Function},isAudioPlaying:{type:Boolean}},setup(V){const v=V,p=o.ref(null),M=o.ref(!1),E=o.ref(null);let r=null,N=null,l=null,t=null,y=null,w=null,k=0,b="neutral",P="none",S=0,_=0,L="";const F={neutral:null,happy:a.VRMExpressionPresetName.Happy,sad:a.VRMExpressionPresetName.Sad,angry:a.VRMExpressionPresetName.Angry,surprised:a.VRMExpressionPresetName.Surprised};function j(){if(!p.value)return;const n=p.value,e=n.clientWidth,B=n.clientHeight;r=new a.Scene,N=new a.PerspectiveCamera(30,e/B,.1,100),N.position.set(0,1.3,1.5),N.lookAt(0,1.2,0),l=new a.WebGLRenderer({antialias:!0,alpha:!0}),l.setSize(e,B),l.setPixelRatio(window.devicePixelRatio),l.outputColorSpace=a.SRGBColorSpace,n.appendChild(l.domElement);const h=new a.AmbientLight(16777215,.6);r.add(h);const d=new a.DirectionalLight(16777215,.8);d.position.set(1,1,1),r.add(d),y=new a.Clock,window.addEventListener("resize",D),C()}function D(){if(!p.value||!N||!l)return;const n=p.value.clientWidth,e=p.value.clientHeight;N.aspect=n/e,N.updateProjectionMatrix(),l.setSize(n,e)}async function U(n){if(r){M.value=!0,E.value=null,t&&(r.remove(t.scene),t=null);try{const e=new a.GLTFLoader;e.register(d=>new a.VRMLoaderPlugin(d));const h=(await e.loadAsync(n)).userData.vrm;if(!h)throw new Error("Failed to load VRM data");r.add(h.scene),t=h,console.log("[Avatar Debug] VRM loaded successfully"),console.log("[Avatar Debug] VRM humanoid:",!!h.humanoid),console.log("[Avatar Debug] VRM expressionManager:",!!h.expressionManager),M.value=!1}catch(e){console.error("Failed to load VRM:",e),E.value=`Failed to load avatar: ${e instanceof Error?e.message:"Unknown error"}`,M.value=!1}}}let R=0;function C(){if(w=requestAnimationFrame(C),!y||!l||!r||!N)return;const n=y.getDelta(),e=y.getElapsedTime();if(R++,R%300===0&&console.log("[Avatar Debug] animate() running, frame:",R,"currentVrm:",!!t,"isAudioPlaying:",v.isAudioPlaying),t){if(t.update(n),v.isAudioPlaying){k+=n*10;const d=(Math.sin(k)+1)*.3;t.expressionManager?.setValue(a.VRMExpressionPresetName.Aa,d);const m=t.humanoid?.getNormalizedBoneNode("head"),c=t.humanoid?.getNormalizedBoneNode("neck"),i=t.humanoid?.getNormalizedBoneNode("spine");k<.2&&console.log("[Avatar Debug] Body animation - Bones found:",{head:!!m,neck:!!c,spine:!!i,humanoid:!!t.humanoid}),m&&(m.rotation.x=Math.sin(e*2)*.08,m.rotation.z=Math.sin(e*1.5)*.05),c&&(c.rotation.y=Math.sin(e*.8)*.05),i&&(i.rotation.z=Math.sin(e*.5)*.03);const s=t.humanoid?.getNormalizedBoneNode("leftShoulder"),g=t.humanoid?.getNormalizedBoneNode("rightShoulder"),f=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),x=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),u=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),A=t.humanoid?.getNormalizedBoneNode("rightLowerArm");s&&(s.rotation.z=.1),g&&(g.rotation.z=-.1),f&&(f.rotation.z=-.8+Math.sin(e*1.2)*.1,f.rotation.x=.4+Math.sin(e*.9)*.15,f.rotation.y=Math.sin(e*.7)*.1),x&&(x.rotation.z=.8+Math.sin(e*1.3)*.1,x.rotation.x=.4+Math.sin(e*1)*.15,x.rotation.y=Math.sin(e*.8)*.1),u&&(u.rotation.y=-1-Math.sin(e*1.5)*.2,u.rotation.z=Math.sin(e*1.1)*.1),A&&(A.rotation.y=1+Math.sin(e*1.4)*.2,A.rotation.z=Math.sin(e*1.2)*.1)}else{k=0,t.expressionManager?.setValue(a.VRMExpressionPresetName.Aa,0);const d=t.humanoid?.getNormalizedBoneNode("spine"),m=t.humanoid?.getNormalizedBoneNode("head");Math.floor(e)%5===0&&e-Math.floor(e)<n&&console.log("[Avatar Debug] Idle animation - Bones found:",{head:!!m,neck:!!t.humanoid?.getNormalizedBoneNode("neck"),spine:!!d}),d&&(d.rotation.x=Math.sin(e*.8)*.02),m&&(m.rotation.x=Math.sin(e*.3)*.03,m.rotation.z=Math.sin(e*.2)*.02);const c=t.humanoid?.getNormalizedBoneNode("leftShoulder"),i=t.humanoid?.getNormalizedBoneNode("rightShoulder"),s=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),g=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),f=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),x=t.humanoid?.getNormalizedBoneNode("rightLowerArm");c&&(c.rotation.z=.1),i&&(i.rotation.z=-.1),s&&(s.rotation.z=-.9,s.rotation.x=.2,s.rotation.y=0),g&&(g.rotation.z=.9,g.rotation.x=.2,g.rotation.y=0),f&&(f.rotation.y=-.8),x&&(x.rotation.y=.8)}e%4<.1?t.expressionManager?.setValue(a.VRMExpressionPresetName.Blink,1):t.expressionManager?.setValue(a.VRMExpressionPresetName.Blink,0);const h=F[b];if(t.expressionManager?.setValue(a.VRMExpressionPresetName.Happy,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Sad,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Angry,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Surprised,0),h&&t.expressionManager?.setValue(h,.8),P!=="none"){const d=e-S,m=1.5;if(d<m){const c=d/m,i=t.humanoid?.getNormalizedBoneNode("head"),s=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),g=t.humanoid?.getNormalizedBoneNode("rightLowerArm"),f=t.humanoid?.getNormalizedBoneNode("spine"),u=(A=>A<.5?2*A*A:1-Math.pow(-2*A+2,2)/2)(c<.5?c*2:(1-c)*2);switch(P){case"nod":i&&(i.rotation.x=Math.sin(c*Math.PI*3)*.2);break;case"shake":i&&(i.rotation.y=Math.sin(c*Math.PI*4)*.3);break;case"wave":s&&(s.rotation.z=1.5*u,s.rotation.x=-.3*u),g&&(g.rotation.y=.5+Math.sin(c*Math.PI*6)*.3);break;case"think":i&&(i.rotation.x=.1*u,i.rotation.z=.1*u),s&&(s.rotation.z=.3*u,s.rotation.x=.8*u),g&&(g.rotation.y=1.5*u);break;case"bow":f&&(f.rotation.x=.4*u),i&&(i.rotation.x=.2*u);break}}else P="none"}}l.render(r,N)}function $(){w!==null&&(cancelAnimationFrame(w),w=null),window.removeEventListener("resize",D),l&&p.value&&(p.value.removeChild(l.domElement),l.dispose(),l=null),t&&(t=null),r=null,N=null,y=null}return o.watch(()=>v.selectedResult,n=>{if(n?.toolName===z.TOOL_NAME&&n.data){const e=n.data;if(e.avatarUrl&&e.avatarUrl!==L&&(console.log("[Avatar Debug] VRM URL changed:",e.avatarUrl),L=e.avatarUrl,U(e.avatarUrl)),e.emotion&&e.emotion!==b&&(console.log("[Avatar Debug] Emotion changed to:",e.emotion),b=e.emotion),e.action&&e.action!=="none"){const B=e.actionTimestamp||0;B>_&&(console.log("[Avatar Debug] Action triggered:",e.action),P=e.action,S=y?.getElapsedTime()||0,_=B)}}},{deep:!0}),o.watch(()=>v.isAudioPlaying,n=>{console.log("[Avatar Debug] Plugin received isAudioPlaying:",n)}),o.onMounted(()=>{if(console.log("[Avatar Debug] View component MOUNTED"),j(),v.selectedResult?.toolName===z.TOOL_NAME&&v.selectedResult.data){const n=v.selectedResult.data;n.avatarUrl&&(console.log("[Avatar Debug] Initial VRM load:",n.avatarUrl),L=n.avatarUrl,U(n.avatarUrl)),n.emotion&&(b=n.emotion)}}),o.onUnmounted(()=>{$()}),(n,e)=>(o.openBlock(),o.createElementBlock("div",q,[o.createElementVNode("div",{ref_key:"containerRef",ref:p,class:"size-full"},null,512),M.value?(o.openBlock(),o.createElementBlock("div",H,[...e[0]||(e[0]=[o.createElementVNode("div",{class:"text-white text-lg"},"Loading Avatar...",-1)])])):o.createCommentVNode("",!0),E.value?(o.openBlock(),o.createElementBlock("div",G,[o.createElementVNode("div",W,o.toDisplayString(E.value),1)])):o.createCommentVNode("",!0),V.isAudioPlaying?(o.openBlock(),o.createElementBlock("div",J," Speaking... ")):o.createCommentVNode("",!0)]))}}),K={class:"p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md"},Q={class:"flex flex-col items-center gap-2"},X={key:0,class:"text-xs px-2 py-0.5 bg-blue-500 text-white rounded-full"},O=o.defineComponent({__name:"Preview",props:{result:{}},setup(V){const v=V,p=o.computed(()=>v.result.data),M=o.computed(()=>p.value?.emotion||"neutral");return(E,r)=>(o.openBlock(),o.createElementBlock("div",K,[o.createElementVNode("div",Q,[r[0]||(r[0]=o.createElementVNode("div",{class:"size-12 bg-slate-600 rounded-full flex items-center justify-center"},[o.createElementVNode("svg",{class:"size-8 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[o.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})])],-1)),r[1]||(r[1]=o.createElementVNode("div",{class:"text-sm font-semibold text-white text-center"}," 3D Avatar ",-1)),M.value&&M.value!=="neutral"?(o.openBlock(),o.createElementBlock("div",X,o.toDisplayString(M.value),1)):o.createCommentVNode("",!0)])]))}}),I={...z.pluginCore,viewComponent:T,previewComponent:O},Y={plugin:I};exports.SAMPLES=z.SAMPLES;exports.TOOL_DEFINITION=z.TOOL_DEFINITION;exports.TOOL_NAME=z.TOOL_NAME;exports.executeAvatar=z.executeAvatar;exports.pluginCore=z.pluginCore;exports.Preview=O;exports.View=T;exports.default=Y;exports.plugin=I;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("./three-vrm.module-FTOSkzpf.cjs"),z=require("./core.cjs"),o=require("vue"),$={class:"size-full bg-gradient-to-b from-slate-800 to-slate-900 relative"},q={key:0,class:"absolute inset-0 flex items-center justify-center bg-slate-900/80"},H={key:1,class:"absolute inset-0 flex items-center justify-center bg-slate-900/80"},G={class:"text-red-400 text-lg text-center p-4"},W={key:2,class:"absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full"},U=o.defineComponent({__name:"View",props:{selectedResult:{},sendTextMessage:{type:Function},isAudioPlaying:{type:Boolean}},setup(y){const A=y,p=o.ref(null),N=o.ref(!1),B=o.ref(null);let r=null,f=null,l=null,t=null,w=null,V=null,S=0,k="neutral",L="none",b=0,P=0,_="";const F={neutral:null,happy:a.VRMExpressionPresetName.Happy,sad:a.VRMExpressionPresetName.Sad,angry:a.VRMExpressionPresetName.Angry,surprised:a.VRMExpressionPresetName.Surprised};function I(){if(!p.value)return;const n=p.value,e=n.clientWidth,E=n.clientHeight;r=new a.Scene,f=new a.PerspectiveCamera(30,e/E,.1,100),f.position.set(0,1.3,1.5),f.lookAt(0,1.2,0),l=new a.WebGLRenderer({antialias:!0,alpha:!0}),l.setSize(e,E),l.setPixelRatio(window.devicePixelRatio),l.outputColorSpace=a.SRGBColorSpace,n.appendChild(l.domElement);const v=new a.AmbientLight(16777215,.6);r.add(v);const c=new a.DirectionalLight(16777215,.8);c.position.set(1,1,1),r.add(c),w=new a.Clock,window.addEventListener("resize",R),T()}function R(){if(!p.value||!f||!l)return;const n=p.value.clientWidth,e=p.value.clientHeight;f.aspect=n/e,f.updateProjectionMatrix(),l.setSize(n,e)}async function C(n){if(r){N.value=!0,B.value=null,t&&(r.remove(t.scene),t=null);try{const e=new a.GLTFLoader;e.register(c=>new a.VRMLoaderPlugin(c));const v=(await e.loadAsync(n)).userData.vrm;if(!v)throw new Error("Failed to load VRM data");r.add(v.scene),t=v,N.value=!1}catch(e){console.error("Failed to load VRM:",e),B.value=`Failed to load avatar: ${e instanceof Error?e.message:"Unknown error"}`,N.value=!1}}}function T(){if(V=requestAnimationFrame(T),!w||!l||!r||!f)return;const n=w.getDelta(),e=w.getElapsedTime();if(t){if(t.update(n),A.isAudioPlaying){S+=n*10;const c=(Math.sin(S)+1)*.3;t.expressionManager?.setValue(a.VRMExpressionPresetName.Aa,c);const h=t.humanoid?.getNormalizedBoneNode("head"),u=t.humanoid?.getNormalizedBoneNode("neck"),i=t.humanoid?.getNormalizedBoneNode("spine");h&&(h.rotation.x=Math.sin(e*2)*.08,h.rotation.z=Math.sin(e*1.5)*.05),u&&(u.rotation.y=Math.sin(e*.8)*.05),i&&(i.rotation.z=Math.sin(e*.5)*.03);const s=t.humanoid?.getNormalizedBoneNode("leftShoulder"),m=t.humanoid?.getNormalizedBoneNode("rightShoulder"),g=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),x=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),d=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),M=t.humanoid?.getNormalizedBoneNode("rightLowerArm");s&&(s.rotation.z=.1),m&&(m.rotation.z=-.1),g&&(g.rotation.z=-.8+Math.sin(e*1.2)*.1,g.rotation.x=.4+Math.sin(e*.9)*.15,g.rotation.y=Math.sin(e*.7)*.1),x&&(x.rotation.z=.8+Math.sin(e*1.3)*.1,x.rotation.x=.4+Math.sin(e*1)*.15,x.rotation.y=Math.sin(e*.8)*.1),d&&(d.rotation.y=-1-Math.sin(e*1.5)*.2,d.rotation.z=Math.sin(e*1.1)*.1),M&&(M.rotation.y=1+Math.sin(e*1.4)*.2,M.rotation.z=Math.sin(e*1.2)*.1)}else{S=0,t.expressionManager?.setValue(a.VRMExpressionPresetName.Aa,0);const c=t.humanoid?.getNormalizedBoneNode("spine"),h=t.humanoid?.getNormalizedBoneNode("head");c&&(c.rotation.x=Math.sin(e*.8)*.02),h&&(h.rotation.x=Math.sin(e*.3)*.03,h.rotation.z=Math.sin(e*.2)*.02);const u=t.humanoid?.getNormalizedBoneNode("leftShoulder"),i=t.humanoid?.getNormalizedBoneNode("rightShoulder"),s=t.humanoid?.getNormalizedBoneNode("leftUpperArm"),m=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),g=t.humanoid?.getNormalizedBoneNode("leftLowerArm"),x=t.humanoid?.getNormalizedBoneNode("rightLowerArm");u&&(u.rotation.z=.1),i&&(i.rotation.z=-.1),s&&(s.rotation.z=-.9,s.rotation.x=.2,s.rotation.y=0),m&&(m.rotation.z=.9,m.rotation.x=.2,m.rotation.y=0),g&&(g.rotation.y=-.8),x&&(x.rotation.y=.8)}e%4<.1?t.expressionManager?.setValue(a.VRMExpressionPresetName.Blink,1):t.expressionManager?.setValue(a.VRMExpressionPresetName.Blink,0);const v=F[k];if(t.expressionManager?.setValue(a.VRMExpressionPresetName.Happy,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Sad,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Angry,0),t.expressionManager?.setValue(a.VRMExpressionPresetName.Surprised,0),v&&t.expressionManager?.setValue(v,.8),L!=="none"){const c=e-b,h=1.5;if(c<h){const u=c/h,i=t.humanoid?.getNormalizedBoneNode("head"),s=t.humanoid?.getNormalizedBoneNode("rightUpperArm"),m=t.humanoid?.getNormalizedBoneNode("rightLowerArm"),g=t.humanoid?.getNormalizedBoneNode("spine"),d=(M=>M<.5?2*M*M:1-Math.pow(-2*M+2,2)/2)(u<.5?u*2:(1-u)*2);switch(L){case"nod":i&&(i.rotation.x=Math.sin(u*Math.PI*3)*.2);break;case"shake":i&&(i.rotation.y=Math.sin(u*Math.PI*4)*.3);break;case"wave":s&&(s.rotation.z=1.5*d,s.rotation.x=-.3*d),m&&(m.rotation.y=.5+Math.sin(u*Math.PI*6)*.3);break;case"think":i&&(i.rotation.x=.1*d,i.rotation.z=.1*d),s&&(s.rotation.z=.3*d,s.rotation.x=.8*d),m&&(m.rotation.y=1.5*d);break;case"bow":g&&(g.rotation.x=.4*d),i&&(i.rotation.x=.2*d);break}}else L="none"}}l.render(r,f)}function j(){V!==null&&(cancelAnimationFrame(V),V=null),window.removeEventListener("resize",R),l&&p.value&&(p.value.removeChild(l.domElement),l.dispose(),l=null),t&&(t=null),r=null,f=null,w=null}return o.watch(()=>A.selectedResult,n=>{if(n?.toolName===z.TOOL_NAME&&n.data){const e=n.data;if(e.avatarUrl&&e.avatarUrl!==_&&(_=e.avatarUrl,C(e.avatarUrl)),e.emotion&&e.emotion!==k&&(console.log("[Avatar Debug] Emotion changed to:",e.emotion),k=e.emotion),e.action&&e.action!=="none"){const E=e.actionTimestamp||0;E>P&&(console.log("[Avatar Debug] Action triggered:",e.action),L=e.action,b=w?.getElapsedTime()||0,P=E)}}},{deep:!0}),o.onMounted(()=>{if(I(),A.selectedResult?.toolName===z.TOOL_NAME&&A.selectedResult.data){const n=A.selectedResult.data;n.avatarUrl&&(_=n.avatarUrl,C(n.avatarUrl)),n.emotion&&(k=n.emotion)}}),o.onUnmounted(()=>{j()}),(n,e)=>(o.openBlock(),o.createElementBlock("div",$,[o.createElementVNode("div",{ref_key:"containerRef",ref:p,class:"size-full"},null,512),N.value?(o.openBlock(),o.createElementBlock("div",q,[...e[0]||(e[0]=[o.createElementVNode("div",{class:"text-white text-lg"},"Loading Avatar...",-1)])])):o.createCommentVNode("",!0),B.value?(o.openBlock(),o.createElementBlock("div",H,[o.createElementVNode("div",G,o.toDisplayString(B.value),1)])):o.createCommentVNode("",!0),y.isAudioPlaying?(o.openBlock(),o.createElementBlock("div",W," Speaking... ")):o.createCommentVNode("",!0)]))}}),J={class:"p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md"},K={class:"flex flex-col items-center gap-2"},Q={key:0,class:"text-xs px-2 py-0.5 bg-blue-500 text-white rounded-full"},O=o.defineComponent({__name:"Preview",props:{result:{}},setup(y){const A=y,p=o.computed(()=>A.result.data),N=o.computed(()=>p.value?.emotion||"neutral");return(B,r)=>(o.openBlock(),o.createElementBlock("div",J,[o.createElementVNode("div",K,[r[0]||(r[0]=o.createElementVNode("div",{class:"size-12 bg-slate-600 rounded-full flex items-center justify-center"},[o.createElementVNode("svg",{class:"size-8 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[o.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})])],-1)),r[1]||(r[1]=o.createElementVNode("div",{class:"text-sm font-semibold text-white text-center"}," 3D Avatar ",-1)),N.value&&N.value!=="neutral"?(o.openBlock(),o.createElementBlock("div",Q,o.toDisplayString(N.value),1)):o.createCommentVNode("",!0)])]))}}),D={...z.pluginCore,viewComponent:U,previewComponent:O},X={plugin:D};exports.SAMPLES=z.SAMPLES;exports.TOOL_DEFINITION=z.TOOL_DEFINITION;exports.TOOL_NAME=z.TOOL_NAME;exports.executeAvatar=z.executeAvatar;exports.pluginCore=z.pluginCore;exports.Preview=O;exports.View=U;exports.default=X;exports.plugin=D;
package/dist/vue.js CHANGED
@@ -1,182 +1,167 @@
1
- import { S as K, P as Q, W as X, a as Y, A as Z, D as ee, G as te, V as oe, b as m, C as ne } from "./three-vrm.module-DJ7DURJm.js";
2
- import { TOOL_NAME as O, pluginCore as ae } from "./core.js";
3
- import { SAMPLES as ye, TOOL_DEFINITION as Be, executeAvatar as be } from "./core.js";
4
- import { defineComponent as G, ref as R, watch as j, onMounted as ie, onUnmounted as re, openBlock as y, createElementBlock as B, createElementVNode as N, createCommentVNode as U, toDisplayString as H, computed as $ } from "vue";
5
- const se = { class: "size-full bg-gradient-to-b from-slate-800 to-slate-900 relative" }, le = {
1
+ import { S as q, P as J, W as K, a as Q, A as X, D as Y, G as Z, V as ee, b as u, C as te } from "./three-vrm.module-DJ7DURJm.js";
2
+ import { TOOL_NAME as I, pluginCore as oe } from "./core.js";
3
+ import { SAMPLES as Ae, TOOL_DEFINITION as ye, executeAvatar as Be } from "./core.js";
4
+ import { defineComponent as j, ref as P, watch as ne, onMounted as ae, onUnmounted as ie, openBlock as y, createElementBlock as B, createElementVNode as z, createCommentVNode as U, toDisplayString as $, computed as O } from "vue";
5
+ const re = { class: "size-full bg-gradient-to-b from-slate-800 to-slate-900 relative" }, se = {
6
6
  key: 0,
7
7
  class: "absolute inset-0 flex items-center justify-center bg-slate-900/80"
8
- }, de = {
8
+ }, le = {
9
9
  key: 1,
10
10
  class: "absolute inset-0 flex items-center justify-center bg-slate-900/80"
11
- }, ce = { class: "text-red-400 text-lg text-center p-4" }, ue = {
11
+ }, de = { class: "text-red-400 text-lg text-center p-4" }, ce = {
12
12
  key: 2,
13
13
  class: "absolute top-4 right-4 px-3 py-1 bg-green-600 text-white text-sm rounded-full"
14
- }, me = /* @__PURE__ */ G({
14
+ }, ue = /* @__PURE__ */ j({
15
15
  __name: "View",
16
16
  props: {
17
17
  selectedResult: {},
18
18
  sendTextMessage: { type: Function },
19
19
  isAudioPlaying: { type: Boolean }
20
20
  },
21
- setup(k) {
22
- const f = k, g = R(null), x = R(!1), b = R(null);
23
- let a = null, v = null, r = null, t = null, w = null, L = null, V = 0, S = "neutral", D = "none", E = 0, C = 0, _ = "";
24
- const W = {
21
+ setup(b) {
22
+ const M = b, m = P(null), g = P(!1), k = P(null);
23
+ let a = null, f = null, r = null, t = null, A = null, L = null, V = 0, S = "neutral", _ = "none", C = 0, R = 0, E = "";
24
+ const G = {
25
25
  neutral: null,
26
- happy: m.Happy,
27
- sad: m.Sad,
28
- angry: m.Angry,
29
- surprised: m.Surprised
26
+ happy: u.Happy,
27
+ sad: u.Sad,
28
+ angry: u.Angry,
29
+ surprised: u.Surprised
30
30
  };
31
- function q() {
32
- if (!g.value) return;
33
- const o = g.value, e = o.clientWidth, z = o.clientHeight;
34
- a = new K(), v = new Q(30, e / z, 0.1, 100), v.position.set(0, 1.3, 1.5), v.lookAt(0, 1.2, 0), r = new X({ antialias: !0, alpha: !0 }), r.setSize(e, z), r.setPixelRatio(window.devicePixelRatio), r.outputColorSpace = Y, o.appendChild(r.domElement);
35
- const h = new Z(16777215, 0.6);
36
- a.add(h);
37
- const s = new ee(16777215, 0.8);
38
- s.position.set(1, 1, 1), a.add(s), w = new ne(), window.addEventListener("resize", T), I();
31
+ function H() {
32
+ if (!m.value) return;
33
+ const o = m.value, e = o.clientWidth, w = o.clientHeight;
34
+ a = new q(), f = new J(30, e / w, 0.1, 100), f.position.set(0, 1.3, 1.5), f.lookAt(0, 1.2, 0), r = new K({ antialias: !0, alpha: !0 }), r.setSize(e, w), r.setPixelRatio(window.devicePixelRatio), r.outputColorSpace = Q, o.appendChild(r.domElement);
35
+ const v = new X(16777215, 0.6);
36
+ a.add(v);
37
+ const l = new Y(16777215, 0.8);
38
+ l.position.set(1, 1, 1), a.add(l), A = new te(), window.addEventListener("resize", T), F();
39
39
  }
40
40
  function T() {
41
- if (!g.value || !v || !r) return;
42
- const o = g.value.clientWidth, e = g.value.clientHeight;
43
- v.aspect = o / e, v.updateProjectionMatrix(), r.setSize(o, e);
41
+ if (!m.value || !f || !r) return;
42
+ const o = m.value.clientWidth, e = m.value.clientHeight;
43
+ f.aspect = o / e, f.updateProjectionMatrix(), r.setSize(o, e);
44
44
  }
45
- async function F(o) {
45
+ async function D(o) {
46
46
  if (a) {
47
- x.value = !0, b.value = null, t && (a.remove(t.scene), t = null);
47
+ g.value = !0, k.value = null, t && (a.remove(t.scene), t = null);
48
48
  try {
49
- const e = new te();
50
- e.register((s) => new oe(s));
51
- const h = (await e.loadAsync(o)).userData.vrm;
52
- if (!h)
49
+ const e = new Z();
50
+ e.register((l) => new ee(l));
51
+ const v = (await e.loadAsync(o)).userData.vrm;
52
+ if (!v)
53
53
  throw new Error("Failed to load VRM data");
54
- a.add(h.scene), t = h, console.log("[Avatar Debug] VRM loaded successfully"), console.log("[Avatar Debug] VRM humanoid:", !!h.humanoid), console.log("[Avatar Debug] VRM expressionManager:", !!h.expressionManager), x.value = !1;
54
+ a.add(v.scene), t = v, g.value = !1;
55
55
  } catch (e) {
56
- console.error("Failed to load VRM:", e), b.value = `Failed to load avatar: ${e instanceof Error ? e.message : "Unknown error"}`, x.value = !1;
56
+ console.error("Failed to load VRM:", e), k.value = `Failed to load avatar: ${e instanceof Error ? e.message : "Unknown error"}`, g.value = !1;
57
57
  }
58
58
  }
59
59
  }
60
- let P = 0;
61
- function I() {
62
- if (L = requestAnimationFrame(I), !w || !r || !a || !v) return;
63
- const o = w.getDelta(), e = w.getElapsedTime();
64
- if (P++, P % 300 === 0 && console.log("[Avatar Debug] animate() running, frame:", P, "currentVrm:", !!t, "isAudioPlaying:", f.isAudioPlaying), t) {
65
- if (t.update(o), f.isAudioPlaying) {
60
+ function F() {
61
+ if (L = requestAnimationFrame(F), !A || !r || !a || !f) return;
62
+ const o = A.getDelta(), e = A.getElapsedTime();
63
+ if (t) {
64
+ if (t.update(o), M.isAudioPlaying) {
66
65
  V += o * 10;
67
- const s = (Math.sin(V) + 1) * 0.3;
68
- t.expressionManager?.setValue(m.Aa, s);
69
- const c = t.humanoid?.getNormalizedBoneNode("head"), l = t.humanoid?.getNormalizedBoneNode("neck"), n = t.humanoid?.getNormalizedBoneNode("spine");
70
- V < 0.2 && console.log("[Avatar Debug] Body animation - Bones found:", {
71
- head: !!c,
72
- neck: !!l,
73
- spine: !!n,
74
- humanoid: !!t.humanoid
75
- }), c && (c.rotation.x = Math.sin(e * 2) * 0.08, c.rotation.z = Math.sin(e * 1.5) * 0.05), l && (l.rotation.y = Math.sin(e * 0.8) * 0.05), n && (n.rotation.z = Math.sin(e * 0.5) * 0.03);
76
- const i = t.humanoid?.getNormalizedBoneNode("leftShoulder"), u = t.humanoid?.getNormalizedBoneNode("rightShoulder"), p = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), A = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), d = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), M = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
77
- i && (i.rotation.z = 0.1), u && (u.rotation.z = -0.1), p && (p.rotation.z = -0.8 + Math.sin(e * 1.2) * 0.1, p.rotation.x = 0.4 + Math.sin(e * 0.9) * 0.15, p.rotation.y = Math.sin(e * 0.7) * 0.1), A && (A.rotation.z = 0.8 + Math.sin(e * 1.3) * 0.1, A.rotation.x = 0.4 + Math.sin(e * 1) * 0.15, A.rotation.y = Math.sin(e * 0.8) * 0.1), d && (d.rotation.y = -1 - Math.sin(e * 1.5) * 0.2, d.rotation.z = Math.sin(e * 1.1) * 0.1), M && (M.rotation.y = 1 + Math.sin(e * 1.4) * 0.2, M.rotation.z = Math.sin(e * 1.2) * 0.1);
66
+ const l = (Math.sin(V) + 1) * 0.3;
67
+ t.expressionManager?.setValue(u.Aa, l);
68
+ const h = t.humanoid?.getNormalizedBoneNode("head"), d = t.humanoid?.getNormalizedBoneNode("neck"), n = t.humanoid?.getNormalizedBoneNode("spine");
69
+ h && (h.rotation.x = Math.sin(e * 2) * 0.08, h.rotation.z = Math.sin(e * 1.5) * 0.05), d && (d.rotation.y = Math.sin(e * 0.8) * 0.05), n && (n.rotation.z = Math.sin(e * 0.5) * 0.03);
70
+ const i = t.humanoid?.getNormalizedBoneNode("leftShoulder"), c = t.humanoid?.getNormalizedBoneNode("rightShoulder"), p = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), x = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), s = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), N = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
71
+ i && (i.rotation.z = 0.1), c && (c.rotation.z = -0.1), p && (p.rotation.z = -0.8 + Math.sin(e * 1.2) * 0.1, p.rotation.x = 0.4 + Math.sin(e * 0.9) * 0.15, p.rotation.y = Math.sin(e * 0.7) * 0.1), x && (x.rotation.z = 0.8 + Math.sin(e * 1.3) * 0.1, x.rotation.x = 0.4 + Math.sin(e * 1) * 0.15, x.rotation.y = Math.sin(e * 0.8) * 0.1), s && (s.rotation.y = -1 - Math.sin(e * 1.5) * 0.2, s.rotation.z = Math.sin(e * 1.1) * 0.1), N && (N.rotation.y = 1 + Math.sin(e * 1.4) * 0.2, N.rotation.z = Math.sin(e * 1.2) * 0.1);
78
72
  } else {
79
- V = 0, t.expressionManager?.setValue(m.Aa, 0);
80
- const s = t.humanoid?.getNormalizedBoneNode("spine"), c = t.humanoid?.getNormalizedBoneNode("head");
81
- Math.floor(e) % 5 === 0 && e - Math.floor(e) < o && console.log("[Avatar Debug] Idle animation - Bones found:", {
82
- head: !!c,
83
- neck: !!t.humanoid?.getNormalizedBoneNode("neck"),
84
- spine: !!s
85
- }), s && (s.rotation.x = Math.sin(e * 0.8) * 0.02), c && (c.rotation.x = Math.sin(e * 0.3) * 0.03, c.rotation.z = Math.sin(e * 0.2) * 0.02);
86
- const l = t.humanoid?.getNormalizedBoneNode("leftShoulder"), n = t.humanoid?.getNormalizedBoneNode("rightShoulder"), i = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), u = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), p = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), A = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
87
- l && (l.rotation.z = 0.1), n && (n.rotation.z = -0.1), i && (i.rotation.z = -0.9, i.rotation.x = 0.2, i.rotation.y = 0), u && (u.rotation.z = 0.9, u.rotation.x = 0.2, u.rotation.y = 0), p && (p.rotation.y = -0.8), A && (A.rotation.y = 0.8);
73
+ V = 0, t.expressionManager?.setValue(u.Aa, 0);
74
+ const l = t.humanoid?.getNormalizedBoneNode("spine"), h = t.humanoid?.getNormalizedBoneNode("head");
75
+ l && (l.rotation.x = Math.sin(e * 0.8) * 0.02), h && (h.rotation.x = Math.sin(e * 0.3) * 0.03, h.rotation.z = Math.sin(e * 0.2) * 0.02);
76
+ const d = t.humanoid?.getNormalizedBoneNode("leftShoulder"), n = t.humanoid?.getNormalizedBoneNode("rightShoulder"), i = t.humanoid?.getNormalizedBoneNode("leftUpperArm"), c = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), p = t.humanoid?.getNormalizedBoneNode("leftLowerArm"), x = t.humanoid?.getNormalizedBoneNode("rightLowerArm");
77
+ d && (d.rotation.z = 0.1), n && (n.rotation.z = -0.1), i && (i.rotation.z = -0.9, i.rotation.x = 0.2, i.rotation.y = 0), c && (c.rotation.z = 0.9, c.rotation.x = 0.2, c.rotation.y = 0), p && (p.rotation.y = -0.8), x && (x.rotation.y = 0.8);
88
78
  }
89
- e % 4 < 0.1 ? t.expressionManager?.setValue(m.Blink, 1) : t.expressionManager?.setValue(m.Blink, 0);
90
- const h = W[S];
91
- if (t.expressionManager?.setValue(m.Happy, 0), t.expressionManager?.setValue(m.Sad, 0), t.expressionManager?.setValue(m.Angry, 0), t.expressionManager?.setValue(m.Surprised, 0), h && t.expressionManager?.setValue(h, 0.8), D !== "none") {
92
- const s = e - E, c = 1.5;
93
- if (s < c) {
94
- const l = s / c, n = t.humanoid?.getNormalizedBoneNode("head"), i = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), u = t.humanoid?.getNormalizedBoneNode("rightLowerArm"), p = t.humanoid?.getNormalizedBoneNode("spine"), d = ((M) => M < 0.5 ? 2 * M * M : 1 - Math.pow(-2 * M + 2, 2) / 2)(l < 0.5 ? l * 2 : (1 - l) * 2);
95
- switch (D) {
79
+ e % 4 < 0.1 ? t.expressionManager?.setValue(u.Blink, 1) : t.expressionManager?.setValue(u.Blink, 0);
80
+ const v = G[S];
81
+ if (t.expressionManager?.setValue(u.Happy, 0), t.expressionManager?.setValue(u.Sad, 0), t.expressionManager?.setValue(u.Angry, 0), t.expressionManager?.setValue(u.Surprised, 0), v && t.expressionManager?.setValue(v, 0.8), _ !== "none") {
82
+ const l = e - C, h = 1.5;
83
+ if (l < h) {
84
+ const d = l / h, n = t.humanoid?.getNormalizedBoneNode("head"), i = t.humanoid?.getNormalizedBoneNode("rightUpperArm"), c = t.humanoid?.getNormalizedBoneNode("rightLowerArm"), p = t.humanoid?.getNormalizedBoneNode("spine"), s = ((N) => N < 0.5 ? 2 * N * N : 1 - Math.pow(-2 * N + 2, 2) / 2)(d < 0.5 ? d * 2 : (1 - d) * 2);
85
+ switch (_) {
96
86
  case "nod":
97
- n && (n.rotation.x = Math.sin(l * Math.PI * 3) * 0.2);
87
+ n && (n.rotation.x = Math.sin(d * Math.PI * 3) * 0.2);
98
88
  break;
99
89
  case "shake":
100
- n && (n.rotation.y = Math.sin(l * Math.PI * 4) * 0.3);
90
+ n && (n.rotation.y = Math.sin(d * Math.PI * 4) * 0.3);
101
91
  break;
102
92
  case "wave":
103
- i && (i.rotation.z = 1.5 * d, i.rotation.x = -0.3 * d), u && (u.rotation.y = 0.5 + Math.sin(l * Math.PI * 6) * 0.3);
93
+ i && (i.rotation.z = 1.5 * s, i.rotation.x = -0.3 * s), c && (c.rotation.y = 0.5 + Math.sin(d * Math.PI * 6) * 0.3);
104
94
  break;
105
95
  case "think":
106
- n && (n.rotation.x = 0.1 * d, n.rotation.z = 0.1 * d), i && (i.rotation.z = 0.3 * d, i.rotation.x = 0.8 * d), u && (u.rotation.y = 1.5 * d);
96
+ n && (n.rotation.x = 0.1 * s, n.rotation.z = 0.1 * s), i && (i.rotation.z = 0.3 * s, i.rotation.x = 0.8 * s), c && (c.rotation.y = 1.5 * s);
107
97
  break;
108
98
  case "bow":
109
- p && (p.rotation.x = 0.4 * d), n && (n.rotation.x = 0.2 * d);
99
+ p && (p.rotation.x = 0.4 * s), n && (n.rotation.x = 0.2 * s);
110
100
  break;
111
101
  }
112
102
  } else
113
- D = "none";
103
+ _ = "none";
114
104
  }
115
105
  }
116
- r.render(a, v);
106
+ r.render(a, f);
117
107
  }
118
- function J() {
119
- L !== null && (cancelAnimationFrame(L), L = null), window.removeEventListener("resize", T), r && g.value && (g.value.removeChild(r.domElement), r.dispose(), r = null), t && (t = null), a = null, v = null, w = null;
108
+ function W() {
109
+ L !== null && (cancelAnimationFrame(L), L = null), window.removeEventListener("resize", T), r && m.value && (m.value.removeChild(r.domElement), r.dispose(), r = null), t && (t = null), a = null, f = null, A = null;
120
110
  }
121
- return j(
122
- () => f.selectedResult,
111
+ return ne(
112
+ () => M.selectedResult,
123
113
  (o) => {
124
- if (o?.toolName === O && o.data) {
114
+ if (o?.toolName === I && o.data) {
125
115
  const e = o.data;
126
- if (e.avatarUrl && e.avatarUrl !== _ && (console.log("[Avatar Debug] VRM URL changed:", e.avatarUrl), _ = e.avatarUrl, F(e.avatarUrl)), e.emotion && e.emotion !== S && (console.log("[Avatar Debug] Emotion changed to:", e.emotion), S = e.emotion), e.action && e.action !== "none") {
127
- const z = e.actionTimestamp || 0;
128
- z > C && (console.log("[Avatar Debug] Action triggered:", e.action), D = e.action, E = w?.getElapsedTime() || 0, C = z);
116
+ if (e.avatarUrl && e.avatarUrl !== E && (E = e.avatarUrl, D(e.avatarUrl)), e.emotion && e.emotion !== S && (console.log("[Avatar Debug] Emotion changed to:", e.emotion), S = e.emotion), e.action && e.action !== "none") {
117
+ const w = e.actionTimestamp || 0;
118
+ w > R && (console.log("[Avatar Debug] Action triggered:", e.action), _ = e.action, C = A?.getElapsedTime() || 0, R = w);
129
119
  }
130
120
  }
131
121
  },
132
122
  { deep: !0 }
133
- ), j(
134
- () => f.isAudioPlaying,
135
- (o) => {
136
- console.log("[Avatar Debug] Plugin received isAudioPlaying:", o);
137
- }
138
- ), ie(() => {
139
- if (console.log("[Avatar Debug] View component MOUNTED"), q(), f.selectedResult?.toolName === O && f.selectedResult.data) {
140
- const o = f.selectedResult.data;
141
- o.avatarUrl && (console.log("[Avatar Debug] Initial VRM load:", o.avatarUrl), _ = o.avatarUrl, F(o.avatarUrl)), o.emotion && (S = o.emotion);
123
+ ), ae(() => {
124
+ if (H(), M.selectedResult?.toolName === I && M.selectedResult.data) {
125
+ const o = M.selectedResult.data;
126
+ o.avatarUrl && (E = o.avatarUrl, D(o.avatarUrl)), o.emotion && (S = o.emotion);
142
127
  }
143
- }), re(() => {
144
- J();
145
- }), (o, e) => (y(), B("div", se, [
146
- N("div", {
128
+ }), ie(() => {
129
+ W();
130
+ }), (o, e) => (y(), B("div", re, [
131
+ z("div", {
147
132
  ref_key: "containerRef",
148
- ref: g,
133
+ ref: m,
149
134
  class: "size-full"
150
135
  }, null, 512),
151
- x.value ? (y(), B("div", le, [...e[0] || (e[0] = [
152
- N("div", { class: "text-white text-lg" }, "Loading Avatar...", -1)
136
+ g.value ? (y(), B("div", se, [...e[0] || (e[0] = [
137
+ z("div", { class: "text-white text-lg" }, "Loading Avatar...", -1)
153
138
  ])])) : U("", !0),
154
- b.value ? (y(), B("div", de, [
155
- N("div", ce, H(b.value), 1)
139
+ k.value ? (y(), B("div", le, [
140
+ z("div", de, $(k.value), 1)
156
141
  ])) : U("", !0),
157
- k.isAudioPlaying ? (y(), B("div", ue, " Speaking... ")) : U("", !0)
142
+ b.isAudioPlaying ? (y(), B("div", ce, " Speaking... ")) : U("", !0)
158
143
  ]));
159
144
  }
160
- }), ge = { class: "p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md" }, he = { class: "flex flex-col items-center gap-2" }, pe = {
145
+ }), me = { class: "p-3 bg-gradient-to-br from-slate-700 to-slate-800 rounded-md" }, he = { class: "flex flex-col items-center gap-2" }, pe = {
161
146
  key: 0,
162
147
  class: "text-xs px-2 py-0.5 bg-blue-500 text-white rounded-full"
163
- }, fe = /* @__PURE__ */ G({
148
+ }, fe = /* @__PURE__ */ j({
164
149
  __name: "Preview",
165
150
  props: {
166
151
  result: {}
167
152
  },
168
- setup(k) {
169
- const f = k, g = $(() => f.result.data), x = $(() => g.value?.emotion || "neutral");
170
- return (b, a) => (y(), B("div", ge, [
171
- N("div", he, [
172
- a[0] || (a[0] = N("div", { class: "size-12 bg-slate-600 rounded-full flex items-center justify-center" }, [
173
- N("svg", {
153
+ setup(b) {
154
+ const M = b, m = O(() => M.result.data), g = O(() => m.value?.emotion || "neutral");
155
+ return (k, a) => (y(), B("div", me, [
156
+ z("div", he, [
157
+ a[0] || (a[0] = z("div", { class: "size-12 bg-slate-600 rounded-full flex items-center justify-center" }, [
158
+ z("svg", {
174
159
  class: "size-8 text-slate-300",
175
160
  fill: "none",
176
161
  stroke: "currentColor",
177
162
  viewBox: "0 0 24 24"
178
163
  }, [
179
- N("path", {
164
+ z("path", {
180
165
  "stroke-linecap": "round",
181
166
  "stroke-linejoin": "round",
182
167
  "stroke-width": "2",
@@ -184,24 +169,24 @@ const se = { class: "size-full bg-gradient-to-b from-slate-800 to-slate-900 rela
184
169
  })
185
170
  ])
186
171
  ], -1)),
187
- a[1] || (a[1] = N("div", { class: "text-sm font-semibold text-white text-center" }, " 3D Avatar ", -1)),
188
- x.value && x.value !== "neutral" ? (y(), B("div", pe, H(x.value), 1)) : U("", !0)
172
+ a[1] || (a[1] = z("div", { class: "text-sm font-semibold text-white text-center" }, " 3D Avatar ", -1)),
173
+ g.value && g.value !== "neutral" ? (y(), B("div", pe, $(g.value), 1)) : U("", !0)
189
174
  ])
190
175
  ]));
191
176
  }
192
- }), ve = {
193
- ...ae,
194
- viewComponent: me,
177
+ }), ge = {
178
+ ...oe,
179
+ viewComponent: ue,
195
180
  previewComponent: fe
196
- }, Ne = { plugin: ve };
181
+ }, ze = { plugin: ge };
197
182
  export {
198
183
  fe as Preview,
199
- ye as SAMPLES,
200
- Be as TOOL_DEFINITION,
201
- O as TOOL_NAME,
202
- me as View,
203
- Ne as default,
204
- be as executeAvatar,
205
- ve as plugin,
206
- ae as pluginCore
184
+ Ae as SAMPLES,
185
+ ye as TOOL_DEFINITION,
186
+ I as TOOL_NAME,
187
+ ue as View,
188
+ ze as default,
189
+ Be as executeAvatar,
190
+ ge as plugin,
191
+ oe as pluginCore
207
192
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gui-chat-plugin/avatar",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "3D Avatar Plugin for GUIChat - VRM avatar with lip-sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",