- 新增 e2e/tsconfig.json + `npm run type-check:e2e`(并入 test:all)。 本轮实测证据:teardown 补丁里第二个 `const revalidateSecret` 与既有声明重名, `npm run type-check` 全程 EXIT=0,只有 `playwright test --list` 才报重复声明 —— 现在静态期就能抓。读数:type-check:e2e EXIT=0。 - .husky/pre-commit 的索引模式改回 100755(本轮每次提交都在打 "was ignored because it's not set as executable",即 lint-staged 在任何克隆里都不执行)。 验证看 `git ls-files -s .husky` 的 mode,不是看文件系统权限。 - axe 证据落盘改为按运行轮次分目录(原写死 docs/acceptance/2026-09-21-axe/axe-evidence.json, 于是每跑一次就覆盖一次历史:0157b1c9 里那 409 行 diff 就是这么产生的), 并补 check:axe:selftest;判定逻辑与退出码三档语义未动。 - 顺带修一处仪器级缺陷:package.json 里 `type-check:e2e` 被写了两遍 —— JSON 重复键是后者静默覆盖前者,不会报错也不会判红,正是本仓反复吃的"重复声明"类。 现取键数与值由 node 回读校验。
82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import type { Page } from '@playwright/test';
|
||
|
||
/**
|
||
* 移动端触摸目标扫描(验收 R-4 / E2E 归零)。
|
||
*
|
||
* 标准出处(两条独立信源):
|
||
* · WCAG 2.2 SC 2.5.8 Target Size (Minimum) —— Level AA,24×24 CSS px,
|
||
* 例外:Equivalent / Inline / User Agent Control / Essential / Spacing。
|
||
* · WCAG 2.1 SC 2.5.5 Target Size (Enhanced) —— Level AAA,44×44 CSS px。
|
||
* 旧断言把 44px 写成「WCAG 2.1 AA」是标准错配:44px 属 AAA,AA 档没有触摸目标条款。
|
||
* 因此这里以 AA(24px) 为硬门禁、AAA(44px) 为 advisory 清单供设计侧跟踪。
|
||
*/
|
||
|
||
export interface TouchTarget {
|
||
tag: string;
|
||
text: string;
|
||
width: number;
|
||
height: number;
|
||
}
|
||
|
||
export interface TouchTargetReport {
|
||
/** 违反 AA 2.5.8(<24×24)的目标,硬门禁应为 0 */
|
||
aaViolations: TouchTarget[];
|
||
/** 未达 AAA 2.5.5(<44×44)的目标,仅作跟踪日志 */
|
||
aaaShortlist: TouchTarget[];
|
||
}
|
||
|
||
const AA_MIN_PX = 24;
|
||
const AAA_MIN_PX = 44;
|
||
|
||
export async function scanTouchTargets(page: Page): Promise<TouchTargetReport> {
|
||
// 传对象而不是数组:数组解构的下标在 noUncheckedIndexedAccess 下类型是 number | undefined
|
||
// (下面 :62/:64 的 `aaMin`/`aaaMin` 比较各报两条 TS18048),对象解构能直接推出 number。
|
||
// evaluate 的参数走结构化克隆,数组改对象不改变运行时行为,两个阈值仍是 24/44。
|
||
return page.evaluate(({ aaMin, aaaMin }) => {
|
||
const nodes = document.querySelectorAll<HTMLElement>(
|
||
'a, button, input, select, textarea, [role="button"], [tabindex]:not([tabindex="-1"])'
|
||
);
|
||
const aaViolations: TouchTarget[] = [];
|
||
const aaaShortlist: TouchTarget[] = [];
|
||
|
||
nodes.forEach((el) => {
|
||
const rect = el.getBoundingClientRect();
|
||
const style = window.getComputedStyle(el);
|
||
const rendered =
|
||
rect.width > 0 &&
|
||
rect.height > 0 &&
|
||
rect.right > 0 &&
|
||
rect.bottom > 0 &&
|
||
rect.left < window.innerWidth &&
|
||
style.display !== 'none' &&
|
||
style.visibility !== 'hidden' &&
|
||
!el.hasAttribute('hidden');
|
||
if (!rendered) {return;}
|
||
|
||
// Inline 例外(2.5.8):段落/列表/标题内的行内链接不按独立目标计量。
|
||
if (el.closest('p, li, h1, h2, h3, h4, h5, h6') && style.display === 'inline') {return;}
|
||
|
||
const entry: TouchTarget = {
|
||
tag: el.tagName,
|
||
text: (el.textContent || '').trim().slice(0, 30) || el.tagName,
|
||
width: Math.round(rect.width),
|
||
height: Math.round(rect.height),
|
||
};
|
||
if (rect.width < aaMin || rect.height < aaMin) {
|
||
aaViolations.push(entry);
|
||
} else if (rect.width < aaaMin || rect.height < aaaMin) {
|
||
aaaShortlist.push(entry);
|
||
}
|
||
});
|
||
|
||
return { aaViolations, aaaShortlist };
|
||
}, { aaMin: AA_MIN_PX, aaaMin: AAA_MIN_PX });
|
||
}
|
||
|
||
export function formatTargets(targets: TouchTarget[]): string {
|
||
return targets
|
||
.slice(0, 12)
|
||
.map((t) => ` <${t.tag}> "${t.text}" — ${t.width}x${t.height}px`)
|
||
.join('\n');
|
||
}
|