orb-ui 0.1.1 → 0.2.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.
- package/README.md +20 -8
- package/dist/adapters.cjs +1 -0
- package/dist/adapters.d.ts +9 -10
- package/dist/adapters.js +75 -87
- package/dist/orb-ui.cjs +11 -0
- package/dist/orb-ui.d.ts +13 -9
- package/dist/orb-ui.js +370 -245
- package/package.json +21 -6
package/README.md
CHANGED
|
@@ -2,11 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
The simplest way to add voice UI to your React app. One install, one component, works with Vapi and ElevenLabs out of the box.
|
|
4
4
|
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://orb-ui-demo.vercel.app">
|
|
7
|
+
<img src="assets/demo-circle.jpg" alt="orb-ui demo — circle theme" width="600" />
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://orb-ui-demo.vercel.app">Live Demo</a> · <a href="https://www.npmjs.com/package/orb-ui">npm</a> · <a href="https://github.com/alexanderqchen/orb-ui">GitHub</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
5
15
|
```jsx
|
|
6
|
-
import {
|
|
16
|
+
import { Orb } from 'orb-ui'
|
|
7
17
|
import { createVapiAdapter } from 'orb-ui/adapters'
|
|
8
18
|
|
|
9
|
-
<
|
|
19
|
+
<Orb adapter={createVapiAdapter(vapi, { assistantId: 'your-id' })} theme="circle" />
|
|
10
20
|
```
|
|
11
21
|
|
|
12
22
|
## Install
|
|
@@ -17,20 +27,22 @@ npm install orb-ui
|
|
|
17
27
|
yarn add orb-ui
|
|
18
28
|
```
|
|
19
29
|
|
|
30
|
+
> **Note:** Orb uses React hooks internally — in Next.js App Router, use it in a `'use client'` component.
|
|
31
|
+
|
|
20
32
|
## Quick Start
|
|
21
33
|
|
|
22
34
|
### With Vapi
|
|
23
35
|
|
|
24
36
|
```jsx
|
|
25
37
|
import Vapi from '@vapi-ai/web'
|
|
26
|
-
import {
|
|
38
|
+
import { Orb } from 'orb-ui'
|
|
27
39
|
import { createVapiAdapter } from 'orb-ui/adapters'
|
|
28
40
|
|
|
29
41
|
const vapi = new Vapi('your-public-key')
|
|
30
42
|
const adapter = createVapiAdapter(vapi, { assistantId: 'your-assistant-id' })
|
|
31
43
|
|
|
32
44
|
function App() {
|
|
33
|
-
return <
|
|
45
|
+
return <Orb adapter={adapter} theme="circle" />
|
|
34
46
|
}
|
|
35
47
|
```
|
|
36
48
|
|
|
@@ -38,27 +50,27 @@ function App() {
|
|
|
38
50
|
|
|
39
51
|
```jsx
|
|
40
52
|
import { Conversation } from '@elevenlabs/client'
|
|
41
|
-
import {
|
|
53
|
+
import { Orb } from 'orb-ui'
|
|
42
54
|
import { createElevenLabsAdapter } from 'orb-ui/adapters'
|
|
43
55
|
|
|
44
56
|
const adapter = createElevenLabsAdapter(Conversation, { agentId: 'your-agent-id' })
|
|
45
57
|
|
|
46
58
|
function App() {
|
|
47
|
-
return <
|
|
59
|
+
return <Orb adapter={adapter} theme="circle" />
|
|
48
60
|
}
|
|
49
61
|
```
|
|
50
62
|
|
|
51
63
|
### Controlled mode (custom integration)
|
|
52
64
|
|
|
53
65
|
```jsx
|
|
54
|
-
import {
|
|
66
|
+
import { Orb } from 'orb-ui'
|
|
55
67
|
import { useState } from 'react'
|
|
56
68
|
|
|
57
69
|
function App() {
|
|
58
70
|
const [state, setState] = useState('idle')
|
|
59
71
|
const [volume, setVolume] = useState(0)
|
|
60
72
|
|
|
61
|
-
return <
|
|
73
|
+
return <Orb state={state} volume={volume} theme="circle" />
|
|
62
74
|
}
|
|
63
75
|
```
|
|
64
76
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=.12;function C(t){let l="idle",e=null;function i(n){if(e&&(clearTimeout(e),e=null),l==="speaking"&&n==="listening"){e=setTimeout(()=>{l=n,t(n),e=null},350);return}l=n,t(n)}function s(){e&&(clearTimeout(e),e=null)}return{emitState:i,clearTimer:s}}function I(t,l){let e=0;function i(s){const n=s<b?0:(s-b)/(1-b),o=n>e?.8:.5;return e=e+(n-e)*o,e}return{async start(){await t.start(l==null?void 0:l.assistantId)},stop(){t.stop()},subscribe({onStateChange:s,onVolumeChange:n}){const{emitState:o,clearTimer:g}=C(s);let a="idle",c=!1;const r=()=>{c=!0,a="listening",o("listening")},u=()=>{c=!1,a="idle",p(),o("idle"),n(0),e=0},S=()=>{c&&(a="speaking",o("speaking"),T())},L=()=>{c&&(p(),a="listening",o("listening"))};let v=0,d=0,m=0;const E=()=>{a==="speaking"&&(d+=(v-d)*.1,n(d)),m=requestAnimationFrame(E)},T=()=>{m||(m=requestAnimationFrame(E))},p=()=>{m&&(cancelAnimationFrame(m),m=0),d=0,v=0},V=f=>{if(a==="speaking"){const A=i(f);v=A/(A+.3)}},h=f=>{},k=f=>{console.error("[orb-ui/vapi] Error:",f),p(),o("error"),n(0),e=0};t.on("call-start",r),t.on("call-end",u),t.on("speech-start",S),t.on("speech-end",L),t.on("volume-level",V),t.on("message",h),t.on("error",k);const y=t.start.bind(t);return t.start=async(...f)=>(o("connecting"),y(...f)),()=>{g(),t.removeListener("call-start",r),t.removeListener("call-end",u),t.removeListener("speech-start",S),t.removeListener("speech-end",L),t.removeListener("volume-level",V),t.removeListener("message",h),t.removeListener("error",k),t.start=y}}}}function O(t,l){let e=null,i=null;const s=new Set;function n(r){s.forEach(u=>u.onStateChange(r))}function o(r){s.forEach(u=>u.onVolumeChange(r))}function g(){i||(i=setInterval(()=>{if(!e)return;const r=e.getOutputVolume();o(Math.min(r*2,1))},33))}function a(){i&&(clearInterval(i),i=null),o(0)}const c={onStatusChange:({status:r})=>{r==="connecting"&&n("connecting")},onConnect:()=>{n("listening")},onModeChange:({mode:r})=>{r==="speaking"?(n("speaking"),g()):(n("listening"),a())},onDisconnect:()=>{a(),n("idle"),o(0),e=null},onError:r=>{console.error("[orb-ui/elevenlabs] Error:",r),a(),n("error"),o(0),e=null}};return{subscribe(r){return s.add(r),()=>{s.delete(r),s.size===0&&a()}},async start(){if(!e)try{e=await t.startSession({...l,...c})}catch(r){console.error("[orb-ui/elevenlabs] startSession failed:",r),n("error"),o(0)}},async stop(){if(e){a();try{await e.endSession()}catch(r){console.error("[orb-ui/elevenlabs] endSession failed:",r)}e=null}}}}exports.createElevenLabsAdapter=O;exports.createVapiAdapter=I;
|
package/dist/adapters.d.ts
CHANGED
|
@@ -8,14 +8,14 @@ export declare interface AdapterCallbacks {
|
|
|
8
8
|
*
|
|
9
9
|
* Unlike createVapiAdapter, this adapter owns the session lifecycle because
|
|
10
10
|
* ElevenLabs requires callbacks to be injected at Conversation.startSession()
|
|
11
|
-
* time. Use the returned start() and stop() methods with
|
|
11
|
+
* time. Use the returned start() and stop() methods with Orb's props.
|
|
12
12
|
*
|
|
13
13
|
* @param ConversationClass - The Conversation class from @elevenlabs/client
|
|
14
14
|
* @param config - agentId / signedUrl + any other startSession options
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* import { Conversation } from '@elevenlabs/client'
|
|
18
|
-
* import {
|
|
18
|
+
* import { Orb } from 'orb-ui'
|
|
19
19
|
* import { createElevenLabsAdapter } from 'orb-ui/adapters'
|
|
20
20
|
*
|
|
21
21
|
* const adapter = createElevenLabsAdapter(Conversation, {
|
|
@@ -24,7 +24,7 @@ export declare interface AdapterCallbacks {
|
|
|
24
24
|
*
|
|
25
25
|
* function App() {
|
|
26
26
|
* return (
|
|
27
|
-
* <
|
|
27
|
+
* <Orb
|
|
28
28
|
* adapter={adapter}
|
|
29
29
|
* theme="circle"
|
|
30
30
|
* onStart={() => adapter.start()}
|
|
@@ -75,9 +75,9 @@ declare interface ElevenLabsConversationClass {
|
|
|
75
75
|
declare type ElevenLabsMode = 'speaking' | 'listening';
|
|
76
76
|
|
|
77
77
|
export declare interface ElevenLabsOrbAdapter extends OrbAdapter {
|
|
78
|
-
/** Call this from
|
|
78
|
+
/** Call this from Orb's onStart prop to begin a conversation. */
|
|
79
79
|
start(): Promise<void>;
|
|
80
|
-
/** Call this from
|
|
80
|
+
/** Call this from Orb's onStop prop to end the current conversation. */
|
|
81
81
|
stop(): Promise<void>;
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -92,13 +92,13 @@ export declare interface OrbAdapter {
|
|
|
92
92
|
onStateChange: (state: OrbState) => void;
|
|
93
93
|
onVolumeChange: (volume: number) => void;
|
|
94
94
|
}): () => void;
|
|
95
|
-
/** Start the voice session. Called internally by
|
|
95
|
+
/** Start the voice session. Called internally by Orb on click. */
|
|
96
96
|
start?: () => void | Promise<void>;
|
|
97
|
-
/** Stop the voice session. Called internally by
|
|
97
|
+
/** Stop the voice session. Called internally by Orb on click. */
|
|
98
98
|
stop?: () => void | Promise<void>;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export declare type OrbState = 'idle' | 'connecting' | 'listening' | '
|
|
101
|
+
export declare type OrbState = 'idle' | 'connecting' | 'listening' | 'speaking' | 'error';
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Creates an OrbAdapter for Vapi voice agents.
|
|
@@ -106,10 +106,9 @@ export declare type OrbState = 'idle' | 'connecting' | 'listening' | 'thinking'
|
|
|
106
106
|
* State mapping:
|
|
107
107
|
* vapi.start() called (intercepted) → 'connecting'
|
|
108
108
|
* call-start → 'listening'
|
|
109
|
-
* message (final user transcript) → 'thinking'
|
|
110
109
|
* speech-start → 'speaking'
|
|
111
110
|
* speech-end → 'listening' (debounced 350 ms)
|
|
112
|
-
* call-end → '
|
|
111
|
+
* call-end → 'idle'
|
|
113
112
|
* error → 'error'
|
|
114
113
|
*
|
|
115
114
|
* Volume: raw Vapi values are normalized (noise gate + EMA) before being
|
package/dist/adapters.js
CHANGED
|
@@ -1,94 +1,88 @@
|
|
|
1
|
-
function
|
|
2
|
-
let l = "idle",
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
l =
|
|
1
|
+
function F(t) {
|
|
2
|
+
let l = "idle", e = null;
|
|
3
|
+
function i(n) {
|
|
4
|
+
if (e && (clearTimeout(e), e = null), l === "speaking" && n === "listening") {
|
|
5
|
+
e = setTimeout(() => {
|
|
6
|
+
l = n, t(n), e = null;
|
|
7
7
|
}, 350);
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
-
l =
|
|
10
|
+
l = n, t(n);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function s() {
|
|
13
|
+
e && (clearTimeout(e), e = null);
|
|
14
14
|
}
|
|
15
|
-
return { emitState:
|
|
15
|
+
return { emitState: i, clearTimer: s };
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return t = t + (n - t) * o, t;
|
|
23
|
-
}
|
|
24
|
-
let c = null;
|
|
25
|
-
if (typeof navigator < "u" && ((m = navigator.mediaDevices) != null && m.getUserMedia)) {
|
|
26
|
-
const a = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
|
27
|
-
navigator.mediaDevices.getUserMedia = async (n) => {
|
|
28
|
-
const o = await a(n);
|
|
29
|
-
return n != null && n.audio && (c = o), o;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function i() {
|
|
33
|
-
c == null || c.getTracks().forEach((a) => {
|
|
34
|
-
a.readyState === "live" && a.stop();
|
|
35
|
-
}), c = null;
|
|
17
|
+
function y(t, l) {
|
|
18
|
+
let e = 0;
|
|
19
|
+
function i(s) {
|
|
20
|
+
const n = s < 0.12 ? 0 : (s - 0.12) / 0.88, o = n > e ? 0.8 : 0.5;
|
|
21
|
+
return e = e + (n - e) * o, e;
|
|
36
22
|
}
|
|
37
23
|
return {
|
|
38
24
|
async start() {
|
|
39
|
-
await
|
|
25
|
+
await t.start(l == null ? void 0 : l.assistantId);
|
|
40
26
|
},
|
|
41
27
|
stop() {
|
|
42
|
-
|
|
28
|
+
t.stop();
|
|
43
29
|
},
|
|
44
|
-
subscribe({ onStateChange:
|
|
45
|
-
const { emitState: o, clearTimer:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
}, S = (
|
|
52
|
-
u
|
|
53
|
-
},
|
|
54
|
-
|
|
30
|
+
subscribe({ onStateChange: s, onVolumeChange: n }) {
|
|
31
|
+
const { emitState: o, clearTimer: d } = F(s);
|
|
32
|
+
let a = "idle", u = !1;
|
|
33
|
+
const r = () => {
|
|
34
|
+
u = !0, a = "listening", o("listening");
|
|
35
|
+
}, c = () => {
|
|
36
|
+
u = !1, a = "idle", p(), o("idle"), n(0), e = 0;
|
|
37
|
+
}, S = () => {
|
|
38
|
+
u && (a = "speaking", o("speaking"), I());
|
|
39
|
+
}, L = () => {
|
|
40
|
+
u && (p(), a = "listening", o("listening"));
|
|
55
41
|
};
|
|
56
|
-
|
|
57
|
-
const b =
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
let v = 0, g = 0, m = 0;
|
|
43
|
+
const b = () => {
|
|
44
|
+
a === "speaking" && (g += (v - g) * 0.1, n(g)), m = requestAnimationFrame(b);
|
|
45
|
+
}, I = () => {
|
|
46
|
+
m || (m = requestAnimationFrame(b));
|
|
47
|
+
}, p = () => {
|
|
48
|
+
m && (cancelAnimationFrame(m), m = 0), g = 0, v = 0;
|
|
49
|
+
}, E = (f) => {
|
|
50
|
+
if (a === "speaking") {
|
|
51
|
+
const k = i(f);
|
|
52
|
+
v = k / (k + 0.3);
|
|
53
|
+
}
|
|
54
|
+
}, O = (f) => {
|
|
55
|
+
}, h = (f) => {
|
|
56
|
+
console.error("[orb-ui/vapi] Error:", f), p(), o("error"), n(0), e = 0;
|
|
57
|
+
};
|
|
58
|
+
t.on("call-start", r), t.on("call-end", c), t.on("speech-start", S), t.on("speech-end", L), t.on("volume-level", E), t.on("message", O), t.on("error", h);
|
|
59
|
+
const V = t.start.bind(t);
|
|
60
|
+
return t.start = async (...f) => (o("connecting"), V(...f)), () => {
|
|
61
|
+
d(), t.removeListener("call-start", r), t.removeListener("call-end", c), t.removeListener("speech-start", S), t.removeListener("speech-end", L), t.removeListener("volume-level", E), t.removeListener("message", O), t.removeListener("error", h), t.start = V;
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return function(t) {
|
|
68
|
-
const s = t > e ? M : T;
|
|
69
|
-
return e = e + (t - e) * s, e;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function _(e, l) {
|
|
73
|
-
let t = null, s = null, c = "listening";
|
|
74
|
-
const i = L(), m = L(), a = /* @__PURE__ */ new Set();
|
|
66
|
+
function A(t, l) {
|
|
67
|
+
let e = null, i = null;
|
|
68
|
+
const s = /* @__PURE__ */ new Set();
|
|
75
69
|
function n(r) {
|
|
76
|
-
|
|
70
|
+
s.forEach((c) => c.onStateChange(r));
|
|
77
71
|
}
|
|
78
72
|
function o(r) {
|
|
79
|
-
|
|
73
|
+
s.forEach((c) => c.onVolumeChange(r));
|
|
80
74
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
if (!
|
|
84
|
-
const r =
|
|
85
|
-
o(
|
|
75
|
+
function d() {
|
|
76
|
+
i || (i = setInterval(() => {
|
|
77
|
+
if (!e) return;
|
|
78
|
+
const r = e.getOutputVolume();
|
|
79
|
+
o(Math.min(r * 2, 1));
|
|
86
80
|
}, 33));
|
|
87
81
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
82
|
+
function a() {
|
|
83
|
+
i && (clearInterval(i), i = null), o(0);
|
|
90
84
|
}
|
|
91
|
-
const
|
|
85
|
+
const u = {
|
|
92
86
|
onStatusChange: ({ status: r }) => {
|
|
93
87
|
r === "connecting" && n("connecting");
|
|
94
88
|
},
|
|
@@ -96,54 +90,48 @@ function _(e, l) {
|
|
|
96
90
|
n("listening");
|
|
97
91
|
},
|
|
98
92
|
onModeChange: ({ mode: r }) => {
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
onVadScore: ({ vadScore: r }) => {
|
|
102
|
-
if (c === "listening") {
|
|
103
|
-
const f = r < p ? 0 : (r - p) / (1 - p);
|
|
104
|
-
o(m(f));
|
|
105
|
-
}
|
|
93
|
+
r === "speaking" ? (n("speaking"), d()) : (n("listening"), a());
|
|
106
94
|
},
|
|
107
95
|
onDisconnect: () => {
|
|
108
|
-
|
|
96
|
+
a(), n("idle"), o(0), e = null;
|
|
109
97
|
},
|
|
110
98
|
onError: (r) => {
|
|
111
|
-
console.error("[orb-ui/elevenlabs] Error:", r),
|
|
99
|
+
console.error("[orb-ui/elevenlabs] Error:", r), a(), n("error"), o(0), e = null;
|
|
112
100
|
}
|
|
113
101
|
};
|
|
114
102
|
return {
|
|
115
103
|
// ── OrbAdapter.subscribe ────────────────────────────────────────────────
|
|
116
104
|
subscribe(r) {
|
|
117
|
-
return
|
|
118
|
-
|
|
105
|
+
return s.add(r), () => {
|
|
106
|
+
s.delete(r), s.size === 0 && a();
|
|
119
107
|
};
|
|
120
108
|
},
|
|
121
109
|
// ── Lifecycle ───────────────────────────────────────────────────────────
|
|
122
110
|
async start() {
|
|
123
|
-
if (!
|
|
111
|
+
if (!e)
|
|
124
112
|
try {
|
|
125
|
-
|
|
113
|
+
e = await t.startSession({
|
|
126
114
|
...l,
|
|
127
|
-
...
|
|
115
|
+
...u
|
|
128
116
|
});
|
|
129
117
|
} catch (r) {
|
|
130
118
|
console.error("[orb-ui/elevenlabs] startSession failed:", r), n("error"), o(0);
|
|
131
119
|
}
|
|
132
120
|
},
|
|
133
121
|
async stop() {
|
|
134
|
-
if (
|
|
135
|
-
|
|
122
|
+
if (e) {
|
|
123
|
+
a();
|
|
136
124
|
try {
|
|
137
|
-
await
|
|
125
|
+
await e.endSession();
|
|
138
126
|
} catch (r) {
|
|
139
127
|
console.error("[orb-ui/elevenlabs] endSession failed:", r);
|
|
140
128
|
}
|
|
141
|
-
|
|
129
|
+
e = null;
|
|
142
130
|
}
|
|
143
131
|
}
|
|
144
132
|
};
|
|
145
133
|
}
|
|
146
134
|
export {
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
A as createElevenLabsAdapter,
|
|
136
|
+
y as createVapiAdapter
|
|
149
137
|
};
|
package/dist/orb-ui.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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=`
|
|
2
|
+
@keyframes orb-circle-idle-pulse {
|
|
3
|
+
from { transform: scale(1); }
|
|
4
|
+
to { transform: scale(1.06); }
|
|
5
|
+
}
|
|
6
|
+
@keyframes orb-circle-connecting-pulse {
|
|
7
|
+
0% { opacity: 1; transform: scale(1); }
|
|
8
|
+
50% { opacity: 0.6; transform: scale(0.95); }
|
|
9
|
+
100% { opacity: 1; transform: scale(1); }
|
|
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;
|
package/dist/orb-ui.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
+
declare function Orb({ state: stateProp, volume: volumeProp, adapter, theme, size, className, style, onStart, onStop, }: OrbProps): JSX_2.Element;
|
|
4
|
+
export { Orb }
|
|
5
|
+
export { Orb as VoiceOrb }
|
|
6
|
+
|
|
3
7
|
export declare interface OrbAdapter {
|
|
4
8
|
/**
|
|
5
9
|
* Subscribe to state and volume changes from a voice provider.
|
|
@@ -9,19 +13,13 @@ export declare interface OrbAdapter {
|
|
|
9
13
|
onStateChange: (state: OrbState) => void;
|
|
10
14
|
onVolumeChange: (volume: number) => void;
|
|
11
15
|
}): () => void;
|
|
12
|
-
/** Start the voice session. Called internally by
|
|
16
|
+
/** Start the voice session. Called internally by Orb on click. */
|
|
13
17
|
start?: () => void | Promise<void>;
|
|
14
|
-
/** Stop the voice session. Called internally by
|
|
18
|
+
/** Stop the voice session. Called internally by Orb on click. */
|
|
15
19
|
stop?: () => void | Promise<void>;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare type OrbTheme = 'debug' | 'circle' | 'bars';
|
|
21
|
-
|
|
22
|
-
export declare function VoiceOrb({ state: stateProp, volume: volumeProp, adapter, theme, size, className, style, onStart, onStop, }: VoiceOrbProps): JSX_2.Element;
|
|
23
|
-
|
|
24
|
-
export declare interface VoiceOrbProps {
|
|
22
|
+
declare interface OrbProps {
|
|
25
23
|
/**
|
|
26
24
|
* Current conversation state. Required in controlled mode (no adapter).
|
|
27
25
|
* Overrides adapter state if both are provided.
|
|
@@ -48,5 +46,11 @@ export declare interface VoiceOrbProps {
|
|
|
48
46
|
/** Called when the Stop button is clicked (debug theme only). */
|
|
49
47
|
onStop?: () => void;
|
|
50
48
|
}
|
|
49
|
+
export { OrbProps }
|
|
50
|
+
export { OrbProps as VoiceOrbProps }
|
|
51
|
+
|
|
52
|
+
export declare type OrbState = 'idle' | 'connecting' | 'listening' | 'speaking' | 'error';
|
|
53
|
+
|
|
54
|
+
export declare type OrbTheme = 'debug' | 'circle' | 'bars';
|
|
51
55
|
|
|
52
56
|
export { }
|
package/dist/orb-ui.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
|
|
1
|
+
import { jsxs as N, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useLayoutEffect as ce, useEffect as B, useState as Z, useCallback as oe } from "react";
|
|
3
|
+
function ie(n) {
|
|
4
|
+
let o = Math.min(n / 0.5, 1);
|
|
5
|
+
return o = Math.pow(o, 1.3), o;
|
|
6
|
+
}
|
|
7
|
+
const se = [
|
|
4
8
|
"idle",
|
|
5
9
|
"connecting",
|
|
6
10
|
"listening",
|
|
7
|
-
"thinking",
|
|
8
11
|
"speaking",
|
|
9
|
-
"error"
|
|
10
|
-
|
|
11
|
-
], I = {
|
|
12
|
+
"error"
|
|
13
|
+
], Q = {
|
|
12
14
|
idle: "#888",
|
|
13
15
|
connecting: "#f0c040",
|
|
14
16
|
listening: "#40c0f0",
|
|
15
|
-
thinking: "#c040f0",
|
|
16
17
|
speaking: "#40f080",
|
|
17
|
-
error: "#f04040"
|
|
18
|
-
disconnected: "#555"
|
|
18
|
+
error: "#f04040"
|
|
19
19
|
};
|
|
20
|
-
function
|
|
21
|
-
state:
|
|
22
|
-
volume:
|
|
23
|
-
size:
|
|
24
|
-
className:
|
|
25
|
-
style:
|
|
26
|
-
onStart:
|
|
27
|
-
onStop:
|
|
20
|
+
function le({
|
|
21
|
+
state: n,
|
|
22
|
+
volume: o,
|
|
23
|
+
size: e,
|
|
24
|
+
className: k,
|
|
25
|
+
style: A,
|
|
26
|
+
onStart: d,
|
|
27
|
+
onStop: M
|
|
28
28
|
}) {
|
|
29
|
-
return /* @__PURE__ */
|
|
29
|
+
return /* @__PURE__ */ N(
|
|
30
30
|
"div",
|
|
31
31
|
{
|
|
32
|
-
className:
|
|
32
|
+
className: k,
|
|
33
33
|
style: {
|
|
34
|
-
width:
|
|
34
|
+
width: e,
|
|
35
35
|
fontFamily: "monospace",
|
|
36
36
|
fontSize: 12,
|
|
37
37
|
background: "#111",
|
|
@@ -41,18 +41,18 @@ function V({
|
|
|
41
41
|
padding: 12,
|
|
42
42
|
boxSizing: "border-box",
|
|
43
43
|
userSelect: "none",
|
|
44
|
-
...
|
|
44
|
+
...A
|
|
45
45
|
},
|
|
46
46
|
children: [
|
|
47
|
-
/* @__PURE__ */
|
|
48
|
-
/* @__PURE__ */
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ l("div", { style: { color: "#555", marginBottom: 10, fontSize: 10, letterSpacing: 1 }, children: "ORB DEBUG" }),
|
|
48
|
+
/* @__PURE__ */ N("div", { style: { marginBottom: 8 }, children: [
|
|
49
|
+
/* @__PURE__ */ l("span", { style: { color: "#555" }, children: "state " }),
|
|
50
|
+
/* @__PURE__ */ l("span", { style: { color: Q[n], fontWeight: "bold" }, children: n })
|
|
51
51
|
] }),
|
|
52
|
-
/* @__PURE__ */
|
|
53
|
-
/* @__PURE__ */
|
|
54
|
-
/* @__PURE__ */
|
|
55
|
-
/* @__PURE__ */
|
|
52
|
+
/* @__PURE__ */ N("div", { style: { marginBottom: 10 }, children: [
|
|
53
|
+
/* @__PURE__ */ l("span", { style: { color: "#555" }, children: "volume " }),
|
|
54
|
+
/* @__PURE__ */ l("span", { style: { color: "#ccc" }, children: o.toFixed(2) }),
|
|
55
|
+
/* @__PURE__ */ l(
|
|
56
56
|
"div",
|
|
57
57
|
{
|
|
58
58
|
style: {
|
|
@@ -62,13 +62,13 @@ function V({
|
|
|
62
62
|
borderRadius: 2,
|
|
63
63
|
overflow: "hidden"
|
|
64
64
|
},
|
|
65
|
-
children: /* @__PURE__ */
|
|
65
|
+
children: /* @__PURE__ */ l(
|
|
66
66
|
"div",
|
|
67
67
|
{
|
|
68
68
|
style: {
|
|
69
69
|
height: "100%",
|
|
70
|
-
width: `${
|
|
71
|
-
background:
|
|
70
|
+
width: `${o * 100}%`,
|
|
71
|
+
background: Q[n],
|
|
72
72
|
borderRadius: 2,
|
|
73
73
|
transition: "width 50ms linear"
|
|
74
74
|
}
|
|
@@ -77,35 +77,35 @@ function V({
|
|
|
77
77
|
}
|
|
78
78
|
)
|
|
79
79
|
] }),
|
|
80
|
-
/* @__PURE__ */
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ N("div", { style: { marginBottom: 10 }, children: [
|
|
81
|
+
/* @__PURE__ */ l("div", { style: { color: "#555", marginBottom: 4, fontSize: 10 }, children: "force state" }),
|
|
82
|
+
/* @__PURE__ */ l("div", { style: { display: "flex", flexWrap: "wrap", gap: 4 }, children: se.map((t) => /* @__PURE__ */ l(
|
|
83
83
|
"button",
|
|
84
84
|
{
|
|
85
85
|
style: {
|
|
86
86
|
fontSize: 10,
|
|
87
87
|
padding: "2px 6px",
|
|
88
|
-
background:
|
|
89
|
-
color:
|
|
90
|
-
border: `1px solid ${
|
|
88
|
+
background: n === t ? Q[t] : "#222",
|
|
89
|
+
color: n === t ? "#000" : "#888",
|
|
90
|
+
border: `1px solid ${n === t ? Q[t] : "#333"}`,
|
|
91
91
|
borderRadius: 3,
|
|
92
92
|
cursor: "pointer"
|
|
93
93
|
},
|
|
94
94
|
onClick: () => {
|
|
95
95
|
console.warn(
|
|
96
|
-
`[orb-ui debug] To force state '${
|
|
96
|
+
`[orb-ui debug] To force state '${t}', use controlled mode: <Orb state="${t}" />`
|
|
97
97
|
);
|
|
98
98
|
},
|
|
99
|
-
children:
|
|
99
|
+
children: t
|
|
100
100
|
},
|
|
101
|
-
|
|
101
|
+
t
|
|
102
102
|
)) })
|
|
103
103
|
] }),
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
-
/* @__PURE__ */
|
|
104
|
+
/* @__PURE__ */ N("div", { style: { display: "flex", gap: 6 }, children: [
|
|
105
|
+
/* @__PURE__ */ l(
|
|
106
106
|
"button",
|
|
107
107
|
{
|
|
108
|
-
onClick:
|
|
108
|
+
onClick: d,
|
|
109
109
|
style: {
|
|
110
110
|
flex: 1,
|
|
111
111
|
padding: "4px 0",
|
|
@@ -119,10 +119,10 @@ function V({
|
|
|
119
119
|
children: "Start"
|
|
120
120
|
}
|
|
121
121
|
),
|
|
122
|
-
/* @__PURE__ */
|
|
122
|
+
/* @__PURE__ */ l(
|
|
123
123
|
"button",
|
|
124
124
|
{
|
|
125
|
-
onClick:
|
|
125
|
+
onClick: M,
|
|
126
126
|
style: {
|
|
127
127
|
flex: 1,
|
|
128
128
|
padding: "4px 0",
|
|
@@ -141,257 +141,382 @@ function V({
|
|
|
141
141
|
}
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function Y(n) {
|
|
145
145
|
return [
|
|
146
|
-
parseInt(
|
|
147
|
-
parseInt(
|
|
148
|
-
parseInt(
|
|
146
|
+
parseInt(n.slice(1, 3), 16),
|
|
147
|
+
parseInt(n.slice(3, 5), 16),
|
|
148
|
+
parseInt(n.slice(5, 7), 16)
|
|
149
149
|
];
|
|
150
150
|
}
|
|
151
|
-
const
|
|
151
|
+
const H = {
|
|
152
152
|
idle: "#cccccc",
|
|
153
153
|
connecting: "#cccccc",
|
|
154
|
-
listening: "#
|
|
155
|
-
speaking: "#
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
disconnected: "#444444"
|
|
159
|
-
}, W = `
|
|
154
|
+
listening: "#999999",
|
|
155
|
+
speaking: "#e8e8e8",
|
|
156
|
+
error: "#f87171"
|
|
157
|
+
}, ue = `
|
|
160
158
|
@keyframes orb-circle-idle-pulse {
|
|
161
159
|
from { transform: scale(1); }
|
|
162
160
|
to { transform: scale(1.06); }
|
|
163
161
|
}
|
|
164
162
|
@keyframes orb-circle-connecting-pulse {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
@keyframes orb-circle-thinking-spin {
|
|
169
|
-
from { transform: rotate(0deg); }
|
|
170
|
-
to { transform: rotate(360deg); }
|
|
163
|
+
0% { opacity: 1; transform: scale(1); }
|
|
164
|
+
50% { opacity: 0.6; transform: scale(0.95); }
|
|
165
|
+
100% { opacity: 1; transform: scale(1); }
|
|
171
166
|
}
|
|
172
|
-
`,
|
|
173
|
-
function
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}, [
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
if (!document.getElementById(
|
|
182
|
-
const
|
|
183
|
-
|
|
167
|
+
`, ae = 0.95, fe = 0.08, z = 0.82, ee = 0.18, de = 24, me = 0;
|
|
168
|
+
function ge({ state: n, volume: o, size: e, className: k, style: A, onClick: d }) {
|
|
169
|
+
const M = s(null), t = s(null), r = s(null), m = s(0), h = s(o);
|
|
170
|
+
ce(() => {
|
|
171
|
+
h.current = o;
|
|
172
|
+
}, [o]);
|
|
173
|
+
const c = s(1), u = s(0), p = s(Y(H.idle)), T = 0.06, S = s(z), g = s(ee);
|
|
174
|
+
B(() => {
|
|
175
|
+
const f = "orb-circle-keyframes";
|
|
176
|
+
if (!document.getElementById(f)) {
|
|
177
|
+
const x = document.createElement("style");
|
|
178
|
+
x.id = f, x.textContent = ue, document.head.appendChild(x);
|
|
184
179
|
}
|
|
185
|
-
}, []),
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
180
|
+
}, []), B(() => {
|
|
181
|
+
const f = M.current;
|
|
182
|
+
if (f)
|
|
183
|
+
if (n === "listening" || n === "speaking") {
|
|
184
|
+
const x = n === "speaking" ? ae : z, q = n === "speaking" ? fe : ee, L = n === "speaking" ? de : me, F = () => {
|
|
185
|
+
const $ = h.current;
|
|
186
|
+
S.current += (x - S.current) * T, g.current += (q - g.current) * T;
|
|
187
|
+
const i = S.current + $ * g.current, w = $ * L;
|
|
188
|
+
n === "listening" ? (c.current += (i - c.current) * 0.45, u.current += (w - u.current) * 0.45) : (c.current = i, u.current = w);
|
|
189
|
+
const P = Y(H[n]), [V, O, G] = p.current;
|
|
190
|
+
p.current = [
|
|
191
|
+
V + (P[0] - V) * 0.05,
|
|
192
|
+
O + (P[1] - O) * 0.05,
|
|
193
|
+
G + (P[2] - G) * 0.05
|
|
197
194
|
];
|
|
198
|
-
const [
|
|
199
|
-
|
|
195
|
+
const [W, b, a] = p.current.map(Math.round);
|
|
196
|
+
f.style.transform = `scale(${c.current})`, f.style.background = `rgb(${W},${b},${a})`, f.style.boxShadow = "none", f.style.animation = "none";
|
|
197
|
+
const v = t.current;
|
|
198
|
+
if (v) {
|
|
199
|
+
const R = u.current;
|
|
200
|
+
v.style.transform = `scale(${c.current})`, v.style.boxShadow = R > 0.5 ? `0 0 ${R}px ${R * 0.4}px rgb(${W},${b},${a})` : "none";
|
|
201
|
+
}
|
|
202
|
+
m.current = requestAnimationFrame(F);
|
|
200
203
|
};
|
|
201
|
-
return
|
|
202
|
-
cancelAnimationFrame(
|
|
204
|
+
return m.current = requestAnimationFrame(F), () => {
|
|
205
|
+
cancelAnimationFrame(m.current);
|
|
203
206
|
};
|
|
204
|
-
} else
|
|
205
|
-
cancelAnimationFrame(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
} else {
|
|
208
|
+
cancelAnimationFrame(m.current), c.current = 1, u.current = 0, p.current = Y(H[n] ?? H.idle), f.style.transform = "", f.style.boxShadow = "none", t.current && (t.current.style.boxShadow = "none");
|
|
209
|
+
const x = H[n] ?? H.idle, [q, L, F] = Y(x);
|
|
210
|
+
f.style.background = x, 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";
|
|
211
|
+
}
|
|
212
|
+
}, [n]);
|
|
213
|
+
const y = e * 0.55;
|
|
214
|
+
return /* @__PURE__ */ l(
|
|
209
215
|
"div",
|
|
210
216
|
{
|
|
211
|
-
className:
|
|
217
|
+
className: k,
|
|
212
218
|
style: {
|
|
213
|
-
width:
|
|
214
|
-
height:
|
|
219
|
+
width: e,
|
|
220
|
+
height: e,
|
|
215
221
|
display: "flex",
|
|
216
222
|
alignItems: "center",
|
|
217
223
|
justifyContent: "center",
|
|
218
224
|
position: "relative",
|
|
219
|
-
...
|
|
225
|
+
...A
|
|
220
226
|
},
|
|
221
|
-
children:
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
227
|
+
children: /* @__PURE__ */ N(
|
|
228
|
+
"div",
|
|
229
|
+
{
|
|
230
|
+
ref: r,
|
|
231
|
+
onClick: d,
|
|
232
|
+
onMouseEnter: () => {
|
|
233
|
+
r.current && (r.current.style.transform = "scale(1.06)", r.current.style.filter = "brightness(1.12)");
|
|
234
|
+
},
|
|
235
|
+
onMouseLeave: () => {
|
|
236
|
+
r.current && (r.current.style.transform = "scale(1)", r.current.style.filter = "brightness(1)");
|
|
237
|
+
},
|
|
238
|
+
onTouchEnd: () => {
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
r.current && (r.current.style.transform = "scale(1)", r.current.style.filter = "brightness(1)");
|
|
241
|
+
}, 200);
|
|
242
|
+
},
|
|
243
|
+
style: {
|
|
244
|
+
transition: "transform 0.3s ease, filter 0.3s ease",
|
|
245
|
+
cursor: d ? "pointer" : "default",
|
|
246
|
+
borderRadius: "50%",
|
|
247
|
+
lineHeight: 0
|
|
248
|
+
},
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ l(
|
|
251
|
+
"div",
|
|
252
|
+
{
|
|
253
|
+
ref: t,
|
|
254
|
+
style: {
|
|
255
|
+
position: "absolute",
|
|
256
|
+
width: y,
|
|
257
|
+
height: y,
|
|
258
|
+
borderRadius: "50%",
|
|
259
|
+
pointerEvents: "none"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
/* @__PURE__ */ l(
|
|
264
|
+
"div",
|
|
265
|
+
{
|
|
266
|
+
ref: M,
|
|
267
|
+
style: {
|
|
268
|
+
position: "relative",
|
|
269
|
+
width: y,
|
|
270
|
+
height: y,
|
|
271
|
+
borderRadius: "50%",
|
|
272
|
+
background: H[n]
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
)
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
)
|
|
245
279
|
}
|
|
246
280
|
);
|
|
247
281
|
}
|
|
248
|
-
const
|
|
282
|
+
const C = 5, he = 1.4, be = Math.PI * 2 / C, j = {
|
|
249
283
|
idle: "#cccccc",
|
|
250
284
|
connecting: "#cccccc",
|
|
251
|
-
listening: "#
|
|
252
|
-
speaking: "#
|
|
253
|
-
|
|
254
|
-
error: "#f87171",
|
|
255
|
-
disconnected: "#444444"
|
|
285
|
+
listening: "#999999",
|
|
286
|
+
speaking: "#e8e8e8",
|
|
287
|
+
error: "#f87171"
|
|
256
288
|
};
|
|
257
|
-
function
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
@keyframes orb-bars-wave-fast {
|
|
265
|
-
0%, 100% { height: ${n}px; }
|
|
266
|
-
50% { height: ${u * 0.5}px; }
|
|
267
|
-
}
|
|
268
|
-
`;
|
|
289
|
+
function ne(n) {
|
|
290
|
+
return [
|
|
291
|
+
parseInt(n.slice(1, 3), 16),
|
|
292
|
+
parseInt(n.slice(3, 5), 16),
|
|
293
|
+
parseInt(n.slice(5, 7), 16)
|
|
294
|
+
];
|
|
269
295
|
}
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}, [
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
296
|
+
function ye({ state: n, volume: o, size: e, className: k, style: A, onClick: d }) {
|
|
297
|
+
const M = s([]), t = s(null), r = s(0), m = s(new Array(C).fill(0)), h = s(o), c = s(!1), u = s(0), p = s(ne(j.idle)), T = 300, S = s(null), g = s(new Array(C).fill(0)), y = s(n);
|
|
298
|
+
B(() => {
|
|
299
|
+
n !== y.current && (g.current = [...m.current], S.current = Date.now(), y.current = n);
|
|
300
|
+
}, [n]), B(() => {
|
|
301
|
+
h.current = o;
|
|
302
|
+
}, [o]), B(() => {
|
|
303
|
+
const $ = e * 0.55, i = e * 0.06, w = j[n] ?? j.idle, P = e * 0.1, V = Array.from({ length: C }, (b, a) => {
|
|
304
|
+
const v = (C - 1) / 2;
|
|
305
|
+
return 1 - 0.7 * (Math.abs(a - v) / v);
|
|
306
|
+
}), O = () => {
|
|
307
|
+
const a = c.current ? P : 0;
|
|
308
|
+
u.current += (a - u.current) * 0.15;
|
|
309
|
+
}, G = (b, a) => {
|
|
310
|
+
O();
|
|
311
|
+
const v = ne(a), [R, E, D] = p.current;
|
|
312
|
+
p.current = [
|
|
313
|
+
R + (v[0] - R) * 0.08,
|
|
314
|
+
E + (v[1] - E) * 0.08,
|
|
315
|
+
D + (v[2] - D) * 0.08
|
|
316
|
+
];
|
|
317
|
+
const [_, J, X] = p.current.map(Math.round), U = `rgb(${_},${J},${X})`;
|
|
318
|
+
for (let I = 0; I < C; I++) {
|
|
319
|
+
const K = M.current[I];
|
|
320
|
+
if (!K) continue;
|
|
321
|
+
const te = n === "idle" ? V[I] : 1, re = u.current * te;
|
|
322
|
+
K.style.height = `${Math.min(b[I] + re, $)}px`, K.style.background = U, K.style.animation = "none";
|
|
283
323
|
}
|
|
284
324
|
};
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
for (let
|
|
289
|
-
const
|
|
290
|
-
|
|
325
|
+
if (n === "listening" || n === "speaking") {
|
|
326
|
+
const b = n === "speaking" ? 1 : 0.4, a = () => {
|
|
327
|
+
const v = h.current, R = Date.now() / 1e3;
|
|
328
|
+
for (let E = 0; E < C; E++) {
|
|
329
|
+
const D = 0.5 + 0.15 * Math.sin(R * he * b * Math.PI * 2 + E * be);
|
|
330
|
+
let _ = i + ($ - i) * v * D;
|
|
331
|
+
if (S.current !== null) {
|
|
332
|
+
const X = Date.now() - S.current, U = Math.min(X / T, 1), I = 1 - (1 - U) * (1 - U);
|
|
333
|
+
_ = g.current[E] + (_ - g.current[E]) * I, U >= 1 && (S.current = null);
|
|
334
|
+
}
|
|
335
|
+
const J = n === "listening" ? 0.45 : 1;
|
|
336
|
+
m.current[E] += (_ - m.current[E]) * J;
|
|
291
337
|
}
|
|
292
|
-
|
|
338
|
+
G(m.current, w), r.current = requestAnimationFrame(a);
|
|
293
339
|
};
|
|
294
|
-
return
|
|
340
|
+
return r.current = requestAnimationFrame(a), () => cancelAnimationFrame(r.current);
|
|
295
341
|
}
|
|
296
|
-
if (
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
342
|
+
if (n === "connecting") {
|
|
343
|
+
const b = Date.now(), a = () => {
|
|
344
|
+
const v = (Date.now() - b) / 1e3;
|
|
345
|
+
O();
|
|
346
|
+
for (let R = 0; R < C; R++) {
|
|
347
|
+
const E = (v * 0.6 + R / C * 0.5) % 1, D = E < 0.5 ? Math.sin(E / 0.5 * Math.PI) : 0, _ = i + ($ * 0.4 - i) * D;
|
|
348
|
+
m.current[R] += (_ - m.current[R]) * 0.15;
|
|
349
|
+
}
|
|
350
|
+
G(m.current, w), r.current = requestAnimationFrame(a);
|
|
302
351
|
};
|
|
303
|
-
return
|
|
352
|
+
return r.current = requestAnimationFrame(a), () => cancelAnimationFrame(r.current);
|
|
304
353
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const d = e === "idle" ? "orb-bars-wave" : "orb-bars-wave-fast";
|
|
312
|
-
o.style.animation = `${d} ${l} ease-in-out ${t * 0.15}s infinite`;
|
|
354
|
+
cancelAnimationFrame(r.current);
|
|
355
|
+
const W = () => {
|
|
356
|
+
O();
|
|
357
|
+
for (let b = 0; b < C; b++) {
|
|
358
|
+
const a = M.current[b];
|
|
359
|
+
a && (a.style.height = `${i + u.current * V[b]}px`, a.style.background = w, a.style.animation = "none");
|
|
313
360
|
}
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}, [e, n]);
|
|
321
|
-
const A = n * 0.055, w = n * 0.035, s = n * 0.03, m = n * 0.55, $ = n * 0.06;
|
|
322
|
-
return /* @__PURE__ */ i(
|
|
361
|
+
r.current = requestAnimationFrame(W);
|
|
362
|
+
};
|
|
363
|
+
return r.current = requestAnimationFrame(W), () => cancelAnimationFrame(r.current);
|
|
364
|
+
}, [n, e]);
|
|
365
|
+
const f = e * 0.055, x = e * 0.035, q = e * 0.03, L = e * 0.55, F = e * 0.06;
|
|
366
|
+
return /* @__PURE__ */ l(
|
|
323
367
|
"div",
|
|
324
368
|
{
|
|
325
|
-
className:
|
|
369
|
+
className: k,
|
|
326
370
|
style: {
|
|
327
|
-
width:
|
|
328
|
-
height:
|
|
371
|
+
width: e,
|
|
372
|
+
height: e,
|
|
329
373
|
display: "flex",
|
|
330
374
|
alignItems: "center",
|
|
331
375
|
justifyContent: "center",
|
|
332
|
-
|
|
333
|
-
...
|
|
376
|
+
position: "relative",
|
|
377
|
+
...A
|
|
334
378
|
},
|
|
335
|
-
children:
|
|
379
|
+
children: /* @__PURE__ */ l(
|
|
336
380
|
"div",
|
|
337
381
|
{
|
|
338
|
-
ref:
|
|
339
|
-
|
|
382
|
+
ref: t,
|
|
383
|
+
onClick: d,
|
|
384
|
+
onMouseEnter: () => {
|
|
385
|
+
c.current = !0, t.current && (t.current.style.filter = "brightness(1.35)");
|
|
386
|
+
},
|
|
387
|
+
onMouseLeave: () => {
|
|
388
|
+
c.current = !1, t.current && (t.current.style.filter = "brightness(1)");
|
|
389
|
+
},
|
|
390
|
+
onTouchEnd: () => {
|
|
391
|
+
setTimeout(() => {
|
|
392
|
+
c.current = !1, t.current && (t.current.style.filter = "brightness(1)");
|
|
393
|
+
}, 200);
|
|
340
394
|
},
|
|
341
395
|
style: {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
396
|
+
display: "flex",
|
|
397
|
+
alignItems: "center",
|
|
398
|
+
justifyContent: "center",
|
|
399
|
+
gap: x,
|
|
400
|
+
transition: "filter 0.3s ease",
|
|
401
|
+
cursor: d ? "pointer" : "default"
|
|
402
|
+
},
|
|
403
|
+
children: Array.from({ length: C }, ($, i) => /* @__PURE__ */ l(
|
|
404
|
+
"div",
|
|
405
|
+
{
|
|
406
|
+
ref: (w) => {
|
|
407
|
+
M.current[i] = w;
|
|
408
|
+
},
|
|
409
|
+
style: {
|
|
410
|
+
width: f,
|
|
411
|
+
minHeight: F,
|
|
412
|
+
maxHeight: L,
|
|
413
|
+
height: F,
|
|
414
|
+
borderRadius: q,
|
|
415
|
+
background: j[n] ?? j.idle
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
i
|
|
419
|
+
))
|
|
420
|
+
}
|
|
421
|
+
)
|
|
353
422
|
}
|
|
354
423
|
);
|
|
355
424
|
}
|
|
356
|
-
function
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
425
|
+
function ve() {
|
|
426
|
+
var m;
|
|
427
|
+
let n = null, o = null, e = null, k = 0, A = 0, d = null;
|
|
428
|
+
if (typeof navigator < "u" && ((m = navigator.mediaDevices) != null && m.getUserMedia)) {
|
|
429
|
+
const h = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
|
430
|
+
navigator.mediaDevices.getUserMedia = async (c) => {
|
|
431
|
+
const u = await h(c);
|
|
432
|
+
return c != null && c.audio && (d = u), u;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function M(h) {
|
|
436
|
+
if (!(!d || o))
|
|
437
|
+
try {
|
|
438
|
+
n = new AudioContext(), o = n.createAnalyser(), o.fftSize = 256, e = n.createMediaStreamSource(d), e.connect(o);
|
|
439
|
+
const c = new Uint8Array(o.frequencyBinCount), u = () => {
|
|
440
|
+
if (!o) return;
|
|
441
|
+
o.getByteFrequencyData(c);
|
|
442
|
+
let p = 0;
|
|
443
|
+
for (let g = 0; g < c.length; g++) p += c[g] * c[g];
|
|
444
|
+
const T = Math.sqrt(p / c.length) / 255, S = T > A ? 0.7 : 0.3;
|
|
445
|
+
A += (T - A) * S, h(ie(A)), k = requestAnimationFrame(u);
|
|
446
|
+
};
|
|
447
|
+
k = requestAnimationFrame(u);
|
|
448
|
+
} catch (c) {
|
|
449
|
+
console.warn("[orb-ui] Mic monitor failed:", c);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function t() {
|
|
453
|
+
cancelAnimationFrame(k), k = 0, A = 0, e == null || e.disconnect(), e = null, o = null;
|
|
454
|
+
}
|
|
455
|
+
function r() {
|
|
456
|
+
t(), n && (n.close().catch(() => {
|
|
457
|
+
}), n = null), d == null || d.getTracks().forEach((h) => {
|
|
458
|
+
h.readyState === "live" && h.stop();
|
|
459
|
+
}), d = null;
|
|
460
|
+
}
|
|
461
|
+
return { start: M, stop: t, release: r };
|
|
462
|
+
}
|
|
463
|
+
function pe({
|
|
464
|
+
state: n,
|
|
465
|
+
volume: o,
|
|
466
|
+
adapter: e,
|
|
467
|
+
theme: k = "debug",
|
|
468
|
+
size: A = 200,
|
|
469
|
+
className: d,
|
|
470
|
+
style: M,
|
|
471
|
+
onStart: t,
|
|
472
|
+
onStop: r
|
|
366
473
|
}) {
|
|
367
|
-
const [
|
|
368
|
-
|
|
369
|
-
onStateChange:
|
|
370
|
-
onVolumeChange:
|
|
371
|
-
}) : void 0, [
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
474
|
+
const [m, h] = Z("idle"), [c, u] = Z(0), [p, T] = Z(0), S = s(ve()), g = s(!1);
|
|
475
|
+
B(() => (h("idle"), u(0), T(0), e ? e.subscribe({
|
|
476
|
+
onStateChange: h,
|
|
477
|
+
onVolumeChange: u
|
|
478
|
+
}) : void 0), [e]);
|
|
479
|
+
const y = n ?? m;
|
|
480
|
+
B(() => {
|
|
481
|
+
const i = S.current;
|
|
482
|
+
if (y === "listening" && e) {
|
|
483
|
+
const w = setTimeout(() => {
|
|
484
|
+
i.start(T), g.current = !0;
|
|
485
|
+
}, 500);
|
|
486
|
+
return () => {
|
|
487
|
+
clearTimeout(w), i.stop(), g.current = !1, T(0);
|
|
488
|
+
};
|
|
489
|
+
} else
|
|
490
|
+
i.stop(), g.current = !1, T(0);
|
|
491
|
+
}, [y, e]), B(() => () => S.current.release(), []);
|
|
492
|
+
const f = o ?? (y === "listening" && g.current ? p : c), x = y !== "idle" && y !== "error", q = oe(() => {
|
|
493
|
+
var i, w;
|
|
494
|
+
x ? r ? r() : (i = e == null ? void 0 : e.stop) == null || i.call(e) : t ? t() : (w = e == null ? void 0 : e.start) == null || w.call(e);
|
|
495
|
+
}, [e, x, t, r]), L = !!(e != null && e.start || t || r), F = { state: y, volume: f, size: A, className: d, style: M }, $ = L ? q : void 0;
|
|
496
|
+
switch (k) {
|
|
497
|
+
case "circle":
|
|
498
|
+
return /* @__PURE__ */ l(ge, { ...F, onClick: $ });
|
|
499
|
+
case "bars":
|
|
500
|
+
return /* @__PURE__ */ l(ye, { ...F, onClick: $ });
|
|
501
|
+
case "debug":
|
|
502
|
+
default:
|
|
503
|
+
return /* @__PURE__ */ l(
|
|
504
|
+
le,
|
|
505
|
+
{
|
|
506
|
+
...F,
|
|
507
|
+
onStart: t ?? (() => {
|
|
508
|
+
var i;
|
|
509
|
+
return (i = e == null ? void 0 : e.start) == null ? void 0 : i.call(e);
|
|
510
|
+
}),
|
|
511
|
+
onStop: r ?? (() => {
|
|
512
|
+
var i;
|
|
513
|
+
return (i = e == null ? void 0 : e.stop) == null ? void 0 : i.call(e);
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
);
|
|
517
|
+
}
|
|
394
518
|
}
|
|
395
519
|
export {
|
|
396
|
-
|
|
520
|
+
pe as Orb,
|
|
521
|
+
pe as VoiceOrb
|
|
397
522
|
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orb-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The simplest voice
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The simplest way to add voice UI to your React app. One install, one component, works with Vapi and ElevenLabs out of the box.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "./dist/orb-ui.cjs",
|
|
6
7
|
"module": "./dist/orb-ui.js",
|
|
7
|
-
"types": "./dist/
|
|
8
|
+
"types": "./dist/orb-ui.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": "./dist/orb-ui.js",
|
|
11
|
-
"
|
|
12
|
+
"require": "./dist/orb-ui.cjs",
|
|
13
|
+
"types": "./dist/orb-ui.d.ts"
|
|
12
14
|
},
|
|
13
15
|
"./adapters": {
|
|
14
16
|
"import": "./dist/adapters.js",
|
|
15
|
-
"
|
|
17
|
+
"require": "./dist/adapters.cjs",
|
|
18
|
+
"types": "./dist/adapters.d.ts"
|
|
16
19
|
}
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
@@ -43,17 +46,29 @@
|
|
|
43
46
|
},
|
|
44
47
|
"keywords": [
|
|
45
48
|
"voice",
|
|
49
|
+
"voice-ui",
|
|
50
|
+
"voice-agent",
|
|
46
51
|
"ai",
|
|
47
52
|
"react",
|
|
48
53
|
"animation",
|
|
49
54
|
"component",
|
|
55
|
+
"state-machine",
|
|
50
56
|
"vapi",
|
|
51
57
|
"elevenlabs"
|
|
52
58
|
],
|
|
53
59
|
"license": "MIT",
|
|
60
|
+
"author": "Alexander Chen",
|
|
61
|
+
"homepage": "https://orb-ui-demo.vercel.app",
|
|
54
62
|
"repository": {
|
|
55
63
|
"type": "git",
|
|
56
64
|
"url": "https://github.com/alexanderqchen/orb-ui.git"
|
|
57
65
|
},
|
|
58
|
-
"dependencies": {}
|
|
66
|
+
"dependencies": {},
|
|
67
|
+
"typesVersions": {
|
|
68
|
+
"*": {
|
|
69
|
+
"adapters": [
|
|
70
|
+
"./dist/adapters.d.ts"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
59
74
|
}
|