@kortix/ui 0.16.2 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/_vendor/kortix-shared.js +1 -4
  2. package/dist/customize/settings/rail-copy-context.d.ts +2 -0
  3. package/dist/customize/settings/rail-copy-context.js +2 -0
  4. package/dist/customize/settings/tabs/chrome-connections-tab.js +1 -1
  5. package/dist/files/renderers/show-content-renderer.js +3 -1
  6. package/dist/i18n/en.d.ts +14 -9
  7. package/dist/i18n/en.js +15 -10
  8. package/dist/internal/chrome/chrome-connect.d.ts +3 -5
  9. package/dist/internal/chrome/chrome-connect.js +7 -10
  10. package/dist/internal/chrome/extension.d.ts +1 -8
  11. package/dist/internal/chrome/extension.js +1 -8
  12. package/dist/internal/chrome/use-chrome-offered.d.ts +6 -12
  13. package/dist/internal/chrome/use-chrome-offered.js +13 -15
  14. package/dist/internal/layout/project-page-header.js +5 -4
  15. package/dist/internal/stores/user-preferences-store.d.ts +17 -0
  16. package/dist/internal/stores/user-preferences-store.js +5 -0
  17. package/dist/primitives/color-picker.d.ts +19 -0
  18. package/dist/primitives/color-picker.js +27 -0
  19. package/dist/primitives/faded-scroll-area.js +4 -0
  20. package/dist/primitives/glyph-picker.d.ts +11 -0
  21. package/dist/primitives/glyph-picker.js +10 -6
  22. package/dist/primitives/gradient-wallpaper-gl.d.ts +61 -0
  23. package/dist/primitives/gradient-wallpaper-gl.js +446 -0
  24. package/dist/primitives/gradient-wallpaper.d.ts +20 -0
  25. package/dist/primitives/gradient-wallpaper.js +242 -0
  26. package/dist/primitives/resizable.d.ts +1 -1
  27. package/dist/session/composer/ComposerCard.js +0 -3
  28. package/dist/session/panel/easy/detail-view.js +3 -2
  29. package/dist/session/panel/shared/collect-tool-parts.js +2 -2
  30. package/dist/session/panel/shared/use-panel-handoffs.js +23 -2
  31. package/dist/session/thread/session-body.js +1 -1
  32. package/dist/session/tool/shared/infrastructure-contexts.d.ts +5 -0
  33. package/dist/session/tool/shared/infrastructure-contexts.js +7 -0
  34. package/dist/session/tool/show-group-renderer.d.ts +5 -5
  35. package/dist/session/tool/show-group-renderer.js +7 -4
  36. package/dist/session/tool/tool-part-renderer.js +3 -1
  37. package/dist/session/tool/tool-renderers.d.ts +1 -1
  38. package/dist/session/tool/tool-renderers.js +1 -1
  39. package/dist/styles.css +1 -1
  40. package/dist/test-utils/intl.d.ts +14 -9
  41. package/dist/theme/index.d.ts +2 -1
  42. package/dist/theme/index.js +2 -1
  43. package/dist/theme/wallpaper-gradients.d.ts +106 -0
  44. package/dist/theme/wallpaper-gradients.js +347 -0
  45. package/dist/theme/wallpapers.d.ts +23 -3
  46. package/dist/theme/wallpapers.js +53 -29
  47. package/dist/workspace/admin/project-admin-dashboard.js +1 -1
  48. package/dist/workspace/layout/project-home.js +1 -1
  49. package/dist/workspace/new/use-create-workspace.d.ts +5 -3
  50. package/dist/workspace/new/use-create-workspace.js +1 -1
  51. package/dist/workspace/session-spaces/space-picker.js +3 -3
  52. package/dist/workspace/setup/setup-banner-snooze.d.ts +10 -0
  53. package/dist/workspace/setup/setup-banner-snooze.js +44 -0
  54. package/dist/workspace/setup/setup-banner.js +19 -36
  55. package/dist/workspace/setup/setup-steps.d.ts +0 -5
  56. package/dist/workspace/setup/setup-steps.js +0 -7
  57. package/dist/workspace/setup/workspace-setup-modal.d.ts +39 -0
  58. package/dist/workspace/setup/workspace-setup-modal.js +202 -0
  59. package/dist/workspace/sidebar/project-session-list.js +2 -1
  60. package/dist/workspace/sidebar/project-sidebar.js +6 -5
  61. package/package.json +14 -10
  62. package/skills/kortix-ui/SKILL.md +1 -1
  63. package/skills/kortix-ui/references/modules.md +3 -1
  64. package/dist/primitives/toast-clearance.d.ts +0 -36
  65. package/dist/primitives/toast-clearance.js +0 -94
  66. package/dist/workspace/setup/workspace-setup-page.d.ts +0 -10
  67. package/dist/workspace/setup/workspace-setup-page.js +0 -91
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The gradient wallpaper renderer: one single-pass WebGL1 fragment shader for
3
+ * every colored wallpaper.
4
+ *
5
+ * Frame budget. The canvas is `pixelScale()` CSS pixels per canvas pixel
6
+ * (2, or more on a very large page), at any device pixel ratio, and the
7
+ * browser upscales it. A canvas never exceeds `MAX_CANVAS_PIXELS` (1 MP): a
8
+ * 1920×1080 page is 960×540 (0.5 MP), a 3840×2160 page is 1280×720 (0.9 MP),
9
+ * against 8.3 MP for a native canvas. The dither finish wants this anyway
10
+ * (its dots are 2 CSS px), and the grain finish is all low frequencies, so
11
+ * the upscale is not visible.
12
+ *
13
+ * Per pixel, a pattern costs 0 to 2 four-octave noise lookups (16 hashes
14
+ * each). The dither finish evaluates the pattern twice, at the cell and at
15
+ * its block, except for `clouds`, which evaluates it once. The worst case is
16
+ * 4 lookups: a dithered `bloom` or `mesh`.
17
+ *
18
+ * The context is created with `failIfMajorPerformanceCaveat`: a browser that
19
+ * would run WebGL on the CPU gets no canvas and the CSS fallback instead.
20
+ *
21
+ * The output is premultiplied color over a transparent canvas. The page's
22
+ * real background shows through, so a wallpaper works on every interface
23
+ * theme without knowing its background color.
24
+ */
25
+ import { type GradientFinish, type GradientPattern } from '../theme/wallpaper-gradients.js';
26
+ /** The fewest CSS pixels per canvas pixel. */
27
+ export declare const PIXEL_SCALE = 2;
28
+ /** The most pixels a wallpaper canvas holds. */
29
+ export declare const MAX_CANVAS_PIXELS = 1000000;
30
+ /** CSS pixels per canvas pixel for a host of this CSS size: a whole number,
31
+ * so every canvas pixel covers the same number of device pixels. */
32
+ export declare function pixelScale(cssWidth: number, cssHeight: number): number;
33
+ export interface GradientDrawParams {
34
+ pattern: GradientPattern;
35
+ finish: GradientFinish;
36
+ /** 2–5 hex colors. */
37
+ colors: string[];
38
+ calm: number;
39
+ anchor?: [number, number];
40
+ }
41
+ export interface GradientRenderer {
42
+ /** Draws one frame at `time` seconds. The canvas size is read at draw. */
43
+ draw(params: GradientDrawParams, time: number): void;
44
+ /** True after the browser took the context away: `draw` then does nothing. */
45
+ isLost(): boolean;
46
+ destroy(): void;
47
+ }
48
+ export declare function hexToRgb(hex: string): [number, number, number];
49
+ /** The `u_colors` uniform: `colors` as RGB triples, padded with the last. */
50
+ export declare function packColors(colors: string[]): Float32Array;
51
+ /**
52
+ * Returns null when WebGL is unavailable or the program does not build. The
53
+ * caller then renders nothing: a wallpaper is decoration.
54
+ */
55
+ export declare function createGradientRenderer(canvas: HTMLCanvasElement): GradientRenderer | null;
56
+ /**
57
+ * Draws one frame into `target`, a 2D canvas, at the target's own size. That
58
+ * size is the canvas a page would get: a 480×270 target shows what a 960×540
59
+ * page shows. Returns false, and leaves the target alone, without WebGL.
60
+ */
61
+ export declare function drawGradientStill(params: GradientDrawParams, target: HTMLCanvasElement): boolean;
@@ -0,0 +1,446 @@
1
+ /**
2
+ * The gradient wallpaper renderer: one single-pass WebGL1 fragment shader for
3
+ * every colored wallpaper.
4
+ *
5
+ * Frame budget. The canvas is `pixelScale()` CSS pixels per canvas pixel
6
+ * (2, or more on a very large page), at any device pixel ratio, and the
7
+ * browser upscales it. A canvas never exceeds `MAX_CANVAS_PIXELS` (1 MP): a
8
+ * 1920×1080 page is 960×540 (0.5 MP), a 3840×2160 page is 1280×720 (0.9 MP),
9
+ * against 8.3 MP for a native canvas. The dither finish wants this anyway
10
+ * (its dots are 2 CSS px), and the grain finish is all low frequencies, so
11
+ * the upscale is not visible.
12
+ *
13
+ * Per pixel, a pattern costs 0 to 2 four-octave noise lookups (16 hashes
14
+ * each). The dither finish evaluates the pattern twice, at the cell and at
15
+ * its block, except for `clouds`, which evaluates it once. The worst case is
16
+ * 4 lookups: a dithered `bloom` or `mesh`.
17
+ *
18
+ * The context is created with `failIfMajorPerformanceCaveat`: a browser that
19
+ * would run WebGL on the CPU gets no canvas and the CSS fallback instead.
20
+ *
21
+ * The output is premultiplied color over a transparent canvas. The page's
22
+ * real background shows through, so a wallpaper works on every interface
23
+ * theme without knowing its background color.
24
+ */
25
+ import { GRADIENT_MAX_COLORS, GRADIENT_PATTERNS, } from '../theme/wallpaper-gradients.js';
26
+ /** The fewest CSS pixels per canvas pixel. */
27
+ export const PIXEL_SCALE = 2;
28
+ /** The most pixels a wallpaper canvas holds. */
29
+ export const MAX_CANVAS_PIXELS = 1_000_000;
30
+ /** CSS pixels per canvas pixel for a host of this CSS size: a whole number,
31
+ * so every canvas pixel covers the same number of device pixels. */
32
+ export function pixelScale(cssWidth, cssHeight) {
33
+ return Math.max(PIXEL_SCALE, Math.ceil(Math.sqrt((cssWidth * cssHeight) / MAX_CANVAS_PIXELS)));
34
+ }
35
+ const VERTEX = `
36
+ attribute vec2 a_pos;
37
+ void main() { gl_Position = vec4(a_pos, 0.0, 1.0); }
38
+ `;
39
+ const FRAGMENT = `
40
+ #ifdef GL_FRAGMENT_PRECISION_HIGH
41
+ precision highp float;
42
+ #else
43
+ precision mediump float;
44
+ #endif
45
+
46
+ uniform vec2 u_res;
47
+ uniform float u_time;
48
+ uniform float u_pattern;
49
+ uniform float u_dither;
50
+ uniform vec3 u_colors[${GRADIENT_MAX_COLORS}];
51
+ uniform float u_count;
52
+ uniform float u_calm;
53
+ uniform vec2 u_anchor;
54
+
55
+ #ifdef GL_FRAGMENT_PRECISION_HIGH
56
+ float hash(vec2 p) {
57
+ vec3 q = fract(p.xyx * 0.1031);
58
+ q += dot(q, q.yzx + 33.33);
59
+ return fract((q.x + q.y) * q.z);
60
+ }
61
+ #else
62
+ // mediump guarantees a range of 2^14 and 10 bits of precision. This hash
63
+ // wraps its input and keeps every intermediate value under 53, so the noise
64
+ // and grain repeat every 64 units on a GPU with no highp fragment floats.
65
+ float hash(vec2 p) {
66
+ return fract(52.9829189 * fract(dot(mod(p, 64.0), vec2(0.06711056, 0.00583715))));
67
+ }
68
+ #endif
69
+
70
+ float noise(vec2 p) {
71
+ vec2 i = floor(p);
72
+ vec2 f = fract(p);
73
+ f = f * f * (3.0 - 2.0 * f);
74
+ return mix(
75
+ mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x),
76
+ mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x),
77
+ f.y
78
+ );
79
+ }
80
+
81
+ float fbm(vec2 p) {
82
+ float amp = 0.5;
83
+ float sum = 0.0;
84
+ for (int i = 0; i < 4; i++) {
85
+ sum += amp * noise(p);
86
+ p = p * 2.03 + vec2(17.1, 9.2);
87
+ amp *= 0.5;
88
+ }
89
+ return sum / 0.9375;
90
+ }
91
+
92
+ float bayer2(vec2 a) {
93
+ // Parity first: the square of a raw row index leaves the mediump range.
94
+ a = mod(floor(a), 2.0);
95
+ return fract(a.x / 2.0 + a.y * a.y * 0.75);
96
+ }
97
+ float bayer4(vec2 a) { return bayer2(0.5 * a) * 0.25 + bayer2(a); }
98
+ float bayer8(vec2 a) { return bayer4(0.5 * a) * 0.25 + bayer2(a); }
99
+
100
+ // Returns (coverage, palette position), both 0..1. uv is 0..1 with y down.
101
+ // Draws every pattern 15% larger than its field (GRADIENT_SCALE), so the
102
+ // shape fills the page edges instead of ending inside them.
103
+ vec2 place(vec2 screen) {
104
+ return (screen - 0.5) / 1.15 + 0.5;
105
+ }
106
+
107
+ vec2 field(vec2 screen) {
108
+ float asp = u_res.x / u_res.y;
109
+ vec2 uv = place(screen);
110
+ float t = u_time;
111
+ float a = 0.0;
112
+ float c = 0.0;
113
+
114
+ if (u_pattern < 0.5) {
115
+ // bloom: color grows out of one corner in streaks aimed at the center.
116
+ vec2 d = uv - u_anchor;
117
+ d.x *= asp;
118
+ float r = length(d) / length(vec2(asp, 1.0));
119
+ vec2 dir = normalize(vec2((0.5 - u_anchor.x) * asp, 0.5 - u_anchor.y));
120
+ float along = dot(d, dir);
121
+ float across = dot(d, vec2(-dir.y, dir.x));
122
+ float n = fbm(vec2(along * 1.3 - t * 0.6, across * 3.4 + t * 0.2));
123
+ float m = fbm(vec2(along * 3.1 + t * 0.3, across * 6.0) + 31.7);
124
+ a = 1.0 - smoothstep(0.0, 0.66, r + (n - 0.5) * 0.45);
125
+ a *= a;
126
+ a = a * (0.62 + 0.5 * m);
127
+ c = a;
128
+ } else if (u_pattern < 1.5) {
129
+ // beam: a diagonal band, soft above and sharp below.
130
+ vec2 q = vec2((uv.x - 0.5) * asp, uv.y - 0.5);
131
+ vec2 nrm = normalize(vec2(-0.5, 1.0));
132
+ float along = dot(q, vec2(nrm.y, -nrm.x));
133
+ float s = dot(q, nrm) + 0.3;
134
+ s += (fbm(vec2(along * 1.4 + t * 0.4, 3.0)) - 0.5) * 0.16;
135
+ float soft = exp(-(s * s) / 0.1);
136
+ float sharp = exp(-(s * s) / 0.0011);
137
+ a = s > 0.0 ? sharp : soft;
138
+ a *= 0.75 + 0.35 * fbm(vec2(along * 2.2 - t * 0.5, s * 9.0) + 7.0);
139
+ c = pow(smoothstep(-0.52, 0.035, s), 1.5);
140
+ } else if (u_pattern < 2.5) {
141
+ // sheet: a wavy half-plane falling from the anchor corner. m is uv
142
+ // mirrored so the anchor is its origin: (0, 0) is the top-left corner,
143
+ // (1, 1) flips both axes to the bottom-right.
144
+ vec2 m = abs(uv - u_anchor);
145
+ float s = (m.x + m.y) * 0.5;
146
+ s += 0.05 * sin(m.x * 5.0 - m.y * 2.0 + t * 1.6);
147
+ s += (fbm(vec2(m.x * asp * 2.0 - t * 0.3, m.y * 2.4 + t * 0.2)) - 0.5) * 0.22;
148
+ a = 1.0 - smoothstep(0.04, 0.5, s);
149
+ c = a * a;
150
+ a = pow(a, 0.8);
151
+ } else if (u_pattern < 3.5) {
152
+ // bands: vertical ribbons that sway.
153
+ float x = uv.x * asp * 0.62;
154
+ x += 0.2 * sin(uv.y * 2.6 + t * 0.9);
155
+ x += (fbm(vec2(uv.x * asp * 1.1, uv.y * 1.2 - t * 0.35)) - 0.5) * 0.7;
156
+ c = 0.5 + 0.5 * sin(x * 4.4 + 0.6);
157
+ a = 0.4 + 0.4 * sin(x * 2.3 + 1.9 + t * 0.4);
158
+ } else if (u_pattern < 4.5) {
159
+ // horizon: a glowing line low on the page over a filled ground.
160
+ float y0 = 0.74 + 0.025 * sin(uv.x * 3.0 + t * 0.8);
161
+ float d = uv.y - y0;
162
+ float glow = exp(-(d * d) / 0.028);
163
+ float ground = smoothstep(-0.03, 0.13, d) * 0.85;
164
+ a = min(glow + ground, 1.0);
165
+ a *= 1.0 - 0.3 * pow(abs(uv.x - 0.5) * 2.0, 2.0) * (1.0 - ground);
166
+ c = 1.0 - smoothstep(-0.26, 0.2, d);
167
+ } else if (u_pattern < 5.5) {
168
+ // arc: the lit rim of a sphere whose body is above the page.
169
+ vec2 q = vec2((uv.x - 0.5) * asp, uv.y);
170
+ float radius = 1.36 + 0.012 * sin(t * 0.9);
171
+ float d = length(q - vec2(0.0, -0.58)) - radius;
172
+ float inside = exp(d * 3.4);
173
+ float outside = exp(-(d * d) / 0.0016);
174
+ a = d < 0.0 ? inside : outside;
175
+ c = d < 0.0 ? exp(d * 5.5) : 1.0;
176
+ } else if (u_pattern < 6.5) {
177
+ // mesh: four pools of light drifting in the corners.
178
+ vec2 w = uv + (vec2(fbm(uv * 2.0 + t * 0.2), fbm(uv * 2.0 + 13.0 - t * 0.2)) - 0.5) * 0.22;
179
+ float sum = 0.0;
180
+ float cs = 0.0;
181
+ for (int i = 0; i < 4; i++) {
182
+ float fi = float(i);
183
+ vec2 base = vec2(
184
+ mod(fi, 2.0) < 0.5 ? 0.06 : 0.94,
185
+ fi < 1.5 ? 0.1 : 0.92
186
+ );
187
+ vec2 pos = base + 0.09 * vec2(sin(t * 0.7 + fi * 1.7), cos(t * 0.5 + fi * 2.3));
188
+ vec2 dd = w - pos;
189
+ dd.x *= asp * 0.75;
190
+ float wgt = exp(-dot(dd, dd) / 0.085);
191
+ sum += wgt;
192
+ cs += wgt * (fi < 0.5 ? 0.15 : fi < 1.5 ? 0.95 : fi < 2.5 ? 0.6 : 0.35);
193
+ }
194
+ a = clamp(sum, 0.0, 1.0);
195
+ c = cs / max(sum, 0.0001);
196
+ } else {
197
+ // clouds: thresholded noise in two banks that rise from the bottom
198
+ // corners and taper under the centered content.
199
+ vec2 p = vec2(uv.x * asp * 1.25 + t * 0.25, uv.y * 1.7);
200
+ float w = fbm(p * 1.6 + 4.0);
201
+ float n = fbm(p + 0.7 * vec2(w, 1.0 - w));
202
+ float side = 0.5 + 0.8 * abs(uv.x - 0.5) * 2.0;
203
+ float lift = 0.46 + 0.62 * smoothstep(0.25, 1.0, uv.y) * side;
204
+ float v = n * lift;
205
+ a = smoothstep(0.4, 0.58, v);
206
+ c = smoothstep(0.42, 0.8, v);
207
+ }
208
+
209
+ // Clear the shape behind the centered content.
210
+ // On a narrow page the content spans the full width, so the cleared area
211
+ // widens as the aspect ratio falls below 1.6.
212
+ vec2 k = screen - vec2(0.5, 0.46);
213
+ k.x *= min(asp, 1.6) / 1.6;
214
+ a *= 1.0 - u_calm * exp(-(k.x * k.x) / 0.15 - (k.y * k.y) / 0.06);
215
+ return clamp(vec2(a, c), 0.0, 1.0);
216
+ }
217
+
218
+ vec3 paletteSmooth(float c) {
219
+ float x = c * (u_count - 1.0);
220
+ vec3 col = u_colors[0];
221
+ for (int i = 1; i < ${GRADIENT_MAX_COLORS}; i++) {
222
+ col = mix(col, u_colors[i], clamp(x - float(i - 1), 0.0, 1.0));
223
+ }
224
+ return col;
225
+ }
226
+
227
+ vec3 paletteStep(float index) {
228
+ vec3 col = u_colors[0];
229
+ for (int i = 1; i < ${GRADIENT_MAX_COLORS}; i++) {
230
+ col = mix(col, u_colors[i], step(float(i), index));
231
+ }
232
+ return col;
233
+ }
234
+
235
+ void main() {
236
+ vec2 fc = floor(gl_FragCoord.xy);
237
+ fc.y = u_res.y - 1.0 - fc.y;
238
+
239
+ if (u_dither > 0.5) {
240
+ // A cell is 2×2 canvas pixels. Its top-left pixel is the dot. Dots fire
241
+ // first, in bayer order, so low coverage reads as a sparse dot grid; the
242
+ // other three pixels then fill the cell, so high coverage reads as
243
+ // solid blocks.
244
+ vec2 cell = floor(fc / 2.0);
245
+ vec2 sub = fc - cell * 2.0;
246
+ vec2 uvCell = (cell * 2.0 + 1.0) / u_res;
247
+ vec2 block = floor(cell / 3.0) * 3.0 + 1.5;
248
+ vec2 uvBlock = (block * 2.0) / u_res;
249
+ // The block sample gives the pixel-art steps. Clouds skip it: their
250
+ // edge should stay round, and it halves their cost.
251
+ vec2 f = field(uvCell);
252
+ // It fades out with coverage, so a faint outer edge stays a soft dot
253
+ // field and only the dense core steps.
254
+ if (u_pattern < 6.5) {
255
+ vec2 fb = field(uvBlock);
256
+ f = mix(f, fb, 0.4 * smoothstep(0.1, 0.5, fb.x));
257
+ }
258
+
259
+ bool isDot = sub.x < 0.5 && sub.y < 0.5;
260
+ float threshold = isDot
261
+ ? bayer8(cell) * 0.4 + 0.004
262
+ : 0.4 + 0.6 * bayer8(cell + vec2(5.0, 3.0));
263
+ if (f.x <= threshold) {
264
+ gl_FragColor = vec4(0.0);
265
+ return;
266
+ }
267
+ float index = floor(f.y * (u_count - 1.0) + bayer8(cell + vec2(2.0, 7.0)));
268
+ gl_FragColor = vec4(paletteStep(index), 1.0);
269
+ return;
270
+ }
271
+
272
+ vec2 f = field((fc + 0.5) / u_res);
273
+ // Static grain: it hides 8-bit banding and gives the print texture.
274
+ float g = hash(fc + 3.7) - 0.5;
275
+ vec3 col = paletteSmooth(f.y) + g * 0.07;
276
+ float alpha = clamp(f.x + g * 0.03, 0.0, 1.0);
277
+ gl_FragColor = vec4(clamp(col, 0.0, 1.0) * alpha, alpha);
278
+ }
279
+ `;
280
+ export function hexToRgb(hex) {
281
+ const value = Number.parseInt(hex.slice(1), 16);
282
+ return [((value >> 16) & 255) / 255, ((value >> 8) & 255) / 255, (value & 255) / 255];
283
+ }
284
+ /** The `u_colors` uniform: `colors` as RGB triples, padded with the last. */
285
+ export function packColors(colors) {
286
+ const packed = new Float32Array(GRADIENT_MAX_COLORS * 3);
287
+ const count = Math.min(colors.length, GRADIENT_MAX_COLORS);
288
+ for (let i = 0; i < GRADIENT_MAX_COLORS; i++) {
289
+ packed.set(hexToRgb(colors[Math.min(i, count - 1)]), i * 3);
290
+ }
291
+ return packed;
292
+ }
293
+ function compile(gl, type, source) {
294
+ const shader = gl.createShader(type);
295
+ if (!shader)
296
+ return null;
297
+ gl.shaderSource(shader, source);
298
+ gl.compileShader(shader);
299
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
300
+ gl.deleteShader(shader);
301
+ return null;
302
+ }
303
+ return shader;
304
+ }
305
+ /**
306
+ * Returns null when WebGL is unavailable or the program does not build. The
307
+ * caller then renders nothing: a wallpaper is decoration.
308
+ */
309
+ export function createGradientRenderer(canvas) {
310
+ let gl = null;
311
+ try {
312
+ gl = canvas.getContext('webgl', {
313
+ alpha: true,
314
+ antialias: false,
315
+ depth: false,
316
+ stencil: false,
317
+ premultipliedAlpha: true,
318
+ powerPreference: 'low-power',
319
+ // No software WebGL: a CPU rasterizer cannot hold the frame budget.
320
+ failIfMajorPerformanceCaveat: true,
321
+ });
322
+ }
323
+ catch {
324
+ return null;
325
+ }
326
+ if (!gl)
327
+ return null;
328
+ const context = gl;
329
+ const vertex = compile(context, context.VERTEX_SHADER, VERTEX);
330
+ const fragment = compile(context, context.FRAGMENT_SHADER, FRAGMENT);
331
+ const program = context.createProgram();
332
+ if (!vertex || !fragment || !program)
333
+ return null;
334
+ context.attachShader(program, vertex);
335
+ context.attachShader(program, fragment);
336
+ context.linkProgram(program);
337
+ if (!context.getProgramParameter(program, context.LINK_STATUS))
338
+ return null;
339
+ context.useProgram(program);
340
+ // One triangle that covers the viewport.
341
+ const buffer = context.createBuffer();
342
+ context.bindBuffer(context.ARRAY_BUFFER, buffer);
343
+ context.bufferData(context.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), context.STATIC_DRAW);
344
+ const position = context.getAttribLocation(program, 'a_pos');
345
+ context.enableVertexAttribArray(position);
346
+ context.vertexAttribPointer(position, 2, context.FLOAT, false, 0, 0);
347
+ const uniform = (name) => context.getUniformLocation(program, name);
348
+ const uRes = uniform('u_res');
349
+ const uTime = uniform('u_time');
350
+ const uPattern = uniform('u_pattern');
351
+ const uDither = uniform('u_dither');
352
+ const uColors = uniform('u_colors[0]');
353
+ const uCount = uniform('u_count');
354
+ const uCalm = uniform('u_calm');
355
+ const uAnchor = uniform('u_anchor');
356
+ // An animation frame changes only the time. The size and the wallpaper's
357
+ // own uniforms are sent again only when they change.
358
+ let sentParams = null;
359
+ let sentWidth = 0;
360
+ let sentHeight = 0;
361
+ return {
362
+ draw(params, time) {
363
+ if (context.isContextLost())
364
+ return;
365
+ const { width, height } = canvas;
366
+ if (width !== sentWidth || height !== sentHeight) {
367
+ context.viewport(0, 0, width, height);
368
+ context.uniform2f(uRes, width, height);
369
+ sentWidth = width;
370
+ sentHeight = height;
371
+ }
372
+ if (params !== sentParams) {
373
+ context.uniform1f(uPattern, GRADIENT_PATTERNS.indexOf(params.pattern));
374
+ context.uniform1f(uDither, params.finish === 'dither' ? 1 : 0);
375
+ context.uniform3fv(uColors, packColors(params.colors));
376
+ context.uniform1f(uCount, Math.min(params.colors.length, GRADIENT_MAX_COLORS));
377
+ context.uniform1f(uCalm, params.calm);
378
+ context.uniform2f(uAnchor, params.anchor?.[0] ?? 1, params.anchor?.[1] ?? 1);
379
+ sentParams = params;
380
+ }
381
+ context.uniform1f(uTime, time);
382
+ context.drawArrays(context.TRIANGLES, 0, 3);
383
+ },
384
+ isLost: () => context.isContextLost(),
385
+ destroy() {
386
+ context.deleteBuffer(buffer);
387
+ context.deleteProgram(program);
388
+ context.deleteShader(vertex);
389
+ context.deleteShader(fragment);
390
+ // Give the context back once the canvas has left the document. A
391
+ // browser keeps about 16 and then drops the oldest. Deferred, because
392
+ // React's strict mode destroys and recreates on a canvas that stays.
393
+ setTimeout(() => {
394
+ if (!canvas.isConnected)
395
+ context.getExtension('WEBGL_lose_context')?.loseContext();
396
+ }, 0);
397
+ },
398
+ };
399
+ }
400
+ // ── Stills ───────────────────────────────────────────────────────────────
401
+ // The settings picker shows eleven gradients at once. A live WebGL canvas per
402
+ // card would hold eleven contexts, so each card is a 2D canvas that receives
403
+ // one frame from a single shared offscreen context. The copy stays on the
404
+ // GPU: no readback and no image encode.
405
+ let still = null;
406
+ /** WebGL refused at this time: stills skip the attempt for a while. */
407
+ let stillFailedAt = Number.NEGATIVE_INFINITY;
408
+ /** 11 thumbnails mount together. One refusal covers them all, then a
409
+ * later draw may try again. */
410
+ const STILL_RETRY_MS = 5000;
411
+ /**
412
+ * Draws one frame into `target`, a 2D canvas, at the target's own size. That
413
+ * size is the canvas a page would get: a 480×270 target shows what a 960×540
414
+ * page shows. Returns false, and leaves the target alone, without WebGL.
415
+ */
416
+ export function drawGradientStill(params, target) {
417
+ // A lost context draws nothing: drop it and build a new one.
418
+ if (still?.renderer.isLost())
419
+ still = null;
420
+ if (!still) {
421
+ if (performance.now() - stillFailedAt < STILL_RETRY_MS)
422
+ return false;
423
+ const canvas = document.createElement('canvas');
424
+ const renderer = createGradientRenderer(canvas);
425
+ if (!renderer) {
426
+ stillFailedAt = performance.now();
427
+ return false;
428
+ }
429
+ still = { canvas, renderer };
430
+ }
431
+ const context = target.getContext('2d');
432
+ if (!context)
433
+ return false;
434
+ // Assigning a size reallocates the drawing buffer, even to the same size.
435
+ if (still.canvas.width !== target.width)
436
+ still.canvas.width = target.width;
437
+ if (still.canvas.height !== target.height)
438
+ still.canvas.height = target.height;
439
+ still.renderer.draw(params, 0);
440
+ if (still.renderer.isLost())
441
+ return false;
442
+ // Copy in the same task as the draw: the drawing buffer is cleared after.
443
+ context.clearRect(0, 0, target.width, target.height);
444
+ context.drawImage(still.canvas, 0, 0);
445
+ return true;
446
+ }
@@ -0,0 +1,20 @@
1
+ import { type GradientConfig } from '../theme/wallpaper-gradients.js';
2
+ /**
3
+ * A full-bleed gradient wallpaper on one small WebGL canvas.
4
+ *
5
+ * Nothing here goes through React state per frame. The loop writes one
6
+ * uniform and issues one draw call. It stops while the canvas is off screen,
7
+ * and reduced motion draws a single still frame. See
8
+ * `primitives/gradient-wallpaper-gl.ts` for the frame budget.
9
+ */
10
+ export declare const GradientWallpaper: import("react").NamedExoticComponent<{
11
+ config: GradientConfig;
12
+ }>;
13
+ /**
14
+ * A still of a gradient wallpaper for the settings picker: a 2D canvas that
15
+ * receives one frame from the shared context. Without WebGL it shows the same
16
+ * CSS fallback as the wallpaper.
17
+ */
18
+ export declare function GradientWallpaperStill({ config }: {
19
+ config: GradientConfig;
20
+ }): import("react").JSX.Element;