iter(g242): 新增令牌对比度门禁,修掉暗色主按钮与淡底强调字不达标
This commit is contained in:
@@ -5,6 +5,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { visualAudit } from '../lib/visual-audit.mjs';
|
||||
import { auditContrast, formatReport, PAIRS } from '../lib/contrast-audit.mjs';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -1569,6 +1570,33 @@ function commitSubjects() {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/*** 对比度审计:把令牌的「文字色 × 底色」配对算成 WCAG 比值,低于阈值即退出码 1
|
||||
* --json 出机器可读明细;--list 只列配对表(看一眼设计契约,不必读代码)
|
||||
*/
|
||||
function cmdAuditContrast(args) {
|
||||
if (args.includes('--list')) {
|
||||
for (const p of PAIRS) console.log(`${p.label}:--ua-color-${p.fg} on --ua-color-${p.bg},阈值 ${p.min}`);
|
||||
return;
|
||||
}
|
||||
let result;
|
||||
try {
|
||||
result = auditContrast(ROOT);
|
||||
} catch (err) {
|
||||
console.error(`audit:contrast 失败:${err.message}`); // 求值不了就红:静默跳过会让人误以为全站达标
|
||||
process.exit(1);
|
||||
}
|
||||
if (args.includes('--json')) {
|
||||
const pairs = result.rows.map((r) => ({
|
||||
label: r.label, fg: r.fg, bg: r.bg, min: r.min,
|
||||
light: Number(r.light.toFixed(2)), dark: Number(r.dark.toFixed(2)), bad: r.bad,
|
||||
}));
|
||||
console.log(JSON.stringify({ ok: result.failures.length === 0, total: pairs.length, failing: result.failures.length, pairs }, null, 2));
|
||||
} else {
|
||||
console.log(formatReport(result));
|
||||
}
|
||||
process.exit(result.failures.length === 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
/*** 迭代留痕校验:.ua/iterations.log 每行 JSON 字段与格式必须符合 ITERATION.md 规范 ***/
|
||||
function cmdLintIterations() {
|
||||
const file = path.join(INDEX_DIR, 'iterations.log');
|
||||
@@ -1704,10 +1732,13 @@ switch (cmd) {
|
||||
case 'audit:visual':
|
||||
visualAudit(args, ROOT);
|
||||
break;
|
||||
case 'audit:contrast':
|
||||
cmdAuditContrast(args);
|
||||
break;
|
||||
case 'mcp':
|
||||
cmdMcp();
|
||||
break;
|
||||
default:
|
||||
console.log('usage: ua <index|list|search <kw>|info <name>|docs|tokens [--json]|style|sync-counts|verify|doctor|commit-lint|lint-iterations|audit:visual [--json|--baseline]|changelog|mcp>');
|
||||
console.log('usage: ua <index|list|search <kw>|info <name>|docs|tokens [--json]|style|sync-counts|verify|doctor|commit-lint|lint-iterations|audit:visual [--json|--baseline]|audit:contrast [--json|--list]|changelog|mcp>');
|
||||
process.exit(cmd ? 1 : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user