@egen-civitas/esm-styleguide 2.2.0 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @egen-civitas/esm-styleguide
2
2
 
3
+ ## 2.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 450752c: `LiveOrb` : la tête est agrandie d'environ 9 % dans sa boîte (nouvelle constante exportée `HEAD_ZOOM = 1.09`). Le zoom est appliqué à toute la scène (caméra du shader, et conteneur du repli sans GPU) : crâne, yeux, trait, oreillettes et halo grandissent du même facteur, donc les proportions mesurées sur la mascotte restent identiques. Le halo néon et la rotation maximale de la tête restent dans le cadre.
8
+
9
+ ## 2.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 477171f: `LiveOrb` devient une **tête 3D de type Baymax** au lieu d'une sphère : crâne large et arrondi, deux yeux ovales reliés par un trait fin, et deux oreillettes de casque avec anneau lumineux vert → jaune. Les proportions ont été mesurées sur la mascotte EGEN (rapport largeur/hauteur de la tête ≈ 1 : 0,74, yeux ≈ 3,7 fois leur largeur d'écart, trait ≈ 15 % de la hauteur d'un œil).
14
+
15
+ - **Rendu** : un seul fragment shader raymarché (scène SDF : crâne ellipsoïdal, oreillettes à cuvette creuse + anneau néon, raccord doux). Éclairage fixe dans le monde (ombres douces, occlusion ambiante, reflet), halo néon, silhouette anti-crénelée.
16
+ - **La tête pivote** vers le pointeur (lacet, tangage, léger roulis) avec un ressort amorti pour un mouvement de cou naturel, et un très léger balancement au repos. Les yeux, le trait et les oreilles sont solidaires du crâne : ils épousent sa courbure et se déforment en perspective quand il tourne. Le clignement écrase les yeux, le trait reste.
17
+ - **Suivi du pointeur** par angle (et non plus saturé à quelques pixels du centre), donc fluide même pour un avatar de 38 px ; retour à la pose neutre quand le pointeur quitte la fenêtre.
18
+ - **Repli sans GPU** refait dans le même design (tête, yeux, trait, oreilles à dégradé néon) avec un léger parallaxe vers le pointeur ; il ne dépend plus d'aucune classe Tailwind.
19
+ - **Robustesse** : la boucle de rendu se met en pause hors écran / onglet masqué, et une perte de contexte WebGL bascule sur le repli.
20
+ - **API rétro-compatible** : `variant` (`white`, `black`, `webgl`, `custom`), `color`, `eyeColor`, `colors`, `interactive`, `blink`, `size`, `className` sont inchangés, donc tous les usages existants (avec leurs variantes) sont mis à jour sans modification. Nouveautés : `ears` (défaut `true`), `earColors` (deux couleurs, défaut vert → jaune ; la matière `webgl` réutilise sa palette), `label` (nom accessible, défaut `Assistant avatar`). `createLiveOrb` accepte les mêmes options ; `headRotation` est exporté depuis le module.
21
+
22
+ Le shell est republié pour embarquer cette version du styleguide.
23
+
3
24
  ## 2.2.0
4
25
 
5
26
  ### Minor Changes
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- export type LiveOrbVariant = "white" | "black" | "webgl" | "custom";
1
+ import React from 'react';
2
+ export type LiveOrbVariant = 'white' | 'black' | 'webgl' | 'custom';
3
3
  export type LiveOrbOptions = {
4
4
  /** Material preset. Default `"white"`. */
5
5
  variant?: LiveOrbVariant;
@@ -9,10 +9,17 @@ export type LiveOrbOptions = {
9
9
  eyeColor?: string;
10
10
  /** Unlit wash stops — used when `variant="webgl"`. */
11
11
  colors?: string[];
12
- /** Eyes follow the pointer. Default `true`. */
12
+ /** The head turns and the eyes follow the pointer. Default `true`. */
13
13
  interactive?: boolean;
14
14
  /** Occasional blink. Default `true`. */
15
15
  blink?: boolean;
16
+ /** Glowing headphone ear-cups on both sides of the head. Default `true`. */
17
+ ears?: boolean;
18
+ /**
19
+ * Neon ring of the ear-cups: two hex stops blended around the ring.
20
+ * Default green → yellow (`variant="webgl"` reuses its own palette).
21
+ */
22
+ earColors?: string[];
16
23
  /** Fires when WebGL is ready (`true`) or torn down (`false`). */
17
24
  onHasGl?: (ok: boolean) => void;
18
25
  };
@@ -34,30 +41,49 @@ export declare const CUSTOM_DEFAULT: {
34
41
  };
35
42
  /** Violet / foam / dust-rose — stock unlit wash. */
36
43
  export declare const WEBGL_COLORS: string[];
37
- export declare function resolveVariant(variant: LiveOrbVariant, color?: string, eyeColor?: string, colors?: string[]): {
44
+ /** Neon ring of the ear-cups: green → yellow (measured on the EGEN mascot). */
45
+ export declare const EAR_COLORS: string[];
46
+ /**
47
+ * Zoom of the whole head in its square box (1 = previous size). The camera is
48
+ * pulled in, so every part (skull, eyes, line, ears, halo) grows by the same
49
+ * factor and the proportions stay exactly as designed.
50
+ */
51
+ export declare const HEAD_ZOOM = 1.09;
52
+ export declare function resolveVariant(variant: LiveOrbVariant, color?: string, eyeColor?: string, colors?: string[], earColors?: string[]): {
38
53
  body: string;
39
54
  eye: string;
40
55
  mode: number;
41
56
  palette: string[];
57
+ ear: string[];
42
58
  };
43
59
  export declare function fallbackFaceStyle(resolved: ReturnType<typeof resolveVariant>): {
44
60
  backgroundColor?: string;
45
61
  backgroundImage?: string;
46
62
  };
47
63
  /**
48
- * Evenly lit sphere with two capsule eyes that follow the pointer.
49
- * The orb stays put — only the gaze moves.
64
+ * Head → world rotation, column-major (what `uniformMatrix3fv` expects).
65
+ * Order: roll about the face axis, then nod (pitch), then turn (yaw) —
66
+ * so the head turns about the vertical axis, like a neck would.
67
+ */
68
+ export declare function headRotation(yaw: number, pitch: number, roll: number): Float32Array;
69
+ /**
70
+ * Evenly lit 3D head (Baymax-style): wide rounded skull, two oval eyes joined
71
+ * by a thin line, glowing headphone ear-cups. The head turns toward the
72
+ * pointer; eyes, line and ears are rigid with it, so they follow the surface.
50
73
  */
51
74
  export declare function createLiveOrb(canvas: HTMLCanvasElement, initial?: LiveOrbOptions): LiveOrbInstance | null;
52
- export type LiveOrbProps = Omit<LiveOrbOptions, "onHasGl"> & {
75
+ export type LiveOrbProps = Omit<LiveOrbOptions, 'onHasGl'> & {
53
76
  className?: string;
54
77
  /** Edge length in CSS pixels. Default `280`. */
55
78
  size?: number;
79
+ /** Accessible name. Default `"Assistant avatar"`. */
80
+ label?: string;
56
81
  };
57
82
  /**
58
- * Evenly lit sphere with two capsule eyes that follow the pointer.
59
- * The orb stays put — only the gaze moves.
83
+ * Evenly lit 3D head (Baymax-style): wide rounded skull, two oval eyes joined
84
+ * by a thin line, glowing headphone ear-cups. The head turns to follow the
85
+ * pointer. Falls back to a CSS head when WebGL is unavailable.
60
86
  */
61
- export declare function LiveOrb({ className, size, variant, color, eyeColor, colors, interactive, blink, }: LiveOrbProps): React.JSX.Element;
87
+ export declare function LiveOrb({ className, size, label, variant, color, eyeColor, colors, interactive, blink, ears, earColors, }: LiveOrbProps): React.JSX.Element;
62
88
  export default LiveOrb;
63
89
  //# sourceMappingURL=live-orb.component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-orb.component.d.ts","sourceRoot":"","sources":["../../src/assistant/live-orb.component.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG;IAC3B,0CAA0C;IAC1C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iEAAiE;IACjE,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,KAAK;;;CAAqD,CAAC;AACxE,eAAO,MAAM,KAAK;;;CAAqD,CAAC;AACxE,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AACX,oDAAoD;AACpD,eAAO,MAAM,YAAY,UAAoC,CAAC;AAmK9D,wBAAgB,cAAc,CAC5B,OAAO,EAAE,cAAc,EACvB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EAAE;;;;;EAqBlB;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,GAC1C;IACD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAUA;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,cAAmB,GAC3B,eAAe,GAAG,IAAI,CA+LxB;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,IAAU,EACV,OAAiB,EACjB,KAAK,EACL,QAAQ,EACR,MAAM,EACN,WAAkB,EAClB,KAAY,GACb,EAAE,YAAY,qBA8Ed;AAED,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"live-orb.component.d.ts","sourceRoot":"","sources":["../../src/assistant/live-orb.component.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG;IAC3B,0CAA0C;IAC1C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,iEAAiE;IACjE,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,KAAK;;;CAAqD,CAAC;AACxE,eAAO,MAAM,KAAK;;;CAAqD,CAAC;AACxE,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AACX,oDAAoD;AACpD,eAAO,MAAM,YAAY,UAAoC,CAAC;AAC9D,+EAA+E;AAC/E,eAAO,MAAM,UAAU,UAAyB,CAAC;AASjD;;;;GAIG;AACH,eAAO,MAAM,SAAS,OAAO,CAAC;AA0W9B,wBAAgB,cAAc,CAC5B,OAAO,EAAE,cAAc,EACvB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EAAE,EACjB,SAAS,CAAC,EAAE,MAAM,EAAE;;;;;;EA4BrB;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG;IAC9E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAUA;AAQD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAkBnF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAE,cAAmB,GAAG,eAAe,GAAG,IAAI,CA0O7G;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AA2HF;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,IAAU,EACV,KAA0B,EAC1B,OAAiB,EACjB,KAAK,EACL,QAAQ,EACR,MAAM,EACN,WAAkB,EAClB,KAAY,EACZ,IAAW,EACX,SAAS,GACV,EAAE,YAAY,qBAuDd;AAED,eAAe,OAAO,CAAC"}
@@ -1,23 +1,27 @@
1
- "use client";
1
+ 'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React, { useEffect, useRef, useState } from "react";
4
4
  import { cn } from "../page-background/page-background.utils.js";
5
5
  export const WHITE = {
6
- color: "#F4F4F5",
7
- eyeColor: "#09090B"
6
+ color: '#F4F4F5',
7
+ eyeColor: '#09090B'
8
8
  };
9
9
  export const BLACK = {
10
- color: "#18181B",
11
- eyeColor: "#F4F4F5"
10
+ color: '#18181B',
11
+ eyeColor: '#F4F4F5'
12
12
  };
13
13
  export const CUSTOM_DEFAULT = {
14
- color: "#7C5CFF",
15
- eyeColor: "#FAFAFA"
14
+ color: '#7C5CFF',
15
+ eyeColor: '#FAFAFA'
16
16
  };
17
17
  /** Violet / foam / dust-rose — stock unlit wash. */ export const WEBGL_COLORS = [
18
- "#7C6AF7",
19
- "#7DD3C7",
20
- "#E8B4D4"
18
+ '#7C6AF7',
19
+ '#7DD3C7',
20
+ '#E8B4D4'
21
+ ];
22
+ /** Neon ring of the ear-cups: green → yellow (measured on the EGEN mascot). */ export const EAR_COLORS = [
23
+ '#3DBA2E',
24
+ '#F2E62F'
21
25
  ];
22
26
  const VERT = `
23
27
  attribute vec2 a_position;
@@ -25,20 +29,60 @@ void main() {
25
29
  gl_Position = vec4(a_position, 0.0, 1.0);
26
30
  }
27
31
  `;
32
+ /**
33
+ * Zoom of the whole head in its square box (1 = previous size). The camera is
34
+ * pulled in, so every part (skull, eyes, line, ears, halo) grows by the same
35
+ * factor and the proportions stay exactly as designed.
36
+ */ export const HEAD_ZOOM = 1.09;
28
37
  const FRAG = `
38
+ #ifdef GL_FRAGMENT_PRECISION_HIGH
29
39
  precision highp float;
40
+ #else
41
+ precision mediump float;
42
+ #endif
30
43
 
31
44
  uniform vec2 u_resolution;
32
45
  uniform float u_time;
33
46
  uniform float u_speed;
34
- uniform vec2 u_look;
47
+ uniform mat3 u_rot;
35
48
  uniform float u_blink;
36
49
  uniform float u_mode;
50
+ uniform float u_ears;
37
51
  uniform vec3 u_body;
38
52
  uniform vec3 u_eye;
39
53
  uniform vec3 u_c1;
40
54
  uniform vec3 u_c2;
41
55
  uniform vec3 u_c3;
56
+ uniform vec3 u_ear1;
57
+ uniform vec3 u_ear2;
58
+
59
+ // ---- Camera ---------------------------------------------------------------
60
+ const float CAM_DIST = 6.0;
61
+ const float HALF_VIEW = ${(1.5 / HEAD_ZOOM).toFixed(4)};
62
+
63
+ // ---- Head (local space, +z = face) ----------------------------------------
64
+ const vec3 HEAD_R = vec3(1.0, 0.74, 0.86);
65
+
66
+ // ---- Face (decals projected on the head surface) --------------------------
67
+ const float EYE_X = 0.455;
68
+ const float EYE_Y = 0.075;
69
+ const float EYE_RX = 0.118;
70
+ const float EYE_RY = 0.128;
71
+ const float LINE_HALF = 0.021;
72
+
73
+ // ---- Ear-cups (headphones) -------------------------------------------------
74
+ const vec3 EAR_C = vec3(1.02, -0.10, 0.02);
75
+ const float EAR_R = 0.385;
76
+ const float EAR_HT = 0.072;
77
+ const float EAR_ROUND = 0.045;
78
+ const float RECESS_R = 0.335;
79
+ const float RECESS_D = 0.020;
80
+ const float RING_R = 0.272;
81
+ const float RING_T = 0.034;
82
+ const float RING_X = 0.062;
83
+ // cos / sin of the toe-in (cup faces slightly forward)
84
+ const float EC = 0.9287;
85
+ const float ES = 0.3709;
42
86
 
43
87
  float hash(vec2 p) {
44
88
  return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
@@ -67,27 +111,6 @@ float fbm(vec2 p) {
67
111
  return v;
68
112
  }
69
113
 
70
- vec3 orient(vec3 p, vec2 look) {
71
- float yaw = look.x * 0.92;
72
- float pitch = -look.y * 0.78;
73
- float cy = cos(yaw);
74
- float sy = sin(yaw);
75
- float cp = cos(pitch);
76
- float sp = sin(pitch);
77
- vec3 q = vec3(p.x, p.y * cp - p.z * sp, p.y * sp + p.z * cp);
78
- return vec3(q.x * cy + q.z * sy, q.y, -q.x * sy + q.z * cy);
79
- }
80
-
81
- float eyeMask(vec3 n, vec3 e, vec3 right, vec3 up, float halfH, float rad) {
82
- float facing = dot(n, e);
83
- float x = dot(n, right) - dot(e, right);
84
- float y = dot(n, up) - dot(e, up);
85
- y -= clamp(y, -halfH, halfH);
86
- float d = length(vec2(x, y)) - rad;
87
- float fill = 1.0 - smoothstep(-0.01, 0.01, d);
88
- return fill * smoothstep(0.12, 0.32, facing);
89
- }
90
-
91
114
  vec3 wash(vec3 n, float t) {
92
115
  vec2 q = n.xy * 2.2 + n.z * 0.85;
93
116
  vec2 w1 = vec2(
@@ -101,51 +124,248 @@ vec3 wash(vec3 n, float t) {
101
124
  return mix(col, u_c3, pow(smoothstep(0.42, 0.9, g), 1.4));
102
125
  }
103
126
 
127
+ float smin(float a, float b, float k) {
128
+ float h = max(k - abs(a - b), 0.0) / k;
129
+ return min(a, b) - h * h * k * 0.25;
130
+ }
131
+
132
+ float smax(float a, float b, float k) {
133
+ return -smin(-a, -b, k);
134
+ }
135
+
136
+ float sdEllipsoid(vec3 p, vec3 r) {
137
+ float k0 = length(p / r);
138
+ float k1 = length(p / (r * r));
139
+ return k0 * (k0 - 1.0) / max(k1, 1e-4);
140
+ }
141
+
142
+ // Ear frame: x = cup axis (outward, toed-in), (y, z) = radial plane. Mirrored.
143
+ vec3 earFrame(vec3 p) {
144
+ vec3 q = vec3(abs(p.x), p.y, p.z) - EAR_C;
145
+ return vec3(EC * q.x + ES * q.z, q.y, -ES * q.x + EC * q.z);
146
+ }
147
+
148
+ float sdCup(vec3 e) {
149
+ float rr = EAR_ROUND;
150
+ float rad = length(e.yz);
151
+ vec2 w = vec2(rad - EAR_R + rr, abs(e.x) - EAR_HT + rr);
152
+ float d = min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - rr;
153
+ // shallow recess in the outer face: the rim stays proud around it
154
+ float rec = max(rad - RECESS_R, (EAR_HT - RECESS_D) - e.x);
155
+ return smax(d, -rec, 0.012);
156
+ }
157
+
158
+ float sdRing(vec3 e) {
159
+ vec2 t = vec2(length(e.yz) - RING_R, e.x - RING_X);
160
+ return length(t) - RING_T;
161
+ }
162
+
163
+ // x = distance to the whole shape, y = distance to the neon ring
164
+ vec2 map(vec3 p) {
165
+ float d = sdEllipsoid(p, HEAD_R);
166
+ float dr = 1e3;
167
+ if (u_ears > 0.5) {
168
+ vec3 e = earFrame(p);
169
+ d = smin(d, sdCup(e), 0.045);
170
+ dr = sdRing(e);
171
+ d = min(d, dr);
172
+ }
173
+ return vec2(d, dr);
174
+ }
175
+
176
+ vec3 calcNormal(vec3 p) {
177
+ const vec2 k = vec2(1.0, -1.0);
178
+ const float h = 0.0016;
179
+ return normalize(
180
+ k.xyy * map(p + k.xyy * h).x +
181
+ k.yyx * map(p + k.yyx * h).x +
182
+ k.yxy * map(p + k.yxy * h).x +
183
+ k.xxx * map(p + k.xxx * h).x
184
+ );
185
+ }
186
+
187
+ float calcAO(vec3 p, vec3 n) {
188
+ float occ = 0.0;
189
+ float s = 1.0;
190
+ for (int i = 1; i <= 4; i++) {
191
+ float h = 0.045 * float(i);
192
+ occ += (h - map(p + n * h).x) * s;
193
+ s *= 0.72;
194
+ }
195
+ return clamp(1.0 - 2.4 * occ, 0.0, 1.0);
196
+ }
197
+
198
+ float softShadow(vec3 ro, vec3 rd) {
199
+ float res = 1.0;
200
+ float t = 0.05;
201
+ for (int i = 0; i < 22; i++) {
202
+ float h = map(ro + rd * t).x;
203
+ res = min(res, 9.0 * h / t);
204
+ t += clamp(h, 0.02, 0.22);
205
+ if (res < 0.002 || t > 2.6) break;
206
+ }
207
+ return clamp(res, 0.0, 1.0);
208
+ }
209
+
104
210
  void main() {
105
211
  vec2 uv = (gl_FragCoord.xy / u_resolution.xy) * 2.0 - 1.0;
106
212
  float aspect = u_resolution.x / max(u_resolution.y, 1.0);
107
213
  uv.x *= aspect;
108
214
 
109
- float radius = 0.94;
110
- vec2 p = uv / radius;
111
- float r2 = dot(p, p);
112
- float edge = 1.0 - smoothstep(0.985, 1.012, sqrt(max(r2, 0.0)));
113
- if (edge <= 0.001) {
215
+ float kView = HALF_VIEW / CAM_DIST;
216
+ float pixAng = 2.0 * kView / max(u_resolution.y, 1.0);
217
+
218
+ vec3 rdW = normalize(vec3(uv * kView, -1.0));
219
+ vec3 roW = vec3(0.0, 0.0, CAM_DIST);
220
+ // world -> head space (u_rot is head -> world; v * M == transpose(M) * v)
221
+ vec3 ro = roW * u_rot;
222
+ vec3 rd = rdW * u_rot;
223
+
224
+ // bounding sphere
225
+ float bnd = 1.55;
226
+ float b = dot(ro, rd);
227
+ float c = dot(ro, ro) - bnd * bnd;
228
+ float disc = b * b - c;
229
+ if (disc < 0.0) {
114
230
  gl_FragColor = vec4(0.0);
115
231
  return;
116
232
  }
233
+ float sq = sqrt(disc);
234
+ float tEnd = -b + sq;
235
+ float t = max(-b - sq, 0.0);
117
236
 
118
- float z = sqrt(max(1.0 - r2, 0.0));
119
- vec3 n = normalize(vec3(p, z));
237
+ float minD = 1e3;
238
+ float tMin = t;
239
+ float glow = 0.0;
240
+ bool hit = false;
241
+ vec2 m = vec2(1e3);
120
242
 
121
- vec2 look = u_look;
122
- float lm = length(look);
123
- if (lm > 1.0) look /= lm;
243
+ for (int i = 0; i < 80; i++) {
244
+ vec3 p = ro + rd * t;
245
+ m = map(p);
246
+ float eps = max(0.0007, 0.35 * t * pixAng);
247
+ if (m.x < eps) {
248
+ hit = true;
249
+ break;
250
+ }
251
+ if (m.x < minD) {
252
+ minD = m.x;
253
+ tMin = t;
254
+ }
255
+ float stp = m.x * 0.85;
256
+ glow += exp(-m.y * m.y * 150.0) * stp;
257
+ t += stp;
258
+ if (t > tEnd) break;
259
+ }
124
260
 
125
- vec3 right = orient(vec3(1.0, 0.0, 0.0), look);
126
- vec3 up = orient(vec3(0.0, 1.0, 0.0), look);
127
- vec3 eL = orient(normalize(vec3(-0.32, 0.08, 1.0)), look);
128
- vec3 eR = orient(normalize(vec3(0.32, 0.08, 1.0)), look);
261
+ vec3 glowCol = mix(u_ear1, u_ear2, 0.5);
262
+ float ga = (u_ears > 0.5) ? (1.0 - exp(-glow * 3.0)) * 0.8 : 0.0;
129
263
 
130
- float halfH = mix(0.128, 0.012, u_blink);
131
- float rad = mix(0.054, 0.062, u_blink);
132
- float eyes = max(
133
- eyeMask(n, eL, right, up, halfH, rad),
134
- eyeMask(n, eR, right, up, halfH, rad)
135
- );
264
+ float cov = 0.0;
265
+ vec3 col = vec3(0.0);
266
+
267
+ if (hit) {
268
+ cov = 1.0;
269
+ vec3 pl = ro + rd * t;
270
+ vec3 nl = calcNormal(pl);
271
+ vec3 nW = normalize(u_rot * nl);
272
+ vec3 v = -rdW;
273
+
274
+ // lights are fixed in the world: turning the head re-shades it
275
+ vec3 keyW = normalize(vec3(-0.5, 0.72, 0.78));
276
+ vec3 fillW = normalize(vec3(0.85, 0.05, 0.45));
277
+ vec3 keyL = keyW * u_rot;
278
+ float sh = softShadow(pl + nl * 0.012, keyL);
279
+ float ao = calcAO(pl, nl);
136
280
 
137
- vec3 body = u_mode > 0.5 ? wash(n, u_time * u_speed) : u_body;
138
- vec3 col = mix(body, u_eye, clamp(eyes, 0.0, 1.0));
281
+ float ndl = dot(nW, keyW);
282
+ float wrap = clamp((ndl + 0.35) / 1.35, 0.0, 1.0);
283
+ float fill = clamp((dot(nW, fillW) + 0.3) / 1.3, 0.0, 1.0);
284
+ float sky = nW.y * 0.5 + 0.5;
285
+ vec3 amb = mix(vec3(0.60, 0.61, 0.64), vec3(0.80, 0.81, 0.84), sky);
286
+ vec3 lightSum = amb * ao
287
+ + vec3(1.0, 0.975, 0.94) * 0.62 * wrap * mix(0.55, 1.0, sh) * (0.55 + 0.45 * ao)
288
+ + vec3(0.82, 0.86, 1.0) * 0.12 * fill * ao;
139
289
 
140
- gl_FragColor = vec4(clamp(col, 0.0, 1.0), edge);
290
+ vec3 hv = normalize(keyW + v);
291
+ float ndh = max(dot(nW, hv), 0.0);
292
+ float specK = (pow(ndh, 64.0) * 0.55 + pow(ndh, 14.0) * 0.10) * sh;
293
+ float ndv = max(dot(nW, v), 0.0);
294
+ float fres = 0.04 + 0.96 * pow(1.0 - ndv, 5.0);
295
+ vec3 refl = reflect(-v, nW);
296
+ vec3 env = mix(vec3(0.30, 0.31, 0.34), vec3(0.96, 0.97, 0.99), smoothstep(-0.25, 0.95, refl.y));
297
+
298
+ float px = t * pixAng;
299
+ vec3 body = (u_mode > 0.5) ? wash(nl, u_time * u_speed) : u_body;
300
+
301
+ // ---- ear materials ------------------------------------------------------
302
+ float plate = 0.0;
303
+ float ringMask = 0.0;
304
+ vec3 ringCol = vec3(0.0);
305
+ float spill = 0.0;
306
+ if (u_ears > 0.5) {
307
+ vec3 e = earFrame(pl);
308
+ float rad = length(e.yz);
309
+ float outward = smoothstep(0.02, 0.05, e.x);
310
+ plate = (1.0 - smoothstep(RECESS_R - 0.006 - px, RECESS_R + 0.004 + px, rad)) * outward;
311
+ float dRing = sdRing(e);
312
+ ringMask = 1.0 - smoothstep(0.0, 0.01 + px, dRing);
313
+ float ang = atan(e.z, e.y);
314
+ float gradT = 0.5 + 0.5 * sin(ang + (pl.x > 0.0 ? 0.6 : 2.5));
315
+ vec3 neon = mix(u_ear1, u_ear2, gradT);
316
+ float core = exp(-pow(dRing / RING_T + 1.0, 2.0) * 1.1);
317
+ ringCol = mix(neon, vec3(1.0), 0.40 * core) * (1.05 + 0.08 * sin(u_time * 1.7));
318
+ spill = exp(-max(dRing, 0.0) * 14.0) * outward;
319
+ }
320
+ vec3 plateCol = mix(vec3(0.16, 0.17, 0.20), u_body * 0.22 + vec3(0.07), 0.5);
321
+ body = mix(body, plateCol, plate);
322
+
323
+ // ---- face decals: eyes + connecting line --------------------------------
324
+ float onFace = smoothstep(0.18, 0.42, pl.z);
325
+ float lid = mix(1.0, 0.10, u_blink);
326
+ float aa = max(px * 1.1, 0.0035);
327
+ vec2 pe = pl.xy - vec2(0.0, EYE_Y);
328
+ vec2 dl = vec2(abs(pe.x) - EYE_X, pe.y) / vec2(EYE_RX, EYE_RY * lid);
329
+ float eyeM = 1.0 - smoothstep(1.0 - aa / EYE_RX, 1.0 + aa / EYE_RX, length(dl));
330
+ float lw = max(LINE_HALF, 0.6 * px);
331
+ float lineM =
332
+ (1.0 - smoothstep(lw - aa, lw + aa, abs(pe.y))) *
333
+ (1.0 - smoothstep(EYE_X - aa, EYE_X + aa, abs(pe.x)));
334
+ float face = clamp(max(eyeM, lineM), 0.0, 1.0) * onFace;
335
+
336
+ // ---- shade ----------------------------------------------------------------
337
+ vec3 lit = body * lightSum;
338
+ lit += vec3(1.0) * specK * (1.0 - plate * 0.6);
339
+ lit = mix(lit, env * mix(vec3(1.0), body, 0.35), fres * 0.42);
340
+
341
+ vec3 eyeLit = u_eye * (0.84 + 0.16 * wrap) + vec3(1.0) * specK * 0.42 + env * fres * 0.16;
342
+ col = mix(lit, eyeLit, face);
343
+
344
+ // neon spills light on the cup face and on the head next to it
345
+ col += mix(u_ear1, u_ear2, 0.5) * spill * 0.34 * (1.0 - face);
346
+ // the ring itself emits: no lighting
347
+ col = mix(col, ringCol, ringMask);
348
+ } else if (minD < 1e2) {
349
+ // anti-aliased silhouette: how close did the ray pass to the surface?
350
+ float r = minD / max(tMin * pixAng, 1e-5);
351
+ cov = 1.0 - smoothstep(0.0, 1.15, r);
352
+ // soft rim colour for the faded edge: reuse the body tone
353
+ vec3 body = (u_mode > 0.5) ? wash(normalize(ro + rd * tMin), u_time * u_speed) : u_body;
354
+ col = body * 0.9;
355
+ }
356
+
357
+ // neon halo behind / around the ring
358
+ vec3 premul = col * cov + glowCol * ga * (1.0 - cov);
359
+ float a = cov + ga * (1.0 - cov);
360
+ gl_FragColor = vec4(clamp(premul / max(a, 1e-4), 0.0, 1.0), clamp(a, 0.0, 1.0));
141
361
  }
142
362
  `;
143
363
  function isDev() {
144
- return typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
364
+ return typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production';
145
365
  }
146
366
  function hexToRgb(hex) {
147
- const h = hex.replace("#", "").trim();
148
- const full = h.length === 3 ? h.split("").map((c)=>c + c).join("") : h.padEnd(6, "0").slice(0, 6);
367
+ const h = hex.replace('#', '').trim();
368
+ const full = h.length === 3 ? h.split('').map((c)=>c + c).join('') : h.padEnd(6, '0').slice(0, 6);
149
369
  const n = Number.parseInt(full, 16);
150
370
  if (Number.isNaN(n)) return [
151
371
  0.96,
@@ -165,35 +385,48 @@ function compile(gl, type, source) {
165
385
  gl.compileShader(shader);
166
386
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
167
387
  if (isDev()) {
168
- console.warn("LiveOrb: shader failed to compile\n", gl.getShaderInfoLog(shader));
388
+ console.warn('LiveOrb: shader failed to compile\n', gl.getShaderInfoLog(shader));
169
389
  }
170
390
  gl.deleteShader(shader);
171
391
  return null;
172
392
  }
173
393
  return shader;
174
394
  }
175
- export function resolveVariant(variant, color, eyeColor, colors) {
395
+ export function resolveVariant(variant, color, eyeColor, colors, earColors) {
176
396
  let body = WHITE.color;
177
397
  let eye = WHITE.eyeColor;
178
398
  let mode = 0;
179
399
  let palette = WEBGL_COLORS;
180
- if (variant === "black") {
400
+ let ear = EAR_COLORS;
401
+ if (variant === 'black') {
181
402
  body = BLACK.color;
182
403
  eye = BLACK.eyeColor;
183
- } else if (variant === "webgl") {
404
+ } else if (variant === 'webgl') {
184
405
  palette = colors && colors.length > 0 ? colors : WEBGL_COLORS;
185
406
  body = palette[1] ?? WEBGL_COLORS[1];
186
- eye = "#0C0C10";
407
+ eye = '#0C0C10';
187
408
  mode = 1;
188
- } else if (variant === "custom") {
409
+ // the neon ring borrows the wash so the whole head stays one palette
410
+ ear = [
411
+ palette[0] ?? WEBGL_COLORS[0],
412
+ palette[2] ?? WEBGL_COLORS[2]
413
+ ];
414
+ } else if (variant === 'custom') {
189
415
  body = color ?? CUSTOM_DEFAULT.color;
190
416
  eye = eyeColor ?? CUSTOM_DEFAULT.eyeColor;
191
417
  }
418
+ if (earColors && earColors.length > 0) {
419
+ ear = [
420
+ earColors[0],
421
+ earColors[1] ?? earColors[0]
422
+ ];
423
+ }
192
424
  return {
193
425
  body,
194
426
  eye,
195
427
  mode,
196
- palette
428
+ palette,
429
+ ear
197
430
  };
198
431
  }
199
432
  export function fallbackFaceStyle(resolved) {
@@ -209,32 +442,73 @@ export function fallbackFaceStyle(resolved) {
209
442
  backgroundColor: resolved.body
210
443
  };
211
444
  }
445
+ /** Head limits (radians) reached when the pointer is far away. */ const MAX_YAW = 0.62;
446
+ const MAX_PITCH = 0.4;
447
+ /** Resting gaze: a hair above the horizon, like a head held up. */ const NEUTRAL_Y = 0.06;
212
448
  /**
213
- * Evenly lit sphere with two capsule eyes that follow the pointer.
214
- * The orb stays put — only the gaze moves.
449
+ * Head → world rotation, column-major (what `uniformMatrix3fv` expects).
450
+ * Order: roll about the face axis, then nod (pitch), then turn (yaw) —
451
+ * so the head turns about the vertical axis, like a neck would.
452
+ */ export function headRotation(yaw, pitch, roll) {
453
+ const cy = Math.cos(yaw);
454
+ const sy = Math.sin(yaw);
455
+ const cp = Math.cos(pitch);
456
+ const sp = Math.sin(pitch);
457
+ const cr = Math.cos(roll);
458
+ const sr = Math.sin(roll);
459
+ // M = Ry(yaw) · Rx(pitch) · Rz(roll)
460
+ const r00 = cy * cr + sy * sp * sr;
461
+ const r01 = -cy * sr + sy * sp * cr;
462
+ const r02 = sy * cp;
463
+ const r10 = cp * sr;
464
+ const r11 = cp * cr;
465
+ const r12 = -sp;
466
+ const r20 = -sy * cr + cy * sp * sr;
467
+ const r21 = sy * sr + cy * sp * cr;
468
+ const r22 = cy * cp;
469
+ return new Float32Array([
470
+ r00,
471
+ r10,
472
+ r20,
473
+ r01,
474
+ r11,
475
+ r21,
476
+ r02,
477
+ r12,
478
+ r22
479
+ ]);
480
+ }
481
+ /**
482
+ * Evenly lit 3D head (Baymax-style): wide rounded skull, two oval eyes joined
483
+ * by a thin line, glowing headphone ear-cups. The head turns toward the
484
+ * pointer; eyes, line and ears are rigid with it, so they follow the surface.
215
485
  */ export function createLiveOrb(canvas, initial = {}) {
216
486
  let options = {
217
- variant: "white",
487
+ variant: 'white',
218
488
  interactive: true,
219
489
  blink: true,
490
+ ears: true,
220
491
  ...initial
221
492
  };
493
+ // `look` is the head pose in [-1, 1]² (x: turn right, y: look up).
222
494
  const look = {
223
495
  x: 0,
224
- y: 0.08
496
+ y: NEUTRAL_Y,
497
+ vx: 0,
498
+ vy: 0
225
499
  };
226
500
  const targetLook = {
227
501
  x: 0,
228
- y: 0.08
502
+ y: NEUTRAL_Y
229
503
  };
230
504
  let reduce = false;
231
- const gl = canvas.getContext("webgl", {
505
+ const gl = canvas.getContext('webgl', {
232
506
  alpha: true,
233
507
  antialias: false,
234
508
  depth: false,
235
509
  stencil: false,
236
510
  premultipliedAlpha: false,
237
- powerPreference: "high-performance"
511
+ powerPreference: 'high-performance'
238
512
  });
239
513
  if (!gl) return null;
240
514
  const vs = compile(gl, gl.VERTEX_SHADER, VERT);
@@ -247,7 +521,7 @@ export function fallbackFaceStyle(resolved) {
247
521
  gl.linkProgram(program);
248
522
  if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
249
523
  if (isDev()) {
250
- console.warn("LiveOrb: program failed to link\n", gl.getProgramInfoLog(program));
524
+ console.warn('LiveOrb: program failed to link\n', gl.getProgramInfoLog(program));
251
525
  }
252
526
  return null;
253
527
  }
@@ -269,25 +543,31 @@ export function fallbackFaceStyle(resolved) {
269
543
  1,
270
544
  1
271
545
  ]), gl.STATIC_DRAW);
272
- const loc = gl.getAttribLocation(program, "a_position");
546
+ const loc = gl.getAttribLocation(program, 'a_position');
273
547
  gl.enableVertexAttribArray(loc);
274
548
  gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
275
- const uResolution = gl.getUniformLocation(program, "u_resolution");
276
- const uTime = gl.getUniformLocation(program, "u_time");
277
- const uSpeed = gl.getUniformLocation(program, "u_speed");
278
- const uLook = gl.getUniformLocation(program, "u_look");
279
- const uBlink = gl.getUniformLocation(program, "u_blink");
280
- const uMode = gl.getUniformLocation(program, "u_mode");
281
- const uBody = gl.getUniformLocation(program, "u_body");
282
- const uEye = gl.getUniformLocation(program, "u_eye");
283
- const uC1 = gl.getUniformLocation(program, "u_c1");
284
- const uC2 = gl.getUniformLocation(program, "u_c2");
285
- const uC3 = gl.getUniformLocation(program, "u_c3");
286
- gl.enable(gl.BLEND);
287
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
549
+ const u = (name)=>gl.getUniformLocation(program, name);
550
+ const uResolution = u('u_resolution');
551
+ const uTime = u('u_time');
552
+ const uSpeed = u('u_speed');
553
+ const uRot = u('u_rot');
554
+ const uBlink = u('u_blink');
555
+ const uMode = u('u_mode');
556
+ const uEars = u('u_ears');
557
+ const uBody = u('u_body');
558
+ const uEye = u('u_eye');
559
+ const uC1 = u('u_c1');
560
+ const uC2 = u('u_c2');
561
+ const uC3 = u('u_c3');
562
+ const uEar1 = u('u_ear1');
563
+ const uEar2 = u('u_ear2');
564
+ // The fragment shader writes final straight-alpha colour: no blending.
565
+ gl.disable(gl.BLEND);
288
566
  let raf = 0;
289
567
  let running = true;
568
+ let visible = true;
290
569
  const start = performance.now();
570
+ let last = start;
291
571
  let nextBlink = start + 1800 + Math.random() * 2400;
292
572
  let blinkAt = -10000;
293
573
  const resize = ()=>{
@@ -306,37 +586,72 @@ export function fallbackFaceStyle(resolved) {
306
586
  resize();
307
587
  const ro = new ResizeObserver(resize);
308
588
  if (canvas.parentElement) ro.observe(canvas.parentElement);
309
- const mqReduce = window.matchMedia("(prefers-reduced-motion: reduce)");
589
+ // No need to burn GPU while the head is scrolled away / in a hidden tab.
590
+ const io = typeof IntersectionObserver !== 'undefined' ? new IntersectionObserver(([entry])=>{
591
+ visible = entry ? entry.isIntersecting : true;
592
+ }) : null;
593
+ io?.observe(canvas);
594
+ const mqReduce = window.matchMedia('(prefers-reduced-motion: reduce)');
310
595
  const onReduce = ()=>{
311
596
  reduce = mqReduce.matches;
312
597
  };
313
598
  onReduce();
314
- mqReduce.addEventListener("change", onReduce);
599
+ mqReduce.addEventListener('change', onReduce);
315
600
  const onMove = (e)=>{
316
601
  if (!options.interactive) return;
317
602
  const parent = canvas.parentElement;
318
603
  if (!parent) return;
319
604
  const rect = parent.getBoundingClientRect();
320
605
  if (rect.width <= 0 || rect.height <= 0) return;
321
- const dx = (e.clientX - (rect.left + rect.width / 2)) / (rect.width / 2);
322
- const dy = (rect.top + rect.height / 2 - e.clientY) / (rect.height / 2);
323
- targetLook.x = Math.min(1, Math.max(-1, dx));
324
- targetLook.y = Math.min(1, Math.max(-1, dy));
606
+ // Angle-like mapping: a small avatar still turns smoothly over a long
607
+ // distance instead of snapping to the limit a few pixels from its centre.
608
+ const reach = Math.max(rect.width, rect.height) * 3 + 120;
609
+ const dx = e.clientX - (rect.left + rect.width / 2);
610
+ const dy = rect.top + rect.height / 2 - e.clientY;
611
+ targetLook.x = Math.tanh(dx / reach * 2.2);
612
+ targetLook.y = Math.tanh(dy / reach * 2.2);
325
613
  };
326
- window.addEventListener("pointermove", onMove, {
614
+ const onLeave = (e)=>{
615
+ if (e.relatedTarget === null) {
616
+ targetLook.x = 0;
617
+ targetLook.y = NEUTRAL_Y;
618
+ }
619
+ };
620
+ window.addEventListener('pointermove', onMove, {
327
621
  passive: true
328
622
  });
623
+ document.addEventListener('mouseout', onLeave);
624
+ const onLost = (e)=>{
625
+ e.preventDefault();
626
+ running = false;
627
+ cancelAnimationFrame(raf);
628
+ options.onHasGl?.(false);
629
+ };
630
+ canvas.addEventListener('webglcontextlost', onLost);
329
631
  const tick = (now)=>{
330
632
  if (!running) return;
331
- const resolved = resolveVariant(options.variant, options.color, options.eyeColor, options.colors);
633
+ raf = requestAnimationFrame(tick);
634
+ const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));
635
+ last = now;
636
+ if (!visible || document.hidden) return;
637
+ const resolved = resolveVariant(options.variant, options.color, options.eyeColor, options.colors, options.earColors);
332
638
  const time = (now - start) / 1000;
333
- if (options.interactive) {
334
- look.x += (targetLook.x - look.x) * 0.16;
335
- look.y += (targetLook.y - look.y) * 0.16;
336
- } else {
337
- look.x += (0 - look.x) * 0.12;
338
- look.y += (0.08 - look.y) * 0.12;
339
- }
639
+ // Spring-damped head pose: a slight overshoot makes it feel like a neck.
640
+ const tx = options.interactive ? targetLook.x : 0;
641
+ const ty = options.interactive ? targetLook.y : NEUTRAL_Y;
642
+ const K = 130;
643
+ const C = 17;
644
+ look.vx += ((tx - look.x) * K - look.vx * C) * dt;
645
+ look.vy += ((ty - look.y) * K - look.vy * C) * dt;
646
+ look.x += look.vx * dt;
647
+ look.y += look.vy * dt;
648
+ // Idle life: a barely-there sway so the 3D form reads even at rest.
649
+ const sway = reduce ? 0 : 1;
650
+ const lx = Math.max(-1, Math.min(1, look.x)) + Math.sin(time * 0.9) * 0.03 * sway;
651
+ const ly = Math.max(-1, Math.min(1, look.y)) + Math.sin(time * 0.67 + 1.3) * 0.022 * sway;
652
+ const yaw = lx * MAX_YAW;
653
+ const pitch = -ly * MAX_PITCH;
654
+ const roll = -lx * 0.09;
340
655
  if (!reduce && options.blink && now >= nextBlink) {
341
656
  blinkAt = now;
342
657
  nextBlink = now + 2200 + Math.random() * 3800;
@@ -355,21 +670,25 @@ export function fallbackFaceStyle(resolved) {
355
670
  1,
356
671
  2
357
672
  ].map((i)=>hexToRgb(resolved.palette[i % resolved.palette.length] ?? WEBGL_COLORS[i]));
673
+ const ear1 = hexToRgb(resolved.ear[0] ?? EAR_COLORS[0]);
674
+ const ear2 = hexToRgb(resolved.ear[1] ?? EAR_COLORS[1]);
358
675
  gl.clearColor(0, 0, 0, 0);
359
676
  gl.clear(gl.COLOR_BUFFER_BIT);
360
677
  gl.uniform2f(uResolution, canvas.width, canvas.height);
361
678
  gl.uniform1f(uTime, reduce ? 0 : time);
362
679
  gl.uniform1f(uSpeed, reduce ? 0 : 0.55);
363
- gl.uniform2f(uLook, look.x, look.y);
680
+ gl.uniformMatrix3fv(uRot, false, headRotation(yaw, pitch, roll));
364
681
  gl.uniform1f(uBlink, b);
365
682
  gl.uniform1f(uMode, resolved.mode);
683
+ gl.uniform1f(uEars, options.ears ? 1 : 0);
366
684
  gl.uniform3f(uBody, body[0], body[1], body[2]);
367
685
  gl.uniform3f(uEye, eye[0], eye[1], eye[2]);
368
686
  gl.uniform3f(uC1, palette[0][0], palette[0][1], palette[0][2]);
369
687
  gl.uniform3f(uC2, palette[1][0], palette[1][1], palette[1][2]);
370
688
  gl.uniform3f(uC3, palette[2][0], palette[2][1], palette[2][2]);
689
+ gl.uniform3f(uEar1, ear1[0], ear1[1], ear1[2]);
690
+ gl.uniform3f(uEar2, ear2[0], ear2[1], ear2[2]);
371
691
  gl.drawArrays(gl.TRIANGLES, 0, 6);
372
- raf = requestAnimationFrame(tick);
373
692
  };
374
693
  raf = requestAnimationFrame(tick);
375
694
  return {
@@ -383,8 +702,11 @@ export function fallbackFaceStyle(resolved) {
383
702
  running = false;
384
703
  cancelAnimationFrame(raf);
385
704
  ro.disconnect();
386
- mqReduce.removeEventListener("change", onReduce);
387
- window.removeEventListener("pointermove", onMove);
705
+ io?.disconnect();
706
+ mqReduce.removeEventListener('change', onReduce);
707
+ window.removeEventListener('pointermove', onMove);
708
+ document.removeEventListener('mouseout', onLeave);
709
+ canvas.removeEventListener('webglcontextlost', onLost);
388
710
  options.onHasGl?.(false);
389
711
  gl.deleteProgram(program);
390
712
  gl.deleteShader(vs);
@@ -394,9 +716,158 @@ export function fallbackFaceStyle(resolved) {
394
716
  };
395
717
  }
396
718
  /**
397
- * Evenly lit sphere with two capsule eyes that follow the pointer.
398
- * The orb stays put — only the gaze moves.
399
- */ export function LiveOrb({ className, size = 280, variant = "white", color, eyeColor, colors, interactive = true, blink = true }) {
719
+ * CSS-only head used when WebGL is unavailable. Same design as the 3D head —
720
+ * wide skull, two oval eyes joined by a line, glowing ear-cups — and a light
721
+ * parallax toward the pointer so it still feels alive without a GPU.
722
+ * Geometry is expressed in % of the box (same units as the shader: the view
723
+ * spans 2.84 head-units, so 1 unit ≈ 35.2 %).
724
+ */ function FallbackHead({ resolved, ears, interactive }) {
725
+ const faceRef = useRef(null);
726
+ const earsRef = useRef(null);
727
+ useEffect(()=>{
728
+ if (!interactive) return undefined;
729
+ const face = faceRef.current;
730
+ const earsEl = earsRef.current;
731
+ const root = face?.parentElement;
732
+ if (!face || !root) return undefined;
733
+ const onMove = (e)=>{
734
+ const rect = root.getBoundingClientRect();
735
+ if (rect.width <= 0 || rect.height <= 0) return;
736
+ const reach = Math.max(rect.width, rect.height) * 3 + 120;
737
+ const x = Math.tanh((e.clientX - (rect.left + rect.width / 2)) / reach * 2.2);
738
+ const y = Math.tanh((rect.top + rect.height / 2 - e.clientY) / reach * 2.2);
739
+ // face features sit on the front: they slide the most
740
+ face.style.transform = `translate(${(x * 5.5).toFixed(2)}%, ${(-y * 3.4).toFixed(2)}%)`;
741
+ // ear-cups are at the back of the sides: they slide the other way, less
742
+ if (earsEl) {
743
+ earsEl.style.transform = `translate(${(-x * 1.8).toFixed(2)}%, ${(-y * 1.2).toFixed(2)}%)`;
744
+ }
745
+ };
746
+ window.addEventListener('pointermove', onMove, {
747
+ passive: true
748
+ });
749
+ return ()=>window.removeEventListener('pointermove', onMove);
750
+ }, [
751
+ interactive
752
+ ]);
753
+ const [c1, c2] = resolved.ear;
754
+ const slide = 'transform 140ms ease-out';
755
+ // Inline on purpose: the fallback must not depend on any stylesheet.
756
+ const abs = {
757
+ position: 'absolute'
758
+ };
759
+ const eye = {
760
+ ...abs,
761
+ backgroundColor: resolved.eye,
762
+ width: '8.3%',
763
+ height: '9%',
764
+ top: '42.9%',
765
+ borderRadius: '50%'
766
+ };
767
+ return /*#__PURE__*/ _jsxs("div", {
768
+ "data-part": "zoom",
769
+ "aria-hidden": true,
770
+ style: {
771
+ ...abs,
772
+ inset: 0,
773
+ transform: `scale(${HEAD_ZOOM})`
774
+ },
775
+ children: [
776
+ ears ? /*#__PURE__*/ _jsx("div", {
777
+ ref: earsRef,
778
+ "data-part": "ears",
779
+ "aria-hidden": true,
780
+ style: {
781
+ ...abs,
782
+ inset: 0,
783
+ transition: slide
784
+ },
785
+ children: [
786
+ 0,
787
+ 1
788
+ ].map((i)=>/*#__PURE__*/ _jsx("span", {
789
+ "data-part": "ear",
790
+ style: {
791
+ ...abs,
792
+ borderRadius: '50%',
793
+ left: i === 0 ? '9%' : '79%',
794
+ top: '37%',
795
+ width: '12%',
796
+ height: '30%',
797
+ background: `linear-gradient(${i === 0 ? 135 : 225}deg, ${c1}, ${c2})`,
798
+ boxShadow: `0 0 6px ${c2}66, inset 0 0 0 2px #0000001f`
799
+ },
800
+ children: /*#__PURE__*/ _jsx("span", {
801
+ style: {
802
+ ...abs,
803
+ borderRadius: '50%',
804
+ inset: '16% 22%',
805
+ background: 'radial-gradient(circle at 40% 30%, #3b3e45, #15171b)'
806
+ }
807
+ })
808
+ }, i))
809
+ }) : null,
810
+ /*#__PURE__*/ _jsx("div", {
811
+ "aria-hidden": true,
812
+ "data-part": "head",
813
+ style: {
814
+ ...abs,
815
+ overflow: 'hidden',
816
+ left: '15%',
817
+ top: '24%',
818
+ width: '70%',
819
+ height: '52%',
820
+ borderRadius: '50%',
821
+ ...fallbackFaceStyle(resolved),
822
+ boxShadow: 'inset -6px -8px 14px #0000002e, inset 5px 6px 12px #ffffff66'
823
+ }
824
+ }),
825
+ /*#__PURE__*/ _jsxs("div", {
826
+ ref: faceRef,
827
+ "aria-hidden": true,
828
+ "data-part": "face",
829
+ style: {
830
+ ...abs,
831
+ inset: 0,
832
+ transition: slide
833
+ },
834
+ children: [
835
+ /*#__PURE__*/ _jsx("span", {
836
+ "data-part": "eye",
837
+ style: {
838
+ ...eye,
839
+ left: '29.9%'
840
+ }
841
+ }),
842
+ /*#__PURE__*/ _jsx("span", {
843
+ "data-part": "eye",
844
+ style: {
845
+ ...eye,
846
+ left: '61.8%'
847
+ }
848
+ }),
849
+ /*#__PURE__*/ _jsx("span", {
850
+ "data-part": "line",
851
+ style: {
852
+ ...abs,
853
+ backgroundColor: resolved.eye,
854
+ left: '34%',
855
+ width: '32%',
856
+ height: '1.6%',
857
+ top: '46.6%',
858
+ borderRadius: '999px'
859
+ }
860
+ })
861
+ ]
862
+ })
863
+ ]
864
+ });
865
+ }
866
+ /**
867
+ * Evenly lit 3D head (Baymax-style): wide rounded skull, two oval eyes joined
868
+ * by a thin line, glowing headphone ear-cups. The head turns to follow the
869
+ * pointer. Falls back to a CSS head when WebGL is unavailable.
870
+ */ export function LiveOrb({ className, size = 280, label = 'Assistant avatar', variant = 'white', color, eyeColor, colors, interactive = true, blink = true, ears = true, earColors }) {
400
871
  const canvasRef = useRef(null);
401
872
  const instanceRef = useRef(null);
402
873
  const [hasGl, setHasGl] = useState(false);
@@ -410,6 +881,8 @@ export function fallbackFaceStyle(resolved) {
410
881
  colors,
411
882
  interactive,
412
883
  blink,
884
+ ears,
885
+ earColors,
413
886
  onHasGl: setHasGl
414
887
  });
415
888
  return ()=>{
@@ -427,6 +900,8 @@ export function fallbackFaceStyle(resolved) {
427
900
  colors,
428
901
  interactive,
429
902
  blink,
903
+ ears,
904
+ earColors,
430
905
  onHasGl: setHasGl
431
906
  });
432
907
  }, [
@@ -435,45 +910,26 @@ export function fallbackFaceStyle(resolved) {
435
910
  eyeColor,
436
911
  colors,
437
912
  interactive,
438
- blink
913
+ blink,
914
+ ears,
915
+ earColors
439
916
  ]);
440
- const resolved = resolveVariant(variant, color, eyeColor, colors);
917
+ const resolved = resolveVariant(variant, color, eyeColor, colors, earColors);
441
918
  return /*#__PURE__*/ _jsxs("div", {
442
919
  "data-slot": "live-orb",
443
920
  role: "img",
444
- "aria-label": "Orb character",
445
- className: cn("relative shrink-0", className),
921
+ "aria-label": label,
922
+ className: cn('relative shrink-0', className),
446
923
  style: {
924
+ position: 'relative',
447
925
  width: size,
448
926
  height: size
449
927
  },
450
928
  children: [
451
- !hasGl ? /*#__PURE__*/ _jsxs("div", {
452
- "aria-hidden": true,
453
- className: "absolute inset-[2%] overflow-hidden rounded-full",
454
- style: fallbackFaceStyle(resolved),
455
- children: [
456
- /*#__PURE__*/ _jsx("span", {
457
- className: "absolute rounded-full",
458
- style: {
459
- backgroundColor: resolved.eye,
460
- width: "13%",
461
- height: "28%",
462
- left: "31%",
463
- top: "34%"
464
- }
465
- }),
466
- /*#__PURE__*/ _jsx("span", {
467
- className: "absolute rounded-full",
468
- style: {
469
- backgroundColor: resolved.eye,
470
- width: "13%",
471
- height: "28%",
472
- left: "56%",
473
- top: "34%"
474
- }
475
- })
476
- ]
929
+ !hasGl ? /*#__PURE__*/ _jsx(FallbackHead, {
930
+ resolved: resolved,
931
+ ears: ears,
932
+ interactive: interactive
477
933
  }) : null,
478
934
  /*#__PURE__*/ _jsx("canvas", {
479
935
  ref: canvasRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-styleguide",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "license": "MPL-2.0",
5
5
  "description": "The styleguide for Egen SPA",
6
6
  "main": "dist/internal.js",