orb-ui 0.2.3 → 0.3.0

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,89 @@
1
+ import { AriaAttributes, CSSProperties } from 'react';
2
+ export type OrbState = 'idle' | 'connecting' | 'listening' | 'thinking' | 'speaking' | 'error';
3
+ export type OrbTheme = 'debug' | 'circle' | 'bars';
4
+ export interface OrbSignal {
5
+ state: OrbState;
6
+ volume?: number;
7
+ inputVolume?: number;
8
+ outputVolume?: number;
9
+ error?: unknown;
10
+ }
11
+ export type OrbSignalListener = (signal: OrbSignal) => void;
12
+ export interface OrbAdapter {
13
+ /**
14
+ * Subscribe to normalized signal changes from a voice provider.
15
+ * Returns an unsubscribe function to clean up listeners.
16
+ */
17
+ subscribe(listener: OrbSignalListener): () => void;
18
+ /** Start the voice session. Called internally by Orb on click. */
19
+ start?: () => void | Promise<void>;
20
+ /** Stop the voice session. Called internally by Orb on click. */
21
+ stop?: () => void | Promise<void>;
22
+ }
23
+ /** @deprecated Use signal-based OrbAdapter.subscribe(listener). */
24
+ export interface AdapterCallbacks {
25
+ onStateChange: (state: OrbState) => void;
26
+ onVolumeChange: (volume: number) => void;
27
+ }
28
+ /** @deprecated Callback-object adapters will be removed in 0.5.0. */
29
+ export interface LegacyOrbAdapter {
30
+ subscribe(callbacks: AdapterCallbacks): () => void;
31
+ start?: () => void | Promise<void>;
32
+ stop?: () => void | Promise<void>;
33
+ }
34
+ type DataAttributeValue = string | number | boolean | null | undefined;
35
+ export interface OrbHtmlAttributes extends AriaAttributes {
36
+ /** Forwarded to the rendered orb control/container. */
37
+ id?: string;
38
+ /** Forwarded to the rendered orb control/container. */
39
+ title?: string;
40
+ /** Override the rendered role when you need custom semantics. */
41
+ role?: string;
42
+ /** Forwarded tab index for non-default keyboard ordering. */
43
+ tabIndex?: number;
44
+ /** Forward data-* attributes, e.g. data-testid. */
45
+ [dataAttribute: `data-${string}`]: DataAttributeValue;
46
+ }
47
+ export interface OrbProps extends OrbHtmlAttributes {
48
+ /**
49
+ * Current voice signal. Use this controlled mode when your app has separate
50
+ * input and output volume levels.
51
+ */
52
+ signal?: OrbSignal;
53
+ /**
54
+ * Current conversation state. Required in controlled mode (no adapter).
55
+ * Overrides signal and adapter state if provided.
56
+ */
57
+ state?: OrbState;
58
+ /**
59
+ * Current audio volume, normalized 0–1.
60
+ * Overrides signal and adapter volume if provided.
61
+ */
62
+ volume?: number;
63
+ /**
64
+ * Provider adapter (Vapi, ElevenLabs, etc.).
65
+ * Handles signal updates automatically from the SDK.
66
+ */
67
+ adapter?: OrbAdapter | LegacyOrbAdapter;
68
+ /** Visual theme. Defaults to 'debug'. */
69
+ theme?: OrbTheme;
70
+ /** Size in pixels. Defaults to 200. */
71
+ size?: number;
72
+ /** Optional class name for the rendered orb container/control. */
73
+ className?: string;
74
+ /** Optional inline styles for the rendered orb container/control. */
75
+ style?: CSSProperties;
76
+ /** Disable clickable themes and debug start/stop controls. */
77
+ disabled?: boolean;
78
+ /**
79
+ * Called when a clickable theme is activated while idle/error.
80
+ * Overrides adapter.start() when provided.
81
+ */
82
+ onStart?: () => void;
83
+ /**
84
+ * Called when a clickable theme is activated while active.
85
+ * Overrides adapter.stop() when provided.
86
+ */
87
+ onStop?: () => void;
88
+ }
89
+ export {};
@@ -0,0 +1,2 @@
1
+ export { Orb } from './Orb.js';
2
+ export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './Orb.types.js';
@@ -0,0 +1,5 @@
1
+ import { AdapterCallbacks, OrbSignal, OrbSignalListener, OrbState } from './Orb.types.js';
2
+ export type HybridOrbSignalListener = OrbSignalListener & AdapterCallbacks;
3
+ export declare function deriveOrbState(state: OrbState | undefined, signal: OrbSignal | undefined, adapterSignal: OrbSignal): OrbState;
4
+ export declare function deriveOrbVolume(volume: number | undefined, state: OrbState, signal: OrbSignal): number;
5
+ export declare function createOrbSignalListener(onSignal: OrbSignalListener, onLegacyAdapterUsed: () => void): HybridOrbSignalListener;
@@ -0,0 +1,4 @@
1
+ export { Orb } from './components/Orb/index.js';
2
+ export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } 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,t,n){return e??t?.state??n.state}function r(e,t,n){return e===void 0?t===`listening`?n.inputVolume??n.volume??0:t===`speaking`?n.outputVolume??n.volume??0:n.volume??0:e}function i(e,t){let n={state:`idle`},r=t=>{n=t,e(t)},i=(e=>{r(e)});return i.onStateChange=e=>{t(),r({...n,state:e})},i.onVolumeChange=e=>{t(),r({...n,volume:e})},i}var a=[`idle`,`connecting`,`listening`,`thinking`,`speaking`,`error`],o={idle:`#888`,connecting:`#f0c040`,listening:`#40c0f0`,thinking:`#c084fc`,speaking:`#40f080`,error:`#f04040`};function s({state:e,volume:n,size:r,className:i,style:s,disabled:c=!1,onStart:l,onStop:u,...d}){return(0,t.jsxs)(`div`,{...d,className:i,style:{width:r,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:o[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:o[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:a.map(n=>(0,t.jsx)(`button`,{disabled:c,style:{fontSize:10,padding:`2px 6px`,background:e===n?o[n]:`#222`,color:e===n?`#000`:`#888`,border:`1px solid ${e===n?o[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 c=typeof window<`u`?e.useLayoutEffect:e.useEffect;function l(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}var u={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`},d=`
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
+ `,f=.95,p=.08,m=.82,h=.18,g=24,_=0,v=.55,y=.12,b=.002;function x({state:n,volume:r,size:i,className:a,style:o,disabled:s=!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);c(()=>{O.current=r},[r]);let k=(0,e.useRef)(1),A=(0,e.useRef)(0),j=(0,e.useRef)(l(u.idle)),M=.06,N=(0,e.useRef)(m),P=(0,e.useRef)(h);(0,e.useEffect)(()=>{let e=`orb-circle-keyframes`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=d,document.head.appendChild(t)}},[]),(0,e.useEffect)(()=>{let e=w.current;if(e)if(n===`listening`||n===`speaking`){let t=n===`speaking`?f:m,r=n===`speaking`?p:h,i=n===`speaking`?g:_,a=()=>{let o=O.current;N.current+=(t-N.current)*M,P.current+=(r-P.current)*M;let s=N.current+o*P.current,c=o*i;n===`listening`?(k.current+=(s-k.current)*v,A.current+=(c-A.current)*v):(k.current=s,A.current=c);let d=l(u[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,g,_]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${h},${g},${_})`,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},${g},${_})`:`none`}D.current=requestAnimationFrame(a)};return D.current=requestAnimationFrame(a),()=>{cancelAnimationFrame(D.current)}}else{cancelAnimationFrame(D.current);let t=u[n]??u.idle,r=l(t),i=()=>{k.current+=(1-k.current)*y,A.current+=(0-A.current)*y;let[a,o,s]=j.current;j.current=[a+(r[0]-a)*y,o+(r[1]-o)*y,s+(r[2]-s)*y];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)<b,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`||n===`thinking`?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`,...o},L=(0,t.jsxs)(`span`,{ref:E,onMouseEnter:()=>{E.current&&!s&&(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?s?`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:u[n]}})]});return x?(0,t.jsx)(`button`,{...C,type:`button`,className:a,disabled:s,onClick:s?void 0:S,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:s?`not-allowed`:`pointer`,...I},children:L}):(0,t.jsx)(`div`,{...C,className:a,style:I,children:L})}var S=5,C=1.4,w=Math.PI*2/S,T={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`};function E(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function D({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(S).fill(0)),h=(0,e.useRef)(r),g=(0,e.useRef)(!1),_=(0,e.useRef)(0),v=(0,e.useRef)(E(T.idle)),y=(0,e.useRef)(null),b=(0,e.useRef)(Array(S).fill(0)),x=(0,e.useRef)(n);(0,e.useEffect)(()=>{n!==x.current&&(b.current=[...m.current],y.current=Date.now(),x.current=n)},[n]),(0,e.useEffect)(()=>{h.current=r},[r]),(0,e.useEffect)(()=>{let e=i*.55,t=i*.06,r=T[n]??T.idle,a=i*.1,o=Array.from({length:S},(e,t)=>{let n=(S-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=E(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<S;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<S;r++){let a=.5+.15*Math.sin(s*C*i*Math.PI*2+r*w),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=b.current[r]+(c-b.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`||n===`thinking`){let n=Date.now(),i=()=>{let a=(Date.now()-n)/1e3;s();for(let n=0;n<S;n++){let r=(a*.6+n/S*.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<S;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:S},(e,r)=>(0,t.jsx)(`span`,{ref:e=>{d.current[r]=e},style:{width:D,minHeight:j,maxHeight:A,height:j,borderRadius:k,background:T[n]??T.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})}var O=!1;function k(){return globalThis.process?.env?.NODE_ENV===`production`}function A(){O||k()||(O=!0,console.warn(`[orb-ui] Callback-object adapters are deprecated. Use subscribe(listener) and emit OrbSignal objects instead. Legacy adapters will be removed in 0.5.0.`))}function j({signal:a,state:o,volume:c,adapter:l,theme:u=`debug`,size:d=200,className:f,style:p,disabled:m=!1,onStart:h,onStop:g,..._}){let[v,y]=(0,e.useState)({state:`idle`});(0,e.useEffect)(()=>{if(y({state:`idle`}),!l)return;let e=i(y,A);return l.subscribe(e)},[l]);let b=a??v,S=n(o,a,v),C=r(c,S,b),w=S!==`idle`&&S!==`error`,T=(0,e.useCallback)(()=>{m||(w?g?g():l?.stop?.():h?h():l?.start?.())},[l,m,w,h,g]),E=w?!!(l?.stop||g):!!(l?.start||h),O=E&&!m?T:void 0,k={state:S,volume:C,size:d,className:f,style:p,disabled:m,..._,"aria-label":_[`aria-label`]??(E?`${w?`Stop`:`Start`} voice session`:void 0)},j={...k,interactive:E};switch(u){case`circle`:return(0,t.jsx)(x,{...j,onClick:O});case`bars`:return(0,t.jsx)(D,{...j,onClick:O});default:return(0,t.jsx)(s,{...k,onStart:m?void 0:h??(()=>l?.start?.()),onStop:m?void 0:g??(()=>l?.stop?.())})}}exports.Orb=j,exports.VoiceOrb=j;