@uselazuli/cli 1.0.1 → 1.0.3
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 +39 -0
- package/README.md +5 -5
- package/bin/lazuli.mjs +69 -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 +3 -3
- package/rules/ui/compose.yaml +28 -1
- package/rules/ui/review.yaml +4 -3
- package/skills/lazuli/SKILL.md +9 -6
- package/skills/lazuli/procedures/review-design.md +1 -0
- package/skills/lazuli/procedures/show-options.md +2 -1
- package/skills/lazuli-content-interface-writing/SKILL.md +1 -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/capture.mjs +1 -1
- package/src/commands/catalog.mjs +1 -1
- package/src/commands/check-design.mjs +62 -17
- package/src/commands/compare-designs.mjs +73 -6
- package/src/commands/draft-memo.mjs +7 -3
- package/src/commands/hooks.mjs +7 -5
- package/src/commands/record-log.mjs +87 -25
- package/src/commands/render-options.mjs +81 -15
- package/src/measure/a11y.mjs +8 -0
- package/src/measure/cases.mjs +24 -5
- package/src/measure/color.mjs +7 -0
- package/src/measure/in-page/a11y.js +84 -0
- package/src/measure/in-page/color.js +3 -1
- package/src/measure/in-page/composition.js +10 -3
- package/src/measure/in-page/extreme.js +42 -9
- package/src/measure/in-page/motion-probe.js +2 -0
- package/src/measure/in-page/type.js +3 -0
- package/src/measure/layout.mjs +21 -3
- package/src/measure/motion.mjs +2 -1
- package/src/measure/registry.mjs +3 -2
- package/src/measure/rhythm.mjs +8 -0
- package/src/measure/timeline.mjs +5 -5
- package/src/project/gate.mjs +12 -3
- package/src/project/lazuli-md.mjs +35 -5
- package/src/project/log.mjs +18 -12
- package/src/project/match.mjs +102 -5
- package/src/report/evaluators/a11y.mjs +24 -0
- package/src/report/evaluators/color.mjs +77 -1
- package/src/report/evaluators/extreme.mjs +45 -9
- package/src/report/evaluators/layout.mjs +10 -1
- package/src/report/evaluators/motion.mjs +10 -3
- package/src/report/evaluators/rhythm.mjs +1 -1
- 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 +3 -1
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/rhythm.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
+
import { isOptionsGoal } from "../project/lazuli-md.mjs";
|
|
2
3
|
|
|
3
4
|
let script;
|
|
4
5
|
|
|
@@ -62,6 +63,12 @@ export async function measureRhythm(page, ctx = {}) {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
// A page covered only by options goals, none with a Rhythm line: the map belongs to the chosen page, not to a folder of options.
|
|
67
|
+
const optionsOnly = goals.length > 0 && goals.every(isOptionsGoal) && declared === null;
|
|
68
|
+
if (optionsOnly) {
|
|
69
|
+
notes.push(`The goals of this page cover a folder of options (${goals.map((g) => g.piece).join(", ")}) and none has a Rhythm line, so the rhythm map was not compared; give the chosen page its own goal with a Rhythm line.`);
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
if (!raw.scrolls) notes.push(NO_SCROLL_NOTE);
|
|
66
73
|
if (raw.noSections && raw.pinnedContent) notes.push("Content sits in a fixed container and was not measured.");
|
|
67
74
|
|
|
@@ -76,6 +83,7 @@ export async function measureRhythm(page, ctx = {}) {
|
|
|
76
83
|
climax,
|
|
77
84
|
declared,
|
|
78
85
|
hasGoal: goals.length > 0,
|
|
86
|
+
optionsOnly,
|
|
79
87
|
notes,
|
|
80
88
|
};
|
|
81
89
|
}
|
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 {
|
|
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
4
|
const MODES = ["director", "delegate"];
|
|
5
|
-
const STATUSES = ["trying", "kept", "reverted"];
|
|
5
|
+
const STATUSES = ["trying", "kept", "reverted", "superseded"];
|
|
6
6
|
const BEATS = ["breathe", "steady", "accelerate", "climax"];
|
|
7
7
|
export const SECTION_NAMES = [
|
|
8
8
|
"platform and constraints",
|
|
@@ -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();
|
|
@@ -424,17 +440,21 @@ function parseBreaks(lines, problems) {
|
|
|
424
440
|
if (STATUSES.includes(value)) {
|
|
425
441
|
status = value;
|
|
426
442
|
} else {
|
|
427
|
-
problems.push(`Break ${rule}: status must be trying, kept or
|
|
443
|
+
problems.push(`Break ${rule}: status must be trying, kept, reverted or superseded`);
|
|
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()}"`));
|
|
@@ -479,6 +503,12 @@ export function parseLazuliMd(text) {
|
|
|
479
503
|
const brand = parseBrand(found.get("brand") ?? [], problems);
|
|
480
504
|
const goals = parseGoals(found.get("goals") ?? [], problems);
|
|
481
505
|
const breaks = parseBreaks(found.get("breaks") ?? [], problems);
|
|
506
|
+
const pieces = new Set(goals.map((g) => g.piece.trim().toLowerCase()));
|
|
507
|
+
for (const b of breaks) {
|
|
508
|
+
if ((b.status === "trying" || b.status === "kept") && !pieces.has(b.piece.trim().toLowerCase())) {
|
|
509
|
+
problems.push(`Break ${b.rule}: Piece "${b.piece}" matches no goal under ## Goals, so it never applies. If the piece is gone, set its status to superseded with record-break.`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
482
512
|
const decisions = parseDecisions(found.get("decisions") ?? [], problems);
|
|
483
513
|
return { mode, idea, audience, brand, goals, breaks, decisions, problems };
|
|
484
514
|
}
|
package/src/project/log.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { BULLET, FIELD, HEADING, SECTION_NAMES, knownSection, stripComments } fr
|
|
|
4
4
|
// Everything the entry does not own stays byte for byte: other sections, comments, hand-written lines
|
|
5
5
|
// and the line ending (LF or CRLF), including a file that has no final newline.
|
|
6
6
|
|
|
7
|
-
const STATUSES = ["trying", "kept", "reverted"];
|
|
7
|
+
const STATUSES = ["trying", "kept", "reverted", "superseded"];
|
|
8
8
|
const norm = (s) => String(s ?? "").trim().toLowerCase();
|
|
9
9
|
const label = (key) => key.charAt(0).toUpperCase() + key.slice(1);
|
|
10
10
|
|
|
@@ -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,18 +307,18 @@ 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
|
}
|
|
308
314
|
}
|
|
309
315
|
if (given.status !== undefined && given.status !== "" && !STATUSES.includes(given.status)) {
|
|
310
|
-
problems.push("Status must be trying, kept or
|
|
316
|
+
problems.push("Status must be trying, kept, reverted or superseded.");
|
|
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") {
|
|
@@ -90,9 +136,12 @@ export function applyBreaks(findings, breaks, goals, rules, knownIds) {
|
|
|
90
136
|
const unapplied = [];
|
|
91
137
|
for (const b of breaks) {
|
|
92
138
|
let reason = null;
|
|
139
|
+
if (b.status === "superseded") {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
93
142
|
if (known && !known.has(norm(b.rule))) {
|
|
94
143
|
reason = "unknown rule id";
|
|
95
|
-
} else if (!pieces.has(norm(b.piece))) {
|
|
144
|
+
} else if (!pieces.has(norm(b.piece)) || !here(b)) {
|
|
96
145
|
continue;
|
|
97
146
|
} else if (b.status === "reverted") {
|
|
98
147
|
reason = "status is reverted";
|
|
@@ -110,3 +159,51 @@ export function applyBreaks(findings, breaks, goals, rules, knownIds) {
|
|
|
110
159
|
}
|
|
111
160
|
return { findings: out, applied: [...applied], unapplied };
|
|
112
161
|
}
|
|
162
|
+
|
|
163
|
+
// Applies the declared moves of the goals of this page, after applyBreaks. A hint whose rule lists
|
|
164
|
+
// declared_by is explained by a decision "<move> followed|broken" or a live break (trying or kept) on the
|
|
165
|
+
// move, of a goal of this page, with no Target or this Target. Only where the finding measured the move
|
|
166
|
+
// (moves[move].holds) does the hint become level declared; elsewhere it stays a hint and says why.
|
|
167
|
+
// The original message always stays as the first evidence line of a declared finding. notHeld lists every
|
|
168
|
+
// move read here that did not hold, with the piece it was declared for and absent: true when the move is not on the page.
|
|
169
|
+
export function applyDeclarations(findings, md, goals, rules, target, cwd) {
|
|
170
|
+
const pieces = new Set(goals.map((g) => norm(g.piece)));
|
|
171
|
+
const here = (e) => pieces.has(norm(e.piece)) && (!e.target || sameTarget(e.target, target, cwd));
|
|
172
|
+
const declarationOf = (move) => {
|
|
173
|
+
const d = (md?.decisions ?? []).find((x) => norm(x.rule) === norm(move) && (x.action === "followed" || x.action === "broken") && here(x));
|
|
174
|
+
if (d) {
|
|
175
|
+
return { piece: d.piece, by: "decision", text: d.decision };
|
|
176
|
+
}
|
|
177
|
+
const b = (md?.breaks ?? []).find((x) => norm(x.rule) === norm(move) && (x.status === "trying" || x.status === "kept") && here(x));
|
|
178
|
+
return b ? { piece: b.piece, by: "break", text: b.effect } : null;
|
|
179
|
+
};
|
|
180
|
+
const applied = [];
|
|
181
|
+
const notHeld = [];
|
|
182
|
+
const out = findings.map((f) => {
|
|
183
|
+
if (f.level !== "hint") {
|
|
184
|
+
return f;
|
|
185
|
+
}
|
|
186
|
+
const rule = rules.find((r) => norm(r.id) === norm(f.ruleId));
|
|
187
|
+
for (const move of rule?.declared_by ?? []) {
|
|
188
|
+
const found = declarationOf(move);
|
|
189
|
+
if (!found) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const read = f.moves?.[move];
|
|
193
|
+
if (!read) {
|
|
194
|
+
return { ...f, evidence: [`${move} is declared for ${found.piece}, but the move was not measured here.`, ...(f.evidence ?? [])] };
|
|
195
|
+
}
|
|
196
|
+
if (!read.holds) {
|
|
197
|
+
notHeld.push({ ruleId: f.ruleId, move, piece: found.piece, width: f.width, ...(read.absent ? { absent: true } : {}) });
|
|
198
|
+
if (read.absent) {
|
|
199
|
+
return { ...f, evidence: [`${move} is declared for ${found.piece}, but here ${read.detail}, so the move is not on this page at this width.`, ...(f.evidence ?? [])] };
|
|
200
|
+
}
|
|
201
|
+
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 ?? [])] };
|
|
202
|
+
}
|
|
203
|
+
applied.push({ ruleId: f.ruleId, move, piece: found.piece, width: f.width, by: found.by, text: found.text });
|
|
204
|
+
return { ...f, level: "declared", message: `Declared move ${move} (${found.text}). Measured: ${read.detail}.`, evidence: [f.message, ...(f.evidence ?? [])] };
|
|
205
|
+
}
|
|
206
|
+
return f;
|
|
207
|
+
});
|
|
208
|
+
return { findings: out, applied, notHeld };
|
|
209
|
+
}
|
|
@@ -104,6 +104,29 @@ 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) => {
|
|
117
|
+
const file = i.alt ? "" : clip(i.fileName ?? "");
|
|
118
|
+
return `${clip(i.selector)}${i.alt ? ` "${clip(i.alt)}"` : file ? ` ${file}` : ""} (${i.treatment})`;
|
|
119
|
+
});
|
|
120
|
+
const shown = lines.slice(0, SHOWN).join(", ") + (lines.length > SHOWN ? `, and ${lines.length - SHOWN} more` : "");
|
|
121
|
+
return makeFinding(
|
|
122
|
+
rule,
|
|
123
|
+
m.width,
|
|
124
|
+
"hint",
|
|
125
|
+
`${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.`,
|
|
126
|
+
lines,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
107
130
|
const who = (e) => `${clip(e.selector)}${e.label ? ` "${clip(e.label, 24)}"` : ""}`;
|
|
108
131
|
|
|
109
132
|
function focusVisible(rule, m) {
|
|
@@ -198,6 +221,7 @@ export const a11yEvaluators = {
|
|
|
198
221
|
"a11y.names": names,
|
|
199
222
|
"a11y.alt": alt,
|
|
200
223
|
"a11y.decorative-images": decorativeImages,
|
|
224
|
+
"a11y.image-treatment": imageTreatment,
|
|
201
225
|
"a11y.lang": lang,
|
|
202
226
|
"a11y.title": title,
|
|
203
227
|
"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,77 @@ 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. The hint only gains a line per token when
|
|
97
|
+
// the view holds the token's hue at another lightness or chroma (maxHueDeg, minChroma; LCH hue and chroma from
|
|
98
|
+
// the Lab the kit already computes, CSS Color 4 section 19); it never turns a hint into a pass.
|
|
99
|
+
const lch = (rgb) => {
|
|
100
|
+
const { a, b } = cvd.toLab(rgb);
|
|
101
|
+
return { h: ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360, c: Math.hypot(a, b) };
|
|
102
|
+
};
|
|
103
|
+
const hueGap = (h1, h2) => {
|
|
104
|
+
const d = Math.abs(h1 - h2);
|
|
105
|
+
return Math.min(d, 360 - d);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function brand(rule, m) {
|
|
109
|
+
const t = rule.threshold;
|
|
110
|
+
if (!m.color || !hasNumbers(t, ["maxDeltaE", "minShare"])) return null;
|
|
111
|
+
const tokens = m.color.brand ?? [];
|
|
112
|
+
const area = (m.color.area ?? []).filter((a) => /^#[0-9a-f]{6}$/i.test(a.hex ?? ""));
|
|
113
|
+
if (tokens.length === 0 || area.length === 0) return null;
|
|
114
|
+
const rows = tokens.map((tok) => {
|
|
115
|
+
const rgb = rgbOf(tok.hex);
|
|
116
|
+
let covered = 0;
|
|
117
|
+
let nearest = null;
|
|
118
|
+
for (const a of area) {
|
|
119
|
+
const d = cvd.deltaE(rgb, rgbOf(a.hex));
|
|
120
|
+
if (d <= t.maxDeltaE) covered += shareOf(a);
|
|
121
|
+
if (!nearest || d < nearest.d) nearest = { hex: a.hex, d, pct: a.pct };
|
|
122
|
+
}
|
|
123
|
+
return { tok, rgb, covered, nearest };
|
|
124
|
+
});
|
|
125
|
+
const label = (tok) => (tok.name ? `${tok.name} ${tok.hex}` : tok.hex);
|
|
126
|
+
const hueLine = (r) => {
|
|
127
|
+
if (!hasNumbers(t, ["maxHueDeg", "minChroma"])) return "";
|
|
128
|
+
const tok = lch(r.rgb);
|
|
129
|
+
if (tok.c < t.minChroma) return "";
|
|
130
|
+
let sum = 0;
|
|
131
|
+
let largest = null;
|
|
132
|
+
for (const a of area) {
|
|
133
|
+
const rgb = rgbOf(a.hex);
|
|
134
|
+
const e = lch(rgb);
|
|
135
|
+
if (e.c < t.minChroma || cvd.deltaE(r.rgb, rgb) <= t.maxDeltaE) continue;
|
|
136
|
+
const gap = hueGap(tok.h, e.h);
|
|
137
|
+
if (gap > t.maxHueDeg) continue;
|
|
138
|
+
sum += shareOf(a);
|
|
139
|
+
if (!largest || shareOf(a) > largest.share) largest = { hex: a.hex, share: shareOf(a), gap };
|
|
140
|
+
}
|
|
141
|
+
if (!largest || sum < t.minShare) return "";
|
|
142
|
+
return `; the first view has ${round1(sum * 100)}% in its hue at another lightness or chroma (largest ${largest.hex} at ${round1(largest.share * 100)}%, hue ${Math.round(largest.gap)} degrees off)`;
|
|
143
|
+
};
|
|
144
|
+
const present = rows.filter((r) => r.covered >= t.minShare).sort((a, b) => b.covered - a.covered);
|
|
145
|
+
if (present.length > 0) {
|
|
146
|
+
return makeFinding(rule, m.width, "pass", `${label(present[0].tok)} covers ${round1(present[0].covered * 100)}% of the first view.`);
|
|
147
|
+
}
|
|
148
|
+
return makeFinding(
|
|
149
|
+
rule,
|
|
150
|
+
m.width,
|
|
151
|
+
"hint",
|
|
152
|
+
"None of the Brand colors is in the first view.",
|
|
153
|
+
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}${hueLine(r)}`),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
82
157
|
export const colorEvaluators = {
|
|
158
|
+
"color.brand": brand,
|
|
83
159
|
"color.contrast": contrast,
|
|
84
160
|
"color.area": area,
|
|
85
161
|
"color.text-chroma": textChroma,
|