@sedum-dev/core 0.1.0-alpha.0 → 0.1.0-alpha.11
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 +16 -16
- package/dist/chunk-C32TDS2U.js +100 -0
- package/dist/index.d.ts +1067 -163
- package/dist/index.js +11203 -3920
- package/dist/page-script/index.global.js +2363 -481
- package/dist/run-result.schema.json +173 -6
- package/dist/script-api-DzYBsXzT.d.ts +221 -0
- package/dist/script-api.d.ts +3 -0
- package/dist/script-api.js +12 -0
- package/package.json +14 -2
|
@@ -3,6 +3,7 @@ var SedumPageScript = (() => {
|
|
|
3
3
|
// src/page-protocol.ts
|
|
4
4
|
var PAGE_PROTOCOL = 1;
|
|
5
5
|
var CANDIDATE_LIMIT = 128;
|
|
6
|
+
var NAME_LIMIT = 120;
|
|
6
7
|
var PEER_LIMIT = 80;
|
|
7
8
|
var DIGEST_LIMIT = 4096;
|
|
8
9
|
var SAFE_ROLES = /* @__PURE__ */ new Set([
|
|
@@ -29,168 +30,212 @@ var SedumPageScript = (() => {
|
|
|
29
30
|
return /^[\p{Sc}\d.,\s%+-]+$/u.test(text) || /^(USD|EUR|GBP|JPY|CAD|AUD|CHF)$/i.test(text);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
// src/page-script/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
// src/page-script/candidate-context.ts
|
|
34
|
+
var SECTIONING = "article,aside,main,nav,section";
|
|
35
|
+
var SECTION_TITLE_LIMIT = 60;
|
|
36
|
+
var CONTROL_SELECTOR = "button,a[href],[role='button'],input[type='button'],input[type='submit']";
|
|
37
|
+
var NAMED_SELECTOR = "[data-product-name],h1,h2,h3,h4,h5,h6,[role='heading']";
|
|
38
|
+
function createCandidateContext(deps) {
|
|
39
|
+
const titleCache = /* @__PURE__ */ new Map();
|
|
40
|
+
const outline = [];
|
|
41
|
+
function reset() {
|
|
42
|
+
titleCache.clear();
|
|
43
|
+
outline.length = 0;
|
|
44
|
+
}
|
|
45
|
+
function landmarkHint(node) {
|
|
46
|
+
return `${node.id} ${typeof node.className === "string" ? node.className : ""}`.toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
function semanticLandmark(node) {
|
|
49
|
+
const tag = node.tagName.toLowerCase();
|
|
50
|
+
const role = node.getAttribute("role");
|
|
51
|
+
if (["dialog", "alertdialog"].includes(role ?? "") || tag === "dialog")
|
|
52
|
+
return "dialog";
|
|
53
|
+
if (role === "banner" || isTopLevelHeader(node)) return "header";
|
|
54
|
+
if (role === "contentinfo" || isTopLevelFooter(node)) return "footer";
|
|
55
|
+
return mappedLandmark(node);
|
|
56
|
+
}
|
|
57
|
+
function isTopLevelHeader(node) {
|
|
58
|
+
if (node.tagName.toLowerCase() !== "header") return false;
|
|
59
|
+
return !node.parentElement?.closest(SECTIONING);
|
|
60
|
+
}
|
|
61
|
+
function isTopLevelFooter(node) {
|
|
62
|
+
if (node.tagName.toLowerCase() !== "footer") return false;
|
|
63
|
+
return !node.parentElement?.closest(SECTIONING);
|
|
64
|
+
}
|
|
65
|
+
function mappedLandmark(node) {
|
|
66
|
+
const landmarks = {
|
|
67
|
+
navigation: "navigation",
|
|
68
|
+
nav: "navigation",
|
|
69
|
+
complementary: "sidebar",
|
|
70
|
+
aside: "sidebar",
|
|
71
|
+
main: "main"
|
|
72
|
+
};
|
|
73
|
+
const role = node.getAttribute("role") ?? "";
|
|
74
|
+
return landmarks[role] ?? landmarks[node.tagName.toLowerCase()] ?? "";
|
|
75
|
+
}
|
|
76
|
+
function hintedLandmark(node) {
|
|
77
|
+
const hint = landmarkHint(node);
|
|
78
|
+
if (/(^|[\s_-])(site-?header|masthead|top-?bar|navbar|header)($|[\s_-])/.test(
|
|
79
|
+
hint
|
|
53
80
|
))
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
return "header";
|
|
82
|
+
if (/(^|[\s_-])(site-?footer|footer)($|[\s_-])/.test(hint)) return "footer";
|
|
83
|
+
return /(^|[\s_-])(sidebar|side-?nav|toc|table-of-contents)($|[\s_-])/.test(
|
|
84
|
+
hint
|
|
85
|
+
) ? "sidebar" : "";
|
|
86
|
+
}
|
|
87
|
+
function landmarkOf(node) {
|
|
88
|
+
return semanticLandmark(node) || hintedLandmark(node);
|
|
89
|
+
}
|
|
90
|
+
function landmarkRoot(element) {
|
|
91
|
+
let root = null;
|
|
92
|
+
for (let node = deps.composedParent(element); node && node !== deps.document.body; node = deps.composedParent(node))
|
|
93
|
+
if (landmarkOf(node)) root = node;
|
|
94
|
+
return root;
|
|
95
|
+
}
|
|
96
|
+
function observeHeading(element) {
|
|
97
|
+
if (!element.matches("h1,h2,h3,h4,h5,h6,[role='heading']")) return null;
|
|
98
|
+
const text = deps.visible(element) ? deps.publicText(element) : "";
|
|
99
|
+
if (!text || Array.from(text).length > 60) return null;
|
|
100
|
+
const heading = {
|
|
101
|
+
text,
|
|
102
|
+
root: landmarkRoot(element),
|
|
103
|
+
level: headingLevel(element)
|
|
104
|
+
};
|
|
105
|
+
while (outline.length && outline[outline.length - 1].level >= heading.level)
|
|
106
|
+
outline.pop();
|
|
107
|
+
outline.push(heading);
|
|
108
|
+
return heading;
|
|
109
|
+
}
|
|
110
|
+
function headingLevel(element) {
|
|
111
|
+
return Number(
|
|
112
|
+
/^h([1-6])$/i.exec(element.tagName)?.[1] ?? element.getAttribute("aria-level")
|
|
113
|
+
) || 2;
|
|
114
|
+
}
|
|
115
|
+
function locationOf(element, heading) {
|
|
116
|
+
const marks = [];
|
|
117
|
+
let root = null;
|
|
118
|
+
for (let node = deps.composedParent(element); node && node !== deps.document.body; node = deps.composedParent(node)) {
|
|
119
|
+
const mark = landmarkOf(node);
|
|
120
|
+
if (!mark) continue;
|
|
121
|
+
root = node;
|
|
122
|
+
if (!marks.includes(mark)) marks.unshift(mark);
|
|
65
123
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
124
|
+
const kept = marks.length > 2 ? [marks[0], marks[marks.length - 1]] : marks;
|
|
125
|
+
const parts = [
|
|
126
|
+
kept.join(", "),
|
|
127
|
+
heading.root === root ? heading.text : ""
|
|
128
|
+
].filter(Boolean);
|
|
129
|
+
return Array.from(parts.join(" \xB7 ")).slice(0, PEER_LIMIT).join("");
|
|
130
|
+
}
|
|
131
|
+
function shortText(element) {
|
|
132
|
+
if ((element.textContent ?? "").length > 400) return "";
|
|
133
|
+
const text = deps.publicText(element);
|
|
134
|
+
return Array.from(text).length <= SECTION_TITLE_LIMIT ? text : "";
|
|
135
|
+
}
|
|
136
|
+
function validTitleChild(child) {
|
|
137
|
+
if (child.matches("li,tr,option,[role='listitem'],[role='row']"))
|
|
68
138
|
return false;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!dialogs.length) return null;
|
|
85
|
-
const native = dialogs.filter(
|
|
86
|
-
(element) => element.matches("dialog:modal")
|
|
139
|
+
const controls = child.querySelectorAll(
|
|
140
|
+
"button,a[href],input,select,textarea,[role='button'],[role='link']"
|
|
141
|
+
).length;
|
|
142
|
+
return deps.interactive(child) ? controls === 0 : controls <= 1;
|
|
143
|
+
}
|
|
144
|
+
function titleFromChild(child) {
|
|
145
|
+
if (!validTitleChild(child)) return null;
|
|
146
|
+
const heading = child.matches("h1,h2,h3,h4,h5,h6,[role='heading']") ? child : child.querySelector("h1,h2,h3,h4,h5,h6,[role='heading']");
|
|
147
|
+
const text = shortText(heading ?? child);
|
|
148
|
+
return text && text.split(/\s+/).length <= 8 && !/^skip to\b/i.test(text) ? { child, text } : null;
|
|
149
|
+
}
|
|
150
|
+
function containerTitle(container) {
|
|
151
|
+
if (titleCache.has(container)) return titleCache.get(container);
|
|
152
|
+
const child = Array.from(container.children).find(
|
|
153
|
+
(item) => !!(item.textContent ?? "").trim() && deps.visible(item)
|
|
87
154
|
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
const found = child ? titleFromChild(child) : null;
|
|
156
|
+
titleCache.set(container, found);
|
|
157
|
+
return found;
|
|
158
|
+
}
|
|
159
|
+
function addLabel(labels, text) {
|
|
160
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
161
|
+
if (!validSectionLabel(labels, clean)) return;
|
|
162
|
+
labels.push(clean);
|
|
163
|
+
}
|
|
164
|
+
function validSectionLabel(labels, text) {
|
|
165
|
+
if (!text || Array.from(text).length > SECTION_TITLE_LIMIT) return false;
|
|
166
|
+
return !labels.includes(text);
|
|
167
|
+
}
|
|
168
|
+
function ariaLabel(node, element) {
|
|
169
|
+
const direct = node.getAttribute("aria-label");
|
|
170
|
+
if (direct) return direct;
|
|
171
|
+
return (node.getAttribute("aria-labelledby") ?? "").split(/\s+/).map((id) => deps.document.getElementById(id)).map(
|
|
172
|
+
(target) => target && target !== element ? deps.publicText(target) : ""
|
|
173
|
+
).join(" ");
|
|
174
|
+
}
|
|
175
|
+
function ownTitle(node, child) {
|
|
176
|
+
const selectors = [
|
|
177
|
+
["fieldset", "legend"],
|
|
178
|
+
["table", "caption"],
|
|
179
|
+
["figure", "figcaption"],
|
|
180
|
+
["details", "summary"]
|
|
181
|
+
];
|
|
182
|
+
const match = selectors.find(([container]) => node.matches(container));
|
|
183
|
+
const title = match && Array.from(node.children).find((item) => item.matches(match[1]));
|
|
184
|
+
return title && title !== child ? shortText(title) : "";
|
|
185
|
+
}
|
|
186
|
+
function collectSectionLabels(element) {
|
|
187
|
+
const labels = [];
|
|
188
|
+
let child = element;
|
|
189
|
+
let node = deps.composedParent(element);
|
|
190
|
+
for (let depth = 0; node && node !== deps.document.body && depth < 30 && labels.length < 6; depth++) {
|
|
191
|
+
collectNodeLabels(labels, node, child, element);
|
|
192
|
+
child = node;
|
|
193
|
+
node = deps.composedParent(node);
|
|
113
194
|
}
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (element instanceof HTMLTextAreaElement) return "textbox";
|
|
140
|
-
if (element instanceof HTMLSelectElement) return "combobox";
|
|
141
|
-
return "";
|
|
142
|
-
}, interactive = function(element) {
|
|
143
|
-
if (element.parentElement?.closest("a[href]")) return false;
|
|
144
|
-
return element.matches(
|
|
145
|
-
"button,a[href],input,textarea,select,[contenteditable]"
|
|
146
|
-
) || [
|
|
147
|
-
"button",
|
|
148
|
-
"link",
|
|
149
|
-
"checkbox",
|
|
150
|
-
"radio",
|
|
151
|
-
"switch",
|
|
152
|
-
"tab",
|
|
153
|
-
"menuitem",
|
|
154
|
-
"option",
|
|
155
|
-
"textbox",
|
|
156
|
-
"searchbox",
|
|
157
|
-
"combobox",
|
|
158
|
-
"spinbutton",
|
|
159
|
-
"slider"
|
|
160
|
-
].includes(role(element));
|
|
161
|
-
}, readable = function(element) {
|
|
162
|
-
if (interactive(element) || excludedTextAncestor(element, true))
|
|
163
|
-
return false;
|
|
164
|
-
if (element.matches("h1,h2,h3,h4,h5,h6,p,blockquote,td,th,[role='heading']"))
|
|
165
|
-
return true;
|
|
166
|
-
return element.children.length === 0 && element.matches("span,strong,em,div,li") && publicText(element).length > 0;
|
|
167
|
-
}, editable = function(element) {
|
|
168
|
-
if (element instanceof HTMLInputElement)
|
|
169
|
-
return FILLABLE_INPUT_TYPES.has(element.type) && !disabled(element);
|
|
170
|
-
if (element instanceof HTMLTextAreaElement) return !disabled(element);
|
|
171
|
-
return element instanceof HTMLElement && element.isContentEditable && !disabled(element);
|
|
172
|
-
}, disabled = function(element) {
|
|
173
|
-
return element.matches(":disabled,[aria-disabled='true']") || !!element.closest("[inert]");
|
|
174
|
-
}, path = function(element) {
|
|
195
|
+
return labels;
|
|
196
|
+
}
|
|
197
|
+
function collectNodeLabels(labels, node, child, element) {
|
|
198
|
+
if (!deps.interactive(node)) addLabel(labels, ariaLabel(node, element));
|
|
199
|
+
addLabel(labels, ownTitle(node, child));
|
|
200
|
+
const title = containerTitle(node);
|
|
201
|
+
if (!titleApplies(title, child, element)) return;
|
|
202
|
+
addLabel(labels, title.text);
|
|
203
|
+
}
|
|
204
|
+
function titleApplies(title, child, element) {
|
|
205
|
+
if (!title || title.child === child) return false;
|
|
206
|
+
return !title.child.contains(element);
|
|
207
|
+
}
|
|
208
|
+
function sectionOf(element) {
|
|
209
|
+
const labels = collectSectionLabels(element);
|
|
210
|
+
const root = landmarkRoot(element);
|
|
211
|
+
for (let index = outline.length - 1; index >= 0; index--)
|
|
212
|
+
if (outline[index].root === root) addLabel(labels, outline[index].text);
|
|
213
|
+
return Array.from(labels.slice(0, 6).join(" \u203A ")).slice(0, 300).join("");
|
|
214
|
+
}
|
|
215
|
+
function boundedName(name) {
|
|
216
|
+
const points = Array.from(name);
|
|
217
|
+
return points.length <= NAME_LIMIT ? name : points.slice(0, NAME_LIMIT - 1).join("") + "\u2026";
|
|
218
|
+
}
|
|
219
|
+
function path(element) {
|
|
175
220
|
const steps = [];
|
|
176
221
|
for (let node = element; node && steps.length < 12; node = node.parentElement) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
(child) => child.tagName === node?.tagName
|
|
222
|
+
const siblings = node.parentElement ? Array.from(node.parentElement.children).filter(
|
|
223
|
+
(child) => child.tagName === node.tagName
|
|
180
224
|
) : [node];
|
|
181
225
|
steps.unshift(`${node.tagName.toLowerCase()}:${siblings.indexOf(node)}`);
|
|
182
226
|
}
|
|
183
227
|
return steps.join("/");
|
|
184
|
-
}
|
|
228
|
+
}
|
|
229
|
+
function inArticleBody(element) {
|
|
185
230
|
return !!element.closest("main,article,[role='main']") && !element.closest("aside,nav,table,[role='navigation'],.infobox,.navbox");
|
|
186
|
-
}
|
|
187
|
-
|
|
231
|
+
}
|
|
232
|
+
function itemContext(region) {
|
|
233
|
+
const walker = deps.document.createTreeWalker(region, NodeFilter.SHOW_TEXT);
|
|
188
234
|
const pieces = [];
|
|
189
235
|
let length = 0;
|
|
190
236
|
while (walker.nextNode()) {
|
|
191
237
|
const parent = walker.currentNode.parentElement;
|
|
192
|
-
if (!
|
|
193
|
-
continue;
|
|
238
|
+
if (!usableTextParent(parent)) continue;
|
|
194
239
|
const part = (walker.currentNode.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
195
240
|
if (!part) continue;
|
|
196
241
|
length += Array.from(part).length + (pieces.length ? 1 : 0);
|
|
@@ -198,165 +243,1729 @@ var SedumPageScript = (() => {
|
|
|
198
243
|
pieces.push(part);
|
|
199
244
|
}
|
|
200
245
|
return { text: pieces.join(" "), complete: true };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
246
|
+
}
|
|
247
|
+
function usableTextParent(parent) {
|
|
248
|
+
if (!parent || !deps.visible(parent)) return false;
|
|
249
|
+
return !deps.excludedTextAncestor(parent, true);
|
|
250
|
+
}
|
|
251
|
+
function rankedPeer(element) {
|
|
252
|
+
const preceding = element.closest("tr")?.previousElementSibling;
|
|
204
253
|
const rank = preceding?.querySelector(".rank");
|
|
205
254
|
const title = preceding?.querySelector(".titleline > a");
|
|
206
|
-
|
|
207
|
-
|
|
255
|
+
if (!rank || !title) return "";
|
|
256
|
+
return Array.from(
|
|
257
|
+
`${deps.publicText(rank)} ${deps.publicText(title)}`.trim()
|
|
258
|
+
).slice(0, PEER_LIMIT).join("");
|
|
259
|
+
}
|
|
260
|
+
function hasRepeatedCard(region) {
|
|
261
|
+
if (!region.classList.length) return false;
|
|
262
|
+
return Array.from(region.parentElement?.children ?? []).some(
|
|
263
|
+
(sibling) => sibling !== region && sibling.tagName === region.tagName && sibling.classList.length === region.classList.length && Array.from(region.classList).every(
|
|
264
|
+
(name) => sibling.classList.contains(name)
|
|
265
|
+
)
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
function sameNamedCount(possible, name) {
|
|
269
|
+
return possible.filter((item) => isSameNamedControl(item, name)).length;
|
|
270
|
+
}
|
|
271
|
+
function isSameNamedControl(item, name) {
|
|
272
|
+
if (!deps.visible(item) && !deps.hoverRevealed(item)) return false;
|
|
273
|
+
return (deps.label(item) || deps.mediaName(item) || deps.iconName(item)) === name;
|
|
274
|
+
}
|
|
275
|
+
function controlsIn(region) {
|
|
276
|
+
const scope = deps.allElements(region, 2e3);
|
|
277
|
+
if (!scope) return null;
|
|
278
|
+
return scope.filter((item) => item.matches(CONTROL_SELECTOR));
|
|
279
|
+
}
|
|
280
|
+
function exceedsPeerScope(possible, name) {
|
|
281
|
+
if (!possible || possible.length > 32) return true;
|
|
282
|
+
return sameNamedCount(possible, name) > 1;
|
|
283
|
+
}
|
|
284
|
+
function isItemBoundary(region, operation) {
|
|
285
|
+
if (region.matches("article,li,[data-product],[role='listitem']"))
|
|
286
|
+
return true;
|
|
287
|
+
if (operation === "click") return deps.pointerTarget(region);
|
|
288
|
+
return operation === "read" && hasRepeatedCard(region);
|
|
289
|
+
}
|
|
290
|
+
function findPeerRegion(element, name, operation) {
|
|
291
|
+
let region = deps.composedParent(element);
|
|
208
292
|
let lastUnique = null;
|
|
209
|
-
while (region && region !== document.body) {
|
|
210
|
-
|
|
211
|
-
"button,a[href],[role='button'],input[type='button'],input[type='submit']"
|
|
212
|
-
);
|
|
213
|
-
if (possible.length > 32) {
|
|
214
|
-
region = lastUnique;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
const sameLabel = Array.from(possible).filter(
|
|
218
|
-
(item) => visible(item) && label(item) === name
|
|
219
|
-
);
|
|
220
|
-
if (sameLabel.length > 1) {
|
|
221
|
-
region = lastUnique;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
293
|
+
while (region && region !== deps.document.body) {
|
|
294
|
+
if (exceedsPeerScope(controlsIn(region), name)) return lastUnique;
|
|
224
295
|
lastUnique = region;
|
|
225
|
-
if (region
|
|
226
|
-
region = region
|
|
296
|
+
if (isItemBoundary(region, operation)) break;
|
|
297
|
+
region = deps.composedParent(region);
|
|
298
|
+
}
|
|
299
|
+
return region === deps.document.body ? lastUnique : region;
|
|
300
|
+
}
|
|
301
|
+
function peerChildren(region) {
|
|
302
|
+
const named = Array.from(region.querySelectorAll(NAMED_SELECTOR));
|
|
303
|
+
const leaves = Array.from(region.querySelectorAll("div,span,strong,p")).filter(
|
|
304
|
+
(child) => child.children.length === 0 && !isWeakPeer(deps.publicText(child))
|
|
305
|
+
).sort(
|
|
306
|
+
(a, b) => Number(b.tagName === "DIV") - Number(a.tagName === "DIV")
|
|
307
|
+
);
|
|
308
|
+
return [
|
|
309
|
+
...named,
|
|
310
|
+
...leaves,
|
|
311
|
+
...Array.from(region.querySelectorAll("strong,span,p"))
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
function appendPeerTexts(result, region, element, name) {
|
|
315
|
+
for (const child of peerChildren(region)) {
|
|
316
|
+
if (result.length === 2) break;
|
|
317
|
+
if (!usablePeerChild(child, element)) continue;
|
|
318
|
+
const text = Array.from(deps.publicText(child)).slice(0, PEER_LIMIT).join("");
|
|
319
|
+
if (newPeerText(result, text, name)) result.push(text);
|
|
227
320
|
}
|
|
228
|
-
|
|
321
|
+
}
|
|
322
|
+
function usablePeerChild(child, element) {
|
|
323
|
+
if (child === element || child.contains(element)) return false;
|
|
324
|
+
if (element.contains(child)) return false;
|
|
325
|
+
return deps.visible(child);
|
|
326
|
+
}
|
|
327
|
+
function newPeerText(result, text, name) {
|
|
328
|
+
if (!text || text === name) return false;
|
|
329
|
+
return !result.includes(text);
|
|
330
|
+
}
|
|
331
|
+
function itemText(region, ranked) {
|
|
332
|
+
const text = `${ranked} ${deps.publicText(region)}`.replace(/\s+/g, " ").trim();
|
|
333
|
+
return Array.from(text).slice(0, 300).join("");
|
|
334
|
+
}
|
|
335
|
+
function peerResult(texts, context, ranked, item) {
|
|
336
|
+
const result = {
|
|
337
|
+
texts,
|
|
338
|
+
contextComplete: !ranked && context.complete && !!context.text
|
|
339
|
+
};
|
|
340
|
+
return item && (context.text || ranked) ? { ...result, item } : result;
|
|
341
|
+
}
|
|
342
|
+
function peers(element, name, operation = "click") {
|
|
343
|
+
const ranked = rankedPeer(element);
|
|
344
|
+
const region = findPeerRegion(element, name, operation);
|
|
229
345
|
if (!region)
|
|
230
|
-
return { texts:
|
|
231
|
-
const result = [];
|
|
232
|
-
|
|
346
|
+
return { texts: ranked ? [ranked] : [], contextComplete: false };
|
|
347
|
+
const result = ranked ? [ranked] : [];
|
|
348
|
+
const item = itemText(region, ranked);
|
|
233
349
|
const context = itemContext(region);
|
|
234
350
|
if (context.text && result.length < 2) result.push(context.text);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
351
|
+
appendPeerTexts(result, region, element, name);
|
|
352
|
+
return peerResult(result, context, ranked, item);
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
reset,
|
|
356
|
+
observeHeading,
|
|
357
|
+
locationOf,
|
|
358
|
+
sectionOf,
|
|
359
|
+
boundedName,
|
|
360
|
+
path,
|
|
361
|
+
inArticleBody,
|
|
362
|
+
peers
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/page-script/candidate-name-icons.ts
|
|
367
|
+
var ICON_KINDS = [
|
|
368
|
+
[/(?:^|-)(?:up-?vote|vote-?up|votearrow)(?:$|-)/, "upvote arrow"],
|
|
369
|
+
[/(?:^|-)(?:down-?vote|vote-?down)(?:$|-)/, "downvote arrow"],
|
|
370
|
+
[/(?:^|-)(?:search|magnifier|magnifying|loupe)(?:$|-)/, "search"],
|
|
371
|
+
[/(?:^|-)(?:hamburger|burger|menu|bars)(?:$|-)/, "menu"],
|
|
372
|
+
[/(?:^|-)(?:close|dismiss|xmark|x-mark|times)(?:$|-)/, "close"],
|
|
373
|
+
[
|
|
374
|
+
/(?:^|-)(?:(?:arrow|chevron|caret|angle|paddlenav)-?(?:right|next|forward)|(?:right|next|forward)-?(?:arrow|chevron|caret))(?:$|-)/,
|
|
375
|
+
"right arrow"
|
|
376
|
+
],
|
|
377
|
+
[
|
|
378
|
+
/(?:^|-)(?:(?:arrow|chevron|caret|angle|paddlenav)-?(?:left|prev|previous|back)|(?:left|prev|previous|back)-?(?:arrow|chevron|caret))(?:$|-)/,
|
|
379
|
+
"left arrow"
|
|
380
|
+
],
|
|
381
|
+
[/(?:^|-)(?:terminal|shell|console|prompt)(?:$|-)/, "terminal"],
|
|
382
|
+
[/(?:^|-)(?:cart|basket)(?:$|-)/, "cart"],
|
|
383
|
+
[/(?:^|-)(?:kebab|ellipsis|more|dots)(?:$|-)/, "more"],
|
|
384
|
+
[/(?:^|-)(?:settings|gear|cog)(?:$|-)/, "settings"],
|
|
385
|
+
[/(?:^|-)share(?:$|-)/, "share"],
|
|
386
|
+
[/(?:^|-)(?:copy|clipboard)(?:$|-)/, "copy"],
|
|
387
|
+
[/(?:^|-)(?:bell|notifications?)(?:$|-)/, "notifications"],
|
|
388
|
+
[/(?:^|-)(?:avatar|account|profile|user)(?:$|-)/, "account"],
|
|
389
|
+
[/(?:^|-)play(?:$|-)/, "play"],
|
|
390
|
+
[/(?:^|-)pause(?:$|-)/, "pause"]
|
|
391
|
+
];
|
|
392
|
+
function iconKind(tokens) {
|
|
393
|
+
return ICON_KINDS.find(
|
|
394
|
+
([pattern]) => tokens.some((token) => pattern.test(token))
|
|
395
|
+
)?.[1] ?? "";
|
|
396
|
+
}
|
|
397
|
+
function hintWords(text) {
|
|
398
|
+
return text.toLocaleLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
399
|
+
}
|
|
400
|
+
function addsWords(text, name) {
|
|
401
|
+
const own = new Set(hintWords(name));
|
|
402
|
+
return hintWords(text).some(
|
|
403
|
+
(word) => word.length > 1 && /\p{L}/u.test(word) && !own.has(word)
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
function includesHintWord(text, word) {
|
|
407
|
+
return hintWords(text).includes(word);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/page-script/candidate-name-hints.ts
|
|
411
|
+
function clip({ text, limit = 48 }) {
|
|
412
|
+
return text.length > limit ? text.slice(0, limit - 1) + "\u2026" : text;
|
|
413
|
+
}
|
|
414
|
+
var HintCollector = class {
|
|
415
|
+
constructor(name) {
|
|
416
|
+
this.name = name;
|
|
417
|
+
}
|
|
418
|
+
name;
|
|
419
|
+
parts = [];
|
|
420
|
+
add(text, payload = text) {
|
|
421
|
+
if (payload && addsWords(payload, [this.name, ...this.parts].join(" ")))
|
|
422
|
+
this.parts.push(text);
|
|
423
|
+
}
|
|
424
|
+
addLiteral(text) {
|
|
425
|
+
this.parts.push(text);
|
|
426
|
+
}
|
|
427
|
+
includes(word) {
|
|
428
|
+
return includesHintWord([this.name, ...this.parts].join(" "), word);
|
|
429
|
+
}
|
|
430
|
+
toString() {
|
|
431
|
+
return this.parts.join(", ");
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
function hasAuthoredFieldLabel(element, referencedLabelText, publicText) {
|
|
435
|
+
if (element.getAttribute("aria-label")?.trim()) return true;
|
|
436
|
+
const referenced = element.getAttribute("aria-labelledby")?.split(/\s+/).some((id) => {
|
|
437
|
+
const node = document.getElementById(id);
|
|
438
|
+
return !!node && !!referencedLabelText(node);
|
|
439
|
+
});
|
|
440
|
+
if (referenced) return true;
|
|
441
|
+
return Array.from(element.labels ?? []).some(
|
|
442
|
+
(node) => !!publicText(node).trim()
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
function addFieldHints(context) {
|
|
446
|
+
const { element, name, collector, dependencies, names } = context;
|
|
447
|
+
if (!isTextEntry(element)) return;
|
|
448
|
+
const placeholder = element.getAttribute("placeholder")?.trim() ?? "";
|
|
449
|
+
addPlaceholderHint(context, placeholder);
|
|
450
|
+
if (!placeholder || placeholder !== name) return;
|
|
451
|
+
if (hasAuthoredFieldLabel(
|
|
452
|
+
element,
|
|
453
|
+
names.referencedLabelText,
|
|
454
|
+
dependencies.publicText
|
|
455
|
+
))
|
|
456
|
+
return;
|
|
457
|
+
addCaptionHint(element, placeholder, collector, names);
|
|
458
|
+
}
|
|
459
|
+
function isTextEntry(element) {
|
|
460
|
+
return element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement;
|
|
461
|
+
}
|
|
462
|
+
function addCaptionHint(element, placeholder, collector, names) {
|
|
463
|
+
const caption = names.nearbyText(element) || names.rowLabel(element);
|
|
464
|
+
if (caption && caption !== placeholder)
|
|
465
|
+
collector.add(`label "${clip({ text: caption })}"`, caption);
|
|
466
|
+
}
|
|
467
|
+
function addPlaceholderHint(context, placeholder) {
|
|
468
|
+
if (placeholder && placeholder !== context.name)
|
|
469
|
+
context.collector.add(
|
|
470
|
+
`placeholder "${clip({ text: placeholder })}"`,
|
|
471
|
+
placeholder
|
|
239
472
|
);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
473
|
+
}
|
|
474
|
+
function addVisibleTextHints(element, name, collector, publicText, referencedLabelText) {
|
|
475
|
+
const shown = publicText(element, true);
|
|
476
|
+
const explicitlyNamed = element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby");
|
|
477
|
+
if (explicitlyNamed && shown)
|
|
478
|
+
collector.add(`shows "${clip({ text: shown })}"`, shown);
|
|
479
|
+
if (!/\p{L}/u.test(name)) {
|
|
480
|
+
const hidden = referencedLabelText(element);
|
|
481
|
+
if (/\p{L}/u.test(hidden))
|
|
482
|
+
collector.add(`text "${clip({ text: hidden })}"`, hidden);
|
|
483
|
+
}
|
|
484
|
+
return shown;
|
|
485
|
+
}
|
|
486
|
+
function hintNodes(element) {
|
|
487
|
+
return Array.from(
|
|
488
|
+
element.querySelectorAll("img,svg,i,span:empty,div:empty,use,kbd")
|
|
489
|
+
).slice(0, 12);
|
|
490
|
+
}
|
|
491
|
+
function tokenValues(element, nodes) {
|
|
492
|
+
return [element, ...nodes].flatMap((node) => [
|
|
493
|
+
node.getAttribute("class") ?? "",
|
|
494
|
+
node.id,
|
|
495
|
+
node.getAttribute("data-icon") ?? "",
|
|
496
|
+
node === element ? "" : node.getAttribute("title") ?? "",
|
|
497
|
+
node.matches("use") ? node.getAttribute("href") ?? "" : "",
|
|
498
|
+
node.matches("use") ? node.getAttribute("xlink:href") ?? "" : "",
|
|
499
|
+
node instanceof HTMLImageElement ? node.alt : "",
|
|
500
|
+
node === element ? "" : node.getAttribute("aria-label") ?? ""
|
|
501
|
+
]);
|
|
502
|
+
}
|
|
503
|
+
function iconTokens(element, nodes) {
|
|
504
|
+
return tokenValues(element, nodes).join(" ").toLocaleLowerCase().split(/\s+/).map((token) => token.replace(/[_:#/.]+/g, "-")).filter(Boolean);
|
|
505
|
+
}
|
|
506
|
+
function isSiteRootLink(element) {
|
|
507
|
+
const href = element.getAttribute("href")?.trim();
|
|
508
|
+
if (!href) return false;
|
|
509
|
+
if (/^(?:\/|\.\/|\/index\.html?|\/home(?:page)?\/?)$/i.test(href))
|
|
510
|
+
return true;
|
|
511
|
+
try {
|
|
512
|
+
const url = new URL(href, location.href);
|
|
513
|
+
return remoteRootMatchesSite(url);
|
|
514
|
+
} catch {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function remoteRootMatchesSite(url) {
|
|
519
|
+
if (url.pathname !== "/") return false;
|
|
520
|
+
if (url.search) return false;
|
|
521
|
+
if (url.host === location.host) return true;
|
|
522
|
+
const canonical = document.querySelector("link[rel='canonical']")?.getAttribute("href") ?? document.querySelector("meta[property='og:url']")?.getAttribute("content");
|
|
523
|
+
return !!canonical && new URL(canonical, location.href).host === url.host;
|
|
524
|
+
}
|
|
525
|
+
function mediaLabel(media) {
|
|
526
|
+
return media.map(
|
|
527
|
+
(node) => node instanceof HTMLImageElement ? node.alt : node.getAttribute("aria-label") ?? node.querySelector("title")?.textContent ?? ""
|
|
528
|
+
).map((text) => text.replace(/\s+/g, " ").trim()).find(Boolean) ?? "";
|
|
529
|
+
}
|
|
530
|
+
function addLogoHints(element, name, media, collector) {
|
|
531
|
+
const label = mediaLabel(media);
|
|
532
|
+
if (label) collector.add(`${clip({ text: label, limit: 32 })} logo`, label);
|
|
533
|
+
if (!collector.includes("logo")) collector.addLiteral("logo");
|
|
534
|
+
if (isSiteRootLink(element) && !/\bhome/i.test(name))
|
|
535
|
+
collector.add("home link");
|
|
536
|
+
}
|
|
537
|
+
function keyboardText(element, publicText) {
|
|
538
|
+
return Array.from(element.querySelectorAll("kbd")).map((node) => publicText(node, true)).join(" ").replace(/\s+/g, " ").trim();
|
|
539
|
+
}
|
|
540
|
+
function addIconHints(context, shown) {
|
|
541
|
+
const { element, name, collector, dependencies } = context;
|
|
542
|
+
const inside = hintNodes(element);
|
|
543
|
+
const media = inside.filter((node) => node.matches("img,svg"));
|
|
544
|
+
const tokens = iconTokens(element, inside);
|
|
545
|
+
const rootLink = isRootLink(element, dependencies.role);
|
|
546
|
+
const keys = keyboardText(element, dependencies.publicText);
|
|
547
|
+
const keyOnly = !!keys && keys === shown;
|
|
548
|
+
const iconOnly = !/\p{L}/u.test(shown) || keyOnly;
|
|
549
|
+
const logo = isLogo(media, rootLink, tokens);
|
|
550
|
+
if (logo) addLogoHints(element, name, media, collector);
|
|
551
|
+
else if (iconOnly && hasIconEvidence(inside, name))
|
|
552
|
+
addIconKind(iconKind(tokens), collector);
|
|
553
|
+
if (keyOnly) collector.add("keyboard shortcut");
|
|
554
|
+
}
|
|
555
|
+
function isRootLink(element, role) {
|
|
556
|
+
const link = element.matches("a[href]") || role(element) === "link";
|
|
557
|
+
return link && isSiteRootLink(element);
|
|
558
|
+
}
|
|
559
|
+
function isLogo(media, rootLink, tokens) {
|
|
560
|
+
if (!media.length) return false;
|
|
561
|
+
if (rootLink) return true;
|
|
562
|
+
return tokens.some((token) => /logo|brand/.test(token));
|
|
563
|
+
}
|
|
564
|
+
function hasIconEvidence(inside, name) {
|
|
565
|
+
return !!inside.length || !/\p{L}/u.test(name);
|
|
566
|
+
}
|
|
567
|
+
function addIconKind(kind, collector) {
|
|
568
|
+
if (kind) collector.add(`${kind} icon`, kind);
|
|
569
|
+
}
|
|
570
|
+
function menuGlyph(node) {
|
|
571
|
+
return Array.from(node.querySelectorAll("i,span,em")).flatMap((icon) => Array.from(icon.classList)).map(
|
|
572
|
+
(token) => /^(?:fa|bi|icon|mdi|ti|ri)-([a-z][a-z0-9-]*)$/.exec(token)?.[1]
|
|
573
|
+
).find(
|
|
574
|
+
(name) => !!name && !/^(lg|[0-9]x|fw|solid|regular|light)$/.test(name)
|
|
575
|
+
)?.replace(/-/g, " ") ?? "";
|
|
576
|
+
}
|
|
577
|
+
function addMenuHint(element, collector, dependencies, referencedLabelText) {
|
|
578
|
+
const items = Array.from(element.querySelectorAll("*")).filter(
|
|
579
|
+
(node) => node !== element && dependencies.interactive(node) && !dependencies.visible(node)
|
|
580
|
+
).slice(0, 6).map(
|
|
581
|
+
(node) => [menuGlyph(node), referencedLabelText(node)].filter(Boolean).join(" ")
|
|
582
|
+
).filter(Boolean);
|
|
583
|
+
if (items.length)
|
|
584
|
+
collector.add(
|
|
585
|
+
`menu "${clip({ text: items.join(", "), limit: 80 })}"`,
|
|
586
|
+
items.join(" ")
|
|
246
587
|
);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
588
|
+
}
|
|
589
|
+
function createNameHint(dependencies, names) {
|
|
590
|
+
return (element, name) => {
|
|
591
|
+
const collector = new HintCollector(name);
|
|
592
|
+
const context = { element, name, collector, dependencies, names };
|
|
593
|
+
addFieldHints(context);
|
|
594
|
+
const shown = addVisibleTextHints(
|
|
595
|
+
element,
|
|
596
|
+
name,
|
|
597
|
+
collector,
|
|
598
|
+
dependencies.publicText,
|
|
599
|
+
names.referencedLabelText
|
|
600
|
+
);
|
|
601
|
+
addIconHints(context, shown);
|
|
602
|
+
addMenuHint(element, collector, dependencies, names.referencedLabelText);
|
|
603
|
+
return collector.toString();
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/page-script/candidate-name-labels.ts
|
|
608
|
+
function normalizedText(value) {
|
|
609
|
+
return (value ?? "").replace(/\s+/g, " ").trim();
|
|
610
|
+
}
|
|
611
|
+
function createLabelNames({ publicText }) {
|
|
612
|
+
function referencedLabelText(element) {
|
|
613
|
+
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
|
614
|
+
const parts = [];
|
|
615
|
+
while (walker.nextNode()) {
|
|
616
|
+
const parent = walker.currentNode.parentElement;
|
|
617
|
+
if (!parent?.closest(
|
|
618
|
+
"script,style,noscript,input,textarea,select,[contenteditable]"
|
|
619
|
+
))
|
|
620
|
+
parts.push(walker.currentNode.textContent ?? "");
|
|
621
|
+
}
|
|
622
|
+
return normalizedText(parts.join(" "));
|
|
623
|
+
}
|
|
624
|
+
function ariaLabel(element) {
|
|
625
|
+
return element.getAttribute("aria-label")?.trim() ?? "";
|
|
626
|
+
}
|
|
627
|
+
function labelledByText(element) {
|
|
628
|
+
return (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).map((id) => document.getElementById(id)).map((node) => node ? referencedLabelText(node) : "").filter(Boolean).join(" ");
|
|
629
|
+
}
|
|
630
|
+
function nativeLabelText(element) {
|
|
631
|
+
if (!(element instanceof HTMLElement) || !("labels" in element)) return "";
|
|
632
|
+
const labels = element.labels;
|
|
633
|
+
if (!labels?.length) return "";
|
|
634
|
+
return Array.from(labels).map((label2) => publicText(label2)).join(" ").trim();
|
|
635
|
+
}
|
|
636
|
+
function placeholderText(element) {
|
|
637
|
+
if (!(element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement))
|
|
638
|
+
return "";
|
|
639
|
+
return element.getAttribute("placeholder")?.trim() ?? "";
|
|
640
|
+
}
|
|
641
|
+
function inputButtonValue(element) {
|
|
642
|
+
if (!(element instanceof HTMLInputElement)) return "";
|
|
643
|
+
if (!["button", "submit", "reset"].includes(element.type)) return "";
|
|
644
|
+
return element.value.trim();
|
|
645
|
+
}
|
|
646
|
+
function ownText(element, visualOnly) {
|
|
647
|
+
return publicText(element, visualOnly, true);
|
|
648
|
+
}
|
|
649
|
+
function titleText(element) {
|
|
650
|
+
return element.getAttribute("title")?.trim() ?? "";
|
|
651
|
+
}
|
|
652
|
+
function label(element, visualOnly = false) {
|
|
653
|
+
const sources = [
|
|
654
|
+
ariaLabel,
|
|
655
|
+
labelledByText,
|
|
656
|
+
nativeLabelText,
|
|
657
|
+
placeholderText,
|
|
658
|
+
inputButtonValue,
|
|
659
|
+
(node) => ownText(node, visualOnly),
|
|
660
|
+
titleText
|
|
661
|
+
];
|
|
662
|
+
for (const source of sources) {
|
|
663
|
+
const value = source(element);
|
|
664
|
+
if (value) return value;
|
|
665
|
+
}
|
|
666
|
+
return "";
|
|
667
|
+
}
|
|
668
|
+
return { referencedLabelText, label };
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// src/page-script/candidate-name-spatial.ts
|
|
672
|
+
function normalizedText2(node) {
|
|
673
|
+
return (node.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
674
|
+
}
|
|
675
|
+
function textRect(node) {
|
|
676
|
+
const range = document.createRange();
|
|
677
|
+
range.selectNodeContents(node);
|
|
678
|
+
return range.getBoundingClientRect();
|
|
679
|
+
}
|
|
680
|
+
function visibleRect(rect) {
|
|
681
|
+
return !!rect.width && !!rect.height;
|
|
682
|
+
}
|
|
683
|
+
function lineAligned(first, second) {
|
|
684
|
+
const firstMiddle = first.top + first.height / 2;
|
|
685
|
+
const secondMiddle = second.top + second.height / 2;
|
|
686
|
+
return Math.abs(firstMiddle - secondMiddle) < Math.max(first.height, second.height) / 2;
|
|
687
|
+
}
|
|
688
|
+
function nearbyDistance(box, rect) {
|
|
689
|
+
if (lineAligned(box, rect)) return horizontalDistance(box, rect);
|
|
690
|
+
const overlapsColumn = rect.left < box.right && rect.right > box.left;
|
|
691
|
+
if (overlapsColumn && rect.bottom <= box.top + 2)
|
|
692
|
+
return box.top - rect.bottom;
|
|
693
|
+
return Infinity;
|
|
694
|
+
}
|
|
695
|
+
function horizontalDistance(box, rect) {
|
|
696
|
+
if (rect.left >= box.right - 2) return rect.left - box.right;
|
|
697
|
+
if (rect.right <= box.left + 2) return box.left - rect.right;
|
|
698
|
+
return Infinity;
|
|
699
|
+
}
|
|
700
|
+
function rowDistance(box, rect) {
|
|
701
|
+
if (lineAligned(box, rect)) return horizontalDistance(box, rect);
|
|
702
|
+
if (rect.bottom <= box.top + 2 && rect.left < box.right)
|
|
703
|
+
return box.top - rect.bottom;
|
|
704
|
+
return Infinity;
|
|
705
|
+
}
|
|
706
|
+
function closer(best, candidate) {
|
|
707
|
+
return !best || candidate.distance < best.distance ? candidate : best;
|
|
708
|
+
}
|
|
709
|
+
function createSpatialNames(dependencies) {
|
|
710
|
+
const {
|
|
711
|
+
allElements,
|
|
712
|
+
composedParent,
|
|
713
|
+
deepContains,
|
|
714
|
+
excludedTextAncestor,
|
|
715
|
+
flatTextNodes,
|
|
716
|
+
interactive,
|
|
717
|
+
visible
|
|
718
|
+
} = dependencies;
|
|
719
|
+
function unavailableParent(element, parent) {
|
|
720
|
+
if (deepContains(element, parent)) return true;
|
|
721
|
+
if (excludedTextAncestor(parent, true)) return true;
|
|
722
|
+
return !visible(parent);
|
|
723
|
+
}
|
|
724
|
+
function eligibleText(element, node, excludeLabels) {
|
|
725
|
+
const parent = node.parentElement;
|
|
726
|
+
const text = normalizedText2(node);
|
|
727
|
+
if (!parent || !text) return null;
|
|
728
|
+
if (unavailableParent(element, parent)) return null;
|
|
729
|
+
const labelsControl = parent.closest("label")?.control;
|
|
730
|
+
if (excludeLabels && labelsControl) return null;
|
|
731
|
+
const rect = textRect(node);
|
|
732
|
+
return visibleRect(rect) ? { text, rect } : null;
|
|
733
|
+
}
|
|
734
|
+
function bestText(search) {
|
|
735
|
+
let best = null;
|
|
736
|
+
for (const node of flatTextNodes(search.root)) {
|
|
737
|
+
const position = eligibleText(search.element, node, search.excludeLabels);
|
|
738
|
+
if (!position) continue;
|
|
739
|
+
const distance = search.distanceFor(search.box, position.rect);
|
|
740
|
+
if (distance <= search.limit)
|
|
741
|
+
best = closer(best, { text: position.text, distance });
|
|
742
|
+
}
|
|
743
|
+
return best;
|
|
744
|
+
}
|
|
745
|
+
function nearbyText(element) {
|
|
746
|
+
const box = element.getBoundingClientRect();
|
|
747
|
+
if (!box.width || !box.height) return "";
|
|
748
|
+
let scope = composedParent(element);
|
|
749
|
+
for (let level = 0; scope && level < 3; level++) {
|
|
750
|
+
const best = bestText({
|
|
751
|
+
element,
|
|
752
|
+
root: scope,
|
|
753
|
+
box,
|
|
754
|
+
distanceFor: nearbyDistance,
|
|
755
|
+
limit: 48,
|
|
756
|
+
excludeLabels: true
|
|
757
|
+
});
|
|
758
|
+
if (best) return best.text;
|
|
759
|
+
scope = composedParent(scope);
|
|
760
|
+
}
|
|
761
|
+
return "";
|
|
762
|
+
}
|
|
763
|
+
function rowContainer(element) {
|
|
764
|
+
let row = null;
|
|
765
|
+
let node = composedParent(element);
|
|
766
|
+
for (let level = 0; node && node !== document.body && level < 7; level++) {
|
|
767
|
+
const inside = allElements(node, 400);
|
|
768
|
+
if (!inside) break;
|
|
769
|
+
const otherControl = inside.some(
|
|
770
|
+
(other) => other !== element && interactive(other) && visible(other)
|
|
771
|
+
);
|
|
772
|
+
if (otherControl) break;
|
|
773
|
+
row = node;
|
|
774
|
+
node = composedParent(node);
|
|
775
|
+
}
|
|
776
|
+
return row;
|
|
777
|
+
}
|
|
778
|
+
function rowLabel(element) {
|
|
779
|
+
if (!element.matches(
|
|
780
|
+
"input,textarea,select,[role='combobox'],[role='textbox']"
|
|
781
|
+
))
|
|
782
|
+
return "";
|
|
783
|
+
const box = element.getBoundingClientRect();
|
|
784
|
+
if (!box.width || !box.height) return "";
|
|
785
|
+
const row = rowContainer(element);
|
|
786
|
+
return row ? bestText({
|
|
787
|
+
element,
|
|
788
|
+
root: row,
|
|
789
|
+
box,
|
|
790
|
+
distanceFor: rowDistance,
|
|
791
|
+
limit: 400,
|
|
792
|
+
excludeLabels: false
|
|
793
|
+
})?.text ?? "" : "";
|
|
794
|
+
}
|
|
795
|
+
return { nearbyText, rowLabel };
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// src/page-script/candidate-names-implementation.ts
|
|
799
|
+
function createCandidateNamesImplementation(dependencies) {
|
|
800
|
+
const {
|
|
801
|
+
allElements,
|
|
802
|
+
composedParent,
|
|
803
|
+
flatTextNodes,
|
|
804
|
+
interactive,
|
|
805
|
+
publicText,
|
|
806
|
+
role,
|
|
807
|
+
visible,
|
|
808
|
+
insideNestedControl,
|
|
809
|
+
ariaHiddenOnly
|
|
810
|
+
} = dependencies;
|
|
811
|
+
const { referencedLabelText, label } = createLabelNames({ publicText });
|
|
812
|
+
const { nearbyText, rowLabel } = createSpatialNames(dependencies);
|
|
813
|
+
function mediaName(element) {
|
|
814
|
+
const selector = "img[alt],svg[aria-label],svg title,[aria-label]";
|
|
815
|
+
for (const node of Array.from(element.querySelectorAll(selector))) {
|
|
816
|
+
const drawn = node.matches("svg title") ? node.closest("svg") : node;
|
|
817
|
+
if (interactive(node) || !visible(drawn, true)) continue;
|
|
818
|
+
const text = mediaText(node);
|
|
819
|
+
if (text) return text;
|
|
820
|
+
}
|
|
821
|
+
return "";
|
|
822
|
+
}
|
|
823
|
+
function mediaText(node) {
|
|
824
|
+
const text = node instanceof HTMLImageElement ? node.alt : node.matches("svg title") ? node.textContent ?? "" : node.getAttribute("aria-label") ?? "";
|
|
825
|
+
return text.replace(/\s+/g, " ").trim();
|
|
826
|
+
}
|
|
827
|
+
function hostLabel(element) {
|
|
828
|
+
const root = element.getRootNode();
|
|
829
|
+
if (!(root instanceof ShadowRoot)) return "";
|
|
830
|
+
const host = root.host;
|
|
831
|
+
const aria = host.getAttribute("aria-label")?.trim();
|
|
832
|
+
if (!aria || interactive(host)) return "";
|
|
833
|
+
const inside = allElements(host, 500) ?? [];
|
|
834
|
+
return inside.filter((node) => interactive(node)).length === 1 ? aria : "";
|
|
835
|
+
}
|
|
836
|
+
function iconName(element) {
|
|
837
|
+
for (const node of Array.from(element.querySelectorAll("i,span,em"))) {
|
|
838
|
+
if (node.textContent?.trim() || !node.getClientRects().length) continue;
|
|
839
|
+
if (insideNestedControl(element, node)) continue;
|
|
840
|
+
const name = iconClassName(node.classList);
|
|
841
|
+
if (name) return name;
|
|
842
|
+
}
|
|
843
|
+
return "";
|
|
844
|
+
}
|
|
845
|
+
function iconClassName(classes) {
|
|
846
|
+
for (const token of Array.from(classes)) {
|
|
847
|
+
const match = /^(?:fa|bi|glyphicon|icon|mdi|ti|ri)-([a-z][a-z0-9-]*)$/.exec(token);
|
|
848
|
+
if (match && !isIconModifier(match[1]))
|
|
849
|
+
return match[1].replace(/-/g, " ");
|
|
850
|
+
}
|
|
851
|
+
return "";
|
|
852
|
+
}
|
|
853
|
+
function isIconModifier(name) {
|
|
854
|
+
return /^(lg|[0-9]x|fw|solid|regular|light|brands|spin|pulse|border|inverse|stack.*|rotate.*|flip.*)$/.test(
|
|
855
|
+
name
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
function describedText(element) {
|
|
859
|
+
const ids = element.getAttribute("aria-describedby");
|
|
860
|
+
if (!ids || role(element) !== "combobox") return "";
|
|
861
|
+
return ids.split(/\s+/).map((id) => document.getElementById(id)).map((node) => node && visible(node) ? publicText(node) : "").filter(Boolean).join(" ").slice(0, 80);
|
|
862
|
+
}
|
|
863
|
+
function hiddenControlText(element) {
|
|
864
|
+
const parts = [];
|
|
865
|
+
for (const node of flatTextNodes(element)) {
|
|
866
|
+
const parent = node.parentElement;
|
|
867
|
+
if (!parent || parent.closest(
|
|
868
|
+
"script,style,noscript,input,textarea,select,[contenteditable]"
|
|
869
|
+
))
|
|
251
870
|
continue;
|
|
252
|
-
|
|
253
|
-
|
|
871
|
+
if (!insideNestedControl(element, parent))
|
|
872
|
+
parts.push(node.textContent ?? "");
|
|
254
873
|
}
|
|
255
|
-
return
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
874
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
875
|
+
}
|
|
876
|
+
function candidateName(element, hoverRevealed = false) {
|
|
877
|
+
const sources = [
|
|
878
|
+
() => label(element, ariaHiddenOnly(element)),
|
|
879
|
+
() => hoverRevealed ? hiddenControlText(element) : "",
|
|
880
|
+
mediaName,
|
|
881
|
+
nearbyText,
|
|
882
|
+
hostLabel,
|
|
883
|
+
iconName,
|
|
884
|
+
describedText,
|
|
885
|
+
rowLabel
|
|
886
|
+
];
|
|
887
|
+
for (const source of sources) {
|
|
888
|
+
const result = source(element);
|
|
889
|
+
if (result) return result;
|
|
890
|
+
}
|
|
891
|
+
return "";
|
|
892
|
+
}
|
|
893
|
+
const nameHint = createNameHint(dependencies, {
|
|
894
|
+
referencedLabelText,
|
|
895
|
+
nearbyText,
|
|
896
|
+
rowLabel
|
|
897
|
+
});
|
|
898
|
+
function countBadgeKind(node, count) {
|
|
899
|
+
const tokens = [];
|
|
900
|
+
const control = collectBadgeTokens(node, tokens);
|
|
901
|
+
if (!control || publicText(control, true).replace(/\s+/g, "") !== count)
|
|
902
|
+
return "";
|
|
903
|
+
return iconKind(tokens);
|
|
904
|
+
}
|
|
905
|
+
function collectBadgeTokens(node, tokens) {
|
|
906
|
+
let current = node;
|
|
907
|
+
for (let depth = 0; current && current !== document.body && depth < 4; depth++) {
|
|
908
|
+
tokens.push(...elementTokens(current));
|
|
909
|
+
if (interactive(current)) return current;
|
|
910
|
+
current = composedParent(current);
|
|
911
|
+
}
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
function elementTokens(element) {
|
|
915
|
+
return [
|
|
916
|
+
element.getAttribute("class") ?? "",
|
|
917
|
+
element.id,
|
|
918
|
+
element.getAttribute("data-test") ?? "",
|
|
919
|
+
element.getAttribute("data-testid") ?? ""
|
|
920
|
+
].join(" ").toLocaleLowerCase().split(/\s+/).map((token) => token.replace(/[_:#/.]+/g, "-")).filter(Boolean);
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
referencedLabelText,
|
|
924
|
+
label,
|
|
925
|
+
nearbyText,
|
|
926
|
+
mediaName,
|
|
927
|
+
hostLabel,
|
|
928
|
+
iconName,
|
|
929
|
+
describedText,
|
|
930
|
+
rowLabel,
|
|
931
|
+
hiddenControlText,
|
|
932
|
+
candidateName,
|
|
933
|
+
nameHint,
|
|
934
|
+
countBadgeKind
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// src/page-script/candidate-names.ts
|
|
939
|
+
function createCandidateNames(dependencies) {
|
|
940
|
+
return createCandidateNamesImplementation(dependencies);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// src/page-script/candidate-scanner.ts
|
|
944
|
+
var MAX_ELEMENTS = 2e4;
|
|
945
|
+
function createCandidateScanner(deps) {
|
|
946
|
+
let sequence = 0;
|
|
947
|
+
let nodeSequence = 0;
|
|
948
|
+
let snapshot;
|
|
949
|
+
const owned = /* @__PURE__ */ new Map();
|
|
950
|
+
const nodeIds = /* @__PURE__ */ new WeakMap();
|
|
951
|
+
function clearRefs() {
|
|
952
|
+
for (const [element, entry] of owned) restoreRef(element, entry);
|
|
953
|
+
owned.clear();
|
|
954
|
+
snapshot = void 0;
|
|
955
|
+
}
|
|
956
|
+
function restoreRef(element, entry) {
|
|
957
|
+
if (element.getAttribute("data-sedum-ref") !== entry.ref) return;
|
|
958
|
+
if (entry.old === null) element.removeAttribute("data-sedum-ref");
|
|
959
|
+
else element.setAttribute("data-sedum-ref", entry.old);
|
|
960
|
+
}
|
|
961
|
+
function scanElements() {
|
|
962
|
+
const selectedModal = deps.modal();
|
|
963
|
+
if (selectedModal === void 0) return { elements: [], complete: false };
|
|
964
|
+
const root = selectedModal ?? deps.document.body;
|
|
965
|
+
if (!root) return { elements: [], complete: true };
|
|
966
|
+
const elements = deps.allElements(root, MAX_ELEMENTS) ?? deps.allElements(root, MAX_ELEMENTS, true);
|
|
967
|
+
return elements ? { elements, complete: true } : { elements: [], complete: false };
|
|
968
|
+
}
|
|
969
|
+
function eligible(element, operation, proxied, shownByHover) {
|
|
970
|
+
if (!isShown(element, operation, shownByHover)) return false;
|
|
971
|
+
if (operation === "read") return deps.readable(element);
|
|
972
|
+
return isActionTarget(element, operation, proxied);
|
|
973
|
+
}
|
|
974
|
+
function isShown(element, operation, shownByHover) {
|
|
975
|
+
if (deps.visible(element) || deps.transparentToggle(element)) return true;
|
|
976
|
+
if (operation !== "click") return false;
|
|
977
|
+
return deps.ariaHiddenOnly(element) || !!shownByHover;
|
|
978
|
+
}
|
|
979
|
+
function isActionTarget(element, operation, proxied) {
|
|
980
|
+
if (deps.interactive(element) || proxied) return true;
|
|
981
|
+
return operation === "click" && deps.pointerTarget(element);
|
|
982
|
+
}
|
|
983
|
+
function allowedForOperation(element, operation) {
|
|
984
|
+
if (operation === "fill") return deps.editable(element);
|
|
985
|
+
if (operation !== "click" || !deps.editable(element)) return true;
|
|
986
|
+
if (element.matches("input[type='checkbox'],input[type='radio']"))
|
|
987
|
+
return true;
|
|
988
|
+
if (deps.role(element) === "combobox") return true;
|
|
989
|
+
return !!element.readOnly;
|
|
990
|
+
}
|
|
991
|
+
function nodeId(element) {
|
|
992
|
+
const existing = nodeIds.get(element);
|
|
993
|
+
if (existing) return existing;
|
|
994
|
+
const created = `${deps.documentId}-node-${++nodeSequence}`;
|
|
995
|
+
nodeIds.set(element, created);
|
|
996
|
+
return created;
|
|
997
|
+
}
|
|
998
|
+
function signals(parts) {
|
|
999
|
+
const { element, rawName, name, peerData, section, hint } = parts;
|
|
1000
|
+
const result = {};
|
|
1001
|
+
copyAttribute(result, "hook", element, "data-testid");
|
|
1002
|
+
if (element.id) result.id = element.id;
|
|
1003
|
+
copyAttribute(result, "name", element, "name");
|
|
1004
|
+
copyAttribute(result, "href", element, "href");
|
|
1005
|
+
if (deps.inArticleBody(element)) result.region = "article-body";
|
|
1006
|
+
if (rawName !== name)
|
|
1007
|
+
Object.assign(result, { nameTruncated: true, rawName });
|
|
1008
|
+
Object.assign(result, {
|
|
1009
|
+
nodeId: nodeId(element),
|
|
1010
|
+
path: deps.path(element),
|
|
1011
|
+
contextComplete: peerData.contextComplete
|
|
1012
|
+
});
|
|
1013
|
+
if (peerData.item) result.item = peerData.item;
|
|
1014
|
+
if (section) result.section = section;
|
|
1015
|
+
if (hint) result.nameHint = hint;
|
|
1016
|
+
return Object.freeze(result);
|
|
1017
|
+
}
|
|
1018
|
+
function copyAttribute(target, key, element, attribute) {
|
|
1019
|
+
const value = element.getAttribute(attribute);
|
|
1020
|
+
if (value) target[key] = value;
|
|
1021
|
+
}
|
|
1022
|
+
function buildCandidate(parts) {
|
|
1023
|
+
const { element, operation, proxied, heading, rawName } = parts;
|
|
1024
|
+
const name = deps.boundedName(rawName);
|
|
1025
|
+
const ref = `${deps.documentId}-${++sequence}`;
|
|
1026
|
+
const peerData = deps.peers(element, name, operation);
|
|
1027
|
+
const location2 = deps.locationOf(element, heading);
|
|
1028
|
+
const section = deps.sectionOf(element);
|
|
1029
|
+
const hint = operation === "read" ? "" : deps.nameHint(element, rawName);
|
|
1030
|
+
owned.set(element, {
|
|
1031
|
+
old: element.getAttribute("data-sedum-ref"),
|
|
1032
|
+
ref,
|
|
1033
|
+
rawName
|
|
1034
|
+
});
|
|
1035
|
+
element.setAttribute("data-sedum-ref", ref);
|
|
1036
|
+
return Object.freeze({
|
|
1037
|
+
ref,
|
|
1038
|
+
tag: element.tagName.toLowerCase(),
|
|
1039
|
+
role: proxied ? deps.role(proxied) : deps.role(element),
|
|
1040
|
+
name,
|
|
1041
|
+
peers: Object.freeze(peerData.texts),
|
|
1042
|
+
...location2 ? { location: location2 } : {},
|
|
1043
|
+
editable: deps.editable(element),
|
|
1044
|
+
disabled: deps.disabled(element),
|
|
1045
|
+
inputType: element instanceof HTMLInputElement ? element.type : "",
|
|
1046
|
+
signals: signals({ element, rawName, name, peerData, section, hint })
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function candidateFor(element, operation, heading) {
|
|
1050
|
+
const proxied = operation === "click" ? deps.toggleLabel(element) : null;
|
|
1051
|
+
const shownByHover = operation === "click" && !deps.visible(element) ? deps.hoverHost(element) : null;
|
|
1052
|
+
if (!eligible(element, operation, proxied, shownByHover)) return null;
|
|
1053
|
+
if (!allowedForOperation(element, operation)) return null;
|
|
1054
|
+
const rawName = operation === "read" ? deps.label(element) : deps.candidateName(element, !!shownByHover);
|
|
1055
|
+
return rawName ? buildCandidate({ element, operation, proxied, heading, rawName }) : null;
|
|
1056
|
+
}
|
|
1057
|
+
function scan(operation) {
|
|
260
1058
|
clearRefs();
|
|
261
1059
|
const refs = /* @__PURE__ */ new Map();
|
|
262
1060
|
const candidates = [];
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (operation === "fill" && !editable(element)) continue;
|
|
275
|
-
if (operation === "click" && editable(element) && !element.matches("input[type='checkbox'],input[type='radio']"))
|
|
276
|
-
continue;
|
|
277
|
-
const name = label(element);
|
|
278
|
-
if (!name) continue;
|
|
279
|
-
const ref = `${documentId}-${++sequence}`;
|
|
280
|
-
const peerData = peers(element, name);
|
|
281
|
-
owned.set(element, { old: element.getAttribute("data-sedum-ref"), ref });
|
|
282
|
-
element.setAttribute("data-sedum-ref", ref);
|
|
283
|
-
refs.set(ref, element);
|
|
284
|
-
candidates.push(
|
|
285
|
-
Object.freeze({
|
|
286
|
-
ref,
|
|
287
|
-
tag: element.tagName.toLowerCase(),
|
|
288
|
-
role: role(element),
|
|
289
|
-
name,
|
|
290
|
-
peers: Object.freeze(peerData.texts),
|
|
291
|
-
editable: editable(element),
|
|
292
|
-
disabled: disabled(element),
|
|
293
|
-
inputType: element instanceof HTMLInputElement ? element.type : "",
|
|
294
|
-
signals: Object.freeze({
|
|
295
|
-
...element.getAttribute("data-testid") ? { hook: element.getAttribute("data-testid") } : {},
|
|
296
|
-
...element.id ? { id: element.id } : {},
|
|
297
|
-
...element.getAttribute("name") ? { name: element.getAttribute("name") } : {},
|
|
298
|
-
...element.getAttribute("href") ? { href: element.getAttribute("href") } : {},
|
|
299
|
-
...inArticleBody(element) ? { region: "article-body" } : {},
|
|
300
|
-
path: path(element),
|
|
301
|
-
contextComplete: peerData.contextComplete
|
|
302
|
-
})
|
|
303
|
-
})
|
|
304
|
-
);
|
|
1061
|
+
const found = scanElements();
|
|
1062
|
+
if (!found.complete) return { candidates, refs, complete: false };
|
|
1063
|
+
let heading = { text: "", root: null };
|
|
1064
|
+
deps.resetContext();
|
|
1065
|
+
deps.resetHover();
|
|
1066
|
+
for (const element of found.elements) {
|
|
1067
|
+
heading = deps.observeHeading(element) ?? heading;
|
|
1068
|
+
const candidate = candidateFor(element, operation, heading);
|
|
1069
|
+
if (!candidate) continue;
|
|
1070
|
+
refs.set(candidate.ref, element);
|
|
1071
|
+
candidates.push(candidate);
|
|
305
1072
|
}
|
|
306
1073
|
return { candidates: Object.freeze(candidates), refs, complete: true };
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return {
|
|
327
|
-
protocol: PAGE_PROTOCOL,
|
|
328
|
-
version: currentSnapshot.version,
|
|
329
|
-
total: 0,
|
|
330
|
-
offset,
|
|
331
|
-
next: null,
|
|
332
|
-
complete: false,
|
|
333
|
-
candidates: []
|
|
334
|
-
};
|
|
335
|
-
const candidates = currentSnapshot.candidates.slice(
|
|
1074
|
+
}
|
|
1075
|
+
function emptyPage(current, offset) {
|
|
1076
|
+
return {
|
|
1077
|
+
protocol: PAGE_PROTOCOL,
|
|
1078
|
+
version: current,
|
|
1079
|
+
total: 0,
|
|
1080
|
+
offset,
|
|
1081
|
+
next: null,
|
|
1082
|
+
complete: false,
|
|
1083
|
+
candidates: []
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
function validContinuation(operation, requestedVersion) {
|
|
1087
|
+
return !!(snapshot && snapshot.operation === operation && requestedVersion && deps.sameVersion(snapshot.version, requestedVersion));
|
|
1088
|
+
}
|
|
1089
|
+
function page(offset) {
|
|
1090
|
+
const current = snapshot;
|
|
1091
|
+
if (!current.complete) return emptyPage(current.version, offset);
|
|
1092
|
+
const candidates = current.candidates.slice(
|
|
336
1093
|
offset,
|
|
337
1094
|
offset + CANDIDATE_LIMIT
|
|
338
1095
|
);
|
|
339
|
-
const
|
|
1096
|
+
const consumed = offset + candidates.length;
|
|
340
1097
|
return {
|
|
341
1098
|
protocol: PAGE_PROTOCOL,
|
|
342
|
-
version:
|
|
343
|
-
total:
|
|
1099
|
+
version: current.version,
|
|
1100
|
+
total: current.candidates.length,
|
|
344
1101
|
offset,
|
|
345
|
-
next,
|
|
1102
|
+
next: consumed < current.candidates.length ? consumed : null,
|
|
346
1103
|
complete: true,
|
|
347
1104
|
candidates
|
|
348
1105
|
};
|
|
349
|
-
}
|
|
1106
|
+
}
|
|
1107
|
+
function collect(input) {
|
|
1108
|
+
const current = deps.version();
|
|
1109
|
+
const offset = input.offset ?? 0;
|
|
1110
|
+
if (offset > 0 && !validContinuation(input.operation, input.version))
|
|
1111
|
+
return emptyPage(current, offset);
|
|
1112
|
+
if (offset === 0) {
|
|
1113
|
+
const result = scan(input.operation);
|
|
1114
|
+
snapshot = {
|
|
1115
|
+
version: deps.version(),
|
|
1116
|
+
operation: input.operation,
|
|
1117
|
+
...result
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
return page(offset);
|
|
1121
|
+
}
|
|
1122
|
+
return {
|
|
1123
|
+
collect,
|
|
1124
|
+
clearRefs,
|
|
1125
|
+
snapshot: () => snapshot,
|
|
1126
|
+
rawName: (element) => owned.get(element)?.rawName,
|
|
1127
|
+
candidates: () => snapshot?.candidates ?? []
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// src/page-script/dom-traversal.ts
|
|
1132
|
+
function createDomTraversal(deps) {
|
|
1133
|
+
function composedParent(element) {
|
|
1134
|
+
if (element.parentElement) return element.parentElement;
|
|
1135
|
+
return element.parentNode instanceof ShadowRoot ? element.parentNode.host : null;
|
|
1136
|
+
}
|
|
1137
|
+
function pushChildren(parent, stack) {
|
|
1138
|
+
for (let index = parent.children.length - 1; index >= 0; index--)
|
|
1139
|
+
stack.push(parent.children[index]);
|
|
1140
|
+
}
|
|
1141
|
+
function pushDescendants(element, stack, skipDrawings) {
|
|
1142
|
+
if (skipDrawings && element instanceof SVGSVGElement) return;
|
|
1143
|
+
pushChildren(element, stack);
|
|
1144
|
+
if (!element.shadowRoot) return;
|
|
1145
|
+
deps.observe(element.shadowRoot);
|
|
1146
|
+
pushChildren(element.shadowRoot, stack);
|
|
1147
|
+
}
|
|
1148
|
+
function allElements(root, limit, skipDrawings = false) {
|
|
1149
|
+
const result = [];
|
|
1150
|
+
const stack = [];
|
|
1151
|
+
if (root.shadowRoot) {
|
|
1152
|
+
deps.observe(root.shadowRoot);
|
|
1153
|
+
pushChildren(root.shadowRoot, stack);
|
|
1154
|
+
}
|
|
1155
|
+
pushChildren(root, stack);
|
|
1156
|
+
while (stack.length) {
|
|
1157
|
+
const element = stack.pop();
|
|
1158
|
+
result.push(element);
|
|
1159
|
+
if (result.length > limit) return null;
|
|
1160
|
+
pushDescendants(element, stack, skipDrawings);
|
|
1161
|
+
}
|
|
1162
|
+
return result;
|
|
1163
|
+
}
|
|
1164
|
+
function flatTextNodes(root) {
|
|
1165
|
+
const result = [];
|
|
1166
|
+
visitFlat(root, result);
|
|
1167
|
+
return result;
|
|
1168
|
+
}
|
|
1169
|
+
function visitFlat(node, result) {
|
|
1170
|
+
if (node instanceof Text) {
|
|
1171
|
+
result.push(node);
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
if (node instanceof HTMLSlotElement) {
|
|
1175
|
+
const assigned = node.assignedNodes({ flatten: true });
|
|
1176
|
+
visitChildren(assigned.length ? assigned : node.childNodes, result);
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
const children = node instanceof Element && node.shadowRoot ? node.shadowRoot.childNodes : node.childNodes;
|
|
1180
|
+
visitChildren(children, result);
|
|
1181
|
+
}
|
|
1182
|
+
function visitChildren(children, result) {
|
|
1183
|
+
for (const child of Array.from(children)) visitFlat(child, result);
|
|
1184
|
+
}
|
|
1185
|
+
function deepElementFromPoint(x, y) {
|
|
1186
|
+
let hit = deps.document.elementFromPoint(x, y);
|
|
1187
|
+
while (hit?.shadowRoot) {
|
|
1188
|
+
const root = hit.shadowRoot;
|
|
1189
|
+
const inner = root.elementsFromPoint(x, y).find((element) => element.getRootNode() === root);
|
|
1190
|
+
if (!inner) break;
|
|
1191
|
+
hit = inner;
|
|
1192
|
+
}
|
|
1193
|
+
return hit;
|
|
1194
|
+
}
|
|
1195
|
+
function deepContains(ancestor, node) {
|
|
1196
|
+
for (let current = node; current; current = composedParent(current))
|
|
1197
|
+
if (current === ancestor) return true;
|
|
1198
|
+
return false;
|
|
1199
|
+
}
|
|
1200
|
+
return {
|
|
1201
|
+
composedParent,
|
|
1202
|
+
allElements,
|
|
1203
|
+
flatTextNodes,
|
|
1204
|
+
deepElementFromPoint,
|
|
1205
|
+
deepContains
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// src/page-script/element-semantics.ts
|
|
1210
|
+
var FILLABLE_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
1211
|
+
"text",
|
|
1212
|
+
"email",
|
|
1213
|
+
"password",
|
|
1214
|
+
"search",
|
|
1215
|
+
"tel",
|
|
1216
|
+
"url",
|
|
1217
|
+
"number",
|
|
1218
|
+
"date",
|
|
1219
|
+
"datetime-local",
|
|
1220
|
+
"time",
|
|
1221
|
+
"month",
|
|
1222
|
+
"week"
|
|
1223
|
+
]);
|
|
1224
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
1225
|
+
"button",
|
|
1226
|
+
"link",
|
|
1227
|
+
"checkbox",
|
|
1228
|
+
"radio",
|
|
1229
|
+
"switch",
|
|
1230
|
+
"tab",
|
|
1231
|
+
"menuitem",
|
|
1232
|
+
"option",
|
|
1233
|
+
"textbox",
|
|
1234
|
+
"searchbox",
|
|
1235
|
+
"combobox",
|
|
1236
|
+
"spinbutton",
|
|
1237
|
+
"slider"
|
|
1238
|
+
]);
|
|
1239
|
+
var TEXT_FIELD_ROLES = /* @__PURE__ */ new Set([
|
|
1240
|
+
"textbox",
|
|
1241
|
+
"searchbox",
|
|
1242
|
+
"combobox",
|
|
1243
|
+
"spinbutton"
|
|
1244
|
+
]);
|
|
1245
|
+
function createElementSemantics(deps) {
|
|
1246
|
+
function hiddenSelector(visualOnly) {
|
|
1247
|
+
return visualOnly ? "[hidden],[inert],dialog:not([open])" : "[hidden],[inert],[aria-hidden='true'],dialog:not([open])";
|
|
1248
|
+
}
|
|
1249
|
+
function outsideViewport(element) {
|
|
1250
|
+
const bounds = element.getBoundingClientRect();
|
|
1251
|
+
return outsideHorizontally(bounds) || outsideVertically(bounds);
|
|
1252
|
+
}
|
|
1253
|
+
function outsideHorizontally(bounds) {
|
|
1254
|
+
return bounds.right <= 0 || bounds.left >= innerWidth;
|
|
1255
|
+
}
|
|
1256
|
+
function outsideVertically(bounds) {
|
|
1257
|
+
return bounds.bottom <= 0 || bounds.top >= innerHeight;
|
|
1258
|
+
}
|
|
1259
|
+
function hiddenAcrossShadowBoundary(node, origin, visualOnly) {
|
|
1260
|
+
if (node.getRootNode() === origin.getRootNode()) return false;
|
|
1261
|
+
return node.matches(
|
|
1262
|
+
visualOnly ? "[hidden],[inert]" : "[hidden],[inert],[aria-hidden='true']"
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
function hiddenByStyle(node, origin, ignoreOwnOpacity) {
|
|
1266
|
+
const style = getComputedStyle(node);
|
|
1267
|
+
if (style.contentVisibility === "hidden") return true;
|
|
1268
|
+
return opacityHidden(style, node === origin, ignoreOwnOpacity);
|
|
1269
|
+
}
|
|
1270
|
+
function opacityHidden(style, own, ignoreOwnOpacity) {
|
|
1271
|
+
if (Number.parseFloat(style.opacity) !== 0) return false;
|
|
1272
|
+
return !own || !ignoreOwnOpacity;
|
|
1273
|
+
}
|
|
1274
|
+
function hiddenAncestor(element, visualOnly, ignoreOwnOpacity) {
|
|
1275
|
+
for (let node = element; node; node = deps.composedParent(node)) {
|
|
1276
|
+
if (hiddenAcrossShadowBoundary(node, element, visualOnly)) return true;
|
|
1277
|
+
if (hiddenByStyle(node, element, ignoreOwnOpacity)) return true;
|
|
1278
|
+
}
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
function contentsVisible(element) {
|
|
1282
|
+
const range = deps.document.createRange();
|
|
1283
|
+
range.selectNodeContents(element);
|
|
1284
|
+
return Array.from(range.getClientRects()).some(
|
|
1285
|
+
(rect) => rect.width > 0 && rect.height > 0
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
function visible(element, visualOnly = false, ignoreOwnOpacity = false) {
|
|
1289
|
+
if (element.closest(hiddenSelector(visualOnly))) return false;
|
|
1290
|
+
const dialog = element.closest("dialog,[role='dialog']");
|
|
1291
|
+
if (dialog && outsideViewport(dialog)) return false;
|
|
1292
|
+
if (hiddenAncestor(element, visualOnly, ignoreOwnOpacity)) return false;
|
|
1293
|
+
return rendered(element);
|
|
1294
|
+
}
|
|
1295
|
+
function rendered(element) {
|
|
1296
|
+
const style = getComputedStyle(element);
|
|
1297
|
+
if (style.display === "none") return false;
|
|
1298
|
+
if (["hidden", "collapse"].includes(style.visibility)) return false;
|
|
1299
|
+
if (element.getClientRects().length > 0) return true;
|
|
1300
|
+
return style.display === "contents" && contentsVisible(element);
|
|
1301
|
+
}
|
|
1302
|
+
function cleanModalOrder() {
|
|
1303
|
+
for (const dialog of deps.modalOrder.keys())
|
|
1304
|
+
if (!dialog.isConnected || !dialog.open) deps.modalOrder.delete(dialog);
|
|
1305
|
+
}
|
|
1306
|
+
function newestNative(dialogs) {
|
|
1307
|
+
const ordered = [...dialogs].sort(
|
|
1308
|
+
(a, b) => (deps.modalOrder.get(b) ?? 0) - (deps.modalOrder.get(a) ?? 0)
|
|
1309
|
+
);
|
|
1310
|
+
return (deps.modalOrder.get(ordered[0]) ?? 0) > 0 ? ordered[0] : void 0;
|
|
1311
|
+
}
|
|
1312
|
+
function selectedNative(dialogs) {
|
|
1313
|
+
const newest = newestNative(dialogs);
|
|
1314
|
+
if (newest) return newest;
|
|
1315
|
+
return dialogs.find(
|
|
1316
|
+
(element) => element.contains(deps.document.activeElement)
|
|
1317
|
+
) ?? (dialogs.length === 1 ? dialogs[0] : void 0);
|
|
1318
|
+
}
|
|
1319
|
+
function modal() {
|
|
1320
|
+
cleanModalOrder();
|
|
1321
|
+
const dialogs = Array.from(
|
|
1322
|
+
deps.document.querySelectorAll(
|
|
1323
|
+
"dialog:modal,[role='dialog'][aria-modal='true']"
|
|
1324
|
+
)
|
|
1325
|
+
).filter((element) => visible(element));
|
|
1326
|
+
if (!dialogs.length) return null;
|
|
1327
|
+
const native = dialogs.filter(
|
|
1328
|
+
(element) => element.matches("dialog:modal")
|
|
1329
|
+
);
|
|
1330
|
+
return native.length ? selectedNative(native) : dialogs.length === 1 ? dialogs[0] : void 0;
|
|
1331
|
+
}
|
|
1332
|
+
function inputRole(element) {
|
|
1333
|
+
if (["button", "submit", "reset", "file"].includes(element.type))
|
|
1334
|
+
return "button";
|
|
1335
|
+
const mapped = {
|
|
1336
|
+
checkbox: "checkbox",
|
|
1337
|
+
radio: "radio",
|
|
1338
|
+
range: "slider",
|
|
1339
|
+
number: "spinbutton",
|
|
1340
|
+
search: "searchbox"
|
|
1341
|
+
};
|
|
1342
|
+
return mapped[element.type] ?? "textbox";
|
|
1343
|
+
}
|
|
1344
|
+
function role(element) {
|
|
1345
|
+
const canonical = element.getAttribute("role")?.split(/\s+/).find(isSafeRole);
|
|
1346
|
+
if (canonical) return canonical;
|
|
1347
|
+
return implicitRole(element);
|
|
1348
|
+
}
|
|
1349
|
+
function implicitRole(element) {
|
|
1350
|
+
if (element instanceof HTMLButtonElement) return "button";
|
|
1351
|
+
if (element.matches("details > summary")) return "button";
|
|
1352
|
+
if (element instanceof HTMLAnchorElement) return "link";
|
|
1353
|
+
if (element instanceof HTMLInputElement) return inputRole(element);
|
|
1354
|
+
if (element instanceof HTMLTextAreaElement) return "textbox";
|
|
1355
|
+
return element instanceof HTMLSelectElement ? "combobox" : "";
|
|
1356
|
+
}
|
|
1357
|
+
function interactive(element) {
|
|
1358
|
+
if (element.parentElement?.closest("a[href]")) return false;
|
|
1359
|
+
if (element.matches(
|
|
1360
|
+
"button,a[href],input,textarea,select,[contenteditable],details > summary"
|
|
1361
|
+
))
|
|
1362
|
+
return true;
|
|
1363
|
+
return INTERACTIVE_ROLES.has(role(element));
|
|
1364
|
+
}
|
|
1365
|
+
function excludedTextAncestor(element, includeActions = false) {
|
|
1366
|
+
for (let node = element; node; node = node.parentElement)
|
|
1367
|
+
if (excludedTextNode(node, includeActions)) return true;
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
function excludedTextNode(node, includeActions) {
|
|
1371
|
+
if (node.matches(
|
|
1372
|
+
"input,textarea,select,[contenteditable],script,style,noscript"
|
|
1373
|
+
))
|
|
1374
|
+
return true;
|
|
1375
|
+
if (TEXT_FIELD_ROLES.has(role(node))) return true;
|
|
1376
|
+
return includeActions && (node.matches("button,a[href]") || ["button", "link"].includes(role(node)));
|
|
1377
|
+
}
|
|
1378
|
+
function insideNestedControl(element, node) {
|
|
1379
|
+
for (let current = node; current && current !== element; current = deps.composedParent(current))
|
|
1380
|
+
if (interactive(current)) return true;
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
function publicText(element, visualOnly = false, ownOnly = false) {
|
|
1384
|
+
const parts = [];
|
|
1385
|
+
for (const node of deps.flatTextNodes(element)) {
|
|
1386
|
+
const parent = node.parentElement;
|
|
1387
|
+
if (!eligibleTextParent(parent, visualOnly)) continue;
|
|
1388
|
+
if (!ownOnly || !insideNestedControl(element, parent))
|
|
1389
|
+
parts.push(node.textContent ?? "");
|
|
1390
|
+
}
|
|
1391
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
1392
|
+
}
|
|
1393
|
+
function eligibleTextParent(parent, visualOnly) {
|
|
1394
|
+
if (!parent) return false;
|
|
1395
|
+
if (!visible(parent, visualOnly)) return false;
|
|
1396
|
+
return !excludedTextAncestor(parent);
|
|
1397
|
+
}
|
|
1398
|
+
function clippedAway(element) {
|
|
1399
|
+
const box = element.getBoundingClientRect();
|
|
1400
|
+
const point = { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
1401
|
+
for (let node = deps.composedParent(element); node && node !== deps.document.body; node = deps.composedParent(node))
|
|
1402
|
+
if (clipsPoint(node, point)) return true;
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
function clipsPoint(node, point) {
|
|
1406
|
+
const style = getComputedStyle(node);
|
|
1407
|
+
if (style.overflowX === "visible" && style.overflowY === "visible")
|
|
1408
|
+
return false;
|
|
1409
|
+
const bounds = node.getBoundingClientRect();
|
|
1410
|
+
return point.x < bounds.left || point.x > bounds.right || point.y < bounds.top || point.y > bounds.bottom;
|
|
1411
|
+
}
|
|
1412
|
+
function ariaHiddenOnly(element) {
|
|
1413
|
+
if (!interactive(element)) return false;
|
|
1414
|
+
if (visible(element)) return false;
|
|
1415
|
+
if (!visible(element, true)) return false;
|
|
1416
|
+
const box = element.getBoundingClientRect();
|
|
1417
|
+
return box.width >= 8 && box.height >= 8 && !clippedAway(element) && !!publicText(element, true);
|
|
1418
|
+
}
|
|
1419
|
+
function isToggle(element) {
|
|
1420
|
+
return element instanceof HTMLInputElement && ["checkbox", "radio"].includes(element.type);
|
|
1421
|
+
}
|
|
1422
|
+
function transparentToggle(element) {
|
|
1423
|
+
if (!isToggle(element) || visible(element)) return false;
|
|
1424
|
+
const box = element.getBoundingClientRect();
|
|
1425
|
+
return box.width >= 8 && box.height >= 8 && visible(element, false, true);
|
|
1426
|
+
}
|
|
1427
|
+
function toggleLabel(element) {
|
|
1428
|
+
if (!(element instanceof HTMLLabelElement)) return null;
|
|
1429
|
+
const control = element.control;
|
|
1430
|
+
if (!control) return null;
|
|
1431
|
+
if (!isToggle(control)) return null;
|
|
1432
|
+
if (visible(control)) return null;
|
|
1433
|
+
if (transparentToggle(control)) return null;
|
|
1434
|
+
if (control.labels?.[0] !== element) return null;
|
|
1435
|
+
return control;
|
|
1436
|
+
}
|
|
1437
|
+
function pointerTarget(element) {
|
|
1438
|
+
if (!pointerCandidate(element) || insideInteractiveAncestor(element))
|
|
1439
|
+
return false;
|
|
1440
|
+
const inside = deps.allElements(element, 500);
|
|
1441
|
+
if (!inside) return false;
|
|
1442
|
+
const controls = inside.filter(
|
|
1443
|
+
(node) => interactive(node) || node.hasAttribute("role")
|
|
1444
|
+
);
|
|
1445
|
+
if (!controls.length) return true;
|
|
1446
|
+
return controls.every(
|
|
1447
|
+
(control) => !interactive(control) || !publicText(control, true)
|
|
1448
|
+
) && !!publicText(element, false, true);
|
|
1449
|
+
}
|
|
1450
|
+
function pointerCandidate(element) {
|
|
1451
|
+
if (interactive(element) || element.matches("html,body,label,svg *"))
|
|
1452
|
+
return false;
|
|
1453
|
+
if (getComputedStyle(element).cursor !== "pointer") return false;
|
|
1454
|
+
const parent = deps.composedParent(element);
|
|
1455
|
+
return !parent || getComputedStyle(parent).cursor !== "pointer";
|
|
1456
|
+
}
|
|
1457
|
+
function insideInteractiveAncestor(element) {
|
|
1458
|
+
for (let node = deps.composedParent(element); node; node = deps.composedParent(node))
|
|
1459
|
+
if (interactive(node)) return true;
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
function disabled(element) {
|
|
1463
|
+
return element.matches(":disabled,[aria-disabled='true']") || !!element.closest("[inert]");
|
|
1464
|
+
}
|
|
1465
|
+
function editable(element) {
|
|
1466
|
+
if (element instanceof HTMLInputElement)
|
|
1467
|
+
return FILLABLE_INPUT_TYPES.has(element.type) && !disabled(element);
|
|
1468
|
+
if (element instanceof HTMLTextAreaElement) return !disabled(element);
|
|
1469
|
+
return element instanceof HTMLElement && element.isContentEditable && !disabled(element);
|
|
1470
|
+
}
|
|
1471
|
+
function readable(element) {
|
|
1472
|
+
if (interactive(element) || excludedTextAncestor(element, true))
|
|
1473
|
+
return false;
|
|
1474
|
+
if (element.matches("h1,h2,h3,h4,h5,h6,p,blockquote,td,th,[role='heading']"))
|
|
1475
|
+
return true;
|
|
1476
|
+
return element.children.length === 0 && element.matches("span,strong,em,div,li") && publicText(element).length > 0;
|
|
1477
|
+
}
|
|
1478
|
+
return {
|
|
1479
|
+
visible,
|
|
1480
|
+
modal,
|
|
1481
|
+
role,
|
|
1482
|
+
interactive,
|
|
1483
|
+
excludedTextAncestor,
|
|
1484
|
+
publicText,
|
|
1485
|
+
insideNestedControl,
|
|
1486
|
+
ariaHiddenOnly,
|
|
1487
|
+
isToggle,
|
|
1488
|
+
transparentToggle,
|
|
1489
|
+
toggleLabel,
|
|
1490
|
+
pointerTarget,
|
|
1491
|
+
disabled,
|
|
1492
|
+
editable,
|
|
1493
|
+
readable
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
// src/page-script/hover.ts
|
|
1498
|
+
var DEPTH_CHANGES = {
|
|
1499
|
+
"(": 1,
|
|
1500
|
+
"[": 1,
|
|
1501
|
+
")": -1,
|
|
1502
|
+
"]": -1
|
|
1503
|
+
};
|
|
1504
|
+
function selectorList(text) {
|
|
1505
|
+
return new SelectorListParser(text).parse();
|
|
1506
|
+
}
|
|
1507
|
+
var SelectorListParser = class {
|
|
1508
|
+
constructor(text) {
|
|
1509
|
+
this.text = text;
|
|
1510
|
+
}
|
|
1511
|
+
text;
|
|
1512
|
+
selectors = [];
|
|
1513
|
+
start = 0;
|
|
1514
|
+
depth = 0;
|
|
1515
|
+
quote = "";
|
|
1516
|
+
parse() {
|
|
1517
|
+
for (let index = 0; index < this.text.length; index++) {
|
|
1518
|
+
this.consume(this.text[index], index);
|
|
1519
|
+
}
|
|
1520
|
+
this.push(this.text.length);
|
|
1521
|
+
return this.selectors.filter(Boolean);
|
|
1522
|
+
}
|
|
1523
|
+
consume(char, index) {
|
|
1524
|
+
if (this.quote) {
|
|
1525
|
+
if (char === this.quote && this.text[index - 1] !== "\\") this.quote = "";
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
const depthChange = DEPTH_CHANGES[char];
|
|
1529
|
+
if (depthChange) {
|
|
1530
|
+
this.depth += depthChange;
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
if (/['"]/.test(char)) {
|
|
1534
|
+
this.quote = char;
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (char === "," && this.depth === 0) this.push(index);
|
|
1538
|
+
}
|
|
1539
|
+
push(end) {
|
|
1540
|
+
this.selectors.push(this.text.slice(this.start, end).trim());
|
|
1541
|
+
this.start = end + 1;
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
function specificity(selector) {
|
|
1545
|
+
if (/\\|\||::|:[\w-]+\(/.test(selector)) return null;
|
|
1546
|
+
const attributes = selector.match(/\[[^\]]*\]/g)?.length ?? 0;
|
|
1547
|
+
const bare = selector.replace(/\[[^\]]*\]/g, " ");
|
|
1548
|
+
const ids = bare.match(/#[\w-]+/g)?.length ?? 0;
|
|
1549
|
+
const classes = bare.match(/\.[\w-]+/g)?.length ?? 0;
|
|
1550
|
+
const pseudos = bare.match(/:(?!:)[\w-]+/g)?.length ?? 0;
|
|
1551
|
+
const withoutQualifiers = bare.replace(/#[\w-]+|\.[\w-]+|:(?!:)[\w-]+/g, "").replace(/\*/g, "");
|
|
1552
|
+
const types = withoutQualifiers.match(/(?:^|[\s>+~])([a-zA-Z][\w-]*)/g)?.length ?? 0;
|
|
1553
|
+
return [ids, attributes + classes + pseudos, types];
|
|
1554
|
+
}
|
|
1555
|
+
function stronger(a, b, property) {
|
|
1556
|
+
const importantA = a.style.getPropertyPriority(property) === "important";
|
|
1557
|
+
const importantB = b.style.getPropertyPriority(property) === "important";
|
|
1558
|
+
if (importantA !== importantB) return importantA;
|
|
1559
|
+
if (!a.specificity || !b.specificity) return false;
|
|
1560
|
+
for (let index = 0; index < 3; index++) {
|
|
1561
|
+
if (a.specificity[index] !== b.specificity[index])
|
|
1562
|
+
return a.specificity[index] > b.specificity[index];
|
|
1563
|
+
}
|
|
1564
|
+
return a.order > b.order;
|
|
1565
|
+
}
|
|
1566
|
+
function hoverWins(element, property, reveal, cascadeRules) {
|
|
1567
|
+
let winner = null;
|
|
1568
|
+
for (const rule of cascadeRules) {
|
|
1569
|
+
const applies = ruleApplies(element, property, rule);
|
|
1570
|
+
if (applies === null) return false;
|
|
1571
|
+
if (!applies) continue;
|
|
1572
|
+
if (!winner || stronger(rule, winner, property)) winner = rule;
|
|
1573
|
+
}
|
|
1574
|
+
return winnerMatchesReveal(winner, reveal);
|
|
1575
|
+
}
|
|
1576
|
+
function winnerMatchesReveal(winner, reveal) {
|
|
1577
|
+
if (winner?.order !== reveal.order) return false;
|
|
1578
|
+
return winner.selector === reveal.selector;
|
|
1579
|
+
}
|
|
1580
|
+
function ruleApplies(element, property, rule) {
|
|
1581
|
+
if (!rule.style.getPropertyValue(property)) return false;
|
|
1582
|
+
const matches = safelyMatches(element, rule.match);
|
|
1583
|
+
if (matches === null) return null;
|
|
1584
|
+
if (matches && !rule.specificity) return null;
|
|
1585
|
+
return matches;
|
|
1586
|
+
}
|
|
1587
|
+
function safelyMatches(element, selector) {
|
|
1588
|
+
try {
|
|
1589
|
+
return element.matches(selector);
|
|
1590
|
+
} catch {
|
|
1591
|
+
return null;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
var StylesheetReader = class {
|
|
1595
|
+
hoverRules = [];
|
|
1596
|
+
declarations = [];
|
|
1597
|
+
complete = true;
|
|
1598
|
+
order = 0;
|
|
1599
|
+
read() {
|
|
1600
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
1601
|
+
try {
|
|
1602
|
+
this.visit(sheet.cssRules, true);
|
|
1603
|
+
} catch {
|
|
1604
|
+
this.complete = false;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
return this.complete ? this.hoverRules : [];
|
|
1608
|
+
}
|
|
1609
|
+
visit(list, safe) {
|
|
1610
|
+
for (const rule of Array.from(list)) this.visitRule(rule, safe);
|
|
1611
|
+
}
|
|
1612
|
+
visitRule(rule, safe) {
|
|
1613
|
+
if (rule instanceof CSSStyleRule) this.visitStyle(rule, safe);
|
|
1614
|
+
else if (rule instanceof CSSImportRule) this.visitImport(rule, safe);
|
|
1615
|
+
else if ("cssRules" in rule) this.visitGroup(rule, safe);
|
|
1616
|
+
}
|
|
1617
|
+
visitStyle(rule, safe) {
|
|
1618
|
+
const style = rule.style;
|
|
1619
|
+
const properties = revealedProperties(style);
|
|
1620
|
+
for (const selector of selectorList(rule.selectorText)) {
|
|
1621
|
+
const declaration = this.createDeclaration(selector, style, safe);
|
|
1622
|
+
if (!declaration) continue;
|
|
1623
|
+
this.declarations.push(declaration);
|
|
1624
|
+
if (!canReveal(safe, declaration, properties)) continue;
|
|
1625
|
+
const hoverRule = createHoverRule(declaration, properties);
|
|
1626
|
+
if (hoverRule) this.hoverRules.push(hoverRule);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
createDeclaration(selector, style, safe) {
|
|
1630
|
+
const match = selector.replace(/:hover/g, "").trim();
|
|
1631
|
+
const declaration = {
|
|
1632
|
+
selector,
|
|
1633
|
+
match,
|
|
1634
|
+
specificity: safe ? specificity(selector) : null,
|
|
1635
|
+
order: ++this.order,
|
|
1636
|
+
style
|
|
1637
|
+
};
|
|
1638
|
+
try {
|
|
1639
|
+
document.querySelector(match);
|
|
1640
|
+
return declaration;
|
|
1641
|
+
} catch {
|
|
1642
|
+
return null;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
visitImport(rule, safe) {
|
|
1646
|
+
try {
|
|
1647
|
+
if (rule.styleSheet) this.visit(rule.styleSheet.cssRules, safe);
|
|
1648
|
+
else this.complete = false;
|
|
1649
|
+
} catch {
|
|
1650
|
+
this.complete = false;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
visitGroup(rule, safe) {
|
|
1654
|
+
const name = rule.constructor.name;
|
|
1655
|
+
if (!groupApplies(rule, name)) return;
|
|
1656
|
+
const unsafe = [
|
|
1657
|
+
"CSSLayerBlockRule",
|
|
1658
|
+
"CSSScopeRule",
|
|
1659
|
+
"CSSContainerRule"
|
|
1660
|
+
].includes(name);
|
|
1661
|
+
this.visit(rule.cssRules, safe && !unsafe);
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
function revealedProperties(style) {
|
|
1665
|
+
return {
|
|
1666
|
+
display: style.display !== "" && style.display !== "none",
|
|
1667
|
+
visibility: style.visibility === "visible",
|
|
1668
|
+
opacity: style.opacity !== "" && Number.parseFloat(style.opacity) > 0
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
function reveals({
|
|
1672
|
+
display,
|
|
1673
|
+
visibility,
|
|
1674
|
+
opacity
|
|
1675
|
+
}) {
|
|
1676
|
+
return display || visibility || opacity;
|
|
1677
|
+
}
|
|
1678
|
+
function canReveal(safe, declaration, properties) {
|
|
1679
|
+
return safe && declaration.specificity !== null && reveals(properties);
|
|
1680
|
+
}
|
|
1681
|
+
function groupApplies(rule, name) {
|
|
1682
|
+
if (name === "CSSMediaRule")
|
|
1683
|
+
return matchMedia(rule.conditionText).matches;
|
|
1684
|
+
if (name === "CSSSupportsRule")
|
|
1685
|
+
return CSS.supports(rule.conditionText);
|
|
1686
|
+
return true;
|
|
1687
|
+
}
|
|
1688
|
+
function createHoverRule(declaration, properties) {
|
|
1689
|
+
const { selector, match: revealed } = declaration;
|
|
1690
|
+
if (!selector.includes(":hover")) return null;
|
|
1691
|
+
const at = selector.lastIndexOf(":hover");
|
|
1692
|
+
const host = selector.slice(0, at).replace(/:hover/g, "").trim();
|
|
1693
|
+
if (!host || host === revealed) return null;
|
|
1694
|
+
try {
|
|
1695
|
+
document.querySelector(host);
|
|
1696
|
+
return { ...declaration, revealed, host, ...properties };
|
|
1697
|
+
} catch {
|
|
1698
|
+
return null;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
function elementPath(element, composedParent, interactive) {
|
|
1702
|
+
const path = [];
|
|
1703
|
+
for (let node = element; node && node !== document.body; node = composedParent(node)) {
|
|
1704
|
+
path.push(node);
|
|
1705
|
+
if (node !== element && interactive(node)) return null;
|
|
1706
|
+
}
|
|
1707
|
+
return path;
|
|
1708
|
+
}
|
|
1709
|
+
function pathCanBeRevealed(path, plan) {
|
|
1710
|
+
return path.every((node) => nodeCanBeRevealed(node, plan));
|
|
1711
|
+
}
|
|
1712
|
+
function nodeCanBeRevealed(node, plan) {
|
|
1713
|
+
const style = getComputedStyle(node);
|
|
1714
|
+
if (style.contentVisibility === "hidden" || inlineHidden(node)) return false;
|
|
1715
|
+
if (style.display === "none" && !plan.display.has(node)) return false;
|
|
1716
|
+
if (computedVisibilityHidden(style) && !plan.visibility) return false;
|
|
1717
|
+
return Number.parseFloat(style.opacity) !== 0 || plan.opacity;
|
|
1718
|
+
}
|
|
1719
|
+
function inlineHidden(node) {
|
|
1720
|
+
if (!(node instanceof HTMLElement)) return false;
|
|
1721
|
+
return node.style.display === "none" || node.style.visibility === "hidden" || Number.parseFloat(node.style.opacity) === 0;
|
|
1722
|
+
}
|
|
1723
|
+
function computedVisibilityHidden(style) {
|
|
1724
|
+
return style.visibility === "hidden" || style.visibility === "collapse";
|
|
1725
|
+
}
|
|
1726
|
+
function revealPlans(path, hoverRules, cascadeRules, composedParent, visible) {
|
|
1727
|
+
const plans = /* @__PURE__ */ new Map();
|
|
1728
|
+
for (const node of path) {
|
|
1729
|
+
for (const rule of hoverRules) {
|
|
1730
|
+
if (!node.matches(rule.revealed)) continue;
|
|
1731
|
+
const hoverHost = matchingHost(node, rule.host, composedParent);
|
|
1732
|
+
if (!hoverHost || !visible(hoverHost)) continue;
|
|
1733
|
+
const plan = plans.get(hoverHost) ?? {
|
|
1734
|
+
display: /* @__PURE__ */ new Set(),
|
|
1735
|
+
visibility: false,
|
|
1736
|
+
opacity: false
|
|
1737
|
+
};
|
|
1738
|
+
if (rule.display && hoverWins(node, "display", rule, cascadeRules))
|
|
1739
|
+
plan.display.add(node);
|
|
1740
|
+
plan.visibility ||= rule.visibility && hoverWins(node, "visibility", rule, cascadeRules);
|
|
1741
|
+
plan.opacity ||= rule.opacity && hoverWins(node, "opacity", rule, cascadeRules);
|
|
1742
|
+
plans.set(hoverHost, plan);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return plans;
|
|
1746
|
+
}
|
|
1747
|
+
function matchingHost(node, selector, composedParent) {
|
|
1748
|
+
let host = node;
|
|
1749
|
+
while (host && !host.matches(selector)) host = composedParent(host);
|
|
1750
|
+
return host;
|
|
1751
|
+
}
|
|
1752
|
+
function createHoverDiscovery({
|
|
1753
|
+
composedParent,
|
|
1754
|
+
interactive,
|
|
1755
|
+
visible
|
|
1756
|
+
}) {
|
|
1757
|
+
let hoverRules;
|
|
1758
|
+
let cascadeRules = [];
|
|
1759
|
+
function readHoverRules() {
|
|
1760
|
+
const reader = new StylesheetReader();
|
|
1761
|
+
const rules = reader.read();
|
|
1762
|
+
cascadeRules = reader.complete ? reader.declarations : [];
|
|
1763
|
+
return rules;
|
|
1764
|
+
}
|
|
1765
|
+
function host(element) {
|
|
1766
|
+
if (!interactive(element)) return null;
|
|
1767
|
+
if (element.closest("[hidden],[inert],[aria-hidden='true']")) return null;
|
|
1768
|
+
hoverRules ??= readHoverRules();
|
|
1769
|
+
const path = elementPath(element, composedParent, interactive);
|
|
1770
|
+
if (!path) return null;
|
|
1771
|
+
const plans = revealPlans(
|
|
1772
|
+
path,
|
|
1773
|
+
hoverRules,
|
|
1774
|
+
cascadeRules,
|
|
1775
|
+
composedParent,
|
|
1776
|
+
visible
|
|
1777
|
+
);
|
|
1778
|
+
return Array.from(plans).filter(
|
|
1779
|
+
([hoverHost, plan]) => pathCanBeRevealed(path.slice(0, path.indexOf(hoverHost) + 1), plan)
|
|
1780
|
+
).map(([hoverHost]) => hoverHost).sort((a, b) => path.indexOf(a) - path.indexOf(b))[0] ?? null;
|
|
1781
|
+
}
|
|
1782
|
+
return {
|
|
1783
|
+
reset: () => {
|
|
1784
|
+
hoverRules = void 0;
|
|
1785
|
+
},
|
|
1786
|
+
host,
|
|
1787
|
+
revealed: (element) => !visible(element) && !!host(element)
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
// src/page-script/page-lifecycle.ts
|
|
1792
|
+
function createPageLifecycle() {
|
|
1793
|
+
const documentId = Array.from(crypto.getRandomValues(new Uint32Array(4))).map((part) => part.toString(16)).join("-");
|
|
1794
|
+
let revision = 0;
|
|
1795
|
+
let route = location.href;
|
|
1796
|
+
const modalOrder = /* @__PURE__ */ new Map();
|
|
1797
|
+
let modalSequence = 0;
|
|
1798
|
+
const observed = /* @__PURE__ */ new WeakSet();
|
|
1799
|
+
function trackDialog(change) {
|
|
1800
|
+
if (change.type !== "attributes" || change.attributeName !== "open") return;
|
|
1801
|
+
if (!(change.target instanceof HTMLDialogElement)) return;
|
|
1802
|
+
if (change.oldValue === null && change.target.matches(":modal")) {
|
|
1803
|
+
modalOrder.set(change.target, ++modalSequence);
|
|
1804
|
+
} else if (!change.target.open) {
|
|
1805
|
+
modalOrder.delete(change.target);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
function changesRevision(change) {
|
|
1809
|
+
return change.type !== "attributes" || change.attributeName !== "data-sedum-ref";
|
|
1810
|
+
}
|
|
1811
|
+
const observer = new MutationObserver((changes) => {
|
|
1812
|
+
changes.forEach(trackDialog);
|
|
1813
|
+
if (changes.some(changesRevision)) revision++;
|
|
1814
|
+
});
|
|
1815
|
+
function observe(root) {
|
|
1816
|
+
if (observed.has(root)) return;
|
|
1817
|
+
observed.add(root);
|
|
1818
|
+
observer.observe(root, {
|
|
1819
|
+
subtree: true,
|
|
1820
|
+
childList: true,
|
|
1821
|
+
characterData: true,
|
|
1822
|
+
attributes: true,
|
|
1823
|
+
attributeOldValue: true
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
function version() {
|
|
1827
|
+
if (route !== location.href) {
|
|
1828
|
+
route = location.href;
|
|
1829
|
+
revision++;
|
|
1830
|
+
}
|
|
1831
|
+
return { document: documentId, revision, route };
|
|
1832
|
+
}
|
|
1833
|
+
function sameVersion(a, b) {
|
|
1834
|
+
return a.document === b.document && a.revision === b.revision && a.route === b.route;
|
|
1835
|
+
}
|
|
1836
|
+
async function quiet(ms, timeoutMs) {
|
|
1837
|
+
const started = performance.now();
|
|
1838
|
+
let stable = started;
|
|
1839
|
+
let last = version();
|
|
1840
|
+
while (performance.now() - started < timeoutMs) {
|
|
1841
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(25, ms)));
|
|
1842
|
+
const now = version();
|
|
1843
|
+
if (!sameVersion(last, now)) {
|
|
1844
|
+
last = now;
|
|
1845
|
+
stable = performance.now();
|
|
1846
|
+
}
|
|
1847
|
+
if (performance.now() - stable >= ms)
|
|
1848
|
+
return { version: now, quiet: true };
|
|
1849
|
+
}
|
|
1850
|
+
return { version: version(), quiet: false };
|
|
1851
|
+
}
|
|
1852
|
+
observe(document);
|
|
1853
|
+
return { documentId, modalOrder, observe, version, sameVersion, quiet };
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// src/page-script/page-text.ts
|
|
1857
|
+
function createPageText(dependencies) {
|
|
1858
|
+
const {
|
|
1859
|
+
version,
|
|
1860
|
+
modal,
|
|
1861
|
+
visible,
|
|
1862
|
+
excludedTextAncestor,
|
|
1863
|
+
label,
|
|
1864
|
+
countBadgeKind,
|
|
1865
|
+
maxTextNodes
|
|
1866
|
+
} = dependencies;
|
|
1867
|
+
function selectOnly(control) {
|
|
1868
|
+
if (control instanceof HTMLSelectElement) return true;
|
|
1869
|
+
if (!nonEditableCombobox(control)) return false;
|
|
1870
|
+
const autocomplete = control.getAttribute("aria-autocomplete");
|
|
1871
|
+
return autocomplete === null || autocomplete.toLowerCase() === "none";
|
|
1872
|
+
}
|
|
1873
|
+
function nonEditableCombobox(control) {
|
|
1874
|
+
if (control.getAttribute("role") !== "combobox") return false;
|
|
1875
|
+
if (control.matches("input,textarea")) return false;
|
|
1876
|
+
if (isEditable(control)) return false;
|
|
1877
|
+
if (hasEditableDescendant(control)) return false;
|
|
1878
|
+
return !hasExcludedParent(control);
|
|
1879
|
+
}
|
|
1880
|
+
function isEditable(control) {
|
|
1881
|
+
return control instanceof HTMLElement && control.isContentEditable;
|
|
1882
|
+
}
|
|
1883
|
+
function hasExcludedParent(control) {
|
|
1884
|
+
return !!control.parentElement && excludedTextAncestor(control.parentElement);
|
|
1885
|
+
}
|
|
1886
|
+
function hasEditableDescendant(control) {
|
|
1887
|
+
return !!control.querySelector(
|
|
1888
|
+
"input,textarea,[contenteditable]:not([contenteditable='false']),[role='textbox'],[role='searchbox'],[role='spinbutton']"
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
function selectedText(control) {
|
|
1892
|
+
if (control instanceof HTMLSelectElement)
|
|
1893
|
+
return normalize(control.selectedOptions[0]?.textContent ?? "");
|
|
1894
|
+
return customSelectedText(control);
|
|
1895
|
+
}
|
|
1896
|
+
function customSelectedText(control) {
|
|
1897
|
+
const walker = document.createTreeWalker(control, NodeFilter.SHOW_TEXT);
|
|
1898
|
+
const parts = [];
|
|
1899
|
+
while (walker.nextNode()) {
|
|
1900
|
+
const parent = walker.currentNode.parentElement;
|
|
1901
|
+
if (isSelectedTextParent(parent))
|
|
1902
|
+
parts.push(walker.currentNode.textContent ?? "");
|
|
1903
|
+
}
|
|
1904
|
+
return normalize(parts.join(" "));
|
|
1905
|
+
}
|
|
1906
|
+
function isSelectedTextParent(parent) {
|
|
1907
|
+
if (!parent || !visible(parent, true)) return false;
|
|
1908
|
+
return !parent.closest(
|
|
1909
|
+
"input,textarea,select,[contenteditable],script,style,noscript,[role='textbox'],[role='searchbox'],[role='spinbutton'],[role='listbox'],[role='option']"
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
function normalize(text) {
|
|
1913
|
+
return text.replace(/\s+/g, " ").trim();
|
|
1914
|
+
}
|
|
1915
|
+
function incomplete(current, error) {
|
|
1916
|
+
return {
|
|
1917
|
+
protocol: PAGE_PROTOCOL,
|
|
1918
|
+
version: current,
|
|
1919
|
+
text: "",
|
|
1920
|
+
complete: false,
|
|
1921
|
+
error
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
function append(state, part, limit) {
|
|
1925
|
+
if (!part) return "skip";
|
|
1926
|
+
state.size += Array.from(part).length + (state.pieces.length ? 1 : 0);
|
|
1927
|
+
if (state.size > limit) return "too-large";
|
|
1928
|
+
state.pieces.push(part);
|
|
1929
|
+
return "added";
|
|
1930
|
+
}
|
|
1931
|
+
function selectionPart(control) {
|
|
1932
|
+
const selection = selectedText(control);
|
|
1933
|
+
if (!selection) return "";
|
|
1934
|
+
const name = label(control).replace(selection, "").replace(/^[\s.,:;–-]+|[\s.,:;–-]+$/g, "");
|
|
1935
|
+
return name ? `${name}: ${selection}` : selection;
|
|
1936
|
+
}
|
|
1937
|
+
function processSelection(control, state, limit) {
|
|
1938
|
+
if (state.emitted.has(control) || !visible(control)) return "skip";
|
|
1939
|
+
state.emitted.add(control);
|
|
1940
|
+
return append(state, selectionPart(control), limit);
|
|
1941
|
+
}
|
|
1942
|
+
function processNode(node, state, limit) {
|
|
1943
|
+
const parent = node.parentElement;
|
|
1944
|
+
const control = parent?.closest("select,[role='combobox']");
|
|
1945
|
+
if (control && isSelectionControl(control, state))
|
|
1946
|
+
return processSelection(control, state, limit);
|
|
1947
|
+
if (!isPublicTextParent(parent)) return "skip";
|
|
1948
|
+
const text = normalize(node.textContent ?? "");
|
|
1949
|
+
if (!text) return "skip";
|
|
1950
|
+
const kind = badgeKind(parent, text);
|
|
1951
|
+
return append(state, kind ? `${kind} icon badge: ${text}` : text, limit);
|
|
1952
|
+
}
|
|
1953
|
+
function isSelectionControl(control, state) {
|
|
1954
|
+
return state.emitted.has(control) || selectOnly(control);
|
|
1955
|
+
}
|
|
1956
|
+
function isPublicTextParent(parent) {
|
|
1957
|
+
if (!parent || !visible(parent)) return false;
|
|
1958
|
+
return !excludedTextAncestor(parent);
|
|
1959
|
+
}
|
|
1960
|
+
function badgeKind(parent, text) {
|
|
1961
|
+
if (!/^\d{1,4}\+?$/.test(text)) return "";
|
|
1962
|
+
return countBadgeKind(parent, text);
|
|
1963
|
+
}
|
|
1964
|
+
function pageText(limit) {
|
|
350
1965
|
const current = version();
|
|
351
1966
|
const selectedModal = modal();
|
|
352
1967
|
if (selectedModal === void 0)
|
|
353
|
-
return
|
|
354
|
-
protocol: PAGE_PROTOCOL,
|
|
355
|
-
version: current,
|
|
356
|
-
text: "",
|
|
357
|
-
complete: false,
|
|
358
|
-
error: "scope_ambiguous"
|
|
359
|
-
};
|
|
1968
|
+
return incomplete(current, "scope_ambiguous");
|
|
360
1969
|
const root = selectedModal ?? document.body;
|
|
361
1970
|
if (!root)
|
|
362
1971
|
return {
|
|
@@ -365,218 +1974,515 @@ var SedumPageScript = (() => {
|
|
|
365
1974
|
text: "",
|
|
366
1975
|
complete: true
|
|
367
1976
|
};
|
|
1977
|
+
return walkText(root, current, limit);
|
|
1978
|
+
}
|
|
1979
|
+
function walkText(root, current, limit) {
|
|
368
1980
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
369
|
-
const
|
|
370
|
-
let size = 0;
|
|
1981
|
+
const state = { pieces: [], emitted: /* @__PURE__ */ new Set(), size: 0 };
|
|
371
1982
|
let count = 0;
|
|
372
1983
|
while (walker.nextNode()) {
|
|
373
|
-
if (++count >
|
|
374
|
-
return
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
text: "",
|
|
378
|
-
complete: false,
|
|
379
|
-
error: "resource_ceiling"
|
|
380
|
-
};
|
|
381
|
-
const node = walker.currentNode;
|
|
382
|
-
const parent = node.parentElement;
|
|
383
|
-
if (!parent || !visible(parent) || excludedTextAncestor(parent)) continue;
|
|
384
|
-
const part = (node.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
385
|
-
if (!part) continue;
|
|
386
|
-
size += Array.from(part).length + (pieces.length ? 1 : 0);
|
|
387
|
-
if (size > DIGEST_LIMIT)
|
|
388
|
-
return {
|
|
389
|
-
protocol: PAGE_PROTOCOL,
|
|
390
|
-
version: current,
|
|
391
|
-
text: "",
|
|
392
|
-
complete: false,
|
|
393
|
-
error: "digest_too_large"
|
|
394
|
-
};
|
|
395
|
-
pieces.push(part);
|
|
1984
|
+
if (++count > maxTextNodes)
|
|
1985
|
+
return incomplete(current, "resource_ceiling");
|
|
1986
|
+
if (processNode(walker.currentNode, state, limit) === "too-large")
|
|
1987
|
+
return incomplete(current, "digest_too_large");
|
|
396
1988
|
}
|
|
397
1989
|
return {
|
|
398
1990
|
protocol: PAGE_PROTOCOL,
|
|
399
1991
|
version: current,
|
|
400
|
-
text: pieces.join(" "),
|
|
1992
|
+
text: state.pieces.join(" "),
|
|
401
1993
|
complete: true
|
|
402
1994
|
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
1995
|
+
}
|
|
1996
|
+
return {
|
|
1997
|
+
digest: () => pageText(DIGEST_LIMIT),
|
|
1998
|
+
visibleText: () => pageText(Number.MAX_SAFE_INTEGER)
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// src/page-script/target-actions.ts
|
|
2003
|
+
var FILLABLE_INPUT_TYPES2 = /* @__PURE__ */ new Set([
|
|
2004
|
+
"text",
|
|
2005
|
+
"email",
|
|
2006
|
+
"password",
|
|
2007
|
+
"search",
|
|
2008
|
+
"tel",
|
|
2009
|
+
"url",
|
|
2010
|
+
"number",
|
|
2011
|
+
"date",
|
|
2012
|
+
"datetime-local",
|
|
2013
|
+
"time",
|
|
2014
|
+
"month",
|
|
2015
|
+
"week"
|
|
2016
|
+
]);
|
|
2017
|
+
function createTargetActions(deps) {
|
|
2018
|
+
function refElement(ref) {
|
|
2019
|
+
const element = deps.snapshot()?.refs.get(ref);
|
|
2020
|
+
if (!element) return null;
|
|
2021
|
+
if (!element.isConnected) return null;
|
|
2022
|
+
if (element.ownerDocument !== deps.document) return null;
|
|
2023
|
+
return element.getAttribute("data-sedum-ref") === ref ? element : null;
|
|
2024
|
+
}
|
|
2025
|
+
function snapshotFor(target, operations) {
|
|
2026
|
+
const current = deps.version();
|
|
2027
|
+
const snapshot = deps.snapshot();
|
|
2028
|
+
if (!snapshot || !operations.includes(snapshot.operation)) return null;
|
|
2029
|
+
if (!deps.sameVersion(snapshot.version, current)) return null;
|
|
2030
|
+
return deps.sameVersion(target.version, current) ? snapshot : null;
|
|
2031
|
+
}
|
|
2032
|
+
function candidateFor(snapshot, target) {
|
|
428
2033
|
const element = refElement(target.ref);
|
|
429
2034
|
const candidate = snapshot.candidates.find(
|
|
430
2035
|
(item) => item.ref === target.ref
|
|
431
2036
|
);
|
|
432
|
-
if (!element || !candidate
|
|
2037
|
+
if (!element || !candidate) return null;
|
|
2038
|
+
if (element.tagName.toLowerCase() !== target.tag) return null;
|
|
2039
|
+
return candidate.name === target.name ? { element, candidate } : null;
|
|
2040
|
+
}
|
|
2041
|
+
function samePeers(element, candidate, operation) {
|
|
2042
|
+
return JSON.stringify(deps.peers(element, candidate.name, operation).texts) === JSON.stringify(candidate.peers);
|
|
2043
|
+
}
|
|
2044
|
+
function uniqueRef(element, ref) {
|
|
2045
|
+
const matches = (deps.allElements(deps.document.documentElement, Infinity) ?? []).filter((node) => node.getAttribute("data-sedum-ref") === ref);
|
|
2046
|
+
return matches.length === 1 && matches[0] === element;
|
|
2047
|
+
}
|
|
2048
|
+
function isFillControl(element) {
|
|
2049
|
+
return [
|
|
2050
|
+
element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement,
|
|
2051
|
+
element instanceof HTMLElement && element.isContentEditable
|
|
2052
|
+
].includes(true);
|
|
2053
|
+
}
|
|
2054
|
+
function fillElement(target) {
|
|
2055
|
+
const snapshot = snapshotFor(target, ["fill"]);
|
|
2056
|
+
if (!snapshot) return null;
|
|
2057
|
+
const found = candidateFor(snapshot, target);
|
|
2058
|
+
if (!found || !uniqueRef(found.element, target.ref)) return null;
|
|
2059
|
+
const { element, candidate } = found;
|
|
2060
|
+
return validFillTarget(element, candidate) ? element : null;
|
|
2061
|
+
}
|
|
2062
|
+
function validFillTarget(element, candidate) {
|
|
2063
|
+
if (!validFillIdentity(element, candidate)) return false;
|
|
2064
|
+
return actionableFill(element);
|
|
2065
|
+
}
|
|
2066
|
+
function validFillIdentity(element, candidate) {
|
|
2067
|
+
return [
|
|
2068
|
+
candidate.editable,
|
|
2069
|
+
isFillControl(element),
|
|
2070
|
+
deps.candidateName(element) === deps.rawName(element),
|
|
2071
|
+
samePeers(element, candidate)
|
|
2072
|
+
].every(Boolean);
|
|
2073
|
+
}
|
|
2074
|
+
function actionableFill(element) {
|
|
2075
|
+
return [
|
|
2076
|
+
deps.editable(element),
|
|
2077
|
+
deps.visible(element),
|
|
2078
|
+
!deps.disabled(element)
|
|
2079
|
+
].every(Boolean);
|
|
2080
|
+
}
|
|
2081
|
+
function readTarget(target) {
|
|
2082
|
+
const snapshot = snapshotFor(target, ["read"]);
|
|
2083
|
+
if (!snapshot) return { status: "stale" };
|
|
2084
|
+
const found = candidateFor(snapshot, target);
|
|
2085
|
+
if (!found || !validReadTarget(found.element, found.candidate))
|
|
433
2086
|
return { status: "stale" };
|
|
434
|
-
const text = publicText(element);
|
|
2087
|
+
const text = deps.publicText(found.element);
|
|
435
2088
|
if (!text) return { status: "empty" };
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
2089
|
+
return Array.from(text).length > 4096 ? { status: "too_long" } : { status: "ok", text };
|
|
2090
|
+
}
|
|
2091
|
+
function validReadTarget(element, candidate) {
|
|
2092
|
+
if (!readIdentityMatches(element, candidate)) return false;
|
|
2093
|
+
return deps.readable(element) && deps.visible(element);
|
|
2094
|
+
}
|
|
2095
|
+
function readIdentityMatches(element, candidate) {
|
|
2096
|
+
if (deps.label(element) !== deps.rawName(element)) return false;
|
|
2097
|
+
return samePeers(element, candidate, "read");
|
|
2098
|
+
}
|
|
2099
|
+
function activeElement(root) {
|
|
2100
|
+
const focused = root.activeElement;
|
|
2101
|
+
return focused?.shadowRoot ? activeElement(focused.shadowRoot) ?? focused : focused;
|
|
2102
|
+
}
|
|
2103
|
+
function textValue(element) {
|
|
2104
|
+
if (publicTextField(element))
|
|
2105
|
+
return element.value;
|
|
2106
|
+
if (!(element instanceof HTMLElement)) return null;
|
|
2107
|
+
return element.isContentEditable ? element.textContent ?? "" : null;
|
|
2108
|
+
}
|
|
2109
|
+
function publicTextField(element) {
|
|
2110
|
+
if (element instanceof HTMLTextAreaElement) return true;
|
|
2111
|
+
if (!(element instanceof HTMLInputElement)) return false;
|
|
2112
|
+
if (!FILLABLE_INPUT_TYPES2.has(element.type)) return false;
|
|
2113
|
+
return element.type !== "password";
|
|
2114
|
+
}
|
|
2115
|
+
function checkedState(control) {
|
|
2116
|
+
if (deps.isToggle(control)) return control.checked;
|
|
2117
|
+
const checked = control.getAttribute("aria-checked");
|
|
2118
|
+
if (checked === "true" || checked === "mixed") return true;
|
|
2119
|
+
return checked === "false" ? false : null;
|
|
2120
|
+
}
|
|
2121
|
+
function controlState(target) {
|
|
2122
|
+
const snapshot = snapshotFor(target, ["click", "fill"]);
|
|
2123
|
+
if (!snapshot) return { status: "stale" };
|
|
2124
|
+
const found = candidateFor(snapshot, target);
|
|
2125
|
+
if (!found) return { status: "stale" };
|
|
2126
|
+
const control = deps.toggleLabel(found.element) ?? found.element;
|
|
2127
|
+
const focused = activeElement(deps.document);
|
|
2128
|
+
return {
|
|
2129
|
+
status: "ok",
|
|
2130
|
+
disabled: deps.disabled(control),
|
|
2131
|
+
checked: checkedState(control),
|
|
2132
|
+
focused: !!focused && (focused === control || deps.deepContains(control, focused)),
|
|
2133
|
+
value: textValue(found.element)
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
function currentAim(ref, expected) {
|
|
2137
|
+
const current = deps.version();
|
|
2138
|
+
const snapshot = deps.snapshot();
|
|
2139
|
+
if (!snapshot || !deps.sameVersion(snapshot.version, current)) return null;
|
|
2140
|
+
if (expected && !matchesVersion(expected, current)) return null;
|
|
2141
|
+
return { current, snapshot, element: refElement(ref) };
|
|
2142
|
+
}
|
|
2143
|
+
function matchesVersion(expected, current) {
|
|
2144
|
+
return expected.document === current.document && expected.route === current.route && expected.revision === current.revision;
|
|
2145
|
+
}
|
|
2146
|
+
function validAimIdentity(element, candidate, expected) {
|
|
446
2147
|
if (expected && element.tagName.toLowerCase() !== expected.tag)
|
|
447
|
-
return
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
2148
|
+
return false;
|
|
2149
|
+
if (deps.candidateName(element, !!deps.hoverHost(element)) !== deps.rawName(element))
|
|
2150
|
+
return false;
|
|
2151
|
+
if (!samePeers(element, candidate)) return false;
|
|
2152
|
+
return !expected || expected.name === candidate.name;
|
|
2153
|
+
}
|
|
2154
|
+
function isSafeAction(element, shownBy) {
|
|
2155
|
+
if (!isShownAction(element, shownBy)) return false;
|
|
2156
|
+
if (deps.disabled(element)) return false;
|
|
2157
|
+
const link = element.closest("a[href]");
|
|
2158
|
+
if (!link) return true;
|
|
2159
|
+
if (link !== element) return false;
|
|
2160
|
+
if (!(link instanceof HTMLAnchorElement)) return true;
|
|
2161
|
+
return isSafeLink(link);
|
|
2162
|
+
}
|
|
2163
|
+
function isShownAction(element, shownBy) {
|
|
2164
|
+
return [
|
|
2165
|
+
deps.visible(element),
|
|
2166
|
+
deps.transparentToggle(element),
|
|
2167
|
+
deps.ariaHiddenOnly(element),
|
|
2168
|
+
!!shownBy
|
|
2169
|
+
].includes(true);
|
|
2170
|
+
}
|
|
2171
|
+
function isSafeLink(link) {
|
|
2172
|
+
if (link.hasAttribute("download")) return false;
|
|
2173
|
+
if (!["", "_self"].includes(link.target)) return false;
|
|
2174
|
+
return ["http:", "https:"].includes(new URL(link.href).protocol);
|
|
2175
|
+
}
|
|
2176
|
+
function points(rect, expected, direct) {
|
|
2177
|
+
if (useExpectedPoint(expected, direct))
|
|
2178
|
+
return [[expected.point.x / rect.width, expected.point.y / rect.height]];
|
|
2179
|
+
return [
|
|
470
2180
|
[0.5, 0.5],
|
|
471
2181
|
[0.25, 0.5],
|
|
472
2182
|
[0.75, 0.5],
|
|
473
2183
|
[0.5, 0.25],
|
|
474
2184
|
[0.5, 0.75]
|
|
475
2185
|
];
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
box: {
|
|
493
|
-
x: Math.max(0, rect.left / innerWidth),
|
|
494
|
-
y: Math.max(0, rect.top / innerHeight),
|
|
495
|
-
width: Math.min(1, rect.width / innerWidth),
|
|
496
|
-
height: Math.min(1, rect.height / innerHeight)
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
}
|
|
2186
|
+
}
|
|
2187
|
+
function useExpectedPoint(expected, direct) {
|
|
2188
|
+
if (!expected || !direct) return false;
|
|
2189
|
+
return !expected.hover;
|
|
2190
|
+
}
|
|
2191
|
+
function hitTest(input) {
|
|
2192
|
+
const target = input.shownBy && !deps.visible(input.element) ? input.shownBy : input.element;
|
|
2193
|
+
const rect = target.getBoundingClientRect();
|
|
2194
|
+
if (!rect.width || !rect.height) return null;
|
|
2195
|
+
for (const [fx, fy] of points(
|
|
2196
|
+
rect,
|
|
2197
|
+
input.expected,
|
|
2198
|
+
target === input.element
|
|
2199
|
+
)) {
|
|
2200
|
+
const result = hitPoint({ input, target, rect, fx, fy });
|
|
2201
|
+
if (result) return result;
|
|
501
2202
|
}
|
|
502
|
-
return
|
|
2203
|
+
return null;
|
|
2204
|
+
}
|
|
2205
|
+
function hitPoint(point) {
|
|
2206
|
+
const { input, target, rect, fx, fy } = point;
|
|
2207
|
+
const { width, height } = deps.viewport();
|
|
2208
|
+
const x = rect.left + rect.width * fx;
|
|
2209
|
+
const y = rect.top + rect.height * fy;
|
|
2210
|
+
if (outsideViewport(x, y, width, height)) return null;
|
|
2211
|
+
const hit = deps.deepElementFromPoint(x, y);
|
|
2212
|
+
if (!hit || !deps.deepContains(target, hit)) return null;
|
|
2213
|
+
return {
|
|
2214
|
+
actionable: true,
|
|
2215
|
+
aim: {
|
|
2216
|
+
ref: input.ref,
|
|
2217
|
+
...input.current,
|
|
2218
|
+
tag: input.element.tagName.toLowerCase(),
|
|
2219
|
+
name: input.candidate.name,
|
|
2220
|
+
point: target === input.element ? { x: rect.width * fx, y: rect.height * fy } : { x: 0, y: 0 },
|
|
2221
|
+
...input.shownBy ? { hover: true } : {},
|
|
2222
|
+
box: {
|
|
2223
|
+
x: Math.max(0, rect.left / width),
|
|
2224
|
+
y: Math.max(0, rect.top / height),
|
|
2225
|
+
width: Math.min(1, rect.width / width),
|
|
2226
|
+
height: Math.min(1, rect.height / height)
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
function outsideViewport(x, y, width, height) {
|
|
2232
|
+
if (x < 0 || y < 0) return true;
|
|
2233
|
+
return x >= width || y >= height;
|
|
2234
|
+
}
|
|
2235
|
+
function aim(ref, expected) {
|
|
2236
|
+
const state = currentAim(ref, expected);
|
|
2237
|
+
if (!state) return { actionable: false, reason: "stale" };
|
|
2238
|
+
if (!state.element) return { actionable: false, reason: "target_missing" };
|
|
2239
|
+
const candidate = aimCandidate(
|
|
2240
|
+
state.snapshot,
|
|
2241
|
+
state.element,
|
|
2242
|
+
ref,
|
|
2243
|
+
expected
|
|
2244
|
+
);
|
|
2245
|
+
if (!candidate) return { actionable: false, reason: "stale" };
|
|
2246
|
+
const shownBy = deps.visible(state.element) ? null : deps.hoverHost(state.element);
|
|
2247
|
+
if (!isSafeAction(state.element, shownBy))
|
|
2248
|
+
return { actionable: false, reason: "not_actionable" };
|
|
2249
|
+
const input = {
|
|
2250
|
+
ref,
|
|
2251
|
+
current: state.current,
|
|
2252
|
+
element: state.element,
|
|
2253
|
+
candidate,
|
|
2254
|
+
shownBy,
|
|
2255
|
+
expected
|
|
2256
|
+
};
|
|
2257
|
+
const inPlace = hitTest(input);
|
|
2258
|
+
if (inPlace) return inPlace;
|
|
2259
|
+
if (expected) return { actionable: false, reason: "not_actionable" };
|
|
2260
|
+
return retryAfterScroll(input);
|
|
2261
|
+
}
|
|
2262
|
+
function aimCandidate(snapshot, element, ref, expected) {
|
|
2263
|
+
const candidate = snapshot.candidates.find((item) => item.ref === ref);
|
|
2264
|
+
if (!candidate) return null;
|
|
2265
|
+
return validAimIdentity(element, candidate, expected) ? candidate : null;
|
|
2266
|
+
}
|
|
2267
|
+
function retryAfterScroll(input) {
|
|
2268
|
+
input.element.scrollIntoView({
|
|
2269
|
+
block: "center",
|
|
2270
|
+
inline: "center",
|
|
2271
|
+
behavior: "instant"
|
|
2272
|
+
});
|
|
2273
|
+
if (targetChanged(input.ref, input.current, input.element))
|
|
2274
|
+
return { actionable: false, reason: "stale" };
|
|
2275
|
+
return hitTest(input) ?? { actionable: false, reason: "not_actionable" };
|
|
2276
|
+
}
|
|
2277
|
+
function targetChanged(ref, version, element) {
|
|
2278
|
+
if (!deps.sameVersion(deps.version(), version)) return true;
|
|
2279
|
+
return refElement(ref) !== element;
|
|
2280
|
+
}
|
|
2281
|
+
function hoverElement(expected) {
|
|
2282
|
+
const current = deps.version();
|
|
2283
|
+
const snapshot = deps.snapshot();
|
|
2284
|
+
if (!snapshot || !deps.sameVersion(snapshot.version, current)) return null;
|
|
2285
|
+
const element = refElement(expected.ref);
|
|
2286
|
+
if (!element || element.tagName.toLowerCase() !== expected.tag) return null;
|
|
2287
|
+
if (deps.candidateName(element, true) !== deps.rawName(element))
|
|
2288
|
+
return null;
|
|
2289
|
+
return deps.visible(element) ? null : deps.hoverHost(element);
|
|
2290
|
+
}
|
|
2291
|
+
return {
|
|
2292
|
+
refElement,
|
|
2293
|
+
fillElement,
|
|
2294
|
+
readTarget,
|
|
2295
|
+
controlState,
|
|
2296
|
+
aim,
|
|
2297
|
+
hoverElement
|
|
503
2298
|
};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
// src/page-script/visual-candidates.ts
|
|
2302
|
+
function createVisualCandidates(deps) {
|
|
2303
|
+
return () => {
|
|
2304
|
+
const current = deps.version();
|
|
2305
|
+
const snapshot = deps.snapshot();
|
|
2306
|
+
if (!snapshot || !deps.sameVersion(snapshot.version, current))
|
|
2307
|
+
throw new Error("stale visual observation");
|
|
2308
|
+
return {
|
|
2309
|
+
version: current,
|
|
2310
|
+
width: innerWidth,
|
|
2311
|
+
height: innerHeight,
|
|
2312
|
+
boxes: snapshot.candidates.flatMap((candidate) => boxFor(candidate.ref))
|
|
2313
|
+
};
|
|
2314
|
+
};
|
|
2315
|
+
function boxFor(ref) {
|
|
2316
|
+
const element = deps.refElement(ref);
|
|
2317
|
+
if (!element) return [];
|
|
2318
|
+
if (!deps.visible(element)) return [];
|
|
2319
|
+
if (deps.disabled(element)) return [];
|
|
2320
|
+
const rect = element.getBoundingClientRect();
|
|
2321
|
+
if (!insideViewport(rect)) return [];
|
|
2322
|
+
const hit = deps.deepElementFromPoint(
|
|
2323
|
+
rect.left + rect.width / 2,
|
|
2324
|
+
rect.top + rect.height / 2
|
|
2325
|
+
);
|
|
2326
|
+
if (!hit || !deps.deepContains(element, hit)) return [];
|
|
2327
|
+
return [
|
|
2328
|
+
{
|
|
2329
|
+
ref,
|
|
2330
|
+
x: rect.left,
|
|
2331
|
+
y: rect.top,
|
|
2332
|
+
width: rect.width,
|
|
2333
|
+
height: rect.height
|
|
535
2334
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
)
|
|
540
|
-
|
|
2335
|
+
];
|
|
2336
|
+
}
|
|
2337
|
+
function insideViewport(rect) {
|
|
2338
|
+
if (rect.width <= 0) return false;
|
|
2339
|
+
if (rect.height <= 0) return false;
|
|
2340
|
+
if (rect.left < 0) return false;
|
|
2341
|
+
if (rect.top < 0) return false;
|
|
2342
|
+
return rect.right <= innerWidth && rect.bottom <= innerHeight;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
// src/page-script/runtime.ts
|
|
2347
|
+
var MAX_TEXT_NODES = 2e4;
|
|
2348
|
+
function createPageBridge() {
|
|
2349
|
+
const lifecycle = createPageLifecycle();
|
|
2350
|
+
const traversal = createDomTraversal({
|
|
2351
|
+
document,
|
|
2352
|
+
observe: lifecycle.observe
|
|
2353
|
+
});
|
|
2354
|
+
const semantics = createElementSemantics({
|
|
2355
|
+
document,
|
|
2356
|
+
modalOrder: lifecycle.modalOrder,
|
|
2357
|
+
composedParent: traversal.composedParent,
|
|
2358
|
+
allElements: traversal.allElements,
|
|
2359
|
+
flatTextNodes: traversal.flatTextNodes
|
|
2360
|
+
});
|
|
2361
|
+
const names = createCandidateNames({
|
|
2362
|
+
...traversal,
|
|
2363
|
+
...semantics
|
|
2364
|
+
});
|
|
2365
|
+
const hover = createHoverDiscovery({
|
|
2366
|
+
composedParent: traversal.composedParent,
|
|
2367
|
+
interactive: semantics.interactive,
|
|
2368
|
+
visible: semantics.visible
|
|
2369
|
+
});
|
|
2370
|
+
const context = createCandidateContext({
|
|
2371
|
+
document,
|
|
2372
|
+
composedParent: traversal.composedParent,
|
|
2373
|
+
allElements: traversal.allElements,
|
|
2374
|
+
visible: semantics.visible,
|
|
2375
|
+
interactive: semantics.interactive,
|
|
2376
|
+
pointerTarget: semantics.pointerTarget,
|
|
2377
|
+
publicText: semantics.publicText,
|
|
2378
|
+
excludedTextAncestor: semantics.excludedTextAncestor,
|
|
2379
|
+
hoverRevealed: hover.revealed,
|
|
2380
|
+
label: names.label,
|
|
2381
|
+
mediaName: names.mediaName,
|
|
2382
|
+
iconName: names.iconName
|
|
2383
|
+
});
|
|
2384
|
+
const scanner = createCandidateScanner({
|
|
2385
|
+
document,
|
|
2386
|
+
documentId: lifecycle.documentId,
|
|
2387
|
+
version: lifecycle.version,
|
|
2388
|
+
sameVersion: lifecycle.sameVersion,
|
|
2389
|
+
modal: semantics.modal,
|
|
2390
|
+
allElements: traversal.allElements,
|
|
2391
|
+
resetContext: context.reset,
|
|
2392
|
+
resetHover: hover.reset,
|
|
2393
|
+
observeHeading: context.observeHeading,
|
|
2394
|
+
visible: semantics.visible,
|
|
2395
|
+
transparentToggle: semantics.transparentToggle,
|
|
2396
|
+
ariaHiddenOnly: semantics.ariaHiddenOnly,
|
|
2397
|
+
hoverHost: hover.host,
|
|
2398
|
+
toggleLabel: semantics.toggleLabel,
|
|
2399
|
+
readable: semantics.readable,
|
|
2400
|
+
interactive: semantics.interactive,
|
|
2401
|
+
pointerTarget: semantics.pointerTarget,
|
|
2402
|
+
editable: semantics.editable,
|
|
2403
|
+
role: semantics.role,
|
|
2404
|
+
label: names.label,
|
|
2405
|
+
candidateName: names.candidateName,
|
|
2406
|
+
boundedName: context.boundedName,
|
|
2407
|
+
peers: context.peers,
|
|
2408
|
+
locationOf: context.locationOf,
|
|
2409
|
+
sectionOf: context.sectionOf,
|
|
2410
|
+
nameHint: names.nameHint,
|
|
2411
|
+
disabled: semantics.disabled,
|
|
2412
|
+
inArticleBody: context.inArticleBody,
|
|
2413
|
+
path: context.path
|
|
2414
|
+
});
|
|
2415
|
+
const pageText = createPageText({
|
|
2416
|
+
version: lifecycle.version,
|
|
2417
|
+
modal: semantics.modal,
|
|
2418
|
+
visible: semantics.visible,
|
|
2419
|
+
excludedTextAncestor: semantics.excludedTextAncestor,
|
|
2420
|
+
label: names.label,
|
|
2421
|
+
countBadgeKind: names.countBadgeKind,
|
|
2422
|
+
maxTextNodes: MAX_TEXT_NODES
|
|
541
2423
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
2424
|
+
const actions = createTargetActions({
|
|
2425
|
+
document,
|
|
2426
|
+
snapshot: scanner.snapshot,
|
|
2427
|
+
version: lifecycle.version,
|
|
2428
|
+
sameVersion: lifecycle.sameVersion,
|
|
2429
|
+
rawName: scanner.rawName,
|
|
2430
|
+
allElements: traversal.allElements,
|
|
2431
|
+
candidateName: names.candidateName,
|
|
2432
|
+
peers: context.peers,
|
|
2433
|
+
editable: semantics.editable,
|
|
2434
|
+
readable: semantics.readable,
|
|
2435
|
+
visible: semantics.visible,
|
|
2436
|
+
disabled: semantics.disabled,
|
|
2437
|
+
label: names.label,
|
|
2438
|
+
publicText: semantics.publicText,
|
|
2439
|
+
toggleLabel: semantics.toggleLabel,
|
|
2440
|
+
isToggle: semantics.isToggle,
|
|
2441
|
+
deepContains: traversal.deepContains,
|
|
2442
|
+
hoverHost: hover.host,
|
|
2443
|
+
transparentToggle: semantics.transparentToggle,
|
|
2444
|
+
ariaHiddenOnly: semantics.ariaHiddenOnly,
|
|
2445
|
+
deepElementFromPoint: traversal.deepElementFromPoint,
|
|
2446
|
+
viewport: () => ({ width: innerWidth, height: innerHeight })
|
|
548
2447
|
});
|
|
549
|
-
const
|
|
2448
|
+
const visualCandidates = createVisualCandidates({
|
|
2449
|
+
version: lifecycle.version,
|
|
2450
|
+
sameVersion: lifecycle.sameVersion,
|
|
2451
|
+
snapshot: scanner.snapshot,
|
|
2452
|
+
refElement: actions.refElement,
|
|
2453
|
+
visible: semantics.visible,
|
|
2454
|
+
disabled: semantics.disabled,
|
|
2455
|
+
deepElementFromPoint: traversal.deepElementFromPoint,
|
|
2456
|
+
deepContains: traversal.deepContains
|
|
2457
|
+
});
|
|
2458
|
+
return createBridge(lifecycle, scanner, pageText, actions, visualCandidates);
|
|
2459
|
+
}
|
|
2460
|
+
function createBridge(lifecycle, scanner, pageText, actions, visualCandidates) {
|
|
2461
|
+
return {
|
|
550
2462
|
protocol: PAGE_PROTOCOL,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
2463
|
+
visualCandidates,
|
|
2464
|
+
collect: scanner.collect,
|
|
2465
|
+
digest: pageText.digest,
|
|
2466
|
+
visibleText: pageText.visibleText,
|
|
2467
|
+
pageVersion: lifecycle.version,
|
|
554
2468
|
findBySignals: ({ operation }) => {
|
|
555
|
-
const first = collect({ operation });
|
|
556
|
-
return { ...first, candidates:
|
|
2469
|
+
const first = scanner.collect({ operation });
|
|
2470
|
+
return { ...first, candidates: scanner.candidates(), next: null };
|
|
557
2471
|
},
|
|
558
|
-
clickTarget: (ref) => aim(ref),
|
|
559
|
-
readTarget,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
let last = version();
|
|
567
|
-
while (performance.now() - started < timeoutMs) {
|
|
568
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(25, ms)));
|
|
569
|
-
const now = version();
|
|
570
|
-
if (!same(last, now)) {
|
|
571
|
-
last = now;
|
|
572
|
-
stable = performance.now();
|
|
573
|
-
}
|
|
574
|
-
if (performance.now() - stable >= ms)
|
|
575
|
-
return { version: now, quiet: true };
|
|
576
|
-
}
|
|
577
|
-
return { version: version(), quiet: false };
|
|
578
|
-
}
|
|
2472
|
+
clickTarget: (ref) => actions.aim(ref),
|
|
2473
|
+
readTarget: actions.readTarget,
|
|
2474
|
+
controlState: actions.controlState,
|
|
2475
|
+
checkAim: (expected) => actions.aim(expected.ref, expected),
|
|
2476
|
+
hoverElement: actions.hoverElement,
|
|
2477
|
+
fillElement: actions.fillElement,
|
|
2478
|
+
clearRefs: scanner.clearRefs,
|
|
2479
|
+
quiet: ({ ms, timeoutMs }) => lifecycle.quiet(ms, timeoutMs)
|
|
579
2480
|
};
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
// src/page-script/index.ts
|
|
2484
|
+
if (!window.__sedum) {
|
|
2485
|
+
const bridge = createPageBridge();
|
|
580
2486
|
Object.freeze(bridge);
|
|
581
2487
|
Object.defineProperty(window, "__sedum", {
|
|
582
2488
|
value: bridge,
|
|
@@ -584,28 +2490,4 @@ var SedumPageScript = (() => {
|
|
|
584
2490
|
writable: false
|
|
585
2491
|
});
|
|
586
2492
|
}
|
|
587
|
-
var version2;
|
|
588
|
-
var same2;
|
|
589
|
-
var clearRefs2;
|
|
590
|
-
var visible2;
|
|
591
|
-
var modal2;
|
|
592
|
-
var excludedTextAncestor2;
|
|
593
|
-
var publicText2;
|
|
594
|
-
var label2;
|
|
595
|
-
var role2;
|
|
596
|
-
var interactive2;
|
|
597
|
-
var readable2;
|
|
598
|
-
var editable2;
|
|
599
|
-
var disabled2;
|
|
600
|
-
var path2;
|
|
601
|
-
var inArticleBody2;
|
|
602
|
-
var itemContext2;
|
|
603
|
-
var peers2;
|
|
604
|
-
var scan2;
|
|
605
|
-
var collect2;
|
|
606
|
-
var digest2;
|
|
607
|
-
var refElement2;
|
|
608
|
-
var fillElement2;
|
|
609
|
-
var readTarget2;
|
|
610
|
-
var aim2;
|
|
611
2493
|
})();
|