rift-ds 1.37.0 → 1.37.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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Waits for a WebGL program to finish linking without making the page wait
3
+ * for it.
4
+ *
5
+ * A browser compiles and links a shader away from the main thread, and the
6
+ * first question that needs the answer (`COMPILE_STATUS`, `LINK_STATUS`, a
7
+ * uniform's location, a draw) stops the main thread until the work is done.
8
+ * On a driver that translates the shader first (Direct3D on Windows) that
9
+ * is a tenth of a second for a small program and seconds for a large one,
10
+ * during which the page answers no press, scroll or key.
11
+ *
12
+ * `KHR_parallel_shader_compile` adds the one question that never waits:
13
+ * whether the work has finished. This asks it once a frame and calls `done`
14
+ * when the answer is yes, so every status read after it returns at once.
15
+ * The rule for a caller: after `linkProgram`, touch nothing about the
16
+ * program or its shaders until `done` runs, and read the statuses there.
17
+ *
18
+ * Without the extension `done` runs at once and the caller's status read
19
+ * waits as it always did. On a context that is lost before the link ends
20
+ * `done` still runs: the statuses then read as failed, which is the truth.
21
+ *
22
+ * Returns a cancel, for a caller that unmounts first; a cancelled wait
23
+ * never calls `done`. `scripts/validate-shader-linking.mjs` holds every
24
+ * `linkProgram` in the library and the site to this.
25
+ */
26
+ export declare function whenProgramLinked(gl: WebGL2RenderingContext, program: WebGLProgram, done: () => void): () => void;
@@ -0,0 +1,22 @@
1
+ function whenProgramLinked(gl, program, done) {
2
+ const parallel = gl.getExtension("KHR_parallel_shader_compile");
3
+ if (!parallel) {
4
+ done();
5
+ return () => {
6
+ };
7
+ }
8
+ let frame = 0;
9
+ const ask = () => {
10
+ if (gl.isContextLost() || gl.getProgramParameter(program, parallel.COMPLETION_STATUS_KHR)) {
11
+ frame = 0;
12
+ done();
13
+ return;
14
+ }
15
+ frame = requestAnimationFrame(ask);
16
+ };
17
+ ask();
18
+ return () => cancelAnimationFrame(frame);
19
+ }
20
+ export {
21
+ whenProgramLinked
22
+ };
@@ -2,6 +2,7 @@
2
2
  import { useState, useRef, useEffect } from "react";
3
3
  import { BLOB_COUNT, vertexSource, fragmentSource } from "./field.glsl.js";
4
4
  import { MOTION_CONTEXT_RESTORE_WAIT_MS, MOTION_SHADER_COLOR_CHECK_MS, MOTION_SHADER_COLOR_FADE_MS } from "../../tokens/motion.js";
5
+ import { whenProgramLinked } from "../../behaviors/whenProgramLinked.js";
5
6
  const DEFAULT_SHADER_PARAMS = {
6
7
  intensity: 0.5,
7
8
  warp: 0.14,
@@ -59,11 +60,6 @@ function compile(gl, type, source) {
59
60
  if (!shader) return null;
60
61
  gl.shaderSource(shader, source);
61
62
  gl.compileShader(shader);
62
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
63
- console.error("ShaderField compile error:", gl.getShaderInfoLog(shader));
64
- gl.deleteShader(shader);
65
- return null;
66
- }
67
63
  return shader;
68
64
  }
69
65
  function useShaderField(canvasRef, params, enabled = true) {
@@ -98,22 +94,47 @@ function useShaderField(canvasRef, params, enabled = true) {
98
94
  let program = null;
99
95
  let vao = null;
100
96
  let loc = {};
101
- function initGL() {
102
- if (!gl) return false;
97
+ let cancelLink = () => {
98
+ };
99
+ function initGL(ready) {
100
+ if (!gl) return ready(false);
101
+ cancelLink();
103
102
  const vs = compile(gl, gl.VERTEX_SHADER, vertexSource);
104
103
  const fs = compile(gl, gl.FRAGMENT_SHADER, fragmentSource);
105
- if (!vs || !fs) return false;
106
- program = gl.createProgram();
107
- if (!program) return false;
108
- gl.attachShader(program, vs);
109
- gl.attachShader(program, fs);
110
- gl.linkProgram(program);
111
- gl.deleteShader(vs);
112
- gl.deleteShader(fs);
113
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
114
- console.error("ShaderField link error:", gl.getProgramInfoLog(program));
104
+ const linking = gl.createProgram();
105
+ if (!vs || !fs || !linking) {
106
+ gl.deleteShader(vs);
107
+ gl.deleteShader(fs);
108
+ gl.deleteProgram(linking);
109
+ return ready(false);
110
+ }
111
+ gl.attachShader(linking, vs);
112
+ gl.attachShader(linking, fs);
113
+ gl.linkProgram(linking);
114
+ cancelLink = whenProgramLinked(gl, linking, () => {
115
+ cancelLink = () => {
116
+ };
117
+ ready(finishGL(linking, vs, fs));
118
+ });
119
+ }
120
+ function finishGL(linking, vs, fs) {
121
+ if (!gl) return false;
122
+ if (!gl.getProgramParameter(linking, gl.LINK_STATUS)) {
123
+ for (const shader of [vs, fs]) {
124
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
125
+ console.error("ShaderField compile error:", gl.getShaderInfoLog(shader));
126
+ }
127
+ }
128
+ console.error("ShaderField link error:", gl.getProgramInfoLog(linking));
129
+ gl.deleteShader(vs);
130
+ gl.deleteShader(fs);
131
+ gl.deleteProgram(linking);
115
132
  return false;
116
133
  }
134
+ gl.deleteShader(vs);
135
+ gl.deleteShader(fs);
136
+ if (program) gl.deleteProgram(program);
137
+ program = linking;
117
138
  gl.useProgram(program);
118
139
  vao = gl.createVertexArray();
119
140
  gl.bindVertexArray(vao);
@@ -194,13 +215,19 @@ function useShaderField(canvasRef, params, enabled = true) {
194
215
  let bufWidth = 0;
195
216
  let bufHeight = 0;
196
217
  let cssWidth = 0;
218
+ let cssHeight = 0;
219
+ let boxStale = true;
197
220
  function resize() {
198
221
  if (!gl) return;
199
222
  const c = canvas;
200
223
  const dpr = window.devicePixelRatio || 1;
201
- cssWidth = c.clientWidth;
202
- const w = Math.max(1, Math.round(c.clientWidth * dpr * RENDER_SCALE));
203
- const h = Math.max(1, Math.round(c.clientHeight * dpr * RENDER_SCALE));
224
+ if (boxStale) {
225
+ boxStale = false;
226
+ cssWidth = c.clientWidth;
227
+ cssHeight = c.clientHeight;
228
+ }
229
+ const w = Math.max(1, Math.round(cssWidth * dpr * RENDER_SCALE));
230
+ const h = Math.max(1, Math.round(cssHeight * dpr * RENDER_SCALE));
204
231
  if (w === bufWidth && h === bufHeight) return;
205
232
  bufWidth = w;
206
233
  bufHeight = h;
@@ -342,6 +369,7 @@ function useShaderField(canvasRef, params, enabled = true) {
342
369
  attributeFilter: ["data-theme", "data-brand", "style"]
343
370
  });
344
371
  const resizeObserver = new ResizeObserver(() => {
372
+ boxStale = true;
345
373
  if (!running) {
346
374
  renderOnce();
347
375
  }
@@ -372,7 +400,9 @@ function useShaderField(canvasRef, params, enabled = true) {
372
400
  }, MOTION_CONTEXT_RESTORE_WAIT_MS);
373
401
  };
374
402
  const onContextRestored = () => {
375
- if (initGL()) {
403
+ program = null;
404
+ initGL((ok) => {
405
+ if (disposed || !ok) return;
376
406
  bufWidth = 0;
377
407
  bufHeight = 0;
378
408
  uploadedBlobs = null;
@@ -380,7 +410,7 @@ function useShaderField(canvasRef, params, enabled = true) {
380
410
  setActive(true);
381
411
  if (reduceQuery.matches) renderOnce();
382
412
  else start();
383
- }
413
+ });
384
414
  };
385
415
  canvas.addEventListener("webglcontextlost", onContextLost);
386
416
  canvas.addEventListener("webglcontextrestored", onContextRestored);
@@ -395,15 +425,21 @@ function useShaderField(canvasRef, params, enabled = true) {
395
425
  queueMicrotask(() => setSupported(false));
396
426
  }
397
427
  }
398
- } else if (initGL()) {
399
- draw(COLOR_FADE_MS);
400
- setActive(true);
401
- start();
402
428
  } else {
403
- setSupported(false);
429
+ initGL((ok) => {
430
+ if (disposed) return;
431
+ if (!ok) {
432
+ setSupported(false);
433
+ return;
434
+ }
435
+ draw(COLOR_FADE_MS);
436
+ setActive(true);
437
+ start();
438
+ });
404
439
  }
405
440
  return () => {
406
441
  disposed = true;
442
+ cancelLink();
407
443
  stop();
408
444
  window.clearTimeout(restoreTimer);
409
445
  redrawRef.current = () => {
@@ -5,7 +5,7 @@ import { MOTION_RENDERER_WATCHDOG_MS, MOTION_SHADER_COLOR_CHECK_MS } from "../..
5
5
  import { PASSES } from "./passes.js";
6
6
  import { warnOnce } from "../../behaviors/devWarning.js";
7
7
  import { sceneProblems } from "./assemble.js";
8
- import { createRenderer, glyphFontFor, coloursFor } from "./renderer.js";
8
+ import { createRendererWhenLinked, glyphFontFor, coloursFor } from "./renderer.js";
9
9
  import { bakeThumbnails } from "./renderer.js";
10
10
  import { SCENES } from "./scenes.js";
11
11
  import { defaultsFor } from "./types.js";
@@ -81,9 +81,15 @@ function ShaderScene({
81
81
  const [gaveUp, setGaveUp] = React.useState(false);
82
82
  const [restored, setRestored] = React.useState(0);
83
83
  const rebuildsWithoutPaint = React.useRef(0);
84
+ const compiling = React.useRef(false);
84
85
  React.useEffect(() => {
85
86
  if (!enabled || gl !== "pending") return;
86
- const timer = window.setTimeout(() => setGaveUp(true), MOTION_RENDERER_WATCHDOG_MS);
87
+ let timer = 0;
88
+ const check = () => {
89
+ if (compiling.current) timer = window.setTimeout(check, MOTION_RENDERER_WATCHDOG_MS);
90
+ else setGaveUp(true);
91
+ };
92
+ timer = window.setTimeout(check, MOTION_RENDERER_WATCHDOG_MS);
87
93
  return () => window.clearTimeout(timer);
88
94
  }, [enabled, gl]);
89
95
  const status = !enabled || gl === "failed" ? "unavailable" : gl === "painted" ? "active" : gaveUp ? "unavailable" : "pending";
@@ -112,13 +118,13 @@ function ShaderScene({
112
118
  const styles = getComputedStyle(host);
113
119
  sceneProblems(definition, PASSES, (property) => styles.getPropertyValue(property).trim() !== "").forEach(warnOnce);
114
120
  }
115
- const renderer = context ? createRenderer(context, definition, PASSES, (log) => {
116
- console.warn(log);
117
- reportError.current?.(log);
118
- }) : null;
119
121
  let lost = false;
120
122
  let near = false;
121
123
  let rebuildFrame = 0;
124
+ let start = () => {
125
+ };
126
+ let stop = () => {
127
+ };
122
128
  const rebuild = () => {
123
129
  if (rebuildsWithoutPaint.current >= 2) return;
124
130
  rebuildsWithoutPaint.current += 1;
@@ -142,81 +148,13 @@ function ShaderScene({
142
148
  canvas?.removeEventListener("webglcontextlost", onContextLost);
143
149
  canvas?.removeEventListener("webglcontextrestored", onContextRestored);
144
150
  };
145
- if (!host || !canvas || !renderer) {
151
+ if (!host || !canvas || !context) {
146
152
  const failed = requestAnimationFrame(() => setGl("failed"));
147
153
  return () => {
148
154
  cancelAnimationFrame(failed);
149
155
  unlisten();
150
156
  };
151
157
  }
152
- const colourTokens = ["--color-bg-page-primary", ...definition.colours];
153
- const colourSignature = () => {
154
- const styles = getComputedStyle(host);
155
- return [
156
- document.documentElement.getAttribute("data-theme"),
157
- ...colourTokens.map((token) => styles.getPropertyValue(token).trim())
158
- ].join("|");
159
- };
160
- let appliedColours = "";
161
- let coloursChecked = 0;
162
- const applyColours = () => {
163
- appliedColours = colourSignature();
164
- renderer.setColours(coloursFor(host, definition));
165
- renderer.setGlyphs(glyphFontFor(host));
166
- };
167
- let ratio = 1;
168
- const fit = () => {
169
- ratio = Math.min(definition.pixelRatio ?? MAX_PIXEL_RATIO, window.devicePixelRatio || 1);
170
- const width = Math.max(1, Math.round(host.clientWidth * ratio));
171
- const height = Math.max(1, Math.round(host.clientHeight * ratio));
172
- if (canvas.width === width && canvas.height === height) return;
173
- canvas.width = width;
174
- canvas.height = height;
175
- };
176
- const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
177
- let time = 20;
178
- let last = performance.now();
179
- let frame = 0;
180
- let painted = false;
181
- const draw = (now) => {
182
- frame = requestAnimationFrame(draw);
183
- if (lost) return;
184
- if (painted && now - last < FRAME_MS - 1) return;
185
- if (now - coloursChecked >= COLOUR_CHECK_MS) {
186
- coloursChecked = now;
187
- if (colourSignature() !== appliedColours) applyColours();
188
- }
189
- const values = liveRef?.current ?? mergedRef.current;
190
- const dt = Math.min(0.1, (now - last) / 1e3);
191
- last = now;
192
- if (!still) time += dt * values.speed;
193
- fit();
194
- renderer.draw(values, time, canvas.width, canvas.height, ratio);
195
- if (!painted) {
196
- painted = true;
197
- rebuildsWithoutPaint.current = 0;
198
- setGl("painted");
199
- }
200
- };
201
- const start = () => {
202
- if (frame) return;
203
- last = performance.now();
204
- frame = requestAnimationFrame(draw);
205
- };
206
- const stop = () => {
207
- cancelAnimationFrame(frame);
208
- frame = 0;
209
- };
210
- applyColours();
211
- start();
212
- let mounted = true;
213
- if (definition.glyphs) {
214
- document.fonts?.ready.then(() => {
215
- if (!mounted) return;
216
- renderer.setGlyphs("");
217
- renderer.setGlyphs(glyphFontFor(host));
218
- });
219
- }
220
158
  const visibilityObserver = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver(
221
159
  (entries) => {
222
160
  near = entries[entries.length - 1].isIntersecting;
@@ -228,30 +166,132 @@ function ShaderScene({
228
166
  );
229
167
  visibilityObserver?.observe(host);
230
168
  if (!visibilityObserver) near = true;
231
- const sizeObserver = new ResizeObserver(() => {
232
- if (frame || lost) return;
233
- fit();
234
- renderer.draw(liveRef?.current ?? mergedRef.current, time, canvas.width, canvas.height, ratio);
235
- });
236
- sizeObserver.observe(host);
237
- const themeObserver = new MutationObserver(applyColours);
238
- themeObserver.observe(document.documentElement, {
239
- attributes: true,
240
- attributeFilter: ["data-theme", "data-brand", "style"]
241
- });
242
- const onSheetLoad = (event) => {
243
- if (event.target instanceof HTMLLinkElement && colourSignature() !== appliedColours) applyColours();
169
+ const run = (renderer) => {
170
+ const colourTokens = ["--color-bg-page-primary", ...definition.colours];
171
+ const colourSignature = () => {
172
+ const styles = getComputedStyle(host);
173
+ return [
174
+ document.documentElement.getAttribute("data-theme"),
175
+ ...colourTokens.map((token) => styles.getPropertyValue(token).trim())
176
+ ].join("|");
177
+ };
178
+ let appliedColours = "";
179
+ let coloursChecked = 0;
180
+ const applyColours = () => {
181
+ appliedColours = colourSignature();
182
+ renderer.setColours(coloursFor(host, definition));
183
+ renderer.setGlyphs(glyphFontFor(host));
184
+ };
185
+ let ratio = 1;
186
+ let boxWidth = 0;
187
+ let boxHeight = 0;
188
+ let boxStale = true;
189
+ const fit = () => {
190
+ ratio = Math.min(definition.pixelRatio ?? MAX_PIXEL_RATIO, window.devicePixelRatio || 1);
191
+ if (boxStale) {
192
+ boxStale = false;
193
+ boxWidth = host.clientWidth;
194
+ boxHeight = host.clientHeight;
195
+ }
196
+ const width = Math.max(1, Math.round(boxWidth * ratio));
197
+ const height = Math.max(1, Math.round(boxHeight * ratio));
198
+ if (canvas.width === width && canvas.height === height) return;
199
+ canvas.width = width;
200
+ canvas.height = height;
201
+ };
202
+ const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
203
+ let time = 20;
204
+ let last = performance.now();
205
+ let frame = 0;
206
+ let painted = false;
207
+ const draw = (now) => {
208
+ frame = requestAnimationFrame(draw);
209
+ if (lost) return;
210
+ if (painted && now - last < FRAME_MS - 1) return;
211
+ if (now - coloursChecked >= COLOUR_CHECK_MS) {
212
+ coloursChecked = now;
213
+ if (colourSignature() !== appliedColours) applyColours();
214
+ }
215
+ const values = liveRef?.current ?? mergedRef.current;
216
+ const dt = Math.min(0.1, (now - last) / 1e3);
217
+ last = now;
218
+ if (!still) time += dt * values.speed;
219
+ fit();
220
+ renderer.draw(values, time, canvas.width, canvas.height, ratio);
221
+ if (!painted) {
222
+ painted = true;
223
+ rebuildsWithoutPaint.current = 0;
224
+ setGl("painted");
225
+ }
226
+ };
227
+ start = () => {
228
+ if (frame) return;
229
+ last = performance.now();
230
+ frame = requestAnimationFrame(draw);
231
+ };
232
+ stop = () => {
233
+ cancelAnimationFrame(frame);
234
+ frame = 0;
235
+ };
236
+ applyColours();
237
+ start();
238
+ let mounted = true;
239
+ if (definition.glyphs) {
240
+ document.fonts?.ready.then(() => {
241
+ if (!mounted) return;
242
+ renderer.setGlyphs("");
243
+ renderer.setGlyphs(glyphFontFor(host));
244
+ });
245
+ }
246
+ const sizeObserver = new ResizeObserver(() => {
247
+ boxStale = true;
248
+ if (frame || lost) return;
249
+ fit();
250
+ renderer.draw(liveRef?.current ?? mergedRef.current, time, canvas.width, canvas.height, ratio);
251
+ });
252
+ sizeObserver.observe(host);
253
+ const themeObserver = new MutationObserver(applyColours);
254
+ themeObserver.observe(document.documentElement, {
255
+ attributes: true,
256
+ attributeFilter: ["data-theme", "data-brand", "style"]
257
+ });
258
+ const onSheetLoad = (event) => {
259
+ if (event.target instanceof HTMLLinkElement && colourSignature() !== appliedColours) applyColours();
260
+ };
261
+ document.addEventListener("load", onSheetLoad, true);
262
+ return () => {
263
+ mounted = false;
264
+ document.removeEventListener("load", onSheetLoad, true);
265
+ stop();
266
+ sizeObserver.disconnect();
267
+ themeObserver.disconnect();
268
+ renderer.dispose();
269
+ };
244
270
  };
245
- document.addEventListener("load", onSheetLoad, true);
271
+ let teardown = null;
272
+ let failedFrame = 0;
273
+ compiling.current = true;
274
+ const cancelBuild = createRendererWhenLinked(
275
+ context,
276
+ definition,
277
+ PASSES,
278
+ (log) => {
279
+ console.warn(log);
280
+ reportError.current?.(log);
281
+ },
282
+ (renderer) => {
283
+ compiling.current = false;
284
+ if (renderer) teardown = run(renderer);
285
+ else failedFrame = requestAnimationFrame(() => setGl("failed"));
286
+ }
287
+ );
246
288
  return () => {
247
- mounted = false;
289
+ compiling.current = false;
290
+ cancelBuild();
291
+ cancelAnimationFrame(failedFrame);
248
292
  unlisten();
249
- document.removeEventListener("load", onSheetLoad, true);
250
- stop();
251
293
  visibilityObserver?.disconnect();
252
- sizeObserver.disconnect();
253
- themeObserver.disconnect();
254
- renderer.dispose();
294
+ teardown?.();
255
295
  };
256
296
  }, [definition, custom, liveRef, enabled, restored]);
257
297
  const classes = ["ds-shader-scene", className].filter(Boolean).join(" ");
@@ -24,9 +24,12 @@ export declare function glyphFontFor(host: HTMLElement): string;
24
24
  /** Where a compiler or linker log goes; the console by default. */
25
25
  type Report = (log: string) => void;
26
26
  /**
27
- * Compiles a scene with the passes. A scene that fails to compile or link
28
- * hands its log to `report` and returns null with nothing left on the
29
- * context; the log's line numbers are the scene's own (assemble.ts).
27
+ * Compiles a scene with the passes, waiting on the main thread for the
28
+ * result. For a caller that needs the picture in the same task (the
29
+ * thumbnail baker); a scene on a page uses `createRendererWhenLinked`. A
30
+ * scene that fails to compile or link hands its log to `report` and returns
31
+ * null with nothing left on the context; the log's line numbers are the
32
+ * scene's own (assemble.ts).
30
33
  */
31
34
  export declare function createRenderer(gl: WebGL2RenderingContext, scene: ShaderSceneSource, passes: Pass[], report?: Report): {
32
35
  setColours({ ground, page, lightMode, colours }: Colours): void;
@@ -35,6 +38,15 @@ export declare function createRenderer(gl: WebGL2RenderingContext, scene: Shader
35
38
  draw(values: Values, time: number, width: number, height: number, ratio?: number): void;
36
39
  dispose(): void;
37
40
  } | null;
41
+ /** What `createRenderer` returns for a scene that compiled. */
42
+ export type Renderer = NonNullable<ReturnType<typeof createRenderer>>;
43
+ /**
44
+ * `createRenderer` without the wait: the scene compiles and links away from
45
+ * the main thread, and `ready` gets the renderer once it has, or null for
46
+ * a scene that failed (its log goes to `report`). Returns a cancel, which
47
+ * drops the unfinished program; after `ready` it does nothing.
48
+ */
49
+ export declare function createRendererWhenLinked(gl: WebGL2RenderingContext, scene: ShaderSceneSource, passes: Pass[], report: Report, ready: (renderer: Renderer | null) => void): () => void;
38
50
  /**
39
51
  * Paints each recipe once on a throwaway context and returns the pictures
40
52
  * as data URLs, then releases the context, so the tiles cost no live GPU
@@ -1,3 +1,4 @@
1
+ import { whenProgramLinked } from "../../behaviors/whenProgramLinked.js";
1
2
  import { assemble, VERTEX } from "./assemble.js";
2
3
  import { MAX_COLOURS } from "./types.js";
3
4
  const NIGHT_GROUND = [15e-4, 18e-4, 3e-3];
@@ -55,35 +56,64 @@ function drawGlyphs(ramp, font) {
55
56
  }
56
57
  return { strip, count: glyphs.length };
57
58
  }
58
- function compile(gl, type, source, report) {
59
+ function shaderOf(gl, type, source) {
59
60
  const shader = gl.createShader(type);
60
61
  if (!shader) return null;
61
62
  gl.shaderSource(shader, source);
62
63
  gl.compileShader(shader);
63
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
64
- report(gl.getShaderInfoLog(shader) ?? "");
65
- gl.deleteShader(shader);
66
- return null;
67
- }
68
64
  return shader;
69
65
  }
70
- function createRenderer(gl, scene, passes, report = (log) => console.warn(log)) {
71
- const vs = compile(gl, gl.VERTEX_SHADER, VERTEX, report);
72
- const fs = compile(gl, gl.FRAGMENT_SHADER, assemble(scene, passes), report);
66
+ function begin(gl, scene, passes) {
67
+ const vs = shaderOf(gl, gl.VERTEX_SHADER, VERTEX);
68
+ const fs = shaderOf(gl, gl.FRAGMENT_SHADER, assemble(scene, passes));
73
69
  const program = gl.createProgram();
74
- const discard = () => {
70
+ if (!vs || !fs || !program) {
75
71
  gl.deleteProgram(program);
76
72
  gl.deleteShader(vs);
77
73
  gl.deleteShader(fs);
78
74
  return null;
79
- };
80
- if (!vs || !fs || !program) return discard();
75
+ }
81
76
  gl.attachShader(program, vs);
82
77
  gl.attachShader(program, fs);
83
78
  gl.linkProgram(program);
79
+ return { program, vs, fs };
80
+ }
81
+ function discard(gl, { program, vs, fs }) {
82
+ gl.deleteProgram(program);
83
+ gl.deleteShader(vs);
84
+ gl.deleteShader(fs);
85
+ return null;
86
+ }
87
+ function createRenderer(gl, scene, passes, report = (log) => console.warn(log)) {
88
+ const build = begin(gl, scene, passes);
89
+ return build ? finish(gl, build, scene, passes, report) : null;
90
+ }
91
+ function createRendererWhenLinked(gl, scene, passes, report, ready) {
92
+ const build = begin(gl, scene, passes);
93
+ if (!build) {
94
+ ready(null);
95
+ return () => {
96
+ };
97
+ }
98
+ let waiting = true;
99
+ const cancelWait = whenProgramLinked(gl, build.program, () => {
100
+ waiting = false;
101
+ ready(finish(gl, build, scene, passes, report));
102
+ });
103
+ return () => {
104
+ if (!waiting) return;
105
+ waiting = false;
106
+ cancelWait();
107
+ discard(gl, build);
108
+ };
109
+ }
110
+ function finish(gl, build, scene, passes, report) {
111
+ const { program, vs, fs } = build;
84
112
  if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
85
- report(gl.getProgramInfoLog(program) ?? "");
86
- return discard();
113
+ const failed = [vs, fs].filter((shader) => !gl.getShaderParameter(shader, gl.COMPILE_STATUS));
114
+ if (failed.length > 0) failed.forEach((shader) => report(gl.getShaderInfoLog(shader) ?? ""));
115
+ else report(gl.getProgramInfoLog(program) ?? "");
116
+ return discard(gl, build);
87
117
  }
88
118
  gl.useProgram(program);
89
119
  const vao = gl.createVertexArray();
@@ -177,6 +207,7 @@ export {
177
207
  bakeThumbnails,
178
208
  coloursFor,
179
209
  createRenderer,
210
+ createRendererWhenLinked,
180
211
  glyphFontFor,
181
212
  readColours
182
213
  };
@@ -261,6 +261,21 @@
261
261
  pointer-events: auto;
262
262
  }
263
263
 
264
+ /* The hover bridge. Between a pill and its menu lie the bar's lower padding
265
+ and the gap the menu hangs by, and neither is the pill nor the menu: a
266
+ pointer that took longer than the hide delay to cross them lost the menu
267
+ on the way, and the press landed on the page. While a menu is open the
268
+ wrapper holds that strip too, so the way down never leaves the menu. It
269
+ stays inside the bar's padding, clear of every control in the row. */
270
+ .ds-site-header__panel:has(> .ds-mega-menu--open)::before {
271
+ content: '';
272
+ position: absolute;
273
+ inset-inline: 0;
274
+ inset-block-end: 100%;
275
+ block-size: calc(var(--gap-200) + var(--padding-1000) / 2);
276
+ pointer-events: auto;
277
+ }
278
+
264
279
  /* A full-width bar wider than the contained width keeps its menu at the
265
280
  contained width and opens it where the reader is looking: the panel
266
281
  starts under the section pills (--ds-site-header-nav-start, measured as
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rift-ds",
3
- "version": "1.37.0",
3
+ "version": "1.37.1",
4
4
  "description": "An AI-ready React design system: accessible components on composable tokens, light/dark theming, and CSS-variable overrides.",
5
5
  "author": {
6
6
  "name": "Robert Ritacca",