rift-ds 1.25.0 → 1.27.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 +3 -1
- package/bin/templates/app/components/rift/font.css +7 -4
- package/chat/ChatThreads.d.ts +3 -1
- package/chat/ChatThreads.js +3 -1
- package/chat/ChatWidget.css +166 -15
- package/chat/ChatWidget.d.ts +1 -1
- package/chat/ChatWidget.js +5 -2
- package/components/ActionCard/ActionCard.d.ts +1 -1
- package/components/ContextMenu/ContextMenu.css +11 -0
- package/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/components/ContextMenu/ContextMenu.js +3 -1
- package/components/DataTable/DataTable.css +24 -4
- package/components/DataTable/DataTable.js +41 -40
- package/components/DropdownMenu/DropdownMenu.css +38 -0
- package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
- package/components/DropdownMenu/DropdownMenu.js +11 -5
- package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
- package/components/DropdownMenu/ShortcutHint.js +6 -0
- package/components/InterruptCard/InterruptCard.d.ts +1 -1
- package/components/MegaMenu/MegaMenu.css +5 -3
- package/components/MegaMenu/MegaMenu.d.ts +4 -1
- package/components/MegaMenu/MegaMenu.js +34 -20
- package/components/MessageCard/MessageCard.css +17 -6
- package/components/MessageCard/MessageCard.d.ts +1 -1
- package/components/ShaderScene/ShaderScene.css +11 -3
- package/components/ShaderScene/ShaderScene.d.ts +14 -12
- package/components/ShaderScene/ShaderScene.js +33 -10
- package/components/ShaderScene/assemble.js +2 -0
- package/components/ShaderScene/renderer.d.ts +5 -1
- package/components/ShaderScene/renderer.js +46 -1
- package/components/ShaderScene/scenes.d.ts +57 -1
- package/components/ShaderScene/scenes.js +590 -8
- package/components/ShaderScene/types.d.ts +13 -0
- package/components/ThreadPanel/ThreadPanel.css +29 -0
- package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
- package/components/ThreadPanel/ThreadPanel.js +13 -2
- package/components/registry.json +1 -1
- package/components/registry.json.d.ts +1 -1
- package/components/registry.json.js +1 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/tokens/presets/contrast.css +167 -290
- package/tokens/presets/coral.css +143 -254
- package/tokens/presets/forest.css +180 -310
- package/tokens/presets/gold.css +220 -391
- package/tokens/presets/marquee.css +150 -253
- package/tokens/presets/mono.css +162 -270
- package/tokens/presets/pink.css +228 -409
- package/tokens/presets/plum.css +228 -367
- package/tokens/presets/presets.css +1 -0
- package/tokens/presets/terminal.css +170 -301
- package/tokens/presets/violet.css +214 -380
- package/tokens/presets/warm.css +166 -293
- package/tokens/presets/zest.css +191 -335
- package/tokens/tokens-dark.css +9 -0
- package/tokens/tokens-forced-colors.css +4 -1
- package/tokens/tokens-light.css +9 -0
- package/tokens/tokens-motion.css +14 -0
- package/tokens/tokens-primitives.css +9 -0
- package/tokens/tokens-typography.css +9 -0
- package/tokens/tokens.css +12 -0
|
@@ -211,6 +211,32 @@
|
|
|
211
211
|
line-height: 1;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
+
/* A row with a description: the label over a caption line, the pair
|
|
215
|
+
stacked and the icon centred on them, the two-line row ThemePicker's
|
|
216
|
+
rows set the pattern for. */
|
|
217
|
+
.ds-dropdown-menu__item-text {
|
|
218
|
+
display: flex;
|
|
219
|
+
flex-direction: column;
|
|
220
|
+
min-width: 0;
|
|
221
|
+
text-align: start;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.ds-dropdown-menu__item-title {
|
|
225
|
+
line-height: var(--font-paragraph-sm-line-height);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.ds-dropdown-menu__item-description {
|
|
229
|
+
font-size: var(--font-caption-size);
|
|
230
|
+
font-weight: var(--font-caption-weight);
|
|
231
|
+
line-height: var(--font-caption-line-height);
|
|
232
|
+
color: var(--color-text-tertiary);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.ds-dropdown-menu__item--destructive .ds-dropdown-menu__item-description {
|
|
236
|
+
color: var(--color-action-destructive-text-secondary);
|
|
237
|
+
opacity: 0.7;
|
|
238
|
+
}
|
|
239
|
+
|
|
214
240
|
/* Figma: icons are 24px within menu items */
|
|
215
241
|
.ds-dropdown-menu__item-icon {
|
|
216
242
|
--icon-size: var(--icon-size-600);
|
|
@@ -222,6 +248,18 @@
|
|
|
222
248
|
line-height: 1;
|
|
223
249
|
}
|
|
224
250
|
|
|
251
|
+
/* A trailing icon (an external link's open_in_new): the row's quietest
|
|
252
|
+
mark, one step under the leading icon, pushed to the trailing edge. */
|
|
253
|
+
.ds-dropdown-menu__item-icon-right {
|
|
254
|
+
--icon-size: var(--icon-size-500);
|
|
255
|
+
color: var(--color-icon-secondary);
|
|
256
|
+
flex-shrink: 0;
|
|
257
|
+
display: flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
margin-inline-start: auto;
|
|
260
|
+
line-height: 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
225
263
|
/* ============================================
|
|
226
264
|
KEYBOARD SHORTCUT
|
|
227
265
|
============================================ */
|
|
@@ -4,12 +4,16 @@ export interface DropdownMenuItem {
|
|
|
4
4
|
type?: 'item';
|
|
5
5
|
/** Display label */
|
|
6
6
|
label: string;
|
|
7
|
+
/** A line under the label, such as what the choice does or means. It wraps the row to two lines in the caption style; the icon stays centred on the pair. */
|
|
8
|
+
description?: string;
|
|
7
9
|
/** Keyboard shortcut hint as literal text (e.g. "⇧ ⌘ P"). `keys` writes it for the reader's platform instead. */
|
|
8
10
|
shortcut?: string;
|
|
9
11
|
/** Keyboard shortcut hint in the shortcut grammar (`mod+shift+p`), written for the reader's platform (⇧⌘P on a Mac, Ctrl+Shift+P elsewhere) and announced through `aria-keyshortcuts`. Display only: bind the action itself with `useShortcut`. Wins over `shortcut`. */
|
|
10
12
|
keys?: Shortcut;
|
|
11
13
|
/** Item icon — Material Symbol name (string) or custom element (ReactNode) */
|
|
12
14
|
icon?: string | React.ReactNode;
|
|
15
|
+
/** A trailing icon after the label, such as `open_in_new` on an item that opens another site. Decorative: say what the item does in its label. A Material Symbol name (string) or a custom element (ReactNode). Ignored on an item that opens a sub-menu. */
|
|
16
|
+
iconRight?: string | React.ReactNode;
|
|
13
17
|
/** Disabled state */
|
|
14
18
|
disabled?: boolean;
|
|
15
19
|
/** Marks a dangerous or irreversible item (delete, remove…): it takes the destructive colour, with the error tint on hover and focus */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import React, { useState, useCallback, useRef, useId, useEffect } from "react";
|
|
4
4
|
import { ChosenMark } from "../Dropdown/Dropdown.js";
|
|
5
5
|
import { CheckboxIndicator } from "../Checkbox/Checkbox.js";
|
|
@@ -8,7 +8,7 @@ import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
|
8
8
|
import { MOTION_HOVER_HIDE_DELAY_MS } from "../../tokens/motion.js";
|
|
9
9
|
import "./DropdownMenu.css";
|
|
10
10
|
import "../../fonts/material-symbols.css";
|
|
11
|
-
import { MenuKeyLabelsContext, MenuShortcutHint } from "./ShortcutHint.js";
|
|
11
|
+
import { MenuKeyLabelsContext, MenuShortcutHint, MenuIconRight } from "./ShortcutHint.js";
|
|
12
12
|
import { shortcutAriaAnyPlatform } from "../../behaviors/shortcut-keys.js";
|
|
13
13
|
import { mirrorClass } from "../../behaviors/direction.js";
|
|
14
14
|
function collectItems(entries) {
|
|
@@ -33,6 +33,10 @@ function itemSemantics(item) {
|
|
|
33
33
|
return { role: "menuitem" };
|
|
34
34
|
}
|
|
35
35
|
const closesOnSelect = (item) => item.closeOnSelect ?? item.checked === void 0;
|
|
36
|
+
const MenuItemText = ({ baseClass, label, description }) => description ? /* @__PURE__ */ jsxs("span", { className: `${baseClass}__item-text`, children: [
|
|
37
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__item-title`, children: label }),
|
|
38
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__item-description`, children: description })
|
|
39
|
+
] }) : /* @__PURE__ */ jsx(Fragment, { children: label });
|
|
36
40
|
const ITEM_SELECTOR = '[role="menuitem"], [role="menuitemradio"], [role="menuitemcheckbox"]';
|
|
37
41
|
const SubMenuItem = ({ item, baseClass, itemId, focused, size, onActivate }) => {
|
|
38
42
|
const [subOpen, setSubOpen] = useState(false);
|
|
@@ -91,7 +95,7 @@ const SubMenuItem = ({ item, baseClass, itemId, focused, size, onActivate }) =>
|
|
|
91
95
|
children: [
|
|
92
96
|
/* @__PURE__ */ jsxs("span", { className: `${baseClass}__item-label`, children: [
|
|
93
97
|
item.icon && (typeof item.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(item.icon)}`, "aria-hidden": "true", children: item.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: item.icon })),
|
|
94
|
-
item.label
|
|
98
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: item.label, description: item.description })
|
|
95
99
|
] }),
|
|
96
100
|
/* @__PURE__ */ jsx("span", { className: `${baseClass}__submenu-icon material-symbols-rounded ds-mirror-rtl`, "aria-hidden": "true", children: "chevron_right" }),
|
|
97
101
|
subOpen && item.children && /* @__PURE__ */ jsx(
|
|
@@ -182,9 +186,10 @@ const MenuPanel = ({
|
|
|
182
186
|
}
|
|
183
187
|
),
|
|
184
188
|
entry.icon && (typeof entry.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(entry.icon)}`, "aria-hidden": "true", children: entry.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: entry.icon })),
|
|
185
|
-
entry.label
|
|
189
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: entry.label, description: entry.description })
|
|
186
190
|
] }),
|
|
187
191
|
/* @__PURE__ */ jsx(MenuShortcutHint, { item: entry, className: `${baseClass}__shortcut` }),
|
|
192
|
+
/* @__PURE__ */ jsx(MenuIconRight, { item: entry, baseClass }),
|
|
188
193
|
entry.selected && /* @__PURE__ */ jsx(ChosenMark, {})
|
|
189
194
|
]
|
|
190
195
|
},
|
|
@@ -393,9 +398,10 @@ const DropdownMenu = React.forwardRef(({
|
|
|
393
398
|
}
|
|
394
399
|
),
|
|
395
400
|
entry.icon && (typeof entry.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(entry.icon)}`, "aria-hidden": "true", children: entry.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: entry.icon })),
|
|
396
|
-
entry.label
|
|
401
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: entry.label, description: entry.description })
|
|
397
402
|
] }),
|
|
398
403
|
/* @__PURE__ */ jsx(MenuShortcutHint, { item: entry, className: `${baseClass}__shortcut` }),
|
|
404
|
+
/* @__PURE__ */ jsx(MenuIconRight, { item: entry, baseClass }),
|
|
399
405
|
entry.selected && /* @__PURE__ */ jsx(ChosenMark, {})
|
|
400
406
|
]
|
|
401
407
|
},
|
|
@@ -10,3 +10,12 @@ export declare function MenuShortcutHint({ item, className }: {
|
|
|
10
10
|
item: DropdownMenuItem;
|
|
11
11
|
className: string;
|
|
12
12
|
}): import("react").JSX.Element | null;
|
|
13
|
+
/**
|
|
14
|
+
* A menu row's trailing icon (`iconRight`), after the label and any
|
|
15
|
+
* shortcut hint, shared by DropdownMenu and ContextMenu. Decorative: the
|
|
16
|
+
* label says what the item does.
|
|
17
|
+
*/
|
|
18
|
+
export declare function MenuIconRight({ item, baseClass }: {
|
|
19
|
+
item: DropdownMenuItem;
|
|
20
|
+
baseClass: string;
|
|
21
|
+
}): import("react").JSX.Element | null;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { usePlatform } from "../../behaviors/shortcuts.js";
|
|
5
|
+
import { mirrorClass } from "../../behaviors/direction.js";
|
|
5
6
|
import { formatShortcut } from "../../behaviors/shortcut-keys.js";
|
|
6
7
|
const MenuKeyLabelsContext = createContext(void 0);
|
|
7
8
|
function MenuShortcutHint({ item, className }) {
|
|
@@ -11,7 +12,12 @@ function MenuShortcutHint({ item, className }) {
|
|
|
11
12
|
if (item.shortcut) return /* @__PURE__ */ jsx("span", { className, children: item.shortcut });
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
15
|
+
function MenuIconRight({ item, baseClass }) {
|
|
16
|
+
if (!item.iconRight) return null;
|
|
17
|
+
return typeof item.iconRight === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon-right material-symbols-rounded ${mirrorClass(item.iconRight)}`, "aria-hidden": "true", children: item.iconRight }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon-right`, "aria-hidden": "true", children: item.iconRight });
|
|
18
|
+
}
|
|
14
19
|
export {
|
|
20
|
+
MenuIconRight,
|
|
15
21
|
MenuKeyLabelsContext,
|
|
16
22
|
MenuShortcutHint
|
|
17
23
|
};
|
|
@@ -37,7 +37,7 @@ type InterruptCardOwnProps = {
|
|
|
37
37
|
title: string;
|
|
38
38
|
/** One line of context under the title. */
|
|
39
39
|
description?: string;
|
|
40
|
-
/**
|
|
40
|
+
/** A Material Symbol name trailing the title, or any custom element. No icon by default. */
|
|
41
41
|
icon?: string | React.ReactNode;
|
|
42
42
|
/** The choices, rendered as buttons left to right. */
|
|
43
43
|
options?: InterruptCardOption[];
|
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/* The link grid:
|
|
51
|
-
|
|
50
|
+
/* The link grid: columns of at least four rows. MegaMenu.tsx sets the row
|
|
51
|
+
count, deepening every column before it adds one (three columns at most
|
|
52
|
+
beside a showcase, four without), so a long menu grows downward first
|
|
53
|
+
and never leaves a column holding one stray row. */
|
|
52
54
|
.ds-mega-menu__grid {
|
|
53
55
|
display: grid;
|
|
54
|
-
grid-template-rows: repeat(4, auto);
|
|
56
|
+
grid-template-rows: repeat(var(--ds-mega-menu-rows, 4), auto);
|
|
55
57
|
grid-auto-flow: column;
|
|
56
58
|
grid-auto-columns: minmax(0, 1fr);
|
|
57
59
|
gap: var(--gap-200) var(--gap-1000);
|
|
@@ -37,7 +37,10 @@ type MegaMenuOwnProps = {
|
|
|
37
37
|
* out and is `inert`, so its links leave the tab order.
|
|
38
38
|
*/
|
|
39
39
|
open: boolean;
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* The link rows, in columns of at least four. A column grows taller before
|
|
42
|
+
* the grid adds one, up to three columns beside a showcase and four without.
|
|
43
|
+
*/
|
|
41
44
|
items: MegaMenuItem[];
|
|
42
45
|
/** A featured card in its own column beside the link grid. */
|
|
43
46
|
showcase?: MegaMenuShowcase;
|
|
@@ -4,6 +4,9 @@ import { mirrorClass } from "../../behaviors/direction.js";
|
|
|
4
4
|
import "./MegaMenu.css";
|
|
5
5
|
import "../../fonts/material-symbols.css";
|
|
6
6
|
import "../../behaviors/direction.css";
|
|
7
|
+
const MIN_ROWS = 4;
|
|
8
|
+
const MAX_COLUMNS_WITH_SHOWCASE = 3;
|
|
9
|
+
const MAX_COLUMNS = 4;
|
|
7
10
|
const isCurrent = (href, currentHref) => currentHref != null && (currentHref === href || currentHref.startsWith(`${href}/`));
|
|
8
11
|
function MegaMenu({
|
|
9
12
|
open,
|
|
@@ -19,31 +22,42 @@ function MegaMenu({
|
|
|
19
22
|
const Link = linkComponent ?? "a";
|
|
20
23
|
const baseClass = "ds-mega-menu";
|
|
21
24
|
const classes = [baseClass, open && `${baseClass}--open`, className].filter(Boolean).join(" ");
|
|
25
|
+
const rows = Math.max(
|
|
26
|
+
MIN_ROWS,
|
|
27
|
+
Math.ceil(items.length / (showcase ? MAX_COLUMNS_WITH_SHOWCASE : MAX_COLUMNS))
|
|
28
|
+
);
|
|
22
29
|
return /* @__PURE__ */ jsx("div", { ...rest, ref, className: classes, inert: !open, children: /* @__PURE__ */ jsxs(
|
|
23
30
|
"div",
|
|
24
31
|
{
|
|
25
32
|
className: [`${baseClass}__layout`, showcase && `${baseClass}__layout--showcase`].filter(Boolean).join(" "),
|
|
26
33
|
children: [
|
|
27
|
-
/* @__PURE__ */ jsx(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
/* @__PURE__ */ jsx(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
className: `${baseClass}__grid`,
|
|
38
|
+
style: { "--ds-mega-menu-rows": rows },
|
|
39
|
+
children: items.map((item) => {
|
|
40
|
+
const current = isCurrent(item.href, currentHref);
|
|
41
|
+
return /* @__PURE__ */ jsxs(
|
|
42
|
+
Link,
|
|
43
|
+
{
|
|
44
|
+
href: item.href,
|
|
45
|
+
className: [`${baseClass}__item`, current && `${baseClass}__item--current`].filter(Boolean).join(" "),
|
|
46
|
+
"aria-current": current ? "page" : void 0,
|
|
47
|
+
onClick: onNavigate,
|
|
48
|
+
children: [
|
|
49
|
+
(item.logo || item.icon) && /* @__PURE__ */ jsx("span", { className: `${baseClass}__icon`, "aria-hidden": "true", children: item.logo ? /* @__PURE__ */ jsx("img", { className: `${baseClass}__logo`, src: item.logo, alt: "" }) : /* @__PURE__ */ jsx("span", { className: `material-symbols-rounded ${mirrorClass(item.icon)}`, children: item.icon }) }),
|
|
50
|
+
/* @__PURE__ */ jsxs("span", { className: `${baseClass}__text`, children: [
|
|
51
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__label`, children: item.label }),
|
|
52
|
+
item.description && /* @__PURE__ */ jsx("span", { className: `${baseClass}__description`, children: item.description })
|
|
53
|
+
] })
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
item.href
|
|
57
|
+
);
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
),
|
|
47
61
|
showcase && /* @__PURE__ */ jsx("div", { className: `${baseClass}__showcase-column`, children: /* @__PURE__ */ jsxs(Link, { href: showcase.href, className: `${baseClass}__showcase`, onClick: onNavigate, children: [
|
|
48
62
|
showcase.cover && /* @__PURE__ */ jsx("span", { className: `${baseClass}__cover`, children: showcase.cover }),
|
|
49
63
|
/* @__PURE__ */ jsxs("span", { className: `${baseClass}__showcase-text`, children: [
|
|
@@ -36,21 +36,32 @@
|
|
|
36
36
|
margin: var(--padding-300) var(--padding-300) 0;
|
|
37
37
|
border-radius: var(--radius-300);
|
|
38
38
|
overflow: hidden;
|
|
39
|
-
/* The slot carries its own surface, so drawn media —
|
|
40
|
-
reads as the same image-shaped panel a photo would:
|
|
41
|
-
the card's crisp fill, so it shows as a slot in both
|
|
39
|
+
/* The slot carries its own surface, so drawn media — an SVG, an
|
|
40
|
+
illustration — reads as the same image-shaped panel a photo would: a
|
|
41
|
+
step in from the card's crisp fill, so it shows as a slot in both
|
|
42
|
+
themes. */
|
|
42
43
|
background-color: var(--color-bg-container-secondary);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/* A chart's slot takes the primary container tone instead. The secondary
|
|
47
|
+
tone is the second elevation, a mid grey in dark mode (three steps
|
|
48
|
+
lighter than the card), and a plot drawn straight on it read as a grey
|
|
49
|
+
block with its fill washed out. The primary tone is the surface every
|
|
50
|
+
chart stands on elsewhere (its own panel's fill), a step in from the card
|
|
51
|
+
and nothing like a block. */
|
|
52
|
+
.ds-message-card__media:has(.ds-chart) {
|
|
53
|
+
background-color: var(--color-bg-container-primary);
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
.ds-message-card__media img {
|
|
46
57
|
display: block;
|
|
47
58
|
width: 100%;
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
/* A Chart in the slot sheds its own panel chrome — the card is already the
|
|
51
|
-
panel, and the slot
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
panel, and the slot above gives it the same primary container tone its
|
|
63
|
+
own panel would, so the drawing sits on one surface, not a panel inside a
|
|
64
|
+
slot. */
|
|
54
65
|
.ds-message-card__media .ds-chart {
|
|
55
66
|
background-color: transparent;
|
|
56
67
|
border: none;
|
|
@@ -10,7 +10,7 @@ type MessageCardOwnProps = {
|
|
|
10
10
|
description?: string;
|
|
11
11
|
/** Top media slot — an image or chart, inset from the card edges with its own rounded corners. */
|
|
12
12
|
media?: React.ReactNode;
|
|
13
|
-
/** Small
|
|
13
|
+
/** Small icon trailing the title at the row's end — a Material Symbol name, or any custom element. */
|
|
14
14
|
icon?: string | React.ReactNode;
|
|
15
15
|
/** Free-text metadata line, e.g. a domain or date, so callers keep their own formatting. */
|
|
16
16
|
meta?: string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* ShaderScene: the canvas, filling its positioned ancestor.
|
|
2
2
|
Placement and clipping belong to that ancestor, as with ShaderField: where
|
|
3
|
-
a scene sits is a layout decision.
|
|
4
|
-
page's, so a machine that cannot run WebGL2 shows the plain page. */
|
|
3
|
+
a scene sits is a layout decision. */
|
|
5
4
|
|
|
6
5
|
.ds-shader-scene {
|
|
7
6
|
position: absolute;
|
|
@@ -9,7 +8,16 @@
|
|
|
9
8
|
overflow: hidden;
|
|
10
9
|
/* Scenery, never a target. */
|
|
11
10
|
pointer-events: none;
|
|
12
|
-
|
|
11
|
+
/* Paints nothing until a context is live and the first frame is drawn,
|
|
12
|
+
as ShaderField does, so whatever the caller lays under it (the page,
|
|
13
|
+
or a fallback of its own) shows while it is pending, disabled or where
|
|
14
|
+
WebGL2 cannot run. Once active the canvas is opaque. */
|
|
15
|
+
opacity: 0;
|
|
16
|
+
transition: opacity var(--motion-duration-slower) var(--motion-ease-entrance);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ds-shader-scene[data-status='active'] {
|
|
20
|
+
opacity: 1;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
.ds-shader-scene__canvas {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Values } from './types';
|
|
3
3
|
/** The scenes ShaderScene paints. */
|
|
4
|
-
export type ShaderSceneId = 'horizon' | 'rift';
|
|
4
|
+
export type ShaderSceneId = 'horizon' | 'rift' | 'glyphs' | 'prism' | 'meteors' | 'waves' | 'aurora';
|
|
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,7 +18,7 @@ export type ShaderScenePassSetting = {
|
|
|
18
18
|
};
|
|
19
19
|
/** Props owned by ShaderScene itself; everything else falls through to the root. */
|
|
20
20
|
type ShaderSceneOwnProps = {
|
|
21
|
-
/** The scene to paint: `horizon`, a planet's limb at night,
|
|
21
|
+
/** The scene to paint: `horizon`, a planet's limb at night, `rift`, a glowing tear, `glyphs`, soft light printed in type, `prism`, beams of light split into a spectrum, `meteors`, a shower over a planet's edge, `waves`, a rolling sea of points, or `aurora`, ribbons of colour round a void. */
|
|
22
22
|
scene?: ShaderSceneId;
|
|
23
23
|
/**
|
|
24
24
|
* The scene's settings, merged over its defaults (`SHADER_SCENES` lists each
|
|
@@ -40,14 +40,15 @@ type ShaderSceneOwnProps = {
|
|
|
40
40
|
*/
|
|
41
41
|
liveRef?: React.RefObject<Values | null>;
|
|
42
42
|
/**
|
|
43
|
-
* False never starts WebGL and reports `unavailable`,
|
|
44
|
-
*
|
|
43
|
+
* False never starts WebGL and reports `unavailable`, painting nothing:
|
|
44
|
+
* the kill switch, as on ShaderField.
|
|
45
45
|
*/
|
|
46
46
|
enabled?: boolean;
|
|
47
47
|
/**
|
|
48
|
-
* Called whenever the status changes. Drive a fallback from this
|
|
49
|
-
*
|
|
50
|
-
* is the caller's design
|
|
48
|
+
* Called whenever the status changes. Drive a fallback from this, or lay
|
|
49
|
+
* one under the scene: it paints nothing until it is `active`, so what
|
|
50
|
+
* shows while it is pending or cannot run is the caller's design
|
|
51
|
+
* decision.
|
|
51
52
|
*/
|
|
52
53
|
onStatusChange?: (status: ShaderSceneStatus) => void;
|
|
53
54
|
/** Additional CSS classes */
|
|
@@ -56,14 +57,14 @@ type ShaderSceneOwnProps = {
|
|
|
56
57
|
export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof ShaderSceneOwnProps> {
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
|
-
* ShaderScene paints one of the system's shader scenes, a horizon
|
|
60
|
-
* in WebGL2, with finishing passes over it (a scrim, a vignette, top and
|
|
60
|
+
* ShaderScene paints one of the system's shader scenes, a horizon, a rift,
|
|
61
|
+
* a field of glyphs, a prism, a meteor shower, a sea of points or an aurora, in WebGL2, with finishing passes over it (a scrim, a vignette, top and
|
|
61
62
|
* bottom fades to the page, film grain). Its colours are the background
|
|
62
63
|
* field's roles (`--color-ambient-*`) read from the live cascade at the
|
|
63
64
|
* scene, so it re-themes with `data-theme`, a preset or any scoped override,
|
|
64
65
|
* and its fades melt into the page ground.
|
|
65
66
|
*
|
|
66
|
-
*
|
|
67
|
+
* Every scene is a night scene: it adds light over a dark ground. On a light
|
|
67
68
|
* page each computes its light against a dark ground of its own and lays it
|
|
68
69
|
* onto the page as a pale tint, so it reads as a soft dawn rather than a dark
|
|
69
70
|
* block. Nothing here sets `data-theme`, which would hide a preset's colours.
|
|
@@ -71,8 +72,9 @@ export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.Compon
|
|
|
71
72
|
* It is scenery, not interface. It fills its positioned ancestor and is inert
|
|
72
73
|
* to pointer events and to assistive tech; give the ancestor the placement and
|
|
73
74
|
* the clipping. It honours reduced motion in JavaScript, holding a still frame
|
|
74
|
-
* that still answers its settings
|
|
75
|
-
* WebGL2 is unavailable
|
|
75
|
+
* that still answers its settings. Like ShaderField it paints nothing until
|
|
76
|
+
* its first frame is drawn, then fades in, so where WebGL2 is unavailable
|
|
77
|
+
* whatever lies under it (the page, or a fallback of the caller's) shows.
|
|
76
78
|
*/
|
|
77
79
|
export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
|
|
78
80
|
export type { ParamSpec as ShaderSceneParamSpec, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
|
|
@@ -3,11 +3,13 @@ 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 { createRenderer, coloursFor } from "./renderer.js";
|
|
6
|
+
import { createRenderer, glyphFontFor, coloursFor } from "./renderer.js";
|
|
7
7
|
import { bakeThumbnails } from "./renderer.js";
|
|
8
8
|
import { SCENES } from "./scenes.js";
|
|
9
9
|
import { defaultsFor } from "./types.js";
|
|
10
10
|
import "./ShaderScene.css";
|
|
11
|
+
const MAX_PIXEL_RATIO = 1;
|
|
12
|
+
const FRAME_MS = 1e3 / 30;
|
|
11
13
|
const DEFAULT_SPEED = 1.6;
|
|
12
14
|
function ShaderScene({
|
|
13
15
|
scene = "horizon",
|
|
@@ -77,11 +79,18 @@ function ShaderScene({
|
|
|
77
79
|
const failed = requestAnimationFrame(() => setGl("failed"));
|
|
78
80
|
return () => cancelAnimationFrame(failed);
|
|
79
81
|
}
|
|
80
|
-
const applyColours = () =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const applyColours = () => {
|
|
83
|
+
renderer.setColours(coloursFor(host, definition));
|
|
84
|
+
renderer.setGlyphs(glyphFontFor(host));
|
|
85
|
+
};
|
|
86
|
+
let ratio = 1;
|
|
87
|
+
const fit = () => {
|
|
88
|
+
ratio = Math.min(definition.pixelRatio ?? MAX_PIXEL_RATIO, window.devicePixelRatio || 1);
|
|
89
|
+
const width = Math.max(1, Math.round(host.clientWidth * ratio));
|
|
90
|
+
const height = Math.max(1, Math.round(host.clientHeight * ratio));
|
|
91
|
+
if (canvas.width === width && canvas.height === height) return;
|
|
92
|
+
canvas.width = width;
|
|
93
|
+
canvas.height = height;
|
|
85
94
|
};
|
|
86
95
|
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
87
96
|
let time = 20;
|
|
@@ -89,16 +98,18 @@ function ShaderScene({
|
|
|
89
98
|
let frame = 0;
|
|
90
99
|
let painted = false;
|
|
91
100
|
const draw = (now) => {
|
|
101
|
+
frame = requestAnimationFrame(draw);
|
|
102
|
+
if (painted && now - last < FRAME_MS - 1) return;
|
|
92
103
|
const values = liveRef?.current ?? mergedRef.current;
|
|
93
104
|
const dt = Math.min(0.1, (now - last) / 1e3);
|
|
94
105
|
last = now;
|
|
95
106
|
if (!still) time += dt * values.speed;
|
|
96
|
-
|
|
107
|
+
fit();
|
|
108
|
+
renderer.draw(values, time, canvas.width, canvas.height, ratio);
|
|
97
109
|
if (!painted) {
|
|
98
110
|
painted = true;
|
|
99
111
|
setGl("painted");
|
|
100
112
|
}
|
|
101
|
-
frame = requestAnimationFrame(draw);
|
|
102
113
|
};
|
|
103
114
|
const start = () => {
|
|
104
115
|
if (frame) return;
|
|
@@ -110,14 +121,25 @@ function ShaderScene({
|
|
|
110
121
|
frame = 0;
|
|
111
122
|
};
|
|
112
123
|
applyColours();
|
|
113
|
-
resize();
|
|
114
124
|
start();
|
|
125
|
+
let mounted = true;
|
|
126
|
+
if (definition.glyphs) {
|
|
127
|
+
document.fonts?.ready.then(() => {
|
|
128
|
+
if (!mounted) return;
|
|
129
|
+
renderer.setGlyphs("");
|
|
130
|
+
renderer.setGlyphs(glyphFontFor(host));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
115
133
|
const visibilityObserver = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver(
|
|
116
134
|
(entries) => entries[entries.length - 1].isIntersecting ? start() : stop(),
|
|
117
135
|
{ rootMargin: "200px 0px" }
|
|
118
136
|
);
|
|
119
137
|
visibilityObserver?.observe(host);
|
|
120
|
-
const sizeObserver = new ResizeObserver(
|
|
138
|
+
const sizeObserver = new ResizeObserver(() => {
|
|
139
|
+
if (frame) return;
|
|
140
|
+
fit();
|
|
141
|
+
renderer.draw(liveRef?.current ?? mergedRef.current, time, canvas.width, canvas.height, ratio);
|
|
142
|
+
});
|
|
121
143
|
sizeObserver.observe(host);
|
|
122
144
|
const themeObserver = new MutationObserver(applyColours);
|
|
123
145
|
themeObserver.observe(document.documentElement, {
|
|
@@ -125,6 +147,7 @@ function ShaderScene({
|
|
|
125
147
|
attributeFilter: ["data-theme", "data-brand", "style"]
|
|
126
148
|
});
|
|
127
149
|
return () => {
|
|
150
|
+
mounted = false;
|
|
128
151
|
stop();
|
|
129
152
|
visibilityObserver?.disconnect();
|
|
130
153
|
sizeObserver.disconnect();
|
|
@@ -31,7 +31,9 @@ uniform float u_time;
|
|
|
31
31
|
uniform vec3 u_ground; // the scene's ground: the page's, or a night scene's own
|
|
32
32
|
uniform vec3 u_page; // the page's ground, which the passes fade to
|
|
33
33
|
uniform float u_lightMode; // 1: a night scene laid onto a light page
|
|
34
|
+
uniform float u_ratio; // drawing-buffer pixels per CSS pixel
|
|
34
35
|
uniform vec3 u_col[${MAX_COLOURS}];
|
|
36
|
+
${scene.glyphs ? "uniform sampler2D u_glyphs;\nuniform float u_glyphCount;" : ""}
|
|
35
37
|
${floats}
|
|
36
38
|
|
|
37
39
|
out vec4 outColor;
|
|
@@ -19,9 +19,13 @@ export declare function readColours(host: HTMLElement, tokens: string[]): Colour
|
|
|
19
19
|
* light.
|
|
20
20
|
*/
|
|
21
21
|
export declare function coloursFor(host: HTMLElement, scene: Scene): Colours;
|
|
22
|
+
/** The face a scene's type is drawn in: the theme's code face at `host`. */
|
|
23
|
+
export declare function glyphFontFor(host: HTMLElement): string;
|
|
22
24
|
export declare function createRenderer(gl: WebGL2RenderingContext, scene: Scene, passes: Pass[]): {
|
|
23
25
|
setColours({ ground, page, lightMode, colours }: Colours): void;
|
|
24
|
-
|
|
26
|
+
/** Draws a type scene's ramp in `font`; a scene without one ignores it. */
|
|
27
|
+
setGlyphs(font: string): void;
|
|
28
|
+
draw(values: Values, time: number, width: number, height: number, ratio?: number): void;
|
|
25
29
|
dispose(): void;
|
|
26
30
|
} | null;
|
|
27
31
|
/**
|
|
@@ -33,6 +33,28 @@ function coloursFor(host, scene) {
|
|
|
33
33
|
}
|
|
34
34
|
return colours;
|
|
35
35
|
}
|
|
36
|
+
function glyphFontFor(host) {
|
|
37
|
+
return getComputedStyle(host).getPropertyValue("--font-family-code").trim() || "monospace";
|
|
38
|
+
}
|
|
39
|
+
const GLYPH_W = 48;
|
|
40
|
+
const GLYPH_H = 80;
|
|
41
|
+
function drawGlyphs(ramp, font) {
|
|
42
|
+
const glyphs = [...ramp];
|
|
43
|
+
const strip = document.createElement("canvas");
|
|
44
|
+
strip.width = GLYPH_W * glyphs.length;
|
|
45
|
+
strip.height = GLYPH_H;
|
|
46
|
+
const ctx = strip.getContext("2d");
|
|
47
|
+
if (ctx) {
|
|
48
|
+
ctx.fillStyle = "#000";
|
|
49
|
+
ctx.fillRect(0, 0, strip.width, strip.height);
|
|
50
|
+
ctx.fillStyle = "#fff";
|
|
51
|
+
ctx.font = `700 ${GLYPH_H * 0.78}px ${font}`;
|
|
52
|
+
ctx.textAlign = "center";
|
|
53
|
+
ctx.textBaseline = "middle";
|
|
54
|
+
glyphs.forEach((glyph, i) => ctx.fillText(glyph, (i + 0.5) * GLYPH_W, GLYPH_H * 0.52));
|
|
55
|
+
}
|
|
56
|
+
return { strip, count: glyphs.length };
|
|
57
|
+
}
|
|
36
58
|
function compile(gl, type, source) {
|
|
37
59
|
const shader = gl.createShader(type);
|
|
38
60
|
if (!shader) return null;
|
|
@@ -74,7 +96,11 @@ function createRenderer(gl, scene, passes) {
|
|
|
74
96
|
const uPage = at("u_page");
|
|
75
97
|
const uLightMode = at("u_lightMode");
|
|
76
98
|
const uCols = at("u_col");
|
|
99
|
+
const uRatio = at("u_ratio");
|
|
100
|
+
const uGlyphCount = at("u_glyphCount");
|
|
77
101
|
const floats = uniformNames(scene, passes).map((name) => [name, at(name)]);
|
|
102
|
+
const glyphTexture = scene.glyphs ? gl.createTexture() : null;
|
|
103
|
+
let glyphFont = "";
|
|
78
104
|
return {
|
|
79
105
|
setColours({ ground, page, lightMode, colours }) {
|
|
80
106
|
gl.uniform3fv(uGround, ground);
|
|
@@ -84,14 +110,31 @@ function createRenderer(gl, scene, passes) {
|
|
|
84
110
|
colours.forEach((rgb, i) => flat.set(rgb, i * 3));
|
|
85
111
|
gl.uniform3fv(uCols, flat);
|
|
86
112
|
},
|
|
87
|
-
|
|
113
|
+
/** Draws a type scene's ramp in `font`; a scene without one ignores it. */
|
|
114
|
+
setGlyphs(font) {
|
|
115
|
+
if (!scene.glyphs || !glyphTexture || font === glyphFont) return;
|
|
116
|
+
glyphFont = font;
|
|
117
|
+
const { strip, count } = drawGlyphs(scene.glyphs, font);
|
|
118
|
+
gl.bindTexture(gl.TEXTURE_2D, glyphTexture);
|
|
119
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
120
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, strip);
|
|
121
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
122
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
123
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
124
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
125
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
126
|
+
gl.uniform1f(uGlyphCount, count);
|
|
127
|
+
},
|
|
128
|
+
draw(values, time, width, height, ratio = 1) {
|
|
88
129
|
gl.viewport(0, 0, width, height);
|
|
89
130
|
gl.uniform2f(uSize, width, height);
|
|
131
|
+
gl.uniform1f(uRatio, ratio);
|
|
90
132
|
gl.uniform1f(uTime, time);
|
|
91
133
|
for (const [name, location] of floats) gl.uniform1f(location, valueOf(values, passes, name));
|
|
92
134
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
93
135
|
},
|
|
94
136
|
dispose() {
|
|
137
|
+
gl.deleteTexture(glyphTexture);
|
|
95
138
|
gl.deleteVertexArray(vao);
|
|
96
139
|
gl.deleteProgram(program);
|
|
97
140
|
gl.deleteShader(vs);
|
|
@@ -109,6 +152,7 @@ function bakeThumbnails(host, jobs, passes, width, height) {
|
|
|
109
152
|
const renderer = createRenderer(gl, scene, passes);
|
|
110
153
|
if (!renderer) return "";
|
|
111
154
|
renderer.setColours(coloursFor(host, scene));
|
|
155
|
+
renderer.setGlyphs(glyphFontFor(host));
|
|
112
156
|
renderer.draw(values, 20, width, height);
|
|
113
157
|
const url = canvas.toDataURL("image/jpeg", 0.85);
|
|
114
158
|
renderer.dispose();
|
|
@@ -121,5 +165,6 @@ export {
|
|
|
121
165
|
bakeThumbnails,
|
|
122
166
|
coloursFor,
|
|
123
167
|
createRenderer,
|
|
168
|
+
glyphFontFor,
|
|
124
169
|
readColours
|
|
125
170
|
};
|