Files
gerbeur/shared/theme.ts
khannurien fd0d81fe66 v4: the emails' words live in the catalogs alone and their look is read from the site's stylesheets — every email message was written as i18n._({ id, message }), so its English sat in the template and again in en.po, and api/mail/styles.ts held a copy of each theme's palette, fonts and radii that a test chased. The templates now name each message by its id only (i18n._("email.reset.title", values)) and its English is written in locales/en.po, its French in fr.po; the four labels the settings tab and the unsubscribe page share with the emails read the same ids through @lingui/react's Trans instead of restating the English. i18n:extract runs without --overwrite, which would write the id where the English is, and i18n:compile runs --strict, so a language lacking a message fails the build; it caught email.digest.hl.mentionIn, never translated into French. The new api/mail/theme-tokens.ts reads src/tokens.css and src/themes/<style>.css and resolves a token for one scheme (var(), light-dark(), color-mix(), translucent colors laid over the card), and styles.ts names tokens for every color, GeoCities' rainbow, Melange's spice and shadow, Kanagawa's syntax hues, the font stack and the corner radii, keeping only what is the email's own (type scale, title, frame, divider, avatar rounding). The copies had drifted: GeoCities' stack had lost Marker Felt and its light emails drew the dark rainbow, which now also recolors its dividers on the "auto" scheme. The pills take the site's badge color, now the --color-badge-bg token that the private badge reads too. The Dockerfile copies src/tokens.css and src/themes/ into the runtime image, which reads them at load. The catalogs were re-extracted, having been stale against the code. 240 backend tests (new: the token reader, the dark rainbow; the palette-copy test is gone) and 661 frontend tests pass, and tsc, deno check and doc:lint are clean; sendDueDigests' empty-digest test fails now and then, as it did before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:21:45 +00:00

53 lines
1.8 KiB
TypeScript

/**
* The site's look is a style and a color scheme, which the client applies and
* the emails render in. This module names them for both halves: the client's
* `ThemeProvider` checks a stored choice against them, and the server checks
* `GERBEUR_DEFAULT_STYLE` and picks an email's palette by them.
*
* @module
*/
/**
* Lists every site style. Each has a stylesheet under `src/themes/`, keyed on
* the root element's `data-style`, and an email style in `api/mail/styles.ts`
* read from that stylesheet.
*/
export const STYLE_NAMES = [
"smooth",
"brutalist",
"geocities",
"nyt",
"kanagawa",
"melange",
] as const;
/** One of the {@link STYLE_NAMES}. */
export type StyleName = typeof STYLE_NAMES[number];
/**
* The style the stylesheets draw when the root element has no `data-style`,
* and the one an unset or unknown `GERBEUR_DEFAULT_STYLE` means.
*/
export const BASE_STYLE: StyleName = "smooth";
/** Lists every color scheme. "auto" follows the system's. */
export const COLOR_SCHEMES = ["auto", "light", "dark"] as const;
/** One of the {@link COLOR_SCHEMES}. */
export type ColorScheme = typeof COLOR_SCHEMES[number];
/** The scheme of whoever hasn't picked one: the system's. */
export const DEFAULT_COLOR_SCHEME: ColorScheme = "auto";
/**
* Checks whether `value` is a {@link StyleName}, as a stored choice or an
* environment variable must be before it is applied.
*/
export function isStyleName(value: unknown): value is StyleName {
return typeof value === "string" &&
(STYLE_NAMES as readonly string[]).includes(value);
}
/** Checks whether `value` is a {@link ColorScheme}. */
export function isColorScheme(value: unknown): value is ColorScheme {
return typeof value === "string" &&
(COLOR_SCHEMES as readonly string[]).includes(value);
}