跳转到内容

01 · 主题定制器与用户偏好

页面组件
博客 / 文档顶栏 ColorThemeSelect
书签导航 /bookmarks/nav/顶栏 ColorThemePicker
书签管理 /bookmarks/admin/登录页与顶栏

任一 Surface 的修改经 localStorage 同步至同浏览器其它标签页。

  • Primary / Neutral / Radius:切换色板与圆角档位。
  • 色彩模式:浅色、深色、跟随系统。
  • 随机:仅随机 Primary / Neutral / Radius,不改变色彩模式。
  • 重置:恢复默认(green / slate / 0.25 / 跟随系统)。

浏览器 localStoragewwlight: 前缀),例如:

  • wwlight:color-mode — 色彩模式
  • wwlight:color-primary — Primary
  • wwlight:color-neutral — Neutral
  • wwlight:theme-radius — Radius

样式不直接读 localStorage;首屏内联脚本将值写入 <html data-theme="…" data-color-primary="…">,再由 CSS 属性选择器生效,避免 FOUC。

书签侧 shadcn 使用 --primary--background;文档站侧栏使用 Starlight --color-accent-*。两套样式表,同一组 data-*,主色变更在两处同时体现。

逻辑位于 src/theme/lib/,对外 API:import { … } from '@/theme'

Terminal window
vpr generate:color-themes # color-tokens.css、options.json 等
vpr generate:theme-init # scripts/init.inline.js(首屏脚本)

默认值定义于 scripts/color-themes.data.mjs(Primary green、Neutral slate、Radius 0.25)。