ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/design-a11y/checks/a11ylib.ts

checks/a11ylib.ts

28 líneas, 1.3 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // Shared parts of the design-a11y checks. The working directory is the project root.
  2. import { blankComments } from '../../design-base/lib/markup.ts';
  3. import { projectFiles, read, settings } from '../../design-base/lib/files.ts';
  4. export const CONFIG = 'design/a11y.md';
  5. export const MARKUP = ['html', 'htm', 'tsx', 'jsx'];
  6. export function config(root = process.cwd()): { minContrast: number; pairs: [string, string][]; skip: Set<string> } {
  7. const fm = settings(CONFIG, root);
  8. const pair = (s: string): [string, string] | null => {
  9. const m = /^\s*(--[\w-]+)\s+(?:on)\s+(--[\w-]+)\s*$/.exec(s);
  10. return m ? [m[1], m[2]] : null;
  11. };
  12. const arr = (v: unknown) => (Array.isArray(v) ? v.map(String) : []);
  13. return {
  14. minContrast: Number(fm.minContrast) > 0 ? Number(fm.minContrast) : 4.5,
  15. pairs: arr(fm.pairs).map(pair).filter((p): p is [string, string] => !!p),
  16. skip: new Set(arr(fm.skipPairs).map((s) => (pair(s) ?? ['', '']).join(' '))),
  17. };
  18. }
  19. /** Markup files of the project with comments blanked (offsets and lines kept). */
  20. export function markupFiles(root = process.cwd()): { rel: string; text: string; html: boolean }[] {
  21. return projectFiles(MARKUP).map((rel) => {
  22. const html = /\.html?$/.test(rel);
  23. return { rel, html, text: blankComments(read(rel, root), html) };
  24. });
  25. }