rift-ds 1.36.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.
- package/README.md +1 -1
- package/behaviors/matchParts.d.ts +9 -0
- package/behaviors/matchParts.js +10 -0
- package/behaviors/useLayer.d.ts +2 -2
- package/behaviors/whenProgramLinked.d.ts +26 -0
- package/behaviors/whenProgramLinked.js +22 -0
- package/bin/templates/blocks/app/landing/page.module.css +50 -0
- package/bin/templates/blocks/app/landing/page.tsx +157 -0
- package/bin/templates/blocks/app/pricing/page.module.css +15 -0
- package/bin/templates/blocks/app/pricing/page.tsx +173 -0
- package/bin/templates/blocks/components/blocks/MarketingShell.module.css +66 -0
- package/bin/templates/blocks/components/blocks/MarketingShell.tsx +141 -0
- package/bin/templates/blocks/components/blocks/emberScene.ts +1 -1
- package/bin/templates/blocks/registry.json +24 -0
- package/chat/AssistantTurn.js +5 -20
- package/components/Chart/ActiveReporter.d.ts +32 -0
- package/components/Chart/ActiveReporter.js +31 -0
- package/components/Chart/AreaChart.d.ts +7 -1
- package/components/Chart/AreaChart.js +8 -3
- package/components/Chart/BarChart.d.ts +12 -0
- package/components/Chart/BarChart.js +8 -3
- package/components/Chart/ComboChart.d.ts +7 -1
- package/components/Chart/ComboChart.js +8 -3
- package/components/Chart/LineChart.d.ts +7 -1
- package/components/Chart/LineChart.js +8 -3
- package/components/Chart/StackedBarChart.d.ts +7 -1
- package/components/Chart/StackedBarChart.js +8 -3
- package/components/Combobox/Combobox.css +26 -0
- package/components/Combobox/Combobox.d.ts +10 -0
- package/components/Combobox/Combobox.js +10 -0
- package/components/CommandPalette/CommandPalette.css +26 -0
- package/components/CommandPalette/CommandPalette.d.ts +2 -1
- package/components/CommandPalette/CommandPalette.js +21 -4
- package/components/Drawer/Drawer.css +49 -7
- package/components/Drawer/Drawer.d.ts +17 -1
- package/components/Drawer/Drawer.js +27 -5
- package/components/Dropdown/Dropdown.css +40 -0
- package/components/Dropdown/Dropdown.d.ts +7 -0
- package/components/Dropdown/Dropdown.js +23 -38
- package/components/Instructions/Instructions.css +21 -0
- package/components/Instructions/Instructions.d.ts +5 -2
- package/components/Instructions/Instructions.js +1 -1
- package/components/Mention/Mention.js +6 -6
- package/components/NavList/NavList.d.ts +2 -0
- package/components/NavList/NavList.js +1 -0
- package/components/ShaderField/useShaderField.js +63 -27
- package/components/ShaderScene/ShaderScene.d.ts +3 -2
- package/components/ShaderScene/ShaderScene.js +135 -95
- package/components/ShaderScene/assemble.js +13 -5
- package/components/ShaderScene/renderer.d.ts +17 -5
- package/components/ShaderScene/renderer.js +45 -14
- package/components/ShaderScene/types.d.ts +2 -1
- package/components/SiteHeader/SiteHeader.css +15 -0
- package/components/registry.json +3 -3
- package/components/registry.json.d.ts +3 -3
- package/components/registry.json.js +1 -1
- package/markdown/index.d.ts +8 -0
- package/markdown/index.js +10 -0
- package/markdown/mappers.d.ts +31 -0
- package/markdown/mappers.js +43 -0
- package/package.json +7 -2
- package/tokens/presets/contrast.css +8 -0
- package/tokens/presets/forest.css +8 -0
- package/tokens/presets/plum.css +18 -5
- package/tokens/presets/warm.css +10 -5
- package/tokens/presets/zest.css +22 -5
- package/tokens/values.json.js +1 -1
|
@@ -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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
gl.
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 = () => {
|
|
@@ -87,8 +87,9 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
|
|
|
87
87
|
*
|
|
88
88
|
* Every scene but the ocean and the sky is a night scene: it adds light over a dark
|
|
89
89
|
* ground. On a light page each computes its light against a dark ground of
|
|
90
|
-
* its own and lays it onto the page as
|
|
91
|
-
*
|
|
90
|
+
* its own and lays it onto the page as colour, its brightest marks as a
|
|
91
|
+
* deepened ink of the scene's lead colour, so it reads as a dawn on paper
|
|
92
|
+
* rather than a dark block, and a crest or a beam stays visible on white. The ocean paints both: a turquoise shallow
|
|
92
93
|
* over a light page ground, deep moonlit water over a dark one. The sky does
|
|
93
94
|
* too: a golden hour over a light ground, the last of a sunset under a night sky
|
|
94
95
|
* over a dark one. Nothing here
|
|
@@ -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 {
|
|
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
|
-
|
|
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 || !
|
|
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
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(" ");
|
|
@@ -50,16 +50,24 @@ void main() {
|
|
|
50
50
|
vec2 uv = gl_FragCoord.xy / u_size;
|
|
51
51
|
vec3 lin = scene(uv, u_time);
|
|
52
52
|
/* A night scene on a light page: the light it adds over its own dark
|
|
53
|
-
ground is laid onto the page as
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
ground is laid onto the page as colour, so a horizon reads as a dawn
|
|
54
|
+
on paper rather than a dark block on it, and the brightest marks
|
|
55
|
+
(a crest, a beam) read as ink rather than vanishing into the white. */
|
|
56
56
|
if (u_lightMode > 0.5) {
|
|
57
57
|
vec3 light = max(lin - u_ground, vec3(0.0));
|
|
58
58
|
float peak = max(light.r, max(light.g, light.b));
|
|
59
59
|
vec3 hue = light / max(peak, 1e-4);
|
|
60
60
|
vec3 pastel = mix(hue, vec3(1.0), 0.3);
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
/* Most of the light is laid on as ink rather than tint: its hue
|
|
62
|
+
resaturated, leaning to the scene's lead colour and deepened, so a
|
|
63
|
+
bright crest darkens against the paper instead of washing out to
|
|
64
|
+
white on it. */
|
|
65
|
+
float hueGrey = dot(hue, vec3(1.0 / 3.0));
|
|
66
|
+
vec3 lead = u_col[0] / max(max(u_col[0].r, max(u_col[0].g, u_col[0].b)), 1e-4);
|
|
67
|
+
vec3 rich = mix(clamp(hueGrey + (hue - hueGrey) * 3.0, 0.0, 1.0), lead, 0.6) * 0.5;
|
|
68
|
+
vec3 tint = mix(u_page * pastel, u_page * rich, 0.8);
|
|
69
|
+
float strength = clamp(pow(dot(light, vec3(0.2126, 0.7152, 0.0722)) * 8.0, 0.7), 0.0, 0.9);
|
|
70
|
+
lin = mix(u_page, tint, strength);
|
|
63
71
|
}
|
|
64
72
|
${call("light", "lin")}
|
|
65
73
|
vec3 srgb = pow(max(lin, vec3(0.0)), vec3(1.0 / 2.2));
|
|
@@ -5,7 +5,7 @@ export type Colours = {
|
|
|
5
5
|
ground: Rgb;
|
|
6
6
|
/** The page's own ground, which the passes fade to. */
|
|
7
7
|
page: Rgb;
|
|
8
|
-
/** A night scene on a light page, laid on as
|
|
8
|
+
/** A night scene on a light page, laid on as colour and ink. */
|
|
9
9
|
lightMode: boolean;
|
|
10
10
|
colours: Rgb[];
|
|
11
11
|
};
|
|
@@ -14,7 +14,7 @@ export declare function readColours(host: HTMLElement, tokens: string[]): Colour
|
|
|
14
14
|
/**
|
|
15
15
|
* A scene's colours for a surface: read from the cascade. A night-only
|
|
16
16
|
* scene on a light page computes its light against a dark ground of its
|
|
17
|
-
* own, and the shader lays that light onto the page as
|
|
17
|
+
* own, and the shader lays that light onto the page as colour and ink
|
|
18
18
|
* (u_lightMode), so its masks still fade to the page and the theme stays
|
|
19
19
|
* light.
|
|
20
20
|
*/
|
|
@@ -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
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
|
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
|
|
71
|
-
const vs =
|
|
72
|
-
const fs =
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
};
|
|
@@ -38,7 +38,8 @@ export type ShaderSceneSource = {
|
|
|
38
38
|
/**
|
|
39
39
|
* `dark` for a scene that only adds light and so only reads on a dark
|
|
40
40
|
* ground. On a light page its light is computed against a near-black
|
|
41
|
-
* ground of its own and laid onto the page as
|
|
41
|
+
* ground of its own and laid onto the page as colour, its brightest
|
|
42
|
+
* marks as a deepened ink of the scene's first colour. A scene
|
|
42
43
|
* without it paints for both modes itself, from the page ground
|
|
43
44
|
* (`u_ground`).
|
|
44
45
|
*/
|
|
@@ -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
|