@uselazuli/cli 0.0.0-stage → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/LICENSE +21 -0
- package/README.md +202 -2
- package/agents/lazuli-design-reviewer.md +30 -0
- package/agents/lazuli-first-look.md +22 -0
- package/agents/lazuli-task-tester.md +25 -0
- package/bin/lazuli.mjs +747 -0
- package/package.json +11 -4
- package/rules/accessibility/HYPOTHESES.md +8 -0
- package/rules/accessibility/_area.yaml +7 -0
- package/rules/accessibility/operable.yaml +100 -0
- package/rules/accessibility/perceivable.yaml +153 -0
- package/rules/accessibility/robust.yaml +24 -0
- package/rules/accessibility/understandable.yaml +72 -0
- package/rules/color/HYPOTHESES.md +27 -0
- package/rules/color/_area.yaml +10 -0
- package/rules/color/adapt.yaml +183 -0
- package/rules/color/create.yaml +259 -0
- package/rules/color/review.yaml +215 -0
- package/rules/color/signal.yaml +196 -0
- package/rules/content/HYPOTHESES.md +19 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +378 -0
- package/rules/content/voice.yaml +144 -0
- package/rules/content/writing.yaml +202 -0
- package/rules/data/HYPOTHESES.md +11 -0
- package/rules/data/_area.yaml +7 -0
- package/rules/data/charts.yaml +189 -0
- package/rules/data/dashboards.yaml +141 -0
- package/rules/data/review.yaml +159 -0
- package/rules/graphic/HYPOTHESES.md +18 -0
- package/rules/graphic/_area.yaml +8 -0
- package/rules/graphic/identity.yaml +141 -0
- package/rules/graphic/pieces.yaml +164 -0
- package/rules/graphic/review.yaml +271 -0
- package/rules/graphic/symbol.yaml +141 -0
- package/rules/motion/HYPOTHESES.md +19 -0
- package/rules/motion/_area.yaml +7 -0
- package/rules/motion/micro.yaml +143 -0
- package/rules/motion/review.yaml +347 -0
- package/rules/motion/transitions.yaml +169 -0
- package/rules/typography/HYPOTHESES.md +12 -0
- package/rules/typography/_area.yaml +8 -0
- package/rules/typography/adapt.yaml +45 -0
- package/rules/typography/create.yaml +126 -0
- package/rules/typography/review.yaml +127 -0
- package/rules/ui/HYPOTHESES.md +23 -0
- package/rules/ui/_area.yaml +9 -0
- package/rules/ui/compose.yaml +246 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +400 -0
- package/rules/ui/states.yaml +257 -0
- package/rules/ux/HYPOTHESES.md +13 -0
- package/rules/ux/_area.yaml +8 -0
- package/rules/ux/flows.yaml +164 -0
- package/rules/ux/forms.yaml +142 -0
- package/rules/ux/review.yaml +186 -0
- package/skills/lazuli/SKILL.md +183 -0
- package/skills/lazuli/procedures/create.md +29 -0
- package/skills/lazuli/procedures/explain-decisions.md +22 -0
- package/skills/lazuli/procedures/improve.md +30 -0
- package/skills/lazuli/procedures/remember-this.md +41 -0
- package/skills/lazuli/procedures/review-design.md +36 -0
- package/skills/lazuli/procedures/show-options.md +33 -0
- package/skills/lazuli-accessibility-check/SKILL.md +68 -0
- package/skills/lazuli-color-context-and-culture/SKILL.md +53 -0
- package/skills/lazuli-color-context-and-culture/references/sectors.md +26 -0
- package/skills/lazuli-color-palette-by-intent/SKILL.md +54 -0
- package/skills/lazuli-color-palette-by-intent/references/intent-chords.md +51 -0
- package/skills/lazuli-color-screen-review/SKILL.md +51 -0
- package/skills/lazuli-color-states-and-signals/SKILL.md +53 -0
- package/skills/lazuli-content-interface-writing/SKILL.md +53 -0
- package/skills/lazuli-content-voice/SKILL.md +40 -0
- package/skills/lazuli-data-charts-and-dashboards/SKILL.md +59 -0
- package/skills/lazuli-graphic-derived-pieces/SKILL.md +40 -0
- package/skills/lazuli-graphic-derived-pieces/references/piece-template.html +24 -0
- package/skills/lazuli-graphic-identity/SKILL.md +45 -0
- package/skills/lazuli-motion-micro-and-transitions/SKILL.md +49 -0
- package/skills/lazuli-typography-choose-and-pair/SKILL.md +50 -0
- package/skills/lazuli-typography-screen-review/SKILL.md +51 -0
- package/skills/lazuli-ui-composition/SKILL.md +42 -0
- package/skills/lazuli-ui-composition/references/option-template.html +34 -0
- package/skills/lazuli-ui-layout-review/SKILL.md +47 -0
- package/skills/lazuli-ui-states-and-system/SKILL.md +54 -0
- package/skills/lazuli-ux-flows-and-forms/SKILL.md +51 -0
- package/skills/lazuli-ux-task-test/SKILL.md +44 -0
- package/src/browser.mjs +162 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +463 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +160 -0
- package/src/commands/draft-memo.mjs +162 -0
- package/src/commands/hooks.mjs +345 -0
- package/src/commands/install-hooks.mjs +120 -0
- package/src/commands/install.mjs +132 -0
- package/src/commands/list-rules.mjs +49 -0
- package/src/commands/map-page.mjs +594 -0
- package/src/commands/record-answers.mjs +79 -0
- package/src/commands/record-log.mjs +325 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +227 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +391 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +566 -0
- package/src/measure/chart-read.mjs +401 -0
- package/src/measure/chart.mjs +264 -0
- package/src/measure/coherence.mjs +145 -0
- package/src/measure/color.mjs +86 -0
- package/src/measure/content.mjs +82 -0
- package/src/measure/cvd.mjs +24 -0
- package/src/measure/extreme.mjs +241 -0
- package/src/measure/forms.mjs +150 -0
- package/src/measure/in-page/a11y.js +522 -0
- package/src/measure/in-page/color.js +348 -0
- package/src/measure/in-page/composition.js +1496 -0
- package/src/measure/in-page/contrast.js +15 -0
- package/src/measure/in-page/cvd.js +173 -0
- package/src/measure/in-page/extreme.js +377 -0
- package/src/measure/in-page/frames.js +781 -0
- package/src/measure/in-page/look.js +28 -0
- package/src/measure/in-page/motion-probe.js +171 -0
- package/src/measure/in-page/style.js +107 -0
- package/src/measure/in-page/svg-strokes.js +112 -0
- package/src/measure/in-page/svg-uses.js +50 -0
- package/src/measure/in-page/symbol.js +123 -0
- package/src/measure/in-page/type.js +269 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +100 -0
- package/src/measure/motion.mjs +509 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +253 -0
- package/src/measure/rhythm.mjs +81 -0
- package/src/measure/signature.mjs +65 -0
- package/src/measure/states.mjs +240 -0
- package/src/measure/style.mjs +13 -0
- package/src/measure/symbol.mjs +268 -0
- package/src/measure/terms.mjs +153 -0
- package/src/measure/tiles.mjs +20 -0
- package/src/measure/timeline.mjs +621 -0
- package/src/measure/type.mjs +167 -0
- package/src/measure/weight.mjs +18 -0
- package/src/private-strings.mjs +81 -0
- package/src/project/blind.mjs +70 -0
- package/src/project/edits.mjs +154 -0
- package/src/project/gate.mjs +168 -0
- package/src/project/lazuli-md.mjs +521 -0
- package/src/project/log.mjs +335 -0
- package/src/project/match.mjs +200 -0
- package/src/project/records.mjs +380 -0
- package/src/project/tasks.mjs +153 -0
- package/src/report/evaluate.mjs +27 -0
- package/src/report/evaluators/a11y.mjs +227 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +133 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +87 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +103 -0
- package/src/report/evaluators/motion.mjs +280 -0
- package/src/report/evaluators/piece.mjs +69 -0
- package/src/report/evaluators/rhythm.mjs +99 -0
- package/src/report/evaluators/states.mjs +39 -0
- package/src/report/evaluators/style.mjs +35 -0
- package/src/report/evaluators/symbol.mjs +110 -0
- package/src/report/evaluators/terms.mjs +49 -0
- package/src/report/evaluators/type.mjs +166 -0
- package/src/report/evaluators/weight.mjs +51 -0
- package/src/report/evidence.mjs +4 -0
- package/src/report/finding.mjs +11 -0
- package/src/report/format.mjs +215 -0
- package/src/rules/hypotheses.mjs +28 -0
- package/src/rules/load.mjs +274 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +220 -0
- package/templates/LAZULI.md +88 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { normalizePhrase } from "../../measure/a11y.mjs";
|
|
4
|
+
|
|
5
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
6
|
+
const buttonsWord = (n) => plural(n, "button", "buttons");
|
|
7
|
+
const phrasesOf = (rule) =>
|
|
8
|
+
Array.isArray(rule.threshold?.phrases) ? rule.threshold.phrases.map((p) => normalizePhrase(String(p))).filter(Boolean) : [];
|
|
9
|
+
// What was not compared is noted by the measurer (no error message); the evaluators then return null, never a
|
|
10
|
+
// vacuous pass.
|
|
11
|
+
|
|
12
|
+
function genericLabels(rule, m) {
|
|
13
|
+
const buttons = m.content?.buttons;
|
|
14
|
+
if (!Array.isArray(buttons) || buttons.length === 0) return null;
|
|
15
|
+
const phrases = phrasesOf(rule);
|
|
16
|
+
const n = buttons.length;
|
|
17
|
+
const generic = buttons.filter((b) => phrases.includes(normalizePhrase(b.name)));
|
|
18
|
+
if (generic.length) {
|
|
19
|
+
const k = generic.length;
|
|
20
|
+
return makeFinding(
|
|
21
|
+
rule,
|
|
22
|
+
m.width,
|
|
23
|
+
"hint",
|
|
24
|
+
`${k} ${plural(k, "button is", "buttons are")} named only by a generic word: ${generic.map((b) => `"${b.name}"`).join(", ")}.`,
|
|
25
|
+
listed(generic.map((b) => `"${b.name}" (${b.selector})`)),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return makeFinding(rule, m.width, "pass", `None of the ${n} ${buttonsWord(n)} is named only by a generic word.`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function labelLength(rule, m) {
|
|
32
|
+
const buttons = m.content?.buttons;
|
|
33
|
+
if (!Array.isArray(buttons) || buttons.length === 0) return null;
|
|
34
|
+
const max = rule.threshold?.maxWords;
|
|
35
|
+
const n = buttons.length;
|
|
36
|
+
const long = buttons.filter((b) => b.words > max);
|
|
37
|
+
if (long.length) {
|
|
38
|
+
const k = long.length;
|
|
39
|
+
return makeFinding(
|
|
40
|
+
rule,
|
|
41
|
+
m.width,
|
|
42
|
+
"hint",
|
|
43
|
+
`${k} ${plural(k, "button uses", "buttons use")} more than ${max} words.`,
|
|
44
|
+
listed(long.map((b) => `"${b.name}" (${b.selector}): ${b.words} words`)),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return makeFinding(rule, m.width, "pass", `Each of the ${n} ${buttonsWord(n)} uses ${max} words or fewer.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function labelCase(rule, m) {
|
|
51
|
+
const styled = (m.content?.buttons ?? []).filter((b) => b.style !== null);
|
|
52
|
+
if (styled.length < 2) return null;
|
|
53
|
+
// Styles in order of first appearance in document order.
|
|
54
|
+
const styles = new Map();
|
|
55
|
+
for (const b of styled) {
|
|
56
|
+
if (!styles.has(b.style)) styles.set(b.style, { count: 0, first: b });
|
|
57
|
+
styles.get(b.style).count += 1;
|
|
58
|
+
}
|
|
59
|
+
if (styles.size > 1) {
|
|
60
|
+
const list = [...styles];
|
|
61
|
+
return makeFinding(
|
|
62
|
+
rule,
|
|
63
|
+
m.width,
|
|
64
|
+
"hint",
|
|
65
|
+
`Buttons mix ${list.length} capitalization styles: ${list.map(([s, v]) => `${s} (${v.count})`).join(", ")}.`,
|
|
66
|
+
listed(list.map(([s, v]) => `${s}: "${v.first.name}"`)),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const n = styled.length;
|
|
70
|
+
return makeFinding(rule, m.width, "pass", `The ${n} ${buttonsWord(n)} with a readable style share one: ${styled[0].style}.`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// A code alone: no lowercase letter and at least one digit ("ERR_422", "500").
|
|
74
|
+
const codeAlone = (text) => !/\p{Ll}/u.test(text) && /\p{N}/u.test(text);
|
|
75
|
+
|
|
76
|
+
function errors(rule, m) {
|
|
77
|
+
const list = m.content?.errors;
|
|
78
|
+
if (!Array.isArray(list) || list.length === 0) return null;
|
|
79
|
+
const phrases = phrasesOf(rule);
|
|
80
|
+
const short = [];
|
|
81
|
+
for (const e of list) {
|
|
82
|
+
const reasons = [];
|
|
83
|
+
if (phrases.includes(normalizePhrase(e.text))) reasons.push("a generic phrase");
|
|
84
|
+
if (codeAlone(e.text)) reasons.push("a code alone");
|
|
85
|
+
if (e.field !== null && e.namesField === false) reasons.push("does not name its field");
|
|
86
|
+
if (reasons.length) short.push({ e, reasons });
|
|
87
|
+
}
|
|
88
|
+
const n = list.length;
|
|
89
|
+
if (short.length) {
|
|
90
|
+
const where = (e) => (e.field === null ? "an alert" : `the "${e.field}" field`);
|
|
91
|
+
return makeFinding(
|
|
92
|
+
rule,
|
|
93
|
+
m.width,
|
|
94
|
+
"hint",
|
|
95
|
+
`${short.length} of ${n} error ${plural(n, "message says", "messages say")} too little to act on.`,
|
|
96
|
+
listed(short.map(({ e, reasons }) => `"${e.text}" on ${where(e)} (${e.selector}): ${reasons.join(", ")}`)),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return makeFinding(
|
|
100
|
+
rule,
|
|
101
|
+
m.width,
|
|
102
|
+
"pass",
|
|
103
|
+
`None of the ${n} error ${plural(n, "message is", "messages is")} a generic phrase or a code alone, and each one tied to a field names it.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const contentEvaluators = {
|
|
108
|
+
"content.generic-labels": genericLabels,
|
|
109
|
+
"content.label-length": labelLength,
|
|
110
|
+
"content.label-case": labelCase,
|
|
111
|
+
"content.errors": errors,
|
|
112
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { caseWords } from "../../measure/extreme.mjs";
|
|
4
|
+
|
|
5
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
6
|
+
const cutHow = { ellipsis: "cut with an ellipsis", clamped: "clamped" };
|
|
7
|
+
// A case that did not run, failed or was not compared is noted by the measurer; the evaluators then return
|
|
8
|
+
// null, never a vacuous pass.
|
|
9
|
+
|
|
10
|
+
// What the case adds, grouped by element in first-seen order (spills, cut, cut away, overlaps, past the right
|
|
11
|
+
// edge): one entry per element with the ways it breaks.
|
|
12
|
+
function byElement(b) {
|
|
13
|
+
const els = new Map();
|
|
14
|
+
const add = (t, how) => {
|
|
15
|
+
const key = t.id ?? `${t.selector} ${t.text}`;
|
|
16
|
+
const e = els.get(key) ?? { selector: t.selector, text: t.text, bleedsAtRest: t.bleedsAtRest === true, how: [] };
|
|
17
|
+
if (!e.how.includes(how)) e.how.push(how);
|
|
18
|
+
els.set(key, e);
|
|
19
|
+
};
|
|
20
|
+
for (const t of b.spills ?? []) add(t, "spills");
|
|
21
|
+
for (const t of b.cut ?? []) add(t, cutHow[t.cut] ?? "cut");
|
|
22
|
+
for (const t of b.lost ?? []) add(t, "cut away");
|
|
23
|
+
for (const [a, x] of b.overlaps ?? []) {
|
|
24
|
+
add(a, `overlaps "${x.text}"`);
|
|
25
|
+
add(x, `overlaps "${a.text}"`);
|
|
26
|
+
}
|
|
27
|
+
for (const t of b.wide ?? []) add(t, "runs past the right edge");
|
|
28
|
+
return [...els.values()];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// UC1 read through CR7 and CR8: the move holds when every element the case names already bleeds at rest and
|
|
32
|
+
// the sideways scroll or the text past a clipped right edge, if any, is named by an element past the right edge. A page where no text bleeds at rest
|
|
33
|
+
// does not show the move: no reading.
|
|
34
|
+
function bleedMove(b, els) {
|
|
35
|
+
if (!Number.isFinite(b.restBleeds) || b.restBleeds === 0) return null;
|
|
36
|
+
if (!(b.wide?.length > 0)) {
|
|
37
|
+
if (Number.isFinite(b.overflowX) && b.overflowX > 0) return { holds: false, detail: "no element was named for the sideways scroll" };
|
|
38
|
+
if (Number.isFinite(b.clippedX) && b.clippedX > 0) return { holds: false, detail: "no element was named for the text past the clipped right edge" };
|
|
39
|
+
}
|
|
40
|
+
const selectors = (list) => [...new Set(list.map((e) => e.selector))].join(", ");
|
|
41
|
+
const off = els.filter((e) => !e.bleedsAtRest);
|
|
42
|
+
if (off.length === 0) return { holds: true, detail: `the elements that break are the ones that already bleed at rest: ${selectors(els)}` };
|
|
43
|
+
return { holds: false, detail: `${off.length} of ${els.length} elements that break do not bleed at rest: ${selectors(off)}` };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The finding of one case: a hint naming what the case adds, else a pass.
|
|
47
|
+
function judge(rule, m, kind, words) {
|
|
48
|
+
const c = m.extreme?.cases?.[kind];
|
|
49
|
+
const b = c?.breaks;
|
|
50
|
+
if (!c || !c.ran || !b) return null;
|
|
51
|
+
const parts = [];
|
|
52
|
+
if (Number.isFinite(b.overflowX) && b.overflowX > 0) parts.push(`the page scrolls sideways by ${Math.round(b.overflowX)} px`);
|
|
53
|
+
if (Number.isFinite(b.clippedX) && b.clippedX > 0) parts.push(`${Math.round(b.clippedX)} px of text runs past the clipped right edge`);
|
|
54
|
+
const n = (list) => list?.length ?? 0;
|
|
55
|
+
if (n(b.spills)) parts.push(`${n(b.spills)} ${plural(n(b.spills), "text spills out of its box", "texts spill out of their box")}`);
|
|
56
|
+
if (n(b.cut)) parts.push(`${n(b.cut)} ${plural(n(b.cut), "text is cut", "texts are cut")}`);
|
|
57
|
+
if (n(b.lost)) parts.push(`${n(b.lost)} ${plural(n(b.lost), "text is cut away entirely", "texts are cut away entirely")}`);
|
|
58
|
+
if (n(b.overlaps)) parts.push(`${n(b.overlaps)} ${plural(n(b.overlaps), "pair of texts overlaps", "pairs of texts overlap")}`);
|
|
59
|
+
if (parts.length === 0) {
|
|
60
|
+
return makeFinding(rule, m.width, "pass", `With ${words}, nothing new spills, is cut or overlaps at ${m.width} px.`);
|
|
61
|
+
}
|
|
62
|
+
const els = byElement(b);
|
|
63
|
+
const evidence = els.map((e) => `${e.selector} "${e.text}": ${e.how.join(", ")}${e.bleedsAtRest ? " (bleeds at rest)" : ""}`);
|
|
64
|
+
const hint = makeFinding(rule, m.width, "hint", `With ${words}, things break at ${m.width} px: ${parts.join(", ")}.`, listed(evidence));
|
|
65
|
+
const move = bleedMove(b, els);
|
|
66
|
+
return move ? { ...hint, moves: { UC1: move } } : hint;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function growth(rule, m) {
|
|
70
|
+
const g = rule.threshold?.growth;
|
|
71
|
+
if (!Number.isFinite(g)) return null;
|
|
72
|
+
return judge(rule, m, "growth", caseWords("growth", { growth: g }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const listCase = (kind) => (rule, m) => {
|
|
76
|
+
const c = m.extreme?.cases?.[kind];
|
|
77
|
+
if (!c) return null;
|
|
78
|
+
return judge(rule, m, kind, caseWords(kind, { lists: c.lists, shortLists: c.shortLists }));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const extremeEvaluators = {
|
|
82
|
+
"extreme.growth": growth,
|
|
83
|
+
"extreme.long-text": (rule, m) => judge(rule, m, "long-text", caseWords("long-text")),
|
|
84
|
+
"extreme.empty": listCase("empty"),
|
|
85
|
+
"extreme.one": listCase("one"),
|
|
86
|
+
"extreme.many": listCase("many"),
|
|
87
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { OUTSIDE } from "../../measure/forms.mjs";
|
|
4
|
+
|
|
5
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
6
|
+
// What was not compared is noted by the measurer (no field, no invalid field, nameless fields); the
|
|
7
|
+
// evaluators then return null, never a vacuous pass.
|
|
8
|
+
|
|
9
|
+
function labels(rule, m) {
|
|
10
|
+
const r = m.forms;
|
|
11
|
+
const named = r ? r.fields - r.unnamed : 0;
|
|
12
|
+
if (!r || !(named > 0)) return null;
|
|
13
|
+
const n = r.unlabeled.length;
|
|
14
|
+
if (n > 0) {
|
|
15
|
+
return makeFinding(
|
|
16
|
+
rule,
|
|
17
|
+
m.width,
|
|
18
|
+
"hint",
|
|
19
|
+
`${n} of ${named} fields have no visible label (placeholder, title or aria-label alone, or a hidden label).`,
|
|
20
|
+
listed(r.unlabeled.map((f) => `${f}: ${r.labelSource[f]}`)),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return makeFinding(rule, m.width, "pass", `All ${named} fields have a visible label.`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function autocomplete(rule, m) {
|
|
27
|
+
const r = m.forms?.autocomplete;
|
|
28
|
+
if (!r || !(r.checked > 0)) return null;
|
|
29
|
+
const n = r.missing.length;
|
|
30
|
+
if (n > 0) {
|
|
31
|
+
return makeFinding(
|
|
32
|
+
rule,
|
|
33
|
+
m.width,
|
|
34
|
+
"hint",
|
|
35
|
+
`${n} ${plural(n, "field that asks for data about the person has", "fields that ask for data about the person have")} no matching autocomplete token.`,
|
|
36
|
+
listed(r.missing.map((x) => `${x.field}: expected ${x.expected}, found ${x.found || "none"}`)),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return makeFinding(rule, m.width, "pass", `All ${r.checked} fields that ask for data about the person carry a matching autocomplete token.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function inputMode(rule, m) {
|
|
43
|
+
const r = m.forms?.inputMode;
|
|
44
|
+
if (!r || !(r.checked > 0)) return null;
|
|
45
|
+
const n = r.mismatched.length;
|
|
46
|
+
if (n > 0) {
|
|
47
|
+
return makeFinding(
|
|
48
|
+
rule,
|
|
49
|
+
m.width,
|
|
50
|
+
"hint",
|
|
51
|
+
`${n} ${plural(n, "field opens a keyboard that does not match its data.", "fields open a keyboard that does not match their data.")}`,
|
|
52
|
+
listed(r.mismatched.map((x) => `${x.field}: ${x.purpose} data, no ${x.purpose} keyboard`)),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return makeFinding(rule, m.width, "pass", `All ${r.checked} fields for email, phone or numeric data open a matching keyboard.`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function required(rule, m) {
|
|
59
|
+
const r = m.forms?.required;
|
|
60
|
+
if (!r || (!(r.checked > 0) && !(r.marked > 0))) return null;
|
|
61
|
+
const parts = [];
|
|
62
|
+
const u = r.unmarked.length;
|
|
63
|
+
const x = r.markedNotRequired.length;
|
|
64
|
+
if (u > 0) parts.push(`Required and optional fields are not marked the same way: ${u} required ${plural(u, "field carries", "fields carry")} no mark.`);
|
|
65
|
+
if (x > 0) parts.push(`${x} ${plural(x, "field is marked required but the form does not require it.", "fields are marked required but the form does not require them.")}`);
|
|
66
|
+
if (parts.length) return makeFinding(rule, m.width, "hint", parts.join(" "), listed([...r.unmarked, ...r.markedNotRequired]));
|
|
67
|
+
if (r.checked > 0) return makeFinding(rule, m.width, "pass", "Required and optional fields are marked the same way.");
|
|
68
|
+
// No form with both kinds of question: only the required marks were set against the form.
|
|
69
|
+
return makeFinding(rule, m.width, "pass", `${r.marked} ${plural(r.marked, "field marked required is", "fields marked required are")} required by the form.`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function errors(rule, m) {
|
|
73
|
+
const r = m.forms?.errors;
|
|
74
|
+
if (!r || !(r.checked > 0)) return null;
|
|
75
|
+
const n = r.unlinked.length;
|
|
76
|
+
if (n > 0) {
|
|
77
|
+
return makeFinding(
|
|
78
|
+
rule,
|
|
79
|
+
m.width,
|
|
80
|
+
"hint",
|
|
81
|
+
`${n} ${plural(n, "field marked invalid has no error message tied to it", "fields marked invalid have no error message tied to them")} (aria-describedby or aria-errormessage).`,
|
|
82
|
+
listed(r.unlinked),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return makeFinding(rule, m.width, "pass", `All ${r.checked} fields marked invalid have an error message tied to them.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Each <form> only: the fields outside a form mix unrelated controls (a header search, a footer
|
|
89
|
+
// newsletter), so they are not one form (the measurer notes them).
|
|
90
|
+
function fieldCount(rule, m) {
|
|
91
|
+
const r = m.forms;
|
|
92
|
+
const max = rule.threshold?.maxFields;
|
|
93
|
+
if (!r || !Number.isFinite(max)) return null;
|
|
94
|
+
const forms = r.forms.filter((f) => f.selector !== OUTSIDE);
|
|
95
|
+
if (!forms.length) return null;
|
|
96
|
+
const over = forms.filter((f) => f.questions > max);
|
|
97
|
+
if (over.length) {
|
|
98
|
+
const n = over.length;
|
|
99
|
+
return makeFinding(
|
|
100
|
+
rule,
|
|
101
|
+
m.width,
|
|
102
|
+
"hint",
|
|
103
|
+
`${n} ${plural(n, "form asks", "forms ask")} more than ${max} questions: ${over.map((f) => `${f.selector} asks ${f.questions}`).join(", ")}.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return makeFinding(rule, m.width, "pass", `Every form asks ${max} questions or fewer.`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const formsEvaluators = {
|
|
110
|
+
"forms.labels": labels,
|
|
111
|
+
"forms.autocomplete": autocomplete,
|
|
112
|
+
"forms.input-mode": inputMode,
|
|
113
|
+
"forms.required": required,
|
|
114
|
+
"forms.errors": errors,
|
|
115
|
+
"forms.field-count": fieldCount,
|
|
116
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
|
|
4
|
+
const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
|
|
5
|
+
const times = (v) => (v === null ? "not measured" : `${v}x`);
|
|
6
|
+
const pct = (v) => `${Math.round(v * 100)}%`;
|
|
7
|
+
|
|
8
|
+
function scaleContrast(rule, m) {
|
|
9
|
+
const r = m.layout;
|
|
10
|
+
const t = rule.threshold;
|
|
11
|
+
if (!r || !hasNumbers(t, ["minTextRatio", "minAreaRatio"])) return null;
|
|
12
|
+
if ((r.blocks ?? []).length === 0) return null;
|
|
13
|
+
const textLow = r.textRatio === null || r.textRatio < t.minTextRatio;
|
|
14
|
+
const areaLow = r.areaRatio === null || r.areaRatio < t.minAreaRatio;
|
|
15
|
+
const evidence = [
|
|
16
|
+
`largest text: ${times(r.textRatio)} the body size (cutoff ${t.minTextRatio}x)`,
|
|
17
|
+
`largest block: ${times(r.areaRatio)} the median block (cutoff ${t.minAreaRatio}x)`,
|
|
18
|
+
];
|
|
19
|
+
if (textLow && areaLow) {
|
|
20
|
+
return makeFinding(rule, m.width, "hint", "The first view has little scale contrast: neither the largest text nor the largest block stands far above the rest.", evidence);
|
|
21
|
+
}
|
|
22
|
+
return makeFinding(rule, m.width, "pass", "The first view has scale contrast in its text or in its blocks.", evidence);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function emptySpace(rule, m) {
|
|
26
|
+
const r = m.layout;
|
|
27
|
+
const t = rule.threshold;
|
|
28
|
+
if (!r || !hasNumbers(t, ["minSpread"])) return null;
|
|
29
|
+
if ((r.blocks ?? []).length === 0) return null; // nothing measured in the first view
|
|
30
|
+
|
|
31
|
+
const cells = r.emptyCells ?? [];
|
|
32
|
+
const side = Math.round(Math.sqrt(cells.length));
|
|
33
|
+
const evidence = [];
|
|
34
|
+
for (let row = 0; row < side; row++) evidence.push(`row ${row + 1} empty: ${cells.slice(row * side, row * side + side).map(pct).join(", ")}`);
|
|
35
|
+
if (r.emptySpread < t.minSpread) {
|
|
36
|
+
return makeFinding(
|
|
37
|
+
rule,
|
|
38
|
+
m.width,
|
|
39
|
+
"hint",
|
|
40
|
+
`Empty space is spread evenly over the first view (the emptiest and fullest areas differ by ${pct(r.emptySpread)}, cutoff ${pct(t.minSpread)}): it reads as leftovers, not a shape.`,
|
|
41
|
+
evidence,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return makeFinding(rule, m.width, "pass", `Empty space gathers in part of the first view (the emptiest and fullest areas differ by ${pct(r.emptySpread)}).`, evidence);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// UC9 read through UR3: the pair of the two largest blocks leads the rest at the UR3 cutoff applied to the
|
|
48
|
+
// pair. With no third block nothing shows the pair leading, so the move does not hold.
|
|
49
|
+
function tensionPair(f, cutoff) {
|
|
50
|
+
const space = f.pairGapPx === null ? "" : f.pairGapPx < 0 ? `; they overlap by ${-f.pairGapPx} px` : `; ${f.pairGapPx} px apart`;
|
|
51
|
+
if (f.pairLead === null) return { holds: false, detail: `the first view has only two blocks, ${f.selector} and ${f.second}, so no third block shows the pair leading${space}` };
|
|
52
|
+
return { holds: f.pairLead >= cutoff, detail: `the two largest blocks, ${f.selector} and ${f.second}, lead the rest at ${f.pairLead}x the third (cutoff ${cutoff}x)${space}` };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function focalPoint(rule, m) {
|
|
56
|
+
const r = m.layout;
|
|
57
|
+
const t = rule.threshold;
|
|
58
|
+
if (!r || !hasNumbers(t, ["minDominance"]) || !r.focal) return null;
|
|
59
|
+
const f = r.focal;
|
|
60
|
+
if (f.dominance === null) return makeFinding(rule, m.width, "pass", `The first view has one block, ${f.selector}.`);
|
|
61
|
+
const evidence = [`${f.selector}: ${f.dominance}x the next largest block, center at ${pct(f.x)} across and ${pct(f.y)} down`];
|
|
62
|
+
if (f.dominance < t.minDominance) {
|
|
63
|
+
const hint = makeFinding(rule, m.width, "hint", `No block leads the first view: the largest is ${f.dominance}x the next (cutoff ${t.minDominance}x).`, evidence);
|
|
64
|
+
return f.second ? { ...hint, moves: { UC9: tensionPair(f, t.minDominance) } } : hint;
|
|
65
|
+
}
|
|
66
|
+
return makeFinding(rule, m.width, "pass", `${f.selector} leads the first view at ${f.dominance}x the next block.`, evidence);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// UG2: judged only from minViewport up; at a phone width almost every page is one centered column.
|
|
70
|
+
function grid(rule, m) {
|
|
71
|
+
const r = m.layout;
|
|
72
|
+
const t = rule.threshold;
|
|
73
|
+
if (!r || !hasNumbers(t, ["minViewport"]) || (r.sections ?? []).length < 2) return null;
|
|
74
|
+
if (!(m.width >= t.minViewport)) return null;
|
|
75
|
+
if (r.uniformGrid) {
|
|
76
|
+
const s = r.sections.find((x) => x.left !== null);
|
|
77
|
+
return makeFinding(
|
|
78
|
+
rule,
|
|
79
|
+
m.width,
|
|
80
|
+
"hint",
|
|
81
|
+
`Every section sits in the same centered container (${s.left} px to ${s.right} px): the grid looks inherited, not chosen. If it was chosen, log it as a decision.`,
|
|
82
|
+
listed(r.sections.map((x) => `${x.selector}: ${x.left} px to ${x.right} px`)),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return makeFinding(rule, m.width, "pass", "Sections do not all sit in one centered container.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// AP5: read at every checked width; the composition tolerance decides, so the rule has no threshold.
|
|
89
|
+
// Always a hint at most: the 320 px norm is AP2.
|
|
90
|
+
function sideways(rule, m) {
|
|
91
|
+
const r = m.layout;
|
|
92
|
+
if (!r || typeof r.sideways !== "boolean") return null;
|
|
93
|
+
if (r.sideways) return makeFinding(rule, m.width, "hint", `At ${m.width} px the page scrolls sideways (content ${r.scrollWidth} px wide).`);
|
|
94
|
+
return makeFinding(rule, m.width, "pass", `At ${m.width} px the page does not scroll sideways.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const layoutEvaluators = {
|
|
98
|
+
"layout.sideways": sideways,
|
|
99
|
+
"layout.scale-contrast": scaleContrast,
|
|
100
|
+
"layout.empty-space": emptySpace,
|
|
101
|
+
"layout.focal-point": focalPoint,
|
|
102
|
+
"layout.grid": grid,
|
|
103
|
+
};
|