Add the theme editor tab and theme preview cards
Phase 5a-5. - Settings → Appearance shows a preview card for each theme. The cards are one radio group. The arrow keys move and select, and the current card has the selection outline and a check mark (UI-047). - Edit theme opens the theme editor as a workbench tab in the window that opened Settings. The window shows each change at once. - The editor shows all 51 color roles in seven groups. Each role has a color picker, a hex field, its lowest readability result, and a reset button. A failure shows a warning icon and its ratio, or "Too close". - Save writes a short schema 3 theme with the built-in theme as its base. A built-in theme does not change. Discard returns to the saved colors, and Duplicate saves a copy. - The editor is a built-in package, like the browser, so it uses the editor tab code of plugins. - 23 new catalog rows with French, Japanese, and Simplified Chinese. - The smoke harness sends emit to every page and emit_to to the pages with the target window label. - Docs: UI-047, ui-design.md, and "Edit a theme" in guides/themes.md. New tests: appearance/themeEditor and tests/unit/theme/themeEditor.spec.ts. Six smoke tests use the cards instead of the theme menu.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// The theme editor model (src/lib/theme/themeEditor.ts): role groups, drafts, saved files, and the results of each role.
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { ROLE_GROUPS, builtinDraft, customDraft, draftColors, draftFindings, draftTheme, roleStatus, uniqueThemeId } from '../../../src/lib/theme/themeEditor.ts';
|
||||
import { ROLES, resolveColors } from '../../../src/lib/theme/roles.ts';
|
||||
import { parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
||||
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
||||
|
||||
test('The editor groups show every role once', () => {
|
||||
const shown = ROLE_GROUPS.flatMap(group => group.roles);
|
||||
assert.equal(new Set(shown).size, shown.length);
|
||||
assert.deepEqual([...shown].sort(), [...ROLES].sort());
|
||||
});
|
||||
|
||||
test('A built-in draft has the colors of its theme', () => {
|
||||
for (const theme of BUILTIN_THEMES) for (const [mode, colors] of Object.entries(theme.variants)) {
|
||||
const draft = builtinDraft(theme.id, mode as 'light' | 'dark', theme.name);
|
||||
assert.deepEqual(draftColors(draft), resolveColors(colors!, mode as 'light' | 'dark'));
|
||||
}
|
||||
});
|
||||
|
||||
test('A saved draft is a short schema 3 theme that the parser accepts and that keeps its colors', () => {
|
||||
const draft = { ...builtinDraft('harvest-moon', 'dark', 'Harvest Moon copy'), overrides: { accent: '#00c8ff', selection: '#20406080' } };
|
||||
const theme = draftTheme(draft, 'harvest-moon-copy', 'Harvest Moon copy');
|
||||
assert.deepEqual(theme, { schema: 3, id: 'harvest-moon-copy', name: 'Harvest Moon copy', mode: 'dark', base: 'harvest-moon', colors: { accent: '#00c8ff', selection: '#20406080' } });
|
||||
const parsed = parseCustomTheme(theme);
|
||||
assert.deepEqual(draftColors(customDraft(parsed)), draftColors(draft));
|
||||
});
|
||||
|
||||
test('Theme IDs from names are valid and unique', () => {
|
||||
assert.equal(uniqueThemeId('RuneStone Dark copy', []), 'runestone-dark-copy');
|
||||
assert.equal(uniqueThemeId('RuneStone Dark copy', ['runestone-dark-copy', 'runestone-dark-copy-2']), 'runestone-dark-copy-3');
|
||||
assert.equal(uniqueThemeId('2026 theme', []), 't-2026-theme');
|
||||
assert.equal(uniqueThemeId('桜', []), 'theme');
|
||||
for (const name of ['RuneStone Dark copy', '2026 theme', '桜', 'x'.repeat(100), '--Ünïcode--']) assert.match(uniqueThemeId(name, []), /^[a-z][a-z0-9-]{0,63}$/);
|
||||
});
|
||||
|
||||
test('A role shows the results where it is the color, the surface, or one of a pair', () => {
|
||||
const draft = { ...builtinDraft('default', 'dark', 'Test'), overrides: { 'text-dim': '#3a3a3a', ok: '#55dcf5' } };
|
||||
const findings = draftFindings(draft);
|
||||
const dim = roleStatus('text-dim', findings);
|
||||
assert(dim.failures.length > 0 && dim.failures.every(finding => finding.subject.startsWith('text-dim on ')));
|
||||
assert(dim.lowest && dim.lowest.value < 4.5);
|
||||
assert(roleStatus('bg', findings).failures.some(finding => finding.subject === 'text-dim on bg'), 'A surface shows the text that fails on it');
|
||||
assert(roleStatus('ok', findings).failures.some(finding => finding.subject === 'accent and ok'), 'A status color shows a pair that is too close');
|
||||
assert.deepEqual(roleStatus('syntax-keyword', findings).failures, []);
|
||||
});
|
||||
Reference in New Issue
Block a user