feat(webui): appearance customization — theme/accent/background/fonts/a11y (phase 2)

Wires the Phase 1 store into a full appearance layer.

ThemeContext is rewritten to load/save UiAppearance from the server (with a
localStorage anti-flash cache + a one-time migration of the legacy per-browser
theme keys), apply ~12 dimensions to <html>, and theme the login page pre-auth.

New Settings controls (外观 / 数据与格式): free-hex accent (+ presets + apply
scope), dark intensity (soft / OLED black), sidebar style, background
(solid / gradient / uploaded image with opacity + blur), font presets, UI
scale, reduce-motion, high-contrast, default-collapsed sidebar, 12h/24h time
format (wired into logs + overview timestamps).

- index.html gains a pre-paint bootstrap script that applies the cached theme
  before the bundle mounts, eliminating the dark/OLED/scale FOUC.
- server saveUiConfig is now a section-level merge so appearance-only and
  layout-only saves never clobber each other.
- reduce-motion uses Framer MotionConfig; the background renders on a fixed
  layer revealed by transparent app roots; custom-accent hex and ui-scale are
  validated/clamped before use (localStorage-tamper hardening).

Verified across 2 adversarial review rounds (FOUC + CSS-injection + impure
state-updater + ref-staleness all fixed).
This commit is contained in:
DrSmoothl committed 2026-06-13 01:15:00 +08:00
1 parent 0b5087b410
commit ac1ffc46d3
9 files changed
+1028 -308

No files matched your search

+55 -2
View File
@@ -153,12 +153,65 @@
background-color: color-mix(in oklab, var(--primary) 28%, transparent);
color: var(--foreground);
}
/* Density: compact tightens the global rhythm a touch. */
/* Density: compact tightens the global rhythm a touch. Use rem (not px) so
it still tracks the UI-scale root font-size. */
html[data-density="compact"] body {
font-size: 13.5px;
font-size: 0.84rem;
line-height: 1.45;
}
html[data-density="compact"] {
--tw-leading: 1.4;
}
}
/* ──────────────────────────────────────────────
Customization layers (driven by ThemeContext via
data-* attributes + CSS vars on <html>)
────────────────────────────────────────────── */
/* Dark intensity: "black" pushes the dark palette toward true black for
OLED screens. Only meaningful in dark mode. */
.dark[data-dark-intensity="black"] {
--background: oklch(0% 0 0);
--foreground: oklch(97% 0.01 240);
--card: oklch(13% 0.008 250);
--card-foreground: oklch(96% 0.01 240);
--popover: oklch(13% 0.008 250);
--popover-foreground: oklch(96% 0.01 240);
--secondary: oklch(17% 0.012 250);
--muted: oklch(15% 0.01 250);
--muted-foreground: oklch(66% 0.02 240);
--border: oklch(22% 0.012 250);
--input: oklch(19% 0.012 250);
--sidebar: oklch(5% 0.006 250);
--sidebar-border: oklch(20% 0.012 250);
}
/* Sidebar style: how distinct the sidebar surface is from the main canvas. */
html[data-sidebar-style="panel"] {
--sidebar: color-mix(in oklab, var(--card) 90%, var(--primary) 4%);
}
html[data-sidebar-style="accent"] {
--sidebar: color-mix(in oklab, var(--background) 76%, var(--primary) 24%);
--sidebar-foreground: color-mix(in oklab, var(--foreground) 85%, var(--primary));
--sidebar-border: color-mix(in oklab, var(--border) 60%, var(--primary) 40%);
}
/* High contrast: strengthen borders + dim-text contrast for legibility. */
html[data-contrast="high"] {
--border: color-mix(in oklab, var(--foreground) 55%, var(--border));
--input: color-mix(in oklab, var(--foreground) 45%, var(--input));
--muted-foreground: color-mix(in oklab, var(--foreground) 78%, var(--muted-foreground));
--sidebar-border: color-mix(in oklab, var(--foreground) 55%, var(--sidebar-border));
}
/* Reduce motion: a CSS fallback for non-Framer transitions/animations.
Framer Motion itself is handled by <MotionConfig reducedMotion>. */
html[data-reduce-motion="1"] *,
html[data-reduce-motion="1"] *::before,
html[data-reduce-motion="1"] *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}