@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,280 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { TIMING_TOLERANCE_MS } from "../../measure/timeline.mjs";
|
|
4
|
+
|
|
5
|
+
// Evaluators of the motion measurer (src/measure/motion.mjs). Each one reads only what was recorded and
|
|
6
|
+
// gives null when nothing of its kind was read (no vacuous pass). Timed readings near a cutoff are not
|
|
7
|
+
// judged: the evaluator gives null and writes a note on the report (once, as evaluate may run twice).
|
|
8
|
+
|
|
9
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
10
|
+
const MICRO = new Set(["hover", "focus", "click"]);
|
|
11
|
+
const PAGE = new Set(["load", "scroll"]);
|
|
12
|
+
const finite = (a) => a.endMs !== null;
|
|
13
|
+
// A scroll-linked animation (animation-timeline) runs with the scroll position, not with time: it has no length.
|
|
14
|
+
const timed = (a) => finite(a) && a.scrollLinked !== true;
|
|
15
|
+
const LINEAR = new Set(["linear", "cubic-bezier(0, 0, 1, 1)"]);
|
|
16
|
+
const listing = (props) => props.join(" and ");
|
|
17
|
+
|
|
18
|
+
function noteOn(m, text) {
|
|
19
|
+
const r = m.motion;
|
|
20
|
+
if (!Array.isArray(r.notes)) r.notes = [];
|
|
21
|
+
if (!r.notes.includes(text)) r.notes.push(text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const animationsOf = (m) => m.motion?.exact?.animations ?? null;
|
|
25
|
+
const durationLine = (a) => `${a.selector} on ${a.trigger}: ${a.name}, ${a.endMs} ms`;
|
|
26
|
+
const longestFirst = (list) => [...list].sort((a, b) => b.endMs - a.endMs);
|
|
27
|
+
|
|
28
|
+
function microDuration(rule, m) {
|
|
29
|
+
const all = animationsOf(m);
|
|
30
|
+
const maxMs = rule.threshold?.maxMs;
|
|
31
|
+
if (!all || !Number.isFinite(maxMs)) return null;
|
|
32
|
+
const list = all.filter((a) => MICRO.has(a.trigger) && timed(a));
|
|
33
|
+
if (list.length === 0) return null;
|
|
34
|
+
const long = list.filter((a) => a.endMs > maxMs);
|
|
35
|
+
if (long.length > 0) {
|
|
36
|
+
const n = long.length;
|
|
37
|
+
return makeFinding(rule, m.width, "hint", `${n} ${plural(n, "microinteraction takes", "microinteractions take")} longer than ${maxMs} ms.`, listed(longestFirst(long).map(durationLine)));
|
|
38
|
+
}
|
|
39
|
+
const n = list.length;
|
|
40
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "microinteraction finishes", "microinteractions finish")} within ${maxMs} ms.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function transitionDuration(rule, m) {
|
|
44
|
+
const all = animationsOf(m);
|
|
45
|
+
const maxMs = rule.threshold?.maxMs;
|
|
46
|
+
if (!all || !Number.isFinite(maxMs)) return null;
|
|
47
|
+
const list = all.filter((a) => PAGE.has(a.trigger) && timed(a));
|
|
48
|
+
if (list.length === 0) return null;
|
|
49
|
+
const long = list.filter((a) => a.endMs > maxMs);
|
|
50
|
+
if (long.length > 0) {
|
|
51
|
+
const n = long.length;
|
|
52
|
+
return makeFinding(rule, m.width, "hint", `${n} ${plural(n, "transition or entrance takes", "transitions or entrances take")} longer than ${maxMs} ms, delay included.`, listed(longestFirst(long).map(durationLine)));
|
|
53
|
+
}
|
|
54
|
+
const n = list.length;
|
|
55
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "transition or entrance finishes", "transitions and entrances finish")} within ${maxMs} ms, delay included.`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function easing(rule, m) {
|
|
59
|
+
const all = animationsOf(m);
|
|
60
|
+
if (!all) return null;
|
|
61
|
+
const linked = all.filter((a) => a.scrollLinked === true && a.moves);
|
|
62
|
+
if (linked.length > 0) {
|
|
63
|
+
const n = linked.length;
|
|
64
|
+
noteOn(m, `${n} ${plural(n, "animation linked to scroll (animation-timeline) is not judged for easing: the scroll position is its curve.", "animations linked to scroll (animation-timeline) are not judged for easing: the scroll position is their curve.")}`);
|
|
65
|
+
}
|
|
66
|
+
const list = all.filter((a) => a.scrollLinked !== true && finite(a) && a.moves);
|
|
67
|
+
if (list.length === 0) return null;
|
|
68
|
+
const linear = list.filter((a) => LINEAR.has(a.easing));
|
|
69
|
+
if (linear.length > 0) {
|
|
70
|
+
const n = linear.length;
|
|
71
|
+
return makeFinding(rule, m.width, "hint", `${n} moving ${plural(n, "animation runs", "animations run")} at a constant speed (linear).`, listed(linear.map((a) => `${a.selector} on ${a.trigger}: ${a.name}`)));
|
|
72
|
+
}
|
|
73
|
+
const n = list.length;
|
|
74
|
+
return makeFinding(rule, m.width, "pass", `None of the ${n} moving ${plural(n, "animation", "animations")} runs at a constant speed.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function properties(rule, m) {
|
|
78
|
+
const all = animationsOf(m);
|
|
79
|
+
if (!all || all.length === 0) return null;
|
|
80
|
+
const layout = all.filter((a) => a.layoutProps.length > 0);
|
|
81
|
+
if (layout.length > 0) {
|
|
82
|
+
const n = layout.length;
|
|
83
|
+
return makeFinding(
|
|
84
|
+
rule,
|
|
85
|
+
m.width,
|
|
86
|
+
"hint",
|
|
87
|
+
`${n} ${plural(n, "animation changes", "animations change")} layout properties, which lays the page out again on every frame.`,
|
|
88
|
+
listed(layout.map((a) => `${a.selector}: ${a.layoutProps.join(", ")}`)),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const n = all.length;
|
|
92
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "animation changes", "animations change")} no layout property.`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Two entrances are the same animation when they change the same properties between the same values over
|
|
96
|
+
// the same duration with the same curve; delay and name do not count (a stagger of
|
|
97
|
+
// one fade is one animation).
|
|
98
|
+
const sameKey = (a) => JSON.stringify([a.properties, a.from, a.to, a.durationMs, a.easing]);
|
|
99
|
+
|
|
100
|
+
function sameness(rule, m) {
|
|
101
|
+
const all = animationsOf(m);
|
|
102
|
+
const min = rule.threshold?.minEntrances;
|
|
103
|
+
if (!all || !Number.isFinite(min)) return null;
|
|
104
|
+
const list = all.filter((a) => a.entrance);
|
|
105
|
+
if (list.length < min) return null;
|
|
106
|
+
const kinds = new Set(list.map(sameKey));
|
|
107
|
+
const n = list.length;
|
|
108
|
+
if (kinds.size === 1) {
|
|
109
|
+
const a = list[0];
|
|
110
|
+
return makeFinding(rule, m.width, "hint", `All ${n} entrances are the same animation: ${listing(a.properties)} over ${a.durationMs} ms, ${a.easing}.`);
|
|
111
|
+
}
|
|
112
|
+
return makeFinding(rule, m.width, "pass", `The ${n} entrances use ${kinds.size} different animations.`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function reduced(rule, m) {
|
|
116
|
+
const r = m.motion?.exact?.reduced;
|
|
117
|
+
if (!r || !(r.moving > 0)) return null;
|
|
118
|
+
const n = r.moving;
|
|
119
|
+
const k = r.kept.length;
|
|
120
|
+
if (k > 0) {
|
|
121
|
+
return makeFinding(
|
|
122
|
+
rule,
|
|
123
|
+
m.width,
|
|
124
|
+
"hint",
|
|
125
|
+
`${k} of ${n} moving ${plural(n, "animation", "animations")} still ${plural(k, "moves", "move")} with reduced motion asked for.`,
|
|
126
|
+
listed(r.kept.map((a) => `${a.selector}: ${a.name} (${a.properties.join(", ")})`)),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return makeFinding(rule, m.width, "pass", `With reduced motion asked for, none of the ${n} moving ${plural(n, "animation", "animations")} still moves.`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function longFrames(rule, m) {
|
|
133
|
+
const t = m.motion?.timed;
|
|
134
|
+
const max = rule.threshold?.maxFrameMs;
|
|
135
|
+
if (!t || t.longFrameApi == null || !Array.isArray(t.longFrames) || !Number.isFinite(max)) return null;
|
|
136
|
+
const long = t.longFrames.filter((f) => f.durationMs > max + TIMING_TOLERANCE_MS);
|
|
137
|
+
if (long.length > 0) {
|
|
138
|
+
const n = long.length;
|
|
139
|
+
const sorted = [...long].sort((a, b) => b.durationMs - a.durationMs);
|
|
140
|
+
return makeFinding(rule, m.width, "hint", `${n} ${plural(n, "frame", "frames")} took longer than ${max} ms while the page was recorded on this machine.`, listed(sorted.map((f) => `${f.step}: ${f.durationMs} ms`)));
|
|
141
|
+
}
|
|
142
|
+
const near = t.longFrames.filter((f) => f.durationMs > max - TIMING_TOLERANCE_MS);
|
|
143
|
+
if (near.length === 0) return makeFinding(rule, m.width, "pass", `No frame took longer than ${max} ms while the page was recorded on this machine.`);
|
|
144
|
+
const ms = Math.max(...near.map((f) => f.durationMs));
|
|
145
|
+
noteOn(m, `A frame of ${ms} ms is within the measurement tolerance (${TIMING_TOLERANCE_MS} ms) of the ${max} ms cutoff; long frames were not judged.`);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The score is compared as printed, to three decimals (exact, no tolerance).
|
|
150
|
+
function layoutShift(rule, m) {
|
|
151
|
+
const shift = m.motion?.timed?.shift;
|
|
152
|
+
const max = rule.threshold?.maxShift;
|
|
153
|
+
if (!shift || !Number.isFinite(max)) return null;
|
|
154
|
+
const s = shift.score.toFixed(3);
|
|
155
|
+
if (Number(s) > max) {
|
|
156
|
+
return makeFinding(rule, m.width, "hint", `Content jumped: layout shift score ${s}, above ${max}.`, listed(shift.top.map((x) => `${x.selector} moved (${x.value.toFixed(3)})`)));
|
|
157
|
+
}
|
|
158
|
+
return makeFinding(rule, m.width, "pass", `Layout shift score ${s}, at or under ${max}.`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Seconds as read: 5000 -> "5", 7012 -> "7", 1250 -> "1.3" (one decimal at most).
|
|
162
|
+
const seconds = (ms) => String(Number((ms / 1000).toFixed(1)));
|
|
163
|
+
const filmOf = (m) => (m.motion?.written ?? []).find((f) => /filmstrip\.png$/.test(f)) ?? null;
|
|
164
|
+
|
|
165
|
+
// Settle: the last change after load outside moving content, judged with TIMING_TOLERANCE_MS.
|
|
166
|
+
function settle(rule, m) {
|
|
167
|
+
const s = m.motion?.timed?.settle;
|
|
168
|
+
const max = rule.threshold?.maxSettleMs;
|
|
169
|
+
if (!s || !Number.isFinite(max)) return null;
|
|
170
|
+
// Areas that keep moving were left out of the reading (moving content judges them): say so in the text.
|
|
171
|
+
const n = s.ignoredAreas ?? 0;
|
|
172
|
+
const outside = n > 0 ? `, outside ${n} ${plural(n, "area that keeps", "areas that keep")} moving` : "";
|
|
173
|
+
if (s.unsettled) {
|
|
174
|
+
const ended = m.motion.timed.frames?.windowMs ?? s.lastChangeMs;
|
|
175
|
+
return makeFinding(rule, m.width, "hint", `The screen was still changing when the recording ended, ${ended} ms after load${outside}.`);
|
|
176
|
+
}
|
|
177
|
+
if (s.lastChangeMs > max + TIMING_TOLERANCE_MS) return makeFinding(rule, m.width, "hint", `The screen was still changing ${s.lastChangeMs} ms after load${outside}.`);
|
|
178
|
+
if (s.lastChangeMs <= max - TIMING_TOLERANCE_MS) return makeFinding(rule, m.width, "pass", `The screen was still ${s.lastChangeMs} ms after load${outside}.`);
|
|
179
|
+
noteOn(m, `The screen settled ${s.lastChangeMs} ms after load, within the measurement tolerance (${TIMING_TOLERANCE_MS} ms) of the ${max} ms cutoff; it was not judged.`);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Banding: exact readings of the lossless gradient clips.
|
|
184
|
+
function banding(rule, m) {
|
|
185
|
+
const list = m.motion?.exact?.banding;
|
|
186
|
+
const max = rule.threshold?.maxBandPx;
|
|
187
|
+
if (!Array.isArray(list) || list.length === 0 || !Number.isFinite(max)) return null;
|
|
188
|
+
const n = list.length;
|
|
189
|
+
const wide = list.filter((g) => g.widestBandPx > max);
|
|
190
|
+
if (wide.length > 0) {
|
|
191
|
+
return makeFinding(
|
|
192
|
+
rule,
|
|
193
|
+
m.width,
|
|
194
|
+
"hint",
|
|
195
|
+
`${wide.length} of ${n} ${plural(n, "gradient shows", "gradients show")} bands wider than ${max} px.`,
|
|
196
|
+
listed(wide.map((g) => `${g.selector}: bands up to ${g.widestBandPx} px, ${g.steps} steps, ${g.levelStep} ${plural(g.levelStep, "level", "levels")} apart`)),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "gradient shows", "gradients show")} no band wider than ${max} px.`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Flashes (WCAG 2.2 2.3.1, a norm): fail only on flashes in place; an over-limit count that involves
|
|
203
|
+
// movement goes to the reviewer. A count at or under the limit is not judged when frames came too slowly.
|
|
204
|
+
function flashes(rule, m) {
|
|
205
|
+
const t = m.motion?.timed;
|
|
206
|
+
const max = rule.threshold?.maxFlashes;
|
|
207
|
+
const fr = t?.frames;
|
|
208
|
+
if (!t?.flashes || !fr || !(fr.count > 0) || !Number.isFinite(max)) return null;
|
|
209
|
+
// Slow frames can only undercount, so a count over the limit stands whatever the frame interval
|
|
210
|
+
// only a count at or under the limit is left unjudged when frames came too slowly.
|
|
211
|
+
const f = t.flashes;
|
|
212
|
+
if (f.inPlace.maxPerSecond > max) {
|
|
213
|
+
return makeFinding(rule, m.width, "fail", `Content flashes ${f.inPlace.maxPerSecond} times in one second, more than ${max}.`, [`from ${f.inPlace.at} ms after load`]);
|
|
214
|
+
}
|
|
215
|
+
if (f.maxPerSecond > max) {
|
|
216
|
+
const film = filmOf(m);
|
|
217
|
+
return makeFinding(
|
|
218
|
+
rule,
|
|
219
|
+
m.width,
|
|
220
|
+
"hint",
|
|
221
|
+
`Content may flash ${f.maxPerSecond} times in one second, more than ${max}, but it moves at the same time; check the frames by eye.`,
|
|
222
|
+
[`from ${f.at} ms after load`, ...(film ? [film] : [])],
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const limit = 1000 / (2 * (max + 1));
|
|
226
|
+
if (fr.changeIntervalMs !== null && fr.changeIntervalMs > limit) {
|
|
227
|
+
noteOn(m, `Frames came every ${Math.round(fr.changeIntervalMs)} ms while the screen changed, too slow to count ${max} flashes in a second; flashes were not checked.`);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
if (fr.changeIntervalMs === null) {
|
|
231
|
+
return makeFinding(rule, m.width, "pass", `No flash in ${fr.count} frames over ${seconds(fr.windowMs)} s in the first view; the screen never changed in two frames in a row.`);
|
|
232
|
+
}
|
|
233
|
+
return makeFinding(
|
|
234
|
+
rule,
|
|
235
|
+
m.width,
|
|
236
|
+
"pass",
|
|
237
|
+
`No more than ${max} flashes in any second in the first view over ${fr.count} frames; frames came every ${Math.round(fr.changeIntervalMs)} ms while the screen changed, so a shorter flash is not seen.`,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Moving content (WCAG 2.2 2.2.2, a norm): content that moves for more than maxMovingMs needs a control
|
|
242
|
+
// named pause, stop or hide; whether it pauses that content is for the reviewer.
|
|
243
|
+
function moving(rule, m) {
|
|
244
|
+
const t = m.motion?.timed;
|
|
245
|
+
const max = rule.threshold?.maxMovingMs;
|
|
246
|
+
const list = t?.moving;
|
|
247
|
+
const w = t?.frames?.windowMs;
|
|
248
|
+
if (!Array.isArray(list) || !Number.isFinite(max) || !Number.isFinite(w)) return null;
|
|
249
|
+
if (w <= max) {
|
|
250
|
+
noteOn(m, `The recording lasted ${seconds(w)} s, not more than ${seconds(max)} s; moving content was not checked.`);
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
if (list.length === 0) return makeFinding(rule, m.width, "pass", `Nothing moved for more than ${seconds(max)} s in the first view over the ${seconds(w)} s recorded after load.`);
|
|
254
|
+
const controls = m.motion?.exact?.pauseControls ?? [];
|
|
255
|
+
if (controls.length > 0) {
|
|
256
|
+
return makeFinding(rule, m.width, "pass", `Content moves for more than ${seconds(max)} s and a control named "${controls[0].name}" was found; whether it pauses that content is for the reviewer.`);
|
|
257
|
+
}
|
|
258
|
+
return makeFinding(
|
|
259
|
+
rule,
|
|
260
|
+
m.width,
|
|
261
|
+
"fail",
|
|
262
|
+
`Content moves for more than ${seconds(max)} s and the page has no control named pause, stop or hide.`,
|
|
263
|
+
listed(list.map((x) => `${x.selector ?? `the box at ${x.box.x}, ${x.box.y}`} moved from ${x.firstMs} to ${x.lastMs} ms`)),
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export const motionEvaluators = {
|
|
268
|
+
"motion.micro-duration": microDuration,
|
|
269
|
+
"motion.transition-duration": transitionDuration,
|
|
270
|
+
"motion.easing": easing,
|
|
271
|
+
"motion.properties": properties,
|
|
272
|
+
"motion.sameness": sameness,
|
|
273
|
+
"motion.reduced": reduced,
|
|
274
|
+
"motion.long-frames": longFrames,
|
|
275
|
+
"motion.layout-shift": layoutShift,
|
|
276
|
+
"motion.settle": settle,
|
|
277
|
+
"motion.banding": banding,
|
|
278
|
+
"motion.flashes": flashes,
|
|
279
|
+
"motion.moving": moving,
|
|
280
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
|
|
4
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
5
|
+
|
|
6
|
+
// Exact comparisons, no cutoff. What was not compared (no Brand tokens, no color read, no text, a raster) is
|
|
7
|
+
// noted by the measurer; the evaluators then return null, never a vacuous pass.
|
|
8
|
+
|
|
9
|
+
function fit(rule, m) {
|
|
10
|
+
const r = m.piece;
|
|
11
|
+
if (!r) return null;
|
|
12
|
+
const canvas = `${r.width}x${r.height}`;
|
|
13
|
+
if (r.raster) {
|
|
14
|
+
if (!r.natural) return null;
|
|
15
|
+
if (r.natural.width !== r.width || r.natural.height !== r.height) {
|
|
16
|
+
return makeFinding(rule, m.width, "hint", `The image is ${r.natural.width}x${r.natural.height}, not the declared ${canvas}.`);
|
|
17
|
+
}
|
|
18
|
+
return makeFinding(rule, m.width, "pass", `The image is the declared ${canvas}.`);
|
|
19
|
+
}
|
|
20
|
+
if (!r.overflow) return null;
|
|
21
|
+
const parts = [];
|
|
22
|
+
if (r.overflow.right > 0) parts.push(`${r.overflow.right} px to the right`);
|
|
23
|
+
if (r.overflow.bottom > 0) parts.push(`${r.overflow.bottom} px below`);
|
|
24
|
+
if (parts.length) {
|
|
25
|
+
return makeFinding(rule, m.width, "hint", `The content runs past the ${canvas} canvas and is cut from the image: ${parts.join(", ")}.`);
|
|
26
|
+
}
|
|
27
|
+
return makeFinding(rule, m.width, "pass", `The content fits the ${canvas} canvas.`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function palette(rule, m) {
|
|
31
|
+
const r = m.piece;
|
|
32
|
+
if (!r || !Array.isArray(r.offBrand) || !Array.isArray(r.colors) || r.colors.length === 0) return null;
|
|
33
|
+
if (r.offBrand.length) {
|
|
34
|
+
return makeFinding(
|
|
35
|
+
rule,
|
|
36
|
+
m.width,
|
|
37
|
+
"hint",
|
|
38
|
+
`${r.offBrand.length} ${plural(r.offBrand.length, "color is not a Brand color.", "colors are not Brand colors.")}`,
|
|
39
|
+
listed(r.offBrand.map((c) => `${c.hex} on ${c.where.join(", ")}`)),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return makeFinding(rule, m.width, "pass", "Every color read from the piece is a Brand color.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fonts(rule, m) {
|
|
46
|
+
const r = m.piece;
|
|
47
|
+
if (!r || !Array.isArray(r.offBrandFonts) || !Array.isArray(r.families) || r.families.length === 0) return null;
|
|
48
|
+
if (r.offBrandFonts.length) {
|
|
49
|
+
const n = r.offBrandFonts.length;
|
|
50
|
+
return makeFinding(rule, m.width, "hint", `${n} ${plural(n, "font family is not a Brand font", "font families are not Brand fonts")}: ${r.offBrandFonts.join(", ")}.`);
|
|
51
|
+
}
|
|
52
|
+
return makeFinding(rule, m.width, "pass", "Every font family rendered is a Brand font.");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function symbol(rule, m) {
|
|
56
|
+
const r = m.piece;
|
|
57
|
+
if (!r || !r.symbol) return null;
|
|
58
|
+
if (r.symbol.file === null) {
|
|
59
|
+
return makeFinding(rule, m.width, "hint", "The piece shows no Brand symbol file (an img, an SVG image or use, or a CSS background that points to it).");
|
|
60
|
+
}
|
|
61
|
+
return makeFinding(rule, m.width, "pass", `The piece shows the Brand symbol (${r.symbol.file}) at ${r.symbol.px} px.`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const pieceEvaluators = {
|
|
65
|
+
"piece.fit": fit,
|
|
66
|
+
"piece.palette": palette,
|
|
67
|
+
"piece.fonts": fonts,
|
|
68
|
+
"piece.symbol": symbol,
|
|
69
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { NO_SCROLL_NOTE, isUnreadNote } from "../../measure/rhythm.mjs";
|
|
4
|
+
|
|
5
|
+
// No comparison with the map on a page that does not scroll (F12) or whose sections were not all read
|
|
6
|
+
// (below the cap): the map describes the whole page.
|
|
7
|
+
const notComparable = (r) => (r.notes ?? []).some((n) => n === NO_SCROLL_NOTE || isUnreadNote(n));
|
|
8
|
+
|
|
9
|
+
const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
|
|
10
|
+
const pct = (v) => `${Math.round(v * 100)}%`;
|
|
11
|
+
const ratio = (v) => (v === Infinity ? "no lower bound (the smallest is 0)" : `${Math.round(v * 100) / 100}x`);
|
|
12
|
+
const median = (xs) => {
|
|
13
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
14
|
+
const mid = Math.floor(s.length / 2);
|
|
15
|
+
return s.length % 2 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
|
|
16
|
+
};
|
|
17
|
+
const sectionLine = (s) => `${s.selector}: ${s.heightVh} viewports, density ${s.density}, scale ${s.scale ?? "none"}`;
|
|
18
|
+
|
|
19
|
+
function pace(rule, m) {
|
|
20
|
+
const r = m.rhythm;
|
|
21
|
+
const t = rule.threshold;
|
|
22
|
+
if (!r || !hasNumbers(t, ["minSections", "minHeightRatio", "minDensityRatio"])) return null;
|
|
23
|
+
const sections = r.sections ?? [];
|
|
24
|
+
if (sections.length < t.minSections) return null;
|
|
25
|
+
const heights = sections.map((s) => s.heightVh);
|
|
26
|
+
// Raw densities when the report has them, so the rounding place never decides whether the sparsest is 0.
|
|
27
|
+
const densities = Array.isArray(r.densityRaw) && r.densityRaw.length === sections.length ? r.densityRaw : sections.map((s) => s.density);
|
|
28
|
+
const heightRatio = Math.min(...heights) > 0 ? Math.max(...heights) / Math.min(...heights) : Infinity;
|
|
29
|
+
// A sparsest density of 0 counts as above the cutoff.
|
|
30
|
+
const densityRatio = Math.min(...densities) > 0 ? Math.max(...densities) / Math.min(...densities) : Infinity;
|
|
31
|
+
const evidence = [
|
|
32
|
+
`tallest section: ${ratio(heightRatio)} the shortest (cutoff ${t.minHeightRatio}x)`,
|
|
33
|
+
`densest section: ${ratio(densityRatio)} the sparsest (cutoff ${t.minDensityRatio}x)`,
|
|
34
|
+
];
|
|
35
|
+
if (heightRatio < t.minHeightRatio && densityRatio < t.minDensityRatio) {
|
|
36
|
+
return makeFinding(rule, m.width, "hint", `The ${sections.length} sections keep one pace: their heights and their densities stay close, so the scroll repeats one beat.`, evidence);
|
|
37
|
+
}
|
|
38
|
+
return makeFinding(rule, m.width, "pass", `The ${sections.length} sections change pace in height or in density.`, evidence);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function map(rule, m) {
|
|
42
|
+
const r = m.rhythm;
|
|
43
|
+
if (!r || notComparable(r)) return null;
|
|
44
|
+
if (!r.declared) {
|
|
45
|
+
if (!r.hasGoal) return null;
|
|
46
|
+
return makeFinding(rule, m.width, "hint", "No rhythm map is declared for this page. Add a Rhythm line under its goal in LAZULI.md.");
|
|
47
|
+
}
|
|
48
|
+
const beats = r.declared.beats;
|
|
49
|
+
const sections = r.sections ?? [];
|
|
50
|
+
if (beats.length !== sections.length) {
|
|
51
|
+
return makeFinding(rule, m.width, "hint", `The map declares ${beats.length} beats and the page has ${sections.length} sections.`, listed(sections.map(sectionLine)));
|
|
52
|
+
}
|
|
53
|
+
const mid = median(sections.map((s) => s.density));
|
|
54
|
+
const off = [];
|
|
55
|
+
sections.forEach((s, i) => {
|
|
56
|
+
// A difference within one row of the coverage grid (densityStep) is below what was measured; reports
|
|
57
|
+
// made before 1.0.1 have no densityStep and compare with the median itself.
|
|
58
|
+
const step = Number.isFinite(s.densityStep) ? s.densityStep : 0;
|
|
59
|
+
if (beats[i] === "breathe" && s.density - mid > step) off.push(`${s.selector}: the map says breathe and its density ${s.density} is above the median ${mid}`);
|
|
60
|
+
if (beats[i] === "accelerate" && mid - s.density > step) off.push(`${s.selector}: the map says accelerate and its density ${s.density} is below the median ${mid}`);
|
|
61
|
+
});
|
|
62
|
+
if (off.length) {
|
|
63
|
+
return makeFinding(rule, m.width, "hint", `${off.length} of ${sections.length} sections do not follow the rhythm map of ${r.declared.piece}.`, listed(off));
|
|
64
|
+
}
|
|
65
|
+
return makeFinding(rule, m.width, "pass", `The sections follow the rhythm map of ${r.declared.piece}.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Compared by scroll position, never by section index: the map's climax beat sits at (index + 0.5) / beats.
|
|
69
|
+
function climax(rule, m) {
|
|
70
|
+
const r = m.rhythm;
|
|
71
|
+
const t = rule.threshold;
|
|
72
|
+
if (!r || !r.declared || !r.climax || !hasNumbers(t, ["maxShift"]) || notComparable(r)) return null;
|
|
73
|
+
const beats = r.declared.beats;
|
|
74
|
+
const at = beats.indexOf("climax");
|
|
75
|
+
if (at < 0) return null;
|
|
76
|
+
const declared = (at + 0.5) / beats.length;
|
|
77
|
+
const { position } = r.climax;
|
|
78
|
+
const where = r.sections?.[r.climax.index]?.selector ?? `section ${r.climax.index + 1}`;
|
|
79
|
+
const evidence = [
|
|
80
|
+
`map: climax is beat ${at + 1} of ${beats.length}, at ${pct(declared)} of the page`,
|
|
81
|
+
`measured: the largest type is in ${where}, centered at ${pct(position)} of the page`,
|
|
82
|
+
];
|
|
83
|
+
if (Math.abs(declared - position) > t.maxShift) {
|
|
84
|
+
return makeFinding(
|
|
85
|
+
rule,
|
|
86
|
+
m.width,
|
|
87
|
+
"hint",
|
|
88
|
+
`The map puts the climax at ${pct(declared)} of the page, but the largest type sits at ${pct(position)} (${where}), more than ${pct(t.maxShift)} away.`,
|
|
89
|
+
evidence,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return makeFinding(rule, m.width, "pass", `The largest type sits at ${pct(position)} of the page, where the map puts the climax (${pct(declared)}).`, evidence);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const rhythmEvaluators = {
|
|
96
|
+
"rhythm.pace": pace,
|
|
97
|
+
"rhythm.map": map,
|
|
98
|
+
"rhythm.climax": climax,
|
|
99
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
|
|
4
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
5
|
+
const PARTS = "on the element, its ::before, ::after or its children.";
|
|
6
|
+
|
|
7
|
+
// Only what was checked is claimed: a hover made by a script or styled on a parent is not seen.
|
|
8
|
+
const forcedState = (key, under) => (rule, m) => {
|
|
9
|
+
const r = m.states?.[key];
|
|
10
|
+
if (!r || !(r.checked > 0)) return null;
|
|
11
|
+
const n = r.unchanged.length;
|
|
12
|
+
if (n > 0) {
|
|
13
|
+
return makeFinding(rule, m.width, "hint", `${n} of ${r.checked} control looks show no change ${under} ${PARTS}`, listed(r.unchanged));
|
|
14
|
+
}
|
|
15
|
+
return makeFinding(rule, m.width, "pass", `All ${r.checked} control looks change ${under}.`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const alikeState = (key, what, peer) => (rule, m) => {
|
|
19
|
+
const r = m.states?.[key];
|
|
20
|
+
if (!r || !(r.checked > 0)) return null;
|
|
21
|
+
const n = r.alike.length;
|
|
22
|
+
if (n > 0) {
|
|
23
|
+
return makeFinding(
|
|
24
|
+
rule,
|
|
25
|
+
m.width,
|
|
26
|
+
"hint",
|
|
27
|
+
`${n} ${plural(n, `${what.one} looks`, `${what.many} look`)} exactly like ${peer}.`,
|
|
28
|
+
listed(r.alike.map((a) => `${a.control} looks like ${a.like}`)),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return makeFinding(rule, m.width, "pass", `${r.checked} ${plural(r.checked, what.one, what.many)} checked; none looks exactly like ${peer}.`);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const statesEvaluators = {
|
|
35
|
+
"states.hover": forcedState("hover", "under :hover"),
|
|
36
|
+
"states.active": forcedState("active", "when pressed (:active)"),
|
|
37
|
+
"states.disabled": alikeState("disabled", { one: "disabled control", many: "disabled controls" }, "an enabled one"),
|
|
38
|
+
"states.invalid": alikeState("invalid", { one: "field marked aria-invalid", many: "fields marked aria-invalid" }, "a valid one"),
|
|
39
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
|
|
3
|
+
function value(rule, m) {
|
|
4
|
+
const s = m.style;
|
|
5
|
+
if (!s) return null;
|
|
6
|
+
const entry = s.rules?.[rule.id];
|
|
7
|
+
if (!entry) return null;
|
|
8
|
+
const t = rule.threshold ?? {};
|
|
9
|
+
const count = entry.offending ?? entry.offenders.length;
|
|
10
|
+
if (count > 0) {
|
|
11
|
+
const first = entry.offenders[0];
|
|
12
|
+
return makeFinding(
|
|
13
|
+
rule,
|
|
14
|
+
m.width,
|
|
15
|
+
"fail",
|
|
16
|
+
`${count} ${count === 1 ? "element" : "elements"} matching ${t.selector} have ${t.property} ${first?.value ?? ""}`.trimEnd(),
|
|
17
|
+
[
|
|
18
|
+
...new Set(entry.offenders.map((o) => o.selector)),
|
|
19
|
+
...(rule.origin === "project" && rule.source ? [`Learned rule from the person: ${rule.source}`] : []),
|
|
20
|
+
],
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const compared = entry.compared ?? entry.checked;
|
|
24
|
+
if (compared > 0) {
|
|
25
|
+
return makeFinding(rule, m.width, "pass", `${compared} ${compared === 1 ? "element" : "elements"} matching ${t.selector} keep ${t.property} within the rule.`);
|
|
26
|
+
}
|
|
27
|
+
// Visible elements that could not be compared already carry a note from the measurer.
|
|
28
|
+
if (entry.checked > 0) return null;
|
|
29
|
+
const note = `${rule.id}: no visible element matches ${t.selector}`;
|
|
30
|
+
if (!Array.isArray(s.notes)) s.notes = [];
|
|
31
|
+
if (!s.notes.includes(note)) s.notes.push(note);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const styleEvaluators = { "style.value": value };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { listed } from "../evidence.mjs";
|
|
3
|
+
import { BACKGROUNDS } from "../../measure/symbol.mjs";
|
|
4
|
+
|
|
5
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
6
|
+
// A share in 0 to 1 as a percent with at most one decimal (0.035 gives 3.5, never 3.5000000000000004).
|
|
7
|
+
const pct = (x) => String(+(x * 100).toFixed(1));
|
|
8
|
+
// What was not compared (an opaque box, a raster, no stroke) is noted by the measurer; the evaluators then
|
|
9
|
+
// return null, never a vacuous pass.
|
|
10
|
+
|
|
11
|
+
function silhouette(rule, m) {
|
|
12
|
+
const r = m.symbol;
|
|
13
|
+
const p = rule.threshold?.minOverlap;
|
|
14
|
+
if (!r || !Array.isArray(r.silhouette) || r.silhouette.length === 0 || !Number.isFinite(p)) return null;
|
|
15
|
+
const under = r.silhouette.filter((x) => x.overlap < p);
|
|
16
|
+
if (under.length) {
|
|
17
|
+
return makeFinding(
|
|
18
|
+
rule,
|
|
19
|
+
m.width,
|
|
20
|
+
"hint",
|
|
21
|
+
`The silhouette keeps less than ${pct(p)}% of its large shape at ${under.map((x) => x.size).join(", ")} px.`,
|
|
22
|
+
listed(under.map((x) => `${x.size} px: ${pct(x.overlap)}% of the shape at ${r.ref} px`)),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const min = Math.min(...r.silhouette.map((x) => x.size));
|
|
26
|
+
return makeFinding(rule, m.width, "pass", `The silhouette keeps at least ${pct(p)}% of its large shape down to ${min} px.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Parts of at least minPartShare of their file. A size draws every part when each such part of the file that
|
|
30
|
+
// renders it is kept there; the smallest such size counts only while every larger size draws every part too.
|
|
31
|
+
function detail(rule, m) {
|
|
32
|
+
const r = m.symbol;
|
|
33
|
+
const p = rule.threshold?.minPartShare;
|
|
34
|
+
if (!r || !Array.isArray(r.parts) || !Number.isFinite(p)) return null;
|
|
35
|
+
const parts = r.parts.filter((x) => x.share >= p);
|
|
36
|
+
if (parts.length === 0) return null;
|
|
37
|
+
const sizes = [...r.sizes].sort((a, b) => b - a);
|
|
38
|
+
const min = sizes.at(-1);
|
|
39
|
+
const lost = parts.filter((x) => x.lostAt.length > 0);
|
|
40
|
+
if (lost.length === 0) {
|
|
41
|
+
return makeFinding(rule, m.width, "pass", `Every part of the symbol of at least ${pct(p)}% of it is still drawn at ${min} px.`);
|
|
42
|
+
}
|
|
43
|
+
const drawsAll = (s) => parts.filter((x) => x.keptAt.includes(s) || x.lostAt.includes(s)).every((x) => x.keptAt.includes(s));
|
|
44
|
+
let smallest = null;
|
|
45
|
+
for (const s of sizes) {
|
|
46
|
+
if (!drawsAll(s)) break;
|
|
47
|
+
smallest = s;
|
|
48
|
+
}
|
|
49
|
+
const n = lost.length;
|
|
50
|
+
const head = `${n} ${plural(n, "part of the symbol is", "parts of the symbol are")} not drawn at small sizes`;
|
|
51
|
+
const tail = smallest !== null && smallest < r.ref ? `the smallest size that draws every part is ${smallest} px.` : `no size below ${r.ref} px draws every part.`;
|
|
52
|
+
return makeFinding(
|
|
53
|
+
rule,
|
|
54
|
+
m.width,
|
|
55
|
+
"hint",
|
|
56
|
+
`${head}; ${tail}`,
|
|
57
|
+
listed(lost.map((x) => `${x.hex} (${pct(x.share)}% of the symbol) is gone at ${x.lostAt.join(", ")} px`)),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function stroke(rule, m) {
|
|
62
|
+
const r = m.symbol;
|
|
63
|
+
const min = rule.threshold?.minStrokePx;
|
|
64
|
+
if (!r || !Array.isArray(r.strokes) || r.strokes.length === 0 || !Array.isArray(r.thinnest) || r.thinnest.length === 0 || !Number.isFinite(min)) return null;
|
|
65
|
+
const under = r.thinnest.filter((x) => x.px < min);
|
|
66
|
+
if (under.length) {
|
|
67
|
+
return makeFinding(
|
|
68
|
+
rule,
|
|
69
|
+
m.width,
|
|
70
|
+
"hint",
|
|
71
|
+
`Strokes go under ${min} px at ${under.map((x) => x.size).join(", ")} px.`,
|
|
72
|
+
listed(under.map((x) => `${x.size} px: ${x.selector} is ${x.px} px`)),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const smallest = Math.min(...r.thinnest.map((x) => x.size));
|
|
76
|
+
return makeFinding(rule, m.width, "pass", `Every stroke stays at ${min} px or more down to ${smallest} px.`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The message names each background under the cutoff with its count of sizes; the evidence lists each
|
|
80
|
+
// background and size.
|
|
81
|
+
function contrast(rule, m) {
|
|
82
|
+
const r = m.symbol;
|
|
83
|
+
const min = rule.threshold?.minContrast;
|
|
84
|
+
if (!r || !Array.isArray(r.contrast) || !Number.isFinite(min)) return null;
|
|
85
|
+
const read = r.contrast.filter((x) => x.median !== null);
|
|
86
|
+
if (read.length === 0) return null;
|
|
87
|
+
const under = read.filter((x) => x.median < min);
|
|
88
|
+
if (under.length) {
|
|
89
|
+
const on = BACKGROUNDS.map((b) => {
|
|
90
|
+
const n = new Set(under.filter((x) => x.background === b.name).map((x) => x.size)).size;
|
|
91
|
+
return n > 0 ? `on ${b.name} (${b.hex}) at ${n} ${plural(n, "size", "sizes")}` : null;
|
|
92
|
+
}).filter(Boolean);
|
|
93
|
+
return makeFinding(
|
|
94
|
+
rule,
|
|
95
|
+
m.width,
|
|
96
|
+
"hint",
|
|
97
|
+
`Half of the symbol's edge is under ${min}:1 ${on.join(" and ")}.`,
|
|
98
|
+
listed(under.map((x) => `On ${x.background} (${x.hex}) at ${x.size} px: median edge contrast ${x.median}:1`)),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const on = BACKGROUNDS.map((b) => `${b.name} (${b.hex})`).join(" and ");
|
|
102
|
+
return makeFinding(rule, m.width, "pass", `Half of the symbol's edge or more reaches ${min}:1 on ${on} at every size.`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const symbolEvaluators = {
|
|
106
|
+
"symbol.silhouette": silhouette,
|
|
107
|
+
"symbol.detail": detail,
|
|
108
|
+
"symbol.stroke": stroke,
|
|
109
|
+
"symbol.contrast": contrast,
|
|
110
|
+
};
|