mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-06 00:01:20 +00:00
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.
This commit is contained in:
1 parent
cf28181cbc
commit
1129b3d90c
2 files changed
+45
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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; }'), [])
|
||||
})
|
||||
Reference in new issue
Block a user