@jonandev/longbeard 0.11.0 → 0.11.2
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/CHANGELOG.md +13 -0
- package/README.md +2 -2
- package/package.json +1 -1
- package/skills/design/SKILL.md +21 -7
- package/skills/design/scripts/capture.mjs +356 -36
- package/skills/design-check/scripts/capture.mjs +356 -36
- package/skills/design-direction/SKILL.md +111 -31
- package/skills/design-direction/references/sources.md +6 -4
- package/skills/design-direction/scripts/capture.mjs +356 -36
- package/skills/design-direction/scripts/moodboard.mjs +290 -53
- package/skills/idea/SKILL.md +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.11.2 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
- `design-direction` asks whether you already have a moodboard: a Figma link (file, page or section), a folder of images, or links. If you do, it is the base. The agent reads the board and checks whether it is enough: three distinct anchors, and every part of the product covered. If it is, there is no search. If not, it says what the board lacks and offers a search for only that (a pool of 20 to 60, one picker round), or the full search when the board is too thin for even one direction. It opens the shortlisted references at full size (from Figma, the original upload, GIFs included, with motion recorded as frames), and proposes 3 directions as small boards of 6 to 8 references. Each direction is anchored on one reference's move, kept whole, with moves from other references combined around it and never averaged, and never one reference's whole concept. The search, the picker and the board of 100 stay for people without a moodboard.
|
|
8
|
+
- `design` keeps the direction's reference shots open while prototyping, for the finish text cannot carry: type character, spacing, texture. They rank below the design rules and are never copied. A reference that moves is replayed before the part it inspires is prototyped: its frames, and its live page recorded again, so the prototype's motion has the same feel.
|
|
9
|
+
|
|
10
|
+
## 0.11.1 — 2026-11-17
|
|
11
|
+
|
|
12
|
+
- The brief has a **Position** section: what the product is up against, the one concrete thing it is remembered for, and its personality. `idea` recommends it from what people do today instead, and `design-direction` builds `ownable`, `voice` and `leave` from it, so the look aims at being distinctive rather than guessing.
|
|
13
|
+
- `design-direction` keeps about 100 references by default instead of 12, spread across the whole site (home, navigation, index, case study, article, blog, photography, motion) or an app's key screens, and reaches back to older award winners. The pool and the second round grow to match, and a keep is the page that shows its part, not just the home page.
|
|
14
|
+
- The moodboard is a picker. Tiles are grouped by part, each with Lead (one per part), Like, No and a note, and a copy-out for the chat. `direction.md` lists its references by part. Recorded motion plays on the tile.
|
|
15
|
+
- `design` lays the approved look out as a bento board in Figma before any component: the name in the display face, the type styles, the colour tokens and themes, real pictures from the prototype, a line in the voice, a key screen, the ownable, and a big number if the product has one. Every tile is bound to the tokens, and they say yes to it before the screens are built.
|
|
16
|
+
- `capture.mjs` waits out loaders and intros (no loader covering the screen, not one flat colour, the network quiet; up to 15 s on the web, 2 s locally, `--wait` to change), turns down cookie banners without removing the page around them, and keeps the first screen when a canvas page comes back blank at full length. `--frames N` records timed frames of an intro, a scroll (`--scroll`) or a click (`--click`), and `--click` alone captures the screen after a click, such as an open menu. Local pages are left as they are (no consent clicks), and a local file can be captured up to 30000 px tall, so a moodboard of 100 fits. WebGL and intro-heavy sites came back blank before, and transitions could not be judged from stills.
|
|
17
|
+
|
|
5
18
|
## 0.11.0 — 2026-11-15
|
|
6
19
|
|
|
7
20
|
- `design-direction` calls itself the inspiration step, and its wording and the README's say so plainly.
|
package/README.md
CHANGED
|
@@ -21,8 +21,8 @@ It is a base. You keep going from here.
|
|
|
21
21
|
| Stage | What happens | You get |
|
|
22
22
|
|---|---|---|
|
|
23
23
|
| 1. Idea | The agent grills the idea in rounds, each question with its recommendation | `docs/brief.md`: one page, no tech choices |
|
|
24
|
-
| 2. Direction | Three questions about what you like, a wide search you mark like or no on a picker page, a sharper second search from your picks, then a moodboard | `design-exploration/<slug>/direction.md`: ideas and patterns, not colours |
|
|
25
|
-
| 3. Design | Questions on colour and type, then two or three prototypes of the key screens; you pick and iterate | `DESIGN.md` on your yes,
|
|
24
|
+
| 2. Direction | Three questions about what you like, a wide search you mark like or no on a picker page, a sharper second search from your picks, then a moodboard of about 100 across the whole site that you mark lead, like or no | `design-exploration/<slug>/direction.md`: ideas and patterns, not colours |
|
|
25
|
+
| 3. Design | Questions on colour and type, then two or three prototypes of the key screens; you pick and iterate | `DESIGN.md` on your yes, a bento board of the look in Figma, then the screens, checked and marked Ready |
|
|
26
26
|
| 4. Architecture | The stack and the words the product uses | `GLOSSARY.md`, decisions |
|
|
27
27
|
| 5. Plan | Each flow becomes a spec, each spec vertical-slice tickets | specs and tickets on GitHub Issues or local files |
|
|
28
28
|
| 6. Build | One agent per ticket, test-first, reviewed, then checked against its Figma frame | one pull request per spec; you merge |
|
package/package.json
CHANGED
package/skills/design/SKILL.md
CHANGED
|
@@ -3,7 +3,8 @@ name: design
|
|
|
3
3
|
description: >
|
|
4
4
|
Turn a direction into the product's look: prototype the brief's key screens
|
|
5
5
|
in plain HTML, let them pick and iterate, then on approval write DESIGN.md
|
|
6
|
-
in one go
|
|
6
|
+
in one go, lay the look out as a bento board in Figma, and build the
|
|
7
|
+
screens from it. Colour, type, spacing and
|
|
7
8
|
copy are chosen here, on rendered screens. Runs when
|
|
8
9
|
design-exploration/<slug>/direction.md exists and there is no approved
|
|
9
10
|
DESIGN.md, or for a feature that needs screens. Figma is required.
|
|
@@ -11,7 +12,7 @@ description: >
|
|
|
11
12
|
|
|
12
13
|
# Design
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
Four things come out, in order: a prototype they approved, `DESIGN.md` (the official look, committed), a bento board of that look in Figma, and the screens in Figma marked **Ready**. Figma is the truth for screens. `DESIGN.md` is the written summary of the rules behind them.
|
|
15
16
|
|
|
16
17
|
Read [design-rules.md](references/design-rules.md) before the first prototype. It is the checklist for every screen here and in `design-check`.
|
|
17
18
|
|
|
@@ -50,6 +51,10 @@ Propose from the direction, so they react rather than start from nothing: for ea
|
|
|
50
51
|
|
|
51
52
|
Read the brief's key screens (2–4) and `direction.md`. Prototype only those, with their main states. Other screens are composed later in Figma from the components.
|
|
52
53
|
|
|
54
|
+
Open the shots `direction.md` lists under References, the anchor or leads first, and keep them open while you prototype. Text carries a direction's structure. The pictures carry its finish: the type's character, the spacing's rhythm, the texture. Take the move, never the design: they rank below design-rules, and nothing in the prototype is lifted from one reference whole.
|
|
55
|
+
|
|
56
|
+
A reference that moves is felt again, not remembered. A still and a caption cannot carry timing. Before prototyping the part it inspires, play its recorded frames, and open its live link again: record it with `capture.mjs <url> --out design-exploration/<slug>/refs/<name>-replay --frames 12`, with `--scroll` or `--click` for what moves on scroll or on a click. Note what moves, in what order, how fast, and how it eases. Then build that kind of motion into the variants in CSS, with the same feel and none of its content, and say in chat which reference it came from. A link that no longer loads: work from the frames, and say so.
|
|
57
|
+
|
|
53
58
|
Load Matt's `prototype`, UI branch, and tell it:
|
|
54
59
|
|
|
55
60
|
- **No app.** Sub-shape B, in `design-exploration/<slug>/prototype/`: one `index.html` per key screen, plain HTML and CSS, no build step, no router, no NODE_ENV gate. It runs by opening the file.
|
|
@@ -86,7 +91,7 @@ Only on their yes to a rendered prototype. Write the whole file from [design-md-
|
|
|
86
91
|
node <skill>/scripts/contrast.mjs "#1b1b1f on #fafaf7" "#c2410c on #fafaf7:mark"
|
|
87
92
|
```
|
|
88
93
|
- **Themes.** A product with more than one theme lists each colour token once, with a value per theme, and every pair passes the contrast check in each theme.
|
|
89
|
-
- **Ideas, not sources.** `
|
|
94
|
+
- **Ideas, not sources.** References live only in `design-exploration/` on this machine, and only for this step. Nothing that outlives it names one: not `DESIGN.md`, not Figma (layers, descriptions, comments), not code or its comments, not a commit, PR, spec or ticket. No product, site, studio, designer or link from the exploration, and no `design-exploration/` path. Turn each into the idea: "a quiet reading page", not whose. Which reference a move came from is said in chat only.
|
|
90
95
|
- **Write down what makes it this design.** Whatever someone would need to rebuild it without the prototype open goes under Components, with values, not adjectives.
|
|
91
96
|
- **Tokens are code names.** Name each colour, type and spacing token as it will be named in code (`color/ink`, `space/md`). Figma variables use the same names, with code syntax `var(--color-ink)`.
|
|
92
97
|
- **Soft rules overridden on purpose** go under Decisions with the reason. Hard rules cannot be overridden.
|
|
@@ -99,8 +104,8 @@ Load `figma-use`, `figma-generate-library` and `figma-generate-design`, and foll
|
|
|
99
104
|
- **Our tokens, not a kit.** Variables and styles come from `DESIGN.md`. New files may come with community kits attached (Material, Apple, Simple Design System). Their discovery steps tell you to reuse them. Do not: search the file only (no `includeLibraryKeys`), and build what is missing from `DESIGN.md`.
|
|
100
105
|
- **Build, do not capture.** Compose screens from the tokens and components. Do not run `generate_figma_design` on the prototype. It is a throwaway with a switcher. For pictures, create the image frames, then `upload_assets` the prototype's own files with those `nodeIds`.
|
|
101
106
|
- **Themes are modes.** One colour collection with a mode per theme. Each screen is built once and switches with the mode, never a colour set or a frame per theme. If Figma refuses the modes, stop and ask. Never fall back to separate sets.
|
|
102
|
-
- **Pages:** Cover, Foundations, Components; one `Screens — <flow>` page per flow from the brief; `Explorations` for anything kept for later, by date.
|
|
103
|
-
- **Order:** tokens and styles from `DESIGN.md` → only the components the key screens need → the key screens → their states. The library grows with features. It is not built ahead.
|
|
107
|
+
- **Pages:** Cover (the board), Foundations, Components; one `Screens — <flow>` page per flow from the brief; `Explorations` for anything kept for later, by date.
|
|
108
|
+
- **Order:** tokens and styles from `DESIGN.md` → the board → only the components the key screens need → the key screens → their states. The library grows with features. It is not built ahead.
|
|
104
109
|
- **States:** every screen has a frame for each of empty, loading and error that a person can reach, next to the default. A state nobody can reach gets no frame: add the screen, the state and the reason under Decisions in `DESIGN.md`.
|
|
105
110
|
- **Names:** `<screen> — <state>`. When a screen's layout differs by device, `<screen> · <device> — <state>`. The state can describe itself. Theme is never in the name.
|
|
106
111
|
- **Components have their states too:** focus and pressed for every control, before a screen uses it.
|
|
@@ -110,6 +115,15 @@ Load `figma-use`, `figma-generate-library` and `figma-generate-design`, and foll
|
|
|
110
115
|
- **Check each screen** with `design-check` frame mode before showing it, passing the prototype shot. Fix its hard findings.
|
|
111
116
|
- **Ready:** when they approve a frame, add `— Ready` to its name. Tickets link Ready frames, and build is checked against them.
|
|
112
117
|
|
|
118
|
+
### The board
|
|
119
|
+
|
|
120
|
+
Before any component, lay the whole look out on one frame, `Board`, on the Cover page: a bento of tiles in different sizes that shows the identity at a glance, the way a studio presents a brand. It is where they see colour, type, imagery and voice working together, and where a weak look shows before a screen is built on it.
|
|
121
|
+
|
|
122
|
+
- **What it holds**, each its own tile: the product's name set in the display face; the type, each text style named and shown in use; the colours, each token as a swatch with its name, and every theme; two or three of the prototype's real pictures, cropped hard; one line in the voice, set large; a crop of an approved key screen in a device frame; the `ownable`; and, if the brief has one, a number or fact about the product set very large. Add a tile for anything else that makes this look this look (a mark, a shape, an illustration). Leave out a tile that would be empty.
|
|
123
|
+
- **Composed, not listed.** One tile leads and is the largest; the rest vary in size and in which colour they sit on. Tiles share one gap and one radius from `DESIGN.md`. Text sits on its tile's colour at the contrast `DESIGN.md` checked.
|
|
124
|
+
- **Real, and bound.** Every fill, text and radius is bound to a variable or style: the board is the tokens in use, and changes when they change. Copy comes from the brief and the prototype, pictures from `prototype/img/`. No placeholder, no reference's name or picture.
|
|
125
|
+
- **Their yes.** Screenshot it, read the text back from the nodes, and show it. Ask whether this is the product. A no is a change to `DESIGN.md` and the prototype first, then the board again. It is not marked Ready: it is not a screen, and nothing is built from it but the feeling.
|
|
126
|
+
|
|
113
127
|
If a Figma decision changes a rule (a new token, a component variant, a spacing step), update `DESIGN.md` in the same turn and say what changed.
|
|
114
128
|
|
|
115
129
|
### 6. Clean up
|
|
@@ -126,14 +140,14 @@ A feature with screens, once `DESIGN.md` exists.
|
|
|
126
140
|
- **New parts?** Prototype only the new parts, on the real screens around them, in `design-exploration/<feature>/prototype/`, then as above.
|
|
127
141
|
- New page `Screens — <feature>`. Reuse components. New ones are added to Components.
|
|
128
142
|
- `DESIGN.md` gets entries (a token, a component, a decision with date and reason). It is never rewritten in a feature.
|
|
129
|
-
- **Identity changes need their own yes.** A new colour role, a typeface, a change to the idea or the voice: ask for each one separately, after showing it rendered. Two such changes are approved one at a time, never bundled.
|
|
143
|
+
- **Identity changes need their own yes.** A new colour role, a typeface, a change to the idea or the voice: ask for each one separately, after showing it rendered. Two such changes are approved one at a time, never bundled. An approved one goes on the board too.
|
|
130
144
|
- A rebrand is not a feature: that is `design-direction` again, then a first pass.
|
|
131
145
|
- **A screen with no Ready frame.** A project that joined with its screens already in Figma has frames nobody marked. When a feature touches one, run `design-check` frame mode on it, add what it lacks, and mark it Ready on their yes. A screen with a copy per theme becomes one frame on modes. Only the screens the feature touches, never the whole file.
|
|
132
146
|
|
|
133
147
|
## Do not
|
|
134
148
|
|
|
135
149
|
- Write `DESIGN.md` before they approve a rendered prototype, or rewrite it during a feature. Only a rebrand's first pass replaces it.
|
|
136
|
-
- Name a reference or a `design-exploration/` path in `DESIGN.md
|
|
150
|
+
- Name a reference, its link, its author or a `design-exploration/` path in anything that outlives the exploration: `DESIGN.md`, Figma, code, comments, commits, PRs, specs, tickets.
|
|
137
151
|
- Use a community kit's components or variables in Figma.
|
|
138
152
|
- Build the whole component library before the screens need it.
|
|
139
153
|
- Mark a frame Ready that lacks a state a person can reach, or that has open hard findings.
|
|
@@ -14,10 +14,33 @@
|
|
|
14
14
|
// shot is of the page asked for.
|
|
15
15
|
// node capture.mjs file:///abs/path/moodboard.html --out /tmp/moodboard.jpg
|
|
16
16
|
// node capture.mjs file:///abs/path/shot.jpg --out design-exploration/<slug>/refs/name.jpg --clip x,y,w,h
|
|
17
|
+
//
|
|
18
|
+
// Before the shot it waits out loaders: until no loader covers the screen and
|
|
19
|
+
// the screen is not one flat colour and the network is quiet, for at most --wait ms (15 s on the web,
|
|
20
|
+
// 2 s for files and localhost). If a full page comes back blank at the top
|
|
21
|
+
// where the screen was not (a canvas that redraws only what is on screen),
|
|
22
|
+
// it keeps the screen it saw as the shot, the full page beside it as
|
|
23
|
+
// <name>-full.jpg, and says so.
|
|
24
|
+
//
|
|
25
|
+
// Motion: --frames N writes N screen-sized frames, --every ms apart (500), to
|
|
26
|
+
// the folder --out names: 01-00000ms.jpg, 02-00500ms.jpg… Without --scroll they
|
|
27
|
+
// start as the page opens, so the loader and the intro are in them. With
|
|
28
|
+
// --scroll they start once it has loaded, and each frame scrolls half a
|
|
29
|
+
// screen by the wheel, so scroll-driven motion plays.
|
|
30
|
+
// node capture.mjs <url> --out design-exploration/<slug>/refs/name-intro --frames 12
|
|
31
|
+
// node capture.mjs <url> --out design-exploration/<slug>/refs/name-scroll --frames 12 --every 400 --scroll
|
|
32
|
+
//
|
|
33
|
+
// --click "css" clicks that element once the page has loaded, as a person
|
|
34
|
+
// would. Alone it keeps the screen after the click (an open menu). With
|
|
35
|
+
// --frames the first frame is before the click and the rest record what the
|
|
36
|
+
// click does (a menu opening, a page transition).
|
|
37
|
+
// node capture.mjs <url> --out design-exploration/<slug>/refs/name-menu.jpg --click "button[aria-label*=menu i]"
|
|
38
|
+
// node capture.mjs <url> --out design-exploration/<slug>/refs/name-menu-open --frames 10 --every 150 --click "header button"
|
|
17
39
|
import { spawn, execSync } from "node:child_process";
|
|
18
40
|
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
19
41
|
import { tmpdir } from "node:os";
|
|
20
42
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
43
|
+
import { inflateSync } from "node:zlib";
|
|
21
44
|
|
|
22
45
|
const args = process.argv.slice(2);
|
|
23
46
|
const flag = (name, def) => {
|
|
@@ -34,14 +57,23 @@ const clipArg = flag("clip", "") || "";
|
|
|
34
57
|
const clipSelector = flag("clip-selector", "") || "";
|
|
35
58
|
// Sent with every request to the page's own origin, as a logged-in browser would.
|
|
36
59
|
const cookieArg = flag("cookie", "") || "";
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
60
|
+
const bool = (name) => {
|
|
61
|
+
const i = args.indexOf(`--${name}`);
|
|
62
|
+
if (i !== -1) args.splice(i, 1);
|
|
63
|
+
return i !== -1;
|
|
64
|
+
};
|
|
65
|
+
const strict = bool("strict");
|
|
66
|
+
const scrollFrames = bool("scroll");
|
|
67
|
+
const framesArg = flag("frames", "") || "";
|
|
68
|
+
// Clicks this element once the page has loaded: a menu button, a link, a tab.
|
|
69
|
+
const clickArg = flag("click", "") || "";
|
|
70
|
+
const everyArg = flag("every", "") || "";
|
|
71
|
+
const waitArg = flag("wait", "") || "";
|
|
40
72
|
// Below 768 the page gets a phone viewport: mobile layout, 2x pixels.
|
|
41
73
|
const width = Math.round(Number(flag("width", "1440")));
|
|
42
74
|
if (!url || !/^(https?|file):\/\//.test(url) || !outArg) {
|
|
43
75
|
console.error(
|
|
44
|
-
'usage: node capture.mjs <https://url | file:///path> --out design-exploration/<slug>/refs/name.jpg [--review /tmp/name-review.jpg] [--clip x,y,w,h | --clip-selector "css"] [--width 390] [--cookie "name=value; …"] [--strict]',
|
|
76
|
+
'usage: node capture.mjs <https://url | file:///path> --out design-exploration/<slug>/refs/name.jpg [--review /tmp/name-review.jpg] [--clip x,y,w,h | --clip-selector "css"] [--width 390] [--cookie "name=value; …"] [--strict] [--wait ms] [--click "css"] [--frames N [--every ms] [--scroll]]',
|
|
45
77
|
);
|
|
46
78
|
process.exit(2);
|
|
47
79
|
}
|
|
@@ -49,6 +81,37 @@ if (!Number.isFinite(width) || width < 200 || width > 3840) {
|
|
|
49
81
|
console.error("width must be a number from 200 to 3840");
|
|
50
82
|
process.exit(2);
|
|
51
83
|
}
|
|
84
|
+
const frames = framesArg ? Number(framesArg) : 0;
|
|
85
|
+
const every = everyArg ? Number(everyArg) : 500;
|
|
86
|
+
if (framesArg && (!Number.isInteger(frames) || frames < 2 || frames > 60)) {
|
|
87
|
+
console.error("frames must be a whole number from 2 to 60");
|
|
88
|
+
process.exit(2);
|
|
89
|
+
}
|
|
90
|
+
if (!Number.isInteger(every) || every < 100 || every > 10000) {
|
|
91
|
+
console.error("every must be a whole number of ms from 100 to 10000");
|
|
92
|
+
process.exit(2);
|
|
93
|
+
}
|
|
94
|
+
if ((everyArg || scrollFrames) && !frames) {
|
|
95
|
+
console.error("--every and --scroll go with --frames");
|
|
96
|
+
process.exit(2);
|
|
97
|
+
}
|
|
98
|
+
if (clickArg && scrollFrames) {
|
|
99
|
+
console.error("pass --click or --scroll, not both");
|
|
100
|
+
process.exit(2);
|
|
101
|
+
}
|
|
102
|
+
if ((frames || clickArg) && (reviewArg || clipArg || clipSelector)) {
|
|
103
|
+
console.error("--frames and --click take whole screens: drop --review, --clip and --clip-selector");
|
|
104
|
+
process.exit(2);
|
|
105
|
+
}
|
|
106
|
+
// A local page has no loader worth waiting for, so a sparse screen costs little.
|
|
107
|
+
// A full page stops at 14000 px; our own files (a picker, a moodboard) can run longer.
|
|
108
|
+
const tallest = /^file:/.test(url) ? 30000 : 14000;
|
|
109
|
+
const local = /^file:/.test(url) || /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(url);
|
|
110
|
+
const maxWait = waitArg ? Number(waitArg) : local ? 2000 : 15000;
|
|
111
|
+
if (!Number.isFinite(maxWait) || maxWait < 0 || maxWait > 120000) {
|
|
112
|
+
console.error("wait must be ms from 0 to 120000");
|
|
113
|
+
process.exit(2);
|
|
114
|
+
}
|
|
52
115
|
const mobile = width < 768;
|
|
53
116
|
const height = mobile ? 844 : 900;
|
|
54
117
|
if (clipArg && clipSelector) {
|
|
@@ -148,6 +211,8 @@ proc = spawn(
|
|
|
148
211
|
"--hide-scrollbars",
|
|
149
212
|
"--mute-audio",
|
|
150
213
|
"--force-color-profile=srgb",
|
|
214
|
+
// Without a GPU, Chrome no longer falls back to software WebGL on its own.
|
|
215
|
+
"--enable-unsafe-swiftshader",
|
|
151
216
|
`--window-size=${width},${height}`,
|
|
152
217
|
"about:blank",
|
|
153
218
|
],
|
|
@@ -178,8 +243,20 @@ await new Promise((res, rej) => {
|
|
|
178
243
|
});
|
|
179
244
|
let nextId = 1;
|
|
180
245
|
const pending = new Map();
|
|
246
|
+
// Requests in flight, so the wait can tell a loader still fetching its assets.
|
|
247
|
+
// A request open for over 10 s is a stream or a poll, not a load.
|
|
248
|
+
const inflight = new Map();
|
|
249
|
+
let lastNetwork = Date.now();
|
|
181
250
|
ws.onmessage = (ev) => {
|
|
182
251
|
const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
|
|
252
|
+
// A hot-reload stream or a socket stays open by design, so it is not a load.
|
|
253
|
+
if (msg.method === "Network.requestWillBeSent" && !/^(EventSource|WebSocket)$/.test(msg.params.type || "")) {
|
|
254
|
+
inflight.set(msg.params.requestId, Date.now());
|
|
255
|
+
lastNetwork = Date.now();
|
|
256
|
+
} else if (msg.method === "Network.loadingFinished" || msg.method === "Network.loadingFailed") {
|
|
257
|
+
inflight.delete(msg.params.requestId);
|
|
258
|
+
lastNetwork = Date.now();
|
|
259
|
+
}
|
|
183
260
|
if (msg.id && pending.has(msg.id)) {
|
|
184
261
|
const { resolve: ok, reject: bad } = pending.get(msg.id);
|
|
185
262
|
pending.delete(msg.id);
|
|
@@ -214,6 +291,7 @@ const page = (method, params, timeoutMs) => send(method, params, sessionId, time
|
|
|
214
291
|
|
|
215
292
|
await page("Page.enable");
|
|
216
293
|
await page("Runtime.enable");
|
|
294
|
+
await page("Network.enable");
|
|
217
295
|
await page("Emulation.setDeviceMetricsOverride", {
|
|
218
296
|
width,
|
|
219
297
|
height,
|
|
@@ -243,44 +321,250 @@ if (cookieArg && /^https?:/.test(url)) {
|
|
|
243
321
|
}
|
|
244
322
|
await page("Network.setCookies", { cookies });
|
|
245
323
|
}
|
|
246
|
-
|
|
247
|
-
await
|
|
324
|
+
const evalValue = async (expression, timeoutMs) =>
|
|
325
|
+
(await page("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true }, timeoutMs)).result?.value;
|
|
248
326
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
)
|
|
327
|
+
// Share of a PNG's pixels in its most common colour, so 1 is one flat colour.
|
|
328
|
+
// Chrome writes 8-bit RGB or RGBA, not interlaced; anything else counts as not flat.
|
|
329
|
+
function flatShare(png) {
|
|
330
|
+
if (png.readUInt32BE(12) !== 0x49484452) return 0;
|
|
331
|
+
const w = png.readUInt32BE(16);
|
|
332
|
+
const h = png.readUInt32BE(20);
|
|
333
|
+
const depth = png[24];
|
|
334
|
+
const type = png[25];
|
|
335
|
+
const bpp = type === 6 ? 4 : type === 2 ? 3 : 0;
|
|
336
|
+
if (depth !== 8 || !bpp || png[28] !== 0) return 0;
|
|
337
|
+
const chunks = [];
|
|
338
|
+
for (let at = 8; at < png.length; ) {
|
|
339
|
+
const len = png.readUInt32BE(at);
|
|
340
|
+
const kind = png.toString("latin1", at + 4, at + 8);
|
|
341
|
+
if (kind === "IDAT") chunks.push(png.subarray(at + 8, at + 8 + len));
|
|
342
|
+
at += len + 12;
|
|
343
|
+
}
|
|
344
|
+
const raw = inflateSync(Buffer.concat(chunks));
|
|
345
|
+
const stride = w * bpp;
|
|
346
|
+
let prev = Buffer.alloc(stride);
|
|
347
|
+
const counts = new Map();
|
|
348
|
+
for (let y = 0; y < h; y++) {
|
|
349
|
+
const filter = raw[y * (stride + 1)];
|
|
350
|
+
const line = Buffer.from(raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1)));
|
|
351
|
+
for (let i = 0; i < stride; i++) {
|
|
352
|
+
const a = i >= bpp ? line[i - bpp] : 0;
|
|
353
|
+
const b = prev[i];
|
|
354
|
+
const c = i >= bpp ? prev[i - bpp] : 0;
|
|
355
|
+
let add = 0;
|
|
356
|
+
if (filter === 1) add = a;
|
|
357
|
+
else if (filter === 2) add = b;
|
|
358
|
+
else if (filter === 3) add = (a + b) >> 1;
|
|
359
|
+
else if (filter === 4) {
|
|
360
|
+
const p = a + b - c;
|
|
361
|
+
const pa = Math.abs(p - a);
|
|
362
|
+
const pb = Math.abs(p - b);
|
|
363
|
+
const pc = Math.abs(p - c);
|
|
364
|
+
add = pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
365
|
+
}
|
|
366
|
+
line[i] = (line[i] + add) & 255;
|
|
367
|
+
}
|
|
368
|
+
for (let i = 0; i < stride; i += bpp) {
|
|
369
|
+
const key = ((line[i] >> 3) << 10) | ((line[i + 1] >> 3) << 5) | (line[i + 2] >> 3);
|
|
370
|
+
counts.set(key, (counts.get(key) || 0) + 1);
|
|
371
|
+
}
|
|
372
|
+
prev = line;
|
|
373
|
+
}
|
|
374
|
+
return Math.max(...counts.values()) / (w * h);
|
|
375
|
+
}
|
|
255
376
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
377
|
+
// How flat the screen is: a small PNG of what a person sees right now, or of
|
|
378
|
+
// the top of the full page once it has been laid out for the full shot.
|
|
379
|
+
const FLAT = 0.985;
|
|
380
|
+
const screenFlat = async (beyond = false) => {
|
|
381
|
+
const { data } = await page(
|
|
382
|
+
"Page.captureScreenshot",
|
|
383
|
+
{ format: "png", clip: { x: 0, y: 0, width, height, scale: 0.25 }, captureBeyondViewport: beyond },
|
|
384
|
+
20000,
|
|
385
|
+
);
|
|
386
|
+
return flatShare(Buffer.from(data, "base64"));
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// A loader is a fixed or absolute layer named like one that covers most of
|
|
390
|
+
// the screen, or a visible count to 100%. A canvas or a video is the page.
|
|
391
|
+
const loaderCheck = `(() => {
|
|
392
|
+
const vw = innerWidth, vh = innerHeight;
|
|
393
|
+
const named = /(^|[-_\\s])(pre-?)?load(er|ing)?([-_\\s]|$)|preload|intro|splash|curtain/i;
|
|
394
|
+
for (const el of document.body ? document.body.querySelectorAll("*") : []) {
|
|
395
|
+
if (el.tagName === "CANVAS" || el.tagName === "VIDEO") continue;
|
|
396
|
+
const label = ((typeof el.className === "string" ? el.className : "") + " " + el.id).trim();
|
|
397
|
+
const count = el.childElementCount === 0 && /^\\s*\\d{1,3}\\s*%\\s*$/.test(el.textContent || "");
|
|
398
|
+
if (!count && !named.test(label)) continue;
|
|
399
|
+
const s = getComputedStyle(el);
|
|
400
|
+
if (s.display === "none" || s.visibility === "hidden" || Number(s.opacity) < 0.05) continue;
|
|
401
|
+
if (!count && s.position !== "fixed" && s.position !== "absolute") continue;
|
|
402
|
+
const r = el.getBoundingClientRect();
|
|
403
|
+
const seen = Math.max(0, Math.min(r.right, vw) - Math.max(r.left, 0)) * Math.max(0, Math.min(r.bottom, vh) - Math.max(r.top, 0));
|
|
404
|
+
if (count ? seen > 0 : seen >= vw * vh * 0.6) return (label || el.tagName).slice(0, 60);
|
|
405
|
+
}
|
|
406
|
+
return "";
|
|
407
|
+
})()`;
|
|
408
|
+
|
|
409
|
+
// Waits for the load event and fonts, then until two checks in a row see no
|
|
410
|
+
// loader, a screen that is not one flat colour (or has stayed flat with the
|
|
411
|
+
// network quiet for 2.5 s), and no request for a second.
|
|
412
|
+
// Returns why it gave up.
|
|
413
|
+
async function settle() {
|
|
414
|
+
const start = Date.now();
|
|
415
|
+
const left = () => Math.max(0, maxWait - (Date.now() - start));
|
|
416
|
+
await evalValue(
|
|
417
|
+
`new Promise((done) => {
|
|
418
|
+
const t = setTimeout(done, ${Math.max(1500, Math.min(maxWait, 20000))});
|
|
419
|
+
const fonts = () => (document.fonts ? document.fonts.ready : Promise.resolve()).then(() => { clearTimeout(t); done(); });
|
|
420
|
+
if (document.readyState === "complete") fonts(); else addEventListener("load", fonts, { once: true });
|
|
421
|
+
})`,
|
|
422
|
+
25000,
|
|
423
|
+
).catch(() => {});
|
|
424
|
+
const busy = () => {
|
|
425
|
+
for (const [id, at] of inflight) if (Date.now() - at > 10000) inflight.delete(id);
|
|
426
|
+
return inflight.size > 0 || Date.now() - lastNetwork < 1000;
|
|
427
|
+
};
|
|
428
|
+
let good = 0;
|
|
429
|
+
let fetched = false;
|
|
430
|
+
let flatSince = 0;
|
|
431
|
+
for (;;) {
|
|
432
|
+
const loader = await evalValue(loaderCheck).catch(() => "");
|
|
433
|
+
const flat = loader ? 1 : await screenFlat().catch(() => 0);
|
|
434
|
+
const fetching = busy();
|
|
435
|
+
fetched ||= fetching;
|
|
436
|
+
// A flat screen with nothing left to fetch for 2.5 s is a sparse page, not a loader.
|
|
437
|
+
flatSince = flat >= FLAT && !loader && !fetching ? flatSince || Date.now() : 0;
|
|
438
|
+
const sparse = flatSince && Date.now() - flatSince >= 2500;
|
|
439
|
+
good = !loader && !fetching && (flat < FLAT || sparse) ? good + 1 : 0;
|
|
440
|
+
if (good >= 2) break;
|
|
441
|
+
if (!left()) {
|
|
442
|
+
return loader
|
|
443
|
+
? `a loader still covers the screen (${loader})`
|
|
444
|
+
: flat >= FLAT
|
|
445
|
+
? "the screen is still one flat colour"
|
|
446
|
+
: "the page is still fetching";
|
|
263
447
|
}
|
|
264
|
-
|
|
265
|
-
|
|
448
|
+
await sleep(Math.min(500, left()));
|
|
449
|
+
}
|
|
450
|
+
// A loader that waited on its assets usually plays a reveal once they land.
|
|
451
|
+
if (fetched && !local) await sleep(Math.min(1500, left()));
|
|
452
|
+
return "";
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Clicks a consent button, which can be any element, or else strips a short
|
|
456
|
+
// privacy notice. Rejecting comes first: a script has no use for tracking,
|
|
457
|
+
// and accepting can start scripts that redraw the page.
|
|
458
|
+
// A local page is a state someone set up on purpose, so it is left as it is.
|
|
459
|
+
const dismissConsent = () =>
|
|
460
|
+
local ? Promise.resolve(false) : evalValue(`(() => {
|
|
461
|
+
const accept = /^(accept( all)?( cookies)?|accept (and|&) close|agree|i agree|ok|okay|got it|allow( all)?( cookies)?|i understand|acepto|aceptar)$/i;
|
|
462
|
+
const reject = /^(reject( all)?( cookies)?|decline( all)?|deny|only (essential|necessary)( cookies)?)$/i;
|
|
463
|
+
const clickable = [...document.querySelectorAll("button, [role=button], a, input[type=button], input[type=submit], [onclick], div, span")]
|
|
464
|
+
.filter((el) => el.childElementCount <= 2 && el.getClientRects().length);
|
|
465
|
+
// Only inside a notice about cookies or privacy, so a menu or a gate is never clicked.
|
|
466
|
+
const notice = (el) => {
|
|
467
|
+
for (let up = el, i = 0; up && i < 8; up = up.parentElement, i++) {
|
|
468
|
+
const t = up.innerText || "";
|
|
469
|
+
if (t.length < 1500 && /cookie|consent|privacy|gdpr|datenschutz/i.test(t)) return true;
|
|
470
|
+
}
|
|
471
|
+
return false;
|
|
472
|
+
};
|
|
473
|
+
const text = (el) => (el.innerText || el.value || el.textContent || "").trim().replace(/\\s+/g, " ");
|
|
474
|
+
const pick = (re) => clickable.find((el) => text(el).length < 40 && re.test(text(el)) && notice(el));
|
|
475
|
+
const hit = pick(reject) || pick(accept);
|
|
476
|
+
if (hit) {
|
|
477
|
+
hit.click();
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
// No button: strip a short privacy notice that floats over the page (e.g.
|
|
481
|
+
// Google Fonts "×" banner). Only a fixed or sticky layer with no canvas or
|
|
482
|
+
// video, because a wrapper whose only text is the notice can hold the page.
|
|
483
|
+
const privacy = /uses cookies|uses essential cookies|privacy and google fonts|cookie settings/i;
|
|
266
484
|
for (const el of [...document.querySelectorAll("div, section, aside, dialog")]) {
|
|
267
485
|
const t = (el.innerText || el.textContent || "").trim();
|
|
268
|
-
|
|
486
|
+
const pos = getComputedStyle(el).position;
|
|
487
|
+
if (t.length > 0 && t.length < 300 && privacy.test(t) && el.children.length < 12 &&
|
|
488
|
+
(pos === "fixed" || pos === "sticky") && !el.querySelector("canvas, video")) {
|
|
269
489
|
el.remove();
|
|
270
490
|
}
|
|
271
491
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
returnByValue: true,
|
|
275
|
-
});
|
|
276
|
-
await sleep(800);
|
|
492
|
+
return false;
|
|
493
|
+
})()`).catch(() => false);
|
|
277
494
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
)
|
|
495
|
+
// A real press and release in the middle of the element, as a person would click.
|
|
496
|
+
async function clickOn(selector) {
|
|
497
|
+
const box = await evalValue(`(() => {
|
|
498
|
+
const el = document.querySelector(${JSON.stringify(selector)});
|
|
499
|
+
if (!el) return null;
|
|
500
|
+
el.scrollIntoView({ block: "center", inline: "center" });
|
|
501
|
+
const r = el.getBoundingClientRect();
|
|
502
|
+
return r.width && r.height ? { x: r.left + r.width / 2, y: r.top + r.height / 2 } : null;
|
|
503
|
+
})()`);
|
|
504
|
+
if (!box) {
|
|
505
|
+
console.error(`no visible element matches ${selector}`);
|
|
506
|
+
drop();
|
|
507
|
+
process.exit(1);
|
|
508
|
+
}
|
|
509
|
+
const at = { x: Math.round(box.x), y: Math.round(box.y), button: "left", clickCount: 1 };
|
|
510
|
+
await page("Input.dispatchMouseEvent", { type: "mouseMoved", x: at.x, y: at.y });
|
|
511
|
+
await page("Input.dispatchMouseEvent", { type: "mousePressed", ...at });
|
|
512
|
+
await page("Input.dispatchMouseEvent", { type: "mouseReleased", ...at });
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const navigateStarted = Date.now();
|
|
516
|
+
await page("Page.navigate", { url: target }, 40000);
|
|
517
|
+
|
|
518
|
+
if (frames) {
|
|
519
|
+
// The frames are the record of motion, so nothing is paused, unstuck or cleaned up.
|
|
520
|
+
const folder = out.replace(/\.(png|jpe?g|webp)$/i, "");
|
|
521
|
+
mkdirSync(folder, { recursive: true });
|
|
522
|
+
let t0 = navigateStarted;
|
|
523
|
+
if (scrollFrames || clickArg) {
|
|
524
|
+
const why = await settle();
|
|
525
|
+
if (why) console.error(`waited ${maxWait} ms: ${why}`);
|
|
526
|
+
if (await dismissConsent()) {
|
|
527
|
+
await sleep(800);
|
|
528
|
+
await settle();
|
|
529
|
+
}
|
|
530
|
+
await sleep(600);
|
|
531
|
+
t0 = Date.now();
|
|
532
|
+
}
|
|
533
|
+
for (let i = 0; i < frames; i++) {
|
|
534
|
+
const due = t0 + i * every;
|
|
535
|
+
if (Date.now() < due) await sleep(due - Date.now());
|
|
536
|
+
if (scrollFrames && i > 0) {
|
|
537
|
+
await page("Input.dispatchMouseEvent", { type: "mouseWheel", x: Math.round(width / 2), y: Math.round(height / 2), deltaX: 0, deltaY: Math.round(height / 2) });
|
|
538
|
+
}
|
|
539
|
+
// While the page is still swapping in, Chrome refuses a shot for a moment.
|
|
540
|
+
let data = "";
|
|
541
|
+
for (let tries = 0; !data && tries < 10; tries++) {
|
|
542
|
+
data = await page("Page.captureScreenshot", { format: "jpeg", quality: 70 }, 20000).then((r) => r.data, () => "");
|
|
543
|
+
if (!data) await sleep(150);
|
|
544
|
+
}
|
|
545
|
+
if (!data) continue;
|
|
546
|
+
const at = Date.now() - t0;
|
|
547
|
+
const file = join(folder, `${String(i + 1).padStart(2, "0")}-${String(at).padStart(5, "0")}ms.jpg`);
|
|
548
|
+
writeFileSync(file, Buffer.from(data, "base64"));
|
|
549
|
+
// The first frame is the page before the click; the rest are what it does.
|
|
550
|
+
if (clickArg && i === 0) await clickOn(clickArg);
|
|
551
|
+
}
|
|
552
|
+
console.log(folder);
|
|
553
|
+
drop();
|
|
554
|
+
process.exit(0);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const waited = await settle();
|
|
558
|
+
if (waited) console.error(`waited ${maxWait} ms: ${waited}`);
|
|
559
|
+
|
|
560
|
+
const beforeHref = await evalValue("location.href");
|
|
561
|
+
// A consent click can make a page redraw from black, so the wait runs again.
|
|
562
|
+
if (await dismissConsent()) {
|
|
563
|
+
await sleep(800);
|
|
564
|
+
const again = await settle();
|
|
565
|
+
if (again) console.error(`after the consent click, waited ${maxWait} ms: ${again}`);
|
|
566
|
+
} else await sleep(800);
|
|
567
|
+
const afterHref = await evalValue("location.href");
|
|
284
568
|
|
|
285
569
|
if (afterHref !== beforeHref) {
|
|
286
570
|
console.error(`navigated away: ${afterHref}`);
|
|
@@ -288,6 +572,26 @@ if (afterHref !== beforeHref) {
|
|
|
288
572
|
process.exit(1);
|
|
289
573
|
}
|
|
290
574
|
|
|
575
|
+
// After a click the page is a new state, often an overlay: the screen is the shot.
|
|
576
|
+
if (clickArg) {
|
|
577
|
+
await clickOn(clickArg);
|
|
578
|
+
await sleep(1500);
|
|
579
|
+
const format = /\.png$/i.test(out) ? "png" : /\.webp$/i.test(out) ? "webp" : "jpeg";
|
|
580
|
+
const { data } = await page("Page.captureScreenshot", { format, ...(format === "png" ? {} : { quality: 70 }) }, 20000);
|
|
581
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
582
|
+
writeFileSync(out, Buffer.from(data, "base64"));
|
|
583
|
+
console.log(out);
|
|
584
|
+
drop();
|
|
585
|
+
process.exit(0);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// The screen as a person first sees it, kept in case the full page loses it.
|
|
589
|
+
const firstFormat = /\.png$/i.test(out) ? "png" : /\.webp$/i.test(out) ? "webp" : "jpeg";
|
|
590
|
+
const firstScreen = (
|
|
591
|
+
await page("Page.captureScreenshot", { format: firstFormat, ...(firstFormat === "png" ? {} : { quality: 70 }) }, 20000)
|
|
592
|
+
).data;
|
|
593
|
+
const firstFlat = await screenFlat().catch(() => 1);
|
|
594
|
+
|
|
291
595
|
await page(
|
|
292
596
|
"Runtime.evaluate",
|
|
293
597
|
{
|
|
@@ -300,7 +604,7 @@ await page(
|
|
|
300
604
|
const step = Math.max(480, Math.round(window.innerHeight * 0.65));
|
|
301
605
|
const limit = Math.min(
|
|
302
606
|
Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight || 0),
|
|
303
|
-
|
|
607
|
+
${tallest}
|
|
304
608
|
);
|
|
305
609
|
let y = 0;
|
|
306
610
|
while (y < limit) {
|
|
@@ -396,7 +700,7 @@ if (clipSelector) {
|
|
|
396
700
|
const metrics = await page("Page.getLayoutMetrics");
|
|
397
701
|
const size = metrics.cssContentSize || metrics.contentSize;
|
|
398
702
|
const fullWidth = Math.max(1, Math.ceil(size.width || width));
|
|
399
|
-
const fullHeight = Math.max(1, Math.min(Math.ceil(size.height || height),
|
|
703
|
+
const fullHeight = Math.max(1, Math.min(Math.ceil(size.height || height), tallest));
|
|
400
704
|
const clipBox = clip || (selected ? { ...selected, scale: 1 } : null);
|
|
401
705
|
const shotClip = clipBox
|
|
402
706
|
? {
|
|
@@ -410,7 +714,7 @@ const shotClip = clipBox
|
|
|
410
714
|
|
|
411
715
|
// The file is what its name says, so a reader that trusts the extension is right.
|
|
412
716
|
const format = /\.png$/i.test(out) ? "png" : /\.webp$/i.test(out) ? "webp" : "jpeg";
|
|
413
|
-
|
|
717
|
+
let { data } = await page(
|
|
414
718
|
"Page.captureScreenshot",
|
|
415
719
|
{
|
|
416
720
|
format,
|
|
@@ -421,6 +725,22 @@ const { data } = await page(
|
|
|
421
725
|
60000,
|
|
422
726
|
);
|
|
423
727
|
|
|
728
|
+
// A canvas that draws only what is on screen goes blank when the page is laid
|
|
729
|
+
// out full length. Then the screen seen first is the honest shot, and the
|
|
730
|
+
// full page is kept beside it for what lies below.
|
|
731
|
+
let fullOut = "";
|
|
732
|
+
if (!clipBox && firstFlat < FLAT && (await screenFlat(true).catch(() => 0)) >= FLAT) {
|
|
733
|
+
if (fullHeight > height * 1.2) {
|
|
734
|
+
fullOut = out.replace(/(\.[a-z]+)?$/i, (ext) => `-full${ext || ".jpg"}`);
|
|
735
|
+
mkdirSync(dirname(fullOut), { recursive: true });
|
|
736
|
+
writeFileSync(fullOut, Buffer.from(data, "base64"));
|
|
737
|
+
}
|
|
738
|
+
data = firstScreen;
|
|
739
|
+
console.error(
|
|
740
|
+
`the full page came back blank at the top (a canvas that draws only what is on screen): kept the first screen${fullOut ? `, and the full page as ${fullOut}` : ""}`,
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
424
744
|
mkdirSync(dirname(out), { recursive: true });
|
|
425
745
|
writeFileSync(out, Buffer.from(data, "base64"));
|
|
426
746
|
console.log(out);
|