@a11y-pulse/browser-adaptor 0.7.0 → 0.8.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 +15 -1
- package/dist/chunk-WI4RV7YK.js +143 -0
- package/dist/chunk-WI4RV7YK.js.map +1 -0
- package/dist/dom.js +3 -138
- package/dist/dom.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/dist/stashed-elements.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install @a11y-pulse/browser-adaptor
|
|
|
20
20
|
|
|
21
21
|
| Entry | Contents |
|
|
22
22
|
| --- | --- |
|
|
23
|
-
| `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect`, `bufferedClip`, `contrastRatio`, `parseOpaqueRgb`, `relativeLuminance` |
|
|
23
|
+
| `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect`, `bufferedClip`, `contrastRatio`, `parseOpaqueRgb`, `relativeLuminance`, `stashedElementSelectors`, `releaseStashedElements` |
|
|
24
24
|
| `@a11y-pulse/browser-adaptor/puppeteer` | `PuppeteerAdaptor` |
|
|
25
25
|
| `@a11y-pulse/browser-adaptor/playwright` | `PlaywrightAdaptor` |
|
|
26
26
|
| `@a11y-pulse/browser-adaptor/dom` | `getSelector`, `truncateHtml` |
|
|
@@ -108,6 +108,20 @@ import { getSelector, truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
|
|
|
108
108
|
|
|
109
109
|
`getSelector` builds a compact selector for an element (intended to run in page context). `truncateHtml` shortens an element's opening tag for display in results.
|
|
110
110
|
|
|
111
|
+
A page script that collects many elements in one evaluate can leave them on `window` under a key of its own, then fetch selectors for only the ones it reports:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import { releaseStashedElements, stashedElementSelectors } from "@a11y-pulse/browser-adaptor";
|
|
115
|
+
|
|
116
|
+
const records = await adaptor.evaluate(collectScript, "__myAuditElements");
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const selectors = await stashedElementSelectors(adaptor, "__myAuditElements", [0, 4]);
|
|
120
|
+
} finally {
|
|
121
|
+
await releaseStashedElements(adaptor, "__myAuditElements");
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
111
125
|
## License
|
|
112
126
|
|
|
113
127
|
[MIT](./LICENSE.md). Use it however you like, including in commercial and competing products.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// src/get-selector.ts
|
|
2
|
+
function getSelector(root) {
|
|
3
|
+
const MAX_LENGTH = 128;
|
|
4
|
+
const esc = (value) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value;
|
|
5
|
+
const tagName = (node2) => node2.nodeType === 1 ? node2.nodeName.toLowerCase() : node2.nodeName.toUpperCase().replace(/^#/, "");
|
|
6
|
+
const rootOf = (element) => {
|
|
7
|
+
const node2 = element.getRootNode?.();
|
|
8
|
+
return node2 && typeof node2.querySelectorAll === "function" ? node2 : null;
|
|
9
|
+
};
|
|
10
|
+
const matchCount = (queryRoot2, selector) => {
|
|
11
|
+
try {
|
|
12
|
+
return queryRoot2.querySelectorAll(selector).length;
|
|
13
|
+
} catch {
|
|
14
|
+
return Number.POSITIVE_INFINITY;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const safeMatches = (element, selector) => {
|
|
18
|
+
try {
|
|
19
|
+
return typeof element.matches === "function" && element.matches(selector);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const idIsUnique = (element, id) => {
|
|
25
|
+
const queryRoot2 = rootOf(element);
|
|
26
|
+
return queryRoot2 === null || matchCount(queryRoot2, `#${esc(id)}`) === 1;
|
|
27
|
+
};
|
|
28
|
+
const classFeature = (cls) => ({
|
|
29
|
+
feature: `.${esc(cls)}`,
|
|
30
|
+
sharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls)
|
|
31
|
+
});
|
|
32
|
+
const rarestFeature = (element, queryRoot2) => {
|
|
33
|
+
const classes = Array.from(element.classList).slice(0, 8);
|
|
34
|
+
if (!queryRoot2) {
|
|
35
|
+
const cls = classes[0];
|
|
36
|
+
return cls === void 0 ? null : classFeature(cls);
|
|
37
|
+
}
|
|
38
|
+
let best = null;
|
|
39
|
+
let bestCount = Number.POSITIVE_INFINITY;
|
|
40
|
+
for (const cls of classes) {
|
|
41
|
+
const candidate = classFeature(cls);
|
|
42
|
+
if (!safeMatches(element, candidate.feature)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const count = matchCount(queryRoot2, candidate.feature);
|
|
46
|
+
if (count < bestCount) {
|
|
47
|
+
best = candidate;
|
|
48
|
+
bestCount = count;
|
|
49
|
+
}
|
|
50
|
+
if (count === 1) {
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const href = typeof element.getAttribute === "function" ? element.getAttribute("href") : null;
|
|
55
|
+
if (href && href.length <= 100 && !/["\\?]/.test(href)) {
|
|
56
|
+
const feature = `[href="${href}"]`;
|
|
57
|
+
if (safeMatches(element, feature) && matchCount(queryRoot2, feature) < bestCount) {
|
|
58
|
+
return {
|
|
59
|
+
feature,
|
|
60
|
+
sharedBy: (sibling) => typeof sibling.getAttribute === "function" && sibling.getAttribute("href") === href
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return best;
|
|
65
|
+
};
|
|
66
|
+
const positionAmongSiblings = (element, sharedBy) => {
|
|
67
|
+
const siblings = element.parentNode?.children;
|
|
68
|
+
if (!siblings) {
|
|
69
|
+
return { nth: 0, ambiguous: false };
|
|
70
|
+
}
|
|
71
|
+
let nth = 0;
|
|
72
|
+
let count = 0;
|
|
73
|
+
let shared = 0;
|
|
74
|
+
for (const sibling of Array.from(siblings)) {
|
|
75
|
+
if (sibling.nodeName !== element.nodeName) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
count++;
|
|
79
|
+
if (sibling === element) {
|
|
80
|
+
nth = count;
|
|
81
|
+
}
|
|
82
|
+
if (sharedBy(sibling)) {
|
|
83
|
+
shared++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { nth, ambiguous: shared > 1 };
|
|
87
|
+
};
|
|
88
|
+
const segmentFor = (element, queryRoot2) => {
|
|
89
|
+
if (element.id && idIsUnique(element, element.id)) {
|
|
90
|
+
return { segment: `#${esc(element.id)}`, anchored: true };
|
|
91
|
+
}
|
|
92
|
+
const feature = rarestFeature(element, queryRoot2);
|
|
93
|
+
let segment = tagName(element) + (feature === null ? "" : feature.feature);
|
|
94
|
+
const { nth, ambiguous } = positionAmongSiblings(
|
|
95
|
+
element,
|
|
96
|
+
feature === null ? () => true : feature.sharedBy
|
|
97
|
+
);
|
|
98
|
+
if (ambiguous && nth > 0) {
|
|
99
|
+
segment += `:nth-of-type(${nth})`;
|
|
100
|
+
}
|
|
101
|
+
return { segment, anchored: false };
|
|
102
|
+
};
|
|
103
|
+
const degradedSegmentFor = (element) => {
|
|
104
|
+
let segment = tagName(element);
|
|
105
|
+
const { nth, ambiguous } = positionAmongSiblings(element, () => true);
|
|
106
|
+
if (ambiguous && nth > 0) {
|
|
107
|
+
segment += `:nth-of-type(${nth})`;
|
|
108
|
+
}
|
|
109
|
+
return segment;
|
|
110
|
+
};
|
|
111
|
+
const segments = [];
|
|
112
|
+
let node = root;
|
|
113
|
+
const queryRoot = root && root.nodeType === 1 ? rootOf(root) : null;
|
|
114
|
+
try {
|
|
115
|
+
while (node && node.nodeType === 1) {
|
|
116
|
+
const element = node;
|
|
117
|
+
let { segment, anchored } = segmentFor(element, queryRoot);
|
|
118
|
+
const joinedWith = (candidate) => segments.length ? candidate.length + 1 + segments.join(">").length : candidate.length;
|
|
119
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
120
|
+
segment = degradedSegmentFor(element);
|
|
121
|
+
anchored = false;
|
|
122
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
segments.unshift(segment);
|
|
127
|
+
if (anchored) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (queryRoot && matchCount(queryRoot, segments.join(">")) === 1) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
node = element.parentNode;
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
return segments.join(">");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
getSelector
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=chunk-WI4RV7YK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/get-selector.ts"],"sourcesContent":["/**\n * Build a compact, hopefully-unique selector for any given element on the page. This function is\n * serialized and run in the page context, so it must not reference any symbols outside its own\n * scope.\n *\n * Mirrors axe-core's approach: each level contributes the fewest features that discriminate the\n * element (a unique id, the rarest single class, or an :nth-of-type position), and the walk stops\n * as soon as the joined selector matches exactly one element. Selectors stay short because of that\n * early stop, not because of truncation; the length budget is only a backstop.\n */\nexport function getSelector(root: Node | null): string {\n\tconst MAX_LENGTH = 128;\n\n\tconst esc = (value: string): string =>\n\t\ttypeof CSS !== \"undefined\" && typeof CSS.escape === \"function\" ? CSS.escape(value) : value;\n\n\tconst tagName = (node: Node): string =>\n\t\tnode.nodeType === 1\n\t\t\t? node.nodeName.toLowerCase()\n\t\t\t: node.nodeName.toUpperCase().replace(/^#/, \"\");\n\n\t// A querySelectorAll-capable root (Document or ShadowRoot) for the element, used to confirm\n\t// uniqueness and class rarity. Absent on the plain objects used in the serialisation unit tests,\n\t// where we trust ids and walk to the top instead of stopping early.\n\tconst rootOf = (element: Element): ParentNode | null => {\n\t\tconst node = (element as Element & { getRootNode?: () => Node }).getRootNode?.();\n\n\t\treturn node && typeof (node as ParentNode).querySelectorAll === \"function\"\n\t\t\t? (node as ParentNode)\n\t\t\t: null;\n\t};\n\n\tconst matchCount = (queryRoot: ParentNode, selector: string): number => {\n\t\ttry {\n\t\t\treturn queryRoot.querySelectorAll(selector).length;\n\t\t} catch {\n\t\t\t// A selector that fails to parse can't be relied on.\n\t\t\treturn Number.POSITIVE_INFINITY;\n\t\t}\n\t};\n\n\t// A candidate feature is only usable if it actually selects this element; an escaping or engine\n\t// mismatch (e.g. CSS string escapes in an attribute value) could otherwise produce a selector\n\t// that matches nothing. Or a different element entirely.\n\tconst safeMatches = (element: Element, selector: string): boolean => {\n\t\ttry {\n\t\t\treturn typeof element.matches === \"function\" && element.matches(selector);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t};\n\n\tconst idIsUnique = (element: Element, id: string): boolean => {\n\t\tconst queryRoot = rootOf(element);\n\n\t\treturn queryRoot === null || matchCount(queryRoot, `#${esc(id)}`) === 1;\n\t};\n\n\t// A discriminating feature for one level of the selector: its CSS text plus a predicate telling\n\t// whether a sibling would match the same feature (used to decide if an :nth-of-type pin is still\n\t// needed).\n\ttype Feature = {\n\t\tfeature: string;\n\t\tsharedBy: (sibling: Element) => boolean;\n\t};\n\n\tconst classFeature = (cls: string): Feature => ({\n\t\tfeature: `.${esc(cls)}`,\n\t\tsharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls),\n\t});\n\n\t// The single feature that narrows the element down the most: the class or href attribute with the\n\t// fewest matches in the root. Hrefs break ties between structurally-identical content blocks,\n\t// where classes and :nth-of-type (which only pins position within one parent) cannot. Without a\n\t// queryable root there is no rarity information, so the first class stands in.\n\tconst rarestFeature = (element: Element, queryRoot: ParentNode | null): Feature | null => {\n\t\tconst classes = Array.from(element.classList).slice(0, 8);\n\n\t\tif (!queryRoot) {\n\t\t\tconst cls = classes[0];\n\n\t\t\treturn cls === undefined ? null : classFeature(cls);\n\t\t}\n\n\t\tlet best: Feature | null = null;\n\t\tlet bestCount = Number.POSITIVE_INFINITY;\n\n\t\tfor (const cls of classes) {\n\t\t\tconst candidate = classFeature(cls);\n\n\t\t\tif (!safeMatches(element, candidate.feature)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst count = matchCount(queryRoot, candidate.feature);\n\n\t\t\tif (count < bestCount) {\n\t\t\t\tbest = candidate;\n\t\t\t\tbestCount = count;\n\t\t\t}\n\n\t\t\tif (count === 1) {\n\t\t\t\treturn best;\n\t\t\t}\n\t\t}\n\n\t\tconst href = typeof element.getAttribute === \"function\" ? element.getAttribute(\"href\") : null;\n\n\t\t// Skip hrefs with characters that change meaning inside a CSS string (quotes, backslashes), and\n\t\t// query strings, which are too volatile across runs to pin a selector to. Fragments (#main)\n\t\t// stay eligible. Skip links make stable discriminators.\n\t\tif (href && href.length <= 100 && !/[\"\\\\?]/.test(href)) {\n\t\t\tconst feature = `[href=\"${href}\"]`;\n\n\t\t\tif (safeMatches(element, feature) && matchCount(queryRoot, feature) < bestCount) {\n\t\t\t\treturn {\n\t\t\t\t\tfeature,\n\t\t\t\t\tsharedBy: (sibling) =>\n\t\t\t\t\t\ttypeof sibling.getAttribute === \"function\" && sibling.getAttribute(\"href\") === href,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn best;\n\t};\n\n\t// The element's 1-based position among same-tag siblings, and whether the chosen feature fails to\n\t// discriminate it from them (so the segment needs an :nth-of-type pin). Siblings are absent on\n\t// the serialisation test nodes. There we skip the pin.\n\tconst positionAmongSiblings = (\n\t\telement: Element,\n\t\tsharedBy: (sibling: Element) => boolean,\n\t): { nth: number; ambiguous: boolean } => {\n\t\tconst siblings = (element.parentNode as ParentNode | null)?.children;\n\n\t\tif (!siblings) {\n\t\t\treturn { nth: 0, ambiguous: false };\n\t\t}\n\n\t\tlet nth = 0;\n\t\tlet count = 0;\n\t\tlet shared = 0;\n\n\t\tfor (const sibling of Array.from(siblings)) {\n\t\t\tif (sibling.nodeName !== element.nodeName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcount++;\n\n\t\t\tif (sibling === element) {\n\t\t\t\tnth = count;\n\t\t\t}\n\n\t\t\tif (sharedBy(sibling)) {\n\t\t\t\tshared++;\n\t\t\t}\n\t\t}\n\n\t\treturn { nth, ambiguous: shared > 1 };\n\t};\n\n\tconst segmentFor = (\n\t\telement: Element,\n\t\tqueryRoot: ParentNode | null,\n\t): { segment: string; anchored: boolean } => {\n\t\t// Only treat an id as an absolute anchor when it actually resolves to a single element: pages\n\t\t// with duplicate ids would otherwise yield a selector (e.g. \"#dup>a\") that matches several\n\t\t// elements.\n\t\tif (element.id && idIsUnique(element, element.id)) {\n\t\t\treturn { segment: `#${esc(element.id)}`, anchored: true };\n\t\t}\n\n\t\tconst feature = rarestFeature(element, queryRoot);\n\t\tlet segment = tagName(element) + (feature === null ? \"\" : feature.feature);\n\n\t\t// When same-tag siblings share the chosen feature, pin the position so the segment selects\n\t\t// exactly this element rather than all of them.\n\t\tconst { nth, ambiguous } = positionAmongSiblings(\n\t\t\telement,\n\t\t\tfeature === null ? () => true : feature.sharedBy,\n\t\t);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn { segment, anchored: false };\n\t};\n\n\t// A minimal segment for when a level's full segment would blow the budget (e.g. an enormous class\n\t// name or a long href): just the tag, pinned by position when same-tag siblings would make the\n\t// bare tag ambiguous.\n\tconst degradedSegmentFor = (element: Element): string => {\n\t\tlet segment = tagName(element);\n\n\t\tconst { nth, ambiguous } = positionAmongSiblings(element, () => true);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn segment;\n\t};\n\n\tconst segments: string[] = [];\n\tlet node: Node | null = root;\n\tconst queryRoot = root && root.nodeType === 1 ? rootOf(root as Element) : null;\n\n\ttry {\n\t\t// Walk only element nodes. Stopping at the first non-element parent (the document, or a\n\t\t// ShadowRoot when the target is inside an open shadow root) keeps the selector within its tree\n\t\t// and avoids reading `classList` off a node that has none.\n\t\twhile (node && node.nodeType === 1) {\n\t\t\tconst element = node as Element;\n\t\t\tlet { segment, anchored } = segmentFor(element, queryRoot);\n\n\t\t\t// Keep within the budget (the +1 accounts for the \">\" that would join this segment to the\n\t\t\t// rest). A level whose full segment doesn't fit is degraded to tag + position rather than\n\t\t\t// discarded, so ancestor context is never lost to one long feature.\n\t\t\tconst joinedWith = (candidate: string): number =>\n\t\t\t\tsegments.length ? candidate.length + 1 + segments.join(\">\").length : candidate.length;\n\n\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\tsegment = degradedSegmentFor(element);\n\t\t\t\tanchored = false;\n\n\t\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsegments.unshift(segment);\n\n\t\t\tif (anchored) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Stop as soon as the selector already identifies a single element. This, not truncation, is\n\t\t\t// what keeps selectors short.\n\t\t\tif (queryRoot && matchCount(queryRoot, segments.join(\">\")) === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tnode = element.parentNode;\n\t\t}\n\t} catch {\n\t\t// A malformed node tree must never crash the audit; return what we have.\n\t}\n\n\treturn segments.join(\">\");\n}\n"],"mappings":";AAUO,SAAS,YAAY,MAA2B;AACtD,QAAM,aAAa;AAEnB,QAAM,MAAM,CAAC,UACZ,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,aAAa,IAAI,OAAO,KAAK,IAAI;AAEtF,QAAM,UAAU,CAACA,UAChBA,MAAK,aAAa,IACfA,MAAK,SAAS,YAAY,IAC1BA,MAAK,SAAS,YAAY,EAAE,QAAQ,MAAM,EAAE;AAKhD,QAAM,SAAS,CAAC,YAAwC;AACvD,UAAMA,QAAQ,QAAmD,cAAc;AAE/E,W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== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value;
|
|
5
|
-
const tagName = (node2) => node2.nodeType === 1 ? node2.nodeName.toLowerCase() : node2.nodeName.toUpperCase().replace(/^#/, "");
|
|
6
|
-
const rootOf = (element) => {
|
|
7
|
-
const node2 = element.getRootNode?.();
|
|
8
|
-
return node2 && typeof node2.querySelectorAll === "function" ? node2 : null;
|
|
9
|
-
};
|
|
10
|
-
const matchCount = (queryRoot2, selector) => {
|
|
11
|
-
try {
|
|
12
|
-
return queryRoot2.querySelectorAll(selector).length;
|
|
13
|
-
} catch {
|
|
14
|
-
return Number.POSITIVE_INFINITY;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const safeMatches = (element, selector) => {
|
|
18
|
-
try {
|
|
19
|
-
return typeof element.matches === "function" && element.matches(selector);
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const idIsUnique = (element, id) => {
|
|
25
|
-
const queryRoot2 = rootOf(element);
|
|
26
|
-
return queryRoot2 === null || matchCount(queryRoot2, `#${esc(id)}`) === 1;
|
|
27
|
-
};
|
|
28
|
-
const classFeature = (cls) => ({
|
|
29
|
-
feature: `.${esc(cls)}`,
|
|
30
|
-
sharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls)
|
|
31
|
-
});
|
|
32
|
-
const rarestFeature = (element, queryRoot2) => {
|
|
33
|
-
const classes = Array.from(element.classList).slice(0, 8);
|
|
34
|
-
if (!queryRoot2) {
|
|
35
|
-
const cls = classes[0];
|
|
36
|
-
return cls === void 0 ? null : classFeature(cls);
|
|
37
|
-
}
|
|
38
|
-
let best = null;
|
|
39
|
-
let bestCount = Number.POSITIVE_INFINITY;
|
|
40
|
-
for (const cls of classes) {
|
|
41
|
-
const candidate = classFeature(cls);
|
|
42
|
-
if (!safeMatches(element, candidate.feature)) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const count = matchCount(queryRoot2, candidate.feature);
|
|
46
|
-
if (count < bestCount) {
|
|
47
|
-
best = candidate;
|
|
48
|
-
bestCount = count;
|
|
49
|
-
}
|
|
50
|
-
if (count === 1) {
|
|
51
|
-
return best;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const href = typeof element.getAttribute === "function" ? element.getAttribute("href") : null;
|
|
55
|
-
if (href && href.length <= 100 && !/["\\?]/.test(href)) {
|
|
56
|
-
const feature = `[href="${href}"]`;
|
|
57
|
-
if (safeMatches(element, feature) && matchCount(queryRoot2, feature) < bestCount) {
|
|
58
|
-
return {
|
|
59
|
-
feature,
|
|
60
|
-
sharedBy: (sibling) => typeof sibling.getAttribute === "function" && sibling.getAttribute("href") === href
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return best;
|
|
65
|
-
};
|
|
66
|
-
const positionAmongSiblings = (element, sharedBy) => {
|
|
67
|
-
const siblings = element.parentNode?.children;
|
|
68
|
-
if (!siblings) {
|
|
69
|
-
return { nth: 0, ambiguous: false };
|
|
70
|
-
}
|
|
71
|
-
let nth = 0;
|
|
72
|
-
let count = 0;
|
|
73
|
-
let shared = 0;
|
|
74
|
-
for (const sibling of Array.from(siblings)) {
|
|
75
|
-
if (sibling.nodeName !== element.nodeName) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
count++;
|
|
79
|
-
if (sibling === element) {
|
|
80
|
-
nth = count;
|
|
81
|
-
}
|
|
82
|
-
if (sharedBy(sibling)) {
|
|
83
|
-
shared++;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return { nth, ambiguous: shared > 1 };
|
|
87
|
-
};
|
|
88
|
-
const segmentFor = (element, queryRoot2) => {
|
|
89
|
-
if (element.id && idIsUnique(element, element.id)) {
|
|
90
|
-
return { segment: `#${esc(element.id)}`, anchored: true };
|
|
91
|
-
}
|
|
92
|
-
const feature = rarestFeature(element, queryRoot2);
|
|
93
|
-
let segment = tagName(element) + (feature === null ? "" : feature.feature);
|
|
94
|
-
const { nth, ambiguous } = positionAmongSiblings(
|
|
95
|
-
element,
|
|
96
|
-
feature === null ? () => true : feature.sharedBy
|
|
97
|
-
);
|
|
98
|
-
if (ambiguous && nth > 0) {
|
|
99
|
-
segment += `:nth-of-type(${nth})`;
|
|
100
|
-
}
|
|
101
|
-
return { segment, anchored: false };
|
|
102
|
-
};
|
|
103
|
-
const degradedSegmentFor = (element) => {
|
|
104
|
-
let segment = tagName(element);
|
|
105
|
-
const { nth, ambiguous } = positionAmongSiblings(element, () => true);
|
|
106
|
-
if (ambiguous && nth > 0) {
|
|
107
|
-
segment += `:nth-of-type(${nth})`;
|
|
108
|
-
}
|
|
109
|
-
return segment;
|
|
110
|
-
};
|
|
111
|
-
const segments = [];
|
|
112
|
-
let node = root;
|
|
113
|
-
const queryRoot = root && root.nodeType === 1 ? rootOf(root) : null;
|
|
114
|
-
try {
|
|
115
|
-
while (node && node.nodeType === 1) {
|
|
116
|
-
const element = node;
|
|
117
|
-
let { segment, anchored } = segmentFor(element, queryRoot);
|
|
118
|
-
const joinedWith = (candidate) => segments.length ? candidate.length + 1 + segments.join(">").length : candidate.length;
|
|
119
|
-
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
120
|
-
segment = degradedSegmentFor(element);
|
|
121
|
-
anchored = false;
|
|
122
|
-
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
segments.unshift(segment);
|
|
127
|
-
if (anchored) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
if (queryRoot && matchCount(queryRoot, segments.join(">")) === 1) {
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
node = element.parentNode;
|
|
134
|
-
}
|
|
135
|
-
} catch {
|
|
136
|
-
}
|
|
137
|
-
return segments.join(">");
|
|
138
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
getSelector
|
|
3
|
+
} from "./chunk-WI4RV7YK.js";
|
|
139
4
|
|
|
140
5
|
// src/truncate-html.ts
|
|
141
6
|
var DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/get-selector.ts","../src/truncate-html.ts"],"sourcesContent":["/**\n * Build a compact, hopefully-unique selector for any given element on the page. This function is\n * serialized and run in the page context, so it must not reference any symbols outside its own\n * scope.\n *\n * Mirrors axe-core's approach: each level contributes the fewest features that discriminate the\n * element (a unique id, the rarest single class, or an :nth-of-type position), and the walk stops\n * as soon as the joined selector matches exactly one element. Selectors stay short because of that\n * early stop, not because of truncation; the length budget is only a backstop.\n */\nexport function getSelector(root: Node | null): string {\n\tconst MAX_LENGTH = 128;\n\n\tconst esc = (value: string): string =>\n\t\ttypeof CSS !== \"undefined\" && typeof CSS.escape === \"function\" ? CSS.escape(value) : value;\n\n\tconst tagName = (node: Node): string =>\n\t\tnode.nodeType === 1\n\t\t\t? node.nodeName.toLowerCase()\n\t\t\t: node.nodeName.toUpperCase().replace(/^#/, \"\");\n\n\t// A querySelectorAll-capable root (Document or ShadowRoot) for the element, used to confirm\n\t// uniqueness and class rarity. Absent on the plain objects used in the serialisation unit tests,\n\t// where we trust ids and walk to the top instead of stopping early.\n\tconst rootOf = (element: Element): ParentNode | null => {\n\t\tconst node = (element as Element & { getRootNode?: () => Node }).getRootNode?.();\n\n\t\treturn node && typeof (node as ParentNode).querySelectorAll === \"function\"\n\t\t\t? (node as ParentNode)\n\t\t\t: null;\n\t};\n\n\tconst matchCount = (queryRoot: ParentNode, selector: string): number => {\n\t\ttry {\n\t\t\treturn queryRoot.querySelectorAll(selector).length;\n\t\t} catch {\n\t\t\t// A selector that fails to parse can't be relied on.\n\t\t\treturn Number.POSITIVE_INFINITY;\n\t\t}\n\t};\n\n\t// A candidate feature is only usable if it actually selects this element; an escaping or engine\n\t// mismatch (e.g. CSS string escapes in an attribute value) could otherwise produce a selector\n\t// that matches nothing. Or a different element entirely.\n\tconst safeMatches = (element: Element, selector: string): boolean => {\n\t\ttry {\n\t\t\treturn typeof element.matches === \"function\" && element.matches(selector);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t};\n\n\tconst idIsUnique = (element: Element, id: string): boolean => {\n\t\tconst queryRoot = rootOf(element);\n\n\t\treturn queryRoot === null || matchCount(queryRoot, `#${esc(id)}`) === 1;\n\t};\n\n\t// A discriminating feature for one level of the selector: its CSS text plus a predicate telling\n\t// whether a sibling would match the same feature (used to decide if an :nth-of-type pin is still\n\t// needed).\n\ttype Feature = {\n\t\tfeature: string;\n\t\tsharedBy: (sibling: Element) => boolean;\n\t};\n\n\tconst classFeature = (cls: string): Feature => ({\n\t\tfeature: `.${esc(cls)}`,\n\t\tsharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls),\n\t});\n\n\t// The single feature that narrows the element down the most: the class or href attribute with the\n\t// fewest matches in the root. Hrefs break ties between structurally-identical content blocks,\n\t// where classes and :nth-of-type (which only pins position within one parent) cannot. Without a\n\t// queryable root there is no rarity information, so the first class stands in.\n\tconst rarestFeature = (element: Element, queryRoot: ParentNode | null): Feature | null => {\n\t\tconst classes = Array.from(element.classList).slice(0, 8);\n\n\t\tif (!queryRoot) {\n\t\t\tconst cls = classes[0];\n\n\t\t\treturn cls === undefined ? null : classFeature(cls);\n\t\t}\n\n\t\tlet best: Feature | null = null;\n\t\tlet bestCount = Number.POSITIVE_INFINITY;\n\n\t\tfor (const cls of classes) {\n\t\t\tconst candidate = classFeature(cls);\n\n\t\t\tif (!safeMatches(element, candidate.feature)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst count = matchCount(queryRoot, candidate.feature);\n\n\t\t\tif (count < bestCount) {\n\t\t\t\tbest = candidate;\n\t\t\t\tbestCount = count;\n\t\t\t}\n\n\t\t\tif (count === 1) {\n\t\t\t\treturn best;\n\t\t\t}\n\t\t}\n\n\t\tconst href = typeof element.getAttribute === \"function\" ? element.getAttribute(\"href\") : null;\n\n\t\t// Skip hrefs with characters that change meaning inside a CSS string (quotes, backslashes), and\n\t\t// query strings, which are too volatile across runs to pin a selector to. Fragments (#main)\n\t\t// stay eligible. Skip links make stable discriminators.\n\t\tif (href && href.length <= 100 && !/[\"\\\\?]/.test(href)) {\n\t\t\tconst feature = `[href=\"${href}\"]`;\n\n\t\t\tif (safeMatches(element, feature) && matchCount(queryRoot, feature) < bestCount) {\n\t\t\t\treturn {\n\t\t\t\t\tfeature,\n\t\t\t\t\tsharedBy: (sibling) =>\n\t\t\t\t\t\ttypeof sibling.getAttribute === \"function\" && sibling.getAttribute(\"href\") === href,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn best;\n\t};\n\n\t// The element's 1-based position among same-tag siblings, and whether the chosen feature fails to\n\t// discriminate it from them (so the segment needs an :nth-of-type pin). Siblings are absent on\n\t// the serialisation test nodes. There we skip the pin.\n\tconst positionAmongSiblings = (\n\t\telement: Element,\n\t\tsharedBy: (sibling: Element) => boolean,\n\t): { nth: number; ambiguous: boolean } => {\n\t\tconst siblings = (element.parentNode as ParentNode | null)?.children;\n\n\t\tif (!siblings) {\n\t\t\treturn { nth: 0, ambiguous: false };\n\t\t}\n\n\t\tlet nth = 0;\n\t\tlet count = 0;\n\t\tlet shared = 0;\n\n\t\tfor (const sibling of Array.from(siblings)) {\n\t\t\tif (sibling.nodeName !== element.nodeName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcount++;\n\n\t\t\tif (sibling === element) {\n\t\t\t\tnth = count;\n\t\t\t}\n\n\t\t\tif (sharedBy(sibling)) {\n\t\t\t\tshared++;\n\t\t\t}\n\t\t}\n\n\t\treturn { nth, ambiguous: shared > 1 };\n\t};\n\n\tconst segmentFor = (\n\t\telement: Element,\n\t\tqueryRoot: ParentNode | null,\n\t): { segment: string; anchored: boolean } => {\n\t\t// Only treat an id as an absolute anchor when it actually resolves to a single element: pages\n\t\t// with duplicate ids would otherwise yield a selector (e.g. \"#dup>a\") that matches several\n\t\t// elements.\n\t\tif (element.id && idIsUnique(element, element.id)) {\n\t\t\treturn { segment: `#${esc(element.id)}`, anchored: true };\n\t\t}\n\n\t\tconst feature = rarestFeature(element, queryRoot);\n\t\tlet segment = tagName(element) + (feature === null ? \"\" : feature.feature);\n\n\t\t// When same-tag siblings share the chosen feature, pin the position so the segment selects\n\t\t// exactly this element rather than all of them.\n\t\tconst { nth, ambiguous } = positionAmongSiblings(\n\t\t\telement,\n\t\t\tfeature === null ? () => true : feature.sharedBy,\n\t\t);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn { segment, anchored: false };\n\t};\n\n\t// A minimal segment for when a level's full segment would blow the budget (e.g. an enormous class\n\t// name or a long href): just the tag, pinned by position when same-tag siblings would make the\n\t// bare tag ambiguous.\n\tconst degradedSegmentFor = (element: Element): string => {\n\t\tlet segment = tagName(element);\n\n\t\tconst { nth, ambiguous } = positionAmongSiblings(element, () => true);\n\n\t\tif (ambiguous && nth > 0) {\n\t\t\tsegment += `:nth-of-type(${nth})`;\n\t\t}\n\n\t\treturn segment;\n\t};\n\n\tconst segments: string[] = [];\n\tlet node: Node | null = root;\n\tconst queryRoot = root && root.nodeType === 1 ? rootOf(root as Element) : null;\n\n\ttry {\n\t\t// Walk only element nodes. Stopping at the first non-element parent (the document, or a\n\t\t// ShadowRoot when the target is inside an open shadow root) keeps the selector within its tree\n\t\t// and avoids reading `classList` off a node that has none.\n\t\twhile (node && node.nodeType === 1) {\n\t\t\tconst element = node as Element;\n\t\t\tlet { segment, anchored } = segmentFor(element, queryRoot);\n\n\t\t\t// Keep within the budget (the +1 accounts for the \">\" that would join this segment to the\n\t\t\t// rest). A level whose full segment doesn't fit is degraded to tag + position rather than\n\t\t\t// discarded, so ancestor context is never lost to one long feature.\n\t\t\tconst joinedWith = (candidate: string): number =>\n\t\t\t\tsegments.length ? candidate.length + 1 + segments.join(\">\").length : candidate.length;\n\n\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\tsegment = degradedSegmentFor(element);\n\t\t\t\tanchored = false;\n\n\t\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsegments.unshift(segment);\n\n\t\t\tif (anchored) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Stop as soon as the selector already identifies a single element. This, not truncation, is\n\t\t\t// what keeps selectors short.\n\t\t\tif (queryRoot && matchCount(queryRoot, segments.join(\">\")) === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tnode = element.parentNode;\n\t\t}\n\t} catch {\n\t\t// A malformed node tree must never crash the audit; return what we have.\n\t}\n\n\treturn segments.join(\">\");\n}\n","const DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;\nconst DEFAULT_MAX_LENGTH = 300;\nconst ELLIPSIS = \"...\";\n\nexport type TruncateHtmlOptions = {\n\tmaxAttributeValueLength?: number;\n\tmaxLength?: number;\n};\n\n/**\n * Given an element's outerHTML, produce a truncated version suitable for display in results. For\n * memory efficiency, pass a shallow outerHTML i.e. `Node.cloneNode(false).outerHTML`.\n */\nexport function truncateHtml(html: string, options: TruncateHtmlOptions = {}): string {\n\tif (!html) {\n\t\treturn \"\";\n\t}\n\n\tconst maxAttributeValueLength =\n\t\toptions.maxAttributeValueLength ?? DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH;\n\tconst maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;\n\n\t// Keep only the opening tag\n\tconst closingBracket = html.indexOf(\">\");\n\tconst openingTag = closingBracket === -1 ? html : html.slice(0, closingBracket + 1);\n\n\t// Shorten long quoted attribute values, preserving the quote style.\n\tconst trimmed = openingTag.replace(\n\t\t/=([\"'])([\\s\\S]*?)\\1/g,\n\t\t(match, quote: string, value: string) => {\n\t\t\tif (value.length <= maxAttributeValueLength) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\treturn `=${quote}${value.slice(0, maxAttributeValueLength)}${ELLIPSIS}${quote}`;\n\t\t},\n\t);\n\n\tif (trimmed.length > maxLength) {\n\t\treturn `${trimmed.slice(0, maxLength)}${ELLIPSIS}`;\n\t}\n\n\treturn trimmed;\n}\n"],"mappings":";AAUO,SAAS,YAAY,MAA2B;AACtD,QAAM,aAAa;AAEnB,QAAM,MAAM,CAAC,UACZ,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,aAAa,IAAI,OAAO,KAAK,IAAI;AAEtF,QAAM,UAAU,CAACA,UAChBA,MAAK,aAAa,IACfA,MAAK,SAAS,YAAY,IAC1BA,MAAK,SAAS,YAAY,EAAE,QAAQ,MAAM,EAAE;AAKhD,QAAM,SAAS,CAAC,YAAwC;AACvD,UAAMA,QAAQ,QAAmD,cAAc;AAE/E,WAAOA,SAAQ,OAAQA,MAAoB,qBAAqB,aAC5DA,QACD;AAAA,EACJ;AAEA,QAAM,aAAa,CAACC,YAAuB,aAA6B;AACvE,QAAI;AACH,aAAOA,WAAU,iBAAiB,QAAQ,EAAE;AAAA,IAC7C,QAAQ;AAEP,aAAO,OAAO;AAAA,IACf;AAAA,EACD;AAKA,QAAM,cAAc,CAAC,SAAkB,aAA8B;AACpE,QAAI;AACH,aAAO,OAAO,QAAQ,YAAY,cAAc,QAAQ,QAAQ,QAAQ;AAAA,IACzE,QAAQ;AACP,aAAO;AAAA,IACR;AAAA,EACD;AAEA,QAAM,aAAa,CAAC,SAAkB,OAAwB;AAC7D,UAAMA,aAAY,OAAO,OAAO;AAEhC,WAAOA,eAAc,QAAQ,WAAWA,YAAW,IAAI,IAAI,EAAE,CAAC,EAAE,MAAM;AAAA,EACvE;AAUA,QAAM,eAAe,CAAC,SAA0B;AAAA,IAC/C,SAAS,IAAI,IAAI,GAAG,CAAC;AAAA,IACrB,UAAU,CAAC,YAAY,MAAM,KAAK,QAAQ,aAAa,CAAC,CAAC,EAAE,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;\nconst DEFAULT_MAX_LENGTH = 300;\nconst ELLIPSIS = \"...\";\n\nexport type TruncateHtmlOptions = {\n\tmaxAttributeValueLength?: number;\n\tmaxLength?: number;\n};\n\n/**\n * Given an element's outerHTML, produce a truncated version suitable for display in results. For\n * memory efficiency, pass a shallow outerHTML i.e. `Node.cloneNode(false).outerHTML`.\n */\nexport function truncateHtml(html: string, options: TruncateHtmlOptions = {}): string {\n\tif (!html) {\n\t\treturn \"\";\n\t}\n\n\tconst maxAttributeValueLength =\n\t\toptions.maxAttributeValueLength ?? DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH;\n\tconst maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;\n\n\t// Keep only the opening tag\n\tconst closingBracket = html.indexOf(\">\");\n\tconst openingTag = closingBracket === -1 ? html : html.slice(0, closingBracket + 1);\n\n\t// Shorten long quoted attribute values, preserving the quote style.\n\tconst trimmed = openingTag.replace(\n\t\t/=([\"'])([\\s\\S]*?)\\1/g,\n\t\t(match, quote: string, value: string) => {\n\t\t\tif (value.length <= maxAttributeValueLength) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\treturn `=${quote}${value.slice(0, maxAttributeValueLength)}${ELLIPSIS}${quote}`;\n\t\t},\n\t);\n\n\tif (trimmed.length > maxLength) {\n\t\treturn `${trimmed.slice(0, maxLength)}${ELLIPSIS}`;\n\t}\n\n\treturn trimmed;\n}\n"],"mappings":";;;;;AAAA,IAAM,qCAAqC;AAC3C,IAAM,qBAAqB;AAC3B,IAAM,WAAW;AAWV,SAAS,aAAa,MAAc,UAA+B,CAAC,GAAW;AACrF,MAAI,CAAC,MAAM;AACV,WAAO;AAAA,EACR;AAEA,QAAM,0BACL,QAAQ,2BAA2B;AACpC,QAAM,YAAY,QAAQ,aAAa;AAGvC,QAAM,iBAAiB,KAAK,QAAQ,GAAG;AACvC,QAAM,aAAa,mBAAmB,KAAK,OAAO,KAAK,MAAM,GAAG,iBAAiB,CAAC;AAGlF,QAAM,UAAU,WAAW;AAAA,IAC1B;AAAA,IACA,CAAC,OAAO,OAAe,UAAkB;AACxC,UAAI,MAAM,UAAU,yBAAyB;AAC5C,eAAO;AAAA,MACR;AAEA,aAAO,IAAI,KAAK,GAAG,MAAM,MAAM,GAAG,uBAAuB,CAAC,GAAG,QAAQ,GAAG,KAAK;AAAA,IAC9E;AAAA,EACD;AAEA,MAAI,QAAQ,SAAS,WAAW;AAC/B,WAAO,GAAG,QAAQ,MAAM,GAAG,SAAS,CAAC,GAAG,QAAQ;AAAA,EACjD;AAEA,SAAO;AACR;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export type { BrowserAdaptor, ElementRef, KeyName, Rect } from "./adaptor";
|
|
|
2
2
|
export { bufferedClip } from "./clip";
|
|
3
3
|
export type { Rgb } from "./contrast";
|
|
4
4
|
export { contrastRatio, parseOpaqueRgb, relativeLuminance } from "./contrast";
|
|
5
|
+
export { releaseStashedElements, stashedElementSelectors } from "./stashed-elements";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSelector
|
|
3
|
+
} from "./chunk-WI4RV7YK.js";
|
|
4
|
+
|
|
1
5
|
// src/clip.ts
|
|
2
6
|
function bufferedClip(rect, pageWidth, pageHeight, buffer) {
|
|
3
7
|
const left = Math.max(0, Math.min(buffer, rect.x));
|
|
@@ -36,10 +40,41 @@ function contrastRatio(a, b) {
|
|
|
36
40
|
const lb = relativeLuminance(b);
|
|
37
41
|
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
38
42
|
}
|
|
43
|
+
|
|
44
|
+
// src/stashed-elements.ts
|
|
45
|
+
function pickStashedScript(stashKey, index) {
|
|
46
|
+
const stash = window[stashKey];
|
|
47
|
+
window.__a11yPulsePickedElement = Array.isArray(stash) ? stash[index] ?? null : null;
|
|
48
|
+
}
|
|
49
|
+
function pickedElementScript() {
|
|
50
|
+
return window.__a11yPulsePickedElement ?? null;
|
|
51
|
+
}
|
|
52
|
+
function releaseStashScript(stashKey) {
|
|
53
|
+
delete window[stashKey];
|
|
54
|
+
delete window.__a11yPulsePickedElement;
|
|
55
|
+
}
|
|
56
|
+
async function stashedElementSelectors(adaptor, stashKey, indices) {
|
|
57
|
+
const selectors = [];
|
|
58
|
+
for (const index of indices) {
|
|
59
|
+
await adaptor.evaluate(pickStashedScript, stashKey, index);
|
|
60
|
+
const handle = await adaptor.evaluateHandle(pickedElementScript);
|
|
61
|
+
try {
|
|
62
|
+
selectors.push(await adaptor.evaluate(getSelector, handle));
|
|
63
|
+
} finally {
|
|
64
|
+
await adaptor.disposeRef(handle);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return selectors;
|
|
68
|
+
}
|
|
69
|
+
async function releaseStashedElements(adaptor, stashKey) {
|
|
70
|
+
await adaptor.evaluate(releaseStashScript, stashKey);
|
|
71
|
+
}
|
|
39
72
|
export {
|
|
40
73
|
bufferedClip,
|
|
41
74
|
contrastRatio,
|
|
42
75
|
parseOpaqueRgb,
|
|
43
|
-
relativeLuminance
|
|
76
|
+
relativeLuminance,
|
|
77
|
+
releaseStashedElements,
|
|
78
|
+
stashedElementSelectors
|
|
44
79
|
};
|
|
45
80
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/clip.ts","../src/contrast.ts"],"sourcesContent":["import type { Rect } from \"./adaptor\";\n\n/**\n * A screenshot clip framing `rect` with up to `buffer` pixels of padding on each side, shrunk where\n * the page edges leave less room. The padding allows for indicators drawn just outside the element\n * box (outlines, shadows) and for anti-aliasing.\n */\nexport function bufferedClip(\n\trect: Rect,\n\tpageWidth: number,\n\tpageHeight: number,\n\tbuffer: number,\n): Rect {\n\tconst left = Math.max(0, Math.min(buffer, rect.x));\n\tconst top = Math.max(0, Math.min(buffer, rect.y));\n\tconst right = Math.max(0, Math.min(buffer, pageWidth - rect.x - rect.width));\n\tconst bottom = Math.max(0, Math.min(buffer, pageHeight - rect.y - rect.height));\n\n\t// Clamp to non-negative origins: an element positioned partially off the top or left of the\n\t// document has a negative page-relative rect, and Puppeteer rejects a screenshot clip with\n\t// negative x/y.\n\treturn {\n\t\tx: Math.max(0, rect.x - left),\n\t\ty: Math.max(0, rect.y - top),\n\t\twidth: rect.width + left + right,\n\t\theight: rect.height + top + bottom,\n\t};\n}\n","export type Rgb = readonly [number, number, number];\n\n// Computed colours serialise as `rgb()` or `rgba()` with comma separators for sRGB values. Colours\n// authored in other spaces (oklch, display-p3) keep their own notation and are not parsed.\nconst RGB_PATTERN = /^rgba?\\(\\s*([\\d.]+),\\s*([\\d.]+),\\s*([\\d.]+)(?:,\\s*([\\d.]+))?\\s*\\)$/;\n\n/**\n * Parse a computed `rgb()` or `rgba()` colour, or return null when it is translucent or in another\n * notation.\n */\nexport function parseOpaqueRgb(value: string): Rgb | null {\n\tconst match = RGB_PATTERN.exec(value.trim());\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tif (match[4] !== undefined && Number(match[4]) < 1) {\n\t\treturn null;\n\t}\n\n\treturn [Number(match[1]), Number(match[2]), Number(match[3])];\n}\n\nfunction linearise(channel: number): number {\n\tconst c = channel / 255;\n\n\treturn c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\n/**\n * The WCAG relative luminance of an sRGB colour, from 0 (black) to 1 (white).\n */\nexport function relativeLuminance([r, g, b]: Rgb): number {\n\treturn 0.2126 * linearise(r) + 0.7152 * linearise(g) + 0.0722 * linearise(b);\n}\n\n/**\n * The WCAG contrast ratio between two colours, from 1 to 21.\n */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n\tconst la = relativeLuminance(a);\n\tconst lb = relativeLuminance(b);\n\n\treturn (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/clip.ts","../src/contrast.ts","../src/stashed-elements.ts"],"sourcesContent":["import type { Rect } from \"./adaptor\";\n\n/**\n * A screenshot clip framing `rect` with up to `buffer` pixels of padding on each side, shrunk where\n * the page edges leave less room. The padding allows for indicators drawn just outside the element\n * box (outlines, shadows) and for anti-aliasing.\n */\nexport function bufferedClip(\n\trect: Rect,\n\tpageWidth: number,\n\tpageHeight: number,\n\tbuffer: number,\n): Rect {\n\tconst left = Math.max(0, Math.min(buffer, rect.x));\n\tconst top = Math.max(0, Math.min(buffer, rect.y));\n\tconst right = Math.max(0, Math.min(buffer, pageWidth - rect.x - rect.width));\n\tconst bottom = Math.max(0, Math.min(buffer, pageHeight - rect.y - rect.height));\n\n\t// Clamp to non-negative origins: an element positioned partially off the top or left of the\n\t// document has a negative page-relative rect, and Puppeteer rejects a screenshot clip with\n\t// negative x/y.\n\treturn {\n\t\tx: Math.max(0, rect.x - left),\n\t\ty: Math.max(0, rect.y - top),\n\t\twidth: rect.width + left + right,\n\t\theight: rect.height + top + bottom,\n\t};\n}\n","export type Rgb = readonly [number, number, number];\n\n// Computed colours serialise as `rgb()` or `rgba()` with comma separators for sRGB values. Colours\n// authored in other spaces (oklch, display-p3) keep their own notation and are not parsed.\nconst RGB_PATTERN = /^rgba?\\(\\s*([\\d.]+),\\s*([\\d.]+),\\s*([\\d.]+)(?:,\\s*([\\d.]+))?\\s*\\)$/;\n\n/**\n * Parse a computed `rgb()` or `rgba()` colour, or return null when it is translucent or in another\n * notation.\n */\nexport function parseOpaqueRgb(value: string): Rgb | null {\n\tconst match = RGB_PATTERN.exec(value.trim());\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tif (match[4] !== undefined && Number(match[4]) < 1) {\n\t\treturn null;\n\t}\n\n\treturn [Number(match[1]), Number(match[2]), Number(match[3])];\n}\n\nfunction linearise(channel: number): number {\n\tconst c = channel / 255;\n\n\treturn c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\n/**\n * The WCAG relative luminance of an sRGB colour, from 0 (black) to 1 (white).\n */\nexport function relativeLuminance([r, g, b]: Rgb): number {\n\treturn 0.2126 * linearise(r) + 0.7152 * linearise(g) + 0.0722 * linearise(b);\n}\n\n/**\n * The WCAG contrast ratio between two colours, from 1 to 21.\n */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n\tconst la = relativeLuminance(a);\n\tconst lb = relativeLuminance(b);\n\n\treturn (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);\n}\n","import type { BrowserAdaptor } from \"./adaptor\";\nimport { getSelector } from \"./get-selector\";\n\ntype PickWindow = Window & { __a11yPulsePickedElement?: Element | null };\n\nfunction pickStashedScript(stashKey: string, index: number): void {\n\tconst stash = (window as unknown as Record<string, unknown>)[stashKey];\n\n\t(window as PickWindow).__a11yPulsePickedElement = Array.isArray(stash)\n\t\t? (stash[index] ?? null)\n\t\t: null;\n}\n\nfunction pickedElementScript(): Element | null {\n\treturn (window as PickWindow).__a11yPulsePickedElement ?? null;\n}\n\nfunction releaseStashScript(stashKey: string): void {\n\tdelete (window as unknown as Record<string, unknown>)[stashKey];\n\tdelete (window as PickWindow).__a11yPulsePickedElement;\n}\n\n/**\n * Return a selector (see getSelector) for each element at `indices` of the array a page script\n * left on `window[stashKey]`.\n */\nexport async function stashedElementSelectors(\n\tadaptor: BrowserAdaptor,\n\tstashKey: string,\n\tindices: readonly number[],\n): Promise<string[]> {\n\tconst selectors: string[] = [];\n\n\tfor (const index of indices) {\n\t\tawait adaptor.evaluate(pickStashedScript, stashKey, index);\n\t\tconst handle = await adaptor.evaluateHandle(pickedElementScript);\n\n\t\ttry {\n\t\t\tselectors.push(await adaptor.evaluate(getSelector, handle));\n\t\t} finally {\n\t\t\tawait adaptor.disposeRef(handle);\n\t\t}\n\t}\n\n\treturn selectors;\n}\n\n/**\n * Remove the array on `window[stashKey]` from the page.\n */\nexport async function releaseStashedElements(\n\tadaptor: BrowserAdaptor,\n\tstashKey: string,\n): Promise<void> {\n\tawait adaptor.evaluate(releaseStashSc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c,GAAQ,GAAgB;AACrD,QAAM,KAAK,kBAAkB,CAAC;AAC9B,QAAM,KAAK,kBAAkB,CAAC;AAE9B,UAAQ,KAAK,IAAI,IAAI,EAAE,IAAI,SAAS,KAAK,IAAI,IAAI,EAAE,IAAI;AACxD;;;ACxCA,SAAS,kBAAkB,UAAkB,OAAqB;AACjE,QAAM,QAAS,OAA8C,QAAQ;AAErE,EAAC,OAAsB,2BAA2B,MAAM,QAAQ,KAAK,IACjE,MAAM,KAAK,KAAK,OACjB;AACJ;AAEA,SAAS,sBAAsC;AAC9C,SAAQ,OAAsB,4BAA4B;AAC3D;AAEA,SAAS,mBAAmB,UAAwB;AACnD,SAAQ,OAA8C,QAAQ;AAC9D,SAAQ,OAAsB;AAC/B;AAMA,eAAsB,wBACrB,SACA,UACA,SACoB;AACpB,QAAM,YAAsB,CAAC;AAE7B,aAAW,SAAS,SAAS;AAC5B,UAAM,QAAQ,SAAS,mBAAmB,UAAU,KAAK;AACzD,UAAM,SAAS,MAAM,QAAQ,eAAe,mBAAmB;AAE/D,QAAI;AACH,gBAAU,KAAK,MAAM,QAAQ,SAAS,aAAa,MAAM,CAAC;AAAA,IAC3D,UAAE;AACD,YAAM,QAAQ,WAAW,MAAM;AAAA,IAChC;AAAA,EACD;AAEA,SAAO;AACR;AAKA,eAAsB,uBACrB,SACA,UACgB;AAChB,QAAM,QAAQ,SAAS,oBAAoB,QAAQ;AACpD;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BrowserAdaptor } from "./adaptor";
|
|
2
|
+
/**
|
|
3
|
+
* Return a selector (see getSelector) for each element at `indices` of the array a page script
|
|
4
|
+
* left on `window[stashKey]`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stashedElementSelectors(adaptor: BrowserAdaptor, stashKey: string, indices: readonly number[]): Promise<string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Remove the array on `window[stashKey]` from the page.
|
|
9
|
+
*/
|
|
10
|
+
export declare function releaseStashedElements(adaptor: BrowserAdaptor, stashKey: string): Promise<void>;
|