@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,227 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
|
|
3
|
+
const clip = (s, n = 40) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
|
|
4
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
5
|
+
const SHOWN = 5;
|
|
6
|
+
|
|
7
|
+
function names(rule, m) {
|
|
8
|
+
if (!m.a11y) return null;
|
|
9
|
+
const list = m.a11y.unnamed ?? [];
|
|
10
|
+
if (list.length === 0) return makeFinding(rule, m.width, "pass", "Every button, link and field has a name in the accessibility tree.");
|
|
11
|
+
return makeFinding(
|
|
12
|
+
rule,
|
|
13
|
+
m.width,
|
|
14
|
+
"fail",
|
|
15
|
+
`${plural(list.length, "control")} without an accessible name.`,
|
|
16
|
+
list.slice(0, SHOWN).map((u) => `${u.role} ${clip(u.selector)}`),
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function alt(rule, m) {
|
|
21
|
+
if (!m.a11y) return null;
|
|
22
|
+
const list = m.a11y.images ?? [];
|
|
23
|
+
if (list.length === 0) return makeFinding(rule, m.width, "pass", "Every content image has a text alternative or is marked decorative.");
|
|
24
|
+
return makeFinding(
|
|
25
|
+
rule,
|
|
26
|
+
m.width,
|
|
27
|
+
"fail",
|
|
28
|
+
`${plural(list.length, "image")} without a text alternative.`,
|
|
29
|
+
list.slice(0, SHOWN).map((i) => `${clip(i.selector)} ${clip(i.src, 60)}`.trim()),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function lang(rule, m) {
|
|
34
|
+
if (!m.a11y) return null;
|
|
35
|
+
if ((m.a11y.lang ?? "").trim() !== "") return makeFinding(rule, m.width, "pass", `The page language is set (${m.a11y.lang}).`);
|
|
36
|
+
return makeFinding(rule, m.width, "fail", "The html element has no lang attribute.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function title(rule, m) {
|
|
40
|
+
if (!m.a11y) return null;
|
|
41
|
+
if ((m.a11y.title ?? "").trim() !== "") return makeFinding(rule, m.width, "pass", "The page has a title.");
|
|
42
|
+
return makeFinding(rule, m.width, "fail", "The page title is empty.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function headings(rule, m) {
|
|
46
|
+
if (!m.a11y) return null;
|
|
47
|
+
const list = m.a11y.headings ?? [];
|
|
48
|
+
const problems = [];
|
|
49
|
+
if (!list.some((h) => h.level === 1)) problems.push("No h1 on the page.");
|
|
50
|
+
for (let i = 1; i < list.length; i += 1) {
|
|
51
|
+
if (list[i].level > list[i - 1].level + 1) {
|
|
52
|
+
problems.push(`h${list[i - 1].level} "${clip(list[i - 1].text)}" is followed by h${list[i].level} "${clip(list[i].text)}".`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (problems.length === 0) return makeFinding(rule, m.width, "pass", "There is an h1 and no heading level is skipped going down.");
|
|
56
|
+
return makeFinding(rule, m.width, "hint", "The heading outline has gaps.", problems.slice(0, SHOWN));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function genericLinks(rule, m) {
|
|
60
|
+
if (!m.a11y) return null;
|
|
61
|
+
if (!Array.isArray(rule.threshold?.phrases) || rule.threshold.phrases.length === 0) return null;
|
|
62
|
+
const list = m.a11y.genericLinks ?? [];
|
|
63
|
+
if (list.length === 0) return makeFinding(rule, m.width, "pass", "No link is named only by a generic phrase.");
|
|
64
|
+
return makeFinding(
|
|
65
|
+
rule,
|
|
66
|
+
m.width,
|
|
67
|
+
"hint",
|
|
68
|
+
`${plural(list.length, "link")} named only by a generic phrase.`,
|
|
69
|
+
list.slice(0, SHOWN).map((l) => `${clip(l.selector)}: "${clip(l.text)}"`),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function targetSize(rule, m) {
|
|
74
|
+
if (!m.a11y) return null;
|
|
75
|
+
const min = rule.threshold?.minPx;
|
|
76
|
+
if (!Number.isFinite(min)) return null;
|
|
77
|
+
const list = m.a11y.targets ?? [];
|
|
78
|
+
if (list.length === 0) return makeFinding(rule, m.width, "pass", `Every target is ${min} by ${min} px or has the spacing around it.`);
|
|
79
|
+
return makeFinding(
|
|
80
|
+
rule,
|
|
81
|
+
m.width,
|
|
82
|
+
"fail",
|
|
83
|
+
`${plural(list.length, "target")} smaller than ${min} by ${min} px without enough space around.`,
|
|
84
|
+
list.slice(0, SHOWN).map((t) => `${clip(t.selector)}${t.label ? ` "${clip(t.label, 24)}"` : ""}: ${t.w} by ${t.h} px`),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// AP6: silent without the cutoff or without a large image; a hint only when every large image is decorative.
|
|
89
|
+
function decorativeImages(rule, m) {
|
|
90
|
+
if (!m.a11y || !Number.isFinite(rule.threshold?.minSidePx)) return null;
|
|
91
|
+
const list = m.a11y.largeImages ?? [];
|
|
92
|
+
if (list.length === 0) return null;
|
|
93
|
+
// Counts images not marked decorative; whether they have a text alternative is AP1's reading.
|
|
94
|
+
const marked = list.filter((i) => !i.decorative).length;
|
|
95
|
+
if (marked > 0) {
|
|
96
|
+
return makeFinding(rule, m.width, "pass", `Of ${plural(list.length, "large image")}, ${marked} ${marked === 1 ? "is" : "are"} not marked decorative.`);
|
|
97
|
+
}
|
|
98
|
+
return makeFinding(
|
|
99
|
+
rule,
|
|
100
|
+
m.width,
|
|
101
|
+
"hint",
|
|
102
|
+
`${plural(list.length, "large image")}, all marked decorative (alt=""). If one carries content (a product, a person, a proof), give it a text alternative.`,
|
|
103
|
+
list.slice(0, SHOWN).map((i) => clip(i.selector)),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// CR14: silent without the filter list or without a large image; a hint naming the large images shown recolored.
|
|
108
|
+
function imageTreatment(rule, m) {
|
|
109
|
+
if (!m.a11y || !Array.isArray(rule.threshold?.filters)) return null;
|
|
110
|
+
const list = m.a11y.largeImages ?? [];
|
|
111
|
+
if (list.length === 0) return null;
|
|
112
|
+
const treated = list.filter((i) => i.treatment);
|
|
113
|
+
// The measurer reads at most a fixed number of large images; past it the count says so.
|
|
114
|
+
const read = Number.isFinite(m.a11y.totalLarge) && m.a11y.totalLarge > list.length ? `, of the first ${plural(list.length, "large image")} read` : "";
|
|
115
|
+
if (treated.length === 0) return makeFinding(rule, m.width, "pass", `No large image is shown recolored by a filter or a blend mode${read}.`);
|
|
116
|
+
const lines = treated.map((i) => `${clip(i.selector)} (${i.treatment})`);
|
|
117
|
+
const shown = lines.slice(0, SHOWN).join(", ") + (lines.length > SHOWN ? `, and ${lines.length - SHOWN} more` : "");
|
|
118
|
+
return makeFinding(
|
|
119
|
+
rule,
|
|
120
|
+
m.width,
|
|
121
|
+
"hint",
|
|
122
|
+
`${treated.length} large ${treated.length === 1 ? "image is" : "images are"} shown recolored${read}: ${shown}. If one is proof (a customer, a result, the product as received), it may read as staged; keep proof close to the original or declare the treatment.`,
|
|
123
|
+
lines,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const who = (e) => `${clip(e.selector)}${e.label ? ` "${clip(e.label, 24)}"` : ""}`;
|
|
128
|
+
|
|
129
|
+
function focusVisible(rule, m) {
|
|
130
|
+
const f = m.a11y?.focus;
|
|
131
|
+
if (!f) return null;
|
|
132
|
+
if (f.invisible.length === 0) {
|
|
133
|
+
// Nothing compared is not a pass; the measurer notes why nothing was compared.
|
|
134
|
+
const compared = Number.isFinite(f.judged) ? f.judged : f.checked;
|
|
135
|
+
if (compared === 0) return null;
|
|
136
|
+
return makeFinding(
|
|
137
|
+
rule,
|
|
138
|
+
m.width,
|
|
139
|
+
"pass",
|
|
140
|
+
`Every element that could be compared showed a focus indicator (${plural(f.checked, "element")} reached with the Tab key${Number.isFinite(f.judged) ? `, ${f.judged} compared` : ""}).`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return makeFinding(
|
|
144
|
+
rule,
|
|
145
|
+
m.width,
|
|
146
|
+
"fail",
|
|
147
|
+
`${plural(f.invisible.length, "element")} showed no focus indicator when focused with the keyboard.`,
|
|
148
|
+
f.invisible.slice(0, SHOWN).map(who),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function focusObscured(rule, m) {
|
|
153
|
+
const f = m.a11y?.focus;
|
|
154
|
+
if (!f) return null;
|
|
155
|
+
if (f.obscured.length === 0) {
|
|
156
|
+
return makeFinding(rule, m.width, "pass", f.checked === 0 ? "No element took keyboard focus when Tab was pressed." : `No focused element was entirely covered by other content (${plural(f.checked, "element")} checked).`);
|
|
157
|
+
}
|
|
158
|
+
return makeFinding(
|
|
159
|
+
rule,
|
|
160
|
+
m.width,
|
|
161
|
+
"fail",
|
|
162
|
+
`${plural(f.obscured.length, "element")} entirely covered by other content when focused with the keyboard.`,
|
|
163
|
+
f.obscured.slice(0, SHOWN).map(who),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Reflow is measured once per check, on a page of its own at the rule width; the finding says so.
|
|
168
|
+
function reflow(rule, m) {
|
|
169
|
+
const r = m.a11y?.reflow;
|
|
170
|
+
if (!r || !Number.isFinite(rule.threshold?.width)) return null;
|
|
171
|
+
const f = reflowFinding(rule, m, r);
|
|
172
|
+
return { ...f, measuredAt: [r.width] };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function reflowFinding(rule, m, r) {
|
|
176
|
+
if (r.scrollWidth > r.width && r.offenders.length > 0) {
|
|
177
|
+
return makeFinding(
|
|
178
|
+
rule,
|
|
179
|
+
m.width,
|
|
180
|
+
"fail",
|
|
181
|
+
`At ${r.width} px the page scrolls sideways (content ${r.scrollWidth} px wide).`,
|
|
182
|
+
r.offenders.slice(0, SHOWN).map((s) => clip(s)),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (r.scrollWidth > r.width) {
|
|
186
|
+
return makeFinding(rule, m.width, "pass", `At ${r.width} px the page is ${r.scrollWidth} px wide, but no element outside the two-dimensional exceptions (tables, images, code, canvas, video, frames) or clipping boxes reaches past ${r.width} px.`);
|
|
187
|
+
}
|
|
188
|
+
return makeFinding(rule, m.width, "pass", `At ${r.width} px the page does not scroll sideways.`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function textSpacing(rule, m) {
|
|
192
|
+
const t = m.a11y?.textSpacing;
|
|
193
|
+
const v = rule.threshold;
|
|
194
|
+
if (!t || ![v?.lineHeight, v?.paragraphSpacing, v?.letterSpacing, v?.wordSpacing].every((n) => Number.isFinite(n))) return null;
|
|
195
|
+
if (t.clipped.length === 0 && t.overlapped.length === 0) {
|
|
196
|
+
return makeFinding(rule, m.width, "pass", "No text is cut off or overlapped when the text spacing values are applied.");
|
|
197
|
+
}
|
|
198
|
+
const parts = [];
|
|
199
|
+
if (t.clipped.length > 0) parts.push(`${plural(t.clipped.length, "element")} cut off`);
|
|
200
|
+
if (t.overlapped.length > 0) parts.push(`${plural(t.overlapped.length, "pair")} of text blocks overlapping`);
|
|
201
|
+
return makeFinding(
|
|
202
|
+
rule,
|
|
203
|
+
m.width,
|
|
204
|
+
"fail",
|
|
205
|
+
`With the text spacing values applied: ${parts.join(" and ")}.`,
|
|
206
|
+
[
|
|
207
|
+
...t.clipped.slice(0, SHOWN).map((c) => `${clip(c.selector)} "${clip(c.text, 24)}" is cut off`),
|
|
208
|
+
...t.overlapped.slice(0, SHOWN).map((o) => `${clip(o.selector, 60)} overlap`),
|
|
209
|
+
].slice(0, SHOWN),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export const a11yEvaluators = {
|
|
214
|
+
"a11y.focus-visible": focusVisible,
|
|
215
|
+
"a11y.focus-obscured": focusObscured,
|
|
216
|
+
"a11y.reflow": reflow,
|
|
217
|
+
"a11y.text-spacing": textSpacing,
|
|
218
|
+
"a11y.names": names,
|
|
219
|
+
"a11y.alt": alt,
|
|
220
|
+
"a11y.decorative-images": decorativeImages,
|
|
221
|
+
"a11y.image-treatment": imageTreatment,
|
|
222
|
+
"a11y.lang": lang,
|
|
223
|
+
"a11y.title": title,
|
|
224
|
+
"a11y.headings": headings,
|
|
225
|
+
"a11y.generic-links": genericLinks,
|
|
226
|
+
"a11y.target-size": targetSize,
|
|
227
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { cvd, distances } from "../../measure/cvd.mjs";
|
|
3
|
+
import { MAX_LISTED } from "../../measure/chart-read.mjs";
|
|
4
|
+
|
|
5
|
+
// The chart evaluators. Each reads m.chart (a ChartReport) and returns null when it compared
|
|
6
|
+
// nothing: no chart, no bar chart with a linear value axis, no svg text, fewer than two series or colors.
|
|
7
|
+
// Values are compared raw against the rule's cutoffs and rounded only for the message.
|
|
8
|
+
|
|
9
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
10
|
+
const joined = (list) => (list.length < 2 ? list.join("") : `${list.slice(0, -1).join(", ")} and ${list[list.length - 1]}`);
|
|
11
|
+
const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
|
|
12
|
+
const SATURATION_KEYS = ["minSaturation", "minLightness", "maxLightness"];
|
|
13
|
+
// A value under its cutoff shown at one decimal, or cut down to two decimals when one decimal would reach the
|
|
14
|
+
// cutoff (11.96 px against 12 is shown 11.96, never 12).
|
|
15
|
+
const shown = (v, cutoff) => {
|
|
16
|
+
const one = Math.round(v * 10) / 10;
|
|
17
|
+
return one >= cutoff ? Math.floor(v * 100) / 100 : one;
|
|
18
|
+
};
|
|
19
|
+
const rgbOf = (hex) => ({ r: parseInt(hex.slice(1, 3), 16), g: parseInt(hex.slice(3, 5), 16), b: parseInt(hex.slice(5, 7), 16) });
|
|
20
|
+
const chartsOf = (m) => m.chart?.charts ?? null;
|
|
21
|
+
const listed = (evidence) => evidence.slice(0, MAX_LISTED);
|
|
22
|
+
|
|
23
|
+
function baseline(rule, m) {
|
|
24
|
+
const charts = chartsOf(m)?.filter((c) => c.bars && c.axis?.kind === "linear" && c.axis.baseValue !== null);
|
|
25
|
+
if (!charts?.length) return null;
|
|
26
|
+
const n = charts.length;
|
|
27
|
+
const off = charts.filter((c) => c.axis.baseValue !== 0);
|
|
28
|
+
if (off.length === 0) return makeFinding(rule, m.width, "pass", `The bars of ${n} ${plural(n, "bar chart start", "bar charts start")} at zero.`);
|
|
29
|
+
const k = off.length;
|
|
30
|
+
const evidence = off.map((c) => {
|
|
31
|
+
const values = c.axis.ticks.map((t) => t.value);
|
|
32
|
+
return `${c.selector}: the bars start at ${c.axis.baseValue}, ticks from ${Math.min(...values)} to ${Math.max(...values)}`;
|
|
33
|
+
});
|
|
34
|
+
return makeFinding(rule, m.width, "hint", `${k} of ${n} ${plural(n, "bar chart", "bar charts")} ${plural(k, "does", "do")} not start at zero.`, listed(evidence));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function labelSize(rule, m) {
|
|
38
|
+
const t = rule.threshold;
|
|
39
|
+
if (!hasNumbers(t, ["minLabelPx"])) return null;
|
|
40
|
+
const charts = chartsOf(m)?.filter((c) => c.kind === "svg" && c.labels && c.labels.count > 0);
|
|
41
|
+
if (!charts?.length) return null;
|
|
42
|
+
const n = charts.length;
|
|
43
|
+
const k = charts.reduce((s, c) => s + c.labels.sizes.filter((px) => px < t.minLabelPx).length, 0);
|
|
44
|
+
if (k === 0) return makeFinding(rule, m.width, "pass", `Every label of the ${n} ${plural(n, "chart", "charts")} is at least ${t.minLabelPx} px.`);
|
|
45
|
+
const evidence = charts.flatMap((c) => c.labels.smallest.filter((s) => s.px < t.minLabelPx).map((s) => `${c.selector}: "${s.text}" at ${shown(s.px, t.minLabelPx)} px`));
|
|
46
|
+
return makeFinding(rule, m.width, "hint", `${k} chart ${plural(k, "label is", "labels are")} smaller than ${t.minLabelPx} px.`, listed(evidence));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function directLabels(rule, m) {
|
|
50
|
+
const charts = chartsOf(m)?.filter((c) => c.kind === "svg" && (c.series?.length ?? 0) >= 2);
|
|
51
|
+
if (!charts?.length) return null;
|
|
52
|
+
const n = charts.length;
|
|
53
|
+
const evidence = [];
|
|
54
|
+
for (const c of charts) {
|
|
55
|
+
const labeled = new Set((c.direct ?? []).map((d) => d.color));
|
|
56
|
+
const entries = c.legend ?? [];
|
|
57
|
+
const legendOnly = entries.filter((e) => !labeled.has(e.color));
|
|
58
|
+
// A series named neither at the data nor in the legend.
|
|
59
|
+
const inLegend = new Set(entries.map((e) => e.color));
|
|
60
|
+
const s = c.series.length;
|
|
61
|
+
const u = c.series.filter((x) => !labeled.has(x.color) && !inLegend.has(x.color)).length;
|
|
62
|
+
const parts = [];
|
|
63
|
+
if (legendOnly.length) parts.push(`${joined(legendOnly.map((e) => e.name))} only in the legend`);
|
|
64
|
+
if (u === s) parts.push(`${s} series and nothing names them`);
|
|
65
|
+
else if (u > 0) parts.push(`${u} of the ${s} series named nowhere`);
|
|
66
|
+
if (parts.length) evidence.push(`${c.selector}: ${parts.join("; ")}`);
|
|
67
|
+
}
|
|
68
|
+
if (evidence.length === 0) {
|
|
69
|
+
return makeFinding(rule, m.width, "pass", `Each of the ${n} ${plural(n, "chart", "charts")} with several series labels every series at the data.`);
|
|
70
|
+
}
|
|
71
|
+
const k = evidence.length;
|
|
72
|
+
return makeFinding(
|
|
73
|
+
rule, m.width, "hint",
|
|
74
|
+
`${k} of ${n} ${plural(n, "chart", "charts")} with several series ${plural(k, "names them", "name them")} only in a legend or not at all.`,
|
|
75
|
+
listed(evidence),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The saturated colors of a chart's colors, with the rule's keys (the color measurer's predicate).
|
|
80
|
+
const saturatedOf = (c, t) => c.colors.list.filter((x) => cvd.saturated(rgbOf(x.hex), t)).map((x) => x.hex);
|
|
81
|
+
|
|
82
|
+
function categories(rule, m) {
|
|
83
|
+
const t = rule.threshold;
|
|
84
|
+
if (!hasNumbers(t, ["maxCategories", ...SATURATION_KEYS])) return null;
|
|
85
|
+
const charts = chartsOf(m)?.filter((c) => c.colors !== null);
|
|
86
|
+
if (!charts?.length) return null;
|
|
87
|
+
const n = charts.length;
|
|
88
|
+
const over = charts.map((c) => ({ c, hexes: saturatedOf(c, t) })).filter((x) => x.hexes.length > t.maxCategories);
|
|
89
|
+
if (over.length === 0) {
|
|
90
|
+
return makeFinding(rule, m.width, "pass", `Every one of the ${n} ${plural(n, "chart", "charts")} uses at most ${t.maxCategories} saturated colors for its series.`);
|
|
91
|
+
}
|
|
92
|
+
const k = over.length;
|
|
93
|
+
const evidence = over.map(({ c, hexes }) => `${c.selector}: ${hexes.length} saturated colors (${hexes.join(", ")})`);
|
|
94
|
+
return makeFinding(rule, m.width, "hint", `${k} ${plural(k, "chart uses", "charts use")} more than ${t.maxCategories} saturated colors for their series.`, listed(evidence));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const viewWords = (view) => (view === "normal" ? "in normal vision" : `with ${view}`);
|
|
98
|
+
|
|
99
|
+
function colorVision(rule, m) {
|
|
100
|
+
const t = rule.threshold;
|
|
101
|
+
if (!hasNumbers(t, ["minDeltaE", ...SATURATION_KEYS])) return null;
|
|
102
|
+
// The series colors of an svg chart; the saturated buckets of a canvas chart.
|
|
103
|
+
const charts = (chartsOf(m) ?? [])
|
|
104
|
+
.filter((c) => c.colors !== null)
|
|
105
|
+
.map((c) => ({ c, colors: c.colors.source === "dom" ? c.colors.list.map((x) => x.hex) : saturatedOf(c, t) }))
|
|
106
|
+
.filter((x) => x.colors.length >= 2);
|
|
107
|
+
if (!charts.length) return null;
|
|
108
|
+
const n = charts.length;
|
|
109
|
+
const close = [];
|
|
110
|
+
let labeledPairs = 0;
|
|
111
|
+
for (const { c, colors } of charts) {
|
|
112
|
+
const labeled = new Set((c.direct ?? []).map((d) => d.color));
|
|
113
|
+
for (const pair of distances(colors)) {
|
|
114
|
+
// Every view under minDeltaE, closest first.
|
|
115
|
+
const under = cvd.VIEWS.filter((v) => pair[v] < t.minDeltaE).sort((a, b) => pair[a] - pair[b]);
|
|
116
|
+
if (!under.length) continue;
|
|
117
|
+
if (labeled.has(pair.a) && labeled.has(pair.b)) {
|
|
118
|
+
labeledPairs += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
close.push({ c, pair, under, closest: pair[under[0]] });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const views = "normal vision, protanopia, deuteranopia, tritanopia and grayscale";
|
|
125
|
+
if (close.length === 0) {
|
|
126
|
+
if (labeledPairs === 0) {
|
|
127
|
+
return makeFinding(rule, m.width, "pass", `Every pair of series colors in ${n} ${plural(n, "chart", "charts")} stays at least Delta E ${t.minDeltaE} apart in ${views}.`);
|
|
128
|
+
}
|
|
129
|
+
return makeFinding(
|
|
130
|
+
rule, m.width, "pass",
|
|
131
|
+
`Every pair of series colors in ${n} ${plural(n, "chart", "charts")} stays at least Delta E ${t.minDeltaE} apart in every view, except ${labeledPairs} ${plural(labeledPairs, "pair whose series are", "pairs whose series are")} both labeled at the data.`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const k = close.length;
|
|
135
|
+
const evidence = close
|
|
136
|
+
.sort((x, y) => x.closest - y.closest)
|
|
137
|
+
.map(({ c, pair, under }) => `${c.selector}: ${pair.a} and ${pair.b}, ${under.map((v) => `Delta E ${shown(pair[v], t.minDeltaE)} ${viewWords(v)}`).join(", ")}`);
|
|
138
|
+
return makeFinding(
|
|
139
|
+
rule, m.width, "hint",
|
|
140
|
+
`${k} ${plural(k, "pair of series colors is", "pairs of series colors are")} closer than Delta E ${t.minDeltaE} in at least one view.`,
|
|
141
|
+
listed(evidence),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const chartEvaluators = {
|
|
146
|
+
"chart.baseline": baseline,
|
|
147
|
+
"chart.label-size": labelSize,
|
|
148
|
+
"chart.direct-labels": directLabels,
|
|
149
|
+
"chart.categories": categories,
|
|
150
|
+
"chart.cvd": colorVision,
|
|
151
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { makeFinding } from "../finding.mjs";
|
|
3
|
+
import { listed } from "../evidence.mjs";
|
|
4
|
+
|
|
5
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
6
|
+
const capitalize = (t) => (t ? t[0].toUpperCase() + t.slice(1) : t);
|
|
7
|
+
// "a", "a and b", "a, b and c".
|
|
8
|
+
export const joined = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`);
|
|
9
|
+
|
|
10
|
+
// A signature in words, never the raw signature: button:get started -> the "Get started" button.
|
|
11
|
+
// label is the name in the page's own capitalization (the reader's label); without one, the name is taken
|
|
12
|
+
// from the signature (lowercased for buttons and links) with its first letter capitalized.
|
|
13
|
+
export function describeSignature(signature, label) {
|
|
14
|
+
const at = signature.indexOf(":");
|
|
15
|
+
const kind = at === -1 ? signature : signature.slice(0, at);
|
|
16
|
+
const rest = at === -1 ? "" : signature.slice(at + 1);
|
|
17
|
+
if (kind === "button" || kind === "link") return `the "${label || capitalize(rest)}" ${kind}`;
|
|
18
|
+
if (kind === "field") {
|
|
19
|
+
const name = rest.slice(rest.indexOf(":") + 1);
|
|
20
|
+
return `the ${label || name} field`;
|
|
21
|
+
}
|
|
22
|
+
// The data-component name, never the label (a control's label is its text).
|
|
23
|
+
if (kind === "component") return `the ${rest} component (data-component)`;
|
|
24
|
+
return `${signature} headings`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Screens named for a reader: a URL by its path (with its query and fragment), a file by its name; the full
|
|
28
|
+
// target when two collide.
|
|
29
|
+
export function screenNames(screens) {
|
|
30
|
+
const short = screens.map((t) => {
|
|
31
|
+
if (/^https?:\/\//i.test(t)) {
|
|
32
|
+
try {
|
|
33
|
+
const u = new URL(t);
|
|
34
|
+
return `${u.pathname}${u.search}${u.hash}`;
|
|
35
|
+
} catch {
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return path.basename(t);
|
|
40
|
+
});
|
|
41
|
+
return short.map((s, i) => (short.some((x, j) => x === s && screens[j] !== screens[i]) ? screens[i] : s));
|
|
42
|
+
}
|
|
43
|
+
export const onScreens = (names, list) => joined(list.map((i) => names[i] ?? String(i)));
|
|
44
|
+
|
|
45
|
+
function sameComponent(rule, m) {
|
|
46
|
+
const r = m.coherence;
|
|
47
|
+
if (!r || !Array.isArray(r.shared) || r.shared.length === 0) return null;
|
|
48
|
+
const names = screenNames(r.screens ?? []);
|
|
49
|
+
const labels = new Map(r.shared.map((s) => [s.signature, s.label]));
|
|
50
|
+
const describe = (sig) => describeSignature(sig, labels.get(sig));
|
|
51
|
+
const n = r.divergent.length;
|
|
52
|
+
if (n > 0) {
|
|
53
|
+
const evidence = r.divergent.flatMap((d) =>
|
|
54
|
+
d.diffs.map((x) => `${describe(d.signature)}: ${x.property} ${x.values.map((v) => `${v.value} on ${onScreens(names, v.screens)}`).join("; ")}`),
|
|
55
|
+
);
|
|
56
|
+
return makeFinding(
|
|
57
|
+
rule,
|
|
58
|
+
m.width,
|
|
59
|
+
"hint",
|
|
60
|
+
`${n} ${plural(n, "component looks", "components look")} different from one screen to another: ${joined(r.divergent.map((d) => describe(d.signature)))}.`,
|
|
61
|
+
listed(evidence),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const s = r.shared.length;
|
|
65
|
+
return makeFinding(rule, m.width, "pass", `${s} ${plural(s, "component that appears on several screens looks", "components that appear on several screens look")} the same on each.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const KIND_WORDS = { button: { one: "Buttons", lower: "buttons" }, field: { one: "Fields", lower: "fields" } };
|
|
69
|
+
|
|
70
|
+
function variants(rule, m) {
|
|
71
|
+
const r = m.coherence;
|
|
72
|
+
const kinds = (r?.variants ?? []).filter((v) => v.looks.length > 0);
|
|
73
|
+
if (kinds.length === 0) return null;
|
|
74
|
+
const max = rule.threshold?.maxLooks;
|
|
75
|
+
if (!Number.isFinite(max)) return null;
|
|
76
|
+
const names = screenNames(r.screens ?? []);
|
|
77
|
+
const over = kinds.filter((v) => v.looks.length > max);
|
|
78
|
+
if (over.length === 0) {
|
|
79
|
+
const found = kinds.map((v) => KIND_WORDS[v.kind]);
|
|
80
|
+
const message = found.length === 1 ? `${found[0].one} stay within ${max} looks.` : `${found[0].one} and ${found.slice(1).map((w) => w.lower).join(" and ")} stay within ${max} looks each.`;
|
|
81
|
+
return makeFinding(rule, m.width, "pass", message);
|
|
82
|
+
}
|
|
83
|
+
const sentences = [];
|
|
84
|
+
const evidence = [];
|
|
85
|
+
for (const v of over) {
|
|
86
|
+
const across = new Set(v.looks.flatMap((l) => l.screens)).size;
|
|
87
|
+
sentences.push(`${KIND_WORDS[v.kind].one} take ${v.looks.length} looks across ${across} ${plural(across, "screen", "screens")}; the cutoff is ${max}.`);
|
|
88
|
+
// Only the properties that differ among this kind's looks.
|
|
89
|
+
const keys = Object.keys(v.looks[0].look ?? {}).filter((k) => new Set(v.looks.map((l) => l.look?.[k])).size > 1);
|
|
90
|
+
v.looks.forEach((l, i) => {
|
|
91
|
+
const props = keys.map((k) => `${k.replace(/^self /, "")} ${l.look?.[k]}`).join(", ");
|
|
92
|
+
// Named by the text of its first named element, never by a CSS selector.
|
|
93
|
+
const name = l.label ? `"${l.label}"` : "no text or label";
|
|
94
|
+
evidence.push(`${KIND_WORDS[v.kind].one}, look ${i + 1} (${name}, ${l.count} ${plural(l.count, "element", "elements")}): ${props} on ${onScreens(names, l.screens)}`);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return makeFinding(rule, m.width, "hint", sentences.join(" "), listed(evidence));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const coherenceEvaluators = {
|
|
101
|
+
"coherence.same-component": sameComponent,
|
|
102
|
+
"coherence.variants": variants,
|
|
103
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { cvd } from "../../measure/cvd.mjs";
|
|
3
|
+
|
|
4
|
+
const clip = (s, n = 40) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
|
|
5
|
+
const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
|
|
6
|
+
|
|
7
|
+
const hslOf = (hex) => {
|
|
8
|
+
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
|
|
9
|
+
const M = Math.max(r, g, b), n = Math.min(r, g, b), l = (M + n) / 2;
|
|
10
|
+
if (M === n) return { h: 0, s: 0, l: l * 100 };
|
|
11
|
+
const d = M - n;
|
|
12
|
+
const s = l > 0.5 ? d / (2 - M - n) : d / (M + n);
|
|
13
|
+
let h = M === r ? (g - b) / d + (g < b ? 6 : 0) : M === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
14
|
+
return { h: h * 60, s: s * 100, l: l * 100 };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// ES5 is about yellow text marked or worded as a warning (row.warning, from the threshold's roles and marks).
|
|
18
|
+
// The band comes from the rule's threshold (hypothesis H21). Unmarked yellow text is left to RV2.
|
|
19
|
+
// A filter takes the rule and gives a row predicate, or null when its keys are missing.
|
|
20
|
+
const yellowText = (rule) => {
|
|
21
|
+
const t = rule.threshold;
|
|
22
|
+
if (!hasNumbers(t, ["minHue", "maxHue", "minSaturation"])) return null;
|
|
23
|
+
return (row) => {
|
|
24
|
+
if (!/^#[0-9a-f]{6}$/i.test(row.fg ?? "")) return false;
|
|
25
|
+
const { h, s } = hslOf(row.fg);
|
|
26
|
+
return row.warning === true && h >= t.minHue && h <= t.maxHue && s > t.minSaturation;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const ROW_FILTERS = { ES5: yellowText };
|
|
30
|
+
|
|
31
|
+
function contrast(rule, m) {
|
|
32
|
+
if (!m.color) return null;
|
|
33
|
+
const t = rule.threshold;
|
|
34
|
+
if (!hasNumbers(t, ["normal", "large"])) return null;
|
|
35
|
+
const makeFilter = ROW_FILTERS[rule.id];
|
|
36
|
+
const filter = makeFilter ? makeFilter(rule) : undefined;
|
|
37
|
+
if (makeFilter && !filter) return null;
|
|
38
|
+
const rows = (m.color.contrast ?? []).filter(filter ?? (() => true));
|
|
39
|
+
// Only fails and a few passes are listed, so "no matching row" is a skip, never a pass.
|
|
40
|
+
if (filter && rows.length === 0) return null;
|
|
41
|
+
const bad = rows.filter((r) => r.ratio < (r.size === "large" ? t.large : t.normal));
|
|
42
|
+
if (bad.length === 0) return makeFinding(rule, m.width, "pass", "Text contrast meets the minimum.");
|
|
43
|
+
const evidence = bad
|
|
44
|
+
.slice(0, 5)
|
|
45
|
+
.flatMap((r) => [
|
|
46
|
+
`"${clip(r.text)}" ${r.fg} on ${r.bg}: ${r.ratio}:1 (${r.size} text needs ${t[r.size]}:1)`,
|
|
47
|
+
...(r.hidden === true
|
|
48
|
+
? [`"${clip(r.text)}" is hidden from assistive technology (aria-hidden). WCAG 1.4.3 exempts text that is pure decoration; if it is, record that as a decision. The fail stays.`]
|
|
49
|
+
: []),
|
|
50
|
+
]);
|
|
51
|
+
return makeFinding(
|
|
52
|
+
rule,
|
|
53
|
+
m.width,
|
|
54
|
+
"fail",
|
|
55
|
+
`${bad.length} text element${bad.length === 1 ? "" : "s"} below the contrast minimum (WCAG 2.2).`,
|
|
56
|
+
evidence,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function area(rule, m) {
|
|
61
|
+
if (!m.color) return null;
|
|
62
|
+
const t = rule.threshold;
|
|
63
|
+
if (!hasNumbers(t, ["minSaturation", "minLightness", "maxLightness", "maxPct"])) return null;
|
|
64
|
+
const big = (m.color.area ?? []).filter(
|
|
65
|
+
(a) => a.s > t.minSaturation && a.l >= t.minLightness && a.l <= t.maxLightness && a.pct > t.maxPct,
|
|
66
|
+
);
|
|
67
|
+
if (big.length === 0) {
|
|
68
|
+
return makeFinding(rule, m.width, "pass", "No saturated color takes a very large share of the first view.");
|
|
69
|
+
}
|
|
70
|
+
const evidence = big.map((a) => `${a.hex} covers ${a.pct}% of the first view`);
|
|
71
|
+
return makeFinding(rule, m.width, "hint", `A saturated color covers more than ${t.maxPct}% of the first view.`, evidence);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function textChroma(rule, m) {
|
|
75
|
+
if (!m.color) return null;
|
|
76
|
+
const t = rule.threshold;
|
|
77
|
+
if (!hasNumbers(t, ["maxChromaticPct"])) return null;
|
|
78
|
+
const tc = m.color.textChroma ?? { chromaticPct: 0, longColoredBlocks: 0 };
|
|
79
|
+
const over = tc.chromaticPct > t.maxChromaticPct || tc.longColoredBlocks > 0;
|
|
80
|
+
if (!over) return makeFinding(rule, m.width, "pass", "Text is mostly neutral.");
|
|
81
|
+
const evidence = [`${tc.chromaticPct}% of text elements are in a chromatic color`];
|
|
82
|
+
if (tc.longColoredBlocks > 0) {
|
|
83
|
+
evidence.push(`${tc.longColoredBlocks} colored text block(s) longer than 80 characters`);
|
|
84
|
+
}
|
|
85
|
+
return makeFinding(rule, m.width, "hint", "Much of the text is in a chromatic color.", evidence);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rgbOf = (hex) => ({ r: parseInt(hex.slice(1, 3), 16), g: parseInt(hex.slice(3, 5), 16), b: parseInt(hex.slice(5, 7), 16) });
|
|
89
|
+
const round1 = (n) => Math.round(n * 10) / 10;
|
|
90
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
91
|
+
// The unrounded fraction of the view an area entry covers (pct, in percent and rounded, for older readings).
|
|
92
|
+
const shareOf = (a) => (Number.isFinite(a.share) ? a.share : a.pct / 100);
|
|
93
|
+
|
|
94
|
+
// GR10: a Brand color is present when the first-view area entries within maxDeltaE of it (Delta E 1976, the
|
|
95
|
+
// chart measurer's conversion) cover at least minShare of the view, on the unrounded shares. Silent without
|
|
96
|
+
// Brand colors or area entries; the measurer notes the missing lines.
|
|
97
|
+
function brand(rule, m) {
|
|
98
|
+
const t = rule.threshold;
|
|
99
|
+
if (!m.color || !hasNumbers(t, ["maxDeltaE", "minShare"])) return null;
|
|
100
|
+
const tokens = m.color.brand ?? [];
|
|
101
|
+
const area = (m.color.area ?? []).filter((a) => /^#[0-9a-f]{6}$/i.test(a.hex ?? ""));
|
|
102
|
+
if (tokens.length === 0 || area.length === 0) return null;
|
|
103
|
+
const rows = tokens.map((tok) => {
|
|
104
|
+
const rgb = rgbOf(tok.hex);
|
|
105
|
+
let covered = 0;
|
|
106
|
+
let nearest = null;
|
|
107
|
+
for (const a of area) {
|
|
108
|
+
const d = cvd.deltaE(rgb, rgbOf(a.hex));
|
|
109
|
+
if (d <= t.maxDeltaE) covered += shareOf(a);
|
|
110
|
+
if (!nearest || d < nearest.d) nearest = { hex: a.hex, d, pct: a.pct };
|
|
111
|
+
}
|
|
112
|
+
return { tok, covered, nearest };
|
|
113
|
+
});
|
|
114
|
+
const label = (tok) => (tok.name ? `${tok.name} ${tok.hex}` : tok.hex);
|
|
115
|
+
const present = rows.filter((r) => r.covered >= t.minShare).sort((a, b) => b.covered - a.covered);
|
|
116
|
+
if (present.length > 0) {
|
|
117
|
+
return makeFinding(rule, m.width, "pass", `${label(present[0].tok)} covers ${round1(present[0].covered * 100)}% of the first view.`);
|
|
118
|
+
}
|
|
119
|
+
return makeFinding(
|
|
120
|
+
rule,
|
|
121
|
+
m.width,
|
|
122
|
+
"hint",
|
|
123
|
+
"None of the Brand colors is in the first view.",
|
|
124
|
+
rows.map((r) => `${label(r.tok)}: nearest ${r.nearest.hex} at Delta E ${round1(r.nearest.d)}, ${round1(r.nearest.pct)}% of the first view, covered ${round2(r.covered * 100)}% within Delta E ${t.maxDeltaE}`),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const colorEvaluators = {
|
|
129
|
+
"color.brand": brand,
|
|
130
|
+
"color.contrast": contrast,
|
|
131
|
+
"color.area": area,
|
|
132
|
+
"color.text-chroma": textChroma,
|
|
133
|
+
};
|