@jonandev/longbeard 0.11.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/AGENTS.md +4 -5
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +64 -43
  4. package/beard.json +124 -28
  5. package/bin/long-beard.js +171 -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 +21 -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/framework-skills/SKILL.md +71 -0
  90. package/skills/idea/SKILL.md +13 -7
  91. package/skills/idea/references/graphic.md +64 -0
  92. package/skills/design/references/design-md-template.md +0 -58
  93. package/skills/design/scripts/contrast.mjs +0 -27
  94. package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
@@ -1,14 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  // A moodboard of the references, built to be marked: every card with a shot
3
- // or recorded frames, grouped by its topic (the part of the product it shows),
4
- // with Lead, Like and No, a note per tile, and a copy-out for the chat. The
3
+ // or recorded frames, grouped by its topic (the family it looks like, or the
4
+ // one piece it is for), with Lead, Like and No, a note per tile, and a
5
+ // copy-out for the chat. The
5
6
  // layout is this file. It shows what we saw. It does not paint a brand.
6
7
  //
7
8
  // A card's fields in board.md: link, shot, frames (a folder that
8
- // capture.mjs --frames wrote, played on hover), topic, pattern, why.
9
+ // capture.mjs --frames wrote, played on hover), topic (or part), pattern (or move), measured
10
+ // (its traits from measure.mjs, shown small under the pattern), why, like (the
11
+ // person's own words from the picker: what they like in it, and why; shown on
12
+ // the card and put in its note until they change it).
9
13
  //
10
- // node moodboard.mjs design-exploration/identity/board.md --out design-exploration/identity/moodboard.html
11
- // node moodboard.mjs design-exploration/pricing/board.md --out design-exploration/pricing/moodboard.html
14
+ // node moodboard.mjs .longbeard/design/moodboard/board.md --out .longbeard/design/moodboard/moodboard.html
15
+ // node moodboard.mjs .longbeard/design/pricing/board.md --out .longbeard/design/pricing/moodboard.html
16
+ //
17
+ // A big pool is chosen in two steps. --overview 6 shows each family as its
18
+ // first six tiles (families.mjs writes the most typical first), how many more
19
+ // it has, and its measured ranges from a "Families:" header line, with one
20
+ // Take button and a note per family. The copy-out lists the families taken.
21
+ // Then a board of only those families is marked as usual.
22
+ // node moodboard.mjs .longbeard/design/moodboard/board.md --overview 6 --out .longbeard/design/families/families.html
12
23
  import { execSync } from "node:child_process";
13
24
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
14
25
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
@@ -16,9 +27,15 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
16
27
  const args = process.argv.slice(2);
17
28
  const outAt = args.indexOf("--out");
18
29
  const outArg = outAt === -1 ? "" : (args.splice(outAt, 2)[1] ?? "");
30
+ const overAt = args.indexOf("--overview");
31
+ const overview = overAt === -1 ? 0 : Number(args.splice(overAt, 2)[1]);
32
+ if (overAt !== -1 && !(Number.isInteger(overview) && overview >= 1 && overview <= 24)) {
33
+ console.error("moodboard: --overview takes how many tiles to show per family, 1 to 24");
34
+ process.exit(2);
35
+ }
19
36
  const boardArg = args[0];
20
37
  if (!boardArg || !outArg || args.length !== 1) {
21
- console.error("usage: node moodboard.mjs design-exploration/<slug>/board.md --out design-exploration/<slug>/moodboard.html");
38
+ console.error("usage: node moodboard.mjs .longbeard/design/<step>/board.md --out .longbeard/design/<step>/moodboard.html");
22
39
  process.exit(2);
23
40
  }
24
41
 
@@ -46,8 +63,14 @@ const esc = (s) =>
46
63
  .replace(/>/g, "&gt;")
47
64
  .replace(/"/g, "&quot;")
48
65
  .replace(/'/g, "&#39;");
66
+ // A local path in a src or href: each part encoded, so # ? % and spaces stay in the name.
49
67
  const href = (abs) => {
50
- const src = relative(dirname(outPath), abs).split("\\").join("/");
68
+ const src = relative(dirname(outPath), abs)
69
+ .split("\\")
70
+ .join("/")
71
+ .split("/")
72
+ .map(encodeURIComponent)
73
+ .join("/");
51
74
  return src.startsWith(".") ? src : `./${src}`;
52
75
  };
53
76
 
@@ -64,7 +87,8 @@ function fieldsOf(text) {
64
87
  // (an app's key screen, say) keeps the order it first appears in on the board.
65
88
  const TOPICS = [
66
89
  ["Home", /^(home|homepage|landing|hero)$/],
67
- ["Navigation", /^(nav|navigation|menu|header)$/],
90
+ // "menu" is left out: for a restaurant or a bakery it is the list of dishes, not the navigation.
91
+ ["Navigation", /^(nav|navigation|nav menu|header)$/],
68
92
  ["Index", /^(index|listing|list|work|archive|grid|catalogue|catalog)$/],
69
93
  ["Case study", /^(case[ -]?stud(y|ies)|project|work detail)$/],
70
94
  ["Article", /^(article|editorial|reading|long[ -]?read|story)$/],
@@ -74,10 +98,10 @@ const TOPICS = [
74
98
  ];
75
99
  function topicOf(raw) {
76
100
  const t = String(raw || "").trim().toLowerCase();
77
- if (!t) return { label: "Other", rank: 1e6 };
101
+ if (!t) return { key: "", label: "Other", rank: 1e6 };
78
102
  const at = TOPICS.findIndex(([, re]) => re.test(t));
79
- if (at !== -1) return { label: TOPICS[at][0], rank: at };
80
- return { label: t.charAt(0).toUpperCase() + t.slice(1), rank: 1000 };
103
+ if (at !== -1) return { key: t, label: TOPICS[at][0], rank: at };
104
+ return { key: t, label: t.charAt(0).toUpperCase() + t.slice(1), rank: 1000 };
81
105
  }
82
106
 
83
107
  // Frames from capture.mjs --frames: 01-00000ms.jpg, 02-00500ms.jpg…
@@ -92,6 +116,13 @@ function framesOf(folder) {
92
116
  }
93
117
 
94
118
  const md = readFileSync(boardPath, "utf8");
119
+ // Ranges per family, from board.md's header: "Families: f1 (light · empty 55–70%) — 42; f2 (…) — 18".
120
+ const ranges = new Map();
121
+ const familiesLine = md.match(/^Families:\s*(.*)$/m)?.[1] || "";
122
+ for (const part of familiesLine.split(";")) {
123
+ const m = part.trim().match(/^(.+?)\s*\((.+)\)/);
124
+ if (m) ranges.set(m[1].trim().toLowerCase(), m[2].trim());
125
+ }
95
126
  const cards = md
96
127
  .split(/^### /m)
97
128
  .slice(1)
@@ -103,6 +134,9 @@ const cards = md
103
134
 
104
135
  const sections = new Map();
105
136
  let n = 0;
137
+ // A mark is saved under the card's name, so adding or dropping a card never
138
+ // moves a mark onto another. Two cards with one name tell apart by order.
139
+ const names = new Map();
106
140
  for (const card of cards) {
107
141
  const frames = card.frames ? framesOf(card.frames) : null;
108
142
  if (card.frames && !frames) console.error(`moodboard: no frames in ${card.frames.trim()}`);
@@ -115,17 +149,21 @@ for (const card of cards) {
115
149
  if (!poster && frames) poster = frames[frames.length - 1].src;
116
150
  if (!poster) continue;
117
151
  const id = `m${++n}`;
118
- const topic = topicOf(card.topic);
152
+ const seenName = (names.get(card.name) ?? 0) + 1;
153
+ names.set(card.name, seenName);
154
+ const markKey = seenName > 1 ? `${card.name} #${seenName}` : card.name;
155
+ const topic = topicOf(card.topic || card.part);
119
156
  // A seed shared in chat has no URL, so its name is not a link.
120
157
  const url = (card.link || "").trim().split(/\s+/)[0];
121
158
  const name = /^https?:\/\//i.test(url)
122
159
  ? `<a class="name" href="${esc(url)}" target="_blank" rel="noopener noreferrer">${esc(card.name)}</a>`
123
160
  : `<span class="name">${esc(card.name)}</span>`;
124
- const line = card.pattern ? `<p class="line">${esc(card.pattern)}</p>` : "";
161
+ const like = (card.like || "").trim();
162
+ const line = ((card.pattern || card.move) ? `<p class="line">${esc(card.pattern || card.move)}</p>` : "") + (card.measured ? `<p class="measured">${esc(card.measured)}</p>` : "") + (like ? `<p class="liked">You liked: ${esc(like)}</p>` : "");
125
163
  const play = frames
126
164
  ? `<button type="button" class="play" aria-label="Play ${esc(card.name)}">Play</button><span class="clock"></span>`
127
165
  : "";
128
- const tile = `<figure class="tile" data-id="${id}" data-title="${esc(card.name)}" data-topic="${esc(topic.label)}"${
166
+ const tile = `<figure class="tile" data-id="${id}" data-title="${esc(card.name)}" data-topic="${esc(topic.label)}" data-key="${esc(markKey)}"${like ? ` data-like="${esc(like)}"` : ""}${
129
167
  frames ? ` data-frames="${esc(JSON.stringify(frames))}"` : ""
130
168
  }>
131
169
  <div class="frame"><a class="open" href="${esc(poster)}" target="_blank" rel="noopener" aria-label="Open the shot of ${esc(card.name)}"><img src="${esc(poster)}" alt="${esc(card.name)}" loading="lazy"></a><span class="id">${id}</span>${play}</div>
@@ -139,8 +177,11 @@ for (const card of cards) {
139
177
  <input class="why" type="text" placeholder="Note (optional)" aria-label="Note on ${esc(card.name)}">
140
178
  </figcaption>
141
179
  </figure>`;
142
- if (!sections.has(topic.label)) sections.set(topic.label, { rank: topic.rank, order: sections.size, tiles: [] });
143
- sections.get(topic.label).tiles.push(tile);
180
+ // In the overview each family is its own section, named by its id as written (f1, not F1), so the
181
+ // copy-out names the list on disk (families/f1.tsv) and the board's Families: line finds its ranges.
182
+ const at = overview ? topic.key : topic.label;
183
+ if (!sections.has(at)) sections.set(at, { label: topic.label, key: topic.key, rank: topic.rank, order: sections.size, tiles: [] });
184
+ sections.get(at).tiles.push(tile);
144
185
  }
145
186
 
146
187
  if (!n) {
@@ -151,17 +192,25 @@ if (!n) {
151
192
  const ordered = [...sections.entries()].sort(([, a], [, b]) => a.rank - b.rank || a.order - b.order);
152
193
  const slug = (s) => `t-${s.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
153
194
  const jump = ordered
154
- .map(([label, s]) => `<a href="#${slug(label)}">${esc(label)} <span>${s.tiles.length}</span></a>`)
195
+ .map(([at, s]) => `<a href="#${slug(at)}">${esc(s.label)} <span>${s.tiles.length}</span></a>`)
155
196
  .join("");
156
197
  const body = ordered
157
- .map(
158
- ([label, s]) => `<section id="${slug(label)}">
159
- <h2>${esc(label)} <span>${s.tiles.length}</span></h2>
198
+ .map(([at, s]) => {
199
+ const { label, key } = s;
200
+ const shown = overview ? s.tiles.slice(0, overview) : s.tiles;
201
+ const more = s.tiles.length - shown.length;
202
+ const head = overview
203
+ ? `<h2>${esc(label)} <span>${s.tiles.length}</span></h2>
204
+ ${ranges.has(key) ? `<p class="ranges">${esc(ranges.get(key))}</p>` : ""}
205
+ <div class="take"><button type="button" class="fam" data-family="${esc(key || label)}" aria-pressed="false">Take this family</button><input class="fam-note" type="text" data-family="${esc(key || label)}" placeholder="Note (optional): two looks in one, belongs with another…" aria-label="Note on ${esc(label)}">${more ? `<span class="more">+${more} more not shown</span>` : ""}</div>`
206
+ : `<h2>${esc(label)} <span>${s.tiles.length}</span></h2>`;
207
+ return `<section id="${slug(at)}">
208
+ ${head}
160
209
  <div class="grid">
161
- ${s.tiles.join("\n ")}
210
+ ${shown.join("\n ")}
162
211
  </div>
163
- </section>`,
164
- )
212
+ </section>`;
213
+ })
165
214
  .join("\n ");
166
215
 
167
216
  const html = `<!DOCTYPE html>
@@ -206,6 +255,9 @@ const html = `<!DOCTYPE html>
206
255
  .name { font-size: 15px; line-height: 1.3; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
207
256
  a.name:hover { text-decoration: underline; }
208
257
  .line { margin: -4px 0 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
258
+ .measured { margin: -6px 0 0; font-size: 11px; line-height: 1.4; color: var(--muted); font-variant-numeric: tabular-nums; }
259
+ .liked { margin: -4px 0 0; font-size: 13px; line-height: 1.4; color: var(--like); }
260
+ [data-overview] .liked { display: none; }
209
261
  .marks { display: flex; gap: 6px; margin-top: auto; }
210
262
  .marks button { flex: 1; font: inherit; font-size: 13px; font-weight: 600; padding: 7px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }
211
263
  .marks button[data-mark="lead"][aria-pressed="true"] { background: var(--lead); border-color: var(--lead); color: #fff; }
@@ -221,15 +273,23 @@ const html = `<!DOCTYPE html>
221
273
  #out { background: #f6f6f4; }
222
274
  .side { display: flex; flex-direction: column; gap: 8px; padding-top: 22px; min-width: 150px; }
223
275
  #count { font-size: 13px; color: var(--muted); }
276
+ [data-overview] .marks, [data-overview] .why, [data-overview] .filters { display: none; }
277
+ .ranges { margin: -6px 0 10px 2px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
278
+ .take { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 12px 2px; }
279
+ .fam { font: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }
280
+ .fam[aria-pressed="true"] { background: var(--like); border-color: var(--like); color: #fff; }
281
+ .fam-note { flex: 1 1 260px; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
282
+ .more { font-size: 13px; color: var(--muted); }
224
283
  #copy { font: inherit; font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 0; background: var(--ink); color: var(--paper); cursor: pointer; }
225
284
  @media (max-width: 800px) { .bar-in { grid-template-columns: 1fr; } .side { padding-top: 0; } main { padding-bottom: 480px; } header { position: static; } }
226
285
  </style>
227
286
  </head>
228
- <body>
287
+ <body${overview ? " data-overview" : ""}>
229
288
  <main>
230
289
  <header>
231
- <h1>Moodboard</h1>
232
- <p class="how">Lead what should set the tone for its group (one per group: a part, or a direction), Like what belongs, No what feels wrong. Add a note where you have one. The picture opens the shot, the name opens the source, and Play runs recorded motion.</p>
290
+ <h1>${overview ? "Families" : "Moodboard"}</h1>
291
+ ${overview ? `<p class="how">Each family shows its most typical ${overview}. Take the ones you want to see in full, any number. Note a family that looks like two, or that belongs with another.</p>` : ""}
292
+ <p class="how"${overview ? " hidden" : ""}>Lead what should set the tone for its group (one per group: a part, or a direction), Like what belongs, No what feels wrong. Add a note where you have one; a tile in the wrong group gets the note "move to" and the group's name. The picture opens the shot, the name opens the source, and Play runs recorded motion.</p>
233
293
  <nav aria-label="Parts">${jump}</nav>
234
294
  <div class="filters" role="group" aria-label="Show">
235
295
  <button type="button" data-show="all" aria-pressed="true">All</button>
@@ -255,20 +315,51 @@ const html = `<!DOCTYPE html>
255
315
  const count = document.getElementById("count");
256
316
  let saved = {};
257
317
  try { saved = JSON.parse(localStorage.getItem(key) || "{}"); } catch (e) { saved = {}; }
258
- // Saved by id and title, so a card dropped and the board rebuilt never moves a mark.
259
- const tag = (t) => t.dataset.id + "|" + t.dataset.title;
318
+ // Saved under the card's name, so a card added or dropped and the board
319
+ // rebuilt never moves a mark. A mark an earlier board saved under a running
320
+ // number and the name is still read.
321
+ const tag = (t) => t.dataset.key;
322
+ const old = (t) => t.dataset.id + "|" + t.dataset.title;
260
323
  const marks = saved.marks || {};
261
324
  const notes = saved.notes || {};
325
+ const read = (from, t) => (tag(t) in from ? from[tag(t)] : from[old(t)]) || "";
262
326
  note.value = saved.note || "";
263
327
  for (const t of tiles) {
264
- if (marks[tag(t)]) t.dataset.state = marks[tag(t)];
265
- t.querySelector(".why").value = notes[tag(t)] || "";
328
+ const mark = read(marks, t);
329
+ if (mark) t.dataset.state = mark;
330
+ // Their words from the picker fill the note until they change it; a note they cleared stays cleared.
331
+ t.querySelector(".why").value = tag(t) in notes || old(t) in notes ? read(notes, t) : t.dataset.like || "";
266
332
  }
267
333
  let show = "all";
268
334
  const short = (s) => (s.length > 48 ? s.slice(0, 47) + "…" : s);
269
335
  const label = (t) => t.dataset.id + " " + short(t.dataset.title) + " (" + t.dataset.topic + ")";
270
336
  const list = (state) => tiles.filter((t) => t.dataset.state === state).map(label);
337
+ const fams = [...document.querySelectorAll(".fam")];
338
+ const famNotes = [...document.querySelectorAll(".fam-note")];
339
+ if (fams.length) {
340
+ const taken = new Set(saved.taken || []);
341
+ for (const b of fams) if (taken.has(b.dataset.family)) b.setAttribute("aria-pressed", "true");
342
+ for (const i of famNotes) i.value = (saved.famNotes || {})[i.dataset.family] || "";
343
+ }
344
+ function renderFamilies() {
345
+ const taken = fams.filter((b) => b.getAttribute("aria-pressed") === "true").map((b) => b.dataset.family);
346
+ const lines = ["Family picks", "take: " + (taken.join("; ") || "none")];
347
+ const written = famNotes.filter((i) => i.value.trim());
348
+ if (written.length) {
349
+ lines.push("notes:");
350
+ for (const i of written) lines.push("- " + i.dataset.family + ": " + i.value.trim().replace(/\\s+/g, " "));
351
+ }
352
+ if (note.value.trim()) lines.push("note: " + note.value.trim().replace(/\\s+/g, " "));
353
+ out.value = lines.join("\\n");
354
+ count.textContent = taken.length + " of " + fams.length + " families taken";
355
+ const keep = {};
356
+ for (const i of written) keep[i.dataset.family] = i.value;
357
+ try { localStorage.setItem(key, JSON.stringify({ taken, famNotes: keep, note: note.value })); } catch (e) {}
358
+ }
359
+ for (const b of fams) b.addEventListener("click", () => { b.setAttribute("aria-pressed", b.getAttribute("aria-pressed") === "true" ? "false" : "true"); render(); });
360
+ for (const i of famNotes) i.addEventListener("input", () => render());
271
361
  function render() {
362
+ if (fams.length) return renderFamilies();
272
363
  const lines = ["Moodboard picks", "lead: " + (list("lead").join("; ") || "none"), "like: " + (list("like").join("; ") || "none"), "no: " + (list("no").join("; ") || "none")];
273
364
  const written = tiles.filter((t) => t.querySelector(".why").value.trim());
274
365
  if (written.length) {
@@ -287,7 +378,7 @@ const html = `<!DOCTYPE html>
287
378
  t.hidden = !(show === "all" || (show === "open" ? !s : !!s));
288
379
  if (s) keepMarks[tag(t)] = s;
289
380
  const w = t.querySelector(".why").value;
290
- if (w.trim()) keepNotes[tag(t)] = w;
381
+ if (w.trim() || t.dataset.like) keepNotes[tag(t)] = w;
291
382
  }
292
383
  for (const sec of document.querySelectorAll("section")) sec.hidden = ![...sec.querySelectorAll(".tile")].some((t) => !t.hidden);
293
384
  try { localStorage.setItem(key, JSON.stringify({ marks: keepMarks, notes: keepNotes, note: note.value })); } catch (e) {}
@@ -298,7 +389,7 @@ const html = `<!DOCTYPE html>
298
389
  const mark = b.dataset.mark;
299
390
  if (t.dataset.state === mark) delete t.dataset.state;
300
391
  else {
301
- // One lead per group (a part, or a direction): a new lead turns the old one into a like.
392
+ // One lead per group (a family, or a piece): a new lead turns the old one into a like.
302
393
  if (mark === "lead") for (const o of tiles) if (o !== t && o.dataset.topic === t.dataset.topic && o.dataset.state === "lead") o.dataset.state = "like";
303
394
  t.dataset.state = mark;
304
395
  }
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env node
2
+ // A picture's colour, checked before it goes on a screen: a cast (a pink or
3
+ // green tint over what should be neutral), blown highlights, crushed
4
+ // shadows. A picture with a strong cast is replaced or corrected, unless its
5
+ // reference tones its pictures on purpose (a sepia, a duotone): then it is
6
+ // reported as toned, not as a fault. Node 22+, an installed Chrome, no
7
+ // dependencies.
8
+ //
9
+ // node picture-cast.mjs .longbeard/design/subject/loaf.jpg pictures/*.jpg
10
+ //
11
+ // It runs on the product's own pictures, not on a capture of a screen: a screen
12
+ // is mostly page ground and type, and says nothing about a picture's colour.
13
+ //
14
+ // How: each picture is drawn at most 512 px wide and read in OKLab. The cast
15
+ // is the mean tint of its near-neutral mid-tones (chroma under 0.045,
16
+ // lightness 0.25 to 0.9): what should be grey, white or stone shows the tint
17
+ // the whole picture has, while the subject's own colour (a brown crust, a
18
+ // red dress) is left out. With too few neutrals (under 3%), the mid-tones'
19
+ // mean tint is reported, marked "from mid-tones": the subject's own colour
20
+ // is in it, so it is never a fault on its own: look at the picture.
21
+ //
22
+ // A picture on a plain white or black ground (a product on a studio sweep, a
23
+ // cut-out) is not blown or crushed for its ground: when most of the picture's
24
+ // edge is one white or one black, that ground, the part of it that reaches the
25
+ // edge, is left out of every count, and blown and crushed are the share of the
26
+ // subject. A white highlight inside the subject still counts.
27
+ //
28
+ // Prints JSON, one entry per picture: { file, cast: "none|warm|red|magenta|
29
+ // cool|green", strength (OKLab distance from neutral, x100), toned (most of
30
+ // the picture in one hue at low chroma: a sepia, a duotone, black and
31
+ // white), mono, blown (share of pixels near white), crushed (share near
32
+ // black), ground: "white|black|none", from: "neutrals|mid-tones", fault }.
33
+ // fault is true for a cast of strength 3 or more, read from neutrals, on a
34
+ // picture that is not toned, or blown or crushed over 8%. A picture that
35
+ // cannot be read, or has nothing visible in it (all transparent), is
36
+ // { file, error }. Exit 0; 1 if any picture has an error; 2 on a usage error.
37
+ import { spawn } from "node:child_process";
38
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
39
+ import { tmpdir } from "node:os";
40
+ import { extname, join } from "node:path";
41
+ if (typeof WebSocket === "undefined") { console.error("Node 22+ is required."); process.exit(1); }
42
+
43
+ const fail = (text, code = 1) => {
44
+ console.error(`picture-cast: ${text}`);
45
+ process.exit(code);
46
+ };
47
+ const kinds = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp", ".gif": "image/gif", ".avif": "image/avif" };
48
+ const args = process.argv.slice(2);
49
+ if (!args.length || args.some((a) => a.startsWith("--"))) fail("usage: node picture-cast.mjs <image | folder> …", 2);
50
+ const files = [];
51
+ for (const a of args) {
52
+ if (!existsSync(a)) fail(`no file at ${a}`, 2);
53
+ if (statSync(a).isDirectory()) files.push(...readdirSync(a).filter((f) => kinds[extname(f).toLowerCase()]).sort().map((f) => join(a, f)));
54
+ else if (kinds[extname(a).toLowerCase()]) files.push(a);
55
+ else fail(`${a} is not a picture (jpg, png, webp, gif, avif)`, 2);
56
+ }
57
+ if (!files.length) fail("no pictures found", 2);
58
+
59
+ function findChrome() {
60
+ const env = process.env.CHROME_PATH;
61
+ // CHROME_PATH=none: run as if no browser were installed (a quick test run).
62
+ if (env === "none") return null;
63
+ if (env && existsSync(env)) return env;
64
+ const home = process.env.HOME || process.env.USERPROFILE || "";
65
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
66
+ return [
67
+ join(pf, "Google/Chrome/Application/chrome.exe"),
68
+ join(process.env.LOCALAPPDATA || "", "Google/Chrome/Application/chrome.exe"),
69
+ join(pf, "Microsoft/Edge/Application/msedge.exe"),
70
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
71
+ "/Applications/Chromium.app/Contents/MacOS/Chromium",
72
+ join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
73
+ "/usr/bin/google-chrome",
74
+ "/usr/bin/google-chrome-stable",
75
+ "/usr/bin/chromium",
76
+ "/usr/bin/chromium-browser",
77
+ ].find((path) => path && existsSync(path));
78
+ }
79
+ const exe = findChrome();
80
+ if (!exe) fail("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
81
+ const dir = mkdtempSync(join(tmpdir(), "picture-cast-"));
82
+ const proc = spawn(exe, ["--headless=new", "--remote-debugging-port=0", `--user-data-dir=${dir}`, "--no-first-run", "--force-color-profile=srgb", "about:blank"], { stdio: ["ignore", "ignore", "pipe"] });
83
+ const drop = () => {
84
+ try {
85
+ proc.kill("SIGKILL");
86
+ } catch {}
87
+ try {
88
+ rmSync(dir, { recursive: true, force: true });
89
+ } catch {}
90
+ };
91
+ process.once("exit", drop);
92
+ // An interrupt or a harness timeout must not leave Chrome or its profile behind.
93
+ for (const [sig, code] of [["SIGINT", 130], ["SIGTERM", 143]]) {
94
+ process.once(sig, () => {
95
+ drop();
96
+ process.exit(code);
97
+ });
98
+ }
99
+ proc.on("error", (e) => fail(`could not start ${exe}: ${e.message}`));
100
+ let buf = "";
101
+ const wsUrl = await new Promise((done, no) => {
102
+ const t = setTimeout(() => no(new Error("Chrome did not start")), 20000);
103
+ proc.stderr.on("data", (d) => {
104
+ const m = (buf += d).match(/DevTools listening on (ws:\/\/\S+)/);
105
+ if (m) done(m[1], clearTimeout(t));
106
+ });
107
+ proc.on("exit", (code) => no(new Error(`Chrome exited ${code}`)));
108
+ }).catch((e) => fail(e.message));
109
+ const ws = new WebSocket(wsUrl);
110
+ await new Promise((done, no) => {
111
+ const t = setTimeout(() => no(new Error("CDP socket did not open")), 10000);
112
+ ws.onopen = () => done(clearTimeout(t));
113
+ ws.onerror = () => no(new Error("CDP socket failed"));
114
+ }).catch((e) => fail(e.message));
115
+ let nextId = 0;
116
+ const pending = new Map();
117
+ ws.onmessage = (ev) => {
118
+ const msg = JSON.parse(String(ev.data));
119
+ if (pending.has(msg.id)) pending.get(msg.id)(msg), pending.delete(msg.id);
120
+ };
121
+ // If Chrome goes away, every call waiting on it fails now, not at its time limit.
122
+ ws.onclose = () => {
123
+ for (const done of [...pending.values()]) done({ error: { message: "Chrome closed the connection" } });
124
+ pending.clear();
125
+ };
126
+ // Every call has a time limit, so a picture that hangs the page fails alone.
127
+ const send = (method, params = {}, sessionId, timeoutMs = 30000) =>
128
+ new Promise((done, no) => {
129
+ const id = ++nextId;
130
+ const timer = setTimeout(() => (pending.delete(id), no(new Error(`Chrome did not answer ${method} in ${timeoutMs / 1000} s`))), timeoutMs);
131
+ pending.set(id, (msg) => done((clearTimeout(timer), msg)));
132
+ try {
133
+ ws.send(JSON.stringify({ id, method, params, sessionId }));
134
+ } catch (e) {
135
+ clearTimeout(timer);
136
+ pending.delete(id);
137
+ no(e);
138
+ }
139
+ });
140
+ const { result: target } = await send("Target.createTarget", { url: "about:blank" }).catch((e) => fail(e.message));
141
+ const { result: att } = await send("Target.attachToTarget", { targetId: target.targetId, flatten: true }).catch((e) => fail(e.message));
142
+ const evaluate = async (expression) => {
143
+ const r = await send("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: true }, att.sessionId);
144
+ if (r.error) throw new Error(r.error.message);
145
+ if (r.result?.exceptionDetails) throw new Error(r.result.exceptionDetails.exception?.description || "the page threw");
146
+ return r.result?.result?.value;
147
+ };
148
+
149
+ // Read in the page: the picture's pixels in OKLab, and the counts the verdict needs.
150
+ const read = (src) => `(async () => {
151
+ const img = new Image();
152
+ img.src = ${JSON.stringify(src)};
153
+ await img.decode();
154
+ const k = Math.min(1, 512 / img.width);
155
+ const w = Math.max(1, Math.round(img.width * k)), h = Math.max(1, Math.round(img.height * k));
156
+ const g = Object.assign(document.createElement("canvas"), { width: w, height: h }).getContext("2d", { willReadFrequently: true });
157
+ g.drawImage(img, 0, 0, w, h);
158
+ const d = g.getImageData(0, 0, w, h).data;
159
+ // A plain white or black ground: most of the edge is one of them. The ground is
160
+ // what reaches the edge in that colour (or in nothing, a transparent edge), not
161
+ // a highlight inside the subject.
162
+ const white = (i) => d[i] >= 235 && d[i + 1] >= 235 && d[i + 2] >= 235;
163
+ const black = (i) => d[i] <= 20 && d[i + 1] <= 20 && d[i + 2] <= 20;
164
+ let edge = 0, edgeWhite = 0, edgeBlack = 0;
165
+ const walk = (x, y) => {
166
+ const i = 4 * (y * w + x);
167
+ if (d[i + 3] < 128) return;
168
+ edge++;
169
+ if (white(i)) edgeWhite++;
170
+ else if (black(i)) edgeBlack++;
171
+ };
172
+ for (let x = 0; x < w; x++) walk(x, 0), walk(x, h - 1);
173
+ for (let y = 1; y < h - 1; y++) walk(0, y), walk(w - 1, y);
174
+ const ground = edge && edgeWhite >= edge * 0.7 ? "white" : edge && edgeBlack >= edge * 0.7 ? "black" : "none";
175
+ const isGround = new Uint8Array(w * h);
176
+ let groundCount = 0, visible = 0;
177
+ for (let i = 3; i < d.length; i += 4) if (d[i] >= 128) visible++;
178
+ if (ground !== "none") {
179
+ const same = ground === "white" ? white : black;
180
+ const stack = [];
181
+ const push = (x, y) => {
182
+ const at = y * w + x;
183
+ if (isGround[at]) return;
184
+ if (d[4 * at + 3] >= 128 && !same(4 * at)) return;
185
+ isGround[at] = 1;
186
+ if (d[4 * at + 3] >= 128) groundCount++;
187
+ stack.push(at);
188
+ };
189
+ for (let x = 0; x < w; x++) push(x, 0), push(x, h - 1);
190
+ for (let y = 0; y < h; y++) push(0, y), push(w - 1, y);
191
+ while (stack.length) {
192
+ const at = stack.pop(), x = at % w, y = (at - x) / w;
193
+ if (x > 0) push(x - 1, y);
194
+ if (x < w - 1) push(x + 1, y);
195
+ if (y > 0) push(x, y - 1);
196
+ if (y < h - 1) push(x, y + 1);
197
+ }
198
+ }
199
+ // With almost nothing but ground there is no subject to judge: the picture is judged whole.
200
+ const leave = ground !== "none" && visible - groundCount >= visible * 0.02;
201
+ const lin = (c) => ((c /= 255) <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
202
+ let n = 0, blown = 0, crushed = 0, nn = 0, na = 0, nb = 0, mn = 0, ma = 0, mb = 0, chromaSum = 0;
203
+ const hues = new Array(36).fill(0);
204
+ for (let i = 0; i < d.length; i += 4) {
205
+ if (d[i + 3] < 128) continue;
206
+ if (leave && isGround[i / 4]) continue;
207
+ n++;
208
+ const r = lin(d[i]), gg = lin(d[i + 1]), b = lin(d[i + 2]);
209
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * gg + 0.0514459929 * b);
210
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * gg + 0.1073969566 * b);
211
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * gg + 0.6299787005 * b);
212
+ const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
213
+ const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
214
+ const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
215
+ if (d[i] > 250 && d[i + 1] > 250 && d[i + 2] > 250) blown++;
216
+ if (d[i] < 10 && d[i + 1] < 10 && d[i + 2] < 10) crushed++;
217
+ const C = Math.hypot(A, B);
218
+ chromaSum += C;
219
+ if (C > 0.015) hues[Math.floor((((Math.atan2(B, A) * 180) / Math.PI + 360) % 360) / 10)] += 1;
220
+ if (L < 0.25 || L > 0.9) continue;
221
+ mn++, (ma += A), (mb += B);
222
+ if (C < 0.045) nn++, (na += A), (nb += B);
223
+ }
224
+ return { n, visible, ground: leave ? ground : "none", blown, crushed, nn, na, nb, mn, ma, mb, chroma: chromaSum / Math.max(1, n), hues };
225
+ })()`;
226
+
227
+ const results = [];
228
+ for (const file of files) {
229
+ const src = `data:${kinds[extname(file).toLowerCase()]};base64,${readFileSync(file).toString("base64")}`;
230
+ let r;
231
+ try {
232
+ r = await evaluate(read(src));
233
+ } catch (e) {
234
+ results.push({ file, error: `could not read: ${e.message.split("\n")[0]}` });
235
+ continue;
236
+ }
237
+ if (!r.visible) {
238
+ results.push({ file, error: "nothing visible: the picture is all transparent" });
239
+ continue;
240
+ }
241
+ const fromNeutrals = r.nn >= r.n * 0.03;
242
+ const [a, b] = fromNeutrals ? [r.na / r.nn, r.nb / r.nn] : r.mn ? [r.ma / r.mn, r.mb / r.mn] : [0, 0];
243
+ const strength = Math.round(Math.hypot(a, b) * 1000) / 10;
244
+ const hue = ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360;
245
+ const name = strength < 1.2 ? "none" : hue < 40 ? "red" : hue < 100 ? "warm" : hue < 190 ? "green" : hue < 290 ? "cool" : hue < 340 ? "magenta" : "red";
246
+ // Toned: the tinted pixels sit in one 60° band of hue, at low chroma (a sepia, a duotone), or there is no chroma at all.
247
+ const tinted = r.hues.reduce((s, v) => s + v, 0);
248
+ let band = 0;
249
+ for (let i = 0; i < 36; i++) band = Math.max(band, [0, 1, 2, 3, 4, 5].reduce((s, j) => s + r.hues[(i + j) % 36], 0));
250
+ const mono = r.chroma < 0.012;
251
+ const toned = mono || (tinted > r.n * 0.3 && band >= tinted * 0.9 && r.chroma < 0.06);
252
+ const share = (v) => Math.round((v / Math.max(1, r.n)) * 1000) / 10;
253
+ const blown = share(r.blown), crushed = share(r.crushed);
254
+ results.push({
255
+ file,
256
+ cast: name,
257
+ strength,
258
+ toned,
259
+ mono,
260
+ blown,
261
+ crushed,
262
+ ground: r.ground,
263
+ from: fromNeutrals ? "neutrals" : "mid-tones",
264
+ fault: (fromNeutrals && strength >= 3 && !toned) || blown > 8 || crushed > 8,
265
+ });
266
+ }
267
+ ws.close();
268
+ console.log(JSON.stringify(results, null, 1));
269
+ for (const r of results) if (r.error) console.error(`picture-cast: ${r.file}: ${r.error}`);
270
+ process.exit(results.some((r) => r.error) ? 1 : 0);