@a11y-pulse/browser-adaptor 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.
- package/LICENSE.md +166 -0
- package/README.md +76 -0
- package/dist/adaptor.d.ts +49 -0
- package/dist/adaptors/puppeteer.d.ts +14 -0
- package/dist/adaptors/puppeteer.js +46 -0
- package/dist/adaptors/puppeteer.js.map +1 -0
- package/dist/dom.d.ts +2 -0
- package/dist/dom.js +170 -0
- package/dist/dom.js.map +1 -0
- package/dist/get-selector.d.ts +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/truncate-html.d.ts +9 -0
- package/package.json +70 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Copyright (c) 2026-present, A11y Pulse Limited (https://www.a11ypulse.com/). All rights reserved.
|
|
2
|
+
|
|
3
|
+
# PolyForm Shield License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree
|
|
10
|
+
to them as both strict obligations and conditions to all
|
|
11
|
+
your licenses.
|
|
12
|
+
|
|
13
|
+
## Copyright License
|
|
14
|
+
|
|
15
|
+
The licensor grants you a copyright license for the
|
|
16
|
+
software to do everything you might do with the software
|
|
17
|
+
that would otherwise infringe the licensor's copyright
|
|
18
|
+
in it for any permitted purpose. However, you may
|
|
19
|
+
only distribute the software according to [Distribution
|
|
20
|
+
License](#distribution-license) and make changes or new works
|
|
21
|
+
based on the software according to [Changes and New Works
|
|
22
|
+
License](#changes-and-new-works-license).
|
|
23
|
+
|
|
24
|
+
## Distribution License
|
|
25
|
+
|
|
26
|
+
The licensor grants you an additional copyright license
|
|
27
|
+
to distribute copies of the software. Your license
|
|
28
|
+
to distribute covers distributing the software with
|
|
29
|
+
changes and new works permitted by [Changes and New Works
|
|
30
|
+
License](#changes-and-new-works-license).
|
|
31
|
+
|
|
32
|
+
## Notices
|
|
33
|
+
|
|
34
|
+
You must ensure that anyone who gets a copy of any part of
|
|
35
|
+
the software from you also gets a copy of these terms or the
|
|
36
|
+
URL for them above, as well as copies of any plain-text lines
|
|
37
|
+
beginning with `Required Notice:` that the licensor provided
|
|
38
|
+
with the software. For example:
|
|
39
|
+
|
|
40
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
41
|
+
|
|
42
|
+
## Changes and New Works License
|
|
43
|
+
|
|
44
|
+
The licensor grants you an additional copyright license to
|
|
45
|
+
make changes and new works based on the software for any
|
|
46
|
+
permitted purpose.
|
|
47
|
+
|
|
48
|
+
## Patent License
|
|
49
|
+
|
|
50
|
+
The licensor grants you a patent license for the software that
|
|
51
|
+
covers patent claims the licensor can license, or becomes able
|
|
52
|
+
to license, that you would infringe by using the software.
|
|
53
|
+
|
|
54
|
+
## Noncompete
|
|
55
|
+
|
|
56
|
+
Any purpose is a permitted purpose, except for providing any
|
|
57
|
+
product that competes with the software or any product the
|
|
58
|
+
licensor or any of its affiliates provides using the software.
|
|
59
|
+
|
|
60
|
+
## Competition
|
|
61
|
+
|
|
62
|
+
Goods and services compete even when they provide functionality
|
|
63
|
+
through different kinds of interfaces or for different technical
|
|
64
|
+
platforms. Applications can compete with services, libraries
|
|
65
|
+
with plugins, frameworks with development tools, and so on,
|
|
66
|
+
even if they're written in different programming languages
|
|
67
|
+
or for different computer architectures. Goods and services
|
|
68
|
+
compete even when provided free of charge. If you market a
|
|
69
|
+
product as a practical substitute for the software or another
|
|
70
|
+
product, it definitely competes.
|
|
71
|
+
|
|
72
|
+
## New Products
|
|
73
|
+
|
|
74
|
+
If you are using the software to provide a product that does
|
|
75
|
+
not compete, but the licensor or any of its affiliates brings
|
|
76
|
+
your product into competition by providing a new version of
|
|
77
|
+
the software or another product using the software, you may
|
|
78
|
+
continue using versions of the software available under these
|
|
79
|
+
terms beforehand to provide your competing product, but not
|
|
80
|
+
any later versions.
|
|
81
|
+
|
|
82
|
+
## Discontinued Products
|
|
83
|
+
|
|
84
|
+
You may begin using the software to compete with a product
|
|
85
|
+
or service that the licensor or any of its affiliates has
|
|
86
|
+
stopped providing, unless the licensor includes a plain-text
|
|
87
|
+
line beginning with `Licensor Line of Business:` with the
|
|
88
|
+
software that mentions that line of business. For example:
|
|
89
|
+
|
|
90
|
+
> Licensor Line of Business: YoyodyneCMS Content Management
|
|
91
|
+
System (http://example.com/cms)
|
|
92
|
+
|
|
93
|
+
## Sales of Business
|
|
94
|
+
|
|
95
|
+
If the licensor or any of its affiliates sells a line of
|
|
96
|
+
business developing the software or using the software
|
|
97
|
+
to provide a product, the buyer can also enforce
|
|
98
|
+
[Noncompete](#noncompete) for that product.
|
|
99
|
+
|
|
100
|
+
## Fair Use
|
|
101
|
+
|
|
102
|
+
You may have "fair use" rights for the software under the
|
|
103
|
+
law. These terms do not limit them.
|
|
104
|
+
|
|
105
|
+
## No Other Rights
|
|
106
|
+
|
|
107
|
+
These terms do not allow you to sublicense or transfer any of
|
|
108
|
+
your licenses to anyone else, or prevent the licensor from
|
|
109
|
+
granting licenses to anyone else. These terms do not imply
|
|
110
|
+
any other licenses.
|
|
111
|
+
|
|
112
|
+
## Patent Defense
|
|
113
|
+
|
|
114
|
+
If you make any written claim that the software infringes or
|
|
115
|
+
contributes to infringement of any patent, your patent license
|
|
116
|
+
for the software granted under these terms ends immediately. If
|
|
117
|
+
your company makes such a claim, your patent license ends
|
|
118
|
+
immediately for work on behalf of your company.
|
|
119
|
+
|
|
120
|
+
## Violations
|
|
121
|
+
|
|
122
|
+
The first time you are notified in writing that you have
|
|
123
|
+
violated any of these terms, or done anything with the software
|
|
124
|
+
not covered by your licenses, your licenses can nonetheless
|
|
125
|
+
continue if you come into full compliance with these terms,
|
|
126
|
+
and take practical steps to correct past violations, within
|
|
127
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
128
|
+
end immediately.
|
|
129
|
+
|
|
130
|
+
## No Liability
|
|
131
|
+
|
|
132
|
+
***As far as the law allows, the software comes as is, without
|
|
133
|
+
any warranty or condition, and the licensor will not be liable
|
|
134
|
+
to you for any damages arising out of these terms or the use
|
|
135
|
+
or nature of the software, under any kind of legal claim.***
|
|
136
|
+
|
|
137
|
+
## Definitions
|
|
138
|
+
|
|
139
|
+
The **licensor** is the individual or entity offering these
|
|
140
|
+
terms, and the **software** is the software the licensor makes
|
|
141
|
+
available under these terms.
|
|
142
|
+
|
|
143
|
+
A **product** can be a good or service, or a combination
|
|
144
|
+
of them.
|
|
145
|
+
|
|
146
|
+
**You** refers to the individual or entity agreeing to these
|
|
147
|
+
terms.
|
|
148
|
+
|
|
149
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
150
|
+
or other kind of organization that you work for, plus all
|
|
151
|
+
its affiliates.
|
|
152
|
+
|
|
153
|
+
**Affiliates** means the other organizations than an
|
|
154
|
+
organization has control over, is under the control of, or is
|
|
155
|
+
under common control with.
|
|
156
|
+
|
|
157
|
+
**Control** means ownership of substantially all the assets of
|
|
158
|
+
an entity, or the power to direct its management and policies
|
|
159
|
+
by vote, contract, or otherwise. Control can be direct or
|
|
160
|
+
indirect.
|
|
161
|
+
|
|
162
|
+
**Your licenses** are all the licenses granted to you for the
|
|
163
|
+
software under these terms.
|
|
164
|
+
|
|
165
|
+
**Use** means anything you do with the software requiring one
|
|
166
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @a11y-pulse/browser-adaptor
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@a11y-pulse/browser-adaptor)
|
|
4
|
+
[](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE.md)
|
|
6
|
+
|
|
7
|
+
Shared browser adaptor primitives and DOM helpers used by [A11y Pulse](https://www.a11ypulse.com/) accessibility audits. Audit packages drive a page through a `BrowserAdaptor` without depending on a specific automation library. This package also exports `getSelector` and `truncateHtml` for building result metadata.
|
|
8
|
+
|
|
9
|
+
Released as source-available under the [PolyForm Shield License 1.0.0](#license).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @a11y-pulse/browser-adaptor
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`puppeteer` is an optional peer dependency. It is only required if you use the bundled [Puppeteer adaptor](#puppeteer-adaptor).
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
| Entry | Contents |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect` |
|
|
24
|
+
| `@a11y-pulse/browser-adaptor/puppeteer` | `PuppeteerAdaptor` |
|
|
25
|
+
| `@a11y-pulse/browser-adaptor/dom` | `getSelector`, `truncateHtml` |
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { PuppeteerAdaptor } from "@a11y-pulse/browser-adaptor/puppeteer";
|
|
31
|
+
import puppeteer from "puppeteer";
|
|
32
|
+
|
|
33
|
+
const browser = await puppeteer.launch();
|
|
34
|
+
const page = await browser.newPage();
|
|
35
|
+
await page.goto("https://example.com/");
|
|
36
|
+
|
|
37
|
+
const adaptor = new PuppeteerAdaptor(page);
|
|
38
|
+
await adaptor.ensureFocusReporting();
|
|
39
|
+
await adaptor.pressTab();
|
|
40
|
+
|
|
41
|
+
await browser.close();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## BrowserAdaptor
|
|
45
|
+
|
|
46
|
+
Implement this interface against your automation library's page or session object:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
interface BrowserAdaptor {
|
|
50
|
+
evaluate<T>(fn: (...args: any[]) => T | Promise<T>, ...args: unknown[]): Promise<T>;
|
|
51
|
+
evaluateHandle(fn: () => Element | null): Promise<ElementRef>;
|
|
52
|
+
disposeRef(ref: ElementRef): Promise<void>;
|
|
53
|
+
pressTab(): Promise<void>;
|
|
54
|
+
pressEnter(): Promise<void>;
|
|
55
|
+
screenshotClip(clip: Rect): Promise<Uint8Array>;
|
|
56
|
+
ensureFocusReporting(): Promise<void>; // must not throw
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Consumers may ignore methods they do not need. `ensureFocusReporting` is best-effort and must not throw.
|
|
61
|
+
|
|
62
|
+
## Puppeteer adaptor
|
|
63
|
+
|
|
64
|
+
`PuppeteerAdaptor` wraps a Puppeteer `Page`. Focus emulation is enabled at most once per page via a `WeakSet`, so reused pages across audit runs do not open extra CDP sessions.
|
|
65
|
+
|
|
66
|
+
## DOM helpers
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import { getSelector, truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`getSelector` builds a compact selector for an element (intended to run in page context). `truncateHtml` shortens an element's opening tag for display in results.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[PolyForm Shield License 1.0.0](./LICENSE.md). Read, fork, and use in non-competing products. Do not use this package to build a competing accessibility monitoring service.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** A screenshot clip region in CSS pixels. */
|
|
2
|
+
export type Rect = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* An element handle in the page. This type is adaptor-specific and is opaque to the audit.
|
|
10
|
+
*/
|
|
11
|
+
export type ElementRef = unknown;
|
|
12
|
+
/**
|
|
13
|
+
* A framework-specific adaptor that provides the primitives needed by tab-loop audits. An
|
|
14
|
+
* adaptor wraps a single page in a web browser.
|
|
15
|
+
*/
|
|
16
|
+
export interface BrowserAdaptor {
|
|
17
|
+
/**
|
|
18
|
+
* Run `fn` in the page context, passing in any serialisable `args`
|
|
19
|
+
*/
|
|
20
|
+
evaluate<T>(fn: (...args: any[]) => T | Promise<T>, ...args: unknown[]): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Return an opaque handle to an element in the page
|
|
23
|
+
*/
|
|
24
|
+
evaluateHandle(fn: () => Element | null): Promise<ElementRef>;
|
|
25
|
+
/**
|
|
26
|
+
* Release a handle previously returned by evaluateHandle
|
|
27
|
+
*/
|
|
28
|
+
disposeRef(ref: ElementRef): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Press the tab key
|
|
31
|
+
*/
|
|
32
|
+
pressTab(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Press the enter key
|
|
35
|
+
*/
|
|
36
|
+
pressEnter(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Screenshot a clipped region of the page defined by `clip`. This function must return PNG bytes.
|
|
39
|
+
*/
|
|
40
|
+
screenshotClip(clip: Rect): Promise<Uint8Array>;
|
|
41
|
+
/**
|
|
42
|
+
* Ensure the page reports focus for its lifetime. In particular, `document.hasFocus()` must
|
|
43
|
+
* function correctly and :focus styles must be applied, even when the page is not the
|
|
44
|
+
* foreground.
|
|
45
|
+
*
|
|
46
|
+
* This function must not throw.
|
|
47
|
+
*/
|
|
48
|
+
ensureFocusReporting(): Promise<void>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Page } from "puppeteer";
|
|
2
|
+
import type { BrowserAdaptor, ElementRef, Rect } from "../adaptor";
|
|
3
|
+
/** A BrowserAdaptor backed by a Puppeteer Page. */
|
|
4
|
+
export declare class PuppeteerAdaptor implements BrowserAdaptor {
|
|
5
|
+
private readonly page;
|
|
6
|
+
constructor(page: Page);
|
|
7
|
+
evaluate<T>(fn: (...args: any[]) => T | Promise<T>, ...args: unknown[]): Promise<T>;
|
|
8
|
+
evaluateHandle(fn: () => Element | null): Promise<ElementRef>;
|
|
9
|
+
disposeRef(ref: ElementRef): Promise<void>;
|
|
10
|
+
pressTab(): Promise<void>;
|
|
11
|
+
pressEnter(): Promise<void>;
|
|
12
|
+
screenshotClip(clip: Rect): Promise<Uint8Array>;
|
|
13
|
+
ensureFocusReporting(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/adaptors/puppeteer.ts
|
|
2
|
+
var focusEmulationEnabled = /* @__PURE__ */ new WeakSet();
|
|
3
|
+
var PuppeteerAdaptor = class {
|
|
4
|
+
constructor(page) {
|
|
5
|
+
this.page = page;
|
|
6
|
+
}
|
|
7
|
+
page;
|
|
8
|
+
evaluate(fn, ...args) {
|
|
9
|
+
return this.page.evaluate(fn, ...args);
|
|
10
|
+
}
|
|
11
|
+
evaluateHandle(fn) {
|
|
12
|
+
return this.page.evaluateHandle(fn);
|
|
13
|
+
}
|
|
14
|
+
async disposeRef(ref) {
|
|
15
|
+
await ref.dispose();
|
|
16
|
+
}
|
|
17
|
+
async pressTab() {
|
|
18
|
+
await this.page.keyboard.press("Tab");
|
|
19
|
+
}
|
|
20
|
+
async pressEnter() {
|
|
21
|
+
await this.page.keyboard.press("Enter");
|
|
22
|
+
}
|
|
23
|
+
async screenshotClip(clip) {
|
|
24
|
+
return await this.page.screenshot({ type: "png", clip });
|
|
25
|
+
}
|
|
26
|
+
async ensureFocusReporting() {
|
|
27
|
+
if (focusEmulationEnabled.has(this.page)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const client = await this.page.createCDPSession();
|
|
32
|
+
await client.send("Emulation.setFocusEmulationEnabled", {
|
|
33
|
+
enabled: true
|
|
34
|
+
});
|
|
35
|
+
focusEmulationEnabled.add(this.page);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.warn("Could not enable focus emulation for the browser adaptor", {
|
|
38
|
+
error
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
PuppeteerAdaptor
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=puppeteer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adaptors/puppeteer.ts"],"sourcesContent":["import type { JSHandle, Page } from \"puppeteer\";\nimport type { BrowserAdaptor, ElementRef, Rect } from \"../adaptor\";\n\n// Pages that already have focus emulation enabled. A fresh adaptor is created per\n// audit run, but a page is often reused across runs (e.g. one page per snapshot,\n// many checks), so without this each run would open another CDP session that is\n// never detached. The emulation persists for the page's lifetime, so enabling it\n// once is enough. (Detaching the session instead is not an option. Chrome clears\n// the emulation when the CDP client disconnects.)\nconst focusEmulationEnabled = new WeakSet<Page>();\n\n/** A BrowserAdaptor backed by a Puppeteer Page. */\nexport class PuppeteerAdaptor implements BrowserAdaptor {\n\tconstructor(private readonly page: Page) {}\n\n\tevaluate<T>(\n\t\t// biome-ignore lint/suspicious/noExplicitAny: the page-evaluated fn accepts arbitrary serialised args and element handles.\n\t\tfn: (...args: any[]) => T | Promise<T>,\n\t\t...args: unknown[]\n\t): Promise<T> {\n\t\t// Puppeteer resolves any JSHandle passed as an arg to the live element.\n\t\treturn this.page.evaluate(fn as never, ...(args as never[])) as Promise<T>;\n\t}\n\n\tevaluateHandle(fn: () => Element | null): Promise<ElementRef> {\n\t\treturn this.page.evaluateHandle(fn);\n\t}\n\n\tasync disposeRef(ref: ElementRef): Promise<void> {\n\t\tawait (ref as JSHandle).dispose();\n\t}\n\n\tasync pressTab(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Tab\");\n\t}\n\n\tasync pressEnter(): Promise<void> {\n\t\tawait this.page.keyboard.press(\"Enter\");\n\t}\n\n\tasync screenshotClip(clip: Rect): Promise<Uint8Array> {\n\t\treturn (await this.page.screenshot({ type: \"png\", clip })) as Uint8Array;\n\t}\n\n\tasync ensureFocusReporting(): Promise<void> {\n\t\t// Pages only report focus while they are the foreground tab. Since this browser instance\n\t\t// is likely running in the background, we need to enable focus emulation to get accurate\n\t\t// results.\n\t\t//\n\t\t// Note this function does not throw if enabling emulation fails; it is a best-effort.\n\t\tif (focusEmulationEnabled.has(this.page)) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = await this.page.createCDPSession();\n\t\t\tawait client.send(\"Emulation.setFocusEmulationEnabled\", {\n\t\t\t\tenabled: true,\n\t\t\t});\n\t\t\tfocusEmulationEnabled.add(this.page);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\"Could not enable focus emulation for the browser adaptor\", {\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";AASA,IAAM,wBAAwB,oBAAI,QAAc;AAGzC,IAAM,mBAAN,MAAiD;AAAA,EACvD,YAA6B,MAAY;AAAZ;AAAA,EAAa;AAAA,EAAb;AAAA,EAE7B,SAEC,OACG,MACU;AAEb,WAAO,KAAK,KAAK,SAAS,IAAa,GAAI,IAAgB;AAAA,EAC5D;AAAA,EAEA,eAAe,IAA+C;AAC7D,WAAO,KAAK,KAAK,eAAe,EAAE;AAAA,EACnC;AAAA,EAEA,MAAM,WAAW,KAAgC;AAChD,UAAO,IAAiB,QAAQ;AAAA,EACjC;AAAA,EAEA,MAAM,WAA0B;AAC/B,UAAM,KAAK,KAAK,SAAS,MAAM,KAAK;AAAA,EACrC;AAAA,EAEA,MAAM,aAA4B;AACjC,UAAM,KAAK,KAAK,SAAS,MAAM,OAAO;AAAA,EACvC;AAAA,EAEA,MAAM,eAAe,MAAiC;AACrD,WAAQ,MAAM,KAAK,KAAK,WAAW,EAAE,MAAM,OAAO,KAAK,CAAC;AAAA,EACzD;AAAA,EAEA,MAAM,uBAAsC;AAM3C,QAAI,sBAAsB,IAAI,KAAK,IAAI,GAAG;AACzC;AAAA,IACD;AAEA,QAAI;AACH,YAAM,SAAS,MAAM,KAAK,KAAK,iBAAiB;AAChD,YAAM,OAAO,KAAK,sCAAsC;AAAA,QACvD,SAAS;AAAA,MACV,CAAC;AACD,4BAAsB,IAAI,KAAK,IAAI;AAAA,IACpC,SAAS,OAAO;AACf,cAAQ,KAAK,4DAA4D;AAAA,QACxE;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AACD;","names":[]}
|
package/dist/dom.d.ts
ADDED
package/dist/dom.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/get-selector.ts
|
|
2
|
+
function getSelector(root) {
|
|
3
|
+
const MAX_LENGTH = 128;
|
|
4
|
+
const esc = (value) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value;
|
|
5
|
+
const tagName = (node2) => node2.nodeType === 1 ? node2.nodeName.toLowerCase() : node2.nodeName.toUpperCase().replace(/^#/, "");
|
|
6
|
+
const rootOf = (element) => {
|
|
7
|
+
const node2 = element.getRootNode?.();
|
|
8
|
+
return node2 && typeof node2.querySelectorAll === "function" ? node2 : null;
|
|
9
|
+
};
|
|
10
|
+
const matchCount = (queryRoot2, selector) => {
|
|
11
|
+
try {
|
|
12
|
+
return queryRoot2.querySelectorAll(selector).length;
|
|
13
|
+
} catch {
|
|
14
|
+
return Number.POSITIVE_INFINITY;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const safeMatches = (element, selector) => {
|
|
18
|
+
try {
|
|
19
|
+
return typeof element.matches === "function" && element.matches(selector);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const idIsUnique = (element, id) => {
|
|
25
|
+
const queryRoot2 = rootOf(element);
|
|
26
|
+
return queryRoot2 === null || matchCount(queryRoot2, `#${esc(id)}`) === 1;
|
|
27
|
+
};
|
|
28
|
+
const classFeature = (cls) => ({
|
|
29
|
+
feature: `.${esc(cls)}`,
|
|
30
|
+
sharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls)
|
|
31
|
+
});
|
|
32
|
+
const rarestFeature = (element, queryRoot2) => {
|
|
33
|
+
const classes = Array.from(element.classList).slice(0, 8);
|
|
34
|
+
if (!queryRoot2) {
|
|
35
|
+
const cls = classes[0];
|
|
36
|
+
return cls === void 0 ? null : classFeature(cls);
|
|
37
|
+
}
|
|
38
|
+
let best = null;
|
|
39
|
+
let bestCount = Number.POSITIVE_INFINITY;
|
|
40
|
+
for (const cls of classes) {
|
|
41
|
+
const candidate = classFeature(cls);
|
|
42
|
+
if (!safeMatches(element, candidate.feature)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const count = matchCount(queryRoot2, candidate.feature);
|
|
46
|
+
if (count < bestCount) {
|
|
47
|
+
best = candidate;
|
|
48
|
+
bestCount = count;
|
|
49
|
+
}
|
|
50
|
+
if (count === 1) {
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const href = typeof element.getAttribute === "function" ? element.getAttribute("href") : null;
|
|
55
|
+
if (href && href.length <= 100 && !/["\\?]/.test(href)) {
|
|
56
|
+
const feature = `[href="${href}"]`;
|
|
57
|
+
if (safeMatches(element, feature) && matchCount(queryRoot2, feature) < bestCount) {
|
|
58
|
+
return {
|
|
59
|
+
feature,
|
|
60
|
+
sharedBy: (sibling) => typeof sibling.getAttribute === "function" && sibling.getAttribute("href") === href
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return best;
|
|
65
|
+
};
|
|
66
|
+
const positionAmongSiblings = (element, sharedBy) => {
|
|
67
|
+
const siblings = element.parentNode?.children;
|
|
68
|
+
if (!siblings) {
|
|
69
|
+
return { nth: 0, ambiguous: false };
|
|
70
|
+
}
|
|
71
|
+
let nth = 0;
|
|
72
|
+
let count = 0;
|
|
73
|
+
let shared = 0;
|
|
74
|
+
for (const sibling of Array.from(siblings)) {
|
|
75
|
+
if (sibling.nodeName !== element.nodeName) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
count++;
|
|
79
|
+
if (sibling === element) {
|
|
80
|
+
nth = count;
|
|
81
|
+
}
|
|
82
|
+
if (sharedBy(sibling)) {
|
|
83
|
+
shared++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { nth, ambiguous: shared > 1 };
|
|
87
|
+
};
|
|
88
|
+
const segmentFor = (element, queryRoot2) => {
|
|
89
|
+
if (element.id && idIsUnique(element, element.id)) {
|
|
90
|
+
return { segment: `#${esc(element.id)}`, anchored: true };
|
|
91
|
+
}
|
|
92
|
+
const feature = rarestFeature(element, queryRoot2);
|
|
93
|
+
let segment = tagName(element) + (feature === null ? "" : feature.feature);
|
|
94
|
+
const { nth, ambiguous } = positionAmongSiblings(
|
|
95
|
+
element,
|
|
96
|
+
feature === null ? () => true : feature.sharedBy
|
|
97
|
+
);
|
|
98
|
+
if (ambiguous && nth > 0) {
|
|
99
|
+
segment += `:nth-of-type(${nth})`;
|
|
100
|
+
}
|
|
101
|
+
return { segment, anchored: false };
|
|
102
|
+
};
|
|
103
|
+
const degradedSegmentFor = (element) => {
|
|
104
|
+
let segment = tagName(element);
|
|
105
|
+
const { nth, ambiguous } = positionAmongSiblings(element, () => true);
|
|
106
|
+
if (ambiguous && nth > 0) {
|
|
107
|
+
segment += `:nth-of-type(${nth})`;
|
|
108
|
+
}
|
|
109
|
+
return segment;
|
|
110
|
+
};
|
|
111
|
+
const segments = [];
|
|
112
|
+
let node = root;
|
|
113
|
+
const queryRoot = root && root.nodeType === 1 ? rootOf(root) : null;
|
|
114
|
+
try {
|
|
115
|
+
while (node && node.nodeType === 1) {
|
|
116
|
+
const element = node;
|
|
117
|
+
let { segment, anchored } = segmentFor(element, queryRoot);
|
|
118
|
+
const joinedWith = (candidate) => segments.length ? candidate.length + 1 + segments.join(">").length : candidate.length;
|
|
119
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
120
|
+
segment = degradedSegmentFor(element);
|
|
121
|
+
anchored = false;
|
|
122
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
segments.unshift(segment);
|
|
127
|
+
if (anchored) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (queryRoot && matchCount(queryRoot, segments.join(">")) === 1) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
node = element.parentNode;
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
return segments.join(">");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/truncate-html.ts
|
|
141
|
+
var DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;
|
|
142
|
+
var DEFAULT_MAX_LENGTH = 300;
|
|
143
|
+
var ELLIPSIS = "...";
|
|
144
|
+
function truncateHtml(html, options = {}) {
|
|
145
|
+
if (!html) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
const maxAttributeValueLength = options.maxAttributeValueLength ?? DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH;
|
|
149
|
+
const maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;
|
|
150
|
+
const closingBracket = html.indexOf(">");
|
|
151
|
+
const openingTag = closingBracket === -1 ? html : html.slice(0, closingBracket + 1);
|
|
152
|
+
const trimmed = openingTag.replace(
|
|
153
|
+
/=(["'])([\s\S]*?)\1/g,
|
|
154
|
+
(match, quote, value) => {
|
|
155
|
+
if (value.length <= maxAttributeValueLength) {
|
|
156
|
+
return match;
|
|
157
|
+
}
|
|
158
|
+
return `=${quote}${value.slice(0, maxAttributeValueLength)}${ELLIPSIS}${quote}`;
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
if (trimmed.length > maxLength) {
|
|
162
|
+
return `${trimmed.slice(0, maxLength)}${ELLIPSIS}`;
|
|
163
|
+
}
|
|
164
|
+
return trimmed;
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
getSelector,
|
|
168
|
+
truncateHtml
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/get-selector.ts","../src/truncate-html.ts"],"sourcesContent":["/**\n * Build a compact, hopefully-unique selector for any given element on the page. This function is\n * serialized and run in the page context, so it must not reference any symbols outside its own\n * scope.\n *\n * Mirrors axe-core's approach: each level contributes the fewest features that discriminate the\n * element (a unique id, the rarest single class, or an :nth-of-type position), and the walk stops\n * as soon as the joined selector matches exactly one element. Selectors stay short because of\n * that early stop, not because of truncation; the length budget is only a backstop.\n */\nexport function getSelector(root: Node | null): string {\n\tconst MAX_LENGTH = 128;\n\n\tconst esc = (value: string): string =>\n\t\ttypeof CSS !== \"undefined\" && typeof CSS.escape === \"function\"\n\t\t\t? CSS.escape(value)\n\t\t\t: value;\n\n\tconst tagName = (node: Node): string =>\n\t\tnode.nodeType === 1\n\t\t\t? node.nodeName.toLowerCase()\n\t\t\t: node.nodeName.toUpperCase().replace(/^#/, \"\");\n\n\t// A querySelectorAll-capable root (Document or ShadowRoot) for the element,\n\t// used to confirm uniqueness and class rarity. Absent on the plain objects\n\t// used in the serialisation unit tests, where we trust ids and walk to the\n\t// top instead of stopping early.\n\tconst rootOf = (element: Element): ParentNode | null => {\n\t\tconst node = (\n\t\t\telement as Element & { getRootNode?: () => Node }\n\t\t).getRootNode?.();\n\n\t\treturn node && typeof (node as ParentNode).querySelectorAll === \"function\"\n\t\t\t? (node as ParentNode)\n\t\t\t: null;\n\t};\n\n\tconst matchCount = (queryRoot: ParentNode, selector: string): number => {\n\t\ttry {\n\t\t\treturn queryRoot.querySelectorAll(selector).length;\n\t\t} catch {\n\t\t\t// A selector that fails to parse can't be relied on.\n\t\t\treturn Number.POSITIVE_INFINITY;\n\t\t}\n\t};\n\n\t// A candidate feature is only usable if it actually selects this element;\n\t// an escaping or engine mismatch (e.g. CSS string escapes in an attribute\n\t// value) could otherwise produce a selector that matches nothing. Or a\n\t// different element entirely.\n\tconst safeMatches = (element: Element, selector: string): boolean => {\n\t\ttry {\n\t\t\treturn typeof element.matches === \"function\" && element.matches(selector);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t};\n\n\tconst idIsUnique = (element: Element, id: string): boolean => {\n\t\tconst queryRoot = rootOf(element);\n\n\t\treturn queryRoot === null || matchCount(queryRoot, `#${esc(id)}`) === 1;\n\t};\n\n\t// A discriminating feature for one level of the selector: its CSS text plus\n\t// a predicate telling whether a sibling would match the same feature (used\n\t// to decide if an :nth-of-type pin is still needed).\n\ttype Feature = {\n\t\tfeature: string;\n\t\tsharedBy: (sibling: Element) => boolean;\n\t};\n\n\tconst classFeature = (cls: string): Feature => ({\n\t\tfeature: `.${esc(cls)}`,\n\t\tsharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls),\n\t});\n\n\t// The single feature that narrows the element down the most: the class or\n\t// href attribute with the fewest matches in the root. Hrefs break ties\n\t// between structurally-identical content blocks, where classes and\n\t// :nth-of-type (which only pins position within one parent) cannot. Without\n\t// a queryable root there is no rarity information, so the first class\n\t// stands in.\n\tconst rarestFeature = (\n\t\telement: Element,\n\t\tqueryRoot: ParentNode | null,\n\t): Feature | null => {\n\t\tconst classes = Array.from(element.classList).slice(0, 8);\n\n\t\tif (!queryRoot) {\n\t\t\tconst cls = classes[0];\n\n\t\t\treturn cls === undefined ? null : classFeature(cls);\n\t\t}\n\n\t\tlet best: Feature | null = null;\n\t\tlet bestCount = Number.POSITIVE_INFINITY;\n\n\t\tfor (const cls of classes) {\n\t\t\tconst candidate = classFeature(cls);\n\n\t\t\tif (!safeMatches(element, candidate.feature)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst count = matchCount(queryRoot, candidate.feature);\n\n\t\t\tif (count < bestCount) {\n\t\t\t\tbest = candidate;\n\t\t\t\tbestCount = count;\n\t\t\t}\n\n\t\t\tif (count === 1) {\n\t\t\t\treturn best;\n\t\t\t}\n\t\t}\n\n\t\tconst href =\n\t\t\ttypeof element.getAttribute === \"function\"\n\t\t\t\t? element.getAttribute(\"href\")\n\t\t\t\t: null;\n\n\t\t// Skip hrefs with characters that change meaning inside a CSS string\n\t\t// (quotes, backslashes), and query strings, which are too volatile\n\t\t// across scans to pin a selector to. Fragments (#main) stay eligible.\n\t\t// Skip links make stable discriminators.\n\t\tif (href && href.length <= 100 && !/[\"\\\\?]/.test(href)) {\n\t\t\tconst feature = `[href=\"${href}\"]`;\n\n\t\t\tif (\n\t\t\t\tsafeMatches(element, feature) &&\n\t\t\t\tmatchCount(queryRoot, feature) < bestCount\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tfeature,\n\t\t\t\t\tsharedBy: (sibling) =>\n\t\t\t\t\t\ttypeof sibling.getAttribute === \"function\" &&\n\t\t\t\t\t\tsibling.getAttribute(\"href\") === href,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn best;\n\t};\n\n\t// The element's 1-based position among same-tag siblings, and whether the\n\t// chosen feature fails to discriminate it from them (so the segment needs\n\t// an :nth-of-type pin). Siblings are absent on the serialisation test\n\t// nodes. There we skip the pin.\n\tconst positionAmongSiblings = (\n\t\telement: Element,\n\t\tsharedBy: (sibling: Element) => boolean,\n\t): { nth: number; ambiguous: boolean } => {\n\t\tconst siblings = (element.parentNode as ParentNode | null)?.children;\n\n\t\tif (!siblings) {\n\t\t\treturn { nth: 0, ambiguous: false };\n\t\t}\n\n\t\tlet nth = 0;\n\t\tlet count = 0;\n\t\tlet shared = 0;\n\n\t\tfor (const sibling of Array.from(siblings)) {\n\t\t\tif (sibling.nodeName !== element.nodeName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcount++;\n\n\t\t\tif (sibling === element) {\n\t\t\t\tnth = count;\n\t\t\t}\n\n\t\t\tif (sharedBy(sibling)) {\n\t\t\t\tshared++;\n\t\t\t}\n\t\t}\n\n\t\treturn { nth, ambiguous: shared > 1 };\n\t};\n\n\tconst segmentFor = (\n\t\telement: Element,\n\t\tqueryRoot: ParentNode | null,\n\t): { segment: string; anchored: boolean } => {\n\t\t// Only treat an id as an absolute anchor when it actually resolves to a\n\t\t// single element: pages with duplicate ids would otherwise yield a\n\t\t// selector (e.g. \"#dup>a\") that matches several elements.\n\t\tif (element.id && idIsUnique(element, element.id)) {\n\t\t\treturn { segment: `#${esc(element.id)}`, anchored: true };\n\t\t}\n\n\t\tconst feature = rarestFeature(element, queryRoot);\n\t\tlet segment = tagName(element) + (feature === null ? \"\" : feature.feature);\n\n\t\t// When same-tag siblings share the chosen feature, pin the position so the\n\t\t// segment selects exactly this element rather than all of them.\n\t\tconst { nth, ambiguous } = positionAmongSiblings(\n\t\t\telement,\n\t\t\tfeature === null ? () => true : feature.sharedBy,\n\t\t);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn { segment, anchored: false };\n\t};\n\n\t// A minimal segment for when a level's full segment would blow the budget\n\t// (e.g. an enormous class name or a long href): just the tag, pinned by\n\t// position when same-tag siblings would make the bare tag ambiguous.\n\tconst degradedSegmentFor = (element: Element): string => {\n\t\tlet segment = tagName(element);\n\n\t\tconst { nth, ambiguous } = positionAmongSiblings(element, () => true);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn segment;\n\t};\n\n\tconst segments: string[] = [];\n\tlet node: Node | null = root;\n\tconst queryRoot =\n\t\troot && root.nodeType === 1 ? rootOf(root as Element) : null;\n\n\ttry {\n\t\t// Walk only element nodes. Stopping at the first non-element parent (the\n\t\t// document, or a ShadowRoot when the target is inside an open shadow root)\n\t\t// keeps the selector within its tree and avoids reading `classList` off a\n\t\t// node that has none.\n\t\twhile (node && node.nodeType === 1) {\n\t\t\tconst element = node as Element;\n\t\t\tlet { segment, anchored } = segmentFor(element, queryRoot);\n\n\t\t\t// Keep within the budget (the +1 accounts for the \">\" that would join\n\t\t\t// this segment to the rest). A level whose full segment doesn't fit is\n\t\t\t// degraded to tag + position rather than discarded, so ancestor context\n\t\t\t// is never lost to one long feature.\n\t\t\tconst joinedWith = (candidate: string): number =>\n\t\t\t\tsegments.length\n\t\t\t\t\t? candidate.length + 1 + segments.join(\">\").length\n\t\t\t\t\t: candidate.length;\n\n\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\tsegment = degradedSegmentFor(element);\n\t\t\t\tanchored = false;\n\n\t\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsegments.unshift(segment);\n\n\t\t\tif (anchored) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Stop as soon as the selector already identifies a single element.\n\t\t\t// This, not truncation, is what keeps selectors short.\n\t\t\tif (queryRoot && matchCount(queryRoot, segments.join(\">\")) === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tnode = element.parentNode;\n\t\t}\n\t} catch {\n\t\t// A malformed node tree must never crash the audit; return what we have.\n\t}\n\n\treturn segments.join(\">\");\n}\n","const DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;\nconst DEFAULT_MAX_LENGTH = 300;\nconst ELLIPSIS = \"...\";\n\nexport type TruncateHtmlOptions = {\n\tmaxAttributeValueLength?: number;\n\tmaxLength?: number;\n};\n\n/**\n * Given an element's outerHTML, produce a truncated version suitable for display in results. For\n * memory efficiency, pass a shallow outerHTML i.e. `Node.cloneNode(false).outerHTML`.\n */\nexport function truncateHtml(\n\thtml: string,\n\toptions: TruncateHtmlOptions = {},\n): string {\n\tif (!html) {\n\t\treturn \"\";\n\t}\n\n\tconst maxAttributeValueLength =\n\t\toptions.maxAttributeValueLength ?? DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH;\n\tconst maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;\n\n\t// Keep only the opening tag\n\tconst closingBracket = html.indexOf(\">\");\n\tconst openingTag =\n\t\tclosingBracket === -1 ? html : html.slice(0, closingBracket + 1);\n\n\t// Shorten long quoted attribute values, preserving the quote style.\n\tconst trimmed = openingTag.replace(\n\t\t/=([\"'])([\\s\\S]*?)\\1/g,\n\t\t(match, quote: string, value: string) => {\n\t\t\tif (value.length <= maxAttributeValueLength) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\treturn `=${quote}${value.slice(0, maxAttributeValueLength)}${ELLIPSIS}${quote}`;\n\t\t},\n\t);\n\n\tif (trimmed.length > maxLength) {\n\t\treturn `${trimmed.slice(0, maxLength)}${ELLIPSIS}`;\n\t}\n\n\treturn trimmed;\n}\n"],"mappings":";AAUO,SAAS,YAAY,MAA2B;AACtD,QAAM,aAAa;AAEnB,QAAM,MAAM,CAAC,UACZ,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,aACjD,IAAI,OAAO,KAAK,IAChB;AAEJ,QAAM,UAAU,CAACA,UAChBA,MAAK,aAAa,IACfA,MAAK,SAAS,YAAY,IAC1BA,MAAK,SAAS,YAAY,EAAE,QAAQ,MAAM,EAAE;AAMhD,QAAM,SAAS,CAAC,YAAwC;AACvD,UAAMA,QACL,QACC,cAAc;AAEhB,WAAOA,SAAQ,OAAQA,MAAoB,qBAAqB,aAC5DA,QACD;AAAA,EACJ;AAEA,QAAM,aAAa,CAACC,YAAuB,aAA6B;AACvE,QAAI;AACH,aAAOA,WAAU,iBAAiB,QAAQ,EAAE;AAAA,IAC7C,QAAQ;AAEP,aAAO,OAAO;AAAA,IACf;AAAA,EACD;AAMA,QAAM,cAAc,CAAC,SAAkB,aAA8B;AACpE,QAAI;AACH,aAAO,OAAO,QAAQ,YAAY,cAAc,QAAQ,QAAQ,QAAQ;AAAA,IACzE,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD;AAEA,QAAM,aAAa,CAAC,SAAkB,OAAwB;AAC7D,UAAMA,aAAY,OAAO,OAAO;AAEhC,WAAOA,eAAc,QAAQ,WAAWA,YAAW,IAAI,IAAI,EAAE,CAAC,EAAE,MAAM;AAAA,EACvE;AAUA,QAAM,eAAe,CAAC,SAA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":["node","queryRoot"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a compact, hopefully-unique selector for any given element on the page. This function is
|
|
3
|
+
* serialized and run in the page context, so it must not reference any symbols outside its own
|
|
4
|
+
* scope.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors axe-core's approach: each level contributes the fewest features that discriminate the
|
|
7
|
+
* element (a unique id, the rarest single class, or an :nth-of-type position), and the walk stops
|
|
8
|
+
* as soon as the joined selector matches exactly one element. Selectors stay short because of
|
|
9
|
+
* that early stop, not because of truncation; the length budget is only a backstop.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSelector(root: Node | null): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { BrowserAdaptor, ElementRef, Rect } from "./adaptor";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type TruncateHtmlOptions = {
|
|
2
|
+
maxAttributeValueLength?: number;
|
|
3
|
+
maxLength?: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Given an element's outerHTML, produce a truncated version suitable for display in results. For
|
|
7
|
+
* memory efficiency, pass a shallow outerHTML i.e. `Node.cloneNode(false).outerHTML`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function truncateHtml(html: string, options?: TruncateHtmlOptions): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a11y-pulse/browser-adaptor",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared browser adaptor primitives and DOM helpers for A11y Pulse accessibility audits.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
7
|
+
"author": "A11y Pulse Limited",
|
|
8
|
+
"homepage": "https://github.com/A11y-Pulse/audits/tree/main/packages/browser-adaptor#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/A11y-Pulse/audits.git",
|
|
12
|
+
"directory": "packages/browser-adaptor"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/A11y-Pulse/audits/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"accessibility",
|
|
19
|
+
"a11y",
|
|
20
|
+
"puppeteer",
|
|
21
|
+
"browser-adaptor",
|
|
22
|
+
"audit"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./puppeteer": {
|
|
33
|
+
"types": "./dist/adaptors/puppeteer.d.ts",
|
|
34
|
+
"import": "./dist/adaptors/puppeteer.js"
|
|
35
|
+
},
|
|
36
|
+
"./dom": {
|
|
37
|
+
"types": "./dist/dom.d.ts",
|
|
38
|
+
"import": "./dist/dom.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE.md"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"lint": "biome check",
|
|
50
|
+
"lint:fix": "biome check --fix",
|
|
51
|
+
"test:unit": "vitest run",
|
|
52
|
+
"test": "npm run typecheck && npm run test:unit",
|
|
53
|
+
"prepublishOnly": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"puppeteer": "^25.5.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"puppeteer": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"happy-dom": "^20.11.2",
|
|
68
|
+
"puppeteer": "^25.5.0"
|
|
69
|
+
}
|
|
70
|
+
}
|