@a11y-pulse/skip-link-audit 0.2.0 → 0.4.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/README.md +58 -10
- package/dist/adaptor.d.ts +2 -2
- package/dist/audit.d.ts +34 -6
- package/dist/browser-scripts.d.ts +94 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.js +489 -109
- package/dist/index.js.map +1 -1
- package/dist/result.d.ts +51 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
|
|
5
5
|
[](./LICENSE.md)
|
|
6
6
|
|
|
7
|
-
An accessibility audit that aims to verify the skip-link technique for [**WCAG 2.4.1 Bypass Blocks**](https://www.w3.org/WAI/WCAG22/Understanding/bypass-blocks.html). When a skip
|
|
7
|
+
An accessibility audit that aims to verify the skip-link technique for [**WCAG 2.4.1 Bypass Blocks**](https://www.w3.org/WAI/WCAG22/Understanding/bypass-blocks.html). When a skip link appears in the first few tab stops, it activates the link with Enter and checks that keyboard focus moves to the target or past it. It also reports skip links that are in the document but can never receive focus. It is built to be framework-agnostic and can be used in any environment that allows you to programmatically tab, press Enter, and read the focused element, such as Puppeteer, Playwright, or Selenium.
|
|
8
8
|
|
|
9
9
|
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).
|
|
10
10
|
|
|
@@ -32,7 +32,7 @@ await page.goto("https://who.likesdogs.nz/");
|
|
|
32
32
|
const result = await runSkipLinkAudit(new PuppeteerAdaptor(page));
|
|
33
33
|
|
|
34
34
|
console.log(result.summary);
|
|
35
|
-
// { found: 1, passed: 1, failed: 0 }
|
|
35
|
+
// { found: 1, passed: 1, failed: 0, unreachable: 0 }
|
|
36
36
|
|
|
37
37
|
console.log(result.skipLinks);
|
|
38
38
|
// [
|
|
@@ -42,7 +42,11 @@ console.log(result.skipLinks);
|
|
|
42
42
|
// fragment: "#main",
|
|
43
43
|
// tabIndex: 1,
|
|
44
44
|
// passed: true,
|
|
45
|
-
// failureReason: null
|
|
45
|
+
// failureReason: null,
|
|
46
|
+
// linkText: "Skip to content",
|
|
47
|
+
// target: { selector: "#main", html: '<main id="main" tabindex="-1">', rendered: true },
|
|
48
|
+
// focusAfterEnter: { position: "inside-target", selector: "#main", html: '<main id="main" tabindex="-1">' },
|
|
49
|
+
// focusAfterTab: null
|
|
46
50
|
// }
|
|
47
51
|
// ]
|
|
48
52
|
|
|
@@ -76,33 +80,73 @@ The following options can be passed to `runSkipLinkAudit` as `SkipLinkOptions`:
|
|
|
76
80
|
|
|
77
81
|
```ts
|
|
78
82
|
type SkipLinkResult = {
|
|
79
|
-
/** Skip
|
|
83
|
+
/** Skip links found in the first tab stops. Empty when none were found. */
|
|
80
84
|
skipLinks: Array<{
|
|
81
85
|
selector: string;
|
|
82
86
|
html: string;
|
|
83
87
|
fragment: string;
|
|
84
88
|
tabIndex: number;
|
|
85
89
|
passed: boolean;
|
|
86
|
-
failureReason: "target-missing" | "activation-no-effect" | null;
|
|
90
|
+
failureReason: "target-missing" | "target-hidden" | "activation-no-effect" | null;
|
|
91
|
+
/** Text of the link, falling back to its aria-label. */
|
|
92
|
+
linkText?: string;
|
|
93
|
+
/** The element the fragment resolves to, or null when nothing matches it. */
|
|
94
|
+
target?: { selector: string; html: string; rendered: boolean } | null;
|
|
95
|
+
/** Where focus was once Enter had been pressed on the link. */
|
|
96
|
+
focusAfterEnter?: SkipLinkFocusLanding;
|
|
97
|
+
/** Where focus was after the follow-up Tab, or null when it was not pressed. */
|
|
98
|
+
focusAfterTab?: SkipLinkFocusLanding | null;
|
|
87
99
|
/** PNG bytes of the focused skip link, clipped and padded. Only captured when it failed. */
|
|
88
100
|
screenshot?: Uint8Array;
|
|
89
101
|
}>;
|
|
102
|
+
/** Skip links that can never be focused. Only looked for when tabbing reached no skip link. */
|
|
103
|
+
unreachable: Array<{
|
|
104
|
+
selector: string;
|
|
105
|
+
html: string;
|
|
106
|
+
fragment: string;
|
|
107
|
+
linkText: string;
|
|
108
|
+
reason: "not-rendered" | "visibility-hidden" | "inert" | "negative-tabindex";
|
|
109
|
+
}>;
|
|
90
110
|
summary: {
|
|
91
111
|
found: number;
|
|
92
112
|
passed: number;
|
|
93
113
|
failed: number;
|
|
114
|
+
unreachable: number;
|
|
94
115
|
};
|
|
95
116
|
};
|
|
117
|
+
|
|
118
|
+
type SkipLinkFocusLanding = {
|
|
119
|
+
position: "inside-target" | "after-target" | "after-link" | "skip-link" | "body" | "elsewhere";
|
|
120
|
+
/** Selector and opening tag of the focused element, or null when nothing was focused. */
|
|
121
|
+
selector: string | null;
|
|
122
|
+
html: string | null;
|
|
123
|
+
};
|
|
96
124
|
```
|
|
97
125
|
|
|
98
|
-
When no
|
|
126
|
+
When no skip link is found, `skipLinks` and `unreachable` are empty and the summary is zeros. Landmark-only pages are not flagged.
|
|
127
|
+
|
|
128
|
+
| `failureReason` | Meaning |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `target-missing` | Nothing in the page matches the fragment (an `id`, or an `<a name>`), and activating the link did not move focus to later content. |
|
|
131
|
+
| `target-hidden` | The target exists but is not rendered, for example inside a `display: none` container, and activating the link did not focus it. |
|
|
132
|
+
| `activation-no-effect` | The target exists, but neither Enter nor the Tab after it put focus in or after the target. `focusAfterEnter` and `focusAfterTab` say where focus went instead. |
|
|
99
133
|
|
|
100
134
|
## How it works
|
|
101
135
|
|
|
102
136
|
1. Enable focus reporting so Tab, Enter, and `:focus` behave as they would in a foreground tab.
|
|
103
|
-
2. Press Tab up to `candidateLimit` times. After each press, inspect the focused element (descending open shadow roots).
|
|
104
|
-
3.
|
|
105
|
-
|
|
137
|
+
2. Press Tab up to `candidateLimit` times. After each press, inspect the focused element (descending open shadow roots). The scan stops early on `<body>` or if focus cycles.
|
|
138
|
+
3. A focused `<a>` is a skip link when its resolved `href` is a fragment of the current document (`#main`, `/this-page#main` or the absolute URL, but not a bare `#`, `#top` or a hash-router path such as `#/home`) and at least one of these holds:
|
|
139
|
+
- its text or `aria-label` uses skip wording: "skip", or a "go to" verb followed by a content or navigation noun ("Jump to content", "Aller au contenu", "Ga naar inhoud", and equivalents in a handful of other languages). Matching is on whole words, so "Popular posts" and "Aller au panier" are not skip wording;
|
|
140
|
+
- its `class` or `id` is a skip token such as `skip`, `skip-link` or `skip-to-content`;
|
|
141
|
+
- its target comes after the link, is rendered, is not a navigation block, and is the page's main content: a heading, the `main` landmark, a wrapper around it or something inside it, or, on a page with no `main` landmark, an element with a conventional id such as `content` or `main-content`.
|
|
142
|
+
|
|
143
|
+
Skipping past other tab stops is not enough on its own: a "Menu" link to a navigation block further down the page does that too, and following it would open the menu.
|
|
144
|
+
|
|
145
|
+
Links with `aria-expanded`, `role="tab"` or `role="button"` are never skip links: they are disclosure triggers, tabs and buttons, and the audit must not activate them.
|
|
146
|
+
4. For each skip link: record the URL and scroll position, re-focus the link, press Enter, and poll for up to 250ms. It passes if focus is now in the target or after it. A link whose fragment matches nothing is activated too, and passes if a script moved focus to content after the link.
|
|
147
|
+
5. If focus did not visibly move and the target is rendered, press Tab once. Browsers move the sequential focus navigation starting point on fragment navigation even when the target is not focusable, so the link passes if the newly focused element is inside the target, or follows it in document order and the fragment was actually followed. That covers targets with nothing focusable inside, such as `<h1 id="title">` or an empty `<a id="content"></a>`. Otherwise record `activation-no-effect`.
|
|
148
|
+
6. Undo each activation: go back in history when following the link added an entry, which restores the URL and clears `:target`, or rewrite the URL in place when it did not, then put the scroll position back. When the audit finishes, including when it throws, drop focus and move the point Tab starts from back to the top of the document, so whatever runs next sees the page as it was loaded and tabs from its first stop.
|
|
149
|
+
7. If tabbing reached no skip link, look through the first links in the document for one whose text or `aria-label` has skip wording and that can never be focused (`display: none`, `visibility: hidden`, inert, or a negative `tabindex`) and report it under `unreachable`.
|
|
106
150
|
|
|
107
151
|
Activation uses a real Enter keypress rather than a synthetic click, so the keyboard path is the one being checked.
|
|
108
152
|
|
|
@@ -146,7 +190,10 @@ Use [`@a11y-pulse/browser-adaptor`'s `src/adaptors/puppeteer.ts`](../browser-ada
|
|
|
146
190
|
|
|
147
191
|
- **Chromium focus emulation.** Accurate `:focus` / `document.hasFocus()` reporting for a backgrounded page relies on Chromium's CDP focus emulation (used by `PuppeteerAdaptor.ensureFocusReporting`). Other browser engines may not offer an equivalent, and results may be less reliable if the page genuinely loses focus during the audit.
|
|
148
192
|
- **First tab stops only.** Skip links beyond `candidateLimit` (default 3) are not detected. The audit stays silent, which never flags a conformant page.
|
|
149
|
-
- **
|
|
193
|
+
- **Links only.** Button-based skip controls are out of scope. A script-driven skip link is checked as long as it is an `<a>` with a fragment `href`.
|
|
194
|
+
- **Skip wording is a short multilingual list.** A skip link whose target is missing, is a navigation block, or is not the page's main content is only recognised by its wording or a skip class or id. One in a language the list does not cover, pointing at a `<div>` with an unconventional id on a page with no `main` landmark, is not evaluated, which never flags a conformant page.
|
|
195
|
+
- **Changes made by activation are not all undone.** The URL, `:target`, scroll position, focus and tab starting point are restored, but anything else a page does when its skip link is activated stays done. The history entry that following a fragment link adds cannot be removed: the page is returned to the entry it was on, and the added one remains as a forward entry, so `history.length` stays one higher. A page whose URL changed without a new history entry has its URL rewritten in place, and `:target` then keeps pointing at the skip target.
|
|
196
|
+
- **A leftover node on positive-tabindex pages.** Where a page uses a positive `tabindex`, resetting the tab starting point leaves an empty, `aria-hidden` `<span data-a11y-pulse-skip-link-focus-start>` in front of the first element in the tab order. It removes itself the next time anything is focused.
|
|
150
197
|
- **Closed shadow roots** are opaque; a skip link inside one is invisible to the scan.
|
|
151
198
|
- **Landmarks and headings** that satisfy 2.4.1 without a skip link are out of scope by design.
|
|
152
199
|
|
|
@@ -154,6 +201,7 @@ Use [`@a11y-pulse/browser-adaptor`'s `src/adaptors/puppeteer.ts`](../browser-ada
|
|
|
154
201
|
|
|
155
202
|
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.
|
|
156
203
|
|
|
204
|
+
- **Skip links hidden at this viewport** (`violations`). A skip link that is `display: none` at the audited viewport size and shown at another is reported as unreachable.
|
|
157
205
|
- **Skip links that move focus slowly** (`violations`). The audit waits 250ms (`activationPollMs`) for focus to arrive. A skip link that only moves focus after a longer smooth-scroll animation is reported as having no effect.
|
|
158
206
|
|
|
159
207
|
## Releasing
|
package/dist/adaptor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Rect } from "@a11y-pulse/browser-adaptor";
|
|
1
|
+
import type { EvaluateArgs, PageFunction, Rect } from "@a11y-pulse/browser-adaptor";
|
|
2
2
|
/**
|
|
3
3
|
* An element handle in the page. This type is adaptor-specific and is opaque to the audit.
|
|
4
4
|
*/
|
|
@@ -11,7 +11,7 @@ export interface SkipLinkAuditAdaptor {
|
|
|
11
11
|
/**
|
|
12
12
|
* Run `fn` in the page context, passing in any serialisable `args`
|
|
13
13
|
*/
|
|
14
|
-
evaluate<
|
|
14
|
+
evaluate<F extends PageFunction>(fn: F, ...args: EvaluateArgs<Parameters<F>>): Promise<Awaited<ReturnType<F>>>;
|
|
15
15
|
/**
|
|
16
16
|
* Return an opaque handle to an element in the page
|
|
17
17
|
*/
|
package/dist/audit.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ElementRef, SkipLinkAuditAdaptor } from "./adaptor";
|
|
2
|
-
import type
|
|
2
|
+
import { type SkipLinkFocusPosition, type SkipLinkPageState } from "./browser-scripts";
|
|
3
|
+
import type { SkipLinkResult, SkipLinkTarget, SkipLinkUnreachableResult } from "./result";
|
|
3
4
|
export declare const DEFAULT_CANDIDATE_LIMIT = 3;
|
|
4
5
|
export declare const DEFAULT_ACTIVATION_POLL_MS = 250;
|
|
5
6
|
export type SkipLinkOptions = {
|
|
@@ -14,7 +15,9 @@ export type SkipLinkCandidate = {
|
|
|
14
15
|
selector: string;
|
|
15
16
|
html: string;
|
|
16
17
|
fragment: string;
|
|
17
|
-
|
|
18
|
+
linkText: string;
|
|
19
|
+
/** The element the fragment resolves to, or null when nothing matches it. */
|
|
20
|
+
target: SkipLinkTarget | null;
|
|
18
21
|
handle: ElementRef;
|
|
19
22
|
};
|
|
20
23
|
export type TabStopProbe = {
|
|
@@ -23,21 +26,46 @@ export type TabStopProbe = {
|
|
|
23
26
|
identity: string;
|
|
24
27
|
candidate: SkipLinkCandidate | null;
|
|
25
28
|
};
|
|
29
|
+
/** Where focus is relative to a skip link, read after a key press. */
|
|
30
|
+
export type FocusReading = {
|
|
31
|
+
position: SkipLinkFocusPosition;
|
|
32
|
+
/** Whether the document's URL fragment is the one the link points at. */
|
|
33
|
+
navigated: boolean;
|
|
34
|
+
/** Whether the link's target exists. */
|
|
35
|
+
targetExists: boolean;
|
|
36
|
+
/** Whether the link's target exists and is rendered. */
|
|
37
|
+
targetRendered: boolean;
|
|
38
|
+
};
|
|
26
39
|
/** The browser-coupled seams the loop drives. Mocked in unit tests. */
|
|
27
40
|
export type SkipLinkProbe = {
|
|
28
41
|
pressTab(): Promise<void>;
|
|
29
42
|
pressEnter(): Promise<void>;
|
|
30
43
|
probeTabStop(): Promise<TabStopProbe>;
|
|
31
44
|
focusHandle(ref: ElementRef): Promise<void>;
|
|
32
|
-
|
|
45
|
+
/** Where focus is now, relative to the skip link behind `ref` and its target. */
|
|
46
|
+
readFocus(ref: ElementRef): Promise<FocusReading>;
|
|
47
|
+
/** Selector and opening tag of the focused element, or null when nothing is focused. */
|
|
48
|
+
describeFocused(): Promise<{
|
|
49
|
+
selector: string;
|
|
50
|
+
html: string;
|
|
51
|
+
} | null>;
|
|
52
|
+
/** Skip links in the document that can never receive keyboard focus. */
|
|
53
|
+
findUnreachable(): Promise<SkipLinkUnreachableResult[]>;
|
|
54
|
+
/** Record the URL, history length and scroll position so activating a link can be undone. */
|
|
55
|
+
saveState(): Promise<SkipLinkPageState>;
|
|
56
|
+
restoreState(state: SkipLinkPageState): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Drop focus and start the tab order from the top again, so the next Tab press does not carry on
|
|
59
|
+
* from a skip target or from the last stop the audit looked at.
|
|
60
|
+
*/
|
|
61
|
+
clearFocus(): Promise<void>;
|
|
33
62
|
/** Focus the element and screenshot it, so a link that only appears on focus is visible. */
|
|
34
63
|
screenshotFocused(ref: ElementRef): Promise<Uint8Array>;
|
|
35
64
|
disposeRef(ref: ElementRef): Promise<void>;
|
|
36
65
|
};
|
|
37
66
|
/**
|
|
38
|
-
* Tab through the first few stops looking for skip
|
|
39
|
-
*
|
|
40
|
-
* loop.
|
|
67
|
+
* Tab through the first few stops looking for skip links, then activate each one and check that
|
|
68
|
+
* keyboard focus moves. Enables focus reporting up front, then drives the loop.
|
|
41
69
|
*/
|
|
42
70
|
export declare function runSkipLinkAudit(adaptor: SkipLinkAuditAdaptor, options?: SkipLinkOptions): Promise<SkipLinkResult>;
|
|
43
71
|
/** The engine-neutral two-phase loop. Exported for unit testing with a fake probe. */
|
|
@@ -1,38 +1,111 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* IMPORTANT: Functions in this file
|
|
3
|
-
* reference any symbols outside their own scope.
|
|
4
|
-
*
|
|
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. Everything that needs the fragment parsing,
|
|
4
|
+
* target resolution or skip-link heuristics goes through `inspectSkipLinkScript`, so there is one
|
|
5
|
+
* copy of that logic and the tests exercise the code that ships.
|
|
5
6
|
*/
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
/** Where the focused element sits relative to a skip link and its target. */
|
|
8
|
+
export type SkipLinkFocusPosition =
|
|
9
|
+
/** Focus is on the target or inside it. */
|
|
10
|
+
"inside-target"
|
|
11
|
+
/** Focus is on content that follows the target in document order. */
|
|
12
|
+
| "after-target"
|
|
13
|
+
/** Focus is on content after the link, and the link has no target to compare against. */
|
|
14
|
+
| "after-link"
|
|
15
|
+
/** Focus is still on the skip link. */
|
|
16
|
+
| "skip-link"
|
|
17
|
+
/** Nothing is focused. */
|
|
18
|
+
| "body"
|
|
19
|
+
/** Focus is somewhere else, such as before the link or between the link and its target. */
|
|
20
|
+
| "elsewhere";
|
|
21
|
+
export type SkipLinkUnreachableReason = "not-rendered" | "visibility-hidden" | "inert" | "negative-tabindex";
|
|
22
|
+
export type SkipLinkTargetInspection = {
|
|
23
|
+
selector: string;
|
|
24
|
+
/** Opening tag of the target. */
|
|
25
|
+
html: string;
|
|
26
|
+
/** False when the target or an ancestor is `display: none` (or otherwise not rendered). */
|
|
27
|
+
rendered: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type SkipLinkInspection = {
|
|
30
|
+
/** True when the inspected element is missing or is `<body>`. */
|
|
17
31
|
isBody: boolean;
|
|
32
|
+
/** Opening tag of the inspected element. */
|
|
18
33
|
html: string;
|
|
34
|
+
/** Visible text of the link, falling back to its `aria-label`. */
|
|
35
|
+
linkText: string;
|
|
19
36
|
/**
|
|
20
|
-
*
|
|
37
|
+
* The same-document fragment the link points at, such as "#main". Null when the element is not a
|
|
38
|
+
* link to a fragment of this document.
|
|
21
39
|
*/
|
|
22
40
|
fragment: string | null;
|
|
23
|
-
|
|
41
|
+
/** Whether the link looks like a skip link rather than a menu toggle or other in-page link. */
|
|
42
|
+
skipLike: boolean;
|
|
43
|
+
target: SkipLinkTargetInspection | null;
|
|
44
|
+
focus: {
|
|
45
|
+
position: SkipLinkFocusPosition;
|
|
46
|
+
/** Whether the document's URL fragment is the one the link points at. */
|
|
47
|
+
navigated: boolean;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type SkipLinkUnreachableInspection = {
|
|
51
|
+
html: string;
|
|
52
|
+
linkText: string;
|
|
53
|
+
fragment: string;
|
|
54
|
+
reason: SkipLinkUnreachableReason;
|
|
55
|
+
};
|
|
56
|
+
export type SkipLinkInspectionResult = {
|
|
57
|
+
/** The inspected element. Null in "unreachable" mode. */
|
|
58
|
+
link: SkipLinkInspection | null;
|
|
59
|
+
/** Skip links that can never receive focus. Only filled in "unreachable" mode. */
|
|
60
|
+
unreachable: SkipLinkUnreachableInspection[];
|
|
24
61
|
};
|
|
62
|
+
/** Attribute that marks unreachable skip links so a handle can be taken to each one in turn. */
|
|
63
|
+
export declare const UNREACHABLE_MARKER = "data-a11y-pulse-unreachable-skip-link";
|
|
25
64
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
65
|
+
* Inspect skip links in the page.
|
|
66
|
+
*
|
|
67
|
+
* - "classify": describe `el` and decide whether it is a skip link.
|
|
68
|
+
* - "focus": describe `el` and where keyboard focus is relative to it and its target.
|
|
69
|
+
* - "unreachable": ignore `el` and find skip links that can never receive keyboard focus, marking
|
|
70
|
+
* each with `data-a11y-pulse-unreachable-skip-link`.
|
|
28
71
|
*/
|
|
29
|
-
export declare function
|
|
72
|
+
export declare function inspectSkipLinkScript(el: Element | null, mode: "classify" | "focus" | "unreachable", limit?: number): SkipLinkInspectionResult;
|
|
30
73
|
/**
|
|
31
74
|
* Return the focused element, descending open shadow roots.
|
|
32
75
|
*/
|
|
33
76
|
export declare function activeElementHandleScript(): Element | null;
|
|
34
77
|
/**
|
|
35
|
-
*
|
|
78
|
+
* Return the next skip link marked by `inspectSkipLinkScript` in "unreachable" mode, removing its
|
|
79
|
+
* marker so the following call returns the one after it.
|
|
36
80
|
*/
|
|
37
|
-
export declare function
|
|
81
|
+
export declare function takeUnreachableSkipLinkScript(): Element | null;
|
|
82
|
+
export type SkipLinkPageState = {
|
|
83
|
+
href: string;
|
|
84
|
+
scrollX: number;
|
|
85
|
+
scrollY: number;
|
|
86
|
+
/** `history.length` before the link was activated, to tell whether following it added an entry. */
|
|
87
|
+
historyLength: number;
|
|
88
|
+
};
|
|
89
|
+
export declare function readPageStateScript(): SkipLinkPageState;
|
|
90
|
+
/**
|
|
91
|
+
* Put the URL, the `:target` element and the scroll position back the way they were before a skip
|
|
92
|
+
* link was activated, so whatever runs next sees the page as it was loaded.
|
|
93
|
+
*
|
|
94
|
+
* Following a fragment link adds a history entry, so the way back is to go back: that returns the
|
|
95
|
+
* document to the entry it was on, which also resets `:target` (rewriting the URL with
|
|
96
|
+
* `replaceState` does not). The entry that was added stays ahead in the history as a forward entry,
|
|
97
|
+
* because nothing can remove one. When the URL changed without a new entry, or by more than its
|
|
98
|
+
* fragment, the URL is rewritten in place instead and `:target` is left as it is.
|
|
99
|
+
*/
|
|
100
|
+
export declare function restorePageStateScript(state: SkipLinkPageState): Promise<void>;
|
|
38
101
|
export declare function focusScript(el: Element | null): void;
|
|
102
|
+
/**
|
|
103
|
+
* Drop focus and put the point sequential focus navigation starts from back at the top of the
|
|
104
|
+
* document, so the next Tab press reaches the first tab stop as it would on a freshly loaded page.
|
|
105
|
+
* Blurring alone leaves that point where focus last was: on a skip link's target, mid-page.
|
|
106
|
+
*
|
|
107
|
+
* The point is moved by focusing a throwaway node. On a page with a positive `tabindex` the node
|
|
108
|
+
* has to stay in front of the first element in the tab order until focus next moves, and removes
|
|
109
|
+
* itself then; otherwise it is taken straight out again and nothing is left behind.
|
|
110
|
+
*/
|
|
111
|
+
export declare function resetFocusScript(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { SkipLinkAuditAdaptor } from "./adaptor";
|
|
2
2
|
export type { SkipLinkOptions } from "./audit";
|
|
3
3
|
export { runSkipLinkAudit } from "./audit";
|
|
4
|
-
export type { SkipLinkElementResult, SkipLinkFailureReason, SkipLinkResult, } from "./result";
|
|
4
|
+
export type { SkipLinkElementResult, SkipLinkFailureReason, SkipLinkFocusLanding, SkipLinkFocusPosition, SkipLinkResult, SkipLinkTarget, SkipLinkUnreachableReason, SkipLinkUnreachableResult, } from "./result";
|
package/dist/index.js
CHANGED
|
@@ -3,42 +3,221 @@ import { captureElementScreenshot } from "@a11y-pulse/browser-adaptor";
|
|
|
3
3
|
import { getSelector, truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
|
|
4
4
|
|
|
5
5
|
// src/browser-scripts.ts
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function inspectSkipLinkScript(el, mode, limit = 3) {
|
|
7
|
+
const WORD = "\\p{L}\\p{N}_";
|
|
8
|
+
const START = `(?:^|[^${WORD}])`;
|
|
9
|
+
const END = `(?![${WORD}])`;
|
|
10
|
+
const GO = "skip|jump|go|zum|zur|springe|aller|passer|acc\xE9der|ir|saltar|salta|vai|passa|pular|avan\xE7ar|ga|naar|spring|hoppa|hopp|g\xE5|till|siirry|hypp\xE4\xE4|przejd\u017A|przeskocz|pomi\u0144|p\u0159esko\u010Dit|p\u0159ej\xEDt|\u043F\u0435\u0440\u0435\u0439\u0442\u0438|\u043F\u0440\u043E\u043F\u0443\u0441\u0442\u0438\u0442\u044C";
|
|
11
|
+
const FILLER = "to|the|main|primary|zu|zum|zur|dem|der|direkt|au|aux|\xE0|la|le|du|directement|al|a|el|alla|allo|ai|il|para|o|ao|naar|de|het|direct|till|til|det|do|na|k|ke|g\u0142\xF3wnej|hlavn\xED|hlavn\xEDmu|\u043A|\u043E\u0441\u043D\u043E\u0432\u043D\u043E\u043C\u0443";
|
|
12
|
+
const NOUN = "content|main|navigation|nav|menu|search|footer|\\p{L}*inhalt|\\p{L}*navigation|men\xFC|suche|contenu|recherche|contenido|navegaci\xF3n|men\xFA|b\xFAsqueda|contenuto|navigazione|ricerca|conte\xFAdo|navega\xE7\xE3o|pesquisa|\\p{L}*inhoud|navigatie|zoeken|\\p{L}*inneh\xE5ll\\p{L}*|navigering\\p{L}*|meny\\p{L}*|\\p{L}*innhold\\p{L}*|\\p{L}*indhold\\p{L}*|navigasjon\\p{L}*|\\p{L}*sis\xE4lt\\p{L}*|navigaatio\\p{L}*|valikko\\p{L}*|tre\u015Bci|zawarto\u015Bci|nawigacj\\p{L}*|obsah\\p{L}*|navigac\\p{L}*|\u0441\u043E\u0434\u0435\u0440\u0436\u0430\u043D\u0438\\p{L}*|\u043A\u043E\u043D\u0442\u0435\u043D\u0442\\p{L}*|\u043D\u0430\u0432\u0438\u0433\u0430\u0446\u0438\\p{L}*|\u043C\u0435\u043D\u044E";
|
|
13
|
+
const SKIP_WORDS = new RegExp(
|
|
14
|
+
[
|
|
15
|
+
// "Skip to content", "Aller au contenu", "Ga direct naar de inhoud", "Перейти к содержанию".
|
|
16
|
+
`${START}(?:${GO})(?:\\s+(?:${FILLER})){0,3}\\s+(?:${NOUN})${END}`,
|
|
17
|
+
// Verbs that only ever mean "skip".
|
|
18
|
+
`${START}(?:skip|\xFCberspringen)${END}`,
|
|
19
|
+
// Scripts written without spaces between words.
|
|
20
|
+
"\u30B9\u30AD\u30C3\u30D7|\u672C\u6587\u3078|\u30E1\u30A4\u30F3\u30B3\u30F3\u30C6\u30F3\u30C4\u3078|\u8DF3[\u8FC7\u904E]|\u8DF3(?:\u5230|\u81F3|\u8F6C\u5230|\u8F49\u5230)\\s*(?:\u4E3B\u8981|\u4E3B|\u6B63\u6587|\u5185\u5BB9|\u5167\u5BB9|\u5BFC\u822A|\u5C0E\u822A)|\uAC74\uB108\uB6F0\uAE30|\uBCF8\uBB38\\s*(?:\uC73C\uB85C|\uBC14\uB85C\\s*\uAC00\uAE30)"
|
|
21
|
+
].join("|"),
|
|
22
|
+
"iu"
|
|
23
|
+
);
|
|
24
|
+
const SKIP_TOKEN = /^skip(?:[-_]?(?:link|nav|navigation|main|content|to[-_]?[a-z]+))?$/i;
|
|
25
|
+
const CONTENT_ID = /^(?:(?:main|page|site|primary|skip)[-_]?)?(?:content|main)(?:[-_]?(?:area|wrapper|container|start))?$|^primary$/i;
|
|
26
|
+
const UNREACHABLE_ATTR = "data-a11y-pulse-unreachable-skip-link";
|
|
27
|
+
function openingTag(node) {
|
|
28
|
+
return node.cloneNode(false).outerHTML;
|
|
10
29
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
function isRendered(node) {
|
|
31
|
+
if (typeof node.checkVisibility === "function") {
|
|
32
|
+
return node.checkVisibility();
|
|
33
|
+
}
|
|
34
|
+
for (let current = node; current; current = current.parentElement) {
|
|
35
|
+
if (getComputedStyle(current).display === "none") {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
18
40
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
function textOf(node) {
|
|
42
|
+
const text = (node.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
43
|
+
return (text || (node.getAttribute("aria-label") ?? "").trim()).slice(0, 200);
|
|
44
|
+
}
|
|
45
|
+
function fragmentOf(node) {
|
|
46
|
+
if (node.tagName !== "A" || !node.hasAttribute("href")) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let url;
|
|
50
|
+
let here;
|
|
51
|
+
try {
|
|
52
|
+
url = new URL(node.href);
|
|
53
|
+
here = new URL(location.href);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (url.origin !== here.origin || url.pathname !== here.pathname || url.search !== here.search) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const hash = url.hash;
|
|
61
|
+
if (hash === "" || hash === "#" || hash.toLowerCase() === "#top") {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (hash.startsWith("#/") || hash.startsWith("#!/")) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return hash;
|
|
24
68
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const raw = fragment.slice(1);
|
|
69
|
+
function targetOf(fragment2) {
|
|
70
|
+
const raw = fragment2.slice(1);
|
|
28
71
|
let decoded = raw;
|
|
29
72
|
try {
|
|
30
73
|
decoded = decodeURIComponent(raw);
|
|
31
74
|
} catch {
|
|
32
75
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
76
|
+
for (const id of raw === decoded ? [raw] : [raw, decoded]) {
|
|
77
|
+
const byId = document.getElementById(id);
|
|
78
|
+
if (byId) {
|
|
79
|
+
return byId;
|
|
80
|
+
}
|
|
81
|
+
for (const named of Array.from(document.getElementsByName(id))) {
|
|
82
|
+
if (named.tagName === "A") {
|
|
83
|
+
return named;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function follows(node, reference) {
|
|
90
|
+
return Boolean(reference.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
91
|
+
}
|
|
92
|
+
function hasSkipWords(node) {
|
|
93
|
+
return SKIP_WORDS.test(`${textOf(node)} ${node.getAttribute("aria-label") ?? ""}`);
|
|
94
|
+
}
|
|
95
|
+
function hasSkipToken(node) {
|
|
96
|
+
if (SKIP_TOKEN.test(node.id)) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return (node.getAttribute("class") ?? "").split(/\s+/).some((token) => SKIP_TOKEN.test(token));
|
|
100
|
+
}
|
|
101
|
+
function isContentTarget(target2) {
|
|
102
|
+
if (target2.matches('h1, h2, h3, h4, h5, h6, [role="heading"]')) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
const main = document.querySelector('main, [role="main"]');
|
|
106
|
+
if (main) {
|
|
107
|
+
return target2 === main || target2.contains(main) || main.contains(target2);
|
|
108
|
+
}
|
|
109
|
+
return CONTENT_ID.test(target2.id || (target2.getAttribute("name") ?? ""));
|
|
110
|
+
}
|
|
111
|
+
function isSkipLike(link, target2) {
|
|
112
|
+
const role = link.getAttribute("role");
|
|
113
|
+
if (link.hasAttribute("aria-expanded") || role === "tab" || role === "button") {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (hasSkipWords(link) || hasSkipToken(link)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (!target2 || !follows(target2, link)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (!isRendered(target2) || target2.closest('nav, [role="navigation"]')) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return isContentTarget(target2);
|
|
126
|
+
}
|
|
127
|
+
function targetSelector(target2) {
|
|
128
|
+
if (target2.id) {
|
|
129
|
+
return `#${CSS.escape(target2.id)}`;
|
|
130
|
+
}
|
|
131
|
+
return `a[name="${CSS.escape(target2.getAttribute("name") ?? "")}"]`;
|
|
132
|
+
}
|
|
133
|
+
function unreachableReason(link) {
|
|
134
|
+
if (!isRendered(link)) {
|
|
135
|
+
return "not-rendered";
|
|
136
|
+
}
|
|
137
|
+
const visibility = getComputedStyle(link).visibility;
|
|
138
|
+
if (visibility === "hidden" || visibility === "collapse") {
|
|
139
|
+
return "visibility-hidden";
|
|
140
|
+
}
|
|
141
|
+
if (link.closest("[inert]")) {
|
|
142
|
+
return "inert";
|
|
143
|
+
}
|
|
144
|
+
const tabindex = link.getAttribute("tabindex");
|
|
145
|
+
if (tabindex !== null && Number.parseInt(tabindex, 10) < 0) {
|
|
146
|
+
return "negative-tabindex";
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (mode === "unreachable") {
|
|
151
|
+
const unreachable = [];
|
|
152
|
+
for (const marked of Array.from(document.querySelectorAll(`[${UNREACHABLE_ATTR}]`))) {
|
|
153
|
+
marked.removeAttribute(UNREACHABLE_ATTR);
|
|
154
|
+
}
|
|
155
|
+
for (const link of Array.from(document.querySelectorAll("a[href]")).slice(0, 50)) {
|
|
156
|
+
if (unreachable.length >= limit) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
const fragment2 = fragmentOf(link);
|
|
160
|
+
if (!fragment2 || !hasSkipWords(link) || !isSkipLike(link, targetOf(fragment2))) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const reason = unreachableReason(link);
|
|
164
|
+
if (!reason) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const html = openingTag(link);
|
|
168
|
+
link.setAttribute(UNREACHABLE_ATTR, String(unreachable.length));
|
|
169
|
+
unreachable.push({ html, linkText: textOf(link), fragment: fragment2, reason });
|
|
170
|
+
}
|
|
171
|
+
return { link: null, unreachable };
|
|
172
|
+
}
|
|
173
|
+
if (!el || el === document.body || el === document.documentElement) {
|
|
174
|
+
return {
|
|
175
|
+
link: {
|
|
176
|
+
isBody: true,
|
|
177
|
+
html: "",
|
|
178
|
+
linkText: "",
|
|
179
|
+
fragment: null,
|
|
180
|
+
skipLike: false,
|
|
181
|
+
target: null,
|
|
182
|
+
focus: { position: "body", navigated: false }
|
|
183
|
+
},
|
|
184
|
+
unreachable: []
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const fragment = fragmentOf(el);
|
|
188
|
+
const target = fragment ? targetOf(fragment) : null;
|
|
189
|
+
const host = document.activeElement;
|
|
190
|
+
let active = host;
|
|
191
|
+
while (active?.shadowRoot?.activeElement) {
|
|
192
|
+
active = active.shadowRoot.activeElement;
|
|
193
|
+
}
|
|
194
|
+
let position = "elsewhere";
|
|
195
|
+
if (!host || !active || host === document.body || host === document.documentElement) {
|
|
196
|
+
position = "body";
|
|
197
|
+
} else if (active === el) {
|
|
198
|
+
position = "skip-link";
|
|
199
|
+
} else if (target && (active === target || target.contains(active) || target.contains(host))) {
|
|
200
|
+
position = "inside-target";
|
|
201
|
+
} else if (target && follows(host, target)) {
|
|
202
|
+
position = "after-target";
|
|
203
|
+
} else if (!target && follows(host, el)) {
|
|
204
|
+
position = "after-link";
|
|
36
205
|
}
|
|
37
206
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
207
|
+
link: {
|
|
208
|
+
isBody: false,
|
|
209
|
+
html: openingTag(el),
|
|
210
|
+
linkText: textOf(el),
|
|
211
|
+
fragment,
|
|
212
|
+
skipLike: mode === "classify" && fragment !== null ? isSkipLike(el, target) : false,
|
|
213
|
+
target: target ? {
|
|
214
|
+
selector: targetSelector(target),
|
|
215
|
+
html: openingTag(target),
|
|
216
|
+
rendered: isRendered(target)
|
|
217
|
+
} : null,
|
|
218
|
+
focus: { position, navigated: fragment !== null && location.hash === fragment }
|
|
219
|
+
},
|
|
220
|
+
unreachable: []
|
|
42
221
|
};
|
|
43
222
|
}
|
|
44
223
|
function activeElementHandleScript() {
|
|
@@ -48,33 +227,156 @@ function activeElementHandleScript() {
|
|
|
48
227
|
}
|
|
49
228
|
return el;
|
|
50
229
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
230
|
+
function takeUnreachableSkipLinkScript() {
|
|
231
|
+
const marked = document.querySelector("[data-a11y-pulse-unreachable-skip-link]");
|
|
232
|
+
marked?.removeAttribute("data-a11y-pulse-unreachable-skip-link");
|
|
233
|
+
return marked;
|
|
234
|
+
}
|
|
235
|
+
function readPageStateScript() {
|
|
236
|
+
return {
|
|
237
|
+
href: location.href,
|
|
238
|
+
scrollX: window.scrollX,
|
|
239
|
+
scrollY: window.scrollY,
|
|
240
|
+
historyLength: history.length
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function restorePageStateScript(state) {
|
|
244
|
+
const withoutFragment = (href) => href.split("#")[0] ?? href;
|
|
245
|
+
const rewrite = () => {
|
|
246
|
+
if (location.href === state.href) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
history.replaceState(history.state, "", state.href);
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const scroll = () => {
|
|
255
|
+
window.scrollTo(state.scrollX, state.scrollY);
|
|
256
|
+
};
|
|
257
|
+
if (location.href === state.href || withoutFragment(location.href) !== withoutFragment(state.href) || history.length !== state.historyLength + 1) {
|
|
258
|
+
rewrite();
|
|
259
|
+
scroll();
|
|
260
|
+
return Promise.resolve();
|
|
68
261
|
}
|
|
69
|
-
return
|
|
262
|
+
return new Promise((resolve) => {
|
|
263
|
+
let settled = false;
|
|
264
|
+
const settle = () => {
|
|
265
|
+
if (settled) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
settled = true;
|
|
269
|
+
window.removeEventListener("popstate", onPopState);
|
|
270
|
+
rewrite();
|
|
271
|
+
scroll();
|
|
272
|
+
resolve();
|
|
273
|
+
};
|
|
274
|
+
const onPopState = () => {
|
|
275
|
+
requestAnimationFrame(() => requestAnimationFrame(settle));
|
|
276
|
+
setTimeout(settle, 100);
|
|
277
|
+
};
|
|
278
|
+
window.addEventListener("popstate", onPopState);
|
|
279
|
+
setTimeout(settle, 1e3);
|
|
280
|
+
history.back();
|
|
281
|
+
});
|
|
70
282
|
}
|
|
71
283
|
function focusScript(el) {
|
|
72
284
|
el?.focus();
|
|
73
285
|
}
|
|
286
|
+
function resetFocusScript() {
|
|
287
|
+
const anchorAttr = "data-a11y-pulse-skip-link-focus-start";
|
|
288
|
+
return new Promise((resolve) => {
|
|
289
|
+
let done = false;
|
|
290
|
+
const run = () => {
|
|
291
|
+
if (done) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
done = true;
|
|
295
|
+
try {
|
|
296
|
+
reset();
|
|
297
|
+
} finally {
|
|
298
|
+
resolve();
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
requestAnimationFrame(() => requestAnimationFrame(run));
|
|
302
|
+
setTimeout(run, 100);
|
|
303
|
+
});
|
|
304
|
+
function reset() {
|
|
305
|
+
let active = document.activeElement;
|
|
306
|
+
while (active?.shadowRoot?.activeElement) {
|
|
307
|
+
active = active.shadowRoot.activeElement;
|
|
308
|
+
}
|
|
309
|
+
active?.blur?.();
|
|
310
|
+
for (const leftover of Array.from(document.querySelectorAll(`[${anchorAttr}]`))) {
|
|
311
|
+
leftover.remove();
|
|
312
|
+
}
|
|
313
|
+
const root = document.documentElement;
|
|
314
|
+
const body = document.body;
|
|
315
|
+
if (!root || !body) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const place = (parent, before) => {
|
|
319
|
+
const anchor = document.createElement("span");
|
|
320
|
+
anchor.tabIndex = -1;
|
|
321
|
+
anchor.setAttribute(anchorAttr, "");
|
|
322
|
+
anchor.setAttribute("aria-hidden", "true");
|
|
323
|
+
anchor.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;outline:none";
|
|
324
|
+
try {
|
|
325
|
+
parent.insertBefore(anchor, before);
|
|
326
|
+
anchor.focus({ preventScroll: true });
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
if (document.activeElement === anchor) {
|
|
330
|
+
return anchor;
|
|
331
|
+
}
|
|
332
|
+
anchor.remove();
|
|
333
|
+
return null;
|
|
334
|
+
};
|
|
335
|
+
let first = null;
|
|
336
|
+
let lowest = Number.POSITIVE_INFINITY;
|
|
337
|
+
for (const candidate of Array.from(document.querySelectorAll("[tabindex]"))) {
|
|
338
|
+
const tabIndex = candidate.tabIndex;
|
|
339
|
+
if (tabIndex <= 0 || tabIndex >= lowest) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (candidate.matches(":disabled") || candidate.closest("[inert]") || typeof candidate.checkVisibility === "function" && !candidate.checkVisibility({ checkVisibilityCSS: true })) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
first = candidate;
|
|
346
|
+
lowest = tabIndex;
|
|
347
|
+
}
|
|
348
|
+
if (first?.parentNode) {
|
|
349
|
+
const anchor = place(first.parentNode, first);
|
|
350
|
+
if (anchor) {
|
|
351
|
+
anchor.blur();
|
|
352
|
+
const cleanUp = (event) => {
|
|
353
|
+
if (event.target !== anchor) {
|
|
354
|
+
anchor.remove();
|
|
355
|
+
window.removeEventListener("focus", cleanUp, true);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
window.addEventListener("focus", cleanUp, true);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const places = [
|
|
363
|
+
[root, body],
|
|
364
|
+
[body, body.firstChild]
|
|
365
|
+
];
|
|
366
|
+
for (const [parent, before] of places) {
|
|
367
|
+
const anchor = place(parent, before);
|
|
368
|
+
if (anchor) {
|
|
369
|
+
anchor.remove();
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
74
375
|
|
|
75
376
|
// src/audit.ts
|
|
76
377
|
var DEFAULT_CANDIDATE_LIMIT = 3;
|
|
77
378
|
var DEFAULT_ACTIVATION_POLL_MS = 250;
|
|
379
|
+
var UNREACHABLE_LIMIT = 3;
|
|
78
380
|
var SCREENSHOT_CLIP_BUFFER = 10;
|
|
79
381
|
var SCREENSHOT_SETTLE_MS = 33;
|
|
80
382
|
function resolveOptions(options) {
|
|
@@ -87,80 +389,103 @@ async function runSkipLinkAudit(adaptor, options = {}) {
|
|
|
87
389
|
await adaptor.ensureFocusReporting();
|
|
88
390
|
return runSkipLinkLoop(createAdaptorProbe(adaptor), resolveOptions(options));
|
|
89
391
|
}
|
|
392
|
+
function movedByEnter(focus) {
|
|
393
|
+
if (focus.position === "inside-target" || focus.position === "after-target") {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
return !focus.targetExists && focus.position === "after-link";
|
|
397
|
+
}
|
|
398
|
+
async function landing(probe, focus) {
|
|
399
|
+
const focused = focus.position === "body" ? null : await probe.describeFocused();
|
|
400
|
+
return {
|
|
401
|
+
position: focus.position,
|
|
402
|
+
selector: focused?.selector ?? null,
|
|
403
|
+
html: focused?.html ?? null
|
|
404
|
+
};
|
|
405
|
+
}
|
|
90
406
|
async function runSkipLinkLoop(probe, options) {
|
|
91
407
|
const collected = [];
|
|
92
408
|
const seen = /* @__PURE__ */ new Set();
|
|
93
|
-
for (let i = 0; i < options.candidateLimit; i++) {
|
|
94
|
-
await probe.pressTab();
|
|
95
|
-
const tabStop = await probe.probeTabStop();
|
|
96
|
-
if (tabStop.isBody || seen.has(tabStop.identity)) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
seen.add(tabStop.identity);
|
|
100
|
-
if (tabStop.candidate) {
|
|
101
|
-
collected.push({ ...tabStop.candidate, tabIndex: i + 1 });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
409
|
const skipLinks = [];
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
screenshot: await probe.screenshotFocused(found.handle)
|
|
116
|
-
});
|
|
117
|
-
continue;
|
|
410
|
+
try {
|
|
411
|
+
for (let i = 0; i < options.candidateLimit; i++) {
|
|
412
|
+
await probe.pressTab();
|
|
413
|
+
const tabStop = await probe.probeTabStop();
|
|
414
|
+
if (tabStop.isBody || seen.has(tabStop.identity)) {
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
seen.add(tabStop.identity);
|
|
418
|
+
if (tabStop.candidate) {
|
|
419
|
+
collected.push({ ...tabStop.candidate, tabIndex: i + 1 });
|
|
118
420
|
}
|
|
119
|
-
await probe.focusHandle(found.handle);
|
|
120
|
-
await probe.pressEnter();
|
|
121
|
-
let passed2 = await pollFocusInsideTarget(probe, found.fragment, options.activationPollMs);
|
|
122
|
-
if (!passed2) {
|
|
123
|
-
await probe.pressTab();
|
|
124
|
-
passed2 = await probe.isFocusInsideTarget(found.fragment);
|
|
125
|
-
}
|
|
126
|
-
skipLinks.push({
|
|
127
|
-
selector: found.selector,
|
|
128
|
-
html: found.html,
|
|
129
|
-
fragment: found.fragment,
|
|
130
|
-
tabIndex: found.tabIndex,
|
|
131
|
-
passed: passed2,
|
|
132
|
-
failureReason: passed2 ? null : "activation-no-effect",
|
|
133
|
-
screenshot: passed2 ? void 0 : await probe.screenshotFocused(found.handle)
|
|
134
|
-
});
|
|
135
|
-
} finally {
|
|
136
|
-
await probe.disposeRef(found.handle);
|
|
137
421
|
}
|
|
422
|
+
for (const found of collected) {
|
|
423
|
+
try {
|
|
424
|
+
const state = await probe.saveState();
|
|
425
|
+
try {
|
|
426
|
+
await probe.focusHandle(found.handle);
|
|
427
|
+
await probe.pressEnter();
|
|
428
|
+
const afterEnter = await pollFocus(probe, found.handle, options.activationPollMs);
|
|
429
|
+
const focusAfterEnter = await landing(probe, afterEnter);
|
|
430
|
+
let passed2 = movedByEnter(afterEnter);
|
|
431
|
+
let failureReason = null;
|
|
432
|
+
let focusAfterTab = null;
|
|
433
|
+
if (!passed2 && !afterEnter.targetExists) {
|
|
434
|
+
failureReason = "target-missing";
|
|
435
|
+
} else if (!passed2 && !afterEnter.targetRendered) {
|
|
436
|
+
failureReason = "target-hidden";
|
|
437
|
+
} else if (!passed2) {
|
|
438
|
+
await probe.pressTab();
|
|
439
|
+
const afterTab = await probe.readFocus(found.handle);
|
|
440
|
+
const activated = afterEnter.navigated || afterEnter.position !== "skip-link";
|
|
441
|
+
focusAfterTab = await landing(probe, afterTab);
|
|
442
|
+
passed2 = afterTab.position === "inside-target" || activated && afterTab.position === "after-target" || afterEnter.navigated && afterTab.position === "body";
|
|
443
|
+
failureReason = passed2 ? null : "activation-no-effect";
|
|
444
|
+
}
|
|
445
|
+
skipLinks.push({
|
|
446
|
+
selector: found.selector,
|
|
447
|
+
html: found.html,
|
|
448
|
+
fragment: found.fragment,
|
|
449
|
+
tabIndex: found.tabIndex,
|
|
450
|
+
passed: passed2,
|
|
451
|
+
failureReason,
|
|
452
|
+
linkText: found.linkText,
|
|
453
|
+
target: found.target,
|
|
454
|
+
focusAfterEnter,
|
|
455
|
+
focusAfterTab,
|
|
456
|
+
screenshot: passed2 ? void 0 : await probe.screenshotFocused(found.handle)
|
|
457
|
+
});
|
|
458
|
+
} finally {
|
|
459
|
+
await probe.restoreState(state);
|
|
460
|
+
}
|
|
461
|
+
} finally {
|
|
462
|
+
await probe.disposeRef(found.handle);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} finally {
|
|
466
|
+
await probe.clearFocus();
|
|
138
467
|
}
|
|
468
|
+
const unreachable = collected.length === 0 ? await probe.findUnreachable() : [];
|
|
139
469
|
const passed = skipLinks.filter((link) => link.passed).length;
|
|
140
470
|
return {
|
|
141
471
|
skipLinks,
|
|
472
|
+
unreachable,
|
|
142
473
|
summary: {
|
|
143
474
|
found: skipLinks.length,
|
|
144
475
|
passed,
|
|
145
|
-
failed: skipLinks.length - passed
|
|
476
|
+
failed: skipLinks.length - passed,
|
|
477
|
+
unreachable: unreachable.length
|
|
146
478
|
}
|
|
147
479
|
};
|
|
148
480
|
}
|
|
149
|
-
async function
|
|
150
|
-
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
if (pollMs <= 0) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
481
|
+
async function pollFocus(probe, ref, pollMs) {
|
|
482
|
+
let focus = await probe.readFocus(ref);
|
|
156
483
|
const deadline = Date.now() + pollMs;
|
|
157
|
-
while (Date.now() < deadline) {
|
|
484
|
+
while (!movedByEnter(focus) && Date.now() < deadline) {
|
|
158
485
|
await new Promise((resolve) => setTimeout(resolve, 16));
|
|
159
|
-
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
486
|
+
focus = await probe.readFocus(ref);
|
|
162
487
|
}
|
|
163
|
-
return
|
|
488
|
+
return focus;
|
|
164
489
|
}
|
|
165
490
|
function createAdaptorProbe(adaptor) {
|
|
166
491
|
return {
|
|
@@ -171,22 +496,23 @@ function createAdaptorProbe(adaptor) {
|
|
|
171
496
|
return adaptor.pressEnter();
|
|
172
497
|
},
|
|
173
498
|
async probeTabStop() {
|
|
174
|
-
const
|
|
175
|
-
|
|
499
|
+
const handle = await adaptor.evaluateHandle(activeElementHandleScript);
|
|
500
|
+
const { link } = await adaptor.evaluate(inspectSkipLinkScript, handle, "classify");
|
|
501
|
+
if (!link || link.isBody) {
|
|
502
|
+
await adaptor.disposeRef(handle);
|
|
176
503
|
return { isBody: true, identity: "body", candidate: null };
|
|
177
504
|
}
|
|
178
|
-
const handle = await adaptor.evaluateHandle(activeElementHandleScript);
|
|
179
505
|
const selector = await adaptor.evaluate(getSelector, handle);
|
|
180
|
-
|
|
181
|
-
if (base.fragment) {
|
|
506
|
+
if (link.fragment && link.skipLike) {
|
|
182
507
|
return {
|
|
183
508
|
isBody: false,
|
|
184
509
|
identity: selector,
|
|
185
510
|
candidate: {
|
|
186
511
|
selector,
|
|
187
|
-
html,
|
|
188
|
-
fragment:
|
|
189
|
-
|
|
512
|
+
html: truncateHtml(link.html),
|
|
513
|
+
fragment: link.fragment,
|
|
514
|
+
linkText: link.linkText,
|
|
515
|
+
target: link.target && { ...link.target, html: truncateHtml(link.target.html) },
|
|
190
516
|
handle
|
|
191
517
|
}
|
|
192
518
|
};
|
|
@@ -197,8 +523,62 @@ function createAdaptorProbe(adaptor) {
|
|
|
197
523
|
focusHandle(ref) {
|
|
198
524
|
return adaptor.evaluate(focusScript, ref);
|
|
199
525
|
},
|
|
200
|
-
|
|
201
|
-
|
|
526
|
+
async readFocus(ref) {
|
|
527
|
+
const { link } = await adaptor.evaluate(inspectSkipLinkScript, ref, "focus");
|
|
528
|
+
return {
|
|
529
|
+
position: link?.focus.position ?? "body",
|
|
530
|
+
navigated: link?.focus.navigated ?? false,
|
|
531
|
+
targetExists: Boolean(link?.target),
|
|
532
|
+
targetRendered: link?.target?.rendered ?? false
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
async describeFocused() {
|
|
536
|
+
const handle = await adaptor.evaluateHandle(activeElementHandleScript);
|
|
537
|
+
try {
|
|
538
|
+
const { link } = await adaptor.evaluate(inspectSkipLinkScript, handle, "focus");
|
|
539
|
+
if (!link || link.isBody) {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
selector: await adaptor.evaluate(getSelector, handle),
|
|
544
|
+
html: truncateHtml(link.html)
|
|
545
|
+
};
|
|
546
|
+
} finally {
|
|
547
|
+
await adaptor.disposeRef(handle);
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
async findUnreachable() {
|
|
551
|
+
const { unreachable } = await adaptor.evaluate(
|
|
552
|
+
inspectSkipLinkScript,
|
|
553
|
+
null,
|
|
554
|
+
"unreachable",
|
|
555
|
+
UNREACHABLE_LIMIT
|
|
556
|
+
);
|
|
557
|
+
const results = [];
|
|
558
|
+
for (const link of unreachable) {
|
|
559
|
+
const handle = await adaptor.evaluateHandle(takeUnreachableSkipLinkScript);
|
|
560
|
+
try {
|
|
561
|
+
results.push({
|
|
562
|
+
selector: await adaptor.evaluate(getSelector, handle),
|
|
563
|
+
html: truncateHtml(link.html),
|
|
564
|
+
fragment: link.fragment,
|
|
565
|
+
linkText: link.linkText,
|
|
566
|
+
reason: link.reason
|
|
567
|
+
});
|
|
568
|
+
} finally {
|
|
569
|
+
await adaptor.disposeRef(handle);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return results;
|
|
573
|
+
},
|
|
574
|
+
saveState() {
|
|
575
|
+
return adaptor.evaluate(readPageStateScript);
|
|
576
|
+
},
|
|
577
|
+
restoreState(state) {
|
|
578
|
+
return adaptor.evaluate(restorePageStateScript, state);
|
|
579
|
+
},
|
|
580
|
+
clearFocus() {
|
|
581
|
+
return adaptor.evaluate(resetFocusScript);
|
|
202
582
|
},
|
|
203
583
|
async screenshotFocused(ref) {
|
|
204
584
|
await adaptor.evaluate(focusScript, ref);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/audit.ts","../src/browser-scripts.ts"],"sourcesContent":["import { captureElementScreenshot } from \"@a11y-pulse/browser-adaptor\";\nimport { getSelector, truncateHtml } from \"@a11y-pulse/browser-adaptor/dom\";\nimport type { ElementRef, SkipLinkAuditAdaptor } from \"./adaptor\";\nimport {\n\tactiveElementHandleScript,\n\tfocusScript,\n\tisFocusInsideTargetScript,\n\tprobeActiveElementScript,\n} from \"./browser-scripts\";\nimport type { SkipLinkElementResult, SkipLinkResult } from \"./result\";\n\nexport const DEFAULT_CANDIDATE_LIMIT = 3;\nexport const DEFAULT_ACTIVATION_POLL_MS = 250;\n\nconst SCREENSHOT_CLIP_BUFFER = 10;\nconst SCREENSHOT_SETTLE_MS = 33; // ~2 frames at 60fps\n\nexport type SkipLinkOptions = {\n\t/** Max tab stops to scan for skip-link candidates. Defaults to 3. */\n\tcandidateLimit?: number;\n};\n\nexport type ResolvedSkipLinkOptions = {\n\tcandidateLimit: number;\n\tactivationPollMs: number;\n};\n\nexport type SkipLinkCandidate = {\n\tselector: string;\n\thtml: string;\n\tfragment: string;\n\ttargetResolves: boolean;\n\thandle: ElementRef;\n};\n\nexport type TabStopProbe = {\n\tisBody: boolean;\n\t/** Unique identity of the focused element, used to detect a focus cycle. */\n\tidentity: string;\n\tcandidate: SkipLinkCandidate | null;\n};\n\n/** The browser-coupled seams the loop drives. Mocked in unit tests. */\nexport type SkipLinkProbe = {\n\tpressTab(): Promise<void>;\n\tpressEnter(): Promise<void>;\n\tprobeTabStop(): Promise<TabStopProbe>;\n\tfocusHandle(ref: ElementRef): Promise<void>;\n\tisFocusInsideTarget(fragment: string): Promise<boolean>;\n\t/** Focus the element and screenshot it, so a link that only appears on focus is visible. */\n\tscreenshotFocused(ref: ElementRef): Promise<Uint8Array>;\n\tdisposeRef(ref: ElementRef): Promise<void>;\n};\n\nfunction resolveOptions(options: SkipLinkOptions): ResolvedSkipLinkOptions {\n\treturn {\n\t\tcandidateLimit: options.candidateLimit ?? DEFAULT_CANDIDATE_LIMIT,\n\t\tactivationPollMs: DEFAULT_ACTIVATION_POLL_MS,\n\t};\n}\n\n/**\n * Tab through the first few stops looking for skip-link-like fragment anchors, then activate each\n * candidate and check that keyboard focus moves. Enables focus reporting up front, then drives the\n * loop.\n */\nexport async function runSkipLinkAudit(\n\tadaptor: SkipLinkAuditAdaptor,\n\toptions: SkipLinkOptions = {},\n): Promise<SkipLinkResult> {\n\tawait adaptor.ensureFocusReporting();\n\n\treturn runSkipLinkLoop(createAdaptorProbe(adaptor), resolveOptions(options));\n}\n\n/** The engine-neutral two-phase loop. Exported for unit testing with a fake probe. */\nexport async function runSkipLinkLoop(\n\tprobe: SkipLinkProbe,\n\toptions: ResolvedSkipLinkOptions,\n): Promise<SkipLinkResult> {\n\tconst collected: Array<SkipLinkCandidate & { tabIndex: number }> = [];\n\tconst seen = new Set<string>();\n\n\tfor (let i = 0; i < options.candidateLimit; i++) {\n\t\tawait probe.pressTab();\n\n\t\tconst tabStop = await probe.probeTabStop();\n\n\t\tif (tabStop.isBody || seen.has(tabStop.identity)) {\n\t\t\tbreak;\n\t\t}\n\n\t\tseen.add(tabStop.identity);\n\n\t\tif (tabStop.candidate) {\n\t\t\tcollected.push({ ...tabStop.candidate, tabIndex: i + 1 });\n\t\t}\n\t}\n\n\tconst skipLinks: SkipLinkElementResult[] = [];\n\n\tfor (const found of collected) {\n\t\ttry {\n\t\t\tif (!found.targetResolves) {\n\t\t\t\tskipLinks.push({\n\t\t\t\t\tselector: found.selector,\n\t\t\t\t\thtml: found.html,\n\t\t\t\t\tfragment: found.fragment,\n\t\t\t\t\ttabIndex: found.tabIndex,\n\t\t\t\t\tpassed: false,\n\t\t\t\t\tfailureReason: \"target-missing\",\n\t\t\t\t\tscreenshot: await probe.screenshotFocused(found.handle),\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait probe.focusHandle(found.handle);\n\t\t\tawait probe.pressEnter();\n\n\t\t\tlet passed = await pollFocusInsideTarget(probe, found.fragment, options.activationPollMs);\n\n\t\t\tif (!passed) {\n\t\t\t\tawait probe.pressTab();\n\t\t\t\tpassed = await probe.isFocusInsideTarget(found.fragment);\n\t\t\t}\n\n\t\t\tskipLinks.push({\n\t\t\t\tselector: found.selector,\n\t\t\t\thtml: found.html,\n\t\t\t\tfragment: found.fragment,\n\t\t\t\ttabIndex: found.tabIndex,\n\t\t\t\tpassed,\n\t\t\t\tfailureReason: passed ? null : \"activation-no-effect\",\n\t\t\t\tscreenshot: passed ? undefined : await probe.screenshotFocused(found.handle),\n\t\t\t});\n\t\t} finally {\n\t\t\tawait probe.disposeRef(found.handle);\n\t\t}\n\t}\n\n\tconst passed = skipLinks.filter((link) => link.passed).length;\n\n\treturn {\n\t\tskipLinks,\n\t\tsummary: {\n\t\t\tfound: skipLinks.length,\n\t\t\tpassed,\n\t\t\tfailed: skipLinks.length - passed,\n\t\t},\n\t};\n}\n\nasync function pollFocusInsideTarget(\n\tprobe: SkipLinkProbe,\n\tfragment: string,\n\tpollMs: number,\n): Promise<boolean> {\n\tif (await probe.isFocusInsideTarget(fragment)) {\n\t\treturn true;\n\t}\n\n\tif (pollMs <= 0) {\n\t\treturn false;\n\t}\n\n\tconst deadline = Date.now() + pollMs;\n\n\twhile (Date.now() < deadline) {\n\t\tawait new Promise((resolve) => setTimeout(resolve, 16));\n\n\t\tif (await probe.isFocusInsideTarget(fragment)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\nfunction createAdaptorProbe(adaptor: SkipLinkAuditAdaptor): SkipLinkProbe {\n\treturn {\n\t\tpressTab() {\n\t\t\treturn adaptor.pressTab();\n\t\t},\n\n\t\tpressEnter() {\n\t\t\treturn adaptor.pressEnter();\n\t\t},\n\n\t\tasync probeTabStop() {\n\t\t\tconst base = await adaptor.evaluate(probeActiveElementScript);\n\n\t\t\tif (base.isBody) {\n\t\t\t\treturn { isBody: true, identity: \"body\", candidate: null };\n\t\t\t}\n\n\t\t\tconst handle = await adaptor.evaluateHandle(activeElementHandleScript);\n\t\t\tconst selector = await adaptor.evaluate(getSelector, handle);\n\t\t\tconst html = truncateHtml(base.html);\n\n\t\t\tif (base.fragment) {\n\t\t\t\treturn {\n\t\t\t\t\tisBody: false,\n\t\t\t\t\tidentity: selector,\n\t\t\t\t\tcandidate: {\n\t\t\t\t\t\tselector,\n\t\t\t\t\t\thtml,\n\t\t\t\t\t\tfragment: base.fragment,\n\t\t\t\t\t\ttargetResolves: base.targetResolves,\n\t\t\t\t\t\thandle,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tawait adaptor.disposeRef(handle);\n\n\t\t\treturn { isBody: false, identity: selector, candidate: null };\n\t\t},\n\n\t\tfocusHandle(ref) {\n\t\t\treturn adaptor.evaluate(focusScript, ref);\n\t\t},\n\n\t\tisFocusInsideTarget(fragment) {\n\t\t\treturn adaptor.evaluate(isFocusInsideTargetScript, fragment);\n\t\t},\n\n\t\tasync screenshotFocused(ref) {\n\t\t\tawait adaptor.evaluate(focusScript, ref);\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, SCREENSHOT_SETTLE_MS));\n\n\t\t\treturn captureElementScreenshot(adaptor, ref, {\n\t\t\t\tclipBuffer: SCREENSHOT_CLIP_BUFFER,\n\t\t\t\tsettleDelay: SCREENSHOT_SETTLE_MS,\n\t\t\t});\n\t\t},\n\n\t\tdisposeRef(ref) {\n\t\t\treturn adaptor.disposeRef(ref);\n\t\t},\n\t};\n}\n","/**\n * IMPORTANT: Functions in this file that are serialized and injected into the audited page must not\n * reference any symbols outside their own scope. Common logic (fragment parsing, target resolution,\n * shadow-root descent) is therefore duplicated inside each injected function.\n */\n\n/**\n * Return the in-page fragment for a skip-link-like href, or null if the href is not a same-document\n * hash (including the bare `#` and `#top`, which have no element target).\n */\nexport function parseInPageFragment(href: string | null): string | null {\n\tif (href === null || href === \"\") {\n\t\treturn null;\n\t}\n\n\tif (!href.startsWith(\"#\")) {\n\t\treturn null;\n\t}\n\n\tif (href === \"#\" || href === \"#top\") {\n\t\treturn null;\n\t}\n\n\t// Hash-router and hashbang paths are not element ids.\n\tif (href.startsWith(\"#/\") || href.startsWith(\"#!/\")) {\n\t\treturn null;\n\t}\n\n\treturn href;\n}\n\n/**\n * Resolve a fragment to an element, preferring `id` then a matching `name`. Serialized and run in\n * the page; must stay self-contained.\n */\nexport function resolveFragmentTargetScript(fragment: string): Element | null {\n\tconst raw = fragment.startsWith(\"#\") ? fragment.slice(1) : fragment;\n\tlet decoded = raw;\n\n\ttry {\n\t\tdecoded = decodeURIComponent(raw);\n\t} catch {\n\t\t// Keep the raw id when it is not valid percent-encoding.\n\t}\n\n\treturn document.getElementById(decoded) ?? document.getElementsByName(decoded)[0] ?? null;\n}\n\nexport type SkipLinkActiveElementBase = {\n\tisBody: boolean;\n\thtml: string;\n\t/**\n\t * In-page fragment such as \"#main\", or null when the focused node is not a skip-link candidate.\n\t */\n\tfragment: string | null;\n\ttargetResolves: boolean;\n};\n\n/**\n * Read the currently focused element (descending open shadow roots) and report whether it is a\n * skip-link-like in-page fragment anchor.\n */\nexport function probeActiveElementScript(): SkipLinkActiveElementBase {\n\tlet el = document.activeElement;\n\n\twhile (el?.shadowRoot?.activeElement) {\n\t\tel = el.shadowRoot.activeElement;\n\t}\n\n\tif (!el || el === document.body) {\n\t\treturn {\n\t\t\tisBody: true,\n\t\t\thtml: \"\",\n\t\t\tfragment: null,\n\t\t\ttargetResolves: false,\n\t\t};\n\t}\n\n\tconst openingTag = (el.cloneNode(false) as Element).outerHTML;\n\tconst href = el.tagName === \"A\" ? (el as HTMLAnchorElement).getAttribute(\"href\") : null;\n\n\tlet fragment: string | null = null;\n\n\tif (\n\t\thref?.startsWith(\"#\") &&\n\t\thref !== \"#\" &&\n\t\thref !== \"#top\" &&\n\t\t!href.startsWith(\"#/\") &&\n\t\t!href.startsWith(\"#!/\")\n\t) {\n\t\tfragment = href;\n\t}\n\n\tlet targetResolves = false;\n\n\tif (fragment) {\n\t\tconst raw = fragment.slice(1);\n\t\tlet decoded = raw;\n\n\t\ttry {\n\t\t\tdecoded = decodeURIComponent(raw);\n\t\t} catch {\n\t\t\t// Keep the raw id when it is not valid percent-encoding.\n\t\t}\n\n\t\ttargetResolves = Boolean(\n\t\t\tdocument.getElementById(decoded) ?? document.getElementsByName(decoded)[0],\n\t\t);\n\t}\n\n\treturn {\n\t\tisBody: false,\n\t\thtml: openingTag,\n\t\tfragment,\n\t\ttargetResolves,\n\t};\n}\n\n/**\n * Return the focused element, descending open shadow roots.\n */\nexport function activeElementHandleScript(): Element | null {\n\tlet el = document.activeElement;\n\n\twhile (el?.shadowRoot?.activeElement) {\n\t\tel = el.shadowRoot.activeElement;\n\t}\n\n\treturn el;\n}\n\n/**\n * Whether document.activeElement is the fragment target or inside it.\n */\nexport function isFocusInsideTargetScript(fragment: string): boolean {\n\tconst raw = fragment.startsWith(\"#\") ? fragment.slice(1) : fragment;\n\tlet decoded = raw;\n\n\ttry {\n\t\tdecoded = decodeURIComponent(raw);\n\t} catch {\n\t\t// Keep the raw id when it is not valid percent-encoding.\n\t}\n\n\tconst target = document.getElementById(decoded) ?? document.getElementsByName(decoded)[0] ?? null;\n\n\tif (!target) {\n\t\treturn false;\n\t}\n\n\tlet el = document.activeElement;\n\n\twhile (el?.shadowRoot?.activeElement) {\n\t\tel = el.shadowRoot.activeElement;\n\t}\n\n\tif (!el) {\n\t\treturn false;\n\t}\n\n\treturn el === target || target.contains(el);\n}\n\nexport function focusScript(el: Element | null): void {\n\t(el as HTMLElement | null)?.focus();\n}\n"],"mappings":";AAAA,SAAS,gCAAgC;AACzC,SAAS,aAAa,oBAAoB;;;AC6DnC,SAAS,2BAAsD;AACrE,MAAI,KAAK,SAAS;AAElB,SAAO,IAAI,YAAY,eAAe;AACrC,SAAK,GAAG,WAAW;AAAA,EACpB;AAEA,MAAI,CAAC,MAAM,OAAO,SAAS,MAAM;AAChC,WAAO;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,M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AEA,aAAa;AACZ,aAAO,QAAQ,WAAW;AAAA,IAC3B;AAAA,IAEA,MAAM,eAAe;AACpB,YAAM,OAAO,MAAM,QAAQ,SAAS,wBAAwB;AAE5D,UAAI,KAAK,QAAQ;AAChB,eAAO,EAAE,QAAQ,MAAM,UAAU,QAAQ,WAAW,KAAK;AAAA,MAC1D;AAEA,YAAM,SAAS,MAAM,QAAQ,eAAe,yBAAyB;AACrE,YAAM,WAAW,MAAM,QAAQ,SAAS,aAAa,MAAM;AAC3D,YAAM,OAAO,aAAa,KAAK,IAAI;AAEnC,UAAI,KAAK,UAAU;AAClB,eAAO;AAAA,UACN,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,WAAW;AAAA,YACV;AAAA,YACA;AAAA,YACA,UAAU,KAAK;AAAA,YACf,gBAAgB,KAAK;AAAA,YACrB;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,WAAW,MAAM;AAE/B,aAAO,EAAE,QAAQ,OAAO,UAAU,UAAU,WAAW,KAAK;AAAA,IAC7D;AAAA,IAEA,YAAY,KAAK;AAChB,aAAO,QAAQ,SAAS,aAAa,GAAG;AAAA,IACzC;AAAA,IAEA,oBAAoB,UAAU;AAC7B,aAAO,QAAQ,SAAS,2BAA2B,QAAQ;AAAA,IAC5D;AAAA,IAEA,MAAM,kBAAkB,KAAK;AAC5B,YAAM,QAAQ,SAAS,aAAa,GAAG;AACvC,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,oBAAoB,CAAC;AAExE,aAAO,yBAAyB,SAAS,KAAK;AAAA,QAC7C,YAAY;AAAA,QACZ,aAAa;AAAA,MACd,CAAC;AAAA,IACF;AAAA,IAEA,WAAW,KAAK;AACf,aAAO,QAAQ,WAAW,GAAG;AAAA,IAC9B;AAAA,EACD;AACD;","names":["passed"]}
|
|
1
|
+
{"version":3,"sources":["../src/audit.ts","../src/browser-scripts.ts"],"sourcesContent":["import { captureElementScreenshot } from \"@a11y-pulse/browser-adaptor\";\nimport { getSelector, truncateHtml } from \"@a11y-pulse/browser-adaptor/dom\";\nimport type { ElementRef, SkipLinkAuditAdaptor } from \"./adaptor\";\nimport {\n\tactiveElementHandleScript,\n\tfocusScript,\n\tinspectSkipLinkScript,\n\treadPageStateScript,\n\tresetFocusScript,\n\trestorePageStateScript,\n\ttype SkipLinkFocusPosition,\n\ttype SkipLinkPageState,\n\ttakeUnreachableSkipLinkScript,\n} from \"./browser-scripts\";\nimport type {\n\tSkipLinkElementResult,\n\tSkipLinkFailureReason,\n\tSkipLinkFocusLanding,\n\tSkipLinkResult,\n\tSkipLinkTarget,\n\tSkipLinkUnreachableResult,\n} from \"./result\";\n\nexport const DEFAULT_CANDIDATE_LIMIT = 3;\nexport const DEFAULT_ACTIVATION_POLL_MS = 250;\n\n/** How many unreachable skip links to report when none can be reached by tabbing. */\nconst UNREACHABLE_LIMIT = 3;\n\nconst SCREENSHOT_CLIP_BUFFER = 10;\nconst SCREENSHOT_SETTLE_MS = 33; // ~2 frames at 60fps\n\nexport type SkipLinkOptions = {\n\t/** Max tab stops to scan for skip-link candidates. Defaults to 3. */\n\tcandidateLimit?: number;\n};\n\nexport type ResolvedSkipLinkOptions = {\n\tcandidateLimit: number;\n\tactivationPollMs: number;\n};\n\nexport type SkipLinkCandidate = {\n\tselector: string;\n\thtml: string;\n\tfragment: string;\n\tlinkText: string;\n\t/** The element the fragment resolves to, or null when nothing matches it. */\n\ttarget: SkipLinkTarget | null;\n\thandle: ElementRef;\n};\n\nexport type TabStopProbe = {\n\tisBody: boolean;\n\t/** Unique identity of the focused element, used to detect a focus cycle. */\n\tidentity: string;\n\tcandidate: SkipLinkCandidate | null;\n};\n\n/** Where focus is relative to a skip link, read after a key press. */\nexport type FocusReading = {\n\tposition: SkipLinkFocusPosition;\n\t/** Whether the document's URL fragment is the one the link points at. */\n\tnavigated: boolean;\n\t/** Whether the link's target exists. */\n\ttargetExists: boolean;\n\t/** Whether the link's target exists and is rendered. */\n\ttargetRendered: boolean;\n};\n\n/** The browser-coupled seams the loop drives. Mocked in unit tests. */\nexport type SkipLinkProbe = {\n\tpressTab(): Promise<void>;\n\tpressEnter(): Promise<void>;\n\tprobeTabStop(): Promise<TabStopProbe>;\n\tfocusHandle(ref: ElementRef): Promise<void>;\n\t/** Where focus is now, relative to the skip link behind `ref` and its target. */\n\treadFocus(ref: ElementRef): Promise<FocusReading>;\n\t/** Selector and opening tag of the focused element, or null when nothing is focused. */\n\tdescribeFocused(): Promise<{ selector: string; html: string } | null>;\n\t/** Skip links in the document that can never receive keyboard focus. */\n\tfindUnreachable(): Promise<SkipLinkUnreachableResult[]>;\n\t/** Record the URL, history length and scroll position so activating a link can be undone. */\n\tsaveState(): Promise<SkipLinkPageState>;\n\trestoreState(state: SkipLinkPageState): Promise<void>;\n\t/**\n\t * Drop focus and start the tab order from the top again, so the next Tab press does not carry on\n\t * from a skip target or from the last stop the audit looked at.\n\t */\n\tclearFocus(): Promise<void>;\n\t/** Focus the element and screenshot it, so a link that only appears on focus is visible. */\n\tscreenshotFocused(ref: ElementRef): Promise<Uint8Array>;\n\tdisposeRef(ref: ElementRef): Promise<void>;\n};\n\nfunction resolveOptions(options: SkipLinkOptions): ResolvedSkipLinkOptions {\n\treturn {\n\t\tcandidateLimit: options.candidateLimit ?? DEFAULT_CANDIDATE_LIMIT,\n\t\tactivationPollMs: DEFAULT_ACTIVATION_POLL_MS,\n\t};\n}\n\n/**\n * Tab through the first few stops looking for skip links, then activate each one and check that\n * keyboard focus moves. Enables focus reporting up front, then drives the loop.\n */\nexport async function runSkipLinkAudit(\n\tadaptor: SkipLinkAuditAdaptor,\n\toptions: SkipLinkOptions = {},\n): Promise<SkipLinkResult> {\n\tawait adaptor.ensureFocusReporting();\n\n\treturn runSkipLinkLoop(createAdaptorProbe(adaptor), resolveOptions(options));\n}\n\n/** Enter alone moved focus to the target, or to later content when there is no target to reach. */\nfunction movedByEnter(focus: FocusReading): boolean {\n\tif (focus.position === \"inside-target\" || focus.position === \"after-target\") {\n\t\treturn true;\n\t}\n\n\treturn !focus.targetExists && focus.position === \"after-link\";\n}\n\nasync function landing(probe: SkipLinkProbe, focus: FocusReading): Promise<SkipLinkFocusLanding> {\n\tconst focused = focus.position === \"body\" ? null : await probe.describeFocused();\n\n\treturn {\n\t\tposition: focus.position,\n\t\tselector: focused?.selector ?? null,\n\t\thtml: focused?.html ?? null,\n\t};\n}\n\n/** The engine-neutral two-phase loop. Exported for unit testing with a fake probe. */\nexport async function runSkipLinkLoop(\n\tprobe: SkipLinkProbe,\n\toptions: ResolvedSkipLinkOptions,\n): Promise<SkipLinkResult> {\n\tconst collected: Array<SkipLinkCandidate & { tabIndex: number }> = [];\n\tconst seen = new Set<string>();\n\tconst skipLinks: SkipLinkElementResult[] = [];\n\n\ttry {\n\t\tfor (let i = 0; i < options.candidateLimit; i++) {\n\t\t\tawait probe.pressTab();\n\n\t\t\tconst tabStop = await probe.probeTabStop();\n\n\t\t\tif (tabStop.isBody || seen.has(tabStop.identity)) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tseen.add(tabStop.identity);\n\n\t\t\tif (tabStop.candidate) {\n\t\t\t\tcollected.push({ ...tabStop.candidate, tabIndex: i + 1 });\n\t\t\t}\n\t\t}\n\n\t\tfor (const found of collected) {\n\t\t\ttry {\n\t\t\t\tconst state = await probe.saveState();\n\n\t\t\t\ttry {\n\t\t\t\t\tawait probe.focusHandle(found.handle);\n\t\t\t\t\tawait probe.pressEnter();\n\n\t\t\t\t\t// A link with no target is still activated: a script may move focus on its behalf.\n\t\t\t\t\tconst afterEnter = await pollFocus(probe, found.handle, options.activationPollMs);\n\t\t\t\t\tconst focusAfterEnter = await landing(probe, afterEnter);\n\n\t\t\t\t\tlet passed = movedByEnter(afterEnter);\n\t\t\t\t\tlet failureReason: SkipLinkFailureReason | null = null;\n\t\t\t\t\tlet focusAfterTab: SkipLinkFocusLanding | null = null;\n\n\t\t\t\t\tif (!passed && !afterEnter.targetExists) {\n\t\t\t\t\t\tfailureReason = \"target-missing\";\n\t\t\t\t\t} else if (!passed && !afterEnter.targetRendered) {\n\t\t\t\t\t\tfailureReason = \"target-hidden\";\n\t\t\t\t\t} else if (!passed) {\n\t\t\t\t\t\t// Following a fragment moves the browser's focus starting point without focusing\n\t\t\t\t\t\t// anything, so the next Tab shows whether the link worked.\n\t\t\t\t\t\tawait probe.pressTab();\n\n\t\t\t\t\t\tconst afterTab = await probe.readFocus(found.handle);\n\t\t\t\t\t\tconst activated = afterEnter.navigated || afterEnter.position !== \"skip-link\";\n\n\t\t\t\t\t\tfocusAfterTab = await landing(probe, afterTab);\n\t\t\t\t\t\t// Tabbing out of the document after the fragment was followed means the target\n\t\t\t\t\t\t// was reached and nothing focusable comes after it.\n\t\t\t\t\t\tpassed =\n\t\t\t\t\t\t\tafterTab.position === \"inside-target\" ||\n\t\t\t\t\t\t\t(activated && afterTab.position === \"after-target\") ||\n\t\t\t\t\t\t\t(afterEnter.navigated && afterTab.position === \"body\");\n\t\t\t\t\t\tfailureReason = passed ? null : \"activation-no-effect\";\n\t\t\t\t\t}\n\n\t\t\t\t\tskipLinks.push({\n\t\t\t\t\t\tselector: found.selector,\n\t\t\t\t\t\thtml: found.html,\n\t\t\t\t\t\tfragment: found.fragment,\n\t\t\t\t\t\ttabIndex: found.tabIndex,\n\t\t\t\t\t\tpassed,\n\t\t\t\t\t\tfailureReason,\n\t\t\t\t\t\tlinkText: found.linkText,\n\t\t\t\t\t\ttarget: found.target,\n\t\t\t\t\t\tfocusAfterEnter,\n\t\t\t\t\t\tfocusAfterTab,\n\t\t\t\t\t\tscreenshot: passed ? undefined : await probe.screenshotFocused(found.handle),\n\t\t\t\t\t});\n\t\t\t\t} finally {\n\t\t\t\t\tawait probe.restoreState(state);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait probe.disposeRef(found.handle);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\t// Looking for candidates moved focus even when none was found, and so did each activation,\n\t\t// including one that threw. Whatever runs next starts tabbing from the top of the page.\n\t\tawait probe.clearFocus();\n\t}\n\n\t// A skip link nobody can tab to is only a problem when no other skip link works in its place.\n\tconst unreachable = collected.length === 0 ? await probe.findUnreachable() : [];\n\tconst passed = skipLinks.filter((link) => link.passed).length;\n\n\treturn {\n\t\tskipLinks,\n\t\tunreachable,\n\t\tsummary: {\n\t\t\tfound: skipLinks.length,\n\t\t\tpassed,\n\t\t\tfailed: skipLinks.length - passed,\n\t\t\tunreachable: unreachable.length,\n\t\t},\n\t};\n}\n\nasync function pollFocus(\n\tprobe: SkipLinkProbe,\n\tref: ElementRef,\n\tpollMs: number,\n): Promise<FocusReading> {\n\tlet focus = await probe.readFocus(ref);\n\tconst deadline = Date.now() + pollMs;\n\n\twhile (!movedByEnter(focus) && Date.now() < deadline) {\n\t\tawait new Promise((resolve) => setTimeout(resolve, 16));\n\n\t\tfocus = await probe.readFocus(ref);\n\t}\n\n\treturn focus;\n}\n\nfunction createAdaptorProbe(adaptor: SkipLinkAuditAdaptor): SkipLinkProbe {\n\treturn {\n\t\tpressTab() {\n\t\t\treturn adaptor.pressTab();\n\t\t},\n\n\t\tpressEnter() {\n\t\t\treturn adaptor.pressEnter();\n\t\t},\n\n\t\tasync probeTabStop() {\n\t\t\tconst handle = await adaptor.evaluateHandle(activeElementHandleScript);\n\t\t\tconst { link } = await adaptor.evaluate(inspectSkipLinkScript, handle, \"classify\");\n\n\t\t\tif (!link || link.isBody) {\n\t\t\t\tawait adaptor.disposeRef(handle);\n\n\t\t\t\treturn { isBody: true, identity: \"body\", candidate: null };\n\t\t\t}\n\n\t\t\tconst selector = await adaptor.evaluate(getSelector, handle);\n\n\t\t\tif (link.fragment && link.skipLike) {\n\t\t\t\treturn {\n\t\t\t\t\tisBody: false,\n\t\t\t\t\tidentity: selector,\n\t\t\t\t\tcandidate: {\n\t\t\t\t\t\tselector,\n\t\t\t\t\t\thtml: truncateHtml(link.html),\n\t\t\t\t\t\tfragment: link.fragment,\n\t\t\t\t\t\tlinkText: link.linkText,\n\t\t\t\t\t\ttarget: link.target && { ...link.target, html: truncateHtml(link.target.html) },\n\t\t\t\t\t\thandle,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tawait adaptor.disposeRef(handle);\n\n\t\t\treturn { isBody: false, identity: selector, candidate: null };\n\t\t},\n\n\t\tfocusHandle(ref) {\n\t\t\treturn adaptor.evaluate(focusScript, ref);\n\t\t},\n\n\t\tasync readFocus(ref) {\n\t\t\tconst { link } = await adaptor.evaluate(inspectSkipLinkScript, ref, \"focus\");\n\n\t\t\treturn {\n\t\t\t\tposition: link?.focus.position ?? \"body\",\n\t\t\t\tnavigated: link?.focus.navigated ?? false,\n\t\t\t\ttargetExists: Boolean(link?.target),\n\t\t\t\ttargetRendered: link?.target?.rendered ?? false,\n\t\t\t};\n\t\t},\n\n\t\tasync describeFocused() {\n\t\t\tconst handle = await adaptor.evaluateHandle(activeElementHandleScript);\n\n\t\t\ttry {\n\t\t\t\tconst { link } = await adaptor.evaluate(inspectSkipLinkScript, handle, \"focus\");\n\n\t\t\t\tif (!link || link.isBody) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tselector: await adaptor.evaluate(getSelector, handle),\n\t\t\t\t\thtml: truncateHtml(link.html),\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait adaptor.disposeRef(handle);\n\t\t\t}\n\t\t},\n\n\t\tasync findUnreachable() {\n\t\t\tconst { unreachable } = await adaptor.evaluate(\n\t\t\t\tinspectSkipLinkScript,\n\t\t\t\tnull,\n\t\t\t\t\"unreachable\",\n\t\t\t\tUNREACHABLE_LIMIT,\n\t\t\t);\n\t\t\tconst results: SkipLinkUnreachableResult[] = [];\n\n\t\t\tfor (const link of unreachable) {\n\t\t\t\tconst handle = await adaptor.evaluateHandle(takeUnreachableSkipLinkScript);\n\n\t\t\t\ttry {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tselector: await adaptor.evaluate(getSelector, handle),\n\t\t\t\t\t\thtml: truncateHtml(link.html),\n\t\t\t\t\t\tfragment: link.fragment,\n\t\t\t\t\t\tlinkText: link.linkText,\n\t\t\t\t\t\treason: link.reason,\n\t\t\t\t\t});\n\t\t\t\t} finally {\n\t\t\t\t\tawait adaptor.disposeRef(handle);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\n\t\tsaveState() {\n\t\t\treturn adaptor.evaluate(readPageStateScript);\n\t\t},\n\n\t\trestoreState(state) {\n\t\t\treturn adaptor.evaluate(restorePageStateScript, state);\n\t\t},\n\n\t\tclearFocus() {\n\t\t\treturn adaptor.evaluate(resetFocusScript);\n\t\t},\n\n\t\tasync screenshotFocused(ref) {\n\t\t\tawait adaptor.evaluate(focusScript, ref);\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, SCREENSHOT_SETTLE_MS));\n\n\t\t\treturn captureElementScreenshot(adaptor, ref, {\n\t\t\t\tclipBuffer: SCREENSHOT_CLIP_BUFFER,\n\t\t\t\tsettleDelay: SCREENSHOT_SETTLE_MS,\n\t\t\t});\n\t\t},\n\n\t\tdisposeRef(ref) {\n\t\t\treturn adaptor.disposeRef(ref);\n\t\t},\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. Everything that needs the fragment parsing,\n * target resolution or skip-link heuristics goes through `inspectSkipLinkScript`, so there is one\n * copy of that logic and the tests exercise the code that ships.\n */\n\n/** Where the focused element sits relative to a skip link and its target. */\nexport type SkipLinkFocusPosition =\n\t/** Focus is on the target or inside it. */\n\t| \"inside-target\"\n\t/** Focus is on content that follows the target in document order. */\n\t| \"after-target\"\n\t/** Focus is on content after the link, and the link has no target to compare against. */\n\t| \"after-link\"\n\t/** Focus is still on the skip link. */\n\t| \"skip-link\"\n\t/** Nothing is focused. */\n\t| \"body\"\n\t/** Focus is somewhere else, such as before the link or between the link and its target. */\n\t| \"elsewhere\";\n\nexport type SkipLinkUnreachableReason =\n\t| \"not-rendered\"\n\t| \"visibility-hidden\"\n\t| \"inert\"\n\t| \"negative-tabindex\";\n\nexport type SkipLinkTargetInspection = {\n\tselector: string;\n\t/** Opening tag of the target. */\n\thtml: string;\n\t/** False when the target or an ancestor is `display: none` (or otherwise not rendered). */\n\trendered: boolean;\n};\n\nexport type SkipLinkInspection = {\n\t/** True when the inspected element is missing or is `<body>`. */\n\tisBody: boolean;\n\t/** Opening tag of the inspected element. */\n\thtml: string;\n\t/** Visible text of the link, falling back to its `aria-label`. */\n\tlinkText: string;\n\t/**\n\t * The same-document fragment the link points at, such as \"#main\". Null when the element is not a\n\t * link to a fragment of this document.\n\t */\n\tfragment: string | null;\n\t/** Whether the link looks like a skip link rather than a menu toggle or other in-page link. */\n\tskipLike: boolean;\n\ttarget: SkipLinkTargetInspection | null;\n\tfocus: {\n\t\tposition: SkipLinkFocusPosition;\n\t\t/** Whether the document's URL fragment is the one the link points at. */\n\t\tnavigated: boolean;\n\t};\n};\n\nexport type SkipLinkUnreachableInspection = {\n\thtml: string;\n\tlinkText: string;\n\tfragment: string;\n\treason: SkipLinkUnreachableReason;\n};\n\nexport type SkipLinkInspectionResult = {\n\t/** The inspected element. Null in \"unreachable\" mode. */\n\tlink: SkipLinkInspection | null;\n\t/** Skip links that can never receive focus. Only filled in \"unreachable\" mode. */\n\tunreachable: SkipLinkUnreachableInspection[];\n};\n\n/** Attribute that marks unreachable skip links so a handle can be taken to each one in turn. */\nexport const UNREACHABLE_MARKER = \"data-a11y-pulse-unreachable-skip-link\";\n\n/**\n * Inspect skip links in the page.\n *\n * - \"classify\": describe `el` and decide whether it is a skip link.\n * - \"focus\": describe `el` and where keyboard focus is relative to it and its target.\n * - \"unreachable\": ignore `el` and find skip links that can never receive keyboard focus, marking\n * each with `data-a11y-pulse-unreachable-skip-link`.\n */\nexport function inspectSkipLinkScript(\n\tel: Element | null,\n\tmode: \"classify\" | \"focus\" | \"unreachable\",\n\tlimit = 3,\n): SkipLinkInspectionResult {\n\t// Letters, digits and underscore in any script. `\\b` only knows ASCII, so without this\n\t// \"aller au\" matches inside \"Smaller audiences\" and accented words are cut in two.\n\tconst WORD = \"\\\\p{L}\\\\p{N}_\";\n\tconst START = `(?:^|[^${WORD}])`;\n\tconst END = `(?![${WORD}])`;\n\t// Verbs and prepositions that mean \"go to\" as much as \"skip to\" (\"Aller au panier\", \"Ga naar\n\t// winkelwagen\"), so they only count when a noun from NOUN follows.\n\tconst GO =\n\t\t\"skip|jump|go|zum|zur|springe|aller|passer|accéder|ir|saltar|salta|vai|passa|pular|avançar|ga|naar|spring|hoppa|hopp|gå|till|siirry|hyppää|przejdź|przeskocz|pomiń|přeskočit|přejít|перейти|пропустить\";\n\tconst FILLER =\n\t\t\"to|the|main|primary|zu|zum|zur|dem|der|direkt|au|aux|à|la|le|du|directement|al|a|el|alla|allo|ai|il|para|o|ao|naar|de|het|direct|till|til|det|do|na|k|ke|głównej|hlavní|hlavnímu|к|основному\";\n\tconst NOUN =\n\t\t\"content|main|navigation|nav|menu|search|footer|\\\\p{L}*inhalt|\\\\p{L}*navigation|menü|suche|contenu|recherche|contenido|navegación|menú|búsqueda|contenuto|navigazione|ricerca|conteúdo|navegação|pesquisa|\\\\p{L}*inhoud|navigatie|zoeken|\\\\p{L}*innehåll\\\\p{L}*|navigering\\\\p{L}*|meny\\\\p{L}*|\\\\p{L}*innhold\\\\p{L}*|\\\\p{L}*indhold\\\\p{L}*|navigasjon\\\\p{L}*|\\\\p{L}*sisält\\\\p{L}*|navigaatio\\\\p{L}*|valikko\\\\p{L}*|treści|zawartości|nawigacj\\\\p{L}*|obsah\\\\p{L}*|navigac\\\\p{L}*|содержани\\\\p{L}*|контент\\\\p{L}*|навигаци\\\\p{L}*|меню\";\n\tconst SKIP_WORDS = new RegExp(\n\t\t[\n\t\t\t// \"Skip to content\", \"Aller au contenu\", \"Ga direct naar de inhoud\", \"Перейти к содержанию\".\n\t\t\t`${START}(?:${GO})(?:\\\\s+(?:${FILLER})){0,3}\\\\s+(?:${NOUN})${END}`,\n\t\t\t// Verbs that only ever mean \"skip\".\n\t\t\t`${START}(?:skip|überspringen)${END}`,\n\t\t\t// Scripts written without spaces between words.\n\t\t\t\"スキップ|本文へ|メインコンテンツへ|跳[过過]|跳(?:到|至|转到|轉到)\\\\s*(?:主要|主|正文|内容|內容|导航|導航)|건너뛰기|본문\\\\s*(?:으로|바로\\\\s*가기)\",\n\t\t].join(\"|\"),\n\t\t\"iu\",\n\t);\n\t// A class or id that names the link a skip link: \"skip\", \"skip-link\", \"skiplink\", \"skip-to-content\".\n\tconst SKIP_TOKEN = /^skip(?:[-_]?(?:link|nav|navigation|main|content|to[-_]?[a-z]+))?$/i;\n\t// Ids that pages conventionally give their main content when they have no main landmark.\n\tconst CONTENT_ID =\n\t\t/^(?:(?:main|page|site|primary|skip)[-_]?)?(?:content|main)(?:[-_]?(?:area|wrapper|container|start))?$|^primary$/i;\n\tconst UNREACHABLE_ATTR = \"data-a11y-pulse-unreachable-skip-link\";\n\n\tfunction openingTag(node: Element): string {\n\t\treturn (node.cloneNode(false) as Element).outerHTML;\n\t}\n\n\tfunction isRendered(node: Element): boolean {\n\t\tif (typeof node.checkVisibility === \"function\") {\n\t\t\treturn node.checkVisibility();\n\t\t}\n\n\t\tfor (let current: Element | null = node; current; current = current.parentElement) {\n\t\t\tif (getComputedStyle(current).display === \"none\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tfunction textOf(node: Element): string {\n\t\tconst text = (node.textContent ?? \"\").replace(/\\s+/g, \" \").trim();\n\n\t\treturn (text || (node.getAttribute(\"aria-label\") ?? \"\").trim()).slice(0, 200);\n\t}\n\n\t/** The fragment of a link to this document, or null for any other element or destination. */\n\tfunction fragmentOf(node: Element): string | null {\n\t\tif (node.tagName !== \"A\" || !node.hasAttribute(\"href\")) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlet url: URL;\n\t\tlet here: URL;\n\n\t\ttry {\n\t\t\t// `href` is the resolved URL, so `/page#main`, absolute URLs and `<base>` are all handled.\n\t\t\turl = new URL((node as HTMLAnchorElement).href);\n\t\t\there = new URL(location.href);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (\n\t\t\turl.origin !== here.origin ||\n\t\t\turl.pathname !== here.pathname ||\n\t\t\turl.search !== here.search\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst hash = url.hash;\n\n\t\t// A bare `#` and `#top` scroll to the top, and hash-router paths are not element ids.\n\t\tif (hash === \"\" || hash === \"#\" || hash.toLowerCase() === \"#top\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (hash.startsWith(\"#/\") || hash.startsWith(\"#!/\")) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn hash;\n\t}\n\n\t/** Resolve a fragment the way browsers do: an id first, then an `<a name>`. */\n\tfunction targetOf(fragment: string): Element | null {\n\t\tconst raw = fragment.slice(1);\n\t\tlet decoded = raw;\n\n\t\ttry {\n\t\t\tdecoded = decodeURIComponent(raw);\n\t\t} catch {\n\t\t\t// Keep the raw id when it is not valid percent-encoding.\n\t\t}\n\n\t\tfor (const id of raw === decoded ? [raw] : [raw, decoded]) {\n\t\t\tconst byId = document.getElementById(id);\n\n\t\t\tif (byId) {\n\t\t\t\treturn byId;\n\t\t\t}\n\n\t\t\tfor (const named of Array.from(document.getElementsByName(id))) {\n\t\t\t\tif (named.tagName === \"A\") {\n\t\t\t\t\treturn named;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tfunction follows(node: Node, reference: Node): boolean {\n\t\treturn Boolean(reference.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING);\n\t}\n\n\t/** Skip wording in what the link says: its text or its `aria-label`. */\n\tfunction hasSkipWords(node: Element): boolean {\n\t\treturn SKIP_WORDS.test(`${textOf(node)} ${node.getAttribute(\"aria-label\") ?? \"\"}`);\n\t}\n\n\t/** A class or id that marks the link as a skip link, such as `class=\"skip-link\"`. */\n\tfunction hasSkipToken(node: Element): boolean {\n\t\tif (SKIP_TOKEN.test(node.id)) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn (node.getAttribute(\"class\") ?? \"\").split(/\\s+/).some((token) => SKIP_TOKEN.test(token));\n\t}\n\n\t/** Whether the target is the page's main content: the main landmark, a heading, or around either. */\n\tfunction isContentTarget(target: Element): boolean {\n\t\tif (target.matches('h1, h2, h3, h4, h5, h6, [role=\"heading\"]')) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst main = document.querySelector('main, [role=\"main\"]');\n\n\t\tif (main) {\n\t\t\treturn target === main || target.contains(main) || main.contains(target);\n\t\t}\n\n\t\t// Without a main landmark, an id such as \"content\" or \"main-content\" is the next best sign.\n\t\treturn CONTENT_ID.test(target.id || (target.getAttribute(\"name\") ?? \"\"));\n\t}\n\n\tfunction isSkipLike(link: Element, target: Element | null): boolean {\n\t\tconst role = link.getAttribute(\"role\");\n\n\t\t// Disclosure toggles, tabs and link-shaped buttons act on the page instead of moving focus.\n\t\tif (link.hasAttribute(\"aria-expanded\") || role === \"tab\" || role === \"button\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (hasSkipWords(link) || hasSkipToken(link)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// From here on only the target can vouch for the link. Jumping past other controls is not\n\t\t// enough: a \"Menu\" link to a navigation block further down the page does that too.\n\t\tif (!target || !follows(target, link)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// A menu or panel revealed by `:target` is hidden until its link is followed, and navigation\n\t\t// is what a skip link skips, not where one goes without saying so.\n\t\tif (!isRendered(target) || target.closest('nav, [role=\"navigation\"]')) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn isContentTarget(target);\n\t}\n\n\tfunction targetSelector(target: Element): string {\n\t\tif (target.id) {\n\t\t\treturn `#${CSS.escape(target.id)}`;\n\t\t}\n\n\t\treturn `a[name=\"${CSS.escape(target.getAttribute(\"name\") ?? \"\")}\"]`;\n\t}\n\n\tfunction unreachableReason(link: Element): SkipLinkUnreachableReason | null {\n\t\tif (!isRendered(link)) {\n\t\t\treturn \"not-rendered\";\n\t\t}\n\n\t\tconst visibility = getComputedStyle(link).visibility;\n\n\t\tif (visibility === \"hidden\" || visibility === \"collapse\") {\n\t\t\treturn \"visibility-hidden\";\n\t\t}\n\n\t\tif (link.closest(\"[inert]\")) {\n\t\t\treturn \"inert\";\n\t\t}\n\n\t\tconst tabindex = link.getAttribute(\"tabindex\");\n\n\t\tif (tabindex !== null && Number.parseInt(tabindex, 10) < 0) {\n\t\t\treturn \"negative-tabindex\";\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tif (mode === \"unreachable\") {\n\t\tconst unreachable: SkipLinkUnreachableInspection[] = [];\n\n\t\tfor (const marked of Array.from(document.querySelectorAll(`[${UNREACHABLE_ATTR}]`))) {\n\t\t\tmarked.removeAttribute(UNREACHABLE_ATTR);\n\t\t}\n\n\t\t// Skip links sit at the top of the document, so only its first links are worth reading.\n\t\tfor (const link of Array.from(document.querySelectorAll(\"a[href]\")).slice(0, 50)) {\n\t\t\tif (unreachable.length >= limit) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst fragment = fragmentOf(link);\n\n\t\t\t// Only what the link says counts here. A hidden link is not about to be followed, so there\n\t\t\t// is no target behaviour to go on, and class names are too loose a sign on their own.\n\t\t\tif (!fragment || !hasSkipWords(link) || !isSkipLike(link, targetOf(fragment))) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst reason = unreachableReason(link);\n\n\t\t\tif (!reason) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst html = openingTag(link);\n\n\t\t\tlink.setAttribute(UNREACHABLE_ATTR, String(unreachable.length));\n\t\t\tunreachable.push({ html, linkText: textOf(link), fragment, reason });\n\t\t}\n\n\t\treturn { link: null, unreachable };\n\t}\n\n\tif (!el || el === document.body || el === document.documentElement) {\n\t\treturn {\n\t\t\tlink: {\n\t\t\t\tisBody: true,\n\t\t\t\thtml: \"\",\n\t\t\t\tlinkText: \"\",\n\t\t\t\tfragment: null,\n\t\t\t\tskipLike: false,\n\t\t\t\ttarget: null,\n\t\t\t\tfocus: { position: \"body\", navigated: false },\n\t\t\t},\n\t\t\tunreachable: [],\n\t\t};\n\t}\n\n\tconst fragment = fragmentOf(el);\n\tconst target = fragment ? targetOf(fragment) : null;\n\n\t// Compare document positions on the light-DOM host, and identity on the deepest focused node.\n\tconst host = document.activeElement;\n\tlet active = host;\n\n\twhile (active?.shadowRoot?.activeElement) {\n\t\tactive = active.shadowRoot.activeElement;\n\t}\n\n\tlet position: SkipLinkFocusPosition = \"elsewhere\";\n\n\tif (!host || !active || host === document.body || host === document.documentElement) {\n\t\tposition = \"body\";\n\t} else if (active === el) {\n\t\tposition = \"skip-link\";\n\t} else if (target && (active === target || target.contains(active) || target.contains(host))) {\n\t\tposition = \"inside-target\";\n\t} else if (target && follows(host, target)) {\n\t\tposition = \"after-target\";\n\t} else if (!target && follows(host, el)) {\n\t\tposition = \"after-link\";\n\t}\n\n\treturn {\n\t\tlink: {\n\t\t\tisBody: false,\n\t\t\thtml: openingTag(el),\n\t\t\tlinkText: textOf(el),\n\t\t\tfragment,\n\t\t\tskipLike: mode === \"classify\" && fragment !== null ? isSkipLike(el, target) : false,\n\t\t\ttarget: target\n\t\t\t\t? {\n\t\t\t\t\t\tselector: targetSelector(target),\n\t\t\t\t\t\thtml: openingTag(target),\n\t\t\t\t\t\trendered: isRendered(target),\n\t\t\t\t\t}\n\t\t\t\t: null,\n\t\t\tfocus: { position, navigated: fragment !== null && location.hash === fragment },\n\t\t},\n\t\tunreachable: [],\n\t};\n}\n\n/**\n * Return the focused element, descending open shadow roots.\n */\nexport function activeElementHandleScript(): Element | null {\n\tlet el = document.activeElement;\n\n\twhile (el?.shadowRoot?.activeElement) {\n\t\tel = el.shadowRoot.activeElement;\n\t}\n\n\treturn el;\n}\n\n/**\n * Return the next skip link marked by `inspectSkipLinkScript` in \"unreachable\" mode, removing its\n * marker so the following call returns the one after it.\n */\nexport function takeUnreachableSkipLinkScript(): Element | null {\n\tconst marked = document.querySelector(\"[data-a11y-pulse-unreachable-skip-link]\");\n\n\tmarked?.removeAttribute(\"data-a11y-pulse-unreachable-skip-link\");\n\n\treturn marked;\n}\n\nexport type SkipLinkPageState = {\n\thref: string;\n\tscrollX: number;\n\tscrollY: number;\n\t/** `history.length` before the link was activated, to tell whether following it added an entry. */\n\thistoryLength: number;\n};\n\nexport function readPageStateScript(): SkipLinkPageState {\n\treturn {\n\t\thref: location.href,\n\t\tscrollX: window.scrollX,\n\t\tscrollY: window.scrollY,\n\t\thistoryLength: history.length,\n\t};\n}\n\n/**\n * Put the URL, the `:target` element and the scroll position back the way they were before a skip\n * link was activated, so whatever runs next sees the page as it was loaded.\n *\n * Following a fragment link adds a history entry, so the way back is to go back: that returns the\n * document to the entry it was on, which also resets `:target` (rewriting the URL with\n * `replaceState` does not). The entry that was added stays ahead in the history as a forward entry,\n * because nothing can remove one. When the URL changed without a new entry, or by more than its\n * fragment, the URL is rewritten in place instead and `:target` is left as it is.\n */\nexport function restorePageStateScript(state: SkipLinkPageState): Promise<void> {\n\tconst withoutFragment = (href: string): string => href.split(\"#\")[0] ?? href;\n\n\tconst rewrite = (): void => {\n\t\tif (location.href === state.href) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\thistory.replaceState(history.state, \"\", state.href);\n\t\t} catch {\n\t\t\t// Documents that cannot rewrite their URL (`about:blank`, sandboxed frames) keep the hash.\n\t\t}\n\t};\n\n\tconst scroll = (): void => {\n\t\twindow.scrollTo(state.scrollX, state.scrollY);\n\t};\n\n\tif (\n\t\tlocation.href === state.href ||\n\t\twithoutFragment(location.href) !== withoutFragment(state.href) ||\n\t\thistory.length !== state.historyLength + 1\n\t) {\n\t\trewrite();\n\t\tscroll();\n\n\t\treturn Promise.resolve();\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tlet settled = false;\n\n\t\tconst settle = (): void => {\n\t\t\tif (settled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsettled = true;\n\t\t\twindow.removeEventListener(\"popstate\", onPopState);\n\t\t\trewrite();\n\t\t\tscroll();\n\t\t\tresolve();\n\t\t};\n\n\t\t// The browser finishes a traversal (its own scroll restoration, and moving the point Tab\n\t\t// starts from) when it next renders, so wait that out instead of racing it. The timer is\n\t\t// for a page that is not being rendered and so never gets its frames.\n\t\tconst onPopState = (): void => {\n\t\t\trequestAnimationFrame(() => requestAnimationFrame(settle));\n\t\t\tsetTimeout(settle, 100);\n\t\t};\n\n\t\twindow.addEventListener(\"popstate\", onPopState);\n\t\t// A traversal that the page or the browser never completes must not hold the audit up.\n\t\tsetTimeout(settle, 1000);\n\t\thistory.back();\n\t});\n}\n\nexport function focusScript(el: Element | null): void {\n\t(el as HTMLElement | null)?.focus();\n}\n\n/**\n * Drop focus and put the point sequential focus navigation starts from back at the top of the\n * document, so the next Tab press reaches the first tab stop as it would on a freshly loaded page.\n * Blurring alone leaves that point where focus last was: on a skip link's target, mid-page.\n *\n * The point is moved by focusing a throwaway node. On a page with a positive `tabindex` the node\n * has to stay in front of the first element in the tab order until focus next moves, and removes\n * itself then; otherwise it is taken straight out again and nothing is left behind.\n */\nexport function resetFocusScript(): Promise<void> {\n\t// Must be a string literal inside this function: it is serialized into the page.\n\tconst anchorAttr = \"data-a11y-pulse-skip-link-focus-start\";\n\n\t// Following a fragment, or going back from one, moves the starting point when the browser next\n\t// renders. Resetting it before then would be undone, so let pending frames run first. The timer\n\t// is for a page that is not being rendered and so never gets its frames.\n\treturn new Promise((resolve) => {\n\t\tlet done = false;\n\n\t\tconst run = (): void => {\n\t\t\tif (done) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdone = true;\n\n\t\t\ttry {\n\t\t\t\treset();\n\t\t\t} finally {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t};\n\n\t\trequestAnimationFrame(() => requestAnimationFrame(run));\n\t\tsetTimeout(run, 100);\n\t});\n\n\tfunction reset(): void {\n\t\tlet active = document.activeElement;\n\n\t\twhile (active?.shadowRoot?.activeElement) {\n\t\t\tactive = active.shadowRoot.activeElement;\n\t\t}\n\n\t\t(active as HTMLElement | null)?.blur?.();\n\n\t\tfor (const leftover of Array.from(document.querySelectorAll(`[${anchorAttr}]`))) {\n\t\t\tleftover.remove();\n\t\t}\n\n\t\tconst root = document.documentElement;\n\t\tconst body = document.body;\n\n\t\tif (!root || !body) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst place = (parent: Node, before: Node | null): HTMLElement | null => {\n\t\t\tconst anchor = document.createElement(\"span\");\n\n\t\t\tanchor.tabIndex = -1;\n\t\t\tanchor.setAttribute(anchorAttr, \"\");\n\t\t\tanchor.setAttribute(\"aria-hidden\", \"true\");\n\t\t\tanchor.style.cssText = \"position:fixed;top:0;left:0;width:1px;height:1px;outline:none\";\n\n\t\t\ttry {\n\t\t\t\tparent.insertBefore(anchor, before);\n\t\t\t\tanchor.focus({ preventScroll: true });\n\t\t\t} catch {\n\t\t\t\t// A document that refuses the node is left as it is.\n\t\t\t}\n\n\t\t\tif (document.activeElement === anchor) {\n\t\t\t\treturn anchor;\n\t\t\t}\n\n\t\t\tanchor.remove();\n\n\t\t\treturn null;\n\t\t};\n\n\t\t// A positive tabindex puts its element ahead of everything else, lowest value first.\n\t\tlet first: Element | null = null;\n\t\tlet lowest = Number.POSITIVE_INFINITY;\n\n\t\tfor (const candidate of Array.from(document.querySelectorAll(\"[tabindex]\"))) {\n\t\t\tconst tabIndex = (candidate as HTMLElement).tabIndex;\n\n\t\t\tif (tabIndex <= 0 || tabIndex >= lowest) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tcandidate.matches(\":disabled\") ||\n\t\t\t\tcandidate.closest(\"[inert]\") ||\n\t\t\t\t(typeof candidate.checkVisibility === \"function\" &&\n\t\t\t\t\t!candidate.checkVisibility({ checkVisibilityCSS: true }))\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfirst = candidate;\n\t\t\tlowest = tabIndex;\n\t\t}\n\n\t\tif (first?.parentNode) {\n\t\t\tconst anchor = place(first.parentNode, first);\n\n\t\t\tif (anchor) {\n\t\t\t\tanchor.blur();\n\n\t\t\t\tconst cleanUp = (event: Event): void => {\n\t\t\t\t\tif (event.target !== anchor) {\n\t\t\t\t\t\tanchor.remove();\n\t\t\t\t\t\twindow.removeEventListener(\"focus\", cleanUp, true);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\twindow.addEventListener(\"focus\", cleanUp, true);\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Ahead of <body> first, so that a focusable <body> is still the first stop.\n\t\tconst places: Array<[Node, Node | null]> = [\n\t\t\t[root, body],\n\t\t\t[body, body.firstChild],\n\t\t];\n\n\t\tfor (const [parent, before] of places) {\n\t\t\tconst anchor = place(parent, before);\n\n\t\t\tif (anchor) {\n\t\t\t\tanchor.remove();\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";AAAA,SAAS,gCAAgC;AACzC,SAAS,aAAa,oBAAoB;;;ACkFnC,SAAS,sBACf,IACA,MACA,QAAQ,GACmB;AAG3B,QAAM,OAAO;AACb,QAAM,QAAQ,UAAU,IAAI;AAC5B,QAAM,MAAM,OAAO,IAAI;AAGvB,QAAM,KACL;AACD,QAAM,SACL;AACD,QAAM,OACL;AACD,QAAM,aAAa,IAAI;AAAA,IACtB;AAAA;AAAA,MAEC,GAAG,KAAK,MAAM,EAAE,cAAc,MAAM,iBAAiB,IAAI,IAAI,GAAG;AAAA;AAAA,MAEhE,GAAG,KAAK,2BAAwB,GAAG;AAAA;AAAA,MAEnC;AAAA,IACD,EAAE,KAAK,GAAG;AAAA,IACV;AAAA,EACD;AAEA,QAAM,aAAa;AAEnB,QAAM,aACL;AACD,QAAM,mBAAmB;AAEzB,WAAS,WAAW,M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,kBAAkB;AACvB,YAAM,EAAE,YAAY,IAAI,MAAM,QAAQ;AAAA,QACrC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,YAAM,UAAuC,CAAC;AAE9C,iBAAW,QAAQ,aAAa;AAC/B,cAAM,SAAS,MAAM,QAAQ,eAAe,6BAA6B;AAEzE,YAAI;AACH,kBAAQ,KAAK;AAAA,YACZ,UAAU,MAAM,QAAQ,SAAS,aAAa,MAAM;AAAA,YACpD,MAAM,aAAa,KAAK,IAAI;AAAA,YAC5B,UAAU,KAAK;AAAA,YACf,UAAU,KAAK;AAAA,YACf,QAAQ,KAAK;AAAA,UACd,CAAC;AAAA,QACF,UAAE;AACD,gBAAM,QAAQ,WAAW,MAAM;AAAA,QAChC;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,IAEA,YAAY;AACX,aAAO,QAAQ,SAAS,mBAAmB;AAAA,IAC5C;AAAA,IAEA,aAAa,OAAO;AACnB,aAAO,QAAQ,SAAS,wBAAwB,KAAK;AAAA,IACtD;AAAA,IAEA,aAAa;AACZ,aAAO,QAAQ,SAAS,gBAAgB;AAAA,IACzC;AAAA,IAEA,MAAM,kBAAkB,KAAK;AAC5B,YAAM,QAAQ,SAAS,aAAa,GAAG;AACvC,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,oBAAoB,CAAC;AAExE,aAAO,yBAAyB,SAAS,KAAK;AAAA,QAC7C,YAAY;AAAA,QACZ,aAAa;AAAA,MACd,CAAC;AAAA,IACF;AAAA,IAEA,WAAW,KAAK;AACf,aAAO,QAAQ,WAAW,GAAG;AAAA,IAC9B;AAAA,EACD;AACD;","names":["fragment","target","passed"]}
|
package/dist/result.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SkipLinkFocusPosition, SkipLinkUnreachableReason } from "./browser-scripts";
|
|
2
|
+
export type { SkipLinkFocusPosition, SkipLinkUnreachableReason };
|
|
3
|
+
export type SkipLinkFailureReason = "target-missing" | "target-hidden" | "activation-no-effect";
|
|
4
|
+
/** The element a skip link's fragment resolves to. */
|
|
5
|
+
export type SkipLinkTarget = {
|
|
6
|
+
/** Selector for the target, by `id` or `a[name]`. */
|
|
7
|
+
selector: string;
|
|
8
|
+
/** Truncated opening tag. */
|
|
9
|
+
html: string;
|
|
10
|
+
/** False when the target or one of its ancestors is not rendered, such as `display: none`. */
|
|
11
|
+
rendered: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Where keyboard focus was after a key press. */
|
|
14
|
+
export type SkipLinkFocusLanding = {
|
|
15
|
+
/** Where the focused element sits relative to the skip link and its target. */
|
|
16
|
+
position: SkipLinkFocusPosition;
|
|
17
|
+
/** Selector for the focused element, or null when nothing was focused. */
|
|
18
|
+
selector: string | null;
|
|
19
|
+
/** Truncated opening tag of the focused element, or null when nothing was focused. */
|
|
20
|
+
html: string | null;
|
|
21
|
+
};
|
|
2
22
|
export type SkipLinkElementResult = {
|
|
3
23
|
/** Selector for the skip-link element (see getSelector). */
|
|
4
24
|
selector: string;
|
|
@@ -12,15 +32,45 @@ export type SkipLinkElementResult = {
|
|
|
12
32
|
passed: boolean;
|
|
13
33
|
/** Why the candidate failed, or null when it passed. */
|
|
14
34
|
failureReason: SkipLinkFailureReason | null;
|
|
35
|
+
/** Text of the link, falling back to its `aria-label`. */
|
|
36
|
+
linkText?: string;
|
|
37
|
+
/** The element the fragment resolves to, or null when nothing in the page matches it. */
|
|
38
|
+
target?: SkipLinkTarget | null;
|
|
39
|
+
/** Where focus was once Enter had been pressed on the link. */
|
|
40
|
+
focusAfterEnter?: SkipLinkFocusLanding;
|
|
41
|
+
/**
|
|
42
|
+
* Where focus was after the follow-up Tab, which is only pressed when Enter did not visibly move
|
|
43
|
+
* focus. Null when it was not pressed.
|
|
44
|
+
*/
|
|
45
|
+
focusAfterTab?: SkipLinkFocusLanding | null;
|
|
15
46
|
/** PNG bytes of the focused skip link, clipped and padded. Only captured when it failed. */
|
|
16
47
|
screenshot?: Uint8Array;
|
|
17
48
|
};
|
|
49
|
+
/** A skip link that is in the document but can never receive keyboard focus. */
|
|
50
|
+
export type SkipLinkUnreachableResult = {
|
|
51
|
+
/** Selector for the skip-link element (see getSelector). */
|
|
52
|
+
selector: string;
|
|
53
|
+
/** Truncated opening tag. */
|
|
54
|
+
html: string;
|
|
55
|
+
/** The href fragment, e.g. "#main". */
|
|
56
|
+
fragment: string;
|
|
57
|
+
/** Text of the link, falling back to its `aria-label`. */
|
|
58
|
+
linkText: string;
|
|
59
|
+
/** Why the link cannot be focused. */
|
|
60
|
+
reason: SkipLinkUnreachableReason;
|
|
61
|
+
};
|
|
18
62
|
export type SkipLinkResult = {
|
|
19
63
|
/** Skip-link candidates found in the first tab stops. Empty when none were found. */
|
|
20
64
|
skipLinks: SkipLinkElementResult[];
|
|
65
|
+
/**
|
|
66
|
+
* Skip links that exist in the document but can never be focused. Only looked for when no skip
|
|
67
|
+
* link was reached by tabbing.
|
|
68
|
+
*/
|
|
69
|
+
unreachable: SkipLinkUnreachableResult[];
|
|
21
70
|
summary: {
|
|
22
71
|
found: number;
|
|
23
72
|
passed: number;
|
|
24
73
|
failed: number;
|
|
74
|
+
unreachable: number;
|
|
25
75
|
};
|
|
26
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a11y-pulse/skip-link-audit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "WCAG 2.4.1 Bypass Blocks audit that finds skip-link-like in-page anchors in the first tab stops and verifies that activating them moves keyboard focus.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@a11y-pulse/browser-adaptor": "*"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"happy-dom": "^21.0.
|
|
58
|
-
"puppeteer": "^25.
|
|
57
|
+
"happy-dom": "^21.0.4",
|
|
58
|
+
"puppeteer": "^25.16.0"
|
|
59
59
|
}
|
|
60
60
|
}
|