orb-ui 0.5.0 → 0.6.1
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 +40 -20
- package/dist/adapters/audio-level.d.ts +5 -0
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/livekit/browser.d.ts +5 -0
- package/dist/adapters/livekit/index.d.ts +9 -2
- package/dist/adapters/pipecat/index.d.ts +16 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +260 -241
- package/dist/components/Orb/Orb.d.ts +1 -1
- package/dist/components/Orb/Orb.types.d.ts +6 -1
- package/dist/livekit-CukEeYFK.js +316 -0
- package/dist/livekit-Dt-QZ6Gs.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -1
- package/dist/livekit-adapter.js +4 -2
- package/dist/orb-ui.cjs +101 -1
- package/dist/orb-ui.js +279 -34
- package/dist/themes/cloud/CloudTheme.d.ts +14 -0
- package/dist/themes/cloud/index.d.ts +1 -0
- package/dist/themes/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/livekit-Dasur3lv.js +0 -240
- package/dist/livekit-Ro6A52eb.cjs +0 -1
package/dist/orb-ui.js
CHANGED
|
@@ -253,7 +253,7 @@ function T({ state: e, volume: n, size: i, className: s, style: c, disabled: l =
|
|
|
253
253
|
}, z = /* @__PURE__ */ o("span", {
|
|
254
254
|
ref: O,
|
|
255
255
|
onMouseEnter: () => {
|
|
256
|
-
O.current && !l && (O.current.style.transform = "scale(1.06)", O.current.style.filter = "brightness(1.12)");
|
|
256
|
+
O.current && u && !l && (O.current.style.transform = "scale(1.06)", O.current.style.filter = "brightness(1.12)");
|
|
257
257
|
},
|
|
258
258
|
onMouseLeave: () => {
|
|
259
259
|
O.current && (O.current.style.transform = "scale(1)", O.current.style.filter = "brightness(1)");
|
|
@@ -347,9 +347,9 @@ function j({ state: e, volume: n, size: i, className: o, style: s, disabled: c =
|
|
|
347
347
|
let n = (E - 1) / 2;
|
|
348
348
|
return 1 - .7 * (Math.abs(t - n) / n);
|
|
349
349
|
}), s = () => {
|
|
350
|
-
let e = _.current ? a : 0;
|
|
351
|
-
v.current += (
|
|
352
|
-
},
|
|
350
|
+
let e = l && !c, t = _.current && e ? a : 0;
|
|
351
|
+
v.current += (t - v.current) * .15;
|
|
352
|
+
}, u = (n, r) => {
|
|
353
353
|
s();
|
|
354
354
|
let i = A(r), [a, c, l] = y.current;
|
|
355
355
|
y.current = [
|
|
@@ -377,7 +377,7 @@ function j({ state: e, volume: n, size: i, className: o, style: s, disabled: c =
|
|
|
377
377
|
let l = e === "listening" ? .45 : 1;
|
|
378
378
|
h.current[r] += (c - h.current[r]) * l;
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
u(h.current, r), m.current = requestAnimationFrame(a);
|
|
381
381
|
};
|
|
382
382
|
return m.current = requestAnimationFrame(a), () => cancelAnimationFrame(m.current);
|
|
383
383
|
}
|
|
@@ -389,17 +389,17 @@ function j({ state: e, volume: n, size: i, className: o, style: s, disabled: c =
|
|
|
389
389
|
let r = (a * .6 + e / E * .5) % 1, i = r < .5 ? Math.sin(r / .5 * Math.PI) : 0, o = n + (t * .4 - n) * i;
|
|
390
390
|
h.current[e] += (o - h.current[e]) * .15;
|
|
391
391
|
}
|
|
392
|
-
|
|
392
|
+
u(h.current, r), m.current = requestAnimationFrame(i);
|
|
393
393
|
};
|
|
394
394
|
return m.current = requestAnimationFrame(i), () => cancelAnimationFrame(m.current);
|
|
395
395
|
}
|
|
396
396
|
cancelAnimationFrame(m.current);
|
|
397
|
-
let
|
|
397
|
+
let d = () => {
|
|
398
398
|
s();
|
|
399
399
|
for (let e = 0; e < E; e++) h.current[e] += (n - h.current[e]) * .16;
|
|
400
|
-
|
|
400
|
+
u(h.current, r), m.current = requestAnimationFrame(d);
|
|
401
401
|
};
|
|
402
|
-
return m.current = requestAnimationFrame(
|
|
402
|
+
return m.current = requestAnimationFrame(d), () => cancelAnimationFrame(m.current);
|
|
403
403
|
}, [e, i]);
|
|
404
404
|
let C = i * .055, w = i * .035, T = i * .03, j = i * .55, M = i * .06, N = {
|
|
405
405
|
width: i,
|
|
@@ -412,7 +412,7 @@ function j({ state: e, volume: n, size: i, className: o, style: s, disabled: c =
|
|
|
412
412
|
}, P = /* @__PURE__ */ a("span", {
|
|
413
413
|
ref: p,
|
|
414
414
|
onMouseEnter: () => {
|
|
415
|
-
c || (_.current = !0, p.current && (p.current.style.filter = "brightness(1.35)"));
|
|
415
|
+
!l || c || (_.current = !0, p.current && (p.current.style.filter = "brightness(1.35)"));
|
|
416
416
|
},
|
|
417
417
|
onMouseLeave: () => {
|
|
418
418
|
_.current = !1, p.current && (p.current.style.filter = "brightness(1)");
|
|
@@ -471,48 +471,293 @@ function j({ state: e, volume: n, size: i, className: o, style: s, disabled: c =
|
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
473
|
//#endregion
|
|
474
|
+
//#region src/themes/cloud/CloudTheme.tsx
|
|
475
|
+
var M = typeof window < "u" ? n : t, N = "\nattribute vec2 a_position;\n\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n}\n", P = "\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_activity;\n\nfloat hash(vec2 p) {\n p = fract(p * vec2(123.34, 456.21));\n p += dot(p, p + 45.32);\n return fract(p.x * p.y);\n}\n\nfloat noise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n\n return mix(\n mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),\n mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\n\nfloat fbm(vec2 p) {\n float value = 0.0;\n float amplitude = 0.52;\n mat2 rotation = mat2(0.80, 0.60, -0.60, 0.80);\n\n for (int octave = 0; octave < 5; octave++) {\n value += amplitude * noise(p);\n p = rotation * p * 1.92 + vec2(9.7, 4.3);\n amplitude *= 0.5;\n }\n\n return value;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution;\n vec2 centered = uv - 0.5;\n float radius = length(centered);\n float edge = 1.0 - smoothstep(0.488, 0.5, radius);\n\n if (edge <= 0.0) discard;\n\n vec2 p = centered * 2.0;\n float t = u_time;\n\n vec2 warp = vec2(\n fbm(p * 1.02 + vec2(t * 0.34, -t * 0.24)),\n fbm(p * 1.08 + vec2(-t * 0.27, t * 0.32) + vec2(6.7, 2.9))\n );\n vec2 curl = vec2(\n sin(p.y * 2.4 + t * 0.68 + warp.y * 3.2),\n cos(p.x * 2.1 - t * 0.61 + warp.x * 3.0)\n );\n vec2 warped =\n p +\n (warp - 0.5) * (1.18 + u_activity * 0.38) +\n curl * (0.035 + u_activity * 0.07);\n float broad = fbm(warped * 0.92 + vec2(t * 0.14, -t * 0.18));\n float folded = fbm(warped * 1.66 + vec2(-t * 0.23, t * 0.19) + 5.2);\n float field = mix(broad, folded, 0.3 + u_activity * 0.14);\n\n float horizon =\n 0.46 +\n 0.08 * sin((uv.x + warp.x * 0.2) * 5.4 + t * 0.42) +\n 0.16 * (broad - 0.5);\n float upper = smoothstep(horizon - 0.12, horizon + 0.08, uv.y);\n float band = exp(-pow((uv.y - horizon) * (5.2 + u_activity * 0.8), 2.0));\n float cloud = smoothstep(0.24, 0.79, field);\n\n vec3 deepPeriwinkle = vec3(0.36, 0.39, 0.985);\n vec3 upperPeriwinkle = vec3(0.48, 0.56, 0.985);\n vec3 lowerLavender = vec3(0.72, 0.78, 0.975);\n vec3 milk = vec3(0.89, 0.92, 0.995);\n\n vec3 color = mix(lowerLavender, upperPeriwinkle, upper);\n float upperDepth = upper * (0.14 + smoothstep(0.42, 0.78, folded) * 0.5);\n color = mix(color, deepPeriwinkle, upperDepth);\n\n float milkAmount = clamp(band * (0.42 + cloud * 0.62), 0.0, 0.88);\n color = mix(color, milk, milkAmount);\n\n float lowerMist = (1.0 - upper) * smoothstep(0.58, 0.9, broad) * 0.18;\n color = mix(color, milk, lowerMist);\n\n float grain = (noise(gl_FragCoord.xy * 0.64) - 0.5) / 255.0;\n color += grain;\n\n gl_FragColor = vec4(color, edge);\n}\n", F = .55, I = .204, L = .2145, R = .063, z = "#5659dc", B = 1.178, V = 180, H = 300, U = 1350, W = 246, G = 420, K = 354, ee = 480;
|
|
476
|
+
function q(e, t = 0, n = 1) {
|
|
477
|
+
return Math.min(n, Math.max(t, e));
|
|
478
|
+
}
|
|
479
|
+
function J(e, t, n, r) {
|
|
480
|
+
return e + (t - e) * (1 - Math.exp(-n * r));
|
|
481
|
+
}
|
|
482
|
+
function te(e) {
|
|
483
|
+
return 1 - (1 - e) ** 3;
|
|
484
|
+
}
|
|
485
|
+
function Y(e, t, n) {
|
|
486
|
+
return e + (t - e) * n;
|
|
487
|
+
}
|
|
488
|
+
function X(e, t, n) {
|
|
489
|
+
let r = q((e - t) / (n - t));
|
|
490
|
+
return r * r * (3 - 2 * r);
|
|
491
|
+
}
|
|
492
|
+
function Z(e) {
|
|
493
|
+
return e === "listening" || e === "speaking" || e === "thinking";
|
|
494
|
+
}
|
|
495
|
+
function Q(e, t, n) {
|
|
496
|
+
let r = e.createShader(t);
|
|
497
|
+
if (r) {
|
|
498
|
+
if (e.shaderSource(r, n), e.compileShader(r), !e.getShaderParameter(r, e.COMPILE_STATUS)) {
|
|
499
|
+
e.deleteShader(r);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
return r;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function ne(e, t) {
|
|
506
|
+
let n = e.getContext("webgl", {
|
|
507
|
+
alpha: !0,
|
|
508
|
+
antialias: !0,
|
|
509
|
+
premultipliedAlpha: !0
|
|
510
|
+
});
|
|
511
|
+
if (!n) return;
|
|
512
|
+
let r = Q(n, n.VERTEX_SHADER, N), i = Q(n, n.FRAGMENT_SHADER, P);
|
|
513
|
+
if (!r || !i) {
|
|
514
|
+
r && n.deleteShader(r), i && n.deleteShader(i);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
let a = n.createProgram(), o = n.createBuffer();
|
|
518
|
+
if (!a || !o) {
|
|
519
|
+
a && n.deleteProgram(a), o && n.deleteBuffer(o), n.deleteShader(r), n.deleteShader(i);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (n.attachShader(a, r), n.attachShader(a, i), n.linkProgram(a), !n.getProgramParameter(a, n.LINK_STATUS)) {
|
|
523
|
+
n.deleteProgram(a), n.deleteBuffer(o), n.deleteShader(r), n.deleteShader(i);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
let s = n.getAttribLocation(a, "a_position"), c = n.getUniformLocation(a, "u_resolution"), l = n.getUniformLocation(a, "u_time"), u = n.getUniformLocation(a, "u_activity");
|
|
527
|
+
if (s < 0 || !c || !l || !u) {
|
|
528
|
+
n.deleteProgram(a), n.deleteBuffer(o), n.deleteShader(r), n.deleteShader(i);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
let d = Math.min(window.devicePixelRatio || 1, 2), f = Math.max(1, Math.round(t * d));
|
|
532
|
+
return e.width = f, e.height = f, n.viewport(0, 0, f, f), n.useProgram(a), n.bindBuffer(n.ARRAY_BUFFER, o), n.bufferData(n.ARRAY_BUFFER, new Float32Array([
|
|
533
|
+
-1,
|
|
534
|
+
-1,
|
|
535
|
+
1,
|
|
536
|
+
-1,
|
|
537
|
+
-1,
|
|
538
|
+
1,
|
|
539
|
+
-1,
|
|
540
|
+
1,
|
|
541
|
+
1,
|
|
542
|
+
-1,
|
|
543
|
+
1,
|
|
544
|
+
1
|
|
545
|
+
]), n.STATIC_DRAW), n.enableVertexAttribArray(s), n.vertexAttribPointer(s, 2, n.FLOAT, !1, 0, 0), n.uniform2f(c, f, f), {
|
|
546
|
+
draw(e, t) {
|
|
547
|
+
n.uniform1f(l, e), n.uniform1f(u, t), n.drawArrays(n.TRIANGLES, 0, 6);
|
|
548
|
+
},
|
|
549
|
+
destroy() {
|
|
550
|
+
n.deleteProgram(a), n.deleteBuffer(o), n.deleteShader(r), n.deleteShader(i);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function re(e) {
|
|
555
|
+
if (e <= V) return R;
|
|
556
|
+
if (e <= 480) return Y(R, B, te((e - V) / H));
|
|
557
|
+
let t = e - V - H;
|
|
558
|
+
if (t >= U) return 1;
|
|
559
|
+
let n = q(t / U);
|
|
560
|
+
return 1 + (B - 1) * (1 - n) ** 2;
|
|
561
|
+
}
|
|
562
|
+
function ie({ state: e, volume: n, size: i, className: s, style: c, disabled: l = !1, interactive: u = !1, onClick: d, ...f }) {
|
|
563
|
+
let p = r(null), m = r(null), h = r(null), g = r(e), _ = r(n), v = r(u), y = r(!1);
|
|
564
|
+
M(() => {
|
|
565
|
+
g.current = e, _.current = n, v.current = u;
|
|
566
|
+
}, [
|
|
567
|
+
u,
|
|
568
|
+
e,
|
|
569
|
+
n
|
|
570
|
+
]);
|
|
571
|
+
let b = i * F;
|
|
572
|
+
t(() => {
|
|
573
|
+
let e = p.current, t = m.current, n = h.current;
|
|
574
|
+
if (!e || !t || !n) return;
|
|
575
|
+
let r = window.matchMedia("(prefers-reduced-motion: reduce)"), i = () => {
|
|
576
|
+
y.current = r.matches;
|
|
577
|
+
};
|
|
578
|
+
i(), r.addEventListener("change", i);
|
|
579
|
+
let a = ne(e, b);
|
|
580
|
+
a || (e.style.background = "linear-gradient(180deg, #626afb 2%, #8f9dfb 32%, #dde6fd 52%, #c9d3fb 84%)");
|
|
581
|
+
let o = 0, s = performance.now(), c = g.current, l = Z(c) ? s : void 0, u = q(_.current), d = 1, f = +!!Z(c), x = 1, S = +(c === "connecting"), C = 0, w = (r) => {
|
|
582
|
+
let i = Math.min((r - s) / 1e3, .05);
|
|
583
|
+
s = r;
|
|
584
|
+
let p = g.current, m = y.current;
|
|
585
|
+
p !== c && (Z(p) && !Z(c) && (l = r), (p === "idle" || p === "error") && (l = void 0), c = p);
|
|
586
|
+
let h = q(_.current);
|
|
587
|
+
u = m ? 0 : J(u, h, h > u ? 11 : 6, i);
|
|
588
|
+
let b = 1;
|
|
589
|
+
p === "listening" && (b = 1 - u * I), p === "speaking" && (b = 1 + u * L);
|
|
590
|
+
let T = Math.abs(b - 1) > Math.abs(d - 1) ? 12 : 6;
|
|
591
|
+
d = m ? 1 : J(d, b, T, i);
|
|
592
|
+
let E = Z(p), D = p === "idle" && v.current, O = E || D ? 1 : 0;
|
|
593
|
+
f = m ? O : J(f, O, 14, i);
|
|
594
|
+
let k = E || D ? 1 : .92;
|
|
595
|
+
x = m ? k : J(x, k, 12, i);
|
|
596
|
+
let A = d * x;
|
|
597
|
+
D && (A = R);
|
|
598
|
+
let j = +!D, M = D ? f : 0;
|
|
599
|
+
if (E && l !== void 0 && !m) {
|
|
600
|
+
let e = r - l, t = re(e), n = q((e - V - H) / U);
|
|
601
|
+
A = t * Y(1, d, n), j = X(e, W, G), M = f * (1 - X(e, K, ee)), e >= 1830 && (l = void 0);
|
|
602
|
+
}
|
|
603
|
+
let N = +(p === "connecting");
|
|
604
|
+
S = m ? N : J(S, N, 18, i), e.style.opacity = String(f * j), e.style.transform = `scale(${A})`, t.style.opacity = String(M), t.style.transform = `scale(${A})`, n.style.opacity = String(S), n.style.transform = `rotate(${m ? 45 : r * .34}deg)`;
|
|
605
|
+
let P = .24, F = .1;
|
|
606
|
+
p === "listening" ? (P = .72 + u * .78, F = .28 + u * .32) : p === "speaking" && (P = 1.65 + u * 1.55, F = .66 + u * .34), m || (C += i * P), a?.draw(C, F), o = requestAnimationFrame(w);
|
|
607
|
+
};
|
|
608
|
+
return o = requestAnimationFrame(w), () => {
|
|
609
|
+
cancelAnimationFrame(o), r.removeEventListener("change", i), a?.destroy();
|
|
610
|
+
};
|
|
611
|
+
}, [b]);
|
|
612
|
+
let x = {
|
|
613
|
+
width: i,
|
|
614
|
+
height: i,
|
|
615
|
+
display: "flex",
|
|
616
|
+
alignItems: "center",
|
|
617
|
+
justifyContent: "center",
|
|
618
|
+
position: "relative",
|
|
619
|
+
...c
|
|
620
|
+
}, S = /* @__PURE__ */ o("span", {
|
|
621
|
+
style: {
|
|
622
|
+
position: "relative",
|
|
623
|
+
display: "block",
|
|
624
|
+
width: b,
|
|
625
|
+
height: b,
|
|
626
|
+
borderRadius: "50%",
|
|
627
|
+
lineHeight: 0,
|
|
628
|
+
cursor: u ? l ? "not-allowed" : "pointer" : "default"
|
|
629
|
+
},
|
|
630
|
+
children: [
|
|
631
|
+
/* @__PURE__ */ a("span", {
|
|
632
|
+
ref: m,
|
|
633
|
+
"data-cloud-launch-dot": "",
|
|
634
|
+
"aria-hidden": "true",
|
|
635
|
+
style: {
|
|
636
|
+
position: "absolute",
|
|
637
|
+
inset: 0,
|
|
638
|
+
display: "block",
|
|
639
|
+
borderRadius: "50%",
|
|
640
|
+
background: z,
|
|
641
|
+
opacity: 0,
|
|
642
|
+
transform: `scale(${R})`,
|
|
643
|
+
transformOrigin: "center",
|
|
644
|
+
willChange: "opacity, transform"
|
|
645
|
+
}
|
|
646
|
+
}),
|
|
647
|
+
/* @__PURE__ */ a("canvas", {
|
|
648
|
+
ref: p,
|
|
649
|
+
"aria-hidden": "true",
|
|
650
|
+
style: {
|
|
651
|
+
position: "absolute",
|
|
652
|
+
inset: 0,
|
|
653
|
+
display: "block",
|
|
654
|
+
width: b,
|
|
655
|
+
height: b,
|
|
656
|
+
borderRadius: "50%",
|
|
657
|
+
opacity: 0,
|
|
658
|
+
transform: `scale(${R})`,
|
|
659
|
+
transformOrigin: "center",
|
|
660
|
+
willChange: "opacity, transform"
|
|
661
|
+
}
|
|
662
|
+
}),
|
|
663
|
+
/* @__PURE__ */ a("span", {
|
|
664
|
+
ref: h,
|
|
665
|
+
"aria-hidden": "true",
|
|
666
|
+
style: {
|
|
667
|
+
position: "absolute",
|
|
668
|
+
left: "50%",
|
|
669
|
+
top: "50%",
|
|
670
|
+
width: b * .105,
|
|
671
|
+
height: b * .105,
|
|
672
|
+
boxSizing: "border-box",
|
|
673
|
+
border: `${Math.max(1.5, b * .012)}px solid rgba(113, 120, 245, 0.24)`,
|
|
674
|
+
borderTopColor: "#777ff6",
|
|
675
|
+
borderRightColor: "#777ff6",
|
|
676
|
+
borderRadius: "50%",
|
|
677
|
+
opacity: 0,
|
|
678
|
+
transform: "rotate(0deg)",
|
|
679
|
+
transformOrigin: "center",
|
|
680
|
+
marginLeft: b * -.0525,
|
|
681
|
+
marginTop: b * -.0525,
|
|
682
|
+
willChange: "opacity, transform"
|
|
683
|
+
}
|
|
684
|
+
})
|
|
685
|
+
]
|
|
686
|
+
});
|
|
687
|
+
return u ? /* @__PURE__ */ a("button", {
|
|
688
|
+
...f,
|
|
689
|
+
type: "button",
|
|
690
|
+
className: s,
|
|
691
|
+
disabled: l,
|
|
692
|
+
onClick: l ? void 0 : d,
|
|
693
|
+
style: {
|
|
694
|
+
appearance: "none",
|
|
695
|
+
WebkitAppearance: "none",
|
|
696
|
+
border: 0,
|
|
697
|
+
padding: 0,
|
|
698
|
+
margin: 0,
|
|
699
|
+
background: "transparent",
|
|
700
|
+
color: "inherit",
|
|
701
|
+
font: "inherit",
|
|
702
|
+
cursor: l ? "not-allowed" : "pointer",
|
|
703
|
+
...x
|
|
704
|
+
},
|
|
705
|
+
children: S
|
|
706
|
+
}) : /* @__PURE__ */ a("div", {
|
|
707
|
+
...f,
|
|
708
|
+
className: s,
|
|
709
|
+
style: x,
|
|
710
|
+
children: S
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
//#endregion
|
|
474
714
|
//#region src/components/Orb/Orb.tsx
|
|
475
|
-
function
|
|
476
|
-
let [
|
|
715
|
+
function $({ signal: n, state: r, volume: o, adapter: l, theme: u = "debug", size: f = 200, className: p, style: m, disabled: h = !1, interactive: g = !0, onStart: _, onStop: v, ...y }) {
|
|
716
|
+
let [b, x] = i({ state: "idle" });
|
|
477
717
|
t(() => {
|
|
478
|
-
if (
|
|
718
|
+
if (x({ state: "idle" }), l) return l.subscribe(x);
|
|
479
719
|
}, [l]);
|
|
480
|
-
let
|
|
481
|
-
h || (
|
|
720
|
+
let S = n ?? b, C = s(r, n, b), w = c(o, C, S), E = C !== "idle" && C !== "error", D = e(() => {
|
|
721
|
+
h || (E ? v ? v() : l?.stop?.() : _ ? _() : l?.start?.());
|
|
482
722
|
}, [
|
|
483
723
|
l,
|
|
484
724
|
h,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
]),
|
|
489
|
-
state:
|
|
490
|
-
volume:
|
|
725
|
+
E,
|
|
726
|
+
_,
|
|
727
|
+
v
|
|
728
|
+
]), O = E ? !!(l?.stop || v) : !!(l?.start || _), k = g && O, A = k && !h ? D : void 0, M = {
|
|
729
|
+
state: C,
|
|
730
|
+
volume: w,
|
|
491
731
|
size: f,
|
|
492
732
|
className: p,
|
|
493
733
|
style: m,
|
|
494
734
|
disabled: h,
|
|
495
|
-
...
|
|
496
|
-
"aria-label":
|
|
497
|
-
},
|
|
498
|
-
...
|
|
499
|
-
interactive:
|
|
735
|
+
...y,
|
|
736
|
+
"aria-label": y["aria-label"] ?? (k ? `${E ? "Stop" : "Start"} voice session` : void 0)
|
|
737
|
+
}, N = {
|
|
738
|
+
...M,
|
|
739
|
+
interactive: k
|
|
500
740
|
};
|
|
501
741
|
switch (u) {
|
|
502
742
|
case "circle": return /* @__PURE__ */ a(T, {
|
|
503
|
-
...
|
|
504
|
-
onClick:
|
|
743
|
+
...N,
|
|
744
|
+
onClick: A
|
|
505
745
|
});
|
|
506
746
|
case "bars": return /* @__PURE__ */ a(j, {
|
|
507
|
-
...
|
|
508
|
-
onClick:
|
|
747
|
+
...N,
|
|
748
|
+
onClick: A
|
|
749
|
+
});
|
|
750
|
+
case "cloud": return /* @__PURE__ */ a(ie, {
|
|
751
|
+
...N,
|
|
752
|
+
onClick: A
|
|
509
753
|
});
|
|
510
754
|
default: return /* @__PURE__ */ a(d, {
|
|
511
|
-
...
|
|
512
|
-
|
|
513
|
-
|
|
755
|
+
...M,
|
|
756
|
+
disabled: h || !g,
|
|
757
|
+
onStart: h || !g ? void 0 : _ ?? (() => l?.start?.()),
|
|
758
|
+
onStop: h || !g ? void 0 : v ?? (() => l?.stop?.())
|
|
514
759
|
});
|
|
515
760
|
}
|
|
516
761
|
}
|
|
517
762
|
//#endregion
|
|
518
|
-
export {
|
|
763
|
+
export { $ as Orb, $ as VoiceOrb };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { OrbHtmlAttributes, OrbState } from '../../components/Orb/Orb.types.js';
|
|
3
|
+
interface CloudThemeProps extends OrbHtmlAttributes {
|
|
4
|
+
state: OrbState;
|
|
5
|
+
volume: number;
|
|
6
|
+
size: number;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
interactive?: boolean;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function CloudTheme({ state, volume, size, className, style, disabled, interactive, onClick, ...controlProps }: CloudThemeProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CloudTheme } from './CloudTheme.js';
|
package/dist/themes/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orb-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "React voice agent UI components with audio-reactive adapters for Vapi, ElevenLabs, LiveKit, Pipecat, OpenAI Realtime, Gemini Live, and custom voice AI apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/orb-ui.cjs",
|
package/dist/livekit-Dasur3lv.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
//#region src/adapters/types.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
let t = Math.min(e / .5, 1);
|
|
4
|
-
return t **= 1.3, t;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/adapters/livekit/index.ts
|
|
8
|
-
var t = 4, n = .03, r = 1.5, i = .6, a = .2, o = .35;
|
|
9
|
-
function s(e) {
|
|
10
|
-
switch (e) {
|
|
11
|
-
case "speaking": return "speaking";
|
|
12
|
-
case "thinking": return "thinking";
|
|
13
|
-
case "listening":
|
|
14
|
-
case "idle": return "listening";
|
|
15
|
-
case "connecting":
|
|
16
|
-
case "pre-connect-buffering":
|
|
17
|
-
case "initializing": return "connecting";
|
|
18
|
-
case "disconnected": return "idle";
|
|
19
|
-
case "failed": return "error";
|
|
20
|
-
default: return "idle";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function c(e) {
|
|
24
|
-
return "RoomClass" in e;
|
|
25
|
-
}
|
|
26
|
-
function l(e) {
|
|
27
|
-
return typeof e == "function" ? e() : e;
|
|
28
|
-
}
|
|
29
|
-
function u(e) {
|
|
30
|
-
if (!e) return {};
|
|
31
|
-
let t = {}, n = (e, n) => {
|
|
32
|
-
n !== void 0 && (t[e] = n);
|
|
33
|
-
};
|
|
34
|
-
return n("roomName", l(e.roomName)), n("participantName", l(e.participantName)), n("participantIdentity", l(e.participantIdentity)), n("participantMetadata", l(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", l(e.agentName)), n("agentMetadata", l(e.agentMetadata)), n("deployment", l(e.deployment)), t;
|
|
35
|
-
}
|
|
36
|
-
function d(e) {
|
|
37
|
-
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
38
|
-
return e;
|
|
39
|
-
}
|
|
40
|
-
async function f(e) {
|
|
41
|
-
let t = u(e.tokenOptions);
|
|
42
|
-
return typeof e.getConnectionDetails == "function" ? d(await e.getConnectionDetails(t)) : e.tokenSource ? d(await e.tokenSource.fetch(t)) : d({
|
|
43
|
-
serverUrl: e.serverUrl,
|
|
44
|
-
participantToken: e.participantToken
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function p(e) {
|
|
48
|
-
for (let [, n] of e.remoteParticipants) if (!n.isLocal && (n.kind === t || n.attributes?.["lk.agent.state"] !== void 0)) return n;
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
function m(e, t, n) {
|
|
52
|
-
let r = e.off;
|
|
53
|
-
if (r) {
|
|
54
|
-
r.call(e, t, n);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
e.removeListener?.call(e, t, n);
|
|
58
|
-
}
|
|
59
|
-
function h(e, t, n) {
|
|
60
|
-
e.on.call(e, t, n);
|
|
61
|
-
}
|
|
62
|
-
function g(l) {
|
|
63
|
-
let u = c(l), d = l.createAudioAnalyser, g = { current: u ? null : l.room }, _ = /* @__PURE__ */ new Set(), v = {
|
|
64
|
-
state: "idle",
|
|
65
|
-
volume: 0,
|
|
66
|
-
inputVolume: 0,
|
|
67
|
-
outputVolume: 0
|
|
68
|
-
}, y = "idle", b = null, x = null, S = null, C = null, w = null, T = null, E = null, D = 0, O = null;
|
|
69
|
-
function k(e) {
|
|
70
|
-
v = e, _.forEach((t) => t(e));
|
|
71
|
-
}
|
|
72
|
-
function A(e) {
|
|
73
|
-
k({
|
|
74
|
-
...v,
|
|
75
|
-
...e,
|
|
76
|
-
state: e.state ?? v.state
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function j(e) {
|
|
80
|
-
let t = e < n ? 0 : e, s = t > D ? i : a;
|
|
81
|
-
D += (t - D) * s;
|
|
82
|
-
let c = Math.min(D * r, 1);
|
|
83
|
-
return c / (c + o);
|
|
84
|
-
}
|
|
85
|
-
function M() {
|
|
86
|
-
D = 0, A({
|
|
87
|
-
volume: 0,
|
|
88
|
-
outputVolume: 0
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function N({ emitZero: e = !0 } = {}) {
|
|
92
|
-
w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), e && A({
|
|
93
|
-
volume: 0,
|
|
94
|
-
inputVolume: 0
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function P(t) {
|
|
98
|
-
if (!(b === t && C)) {
|
|
99
|
-
N({ emitZero: !1 }), b = t;
|
|
100
|
-
try {
|
|
101
|
-
C = d(t);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
w = setInterval(() => {
|
|
107
|
-
if (!C || y !== "listening") return;
|
|
108
|
-
let t = e(C.calculateVolume());
|
|
109
|
-
A({
|
|
110
|
-
volume: t,
|
|
111
|
-
inputVolume: t,
|
|
112
|
-
outputVolume: 0
|
|
113
|
-
});
|
|
114
|
-
}, 33);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function F({ emitZero: e = !0 } = {}) {
|
|
118
|
-
E &&= (clearInterval(E), null), T &&= (T.cleanup().catch(() => {}), null), D = 0, e && A({
|
|
119
|
-
volume: 0,
|
|
120
|
-
outputVolume: 0
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function I(e) {
|
|
124
|
-
F();
|
|
125
|
-
try {
|
|
126
|
-
T = d(e);
|
|
127
|
-
} catch (e) {
|
|
128
|
-
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
E = setInterval(() => {
|
|
132
|
-
if (!T || y !== "speaking") return;
|
|
133
|
-
let e = j(T.calculateVolume());
|
|
134
|
-
A({
|
|
135
|
-
volume: e,
|
|
136
|
-
inputVolume: 0,
|
|
137
|
-
outputVolume: e
|
|
138
|
-
});
|
|
139
|
-
}, 33);
|
|
140
|
-
}
|
|
141
|
-
function L(e) {
|
|
142
|
-
y = e, A({
|
|
143
|
-
state: e,
|
|
144
|
-
volume: 0,
|
|
145
|
-
inputVolume: 0,
|
|
146
|
-
outputVolume: 0
|
|
147
|
-
}), e === "speaking" && x ? I(x) : e !== "speaking" && F({ emitZero: !1 });
|
|
148
|
-
}
|
|
149
|
-
function R(e) {
|
|
150
|
-
S || typeof document > "u" || (S = e.attach(), S.id = "orb-ui-livekit-agent-audio", document.body.appendChild(S));
|
|
151
|
-
}
|
|
152
|
-
function z() {
|
|
153
|
-
S &&= (S.remove(), null);
|
|
154
|
-
}
|
|
155
|
-
function B(e) {
|
|
156
|
-
x = e, R(e), y === "speaking" && I(e);
|
|
157
|
-
}
|
|
158
|
-
function V(e) {
|
|
159
|
-
P(e);
|
|
160
|
-
}
|
|
161
|
-
function H(e) {
|
|
162
|
-
let t = e.getTrackPublication?.("microphone");
|
|
163
|
-
t?.track && V(t.track);
|
|
164
|
-
}
|
|
165
|
-
function U(e) {
|
|
166
|
-
let t = s(e);
|
|
167
|
-
t !== y && L(t);
|
|
168
|
-
}
|
|
169
|
-
function W(e) {
|
|
170
|
-
let t = e.attributes?.["lk.agent.state"];
|
|
171
|
-
t && U(t);
|
|
172
|
-
let n = e.getTrackPublication("microphone");
|
|
173
|
-
n?.track && B(n.track);
|
|
174
|
-
}
|
|
175
|
-
function G(e) {
|
|
176
|
-
if (O) return;
|
|
177
|
-
let n = (e, t) => {
|
|
178
|
-
if (t.isLocal) return;
|
|
179
|
-
let n = e["lk.agent.state"];
|
|
180
|
-
n && U(n);
|
|
181
|
-
}, r = (e, n, r) => {
|
|
182
|
-
r.isLocal || !(r.kind === t || r.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || B(e);
|
|
183
|
-
}, i = (e) => {
|
|
184
|
-
x === e && (x = null, z(), F());
|
|
185
|
-
}, a = (e) => {
|
|
186
|
-
e.source !== "microphone" || !e.track || V(e.track);
|
|
187
|
-
}, o = (e) => {
|
|
188
|
-
e.source === "microphone" && (b = null, N());
|
|
189
|
-
}, s = () => {
|
|
190
|
-
b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), L("idle");
|
|
191
|
-
};
|
|
192
|
-
if (h(e, "participantAttributesChanged", n), h(e, "trackSubscribed", r), h(e, "trackUnsubscribed", i), h(e, "localTrackPublished", a), h(e, "localTrackUnpublished", o), h(e, "disconnected", s), O = () => {
|
|
193
|
-
m(e, "participantAttributesChanged", n), m(e, "trackSubscribed", r), m(e, "trackUnsubscribed", i), m(e, "localTrackPublished", a), m(e, "localTrackUnpublished", o), m(e, "disconnected", s);
|
|
194
|
-
}, H(e.localParticipant), e.state === "connected") {
|
|
195
|
-
let t = p(e);
|
|
196
|
-
t ? W(t) : L("connecting");
|
|
197
|
-
} else L("idle");
|
|
198
|
-
}
|
|
199
|
-
function K() {
|
|
200
|
-
O?.(), O = null, b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), A({
|
|
201
|
-
volume: 0,
|
|
202
|
-
inputVolume: 0,
|
|
203
|
-
outputVolume: 0
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
let q = (e) => {
|
|
207
|
-
_.add(e), e(v);
|
|
208
|
-
let t = g.current;
|
|
209
|
-
return t && G(t), () => {
|
|
210
|
-
_.delete(e), _.size === 0 && K();
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
return u ? {
|
|
214
|
-
subscribe: q,
|
|
215
|
-
async start() {
|
|
216
|
-
if (g.current) return;
|
|
217
|
-
let e = l, t = new e.RoomClass();
|
|
218
|
-
L("connecting");
|
|
219
|
-
try {
|
|
220
|
-
let n = await f(e);
|
|
221
|
-
if (await t.connect(n.serverUrl, n.participantToken, e.connectOptions), g.current = t, G(t), e.enableMicrophone !== !1) {
|
|
222
|
-
let e = (await t.localParticipant.setMicrophoneEnabled(!0))?.track ?? t.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
223
|
-
e && V(e);
|
|
224
|
-
}
|
|
225
|
-
} catch (e) {
|
|
226
|
-
throw console.error("[orb-ui/livekit] connect failed:", e), g.current === t && K(), t.disconnect(), g.current = null, L("error"), M(), A({ error: e }), e;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
async stop() {
|
|
230
|
-
let e = g.current;
|
|
231
|
-
if (!e) {
|
|
232
|
-
L("idle");
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
K(), e.disconnect(), g.current = null, L("idle");
|
|
236
|
-
}
|
|
237
|
-
} : { subscribe: q };
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
export { g as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t=4,n=.03,r=1.5,i=.6,a=.2,o=.35;function s(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function c(e){return`RoomClass`in e}function l(e){return typeof e==`function`?e():e}function u(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,l(e.roomName)),n(`participantName`,l(e.participantName)),n(`participantIdentity`,l(e.participantIdentity)),n(`participantMetadata`,l(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,l(e.agentName)),n(`agentMetadata`,l(e.agentMetadata)),n(`deployment`,l(e.deployment)),t}function d(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function f(e){let t=u(e.tokenOptions);return typeof e.getConnectionDetails==`function`?d(await e.getConnectionDetails(t)):e.tokenSource?d(await e.tokenSource.fetch(t)):d({serverUrl:e.serverUrl,participantToken:e.participantToken})}function p(e){for(let[,n]of e.remoteParticipants)if(!n.isLocal&&(n.kind===t||n.attributes?.[`lk.agent.state`]!==void 0))return n;return null}function m(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function h(e,t,n){e.on.call(e,t,n)}function g(l){let u=c(l),d=l.createAudioAnalyser,g={current:u?null:l.room},_=new Set,v={state:`idle`,volume:0,inputVolume:0,outputVolume:0},y=`idle`,b=null,x=null,S=null,C=null,w=null,T=null,E=null,D=0,O=null;function k(e){v=e,_.forEach(t=>t(e))}function A(e){k({...v,...e,state:e.state??v.state})}function j(e){let t=e<n?0:e,s=t>D?i:a;D+=(t-D)*s;let c=Math.min(D*r,1);return c/(c+o)}function M(){D=0,A({volume:0,outputVolume:0})}function N({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),e&&A({volume:0,inputVolume:0})}function P(t){if(!(b===t&&C)){N({emitZero:!1}),b=t;try{C=d(t)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||y!==`listening`)return;let t=e(C.calculateVolume());A({volume:t,inputVolume:t,outputVolume:0})},33)}}function F({emitZero:e=!0}={}){E&&=(clearInterval(E),null),T&&=(T.cleanup().catch(()=>{}),null),D=0,e&&A({volume:0,outputVolume:0})}function I(e){F();try{T=d(e)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}E=setInterval(()=>{if(!T||y!==`speaking`)return;let e=j(T.calculateVolume());A({volume:e,inputVolume:0,outputVolume:e})},33)}function L(e){y=e,A({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&x?I(x):e!==`speaking`&&F({emitZero:!1})}function R(e){S||typeof document>`u`||(S=e.attach(),S.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(S))}function z(){S&&=(S.remove(),null)}function B(e){x=e,R(e),y===`speaking`&&I(e)}function V(e){P(e)}function H(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&V(t.track)}function U(e){let t=s(e);t!==y&&L(t)}function W(e){let t=e.attributes?.[`lk.agent.state`];t&&U(t);let n=e.getTrackPublication(`microphone`);n?.track&&B(n.track)}function G(e){if(O)return;let n=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&U(n)},r=(e,n,r)=>{r.isLocal||!(r.kind===t||r.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||B(e)},i=e=>{x===e&&(x=null,z(),F())},a=e=>{e.source!==`microphone`||!e.track||V(e.track)},o=e=>{e.source===`microphone`&&(b=null,N())},s=()=>{b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),L(`idle`)};if(h(e,`participantAttributesChanged`,n),h(e,`trackSubscribed`,r),h(e,`trackUnsubscribed`,i),h(e,`localTrackPublished`,a),h(e,`localTrackUnpublished`,o),h(e,`disconnected`,s),O=()=>{m(e,`participantAttributesChanged`,n),m(e,`trackSubscribed`,r),m(e,`trackUnsubscribed`,i),m(e,`localTrackPublished`,a),m(e,`localTrackUnpublished`,o),m(e,`disconnected`,s)},H(e.localParticipant),e.state===`connected`){let t=p(e);t?W(t):L(`connecting`)}else L(`idle`)}function K(){O?.(),O=null,b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),A({volume:0,inputVolume:0,outputVolume:0})}let q=e=>{_.add(e),e(v);let t=g.current;return t&&G(t),()=>{_.delete(e),_.size===0&&K()}};return u?{subscribe:q,async start(){if(g.current)return;let e=l,t=new e.RoomClass;L(`connecting`);try{let n=await f(e);if(await t.connect(n.serverUrl,n.participantToken,e.connectOptions),g.current=t,G(t),e.enableMicrophone!==!1){let e=(await t.localParticipant.setMicrophoneEnabled(!0))?.track??t.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&V(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),g.current===t&&K(),t.disconnect(),g.current=null,L(`error`),M(),A({error:e}),e}},async stop(){let e=g.current;if(!e){L(`idle`);return}K(),e.disconnect(),g.current=null,L(`idle`)}}:{subscribe:q}}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return g}});
|