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.
package/dist/orb-ui.js CHANGED
@@ -1,522 +1,566 @@
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;
1
+ import { useCallback as e, useEffect as t, useLayoutEffect as n, useRef as r, useState as i } from "react";
2
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
3
+ //#region src/adapters/types.ts
4
+ function s(e) {
5
+ let t = Math.min(e / .5, 1);
6
+ return t **= 1.3, t;
6
7
  }
7
- const se = [
8
- "idle",
9
- "connecting",
10
- "listening",
11
- "speaking",
12
- "error"
13
- ], Q = {
14
- idle: "#888",
15
- connecting: "#f0c040",
16
- listening: "#40c0f0",
17
- speaking: "#40f080",
18
- error: "#f04040"
8
+ //#endregion
9
+ //#region src/themes/debug/DebugTheme.tsx
10
+ var c = [
11
+ "idle",
12
+ "connecting",
13
+ "listening",
14
+ "speaking",
15
+ "error"
16
+ ], l = {
17
+ idle: "#888",
18
+ connecting: "#f0c040",
19
+ listening: "#40c0f0",
20
+ speaking: "#40f080",
21
+ error: "#f04040"
19
22
  };
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
- }) {
29
- return /* @__PURE__ */ N(
30
- "div",
31
- {
32
- className: k,
33
- style: {
34
- width: e,
35
- fontFamily: "monospace",
36
- fontSize: 12,
37
- background: "#111",
38
- color: "#ccc",
39
- border: "1px solid #333",
40
- borderRadius: 8,
41
- padding: 12,
42
- boxSizing: "border-box",
43
- userSelect: "none",
44
- ...A
45
- },
46
- children: [
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
- ] }),
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
- "div",
57
- {
58
- style: {
59
- marginTop: 4,
60
- height: 4,
61
- background: "#222",
62
- borderRadius: 2,
63
- overflow: "hidden"
64
- },
65
- children: /* @__PURE__ */ l(
66
- "div",
67
- {
68
- style: {
69
- height: "100%",
70
- width: `${o * 100}%`,
71
- background: Q[n],
72
- borderRadius: 2,
73
- transition: "width 50ms linear"
74
- }
75
- }
76
- )
77
- }
78
- )
79
- ] }),
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
- "button",
84
- {
85
- style: {
86
- fontSize: 10,
87
- padding: "2px 6px",
88
- background: n === t ? Q[t] : "#222",
89
- color: n === t ? "#000" : "#888",
90
- border: `1px solid ${n === t ? Q[t] : "#333"}`,
91
- borderRadius: 3,
92
- cursor: "pointer"
93
- },
94
- onClick: () => {
95
- console.warn(
96
- `[orb-ui debug] To force state '${t}', use controlled mode: <Orb state="${t}" />`
97
- );
98
- },
99
- children: t
100
- },
101
- t
102
- )) })
103
- ] }),
104
- /* @__PURE__ */ N("div", { style: { display: "flex", gap: 6 }, children: [
105
- /* @__PURE__ */ l(
106
- "button",
107
- {
108
- onClick: d,
109
- style: {
110
- flex: 1,
111
- padding: "4px 0",
112
- background: "#1a3a1a",
113
- color: "#40f080",
114
- border: "1px solid #40f080",
115
- borderRadius: 4,
116
- cursor: "pointer",
117
- fontSize: 11
118
- },
119
- children: "Start"
120
- }
121
- ),
122
- /* @__PURE__ */ l(
123
- "button",
124
- {
125
- onClick: M,
126
- style: {
127
- flex: 1,
128
- padding: "4px 0",
129
- background: "#3a1a1a",
130
- color: "#f04040",
131
- border: "1px solid #f04040",
132
- borderRadius: 4,
133
- cursor: "pointer",
134
- fontSize: 11
135
- },
136
- children: "Stop"
137
- }
138
- )
139
- ] })
140
- ]
141
- }
142
- );
23
+ function u({ state: e, volume: t, size: n, className: r, style: i, disabled: s = !1, onStart: u, onStop: d, ...f }) {
24
+ return /* @__PURE__ */ o("div", {
25
+ ...f,
26
+ className: r,
27
+ style: {
28
+ width: n,
29
+ fontFamily: "monospace",
30
+ fontSize: 12,
31
+ background: "#111",
32
+ color: "#ccc",
33
+ border: "1px solid #333",
34
+ borderRadius: 8,
35
+ padding: 12,
36
+ boxSizing: "border-box",
37
+ userSelect: "none",
38
+ ...i
39
+ },
40
+ children: [
41
+ /* @__PURE__ */ a("div", {
42
+ style: {
43
+ color: "#555",
44
+ marginBottom: 10,
45
+ fontSize: 10,
46
+ letterSpacing: 1
47
+ },
48
+ children: "ORB DEBUG"
49
+ }),
50
+ /* @__PURE__ */ o("div", {
51
+ style: { marginBottom: 8 },
52
+ children: [/* @__PURE__ */ a("span", {
53
+ style: { color: "#555" },
54
+ children: "state "
55
+ }), /* @__PURE__ */ a("span", {
56
+ style: {
57
+ color: l[e],
58
+ fontWeight: "bold"
59
+ },
60
+ children: e
61
+ })]
62
+ }),
63
+ /* @__PURE__ */ o("div", {
64
+ style: { marginBottom: 10 },
65
+ children: [
66
+ /* @__PURE__ */ a("span", {
67
+ style: { color: "#555" },
68
+ children: "volume "
69
+ }),
70
+ /* @__PURE__ */ a("span", {
71
+ style: { color: "#ccc" },
72
+ children: t.toFixed(2)
73
+ }),
74
+ /* @__PURE__ */ a("div", {
75
+ style: {
76
+ marginTop: 4,
77
+ height: 4,
78
+ background: "#222",
79
+ borderRadius: 2,
80
+ overflow: "hidden"
81
+ },
82
+ children: /* @__PURE__ */ a("div", { style: {
83
+ height: "100%",
84
+ width: `${t * 100}%`,
85
+ background: l[e],
86
+ borderRadius: 2,
87
+ transition: "width 50ms linear"
88
+ } })
89
+ })
90
+ ]
91
+ }),
92
+ /* @__PURE__ */ o("div", {
93
+ style: { marginBottom: 10 },
94
+ children: [/* @__PURE__ */ a("div", {
95
+ style: {
96
+ color: "#555",
97
+ marginBottom: 4,
98
+ fontSize: 10
99
+ },
100
+ children: "force state"
101
+ }), /* @__PURE__ */ a("div", {
102
+ style: {
103
+ display: "flex",
104
+ flexWrap: "wrap",
105
+ gap: 4
106
+ },
107
+ children: c.map((t) => /* @__PURE__ */ a("button", {
108
+ disabled: s,
109
+ style: {
110
+ fontSize: 10,
111
+ padding: "2px 6px",
112
+ background: e === t ? l[t] : "#222",
113
+ color: e === t ? "#000" : "#888",
114
+ border: `1px solid ${e === t ? l[t] : "#333"}`,
115
+ borderRadius: 3,
116
+ cursor: s ? "not-allowed" : "pointer"
117
+ },
118
+ onClick: () => {
119
+ console.warn(`[orb-ui debug] To force state '${t}', use controlled mode: <Orb state="${t}" />`);
120
+ },
121
+ children: t
122
+ }, t))
123
+ })]
124
+ }),
125
+ /* @__PURE__ */ o("div", {
126
+ style: {
127
+ display: "flex",
128
+ gap: 6
129
+ },
130
+ children: [/* @__PURE__ */ a("button", {
131
+ disabled: s,
132
+ onClick: u,
133
+ style: {
134
+ flex: 1,
135
+ padding: "4px 0",
136
+ background: "#1a3a1a",
137
+ color: "#40f080",
138
+ border: "1px solid #40f080",
139
+ borderRadius: 4,
140
+ cursor: s ? "not-allowed" : "pointer",
141
+ fontSize: 11
142
+ },
143
+ children: "Start"
144
+ }), /* @__PURE__ */ a("button", {
145
+ disabled: s,
146
+ onClick: d,
147
+ style: {
148
+ flex: 1,
149
+ padding: "4px 0",
150
+ background: "#3a1a1a",
151
+ color: "#f04040",
152
+ border: "1px solid #f04040",
153
+ borderRadius: 4,
154
+ cursor: s ? "not-allowed" : "pointer",
155
+ fontSize: 11
156
+ },
157
+ children: "Stop"
158
+ })]
159
+ })
160
+ ]
161
+ });
143
162
  }
144
- function Y(n) {
145
- return [
146
- parseInt(n.slice(1, 3), 16),
147
- parseInt(n.slice(3, 5), 16),
148
- parseInt(n.slice(5, 7), 16)
149
- ];
163
+ //#endregion
164
+ //#region src/themes/circle/CircleTheme.tsx
165
+ var d = typeof window < "u" ? n : t;
166
+ function f(e) {
167
+ return [
168
+ parseInt(e.slice(1, 3), 16),
169
+ parseInt(e.slice(3, 5), 16),
170
+ parseInt(e.slice(5, 7), 16)
171
+ ];
150
172
  }
151
- const H = {
152
- idle: "#cccccc",
153
- connecting: "#cccccc",
154
- listening: "#999999",
155
- speaking: "#e8e8e8",
156
- error: "#f87171"
157
- }, ue = `
158
- @keyframes orb-circle-idle-pulse {
159
- from { transform: scale(1); }
160
- to { transform: scale(1.06); }
173
+ var p = {
174
+ idle: "#cccccc",
175
+ connecting: "#cccccc",
176
+ listening: "#999999",
177
+ speaking: "#e8e8e8",
178
+ error: "#f87171"
179
+ }, m = "\n@keyframes orb-circle-idle-pulse {\n from { transform: scale(1); }\n to { transform: scale(1.06); }\n}\n@keyframes orb-circle-connecting-pulse {\n 0% { opacity: 1; transform: scale(1); }\n 50% { opacity: 0.6; transform: scale(0.95); }\n 100% { opacity: 1; transform: scale(1); }\n}\n", h = .95, g = .08, _ = .82, v = .18, y = 24, b = 0, x = .55, S = .12, C = .002;
180
+ function w({ state: e, volume: n, size: i, className: s, style: c, disabled: l = !1, interactive: u = !1, onClick: w, ...T }) {
181
+ let E = r(null), D = r(null), O = r(null), k = r(0), A = r(n);
182
+ d(() => {
183
+ A.current = n;
184
+ }, [n]);
185
+ let j = r(1), M = r(0), N = r(f(p.idle)), P = .06, F = r(_), I = r(v);
186
+ t(() => {
187
+ let e = "orb-circle-keyframes";
188
+ if (!document.getElementById(e)) {
189
+ let t = document.createElement("style");
190
+ t.id = e, t.textContent = m, document.head.appendChild(t);
191
+ }
192
+ }, []), t(() => {
193
+ let t = E.current;
194
+ if (t) if (e === "listening" || e === "speaking") {
195
+ let n = e === "speaking" ? h : _, r = e === "speaking" ? g : v, i = e === "speaking" ? y : b, a = () => {
196
+ let o = A.current;
197
+ F.current += (n - F.current) * P, I.current += (r - I.current) * P;
198
+ let s = F.current + o * I.current, c = o * i;
199
+ e === "listening" ? (j.current += (s - j.current) * x, M.current += (c - M.current) * x) : (j.current = s, M.current = c);
200
+ let l = f(p[e]), [u, d, m] = N.current;
201
+ N.current = [
202
+ u + (l[0] - u) * .05,
203
+ d + (l[1] - d) * .05,
204
+ m + (l[2] - m) * .05
205
+ ];
206
+ let [h, g, _] = N.current.map(Math.round);
207
+ t.style.transform = `scale(${j.current})`, t.style.background = `rgb(${h},${g},${_})`, t.style.boxShadow = "none", t.style.animation = "none";
208
+ let v = D.current;
209
+ if (v) {
210
+ let e = M.current;
211
+ v.style.transform = `scale(${j.current})`, v.style.boxShadow = e > .5 ? `0 0 ${e}px ${e * .4}px rgb(${h},${g},${_})` : "none";
212
+ }
213
+ k.current = requestAnimationFrame(a);
214
+ };
215
+ return k.current = requestAnimationFrame(a), () => {
216
+ cancelAnimationFrame(k.current);
217
+ };
218
+ } else {
219
+ cancelAnimationFrame(k.current);
220
+ let n = p[e] ?? p.idle, r = f(n), i = () => {
221
+ j.current += (1 - j.current) * S, M.current += (0 - M.current) * S;
222
+ let [a, o, s] = N.current;
223
+ N.current = [
224
+ a + (r[0] - a) * S,
225
+ o + (r[1] - o) * S,
226
+ s + (r[2] - s) * S
227
+ ];
228
+ let [c, l, u] = N.current.map(Math.round);
229
+ t.style.transform = `scale(${j.current})`, t.style.background = `rgb(${c},${l},${u})`, t.style.boxShadow = "none", t.style.animation = "none", D.current && (D.current.style.transform = `scale(${j.current})`, D.current.style.boxShadow = "none");
230
+ let d = Math.abs(j.current - 1) < C, f = M.current < .1, p = N.current.every((e, t) => Math.abs(e - r[t]) < 1);
231
+ if (d && f && p) {
232
+ j.current = 1, M.current = 0, N.current = r, t.style.transform = "", t.style.boxShadow = "none", t.style.background = n, D.current && (D.current.style.transform = "scale(1)", D.current.style.boxShadow = "none"), e === "idle" ? t.style.animation = "orb-circle-idle-pulse 3s ease-in-out infinite alternate" : e === "connecting" ? t.style.animation = "orb-circle-connecting-pulse 1.5s ease-in-out infinite" : t.style.animation = "none";
233
+ return;
234
+ }
235
+ k.current = requestAnimationFrame(i);
236
+ };
237
+ return k.current = requestAnimationFrame(i), () => cancelAnimationFrame(k.current);
238
+ }
239
+ }, [e]);
240
+ let L = i * .55, R = {
241
+ width: i,
242
+ height: i,
243
+ display: "flex",
244
+ alignItems: "center",
245
+ justifyContent: "center",
246
+ position: "relative",
247
+ ...c
248
+ }, z = /* @__PURE__ */ o("span", {
249
+ ref: O,
250
+ onMouseEnter: () => {
251
+ O.current && !l && (O.current.style.transform = "scale(1.06)", O.current.style.filter = "brightness(1.12)");
252
+ },
253
+ onMouseLeave: () => {
254
+ O.current && (O.current.style.transform = "scale(1)", O.current.style.filter = "brightness(1)");
255
+ },
256
+ onTouchEnd: () => {
257
+ setTimeout(() => {
258
+ O.current && (O.current.style.transform = "scale(1)", O.current.style.filter = "brightness(1)");
259
+ }, 200);
260
+ },
261
+ style: {
262
+ position: "relative",
263
+ display: "inline-block",
264
+ transition: "transform 0.3s ease, filter 0.3s ease",
265
+ cursor: u ? l ? "not-allowed" : "pointer" : "default",
266
+ borderRadius: "50%",
267
+ lineHeight: 0
268
+ },
269
+ children: [/* @__PURE__ */ a("span", {
270
+ ref: D,
271
+ style: {
272
+ position: "absolute",
273
+ display: "block",
274
+ width: L,
275
+ height: L,
276
+ borderRadius: "50%",
277
+ pointerEvents: "none"
278
+ }
279
+ }), /* @__PURE__ */ a("span", {
280
+ ref: E,
281
+ style: {
282
+ position: "relative",
283
+ display: "block",
284
+ width: L,
285
+ height: L,
286
+ borderRadius: "50%",
287
+ background: p[e]
288
+ }
289
+ })]
290
+ });
291
+ return u ? /* @__PURE__ */ a("button", {
292
+ ...T,
293
+ type: "button",
294
+ className: s,
295
+ disabled: l,
296
+ onClick: l ? void 0 : w,
297
+ style: {
298
+ appearance: "none",
299
+ WebkitAppearance: "none",
300
+ border: 0,
301
+ padding: 0,
302
+ margin: 0,
303
+ background: "transparent",
304
+ color: "inherit",
305
+ font: "inherit",
306
+ cursor: l ? "not-allowed" : "pointer",
307
+ ...R
308
+ },
309
+ children: z
310
+ }) : /* @__PURE__ */ a("div", {
311
+ ...T,
312
+ className: s,
313
+ style: R,
314
+ children: z
315
+ });
161
316
  }
162
- @keyframes orb-circle-connecting-pulse {
163
- 0% { opacity: 1; transform: scale(1); }
164
- 50% { opacity: 0.6; transform: scale(0.95); }
165
- 100% { opacity: 1; transform: scale(1); }
166
- }
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);
179
- }
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
194
- ];
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);
203
- };
204
- return m.current = requestAnimationFrame(F), () => {
205
- cancelAnimationFrame(m.current);
206
- };
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(
215
- "div",
216
- {
217
- className: k,
218
- style: {
219
- width: e,
220
- height: e,
221
- display: "flex",
222
- alignItems: "center",
223
- justifyContent: "center",
224
- position: "relative",
225
- ...A
226
- },
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
- )
279
- }
280
- );
281
- }
282
- const C = 5, he = 1.4, be = Math.PI * 2 / C, j = {
283
- idle: "#cccccc",
284
- connecting: "#cccccc",
285
- listening: "#999999",
286
- speaking: "#e8e8e8",
287
- error: "#f87171"
317
+ //#endregion
318
+ //#region src/themes/bars/BarsTheme.tsx
319
+ var T = 5, E = 1.4, D = Math.PI * 2 / T, O = {
320
+ idle: "#cccccc",
321
+ connecting: "#cccccc",
322
+ listening: "#999999",
323
+ speaking: "#e8e8e8",
324
+ error: "#f87171"
288
325
  };
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
- ];
326
+ function k(e) {
327
+ return [
328
+ parseInt(e.slice(1, 3), 16),
329
+ parseInt(e.slice(3, 5), 16),
330
+ parseInt(e.slice(5, 7), 16)
331
+ ];
295
332
  }
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";
323
- }
324
- };
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;
337
- }
338
- G(m.current, w), r.current = requestAnimationFrame(a);
339
- };
340
- return r.current = requestAnimationFrame(a), () => cancelAnimationFrame(r.current);
341
- }
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);
351
- };
352
- return r.current = requestAnimationFrame(a), () => cancelAnimationFrame(r.current);
353
- }
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");
360
- }
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(
367
- "div",
368
- {
369
- className: k,
370
- style: {
371
- width: e,
372
- height: e,
373
- display: "flex",
374
- alignItems: "center",
375
- justifyContent: "center",
376
- position: "relative",
377
- ...A
378
- },
379
- children: /* @__PURE__ */ l(
380
- "div",
381
- {
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);
394
- },
395
- style: {
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
- )
422
- }
423
- );
333
+ function A({ state: e, volume: n, size: i, className: o, style: s, disabled: c = !1, interactive: l = !1, onClick: u, ...d }) {
334
+ let f = r([]), p = r(null), m = r(0), h = r(Array(T).fill(0)), g = r(n), _ = r(!1), v = r(0), y = r(k(O.idle)), b = r(null), x = r(Array(T).fill(0)), S = r(e);
335
+ t(() => {
336
+ e !== S.current && (x.current = [...h.current], b.current = Date.now(), S.current = e);
337
+ }, [e]), t(() => {
338
+ g.current = n;
339
+ }, [n]), t(() => {
340
+ let t = i * .55, n = i * .06, r = O[e] ?? O.idle, a = i * .1, o = Array.from({ length: T }, (e, t) => {
341
+ let n = (T - 1) / 2;
342
+ return 1 - .7 * (Math.abs(t - n) / n);
343
+ }), s = () => {
344
+ let e = _.current ? a : 0;
345
+ v.current += (e - v.current) * .15;
346
+ }, c = (n, r) => {
347
+ s();
348
+ let i = k(r), [a, c, l] = y.current;
349
+ y.current = [
350
+ a + (i[0] - a) * .08,
351
+ c + (i[1] - c) * .08,
352
+ l + (i[2] - l) * .08
353
+ ];
354
+ let [u, d, p] = y.current.map(Math.round), m = `rgb(${u},${d},${p})`;
355
+ for (let r = 0; r < T; r++) {
356
+ let i = f.current[r];
357
+ if (!i) continue;
358
+ let a = e === "idle" ? o[r] : 1, s = v.current * a;
359
+ i.style.height = `${Math.min(n[r] + s, t)}px`, i.style.background = m, i.style.animation = "none";
360
+ }
361
+ };
362
+ if (e === "listening" || e === "speaking") {
363
+ let i = e === "speaking" ? 1 : .4, a = () => {
364
+ let o = g.current, s = Date.now() / 1e3;
365
+ for (let r = 0; r < T; r++) {
366
+ let a = .5 + .15 * Math.sin(s * E * i * Math.PI * 2 + r * D), c = n + (t - n) * o * a;
367
+ if (b.current !== null) {
368
+ let e = Date.now() - b.current, t = Math.min(e / 300, 1), n = 1 - (1 - t) * (1 - t);
369
+ c = x.current[r] + (c - x.current[r]) * n, t >= 1 && (b.current = null);
370
+ }
371
+ let l = e === "listening" ? .45 : 1;
372
+ h.current[r] += (c - h.current[r]) * l;
373
+ }
374
+ c(h.current, r), m.current = requestAnimationFrame(a);
375
+ };
376
+ return m.current = requestAnimationFrame(a), () => cancelAnimationFrame(m.current);
377
+ }
378
+ if (e === "connecting") {
379
+ let e = Date.now(), i = () => {
380
+ let a = (Date.now() - e) / 1e3;
381
+ s();
382
+ for (let e = 0; e < T; e++) {
383
+ let r = (a * .6 + e / T * .5) % 1, i = r < .5 ? Math.sin(r / .5 * Math.PI) : 0, o = n + (t * .4 - n) * i;
384
+ h.current[e] += (o - h.current[e]) * .15;
385
+ }
386
+ c(h.current, r), m.current = requestAnimationFrame(i);
387
+ };
388
+ return m.current = requestAnimationFrame(i), () => cancelAnimationFrame(m.current);
389
+ }
390
+ cancelAnimationFrame(m.current);
391
+ let l = () => {
392
+ s();
393
+ for (let e = 0; e < T; e++) h.current[e] += (n - h.current[e]) * .16;
394
+ c(h.current, r), m.current = requestAnimationFrame(l);
395
+ };
396
+ return m.current = requestAnimationFrame(l), () => cancelAnimationFrame(m.current);
397
+ }, [e, i]);
398
+ let C = i * .055, w = i * .035, A = i * .03, j = i * .55, M = i * .06, N = {
399
+ width: i,
400
+ height: i,
401
+ display: "flex",
402
+ alignItems: "center",
403
+ justifyContent: "center",
404
+ position: "relative",
405
+ ...s
406
+ }, P = /* @__PURE__ */ a("span", {
407
+ ref: p,
408
+ onMouseEnter: () => {
409
+ c || (_.current = !0, p.current && (p.current.style.filter = "brightness(1.35)"));
410
+ },
411
+ onMouseLeave: () => {
412
+ _.current = !1, p.current && (p.current.style.filter = "brightness(1)");
413
+ },
414
+ onTouchEnd: () => {
415
+ setTimeout(() => {
416
+ _.current = !1, p.current && (p.current.style.filter = "brightness(1)");
417
+ }, 200);
418
+ },
419
+ style: {
420
+ display: "flex",
421
+ alignItems: "center",
422
+ justifyContent: "center",
423
+ gap: w,
424
+ transition: "filter 0.3s ease",
425
+ cursor: l ? c ? "not-allowed" : "pointer" : "default"
426
+ },
427
+ children: Array.from({ length: T }, (t, n) => /* @__PURE__ */ a("span", {
428
+ ref: (e) => {
429
+ f.current[n] = e;
430
+ },
431
+ style: {
432
+ width: C,
433
+ minHeight: M,
434
+ maxHeight: j,
435
+ height: M,
436
+ borderRadius: A,
437
+ background: O[e] ?? O.idle
438
+ }
439
+ }, n))
440
+ });
441
+ return l ? /* @__PURE__ */ a("button", {
442
+ ...d,
443
+ type: "button",
444
+ className: o,
445
+ disabled: c,
446
+ onClick: c ? void 0 : u,
447
+ style: {
448
+ appearance: "none",
449
+ WebkitAppearance: "none",
450
+ border: 0,
451
+ padding: 0,
452
+ margin: 0,
453
+ background: "transparent",
454
+ color: "inherit",
455
+ font: "inherit",
456
+ cursor: c ? "not-allowed" : "pointer",
457
+ ...N
458
+ },
459
+ children: P
460
+ }) : /* @__PURE__ */ a("div", {
461
+ ...d,
462
+ className: o,
463
+ style: N,
464
+ children: P
465
+ });
424
466
  }
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 };
467
+ //#endregion
468
+ //#region src/components/Orb/Orb.tsx
469
+ function j() {
470
+ let e = null, t = null, n = null, r = 0, i = 0, a = null;
471
+ if (typeof navigator < "u" && navigator.mediaDevices?.getUserMedia) {
472
+ let e = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
473
+ navigator.mediaDevices.getUserMedia = async (t) => {
474
+ let n = await e(t);
475
+ return t?.audio && (a = n), n;
476
+ };
477
+ }
478
+ function o(o) {
479
+ if (!(!a || t)) try {
480
+ e = new AudioContext(), t = e.createAnalyser(), t.fftSize = 256, n = e.createMediaStreamSource(a), n.connect(t);
481
+ let c = new Uint8Array(t.frequencyBinCount), l = () => {
482
+ if (!t) return;
483
+ t.getByteFrequencyData(c);
484
+ let e = 0;
485
+ for (let t = 0; t < c.length; t++) e += c[t] * c[t];
486
+ let n = Math.sqrt(e / c.length) / 255, a = n > i ? .7 : .3;
487
+ i += (n - i) * a, o(s(i)), r = requestAnimationFrame(l);
488
+ };
489
+ r = requestAnimationFrame(l);
490
+ } catch (e) {
491
+ console.warn("[orb-ui] Mic monitor failed:", e);
492
+ }
493
+ }
494
+ function c() {
495
+ cancelAnimationFrame(r), r = 0, i = 0, n?.disconnect(), n = null, t = null;
496
+ }
497
+ function l() {
498
+ c(), e &&= (e.close().catch(() => {}), null), a?.getTracks().forEach((e) => {
499
+ e.readyState === "live" && e.stop();
500
+ }), a = null;
501
+ }
502
+ return {
503
+ start: o,
504
+ stop: c,
505
+ release: l
506
+ };
462
507
  }
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
473
- }) {
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
- }
508
+ function M({ state: n, volume: o, adapter: s, theme: c = "debug", size: l = 200, className: d, style: f, disabled: p = !1, onStart: m, onStop: h, ...g }) {
509
+ let [_, v] = i("idle"), [y, b] = i(0), [x, S] = i(0), C = r(j()), T = r(!1);
510
+ t(() => {
511
+ if (v("idle"), b(0), S(0), s) return s.subscribe({
512
+ onStateChange: v,
513
+ onVolumeChange: b
514
+ });
515
+ }, [s]);
516
+ let E = n ?? _;
517
+ t(() => {
518
+ let e = C.current;
519
+ if (E === "listening" && s) {
520
+ let t = setTimeout(() => {
521
+ e.start(S), T.current = !0;
522
+ }, 500);
523
+ return () => {
524
+ clearTimeout(t), e.stop(), T.current = !1, S(0);
525
+ };
526
+ } else e.stop(), T.current = !1, S(0);
527
+ }, [E, s]), t(() => () => C.current.release(), []);
528
+ let D = o ?? (E === "listening" && T.current ? x : y), O = E !== "idle" && E !== "error", k = e(() => {
529
+ p || (O ? h ? h() : s?.stop?.() : m ? m() : s?.start?.());
530
+ }, [
531
+ s,
532
+ p,
533
+ O,
534
+ m,
535
+ h
536
+ ]), M = O ? !!(s?.stop || h) : !!(s?.start || m), N = M && !p ? k : void 0, P = {
537
+ state: E,
538
+ volume: D,
539
+ size: l,
540
+ className: d,
541
+ style: f,
542
+ disabled: p,
543
+ ...g,
544
+ "aria-label": g["aria-label"] ?? (M ? `${O ? "Stop" : "Start"} voice session` : void 0)
545
+ }, F = {
546
+ ...P,
547
+ interactive: M
548
+ };
549
+ switch (c) {
550
+ case "circle": return /* @__PURE__ */ a(w, {
551
+ ...F,
552
+ onClick: N
553
+ });
554
+ case "bars": return /* @__PURE__ */ a(A, {
555
+ ...F,
556
+ onClick: N
557
+ });
558
+ default: return /* @__PURE__ */ a(u, {
559
+ ...P,
560
+ onStart: p ? void 0 : m ?? (() => s?.start?.()),
561
+ onStop: p ? void 0 : h ?? (() => s?.stop?.())
562
+ });
563
+ }
518
564
  }
519
- export {
520
- pe as Orb,
521
- pe as VoiceOrb
522
- };
565
+ //#endregion
566
+ export { M as Orb, M as VoiceOrb };