themes-v1: 18 preset palettes + Settings picker

Adds 18 preset themes (16 dual-mode + 2 light-only) selectable from
a new /settings route. Persists per-user via the existing key-value
settings table — no schema refactor. Default on first load is
obsidian dark.

Storage: two new seeded keys (theme_id, theme_mode) inserted
idempotently from schema.sql. PATCH /api/settings tightens validation
with a discriminated branch — theme_id must be one of the 18
whitelisted ids, theme_mode ∈ {dark,light,system}, anything else
rejects 400. Other keys pass through the loose record schema.

CSS layer: 18 files in apps/web/src/styles/themes/, each declaring
.theme-<id> (light) and .theme-<id>.dark (dark) — except ivory and
chalk which are light-only. Anchor-to-token mapping per spec §3.
--destructive stays red across all themes. --radius unchanged at
0.625rem (spec parenthetical was about "not per-theme", not a
specific value swap).

Frontend: lib/theme.ts owns THEMES, applyTheme(), setTheme(), and
useTheme() — module-singleton with optimistic PATCH + revert on
failure (mirrors useChatStatus / useSidebar pattern). Settings.tsx
renders a 3-col (md) / 2-col (mobile) grid of shadcn Card swatches
with a Dark/Light/System radio group on top. App.tsx mounts
useTheme() at AppShell top and wires the /settings route.
index.html ships a pre-React FOUC script that reads localStorage
'boocode.theme' and stamps the className on <html> before any
paint. Stripped two pre-existing dark-mode lock-ins (AppShell's
hardcoded 'dark' className and body's neutral-950/100 tailwind
utilities) that would have fought theme tokens.

Light-only + dark request → falls back to obsidian dark in three
places: lib/theme.ts effectiveThemeId(), the FOUC script, and the
picker's "Light only" badge. No inline message; matches spec §8
decision 1.

shadcn primitives card and radio-group installed via shadcn CLI
(no hand-rolling). card.tsx and radio-group.tsx are the only ui/
additions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 16:25:15 +00:00
parent efbecd074a
commit 9b174cdb5e
28 changed files with 1895 additions and 2 deletions

View File

@@ -0,0 +1,60 @@
/* themes-v1: Matrix (family: green, neon).
Dark anchors: #000a00 #031403 #0a200a #208030 #00ff41. */
.theme-matrix {
--background: #f0fff4;
--foreground: #0a2a15;
--card: #e0f8e8;
--card-foreground: #0a2a15;
--popover: #e0f8e8;
--popover-foreground: #0a2a15;
--primary: #00b830;
--primary-foreground: #ffffff;
--secondary: #c0e8d0;
--secondary-foreground: #0a2a15;
--muted: #c0e8d0;
--muted-foreground: #208048;
--accent: #00b830;
--accent-foreground: #ffffff;
--destructive: #b91c1c;
--destructive-foreground: #ffffff;
--border: #c0e8d0;
--input: #c0e8d0;
--ring: #00b830;
--sidebar: #e0f8e8;
--sidebar-foreground: #0a2a15;
--sidebar-primary: #00b830;
--sidebar-primary-foreground: #ffffff;
--sidebar-accent: #c0e8d0;
--sidebar-accent-foreground: #0a2a15;
--sidebar-border: #c0e8d0;
--sidebar-ring: #00b830;
}
.theme-matrix.dark {
--background: #000a00;
--foreground: #d8f8e0;
--card: #031403;
--card-foreground: #d8f8e0;
--popover: #031403;
--popover-foreground: #d8f8e0;
--primary: #00ff41;
--primary-foreground: #000a00;
--secondary: #0a200a;
--secondary-foreground: #d8f8e0;
--muted: #0a200a;
--muted-foreground: #208030;
--accent: #00ff41;
--accent-foreground: #000a00;
--destructive: #dc2626;
--destructive-foreground: #ffffff;
--border: #0a200a;
--input: #0a200a;
--ring: #00ff41;
--sidebar: #031403;
--sidebar-foreground: #d8f8e0;
--sidebar-primary: #00ff41;
--sidebar-primary-foreground: #000a00;
--sidebar-accent: #00ff41;
--sidebar-accent-foreground: #000a00;
--sidebar-border: #0a200a;
--sidebar-ring: #00ff41;
}