@burdenoff/ui-engine 2026.1127.3 → 2026.1127.4
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 +45 -5
- package/dist/dom-runtime.iife.js +1 -1
- package/dist/dom-runtime.js +27 -532
- package/dist/drivers/dom-driver.d.ts +44 -0
- package/dist/drivers/index.d.ts +7 -0
- package/dist/drivers/snapshot-driver.d.ts +59 -0
- package/dist/drivers.d.ts +2 -0
- package/dist/drivers.js +170 -0
- package/dist/index-3f1j8386.js +334 -0
- package/dist/index-3jymbm5t.js +315 -0
- package/dist/{index-q1b0j9yr.js → index-5k26keah.js} +58 -592
- package/dist/index-77pcz6n3.js +303 -0
- package/dist/index-895kscx3.js +741 -0
- package/dist/index-ct2xctrq.js +229 -0
- package/dist/index-h88y5qgv.js +400 -0
- package/dist/{index-zwrxw3zp.js → index-pm13mvvc.js} +24 -1009
- package/dist/index-vg8r40y7.js +220 -0
- package/dist/index-ycs2bz1a.js +589 -0
- package/dist/index-zzhysbkj.js +1731 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +123 -37
- package/dist/interpret/compile.d.ts +58 -0
- package/dist/interpret/driver.d.ts +171 -0
- package/dist/interpret/errors.d.ts +194 -0
- package/dist/interpret/events.d.ts +73 -0
- package/dist/interpret/expr.d.ts +35 -0
- package/dist/interpret/index.d.ts +13 -0
- package/dist/interpret/run.d.ts +77 -0
- package/dist/interpret.d.ts +2 -0
- package/dist/interpret.js +84 -0
- package/dist/script/adapters/browser-action-contract.d.ts +5 -2
- package/dist/script/limits.d.ts +2 -0
- package/dist/script.js +44 -38
- package/dist/target/index.d.ts +1 -1
- package/dist/target/resolve.d.ts +18 -1
- package/dist/target.js +23 -19
- package/dist/testing/fake-web-driver.d.ts +28 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing.js +55 -0
- package/package.json +11 -3
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
// src/target/markers.ts
|
|
2
|
+
var SENSITIVE_MARKERS2 = ["data-fg-sensitive", "data-sensitive", "data-private"];
|
|
3
|
+
function hasSensitiveMarker2(element) {
|
|
4
|
+
return SENSITIVE_MARKERS2.some((marker) => element.hasAttribute(marker));
|
|
5
|
+
}
|
|
6
|
+
function assignedSlotOf(element) {
|
|
7
|
+
const native = element.assignedSlot;
|
|
8
|
+
if (native !== undefined)
|
|
9
|
+
return native;
|
|
10
|
+
const shadow = element.parentElement?.shadowRoot;
|
|
11
|
+
if (!shadow)
|
|
12
|
+
return null;
|
|
13
|
+
for (const slot of Array.from(shadow.querySelectorAll("slot"))) {
|
|
14
|
+
const assigned = typeof slot.assignedNodes === "function" ? slot.assignedNodes() : [];
|
|
15
|
+
if (assigned.includes(element))
|
|
16
|
+
return slot;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function containerOf(element) {
|
|
21
|
+
const slot = assignedSlotOf(element);
|
|
22
|
+
if (slot)
|
|
23
|
+
return slot;
|
|
24
|
+
if (element.parentElement)
|
|
25
|
+
return element.parentElement;
|
|
26
|
+
const root = element.getRootNode();
|
|
27
|
+
if (root && "host" in root)
|
|
28
|
+
return root.host;
|
|
29
|
+
try {
|
|
30
|
+
return element.ownerDocument.defaultView?.frameElement ?? null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isMarkedSensitive(element) {
|
|
36
|
+
for (let current = element;current; current = containerOf(current)) {
|
|
37
|
+
if (hasSensitiveMarker2(current))
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/target/text.ts
|
|
44
|
+
var MAX_COMPARED_TEXT2 = 256;
|
|
45
|
+
function normaliseText2(value) {
|
|
46
|
+
return (value ?? "").normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
function sameText2(a, b) {
|
|
49
|
+
return normaliseText2(a) === normaliseText2(b);
|
|
50
|
+
}
|
|
51
|
+
function containsText2(haystack, needle) {
|
|
52
|
+
const wanted = normaliseText2(needle);
|
|
53
|
+
return wanted.length > 0 && normaliseText2(haystack).includes(wanted);
|
|
54
|
+
}
|
|
55
|
+
function editDistance2(a, b) {
|
|
56
|
+
if (a === b)
|
|
57
|
+
return 0;
|
|
58
|
+
if (a.length === 0)
|
|
59
|
+
return b.length;
|
|
60
|
+
if (b.length === 0)
|
|
61
|
+
return a.length;
|
|
62
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
63
|
+
for (let i = 1;i <= a.length; i += 1) {
|
|
64
|
+
const current = [i];
|
|
65
|
+
for (let j = 1;j <= b.length; j += 1) {
|
|
66
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
67
|
+
current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost);
|
|
68
|
+
}
|
|
69
|
+
previous = current;
|
|
70
|
+
}
|
|
71
|
+
return previous[b.length] ?? 0;
|
|
72
|
+
}
|
|
73
|
+
function textSimilarity2(a, b) {
|
|
74
|
+
const left = normaliseText2(a).slice(0, MAX_COMPARED_TEXT2);
|
|
75
|
+
const right = normaliseText2(b).slice(0, MAX_COMPARED_TEXT2);
|
|
76
|
+
const longest = Math.max(left.length, right.length);
|
|
77
|
+
if (longest === 0)
|
|
78
|
+
return 0;
|
|
79
|
+
return 1 - editDistance2(left, right) / longest;
|
|
80
|
+
}
|
|
81
|
+
function clip2(value, max) {
|
|
82
|
+
return value.length <= max ? value : `${value.slice(0, Math.max(0, max - 1))}…`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/target/aria.ts
|
|
86
|
+
var MAX_NAME_LENGTH3 = 512;
|
|
87
|
+
var MAX_VISIBLE_TEXT2 = 65536;
|
|
88
|
+
var INPUT_ROLES = {
|
|
89
|
+
button: "button",
|
|
90
|
+
submit: "button",
|
|
91
|
+
reset: "button",
|
|
92
|
+
image: "button",
|
|
93
|
+
checkbox: "checkbox",
|
|
94
|
+
radio: "radio",
|
|
95
|
+
range: "slider",
|
|
96
|
+
number: "spinbutton",
|
|
97
|
+
search: "searchbox",
|
|
98
|
+
email: "textbox",
|
|
99
|
+
tel: "textbox",
|
|
100
|
+
text: "textbox",
|
|
101
|
+
url: "textbox",
|
|
102
|
+
password: "textbox",
|
|
103
|
+
date: "textbox",
|
|
104
|
+
"datetime-local": "textbox",
|
|
105
|
+
month: "textbox",
|
|
106
|
+
time: "textbox",
|
|
107
|
+
week: "textbox",
|
|
108
|
+
color: "textbox",
|
|
109
|
+
file: "button"
|
|
110
|
+
};
|
|
111
|
+
var TAG_ROLES = {
|
|
112
|
+
article: "article",
|
|
113
|
+
aside: "complementary",
|
|
114
|
+
button: "button",
|
|
115
|
+
datalist: "listbox",
|
|
116
|
+
dd: "definition",
|
|
117
|
+
details: "group",
|
|
118
|
+
dialog: "dialog",
|
|
119
|
+
dt: "term",
|
|
120
|
+
fieldset: "group",
|
|
121
|
+
figure: "figure",
|
|
122
|
+
h1: "heading",
|
|
123
|
+
h2: "heading",
|
|
124
|
+
h3: "heading",
|
|
125
|
+
h4: "heading",
|
|
126
|
+
h5: "heading",
|
|
127
|
+
h6: "heading",
|
|
128
|
+
hr: "separator",
|
|
129
|
+
li: "listitem",
|
|
130
|
+
main: "main",
|
|
131
|
+
menu: "list",
|
|
132
|
+
meter: "meter",
|
|
133
|
+
nav: "navigation",
|
|
134
|
+
ol: "list",
|
|
135
|
+
optgroup: "group",
|
|
136
|
+
option: "option",
|
|
137
|
+
output: "status",
|
|
138
|
+
p: "paragraph",
|
|
139
|
+
progress: "progressbar",
|
|
140
|
+
summary: "button",
|
|
141
|
+
table: "table",
|
|
142
|
+
tbody: "rowgroup",
|
|
143
|
+
td: "cell",
|
|
144
|
+
textarea: "textbox",
|
|
145
|
+
tfoot: "rowgroup",
|
|
146
|
+
thead: "rowgroup",
|
|
147
|
+
tr: "row",
|
|
148
|
+
ul: "list"
|
|
149
|
+
};
|
|
150
|
+
var NAME_FROM_CONTENT = new Set([
|
|
151
|
+
"button",
|
|
152
|
+
"cell",
|
|
153
|
+
"checkbox",
|
|
154
|
+
"columnheader",
|
|
155
|
+
"gridcell",
|
|
156
|
+
"heading",
|
|
157
|
+
"link",
|
|
158
|
+
"menuitem",
|
|
159
|
+
"menuitemcheckbox",
|
|
160
|
+
"menuitemradio",
|
|
161
|
+
"option",
|
|
162
|
+
"radio",
|
|
163
|
+
"row",
|
|
164
|
+
"rowheader",
|
|
165
|
+
"switch",
|
|
166
|
+
"tab",
|
|
167
|
+
"tooltip",
|
|
168
|
+
"treeitem"
|
|
169
|
+
]);
|
|
170
|
+
var LABELABLE = new Set(["button", "input", "meter", "output", "progress", "select", "textarea"]);
|
|
171
|
+
var SKIPPED_CONTENT = new Set(["script", "style", "noscript", "template", "head", "title", "meta", "link"]);
|
|
172
|
+
function tagOf(element) {
|
|
173
|
+
return element.localName.toLowerCase();
|
|
174
|
+
}
|
|
175
|
+
function hasSectioningAncestor(element) {
|
|
176
|
+
return element.parentElement?.closest("article, aside, main, nav, section") != null;
|
|
177
|
+
}
|
|
178
|
+
function implicitRole(element) {
|
|
179
|
+
const tag = tagOf(element);
|
|
180
|
+
switch (tag) {
|
|
181
|
+
case "a":
|
|
182
|
+
case "area":
|
|
183
|
+
return element.hasAttribute("href") ? "link" : "";
|
|
184
|
+
case "input": {
|
|
185
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
186
|
+
if (type === "hidden")
|
|
187
|
+
return "";
|
|
188
|
+
if (element.hasAttribute("list") && ["text", "search", "email", "tel", "url"].includes(type))
|
|
189
|
+
return "combobox";
|
|
190
|
+
return INPUT_ROLES[type] ?? "textbox";
|
|
191
|
+
}
|
|
192
|
+
case "select": {
|
|
193
|
+
const size = Number(element.getAttribute("size") ?? "0");
|
|
194
|
+
return element.hasAttribute("multiple") || size > 1 ? "listbox" : "combobox";
|
|
195
|
+
}
|
|
196
|
+
case "img": {
|
|
197
|
+
const alt = element.getAttribute("alt");
|
|
198
|
+
return alt === "" ? "presentation" : "img";
|
|
199
|
+
}
|
|
200
|
+
case "th":
|
|
201
|
+
return element.getAttribute("scope") === "row" ? "rowheader" : "columnheader";
|
|
202
|
+
case "header":
|
|
203
|
+
return hasSectioningAncestor(element) ? "" : "banner";
|
|
204
|
+
case "footer":
|
|
205
|
+
return hasSectioningAncestor(element) ? "" : "contentinfo";
|
|
206
|
+
case "section":
|
|
207
|
+
case "form":
|
|
208
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? tag === "form" ? "form" : "region" : "";
|
|
209
|
+
default:
|
|
210
|
+
return TAG_ROLES[tag] ?? "";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function roleOf2(element) {
|
|
214
|
+
const explicit = element.getAttribute("role")?.trim().split(/\s+/)[0];
|
|
215
|
+
return explicit ? explicit.toLowerCase() : implicitRole(element);
|
|
216
|
+
}
|
|
217
|
+
function byId(element, id) {
|
|
218
|
+
const root = element.getRootNode();
|
|
219
|
+
return typeof root.getElementById === "function" ? root.getElementById(id) : null;
|
|
220
|
+
}
|
|
221
|
+
function isHiddenForName(element) {
|
|
222
|
+
return element.hasAttribute("hidden") || element.getAttribute("aria-hidden") === "true";
|
|
223
|
+
}
|
|
224
|
+
function cssHiding(element) {
|
|
225
|
+
const view = element.ownerDocument.defaultView;
|
|
226
|
+
if (!view)
|
|
227
|
+
return "none";
|
|
228
|
+
const style = view.getComputedStyle(element);
|
|
229
|
+
if (style.display === "none")
|
|
230
|
+
return "subtree";
|
|
231
|
+
return style.visibility === "hidden" || style.visibility === "collapse" ? "self" : "none";
|
|
232
|
+
}
|
|
233
|
+
function isEditingHost(element) {
|
|
234
|
+
const value = element.getAttribute("contenteditable");
|
|
235
|
+
if (value === null)
|
|
236
|
+
return false;
|
|
237
|
+
const normalised = value.trim().toLowerCase();
|
|
238
|
+
return normalised === "" || normalised === "true" || normalised === "plaintext-only";
|
|
239
|
+
}
|
|
240
|
+
function renderedChildren(element) {
|
|
241
|
+
if (element.shadowRoot)
|
|
242
|
+
return Array.from(element.shadowRoot.childNodes);
|
|
243
|
+
if (tagOf(element) === "slot") {
|
|
244
|
+
const slot = element;
|
|
245
|
+
const assigned = typeof slot.assignedNodes === "function" ? slot.assignedNodes({ flatten: true }) : [];
|
|
246
|
+
if (assigned.length > 0)
|
|
247
|
+
return assigned;
|
|
248
|
+
}
|
|
249
|
+
return Array.from(element.childNodes);
|
|
250
|
+
}
|
|
251
|
+
var BLOCK_TAGS = /^(div|p|li|tr|td|th|br|h[1-6]|section|article|header|footer)$/;
|
|
252
|
+
function push(sink, text) {
|
|
253
|
+
if (sink.remaining <= 0 || text.length === 0)
|
|
254
|
+
return;
|
|
255
|
+
const kept = text.slice(0, sink.remaining);
|
|
256
|
+
sink.parts.push(kept);
|
|
257
|
+
sink.remaining -= kept.length;
|
|
258
|
+
}
|
|
259
|
+
function collectText(node, depth, sink, probe, includeHidden, textHidden = false) {
|
|
260
|
+
if (depth > 32 || sink.remaining <= 0)
|
|
261
|
+
return;
|
|
262
|
+
if (node.nodeType === 3) {
|
|
263
|
+
if (!textHidden)
|
|
264
|
+
push(sink, node.textContent ?? "");
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (node.nodeType !== 1)
|
|
268
|
+
return;
|
|
269
|
+
const element = node;
|
|
270
|
+
const tag = tagOf(element);
|
|
271
|
+
if (SKIPPED_CONTENT.has(tag) || hasSensitiveMarker2(element))
|
|
272
|
+
return;
|
|
273
|
+
if (!includeHidden && isHiddenForName(element))
|
|
274
|
+
return;
|
|
275
|
+
let hidden = false;
|
|
276
|
+
if (depth > 0 && !includeHidden) {
|
|
277
|
+
const visible = probe?.isVisible?.(element);
|
|
278
|
+
if (visible === false)
|
|
279
|
+
hidden = true;
|
|
280
|
+
else if (visible === undefined) {
|
|
281
|
+
const hiding = cssHiding(element);
|
|
282
|
+
if (hiding === "subtree")
|
|
283
|
+
return;
|
|
284
|
+
hidden = hiding === "self";
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const label = element.getAttribute("aria-label")?.trim();
|
|
288
|
+
if (label && depth > 0 && !hidden) {
|
|
289
|
+
push(sink, ` ${label} `);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (tag === "img" || tag === "input" && element.getAttribute("type") === "image") {
|
|
293
|
+
if (!hidden)
|
|
294
|
+
push(sink, ` ${element.getAttribute("alt") ?? ""} `);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (tag === "input" || tag === "textarea" || tag === "select")
|
|
298
|
+
return;
|
|
299
|
+
if (depth > 0 && isEditingHost(element))
|
|
300
|
+
return;
|
|
301
|
+
const block = depth > 0 && BLOCK_TAGS.test(tag);
|
|
302
|
+
if (block)
|
|
303
|
+
push(sink, " ");
|
|
304
|
+
for (const child of renderedChildren(element))
|
|
305
|
+
collectText(child, depth + 1, sink, probe, includeHidden, hidden);
|
|
306
|
+
if (block)
|
|
307
|
+
push(sink, " ");
|
|
308
|
+
}
|
|
309
|
+
function isTypedContent2(element) {
|
|
310
|
+
const tag = tagOf(element);
|
|
311
|
+
if (tag === "textarea" || isEditingHost(element))
|
|
312
|
+
return true;
|
|
313
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
314
|
+
if (tagOf(current) === "textarea" || isEditingHost(current))
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
function isInsideFieldValue(element) {
|
|
320
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
321
|
+
const tag = tagOf(current);
|
|
322
|
+
if (tag === "textarea" || tag === "select" || isEditingHost(current))
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
function referencedText(label, probe, includeHidden = false) {
|
|
328
|
+
const tag = tagOf(label);
|
|
329
|
+
const isFieldValue = tag === "textarea" || tag === "select" || isEditingHost(label) || isInsideFieldValue(label);
|
|
330
|
+
if (isFieldValue || isMarkedSensitive(label))
|
|
331
|
+
return "";
|
|
332
|
+
const ownLabel = collapse(label.getAttribute("aria-label") ?? "");
|
|
333
|
+
return ownLabel || contentText(label, probe, MAX_NAME_LENGTH3, includeHidden);
|
|
334
|
+
}
|
|
335
|
+
function contentText(node, probe, max = MAX_NAME_LENGTH3, includeHidden = false) {
|
|
336
|
+
if (node.nodeType === 1 && isMarkedSensitive(node))
|
|
337
|
+
return "";
|
|
338
|
+
const sink = { parts: [], remaining: max * 2 + 64 };
|
|
339
|
+
collectText(node, 0, sink, probe, includeHidden);
|
|
340
|
+
return collapse(sink.parts.join(""), max);
|
|
341
|
+
}
|
|
342
|
+
function collapse(text, max = MAX_NAME_LENGTH3) {
|
|
343
|
+
return text.replace(/\s+/g, " ").trim().slice(0, max);
|
|
344
|
+
}
|
|
345
|
+
function labelsOf(element, probe) {
|
|
346
|
+
const parts = [];
|
|
347
|
+
const id = element.getAttribute("id");
|
|
348
|
+
if (id) {
|
|
349
|
+
const root = element.getRootNode();
|
|
350
|
+
for (const label of Array.from(root.querySelectorAll("label"))) {
|
|
351
|
+
if (label.getAttribute("for") === id)
|
|
352
|
+
parts.push(referencedText(label, probe, true));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const wrapping = element.closest("label");
|
|
356
|
+
if (wrapping && !wrapping.hasAttribute("for"))
|
|
357
|
+
parts.push(referencedText(wrapping, probe, true));
|
|
358
|
+
return collapse(parts.join(" "));
|
|
359
|
+
}
|
|
360
|
+
function firstChildText(element, tag, probe) {
|
|
361
|
+
const child = Array.from(element.children).find((candidate) => tagOf(candidate) === tag);
|
|
362
|
+
return child ? referencedText(child, probe) : "";
|
|
363
|
+
}
|
|
364
|
+
function accessibleName2(element, probe) {
|
|
365
|
+
return computeName(element, probe, true);
|
|
366
|
+
}
|
|
367
|
+
function labelName2(element, probe) {
|
|
368
|
+
return computeName(element, probe, false);
|
|
369
|
+
}
|
|
370
|
+
function svgTitle(svg, probe) {
|
|
371
|
+
const title = Array.from(svg.children).find((child) => tagOf(child) === "title");
|
|
372
|
+
if (!title || isMarkedSensitive(title) || isInsideFieldValue(title))
|
|
373
|
+
return "";
|
|
374
|
+
return collapse(Array.from(title.childNodes).map((child) => contentText(child, probe)).join(" "));
|
|
375
|
+
}
|
|
376
|
+
function computeName(element, probe, fromContent) {
|
|
377
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
378
|
+
if (labelledBy) {
|
|
379
|
+
const text = labelledBy.split(/\s+/).filter(Boolean).map((id) => byId(element, id)).filter((label) => label !== null).map((label) => referencedText(label, probe, true)).join(" ");
|
|
380
|
+
if (collapse(text))
|
|
381
|
+
return collapse(text);
|
|
382
|
+
}
|
|
383
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
384
|
+
if (ariaLabel && collapse(ariaLabel))
|
|
385
|
+
return collapse(ariaLabel);
|
|
386
|
+
const tag = tagOf(element);
|
|
387
|
+
if (LABELABLE.has(tag)) {
|
|
388
|
+
const labels = labelsOf(element, probe);
|
|
389
|
+
if (labels)
|
|
390
|
+
return labels;
|
|
391
|
+
}
|
|
392
|
+
if (tag === "input") {
|
|
393
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
394
|
+
if (type === "button" || type === "submit" || type === "reset") {
|
|
395
|
+
const value = element.getAttribute("value");
|
|
396
|
+
if (value !== null)
|
|
397
|
+
return collapse(value);
|
|
398
|
+
return type === "submit" ? "Submit" : type === "reset" ? "Reset" : "";
|
|
399
|
+
}
|
|
400
|
+
if (type === "image")
|
|
401
|
+
return collapse(element.getAttribute("alt") ?? "");
|
|
402
|
+
}
|
|
403
|
+
if (tag === "img" || tag === "area") {
|
|
404
|
+
const alt = element.getAttribute("alt");
|
|
405
|
+
if (alt)
|
|
406
|
+
return collapse(alt);
|
|
407
|
+
}
|
|
408
|
+
if (tag === "svg") {
|
|
409
|
+
const title = svgTitle(element, probe);
|
|
410
|
+
if (title)
|
|
411
|
+
return title;
|
|
412
|
+
}
|
|
413
|
+
if (tag === "fieldset") {
|
|
414
|
+
const legend = firstChildText(element, "legend", probe);
|
|
415
|
+
if (legend)
|
|
416
|
+
return legend;
|
|
417
|
+
}
|
|
418
|
+
if (tag === "table") {
|
|
419
|
+
const caption = firstChildText(element, "caption", probe);
|
|
420
|
+
if (caption)
|
|
421
|
+
return caption;
|
|
422
|
+
}
|
|
423
|
+
if (tag === "option") {
|
|
424
|
+
const label = collapse(element.getAttribute("label") ?? "");
|
|
425
|
+
if (label)
|
|
426
|
+
return label;
|
|
427
|
+
}
|
|
428
|
+
if (tag === "figure") {
|
|
429
|
+
const caption = firstChildText(element, "figcaption", probe);
|
|
430
|
+
if (caption)
|
|
431
|
+
return caption;
|
|
432
|
+
}
|
|
433
|
+
if (fromContent && NAME_FROM_CONTENT.has(roleOf2(element))) {
|
|
434
|
+
const text = contentText(element, probe);
|
|
435
|
+
if (text)
|
|
436
|
+
return text;
|
|
437
|
+
}
|
|
438
|
+
const title = element.getAttribute("title");
|
|
439
|
+
if (title && collapse(title))
|
|
440
|
+
return collapse(title);
|
|
441
|
+
const placeholder = element.getAttribute("placeholder");
|
|
442
|
+
if (placeholder && collapse(placeholder))
|
|
443
|
+
return collapse(placeholder);
|
|
444
|
+
return "";
|
|
445
|
+
}
|
|
446
|
+
function visibleText2(element, probe) {
|
|
447
|
+
const tag = tagOf(element);
|
|
448
|
+
if (tag === "input") {
|
|
449
|
+
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
450
|
+
return type === "button" || type === "submit" || type === "reset" ? accessibleName2(element, probe) : "";
|
|
451
|
+
}
|
|
452
|
+
return contentText(element, probe, MAX_VISIBLE_TEXT2);
|
|
453
|
+
}
|
|
454
|
+
function matchesRoleAndName2(element, role, name, probe) {
|
|
455
|
+
return roleOf2(element) === role.trim().toLowerCase() && normaliseText2(accessibleName2(element, probe)) === normaliseText2(name);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/target/dom.ts
|
|
459
|
+
function viewOf(element) {
|
|
460
|
+
return element.ownerDocument.defaultView;
|
|
461
|
+
}
|
|
462
|
+
function parentAcrossShadow2(element) {
|
|
463
|
+
const slot = assignedSlotOf(element);
|
|
464
|
+
if (slot)
|
|
465
|
+
return slot;
|
|
466
|
+
if (element.parentElement)
|
|
467
|
+
return element.parentElement;
|
|
468
|
+
const root = element.getRootNode();
|
|
469
|
+
return root && "host" in root ? root.host : null;
|
|
470
|
+
}
|
|
471
|
+
function isElementVisible2(element, probe) {
|
|
472
|
+
const override = probe?.isVisible?.(element);
|
|
473
|
+
if (override !== undefined)
|
|
474
|
+
return override;
|
|
475
|
+
if (!element.isConnected)
|
|
476
|
+
return false;
|
|
477
|
+
const view = viewOf(element);
|
|
478
|
+
let current = element;
|
|
479
|
+
while (current) {
|
|
480
|
+
if (current.hasAttribute("hidden"))
|
|
481
|
+
return false;
|
|
482
|
+
if (current.localName === "input" && current.getAttribute("type")?.toLowerCase() === "hidden")
|
|
483
|
+
return false;
|
|
484
|
+
if (view && view.getComputedStyle(current).display === "none")
|
|
485
|
+
return false;
|
|
486
|
+
current = parentAcrossShadow2(current);
|
|
487
|
+
}
|
|
488
|
+
if (view) {
|
|
489
|
+
const style = view.getComputedStyle(element);
|
|
490
|
+
if (style.visibility === "hidden" || style.visibility === "collapse")
|
|
491
|
+
return false;
|
|
492
|
+
if (style.display === "contents")
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
const check = element.checkVisibility;
|
|
496
|
+
return typeof check === "function" ? check.call(element) : true;
|
|
497
|
+
}
|
|
498
|
+
function isElementEnabled2(element) {
|
|
499
|
+
for (let current = element;current; current = containerOf(current)) {
|
|
500
|
+
if (current.getAttribute("aria-disabled") === "true" || current.hasAttribute("inert"))
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
if (!FORM_CONTROLS.has(element.localName)) {
|
|
504
|
+
const control = element.parentElement?.closest("button, select, option, optgroup, textarea");
|
|
505
|
+
return control ? isElementEnabled2(control) : true;
|
|
506
|
+
}
|
|
507
|
+
if (element.hasAttribute("disabled"))
|
|
508
|
+
return false;
|
|
509
|
+
const fieldset = element.parentElement?.closest("fieldset[disabled]");
|
|
510
|
+
if (fieldset) {
|
|
511
|
+
const legend = Array.from(fieldset.children).find((child) => child.localName === "legend");
|
|
512
|
+
if (!legend?.contains(element))
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
return !element.matches(":disabled");
|
|
517
|
+
} catch {
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
var FORM_CONTROLS = new Set(["button", "input", "select", "textarea", "optgroup", "option", "fieldset"]);
|
|
522
|
+
function elementRect2(element, probe, offset) {
|
|
523
|
+
const given = probe?.rectOf?.(element);
|
|
524
|
+
const box = given ?? element.getBoundingClientRect();
|
|
525
|
+
return {
|
|
526
|
+
x: Math.round(box.x + (offset?.x ?? 0)),
|
|
527
|
+
y: Math.round(box.y + (offset?.y ?? 0)),
|
|
528
|
+
width: Math.round(box.width),
|
|
529
|
+
height: Math.round(box.height)
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function elementsUnder2(root) {
|
|
533
|
+
const all = Array.from(root.querySelectorAll("*"));
|
|
534
|
+
return root.nodeType === 1 ? [root, ...all] : all;
|
|
535
|
+
}
|
|
536
|
+
var SECRET_FIELD = /password|passcode|passwd|\bpin\b|otp|one[\s-]?time|verification|security code|auth(?:entication)? code|\bcvv\b|\bcvc\b|card number|secret|token|recovery/i;
|
|
537
|
+
var SECRET_AUTOCOMPLETE = /password|one-time-code|^cc-/i;
|
|
538
|
+
function isSecretFieldName2(name) {
|
|
539
|
+
return SECRET_FIELD.test(name);
|
|
540
|
+
}
|
|
541
|
+
function isSensitiveElement2(element) {
|
|
542
|
+
if (isMarkedSensitive(element))
|
|
543
|
+
return true;
|
|
544
|
+
if (isSensitiveField(element))
|
|
545
|
+
return true;
|
|
546
|
+
for (let current = containerOf(element);current; current = containerOf(current)) {
|
|
547
|
+
if (isSensitiveField(current))
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
function isSensitiveField(element) {
|
|
553
|
+
const tag = element.localName;
|
|
554
|
+
const editable = element.getAttribute("contenteditable");
|
|
555
|
+
const isEditingHost = editable !== null && editable.trim().toLowerCase() !== "false";
|
|
556
|
+
if (tag !== "input" && tag !== "textarea" && tag !== "select" && !isEditingHost)
|
|
557
|
+
return false;
|
|
558
|
+
if (element.getAttribute("type")?.toLowerCase() === "password")
|
|
559
|
+
return true;
|
|
560
|
+
const tokens = (element.getAttribute("autocomplete") ?? "").trim().split(/\s+/).filter(Boolean);
|
|
561
|
+
if (tokens.some((token) => SECRET_AUTOCOMPLETE.test(token)))
|
|
562
|
+
return true;
|
|
563
|
+
return fieldHints(element).some((hint) => hint.length > 0 && isSecretFieldName2(hint.replace(/[-_]/g, " ")));
|
|
564
|
+
}
|
|
565
|
+
function fieldHints(element) {
|
|
566
|
+
const raw = (value) => (value ?? "").slice(0, 512);
|
|
567
|
+
const hints = [
|
|
568
|
+
accessibleName2(element),
|
|
569
|
+
raw(element.getAttribute("aria-label")),
|
|
570
|
+
raw(element.getAttribute("placeholder")),
|
|
571
|
+
raw(element.getAttribute("title")),
|
|
572
|
+
raw(element.getAttribute("name")),
|
|
573
|
+
raw(element.getAttribute("id"))
|
|
574
|
+
];
|
|
575
|
+
const root = element.getRootNode();
|
|
576
|
+
const byId = (id) => typeof root.getElementById === "function" ? root.getElementById(id) : null;
|
|
577
|
+
for (const id of (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).filter(Boolean)) {
|
|
578
|
+
const target = byId(id);
|
|
579
|
+
if (target)
|
|
580
|
+
hints.push(raw(target.getAttribute("aria-label")), raw(target.textContent));
|
|
581
|
+
}
|
|
582
|
+
const id = element.getAttribute("id");
|
|
583
|
+
const labels = Array.from(root.querySelectorAll("label")).filter((label) => id !== null && label.getAttribute("for") === id || !label.hasAttribute("for") && label.contains(element));
|
|
584
|
+
for (const label of labels)
|
|
585
|
+
hints.push(raw(label.getAttribute("aria-label")), raw(label.textContent));
|
|
586
|
+
return hints;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export { SENSITIVE_MARKERS2, hasSensitiveMarker2, assignedSlotOf, containerOf, isMarkedSensitive, MAX_COMPARED_TEXT2, normaliseText2, sameText2, containsText2, editDistance2, textSimilarity2, clip2, MAX_NAME_LENGTH3, MAX_VISIBLE_TEXT2, roleOf2, isTypedContent2, accessibleName2, labelName2, visibleText2, matchesRoleAndName2, parentAcrossShadow2, isElementVisible2, isElementEnabled2, elementRect2, elementsUnder2, isSecretFieldName2, isSensitiveElement2 };
|