import { describe, expect, it } from 'vitest' /** WCAG 相对亮度与对比度(纯函数审计) */ function luminance(hex: string): number { const m = hex.replace('#', '') const [r, g, b] = [0, 2, 4].map((i) => parseInt(m.slice(i, i + 2), 16) / 255) const lin = (c: number) => (c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4)) return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b) } function contrast(a: string, b: string): number { const la = luminance(a), lb = luminance(b) const [hi, lo] = la > lb ? [la, lb] : [lb, la] return (hi + 0.05) / (lo + 0.05) } describe('0.1.26 页面可读性(对比度审计)', () => { const BG = '#100d0a' it('次级文本 (dim/dim2/help-text) 对比度 ≥ 4.5:1', () => { const cases: Array<[string, string]> = [ ['#a99c80', '.dim'], ['#c3b595', '.dim2'], ['#c9b894', '.help-text'], ['#efe4c9', '.feed-item'], ['#e2d3b4', '.tag 文字'] as never ] for (const [hex, label] of cases) { const c = contrast(hex, BG) expect(c, `${label} 对比 ${c.toFixed(2)}`).toBeGreaterThanOrEqual(4.5) } }) it('主文本 paper 对比充足(≥8:1)', () => { expect(contrast('#f2e9d4', BG)).toBeGreaterThanOrEqual(8) }) it('历史暗色 #6d6150 不再被引用(提亮迁移核对)', () => { const css = require('fs').readFileSync('src/renderer/ui/styles.css', 'utf-8') expect(css.includes('#6d6150')).toBe(false) expect(css.includes('#96896e')).toBe(false) }) })