@navai/voice-frontend 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import {
2
+ Orb
3
+ } from "./chunk-KBBRQQLK.js";
4
+ export {
5
+ Orb as default
6
+ };
@@ -0,0 +1,531 @@
1
+ // src/orb/Orb.tsx
2
+ import { Mesh, Program, Renderer, Triangle, Vec3 } from "ogl";
3
+ import { useEffect as useEffect2, useRef } from "react";
4
+
5
+ // src/orb/styles.ts
6
+ import { useEffect } from "react";
7
+ var NAVAI_VOICE_ORB_STYLE_ID = "navai-voice-orb-styles";
8
+ var NAVAI_VOICE_ORB_CSS = `
9
+ .navai-orb-container { position: relative; z-index: 0; width: 100%; height: 100%; }
10
+ .navai-voice-orb-dock { display: grid; justify-items: center; gap: 0.6rem; }
11
+ .navai-voice-orb-dock.is-bottom-right,
12
+ .navai-voice-orb-dock.is-bottom-left { position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 70; }
13
+ .navai-voice-orb-dock.is-bottom-right { right: calc(1rem + env(safe-area-inset-right)); }
14
+ .navai-voice-orb-dock.is-bottom-left { left: calc(1rem + env(safe-area-inset-left)); }
15
+ .navai-voice-orb-wrap { position: relative; width: clamp(4.2rem, 8vw, 5.5rem); aspect-ratio: 1 / 1; display: grid; place-items: center; }
16
+ .navai-voice-orb-surface { position: absolute; inset: 0; border-radius: 999px; overflow: hidden; transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease; }
17
+ .navai-voice-orb-surface::after { content: ""; position: absolute; inset: 10%; border-radius: inherit; background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.1), rgba(6,9,20,0)); pointer-events: none; }
18
+ .navai-voice-orb-surface.is-highlighted { transform: scale(1.03); filter: saturate(1.08); }
19
+ .navai-voice-orb-surface .navai-orb-container { border-radius: inherit; overflow: hidden; }
20
+ .navai-voice-orb-surface .navai-orb-container canvas { display: block; width: 100% !important; height: 100% !important; transform: scale(1.08); transform-origin: center; }
21
+ .navai-voice-orb-button-shell { position: relative; z-index: 1; display: grid; place-items: center; width: clamp(2.7rem, 5vw, 3.15rem); height: clamp(2.7rem, 5vw, 3.15rem); border-radius: 999px; border: 1px solid rgba(156,182,255,0.4); background: rgba(10,14,36,0.72); box-shadow: inset 0 0 24px rgba(8,12,31,0.28), 0 10px 22px rgba(4,8,24,0.42); backdrop-filter: blur(8px); }
22
+ .navai-voice-orb-button-shell.is-active { border-color: rgba(255,156,192,0.92); box-shadow: 0 0 0 2px rgba(255,112,160,0.18), inset 0 0 28px rgba(61,14,40,0.3), 0 12px 26px rgba(85,16,49,0.42); }
23
+ .navai-voice-orb-button { display: grid; place-items: center; width: clamp(2.05rem, 4vw, 2.4rem); height: clamp(2.05rem, 4vw, 2.4rem); border-radius: 999px; border: 1px solid rgba(162,193,255,0.58); background: linear-gradient(145deg, rgba(245,249,255,0.98), rgba(223,233,255,0.94)); color: #2154d9; box-shadow: 0 8px 18px rgba(14,26,61,0.34); cursor: pointer; transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease, border-color 160ms ease; }
24
+ .navai-voice-orb-button:hover:not(:disabled) { transform: translateY(-1px) scale(1.02); }
25
+ .navai-voice-orb-button:focus-visible { outline: 2px solid rgba(191,219,254,0.92); outline-offset: 3px; }
26
+ .navai-voice-orb-button.is-active { background: rgba(255,92,132,0.96); color: rgba(255,255,255,0.98); border-color: rgba(255,164,190,0.98); box-shadow: 0 0 0 3px rgba(255,108,154,0.24), 0 10px 24px rgba(96,14,39,0.42); }
27
+ .navai-voice-orb-button.is-connecting { background: linear-gradient(145deg, rgba(255,246,214,0.98), rgba(252,220,128,0.94)); color: #7c4300; border-color: rgba(251,191,36,0.9); }
28
+ .navai-voice-orb-button:disabled { opacity: 0.74; cursor: not-allowed; }
29
+ .navai-voice-orb-status { margin: 0; max-width: min(18rem, 80vw); padding: 0.45rem 0.6rem; border-radius: 0.7rem; border: 1px solid rgba(244,114,182,0.24); background: rgba(6,12,28,0.84); color: rgba(230,240,255,0.96); font-size: 0.74rem; line-height: 1.35; text-align: center; box-shadow: 0 10px 20px rgba(4,8,24,0.24); }
30
+ .navai-voice-orb-status.is-error { border-color: rgba(248,113,113,0.46); background: rgba(69,10,10,0.84); color: rgba(254,202,202,0.98); }
31
+ .navai-voice-orb-live { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
32
+ .navai-voice-orb-hero { width: min(32rem, 100%); aspect-ratio: 1 / 1; }
33
+ .navai-voice-orb-icon { display: block; }
34
+ .navai-voice-orb-icon.is-pulsing { animation: navai-voice-orb-pulse 1.05s ease-in-out infinite; }
35
+ .navai-voice-orb-spinner { display: block; box-sizing: border-box; border-radius: 999px; border: 2px solid currentColor; border-right-color: transparent; animation: navai-voice-orb-spin 0.72s linear infinite; }
36
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button-shell,
37
+ .navai-voice-orb-hero.is-light { color: #10245e; }
38
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button-shell { border-color: rgba(121,146,220,0.34); background: rgba(244,249,255,0.88); box-shadow: inset 0 0 20px rgba(111,134,183,0.14), 0 10px 22px rgba(86,104,149,0.22); }
39
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button-shell.is-active { border-color: rgba(255,142,188,0.82); box-shadow: 0 0 0 2px rgba(255,130,183,0.18), inset 0 0 24px rgba(255,141,191,0.2), 0 10px 24px rgba(141,81,110,0.24); }
40
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button { border-color: rgba(70,136,246,0.42); background: linear-gradient(145deg, rgba(255,255,255,0.98), rgba(228,238,255,0.95)); color: #1d3d9a; box-shadow: 0 8px 18px rgba(71,85,105,0.18); }
41
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button.is-connecting { background: linear-gradient(145deg, rgba(255,246,214,0.98), rgba(252,220,128,0.94)); color: #7c4300; border-color: rgba(251,191,36,0.9); }
42
+ .navai-voice-orb-dock.is-light .navai-voice-orb-button.is-active { background: rgba(255,92,132,0.96); color: rgba(255,255,255,0.98); border-color: rgba(255,164,190,0.98); box-shadow: 0 0 0 3px rgba(255,108,154,0.24), 0 10px 24px rgba(96,14,39,0.28); }
43
+ .navai-voice-orb-dock.is-light .navai-voice-orb-status { border-color: rgba(59,130,246,0.18); background: rgba(255,255,255,0.92); color: #1f2937; box-shadow: 0 10px 20px rgba(148,163,184,0.18); }
44
+ .navai-voice-orb-dock.is-light .navai-voice-orb-status.is-error { border-color: rgba(248,113,113,0.34); background: rgba(255,241,242,0.96); color: #9f1239; }
45
+ @keyframes navai-voice-orb-pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.08); opacity: 0.78; } 100% { transform: scale(1); opacity: 1; } }
46
+ @keyframes navai-voice-orb-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
47
+ @media (max-width: 640px) {
48
+ .navai-voice-orb-dock.is-bottom-right, .navai-voice-orb-dock.is-bottom-left { bottom: calc(0.8rem + env(safe-area-inset-bottom)); }
49
+ .navai-voice-orb-dock.is-bottom-right { right: calc(0.8rem + env(safe-area-inset-right)); }
50
+ .navai-voice-orb-dock.is-bottom-left { left: calc(0.8rem + env(safe-area-inset-left)); }
51
+ .navai-voice-orb-wrap { width: clamp(3.8rem, 22vw, 4.4rem); }
52
+ .navai-voice-orb-button-shell { width: clamp(2.45rem, 13vw, 2.82rem); height: clamp(2.45rem, 13vw, 2.82rem); }
53
+ .navai-voice-orb-button { width: clamp(1.85rem, 10vw, 2.18rem); height: clamp(1.85rem, 10vw, 2.18rem); }
54
+ }
55
+ `;
56
+ function ensureNavaiVoiceOrbStyles() {
57
+ if (typeof document === "undefined") {
58
+ return;
59
+ }
60
+ if (document.getElementById(NAVAI_VOICE_ORB_STYLE_ID)) {
61
+ return;
62
+ }
63
+ const style = document.createElement("style");
64
+ style.id = NAVAI_VOICE_ORB_STYLE_ID;
65
+ style.textContent = NAVAI_VOICE_ORB_CSS;
66
+ document.head.appendChild(style);
67
+ }
68
+ function useNavaiVoiceOrbStyles() {
69
+ useEffect(() => {
70
+ ensureNavaiVoiceOrbStyles();
71
+ }, []);
72
+ }
73
+
74
+ // src/orb/Orb.tsx
75
+ import { jsx } from "react/jsx-runtime";
76
+ var VERTEX_SHADER = (
77
+ /* glsl */
78
+ `
79
+ precision highp float;
80
+ attribute vec2 position;
81
+ attribute vec2 uv;
82
+ varying vec2 vUv;
83
+
84
+ void main() {
85
+ vUv = uv;
86
+ gl_Position = vec4(position, 0.0, 1.0);
87
+ }
88
+ `
89
+ );
90
+ var FRAGMENT_SHADER = (
91
+ /* glsl */
92
+ `
93
+ precision highp float;
94
+
95
+ uniform float iTime;
96
+ uniform vec3 iResolution;
97
+ uniform float hue;
98
+ uniform float hover;
99
+ uniform float rot;
100
+ uniform float hoverIntensity;
101
+ uniform vec3 backgroundColor;
102
+ varying vec2 vUv;
103
+
104
+ vec3 rgb2yiq(vec3 c) {
105
+ float y = dot(c, vec3(0.299, 0.587, 0.114));
106
+ float i = dot(c, vec3(0.596, -0.274, -0.322));
107
+ float q = dot(c, vec3(0.211, -0.523, 0.312));
108
+ return vec3(y, i, q);
109
+ }
110
+
111
+ vec3 yiq2rgb(vec3 c) {
112
+ float r = c.x + 0.956 * c.y + 0.621 * c.z;
113
+ float g = c.x - 0.272 * c.y - 0.647 * c.z;
114
+ float b = c.x - 1.106 * c.y + 1.703 * c.z;
115
+ return vec3(r, g, b);
116
+ }
117
+
118
+ vec3 adjustHue(vec3 color, float hueDeg) {
119
+ float hueRad = hueDeg * 3.14159265 / 180.0;
120
+ vec3 yiq = rgb2yiq(color);
121
+ float cosA = cos(hueRad);
122
+ float sinA = sin(hueRad);
123
+ float i = yiq.y * cosA - yiq.z * sinA;
124
+ float q = yiq.y * sinA + yiq.z * cosA;
125
+ yiq.y = i;
126
+ yiq.z = q;
127
+ return yiq2rgb(yiq);
128
+ }
129
+
130
+ vec3 hash33(vec3 p3) {
131
+ p3 = fract(p3 * vec3(0.1031, 0.11369, 0.13787));
132
+ p3 += dot(p3, p3.yxz + 19.19);
133
+ return -1.0 + 2.0 * fract(vec3(
134
+ p3.x + p3.y,
135
+ p3.x + p3.z,
136
+ p3.y + p3.z
137
+ ) * p3.zyx);
138
+ }
139
+
140
+ float snoise3(vec3 p) {
141
+ const float K1 = 0.333333333;
142
+ const float K2 = 0.166666667;
143
+ vec3 i = floor(p + (p.x + p.y + p.z) * K1);
144
+ vec3 d0 = p - (i - (i.x + i.y + i.z) * K2);
145
+ vec3 e = step(vec3(0.0), d0 - d0.yzx);
146
+ vec3 i1 = e * (1.0 - e.zxy);
147
+ vec3 i2 = 1.0 - e.zxy * (1.0 - e);
148
+ vec3 d1 = d0 - (i1 - K2);
149
+ vec3 d2 = d0 - (i2 - K1);
150
+ vec3 d3 = d0 - 0.5;
151
+ vec4 h = max(0.6 - vec4(
152
+ dot(d0, d0),
153
+ dot(d1, d1),
154
+ dot(d2, d2),
155
+ dot(d3, d3)
156
+ ), 0.0);
157
+ vec4 n = h * h * h * h * vec4(
158
+ dot(d0, hash33(i)),
159
+ dot(d1, hash33(i + i1)),
160
+ dot(d2, hash33(i + i2)),
161
+ dot(d3, hash33(i + 1.0))
162
+ );
163
+ return dot(vec4(31.316), n);
164
+ }
165
+
166
+ vec4 extractAlpha(vec3 colorIn) {
167
+ float a = max(max(colorIn.r, colorIn.g), colorIn.b);
168
+ return vec4(colorIn.rgb / (a + 1e-5), a);
169
+ }
170
+
171
+ const vec3 baseColor1 = vec3(0.611765, 0.262745, 0.996078);
172
+ const vec3 baseColor2 = vec3(0.298039, 0.760784, 0.913725);
173
+ const vec3 baseColor3 = vec3(0.062745, 0.078431, 0.600000);
174
+ const float innerRadius = 0.6;
175
+ const float noiseScale = 0.65;
176
+
177
+ float light1(float intensity, float attenuation, float dist) {
178
+ return intensity / (1.0 + dist * attenuation);
179
+ }
180
+
181
+ float light2(float intensity, float attenuation, float dist) {
182
+ return intensity / (1.0 + dist * dist * attenuation);
183
+ }
184
+
185
+ vec4 draw(vec2 uv) {
186
+ vec3 color1 = adjustHue(baseColor1, hue);
187
+ vec3 color2 = adjustHue(baseColor2, hue);
188
+ vec3 color3 = adjustHue(baseColor3, hue);
189
+
190
+ float ang = atan(uv.y, uv.x);
191
+ float len = length(uv);
192
+ float invLen = len > 0.0 ? 1.0 / len : 0.0;
193
+ float bgLuminance = dot(backgroundColor, vec3(0.299, 0.587, 0.114));
194
+
195
+ float n0 = snoise3(vec3(uv * noiseScale, iTime * 0.5)) * 0.5 + 0.5;
196
+ float r0 = mix(mix(innerRadius, 1.0, 0.4), mix(innerRadius, 1.0, 0.6), n0);
197
+ float d0 = distance(uv, (r0 * invLen) * uv);
198
+ float v0 = light1(1.0, 10.0, d0);
199
+
200
+ v0 *= smoothstep(r0 * 1.05, r0, len);
201
+ float innerFade = smoothstep(r0 * 0.8, r0 * 0.95, len);
202
+ v0 *= mix(innerFade, 1.0, bgLuminance * 0.7);
203
+ float cl = cos(ang + iTime * 2.0) * 0.5 + 0.5;
204
+
205
+ float a = iTime * -1.0;
206
+ vec2 pos = vec2(cos(a), sin(a)) * r0;
207
+ float d = distance(uv, pos);
208
+ float v1 = light2(1.5, 5.0, d);
209
+ v1 *= light1(1.0, 50.0, d0);
210
+
211
+ float v2 = smoothstep(1.0, mix(innerRadius, 1.0, n0 * 0.5), len);
212
+ float v3 = smoothstep(innerRadius, mix(innerRadius, 1.0, 0.5), len);
213
+
214
+ vec3 colBase = mix(color1, color2, cl);
215
+ float fadeAmount = mix(1.0, 0.1, bgLuminance);
216
+ vec3 darkCol = mix(color3, colBase, v0);
217
+ darkCol = (darkCol + v1) * v2 * v3;
218
+ darkCol = clamp(darkCol, 0.0, 1.0);
219
+
220
+ vec3 lightCol = (colBase + v1) * mix(1.0, v2 * v3, fadeAmount);
221
+ lightCol = mix(backgroundColor, lightCol, v0);
222
+ lightCol = clamp(lightCol, 0.0, 1.0);
223
+
224
+ return extractAlpha(mix(darkCol, lightCol, bgLuminance));
225
+ }
226
+
227
+ vec4 mainImage(vec2 fragCoord) {
228
+ vec2 center = iResolution.xy * 0.5;
229
+ float size = min(iResolution.x, iResolution.y);
230
+ vec2 uv = (fragCoord - center) / size * 2.0;
231
+
232
+ float angle = rot;
233
+ float s = sin(angle);
234
+ float c = cos(angle);
235
+ uv = vec2(c * uv.x - s * uv.y, s * uv.x + c * uv.y);
236
+ uv.x += hover * hoverIntensity * 0.1 * sin(uv.y * 10.0 + iTime);
237
+ uv.y += hover * hoverIntensity * 0.1 * sin(uv.x * 10.0 + iTime);
238
+
239
+ return draw(uv);
240
+ }
241
+
242
+ void main() {
243
+ vec2 fragCoord = vUv * iResolution.xy;
244
+ vec4 col = mainImage(fragCoord);
245
+ gl_FragColor = vec4(col.rgb * col.a, col.a);
246
+ }
247
+ `
248
+ );
249
+ function Orb({
250
+ hue = 0,
251
+ autoHueShift = true,
252
+ hueShiftMin = 0,
253
+ hueShiftMax = 360,
254
+ hueShiftHalfCycleSeconds = 30,
255
+ hoverIntensity = 0.2,
256
+ rotateOnHover = true,
257
+ forceHoverState = false,
258
+ enablePointerHover = true,
259
+ backgroundColor = "#000000",
260
+ animate = true
261
+ }) {
262
+ useNavaiVoiceOrbStyles();
263
+ const containerRef = useRef(null);
264
+ const hueRef = useRef(hue);
265
+ const autoHueShiftRef = useRef(autoHueShift);
266
+ const hueShiftMinRef = useRef(hueShiftMin);
267
+ const hueShiftMaxRef = useRef(hueShiftMax);
268
+ const hueShiftHalfCycleSecondsRef = useRef(hueShiftHalfCycleSeconds);
269
+ const hoverIntensityRef = useRef(hoverIntensity);
270
+ const rotateOnHoverRef = useRef(rotateOnHover);
271
+ const forceHoverStateRef = useRef(forceHoverState);
272
+ const enablePointerHoverRef = useRef(enablePointerHover);
273
+ const backgroundColorVecRef = useRef(hexToVec3(backgroundColor));
274
+ const animateRef = useRef(animate);
275
+ useEffect2(() => {
276
+ hueRef.current = hue;
277
+ }, [hue]);
278
+ useEffect2(() => {
279
+ autoHueShiftRef.current = autoHueShift;
280
+ }, [autoHueShift]);
281
+ useEffect2(() => {
282
+ hueShiftMinRef.current = hueShiftMin;
283
+ }, [hueShiftMin]);
284
+ useEffect2(() => {
285
+ hueShiftMaxRef.current = hueShiftMax;
286
+ }, [hueShiftMax]);
287
+ useEffect2(() => {
288
+ hueShiftHalfCycleSecondsRef.current = hueShiftHalfCycleSeconds;
289
+ }, [hueShiftHalfCycleSeconds]);
290
+ useEffect2(() => {
291
+ hoverIntensityRef.current = hoverIntensity;
292
+ }, [hoverIntensity]);
293
+ useEffect2(() => {
294
+ rotateOnHoverRef.current = rotateOnHover;
295
+ }, [rotateOnHover]);
296
+ useEffect2(() => {
297
+ forceHoverStateRef.current = forceHoverState;
298
+ }, [forceHoverState]);
299
+ useEffect2(() => {
300
+ enablePointerHoverRef.current = enablePointerHover;
301
+ }, [enablePointerHover]);
302
+ useEffect2(() => {
303
+ backgroundColorVecRef.current = hexToVec3(backgroundColor);
304
+ }, [backgroundColor]);
305
+ useEffect2(() => {
306
+ animateRef.current = animate;
307
+ }, [animate]);
308
+ useEffect2(() => {
309
+ const container = containerRef.current;
310
+ if (!container) {
311
+ return;
312
+ }
313
+ const renderer = new Renderer({ alpha: true, premultipliedAlpha: false });
314
+ const gl = renderer.gl;
315
+ gl.clearColor(0, 0, 0, 0);
316
+ container.appendChild(gl.canvas);
317
+ const geometry = new Triangle(gl);
318
+ const program = new Program(gl, {
319
+ vertex: VERTEX_SHADER,
320
+ fragment: FRAGMENT_SHADER,
321
+ uniforms: {
322
+ iTime: { value: 0 },
323
+ iResolution: {
324
+ value: new Vec3(gl.canvas.width, gl.canvas.height, gl.canvas.width / Math.max(gl.canvas.height, 1))
325
+ },
326
+ hue: { value: hueRef.current },
327
+ hover: { value: 0 },
328
+ rot: { value: 0 },
329
+ hoverIntensity: { value: hoverIntensityRef.current },
330
+ backgroundColor: { value: backgroundColorVecRef.current }
331
+ }
332
+ });
333
+ const mesh = new Mesh(gl, { geometry, program });
334
+ const resize = () => {
335
+ const dpr = window.devicePixelRatio || 1;
336
+ const width = Math.max(container.clientWidth, 1);
337
+ const height = Math.max(container.clientHeight, 1);
338
+ renderer.setSize(width * dpr, height * dpr);
339
+ gl.canvas.style.width = `${width}px`;
340
+ gl.canvas.style.height = `${height}px`;
341
+ program.uniforms.iResolution.value.set(gl.canvas.width, gl.canvas.height, gl.canvas.width / gl.canvas.height);
342
+ };
343
+ window.addEventListener("resize", resize);
344
+ resize();
345
+ let targetHover = 0;
346
+ let lastTime = 0;
347
+ let currentRotation = 0;
348
+ const rotationSpeed = 0.3;
349
+ const handlePointerMove = (event) => {
350
+ if (!enablePointerHoverRef.current) {
351
+ return;
352
+ }
353
+ const rect = container.getBoundingClientRect();
354
+ const x = event.clientX - rect.left;
355
+ const y = event.clientY - rect.top;
356
+ const size = Math.min(rect.width, rect.height);
357
+ const centerX = rect.width / 2;
358
+ const centerY = rect.height / 2;
359
+ const uvX = (x - centerX) / size * 2;
360
+ const uvY = (y - centerY) / size * 2;
361
+ targetHover = Math.sqrt(uvX * uvX + uvY * uvY) < 0.8 ? 1 : 0;
362
+ };
363
+ const handlePointerLeave = () => {
364
+ if (!enablePointerHoverRef.current) {
365
+ return;
366
+ }
367
+ targetHover = 0;
368
+ };
369
+ container.addEventListener("mousemove", handlePointerMove);
370
+ container.addEventListener("mouseleave", handlePointerLeave);
371
+ let animationFrameId = 0;
372
+ let idleTimerId = 0;
373
+ let lastRenderTime = 0;
374
+ let hasRenderedStaticFrame = false;
375
+ const frameIntervalMs = 1e3 / 24;
376
+ const idleCheckIntervalMs = 750;
377
+ const getAnimatedHueValue = (timeMs = 0) => {
378
+ if (!autoHueShiftRef.current) {
379
+ return hueRef.current;
380
+ }
381
+ const minHue = hueShiftMinRef.current;
382
+ const maxHue = hueShiftMaxRef.current;
383
+ const halfCycleSeconds = hueShiftHalfCycleSecondsRef.current;
384
+ const hueRange = maxHue - minHue;
385
+ if (halfCycleSeconds <= 0 || hueRange <= 0) {
386
+ return minHue;
387
+ }
388
+ const fullCycleSeconds = halfCycleSeconds * 2;
389
+ const elapsedSeconds = timeMs * 1e-3;
390
+ const cycleSeconds = (elapsedSeconds % fullCycleSeconds + fullCycleSeconds) % fullCycleSeconds;
391
+ const halfCycleProgress = cycleSeconds / halfCycleSeconds;
392
+ const wave = halfCycleProgress <= 1 ? halfCycleProgress : 2 - halfCycleProgress;
393
+ return minHue + wave * hueRange;
394
+ };
395
+ const renderStaticFrame = (timeMs = 0) => {
396
+ program.uniforms.iTime.value = 0;
397
+ program.uniforms.hue.value = getAnimatedHueValue(timeMs);
398
+ program.uniforms.hoverIntensity.value = hoverIntensityRef.current;
399
+ program.uniforms.backgroundColor.value = backgroundColorVecRef.current;
400
+ program.uniforms.hover.value = 0;
401
+ program.uniforms.rot.value = currentRotation;
402
+ renderer.render({ scene: mesh });
403
+ };
404
+ const scheduleNextFrame = () => {
405
+ if (animateRef.current && !document.hidden) {
406
+ animationFrameId = window.requestAnimationFrame(update);
407
+ return;
408
+ }
409
+ idleTimerId = window.setTimeout(() => {
410
+ animationFrameId = window.requestAnimationFrame(update);
411
+ }, idleCheckIntervalMs);
412
+ };
413
+ const update = (timeMs) => {
414
+ if (document.hidden) {
415
+ scheduleNextFrame();
416
+ return;
417
+ }
418
+ if (!animateRef.current) {
419
+ if (!hasRenderedStaticFrame) {
420
+ renderStaticFrame(timeMs);
421
+ hasRenderedStaticFrame = true;
422
+ }
423
+ scheduleNextFrame();
424
+ return;
425
+ }
426
+ hasRenderedStaticFrame = false;
427
+ if (timeMs - lastRenderTime < frameIntervalMs) {
428
+ scheduleNextFrame();
429
+ return;
430
+ }
431
+ lastRenderTime = timeMs;
432
+ const deltaSeconds = (timeMs - lastTime) * 1e-3;
433
+ lastTime = timeMs;
434
+ program.uniforms.iTime.value = timeMs * 1e-3;
435
+ program.uniforms.hue.value = getAnimatedHueValue(timeMs);
436
+ program.uniforms.hoverIntensity.value = hoverIntensityRef.current;
437
+ program.uniforms.backgroundColor.value = backgroundColorVecRef.current;
438
+ const effectiveHover = forceHoverStateRef.current ? 1 : enablePointerHoverRef.current ? targetHover : 0;
439
+ program.uniforms.hover.value += (effectiveHover - program.uniforms.hover.value) * 0.1;
440
+ if (rotateOnHoverRef.current && effectiveHover > 0.5) {
441
+ currentRotation += deltaSeconds * rotationSpeed;
442
+ }
443
+ program.uniforms.rot.value = currentRotation;
444
+ renderer.render({ scene: mesh });
445
+ scheduleNextFrame();
446
+ };
447
+ scheduleNextFrame();
448
+ return () => {
449
+ window.cancelAnimationFrame(animationFrameId);
450
+ window.clearTimeout(idleTimerId);
451
+ window.removeEventListener("resize", resize);
452
+ container.removeEventListener("mousemove", handlePointerMove);
453
+ container.removeEventListener("mouseleave", handlePointerLeave);
454
+ if (gl.canvas.parentElement === container) {
455
+ container.removeChild(gl.canvas);
456
+ }
457
+ gl.getExtension("WEBGL_lose_context")?.loseContext();
458
+ };
459
+ }, []);
460
+ return /* @__PURE__ */ jsx("div", { ref: containerRef, className: "navai-orb-container" });
461
+ }
462
+ function hslToRgb(hue, saturation, lightness) {
463
+ if (saturation === 0) {
464
+ return new Vec3(lightness, lightness, lightness);
465
+ }
466
+ const hueToRgb = (p2, q2, t) => {
467
+ let normalizedT = t;
468
+ if (normalizedT < 0) {
469
+ normalizedT += 1;
470
+ }
471
+ if (normalizedT > 1) {
472
+ normalizedT -= 1;
473
+ }
474
+ if (normalizedT < 1 / 6) {
475
+ return p2 + (q2 - p2) * 6 * normalizedT;
476
+ }
477
+ if (normalizedT < 1 / 2) {
478
+ return q2;
479
+ }
480
+ if (normalizedT < 2 / 3) {
481
+ return p2 + (q2 - p2) * (2 / 3 - normalizedT) * 6;
482
+ }
483
+ return p2;
484
+ };
485
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
486
+ const p = 2 * lightness - q;
487
+ return new Vec3(hueToRgb(p, q, hue + 1 / 3), hueToRgb(p, q, hue), hueToRgb(p, q, hue - 1 / 3));
488
+ }
489
+ function hexToVec3(color) {
490
+ if (color.startsWith("#")) {
491
+ const hex = color.slice(1);
492
+ if (hex.length === 3) {
493
+ return new Vec3(
494
+ Number.parseInt(`${hex[0]}${hex[0]}`, 16) / 255,
495
+ Number.parseInt(`${hex[1]}${hex[1]}`, 16) / 255,
496
+ Number.parseInt(`${hex[2]}${hex[2]}`, 16) / 255
497
+ );
498
+ }
499
+ if (hex.length >= 6) {
500
+ return new Vec3(
501
+ Number.parseInt(hex.slice(0, 2), 16) / 255,
502
+ Number.parseInt(hex.slice(2, 4), 16) / 255,
503
+ Number.parseInt(hex.slice(4, 6), 16) / 255
504
+ );
505
+ }
506
+ }
507
+ const rgbMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
508
+ if (rgbMatch) {
509
+ const [, red, green, blue] = rgbMatch;
510
+ return new Vec3(
511
+ Number.parseInt(red ?? "0", 10) / 255,
512
+ Number.parseInt(green ?? "0", 10) / 255,
513
+ Number.parseInt(blue ?? "0", 10) / 255
514
+ );
515
+ }
516
+ const hslMatch = color.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%/);
517
+ if (hslMatch) {
518
+ const [, hue, saturation, lightness] = hslMatch;
519
+ return hslToRgb(
520
+ Number.parseInt(hue ?? "0", 10) / 360,
521
+ Number.parseInt(saturation ?? "0", 10) / 100,
522
+ Number.parseInt(lightness ?? "0", 10) / 100
523
+ );
524
+ }
525
+ return new Vec3(0, 0, 0);
526
+ }
527
+
528
+ export {
529
+ useNavaiVoiceOrbStyles,
530
+ Orb
531
+ };