@jonandev/longbeard 0.0.0-stage → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@jonandev/longbeard",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Drop into a project so the agents you already use produce better work.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/jonanderdev/longbeard.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "bin": {
15
+ "longbeard": "./bin/long-beard.js"
16
+ },
17
+ "files": [
18
+ "bin",
19
+ "beard.json",
20
+ "AGENTS.md",
21
+ "skills"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "scripts": {
27
+ "longbeard": "node ./bin/long-beard.js"
28
+ }
29
+ }
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: design-md
3
+ description: >
4
+ Use when building or changing UI and the project has a DESIGN.md, or when
5
+ the user asks to write or follow a brand file. Follow that file.
6
+ If they asked to design a page and there is no DESIGN.md and no Figma,
7
+ that is design-reference-hunt, not this skill. Do not invent a look.
8
+ ---
9
+
10
+ # DESIGN.md
11
+
12
+ The project's `DESIGN.md` is the look.
13
+
14
+ If that file exists, read it before writing UI. Use its color, type, spacing, and components the way that file states them.
15
+
16
+ If it does not exist:
17
+
18
+ - They asked to **design a page or a piece** → load `design-reference-hunt`. Do not ask what the brand is.
19
+ - They asked for a **brand file / DESIGN.md** → ask which reference to follow. Write the file only when they want one.
20
+
21
+ Leave brand catalogs out of the repo. Leave a second visual system out when one already exists.
@@ -0,0 +1,161 @@
1
+ ---
2
+ name: design-reference-hunt
3
+ description: >
4
+ Find real visual references when the project has no official look: no
5
+ DESIGN.md, no Figma link, no .design/board.md. Ask once if they have a
6
+ Figma file; if they paste one, stop hunting. If not, do the full hunt
7
+ and write .design/board.md. Look widely. Scroll and screenshot only
8
+ what you keep. A website aims for 10 live award sites this year; those
9
+ outweigh Dribbble, which is up to 20. An application aims for up to 20
10
+ screen shots; those outweigh award sites. A short board names each drop.
11
+ Cover the same job and also the page type, component, or element,
12
+ including other subjects. The shot files are the evidence. The board’s cards are written in the
13
+ shape taste already reads: idea, hero, type, colour, worth taking.
14
+ A short “Read this” at the top is for a person, or for a builder that
15
+ is not taste. A later section, or a look that already exists: 10
16
+ filtered shots to .design/piece.md. Only keep high-rated Awwwards
17
+ (not weak nominees) and strongly voted Dribbble.
18
+ Use when they ask to design a page or a piece and no direction exists yet.
19
+ This skill writes the board. Taste builds from the cards. This file
20
+ does not say how to lay the page out.
21
+ ---
22
+
23
+ # Reference hunt
24
+
25
+ No official look → this skill. Write a board. Then **keep going and build from that board**. Which builder to load is the project’s router, not this file.
26
+
27
+ Read [quality.md](references/quality.md) before you keep a reference. Weak nominees and generic Dribbble do not go on the board.
28
+
29
+ A Dribbble illustration is **imagery**, not a website. A Dribbble shot of a real screen can be a screen reference. It is never a Site.
30
+
31
+ ## Gate (do this first)
32
+
33
+ Check the repo and the prompt, in order. Stop at the first hit.
34
+
35
+ 1. `DESIGN.md` exists → follow it. Do not hunt a whole look.
36
+ 2. The prompt has a Figma file or link → implement from that file. Do not hunt.
37
+ 3. `.design/board.md` exists → whole look is done when **Read this** names a primary card, that card’s hero names the control, and any shortfall is named. Aims: a website, 10 live sites and up to 20 screens; an application, up to 20 screens and not an Awwwards set. Imagery is up to 10. A short board that does not name each drop is unfinished: finish the hunt. Missing control: open the shot and write it, then build. Or run **Piece** if they asked for a section.
38
+ 4. Otherwise, for a **whole look** only: ask **once**, and wait:
39
+
40
+ Do you have a Figma file for this, or should I hunt references?
41
+
42
+ - They paste a Figma link → implement from Figma. Stop hunting.
43
+ - They say no, skip, or “hunt” → **Whole look** below. Do not ask again.
44
+
45
+ Do not ask this on a piece hunt. Do not ask whether DESIGN.md exists; look for the file.
46
+
47
+ ## Whole look
48
+
49
+ No `DESIGN.md`, no Figma, no `.design/board.md`. The first time this project needs a look. A direction that already exists is **Piece**, not this.
50
+
51
+ Say once, in one line, what you are looking for, and that the closest come back as a short list. Then look without narrating. No scores, no drops, and no site called interesting until that list.
52
+
53
+ Look, then keep. The counts below are what you **keep**. They are not how many you open. Read listings and score pages until the keep is full of ones that pass [quality.md](references/quality.md), and do not stop at the first page. There is no small cap on looking. A website looks through at least 30 live candidates before it accepts fewer than 10 sites, and through the popular Dribbble sort (and the other-subject queries) before it accepts fewer than the screens it could have kept. If that pass is weak, look at the next gallery. A thin field stays thin: name each drop, and do not lower the filter to fill the count.
54
+
55
+ Scroll and screenshot only a keep. Do not scroll a candidate. Do not screenshot a listing, a score page, or a URL you might drop. The capture script scrolls; run it only on a keep. A file in `.design/refs/` that is not on the board gets deleted.
56
+
57
+ 1. Name the subject and the **surface**: `website` or `app`.
58
+ 2. This year’s date. Do not search only the same subject. Also search the page type, the component, and the element, including other subjects that share that form. Filter with [quality.md](references/quality.md).
59
+ - **Website — Sites (aim 10), mixed `fit`:** live URLs from this year. These outweigh Dribbble. Prefer Awwwards SOTD / high scores (overall and Design ≥ 7.5; never 4s). Also Godly, Land-book, siteinspire. Aim `same-job` 2, `register` 2, `form` 6. `same-job` is this subject. `register` shares its feeling: the hour, the material, the ritual, or the kind of place. `form` is another type of business. From it, take only a layout or a component that still works once this topic’s pictures and words are in the frame. If that frame only makes sense for the other type, drop it. Not its type, and not its colours. Leave their identity. An older site only when nothing current has that structure.
60
+ - **Website — Screens (up to 20):** strongly voted Dribbble from this year, after the quality filter. They lose to a kept site. Tag `role: page | component | element` and `subject: same-job | other`. An illustration stays imagery. These are not Sites.
61
+ - **App — Products (up to 6):** public product pages of this job. Not Awwwards, not a campaign site. Fewer is valid when the board names each drop (a login wall, no public page).
62
+ - **App — Screens (up to 20):** strongly voted Dribbble and component galleries. These outweigh product pages and award sites. The shot is the screen, a component, or an element. Other subjects that share that role count. An illustration stays imagery. Do not fill this board with Awwwards.
63
+ - **Imagery (up to 10):** this subject’s world (Unsplash, Wikimedia, museums). Not stock category. A file counts when a crop can make the principle the subject. Drop the rest. Do not pad.
64
+ - **Type / marks (1–2):** a pairing or a stamp you can name.
65
+ 3. Scroll and screenshot only a keep. `node <skill>/scripts/capture.mjs <url> --out .design/refs/<name>.jpg` for that URL only. Do not stitch. How: [shots.md](references/shots.md). Jury quotes only from an Awwwards page you kept. Dribbble: the shot artwork of a keep, not the search grid.
66
+ 4. Write `.design/board.md`. One file, two layers. **Read this** is a few lines a person can read. **Cards** are the references, in the shape taste already reads. A website is valid at 10 sites, or short when each missing site is named after the 30-candidate look. Screens are up to 20. An application is valid with its screens, and invalid if the spine is Awwwards. A short one names each missing screen. Imagery is up to 10. Products are up to 6. Do not pad by lowering the filter. Hexes come from a kept shot, not a palette library. Later pages reuse it. Do not run **whole look** again. Do not build from a board that is short and does not name each drop.
67
+
68
+ **Read this** is written from the cards, after they choose. The primary card is the closest to this subject, not the largest type and not the highest score. Closest means the subject’s world is in the shot: the same job, or a register that shares its hour, its material, its ritual, or its kind of place. Colour and type come from that card, or from this subject’s pictures. A form card does not supply them. It can only add a layout or a component that still belongs on this topic.
69
+
70
+ Before you write **Read this**, ask once, and wait. That message names the two or three closest cards. Each one has its idea in one line, why it is close, and the live URL, so the page can be opened. It also says the shots and the other cards are in `.design/board.md`. It does not list scores, drops, or the other keeps. Their answer is the primary card. If they say you should choose, take the closest.
71
+
72
+ ```
73
+ ## Read this
74
+ - primary: <card name>
75
+ - also: <one other card>
76
+ - control: <as that card’s hero describes it: text link, filled shape, or absent, and where it sits>
77
+ - colour: <where it sits in the shot>
78
+ - type: <the pairing>
79
+ - leave: <one line>
80
+ ```
81
+
82
+ Each site, product page, or screen is a card, written from the open shot file. `role` is required on `form`. A hero that says “one action” and does not say what the control is does not count. On a website the primary card is the closest live site, not a form site chosen for its type. On an application it is a screen, not an award site.
83
+
84
+ ```
85
+ ### <name>
86
+ - source:
87
+ - score:
88
+ - fit: same-job | register | form
89
+ - role: page | component | element
90
+ - subject: same-job | other
91
+ - url:
92
+ - shot: .design/refs/<file>
93
+ - idea: <one sentence. The principle, not their name>
94
+ - hero: <what is in the frame. The control: text link, filled shape, or absent, and where it sits>
95
+ - type: <the faces, and how the shot uses them>
96
+ - colour: <hexes you can see, and where each sits. A colour is a button fill only when the shot fills a button with it>
97
+ - imagery: <what the pictures are>
98
+ - worth taking: <one principle. On a form card: a layout or a component only, and only if it still works on this topic. Not their type. Not their colours>
99
+ - leave: <their identity, and anything that is not the principle>
100
+ ```
101
+
102
+ Imagery and type stay short. They are material, not cards.
103
+
104
+ ```
105
+ - kind: imagery | type
106
+ - url:
107
+ - shot: .design/refs/<file>
108
+ - shows:
109
+ - leave:
110
+ ```
111
+
112
+ The cards are the references. The shot files are the evidence.
113
+
114
+ ## Piece
115
+
116
+ The smaller hunt. A direction already exists (`DESIGN.md`, Figma, or a board), or they only asked for this piece.
117
+
118
+ 1. Name the piece (hero, menu, pricing, empty state, icon, …) and its role: page, component, or element.
119
+ 2. **Keep 10** after the quality filter. Not 20. Look through more than 10 before you choose, including the same role in other subjects. Dribbble (popular, this year), Land-book, Godly, component galleries, Unsplash for imagery. Capture only the 10 you keep. Crop to the **shot**, not the gallery. Live sites only if the piece is a whole block on a real page.
120
+ 3. Tag each: `kind: section | component | imagery | type | mark` and `subject: same-job | other`. Do not file a drawing as a section.
121
+ 4. Write `.design/piece.md` (or `.design/piece-<slug>.md` if more than one). Do **not** replace `.design/board.md`. If a board or `DESIGN.md` exists, take the layout principle from the piece refs and keep that look’s colour and type.
122
+
123
+ ```
124
+ # Piece
125
+ Name: <hero / menu / …>
126
+ ### <name>
127
+ - kind: section | component | imagery | type | mark
128
+ - subject: same-job | other
129
+ - url:
130
+ - shot: .design/refs/<file>
131
+ - idea:
132
+ - hero: <the frame, and the control>
133
+ - worth taking:
134
+ - leave:
135
+ Read this: <one sentence, from the cards>
136
+ ```
137
+
138
+ ## After the board
139
+
140
+ Do not end the turn on the cards. In the chat, name only the two or three closest, each with its live URL, and say the shots are in `.design/board.md`. Then wait. After they answer, write **Read this**, say it in the chat, and build. The cards stay in the file.
141
+
142
+ The cards are the references. Do not deal a library of other ones. On a website the site cards outweigh the screen cards. On an application the screen cards outweigh award sites. How the page is built — scale, grid, sections, motion — belongs to the builder, and with this kit that builder is taste. The control in the primary card is the control. Do not add a filled button the card does not show. Do not lower the score for that. A custom cursor, a password gate, or a WebGL scene is used only when a card shows it.
143
+
144
+ ## Do not
145
+
146
+ - Keep an Awwwards nominee with 4s or overall under 7.5.
147
+ - Stitch viewport screenshots. A file that repeats one fold is invalid.
148
+ - Screenshot a gallery listing.
149
+ - Put files under `.claude/`.
150
+ - Put layout steps in this file. The description may name taste as the reader of the cards.
151
+ - Run whole look twice. A piece hunt is allowed later; a second project board is not.
152
+ - Pad the count by lowering the filter, or by keeping pictures you would not put on the page.
153
+ - Stop looking at the first page of results, or treat the keep count as the number of candidates you open.
154
+ - Scroll or screenshot a candidate. The capture script runs on a keep only.
155
+ - Narrate candidates, scores, or drops while looking. After the opening line, the next thing said is the short list of the closest, each with its live URL.
156
+ - Write a hero that does not say what the control is.
157
+ - Build from a short board that does not name each drop.
158
+ - Take colour or type from a card about another business.
159
+ - Let a card lead because its type is large, when a closer card has the subject’s world in the shot.
160
+ - Let a screen card be the primary card on a website, or an award site be the primary card on an application.
161
+ - Fill an application board with Awwwards.
@@ -0,0 +1,45 @@
1
+ # Keep the strong ones
2
+
3
+ A nominee is not a reference. Open the score (or the shot) and drop anything weak before it hits the board. The keep count is the board. Looking goes past it. A weak pass means fewer keeps, not a lower bar.
4
+
5
+ ## Awwwards
6
+
7
+ Look at the **Awwwards site page**, not the listing card.
8
+
9
+ Keep:
10
+
11
+ - Site of the Day, Site of the Month, Developer Award, or Site of the Year, **or**
12
+ - Honorable Mention / Nominee only if **overall ≥ 7.5** and **Design ≥ 7.5** (scores are /10).
13
+
14
+ Drop:
15
+
16
+ - Overall or Design at **6 or below**, and anything with **4s** on Design, Usability, or Creativity.
17
+ - Nominee-only with no SOTD/HM and a soft score.
18
+ - Gates, password walls, or a hero you cannot actually see.
19
+ - A high score whose offer only makes sense for another type of business. Keep that page only when a layout or a component still works once this topic’s pictures and words are in the frame. Do not take its type or its colours.
20
+
21
+ Quote jury lines only from that page, and only for sites you kept.
22
+
23
+ ## Godly, Land-book, siteinspire
24
+
25
+ Curated, not scored. Keep a site if the **live page** has a clear idea (a crop, a component, one arrangement). From another business, that idea has to be a layout or a component that still works on this topic. Drop their type and their colours. Drop generic SaaS: centred headline, three icon cards, soft gradient, Inter.
26
+
27
+ ## Dribbble / Behance
28
+
29
+ Open `/shots/...`, not search.
30
+
31
+ Sort this year by most saved or most liked. Latest is the wrong feed. Look through that sort, then the page type, the component, and the element, including other subjects. A whole-look board keeps up to 20 that pass this filter. On a website they lose to a kept live site. On an application they outweigh award sites. A piece hunt keeps 10. Open more than you keep. If the pass is weak, the board stays short. Do not lower the filter to finish the count.
32
+
33
+ Keep if you can name what is worth taking in one line (a crop, a type pairing, a palette, a component, a screen). The shot has to be one people actually saved.
34
+
35
+ Drop: AI mush, fake browser chrome around a 3-card landing, purple gradient on dark, Inter-everywhere, emoji icons, melted type, a shot whose only job is “bakery website mockup.”
36
+
37
+ A Dribbble drawing is **imagery**, never a site.
38
+
39
+ ## Unsplash / Wikimedia
40
+
41
+ Search **this** subject, not a stock category name. Drop posed lifestyle and fake product. One real place or material beats a pile of similar ones.
42
+
43
+ A file counts when you can point at a crop where that principle is the subject. If the thing you would leave is what the frame is about, drop it or write the crop. Do not keep ten near-misses to fill a count. The page may use fewer.
44
+
45
+ If a pass cannot fill the count without lowering these gates, hunt another gallery. Do not fill the board with 4s.
@@ -0,0 +1,38 @@
1
+ # The whole page, not the gallery, not only the hero
2
+
3
+ A reference is the design from top to bottom. The builder has to take how the **rest** of the page works, not only the first screen.
4
+
5
+ ## Live sites — the script is for a keep
6
+
7
+ Open as many listings and score pages as the hunt asks. Do not scroll a candidate, and do not screenshot one. Run the script only on a URL you are keeping. That run is the only scroll. Do not screenshot the tab by hand. Do not stitch folds. Stitching is what repeats a sticky hero down the file. A file in `.design/refs/` that is not on the board gets deleted.
8
+
9
+ From the project root:
10
+
11
+ ```
12
+ node <skill>/scripts/capture.mjs https://example.com --out .design/refs/<name>.jpg
13
+ ```
14
+
15
+ The script opens Chrome, accepts a cookie button if it can, then scrolls a viewport at a time and pauses so pictures and reveals can finish. It pauses motion. It does not turn animations off, because that puts a revealed section back to blank. Then it unsticks `fixed`/`sticky` and takes **one** JPEG of the document. Node 22+. Chrome, Edge, or Chromium must be installed (`CHROME_PATH` if it is not in the usual place).
16
+
17
+ Then open the file. Write the hero and what is worth taking from it. A line you could have written without opening it does not count. Invalid if:
18
+
19
+ - the same band of the page appears twice (a stacked face, a repeated headline)
20
+ - a cookie dialog is still on it
21
+ - it is only the first screen of a long site
22
+ - most of the file is empty bands. Run the script once more. If the second file is still empty bands, the page is pinned or a canvas: write `coverage: fold`, keep a single viewport, and delete the tall file.
23
+
24
+ If it is invalid, delete it and run the script again. If the site will not scroll (WebGL, a locked canvas), say `coverage: fold` on the board, keep a **single** viewport shot, and find another scrolling site. Never glue folds by hand.
25
+
26
+ ## Open the piece
27
+
28
+ - Prefer a **live site**. Click through from Awwwards / Godly / Land-book to the actual URL, then run the script on that URL.
29
+ - Dribbble: open the **shot page** (`/shots/...`). Capture the artwork image only, not `/search`.
30
+ - Never capture a search grid, a home feed, or a listing of cards.
31
+
32
+ ## Dribbble / Behance / Unsplash — not sites
33
+
34
+ These are pictures, not pages. Capture the **image** (or the type specimen), no page chrome. An illustration goes under **Material** (`kind: imagery`, `type`, or `mark`). A shot of a real screen goes under **Screens**. Never under Sites.
35
+
36
+ Unsplash and Wikimedia: search the **subject**, not stock category.
37
+
38
+ A board entry whose `shot` is a gallery listing, a stitched repeat, or an illustration filed as a website does not count.
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/env node
2
+ // Full-page capture. Unsticks fixed/sticky chrome first so Chrome does not
3
+ // repeat the same fold. Node 22+. Uses an installed Chrome/Edge/Chromium.
4
+ //
5
+ // node capture.mjs <url> --out .design/refs/name.jpg
6
+ import { spawn } from "node:child_process";
7
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { dirname, join, resolve } from "node:path";
10
+
11
+ const args = process.argv.slice(2);
12
+ const flag = (name, def) => {
13
+ const i = args.indexOf(`--${name}`);
14
+ if (i === -1) return def;
15
+ const v = args[i + 1];
16
+ args.splice(i, 2);
17
+ return v;
18
+ };
19
+ const url = args[0];
20
+ const out = resolve(flag("out", "") || "");
21
+ if (!url || !/^https?:\/\//.test(url) || !out) {
22
+ console.error("usage: node capture.mjs <https://url> --out .design/refs/name.jpg");
23
+ process.exit(2);
24
+ }
25
+
26
+ function findChrome() {
27
+ const env = process.env.CHROME_PATH;
28
+ if (env && existsSync(env)) return env;
29
+ const home = process.env.HOME || process.env.USERPROFILE || "";
30
+ const local = process.env.LOCALAPPDATA || "";
31
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
32
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
33
+ const candidates = [
34
+ join(pf, "Google/Chrome/Application/chrome.exe"),
35
+ join(pf86, "Google/Chrome/Application/chrome.exe"),
36
+ join(local, "Google/Chrome/Application/chrome.exe"),
37
+ join(pf, "Microsoft/Edge/Application/msedge.exe"),
38
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
39
+ "/Applications/Chromium.app/Contents/MacOS/Chromium",
40
+ "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
41
+ join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
42
+ "/usr/bin/google-chrome",
43
+ "/usr/bin/google-chrome-stable",
44
+ "/usr/bin/chromium",
45
+ "/usr/bin/chromium-browser",
46
+ ];
47
+ return candidates.find((path) => path && existsSync(path)) || null;
48
+ }
49
+
50
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
51
+
52
+ const exe = findChrome();
53
+ if (!exe) {
54
+ console.error("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
55
+ process.exit(1);
56
+ }
57
+ if (typeof WebSocket === "undefined") {
58
+ console.error("Node 22+ is required.");
59
+ process.exit(1);
60
+ }
61
+
62
+ const dir = mkdtempSync(join(tmpdir(), "hunt-chrome-"));
63
+ let proc;
64
+ const drop = () => {
65
+ try {
66
+ if (proc?.pid) process.kill(proc.pid, "SIGKILL");
67
+ } catch {}
68
+ try {
69
+ rmSync(dir, { recursive: true, force: true });
70
+ } catch {}
71
+ };
72
+ process.once("exit", drop);
73
+
74
+ proc = spawn(
75
+ exe,
76
+ [
77
+ "--headless=new",
78
+ "--remote-debugging-port=0",
79
+ `--user-data-dir=${dir}`,
80
+ "--no-first-run",
81
+ "--hide-scrollbars",
82
+ "--mute-audio",
83
+ "--force-color-profile=srgb",
84
+ "--window-size=1440,900",
85
+ "about:blank",
86
+ ],
87
+ { stdio: ["ignore", "ignore", "pipe"] },
88
+ );
89
+
90
+ let buf = "";
91
+ const wsUrl = await new Promise((resolveWs, reject) => {
92
+ const t = setTimeout(() => reject(new Error("Chrome did not start")), 20000);
93
+ proc.stderr.on("data", (d) => {
94
+ buf += d.toString();
95
+ const m = buf.match(/DevTools listening on (ws:\/\/[^\s]+)/);
96
+ if (m) {
97
+ clearTimeout(t);
98
+ resolveWs(m[1]);
99
+ }
100
+ });
101
+ proc.on("exit", (code) => {
102
+ clearTimeout(t);
103
+ reject(new Error(`Chrome exited ${code}`));
104
+ });
105
+ });
106
+
107
+ const ws = new WebSocket(wsUrl);
108
+ await new Promise((res, rej) => {
109
+ ws.onopen = res;
110
+ ws.onerror = () => rej(new Error("CDP socket failed"));
111
+ });
112
+ let nextId = 1;
113
+ const pending = new Map();
114
+ ws.onmessage = (ev) => {
115
+ const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
116
+ if (msg.id && pending.has(msg.id)) {
117
+ const { resolve: ok, reject: bad } = pending.get(msg.id);
118
+ pending.delete(msg.id);
119
+ if (msg.error) bad(new Error(msg.error.message));
120
+ else ok(msg.result);
121
+ }
122
+ };
123
+ const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
124
+ const id = nextId++;
125
+ return new Promise((resolveSend, reject) => {
126
+ const timer = setTimeout(() => {
127
+ pending.delete(id);
128
+ reject(new Error(`CDP timeout: ${method}`));
129
+ }, timeoutMs);
130
+ pending.set(id, {
131
+ resolve: (v) => {
132
+ clearTimeout(timer);
133
+ resolveSend(v);
134
+ },
135
+ reject: (e) => {
136
+ clearTimeout(timer);
137
+ reject(e);
138
+ },
139
+ });
140
+ ws.send(JSON.stringify(sessionId ? { id, method, params, sessionId } : { id, method, params }));
141
+ });
142
+ };
143
+
144
+ const { targetId } = await send("Target.createTarget", { url: "about:blank" });
145
+ const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
146
+ const page = (method, params, timeoutMs) => send(method, params, sessionId, timeoutMs);
147
+
148
+ await page("Page.enable");
149
+ await page("Runtime.enable");
150
+ await page("Emulation.setDeviceMetricsOverride", {
151
+ width: 1440,
152
+ height: 900,
153
+ deviceScaleFactor: 1,
154
+ mobile: false,
155
+ });
156
+ await page("Page.navigate", { url }, 40000);
157
+ await sleep(2500);
158
+
159
+ await page("Runtime.evaluate", {
160
+ expression: `(() => {
161
+ const labels = /accept|agree|ok|got it|allow|i understand|acepto|aceptar/i;
162
+ for (const el of document.querySelectorAll("button, [role=button], a")) {
163
+ const t = (el.innerText || el.textContent || "").trim();
164
+ if (t.length < 40 && labels.test(t)) { el.click(); break; }
165
+ }
166
+ })()`,
167
+ awaitPromise: true,
168
+ returnByValue: true,
169
+ });
170
+ await sleep(800);
171
+
172
+ await page(
173
+ "Runtime.evaluate",
174
+ {
175
+ expression: `(() => new Promise((done) => {
176
+ (async () => {
177
+ for (const img of document.images) {
178
+ if (img.loading === "lazy") img.loading = "eager";
179
+ }
180
+ const dwell = (ms) => new Promise((r) => setTimeout(r, ms));
181
+ const step = Math.max(480, Math.round(window.innerHeight * 0.65));
182
+ const limit = Math.min(
183
+ Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight || 0),
184
+ 14000
185
+ );
186
+ let y = 0;
187
+ while (y < limit) {
188
+ y = Math.min(limit, y + step);
189
+ window.scrollTo(0, y);
190
+ await dwell(600);
191
+ }
192
+ await Promise.race([
193
+ Promise.all([...document.images].map((img) => img.decode().catch(() => {}))),
194
+ dwell(8000),
195
+ ]);
196
+ window.scrollTo(0, 0);
197
+ await dwell(700);
198
+ done();
199
+ })().catch(() => done());
200
+ }))()`,
201
+ awaitPromise: true,
202
+ returnByValue: true,
203
+ },
204
+ 90000,
205
+ );
206
+
207
+ await page("Runtime.evaluate", {
208
+ expression: `(() => {
209
+ const style = document.createElement("style");
210
+ style.textContent = \`
211
+ html, body { height: auto !important; max-height: none !important; overflow: visible !important; }
212
+ * { animation-play-state: paused !important; transition: none !important; scroll-behavior: auto !important; }
213
+ \`;
214
+ document.head.appendChild(style);
215
+ for (const el of document.querySelectorAll("*")) {
216
+ const pos = getComputedStyle(el).position;
217
+ if (pos === "fixed" || pos === "sticky") {
218
+ el.style.setProperty("position", "relative", "important");
219
+ el.style.setProperty("top", "auto", "important");
220
+ el.style.setProperty("bottom", "auto", "important");
221
+ }
222
+ }
223
+ })()`,
224
+ awaitPromise: true,
225
+ returnByValue: true,
226
+ });
227
+ await sleep(400);
228
+
229
+ const metrics = await page("Page.getLayoutMetrics");
230
+ const size = metrics.cssContentSize || metrics.contentSize;
231
+ const width = Math.max(1, Math.ceil(size.width || 1440));
232
+ const height = Math.max(1, Math.min(Math.ceil(size.height || 900), 14000));
233
+ const { data } = await page(
234
+ "Page.captureScreenshot",
235
+ {
236
+ format: "jpeg",
237
+ quality: 70,
238
+ captureBeyondViewport: true,
239
+ clip: { x: 0, y: 0, width, height, scale: 1 },
240
+ },
241
+ 60000,
242
+ );
243
+
244
+ mkdirSync(dirname(out), { recursive: true });
245
+ writeFileSync(out, Buffer.from(data, "base64"));
246
+ console.log(out);
247
+ drop();
248
+ process.exit(0);