@w0nna_dev/lina-widget 1.0.2 → 1.0.4
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/lina-widget.es.js
CHANGED
|
@@ -41535,37 +41535,39 @@ const rw = {
|
|
|
41535
41535
|
};
|
|
41536
41536
|
class aw {
|
|
41537
41537
|
constructor(e, t = {}) {
|
|
41538
|
-
this.shellSegments = [], this.coreInner = null, this.coreOuter = null, this.coreGlow = null, this.pulseRings = [], this.particles = null, this.particlePositions = null, this.particleVelocities = null, this.animationId = null, this._currentState = "idle", this._currentEmotion = "neutral", this.targetConfig = { ...rl.idle }, this.currentConfig = { ...rl.idle }, this.
|
|
41538
|
+
this.shellSegments = [], this.coreInner = null, this.coreOuter = null, this.coreGlow = null, this.pulseRings = [], this.particles = null, this.particlePositions = null, this.particleVelocities = null, this.animationId = null, this._currentState = "idle", this._currentEmotion = "neutral", this.targetConfig = { ...rl.idle }, this.currentConfig = { ...rl.idle }, this.targetAudioLevel = 0, this.currentAudioLevel = 0, this.audioVelocity = 0, this.targetPulseColor = new Ue("#a855f7"), this.currentPulseColor = new Ue("#a855f7"), this.targetRotation = { x: 0, y: 0 }, this.currentRotation = { x: 0, y: 0 }, this.time = 0, this.animate = () => {
|
|
41539
41539
|
this.animationId = requestAnimationFrame(this.animate);
|
|
41540
41540
|
const n = this.clock.getDelta();
|
|
41541
41541
|
this.time += n;
|
|
41542
41542
|
const s = 0.05;
|
|
41543
41543
|
this.currentConfig.coreIntensity += (this.targetConfig.coreIntensity - this.currentConfig.coreIntensity) * s, this.currentConfig.lightningCount += (this.targetConfig.lightningCount - this.currentConfig.lightningCount) * s, this.currentConfig.lightningIntensity += (this.targetConfig.lightningIntensity - this.currentConfig.lightningIntensity) * s, this.currentConfig.particleSpeed += (this.targetConfig.particleSpeed - this.currentConfig.particleSpeed) * s, this.currentConfig.coreScale += (this.targetConfig.coreScale - this.currentConfig.coreScale) * s;
|
|
41544
|
-
const r =
|
|
41545
|
-
|
|
41546
|
-
|
|
41547
|
-
|
|
41548
|
-
const
|
|
41549
|
-
this.
|
|
41544
|
+
const r = 0.08, o = 0.75, a = (this.targetAudioLevel - this.currentAudioLevel) * r;
|
|
41545
|
+
this.audioVelocity += a, this.audioVelocity *= o, this.currentAudioLevel += this.audioVelocity, this.currentAudioLevel = Math.max(0, Math.min(1, this.currentAudioLevel));
|
|
41546
|
+
const c = 1 + this.currentAudioLevel * 0.4;
|
|
41547
|
+
if (this.coreLight && (this.coreLight.intensity = 3 + this.currentConfig.coreIntensity * 2 * c), this.coreInner) {
|
|
41548
|
+
const l = this.coreInner.material;
|
|
41549
|
+
l.uniforms && (l.uniforms.uTime.value = this.time, l.uniforms.uIntensity.value = this.currentConfig.coreIntensity * c);
|
|
41550
|
+
const d = this.currentConfig.coreScale * 0.9 * c;
|
|
41551
|
+
this.coreInner.scale.setScalar(d);
|
|
41550
41552
|
}
|
|
41551
41553
|
if (this.coreOuter) {
|
|
41552
|
-
const
|
|
41553
|
-
|
|
41554
|
-
const
|
|
41555
|
-
this.coreOuter.scale.setScalar(
|
|
41554
|
+
const l = this.coreOuter.material;
|
|
41555
|
+
l.uniforms.uTime.value = this.time, l.uniforms.uIntensity.value = this.currentConfig.coreIntensity * c;
|
|
41556
|
+
const d = this.currentConfig.coreScale * c;
|
|
41557
|
+
this.coreOuter.scale.setScalar(d);
|
|
41556
41558
|
}
|
|
41557
41559
|
if (this.coreGlow) {
|
|
41558
|
-
const
|
|
41559
|
-
|
|
41560
|
-
const
|
|
41561
|
-
this.coreGlow.scale.setScalar(
|
|
41560
|
+
const l = this.coreGlow.material;
|
|
41561
|
+
l.uniforms.uTime.value = this.time, l.uniforms.uIntensity.value = this.currentConfig.coreIntensity * 0.7 * c;
|
|
41562
|
+
const d = 1 + Math.sin(this.time * 1.5) * 0.03 * this.currentConfig.coreIntensity;
|
|
41563
|
+
this.coreGlow.scale.setScalar(d);
|
|
41562
41564
|
}
|
|
41563
41565
|
this.updateParticles(n), this.currentPulseColor.lerp(this.targetPulseColor, 0.08);
|
|
41564
|
-
for (const
|
|
41565
|
-
const
|
|
41566
|
-
|
|
41567
|
-
const
|
|
41568
|
-
|
|
41566
|
+
for (const l of this.pulseRings) {
|
|
41567
|
+
const d = l.material;
|
|
41568
|
+
d.uniforms.uTime.value = this.time, d.uniforms.uAudioLevel.value = this.currentAudioLevel, d.uniforms.uIntensity.value = this.currentConfig.coreIntensity, d.uniforms.uColor.value.copy(this.currentPulseColor);
|
|
41569
|
+
const u = l.ringConfig;
|
|
41570
|
+
l.rotation.y += 3e-3 * u.speed, l.rotation.x = u.tiltX + Math.sin(this.time * 0.5 + u.phase) * 0.1, l.rotation.z = u.tiltZ + Math.cos(this.time * 0.4 + u.phase) * 0.08;
|
|
41569
41571
|
}
|
|
41570
41572
|
this.currentRotation.x += (this.targetRotation.x - this.currentRotation.x) * 0.05, this.currentRotation.y += (this.targetRotation.y - this.currentRotation.y) * 0.05, this.scene.rotation.x = this.currentRotation.x, this.scene.rotation.y = this.currentRotation.y, this.renderer.render(this.scene, this.camera);
|
|
41571
41573
|
}, this.handleResize = () => {
|
|
@@ -42078,7 +42080,7 @@ class aw {
|
|
|
42078
42080
|
return this._currentState;
|
|
42079
42081
|
}
|
|
42080
42082
|
setAudioLevel(e) {
|
|
42081
|
-
this.
|
|
42083
|
+
this.targetAudioLevel = Math.max(0, Math.min(1, e));
|
|
42082
42084
|
}
|
|
42083
42085
|
/**
|
|
42084
42086
|
* Set emotion for pulse line color
|
|
@@ -42132,7 +42134,7 @@ var ow = Object.defineProperty, cw = Object.getOwnPropertyDescriptor, Ln = (i, e
|
|
|
42132
42134
|
};
|
|
42133
42135
|
let gn = class extends Qi {
|
|
42134
42136
|
constructor() {
|
|
42135
|
-
super(...arguments), this.orbRenderer = null, this.orbContainerRef = No(), this.audioSimPhase = 0, this.animationId = null, this.callManager = null, this.size = 300, this.headerLogo = "HANC.ai", this.headerTitle = "Lina-Voice AI", this.showBranding = !0, this.version = "v1.0.
|
|
42137
|
+
super(...arguments), this.orbRenderer = null, this.orbContainerRef = No(), this.audioSimPhase = 0, this.animationId = null, this.callManager = null, this.size = 300, this.headerLogo = "HANC.ai", this.headerTitle = "Lina-Voice AI", this.showBranding = !0, this.version = "v1.0.3", this.agentId = "", this.voiceServiceUrl = "", this.btnStartText = "Start", this.btnEndText = "End", this.colors = {}, this.currentState = "idle", this.callStatus = "idle", this._hasMicPermission = null, this.handleCallClick = async () => {
|
|
42136
42138
|
if (this.callStatus === "mic-denied")
|
|
42137
42139
|
try {
|
|
42138
42140
|
(await navigator.mediaDevices.getUserMedia({ audio: !0 })).getTracks().forEach((e) => e.stop()), this._hasMicPermission = !0, this.callStatus = "idle";
|
package/dist/lina-widget.umd.js
CHANGED
|
@@ -5206,7 +5206,7 @@ void main() {
|
|
|
5206
5206
|
display: inline-block;
|
|
5207
5207
|
contain: layout style;
|
|
5208
5208
|
}
|
|
5209
|
-
`,Et([pe({type:String,attribute:"agent-id"})],$.PillCall.prototype,"agentId",2),Et([pe({type:String,attribute:"voice-service-url"})],$.PillCall.prototype,"voiceServiceUrl",2),Et([Fi()],$.PillCall.prototype,"callStatus",2),Et([Fi()],$.PillCall.prototype,"microphoneEnabled",2),Et([pe({type:String,attribute:"button-start-text"})],$.PillCall.prototype,"buttonStartText",2),Et([pe({type:String,attribute:"button-connecting-text"})],$.PillCall.prototype,"buttonConnectingText",2),Et([pe({type:String,attribute:"button-end-text"})],$.PillCall.prototype,"buttonEndText",2),Et([pe({type:Number,attribute:"orb-size"})],$.PillCall.prototype,"orbSize",2),Et([pe({type:String,attribute:"theme"})],$.PillCall.prototype,"theme",2),Et([pe({type:String,attribute:"theme-mode"})],$.PillCall.prototype,"themeMode",2),Et([pe({type:Object,attribute:"orb-colors"})],$.PillCall.prototype,"orbColors",2),Et([pe({type:Number,attribute:"glow-intensity"})],$.PillCall.prototype,"glowIntensity",2),Et([pe({type:Number,attribute:"idle-glow-multiplier"})],$.PillCall.prototype,"idleGlowMultiplier",2),Et([pe({type:Number,attribute:"morph-strength"})],$.PillCall.prototype,"morphStrength",2),Et([pe({type:Number,attribute:"noise-scale"})],$.PillCall.prototype,"noiseScale",2),Et([pe({type:Number,attribute:"noise-speed"})],$.PillCall.prototype,"noiseSpeed",2),Et([pe({type:Number,attribute:"fresnel-power"})],$.PillCall.prototype,"fresnelPower",2),Et([pe({type:Number,attribute:"rotation-speed"})],$.PillCall.prototype,"rotationSpeed",2),Et([pe({type:Number,attribute:"audio-reactivity"})],$.PillCall.prototype,"audioReactivity",2),Et([pe({type:Number,attribute:"audio-smoothing"})],$.PillCall.prototype,"audioSmoothing",2),Et([pe({type:Number,attribute:"idle-morph-multiplier"})],$.PillCall.prototype,"idleMorphMultiplier",2),Et([pe({type:Number,attribute:"color-contrast"})],$.PillCall.prototype,"colorContrast",2),Et([pe({type:Boolean,attribute:"sound-enabled"})],$.PillCall.prototype,"soundEnabled",2),Et([pe({type:Number,attribute:"sound-volume"})],$.PillCall.prototype,"soundVolume",2),$.PillCall=Et([_a("hanc-ai-pill-call")],$.PillCall);const _M={core:"#ffffff",coreGlow:"#a855f7",lightning:"#c084fc",shell:"#1e1b2e",shellInner:"#0f0d17",particles:"#e9d5ff",pulseNeutral:"#a855f7",pulseJoy:"#22c55e",pulseThinking:"#3b82f6",pulseInterrupted:"#ef4444"},pu={idle:{shellOpen:0,coreIntensity:.6,lightningCount:2,lightningIntensity:.3,particleSpeed:.3,coreScale:.7},listening:{shellOpen:.15,coreIntensity:.8,lightningCount:4,lightningIntensity:.5,particleSpeed:.5,coreScale:.8},thinking:{shellOpen:.25,coreIntensity:1,lightningCount:6,lightningIntensity:.7,particleSpeed:.7,coreScale:.9},speaking:{shellOpen:.4,coreIntensity:1.2,lightningCount:10,lightningIntensity:1,particleSpeed:1,coreScale:1}};class pg{constructor(e,t={}){this.shellSegments=[],this.coreInner=null,this.coreOuter=null,this.coreGlow=null,this.pulseRings=[],this.particles=null,this.particlePositions=null,this.particleVelocities=null,this.animationId=null,this._currentState="idle",this._currentEmotion="neutral",this.targetConfig={...pu.idle},this.currentConfig={...pu.idle},this.
|
|
5209
|
+
`,Et([pe({type:String,attribute:"agent-id"})],$.PillCall.prototype,"agentId",2),Et([pe({type:String,attribute:"voice-service-url"})],$.PillCall.prototype,"voiceServiceUrl",2),Et([Fi()],$.PillCall.prototype,"callStatus",2),Et([Fi()],$.PillCall.prototype,"microphoneEnabled",2),Et([pe({type:String,attribute:"button-start-text"})],$.PillCall.prototype,"buttonStartText",2),Et([pe({type:String,attribute:"button-connecting-text"})],$.PillCall.prototype,"buttonConnectingText",2),Et([pe({type:String,attribute:"button-end-text"})],$.PillCall.prototype,"buttonEndText",2),Et([pe({type:Number,attribute:"orb-size"})],$.PillCall.prototype,"orbSize",2),Et([pe({type:String,attribute:"theme"})],$.PillCall.prototype,"theme",2),Et([pe({type:String,attribute:"theme-mode"})],$.PillCall.prototype,"themeMode",2),Et([pe({type:Object,attribute:"orb-colors"})],$.PillCall.prototype,"orbColors",2),Et([pe({type:Number,attribute:"glow-intensity"})],$.PillCall.prototype,"glowIntensity",2),Et([pe({type:Number,attribute:"idle-glow-multiplier"})],$.PillCall.prototype,"idleGlowMultiplier",2),Et([pe({type:Number,attribute:"morph-strength"})],$.PillCall.prototype,"morphStrength",2),Et([pe({type:Number,attribute:"noise-scale"})],$.PillCall.prototype,"noiseScale",2),Et([pe({type:Number,attribute:"noise-speed"})],$.PillCall.prototype,"noiseSpeed",2),Et([pe({type:Number,attribute:"fresnel-power"})],$.PillCall.prototype,"fresnelPower",2),Et([pe({type:Number,attribute:"rotation-speed"})],$.PillCall.prototype,"rotationSpeed",2),Et([pe({type:Number,attribute:"audio-reactivity"})],$.PillCall.prototype,"audioReactivity",2),Et([pe({type:Number,attribute:"audio-smoothing"})],$.PillCall.prototype,"audioSmoothing",2),Et([pe({type:Number,attribute:"idle-morph-multiplier"})],$.PillCall.prototype,"idleMorphMultiplier",2),Et([pe({type:Number,attribute:"color-contrast"})],$.PillCall.prototype,"colorContrast",2),Et([pe({type:Boolean,attribute:"sound-enabled"})],$.PillCall.prototype,"soundEnabled",2),Et([pe({type:Number,attribute:"sound-volume"})],$.PillCall.prototype,"soundVolume",2),$.PillCall=Et([_a("hanc-ai-pill-call")],$.PillCall);const _M={core:"#ffffff",coreGlow:"#a855f7",lightning:"#c084fc",shell:"#1e1b2e",shellInner:"#0f0d17",particles:"#e9d5ff",pulseNeutral:"#a855f7",pulseJoy:"#22c55e",pulseThinking:"#3b82f6",pulseInterrupted:"#ef4444"},pu={idle:{shellOpen:0,coreIntensity:.6,lightningCount:2,lightningIntensity:.3,particleSpeed:.3,coreScale:.7},listening:{shellOpen:.15,coreIntensity:.8,lightningCount:4,lightningIntensity:.5,particleSpeed:.5,coreScale:.8},thinking:{shellOpen:.25,coreIntensity:1,lightningCount:6,lightningIntensity:.7,particleSpeed:.7,coreScale:.9},speaking:{shellOpen:.4,coreIntensity:1.2,lightningCount:10,lightningIntensity:1,particleSpeed:1,coreScale:1}};class pg{constructor(e,t={}){this.shellSegments=[],this.coreInner=null,this.coreOuter=null,this.coreGlow=null,this.pulseRings=[],this.particles=null,this.particlePositions=null,this.particleVelocities=null,this.animationId=null,this._currentState="idle",this._currentEmotion="neutral",this.targetConfig={...pu.idle},this.currentConfig={...pu.idle},this.targetAudioLevel=0,this.currentAudioLevel=0,this.audioVelocity=0,this.targetPulseColor=new Fe("#a855f7"),this.currentPulseColor=new Fe("#a855f7"),this.targetRotation={x:0,y:0},this.currentRotation={x:0,y:0},this.time=0,this.animate=()=>{this.animationId=requestAnimationFrame(this.animate);const n=this.clock.getDelta();this.time+=n;const s=.05;this.currentConfig.coreIntensity+=(this.targetConfig.coreIntensity-this.currentConfig.coreIntensity)*s,this.currentConfig.lightningCount+=(this.targetConfig.lightningCount-this.currentConfig.lightningCount)*s,this.currentConfig.lightningIntensity+=(this.targetConfig.lightningIntensity-this.currentConfig.lightningIntensity)*s,this.currentConfig.particleSpeed+=(this.targetConfig.particleSpeed-this.currentConfig.particleSpeed)*s,this.currentConfig.coreScale+=(this.targetConfig.coreScale-this.currentConfig.coreScale)*s;const r=.08,o=.75,a=(this.targetAudioLevel-this.currentAudioLevel)*r;this.audioVelocity+=a,this.audioVelocity*=o,this.currentAudioLevel+=this.audioVelocity,this.currentAudioLevel=Math.max(0,Math.min(1,this.currentAudioLevel));const c=1+this.currentAudioLevel*.4;if(this.coreLight&&(this.coreLight.intensity=3+this.currentConfig.coreIntensity*2*c),this.coreInner){const l=this.coreInner.material;l.uniforms&&(l.uniforms.uTime.value=this.time,l.uniforms.uIntensity.value=this.currentConfig.coreIntensity*c);const d=this.currentConfig.coreScale*.9*c;this.coreInner.scale.setScalar(d)}if(this.coreOuter){const l=this.coreOuter.material;l.uniforms.uTime.value=this.time,l.uniforms.uIntensity.value=this.currentConfig.coreIntensity*c;const d=this.currentConfig.coreScale*c;this.coreOuter.scale.setScalar(d)}if(this.coreGlow){const l=this.coreGlow.material;l.uniforms.uTime.value=this.time,l.uniforms.uIntensity.value=this.currentConfig.coreIntensity*.7*c;const d=1+Math.sin(this.time*1.5)*.03*this.currentConfig.coreIntensity;this.coreGlow.scale.setScalar(d)}this.updateParticles(n),this.currentPulseColor.lerp(this.targetPulseColor,.08);for(const l of this.pulseRings){const d=l.material;d.uniforms.uTime.value=this.time,d.uniforms.uAudioLevel.value=this.currentAudioLevel,d.uniforms.uIntensity.value=this.currentConfig.coreIntensity,d.uniforms.uColor.value.copy(this.currentPulseColor);const u=l.ringConfig;l.rotation.y+=.003*u.speed,l.rotation.x=u.tiltX+Math.sin(this.time*.5+u.phase)*.1,l.rotation.z=u.tiltZ+Math.cos(this.time*.4+u.phase)*.08}this.currentRotation.x+=(this.targetRotation.x-this.currentRotation.x)*.05,this.currentRotation.y+=(this.targetRotation.y-this.currentRotation.y)*.05,this.scene.rotation.x=this.currentRotation.x,this.scene.rotation.y=this.currentRotation.y,this.renderer.render(this.scene,this.camera)},this.handleResize=()=>{const n=this.container.clientWidth*this.config.canvasPadding,s=this.container.clientHeight*this.config.canvasPadding;this.camera.aspect=n/s,this.camera.updateProjectionMatrix(),this.renderer.setSize(n,s)},this.handleMouseMove=n=>{const s=this.container.getBoundingClientRect(),r=(n.clientX-s.left)/s.width*2-1,o=-((n.clientY-s.top)/s.height)*2+1;this.targetRotation.x=o*.3,this.targetRotation.y=r*.3},this.handleMouseLeave=()=>{this.targetRotation.x=0,this.targetRotation.y=0},this.container=e,this.config={size:t.size??1,shellSegments:t.shellSegments??6,colors:t.colors??{},canvasPadding:t.canvasPadding??2},this.colors={..._M,...t.colors},this.clock=new Nm,this.initScene(),this.createShell(),this.createCore(),this.createParticles(),window.addEventListener("resize",this.handleResize),e.addEventListener("mousemove",this.handleMouseMove),e.addEventListener("mouseleave",this.handleMouseLeave)}initScene(){this.scene=new Mm;const e=this.container.clientWidth*this.config.canvasPadding,t=this.container.clientHeight*this.config.canvasPadding;this.camera=new xn(50,e/t,.1,100),this.camera.position.z=3.5,this.renderer=new ug({antialias:!0,alpha:!0,powerPreference:"high-performance"}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e,t),this.renderer.setClearColor(0,0);const n=this.renderer.domElement;n.style.position="absolute",n.style.left="50%",n.style.top="50%",n.style.transform="translate(-50%, -50%)",n.style.pointerEvents="none",this.container.appendChild(n)}createShell(){const e=new zS(1710638,.6);this.scene.add(e);const t=new iu(16777215,1);t.position.set(3,4,5),this.scene.add(t);const n=new iu(9133302,.4);n.position.set(-3,2,3),this.scene.add(n);const s=new iu(6514417,.5);s.position.set(0,-2,-4),this.scene.add(s);const r=new FS(new Fe(this.colors.coreGlow),4,6);r.position.set(0,0,0),this.scene.add(r),this.coreLight=r}createCore(){const e=this.config.size*.3,t=new yr(e*.5,64,64),n=new en({uniforms:{uTime:{value:0},uIntensity:{value:1}},vertexShader:`
|
|
5210
5210
|
varying vec3 vNormal;
|
|
5211
5211
|
varying vec3 vPosition;
|
|
5212
5212
|
void main() {
|
|
@@ -5524,7 +5524,7 @@ void main() {
|
|
|
5524
5524
|
|
|
5525
5525
|
gl_FragColor = vec4(color, alpha * 0.8);
|
|
5526
5526
|
}
|
|
5527
|
-
`,transparent:!0,blending:Ji,depthWrite:!1});this.particles=new IS(s,r),this.particleMaterial=r,this.scene.add(this.particles)}resetParticleFromCore(e){if(!this.particlePositions||!this.particleVelocities)return;const t=e*3,n=Math.random()*Math.PI*2,s=Math.acos(2*Math.random()-1),r=this.config.size*(.1+Math.random()*.15);this.particlePositions[t]=Math.sin(s)*Math.cos(n)*r,this.particlePositions[t+1]=Math.cos(s)*r,this.particlePositions[t+2]=Math.sin(s)*Math.sin(n)*r;const o=.0027+Math.random()*.008;this.particleVelocities[t]=this.particlePositions[t]/r*o,this.particleVelocities[t+1]=this.particlePositions[t+1]/r*o,this.particleVelocities[t+2]=this.particlePositions[t+2]/r*o,this.particleVelocities[t]+=(Math.random()-.5)*.0013,this.particleVelocities[t+1]+=(Math.random()-.5)*.0013,this.particleVelocities[t+2]+=(Math.random()-.5)*.0013}updateParticles(e){if(!this.particlePositions||!this.particleVelocities||!this.particles)return;const t=this.currentConfig.particleSpeed,n=this.config.size*.7;this.particleMaterial&&(this.particleMaterial.uniforms.uTime.value=this.time);for(let s=0;s<this.particlePositions.length/3;s++){const r=s*3;this.particlePositions[r]+=this.particleVelocities[r]*t,this.particlePositions[r+1]+=this.particleVelocities[r+1]*t,this.particlePositions[r+2]+=this.particleVelocities[r+2]*t,(Math.sqrt(this.particlePositions[r]**2+this.particlePositions[r+1]**2+this.particlePositions[r+2]**2)>=n||Math.random()<.003)&&this.resetParticleFromCore(s)}this.particles.geometry.attributes.position.needsUpdate=!0}setState(e){this._currentState=e,this.targetConfig={...pu[e]}}getState(){return this._currentState}setAudioLevel(e){this.audioLevel=Math.max(0,Math.min(1,e))}setEmotion(e){switch(this._currentEmotion=e,e){case"joy":this.targetPulseColor.set(this.colors.pulseJoy);break;case"thinking":this.targetPulseColor.set(this.colors.pulseThinking);break;case"interrupted":this.targetPulseColor.set(this.colors.pulseInterrupted);break;default:this.targetPulseColor.set(this.colors.pulseNeutral)}}getEmotion(){return this._currentEmotion}setColors(e){this.colors={...this.colors,...e},e.coreGlow&&this.coreOuter&&this.coreOuter.material.uniforms.uColorOuter.value.set(e.coreGlow),e.coreGlow&&this.coreGlow&&this.coreGlow.material.uniforms.uColor.value.set(e.coreGlow),e.particles&&this.particleMaterial&&this.particleMaterial.uniforms.uColor.value.set(e.particles),e.coreGlow&&this.coreLight&&this.coreLight.color.set(e.coreGlow),(e.pulseNeutral||e.pulseJoy||e.pulseThinking||e.pulseInterrupted)&&this.setEmotion(this._currentEmotion)}start(){this.animationId===null&&(this.clock.start(),this.animate())}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}getCanvas(){return this.renderer.domElement}destroy(){this.stop(),window.removeEventListener("resize",this.handleResize),this.container.removeEventListener("mousemove",this.handleMouseMove),this.container.removeEventListener("mouseleave",this.handleMouseLeave),this.shellSegments.forEach(e=>{e.geometry.dispose(),e.material.dispose()}),this.coreInner&&(this.coreInner.geometry.dispose(),this.coreInner.material.dispose()),this.coreOuter&&(this.coreOuter.geometry.dispose(),this.coreOuter.material.dispose()),this.coreGlow&&(this.coreGlow.geometry.dispose(),this.coreGlow.material.dispose());for(const e of this.pulseRings)e.geometry.dispose(),e.material.dispose();this.pulseRings=[],this.particles&&(this.particles.geometry.dispose(),this.particles.material.dispose()),this.renderer.dispose(),this.renderer.domElement.parentNode&&this.renderer.domElement.parentNode.removeChild(this.renderer.domElement)}}var SM=Object.defineProperty,xM=Object.getOwnPropertyDescriptor,Rn=(i,e,t,n)=>{for(var s=n>1?void 0:n?xM(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&SM(e,t,s),s};$.LinaWidget=class extends Ui{constructor(){super(...arguments),this.orbRenderer=null,this.orbContainerRef=xa(),this.audioSimPhase=0,this.animationId=null,this.callManager=null,this.size=300,this.headerLogo="HANC.ai",this.headerTitle="Lina-Voice AI",this.showBranding=!0,this.version="v1.0.2",this.agentId="",this.voiceServiceUrl="",this.btnStartText="Start",this.btnEndText="End",this.colors={},this.currentState="idle",this.callStatus="idle",this._hasMicPermission=null,this.handleCallClick=async()=>{if(this.callStatus==="mic-denied")try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(t=>t.stop()),this._hasMicPermission=!0,this.callStatus="idle"}catch{return}this.callStatus==="active"||this.callStatus==="connecting"?await this.endCall():this.callStatus==="idle"&&await this.startCall()}}connectedCallback(){super.connectedCallback(),this.checkMicrophonePermission()}disconnectedCallback(){super.disconnectedCallback(),this.cleanup()}firstUpdated(){this.initializeOrb()}async checkMicrophonePermission(){try{const e=await navigator.permissions.query({name:"microphone"});this._hasMicPermission=e.state==="granted",e.addEventListener("change",()=>{this._hasMicPermission=e.state==="granted",e.state==="denied"?this.callStatus="mic-denied":this.callStatus==="mic-denied"&&(this.callStatus="idle")})}catch{this._hasMicPermission=null}}initializeOrb(){const e=this.orbContainerRef.value;e&&(this.orbRenderer=new pg(e,{size:1,colors:this.colors}),this.orbRenderer.start(),this.startIdleAnimation())}initializeCallManager(){this.callManager||(this.callManager=new ro,this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl),this.callManager.addEventListener("status-changed",(e=>{const t=e.detail;this.handleCallStatusChange(t)})),this.callManager.addEventListener("audio-track",(e=>{const t=e.detail;if(t){const n=new MediaStream([t]);this.connectAudioStream(n)}})),this.callManager.addEventListener("microphone-disabled",()=>{this.callStatus==="active"&&(this._hasMicPermission=!1)}),this.callManager.addEventListener("error",(e=>{var t,n;console.error("Call error:",(t=e.detail)==null?void 0:t.error),this.callStatus="error",this.currentState="idle",(n=this.orbRenderer)==null||n.setState("idle"),setTimeout(()=>{this.callStatus==="error"&&(this.callStatus="idle")},3e3)})))}handleCallStatusChange(e){var t,n,s,r;switch(e){case"connecting":case"ringing":this.callStatus="connecting",this.currentState="listening",(t=this.orbRenderer)==null||t.setState("listening");break;case"connected":case"agent-connected":this.callStatus="active",this.currentState="speaking",(n=this.orbRenderer)==null||n.setState("speaking"),this.startActiveAnimation();break;case"disconnecting":this.callStatus="ending";break;case"disconnected":this.callStatus="idle",this.currentState="idle",(s=this.orbRenderer)==null||s.setState("idle"),this.startIdleAnimation();break;case"error":this.callStatus="error",this.currentState="idle",(r=this.orbRenderer)==null||r.setState("idle");break}}cleanup(){var e,t;this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),(e=this.callManager)==null||e.hangUp(),(t=this.orbRenderer)==null||t.destroy(),this.orbRenderer=null}startIdleAnimation(){this.animationId!==null&&cancelAnimationFrame(this.animationId);const e=()=>{if(!this.orbRenderer)return;const t=performance.now()/1e3,n=Math.sin(t*.4)*.08+Math.sin(t*.7)*.04+.15;this.orbRenderer.setAudioLevel(n),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}startActiveAnimation(){this.animationId!==null&&cancelAnimationFrame(this.animationId),this.audioSimPhase=Math.random()*Math.PI*2;const e=()=>{if(!this.orbRenderer||this.callStatus!=="active"){this.startIdleAnimation();return}this.audioSimPhase+=.03;const t=Math.sin(this.audioSimPhase*.25)*.25+.45,n=Math.sin(this.audioSimPhase*2)*.15,s=Math.sin(this.audioSimPhase*4.5)*.08,r=(Math.random()-.5)*.08,o=Math.random()>.97?Math.random()*.2:0,a=Math.max(0,Math.min(1,t+n+s+r+o));this.orbRenderer.setAudioLevel(a),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}connectAudioStream(e){if(!this.orbRenderer)return;this.animationId!==null&&cancelAnimationFrame(this.animationId);const t=new AudioContext,n=t.createAnalyser();n.fftSize=256,t.createMediaStreamSource(e).connect(n);const r=new Uint8Array(n.frequencyBinCount),o=()=>{if(!this.orbRenderer||this.callStatus!=="active"){t.close(),this.startIdleAnimation();return}n.getByteFrequencyData(r);let a=0;for(let d=0;d<r.length;d++)a+=r[d];const c=a/r.length/255,l=Math.pow(c,.7)*1.2;this.orbRenderer.setAudioLevel(Math.min(1,l)),this.animationId=requestAnimationFrame(o)};this.animationId=requestAnimationFrame(o)}async startCall(){var e,t,n,s;if(this._hasMicPermission!==!0)try{(await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})).getTracks().forEach(o=>o.stop()),this._hasMicPermission=!0}catch{this._hasMicPermission=!1,this.callStatus="mic-denied";return}if(this.agentId&&this.voiceServiceUrl){this.initializeCallManager(),this.callStatus="connecting",this.currentState="listening",(e=this.orbRenderer)==null||e.setState("listening");try{await((t=this.callManager)==null?void 0:t.makeCall({agentId:this.agentId}))}catch(r){console.error("Failed to start call:",r),this.callStatus="error",setTimeout(()=>{var o;this.callStatus==="error"&&(this.callStatus="idle",this.currentState="idle",(o=this.orbRenderer)==null||o.setState("idle"))},3e3)}}else this.callStatus="connecting",this.currentState="listening",(n=this.orbRenderer)==null||n.setState("listening"),await new Promise(r=>setTimeout(r,1500)),this.callStatus="active",this.currentState="speaking",(s=this.orbRenderer)==null||s.setState("speaking"),this.startActiveAnimation(),this.dispatchEvent(new CustomEvent("call-start",{detail:{agentId:"demo",timestamp:Date.now()},bubbles:!0,composed:!0}))}async endCall(){var e;this.callStatus="ending",this.callManager&&await this.callManager.hangUp(),this.callStatus="idle",this.currentState="idle",(e=this.orbRenderer)==null||e.setState("idle"),this.startIdleAnimation(),this.dispatchEvent(new CustomEvent("call-end",{detail:{timestamp:Date.now()},bubbles:!0,composed:!0}))}setState(e){var t;this.currentState=e,(t=this.orbRenderer)==null||t.setState(e)}setAudioLevel(e){var t;(t=this.orbRenderer)==null||t.setAudioLevel(e)}setColors(e){var t;this.colors={...this.colors,...e},(t=this.orbRenderer)==null||t.setColors(e)}setEmotion(e){var t;(t=this.orbRenderer)==null||t.setEmotion(e)}getEmotion(){var e;return(e=this.orbRenderer)==null?void 0:e.getEmotion()}getState(){return this.currentState}getCallStatus(){return this.callStatus}getButtonContent(){switch(this.callStatus){case"connecting":return Rt`
|
|
5527
|
+
`,transparent:!0,blending:Ji,depthWrite:!1});this.particles=new IS(s,r),this.particleMaterial=r,this.scene.add(this.particles)}resetParticleFromCore(e){if(!this.particlePositions||!this.particleVelocities)return;const t=e*3,n=Math.random()*Math.PI*2,s=Math.acos(2*Math.random()-1),r=this.config.size*(.1+Math.random()*.15);this.particlePositions[t]=Math.sin(s)*Math.cos(n)*r,this.particlePositions[t+1]=Math.cos(s)*r,this.particlePositions[t+2]=Math.sin(s)*Math.sin(n)*r;const o=.0027+Math.random()*.008;this.particleVelocities[t]=this.particlePositions[t]/r*o,this.particleVelocities[t+1]=this.particlePositions[t+1]/r*o,this.particleVelocities[t+2]=this.particlePositions[t+2]/r*o,this.particleVelocities[t]+=(Math.random()-.5)*.0013,this.particleVelocities[t+1]+=(Math.random()-.5)*.0013,this.particleVelocities[t+2]+=(Math.random()-.5)*.0013}updateParticles(e){if(!this.particlePositions||!this.particleVelocities||!this.particles)return;const t=this.currentConfig.particleSpeed,n=this.config.size*.7;this.particleMaterial&&(this.particleMaterial.uniforms.uTime.value=this.time);for(let s=0;s<this.particlePositions.length/3;s++){const r=s*3;this.particlePositions[r]+=this.particleVelocities[r]*t,this.particlePositions[r+1]+=this.particleVelocities[r+1]*t,this.particlePositions[r+2]+=this.particleVelocities[r+2]*t,(Math.sqrt(this.particlePositions[r]**2+this.particlePositions[r+1]**2+this.particlePositions[r+2]**2)>=n||Math.random()<.003)&&this.resetParticleFromCore(s)}this.particles.geometry.attributes.position.needsUpdate=!0}setState(e){this._currentState=e,this.targetConfig={...pu[e]}}getState(){return this._currentState}setAudioLevel(e){this.targetAudioLevel=Math.max(0,Math.min(1,e))}setEmotion(e){switch(this._currentEmotion=e,e){case"joy":this.targetPulseColor.set(this.colors.pulseJoy);break;case"thinking":this.targetPulseColor.set(this.colors.pulseThinking);break;case"interrupted":this.targetPulseColor.set(this.colors.pulseInterrupted);break;default:this.targetPulseColor.set(this.colors.pulseNeutral)}}getEmotion(){return this._currentEmotion}setColors(e){this.colors={...this.colors,...e},e.coreGlow&&this.coreOuter&&this.coreOuter.material.uniforms.uColorOuter.value.set(e.coreGlow),e.coreGlow&&this.coreGlow&&this.coreGlow.material.uniforms.uColor.value.set(e.coreGlow),e.particles&&this.particleMaterial&&this.particleMaterial.uniforms.uColor.value.set(e.particles),e.coreGlow&&this.coreLight&&this.coreLight.color.set(e.coreGlow),(e.pulseNeutral||e.pulseJoy||e.pulseThinking||e.pulseInterrupted)&&this.setEmotion(this._currentEmotion)}start(){this.animationId===null&&(this.clock.start(),this.animate())}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}getCanvas(){return this.renderer.domElement}destroy(){this.stop(),window.removeEventListener("resize",this.handleResize),this.container.removeEventListener("mousemove",this.handleMouseMove),this.container.removeEventListener("mouseleave",this.handleMouseLeave),this.shellSegments.forEach(e=>{e.geometry.dispose(),e.material.dispose()}),this.coreInner&&(this.coreInner.geometry.dispose(),this.coreInner.material.dispose()),this.coreOuter&&(this.coreOuter.geometry.dispose(),this.coreOuter.material.dispose()),this.coreGlow&&(this.coreGlow.geometry.dispose(),this.coreGlow.material.dispose());for(const e of this.pulseRings)e.geometry.dispose(),e.material.dispose();this.pulseRings=[],this.particles&&(this.particles.geometry.dispose(),this.particles.material.dispose()),this.renderer.dispose(),this.renderer.domElement.parentNode&&this.renderer.domElement.parentNode.removeChild(this.renderer.domElement)}}var SM=Object.defineProperty,xM=Object.getOwnPropertyDescriptor,Rn=(i,e,t,n)=>{for(var s=n>1?void 0:n?xM(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&SM(e,t,s),s};$.LinaWidget=class extends Ui{constructor(){super(...arguments),this.orbRenderer=null,this.orbContainerRef=xa(),this.audioSimPhase=0,this.animationId=null,this.callManager=null,this.size=300,this.headerLogo="HANC.ai",this.headerTitle="Lina-Voice AI",this.showBranding=!0,this.version="v1.0.3",this.agentId="",this.voiceServiceUrl="",this.btnStartText="Start",this.btnEndText="End",this.colors={},this.currentState="idle",this.callStatus="idle",this._hasMicPermission=null,this.handleCallClick=async()=>{if(this.callStatus==="mic-denied")try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(t=>t.stop()),this._hasMicPermission=!0,this.callStatus="idle"}catch{return}this.callStatus==="active"||this.callStatus==="connecting"?await this.endCall():this.callStatus==="idle"&&await this.startCall()}}connectedCallback(){super.connectedCallback(),this.checkMicrophonePermission()}disconnectedCallback(){super.disconnectedCallback(),this.cleanup()}firstUpdated(){this.initializeOrb()}async checkMicrophonePermission(){try{const e=await navigator.permissions.query({name:"microphone"});this._hasMicPermission=e.state==="granted",e.addEventListener("change",()=>{this._hasMicPermission=e.state==="granted",e.state==="denied"?this.callStatus="mic-denied":this.callStatus==="mic-denied"&&(this.callStatus="idle")})}catch{this._hasMicPermission=null}}initializeOrb(){const e=this.orbContainerRef.value;e&&(this.orbRenderer=new pg(e,{size:1,colors:this.colors}),this.orbRenderer.start(),this.startIdleAnimation())}initializeCallManager(){this.callManager||(this.callManager=new ro,this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl),this.callManager.addEventListener("status-changed",(e=>{const t=e.detail;this.handleCallStatusChange(t)})),this.callManager.addEventListener("audio-track",(e=>{const t=e.detail;if(t){const n=new MediaStream([t]);this.connectAudioStream(n)}})),this.callManager.addEventListener("microphone-disabled",()=>{this.callStatus==="active"&&(this._hasMicPermission=!1)}),this.callManager.addEventListener("error",(e=>{var t,n;console.error("Call error:",(t=e.detail)==null?void 0:t.error),this.callStatus="error",this.currentState="idle",(n=this.orbRenderer)==null||n.setState("idle"),setTimeout(()=>{this.callStatus==="error"&&(this.callStatus="idle")},3e3)})))}handleCallStatusChange(e){var t,n,s,r;switch(e){case"connecting":case"ringing":this.callStatus="connecting",this.currentState="listening",(t=this.orbRenderer)==null||t.setState("listening");break;case"connected":case"agent-connected":this.callStatus="active",this.currentState="speaking",(n=this.orbRenderer)==null||n.setState("speaking"),this.startActiveAnimation();break;case"disconnecting":this.callStatus="ending";break;case"disconnected":this.callStatus="idle",this.currentState="idle",(s=this.orbRenderer)==null||s.setState("idle"),this.startIdleAnimation();break;case"error":this.callStatus="error",this.currentState="idle",(r=this.orbRenderer)==null||r.setState("idle");break}}cleanup(){var e,t;this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),(e=this.callManager)==null||e.hangUp(),(t=this.orbRenderer)==null||t.destroy(),this.orbRenderer=null}startIdleAnimation(){this.animationId!==null&&cancelAnimationFrame(this.animationId);const e=()=>{if(!this.orbRenderer)return;const t=performance.now()/1e3,n=Math.sin(t*.4)*.08+Math.sin(t*.7)*.04+.15;this.orbRenderer.setAudioLevel(n),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}startActiveAnimation(){this.animationId!==null&&cancelAnimationFrame(this.animationId),this.audioSimPhase=Math.random()*Math.PI*2;const e=()=>{if(!this.orbRenderer||this.callStatus!=="active"){this.startIdleAnimation();return}this.audioSimPhase+=.03;const t=Math.sin(this.audioSimPhase*.25)*.25+.45,n=Math.sin(this.audioSimPhase*2)*.15,s=Math.sin(this.audioSimPhase*4.5)*.08,r=(Math.random()-.5)*.08,o=Math.random()>.97?Math.random()*.2:0,a=Math.max(0,Math.min(1,t+n+s+r+o));this.orbRenderer.setAudioLevel(a),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}connectAudioStream(e){if(!this.orbRenderer)return;this.animationId!==null&&cancelAnimationFrame(this.animationId);const t=new AudioContext,n=t.createAnalyser();n.fftSize=256,t.createMediaStreamSource(e).connect(n);const r=new Uint8Array(n.frequencyBinCount),o=()=>{if(!this.orbRenderer||this.callStatus!=="active"){t.close(),this.startIdleAnimation();return}n.getByteFrequencyData(r);let a=0;for(let d=0;d<r.length;d++)a+=r[d];const c=a/r.length/255,l=Math.pow(c,.7)*1.2;this.orbRenderer.setAudioLevel(Math.min(1,l)),this.animationId=requestAnimationFrame(o)};this.animationId=requestAnimationFrame(o)}async startCall(){var e,t,n,s;if(this._hasMicPermission!==!0)try{(await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})).getTracks().forEach(o=>o.stop()),this._hasMicPermission=!0}catch{this._hasMicPermission=!1,this.callStatus="mic-denied";return}if(this.agentId&&this.voiceServiceUrl){this.initializeCallManager(),this.callStatus="connecting",this.currentState="listening",(e=this.orbRenderer)==null||e.setState("listening");try{await((t=this.callManager)==null?void 0:t.makeCall({agentId:this.agentId}))}catch(r){console.error("Failed to start call:",r),this.callStatus="error",setTimeout(()=>{var o;this.callStatus==="error"&&(this.callStatus="idle",this.currentState="idle",(o=this.orbRenderer)==null||o.setState("idle"))},3e3)}}else this.callStatus="connecting",this.currentState="listening",(n=this.orbRenderer)==null||n.setState("listening"),await new Promise(r=>setTimeout(r,1500)),this.callStatus="active",this.currentState="speaking",(s=this.orbRenderer)==null||s.setState("speaking"),this.startActiveAnimation(),this.dispatchEvent(new CustomEvent("call-start",{detail:{agentId:"demo",timestamp:Date.now()},bubbles:!0,composed:!0}))}async endCall(){var e;this.callStatus="ending",this.callManager&&await this.callManager.hangUp(),this.callStatus="idle",this.currentState="idle",(e=this.orbRenderer)==null||e.setState("idle"),this.startIdleAnimation(),this.dispatchEvent(new CustomEvent("call-end",{detail:{timestamp:Date.now()},bubbles:!0,composed:!0}))}setState(e){var t;this.currentState=e,(t=this.orbRenderer)==null||t.setState(e)}setAudioLevel(e){var t;(t=this.orbRenderer)==null||t.setAudioLevel(e)}setColors(e){var t;this.colors={...this.colors,...e},(t=this.orbRenderer)==null||t.setColors(e)}setEmotion(e){var t;(t=this.orbRenderer)==null||t.setEmotion(e)}getEmotion(){var e;return(e=this.orbRenderer)==null?void 0:e.getEmotion()}getState(){return this.currentState}getCallStatus(){return this.callStatus}getButtonContent(){switch(this.callStatus){case"connecting":return Rt`
|
|
5528
5528
|
<svg viewBox="0 0 24 24" fill="none">
|
|
5529
5529
|
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="50 20" stroke-linecap="round"/>
|
|
5530
5530
|
</svg>
|
|
@@ -39,7 +39,9 @@ export declare class LinaOrbRenderer {
|
|
|
39
39
|
private _currentEmotion;
|
|
40
40
|
private targetConfig;
|
|
41
41
|
private currentConfig;
|
|
42
|
-
private
|
|
42
|
+
private targetAudioLevel;
|
|
43
|
+
private currentAudioLevel;
|
|
44
|
+
private audioVelocity;
|
|
43
45
|
private targetPulseColor;
|
|
44
46
|
private currentPulseColor;
|
|
45
47
|
private targetRotation;
|