Files
ChronicleOfTheImmortalClan/tests/contrast-readability.test.ts
T
thzxx ba9766e152 v0.1.26: 墨规清辉——MOD 规范范式 + 灾因注册表 + 页面提亮(1047 全绿)
【MOD 规范与范式(核心命题)】
- docs/MOD_GUIDE.md:完整作者守则——命名/id 规约/semver/schema:1/五数据口
  (事件/模板/词库/灾因/配方)/依赖冲突/安全红线(无脚本·禁碰 rng·不动核心时序)/
  打包分发(.cotymod 单文件)/行为承诺
- validateMod 深度校验:category/weight/境界/负成本/非空/options.eff 形状
- modPreflight 权威冲突检测:findEvent(池+动态分支 raid/渡劫/大比/传薪全量)
- MOD_SCHEMA_VERSION=1 + schema 声明与升级提示;PluginStatus.author 展示

【灾因归一化(平衡版落地)】
- calamities 由 as const 死表→聚合注册表(calamityNames/calamityFamilyOf/calamityEffectOf+addCalamity)
- WorldSim 灾签/生产/Market 全链路走聚合读口——MOD 灾因(剑灾/灵潮湍变)进入世界循环
- 默认表不变→基准世界指纹零漂(clock.test 全绿实证)

【页面可读性(有点暗)】
- .dim #6d6150→#a99c80(3.4:1→7+:1)、.dim2 #96896e→#c3b595、.help-text 提亮、
  .feed-item 显色 #efe4c9 + 灰金系 8 处提亮(styles.css 12+/11- 纯色值)
- tests/contrast-readability.test.ts:WCAG 对比度审计(≥4.5:1)+ 历史暗色迁移断言

【测试】1047 全绿(47 套件):mod-system 9(+validate/灾因/冲突/预检)、contrast 3;
【金钟罩】0.1.25 基线零漂;build 通过
2026-08-23 16:37:11 +08:00

42 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
})
})