Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): 外观页的主题换成一排画着自己颜色的卡片

lmlihengfae52bb9f2f8
diff --git a/changelog/unreleased/2026-10-27-theme-picker-cards.md b/changelog/unreleased/2026-10-27-theme-picker-cards.md
new file mode 100644
index 00000000..9e00a969
--- /dev/null
+++ b/changelog/unreleased/2026-10-27-theme-picker-cards.md
@@ -0,0 +1,47 @@
+# The theme picker is a row of cards, each painted with its own colors
+
+- **Date:** 2026-10-27
+- **Type:** feat
+- **Scope:** `web`, `docs`
+- **Breaking:** no
+
+[中文](2026-10-27-theme-picker-cards.zh.md)
+
+Choosing a theme used to be a row of buttons with one word each — **Primer**, **Frost**, **Console** — and
+once a machine imported a few themes that row either wrapped into a block of chips or scrolled sideways.
+Either way you were choosing between names you could not see: what separates Frost from Console is
+something you learned by switching to it. The themes are cards now. Each card paints that theme's own
+canvas, surface, a line of ink and an accent chip, with the name underneath; the three the package ships
+sit under **Built in**, the ones files brought under **Imported**, and a group appears only when it has
+something in it.
+
+The block under the picker changed with it. It used to be a paragraph — the themes directory's absolute
+path, what a file looks like, how to refresh, that an admin can import too — with **Read again** and
+**Import…** hanging off the end of it. That paragraph is worth reading once and was scrolled past on
+every later visit. It is now the two things one can actually do (**Read again**, and an admin's
+**Import a theme…**) beside one line naming the folder, with the path and the file format behind the "?"
+next to them. An imported theme that sets only part of the values is one line per theme — "203 tokens
+keep the default" — that opens to the names, instead of the wall of `--ui-` names it printed before.
+
+## Details
+
+- `packages/web/src/features/settings/theme-picker.tsx` (new): `ThemePicker` and the card. The shipped
+ three themes' four colors are spelled out in `BUILTIN_PREVIEW`, because their rules answer
+ `:root[data-theme="…"]` one theme at a time and drawing three at once would repaint the page per card;
+ an imported theme's colors come from its own file. Each card shows the mode the page is drawn in.
+- `packages/web/src/state/external-themes.ts`: `ImportedThemeView` gains `preview`, the four colors of an
+ imported theme in each mode, filled in from the default theme for names the file leaves out.
+- `packages/web/src/features/settings/appearance-section.tsx`: the theme row becomes a full-width
+ `ThemePicker` (a grid needs the row's whole width to wrap into); the note becomes the folder line with
+ its "?" and two actions, and the problem list becomes one collapsible line per theme.
+- `packages/web/src/features/settings/theme-import-dialog.tsx`: the import entry is a secondary button
+ beside **Read again** rather than a line of small text under the paragraph.
+- Strings: `themeBuiltin` / `themeImportedGroup` / `importedThemeUnknownShort` /
+ `importedThemeMissingShort` / `importedThemeDetails` / `importedThemesHelp` (`importedThemesDir` is gone).
+- Docs: the Appearance section of `packages/docs/content/settings.{zh,en}.md` — its "Theme: Light / Dark /
+ System" row was wrong (that is **Color mode**), so the two are separate rows now, with a paragraph on
+ imported themes.
+
+## Compatibility
+
+- No API, on-disk or configuration change: same theme format, same directory, same `data-theme` attribute.
diff --git a/changelog/unreleased/2026-10-27-theme-picker-cards.zh.md b/changelog/unreleased/2026-10-27-theme-picker-cards.zh.md
new file mode 100644
index 00000000..9dda9ce1
--- /dev/null
+++ b/changelog/unreleased/2026-10-27-theme-picker-cards.zh.md
@@ -0,0 +1,40 @@
+# 外观页的主题变成一排卡片,每张画着自己的颜色
+
+- **Date:** 2026-10-27
+- **Type:** feat
+- **Scope:** `web`, `docs`
+- **Breaking:** no
+
+[English](2026-10-27-theme-picker-cards.md)
+
+以前挑主题是一行按钮,每个主题占一个词:**通用**、**白领**、**极客**。这台机器一旦导入几个主题,这行
+要么折成一坨、要么横向滚动,而且不管哪种,你挑的都是几个看不见的名字 —— 「白领」和「极客」差在哪儿,
+只有切过去才知道。现在主题是一组卡片,每张卡片画着这个主题自己的底色、面板色、一行文字色和一枚强调色,
+文字名字写在下面。内置的主题在**内置主题**那一组,文件带来的在**导入主题**那一组,两组各自只在有内容
+时出现。
+
+主题列表下面那一块也跟着改了:以前是一段说明 —— 主题目录的绝对路径、什么文件、怎么刷新、管理员还能
+导入 —— 后面挂着「重新读取」和「导入…」。这段话第一次看有用,之后每次进来都要从它上面滚过去。现在那一块
+只有两件能做的事(**重新读取**、管理员的**导入主题…**)和一行「主题目录」,路径与文件格式收进旁边的
+「?」里。导入的主题如果只写了一部分取值,下面按主题一行说「N 个令牌沿用默认值」,点开才是具体名字 ——
+以前那一长串 `--ui-` 名字是直接铺开的。
+
+## 细节
+
+- `packages/web/src/features/settings/theme-picker.tsx`(新增):`ThemePicker` 与卡片本身。内置三个主题的
+ 四种颜色在 `BUILTIN_PREVIEW` 里写死(它们的规则按 `:root[data-theme="…"]` 一次只答一个主题,页面上同时
+ 画三个就得每张卡重刷一遍),导入主题的颜色来自它自己的文件;明暗跟着当前模式走。
+- `packages/web/src/state/external-themes.ts`:`ImportedThemeView` 多一个 `preview`,是这台机器导入的
+ 主题在两种模式下的四个颜色(文件没写的取默认主题的值)。
+- `packages/web/src/features/settings/appearance-section.tsx`:主题那一行换成占满整行宽度的 `ThemePicker`
+ (网格要整行才折得开);下面那块改成「主题目录 + ?」加两个动作按钮,问题清单改成可折叠的一行一条。
+- `packages/web/src/features/settings/theme-import-dialog.tsx`:导入入口从小字链接改成次要按钮,和
+ 「重新读取」并排。
+- 文案:`themeBuiltin` / `themeImportedGroup` / `importedThemeUnknownShort` / `importedThemeMissingShort` /
+ `importedThemeDetails` / `importedThemesHelp`(旧的 `importedThemesDir` 不再使用)。
+- 文档:`packages/docs/content/settings.{zh,en}.md` 的外观一节 —— 原来的「主题 = 浅色 / 深色 / 跟随系统」
+ 那一行写错了(那是**明暗**),这版分成两行,并补了一段导入主题的说明。
+
+## 兼容
+
+- 没有接口、磁盘格式或配置变化:主题文件还是同一个格式、同一个目录,`data-theme` 还是同一个属性。
diff --git a/packages/docs/content/settings.en.md b/packages/docs/content/settings.en.md
index ccf7f215..2b0c4aaa 100644
--- a/packages/docs/content/settings.en.md
+++ b/packages/docs/content/settings.en.md
@@ -120,14 +120,17 @@ The **Appearance** page is personal.
| Setting | Options | What it does |
| --- | --- | --- |
-| **Theme** | Light / Dark / System | The interface theme. |
+| **Theme** | Primer, Frost, Console, plus whatever this machine imported | The interface's overall style: layout, lines, type and motion change with it. Each card paints that theme's own canvas, surface, ink and accent, so you can see a choice before picking it. |
+| **Color mode** | Light / Dark / System | The light or dark version of the theme. |
| **Terminal theme** | App / Light / Dark | The terminal panel keeps its own light or dark and follows the app theme by default. Pin it to Light or Dark to decouple the two, for prompts and TUIs tuned to one screen. |
| **Font size** | S / M / L | The interface font size. |
-| **Accent** | Neutral, Blue, Green, Violet, Rose or Amber | The interface accent color. |
+| **Accent** | Neutral, Blue, Green, Violet, Rose or Amber, plus the ones the current theme brings | The interface accent color. |
| **Shortcuts launcher** | On / Off | The round button floating on the conversation's right edge that fans out shortcuts to the workbench's panels and the terminal. The fan's **Hide launcher** entry does the same. |
| **Tool short names** | On / Off | Tool cards in a conversation name built-in tools by a short alias (`read_file` reads as "read"). Every other tool, MCP tools included, and the Trace viewer keep the tool's own name. Hovering a short name shows it. |
| **Tray icon** | On / Off (on by default) | Desktop app only. See below. |
+About **imported themes**: a theme is only a set of values, which is why a machine can have its own. Drop a theme's `.json` file into the data root's `themes/` folder and choose **Read again** under the theme list: it appears as a card in the **Imported** group, painted with its own colors. The "?" beside those two actions says where the folder is and what a file looks like, and an admin can instead press **Import a theme…** and upload the file without walking to the folder. A file may set only part of the values: the names it leaves out keep the default theme's, and the lines under the list say how many token names went unrecognised and how many keep the default — click one to see the names themselves.
+
About **Tray icon**: the desktop app keeps an icon in the system tray: the Windows notification area, the macOS menu bar, or the Linux tray. It stays there for as long as the app runs. Click the icon to come back to the window. Right-click it to start a new Session or quit.
Turning it off removes the icon at once, with no restart. Closing the window then no longer hides it there: the app stays in the Dock on macOS, and quits on Windows and Linux.
diff --git a/packages/docs/content/settings.zh.md b/packages/docs/content/settings.zh.md
index beabf726..353d25b6 100644
--- a/packages/docs/content/settings.zh.md
+++ b/packages/docs/content/settings.zh.md
@@ -120,14 +120,21 @@ Trace 会成为该 Agent 的一段新对话。如果该 Agent 下已有相同 id
| 设置 | 选项 | 作用 |
| --- | --- | --- |
-| **主题** | 浅色 / 深色 / 跟随系统 | 界面主题。 |
+| **主题** | 通用 / 白领 / 极客,外加这台机器导入的主题 | 界面的整体风格:布局、线条、字体与动效随之改变。每张卡片画着它自己的底色、面板色、文字色与强调色,所以不用逐个试。 |
+| **明暗** | 浅色 / 深色 / 跟随系统 | 主题的明暗版本。 |
| **终端主题** | 跟随主题 / 浅色 / 深色 | 终端面板有自己的明暗配色,默认跟随应用主题。固定为浅色或深色即与应用主题脱钩,适合只针对一种底色调校过的命令行提示符和 TUI。 |
| **字号** | 小 / 中 / 大 | 界面字号。 |
-| **主题色** | 灰白、蓝、绿、紫、红、橙 | 界面的主题色。 |
+| **强调色** | 灰白、蓝、绿、紫、红、橙,以及当前主题自带的那几个 | 界面的强调色。 |
| **快捷方式悬浮球** | 开 / 关 | 浮在对话区右缘的圆形按钮,展开后是通往工作台各面板和终端的快捷方式。关掉它与点击展开项里的**隐藏悬浮球**效果相同。 |
| **工具短名** | 开 / 关 | 对话里的工具卡片用短名称呼内置工具(`read_file` 显示为「读取」)。其余工具(含 MCP 工具)和轨迹观测始终显示工具原名,悬停短名也能看到原名。 |
| **托盘图标** | 开 / 关(默认开启) | 仅桌面应用。见下文。 |
+关于**导入的主题**:主题只是一组取值,所以一台机器可以拥有自己的主题。把主题的 `.json` 文件放进数据根下
+的 `themes/` 目录,再点主题列表下方的**重新读取**,它就会作为一张卡片出现在**导入主题**那一组里,画着它
+自己的颜色。这个目录在哪、文件长什么样,点旁边那个「?」都有;管理员还可以点**导入主题…** 直接把文件
+传上去,不用走到目录里。主题文件只写得出一部分取值也没关系:没写的那些沿用「通用」主题,列表下方会
+写哪几个令牌不认识、哪几个沿用了默认值,点一下能看见具体名字。
+
关于**托盘图标**:桌面应用运行期间,会在系统托盘(Windows 的通知区域、macOS 的菜单栏、Linux 的托盘)里常驻一个图标。点击图标回到窗口,右键可以开新会话或退出。
关掉后图标立即消失,无需重启。此后关闭窗口不再收进托盘:macOS 上应用留在 Dock 中,Windows 和 Linux 上则直接退出。
diff --git a/packages/web/src/features/settings/appearance-section.tsx b/packages/web/src/features/settings/appearance-section.tsx
index f5e7ebab..450f8274 100644
--- a/packages/web/src/features/settings/appearance-section.tsx
+++ b/packages/web/src/features/settings/appearance-section.tsx
@@ -14,15 +14,27 @@
* THEMES AN INSTALLATION IMPORTED are rows of the theme picker like the three the UI package
* ships, and they arrive as data: this page lists them, paints their accents and says what a file
* got wrong — the file games no say in the layout, because a theme is only values (see
- * state/external-themes.ts). The note under the theme row is where the reader learns which
- * directory to drop a file in and why one did not read, since nothing here discovers files by
- * itself: the browser cannot see the server's disk. An admin gets one more thing in that line — the
- * import entry, for the same install without the walk to the folder — and it is the server's own
- * rule that decides who may use it: the routes answer 403 to anyone else, so the entry is drawn for
- * an admin only rather than offered and refused.
+ * state/external-themes.ts). The row under the picker is the two things one can do about that
+ * directory — read it again, or import a file into it — because nothing here discovers files by
+ * itself: the browser cannot see the server's disk. Where a file goes, and the shape of one, sit
+ * behind the "?" beside those two actions: they answer a question asked once, and printed in full
+ * they were a paragraph every later visit scrolled past. An admin gets the second action, for the
+ * same install without the walk to the folder, and it is the server's own rule that decides who
+ * may use it: the routes answer 403 to anyone else, so the entry is drawn for an admin only rather
+ * than offered and refused.
*/
import { useEffect, useState, useSyncExternalStore } from "react";
-import { PrefRow, Segmented, Select, SwatchPicker, THEME_IDS, ToggleRow } from "@adelie/ui";
+import {
+ Button,
+ InfoPopover,
+ PrefRow,
+ PrefRowLabel,
+ Segmented,
+ Select,
+ SwatchPicker,
+ THEME_IDS,
+ ToggleRow,
+} from "@adelie/ui";
import { FONT_CJK_OPTIONS, FONT_LATIN_OPTIONS, TEXT_SIZES } from "@adelie/ui/boot";
import { S } from "../../lib/strings";
import * as api from "../../api/endpoints";
@@ -46,6 +58,7 @@ import type { ImportedThemesState } from "../../state/external-themes";
import { localizedText } from "../chat/skill-use";
import { FONT_FOLLOWS_THEME, effectiveAccent } from "../../state/theme-prefs";
import { ThemeImportActions } from "./theme-import-dialog";
+import { ThemePicker } from "./theme-picker";
/**
* A font select's choices: the theme's own face first — it is the default, and the named faces
@@ -123,9 +136,15 @@ function nameList(names: readonly string[], locale: "zh" | "en"): string {
}
/**
- * What this installation imported, under the theme row: the directory to drop a file in, and one
- * line per thing that did not come out right. Nothing is said while the list has not arrived (or
- * when the request itself failed, which is one line rather than a claim about the directory).
+ * What this installation imported, under the theme picker: what one can do about the directory —
+ * read it again, and (as an admin) import a file into it — plus one line per thing that did not
+ * come out right.
+ *
+ * WHERE A FILE GOES IS BEHIND THE "?". The path, the shape of a file and the fact that importing
+ * is install-level are read once and then never again; spelled out under the picker they were a
+ * paragraph every later visit scrolled past, with the two actions they explained buried in it. The
+ * actions are the row now, and the prose is one click away. A failed read keeps the row — "read
+ * again" is the retry — and adds the one line that says the list is unknown rather than empty.
*
* An imported theme that is merely FILLED IN PARTLY says so here and still paints — a name it
* leaves out keeps the default theme's value — while a file that would not read is reported with
@@ -144,60 +163,78 @@ function ImportedThemesNote({
canImport: boolean;
}) {
const [reading, setReading] = useState(false);
- if (state.failed)
- return (
- <p className="py-3.5 text-xs text-gray-500 dark:text-gray-400">
- {S.settings.importedThemesFailed}
- </p>
- );
- if (state.dir === null) return null;
const problems = state.themes.filter(
(theme) => theme.unknown.length > 0 || theme.missing.length > 0,
);
const orphan = themeIdOptionsInclude(state, activeId) ? null : activeId;
return (
- <div className="space-y-1 py-3.5 text-xs text-gray-500 dark:text-gray-400">
- <p className="flex flex-wrap items-center gap-x-2 gap-y-1">
- <span className="font-mono break-all">{S.settings.importedThemesDir(state.dir)}</span>
- <button
- type="button"
+ <div className="space-y-1.5 py-3 text-xs text-fg-subtle">
+ <div className="flex flex-wrap items-center gap-2">
+ {/* The row's subject, then the "?" that answers where a file goes — a "?" needs a title
+ beside it to modify (see packages/ui's InfoPopover), and "read again" needs one to say
+ what it reads. */}
+ <p className="flex items-center gap-1.5 text-fg-muted">
+ {S.settings.importedThemesHelp}
+ <InfoPopover label={S.settings.importedThemesHelp}>
+ <div className="space-y-1.5">
+ {state.dir !== null && <p className="font-mono break-all">{state.dir}</p>}
+ <p>{S.settings.importedThemesHint}</p>
+ </div>
+ </InfoPopover>
+ </p>
+ <Button
+ size="sm"
+ variant="ghost"
disabled={reading}
onClick={() => {
setReading(true);
void refreshImportedThemes(true).finally(() => setReading(false));
}}
- className="shrink-0 text-gray-600 underline transition-colors duration-150 hover:text-gray-900 disabled:opacity-50 dark:text-gray-300 dark:hover:text-gray-100"
>
{S.settings.importedThemesReadAgain}
- </button>
- {/* Right beside the path it writes into, because it is the same install: the file that
- would have been dropped there, put there. */}
+ </Button>
+ {/* The file that would have been dropped into that directory, put there instead. */}
{canImport && <ThemeImportActions onImported={() => refreshImportedThemes(true)} />}
- </p>
- <p>{S.settings.importedThemesHint}</p>
+ </div>
+ {state.failed && <p>{S.settings.importedThemesFailed}</p>}
{orphan !== null && <p>{S.settings.importedThemesNoFile(orphan)}</p>}
+ {/* One line per theme with something to say, and the token names one click away: a theme is
+ allowed to set only what it changes, so "a hundred names keep the default" is the normal
+ case and printing them all buried the row under a wall of --ui- names. */}
{problems.map((theme) => (
- <div key={theme.id}>
- <p className="text-gray-600 dark:text-gray-300">
+ <details key={theme.id}>
+ <summary className="cursor-pointer text-fg-muted">
{localizedText(locale, theme.name, theme.nameZh)}
- </p>
- {theme.unknown.length > 0 && (
- <p>
- {S.settings.importedThemeUnknown(
- theme.unknown.length,
- nameList(theme.unknown, locale),
- )}
- </p>
- )}
- {theme.missing.length > 0 && (
- <p>
- {S.settings.importedThemeMissing(
- theme.missing.length,
- nameList(theme.missing, locale),
- )}
- </p>
- )}
- </div>
+ {" · "}
+ {[
+ theme.unknown.length > 0 &&
+ S.settings.importedThemeUnknownShort(theme.unknown.length),
+ theme.missing.length > 0 &&
+ S.settings.importedThemeMissingShort(theme.missing.length),
+ ]
+ .filter(Boolean)
+ .join(locale === "zh" ? "、" : ", ")}
+ <span className="ml-1 text-fg-subtle">{S.settings.importedThemeDetails}</span>
+ </summary>
+ <div className="mt-1 space-y-1 pl-3">
+ {theme.unknown.length > 0 && (
+ <p>
+ {S.settings.importedThemeUnknown(
+ theme.unknown.length,
+ nameList(theme.unknown, locale),
+ )}
+ </p>
+ )}
+ {theme.missing.length > 0 && (
+ <p>
+ {S.settings.importedThemeMissing(
+ theme.missing.length,
+ nameList(theme.missing, locale),
+ )}
+ </p>
+ )}
+ </div>
+ </details>
))}
{state.rejected.map(({ file, errors }) => (
<p key={file} className="font-mono break-all">
@@ -294,17 +331,6 @@ export function AppearanceSection() {
{ value: "light", label: S.settings.themeLight },
{ value: "dark", label: S.settings.themeDark },
];
- const themeIdOptions: ReadonlyArray<{ value: string; label: string }> = [
- ...THEME_IDS.map((id) => ({ value: id, label: S.settings.themeNames[id] })),
- ...imported.themes.map((theme) => ({
- value: theme.id,
- label: localizedText(locale, theme.name, theme.nameZh),
- })),
- // A stored id nothing provides keeps its place in the picker: the row then shows what the root
- // actually carries (and the note below says why nothing paints for it) rather than quietly
- // claiming the default theme is what was chosen.
- ...(themeIdOptionsInclude(imported, themeId) ? [] : [{ value: themeId, label: themeId }]),
- ];
const swatches = accentSwatches(themeId, dark, imported.themes);
const textSizeOptions: ReadonlyArray<{ value: TextSize; label: string }> = TEXT_SIZES.map(
(size) => ({ value: size, label: S.settings.textSizeNames[size] }),
@@ -312,9 +338,18 @@ export function AppearanceSection() {
return (
<div className="divide-y divide-gray-100 dark:divide-gray-800/60">
- <PrefRow label={S.settings.theme} info={S.settings.themeInfo}>
- <Segmented options={themeIdOptions} value={themeId} onChange={setThemeId} />
- </PrefRow>
+ {/* The picker is a grid, not a control beside the label: it needs the row's whole width to
+ wrap into, which the row's own control slot does not give it. */}
+ <div className="py-3.5 first:pt-0">
+ <PrefRowLabel label={S.settings.theme} info={S.settings.themeInfo} />
+ <ThemePicker
+ imported={imported.themes}
+ value={themeId}
+ onChange={setThemeId}
+ dark={dark}
+ locale={locale}
+ />
+ </div>
<ImportedThemesNote
state={imported}
activeId={themeId}
diff --git a/packages/web/src/features/settings/theme-import-dialog.tsx b/packages/web/src/features/settings/theme-import-dialog.tsx
index 7ef0b648..c50faaea 100644
--- a/packages/web/src/features/settings/theme-import-dialog.tsx
+++ b/packages/web/src/features/settings/theme-import-dialog.tsx
@@ -7,8 +7,9 @@
* it is called, and the server writes it under that name (`<id>.json`), so the only question left
* is where the bytes come from. That is a two-way switch, and everything after it is shared — one
* body, one confirm button, one overwrite confirmation, one success path — which is what keeps the
- * dialog from being two nearly identical ones. The switch is also why this is not the note's own
- * pair of buttons: the directory line is a line of small text, and two buttons there would shout.
+ * dialog from being two nearly identical ones. It is also why the note under the picker offers ONE
+ * import entry rather than one per source: which way the bytes come is the dialog's question, not a
+ * third button on the page.
*
* Both flows are the same import twice, as in the plugin dialogs: one carries the file in the
* request, the other a URL the server fetches, and a 409 `theme_exists` opens the overwrite
@@ -172,15 +173,12 @@ export function ThemeImportActions({
return (
<>
- {/* The entry sits in the directory line, beside "read again": the two are the same read and
- the same write, so they belong to the same sentence about the folder. */}
- <button
- type="button"
- onClick={() => setOpen(true)}
- className="shrink-0 text-gray-600 underline transition-colors duration-150 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100"
- >
+ {/* The entry sits beside "read again": the two are the same read and the same write, so they
+ belong to one row of actions on the folder. Bordered rather than a third line of small
+ text, because it is the only one of them that brings something in. */}
+ <Button size="sm" variant="secondary" onClick={() => setOpen(true)}>
{S.settings.themeImport}
- </button>
+ </Button>
<Modal
open={open}
diff --git a/packages/web/src/features/settings/theme-picker.tsx b/packages/web/src/features/settings/theme-picker.tsx
new file mode 100644
index 00000000..af66649e
--- /dev/null
+++ b/packages/web/src/features/settings/theme-picker.tsx
@@ -0,0 +1,250 @@
+/**
+ * The theme picker: every theme as a card that shows the colours it paints, not only its name.
+ *
+ * WHY CARDS AND NOT A SEGMENTED ROW. A segmented row gives each theme one word of room, so the
+ * list stops fitting the moment an installation imports a few files — the row either wraps into a
+ * block of chips or scrolls sideways, and either way the reader is choosing between names they
+ * cannot see. A grid of cards costs the same vertical band, wraps instead of overflowing, scrolls
+ * once it outgrows that band, and shows what each choice looks like where the name would be alone.
+ *
+ * THE CHIP IS PAINTED FROM DATA. An imported theme's four colours come from its own file (the same
+ * values its stylesheet is generated from). The three themes the package ships cannot be read that
+ * way — their rules answer `:root[data-theme="…"]`, one theme at a time, so a page showing three of
+ * them at once would have to repaint itself per card. Their four chip colours are spelled out in
+ * {@link BUILTIN_PREVIEW} instead, copied from `packages/ui/src/themes/*.css`; the accent is taken
+ * from the package's own table when it has one.
+ */
+import { Text, THEME_IDS, THEME_OWN_ACCENTS } from "@adelie/ui";
+import { S } from "../../lib/strings";
+import { localizedText } from "../chat/skill-use";
+import type { ImportedThemeView } from "../../state/external-themes";
+
+/** The four colours a card paints its chip with. */
+export interface ThemePreview {
+ readonly canvas: string;
+ readonly surface: string;
+ readonly fg: string;
+ readonly accent: string;
+}
+
+/** What a theme paints in each mode; the picker shows the one the page is drawn in. */
+export interface ThemePreviewPair {
+ readonly light: ThemePreview;
+ readonly dark: ThemePreview;
+}
+
+/**
+ * The shipped themes' chip colours, from `packages/ui/src/themes/*.css` (light, then dark). The
+ * accent is the package's own where {@link THEME_OWN_ACCENTS} lists it.
+ */
+const BUILTIN_PREVIEW: Readonly<Record<string, ThemePreviewPair>> = {
+ modern: {
+ light: { canvas: "#fafafa", surface: "#ffffff", fg: "#232527", accent: "#006838" },
+ dark: { canvas: "#1b1c1e", surface: "#232426", fg: "#e6e6e6", accent: "#4aa45c" },
+ },
+ github: {
+ light: { canvas: "#ffffff", surface: "#ffffff", fg: "#171717", accent: "#171717" },
+ dark: { canvas: "#0a0a0a", surface: "#1c1c1c", fg: "#ededed", accent: "#f5f5f5" },
+ },
+ geek: {
+ light: { canvas: "#fbfafa", surface: "#fbfafa", fg: "#1d1d1f", accent: "#1d1d1f" },
+ dark: { canvas: "#131010", surface: "#1a1717", fg: "#ededed", accent: "#f4f2f2" },
+ },
+};
+
+/** What a card shows: the id, the words, whether a file brought it, and its colours. */
+export interface ThemeChoice {
+ readonly id: string;
+ readonly label: string;
+ readonly imported: boolean;
+ readonly preview: ThemePreviewPair;
+}
+
+/** The chip for one mode: the canvas, a surface bar, a line of ink and the accent beside it. */
+function ThemeChip({ preview }: { preview: ThemePreview }) {
+ return (
+ <span
+ aria-hidden
+ className="block overflow-hidden rounded-[var(--ui-radius-sm)] border border-line/70"
+ style={{ background: preview.canvas, height: "2.75rem" }}
+ >
+ <span
+ className="mt-1.5 ml-1.5 block"
+ style={{
+ background: preview.surface,
+ border: `1px solid ${preview.fg}1f`,
+ borderRadius: "0.25rem",
+ height: "0.75rem",
+ }}
+ />
+ <span className="mt-1 ml-1.5 flex items-center gap-1">
+ <span
+ className="block"
+ style={{
+ background: preview.fg,
+ borderRadius: "9999px",
+ height: "0.1875rem",
+ opacity: 0.5,
+ width: "2.25rem",
+ }}
+ />
+ <span
+ className="block"
+ style={{
+ background: preview.accent,
+ borderRadius: "9999px",
+ height: "0.1875rem",
+ width: "0.75rem",
+ }}
+ />
+ </span>
+ </span>
+ );
+}
+
+function ThemeCard({
+ choice,
+ selected,
+ dark,
+ onPick,
+}: {
+ choice: ThemeChoice;
+ selected: boolean;
+ dark: boolean;
+ onPick: () => void;
+}) {
+ const preview = dark ? choice.preview.dark : choice.preview.light;
+ return (
+ <button
+ type="button"
+ role="radio"
+ aria-checked={selected}
+ onClick={onPick}
+ className={`flex flex-col gap-1.5 rounded-[var(--ui-radius-md)] border p-1.5 text-left transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring ${
+ selected
+ ? "border-accent bg-accent-muted"
+ : "border-line bg-surface hover:border-line-emphasis hover:bg-surface-muted"
+ }`}
+ style={selected ? { boxShadow: `inset 0 0 0 1px ${preview.accent}` } : undefined}
+ >
+ <ThemeChip preview={preview} />
+ <span className="flex min-w-0 items-center gap-1 px-0.5">
+ <span className={`truncate text-sm ${selected ? "text-fg-emphasis" : "text-fg"}`}>
+ {choice.label}
+ </span>
+ {selected && (
+ <span aria-hidden className="ml-auto shrink-0 text-xs text-accent">
+ ✓
+ </span>
+ )}
+ </span>
+ </button>
+ );
+}
+
+/**
+ * The grid: the shipped themes first, then the ones files brought, each group only when it has
+ * anything in it. Four across on a wide settings page, two on a narrow one; the band scrolls
+ * rather than growing the page when a folder holds a dozen themes.
+ */
+export function ThemePicker({
+ imported,
+ value,
+ onChange,
+ dark,
+ locale,
+}: {
+ /** What this installation imported, in the server's order; painted with their own colours. */
+ imported: readonly ImportedThemeView[];
+ value: string;
+ onChange: (id: string) => void;
+ dark: boolean;
+ locale: "zh" | "en";
+}) {
+ const builtin: ThemeChoice[] = THEME_IDS.map((id) => {
+ const preview = BUILTIN_PREVIEW[id] ?? BUILTIN_PREVIEW.modern!;
+ const own = THEME_OWN_ACCENTS[id];
+ return {
+ id,
+ label: S.settings.themeNames[id],
+ imported: false,
+ preview:
+ own === undefined
+ ? preview
+ : {
+ light: { ...preview.light, accent: own.light },
+ dark: { ...preview.dark, accent: own.dark },
+ },
+ };
+ });
+ const files: ThemeChoice[] = imported.map((theme) => ({
+ id: theme.id,
+ label: localizedText(locale, theme.name, theme.nameZh),
+ imported: true,
+ preview: theme.preview,
+ }));
+ // A stored id nothing provides keeps its place, so the row never quietly claims the default
+ // theme is what is chosen while the root carries something else.
+ const orphan: ThemeChoice | null =
+ builtin.some((choice) => choice.id === value) || files.some((choice) => choice.id === value)
+ ? null
+ : {
+ id: value,
+ label: value,
+ imported: true,
+ preview: builtin[0]!.preview,
+ };
+ return (
+ <div className="mt-3 flex max-h-[15rem] flex-col gap-2 overflow-y-auto pr-1">
+ <ThemeGroup
+ label={S.settings.themeBuiltin}
+ choices={builtin}
+ value={value}
+ dark={dark}
+ onChange={onChange}
+ />
+ {(files.length > 0 || orphan !== null) && (
+ <ThemeGroup
+ label={S.settings.themeImportedGroup}
+ choices={orphan === null ? files : [...files, orphan]}
+ value={value}
+ dark={dark}
+ onChange={onChange}
+ />
+ )}
+ </div>
+ );
+}
+
+function ThemeGroup({
+ label,
+ choices,
+ value,
+ dark,
+ onChange,
+}: {
+ label: string;
+ choices: readonly ThemeChoice[];
+ value: string;
+ dark: boolean;
+ onChange: (id: string) => void;
+}) {
+ return (
+ <div role="radiogroup" aria-label={label}>
+ <Text variant="eyebrow" className="mb-1">
+ {label}
+ </Text>
+ <div className="grid grid-cols-[repeat(auto-fill,minmax(7.5rem,1fr))] gap-2">
+ {choices.map((choice) => (
+ <ThemeCard
+ key={choice.id}
+ choice={choice}
+ selected={choice.id === value}
+ dark={dark}
+ onPick={() => onChange(choice.id)}
+ />
+ ))}
+ </div>
+ </div>
+ );
+}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index f7b11bd2..121a882c 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -740,12 +740,22 @@ export const en: Strings = {
themeInfo:
"The app's overall style: layout, lines, type and motion change with it; content and every other setting stay as they are.",
themeNames: { github: "Primer", modern: "Frost", geek: "Console" },
- /** The row under the theme picker: where a theme file goes, and what one got wrong. */
- importedThemesDir: (dir: string) => `Themes directory ${dir}`,
+ /**
+ * The row under the theme picker: the folder the server reads, with the "?" beside it saying
+ * which path and what a file looks like.
+ */
+ importedThemesHelp: "Themes folder",
importedThemesHint:
- "Drop a theme's .json file in this directory and reload the page: it appears in the theme list above. The format is in the repository's examples/themes/warm-paper.json. An admin can import one here as well.",
+ "Drop a theme's .json file in this folder and choose Read again: it appears in the theme list above. The format is in the repository's examples/themes/warm-paper.json. An admin can import one here as well, without walking to the folder.",
importedThemesReadAgain: "Read again",
- /** The admin's entry beside the directory line: the same install, without walking to the folder. */
+ importedThemeUnknownShort: (count: number) =>
+ `${count} token ${count === 1 ? "name" : "names"} not recognised`,
+ importedThemeMissingShort: (count: number) =>
+ `${count} token${count === 1 ? "" : "s"} keep the default`,
+ importedThemeDetails: "which ones",
+ themeBuiltin: "Built in",
+ themeImportedGroup: "Imported",
+ /** The admin's entry beside "read again": the same install, without walking to the folder. */
themeImport: "Import a theme…",
themeImportTitle: "Import a theme",
/** The dialog's source switch: the two ways a theme file reaches the server. */
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 7b69b249..2cbcad9b 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -798,12 +798,15 @@ export const zh = {
themeInfo: "应用的整体风格:布局、线条、字体与动效随之改变,内容与其他设置不受影响。",
/** Display names of the three themes; the ids stay github / modern / geek. */
themeNames: { github: "通用", modern: "白领", geek: "极客" },
- /** The row under the theme picker: where a theme file goes, and what one got wrong. */
- importedThemesDir: (dir: string) => `主题目录 ${dir}`,
+ /**
+ * The row under the theme picker: the folder the server reads, with the "?" beside it saying
+ * which path and what a file looks like.
+ */
+ importedThemesHelp: "主题目录",
importedThemesHint:
- "把主题的 .json 文件放进这个目录、刷新页面,它就会出现在上面的主题列表里;格式见仓库里的 examples/themes/warm-paper.json。管理员也可以直接导入。",
+ "把主题的 .json 文件放进这个目录,点「重新读取」它就会出现在上面的主题列表里;格式见仓库里的 examples/themes/warm-paper.json。管理员也可以直接导入,不用走到目录里。",
importedThemesReadAgain: "重新读取",
- /** The admin's entry beside the directory line: the same install, without walking to the folder. */
+ /** The admin's entry beside "read again": the same install, without walking to the folder. */
themeImport: "导入主题…",
themeImportTitle: "导入主题",
/** The dialog's source switch: the two ways a theme file reaches the server. */
@@ -839,6 +842,13 @@ export const zh = {
`${count} 个名字这边不认识(${names}),这些设置不会生效。`,
importedThemeMissing: (count: number, names: string) =>
`${count} 个令牌这个主题没写(${names}),它们沿用「通用」主题的值。`,
+ /** The same two facts as one line each, so a half-filled theme is not a wall of names. */
+ importedThemeUnknownShort: (count: number) => `${count} 个令牌名不认识`,
+ importedThemeMissingShort: (count: number) => `${count} 个令牌沿用默认值`,
+ importedThemeDetails: "看是哪些",
+ /** The picker's two groups, and the tag on a card a file brought. */
+ themeBuiltin: "内置主题",
+ themeImportedGroup: "导入主题",
importedThemeRejected: (file: string, reason: string) => `${file}:${reason}`,
colorMode: "明暗",
colorModeInfo: "应用的明暗外观。",
diff --git a/packages/web/src/state/external-themes.ts b/packages/web/src/state/external-themes.ts
index b5a8e31b..fa7d5e62 100644
--- a/packages/web/src/state/external-themes.ts
+++ b/packages/web/src/state/external-themes.ts
@@ -40,12 +40,28 @@ export interface ImportedThemeView {
readonly presets: ReadonlyArray<{ readonly id: string; readonly swatch: string }>;
/** The accent it paints when no preset is chosen, per mode (`neutral`'s swatch). */
readonly own: { readonly light: string; readonly dark: string };
+ /**
+ * The four colours the picker's chip paints, per mode: its own canvas, surface, ink and accent,
+ * each falling back to the default theme's value for the names the file leaves out.
+ */
+ readonly preview: {
+ readonly light: ThemePreviewColors;
+ readonly dark: ThemePreviewColors;
+ };
/** Token names the contract has never heard of — they paint nothing. */
readonly unknown: readonly string[];
/** Token names the file does not set — they keep the default theme's values. */
readonly missing: readonly string[];
}
+/** The colours one mode of a chip needs; see `features/settings/theme-picker.tsx`. */
+export interface ThemePreviewColors {
+ readonly canvas: string;
+ readonly surface: string;
+ readonly fg: string;
+ readonly accent: string;
+}
+
export interface ImportedThemesState {
/** The directory the server read, for the line that says where to put a file; null until read. */
readonly dir: string | null;
@@ -70,6 +86,37 @@ function publish(next: ImportedThemesState): void {
/** The default theme's own accent — what a name a theme leaves out ends up painting. */
const FALLBACK_ACCENT = THEME_OWN_ACCENTS[DEFAULT_THEME_ID];
+/**
+ * The default theme's canvas, surface and ink, for the chip of a theme that leaves those names
+ * out. Spelled here for the same reason the picker spells the shipped themes' colours: the page
+ * holds no theme's values, only the files' and this one fallback.
+ */
+const FALLBACK_PREVIEW: ThemePreviewColors = {
+ canvas: "#fafafa",
+ surface: "#ffffff",
+ fg: "#232527",
+ accent: FALLBACK_ACCENT.light,
+};
+const FALLBACK_PREVIEW_DARK: ThemePreviewColors = {
+ canvas: "#1b1c1e",
+ surface: "#232426",
+ fg: "#e6e6e6",
+ accent: FALLBACK_ACCENT.dark,
+};
+
+/** One mode's chip colours: the file's own values, filled in from the default theme. */
+function previewOf(
+ tokens: Readonly<Record<string, string>> | undefined,
+ fallback: ThemePreviewColors,
+): ThemePreviewColors {
+ return {
+ canvas: tokens?.["--ui-canvas"] ?? fallback.canvas,
+ surface: tokens?.["--ui-surface"] ?? fallback.surface,
+ fg: tokens?.["--ui-fg"] ?? fallback.fg,
+ accent: tokens?.["--ui-accent"] ?? fallback.accent,
+ };
+}
+
/** The `--ui-accent` a token map sets, or null when it does not set one at all. */
function accentOf(tokens: Readonly<Record<string, string>> | undefined): string | null {
return tokens?.["--ui-accent"] ?? null;
@@ -102,6 +149,10 @@ export function viewOfTheme(file: string, theme: ExternalTheme): ImportedThemeVi
// `neutral` is the accent the theme itself paints: its own `--ui-accent` where it sets one, and
// the default theme's where it does not (a name it leaves out keeps the default's value).
own: { light: ownLight, dark: accentOf(theme.dark) ?? FALLBACK_ACCENT.dark },
+ preview: {
+ light: previewOf(theme.light, FALLBACK_PREVIEW),
+ dark: previewOf(theme.dark, { ...FALLBACK_PREVIEW_DARK, accent: ownLight }),
+ },
unknown: [...new Set(names.filter((name) => !contract.includes(name)))],
missing: contract.filter((name) => !(name in light)),
};