@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.
Files changed (61) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +5 -5
  3. package/bin/lazuli.mjs +69 -19
  4. package/package.json +1 -1
  5. package/rules/content/HYPOTHESES.md +3 -2
  6. package/rules/content/review.yaml +33 -2
  7. package/rules/graphic/HYPOTHESES.md +1 -0
  8. package/rules/graphic/review.yaml +29 -0
  9. package/rules/motion/HYPOTHESES.md +3 -3
  10. package/rules/motion/review.yaml +4 -4
  11. package/rules/typography/HYPOTHESES.md +1 -1
  12. package/rules/typography/review.yaml +2 -2
  13. package/rules/ui/HYPOTHESES.md +3 -3
  14. package/rules/ui/compose.yaml +28 -1
  15. package/rules/ui/review.yaml +4 -3
  16. package/skills/lazuli/SKILL.md +9 -6
  17. package/skills/lazuli/procedures/review-design.md +1 -0
  18. package/skills/lazuli/procedures/show-options.md +2 -1
  19. package/skills/lazuli-content-interface-writing/SKILL.md +1 -1
  20. package/skills/lazuli-content-voice/SKILL.md +1 -0
  21. package/skills/lazuli-graphic-identity/SKILL.md +3 -1
  22. package/skills/lazuli-ui-composition/SKILL.md +4 -4
  23. package/skills/lazuli-ui-layout-review/SKILL.md +2 -2
  24. package/src/browser.mjs +2 -1
  25. package/src/commands/capture.mjs +1 -1
  26. package/src/commands/catalog.mjs +1 -1
  27. package/src/commands/check-design.mjs +62 -17
  28. package/src/commands/compare-designs.mjs +73 -6
  29. package/src/commands/draft-memo.mjs +7 -3
  30. package/src/commands/hooks.mjs +7 -5
  31. package/src/commands/record-log.mjs +87 -25
  32. package/src/commands/render-options.mjs +81 -15
  33. package/src/measure/a11y.mjs +8 -0
  34. package/src/measure/cases.mjs +24 -5
  35. package/src/measure/color.mjs +7 -0
  36. package/src/measure/in-page/a11y.js +84 -0
  37. package/src/measure/in-page/color.js +3 -1
  38. package/src/measure/in-page/composition.js +10 -3
  39. package/src/measure/in-page/extreme.js +42 -9
  40. package/src/measure/in-page/motion-probe.js +2 -0
  41. package/src/measure/in-page/type.js +3 -0
  42. package/src/measure/layout.mjs +21 -3
  43. package/src/measure/motion.mjs +2 -1
  44. package/src/measure/registry.mjs +3 -2
  45. package/src/measure/rhythm.mjs +8 -0
  46. package/src/measure/timeline.mjs +5 -5
  47. package/src/project/gate.mjs +12 -3
  48. package/src/project/lazuli-md.mjs +35 -5
  49. package/src/project/log.mjs +18 -12
  50. package/src/project/match.mjs +102 -5
  51. package/src/report/evaluators/a11y.mjs +24 -0
  52. package/src/report/evaluators/color.mjs +77 -1
  53. package/src/report/evaluators/extreme.mjs +45 -9
  54. package/src/report/evaluators/layout.mjs +10 -1
  55. package/src/report/evaluators/motion.mjs +10 -3
  56. package/src/report/evaluators/rhythm.mjs +1 -1
  57. package/src/report/evaluators/type.mjs +6 -3
  58. package/src/report/format.mjs +4 -4
  59. package/src/rules/load.mjs +18 -0
  60. package/src/rules/schema.mjs +8 -0
  61. package/templates/LAZULI.md +3 -1
@@ -3,11 +3,48 @@ import { listed } from "../evidence.mjs";
3
3
  import { caseWords } from "../../measure/extreme.mjs";
4
4
 
5
5
  const plural = (n, one, many) => (n === 1 ? one : many);
6
- const quoted = (t) => `"${t.text}" (${t.selector})`;
7
- const cutHow = { ellipsis: ", with an ellipsis", clamped: ", clamped" };
6
+ const cutHow = { ellipsis: "cut with an ellipsis", clamped: "clamped" };
8
7
  // A case that did not run, failed or was not compared is noted by the measurer; the evaluators then return
9
8
  // null, never a vacuous pass.
10
9
 
10
+ // What the case adds, grouped by element in first-seen order (spills, cut, cut away, overlaps, past the right
11
+ // edge): one entry per element with the ways it breaks.
12
+ function byElement(b) {
13
+ const els = new Map();
14
+ const add = (t, how) => {
15
+ const key = t.id ?? `${t.selector} ${t.text}`;
16
+ const e = els.get(key) ?? { selector: t.selector, text: t.text, bleedsAtRest: t.bleedsAtRest === true, how: [] };
17
+ if (!e.how.includes(how)) e.how.push(how);
18
+ els.set(key, e);
19
+ };
20
+ for (const t of b.spills ?? []) add(t, "spills");
21
+ for (const t of b.cut ?? []) add(t, cutHow[t.cut] ?? "cut");
22
+ for (const t of b.lost ?? []) add(t, "cut away");
23
+ for (const [a, x] of b.overlaps ?? []) {
24
+ add(a, `overlaps "${x.text}"`);
25
+ add(x, `overlaps "${a.text}"`);
26
+ }
27
+ for (const t of b.wide ?? []) add(t, "runs past the right edge");
28
+ return [...els.values()];
29
+ }
30
+
31
+ // UC1 read through CR7 and CR8: the move holds when every element the case names already bleeds at rest and
32
+ // the sideways scroll or the text past a clipped right edge, if any, is named by an element past the right edge. A page where no text
33
+ // (decorative included) bleeds at rest does not show the move: it reads as absent, and says when that is because the page
34
+ // scrolls sideways at rest. A reading without the count gives none.
35
+ function bleedMove(b, els) {
36
+ if (!Number.isFinite(b.restBleeds)) return null;
37
+ if (b.restBleeds === 0) return { holds: false, absent: true, detail: b.restSideways ? "the page scrolls sideways at rest, and a text past the edge of a scrolling page is not a bleed" : "no text crosses the edge of the view at rest" };
38
+ if (!(b.wide?.length > 0)) {
39
+ if (Number.isFinite(b.overflowX) && b.overflowX > 0) return { holds: false, detail: "no element was named for the sideways scroll" };
40
+ if (Number.isFinite(b.clippedX) && b.clippedX > 0) return { holds: false, detail: "no element was named for the text past the clipped right edge" };
41
+ }
42
+ const selectors = (list) => [...new Set(list.map((e) => e.selector))].join(", ");
43
+ const off = els.filter((e) => !e.bleedsAtRest);
44
+ if (off.length === 0) return { holds: true, detail: `the elements that break are the ones that already bleed at rest: ${selectors(els)}` };
45
+ return { holds: false, detail: `${off.length} of ${els.length} elements that break do not bleed at rest: ${selectors(off)}` };
46
+ }
47
+
11
48
  // The finding of one case: a hint naming what the case adds, else a pass.
12
49
  function judge(rule, m, kind, words) {
13
50
  const c = m.extreme?.cases?.[kind];
@@ -15,6 +52,7 @@ function judge(rule, m, kind, words) {
15
52
  if (!c || !c.ran || !b) return null;
16
53
  const parts = [];
17
54
  if (Number.isFinite(b.overflowX) && b.overflowX > 0) parts.push(`the page scrolls sideways by ${Math.round(b.overflowX)} px`);
55
+ if (Number.isFinite(b.clippedX) && b.clippedX > 0) parts.push(`${Math.round(b.clippedX)} px of text runs past the clipped right edge`);
18
56
  const n = (list) => list?.length ?? 0;
19
57
  if (n(b.spills)) parts.push(`${n(b.spills)} ${plural(n(b.spills), "text spills out of its box", "texts spill out of their box")}`);
20
58
  if (n(b.cut)) parts.push(`${n(b.cut)} ${plural(n(b.cut), "text is cut", "texts are cut")}`);
@@ -23,13 +61,11 @@ function judge(rule, m, kind, words) {
23
61
  if (parts.length === 0) {
24
62
  return makeFinding(rule, m.width, "pass", `With ${words}, nothing new spills, is cut or overlaps at ${m.width} px.`);
25
63
  }
26
- const evidence = [
27
- ...(b.spills ?? []).map((t) => `spills: ${quoted(t)}`),
28
- ...(b.cut ?? []).map((t) => `cut: ${quoted(t)}${cutHow[t.cut] ?? ""}`),
29
- ...(b.lost ?? []).map((t) => `cut away: ${quoted(t)}`),
30
- ...(b.overlaps ?? []).map(([a, x]) => `overlap: ${quoted(a)} and ${quoted(x)}`),
31
- ];
32
- return makeFinding(rule, m.width, "hint", `With ${words}, things break at ${m.width} px: ${parts.join(", ")}.`, listed(evidence));
64
+ const els = byElement(b);
65
+ const evidence = els.map((e) => `${e.selector} "${e.text}": ${e.how.join(", ")}${e.bleedsAtRest ? " (bleeds at rest)" : ""}`);
66
+ const hint = makeFinding(rule, m.width, "hint", `With ${words}, things break at ${m.width} px: ${parts.join(", ")}.`, listed(evidence));
67
+ const move = bleedMove(b, els);
68
+ return move ? { ...hint, moves: { UC1: move } } : hint;
33
69
  }
34
70
 
35
71
  function growth(rule, m) {
@@ -44,6 +44,14 @@ function emptySpace(rule, m) {
44
44
  return makeFinding(rule, m.width, "pass", `Empty space gathers in part of the first view (the emptiest and fullest areas differ by ${pct(r.emptySpread)}).`, evidence);
45
45
  }
46
46
 
47
+ // UC9 read through UR3: the pair of the two largest blocks leads the rest at the UR3 cutoff applied to the
48
+ // pair. With no third block nothing shows the pair leading, so the move does not hold.
49
+ function tensionPair(f, cutoff) {
50
+ const space = f.pairGapPx === null ? "" : f.pairGapPx < 0 ? `; they overlap by ${-f.pairGapPx} px` : `; ${f.pairGapPx} px apart`;
51
+ if (f.pairLead === null) return { holds: false, detail: `the first view has only two blocks, ${f.selector} and ${f.second}, so no third block shows the pair leading${space}` };
52
+ return { holds: f.pairLead >= cutoff, detail: `the two largest blocks, ${f.selector} and ${f.second}, lead the rest at ${f.pairLead}x the third (cutoff ${cutoff}x)${space}` };
53
+ }
54
+
47
55
  function focalPoint(rule, m) {
48
56
  const r = m.layout;
49
57
  const t = rule.threshold;
@@ -52,7 +60,8 @@ function focalPoint(rule, m) {
52
60
  if (f.dominance === null) return makeFinding(rule, m.width, "pass", `The first view has one block, ${f.selector}.`);
53
61
  const evidence = [`${f.selector}: ${f.dominance}x the next largest block, center at ${pct(f.x)} across and ${pct(f.y)} down`];
54
62
  if (f.dominance < t.minDominance) {
55
- return makeFinding(rule, m.width, "hint", `No block leads the first view: the largest is ${f.dominance}x the next (cutoff ${t.minDominance}x).`, evidence);
63
+ const hint = makeFinding(rule, m.width, "hint", `No block leads the first view: the largest is ${f.dominance}x the next (cutoff ${t.minDominance}x).`, evidence);
64
+ return f.second ? { ...hint, moves: { UC9: tensionPair(f, t.minDominance) } } : hint;
56
65
  }
57
66
  return makeFinding(rule, m.width, "pass", `${f.selector} leads the first view at ${f.dominance}x the next block.`, evidence);
58
67
  }
@@ -10,6 +10,8 @@ const plural = (n, one, many) => (n === 1 ? one : many);
10
10
  const MICRO = new Set(["hover", "focus", "click"]);
11
11
  const PAGE = new Set(["load", "scroll"]);
12
12
  const finite = (a) => a.endMs !== null;
13
+ // A scroll-linked animation (animation-timeline) runs with the scroll position, not with time: it has no length.
14
+ const timed = (a) => finite(a) && a.scrollLinked !== true;
13
15
  const LINEAR = new Set(["linear", "cubic-bezier(0, 0, 1, 1)"]);
14
16
  const listing = (props) => props.join(" and ");
15
17
 
@@ -27,7 +29,7 @@ function microDuration(rule, m) {
27
29
  const all = animationsOf(m);
28
30
  const maxMs = rule.threshold?.maxMs;
29
31
  if (!all || !Number.isFinite(maxMs)) return null;
30
- const list = all.filter((a) => MICRO.has(a.trigger) && finite(a));
32
+ const list = all.filter((a) => MICRO.has(a.trigger) && timed(a));
31
33
  if (list.length === 0) return null;
32
34
  const long = list.filter((a) => a.endMs > maxMs);
33
35
  if (long.length > 0) {
@@ -42,7 +44,7 @@ function transitionDuration(rule, m) {
42
44
  const all = animationsOf(m);
43
45
  const maxMs = rule.threshold?.maxMs;
44
46
  if (!all || !Number.isFinite(maxMs)) return null;
45
- const list = all.filter((a) => PAGE.has(a.trigger) && finite(a));
47
+ const list = all.filter((a) => PAGE.has(a.trigger) && timed(a));
46
48
  if (list.length === 0) return null;
47
49
  const long = list.filter((a) => a.endMs > maxMs);
48
50
  if (long.length > 0) {
@@ -56,7 +58,12 @@ function transitionDuration(rule, m) {
56
58
  function easing(rule, m) {
57
59
  const all = animationsOf(m);
58
60
  if (!all) return null;
59
- const list = all.filter((a) => finite(a) && a.moves);
61
+ const linked = all.filter((a) => a.scrollLinked === true && a.moves);
62
+ if (linked.length > 0) {
63
+ const n = linked.length;
64
+ noteOn(m, `${n} ${plural(n, "animation linked to scroll (animation-timeline) is not judged for easing: the scroll position is its curve.", "animations linked to scroll (animation-timeline) are not judged for easing: the scroll position is their curve.")}`);
65
+ }
66
+ const list = all.filter((a) => a.scrollLinked !== true && finite(a) && a.moves);
60
67
  if (list.length === 0) return null;
61
68
  const linear = list.filter((a) => LINEAR.has(a.easing));
62
69
  if (linear.length > 0) {
@@ -40,7 +40,7 @@ function pace(rule, m) {
40
40
 
41
41
  function map(rule, m) {
42
42
  const r = m.rhythm;
43
- if (!r || notComparable(r)) return null;
43
+ if (!r || notComparable(r) || r.optionsOnly) return null;
44
44
  if (!r.declared) {
45
45
  if (!r.hasGoal) return null;
46
46
  return makeFinding(rule, m.width, "hint", "No rhythm map is declared for this page. Add a Rhythm line under its goal in LAZULI.md.");
@@ -45,7 +45,7 @@ function lineLength(rule, m) {
45
45
  // A block with fewer characters in all than minLines full lines at minChars is a caption, not running
46
46
  // text: the cutoff is derived from the two rule values, not a third number.
47
47
  const captionChars = t.minLines * t.minChars;
48
- const total = (b) => (Number.isFinite(b.chars) ? b.chars : b.charsPerLine * b.lines);
48
+ const total = (b) => (Number.isFinite(b.chars) ? b.chars : Number.isFinite(b.charsPerLine * b.lines) ? b.charsPerLine * b.lines : Infinity);
49
49
  const tall = (m.type.blocks ?? []).filter((b) => b.lines >= t.minLines);
50
50
  const long = tall.filter((b) => total(b) >= captionChars);
51
51
  const skipped = long.length < tall.length ? `; blocks under ${captionChars} characters in all were read as captions and not judged` : "";
@@ -87,9 +87,12 @@ function lineHeight(rule, m) {
87
87
  if (!hasNumbers(t, ["minRatio", "maxRatio"])) return null;
88
88
  const multi = (m.type.blocks ?? []).filter((b) => b.lines >= 2);
89
89
  if (multi.length === 0) return null;
90
- const bad = multi.filter((b) => b.lineHeightRatio < t.minRatio || b.lineHeightRatio > t.maxRatio);
90
+ // Display type (WCAG large scale) is judged for the upper bound only: large headings need less.
91
+ const bad = multi.filter((b) => (b.large !== true && b.lineHeightRatio < t.minRatio) || b.lineHeightRatio > t.maxRatio);
91
92
  if (bad.length === 0) {
92
- return makeFinding(rule, m.width, "pass", `Line height is between ${t.minRatio} and ${t.maxRatio} times the font size in every multi-line block.`);
93
+ const display = multi.filter((b) => b.large === true).length;
94
+ const tail = display > 0 ? `; ${plural(display, "display block")} (large scale) ${display === 1 ? "was" : "were"} checked for the upper bound only` : "";
95
+ return makeFinding(rule, m.width, "pass", `Line height is between ${t.minRatio} and ${t.maxRatio} times the font size in every multi-line block${tail}.`);
93
96
  }
94
97
  return makeFinding(
95
98
  rule,
@@ -1,4 +1,4 @@
1
- const ORDER = { fail: 0, hint: 1, break: 2, pass: 3 };
1
+ const ORDER = { fail: 0, hint: 1, break: 2, declared: 3, pass: 4 };
2
2
 
3
3
  // Rules that share a measure give identical findings; show them once with all rule ids.
4
4
  function group(rows) {
@@ -31,7 +31,7 @@ function ruleCounts(findings) {
31
31
  const cur = worst.get(f.ruleId);
32
32
  if (cur === undefined || ORDER[f.level] < ORDER[cur]) worst.set(f.ruleId, f.level);
33
33
  }
34
- const counts = { fail: 0, hint: 0, break: 0, pass: 0 };
34
+ const counts = { fail: 0, hint: 0, break: 0, declared: 0, pass: 0 };
35
35
  for (const level of worst.values()) counts[level] = (counts[level] ?? 0) + 1;
36
36
  return counts;
37
37
  }
@@ -97,7 +97,7 @@ export function formatReport(result) {
97
97
  const top =
98
98
  findings.length === 0
99
99
  ? `Nothing was measured${failedText ? `, ${failedText}` : ""}.`
100
- : `${total.fail} fail, ${total.hint} hint, ${total.pass} pass${total.break > 0 ? `, ${total.break} break` : ""} (rules)${failedText ? `, ${failedText}` : ""}`;
100
+ : `${total.fail} fail, ${total.hint} hint, ${total.pass} pass${total.break > 0 ? `, ${total.break} break` : ""}${total.declared > 0 ? `, ${total.declared} declared` : ""} (rules)${failedText ? `, ${failedText}` : ""}`;
101
101
  const lines = [`Lazuli design check: ${top}`];
102
102
  if (uncheckedNorms.length > 0) {
103
103
  lines.push(`Norms and learned rules not checked because their measurer failed: ${uncheckedNorms.join(", ")}.`);
@@ -163,7 +163,7 @@ export function formatReport(result) {
163
163
  b.rules === undefined
164
164
  ? ""
165
165
  : ` (${b.measured} of ${b.rules} rules measured here; ${failedNote ? `${failedNote}; ` : ""}the others are checked by your agent or by people)`;
166
- const brk = count("break") > 0 ? `, ${count("break")} break` : "";
166
+ const brk = `${count("break") > 0 ? `, ${count("break")} break` : ""}${count("declared") > 0 ? `, ${count("declared")} declared` : ""}`;
167
167
  lines.push(`${b.title}: ${count("fail")} fail, ${count("hint")} hint, ${count("pass")} pass${brk}${coverage}`);
168
168
 
169
169
  const shown = b.groups.filter((g) => g.level !== "pass").sort((a, c) => ORDER[a.level] - ORDER[c.level]);
@@ -103,6 +103,22 @@ const PROJECT_AREA = {
103
103
  skills: [],
104
104
  };
105
105
 
106
+ // Each declared_by id of a rule must be a rule of the kit with moment create (a move).
107
+ function declaredByProblems(own, kit) {
108
+ const problems = [];
109
+ for (const rule of own) {
110
+ for (const id of rule.declared_by ?? []) {
111
+ const move = kit.find((r) => r.id === id);
112
+ if (!move) {
113
+ problems.push(`${rule.id}: declared_by ${id} is not a rule of the kit`);
114
+ } else if (move.moment !== "create") {
115
+ problems.push(`${rule.id}: declared_by ${id} is not a create rule`);
116
+ }
117
+ }
118
+ }
119
+ return problems;
120
+ }
121
+
106
122
  export async function loadKit({ dirs, projectDir }) {
107
123
  const problems = [];
108
124
  const seen = new Map();
@@ -218,6 +234,7 @@ export async function loadKit({ dirs, projectDir }) {
218
234
  }
219
235
  }
220
236
 
237
+ problems.push(...declaredByProblems(rules, rules));
221
238
  if (problems.length > 0) {
222
239
  throw new Error(`Invalid rules:\n${problems.join("\n")}`);
223
240
  }
@@ -239,6 +256,7 @@ export async function loadKit({ dirs, projectDir }) {
239
256
  if (rule.origin === "norm") {
240
257
  errs.push(`${rule.id}: a learned rule cannot be a norm`);
241
258
  }
259
+ errs.push(...declaredByProblems([rule], [...rules, ...projectRules]));
242
260
  if (errs.length > 0) {
243
261
  projectProblems.push(...errs);
244
262
  } else {
@@ -137,6 +137,14 @@ export function validateRule(rule) {
137
137
  }
138
138
  }
139
139
 
140
+ // The moves (create rules) whose declaration can explain this rule's finding; the loader checks they exist.
141
+ if (rule.declared_by !== undefined) {
142
+ const d = rule.declared_by;
143
+ if (!Array.isArray(d) || d.length === 0 || !d.every((x) => typeof x === "string" && ID_RE.test(x))) {
144
+ errors.push("declared_by must be a non-empty list of rule ids");
145
+ }
146
+ }
147
+
140
148
  if (rule.name === undefined || rule.name === null || rule.name === "") {
141
149
  errors.push("name is required");
142
150
  } else if (!isText(rule.name)) {
@@ -49,6 +49,8 @@ One entry per screen or piece: what it must make people understand, feel and do.
49
49
 
50
50
  <!-- Do: is written as a task a person can try on that page (for example book a first visit). The simulated task walks it. -->
51
51
 
52
+ <!-- For the options stage, one goal can cover a folder: Target: ./options/*.html. A break or decision can add Target: <one file> to apply to that file only. -->
53
+
52
54
  - Piece: (name)
53
55
  - Target: (URL or file path of the page, optional)
54
56
  - Understand:
@@ -66,7 +68,7 @@ A log of rules broken on purpose, one entry each. Copy the format below outside
66
68
  - Piece: (name of the piece, as in Goals)
67
69
  - Effect: (the effect you intend)
68
70
  - Check: (the check planned for the effect when the break is logged: a measurement, a separate reviewer or a test with people)
69
- - Status: (trying, kept or reverted)
71
+ - Status: (trying, kept, reverted or superseded)
70
72
  -->
71
73
 
72
74
  ## Decisions