@geonosis/walk 2.12.0 → 3.0.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/CHANGELOG.md +8 -0
- package/bin/geonosis-walk.mjs +7 -192
- package/dist/browser.d.ts +124 -0
- package/dist/browser.js +242 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +100 -0
- package/dist/index.d.ts +7 -153
- package/dist/index.js +5 -13
- package/dist/options.d.ts +19 -0
- package/dist/options.js +64 -0
- package/dist/probes/buy-box-above-fold.d.ts +14 -0
- package/dist/probes/buy-box-above-fold.js +54 -0
- package/dist/probes/empty-section.d.ts +16 -0
- package/dist/probes/empty-section.js +29 -0
- package/dist/probes/error-page-status.d.ts +20 -0
- package/dist/probes/error-page-status.js +37 -0
- package/dist/probes/fabricated-claim.d.ts +14 -0
- package/dist/probes/fabricated-claim.js +29 -0
- package/dist/probes/fake-session.d.ts +14 -0
- package/dist/probes/fake-session.js +45 -0
- package/dist/probes/index.d.ts +9 -0
- package/dist/probes/index.js +42 -0
- package/dist/probes/light-on-light.d.ts +15 -0
- package/dist/probes/light-on-light.js +26 -0
- package/dist/probes/link-integrity.d.ts +14 -0
- package/dist/probes/link-integrity.js +69 -0
- package/dist/probes/money-format.d.ts +14 -0
- package/dist/probes/money-format.js +33 -0
- package/dist/probes/ops-leakage.d.ts +13 -0
- package/dist/probes/ops-leakage.js +29 -0
- package/dist/probes/orphan-url.d.ts +13 -0
- package/dist/probes/orphan-url.js +54 -0
- package/dist/probes/placeholder-asset.d.ts +14 -0
- package/dist/probes/placeholder-asset.js +40 -0
- package/dist/probes/stub-only-entity.d.ts +14 -0
- package/dist/probes/stub-only-entity.js +30 -0
- package/dist/probes/thin-page.d.ts +14 -0
- package/dist/probes/thin-page.js +30 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +10 -0
- package/dist/walk-cli.js +41 -47
- package/dist/walk.d.ts +23 -0
- package/dist/walk.js +93 -0
- package/package.json +5 -4
- package/dist/chunk-VCGYSFL5.js +0 -956
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @geonosis/walk
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1e38e4e: `geonosis-themekit`, `geonosis-rails` and `geonosis-evals` read their arguments with `node:util`'s `parseArgs`. A flag one does not know is refused by name, exit 2, where the hand-written readers ignored it and ran without it; a flag given twice keeps its last value in all three (evals kept the first). `geonosis-evals compare --tolerance x=0.1 a.json b.json` reads `a.json` and `b.json` as the scores: the old reader took the tolerance's value for the first score file. `geonosis-ratchet` and `geonosis-verify`, which already refused what they did not know, read their flags the same way; verify still refuses a flag that belongs to another of its commands. `geonosis-doctor` reads its flags with `parseArgs` too, its optional `--baseline-against` ref through the parser's tokens. `@geonosis/ledger`'s exported `parseArgs(argv, valued, switches)` is `node:util`'s underneath and takes the switches it accepts, refusing an undeclared one and a valued flag followed by another flag (`--note --plan 3` used to store `--plan` as the note); `rejectUnknownSwitches` is gone. `geonosis-walk`, `geonosis-review` and `geonosis-lint-parity` parse the same way; parity keeps its own words for a bare `--corpus` or `--expect-changed`. `geonosis-observability`, `geonosis-verify-arch`, `geonosis-testbed` and `geonosis-visual-diff` follow; the last two used to accept a flag they did not know (testbed ignored it, visual-diff read it as a switch) and now refuse it. `@geonosis/release`'s exported `parseArgs` keeps its `Parsed` shape over `node:util`'s. `@geonosis/cli`'s `parseArgv` and `create-geonosis`'s `parseArgs` are built on it too, keeping their own refusals; `parseArgv` now refuses a valued flag followed by another flag instead of taking that flag as its value.
|
|
8
|
+
|
|
9
|
+
## 2.13.0
|
|
10
|
+
|
|
3
11
|
## 2.12.0
|
|
4
12
|
|
|
5
13
|
## 2.11.1
|
package/bin/geonosis-walk.mjs
CHANGED
|
@@ -1,196 +1,11 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// than src answered for a fix it did not carry once (#62); the published package ships no src, so
|
|
6
|
-
// there the check is skipped.
|
|
7
|
-
import { createHash } from 'node:crypto'
|
|
8
|
-
import {
|
|
9
|
-
existsSync,
|
|
10
|
-
mkdirSync,
|
|
11
|
-
readdirSync,
|
|
12
|
-
readFileSync,
|
|
13
|
-
realpathSync,
|
|
14
|
-
statSync,
|
|
15
|
-
writeFileSync
|
|
16
|
-
} from 'node:fs'
|
|
17
|
-
import { dirname, join } from 'node:path'
|
|
18
|
-
import { fileURLToPath } from 'node:url'
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// Generated by pnpm generate:shims. In the kit's own tree src/ sits beside dist/, and a dist older
|
|
3
|
+
// than src once answered for a fix it did not carry (#62); a published package ships no src/.
|
|
4
|
+
import { existsSync } from 'node:fs'
|
|
19
5
|
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
// not gone stale (#399).
|
|
24
|
-
const NOT_SOURCE = (name) =>
|
|
25
|
-
name.endsWith('.test.ts') ||
|
|
26
|
-
name.endsWith('.test.tsx') ||
|
|
27
|
-
name === '__tests__' ||
|
|
28
|
-
name === '__fixtures__'
|
|
29
|
-
const newest = (dir, skip) =>
|
|
30
|
-
existsSync(dir)
|
|
31
|
-
? readdirSync(dir, { withFileTypes: true }).reduce((most, entry) => {
|
|
32
|
-
if (skip !== undefined && skip(entry.name)) return most
|
|
33
|
-
const at = join(dir, entry.name)
|
|
34
|
-
return Math.max(most, entry.isDirectory() ? newest(at, skip) : statSync(at).mtimeMs)
|
|
35
|
-
}, 0)
|
|
36
|
-
: 0
|
|
37
|
-
const digestOf = (dir, hash) => {
|
|
38
|
-
for (const name of readdirSync(dir).toSorted()) {
|
|
39
|
-
if (NOT_SOURCE(name)) continue
|
|
40
|
-
const at = join(dir, name)
|
|
41
|
-
if (statSync(at).isDirectory()) {
|
|
42
|
-
digestOf(at, hash)
|
|
43
|
-
continue
|
|
44
|
-
}
|
|
45
|
-
hash.update(name).update('\0').update(readFileSync(at)).update('\0')
|
|
46
|
-
}
|
|
47
|
-
return hash
|
|
48
|
-
}
|
|
49
|
-
const digest = (...dirs) => {
|
|
50
|
-
const hash = createHash('sha256')
|
|
51
|
-
for (const dir of dirs) if (existsSync(dir)) digestOf(dir, hash)
|
|
52
|
-
return hash.digest('hex')
|
|
53
|
-
}
|
|
54
|
-
// mtime says a source file was WRITTEN, not that it CHANGED. A checkout rewrites it with the same
|
|
55
|
-
// content, and the next `pnpm build` is a cache hit that leaves the current dist exactly as it
|
|
56
|
-
// was — so every bin refused with "run pnpm build", the action that had just changed nothing and
|
|
57
|
-
// would change nothing again. So a digest of the sources is kept from the last run that found
|
|
58
|
-
// dist current: the same digest later is the same sources, whatever their timestamps say, and a
|
|
59
|
-
// different one is the staleness this guard exists for. The newest mtime is kept beside it so a
|
|
60
|
-
// run over untouched sources need not hash them again. The second line is the same record for
|
|
61
|
-
// the dists of the workspace dependencies this build read (row 584, below).
|
|
62
|
-
const recordOf = (pkg) => join(pkg, '.turbo', 'geonosis-src-digest')
|
|
63
|
-
const recorded = (pkg) => {
|
|
64
|
-
try {
|
|
65
|
-
const [first = '', second = ''] = readFileSync(recordOf(pkg), 'utf8').split('\n')
|
|
66
|
-
const [seen = '', sum = ''] = first.trim().split(' ')
|
|
67
|
-
const [depsSeen = '', depsSum = ''] = second.trim().split(' ')
|
|
68
|
-
return { depsSeen: Number(depsSeen), depsSum, seen: Number(seen), sum }
|
|
69
|
-
} catch {
|
|
70
|
-
return { depsSeen: 0, depsSum: '', seen: 0, sum: '' }
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const remember = (pkg, known) => {
|
|
74
|
-
try {
|
|
75
|
-
mkdirSync(dirname(recordOf(pkg)), { recursive: true })
|
|
76
|
-
writeFileSync(recordOf(pkg), `${known.seen} ${known.sum}\n${known.depsSeen} ${known.depsSum}\n`)
|
|
77
|
-
} catch {
|
|
78
|
-
// A record nothing could write costs one more hash next time, never a wrong answer.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// The refusal names a package for turbo's --filter. A manifest that cannot be read costs the
|
|
82
|
-
// name, never the decision: the first digest shim threw here — exit 1 and a node:fs frame — over a
|
|
83
|
-
// tree with no package.json, and a guard that throws neither answers nor refuses.
|
|
84
|
-
const manifestOf = (pkg) => {
|
|
85
|
-
try {
|
|
86
|
-
return JSON.parse(readFileSync(join(pkg, 'package.json'), 'utf8'))
|
|
87
|
-
} catch {
|
|
88
|
-
return {}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const refuse = (sentence) => {
|
|
92
|
-
process.stderr.write(`geonosis-walk: ${sentence}\n`)
|
|
93
|
-
process.exit(2)
|
|
94
|
-
}
|
|
95
|
-
// Whether one package's dist reflects its src: 'unbuilt', 'stale' or 'current'. The same reading
|
|
96
|
-
// for this package and for each workspace dependency, off that package's own record.
|
|
97
|
-
const standing = (pkg) => {
|
|
98
|
-
const src = join(pkg, 'src')
|
|
99
|
-
const dist = join(pkg, 'dist')
|
|
100
|
-
if (!existsSync(src)) return 'current'
|
|
101
|
-
const built = newest(dist)
|
|
102
|
-
if (built === 0) return 'unbuilt'
|
|
103
|
-
const written = newest(src, NOT_SOURCE)
|
|
104
|
-
const known = recorded(pkg)
|
|
105
|
-
if (written > built) {
|
|
106
|
-
const sum = known.seen === written ? known.sum : digest(src)
|
|
107
|
-
if (sum !== known.sum) return 'stale'
|
|
108
|
-
if (known.seen !== written) remember(pkg, { ...known, seen: written, sum })
|
|
109
|
-
} else if (known.seen !== written) {
|
|
110
|
-
remember(pkg, { ...known, seen: written, sum: digest(src) })
|
|
111
|
-
}
|
|
112
|
-
return 'current'
|
|
113
|
-
}
|
|
114
|
-
// Row 584: a dist current against its own src can still have been built against an OLDER
|
|
115
|
-
// dependency's dist — literally, when tsup inlined a workspace devDependency into it — and a
|
|
116
|
-
// dependency whose src has moved past its dist is read by this dist stale, inlined or imported.
|
|
117
|
-
// So every workspace dependency this manifest names (`workspace:`, resolved through the link pnpm
|
|
118
|
-
// made, transitively) is held to the same reading as this package, and this dist must not be
|
|
119
|
-
// older than any of theirs — by content: a dependency rebuilt to the same bytes is the same build,
|
|
120
|
-
// so the `--force --filter` escape below cannot poison the tree it was run in.
|
|
121
|
-
const workspaceDependencies = (pkg, found = new Map()) => {
|
|
122
|
-
const manifest = manifestOf(pkg)
|
|
123
|
-
for (const block of [
|
|
124
|
-
manifest.dependencies,
|
|
125
|
-
manifest.devDependencies,
|
|
126
|
-
manifest.optionalDependencies,
|
|
127
|
-
manifest.peerDependencies
|
|
128
|
-
]) {
|
|
129
|
-
for (const [name, range] of Object.entries(block ?? {})) {
|
|
130
|
-
if (typeof range !== 'string' || !range.startsWith('workspace:')) continue
|
|
131
|
-
let dir
|
|
132
|
-
try {
|
|
133
|
-
dir = realpathSync(join(pkg, 'node_modules', name))
|
|
134
|
-
} catch {
|
|
135
|
-
continue // Not linked: the import will say so far more loudly than this guard can.
|
|
136
|
-
}
|
|
137
|
-
if (found.has(dir)) continue
|
|
138
|
-
found.set(dir, name)
|
|
139
|
-
workspaceDependencies(dir, found)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return found
|
|
143
|
-
}
|
|
144
|
-
// `newest` answers 0 for a directory that is NOT THERE and for one that is merely old, so the
|
|
145
|
-
// two conditions were one comparison and one sentence — and the staleness sentence was printed
|
|
146
|
-
// over trees that had never been built at all, blocking a turn in a fresh git worktree, which
|
|
147
|
-
// has no dist because dist is not committed (#357). Only the second is evidence of a mistake.
|
|
148
|
-
if (existsSync(join(own, 'src'))) {
|
|
149
|
-
const built = newest(join(own, 'dist'))
|
|
150
|
-
if (built === 0) {
|
|
151
|
-
refuse(
|
|
152
|
-
'this tree has never been built — run pnpm build. No dist here at all, which is what a fresh clone or a linked git worktree starts with; nothing is stale.'
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
const name = manifestOf(own).name ?? '<this package>'
|
|
156
|
-
if (standing(own) === 'stale') {
|
|
157
|
-
refuse(
|
|
158
|
-
`dist is older than src — run pnpm build before trusting this bin. If that build just said FULL TURBO, the cache hit left a current dist with its old timestamp and this bin had not yet recorded the sources it was current for: pnpm build --force --filter=${name} rebuilds this one package and clears it.`
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
const dependencies = workspaceDependencies(own)
|
|
162
|
-
const dists = new Map()
|
|
163
|
-
for (const [dir, dependency] of dependencies) {
|
|
164
|
-
const state = standing(dir)
|
|
165
|
-
if (state === 'unbuilt') {
|
|
166
|
-
refuse(
|
|
167
|
-
`${dependency}, which this dist reads, has never been built — run pnpm build. No dist there at all; nothing is stale.`
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
if (state === 'stale') {
|
|
171
|
-
refuse(
|
|
172
|
-
`${dependency}'s dist is older than its src, and this dist reads that dist — run pnpm build before trusting this bin. If that build just said FULL TURBO, the cache hit left that dist current with its old timestamp and nothing had yet recorded the sources it was current for: pnpm build --force --filter=${dependency} rebuilds that one package and clears it.`
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
dists.set(join(dir, 'dist'), dependency)
|
|
176
|
-
}
|
|
177
|
-
if (dists.size > 0) {
|
|
178
|
-
const known = recorded(own)
|
|
179
|
-
const theirs = [...dists.keys()].toSorted()
|
|
180
|
-
const depsNewest = theirs.reduce((most, dist) => Math.max(most, newest(dist)), 0)
|
|
181
|
-
if (depsNewest > built) {
|
|
182
|
-
const depsSum = known.depsSeen === depsNewest ? known.depsSum : digest(...theirs)
|
|
183
|
-
if (depsSum !== known.depsSum) {
|
|
184
|
-
const newer = theirs.filter((dist) => newest(dist) > built).map((dist) => dists.get(dist))
|
|
185
|
-
refuse(
|
|
186
|
-
`dist was built before the current dist of ${newer.join(', ')}, which it reads — run pnpm build before trusting this bin. If that build just said FULL TURBO, the dependency was rebuilt alone and this bin had not yet recorded the build it was current against: pnpm build --force --filter=${name} rebuilds this one package against it.`
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
if (known.depsSeen !== depsNewest) remember(own, { ...known, depsSeen: depsNewest, depsSum })
|
|
190
|
-
} else if (known.depsSeen !== depsNewest) {
|
|
191
|
-
remember(own, { ...known, depsSeen: depsNewest, depsSum: digest(...theirs) })
|
|
192
|
-
}
|
|
193
|
-
}
|
|
6
|
+
if (existsSync(new URL('../src', import.meta.url))) {
|
|
7
|
+
const { guardBuild } = await import('../../../tooling/bin-guard.mjs')
|
|
8
|
+
guardBuild(new URL('..', import.meta.url), 'geonosis-walk')
|
|
194
9
|
}
|
|
195
10
|
|
|
196
11
|
await import('../dist/walk-cli.js')
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Page } from 'playwright';
|
|
2
|
+
/**
|
|
3
|
+
* The browser's own globals, declared here rather than by adding `"lib": ["DOM"]`.
|
|
4
|
+
*
|
|
5
|
+
* The repo typechecks eleven packages against one `tsconfig.base.json`; turning the DOM on for all
|
|
6
|
+
* of them so that this one file can say `document` would put `fetch`, `Response` and `Request` into
|
|
7
|
+
* ten Node packages that have their own. So the surface these probes actually read is written out,
|
|
8
|
+
* module-locally — it leaks into nothing, and it is a list of exactly what the walk touches.
|
|
9
|
+
*/
|
|
10
|
+
type DomRect = {
|
|
11
|
+
height: number;
|
|
12
|
+
left: number;
|
|
13
|
+
top: number;
|
|
14
|
+
width: number;
|
|
15
|
+
};
|
|
16
|
+
export type ContrastHit = {
|
|
17
|
+
background: string;
|
|
18
|
+
container: string;
|
|
19
|
+
containerSelector: string;
|
|
20
|
+
contrast: number;
|
|
21
|
+
selector: string;
|
|
22
|
+
};
|
|
23
|
+
export type AssetHit = {
|
|
24
|
+
label: string;
|
|
25
|
+
selector: string;
|
|
26
|
+
signature: string;
|
|
27
|
+
};
|
|
28
|
+
export type LinkHit = {
|
|
29
|
+
href: null | string;
|
|
30
|
+
resolved: string;
|
|
31
|
+
selector: string;
|
|
32
|
+
text: string;
|
|
33
|
+
};
|
|
34
|
+
export type TextHit = {
|
|
35
|
+
pattern: string;
|
|
36
|
+
selector: string;
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
export type EntityHit = {
|
|
40
|
+
affordance: boolean;
|
|
41
|
+
id: string;
|
|
42
|
+
selector: string;
|
|
43
|
+
};
|
|
44
|
+
export type PresentHit = {
|
|
45
|
+
present: boolean;
|
|
46
|
+
selector: string;
|
|
47
|
+
};
|
|
48
|
+
export type GeometryHit = {
|
|
49
|
+
rect: DomRect | null;
|
|
50
|
+
selector: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* How much a container actually says, counted after layout: the words a reader is shown, how many
|
|
54
|
+
* of them are its own headings, and how many pieces of media stand in for the rest. A section with
|
|
55
|
+
* a heading and nothing under it renders perfectly and tells nobody anything.
|
|
56
|
+
*/
|
|
57
|
+
export type ProseHit = {
|
|
58
|
+
headingWords: number;
|
|
59
|
+
media: number;
|
|
60
|
+
selector: string;
|
|
61
|
+
words: number;
|
|
62
|
+
};
|
|
63
|
+
export type Job = {
|
|
64
|
+
assetSelector: string;
|
|
65
|
+
kind: 'assets';
|
|
66
|
+
scope: string;
|
|
67
|
+
} | {
|
|
68
|
+
affordance: string;
|
|
69
|
+
attribute: string;
|
|
70
|
+
kind: 'entities';
|
|
71
|
+
selector: string;
|
|
72
|
+
} | {
|
|
73
|
+
flags: string;
|
|
74
|
+
kind: 'text';
|
|
75
|
+
patterns: string[];
|
|
76
|
+
scope: string;
|
|
77
|
+
} | {
|
|
78
|
+
kind: 'contrast';
|
|
79
|
+
ignore: string[];
|
|
80
|
+
minContrast: number;
|
|
81
|
+
selector: string;
|
|
82
|
+
} | {
|
|
83
|
+
kind: 'geometry';
|
|
84
|
+
selectors: string[];
|
|
85
|
+
} | {
|
|
86
|
+
kind: 'links';
|
|
87
|
+
selector: string;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'present';
|
|
90
|
+
selectors: string[];
|
|
91
|
+
} | {
|
|
92
|
+
headingSelector: string;
|
|
93
|
+
kind: 'prose';
|
|
94
|
+
mediaSelector: string;
|
|
95
|
+
selector: string;
|
|
96
|
+
} | {
|
|
97
|
+
flags: string;
|
|
98
|
+
kind: 'matches';
|
|
99
|
+
patterns: string[];
|
|
100
|
+
scope: string;
|
|
101
|
+
};
|
|
102
|
+
export type JobResult = {
|
|
103
|
+
assets: AssetHit[];
|
|
104
|
+
contrast: ContrastHit[];
|
|
105
|
+
entities: EntityHit[];
|
|
106
|
+
geometry: {
|
|
107
|
+
rects: GeometryHit[];
|
|
108
|
+
viewportHeight: number;
|
|
109
|
+
};
|
|
110
|
+
links: LinkHit[];
|
|
111
|
+
matches: TextHit[];
|
|
112
|
+
present: PresentHit[];
|
|
113
|
+
prose: ProseHit[];
|
|
114
|
+
text: TextHit[];
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The one cast in the package. `page.evaluate` runs `inPage` in another VM, so nothing about the
|
|
118
|
+
* value that comes back is checkable from here — the discriminant is the contract, and it is
|
|
119
|
+
* covered by the probe tests that read each shape through a real browser.
|
|
120
|
+
*/
|
|
121
|
+
export declare const collect: <K extends Job['kind']>(page: Page, job: Extract<Job, {
|
|
122
|
+
kind: K;
|
|
123
|
+
}>) => Promise<JobResult[K]>;
|
|
124
|
+
export {};
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// src/browser.ts
|
|
2
|
+
var inPage = (job) => {
|
|
3
|
+
const dom = {
|
|
4
|
+
deepest: (root, needle) => {
|
|
5
|
+
let node = root;
|
|
6
|
+
let moved = true;
|
|
7
|
+
while (moved) {
|
|
8
|
+
moved = false;
|
|
9
|
+
for (const child of node.children) {
|
|
10
|
+
if (dom.textOf(child).includes(needle)) {
|
|
11
|
+
node = child;
|
|
12
|
+
moved = true;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return node;
|
|
18
|
+
},
|
|
19
|
+
rectOf: (element) => {
|
|
20
|
+
const box = element.getBoundingClientRect();
|
|
21
|
+
return { height: box.height, left: box.left, top: box.top, width: box.width };
|
|
22
|
+
},
|
|
23
|
+
selectorOf: (element) => {
|
|
24
|
+
if (element.id !== "")
|
|
25
|
+
return `#${element.id}`;
|
|
26
|
+
const testId = element.getAttribute("data-testid");
|
|
27
|
+
if (testId !== null && testId !== "")
|
|
28
|
+
return `[data-testid="${testId}"]`;
|
|
29
|
+
const parts = [];
|
|
30
|
+
let node = element;
|
|
31
|
+
while (node !== null && parts.length < 5 && node.tagName !== "BODY") {
|
|
32
|
+
const parent = node.parentElement;
|
|
33
|
+
if (parent === null)
|
|
34
|
+
break;
|
|
35
|
+
const current = node;
|
|
36
|
+
const siblings = [...parent.children].filter((one) => one.tagName === current.tagName);
|
|
37
|
+
const nth = siblings.indexOf(current) + 1;
|
|
38
|
+
const tag = current.tagName.toLowerCase();
|
|
39
|
+
parts.unshift(siblings.length > 1 ? `${tag}:nth-of-type(${nth})` : tag);
|
|
40
|
+
node = parent;
|
|
41
|
+
}
|
|
42
|
+
return parts.join(" > ");
|
|
43
|
+
},
|
|
44
|
+
shown: (element) => {
|
|
45
|
+
const box = element.getBoundingClientRect();
|
|
46
|
+
return box.width > 0 && box.height > 0 && getComputedStyle(element).visibility !== "hidden";
|
|
47
|
+
},
|
|
48
|
+
textOf: (element) => element.innerText ?? element.textContent ?? "",
|
|
49
|
+
wordsIn: (text) => text.split(/\s+/).filter((one) => one !== "").length
|
|
50
|
+
};
|
|
51
|
+
if (job.kind === "contrast") {
|
|
52
|
+
const rgb = {
|
|
53
|
+
bordered: (style) => style.borderStyle !== "none" && [
|
|
54
|
+
style.borderTopWidth,
|
|
55
|
+
style.borderRightWidth,
|
|
56
|
+
style.borderBottomWidth,
|
|
57
|
+
style.borderLeftWidth
|
|
58
|
+
].some((width) => Number.parseFloat(width) > 0),
|
|
59
|
+
channel: (value) => value / 255 <= 0.03928 ? value / 255 / 12.92 : ((value / 255 + 0.055) / 1.055) ** 2.4,
|
|
60
|
+
luminance: ({ b, g, r }) => 0.2126 * rgb.channel(r) + 0.7152 * rgb.channel(g) + 0.0722 * rgb.channel(b),
|
|
61
|
+
parse: (value) => {
|
|
62
|
+
const inside = /rgba?\(([^)]+)\)/.exec(value)?.[1];
|
|
63
|
+
if (inside === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
const numbers = inside.split(/[,\s/]+/).filter((one) => one !== "").map(Number);
|
|
66
|
+
const [r, g, b, a] = numbers;
|
|
67
|
+
if (r === undefined || g === undefined || b === undefined)
|
|
68
|
+
return null;
|
|
69
|
+
return { a: a ?? 1, b, g, r };
|
|
70
|
+
},
|
|
71
|
+
ratio: (one, other) => {
|
|
72
|
+
const first = rgb.luminance(one);
|
|
73
|
+
const second = rgb.luminance(other);
|
|
74
|
+
return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const hits = [];
|
|
78
|
+
const white = { a: 1, b: 255, g: 255, r: 255 };
|
|
79
|
+
for (const element of document.querySelectorAll(job.selector)) {
|
|
80
|
+
const tag = element.tagName;
|
|
81
|
+
if (tag === "HTML" || tag === "BODY")
|
|
82
|
+
continue;
|
|
83
|
+
if (job.ignore.some((one) => element.matches(one)))
|
|
84
|
+
continue;
|
|
85
|
+
const style = getComputedStyle(element);
|
|
86
|
+
const own = rgb.parse(style.backgroundColor);
|
|
87
|
+
if (own === null || own.a !== 1)
|
|
88
|
+
continue;
|
|
89
|
+
if (style.backgroundImage !== "none" || style.boxShadow !== "none")
|
|
90
|
+
continue;
|
|
91
|
+
if (style.outlineStyle !== "none" || rgb.bordered(style))
|
|
92
|
+
continue;
|
|
93
|
+
if (!dom.shown(element))
|
|
94
|
+
continue;
|
|
95
|
+
const box = element.getBoundingClientRect();
|
|
96
|
+
let node = element.parentElement;
|
|
97
|
+
let behind = null;
|
|
98
|
+
let fullBleed = false;
|
|
99
|
+
let behindSelector = "the canvas";
|
|
100
|
+
let behindValue = "rgb(255, 255, 255)";
|
|
101
|
+
while (node !== null) {
|
|
102
|
+
const parentStyle = getComputedStyle(node);
|
|
103
|
+
const colour = rgb.parse(parentStyle.backgroundColor);
|
|
104
|
+
if (colour !== null && colour.a === 1) {
|
|
105
|
+
const parentBox = node.getBoundingClientRect();
|
|
106
|
+
fullBleed = parentBox.width <= box.width && parentBox.height <= box.height;
|
|
107
|
+
behind = colour;
|
|
108
|
+
behindSelector = node.tagName === "BODY" ? "body" : dom.selectorOf(node);
|
|
109
|
+
behindValue = parentStyle.backgroundColor;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
node = node.parentElement;
|
|
113
|
+
}
|
|
114
|
+
if (fullBleed)
|
|
115
|
+
continue;
|
|
116
|
+
const contrast = rgb.ratio(own, behind ?? white);
|
|
117
|
+
if (contrast >= job.minContrast)
|
|
118
|
+
continue;
|
|
119
|
+
hits.push({
|
|
120
|
+
background: style.backgroundColor,
|
|
121
|
+
container: behindValue,
|
|
122
|
+
containerSelector: behindSelector,
|
|
123
|
+
contrast: Math.round(contrast * 100) / 100,
|
|
124
|
+
selector: dom.selectorOf(element)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return hits;
|
|
128
|
+
}
|
|
129
|
+
if (job.kind === "assets") {
|
|
130
|
+
const geometry = ["d", "points", "cx", "cy", "r", "x", "y", "x1", "y1", "x2", "y2", "href"];
|
|
131
|
+
const scope = document.querySelector(job.scope) ?? document.body;
|
|
132
|
+
const hits = [];
|
|
133
|
+
for (const element of scope.querySelectorAll(job.assetSelector)) {
|
|
134
|
+
if (!dom.shown(element))
|
|
135
|
+
continue;
|
|
136
|
+
const tag = element.tagName.toLowerCase();
|
|
137
|
+
const signature = tag === "img" ? `src:${element.src ?? element.getAttribute("src") ?? ""}` : `svg:${[
|
|
138
|
+
...element.querySelectorAll("path,circle,rect,ellipse,line,polygon,polyline,use")
|
|
139
|
+
].map((shape) => `${shape.tagName.toLowerCase()}(${geometry.map((name) => shape.getAttribute(name) ?? "").join(",")})`).join("|")}`;
|
|
140
|
+
hits.push({
|
|
141
|
+
label: [
|
|
142
|
+
element.getAttribute("alt") ?? "",
|
|
143
|
+
element.getAttribute("aria-label") ?? "",
|
|
144
|
+
element.getAttribute("title") ?? ""
|
|
145
|
+
].filter((one) => one !== "").join(" "),
|
|
146
|
+
selector: dom.selectorOf(element),
|
|
147
|
+
signature
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return hits;
|
|
151
|
+
}
|
|
152
|
+
if (job.kind === "links") {
|
|
153
|
+
return [...document.querySelectorAll(job.selector)].map((element) => ({
|
|
154
|
+
href: element.getAttribute("href"),
|
|
155
|
+
resolved: element.href ?? "",
|
|
156
|
+
selector: dom.selectorOf(element),
|
|
157
|
+
text: dom.textOf(element).trim().slice(0, 80)
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
if (job.kind === "text") {
|
|
161
|
+
const roots = job.scope === "" ? [document.body] : [...document.querySelectorAll(job.scope)];
|
|
162
|
+
const hits = [];
|
|
163
|
+
for (const root of roots) {
|
|
164
|
+
const text = dom.textOf(root);
|
|
165
|
+
for (const pattern of job.patterns) {
|
|
166
|
+
const matcher = new RegExp(pattern, `${job.flags}g`);
|
|
167
|
+
let found = matcher.exec(text);
|
|
168
|
+
while (found !== null) {
|
|
169
|
+
const matched = found[0];
|
|
170
|
+
if (matched === "")
|
|
171
|
+
break;
|
|
172
|
+
hits.push({
|
|
173
|
+
pattern,
|
|
174
|
+
selector: dom.selectorOf(dom.deepest(root, matched)),
|
|
175
|
+
text: matched
|
|
176
|
+
});
|
|
177
|
+
found = matcher.exec(text);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return hits;
|
|
182
|
+
}
|
|
183
|
+
if (job.kind === "entities") {
|
|
184
|
+
return [...document.querySelectorAll(job.selector)].map((element) => ({
|
|
185
|
+
affordance: job.affordance === "" || element.querySelector(job.affordance) !== null,
|
|
186
|
+
id: element.getAttribute(job.attribute) ?? "",
|
|
187
|
+
selector: dom.selectorOf(element)
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
if (job.kind === "matches") {
|
|
191
|
+
const scope = job.scope === "" ? document.body : document.querySelector(job.scope);
|
|
192
|
+
const hits = [];
|
|
193
|
+
if (scope === null)
|
|
194
|
+
return hits;
|
|
195
|
+
const walker = document.createTreeWalker(scope, 4);
|
|
196
|
+
let node = walker.nextNode();
|
|
197
|
+
while (node !== null) {
|
|
198
|
+
const parent = node.parentElement;
|
|
199
|
+
const text = node.nodeValue ?? "";
|
|
200
|
+
if (parent !== null && text.trim() !== "" && dom.shown(parent)) {
|
|
201
|
+
for (const pattern of job.patterns) {
|
|
202
|
+
const matcher = new RegExp(pattern, `${job.flags}g`);
|
|
203
|
+
let found = matcher.exec(text);
|
|
204
|
+
while (found !== null) {
|
|
205
|
+
const matched = found[0];
|
|
206
|
+
if (matched === "")
|
|
207
|
+
break;
|
|
208
|
+
hits.push({ pattern, selector: dom.selectorOf(parent), text: matched });
|
|
209
|
+
found = matcher.exec(text);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
node = walker.nextNode();
|
|
214
|
+
}
|
|
215
|
+
return hits;
|
|
216
|
+
}
|
|
217
|
+
if (job.kind === "prose") {
|
|
218
|
+
return [...document.querySelectorAll(job.selector)].filter((element) => dom.shown(element)).map((element) => ({
|
|
219
|
+
headingWords: [...element.querySelectorAll(job.headingSelector)].filter((heading) => dom.shown(heading)).reduce((total, heading) => total + dom.wordsIn(dom.textOf(heading)), 0),
|
|
220
|
+
media: [...element.querySelectorAll(job.mediaSelector)].filter((one) => dom.shown(one)).length,
|
|
221
|
+
selector: dom.selectorOf(element),
|
|
222
|
+
words: dom.wordsIn(dom.textOf(element))
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
if (job.kind === "present") {
|
|
226
|
+
return job.selectors.map((selector) => ({
|
|
227
|
+
present: document.querySelector(selector) !== null,
|
|
228
|
+
selector
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
rects: job.selectors.map((selector) => {
|
|
233
|
+
const element = document.querySelector(selector);
|
|
234
|
+
return { rect: element === null ? null : dom.rectOf(element), selector };
|
|
235
|
+
}),
|
|
236
|
+
viewportHeight: innerHeight
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
var collect = async (page, job) => await page.evaluate(inPage, job);
|
|
240
|
+
export {
|
|
241
|
+
collect
|
|
242
|
+
};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Viewport } from './types.js';
|
|
2
|
+
export type WalkConfig = {
|
|
3
|
+
options: Record<string, Record<string, unknown>>;
|
|
4
|
+
probes: string[];
|
|
5
|
+
report: string;
|
|
6
|
+
urls: string[];
|
|
7
|
+
viewport: Viewport;
|
|
8
|
+
};
|
|
9
|
+
export declare const WALK_REPORT = ".geonosis/walk-report.json";
|
|
10
|
+
export declare const WALK_DEFAULT: WalkConfig;
|
|
11
|
+
export declare const configShape: () => string;
|
|
12
|
+
/** `WxH`, the shape a viewport is written in everywhere else — 1440x900, 390x844. */
|
|
13
|
+
export declare const parseViewport: (value: string) => Viewport;
|
|
14
|
+
/** The `walk` block of `geonosis.json`, every key optional, every default a contract. */
|
|
15
|
+
export declare const loadWalkConfig: (file: string) => WalkConfig;
|
|
16
|
+
export declare const configPath: (cwd: string, given?: string) => string;
|