// An app's look, as its .json gives it: a palette for light and // one for dark, each in place.hud.defs#palette's fields as HUD's themes // (themes/*.json) name them, and its fonts. Each palette colour is written // on the root, in the page's as the server sends it, as the // renderer's variable it is drawn as (the MCP Apps host variables of // @hud/renderer/theme.css, mapped as web/workspace/app.css maps HUD's // tokens to them), a `light-dark()` of the two, so the page follows the // system's scheme as the app does; signed in, the account's own choice of // scheme (`Scheme`, Grain's theme preference), where it makes one, forces // light or dark on the root's `color-scheme`. The app's server keeps that // choice (Grain's in a cookie) as it reads it (`frameData`), so a page is // drawn in it from its first paint. import type { Call } from '@hud/shared/result'; import { at } from './app'; /** The colours of one scheme, as HUD's palettes name them. */ export type Palette = { canvas: string; background: string; panel: string; soft: string; border: string; borderStrong: string; text: string; textMuted: string; textFaint: string; primary: string; onPrimary: string; accent: string; accentSoft: string; danger: string; notice: string; onNotice: string; }; export type Look = { light: Palette; dark: Palette; /** A stylesheet that loads them, the body's font and the display font titles take. */ fonts?: { href: string; sans: string; display: string }; }; /** Each renderer variable, by the palette colour it is drawn in. */ const VARIABLES: Record = { '--color-background-primary': 'background', '--color-background-secondary': 'soft', '--color-background-tertiary': 'border', '--color-background-inverse': 'text', '--color-background-info': 'accentSoft', '--color-background-danger': 'soft', '--color-background-warning': 'notice', '--color-text-primary': 'text', '--color-text-secondary': 'textMuted', '--color-text-tertiary': 'textFaint', '--color-text-inverse': 'background', '--color-text-info': 'accent', '--color-text-danger': 'danger', '--color-text-warning': 'onNotice', '--color-border-primary': 'borderStrong', '--color-border-secondary': 'border', '--color-border-danger': 'danger', '--color-ring-primary': 'primary', '--color-background-action': 'primary', '--color-text-on-action': 'onPrimary', '--app-canvas': 'canvas', '--app-panel': 'panel', '--app-primary': 'primary', '--app-on-primary': 'onPrimary', '--app-accent': 'accent', '--app-accent-soft': 'accentSoft' }; /** The stylesheet that draws the page in `look`: its variables on the root. */ export function lookCss(look: Look): string { const values = Object.entries(VARIABLES).map(([variable, field]) => `${variable}:light-dark(${look.light[field]},${look.dark[field]})`); if (look.fonts) values.push(`--font-sans:${look.fonts.sans}`, `--app-font-display:${look.fonts.display}`); // The app's own file, but a stylesheet all the same: nothing in it ends the