@uselazuli/cli 0.0.0-stage → 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 +120 -0
- package/LICENSE +21 -0
- package/README.md +202 -2
- package/agents/lazuli-design-reviewer.md +30 -0
- package/agents/lazuli-first-look.md +22 -0
- package/agents/lazuli-task-tester.md +25 -0
- package/bin/lazuli.mjs +747 -0
- package/package.json +11 -4
- package/rules/accessibility/HYPOTHESES.md +8 -0
- package/rules/accessibility/_area.yaml +7 -0
- package/rules/accessibility/operable.yaml +100 -0
- package/rules/accessibility/perceivable.yaml +153 -0
- package/rules/accessibility/robust.yaml +24 -0
- package/rules/accessibility/understandable.yaml +72 -0
- package/rules/color/HYPOTHESES.md +27 -0
- package/rules/color/_area.yaml +10 -0
- package/rules/color/adapt.yaml +183 -0
- package/rules/color/create.yaml +259 -0
- package/rules/color/review.yaml +215 -0
- package/rules/color/signal.yaml +196 -0
- package/rules/content/HYPOTHESES.md +19 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +378 -0
- package/rules/content/voice.yaml +144 -0
- package/rules/content/writing.yaml +202 -0
- package/rules/data/HYPOTHESES.md +11 -0
- package/rules/data/_area.yaml +7 -0
- package/rules/data/charts.yaml +189 -0
- package/rules/data/dashboards.yaml +141 -0
- package/rules/data/review.yaml +159 -0
- package/rules/graphic/HYPOTHESES.md +18 -0
- package/rules/graphic/_area.yaml +8 -0
- package/rules/graphic/identity.yaml +141 -0
- package/rules/graphic/pieces.yaml +164 -0
- package/rules/graphic/review.yaml +271 -0
- package/rules/graphic/symbol.yaml +141 -0
- package/rules/motion/HYPOTHESES.md +19 -0
- package/rules/motion/_area.yaml +7 -0
- package/rules/motion/micro.yaml +143 -0
- package/rules/motion/review.yaml +347 -0
- package/rules/motion/transitions.yaml +169 -0
- package/rules/typography/HYPOTHESES.md +12 -0
- package/rules/typography/_area.yaml +8 -0
- package/rules/typography/adapt.yaml +45 -0
- package/rules/typography/create.yaml +126 -0
- package/rules/typography/review.yaml +127 -0
- package/rules/ui/HYPOTHESES.md +23 -0
- package/rules/ui/_area.yaml +9 -0
- package/rules/ui/compose.yaml +246 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +400 -0
- package/rules/ui/states.yaml +257 -0
- package/rules/ux/HYPOTHESES.md +13 -0
- package/rules/ux/_area.yaml +8 -0
- package/rules/ux/flows.yaml +164 -0
- package/rules/ux/forms.yaml +142 -0
- package/rules/ux/review.yaml +186 -0
- package/skills/lazuli/SKILL.md +183 -0
- package/skills/lazuli/procedures/create.md +29 -0
- package/skills/lazuli/procedures/explain-decisions.md +22 -0
- package/skills/lazuli/procedures/improve.md +30 -0
- package/skills/lazuli/procedures/remember-this.md +41 -0
- package/skills/lazuli/procedures/review-design.md +36 -0
- package/skills/lazuli/procedures/show-options.md +33 -0
- package/skills/lazuli-accessibility-check/SKILL.md +68 -0
- package/skills/lazuli-color-context-and-culture/SKILL.md +53 -0
- package/skills/lazuli-color-context-and-culture/references/sectors.md +26 -0
- package/skills/lazuli-color-palette-by-intent/SKILL.md +54 -0
- package/skills/lazuli-color-palette-by-intent/references/intent-chords.md +51 -0
- package/skills/lazuli-color-screen-review/SKILL.md +51 -0
- package/skills/lazuli-color-states-and-signals/SKILL.md +53 -0
- package/skills/lazuli-content-interface-writing/SKILL.md +53 -0
- package/skills/lazuli-content-voice/SKILL.md +40 -0
- package/skills/lazuli-data-charts-and-dashboards/SKILL.md +59 -0
- package/skills/lazuli-graphic-derived-pieces/SKILL.md +40 -0
- package/skills/lazuli-graphic-derived-pieces/references/piece-template.html +24 -0
- package/skills/lazuli-graphic-identity/SKILL.md +45 -0
- package/skills/lazuli-motion-micro-and-transitions/SKILL.md +49 -0
- package/skills/lazuli-typography-choose-and-pair/SKILL.md +50 -0
- package/skills/lazuli-typography-screen-review/SKILL.md +51 -0
- package/skills/lazuli-ui-composition/SKILL.md +42 -0
- package/skills/lazuli-ui-composition/references/option-template.html +34 -0
- package/skills/lazuli-ui-layout-review/SKILL.md +47 -0
- package/skills/lazuli-ui-states-and-system/SKILL.md +54 -0
- package/skills/lazuli-ux-flows-and-forms/SKILL.md +51 -0
- package/skills/lazuli-ux-task-test/SKILL.md +44 -0
- package/src/browser.mjs +162 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +463 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +160 -0
- package/src/commands/draft-memo.mjs +162 -0
- package/src/commands/hooks.mjs +345 -0
- package/src/commands/install-hooks.mjs +120 -0
- package/src/commands/install.mjs +132 -0
- package/src/commands/list-rules.mjs +49 -0
- package/src/commands/map-page.mjs +594 -0
- package/src/commands/record-answers.mjs +79 -0
- package/src/commands/record-log.mjs +325 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +227 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +391 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +566 -0
- package/src/measure/chart-read.mjs +401 -0
- package/src/measure/chart.mjs +264 -0
- package/src/measure/coherence.mjs +145 -0
- package/src/measure/color.mjs +86 -0
- package/src/measure/content.mjs +82 -0
- package/src/measure/cvd.mjs +24 -0
- package/src/measure/extreme.mjs +241 -0
- package/src/measure/forms.mjs +150 -0
- package/src/measure/in-page/a11y.js +522 -0
- package/src/measure/in-page/color.js +348 -0
- package/src/measure/in-page/composition.js +1496 -0
- package/src/measure/in-page/contrast.js +15 -0
- package/src/measure/in-page/cvd.js +173 -0
- package/src/measure/in-page/extreme.js +377 -0
- package/src/measure/in-page/frames.js +781 -0
- package/src/measure/in-page/look.js +28 -0
- package/src/measure/in-page/motion-probe.js +171 -0
- package/src/measure/in-page/style.js +107 -0
- package/src/measure/in-page/svg-strokes.js +112 -0
- package/src/measure/in-page/svg-uses.js +50 -0
- package/src/measure/in-page/symbol.js +123 -0
- package/src/measure/in-page/type.js +269 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +100 -0
- package/src/measure/motion.mjs +509 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +253 -0
- package/src/measure/rhythm.mjs +81 -0
- package/src/measure/signature.mjs +65 -0
- package/src/measure/states.mjs +240 -0
- package/src/measure/style.mjs +13 -0
- package/src/measure/symbol.mjs +268 -0
- package/src/measure/terms.mjs +153 -0
- package/src/measure/tiles.mjs +20 -0
- package/src/measure/timeline.mjs +621 -0
- package/src/measure/type.mjs +167 -0
- package/src/measure/weight.mjs +18 -0
- package/src/private-strings.mjs +81 -0
- package/src/project/blind.mjs +70 -0
- package/src/project/edits.mjs +154 -0
- package/src/project/gate.mjs +168 -0
- package/src/project/lazuli-md.mjs +521 -0
- package/src/project/log.mjs +335 -0
- package/src/project/match.mjs +200 -0
- package/src/project/records.mjs +380 -0
- package/src/project/tasks.mjs +153 -0
- package/src/report/evaluate.mjs +27 -0
- package/src/report/evaluators/a11y.mjs +227 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +133 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +87 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +103 -0
- package/src/report/evaluators/motion.mjs +280 -0
- package/src/report/evaluators/piece.mjs +69 -0
- package/src/report/evaluators/rhythm.mjs +99 -0
- package/src/report/evaluators/states.mjs +39 -0
- package/src/report/evaluators/style.mjs +35 -0
- package/src/report/evaluators/symbol.mjs +110 -0
- package/src/report/evaluators/terms.mjs +49 -0
- package/src/report/evaluators/type.mjs +166 -0
- package/src/report/evaluators/weight.mjs +51 -0
- package/src/report/evidence.mjs +4 -0
- package/src/report/finding.mjs +11 -0
- package/src/report/format.mjs +215 -0
- package/src/rules/hypotheses.mjs +28 -0
- package/src/rules/load.mjs +274 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +220 -0
- package/templates/LAZULI.md +88 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
const MODES = ["director", "delegate"];
|
|
5
|
+
const STATUSES = ["trying", "kept", "reverted"];
|
|
6
|
+
const BEATS = ["breathe", "steady", "accelerate", "climax"];
|
|
7
|
+
export const SECTION_NAMES = [
|
|
8
|
+
"platform and constraints",
|
|
9
|
+
"learned rules",
|
|
10
|
+
"product",
|
|
11
|
+
"audience",
|
|
12
|
+
"brand",
|
|
13
|
+
"language",
|
|
14
|
+
"mode",
|
|
15
|
+
"idea",
|
|
16
|
+
"goals",
|
|
17
|
+
"breaks",
|
|
18
|
+
"decisions",
|
|
19
|
+
];
|
|
20
|
+
const IDEA_PLACEHOLDER = "One sentence that links something only this client has to a visual device. Every screen carries it.";
|
|
21
|
+
// The template sentence, and the one older templates carried, both mean "not written yet".
|
|
22
|
+
const AUDIENCE_PLACEHOLDERS = [
|
|
23
|
+
"Who uses it, their age range, country, device and context of use. The simulated task walks the main task as this person.",
|
|
24
|
+
"Who uses it, their age range, country and context of use.",
|
|
25
|
+
].map((s) => s.toLowerCase());
|
|
26
|
+
export const HEADING = /^(#{1,6})[ \t]+(.*?)[ \t]*$/;
|
|
27
|
+
export const BULLET = /^([ \t]*)(?:[-*+]|\d+[.)])[ \t]+(.*)$/;
|
|
28
|
+
// A field name, optionally wrapped in bold or italic markers: Piece:, **Piece:**, __Piece__:, *Piece*:
|
|
29
|
+
const EMPHASIS = String.raw`(?:\*\*|__|\*|_)?`;
|
|
30
|
+
export const FIELD = new RegExp(String.raw`^(${EMPHASIS})([A-Za-z]+)${EMPHASIS}[ \t]*:${EMPHASIS}[ \t]*(.*?)[ \t]*$`);
|
|
31
|
+
const RULE_ACTION = /^([A-Za-z]{2}\d{1,3})[ \t]+(followed|broken|accepted)$/i;
|
|
32
|
+
const RULE_NONE = /^none$/i;
|
|
33
|
+
|
|
34
|
+
function isPlaceholder(value) {
|
|
35
|
+
return /^\(.*\)$/.test(value.trim());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isLive(head) {
|
|
39
|
+
return head.trim() !== "" && !isPlaceholder(head);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Blanks every comment (keeping its line breaks so line numbers stay true). A comment that never
|
|
43
|
+
// closes only loses the rest of its own line; the text after it is read and the file is told.
|
|
44
|
+
export function stripComments(clean, problems) {
|
|
45
|
+
let out = "";
|
|
46
|
+
let at = 0;
|
|
47
|
+
for (;;) {
|
|
48
|
+
const open = clean.indexOf("<!--", at);
|
|
49
|
+
if (open === -1) {
|
|
50
|
+
return out + clean.slice(at);
|
|
51
|
+
}
|
|
52
|
+
out += clean.slice(at, open);
|
|
53
|
+
const close = clean.indexOf("-->", open + 4);
|
|
54
|
+
if (close !== -1) {
|
|
55
|
+
out += clean.slice(open, close + 3).replace(/[^\n]/g, "");
|
|
56
|
+
at = close + 3;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const line = clean.slice(0, open).split("\n").length;
|
|
60
|
+
problems.push(`LAZULI.md: a comment opened with <!-- on line ${line} never closes; the text after it was read`);
|
|
61
|
+
const end = clean.indexOf("\n", open);
|
|
62
|
+
if (end === -1) {
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
at = end;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// A heading maps to a known section when its text starts with the name and the next character is not a letter.
|
|
70
|
+
export function knownSection(heading) {
|
|
71
|
+
const lower = heading.toLowerCase();
|
|
72
|
+
return SECTION_NAMES.find((name) => lower.startsWith(name) && !/^[a-z]/.test(lower.slice(name.length))) ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function titleCase(key) {
|
|
76
|
+
return key.charAt(0).toUpperCase() + key.slice(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Splits the file into sections keyed by section name; text before the first heading is dropped.
|
|
80
|
+
function sections(text, problems) {
|
|
81
|
+
const clean = stripComments(text.replace(/^/, "").replace(/\r\n?/g, "\n"), problems);
|
|
82
|
+
const out = new Map();
|
|
83
|
+
let current = null;
|
|
84
|
+
const lines = clean.split("\n");
|
|
85
|
+
const open = (name) => {
|
|
86
|
+
current = name;
|
|
87
|
+
if (!out.has(current)) {
|
|
88
|
+
out.set(current, []);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
for (let i = 0; i < lines.length; i++) {
|
|
92
|
+
const line = lines[i];
|
|
93
|
+
const heading = HEADING.exec(line);
|
|
94
|
+
// Level 2 may carry extra words; any other level opens a section only on the exact name,
|
|
95
|
+
// so a subheading like "### Mode of delivery" stays content of the section it sits in.
|
|
96
|
+
const exact = heading ? SECTION_NAMES.find((name) => name === heading[2].toLowerCase()) : undefined;
|
|
97
|
+
const plain = line.trim().toLowerCase();
|
|
98
|
+
const setext = !heading && SECTION_NAMES.includes(plain) && /^[ \t]*(?:=+|-+)[ \t]*$/.test(lines[i + 1] ?? "");
|
|
99
|
+
if (heading && heading[1] === "##") {
|
|
100
|
+
open(knownSection(heading[2]) ?? heading[2].toLowerCase());
|
|
101
|
+
} else if (exact) {
|
|
102
|
+
problems.push(`LAZULI.md: "${line.trim()}" is not a level-2 heading; its text was read as the ${exact} section`);
|
|
103
|
+
open(exact);
|
|
104
|
+
} else if (setext) {
|
|
105
|
+
problems.push(`LAZULI.md: "${line.trim()}" is underlined, not a level-2 heading; its text was read as the ${plain} section`);
|
|
106
|
+
open(plain);
|
|
107
|
+
i++;
|
|
108
|
+
} else if (current !== null) {
|
|
109
|
+
out.get(current).push(line);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Groups bullets: a bullet whose key is `openKey` at the base indent starts an entry; bullets with a
|
|
116
|
+
// key in `fields` fill the open entry, nested under it or (flat) beside it. Returns { entries, ignored }:
|
|
117
|
+
// each entry is { head, fields, flat }; `ignored` lists bullets nothing read as { kind, text, entry }.
|
|
118
|
+
function entries(lines, openKey, fields) {
|
|
119
|
+
const bullets = [];
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
const bullet = BULLET.exec(line);
|
|
122
|
+
if (!bullet) {
|
|
123
|
+
// A Key: value line that is not a bullet cannot open or fill an entry; name it.
|
|
124
|
+
if (FIELD.test(line.trim())) {
|
|
125
|
+
bullets.push({ loose: true, text: line.trim() });
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const field = FIELD.exec(bullet[2]);
|
|
130
|
+
const indent = bullet[1].replace(/\t/g, " ").length;
|
|
131
|
+
let value = field ? field[3] : bullet[2];
|
|
132
|
+
// A field wrapped whole in emphasis, - **Piece: Home**, carries the closing marker in its value.
|
|
133
|
+
if (field && field[1] && value.endsWith(field[1]) && !value.startsWith(field[1])) {
|
|
134
|
+
value = value.slice(0, -field[1].length).trim();
|
|
135
|
+
}
|
|
136
|
+
bullets.push({
|
|
137
|
+
indent,
|
|
138
|
+
key: field ? field[2].toLowerCase() : null,
|
|
139
|
+
value,
|
|
140
|
+
text: bullet[2].trim(),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const result = [];
|
|
144
|
+
const ignored = [];
|
|
145
|
+
if (bullets.length === 0) {
|
|
146
|
+
return { entries: result, ignored };
|
|
147
|
+
}
|
|
148
|
+
const indents = bullets.filter((b) => !b.loose).map((b) => b.indent);
|
|
149
|
+
const base = indents.length > 0 ? Math.min(...indents) : 0;
|
|
150
|
+
let current = null;
|
|
151
|
+
for (const bullet of bullets) {
|
|
152
|
+
if (bullet.loose) {
|
|
153
|
+
ignored.push({ kind: "line", text: bullet.text, entry: null });
|
|
154
|
+
} else if (bullet.key === openKey && bullet.indent <= base) {
|
|
155
|
+
current = { head: bullet.value, fields: {}, flat: false, dups: [] };
|
|
156
|
+
result.push(current);
|
|
157
|
+
} else if (bullet.key && fields.includes(bullet.key) && current) {
|
|
158
|
+
if (bullet.indent <= base) {
|
|
159
|
+
current.flat = true;
|
|
160
|
+
}
|
|
161
|
+
if (bullet.key in current.fields) {
|
|
162
|
+
current.dups.push(bullet.key);
|
|
163
|
+
} else {
|
|
164
|
+
current.fields[bullet.key] = bullet.value;
|
|
165
|
+
}
|
|
166
|
+
} else if (bullet.indent > base && current) {
|
|
167
|
+
ignored.push({ kind: "field", text: bullet.text, entry: current });
|
|
168
|
+
} else {
|
|
169
|
+
current = null;
|
|
170
|
+
ignored.push({ kind: "line", text: bullet.text, entry: null });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { entries: result, ignored };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Names what a section's bullets left unread. Placeholder entries (empty head or text in
|
|
177
|
+
// parentheses) are skipped silently, with whatever sits under them.
|
|
178
|
+
function ignoredProblems(found, ignored, section, label) {
|
|
179
|
+
const live = new Set(found.filter((e) => isLive(e.head)));
|
|
180
|
+
return ignored
|
|
181
|
+
.filter((i) => i.entry === null || live.has(i.entry))
|
|
182
|
+
.map((i) => (i.kind === "field" ? `${label(i.entry)}: field not read: "${i.text}"` : `${section}: line not read: "${i.text}"`));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// A placeholder entry stays silent only while its fields are empty or in parentheses.
|
|
186
|
+
function orphanProblems(entry, noun, openName) {
|
|
187
|
+
return Object.entries(entry.fields)
|
|
188
|
+
.filter(([, value]) => value.trim() !== "" && !isPlaceholder(value))
|
|
189
|
+
.map(([key, value]) => `${noun} with no ${openName}: ${titleCase(key)} "${value.trim()}" was not read`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function dupProblems(entry, label) {
|
|
193
|
+
return entry.dups.map((key) => `${label}: ${titleCase(key)} appears twice; the first was used`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function parseMode(lines, problems) {
|
|
197
|
+
const first = lines.map((l) => l.trim()).find((l) => l !== "");
|
|
198
|
+
if (first === undefined) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const words = first.toLowerCase().match(/[a-z]+/g) ?? [];
|
|
202
|
+
if (words.includes("director") && words.includes("delegate")) {
|
|
203
|
+
problems.push("Mode names both director and delegate; keep one");
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const value = first
|
|
207
|
+
.replace(/^[-*][ \t]+/, "")
|
|
208
|
+
.replace(/[*_`]/g, "")
|
|
209
|
+
.replace(/^mode[ \t]*:/i, "")
|
|
210
|
+
.trim()
|
|
211
|
+
.replace(/[.!]+$/, "")
|
|
212
|
+
.trim()
|
|
213
|
+
.toLowerCase();
|
|
214
|
+
if (MODES.includes(value)) {
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
problems.push("Mode must be director or delegate");
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Paragraphs of a section: runs of non-blank lines, each joined by a space.
|
|
222
|
+
function paragraphsOf(lines) {
|
|
223
|
+
const paragraphs = [];
|
|
224
|
+
let open = [];
|
|
225
|
+
for (const line of [...lines, ""]) {
|
|
226
|
+
if (line.trim() === "") {
|
|
227
|
+
if (open.length > 0) {
|
|
228
|
+
paragraphs.push(open.join(" "));
|
|
229
|
+
open = [];
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
open.push(line.trim());
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return paragraphs;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function parseIdea(lines) {
|
|
239
|
+
const idea = paragraphsOf(lines).find((p) => p.toLowerCase() !== IDEA_PLACEHOLDER.toLowerCase() && !isPlaceholder(p));
|
|
240
|
+
return idea ?? null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// The audience: every paragraph that is not the template sentence or a placeholder, joined by a space.
|
|
244
|
+
function parseAudience(lines) {
|
|
245
|
+
const own = paragraphsOf(lines).filter((p) => !AUDIENCE_PLACEHOLDERS.includes(p.toLowerCase()) && !isPlaceholder(p));
|
|
246
|
+
return own.length > 0 ? own.join(" ") : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The rhythm map: one beat per section, top to bottom, exactly one climax. A placeholder or an empty
|
|
250
|
+
// value is null and silent; a map with an unknown beat or without exactly one climax is null and named.
|
|
251
|
+
function parseRhythm(piece, value, problems) {
|
|
252
|
+
if (value === undefined || value.trim() === "" || isPlaceholder(value)) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
// An empty beat is kept so a map wrapped onto a second line is refused instead of read short.
|
|
256
|
+
const beats = value.split(",").map((b) => b.trim());
|
|
257
|
+
const unknown = beats.find((b) => !BEATS.includes(b.toLowerCase()));
|
|
258
|
+
if (unknown !== undefined) {
|
|
259
|
+
problems.push(`Goal "${piece}": Rhythm beat "${unknown}" is not one of breathe, steady, accelerate, climax; the map was not read`);
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const lower = beats.map((b) => b.toLowerCase());
|
|
263
|
+
if (lower.filter((b) => b === "climax").length !== 1) {
|
|
264
|
+
problems.push(`Goal "${piece}": Rhythm needs exactly one climax; the map was not read`);
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return lower;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// A canvas side in pixels: 16 is the smallest favicon size, 4000 a bound no piece reaches.
|
|
271
|
+
const MIN_SIDE = 16;
|
|
272
|
+
const MAX_SIDE = 4000;
|
|
273
|
+
|
|
274
|
+
// A comma list of canvases, <w>x<h> or <n> for a square. Null for anything else, an empty item included,
|
|
275
|
+
// so a list wrapped onto a second line is refused instead of read short. Duplicates are dropped, order kept.
|
|
276
|
+
export function parseSizes(text) {
|
|
277
|
+
if (typeof text !== "string") {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
const sizes = [];
|
|
281
|
+
for (const item of text.split(",").map((s) => s.trim())) {
|
|
282
|
+
const m = /^(\d+)(?:x(\d+))?$/i.exec(item);
|
|
283
|
+
if (!m) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const width = Number(m[1]);
|
|
287
|
+
const height = m[2] === undefined ? width : Number(m[2]);
|
|
288
|
+
if (![width, height].every((n) => n >= MIN_SIDE && n <= MAX_SIDE)) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
if (!sizes.some((s) => s.width === width && s.height === height)) {
|
|
292
|
+
sizes.push({ width, height });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return sizes;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function parseSize(piece, value, problems) {
|
|
299
|
+
if (value === undefined || value.trim() === "" || isPlaceholder(value)) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
const sizes = parseSizes(value);
|
|
303
|
+
if (sizes === null) {
|
|
304
|
+
problems.push(`Goal "${piece}": Size "${value.trim()}" is not a list such as 1200x630 or 16, 32, 180; it was not read`);
|
|
305
|
+
}
|
|
306
|
+
return sizes;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// A goal that names a derived piece (it has a Size) or a symbol or image file. It is not a screen:
|
|
310
|
+
// --site and the post-edit hook leave it out.
|
|
311
|
+
export function isAssetGoal(goal) {
|
|
312
|
+
if (goal?.size) {
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
const target = String(goal?.target ?? "").replace(/[?#].*$/, "");
|
|
316
|
+
return /\.(?:svg|png|ico|jpe?g|webp)$/i.test(target);
|
|
317
|
+
}
|
|
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
|
+
|
|
332
|
+
export function emptyBrand() {
|
|
333
|
+
return { colors: [], fonts: [], symbols: [] };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Brand tokens: bullets labelled exactly Color, Font or Symbol, anywhere in ## Brand. Prose, other
|
|
337
|
+
// bullets and placeholders are ignored; a token line that cannot be read is named.
|
|
338
|
+
function parseBrand(lines, problems) {
|
|
339
|
+
const brand = emptyBrand();
|
|
340
|
+
for (const line of lines) {
|
|
341
|
+
const bullet = BULLET.exec(line);
|
|
342
|
+
const field = bullet ? FIELD.exec(bullet[2]) : null;
|
|
343
|
+
if (!field) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const label = field[2].toLowerCase();
|
|
347
|
+
if (!["color", "font", "symbol"].includes(label)) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
let value = field[3];
|
|
351
|
+
// A token wrapped whole in emphasis, - **Color: ink #1a1a1a**, carries the closing marker in its value.
|
|
352
|
+
if (field[1] && value.endsWith(field[1]) && !value.startsWith(field[1])) {
|
|
353
|
+
value = value.slice(0, -field[1].length).trim();
|
|
354
|
+
}
|
|
355
|
+
if (value === "" || isPlaceholder(value)) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const text = bullet[2].trim();
|
|
359
|
+
if (label === "color") {
|
|
360
|
+
const m = /^(?:(.*?)[ \t]+)?#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value);
|
|
361
|
+
if (!m) {
|
|
362
|
+
problems.push(`Brand: "${text}" needs a hex color such as #23399A; it was not read`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const digits = m[2].length === 3 ? [...m[2]].map((c) => c + c).join("") : m[2];
|
|
366
|
+
brand.colors.push({ name: (m[1] ?? "").trim(), hex: `#${digits.toLowerCase()}` });
|
|
367
|
+
} else if (label === "font") {
|
|
368
|
+
brand.fonts.push(value);
|
|
369
|
+
} else {
|
|
370
|
+
const range = /^(.*?)[ \t]+\(([^()]*)\)$/.exec(value);
|
|
371
|
+
let file = value;
|
|
372
|
+
let upTo = null;
|
|
373
|
+
if (range) {
|
|
374
|
+
const m = /^up to (\d+) px$/i.exec(range[2].trim());
|
|
375
|
+
if (!m || Number(m[1]) < 1) {
|
|
376
|
+
problems.push(`Brand: "${text}" has a size range that is not "(up to <n> px)"; it was not read`);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
file = range[1].trim();
|
|
380
|
+
upTo = Number(m[1]);
|
|
381
|
+
}
|
|
382
|
+
if (upTo === null && brand.symbols.some((s) => s.upTo === null)) {
|
|
383
|
+
problems.push(`Brand: only one Symbol line can be the main symbol (the others say up to <n> px); "${file}" was not read`);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
brand.symbols.push({ file, upTo });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return brand;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function parseGoals(lines, problems) {
|
|
393
|
+
const { entries: found, ignored } = entries(lines, "piece", ["target", "understand", "feel", "do", "rhythm", "size"]);
|
|
394
|
+
const goals = [];
|
|
395
|
+
for (const entry of found) {
|
|
396
|
+
const piece = entry.head.trim();
|
|
397
|
+
if (!isLive(piece)) {
|
|
398
|
+
problems.push(...orphanProblems(entry, "Goal", "Piece"));
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
problems.push(...dupProblems(entry, `Goal "${piece}"`));
|
|
402
|
+
if (entry.flat) {
|
|
403
|
+
problems.push(`Goal "${piece}": fields should be indented under Piece; read anyway`);
|
|
404
|
+
}
|
|
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
|
+
}
|
|
409
|
+
goals.push({
|
|
410
|
+
piece,
|
|
411
|
+
target: f.target ? f.target : null,
|
|
412
|
+
understand: f.understand ?? "",
|
|
413
|
+
feel: f.feel ?? "",
|
|
414
|
+
do: f.do ?? "",
|
|
415
|
+
rhythm: parseRhythm(piece, f.rhythm, problems),
|
|
416
|
+
size: parseSize(piece, f.size, problems),
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
problems.push(...ignoredProblems(found, ignored, "Goals", (e) => `Goal "${e.head.trim()}"`));
|
|
420
|
+
return goals;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function parseBreaks(lines, problems) {
|
|
424
|
+
const { entries: found, ignored } = entries(lines, "rule", ["piece", "target", "effect", "check", "status"]);
|
|
425
|
+
const breaks = [];
|
|
426
|
+
for (const entry of found) {
|
|
427
|
+
const rule = entry.head.trim();
|
|
428
|
+
if (!isLive(rule)) {
|
|
429
|
+
problems.push(...orphanProblems(entry, "Break", "Rule"));
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
problems.push(...dupProblems(entry, `Break ${rule}`));
|
|
433
|
+
if (entry.flat) {
|
|
434
|
+
problems.push(`Break ${rule}: fields should be indented under Rule; read anyway`);
|
|
435
|
+
}
|
|
436
|
+
const f = entry.fields;
|
|
437
|
+
let status = null;
|
|
438
|
+
if (f.status && !isPlaceholder(f.status)) {
|
|
439
|
+
const value = f.status.toLowerCase();
|
|
440
|
+
if (STATUSES.includes(value)) {
|
|
441
|
+
status = value;
|
|
442
|
+
} else {
|
|
443
|
+
problems.push(`Break ${rule}: status must be trying, kept or reverted`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
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 });
|
|
451
|
+
}
|
|
452
|
+
problems.push(...ignoredProblems(found, ignored, "Breaks", (e) => `Break ${e.head.trim()}`));
|
|
453
|
+
return breaks;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function parseDecisions(lines, problems) {
|
|
457
|
+
const { entries: found, ignored } = entries(lines, "decision", ["piece", "target", "goal", "rule", "measure"]);
|
|
458
|
+
const decisions = [];
|
|
459
|
+
for (const entry of found) {
|
|
460
|
+
const decision = entry.head.trim();
|
|
461
|
+
if (!isLive(decision)) {
|
|
462
|
+
problems.push(...orphanProblems(entry, "Decision", "Decision"));
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
problems.push(...dupProblems(entry, `Decision "${decision}"`));
|
|
466
|
+
if (entry.flat) {
|
|
467
|
+
problems.push(`Decision "${decision}": fields should be indented under Decision; read anyway`);
|
|
468
|
+
}
|
|
469
|
+
const f = entry.fields;
|
|
470
|
+
const written = (f.rule ?? "").trim();
|
|
471
|
+
const match = RULE_ACTION.exec(written);
|
|
472
|
+
const none = RULE_NONE.test(written);
|
|
473
|
+
if (!match && !none) {
|
|
474
|
+
problems.push(`Decision "${decision}": Rule must be a rule id followed by "followed", "broken" or "accepted", or "none"`);
|
|
475
|
+
}
|
|
476
|
+
const piece = f.piece ?? "";
|
|
477
|
+
if (piece.trim() === "") {
|
|
478
|
+
problems.push(`Decision "${decision}": Piece is missing`);
|
|
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
|
+
}
|
|
483
|
+
decisions.push({
|
|
484
|
+
decision,
|
|
485
|
+
piece,
|
|
486
|
+
goal: f.goal ?? "",
|
|
487
|
+
rule: match ? match[1].toUpperCase() : none ? "none" : written,
|
|
488
|
+
action: match ? match[2].toLowerCase() : none ? "none" : null,
|
|
489
|
+
measure: f.measure ?? "",
|
|
490
|
+
target: entryTarget(f.target),
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
problems.push(...ignoredProblems(found, ignored, "Decisions", (e) => `Decision "${e.head.trim()}"`));
|
|
494
|
+
return decisions;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export function parseLazuliMd(text) {
|
|
498
|
+
const problems = [];
|
|
499
|
+
const found = sections(typeof text === "string" ? text : "", problems);
|
|
500
|
+
const mode = parseMode(found.get("mode") ?? [], problems);
|
|
501
|
+
const idea = parseIdea(found.get("idea") ?? []);
|
|
502
|
+
const audience = parseAudience(found.get("audience") ?? []);
|
|
503
|
+
const brand = parseBrand(found.get("brand") ?? [], problems);
|
|
504
|
+
const goals = parseGoals(found.get("goals") ?? [], problems);
|
|
505
|
+
const breaks = parseBreaks(found.get("breaks") ?? [], problems);
|
|
506
|
+
const decisions = parseDecisions(found.get("decisions") ?? [], problems);
|
|
507
|
+
return { mode, idea, audience, brand, goals, breaks, decisions, problems };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export async function readLazuliMd(cwd = process.cwd()) {
|
|
511
|
+
for (const name of ["LAZULI.md", "lazuli.md"]) {
|
|
512
|
+
try {
|
|
513
|
+
return parseLazuliMd(await readFile(join(cwd, name), "utf8"));
|
|
514
|
+
} catch (error) {
|
|
515
|
+
if (error?.code !== "ENOENT" && error?.code !== "EISDIR") {
|
|
516
|
+
throw error;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
}
|