@jonandev/longbeard 0.11.2 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -5
- package/CHANGELOG.md +72 -0
- package/README.md +64 -43
- package/beard.json +124 -28
- package/bin/long-beard.js +171 -36
- package/package.json +1 -1
- package/skills/design/SKILL.md +51 -126
- package/skills/design-brief/SKILL.md +146 -0
- package/skills/design-brief/references/graphic.md +59 -0
- package/skills/design-check/SKILL.md +27 -11
- package/skills/design-check/references/design-rules.md +21 -7
- package/skills/design-check/scripts/capture.mjs +121 -37
- package/skills/design-check/scripts/contrast.mjs +23 -9
- package/skills/design-check/scripts/rules.mjs +613 -0
- package/skills/design-check/scripts/screen-contrast.mjs +428 -0
- package/skills/design-check/scripts/tokens.mjs +346 -0
- package/skills/design-content/SKILL.md +118 -0
- package/skills/design-content/scripts/contact-sheet.mjs +259 -0
- package/skills/design-content/scripts/pictures.mjs +197 -0
- package/skills/design-direction/SKILL.md +115 -200
- package/skills/design-direction/references/controls.md +58 -0
- package/skills/{design → design-direction}/references/design-rules.md +21 -7
- package/skills/design-direction/references/five-second.md +47 -0
- package/skills/design-direction/references/full-build.md +19 -0
- package/skills/design-direction/references/graphic.md +35 -0
- package/skills/design-direction/references/grid.md +114 -0
- package/skills/design-direction/references/library.md +75 -0
- package/skills/design-direction/references/screen-template.html +233 -0
- package/skills/design-direction/references/subject.md +33 -0
- package/skills/design-direction/scripts/capture.mjs +121 -37
- package/skills/design-direction/scripts/contact-sheet.mjs +18 -7
- package/skills/design-direction/scripts/fonts.mjs +276 -0
- package/skills/design-direction/scripts/layout-diff.mjs +118 -0
- package/skills/design-direction/scripts/measure.mjs +1728 -0
- package/skills/design-direction/scripts/moodboard.mjs +123 -32
- package/skills/design-direction/scripts/picture-cast.mjs +270 -0
- package/skills/design-direction/scripts/pictures.mjs +197 -0
- package/skills/design-direction/scripts/screen-contrast.mjs +428 -0
- package/skills/design-direction/scripts/sheet.mjs +67 -0
- package/skills/design-direction/scripts/subject-colours.mjs +410 -0
- package/skills/design-families/SKILL.md +138 -0
- package/skills/design-families/scripts/contact-sheet.mjs +259 -0
- package/skills/design-families/scripts/families.mjs +606 -0
- package/skills/design-families/scripts/measure.mjs +1728 -0
- package/skills/design-families/scripts/moodboard.mjs +467 -0
- package/skills/design-families/scripts/tag.mjs +289 -0
- package/skills/design-figma/SKILL.md +69 -0
- package/skills/design-figma/references/graphic.md +26 -0
- package/skills/design-identity/SKILL.md +134 -0
- package/skills/design-identity/references/graphic.md +8 -0
- package/skills/design-identity/references/identity-board.html +140 -0
- package/skills/{design → design-identity}/scripts/capture.mjs +121 -37
- package/skills/design-identity/scripts/colours.mjs +213 -0
- package/skills/design-identity/scripts/contrast.mjs +41 -0
- package/skills/design-identity/scripts/fonts.mjs +276 -0
- package/skills/design-identity/scripts/measure.mjs +1728 -0
- package/skills/design-identity/scripts/sheet.mjs +67 -0
- package/skills/design-identity/scripts/subject-colours.mjs +410 -0
- package/skills/design-moodboard/SKILL.md +184 -0
- package/skills/design-moodboard/references/graphic.md +25 -0
- package/skills/{design-direction → design-moodboard}/references/sources.md +21 -11
- package/skills/design-moodboard/scripts/capture.mjs +893 -0
- package/skills/design-moodboard/scripts/contact-sheet.mjs +259 -0
- package/skills/design-moodboard/scripts/crops.mjs +256 -0
- package/skills/design-moodboard/scripts/dribbble-cards.mjs +418 -0
- package/skills/design-moodboard/scripts/families.mjs +606 -0
- package/skills/design-moodboard/scripts/group.mjs +221 -0
- package/skills/design-moodboard/scripts/measure.mjs +1728 -0
- package/skills/design-moodboard/scripts/moodboard.mjs +467 -0
- package/skills/{design-direction → design-moodboard}/scripts/picker.mjs +121 -20
- package/skills/design-moodboard/scripts/pictures.mjs +197 -0
- package/skills/design-moodboard/scripts/tag.mjs +289 -0
- package/skills/design-prototype/SKILL.md +149 -0
- package/skills/design-prototype/references/design-md-template.md +82 -0
- package/skills/design-prototype/references/design-rules.md +203 -0
- package/skills/design-prototype/references/five-second.md +47 -0
- package/skills/design-prototype/references/graphic.md +27 -0
- package/skills/design-prototype/scripts/capture.mjs +893 -0
- package/skills/design-prototype/scripts/contrast.mjs +41 -0
- package/skills/design-prototype/scripts/links.mjs +308 -0
- package/skills/design-prototype/scripts/pictures.mjs +197 -0
- package/skills/design-prototype/scripts/rules.mjs +613 -0
- package/skills/design-prototype/scripts/screen-contrast.mjs +428 -0
- package/skills/design-prototype/scripts/sheet.mjs +67 -0
- package/skills/design-prototype/scripts/tokens.mjs +346 -0
- package/skills/design-wordmark/SKILL.md +65 -0
- package/skills/design-wordmark/scripts/capture.mjs +893 -0
- package/skills/design-wordmark/scripts/sheet.mjs +67 -0
- package/skills/framework-skills/SKILL.md +71 -0
- package/skills/idea/SKILL.md +13 -7
- package/skills/idea/references/graphic.md +64 -0
- package/skills/design/references/design-md-template.md +0 -58
- package/skills/design/scripts/contrast.mjs +0 -27
- package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Writes the token block at the top of DESIGN.md from the token tables below it, or checks that the two agree.
|
|
3
|
+
//
|
|
4
|
+
// node tokens.mjs [DESIGN.md] [--name <product name>] write or refresh the front matter
|
|
5
|
+
// node tokens.mjs [DESIGN.md] --check exit 1 when the front matter and the tables disagree
|
|
6
|
+
//
|
|
7
|
+
// Exit 0: written, or agrees. Exit 1: --check found a disagreement or no front matter. Exit 2: could not read the tables.
|
|
8
|
+
//
|
|
9
|
+
// The tables are the source a person reads and edits; the front matter is a generated copy, so a tool that reads the
|
|
10
|
+
// published DESIGN.md format (https://github.com/google-labs-code/design.md, spec in docs/spec.md, version "alpha")
|
|
11
|
+
// can take the design without Long Beard. Nothing else in the file is touched: text after the closing --- is kept byte
|
|
12
|
+
// for byte, and front-matter keys this script does not make (description, components, omitted) are kept as they are.
|
|
13
|
+
// Anyone who wants to can check the result with that format's own linter: npx @google/design.md lint DESIGN.md.
|
|
14
|
+
// It is not required and nothing here depends on it.
|
|
15
|
+
//
|
|
16
|
+
// The names, both ways. A token in a table is group/name; the block uses the published format's group names.
|
|
17
|
+
//
|
|
18
|
+
// table row block key
|
|
19
|
+
// color/ink colors.ink (colors.<theme>.ink when the table has a column per theme)
|
|
20
|
+
// type/heading typography.heading
|
|
21
|
+
// space/md spacing.md
|
|
22
|
+
// radius/md rounded.md
|
|
23
|
+
// motion/enter motion.enter
|
|
24
|
+
//
|
|
25
|
+
// Back: colors→color, typography→type, spacing→space, rounded→radius, motion→motion; the rest of the key is the
|
|
26
|
+
// token's name. A second slash in a name (color/accent/hover) becomes a hyphen in the block (colors.accent-hover).
|
|
27
|
+
//
|
|
28
|
+
// What each table holds. A table is found by its rows (a Token cell that starts with one of the groups above), not
|
|
29
|
+
// by its heading. Columns are found by their header, so extra columns and any order are fine.
|
|
30
|
+
// Colour: Token, one column of values or one per theme (the header names the theme: Light, Dark), Use.
|
|
31
|
+
// A blank or dash cell means the token does not exist in that theme.
|
|
32
|
+
// Type: Token, "Face, weight" (Fraunces, 600 or Fraunces, Semibold), "Size / line height" (48 / 1.1 or 18 / 28),
|
|
33
|
+
// optional Tracking, Use. A bare size is px. A bare line height under 4 is a multiplier, 4 and over is px.
|
|
34
|
+
// A bare tracking is em. Italic is not a field in the format, so it stays in the prose.
|
|
35
|
+
// Space and radius: Token, Value (a bare number is px), Use.
|
|
36
|
+
// An older DESIGN.md gave them as bullets, and those are read like table rows: space/<name> <number> pairs
|
|
37
|
+
// (- Scale: space/sm 8, space/md 16) and radius/<name> <number> pairs. A radius bullet that gives only a value
|
|
38
|
+
// and words (- Corner radius: 8px on cards) has no name to give the token: it is left out, with a line saying
|
|
39
|
+
// which line and that it needs a radius/<name> row in the table. A name is never guessed.
|
|
40
|
+
// Motion: Token, Duration (250ms; a bare number is ms), Easing, optional Delay, Use.
|
|
41
|
+
//
|
|
42
|
+
// primary. The format expects a colour named primary. Ours stay as they are, and the block gets one more key at the
|
|
43
|
+
// top level: primary, a reference to the colour this design leads with. That is color/primary if the table has one,
|
|
44
|
+
// else color/accent, else color/ink. With themes it points into the first theme's column, and each theme group also
|
|
45
|
+
// gets its own primary, pointing at that theme's colour, so a reader of the dark group gets the dark value. The format
|
|
46
|
+
// allows both: colors.primary and colors.dark.primary are different paths, and a primary may sit in a group.
|
|
47
|
+
//
|
|
48
|
+
// Name. Kept from the existing front matter; else --name; else the first heading of docs/brief.md; else the folder's name.
|
|
49
|
+
import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
50
|
+
import { basename, dirname, resolve } from "node:path";
|
|
51
|
+
import { fileURLToPath } from "node:url";
|
|
52
|
+
|
|
53
|
+
export const groupOf = { color: "colors", type: "typography", space: "spacing", radius: "rounded", motion: "motion" };
|
|
54
|
+
export const prefixOf = Object.fromEntries(Object.entries(groupOf).map(([a, b]) => [b, a]));
|
|
55
|
+
const generated = ["version", "name", "colors", "typography", "rounded", "spacing", "motion"];
|
|
56
|
+
const groupOrder = ["colors", "typography", "rounded", "spacing", "motion"];
|
|
57
|
+
|
|
58
|
+
// color/accent/hover -> { group: "colors", key: "accent-hover" }
|
|
59
|
+
export const blockKey = (token) => {
|
|
60
|
+
const m = /^(color|type|space|radius|motion)\/([\w/-]+)$/.exec(token);
|
|
61
|
+
return m ? { group: groupOf[m[1]], key: m[2].replace(/\//g, "-") } : null;
|
|
62
|
+
};
|
|
63
|
+
// colors.ink -> color/ink; colors.light.ink -> color/ink (in the light theme)
|
|
64
|
+
export const tokenName = (path) => {
|
|
65
|
+
const [group, ...rest] = path.split(".");
|
|
66
|
+
if (!prefixOf[group] || !rest.length) return null;
|
|
67
|
+
return `${prefixOf[group]}/${rest[rest.length - 1]}`;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const weights = { thin: 100, hairline: 100, extralight: 200, ultralight: 200, light: 300, regular: 400, normal: 400, book: 400, medium: 500, semibold: 600, demibold: 600, bold: 700, extrabold: 800, ultrabold: 800, black: 900, heavy: 900 };
|
|
71
|
+
|
|
72
|
+
class Fail extends Error {}
|
|
73
|
+
const warnings = [];
|
|
74
|
+
|
|
75
|
+
const unwrap = (cell) => cell.trim().replace(/^`+|`+$/g, "").replace(/^\*+|\*+$/g, "").trim();
|
|
76
|
+
const blank = (cell) => /^(|-|—|–|n\/a)$/i.test(unwrap(cell));
|
|
77
|
+
const slug = (text) => unwrap(text).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
78
|
+
|
|
79
|
+
export function tables(text) {
|
|
80
|
+
const out = [];
|
|
81
|
+
let fence = false;
|
|
82
|
+
let current = null;
|
|
83
|
+
for (const line of text.split("\n")) {
|
|
84
|
+
if (/^\s*(```|~~~)/.test(line)) fence = !fence;
|
|
85
|
+
if (fence || !/^\s*\|/.test(line)) { current = null; continue; }
|
|
86
|
+
const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
87
|
+
if (!current) { current = { header: cells, rows: [], sawRule: false }; out.push(current); continue; }
|
|
88
|
+
if (!current.sawRule && cells.every((c) => /^:?-{2,}:?$/.test(c))) { current.sawRule = true; continue; }
|
|
89
|
+
current.rows.push(cells);
|
|
90
|
+
}
|
|
91
|
+
return out.filter((t) => t.sawRule);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const colourValue = (v) => /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(v) || /^(?:rgba?|hsla?|hwb|oklch|oklab|lch|lab|color-mix)\(.+\)$/i.test(v) || v.toLowerCase() === "transparent";
|
|
95
|
+
|
|
96
|
+
function dimension(value, bare, what) {
|
|
97
|
+
const v = value.trim();
|
|
98
|
+
if (/^-?\d*\.?\d+$/.test(v)) return `${v}${bare}`;
|
|
99
|
+
if (/^-?\d*\.?\d+(px|em|rem)$/.test(v)) return v;
|
|
100
|
+
warnings.push(`${what}: "${v}" is not px, em or rem; written as it stands`);
|
|
101
|
+
return v;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function readTables(text) {
|
|
105
|
+
const tokens = []; // { token, group, key, value } where value is a scalar, an object, or { theme: scalar }
|
|
106
|
+
const seen = new Map();
|
|
107
|
+
const themes = [];
|
|
108
|
+
for (const t of tables(text)) {
|
|
109
|
+
const head = t.header.map(unwrap);
|
|
110
|
+
const col = (re) => head.findIndex((h, i) => i > 0 && re.test(h));
|
|
111
|
+
const tokenCol = 0;
|
|
112
|
+
const use = head.findIndex((h, i) => i > 0 && /^use$/i.test(h));
|
|
113
|
+
const face = col(/face|font/i);
|
|
114
|
+
const size = col(/size/i);
|
|
115
|
+
const track = col(/track|letter/i);
|
|
116
|
+
const dur = col(/duration|time/i);
|
|
117
|
+
const ease = col(/eas|curve|timing/i);
|
|
118
|
+
const delay = col(/delay/i);
|
|
119
|
+
const others = head.map((h, i) => i).filter((i) => i > 0 && i !== use && ![face, size, track, dur, ease, delay].includes(i));
|
|
120
|
+
// A colour table's value columns are the ones that hold a colour (a column of notes does not).
|
|
121
|
+
const colourRows = t.rows.filter((r) => blockKey(unwrap(r[0] || ""))?.group === "colors");
|
|
122
|
+
const valueCols = colourRows.length ? others.filter((i) => colourRows.some((r) => colourValue(unwrap(r[i] || "")))) : others;
|
|
123
|
+
for (const row of t.rows) {
|
|
124
|
+
const token = unwrap(row[tokenCol] || "");
|
|
125
|
+
const bk = blockKey(token);
|
|
126
|
+
if (!bk) continue;
|
|
127
|
+
const at = `${token}`;
|
|
128
|
+
if (seen.has(`${bk.group}.${bk.key}`)) throw new Fail(`${at} is in the tables twice (or collides with ${seen.get(`${bk.group}.${bk.key}`)} once its slashes are hyphens)`);
|
|
129
|
+
seen.set(`${bk.group}.${bk.key}`, token);
|
|
130
|
+
let value;
|
|
131
|
+
if (bk.group === "colors") {
|
|
132
|
+
const cols = valueCols.filter((i) => i < row.length);
|
|
133
|
+
const named = cols.length > 1;
|
|
134
|
+
const got = {};
|
|
135
|
+
for (const i of cols) {
|
|
136
|
+
if (blank(row[i] || "")) continue;
|
|
137
|
+
const v = unwrap(row[i]);
|
|
138
|
+
if (!colourValue(v)) throw new Fail(`${at}: "${v}" is not a colour (a hex, or a css colour function)`);
|
|
139
|
+
const theme = named ? slug(head[i]) : "";
|
|
140
|
+
if (named && !themes.includes(theme)) themes.push(theme);
|
|
141
|
+
got[theme] = v;
|
|
142
|
+
}
|
|
143
|
+
if (!Object.keys(got).length) throw new Fail(`${at} has no colour in any column`);
|
|
144
|
+
value = got;
|
|
145
|
+
} else if (bk.group === "typography") {
|
|
146
|
+
if (face < 0) throw new Fail(`${at}: the type table needs a "Face, weight" column`);
|
|
147
|
+
const cell = unwrap(row[face] || "");
|
|
148
|
+
const m = /^(.*?)[,\s]+((?:\d{3}|[A-Za-z-]+)(?:\s+italic)?)$/i.exec(cell);
|
|
149
|
+
let family = cell, weight;
|
|
150
|
+
if (m) {
|
|
151
|
+
const w = m[2].replace(/\s+italic$/i, "").toLowerCase().replace(/-/g, "");
|
|
152
|
+
if (/^\d{3}$/.test(w)) { family = m[1]; weight = Number(w); }
|
|
153
|
+
else if (weights[w]) { family = m[1]; weight = weights[w]; }
|
|
154
|
+
}
|
|
155
|
+
family = family.replace(/^["']|["']$/g, "").trim();
|
|
156
|
+
if (!family) throw new Fail(`${at}: no face`);
|
|
157
|
+
value = { fontFamily: family };
|
|
158
|
+
const [sz, lh] = size >= 0 ? unwrap(row[size] || "").split("/").map((s) => s.trim()) : [];
|
|
159
|
+
if (sz) value.fontSize = dimension(sz, "px", `${at} size`);
|
|
160
|
+
if (weight) value.fontWeight = weight;
|
|
161
|
+
if (lh) value.lineHeight = /^\d*\.?\d+$/.test(lh) ? (Number(lh) >= 4 ? `${lh}px` : Number(lh)) : dimension(lh, "px", `${at} line height`);
|
|
162
|
+
const tr = track >= 0 ? unwrap(row[track] || "") : "";
|
|
163
|
+
if (tr && !blank(tr)) value.letterSpacing = dimension(tr, "em", `${at} tracking`);
|
|
164
|
+
if (!value.fontSize) throw new Fail(`${at}: no size (the "Size / line height" column is empty)`);
|
|
165
|
+
} else if (bk.group === "motion") {
|
|
166
|
+
const d = dur >= 0 ? unwrap(row[dur] || "") : "";
|
|
167
|
+
if (!d) throw new Fail(`${at}: the motion table needs a Duration column`);
|
|
168
|
+
const ms = (s) => (/^\d*\.?\d+$/.test(s) ? `${s}ms` : /^(\d*\.?\d+)s$/.test(s) ? `${Math.round(parseFloat(s) * 1000)}ms` : s);
|
|
169
|
+
value = { duration: ms(d) };
|
|
170
|
+
if (delay >= 0 && !blank(row[delay] || "")) value.delay = ms(unwrap(row[delay]));
|
|
171
|
+
if (ease >= 0 && !blank(row[ease] || "")) value.timingFunction = unwrap(row[ease]);
|
|
172
|
+
} else {
|
|
173
|
+
const i = valueCols[0];
|
|
174
|
+
const v = i === undefined ? "" : unwrap(row[i] || "");
|
|
175
|
+
if (!v) throw new Fail(`${at} has no value`);
|
|
176
|
+
value = dimension(v, "px", at);
|
|
177
|
+
}
|
|
178
|
+
tokens.push({ token, ...bk, value });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
readBullets(text, tokens, seen);
|
|
182
|
+
return { tokens, themes };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// An older DESIGN.md's spacing and radius bullets, read like table rows. Fenced code is not read.
|
|
186
|
+
function readBullets(text, tokens, seen) {
|
|
187
|
+
let fence = false;
|
|
188
|
+
text.split("\n").forEach((line, i) => {
|
|
189
|
+
if (/^\s*(```|~~~)/.test(line)) fence = !fence;
|
|
190
|
+
if (fence || !/^\s*[-*]\s/.test(line)) return;
|
|
191
|
+
const pairs = [...line.matchAll(/(?<![\w/])((?:space|radius)\/[\w/-]+)\s*[:=]?\s*(-?\d*\.?\d+(?:px|rem|em)?)(?![\w.])/g)];
|
|
192
|
+
for (const [, token, v] of pairs) {
|
|
193
|
+
const bk = blockKey(token);
|
|
194
|
+
if (seen.has(`${bk.group}.${bk.key}`)) throw new Fail(`${token} is in the tables twice (or collides with ${seen.get(`${bk.group}.${bk.key}`)} once its slashes are hyphens)`);
|
|
195
|
+
seen.set(`${bk.group}.${bk.key}`, token);
|
|
196
|
+
tokens.push({ token, ...bk, value: dimension(v, "px", token) });
|
|
197
|
+
}
|
|
198
|
+
if (!pairs.some((p) => p[1].startsWith("radius/")) && /^\s*[-*]\s*\**(corner radius|corner radii|radius|radii|rounding|corners)\**\s*:/i.test(line)) {
|
|
199
|
+
warnings.push(`line ${i + 1}: "${line.trim().slice(0, 60)}" has no name for its radius, so it is left out. It needs a radius/<name> row in the table.`);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// The tokens as a flat list of [dotted path, scalar], in file order, and the same as YAML lines.
|
|
205
|
+
export function build(text) {
|
|
206
|
+
const { tokens, themes } = readTables(text);
|
|
207
|
+
if (!tokens.length) throw new Fail("no token table found: expected rows such as color/ink, type/body, space/md");
|
|
208
|
+
const flat = [];
|
|
209
|
+
const tree = {};
|
|
210
|
+
const put = (path, value) => {
|
|
211
|
+
flat.push([path.join("."), value]);
|
|
212
|
+
let o = tree;
|
|
213
|
+
for (const k of path.slice(0, -1)) o = o[k] ||= {};
|
|
214
|
+
o[path[path.length - 1]] = value;
|
|
215
|
+
};
|
|
216
|
+
const colours = tokens.filter((t) => t.group === "colors");
|
|
217
|
+
if (colours.length) {
|
|
218
|
+
const names = new Set(colours.map((t) => t.key));
|
|
219
|
+
const lead = ["primary", "accent", "ink"].find((n) => names.has(n));
|
|
220
|
+
const first = themes[0] || "";
|
|
221
|
+
if (!lead) warnings.push("no color/primary, color/accent or color/ink: the block has no primary");
|
|
222
|
+
else if (!(lead === "primary" && !themes.length)) {
|
|
223
|
+
if (colours.find((t) => t.key === lead).value[first] === undefined) throw new Fail(`color/${lead} has no value in the ${first} column, so primary cannot point at it`);
|
|
224
|
+
put(["colors", "primary"], `{colors.${first ? `${first}.` : ""}${lead}}`);
|
|
225
|
+
}
|
|
226
|
+
// With themes, each group leads with its own primary (unless the table has a color/primary row, which is there already).
|
|
227
|
+
const own = lead && lead !== "primary" ? colours.find((t) => t.key === lead) : null;
|
|
228
|
+
for (const theme of themes) {
|
|
229
|
+
if (own?.value[theme] !== undefined) put(["colors", theme, "primary"], `{colors.${theme}.${lead}}`);
|
|
230
|
+
for (const t of colours) if (t.value[theme] !== undefined) put(["colors", theme, t.key], t.value[theme]);
|
|
231
|
+
}
|
|
232
|
+
for (const t of colours) if (t.value[""] !== undefined) put(["colors", t.key], t.value[""]);
|
|
233
|
+
}
|
|
234
|
+
for (const g of groupOrder.slice(1)) {
|
|
235
|
+
for (const t of tokens.filter((x) => x.group === g)) {
|
|
236
|
+
if (typeof t.value === "object") for (const [k, v] of Object.entries(t.value)) put([g, t.key, k], v);
|
|
237
|
+
else put([g, t.key], t.value);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { tree, flat, count: tokens.length };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const plain = /^-?[A-Za-z0-9_./()%][^:#]*$/;
|
|
244
|
+
export const scalar = (v) => {
|
|
245
|
+
if (typeof v === "number") return String(v);
|
|
246
|
+
const s = String(v);
|
|
247
|
+
return plain.test(s) && !/^(true|false|null|yes|no|on|off|~)$/i.test(s) && !/\s$/.test(s) && !/^\d+$/.test(s) ? s : JSON.stringify(s);
|
|
248
|
+
};
|
|
249
|
+
const key = (k) => (/^[A-Za-z_][\w-]*$/.test(k) ? k : JSON.stringify(k));
|
|
250
|
+
|
|
251
|
+
export function emit(tree, indent = 1) {
|
|
252
|
+
const pad = " ".repeat(indent);
|
|
253
|
+
return Object.entries(tree).flatMap(([k, v]) => (typeof v === "object" ? [`${pad}${key(k)}:`, ...emit(v, indent + 1)] : [`${pad}${key(k)}: ${scalar(v)}`]));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// The front matter a file has now: its text, its top-level blocks, and where the body starts.
|
|
257
|
+
export function split(text) {
|
|
258
|
+
const m = /^---[ \t]*\r?\n([\s\S]*?\r?\n)?---[ \t]*(?:\r?\n|$)/.exec(text);
|
|
259
|
+
if (!m) return { front: null, body: text, blocks: [] };
|
|
260
|
+
const lines = (m[1] || "").split(/\r?\n/);
|
|
261
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
262
|
+
const blocks = [];
|
|
263
|
+
for (const line of lines) {
|
|
264
|
+
const k = /^([A-Za-z_][\w-]*):/.exec(line);
|
|
265
|
+
if (k || !blocks.length) blocks.push({ key: k ? k[1] : null, lines: [line] });
|
|
266
|
+
else blocks[blocks.length - 1].lines.push(line);
|
|
267
|
+
}
|
|
268
|
+
return { front: m[0], body: text.slice(m[0].length), blocks };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const unquote = (s) => { s = s.trim(); return /^(".*"|'.*')$/.test(s) ? (s[0] === '"' ? safeJson(s) : s.slice(1, -1)) : s.replace(/\s+#.*$/, ""); };
|
|
272
|
+
const safeJson = (s) => { try { return JSON.parse(s); } catch { return s.slice(1, -1); } };
|
|
273
|
+
|
|
274
|
+
// A flat path -> text map of the generated groups in a front matter's blocks.
|
|
275
|
+
export function flatten(blocks) {
|
|
276
|
+
const out = new Map();
|
|
277
|
+
for (const b of blocks) {
|
|
278
|
+
if (!groupOrder.includes(b.key)) continue;
|
|
279
|
+
const stack = [];
|
|
280
|
+
for (const line of b.lines) {
|
|
281
|
+
if (!line.trim() || /^\s*#/.test(line)) continue;
|
|
282
|
+
const m = /^(\s*)("[^"]*"|'[^']*'|[^\s:][^:]*?)\s*:\s*(.*)$/.exec(line);
|
|
283
|
+
if (!m) continue;
|
|
284
|
+
const depth = m[1].length / 2;
|
|
285
|
+
stack.length = depth;
|
|
286
|
+
stack[depth] = unquote(m[2]);
|
|
287
|
+
if (m[3].trim()) out.set(stack.slice(0, depth + 1).join("."), String(unquote(m[3])));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function nameOf(blocks, file, given) {
|
|
294
|
+
const existing = blocks.find((b) => b.key === "name")?.lines[0].replace(/^name:\s*/, "");
|
|
295
|
+
if (existing && unquote(existing)) return unquote(existing);
|
|
296
|
+
if (given) return given;
|
|
297
|
+
const brief = resolve(dirname(file), "docs/brief.md");
|
|
298
|
+
const h = existsSync(brief) && /^#\s+(.+)$/m.exec(readFileSync(brief, "utf8"));
|
|
299
|
+
if (h) return h[1].trim();
|
|
300
|
+
return basename(dirname(resolve(file)));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// The whole file as it should be, and what the tables hold.
|
|
304
|
+
export function render(text, file, given) {
|
|
305
|
+
const { front, body, blocks } = split(text);
|
|
306
|
+
const { tree, flat, count } = build(text);
|
|
307
|
+
const lines = ["version: alpha", `name: ${scalar(nameOf(blocks, file, given))}`];
|
|
308
|
+
const keep = blocks.filter((b) => b.key && !generated.includes(b.key));
|
|
309
|
+
const description = keep.find((b) => b.key === "description");
|
|
310
|
+
if (description) lines.push(...description.lines);
|
|
311
|
+
for (const g of groupOrder) if (tree[g]) lines.push(`${g}:`, ...emit(tree[g]));
|
|
312
|
+
for (const b of keep) if (b !== description) lines.push(...b.lines);
|
|
313
|
+
const head = `---\n${lines.join("\n")}\n---\n`;
|
|
314
|
+
return { out: front ? head + body : `${head}\n${body}`, flat, count, front, blocks };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function main(argv) {
|
|
318
|
+
const args = argv.slice(2);
|
|
319
|
+
const check = args.includes("--check");
|
|
320
|
+
const n = args.indexOf("--name");
|
|
321
|
+
const given = n >= 0 ? args[n + 1] : undefined;
|
|
322
|
+
const file = args.find((a, i) => !a.startsWith("--") && args[i - 1] !== "--name") || "DESIGN.md";
|
|
323
|
+
if (!existsSync(file)) { console.error(`${file}: not found`); return 2; }
|
|
324
|
+
const text = readFileSync(file, "utf8");
|
|
325
|
+
let r;
|
|
326
|
+
try { r = render(text, file, given); } catch (e) { if (e instanceof Fail) { console.error(`${file}: ${e.message}`); return 2; } throw e; }
|
|
327
|
+
for (const w of warnings) console.error(`${file}: ${w}`);
|
|
328
|
+
if (check) {
|
|
329
|
+
if (!r.front) { console.log(`${file}: no front matter. Run tokens.mjs to write it from the tables.`); return 1; }
|
|
330
|
+
const have = flatten(r.blocks);
|
|
331
|
+
const want = new Map(r.flat.map(([k, v]) => [k, String(v)]));
|
|
332
|
+
const bad = [];
|
|
333
|
+
for (const [k, v] of want) if (!have.has(k)) bad.push(`${k}: in the table (${v}), not in the front matter`);
|
|
334
|
+
else if (have.get(k) !== v) bad.push(`${k}: table ${v}, front matter ${have.get(k)}`);
|
|
335
|
+
for (const k of have.keys()) if (!want.has(k)) bad.push(`${k}: in the front matter, not in the tables`);
|
|
336
|
+
if (!r.blocks.some((b) => b.key === "name")) bad.push("name: not in the front matter");
|
|
337
|
+
if (bad.length) { console.log(`${file}: tokens disagree with the tables (${bad.length}). Run tokens.mjs to rewrite the front matter.\n${bad.map((b) => `- ${b}`).join("\n")}`); return 1; }
|
|
338
|
+
console.log(`${file}: front matter agrees with the tables (${r.count} tokens)`);
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
if (r.out === text) console.log(`${file}: front matter already agrees (${r.count} tokens)`);
|
|
342
|
+
else { writeFileSync(file, r.out); console.log(`${file}: front matter ${r.front ? "refreshed" : "written"} from the tables (${r.count} tokens)`); }
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) process.exitCode = main(process.argv);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: design-content
|
|
3
|
+
description: >
|
|
4
|
+
Optional, any time. Plan what each key screen says and shows: its sections in
|
|
5
|
+
order, the one thing it leads with, real copy in the product's voice, and
|
|
6
|
+
the full set of pictures each screen needs, with licensed stand-ins of the
|
|
7
|
+
product's own subject where they have none. (The first three or four
|
|
8
|
+
pictures are found by design-direction.) Never asks them to write final copy.
|
|
9
|
+
Writes docs/design/design-content.md. Runs after the design brief, when
|
|
10
|
+
they ask about copy or imagery, or when design offers it because they have
|
|
11
|
+
no pictures.
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Design content
|
|
15
|
+
|
|
16
|
+
**Needs:** `docs/design/design-brief.md`
|
|
17
|
+
**Uses if there:** `docs/design/design-identity.md`, `docs/design/design-direction.md`
|
|
18
|
+
**Writes:** `docs/design/design-content.md`
|
|
19
|
+
|
|
20
|
+
The screens skill drafts copy on its own, so this one is never required. Run it when content deserves its own decisions: a site that lives on its words, a product with no pictures yet, or a team that wants to sign off copy before screens.
|
|
21
|
+
|
|
22
|
+
Comes out:
|
|
23
|
+
|
|
24
|
+
- **`docs/design/design-content.md`**, committed: per key screen, what it says and shows.
|
|
25
|
+
- New stand-ins join `.longbeard/design/pictures/` (gitignored), with `credits.tsv`.
|
|
26
|
+
|
|
27
|
+
## Gate
|
|
28
|
+
|
|
29
|
+
1. No `docs/design/design-brief.md` → `design-brief` first. Stop.
|
|
30
|
+
2. A content doc exists → a change: ask what changes, and update only that.
|
|
31
|
+
|
|
32
|
+
Read the brief (flows, key screens, identity nouns), the design brief (takeaway, voice, what is fixed) and, if they exist, the direction (what it carries, what waits for the prototype, the headline) and the identity (how pictures should feel).
|
|
33
|
+
|
|
34
|
+
## 1. Facts first, then the draft, then ask once
|
|
35
|
+
|
|
36
|
+
Copy is made from facts the product has, never from plausible inventions. Before any sentence, fill the fact sheet from the brief and the design brief, in their words where you can:
|
|
37
|
+
|
|
38
|
+
- **What it is:** one plain sentence.
|
|
39
|
+
- **Who it is for,** and who it is not for.
|
|
40
|
+
- **What people do today instead.**
|
|
41
|
+
- **What is true here and not elsewhere,** with its proof.
|
|
42
|
+
- **Words their customers use.**
|
|
43
|
+
- **Numbers,** each with where it came from.
|
|
44
|
+
- **One limit:** what it does not do, or who it is wrong for.
|
|
45
|
+
|
|
46
|
+
The voice is the design brief's `voice` line, as confirmed in its read-back. Do not add to it.
|
|
47
|
+
|
|
48
|
+
An empty field stays empty. Never fill it with a likely fact. Each section is built from fields that have something in them. A section with none is shortened or dropped, and the doc lists what they must supply. A fact you assumed to go on is marked as assumed (see the prototype's stand-in marks), not stated as true.
|
|
49
|
+
|
|
50
|
+
Each rhetorical device (a heading in two fragments, "X, not Y", a row of three figures) is used once per screen, where it lands hardest. A generic line gets a fact or a decision, never a synonym.
|
|
51
|
+
|
|
52
|
+
You write; they correct. For each key screen in the brief:
|
|
53
|
+
|
|
54
|
+
- **Job:** what a person comes to do here, in one line.
|
|
55
|
+
- **Leads with:** the first read: a headline, a number, a picture.
|
|
56
|
+
- **Sections, in order:** each with what it is for and its real copy, in the voice. Real names, real numbers, the longest real string where it matters.
|
|
57
|
+
- **Actions:** primary and secondary, worded.
|
|
58
|
+
- **Pictures:** what each shows (the subject, not a mood), how many, and whether theirs exist.
|
|
59
|
+
- **States:** what the empty, loading and error states say.
|
|
60
|
+
|
|
61
|
+
Show it in chat, one screen at a time if there are many, compact:
|
|
62
|
+
|
|
63
|
+
> Home: leads with "<headline>". Sections: <a>, <b>, <c>. Pictures: today's bread, the oven, the street. Still to supply: <empty fields>. Right, or what's off?
|
|
64
|
+
|
|
65
|
+
One round of corrections. "Go" takes the draft.
|
|
66
|
+
|
|
67
|
+
A fact the brief does not give (a price, an hour, a number, a name) is an assumed fact: it goes under `assumed:` on its screen below, and carries `data-standin="fact"` where a screen shows it.
|
|
68
|
+
|
|
69
|
+
## 2. The picture list, and stand-ins for the gaps
|
|
70
|
+
|
|
71
|
+
`design-direction` already found three or four pictures of the subject in `.longbeard/design/pictures/`. Here, list every picture the key screens need, mark which exist (theirs, or those stand-ins), and find only the missing ones: one query per picture, of the product's own subject, never the references'.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
node <skill>/scripts/pictures.mjs "baker shaping dough" --out .longbeard/design/pictures --count 1
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
It keeps only licences that hold everywhere (CC0, CC BY, CC BY-SA, public domain marked as worldwide), large enough for a screen, and adds each to `credits.tsv` with a ready credit line. Credits required by a licence must appear in the product, and the ready line is in `credits.tsv`; a share-alike picture, cropped or toned, stays under the same licence. Of the kind the look uses, treated the way the direction says (crop, toning). Show what was added on a contact sheet; they drop any they dislike. Never ranked.
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
node <skill>/scripts/contact-sheet.mjs .longbeard/design/pictures/credits.tsv --out <scratch>/pictures
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Stand-ins stay marked as stand-ins everywhere they are used, until theirs replace them: each one on a screen carries `data-standin="picture"` in the markup.
|
|
84
|
+
|
|
85
|
+
## Write `docs/design/design-content.md`
|
|
86
|
+
|
|
87
|
+
```markdown
|
|
88
|
+
# Content: <product>
|
|
89
|
+
|
|
90
|
+
## Facts
|
|
91
|
+
- is: <one sentence> · for: <who> · not for: <who>
|
|
92
|
+
- instead: <what people do today>
|
|
93
|
+
- only here: <what is true here, with its proof>
|
|
94
|
+
- their words: <…>
|
|
95
|
+
- numbers: <each with its source>
|
|
96
|
+
- limit: <what it does not do>
|
|
97
|
+
- to supply: <empty fields, and the sections they shrink or drop>
|
|
98
|
+
|
|
99
|
+
## <Key screen>
|
|
100
|
+
- job: <one line>
|
|
101
|
+
- leads with: <the first read>
|
|
102
|
+
- sections: 1. <name>: "<copy>" 2. …
|
|
103
|
+
- actions: <primary> · <secondary>
|
|
104
|
+
- pictures: <what each shows> — <theirs | stand-ins: n chosen>
|
|
105
|
+
- states: empty "<…>" · loading "<…>" · error "<…>"
|
|
106
|
+
- assumed: <each fact the brief does not give, as written above, or "none">
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Credits stay in `.longbeard/`, except where a licence requires credit in the product: then say where it must appear.
|
|
110
|
+
|
|
111
|
+
Then the next step in one line, from where the project is (`design` knows).
|
|
112
|
+
|
|
113
|
+
## Do not
|
|
114
|
+
|
|
115
|
+
- Ask them to write the copy. Draft it.
|
|
116
|
+
- Invent a number, a name or a quote. An empty field is a gap to name.
|
|
117
|
+
- Use the references' pictures, subject or words.
|
|
118
|
+
- Keep a picture without a clear licence, or rank pictures.
|