@a11y-pulse/orphaned-tab-roles-audit 0.0.0-stage → 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/LICENSE.md +166 -0
- package/README.md +140 -2
- package/dist/audit.d.ts +11 -0
- package/dist/browser-scripts.d.ts +26 -0
- package/dist/classify.d.ts +22 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/result.d.ts +26 -0
- package/package.json +60 -5
package/LICENSE.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Copyright (c) 2026-present, A11y Pulse (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
CHANGED
|
@@ -1,3 +1,141 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @a11y-pulse/orphaned-tab-roles-audit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@a11y-pulse/orphaned-tab-roles-audit)
|
|
4
|
+
[](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE.md)
|
|
6
|
+
|
|
7
|
+
An accessibility audit that checks the ARIA tab contract that axe-core does not: that every `tab` has a `tabpanel` and every `tabpanel` has a `tab`. axe-core's `aria-required-parent` and `aria-required-children` check that tabs sit in a tablist, but a tab with no panel anywhere, or a tab panel nothing controls, passes every axe-core rule. A screen reader announces such a tab as "tab, 1 of 15", promising in-page panels that do not exist. The most common case is navigation links given `role="tab"` by a component library, which take the user to another page when activated.
|
|
8
|
+
|
|
9
|
+
WCAG names no failure technique for this. Following axe-core's convention for ARIA structure, results are mapped to [**WCAG 2.2: 1.3.1 Info and Relationships**](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships) and [**4.1.2 Name, Role, Value**](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value), on the reading that a role the element cannot live up to misinforms assistive technology.
|
|
10
|
+
|
|
11
|
+
This audit was developed by [A11y Pulse](https://www.a11ypulse.com/) for its accessibility monitoring service. It is released as source-available under the [PolyForm Shield License 1.0.0](#license).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @a11y-pulse/orphaned-tab-roles-audit @a11y-pulse/browser-adaptor puppeteer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { runOrphanedTabRolesAudit } from "@a11y-pulse/orphaned-tab-roles-audit";
|
|
23
|
+
import { PuppeteerAdaptor } from "@a11y-pulse/browser-adaptor/puppeteer";
|
|
24
|
+
import puppeteer from "puppeteer";
|
|
25
|
+
|
|
26
|
+
const browser = await puppeteer.launch();
|
|
27
|
+
const page = await browser.newPage();
|
|
28
|
+
await page.goto("https://who.likesdogs.nz/");
|
|
29
|
+
|
|
30
|
+
const result = await runOrphanedTabRolesAudit(new PuppeteerAdaptor(page));
|
|
31
|
+
|
|
32
|
+
console.log(result.summary);
|
|
33
|
+
// { checked: 5, failed: 3, needsReview: 2, passed: 0 }
|
|
34
|
+
|
|
35
|
+
console.log(result.failed[0]);
|
|
36
|
+
// {
|
|
37
|
+
// selector: "#nav-dogs",
|
|
38
|
+
// html: '<a id="nav-dogs" role="tab" href="/dogs">',
|
|
39
|
+
// role: "tab",
|
|
40
|
+
// finding: "tab-used-as-link"
|
|
41
|
+
// }
|
|
42
|
+
|
|
43
|
+
await browser.close();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## How it decides
|
|
47
|
+
|
|
48
|
+
The audit reads every element whose role is `tab` or `tabpanel` in one call into the page, hidden ones included, since an inactive tab's hidden panel is the correct pattern. A tab and a panel are associated when the tab's `aria-controls` names the panel, or the panel's `aria-labelledby` names the tab.
|
|
49
|
+
|
|
50
|
+
For each tab, the first rule that applies:
|
|
51
|
+
|
|
52
|
+
| Finding | Bucket | When |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| none | `passed` | The tab is associated with a tab panel |
|
|
55
|
+
| `tab-used-as-link` | `failed` | The tab is, or sits inside, a link to another document. Fragment links (`#panel`), same-page URLs and `javascript:` links do not count |
|
|
56
|
+
| `controls-not-a-tabpanel` | `needsReview` | `aria-controls` points at an element that is not a tab panel |
|
|
57
|
+
| `tab-without-panel` | `failed` | The page has no tab panels, or the tab has no `aria-controls` and every tab panel on the page is associated with another tab |
|
|
58
|
+
| `association-unverifiable` | `needsReview` | Anything else: tab panels without an association exist, or the tab's `aria-controls` names a panel that is not in the page |
|
|
59
|
+
|
|
60
|
+
For each tab panel:
|
|
61
|
+
|
|
62
|
+
| Finding | Bucket | When |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| none | `passed` | The panel is associated with a tab |
|
|
65
|
+
| `tabpanel-without-tab` | `failed` | The page has no tabs, or every tab on the page is associated with another panel or has an `aria-controls` that points only at tab panels or at nothing mounted yet, so each already has a panel of its own |
|
|
66
|
+
| `association-unverifiable` | `needsReview` | Some tab declares no association, so it may be this panel's |
|
|
67
|
+
|
|
68
|
+
The failures never depend on guessing which panel belongs to which tab, only on there being none left over for it. That is also why the check is document-wide rather than per tablist: an unwired tab widget next to a wired one fails, because the wired widget's panels are all spoken for.
|
|
69
|
+
|
|
70
|
+
## Browser support
|
|
71
|
+
|
|
72
|
+
| Adaptor | Browser | Supported |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| Puppeteer | Chrome | Yes |
|
|
75
|
+
| Playwright | Chromium | Yes |
|
|
76
|
+
| Playwright | WebKit | Yes |
|
|
77
|
+
| Playwright | Firefox | Yes |
|
|
78
|
+
|
|
79
|
+
## Options
|
|
80
|
+
|
|
81
|
+
| Option | Type | Default | Description |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| `reportLimit` | `number` | `10` | Max elements to list in each of `failed`, `needsReview` and `passed`. The summary still counts every element. |
|
|
84
|
+
|
|
85
|
+
## Result shape
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
type OrphanedTabRolesElement = {
|
|
89
|
+
selector: string;
|
|
90
|
+
html: string;
|
|
91
|
+
role: "tab" | "tabpanel";
|
|
92
|
+
finding:
|
|
93
|
+
| "tab-used-as-link"
|
|
94
|
+
| "tab-without-panel"
|
|
95
|
+
| "tabpanel-without-tab"
|
|
96
|
+
| "controls-not-a-tabpanel"
|
|
97
|
+
| "association-unverifiable"
|
|
98
|
+
| null;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type OrphanedTabRolesResult = {
|
|
102
|
+
failed: OrphanedTabRolesElement[];
|
|
103
|
+
needsReview: OrphanedTabRolesElement[];
|
|
104
|
+
passed: OrphanedTabRolesElement[];
|
|
105
|
+
summary: {
|
|
106
|
+
checked: number;
|
|
107
|
+
failed: number;
|
|
108
|
+
needsReview: number;
|
|
109
|
+
passed: number;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`classifyTabRoles(elements)`, the pure classifier behind the audit, is also exported.
|
|
115
|
+
|
|
116
|
+
## Limitations
|
|
117
|
+
|
|
118
|
+
- **Association, not pairing.** A tab whose `aria-controls` names another tab's panel passes: the audit checks that an association exists, not that it is the right one.
|
|
119
|
+
- **Markup, not behaviour.** Arrow-key navigation, `aria-selected` and whether activating a tab shows its panel are not tested.
|
|
120
|
+
- **Light DOM and attributes only.** Tabs inside shadow roots or iframes, and custom elements that take their role from `ElementInternals` rather than a `role` attribute, are not reached.
|
|
121
|
+
- **Tabs outside a tablist** are axe-core's `aria-required-parent`. Such a tab is still checked for a panel here, so a navigation link with `role="tab"` and no tablist can be reported by both.
|
|
122
|
+
|
|
123
|
+
## Known false positives
|
|
124
|
+
|
|
125
|
+
Cases where the audit reports a problem that is not one. Each says which bucket it lands in: `incomplete` asks for a human to check, `violations` claims a failure.
|
|
126
|
+
|
|
127
|
+
In the A11y Pulse audit runner, `failed` is reported in `violations` and `needsReview` in `incomplete`.
|
|
128
|
+
|
|
129
|
+
- **Widgets wired up after load** (`incomplete`). A script that adds `aria-controls` when a tab is first activated leaves its tabs and panels without an association when the audit runs.
|
|
130
|
+
- **Lazily mounted panels** (`incomplete`). A tab whose `aria-controls` names a panel the page has not rendered yet is reviewed rather than passed. Only a page with no tab panels at all fails it.
|
|
131
|
+
- **Tabs that control a region** (`incomplete`). A tab whose `aria-controls` names a wrapper without `role="tabpanel"` may still work. The tab panels beside it are reviewed too, since the wrapper may hold one of them.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
Released under the [PolyForm Shield License 1.0.0](./LICENSE.md), in plain language:
|
|
136
|
+
|
|
137
|
+
- **Source-available.** The source is public and you can read, fork, and modify it.
|
|
138
|
+
- **Permitted for non-competing use.** You can use this package freely in your own products and services, as long as they don't compete with A11y Pulse.
|
|
139
|
+
- **Competing products are forbidden.** You may not use this software (or a modified version of it) to build a product or service that competes with A11y Pulse's accessibility monitoring offering.
|
|
140
|
+
|
|
141
|
+
See [LICENSE.md](./LICENSE.md) for the full, binding terms.
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type BrowserAdaptor } from "@a11y-pulse/browser-adaptor";
|
|
2
|
+
import type { OrphanedTabRolesResult } from "./result";
|
|
3
|
+
export declare const DEFAULT_REPORT_LIMIT = 10;
|
|
4
|
+
export type OrphanedTabRolesOptions = {
|
|
5
|
+
/** Max elements to report in each of `failed`, `needsReview` and `passed`. Defaults to 10. */
|
|
6
|
+
reportLimit?: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Check that every tab on the page has a tab panel and every tab panel has a tab.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runOrphanedTabRolesAudit(adaptor: BrowserAdaptor, options?: OrphanedTabRolesOptions): Promise<OrphanedTabRolesResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT: Functions in this file are serialized and injected into the audited page, so they must
|
|
3
|
+
* not reference any symbols outside their own scope.
|
|
4
|
+
*/
|
|
5
|
+
export type TabRole = "tab" | "tabpanel";
|
|
6
|
+
export type CollectedTabRole = {
|
|
7
|
+
role: TabRole;
|
|
8
|
+
/** Indices of the collected elements this element's `aria-controls` resolves to. */
|
|
9
|
+
controls: number[];
|
|
10
|
+
/** `aria-controls` lists at least one id, whether or not it resolves. */
|
|
11
|
+
hasControls: boolean;
|
|
12
|
+
/** `aria-controls` resolves to an element that is not a tab panel. */
|
|
13
|
+
controlsOther: boolean;
|
|
14
|
+
/** Indices of the collected elements this element's `aria-labelledby` resolves to. */
|
|
15
|
+
labelledBy: number[];
|
|
16
|
+
/** A link to another document, so activating it navigates instead of switching panels. */
|
|
17
|
+
navigates: boolean;
|
|
18
|
+
/** Shallow outerHTML. */
|
|
19
|
+
html: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Collect every element whose role is `tab` or `tabpanel` in the main document, hidden ones
|
|
23
|
+
* included, and resolve their `aria-controls` and `aria-labelledby` references. The collected
|
|
24
|
+
* elements are left on `window[stashKey]`, in the same order.
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectTabRolesScript(stashKey: string): CollectedTabRole[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CollectedTabRole } from "./browser-scripts";
|
|
2
|
+
/**
|
|
3
|
+
* - `tab-used-as-link`: a tab that links to another document and is associated with no panel.
|
|
4
|
+
* - `tab-without-panel`: a tab with no panel it could control, because the page has none or every
|
|
5
|
+
* one belongs to another tab.
|
|
6
|
+
* - `tabpanel-without-tab`: a tab panel no tab could control, because the page has no tabs or every
|
|
7
|
+
* one belongs to another panel.
|
|
8
|
+
* - `controls-not-a-tabpanel`: a tab whose `aria-controls` points at something other than a tab
|
|
9
|
+
* panel.
|
|
10
|
+
* - `association-unverifiable`: no association is declared, but one may be wired up some other way.
|
|
11
|
+
*/
|
|
12
|
+
export type TabRoleFinding = "tab-used-as-link" | "tab-without-panel" | "tabpanel-without-tab" | "controls-not-a-tabpanel" | "association-unverifiable";
|
|
13
|
+
export type TabRoleVerdict = "failed" | "needs-review" | "passed";
|
|
14
|
+
export type TabRoleClassification = {
|
|
15
|
+
verdict: TabRoleVerdict;
|
|
16
|
+
finding: TabRoleFinding | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Classify each collected tab and tab panel by whether it is associated with a counterpart, in the
|
|
20
|
+
* same order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function classifyTabRoles(elements: readonly CollectedTabRole[]): TabRoleClassification[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { BrowserAdaptor, ElementRef } from "@a11y-pulse/browser-adaptor";
|
|
2
|
+
export type { OrphanedTabRolesOptions } from "./audit";
|
|
3
|
+
export { DEFAULT_REPORT_LIMIT, runOrphanedTabRolesAudit } from "./audit";
|
|
4
|
+
export type { CollectedTabRole, TabRole } from "./browser-scripts";
|
|
5
|
+
export type { TabRoleClassification, TabRoleFinding, TabRoleVerdict } from "./classify";
|
|
6
|
+
export { classifyTabRoles } from "./classify";
|
|
7
|
+
export type { OrphanedTabRolesElement, OrphanedTabRolesResult } from "./result";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// src/audit.ts
|
|
2
|
+
import {
|
|
3
|
+
releaseStashedElements,
|
|
4
|
+
stashedElementSelectors
|
|
5
|
+
} from "@a11y-pulse/browser-adaptor";
|
|
6
|
+
import { truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
|
|
7
|
+
|
|
8
|
+
// src/browser-scripts.ts
|
|
9
|
+
function collectTabRolesScript(stashKey) {
|
|
10
|
+
const roleOf = (el) => (el.getAttribute("role") ?? "").trim().split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
11
|
+
const elements = Array.from(document.querySelectorAll("[role]")).filter((el) => {
|
|
12
|
+
const role = roleOf(el);
|
|
13
|
+
return role === "tab" || role === "tabpanel";
|
|
14
|
+
});
|
|
15
|
+
const idrefs = (el, attribute) => (el.getAttribute(attribute) ?? "").split(/\s+/).filter(Boolean).flatMap((id) => {
|
|
16
|
+
const target = document.getElementById(id);
|
|
17
|
+
return target ? [target] : [];
|
|
18
|
+
});
|
|
19
|
+
const navigates = (el) => {
|
|
20
|
+
const link = el.closest("a[href]");
|
|
21
|
+
if (!link) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const href = link.getAttribute("href") ?? "";
|
|
25
|
+
if (href.startsWith("#") || /^\s*javascript:/i.test(href)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const target = new URL(link.href, document.baseURI);
|
|
29
|
+
const here = new URL(location.href);
|
|
30
|
+
return target.origin !== here.origin || target.pathname !== here.pathname || target.search !== here.search;
|
|
31
|
+
};
|
|
32
|
+
const collected = elements.map((el) => {
|
|
33
|
+
const controlled = idrefs(el, "aria-controls");
|
|
34
|
+
return {
|
|
35
|
+
role: roleOf(el),
|
|
36
|
+
controls: controlled.map((target) => elements.indexOf(target)).filter((i) => i !== -1),
|
|
37
|
+
hasControls: Boolean(el.getAttribute("aria-controls")?.trim()),
|
|
38
|
+
controlsOther: controlled.some((target) => roleOf(target) !== "tabpanel"),
|
|
39
|
+
labelledBy: idrefs(el, "aria-labelledby").map((target) => elements.indexOf(target)).filter((i) => i !== -1),
|
|
40
|
+
navigates: navigates(el),
|
|
41
|
+
html: el.cloneNode(false).outerHTML
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
window[stashKey] = elements;
|
|
45
|
+
return collected;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/classify.ts
|
|
49
|
+
var PASSED = { verdict: "passed", finding: null };
|
|
50
|
+
function failed(finding) {
|
|
51
|
+
return { verdict: "failed", finding };
|
|
52
|
+
}
|
|
53
|
+
function needsReview(finding) {
|
|
54
|
+
return { verdict: "needs-review", finding };
|
|
55
|
+
}
|
|
56
|
+
function classifyTabRoles(elements) {
|
|
57
|
+
const isTab = (i) => elements[i]?.role === "tab";
|
|
58
|
+
const isPanel = (i) => elements[i]?.role === "tabpanel";
|
|
59
|
+
const partners = elements.map(() => /* @__PURE__ */ new Set());
|
|
60
|
+
elements.forEach((element, i) => {
|
|
61
|
+
const controlled = element.role === "tab" ? element.controls.filter(isPanel) : [];
|
|
62
|
+
const labellers = element.role === "tabpanel" ? element.labelledBy.filter(isTab) : [];
|
|
63
|
+
for (const panel of controlled) {
|
|
64
|
+
partners[i].add(panel);
|
|
65
|
+
partners[panel].add(i);
|
|
66
|
+
}
|
|
67
|
+
for (const tab of labellers) {
|
|
68
|
+
partners[i].add(tab);
|
|
69
|
+
partners[tab].add(i);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const tabs = elements.flatMap((element, i) => element.role === "tab" ? [i] : []);
|
|
73
|
+
const panels = elements.flatMap((element, i) => element.role === "tabpanel" ? [i] : []);
|
|
74
|
+
const associated = (i) => partners[i].size > 0;
|
|
75
|
+
const tabHasOwnPanel = (i) => associated(i) || elements[i].hasControls && !elements[i].controlsOther;
|
|
76
|
+
return elements.map((element, i) => {
|
|
77
|
+
if (associated(i)) {
|
|
78
|
+
return PASSED;
|
|
79
|
+
}
|
|
80
|
+
if (element.role === "tabpanel") {
|
|
81
|
+
return tabs.every(tabHasOwnPanel) ? failed("tabpanel-without-tab") : needsReview("association-unverifiable");
|
|
82
|
+
}
|
|
83
|
+
if (element.navigates) {
|
|
84
|
+
return failed("tab-used-as-link");
|
|
85
|
+
}
|
|
86
|
+
if (element.controlsOther) {
|
|
87
|
+
return needsReview("controls-not-a-tabpanel");
|
|
88
|
+
}
|
|
89
|
+
if (panels.length === 0 || !element.hasControls && panels.every(associated)) {
|
|
90
|
+
return failed("tab-without-panel");
|
|
91
|
+
}
|
|
92
|
+
return needsReview("association-unverifiable");
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/audit.ts
|
|
97
|
+
var DEFAULT_REPORT_LIMIT = 10;
|
|
98
|
+
var STASH_KEY = "__a11yPulseOrphanedTabRoles";
|
|
99
|
+
async function toElements(adaptor, classified) {
|
|
100
|
+
const selectors = await stashedElementSelectors(
|
|
101
|
+
adaptor,
|
|
102
|
+
STASH_KEY,
|
|
103
|
+
classified.map(({ index }) => index)
|
|
104
|
+
);
|
|
105
|
+
return classified.map(({ element, finding }, i) => ({
|
|
106
|
+
selector: selectors[i],
|
|
107
|
+
html: truncateHtml(element.html),
|
|
108
|
+
role: element.role,
|
|
109
|
+
finding
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
async function runOrphanedTabRolesAudit(adaptor, options = {}) {
|
|
113
|
+
const reportLimit = options.reportLimit ?? DEFAULT_REPORT_LIMIT;
|
|
114
|
+
const elements = await adaptor.evaluate(collectTabRolesScript, STASH_KEY);
|
|
115
|
+
try {
|
|
116
|
+
const classified = classifyTabRoles(elements).map((classification, index) => ({
|
|
117
|
+
...classification,
|
|
118
|
+
index,
|
|
119
|
+
element: elements[index]
|
|
120
|
+
}));
|
|
121
|
+
const withVerdict = (verdict) => classified.filter((entry) => entry.verdict === verdict);
|
|
122
|
+
const failed2 = withVerdict("failed");
|
|
123
|
+
const needsReview2 = withVerdict("needs-review");
|
|
124
|
+
const passed = withVerdict("passed");
|
|
125
|
+
return {
|
|
126
|
+
failed: await toElements(adaptor, failed2.slice(0, reportLimit)),
|
|
127
|
+
needsReview: await toElements(adaptor, needsReview2.slice(0, reportLimit)),
|
|
128
|
+
passed: await toElements(adaptor, passed.slice(0, reportLimit)),
|
|
129
|
+
summary: {
|
|
130
|
+
checked: classified.length,
|
|
131
|
+
failed: failed2.length,
|
|
132
|
+
needsReview: needsReview2.length,
|
|
133
|
+
passed: passed.length
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
} finally {
|
|
137
|
+
await releaseStashedElements(adaptor, STASH_KEY);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
DEFAULT_REPORT_LIMIT,
|
|
142
|
+
classifyTabRoles,
|
|
143
|
+
runOrphanedTabRolesAudit
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/audit.ts","../src/browser-scripts.ts","../src/classify.ts"],"sourcesContent":["import {\n\ttype BrowserAdaptor,\n\treleaseStashedElements,\n\tstashedElementSelectors,\n} from \"@a11y-pulse/browser-adaptor\";\nimport { truncateHtml } from \"@a11y-pulse/browser-adaptor/dom\";\nimport { type CollectedTabRole, collectTabRolesScript } from \"./browser-scripts\";\nimport { classifyTabRoles, type TabRoleClassification, type TabRoleVerdict } from \"./classify\";\nimport type { OrphanedTabRolesElement, OrphanedTabRolesResult } from \"./result\";\n\nexport const DEFAULT_REPORT_LIMIT = 10;\n\nconst STASH_KEY = \"__a11yPulseOrphanedTabRoles\";\n\nexport type OrphanedTabRolesOptions = {\n\t/** Max elements to report in each of `failed`, `needsReview` and `passed`. Defaults to 10. */\n\treportLimit?: number;\n};\n\ntype Classified = TabRoleClassification & { index: number; element: CollectedTabRole };\n\nasync function toElements(\n\tadaptor: BrowserAdaptor,\n\tclassified: readonly Classified[],\n): Promise<OrphanedTabRolesElement[]> {\n\tconst selectors = await stashedElementSelectors(\n\t\tadaptor,\n\t\tSTASH_KEY,\n\t\tclassified.map(({ index }) => index),\n\t);\n\n\treturn classified.map(({ element, finding }, i) => ({\n\t\tselector: selectors[i]!,\n\t\thtml: truncateHtml(element.html),\n\t\trole: element.role,\n\t\tfinding,\n\t}));\n}\n\n/**\n * Check that every tab on the page has a tab panel and every tab panel has a tab.\n */\nexport async function runOrphanedTabRolesAudit(\n\tadaptor: BrowserAdaptor,\n\toptions: OrphanedTabRolesOptions = {},\n): Promise<OrphanedTabRolesResult> {\n\tconst reportLimit = options.reportLimit ?? DEFAULT_REPORT_LIMIT;\n\n\tconst elements = await adaptor.evaluate(collectTabRolesScript, STASH_KEY);\n\n\ttry {\n\t\tconst classified: Classified[] = classifyTabRoles(elements).map((classification, index) => ({\n\t\t\t...classification,\n\t\t\tindex,\n\t\t\telement: elements[index]!,\n\t\t}));\n\t\tconst withVerdict = (verdict: TabRoleVerdict) =>\n\t\t\tclassified.filter((entry) => entry.verdict === verdict);\n\n\t\tconst failed = withVerdict(\"failed\");\n\t\tconst needsReview = withVerdict(\"needs-review\");\n\t\tconst passed = withVerdict(\"passed\");\n\n\t\treturn {\n\t\t\tfailed: await toElements(adaptor, failed.slice(0, reportLimit)),\n\t\t\tneedsReview: await toElements(adaptor, needsReview.slice(0, reportLimit)),\n\t\t\tpassed: await toElements(adaptor, passed.slice(0, reportLimit)),\n\t\t\tsummary: {\n\t\t\t\tchecked: classified.length,\n\t\t\t\tfailed: failed.length,\n\t\t\t\tneedsReview: needsReview.length,\n\t\t\t\tpassed: passed.length,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tawait releaseStashedElements(adaptor, STASH_KEY);\n\t}\n}\n","/**\n * IMPORTANT: Functions in this file are serialized and injected into the audited page, so they must\n * not reference any symbols outside their own scope.\n */\n\nexport type TabRole = \"tab\" | \"tabpanel\";\n\nexport type CollectedTabRole = {\n\trole: TabRole;\n\t/** Indices of the collected elements this element's `aria-controls` resolves to. */\n\tcontrols: number[];\n\t/** `aria-controls` lists at least one id, whether or not it resolves. */\n\thasControls: boolean;\n\t/** `aria-controls` resolves to an element that is not a tab panel. */\n\tcontrolsOther: boolean;\n\t/** Indices of the collected elements this element's `aria-labelledby` resolves to. */\n\tlabelledBy: number[];\n\t/** A link to another document, so activating it navigates instead of switching panels. */\n\tnavigates: boolean;\n\t/** Shallow outerHTML. */\n\thtml: string;\n};\n\n/**\n * Collect every element whose role is `tab` or `tabpanel` in the main document, hidden ones\n * included, and resolve their `aria-controls` and `aria-labelledby` references. The collected\n * elements are left on `window[stashKey]`, in the same order.\n */\nexport function collectTabRolesScript(stashKey: string): CollectedTabRole[] {\n\tconst roleOf = (el: Element): string =>\n\t\t(el.getAttribute(\"role\") ?? \"\").trim().split(/\\s+/)[0]?.toLowerCase() ?? \"\";\n\n\tconst elements = Array.from(document.querySelectorAll(\"[role]\")).filter((el) => {\n\t\tconst role = roleOf(el);\n\n\t\treturn role === \"tab\" || role === \"tabpanel\";\n\t});\n\n\tconst idrefs = (el: Element, attribute: string): Element[] =>\n\t\t(el.getAttribute(attribute) ?? \"\")\n\t\t\t.split(/\\s+/)\n\t\t\t.filter(Boolean)\n\t\t\t.flatMap((id) => {\n\t\t\t\tconst target = document.getElementById(id);\n\n\t\t\t\treturn target ? [target] : [];\n\t\t\t});\n\n\t// Fragment-only and same-document hrefs are how Bootstrap-style tab anchors point at panels.\n\tconst navigates = (el: Element): boolean => {\n\t\tconst link = el.closest(\"a[href]\") as HTMLAnchorElement | null;\n\n\t\tif (!link) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst href = link.getAttribute(\"href\") ?? \"\";\n\n\t\tif (href.startsWith(\"#\") || /^\\s*javascript:/i.test(href)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst target = new URL(link.href, document.baseURI);\n\t\tconst here = new URL(location.href);\n\n\t\treturn (\n\t\t\ttarget.origin !== here.origin ||\n\t\t\ttarget.pathname !== here.pathname ||\n\t\t\ttarget.search !== here.search\n\t\t);\n\t};\n\n\tconst collected = elements.map((el): CollectedTabRole => {\n\t\tconst controlled = idrefs(el, \"aria-controls\");\n\n\t\treturn {\n\t\t\trole: roleOf(el) as TabRole,\n\t\t\tcontrols: controlled.map((target) => elements.indexOf(target)).filter((i) => i !== -1),\n\t\t\thasControls: Boolean(el.getAttribute(\"aria-controls\")?.trim()),\n\t\t\tcontrolsOther: controlled.some((target) => roleOf(target) !== \"tabpanel\"),\n\t\t\tlabelledBy: idrefs(el, \"aria-labelledby\")\n\t\t\t\t.map((target) => elements.indexOf(target))\n\t\t\t\t.filter((i) => i !== -1),\n\t\t\tnavigates: navigates(el),\n\t\t\thtml: (el.cloneNode(false) as Element).outerHTML,\n\t\t};\n\t});\n\n\t(window as unknown as Record<string, unknown>)[stashKey] = elements;\n\n\treturn collected;\n}\n","import type { CollectedTabRole } from \"./browser-scripts\";\n\n/**\n * - `tab-used-as-link`: a tab that links to another document and is associated with no panel.\n * - `tab-without-panel`: a tab with no panel it could control, because the page has none or every\n * one belongs to another tab.\n * - `tabpanel-without-tab`: a tab panel no tab could control, because the page has no tabs or every\n * one belongs to another panel.\n * - `controls-not-a-tabpanel`: a tab whose `aria-controls` points at something other than a tab\n * panel.\n * - `association-unverifiable`: no association is declared, but one may be wired up some other way.\n */\nexport type TabRoleFinding =\n\t| \"tab-used-as-link\"\n\t| \"tab-without-panel\"\n\t| \"tabpanel-without-tab\"\n\t| \"controls-not-a-tabpanel\"\n\t| \"association-unverifiable\";\n\nexport type TabRoleVerdict = \"failed\" | \"needs-review\" | \"passed\";\n\nexport type TabRoleClassification = { verdict: TabRoleVerdict; finding: TabRoleFinding | null };\n\nconst PASSED: TabRoleClassification = { verdict: \"passed\", finding: null };\n\nfunction failed(finding: TabRoleFinding): TabRoleClassification {\n\treturn { verdict: \"failed\", finding };\n}\n\nfunction needsReview(finding: TabRoleFinding): TabRoleClassification {\n\treturn { verdict: \"needs-review\", finding };\n}\n\n/**\n * Classify each collected tab and tab panel by whether it is associated with a counterpart, in the\n * same order.\n */\nexport function classifyTabRoles(elements: readonly CollectedTabRole[]): TabRoleClassification[] {\n\tconst isTab = (i: number) => elements[i]?.role === \"tab\";\n\tconst isPanel = (i: number) => elements[i]?.role === \"tabpanel\";\n\n\t// An explicit association runs either way: the tab's `aria-controls` names the panel, or the\n\t// panel's `aria-labelledby` names the tab.\n\tconst partners = elements.map(() => new Set<number>());\n\n\telements.forEach((element, i) => {\n\t\tconst controlled = element.role === \"tab\" ? element.controls.filter(isPanel) : [];\n\t\tconst labellers = element.role === \"tabpanel\" ? element.labelledBy.filter(isTab) : [];\n\n\t\tfor (const panel of controlled) {\n\t\t\tpartners[i]!.add(panel);\n\t\t\tpartners[panel]!.add(i);\n\t\t}\n\n\t\tfor (const tab of labellers) {\n\t\t\tpartners[i]!.add(tab);\n\t\t\tpartners[tab]!.add(i);\n\t\t}\n\t});\n\n\tconst tabs = elements.flatMap((element, i) => (element.role === \"tab\" ? [i] : []));\n\tconst panels = elements.flatMap((element, i) => (element.role === \"tabpanel\" ? [i] : []));\n\tconst associated = (i: number) => partners[i]!.size > 0;\n\n\t// A tab whose `aria-controls` names a panel that is not mounted yet still has a panel of its own,\n\t// but one that names only other elements may be pointing at a wrapper around its panel.\n\tconst tabHasOwnPanel = (i: number) =>\n\t\tassociated(i) || (elements[i]!.hasControls && !elements[i]!.controlsOther);\n\n\treturn elements.map((element, i) => {\n\t\tif (associated(i)) {\n\t\t\treturn PASSED;\n\t\t}\n\n\t\tif (element.role === \"tabpanel\") {\n\t\t\treturn tabs.every(tabHasOwnPanel)\n\t\t\t\t? failed(\"tabpanel-without-tab\")\n\t\t\t\t: needsReview(\"association-unverifiable\");\n\t\t}\n\n\t\tif (element.navigates) {\n\t\t\treturn failed(\"tab-used-as-link\");\n\t\t}\n\n\t\tif (element.controlsOther) {\n\t\t\treturn needsReview(\"controls-not-a-tabpanel\");\n\t\t}\n\n\t\t// A dangling `aria-controls` is how lazily mounted panels look, so only a page with no panels\n\t\t// at all fails such a tab.\n\t\tif (panels.length === 0 || (!element.hasControls && panels.every(associated))) {\n\t\t\treturn failed(\"tab-without-panel\");\n\t\t}\n\n\t\treturn needsReview(\"association-unverifiable\");\n\t});\n}\n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AACH;AAKA,eAAsB,yBACrB,SACA,UAAmC,CAAC,GACF;AAClC,QAAM,cAAc,QAAQ,eAAe;AAE3C,QAAM,WAAW,MAAM,QAAQ,SAAS,uBAAuB,SAAS;AAExE,MAAI;AACH,UAAM,aAA2B,iBAAiB,QAAQ,EAAE,IAAI,CAAC,gBAAgB,WAAW;AAAA,MAC3F,GAAG;AAAA,MACH;AAAA,MACA,SAAS,SAAS,KAAK;AAAA,IACxB,EAAE;AACF,UAAM,cAAc,CAAC,YACpB,WAAW,OAAO,CAAC,UAAU,MAAM,YAAY,OAAO;AAEvD,UAAMA,UAAS,YAAY,QAAQ;AACnC,UAAMC,eAAc,YAAY,cAAc;AAC9C,UAAM,SAAS,YAAY,QAAQ;AAEnC,WAAO;AAAA,MACN,QAAQ,MAAM,WAAW,SAASD,QAAO,MAAM,GAAG,WAAW,CAAC;AAAA,MAC9D,aAAa,MAAM,WAAW,SAASC,aAAY,MAAM,GAAG,WAAW,CAAC;AAAA,MACxE,QAAQ,MAAM,WAAW,SAAS,OAAO,MAAM,GAAG,WAAW,CAAC;AAAA,MAC9D,SAAS;AAAA,QACR,SAAS,WAAW;AAAA,QACpB,QAAQD,QAAO;AAAA,QACf,aAAaC,aAAY;AAAA,QACzB,QAAQ,OAAO;AAAA,MAChB;AAAA,IACD;AAAA,EACD,UAAE;AACD,UAAM,uBAAuB,SAAS,SAAS;AAAA,EAChD;AACD;","names":["failed","needsReview"]}
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TabRole } from "./browser-scripts";
|
|
2
|
+
import type { TabRoleFinding } from "./classify";
|
|
3
|
+
export type OrphanedTabRolesElement = {
|
|
4
|
+
/** Selector for the element (see getSelector). */
|
|
5
|
+
selector: string;
|
|
6
|
+
/** Truncated opening tag. */
|
|
7
|
+
html: string;
|
|
8
|
+
role: TabRole;
|
|
9
|
+
/** What is wrong with the element's association, or null when it has one. */
|
|
10
|
+
finding: TabRoleFinding | null;
|
|
11
|
+
};
|
|
12
|
+
export type OrphanedTabRolesResult = {
|
|
13
|
+
/** Tabs and tab panels that provably have no counterpart. */
|
|
14
|
+
failed: OrphanedTabRolesElement[];
|
|
15
|
+
/** Tabs and tab panels with no declared counterpart, for a human to check. */
|
|
16
|
+
needsReview: OrphanedTabRolesElement[];
|
|
17
|
+
passed: OrphanedTabRolesElement[];
|
|
18
|
+
/** Full counts. Each element list stops at `reportLimit`. */
|
|
19
|
+
summary: {
|
|
20
|
+
/** Elements with role `tab` or `tabpanel`. */
|
|
21
|
+
checked: number;
|
|
22
|
+
failed: number;
|
|
23
|
+
needsReview: number;
|
|
24
|
+
passed: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@a11y-pulse/orphaned-tab-roles-audit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WCAG 1.3.1 and 4.1.2 audit that flags ARIA tabs with no tab panel and tab panels with no tab, including navigation links dressed up as tabs.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
7
|
+
"author": "A11y Pulse",
|
|
8
|
+
"homepage": "https://github.com/A11y-Pulse/audits/tree/main/packages/orphaned-tab-roles-audit#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/A11y-Pulse/audits.git",
|
|
12
|
+
"directory": "packages/orphaned-tab-roles-audit"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/A11y-Pulse/audits/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"accessibility",
|
|
19
|
+
"a11y",
|
|
20
|
+
"wcag",
|
|
21
|
+
"aria",
|
|
22
|
+
"tabs",
|
|
23
|
+
"audit"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"source": "./src/index.ts",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE.md"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "biome check",
|
|
44
|
+
"lint:fix": "biome check --fix",
|
|
45
|
+
"test:unit": "vitest run",
|
|
46
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
47
|
+
"test": "npm run typecheck && npm run test:unit",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@a11y-pulse/browser-adaptor": "*"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"happy-dom": "^21.0.1",
|
|
58
|
+
"playwright-core": "^1.64.1",
|
|
59
|
+
"puppeteer": "^25.14.0"
|
|
60
|
+
}
|
|
61
|
+
}
|