From 4da188bfe5455066b4696232a2e1d361ae288872 Mon Sep 17 00:00:00 2001
From: 7418 <7418@openclaw.ai>
Date: Mon, 9 Mar 2026 11:15:01 +0800
Subject: [PATCH] feat: theme family system with 12 color palettes + NavRail
redesign
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Theme system:
- Two-layer architecture: mode (light/dark/system via next-themes) + theme family (color palette via CSS variables)
- 12 theme families: Default, GitHub, Rosé Pine, Tokyo Night, Everforest, Nord, Kanagawa, Night Owl, Poimandres, Vesper, Horizon, SynthWave '84
- Per-family code block highlighting for Prism, HLJS, and Shiki (no more generic oneLight/oneDark fallback)
- Anti-FOUC: synchronous script in
reads localStorage and sets data-theme-family before paint
- Theme JSON files in themes/ directory, auto-discovered by server-side loader
- OKLCH color space for all values; CSS specificity html[data-theme-family] beats :root
UI changes:
- NavRail: moved Settings to bottom (replacing theme toggle), removed light/dark toggle button
- Settings: merged General controls into one card with dividers; Appearance section with live Shiki code preview
- Replaced hardcoded blue-500/blue-600 with primary/primary-foreground across 19 components
- Appearance settings: pill mode selector (light/dark/system), theme family dropdown, live code preview
New files:
- src/lib/theme/{types,loader,render-css,context,code-themes}.ts — core theme infrastructure
- src/components/layout/ThemeFamilyProvider.tsx — client context provider
- src/components/settings/AppearanceSection.tsx — appearance settings UI
- src/hooks/useAppTheme.ts — combined theme hook
- themes/*.json — 12 theme family definitions
- docs/handover/theme-system.md — handover documentation
Co-Authored-By: Claude Opus 4.6
---
docs/handover/README.md | 1 +
docs/handover/theme-system.md | 82 +++++++
electron-builder.yml | 3 +
src/__tests__/unit/theme-loader.test.ts | 193 +++++++++++++++
src/__tests__/unit/theme-render-css.test.ts | 107 +++++++++
src/app/globals.css | 20 +-
src/app/layout.tsx | 21 +-
src/components/ai-elements/code-block.tsx | 68 ++++--
src/components/bridge/BridgeSection.tsx | 6 +-
src/components/chat/CodeBlock.tsx | 65 +++--
src/components/chat/FolderPicker.tsx | 2 +-
src/components/chat/ImageGenConfirmation.tsx | 4 +-
src/components/chat/ImageGenToggle.tsx | 2 +-
src/components/chat/MessageInput.tsx | 6 +-
src/components/chat/MessageList.tsx | 2 +-
src/components/chat/ToolCallBlock.tsx | 14 +-
.../batch-image-gen/BatchExecutionItem.tsx | 4 +-
src/components/layout/DocPreview.tsx | 17 +-
src/components/layout/InstallWizard.tsx | 12 +-
src/components/layout/NavRail.tsx | 57 ++---
src/components/layout/SplitColumn.tsx | 6 +-
src/components/layout/ThemeFamilyProvider.tsx | 60 +++++
src/components/layout/UpdateBanner.tsx | 2 +-
src/components/layout/UpdateDialog.tsx | 4 +-
src/components/plugins/McpManager.tsx | 2 +-
src/components/plugins/McpServerList.tsx | 4 +-
src/components/project/FilePreview.tsx | 18 +-
src/components/project/TaskCard.tsx | 2 +-
src/components/settings/AppearanceSection.tsx | 226 ++++++++++++++++++
src/components/settings/GeneralSection.tsx | 27 ++-
src/components/skills/CreateSkillDialog.tsx | 2 +-
.../skills/InstallProgressDialog.tsx | 2 +-
src/components/skills/SkillEditor.tsx | 4 +-
src/hooks/useAppTheme.ts | 16 ++
src/i18n/en.ts | 11 +
src/i18n/zh.ts | 11 +
src/lib/theme/code-themes.ts | 191 +++++++++++++++
src/lib/theme/context.ts | 18 ++
src/lib/theme/loader.ts | 214 +++++++++++++++++
src/lib/theme/render-css.ts | 46 ++++
src/lib/theme/types.ts | 78 ++++++
themes/default.json | 80 +++++++
themes/everforest.json | 80 +++++++
themes/github.json | 80 +++++++
themes/horizon.json | 80 +++++++
themes/kanagawa.json | 80 +++++++
themes/night-owl.json | 80 +++++++
themes/nord.json | 80 +++++++
themes/poimandres.json | 80 +++++++
themes/rose-pine.json | 80 +++++++
themes/synthwave84.json | 80 +++++++
themes/tokyo-night.json | 80 +++++++
themes/vesper.json | 80 +++++++
53 files changed, 2446 insertions(+), 144 deletions(-)
create mode 100644 docs/handover/theme-system.md
create mode 100644 src/__tests__/unit/theme-loader.test.ts
create mode 100644 src/__tests__/unit/theme-render-css.test.ts
create mode 100644 src/components/layout/ThemeFamilyProvider.tsx
create mode 100644 src/components/settings/AppearanceSection.tsx
create mode 100644 src/hooks/useAppTheme.ts
create mode 100644 src/lib/theme/code-themes.ts
create mode 100644 src/lib/theme/context.ts
create mode 100644 src/lib/theme/loader.ts
create mode 100644 src/lib/theme/render-css.ts
create mode 100644 src/lib/theme/types.ts
create mode 100644 themes/default.json
create mode 100644 themes/everforest.json
create mode 100644 themes/github.json
create mode 100644 themes/horizon.json
create mode 100644 themes/kanagawa.json
create mode 100644 themes/night-owl.json
create mode 100644 themes/nord.json
create mode 100644 themes/poimandres.json
create mode 100644 themes/rose-pine.json
create mode 100644 themes/synthwave84.json
create mode 100644 themes/tokyo-night.json
create mode 100644 themes/vesper.json
diff --git a/docs/handover/README.md b/docs/handover/README.md
index 37c268e..9cefb10 100644
--- a/docs/handover/README.md
+++ b/docs/handover/README.md
@@ -11,3 +11,4 @@
| agent-tooling-todo-bridge.md | SDK → SSE → DB 事件流、TodoWrite 字段映射、去重策略 |
| bridge-system.md | 多 IM 远程桥接系统架构(目录结构、数据流、设计决策) |
| assistant-workspace.md | 助理工作区:人格/记忆文件、对话式引导、自动触发、确定性落盘 |
+| theme-system.md | 主题家族系统:两层架构、JSON schema、代码高亮三条渲染链、12 个主题清单 |
diff --git a/docs/handover/theme-system.md b/docs/handover/theme-system.md
new file mode 100644
index 0000000..542a23e
--- /dev/null
+++ b/docs/handover/theme-system.md
@@ -0,0 +1,82 @@
+# Theme Family System / 主题家族系统
+
+## 概述
+
+两层主题系统:`mode`(light/dark/system,由 next-themes 管理)+ `theme family`(色板,由自定义 context + CSS 变量管理)。
+
+## 架构
+
+```
+themes/*.json → 定义色板(OKLCH)、代码主题映射
+src/lib/theme/loader.ts → 服务端读取 + 校验 JSON,按 order 排序
+src/lib/theme/render-css.ts → 生成 html[data-theme-family="x"] 规则
+src/app/layout.tsx → 注入反闪烁脚本 +