@jonandev/longbeard 0.11.1 → 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 +72 -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 -122
  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 +117 -145
  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,140 @@
1
+ <!doctype html>
2
+ <!--
3
+ The identity board. Copy it to .longbeard/design/identity/board.html for the
4
+ options, and to docs/design/design-identity.html once they say "this is us".
5
+ Write only the IDENTITY block below: the product's name, the two faces and
6
+ the colours. Everything else is built from it, so the board is never laid
7
+ out by hand.
8
+
9
+ Options are copies of this page, one per option (option-1.html …), each with
10
+ its own block, captured and set on one sheet with sheet.mjs.
11
+ The page sets document.title to "ready" once the faces have loaded.
12
+ -->
13
+ <html lang="en">
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <meta name="viewport" content="width=device-width, initial-scale=1">
17
+ <title>Identity</title>
18
+ <script id="identity" type="application/json">
19
+ {
20
+ "name": "Product",
21
+ "line": "One line in the product's voice, set in its faces.",
22
+ "display": { "face": "Unbounded", "weight": 500, "case": "uppercase", "tracking": "-0.01em", "css": null, "note": "Display" },
23
+ "body": { "face": "Inter", "weight": 400, "css": null, "note": "Text" },
24
+ "colours": [
25
+ { "name": "Signal", "hex": "#C0FF00", "role": ["accent", "ground"] },
26
+ { "name": "Paper", "hex": "#EEEEEE", "role": "ground" },
27
+ { "name": "Stone", "hex": "#C0C0C0", "role": "ground" },
28
+ { "name": "Ink", "hex": "#0B0B0B", "role": ["ink", "ground"] }
29
+ ]
30
+ }
31
+ </script>
32
+ <style>
33
+ :root {
34
+ --board: #f4f2ee;
35
+ --board-ink: #17171a;
36
+ --board-soft: #6d6a64;
37
+ --rule: rgba(23, 23, 26, 0.1);
38
+ --r: 36px;
39
+ }
40
+ * { box-sizing: border-box; margin: 0; }
41
+ body {
42
+ background: var(--board);
43
+ color: var(--board-ink);
44
+ font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
45
+ -webkit-font-smoothing: antialiased;
46
+ }
47
+ .board { width: 1280px; margin: 0 auto; padding: 72px 80px 88px; display: grid; gap: 72px; }
48
+ .label { display: flex; justify-content: space-between; color: var(--board-soft); font-size: 13px; letter-spacing: 0.01em; margin-bottom: 28px; }
49
+ .label b { color: var(--board-ink); font-weight: 500; }
50
+ header { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--rule); padding-bottom: 20px; }
51
+ header .name { font-size: 15px; font-weight: 600; }
52
+ header .what { color: var(--board-soft); }
53
+
54
+ .display .specimen {
55
+ font-family: var(--display); font-weight: var(--display-weight); text-transform: var(--display-case);
56
+ letter-spacing: var(--display-tracking); font-size: 168px; line-height: 0.9; overflow-wrap: anywhere;
57
+ }
58
+ .text { display: grid; grid-template-columns: 1fr 1fr; gap: 64px; align-items: end; }
59
+ .text .specimen { font-family: var(--body); font-weight: var(--body-weight); font-size: 132px; line-height: 0.95; letter-spacing: -0.02em; }
60
+ .text .glyphs { font-family: var(--body); font-size: 30px; line-height: 1.3; overflow-wrap: anywhere; }
61
+ .text .glyphs span { display: block; color: var(--board-soft); font-size: 15px; margin-top: 16px; line-height: 1.5; }
62
+
63
+ .swatches { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 16px; }
64
+ .swatch {
65
+ aspect-ratio: 1; border-radius: var(--r); corner-shape: squircle;
66
+ padding: 24px; display: flex; flex-direction: column; justify-content: space-between;
67
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
68
+ }
69
+ @supports (corner-shape: squircle) { .swatch { --r: 72px; } }
70
+ .swatch .n { font-size: 15px; font-weight: 600; }
71
+ .swatch .meta { display: flex; justify-content: space-between; align-items: end; font-size: 13px; }
72
+ .swatch .meta i { font-style: normal; opacity: 0.7; }
73
+
74
+ </style>
75
+ </head>
76
+ <body>
77
+ <main class="board" id="board"></main>
78
+ <script>
79
+ const data = JSON.parse(document.getElementById("identity").textContent);
80
+ const q = new URLSearchParams(location.search);
81
+ const roles = (c) => [].concat(c.role || []);
82
+ const hex = (h) => (/^#[0-9a-f]{3}$/i.test(h) ? "#" + [...h.slice(1)].map((c) => c + c).join("") : h).toUpperCase();
83
+ const lum = (h) => {
84
+ const v = [1, 3, 5].map((i) => parseInt(hex(h).slice(i, i + 2), 16) / 255).map((x) => (x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4));
85
+ return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
86
+ };
87
+ const esc = (s) => String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
88
+
89
+ const colours = data.colours.map((c) => ({ ...c, hex: hex(c.hex) }));
90
+
91
+ const root = document.documentElement.style;
92
+ root.setProperty("--display", `"${data.display.face}", ${data.display.fallback || "sans-serif"}`);
93
+ root.setProperty("--display-weight", data.display.weight || 400);
94
+ root.setProperty("--display-case", data.display.case && data.display.case !== "none" ? data.display.case : "none");
95
+ root.setProperty("--display-tracking", data.display.tracking || "0");
96
+ root.setProperty("--body", `"${data.body.face}", ${data.body.fallback || "sans-serif"}`);
97
+ root.setProperty("--body-weight", data.body.weight || 400);
98
+ root.setProperty("--n", colours.length);
99
+
100
+ const swatches = colours.map((c) => {
101
+ // The label ink that reads best on the swatch: whichever of the two has the higher contrast.
102
+ const ratio = (a, b) => (Math.max(lum(a), lum(b)) + 0.05) / (Math.min(lum(a), lum(b)) + 0.05);
103
+ const ink = ratio(c.hex, "#0B0B0B") >= ratio(c.hex, "#F5F5F5") ? "#0B0B0B" : "#F5F5F5";
104
+ return `<div class="swatch" style="background:${c.hex};color:${ink}">
105
+ <span class="n">${esc(c.name)}</span>
106
+ <span class="meta"><span>${c.hex}</span><i>${esc(roles(c).join(" · "))}</i></span></div>`;
107
+ }).join("");
108
+
109
+ const alphabet = "Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz 0123456789 &?!@";
110
+ document.getElementById("board").innerHTML = `
111
+ <header><span class="name">${esc(data.name)}</span><span class="what">Identity</span></header>
112
+ <section class="display"><div class="label"><span><b>Primary type</b> · ${esc(data.display.face)}</span><span>${esc(data.display.note || "Display")} · ${data.display.weight || 400}</span></div>
113
+ <div class="specimen">${esc(data.display.sample || data.name)}</div></section>
114
+ <section><div class="label"><span><b>Secondary type</b> · ${esc(data.body.face)}</span><span>${esc(data.body.note || "Text")} · ${data.body.weight || 400}</span></div>
115
+ <div class="text"><div class="specimen">${esc(data.body.face)}</div>
116
+ <div class="glyphs">${alphabet}<span>${esc(data.line)}</span></div></div></section>
117
+ <section><div class="label"><span><b>Colour</b></span><span>${colours.length} colours</span></div>
118
+ <div class="swatches">${swatches}</div></section>`;
119
+
120
+ // Faces: Google Fonts by name unless the identity gives a stylesheet. "ready" waits for each
121
+ // stylesheet, then for each face at each weight, so a capture never shows a fallback.
122
+ const sheets = [], wanted = [];
123
+ const sheet = (face, weights, css) => {
124
+ const link = document.createElement("link");
125
+ link.rel = "stylesheet";
126
+ link.href = css || `https://fonts.googleapis.com/css2?family=${encodeURIComponent(face).replace(/%20/g, "+")}:wght@${weights.join(";")}&display=block`;
127
+ sheets.push(new Promise((done) => ((link.onload = done), (link.onerror = done))));
128
+ document.head.appendChild(link);
129
+ for (const w of weights) wanted.push(`${w} 100px "${face}"`);
130
+ };
131
+ sheet(data.display.face, [data.display.weight || 400], data.display.css);
132
+ if (data.body.face !== data.display.face) sheet(data.body.face, [...new Set([data.body.weight || 400, 600])].sort(), data.body.css);
133
+ const loaded = Promise.all(sheets)
134
+ .then(() => Promise.all(wanted.map((f) => document.fonts.load(f).catch(() => []))))
135
+ .then(() => document.fonts.ready);
136
+ Promise.race([loaded, new Promise((r) => setTimeout(r, 6000))])
137
+ .then(() => { document.title = "ready"; });
138
+ </script>
139
+ </body>
140
+ </html>
@@ -2,10 +2,10 @@
2
2
  // Full-page capture. Unsticks fixed/sticky chrome first so Chrome does not
3
3
  // repeat the same fold. Node 22+. Uses an installed Chrome/Edge/Chromium.
4
4
  //
5
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg
6
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --review /tmp/name-review.jpg
7
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --clip x,y,w,h
8
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --clip-selector "main"
5
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name.jpg
6
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name.jpg --review /tmp/name-review.jpg
7
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name.jpg --clip x,y,w,h
8
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name.jpg --clip-selector "main"
9
9
  // node capture.mjs <url> --out /tmp/mobile.png --width 390
10
10
  // node capture.mjs http://localhost:3000/app --out /tmp/app.png --cookie "session=abc; theme=dark" --strict
11
11
  //
@@ -13,7 +13,7 @@
13
13
  // www) is named on stderr. With --strict that is exit 1, so a 0 means the
14
14
  // shot is of the page asked for.
15
15
  // node capture.mjs file:///abs/path/moodboard.html --out /tmp/moodboard.jpg
16
- // node capture.mjs file:///abs/path/shot.jpg --out design-exploration/<slug>/refs/name.jpg --clip x,y,w,h
16
+ // node capture.mjs file:///abs/path/shot.jpg --out .longbeard/design/moodboard/refs/name.jpg --clip x,y,w,h
17
17
  //
18
18
  // Before the shot it waits out loaders: until no loader covers the screen and
19
19
  // the screen is not one flat colour and the network is quiet, for at most --wait ms (15 s on the web,
@@ -27,19 +27,20 @@
27
27
  // start as the page opens, so the loader and the intro are in them. With
28
28
  // --scroll they start once it has loaded, and each frame scrolls half a
29
29
  // screen by the wheel, so scroll-driven motion plays.
30
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name-intro --frames 12
31
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name-scroll --frames 12 --every 400 --scroll
30
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name-intro --frames 12
31
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name-scroll --frames 12 --every 400 --scroll
32
32
  //
33
33
  // --click "css" clicks that element once the page has loaded, as a person
34
34
  // would. Alone it keeps the screen after the click (an open menu). With
35
35
  // --frames the first frame is before the click and the rest record what the
36
36
  // click does (a menu opening, a page transition).
37
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name-menu.jpg --click "button[aria-label*=menu i]"
38
- // node capture.mjs <url> --out design-exploration/<slug>/refs/name-menu-open --frames 10 --every 150 --click "header button"
39
- import { spawn, execSync } from "node:child_process";
37
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name-menu.jpg --click "button[aria-label*=menu i]"
38
+ // node capture.mjs <url> --out .longbeard/design/moodboard/refs/name-menu-open --frames 10 --every 150 --click "header button"
39
+ import { spawn } from "node:child_process";
40
40
  import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
41
41
  import { tmpdir } from "node:os";
42
- import { dirname, isAbsolute, join, resolve } from "node:path";
42
+ import { dirname, join, resolve } from "node:path";
43
+ import { fileURLToPath } from "node:url";
43
44
  import { inflateSync } from "node:zlib";
44
45
 
45
46
  const args = process.argv.slice(2);
@@ -47,6 +48,11 @@ const flag = (name, def) => {
47
48
  const i = args.indexOf(`--${name}`);
48
49
  if (i === -1) return def;
49
50
  const v = args[i + 1];
51
+ // A flag that needs a value and has none is a usage error, not a plain shot.
52
+ if (v === undefined || /^--[a-z]/.test(v)) {
53
+ console.error(`--${name} needs a value`);
54
+ process.exit(2);
55
+ }
50
56
  args.splice(i, 2);
51
57
  return v;
52
58
  };
@@ -73,7 +79,7 @@ const waitArg = flag("wait", "") || "";
73
79
  const width = Math.round(Number(flag("width", "1440")));
74
80
  if (!url || !/^(https?|file):\/\//.test(url) || !outArg) {
75
81
  console.error(
76
- 'usage: node capture.mjs <https://url | file:///path> --out design-exploration/<slug>/refs/name.jpg [--review /tmp/name-review.jpg] [--clip x,y,w,h | --clip-selector "css"] [--width 390] [--cookie "name=value; …"] [--strict] [--wait ms] [--click "css"] [--frames N [--every ms] [--scroll]]',
82
+ 'usage: node capture.mjs <https://url | file:///path> --out .longbeard/design/moodboard/refs/name.jpg [--review /tmp/name-review.jpg] [--clip x,y,w,h | --clip-selector "css"] [--width 390] [--cookie "name=value; …"] [--strict] [--wait ms] [--click "css"] [--frames N [--every ms] [--scroll]]',
77
83
  );
78
84
  process.exit(2);
79
85
  }
@@ -104,7 +110,8 @@ if ((frames || clickArg) && (reviewArg || clipArg || clipSelector)) {
104
110
  process.exit(2);
105
111
  }
106
112
  // A local page has no loader worth waiting for, so a sparse screen costs little.
107
- // A full page stops at 14000 px; our own files (a picker, a moodboard) can run longer.
113
+ // A full page stops at 14000 px; our own files (a picker, a moodboard) run to 30000 px a part,
114
+ // and a longer one is kept in parts (see below).
108
115
  const tallest = /^file:/.test(url) ? 30000 : 14000;
109
116
  const local = /^file:/.test(url) || /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(url);
110
117
  const maxWait = waitArg ? Number(waitArg) : local ? 2000 : 15000;
@@ -119,23 +126,26 @@ if (clipArg && clipSelector) {
119
126
  process.exit(2);
120
127
  }
121
128
 
122
- function projectRoot() {
123
- try {
124
- return execSync("git rev-parse --show-toplevel", { encoding: "utf8" }).trim();
125
- } catch {
126
- return process.cwd();
127
- }
128
- }
129
-
129
+ // A relative path is relative to the folder the command runs in.
130
130
  function resolveOut(path) {
131
- if (!path) return "";
132
- if (isAbsolute(path)) return path;
133
- return resolve(projectRoot(), path);
131
+ return path ? resolve(path) : "";
134
132
  }
135
133
 
136
134
  const out = resolveOut(outArg);
137
135
  const reviewOut = resolveOut(reviewArg);
138
136
 
137
+ // A page that is not there would otherwise be a black shot that looks like a result.
138
+ if (/^file:/.test(url)) {
139
+ let file = "";
140
+ try {
141
+ file = fileURLToPath(url.replace(/[?#].*$/, ""));
142
+ } catch {}
143
+ if (!file || !existsSync(file)) {
144
+ console.error(`no such file: ${file || url}`);
145
+ process.exit(1);
146
+ }
147
+ }
148
+
139
149
  function parseClip(s) {
140
150
  if (!s) return null;
141
151
  const parts = s.split(",").map((n) => Number(n.trim()));
@@ -155,6 +165,8 @@ const clip = parseClip(clipArg);
155
165
 
156
166
  function findChrome() {
157
167
  const env = process.env.CHROME_PATH;
168
+ // CHROME_PATH=none: run as if no browser were installed (a quick test run).
169
+ if (env === "none") return null;
158
170
  if (env && existsSync(env)) return env;
159
171
  const home = process.env.HOME || process.env.USERPROFILE || "";
160
172
  const local = process.env.LOCALAPPDATA || "";
@@ -200,6 +212,13 @@ const drop = () => {
200
212
  } catch {}
201
213
  };
202
214
  process.once("exit", drop);
215
+ // An interrupt or a harness timeout must not leave Chrome or its profile behind.
216
+ for (const [sig, code] of [["SIGINT", 130], ["SIGTERM", 143]]) {
217
+ process.once(sig, () => {
218
+ drop();
219
+ process.exit(code);
220
+ });
221
+ }
203
222
 
204
223
  proc = spawn(
205
224
  exe,
@@ -218,6 +237,10 @@ proc = spawn(
218
237
  ],
219
238
  { stdio: ["ignore", "ignore", "pipe"] },
220
239
  );
240
+ proc.on("error", (e) => {
241
+ console.error(`could not start ${exe}: ${e.message}`);
242
+ process.exit(1);
243
+ });
221
244
 
222
245
  let buf = "";
223
246
  const wsUrl = await new Promise((resolveWs, reject) => {
@@ -238,8 +261,15 @@ const wsUrl = await new Promise((resolveWs, reject) => {
238
261
 
239
262
  const ws = new WebSocket(wsUrl);
240
263
  await new Promise((res, rej) => {
241
- ws.onopen = res;
242
- ws.onerror = () => rej(new Error("CDP socket failed"));
264
+ const t = setTimeout(() => rej(new Error("CDP socket did not open")), 10000);
265
+ ws.onopen = () => {
266
+ clearTimeout(t);
267
+ res();
268
+ };
269
+ ws.onerror = () => {
270
+ clearTimeout(t);
271
+ rej(new Error("CDP socket failed"));
272
+ };
243
273
  });
244
274
  let nextId = 1;
245
275
  const pending = new Map();
@@ -257,6 +287,10 @@ ws.onmessage = (ev) => {
257
287
  inflight.delete(msg.params.requestId);
258
288
  lastNetwork = Date.now();
259
289
  }
290
+ // An alert, confirm or beforeunload prompt holds the page until it is answered.
291
+ if (msg.method === "Page.javascriptDialogOpening") {
292
+ send("Page.handleJavaScriptDialog", { accept: false }, msg.sessionId).catch(() => {});
293
+ }
260
294
  if (msg.id && pending.has(msg.id)) {
261
295
  const { resolve: ok, reject: bad } = pending.get(msg.id);
262
296
  pending.delete(msg.id);
@@ -264,6 +298,10 @@ ws.onmessage = (ev) => {
264
298
  else ok(msg.result);
265
299
  }
266
300
  };
301
+ // If Chrome goes away, every call waiting on it fails now, not at its time limit.
302
+ ws.onclose = () => {
303
+ for (const { reject: bad } of [...pending.values()]) bad(new Error("Chrome closed the connection"));
304
+ };
267
305
  const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
268
306
  const id = nextId++;
269
307
  return new Promise((resolveSend, reject) => {
@@ -455,18 +493,41 @@ async function settle() {
455
493
  // Clicks a consent button, which can be any element, or else strips a short
456
494
  // privacy notice. Rejecting comes first: a script has no use for tracking,
457
495
  // and accepting can start scripts that redraw the page.
458
- // A local page is a state someone set up on purpose, so it is left as it is.
496
+ // A local page is a state someone set up on purpose, so it is left as it is, and
497
+ // so is a record of motion (--frames): nothing there is cleaned up.
459
498
  const dismissConsent = () =>
460
499
  local ? Promise.resolve(false) : evalValue(`(() => {
461
- const accept = /^(accept( all)?( cookies)?|accept (and|&) close|agree|i agree|ok|okay|got it|allow( all)?( cookies)?|i understand|acepto|aceptar)$/i;
462
- const reject = /^(reject( all)?( cookies)?|decline( all)?|deny|only (essential|necessary)( cookies)?)$/i;
500
+ // The common consent tools first, by their own ids: reject, then accept.
501
+ const known = [
502
+ "#onetrust-reject-all-handler", "#CybotCookiebotDialogBodyButtonDecline", "#didomi-notice-disagree-button",
503
+ ".cky-btn-reject", "#cmplz-deny, .cmplz-deny", "[data-cookiefirst-action=reject]", ".iubenda-cs-reject-btn",
504
+ "#onetrust-accept-btn-handler", "#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll", "#didomi-notice-agree-button",
505
+ ".cky-btn-accept", ".cmplz-accept", "[data-cookiefirst-action=accept]", ".iubenda-cs-accept-btn",
506
+ ];
507
+ for (const sel of known) {
508
+ const el = document.querySelector(sel);
509
+ if (el && el.getClientRects().length) {
510
+ el.click();
511
+ return true;
512
+ }
513
+ }
514
+ const accept = /^(accept( all)?( cookies)?|accept (and|&) (close|continue)|agree|i agree|ok|okay|got it|allow( all)?( cookies)?|i understand|acepto|aceptar( todas?| todo| cookies)?|aceptar y (cerrar|continuar)|onartu( guztiak)?|accepter( tout)?|tout accepter|j'accepte|alle akzeptieren|akzeptieren|accetta( tutti)?|accetto|aceitar( todos)?)$/i;
515
+ const reject = /^(reject( all)?( cookies)?|decline( all)?|deny|only (essential|necessary)( cookies)?|rechazar( todas?| todo| cookies)?|denegar|ukatu( guztiak)?|refuser( tout)?|tout refuser|continuer sans accepter|alle ablehnen|ablehnen|rifiuta( tutti)?|rejeitar( todos)?)$/i;
463
516
  const clickable = [...document.querySelectorAll("button, [role=button], a, input[type=button], input[type=submit], [onclick], div, span")]
464
517
  .filter((el) => el.childElementCount <= 2 && el.getClientRects().length);
465
- // Only inside a notice about cookies or privacy, so a menu or a gate is never clicked.
518
+ // Only inside something that looks like a notice about cookies or privacy: a
519
+ // dialog, a layer fixed or sticky over the page, or one named like a banner.
520
+ // Never the page itself, so a short page that mentions privacy is not a notice.
521
+ const about = /cookie|consent|privacy|gdpr|datenschutz|privacidad|consentimiento|confidentialit|privacit/i;
522
+ const named = /cookie|consent|gdpr|privacy|banner|notice|popup|modal|dialog/i;
466
523
  const notice = (el) => {
467
- for (let up = el, i = 0; up && i < 8; up = up.parentElement, i++) {
524
+ for (let up = el, i = 0; up && up !== document.body && up !== document.documentElement && i < 8; up = up.parentElement, i++) {
468
525
  const t = up.innerText || "";
469
- if (t.length < 1500 && /cookie|consent|privacy|gdpr|datenschutz/i.test(t)) return true;
526
+ if (t.length >= 1500 || !about.test(t)) continue;
527
+ const pos = getComputedStyle(up).position;
528
+ const label = (typeof up.className === "string" ? up.className : "") + " " + up.id;
529
+ if (up.tagName === "DIALOG" || /^(dialog|alertdialog)$/.test(up.getAttribute("role") || "") ||
530
+ up.getAttribute("aria-modal") === "true" || pos === "fixed" || pos === "sticky" || named.test(label)) return true;
470
531
  }
471
532
  return false;
472
533
  };
@@ -513,7 +574,14 @@ async function clickOn(selector) {
513
574
  }
514
575
 
515
576
  const navigateStarted = Date.now();
516
- await page("Page.navigate", { url: target }, 40000);
577
+ // A page that cannot be reached comes back as Chrome's own error page, which would be saved as if
578
+ // it were the site: say so and stop.
579
+ const nav = await page("Page.navigate", { url: target }, 40000);
580
+ if (nav?.errorText && nav.errorText !== "net::ERR_ABORTED") {
581
+ console.error(`could not reach ${target}: ${nav.errorText}`);
582
+ drop();
583
+ process.exit(1);
584
+ }
517
585
 
518
586
  if (frames) {
519
587
  // The frames are the record of motion, so nothing is paused, unstuck or cleaned up.
@@ -523,10 +591,6 @@ if (frames) {
523
591
  if (scrollFrames || clickArg) {
524
592
  const why = await settle();
525
593
  if (why) console.error(`waited ${maxWait} ms: ${why}`);
526
- if (await dismissConsent()) {
527
- await sleep(800);
528
- await settle();
529
- }
530
594
  await sleep(600);
531
595
  t0 = Date.now();
532
596
  }
@@ -745,6 +809,26 @@ mkdirSync(dirname(out), { recursive: true });
745
809
  writeFileSync(out, Buffer.from(data, "base64"));
746
810
  console.log(out);
747
811
 
812
+ // A local page longer than one shot (a families board of hundreds) is kept whole, in parts:
813
+ // <out>-2, <out>-3 … each up to the same height, so nothing below the first part is lost.
814
+ const realHeight = Math.ceil(size.height || height);
815
+ if (clipBox && (shotClip.height < clipBox.height || shotClip.width < clipBox.width)) {
816
+ console.error(`the clip reaches past the page (${fullWidth}x${realHeight} px): kept ${shotClip.width}x${shotClip.height} px of ${clipBox.width}x${clipBox.height}`);
817
+ } else if (!clipBox && !/^file:/.test(url) && realHeight > fullHeight) {
818
+ console.error(`the page is ${realHeight} px, over the ${tallest} px limit: kept the first ${fullHeight} px`);
819
+ }
820
+ if (!clipBox && /^file:/.test(url) && realHeight > fullHeight) {
821
+ const parts = Math.min(10, Math.ceil(realHeight / tallest));
822
+ for (let i = 1; i < parts; i++) {
823
+ const y = i * tallest;
824
+ const { data: part } = await page("Page.captureScreenshot", { format, ...(format === "png" ? {} : { quality: 70 }), captureBeyondViewport: true, clip: { x: 0, y, width: fullWidth, height: Math.min(tallest, realHeight - y), scale: 1 } }, 60000);
825
+ const partOut = out.replace(/(\.[a-z]+)?$/i, (ext) => `-${i + 1}${ext || ".jpg"}`);
826
+ writeFileSync(partOut, Buffer.from(part, "base64"));
827
+ console.log(partOut);
828
+ }
829
+ if (realHeight > parts * tallest) console.error(`the page is ${realHeight} px: kept the first ${parts * tallest} px in ${parts} parts`);
830
+ }
831
+
748
832
  if (reviewOut) {
749
833
  // Side-by-side columns ~2800 px tall so a tall capture stays readable.
750
834
  // Real capture stays the single tall file; review is scratch only.
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env node
2
+ // The colour options of design-identity, made by rule, not picked by the agent: the
3
+ // chosen screen's ground and accent, even steps around each in OKLCH (lighter,
4
+ // darker, warmer, cooler), the family's own colours, and theirs. Every ground
5
+ // keeps the built ink where it reads, or else gets near-black or near-white, and an option that fails contrast is left
6
+ // out: 4.5:1 for text on a ground, 3:1 for an accent on its ground. --level AAA
7
+ // (the design brief's accessibility) asks 7:1 for text and 4.5:1 for an accent,
8
+ // which may carry large text; a mark such as a button's fill stays 3:1. No
9
+ // dependencies.
10
+ //
11
+ // node colours.mjs --ground "#f1ede4" --ink "#111111" --accent "#fe2601" \
12
+ // --family "#ebe4e0,#b6bc94,#fd3b19" --theirs "#2b4c7e" [--level AAA]
13
+ //
14
+ // Three choices only: the ground, the text colour (ink) and one accent. The
15
+ // ink has its own row, the built ink first: lighter, darker, warmer and cooler
16
+ // steps of it, near-black and near-white, each checked on the built ground.
17
+ //
18
+ // Prints one row per option: row, label, colour, ink (for grounds), contrast
19
+ // (cut, not rounded, to one place, so a ratio just under its need never prints as the need).
20
+ // --json prints the same as JSON, for a page that renders the rows.
21
+ //
22
+ // --roles: once the three are picked, every other role is derived by rule and
23
+ // checked, never chosen one by one: soft text, a hairline, the button's fill
24
+ // and label, a picture tone, and status (ok, warn, error) on the ground.
25
+ // node colours.mjs --roles --ground "#3b2416" --ink "#d8b98c" --accent "#e8643c"
26
+
27
+ const args = process.argv.slice(2);
28
+ const flag = (name) => {
29
+ const i = args.indexOf(`--${name}`);
30
+ return i === -1 ? "" : (args.splice(i, 2)[1] ?? "");
31
+ };
32
+ const json = args.includes("--json");
33
+ const rolesMode = args.includes("--roles");
34
+ const groundArg = flag("ground");
35
+ const inkArg = flag("ink");
36
+ const accentArg = flag("accent");
37
+ const familyArg = flag("family");
38
+ const theirsArg = flag("theirs");
39
+ const levelArg = (flag("level") || "AA").toUpperCase();
40
+ if (levelArg !== "AA" && levelArg !== "AAA") {
41
+ console.error("colours: --level is AA or AAA");
42
+ process.exit(2);
43
+ }
44
+ // What each kind of colour has to reach: text, an accent (which may carry large text), a mark.
45
+ const textNeed = levelArg === "AAA" ? 7 : 4.5;
46
+ const accentNeed = levelArg === "AAA" ? 4.5 : 3;
47
+ const markNeed = 3;
48
+ const cut = (v) => Math.floor(v * 10) / 10;
49
+ const hex6 = (v) => {
50
+ const s = String(v || "").trim().toLowerCase();
51
+ if (/^#[0-9a-f]{3}$/.test(s)) return `#${[...s.slice(1)].map((c) => c + c).join("")}`;
52
+ return /^#[0-9a-f]{6}$/.test(s) ? s : null;
53
+ };
54
+ const list = (v) => (v ? v.split(",").map(hex6).filter(Boolean) : []);
55
+ const ground = hex6(groundArg);
56
+ const ink = hex6(inkArg);
57
+ if (!ground || !ink) {
58
+ console.error('usage: node colours.mjs --ground "#rrggbb" --ink "#rrggbb" [--accent "#rrggbb"] [--family "#a,#b"] [--theirs "#c"] [--level AA|AAA] [--json]');
59
+ process.exit(2);
60
+ }
61
+ const accent = hex6(accentArg);
62
+
63
+ // sRGB and OKLCH, both ways. Out of gamut, chroma is reduced until the colour fits.
64
+ const toLin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
65
+ const toGam = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
66
+ const rgbOf = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
67
+ const hexOf = (rgb) => `#${rgb.map((c) => Math.round(Math.min(1, Math.max(0, c)) * 255).toString(16).padStart(2, "0")).join("")}`;
68
+ function oklch(hex) {
69
+ const [r, g, b] = rgbOf(hex).map(toLin);
70
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
71
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
72
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
73
+ const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
74
+ const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
75
+ const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
76
+ return [L, Math.hypot(A, B), ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360];
77
+ }
78
+ function fromOklch([L, C, H]) {
79
+ for (let c = C; c >= 0; c -= 0.005) {
80
+ const a = c * Math.cos((H * Math.PI) / 180), b = c * Math.sin((H * Math.PI) / 180);
81
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
82
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
83
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
84
+ const rgb = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
85
+ if (rgb.every((v) => v >= -0.0005 && v <= 1.0005)) return hexOf(rgb.map(toGam));
86
+ }
87
+ return hexOf([L, L, L].map(toGam));
88
+ }
89
+ // WCAG contrast.
90
+ const lum = (hex) => {
91
+ const [r, g, b] = rgbOf(hex).map(toLin);
92
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
93
+ };
94
+ const contrast = (a, b) => {
95
+ const [hi, lo] = [lum(a), lum(b)].sort((x, y) => y - x);
96
+ return (hi + 0.05) / (lo + 0.05);
97
+ };
98
+ // A step: lighter or darker by 0.06 in lightness; warmer or cooler by 20 degrees of hue toward
99
+ // orange (55) or blue (250), whichever way is shorter.
100
+ const toward = (h, target, by) => {
101
+ const d = ((target - h + 540) % 360) - 180;
102
+ return (h + Math.sign(d) * Math.min(by, Math.abs(d)) + 360) % 360;
103
+ };
104
+ const step = (hex, kind) => {
105
+ const [L, C, H] = oklch(hex);
106
+ if (kind === "lighter") return fromOklch([Math.min(0.99, L + 0.06), C, H]);
107
+ if (kind === "darker") return fromOklch([Math.max(0.02, L - 0.06), C, H]);
108
+ if (kind === "warmer") return fromOklch([L, Math.max(C, 0.02), toward(H, 55, 20)]);
109
+ return fromOklch([L, Math.max(C, 0.02), toward(H, 250, 20)]);
110
+ };
111
+
112
+ // A colour between two, in OKLCH: t of the way from a to b.
113
+ const mix = (a, b, t) => {
114
+ const [L1, C1, H1] = oklch(a), [L2, C2, H2] = oklch(b);
115
+ const dh = ((H2 - H1 + 540) % 360) - 180;
116
+ return fromOklch([L1 + (L2 - L1) * t, C1 + (C2 - C1) * t, (H1 + dh * t + 360) % 360]);
117
+ };
118
+ if (rolesMode) {
119
+ const r1 = cut;
120
+ const roles = [];
121
+ const role = (name, colour, on, need, rule) => roles.push({ role: name, colour, on, contrast: r1(contrast(colour, on)), need, rule, ok: contrast(colour, on) >= need });
122
+ role("text", ink, ground, textNeed, "the ink they picked");
123
+ // Soft text: the ink toward the ground, as far as it still reads at the text level.
124
+ let soft = ink;
125
+ for (let t = 0.05; t <= 0.6; t += 0.05) {
126
+ const c = mix(ink, ground, t);
127
+ if (contrast(c, ground) < textNeed) break;
128
+ soft = c;
129
+ }
130
+ role("soft text", soft, ground, textNeed, `the ink toward the ground, while it reads at ${textNeed}:1`);
131
+ role("hairline", mix(ink, ground, 0.8), ground, 1.2, "the ink, 20% over the ground: a line, not text");
132
+ // The button: the accent when it stands off the ground at 3:1 (a mark), else the ink; its label the
133
+ // ground or the ink, whichever reads on the fill.
134
+ const fill = accent && contrast(accent, ground) >= markNeed ? accent : ink;
135
+ role("button fill", fill, ground, markNeed, fill === ink ? "the ink: the accent is under 3:1 on the ground" : "the accent");
136
+ const label = [ground, ink].find((c) => c !== fill && contrast(c, fill) >= textNeed) || ["#111111", "#f7f7f5"].sort((a, b) => contrast(b, fill) - contrast(a, fill))[0];
137
+ role("button label", label, fill, textNeed, "the ground or the ink where it reads on the fill, else near-black or near-white");
138
+ // A picture tone: the ground's hue at low chroma, for duotones and the overlay under text on photos.
139
+ const [gL, , gH] = oklch(ground);
140
+ roles.push({ role: "picture tone", colour: fromOklch([gL < 0.5 ? 0.25 : 0.75, 0.04, gH]), rule: "the ground's hue, low colour: tone photos toward it, and lay it under text on a photo" });
141
+ // Status: green, amber and red at the lightness that reads on the ground at 3:1 (marks, not body text).
142
+ for (const [name, hue] of [["ok", 145], ["warn", 75], ["error", 25]]) {
143
+ const dark = oklch(ground)[0] < 0.5;
144
+ let found = null;
145
+ for (let L = dark ? 0.6 : 0.6; dark ? L <= 0.95 : L >= 0.2; L += dark ? 0.02 : -0.02) {
146
+ const c = fromOklch([L, 0.15, hue]);
147
+ if (contrast(c, ground) >= markNeed) { found = c; break; }
148
+ }
149
+ if (found) role(`status ${name}`, found, ground, markNeed, "its hue at the lightness that reads on the ground");
150
+ }
151
+ const failing = roles.filter((r) => r.ok === false);
152
+ if (json) console.log(JSON.stringify({ roles }, null, 1));
153
+ else {
154
+ for (const r of roles) console.log([r.role, r.colour, r.on || "", r.contrast ?? "", r.need ? `${r.need}:1` : "", r.rule].join("\t"));
155
+ }
156
+ for (const r of failing) console.error(`colours: ${r.role} ${r.colour} is ${r.contrast}:1 on ${r.on}, under ${r.need}:1`);
157
+ process.exit(failing.length ? 1 : 0);
158
+ }
159
+
160
+ const rows = [];
161
+ const seen = new Set();
162
+ const add = (row, label, colour, extra) => {
163
+ if (!colour || seen.has(`${row}${colour}`)) return;
164
+ seen.add(`${row}${colour}`);
165
+ rows.push({ row, label, colour, ...extra });
166
+ };
167
+ // Grounds: each with an ink. The built ink is part of the chosen look (tan on brown), so it stays
168
+ // wherever it reads; only where it fails does the ground take near-black or near-white, whichever
169
+ // reads best.
170
+ const inks = ["#111111", "#f7f7f5"];
171
+ const groundOption = (label, colour) => {
172
+ const own = contrast(ink, colour);
173
+ const best = own >= textNeed ? [ink, own] : inks.map((i) => [i, contrast(i, colour)]).sort((a, b) => b[1] - a[1])[0];
174
+ if (best[1] >= textNeed) add("ground", label, colour, { ink: best[0], contrast: cut(best[1]) });
175
+ };
176
+ groundOption("as built", ground);
177
+ groundOption("lighter", step(ground, "lighter"));
178
+ groundOption("darker", step(ground, "darker"));
179
+ groundOption("warmer", step(ground, "warmer"));
180
+ groundOption("cooler", step(ground, "cooler"));
181
+ const family = list(familyArg);
182
+ const theirs = list(theirsArg);
183
+ for (const c of family) if (oklch(c)[1] < 0.08) groundOption("the family's", c);
184
+ for (const c of theirs) groundOption("theirs", c);
185
+ // Ink: its own row, the built ink first, each on the built ground at the text level or out.
186
+ const inkOption = (label, colour) => {
187
+ const k = contrast(colour, ground);
188
+ if (k >= textNeed) add("ink", label, colour, { contrast: cut(k) });
189
+ };
190
+ inkOption("as built", ink);
191
+ for (const kind of ["lighter", "darker", "warmer", "cooler"]) inkOption(kind, step(ink, kind));
192
+ inkOption("near-black", "#111111");
193
+ inkOption("near-white", "#f7f7f5");
194
+ for (const c of theirs) inkOption("theirs", c);
195
+ // Accents: against the chosen ground, at the accent level or out.
196
+ const accentOption = (label, colour) => {
197
+ const k = contrast(colour, ground);
198
+ if (k >= accentNeed) add("accent", label, colour, { contrast: cut(k) });
199
+ };
200
+ if (accent) {
201
+ accentOption("as built", accent);
202
+ for (const kind of ["lighter", "darker", "warmer", "cooler"]) accentOption(kind, step(accent, kind));
203
+ }
204
+ for (const c of family) if (oklch(c)[1] >= 0.08) accentOption("the family's", c);
205
+ for (const c of theirs) accentOption("theirs", c);
206
+ add("accent", "none", "none", {});
207
+
208
+ const left = [...(accent && !rows.some((r) => r.row === "accent" && r.label === "as built") ? [`the built accent (under ${accentNeed}:1 on this ground)`] : [])];
209
+ if (json) console.log(JSON.stringify({ rows, left }, null, 1));
210
+ else {
211
+ for (const r of rows) console.log([r.row, r.label, r.colour, r.ink || "", r.contrast ?? ""].join("\t"));
212
+ for (const l of left) console.error(`colours: left out ${l}`);
213
+ }