@uselazuli/cli 1.0.1 → 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 +22 -0
- package/README.md +3 -3
- package/bin/lazuli.mjs +67 -19
- package/package.json +1 -1
- package/rules/content/HYPOTHESES.md +3 -2
- package/rules/content/review.yaml +33 -2
- package/rules/graphic/HYPOTHESES.md +1 -0
- package/rules/graphic/review.yaml +29 -0
- package/rules/motion/HYPOTHESES.md +3 -3
- package/rules/motion/review.yaml +4 -4
- package/rules/typography/HYPOTHESES.md +1 -1
- package/rules/typography/review.yaml +2 -2
- package/rules/ui/HYPOTHESES.md +1 -1
- package/rules/ui/compose.yaml +27 -0
- package/rules/ui/review.yaml +2 -1
- package/skills/lazuli/SKILL.md +8 -5
- package/skills/lazuli/procedures/review-design.md +1 -0
- package/skills/lazuli/procedures/show-options.md +2 -1
- package/skills/lazuli-content-voice/SKILL.md +1 -0
- package/skills/lazuli-graphic-identity/SKILL.md +3 -1
- package/skills/lazuli-ui-composition/SKILL.md +4 -4
- package/skills/lazuli-ui-layout-review/SKILL.md +2 -2
- package/src/browser.mjs +2 -1
- package/src/commands/catalog.mjs +1 -1
- package/src/commands/check-design.mjs +51 -16
- package/src/commands/compare-designs.mjs +65 -2
- package/src/commands/draft-memo.mjs +4 -3
- package/src/commands/hooks.mjs +7 -5
- package/src/commands/record-log.mjs +54 -25
- package/src/commands/render-options.mjs +78 -15
- package/src/measure/a11y.mjs +8 -0
- package/src/measure/cases.mjs +22 -5
- package/src/measure/color.mjs +7 -0
- package/src/measure/in-page/a11y.js +33 -0
- package/src/measure/in-page/color.js +3 -1
- package/src/measure/in-page/extreme.js +28 -6
- package/src/measure/in-page/motion-probe.js +2 -0
- package/src/measure/in-page/type.js +3 -0
- package/src/measure/layout.mjs +9 -0
- package/src/measure/motion.mjs +2 -1
- package/src/measure/registry.mjs +3 -2
- package/src/measure/timeline.mjs +5 -5
- package/src/project/gate.mjs +12 -3
- package/src/project/lazuli-md.mjs +27 -3
- package/src/project/log.mjs +16 -10
- package/src/project/match.mjs +93 -5
- package/src/report/evaluators/a11y.mjs +21 -0
- package/src/report/evaluators/color.mjs +48 -1
- package/src/report/evaluators/extreme.mjs +43 -9
- package/src/report/evaluators/layout.mjs +10 -1
- package/src/report/evaluators/motion.mjs +10 -3
- package/src/report/evaluators/type.mjs +6 -3
- package/src/report/format.mjs +4 -4
- package/src/rules/load.mjs +18 -0
- package/src/rules/schema.mjs +8 -0
- package/templates/LAZULI.md +2 -0
|
@@ -12,14 +12,19 @@
|
|
|
12
12
|
// item (many) has its data-lazuli-x and those of its descendants rewritten to <original>~c<k> and its id
|
|
13
13
|
// attributes removed, so every copy stays apart and is compared through its original. The caller runs
|
|
14
14
|
// the at-rest walk again (restStill) before read().
|
|
15
|
-
// read() -> { overflowX, texts: { id, selector, text, spills, cut, whole }[], kept, overlaps,
|
|
16
|
-
// fonts, sheets, brokenImages }.
|
|
15
|
+
// read() -> { overflowX, clippedX, texts: { id, selector, text, spills, cut, whole, bleeds, pastRight, right }[], kept, overlaps,
|
|
16
|
+
// rectsCut, away, fonts, sheets, brokenImages }. overflowX: how far the page scrolls sideways, null when the
|
|
17
|
+
// viewport hides its sideways overflow (html, or body when html is visible, has overflow-x hidden or clip, as
|
|
18
|
+
// composition reads it); clippedX: on such a page, how far the content runs past the clipped right edge, else
|
|
19
|
+
// null. whole: every line box of the text was read for overlap. bleeds:
|
|
20
|
+
// the text's box (its element's box joined with its line boxes) is partly in the viewport and crosses its left
|
|
21
|
+
// or right edge by more than ALIGN_PX, on a page that does not scroll sideways (the gate of composition's bleeds); pastRight: that box's right edge passes the viewport by more than ALIGN_PX; right: that edge in px. away: the
|
|
17
22
|
// tagged text elements the walk did not keep whose every line box lies outside the padding box of a hidden or
|
|
18
23
|
// clip ancestor, walked by containing block. fonts: the font faces loaded, loading or failed; sheets: the
|
|
19
24
|
// linked stylesheets and how many rules each holds; brokenImages: the ids of images that failed.
|
|
20
25
|
(composition, defs) => {
|
|
21
26
|
const {
|
|
22
|
-
SLACK_PX, MANY_ITEMS, LIST_SELECTOR, NOT_LIST, REPEATED_MIN, LABEL_SCOPE, HEADING_SCOPE, DECORATIVE, INLINE_ITEMS,
|
|
27
|
+
SLACK_PX, ALIGN_PX, MANY_ITEMS, LIST_SELECTOR, NOT_LIST, REPEATED_MIN, LABEL_SCOPE, HEADING_SCOPE, DECORATIVE, INLINE_ITEMS,
|
|
23
28
|
LONG_LABEL, LONG_HEADING, LONG_TEXT, GROWTH_FILL, MAX_LISTS, MAX_CLONE_ELEMENTS, MAX_RECTS,
|
|
24
29
|
} = defs;
|
|
25
30
|
const ATTR = "data-lazuli-x";
|
|
@@ -257,9 +262,23 @@
|
|
|
257
262
|
);
|
|
258
263
|
};
|
|
259
264
|
|
|
265
|
+
// The text's box across: its element's box joined with its line boxes (a word can run out of its box).
|
|
266
|
+
const across = (el, rects) => {
|
|
267
|
+
const b = el.getBoundingClientRect();
|
|
268
|
+
return { left: Math.min(b.left, ...rects.map((r) => r.left)), right: Math.max(b.right, ...rects.map((r) => r.right)) };
|
|
269
|
+
};
|
|
270
|
+
|
|
260
271
|
const read = () => {
|
|
261
272
|
const kept = keptEls();
|
|
262
273
|
const keptSet = new Set(kept);
|
|
274
|
+
const root = document.documentElement;
|
|
275
|
+
const vw = root.clientWidth;
|
|
276
|
+
// As composition's bleeds: a page that scrolls sideways (html, or body when html is visible, does not
|
|
277
|
+
// hide that overflow) has no bleed.
|
|
278
|
+
const rootStyle = getComputedStyle(root);
|
|
279
|
+
const viewStyle = rootStyle.overflowX === "visible" && rootStyle.overflowY === "visible" ? getComputedStyle(document.body) : rootStyle;
|
|
280
|
+
const lockedX = CLIPS.has(viewStyle.overflowX);
|
|
281
|
+
const sideways = root.scrollWidth > vw + ALIGN_PX && !lockedX;
|
|
263
282
|
const entries = [];
|
|
264
283
|
for (const el of kept) {
|
|
265
284
|
const id = idOf(el);
|
|
@@ -268,9 +287,12 @@
|
|
|
268
287
|
if (nodes.length === 0) continue;
|
|
269
288
|
const rects = rectsOf(nodes);
|
|
270
289
|
const container = containerOf(el);
|
|
290
|
+
const box = across(el, rects);
|
|
291
|
+
const pastRight = box.right > vw + ALIGN_PX;
|
|
292
|
+
const bleeds = !sideways && box.right > 0 && box.left < vw && (box.left < -ALIGN_PX || pastRight);
|
|
271
293
|
entries.push({
|
|
272
294
|
el, rects, container,
|
|
273
|
-
text: { id, selector: selectorOf(el), text: collapse(nodes.map((n) => n.nodeValue).join(" ")).slice(0, 40), spills: spillsOf(container, rects), cut: cutOf(container, rects), whole: true },
|
|
295
|
+
text: { id, selector: selectorOf(el), text: collapse(nodes.map((n) => n.nodeValue).join(" ")).slice(0, 40), spills: spillsOf(container, rects), cut: cutOf(container, rects), whole: true, bleeds, pastRight, right: box.right },
|
|
274
296
|
});
|
|
275
297
|
}
|
|
276
298
|
// Overlaps over the first MAX_RECTS line boxes, in document order.
|
|
@@ -337,9 +359,9 @@
|
|
|
337
359
|
})
|
|
338
360
|
.sort((a, b) => (a.href < b.href ? -1 : a.href > b.href ? 1 : 0));
|
|
339
361
|
const brokenImages = [...new Set([...document.images].filter((img) => img.complete && img.naturalWidth === 0 && idOf(img) !== null).map(idOf))].sort(byId);
|
|
340
|
-
const root = document.documentElement;
|
|
341
362
|
return {
|
|
342
|
-
overflowX: root.scrollWidth - root.clientWidth,
|
|
363
|
+
overflowX: lockedX ? null : root.scrollWidth - root.clientWidth,
|
|
364
|
+
clippedX: lockedX ? root.scrollWidth - root.clientWidth : null,
|
|
343
365
|
texts: entries.map((e) => e.text),
|
|
344
366
|
kept: kept.map(idOf).filter((id) => id !== null),
|
|
345
367
|
overlaps,
|
|
@@ -98,6 +98,8 @@
|
|
|
98
98
|
from: valuesAt(frames[0]),
|
|
99
99
|
to: valuesAt(frames[frames.length - 1]),
|
|
100
100
|
related,
|
|
101
|
+
// A scroll or view timeline: the scroll position is the curve, not the timing function.
|
|
102
|
+
scrollLinked: !!a.timeline && a.timeline !== document.timeline,
|
|
101
103
|
});
|
|
102
104
|
};
|
|
103
105
|
const scan = () => {
|
|
@@ -208,12 +208,15 @@
|
|
|
208
208
|
const pad = ["paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"].reduce((s, k) => s + (parseFloat(cs[k]) || 0), 0);
|
|
209
209
|
ratio = (box - pad) / size;
|
|
210
210
|
}
|
|
211
|
+
const weight = parseInt(cs.fontWeight, 10) || 400;
|
|
211
212
|
return {
|
|
212
213
|
selector: selectorOf(el),
|
|
213
214
|
chars,
|
|
214
215
|
lines,
|
|
215
216
|
charsPerLine: round(chars / lines),
|
|
216
217
|
sizePx: round(size, 2),
|
|
218
|
+
// WCAG 2.2 large scale (24 px, or 18.66 px at weight 700 or more), the same rule the color reading uses.
|
|
219
|
+
large: size >= 24 || (size >= 18.66 && weight >= 700),
|
|
217
220
|
lineHeightRatio: round(ratio, 3),
|
|
218
221
|
charAdvancePx: round(textWidth / chars, 2),
|
|
219
222
|
};
|
package/src/measure/layout.mjs
CHANGED
|
@@ -39,9 +39,18 @@ export async function measureLayout(page, ctx = {}) {
|
|
|
39
39
|
const order = areas.map((a, i) => i).sort((a, b) => areas[b] - areas[a] || a - b);
|
|
40
40
|
const top = order[0];
|
|
41
41
|
const c = raw.clipped[top];
|
|
42
|
+
// The pair of the two largest blocks: the second over the third, and the gap between their boxes
|
|
43
|
+
// (the larger of the gaps across and down; negative when the boxes overlap, the overlap depth).
|
|
44
|
+
const pair = order.length >= 2 ? raw.clipped[order[1]] : null;
|
|
45
|
+
const gap = pair
|
|
46
|
+
? Math.max(Math.max(c.x, pair.x) - Math.min(c.x + c.w, pair.x + pair.w), Math.max(c.y, pair.y) - Math.min(c.y + c.h, pair.y + pair.h))
|
|
47
|
+
: null;
|
|
42
48
|
focal = {
|
|
43
49
|
selector: raw.blocks[top].selector,
|
|
50
|
+
second: pair ? raw.blocks[order[1]].selector : null,
|
|
44
51
|
dominance: areas.length >= 2 && areas[order[1]] > 0 ? round(areas[top] / areas[order[1]]) : null,
|
|
52
|
+
pairLead: areas.length >= 3 && areas[order[2]] > 0 ? round(areas[order[1]] / areas[order[2]]) : null,
|
|
53
|
+
pairGapPx: round(gap),
|
|
45
54
|
x: round((c.x + c.w / 2) / w),
|
|
46
55
|
y: round((c.y + c.h / 2) / h),
|
|
47
56
|
};
|
package/src/measure/motion.mjs
CHANGED
|
@@ -144,11 +144,12 @@ function inventory(pass) {
|
|
|
144
144
|
delayMs: Math.round(a.delayMs),
|
|
145
145
|
durationMs: Math.round(a.durationMs),
|
|
146
146
|
easing: a.easing,
|
|
147
|
+
scrollLinked: a.scrollLinked === true,
|
|
147
148
|
properties,
|
|
148
149
|
from,
|
|
149
150
|
to,
|
|
150
151
|
moves,
|
|
151
|
-
entrance: (trigger === "load" || trigger === "scroll") && endMs !== null && (opacityRises || returns),
|
|
152
|
+
entrance: (trigger === "load" || trigger === "scroll") && endMs !== null && a.scrollLinked !== true && (opacityRises || returns),
|
|
152
153
|
layoutProps: properties.filter((p) => LAYOUT_PROPS.includes(p)),
|
|
153
154
|
},
|
|
154
155
|
});
|
package/src/measure/registry.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export const MEASURERS = [
|
|
|
49
49
|
{
|
|
50
50
|
name: "color",
|
|
51
51
|
scope: "page",
|
|
52
|
-
ids: ["color.area", "color.contrast", "color.text-chroma"],
|
|
52
|
+
ids: ["color.area", "color.contrast", "color.text-chroma", "color.brand"],
|
|
53
53
|
run: (page, ctx) => measureColor(page, ctx),
|
|
54
54
|
evaluators: colorEvaluators,
|
|
55
55
|
},
|
|
@@ -94,8 +94,9 @@ export const MEASURERS = [
|
|
|
94
94
|
"a11y.reflow",
|
|
95
95
|
"a11y.text-spacing",
|
|
96
96
|
"a11y.decorative-images",
|
|
97
|
+
"a11y.image-treatment",
|
|
97
98
|
],
|
|
98
|
-
thresholdIds: ["a11y.generic-links", "a11y.target-size", "a11y.reflow", "a11y.text-spacing", "a11y.decorative-images"],
|
|
99
|
+
thresholdIds: ["a11y.generic-links", "a11y.target-size", "a11y.reflow", "a11y.text-spacing", "a11y.decorative-images", "a11y.image-treatment"],
|
|
99
100
|
run: (page, ctx) => measureA11y(page, ctx),
|
|
100
101
|
evaluators: a11yEvaluators,
|
|
101
102
|
},
|
package/src/measure/timeline.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import { cdpSession, toUrl
|
|
2
|
+
import { cdpSession, toUrl } from "../browser.mjs";
|
|
3
3
|
import { flowStopUrl, hasStopWord, isLocalTarget } from "../project/tasks.mjs";
|
|
4
4
|
import { restOff, restOn } from "./at-rest.mjs";
|
|
5
5
|
import { bounded } from "./states.mjs";
|
|
@@ -327,16 +327,16 @@ function scrollEnd([y0, start, maxMs]) {
|
|
|
327
327
|
const heldKey = (step) => JSON.stringify([step.selector, step.name, step.box]);
|
|
328
328
|
|
|
329
329
|
// Hover: the pointer over the vetted element's center. Focus: element.focus() on the same element (no key
|
|
330
|
-
// event), through the handle its hover vetted when there is one. Scroll: one wheel of
|
|
330
|
+
// event), through the handle its hover vetted when there is one. Scroll: one wheel of the page's viewport height from
|
|
331
331
|
// the viewport center; step.scrollEndMs is when scrollY stopped changing. Returns the start time, or null.
|
|
332
332
|
async function runStep(page, step, mark, notes, live, held) {
|
|
333
333
|
if (step.kind === "click") return clickVetted(page, step, mark, notes, live);
|
|
334
334
|
if (step.kind === "scroll") {
|
|
335
|
-
const { width } = page.viewportSize();
|
|
335
|
+
const { width, height } = page.viewportSize();
|
|
336
336
|
const y0 = await page.evaluate(() => scrollY);
|
|
337
337
|
const startMs = await mark();
|
|
338
|
-
await page.mouse.move(width / 2,
|
|
339
|
-
await page.mouse.wheel(0,
|
|
338
|
+
await page.mouse.move(width / 2, height / 2);
|
|
339
|
+
await page.mouse.wheel(0, height);
|
|
340
340
|
step.scrollEndMs = await page.evaluate(scrollEnd, [y0, startMs, STEP_WINDOW_MS]);
|
|
341
341
|
return startMs;
|
|
342
342
|
}
|
package/src/project/gate.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { toUrl } from "../browser.mjs";
|
|
3
3
|
import { isStale, readEdits } from "./edits.mjs";
|
|
4
|
+
import { isOptionsGoal } from "./lazuli-md.mjs";
|
|
4
5
|
import { matchGoals, targetKey } from "./match.mjs";
|
|
5
6
|
import { findCapture, readRecords } from "./records.mjs";
|
|
6
7
|
|
|
@@ -65,6 +66,12 @@ export async function gateStatus({ cwd = process.cwd(), md, target }) {
|
|
|
65
66
|
notes.push(`"${g.piece}" has no Target, so Lazuli cannot check it; check it by hand.`);
|
|
66
67
|
continue;
|
|
67
68
|
}
|
|
69
|
+
// An options goal covers option files; an option review never counts for the page.
|
|
70
|
+
if (isOptionsGoal(g)) {
|
|
71
|
+
goals.push({ piece: g.piece, target: g.target, status: "options", verdict: null, reviewedAt: null, reviewer: null });
|
|
72
|
+
notes.push(`"${g.piece}" covers option files (${g.target}); options are not gated. Give the chosen page its own goal.`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
68
75
|
const key = targetKey(g.target, root);
|
|
69
76
|
if (!pages.has(key)) {
|
|
70
77
|
pages.set(key, await reviewOf(root, g.target));
|
|
@@ -129,7 +136,8 @@ export async function gateStatus({ cwd = process.cwd(), md, target }) {
|
|
|
129
136
|
}
|
|
130
137
|
}
|
|
131
138
|
|
|
132
|
-
const
|
|
139
|
+
const isGated = (g) => g.target && g.status !== "options";
|
|
140
|
+
const gated = new Set(goals.filter(isGated).map((g) => norm(g.piece)));
|
|
133
141
|
const tryingBreaks = [];
|
|
134
142
|
for (const b of md?.breaks ?? []) {
|
|
135
143
|
if (b.status === "trying" && gated.has(norm(b.piece)) && !tryingBreaks.some((t) => norm(t.rule) === norm(b.rule) && norm(t.piece) === norm(b.piece))) {
|
|
@@ -140,8 +148,9 @@ export async function gateStatus({ cwd = process.cwd(), md, target }) {
|
|
|
140
148
|
if (urlChecked) {
|
|
141
149
|
notes.push("A URL target is checked for freshness only from edits the hook recorded; a change made outside the agent is not seen.");
|
|
142
150
|
}
|
|
143
|
-
const gatedGoals = goals.filter(
|
|
144
|
-
|
|
151
|
+
const gatedGoals = goals.filter(isGated);
|
|
152
|
+
// With only options goals, their note already says why nothing is gated.
|
|
153
|
+
if (gatedGoals.length === 0 && !goals.some((g) => g.status === "options")) {
|
|
145
154
|
if (target && (md?.goals ?? []).length > 0) {
|
|
146
155
|
items.push(`No goal in LAZULI.md has this Target: ${target}`);
|
|
147
156
|
} else {
|
|
@@ -316,6 +316,19 @@ export function isAssetGoal(goal) {
|
|
|
316
316
|
return /\.(?:svg|png|ico|jpe?g|webp)$/i.test(target);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
// A goal whose Target holds a * covers a folder of option files (Target: ./options/*.html). It is not a
|
|
320
|
+
// screen and it is never gated: an option review never counts for the page.
|
|
321
|
+
export function isOptionsGoal(goal) {
|
|
322
|
+
return typeof goal?.target === "string" && goal.target.includes("*");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// An optional Target of a break or decision: one file the entry applies to, or null.
|
|
326
|
+
const entryTarget = (value) => (value && value.trim() !== "" && !isPlaceholder(value) ? value.trim() : null);
|
|
327
|
+
|
|
328
|
+
// The glob of an options goal is matched against paths relative to the project: an absolute path, a drive, a
|
|
329
|
+
// file:// or a web URL matches no file.
|
|
330
|
+
const relativeGlob = (target) => !/^(?:[\\/]|[a-z][a-z0-9+.-]*:)/i.test(target.trim());
|
|
331
|
+
|
|
319
332
|
export function emptyBrand() {
|
|
320
333
|
return { colors: [], fonts: [], symbols: [] };
|
|
321
334
|
}
|
|
@@ -390,6 +403,9 @@ function parseGoals(lines, problems) {
|
|
|
390
403
|
problems.push(`Goal "${piece}": fields should be indented under Piece; read anyway`);
|
|
391
404
|
}
|
|
392
405
|
const f = entry.fields;
|
|
406
|
+
if (f.target && f.target.includes("*") && !relativeGlob(f.target)) {
|
|
407
|
+
problems.push(`Goal "${piece}": Target ${f.target.trim()} covers option files but is not a relative path, so it matches no file`);
|
|
408
|
+
}
|
|
393
409
|
goals.push({
|
|
394
410
|
piece,
|
|
395
411
|
target: f.target ? f.target : null,
|
|
@@ -405,7 +421,7 @@ function parseGoals(lines, problems) {
|
|
|
405
421
|
}
|
|
406
422
|
|
|
407
423
|
function parseBreaks(lines, problems) {
|
|
408
|
-
const { entries: found, ignored } = entries(lines, "rule", ["piece", "effect", "check", "status"]);
|
|
424
|
+
const { entries: found, ignored } = entries(lines, "rule", ["piece", "target", "effect", "check", "status"]);
|
|
409
425
|
const breaks = [];
|
|
410
426
|
for (const entry of found) {
|
|
411
427
|
const rule = entry.head.trim();
|
|
@@ -427,14 +443,18 @@ function parseBreaks(lines, problems) {
|
|
|
427
443
|
problems.push(`Break ${rule}: status must be trying, kept or reverted`);
|
|
428
444
|
}
|
|
429
445
|
}
|
|
430
|
-
|
|
446
|
+
const target = entryTarget(f.target);
|
|
447
|
+
if (target?.includes("*")) {
|
|
448
|
+
problems.push(`Break ${rule}: Target ${target} holds a *, but a break names one file, so it never applies`);
|
|
449
|
+
}
|
|
450
|
+
breaks.push({ rule, piece: f.piece ?? "", effect: f.effect ?? "", check: f.check ?? "", status, target });
|
|
431
451
|
}
|
|
432
452
|
problems.push(...ignoredProblems(found, ignored, "Breaks", (e) => `Break ${e.head.trim()}`));
|
|
433
453
|
return breaks;
|
|
434
454
|
}
|
|
435
455
|
|
|
436
456
|
function parseDecisions(lines, problems) {
|
|
437
|
-
const { entries: found, ignored } = entries(lines, "decision", ["piece", "goal", "rule", "measure"]);
|
|
457
|
+
const { entries: found, ignored } = entries(lines, "decision", ["piece", "target", "goal", "rule", "measure"]);
|
|
438
458
|
const decisions = [];
|
|
439
459
|
for (const entry of found) {
|
|
440
460
|
const decision = entry.head.trim();
|
|
@@ -457,6 +477,9 @@ function parseDecisions(lines, problems) {
|
|
|
457
477
|
if (piece.trim() === "") {
|
|
458
478
|
problems.push(`Decision "${decision}": Piece is missing`);
|
|
459
479
|
}
|
|
480
|
+
if (entryTarget(f.target)?.includes("*")) {
|
|
481
|
+
problems.push(`Decision "${decision}": Target ${entryTarget(f.target)} holds a *, but a decision names one file, so it never applies`);
|
|
482
|
+
}
|
|
460
483
|
decisions.push({
|
|
461
484
|
decision,
|
|
462
485
|
piece,
|
|
@@ -464,6 +487,7 @@ function parseDecisions(lines, problems) {
|
|
|
464
487
|
rule: match ? match[1].toUpperCase() : none ? "none" : written,
|
|
465
488
|
action: match ? match[2].toLowerCase() : none ? "none" : null,
|
|
466
489
|
measure: f.measure ?? "",
|
|
490
|
+
target: entryTarget(f.target),
|
|
467
491
|
});
|
|
468
492
|
}
|
|
469
493
|
problems.push(...ignoredProblems(found, ignored, "Decisions", (e) => `Decision "${e.head.trim()}"`));
|
package/src/project/log.mjs
CHANGED
|
@@ -17,8 +17,8 @@ export class LogInputError extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const BREAKS = { section: "breaks", heading: "Breaks", open: "rule", fields: ["piece", "effect", "check", "status"] };
|
|
21
|
-
const DECISIONS = { section: "decisions", heading: "Decisions", open: "decision", fields: ["piece", "goal", "rule", "measure"] };
|
|
20
|
+
const BREAKS = { section: "breaks", heading: "Breaks", open: "rule", fields: ["piece", "target", "effect", "check", "status"] };
|
|
21
|
+
const DECISIONS = { section: "decisions", heading: "Decisions", open: "decision", fields: ["piece", "target", "goal", "rule", "measure"] };
|
|
22
22
|
|
|
23
23
|
// Lines keep their own terminator so nothing about them changes unless we edit them.
|
|
24
24
|
function splitLines(text) {
|
|
@@ -206,13 +206,15 @@ function withValue(raw, key, value) {
|
|
|
206
206
|
return placed ? `${m[1]}${body.join("").trimEnd()}` : `${m[1]}${value}${closing}${m[3].trim() === "" ? "" : ` ${m[3].trim()}`}`;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
// sameTarget(a, b): whether two Target values name the same file; written text compared case-insensitively by default.
|
|
210
|
+
function write(text, spec, head, given, problems, sameTarget = (a, b) => norm(a) === norm(b)) {
|
|
210
211
|
const lines = splitLines(text);
|
|
211
212
|
const fileEol = lines.find((l) => l.eol !== "")?.eol ?? "\n";
|
|
212
213
|
const vis = visibleLines(lines);
|
|
213
214
|
const ranges = sectionRanges(vis, spec.section);
|
|
214
215
|
const entries = ranges.flatMap((r) => scanEntries(vis, r, spec));
|
|
215
|
-
|
|
216
|
+
// An entry is its head, its piece and its Target: the same rule on two files of one piece is two entries.
|
|
217
|
+
const hit = entries.find((e) => norm(e.value) === norm(head) && norm(e.fields.piece?.value) === norm(given.piece) && sameTarget(e.fields.target?.value, given.target));
|
|
216
218
|
const keys = spec.fields.filter((k) => given[k] !== undefined);
|
|
217
219
|
|
|
218
220
|
if (hit) {
|
|
@@ -225,6 +227,10 @@ function write(text, spec, head, given, problems) {
|
|
|
225
227
|
continue;
|
|
226
228
|
}
|
|
227
229
|
const have = hit.fields[key];
|
|
230
|
+
// The same file written another way keeps the person's text.
|
|
231
|
+
if (key === "target" && have !== undefined && sameTarget(have.value, given[key])) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
228
234
|
if (have === undefined) {
|
|
229
235
|
added.push(key);
|
|
230
236
|
} else if (have.value !== given[key]) {
|
|
@@ -293,7 +299,7 @@ function write(text, spec, head, given, problems) {
|
|
|
293
299
|
return lines.map((l) => l.text + l.eol).join("");
|
|
294
300
|
}
|
|
295
301
|
|
|
296
|
-
export function writeBreak(text, brk) {
|
|
302
|
+
export function writeBreak(text, brk, { sameTarget } = {}) {
|
|
297
303
|
const problems = [];
|
|
298
304
|
const rule = clean(brk.rule ?? "", "Rule", problems);
|
|
299
305
|
const piece = clean(brk.piece ?? "", "Piece", problems);
|
|
@@ -301,7 +307,7 @@ export function writeBreak(text, brk) {
|
|
|
301
307
|
problems.push("A break needs a rule and a piece.");
|
|
302
308
|
}
|
|
303
309
|
const given = { piece };
|
|
304
|
-
for (const key of ["effect", "check", "status"]) {
|
|
310
|
+
for (const key of ["target", "effect", "check", "status"]) {
|
|
305
311
|
if (brk[key] !== undefined) {
|
|
306
312
|
given[key] = clean(brk[key], label(key), problems);
|
|
307
313
|
}
|
|
@@ -309,10 +315,10 @@ export function writeBreak(text, brk) {
|
|
|
309
315
|
if (given.status !== undefined && given.status !== "" && !STATUSES.includes(given.status)) {
|
|
310
316
|
problems.push("Status must be trying, kept or reverted.");
|
|
311
317
|
}
|
|
312
|
-
return write(text, BREAKS, rule, given, problems);
|
|
318
|
+
return write(text, BREAKS, rule, given, problems, sameTarget);
|
|
313
319
|
}
|
|
314
320
|
|
|
315
|
-
export function writeDecision(text, d) {
|
|
321
|
+
export function writeDecision(text, d, { sameTarget } = {}) {
|
|
316
322
|
const problems = [];
|
|
317
323
|
const decision = clean(d.decision ?? "", "Decision", problems);
|
|
318
324
|
const piece = clean(d.piece ?? "", "Piece", problems);
|
|
@@ -320,10 +326,10 @@ export function writeDecision(text, d) {
|
|
|
320
326
|
problems.push("A decision needs a decision text and a piece.");
|
|
321
327
|
}
|
|
322
328
|
const given = { piece };
|
|
323
|
-
for (const key of ["goal", "rule", "measure"]) {
|
|
329
|
+
for (const key of ["target", "goal", "rule", "measure"]) {
|
|
324
330
|
if (d[key] !== undefined) {
|
|
325
331
|
given[key] = clean(d[key], label(key), problems);
|
|
326
332
|
}
|
|
327
333
|
}
|
|
328
|
-
return write(text, DECISIONS, decision, given, problems);
|
|
334
|
+
return write(text, DECISIONS, decision, given, problems, sameTarget);
|
|
329
335
|
}
|
package/src/project/match.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
2
4
|
import { toUrl } from "../browser.mjs";
|
|
5
|
+
import { isOptionsGoal } from "./lazuli-md.mjs";
|
|
3
6
|
|
|
4
7
|
// A page identity string: file URLs decoded, web URLs by origin + path (no trailing slash) + query.
|
|
5
8
|
export function identity(target, cwd) {
|
|
@@ -52,19 +55,62 @@ export function targetKey(target, cwd) {
|
|
|
52
55
|
return `${slug || "page"}-${hash}`;
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
// A path relative to cwd with forward slashes and no leading ./, or null for a URL target.
|
|
59
|
+
export function relativeFile(target, cwd) {
|
|
60
|
+
const url = toUrl(String(target).trim(), cwd);
|
|
61
|
+
if (!/^file:/i.test(url)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
let file;
|
|
65
|
+
try {
|
|
66
|
+
file = fileURLToPath(url);
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return path.relative(path.resolve(cwd), file).split(path.sep).join("/");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The Target glob of an options goal against a local file: * matches any run of characters except /.
|
|
74
|
+
function globMatches(glob, target, cwd) {
|
|
75
|
+
const rel = relativeFile(target, cwd);
|
|
76
|
+
if (rel === null) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const pattern = path.posix.normalize(glob.trim().replace(/\\/g, "/")).replace(/^\.\//, "");
|
|
80
|
+
const source = pattern
|
|
81
|
+
.split("*")
|
|
82
|
+
.map((p) => p.replace(/[.+?^${}()|[\]\\]/g, "\\$&"))
|
|
83
|
+
.join("[^/]*");
|
|
84
|
+
return new RegExp(`^${source}$`, process.platform === "win32" ? "i" : "").test(rel);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The Target of a break or decision as record-break and record-decision write it: a local file relative to cwd
|
|
88
|
+
// with forward slashes and no leading ./, a URL as written.
|
|
89
|
+
export function entryTargetForm(target, cwd) {
|
|
90
|
+
return relativeFile(target, cwd) ?? String(target).trim();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Two optional entry Targets name the same file: both absent, or the same page.
|
|
94
|
+
export function sameEntryTarget(a, b, cwd) {
|
|
95
|
+
const blank = (t) => t === undefined || t === null || String(t).trim() === "";
|
|
96
|
+
return blank(a) || blank(b) ? blank(a) && blank(b) : sameTarget(a, b, cwd);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The goals of this page in file order: an exact Target, or the glob of an options goal that covers it.
|
|
55
100
|
export function matchGoals(md, target, cwd) {
|
|
56
|
-
return (md?.goals ?? []).filter((g) => g.target && sameTarget(g.target, target, cwd));
|
|
101
|
+
return (md?.goals ?? []).filter((g) => g.target && (isOptionsGoal(g) ? globMatches(g.target, target, cwd) : sameTarget(g.target, target, cwd)));
|
|
57
102
|
}
|
|
58
103
|
|
|
59
104
|
const norm = (s) => String(s ?? "").trim().toLowerCase();
|
|
60
105
|
|
|
61
106
|
// Applies the declared breaks of the goals of this page to the findings. `unapplied` lists the breaks
|
|
62
107
|
// that did nothing and why: any break whose rule id is not in knownIds, and each break of a goal of this
|
|
63
|
-
// page that was not applied. A break of another page is not listed.
|
|
64
|
-
export function applyBreaks(findings, breaks, goals, rules, knownIds) {
|
|
108
|
+
// page that was not applied. A break of another page, or one whose Target names another file, is not listed.
|
|
109
|
+
export function applyBreaks(findings, breaks, goals, rules, knownIds, target, cwd) {
|
|
65
110
|
const pieces = new Set(goals.map((g) => norm(g.piece)));
|
|
66
111
|
const known = knownIds ? new Set([...knownIds].map(norm)) : null;
|
|
67
|
-
const
|
|
112
|
+
const here = (b) => !b.target || sameTarget(b.target, target, cwd);
|
|
113
|
+
const live = breaks.filter((b) => (b.status === "kept" || b.status === "trying") && pieces.has(norm(b.piece)) && here(b));
|
|
68
114
|
const applied = new Set();
|
|
69
115
|
const out = findings.map((f) => {
|
|
70
116
|
if (f.level !== "fail" && f.level !== "hint") {
|
|
@@ -92,7 +138,7 @@ export function applyBreaks(findings, breaks, goals, rules, knownIds) {
|
|
|
92
138
|
let reason = null;
|
|
93
139
|
if (known && !known.has(norm(b.rule))) {
|
|
94
140
|
reason = "unknown rule id";
|
|
95
|
-
} else if (!pieces.has(norm(b.piece))) {
|
|
141
|
+
} else if (!pieces.has(norm(b.piece)) || !here(b)) {
|
|
96
142
|
continue;
|
|
97
143
|
} else if (b.status === "reverted") {
|
|
98
144
|
reason = "status is reverted";
|
|
@@ -110,3 +156,45 @@ export function applyBreaks(findings, breaks, goals, rules, knownIds) {
|
|
|
110
156
|
}
|
|
111
157
|
return { findings: out, applied: [...applied], unapplied };
|
|
112
158
|
}
|
|
159
|
+
|
|
160
|
+
// Applies the declared moves of the goals of this page, after applyBreaks. A hint whose rule lists
|
|
161
|
+
// declared_by is explained by a decision "<move> followed|broken" or a live break (trying or kept) on the
|
|
162
|
+
// move, of a goal of this page, with no Target or this Target. Only where the finding measured the move
|
|
163
|
+
// (moves[move].holds) does the hint become level declared; elsewhere it stays a hint and says why.
|
|
164
|
+
// The original message always stays as the first evidence line of a declared finding.
|
|
165
|
+
export function applyDeclarations(findings, md, goals, rules, target, cwd) {
|
|
166
|
+
const pieces = new Set(goals.map((g) => norm(g.piece)));
|
|
167
|
+
const here = (e) => pieces.has(norm(e.piece)) && (!e.target || sameTarget(e.target, target, cwd));
|
|
168
|
+
const declarationOf = (move) => {
|
|
169
|
+
const d = (md?.decisions ?? []).find((x) => norm(x.rule) === norm(move) && (x.action === "followed" || x.action === "broken") && here(x));
|
|
170
|
+
if (d) {
|
|
171
|
+
return { piece: d.piece, by: "decision", text: d.decision };
|
|
172
|
+
}
|
|
173
|
+
const b = (md?.breaks ?? []).find((x) => norm(x.rule) === norm(move) && (x.status === "trying" || x.status === "kept") && here(x));
|
|
174
|
+
return b ? { piece: b.piece, by: "break", text: b.effect } : null;
|
|
175
|
+
};
|
|
176
|
+
const applied = [];
|
|
177
|
+
const out = findings.map((f) => {
|
|
178
|
+
if (f.level !== "hint") {
|
|
179
|
+
return f;
|
|
180
|
+
}
|
|
181
|
+
const rule = rules.find((r) => norm(r.id) === norm(f.ruleId));
|
|
182
|
+
for (const move of rule?.declared_by ?? []) {
|
|
183
|
+
const found = declarationOf(move);
|
|
184
|
+
if (!found) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const read = f.moves?.[move];
|
|
188
|
+
if (!read) {
|
|
189
|
+
return { ...f, evidence: [`${move} is declared for ${found.piece}, but the move was not measured here.`, ...(f.evidence ?? [])] };
|
|
190
|
+
}
|
|
191
|
+
if (!read.holds) {
|
|
192
|
+
return { ...f, evidence: [`${move} is declared for ${found.piece}, but here ${read.detail}, so it reads as the move's excess, not the move.`, ...(f.evidence ?? [])] };
|
|
193
|
+
}
|
|
194
|
+
applied.push({ ruleId: f.ruleId, move, piece: found.piece, width: f.width, by: found.by, text: found.text });
|
|
195
|
+
return { ...f, level: "declared", message: `Declared move ${move} (${found.text}). Measured: ${read.detail}.`, evidence: [f.message, ...(f.evidence ?? [])] };
|
|
196
|
+
}
|
|
197
|
+
return f;
|
|
198
|
+
});
|
|
199
|
+
return { findings: out, applied };
|
|
200
|
+
}
|
|
@@ -104,6 +104,26 @@ function decorativeImages(rule, m) {
|
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// CR14: silent without the filter list or without a large image; a hint naming the large images shown recolored.
|
|
108
|
+
function imageTreatment(rule, m) {
|
|
109
|
+
if (!m.a11y || !Array.isArray(rule.threshold?.filters)) return null;
|
|
110
|
+
const list = m.a11y.largeImages ?? [];
|
|
111
|
+
if (list.length === 0) return null;
|
|
112
|
+
const treated = list.filter((i) => i.treatment);
|
|
113
|
+
// The measurer reads at most a fixed number of large images; past it the count says so.
|
|
114
|
+
const read = Number.isFinite(m.a11y.totalLarge) && m.a11y.totalLarge > list.length ? `, of the first ${plural(list.length, "large image")} read` : "";
|
|
115
|
+
if (treated.length === 0) return makeFinding(rule, m.width, "pass", `No large image is shown recolored by a filter or a blend mode${read}.`);
|
|
116
|
+
const lines = treated.map((i) => `${clip(i.selector)} (${i.treatment})`);
|
|
117
|
+
const shown = lines.slice(0, SHOWN).join(", ") + (lines.length > SHOWN ? `, and ${lines.length - SHOWN} more` : "");
|
|
118
|
+
return makeFinding(
|
|
119
|
+
rule,
|
|
120
|
+
m.width,
|
|
121
|
+
"hint",
|
|
122
|
+
`${treated.length} large ${treated.length === 1 ? "image is" : "images are"} shown recolored${read}: ${shown}. If one is proof (a customer, a result, the product as received), it may read as staged; keep proof close to the original or declare the treatment.`,
|
|
123
|
+
lines,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
107
127
|
const who = (e) => `${clip(e.selector)}${e.label ? ` "${clip(e.label, 24)}"` : ""}`;
|
|
108
128
|
|
|
109
129
|
function focusVisible(rule, m) {
|
|
@@ -198,6 +218,7 @@ export const a11yEvaluators = {
|
|
|
198
218
|
"a11y.names": names,
|
|
199
219
|
"a11y.alt": alt,
|
|
200
220
|
"a11y.decorative-images": decorativeImages,
|
|
221
|
+
"a11y.image-treatment": imageTreatment,
|
|
201
222
|
"a11y.lang": lang,
|
|
202
223
|
"a11y.title": title,
|
|
203
224
|
"a11y.headings": headings,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { makeFinding } from "../finding.mjs";
|
|
2
|
+
import { cvd } from "../../measure/cvd.mjs";
|
|
2
3
|
|
|
3
4
|
const clip = (s, n = 40) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
|
|
4
5
|
const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
|
|
@@ -41,7 +42,12 @@ function contrast(rule, m) {
|
|
|
41
42
|
if (bad.length === 0) return makeFinding(rule, m.width, "pass", "Text contrast meets the minimum.");
|
|
42
43
|
const evidence = bad
|
|
43
44
|
.slice(0, 5)
|
|
44
|
-
.
|
|
45
|
+
.flatMap((r) => [
|
|
46
|
+
`"${clip(r.text)}" ${r.fg} on ${r.bg}: ${r.ratio}:1 (${r.size} text needs ${t[r.size]}:1)`,
|
|
47
|
+
...(r.hidden === true
|
|
48
|
+
? [`"${clip(r.text)}" is hidden from assistive technology (aria-hidden). WCAG 1.4.3 exempts text that is pure decoration; if it is, record that as a decision. The fail stays.`]
|
|
49
|
+
: []),
|
|
50
|
+
]);
|
|
45
51
|
return makeFinding(
|
|
46
52
|
rule,
|
|
47
53
|
m.width,
|
|
@@ -79,7 +85,48 @@ function textChroma(rule, m) {
|
|
|
79
85
|
return makeFinding(rule, m.width, "hint", "Much of the text is in a chromatic color.", evidence);
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
const rgbOf = (hex) => ({ r: parseInt(hex.slice(1, 3), 16), g: parseInt(hex.slice(3, 5), 16), b: parseInt(hex.slice(5, 7), 16) });
|
|
89
|
+
const round1 = (n) => Math.round(n * 10) / 10;
|
|
90
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
91
|
+
// The unrounded fraction of the view an area entry covers (pct, in percent and rounded, for older readings).
|
|
92
|
+
const shareOf = (a) => (Number.isFinite(a.share) ? a.share : a.pct / 100);
|
|
93
|
+
|
|
94
|
+
// GR10: a Brand color is present when the first-view area entries within maxDeltaE of it (Delta E 1976, the
|
|
95
|
+
// chart measurer's conversion) cover at least minShare of the view, on the unrounded shares. Silent without
|
|
96
|
+
// Brand colors or area entries; the measurer notes the missing lines.
|
|
97
|
+
function brand(rule, m) {
|
|
98
|
+
const t = rule.threshold;
|
|
99
|
+
if (!m.color || !hasNumbers(t, ["maxDeltaE", "minShare"])) return null;
|
|
100
|
+
const tokens = m.color.brand ?? [];
|
|
101
|
+
const area = (m.color.area ?? []).filter((a) => /^#[0-9a-f]{6}$/i.test(a.hex ?? ""));
|
|
102
|
+
if (tokens.length === 0 || area.length === 0) return null;
|
|
103
|
+
const rows = tokens.map((tok) => {
|
|
104
|
+
const rgb = rgbOf(tok.hex);
|
|
105
|
+
let covered = 0;
|
|
106
|
+
let nearest = null;
|
|
107
|
+
for (const a of area) {
|
|
108
|
+
const d = cvd.deltaE(rgb, rgbOf(a.hex));
|
|
109
|
+
if (d <= t.maxDeltaE) covered += shareOf(a);
|
|
110
|
+
if (!nearest || d < nearest.d) nearest = { hex: a.hex, d, pct: a.pct };
|
|
111
|
+
}
|
|
112
|
+
return { tok, covered, nearest };
|
|
113
|
+
});
|
|
114
|
+
const label = (tok) => (tok.name ? `${tok.name} ${tok.hex}` : tok.hex);
|
|
115
|
+
const present = rows.filter((r) => r.covered >= t.minShare).sort((a, b) => b.covered - a.covered);
|
|
116
|
+
if (present.length > 0) {
|
|
117
|
+
return makeFinding(rule, m.width, "pass", `${label(present[0].tok)} covers ${round1(present[0].covered * 100)}% of the first view.`);
|
|
118
|
+
}
|
|
119
|
+
return makeFinding(
|
|
120
|
+
rule,
|
|
121
|
+
m.width,
|
|
122
|
+
"hint",
|
|
123
|
+
"None of the Brand colors is in the first view.",
|
|
124
|
+
rows.map((r) => `${label(r.tok)}: nearest ${r.nearest.hex} at Delta E ${round1(r.nearest.d)}, ${round1(r.nearest.pct)}% of the first view, covered ${round2(r.covered * 100)}% within Delta E ${t.maxDeltaE}`),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
82
128
|
export const colorEvaluators = {
|
|
129
|
+
"color.brand": brand,
|
|
83
130
|
"color.contrast": contrast,
|
|
84
131
|
"color.area": area,
|
|
85
132
|
"color.text-chroma": textChroma,
|