@uselazuli/cli 0.0.0-stage → 1.0.1
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 +98 -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 +699 -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 +18 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +347 -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 +17 -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 +242 -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 +219 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +399 -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 +180 -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 +35 -0
- package/skills/lazuli/procedures/show-options.md +32 -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 +39 -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 +43 -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 +161 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +428 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +97 -0
- package/src/commands/draft-memo.mjs +161 -0
- package/src/commands/hooks.mjs +343 -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 +296 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +164 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +383 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +549 -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 +79 -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 +489 -0
- package/src/measure/in-page/color.js +346 -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 +355 -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 +169 -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 +266 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +91 -0
- package/src/measure/motion.mjs +508 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +252 -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 +159 -0
- package/src/project/lazuli-md.mjs +497 -0
- package/src/project/log.mjs +329 -0
- package/src/project/match.mjs +112 -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 +206 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +86 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +53 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +94 -0
- package/src/report/evaluators/motion.mjs +273 -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 +163 -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 +256 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +212 -0
- package/templates/LAZULI.md +86 -0
|
@@ -0,0 +1,53 @@
|
|
|
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 quoted = (t) => `"${t.text}" (${t.selector})`;
|
|
7
|
+
const cutHow = { ellipsis: ", with an ellipsis", clamped: ", clamped" };
|
|
8
|
+
// A case that did not run, failed or was not compared is noted by the measurer; the evaluators then return
|
|
9
|
+
// null, never a vacuous pass.
|
|
10
|
+
|
|
11
|
+
// The finding of one case: a hint naming what the case adds, else a pass.
|
|
12
|
+
function judge(rule, m, kind, words) {
|
|
13
|
+
const c = m.extreme?.cases?.[kind];
|
|
14
|
+
const b = c?.breaks;
|
|
15
|
+
if (!c || !c.ran || !b) return null;
|
|
16
|
+
const parts = [];
|
|
17
|
+
if (Number.isFinite(b.overflowX) && b.overflowX > 0) parts.push(`the page scrolls sideways by ${Math.round(b.overflowX)} px`);
|
|
18
|
+
const n = (list) => list?.length ?? 0;
|
|
19
|
+
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")}`);
|
|
20
|
+
if (n(b.cut)) parts.push(`${n(b.cut)} ${plural(n(b.cut), "text is cut", "texts are cut")}`);
|
|
21
|
+
if (n(b.lost)) parts.push(`${n(b.lost)} ${plural(n(b.lost), "text is cut away entirely", "texts are cut away entirely")}`);
|
|
22
|
+
if (n(b.overlaps)) parts.push(`${n(b.overlaps)} ${plural(n(b.overlaps), "pair of texts overlaps", "pairs of texts overlap")}`);
|
|
23
|
+
if (parts.length === 0) {
|
|
24
|
+
return makeFinding(rule, m.width, "pass", `With ${words}, nothing new spills, is cut or overlaps at ${m.width} px.`);
|
|
25
|
+
}
|
|
26
|
+
const evidence = [
|
|
27
|
+
...(b.spills ?? []).map((t) => `spills: ${quoted(t)}`),
|
|
28
|
+
...(b.cut ?? []).map((t) => `cut: ${quoted(t)}${cutHow[t.cut] ?? ""}`),
|
|
29
|
+
...(b.lost ?? []).map((t) => `cut away: ${quoted(t)}`),
|
|
30
|
+
...(b.overlaps ?? []).map(([a, x]) => `overlap: ${quoted(a)} and ${quoted(x)}`),
|
|
31
|
+
];
|
|
32
|
+
return makeFinding(rule, m.width, "hint", `With ${words}, things break at ${m.width} px: ${parts.join(", ")}.`, listed(evidence));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function growth(rule, m) {
|
|
36
|
+
const g = rule.threshold?.growth;
|
|
37
|
+
if (!Number.isFinite(g)) return null;
|
|
38
|
+
return judge(rule, m, "growth", caseWords("growth", { growth: g }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const listCase = (kind) => (rule, m) => {
|
|
42
|
+
const c = m.extreme?.cases?.[kind];
|
|
43
|
+
if (!c) return null;
|
|
44
|
+
return judge(rule, m, kind, caseWords(kind, { lists: c.lists, shortLists: c.shortLists }));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const extremeEvaluators = {
|
|
48
|
+
"extreme.growth": growth,
|
|
49
|
+
"extreme.long-text": (rule, m) => judge(rule, m, "long-text", caseWords("long-text")),
|
|
50
|
+
"extreme.empty": listCase("empty"),
|
|
51
|
+
"extreme.one": listCase("one"),
|
|
52
|
+
"extreme.many": listCase("many"),
|
|
53
|
+
};
|
|
@@ -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,94 @@
|
|
|
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
|
+
function focalPoint(rule, m) {
|
|
48
|
+
const r = m.layout;
|
|
49
|
+
const t = rule.threshold;
|
|
50
|
+
if (!r || !hasNumbers(t, ["minDominance"]) || !r.focal) return null;
|
|
51
|
+
const f = r.focal;
|
|
52
|
+
if (f.dominance === null) return makeFinding(rule, m.width, "pass", `The first view has one block, ${f.selector}.`);
|
|
53
|
+
const evidence = [`${f.selector}: ${f.dominance}x the next largest block, center at ${pct(f.x)} across and ${pct(f.y)} down`];
|
|
54
|
+
if (f.dominance < t.minDominance) {
|
|
55
|
+
return makeFinding(rule, m.width, "hint", `No block leads the first view: the largest is ${f.dominance}x the next (cutoff ${t.minDominance}x).`, evidence);
|
|
56
|
+
}
|
|
57
|
+
return makeFinding(rule, m.width, "pass", `${f.selector} leads the first view at ${f.dominance}x the next block.`, evidence);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// UG2: judged only from minViewport up; at a phone width almost every page is one centered column.
|
|
61
|
+
function grid(rule, m) {
|
|
62
|
+
const r = m.layout;
|
|
63
|
+
const t = rule.threshold;
|
|
64
|
+
if (!r || !hasNumbers(t, ["minViewport"]) || (r.sections ?? []).length < 2) return null;
|
|
65
|
+
if (!(m.width >= t.minViewport)) return null;
|
|
66
|
+
if (r.uniformGrid) {
|
|
67
|
+
const s = r.sections.find((x) => x.left !== null);
|
|
68
|
+
return makeFinding(
|
|
69
|
+
rule,
|
|
70
|
+
m.width,
|
|
71
|
+
"hint",
|
|
72
|
+
`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.`,
|
|
73
|
+
listed(r.sections.map((x) => `${x.selector}: ${x.left} px to ${x.right} px`)),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return makeFinding(rule, m.width, "pass", "Sections do not all sit in one centered container.");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// AP5: read at every checked width; the composition tolerance decides, so the rule has no threshold.
|
|
80
|
+
// Always a hint at most: the 320 px norm is AP2.
|
|
81
|
+
function sideways(rule, m) {
|
|
82
|
+
const r = m.layout;
|
|
83
|
+
if (!r || typeof r.sideways !== "boolean") return null;
|
|
84
|
+
if (r.sideways) return makeFinding(rule, m.width, "hint", `At ${m.width} px the page scrolls sideways (content ${r.scrollWidth} px wide).`);
|
|
85
|
+
return makeFinding(rule, m.width, "pass", `At ${m.width} px the page does not scroll sideways.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const layoutEvaluators = {
|
|
89
|
+
"layout.sideways": sideways,
|
|
90
|
+
"layout.scale-contrast": scaleContrast,
|
|
91
|
+
"layout.empty-space": emptySpace,
|
|
92
|
+
"layout.focal-point": focalPoint,
|
|
93
|
+
"layout.grid": grid,
|
|
94
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
const LINEAR = new Set(["linear", "cubic-bezier(0, 0, 1, 1)"]);
|
|
14
|
+
const listing = (props) => props.join(" and ");
|
|
15
|
+
|
|
16
|
+
function noteOn(m, text) {
|
|
17
|
+
const r = m.motion;
|
|
18
|
+
if (!Array.isArray(r.notes)) r.notes = [];
|
|
19
|
+
if (!r.notes.includes(text)) r.notes.push(text);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const animationsOf = (m) => m.motion?.exact?.animations ?? null;
|
|
23
|
+
const durationLine = (a) => `${a.selector} on ${a.trigger}: ${a.name}, ${a.endMs} ms`;
|
|
24
|
+
const longestFirst = (list) => [...list].sort((a, b) => b.endMs - a.endMs);
|
|
25
|
+
|
|
26
|
+
function microDuration(rule, m) {
|
|
27
|
+
const all = animationsOf(m);
|
|
28
|
+
const maxMs = rule.threshold?.maxMs;
|
|
29
|
+
if (!all || !Number.isFinite(maxMs)) return null;
|
|
30
|
+
const list = all.filter((a) => MICRO.has(a.trigger) && finite(a));
|
|
31
|
+
if (list.length === 0) return null;
|
|
32
|
+
const long = list.filter((a) => a.endMs > maxMs);
|
|
33
|
+
if (long.length > 0) {
|
|
34
|
+
const n = long.length;
|
|
35
|
+
return makeFinding(rule, m.width, "hint", `${n} ${plural(n, "microinteraction takes", "microinteractions take")} longer than ${maxMs} ms.`, listed(longestFirst(long).map(durationLine)));
|
|
36
|
+
}
|
|
37
|
+
const n = list.length;
|
|
38
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "microinteraction finishes", "microinteractions finish")} within ${maxMs} ms.`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function transitionDuration(rule, m) {
|
|
42
|
+
const all = animationsOf(m);
|
|
43
|
+
const maxMs = rule.threshold?.maxMs;
|
|
44
|
+
if (!all || !Number.isFinite(maxMs)) return null;
|
|
45
|
+
const list = all.filter((a) => PAGE.has(a.trigger) && finite(a));
|
|
46
|
+
if (list.length === 0) return null;
|
|
47
|
+
const long = list.filter((a) => a.endMs > maxMs);
|
|
48
|
+
if (long.length > 0) {
|
|
49
|
+
const n = long.length;
|
|
50
|
+
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)));
|
|
51
|
+
}
|
|
52
|
+
const n = list.length;
|
|
53
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "transition or entrance finishes", "transitions and entrances finish")} within ${maxMs} ms, delay included.`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function easing(rule, m) {
|
|
57
|
+
const all = animationsOf(m);
|
|
58
|
+
if (!all) return null;
|
|
59
|
+
const list = all.filter((a) => finite(a) && a.moves);
|
|
60
|
+
if (list.length === 0) return null;
|
|
61
|
+
const linear = list.filter((a) => LINEAR.has(a.easing));
|
|
62
|
+
if (linear.length > 0) {
|
|
63
|
+
const n = linear.length;
|
|
64
|
+
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}`)));
|
|
65
|
+
}
|
|
66
|
+
const n = list.length;
|
|
67
|
+
return makeFinding(rule, m.width, "pass", `None of the ${n} moving ${plural(n, "animation", "animations")} runs at a constant speed.`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function properties(rule, m) {
|
|
71
|
+
const all = animationsOf(m);
|
|
72
|
+
if (!all || all.length === 0) return null;
|
|
73
|
+
const layout = all.filter((a) => a.layoutProps.length > 0);
|
|
74
|
+
if (layout.length > 0) {
|
|
75
|
+
const n = layout.length;
|
|
76
|
+
return makeFinding(
|
|
77
|
+
rule,
|
|
78
|
+
m.width,
|
|
79
|
+
"hint",
|
|
80
|
+
`${n} ${plural(n, "animation changes", "animations change")} layout properties, which lays the page out again on every frame.`,
|
|
81
|
+
listed(layout.map((a) => `${a.selector}: ${a.layoutProps.join(", ")}`)),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
const n = all.length;
|
|
85
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "animation changes", "animations change")} no layout property.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Two entrances are the same animation when they change the same properties between the same values over
|
|
89
|
+
// the same duration with the same curve; delay and name do not count (a stagger of
|
|
90
|
+
// one fade is one animation).
|
|
91
|
+
const sameKey = (a) => JSON.stringify([a.properties, a.from, a.to, a.durationMs, a.easing]);
|
|
92
|
+
|
|
93
|
+
function sameness(rule, m) {
|
|
94
|
+
const all = animationsOf(m);
|
|
95
|
+
const min = rule.threshold?.minEntrances;
|
|
96
|
+
if (!all || !Number.isFinite(min)) return null;
|
|
97
|
+
const list = all.filter((a) => a.entrance);
|
|
98
|
+
if (list.length < min) return null;
|
|
99
|
+
const kinds = new Set(list.map(sameKey));
|
|
100
|
+
const n = list.length;
|
|
101
|
+
if (kinds.size === 1) {
|
|
102
|
+
const a = list[0];
|
|
103
|
+
return makeFinding(rule, m.width, "hint", `All ${n} entrances are the same animation: ${listing(a.properties)} over ${a.durationMs} ms, ${a.easing}.`);
|
|
104
|
+
}
|
|
105
|
+
return makeFinding(rule, m.width, "pass", `The ${n} entrances use ${kinds.size} different animations.`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function reduced(rule, m) {
|
|
109
|
+
const r = m.motion?.exact?.reduced;
|
|
110
|
+
if (!r || !(r.moving > 0)) return null;
|
|
111
|
+
const n = r.moving;
|
|
112
|
+
const k = r.kept.length;
|
|
113
|
+
if (k > 0) {
|
|
114
|
+
return makeFinding(
|
|
115
|
+
rule,
|
|
116
|
+
m.width,
|
|
117
|
+
"hint",
|
|
118
|
+
`${k} of ${n} moving ${plural(n, "animation", "animations")} still ${plural(k, "moves", "move")} with reduced motion asked for.`,
|
|
119
|
+
listed(r.kept.map((a) => `${a.selector}: ${a.name} (${a.properties.join(", ")})`)),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return makeFinding(rule, m.width, "pass", `With reduced motion asked for, none of the ${n} moving ${plural(n, "animation", "animations")} still moves.`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function longFrames(rule, m) {
|
|
126
|
+
const t = m.motion?.timed;
|
|
127
|
+
const max = rule.threshold?.maxFrameMs;
|
|
128
|
+
if (!t || t.longFrameApi == null || !Array.isArray(t.longFrames) || !Number.isFinite(max)) return null;
|
|
129
|
+
const long = t.longFrames.filter((f) => f.durationMs > max + TIMING_TOLERANCE_MS);
|
|
130
|
+
if (long.length > 0) {
|
|
131
|
+
const n = long.length;
|
|
132
|
+
const sorted = [...long].sort((a, b) => b.durationMs - a.durationMs);
|
|
133
|
+
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`)));
|
|
134
|
+
}
|
|
135
|
+
const near = t.longFrames.filter((f) => f.durationMs > max - TIMING_TOLERANCE_MS);
|
|
136
|
+
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.`);
|
|
137
|
+
const ms = Math.max(...near.map((f) => f.durationMs));
|
|
138
|
+
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.`);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// The score is compared as printed, to three decimals (exact, no tolerance).
|
|
143
|
+
function layoutShift(rule, m) {
|
|
144
|
+
const shift = m.motion?.timed?.shift;
|
|
145
|
+
const max = rule.threshold?.maxShift;
|
|
146
|
+
if (!shift || !Number.isFinite(max)) return null;
|
|
147
|
+
const s = shift.score.toFixed(3);
|
|
148
|
+
if (Number(s) > max) {
|
|
149
|
+
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)})`)));
|
|
150
|
+
}
|
|
151
|
+
return makeFinding(rule, m.width, "pass", `Layout shift score ${s}, at or under ${max}.`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Seconds as read: 5000 -> "5", 7012 -> "7", 1250 -> "1.3" (one decimal at most).
|
|
155
|
+
const seconds = (ms) => String(Number((ms / 1000).toFixed(1)));
|
|
156
|
+
const filmOf = (m) => (m.motion?.written ?? []).find((f) => /filmstrip\.png$/.test(f)) ?? null;
|
|
157
|
+
|
|
158
|
+
// Settle: the last change after load outside moving content, judged with TIMING_TOLERANCE_MS.
|
|
159
|
+
function settle(rule, m) {
|
|
160
|
+
const s = m.motion?.timed?.settle;
|
|
161
|
+
const max = rule.threshold?.maxSettleMs;
|
|
162
|
+
if (!s || !Number.isFinite(max)) return null;
|
|
163
|
+
// Areas that keep moving were left out of the reading (moving content judges them): say so in the text.
|
|
164
|
+
const n = s.ignoredAreas ?? 0;
|
|
165
|
+
const outside = n > 0 ? `, outside ${n} ${plural(n, "area that keeps", "areas that keep")} moving` : "";
|
|
166
|
+
if (s.unsettled) {
|
|
167
|
+
const ended = m.motion.timed.frames?.windowMs ?? s.lastChangeMs;
|
|
168
|
+
return makeFinding(rule, m.width, "hint", `The screen was still changing when the recording ended, ${ended} ms after load${outside}.`);
|
|
169
|
+
}
|
|
170
|
+
if (s.lastChangeMs > max + TIMING_TOLERANCE_MS) return makeFinding(rule, m.width, "hint", `The screen was still changing ${s.lastChangeMs} ms after load${outside}.`);
|
|
171
|
+
if (s.lastChangeMs <= max - TIMING_TOLERANCE_MS) return makeFinding(rule, m.width, "pass", `The screen was still ${s.lastChangeMs} ms after load${outside}.`);
|
|
172
|
+
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.`);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Banding: exact readings of the lossless gradient clips.
|
|
177
|
+
function banding(rule, m) {
|
|
178
|
+
const list = m.motion?.exact?.banding;
|
|
179
|
+
const max = rule.threshold?.maxBandPx;
|
|
180
|
+
if (!Array.isArray(list) || list.length === 0 || !Number.isFinite(max)) return null;
|
|
181
|
+
const n = list.length;
|
|
182
|
+
const wide = list.filter((g) => g.widestBandPx > max);
|
|
183
|
+
if (wide.length > 0) {
|
|
184
|
+
return makeFinding(
|
|
185
|
+
rule,
|
|
186
|
+
m.width,
|
|
187
|
+
"hint",
|
|
188
|
+
`${wide.length} of ${n} ${plural(n, "gradient shows", "gradients show")} bands wider than ${max} px.`,
|
|
189
|
+
listed(wide.map((g) => `${g.selector}: bands up to ${g.widestBandPx} px, ${g.steps} steps, ${g.levelStep} ${plural(g.levelStep, "level", "levels")} apart`)),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return makeFinding(rule, m.width, "pass", `${n} ${plural(n, "gradient shows", "gradients show")} no band wider than ${max} px.`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Flashes (WCAG 2.2 2.3.1, a norm): fail only on flashes in place; an over-limit count that involves
|
|
196
|
+
// movement goes to the reviewer. A count at or under the limit is not judged when frames came too slowly.
|
|
197
|
+
function flashes(rule, m) {
|
|
198
|
+
const t = m.motion?.timed;
|
|
199
|
+
const max = rule.threshold?.maxFlashes;
|
|
200
|
+
const fr = t?.frames;
|
|
201
|
+
if (!t?.flashes || !fr || !(fr.count > 0) || !Number.isFinite(max)) return null;
|
|
202
|
+
// Slow frames can only undercount, so a count over the limit stands whatever the frame interval
|
|
203
|
+
// only a count at or under the limit is left unjudged when frames came too slowly.
|
|
204
|
+
const f = t.flashes;
|
|
205
|
+
if (f.inPlace.maxPerSecond > max) {
|
|
206
|
+
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`]);
|
|
207
|
+
}
|
|
208
|
+
if (f.maxPerSecond > max) {
|
|
209
|
+
const film = filmOf(m);
|
|
210
|
+
return makeFinding(
|
|
211
|
+
rule,
|
|
212
|
+
m.width,
|
|
213
|
+
"hint",
|
|
214
|
+
`Content may flash ${f.maxPerSecond} times in one second, more than ${max}, but it moves at the same time; check the frames by eye.`,
|
|
215
|
+
[`from ${f.at} ms after load`, ...(film ? [film] : [])],
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const limit = 1000 / (2 * (max + 1));
|
|
219
|
+
if (fr.changeIntervalMs !== null && fr.changeIntervalMs > limit) {
|
|
220
|
+
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.`);
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
if (fr.changeIntervalMs === null) {
|
|
224
|
+
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.`);
|
|
225
|
+
}
|
|
226
|
+
return makeFinding(
|
|
227
|
+
rule,
|
|
228
|
+
m.width,
|
|
229
|
+
"pass",
|
|
230
|
+
`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.`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Moving content (WCAG 2.2 2.2.2, a norm): content that moves for more than maxMovingMs needs a control
|
|
235
|
+
// named pause, stop or hide; whether it pauses that content is for the reviewer.
|
|
236
|
+
function moving(rule, m) {
|
|
237
|
+
const t = m.motion?.timed;
|
|
238
|
+
const max = rule.threshold?.maxMovingMs;
|
|
239
|
+
const list = t?.moving;
|
|
240
|
+
const w = t?.frames?.windowMs;
|
|
241
|
+
if (!Array.isArray(list) || !Number.isFinite(max) || !Number.isFinite(w)) return null;
|
|
242
|
+
if (w <= max) {
|
|
243
|
+
noteOn(m, `The recording lasted ${seconds(w)} s, not more than ${seconds(max)} s; moving content was not checked.`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
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.`);
|
|
247
|
+
const controls = m.motion?.exact?.pauseControls ?? [];
|
|
248
|
+
if (controls.length > 0) {
|
|
249
|
+
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.`);
|
|
250
|
+
}
|
|
251
|
+
return makeFinding(
|
|
252
|
+
rule,
|
|
253
|
+
m.width,
|
|
254
|
+
"fail",
|
|
255
|
+
`Content moves for more than ${seconds(max)} s and the page has no control named pause, stop or hide.`,
|
|
256
|
+
listed(list.map((x) => `${x.selector ?? `the box at ${x.box.x}, ${x.box.y}`} moved from ${x.firstMs} to ${x.lastMs} ms`)),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export const motionEvaluators = {
|
|
261
|
+
"motion.micro-duration": microDuration,
|
|
262
|
+
"motion.transition-duration": transitionDuration,
|
|
263
|
+
"motion.easing": easing,
|
|
264
|
+
"motion.properties": properties,
|
|
265
|
+
"motion.sameness": sameness,
|
|
266
|
+
"motion.reduced": reduced,
|
|
267
|
+
"motion.long-frames": longFrames,
|
|
268
|
+
"motion.layout-shift": layoutShift,
|
|
269
|
+
"motion.settle": settle,
|
|
270
|
+
"motion.banding": banding,
|
|
271
|
+
"motion.flashes": flashes,
|
|
272
|
+
"motion.moving": moving,
|
|
273
|
+
};
|
|
@@ -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
|
+
};
|