包文件→ .shtukbase/packages/design-a11y/checks/a11ylib.ts
checks/a11ylib.ts
28 行, 1.3 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // Shared parts of the design-a11y checks. The working directory is the project root.
- import { blankComments } from '../../design-base/lib/markup.ts';
- import { projectFiles, read, settings } from '../../design-base/lib/files.ts';
- export const CONFIG = 'design/a11y.md';
- export const MARKUP = ['html', 'htm', 'tsx', 'jsx'];
- export function config(root = process.cwd()): { minContrast: number; pairs: [string, string][]; skip: Set<string> } {
- const fm = settings(CONFIG, root);
- const pair = (s: string): [string, string] | null => {
- const m = /^\s*(--[\w-]+)\s+(?:on)\s+(--[\w-]+)\s*$/.exec(s);
- return m ? [m[1], m[2]] : null;
- };
- const arr = (v: unknown) => (Array.isArray(v) ? v.map(String) : []);
- return {
- minContrast: Number(fm.minContrast) > 0 ? Number(fm.minContrast) : 4.5,
- pairs: arr(fm.pairs).map(pair).filter((p): p is [string, string] => !!p),
- skip: new Set(arr(fm.skipPairs).map((s) => (pair(s) ?? ['', '']).join(' '))),
- };
- }
- /** Markup files of the project with comments blanked (offsets and lines kept). */
- export function markupFiles(root = process.cwd()): { rel: string; text: string; html: boolean }[] {
- return projectFiles(MARKUP).map((rel) => {
- const html = /\.html?$/.test(rel);
- return { rel, html, text: blankComments(read(rel, root), html) };
- });
- }