rift-ds 1.28.0 → 1.30.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 +5 -4
- package/bin/rift-ds.mjs +5 -4
- package/bin/templates/app/components/rift/ColorModeScript.tsx +7 -3
- package/bin/templates/blocks/app/settings/ProfileForm.tsx +98 -0
- package/bin/templates/blocks/app/settings/page.module.css +11 -0
- package/bin/templates/blocks/app/settings/page.tsx +84 -0
- 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/AppShell.module.css +8 -41
- package/bin/templates/blocks/components/blocks/AppShell.tsx +9 -11
- package/bin/templates/blocks/components/blocks/emberScene.ts +53 -0
- package/bin/templates/blocks/registry.json +24 -0
- package/bin/templates/chat/app/api/chat/feedback/route.ts +0 -3
- package/bin/templates/chat/app/api/chat/followups/route.ts +0 -3
- package/bin/templates/chat/app/api/chat/route.ts +0 -2
- package/chat/ChatLauncher.d.ts +9 -1
- package/chat/ChatLauncher.js +3 -1
- package/chat/threads.js +7 -4
- package/components/Alert/Alert.css +12 -0
- package/components/Alert/Alert.d.ts +2 -0
- package/components/Alert/Alert.js +3 -1
- package/components/Attachment/Attachment.css +92 -0
- package/components/Attachment/FileRow.d.ts +47 -0
- package/components/Attachment/FileRow.js +38 -0
- package/components/Avatar/Avatar.css +14 -0
- package/components/Avatar/Avatar.d.ts +3 -1
- package/components/Avatar/Avatar.js +3 -2
- package/components/Button/Button.css +38 -0
- package/components/Button/Button.d.ts +8 -0
- package/components/Button/Button.js +2 -0
- package/components/Chart/AreaChart.d.ts +2 -0
- package/components/Chart/AreaChart.js +2 -1
- package/components/Chart/BarChart.d.ts +2 -0
- package/components/Chart/BarChart.js +2 -1
- package/components/Chart/ComboChart.d.ts +4 -0
- package/components/Chart/ComboChart.js +4 -2
- package/components/Chart/LineChart.d.ts +2 -0
- package/components/Chart/LineChart.js +2 -1
- package/components/Chart/PieChart.d.ts +4 -4
- package/components/Chart/PieChart.js +1 -1
- package/components/Chart/ScatterChart.d.ts +2 -0
- package/components/Chart/ScatterChart.js +2 -1
- package/components/Checklist/Checklist.css +123 -0
- package/components/Checklist/Checklist.d.ts +66 -0
- package/components/Checklist/Checklist.js +115 -0
- package/components/CircularButton/CircularButton.css +39 -0
- package/components/CircularButton/CircularButton.d.ts +13 -0
- package/components/CircularButton/CircularButton.js +18 -4
- package/components/ColourSwatch/ColourSwatch.css +3 -1
- package/components/ColourSwatch/ColourSwatch.d.ts +5 -3
- package/components/ColourSwatch/ColourSwatch.js +5 -0
- package/components/Combobox/Combobox.d.ts +4 -2
- package/components/Combobox/Combobox.js +7 -3
- package/components/DataTable/DataTable.css +35 -0
- package/components/DataTable/DataTable.d.ts +34 -2
- package/components/DataTable/DataTable.js +58 -5
- package/components/DataTable/columnTypes.d.ts +1 -1
- package/components/DataTable/columnTypes.js +1 -1
- package/components/DateInput/DateInput.d.ts +4 -2
- package/components/DateInput/DateInput.js +7 -3
- package/components/DescriptionList/DescriptionList.css +28 -0
- package/components/DescriptionList/DescriptionList.d.ts +3 -1
- package/components/DescriptionList/DescriptionList.js +4 -3
- package/components/DescriptionList/DescriptionListCopy.js +2 -0
- package/components/Dropdown/Dropdown.d.ts +4 -2
- package/components/Dropdown/Dropdown.js +7 -3
- package/components/EmptyState/EmptyState.css +12 -0
- package/components/EmptyState/EmptyState.d.ts +7 -0
- package/components/EmptyState/EmptyState.js +2 -0
- package/components/EventCalendar/EventCalendar.css +59 -0
- package/components/EventCalendar/EventCalendar.d.ts +24 -2
- package/components/EventCalendar/EventCalendar.js +104 -19
- package/components/FormSection/FormSection.css +70 -0
- package/components/FormSection/FormSection.d.ts +35 -0
- package/components/FormSection/FormSection.js +35 -0
- package/components/Grid/Grid.css +52 -0
- package/components/Grid/Grid.d.ts +30 -0
- package/components/Grid/Grid.js +36 -0
- package/components/Icon/Icon.css +55 -0
- package/components/Icon/Icon.d.ts +27 -0
- package/components/Icon/Icon.js +42 -0
- package/components/NumberInput/NumberInput.d.ts +4 -2
- package/components/NumberInput/NumberInput.js +7 -3
- package/components/OrgChart/OrgChart.css +143 -0
- package/components/OrgChart/OrgChart.d.ts +44 -0
- package/components/OrgChart/OrgChart.js +26 -0
- package/components/PageHeader/PageHeader.css +74 -0
- package/components/PageHeader/PageHeader.d.ts +39 -0
- package/components/PageHeader/PageHeader.js +33 -0
- package/components/Panel/Panel.css +7 -0
- package/components/Panel/Panel.d.ts +5 -2
- package/components/Panel/Panel.js +2 -1
- package/components/ResourceTimeline/ResourceTimeline.css +194 -0
- package/components/ResourceTimeline/ResourceTimeline.d.ts +57 -0
- package/components/ResourceTimeline/ResourceTimeline.js +129 -0
- package/components/ShaderField/useShaderField.js +13 -1
- package/components/ShaderScene/ShaderScene.d.ts +39 -15
- package/components/ShaderScene/ShaderScene.js +87 -6
- 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/Stack/Stack.css +68 -0
- package/components/Stack/Stack.d.ts +37 -0
- package/components/Stack/Stack.js +39 -0
- package/components/Stat/Stat.css +65 -0
- package/components/Stat/Stat.d.ts +7 -1
- package/components/Stat/Stat.js +16 -1
- package/components/Table/Table.css +11 -0
- package/components/Table/Table.d.ts +2 -0
- package/components/Table/Table.js +5 -1
- package/components/Tabs/Tabs.css +23 -0
- package/components/Tabs/Tabs.d.ts +9 -8
- package/components/Tabs/Tabs.js +38 -5
- package/components/Textarea/Textarea.d.ts +4 -2
- package/components/Textarea/Textarea.js +7 -3
- package/components/ThemeToggle/colorMode.d.ts +17 -1
- package/components/ThemeToggle/colorMode.js +11 -2
- package/components/Widget/Widget.css +21 -0
- package/components/Widget/Widget.d.ts +4 -0
- package/components/Widget/Widget.js +13 -5
- package/components/Wizard/Wizard.css +67 -0
- package/components/Wizard/Wizard.d.ts +54 -0
- package/components/Wizard/Wizard.js +71 -0
- package/components/registry.d.ts +25 -0
- package/components/registry.js +8 -0
- package/components/registry.json +234 -33
- package/components/registry.json.d.ts +234 -33
- package/components/registry.json.js +1 -1
- package/index.d.ts +10 -0
- package/index.js +20 -0
- package/package.json +1 -1
- package/tokens/motion.d.ts +2 -0
- package/tokens/motion.js +2 -0
- package/tokens/values.d.ts +31 -0
- package/tokens/values.js +16 -0
- package/tokens/values.json.js +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/** The accents a bar can take, the core accent roles the calendar's events use. */
|
|
3
|
+
export type ResourceTimelineColor = "neutral" | "coral" | "violet" | "cobalt" | "amber" | "gold" | "mint";
|
|
4
|
+
/** One stretch of time on a row: a booking, a meeting, a run. */
|
|
5
|
+
export interface ResourceTimelineBar {
|
|
6
|
+
/** A stable id for the bar. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** When it starts, as 24-hour `HH:MM`. */
|
|
9
|
+
start: string;
|
|
10
|
+
/** When it ends, as 24-hour `HH:MM`. */
|
|
11
|
+
end: string;
|
|
12
|
+
/** A short label on the bar ("Front desk", "Break"). */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** The bar's accent. Defaults to `neutral`. */
|
|
15
|
+
color?: ResourceTimelineColor;
|
|
16
|
+
}
|
|
17
|
+
/** One row of the timeline: a person, a room, a machine. */
|
|
18
|
+
export interface ResourceTimelineRow {
|
|
19
|
+
/** A stable id for the row. */
|
|
20
|
+
id: string;
|
|
21
|
+
/** What the row is, shown in the label column. */
|
|
22
|
+
label: string;
|
|
23
|
+
/** The row's bars, in any order. */
|
|
24
|
+
bars: ResourceTimelineBar[];
|
|
25
|
+
}
|
|
26
|
+
/** Props owned by ResourceTimeline itself; everything else falls through to the root `<div>`. */
|
|
27
|
+
type ResourceTimelineOwnProps = {
|
|
28
|
+
/** The rows, top to bottom. */
|
|
29
|
+
rows: ResourceTimelineRow[];
|
|
30
|
+
/** The first hour the axis shows, 0 to 23. Defaults to 6. */
|
|
31
|
+
startHour?: number;
|
|
32
|
+
/** The hour the axis ends at, 1 to 24. Defaults to 22. */
|
|
33
|
+
endHour?: number;
|
|
34
|
+
/** A line at this time (`HH:MM`), such as the time now. */
|
|
35
|
+
now?: string;
|
|
36
|
+
/** The timeline's name, read before its rows ("Bookings, Tuesday 4 March"). */
|
|
37
|
+
label: string;
|
|
38
|
+
/** The header of the label column. Defaults to "Name". */
|
|
39
|
+
rowHeaderLabel?: string;
|
|
40
|
+
/** Called with the bar and its row when a bar is pressed; bars are buttons only when it is set. */
|
|
41
|
+
onBarClick?: (bar: ResourceTimelineBar, row: ResourceTimelineRow) => void;
|
|
42
|
+
/** The BCP 47 locale the times are written in, such as `de-DE`. Defaults to `en-US`. This component can render from a Server Component, so it takes the prop alone and reads no LocaleProvider. */
|
|
43
|
+
locale?: string;
|
|
44
|
+
/** Additional CSS classes */
|
|
45
|
+
className?: string;
|
|
46
|
+
};
|
|
47
|
+
export interface ResourceTimelineProps extends ResourceTimelineOwnProps, Omit<React.ComponentPropsWithRef<"div">, keyof ResourceTimelineOwnProps | "children"> {
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hours within one day: a row per person or resource, a bar from each
|
|
51
|
+
* start to its end, on an axis of hours in the reader's locale. Room
|
|
52
|
+
* bookings, a team's meetings, a machine's runs. Each bar is named with its row and its times,
|
|
53
|
+
* and its label sits on the calendar's event fill, so it reads in every
|
|
54
|
+
* theme whatever the accent. Server-renderable.
|
|
55
|
+
*/
|
|
56
|
+
export declare function ResourceTimeline({ rows, startHour, endHour, now, label, rowHeaderLabel, onBarClick, locale, className, style, ref, ...rest }: ResourceTimelineProps): React.JSX.Element;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { DEFAULT_LOCALE } from "../../behaviors/locale.js";
|
|
4
|
+
import { ScrollRegion } from "../../behaviors/ScrollRegion.js";
|
|
5
|
+
import "../../behaviors/visually-hidden.css";
|
|
6
|
+
import "../../behaviors/direction.css";
|
|
7
|
+
import "./ResourceTimeline.css";
|
|
8
|
+
const minutesOf = (time) => {
|
|
9
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(time);
|
|
10
|
+
if (!match) return null;
|
|
11
|
+
return Number(match[1]) * 60 + Number(match[2]);
|
|
12
|
+
};
|
|
13
|
+
function ResourceTimeline({
|
|
14
|
+
rows,
|
|
15
|
+
startHour = 6,
|
|
16
|
+
endHour = 22,
|
|
17
|
+
now,
|
|
18
|
+
label,
|
|
19
|
+
rowHeaderLabel = "Name",
|
|
20
|
+
onBarClick,
|
|
21
|
+
locale = DEFAULT_LOCALE,
|
|
22
|
+
className = "",
|
|
23
|
+
style,
|
|
24
|
+
ref,
|
|
25
|
+
...rest
|
|
26
|
+
}) {
|
|
27
|
+
const from = Math.max(0, Math.min(23, startHour)) * 60;
|
|
28
|
+
const to = Math.max(from / 60 + 1, Math.min(24, endHour)) * 60;
|
|
29
|
+
const span = to - from;
|
|
30
|
+
const at = (minutes) => (Math.min(Math.max(minutes, from), to) - from) / span * 100;
|
|
31
|
+
const hourFormat = new Intl.DateTimeFormat(locale, { hour: "numeric" });
|
|
32
|
+
const timeFormat = new Intl.DateTimeFormat(locale, {
|
|
33
|
+
hour: "numeric",
|
|
34
|
+
minute: "2-digit"
|
|
35
|
+
});
|
|
36
|
+
const asDate = (minutes) => new Date(2e3, 0, 1, Math.floor(minutes / 60), minutes % 60);
|
|
37
|
+
const range = (start, end) => timeFormat.formatRange(asDate(start), asDate(end));
|
|
38
|
+
const hours = [];
|
|
39
|
+
for (let h = from / 60; h <= to / 60; h++) hours.push(h);
|
|
40
|
+
const nowMinutes = now ? minutesOf(now) : null;
|
|
41
|
+
const classes = ["ds-resource-timeline", className].filter(Boolean).join(" ");
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
role: "group",
|
|
46
|
+
"aria-label": label,
|
|
47
|
+
...rest,
|
|
48
|
+
ref,
|
|
49
|
+
className: classes,
|
|
50
|
+
style: {
|
|
51
|
+
...style,
|
|
52
|
+
"--ds-resource-timeline-hours": hours.length - 1
|
|
53
|
+
},
|
|
54
|
+
children: /* @__PURE__ */ jsxs(ScrollRegion, { className: "ds-resource-timeline__scroll", children: [
|
|
55
|
+
/* @__PURE__ */ jsxs("div", { className: "ds-resource-timeline__head", "aria-hidden": "true", children: [
|
|
56
|
+
/* @__PURE__ */ jsx("span", { className: "ds-resource-timeline__row-header", children: rowHeaderLabel }),
|
|
57
|
+
/* @__PURE__ */ jsx("div", { className: "ds-resource-timeline__axis", children: hours.map((h) => /* @__PURE__ */ jsx(
|
|
58
|
+
"span",
|
|
59
|
+
{
|
|
60
|
+
className: "ds-resource-timeline__tick",
|
|
61
|
+
style: { insetInlineStart: `${at(h * 60)}%` },
|
|
62
|
+
children: h < 24 ? hourFormat.format(asDate(h * 60)) : ""
|
|
63
|
+
},
|
|
64
|
+
h
|
|
65
|
+
)) })
|
|
66
|
+
] }),
|
|
67
|
+
/* @__PURE__ */ jsx("ul", { className: "ds-resource-timeline__rows", children: rows.map((row) => /* @__PURE__ */ jsxs("li", { className: "ds-resource-timeline__row", children: [
|
|
68
|
+
/* @__PURE__ */ jsx("span", { className: "ds-resource-timeline__label", children: row.label }),
|
|
69
|
+
/* @__PURE__ */ jsxs("div", { className: "ds-resource-timeline__track", children: [
|
|
70
|
+
hours.map((h) => /* @__PURE__ */ jsx(
|
|
71
|
+
"span",
|
|
72
|
+
{
|
|
73
|
+
className: "ds-resource-timeline__gridline",
|
|
74
|
+
style: { insetInlineStart: `${at(h * 60)}%` },
|
|
75
|
+
"aria-hidden": "true"
|
|
76
|
+
},
|
|
77
|
+
h
|
|
78
|
+
)),
|
|
79
|
+
nowMinutes !== null && nowMinutes >= from && nowMinutes <= to && /* @__PURE__ */ jsx(
|
|
80
|
+
"span",
|
|
81
|
+
{
|
|
82
|
+
className: "ds-resource-timeline__now",
|
|
83
|
+
style: { insetInlineStart: `${at(nowMinutes)}%` },
|
|
84
|
+
"aria-hidden": "true"
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
row.bars.map((bar) => {
|
|
88
|
+
const start = minutesOf(bar.start);
|
|
89
|
+
const end = minutesOf(bar.end);
|
|
90
|
+
if (start === null || end === null || end <= start)
|
|
91
|
+
return null;
|
|
92
|
+
const name = `${row.label}, ${bar.label ? `${bar.label}, ` : ""}${range(start, end)}`;
|
|
93
|
+
const barClass = `ds-resource-timeline__bar ds-resource-timeline__bar--${bar.color ?? "neutral"}`;
|
|
94
|
+
const barStyle = {
|
|
95
|
+
insetInlineStart: `${at(start)}%`,
|
|
96
|
+
inlineSize: `${at(end) - at(start)}%`
|
|
97
|
+
};
|
|
98
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"span",
|
|
101
|
+
{
|
|
102
|
+
className: "ds-resource-timeline__bar-label",
|
|
103
|
+
"aria-hidden": "true",
|
|
104
|
+
children: bar.label ?? range(start, end)
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", children: name })
|
|
108
|
+
] });
|
|
109
|
+
return onBarClick ? /* @__PURE__ */ jsx(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
type: "button",
|
|
113
|
+
className: barClass,
|
|
114
|
+
style: barStyle,
|
|
115
|
+
onClick: () => onBarClick(bar, row),
|
|
116
|
+
children: content
|
|
117
|
+
},
|
|
118
|
+
bar.id
|
|
119
|
+
) : /* @__PURE__ */ jsx("span", { className: barClass, style: barStyle, children: content }, bar.id);
|
|
120
|
+
})
|
|
121
|
+
] })
|
|
122
|
+
] }, row.id)) })
|
|
123
|
+
] })
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
ResourceTimeline
|
|
129
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useState, useRef, useEffect } from "react";
|
|
3
3
|
import { BLOB_COUNT, vertexSource, fragmentSource } from "./field.glsl.js";
|
|
4
|
-
import { MOTION_CONTEXT_RESTORE_WAIT_MS, MOTION_SHADER_COLOR_FADE_MS } from "../../tokens/motion.js";
|
|
4
|
+
import { MOTION_CONTEXT_RESTORE_WAIT_MS, MOTION_SHADER_COLOR_CHECK_MS, MOTION_SHADER_COLOR_FADE_MS } from "../../tokens/motion.js";
|
|
5
5
|
const DEFAULT_SHADER_PARAMS = {
|
|
6
6
|
intensity: 0.5,
|
|
7
7
|
warp: 0.14,
|
|
@@ -32,6 +32,7 @@ const FRAME_MS = 1e3 / 30;
|
|
|
32
32
|
const FRAME_MS_ACTIVE = 1e3 / 60;
|
|
33
33
|
const WAKE_IDLE = 0.015;
|
|
34
34
|
const COLOR_FADE_MS = MOTION_SHADER_COLOR_FADE_MS;
|
|
35
|
+
const COLOR_CHECK_MS = MOTION_SHADER_COLOR_CHECK_MS;
|
|
35
36
|
function parseColor(value) {
|
|
36
37
|
const v = value.trim();
|
|
37
38
|
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(v);
|
|
@@ -169,8 +170,15 @@ function useShaderField(canvasRef, params, enabled = true) {
|
|
|
169
170
|
const colorCurrent = new Float32Array(BLOB_COUNT * 3);
|
|
170
171
|
const colorTarget = new Float32Array(BLOB_COUNT * 3);
|
|
171
172
|
let colorFadeT = COLOR_FADE_MS;
|
|
173
|
+
let colorSignature = "";
|
|
174
|
+
let colorsChecked = 0;
|
|
175
|
+
function readSignature() {
|
|
176
|
+
const style = getComputedStyle(canvas);
|
|
177
|
+
return paramsRef.current.blobs.slice(0, BLOB_COUNT).map((b) => style.getPropertyValue(b.token).trim()).join("|");
|
|
178
|
+
}
|
|
172
179
|
function readColors(into) {
|
|
173
180
|
const style = getComputedStyle(canvas);
|
|
181
|
+
colorSignature = readSignature();
|
|
174
182
|
into.fill(0);
|
|
175
183
|
paramsRef.current.blobs.slice(0, BLOB_COUNT).forEach((b, i) => {
|
|
176
184
|
const parsed = parseColor(style.getPropertyValue(b.token));
|
|
@@ -283,6 +291,10 @@ function useShaderField(canvasRef, params, enabled = true) {
|
|
|
283
291
|
if (elapsed < frameBudget - 1) return;
|
|
284
292
|
const dt = Math.min(elapsed, 100);
|
|
285
293
|
lastDraw = now;
|
|
294
|
+
if (now - colorsChecked >= COLOR_CHECK_MS) {
|
|
295
|
+
colorsChecked = now;
|
|
296
|
+
if (readSignature() !== colorSignature) colorsDirty = true;
|
|
297
|
+
}
|
|
286
298
|
fieldTime += dt / 1e3 * paramsRef.current.speed;
|
|
287
299
|
draw(dt);
|
|
288
300
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
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`
|
|
8
|
-
* once a frame has painted, `unavailable` when it is disabled
|
|
9
|
-
* cannot run it
|
|
8
|
+
* once a frame has painted, `unavailable` when it is disabled, WebGL2
|
|
9
|
+
* cannot run it or its context is lost (it returns to `active` when the
|
|
10
|
+
* context comes back).
|
|
10
11
|
*/
|
|
11
12
|
export type ShaderSceneStatus = 'pending' | 'active' | 'unavailable';
|
|
12
13
|
/** One finishing pass's setting: whether it runs, and its own settings. */
|
|
@@ -18,11 +19,17 @@ export type ShaderScenePassSetting = {
|
|
|
18
19
|
};
|
|
19
20
|
/** Props owned by ShaderScene itself; everything else falls through to the root. */
|
|
20
21
|
type ShaderSceneOwnProps = {
|
|
21
|
-
/**
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The scene to paint: one of the library's by id, or a scene of your own as
|
|
24
|
+
* a `ShaderSceneSource` (its colour roles, its settings and the GLSL that
|
|
25
|
+
* 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
|
|
26
|
+
* an object written inline rebuilds nothing until what it says changes.
|
|
27
|
+
*/
|
|
28
|
+
scene?: ShaderSceneId | ShaderSceneSource;
|
|
23
29
|
/**
|
|
24
30
|
* The scene's settings, merged over its defaults (`SHADER_SCENES` lists each
|
|
25
|
-
* scene's keys and ranges
|
|
31
|
+
* library scene's keys and ranges; your own scene declares its own), so
|
|
32
|
+
* passing one changes one thing. Changing them
|
|
26
33
|
* never rebuilds the GL state.
|
|
27
34
|
*/
|
|
28
35
|
params?: Partial<Record<string, number>>;
|
|
@@ -51,6 +58,14 @@ type ShaderSceneOwnProps = {
|
|
|
51
58
|
* decision.
|
|
52
59
|
*/
|
|
53
60
|
onStatusChange?: (status: ShaderSceneStatus) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Called with the compiler's log when the scene's GLSL fails to compile or
|
|
63
|
+
* link, for a scene of your own. Its line numbers count from the first
|
|
64
|
+
* line of the scene's `glsl`, written `1:<line>`. The status becomes
|
|
65
|
+
* `unavailable` as well, and the log still reaches the console. Replaces
|
|
66
|
+
* the native `onError` attribute, which a scene's root never fires.
|
|
67
|
+
*/
|
|
68
|
+
onError?: (message: string) => void;
|
|
54
69
|
/** Additional CSS classes */
|
|
55
70
|
className?: string;
|
|
56
71
|
};
|
|
@@ -58,16 +73,25 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
|
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
60
75
|
* 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
|
|
76
|
+
* 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
77
|
* bottom fades to the page, film grain). Its colours are the background
|
|
63
78
|
* field's roles (`--color-ambient-*`) read from the live cascade at the
|
|
64
79
|
* scene, so it re-themes with `data-theme`, a preset or any scoped override,
|
|
65
80
|
* and its fades melt into the page ground.
|
|
66
81
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
82
|
+
* It paints a scene of your own the same way: pass `scene` a
|
|
83
|
+
* `ShaderSceneSource` and it gets the same uniforms, noise helpers, passes,
|
|
84
|
+
* light-mode handling and budget the library's scenes do. A scene that
|
|
85
|
+
* fails to compile reports `unavailable` and hands its log to `onError`.
|
|
86
|
+
*
|
|
87
|
+
* Every scene but the ocean and the sky is a night scene: it adds light over a dark
|
|
88
|
+
* ground. On a light page each computes its light against a dark ground of
|
|
89
|
+
* its own and lays it onto the page as a pale tint, so it reads as a soft
|
|
90
|
+
* dawn rather than a dark block. The ocean paints both: a turquoise shallow
|
|
91
|
+
* over a light page ground, deep moonlit water over a dark one. The sky does
|
|
92
|
+
* too: a golden hour over a light ground, the last of a sunset under a night sky
|
|
93
|
+
* over a dark one. Nothing here
|
|
94
|
+
* sets `data-theme`, which would hide a preset's colours.
|
|
71
95
|
*
|
|
72
96
|
* It is scenery, not interface. It fills its positioned ancestor and is inert
|
|
73
97
|
* to pointer events and to assistive tech; give the ancestor the placement and
|
|
@@ -76,8 +100,8 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
|
|
|
76
100
|
* its first frame is drawn, then fades in, so where WebGL2 is unavailable
|
|
77
101
|
* whatever lies under it (the page, or a fallback of the caller's) shows.
|
|
78
102
|
*/
|
|
79
|
-
export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
|
|
80
|
-
export type {
|
|
103
|
+
export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, onError, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
|
|
104
|
+
export type { ShaderSceneParamSpec, ShaderSceneSource, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
|
|
81
105
|
export { SCENES as SHADER_SCENES } from './scenes';
|
|
82
106
|
export { PASSES as SHADER_PASSES } from './passes';
|
|
83
107
|
export { defaultsFor as shaderSceneDefaults } from './types';
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import React from "react";
|
|
4
|
-
import { MOTION_RENDERER_WATCHDOG_MS } from "../../tokens/motion.js";
|
|
4
|
+
import { MOTION_RENDERER_WATCHDOG_MS, MOTION_SHADER_COLOR_CHECK_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";
|
|
@@ -10,6 +12,7 @@ import { defaultsFor } from "./types.js";
|
|
|
10
12
|
import "./ShaderScene.css";
|
|
11
13
|
const MAX_PIXEL_RATIO = 1;
|
|
12
14
|
const FRAME_MS = 1e3 / 30;
|
|
15
|
+
const COLOUR_CHECK_MS = MOTION_SHADER_COLOR_CHECK_MS;
|
|
13
16
|
const DEFAULT_SPEED = 1.6;
|
|
14
17
|
function ShaderScene({
|
|
15
18
|
scene = "horizon",
|
|
@@ -19,13 +22,38 @@ function ShaderScene({
|
|
|
19
22
|
liveRef,
|
|
20
23
|
enabled = true,
|
|
21
24
|
onStatusChange,
|
|
25
|
+
onError,
|
|
22
26
|
className = "",
|
|
23
27
|
ref,
|
|
24
28
|
...rest
|
|
25
29
|
}) {
|
|
26
30
|
const hostRef = React.useRef(null);
|
|
27
31
|
const canvasRef = React.useRef(null);
|
|
28
|
-
const
|
|
32
|
+
const sceneKey = React.useMemo(() => {
|
|
33
|
+
if (typeof scene === "string") return scene;
|
|
34
|
+
const shipped = SCENES.find((s) => s === scene);
|
|
35
|
+
if (shipped) return shipped.id;
|
|
36
|
+
return JSON.stringify({
|
|
37
|
+
colours: scene.colours,
|
|
38
|
+
mode: scene.mode,
|
|
39
|
+
glyphs: scene.glyphs,
|
|
40
|
+
pixelRatio: scene.pixelRatio,
|
|
41
|
+
params: scene.params.map((param) => ({
|
|
42
|
+
key: param.key,
|
|
43
|
+
label: param.label,
|
|
44
|
+
min: param.min,
|
|
45
|
+
max: param.max,
|
|
46
|
+
step: param.step,
|
|
47
|
+
default: param.default
|
|
48
|
+
})),
|
|
49
|
+
glsl: scene.glsl
|
|
50
|
+
});
|
|
51
|
+
}, [scene]);
|
|
52
|
+
const custom = sceneKey.startsWith("{");
|
|
53
|
+
const definition = React.useMemo(
|
|
54
|
+
() => custom ? JSON.parse(sceneKey) : SCENES.find((s) => s.id === sceneKey) ?? SCENES[0],
|
|
55
|
+
[custom, sceneKey]
|
|
56
|
+
);
|
|
29
57
|
const merged = React.useMemo(
|
|
30
58
|
() => ({
|
|
31
59
|
speed,
|
|
@@ -51,6 +79,7 @@ function ShaderScene({
|
|
|
51
79
|
}, [merged]);
|
|
52
80
|
const [gl, setGl] = React.useState("pending");
|
|
53
81
|
const [gaveUp, setGaveUp] = React.useState(false);
|
|
82
|
+
const [restored, setRestored] = React.useState(0);
|
|
54
83
|
React.useEffect(() => {
|
|
55
84
|
if (!enabled || gl !== "pending") return;
|
|
56
85
|
const timer = window.setTimeout(() => setGaveUp(true), MOTION_RENDERER_WATCHDOG_MS);
|
|
@@ -64,6 +93,10 @@ function ShaderScene({
|
|
|
64
93
|
React.useEffect(() => {
|
|
65
94
|
notify.current?.(status);
|
|
66
95
|
}, [status]);
|
|
96
|
+
const reportError = React.useRef(onError);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
reportError.current = onError;
|
|
99
|
+
}, [onError]);
|
|
67
100
|
const setRef = (node) => {
|
|
68
101
|
hostRef.current = node;
|
|
69
102
|
if (typeof ref === "function") ref(node);
|
|
@@ -74,12 +107,49 @@ function ShaderScene({
|
|
|
74
107
|
const host = hostRef.current;
|
|
75
108
|
const canvas = canvasRef.current;
|
|
76
109
|
const context = canvas?.getContext("webgl2", { antialias: false, alpha: false });
|
|
77
|
-
|
|
110
|
+
if (host && custom) {
|
|
111
|
+
const styles = getComputedStyle(host);
|
|
112
|
+
sceneProblems(definition, PASSES, (property) => styles.getPropertyValue(property).trim() !== "").forEach(warnOnce);
|
|
113
|
+
}
|
|
114
|
+
const renderer = context ? createRenderer(context, definition, PASSES, (log) => {
|
|
115
|
+
console.warn(log);
|
|
116
|
+
reportError.current?.(log);
|
|
117
|
+
}) : null;
|
|
118
|
+
let lost = false;
|
|
119
|
+
const onContextLost = (event) => {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
lost = true;
|
|
122
|
+
setGl("failed");
|
|
123
|
+
};
|
|
124
|
+
const onContextRestored = () => {
|
|
125
|
+
setGl("pending");
|
|
126
|
+
setRestored((count) => count + 1);
|
|
127
|
+
};
|
|
128
|
+
canvas?.addEventListener("webglcontextlost", onContextLost);
|
|
129
|
+
canvas?.addEventListener("webglcontextrestored", onContextRestored);
|
|
130
|
+
const unlisten = () => {
|
|
131
|
+
canvas?.removeEventListener("webglcontextlost", onContextLost);
|
|
132
|
+
canvas?.removeEventListener("webglcontextrestored", onContextRestored);
|
|
133
|
+
};
|
|
78
134
|
if (!host || !canvas || !renderer) {
|
|
79
135
|
const failed = requestAnimationFrame(() => setGl("failed"));
|
|
80
|
-
return () =>
|
|
136
|
+
return () => {
|
|
137
|
+
cancelAnimationFrame(failed);
|
|
138
|
+
unlisten();
|
|
139
|
+
};
|
|
81
140
|
}
|
|
141
|
+
const colourTokens = ["--color-bg-page-primary", ...definition.colours];
|
|
142
|
+
const colourSignature = () => {
|
|
143
|
+
const styles = getComputedStyle(host);
|
|
144
|
+
return [
|
|
145
|
+
document.documentElement.getAttribute("data-theme"),
|
|
146
|
+
...colourTokens.map((token) => styles.getPropertyValue(token).trim())
|
|
147
|
+
].join("|");
|
|
148
|
+
};
|
|
149
|
+
let appliedColours = "";
|
|
150
|
+
let coloursChecked = 0;
|
|
82
151
|
const applyColours = () => {
|
|
152
|
+
appliedColours = colourSignature();
|
|
83
153
|
renderer.setColours(coloursFor(host, definition));
|
|
84
154
|
renderer.setGlyphs(glyphFontFor(host));
|
|
85
155
|
};
|
|
@@ -99,7 +169,12 @@ function ShaderScene({
|
|
|
99
169
|
let painted = false;
|
|
100
170
|
const draw = (now) => {
|
|
101
171
|
frame = requestAnimationFrame(draw);
|
|
172
|
+
if (lost) return;
|
|
102
173
|
if (painted && now - last < FRAME_MS - 1) return;
|
|
174
|
+
if (now - coloursChecked >= COLOUR_CHECK_MS) {
|
|
175
|
+
coloursChecked = now;
|
|
176
|
+
if (colourSignature() !== appliedColours) applyColours();
|
|
177
|
+
}
|
|
103
178
|
const values = liveRef?.current ?? mergedRef.current;
|
|
104
179
|
const dt = Math.min(0.1, (now - last) / 1e3);
|
|
105
180
|
last = now;
|
|
@@ -136,7 +211,7 @@ function ShaderScene({
|
|
|
136
211
|
);
|
|
137
212
|
visibilityObserver?.observe(host);
|
|
138
213
|
const sizeObserver = new ResizeObserver(() => {
|
|
139
|
-
if (frame) return;
|
|
214
|
+
if (frame || lost) return;
|
|
140
215
|
fit();
|
|
141
216
|
renderer.draw(liveRef?.current ?? mergedRef.current, time, canvas.width, canvas.height, ratio);
|
|
142
217
|
});
|
|
@@ -146,15 +221,21 @@ function ShaderScene({
|
|
|
146
221
|
attributes: true,
|
|
147
222
|
attributeFilter: ["data-theme", "data-brand", "style"]
|
|
148
223
|
});
|
|
224
|
+
const onSheetLoad = (event) => {
|
|
225
|
+
if (event.target instanceof HTMLLinkElement && colourSignature() !== appliedColours) applyColours();
|
|
226
|
+
};
|
|
227
|
+
document.addEventListener("load", onSheetLoad, true);
|
|
149
228
|
return () => {
|
|
150
229
|
mounted = false;
|
|
230
|
+
unlisten();
|
|
231
|
+
document.removeEventListener("load", onSheetLoad, true);
|
|
151
232
|
stop();
|
|
152
233
|
visibilityObserver?.disconnect();
|
|
153
234
|
sizeObserver.disconnect();
|
|
154
235
|
themeObserver.disconnect();
|
|
155
236
|
renderer.dispose();
|
|
156
237
|
};
|
|
157
|
-
}, [definition, liveRef, enabled]);
|
|
238
|
+
}, [definition, custom, liveRef, enabled, restored]);
|
|
158
239
|
const classes = ["ds-shader-scene", className].filter(Boolean).join(" ");
|
|
159
240
|
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
241
|
}
|
|
@@ -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 {};
|