Sub-project 1 of the redesign. The diagnosis that shaped it: a design system already existed and was never wired up. src/index.css defined --paper, --ink and a muted teal with a contract document behind them, while the app painted itself with shadcn's default white and near-black. Those tokens reached the screen in exactly two places — the carry meter and the +/- number colours. TOKENS. Two layers: --budget-* is the app's own vocabulary, defined once per theme, and shadcn's whole variable set points at it, so every primitive inherits both themes rather than being fought. Light is cool paper with ink navy; dark is deep slate, never pure black, because a black ground makes the hairlines and the carry meter float. The brand teal is --primary, NOT --accent. That is precisely what the old bug got wrong: shadcn's --accent is a subtle hover BACKGROUND paired with --accent-foreground, so a saturated colour there turns every hover into a coloured slab with unreadable text. src/cssPairs.test.ts now makes the rule mechanical — redefining either half of a shadcn pair without the other fails the build, in any block. CONTRAST was computed, not eyeballed: the weakest text pair is 5.50:1 against a 4.5:1 requirement, and field borders clear the 3:1 non-text requirement on both of their backgrounds. Verified afterwards by reading the tokens back out of the live browser in both themes rather than trusting the arithmetic. TYPE. Inter and JetBrains Mono, self-hosted (SIL OFL, licences committed alongside), latin + latin-ext only. Not in index.css: Bun's CSS bundler resolves every url() from disk and inlines woff2 as base64 — relative or absolute, and a "file" loader override does not stop it — which made the stylesheet 303 KB of render-blocking bytes and defeated the unicode-range subsetting entirely. They are injected at boot from one definition instead, which is the only arrangement identical in dev and in a subpath build. THEME TOGGLE cycles system / light / dark, remembers the choice in localStorage (a per-device display preference does not belong in the exported budget), keeps following the OS while set to "system", and is applied by a tiny inline script before first paint so a dark-theme user never sees a white flash. Every storage access is wrapped: localStorage throws outright in some configurations, and a theme preference must never stop the app booting. A REGRESSION I CAUSED AND CAUGHT: renaming --rule to --budget-rule silently killed the carry meter. An undefined custom property inside linear-gradient() does not warn, does not throw and does not fall back — the declaration is invalid, so the element paints nothing. It looked like a missing feature. Only pixel-sampling a screenshot found it. src/ui/cssTokens.test.ts now fails if any TypeScript file references a token src/index.css does not define. Also: one Section/Stat card treatment applied across month, year, summary and settings; quiet uppercase table headers; row hover; the rule-editing and purchase-row actions revealed on hover instead of six always-on links; a scroll fade on the year matrix so it reads as "more to come" rather than clipped; and "September 2026" instead of "2026-09" as the month heading. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
/**
|
|
* Downloads the self-hosted webfonts into src/fonts/.
|
|
*
|
|
* bun scripts/fetch-fonts.ts
|
|
*
|
|
* Self-hosted, not linked from a CDN, because PRODUCT.md's position is that the
|
|
* app works offline and needs no third party: a font request to another origin
|
|
* on every cold load contradicts that, and would leak the fact that the app was
|
|
* opened. The files are COMMITTED so neither the build nor a fresh checkout
|
|
* needs network.
|
|
*
|
|
* Only the `latin` and `latin-ext` subsets are taken. Danish needs æ, ø and å
|
|
* (U+00E6, U+00F8, U+00E5), all inside `latin`; `latin-ext` covers the rest of
|
|
* European diacritics for post names. Cyrillic, Greek and Vietnamese are
|
|
* dropped, which is most of the weight.
|
|
*
|
|
* Both faces are SIL Open Font License 1.1, which permits self-hosting as long
|
|
* as the licence travels with them — hence src/fonts/OFL.txt.
|
|
*/
|
|
import { mkdir } from "node:fs/promises";
|
|
|
|
const UA =
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36";
|
|
|
|
const FAMILIES = [
|
|
{ css: "Inter:[email protected]", slug: "inter" },
|
|
{ css: "JetBrains+Mono:[email protected]", slug: "jetbrains-mono" },
|
|
];
|
|
const WANTED = new Set(["latin", "latin-ext"]);
|
|
|
|
await mkdir("src/fonts", { recursive: true });
|
|
|
|
for (const family of FAMILIES) {
|
|
const url = `https://fonts.googleapis.com/css2?family=${family.css}&display=swap`;
|
|
const css = await (await fetch(url, { headers: { "user-agent": UA } })).text();
|
|
|
|
// Google labels each @font-face block with a /* subset */ comment above it.
|
|
const blocks = css.split("/*").slice(1);
|
|
let taken = 0;
|
|
|
|
for (const block of blocks) {
|
|
const subset = block.slice(0, block.indexOf("*/")).trim();
|
|
if (!WANTED.has(subset)) continue;
|
|
|
|
const src = /url\((https:\/\/[^)]+\.woff2)\)/.exec(block)?.[1];
|
|
const range = /unicode-range:\s*([^;]+);/.exec(block)?.[1]?.trim();
|
|
if (!src || !range) throw new Error(`${family.slug}/${subset}: no src or unicode-range`);
|
|
|
|
const response = await fetch(src, { headers: { "user-agent": UA } });
|
|
if (!response.ok) throw new Error(`${src} returned ${response.status}`);
|
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
|
|
const file = `src/fonts/${family.slug}-${subset}.woff2`;
|
|
await Bun.write(file, bytes);
|
|
console.log(`${file} ${bytes.length} bytes`);
|
|
console.log(` unicode-range: ${range}`);
|
|
taken++;
|
|
}
|
|
|
|
if (taken !== WANTED.size) {
|
|
throw new Error(`${family.slug}: took ${taken} subsets, expected ${WANTED.size}`);
|
|
}
|
|
}
|