ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/design-scales/checks/measure.ts

checks/measure.ts

31 líneas, 1.5 KB.

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

  1. // SCL-R04 sensor (not a check: always exits 0). Lists widths written in `ch` (CSS max-width/width/inline-size and
  2. // Tailwind max-w-[Nch], w-[Nch]) that fall outside the readable measure (45–75 characters, from `measure` of
  3. // /design/scales.md). A narrow ch width on a label or a cell is often meant — the judge decides; the sensor only
  4. // shows where to look.
  5. import { classes, config, cssDecls, utility } from './scaleslib.ts';
  6. const PROP = /^(max-width|width|inline-size|max-inline-size)$/;
  7. export function look(root = process.cwd()): string[] {
  8. const [lo, hi] = config(root).measure;
  9. const out: string[] = [];
  10. const ch = (at: string, what: string, v: string) => {
  11. const m = /^(\d*\.?\d+)ch$/.exec(v.trim());
  12. if (!m) return;
  13. const n = Number(m[1]);
  14. if (n > hi) out.push(`${at}: ${what} — ${n} characters per line, longer than ${hi}: for text, the line tires the reader`);
  15. else if (n < lo) out.push(`${at}: ${what} — ${n} characters per line, shorter than ${lo}: for a paragraph, the line is ragged`);
  16. };
  17. for (const d of cssDecls(root)) if (PROP.test(d.prop)) ch(d.at, `${d.prop}: ${d.value}`, d.value);
  18. for (const k of classes(root)) {
  19. const m = /^(?:max-w|w)-\[([^\]]+)\]$/.exec(utility(k.cls));
  20. if (m) ch(k.at, k.cls, m[1]);
  21. }
  22. return out;
  23. }
  24. if (import.meta.main) {
  25. const out = look();
  26. console.log(out.length ? out.join('\n') : 'no widths in ch outside 45–75');
  27. console.log('Judge: .shtukbase/packages/design-scales/judges/measure.md');
  28. }