rift-ds 1.27.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 +1 -1
- package/behaviors/typeahead.d.ts +27 -0
- package/behaviors/typeahead.js +30 -0
- package/bin/rift-ds.mjs +5 -4
- package/bin/templates/blocks/app/shader/page.module.css +75 -0
- package/bin/templates/blocks/app/shader/page.tsx +81 -0
- package/bin/templates/blocks/components/blocks/emberScene.ts +53 -0
- package/bin/templates/blocks/registry.json +11 -0
- package/chat/ChatWidget.d.ts +1 -1
- package/chat/threads.js +7 -4
- package/components/Button/Button.css +38 -0
- package/components/Button/Button.d.ts +12 -1
- package/components/Button/Button.js +2 -0
- package/components/Carousel/Carousel.js +4 -0
- package/components/ColorPicker/ColorPicker.js +5 -0
- package/components/CommandPalette/CommandPalette.js +1 -0
- package/components/ContextMenu/ContextMenu.js +8 -0
- package/components/DataTable/DataTable.css +1 -1
- package/components/Dropdown/Dropdown.js +13 -0
- package/components/DropdownMenu/DropdownMenu.js +12 -0
- package/components/EntitySwitcher/EntitySwitcher.js +23 -1
- package/components/FilterBar/FilterBar.js +8 -0
- package/components/ModelPicker/ModelPicker.js +8 -0
- package/components/RadioButton/RadioButton.js +19 -2
- package/components/RichDropdown/RichDropdown.js +8 -0
- package/components/SegmentedControl/SegmentedControl.js +6 -0
- package/components/ShaderScene/ShaderScene.d.ts +36 -13
- package/components/ShaderScene/ShaderScene.js +41 -3
- package/components/ShaderScene/assemble.d.ts +10 -3
- package/components/ShaderScene/assemble.js +29 -0
- package/components/ShaderScene/renderer.d.ts +12 -4
- package/components/ShaderScene/renderer.js +32 -20
- package/components/ShaderScene/scenes.d.ts +78 -0
- package/components/ShaderScene/scenes.js +933 -1
- package/components/ShaderScene/types.d.ts +52 -23
- package/components/ThemePicker/ThemePicker.js +14 -2
- package/components/TimePicker/TimePicker.js +8 -0
- package/components/Toolbar/Toolbar.d.ts +3 -1
- package/components/TreeView/TreeView.js +10 -0
- package/components/WorldMap/WorldMap.d.ts +1 -1
- package/components/WorldMap/WorldMap.js +1 -1
- package/components/keyboard-patterns.json.d.ts +625 -0
- package/components/keyboard-patterns.json.js +8 -0
- package/components/registry.d.ts +52 -0
- package/components/registry.js +13 -1
- package/components/registry.json +358 -179
- package/components/registry.json.d.ts +358 -179
- package/components/registry.json.js +1 -1
- package/package.json +1 -1
- package/tokens/presets/contrast.css +2 -2
- package/tokens/presets/coral.css +2 -2
- package/tokens/presets/forest.css +2 -2
- package/tokens/presets/gold.css +2 -2
- package/tokens/presets/mono.css +92 -98
- package/tokens/presets/pink.css +2 -2
- package/tokens/presets/plum.css +2 -2
- package/tokens/presets/terminal.css +2 -2
- package/tokens/presets/warm.css +2 -2
- package/tokens/presets/zest.css +2 -2
- package/tokens/registry.json +19 -18
- package/tokens/registry.json.d.ts +19 -18
- package/tokens/registry.json.js +1 -1
- package/tokens/tokens-dark.css +4 -1
- package/tokens/tokens-light.css +3 -0
- package/tokens/values.json.js +1 -1
|
@@ -4,6 +4,7 @@ import React, { useId, useState, useRef, useCallback } from "react";
|
|
|
4
4
|
import { CheckboxIndicator } from "../Checkbox/Checkbox.js";
|
|
5
5
|
import { ChosenMark } from "../Dropdown/Dropdown.js";
|
|
6
6
|
import { useLayer } from "../../behaviors/useLayer.js";
|
|
7
|
+
import { useTypeahead } from "../../behaviors/typeahead.js";
|
|
7
8
|
import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
8
9
|
import "./FilterBar.css";
|
|
9
10
|
import "../../fonts/material-symbols.css";
|
|
@@ -80,8 +81,15 @@ const FilterBar = React.forwardRef(
|
|
|
80
81
|
setFocusedIndex(-1);
|
|
81
82
|
setOpenId((current) => current === filter.id ? null : filter.id);
|
|
82
83
|
};
|
|
84
|
+
const typeahead = useTypeahead();
|
|
83
85
|
const handleTriggerKeyDown = (e, filter) => {
|
|
84
86
|
const isOpen = openId === filter.id;
|
|
87
|
+
const hit = typeahead(e, filter.options.map((option) => option.label), focusedIndex);
|
|
88
|
+
if (hit !== null && isOpen) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
setFocusedIndex(hit);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
85
93
|
switch (e.key) {
|
|
86
94
|
case "Enter":
|
|
87
95
|
case " ":
|
|
@@ -4,6 +4,7 @@ import React, { useId, useRef, useState, useEffect } from "react";
|
|
|
4
4
|
import { ChosenMark } from "../Dropdown/Dropdown.js";
|
|
5
5
|
import { SegmentedControl } from "../SegmentedControl/SegmentedControl.js";
|
|
6
6
|
import { useLayer } from "../../behaviors/useLayer.js";
|
|
7
|
+
import { useTypeahead } from "../../behaviors/typeahead.js";
|
|
7
8
|
import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
8
9
|
import "./ModelPicker.css";
|
|
9
10
|
import "../../fonts/material-symbols.css";
|
|
@@ -83,8 +84,15 @@ const ModelPicker = React.forwardRef(
|
|
|
83
84
|
dismissOnOutsidePress: true,
|
|
84
85
|
getElements: () => [rootRef.current]
|
|
85
86
|
});
|
|
87
|
+
const typeahead = useTypeahead();
|
|
86
88
|
const handleTriggerKeyDown = (e) => {
|
|
87
89
|
if (disabled) return;
|
|
90
|
+
const hit = typeahead(e, models.map((model) => model.disabled ? null : model.label), focusedIndex);
|
|
91
|
+
if (hit !== null && isOpen) {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
setFocusedIndex(hit);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
88
96
|
switch (e.key) {
|
|
89
97
|
case "Enter":
|
|
90
98
|
case " ":
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
3
|
import React, { useId, useState } from "react";
|
|
4
4
|
import { Field } from "../Field/Field.js";
|
|
5
|
+
import { logicalArrowKey } from "../../behaviors/direction.js";
|
|
5
6
|
import "./RadioButton.css";
|
|
6
7
|
const RadioButton = React.forwardRef(
|
|
7
8
|
({
|
|
@@ -62,7 +63,7 @@ const RadioButton = React.forwardRef(
|
|
|
62
63
|
"aria-disabled": disabled,
|
|
63
64
|
"aria-label": rest["aria-label"] || ariaLabel || label,
|
|
64
65
|
"aria-describedby": describedBy,
|
|
65
|
-
tabIndex: disabled ? -1 : 0,
|
|
66
|
+
tabIndex: disabled ? -1 : rest.tabIndex ?? 0,
|
|
66
67
|
children: [
|
|
67
68
|
/* @__PURE__ */ jsx(RadioIndicator, { checked }),
|
|
68
69
|
helperText ? /* @__PURE__ */ jsxs("span", { className: `${baseClass}__text`, children: [
|
|
@@ -107,6 +108,21 @@ const RadioGroup = React.forwardRef(
|
|
|
107
108
|
onValueChange?.(next);
|
|
108
109
|
onChange?.(next);
|
|
109
110
|
};
|
|
111
|
+
const enabledOptions = options.filter((option) => !option.disabled);
|
|
112
|
+
const tabStop = enabledOptions.some((option) => option.value === value) ? value : enabledOptions[0]?.value;
|
|
113
|
+
const handleOptionsKeyDown = (event) => {
|
|
114
|
+
const radios = Array.from(
|
|
115
|
+
event.currentTarget.querySelectorAll('[role="radio"]:not([aria-disabled="true"])')
|
|
116
|
+
);
|
|
117
|
+
const at = radios.indexOf(document.activeElement);
|
|
118
|
+
if (at === -1 || radios.length !== enabledOptions.length) return;
|
|
119
|
+
const key = logicalArrowKey(event.key, event.currentTarget);
|
|
120
|
+
const to = key === "ArrowRight" || key === "ArrowDown" ? (at + 1) % radios.length : key === "ArrowLeft" || key === "ArrowUp" ? (at - 1 + radios.length) % radios.length : key === "Home" ? 0 : key === "End" ? radios.length - 1 : -1;
|
|
121
|
+
if (to === -1) return;
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
radios[to].focus();
|
|
124
|
+
handleSelect(enabledOptions[to].value);
|
|
125
|
+
};
|
|
110
126
|
return /* @__PURE__ */ jsx(
|
|
111
127
|
Field,
|
|
112
128
|
{
|
|
@@ -123,7 +139,7 @@ const RadioGroup = React.forwardRef(
|
|
|
123
139
|
"aria-labelledby": labelId,
|
|
124
140
|
"aria-describedby": describedBy,
|
|
125
141
|
"aria-invalid": error || void 0,
|
|
126
|
-
children: /* @__PURE__ */ jsx("div", { className: `${baseClass}__options`, children: options.map((option) => /* @__PURE__ */ jsx(
|
|
142
|
+
children: /* @__PURE__ */ jsx("div", { className: `${baseClass}__options`, onKeyDown: handleOptionsKeyDown, children: options.map((option) => /* @__PURE__ */ jsx(
|
|
127
143
|
RadioButton,
|
|
128
144
|
{
|
|
129
145
|
name,
|
|
@@ -131,6 +147,7 @@ const RadioGroup = React.forwardRef(
|
|
|
131
147
|
value: option.value,
|
|
132
148
|
checked: value === option.value,
|
|
133
149
|
disabled: option.disabled,
|
|
150
|
+
tabIndex: option.value === tabStop ? 0 : -1,
|
|
134
151
|
onValueChange: handleSelect
|
|
135
152
|
},
|
|
136
153
|
option.value
|
|
@@ -3,6 +3,7 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import React, { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { ChosenMark } from "../Dropdown/Dropdown.js";
|
|
5
5
|
import { useLayer } from "../../behaviors/useLayer.js";
|
|
6
|
+
import { useTypeahead } from "../../behaviors/typeahead.js";
|
|
6
7
|
import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
7
8
|
import { Field } from "../Field/Field.js";
|
|
8
9
|
import "./RichDropdown.css";
|
|
@@ -94,8 +95,15 @@ const RichDropdown = React.forwardRef(
|
|
|
94
95
|
dismissOnOutsidePress: true,
|
|
95
96
|
getElements: () => [rootRef.current]
|
|
96
97
|
});
|
|
98
|
+
const typeahead = useTypeahead();
|
|
97
99
|
const handleKeyDown = (e) => {
|
|
98
100
|
if (disabled) return;
|
|
101
|
+
const hit = typeahead(e, options.map((option) => option.disabled ? null : option.label), focusedIndex);
|
|
102
|
+
if (hit !== null && isOpen) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
setFocusedIndex(hit);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
99
107
|
switch (e.key) {
|
|
100
108
|
case "Enter":
|
|
101
109
|
case " ":
|
|
@@ -8,6 +8,7 @@ import { mirrorClass, logicalArrowKey } from "../../behaviors/direction.js";
|
|
|
8
8
|
import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
9
9
|
import { useTopLayer } from "../../behaviors/useTopLayer.js";
|
|
10
10
|
import { CircularButton } from "../CircularButton/CircularButton.js";
|
|
11
|
+
import { warnOnce } from "../../behaviors/devWarning.js";
|
|
11
12
|
const SegmentedControl = React.forwardRef(
|
|
12
13
|
({
|
|
13
14
|
segments,
|
|
@@ -30,6 +31,11 @@ const SegmentedControl = React.forwardRef(
|
|
|
30
31
|
...rest
|
|
31
32
|
}, ref) => {
|
|
32
33
|
const name = nativeAriaLabel ?? ariaLabel;
|
|
34
|
+
if (!name && !rest["aria-labelledby"]) {
|
|
35
|
+
warnOnce(
|
|
36
|
+
"SegmentedControl has no accessible name. Pass aria-label or aria-labelledby so a screen reader can announce what the set chooses."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
33
39
|
const controlledValue = value ?? legacyActiveSegment;
|
|
34
40
|
const isControlled = controlledValue !== void 0;
|
|
35
41
|
const [internalValue, setInternalValue] = useState(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { Values } from './types';
|
|
3
|
-
/** The scenes
|
|
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
|
-
/**
|
|
22
|
-
|
|
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
|
|
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
|
|
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
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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,
|
|
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:
|
|
5
|
-
export declare function assemble(scene:
|
|
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,
|
|
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:
|
|
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
|
-
|
|
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:
|
|
44
|
+
scene: ShaderSceneSource;
|
|
38
45
|
values: Values;
|
|
39
46
|
}[], passes: Pass[], width: number, height: number): string[];
|
|
47
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assemble,
|
|
1
|
+
import { assemble, VERTEX } from "./assemble.js";
|
|
2
2
|
import { MAX_COLOURS } from "./types.js";
|
|
3
3
|
const NIGHT_GROUND = [15e-4, 18e-4, 3e-3];
|
|
4
4
|
function readColours(host, tokens) {
|
|
@@ -55,37 +55,36 @@ function drawGlyphs(ramp, font) {
|
|
|
55
55
|
}
|
|
56
56
|
return { strip, count: glyphs.length };
|
|
57
57
|
}
|
|
58
|
-
function compile(gl, type, source) {
|
|
58
|
+
function compile(gl, type, source, report) {
|
|
59
59
|
const shader = gl.createShader(type);
|
|
60
60
|
if (!shader) return null;
|
|
61
61
|
gl.shaderSource(shader, source);
|
|
62
62
|
gl.compileShader(shader);
|
|
63
63
|
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
64
|
-
|
|
64
|
+
report(gl.getShaderInfoLog(shader) ?? "");
|
|
65
65
|
gl.deleteShader(shader);
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
68
|
return shader;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!name.startsWith(prefix)) continue;
|
|
74
|
-
const state = values.passes[pass.id];
|
|
75
|
-
const key = name.slice(prefix.length);
|
|
76
|
-
if (key === "on") return state?.on ? 1 : 0;
|
|
77
|
-
return state?.params[key] ?? 0;
|
|
78
|
-
}
|
|
79
|
-
return values.scene[name.slice(2)] ?? 0;
|
|
80
|
-
}
|
|
81
|
-
function createRenderer(gl, scene, passes) {
|
|
82
|
-
const vs = compile(gl, gl.VERTEX_SHADER, VERTEX);
|
|
83
|
-
const fs = compile(gl, gl.FRAGMENT_SHADER, assemble(scene, passes));
|
|
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);
|
|
84
73
|
const program = gl.createProgram();
|
|
85
|
-
|
|
74
|
+
const discard = () => {
|
|
75
|
+
gl.deleteProgram(program);
|
|
76
|
+
gl.deleteShader(vs);
|
|
77
|
+
gl.deleteShader(fs);
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
if (!vs || !fs || !program) return discard();
|
|
86
81
|
gl.attachShader(program, vs);
|
|
87
82
|
gl.attachShader(program, fs);
|
|
88
83
|
gl.linkProgram(program);
|
|
84
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
85
|
+
report(gl.getProgramInfoLog(program) ?? "");
|
|
86
|
+
return discard();
|
|
87
|
+
}
|
|
89
88
|
gl.useProgram(program);
|
|
90
89
|
const vao = gl.createVertexArray();
|
|
91
90
|
gl.bindVertexArray(vao);
|
|
@@ -98,7 +97,20 @@ function createRenderer(gl, scene, passes) {
|
|
|
98
97
|
const uCols = at("u_col");
|
|
99
98
|
const uRatio = at("u_ratio");
|
|
100
99
|
const uGlyphCount = at("u_glyphCount");
|
|
101
|
-
const floats =
|
|
100
|
+
const floats = [
|
|
101
|
+
...scene.params.map(
|
|
102
|
+
(param) => [at(`u_${param.key}`), (values) => values.scene[param.key] ?? 0]
|
|
103
|
+
),
|
|
104
|
+
...passes.flatMap((pass) => [
|
|
105
|
+
[at(`u_${pass.id}_on`), (values) => values.passes[pass.id]?.on ? 1 : 0],
|
|
106
|
+
...pass.params.map(
|
|
107
|
+
(param) => [
|
|
108
|
+
at(`u_${pass.id}_${param.key}`),
|
|
109
|
+
(values) => values.passes[pass.id]?.params[param.key] ?? 0
|
|
110
|
+
]
|
|
111
|
+
)
|
|
112
|
+
])
|
|
113
|
+
];
|
|
102
114
|
const glyphTexture = scene.glyphs ? gl.createTexture() : null;
|
|
103
115
|
let glyphFont = "";
|
|
104
116
|
return {
|
|
@@ -130,7 +142,7 @@ function createRenderer(gl, scene, passes) {
|
|
|
130
142
|
gl.uniform2f(uSize, width, height);
|
|
131
143
|
gl.uniform1f(uRatio, ratio);
|
|
132
144
|
gl.uniform1f(uTime, time);
|
|
133
|
-
for (const [
|
|
145
|
+
for (const [location, read] of floats) gl.uniform1f(location, read(values));
|
|
134
146
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
135
147
|
},
|
|
136
148
|
dispose() {
|
|
@@ -72,5 +72,83 @@ export declare const waves: Scene;
|
|
|
72
72
|
* gives the colour its depth. Nothing in it has an edge.
|
|
73
73
|
*/
|
|
74
74
|
export declare const aurora: Scene;
|
|
75
|
+
/**
|
|
76
|
+
* The highway: a straight highway at night, seen from its shoulder, running to a
|
|
77
|
+
* low horizon. It is drawn in long-exposure light trails, every one a
|
|
78
|
+
* straight line to the single point where the road ends, with light
|
|
79
|
+
* streaming along them rather than the lines themselves moving. A cold haze
|
|
80
|
+
* sits on the horizon and drifts over the ground, and a hot point with a
|
|
81
|
+
* flare marks where the trails meet, and a city's lights lie along the
|
|
82
|
+
* horizon under slow clouds and drifting mist.
|
|
83
|
+
*/
|
|
84
|
+
export declare const highway: Scene;
|
|
75
85
|
/** Every scene, in picker order. */
|
|
86
|
+
/**
|
|
87
|
+
* The ocean: open water seen from straight above, with sea life drawn in
|
|
88
|
+
* type swimming through it. It is the one scene with a day of its own, told
|
|
89
|
+
* from the page ground: on a light page it is a shallow tropical sea, the
|
|
90
|
+
* ground showing through turquoise water under a net of sunlight, the
|
|
91
|
+
* animals dark against the sand; on a dark page it is deep water at night,
|
|
92
|
+
* deep blue with the net cut into it as shadow and a patch of moonlight, where the animals
|
|
93
|
+
* are bioluminescent: their characters pulse in their own colour and the
|
|
94
|
+
* water round each body glows with it. The water is drawn
|
|
95
|
+
* in square blocks with a few flat steps of light, as a pixel drawing is,
|
|
96
|
+
* and the animals are type, as are the loose characters that trace the
|
|
97
|
+
* crests of the net and travel with them; nothing in the scene sits still. The water answers the animals: each
|
|
98
|
+
* parts it at the nose and drags a rippled wake behind, the net of light
|
|
99
|
+
* carried along at the animal's own pace, and by night the stirred water
|
|
100
|
+
* glows. The animals wear the theme's accents, each its own and every
|
|
101
|
+
* fish of a school a different one. Each animal is a silhouette (a shark, a ray, a turtle,
|
|
102
|
+
* schools of small fish) read at the centre of every character cell, so it
|
|
103
|
+
* moves a cell at a time, and a cell prints a heavier character the deeper
|
|
104
|
+
* inside the body it lies. Every crossing takes a new heading and lane.
|
|
105
|
+
*/
|
|
106
|
+
export declare const ocean: Scene;
|
|
107
|
+
/**
|
|
108
|
+
* The sky: cloud massed overhead and lit by a low sun, painted more than
|
|
109
|
+
* observed. The clouds lie on one flat layer far above, so they are large
|
|
110
|
+
* and slow at the top of the frame and small, close-packed and hazed where
|
|
111
|
+
* the layer runs off to the horizon, and the layer is bent before it is
|
|
112
|
+
* read, so a cloud billows and curls as paint does rather than sitting as
|
|
113
|
+
* a puff. The drama is the light. The sun stands low and the cloud burns
|
|
114
|
+
* with it: each cloud is lit by comparing its thickness with the cloud a
|
|
115
|
+
* step towards the light, which gives it a hot side and a shaded one
|
|
116
|
+
* without a ray being marched, and the colour runs from the hot side
|
|
117
|
+
* through an ember middle to a cold shade; where cloud is thin in front of
|
|
118
|
+
* the sun the light comes through it, and the strip of sky on the horizon
|
|
119
|
+
* under the cloud burns hardest of all. Like the ocean it has a day of its own, told from the page
|
|
120
|
+
* ground: on a light page a golden hour, cream and rose cloud with a deep
|
|
121
|
+
* blue shade over a sky that warms to the horizon; on a dark page the
|
|
122
|
+
* last of a sunset with the night already overhead: the sky near black
|
|
123
|
+
* with stars, heavy cloud standing as silhouettes darker still, burning
|
|
124
|
+
* like coals only where it faces the sun, over a horizon on fire. The sky is the fourth ambient role cooled with a
|
|
125
|
+
* little of the second, the sun the first, the fire in the cloud the fifth
|
|
126
|
+
* and sixth and its shade the third, so a theme recolours it. Contrails
|
|
127
|
+
* cross the far sky low over the horizon, well above the weather, so
|
|
128
|
+
* every cloud stands in front of them, and they hold the sun's colour;
|
|
129
|
+
* one more is still being laid, high in the frame, by a plane a few pixels
|
|
130
|
+
* long. Deep blue shows through overhead in slow patches.
|
|
131
|
+
*/
|
|
132
|
+
export declare const sky: Scene;
|
|
133
|
+
/**
|
|
134
|
+
* The galaxy: a spiral seen at a slant, deep in a field of stars. A disc
|
|
135
|
+
* of light thins outwards from a hot core, wound into two arms. The arms
|
|
136
|
+
* are drawn on the disc unwound, where each lies straight, so the cloud
|
|
137
|
+
* in them, the dust lanes cut along their inner edges and the knots of
|
|
138
|
+
* young stars strung down them all run with the arm, in filaments, and
|
|
139
|
+
* the dust is heavier on the side of the disc tipped towards the eye. The
|
|
140
|
+
* core is a bulge rounder than the disc, standing out of it, near white
|
|
141
|
+
* at its heart in a wide halo of the theme's warm colours, and the disc
|
|
142
|
+
* cools through the theme's colours to its rim. Two companions keep it
|
|
143
|
+
* company, a small soft ellipse off the disc and a tight bright one
|
|
144
|
+
* beside the core. The stars are four depths of points, one to a cell at
|
|
145
|
+
* most, thick in some parts of the sky and thin in others: a dust of
|
|
146
|
+
* faint ones, two scatters of brighter ones and a few near ones with a
|
|
147
|
+
* glow of their own, all twinkling slowly. Behind it all a band of lit
|
|
148
|
+
* gas crosses the sky, billowed and creeping, with a rift of dust down
|
|
149
|
+
* its middle and the stars crowded into it. The arms turn, too slowly to
|
|
150
|
+
* see move. Stars are points, finer than soft light, so the scene draws
|
|
151
|
+
* at up to two pixels per CSS pixel and sizes everything in CSS pixels.
|
|
152
|
+
*/
|
|
153
|
+
export declare const galaxy: Scene;
|
|
76
154
|
export declare const SCENES: Scene[];
|