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,7 +1,14 @@
|
||||
// Character palettes: WCAG contrast of text and syntax colors on opaque and image-tinted surfaces, plus per-theme palette rules.
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { characterTheme, characterSyntax, SYNTAX_ROLES } from '../../../src/lib/theme/characterThemes.ts';
|
||||
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
||||
import { SYNTAX_ROLES, resolveColors } from '../../../src/lib/theme/roles.ts';
|
||||
|
||||
/** Every role of a dark character palette, with the derived roles. */
|
||||
function characterTheme(theme: string) {
|
||||
const palette = BUILTIN_THEMES.find(item => item.id === theme);
|
||||
return palette && 'dark' in palette.variants ? resolveColors(palette.variants.dark, 'dark') : undefined;
|
||||
}
|
||||
|
||||
const rgb = (color: string) => color.slice(1).match(/../g)!.map(value => parseInt(value, 16));
|
||||
const mix = (foreground: string, background: string, opacity: number) => '#' + rgb(foreground)
|
||||
@@ -19,13 +26,13 @@ function contrast(foreground: string, background: string) {
|
||||
/** Named foreground groups and surfaces of a palette. Image surfaces are tinted over a white image. */
|
||||
function roles(theme: string) {
|
||||
const palette = characterTheme(theme)!;
|
||||
const [bg, elevated, active, , dim, text, strong, accent, selection] = palette.surfaces;
|
||||
const { bg, 'bg-elevated': elevated, 'bg-active': active, 'text-dim': dim, text, 'text-strong': strong, accent, selection } = palette;
|
||||
const editorOnWhite = mix(bg, '#ffffff', 0.9);
|
||||
const panelOnWhite = mix(elevated, '#ffffff', 0.82);
|
||||
const foregrounds = {
|
||||
ui: { dim, text, strong },
|
||||
accents: { accent, secondary: palette.secondary },
|
||||
syntax: Object.fromEntries(SYNTAX_ROLES.map((role, index) => [`syntax-${role}`, palette.syntax[index]])),
|
||||
accents: { accent, secondary: palette['accent-2'] },
|
||||
syntax: Object.fromEntries(SYNTAX_ROLES.map(role => [`syntax-${role}`, palette[`syntax-${role}`]])),
|
||||
};
|
||||
const surfaces = {
|
||||
bg, elevated, active, selection, editorOnWhite, panelOnWhite,
|
||||
@@ -69,14 +76,14 @@ for (const { theme, name, checks } of readable) {
|
||||
|
||||
test('Harvest Moon uses the warm character colors for all palette roles', () => {
|
||||
const palette = characterTheme('harvest-moon')!;
|
||||
for (const color of [...palette.surfaces, palette.secondary, ...palette.syntax]) {
|
||||
const identity = ['bg', 'bg-elevated', 'bg-active', 'border', 'text', 'text-dim', 'text-strong', 'accent', 'accent-2', 'selection', ...SYNTAX_ROLES.map(role => `syntax-${role}` as const)] as const;
|
||||
for (const role of identity) {
|
||||
const color = palette[role];
|
||||
assert.match(color, /^#[0-9a-f]{6}$/i);
|
||||
const [red, green, blue] = rgb(color);
|
||||
assert(red >= green && green >= blue, `${color} must follow the copper, amber, red, or cream palette`);
|
||||
assert(red >= green && green >= blue, `${role} ${color} must follow the copper, amber, red, or cream palette`);
|
||||
}
|
||||
assert.equal(palette.mode, 'dark');
|
||||
assert.equal(Object.keys(characterSyntax('harvest-moon')).length, SYNTAX_ROLES.length);
|
||||
assert.deepEqual(characterSyntax('unknown'), {});
|
||||
assert.deepEqual(Object.keys(BUILTIN_THEMES.find(item => item.id === 'harvest-moon')!.variants), ['dark']);
|
||||
});
|
||||
|
||||
test('Silver Serpent selection has a readable perimeter and a separate fill', () => {
|
||||
|
||||
Reference in New Issue
Block a user