@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.
Files changed (93) hide show
  1. package/AGENTS.md +3 -4
  2. package/CHANGELOG.md +67 -0
  3. package/README.md +63 -43
  4. package/beard.json +113 -26
  5. package/bin/long-beard.js +172 -36
  6. package/package.json +1 -1
  7. package/skills/design/SKILL.md +51 -126
  8. package/skills/design-brief/SKILL.md +146 -0
  9. package/skills/design-brief/references/graphic.md +59 -0
  10. package/skills/design-check/SKILL.md +27 -11
  11. package/skills/design-check/references/design-rules.md +21 -7
  12. package/skills/design-check/scripts/capture.mjs +121 -37
  13. package/skills/design-check/scripts/contrast.mjs +23 -9
  14. package/skills/design-check/scripts/rules.mjs +613 -0
  15. package/skills/design-check/scripts/screen-contrast.mjs +428 -0
  16. package/skills/design-check/scripts/tokens.mjs +346 -0
  17. package/skills/design-content/SKILL.md +118 -0
  18. package/skills/design-content/scripts/contact-sheet.mjs +259 -0
  19. package/skills/design-content/scripts/pictures.mjs +197 -0
  20. package/skills/design-direction/SKILL.md +115 -200
  21. package/skills/design-direction/references/controls.md +58 -0
  22. package/skills/{design → design-direction}/references/design-rules.md +21 -7
  23. package/skills/design-direction/references/five-second.md +47 -0
  24. package/skills/design-direction/references/full-build.md +19 -0
  25. package/skills/design-direction/references/graphic.md +35 -0
  26. package/skills/design-direction/references/grid.md +114 -0
  27. package/skills/design-direction/references/library.md +75 -0
  28. package/skills/design-direction/references/screen-template.html +233 -0
  29. package/skills/design-direction/references/subject.md +33 -0
  30. package/skills/design-direction/scripts/capture.mjs +121 -37
  31. package/skills/design-direction/scripts/contact-sheet.mjs +18 -7
  32. package/skills/design-direction/scripts/fonts.mjs +276 -0
  33. package/skills/design-direction/scripts/layout-diff.mjs +118 -0
  34. package/skills/design-direction/scripts/measure.mjs +1728 -0
  35. package/skills/design-direction/scripts/moodboard.mjs +123 -32
  36. package/skills/design-direction/scripts/picture-cast.mjs +270 -0
  37. package/skills/design-direction/scripts/pictures.mjs +197 -0
  38. package/skills/design-direction/scripts/screen-contrast.mjs +428 -0
  39. package/skills/design-direction/scripts/sheet.mjs +67 -0
  40. package/skills/design-direction/scripts/subject-colours.mjs +410 -0
  41. package/skills/design-families/SKILL.md +138 -0
  42. package/skills/design-families/scripts/contact-sheet.mjs +259 -0
  43. package/skills/design-families/scripts/families.mjs +606 -0
  44. package/skills/design-families/scripts/measure.mjs +1728 -0
  45. package/skills/design-families/scripts/moodboard.mjs +467 -0
  46. package/skills/design-families/scripts/tag.mjs +289 -0
  47. package/skills/design-figma/SKILL.md +69 -0
  48. package/skills/design-figma/references/graphic.md +26 -0
  49. package/skills/design-identity/SKILL.md +134 -0
  50. package/skills/design-identity/references/graphic.md +8 -0
  51. package/skills/design-identity/references/identity-board.html +140 -0
  52. package/skills/{design → design-identity}/scripts/capture.mjs +121 -37
  53. package/skills/design-identity/scripts/colours.mjs +213 -0
  54. package/skills/design-identity/scripts/contrast.mjs +41 -0
  55. package/skills/design-identity/scripts/fonts.mjs +276 -0
  56. package/skills/design-identity/scripts/measure.mjs +1728 -0
  57. package/skills/design-identity/scripts/sheet.mjs +67 -0
  58. package/skills/design-identity/scripts/subject-colours.mjs +410 -0
  59. package/skills/design-moodboard/SKILL.md +184 -0
  60. package/skills/design-moodboard/references/graphic.md +25 -0
  61. package/skills/{design-direction → design-moodboard}/references/sources.md +17 -11
  62. package/skills/design-moodboard/scripts/capture.mjs +893 -0
  63. package/skills/design-moodboard/scripts/contact-sheet.mjs +259 -0
  64. package/skills/design-moodboard/scripts/crops.mjs +256 -0
  65. package/skills/design-moodboard/scripts/dribbble-cards.mjs +418 -0
  66. package/skills/design-moodboard/scripts/families.mjs +606 -0
  67. package/skills/design-moodboard/scripts/group.mjs +221 -0
  68. package/skills/design-moodboard/scripts/measure.mjs +1728 -0
  69. package/skills/design-moodboard/scripts/moodboard.mjs +467 -0
  70. package/skills/{design-direction → design-moodboard}/scripts/picker.mjs +121 -20
  71. package/skills/design-moodboard/scripts/pictures.mjs +197 -0
  72. package/skills/design-moodboard/scripts/tag.mjs +289 -0
  73. package/skills/design-prototype/SKILL.md +149 -0
  74. package/skills/design-prototype/references/design-md-template.md +82 -0
  75. package/skills/design-prototype/references/design-rules.md +203 -0
  76. package/skills/design-prototype/references/five-second.md +47 -0
  77. package/skills/design-prototype/references/graphic.md +27 -0
  78. package/skills/design-prototype/scripts/capture.mjs +893 -0
  79. package/skills/design-prototype/scripts/contrast.mjs +41 -0
  80. package/skills/design-prototype/scripts/links.mjs +308 -0
  81. package/skills/design-prototype/scripts/pictures.mjs +197 -0
  82. package/skills/design-prototype/scripts/rules.mjs +613 -0
  83. package/skills/design-prototype/scripts/screen-contrast.mjs +428 -0
  84. package/skills/design-prototype/scripts/sheet.mjs +67 -0
  85. package/skills/design-prototype/scripts/tokens.mjs +346 -0
  86. package/skills/design-wordmark/SKILL.md +65 -0
  87. package/skills/design-wordmark/scripts/capture.mjs +893 -0
  88. package/skills/design-wordmark/scripts/sheet.mjs +67 -0
  89. package/skills/idea/SKILL.md +13 -7
  90. package/skills/idea/references/graphic.md +64 -0
  91. package/skills/design/references/design-md-template.md +0 -58
  92. package/skills/design/scripts/contrast.mjs +0 -27
  93. package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ // Put a screen beside the reference it was built from, measured the same way,
3
+ // so the critic's eye has numbers under it. Node 22+, an installed Chrome.
4
+ //
5
+ // node layout-diff.mjs <reference picture> <screen capture> --out <folder> [--mirror]
6
+ //
7
+ // Both pictures are read by measure.mjs (a reference in a presentation frame
8
+ // is read inside it). Writes to --out:
9
+ // diff.json each measure on both sides and whether it is off: the
10
+ // headline's size against the screen, its box, its lines, the
11
+ // type scale, the margins the text keeps on each side, how
12
+ // much is empty and how much is pictures, and every line of
13
+ // text matched to its nearest line in the reference;
14
+ // side.png the reference (cropped to its screen) and the screen, side by side, at one size;
15
+ // overlay.png the screen with the reference faintly over it, at the same size,
16
+ // so a box that moved, a gap that closed or a size that drifted shows.
17
+ // --mirror compares against the reference flipped, for a screen whose layout turned.
18
+ // Sizes are shares of the screen; "off" is more than 15% apart, or a box more
19
+ // than 3% of the screen away. Exit 0 whenever both pictures were read, whatever is
20
+ // off: it reports, the critic decides. Exit 1 when a picture could not be read,
21
+ // 2 when called wrong. A picture that could not be drawn is said on stderr and
22
+ // leaves the exit alone; diff.json is already written.
23
+ // A tall capture is read on its first screen only, and the pictures show that
24
+ // first screen and nothing below it. --out may be relative: it is taken from
25
+ // where this is run, and the pictures land beside diff.json.
26
+ import { spawnSync } from "node:child_process";
27
+ import { mkdirSync, writeFileSync } from "node:fs";
28
+ import { dirname, join, resolve } from "node:path";
29
+ import { fileURLToPath, pathToFileURL } from "node:url";
30
+
31
+ const here = dirname(fileURLToPath(import.meta.url));
32
+ const args = process.argv.slice(2);
33
+ const flag = (name) => {
34
+ const i = args.indexOf(`--${name}`);
35
+ return i === -1 ? null : args.splice(i, 2)[1];
36
+ };
37
+ const has = (name) => {
38
+ const i = args.indexOf(`--${name}`);
39
+ return i === -1 ? false : (args.splice(i, 1), true);
40
+ };
41
+ const out = flag("out");
42
+ const mirror = has("mirror");
43
+ if (args.length !== 2 || !out) {
44
+ console.error("usage: node layout-diff.mjs <reference picture> <screen capture> --out <folder> [--mirror]");
45
+ process.exit(2);
46
+ }
47
+ const [refFile, screenFile] = args.map((f) => resolve(f));
48
+ const outDir = resolve(out);
49
+ mkdirSync(outDir, { recursive: true });
50
+
51
+ function read(file) {
52
+ const r = spawnSync(process.execPath, [join(here, "measure.mjs"), file, "--lines"], { encoding: "utf8", maxBuffer: 1 << 26 });
53
+ if (r.status !== 0) {
54
+ console.error(`layout-diff: could not read ${file}: ${r.stderr.trim()}`);
55
+ process.exit(1);
56
+ }
57
+ return JSON.parse(r.stdout);
58
+ }
59
+ const ref = read(refFile);
60
+ const screen = read(screenFile);
61
+
62
+ // Boxes as [x, y, w, h] shares of the screen read; the reference's flipped when it turned.
63
+ const flip = (b) => (mirror ? [1 - b[0] - b[2], b[1], b[2], b[3]] : b);
64
+ const lines = (m, f = (b) => b) => (m.type?.lines || []).map((l) => ({ size: l.size, px: l.px1440, box: f(l.box), case: l.case }));
65
+ const R = lines(ref, flip);
66
+ const S = lines(screen);
67
+ const round = (n, d = 3) => (n == null ? null : Math.round(n * 10 ** d) / 10 ** d);
68
+ const ratioOff = (a, b) => a != null && b != null && a > 0 && b > 0 && Math.max(a / b, b / a) > 1.15;
69
+ const rows = [];
70
+ const row = (what, r, s, off) => rows.push({ what, reference: r, screen: s, off: Boolean(off) });
71
+
72
+ const rd = ref.type?.display, sd = screen.type?.display;
73
+ row("headline size (share of the screen's height)", round(rd?.size), round(sd?.size), ratioOff(rd?.size, sd?.size));
74
+ if (rd?.box && sd?.box) {
75
+ const rb = flip(rd.box);
76
+ const far = Math.max(...rb.map((v, i) => Math.abs(v - sd.box[i]))) > 0.03;
77
+ row("headline box [x, y, w, h]", rb.map((v) => round(v)), sd.box.map((v) => round(v)), far);
78
+ }
79
+ row("headline lines", ref.type?.headline?.lines ?? null, screen.type?.headline?.lines ?? null, (ref.type?.headline?.lines ?? 0) !== (screen.type?.headline?.lines ?? 0));
80
+ row("type scale (headline over body)", ref.type?.scale ?? null, screen.type?.scale ?? null, ratioOff(ref.type?.scale, screen.type?.scale));
81
+ const margins = (L) => (L.length ? { left: round(Math.min(...L.map((l) => l.box[0]))), right: round(1 - Math.max(...L.map((l) => l.box[0] + l.box[2]))), top: round(Math.min(...L.map((l) => l.box[1]))), bottom: round(1 - Math.max(...L.map((l) => l.box[1] + l.box[3]))) } : null);
82
+ const rm = margins(R), sm = margins(S);
83
+ for (const side of ["left", "right", "top", "bottom"]) if (rm && sm) row(`text margin, ${side}`, rm[side], sm[side], Math.abs(rm[side] - sm[side]) > 0.03 && ratioOff(rm[side] + 0.001, sm[side] + 0.001));
84
+ row("empty (%)", ref.traits?.empty ?? null, screen.traits?.empty ?? null, Math.abs((ref.traits?.empty ?? 0) - (screen.traits?.empty ?? 0)) > 15);
85
+ row("pictures (%)", ref.traits?.pictures ?? null, screen.traits?.pictures ?? null, Math.abs((ref.traits?.pictures ?? 0) - (screen.traits?.pictures ?? 0)) > 15);
86
+ row("small text blocks", ref.type?.small ?? null, screen.type?.small ?? null, (screen.type?.small ?? 0) > (ref.type?.small ?? 0) + 1);
87
+
88
+ // Each line of the screen matched to the nearest line of the reference of a like size.
89
+ const matched = S.map((s) => {
90
+ let best = null, cost = Infinity;
91
+ for (const r of R) {
92
+ const c = Math.hypot(s.box[0] - r.box[0], s.box[1] - r.box[1]) + Math.abs(Math.log(s.size / r.size));
93
+ if (c < cost) (cost = c), (best = r);
94
+ }
95
+ if (!best) return { screen: s, reference: null, off: true };
96
+ const moved = Math.hypot(s.box[0] - best.box[0], s.box[1] - best.box[1]);
97
+ return { screen: { px: s.px, box: s.box.map((v) => round(v)) }, reference: { px: best.px, box: best.box.map((v) => round(v)) }, moved: round(moved), off: moved > 0.03 || ratioOff(s.size, best.size) };
98
+ });
99
+
100
+ const off = rows.filter((r) => r.off).map((r) => r.what);
101
+ const report = { reference: refFile, screen: screenFile, mirror, off, measures: rows, lines: matched, unread: "pictures' boxes and the gaps between them are not measured here: the critic judges them on side.png and overlay.png" };
102
+ writeFileSync(join(outDir, "diff.json"), JSON.stringify(report, null, 1));
103
+
104
+ // The pictures: the reference cropped to the screen measure.mjs read, both at 1440 wide.
105
+ // That is the frame it found, else (a tall capture, firstScreen) the top 1440 by 900 share, else the whole.
106
+ const [fx, fy, fw, fh] = ref.frame?.box || [0, 0, ref.width, ref.firstScreen ? Math.round((ref.width * 900) / 1440) : ref.height];
107
+ const W = 1440, H = Math.round((W * fh) / fw);
108
+ const refLayer = (opacity) => `<div style="position:absolute;inset:0;overflow:hidden;opacity:${opacity}"><img src="${pathToFileURL(refFile)}" style="position:absolute;left:${(-fx * W) / fw}px;top:${(-fy * W) / fw}px;width:${(ref.width * W) / fw}px;${mirror ? "transform:scaleX(-1);transform-origin:" + ((fx + fw / 2) * W) / fw + "px 0;" : ""}"></div>`;
109
+ const shot = `<img src="${pathToFileURL(screenFile)}" style="position:absolute;inset:0;width:${W}px;height:${H}px;object-fit:cover;object-position:top">`;
110
+ const page = (body, w) => `<!doctype html><html><head><title>ready</title><style>*{margin:0}body{width:${w}px;background:#777}.f{position:relative;width:${W}px;height:${H}px;overflow:hidden;display:inline-block;vertical-align:top}</style></head><body>${body}</body></html>`;
111
+ writeFileSync(join(outDir, "side.html"), page(`<div class="f">${refLayer(1)}</div><div class="f" style="margin-left:20px">${shot}</div>`, W * 2 + 20));
112
+ writeFileSync(join(outDir, "overlay.html"), page(`<div class="f">${shot}${refLayer(0.4)}</div>`, W));
113
+ for (const [name, w] of [["side", W * 2 + 20], ["overlay", W]]) {
114
+ const c = spawnSync(process.execPath, [join(here, "capture.mjs"), pathToFileURL(join(outDir, `${name}.html`)).href, "--out", join(outDir, `${name}.png`), "--width", String(w), "--clip", `0,0,${w},${H}`], { encoding: "utf8" });
115
+ if (c.status !== 0) console.error(`layout-diff: ${name}.png not drawn: ${c.stderr.trim()}`);
116
+ }
117
+ console.log(off.length ? `off: ${off.join("; ")}` : "nothing measured is off");
118
+ console.log(`lines off: ${matched.filter((m) => m.off).length} of ${matched.length}. ${join(outDir, "diff.json")}, side.png, overlay.png`);