rift-ds 1.28.0 → 1.29.0

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 CHANGED
@@ -76,7 +76,7 @@ The quickest start is one file: save [AGENTS.md](https://rift-ds.com/AGENTS.md)
76
76
  curl -o AGENTS.md https://rift-ds.com/AGENTS.md
77
77
  ```
78
78
 
79
- For the full setup, one command teaches a coding agent the system: it installs the generated agent skills into your project and prints the MCP connect line. The skills cover the library's rules, moving existing screens onto the tokens and components, and auditing styles against them.
79
+ For the full setup, one command teaches a coding agent the system: it installs the generated agent skills into your project and prints the MCP connect line. The skills cover the library's rules, moving existing screens onto the tokens and components, auditing styles against them, and writing a shader scene of your own.
80
80
 
81
81
  ```bash
82
82
  npx rift-ds init
package/bin/rift-ds.mjs CHANGED
@@ -121,10 +121,11 @@ init chat
121
121
 
122
122
  init block [<name>]
123
123
  Copies a block into a Next.js app router project: a whole starting page
124
- (an app shell, a dashboard, a sign-in) built from the library, its page
125
- under app/ and any shared parts under components/blocks/. The files are
126
- yours from then on. With no name, lists the blocks. Run init app first.
127
- Existing files are never overwritten.
124
+ (an app shell, a dashboard, a sign-in, a shader scene) built from the
125
+ library, its page under app/ and any shared parts under
126
+ components/blocks/. The files are yours from then on. With no name,
127
+ lists the blocks. Run init app first. Existing files are never
128
+ overwritten.
128
129
 
129
130
  --app <dir> The app router folder (default: app/ or src/app/, whichever exists)
130
131
  --dry-run Print what would be written and write nothing
@@ -0,0 +1,75 @@
1
+ /* The scene on a stage beside its controls: two columns on a desktop, the
2
+ stage above the panel on a phone. The stage is the scene's positioned
3
+ ancestor, and it clips the scene to its own rounded box. */
4
+
5
+ .page {
6
+ min-height: 100dvh;
7
+ display: grid;
8
+ grid-template-columns: minmax(0, 1fr) 320px;
9
+ gap: var(--gap-500);
10
+ padding: var(--padding-500);
11
+ background-color: var(--color-bg-page-primary);
12
+ }
13
+
14
+ .stage {
15
+ position: relative;
16
+ min-height: 320px;
17
+ overflow: hidden;
18
+ border-radius: var(--radius-600);
19
+ background-color: var(--color-bg-container-secondary);
20
+ }
21
+
22
+ .panel {
23
+ align-self: start;
24
+ display: flex;
25
+ flex-direction: column;
26
+ gap: var(--gap-500);
27
+ padding: var(--padding-500);
28
+ border-radius: var(--radius-600);
29
+ background-color: var(--color-bg-container-primary);
30
+ }
31
+
32
+ .intro {
33
+ display: flex;
34
+ flex-direction: column;
35
+ gap: var(--gap-200);
36
+ }
37
+
38
+ .title {
39
+ margin: 0;
40
+ font-family: var(--font-heading-2-family);
41
+ font-size: var(--font-heading-2-size);
42
+ font-weight: var(--font-heading-2-weight);
43
+ line-height: var(--font-heading-2-line-height);
44
+ letter-spacing: var(--font-heading-2-letter-spacing);
45
+ color: var(--color-text-primary);
46
+ }
47
+
48
+ .subhead,
49
+ .note {
50
+ margin: 0;
51
+ font-size: var(--font-paragraph-sm-size);
52
+ line-height: var(--font-paragraph-sm-line-height);
53
+ color: var(--color-text-secondary);
54
+ }
55
+
56
+ .log {
57
+ margin: 0;
58
+ padding: var(--padding-300);
59
+ overflow-x: auto;
60
+ border-radius: var(--radius-300);
61
+ background-color: var(--color-bg-container-secondary);
62
+ font-family: var(--font-family-code);
63
+ font-size: var(--font-paragraph-sm-size);
64
+ line-height: var(--font-paragraph-sm-line-height);
65
+ color: var(--color-text-primary);
66
+ white-space: pre-wrap;
67
+ }
68
+
69
+ @media (max-width: 959px) {
70
+ .page {
71
+ grid-template-columns: minmax(0, 1fr);
72
+ grid-template-rows: minmax(320px, 50dvh) auto;
73
+ padding: var(--padding-400);
74
+ }
75
+ }
@@ -0,0 +1,81 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * The shader scene block: a scene of your own on a stage, with a slider for
5
+ * each setting it declares. The scene is `emberScene` in
6
+ * components/blocks/emberScene.ts; edit its GLSL and this page follows.
7
+ */
8
+
9
+ import { useState } from 'react';
10
+ import {
11
+ SHADER_PASSES,
12
+ ShaderScene,
13
+ shaderSceneDefaults,
14
+ type ShaderSceneStatus,
15
+ type ShaderSceneValues,
16
+ } from 'rift-ds/components/ShaderScene/ShaderScene';
17
+ import { Slider } from 'rift-ds/components/Slider/Slider';
18
+ import { emberScene } from '../../components/blocks/emberScene';
19
+ import styles from './page.module.css';
20
+
21
+ const SPEED = 1.6;
22
+
23
+ /* What the scene reads each frame: its own settings and every finishing
24
+ pass, at their defaults, with the two fades off so the light fills the
25
+ stage. */
26
+ const initialValues = (): ShaderSceneValues => ({
27
+ speed: SPEED,
28
+ scene: shaderSceneDefaults(emberScene.params),
29
+ passes: Object.fromEntries(
30
+ SHADER_PASSES.map((pass) => [
31
+ pass.id,
32
+ { on: pass.id.startsWith('fade') ? false : pass.on, params: shaderSceneDefaults(pass.params) },
33
+ ])
34
+ ),
35
+ });
36
+
37
+ export default function ShaderScenePage() {
38
+ /* The sliders write this ref and the scene reads it every frame, so a
39
+ drag moves the picture without rendering the page. */
40
+ const [values] = useState(() => ({ current: initialValues() }));
41
+
42
+ const [status, setStatus] = useState<ShaderSceneStatus>('pending');
43
+ const [error, setError] = useState<string>();
44
+
45
+ return (
46
+ <div className={styles.page}>
47
+ <div className={styles.stage}>
48
+ <ShaderScene scene={emberScene} liveRef={values} onStatusChange={setStatus} onError={setError} />
49
+ </div>
50
+
51
+ <main className={styles.panel}>
52
+ <div className={styles.intro}>
53
+ <h1 className={styles.title}>Ember</h1>
54
+ <p className={styles.subhead}>A scene of your own, in the theme’s colours.</p>
55
+ </div>
56
+
57
+ {emberScene.params.map((param) => (
58
+ <Slider
59
+ key={param.key}
60
+ label={param.label}
61
+ min={param.min}
62
+ max={param.max}
63
+ step={param.step}
64
+ defaultValue={param.default}
65
+ showValue
66
+ onValueChange={(value) => {
67
+ values.current.scene[param.key] = value;
68
+ }}
69
+ />
70
+ ))}
71
+
72
+ {status === 'unavailable' && (
73
+ <p className={styles.note} role="status">
74
+ {error ? 'The scene did not compile:' : 'This browser cannot run the scene.'}
75
+ </p>
76
+ )}
77
+ {error && <pre className={styles.log}>{error}</pre>}
78
+ </main>
79
+ </div>
80
+ );
81
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A shader scene of your own, for ShaderScene's `scene` prop: a bed of
3
+ * light that rises in slow tongues. Rename it, then change it. The three
4
+ * parts are everything a scene is:
5
+ *
6
+ * - `colours`: the custom properties it reads, handed to the GLSL as
7
+ * `u_col[0]`, `u_col[1]` and so on. Naming the theme's ambient roles
8
+ * means it follows the theme and the colour mode.
9
+ * - `params`: its settings. Each arrives as `uniform float u_<key>`,
10
+ * declared for you, and is set through the component's `params` prop.
11
+ * - `glsl`: `vec3 scene(vec2 uv, float t)`, returning the pixel's linear
12
+ * colour over the ground (`u_ground`). `uv` runs 0 to 1 from the bottom
13
+ * left, `t` is seconds, and `fbm`, `vnoise`, `rnd` and `lobe` are there
14
+ * to call.
15
+ *
16
+ * `mode: 'dark'` says it only adds light: on a light page the component
17
+ * lays that light on as a pale tint. Leave it out for a scene that paints
18
+ * both modes itself.
19
+ */
20
+
21
+ import type { ShaderSceneSource } from 'rift-ds/components/ShaderScene/ShaderScene';
22
+
23
+ export const emberScene: ShaderSceneSource = {
24
+ mode: 'dark',
25
+ colours: ['--color-ambient-4', '--color-ambient-5'],
26
+ params: [
27
+ { key: 'glow', label: 'Glow', min: 0, max: 2, step: 0.01, default: 1 },
28
+ { key: 'height', label: 'Height', min: 0.1, max: 1.5, step: 0.01, default: 0.8 },
29
+ { key: 'scale', label: 'Scale', min: 0.5, max: 6, step: 0.05, default: 2.4 },
30
+ ],
31
+ glsl: /* glsl */ `
32
+ vec3 scene(vec2 uv, float t) {
33
+ // Square the space up, so the noise is not stretched on a wide stage.
34
+ float aspect = u_size.x / u_size.y;
35
+ vec2 p = vec2((uv.x - 0.5) * aspect, uv.y);
36
+
37
+ // How high the light reaches in this column: slow noise, drifting.
38
+ float reach = u_height * (0.35 + 1.1 * fbm(vec2(p.x * u_scale + t * 0.05, t * 0.08)));
39
+
40
+ // Brightest at the floor and gone at its reach, with a soft top edge.
41
+ float body = smoothstep(reach, 0.0, uv.y);
42
+ body *= body;
43
+
44
+ // Finer noise rising through it lifts the second colour out as embers.
45
+ float fine = fbm(vec2(p.x, uv.y) * u_scale * 5.0 - vec2(0.0, t * 0.35));
46
+ float embers = smoothstep(0.5, 0.85, fine) * body;
47
+
48
+ // Add the light to the ground: the fades and light mode depend on it.
49
+ vec3 light = (u_col[0] * body * 1.2 + u_col[1] * embers * 0.5) * u_glow;
50
+ return u_ground + light;
51
+ }
52
+ `,
53
+ };
@@ -34,6 +34,17 @@
34
34
  "app/sign-in/page.tsx",
35
35
  "app/sign-in/page.module.css"
36
36
  ]
37
+ },
38
+ {
39
+ "name": "shader-scene",
40
+ "label": "Shader scene",
41
+ "description": "A shader scene of your own on a stage, written in GLSL from the theme's colour roles, with a slider for each setting it declares.",
42
+ "route": "/shader",
43
+ "files": [
44
+ "components/blocks/emberScene.ts",
45
+ "app/shader/page.tsx",
46
+ "app/shader/page.module.css"
47
+ ]
37
48
  }
38
49
  ]
39
50
  }
package/chat/threads.js CHANGED
@@ -35,10 +35,13 @@ function useThreads(chat, options = {}) {
35
35
  const [groups, setGroups] = useState(initialGroups);
36
36
  const [activeThreadId, setActiveThreadId] = useState("");
37
37
  const [renamingId, setRenamingId] = useState(null);
38
- const [projects, setProjects] = useState(options.projects ?? []);
39
- const [activeProjectId, setActiveProjectId] = useState(
40
- options.projects?.[0]?.id
38
+ const [addedProjects, setAddedProjects] = useState([]);
39
+ const projects = useMemo(
40
+ () => [...options.projects ?? [], ...addedProjects],
41
+ [options.projects, addedProjects]
41
42
  );
43
+ const [pickedProjectId, setActiveProjectId] = useState(void 0);
44
+ const activeProjectId = projects.some((project) => project.id === pickedProjectId) ? pickedProjectId : projects[0]?.id;
42
45
  const [openTabs, setOpenTabs] = useState([]);
43
46
  const threadSeq = useRef(0);
44
47
  const nameCursor = useRef(0);
@@ -199,7 +202,7 @@ function useThreads(chat, options = {}) {
199
202
  projectSeq.current += 1;
200
203
  const id = `project-${projectSeq.current}`;
201
204
  const index = projectSeq.current;
202
- setProjects((list) => [...list, { id, label: labels.newProject(index), meta: labels.newProjectMeta }]);
205
+ setAddedProjects((list) => [...list, { id, label: labels.newProject(index), meta: labels.newProjectMeta }]);
203
206
  setActiveProjectId(id);
204
207
  }, [labels]);
205
208
  const actionsFor = useCallback(
@@ -573,6 +573,44 @@
573
573
  height: 100%;
574
574
  }
575
575
 
576
+ /* ============================================
577
+ GLASS
578
+ glass: the button frosts what is behind it, for a busy ground. The blur
579
+ is the floating surfaces' own. An outlined or ghost cell takes the glass
580
+ fill at rest; a filled cell keeps its colour and lets a little of the
581
+ ground through it. These sit after the cells' rest rules and match
582
+ their weight, so they win at rest (and on a disabled button, which
583
+ keeps its glass under the usual dimming), while every pointer hover and
584
+ press rule above carries one more class and still fills the button
585
+ solid. The documentation-only hover and active classes are left out
586
+ through :where(), which adds no weight, so a forced state shows the
587
+ cell's own fill too.
588
+ ============================================ */
589
+
590
+ .ds-button--glass {
591
+ -webkit-backdrop-filter: blur(24px);
592
+ backdrop-filter: blur(24px);
593
+ }
594
+
595
+ .ds-button--glass.ds-button--secondary:where(:not(.ds-button--hover, .ds-button--active)),
596
+ .ds-button--glass.ds-button--secondary-neutral:where(:not(.ds-button--hover, .ds-button--active)),
597
+ .ds-button--glass.ds-button--tertiary:where(:not(.ds-button--hover, .ds-button--active)),
598
+ .ds-button--glass.ds-button--destructive:where(:not(.ds-button--hover, .ds-button--active)) {
599
+ background-color: var(--color-bg-glass);
600
+ }
601
+
602
+ .ds-button--glass.ds-button--primary:where(:not(.ds-button--hover, .ds-button--active)) {
603
+ background-color: color-mix(in srgb, var(--color-action-primary-bg) 72%, transparent);
604
+ }
605
+
606
+ .ds-button--glass.ds-button--neutral:where(:not(.ds-button--hover, .ds-button--active)) {
607
+ background-color: color-mix(in srgb, var(--color-action-neutral-bg) 72%, transparent);
608
+ }
609
+
610
+ .ds-button--glass.ds-button--primary-destructive:where(:not(.ds-button--hover, .ds-button--active)) {
611
+ background-color: color-mix(in srgb, var(--color-action-destructive-bg) 72%, transparent);
612
+ }
613
+
576
614
  /* ============================================
577
615
  FOCUS
578
616
  ============================================ */
@@ -44,6 +44,14 @@ type ButtonOwnProps = {
44
44
  * `disabled`) and sets `aria-busy` on the rendered element.
45
45
  */
46
46
  loading?: boolean;
47
+ /**
48
+ * Frosts the button for a busy ground (a shader, a photo, a chart): the
49
+ * page behind it is blurred, an outlined or ghost button takes the glass
50
+ * fill at rest and a filled one lets a little of the ground through its
51
+ * colour. Hover and press are the variant's own. Works on every `variant`
52
+ * and `tone`.
53
+ */
54
+ glass?: boolean;
47
55
  /** Optional href — renders as <a> instead of <button> */
48
56
  href?: string;
49
57
  /** Optional target attribute for links */
@@ -35,6 +35,7 @@ const Button = React.forwardRef(
35
35
  size = "default",
36
36
  disabled,
37
37
  loading,
38
+ glass,
38
39
  href,
39
40
  target,
40
41
  rel,
@@ -66,6 +67,7 @@ const Button = React.forwardRef(
66
67
  `${baseClass}--${resolvedState}`,
67
68
  `${baseClass}--${size}`,
68
69
  isLoading && `${baseClass}--loading`,
70
+ glass && `${baseClass}--glass`,
69
71
  className
70
72
  ].filter(Boolean).join(" ");
71
73
  const iconClass = "material-symbols-rounded";
@@ -1,7 +1,7 @@
1
1
  import { default as React } from 'react';
2
- import { Values } from './types';
3
- /** The scenes ShaderScene paints. */
4
- export type ShaderSceneId = 'horizon' | 'rift' | 'glyphs' | 'prism' | 'meteors' | 'waves' | 'aurora';
2
+ import { ShaderSceneSource, Values } from './types';
3
+ /** The scenes the library ships, picked by id. */
4
+ export type ShaderSceneId = 'horizon' | 'rift' | 'glyphs' | 'prism' | 'meteors' | 'waves' | 'aurora' | 'highway' | 'ocean' | 'sky' | 'galaxy';
5
5
  /**
6
6
  * How the scene resolved, the same three states ShaderField reports.
7
7
  * `pending` while the GL context comes up (bounded by a watchdog), `active`
@@ -18,11 +18,17 @@ export type ShaderScenePassSetting = {
18
18
  };
19
19
  /** Props owned by ShaderScene itself; everything else falls through to the root. */
20
20
  type ShaderSceneOwnProps = {
21
- /** The scene to paint: `horizon`, a planet's limb at night, `rift`, a glowing tear, `glyphs`, soft light printed in type, `prism`, beams of light split into a spectrum, `meteors`, a shower over a planet's edge, `waves`, a rolling sea of points, or `aurora`, ribbons of colour round a void. */
22
- scene?: ShaderSceneId;
21
+ /**
22
+ * The scene to paint: one of the library's by id, or a scene of your own as
23
+ * a `ShaderSceneSource` (its colour roles, its settings and the GLSL that
24
+ * paints it). The library's are `horizon`, a planet's limb at night, `rift`, a glowing tear, `glyphs`, soft light printed in type, `prism`, beams of light split into a spectrum, `meteors`, a shower over a planet's edge, `waves`, a rolling sea of points, `highway`, a straight highway at night drawn in light trails, `aurora`, ribbons of colour round a void, `ocean`, open water from above with sea life drawn in type, turquoise on a light page and moonlit on a dark one, `sky`, cloud massed overhead and burning with a low sun, a golden hour on a light page and the last of a sunset under a night sky on a dark one, and `galaxy`, a spiral galaxy seen at a slant, deep in a field of stars. A scene of your own is compared by content, so
25
+ * an object written inline rebuilds nothing until what it says changes.
26
+ */
27
+ scene?: ShaderSceneId | ShaderSceneSource;
23
28
  /**
24
29
  * The scene's settings, merged over its defaults (`SHADER_SCENES` lists each
25
- * scene's keys and ranges), so passing one changes one thing. Changing them
30
+ * library scene's keys and ranges; your own scene declares its own), so
31
+ * passing one changes one thing. Changing them
26
32
  * never rebuilds the GL state.
27
33
  */
28
34
  params?: Partial<Record<string, number>>;
@@ -51,6 +57,14 @@ type ShaderSceneOwnProps = {
51
57
  * decision.
52
58
  */
53
59
  onStatusChange?: (status: ShaderSceneStatus) => void;
60
+ /**
61
+ * Called with the compiler's log when the scene's GLSL fails to compile or
62
+ * link, for a scene of your own. Its line numbers count from the first
63
+ * line of the scene's `glsl`, written `1:<line>`. The status becomes
64
+ * `unavailable` as well, and the log still reaches the console. Replaces
65
+ * the native `onError` attribute, which a scene's root never fires.
66
+ */
67
+ onError?: (message: string) => void;
54
68
  /** Additional CSS classes */
55
69
  className?: string;
56
70
  };
@@ -58,16 +72,25 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
58
72
  }
59
73
  /**
60
74
  * ShaderScene paints one of the system's shader scenes, a horizon, a rift,
61
- * a field of glyphs, a prism, a meteor shower, a sea of points or an aurora, in WebGL2, with finishing passes over it (a scrim, a vignette, top and
75
+ * a field of glyphs, a prism, a meteor shower, a sea of points, an aurora, a night highway, an ocean seen from above, a sky of burning cloud or a spiral galaxy, in WebGL2, with finishing passes over it (a scrim, a vignette, top and
62
76
  * bottom fades to the page, film grain). Its colours are the background
63
77
  * field's roles (`--color-ambient-*`) read from the live cascade at the
64
78
  * scene, so it re-themes with `data-theme`, a preset or any scoped override,
65
79
  * and its fades melt into the page ground.
66
80
  *
67
- * Every scene is a night scene: it adds light over a dark ground. On a light
68
- * page each computes its light against a dark ground of its own and lays it
69
- * onto the page as a pale tint, so it reads as a soft dawn rather than a dark
70
- * block. Nothing here sets `data-theme`, which would hide a preset's colours.
81
+ * It paints a scene of your own the same way: pass `scene` a
82
+ * `ShaderSceneSource` and it gets the same uniforms, noise helpers, passes,
83
+ * light-mode handling and budget the library's scenes do. A scene that
84
+ * fails to compile reports `unavailable` and hands its log to `onError`.
85
+ *
86
+ * Every scene but the ocean and the sky is a night scene: it adds light over a dark
87
+ * ground. On a light page each computes its light against a dark ground of
88
+ * its own and lays it onto the page as a pale tint, so it reads as a soft
89
+ * dawn rather than a dark block. The ocean paints both: a turquoise shallow
90
+ * over a light page ground, deep moonlit water over a dark one. The sky does
91
+ * too: a golden hour over a light ground, the last of a sunset under a night sky
92
+ * over a dark one. Nothing here
93
+ * sets `data-theme`, which would hide a preset's colours.
71
94
  *
72
95
  * It is scenery, not interface. It fills its positioned ancestor and is inert
73
96
  * to pointer events and to assistive tech; give the ancestor the placement and
@@ -76,8 +99,8 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
76
99
  * its first frame is drawn, then fades in, so where WebGL2 is unavailable
77
100
  * whatever lies under it (the page, or a fallback of the caller's) shows.
78
101
  */
79
- export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
80
- export type { ParamSpec as ShaderSceneParamSpec, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
102
+ export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, onError, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
103
+ export type { ShaderSceneParamSpec, ShaderSceneSource, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
81
104
  export { SCENES as SHADER_SCENES } from './scenes';
82
105
  export { PASSES as SHADER_PASSES } from './passes';
83
106
  export { defaultsFor as shaderSceneDefaults } from './types';
@@ -3,6 +3,8 @@ import { jsx } from "react/jsx-runtime";
3
3
  import React from "react";
4
4
  import { MOTION_RENDERER_WATCHDOG_MS } from "../../tokens/motion.js";
5
5
  import { PASSES } from "./passes.js";
6
+ import { warnOnce } from "../../behaviors/devWarning.js";
7
+ import { sceneProblems } from "./assemble.js";
6
8
  import { createRenderer, glyphFontFor, coloursFor } from "./renderer.js";
7
9
  import { bakeThumbnails } from "./renderer.js";
8
10
  import { SCENES } from "./scenes.js";
@@ -19,13 +21,38 @@ function ShaderScene({
19
21
  liveRef,
20
22
  enabled = true,
21
23
  onStatusChange,
24
+ onError,
22
25
  className = "",
23
26
  ref,
24
27
  ...rest
25
28
  }) {
26
29
  const hostRef = React.useRef(null);
27
30
  const canvasRef = React.useRef(null);
28
- const definition = SCENES.find((s) => s.id === scene) ?? SCENES[0];
31
+ const sceneKey = React.useMemo(() => {
32
+ if (typeof scene === "string") return scene;
33
+ const shipped = SCENES.find((s) => s === scene);
34
+ if (shipped) return shipped.id;
35
+ return JSON.stringify({
36
+ colours: scene.colours,
37
+ mode: scene.mode,
38
+ glyphs: scene.glyphs,
39
+ pixelRatio: scene.pixelRatio,
40
+ params: scene.params.map((param) => ({
41
+ key: param.key,
42
+ label: param.label,
43
+ min: param.min,
44
+ max: param.max,
45
+ step: param.step,
46
+ default: param.default
47
+ })),
48
+ glsl: scene.glsl
49
+ });
50
+ }, [scene]);
51
+ const custom = sceneKey.startsWith("{");
52
+ const definition = React.useMemo(
53
+ () => custom ? JSON.parse(sceneKey) : SCENES.find((s) => s.id === sceneKey) ?? SCENES[0],
54
+ [custom, sceneKey]
55
+ );
29
56
  const merged = React.useMemo(
30
57
  () => ({
31
58
  speed,
@@ -64,6 +91,10 @@ function ShaderScene({
64
91
  React.useEffect(() => {
65
92
  notify.current?.(status);
66
93
  }, [status]);
94
+ const reportError = React.useRef(onError);
95
+ React.useEffect(() => {
96
+ reportError.current = onError;
97
+ }, [onError]);
67
98
  const setRef = (node) => {
68
99
  hostRef.current = node;
69
100
  if (typeof ref === "function") ref(node);
@@ -74,7 +105,14 @@ function ShaderScene({
74
105
  const host = hostRef.current;
75
106
  const canvas = canvasRef.current;
76
107
  const context = canvas?.getContext("webgl2", { antialias: false, alpha: false });
77
- const renderer = context ? createRenderer(context, definition, PASSES) : null;
108
+ if (host && custom) {
109
+ const styles = getComputedStyle(host);
110
+ sceneProblems(definition, PASSES, (property) => styles.getPropertyValue(property).trim() !== "").forEach(warnOnce);
111
+ }
112
+ const renderer = context ? createRenderer(context, definition, PASSES, (log) => {
113
+ console.warn(log);
114
+ reportError.current?.(log);
115
+ }) : null;
78
116
  if (!host || !canvas || !renderer) {
79
117
  const failed = requestAnimationFrame(() => setGl("failed"));
80
118
  return () => cancelAnimationFrame(failed);
@@ -154,7 +192,7 @@ function ShaderScene({
154
192
  themeObserver.disconnect();
155
193
  renderer.dispose();
156
194
  };
157
- }, [definition, liveRef, enabled]);
195
+ }, [definition, custom, liveRef, enabled]);
158
196
  const classes = ["ds-shader-scene", className].filter(Boolean).join(" ");
159
197
  return /* @__PURE__ */ jsx("div", { ...rest, ref: setRef, className: classes, "data-status": status, "aria-hidden": "true", children: enabled && /* @__PURE__ */ jsx("canvas", { ref: canvasRef, className: "ds-shader-scene__canvas" }) });
160
198
  }
@@ -1,5 +1,12 @@
1
- import { Pass, Scene } from './types';
1
+ import { Pass, ShaderSceneSource } from './types';
2
2
  export declare const VERTEX = "#version 300 es\nvoid main() {\n vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);\n gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}\n";
3
3
  /** Every float uniform the shader declares, for the canvas to set each frame. */
4
- export declare function uniformNames(scene: Scene, passes: Pass[]): string[];
5
- export declare function assemble(scene: Scene, passes: Pass[]): string;
4
+ export declare function uniformNames(scene: ShaderSceneSource, passes: Pass[]): string[];
5
+ export declare function assemble(scene: ShaderSceneSource, passes: Pass[]): string;
6
+ /**
7
+ * What is wrong with a scene before the compiler is asked, for the
8
+ * development warnings: the mistakes whose compiler message, or whose
9
+ * silence, would not lead an author back to the cause. `resolves` says
10
+ * whether a colour custom property has a value at the scene.
11
+ */
12
+ export declare function sceneProblems(scene: ShaderSceneSource, passes: Pass[], resolves: (property: string) => boolean): string[];
@@ -40,7 +40,9 @@ out vec4 outColor;
40
40
 
41
41
  ${COMMON_GLSL}
42
42
 
43
+ #line 1 1
43
44
  ${scene.glsl}
45
+ #line 1 2
44
46
 
45
47
  ${passes.map((pass) => pass.glsl).join("\n")}
46
48
 
@@ -69,8 +71,35 @@ ${call("srgb", "srgb")}
69
71
  `
70
72
  );
71
73
  }
74
+ function sceneProblems(scene, passes, resolves) {
75
+ const problems = [];
76
+ for (const param of scene.params) {
77
+ if (!/^[A-Za-z]\w*$/.test(param.key)) {
78
+ problems.push(`ShaderScene: the param key "${param.key}" is not a GLSL identifier, so its uniform cannot be declared.`);
79
+ }
80
+ }
81
+ const declared = /* @__PURE__ */ new Set();
82
+ const twice = /* @__PURE__ */ new Set();
83
+ for (const [, name] of assemble(scene, passes).matchAll(/^\s*uniform\s+\w+\s+(\w+)/gm)) {
84
+ if (declared.has(name)) twice.add(name);
85
+ declared.add(name);
86
+ }
87
+ for (const name of twice) {
88
+ problems.push(`ShaderScene: the uniform ${name} is declared twice. A param key must not repeat a uniform the engine or a pass declares, and the scene's GLSL must not declare its params itself.`);
89
+ }
90
+ if (scene.colours.length > MAX_COLOURS) {
91
+ problems.push(`ShaderScene: a scene reads at most ${MAX_COLOURS} colours, and this one lists ${scene.colours.length}; the rest are dropped.`);
92
+ }
93
+ for (const property of scene.colours) {
94
+ if (!resolves(property)) {
95
+ problems.push(`ShaderScene: the colour ${property} has no value at the scene, so it falls back to the text colour.`);
96
+ }
97
+ }
98
+ return problems;
99
+ }
72
100
  export {
73
101
  VERTEX,
74
102
  assemble,
103
+ sceneProblems,
75
104
  uniformNames
76
105
  };
@@ -1,4 +1,4 @@
1
- import { Pass, Scene, Values } from './types';
1
+ import { Pass, ShaderSceneSource, Values } from './types';
2
2
  export type Rgb = [number, number, number];
3
3
  export type Colours = {
4
4
  /** The ground the scene is painted against. */
@@ -18,10 +18,17 @@ export declare function readColours(host: HTMLElement, tokens: string[]): Colour
18
18
  * (u_lightMode), so its masks still fade to the page and the theme stays
19
19
  * light.
20
20
  */
21
- export declare function coloursFor(host: HTMLElement, scene: Scene): Colours;
21
+ export declare function coloursFor(host: HTMLElement, scene: ShaderSceneSource): Colours;
22
22
  /** The face a scene's type is drawn in: the theme's code face at `host`. */
23
23
  export declare function glyphFontFor(host: HTMLElement): string;
24
- export declare function createRenderer(gl: WebGL2RenderingContext, scene: Scene, passes: Pass[]): {
24
+ /** Where a compiler or linker log goes; the console by default. */
25
+ type Report = (log: string) => void;
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).
30
+ */
31
+ export declare function createRenderer(gl: WebGL2RenderingContext, scene: ShaderSceneSource, passes: Pass[], report?: Report): {
25
32
  setColours({ ground, page, lightMode, colours }: Colours): void;
26
33
  /** Draws a type scene's ramp in `font`; a scene without one ignores it. */
27
34
  setGlyphs(font: string): void;
@@ -34,6 +41,7 @@ export declare function createRenderer(gl: WebGL2RenderingContext, scene: Scene,
34
41
  * context of their own and the page keeps one.
35
42
  */
36
43
  export declare function bakeThumbnails(host: HTMLElement, jobs: {
37
- scene: Scene;
44
+ scene: ShaderSceneSource;
38
45
  values: Values;
39
46
  }[], passes: Pass[], width: number, height: number): string[];
47
+ export {};