@sedum-dev/core 0.1.0-alpha.0 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/index.d.ts +95 -1
- package/dist/index.js +657 -124
- package/dist/page-script/index.global.js +678 -96
- package/package.json +4 -1
|
@@ -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([
|
|
@@ -31,7 +32,78 @@ var SedumPageScript = (() => {
|
|
|
31
32
|
|
|
32
33
|
// src/page-script/index.ts
|
|
33
34
|
if (!window.__sedum) {
|
|
34
|
-
let
|
|
35
|
+
let observe = function(root) {
|
|
36
|
+
if (observed.has(root)) return;
|
|
37
|
+
observed.add(root);
|
|
38
|
+
observer.observe(root, {
|
|
39
|
+
subtree: true,
|
|
40
|
+
childList: true,
|
|
41
|
+
characterData: true,
|
|
42
|
+
attributes: true,
|
|
43
|
+
attributeOldValue: true
|
|
44
|
+
});
|
|
45
|
+
}, composedParent = function(element) {
|
|
46
|
+
if (element.parentElement) return element.parentElement;
|
|
47
|
+
const parent = element.parentNode;
|
|
48
|
+
return parent instanceof ShadowRoot ? parent.host : null;
|
|
49
|
+
}, allElements = function(root, limit, skipDrawings = false) {
|
|
50
|
+
const result = [];
|
|
51
|
+
const stack = [];
|
|
52
|
+
const push = (parent) => {
|
|
53
|
+
for (let i = parent.children.length - 1; i >= 0; i--)
|
|
54
|
+
stack.push(parent.children[i]);
|
|
55
|
+
};
|
|
56
|
+
if (root.shadowRoot) {
|
|
57
|
+
observe(root.shadowRoot);
|
|
58
|
+
push(root.shadowRoot);
|
|
59
|
+
}
|
|
60
|
+
push(root);
|
|
61
|
+
while (stack.length) {
|
|
62
|
+
const element = stack.pop();
|
|
63
|
+
result.push(element);
|
|
64
|
+
if (result.length > limit) return null;
|
|
65
|
+
if (skipDrawings && element instanceof SVGSVGElement) continue;
|
|
66
|
+
push(element);
|
|
67
|
+
if (element.shadowRoot) {
|
|
68
|
+
observe(element.shadowRoot);
|
|
69
|
+
push(element.shadowRoot);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}, flatTextNodes = function(root) {
|
|
74
|
+
const result = [];
|
|
75
|
+
const visit = (node) => {
|
|
76
|
+
if (node instanceof Text) {
|
|
77
|
+
result.push(node);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (node instanceof HTMLSlotElement) {
|
|
81
|
+
const assigned = node.assignedNodes({ flatten: true });
|
|
82
|
+
for (const child of assigned.length ? assigned : Array.from(node.childNodes))
|
|
83
|
+
visit(child);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const children = node instanceof Element && node.shadowRoot ? node.shadowRoot.childNodes : node.childNodes;
|
|
87
|
+
for (const child of Array.from(children)) visit(child);
|
|
88
|
+
};
|
|
89
|
+
visit(root);
|
|
90
|
+
return result;
|
|
91
|
+
}, deepElementFromPoint = function(x, y) {
|
|
92
|
+
let hit = document.elementFromPoint(x, y);
|
|
93
|
+
while (hit?.shadowRoot) {
|
|
94
|
+
const root = hit.shadowRoot;
|
|
95
|
+
const inner = root.elementsFromPoint(x, y).find((element) => element.getRootNode() === root);
|
|
96
|
+
if (!inner) break;
|
|
97
|
+
hit = inner;
|
|
98
|
+
}
|
|
99
|
+
return hit;
|
|
100
|
+
}, deepContains = function(ancestor, node) {
|
|
101
|
+
for (let current = node; current; ) {
|
|
102
|
+
if (current === ancestor) return true;
|
|
103
|
+
current = composedParent(current);
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}, version = function() {
|
|
35
107
|
if (route !== location.href) {
|
|
36
108
|
route = location.href;
|
|
37
109
|
revision++;
|
|
@@ -47,9 +119,9 @@ var SedumPageScript = (() => {
|
|
|
47
119
|
}
|
|
48
120
|
owned.clear();
|
|
49
121
|
snapshot = void 0;
|
|
50
|
-
}, visible = function(element) {
|
|
122
|
+
}, visible = function(element, visualOnly = false, ignoreOwnOpacity = false) {
|
|
51
123
|
if (element.closest(
|
|
52
|
-
"[hidden],[inert],[aria-hidden='true'],dialog:not([open])"
|
|
124
|
+
visualOnly ? "[hidden],[inert],dialog:not([open])" : "[hidden],[inert],[aria-hidden='true'],dialog:not([open])"
|
|
53
125
|
))
|
|
54
126
|
return false;
|
|
55
127
|
const dialog = element.closest("dialog,[role='dialog']");
|
|
@@ -58,9 +130,13 @@ var SedumPageScript = (() => {
|
|
|
58
130
|
if (bounds.right <= 0 || bounds.bottom <= 0 || bounds.left >= innerWidth || bounds.top >= innerHeight)
|
|
59
131
|
return false;
|
|
60
132
|
}
|
|
61
|
-
for (let node = element; node; node = node
|
|
133
|
+
for (let node = element; node; node = composedParent(node)) {
|
|
134
|
+
if (node.getRootNode() !== element.getRootNode() && node.matches(
|
|
135
|
+
visualOnly ? "[hidden],[inert]" : "[hidden],[inert],[aria-hidden='true']"
|
|
136
|
+
))
|
|
137
|
+
return false;
|
|
62
138
|
const style2 = getComputedStyle(node);
|
|
63
|
-
if (Number.parseFloat(style2.opacity) === 0 || style2.contentVisibility === "hidden")
|
|
139
|
+
if (Number.parseFloat(style2.opacity) === 0 && !(ignoreOwnOpacity && node === element) || style2.contentVisibility === "hidden")
|
|
64
140
|
return false;
|
|
65
141
|
}
|
|
66
142
|
const style = getComputedStyle(element);
|
|
@@ -80,7 +156,7 @@ var SedumPageScript = (() => {
|
|
|
80
156
|
document.querySelectorAll(
|
|
81
157
|
"dialog:modal,[role='dialog'][aria-modal='true']"
|
|
82
158
|
)
|
|
83
|
-
).filter(visible);
|
|
159
|
+
).filter((element) => visible(element));
|
|
84
160
|
if (!dialogs.length) return null;
|
|
85
161
|
const native = dialogs.filter(
|
|
86
162
|
(element) => element.matches("dialog:modal")
|
|
@@ -103,31 +179,385 @@ var SedumPageScript = (() => {
|
|
|
103
179
|
return true;
|
|
104
180
|
}
|
|
105
181
|
return false;
|
|
106
|
-
}, publicText = function(element) {
|
|
182
|
+
}, publicText = function(element, visualOnly = false) {
|
|
183
|
+
const parts = [];
|
|
184
|
+
for (const node of flatTextNodes(element)) {
|
|
185
|
+
const parent = node.parentElement;
|
|
186
|
+
if (parent && visible(parent, visualOnly) && !excludedTextAncestor(parent))
|
|
187
|
+
parts.push(node.textContent ?? "");
|
|
188
|
+
}
|
|
189
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
190
|
+
}, referencedLabelText = function(element) {
|
|
107
191
|
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
|
108
192
|
const parts = [];
|
|
109
193
|
while (walker.nextNode()) {
|
|
110
194
|
const parent = walker.currentNode.parentElement;
|
|
111
|
-
if (parent
|
|
112
|
-
|
|
195
|
+
if (parent?.closest(
|
|
196
|
+
"script,style,noscript,input,textarea,select,[contenteditable]"
|
|
197
|
+
))
|
|
198
|
+
continue;
|
|
199
|
+
parts.push(walker.currentNode.textContent ?? "");
|
|
113
200
|
}
|
|
114
201
|
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
115
|
-
}, label = function(element) {
|
|
116
|
-
const aria = element.getAttribute("aria-label");
|
|
117
|
-
if (aria) return aria
|
|
202
|
+
}, label = function(element, visualOnly = false) {
|
|
203
|
+
const aria = element.getAttribute("aria-label")?.trim();
|
|
204
|
+
if (aria) return aria;
|
|
118
205
|
const labelledby = element.getAttribute("aria-labelledby");
|
|
119
|
-
if (labelledby)
|
|
120
|
-
|
|
206
|
+
if (labelledby) {
|
|
207
|
+
const text = labelledby.split(/\s+/).map((id) => {
|
|
121
208
|
const named = document.getElementById(id);
|
|
122
|
-
return named ?
|
|
209
|
+
return named ? referencedLabelText(named) : "";
|
|
123
210
|
}).filter(Boolean).join(" ");
|
|
211
|
+
if (text) return text;
|
|
212
|
+
}
|
|
124
213
|
if (element instanceof HTMLElement && "labels" in element) {
|
|
125
214
|
const labels = element.labels;
|
|
126
|
-
|
|
215
|
+
const text = labels?.length ? Array.from(labels).map((node) => publicText(node)).join(" ").trim() : "";
|
|
216
|
+
if (text) return text;
|
|
217
|
+
}
|
|
218
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
|
|
219
|
+
const placeholder = element.getAttribute("placeholder")?.trim();
|
|
220
|
+
if (placeholder) return placeholder;
|
|
221
|
+
}
|
|
222
|
+
if (element instanceof HTMLInputElement && ["button", "submit", "reset"].includes(element.type)) {
|
|
223
|
+
const value = element.value.trim();
|
|
224
|
+
if (value) return value;
|
|
127
225
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
226
|
+
return publicText(element, visualOnly) || element.getAttribute("title")?.trim() || "";
|
|
227
|
+
}, nearbyText = function(element) {
|
|
228
|
+
const box = element.getBoundingClientRect();
|
|
229
|
+
if (!box.width || !box.height) return "";
|
|
230
|
+
const middle = box.top + box.height / 2;
|
|
231
|
+
let best = null;
|
|
232
|
+
let scope = composedParent(element);
|
|
233
|
+
for (let level = 0; scope && level < 3 && !best; level++) {
|
|
234
|
+
for (const node of flatTextNodes(scope)) {
|
|
235
|
+
const parent = node.parentElement;
|
|
236
|
+
const text = (node.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
237
|
+
if (!parent || !text || deepContains(element, parent) || excludedTextAncestor(parent, true) || // Text that already labels another control is that control's name.
|
|
238
|
+
parent.closest("label")?.control || !visible(parent))
|
|
239
|
+
continue;
|
|
240
|
+
const range = document.createRange();
|
|
241
|
+
range.selectNodeContents(node);
|
|
242
|
+
const rect = range.getBoundingClientRect();
|
|
243
|
+
if (!rect.width || !rect.height) continue;
|
|
244
|
+
const sameLine = Math.abs(rect.top + rect.height / 2 - middle) < Math.max(box.height, rect.height) / 2;
|
|
245
|
+
const overlapsColumn = rect.left < box.right && rect.right > box.left;
|
|
246
|
+
let distance = Infinity;
|
|
247
|
+
if (sameLine && rect.left >= box.right - 2)
|
|
248
|
+
distance = rect.left - box.right;
|
|
249
|
+
else if (sameLine && rect.right <= box.left + 2)
|
|
250
|
+
distance = box.left - rect.right;
|
|
251
|
+
else if (overlapsColumn && rect.bottom <= box.top + 2)
|
|
252
|
+
distance = box.top - rect.bottom;
|
|
253
|
+
if (distance > 48) continue;
|
|
254
|
+
if (!best || distance < best.distance) best = { text, distance };
|
|
255
|
+
}
|
|
256
|
+
scope = scope && composedParent(scope);
|
|
257
|
+
}
|
|
258
|
+
return best?.text ?? "";
|
|
259
|
+
}, mediaName = function(element) {
|
|
260
|
+
for (const node of Array.from(
|
|
261
|
+
element.querySelectorAll(
|
|
262
|
+
"img[alt],svg[aria-label],svg title,[aria-label]"
|
|
263
|
+
)
|
|
264
|
+
)) {
|
|
265
|
+
const drawn = node.matches("svg title") ? node.closest("svg") : node;
|
|
266
|
+
if (interactive(node) || !visible(drawn, true)) continue;
|
|
267
|
+
const text = (node instanceof HTMLImageElement ? node.alt : node.matches("svg title") ? node.textContent ?? "" : node.getAttribute("aria-label") ?? "").replace(/\s+/g, " ").trim();
|
|
268
|
+
if (text) return text;
|
|
269
|
+
}
|
|
270
|
+
return "";
|
|
271
|
+
}, hostLabel = function(element) {
|
|
272
|
+
const root = element.getRootNode();
|
|
273
|
+
if (!(root instanceof ShadowRoot)) return "";
|
|
274
|
+
const host = root.host;
|
|
275
|
+
const aria = host.getAttribute("aria-label")?.trim();
|
|
276
|
+
if (!aria || interactive(host)) return "";
|
|
277
|
+
const inside = allElements(host, 500) ?? [];
|
|
278
|
+
return inside.filter((node) => interactive(node)).length === 1 ? aria : "";
|
|
279
|
+
}, iconName = function(element) {
|
|
280
|
+
for (const node of Array.from(element.querySelectorAll("i,span,em"))) {
|
|
281
|
+
if (node.textContent?.trim()) continue;
|
|
282
|
+
for (const token of Array.from(node.classList)) {
|
|
283
|
+
const match = /^(?:fa|bi|glyphicon|icon|mdi|ti|ri)-([a-z][a-z0-9-]*)$/.exec(token);
|
|
284
|
+
if (match && !/^(lg|[0-9]x|fw|solid|regular|light|brands|spin|pulse|border|inverse|stack.*|rotate.*|flip.*)$/.test(
|
|
285
|
+
match[1]
|
|
286
|
+
))
|
|
287
|
+
return match[1].replace(/-/g, " ");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return "";
|
|
291
|
+
}, describedText = function(element) {
|
|
292
|
+
const ids = element.getAttribute("aria-describedby");
|
|
293
|
+
if (!ids || role(element) !== "combobox") return "";
|
|
294
|
+
return ids.split(/\s+/).map((id) => {
|
|
295
|
+
const node = document.getElementById(id);
|
|
296
|
+
return node && visible(node) ? publicText(node) : "";
|
|
297
|
+
}).filter(Boolean).join(" ").slice(0, 80);
|
|
298
|
+
}, rowLabel = function(element) {
|
|
299
|
+
if (!element.matches(
|
|
300
|
+
"input,textarea,select,[role='combobox'],[role='textbox']"
|
|
301
|
+
))
|
|
302
|
+
return "";
|
|
303
|
+
const box = element.getBoundingClientRect();
|
|
304
|
+
if (!box.width || !box.height) return "";
|
|
305
|
+
let row = null;
|
|
306
|
+
let node = composedParent(element);
|
|
307
|
+
for (let level = 0; node && node !== document.body && level < 7; level++) {
|
|
308
|
+
const inside = allElements(node, 400);
|
|
309
|
+
if (!inside || inside.some(
|
|
310
|
+
(other) => other !== element && interactive(other) && visible(other)
|
|
311
|
+
))
|
|
312
|
+
break;
|
|
313
|
+
row = node;
|
|
314
|
+
node = composedParent(node);
|
|
315
|
+
}
|
|
316
|
+
if (!row) return "";
|
|
317
|
+
const middle = box.top + box.height / 2;
|
|
318
|
+
let best = null;
|
|
319
|
+
for (const text of flatTextNodes(row)) {
|
|
320
|
+
const parent = text.parentElement;
|
|
321
|
+
const value = (text.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
322
|
+
if (!parent || !value || deepContains(element, parent) || excludedTextAncestor(parent, true) || !visible(parent))
|
|
323
|
+
continue;
|
|
324
|
+
const range = document.createRange();
|
|
325
|
+
range.selectNodeContents(text);
|
|
326
|
+
const rect = range.getBoundingClientRect();
|
|
327
|
+
if (!rect.width || !rect.height) continue;
|
|
328
|
+
const sameLine = Math.abs(rect.top + rect.height / 2 - middle) < Math.max(box.height, rect.height) / 2;
|
|
329
|
+
let distance = Infinity;
|
|
330
|
+
if (sameLine && rect.right <= box.left + 2)
|
|
331
|
+
distance = box.left - rect.right;
|
|
332
|
+
else if (rect.bottom <= box.top + 2 && rect.left < box.right)
|
|
333
|
+
distance = box.top - rect.bottom;
|
|
334
|
+
if (distance > 400) continue;
|
|
335
|
+
if (!best || distance < best.distance) best = { text: value, distance };
|
|
336
|
+
}
|
|
337
|
+
return best?.text ?? "";
|
|
338
|
+
}, candidateName = function(element) {
|
|
339
|
+
const visualOnly = ariaHiddenOnly(element);
|
|
340
|
+
return label(element, visualOnly) || mediaName(element) || nearbyText(element) || hostLabel(element) || iconName(element) || describedText(element) || rowLabel(element);
|
|
341
|
+
}, hintWords = function(text) {
|
|
342
|
+
return text.toLocaleLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
343
|
+
}, addsWords = function(text, name) {
|
|
344
|
+
const own = new Set(hintWords(name));
|
|
345
|
+
return hintWords(text).some(
|
|
346
|
+
(word) => word.length > 1 && /\p{L}/u.test(word) && !own.has(word)
|
|
347
|
+
);
|
|
348
|
+
}, siteRootLink = function(element) {
|
|
349
|
+
const href = element.getAttribute("href")?.trim();
|
|
350
|
+
if (!href) return false;
|
|
351
|
+
if (/^(?:\/|\.\/|\/index\.html?|\/home(?:page)?\/?)$/i.test(href))
|
|
352
|
+
return true;
|
|
353
|
+
try {
|
|
354
|
+
const url = new URL(href, location.href);
|
|
355
|
+
if (url.pathname !== "/" || url.search) return false;
|
|
356
|
+
if (url.host === location.host) return true;
|
|
357
|
+
const canonical = document.querySelector("link[rel='canonical']")?.getAttribute("href") ?? document.querySelector("meta[property='og:url']")?.getAttribute("content");
|
|
358
|
+
return !!canonical && new URL(canonical, location.href).host === url.host;
|
|
359
|
+
} catch {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
}, nameHint = function(element, name) {
|
|
363
|
+
const parts = [];
|
|
364
|
+
const clip = (text, limit = 48) => text.length > limit ? text.slice(0, limit - 1) + "\u2026" : text;
|
|
365
|
+
const addPart = (text, payload = text) => {
|
|
366
|
+
if (payload && addsWords(payload, [name, ...parts].join(" ")))
|
|
367
|
+
parts.push(text);
|
|
368
|
+
};
|
|
369
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
|
|
370
|
+
const placeholder = element.getAttribute("placeholder")?.trim() ?? "";
|
|
371
|
+
if (placeholder && placeholder !== name)
|
|
372
|
+
addPart(`placeholder "${clip(placeholder)}"`, placeholder);
|
|
373
|
+
}
|
|
374
|
+
const named = element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby");
|
|
375
|
+
const shown = publicText(element, true);
|
|
376
|
+
if (named && shown) addPart(`shows "${clip(shown)}"`, shown);
|
|
377
|
+
if (!/\p{L}/u.test(name)) {
|
|
378
|
+
const hidden = referencedLabelText(element);
|
|
379
|
+
if (/\p{L}/u.test(hidden)) addPart(`text "${clip(hidden)}"`, hidden);
|
|
380
|
+
}
|
|
381
|
+
const inside = Array.from(
|
|
382
|
+
element.querySelectorAll("img,svg,i,span:empty,div:empty,use,kbd")
|
|
383
|
+
).slice(0, 12);
|
|
384
|
+
const media = inside.filter((node) => node.matches("img,svg"));
|
|
385
|
+
const raw = [element, ...inside].flatMap((node) => [
|
|
386
|
+
node.getAttribute("class") ?? "",
|
|
387
|
+
node.id,
|
|
388
|
+
node.getAttribute("data-icon") ?? "",
|
|
389
|
+
node === element ? "" : node.getAttribute("title") ?? "",
|
|
390
|
+
node.matches("use") ? node.getAttribute("href") ?? "" : "",
|
|
391
|
+
node.matches("use") ? node.getAttribute("xlink:href") ?? "" : "",
|
|
392
|
+
node instanceof HTMLImageElement ? node.alt : "",
|
|
393
|
+
node === element ? "" : node.getAttribute("aria-label") ?? ""
|
|
394
|
+
]);
|
|
395
|
+
const tokens = raw.join(" ").toLocaleLowerCase().split(/\s+/).map((token) => token.replace(/[_:#/.]+/g, "-")).filter(Boolean);
|
|
396
|
+
const isLink = element.matches("a[href]") || role(element) === "link";
|
|
397
|
+
const rootLink = isLink && siteRootLink(element);
|
|
398
|
+
const kbdText = Array.from(element.querySelectorAll("kbd")).map((node) => publicText(node, true)).join(" ").replace(/\s+/g, " ").trim();
|
|
399
|
+
const iconOnly = !/\p{L}/u.test(shown) || !!kbdText && kbdText === shown;
|
|
400
|
+
if (media.length && (rootLink || tokens.some((token) => /logo|brand/.test(token)))) {
|
|
401
|
+
const mediaLabel = media.map(
|
|
402
|
+
(node) => node instanceof HTMLImageElement ? node.alt : node.getAttribute("aria-label") ?? node.querySelector("title")?.textContent ?? ""
|
|
403
|
+
).map((text) => text.replace(/\s+/g, " ").trim()).find(Boolean);
|
|
404
|
+
if (mediaLabel) addPart(`${clip(mediaLabel, 32)} logo`, mediaLabel);
|
|
405
|
+
if (!hintWords([name, ...parts].join(" ")).includes("logo"))
|
|
406
|
+
parts.push("logo");
|
|
407
|
+
if (rootLink && !/\bhome/i.test(name)) addPart("home link");
|
|
408
|
+
} else if (iconOnly && (inside.length || !/\p{L}/u.test(name))) {
|
|
409
|
+
const kind = ICON_KINDS.find(
|
|
410
|
+
([pattern]) => tokens.some((token) => pattern.test(token))
|
|
411
|
+
);
|
|
412
|
+
if (kind) addPart(`${kind[1]} icon`, kind[1]);
|
|
413
|
+
}
|
|
414
|
+
if (kbdText && kbdText === shown) addPart("keyboard shortcut");
|
|
415
|
+
return parts.join(", ");
|
|
416
|
+
}, clippedAway = function(element) {
|
|
417
|
+
const box = element.getBoundingClientRect();
|
|
418
|
+
const x = box.left + box.width / 2;
|
|
419
|
+
const y = box.top + box.height / 2;
|
|
420
|
+
for (let node = composedParent(element); node && node !== document.body; node = composedParent(node)) {
|
|
421
|
+
const style = getComputedStyle(node);
|
|
422
|
+
if (style.overflowX === "visible" && style.overflowY === "visible")
|
|
423
|
+
continue;
|
|
424
|
+
const bounds = node.getBoundingClientRect();
|
|
425
|
+
if (x < bounds.left || x > bounds.right || y < bounds.top || y > bounds.bottom)
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
return false;
|
|
429
|
+
}, ariaHiddenOnly = function(element) {
|
|
430
|
+
if (!interactive(element) || visible(element) || !visible(element, true))
|
|
431
|
+
return false;
|
|
432
|
+
const box = element.getBoundingClientRect();
|
|
433
|
+
return box.width >= 8 && box.height >= 8 && !clippedAway(element) && !!publicText(element, true);
|
|
434
|
+
}, isToggle = function(element) {
|
|
435
|
+
return element instanceof HTMLInputElement && (element.type === "checkbox" || element.type === "radio");
|
|
436
|
+
}, transparentToggle = function(element) {
|
|
437
|
+
if (!isToggle(element) || visible(element)) return false;
|
|
438
|
+
const box = element.getBoundingClientRect();
|
|
439
|
+
return box.width >= 8 && box.height >= 8 && visible(element, false, true);
|
|
440
|
+
}, toggleLabel = function(element) {
|
|
441
|
+
if (!(element instanceof HTMLLabelElement)) return null;
|
|
442
|
+
const control = element.control;
|
|
443
|
+
if (!control || !isToggle(control) || visible(control) || transparentToggle(control) || control.labels?.[0] !== element)
|
|
444
|
+
return null;
|
|
445
|
+
return control;
|
|
446
|
+
}, pointerTarget = function(element) {
|
|
447
|
+
if (interactive(element) || element.matches("html,body,label,svg *") || getComputedStyle(element).cursor !== "pointer")
|
|
448
|
+
return false;
|
|
449
|
+
const parent = composedParent(element);
|
|
450
|
+
if (parent && getComputedStyle(parent).cursor === "pointer") return false;
|
|
451
|
+
for (let node = parent; node; node = composedParent(node))
|
|
452
|
+
if (interactive(node)) return false;
|
|
453
|
+
const inside = allElements(element, 500);
|
|
454
|
+
return !!inside && !inside.some((node) => interactive(node) || node.hasAttribute("role"));
|
|
455
|
+
}, landmarkOf = function(node) {
|
|
456
|
+
const tag = node.tagName.toLowerCase();
|
|
457
|
+
const explicit = node.getAttribute("role");
|
|
458
|
+
if (tag === "dialog" || explicit === "dialog" || explicit === "alertdialog")
|
|
459
|
+
return "dialog";
|
|
460
|
+
if (explicit === "banner" || tag === "header" && !node.parentElement?.closest(SECTIONING))
|
|
461
|
+
return "header";
|
|
462
|
+
if (explicit === "contentinfo" || tag === "footer" && !node.parentElement?.closest(SECTIONING))
|
|
463
|
+
return "footer";
|
|
464
|
+
if (tag === "nav" || explicit === "navigation") return "navigation";
|
|
465
|
+
if (tag === "aside" || explicit === "complementary") return "sidebar";
|
|
466
|
+
if (tag === "main" || explicit === "main") return "main";
|
|
467
|
+
const hint = `${node.id} ${typeof node.className === "string" ? node.className : ""}`.toLowerCase();
|
|
468
|
+
if (/(^|[\s_-])(site-?header|masthead|top-?bar|navbar|header)($|[\s_-])/.test(
|
|
469
|
+
hint
|
|
470
|
+
))
|
|
471
|
+
return "header";
|
|
472
|
+
if (/(^|[\s_-])(site-?footer|footer)($|[\s_-])/.test(hint)) return "footer";
|
|
473
|
+
if (/(^|[\s_-])(sidebar|side-?nav|toc|table-of-contents)($|[\s_-])/.test(hint))
|
|
474
|
+
return "sidebar";
|
|
475
|
+
return "";
|
|
476
|
+
}, landmarkRoot = function(element) {
|
|
477
|
+
let root = null;
|
|
478
|
+
for (let node = composedParent(element); node && node !== document.body; node = composedParent(node))
|
|
479
|
+
if (landmarkOf(node)) root = node;
|
|
480
|
+
return root;
|
|
481
|
+
}, locationOf = function(element, heading) {
|
|
482
|
+
const marks = [];
|
|
483
|
+
let root = null;
|
|
484
|
+
for (let node = composedParent(element); node && node !== document.body; node = composedParent(node)) {
|
|
485
|
+
const mark = landmarkOf(node);
|
|
486
|
+
if (!mark) continue;
|
|
487
|
+
root = node;
|
|
488
|
+
if (!marks.includes(mark)) marks.unshift(mark);
|
|
489
|
+
}
|
|
490
|
+
const kept = marks.length > 2 ? [marks[0], marks[marks.length - 1]] : marks;
|
|
491
|
+
const parts = [
|
|
492
|
+
kept.join(", "),
|
|
493
|
+
heading.root === root ? heading.text : ""
|
|
494
|
+
].filter(Boolean);
|
|
495
|
+
return Array.from(parts.join(" \xB7 ")).slice(0, PEER_LIMIT).join("");
|
|
496
|
+
}, shortText = function(element) {
|
|
497
|
+
if ((element.textContent ?? "").length > 400) return "";
|
|
498
|
+
const text = publicText(element);
|
|
499
|
+
return Array.from(text).length <= SECTION_TITLE_LIMIT ? text : "";
|
|
500
|
+
}, containerTitle = function(container) {
|
|
501
|
+
if (titleCache.has(container)) return titleCache.get(container);
|
|
502
|
+
let found = null;
|
|
503
|
+
for (const child of Array.from(container.children)) {
|
|
504
|
+
if (!(child.textContent ?? "").trim() || !visible(child)) continue;
|
|
505
|
+
const controls = child.querySelectorAll(
|
|
506
|
+
"button,a[href],input,select,textarea,[role='button'],[role='link']"
|
|
507
|
+
).length;
|
|
508
|
+
if (!child.matches("li,tr,option,[role='listitem'],[role='row']") && (interactive(child) ? controls === 0 : controls <= 1)) {
|
|
509
|
+
const heading = child.matches("h1,h2,h3,h4,h5,h6,[role='heading']") ? child : child.querySelector("h1,h2,h3,h4,h5,h6,[role='heading']");
|
|
510
|
+
const text = shortText(heading ?? child);
|
|
511
|
+
if (text && text.split(/\s+/).length <= 8 && !/^skip to\b/i.test(text))
|
|
512
|
+
found = { child, text };
|
|
513
|
+
}
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
titleCache.set(container, found);
|
|
517
|
+
return found;
|
|
518
|
+
}, sectionOf = function(element, outline) {
|
|
519
|
+
const labels = [];
|
|
520
|
+
const add = (text) => {
|
|
521
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
522
|
+
if (clean && Array.from(clean).length <= SECTION_TITLE_LIMIT && !labels.includes(clean))
|
|
523
|
+
labels.push(clean);
|
|
524
|
+
};
|
|
525
|
+
let child = element;
|
|
526
|
+
let depth = 0;
|
|
527
|
+
for (let node = composedParent(element); node && node !== document.body && depth < 30 && labels.length < 6; child = node, node = composedParent(node), depth++) {
|
|
528
|
+
if (!interactive(node)) {
|
|
529
|
+
const aria = node.getAttribute("aria-label");
|
|
530
|
+
if (aria) add(aria);
|
|
531
|
+
const labelledby = node.getAttribute("aria-labelledby");
|
|
532
|
+
if (labelledby)
|
|
533
|
+
add(
|
|
534
|
+
labelledby.split(/\s+/).map((id) => {
|
|
535
|
+
const target = document.getElementById(id);
|
|
536
|
+
return target && target !== element ? publicText(target) : "";
|
|
537
|
+
}).join(" ")
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
const own = (selector) => {
|
|
541
|
+
const title2 = Array.from(node.children).find(
|
|
542
|
+
(item) => item.matches(selector)
|
|
543
|
+
);
|
|
544
|
+
return title2 && title2 !== child ? shortText(title2) : "";
|
|
545
|
+
};
|
|
546
|
+
if (node.matches("fieldset")) add(own("legend"));
|
|
547
|
+
if (node.matches("table")) add(own("caption"));
|
|
548
|
+
if (node.matches("figure")) add(own("figcaption"));
|
|
549
|
+
if (node.matches("details")) add(own("summary"));
|
|
550
|
+
const title = containerTitle(node);
|
|
551
|
+
if (title && title.child !== child && !title.child.contains(element))
|
|
552
|
+
add(title.text);
|
|
553
|
+
}
|
|
554
|
+
const root = landmarkRoot(element);
|
|
555
|
+
for (let index = outline.length - 1; index >= 0; index--)
|
|
556
|
+
if (outline[index].root === root) add(outline[index].text);
|
|
557
|
+
return Array.from(labels.slice(0, 6).join(" \u203A ")).slice(0, 300).join("");
|
|
558
|
+
}, boundedName = function(name) {
|
|
559
|
+
const points = Array.from(name);
|
|
560
|
+
return points.length <= NAME_LIMIT ? name : points.slice(0, NAME_LIMIT - 1).join("") + "\u2026";
|
|
131
561
|
}, role = function(element) {
|
|
132
562
|
const explicit = element.getAttribute("role");
|
|
133
563
|
const canonical = explicit?.split(/\s+/).find(isSafeRole);
|
|
@@ -135,14 +565,15 @@ var SedumPageScript = (() => {
|
|
|
135
565
|
if (element instanceof HTMLButtonElement) return "button";
|
|
136
566
|
if (element instanceof HTMLAnchorElement) return "link";
|
|
137
567
|
if (element instanceof HTMLInputElement)
|
|
138
|
-
return ["button", "submit", "reset"].includes(element.type) ? "button" : element.type === "checkbox" ? "checkbox" : element.type === "radio" ? "radio" : element.type === "range" ? "slider" : element.type === "number" ? "spinbutton" : element.type === "search" ? "searchbox" : "textbox";
|
|
568
|
+
return ["button", "submit", "reset"].includes(element.type) ? "button" : element.type === "checkbox" ? "checkbox" : element.type === "radio" ? "radio" : element.type === "range" ? "slider" : element.type === "number" ? "spinbutton" : element.type === "search" ? "searchbox" : element.type === "file" ? "button" : "textbox";
|
|
139
569
|
if (element instanceof HTMLTextAreaElement) return "textbox";
|
|
570
|
+
if (element.matches("details > summary")) return "button";
|
|
140
571
|
if (element instanceof HTMLSelectElement) return "combobox";
|
|
141
572
|
return "";
|
|
142
573
|
}, interactive = function(element) {
|
|
143
574
|
if (element.parentElement?.closest("a[href]")) return false;
|
|
144
575
|
return element.matches(
|
|
145
|
-
"button,a[href],input,textarea,select,[contenteditable]"
|
|
576
|
+
"button,a[href],input,textarea,select,[contenteditable],details > summary"
|
|
146
577
|
) || [
|
|
147
578
|
"button",
|
|
148
579
|
"link",
|
|
@@ -204,18 +635,21 @@ var SedumPageScript = (() => {
|
|
|
204
635
|
const rank = preceding?.querySelector(".rank");
|
|
205
636
|
const title = preceding?.querySelector(".titleline > a");
|
|
206
637
|
const rankedPeer = rank && title ? Array.from(`${publicText(rank)} ${publicText(title)}`.trim()).slice(0, PEER_LIMIT).join("") : "";
|
|
207
|
-
let region = element
|
|
638
|
+
let region = composedParent(element);
|
|
208
639
|
let lastUnique = null;
|
|
209
640
|
while (region && region !== document.body) {
|
|
210
|
-
const
|
|
211
|
-
|
|
641
|
+
const scope = allElements(region, 2e3);
|
|
642
|
+
const possible = (scope ?? []).filter(
|
|
643
|
+
(item2) => item2.matches(
|
|
644
|
+
"button,a[href],[role='button'],input[type='button'],input[type='submit']"
|
|
645
|
+
)
|
|
212
646
|
);
|
|
213
|
-
if (possible.length > 32) {
|
|
647
|
+
if (!scope || possible.length > 32) {
|
|
214
648
|
region = lastUnique;
|
|
215
649
|
break;
|
|
216
650
|
}
|
|
217
651
|
const sameLabel = Array.from(possible).filter(
|
|
218
|
-
(
|
|
652
|
+
(item2) => visible(item2) && label(item2) === name
|
|
219
653
|
);
|
|
220
654
|
if (sameLabel.length > 1) {
|
|
221
655
|
region = lastUnique;
|
|
@@ -223,13 +657,16 @@ var SedumPageScript = (() => {
|
|
|
223
657
|
}
|
|
224
658
|
lastUnique = region;
|
|
225
659
|
if (region.matches("article,li,[data-product],[role='listitem']")) break;
|
|
226
|
-
region = region
|
|
660
|
+
region = composedParent(region);
|
|
227
661
|
}
|
|
228
662
|
region = region === document.body ? lastUnique : region;
|
|
229
663
|
if (!region)
|
|
230
664
|
return { texts: rankedPeer ? [rankedPeer] : [], contextComplete: false };
|
|
231
665
|
const result = [];
|
|
232
666
|
if (rankedPeer) result.push(rankedPeer);
|
|
667
|
+
const item = Array.from(
|
|
668
|
+
`${rankedPeer} ${publicText(region)}`.replace(/\s+/g, " ").trim()
|
|
669
|
+
).slice(0, 300).join("");
|
|
233
670
|
const context = itemContext(region);
|
|
234
671
|
if (context.text && result.length < 2) result.push(context.text);
|
|
235
672
|
const named = Array.from(
|
|
@@ -254,7 +691,10 @@ var SedumPageScript = (() => {
|
|
|
254
691
|
}
|
|
255
692
|
return {
|
|
256
693
|
texts: result,
|
|
257
|
-
contextComplete: !rankedPeer && context.complete && !!context.text
|
|
694
|
+
contextComplete: !rankedPeer && context.complete && !!context.text,
|
|
695
|
+
// An item holding nothing but controls, such as the action bar of a
|
|
696
|
+
// comment with nested replies, is only part of the real item.
|
|
697
|
+
...item && (context.text || rankedPeer) ? { item } : {}
|
|
258
698
|
};
|
|
259
699
|
}, scan = function(operation) {
|
|
260
700
|
clearRefs();
|
|
@@ -265,29 +705,61 @@ var SedumPageScript = (() => {
|
|
|
265
705
|
return { candidates, refs, complete: false };
|
|
266
706
|
const root = selectedModal ?? document.body;
|
|
267
707
|
if (!root) return { candidates, refs, complete: true };
|
|
268
|
-
const elements = root
|
|
269
|
-
if (elements
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
708
|
+
const elements = allElements(root, MAX_ELEMENTS) ?? allElements(root, MAX_ELEMENTS, true);
|
|
709
|
+
if (!elements) return { candidates, refs, complete: false };
|
|
710
|
+
let heading = {
|
|
711
|
+
text: "",
|
|
712
|
+
root: null
|
|
713
|
+
};
|
|
714
|
+
const outline = [];
|
|
715
|
+
titleCache.clear();
|
|
716
|
+
for (const element of elements) {
|
|
717
|
+
if (element.matches("h1,h2,h3,h4,h5,h6,[role='heading']")) {
|
|
718
|
+
const text = visible(element) ? publicText(element) : "";
|
|
719
|
+
if (text && Array.from(text).length <= 60) {
|
|
720
|
+
heading = { text, root: landmarkRoot(element) };
|
|
721
|
+
const level = Number(
|
|
722
|
+
/^h([1-6])$/i.exec(element.tagName)?.[1] ?? element.getAttribute("aria-level")
|
|
723
|
+
) || 2;
|
|
724
|
+
while (outline.length && outline[outline.length - 1].level >= level)
|
|
725
|
+
outline.pop();
|
|
726
|
+
outline.push({ ...heading, level });
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
const proxied = operation === "click" ? toggleLabel(element) : null;
|
|
730
|
+
if (!(visible(element) || transparentToggle(element) || operation === "click" && ariaHiddenOnly(element)) || (operation === "read" ? !readable(element) : !interactive(element) && !proxied && (operation !== "click" || !pointerTarget(element))))
|
|
273
731
|
continue;
|
|
274
732
|
if (operation === "fill" && !editable(element)) continue;
|
|
275
|
-
if (operation === "click" && editable(element) && !element.matches("input[type='checkbox'],input[type='radio']"))
|
|
733
|
+
if (operation === "click" && editable(element) && !element.matches("input[type='checkbox'],input[type='radio']") && role(element) !== "combobox" && !element.readOnly)
|
|
276
734
|
continue;
|
|
277
|
-
const
|
|
278
|
-
if (!
|
|
735
|
+
const rawName = operation === "read" ? label(element) : candidateName(element);
|
|
736
|
+
if (!rawName) continue;
|
|
737
|
+
const name = boundedName(rawName);
|
|
279
738
|
const ref = `${documentId}-${++sequence}`;
|
|
739
|
+
let nodeId = nodeIds.get(element);
|
|
740
|
+
if (!nodeId) {
|
|
741
|
+
nodeId = `${documentId}-node-${++nodeSequence}`;
|
|
742
|
+
nodeIds.set(element, nodeId);
|
|
743
|
+
}
|
|
280
744
|
const peerData = peers(element, name);
|
|
281
|
-
|
|
745
|
+
const location2 = locationOf(element, heading);
|
|
746
|
+
const section = sectionOf(element, outline);
|
|
747
|
+
const hint = operation === "read" ? "" : nameHint(element, rawName);
|
|
748
|
+
owned.set(element, {
|
|
749
|
+
old: element.getAttribute("data-sedum-ref"),
|
|
750
|
+
ref,
|
|
751
|
+
rawName
|
|
752
|
+
});
|
|
282
753
|
element.setAttribute("data-sedum-ref", ref);
|
|
283
754
|
refs.set(ref, element);
|
|
284
755
|
candidates.push(
|
|
285
756
|
Object.freeze({
|
|
286
757
|
ref,
|
|
287
758
|
tag: element.tagName.toLowerCase(),
|
|
288
|
-
role: role(element),
|
|
759
|
+
role: proxied ? role(proxied) : role(element),
|
|
289
760
|
name,
|
|
290
761
|
peers: Object.freeze(peerData.texts),
|
|
762
|
+
...location2 ? { location: location2 } : {},
|
|
291
763
|
editable: editable(element),
|
|
292
764
|
disabled: disabled(element),
|
|
293
765
|
inputType: element instanceof HTMLInputElement ? element.type : "",
|
|
@@ -297,8 +769,13 @@ var SedumPageScript = (() => {
|
|
|
297
769
|
...element.getAttribute("name") ? { name: element.getAttribute("name") } : {},
|
|
298
770
|
...element.getAttribute("href") ? { href: element.getAttribute("href") } : {},
|
|
299
771
|
...inArticleBody(element) ? { region: "article-body" } : {},
|
|
772
|
+
...rawName !== name ? { nameTruncated: true, rawName } : {},
|
|
773
|
+
nodeId,
|
|
300
774
|
path: path(element),
|
|
301
|
-
contextComplete: peerData.contextComplete
|
|
775
|
+
contextComplete: peerData.contextComplete,
|
|
776
|
+
...peerData.item ? { item: peerData.item } : {},
|
|
777
|
+
...section ? { section } : {},
|
|
778
|
+
...hint ? { nameHint: hint } : {}
|
|
302
779
|
})
|
|
303
780
|
})
|
|
304
781
|
);
|
|
@@ -307,7 +784,7 @@ var SedumPageScript = (() => {
|
|
|
307
784
|
}, collect = function(input) {
|
|
308
785
|
const current = version();
|
|
309
786
|
const offset = input.offset ?? 0;
|
|
310
|
-
if (offset > 0 && (!snapshot || snapshot.operation !== input.operation || !input.version || !same(snapshot.version, input.version)
|
|
787
|
+
if (offset > 0 && (!snapshot || snapshot.operation !== input.operation || !input.version || !same(snapshot.version, input.version)))
|
|
311
788
|
return {
|
|
312
789
|
protocol: PAGE_PROTOCOL,
|
|
313
790
|
version: current,
|
|
@@ -346,6 +823,28 @@ var SedumPageScript = (() => {
|
|
|
346
823
|
complete: true,
|
|
347
824
|
candidates
|
|
348
825
|
};
|
|
826
|
+
}, selectOnly = function(control) {
|
|
827
|
+
if (control instanceof HTMLSelectElement) return true;
|
|
828
|
+
if (control.getAttribute("role") !== "combobox" || control.matches("input,textarea") || control instanceof HTMLElement && control.isContentEditable || control.querySelector(
|
|
829
|
+
"input,textarea,[contenteditable]:not([contenteditable='false']),[role='textbox'],[role='searchbox'],[role='spinbutton']"
|
|
830
|
+
) || control.parentElement && excludedTextAncestor(control.parentElement))
|
|
831
|
+
return false;
|
|
832
|
+
const autocomplete = control.getAttribute("aria-autocomplete");
|
|
833
|
+
return autocomplete === null || autocomplete.toLowerCase() === "none";
|
|
834
|
+
}, selectedText = function(control) {
|
|
835
|
+
if (control instanceof HTMLSelectElement)
|
|
836
|
+
return (control.selectedOptions[0]?.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
837
|
+
const walker = document.createTreeWalker(control, NodeFilter.SHOW_TEXT);
|
|
838
|
+
const parts = [];
|
|
839
|
+
while (walker.nextNode()) {
|
|
840
|
+
const parent = walker.currentNode.parentElement;
|
|
841
|
+
if (!parent || !visible(parent, true) || parent.closest(
|
|
842
|
+
"input,textarea,select,[contenteditable],script,style,noscript,[role='textbox'],[role='searchbox'],[role='spinbutton'],[role='listbox'],[role='option']"
|
|
843
|
+
))
|
|
844
|
+
continue;
|
|
845
|
+
parts.push(walker.currentNode.textContent ?? "");
|
|
846
|
+
}
|
|
847
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
349
848
|
}, digest = function() {
|
|
350
849
|
const current = version();
|
|
351
850
|
const selectedModal = modal();
|
|
@@ -367,6 +866,7 @@ var SedumPageScript = (() => {
|
|
|
367
866
|
};
|
|
368
867
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
369
868
|
const pieces = [];
|
|
869
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
370
870
|
let size = 0;
|
|
371
871
|
let count = 0;
|
|
372
872
|
while (walker.nextNode()) {
|
|
@@ -380,6 +880,26 @@ var SedumPageScript = (() => {
|
|
|
380
880
|
};
|
|
381
881
|
const node = walker.currentNode;
|
|
382
882
|
const parent = node.parentElement;
|
|
883
|
+
const control = parent?.closest("select,[role='combobox']");
|
|
884
|
+
if (control && (emitted.has(control) || selectOnly(control))) {
|
|
885
|
+
if (emitted.has(control) || !visible(control)) continue;
|
|
886
|
+
emitted.add(control);
|
|
887
|
+
const selection = selectedText(control);
|
|
888
|
+
const name = selection ? label(control).replace(selection, "").replace(/^[\s.,:;–-]+|[\s.,:;–-]+$/g, "") : "";
|
|
889
|
+
const part2 = !selection ? "" : name ? `${name}: ${selection}` : selection;
|
|
890
|
+
if (!part2) continue;
|
|
891
|
+
size += Array.from(part2).length + (pieces.length ? 1 : 0);
|
|
892
|
+
if (size > DIGEST_LIMIT)
|
|
893
|
+
return {
|
|
894
|
+
protocol: PAGE_PROTOCOL,
|
|
895
|
+
version: current,
|
|
896
|
+
text: "",
|
|
897
|
+
complete: false,
|
|
898
|
+
error: "digest_too_large"
|
|
899
|
+
};
|
|
900
|
+
pieces.push(part2);
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
383
903
|
if (!parent || !visible(parent) || excludedTextAncestor(parent)) continue;
|
|
384
904
|
const part = (node.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
385
905
|
if (!part) continue;
|
|
@@ -411,14 +931,12 @@ var SedumPageScript = (() => {
|
|
|
411
931
|
return null;
|
|
412
932
|
const element = refElement(target.ref);
|
|
413
933
|
if (!element || element.tagName.toLowerCase() !== target.tag) return null;
|
|
414
|
-
const matches =
|
|
415
|
-
document.querySelectorAll("[data-sedum-ref]")
|
|
416
|
-
).filter((node) => node.getAttribute("data-sedum-ref") === target.ref);
|
|
934
|
+
const matches = (allElements(document.documentElement, Infinity) ?? []).filter((node) => node.getAttribute("data-sedum-ref") === target.ref);
|
|
417
935
|
if (matches.length !== 1 || matches[0] !== element) return null;
|
|
418
936
|
const candidate = snapshot.candidates.find(
|
|
419
937
|
(item) => item.ref === target.ref
|
|
420
938
|
);
|
|
421
|
-
if (!candidate || !candidate.editable || !(element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLElement && element.isContentEditable) || candidate.name !== target.name ||
|
|
939
|
+
if (!candidate || !candidate.editable || !(element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLElement && element.isContentEditable) || candidate.name !== target.name || candidateName(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers) || !editable(element) || !visible(element) || disabled(element))
|
|
422
940
|
return null;
|
|
423
941
|
return element;
|
|
424
942
|
}, readTarget = function(target) {
|
|
@@ -429,7 +947,7 @@ var SedumPageScript = (() => {
|
|
|
429
947
|
const candidate = snapshot.candidates.find(
|
|
430
948
|
(item) => item.ref === target.ref
|
|
431
949
|
);
|
|
432
|
-
if (!element || !candidate || element.tagName.toLowerCase() !== target.tag || candidate.name !== target.name || !readable(element) || !visible(element) || label(element) !==
|
|
950
|
+
if (!element || !candidate || element.tagName.toLowerCase() !== target.tag || candidate.name !== target.name || !readable(element) || !visible(element) || label(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers))
|
|
433
951
|
return { status: "stale" };
|
|
434
952
|
const text = publicText(element);
|
|
435
953
|
if (!text) return { status: "empty" };
|
|
@@ -446,9 +964,9 @@ var SedumPageScript = (() => {
|
|
|
446
964
|
if (expected && element.tagName.toLowerCase() !== expected.tag)
|
|
447
965
|
return { actionable: false, reason: "stale" };
|
|
448
966
|
const candidate = snapshot?.candidates.find((item) => item.ref === ref);
|
|
449
|
-
if (!candidate ||
|
|
967
|
+
if (!candidate || candidateName(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers) || expected && expected.name !== candidate.name)
|
|
450
968
|
return { actionable: false, reason: "stale" };
|
|
451
|
-
if (!visible(element) || disabled(element))
|
|
969
|
+
if (!(visible(element) || transparentToggle(element) || ariaHiddenOnly(element)) || disabled(element))
|
|
452
970
|
return { actionable: false, reason: "not_actionable" };
|
|
453
971
|
const enclosingLink = element.closest("a[href]");
|
|
454
972
|
if (enclosingLink) {
|
|
@@ -457,57 +975,65 @@ var SedumPageScript = (() => {
|
|
|
457
975
|
if (enclosingLink instanceof HTMLAnchorElement && (enclosingLink.hasAttribute("download") || !["", "_self"].includes(enclosingLink.target) || !["http:", "https:"].includes(new URL(enclosingLink.href).protocol)))
|
|
458
976
|
return { actionable: false, reason: "not_actionable" };
|
|
459
977
|
}
|
|
460
|
-
|
|
461
|
-
element.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
[
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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)
|
|
978
|
+
const hitTest = () => {
|
|
979
|
+
const rect = element.getBoundingClientRect();
|
|
980
|
+
if (!rect.width || !rect.height) return null;
|
|
981
|
+
const points = expected ? [[expected.point.x / rect.width, expected.point.y / rect.height]] : [
|
|
982
|
+
[0.5, 0.5],
|
|
983
|
+
[0.25, 0.5],
|
|
984
|
+
[0.75, 0.5],
|
|
985
|
+
[0.5, 0.25],
|
|
986
|
+
[0.5, 0.75]
|
|
987
|
+
];
|
|
988
|
+
for (const [fx, fy] of points) {
|
|
989
|
+
const x = rect.left + rect.width * fx;
|
|
990
|
+
const y = rect.top + rect.height * fy;
|
|
991
|
+
if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) continue;
|
|
992
|
+
const hit = deepElementFromPoint(x, y);
|
|
993
|
+
if (hit && deepContains(element, hit)) {
|
|
994
|
+
return {
|
|
995
|
+
actionable: true,
|
|
996
|
+
aim: {
|
|
997
|
+
ref,
|
|
998
|
+
document: current.document,
|
|
999
|
+
route: current.route,
|
|
1000
|
+
revision: current.revision,
|
|
1001
|
+
tag: element.tagName.toLowerCase(),
|
|
1002
|
+
name: candidate.name,
|
|
1003
|
+
point: { x: rect.width * fx, y: rect.height * fy },
|
|
1004
|
+
box: {
|
|
1005
|
+
x: Math.max(0, rect.left / innerWidth),
|
|
1006
|
+
y: Math.max(0, rect.top / innerHeight),
|
|
1007
|
+
width: Math.min(1, rect.width / innerWidth),
|
|
1008
|
+
height: Math.min(1, rect.height / innerHeight)
|
|
1009
|
+
}
|
|
497
1010
|
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
500
1013
|
}
|
|
501
|
-
|
|
502
|
-
|
|
1014
|
+
return null;
|
|
1015
|
+
};
|
|
1016
|
+
const inPlace = hitTest();
|
|
1017
|
+
if (inPlace) return inPlace;
|
|
1018
|
+
if (expected) return { actionable: false, reason: "not_actionable" };
|
|
1019
|
+
element.scrollIntoView({
|
|
1020
|
+
block: "center",
|
|
1021
|
+
inline: "center",
|
|
1022
|
+
behavior: "instant"
|
|
1023
|
+
});
|
|
1024
|
+
if (!same(version(), current) || refElement(ref) !== element)
|
|
1025
|
+
return { actionable: false, reason: "stale" };
|
|
1026
|
+
return hitTest() ?? { actionable: false, reason: "not_actionable" };
|
|
503
1027
|
};
|
|
504
|
-
version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, label2 = label, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, digest2 = digest, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, aim2 = aim;
|
|
1028
|
+
observe2 = observe, composedParent2 = composedParent, allElements2 = allElements, flatTextNodes2 = flatTextNodes, deepElementFromPoint2 = deepElementFromPoint, deepContains2 = deepContains, version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, referencedLabelText2 = referencedLabelText, label2 = label, nearbyText2 = nearbyText, mediaName2 = mediaName, hostLabel2 = hostLabel, iconName2 = iconName, describedText2 = describedText, rowLabel2 = rowLabel, candidateName2 = candidateName, hintWords2 = hintWords, addsWords2 = addsWords, siteRootLink2 = siteRootLink, nameHint2 = nameHint, clippedAway2 = clippedAway, ariaHiddenOnly2 = ariaHiddenOnly, isToggle2 = isToggle, transparentToggle2 = transparentToggle, toggleLabel2 = toggleLabel, pointerTarget2 = pointerTarget, landmarkOf2 = landmarkOf, landmarkRoot2 = landmarkRoot, locationOf2 = locationOf, shortText2 = shortText, containerTitle2 = containerTitle, sectionOf2 = sectionOf, boundedName2 = boundedName, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, selectOnly2 = selectOnly, selectedText2 = selectedText, digest2 = digest, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, aim2 = aim;
|
|
505
1029
|
const documentId = Array.from(crypto.getRandomValues(new Uint32Array(4))).map((part) => part.toString(16)).join("-");
|
|
506
1030
|
let revision = 0;
|
|
507
1031
|
let route = location.href;
|
|
508
1032
|
let sequence = 0;
|
|
509
1033
|
let snapshot;
|
|
510
1034
|
const owned = /* @__PURE__ */ new Map();
|
|
1035
|
+
const nodeIds = /* @__PURE__ */ new WeakMap();
|
|
1036
|
+
let nodeSequence = 0;
|
|
511
1037
|
const MAX_ELEMENTS = 2e4;
|
|
512
1038
|
const MAX_TEXT_NODES = 2e4;
|
|
513
1039
|
const FILLABLE_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -539,13 +1065,36 @@ var SedumPageScript = (() => {
|
|
|
539
1065
|
))
|
|
540
1066
|
revision++;
|
|
541
1067
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
1068
|
+
const observed = /* @__PURE__ */ new WeakSet();
|
|
1069
|
+
observe(document);
|
|
1070
|
+
const ICON_KINDS = [
|
|
1071
|
+
[/(?:^|-)(?:up-?vote|vote-?up|votearrow)(?:$|-)/, "upvote arrow"],
|
|
1072
|
+
[/(?:^|-)(?:down-?vote|vote-?down)(?:$|-)/, "downvote arrow"],
|
|
1073
|
+
[/(?:^|-)(?:search|magnifier|magnifying|loupe)(?:$|-)/, "search"],
|
|
1074
|
+
[/(?:^|-)(?:hamburger|burger|menu|bars)(?:$|-)/, "menu"],
|
|
1075
|
+
[/(?:^|-)(?:close|dismiss|xmark|x-mark|times)(?:$|-)/, "close"],
|
|
1076
|
+
[
|
|
1077
|
+
/(?:^|-)(?:(?:arrow|chevron|caret|angle|paddlenav)-?(?:right|next|forward)|(?:right|next|forward)-?(?:arrow|chevron|caret))(?:$|-)/,
|
|
1078
|
+
"right arrow"
|
|
1079
|
+
],
|
|
1080
|
+
[
|
|
1081
|
+
/(?:^|-)(?:(?:arrow|chevron|caret|angle|paddlenav)-?(?:left|prev|previous|back)|(?:left|prev|previous|back)-?(?:arrow|chevron|caret))(?:$|-)/,
|
|
1082
|
+
"left arrow"
|
|
1083
|
+
],
|
|
1084
|
+
[/(?:^|-)(?:terminal|shell|console|prompt)(?:$|-)/, "terminal"],
|
|
1085
|
+
[/(?:^|-)(?:cart|basket)(?:$|-)/, "cart"],
|
|
1086
|
+
[/(?:^|-)(?:kebab|ellipsis|more|dots)(?:$|-)/, "more"],
|
|
1087
|
+
[/(?:^|-)(?:settings|gear|cog)(?:$|-)/, "settings"],
|
|
1088
|
+
[/(?:^|-)share(?:$|-)/, "share"],
|
|
1089
|
+
[/(?:^|-)(?:copy|clipboard)(?:$|-)/, "copy"],
|
|
1090
|
+
[/(?:^|-)(?:bell|notifications?)(?:$|-)/, "notifications"],
|
|
1091
|
+
[/(?:^|-)(?:avatar|account|profile|user)(?:$|-)/, "account"],
|
|
1092
|
+
[/(?:^|-)play(?:$|-)/, "play"],
|
|
1093
|
+
[/(?:^|-)pause(?:$|-)/, "pause"]
|
|
1094
|
+
];
|
|
1095
|
+
const SECTIONING = "article,aside,main,nav,section";
|
|
1096
|
+
const SECTION_TITLE_LIMIT = 60;
|
|
1097
|
+
const titleCache = /* @__PURE__ */ new Map();
|
|
549
1098
|
const bridge = {
|
|
550
1099
|
protocol: PAGE_PROTOCOL,
|
|
551
1100
|
collect,
|
|
@@ -584,6 +1133,12 @@ var SedumPageScript = (() => {
|
|
|
584
1133
|
writable: false
|
|
585
1134
|
});
|
|
586
1135
|
}
|
|
1136
|
+
var observe2;
|
|
1137
|
+
var composedParent2;
|
|
1138
|
+
var allElements2;
|
|
1139
|
+
var flatTextNodes2;
|
|
1140
|
+
var deepElementFromPoint2;
|
|
1141
|
+
var deepContains2;
|
|
587
1142
|
var version2;
|
|
588
1143
|
var same2;
|
|
589
1144
|
var clearRefs2;
|
|
@@ -591,7 +1146,32 @@ var SedumPageScript = (() => {
|
|
|
591
1146
|
var modal2;
|
|
592
1147
|
var excludedTextAncestor2;
|
|
593
1148
|
var publicText2;
|
|
1149
|
+
var referencedLabelText2;
|
|
594
1150
|
var label2;
|
|
1151
|
+
var nearbyText2;
|
|
1152
|
+
var mediaName2;
|
|
1153
|
+
var hostLabel2;
|
|
1154
|
+
var iconName2;
|
|
1155
|
+
var describedText2;
|
|
1156
|
+
var rowLabel2;
|
|
1157
|
+
var candidateName2;
|
|
1158
|
+
var hintWords2;
|
|
1159
|
+
var addsWords2;
|
|
1160
|
+
var siteRootLink2;
|
|
1161
|
+
var nameHint2;
|
|
1162
|
+
var clippedAway2;
|
|
1163
|
+
var ariaHiddenOnly2;
|
|
1164
|
+
var isToggle2;
|
|
1165
|
+
var transparentToggle2;
|
|
1166
|
+
var toggleLabel2;
|
|
1167
|
+
var pointerTarget2;
|
|
1168
|
+
var landmarkOf2;
|
|
1169
|
+
var landmarkRoot2;
|
|
1170
|
+
var locationOf2;
|
|
1171
|
+
var shortText2;
|
|
1172
|
+
var containerTitle2;
|
|
1173
|
+
var sectionOf2;
|
|
1174
|
+
var boundedName2;
|
|
595
1175
|
var role2;
|
|
596
1176
|
var interactive2;
|
|
597
1177
|
var readable2;
|
|
@@ -603,6 +1183,8 @@ var SedumPageScript = (() => {
|
|
|
603
1183
|
var peers2;
|
|
604
1184
|
var scan2;
|
|
605
1185
|
var collect2;
|
|
1186
|
+
var selectOnly2;
|
|
1187
|
+
var selectedText2;
|
|
606
1188
|
var digest2;
|
|
607
1189
|
var refElement2;
|
|
608
1190
|
var fillElement2;
|