@jonandev/longbeard 0.11.2 → 0.12.0
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 +3 -4
- package/CHANGELOG.md +67 -0
- package/README.md +63 -43
- package/beard.json +113 -26
- package/bin/long-beard.js +172 -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 +17 -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/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,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: design-wordmark
|
|
3
|
+
description: >
|
|
4
|
+
Optional, after the identity. A wordmark made from the identity's own faces and devices:
|
|
5
|
+
four to six marks rendered in the navigation and at hero size on the
|
|
6
|
+
identity's grounds, picked and pushed once. Adds the mark to
|
|
7
|
+
docs/design/design-identity.md and the identity board. Runs once the
|
|
8
|
+
identity is chosen, when they want a mark beyond the name set in the
|
|
9
|
+
display face.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Design wordmark
|
|
13
|
+
|
|
14
|
+
**Needs:** `docs/design/design-identity.md`, `docs/design/design-direction.md`
|
|
15
|
+
**Uses if there:** `DESIGN.md`
|
|
16
|
+
**Writes:** `docs/design/wordmark.svg`, a section in `docs/design/design-identity.md`
|
|
17
|
+
|
|
18
|
+
A product does not need a mark to be designed: until then, the name is set in the display face. This skill is for when they want one. It is not a logo project: it draws marks from the type and colour already chosen.
|
|
19
|
+
|
|
20
|
+
Comes out: the chosen mark as SVG in `docs/design/wordmark.svg`, a section in `design-identity.md`, and the mark on the identity board. Options live in `.longbeard/design/wordmark/`.
|
|
21
|
+
|
|
22
|
+
## Gate
|
|
23
|
+
|
|
24
|
+
1. No `docs/design/design-direction.md` → `design-direction` first: a mark is judged where the name actually sits. No `docs/design/design-identity.md` → `design-identity`. Stop.
|
|
25
|
+
2. A mark exists → a change: show it, ask what changes.
|
|
26
|
+
|
|
27
|
+
Read the identity, the brief's name and identity nouns, and the design brief's personality.
|
|
28
|
+
|
|
29
|
+
## 1. Marks, one sheet
|
|
30
|
+
|
|
31
|
+
Four to six marks, each a small HTML page in `.longbeard/design/wordmark/`, made only from the identity's faces and colours and devices that belong to them: a cut, a ligature, a case, a rule, a shape, the accent. One of them is the name set plainly in the display face, so not making a mark is a choice too. Never a stock icon, a generic symbol, or anything from a reference.
|
|
32
|
+
|
|
33
|
+
Each is shown where the name actually sits in the chosen screen (`.longbeard/design/direction/prototype/first.html`), at that size and on that ground, and once large on its own. Where the chosen screen does not show the name at all, that stays so: the mark is for the places that do (the navigation, the tab, the favicon). Capture them and set them on one sheet:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
node <skill>/scripts/capture.mjs "file://$PWD/.longbeard/design/wordmark/1.html" --out .longbeard/design/wordmark/1.png
|
|
37
|
+
node <skill>/scripts/sheet.mjs .longbeard/design/wordmark/sheet.html .longbeard/design/wordmark/1.png … --cols 3
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each with one line of what it does ("the A's crossbar is the accent bar"). Numbered, never ranked.
|
|
41
|
+
|
|
42
|
+
> Which mark? Or one to push further ("2, but tighter").
|
|
43
|
+
|
|
44
|
+
## 2. Push once
|
|
45
|
+
|
|
46
|
+
On their pick, two or three variations of it (spacing, weight, the device's size), the same way. Then their yes.
|
|
47
|
+
|
|
48
|
+
## 3. Write it
|
|
49
|
+
|
|
50
|
+
- Export the mark as clean SVG, text outlined, at `docs/design/wordmark.svg`, with a version per ground that needs one.
|
|
51
|
+
- Add to `design-identity.md`:
|
|
52
|
+
|
|
53
|
+
```markdown
|
|
54
|
+
## Wordmark
|
|
55
|
+
docs/design/wordmark.svg — <what it does, in one line>. Smallest size: <px>. On: <grounds>.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Add it to `docs/design/design-identity.html` (the header), to the chosen screen in place of the plain name, and to the Figma Cover if `design-figma` has run.
|
|
59
|
+
|
|
60
|
+
## Do not
|
|
61
|
+
|
|
62
|
+
- Make a mark before the direction is chosen, or change the identity or the composition to fit a mark.
|
|
63
|
+
- Add the name or the mark to a screen whose composition leaves it out.
|
|
64
|
+
- Use a stock icon, a generic symbol, or a reference's mark.
|
|
65
|
+
- Rank the marks.
|