@a11y-pulse/browser-adaptor 0.8.0 → 0.10.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 +25 -5
- package/dist/adaptor.d.ts +15 -1
- package/dist/adaptors/playwright.d.ts +24 -0
- package/dist/adaptors/playwright.js +85 -7
- package/dist/adaptors/playwright.js.map +1 -1
- package/dist/adaptors/puppeteer.d.ts +17 -0
- package/dist/adaptors/puppeteer.js +78 -2
- package/dist/adaptors/puppeteer.js.map +1 -1
- package/dist/chunk-GRS3X3VZ.js +198 -0
- package/dist/chunk-GRS3X3VZ.js.map +1 -0
- package/dist/{chunk-QUDMCLZ7.js → chunk-M2OOSZU3.js} +2 -1
- package/dist/chunk-M2OOSZU3.js.map +1 -0
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +76 -7
- package/dist/dom.js.map +1 -1
- package/dist/element-screenshot.d.ts +39 -0
- package/dist/get-selector.d.ts +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +90 -3
- package/dist/index.js.map +1 -1
- package/dist/stashed-elements.d.ts +6 -1
- package/dist/truncate-html.d.ts +4 -0
- package/package.json +5 -5
- package/dist/chunk-QUDMCLZ7.js.map +0 -1
- package/dist/chunk-WI4RV7YK.js +0 -143
- package/dist/chunk-WI4RV7YK.js.map +0 -1
|
@@ -0,0 +1,198 @@
|
|
|
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 = (node) => node.nodeType === 1 ? node.nodeName.toLowerCase() : node.nodeName.toUpperCase().replace(/^#/, "");
|
|
6
|
+
const rootOf = (element) => {
|
|
7
|
+
const node = element.getRootNode?.();
|
|
8
|
+
return node && typeof node.querySelectorAll === "function" ? node : null;
|
|
9
|
+
};
|
|
10
|
+
const countsByRoot = /* @__PURE__ */ new Map();
|
|
11
|
+
const matchCount = (queryRoot, selector) => {
|
|
12
|
+
let counts = countsByRoot.get(queryRoot);
|
|
13
|
+
if (counts === void 0) {
|
|
14
|
+
counts = /* @__PURE__ */ new Map();
|
|
15
|
+
countsByRoot.set(queryRoot, counts);
|
|
16
|
+
}
|
|
17
|
+
let count = counts.get(selector);
|
|
18
|
+
if (count === void 0) {
|
|
19
|
+
try {
|
|
20
|
+
count = queryRoot.querySelectorAll(selector).length;
|
|
21
|
+
} catch {
|
|
22
|
+
count = Number.POSITIVE_INFINITY;
|
|
23
|
+
}
|
|
24
|
+
counts.set(selector, count);
|
|
25
|
+
}
|
|
26
|
+
return count;
|
|
27
|
+
};
|
|
28
|
+
const classCount = (queryRoot, cls, selector) => {
|
|
29
|
+
const byClassName = queryRoot.getElementsByClassName;
|
|
30
|
+
if (typeof byClassName === "function" && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
31
|
+
try {
|
|
32
|
+
return byClassName.call(queryRoot, cls).length;
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return matchCount(queryRoot, selector);
|
|
37
|
+
};
|
|
38
|
+
const safeMatches = (element, selector) => {
|
|
39
|
+
try {
|
|
40
|
+
return typeof element.matches === "function" && element.matches(selector);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const idIsUnique = (element, id) => {
|
|
46
|
+
const queryRoot = rootOf(element);
|
|
47
|
+
return queryRoot === null || matchCount(queryRoot, `#${esc(id)}`) === 1;
|
|
48
|
+
};
|
|
49
|
+
const classFeature = (cls) => ({
|
|
50
|
+
feature: `.${esc(cls)}`,
|
|
51
|
+
sharedBy: (sibling) => Array.from(sibling.classList ?? []).includes(cls)
|
|
52
|
+
});
|
|
53
|
+
const rarestFeature = (element, queryRoot) => {
|
|
54
|
+
const classes = Array.from(element.classList).slice(0, 8);
|
|
55
|
+
if (!queryRoot) {
|
|
56
|
+
const cls = classes[0];
|
|
57
|
+
return cls === void 0 ? null : classFeature(cls);
|
|
58
|
+
}
|
|
59
|
+
let best = null;
|
|
60
|
+
let bestCount = Number.POSITIVE_INFINITY;
|
|
61
|
+
for (const cls of classes) {
|
|
62
|
+
const candidate = classFeature(cls);
|
|
63
|
+
if (!safeMatches(element, candidate.feature)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const count = classCount(queryRoot, cls, candidate.feature);
|
|
67
|
+
if (count < bestCount) {
|
|
68
|
+
best = candidate;
|
|
69
|
+
bestCount = count;
|
|
70
|
+
}
|
|
71
|
+
if (count === 1) {
|
|
72
|
+
return best;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const href = typeof element.getAttribute === "function" ? element.getAttribute("href") : null;
|
|
76
|
+
if (href && href.length <= 100 && !/["\\?]/.test(href)) {
|
|
77
|
+
const feature = `[href="${href}"]`;
|
|
78
|
+
if (safeMatches(element, feature) && matchCount(queryRoot, feature) < bestCount) {
|
|
79
|
+
return {
|
|
80
|
+
feature,
|
|
81
|
+
sharedBy: (sibling) => typeof sibling.getAttribute === "function" && sibling.getAttribute("href") === href
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return best;
|
|
86
|
+
};
|
|
87
|
+
const positionAmongSiblings = (element, sharedBy) => {
|
|
88
|
+
const siblings = element.parentNode?.children;
|
|
89
|
+
if (!siblings) {
|
|
90
|
+
return { nth: 0, ambiguous: false };
|
|
91
|
+
}
|
|
92
|
+
let nth = 0;
|
|
93
|
+
let count = 0;
|
|
94
|
+
let shared = 0;
|
|
95
|
+
for (const sibling of Array.from(siblings)) {
|
|
96
|
+
if (sibling.nodeName !== element.nodeName) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
count++;
|
|
100
|
+
if (sibling === element) {
|
|
101
|
+
nth = count;
|
|
102
|
+
}
|
|
103
|
+
if (sharedBy(sibling)) {
|
|
104
|
+
shared++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { nth, ambiguous: shared > 1 };
|
|
108
|
+
};
|
|
109
|
+
const segmentFor = (element, queryRoot) => {
|
|
110
|
+
if (element.id && idIsUnique(element, element.id)) {
|
|
111
|
+
return { segment: `#${esc(element.id)}`, anchored: true };
|
|
112
|
+
}
|
|
113
|
+
const feature = rarestFeature(element, queryRoot);
|
|
114
|
+
let segment = tagName(element) + (feature === null ? "" : feature.feature);
|
|
115
|
+
const { nth, ambiguous } = positionAmongSiblings(
|
|
116
|
+
element,
|
|
117
|
+
feature === null ? () => true : feature.sharedBy
|
|
118
|
+
);
|
|
119
|
+
if (ambiguous && nth > 0) {
|
|
120
|
+
segment += `:nth-of-type(${nth})`;
|
|
121
|
+
}
|
|
122
|
+
return { segment, anchored: false };
|
|
123
|
+
};
|
|
124
|
+
const degradedSegmentFor = (element) => {
|
|
125
|
+
let segment = tagName(element);
|
|
126
|
+
const { nth, ambiguous } = positionAmongSiblings(element, () => true);
|
|
127
|
+
if (ambiguous && nth > 0) {
|
|
128
|
+
segment += `:nth-of-type(${nth})`;
|
|
129
|
+
}
|
|
130
|
+
return segment;
|
|
131
|
+
};
|
|
132
|
+
const selectorWithin = (start) => {
|
|
133
|
+
const segments = [];
|
|
134
|
+
let node = start;
|
|
135
|
+
const queryRoot = start && start.nodeType === 1 ? rootOf(start) : null;
|
|
136
|
+
try {
|
|
137
|
+
while (node && node.nodeType === 1) {
|
|
138
|
+
const element = node;
|
|
139
|
+
let { segment, anchored } = segmentFor(element, queryRoot);
|
|
140
|
+
const joinedWith = (candidate) => segments.length ? candidate.length + 1 + segments.join(">").length : candidate.length;
|
|
141
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
142
|
+
segment = degradedSegmentFor(element);
|
|
143
|
+
anchored = false;
|
|
144
|
+
if (joinedWith(segment) > MAX_LENGTH - 1) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
segments.unshift(segment);
|
|
149
|
+
if (anchored) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
if (queryRoot && matchCount(queryRoot, segments.join(">")) === 1) {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
node = element.parentNode;
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
return segments.join(">");
|
|
160
|
+
};
|
|
161
|
+
const parts = [selectorWithin(root)];
|
|
162
|
+
try {
|
|
163
|
+
let inner = root;
|
|
164
|
+
while (inner && inner.nodeType === 1) {
|
|
165
|
+
const tree = inner.getRootNode?.();
|
|
166
|
+
const host = tree && tree.nodeType === 11 ? tree.host ?? null : null;
|
|
167
|
+
if (!host) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
parts.unshift(selectorWithin(host));
|
|
171
|
+
inner = host;
|
|
172
|
+
}
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
return parts.join(" >>> ");
|
|
176
|
+
}
|
|
177
|
+
function resolveSelector(selector) {
|
|
178
|
+
let scope = document;
|
|
179
|
+
let element = null;
|
|
180
|
+
for (const part of selector.split(" >>> ")) {
|
|
181
|
+
try {
|
|
182
|
+
element = scope.querySelector(part);
|
|
183
|
+
} catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (!element) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
scope = element.shadowRoot ?? element;
|
|
190
|
+
}
|
|
191
|
+
return element;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export {
|
|
195
|
+
getSelector,
|
|
196
|
+
resolveSelector
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=chunk-GRS3X3VZ.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 *\n * A selector is only unique within the tree the element lives in. For an element inside an open\n * shadow root, each host on the way out contributes its own selector, joined outermost first with\n * ` >>> `: `my-footer >>> a.link`. That is deliberately not valid CSS, so `document.querySelector`\n * throws on it rather than quietly resolving the inner part to some other element in the light DOM.\n * Use `resolveSelector` to turn one back into its element.\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\t// Counting matches walks the whole tree, and the same few selectors come up at every level of\n\t// the walk, so each count is taken once per call. Nothing changes the page in between.\n\tconst countsByRoot = new Map<ParentNode, Map<string, number>>();\n\n\tconst matchCount = (queryRoot: ParentNode, selector: string): number => {\n\t\tlet counts = countsByRoot.get(queryRoot);\n\n\t\tif (counts === undefined) {\n\t\t\tcounts = new Map();\n\t\t\tcountsByRoot.set(queryRoot, counts);\n\t\t}\n\n\t\tlet count = counts.get(selector);\n\n\t\tif (count === undefined) {\n\t\t\ttry {\n\t\t\t\tcount = queryRoot.querySelectorAll(selector).length;\n\t\t\t} catch {\n\t\t\t\t// A selector that fails to parse can't be relied on.\n\t\t\t\tcount = Number.POSITIVE_INFINITY;\n\t\t\t}\n\n\t\t\tcounts.set(selector, count);\n\t\t}\n\n\t\treturn count;\n\t};\n\n\t// How many elements in the root carry the class. Where the root offers it, the live collection\n\t// answers this: the browser keeps its length until the document changes, so the count stays cheap\n\t// across the many calls an audit makes, where a selector query walks the tree every time.\n\tconst classCount = (queryRoot: ParentNode, cls: string, selector: string): number => {\n\t\tconst byClassName = (queryRoot as Partial<Document>).getElementsByClassName;\n\n\t\tif (\n\t\t\ttypeof byClassName === \"function\" &&\n\t\t\ttypeof CSS !== \"undefined\" &&\n\t\t\ttypeof CSS.escape === \"function\"\n\t\t) {\n\t\t\ttry {\n\t\t\t\treturn byClassName.call(queryRoot, cls).length;\n\t\t\t} catch {}\n\t\t}\n\n\t\treturn matchCount(queryRoot, selector);\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 = classCount(queryRoot, cls, 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\t// The selector for `start` within its own tree (the document, or the shadow root it is in).\n\tconst selectorWithin = (start: Node | null): string => {\n\t\tconst segments: string[] = [];\n\t\tlet node: Node | null = start;\n\t\tconst queryRoot = start && start.nodeType === 1 ? rootOf(start as Element) : null;\n\n\t\ttry {\n\t\t\t// Walk only element nodes. Stopping at the first non-element parent (the document, or a\n\t\t\t// ShadowRoot when the target is inside an open shadow root) keeps the selector within its tree\n\t\t\t// and avoids reading `classList` off a node that has none.\n\t\t\twhile (node && node.nodeType === 1) {\n\t\t\t\tconst element = node as Element;\n\t\t\t\tlet { segment, anchored } = segmentFor(element, queryRoot);\n\n\t\t\t\t// Keep within the budget (the +1 accounts for the \">\" that would join this segment to the\n\t\t\t\t// rest). A level whose full segment doesn't fit is degraded to tag + position rather than\n\t\t\t\t// discarded, so ancestor context is never lost to one long feature.\n\t\t\t\tconst joinedWith = (candidate: string): number =>\n\t\t\t\t\tsegments.length ? candidate.length + 1 + segments.join(\">\").length : candidate.length;\n\n\t\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\t\tsegment = degradedSegmentFor(element);\n\t\t\t\t\tanchored = false;\n\n\t\t\t\t\tif (joinedWith(segment) > MAX_LENGTH - 1) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tsegments.unshift(segment);\n\n\t\t\t\tif (anchored) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// Stop as soon as the selector already identifies a single element. This, not truncation, is\n\t\t\t\t// what keeps selectors short.\n\t\t\t\tif (queryRoot && matchCount(queryRoot, segments.join(\">\")) === 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tnode = element.parentNode;\n\t\t\t}\n\t\t} catch {\n\t\t\t// A malformed node tree must never crash the audit; return what we have.\n\t\t}\n\n\t\treturn segments.join(\">\");\n\t};\n\n\tconst parts: string[] = [selectorWithin(root)];\n\n\ttry {\n\t\tlet inner: Node | null = root;\n\n\t\t// Step out through each enclosing shadow root to its host.\n\t\twhile (inner && inner.nodeType === 1) {\n\t\t\tconst tree = (inner as Element & { getRootNode?: () => Node }).getRootNode?.();\n\t\t\tconst host: Element | null =\n\t\t\t\ttree && tree.nodeType === 11 ? ((tree as ShadowRoot).host ?? null) : null;\n\n\t\t\tif (!host) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tparts.unshift(selectorWithin(host));\n\t\t\tinner = host;\n\t\t}\n\t} catch {\n\t\t// As above: return what we have.\n\t}\n\n\treturn parts.join(\" >>> \");\n}\n\n/**\n * Find the element a `getSelector` selector names, stepping into the shadow root of each host it\n * lists. Returns `null` when any part matches nothing. This function is serialized and run in the\n * page context, so it must not reference any symbols outside its own scope.\n */\nexport function resolveSelector(selector: string): Element | null {\n\tlet scope: ParentNode = document;\n\tlet element: Element | null = null;\n\n\tfor (const part of selector.split(\" >>> \")) {\n\t\ttry {\n\t\t\telement = scope.querySelector(part);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (!element) {\n\t\t\treturn null;\n\t\t}\n\n\t\tscope = element.shadowRoot ?? element;\n\t}\n\n\treturn element;\n}\n"],"mappings":";AAgBO,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,CAAC,SAChB,KAAK,aAAa,IACf,KAAK,SAAS,YAAY,IAC1B,KAAK,SAAS,YAAY,EAAE,QAAQ,MAAM,EAAE;AAKhD,QAAM,SAAS,CAAC,YAAwC;AACvD,UAAM,OAAQ,QAAmD,cAAc;AAE/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
|
5
5
|
requestAnimationFrame(() => resolve());
|
|
6
6
|
});
|
|
7
|
+
setTimeout(() => resolve(), 200);
|
|
7
8
|
});
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
nextPaintScript
|
|
12
13
|
};
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
14
|
+
//# sourceMappingURL=chunk-M2OOSZU3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/paint.ts"],"sourcesContent":["/**\n * A doubleRAF that aims to wait until the page has painted the next frame.\n */\nexport function nextPaintScript(): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\trequestAnimationFrame(() => {\n\t\t\trequestAnimationFrame(() => resolve());\n\t\t});\n\t\t// A page that is not being rendered (a background tab) never gets its frames.\n\t\tsetTimeout(() => resolve(), 200);\n\t});\n}\n"],"mappings":";AAGO,SAAS,kBAAiC;AAChD,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC/B,0BAAsB,MAAM;AAC3B,4BAAsB,MAAM,QAAQ,CAAC;AAAA,IACtC,CAAC;AAED,eAAW,MAAM,QAAQ,GAAG,GAAG;AAAA,EAChC,CAAC;AACF;","names":[]}
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getSelector } from "./get-selector";
|
|
1
|
+
export { getSelector, resolveSelector } from "./get-selector";
|
|
2
2
|
export { type TruncateHtmlOptions, truncateHtml } from "./truncate-html";
|
package/dist/dom.js
CHANGED
|
@@ -1,35 +1,104 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getSelector
|
|
3
|
-
|
|
2
|
+
getSelector,
|
|
3
|
+
resolveSelector
|
|
4
|
+
} from "./chunk-GRS3X3VZ.js";
|
|
4
5
|
|
|
5
6
|
// src/truncate-html.ts
|
|
6
7
|
var DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;
|
|
7
8
|
var DEFAULT_MAX_LENGTH = 300;
|
|
8
9
|
var ELLIPSIS = "...";
|
|
10
|
+
var REDACTED = "[redacted]";
|
|
11
|
+
var INPUT_TYPES_WITH_AUTHORED_VALUE = /* @__PURE__ */ new Set([
|
|
12
|
+
"button",
|
|
13
|
+
"checkbox",
|
|
14
|
+
"color",
|
|
15
|
+
"image",
|
|
16
|
+
"radio",
|
|
17
|
+
"range",
|
|
18
|
+
"reset",
|
|
19
|
+
"submit"
|
|
20
|
+
]);
|
|
21
|
+
function openingTagEnd(html) {
|
|
22
|
+
let quote = null;
|
|
23
|
+
let lastSignificant = "";
|
|
24
|
+
for (let i = 0; i < html.length; i++) {
|
|
25
|
+
const char = html[i];
|
|
26
|
+
if (quote !== null) {
|
|
27
|
+
if (char === quote) {
|
|
28
|
+
quote = null;
|
|
29
|
+
}
|
|
30
|
+
} else if ((char === '"' || char === "'") && lastSignificant === "=") {
|
|
31
|
+
quote = char;
|
|
32
|
+
} else if (char === ">") {
|
|
33
|
+
return i;
|
|
34
|
+
}
|
|
35
|
+
if (!/\s/.test(char)) {
|
|
36
|
+
lastSignificant = char;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
function attributeValue(openingTag, name) {
|
|
42
|
+
const afterTagName = openingTag.replace(/^<\s*[^\s/>]+/, "");
|
|
43
|
+
const attribute = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
44
|
+
for (const match of afterTagName.matchAll(attribute)) {
|
|
45
|
+
if (match[1].toLowerCase() === name) {
|
|
46
|
+
return match[2] ?? match[3] ?? match[4] ?? "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function sliceWhole(text, length) {
|
|
52
|
+
if (text.length <= length) {
|
|
53
|
+
return text;
|
|
54
|
+
}
|
|
55
|
+
let end = Math.max(length, 0);
|
|
56
|
+
const before = text.charCodeAt(end - 1);
|
|
57
|
+
if (before >= 55296 && before <= 56319) {
|
|
58
|
+
end--;
|
|
59
|
+
}
|
|
60
|
+
const ampersand = text.lastIndexOf("&", end - 1);
|
|
61
|
+
if (ampersand !== -1 && !text.slice(ampersand, end).includes(";")) {
|
|
62
|
+
const reference = /^&#?[a-z0-9]{1,31};/i.exec(text.slice(ampersand, ampersand + 34));
|
|
63
|
+
if (reference && ampersand + reference[0].length > end) {
|
|
64
|
+
end = ampersand;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return text.slice(0, end);
|
|
68
|
+
}
|
|
9
69
|
function truncateHtml(html, options = {}) {
|
|
10
70
|
if (!html) {
|
|
11
71
|
return "";
|
|
12
72
|
}
|
|
13
73
|
const maxAttributeValueLength = options.maxAttributeValueLength ?? DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH;
|
|
14
74
|
const maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;
|
|
15
|
-
const closingBracket = html
|
|
75
|
+
const closingBracket = openingTagEnd(html);
|
|
16
76
|
const openingTag = closingBracket === -1 ? html : html.slice(0, closingBracket + 1);
|
|
77
|
+
const tagName = /^<\s*([^\s/>]+)/.exec(openingTag)?.[1]?.toLowerCase();
|
|
78
|
+
const inputType = (attributeValue(openingTag, "type") ?? "").trim().toLowerCase() || "text";
|
|
79
|
+
const redactValue = tagName === "input" && !INPUT_TYPES_WITH_AUTHORED_VALUE.has(inputType);
|
|
17
80
|
const trimmed = openingTag.replace(
|
|
18
|
-
|
|
19
|
-
(match, quote, value) => {
|
|
81
|
+
/([^\s"'<>/=]+)(\s*=\s*)(["'])([\s\S]*?)\3/g,
|
|
82
|
+
(match, name, equals, quote, value) => {
|
|
83
|
+
if (redactValue && name.toLowerCase() === "value" && value !== "") {
|
|
84
|
+
return `${name}${equals}${quote}${REDACTED}${quote}`;
|
|
85
|
+
}
|
|
20
86
|
if (value.length <= maxAttributeValueLength) {
|
|
21
87
|
return match;
|
|
22
88
|
}
|
|
23
|
-
|
|
89
|
+
const dataUri = /^\s*data:[^,]{0,64},/i.exec(value);
|
|
90
|
+
const kept = dataUri ? dataUri[0] : sliceWhole(value, maxAttributeValueLength);
|
|
91
|
+
return `${name}${equals}${quote}${kept}${ELLIPSIS}${quote}`;
|
|
24
92
|
}
|
|
25
93
|
);
|
|
26
94
|
if (trimmed.length > maxLength) {
|
|
27
|
-
return `${trimmed
|
|
95
|
+
return `${sliceWhole(trimmed, maxLength)}${ELLIPSIS}`;
|
|
28
96
|
}
|
|
29
97
|
return trimmed;
|
|
30
98
|
}
|
|
31
99
|
export {
|
|
32
100
|
getSelector,
|
|
101
|
+
resolveSelector,
|
|
33
102
|
truncateHtml
|
|
34
103
|
};
|
|
35
104
|
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/truncate-html.ts"],"sourcesContent":["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
|
|
1
|
+
{"version":3,"sources":["../src/truncate-html.ts"],"sourcesContent":["const DEFAULT_MAX_ATTRIBUTE_VALUE_LENGTH = 50;\nconst DEFAULT_MAX_LENGTH = 300;\nconst ELLIPSIS = \"...\";\nconst REDACTED = \"[redacted]\";\n\n// Input types whose `value` is a label or a fixed choice the page author wrote, rather than text\n// that may have been filled in for the person using the page.\nconst INPUT_TYPES_WITH_AUTHORED_VALUE = new Set([\n\t\"button\",\n\t\"checkbox\",\n\t\"color\",\n\t\"image\",\n\t\"radio\",\n\t\"range\",\n\t\"reset\",\n\t\"submit\",\n]);\n\nexport type TruncateHtmlOptions = {\n\tmaxAttributeValueLength?: number;\n\tmaxLength?: number;\n};\n\n/**\n * Where the opening tag ends: the first `>` that is not inside a quoted attribute value. Serialised\n * HTML leaves `>` unescaped in attribute values, so the first one in the string is not always it.\n */\nfunction openingTagEnd(html: string): number {\n\tlet quote: string | null = null;\n\tlet lastSignificant = \"\";\n\n\tfor (let i = 0; i < html.length; i++) {\n\t\tconst char = html[i]!;\n\n\t\tif (quote !== null) {\n\t\t\tif (char === quote) {\n\t\t\t\tquote = null;\n\t\t\t}\n\t\t} else if ((char === '\"' || char === \"'\") && lastSignificant === \"=\") {\n\t\t\tquote = char;\n\t\t} else if (char === \">\") {\n\t\t\treturn i;\n\t\t}\n\n\t\tif (!/\\s/.test(char)) {\n\t\t\tlastSignificant = char;\n\t\t}\n\t}\n\n\treturn -1;\n}\n\n/**\n * The value of the opening tag's own `name` attribute, or null without one. The tag is walked one\n * attribute at a time, so text inside another attribute's value is never mistaken for an attribute.\n */\nfunction attributeValue(openingTag: string, name: string): string | null {\n\tconst afterTagName = openingTag.replace(/^<\\s*[^\\s/>]+/, \"\");\n\tconst attribute = /([^\\s\"'<>/=]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\n\tfor (const match of afterTagName.matchAll(attribute)) {\n\t\t// As in HTML, the first attribute of a name is the one that counts.\n\t\tif (match[1]!.toLowerCase() === name) {\n\t\t\treturn match[2] ?? match[3] ?? match[4] ?? \"\";\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * The first `length` characters of `text`, shortened further where the cut would otherwise split a\n * surrogate pair or a character reference such as `&`.\n */\nfunction sliceWhole(text: string, length: number): string {\n\tif (text.length <= length) {\n\t\treturn text;\n\t}\n\n\tlet end = Math.max(length, 0);\n\tconst before = text.charCodeAt(end - 1);\n\n\tif (before >= 0xd800 && before <= 0xdbff) {\n\t\tend--;\n\t}\n\n\tconst ampersand = text.lastIndexOf(\"&\", end - 1);\n\n\tif (ampersand !== -1 && !text.slice(ampersand, end).includes(\";\")) {\n\t\tconst reference = /^&#?[a-z0-9]{1,31};/i.exec(text.slice(ampersand, ampersand + 34));\n\n\t\tif (reference && ampersand + reference[0].length > end) {\n\t\t\tend = ampersand;\n\t\t}\n\t}\n\n\treturn text.slice(0, end);\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 *\n * Only the opening tag is kept. Long attribute values are shortened, `data:` URIs are cut back to\n * their media type, and the `value` of a text-entry `<input>` is redacted, since it can hold\n * whatever the page was pre-filled with for the person using it.\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 = openingTagEnd(html);\n\tconst openingTag = closingBracket === -1 ? html : html.slice(0, closingBracket + 1);\n\n\tconst tagName = /^<\\s*([^\\s/>]+)/.exec(openingTag)?.[1]?.toLowerCase();\n\tconst inputType = (attributeValue(openingTag, \"type\") ?? \"\").trim().toLowerCase() || \"text\";\n\tconst redactValue = tagName === \"input\" && !INPUT_TYPES_WITH_AUTHORED_VALUE.has(inputType);\n\n\t// Shorten long quoted attribute values, preserving the quote style.\n\tconst trimmed = openingTag.replace(\n\t\t/([^\\s\"'<>/=]+)(\\s*=\\s*)([\"'])([\\s\\S]*?)\\3/g,\n\t\t(match, name: string, equals: string, quote: string, value: string) => {\n\t\t\tif (redactValue && name.toLowerCase() === \"value\" && value !== \"\") {\n\t\t\t\treturn `${name}${equals}${quote}${REDACTED}${quote}`;\n\t\t\t}\n\n\t\t\tif (value.length <= maxAttributeValueLength) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\tconst dataUri = /^\\s*data:[^,]{0,64},/i.exec(value);\n\t\t\tconst kept = dataUri ? dataUri[0] : sliceWhole(value, maxAttributeValueLength);\n\n\t\t\treturn `${name}${equals}${quote}${kept}${ELLIPSIS}${quote}`;\n\t\t},\n\t);\n\n\tif (trimmed.length > maxLength) {\n\t\treturn `${sliceWhole(trimmed, maxLength)}${ELLIPSIS}`;\n\t}\n\n\treturn trimmed;\n}\n"],"mappings":";;;;;;AAAA,IAAM,qCAAqC;AAC3C,IAAM,qBAAqB;AAC3B,IAAM,WAAW;AACjB,IAAM,WAAW;AAIjB,IAAM,kCAAkC,oBAAI,IAAI;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAWD,SAAS,cAAc,MAAsB;AAC5C,MAAI,QAAuB;AAC3B,MAAI,kBAAkB;AAEtB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACrC,UAAM,OAAO,KAAK,CAAC;AAEnB,QAAI,UAAU,MAAM;AACnB,UAAI,SAAS,OAAO;AACnB,gBAAQ;AAAA,MACT;AAAA,IACD,YAAY,SAAS,OAAO,SAAS,QAAQ,oBAAoB,KAAK;AACrE,cAAQ;AAAA,IACT,WAAW,SAAS,KAAK;AACxB,aAAO;AAAA,IACR;AAEA,QAAI,CAAC,KAAK,KAAK,IAAI,GAAG;AACrB,wBAAkB;AAAA,IACnB;AAAA,EACD;AAEA,SAAO;AACR;AAMA,SAAS,eAAe,YAAoB,MAA6B;AACxE,QAAM,eAAe,WAAW,QAAQ,iBAAiB,EAAE;AAC3D,QAAM,YAA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AAA,IAC1B;AAAA,IACA,CAAC,OAAO,MAAc,QAAgB,OAAe,UAAkB;AACtE,UAAI,eAAe,KAAK,YAAY,MAAM,WAAW,UAAU,IAAI;AAClE,eAAO,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK;AAAA,MACnD;AAEA,UAAI,MAAM,UAAU,yBAAyB;AAC5C,eAAO;AAAA,MACR;AAEA,YAAM,UAAU,wBAAwB,KAAK,KAAK;AAClD,YAAM,OAAO,UAAU,QAAQ,CAAC,IAAI,WAAW,OAAO,uBAAuB;AAE7E,aAAO,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,QAAQ,GAAG,KAAK;AAAA,IAC1D;AAAA,EACD;AAEA,MAAI,QAAQ,SAAS,WAAW;AAC/B,WAAO,GAAG,WAAW,SAAS,SAAS,CAAC,GAAG,QAAQ;AAAA,EACpD;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT: The `*Script` functions in this file are serialized and injected into the audited page,
|
|
3
|
+
* so they must not reference any symbols outside their own scope.
|
|
4
|
+
*/
|
|
5
|
+
import type { BrowserAdaptor, ElementRef, Rect } from "./adaptor";
|
|
6
|
+
export declare function pageDimensionsScript(): {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function elementRectScript(el: Element | null): Rect;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the element should be centred in the viewport before its screenshots are taken: either
|
|
13
|
+
* something unrelated covers its centre, or its screenshot clip (its box padded by `buffer`, cut
|
|
14
|
+
* off at the document edges like bufferedClip) reaches past an edge of the viewport. A capture only
|
|
15
|
+
* shows what is inside the viewport, so such a clip would lose an indicator drawn in the padding. A
|
|
16
|
+
* clip larger than the viewport does not count, since scrolling cannot fit it anyway.
|
|
17
|
+
*/
|
|
18
|
+
export declare function needsCentringScript(el: Element | null, buffer: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Scroll the window so the element sits at the vertical centre of the viewport and is inside it
|
|
21
|
+
* horizontally with `buffer` to spare, instantly so a screenshot taken immediately afterwards isn't
|
|
22
|
+
* captured mid-animation. Scrolls the window directly rather than via scrollIntoView(): Chromium
|
|
23
|
+
* moves the sequential focus navigation starting point to the element passed to scrollIntoView(),
|
|
24
|
+
* so when focus cannot be handed back afterwards (a closed shadow host) the next Tab would re-enter
|
|
25
|
+
* the same element instead of moving on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scrollToCenterScript(el: Element | null, buffer?: number): void;
|
|
28
|
+
export type ElementScreenshotOptions = {
|
|
29
|
+
/** Padding around the element's box. */
|
|
30
|
+
clipBuffer: number;
|
|
31
|
+
/** How long to wait (ms) after scrolling for the page to settle. */
|
|
32
|
+
settleDelay: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Screenshot the element `handle` refers to, clipped to its box plus `clipBuffer` padding, first
|
|
36
|
+
* centring it in the viewport when its clip would not fit or something covers it. The caller owns
|
|
37
|
+
* `handle`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function captureElementScreenshot(adaptor: Pick<BrowserAdaptor, "evaluate" | "screenshotClip" | "screenshotClipScale">, handle: ElementRef, options: ElementScreenshotOptions): Promise<Uint8Array>;
|
package/dist/get-selector.d.ts
CHANGED
|
@@ -7,5 +7,17 @@
|
|
|
7
7
|
* element (a unique id, the rarest single class, or an :nth-of-type position), and the walk stops
|
|
8
8
|
* as soon as the joined selector matches exactly one element. Selectors stay short because of that
|
|
9
9
|
* early stop, not because of truncation; the length budget is only a backstop.
|
|
10
|
+
*
|
|
11
|
+
* A selector is only unique within the tree the element lives in. For an element inside an open
|
|
12
|
+
* shadow root, each host on the way out contributes its own selector, joined outermost first with
|
|
13
|
+
* ` >>> `: `my-footer >>> a.link`. That is deliberately not valid CSS, so `document.querySelector`
|
|
14
|
+
* throws on it rather than quietly resolving the inner part to some other element in the light DOM.
|
|
15
|
+
* Use `resolveSelector` to turn one back into its element.
|
|
10
16
|
*/
|
|
11
17
|
export declare function getSelector(root: Node | null): string;
|
|
18
|
+
/**
|
|
19
|
+
* Find the element a `getSelector` selector names, stepping into the shadow root of each host it
|
|
20
|
+
* lists. Returns `null` when any part matches nothing. This function is serialized and run in the
|
|
21
|
+
* page context, so it must not reference any symbols outside its own scope.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveSelector(selector: string): Element | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ 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 {
|
|
5
|
+
export { captureElementScreenshot, type ElementScreenshotOptions, elementRectScript, needsCentringScript, pageDimensionsScript, scrollToCenterScript, } from "./element-screenshot";
|
|
6
|
+
export { releaseStashedElements, stashedElementHandle, stashedElementSelectors, } from "./stashed-elements";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSelector
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GRS3X3VZ.js";
|
|
4
4
|
|
|
5
5
|
// src/clip.ts
|
|
6
6
|
function bufferedClip(rect, pageWidth, pageHeight, buffer) {
|
|
@@ -41,6 +41,84 @@ function contrastRatio(a, b) {
|
|
|
41
41
|
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// src/element-screenshot.ts
|
|
45
|
+
function pageDimensionsScript() {
|
|
46
|
+
return {
|
|
47
|
+
width: document.documentElement.scrollWidth,
|
|
48
|
+
height: document.documentElement.scrollHeight
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function elementRectScript(el) {
|
|
52
|
+
if (!el) {
|
|
53
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
54
|
+
}
|
|
55
|
+
const rect = el.getBoundingClientRect();
|
|
56
|
+
return {
|
|
57
|
+
x: rect.left + window.scrollX,
|
|
58
|
+
y: rect.top + window.scrollY,
|
|
59
|
+
width: rect.width,
|
|
60
|
+
height: rect.height
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function needsCentringScript(el, buffer) {
|
|
64
|
+
if (!el) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const rect = el.getBoundingClientRect();
|
|
68
|
+
const viewport = document.scrollingElement ?? document.documentElement;
|
|
69
|
+
const viewportWidth = viewport.clientWidth;
|
|
70
|
+
const viewportHeight = viewport.clientHeight;
|
|
71
|
+
const x = Math.min(Math.max(rect.left + rect.width / 2, 0), viewportWidth - 1);
|
|
72
|
+
const y = Math.min(Math.max(rect.top + rect.height / 2, 0), viewportHeight - 1);
|
|
73
|
+
let hit = document.elementFromPoint(x, y);
|
|
74
|
+
while (hit?.shadowRoot) {
|
|
75
|
+
const inner = hit.shadowRoot.elementFromPoint(x, y);
|
|
76
|
+
if (!inner || inner === hit) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
hit = inner;
|
|
80
|
+
}
|
|
81
|
+
if (hit && hit !== el && !el.contains(hit) && !hit.contains(el)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const docLeft = -window.scrollX;
|
|
85
|
+
const docTop = -window.scrollY;
|
|
86
|
+
const left = Math.max(rect.left - buffer, docLeft);
|
|
87
|
+
const top = Math.max(rect.top - buffer, docTop);
|
|
88
|
+
const right = Math.min(rect.right + buffer, docLeft + document.documentElement.scrollWidth);
|
|
89
|
+
const bottom = Math.min(rect.bottom + buffer, docTop + document.documentElement.scrollHeight);
|
|
90
|
+
if (right - left > viewportWidth || bottom - top > viewportHeight) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return left < 0 || top < 0 || right > viewportWidth || bottom > viewportHeight;
|
|
94
|
+
}
|
|
95
|
+
function scrollToCenterScript(el, buffer = 0) {
|
|
96
|
+
if (!el) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const rect = el.getBoundingClientRect();
|
|
100
|
+
const viewport = document.scrollingElement ?? document.documentElement;
|
|
101
|
+
const viewportWidth = viewport.clientWidth;
|
|
102
|
+
const top = rect.top + rect.height / 2 - viewport.clientHeight / 2;
|
|
103
|
+
let left = 0;
|
|
104
|
+
if (rect.left - buffer < 0) {
|
|
105
|
+
left = rect.left - buffer;
|
|
106
|
+
} else if (rect.right + buffer > viewportWidth) {
|
|
107
|
+
left = Math.min(rect.right + buffer - viewportWidth, rect.left - buffer);
|
|
108
|
+
}
|
|
109
|
+
window.scrollBy({ top, left, behavior: "instant" });
|
|
110
|
+
}
|
|
111
|
+
async function captureElementScreenshot(adaptor, handle, options) {
|
|
112
|
+
if (await adaptor.evaluate(needsCentringScript, handle, options.clipBuffer)) {
|
|
113
|
+
await adaptor.evaluate(scrollToCenterScript, handle, options.clipBuffer);
|
|
114
|
+
await new Promise((resolve) => setTimeout(resolve, options.settleDelay));
|
|
115
|
+
}
|
|
116
|
+
const { width: pageWidth, height: pageHeight } = await adaptor.evaluate(pageDimensionsScript);
|
|
117
|
+
const rect = await adaptor.evaluate(elementRectScript, handle);
|
|
118
|
+
const clip = bufferedClip(rect, pageWidth, pageHeight, options.clipBuffer);
|
|
119
|
+
return adaptor.screenshotClip(clip, adaptor.screenshotClipScale ?? 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
44
122
|
// src/stashed-elements.ts
|
|
45
123
|
function pickStashedScript(stashKey, index) {
|
|
46
124
|
const stash = window[stashKey];
|
|
@@ -53,11 +131,14 @@ function releaseStashScript(stashKey) {
|
|
|
53
131
|
delete window[stashKey];
|
|
54
132
|
delete window.__a11yPulsePickedElement;
|
|
55
133
|
}
|
|
134
|
+
async function stashedElementHandle(adaptor, stashKey, index) {
|
|
135
|
+
await adaptor.evaluate(pickStashedScript, stashKey, index);
|
|
136
|
+
return adaptor.evaluateHandle(pickedElementScript);
|
|
137
|
+
}
|
|
56
138
|
async function stashedElementSelectors(adaptor, stashKey, indices) {
|
|
57
139
|
const selectors = [];
|
|
58
140
|
for (const index of indices) {
|
|
59
|
-
await adaptor
|
|
60
|
-
const handle = await adaptor.evaluateHandle(pickedElementScript);
|
|
141
|
+
const handle = await stashedElementHandle(adaptor, stashKey, index);
|
|
61
142
|
try {
|
|
62
143
|
selectors.push(await adaptor.evaluate(getSelector, handle));
|
|
63
144
|
} finally {
|
|
@@ -71,10 +152,16 @@ async function releaseStashedElements(adaptor, stashKey) {
|
|
|
71
152
|
}
|
|
72
153
|
export {
|
|
73
154
|
bufferedClip,
|
|
155
|
+
captureElementScreenshot,
|
|
74
156
|
contrastRatio,
|
|
157
|
+
elementRectScript,
|
|
158
|
+
needsCentringScript,
|
|
159
|
+
pageDimensionsScript,
|
|
75
160
|
parseOpaqueRgb,
|
|
76
161
|
relativeLuminance,
|
|
77
162
|
releaseStashedElements,
|
|
163
|
+
scrollToCenterScript,
|
|
164
|
+
stashedElementHandle,
|
|
78
165
|
stashedElementSelectors
|
|
79
166
|
};
|
|
80
167
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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(releaseStashScript, stashKey);\n}\n"],"mappings":";;;;;AAOO,SAAS,aACf,MACA,WACA,YACA,QACO;AACP,QAAM,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AACjD,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AAChD,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,YAAY,KAAK,IAAI,KAAK,KAAK,CAAC;AAC3E,QAAM,SAAS,KAAK,IAAI,GAAG,KAAK,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C9C,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":[]}
|
|
1
|
+
{"version":3,"sources":["../src/clip.ts","../src/contrast.ts","../src/element-screenshot.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","/**\n * IMPORTANT: The `*Script` functions in this file are serialized and injected into the audited page,\n * so they must not reference any symbols outside their own scope.\n */\n\nimport type { BrowserAdaptor, ElementRef, Rect } from \"./adaptor\";\nimport { bufferedClip } from \"./clip\";\n\nexport function pageDimensionsScript(): { width: number; height: number } {\n\treturn {\n\t\twidth: document.documentElement.scrollWidth,\n\t\theight: document.documentElement.scrollHeight,\n\t};\n}\n\nexport function elementRectScript(el: Element | null): Rect {\n\tif (!el) {\n\t\treturn { x: 0, y: 0, width: 0, height: 0 };\n\t}\n\n\tconst rect = el.getBoundingClientRect();\n\n\treturn {\n\t\tx: rect.left + window.scrollX,\n\t\ty: rect.top + window.scrollY,\n\t\twidth: rect.width,\n\t\theight: rect.height,\n\t};\n}\n\n/**\n * Whether the element should be centred in the viewport before its screenshots are taken: either\n * something unrelated covers its centre, or its screenshot clip (its box padded by `buffer`, cut\n * off at the document edges like bufferedClip) reaches past an edge of the viewport. A capture only\n * shows what is inside the viewport, so such a clip would lose an indicator drawn in the padding. A\n * clip larger than the viewport does not count, since scrolling cannot fit it anyway.\n */\nexport function needsCentringScript(el: Element | null, buffer: number): boolean {\n\tif (!el) {\n\t\treturn false;\n\t}\n\n\tconst rect = el.getBoundingClientRect();\n\t// In quirks mode the viewport's size is on <body>, and <html> measures the whole document.\n\tconst viewport = document.scrollingElement ?? document.documentElement;\n\tconst viewportWidth = viewport.clientWidth;\n\tconst viewportHeight = viewport.clientHeight;\n\n\tconst x = Math.min(Math.max(rect.left + rect.width / 2, 0), viewportWidth - 1);\n\tconst y = Math.min(Math.max(rect.top + rect.height / 2, 0), viewportHeight - 1);\n\n\tlet hit = document.elementFromPoint(x, y);\n\n\twhile (hit?.shadowRoot) {\n\t\tconst inner = hit.shadowRoot.elementFromPoint(x, y);\n\n\t\tif (!inner || inner === hit) {\n\t\t\tbreak;\n\t\t}\n\n\t\thit = inner;\n\t}\n\n\tif (hit && hit !== el && !el.contains(hit) && !hit.contains(el)) {\n\t\treturn true;\n\t}\n\n\tconst docLeft = -window.scrollX;\n\tconst docTop = -window.scrollY;\n\tconst left = Math.max(rect.left - buffer, docLeft);\n\tconst top = Math.max(rect.top - buffer, docTop);\n\tconst right = Math.min(rect.right + buffer, docLeft + document.documentElement.scrollWidth);\n\tconst bottom = Math.min(rect.bottom + buffer, docTop + document.documentElement.scrollHeight);\n\n\tif (right - left > viewportWidth || bottom - top > viewportHeight) {\n\t\treturn false;\n\t}\n\n\treturn left < 0 || top < 0 || right > viewportWidth || bottom > viewportHeight;\n}\n\n/**\n * Scroll the window so the element sits at the vertical centre of the viewport and is inside it\n * horizontally with `buffer` to spare, instantly so a screenshot taken immediately afterwards isn't\n * captured mid-animation. Scrolls the window directly rather than via scrollIntoView(): Chromium\n * moves the sequential focus navigation starting point to the element passed to scrollIntoView(),\n * so when focus cannot be handed back afterwards (a closed shadow host) the next Tab would re-enter\n * the same element instead of moving on.\n */\nexport function scrollToCenterScript(el: Element | null, buffer = 0): void {\n\tif (!el) {\n\t\treturn;\n\t}\n\n\tconst rect = el.getBoundingClientRect();\n\t// In quirks mode the viewport's size is on <body>, and <html> measures the whole document.\n\tconst viewport = document.scrollingElement ?? document.documentElement;\n\tconst viewportWidth = viewport.clientWidth;\n\tconst top = rect.top + rect.height / 2 - viewport.clientHeight / 2;\n\tlet left = 0;\n\n\tif (rect.left - buffer < 0) {\n\t\tleft = rect.left - buffer;\n\t} else if (rect.right + buffer > viewportWidth) {\n\t\tleft = Math.min(rect.right + buffer - viewportWidth, rect.left - buffer);\n\t}\n\n\twindow.scrollBy({ top, left, behavior: \"instant\" });\n}\n\nexport type ElementScreenshotOptions = {\n\t/** Padding around the element's box. */\n\tclipBuffer: number;\n\t/** How long to wait (ms) after scrolling for the page to settle. */\n\tsettleDelay: number;\n};\n\n/**\n * Screenshot the element `handle` refers to, clipped to its box plus `clipBuffer` padding, first\n * centring it in the viewport when its clip would not fit or something covers it. The caller owns\n * `handle`.\n */\nexport async function captureElementScreenshot(\n\tadaptor: Pick<BrowserAdaptor, \"evaluate\" | \"screenshotClip\" | \"screenshotClipScale\">,\n\thandle: ElementRef,\n\toptions: ElementScreenshotOptions,\n): Promise<Uint8Array> {\n\tif (await adaptor.evaluate(needsCentringScript, handle, options.clipBuffer)) {\n\t\tawait adaptor.evaluate(scrollToCenterScript, handle, options.clipBuffer);\n\t\tawait new Promise((resolve) => setTimeout(resolve, options.settleDelay));\n\t}\n\n\tconst { width: pageWidth, height: pageHeight } = await adaptor.evaluate(pageDimensionsScript);\n\tconst rect = await adaptor.evaluate(elementRectScript, handle);\n\tconst clip = bufferedClip(rect, pageWidth, pageHeight, options.clipBuffer);\n\n\treturn adaptor.screenshotClip(clip, adaptor.screenshotClipScale ?? 1);\n}\n","import type { BrowserAdaptor, ElementRef } 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 handle to the element at `index` of the array a page script left on `window[stashKey]`.\n * The caller owns the handle.\n */\nexport async function stashedElementHandle(\n\tadaptor: BrowserAdaptor,\n\tstashKey: string,\n\tindex: number,\n): Promise<ElementRef> {\n\tawait adaptor.evaluate(pickStashedScript, stashKey, index);\n\n\treturn adaptor.evaluateHandle(pickedElementScript);\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\tconst handle = await stashedElementHandle(adaptor, stashKey, index);\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 ad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} from "./adaptor";
|
|
2
|
+
/**
|
|
3
|
+
* Return a handle to the element at `index` of the array a page script left on `window[stashKey]`.
|
|
4
|
+
* The caller owns the handle.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stashedElementHandle(adaptor: BrowserAdaptor, stashKey: string, index: number): Promise<ElementRef>;
|
|
2
7
|
/**
|
|
3
8
|
* Return a selector (see getSelector) for each element at `indices` of the array a page script
|
|
4
9
|
* left on `window[stashKey]`.
|