From 1129b3d90c44e131d4b714fb792d4e824dfdbbe4 Mon Sep 17 00:00:00 2001 From: yibaiba <946100224@qq.com> Date: Thu, 13 Aug 2026 23:47:10 +0800 Subject: [PATCH] feat(web): establish readable typography scale Why: Migrated operations pages used ad-hoc text sizes below the design system minimum.\n\nWhy this works: Shared typography tokens encode the supported scale and a source audit helper detects sub-12px declarations as each page is migrated.\n\nRemaining: Apply the scale and browser-check each migrated route. --- web/src/style.css | 6 +++ web/tests/typographyReadabilitySource.test.ts | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 web/tests/typographyReadabilitySource.test.ts diff --git a/web/src/style.css b/web/src/style.css index 0271965b..84d5f0b2 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -26,6 +26,12 @@ --ui-success: #198754; --ui-warning: #b86a0b; --ui-danger: #c53b3b; + --ui-font-caption: 12px; + --ui-font-body-sm: 13px; + --ui-font-body: 14px; + --ui-font-title: 16px; + --ui-font-section: 20px; + --ui-font-page-title: 24px; --ui-radius-sm: 4px; --ui-radius-md: 12px; --ui-radius-lg: 16px; diff --git a/web/tests/typographyReadabilitySource.test.ts b/web/tests/typographyReadabilitySource.test.ts new file mode 100644 index 00000000..e3b732cd --- /dev/null +++ b/web/tests/typographyReadabilitySource.test.ts @@ -0,0 +1,39 @@ +import assert from 'node:assert/strict' +import { readFile } from 'node:fs/promises' +import test from 'node:test' + +const MIN_READABLE_FONT_SIZE = 12 +const globalStyles = await readFile(new URL('../src/style.css', import.meta.url), 'utf8') + +const FONT_DECLARATION_PATTERNS = [ + /font-size:\s*([0-9.]+)px/g, + /font:\s*[^;{}]*?([0-9.]+)px(?:\/[^\s;{}]+)?/g +] as const + +function findUnreadableFontSizes(source: string): number[] { + return FONT_DECLARATION_PATTERNS.flatMap((pattern) => { + return Array.from(source.matchAll(pattern), (match) => Number(match[1])) + .filter((size) => size < MIN_READABLE_FONT_SIZE) + }) +} + +test('shared typography tokens follow the production design scale', () => { + const expectedTokens = { + caption: 12, + 'body-sm': 13, + body: 14, + title: 16, + section: 20, + 'page-title': 24 + } + + for (const [name, size] of Object.entries(expectedTokens)) { + assert.match(globalStyles, new RegExp(`--ui-font-${name}:\\s*${size}px`)) + } +}) + +test('typography audit detects declarations below the readable minimum', () => { + assert.deepEqual(findUnreadableFontSizes('.metadata { font-size: 11px; }'), [11]) + assert.deepEqual(findUnreadableFontSizes('.code { font: 10px/1.4 monospace; }'), [10]) + assert.deepEqual(findUnreadableFontSizes('.body { font-size: 12px; }'), []) +})