@a11ied/observe 0.0.0-placeholder → 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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.d.ts +285 -0
- package/dist/index.js +868 -0
- package/package.json +49 -1
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hypothesi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @a11ied/observe
|
|
2
|
+
|
|
3
|
+
Browser observation, page probes, and contrast sampling.
|
|
4
|
+
|
|
5
|
+
## internal package
|
|
6
|
+
|
|
7
|
+
This is an internal package of [`a11ied`](https://www.npmjs.com/package/a11ied). It is published because `a11ied` depends on it, and its API can change in any release. Install `a11ied` instead.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { MediaInventory } from '@a11ied/contracts';
|
|
2
|
+
import { Page, CDPSession, Browser } from 'playwright';
|
|
3
|
+
|
|
4
|
+
/** Atomic rename so external callers do not import `rename` from `node:fs/promises`. */
|
|
5
|
+
declare function renameAtomicPath(from: string, to: string): Promise<void>;
|
|
6
|
+
/** Lock configuration shared by all primitives; total retry budget >= 10s. */
|
|
7
|
+
declare const LOCK_CONFIG: {
|
|
8
|
+
readonly stale: 30000;
|
|
9
|
+
readonly retries: {
|
|
10
|
+
readonly retries: 40;
|
|
11
|
+
readonly factor: 1.25;
|
|
12
|
+
readonly minTimeout: 25;
|
|
13
|
+
readonly maxTimeout: 500;
|
|
14
|
+
readonly randomize: true;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** Resolve filesystem aliases even when the destination has not been created yet. */
|
|
18
|
+
declare function getCanonicalPath(path: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Primitive 2 — Queue in-process callers on the same path, then acquire the filesystem
|
|
21
|
+
* lock. LOCK ORDERING: acquire `run.json` before `evidence.jsonl`, never the reverse.
|
|
22
|
+
*/
|
|
23
|
+
declare function withPathLock<TResult>(lockTargetPath: string, fn: () => Promise<TResult>): Promise<TResult>;
|
|
24
|
+
/** Backwards-compatible alias for `withPathLock`. */
|
|
25
|
+
declare function withFileLock<TResult>(path: string, run: () => Promise<TResult>): Promise<TResult>;
|
|
26
|
+
/** Write options for `writeAtomic`. */
|
|
27
|
+
interface WriteAtomicOptions {
|
|
28
|
+
overwrite?: boolean;
|
|
29
|
+
mode?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Primitive 1 — Atomic write of text, bytes, or JSON-serializable object. Writes to a
|
|
33
|
+
* unique temporary file, fsyncs, then renames or links atomically.
|
|
34
|
+
*/
|
|
35
|
+
declare function writeAtomic(path: string, data: string | Uint8Array | object, options?: WriteAtomicOptions): Promise<void>;
|
|
36
|
+
/** Replace text files without exposing partial writes or following leaf links. */
|
|
37
|
+
declare function writeTextAtomic(value: string, path: string, overwrite?: boolean): Promise<void>;
|
|
38
|
+
/** Replace binary files without exposing partial writes or following leaf links. */
|
|
39
|
+
declare function writeBytesAtomic(value: Uint8Array, path: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Replace JSON-serializable files without exposing partially written content or following
|
|
42
|
+
* leaf links.
|
|
43
|
+
*/
|
|
44
|
+
declare function writeJsonAtomic(value: unknown, path: string, overwrite?: boolean): Promise<void>;
|
|
45
|
+
/** Read-modify-write helper that transforms while holding the path lock. */
|
|
46
|
+
declare function updateJsonAtomic<TData>(path: string, update: (current: TData | undefined) => TData | Promise<TData>): Promise<TData>;
|
|
47
|
+
/** Options for locked file read-modify-write operations. */
|
|
48
|
+
interface LockedFileOptions<TState> {
|
|
49
|
+
/** Parse raw file content (undefined if file doesn't exist) into state. */
|
|
50
|
+
parse: (raw: string | undefined) => TState;
|
|
51
|
+
/** Serialize state for atomic write. Defaults to JSON with indentation. */
|
|
52
|
+
serialize?: (state: TState) => string | Uint8Array | object;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Primitive 3 — Single-file read-modify-write under lock. Reads, transforms via `mutate`,
|
|
56
|
+
* and writes atomically unless `write === false`.
|
|
57
|
+
*/
|
|
58
|
+
declare function withLockedFile<TState, TResult>(path: string, options: LockedFileOptions<TState>, mutate: (state: TState) => Promise<{
|
|
59
|
+
state: TState;
|
|
60
|
+
result: TResult;
|
|
61
|
+
write?: boolean;
|
|
62
|
+
}> | {
|
|
63
|
+
state: TState;
|
|
64
|
+
result: TResult;
|
|
65
|
+
write?: boolean;
|
|
66
|
+
}): Promise<TResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Append a single newline-terminated line without acquiring a lock. Use inside
|
|
69
|
+
* `withPathLock` or `withRunTransaction` to avoid deadlock.
|
|
70
|
+
*/
|
|
71
|
+
declare function appendLineUnlocked(path: string, record: string | object): Promise<void>;
|
|
72
|
+
/** Primitive 4 — Append a single newline-terminated line atomically under lock. */
|
|
73
|
+
declare function appendLine(path: string, record: string | object): Promise<void>;
|
|
74
|
+
/** Options for directory commit customization. */
|
|
75
|
+
interface DirectoryCommitOptions {
|
|
76
|
+
lockPath?: string | undefined;
|
|
77
|
+
stagePath?: string | undefined;
|
|
78
|
+
beforeCreateStage?: () => Promise<void>;
|
|
79
|
+
afterCreateStage?: (stageDir: string) => Promise<void>;
|
|
80
|
+
commitStage?: (stageDir: string, targetDir: string) => Promise<void>;
|
|
81
|
+
discardStage?: (stageDir: string, targetDir: string) => Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/** Primitive 5 — Multi-file directory commit under lock; stage then swap into place. */
|
|
84
|
+
declare function withDirectoryCommit<TResult>(targetDir: string, populate: (stagingDir: string) => Promise<TResult>, options?: DirectoryCommitOptions): Promise<TResult>;
|
|
85
|
+
/** Build an `<stem>.attempt-<attempt>.<ext>` artifact path. */
|
|
86
|
+
declare function attemptArtifactPath(dir: string, stem: string, ...rest: [attempt: number | string, ext: string]): string;
|
|
87
|
+
|
|
88
|
+
interface AriaTreeNode {
|
|
89
|
+
role: string;
|
|
90
|
+
name?: string;
|
|
91
|
+
level?: number;
|
|
92
|
+
text?: string;
|
|
93
|
+
children: AriaTreeNode[];
|
|
94
|
+
}
|
|
95
|
+
/** Parses snapshot YAML, omitting parent properties such as /url from the tree. */
|
|
96
|
+
declare function parseAriaSnapshot(yamlText: string): AriaTreeNode[];
|
|
97
|
+
/** Serializes a filtered tree back into the same YAML-like shape ariaSnapshot() uses. */
|
|
98
|
+
declare function serializeAriaTree(nodes: AriaTreeNode[], depth?: number): string;
|
|
99
|
+
/** Keeps a node when it matches `predicate`, or when any descendant does (its ancestors). */
|
|
100
|
+
declare function filterAriaTree(nodes: AriaTreeNode[], predicate: (node: AriaTreeNode) => boolean): AriaTreeNode[];
|
|
101
|
+
|
|
102
|
+
interface TabStop {
|
|
103
|
+
tag: string;
|
|
104
|
+
label: string;
|
|
105
|
+
outline: boolean;
|
|
106
|
+
shadow: boolean;
|
|
107
|
+
top: number;
|
|
108
|
+
left: number;
|
|
109
|
+
inView: boolean;
|
|
110
|
+
obscured: boolean;
|
|
111
|
+
hiddenFocus: boolean;
|
|
112
|
+
id: string;
|
|
113
|
+
}
|
|
114
|
+
interface Heading {
|
|
115
|
+
level: number;
|
|
116
|
+
text: string;
|
|
117
|
+
}
|
|
118
|
+
interface Control {
|
|
119
|
+
tag: string;
|
|
120
|
+
type: string;
|
|
121
|
+
name: string;
|
|
122
|
+
label: string;
|
|
123
|
+
placeholder: string;
|
|
124
|
+
autocomplete: string | null;
|
|
125
|
+
required: boolean;
|
|
126
|
+
}
|
|
127
|
+
interface SmallTarget {
|
|
128
|
+
html: string;
|
|
129
|
+
width: number;
|
|
130
|
+
height: number;
|
|
131
|
+
crowded: boolean;
|
|
132
|
+
}
|
|
133
|
+
interface Animation {
|
|
134
|
+
name: string;
|
|
135
|
+
dur: number | null;
|
|
136
|
+
iter: number | null;
|
|
137
|
+
}
|
|
138
|
+
interface BaseFacts {
|
|
139
|
+
title: string;
|
|
140
|
+
lang: string;
|
|
141
|
+
headings: Heading[];
|
|
142
|
+
landmarks: {
|
|
143
|
+
main: number;
|
|
144
|
+
nav: number;
|
|
145
|
+
header: number;
|
|
146
|
+
footer: number;
|
|
147
|
+
};
|
|
148
|
+
images: {
|
|
149
|
+
src: string;
|
|
150
|
+
alt: string | null;
|
|
151
|
+
inLink: boolean;
|
|
152
|
+
width: number;
|
|
153
|
+
}[];
|
|
154
|
+
svgImgs: {
|
|
155
|
+
hidden: boolean;
|
|
156
|
+
label: string | null;
|
|
157
|
+
inInteractive: boolean;
|
|
158
|
+
}[];
|
|
159
|
+
links: {
|
|
160
|
+
name: string;
|
|
161
|
+
href: string | null;
|
|
162
|
+
text: string;
|
|
163
|
+
}[];
|
|
164
|
+
unnamedButtons: string[];
|
|
165
|
+
controls: Control[];
|
|
166
|
+
forms: number;
|
|
167
|
+
media: {
|
|
168
|
+
video: number;
|
|
169
|
+
audio: number;
|
|
170
|
+
embeds: string[];
|
|
171
|
+
autoplay: number;
|
|
172
|
+
canvas: number;
|
|
173
|
+
};
|
|
174
|
+
metaRefresh: boolean;
|
|
175
|
+
marquee: number;
|
|
176
|
+
titleAttrs: number;
|
|
177
|
+
sliders: string[];
|
|
178
|
+
liveRegions: number;
|
|
179
|
+
pointerCursorNonInteractive: string[];
|
|
180
|
+
runningAnimations: Animation[];
|
|
181
|
+
bodyText: string;
|
|
182
|
+
navLinks: string[];
|
|
183
|
+
helpLinks: {
|
|
184
|
+
txt: string;
|
|
185
|
+
top: number;
|
|
186
|
+
left: number;
|
|
187
|
+
}[];
|
|
188
|
+
interactiveCount: number;
|
|
189
|
+
}
|
|
190
|
+
interface Instrumented {
|
|
191
|
+
mediaPlays: number;
|
|
192
|
+
audioContexts: number;
|
|
193
|
+
motionListeners: string[];
|
|
194
|
+
}
|
|
195
|
+
/** Everything a criterion probe may read about one page. */
|
|
196
|
+
interface PageFacts extends BaseFacts {
|
|
197
|
+
mediaInventory?: MediaInventory;
|
|
198
|
+
url: string;
|
|
199
|
+
smallTargets: SmallTarget[];
|
|
200
|
+
instrumented: Instrumented;
|
|
201
|
+
listeners: {
|
|
202
|
+
window: string[];
|
|
203
|
+
document: string[];
|
|
204
|
+
body: string[];
|
|
205
|
+
};
|
|
206
|
+
clickOnNonInteractive: string[];
|
|
207
|
+
downHandlers: {
|
|
208
|
+
html: string;
|
|
209
|
+
types: string[];
|
|
210
|
+
}[];
|
|
211
|
+
tabStops: (TabStop | null)[];
|
|
212
|
+
urlUnchangedAfterTab: boolean;
|
|
213
|
+
noIndicator: string[];
|
|
214
|
+
trapSuspected: boolean;
|
|
215
|
+
skipLink: string | undefined;
|
|
216
|
+
reflow: {
|
|
217
|
+
overflowPx: number;
|
|
218
|
+
wide: string[];
|
|
219
|
+
};
|
|
220
|
+
zoom200OverflowPx: number;
|
|
221
|
+
portraitOverflowPx: number;
|
|
222
|
+
textSpacingClipped: string[];
|
|
223
|
+
}
|
|
224
|
+
interface ListenerInfo {
|
|
225
|
+
html: string;
|
|
226
|
+
native: boolean;
|
|
227
|
+
focusable: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Reads structure, names, media, and animation facts from the loaded page. */
|
|
231
|
+
declare const PAGE_FACTS_SCRIPT: string;
|
|
232
|
+
/** Lists targets under 24px and whether another target sits inside their 24px circle. */
|
|
233
|
+
declare const SMALL_TARGETS_SCRIPT: string;
|
|
234
|
+
/** Describes the element that currently holds keyboard focus. */
|
|
235
|
+
declare const TAB_STOP_SCRIPT: string;
|
|
236
|
+
/**
|
|
237
|
+
* Tests whether focusing the target element changes its own styling or parent
|
|
238
|
+
* focus-within styling.
|
|
239
|
+
*/
|
|
240
|
+
declare const FOCUS_CHANGES_STYLE_SCRIPT: string;
|
|
241
|
+
/** Counts media playback, audio contexts, and motion listeners before page scripts run. */
|
|
242
|
+
declare const INSTRUMENT_SCRIPT: string;
|
|
243
|
+
|
|
244
|
+
/** CDP includes closed shadow roots; missing frame instrumentation keeps absence unproved. */
|
|
245
|
+
declare function collectMediaInventory(page: Page): Promise<MediaInventory>;
|
|
246
|
+
|
|
247
|
+
type ElementListenerFacts = Pick<PageFacts, 'clickOnNonInteractive' | 'downHandlers'>;
|
|
248
|
+
declare function readElementListeners(cdp: CDPSession): Promise<ElementListenerFacts>;
|
|
249
|
+
declare function readInstrumentation(page: Page, cdp: CDPSession): Promise<Pick<PageFacts, 'instrumented' | 'listeners'>>;
|
|
250
|
+
|
|
251
|
+
declare function measureViewports(page: Page, _url?: string): Promise<Pick<PageFacts, 'reflow' | 'zoom200OverflowPx' | 'portraitOverflowPx'>>;
|
|
252
|
+
declare function measureClippedText(page: Page): Promise<string[]>;
|
|
253
|
+
declare function isTextSpacingApplied(page: Page): Promise<boolean>;
|
|
254
|
+
declare function withTextSpacing<TResult>(page: Page, operation: () => Promise<TResult>): Promise<TResult>;
|
|
255
|
+
declare function findClippedText(page: Page): Promise<string[]>;
|
|
256
|
+
|
|
257
|
+
/** Opens an isolated page whose media and motion hooks load before the site's scripts. */
|
|
258
|
+
declare function openProbePage(browser: Browser, options?: {
|
|
259
|
+
storageStatePath?: string | undefined;
|
|
260
|
+
}): Promise<Page>;
|
|
261
|
+
interface IndicatorProbe {
|
|
262
|
+
id: string;
|
|
263
|
+
keyLength?: number;
|
|
264
|
+
selector?: string;
|
|
265
|
+
index?: number;
|
|
266
|
+
}
|
|
267
|
+
/** True when focusing the stop changes its own styling, or null when it cannot be found. */
|
|
268
|
+
declare function focusChangesStyle(probe: IndicatorProbe): boolean | undefined;
|
|
269
|
+
declare function readSkipLink(page: Page, _url?: string): Promise<string | undefined>;
|
|
270
|
+
/** Collects the observable facts on an already loaded page without reloading. */
|
|
271
|
+
declare function collectLoadedPageFacts(page: Page, url?: string): Promise<PageFacts>;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Maps over `items` with bounded concurrency while preserving the exact input order of
|
|
275
|
+
* the returned array.
|
|
276
|
+
*
|
|
277
|
+
* - At most `concurrency` workers run at once; fewer run when the input is shorter.
|
|
278
|
+
* - Results are written to `results[index]`, so the returned array always reflects the
|
|
279
|
+
* original input order regardless of which worker finishes first.
|
|
280
|
+
*
|
|
281
|
+
* Throws a `RangeError` if `concurrency` is not a positive integer.
|
|
282
|
+
*/
|
|
283
|
+
declare function mapWithConcurrency<TInput, TResult>(items: readonly TInput[], concurrency: number, worker: (item: TInput, index: number) => Promise<TResult>): Promise<TResult[]>;
|
|
284
|
+
|
|
285
|
+
export { type AriaTreeNode, type BaseFacts, type DirectoryCommitOptions, FOCUS_CHANGES_STYLE_SCRIPT, INSTRUMENT_SCRIPT, type IndicatorProbe, type Instrumented, LOCK_CONFIG, type ListenerInfo, type LockedFileOptions, PAGE_FACTS_SCRIPT, type PageFacts, SMALL_TARGETS_SCRIPT, type SmallTarget, TAB_STOP_SCRIPT, type TabStop, type WriteAtomicOptions, appendLine, appendLineUnlocked, attemptArtifactPath, collectLoadedPageFacts, collectMediaInventory, filterAriaTree, findClippedText, focusChangesStyle, getCanonicalPath, isTextSpacingApplied, mapWithConcurrency, measureClippedText, measureViewports, openProbePage, parseAriaSnapshot, readElementListeners, readInstrumentation, readSkipLink, renameAtomicPath, serializeAriaTree, updateJsonAtomic, withDirectoryCommit, withFileLock, withLockedFile, withPathLock, withTextSpacing, writeAtomic, writeBytesAtomic, writeJsonAtomic, writeTextAtomic };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
// src/files-store.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import {
|
|
4
|
+
link,
|
|
5
|
+
mkdir,
|
|
6
|
+
open,
|
|
7
|
+
readFile,
|
|
8
|
+
realpath,
|
|
9
|
+
rename,
|
|
10
|
+
rm
|
|
11
|
+
} from "fs/promises";
|
|
12
|
+
import { basename, dirname, resolve } from "path";
|
|
13
|
+
import { lock } from "proper-lockfile";
|
|
14
|
+
async function renameAtomicPath(from, to) {
|
|
15
|
+
await rename(from, to);
|
|
16
|
+
}
|
|
17
|
+
var LOCK_CONFIG = {
|
|
18
|
+
stale: 3e4,
|
|
19
|
+
retries: {
|
|
20
|
+
retries: 40,
|
|
21
|
+
factor: 1.25,
|
|
22
|
+
minTimeout: 25,
|
|
23
|
+
maxTimeout: 500,
|
|
24
|
+
randomize: true
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var PRIVATE_FILE_MODE = 384;
|
|
28
|
+
var JSON_INDENT = 3;
|
|
29
|
+
var waitingFiles = /* @__PURE__ */ new Map();
|
|
30
|
+
async function getCanonicalPath(path) {
|
|
31
|
+
const input = resolve(path);
|
|
32
|
+
try {
|
|
33
|
+
return await realpath(input);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
36
|
+
const parent = dirname(input);
|
|
37
|
+
if (parent !== input) {
|
|
38
|
+
return resolve(await getCanonicalPath(parent), basename(input));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function withFilesystemLock(lockTargetPath, fn) {
|
|
45
|
+
await mkdir(dirname(lockTargetPath), { recursive: true });
|
|
46
|
+
const release = await lock(lockTargetPath, {
|
|
47
|
+
realpath: false,
|
|
48
|
+
stale: LOCK_CONFIG.stale,
|
|
49
|
+
retries: LOCK_CONFIG.retries
|
|
50
|
+
}).catch((error) => {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
throw new Error(`Failed to acquire lock on ${lockTargetPath}: ${message}`, {
|
|
53
|
+
cause: error
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
return await fn();
|
|
58
|
+
} finally {
|
|
59
|
+
await release();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function withPathLock(lockTargetPath, fn) {
|
|
63
|
+
const key = resolve(lockTargetPath);
|
|
64
|
+
const previous = waitingFiles.get(key) ?? Promise.resolve();
|
|
65
|
+
const pending = (async () => {
|
|
66
|
+
await Promise.allSettled([previous]);
|
|
67
|
+
return withFilesystemLock(lockTargetPath, fn);
|
|
68
|
+
})();
|
|
69
|
+
waitingFiles.set(key, pending);
|
|
70
|
+
try {
|
|
71
|
+
return await pending;
|
|
72
|
+
} finally {
|
|
73
|
+
if (waitingFiles.get(key) === pending) {
|
|
74
|
+
waitingFiles.delete(key);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function withFileLock(path, run) {
|
|
79
|
+
return withPathLock(path, run);
|
|
80
|
+
}
|
|
81
|
+
function serializePayload(data) {
|
|
82
|
+
return typeof data === "string" || data instanceof Uint8Array ? data : `${JSON.stringify(data, void 0, JSON_INDENT)}
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
async function flushToHandle(handle, payload) {
|
|
86
|
+
await (typeof payload === "string" ? handle.writeFile(payload, "utf8") : handle.writeFile(payload));
|
|
87
|
+
await handle.sync();
|
|
88
|
+
}
|
|
89
|
+
async function writeAtomic(path, data, options = {}) {
|
|
90
|
+
const { overwrite = true, mode = PRIVATE_FILE_MODE } = options;
|
|
91
|
+
const temporaryPath = `${path}.tmp-${process.pid}-${randomUUID()}`;
|
|
92
|
+
await mkdir(dirname(path), { recursive: true });
|
|
93
|
+
const payload = serializePayload(data);
|
|
94
|
+
const handle = await open(temporaryPath, "wx", mode);
|
|
95
|
+
try {
|
|
96
|
+
try {
|
|
97
|
+
await flushToHandle(handle, payload);
|
|
98
|
+
} finally {
|
|
99
|
+
await handle.close();
|
|
100
|
+
}
|
|
101
|
+
await (overwrite ? rename(temporaryPath, path) : link(temporaryPath, path));
|
|
102
|
+
} finally {
|
|
103
|
+
await rm(temporaryPath, { force: true });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function writeTextAtomic(value, path, overwrite = true) {
|
|
107
|
+
return writeAtomic(path, value, { overwrite });
|
|
108
|
+
}
|
|
109
|
+
async function writeBytesAtomic(value, path) {
|
|
110
|
+
return writeAtomic(path, value);
|
|
111
|
+
}
|
|
112
|
+
async function writeJsonAtomic(value, path, overwrite = true) {
|
|
113
|
+
return writeTextAtomic(
|
|
114
|
+
`${JSON.stringify(value, void 0, JSON_INDENT)}
|
|
115
|
+
`,
|
|
116
|
+
path,
|
|
117
|
+
overwrite
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
async function readOptionalFile(path) {
|
|
121
|
+
try {
|
|
122
|
+
return await readFile(path, "utf8");
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function updateJsonAtomic(path, update) {
|
|
131
|
+
return withPathLock(path, async () => {
|
|
132
|
+
const raw = await readOptionalFile(path);
|
|
133
|
+
const current = raw ? JSON.parse(raw) : void 0;
|
|
134
|
+
const next = await update(current);
|
|
135
|
+
await writeAtomic(path, next);
|
|
136
|
+
return next;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async function withLockedFile(path, options, mutate) {
|
|
140
|
+
return withPathLock(path, async () => {
|
|
141
|
+
const raw = await readOptionalFile(path);
|
|
142
|
+
const currentState = options.parse(raw);
|
|
143
|
+
const next = await mutate(currentState);
|
|
144
|
+
if (next.write !== false) {
|
|
145
|
+
const payload = options.serialize ? options.serialize(next.state) : next.state;
|
|
146
|
+
await writeAtomic(path, payload);
|
|
147
|
+
}
|
|
148
|
+
return next.result;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function formatLineRecord(record) {
|
|
152
|
+
if (typeof record === "string") {
|
|
153
|
+
return record.endsWith("\n") ? record : `${record}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
return `${JSON.stringify(record)}
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
async function appendLineUnlocked(path, record) {
|
|
160
|
+
await mkdir(dirname(path), { recursive: true });
|
|
161
|
+
const line = formatLineRecord(record);
|
|
162
|
+
const handle = await open(path, "a", PRIVATE_FILE_MODE);
|
|
163
|
+
try {
|
|
164
|
+
await handle.writeFile(line, "utf8");
|
|
165
|
+
await handle.sync();
|
|
166
|
+
} finally {
|
|
167
|
+
await handle.close();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function appendLine(path, record) {
|
|
171
|
+
return withPathLock(path, () => appendLineUnlocked(path, record));
|
|
172
|
+
}
|
|
173
|
+
async function swapDirectory(stagingDir, targetDir) {
|
|
174
|
+
const targetExists = await realpath(targetDir).then(() => true).catch(() => false);
|
|
175
|
+
const backupDir = `${targetDir}.bak-${process.pid}-${randomUUID()}`;
|
|
176
|
+
if (targetExists) {
|
|
177
|
+
await rename(targetDir, backupDir);
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
await rename(stagingDir, targetDir);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (targetExists) {
|
|
183
|
+
await rename(backupDir, targetDir);
|
|
184
|
+
}
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
if (targetExists) {
|
|
188
|
+
await rm(backupDir, { recursive: true, force: true });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function withDirectoryCommit(targetDir, populate, options) {
|
|
192
|
+
const resolvedTargetDir = resolve(targetDir);
|
|
193
|
+
return withPathLock(options?.lockPath ?? targetDir, async () => {
|
|
194
|
+
await options?.beforeCreateStage?.();
|
|
195
|
+
const stagingDir = options?.stagePath ?? `${resolvedTargetDir}.stage-${process.pid}-${randomUUID()}`;
|
|
196
|
+
await mkdir(stagingDir, { recursive: options?.stagePath === void 0 });
|
|
197
|
+
await options?.afterCreateStage?.(stagingDir);
|
|
198
|
+
const commitStage = options?.commitStage ?? swapDirectory, discardStage = options?.discardStage ?? ((stage) => rm(stage, { recursive: true, force: true }));
|
|
199
|
+
let committed = false;
|
|
200
|
+
try {
|
|
201
|
+
const result = await populate(stagingDir);
|
|
202
|
+
await commitStage(stagingDir, resolvedTargetDir);
|
|
203
|
+
committed = true;
|
|
204
|
+
return result;
|
|
205
|
+
} finally {
|
|
206
|
+
if (!committed) {
|
|
207
|
+
await discardStage(stagingDir, resolvedTargetDir);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function attemptArtifactPath(dir, stem, ...rest) {
|
|
213
|
+
const [attempt, ext] = rest;
|
|
214
|
+
const safeStem = stem.replaceAll(/[^a-zA-Z0-9._-]+/gu, "-");
|
|
215
|
+
const cleanExt = ext.replace(/^\.+/u, "");
|
|
216
|
+
return resolve(dir, `${safeStem}.attempt-${attempt}.${cleanExt}`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/tree-parse.ts
|
|
220
|
+
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
221
|
+
var DESCRIPTOR_PATTERN = /^([^\s"[:]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s+\[([^\]]*)\])?$/u;
|
|
222
|
+
var LEVEL_ATTR_PATTERN = /level=(\d+)/u;
|
|
223
|
+
function parseDescriptor(descriptor) {
|
|
224
|
+
const match = DESCRIPTOR_PATTERN.exec(descriptor);
|
|
225
|
+
if (!match || descriptor.startsWith("/")) {
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
const [, role = "", encodedName, attrs] = match, level = LEVEL_ATTR_PATTERN.exec(attrs ?? ""), node = { role, children: [] };
|
|
229
|
+
if (encodedName) {
|
|
230
|
+
node.name = JSON.parse(`"${encodedName}"`);
|
|
231
|
+
}
|
|
232
|
+
if (level) {
|
|
233
|
+
node.level = Number(level[1]);
|
|
234
|
+
}
|
|
235
|
+
return node;
|
|
236
|
+
}
|
|
237
|
+
function parseSnapshotEntry(entry) {
|
|
238
|
+
if (isScalar(entry) && typeof entry.value === "string") {
|
|
239
|
+
const node = parseDescriptor(entry.value);
|
|
240
|
+
return node ? [node] : [];
|
|
241
|
+
}
|
|
242
|
+
if (!isMap(entry)) {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
const nodes = [];
|
|
246
|
+
for (const pair of entry.items) {
|
|
247
|
+
if (!isScalar(pair.key) || typeof pair.key.value !== "string") {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const node = parseDescriptor(pair.key.value);
|
|
251
|
+
if (!node) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (isSeq(pair.value)) {
|
|
255
|
+
node.children = pair.value.items.flatMap(parseSnapshotEntry);
|
|
256
|
+
} else if (isScalar(pair.value) && pair.value.value !== null) {
|
|
257
|
+
node.text = String(pair.value.value);
|
|
258
|
+
}
|
|
259
|
+
nodes.push(node);
|
|
260
|
+
}
|
|
261
|
+
return nodes;
|
|
262
|
+
}
|
|
263
|
+
function parseAriaSnapshot(yamlText) {
|
|
264
|
+
const document2 = parseDocument(yamlText);
|
|
265
|
+
if (document2.errors.length > 0) {
|
|
266
|
+
throw document2.errors[0];
|
|
267
|
+
}
|
|
268
|
+
return isSeq(document2.contents) ? document2.contents.items.flatMap(parseSnapshotEntry) : [];
|
|
269
|
+
}
|
|
270
|
+
function buildNodeHeadline(node) {
|
|
271
|
+
const parts = [node.role];
|
|
272
|
+
if (node.name) {
|
|
273
|
+
parts.push(`"${node.name}"`);
|
|
274
|
+
}
|
|
275
|
+
const headline = parts.join(" ");
|
|
276
|
+
if (node.level === void 0) {
|
|
277
|
+
return headline;
|
|
278
|
+
}
|
|
279
|
+
return `${headline} [level=${node.level}]`;
|
|
280
|
+
}
|
|
281
|
+
function serializeAriaTree(nodes, depth = 0) {
|
|
282
|
+
const indent = " ".repeat(depth);
|
|
283
|
+
const lines = nodes.flatMap((node) => {
|
|
284
|
+
const headline = buildNodeHeadline(node);
|
|
285
|
+
if (node.children.length > 0) {
|
|
286
|
+
return [`${indent}- ${headline}:`, serializeAriaTree(node.children, depth + 1)];
|
|
287
|
+
}
|
|
288
|
+
const textSuffix = node.text ? `: ${node.text}` : "";
|
|
289
|
+
return [`${indent}- ${headline}${textSuffix}`];
|
|
290
|
+
});
|
|
291
|
+
return lines.join("\n");
|
|
292
|
+
}
|
|
293
|
+
function filterAriaTree(nodes, predicate) {
|
|
294
|
+
const kept = [];
|
|
295
|
+
for (const node of nodes) {
|
|
296
|
+
const filteredChildren = filterAriaTree(node.children, predicate);
|
|
297
|
+
if (predicate(node) || filteredChildren.length > 0) {
|
|
298
|
+
kept.push({ ...node, children: filteredChildren });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return kept;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/probe/page-script.ts
|
|
305
|
+
var PAGE_FACTS_SCRIPT = [
|
|
306
|
+
"(() => {",
|
|
307
|
+
String.raw` const text = (e) => (e.textContent || '').replace(/\s+/g, ' ').trim();`,
|
|
308
|
+
" const visible = (e) => { const b = e.getBoundingClientRect(); const s = getComputedStyle(e); return b.width > 0 && b.height > 0 && s.visibility !== 'hidden' && s.display !== 'none'; };",
|
|
309
|
+
" const accName = (e) => e.getAttribute('aria-label') || (e.getAttribute('aria-labelledby') && [...e.getAttribute('aria-labelledby').split(' ')].map((i) => (document.getElementById(i)?.textContent || '').trim()).join(' ')) || text(e) || e.getAttribute('title') || e.querySelector('img[alt]')?.getAttribute('alt') || e.querySelector('svg title')?.textContent || '';",
|
|
310
|
+
" const interactive = [...document.querySelectorAll('a[href],button,input,select,textarea,summary,[role=button],[role=link],[tabindex]')].filter(visible);",
|
|
311
|
+
" return {",
|
|
312
|
+
" title: document.title,",
|
|
313
|
+
" lang: document.documentElement.lang,",
|
|
314
|
+
" headings: [...document.querySelectorAll('h1,h2,h3,h4,h5,h6')].map((h) => ({ level: Number(h.tagName[1]), text: text(h) })),",
|
|
315
|
+
" landmarks: { main: document.querySelectorAll('main,[role=main]').length, nav: document.querySelectorAll('nav,[role=navigation]').length, header: document.querySelectorAll('header,[role=banner]').length, footer: document.querySelectorAll('footer,[role=contentinfo]').length },",
|
|
316
|
+
" images: [...document.images].filter(visible).map((i) => ({ src: i.currentSrc || i.src, alt: i.getAttribute('alt'), inLink: !!i.closest('a'), width: i.naturalWidth })),",
|
|
317
|
+
" svgImgs: [...document.querySelectorAll('svg')].filter(visible).map((s) => ({ hidden: s.getAttribute('aria-hidden') === 'true', label: s.getAttribute('aria-label') || s.querySelector('title')?.textContent || null, inInteractive: !!s.closest('a,button') })),",
|
|
318
|
+
" links: [...document.querySelectorAll('a[href]')].filter(visible).map((a) => ({ name: accName(a).trim(), href: a.getAttribute('href'), text: text(a) })),",
|
|
319
|
+
" unnamedButtons: [...document.querySelectorAll('button,[role=button]')].filter(visible).filter((b) => !accName(b).trim()).map((b) => b.outerHTML.slice(0, 120)),",
|
|
320
|
+
" controls: [...document.querySelectorAll('input:not([type=hidden]),select,textarea')].filter(visible).map((c) => ({ tag: c.tagName, type: c.type, name: c.name, label: (c.labels && c.labels[0] ? text(c.labels[0]) : '') || c.getAttribute('aria-label') || '', placeholder: c.placeholder, autocomplete: c.getAttribute('autocomplete'), required: c.required || c.getAttribute('aria-required') === 'true' })),",
|
|
321
|
+
" forms: document.forms.length,",
|
|
322
|
+
" media: { video: document.querySelectorAll('video').length, audio: document.querySelectorAll('audio').length, embeds: [...document.querySelectorAll('iframe,embed,object')].map((e) => e.src || e.data || '').filter(Boolean), autoplay: document.querySelectorAll('video[autoplay],audio[autoplay]').length, canvas: document.querySelectorAll('canvas').length },",
|
|
323
|
+
" metaRefresh: !!document.querySelector('meta[http-equiv=refresh]'),",
|
|
324
|
+
" marquee: document.querySelectorAll('marquee,blink').length,",
|
|
325
|
+
" titleAttrs: document.querySelectorAll('[title]').length,",
|
|
326
|
+
" sliders: [...document.querySelectorAll('[role=slider],input[type=range],[class*=compare],[class*=before-after],[class*=slider],[class*=swiper],[class*=carousel]')].filter(visible).map((e) => e.tagName + '.' + String(e.className).slice(0, 60)),",
|
|
327
|
+
" liveRegions: document.querySelectorAll('[role=status],[role=alert],[aria-live]').length,",
|
|
328
|
+
" pointerCursorNonInteractive: [...document.querySelectorAll('div,span,li,img,p')].filter(visible).filter((e) => getComputedStyle(e).cursor === 'pointer' && !e.closest('a,button,[role=button],[tabindex]')).slice(0, 5).map((e) => e.outerHTML.slice(0, 100)),",
|
|
329
|
+
" runningAnimations: document.getAnimations().filter((a) => a.playState === 'running').map((a) => ({ name: a.animationName || a.constructor.name, dur: a.effect.getTiming().duration, iter: a.effect.getTiming().iterations })).slice(0, 200),",
|
|
330
|
+
" bodyText: document.body.innerText.slice(0, 20000),",
|
|
331
|
+
" navLinks: [...document.querySelectorAll('nav a[href]')].map((a) => text(a) + '>' + a.getAttribute('href')),",
|
|
332
|
+
` helpLinks: [...document.querySelectorAll('a[href^="tel:"],a[href^="mailto:"],a[href*=contact],[class*=chat],chat-widget')].filter(visible).map((a) => ({ txt: text(a) || a.tagName, top: Math.round(a.getBoundingClientRect().top + scrollY), left: Math.round(a.getBoundingClientRect().left) })),`,
|
|
333
|
+
" interactiveCount: interactive.length,",
|
|
334
|
+
" };",
|
|
335
|
+
"",
|
|
336
|
+
"})()"
|
|
337
|
+
].join("\n");
|
|
338
|
+
var SMALL_TARGETS_SCRIPT = [
|
|
339
|
+
"(() => {",
|
|
340
|
+
" const els = [...document.querySelectorAll('a[href],button,input:not([type=hidden]),select,textarea,[role=button]')].filter((e) => { const b = e.getBoundingClientRect(); return b.width > 0 && b.height > 0; });",
|
|
341
|
+
" const boxes = els.map((e) => ({ e, b: e.getBoundingClientRect() }));",
|
|
342
|
+
" const inlineInText = (e) => getComputedStyle(e).display === 'inline' && e.closest('p,li,span,td');",
|
|
343
|
+
" const out = [];",
|
|
344
|
+
" for (const { e, b } of boxes) {",
|
|
345
|
+
" if (b.width >= 24 && b.height >= 24) { continue; }",
|
|
346
|
+
" if (inlineInText(e)) { continue; }",
|
|
347
|
+
" const cx = b.left + b.width / 2, cy = b.top + b.height / 2;",
|
|
348
|
+
" const crowded = boxes.some(({ e: o, b: ob }) => o !== e && !o.contains(e) && !e.contains(o) && Math.max(ob.left - cx, 0, cx - ob.right) ** 2 + Math.max(ob.top - cy, 0, cy - ob.bottom) ** 2 < 144);",
|
|
349
|
+
" out.push({ html: e.outerHTML.slice(0, 100), width: Math.round(b.width), height: Math.round(b.height), crowded });",
|
|
350
|
+
" }",
|
|
351
|
+
" return out;",
|
|
352
|
+
"",
|
|
353
|
+
"})()"
|
|
354
|
+
].join("\n");
|
|
355
|
+
var TAB_STOP_SCRIPT = [
|
|
356
|
+
"(() => {",
|
|
357
|
+
" let e = document.activeElement;",
|
|
358
|
+
" while (e && e.shadowRoot && e.shadowRoot.activeElement) { e = e.shadowRoot.activeElement; }",
|
|
359
|
+
" if (!e || e === document.body) { return null; }",
|
|
360
|
+
" const cs = getComputedStyle(e), b = e.getBoundingClientRect();",
|
|
361
|
+
" const cx = Math.min(Math.max(b.left + b.width / 2, 0), innerWidth - 1), cy = Math.min(Math.max(b.top + b.height / 2, 0), innerHeight - 1);",
|
|
362
|
+
" let top = document.elementFromPoint(cx, cy);",
|
|
363
|
+
" for (let inner = top && top.shadowRoot && top.shadowRoot.elementFromPoint(cx, cy); inner && inner !== top; inner = top.shadowRoot && top.shadowRoot.elementFromPoint(cx, cy)) { top = inner; }",
|
|
364
|
+
" const parentIndicator = (() => { for (let n = e.parentElement; n && n !== document.body; n = n.parentElement) { const c = getComputedStyle(n); if ((c.outlineStyle !== 'none' && parseFloat(c.outlineWidth) > 0) || c.boxShadow !== 'none') { return true; } } return false; })();",
|
|
365
|
+
" return { tag: e.tagName, label: (e.getAttribute('aria-label') || e.textContent || '').trim().slice(0, 40), outline: (cs.outlineStyle !== 'none' && parseFloat(cs.outlineWidth) > 0) || parentIndicator, shadow: cs.boxShadow !== 'none' || parentIndicator, bg: cs.backgroundColor, color: cs.color, deco: cs.textDecorationLine, border: cs.borderTopColor + cs.borderTopWidth, top: Math.round(b.top + scrollY), left: Math.round(b.left), inView: b.bottom > 0 && b.top < innerHeight, obscured: !!top && top !== e && !e.contains(top) && !top.contains(e), hiddenFocus: (() => { for (let n = e; n && n !== document.body; n = n.parentElement) { const c = getComputedStyle(n); if (n.clientHeight === 0 && c.overflow === 'hidden' && n.scrollHeight > 0) { return true; } } return false; })(), id: e.tagName + ':' + (e.id || (e.textContent || '').trim().slice(0, 20)) };",
|
|
366
|
+
"",
|
|
367
|
+
"})()"
|
|
368
|
+
].join("\n");
|
|
369
|
+
var FOCUS_CHANGES_STYLE_SCRIPT = [
|
|
370
|
+
"(probe) => {",
|
|
371
|
+
" let element = null;",
|
|
372
|
+
" if (probe.selector) {",
|
|
373
|
+
" element = document.querySelector(probe.selector);",
|
|
374
|
+
" } else if (typeof probe.index === 'number') {",
|
|
375
|
+
" element = document.querySelectorAll('*')[probe.index] || null;",
|
|
376
|
+
" }",
|
|
377
|
+
" if (!element) {",
|
|
378
|
+
" const colonIndex = probe.id.indexOf(':');",
|
|
379
|
+
" const tag = colonIndex >= 0 ? probe.id.slice(0, colonIndex) : probe.id;",
|
|
380
|
+
" const key = colonIndex >= 0 ? probe.id.slice(colonIndex + 1) : '';",
|
|
381
|
+
" const keyLength = probe.keyLength || 20;",
|
|
382
|
+
" element = [...document.querySelectorAll(tag || '*')].find(",
|
|
383
|
+
" (node) => (node.id || (node.textContent || '').trim().slice(0, keyLength)) === key,",
|
|
384
|
+
" ) || null;",
|
|
385
|
+
" }",
|
|
386
|
+
" if (!(element instanceof HTMLElement)) {",
|
|
387
|
+
" return undefined;",
|
|
388
|
+
" }",
|
|
389
|
+
" const describe = () => {",
|
|
390
|
+
" const computed = getComputedStyle(element);",
|
|
391
|
+
" const selfStyles = [",
|
|
392
|
+
" computed.outlineColor,",
|
|
393
|
+
" computed.outlineWidth,",
|
|
394
|
+
" computed.outlineStyle,",
|
|
395
|
+
" computed.boxShadow,",
|
|
396
|
+
" computed.borderTopColor,",
|
|
397
|
+
" computed.borderRightColor,",
|
|
398
|
+
" computed.borderBottomColor,",
|
|
399
|
+
" computed.borderLeftColor,",
|
|
400
|
+
" computed.backgroundColor,",
|
|
401
|
+
" computed.color,",
|
|
402
|
+
" computed.textDecorationLine,",
|
|
403
|
+
" computed.opacity,",
|
|
404
|
+
" computed.transform,",
|
|
405
|
+
" ].join('|');",
|
|
406
|
+
" const parentStyles = [];",
|
|
407
|
+
" for (let parent = element.parentElement; parent && parent !== document.documentElement; parent = parent.parentElement) {",
|
|
408
|
+
" const pc = getComputedStyle(parent);",
|
|
409
|
+
" parentStyles.push([",
|
|
410
|
+
" pc.outlineColor,",
|
|
411
|
+
" pc.outlineWidth,",
|
|
412
|
+
" pc.outlineStyle,",
|
|
413
|
+
" pc.boxShadow,",
|
|
414
|
+
" pc.borderTopColor,",
|
|
415
|
+
" pc.borderRightColor,",
|
|
416
|
+
" pc.borderBottomColor,",
|
|
417
|
+
" pc.borderLeftColor,",
|
|
418
|
+
" ].join(';'));",
|
|
419
|
+
" }",
|
|
420
|
+
' return selfStyles + "#" + parentStyles.join(";");',
|
|
421
|
+
" };",
|
|
422
|
+
" element.blur();",
|
|
423
|
+
" const before = describe();",
|
|
424
|
+
" element.focus({ focusVisible: true });",
|
|
425
|
+
" return before !== describe();",
|
|
426
|
+
"}"
|
|
427
|
+
].join("\n");
|
|
428
|
+
var INSTRUMENT_SCRIPT = [
|
|
429
|
+
"(() => {",
|
|
430
|
+
"window.__a11 = { mediaPlays: 0, audioContexts: 0, motionListeners: [] };",
|
|
431
|
+
"const play = HTMLMediaElement.prototype.play;",
|
|
432
|
+
"HTMLMediaElement.prototype.play = function (...args) { window.__a11.mediaPlays += 1; return play.apply(this, args); };",
|
|
433
|
+
"for (const name of ['AudioContext', 'webkitAudioContext']) {",
|
|
434
|
+
" const Orig = window[name];",
|
|
435
|
+
" if (Orig) { window[name] = function (...args) { window.__a11.audioContexts += 1; return new Orig(...args); }; }",
|
|
436
|
+
"}",
|
|
437
|
+
"const add = EventTarget.prototype.addEventListener;",
|
|
438
|
+
"EventTarget.prototype.addEventListener = function (type, ...rest) { if (/^device(motion|orientation)$/.test(type)) { window.__a11.motionListeners.push(type); } return add.call(this, type, ...rest); };",
|
|
439
|
+
"})()"
|
|
440
|
+
].join("\n");
|
|
441
|
+
|
|
442
|
+
// src/probe/media-inventory.ts
|
|
443
|
+
import { z } from "zod";
|
|
444
|
+
var instrumentationSchema = z.object({
|
|
445
|
+
mediaPlays: z.number().int().nonnegative(),
|
|
446
|
+
audioContexts: z.number().int().nonnegative()
|
|
447
|
+
});
|
|
448
|
+
async function collectMediaInventory(page) {
|
|
449
|
+
const cdp = await page.context().newCDPSession(page);
|
|
450
|
+
try {
|
|
451
|
+
const snapshot = await cdp.send("DOMSnapshot.captureSnapshot", {
|
|
452
|
+
computedStyles: []
|
|
453
|
+
});
|
|
454
|
+
const names = snapshot.documents.flatMap(
|
|
455
|
+
(document2) => (document2.nodes.nodeName ?? []).map((index) => snapshot.strings[index])
|
|
456
|
+
);
|
|
457
|
+
const frames = page.frames();
|
|
458
|
+
const observations = await Promise.all(
|
|
459
|
+
frames.map(async (frame) => {
|
|
460
|
+
try {
|
|
461
|
+
return instrumentationSchema.safeParse(
|
|
462
|
+
await frame.evaluate("window.__a11")
|
|
463
|
+
);
|
|
464
|
+
} catch {
|
|
465
|
+
return instrumentationSchema.safeParse({});
|
|
466
|
+
}
|
|
467
|
+
})
|
|
468
|
+
);
|
|
469
|
+
const inventory = {
|
|
470
|
+
url: page.url(),
|
|
471
|
+
video: names.filter((name) => name === "VIDEO").length,
|
|
472
|
+
audio: names.filter((name) => name === "AUDIO").length,
|
|
473
|
+
embeds: names.filter((name) => name === "OBJECT" || name === "EMBED").length,
|
|
474
|
+
mediaPlays: 0,
|
|
475
|
+
audioContexts: 0,
|
|
476
|
+
uninspectedTrees: Math.max(0, frames.length - snapshot.documents.length) + snapshot.documents.filter((document2) => document2.nodes.nodeName === void 0).length,
|
|
477
|
+
method: "CDP DOMSnapshot inventories document and shadow trees; pre-navigation hooks count media play calls and audio contexts in every reachable frame."
|
|
478
|
+
};
|
|
479
|
+
for (const observation of observations) {
|
|
480
|
+
if (observation.success) {
|
|
481
|
+
inventory.mediaPlays += observation.data.mediaPlays;
|
|
482
|
+
inventory.audioContexts += observation.data.audioContexts;
|
|
483
|
+
} else {
|
|
484
|
+
inventory.uninspectedTrees += 1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return inventory;
|
|
488
|
+
} finally {
|
|
489
|
+
await cdp.detach();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/probe/page-cdp.ts
|
|
494
|
+
var DOWN_EVENTS = /* @__PURE__ */ new Set(["mousedown", "pointerdown", "touchstart"]);
|
|
495
|
+
var INSTRUMENT_MS = 1500;
|
|
496
|
+
var SENSOR_ORIENTATION = "absolute-orientation";
|
|
497
|
+
var SNIPPET_LENGTH = 100;
|
|
498
|
+
function ignoreUnsupportedSensor() {
|
|
499
|
+
}
|
|
500
|
+
async function listenerTypes(cdp, expression) {
|
|
501
|
+
const { result } = await cdp.send("Runtime.evaluate", { expression });
|
|
502
|
+
if (!result.objectId) {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
const { listeners } = await cdp.send("DOMDebugger.getEventListeners", {
|
|
506
|
+
objectId: result.objectId
|
|
507
|
+
});
|
|
508
|
+
return [...new Set(listeners.map((listener) => listener.type))];
|
|
509
|
+
}
|
|
510
|
+
var DESCRIBE_ELEMENT = `function () { return { html: this.outerHTML.slice(0, ${String(SNIPPET_LENGTH)}), native: !!this.closest("a[href],button,input,select,textarea,summary,label"), focusable: this.tabIndex >= 0 }; }`;
|
|
511
|
+
async function describeListeners(cdp, objectId) {
|
|
512
|
+
const { listeners } = await cdp.send("DOMDebugger.getEventListeners", { objectId });
|
|
513
|
+
const types = [...new Set(listeners.map((listener) => listener.type))];
|
|
514
|
+
if (types.length === 0) {
|
|
515
|
+
return void 0;
|
|
516
|
+
}
|
|
517
|
+
const { result } = await cdp.send("Runtime.callFunctionOn", {
|
|
518
|
+
objectId,
|
|
519
|
+
functionDeclaration: DESCRIBE_ELEMENT,
|
|
520
|
+
returnByValue: true
|
|
521
|
+
});
|
|
522
|
+
const info = result.value;
|
|
523
|
+
return { types, info };
|
|
524
|
+
}
|
|
525
|
+
function listObjectIds(properties) {
|
|
526
|
+
return properties.filter((entry) => /^\d+$/.test(entry.name)).map((entry) => entry.value?.objectId).filter((objectId) => objectId !== void 0);
|
|
527
|
+
}
|
|
528
|
+
function classifyListeners(described) {
|
|
529
|
+
const facts = { clickOnNonInteractive: [], downHandlers: [] };
|
|
530
|
+
for (const entry of described) {
|
|
531
|
+
if (!entry) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const { types, info } = entry;
|
|
535
|
+
if (types.includes("click") && !info.native && !info.focusable) {
|
|
536
|
+
facts.clickOnNonInteractive.push(info.html);
|
|
537
|
+
}
|
|
538
|
+
if (types.some((type) => DOWN_EVENTS.has(type))) {
|
|
539
|
+
facts.downHandlers.push({ html: info.html, types });
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return facts;
|
|
543
|
+
}
|
|
544
|
+
async function readElementListeners(cdp) {
|
|
545
|
+
const { result } = await cdp.send("Runtime.evaluate", {
|
|
546
|
+
expression: 'Array.from(document.querySelectorAll("*"))'
|
|
547
|
+
});
|
|
548
|
+
if (!result.objectId) {
|
|
549
|
+
return { clickOnNonInteractive: [], downHandlers: [] };
|
|
550
|
+
}
|
|
551
|
+
const { result: properties } = await cdp.send("Runtime.getProperties", {
|
|
552
|
+
objectId: result.objectId,
|
|
553
|
+
ownProperties: true
|
|
554
|
+
});
|
|
555
|
+
const described = await Promise.all(
|
|
556
|
+
listObjectIds(properties).map((objectId) => describeListeners(cdp, objectId))
|
|
557
|
+
);
|
|
558
|
+
return classifyListeners(described);
|
|
559
|
+
}
|
|
560
|
+
async function readInstrumentation(page, cdp) {
|
|
561
|
+
await cdp.send("Emulation.setSensorOverrideEnabled", {
|
|
562
|
+
enabled: true,
|
|
563
|
+
type: SENSOR_ORIENTATION
|
|
564
|
+
}).catch(ignoreUnsupportedSensor);
|
|
565
|
+
await page.waitForTimeout(INSTRUMENT_MS);
|
|
566
|
+
return {
|
|
567
|
+
instrumented: await page.evaluate("window.__a11"),
|
|
568
|
+
listeners: {
|
|
569
|
+
window: await listenerTypes(cdp, "window"),
|
|
570
|
+
document: await listenerTypes(cdp, "document"),
|
|
571
|
+
body: await listenerTypes(cdp, "document.body")
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// src/probe/page-layout.ts
|
|
577
|
+
var DESKTOP = { width: 1280, height: 900 };
|
|
578
|
+
var MIN_CLIPPED_HEIGHT = 4;
|
|
579
|
+
var PHONE = { width: 320, height: 800 };
|
|
580
|
+
var PORTRAIT = { width: 800, height: 1280 };
|
|
581
|
+
var SAMPLE_SIZE = 5;
|
|
582
|
+
var SETTLE_MS = 300;
|
|
583
|
+
var SNIPPET_LENGTH2 = 100;
|
|
584
|
+
var SNIPPET_SHORT = 20;
|
|
585
|
+
var TEXT_SPACING_CSS = "*{line-height:1.5!important;letter-spacing:.12em!important;word-spacing:.16em!important}p{margin-bottom:2em!important}";
|
|
586
|
+
var ZOOMED = { width: 640, height: 800 };
|
|
587
|
+
function measureReflow(probe) {
|
|
588
|
+
return {
|
|
589
|
+
overflowPx: document.documentElement.scrollWidth - probe.width,
|
|
590
|
+
wide: [...document.querySelectorAll("body *")].filter((element) => element.getBoundingClientRect().right > probe.width + 1).slice(0, probe.sample).map(
|
|
591
|
+
(element) => `${element.tagName}.${String(element.className).slice(0, probe.snippet)}`
|
|
592
|
+
)
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
async function measureViewports(page, _url) {
|
|
596
|
+
try {
|
|
597
|
+
await page.setViewportSize(PHONE);
|
|
598
|
+
await page.waitForTimeout(SETTLE_MS);
|
|
599
|
+
const reflow = await page.evaluate(measureReflow, {
|
|
600
|
+
width: PHONE.width,
|
|
601
|
+
sample: SAMPLE_SIZE,
|
|
602
|
+
snippet: SNIPPET_SHORT
|
|
603
|
+
});
|
|
604
|
+
const overflowAt = (width) => page.evaluate((target) => document.documentElement.scrollWidth - target, width);
|
|
605
|
+
await page.setViewportSize(ZOOMED);
|
|
606
|
+
await page.waitForTimeout(SETTLE_MS);
|
|
607
|
+
const zoom200OverflowPx = await overflowAt(ZOOMED.width);
|
|
608
|
+
await page.setViewportSize(PORTRAIT);
|
|
609
|
+
const portraitOverflowPx = await overflowAt(PORTRAIT.width);
|
|
610
|
+
return { reflow, zoom200OverflowPx, portraitOverflowPx };
|
|
611
|
+
} finally {
|
|
612
|
+
await page.setViewportSize(DESKTOP);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function findClipped(probe) {
|
|
616
|
+
return [...document.querySelectorAll("p,li,a,button,h1,h2,h3,span,div")].filter(
|
|
617
|
+
(element) => getComputedStyle(element).overflow === "hidden" && element.clientHeight > probe.minHeight && element.scrollHeight > element.clientHeight + 1 && (element.textContent ?? "").trim().length > 0
|
|
618
|
+
).slice(0, probe.sample).map((element) => element.outerHTML.slice(0, probe.snippet));
|
|
619
|
+
}
|
|
620
|
+
async function measureClippedText(page) {
|
|
621
|
+
return page.evaluate(findClipped, {
|
|
622
|
+
minHeight: MIN_CLIPPED_HEIGHT,
|
|
623
|
+
sample: SAMPLE_SIZE,
|
|
624
|
+
snippet: SNIPPET_LENGTH2
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
async function isTextSpacingApplied(page) {
|
|
628
|
+
return page.evaluate(() => {
|
|
629
|
+
const letterFactor = 0.12, lineFactor = 1.5, paragraphFactor = 2, tolerance = 0.1, wordFactor = 0.16;
|
|
630
|
+
return [...document.querySelectorAll("html, body, body *")].every((element) => {
|
|
631
|
+
if (!(element instanceof HTMLElement) || !element.textContent?.trim()) {
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
const style = getComputedStyle(element);
|
|
635
|
+
const size = Number.parseFloat(style.fontSize);
|
|
636
|
+
const letter = Number.parseFloat(style.letterSpacing), line = Number.parseFloat(style.lineHeight), word = Number.parseFloat(style.wordSpacing);
|
|
637
|
+
const paragraph = element.tagName !== "P" || Number.parseFloat(style.marginBottom) + tolerance >= size * paragraphFactor;
|
|
638
|
+
return line + tolerance >= size * lineFactor && letter + tolerance >= size * letterFactor && word + tolerance >= size * wordFactor && paragraph;
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
async function withTextSpacing(page, operation) {
|
|
643
|
+
const styleHandle = await page.addStyleTag({ content: TEXT_SPACING_CSS });
|
|
644
|
+
try {
|
|
645
|
+
return await operation();
|
|
646
|
+
} finally {
|
|
647
|
+
await styleHandle.evaluate((element) => element.remove());
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async function findClippedText(page) {
|
|
651
|
+
await page.setViewportSize(DESKTOP);
|
|
652
|
+
return withTextSpacing(page, async () => measureClippedText(page));
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// src/probe/page-facts.ts
|
|
656
|
+
var DESKTOP2 = { width: 1280, height: 900 };
|
|
657
|
+
var MAX_TAB_STOPS = 120;
|
|
658
|
+
var MIN_DISTINCT_STOPS = 3;
|
|
659
|
+
var SETTLE_MS2 = 300;
|
|
660
|
+
var STOP_KEY_LENGTH = 20;
|
|
661
|
+
var TRAILING_NULL_STOPS = 3;
|
|
662
|
+
async function openProbePage(browser, options = {}) {
|
|
663
|
+
const context = await browser.newContext({
|
|
664
|
+
viewport: DESKTOP2,
|
|
665
|
+
...options.storageStatePath ? { storageState: options.storageStatePath } : {}
|
|
666
|
+
});
|
|
667
|
+
await context.addInitScript(INSTRUMENT_SCRIPT);
|
|
668
|
+
return context.newPage();
|
|
669
|
+
}
|
|
670
|
+
async function walkTabStops(page) {
|
|
671
|
+
const startUrl = page.url();
|
|
672
|
+
const tabStops = [];
|
|
673
|
+
for (let press = 0; press < MAX_TAB_STOPS; press += 1) {
|
|
674
|
+
await page.keyboard.press("Tab");
|
|
675
|
+
tabStops.push(await page.evaluate(TAB_STOP_SCRIPT));
|
|
676
|
+
const trailing = tabStops.slice(-TRAILING_NULL_STOPS);
|
|
677
|
+
if (trailing.length === TRAILING_NULL_STOPS && trailing.every((stop) => stop === null)) {
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
const stops = tabStops.filter((stop) => stop !== null);
|
|
682
|
+
return {
|
|
683
|
+
tabStops,
|
|
684
|
+
urlUnchangedAfterTab: page.url() === startUrl,
|
|
685
|
+
trapSuspected: stops.length > 0 && new Set(stops.map((stop) => stop.id)).size < MIN_DISTINCT_STOPS
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
function focusChangesStyle(probe) {
|
|
689
|
+
const defaultStopKeyLength = 20;
|
|
690
|
+
const resolveTarget = () => {
|
|
691
|
+
if (probe.selector) {
|
|
692
|
+
return document.querySelector(probe.selector) ?? void 0;
|
|
693
|
+
}
|
|
694
|
+
if (typeof probe.index === "number") {
|
|
695
|
+
return document.querySelectorAll("*")[probe.index];
|
|
696
|
+
}
|
|
697
|
+
const colonIndex = probe.id.indexOf(":");
|
|
698
|
+
const tag = colonIndex === -1 ? probe.id : probe.id.slice(0, colonIndex);
|
|
699
|
+
const key = colonIndex === -1 ? "" : probe.id.slice(colonIndex + 1);
|
|
700
|
+
const keyLength = probe.keyLength ?? defaultStopKeyLength;
|
|
701
|
+
return [...document.querySelectorAll(tag || "*")].find(
|
|
702
|
+
(node) => (node.id || (node.textContent ?? "").trim().slice(0, keyLength)) === key
|
|
703
|
+
);
|
|
704
|
+
};
|
|
705
|
+
const element = resolveTarget();
|
|
706
|
+
if (!(element instanceof HTMLElement)) {
|
|
707
|
+
return void 0;
|
|
708
|
+
}
|
|
709
|
+
const describe = () => {
|
|
710
|
+
const computed = getComputedStyle(element);
|
|
711
|
+
const selfStyles = [
|
|
712
|
+
computed.outlineColor,
|
|
713
|
+
computed.outlineWidth,
|
|
714
|
+
computed.outlineStyle,
|
|
715
|
+
computed.boxShadow,
|
|
716
|
+
computed.borderTopColor,
|
|
717
|
+
computed.borderRightColor,
|
|
718
|
+
computed.borderBottomColor,
|
|
719
|
+
computed.borderLeftColor,
|
|
720
|
+
computed.backgroundColor,
|
|
721
|
+
computed.color,
|
|
722
|
+
computed.textDecorationLine,
|
|
723
|
+
computed.opacity,
|
|
724
|
+
computed.transform
|
|
725
|
+
].join("|");
|
|
726
|
+
const parentStyles = [];
|
|
727
|
+
for (let parent = element.parentElement; parent && parent !== document.documentElement; parent = parent.parentElement) {
|
|
728
|
+
const pc = getComputedStyle(parent);
|
|
729
|
+
parentStyles.push(
|
|
730
|
+
[
|
|
731
|
+
pc.outlineColor,
|
|
732
|
+
pc.outlineWidth,
|
|
733
|
+
pc.outlineStyle,
|
|
734
|
+
pc.boxShadow,
|
|
735
|
+
pc.borderTopColor,
|
|
736
|
+
pc.borderRightColor,
|
|
737
|
+
pc.borderBottomColor,
|
|
738
|
+
pc.borderLeftColor
|
|
739
|
+
].join(";")
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
return `${selfStyles}#${parentStyles.join(";")}`;
|
|
743
|
+
};
|
|
744
|
+
element.blur();
|
|
745
|
+
const before = describe();
|
|
746
|
+
element.focus({ focusVisible: true });
|
|
747
|
+
return before !== describe();
|
|
748
|
+
}
|
|
749
|
+
async function findStopsWithoutIndicator(page, stops) {
|
|
750
|
+
const candidates = stops.filter((entry) => !entry.outline && !entry.shadow);
|
|
751
|
+
const results = [];
|
|
752
|
+
for (const stop of candidates) {
|
|
753
|
+
const changed = await page.evaluate(focusChangesStyle, {
|
|
754
|
+
id: stop.id,
|
|
755
|
+
keyLength: STOP_KEY_LENGTH
|
|
756
|
+
});
|
|
757
|
+
results.push({ id: stop.id, changed });
|
|
758
|
+
}
|
|
759
|
+
return results.filter((entry) => entry.changed !== true).map((entry) => entry.id);
|
|
760
|
+
}
|
|
761
|
+
function readFocusedSkipLink() {
|
|
762
|
+
const element = document.activeElement;
|
|
763
|
+
const href = element?.getAttribute("href") ?? "";
|
|
764
|
+
return element?.tagName === "A" && href.startsWith("#") ? (element.textContent ?? "").trim() : void 0;
|
|
765
|
+
}
|
|
766
|
+
async function readSkipLink(page, _url) {
|
|
767
|
+
await page.evaluate(() => {
|
|
768
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
769
|
+
document.activeElement.blur();
|
|
770
|
+
}
|
|
771
|
+
document.body?.focus();
|
|
772
|
+
});
|
|
773
|
+
await page.keyboard.press("Tab");
|
|
774
|
+
return page.evaluate(readFocusedSkipLink);
|
|
775
|
+
}
|
|
776
|
+
async function collectLoadedPageFacts(page, url = page.url()) {
|
|
777
|
+
const cdp = await page.context().newCDPSession(page);
|
|
778
|
+
await page.waitForTimeout(SETTLE_MS2);
|
|
779
|
+
const base = await page.evaluate(PAGE_FACTS_SCRIPT);
|
|
780
|
+
const smallTargets = await page.evaluate(SMALL_TARGETS_SCRIPT);
|
|
781
|
+
const instruments = await readInstrumentation(page, cdp);
|
|
782
|
+
const mediaInventory = await collectMediaInventory(page);
|
|
783
|
+
const elementListeners = await readElementListeners(cdp);
|
|
784
|
+
const walked = await walkTabStops(page);
|
|
785
|
+
const stops = walked.tabStops.filter((stop) => stop !== null);
|
|
786
|
+
const noIndicator = await findStopsWithoutIndicator(page, stops);
|
|
787
|
+
const skipLink = await readSkipLink(page, url);
|
|
788
|
+
const viewports = await measureViewports(page, url);
|
|
789
|
+
const textSpacingClipped = await findClippedText(page);
|
|
790
|
+
return {
|
|
791
|
+
...base,
|
|
792
|
+
mediaInventory,
|
|
793
|
+
...instruments,
|
|
794
|
+
...elementListeners,
|
|
795
|
+
...walked,
|
|
796
|
+
...viewports,
|
|
797
|
+
url,
|
|
798
|
+
smallTargets,
|
|
799
|
+
noIndicator,
|
|
800
|
+
skipLink,
|
|
801
|
+
textSpacingClipped
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// src/parallel.ts
|
|
806
|
+
async function mapWithConcurrency(items, concurrency, worker) {
|
|
807
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
808
|
+
throw new RangeError("concurrency must be a positive integer");
|
|
809
|
+
}
|
|
810
|
+
const results = Array.from({ length: items.length });
|
|
811
|
+
let nextIndex = 0;
|
|
812
|
+
const workerCount = Math.min(concurrency, items.length);
|
|
813
|
+
async function run() {
|
|
814
|
+
while (true) {
|
|
815
|
+
const index = nextIndex;
|
|
816
|
+
nextIndex += 1;
|
|
817
|
+
const item = items[index];
|
|
818
|
+
if (index >= items.length || item === void 0) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
results[index] = await worker(item, index);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
const workers = [];
|
|
825
|
+
for (let slot = 0; slot < workerCount; slot += 1) {
|
|
826
|
+
workers.push(run());
|
|
827
|
+
}
|
|
828
|
+
await Promise.all(workers);
|
|
829
|
+
return results;
|
|
830
|
+
}
|
|
831
|
+
export {
|
|
832
|
+
FOCUS_CHANGES_STYLE_SCRIPT,
|
|
833
|
+
INSTRUMENT_SCRIPT,
|
|
834
|
+
LOCK_CONFIG,
|
|
835
|
+
PAGE_FACTS_SCRIPT,
|
|
836
|
+
SMALL_TARGETS_SCRIPT,
|
|
837
|
+
TAB_STOP_SCRIPT,
|
|
838
|
+
appendLine,
|
|
839
|
+
appendLineUnlocked,
|
|
840
|
+
attemptArtifactPath,
|
|
841
|
+
collectLoadedPageFacts,
|
|
842
|
+
collectMediaInventory,
|
|
843
|
+
filterAriaTree,
|
|
844
|
+
findClippedText,
|
|
845
|
+
focusChangesStyle,
|
|
846
|
+
getCanonicalPath,
|
|
847
|
+
isTextSpacingApplied,
|
|
848
|
+
mapWithConcurrency,
|
|
849
|
+
measureClippedText,
|
|
850
|
+
measureViewports,
|
|
851
|
+
openProbePage,
|
|
852
|
+
parseAriaSnapshot,
|
|
853
|
+
readElementListeners,
|
|
854
|
+
readInstrumentation,
|
|
855
|
+
readSkipLink,
|
|
856
|
+
renameAtomicPath,
|
|
857
|
+
serializeAriaTree,
|
|
858
|
+
updateJsonAtomic,
|
|
859
|
+
withDirectoryCommit,
|
|
860
|
+
withFileLock,
|
|
861
|
+
withLockedFile,
|
|
862
|
+
withPathLock,
|
|
863
|
+
withTextSpacing,
|
|
864
|
+
writeAtomic,
|
|
865
|
+
writeBytesAtomic,
|
|
866
|
+
writeJsonAtomic,
|
|
867
|
+
writeTextAtomic
|
|
868
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@a11ied/observe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Browser observation, page probes, and contrast sampling. Internal package of a11ied, published because the a1 CLI depends on it. Its API can change in any release; install a11ied instead.",
|
|
5
|
+
"homepage": "https://github.com/hypothesi/a11ied/tree/master/packages/observe#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/hypothesi/a11ied/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/hypothesi/a11ied.git",
|
|
13
|
+
"directory": "packages/observe"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"CHANGELOG.md"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"prepack": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@a11ied/contracts": "0.1.0",
|
|
38
|
+
"playwright": "^1.62.1",
|
|
39
|
+
"proper-lockfile": "4.1.2",
|
|
40
|
+
"yaml": "2.8.3",
|
|
41
|
+
"zod": "^4.6.6"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/proper-lockfile": "4.1.4"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=24"
|
|
48
|
+
}
|
|
49
|
+
}
|