Give themes named color roles, theme data files, and file format 3
Phase 5a-1 and 5a-2. - roles.ts names 51 color roles. One derivation rule fills the roles that a theme does not give, for all themes. tokens.css keeps only the root defaults, without theme blocks. - Each built-in theme is one data file in src/lib/theme/themes/. No code outside the theme data names a theme ID. characterThemes.ts is gone. - New roles: link, focus, on-accent, highlight, scrim, the syntax roles, and 16 terminal (ANSI) roles. Stray colors in components use the roles. - contrast.ts checks each theme against the readability rules of docs/ui-color.md. The tests mark the known palette failures as todo, and a second test fails when a known failure starts to pass. - Theme files use schema 3 with a mode and an optional built-in base. A short file gets the missing colors and fonts from the base. Schema 1 and 2 files still import. Old syntax names convert on import. - Docs: ui-color.md, plugin-development.md (theme tokens), ui-design.md, guides/themes.md, and UI-041 and UI-042 in design-decisions.md. The applied colors stay the same for every built-in theme, except three small changes: the conflict line uses the warn color, the Write highlight uses the highlight role, and two dialog backdrops use the scrim role. pnpm check passes. pnpm test: 447 pass, 31 todo, 0 fail. Full smoke suite: 93 passed, 2 known. appearance/palettes read the old syntax names and passed 3 of 3 times after the fix. workspace/manageTemplates failed one time and passed on retry.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Import a custom theme JSON in Settings > Appearance; its dark and light backgrounds apply.
|
||||
// Import custom theme files in Settings > Appearance: schema 1 palettes for each mode, and a short schema 3 file with a base theme.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
@@ -15,8 +15,9 @@ await runSmoke(name, async ({ page }) => {
|
||||
await page.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
const theme = { schema: 1, id: "smoke", name: "Smoke theme", light: { bg: "#fefefe", text: "#222222", accent: "#334499" }, dark: { bg: "#181820", text: "#eeeeee", accent: "#aabbff" } };
|
||||
const importTheme = () => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(theme)) });
|
||||
const background = () => page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim());
|
||||
const importTheme = (file = theme) => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(file)) });
|
||||
const token = name => page.evaluate(name => getComputedStyle(document.documentElement).getPropertyValue(`--rs-${name}`).trim(), name);
|
||||
const background = () => token("bg");
|
||||
await importTheme();
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
|
||||
assert.equal(await background(), "#181820");
|
||||
@@ -29,5 +30,18 @@ await runSmoke(name, async ({ page }) => {
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
|
||||
assert.equal(await background(), "#fefefe");
|
||||
await page.screenshot({ path: path.join(output, "custom-theme-light.png") });
|
||||
console.log("PASS: custom theme import applies its dark and light backgrounds");
|
||||
|
||||
// A short schema 3 file takes the missing colors and fonts from its base theme. An earlier theme ID names the base.
|
||||
await importTheme({ schema: 3, id: "short", name: "Short theme", mode: "dark", base: "holo", colors: { accent: "#00c8ff" } });
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:short");
|
||||
assert.deepEqual([await background(), await token("accent"), await token("link"), await token("syntax-keyword")], ["#251b17", "#00c8ff", "#00c8ff", "#ff6740"]);
|
||||
assert.match(await token("font-ui"), /Candara/);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.dataset.theme), "dark");
|
||||
await page.screenshot({ path: path.join(output, "custom-theme-short.png") });
|
||||
|
||||
// A base without a palette in the file's mode stops the installation with an error.
|
||||
await importTheme({ schema: 3, id: "wrong", name: "Wrong base", mode: "dark", base: "sakura", colors: {} });
|
||||
await page.getByRole("alert").filter({ hasText: "Use a built-in theme with a dark palette as the base." }).waitFor();
|
||||
assert.equal(await page.evaluate(() => document.documentElement.dataset.palette), "custom:short");
|
||||
console.log("PASS: custom theme import applies schema 1 palettes, a short schema 3 file with a base, and rejects a wrong base");
|
||||
}, { timeout: 15000 });
|
||||
|
||||
Reference in New Issue
Block a user