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