@e2e-dev/electron 0.0.0-stage → 0.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.
Files changed (75) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +91 -2
  4. package/dist/.build.json +1 -0
  5. package/dist/actionability.d.ts +41 -0
  6. package/dist/actionability.js +121 -0
  7. package/dist/actions.d.ts +52 -0
  8. package/dist/actions.js +418 -0
  9. package/dist/app-process.d.ts +114 -0
  10. package/dist/app-process.js +610 -0
  11. package/dist/budget.d.ts +33 -0
  12. package/dist/budget.js +64 -0
  13. package/dist/capture.d.ts +21 -0
  14. package/dist/capture.js +137 -0
  15. package/dist/cdp/connection.d.ts +68 -0
  16. package/dist/cdp/connection.js +232 -0
  17. package/dist/cdp/input.d.ts +67 -0
  18. package/dist/cdp/input.js +195 -0
  19. package/dist/cdp/keys.d.ts +21 -0
  20. package/dist/cdp/keys.js +114 -0
  21. package/dist/console-text.d.ts +4 -0
  22. package/dist/console-text.js +27 -0
  23. package/dist/devtools.d.ts +36 -0
  24. package/dist/devtools.js +111 -0
  25. package/dist/dialogs.d.ts +38 -0
  26. package/dist/dialogs.js +81 -0
  27. package/dist/electron.d.ts +9 -0
  28. package/dist/electron.js +174 -0
  29. package/dist/engine-entry.d.ts +13 -0
  30. package/dist/engine-entry.js +9 -0
  31. package/dist/engine.d.ts +27 -0
  32. package/dist/engine.js +98 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.js +54 -0
  35. package/dist/evaluate.d.ts +40 -0
  36. package/dist/evaluate.js +115 -0
  37. package/dist/executable.d.ts +29 -0
  38. package/dist/executable.js +249 -0
  39. package/dist/ffmpeg.d.ts +12 -0
  40. package/dist/ffmpeg.js +100 -0
  41. package/dist/fields.d.ts +93 -0
  42. package/dist/fields.js +254 -0
  43. package/dist/file-bound.d.ts +31 -0
  44. package/dist/file-bound.js +104 -0
  45. package/dist/fixtures.d.ts +168 -0
  46. package/dist/fixtures.js +6 -0
  47. package/dist/in-page/masks.d.ts +25 -0
  48. package/dist/in-page/masks.js +140 -0
  49. package/dist/in-page/node-ops.d.ts +96 -0
  50. package/dist/in-page/node-ops.js +406 -0
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +18 -0
  53. package/dist/launcher.d.ts +45 -0
  54. package/dist/launcher.js +167 -0
  55. package/dist/locate.d.ts +46 -0
  56. package/dist/locate.js +103 -0
  57. package/dist/main-process.d.ts +25 -0
  58. package/dist/main-process.js +60 -0
  59. package/dist/options.d.ts +65 -0
  60. package/dist/options.js +120 -0
  61. package/dist/page.d.ts +100 -0
  62. package/dist/page.js +229 -0
  63. package/dist/runner-test.d.ts +15 -0
  64. package/dist/runner-test.js +45 -0
  65. package/dist/snapshot.d.ts +143 -0
  66. package/dist/snapshot.js +260 -0
  67. package/dist/surface.d.ts +158 -0
  68. package/dist/surface.js +602 -0
  69. package/dist/tree.d.ts +51 -0
  70. package/dist/tree.js +406 -0
  71. package/dist/video.d.ts +42 -0
  72. package/dist/video.js +253 -0
  73. package/dist/windows.d.ts +81 -0
  74. package/dist/windows.js +200 -0
  75. package/package.json +72 -3
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Which executable a launch starts: the one `electron({ executablePath })`
3
+ * names, else the Electron binary of the `electron` package installed in the
4
+ * project. That package downloads its binary on first use (Electron 45 and
5
+ * later have no install script), so `prepare` fetches it once per run,
6
+ * before the run's clock starts, and a worker only checks it is there.
7
+ */
8
+ import { spawn } from 'node:child_process';
9
+ import { accessSync, closeSync, constants, existsSync, openSync, readdirSync, readFileSync, readSync, statSync } from 'node:fs';
10
+ import { createRequire } from 'node:module';
11
+ import path from 'node:path';
12
+ import { ConfigurationError, InfrastructureError } from '@e2e-dev/core/engine';
13
+ /** How much of a failed download's output its error quotes, in characters. */
14
+ const INSTALL_OUTPUT_TAIL = 2000;
15
+ /** The project's `electron` package, or undefined when the project has none. */
16
+ function electronPackage(projectRoot, env) {
17
+ let manifest;
18
+ try {
19
+ manifest = createRequire(path.join(projectRoot, 'package.json')).resolve('electron/package.json');
20
+ }
21
+ catch {
22
+ return undefined;
23
+ }
24
+ const directory = path.dirname(manifest);
25
+ const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
26
+ const version = typeof parsed === 'object' && parsed !== null && 'version' in parsed && typeof parsed.version === 'string' ? parsed.version : 'unknown';
27
+ const pathFile = path.join(directory, 'path.txt');
28
+ const relative = existsSync(pathFile) ? readFileSync(pathFile, 'utf8').trim() : '';
29
+ // Electron's own index.js takes the binary from ELECTRON_OVERRIDE_DIST_PATH when it is set (a build of your own, Nix).
30
+ const override = env['ELECTRON_OVERRIDE_DIST_PATH'];
31
+ const overridden = override !== undefined && override !== '';
32
+ const binary = overridden ? path.join(override, relative === '' ? 'electron' : relative) : relative === '' ? undefined : path.join(directory, 'dist', relative);
33
+ return { directory, binary: binary !== undefined && existsSync(binary) ? binary : undefined, version, ...(overridden && binary !== undefined ? { override: binary } : {}) };
34
+ }
35
+ /**
36
+ * Whether a path names a regular file this process may execute: a directory
37
+ * passes the execute-permission check too (search permission), so it is
38
+ * ruled out first. A packaged macOS app is the binary inside the bundle,
39
+ * `MyApp.app/Contents/MacOS/MyApp`, not the `.app` directory. Windows has no
40
+ * execute permission, and starts only a program image: a file that begins
41
+ * with the `MZ` signature, which a shortcut or a script does not.
42
+ */
43
+ function isExecutableFile(file, platform) {
44
+ try {
45
+ if (!statSync(file).isFile())
46
+ return false;
47
+ if (platform !== 'win32') {
48
+ accessSync(file, constants.X_OK);
49
+ return true;
50
+ }
51
+ const signature = Buffer.alloc(2);
52
+ const handle = openSync(file, 'r');
53
+ try {
54
+ return readSync(handle, signature, 0, 2, 0) === 2 && signature.toString('latin1') === 'MZ';
55
+ }
56
+ finally {
57
+ closeSync(handle);
58
+ }
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ }
64
+ function isDirectory(file) {
65
+ try {
66
+ return statSync(file).isDirectory();
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
72
+ /** The names in a directory, or none when it cannot be read. */
73
+ function entries(directory) {
74
+ try {
75
+ return readdirSync(directory);
76
+ }
77
+ catch {
78
+ return [];
79
+ }
80
+ }
81
+ /** How many `.exe` files of a folder a hint names. */
82
+ const NAMED_EXECUTABLES = 5;
83
+ /**
84
+ * Where a Squirrel.Windows launcher's app is, when `file` is one: an
85
+ * installer made with Squirrel (electron-winstaller, Electron Forge's
86
+ * default) puts the app in `app-<version>` folders beside `Update.exe`, and
87
+ * a small launcher of the app's name next to them. The launcher starts one
88
+ * of the versions and exits, so the engine would be left holding a process
89
+ * that is not the app. One installed version is named by its path; of
90
+ * several, the launcher's pick is its own rule, so their folders are named.
91
+ */
92
+ function squirrelApp(file) {
93
+ const directory = path.dirname(file);
94
+ const name = path.basename(file);
95
+ const siblings = entries(directory);
96
+ if (!siblings.some((sibling) => sibling.toLowerCase() === 'update.exe'))
97
+ return undefined;
98
+ const versions = siblings.filter((sibling) => /^app-\d/.test(sibling) && existsSync(path.join(directory, sibling, name))).toSorted();
99
+ const [only] = versions;
100
+ if (only === undefined)
101
+ return undefined;
102
+ return versions.length === 1 ? path.join(directory, only, name) : `${name} in one of the version folders beside it (${versions.join(', ')})`;
103
+ }
104
+ /** What to name instead of an `executablePath` that is no executable file, for the mistakes each platform invites. */
105
+ function executableHint(resolved, platform) {
106
+ if (/\.app[\\/]?$/.test(resolved))
107
+ return `; a macOS app runs as the binary inside its bundle, ${path.join(resolved, 'Contents', 'MacOS', path.basename(resolved, '.app'))}`;
108
+ if (platform !== 'win32')
109
+ return '';
110
+ if (/\.lnk$/i.test(resolved))
111
+ return '; it is a shortcut: name the .exe it points to (its Target, under Properties)';
112
+ if (isExecutableFile(`${resolved}.exe`, platform))
113
+ return `; name the file with its extension, ${squirrelApp(`${resolved}.exe`) ?? `${resolved}.exe`}`;
114
+ if (!isDirectory(resolved))
115
+ return '';
116
+ const programs = entries(resolved)
117
+ .filter((name) => /\.exe$/i.test(name))
118
+ .toSorted();
119
+ if (programs.length === 0)
120
+ return '; name the app\'s .exe, not a folder';
121
+ // A Squirrel install's own folder: the app is not the launcher at its top.
122
+ const installed = programs.map((name) => squirrelApp(path.join(resolved, name))).find((app) => app !== undefined);
123
+ if (installed !== undefined)
124
+ return `; name the app's .exe, ${installed}`;
125
+ return `; name the app's .exe inside the folder (it holds ${programs.slice(0, NAMED_EXECUTABLES).join(', ')}${programs.length > NAMED_EXECUTABLES ? ', and more' : ''})`;
126
+ }
127
+ function locateExecutable(projectRoot, executablePath, env, platform) {
128
+ if (executablePath !== undefined) {
129
+ const resolved = path.resolve(projectRoot, executablePath);
130
+ if (!isExecutableFile(resolved, platform)) {
131
+ return { kind: 'misconfigured', problem: `electron({ executablePath }) names ${resolved}, which is not an executable file${executableHint(resolved, platform)}` };
132
+ }
133
+ const launched = platform === 'win32' ? squirrelApp(resolved) : undefined;
134
+ if (launched !== undefined) {
135
+ return { kind: 'misconfigured', problem: `electron({ executablePath }) names ${resolved}, the launcher its installer left there: it starts the app and exits, so name the app itself, ${launched}` };
136
+ }
137
+ return { kind: 'named', file: resolved };
138
+ }
139
+ const installed = electronPackage(projectRoot, env);
140
+ if (installed === undefined) {
141
+ return {
142
+ kind: 'misconfigured',
143
+ problem: `electron() starts the electron package installed in the project, and ${projectRoot} has none: install it (npm install --save-dev electron), or name an executable with electron({ executablePath })`,
144
+ };
145
+ }
146
+ if (installed.binary !== undefined)
147
+ return { kind: 'installed', file: installed.binary, version: installed.version };
148
+ // The variable is wrong, and downloading would not help.
149
+ if (installed.override !== undefined) {
150
+ return { kind: 'misconfigured', problem: `ELECTRON_OVERRIDE_DIST_PATH names the directory of the Electron binary, and none is at ${installed.override}; fix the variable or unset it` };
151
+ }
152
+ return { kind: 'undownloaded', package: installed };
153
+ }
154
+ /** The executable a launch starts, checked: an `executablePath` that runs, or the project's downloaded Electron binary. */
155
+ export function resolveExecutable(projectRoot, executablePath, env, platform = process.platform) {
156
+ const found = locateExecutable(projectRoot, executablePath, env, platform);
157
+ switch (found.kind) {
158
+ case 'named':
159
+ case 'installed':
160
+ return found.file;
161
+ case 'misconfigured':
162
+ throw new ConfigurationError('INVALID_CONFIG', found.problem);
163
+ case 'undownloaded':
164
+ throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `electron ${found.package.version} is installed at ${found.package.directory} without its binary; the engine's prepare step downloads it before the first test`);
165
+ }
166
+ }
167
+ /**
168
+ * Downloads the project's Electron binary when it is missing. Nothing to do
169
+ * with `executablePath`, or with the binary in place; a wrong path fails
170
+ * here, once for the run rather than once per test.
171
+ */
172
+ export async function ensureElectronBinary(projectRoot, executablePath, env, log, signal) {
173
+ const found = locateExecutable(projectRoot, executablePath, env, process.platform);
174
+ if (found.kind === 'misconfigured')
175
+ throw new ConfigurationError('INVALID_CONFIG', found.problem);
176
+ if (found.kind !== 'undownloaded')
177
+ return;
178
+ await download(found.package, env, log, signal);
179
+ if (electronPackage(projectRoot, env)?.binary === undefined) {
180
+ throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `electron ${found.package.version}'s install.js finished, but its binary is still missing at ${found.package.directory}`);
181
+ }
182
+ }
183
+ /** Runs the package's own `install.js` (what its first `require` would run), its output sent to `log`. */
184
+ async function download(installed, env, log, signal) {
185
+ const script = path.join(installed.directory, 'install.js');
186
+ if (!existsSync(script)) {
187
+ throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `electron ${installed.version} at ${installed.directory} has no binary and no install.js to download it with; reinstall the electron package`);
188
+ }
189
+ log(`downloading the Electron ${installed.version} binary`);
190
+ const failure = await new Promise((resolve) => {
191
+ const child = spawn(process.execPath, [script], { cwd: installed.directory, env, stdio: ['ignore', 'pipe', 'pipe'], signal });
192
+ let tail = '';
193
+ const read = (chunk) => {
194
+ const text = chunk.toString('utf8');
195
+ tail = (tail + text).slice(-INSTALL_OUTPUT_TAIL);
196
+ for (const line of text.split(/\r?\n/))
197
+ if (line.trim() !== '')
198
+ log(line.trim());
199
+ };
200
+ child.stdout.on('data', read);
201
+ child.stderr.on('data', read);
202
+ child.on('error', (cause) => resolve(cause.message));
203
+ child.on('close', (code) => resolve(code === 0 ? undefined : `install.js exited with ${code}: ${tail.trim()}`));
204
+ });
205
+ if (failure !== undefined)
206
+ throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `downloading the Electron ${installed.version} binary failed: ${failure}`);
207
+ }
208
+ /** For `e2e doctor`: what a run would start, without downloading anything. */
209
+ export function describeExecutable(projectRoot, executablePath, env, platform = process.platform) {
210
+ const found = locateExecutable(projectRoot, executablePath, env, platform);
211
+ switch (found.kind) {
212
+ case 'named':
213
+ return { status: 'pass', message: `starts ${found.file}` };
214
+ case 'installed':
215
+ return { status: 'pass', message: `electron ${found.version} at ${found.file}` };
216
+ case 'undownloaded':
217
+ return { status: 'warn', message: `electron ${found.package.version} is installed without its binary; the first run downloads it` };
218
+ case 'misconfigured':
219
+ return { status: 'fail', message: found.problem };
220
+ }
221
+ }
222
+ /**
223
+ * Why `app.appPath` names no app Electron can start, or undefined when it
224
+ * does: a main script, or a directory whose `package.json` names an existing
225
+ * `main` (else Electron runs its `index.js`).
226
+ */
227
+ export function appPathProblem(projectRoot, appPath) {
228
+ const resolved = path.resolve(projectRoot, appPath);
229
+ if (!existsSync(resolved))
230
+ return `app.appPath names ${resolved}, which does not exist`;
231
+ if (statSync(resolved).isFile())
232
+ return undefined;
233
+ const manifest = path.join(resolved, 'package.json');
234
+ let main = 'index.js';
235
+ if (existsSync(manifest)) {
236
+ try {
237
+ const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
238
+ if (typeof parsed === 'object' && parsed !== null && 'main' in parsed && typeof parsed.main === 'string' && parsed.main !== '')
239
+ main = parsed.main;
240
+ }
241
+ catch {
242
+ return `app.appPath names ${resolved}, whose package.json is not valid JSON`;
243
+ }
244
+ }
245
+ const script = path.resolve(resolved, main);
246
+ if (!existsSync(script) && !existsSync(`${script}.js`))
247
+ return `app.appPath names ${resolved}, and its main script ${script} does not exist; set "main" in its package.json`;
248
+ return undefined;
249
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The ffmpeg that encodes a recording: `E2E_FFMPEG_PATH`, else the pinned
3
+ * build in the e2e cache, else a system one with VP9, else that pinned build
4
+ * downloaded on the first recording.
5
+ */
6
+ type Env = Readonly<Record<string, string | undefined>>;
7
+ /**
8
+ * The ffmpeg to encode with, downloaded into the cache when the machine has
9
+ * none. Throws `UNSUPPORTED_CAPABILITY` on a platform with no pinned build.
10
+ */
11
+ export declare function ensureFfmpeg(env: Env, signal: AbortSignal): Promise<string>;
12
+ export {};
package/dist/ffmpeg.js ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The ffmpeg that encodes a recording: `E2E_FFMPEG_PATH`, else the pinned
3
+ * build in the e2e cache, else a system one with VP9, else that pinned build
4
+ * downloaded on the first recording.
5
+ */
6
+ import { spawnSync } from 'node:child_process';
7
+ import { createHash } from 'node:crypto';
8
+ import { chmodSync, existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
9
+ import os from 'node:os';
10
+ import path from 'node:path';
11
+ import { gunzipSync } from 'node:zlib';
12
+ import { EngineError, InfrastructureError } from '@e2e-dev/core/engine';
13
+ /** The pinned `eugeneware/ffmpeg-static` release, and the SHA-256 of each platform's `.gz` asset. */
14
+ const BUILD = 'b6.1.1';
15
+ const SHA256 = {
16
+ 'darwin-arm64': '8923876afa8db5585022d7860ec7e589af192f441c56793971276d450ed3bbfa',
17
+ 'darwin-x64': '929b375c1182d956c51f7ac25e0b2b0411fb01f6f407aa15c9758efeb4242106',
18
+ 'linux-x64': 'bfe8a8fc511530457b528c48d77b5737527b504a3797a9bc4866aeca69c2dffa',
19
+ 'linux-arm64': '754a678672298bc68156adff58aa7385a592c2b30b1d0ae8750c45c915c4bac0',
20
+ 'win32-x64': '8883a3dffbd0a16cf4ef95206ea05283f78908dbfb118f73c83f4951dcc06d77',
21
+ };
22
+ /** The cache directory e2e's engines keep downloaded binaries in. */
23
+ function cacheDirectory(env) {
24
+ const configured = env['E2E_BROWSERS_PATH'];
25
+ if (configured !== undefined && configured !== '')
26
+ return path.resolve(configured);
27
+ if (process.platform === 'win32')
28
+ return path.join(env['LOCALAPPDATA'] ?? path.join(os.homedir(), 'AppData', 'Local'), 'e2e', 'browsers');
29
+ if (process.platform === 'darwin')
30
+ return path.join(os.homedir(), 'Library', 'Caches', 'e2e', 'browsers');
31
+ return path.join(env['XDG_CACHE_HOME'] ?? path.join(os.homedir(), '.cache'), 'e2e', 'browsers');
32
+ }
33
+ function cachedFfmpeg(env) {
34
+ return path.join(cacheDirectory(env), `ffmpeg-${BUILD}`, process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg');
35
+ }
36
+ /** `ffmpeg` on the PATH when it encodes VP9, else null; probed once. */
37
+ let systemFfmpeg;
38
+ function encodesVp9(executable) {
39
+ const result = spawnSync(executable, ['-hide_banner', '-encoders'], { encoding: 'utf8', timeout: 10_000 });
40
+ return result.status === 0 && result.stdout.includes('libvpx-vp9');
41
+ }
42
+ /** One download per process, shared by attempts that start recording together. */
43
+ let downloading;
44
+ /**
45
+ * The ffmpeg to encode with, downloaded into the cache when the machine has
46
+ * none. Throws `UNSUPPORTED_CAPABILITY` on a platform with no pinned build.
47
+ */
48
+ export async function ensureFfmpeg(env, signal) {
49
+ const configured = env['E2E_FFMPEG_PATH'];
50
+ if (configured !== undefined && configured !== '')
51
+ return configured;
52
+ const cached = cachedFfmpeg(env);
53
+ if (existsSync(cached))
54
+ return cached;
55
+ systemFfmpeg ??= encodesVp9('ffmpeg') ? 'ffmpeg' : null;
56
+ if (systemFfmpeg !== null)
57
+ return systemFfmpeg;
58
+ // Windows on Arm runs the x64 build.
59
+ const platform = process.platform === 'win32' ? 'win32-x64' : `${process.platform}-${process.arch}`;
60
+ const sha256 = SHA256[platform];
61
+ if (sha256 === undefined) {
62
+ throw new EngineError('UNSUPPORTED_CAPABILITY', `recording video needs an ffmpeg with libvpx-vp9, and none is pinned for ${platform}: set E2E_FFMPEG_PATH`, { retryable: false });
63
+ }
64
+ downloading ??= download(platform, sha256, cached, signal).finally(() => {
65
+ downloading = undefined;
66
+ });
67
+ return await downloading;
68
+ }
69
+ async function download(platform, sha256, target, signal) {
70
+ const url = `https://github.com/eugeneware/ffmpeg-static/releases/download/${BUILD}/ffmpeg-${platform}.gz`;
71
+ const failed = (why, cause) => new InfrastructureError('ELECTRON_INSTALL_FAILED', `downloading ffmpeg for video recording from ${url} failed: ${why}; set E2E_FFMPEG_PATH to an ffmpeg with libvpx-vp9`, { cause });
72
+ let archive;
73
+ try {
74
+ const response = await fetch(url, { signal, redirect: 'follow' });
75
+ if (!response.ok)
76
+ throw new Error(`HTTP ${response.status}`);
77
+ archive = Buffer.from(await response.arrayBuffer());
78
+ }
79
+ catch (cause) {
80
+ throw failed(cause instanceof Error ? cause.message : String(cause), cause);
81
+ }
82
+ const actual = createHash('sha256').update(archive).digest('hex');
83
+ if (actual !== sha256)
84
+ throw failed(`its SHA-256 is ${actual}, not the pinned ${sha256}`);
85
+ mkdirSync(path.dirname(target), { recursive: true });
86
+ // Written beside the target and renamed over it, so another worker never runs half a file.
87
+ const staged = `${target}.${process.pid}.tmp`;
88
+ try {
89
+ writeFileSync(staged, gunzipSync(archive));
90
+ chmodSync(staged, 0o755);
91
+ renameSync(staged, target);
92
+ }
93
+ catch (cause) {
94
+ rmSync(staged, { force: true });
95
+ // Another process may have put it there first.
96
+ if (!existsSync(target))
97
+ throw failed(cause instanceof Error ? cause.message : String(cause), cause);
98
+ }
99
+ return target;
100
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * What one element reads as: its role, states, level, value, and attributes,
3
+ * each a pure function of the element's accessibility node (when Chromium
4
+ * gave it one) and its DOM facts. An element the accessibility tree leaves
5
+ * out reads by the same rules with no accessibility node.
6
+ */
7
+ import type { SemanticNode } from '@e2e-dev/core/engine';
8
+ import { type DomFacts } from './snapshot.ts';
9
+ /** The fields of a Chromium `AXValue` the projection reads. */
10
+ interface AXValue {
11
+ readonly value?: unknown;
12
+ }
13
+ /** One node of `Accessibility.getFullAXTree`, the fields the projection reads. */
14
+ export interface AXNode {
15
+ readonly nodeId: string;
16
+ readonly ignored: boolean;
17
+ readonly ignoredReasons?: readonly {
18
+ readonly name: string;
19
+ }[];
20
+ readonly role?: AXValue;
21
+ readonly name?: AXValue;
22
+ readonly value?: AXValue;
23
+ readonly properties?: readonly {
24
+ readonly name: string;
25
+ readonly value: AXValue;
26
+ }[];
27
+ readonly parentId?: string;
28
+ readonly childIds?: readonly string[];
29
+ readonly backendDOMNodeId?: number;
30
+ }
31
+ /**
32
+ * Where a model's observation and a locator's read differ, as data: an
33
+ * observation is bounded and shows what a model reads a control by; a locator
34
+ * reads every attribute, whole fields, and each element's text with its
35
+ * descendants'.
36
+ */
37
+ export interface ProjectionPolicy {
38
+ readonly textLimit: number;
39
+ readonly nameLimit: number;
40
+ /** The most nodes one projection keeps: a locator reads every node, or it would miss a match past the cap. */
41
+ readonly maxNodes: number;
42
+ /** The attributes kept beside every `aria-*` one; null keeps all of them. */
43
+ readonly attributes: ReadonlySet<string> | null;
44
+ /** A link shows as origin and path, its query and fragment elided. */
45
+ readonly redactHref: boolean;
46
+ /** An editing host with no role reads as a text field. A role query does not find it as one, as the web's does not. */
47
+ readonly editingHostRole: boolean;
48
+ /** A checkbox or radio reports the token it submits. */
49
+ readonly checkableValue: boolean;
50
+ /** Reports `empty`, which only `toBeEmpty` reads. */
51
+ readonly emptyState: boolean;
52
+ /** An element's text includes its descendants', and several runs under one element stay nodes an exact text query finds. */
53
+ readonly descendantText: boolean;
54
+ /** An element with a test id that the accessibility tree leaves out still joins the tree. */
55
+ readonly hiddenTestIds: boolean;
56
+ }
57
+ export declare function stringOf(value: AXValue | undefined): string | undefined;
58
+ /** Whether Chromium hides the node from a person, and its subtree with it. */
59
+ export declare function isHiddenSubtree(node: AXNode): boolean;
60
+ /** A focusable element with no role (a span with a tabindex) is a control of the app's own. */
61
+ export declare function isFocusable(node: AXNode): boolean;
62
+ /** An input or textarea: its value is the element's own, and its inner editor is not read as text. */
63
+ export declare function isTextField(facts: DomFacts | undefined): boolean;
64
+ /** An input drawn as a button: the value it shows is its text, as the web reads it. */
65
+ export declare function isButtonInput(facts: DomFacts | undefined): boolean;
66
+ export declare function isSecure(facts: DomFacts | undefined): boolean;
67
+ export declare function isCheckable(facts: DomFacts | undefined): boolean;
68
+ interface Role {
69
+ /** The contract role the element reads as. */
70
+ readonly role: string;
71
+ /** A container that says nothing on its own: it gives its place to its children unless something makes it addressable. */
72
+ readonly silent: boolean;
73
+ }
74
+ export declare function roleOf(node: AXNode, facts: DomFacts | undefined, policy: ProjectionPolicy): Role;
75
+ /** The fields of a contract node an element's own facts decide; its name, box, and text come from the tree around it. */
76
+ export interface ElementFields {
77
+ readonly states: Record<string, boolean>;
78
+ readonly testId?: string;
79
+ readonly inputPurpose?: SemanticNode['inputPurpose'];
80
+ readonly level?: number;
81
+ /** Whole: the projection bounds it. */
82
+ readonly value?: string;
83
+ readonly attributes?: Record<string, string>;
84
+ }
85
+ export interface FieldContext {
86
+ readonly policy: ProjectionPolicy;
87
+ readonly testIdAttribute: string;
88
+ /** The document's URL, which a relative link resolves against. */
89
+ readonly baseUrl: string | undefined;
90
+ }
91
+ /** Reads an element's fields. `node` is undefined for an element the accessibility tree leaves out. */
92
+ export declare function elementFields(node: AXNode | undefined, facts: DomFacts | undefined, role: string, context: FieldContext): ElementFields;
93
+ export {};