@jonandev/longbeard 0.5.0 → 0.5.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.
@@ -0,0 +1,447 @@
1
+ #!/usr/bin/env node
2
+ // A moodboard of the references that lead. The layout is this file.
3
+ // It shows what we saw. It does not paint a brand, a logo, a line, or a stat.
4
+ //
5
+ // node moodboard.mjs .design/board.md --out .design/moodboard.html --leads "North Room" --also "Margin"
6
+ import { execSync } from "node:child_process";
7
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
8
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
9
+
10
+ const args = process.argv.slice(2);
11
+ const flag = (name) => {
12
+ const i = args.indexOf(`--${name}`);
13
+ if (i === -1) return "";
14
+ const v = args[i + 1] ?? "";
15
+ args.splice(i, 2);
16
+ return v;
17
+ };
18
+
19
+ const outArg = flag("out");
20
+ const leadsArg = flag("leads");
21
+ const alsoArg = flag("also");
22
+ const boardArg = args[0];
23
+ if (!boardArg || !outArg || args.length !== 1) {
24
+ console.error('usage: node moodboard.mjs .design/board.md --out .design/moodboard.html --leads "Name" [--also "Name"]');
25
+ process.exit(2);
26
+ }
27
+
28
+ function projectRoot() {
29
+ try {
30
+ return execSync("git rev-parse --show-toplevel", { encoding: "utf8" }).trim();
31
+ } catch {
32
+ return process.cwd();
33
+ }
34
+ }
35
+
36
+ function resolvePath(path) {
37
+ if (!path) return "";
38
+ if (isAbsolute(path)) return path;
39
+ return resolve(projectRoot(), path);
40
+ }
41
+
42
+ const boardPath = resolvePath(boardArg);
43
+ const outPath = resolvePath(outArg);
44
+ if (!existsSync(boardPath)) {
45
+ console.error(`moodboard: no board at ${boardArg}`);
46
+ process.exit(1);
47
+ }
48
+
49
+ const esc = (s) =>
50
+ String(s ?? "")
51
+ .replace(/&/g, "&")
52
+ .replace(/</g, "&lt;")
53
+ .replace(/>/g, "&gt;")
54
+ .replace(/"/g, "&quot;");
55
+
56
+ const norm = (s) => s.trim().toLowerCase().replace(/\s+/g, " ").replace(/\.$/, "");
57
+
58
+ function fieldsOf(text) {
59
+ const fields = {};
60
+ let key = null;
61
+ for (const line of text.split(/\r?\n/)) {
62
+ const m = line.match(/^- ([a-z][a-z /]*):\s*(.*)$/i);
63
+ if (m) {
64
+ key = m[1].toLowerCase();
65
+ fields[key] = m[2].trim();
66
+ continue;
67
+ }
68
+ if (key && /^\s+\S/.test(line)) fields[key] = `${fields[key]} ${line.trim()}`.trim();
69
+ }
70
+ return fields;
71
+ }
72
+
73
+ function lum(hex) {
74
+ const [r, g, b] = [0, 2, 4]
75
+ .map((i) => parseInt(hex.slice(i + 1, i + 3), 16) / 255)
76
+ .map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
77
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
78
+ }
79
+
80
+ function expand(hex) {
81
+ const h = hex.replace("#", "");
82
+ const full = h.length === 3 ? h.replace(/./g, (c) => c + c) : h;
83
+ return `#${full.toLowerCase()}`;
84
+ }
85
+
86
+ function swatches(colour) {
87
+ const found = [];
88
+ const re = /#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})(?:\s*(?:→|->)\s*#([0-9a-fA-F]{6}|[0-9a-fA-F]{3}))?/g;
89
+ let m;
90
+ while ((m = re.exec(colour))) found.push({ index: m.index, end: re.lastIndex, hex: expand(m[2] || m[1]) });
91
+ const out = [];
92
+ for (let i = 0; i < found.length; i++) {
93
+ const end = i + 1 < found.length ? found[i + 1].index : colour.length;
94
+ const label = colour
95
+ .slice(found[i].end, end)
96
+ .replace(/^[\s,;:–\-."']+|[\s,;:–\-."']+$/g, "")
97
+ .replace(/\s+/g, " ")
98
+ .trim();
99
+ if (!out.some((s) => s.hex === found[i].hex)) out.push({ hex: found[i].hex, label });
100
+ }
101
+ return out.slice(0, 8);
102
+ }
103
+
104
+ function facesOf(typeLine) {
105
+ return typeLine
106
+ .split(/,|\s+and\s+|\s+&\s+|\s+\+\s+/i)
107
+ .map((s) => s.replace(/\s+for\s+.*/i, "").replace(/^(a pairing of|pairing of|the)\s+/i, "").trim())
108
+ .filter(Boolean)
109
+ .slice(0, 2);
110
+ }
111
+
112
+ function isSans(name) {
113
+ return /sans|grotesk|grotesque|gothic|america|aeonik|inter|helvetica|neue|haas|sohne|söhne|geist|satoshi|switzer|untitled/i.test(
114
+ name,
115
+ );
116
+ }
117
+
118
+ function cssFamily(name) {
119
+ if (!name) return '"Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif';
120
+ const safe = name.replace(/["\\<>]/g, "").slice(0, 80);
121
+ const fallback = isSans(name)
122
+ ? '"Helvetica Neue", Helvetica, Arial, sans-serif'
123
+ : '"Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif';
124
+ return `"${safe}", ${fallback}`;
125
+ }
126
+
127
+ function webPath(fromFile, absTarget) {
128
+ let rel = relative(dirname(fromFile), absTarget).split("\\").join("/");
129
+ if (!rel.startsWith(".")) rel = `./${rel}`;
130
+ return rel;
131
+ }
132
+
133
+ function shotSrc(shot) {
134
+ if (!shot) return "";
135
+ const abs = resolvePath(shot.trim());
136
+ if (!existsSync(abs)) {
137
+ console.error(`moodboard: missing shot ${shot.trim()}`);
138
+ return "";
139
+ }
140
+ return webPath(outPath, abs);
141
+ }
142
+
143
+ const md = readFileSync(boardPath, "utf8");
144
+ const readSlice = md.match(/## Read this\s*\n([\s\S]*?)(?=\n## |\n### |\n- kind:|$)/);
145
+ const read = readSlice ? fieldsOf(readSlice[1]) : {};
146
+ const leadsName = leadsArg || read.leads || read.primary || "";
147
+ if (!leadsName) {
148
+ console.error("moodboard: name the leading card with --leads");
149
+ process.exit(1);
150
+ }
151
+
152
+ const cards = [];
153
+ const chunks = md.split(/^### /m).slice(1);
154
+ for (const chunk of chunks) {
155
+ const nl = chunk.indexOf("\n");
156
+ const name = (nl === -1 ? chunk : chunk.slice(0, nl)).trim();
157
+ const body = nl === -1 ? "" : chunk.slice(nl + 1);
158
+ const cut = body.search(/^- kind:/m);
159
+ cards.push({ name, ...fieldsOf((cut === -1 ? body : body.slice(0, cut)).split(/^## /m)[0]) });
160
+ }
161
+
162
+ const primary = cards.find((c) => norm(c.name) === norm(leadsName));
163
+ if (!primary) {
164
+ console.error(`moodboard: no card named ${leadsName}`);
165
+ process.exit(1);
166
+ }
167
+ const alsoName = alsoArg || (read.also && !/^none$/i.test(read.also.trim()) ? read.also : "");
168
+ const also = alsoName ? cards.find((c) => norm(c.name) === norm(alsoName)) : null;
169
+ if (alsoName && !also) console.error(`moodboard: no card named ${alsoName}`);
170
+
171
+ const imagery = [];
172
+ {
173
+ let inCard = false;
174
+ let cur = null;
175
+ const push = () => {
176
+ if (cur?.kind === "imagery" && cur.shot) imagery.push(cur);
177
+ cur = null;
178
+ };
179
+ for (const line of md.split(/\r?\n/)) {
180
+ if (line.startsWith("### ")) {
181
+ inCard = true;
182
+ push();
183
+ continue;
184
+ }
185
+ if (line.startsWith("## ")) {
186
+ inCard = false;
187
+ push();
188
+ continue;
189
+ }
190
+ const m = line.match(/^- ([a-z][a-z /]*):\s*(.*)$/i);
191
+ if (m && m[1].toLowerCase() === "kind") {
192
+ inCard = false;
193
+ push();
194
+ cur = { kind: m[2].trim().toLowerCase() };
195
+ continue;
196
+ }
197
+ if (inCard) continue;
198
+ if (cur && m) cur[m[1].toLowerCase()] = m[2].trim();
199
+ else if (cur && line.trim() === "") push();
200
+ }
201
+ push();
202
+ }
203
+ if (imagery.length > 3) console.error(`moodboard: showing 3 of ${imagery.length} imagery`);
204
+
205
+ const colours = swatches(primary.colour || "").slice(0, 6);
206
+ const seenFaces = [];
207
+ for (const line of [primary.type, also && also.fit !== "form" ? also.type : ""]) {
208
+ for (const face of facesOf(line || "")) {
209
+ if (!seenFaces.some((f) => norm(f) === norm(face))) seenFaces.push(face);
210
+ }
211
+ }
212
+ const faces = seenFaces.slice(0, 3);
213
+ const family = cssFamily(faces[0] || "");
214
+ const ink = "#1c1c1a";
215
+
216
+ const principle = (primary["worth taking"] || "").trim();
217
+ const primarySrc = shotSrc(primary.shot);
218
+ const alsoSrc = also ? shotSrc(also.shot) : "";
219
+ const pictures = imagery.slice(0, 3).flatMap((item) => {
220
+ const src = shotSrc(item.shot);
221
+ return src ? [{ src, caption: (item.shows || "").trim() }] : [];
222
+ });
223
+
224
+ const tiles = [];
225
+ if (faces.length) {
226
+ const names = faces
227
+ .map((face) => `<p class="face" style="font-family:${cssFamily(face)}">${esc(face)}</p>`)
228
+ .join("");
229
+ tiles.push(`<article class="tile type span-${colours.length ? 2 : 6}">
230
+ <p class="kicker">Type we saw</p>
231
+ <p class="aa">Aa</p>
232
+ <div class="faces">${names}</div>
233
+ </article>`);
234
+ }
235
+ if (colours.length) {
236
+ const span = faces.length ? 4 : 6;
237
+ const chips = colours
238
+ .map((s) => {
239
+ const edge = lum(s.hex) > 0.86 ? " chip-edge" : "";
240
+ return `<div class="swatch"><div class="chip${edge}" style="background:${s.hex}"></div><p class="hex">${esc(s.hex)}</p>${s.label ? `<p class="role">${esc(s.label)}</p>` : ""}</div>`;
241
+ })
242
+ .join("");
243
+ tiles.push(`<article class="tile colour span-${span}"><p class="kicker">Colour we saw</p><div class="swatches">${chips}</div></article>`);
244
+ }
245
+ if (primarySrc || principle) {
246
+ const span = also && (alsoSrc || also["worth taking"]) ? 3 : 6;
247
+ const shot = primarySrc ? `<img src="${esc(primarySrc)}" alt="Leading reference, top of the shot">` : "";
248
+ tiles.push(`<article class="tile primary span-${span}${primarySrc ? " shot" : " no-shot"}">${shot}<div class="caption"><p class="kicker">Leads</p>${principle ? `<p class="control">${esc(principle)}</p>` : ""}</div></article>`);
249
+ }
250
+ if (also && (alsoSrc || also["worth taking"])) {
251
+ const span = primarySrc || principle ? 3 : 6;
252
+ const shot = alsoSrc ? `<img src="${esc(alsoSrc)}" alt="Also reference, top of the shot">` : "";
253
+ const line = (also["worth taking"] || "").trim();
254
+ tiles.push(`<article class="tile also span-${span}${alsoSrc ? " shot" : ""}">${shot}<div class="caption"><p class="kicker">Also</p>${line ? `<p class="control">${esc(line)}</p>` : ""}</div></article>`);
255
+ }
256
+ const pictureSpan = pictures.length === 1 ? 6 : pictures.length === 2 ? 3 : 2;
257
+ for (const pic of pictures) {
258
+ const cap = pic.caption ? `<figcaption>${esc(pic.caption)}</figcaption>` : "";
259
+ tiles.push(`<figure class="tile picture shot span-${pictureSpan}"><img src="${esc(pic.src)}" alt="${esc(pic.caption || "Imagery")}">${cap}</figure>`);
260
+ }
261
+
262
+ if (!tiles.length) {
263
+ console.error("moodboard: nothing on the board to show");
264
+ process.exit(1);
265
+ }
266
+
267
+ const html = `<!DOCTYPE html>
268
+ <html lang="en">
269
+ <head>
270
+ <meta charset="utf-8">
271
+ <meta name="viewport" content="width=device-width, initial-scale=1">
272
+ <title>Moodboard</title>
273
+ <style>
274
+ :root {
275
+ --display: ${family};
276
+ --ink: ${ink};
277
+ --paper: #ffffff;
278
+ --canvas: #e4e4e2;
279
+ --muted: #6f6f6a;
280
+ --ui: "Helvetica Neue", Helvetica, Arial, sans-serif;
281
+ }
282
+ * { box-sizing: border-box; }
283
+ html { color-scheme: light; }
284
+ body {
285
+ margin: 0;
286
+ min-height: 100vh;
287
+ background: var(--canvas);
288
+ color: var(--ink);
289
+ font-family: var(--ui);
290
+ -webkit-font-smoothing: antialiased;
291
+ }
292
+ .sheet { max-width: 1080px; margin: 0 auto; padding: 52px 28px 80px; }
293
+ h1 {
294
+ margin: 0 0 16px 2px;
295
+ font-family: var(--ui);
296
+ font-size: 11px;
297
+ font-weight: 600;
298
+ letter-spacing: 0.18em;
299
+ text-transform: uppercase;
300
+ color: var(--muted);
301
+ }
302
+ .grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; align-items: stretch; }
303
+ .tile { background: var(--paper); border-radius: 22px; overflow: hidden; min-width: 0; }
304
+ .span-2 { grid-column: span 2; }
305
+ .span-3 { grid-column: span 3; }
306
+ .span-4 { grid-column: span 4; }
307
+ .span-6 { grid-column: span 6; }
308
+ .kicker {
309
+ margin: 0;
310
+ font-size: 11px;
311
+ font-weight: 600;
312
+ letter-spacing: 0.16em;
313
+ text-transform: uppercase;
314
+ color: var(--muted);
315
+ }
316
+ .type, .colour, .principle, .leave { padding: 22px 24px 20px; }
317
+ .type {
318
+ display: flex;
319
+ flex-direction: column;
320
+ min-height: 250px;
321
+ background: #171717;
322
+ color: #f6f5f2;
323
+ }
324
+ .type .kicker { color: rgba(255, 255, 255, 0.55); }
325
+ .aa {
326
+ margin: 22px 0 0;
327
+ font-family: var(--display);
328
+ font-size: 104px;
329
+ line-height: 0.78;
330
+ letter-spacing: -0.045em;
331
+ font-weight: 500;
332
+ color: #f6f5f2;
333
+ }
334
+ .faces { margin-top: 20px; }
335
+ .face {
336
+ margin: 0;
337
+ font-family: var(--display);
338
+ font-size: 22px;
339
+ line-height: 1.2;
340
+ letter-spacing: -0.03em;
341
+ color: #f6f5f2;
342
+ }
343
+ .face + .face { margin-top: 2px; font-size: 16px; color: rgba(255, 255, 255, 0.62); }
344
+ .colour { display: flex; flex-direction: column; min-height: 250px; }
345
+ .swatches {
346
+ margin-top: auto;
347
+ padding-top: 22px;
348
+ display: grid;
349
+ grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
350
+ gap: 10px 12px;
351
+ }
352
+ .chip { height: 92px; border-radius: 14px; }
353
+ .chip-edge { box-shadow: inset 0 0 0 1px rgba(28, 28, 26, 0.14); }
354
+ .hex {
355
+ margin: 8px 0 0;
356
+ font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
357
+ font-size: 11px;
358
+ letter-spacing: 0.02em;
359
+ color: #3c3c39;
360
+ }
361
+ .role {
362
+ margin: 2px 0 0;
363
+ font-size: 12px;
364
+ line-height: 1.3;
365
+ color: var(--muted);
366
+ display: -webkit-box;
367
+ -webkit-line-clamp: 2;
368
+ -webkit-box-orient: vertical;
369
+ overflow: hidden;
370
+ }
371
+ .principle { display: flex; flex-direction: column; min-height: 320px; }
372
+ .principle .kicker { color: color-mix(in srgb, currentColor 58%, transparent); }
373
+ .statement {
374
+ margin: auto 0 0;
375
+ max-width: 16ch;
376
+ font-family: var(--display);
377
+ font-size: 40px;
378
+ line-height: 1.05;
379
+ letter-spacing: -0.035em;
380
+ font-weight: 500;
381
+ }
382
+ .statement.long { font-size: 28px; line-height: 1.15; max-width: 22ch; }
383
+ .shot { position: relative; background: #1a1a1a; }
384
+ .shot img {
385
+ display: block;
386
+ width: 100%;
387
+ height: 320px;
388
+ object-fit: cover;
389
+ object-position: top center;
390
+ background: #eceae6;
391
+ }
392
+ .picture img { height: 250px; object-position: center; }
393
+ .shot .caption, .picture figcaption {
394
+ position: absolute;
395
+ left: 0;
396
+ right: 0;
397
+ bottom: 0;
398
+ margin: 0;
399
+ padding: 64px 18px 16px;
400
+ background: linear-gradient(to top, rgba(10, 10, 10, 0.78) 0%, rgba(10, 10, 10, 0.28) 52%, rgba(10, 10, 10, 0) 100%);
401
+ color: #fff;
402
+ }
403
+ .shot .kicker { color: rgba(255, 255, 255, 0.72); }
404
+ .shot .control { margin: 4px 0 0; font-size: 16px; line-height: 1.3; color: #fff; }
405
+ .picture { margin: 0; }
406
+ .picture figcaption {
407
+ font-size: 14px;
408
+ line-height: 1.3;
409
+ display: -webkit-box;
410
+ -webkit-line-clamp: 2;
411
+ -webkit-box-orient: vertical;
412
+ overflow: hidden;
413
+ }
414
+ .primary.no-shot { min-height: 220px; background: var(--paper); }
415
+ .primary.no-shot .caption { position: static; padding: 22px 24px; background: none; color: inherit; }
416
+ .primary.no-shot .kicker { color: var(--muted); }
417
+ .primary.no-shot .control {
418
+ font-family: var(--display);
419
+ font-size: 28px;
420
+ line-height: 1.15;
421
+ letter-spacing: -0.03em;
422
+ color: #2a2a28;
423
+ }
424
+ .leave { display: flex; flex-direction: column; justify-content: center; gap: 12px; min-height: 180px; }
425
+ .quiet { margin: 0; max-width: 28em; font-size: 20px; line-height: 1.35; letter-spacing: -0.02em; color: #3a3a38; }
426
+ @media (max-width: 800px) {
427
+ .sheet { padding: 28px 16px 48px; }
428
+ .tile, .span-2, .span-3, .span-4, .span-6 { grid-column: 1 / -1; }
429
+ .aa { font-size: 84px; }
430
+ .statement { font-size: 32px; }
431
+ }
432
+ </style>
433
+ </head>
434
+ <body>
435
+ <main class="sheet">
436
+ <h1>Moodboard</h1>
437
+ <div class="grid">
438
+ ${tiles.join("\n ")}
439
+ </div>
440
+ </main>
441
+ </body>
442
+ </html>
443
+ `;
444
+
445
+ mkdirSync(dirname(outPath), { recursive: true });
446
+ writeFileSync(outPath, html);
447
+ console.log(outArg);