@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,145 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { restOn, restOff } from "./at-rest.mjs";
|
|
3
|
+
|
|
4
|
+
// A definition, not a cutoff: the computed properties a component's look is compared on across screens.
|
|
5
|
+
export const COHERENCE_PROPS = [
|
|
6
|
+
"color", "background-color", "border-color", "border-width", "border-radius",
|
|
7
|
+
"font-family", "font-size", "font-weight", "text-transform", "padding", "box-shadow",
|
|
8
|
+
];
|
|
9
|
+
// The kinds whose distinct looks are counted as variants.
|
|
10
|
+
const VARIANT_KINDS = ["button", "field"];
|
|
11
|
+
|
|
12
|
+
let composition;
|
|
13
|
+
let look;
|
|
14
|
+
|
|
15
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
16
|
+
// Looks are read in COHERENCE_PROPS order, so the JSON text is a stable key.
|
|
17
|
+
const keyOf = (l) => JSON.stringify(l);
|
|
18
|
+
|
|
19
|
+
// The most common look among a screen's elements of one signature; ties go to the first in document order.
|
|
20
|
+
function commonLook(items) {
|
|
21
|
+
const counts = new Map();
|
|
22
|
+
for (const c of items) {
|
|
23
|
+
const k = keyOf(c.look);
|
|
24
|
+
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
25
|
+
}
|
|
26
|
+
let best = null;
|
|
27
|
+
for (const c of items) {
|
|
28
|
+
const k = keyOf(c.look);
|
|
29
|
+
if (best === null || counts.get(k) > counts.get(keyOf(best.look))) best = c;
|
|
30
|
+
}
|
|
31
|
+
return best.look;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Reads the components of every screen (fixed and sticky content kept, hidden and clipped content left
|
|
35
|
+
// out) and compares them: the same signature on two or more screens (shared), shared signatures whose look
|
|
36
|
+
// differs (divergent), and the distinct looks of buttons and fields across all screens (variants).
|
|
37
|
+
// Disabled, invalid and current components are states, not variants: they are left out. Looks are read
|
|
38
|
+
// at rest (transitions off, animations finished or stopped, see at-rest.mjs); nothing else is changed.
|
|
39
|
+
// pages: { target, page }[] in screen order; ctx.screens lists every screen asked for (a screen that could
|
|
40
|
+
// not be opened is absent from pages but keeps its index).
|
|
41
|
+
export async function measureCoherence(pages, ctx = {}) {
|
|
42
|
+
composition ??= await fs.readFile(new URL("./in-page/composition.js", import.meta.url), "utf8");
|
|
43
|
+
look ??= await fs.readFile(new URL("./in-page/look.js", import.meta.url), "utf8");
|
|
44
|
+
const screens = Array.isArray(ctx.screens) && ctx.screens.length ? [...ctx.screens] : pages.map((p) => p.target);
|
|
45
|
+
const notes = [];
|
|
46
|
+
const opts = { read: "components", props: COHERENCE_PROPS, keepPinned: true };
|
|
47
|
+
|
|
48
|
+
// Per screen, in screen order, the compared components in document order.
|
|
49
|
+
const read = [];
|
|
50
|
+
const used = new Set();
|
|
51
|
+
for (const { target, page } of pages) {
|
|
52
|
+
let screen = screens.findIndex((s, i) => s === target && !used.has(i));
|
|
53
|
+
if (screen !== -1) used.add(screen);
|
|
54
|
+
else {
|
|
55
|
+
screens.push(target);
|
|
56
|
+
screen = screens.length - 1;
|
|
57
|
+
}
|
|
58
|
+
let out;
|
|
59
|
+
try {
|
|
60
|
+
// Read at rest: transitions off and animations finished or stopped while the looks are read, undone after.
|
|
61
|
+
await page.evaluate(restOn());
|
|
62
|
+
try {
|
|
63
|
+
out = await page.evaluate(`(${composition})(${JSON.stringify(opts)}, ${look})`);
|
|
64
|
+
} finally {
|
|
65
|
+
await page.evaluate(restOff()).catch(() => {});
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
notes.push(`Screen ${target} could not be read: ${err?.message ?? err}`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// The reader's descendant note concerns looks read with parts; coherence reads self looks only.
|
|
72
|
+
for (const n of out.notes) if (!n.includes("descendant elements")) notes.push(`${target}: ${n}`);
|
|
73
|
+
const kept = out.components.filter((c) => !c.disabled && !c.invalid && !c.current);
|
|
74
|
+
read.push({ screen, components: kept });
|
|
75
|
+
}
|
|
76
|
+
read.sort((a, b) => a.screen - b.screen);
|
|
77
|
+
|
|
78
|
+
// Shared: named components grouped by signature, in order of first appearance.
|
|
79
|
+
let unnamed = 0;
|
|
80
|
+
const bySig = new Map();
|
|
81
|
+
for (const { screen, components } of read) {
|
|
82
|
+
for (const c of components) {
|
|
83
|
+
if ((c.kind === "button" || c.kind === "link") && !c.named) {
|
|
84
|
+
unnamed += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!bySig.has(c.signature)) bySig.set(c.signature, { signature: c.signature, kind: c.kind, label: c.label, perScreen: new Map() });
|
|
88
|
+
const entry = bySig.get(c.signature);
|
|
89
|
+
if (!entry.perScreen.has(screen)) entry.perScreen.set(screen, []);
|
|
90
|
+
entry.perScreen.get(screen).push(c);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (unnamed) {
|
|
94
|
+
notes.push(`${unnamed} ${plural(unnamed, "button or link has no text or label and was not matched across screens.", "buttons or links have no text or label and were not matched across screens.")}`);
|
|
95
|
+
}
|
|
96
|
+
const shared = [];
|
|
97
|
+
for (const e of bySig.values()) {
|
|
98
|
+
if (e.perScreen.size < 2) continue;
|
|
99
|
+
shared.push({
|
|
100
|
+
signature: e.signature,
|
|
101
|
+
kind: e.kind,
|
|
102
|
+
label: e.label,
|
|
103
|
+
screens: [...e.perScreen].map(([screen, items]) => ({ screen, count: items.length, look: commonLook(items) })),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (shared.length === 0) notes.push("No component appears on two or more screens.");
|
|
107
|
+
|
|
108
|
+
// Divergent: one diffs entry per property whose value differs between screens.
|
|
109
|
+
const divergent = [];
|
|
110
|
+
for (const s of shared) {
|
|
111
|
+
const diffs = [];
|
|
112
|
+
for (const key of Object.keys(s.screens[0].look ?? {})) {
|
|
113
|
+
const values = [];
|
|
114
|
+
for (const { screen, look: l } of s.screens) {
|
|
115
|
+
const value = l?.[key] ?? "";
|
|
116
|
+
const found = values.find((v) => v.value === value);
|
|
117
|
+
if (found) found.screens.push(screen);
|
|
118
|
+
else values.push({ value, screens: [screen] });
|
|
119
|
+
}
|
|
120
|
+
if (values.length > 1) diffs.push({ property: key.replace(/^self /, ""), values });
|
|
121
|
+
}
|
|
122
|
+
if (diffs.length) divergent.push({ signature: s.signature, kind: s.kind, diffs });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Variants: every visible, enabled, non-current button and field, named or not (E9).
|
|
126
|
+
const variants = [];
|
|
127
|
+
for (const kind of VARIANT_KINDS) {
|
|
128
|
+
const looks = new Map();
|
|
129
|
+
for (const { screen, components } of read) {
|
|
130
|
+
for (const c of components) {
|
|
131
|
+
if (c.kind !== kind) continue;
|
|
132
|
+
const k = keyOf(c.look);
|
|
133
|
+
if (!looks.has(k)) looks.set(k, { look: c.look, screens: [], count: 0, example: c.selector, label: "" });
|
|
134
|
+
const v = looks.get(k);
|
|
135
|
+
// The report names a look by the text of its first named element ("" when none has a name).
|
|
136
|
+
if (!v.label && c.named) v.label = c.label;
|
|
137
|
+
v.count += 1;
|
|
138
|
+
if (!v.screens.includes(screen)) v.screens.push(screen);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (looks.size) variants.push({ kind, looks: [...looks.values()] });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return { screens, shared, divergent, variants, notes };
|
|
145
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { pageTiles } from "./tiles.mjs";
|
|
3
|
+
|
|
4
|
+
let script;
|
|
5
|
+
let contrast;
|
|
6
|
+
|
|
7
|
+
const toDataUrl = (buf) => `data:image/png;base64,${buf.toString("base64")}`;
|
|
8
|
+
|
|
9
|
+
// The color reports of the tiles of one page, in order, as one report. Area and text chroma come from the
|
|
10
|
+
// first part (area is the first view, which lies in the first tile). Contrast rows are merged by element:
|
|
11
|
+
// the first row whose box is not outside its tile, else the first row. Then, as on one screenshot, fails
|
|
12
|
+
// sorted by ratio and the five lowest passes. Notes are kept once each, in order, then one note with the
|
|
13
|
+
// uncertain rows of all parts summed. Pure.
|
|
14
|
+
export function mergeColorReports(parts) {
|
|
15
|
+
const byElement = new Map();
|
|
16
|
+
for (const { report } of parts) {
|
|
17
|
+
for (const row of report.contrast) {
|
|
18
|
+
const kept = byElement.get(row.el);
|
|
19
|
+
if (!kept || (kept.outside && !row.outside)) {
|
|
20
|
+
byElement.set(row.el, row);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const rows = [...byElement.values()].map(({ el, outside, ...row }) => row);
|
|
25
|
+
rows.sort((a, b) => a.ratio - b.ratio);
|
|
26
|
+
const notes = [];
|
|
27
|
+
for (const { report } of parts) {
|
|
28
|
+
for (const n of report.notes) {
|
|
29
|
+
if (!notes.includes(n)) notes.push(n);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const uncertain = parts.reduce((sum, { report }) => sum + (report.uncertain ?? 0), 0);
|
|
33
|
+
if (uncertain > 0) {
|
|
34
|
+
notes.push(
|
|
35
|
+
`${uncertain} text element${uncertain === 1 ? "" : "s"} failed against the computed background but could not be checked against the screenshot; reported as uncertain, not as a fail.`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
area: parts[0].report.area,
|
|
40
|
+
contrast: [...rows.filter((r) => !r.pass), ...rows.filter((r) => r.pass).slice(0, 5)],
|
|
41
|
+
textChroma: parts[0].report.textChroma,
|
|
42
|
+
notes,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Measures color from the rendered page: dominant areas from screenshot pixels of the first view,
|
|
47
|
+
// text contrast from computed styles (with transparency composited) and, where styles cannot tell, from
|
|
48
|
+
// the pixels of the tile the text sits in. ctx.rules: the run's color rules; the roles and marks lists of a
|
|
49
|
+
// color.contrast threshold (ES5) say which text counts as a warning (row.warning).
|
|
50
|
+
export async function measureColor(page, ctx = {}) {
|
|
51
|
+
script ??= await fs.readFile(new URL("./in-page/color.js", import.meta.url), "utf8");
|
|
52
|
+
contrast ??= await fs.readFile(new URL("./in-page/contrast.js", import.meta.url), "utf8");
|
|
53
|
+
const lists = (ctx.rules ?? []).find((r) => r.measure === "color.contrast" && Array.isArray(r.threshold?.marks))?.threshold;
|
|
54
|
+
const warn = { roles: lists?.roles ?? [], marks: lists?.marks ?? [] };
|
|
55
|
+
const run = (dataUrl, cssWidth, tile) =>
|
|
56
|
+
page.evaluate(
|
|
57
|
+
`(${script})(${JSON.stringify(dataUrl)}, ${cssWidth}, ${contrast}, ${JSON.stringify(tile)}, ${JSON.stringify(warn)})`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const { tiles, notes: extra } = await pageTiles(page, page.viewportSize()?.width);
|
|
61
|
+
let parts;
|
|
62
|
+
try {
|
|
63
|
+
parts = [];
|
|
64
|
+
for (const tile of tiles) {
|
|
65
|
+
const buf = await page.screenshot({ type: "png", fullPage: true, clip: tile });
|
|
66
|
+
const report = await run(toDataUrl(buf), tile.width, { offsetY: tile.y, heightPx: tile.height });
|
|
67
|
+
parts.push({ report });
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
const vp = page.viewportSize();
|
|
71
|
+
const w = vp?.width ?? tiles[0].width;
|
|
72
|
+
const buf = await page.screenshot({ type: "png" });
|
|
73
|
+
parts = [{ report: await run(toDataUrl(buf), w, { offsetY: 0 }) }];
|
|
74
|
+
extra.push("Full-page capture failed; fell back to the first viewport only.");
|
|
75
|
+
}
|
|
76
|
+
const report = mergeColorReports(parts);
|
|
77
|
+
report.notes.push(...extra);
|
|
78
|
+
return report;
|
|
79
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { restOn, restOff } from "./at-rest.mjs";
|
|
3
|
+
|
|
4
|
+
let composition;
|
|
5
|
+
|
|
6
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
7
|
+
|
|
8
|
+
// Definitions, not cutoffs (fixed before any page was read, never edited after a reading).
|
|
9
|
+
// A word after the first counts for the capitalization style only when it has this many letters or more,
|
|
10
|
+
// so "of", "to", "a" and "de" are neutral.
|
|
11
|
+
export const CASE_WORD_LETTERS = 4;
|
|
12
|
+
// A message names its field when the two share a folded word of this many letters or more.
|
|
13
|
+
export const MIN_WORD_LETTERS = 3;
|
|
14
|
+
// A word keeps an inner hyphen, period or apostrophe: "e-mail" is one word.
|
|
15
|
+
export const WORD = /[\p{L}\p{N}]+(?:[-.'][\p{L}\p{N}]+)*/gu;
|
|
16
|
+
|
|
17
|
+
export const NO_MESSAGE_NOTE =
|
|
18
|
+
"No error message is shown on this render; stage an error state to check the wording (see lazuli-ui-states-and-system).";
|
|
19
|
+
|
|
20
|
+
const wordsOf = (text) => text.match(WORD) ?? [];
|
|
21
|
+
const lettersOf = (word) => [...word].filter((c) => /\p{L}/u.test(c)).length;
|
|
22
|
+
// Folding: lowercase, Unicode NFD with combining marks removed; used for field-name matching only.
|
|
23
|
+
export const fold = (text) => text.toLowerCase().normalize("NFD").replace(/\p{M}/gu, "");
|
|
24
|
+
|
|
25
|
+
// A button's capitalization style: from text-transform first (capitalize reads as title), else from the
|
|
26
|
+
// source text of a name of two or more words. null when no style can be read.
|
|
27
|
+
export function styleOf(name, transform) {
|
|
28
|
+
if (transform === "uppercase") return "uppercase";
|
|
29
|
+
if (transform === "lowercase") return "lowercase";
|
|
30
|
+
if (transform === "capitalize") return "title";
|
|
31
|
+
const words = wordsOf(name);
|
|
32
|
+
if (words.length < 2) return null;
|
|
33
|
+
const later = words.slice(1).filter((w) => lettersOf(w) >= CASE_WORD_LETTERS);
|
|
34
|
+
if (later.length === 0) return null;
|
|
35
|
+
const upper = (w) => w[0] !== w[0].toLowerCase();
|
|
36
|
+
const lower = (w) => w[0] !== w[0].toUpperCase();
|
|
37
|
+
if (later.every(upper)) return "title";
|
|
38
|
+
if (later.every(lower)) return "sentence";
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// True when the folded message and the folded field name share a word of MIN_WORD_LETTERS letters or more.
|
|
43
|
+
export function namesField(text, field) {
|
|
44
|
+
const own = new Set(wordsOf(fold(field)).filter((w) => lettersOf(w) >= MIN_WORD_LETTERS));
|
|
45
|
+
return wordsOf(fold(text)).some((w) => own.has(w));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Buttons, links, headings and labels with their text as written, and the visible error messages (field
|
|
49
|
+
// messages from the forms reader, then alerts), read at rest; the page is never changed beyond the at-rest
|
|
50
|
+
// style and its removal.
|
|
51
|
+
export async function measureContent(page) {
|
|
52
|
+
composition ??= await fs.readFile(new URL("./in-page/composition.js", import.meta.url), "utf8");
|
|
53
|
+
let read;
|
|
54
|
+
let forms;
|
|
55
|
+
try {
|
|
56
|
+
await page.evaluate(restOn());
|
|
57
|
+
read = await page.evaluate(`(${composition})(${JSON.stringify({ read: "content", keepPinned: true })})`);
|
|
58
|
+
forms = await page.evaluate(`(${composition})(${JSON.stringify({ read: "forms", keepPinned: true })})`);
|
|
59
|
+
} finally {
|
|
60
|
+
await page.evaluate(restOff()).catch(() => {});
|
|
61
|
+
}
|
|
62
|
+
const notes = [...read.notes];
|
|
63
|
+
|
|
64
|
+
const buttons = read.items
|
|
65
|
+
.filter((i) => i.kind === "button")
|
|
66
|
+
.map((i) => ({ name: i.text, selector: i.selector, words: wordsOf(i.text).length, style: styleOf(i.text, i.transform) }));
|
|
67
|
+
|
|
68
|
+
const fields = forms.forms.flatMap((f) => f.fields).filter((f) => f.invalid);
|
|
69
|
+
const errors = [
|
|
70
|
+
...fields
|
|
71
|
+
.filter((f) => f.errorText)
|
|
72
|
+
.map((f) => ({ text: f.errorText, selector: f.selector, field: f.name, namesField: namesField(f.errorText, f.name) })),
|
|
73
|
+
...read.alerts.map((a) => ({ text: a.text, selector: a.selector, field: null, namesField: null })),
|
|
74
|
+
];
|
|
75
|
+
if (errors.length === 0) notes.push(NO_MESSAGE_NOTE);
|
|
76
|
+
const silent = fields.filter((f) => !f.errorText).length;
|
|
77
|
+
if (silent) {
|
|
78
|
+
notes.push(`${silent} ${plural(silent, "invalid field has no message tied to it; XR5 lists it.", "invalid fields have no message tied to them; XR5 lists them.")}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { buttons, items: read.items, errors, notes };
|
|
82
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The color library of the chart measure in Node: the same in-page/cvd.js the analysis page runs, loaded once
|
|
2
|
+
// with vm, so the evaluators' distances and the review sheet come from one model.
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import vm from "node:vm";
|
|
5
|
+
|
|
6
|
+
export const cvdSource = readFileSync(new URL("./in-page/cvd.js", import.meta.url), "utf8");
|
|
7
|
+
export const cvd = vm.runInNewContext(cvdSource);
|
|
8
|
+
|
|
9
|
+
const rgbOf = (hex) => ({ r: parseInt(hex.slice(1, 3), 16), g: parseInt(hex.slice(3, 5), 16), b: parseInt(hex.slice(5, 7), 16) });
|
|
10
|
+
|
|
11
|
+
// Every pair of colors once, in color order, with the Delta E in each view. Raw values: the evaluator compares
|
|
12
|
+
// them to minDeltaE and rounds only for display.
|
|
13
|
+
export function distances(colors) {
|
|
14
|
+
const rgb = colors.map(rgbOf);
|
|
15
|
+
const out = [];
|
|
16
|
+
for (let i = 0; i < colors.length; i++) {
|
|
17
|
+
for (let j = i + 1; j < colors.length; j++) {
|
|
18
|
+
const pair = { a: colors[i], b: colors[j] };
|
|
19
|
+
for (const view of cvd.VIEWS) pair[view] = cvd.deltaE(cvd.simulate(rgb[i], view), cvd.simulate(rgb[j], view));
|
|
20
|
+
out.push(pair);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { bounded } from "./states.mjs";
|
|
2
|
+
import { MANY_ITEMS, MAX_RECTS, caseGuard, judgeCase, loadCase, memoryNote, openCase, recorder, resourceMemory, runCase, snapshotOf } from "./cases.mjs";
|
|
3
|
+
|
|
4
|
+
// The extreme content measurer: at each width it opens its own page of the target (a normal open), takes a
|
|
5
|
+
// script-free snapshot and closes it; then one guarded context (page scripts off, nothing leaves but GET for
|
|
6
|
+
// styles, fonts and images, see cases.mjs) where the base copy and each selected case load in a fresh page,
|
|
7
|
+
// closed before the next. Only what a case adds to the base is reported. The shared page given to run() is
|
|
8
|
+
// never used.
|
|
9
|
+
|
|
10
|
+
// Caps, not rule cutoffs: one case page (load, inject, read), and one width (source open, snapshot,
|
|
11
|
+
// every case). Tests pass ctx.caseCapMs (a number, or one per case name, "base" included) and ctx.widthCapMs.
|
|
12
|
+
export const CASE_CAP_MS = 15000;
|
|
13
|
+
export const EXTREME_WIDTH_CAP_MS = 60000;
|
|
14
|
+
|
|
15
|
+
// The cases in the order they run; the list cases share one list search, made on the base copy.
|
|
16
|
+
export const CASES = ["growth", "long-text", "empty", "one", "many"];
|
|
17
|
+
const LIST_CASES = new Set(["empty", "one", "many"]);
|
|
18
|
+
|
|
19
|
+
export const SCRIPT_FREE_NOTE =
|
|
20
|
+
"A script-free copy of the page was used: content that a script would change after load, and the app's own empty state, are not in it.";
|
|
21
|
+
export const NO_LIST_NOTE = "No list was found outside navigation, so the empty, one-item and many-items cases did not run.";
|
|
22
|
+
const RECTS_NOTE = `${MAX_RECTS} text line boxes were read for overlap, not all; later lines were not compared.`;
|
|
23
|
+
|
|
24
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
25
|
+
const joined = (list) => (list.length < 2 ? list.join("") : `${list.slice(0, -1).join(", ")} and ${list[list.length - 1]}`);
|
|
26
|
+
const firstLine = (err) => String(err?.message ?? err).split("\n")[0];
|
|
27
|
+
const sorted = (o) => Object.fromEntries(Object.keys(o ?? {}).sort().map((k) => [k, o[k]]));
|
|
28
|
+
|
|
29
|
+
// A case in words, for findings and notes. lists: the lists the case changed; shortLists: the lists the many
|
|
30
|
+
// case filled with fewer than MANY_ITEMS items (their counts are in the notes). No per-list count is stated that
|
|
31
|
+
// was not measured.
|
|
32
|
+
export function caseWords(kind, { growth, lists = 0, shortLists = 0 } = {}) {
|
|
33
|
+
const n = `(${lists} ${plural(lists, "list", "lists")})`;
|
|
34
|
+
if (kind === "growth") return `every text ${growth} times longer, as when the language changes`;
|
|
35
|
+
if (kind === "long-text") return "long Portuguese text in every label, heading and paragraph";
|
|
36
|
+
if (kind === "empty") return `every list emptied ${n}`;
|
|
37
|
+
if (kind === "one") return `one item in every list ${n}`;
|
|
38
|
+
if (shortLists > 0) {
|
|
39
|
+
return `up to ${MANY_ITEMS} items in every list (${lists} ${plural(lists, "list", "lists")}; ${shortLists} ${plural(shortLists, "list got", "lists got")} fewer, see notes)`;
|
|
40
|
+
}
|
|
41
|
+
return `${MANY_ITEMS} items in every list ${n}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Runs the selected cases at ctx.width. ctx.rules: the selected rules of this measurer; a case runs only when a
|
|
45
|
+
// rule measures it, and growth only with a finite growth threshold in its rule (never from code).
|
|
46
|
+
export async function measureExtreme(_page, ctx = {}) {
|
|
47
|
+
const started = Date.now();
|
|
48
|
+
const width = ctx.width;
|
|
49
|
+
const rules = ctx.rules ?? [];
|
|
50
|
+
const rulesOf = (kind) => rules.filter((r) => r.measure === `extreme.${kind}`);
|
|
51
|
+
const growth = rulesOf("growth").map((r) => r.threshold?.growth).find((g) => Number.isFinite(g));
|
|
52
|
+
// "<rule names> was not checked" or "were not checked" (the measure ids when no rule names them).
|
|
53
|
+
const notChecked = (kinds) => {
|
|
54
|
+
const list = kinds.flatMap((k) => {
|
|
55
|
+
const names = rulesOf(k).map((r) => r.name).filter(Boolean);
|
|
56
|
+
return names.length ? names : [`extreme.${k}`];
|
|
57
|
+
});
|
|
58
|
+
return `${joined(list)} ${plural(list.length, "was", "were")} not checked`;
|
|
59
|
+
};
|
|
60
|
+
const capFor = (kind) => {
|
|
61
|
+
const c = ctx.caseCapMs;
|
|
62
|
+
if (Number.isFinite(c)) return c;
|
|
63
|
+
return Number.isFinite(c?.[kind]) ? c[kind] : CASE_CAP_MS;
|
|
64
|
+
};
|
|
65
|
+
const widthCap = Number.isFinite(ctx.widthCapMs) ? ctx.widthCapMs : EXTREME_WIDTH_CAP_MS;
|
|
66
|
+
|
|
67
|
+
const cases = Object.fromEntries(CASES.map((k) => [k, { ran: false, breaks: null }]));
|
|
68
|
+
const notes = [];
|
|
69
|
+
const requests = { sent: 0, byType: {} };
|
|
70
|
+
const finish = () => ({ width, cases, requests, notes: [...new Set(notes)], elapsedMs: Date.now() - started });
|
|
71
|
+
|
|
72
|
+
const runnable = CASES.filter((k) => rulesOf(k).length > 0);
|
|
73
|
+
if (runnable.includes("growth") && !Number.isFinite(growth)) {
|
|
74
|
+
runnable.splice(runnable.indexOf("growth"), 1);
|
|
75
|
+
notes.push(`The growth case has no growth threshold in its rule; ${notChecked(["growth"])}.`);
|
|
76
|
+
}
|
|
77
|
+
if (runnable.length === 0) return finish();
|
|
78
|
+
|
|
79
|
+
// After the width cap nothing the late work does reaches the report, and any context it opens is closed.
|
|
80
|
+
const stop = { stopped: false };
|
|
81
|
+
const note = (text) => {
|
|
82
|
+
if (!stop.stopped && text) notes.push(text);
|
|
83
|
+
};
|
|
84
|
+
const setCase = (kind, value) => {
|
|
85
|
+
if (!stop.stopped) cases[kind] = value;
|
|
86
|
+
};
|
|
87
|
+
const contexts = new Set();
|
|
88
|
+
const track = async (context) => {
|
|
89
|
+
if (stop.stopped) {
|
|
90
|
+
await context.close().catch(() => {});
|
|
91
|
+
throw new Error("extreme content was stopped");
|
|
92
|
+
}
|
|
93
|
+
contexts.add(context);
|
|
94
|
+
};
|
|
95
|
+
const done = new Set();
|
|
96
|
+
const memory = resourceMemory();
|
|
97
|
+
let guard = null;
|
|
98
|
+
|
|
99
|
+
const work = async () => {
|
|
100
|
+
// The source: a normal open that records styles, fonts and images, its snapshot, then closed.
|
|
101
|
+
const rec = recorder(memory);
|
|
102
|
+
const source = await ctx.openPage({
|
|
103
|
+
prepare: async (c) => {
|
|
104
|
+
await track(c);
|
|
105
|
+
await rec.prepare(c);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
let snap;
|
|
109
|
+
let url;
|
|
110
|
+
try {
|
|
111
|
+
snap = await snapshotOf(source);
|
|
112
|
+
url = source.url();
|
|
113
|
+
} finally {
|
|
114
|
+
await source.context().close().catch(() => {});
|
|
115
|
+
}
|
|
116
|
+
for (const n of snap.notes) note(n);
|
|
117
|
+
note(SCRIPT_FREE_NOTE);
|
|
118
|
+
|
|
119
|
+
// The guarded context: its first page is the base copy (bare and noScript, so no reveal pass runs).
|
|
120
|
+
guard = caseGuard(memory);
|
|
121
|
+
const wantLists = runnable.some((k) => LIST_CASES.has(k));
|
|
122
|
+
let basePage = null;
|
|
123
|
+
let context = null;
|
|
124
|
+
const baseWork = (async () => {
|
|
125
|
+
const p = await ctx.openPage({
|
|
126
|
+
bare: true,
|
|
127
|
+
noScript: true,
|
|
128
|
+
prepare: async (c) => {
|
|
129
|
+
await track(c);
|
|
130
|
+
await guard.install(c);
|
|
131
|
+
},
|
|
132
|
+
navigate: (page) => loadCase(page, url, snap.html, capFor("base")),
|
|
133
|
+
});
|
|
134
|
+
basePage = p;
|
|
135
|
+
context = p.context();
|
|
136
|
+
const base = await runCase(p, "base");
|
|
137
|
+
// The one list search of the list cases, on the base copy after its reading.
|
|
138
|
+
const search = wantLists ? await p.evaluate(() => window.__lazuliExtreme.inject("empty", {})) : null;
|
|
139
|
+
return { base, search };
|
|
140
|
+
})();
|
|
141
|
+
baseWork.catch(() => {});
|
|
142
|
+
let base;
|
|
143
|
+
let lists = 0;
|
|
144
|
+
try {
|
|
145
|
+
const out = await bounded(baseWork, capFor("base"), "the base copy");
|
|
146
|
+
base = out.base;
|
|
147
|
+
lists = out.search?.lists ?? 0;
|
|
148
|
+
} catch (err) {
|
|
149
|
+
note(`The base copy failed: ${firstLine(err)}; ${notChecked(runnable)}.`);
|
|
150
|
+
for (const k of runnable) done.add(k);
|
|
151
|
+
return;
|
|
152
|
+
} finally {
|
|
153
|
+
if (basePage) await basePage.close().catch(() => {});
|
|
154
|
+
}
|
|
155
|
+
if (stop.stopped) return;
|
|
156
|
+
const baseMissing = guard.unserved(basePage);
|
|
157
|
+
if (base.breaks.rectsCut) note(RECTS_NOTE);
|
|
158
|
+
if (wantLists && lists === 0) {
|
|
159
|
+
note(NO_LIST_NOTE);
|
|
160
|
+
for (const k of runnable.filter((x) => LIST_CASES.has(x))) {
|
|
161
|
+
setCase(k, { ran: false, lists: 0, breaks: null });
|
|
162
|
+
done.add(k);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (const kind of runnable) {
|
|
167
|
+
if (done.has(kind)) continue;
|
|
168
|
+
if (stop.stopped) return;
|
|
169
|
+
const isList = LIST_CASES.has(kind);
|
|
170
|
+
const cap = capFor(kind);
|
|
171
|
+
let page = null;
|
|
172
|
+
let over = false;
|
|
173
|
+
const caseWork = (async () => {
|
|
174
|
+
const p = await openCase(context, url, snap.html, cap);
|
|
175
|
+
if (over || stop.stopped) {
|
|
176
|
+
await p.close().catch(() => {});
|
|
177
|
+
throw new Error("the case was stopped");
|
|
178
|
+
}
|
|
179
|
+
page = p;
|
|
180
|
+
return runCase(p, kind, kind === "growth" ? { growth } : {});
|
|
181
|
+
})();
|
|
182
|
+
caseWork.catch(() => {});
|
|
183
|
+
try {
|
|
184
|
+
const out = await bounded(caseWork, cap, `the ${kind} case`);
|
|
185
|
+
if (stop.stopped) return;
|
|
186
|
+
const { injected } = out;
|
|
187
|
+
const words = caseWords(kind, { growth, lists: injected.lists, shortLists: injected.shortLists });
|
|
188
|
+
for (const c of injected.cut) note(c);
|
|
189
|
+
if (out.breaks.rectsCut) note(RECTS_NOTE);
|
|
190
|
+
const judged = judgeCase(base.breaks, out.breaks, injected, { caseWords: words, missing: [...baseMissing, ...guard.unserved(page)] });
|
|
191
|
+
// A case that was not compared names its rules.
|
|
192
|
+
if (judged.note) note(judged.note.replace(/, so its breaks are not reported\.$/, `; ${notChecked([kind])}.`));
|
|
193
|
+
setCase(kind, {
|
|
194
|
+
ran: true,
|
|
195
|
+
...(isList ? { lists: injected.lists } : {}),
|
|
196
|
+
...(kind === "many" ? { added: injected.added, shortLists: injected.shortLists } : {}),
|
|
197
|
+
breaks: judged.breaks,
|
|
198
|
+
});
|
|
199
|
+
} catch (err) {
|
|
200
|
+
over = true;
|
|
201
|
+
if (stop.stopped) return;
|
|
202
|
+
note(`The ${caseWords(kind, { growth, lists })} case failed: ${firstLine(err)}; ${notChecked([kind])}.`);
|
|
203
|
+
setCase(kind, { ran: true, ...(isList ? { lists } : {}), breaks: null });
|
|
204
|
+
} finally {
|
|
205
|
+
if (page) await page.close().catch(() => {});
|
|
206
|
+
done.add(kind);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const running = work().then(
|
|
212
|
+
() => null,
|
|
213
|
+
(err) => err,
|
|
214
|
+
);
|
|
215
|
+
try {
|
|
216
|
+
const err = await bounded(running, widthCap, `extreme content at ${width} px`);
|
|
217
|
+
if (err && !stop.stopped) {
|
|
218
|
+
const left = runnable.filter((k) => !done.has(k));
|
|
219
|
+
notes.push(`Extreme content could not run at ${width} px: ${firstLine(err).replace(/\.$/, "")}; ${notChecked(left)}.`);
|
|
220
|
+
}
|
|
221
|
+
} catch {
|
|
222
|
+
// Past the width cap: nothing waits on the late work; the cases it had not finished are named.
|
|
223
|
+
stop.stopped = true;
|
|
224
|
+
const left = runnable.filter((k) => !done.has(k));
|
|
225
|
+
for (const k of left) cases[k] = { ran: false, breaks: null };
|
|
226
|
+
notes.push(`Extreme content stopped at ${width} px after ${((Date.now() - started) / 1000).toFixed(1)} s; ${notChecked(left)}.`);
|
|
227
|
+
} finally {
|
|
228
|
+
stop.stopped = true;
|
|
229
|
+
for (const c of contexts) await c.close().catch(() => {});
|
|
230
|
+
}
|
|
231
|
+
if (guard) {
|
|
232
|
+
const s = guard.state;
|
|
233
|
+
Object.assign(requests, { sent: s.sent, byType: sorted(s.byType), fromMemory: s.fromMemory, passed: s.passed, stops: s.stops });
|
|
234
|
+
}
|
|
235
|
+
const mem = memoryNote(memory);
|
|
236
|
+
if (mem) notes.push(mem);
|
|
237
|
+
if (requests.sent > 0) {
|
|
238
|
+
notes.push(`${requests.sent} ${plural(requests.sent, "request other than styles, fonts and images was", "requests other than styles, fonts and images were")} blocked in the case pages.`);
|
|
239
|
+
}
|
|
240
|
+
return finish();
|
|
241
|
+
}
|