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.
139 lines
9.0 KiB
JavaScript
139 lines
9.0 KiB
JavaScript
// Character theme typography: CSS families and the fonts Chromium renders for UI, prose, headings, and code, plus narrow settings.
|
|
import assert from 'node:assert/strict';
|
|
import { writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { mockTauri, openPage, outputDir, runSmoke, settle, smokeUrl } from '../_harness/index.mjs';
|
|
|
|
await runSmoke('appearance/typography', async ({ browser }) => {
|
|
const output = await outputDir('appearance/typography');
|
|
const report = [];
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
|
await mockTauri(context, {
|
|
commands: test => ({
|
|
...test.workspace({
|
|
root: 'C:\\font-smoke',
|
|
files: { 'Typography.md': '# A place for your ideas\n\nRead the next chapter, collect clear notes, and keep your work close. Small letters, open spaces, and steady lines help each sentence stay readable.\n\n## Details worth keeping\n\nThe quick brown fox jumps over the lazy dog. Il1 O0 rn m, 0123456789.\n\n`const name = "RuneStone";`\n' },
|
|
}),
|
|
plugins_snapshot: () => ({ root: 'C:/font-smoke-plugins', plugins: [] }),
|
|
}),
|
|
});
|
|
const main = await openPage(context);
|
|
const settings = await openPage(context);
|
|
await main.goto(smokeUrl);
|
|
await main.getByText('font-smoke', { exact: true }).waitFor();
|
|
await main.keyboard.press('Control+p');
|
|
await main.getByRole('textbox', { name: 'Find a file' }).fill('Typography.md');
|
|
await main.getByRole('textbox', { name: 'Find a file' }).press('Enter');
|
|
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
|
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
|
|
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
|
|
|
const sessions = new Map();
|
|
// The CSS font of `selector` and the platform fonts Chromium used to draw its glyphs.
|
|
async function rendered(page, selector) {
|
|
await settle(page);
|
|
let session = sessions.get(page);
|
|
if (!session) {
|
|
session = await context.newCDPSession(page);
|
|
await session.send('DOM.enable'); await session.send('CSS.enable'); sessions.set(page, session);
|
|
}
|
|
const { root } = await session.send('DOM.getDocument');
|
|
const { nodeId } = await session.send('DOM.querySelector', { nodeId: root.nodeId, selector });
|
|
assert(nodeId, selector);
|
|
const { fonts } = await session.send('CSS.getPlatformFontsForNode', { nodeId });
|
|
const style = await page.locator(selector).first().evaluate(node => {
|
|
const css = getComputedStyle(node);
|
|
return { family: css.fontFamily, size: css.fontSize, weight: css.fontWeight, lineHeight: css.lineHeight };
|
|
});
|
|
return { ...style, rendered: fonts.filter(font => font.glyphCount).map(({ familyName, postScriptName, glyphCount, isCustomFont }) => ({ familyName, postScriptName, glyphCount, isCustomFont })) };
|
|
}
|
|
const setPluginTools = count => settings.evaluate(async count => {
|
|
const { pluginTools } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
|
pluginTools.set(Array.from({ length: count }, (_, index) => ({ owner: 'org.example.font-check', id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: 'settings' })));
|
|
}, count);
|
|
const selectors = { ui: '.picker[aria-label="Color theme"]', prose: '.cm-line:not(.writer-heading):not(.writer-blank)', heading: '.writer-h1' };
|
|
const cases = [
|
|
['harvest-moon', 'Harvest Moon', 'Constantia', 'Candara', 'Constantia', 'Constantia'],
|
|
['crimson-pilot', 'Crimson Pilot', 'Bahnschrift', 'Bahnschrift', 'Segoe UI', 'Bahnschrift'],
|
|
['silver-serpent', 'Silver Serpent', 'Palatino Linotype', 'Corbel', 'Palatino Linotype', 'Palatino Linotype'],
|
|
];
|
|
for (const [theme, label, oldFont, ui, prose, heading] of cases) {
|
|
await settings.setViewportSize({ width: 1100, height: 780 });
|
|
const picker = settings.locator('.picker').and(settings.getByRole('button', { name: 'Color theme', exact: true }));
|
|
await picker.click();
|
|
await settings.getByRole('menuitemradio', { name: label, exact: true }).click();
|
|
await main.waitForFunction(theme => document.documentElement.dataset.palette === theme, theme);
|
|
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).press('Control+Home');
|
|
await main.evaluate(() => { getSelection().removeAllRanges(); document.activeElement?.blur(); });
|
|
// The theme sets its fonts as inline properties of the root. Put back those values after each temporary change.
|
|
for (const page of [main, settings]) {
|
|
const saved = await page.evaluate(font => ['ui', 'prose', 'heading'].map(role => {
|
|
const value = document.documentElement.style.getPropertyValue(`--rs-font-${role}`);
|
|
document.documentElement.style.setProperty(`--rs-font-${role}`, `"${font}"`);
|
|
return value;
|
|
}), oldFont);
|
|
await page.screenshot({ path: path.join(output, `${theme}-before-${page === main ? 'document' : 'settings'}.png`) });
|
|
await page.evaluate(saved => {
|
|
['ui', 'prose', 'heading'].forEach((role, index) => document.documentElement.style.setProperty(`--rs-font-${role}`, saved[index]));
|
|
}, saved);
|
|
}
|
|
const roles = {
|
|
ui: await rendered(settings, selectors.ui),
|
|
prose: await rendered(main, selectors.prose),
|
|
heading: await rendered(main, selectors.heading),
|
|
mono: await rendered(settings, '.preview-code'),
|
|
};
|
|
for (const [role, family] of Object.entries({ ui, prose, heading })) {
|
|
assert(roles[role].family.includes(family), `${theme}: ${role} CSS family`);
|
|
assert(roles[role].rendered.some(font => font.familyName === family), `${theme}: ${role} actually renders ${family}: ${JSON.stringify(roles[role])}`);
|
|
}
|
|
assert.equal(roles.ui.size, '13px');
|
|
assert.equal(roles.prose.size, '15px');
|
|
assert(roles.mono.family.includes('Cascadia Mono'));
|
|
assert(roles.mono.rendered.some(font => font.familyName === 'Cascadia Mono'));
|
|
await settings.screenshot({ path: path.join(output, `${theme}-after-settings.png`) });
|
|
await main.screenshot({ path: path.join(output, `${theme}-after-document.png`) });
|
|
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).evaluate(node => {
|
|
node.focus();
|
|
const paragraph = [...node.querySelectorAll('.cm-line')].find(line => line.textContent.includes('Read the next chapter'));
|
|
const range = document.createRange(); range.selectNodeContents(paragraph);
|
|
const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range);
|
|
});
|
|
assert((await main.evaluate(() => getSelection().toString())).includes('Read the next chapter'));
|
|
await main.screenshot({ path: path.join(output, `${theme}-selected-prose.png`) });
|
|
await settings.setViewportSize({ width: 360, height: 480 });
|
|
const content = settings.locator('dialog .content');
|
|
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth), `${theme}: narrow overflow`);
|
|
await picker.scrollIntoViewIfNeeded(); await picker.focus(); await settings.keyboard.press('Enter');
|
|
const current = settings.getByRole('menuitemradio', { name: label, exact: true });
|
|
await current.waitFor();
|
|
assert(await current.evaluate(node => node === document.activeElement));
|
|
await settings.screenshot({ path: path.join(output, `${theme}-narrow-menu.png`) });
|
|
await settings.keyboard.press('Escape');
|
|
assert(await picker.evaluate(node => node === document.activeElement));
|
|
await setPluginTools(16);
|
|
const bodyBounds = await settings.locator('dialog .body').boundingBox();
|
|
assert((await settings.locator('dialog aside').boundingBox()).height <= bodyBounds.height * .4 + 1);
|
|
await settings.getByRole('button', { name: 'Plugin settings 16', exact: true }).scrollIntoViewIfNeeded();
|
|
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth));
|
|
await settings.screenshot({ path: path.join(output, `${theme}-narrow-long-plugins.png`) });
|
|
await setPluginTools(0);
|
|
// Drop the first family from each stack and check that the fallback still renders glyphs.
|
|
const fallback = {};
|
|
for (const [role, page] of [['ui', settings], ['prose', main], ['heading', main]]) {
|
|
const stack = await page.evaluate(role => {
|
|
const stack = getComputedStyle(document.documentElement).getPropertyValue(`--rs-font-${role}`);
|
|
document.documentElement.style.setProperty(`--rs-font-${role}`, stack.slice(stack.indexOf(',') + 1));
|
|
return stack;
|
|
}, role);
|
|
fallback[role] = await rendered(page, selectors[role]);
|
|
assert(fallback[role].rendered.length > 0);
|
|
await page.evaluate(([role, stack]) => document.documentElement.style.setProperty(`--rs-font-${role}`, stack), [role, stack]);
|
|
}
|
|
report.push({ theme, oldFont, roles, fallback });
|
|
console.log(`PASS ${theme}: real UI and prose sizes, rendered fonts, shared monospace, selection, narrow settings, keyboard focus, long plugin navigation`);
|
|
}
|
|
assert.deepEqual([...main.errors, ...settings.errors], []);
|
|
await writeFile(path.join(output, 'rendered-fonts.json'), JSON.stringify(report, null, 2));
|
|
});
|