@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,67 @@
1
+ #!/usr/bin/env node
2
+ // Lay screenshots out as one numbered sheet, so a round of first screens can
3
+ // be seen and picked from together. It writes an HTML page; capture.mjs turns
4
+ // that into the picture to show. No dependencies.
5
+ //
6
+ // node sheet.mjs .longbeard/design/direction/grid/sheet.html .longbeard/design/direction/grid/1.png .longbeard/design/direction/grid/2.png …
7
+ // node sheet.mjs .longbeard/design/direction/grid/vary.html --cols 5 .longbeard/design/direction/grid/v*.png
8
+ // node capture.mjs "file://$PWD/.longbeard/design/direction/grid/sheet.html" --out .longbeard/design/direction/grid/sheet.png
9
+ // node sheet.mjs <out.html> --rough 1,2,4 --note "built without fresh agents: weaker" <shots…>
10
+ //
11
+ // --rough 1,2,4 (or none) labels those tiles "rough" and the rest "full", so a quick screen is never
12
+ // read as a finished one. --note prints a line under the sheet.
13
+
14
+ // Tiles are numbered in the order given, left to right, top to bottom, which
15
+ // is the recipe's number when the shots are passed in order.
16
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
17
+ import { dirname, relative, resolve } from "node:path";
18
+
19
+ const args = process.argv.slice(2);
20
+ const at = args.indexOf("--cols");
21
+ const cols = at === -1 ? 2 : Number(args.splice(at, 2)[1]);
22
+ const take = (name) => {
23
+ const i = args.indexOf(name);
24
+ return i === -1 ? null : (args.splice(i, 2)[1] ?? "");
25
+ };
26
+ const roughArg = take("--rough");
27
+ const note = take("--note");
28
+ const rough = new Set((roughArg ?? "").split(",").filter((n) => n && n !== "none").map(Number));
29
+ const [outArg, ...shots] = args;
30
+ if (!outArg || [...rough].some((n) => !Number.isInteger(n) || n < 1) || roughArg === "" || note === "" || !/\.html$/.test(outArg) || !shots.length || !Number.isInteger(cols) || cols < 1 || cols > 8) {
31
+ console.error('usage: node sheet.mjs <out.html> [--cols 2] [--rough 1,2|none] [--note "text"] <shot.png> …');
32
+ process.exit(2);
33
+ }
34
+ const out = resolve(outArg);
35
+ for (const shot of shots) {
36
+ if (!existsSync(resolve(shot))) {
37
+ console.error(`sheet: no file at ${shot}`);
38
+ process.exit(1);
39
+ }
40
+ }
41
+ const escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
42
+ // A local path in a src: each part encoded, so # ? % and spaces stay in the name.
43
+ const urlPath = (path) => path.split("/").map(encodeURIComponent).join("/");
44
+ const tiles = shots
45
+ .map((shot, i) => `<figure><img src="${escape(urlPath(relative(dirname(out), resolve(shot)).split("\\").join("/")))}" alt="Screen ${i + 1}"><figcaption>${i + 1}${roughArg === null ? "" : rough.has(i + 1) ? " · rough" : " · full"}</figcaption></figure>`)
46
+ .join("\n");
47
+ mkdirSync(dirname(out), { recursive: true });
48
+ writeFileSync(
49
+ out,
50
+ `<!doctype html>
51
+ <meta charset="utf-8">
52
+ <title>Sheet</title>
53
+ <style>
54
+ body { margin: 0; padding: 24px; background: #6f6f6f; font: 600 22px/1 system-ui, sans-serif; }
55
+ main { display: grid; grid-template-columns: repeat(${cols}, 720px); gap: 24px; width: max-content; }
56
+ figure { margin: 0; display: flex; flex-direction: column-reverse; gap: 8px; }
57
+ img { display: block; width: 720px; height: auto; }
58
+ /* The number sits above the screen, never on it: a corner of a screen is where its name or menu is. */
59
+ p { margin: 24px 0 0; max-width: 1200px; font-weight: 400; font-size: 20px; line-height: 1.4; color: #fff; }
60
+ figcaption { align-self: flex-start; min-width: 44px; padding: 8px 10px; text-align: center; background: #111; color: #fff; }
61
+ </style>
62
+ <main>
63
+ ${tiles}
64
+ </main>
65
+ ${note ? `<p>${escape(note)}</p>\n` : ""}`,
66
+ );
67
+ console.log(`${shots.length} screens, ${cols} across: ${outArg}`);
@@ -11,9 +11,9 @@ description: >
11
11
 
12
12
  # Idea
13
13
 
14
- One file comes out: `docs/brief.md`, about 500 words, one page. Every later stage reads it: `design-direction` for the people, surface, position and identity nouns, `design` for the key screens, `to-spec` for the flows. No stage asks for these again, so the brief has to settle them.
14
+ One file comes out: `docs/brief.md`, about 500 words, one page. Every later stage reads it: the design-* skills for the people, surface, position, identity nouns and key screens, `to-spec` for the flows. No stage asks for these again, so the brief has to settle them.
15
15
 
16
- The brief says what and for whom, never how. No framework, database, host or library. Those are Architecture's.
16
+ The brief says what and for whom, never how. No framework, database, host or library. Those are Architecture's. And never how it looks: no layout, colour, typeface, named style or page furniture. Those are chosen in Design, on rendered screens, and a brief that describes a look decides it before anyone has seen it.
17
17
 
18
18
  ## Gate
19
19
 
@@ -24,6 +24,8 @@ Look at the repo. Do not ask what is there.
24
24
  3. No brief, and the repo has code or a README → **Existing project**.
25
25
  4. Otherwise → **New idea**.
26
26
 
27
+ The idea is a piece to look at, not a product to use (a poster, a card, a social post): read [graphic.md](references/graphic.md) first.
28
+
27
29
  ## New idea
28
30
 
29
31
  Load Matt's `grilling` and run it. The design tree is the brief's sections below. Start with the frontier: a working name, problem, who it is for, surface. Flows, screens, position and scope hang off those. A working name is enough; it can change.
@@ -68,7 +70,7 @@ Read the brief. Grill only what changes and what hangs off it: a new surface reo
68
70
  <2–4. The screens design prototypes first. No UI: "none".>
69
71
 
70
72
  ## Surface
71
- <site | app | no UI (CLI, API, library)>. <One line why. A site is the page a person lands on to understand or choose; an app is the tool they come back to.>
73
+ <site | app | graphic | no UI (CLI, API, library)>. <One line why. A site is the page a person lands on to understand or choose; an app is the tool they come back to.>
72
74
 
73
75
  ## V1 and later
74
76
  - v1: <what ships first, as flows from above>
@@ -92,22 +94,26 @@ Read the brief. Grill only what changes and what hangs off it: a new surface reo
92
94
  - Every section has content. "None" is an answer. A guess is not.
93
95
  - **Changes** is added under Out of scope by the first Change, never before.
94
96
  - Position is concrete. "Fast, simple, trustworthy" says nothing every rival would not say. `remembered for` is a thing you could point at on a screen or in a sentence; `against` names real products or habits.
95
- - Content is real: the longest names the people will type, the likely numbers, the real empty case. `design` uses them as copy.
97
+ - Content is real: the longest names the people will type, the likely numbers, the real empty case. `design-prototype` uses them as copy.
98
+ - A screen is described by what is on it and what it is for, never by how it is arranged or styled. `remembered for` is a thing the product has or does, in the product's own words. If they describe a look while being grilled, keep it out of the brief and tell them it belongs in `design-brief`, which asks it next.
96
99
  - Over a page means a flow is really two products, or a section is doing Architecture's job. Cut it.
97
100
 
98
101
  ## After writing
99
102
 
100
- Offer the next stage in one line. A stage whose file already exists is done, so go past it:
103
+ Offer the next stage in one line, from the stages the router lists. A stage whose file already exists is done, so go past it:
101
104
 
102
- - Site or app, no `DESIGN.md` → `design-direction`.
103
- - No UI, or `DESIGN.md` exists → stages 2 and 3 are skipped. Next is Architecture: they type `/grill-with-docs`.
105
+ - Site, app or graphic, no `DESIGN.md` → `design`, which suggests the first design skill (`design-brief`).
106
+ - No UI, or `DESIGN.md` exists → Design is skipped. Next is Architecture: they type `/grill-with-docs`.
104
107
  - `GLOSSARY.md` exists too → next is Plan: they type `/to-spec` for the first flow or feature.
105
108
 
109
+ With no Architecture stage in the router (a design-only install), the next stage is `design` for a site or app. Otherwise the brief is the result.
110
+
106
111
  Do not start it until they say so.
107
112
 
108
113
  ## Do not
109
114
 
110
115
  - Pick a stack, or write a requirement as one ("uses Postgres").
116
+ - Describe a look: a layout, a colour, a typeface, a style by name.
111
117
  - Ask a question the repo or the idea already answers.
112
118
  - Write the brief before they confirm the seven-line summary.
113
119
  - Edit the brief for a feature. Features get specs.
@@ -0,0 +1,64 @@
1
+ # A graphic
2
+
3
+ Read when the idea is a piece to look at, not a product to use: a poster, a card or invitation, a social post, a cover. Everything in `SKILL.md` holds except what is said here. A piece counts as a screen wherever a skill says screen.
4
+
5
+ The kind is said once, here, on the brief's `surface` line, and no later skill asks it again.
6
+
7
+ ## What changes
8
+
9
+ - **Do not ask for flows or key screens.** A piece has none.
10
+ - **Ask for four things:** what it is for, who sees it and where, the facts it must carry, and the format.
11
+ - **One round, two at most.** Start with what the idea gives and recommend the rest. A birthday card needs a few lines, not a page.
12
+ - **Facts first.** The facts are what, when, where, who, and a link or a code if there is one. Each is given, or marked missing. A missing fact is never invented: it is written "missing" and stays in the brief until they supply it.
13
+ - **Format.** A size (a paper size, or pixels), portrait or landscape, print or screen. For a set (a poster with a story and a square version), list each piece with its size. A single piece is one line.
14
+ - **A set or a single piece.** Ask only if the idea does not say.
15
+
16
+ ## The brief
17
+
18
+ About 250 words. The headings the design skills read by name stay; flows, key screens and v1 are replaced.
19
+
20
+ ```markdown
21
+ # <Piece name>
22
+
23
+ <One sentence: what it is, and for whom.>
24
+
25
+ ## What it is for
26
+ <The one thing it makes someone do or feel, in two sentences. The cost of it going unseen.>
27
+
28
+ ## Seen by
29
+ <Who sees it, where, and from how far: a street, a phone feed, a hand.>
30
+
31
+ ## Must carry
32
+ - what: <…>
33
+ - when: <…, or "missing">
34
+ - where: <…, or "missing">
35
+ - who: <…>
36
+ - link or code: <…, or "none">
37
+
38
+ ## Format
39
+ - <size, portrait or landscape, print or screen>
40
+ - <for a set, one line per piece>
41
+
42
+ ## Surface
43
+ graphic. <One line why: a piece to look at, not a tool to use.>
44
+
45
+ ## Constraints
46
+ - <What is fixed: a deadline, a budget, a logo or colours they own. Not tech choices and not a look.>
47
+
48
+ ## Position
49
+ - against: <what pieces of its kind usually look like, or "none: a personal piece">
50
+ - remembered for: <one concrete thing someone would describe to a friend>
51
+ - personality: <three adjectives>. Says: "<a line it would say>". Never: "<a line it would never say>"
52
+
53
+ ## Identity nouns
54
+ <4–8 concrete nouns from its world.>
55
+
56
+ ## Out of scope
57
+ - <What it will not do or carry.>
58
+ ```
59
+
60
+ Every section has content. "None" is an answer. A guess is not. The brief names no look, as in any brief.
61
+
62
+ ## After writing
63
+
64
+ Offer `design` in one line. A graphic's run ends at its exported Figma frame: never offer Architecture or Plan, even though no `GLOSSARY.md` exists.
@@ -1,58 +0,0 @@
1
- # DESIGN.md template
2
-
3
- Write the whole file once, from the approved prototype. A builder follows it without the prototype or the references open. Short lines. Our words, never a reference's name.
4
-
5
- ```markdown
6
- # Design
7
-
8
- Figma: <file URL>. Figma is the truth for screens. This file is the rules behind them.
9
-
10
- ## Idea
11
- <one sentence: what this product's look says>
12
- - ownable: <the one element made from the product's own identity, as approved on the prototype>
13
-
14
- ## Voice
15
- - <three adjectives>
16
- - <one sample line, and one line it would never say>
17
-
18
- ## Colour
19
- | Token | Value | Use |
20
- |---|---|---|
21
- | color/bg | #… | page ground |
22
- | color/ink | #… | body text |
23
- | … | | |
24
-
25
- Contrast (scripts/contrast.mjs):
26
- - color/ink on color/bg: <ratio> <AA | AAA>
27
- - <every text, control and focus pair>
28
-
29
- ## Type
30
- | Token | Face, weight | Size / line height | Use |
31
- |---|---|---|---|
32
- | type/heading | … | …/… | screen titles |
33
- | type/body | … | …/… | body, lists |
34
-
35
- - Licence: <covers how this ships: web, app bundle>
36
-
37
- ## Spacing
38
- - Scale: <space/sm 8, space/md 16, …>
39
- - <how the scale is used: inside components, between items, between groups, between sections>
40
- - Corner radius: <value, and where>
41
-
42
- ## Components
43
- - <component>: <what it is for, its variants, its states>
44
-
45
- ## Imagery
46
- - <what the pictures are and how they are treated, or "none">
47
-
48
- ## Decisions
49
- - <date>: <what was decided> — <the reason>. <Soft rule overridden, if any: rule number and why>
50
-
51
- ## Do not
52
- - <what we leave, as ideas: "a bright brand accent", never whose>
53
- ```
54
-
55
- - Every token name is its code name, and the same name in Figma.
56
- - Every colour pair in the table has been through `scripts/contrast.mjs`. No FAIL is written.
57
- - More than one theme: one row per token, with a value column per theme. Every pair is checked in each theme.
58
- - A section with nothing to say is left out, not filled with a guess.
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
- // WCAG 2.x contrast for colour pairs.
3
- // node contrast.mjs "#2c2824 on #f6f1e7" "#b0563a on #f6f1e7:mark"
4
- // Suffix :large or :mark checks against 3:1 instead of 4.5:1.
5
- const lum = (hex) => {
6
- const [r, g, b] = [1, 3, 5]
7
- .map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
8
- .map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
9
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
10
- };
11
- let failed = false;
12
- for (const arg of process.argv.slice(2)) {
13
- const m = arg.match(/^(#[0-9a-f]{6})\s+on\s+(#[0-9a-f]{6})(?::(large|mark))?$/i);
14
- if (!m) {
15
- console.error(`skip: ${arg}`);
16
- continue;
17
- }
18
- const [a, b] = [lum(m[1]), lum(m[2])];
19
- const ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
20
- const need = m[3] ? 3 : 4.5;
21
- const verdict = ratio >= 7 && !m[3] ? "AAA" : ratio >= need ? "AA" : "FAIL";
22
- if (verdict === "FAIL") failed = true;
23
- console.log(
24
- `${m[1]} on ${m[2]} ${ratio.toFixed(2)}:1 ${verdict}${m[3] ? ` (${m[3]}, needs 3:1)` : ""}`,
25
- );
26
- }
27
- process.exit(failed ? 1 : 0);
@@ -1,356 +0,0 @@
1
- #!/usr/bin/env node
2
- // List Dribbble search/popular cards from a listing URL.
3
- // Headless Chrome; prints TSV: id-slug\tlikes\tviews\tdesigner\timageURL\ttitle
4
- // Counts come from the card's own stat elements. A column it cannot read
5
- // stays empty. It never guesses a count from the title.
6
- //
7
- // Dribbble's "popular" order mixes likes with recency, so page order is not
8
- // quality. Rows come out sorted by likes, most first, and a card under
9
- // --min-likes (default 100) is dropped. A card whose likes cannot be read
10
- // is kept, last.
11
- //
12
- // Off-topic cards (merch, resumes, worksheets, posters) are dropped by slug
13
- // and title before anything is fetched, and the noise rate goes to stderr.
14
- //
15
- // node dribbble-cards.mjs "https://dribbble.com/search/shots/popular/product-design?q=writing+app&timeframe=year" --scrolls 4
16
- // node dribbble-cards.mjs "<url>" --drop "mood,habit" --keep "font,illustration"
17
- // node dribbble-cards.mjs "<url>" --min-likes 300
18
- // node dribbble-cards.mjs "<url>" --picker >> candidates.tsv # rows for picker.mjs
19
- import { spawn } from "node:child_process";
20
- import { existsSync, mkdtempSync, rmSync } from "node:fs";
21
- import { tmpdir } from "node:os";
22
- import { join } from "node:path";
23
-
24
- const args = process.argv.slice(2);
25
- const flag = (name, def) => {
26
- const i = args.indexOf(`--${name}`);
27
- if (i === -1) return def;
28
- const v = args[i + 1];
29
- args.splice(i, 2);
30
- return v;
31
- };
32
- const has = (name) => {
33
- const i = args.indexOf(`--${name}`);
34
- if (i === -1) return false;
35
- args.splice(i, 1);
36
- return true;
37
- };
38
- const url = args[0];
39
- const scrolls = Math.max(0, Number(flag("scrolls", "3")) || 3);
40
- const noFilter = has("no-filter");
41
- const forPicker = has("picker");
42
- const minLikes = Math.max(0, Number(flag("min-likes", "100")) || 0);
43
- const words = (s) =>
44
- String(s || "")
45
- .toLowerCase()
46
- .split(",")
47
- .map((w) => w.trim())
48
- .filter(Boolean);
49
- // The shared negative list. These sell the word, not the form: a search for
50
- // "writing app" returns tees, CV services and tracing worksheets.
51
- const OFF_TOPIC = [
52
- "t-shirt", "tshirt", "tee", "merch", "apparel", "hoodie",
53
- "resume", "cv", "cover letter", "essay",
54
- "worksheet", "tracing", "handwriting practice", "alphabet",
55
- "halloween", "christmas", "valentine",
56
- "logo", "logotype", "branding", "brand identity", "packaging",
57
- "poster", "book cover", "sticker", "mockup",
58
- "chatbot", "mood tracker", "habit tracker",
59
- // "Editor" on Dribbble is mostly code, video, and photo tools and AI products.
60
- "video editor", "photo editor", "code editor", "ide",
61
- "agent", "assistant", "copilot", "generator",
62
- "dashboard", "saas", "crm",
63
- ];
64
- const keep = words(flag("keep", ""));
65
- const dropWords = [...OFF_TOPIC.filter((w) => !keep.includes(w)), ...words(flag("drop", ""))];
66
- if (!url || !/^https?:\/\/(www\.)?dribbble\.com\//i.test(url)) {
67
- console.error(
68
- 'usage: node dribbble-cards.mjs "https://dribbble.com/search/..." [--scrolls 4] [--min-likes 100] [--drop "a,b"] [--keep "a,b"] [--no-filter] [--picker]',
69
- );
70
- process.exit(2);
71
- }
72
-
73
- // Whole words only, so "ai" does not swallow "detail" and "cv" does not
74
- // swallow "cvs". A hyphen in a slug counts as a space.
75
- function offTopic(text) {
76
- const hay = ` ${String(text).toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
77
- return dropWords.find((word) => hay.includes(` ${word.replace(/[^a-z0-9]+/g, " ")} `)) || "";
78
- }
79
-
80
- // "15.7k" -> 15700. An unreadable count is NaN, never 0.
81
- function count(text) {
82
- const m = String(text || "").replace(/,/g, "").match(/^([\d.]+)([kKmM]?)$/);
83
- if (!m) return NaN;
84
- const n = Number(m[1]) * ({ k: 1e3, m: 1e6 }[m[2].toLowerCase()] || 1);
85
- return Number.isFinite(n) ? n : NaN;
86
- }
87
-
88
- function findChrome() {
89
- const env = process.env.CHROME_PATH;
90
- if (env && existsSync(env)) return env;
91
- const home = process.env.HOME || process.env.USERPROFILE || "";
92
- const local = process.env.LOCALAPPDATA || "";
93
- const pf = process.env.PROGRAMFILES || "C:\\Program Files";
94
- const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
95
- const candidates = [
96
- join(pf, "Google/Chrome/Application/chrome.exe"),
97
- join(pf86, "Google/Chrome/Application/chrome.exe"),
98
- join(local, "Google/Chrome/Application/chrome.exe"),
99
- join(pf, "Microsoft/Edge/Application/msedge.exe"),
100
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
101
- "/Applications/Chromium.app/Contents/MacOS/Chromium",
102
- "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
103
- join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
104
- "/usr/bin/google-chrome",
105
- "/usr/bin/google-chrome-stable",
106
- "/usr/bin/chromium",
107
- "/usr/bin/chromium-browser",
108
- ];
109
- return candidates.find((path) => path && existsSync(path)) || null;
110
- }
111
-
112
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
113
- const exe = findChrome();
114
- if (!exe) {
115
- console.error("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
116
- process.exit(1);
117
- }
118
- if (typeof WebSocket === "undefined") {
119
- console.error("Node 22+ is required.");
120
- process.exit(1);
121
- }
122
-
123
- const dir = mkdtempSync(join(tmpdir(), "hunt-dribbble-"));
124
- let proc;
125
- const drop = () => {
126
- try {
127
- if (proc?.pid) process.kill(proc.pid, "SIGKILL");
128
- } catch {}
129
- try {
130
- rmSync(dir, { recursive: true, force: true });
131
- } catch {}
132
- };
133
- process.once("exit", drop);
134
-
135
- proc = spawn(
136
- exe,
137
- [
138
- "--headless=new",
139
- "--remote-debugging-port=0",
140
- `--user-data-dir=${dir}`,
141
- "--no-first-run",
142
- "--hide-scrollbars",
143
- "--mute-audio",
144
- "--force-color-profile=srgb",
145
- "--window-size=1440,900",
146
- "about:blank",
147
- ],
148
- { stdio: ["ignore", "ignore", "pipe"] },
149
- );
150
-
151
- let buf = "";
152
- const wsUrl = await new Promise((resolveWs, reject) => {
153
- const t = setTimeout(() => reject(new Error("Chrome did not start")), 20000);
154
- proc.stderr.on("data", (d) => {
155
- buf += d.toString();
156
- const m = buf.match(/DevTools listening on (ws:\/\/[^\s]+)/);
157
- if (m) {
158
- clearTimeout(t);
159
- resolveWs(m[1]);
160
- }
161
- });
162
- proc.on("exit", (code) => {
163
- clearTimeout(t);
164
- reject(new Error(`Chrome exited ${code}`));
165
- });
166
- });
167
-
168
- const ws = new WebSocket(wsUrl);
169
- await new Promise((res, rej) => {
170
- ws.onopen = res;
171
- ws.onerror = () => rej(new Error("CDP socket failed"));
172
- });
173
- let nextId = 1;
174
- const pending = new Map();
175
- ws.onmessage = (ev) => {
176
- const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
177
- if (msg.id && pending.has(msg.id)) {
178
- const { resolve: ok, reject: bad } = pending.get(msg.id);
179
- pending.delete(msg.id);
180
- if (msg.error) bad(new Error(msg.error.message));
181
- else ok(msg.result);
182
- }
183
- };
184
- const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
185
- const id = nextId++;
186
- return new Promise((resolveSend, reject) => {
187
- const timer = setTimeout(() => {
188
- pending.delete(id);
189
- reject(new Error(`CDP timeout: ${method}`));
190
- }, timeoutMs);
191
- pending.set(id, {
192
- resolve: (v) => {
193
- clearTimeout(timer);
194
- resolveSend(v);
195
- },
196
- reject: (e) => {
197
- clearTimeout(timer);
198
- reject(e);
199
- },
200
- });
201
- ws.send(JSON.stringify(sessionId ? { id, method, params, sessionId } : { id, method, params }));
202
- });
203
- };
204
-
205
- const { targetId } = await send("Target.createTarget", { url: "about:blank" });
206
- const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
207
- const page = (method, params, timeoutMs) => send(method, params, sessionId, timeoutMs);
208
-
209
- await page("Page.enable");
210
- await page("Runtime.enable");
211
- await page("Emulation.setDeviceMetricsOverride", {
212
- width: 1440,
213
- height: 900,
214
- deviceScaleFactor: 1,
215
- mobile: false,
216
- });
217
- await page("Page.navigate", { url }, 40000);
218
- await sleep(3000);
219
-
220
- for (let i = 0; i < scrolls; i++) {
221
- await page("Runtime.evaluate", {
222
- expression: "window.scrollBy(0, Math.round(window.innerHeight * 0.9))",
223
- returnByValue: true,
224
- });
225
- await sleep(900);
226
- }
227
-
228
- const { result } = await page("Runtime.evaluate", {
229
- expression: `(() => {
230
- const rows = [];
231
- const seen = new Set();
232
- const tidy = (t) => (t || "").replace(/\\s+/g, "");
233
- const isCount = (t) => /^[\\d][\\d.,]*[kKmM]?$/.test(t);
234
- const hints = (el) =>
235
- ["aria-label", "title", "class", "data-type", "data-test"]
236
- .map((name) => el.getAttribute(name) || "")
237
- .join(" ");
238
- // A counter labelled as likes or views: its own text, or the one
239
- // descendant that is nothing but a count.
240
- const labelled = (li, word) => {
241
- const re = new RegExp(word, "i");
242
- for (const el of li.querySelectorAll("*")) {
243
- if (!re.test(hints(el))) continue;
244
- const own = tidy(el.textContent);
245
- if (isCount(own)) return own;
246
- for (const kid of el.querySelectorAll("*")) {
247
- const t = tidy(kid.textContent);
248
- if (isCount(t)) return t;
249
- }
250
- }
251
- return "";
252
- };
253
- // Fallback: leaf elements whose whole text is a count, in DOM order.
254
- // Dribbble prints likes first, then views. Free text is never read.
255
- const leafCounts = (li) => {
256
- const out = [];
257
- for (const el of li.querySelectorAll("*")) {
258
- if (el.children.length) continue;
259
- const t = tidy(el.textContent);
260
- if (isCount(t)) out.push(t);
261
- }
262
- return out;
263
- };
264
- for (const li of document.querySelectorAll("li")) {
265
- const a = li.querySelector('a[href*="/shots/"]');
266
- if (!a) continue;
267
- const m = (a.getAttribute("href") || "").match(/\\/shots\\/([^/?#]+)/);
268
- if (!m) continue;
269
- const idSlug = m[1];
270
- if (seen.has(idSlug)) continue;
271
- const img = li.querySelector("img");
272
- if (!img) continue;
273
- const raw = img.getAttribute("data-src") || img.currentSrc || img.src || "";
274
- const imageURL = raw.replace(/\\?.*$/, "");
275
- if (!imageURL) continue;
276
- seen.add(idSlug);
277
- let likes = labelled(li, "like");
278
- let views = labelled(li, "view");
279
- if (!likes && !views) {
280
- const counts = leafCounts(li);
281
- likes = counts[0] || "";
282
- views = counts[1] || "";
283
- }
284
- // The profile handle, from the card's own designer link.
285
- const who = li.querySelector('.user-information a[href^="/"]');
286
- const designer = who ? (who.getAttribute("href") || "").replace(/^\\/|[?#].*$/g, "") : "";
287
- const title = (img.getAttribute("alt") || a.getAttribute("title") || idSlug).replace(/\\t/g, " ").trim();
288
- rows.push([idSlug, likes, views, designer, imageURL, title].join("\\t"));
289
- }
290
- return rows.join("\\n");
291
- })()`,
292
- returnByValue: true,
293
- });
294
-
295
- const tsv = result?.value || "";
296
- if (!tsv.trim()) {
297
- console.error(
298
- "0 cards (empty listing or rate limit — retry after 8s, then after 30s; if it is still 0, record it under the board's drops as `<query>: 0 cards (rate limit?)`)",
299
- );
300
- drop();
301
- process.exit(1);
302
- }
303
-
304
- const all = tsv.split("\n").filter(Boolean);
305
- const reasons = new Map();
306
- const kept = noFilter
307
- ? all
308
- : all.filter((row) => {
309
- const [idSlug, , , , , title = ""] = row.split("\t");
310
- const word = offTopic(`${idSlug} ${title}`);
311
- if (!word) return true;
312
- reasons.set(word, (reasons.get(word) ?? 0) + 1);
313
- return false;
314
- });
315
- const cut = all.length - kept.length;
316
- if (cut > 0) {
317
- const top = [...reasons.entries()]
318
- .sort((a, b) => b[1] - a[1])
319
- .slice(0, 6)
320
- .map(([word, n]) => `${word} ${n}`)
321
- .join(", ");
322
- // The noise rate belongs under the board's drops. A high one means the
323
- // query is wrong, not that there is more scrolling to do.
324
- console.error(
325
- `${kept.length} of ${all.length} cards kept, ${Math.round((cut / all.length) * 100)}% off-topic (${top})`,
326
- );
327
- }
328
- if (!kept.length) {
329
- console.error("every card was off-topic — query the form, not the word (add \"ui\", \"screen\", or a category path)");
330
- drop();
331
- process.exit(1);
332
- }
333
- // Likes are the signal people valued a shot. Sort by them, and drop the
334
- // ones under the floor. An unreadable count is kept, last, so a markup
335
- // change shows as empty columns instead of an empty list.
336
- const likesOf = (row) => count(row.split("\t")[1]);
337
- const strong = kept.filter((row) => !(likesOf(row) < minLikes));
338
- const weak = kept.length - strong.length;
339
- if (weak > 0) {
340
- console.error(`${weak} of ${kept.length} under ${minLikes} likes, dropped (lower it with --min-likes)`);
341
- }
342
- if (!strong.length) {
343
- console.error("every card was under the likes floor — try a broader form or timeframe before lowering it");
344
- drop();
345
- process.exit(1);
346
- }
347
- strong.sort((a, b) => (likesOf(b) || -1) - (likesOf(a) || -1));
348
- // --picker prints picker.mjs rows: title, thumbnail, shot page, source, meta.
349
- const asPicker = (row) => {
350
- const [idSlug, likes, , designer, imageURL, title] = row.split("\t");
351
- const meta = [designer, likes && `${likes} likes`].filter(Boolean).join(" · ");
352
- return [title, `${imageURL}?resize=400x300`, `https://dribbble.com/shots/${idSlug}`, "dribbble", meta].join("\t");
353
- };
354
- console.log((forPicker ? strong.map(asPicker) : strong).join("\n"));
355
- drop();
356
- process.exit(0);