rift-ds 1.24.0 → 1.25.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 +4 -4
- package/chat/ChatWidget.d.ts +5 -1
- package/chat/ChatWidget.js +12 -1
- package/components/Attachment/Attachment.css +8 -0
- package/components/Attachment/AttachmentViewer.js +26 -5
- package/components/Attachment/fileTypes.d.ts +4 -0
- package/components/CurrencyInput/CurrencyInput.css +12 -0
- package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
- package/components/CurrencyInput/CurrencyInput.js +158 -0
- package/components/DataTable/columnTypes.js +4 -16
- package/components/DatePicker/DatePicker.d.ts +2 -0
- package/components/DatePicker/DatePicker.js +44 -131
- package/components/DatePicker/MonthGrid.d.ts +56 -0
- package/components/DatePicker/MonthGrid.js +65 -0
- package/components/DatePicker/calendar.d.ts +42 -0
- package/components/DatePicker/calendar.js +108 -0
- package/components/DateRangePicker/DateRangePicker.css +92 -0
- package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
- package/components/DateRangePicker/DateRangePicker.js +294 -0
- package/components/Deadline/Deadline.css +82 -0
- package/components/Deadline/Deadline.d.ts +44 -0
- package/components/Deadline/Deadline.js +94 -0
- package/components/Deadline/deadlineStatus.d.ts +15 -0
- package/components/Deadline/deadlineStatus.js +13 -0
- package/components/DescriptionList/DescriptionList.css +184 -0
- package/components/DescriptionList/DescriptionList.d.ts +64 -0
- package/components/DescriptionList/DescriptionList.js +100 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
- package/components/DescriptionList/DescriptionListCopy.js +45 -0
- package/components/DocumentViewer/DocumentViewer.css +188 -0
- package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
- package/components/DocumentViewer/DocumentViewer.js +185 -0
- package/components/ErrorSummary/ErrorSummary.css +94 -0
- package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
- package/components/ErrorSummary/ErrorSummary.js +70 -0
- package/components/ErrorSummary/fieldErrors.d.ts +36 -0
- package/components/ErrorSummary/fieldErrors.js +19 -0
- package/components/Field/Field.css +12 -0
- package/components/Field/Field.d.ts +10 -2
- package/components/Field/Field.js +12 -5
- package/components/Heading/Heading.css +129 -0
- package/components/Heading/Heading.d.ts +31 -0
- package/components/Heading/Heading.js +39 -0
- package/components/Input/Input.css +120 -0
- package/components/Input/Input.d.ts +20 -1
- package/components/Input/Input.js +70 -5
- package/components/Link/Link.css +84 -0
- package/components/Link/Link.d.ts +43 -0
- package/components/Link/Link.js +74 -0
- package/components/List/List.css +173 -0
- package/components/List/List.d.ts +44 -0
- package/components/List/List.js +60 -0
- package/components/MaskedInput/MaskedInput.css +16 -0
- package/components/MaskedInput/MaskedInput.d.ts +57 -0
- package/components/MaskedInput/MaskedInput.js +142 -0
- package/components/MaskedInput/mask.d.ts +58 -0
- package/components/MaskedInput/mask.js +106 -0
- package/components/ShaderScene/ShaderScene.css +19 -0
- package/components/ShaderScene/ShaderScene.d.ts +82 -0
- package/components/ShaderScene/ShaderScene.js +144 -0
- package/components/ShaderScene/assemble.d.ts +5 -0
- package/components/ShaderScene/assemble.js +74 -0
- package/components/ShaderScene/common.glsl.d.ts +6 -0
- package/components/ShaderScene/common.glsl.js +49 -0
- package/components/ShaderScene/passes.d.ts +2 -0
- package/components/ShaderScene/passes.js +93 -0
- package/components/ShaderScene/renderer.d.ts +35 -0
- package/components/ShaderScene/renderer.js +125 -0
- package/components/ShaderScene/scenes.d.ts +20 -0
- package/components/ShaderScene/scenes.js +184 -0
- package/components/ShaderScene/types.d.ts +70 -0
- package/components/ShaderScene/types.js +8 -0
- package/components/SignaturePad/SignaturePad.css +141 -0
- package/components/SignaturePad/SignaturePad.d.ts +68 -0
- package/components/SignaturePad/SignaturePad.js +287 -0
- package/components/SignaturePad/signature.d.ts +32 -0
- package/components/SignaturePad/signature.js +46 -0
- package/components/Text/Text.css +129 -0
- package/components/Text/Text.d.ts +36 -0
- package/components/Text/Text.js +36 -0
- package/components/Widget/Widget.css +111 -0
- package/components/Widget/Widget.d.ts +15 -1
- package/components/Widget/Widget.js +63 -11
- package/components/Widget/WidgetDisclosure.d.ts +30 -0
- package/components/Widget/WidgetDisclosure.js +52 -0
- package/components/registry.json +111 -2
- package/components/registry.json.d.ts +111 -2
- package/components/registry.json.js +2 -2
- package/format/index.d.ts +15 -0
- package/format/index.js +17 -0
- package/format/money.d.ts +89 -0
- package/format/money.js +187 -0
- package/format/relative.d.ts +49 -0
- package/format/relative.js +50 -0
- package/index.d.ts +13 -0
- package/index.js +46 -0
- package/package.json +9 -2
- package/tokens/motion.d.ts +4 -0
- package/tokens/motion.js +4 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Values } from './types';
|
|
3
|
+
/** The scenes ShaderScene paints. */
|
|
4
|
+
export type ShaderSceneId = 'horizon' | 'rift';
|
|
5
|
+
/**
|
|
6
|
+
* How the scene resolved, the same three states ShaderField reports.
|
|
7
|
+
* `pending` while the GL context comes up (bounded by a watchdog), `active`
|
|
8
|
+
* once a frame has painted, `unavailable` when it is disabled or WebGL2
|
|
9
|
+
* cannot run it.
|
|
10
|
+
*/
|
|
11
|
+
export type ShaderSceneStatus = 'pending' | 'active' | 'unavailable';
|
|
12
|
+
/** One finishing pass's setting: whether it runs, and its own settings. */
|
|
13
|
+
export type ShaderScenePassSetting = {
|
|
14
|
+
/** Run the pass. Each pass has its own default. */
|
|
15
|
+
on?: boolean;
|
|
16
|
+
/** The pass's settings, merged over its defaults. */
|
|
17
|
+
params?: Partial<Record<string, number>>;
|
|
18
|
+
};
|
|
19
|
+
/** Props owned by ShaderScene itself; everything else falls through to the root. */
|
|
20
|
+
type ShaderSceneOwnProps = {
|
|
21
|
+
/** The scene to paint: `horizon`, a planet's limb at night, or `rift`, a glowing tear. */
|
|
22
|
+
scene?: ShaderSceneId;
|
|
23
|
+
/**
|
|
24
|
+
* 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
|
|
26
|
+
* never rebuilds the GL state.
|
|
27
|
+
*/
|
|
28
|
+
params?: Partial<Record<string, number>>;
|
|
29
|
+
/**
|
|
30
|
+
* The finishing passes (`scrim`, `vignette`, `fadeTop`, `fadeBottom`,
|
|
31
|
+
* `grain`), each merged over its defaults.
|
|
32
|
+
*/
|
|
33
|
+
passes?: Partial<Record<string, ShaderScenePassSetting>>;
|
|
34
|
+
/** Scene seconds per second: how fast it moves. 0 holds it still. */
|
|
35
|
+
speed?: number;
|
|
36
|
+
/**
|
|
37
|
+
* A ref the scene reads every frame in place of `params`, `passes` and
|
|
38
|
+
* `speed`, for a host that tunes it by drag: writing the ref moves the
|
|
39
|
+
* scene and renders nothing. Empty falls back to the props.
|
|
40
|
+
*/
|
|
41
|
+
liveRef?: React.RefObject<Values | null>;
|
|
42
|
+
/**
|
|
43
|
+
* False never starts WebGL and reports `unavailable`, leaving the page
|
|
44
|
+
* ground: the kill switch, as on ShaderField.
|
|
45
|
+
*/
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Called whenever the status changes. Drive a fallback from this: the scene
|
|
49
|
+
* paints only the page ground when it cannot run, and what to show instead
|
|
50
|
+
* is the caller's design decision.
|
|
51
|
+
*/
|
|
52
|
+
onStatusChange?: (status: ShaderSceneStatus) => void;
|
|
53
|
+
/** Additional CSS classes */
|
|
54
|
+
className?: string;
|
|
55
|
+
};
|
|
56
|
+
export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof ShaderSceneOwnProps> {
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* ShaderScene paints one of the system's shader scenes, a horizon or a rift,
|
|
60
|
+
* in WebGL2, with finishing passes over it (a scrim, a vignette, top and
|
|
61
|
+
* bottom fades to the page, film grain). Its colours are the background
|
|
62
|
+
* field's roles (`--color-ambient-*`) read from the live cascade at the
|
|
63
|
+
* scene, so it re-themes with `data-theme`, a preset or any scoped override,
|
|
64
|
+
* and its fades melt into the page ground.
|
|
65
|
+
*
|
|
66
|
+
* Both scenes are night scenes: they add light over a dark ground. On a light
|
|
67
|
+
* page each computes its light against a dark ground of its own and lays it
|
|
68
|
+
* onto the page as a pale tint, so it reads as a soft dawn rather than a dark
|
|
69
|
+
* block. Nothing here sets `data-theme`, which would hide a preset's colours.
|
|
70
|
+
*
|
|
71
|
+
* It is scenery, not interface. It fills its positioned ancestor and is inert
|
|
72
|
+
* to pointer events and to assistive tech; give the ancestor the placement and
|
|
73
|
+
* the clipping. It honours reduced motion in JavaScript, holding a still frame
|
|
74
|
+
* that still answers its settings, and paints the page ground alone where
|
|
75
|
+
* WebGL2 is unavailable.
|
|
76
|
+
*/
|
|
77
|
+
export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
|
|
78
|
+
export type { ParamSpec as ShaderSceneParamSpec, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
|
|
79
|
+
export { SCENES as SHADER_SCENES } from './scenes';
|
|
80
|
+
export { PASSES as SHADER_PASSES } from './passes';
|
|
81
|
+
export { defaultsFor as shaderSceneDefaults } from './types';
|
|
82
|
+
export { bakeThumbnails as shaderSceneStills } from './renderer';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { MOTION_RENDERER_WATCHDOG_MS } from "../../tokens/motion.js";
|
|
5
|
+
import { PASSES } from "./passes.js";
|
|
6
|
+
import { createRenderer, coloursFor } from "./renderer.js";
|
|
7
|
+
import { bakeThumbnails } from "./renderer.js";
|
|
8
|
+
import { SCENES } from "./scenes.js";
|
|
9
|
+
import { defaultsFor } from "./types.js";
|
|
10
|
+
import "./ShaderScene.css";
|
|
11
|
+
const DEFAULT_SPEED = 1.6;
|
|
12
|
+
function ShaderScene({
|
|
13
|
+
scene = "horizon",
|
|
14
|
+
params,
|
|
15
|
+
passes,
|
|
16
|
+
speed = DEFAULT_SPEED,
|
|
17
|
+
liveRef,
|
|
18
|
+
enabled = true,
|
|
19
|
+
onStatusChange,
|
|
20
|
+
className = "",
|
|
21
|
+
ref,
|
|
22
|
+
...rest
|
|
23
|
+
}) {
|
|
24
|
+
const hostRef = React.useRef(null);
|
|
25
|
+
const canvasRef = React.useRef(null);
|
|
26
|
+
const definition = SCENES.find((s) => s.id === scene) ?? SCENES[0];
|
|
27
|
+
const merged = React.useMemo(
|
|
28
|
+
() => ({
|
|
29
|
+
speed,
|
|
30
|
+
scene: { ...defaultsFor(definition.params), ...params },
|
|
31
|
+
passes: Object.fromEntries(
|
|
32
|
+
PASSES.map((pass) => {
|
|
33
|
+
const setting = passes?.[pass.id];
|
|
34
|
+
return [
|
|
35
|
+
pass.id,
|
|
36
|
+
{
|
|
37
|
+
on: setting?.on ?? pass.on,
|
|
38
|
+
params: { ...defaultsFor(pass.params), ...setting?.params }
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
}),
|
|
44
|
+
[definition, params, passes, speed]
|
|
45
|
+
);
|
|
46
|
+
const mergedRef = React.useRef(merged);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
mergedRef.current = merged;
|
|
49
|
+
}, [merged]);
|
|
50
|
+
const [gl, setGl] = React.useState("pending");
|
|
51
|
+
const [gaveUp, setGaveUp] = React.useState(false);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
if (!enabled || gl !== "pending") return;
|
|
54
|
+
const timer = window.setTimeout(() => setGaveUp(true), MOTION_RENDERER_WATCHDOG_MS);
|
|
55
|
+
return () => window.clearTimeout(timer);
|
|
56
|
+
}, [enabled, gl]);
|
|
57
|
+
const status = !enabled || gl === "failed" ? "unavailable" : gl === "painted" ? "active" : gaveUp ? "unavailable" : "pending";
|
|
58
|
+
const notify = React.useRef(onStatusChange);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
notify.current = onStatusChange;
|
|
61
|
+
}, [onStatusChange]);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
notify.current?.(status);
|
|
64
|
+
}, [status]);
|
|
65
|
+
const setRef = (node) => {
|
|
66
|
+
hostRef.current = node;
|
|
67
|
+
if (typeof ref === "function") ref(node);
|
|
68
|
+
else if (ref) ref.current = node;
|
|
69
|
+
};
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (!enabled) return;
|
|
72
|
+
const host = hostRef.current;
|
|
73
|
+
const canvas = canvasRef.current;
|
|
74
|
+
const context = canvas?.getContext("webgl2", { antialias: false, alpha: false });
|
|
75
|
+
const renderer = context ? createRenderer(context, definition, PASSES) : null;
|
|
76
|
+
if (!host || !canvas || !renderer) {
|
|
77
|
+
const failed = requestAnimationFrame(() => setGl("failed"));
|
|
78
|
+
return () => cancelAnimationFrame(failed);
|
|
79
|
+
}
|
|
80
|
+
const applyColours = () => renderer.setColours(coloursFor(host, definition));
|
|
81
|
+
const resize = () => {
|
|
82
|
+
const ratio = Math.min(2, window.devicePixelRatio || 1);
|
|
83
|
+
canvas.width = Math.max(1, Math.round(host.clientWidth * ratio));
|
|
84
|
+
canvas.height = Math.max(1, Math.round(host.clientHeight * ratio));
|
|
85
|
+
};
|
|
86
|
+
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
87
|
+
let time = 20;
|
|
88
|
+
let last = performance.now();
|
|
89
|
+
let frame = 0;
|
|
90
|
+
let painted = false;
|
|
91
|
+
const draw = (now) => {
|
|
92
|
+
const values = liveRef?.current ?? mergedRef.current;
|
|
93
|
+
const dt = Math.min(0.1, (now - last) / 1e3);
|
|
94
|
+
last = now;
|
|
95
|
+
if (!still) time += dt * values.speed;
|
|
96
|
+
renderer.draw(values, time, canvas.width, canvas.height);
|
|
97
|
+
if (!painted) {
|
|
98
|
+
painted = true;
|
|
99
|
+
setGl("painted");
|
|
100
|
+
}
|
|
101
|
+
frame = requestAnimationFrame(draw);
|
|
102
|
+
};
|
|
103
|
+
const start = () => {
|
|
104
|
+
if (frame) return;
|
|
105
|
+
last = performance.now();
|
|
106
|
+
frame = requestAnimationFrame(draw);
|
|
107
|
+
};
|
|
108
|
+
const stop = () => {
|
|
109
|
+
cancelAnimationFrame(frame);
|
|
110
|
+
frame = 0;
|
|
111
|
+
};
|
|
112
|
+
applyColours();
|
|
113
|
+
resize();
|
|
114
|
+
start();
|
|
115
|
+
const visibilityObserver = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver(
|
|
116
|
+
(entries) => entries[entries.length - 1].isIntersecting ? start() : stop(),
|
|
117
|
+
{ rootMargin: "200px 0px" }
|
|
118
|
+
);
|
|
119
|
+
visibilityObserver?.observe(host);
|
|
120
|
+
const sizeObserver = new ResizeObserver(resize);
|
|
121
|
+
sizeObserver.observe(host);
|
|
122
|
+
const themeObserver = new MutationObserver(applyColours);
|
|
123
|
+
themeObserver.observe(document.documentElement, {
|
|
124
|
+
attributes: true,
|
|
125
|
+
attributeFilter: ["data-theme", "data-brand", "style"]
|
|
126
|
+
});
|
|
127
|
+
return () => {
|
|
128
|
+
stop();
|
|
129
|
+
visibilityObserver?.disconnect();
|
|
130
|
+
sizeObserver.disconnect();
|
|
131
|
+
themeObserver.disconnect();
|
|
132
|
+
renderer.dispose();
|
|
133
|
+
};
|
|
134
|
+
}, [definition, liveRef, enabled]);
|
|
135
|
+
const classes = ["ds-shader-scene", className].filter(Boolean).join(" ");
|
|
136
|
+
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" }) });
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
PASSES as SHADER_PASSES,
|
|
140
|
+
SCENES as SHADER_SCENES,
|
|
141
|
+
ShaderScene,
|
|
142
|
+
defaultsFor as shaderSceneDefaults,
|
|
143
|
+
bakeThumbnails as shaderSceneStills
|
|
144
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Pass, Scene } from './types';
|
|
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
|
+
/** 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;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { COMMON_GLSL } from "./common.glsl.js";
|
|
2
|
+
import { MAX_COLOURS } from "./types.js";
|
|
3
|
+
const VERTEX = (
|
|
4
|
+
/* glsl */
|
|
5
|
+
`#version 300 es
|
|
6
|
+
void main() {
|
|
7
|
+
vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
|
|
8
|
+
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
);
|
|
12
|
+
function uniformNames(scene, passes) {
|
|
13
|
+
return [
|
|
14
|
+
...scene.params.map((param) => `u_${param.key}`),
|
|
15
|
+
...passes.flatMap((pass) => [
|
|
16
|
+
`u_${pass.id}_on`,
|
|
17
|
+
...pass.params.map((param) => `u_${pass.id}_${param.key}`)
|
|
18
|
+
])
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
function assemble(scene, passes) {
|
|
22
|
+
const floats = uniformNames(scene, passes).map((name) => `uniform float ${name};`).join("\n");
|
|
23
|
+
const call = (stage, target) => passes.filter((pass) => pass.stage === stage).map((pass) => ` if (u_${pass.id}_on > 0.5) ${target} = pass_${pass.id}(${target}, uv);`).join("\n");
|
|
24
|
+
return (
|
|
25
|
+
/* glsl */
|
|
26
|
+
`#version 300 es
|
|
27
|
+
precision highp float;
|
|
28
|
+
|
|
29
|
+
uniform vec2 u_size;
|
|
30
|
+
uniform float u_time;
|
|
31
|
+
uniform vec3 u_ground; // the scene's ground: the page's, or a night scene's own
|
|
32
|
+
uniform vec3 u_page; // the page's ground, which the passes fade to
|
|
33
|
+
uniform float u_lightMode; // 1: a night scene laid onto a light page
|
|
34
|
+
uniform vec3 u_col[${MAX_COLOURS}];
|
|
35
|
+
${floats}
|
|
36
|
+
|
|
37
|
+
out vec4 outColor;
|
|
38
|
+
|
|
39
|
+
${COMMON_GLSL}
|
|
40
|
+
|
|
41
|
+
${scene.glsl}
|
|
42
|
+
|
|
43
|
+
${passes.map((pass) => pass.glsl).join("\n")}
|
|
44
|
+
|
|
45
|
+
void main() {
|
|
46
|
+
vec2 uv = gl_FragCoord.xy / u_size;
|
|
47
|
+
vec3 lin = scene(uv, u_time);
|
|
48
|
+
/* A night scene on a light page: the light it adds over its own dark
|
|
49
|
+
ground is laid onto the page as a pale tint, its hue washed most of
|
|
50
|
+
the way to white and never more than a light wash, so a horizon reads
|
|
51
|
+
as a soft dawn on paper rather than a dark block on it. */
|
|
52
|
+
if (u_lightMode > 0.5) {
|
|
53
|
+
vec3 light = max(lin - u_ground, vec3(0.0));
|
|
54
|
+
float peak = max(light.r, max(light.g, light.b));
|
|
55
|
+
vec3 hue = light / max(peak, 1e-4);
|
|
56
|
+
vec3 pastel = mix(hue, vec3(1.0), 0.3);
|
|
57
|
+
float strength = clamp(pow(dot(light, vec3(0.2126, 0.7152, 0.0722)) * 4.0, 0.7), 0.0, 0.85);
|
|
58
|
+
lin = mix(u_page, u_page * pastel, strength);
|
|
59
|
+
}
|
|
60
|
+
${call("light", "lin")}
|
|
61
|
+
vec3 srgb = pow(max(lin, vec3(0.0)), vec3(1.0 / 2.2));
|
|
62
|
+
/* A one-step dither under everything, so wide ramps never band. */
|
|
63
|
+
srgb += (float(ihash(uvec2(gl_FragCoord.xy)) & 255u) / 255.0 - 0.5) / 255.0;
|
|
64
|
+
${call("srgb", "srgb")}
|
|
65
|
+
outColor = vec4(clamp(srgb, 0.0, 1.0), 1.0);
|
|
66
|
+
}
|
|
67
|
+
`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
VERTEX,
|
|
72
|
+
assemble,
|
|
73
|
+
uniformNames
|
|
74
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GLSL every scene and pass can call: ShaderField's integer hash (no
|
|
3
|
+
* fract(sin()) patterning, so no lines in the grain), value noise, fbm and
|
|
4
|
+
* the one-sided Gaussian the horizon is built from.
|
|
5
|
+
*/
|
|
6
|
+
export declare const COMMON_GLSL = "\nuint ihash(uvec2 p) {\n p = p * uvec2(73333u, 7777u) ^ (p.yx >> 3u);\n uint h = p.x ^ (p.y * 2654435761u);\n h ^= h >> 15u;\n h *= 2246822519u;\n h ^= h >> 13u;\n return h;\n}\n\nfloat rnd(ivec2 p) {\n return float(ihash(uvec2(p)) >> 8) * (1.0 / 16777216.0);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n ivec2 c = ivec2(i) + 4096;\n return mix(\n mix(rnd(c), rnd(c + ivec2(1, 0)), u.x),\n mix(rnd(c + ivec2(0, 1)), rnd(c + ivec2(1, 1)), u.x),\n u.y\n );\n}\n\nfloat fbm(vec2 p) {\n float s = 0.0;\n float a = 0.5;\n for (int i = 0; i < 4; i++) {\n s += a * vnoise(p);\n p = p * 2.02 + vec2(17.0, 9.0);\n a *= 0.5;\n }\n return s;\n}\n\n/* A one-sided Gaussian: one sigma above zero, another below. */\nfloat lobe(float d, float above, float below) {\n float s = d > 0.0 ? above : below;\n return exp(-(d * d) / (2.0 * s * s));\n}\n";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const COMMON_GLSL = (
|
|
2
|
+
/* glsl */
|
|
3
|
+
`
|
|
4
|
+
uint ihash(uvec2 p) {
|
|
5
|
+
p = p * uvec2(73333u, 7777u) ^ (p.yx >> 3u);
|
|
6
|
+
uint h = p.x ^ (p.y * 2654435761u);
|
|
7
|
+
h ^= h >> 15u;
|
|
8
|
+
h *= 2246822519u;
|
|
9
|
+
h ^= h >> 13u;
|
|
10
|
+
return h;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
float rnd(ivec2 p) {
|
|
14
|
+
return float(ihash(uvec2(p)) >> 8) * (1.0 / 16777216.0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
float vnoise(vec2 p) {
|
|
18
|
+
vec2 i = floor(p);
|
|
19
|
+
vec2 f = fract(p);
|
|
20
|
+
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
|
21
|
+
ivec2 c = ivec2(i) + 4096;
|
|
22
|
+
return mix(
|
|
23
|
+
mix(rnd(c), rnd(c + ivec2(1, 0)), u.x),
|
|
24
|
+
mix(rnd(c + ivec2(0, 1)), rnd(c + ivec2(1, 1)), u.x),
|
|
25
|
+
u.y
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
float fbm(vec2 p) {
|
|
30
|
+
float s = 0.0;
|
|
31
|
+
float a = 0.5;
|
|
32
|
+
for (int i = 0; i < 4; i++) {
|
|
33
|
+
s += a * vnoise(p);
|
|
34
|
+
p = p * 2.02 + vec2(17.0, 9.0);
|
|
35
|
+
a *= 0.5;
|
|
36
|
+
}
|
|
37
|
+
return s;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* A one-sided Gaussian: one sigma above zero, another below. */
|
|
41
|
+
float lobe(float d, float above, float below) {
|
|
42
|
+
float s = d > 0.0 ? above : below;
|
|
43
|
+
return exp(-(d * d) / (2.0 * s * s));
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
export {
|
|
48
|
+
COMMON_GLSL
|
|
49
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const PASSES = [
|
|
2
|
+
{
|
|
3
|
+
id: "scrim",
|
|
4
|
+
label: "Scrim",
|
|
5
|
+
stage: "light",
|
|
6
|
+
on: false,
|
|
7
|
+
params: [{ key: "amount", label: "Amount", min: 0, max: 0.9, step: 0.01, default: 0.35 }],
|
|
8
|
+
glsl: (
|
|
9
|
+
/* glsl */
|
|
10
|
+
`
|
|
11
|
+
vec3 pass_scrim(vec3 c, vec2 uv) {
|
|
12
|
+
return mix(c, u_page, u_scrim_amount);
|
|
13
|
+
}`
|
|
14
|
+
)
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "vignette",
|
|
18
|
+
label: "Vignette",
|
|
19
|
+
stage: "light",
|
|
20
|
+
on: false,
|
|
21
|
+
params: [
|
|
22
|
+
{ key: "amount", label: "Amount", min: 0, max: 1, step: 0.01, default: 0.5 },
|
|
23
|
+
{ key: "size", label: "Size", min: 0.2, max: 1.2, step: 0.01, default: 0.75 }
|
|
24
|
+
],
|
|
25
|
+
glsl: (
|
|
26
|
+
/* glsl */
|
|
27
|
+
`
|
|
28
|
+
vec3 pass_vignette(vec3 c, vec2 uv) {
|
|
29
|
+
vec2 q = (uv - 0.5) * vec2(u_size.x / u_size.y, 1.0);
|
|
30
|
+
float v = smoothstep(u_vignette_size, u_vignette_size * 0.35, length(q));
|
|
31
|
+
return mix(u_page, c, mix(1.0, v, u_vignette_amount));
|
|
32
|
+
}`
|
|
33
|
+
)
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "fadeTop",
|
|
37
|
+
label: "Fade the top",
|
|
38
|
+
stage: "light",
|
|
39
|
+
on: true,
|
|
40
|
+
params: [
|
|
41
|
+
{ key: "start", label: "Starts at", min: 0.2, max: 0.95, step: 0.01, default: 0.43 },
|
|
42
|
+
{ key: "softness", label: "Softness", min: 0.3, max: 2, step: 0.01, default: 0.75 }
|
|
43
|
+
],
|
|
44
|
+
glsl: (
|
|
45
|
+
/* glsl */
|
|
46
|
+
`
|
|
47
|
+
vec3 pass_fadeTop(vec3 c, vec2 uv) {
|
|
48
|
+
float f = 1.0 - pow(smoothstep(u_fadeTop_start, 1.0, uv.y), u_fadeTop_softness);
|
|
49
|
+
return mix(u_page, c, f);
|
|
50
|
+
}`
|
|
51
|
+
)
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "fadeBottom",
|
|
55
|
+
label: "Fade the bottom",
|
|
56
|
+
stage: "light",
|
|
57
|
+
on: true,
|
|
58
|
+
params: [
|
|
59
|
+
{ key: "from", label: "Solid below", min: 0, max: 0.4, step: 0.01, default: 0.04 },
|
|
60
|
+
{ key: "to", label: "Clear above", min: 0.05, max: 0.7, step: 0.01, default: 0.3 }
|
|
61
|
+
],
|
|
62
|
+
glsl: (
|
|
63
|
+
/* glsl */
|
|
64
|
+
`
|
|
65
|
+
vec3 pass_fadeBottom(vec3 c, vec2 uv) {
|
|
66
|
+
float f = smoothstep(u_fadeBottom_from, max(u_fadeBottom_to, u_fadeBottom_from + 0.01), uv.y);
|
|
67
|
+
return mix(u_page, c, f);
|
|
68
|
+
}`
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "grain",
|
|
73
|
+
label: "Film grain",
|
|
74
|
+
stage: "srgb",
|
|
75
|
+
on: true,
|
|
76
|
+
params: [{ key: "amount", label: "Amount", min: 0, max: 0.4, step: 5e-3, default: 0.198 }],
|
|
77
|
+
glsl: (
|
|
78
|
+
/* glsl */
|
|
79
|
+
`
|
|
80
|
+
vec3 pass_grain(vec3 c, vec2 uv) {
|
|
81
|
+
uvec2 gp = uvec2(gl_FragCoord.xy) + uvec2(
|
|
82
|
+
uint(fract(u_time * 7.31) * 1024.0) * 7919u,
|
|
83
|
+
uint(fract(u_time * 3.17) * 1024.0) * 104729u
|
|
84
|
+
);
|
|
85
|
+
float gr = float(ihash(gp) & 255u) / 255.0 - 0.5;
|
|
86
|
+
return c + gr * u_grain_amount * 0.35;
|
|
87
|
+
}`
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
export {
|
|
92
|
+
PASSES
|
|
93
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Pass, Scene, Values } from './types';
|
|
2
|
+
export type Rgb = [number, number, number];
|
|
3
|
+
export type Colours = {
|
|
4
|
+
/** The ground the scene is painted against. */
|
|
5
|
+
ground: Rgb;
|
|
6
|
+
/** The page's own ground, which the passes fade to. */
|
|
7
|
+
page: Rgb;
|
|
8
|
+
/** A night scene on a light page, laid on as a pale tint. */
|
|
9
|
+
lightMode: boolean;
|
|
10
|
+
colours: Rgb[];
|
|
11
|
+
};
|
|
12
|
+
/** Resolves the page ground and a scene's tokens to linear RGB at `host`. */
|
|
13
|
+
export declare function readColours(host: HTMLElement, tokens: string[]): Colours;
|
|
14
|
+
/**
|
|
15
|
+
* A scene's colours for a surface: read from the cascade. A night-only
|
|
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 a pale tint
|
|
18
|
+
* (u_lightMode), so its masks still fade to the page and the theme stays
|
|
19
|
+
* light.
|
|
20
|
+
*/
|
|
21
|
+
export declare function coloursFor(host: HTMLElement, scene: Scene): Colours;
|
|
22
|
+
export declare function createRenderer(gl: WebGL2RenderingContext, scene: Scene, passes: Pass[]): {
|
|
23
|
+
setColours({ ground, page, lightMode, colours }: Colours): void;
|
|
24
|
+
draw(values: Values, time: number, width: number, height: number): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
} | null;
|
|
27
|
+
/**
|
|
28
|
+
* Paints each recipe once on a throwaway context and returns the pictures
|
|
29
|
+
* as data URLs, then releases the context, so the tiles cost no live GPU
|
|
30
|
+
* context of their own and the page keeps one.
|
|
31
|
+
*/
|
|
32
|
+
export declare function bakeThumbnails(host: HTMLElement, jobs: {
|
|
33
|
+
scene: Scene;
|
|
34
|
+
values: Values;
|
|
35
|
+
}[], passes: Pass[], width: number, height: number): string[];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { assemble, uniformNames, VERTEX } from "./assemble.js";
|
|
2
|
+
import { MAX_COLOURS } from "./types.js";
|
|
3
|
+
const NIGHT_GROUND = [15e-4, 18e-4, 3e-3];
|
|
4
|
+
function readColours(host, tokens) {
|
|
5
|
+
const probe = document.createElement("span");
|
|
6
|
+
probe.style.display = "none";
|
|
7
|
+
host.appendChild(probe);
|
|
8
|
+
const dot = document.createElement("canvas");
|
|
9
|
+
dot.width = 1;
|
|
10
|
+
dot.height = 1;
|
|
11
|
+
const ctx = dot.getContext("2d", { willReadFrequently: true });
|
|
12
|
+
const lin = (c) => Math.pow(c / 255, 2.2);
|
|
13
|
+
const read = (token) => {
|
|
14
|
+
if (!ctx) return [0.2, 0.2, 0.2];
|
|
15
|
+
probe.style.color = `var(${token})`;
|
|
16
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
17
|
+
ctx.fillStyle = getComputedStyle(probe).color;
|
|
18
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
19
|
+
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
|
|
20
|
+
return [lin(r), lin(g), lin(b)];
|
|
21
|
+
};
|
|
22
|
+
const ground = read("--color-bg-page-primary");
|
|
23
|
+
const colours = tokens.slice(0, MAX_COLOURS).map(read);
|
|
24
|
+
probe.remove();
|
|
25
|
+
return { ground, page: ground, lightMode: false, colours };
|
|
26
|
+
}
|
|
27
|
+
function coloursFor(host, scene) {
|
|
28
|
+
const colours = readColours(host, scene.colours);
|
|
29
|
+
const pageIsDark = document.documentElement.getAttribute("data-theme") === "dark";
|
|
30
|
+
if (scene.mode === "dark" && !pageIsDark) {
|
|
31
|
+
colours.ground = NIGHT_GROUND;
|
|
32
|
+
colours.lightMode = true;
|
|
33
|
+
}
|
|
34
|
+
return colours;
|
|
35
|
+
}
|
|
36
|
+
function compile(gl, type, source) {
|
|
37
|
+
const shader = gl.createShader(type);
|
|
38
|
+
if (!shader) return null;
|
|
39
|
+
gl.shaderSource(shader, source);
|
|
40
|
+
gl.compileShader(shader);
|
|
41
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
42
|
+
console.warn(gl.getShaderInfoLog(shader));
|
|
43
|
+
gl.deleteShader(shader);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return shader;
|
|
47
|
+
}
|
|
48
|
+
function valueOf(values, passes, name) {
|
|
49
|
+
for (const pass of passes) {
|
|
50
|
+
const prefix = `u_${pass.id}_`;
|
|
51
|
+
if (!name.startsWith(prefix)) continue;
|
|
52
|
+
const state = values.passes[pass.id];
|
|
53
|
+
const key = name.slice(prefix.length);
|
|
54
|
+
if (key === "on") return state?.on ? 1 : 0;
|
|
55
|
+
return state?.params[key] ?? 0;
|
|
56
|
+
}
|
|
57
|
+
return values.scene[name.slice(2)] ?? 0;
|
|
58
|
+
}
|
|
59
|
+
function createRenderer(gl, scene, passes) {
|
|
60
|
+
const vs = compile(gl, gl.VERTEX_SHADER, VERTEX);
|
|
61
|
+
const fs = compile(gl, gl.FRAGMENT_SHADER, assemble(scene, passes));
|
|
62
|
+
const program = gl.createProgram();
|
|
63
|
+
if (!vs || !fs || !program) return null;
|
|
64
|
+
gl.attachShader(program, vs);
|
|
65
|
+
gl.attachShader(program, fs);
|
|
66
|
+
gl.linkProgram(program);
|
|
67
|
+
gl.useProgram(program);
|
|
68
|
+
const vao = gl.createVertexArray();
|
|
69
|
+
gl.bindVertexArray(vao);
|
|
70
|
+
const at = (name) => gl.getUniformLocation(program, name);
|
|
71
|
+
const uSize = at("u_size");
|
|
72
|
+
const uTime = at("u_time");
|
|
73
|
+
const uGround = at("u_ground");
|
|
74
|
+
const uPage = at("u_page");
|
|
75
|
+
const uLightMode = at("u_lightMode");
|
|
76
|
+
const uCols = at("u_col");
|
|
77
|
+
const floats = uniformNames(scene, passes).map((name) => [name, at(name)]);
|
|
78
|
+
return {
|
|
79
|
+
setColours({ ground, page, lightMode, colours }) {
|
|
80
|
+
gl.uniform3fv(uGround, ground);
|
|
81
|
+
gl.uniform3fv(uPage, page);
|
|
82
|
+
gl.uniform1f(uLightMode, lightMode ? 1 : 0);
|
|
83
|
+
const flat = new Float32Array(MAX_COLOURS * 3);
|
|
84
|
+
colours.forEach((rgb, i) => flat.set(rgb, i * 3));
|
|
85
|
+
gl.uniform3fv(uCols, flat);
|
|
86
|
+
},
|
|
87
|
+
draw(values, time, width, height) {
|
|
88
|
+
gl.viewport(0, 0, width, height);
|
|
89
|
+
gl.uniform2f(uSize, width, height);
|
|
90
|
+
gl.uniform1f(uTime, time);
|
|
91
|
+
for (const [name, location] of floats) gl.uniform1f(location, valueOf(values, passes, name));
|
|
92
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
93
|
+
},
|
|
94
|
+
dispose() {
|
|
95
|
+
gl.deleteVertexArray(vao);
|
|
96
|
+
gl.deleteProgram(program);
|
|
97
|
+
gl.deleteShader(vs);
|
|
98
|
+
gl.deleteShader(fs);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function bakeThumbnails(host, jobs, passes, width, height) {
|
|
103
|
+
const canvas = document.createElement("canvas");
|
|
104
|
+
canvas.width = width;
|
|
105
|
+
canvas.height = height;
|
|
106
|
+
const gl = canvas.getContext("webgl2", { antialias: false, alpha: false, preserveDrawingBuffer: true });
|
|
107
|
+
if (!gl) return jobs.map(() => "");
|
|
108
|
+
const urls = jobs.map(({ scene, values }) => {
|
|
109
|
+
const renderer = createRenderer(gl, scene, passes);
|
|
110
|
+
if (!renderer) return "";
|
|
111
|
+
renderer.setColours(coloursFor(host, scene));
|
|
112
|
+
renderer.draw(values, 20, width, height);
|
|
113
|
+
const url = canvas.toDataURL("image/jpeg", 0.85);
|
|
114
|
+
renderer.dispose();
|
|
115
|
+
return url;
|
|
116
|
+
});
|
|
117
|
+
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
118
|
+
return urls;
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
bakeThumbnails,
|
|
122
|
+
coloursFor,
|
|
123
|
+
createRenderer,
|
|
124
|
+
readColours
|
|
125
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Scene } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The horizon, ported from /labs/horizon as a scene: a planet's limb at
|
|
4
|
+
* night with a fixed sun at the apex, soft layers of light along the arc,
|
|
5
|
+
* a hazy world of land and cloud below, and deep ocean blue further down.
|
|
6
|
+
* The horizon lab's own fades and grain are passes here, so they can be switched
|
|
7
|
+
* and tuned like any other scene's.
|
|
8
|
+
*/
|
|
9
|
+
export declare const horizon: Scene;
|
|
10
|
+
/**
|
|
11
|
+
* The rift, after /labs/rift, as a soft shader rather than streaming type:
|
|
12
|
+
* a glowing vertical tear in the page that opens widest at its middle and
|
|
13
|
+
* narrows to a seam at either end, a bright core inside a wide glow and a
|
|
14
|
+
* faint haze, and streaks of light drawn in toward it from both sides. The
|
|
15
|
+
* tear's line wanders slowly, and the colour runs from one ambient tone at
|
|
16
|
+
* the top to another at the bottom, the rift lab's own pair.
|
|
17
|
+
*/
|
|
18
|
+
export declare const rift: Scene;
|
|
19
|
+
/** Every scene, in picker order. */
|
|
20
|
+
export declare const SCENES: Scene[];
|