orb-ui 0.2.3 → 0.2.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.
@@ -0,0 +1,68 @@
1
+ import { AriaAttributes, CSSProperties } from 'react';
2
+ export type OrbState = 'idle' | 'connecting' | 'listening' | 'speaking' | 'error';
3
+ export type OrbTheme = 'debug' | 'circle' | 'bars';
4
+ export interface OrbAdapter {
5
+ /**
6
+ * Subscribe to state and volume changes from a voice provider.
7
+ * Returns an unsubscribe function to clean up listeners.
8
+ */
9
+ subscribe(callbacks: {
10
+ onStateChange: (state: OrbState) => void;
11
+ onVolumeChange: (volume: number) => void;
12
+ }): () => void;
13
+ /** Start the voice session. Called internally by Orb on click. */
14
+ start?: () => void | Promise<void>;
15
+ /** Stop the voice session. Called internally by Orb on click. */
16
+ stop?: () => void | Promise<void>;
17
+ }
18
+ type DataAttributeValue = string | number | boolean | null | undefined;
19
+ export interface OrbHtmlAttributes extends AriaAttributes {
20
+ /** Forwarded to the rendered orb control/container. */
21
+ id?: string;
22
+ /** Forwarded to the rendered orb control/container. */
23
+ title?: string;
24
+ /** Override the rendered role when you need custom semantics. */
25
+ role?: string;
26
+ /** Forwarded tab index for non-default keyboard ordering. */
27
+ tabIndex?: number;
28
+ /** Forward data-* attributes, e.g. data-testid. */
29
+ [dataAttribute: `data-${string}`]: DataAttributeValue;
30
+ }
31
+ export interface OrbProps extends OrbHtmlAttributes {
32
+ /**
33
+ * Current conversation state. Required in controlled mode (no adapter).
34
+ * Overrides adapter state if both are provided.
35
+ */
36
+ state?: OrbState;
37
+ /**
38
+ * Current audio volume, normalized 0–1.
39
+ * Overrides adapter volume if both are provided.
40
+ */
41
+ volume?: number;
42
+ /**
43
+ * Provider adapter (Vapi, ElevenLabs, etc.).
44
+ * Handles state and volume automatically from the SDK.
45
+ */
46
+ adapter?: OrbAdapter;
47
+ /** Visual theme. Defaults to 'debug'. */
48
+ theme?: OrbTheme;
49
+ /** Size in pixels. Defaults to 200. */
50
+ size?: number;
51
+ /** Optional class name for the rendered orb container/control. */
52
+ className?: string;
53
+ /** Optional inline styles for the rendered orb container/control. */
54
+ style?: CSSProperties;
55
+ /** Disable clickable themes and debug start/stop controls. */
56
+ disabled?: boolean;
57
+ /**
58
+ * Called when a clickable theme is activated while idle/error.
59
+ * Overrides adapter.start() when provided.
60
+ */
61
+ onStart?: () => void;
62
+ /**
63
+ * Called when a clickable theme is activated while active.
64
+ * Overrides adapter.stop() when provided.
65
+ */
66
+ onStop?: () => void;
67
+ }
68
+ export {};
@@ -0,0 +1,2 @@
1
+ export { Orb } from './Orb.js';
2
+ export type { OrbProps, OrbState, OrbTheme, OrbAdapter } from './Orb.types.js';
@@ -0,0 +1,4 @@
1
+ export { Orb } from './components/Orb/index.js';
2
+ export type { OrbProps, OrbState, OrbTheme, OrbAdapter } from './components/Orb/index.js';
3
+ export { Orb as VoiceOrb } from './components/Orb/index.js';
4
+ export type { OrbProps as VoiceOrbProps } from './components/Orb/index.js';
package/dist/orb-ui.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),t=require("react");function te(n){let i=Math.min(n/.5,1);return i=Math.pow(i,1.3),i}const re=["idle","connecting","listening","speaking","error"],U={idle:"#888",connecting:"#f0c040",listening:"#40c0f0",speaking:"#40f080",error:"#f04040"};function ce({state:n,volume:i,size:e,className:j,style:v,onStart:d,onStop:k}){return o.jsxs("div",{className:j,style:{width:e,fontFamily:"monospace",fontSize:12,background:"#111",color:"#ccc",border:"1px solid #333",borderRadius:8,padding:12,boxSizing:"border-box",userSelect:"none",...v},children:[o.jsx("div",{style:{color:"#555",marginBottom:10,fontSize:10,letterSpacing:1},children:"ORB DEBUG"}),o.jsxs("div",{style:{marginBottom:8},children:[o.jsx("span",{style:{color:"#555"},children:"state "}),o.jsx("span",{style:{color:U[n],fontWeight:"bold"},children:n})]}),o.jsxs("div",{style:{marginBottom:10},children:[o.jsx("span",{style:{color:"#555"},children:"volume "}),o.jsx("span",{style:{color:"#ccc"},children:i.toFixed(2)}),o.jsx("div",{style:{marginTop:4,height:4,background:"#222",borderRadius:2,overflow:"hidden"},children:o.jsx("div",{style:{height:"100%",width:`${i*100}%`,background:U[n],borderRadius:2,transition:"width 50ms linear"}})})]}),o.jsxs("div",{style:{marginBottom:10},children:[o.jsx("div",{style:{color:"#555",marginBottom:4,fontSize:10},children:"force state"}),o.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:re.map(r=>o.jsx("button",{style:{fontSize:10,padding:"2px 6px",background:n===r?U[r]:"#222",color:n===r?"#000":"#888",border:`1px solid ${n===r?U[r]:"#333"}`,borderRadius:3,cursor:"pointer"},onClick:()=>{console.warn(`[orb-ui debug] To force state '${r}', use controlled mode: <Orb state="${r}" />`)},children:r},r))})]}),o.jsxs("div",{style:{display:"flex",gap:6},children:[o.jsx("button",{onClick:d,style:{flex:1,padding:"4px 0",background:"#1a3a1a",color:"#40f080",border:"1px solid #40f080",borderRadius:4,cursor:"pointer",fontSize:11},children:"Start"}),o.jsx("button",{onClick:k,style:{flex:1,padding:"4px 0",background:"#3a1a1a",color:"#f04040",border:"1px solid #f04040",borderRadius:4,cursor:"pointer",fontSize:11},children:"Stop"})]})]})}function K(n){return[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)]}const _={idle:"#cccccc",connecting:"#cccccc",listening:"#999999",speaking:"#e8e8e8",error:"#f87171"},oe=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");function n(e){let t=Math.min(e/.5,1);return t**=1.3,t}var r=[`idle`,`connecting`,`listening`,`speaking`,`error`],i={idle:`#888`,connecting:`#f0c040`,listening:`#40c0f0`,speaking:`#40f080`,error:`#f04040`};function a({state:e,volume:n,size:a,className:o,style:s,disabled:c=!1,onStart:l,onStop:u,...d}){return(0,t.jsxs)(`div`,{...d,className:o,style:{width:a,fontFamily:`monospace`,fontSize:12,background:`#111`,color:`#ccc`,border:`1px solid #333`,borderRadius:8,padding:12,boxSizing:`border-box`,userSelect:`none`,...s},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:10,fontSize:10,letterSpacing:1},children:`ORB DEBUG`}),(0,t.jsxs)(`div`,{style:{marginBottom:8},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`state `}),(0,t.jsx)(`span`,{style:{color:i[e],fontWeight:`bold`},children:e})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`volume `}),(0,t.jsx)(`span`,{style:{color:`#ccc`},children:n.toFixed(2)}),(0,t.jsx)(`div`,{style:{marginTop:4,height:4,background:`#222`,borderRadius:2,overflow:`hidden`},children:(0,t.jsx)(`div`,{style:{height:`100%`,width:`${n*100}%`,background:i[e],borderRadius:2,transition:`width 50ms linear`}})})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:4,fontSize:10},children:`force state`}),(0,t.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:4},children:r.map(n=>(0,t.jsx)(`button`,{disabled:c,style:{fontSize:10,padding:`2px 6px`,background:e===n?i[n]:`#222`,color:e===n?`#000`:`#888`,border:`1px solid ${e===n?i[n]:`#333`}`,borderRadius:3,cursor:c?`not-allowed`:`pointer`},onClick:()=>{console.warn(`[orb-ui debug] To force state '${n}', use controlled mode: <Orb state="${n}" />`)},children:n},n))})]}),(0,t.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,t.jsx)(`button`,{disabled:c,onClick:l,style:{flex:1,padding:`4px 0`,background:`#1a3a1a`,color:`#40f080`,border:`1px solid #40f080`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Start`}),(0,t.jsx)(`button`,{disabled:c,onClick:u,style:{flex:1,padding:`4px 0`,background:`#3a1a1a`,color:`#f04040`,border:`1px solid #f04040`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Stop`})]})]})}var o=typeof window<`u`?e.useLayoutEffect:e.useEffect;function s(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}var c={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,speaking:`#e8e8e8`,error:`#f87171`},l=`
2
2
  @keyframes orb-circle-idle-pulse {
3
3
  from { transform: scale(1); }
4
4
  to { transform: scale(1.06); }
@@ -8,4 +8,4 @@
8
8
  50% { opacity: 0.6; transform: scale(0.95); }
9
9
  100% { opacity: 1; transform: scale(1); }
10
10
  }
11
- `,se=.95,ie=.08,J=.82,X=.18,le=24,ue=0;function ae({state:n,volume:i,size:e,className:j,style:v,onClick:d}){const k=t.useRef(null),r=t.useRef(null),c=t.useRef(null),m=t.useRef(0),h=t.useRef(i);t.useLayoutEffect(()=>{h.current=i},[i]);const s=t.useRef(1),u=t.useRef(0),A=t.useRef(K(_.idle)),M=.06,S=t.useRef(J),g=t.useRef(X);t.useEffect(()=>{const f="orb-circle-keyframes";if(!document.getElementById(f)){const p=document.createElement("style");p.id=f,p.textContent=oe,document.head.appendChild(p)}},[]),t.useEffect(()=>{const f=k.current;if(f)if(n==="listening"||n==="speaking"){const p=n==="speaking"?se:J,I=n==="speaking"?ie:X,q=n==="speaking"?le:ue,C=()=>{const F=h.current;S.current+=(p-S.current)*M,g.current+=(I-g.current)*M;const l=S.current+F*g.current,E=F*q;n==="listening"?(s.current+=(l-s.current)*.45,u.current+=(E-u.current)*.45):(s.current=l,u.current=E);const L=K(_[n]),[D,O,P]=A.current;A.current=[D+(L[0]-D)*.05,O+(L[1]-O)*.05,P+(L[2]-P)*.05];const[N,b,a]=A.current.map(Math.round);f.style.transform=`scale(${s.current})`,f.style.background=`rgb(${N},${b},${a})`,f.style.boxShadow="none",f.style.animation="none";const R=r.current;if(R){const x=u.current;R.style.transform=`scale(${s.current})`,R.style.boxShadow=x>.5?`0 0 ${x}px ${x*.4}px rgb(${N},${b},${a})`:"none"}m.current=requestAnimationFrame(C)};return m.current=requestAnimationFrame(C),()=>{cancelAnimationFrame(m.current)}}else{cancelAnimationFrame(m.current),s.current=1,u.current=0,A.current=K(_[n]??_.idle),f.style.transform="",f.style.boxShadow="none",r.current&&(r.current.style.boxShadow="none");const p=_[n]??_.idle,[I,q,C]=K(p);f.style.background=p,n==="idle"?f.style.animation="orb-circle-idle-pulse 3s ease-in-out infinite alternate":n==="connecting"?f.style.animation="orb-circle-connecting-pulse 1.5s ease-in-out infinite":f.style.animation="none"}},[n]);const y=e*.55;return o.jsx("div",{className:j,style:{width:e,height:e,display:"flex",alignItems:"center",justifyContent:"center",position:"relative",...v},children:o.jsxs("div",{ref:c,onClick:d,onMouseEnter:()=>{c.current&&(c.current.style.transform="scale(1.06)",c.current.style.filter="brightness(1.12)")},onMouseLeave:()=>{c.current&&(c.current.style.transform="scale(1)",c.current.style.filter="brightness(1)")},onTouchEnd:()=>{setTimeout(()=>{c.current&&(c.current.style.transform="scale(1)",c.current.style.filter="brightness(1)")},200)},style:{transition:"transform 0.3s ease, filter 0.3s ease",cursor:d?"pointer":"default",borderRadius:"50%",lineHeight:0},children:[o.jsx("div",{ref:r,style:{position:"absolute",width:y,height:y,borderRadius:"50%",pointerEvents:"none"}}),o.jsx("div",{ref:k,style:{position:"relative",width:y,height:y,borderRadius:"50%",background:_[n]}})]})})}const T=5,fe=1.4,de=Math.PI*2/T,G={idle:"#cccccc",connecting:"#cccccc",listening:"#999999",speaking:"#e8e8e8",error:"#f87171"};function Z(n){return[parseInt(n.slice(1,3),16),parseInt(n.slice(3,5),16),parseInt(n.slice(5,7),16)]}function me({state:n,volume:i,size:e,className:j,style:v,onClick:d}){const k=t.useRef([]),r=t.useRef(null),c=t.useRef(0),m=t.useRef(new Array(T).fill(0)),h=t.useRef(i),s=t.useRef(!1),u=t.useRef(0),A=t.useRef(Z(G.idle)),M=300,S=t.useRef(null),g=t.useRef(new Array(T).fill(0)),y=t.useRef(n);t.useEffect(()=>{n!==y.current&&(g.current=[...m.current],S.current=Date.now(),y.current=n)},[n]),t.useEffect(()=>{h.current=i},[i]),t.useEffect(()=>{const F=e*.55,l=e*.06,E=G[n]??G.idle,L=e*.1,D=Array.from({length:T},(b,a)=>{const R=(T-1)/2;return 1-.7*(Math.abs(a-R)/R)}),O=()=>{const a=s.current?L:0;u.current+=(a-u.current)*.15},P=(b,a)=>{O();const R=Z(a),[x,w,H]=A.current;A.current=[x+(R[0]-x)*.08,w+(R[1]-w)*.08,H+(R[2]-H)*.08];const[$,Q,Y]=A.current.map(Math.round),V=`rgb(${$},${Q},${Y})`;for(let B=0;B<T;B++){const W=k.current[B];if(!W)continue;const ee=n==="idle"?D[B]:1,ne=u.current*ee;W.style.height=`${Math.min(b[B]+ne,F)}px`,W.style.background=V,W.style.animation="none"}};if(n==="listening"||n==="speaking"){const b=n==="speaking"?1:.4,a=()=>{const R=h.current,x=Date.now()/1e3;for(let w=0;w<T;w++){const H=.5+.15*Math.sin(x*fe*b*Math.PI*2+w*de);let $=l+(F-l)*R*H;if(S.current!==null){const Y=Date.now()-S.current,V=Math.min(Y/M,1),B=1-(1-V)*(1-V);$=g.current[w]+($-g.current[w])*B,V>=1&&(S.current=null)}const Q=n==="listening"?.45:1;m.current[w]+=($-m.current[w])*Q}P(m.current,E),c.current=requestAnimationFrame(a)};return c.current=requestAnimationFrame(a),()=>cancelAnimationFrame(c.current)}if(n==="connecting"){const b=Date.now(),a=()=>{const R=(Date.now()-b)/1e3;O();for(let x=0;x<T;x++){const w=(R*.6+x/T*.5)%1,H=w<.5?Math.sin(w/.5*Math.PI):0,$=l+(F*.4-l)*H;m.current[x]+=($-m.current[x])*.15}P(m.current,E),c.current=requestAnimationFrame(a)};return c.current=requestAnimationFrame(a),()=>cancelAnimationFrame(c.current)}cancelAnimationFrame(c.current);const N=()=>{O();for(let b=0;b<T;b++){const a=k.current[b];a&&(a.style.height=`${l+u.current*D[b]}px`,a.style.background=E,a.style.animation="none")}c.current=requestAnimationFrame(N)};return c.current=requestAnimationFrame(N),()=>cancelAnimationFrame(c.current)},[n,e]);const f=e*.055,p=e*.035,I=e*.03,q=e*.55,C=e*.06;return o.jsx("div",{className:j,style:{width:e,height:e,display:"flex",alignItems:"center",justifyContent:"center",position:"relative",...v},children:o.jsx("div",{ref:r,onClick:d,onMouseEnter:()=>{s.current=!0,r.current&&(r.current.style.filter="brightness(1.35)")},onMouseLeave:()=>{s.current=!1,r.current&&(r.current.style.filter="brightness(1)")},onTouchEnd:()=>{setTimeout(()=>{s.current=!1,r.current&&(r.current.style.filter="brightness(1)")},200)},style:{display:"flex",alignItems:"center",justifyContent:"center",gap:p,transition:"filter 0.3s ease",cursor:d?"pointer":"default"},children:Array.from({length:T},(F,l)=>o.jsx("div",{ref:E=>{k.current[l]=E},style:{width:f,minHeight:C,maxHeight:q,height:C,borderRadius:I,background:G[n]??G.idle}},l))})})}function ge(){var m;let n=null,i=null,e=null,j=0,v=0,d=null;if(typeof navigator<"u"&&((m=navigator.mediaDevices)!=null&&m.getUserMedia)){const h=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=async s=>{const u=await h(s);return s!=null&&s.audio&&(d=u),u}}function k(h){if(!(!d||i))try{n=new AudioContext,i=n.createAnalyser(),i.fftSize=256,e=n.createMediaStreamSource(d),e.connect(i);const s=new Uint8Array(i.frequencyBinCount),u=()=>{if(!i)return;i.getByteFrequencyData(s);let A=0;for(let g=0;g<s.length;g++)A+=s[g]*s[g];const M=Math.sqrt(A/s.length)/255,S=M>v?.7:.3;v+=(M-v)*S,h(te(v)),j=requestAnimationFrame(u)};j=requestAnimationFrame(u)}catch(s){console.warn("[orb-ui] Mic monitor failed:",s)}}function r(){cancelAnimationFrame(j),j=0,v=0,e==null||e.disconnect(),e=null,i=null}function c(){r(),n&&(n.close().catch(()=>{}),n=null),d==null||d.getTracks().forEach(h=>{h.readyState==="live"&&h.stop()}),d=null}return{start:k,stop:r,release:c}}function z({state:n,volume:i,adapter:e,theme:j="debug",size:v=200,className:d,style:k,onStart:r,onStop:c}){const[m,h]=t.useState("idle"),[s,u]=t.useState(0),[A,M]=t.useState(0),S=t.useRef(ge()),g=t.useRef(!1);t.useEffect(()=>(h("idle"),u(0),M(0),e?e.subscribe({onStateChange:h,onVolumeChange:u}):void 0),[e]);const y=n??m;t.useEffect(()=>{const l=S.current;if(y==="listening"&&e){const E=setTimeout(()=>{l.start(M),g.current=!0},500);return()=>{clearTimeout(E),l.stop(),g.current=!1,M(0)}}else l.stop(),g.current=!1,M(0)},[y,e]),t.useEffect(()=>()=>S.current.release(),[]);const f=i??(y==="listening"&&g.current?A:s),p=y!=="idle"&&y!=="error",I=t.useCallback(()=>{var l,E;p?c?c():(l=e==null?void 0:e.stop)==null||l.call(e):r?r():(E=e==null?void 0:e.start)==null||E.call(e)},[e,p,r,c]),q=!!(e!=null&&e.start||r||c),C={state:y,volume:f,size:v,className:d,style:k},F=q?I:void 0;switch(j){case"circle":return o.jsx(ae,{...C,onClick:F});case"bars":return o.jsx(me,{...C,onClick:F});case"debug":default:return o.jsx(ce,{...C,onStart:r??(()=>{var l;return(l=e==null?void 0:e.start)==null?void 0:l.call(e)}),onStop:c??(()=>{var l;return(l=e==null?void 0:e.stop)==null?void 0:l.call(e)})})}}exports.Orb=z;exports.VoiceOrb=z;
11
+ `,u=.95,d=.08,f=.82,p=.18,m=24,h=0,g=.55,_=.12,v=.002;function y({state:n,volume:r,size:i,className:a,style:y,disabled:b=!1,interactive:x=!1,onClick:S,...C}){let w=(0,e.useRef)(null),T=(0,e.useRef)(null),E=(0,e.useRef)(null),D=(0,e.useRef)(0),O=(0,e.useRef)(r);o(()=>{O.current=r},[r]);let k=(0,e.useRef)(1),A=(0,e.useRef)(0),j=(0,e.useRef)(s(c.idle)),M=.06,N=(0,e.useRef)(f),P=(0,e.useRef)(p);(0,e.useEffect)(()=>{let e=`orb-circle-keyframes`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=l,document.head.appendChild(t)}},[]),(0,e.useEffect)(()=>{let e=w.current;if(e)if(n===`listening`||n===`speaking`){let t=n===`speaking`?u:f,r=n===`speaking`?d:p,i=n===`speaking`?m:h,a=()=>{let o=O.current;N.current+=(t-N.current)*M,P.current+=(r-P.current)*M;let l=N.current+o*P.current,u=o*i;n===`listening`?(k.current+=(l-k.current)*g,A.current+=(u-A.current)*g):(k.current=l,A.current=u);let d=s(c[n]),[f,p,m]=j.current;j.current=[f+(d[0]-f)*.05,p+(d[1]-p)*.05,m+(d[2]-m)*.05];let[h,_,v]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${h},${_},${v})`,e.style.boxShadow=`none`,e.style.animation=`none`;let y=T.current;if(y){let e=A.current;y.style.transform=`scale(${k.current})`,y.style.boxShadow=e>.5?`0 0 ${e}px ${e*.4}px rgb(${h},${_},${v})`:`none`}D.current=requestAnimationFrame(a)};return D.current=requestAnimationFrame(a),()=>{cancelAnimationFrame(D.current)}}else{cancelAnimationFrame(D.current);let t=c[n]??c.idle,r=s(t),i=()=>{k.current+=(1-k.current)*_,A.current+=(0-A.current)*_;let[a,o,s]=j.current;j.current=[a+(r[0]-a)*_,o+(r[1]-o)*_,s+(r[2]-s)*_];let[c,l,u]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${c},${l},${u})`,e.style.boxShadow=`none`,e.style.animation=`none`,T.current&&(T.current.style.transform=`scale(${k.current})`,T.current.style.boxShadow=`none`);let d=Math.abs(k.current-1)<v,f=A.current<.1,p=j.current.every((e,t)=>Math.abs(e-r[t])<1);if(d&&f&&p){k.current=1,A.current=0,j.current=r,e.style.transform=``,e.style.boxShadow=`none`,e.style.background=t,T.current&&(T.current.style.transform=`scale(1)`,T.current.style.boxShadow=`none`),n===`idle`?e.style.animation=`orb-circle-idle-pulse 3s ease-in-out infinite alternate`:n===`connecting`?e.style.animation=`orb-circle-connecting-pulse 1.5s ease-in-out infinite`:e.style.animation=`none`;return}D.current=requestAnimationFrame(i)};return D.current=requestAnimationFrame(i),()=>cancelAnimationFrame(D.current)}},[n]);let F=i*.55,I={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...y},L=(0,t.jsxs)(`span`,{ref:E,onMouseEnter:()=>{E.current&&!b&&(E.current.style.transform=`scale(1.06)`,E.current.style.filter=`brightness(1.12)`)},onMouseLeave:()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},200)},style:{position:`relative`,display:`inline-block`,transition:`transform 0.3s ease, filter 0.3s ease`,cursor:x?b?`not-allowed`:`pointer`:`default`,borderRadius:`50%`,lineHeight:0},children:[(0,t.jsx)(`span`,{ref:T,style:{position:`absolute`,display:`block`,width:F,height:F,borderRadius:`50%`,pointerEvents:`none`}}),(0,t.jsx)(`span`,{ref:w,style:{position:`relative`,display:`block`,width:F,height:F,borderRadius:`50%`,background:c[n]}})]});return x?(0,t.jsx)(`button`,{...C,type:`button`,className:a,disabled:b,onClick:b?void 0:S,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:b?`not-allowed`:`pointer`,...I},children:L}):(0,t.jsx)(`div`,{...C,className:a,style:I,children:L})}var b=5,x=1.4,S=Math.PI*2/b,C={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,speaking:`#e8e8e8`,error:`#f87171`};function w(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function T({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:c=!1,onClick:l,...u}){let d=(0,e.useRef)([]),f=(0,e.useRef)(null),p=(0,e.useRef)(0),m=(0,e.useRef)(Array(b).fill(0)),h=(0,e.useRef)(r),g=(0,e.useRef)(!1),_=(0,e.useRef)(0),v=(0,e.useRef)(w(C.idle)),y=(0,e.useRef)(null),T=(0,e.useRef)(Array(b).fill(0)),E=(0,e.useRef)(n);(0,e.useEffect)(()=>{n!==E.current&&(T.current=[...m.current],y.current=Date.now(),E.current=n)},[n]),(0,e.useEffect)(()=>{h.current=r},[r]),(0,e.useEffect)(()=>{let e=i*.55,t=i*.06,r=C[n]??C.idle,a=i*.1,o=Array.from({length:b},(e,t)=>{let n=(b-1)/2;return 1-.7*(Math.abs(t-n)/n)}),s=()=>{let e=g.current?a:0;_.current+=(e-_.current)*.15},c=(t,r)=>{s();let i=w(r),[a,c,l]=v.current;v.current=[a+(i[0]-a)*.08,c+(i[1]-c)*.08,l+(i[2]-l)*.08];let[u,f,p]=v.current.map(Math.round),m=`rgb(${u},${f},${p})`;for(let r=0;r<b;r++){let i=d.current[r];if(!i)continue;let a=n===`idle`?o[r]:1,s=_.current*a;i.style.height=`${Math.min(t[r]+s,e)}px`,i.style.background=m,i.style.animation=`none`}};if(n===`listening`||n===`speaking`){let i=n===`speaking`?1:.4,a=()=>{let o=h.current,s=Date.now()/1e3;for(let r=0;r<b;r++){let a=.5+.15*Math.sin(s*x*i*Math.PI*2+r*S),c=t+(e-t)*o*a;if(y.current!==null){let e=Date.now()-y.current,t=Math.min(e/300,1),n=1-(1-t)*(1-t);c=T.current[r]+(c-T.current[r])*n,t>=1&&(y.current=null)}let l=n===`listening`?.45:1;m.current[r]+=(c-m.current[r])*l}c(m.current,r),p.current=requestAnimationFrame(a)};return p.current=requestAnimationFrame(a),()=>cancelAnimationFrame(p.current)}if(n===`connecting`){let n=Date.now(),i=()=>{let a=(Date.now()-n)/1e3;s();for(let n=0;n<b;n++){let r=(a*.6+n/b*.5)%1,i=r<.5?Math.sin(r/.5*Math.PI):0,o=t+(e*.4-t)*i;m.current[n]+=(o-m.current[n])*.15}c(m.current,r),p.current=requestAnimationFrame(i)};return p.current=requestAnimationFrame(i),()=>cancelAnimationFrame(p.current)}cancelAnimationFrame(p.current);let l=()=>{s();for(let e=0;e<b;e++)m.current[e]+=(t-m.current[e])*.16;c(m.current,r),p.current=requestAnimationFrame(l)};return p.current=requestAnimationFrame(l),()=>cancelAnimationFrame(p.current)},[n,i]);let D=i*.055,O=i*.035,k=i*.03,A=i*.55,j=i*.06,M={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},N=(0,t.jsx)(`span`,{ref:f,onMouseEnter:()=>{s||(g.current=!0,f.current&&(f.current.style.filter=`brightness(1.35)`))},onMouseLeave:()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},200)},style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:O,transition:`filter 0.3s ease`,cursor:c?s?`not-allowed`:`pointer`:`default`},children:Array.from({length:b},(e,r)=>(0,t.jsx)(`span`,{ref:e=>{d.current[r]=e},style:{width:D,minHeight:j,maxHeight:A,height:j,borderRadius:k,background:C[n]??C.idle}},r))});return c?(0,t.jsx)(`button`,{...u,type:`button`,className:a,disabled:s,onClick:s?void 0:l,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:s?`not-allowed`:`pointer`,...M},children:N}):(0,t.jsx)(`div`,{...u,className:a,style:M,children:N})}function E(){let e=null,t=null,r=null,i=0,a=0,o=null;if(typeof navigator<`u`&&navigator.mediaDevices?.getUserMedia){let e=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=async t=>{let n=await e(t);return t?.audio&&(o=n),n}}function s(s){if(!(!o||t))try{e=new AudioContext,t=e.createAnalyser(),t.fftSize=256,r=e.createMediaStreamSource(o),r.connect(t);let c=new Uint8Array(t.frequencyBinCount),l=()=>{if(!t)return;t.getByteFrequencyData(c);let e=0;for(let t=0;t<c.length;t++)e+=c[t]*c[t];let r=Math.sqrt(e/c.length)/255,o=r>a?.7:.3;a+=(r-a)*o,s(n(a)),i=requestAnimationFrame(l)};i=requestAnimationFrame(l)}catch(e){console.warn(`[orb-ui] Mic monitor failed:`,e)}}function c(){cancelAnimationFrame(i),i=0,a=0,r?.disconnect(),r=null,t=null}function l(){c(),e&&=(e.close().catch(()=>{}),null),o?.getTracks().forEach(e=>{e.readyState===`live`&&e.stop()}),o=null}return{start:s,stop:c,release:l}}function D({state:n,volume:r,adapter:i,theme:o=`debug`,size:s=200,className:c,style:l,disabled:u=!1,onStart:d,onStop:f,...p}){let[m,h]=(0,e.useState)(`idle`),[g,_]=(0,e.useState)(0),[v,b]=(0,e.useState)(0),x=(0,e.useRef)(E()),S=(0,e.useRef)(!1);(0,e.useEffect)(()=>{if(h(`idle`),_(0),b(0),i)return i.subscribe({onStateChange:h,onVolumeChange:_})},[i]);let C=n??m;(0,e.useEffect)(()=>{let e=x.current;if(C===`listening`&&i){let t=setTimeout(()=>{e.start(b),S.current=!0},500);return()=>{clearTimeout(t),e.stop(),S.current=!1,b(0)}}else e.stop(),S.current=!1,b(0)},[C,i]),(0,e.useEffect)(()=>()=>x.current.release(),[]);let w=r??(C===`listening`&&S.current?v:g),D=C!==`idle`&&C!==`error`,O=(0,e.useCallback)(()=>{u||(D?f?f():i?.stop?.():d?d():i?.start?.())},[i,u,D,d,f]),k=D?!!(i?.stop||f):!!(i?.start||d),A=k&&!u?O:void 0,j={state:C,volume:w,size:s,className:c,style:l,disabled:u,...p,"aria-label":p[`aria-label`]??(k?`${D?`Stop`:`Start`} voice session`:void 0)},M={...j,interactive:k};switch(o){case`circle`:return(0,t.jsx)(y,{...M,onClick:A});case`bars`:return(0,t.jsx)(T,{...M,onClick:A});default:return(0,t.jsx)(a,{...j,onStart:u?void 0:d??(()=>i?.start?.()),onStop:u?void 0:f??(()=>i?.stop?.())})}}exports.Orb=D,exports.VoiceOrb=D;