spana-test 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +11 -8
- package/dist/agent-fixture-5C4MCWRD.js +20 -0
- package/dist/{allure-RAEK4SIH.js → allure-FGVR5LND.js} +5 -1
- package/dist/allure-FGVR5LND.js.map +1 -0
- package/dist/app-RSDPDTKT.js +10 -0
- package/dist/cache-command-PANUAEMZ.js +12 -0
- package/dist/{chunk-Y2RZNOKU.js → chunk-26NJXP55.js} +2 -2
- package/dist/{chunk-ALPQES3J.js → chunk-3IZMPNE7.js} +549 -2002
- package/dist/chunk-3IZMPNE7.js.map +1 -0
- package/dist/chunk-4KK4E3N3.js +3587 -0
- package/dist/chunk-4KK4E3N3.js.map +1 -0
- package/dist/{chunk-IGTK5MHB.js → chunk-4SA7JK5D.js} +23 -15
- package/dist/chunk-4SA7JK5D.js.map +1 -0
- package/dist/{chunk-PLE7RFQE.js → chunk-64UZQP7Z.js} +52 -3
- package/dist/chunk-64UZQP7Z.js.map +1 -0
- package/dist/chunk-6PTUVG6A.js +127 -0
- package/dist/chunk-6PTUVG6A.js.map +1 -0
- package/dist/chunk-FPQAJNE3.js +2874 -0
- package/dist/chunk-FPQAJNE3.js.map +1 -0
- package/dist/{chunk-3UVSUVHW.js → chunk-FXBWACUT.js} +530 -3360
- package/dist/chunk-FXBWACUT.js.map +1 -0
- package/dist/chunk-OPTNFLBL.js +556 -0
- package/dist/chunk-OPTNFLBL.js.map +1 -0
- package/dist/chunk-S7MSBZ3F.js +72 -0
- package/dist/chunk-S7MSBZ3F.js.map +1 -0
- package/dist/chunk-SGZMO456.js +2125 -0
- package/dist/chunk-SGZMO456.js.map +1 -0
- package/dist/{chunk-2KRVN4WN.js → chunk-SIJJVN2D.js} +358 -3
- package/dist/chunk-SIJJVN2D.js.map +1 -0
- package/dist/{chunk-SF7UYW4I.js → chunk-VUNH4AJD.js} +4 -4
- package/dist/{chunk-UEWZ2EXL.js → chunk-WS2TVNMY.js} +107 -1976
- package/dist/chunk-WS2TVNMY.js.map +1 -0
- package/dist/{chunk-FP6PVHHR.js → chunk-WZAQANN6.js} +2 -2
- package/dist/{chunk-JZZ2W2XH.js → chunk-XA6LWLZQ.js} +65 -3
- package/dist/chunk-XA6LWLZQ.js.map +1 -0
- package/dist/cli.js +195 -17
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-CNGIW2XK.js +9 -0
- package/dist/{console-BGAK7Z2L.js → console-DIYEJSSP.js} +9 -2
- package/dist/console-DIYEJSSP.js.map +1 -0
- package/dist/{discover-RLSKEBAX.js → discover-NKDMB4UI.js} +3 -3
- package/dist/{doctor-command-YTCQ2SC7.js → doctor-command-6ZVJWCW7.js} +5 -4
- package/dist/{doctor-command-YTCQ2SC7.js.map → doctor-command-6ZVJWCW7.js.map} +1 -1
- package/dist/{app-DSh1ejLh.d.ts → flow-DddAj1xv.d.ts} +1002 -355
- package/dist/gherkin/steps.d.ts +1 -2
- package/dist/{html-JO2YNRWX.js → html-FLMWPFQD.js} +2 -1
- package/dist/html-FLMWPFQD.js.map +1 -0
- package/dist/index.d.ts +498 -131
- package/dist/index.js +491 -278
- package/dist/index.js.map +1 -1
- package/dist/{junit-HLC62MK6.js → junit-CGB3LKHD.js} +3 -2
- package/dist/junit-CGB3LKHD.js.map +1 -0
- package/dist/local-DM3YBSV5.js +31 -0
- package/dist/{runner-TF4OKPYP.js → runner-WOVZWUQR.js} +6 -2
- package/dist/runner-WOVZWUQR.js.map +1 -0
- package/dist/{server-IS4K5FCT.js → server-ING5D5ZJ.js} +2 -2
- package/dist/server-ING5D5ZJ.js.map +1 -0
- package/dist/{server-4YLBAZEM.js → server-JNQ2PLCC.js} +17 -14
- package/dist/{server-4YLBAZEM.js.map → server-JNQ2PLCC.js.map} +1 -1
- package/dist/session-5TNWVGQQ.js +21 -0
- package/dist/session-5TNWVGQQ.js.map +1 -0
- package/dist/{session-CgvT-Oso.d.ts → session-uT8xL03K.d.ts} +5 -1
- package/dist/{studio-command-RFPV2DS7.js → studio-command-KK7A3KN6.js} +2 -2
- package/dist/{test-command-UEJG5AI6.js → test-command-QGIJBRH7.js} +278 -41
- package/dist/test-command-QGIJBRH7.js.map +1 -0
- package/dist/{validator-BLOLIHUY.js → validator-WO5IL7IY.js} +3 -3
- package/dist/validator-WO5IL7IY.js.map +1 -0
- package/package.json +10 -10
- package/dist/allure-RAEK4SIH.js.map +0 -1
- package/dist/chunk-2KRVN4WN.js.map +0 -1
- package/dist/chunk-3UVSUVHW.js.map +0 -1
- package/dist/chunk-ALPQES3J.js.map +0 -1
- package/dist/chunk-IGTK5MHB.js.map +0 -1
- package/dist/chunk-JZZ2W2XH.js.map +0 -1
- package/dist/chunk-PLE7RFQE.js.map +0 -1
- package/dist/chunk-UEWZ2EXL.js.map +0 -1
- package/dist/config-loader-F5YAY7RP.js +0 -9
- package/dist/console-BGAK7Z2L.js.map +0 -1
- package/dist/flow-CSMwD9Fh.d.ts +0 -69
- package/dist/html-JO2YNRWX.js.map +0 -1
- package/dist/junit-HLC62MK6.js.map +0 -1
- package/dist/session-K7FCRKOC.js +0 -18
- package/dist/test-command-UEJG5AI6.js.map +0 -1
- /package/dist/{config-loader-F5YAY7RP.js.map → agent-fixture-5C4MCWRD.js.map} +0 -0
- /package/dist/{discover-RLSKEBAX.js.map → app-RSDPDTKT.js.map} +0 -0
- /package/dist/{runner-TF4OKPYP.js.map → cache-command-PANUAEMZ.js.map} +0 -0
- /package/dist/{chunk-Y2RZNOKU.js.map → chunk-26NJXP55.js.map} +0 -0
- /package/dist/{chunk-SF7UYW4I.js.map → chunk-VUNH4AJD.js.map} +0 -0
- /package/dist/{chunk-FP6PVHHR.js.map → chunk-WZAQANN6.js.map} +0 -0
- /package/dist/{server-IS4K5FCT.js.map → config-loader-CNGIW2XK.js.map} +0 -0
- /package/dist/{session-K7FCRKOC.js.map → discover-NKDMB4UI.js.map} +0 -0
- /package/dist/{validator-BLOLIHUY.js.map → local-DM3YBSV5.js.map} +0 -0
- /package/dist/{studio-command-RFPV2DS7.js.map → studio-command-KK7A3KN6.js.map} +0 -0
|
@@ -1,1955 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adbShell,
|
|
3
|
+
findADB
|
|
4
|
+
} from "./chunk-2AFWVHQK.js";
|
|
1
5
|
import {
|
|
2
6
|
allocatePort,
|
|
3
7
|
releasePort
|
|
4
8
|
} from "./chunk-JPZCZHL4.js";
|
|
5
9
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
) {
|
|
20
|
-
};
|
|
21
|
-
var TextMismatchError = class extends Schema.TaggedError()(
|
|
22
|
-
"TextMismatchError",
|
|
23
|
-
{
|
|
24
|
-
message: Schema.String,
|
|
25
|
-
expected: Schema.String,
|
|
26
|
-
actual: Schema.optional(Schema.String),
|
|
27
|
-
selector: Schema.Unknown
|
|
28
|
-
}
|
|
29
|
-
) {
|
|
30
|
-
};
|
|
31
|
-
var TimeoutError = class extends Schema.TaggedError()("TimeoutError", {
|
|
32
|
-
message: Schema.String,
|
|
33
|
-
operation: Schema.String,
|
|
34
|
-
timeoutMs: Schema.Number
|
|
35
|
-
}) {
|
|
36
|
-
};
|
|
37
|
-
var WaitTimeoutError = class extends Schema.TaggedError()("WaitTimeoutError", {
|
|
38
|
-
message: Schema.String,
|
|
39
|
-
selector: Schema.Unknown,
|
|
40
|
-
timeoutMs: Schema.Number
|
|
41
|
-
}) {
|
|
42
|
-
};
|
|
43
|
-
var DriverError = class extends Schema.TaggedError()("DriverError", {
|
|
44
|
-
message: Schema.String,
|
|
45
|
-
command: Schema.optional(Schema.String),
|
|
46
|
-
exitCode: Schema.optional(Schema.Number),
|
|
47
|
-
stdout: Schema.optional(Schema.String),
|
|
48
|
-
stderr: Schema.optional(Schema.String)
|
|
49
|
-
}) {
|
|
50
|
-
};
|
|
51
|
-
var DeviceDisconnectedError = class extends Schema.TaggedError()(
|
|
52
|
-
"DeviceDisconnectedError",
|
|
53
|
-
{
|
|
54
|
-
message: Schema.String,
|
|
55
|
-
deviceId: Schema.optional(Schema.String),
|
|
56
|
-
platform: Schema.optional(Schema.String)
|
|
57
|
-
}
|
|
58
|
-
) {
|
|
59
|
-
};
|
|
60
|
-
var AppCrashedError = class extends Schema.TaggedError()("AppCrashedError", {
|
|
61
|
-
message: Schema.String,
|
|
62
|
-
appId: Schema.optional(Schema.String),
|
|
63
|
-
platform: Schema.optional(Schema.String)
|
|
64
|
-
}) {
|
|
65
|
-
};
|
|
66
|
-
var AppNotInstalledError = class extends Schema.TaggedError()(
|
|
67
|
-
"AppNotInstalledError",
|
|
68
|
-
{
|
|
69
|
-
message: Schema.String,
|
|
70
|
-
appId: Schema.String,
|
|
71
|
-
platform: Schema.optional(Schema.String)
|
|
72
|
-
}
|
|
73
|
-
) {
|
|
74
|
-
};
|
|
75
|
-
var FlowSyntaxError = class extends Schema.TaggedError()("FlowSyntaxError", {
|
|
76
|
-
message: Schema.String,
|
|
77
|
-
filePath: Schema.String
|
|
78
|
-
}) {
|
|
79
|
-
};
|
|
80
|
-
var DeviceNotFoundError = class extends Schema.TaggedError()(
|
|
81
|
-
"DeviceNotFoundError",
|
|
82
|
-
{
|
|
83
|
-
message: Schema.String,
|
|
84
|
-
platform: Schema.optional(Schema.String),
|
|
85
|
-
deviceId: Schema.optional(Schema.String)
|
|
86
|
-
}
|
|
87
|
-
) {
|
|
88
|
-
};
|
|
89
|
-
var ConfigError = class extends Schema.TaggedError()("ConfigError", {
|
|
90
|
-
message: Schema.String,
|
|
91
|
-
filePath: Schema.optional(Schema.String)
|
|
92
|
-
}) {
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// src/channels/dom-channel.ts
|
|
96
|
-
function domMatchToElement(match, screenBounds) {
|
|
97
|
-
return {
|
|
98
|
-
...match.id !== void 0 ? { id: match.id } : {},
|
|
99
|
-
...match.text !== void 0 ? { text: match.text } : {},
|
|
100
|
-
...match.textContent !== void 0 ? { textContent: match.textContent } : {},
|
|
101
|
-
...match.value !== void 0 ? { value: match.value } : {},
|
|
102
|
-
...match.accessibilityLabel !== void 0 ? { accessibilityLabel: match.accessibilityLabel } : {},
|
|
103
|
-
...match.accessibleDescription !== void 0 ? { accessibleDescription: match.accessibleDescription } : {},
|
|
104
|
-
...match.tag !== void 0 ? { elementType: match.tag } : {},
|
|
105
|
-
bounds: screenBounds ?? {
|
|
106
|
-
x: Math.round(match.rect.x),
|
|
107
|
-
y: Math.round(match.rect.y),
|
|
108
|
-
width: Math.round(match.rect.width),
|
|
109
|
-
height: Math.round(match.rect.height)
|
|
110
|
-
},
|
|
111
|
-
enabled: match.enabled,
|
|
112
|
-
visible: match.visible,
|
|
113
|
-
clickable: match.clickable,
|
|
114
|
-
...match.focused !== void 0 ? { focused: match.focused } : {},
|
|
115
|
-
...match.attributes && Object.keys(match.attributes).length > 0 ? { attributes: match.attributes } : {}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function buildEvaluateExpression(script, args = []) {
|
|
119
|
-
if (typeof script === "function") {
|
|
120
|
-
const serializedArgs = args.map((arg) => JSON.stringify(arg)).join(", ");
|
|
121
|
-
return `(${script.toString()})(${serializedArgs})`;
|
|
122
|
-
}
|
|
123
|
-
const trimmed = script.trim();
|
|
124
|
-
if (/\breturn\b/.test(trimmed) && !trimmed.startsWith("(") && !trimmed.startsWith("async")) {
|
|
125
|
-
const serializedArgs = args.map((arg) => JSON.stringify(arg)).join(", ");
|
|
126
|
-
return `(function(){ ${trimmed} })(${serializedArgs})`;
|
|
127
|
-
}
|
|
128
|
-
return script;
|
|
129
|
-
}
|
|
130
|
-
function serializeSelectorForDom(sel) {
|
|
131
|
-
if (sel instanceof RegExp) {
|
|
132
|
-
return { __spanaRegex: sel.source, flags: sel.flags };
|
|
133
|
-
}
|
|
134
|
-
if (Array.isArray(sel)) {
|
|
135
|
-
return sel.map((item) => serializeSelectorForDom(item));
|
|
136
|
-
}
|
|
137
|
-
if (sel && typeof sel === "object") {
|
|
138
|
-
const out = {};
|
|
139
|
-
for (const [k, v] of Object.entries(sel)) {
|
|
140
|
-
if (v !== void 0) {
|
|
141
|
-
out[k] = serializeSelectorForDom(v);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
return sel;
|
|
147
|
-
}
|
|
148
|
-
var SHARED_DOM_TRAVERSAL_HELPERS = `
|
|
149
|
-
function matchSpec(actual, spec, exact) {
|
|
150
|
-
var str = String(actual || "");
|
|
151
|
-
if (spec && typeof spec === "object" && typeof spec.__spanaRegex === "string") {
|
|
152
|
-
try { return new RegExp(spec.__spanaRegex, spec.flags || "").test(str); } catch (e) { return false; }
|
|
153
|
-
}
|
|
154
|
-
var needle = String(spec == null ? "" : spec);
|
|
155
|
-
if (exact) return str.trim() === needle.trim();
|
|
156
|
-
return str.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
|
|
157
|
-
}
|
|
158
|
-
function getImplicitRole(el) {
|
|
159
|
-
if (!el || !el.getAttribute) return "";
|
|
160
|
-
var explicit = (el.getAttribute("role") || "").trim().toLowerCase();
|
|
161
|
-
if (explicit) return explicit.split(/\\s+/)[0] || "";
|
|
162
|
-
var tag = el.tagName ? el.tagName.toUpperCase() : "";
|
|
163
|
-
if (tag === "BUTTON") return "button";
|
|
164
|
-
if (tag === "A") return el.hasAttribute("href") ? "link" : "";
|
|
165
|
-
if (tag === "TEXTAREA") return "textbox";
|
|
166
|
-
if (tag === "SELECT") return (el.hasAttribute("multiple") || Number(el.getAttribute("size") || 0) > 1) ? "listbox" : "combobox";
|
|
167
|
-
if (tag === "OPTION") return "option";
|
|
168
|
-
if (tag === "IMG") return el.getAttribute("alt") === "" ? "presentation" : "img";
|
|
169
|
-
if (tag === "DIALOG") return "dialog";
|
|
170
|
-
if (tag === "NAV") return "navigation";
|
|
171
|
-
if (tag === "MAIN") return "main";
|
|
172
|
-
if (tag === "HEADER") return "banner";
|
|
173
|
-
if (tag === "FOOTER") return "contentinfo";
|
|
174
|
-
if (tag === "ASIDE") return "complementary";
|
|
175
|
-
if (tag === "UL" || tag === "OL") return "list";
|
|
176
|
-
if (tag === "LI") return "listitem";
|
|
177
|
-
if (tag === "TABLE") return "table";
|
|
178
|
-
if (tag === "TR") return "row";
|
|
179
|
-
if (tag === "TD") return "cell";
|
|
180
|
-
if (tag === "TH") return "columnheader";
|
|
181
|
-
if (tag === "ARTICLE") return "article";
|
|
182
|
-
if (tag === "FORM") return "form";
|
|
183
|
-
if (tag === "PROGRESS") return "progressbar";
|
|
184
|
-
if (tag === "HR") return "separator";
|
|
185
|
-
if (tag === "SECTION") return (el.hasAttribute("aria-label") || el.hasAttribute("aria-labelledby")) ? "region" : "";
|
|
186
|
-
if (/^H[1-6]$/.test(tag)) return "heading";
|
|
187
|
-
if (tag === "INPUT") {
|
|
188
|
-
var t = (el.getAttribute("type") || "text").toLowerCase();
|
|
189
|
-
if (t === "button" || t === "submit" || t === "reset" || t === "image") return "button";
|
|
190
|
-
if (t === "checkbox") return "checkbox";
|
|
191
|
-
if (t === "radio") return "radio";
|
|
192
|
-
if (t === "search") return "searchbox";
|
|
193
|
-
if (t === "number") return "spinbutton";
|
|
194
|
-
if (t === "range") return "slider";
|
|
195
|
-
if (t === "hidden") return "";
|
|
196
|
-
return "textbox";
|
|
197
|
-
}
|
|
198
|
-
return "";
|
|
199
|
-
}
|
|
200
|
-
function visibleTextOf(node, allowHiddenRoot, skipControl) {
|
|
201
|
-
if (!node) return "";
|
|
202
|
-
if (node.nodeType === 3) return node.nodeValue || "";
|
|
203
|
-
if (node.nodeType !== 1 && node.nodeType !== 11) return "";
|
|
204
|
-
if (node.nodeType === 1) {
|
|
205
|
-
if (skipControl && node === skipControl) return "";
|
|
206
|
-
var t = node.tagName ? node.tagName.toUpperCase() : "";
|
|
207
|
-
if (t === "SCRIPT" || t === "STYLE" || t === "NOSCRIPT" || t === "TEMPLATE") return "";
|
|
208
|
-
if (skipControl && (t === "SELECT" || t === "TEXTAREA" || t === "INPUT")) return "";
|
|
209
|
-
if (!allowHiddenRoot) {
|
|
210
|
-
if (node.getAttribute && node.getAttribute("aria-hidden") === "true") return "";
|
|
211
|
-
var win = (node.ownerDocument && node.ownerDocument.defaultView) || window;
|
|
212
|
-
if (win && win.getComputedStyle) {
|
|
213
|
-
var st = win.getComputedStyle(node);
|
|
214
|
-
if (st && (st.display === "none" || st.visibility === "hidden" || st.visibility === "collapse")) {
|
|
215
|
-
return "";
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
var out = [];
|
|
221
|
-
if (node.shadowRoot) {
|
|
222
|
-
var stxt = visibleTextOf(node.shadowRoot, false, skipControl);
|
|
223
|
-
if (stxt) out.push(stxt);
|
|
224
|
-
}
|
|
225
|
-
var kids = node.childNodes || [];
|
|
226
|
-
for (var i = 0; i < kids.length; i++) {
|
|
227
|
-
var k = visibleTextOf(kids[i], false, skipControl);
|
|
228
|
-
if (k) out.push(k);
|
|
229
|
-
}
|
|
230
|
-
return out.join(" ").replace(/\\s+/g, " ").trim();
|
|
231
|
-
}
|
|
232
|
-
function isAriaHidden(el) {
|
|
233
|
-
if (!el) return true;
|
|
234
|
-
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
235
|
-
var cur = el;
|
|
236
|
-
var guard = 0;
|
|
237
|
-
while (cur && guard++ < 32) {
|
|
238
|
-
if (cur.getAttribute) {
|
|
239
|
-
if (cur.getAttribute("aria-hidden") === "true") return true;
|
|
240
|
-
if (cur.hasAttribute && cur.hasAttribute("inert")) return true;
|
|
241
|
-
}
|
|
242
|
-
if (cur.nodeType === 1 && win && win.getComputedStyle) {
|
|
243
|
-
var cs = win.getComputedStyle(cur);
|
|
244
|
-
if (cs && cs.display === "none") return true;
|
|
245
|
-
}
|
|
246
|
-
var root = typeof cur.getRootNode === "function" ? cur.getRootNode() : null;
|
|
247
|
-
cur = cur.parentElement || (root && root.host) || null;
|
|
248
|
-
}
|
|
249
|
-
if (typeof el.checkVisibility === "function") {
|
|
250
|
-
try {
|
|
251
|
-
if (!el.checkVisibility({ visibilityProperty: true })) return true;
|
|
252
|
-
} catch (e) {}
|
|
253
|
-
} else if (win && win.getComputedStyle) {
|
|
254
|
-
var selfCs = win.getComputedStyle(el);
|
|
255
|
-
if (selfCs && (selfCs.visibility === "hidden" || selfCs.visibility === "collapse")) return true;
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
function headingLevelOf(el) {
|
|
260
|
-
if (!el) return null;
|
|
261
|
-
var explicit = el.getAttribute && el.getAttribute("aria-level");
|
|
262
|
-
if (explicit) {
|
|
263
|
-
var parsed = parseInt(explicit, 10);
|
|
264
|
-
if (!isNaN(parsed)) return parsed;
|
|
265
|
-
}
|
|
266
|
-
var tag = el.tagName ? el.tagName.toUpperCase() : "";
|
|
267
|
-
var m = /^H([1-6])$/.exec(tag);
|
|
268
|
-
return m ? parseInt(m[1], 10) : null;
|
|
269
|
-
}
|
|
270
|
-
function getAccessibleName(el) {
|
|
271
|
-
if (!el) return "";
|
|
272
|
-
var doc = el.ownerDocument || document;
|
|
273
|
-
var labelledBy = el.getAttribute && el.getAttribute("aria-labelledby");
|
|
274
|
-
if (labelledBy) {
|
|
275
|
-
var parts = [];
|
|
276
|
-
var ids = labelledBy.trim().split(/\\s+/);
|
|
277
|
-
for (var i = 0; i < ids.length; i++) {
|
|
278
|
-
var ref = doc.getElementById ? doc.getElementById(ids[i]) : null;
|
|
279
|
-
if (ref) {
|
|
280
|
-
var rt = visibleTextOf(ref, true, null);
|
|
281
|
-
if (rt) parts.push(rt);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (parts.length > 0) return parts.join(" ").replace(/\\s+/g, " ").trim();
|
|
285
|
-
}
|
|
286
|
-
var ariaLabel = el.getAttribute && el.getAttribute("aria-label");
|
|
287
|
-
if (ariaLabel && ariaLabel.trim()) return ariaLabel.trim();
|
|
288
|
-
var tag = el.tagName ? el.tagName.toUpperCase() : "";
|
|
289
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") {
|
|
290
|
-
if (el.id && doc.querySelector) {
|
|
291
|
-
try {
|
|
292
|
-
var escId = typeof CSS !== "undefined" && CSS.escape ? CSS.escape(el.id) : el.id;
|
|
293
|
-
var forLbl = doc.querySelector('label[for="' + escId + '"]');
|
|
294
|
-
if (forLbl) {
|
|
295
|
-
var ft = visibleTextOf(forLbl, false, el);
|
|
296
|
-
if (ft) return ft;
|
|
297
|
-
}
|
|
298
|
-
} catch (e) {}
|
|
299
|
-
}
|
|
300
|
-
if (el.closest) {
|
|
301
|
-
var wrapLbl = el.closest("label");
|
|
302
|
-
if (wrapLbl) {
|
|
303
|
-
var wt = visibleTextOf(wrapLbl, false, el);
|
|
304
|
-
if (wt) return wt;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
var itype = tag === "INPUT" ? (el.getAttribute("type") || "text").toLowerCase() : "";
|
|
308
|
-
if ((itype === "button" || itype === "submit" || itype === "reset") && el.value) {
|
|
309
|
-
return String(el.value).trim();
|
|
310
|
-
}
|
|
311
|
-
var ph = el.getAttribute && el.getAttribute("placeholder");
|
|
312
|
-
if (ph && ph.trim()) return ph.trim();
|
|
313
|
-
}
|
|
314
|
-
if (tag === "IMG") {
|
|
315
|
-
var alt = el.getAttribute && el.getAttribute("alt");
|
|
316
|
-
if (alt && alt.trim()) return alt.trim();
|
|
317
|
-
}
|
|
318
|
-
var txt = visibleTextOf(el, false, null);
|
|
319
|
-
if (txt) return txt;
|
|
320
|
-
var title = el.getAttribute && el.getAttribute("title");
|
|
321
|
-
return title ? title.trim() : "";
|
|
322
|
-
}
|
|
323
|
-
function getAccessibleDescription(el) {
|
|
324
|
-
if (!el) return "";
|
|
325
|
-
var doc = el.ownerDocument || document;
|
|
326
|
-
var describedBy = el.getAttribute && el.getAttribute("aria-describedby");
|
|
327
|
-
if (describedBy) {
|
|
328
|
-
var parts = [];
|
|
329
|
-
var ids = describedBy.trim().split(/\\s+/);
|
|
330
|
-
for (var i = 0; i < ids.length; i++) {
|
|
331
|
-
var ref = doc.getElementById ? doc.getElementById(ids[i]) : null;
|
|
332
|
-
if (ref) {
|
|
333
|
-
var rt = visibleTextOf(ref, true, null);
|
|
334
|
-
if (rt) parts.push(rt);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if (parts.length > 0) return parts.join(" ").replace(/\\s+/g, " ").trim();
|
|
338
|
-
}
|
|
339
|
-
var ariaDesc = el.getAttribute && el.getAttribute("aria-description");
|
|
340
|
-
if (ariaDesc && ariaDesc.trim()) return ariaDesc.trim();
|
|
341
|
-
var title = el.getAttribute && el.getAttribute("title");
|
|
342
|
-
if (title && title.trim()) {
|
|
343
|
-
var accName = getAccessibleName(el);
|
|
344
|
-
if (accName && accName !== title.trim()) return title.trim();
|
|
345
|
-
}
|
|
346
|
-
return "";
|
|
347
|
-
}
|
|
348
|
-
function collectRoots(root, offsetX, offsetY, inShadow, inIframe, out) {
|
|
349
|
-
if (!root) return;
|
|
350
|
-
out.push({ root: root, offsetX: offsetX, offsetY: offsetY, inShadow: inShadow, inIframe: inIframe });
|
|
351
|
-
if (root.shadowRoot) {
|
|
352
|
-
collectRoots(root.shadowRoot, offsetX, offsetY, true, inIframe, out);
|
|
353
|
-
}
|
|
354
|
-
var nodes = root.querySelectorAll ? root.querySelectorAll("*") : [];
|
|
355
|
-
for (var i = 0; i < nodes.length; i++) {
|
|
356
|
-
var el = nodes[i];
|
|
357
|
-
if (el.shadowRoot) {
|
|
358
|
-
collectRoots(el.shadowRoot, offsetX, offsetY, true, inIframe, out);
|
|
359
|
-
}
|
|
360
|
-
if (el.tagName === "IFRAME") {
|
|
361
|
-
try {
|
|
362
|
-
var frameDoc = el.contentDocument;
|
|
363
|
-
if (frameDoc) {
|
|
364
|
-
var frameRect = el.getBoundingClientRect();
|
|
365
|
-
collectRoots(frameDoc, offsetX + frameRect.left, offsetY + frameRect.top, inShadow, true, out);
|
|
366
|
-
}
|
|
367
|
-
} catch (e) {}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function findTextInRoot(root, needle, exact, ctx, pushHit) {
|
|
372
|
-
var doc = root.ownerDocument || (root.nodeType === 9 ? root : document);
|
|
373
|
-
if (doc && typeof doc.createTreeWalker === "function" && typeof NodeFilter !== "undefined") {
|
|
374
|
-
var walker = doc.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
375
|
-
var txtNode;
|
|
376
|
-
while ((txtNode = walker.nextNode())) {
|
|
377
|
-
var rawVal = (txtNode.nodeValue || "").trim();
|
|
378
|
-
var val = rawVal.toLowerCase();
|
|
379
|
-
var ok = exact ? rawVal === needle : (val && val.indexOf(needle.toLowerCase()) !== -1);
|
|
380
|
-
if (ok && txtNode.parentElement) {
|
|
381
|
-
pushHit(txtNode.parentElement, ctx);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (typeof root.querySelectorAll === "function") {
|
|
385
|
-
var inputs = root.querySelectorAll("input, button");
|
|
386
|
-
for (var ii = 0; ii < inputs.length; ii++) {
|
|
387
|
-
var inp = inputs[ii];
|
|
388
|
-
var rawInp = String(inp.value || "").trim();
|
|
389
|
-
var inpOk = exact ? rawInp === needle : (rawInp && rawInp.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
390
|
-
if (inpOk) {
|
|
391
|
-
pushHit(inp, ctx);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
var all = root.querySelectorAll ? root.querySelectorAll("*") : [];
|
|
398
|
-
for (var k = 0; k < all.length; k++) {
|
|
399
|
-
var node = all[k];
|
|
400
|
-
var directText = "";
|
|
401
|
-
for (var c = 0; c < node.childNodes.length; c++) {
|
|
402
|
-
if (node.childNodes[c].nodeType === 3) directText += node.childNodes[c].textContent || "";
|
|
403
|
-
}
|
|
404
|
-
var trimmedDirect = directText.trim();
|
|
405
|
-
var inpVal = (node.tagName === "INPUT" || node.tagName === "BUTTON") ? String(node.value || "").trim() : "";
|
|
406
|
-
var directOk = exact ? trimmedDirect === needle : (trimmedDirect && trimmedDirect.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
407
|
-
var inputOk = exact ? inpVal === needle : (inpVal && inpVal.toLowerCase().indexOf(needle.toLowerCase()) !== -1);
|
|
408
|
-
if (directOk || inputOk) {
|
|
409
|
-
pushHit(node, ctx);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function findRoleInRoot(root, roleLower, nameSpec, exact, ctx, pushHit, includeHidden, level) {
|
|
414
|
-
if (!root || !root.querySelectorAll) return;
|
|
415
|
-
var candidates = root.querySelectorAll("*");
|
|
416
|
-
for (var i = 0; i < candidates.length; i++) {
|
|
417
|
-
var el = candidates[i];
|
|
418
|
-
if (getImplicitRole(el) !== roleLower) continue;
|
|
419
|
-
if (!includeHidden && isAriaHidden(el)) continue;
|
|
420
|
-
if (level !== undefined && level !== null && headingLevelOf(el) !== Number(level)) continue;
|
|
421
|
-
if (nameSpec !== undefined && nameSpec !== null) {
|
|
422
|
-
var accName = getAccessibleName(el);
|
|
423
|
-
if (!matchSpec(accName, nameSpec, Boolean(exact))) continue;
|
|
424
|
-
}
|
|
425
|
-
pushHit(el, ctx);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
function applyModifiersAndSlice(hits, sel) {
|
|
429
|
-
if (!sel || typeof sel !== "object" || "point" in sel) return hits;
|
|
430
|
-
var filtered = hits;
|
|
431
|
-
if (sel.hasText !== undefined) {
|
|
432
|
-
filtered = filtered.filter(function(h) {
|
|
433
|
-
var txt = (h.el.innerText || h.el.textContent || h.el.value || getAccessibleName(h.el) || "");
|
|
434
|
-
return matchSpec(txt, sel.hasText, false);
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
if (sel.hasNotText !== undefined) {
|
|
438
|
-
filtered = filtered.filter(function(h) {
|
|
439
|
-
var txt = (h.el.innerText || h.el.textContent || h.el.value || getAccessibleName(h.el) || "");
|
|
440
|
-
return !matchSpec(txt, sel.hasNotText, false);
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if (sel.has !== undefined) {
|
|
444
|
-
filtered = filtered.filter(function(h) {
|
|
445
|
-
return findInScope(sel.has, h.el, h.offsetX, h.offsetY, h.inShadow, h.inIframe).length > 0;
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
if (sel.hasNot !== undefined) {
|
|
449
|
-
filtered = filtered.filter(function(h) {
|
|
450
|
-
return findInScope(sel.hasNot, h.el, h.offsetX, h.offsetY, h.inShadow, h.inIframe).length === 0;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
if (sel.first) return filtered.length > 0 ? [filtered[0]] : [];
|
|
454
|
-
if (sel.last) return filtered.length > 0 ? [filtered[filtered.length - 1]] : [];
|
|
455
|
-
if (typeof sel.nth === "number") {
|
|
456
|
-
var idx = sel.nth < 0 ? filtered.length + sel.nth : sel.nth;
|
|
457
|
-
return idx >= 0 && idx < filtered.length ? [filtered[idx]] : [];
|
|
458
|
-
}
|
|
459
|
-
return filtered;
|
|
460
|
-
}
|
|
461
|
-
function findInScope(sel, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe) {
|
|
462
|
-
var hits = [];
|
|
463
|
-
var seen = typeof Set !== "undefined" ? new Set() : null;
|
|
464
|
-
function pushHit(el, ctx) {
|
|
465
|
-
if (seen) {
|
|
466
|
-
if (seen.has(el)) return;
|
|
467
|
-
seen.add(el);
|
|
468
|
-
}
|
|
469
|
-
hits.push({ el: el, offsetX: ctx.offsetX, offsetY: ctx.offsetY, inShadow: ctx.inShadow, inIframe: ctx.inIframe });
|
|
470
|
-
}
|
|
471
|
-
if (typeof sel === "object" && sel !== null && "point" in sel) {
|
|
472
|
-
var atPt = document.elementFromPoint(sel.point.x, sel.point.y);
|
|
473
|
-
if (atPt) pushHit(atPt, { offsetX: 0, offsetY: 0, inShadow: false, inIframe: false });
|
|
474
|
-
return hits;
|
|
475
|
-
}
|
|
476
|
-
// Frame scoping: find matching <iframe> first, then search inside its contentDocument
|
|
477
|
-
if (typeof sel === "object" && sel !== null && sel.frame) {
|
|
478
|
-
var frameHits = findInScope(sel.frame, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe);
|
|
479
|
-
var innerSel = Object.assign({}, sel);
|
|
480
|
-
delete innerSel.frame;
|
|
481
|
-
for (var fi = 0; fi < frameHits.length; fi++) {
|
|
482
|
-
var fEl = frameHits[fi].el;
|
|
483
|
-
if (fEl && fEl.tagName === "IFRAME") {
|
|
484
|
-
try {
|
|
485
|
-
var fDoc = fEl.contentDocument;
|
|
486
|
-
if (fDoc) {
|
|
487
|
-
var fRect = fEl.getBoundingClientRect();
|
|
488
|
-
var sub = findInScope(innerSel, fDoc, frameHits[fi].offsetX + fRect.left, frameHits[fi].offsetY + fRect.top, frameHits[fi].inShadow, true);
|
|
489
|
-
for (var si = 0; si < sub.length; si++) pushHit(sub[si].el, sub[si]);
|
|
490
|
-
}
|
|
491
|
-
} catch (e) {}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return hits;
|
|
495
|
-
}
|
|
496
|
-
// Parent scoping: resolve 'within' first, then search inside each matched container
|
|
497
|
-
if (typeof sel === "object" && sel !== null && sel.within) {
|
|
498
|
-
var parentHits = findInScope(sel.within, scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe);
|
|
499
|
-
var childSel = Object.assign({}, sel);
|
|
500
|
-
delete childSel.within;
|
|
501
|
-
delete childSel.hasText;
|
|
502
|
-
delete childSel.hasNotText;
|
|
503
|
-
delete childSel.has;
|
|
504
|
-
delete childSel.hasNot;
|
|
505
|
-
delete childSel.first;
|
|
506
|
-
delete childSel.last;
|
|
507
|
-
delete childSel.nth;
|
|
508
|
-
var combined = [];
|
|
509
|
-
var cSeen = typeof Set !== "undefined" ? new Set() : null;
|
|
510
|
-
for (var pi = 0; pi < parentHits.length; pi++) {
|
|
511
|
-
var ph = parentHits[pi];
|
|
512
|
-
var subHits = findInScope(childSel, ph.el, ph.offsetX, ph.offsetY, ph.inShadow, ph.inIframe);
|
|
513
|
-
for (var ci = 0; ci < subHits.length; ci++) {
|
|
514
|
-
if (cSeen && cSeen.has(subHits[ci].el)) continue;
|
|
515
|
-
if (cSeen) cSeen.add(subHits[ci].el);
|
|
516
|
-
combined.push(subHits[ci]);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return applyModifiersAndSlice(combined, sel);
|
|
520
|
-
}
|
|
521
|
-
// Logical OR composition (anyOf): union deduplicated hits across branches
|
|
522
|
-
if (typeof sel === "object" && sel !== null && Array.isArray(sel.anyOf)) {
|
|
523
|
-
for (var bi = 0; bi < sel.anyOf.length; bi++) {
|
|
524
|
-
var branchHits = findInScope(sel.anyOf[bi], scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe);
|
|
525
|
-
for (var bh = 0; bh < branchHits.length; bh++) {
|
|
526
|
-
pushHit(branchHits[bh].el, branchHits[bh]);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
return applyModifiersAndSlice(hits, sel);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
var esc = function(v) {
|
|
533
|
-
return typeof CSS !== "undefined" && CSS.escape ? CSS.escape(v) : String(v).replace(/\\\\/g, "\\\\\\\\").replace(/"/g, '\\\\"');
|
|
534
|
-
};
|
|
535
|
-
var mainCtx = { root: scopeRoot, offsetX: baseOffsetX, offsetY: baseOffsetY, inShadow: baseInShadow, inIframe: baseInIframe };
|
|
536
|
-
var hasModifiers = typeof sel === "object" && sel !== null && (sel.hasText !== undefined || sel.hasNotText !== undefined || sel.has !== undefined || sel.hasNot !== undefined || sel.first || sel.last || typeof sel.nth === "number");
|
|
537
|
-
|
|
538
|
-
// O(1)-ish Light-DOM fast path: avoids scanning thousands of nodes with querySelectorAll("*")
|
|
539
|
-
// unless Shadow DOM / iframe piercing is needed or no Light-DOM match exists.
|
|
540
|
-
if (scopeRoot && scopeRoot.querySelectorAll && !hasModifiers) {
|
|
541
|
-
if (typeof sel === "object" && sel !== null && "testID" in sel) {
|
|
542
|
-
var fastTid = esc(sel.testID);
|
|
543
|
-
var fastFound = scopeRoot.querySelectorAll('[data-testid="' + fastTid + '"], [testID="' + fastTid + '"]');
|
|
544
|
-
if (fastFound.length > 0) {
|
|
545
|
-
for (var fi2 = 0; fi2 < fastFound.length; fi2++) pushHit(fastFound[fi2], mainCtx);
|
|
546
|
-
return hits;
|
|
547
|
-
}
|
|
548
|
-
} else if (typeof sel === "object" && sel !== null && "css" in sel) {
|
|
549
|
-
try {
|
|
550
|
-
var fastCss = scopeRoot.querySelectorAll(sel.css);
|
|
551
|
-
if (fastCss.length > 0) {
|
|
552
|
-
for (var fc = 0; fc < fastCss.length; fc++) pushHit(fastCss[fc], mainCtx);
|
|
553
|
-
return hits;
|
|
554
|
-
}
|
|
555
|
-
} catch (e) {}
|
|
556
|
-
} else if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel) {
|
|
557
|
-
var fastLbl = esc(sel.accessibilityLabel);
|
|
558
|
-
var fastFoundLbl = scopeRoot.querySelectorAll('[aria-label="' + fastLbl + '"]');
|
|
559
|
-
if (fastFoundLbl.length > 0) {
|
|
560
|
-
for (var fj = 0; fj < fastFoundLbl.length; fj++) pushHit(fastFoundLbl[fj], mainCtx);
|
|
561
|
-
return hits;
|
|
562
|
-
}
|
|
563
|
-
} else if (typeof sel === "object" && sel !== null && "role" in sel) {
|
|
564
|
-
findRoleInRoot(scopeRoot, String(sel.role).toLowerCase(), sel.name, sel.exact, mainCtx, pushHit, sel.includeHidden, sel.level);
|
|
565
|
-
if (hits.length > 0) return hits;
|
|
566
|
-
} else if (typeof sel === "string" || (typeof sel === "object" && sel !== null && "text" in sel)) {
|
|
567
|
-
var fastNeedle = typeof sel === "string" ? sel : sel.text;
|
|
568
|
-
var fastExact = typeof sel === "object" && sel !== null && Boolean(sel.exact);
|
|
569
|
-
findTextInRoot(scopeRoot, fastNeedle, fastExact, mainCtx, pushHit);
|
|
570
|
-
if (hits.length > 0) return hits;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
var roots = [];
|
|
575
|
-
collectRoots(scopeRoot, baseOffsetX, baseOffsetY, baseInShadow, baseInIframe, roots);
|
|
576
|
-
for (var r = 0; r < roots.length; r++) {
|
|
577
|
-
var ctx = roots[r];
|
|
578
|
-
var root = ctx.root;
|
|
579
|
-
if (!root || !root.querySelectorAll) continue;
|
|
580
|
-
if (typeof sel === "object" && sel !== null && "testID" in sel) {
|
|
581
|
-
var tid = esc(sel.testID);
|
|
582
|
-
var found = root.querySelectorAll('[data-testid="' + tid + '"], [testID="' + tid + '"]');
|
|
583
|
-
for (var i = 0; i < found.length; i++) pushHit(found[i], ctx);
|
|
584
|
-
} else if (typeof sel === "object" && sel !== null && "css" in sel) {
|
|
585
|
-
try {
|
|
586
|
-
var foundCss = root.querySelectorAll(sel.css);
|
|
587
|
-
for (var ci2 = 0; ci2 < foundCss.length; ci2++) pushHit(foundCss[ci2], ctx);
|
|
588
|
-
} catch (e) {}
|
|
589
|
-
} else if (typeof sel === "object" && sel !== null && "accessibilityLabel" in sel) {
|
|
590
|
-
var lbl = esc(sel.accessibilityLabel);
|
|
591
|
-
var foundLbl = root.querySelectorAll('[aria-label="' + lbl + '"]');
|
|
592
|
-
for (var j = 0; j < foundLbl.length; j++) pushHit(foundLbl[j], ctx);
|
|
593
|
-
} else if (typeof sel === "object" && sel !== null && "role" in sel) {
|
|
594
|
-
findRoleInRoot(root, String(sel.role).toLowerCase(), sel.name, sel.exact, ctx, pushHit, sel.includeHidden, sel.level);
|
|
595
|
-
} else if (typeof sel === "string" || (typeof sel === "object" && sel !== null && "text" in sel)) {
|
|
596
|
-
var needle = typeof sel === "string" ? sel : sel.text;
|
|
597
|
-
var isExact = typeof sel === "object" && sel !== null && Boolean(sel.exact);
|
|
598
|
-
findTextInRoot(root, needle, isExact, ctx, pushHit);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return applyModifiersAndSlice(hits, sel);
|
|
602
|
-
}
|
|
603
|
-
function findAcrossRoots(sel) {
|
|
604
|
-
return findInScope(sel, document, 0, 0, false, false);
|
|
605
|
-
}
|
|
606
|
-
function isClickable(el) {
|
|
607
|
-
var tag = el.tagName;
|
|
608
|
-
if (tag === "BUTTON" || tag === "A" || tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA") return true;
|
|
609
|
-
var role = el.getAttribute && el.getAttribute("role");
|
|
610
|
-
if (role === "button" || role === "link" || role === "tab" || role === "checkbox" || role === "switch") return true;
|
|
611
|
-
if (typeof el.onclick === "function") return true;
|
|
612
|
-
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
613
|
-
var cursor = win.getComputedStyle(el).cursor;
|
|
614
|
-
return cursor === "pointer";
|
|
615
|
-
}
|
|
616
|
-
function isAppReady() {
|
|
617
|
-
var sig = typeof window !== "undefined" ? window.__SPANA_APP_READY__ : undefined;
|
|
618
|
-
if (typeof sig === "function") {
|
|
619
|
-
try { return Boolean(sig()); } catch (e) { return false; }
|
|
620
|
-
}
|
|
621
|
-
if (typeof sig === "boolean") return sig;
|
|
622
|
-
return true;
|
|
623
|
-
}
|
|
624
|
-
function deepElementFromPoint(rootDoc, x, y) {
|
|
625
|
-
if (!rootDoc || typeof rootDoc.elementFromPoint !== "function") return null;
|
|
626
|
-
var el = rootDoc.elementFromPoint(x, y);
|
|
627
|
-
var guard = 0;
|
|
628
|
-
while (el && guard++ < 16) {
|
|
629
|
-
if (el.shadowRoot && typeof el.shadowRoot.elementFromPoint === "function") {
|
|
630
|
-
var inner = el.shadowRoot.elementFromPoint(x, y);
|
|
631
|
-
if (inner && inner !== el) { el = inner; continue; }
|
|
632
|
-
}
|
|
633
|
-
if (el.tagName === "IFRAME") {
|
|
634
|
-
try {
|
|
635
|
-
var fdoc = el.contentDocument;
|
|
636
|
-
if (fdoc && typeof fdoc.elementFromPoint === "function") {
|
|
637
|
-
var fr = el.getBoundingClientRect();
|
|
638
|
-
var fx = x - fr.left;
|
|
639
|
-
var fy = y - fr.top;
|
|
640
|
-
var fEl = fdoc.elementFromPoint(fx, fy);
|
|
641
|
-
if (fEl && fEl !== el) { el = fEl; x = fx; y = fy; continue; }
|
|
642
|
-
}
|
|
643
|
-
} catch (e) {}
|
|
644
|
-
}
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
return el;
|
|
648
|
-
}
|
|
649
|
-
function labelControlOf(node) {
|
|
650
|
-
var cur = node;
|
|
651
|
-
var guard = 0;
|
|
652
|
-
while (cur && guard++ < 8) {
|
|
653
|
-
if (cur.tagName === "LABEL") return cur.control || null;
|
|
654
|
-
cur = cur.parentElement;
|
|
655
|
-
}
|
|
656
|
-
return null;
|
|
657
|
-
}
|
|
658
|
-
function isSameOrDescendant(target, candidate) {
|
|
659
|
-
if (!target || !candidate) return false;
|
|
660
|
-
if (target === candidate) return true;
|
|
661
|
-
try {
|
|
662
|
-
if (typeof target.contains === "function" && target.contains(candidate)) return true;
|
|
663
|
-
} catch (e) {}
|
|
664
|
-
if (labelControlOf(candidate) === target) return true;
|
|
665
|
-
var cur = candidate;
|
|
666
|
-
var guard = 0;
|
|
667
|
-
while (cur && guard++ < 24) {
|
|
668
|
-
if (cur === target) return true;
|
|
669
|
-
var root = typeof cur.getRootNode === "function" ? cur.getRootNode() : null;
|
|
670
|
-
if (root && root.host) {
|
|
671
|
-
cur = root.host;
|
|
672
|
-
} else {
|
|
673
|
-
cur = cur.parentElement;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
return false;
|
|
677
|
-
}
|
|
678
|
-
function describeEl(el) {
|
|
679
|
-
if (!el) return "(unknown)";
|
|
680
|
-
var tag = el.tagName ? el.tagName.toLowerCase() : "element";
|
|
681
|
-
var idPart = el.id ? "#" + el.id : "";
|
|
682
|
-
var cls = typeof el.className === "string" ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0, 3).join(".") : "";
|
|
683
|
-
var clsPart = cls ? "." + cls : "";
|
|
684
|
-
var txt = (el.innerText || el.textContent || "").replace(/\\s+/g, " ").trim();
|
|
685
|
-
if (txt.length > 40) txt = txt.slice(0, 37) + "...";
|
|
686
|
-
return "<" + tag + idPart + clsPart + (txt ? ">" + txt + "</" + tag + ">" : ">");
|
|
687
|
-
}
|
|
688
|
-
function getHitTestBlocker(hit) {
|
|
689
|
-
var el = hit.el;
|
|
690
|
-
var rect = el.getBoundingClientRect();
|
|
691
|
-
var vw = (window.visualViewport && window.visualViewport.width) || window.innerWidth || document.documentElement.clientWidth || 0;
|
|
692
|
-
var vh = (window.visualViewport && window.visualViewport.height) || window.innerHeight || document.documentElement.clientHeight || 0;
|
|
693
|
-
var cx = rect.left + hit.offsetX + rect.width / 2;
|
|
694
|
-
var cy = rect.top + hit.offsetY + rect.height / 2;
|
|
695
|
-
if (vw > 0 && vh > 0 && (cx < 0 || cy < 0 || cx > vw || cy > vh)) {
|
|
696
|
-
return "outside viewport";
|
|
697
|
-
}
|
|
698
|
-
var topEl = deepElementFromPoint(document, cx, cy);
|
|
699
|
-
if (!topEl) return null;
|
|
700
|
-
if (isSameOrDescendant(el, topEl)) return null;
|
|
701
|
-
return describeEl(topEl);
|
|
702
|
-
}
|
|
703
|
-
function isHitTestClear(hit) {
|
|
704
|
-
var el = hit.el;
|
|
705
|
-
var rect = el.getBoundingClientRect();
|
|
706
|
-
var vw = (window.visualViewport && window.visualViewport.width) || window.innerWidth || document.documentElement.clientWidth || 0;
|
|
707
|
-
var vh = (window.visualViewport && window.visualViewport.height) || window.innerHeight || document.documentElement.clientHeight || 0;
|
|
708
|
-
var cx = rect.left + hit.offsetX + rect.width / 2;
|
|
709
|
-
var cy = rect.top + hit.offsetY + rect.height / 2;
|
|
710
|
-
if (vw > 0 && vh > 0 && (cx < 0 || cy < 0 || cx > vw || cy > vh)) {
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
var topEl = deepElementFromPoint(document, cx, cy);
|
|
714
|
-
if (!topEl) return true;
|
|
715
|
-
return isSameOrDescendant(el, topEl);
|
|
716
|
-
}
|
|
717
|
-
function ensureInViewport(hit) {
|
|
718
|
-
var el = hit.el;
|
|
719
|
-
var rect = el.getBoundingClientRect();
|
|
720
|
-
var vw = (window.visualViewport && window.visualViewport.width) || window.innerWidth || document.documentElement.clientWidth || 0;
|
|
721
|
-
var vh = (window.visualViewport && window.visualViewport.height) || window.innerHeight || document.documentElement.clientHeight || 0;
|
|
722
|
-
var cx = rect.left + hit.offsetX + rect.width / 2;
|
|
723
|
-
var cy = rect.top + hit.offsetY + rect.height / 2;
|
|
724
|
-
if (vw > 0 && vh > 0 && (cx < 1 || cy < 1 || cx > vw - 1 || cy > vh - 1)) {
|
|
725
|
-
if (typeof el.scrollIntoView === "function") {
|
|
726
|
-
try { el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }
|
|
727
|
-
catch (e) { try { el.scrollIntoView(true); } catch (e2) {} }
|
|
728
|
-
}
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
function scrollToUnobscure(hit) {
|
|
734
|
-
var el = hit.el;
|
|
735
|
-
if (typeof el.scrollIntoView !== "function") return false;
|
|
736
|
-
var blocks = ["center", "end", "start", "nearest"];
|
|
737
|
-
for (var i = 0; i < blocks.length; i++) {
|
|
738
|
-
try {
|
|
739
|
-
el.scrollIntoView({ block: blocks[i], inline: "center", behavior: "instant" });
|
|
740
|
-
} catch (e) {
|
|
741
|
-
try { el.scrollIntoView(true); } catch (e2) {}
|
|
742
|
-
}
|
|
743
|
-
if (isHitTestClear(hit)) return true;
|
|
744
|
-
}
|
|
745
|
-
return false;
|
|
746
|
-
}
|
|
747
|
-
function hasActiveAnimation(el) {
|
|
748
|
-
var cur = el;
|
|
749
|
-
var depth = 0;
|
|
750
|
-
while (cur && depth++ < 8) {
|
|
751
|
-
if (typeof cur.getAnimations === "function") {
|
|
752
|
-
try {
|
|
753
|
-
var anims = cur.getAnimations();
|
|
754
|
-
for (var i = 0; i < anims.length; i++) {
|
|
755
|
-
if (anims[i] && anims[i].playState === "running") return true;
|
|
756
|
-
}
|
|
757
|
-
} catch (e) {}
|
|
758
|
-
}
|
|
759
|
-
cur = cur.parentElement;
|
|
760
|
-
}
|
|
761
|
-
return false;
|
|
762
|
-
}
|
|
763
|
-
function isVisible(el, rect) {
|
|
764
|
-
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
765
|
-
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
766
|
-
var style = win.getComputedStyle(el);
|
|
767
|
-
if (style.display === "none" || style.visibility === "hidden" || parseFloat(style.opacity || "1") === 0) return false;
|
|
768
|
-
return true;
|
|
769
|
-
}
|
|
770
|
-
function toMatch(hit) {
|
|
771
|
-
var el = hit.el;
|
|
772
|
-
var rect = el.getBoundingClientRect();
|
|
773
|
-
var attrs = {};
|
|
774
|
-
if (el.attributes) {
|
|
775
|
-
for (var i = 0; i < el.attributes.length; i++) {
|
|
776
|
-
attrs[el.attributes[i].name] = el.attributes[i].value;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
var tag = el.tagName ? el.tagName.toLowerCase() : undefined;
|
|
780
|
-
var val = (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT")
|
|
781
|
-
? String(el.value ?? "")
|
|
782
|
-
: undefined;
|
|
783
|
-
var text = (el.innerText || el.textContent || "").trim() || undefined;
|
|
784
|
-
var normTextContent = (el.textContent || "").replace(/\\s+/g, " ").trim() || undefined;
|
|
785
|
-
var accName = getAccessibleName(el) || undefined;
|
|
786
|
-
var accDesc = getAccessibleDescription(el) || undefined;
|
|
787
|
-
var role = getImplicitRole(el) || undefined;
|
|
788
|
-
return {
|
|
789
|
-
id: el.getAttribute("data-testid") || el.getAttribute("testID") || undefined,
|
|
790
|
-
tag: tag,
|
|
791
|
-
role: role,
|
|
792
|
-
text: text,
|
|
793
|
-
textContent: normTextContent,
|
|
794
|
-
value: val,
|
|
795
|
-
accessibilityLabel: el.getAttribute("aria-label") || undefined,
|
|
796
|
-
accessibleName: accName,
|
|
797
|
-
accessibleDescription: accDesc,
|
|
798
|
-
rect: { x: rect.x + hit.offsetX, y: rect.y + hit.offsetY, width: rect.width, height: rect.height },
|
|
799
|
-
scrollX: window.scrollX || window.pageXOffset || 0,
|
|
800
|
-
scrollY: window.scrollY || window.pageYOffset || 0,
|
|
801
|
-
devicePixelRatio: window.devicePixelRatio || 1,
|
|
802
|
-
viewportWidth: (window.visualViewport && window.visualViewport.width) || window.innerWidth || document.documentElement.clientWidth || 0,
|
|
803
|
-
viewportHeight: (window.visualViewport && window.visualViewport.height) || window.innerHeight || document.documentElement.clientHeight || 0,
|
|
804
|
-
visible: isVisible(el, rect),
|
|
805
|
-
enabled: !el.hasAttribute("disabled") && el.getAttribute("aria-disabled") !== "true",
|
|
806
|
-
clickable: isClickable(el),
|
|
807
|
-
focused: document.activeElement === el,
|
|
808
|
-
attributes: attrs,
|
|
809
|
-
inShadowDom: hit.inShadow || undefined,
|
|
810
|
-
inIframe: hit.inIframe || undefined
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
`;
|
|
814
|
-
function buildDomQueryScript(selector) {
|
|
815
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
816
|
-
return `(function(sel) {
|
|
817
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
818
|
-
return findAcrossRoots(sel).map(toMatch);
|
|
819
|
-
})(${serialized})`;
|
|
820
|
-
}
|
|
821
|
-
function buildDomScrollIntoViewScript(selector) {
|
|
822
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
823
|
-
return `(function(sel) {
|
|
824
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
825
|
-
var hits = findAcrossRoots(sel);
|
|
826
|
-
if (hits.length === 0) return null;
|
|
827
|
-
var hit = hits[hits.length - 1];
|
|
828
|
-
if (typeof hit.el.scrollIntoView === "function") {
|
|
829
|
-
try { hit.el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }
|
|
830
|
-
catch (e) { try { hit.el.scrollIntoView(true); } catch (e2) {} }
|
|
831
|
-
}
|
|
832
|
-
return toMatch(hit);
|
|
833
|
-
})(${serialized})`;
|
|
834
|
-
}
|
|
835
|
-
function buildDomTapScript(selector) {
|
|
836
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
837
|
-
return `(function(sel) {
|
|
838
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
839
|
-
var hits = findAcrossRoots(sel);
|
|
840
|
-
if (hits.length === 0) return false;
|
|
841
|
-
var hit = hits[hits.length - 1];
|
|
842
|
-
var el = hit.el;
|
|
843
|
-
if (typeof el.scrollIntoView === "function") {
|
|
844
|
-
try { el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); } catch (e) {}
|
|
845
|
-
}
|
|
846
|
-
var rect = el.getBoundingClientRect();
|
|
847
|
-
var cx = rect.left + rect.width / 2;
|
|
848
|
-
var cy = rect.top + rect.height / 2;
|
|
849
|
-
var init = { bubbles: true, cancelable: true, composed: true, clientX: cx, clientY: cy };
|
|
850
|
-
try { el.dispatchEvent(new PointerEvent("pointerdown", init)); } catch (e) {}
|
|
851
|
-
try { el.dispatchEvent(new MouseEvent("mousedown", init)); } catch (e) {}
|
|
852
|
-
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
853
|
-
try { el.dispatchEvent(new PointerEvent("pointerup", init)); } catch (e) {}
|
|
854
|
-
try { el.dispatchEvent(new MouseEvent("mouseup", init)); } catch (e) {}
|
|
855
|
-
if (typeof el.click === "function") { el.click(); }
|
|
856
|
-
else { el.dispatchEvent(new MouseEvent("click", init)); }
|
|
857
|
-
return true;
|
|
858
|
-
})(${serialized})`;
|
|
859
|
-
}
|
|
860
|
-
function defaultActionStableFrames() {
|
|
861
|
-
const envVal = process.env["SPANA_ACTION_STABLE_FRAMES"];
|
|
862
|
-
if (envVal !== void 0) {
|
|
863
|
-
const parsed = Number.parseInt(envVal, 10);
|
|
864
|
-
if (Number.isFinite(parsed) && parsed >= 0) return parsed;
|
|
865
|
-
}
|
|
866
|
-
return 2;
|
|
867
|
-
}
|
|
868
|
-
function buildDomWaitForSelectorScript(selector, opts = {}) {
|
|
869
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
870
|
-
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
871
|
-
const forAction = Boolean(opts.forAction);
|
|
872
|
-
const failFastWhenIdle = Boolean(opts.failFastWhenIdle);
|
|
873
|
-
const idleQuietMs = Math.max(50, Math.round(opts.idleQuietMs ?? 250));
|
|
874
|
-
const stableFrames = opts.stableFrames !== void 0 ? Math.max(0, Math.round(opts.stableFrames)) : forAction ? defaultActionStableFrames() : 0;
|
|
875
|
-
const checkHitTest = opts.checkHitTest !== void 0 ? Boolean(opts.checkHitTest) : forAction;
|
|
876
|
-
const waitForAppReady = opts.waitForAppReady !== void 0 ? Boolean(opts.waitForAppReady) : true;
|
|
877
|
-
return `(function(sel, timeoutMs, forAction, failFastWhenIdle, idleQuietMs, reqStableFrames, checkHitTest, waitForAppReady) {
|
|
878
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
879
|
-
var instantAnim = Boolean(typeof document !== "undefined" && document.getElementById && document.getElementById("__spana_instant_anim"));
|
|
880
|
-
var explicitStableFrames = instantAnim ? 0 : reqStableFrames;
|
|
881
|
-
|
|
882
|
-
function findCandidates() {
|
|
883
|
-
if (waitForAppReady && !isAppReady()) return null;
|
|
884
|
-
var rawHits = findAcrossRoots(sel);
|
|
885
|
-
var ready = [];
|
|
886
|
-
for (var i = 0; i < rawHits.length; i++) {
|
|
887
|
-
var h = rawHits[i];
|
|
888
|
-
var m = toMatch(h);
|
|
889
|
-
if (!m.visible) continue;
|
|
890
|
-
if (forAction && !m.enabled) continue;
|
|
891
|
-
ready.push({ hit: h, match: m });
|
|
892
|
-
}
|
|
893
|
-
return ready.length > 0 ? ready : null;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
function checkActionableNow() {
|
|
897
|
-
var ready = findCandidates();
|
|
898
|
-
if (!ready) return null;
|
|
899
|
-
if (!forAction) return ready.map(function(r) { return r.match; });
|
|
900
|
-
var target = ready[ready.length - 1];
|
|
901
|
-
var didScroll = ensureInViewport(target.hit);
|
|
902
|
-
if (checkHitTest && !isHitTestClear(target.hit)) {
|
|
903
|
-
if (scrollToUnobscure(target.hit)) {
|
|
904
|
-
didScroll = true;
|
|
905
|
-
}
|
|
906
|
-
if (!isHitTestClear(target.hit)) return null;
|
|
907
|
-
}
|
|
908
|
-
var updated = toMatch(target.hit);
|
|
909
|
-
if (!updated.visible || !updated.enabled) return null;
|
|
910
|
-
return { hits: ready, target: target, match: updated, didScroll: didScroll };
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
function neededStableFrames(candidate) {
|
|
914
|
-
if (!forAction || typeof requestAnimationFrame !== "function") return 0;
|
|
915
|
-
if (explicitStableFrames >= 0) return explicitStableFrames;
|
|
916
|
-
// Smart auto stability: 0 rAF wait on static, unobstructed elements;
|
|
917
|
-
// wait 2 frames if CSS animations/transitions are running or 1 frame right after scroll.
|
|
918
|
-
if (hasActiveAnimation(candidate.target.hit.el)) return 2;
|
|
919
|
-
if (candidate.didScroll) return 1;
|
|
920
|
-
return 0;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// Fast synchronous exit when target is already actionable and needs 0 stability frames
|
|
924
|
-
var imm = checkActionableNow();
|
|
925
|
-
if (imm) {
|
|
926
|
-
if (!forAction) return imm;
|
|
927
|
-
if (neededStableFrames(imm) <= 0) return [imm.match];
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
return new Promise(function(resolve) {
|
|
931
|
-
var done = false;
|
|
932
|
-
var observer = null;
|
|
933
|
-
var timeoutTimer = null;
|
|
934
|
-
var fallbackInterval = null;
|
|
935
|
-
var idleTimer = null;
|
|
936
|
-
var rafId = null;
|
|
937
|
-
var checkingStability = false;
|
|
938
|
-
|
|
939
|
-
function finish(result) {
|
|
940
|
-
if (done) return;
|
|
941
|
-
done = true;
|
|
942
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
943
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
944
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
945
|
-
if (idleTimer) clearTimeout(idleTimer);
|
|
946
|
-
if (rafId !== null && typeof cancelAnimationFrame === "function") {
|
|
947
|
-
try { cancelAnimationFrame(rafId); } catch (e) {}
|
|
948
|
-
}
|
|
949
|
-
resolve(result);
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
function armIdleTimer() {
|
|
953
|
-
if (!failFastWhenIdle) return;
|
|
954
|
-
if (idleTimer) clearTimeout(idleTimer);
|
|
955
|
-
idleTimer = setTimeout(function() {
|
|
956
|
-
if (document.readyState === "complete" && (!waitForAppReady || isAppReady())) {
|
|
957
|
-
var hit = checkActionableNow();
|
|
958
|
-
if (hit) {
|
|
959
|
-
finish(forAction ? [hit.match] : hit);
|
|
960
|
-
} else {
|
|
961
|
-
finish([]);
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
armIdleTimer();
|
|
965
|
-
}
|
|
966
|
-
}, idleQuietMs);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
function verifyStability(candidate) {
|
|
970
|
-
if (done || checkingStability) return;
|
|
971
|
-
var framesToWait = neededStableFrames(candidate);
|
|
972
|
-
if (!forAction || framesToWait <= 0 || typeof requestAnimationFrame !== "function") {
|
|
973
|
-
finish(forAction ? [candidate.match] : candidate);
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
checkingStability = true;
|
|
977
|
-
var el = candidate.target.hit.el;
|
|
978
|
-
var lastRect = candidate.match.rect;
|
|
979
|
-
var remainingFrames = framesToWait;
|
|
980
|
-
|
|
981
|
-
function step() {
|
|
982
|
-
if (done) return;
|
|
983
|
-
if (!el.isConnected) {
|
|
984
|
-
checkingStability = false;
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
if (checkHitTest && !isHitTestClear(candidate.target.hit)) {
|
|
988
|
-
checkingStability = false;
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
var cur = toMatch(candidate.target.hit);
|
|
992
|
-
if (!cur.visible || !cur.enabled) {
|
|
993
|
-
checkingStability = false;
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
|
-
var dx = Math.abs(cur.rect.x - lastRect.x);
|
|
997
|
-
var dy = Math.abs(cur.rect.y - lastRect.y);
|
|
998
|
-
var dw = Math.abs(cur.rect.width - lastRect.width);
|
|
999
|
-
var dh = Math.abs(cur.rect.height - lastRect.height);
|
|
1000
|
-
if (dx <= 1 && dy <= 1 && dw <= 1 && dh <= 1) {
|
|
1001
|
-
remainingFrames -= 1;
|
|
1002
|
-
if (remainingFrames <= 0) {
|
|
1003
|
-
finish([cur]);
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
} else {
|
|
1007
|
-
remainingFrames = framesToWait;
|
|
1008
|
-
lastRect = cur.rect;
|
|
1009
|
-
}
|
|
1010
|
-
rafId = requestAnimationFrame(step);
|
|
1011
|
-
}
|
|
1012
|
-
rafId = requestAnimationFrame(step);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
function attempt() {
|
|
1016
|
-
if (done || checkingStability) return;
|
|
1017
|
-
var hit = checkActionableNow();
|
|
1018
|
-
if (hit) {
|
|
1019
|
-
if (forAction) {
|
|
1020
|
-
verifyStability(hit);
|
|
1021
|
-
} else {
|
|
1022
|
-
finish(hit);
|
|
1023
|
-
}
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
armIdleTimer();
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
var scheduled = false;
|
|
1030
|
-
function scheduleAttempt() {
|
|
1031
|
-
if (done || scheduled || checkingStability) return;
|
|
1032
|
-
scheduled = true;
|
|
1033
|
-
Promise.resolve().then(function() {
|
|
1034
|
-
scheduled = false;
|
|
1035
|
-
attempt();
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
timeoutTimer = setTimeout(function() {
|
|
1040
|
-
var finalHit = checkActionableNow();
|
|
1041
|
-
finish(finalHit ? (forAction ? [finalHit.match] : finalHit) : []);
|
|
1042
|
-
}, timeoutMs);
|
|
1043
|
-
|
|
1044
|
-
fallbackInterval = setInterval(attempt, forAction ? 40 : 120);
|
|
1045
|
-
|
|
1046
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1047
|
-
var root = document.documentElement || document.body || document;
|
|
1048
|
-
if (root) {
|
|
1049
|
-
observer = new MutationObserver(scheduleAttempt);
|
|
1050
|
-
observer.observe(root, {
|
|
1051
|
-
childList: true,
|
|
1052
|
-
subtree: true,
|
|
1053
|
-
attributes: true,
|
|
1054
|
-
characterData: true
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
attempt();
|
|
1060
|
-
});
|
|
1061
|
-
})(${serialized}, ${timeoutMs}, ${forAction}, ${failFastWhenIdle}, ${idleQuietMs}, ${stableFrames}, ${checkHitTest}, ${waitForAppReady})`;
|
|
1062
|
-
}
|
|
1063
|
-
function buildDomWaitForHiddenScript(selector, opts = {}) {
|
|
1064
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
1065
|
-
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
1066
|
-
return `(function(sel, timeoutMs) {
|
|
1067
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1068
|
-
function isHiddenNow() {
|
|
1069
|
-
var hits = findAcrossRoots(sel);
|
|
1070
|
-
for (var i = 0; i < hits.length; i++) {
|
|
1071
|
-
if (toMatch(hits[i]).visible) return false;
|
|
1072
|
-
}
|
|
1073
|
-
return true;
|
|
1074
|
-
}
|
|
1075
|
-
if (isHiddenNow()) return true;
|
|
1076
|
-
|
|
1077
|
-
return new Promise(function(resolve) {
|
|
1078
|
-
var done = false;
|
|
1079
|
-
var observer = null;
|
|
1080
|
-
var timeoutTimer = null;
|
|
1081
|
-
var fallbackInterval = null;
|
|
1082
|
-
|
|
1083
|
-
function finish(val) {
|
|
1084
|
-
if (done) return;
|
|
1085
|
-
done = true;
|
|
1086
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1087
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1088
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1089
|
-
resolve(val);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
function onChange() {
|
|
1093
|
-
if (isHiddenNow()) finish(true);
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
timeoutTimer = setTimeout(function() {
|
|
1097
|
-
finish(isHiddenNow());
|
|
1098
|
-
}, timeoutMs);
|
|
1099
|
-
|
|
1100
|
-
fallbackInterval = setInterval(onChange, 120);
|
|
1101
|
-
|
|
1102
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1103
|
-
var root = document.documentElement || document.body || document;
|
|
1104
|
-
if (root) {
|
|
1105
|
-
observer = new MutationObserver(onChange);
|
|
1106
|
-
observer.observe(root, {
|
|
1107
|
-
childList: true,
|
|
1108
|
-
subtree: true,
|
|
1109
|
-
attributes: true,
|
|
1110
|
-
characterData: true
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
})(${serialized}, ${timeoutMs})`;
|
|
1116
|
-
}
|
|
1117
|
-
function buildDomWaitForMatchScript(selector, opts) {
|
|
1118
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
1119
|
-
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
1120
|
-
const kind = JSON.stringify(opts.kind);
|
|
1121
|
-
const expected = JSON.stringify(opts.expected ?? null);
|
|
1122
|
-
const expectedCount = JSON.stringify(opts.expectedCount ?? null);
|
|
1123
|
-
const attributeName = JSON.stringify(opts.attributeName ?? null);
|
|
1124
|
-
const patternSource = JSON.stringify(opts.patternSource ?? null);
|
|
1125
|
-
const patternFlags = JSON.stringify(opts.patternFlags ?? "");
|
|
1126
|
-
const negate = Boolean(opts.negate);
|
|
1127
|
-
return `(function(sel, timeoutMs, kind, expected, expectedCount, attributeName, patternSource, patternFlags, negate) {
|
|
1128
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1129
|
-
var lastActual = undefined;
|
|
1130
|
-
var regex = patternSource !== null ? new RegExp(patternSource, patternFlags) : null;
|
|
1131
|
-
|
|
1132
|
-
function evaluateMatch() {
|
|
1133
|
-
if (kind === "url") {
|
|
1134
|
-
var href = String(window.location.href || "");
|
|
1135
|
-
lastActual = href;
|
|
1136
|
-
var urlOk = regex
|
|
1137
|
-
? regex.test(href)
|
|
1138
|
-
: (expected !== null && (href === expected || href.indexOf(String(expected)) !== -1));
|
|
1139
|
-
if (negate ? !urlOk : urlOk) return { matched: true, actual: href };
|
|
1140
|
-
return null;
|
|
1141
|
-
}
|
|
1142
|
-
var hits = findAcrossRoots(sel);
|
|
1143
|
-
if (kind === "count") {
|
|
1144
|
-
var visibleCount = 0;
|
|
1145
|
-
for (var ci = 0; ci < hits.length; ci++) {
|
|
1146
|
-
if (toMatch(hits[ci]).visible) visibleCount += 1;
|
|
1147
|
-
}
|
|
1148
|
-
lastActual = String(visibleCount);
|
|
1149
|
-
var countOk = visibleCount === expectedCount;
|
|
1150
|
-
if (negate ? !countOk : countOk) return { matched: true, actual: String(visibleCount) };
|
|
1151
|
-
return null;
|
|
1152
|
-
}
|
|
1153
|
-
var anyVisible = false;
|
|
1154
|
-
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1155
|
-
var m = toMatch(hits[i]);
|
|
1156
|
-
if (!m.visible) continue;
|
|
1157
|
-
anyVisible = true;
|
|
1158
|
-
var matched = false;
|
|
1159
|
-
var actualVal = undefined;
|
|
1160
|
-
if (kind === "focused") {
|
|
1161
|
-
var isFoc = Boolean(m.focused);
|
|
1162
|
-
actualVal = isFoc ? "focused" : "not focused";
|
|
1163
|
-
matched = isFoc;
|
|
1164
|
-
} else if (kind === "accessibleName") {
|
|
1165
|
-
var acc = m.accessibleName || "";
|
|
1166
|
-
actualVal = acc;
|
|
1167
|
-
matched = regex ? regex.test(acc) : (expected === null ? acc.length > 0 : acc.trim() === String(expected).trim());
|
|
1168
|
-
} else if (kind === "accessibleDescription") {
|
|
1169
|
-
var accD = m.accessibleDescription || "";
|
|
1170
|
-
actualVal = accD;
|
|
1171
|
-
matched = regex ? regex.test(accD) : (expected === null ? accD.length > 0 : accD.trim() === String(expected).trim());
|
|
1172
|
-
} else if (kind === "text") {
|
|
1173
|
-
var normTxt = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1174
|
-
actualVal = normTxt;
|
|
1175
|
-
matched = normTxt === (expected !== null ? String(expected).replace(/\\s+/g, " ").trim() : expected);
|
|
1176
|
-
} else if (kind === "containsText") {
|
|
1177
|
-
var actual = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1178
|
-
actualVal = actual;
|
|
1179
|
-
matched = expected !== null && actual.toLowerCase().indexOf(String(expected).replace(/\\s+/g, " ").trim().toLowerCase()) !== -1;
|
|
1180
|
-
} else if (kind === "matchesText") {
|
|
1181
|
-
var actualRe = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1182
|
-
actualVal = actualRe;
|
|
1183
|
-
matched = Boolean(regex && regex.test(actualRe));
|
|
1184
|
-
} else if (kind === "value") {
|
|
1185
|
-
var val = m.value !== undefined ? m.value : "";
|
|
1186
|
-
actualVal = val;
|
|
1187
|
-
matched = val === expected;
|
|
1188
|
-
} else if (kind === "attribute" && attributeName !== null) {
|
|
1189
|
-
var attrVal = m.attributes ? m.attributes[attributeName] : undefined;
|
|
1190
|
-
actualVal = attrVal;
|
|
1191
|
-
matched = expected === null ? attrVal !== undefined : attrVal === expected;
|
|
1192
|
-
} else if (kind === "accessibilityLabel") {
|
|
1193
|
-
var lbl = m.accessibilityLabel;
|
|
1194
|
-
actualVal = lbl;
|
|
1195
|
-
matched = expected === null ? (lbl !== undefined && lbl.length > 0) : lbl === expected;
|
|
1196
|
-
}
|
|
1197
|
-
lastActual = actualVal;
|
|
1198
|
-
if (negate ? !matched : matched) return { matched: true, actual: actualVal };
|
|
1199
|
-
}
|
|
1200
|
-
return null;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
var immediate = evaluateMatch();
|
|
1204
|
-
if (immediate) return immediate;
|
|
1205
|
-
|
|
1206
|
-
return new Promise(function(resolve) {
|
|
1207
|
-
var done = false;
|
|
1208
|
-
var observer = null;
|
|
1209
|
-
var timeoutTimer = null;
|
|
1210
|
-
var fallbackInterval = null;
|
|
1211
|
-
var scheduled = false;
|
|
1212
|
-
|
|
1213
|
-
function finish(res) {
|
|
1214
|
-
if (done) return;
|
|
1215
|
-
done = true;
|
|
1216
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1217
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1218
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1219
|
-
if (typeof document !== "undefined") {
|
|
1220
|
-
document.removeEventListener("input", onChange, true);
|
|
1221
|
-
document.removeEventListener("change", onChange, true);
|
|
1222
|
-
document.removeEventListener("focusin", onChange, true);
|
|
1223
|
-
}
|
|
1224
|
-
if (typeof window !== "undefined") {
|
|
1225
|
-
window.removeEventListener("popstate", onChange);
|
|
1226
|
-
window.removeEventListener("hashchange", onChange);
|
|
1227
|
-
}
|
|
1228
|
-
resolve(res);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
function onChange() {
|
|
1232
|
-
if (done || scheduled) return;
|
|
1233
|
-
scheduled = true;
|
|
1234
|
-
Promise.resolve().then(function() {
|
|
1235
|
-
scheduled = false;
|
|
1236
|
-
if (done) return;
|
|
1237
|
-
var res = evaluateMatch();
|
|
1238
|
-
if (res) finish(res);
|
|
1239
|
-
});
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
timeoutTimer = setTimeout(function() {
|
|
1243
|
-
var finalRes = evaluateMatch();
|
|
1244
|
-
finish(finalRes || { matched: false, actual: lastActual });
|
|
1245
|
-
}, timeoutMs);
|
|
1246
|
-
|
|
1247
|
-
fallbackInterval = setInterval(onChange, kind === "url" ? 50 : 100);
|
|
1248
|
-
|
|
1249
|
-
if (typeof document !== "undefined") {
|
|
1250
|
-
document.addEventListener("input", onChange, true);
|
|
1251
|
-
document.addEventListener("change", onChange, true);
|
|
1252
|
-
document.addEventListener("focusin", onChange, true);
|
|
1253
|
-
}
|
|
1254
|
-
if (typeof window !== "undefined") {
|
|
1255
|
-
window.addEventListener("popstate", onChange);
|
|
1256
|
-
window.addEventListener("hashchange", onChange);
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1260
|
-
var root = document.documentElement || document.body || document;
|
|
1261
|
-
if (root) {
|
|
1262
|
-
observer = new MutationObserver(onChange);
|
|
1263
|
-
observer.observe(root, {
|
|
1264
|
-
childList: true,
|
|
1265
|
-
subtree: true,
|
|
1266
|
-
attributes: true,
|
|
1267
|
-
characterData: true
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
});
|
|
1272
|
-
})(${serialized}, ${timeoutMs}, ${kind}, ${expected}, ${expectedCount}, ${attributeName}, ${patternSource}, ${patternFlags}, ${negate})`;
|
|
1273
|
-
}
|
|
1274
|
-
function buildDomFillScript(selector, value, opts = {}) {
|
|
1275
|
-
const serializedSel = JSON.stringify(serializeSelectorForDom(selector));
|
|
1276
|
-
const serializedVal = JSON.stringify(value);
|
|
1277
|
-
const timeoutMs = Math.max(10, Math.round(opts.timeoutMs ?? 5e3));
|
|
1278
|
-
const checkHitTest = opts.checkHitTest !== void 0 ? Boolean(opts.checkHitTest) : true;
|
|
1279
|
-
return `(function(sel, val, timeoutMs, checkHitTest) {
|
|
1280
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1281
|
-
function writeValue(el) {
|
|
1282
|
-
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
1283
|
-
var tag = el.tagName;
|
|
1284
|
-
// Rich-text contenteditable editors (TipTap/ProseMirror/Lexical/Slate) require native keyboard input;
|
|
1285
|
-
// return false so coordinator falls back cleanly to real tap + SelectAll + Input.insertText.
|
|
1286
|
-
if (el.isContentEditable) return false;
|
|
1287
|
-
if (tag === "INPUT" || tag === "TEXTAREA") {
|
|
1288
|
-
var proto = tag === "TEXTAREA"
|
|
1289
|
-
? (window.HTMLTextAreaElement && window.HTMLTextAreaElement.prototype)
|
|
1290
|
-
: (window.HTMLInputElement && window.HTMLInputElement.prototype);
|
|
1291
|
-
var desc = proto ? Object.getOwnPropertyDescriptor(proto, "value") : null;
|
|
1292
|
-
if (desc && typeof desc.set === "function") {
|
|
1293
|
-
desc.set.call(el, val);
|
|
1294
|
-
} else {
|
|
1295
|
-
el.value = val;
|
|
1296
|
-
}
|
|
1297
|
-
// Reset React's internal _valueTracker so synthetic controlled onChange always fires
|
|
1298
|
-
if (el._valueTracker && typeof el._valueTracker.setValue === "function") {
|
|
1299
|
-
try { el._valueTracker.setValue(val === "" ? " " : ""); } catch (e) {}
|
|
1300
|
-
}
|
|
1301
|
-
} else if (tag === "SELECT") {
|
|
1302
|
-
el.value = val;
|
|
1303
|
-
} else {
|
|
1304
|
-
el.value = val;
|
|
1305
|
-
}
|
|
1306
|
-
try { el.dispatchEvent(new InputEvent("input", { bubbles: true, cancelable: true, data: val, inputType: "insertText" })); }
|
|
1307
|
-
catch (e) { el.dispatchEvent(new Event("input", { bubbles: true, cancelable: true })); }
|
|
1308
|
-
el.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
|
|
1309
|
-
return true;
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
function findEditableNow() {
|
|
1313
|
-
if (!isAppReady()) return null;
|
|
1314
|
-
var hits = findAcrossRoots(sel);
|
|
1315
|
-
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1316
|
-
var h = hits[i];
|
|
1317
|
-
var m = toMatch(h);
|
|
1318
|
-
if (!m.visible || !m.enabled) continue;
|
|
1319
|
-
ensureInViewport(h);
|
|
1320
|
-
if (checkHitTest && !isHitTestClear(h)) {
|
|
1321
|
-
scrollToUnobscure(h);
|
|
1322
|
-
if (!isHitTestClear(h)) continue;
|
|
1323
|
-
}
|
|
1324
|
-
return h.el;
|
|
1325
|
-
}
|
|
1326
|
-
return null;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
function verifyAndRetryFill(attemptsLeft) {
|
|
1330
|
-
var el = findEditableNow();
|
|
1331
|
-
if (!el) return Promise.resolve(false);
|
|
1332
|
-
if (el.isContentEditable) return Promise.resolve(false);
|
|
1333
|
-
if (!writeValue(el)) return Promise.resolve(false);
|
|
1334
|
-
return new Promise(function(resolve) {
|
|
1335
|
-
// Let React/Vue microtask + single paint flush settle, then verify value survived remount/re-render
|
|
1336
|
-
setTimeout(function() {
|
|
1337
|
-
var latest = findEditableNow() || el;
|
|
1338
|
-
if (latest && latest.isConnected && String(latest.value == null ? "" : latest.value) === val) {
|
|
1339
|
-
resolve(true);
|
|
1340
|
-
return;
|
|
1341
|
-
}
|
|
1342
|
-
if (attemptsLeft > 1) {
|
|
1343
|
-
verifyAndRetryFill(attemptsLeft - 1).then(resolve);
|
|
1344
|
-
} else {
|
|
1345
|
-
resolve(false);
|
|
1346
|
-
}
|
|
1347
|
-
}, 12);
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
var immEl = findEditableNow();
|
|
1352
|
-
if (immEl) {
|
|
1353
|
-
if (immEl.isContentEditable) return false;
|
|
1354
|
-
return verifyAndRetryFill(3);
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
return new Promise(function(resolve) {
|
|
1358
|
-
var done = false;
|
|
1359
|
-
var observer = null;
|
|
1360
|
-
var timeoutTimer = null;
|
|
1361
|
-
var fallbackInterval = null;
|
|
1362
|
-
var scheduled = false;
|
|
1363
|
-
var filling = false;
|
|
1364
|
-
|
|
1365
|
-
function finish(ok) {
|
|
1366
|
-
if (done) return;
|
|
1367
|
-
done = true;
|
|
1368
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1369
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1370
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1371
|
-
resolve(ok);
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
function onChange() {
|
|
1375
|
-
if (done || scheduled || filling) return;
|
|
1376
|
-
scheduled = true;
|
|
1377
|
-
Promise.resolve().then(function() {
|
|
1378
|
-
scheduled = false;
|
|
1379
|
-
if (done || filling) return;
|
|
1380
|
-
var target = findEditableNow();
|
|
1381
|
-
if (!target) return;
|
|
1382
|
-
if (target.isContentEditable) { finish(false); return; }
|
|
1383
|
-
filling = true;
|
|
1384
|
-
verifyAndRetryFill(3).then(function(ok) { finish(ok); });
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
timeoutTimer = setTimeout(function() {
|
|
1389
|
-
if (filling) return;
|
|
1390
|
-
var target = findEditableNow();
|
|
1391
|
-
if (!target || target.isContentEditable) { finish(false); return; }
|
|
1392
|
-
filling = true;
|
|
1393
|
-
verifyAndRetryFill(2).then(function(ok) { finish(ok); });
|
|
1394
|
-
}, timeoutMs);
|
|
1395
|
-
|
|
1396
|
-
fallbackInterval = setInterval(onChange, 40);
|
|
1397
|
-
|
|
1398
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1399
|
-
var root = document.documentElement || document.body || document;
|
|
1400
|
-
if (root) {
|
|
1401
|
-
observer = new MutationObserver(onChange);
|
|
1402
|
-
observer.observe(root, {
|
|
1403
|
-
childList: true,
|
|
1404
|
-
subtree: true,
|
|
1405
|
-
attributes: true,
|
|
1406
|
-
characterData: true
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
});
|
|
1411
|
-
})(${serializedSel}, ${serializedVal}, ${timeoutMs}, ${checkHitTest})`;
|
|
1412
|
-
}
|
|
1413
|
-
var SPANA_RUNTIME_MISSING_SENTINEL = "__SPANA_RT_MISSING__";
|
|
1414
|
-
var SPANA_INJECTED_RUNTIME_SCRIPT = `(function() {
|
|
1415
|
-
if (typeof window === "undefined" || window.__spanaRt) return true;
|
|
1416
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1417
|
-
|
|
1418
|
-
function query(sel) {
|
|
1419
|
-
return findAcrossRoots(sel).map(toMatch);
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
function scrollIntoView(sel) {
|
|
1423
|
-
var hits = findAcrossRoots(sel);
|
|
1424
|
-
if (hits.length === 0) return null;
|
|
1425
|
-
var hit = hits[hits.length - 1];
|
|
1426
|
-
if (typeof hit.el.scrollIntoView === "function") {
|
|
1427
|
-
try { hit.el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }
|
|
1428
|
-
catch (e) { try { hit.el.scrollIntoView(true); } catch (e2) {} }
|
|
1429
|
-
}
|
|
1430
|
-
return toMatch(hit);
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
function tap(sel) {
|
|
1434
|
-
var hits = findAcrossRoots(sel);
|
|
1435
|
-
if (hits.length === 0) return false;
|
|
1436
|
-
var hit = hits[hits.length - 1];
|
|
1437
|
-
var el = hit.el;
|
|
1438
|
-
if (typeof el.scrollIntoView === "function") {
|
|
1439
|
-
try { el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); } catch (e) {}
|
|
1440
|
-
}
|
|
1441
|
-
var rect = el.getBoundingClientRect();
|
|
1442
|
-
var cx = rect.left + rect.width / 2;
|
|
1443
|
-
var cy = rect.top + rect.height / 2;
|
|
1444
|
-
var init = { bubbles: true, cancelable: true, composed: true, clientX: cx, clientY: cy };
|
|
1445
|
-
try { el.dispatchEvent(new PointerEvent("pointerdown", init)); } catch (e) {}
|
|
1446
|
-
try { el.dispatchEvent(new MouseEvent("mousedown", init)); } catch (e) {}
|
|
1447
|
-
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
1448
|
-
try { el.dispatchEvent(new PointerEvent("pointerup", init)); } catch (e) {}
|
|
1449
|
-
try { el.dispatchEvent(new MouseEvent("mouseup", init)); } catch (e) {}
|
|
1450
|
-
if (typeof el.click === "function") { el.click(); }
|
|
1451
|
-
else { el.dispatchEvent(new MouseEvent("click", init)); }
|
|
1452
|
-
return true;
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
function waitForSelector(sel, opts) {
|
|
1456
|
-
opts = opts || {};
|
|
1457
|
-
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1458
|
-
var forAction = Boolean(opts.forAction);
|
|
1459
|
-
var failFastWhenIdle = Boolean(opts.failFastWhenIdle);
|
|
1460
|
-
var idleQuietMs = Math.max(50, Math.round(opts.idleQuietMs != null ? opts.idleQuietMs : 250));
|
|
1461
|
-
var reqStableFrames = opts.stableFrames !== undefined ? Math.max(0, Math.round(opts.stableFrames)) : (forAction ? 2 : 0);
|
|
1462
|
-
var checkHitTest = opts.checkHitTest !== undefined ? Boolean(opts.checkHitTest) : forAction;
|
|
1463
|
-
var waitForAppReady = opts.waitForAppReady !== undefined ? Boolean(opts.waitForAppReady) : true;
|
|
1464
|
-
var instantAnim = Boolean(typeof document !== "undefined" && document.getElementById && document.getElementById("__spana_instant_anim"));
|
|
1465
|
-
var explicitStableFrames = instantAnim ? 0 : reqStableFrames;
|
|
1466
|
-
|
|
1467
|
-
function findCandidates() {
|
|
1468
|
-
if (waitForAppReady && !isAppReady()) return null;
|
|
1469
|
-
var rawHits = findAcrossRoots(sel);
|
|
1470
|
-
var ready = [];
|
|
1471
|
-
for (var i = 0; i < rawHits.length; i++) {
|
|
1472
|
-
var h = rawHits[i];
|
|
1473
|
-
var m = toMatch(h);
|
|
1474
|
-
if (!m.visible) continue;
|
|
1475
|
-
if (forAction && !m.enabled) continue;
|
|
1476
|
-
ready.push({ hit: h, match: m });
|
|
1477
|
-
}
|
|
1478
|
-
return ready.length > 0 ? ready : null;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
function checkActionableNow() {
|
|
1482
|
-
var ready = findCandidates();
|
|
1483
|
-
if (!ready) return null;
|
|
1484
|
-
if (!forAction) return ready.map(function(r) { return r.match; });
|
|
1485
|
-
var target = ready[ready.length - 1];
|
|
1486
|
-
var didScroll = ensureInViewport(target.hit);
|
|
1487
|
-
if (checkHitTest && !isHitTestClear(target.hit)) {
|
|
1488
|
-
if (scrollToUnobscure(target.hit)) {
|
|
1489
|
-
didScroll = true;
|
|
1490
|
-
}
|
|
1491
|
-
if (!isHitTestClear(target.hit)) return null;
|
|
1492
|
-
}
|
|
1493
|
-
var updated = toMatch(target.hit);
|
|
1494
|
-
if (!updated.visible || !updated.enabled) return null;
|
|
1495
|
-
return { hits: ready, target: target, match: updated, didScroll: didScroll };
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
function neededStableFrames(candidate) {
|
|
1499
|
-
if (!forAction || typeof requestAnimationFrame !== "function") return 0;
|
|
1500
|
-
if (explicitStableFrames >= 0) return explicitStableFrames;
|
|
1501
|
-
if (hasActiveAnimation(candidate.target.hit.el)) return 2;
|
|
1502
|
-
if (candidate.didScroll) return 1;
|
|
1503
|
-
return 0;
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
var imm = checkActionableNow();
|
|
1507
|
-
if (imm) {
|
|
1508
|
-
if (!forAction) return imm;
|
|
1509
|
-
if (neededStableFrames(imm) <= 0) return [imm.match];
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
return new Promise(function(resolve) {
|
|
1513
|
-
var done = false;
|
|
1514
|
-
var observer = null;
|
|
1515
|
-
var timeoutTimer = null;
|
|
1516
|
-
var fallbackInterval = null;
|
|
1517
|
-
var idleTimer = null;
|
|
1518
|
-
var rafId = null;
|
|
1519
|
-
var checkingStability = false;
|
|
1520
|
-
|
|
1521
|
-
function finish(result) {
|
|
1522
|
-
if (done) return;
|
|
1523
|
-
done = true;
|
|
1524
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1525
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1526
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1527
|
-
if (idleTimer) clearTimeout(idleTimer);
|
|
1528
|
-
if (rafId !== null && typeof cancelAnimationFrame === "function") {
|
|
1529
|
-
try { cancelAnimationFrame(rafId); } catch (e) {}
|
|
1530
|
-
}
|
|
1531
|
-
resolve(result);
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
function armIdleTimer() {
|
|
1535
|
-
if (!failFastWhenIdle) return;
|
|
1536
|
-
if (idleTimer) clearTimeout(idleTimer);
|
|
1537
|
-
idleTimer = setTimeout(function() {
|
|
1538
|
-
if (document.readyState === "complete" && (!waitForAppReady || isAppReady())) {
|
|
1539
|
-
var hit = checkActionableNow();
|
|
1540
|
-
finish(hit ? (forAction ? [hit.match] : hit) : []);
|
|
1541
|
-
} else {
|
|
1542
|
-
armIdleTimer();
|
|
1543
|
-
}
|
|
1544
|
-
}, idleQuietMs);
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
function verifyStability(candidate) {
|
|
1548
|
-
if (done || checkingStability) return;
|
|
1549
|
-
var framesToWait = neededStableFrames(candidate);
|
|
1550
|
-
if (!forAction || framesToWait <= 0 || typeof requestAnimationFrame !== "function") {
|
|
1551
|
-
finish(forAction ? [candidate.match] : candidate);
|
|
1552
|
-
return;
|
|
1553
|
-
}
|
|
1554
|
-
checkingStability = true;
|
|
1555
|
-
var el = candidate.target.hit.el;
|
|
1556
|
-
var lastRect = candidate.match.rect;
|
|
1557
|
-
var remainingFrames = framesToWait;
|
|
1558
|
-
|
|
1559
|
-
function step() {
|
|
1560
|
-
if (done) return;
|
|
1561
|
-
if (!el.isConnected) { checkingStability = false; return; }
|
|
1562
|
-
if (checkHitTest && !isHitTestClear(candidate.target.hit)) { checkingStability = false; return; }
|
|
1563
|
-
var cur = toMatch(candidate.target.hit);
|
|
1564
|
-
if (!cur.visible || !cur.enabled) { checkingStability = false; return; }
|
|
1565
|
-
var dx = Math.abs(cur.rect.x - lastRect.x);
|
|
1566
|
-
var dy = Math.abs(cur.rect.y - lastRect.y);
|
|
1567
|
-
var dw = Math.abs(cur.rect.width - lastRect.width);
|
|
1568
|
-
var dh = Math.abs(cur.rect.height - lastRect.height);
|
|
1569
|
-
if (dx <= 1 && dy <= 1 && dw <= 1 && dh <= 1) {
|
|
1570
|
-
remainingFrames -= 1;
|
|
1571
|
-
if (remainingFrames <= 0) { finish([cur]); return; }
|
|
1572
|
-
} else {
|
|
1573
|
-
remainingFrames = framesToWait;
|
|
1574
|
-
lastRect = cur.rect;
|
|
1575
|
-
}
|
|
1576
|
-
rafId = requestAnimationFrame(step);
|
|
1577
|
-
}
|
|
1578
|
-
rafId = requestAnimationFrame(step);
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
function attempt() {
|
|
1582
|
-
if (done || checkingStability) return;
|
|
1583
|
-
var hit = checkActionableNow();
|
|
1584
|
-
if (hit) {
|
|
1585
|
-
if (forAction) verifyStability(hit);
|
|
1586
|
-
else finish(hit);
|
|
1587
|
-
return;
|
|
1588
|
-
}
|
|
1589
|
-
armIdleTimer();
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
var scheduled = false;
|
|
1593
|
-
function scheduleAttempt() {
|
|
1594
|
-
if (done || scheduled || checkingStability) return;
|
|
1595
|
-
scheduled = true;
|
|
1596
|
-
Promise.resolve().then(function() { scheduled = false; attempt(); });
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
timeoutTimer = setTimeout(function() {
|
|
1600
|
-
var finalHit = checkActionableNow();
|
|
1601
|
-
finish(finalHit ? (forAction ? [finalHit.match] : finalHit) : []);
|
|
1602
|
-
}, timeoutMs);
|
|
1603
|
-
fallbackInterval = setInterval(attempt, forAction ? 40 : 120);
|
|
1604
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1605
|
-
var root = document.documentElement || document.body || document;
|
|
1606
|
-
if (root) {
|
|
1607
|
-
observer = new MutationObserver(scheduleAttempt);
|
|
1608
|
-
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
attempt();
|
|
1612
|
-
});
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
function waitForHidden(sel, opts) {
|
|
1616
|
-
opts = opts || {};
|
|
1617
|
-
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1618
|
-
function isHiddenNow() {
|
|
1619
|
-
var hits = findAcrossRoots(sel);
|
|
1620
|
-
for (var i = 0; i < hits.length; i++) {
|
|
1621
|
-
if (toMatch(hits[i]).visible) return false;
|
|
1622
|
-
}
|
|
1623
|
-
return true;
|
|
1624
|
-
}
|
|
1625
|
-
if (isHiddenNow()) return true;
|
|
1626
|
-
return new Promise(function(resolve) {
|
|
1627
|
-
var done = false;
|
|
1628
|
-
var observer = null;
|
|
1629
|
-
var timeoutTimer = null;
|
|
1630
|
-
var fallbackInterval = null;
|
|
1631
|
-
function finish(val) {
|
|
1632
|
-
if (done) return;
|
|
1633
|
-
done = true;
|
|
1634
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1635
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1636
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1637
|
-
resolve(val);
|
|
1638
|
-
}
|
|
1639
|
-
function onChange() { if (isHiddenNow()) finish(true); }
|
|
1640
|
-
timeoutTimer = setTimeout(function() { finish(isHiddenNow()); }, timeoutMs);
|
|
1641
|
-
fallbackInterval = setInterval(onChange, 120);
|
|
1642
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1643
|
-
var root = document.documentElement || document.body || document;
|
|
1644
|
-
if (root) {
|
|
1645
|
-
observer = new MutationObserver(onChange);
|
|
1646
|
-
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
function waitForMatch(sel, opts) {
|
|
1653
|
-
opts = opts || {};
|
|
1654
|
-
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1655
|
-
var kind = opts.kind;
|
|
1656
|
-
var expected = opts.expected !== undefined ? opts.expected : null;
|
|
1657
|
-
var expectedCount = opts.expectedCount !== undefined ? opts.expectedCount : null;
|
|
1658
|
-
var attributeName = opts.attributeName !== undefined ? opts.attributeName : null;
|
|
1659
|
-
var patternSource = opts.patternSource !== undefined ? opts.patternSource : null;
|
|
1660
|
-
var patternFlags = opts.patternFlags || "";
|
|
1661
|
-
var negate = Boolean(opts.negate);
|
|
1662
|
-
var lastActual = undefined;
|
|
1663
|
-
var regex = patternSource !== null ? new RegExp(patternSource, patternFlags) : null;
|
|
1664
|
-
|
|
1665
|
-
function evaluateMatch() {
|
|
1666
|
-
if (kind === "url") {
|
|
1667
|
-
var href = typeof window !== "undefined" && window.location ? String(window.location.href || "") : "";
|
|
1668
|
-
lastActual = href;
|
|
1669
|
-
var urlOk = regex
|
|
1670
|
-
? regex.test(href)
|
|
1671
|
-
: (expected !== null && (href === expected || href.indexOf(String(expected)) !== -1));
|
|
1672
|
-
if (negate ? !urlOk : urlOk) return { matched: true, actual: href };
|
|
1673
|
-
return null;
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
var hits = findAcrossRoots(sel);
|
|
1677
|
-
|
|
1678
|
-
if (kind === "count") {
|
|
1679
|
-
var visibleCount = 0;
|
|
1680
|
-
for (var ci = 0; ci < hits.length; ci++) {
|
|
1681
|
-
if (toMatch(hits[ci]).visible) visibleCount++;
|
|
1682
|
-
}
|
|
1683
|
-
lastActual = String(visibleCount);
|
|
1684
|
-
var countOk = expectedCount !== null && visibleCount === expectedCount;
|
|
1685
|
-
if (negate ? !countOk : countOk) {
|
|
1686
|
-
return { matched: true, actual: String(visibleCount) };
|
|
1687
|
-
}
|
|
1688
|
-
return null;
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1692
|
-
var m = toMatch(hits[i]);
|
|
1693
|
-
if (!m.visible) continue;
|
|
1694
|
-
var matched = false;
|
|
1695
|
-
var actualVal = undefined;
|
|
1696
|
-
if (kind === "text") {
|
|
1697
|
-
var normTxt = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1698
|
-
actualVal = normTxt;
|
|
1699
|
-
matched = normTxt === (expected !== null ? String(expected).replace(/\\s+/g, " ").trim() : expected);
|
|
1700
|
-
} else if (kind === "containsText") {
|
|
1701
|
-
var actual = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1702
|
-
actualVal = actual;
|
|
1703
|
-
matched = expected !== null && actual.toLowerCase().indexOf(String(expected).replace(/\\s+/g, " ").trim().toLowerCase()) !== -1;
|
|
1704
|
-
} else if (kind === "matchesText") {
|
|
1705
|
-
var actualRe = m.textContent !== undefined ? m.textContent : (m.text || "");
|
|
1706
|
-
actualVal = actualRe;
|
|
1707
|
-
matched = Boolean(regex && regex.test(actualRe));
|
|
1708
|
-
} else if (kind === "value") {
|
|
1709
|
-
var val = m.value !== undefined ? m.value : "";
|
|
1710
|
-
actualVal = val;
|
|
1711
|
-
matched = val === expected;
|
|
1712
|
-
} else if (kind === "attribute" && attributeName !== null) {
|
|
1713
|
-
var attrVal = m.attributes ? m.attributes[attributeName] : undefined;
|
|
1714
|
-
actualVal = attrVal;
|
|
1715
|
-
matched = expected === null ? attrVal !== undefined : attrVal === expected;
|
|
1716
|
-
} else if (kind === "accessibilityLabel") {
|
|
1717
|
-
var lbl = m.accessibilityLabel;
|
|
1718
|
-
actualVal = lbl;
|
|
1719
|
-
matched = expected === null ? (lbl !== undefined && lbl.length > 0) : lbl === expected;
|
|
1720
|
-
} else if (kind === "accessibleName") {
|
|
1721
|
-
var accName = m.accessibleName || m.accessibilityLabel || m.text || "";
|
|
1722
|
-
actualVal = accName;
|
|
1723
|
-
matched = regex ? regex.test(accName) : (expected === null ? accName.length > 0 : accName.trim() === String(expected).trim());
|
|
1724
|
-
} else if (kind === "accessibleDescription") {
|
|
1725
|
-
var accDesc = m.accessibleDescription || "";
|
|
1726
|
-
actualVal = accDesc;
|
|
1727
|
-
matched = regex ? regex.test(accDesc) : (expected === null ? accDesc.length > 0 : accDesc.trim() === String(expected).trim());
|
|
1728
|
-
} else if (kind === "focused") {
|
|
1729
|
-
actualVal = m.focused ? "focused" : "not focused";
|
|
1730
|
-
matched = Boolean(m.focused);
|
|
1731
|
-
}
|
|
1732
|
-
lastActual = actualVal;
|
|
1733
|
-
if (negate ? !matched : matched) return { matched: true, actual: actualVal };
|
|
1734
|
-
}
|
|
1735
|
-
return null;
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
var immediate = evaluateMatch();
|
|
1739
|
-
if (immediate) return immediate;
|
|
1740
|
-
|
|
1741
|
-
return new Promise(function(resolve) {
|
|
1742
|
-
var done = false;
|
|
1743
|
-
var observer = null;
|
|
1744
|
-
var timeoutTimer = null;
|
|
1745
|
-
var fallbackInterval = null;
|
|
1746
|
-
var scheduled = false;
|
|
1747
|
-
function finish(res) {
|
|
1748
|
-
if (done) return;
|
|
1749
|
-
done = true;
|
|
1750
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1751
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1752
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1753
|
-
if (typeof document !== "undefined") {
|
|
1754
|
-
document.removeEventListener("input", onChange, true);
|
|
1755
|
-
document.removeEventListener("change", onChange, true);
|
|
1756
|
-
document.removeEventListener("focusin", onChange, true);
|
|
1757
|
-
document.removeEventListener("focusout", onChange, true);
|
|
1758
|
-
}
|
|
1759
|
-
if (typeof window !== "undefined") {
|
|
1760
|
-
window.removeEventListener("popstate", onChange);
|
|
1761
|
-
window.removeEventListener("hashchange", onChange);
|
|
1762
|
-
}
|
|
1763
|
-
resolve(res);
|
|
1764
|
-
}
|
|
1765
|
-
function onChange() {
|
|
1766
|
-
if (done || scheduled) return;
|
|
1767
|
-
scheduled = true;
|
|
1768
|
-
Promise.resolve().then(function() {
|
|
1769
|
-
scheduled = false;
|
|
1770
|
-
if (done) return;
|
|
1771
|
-
var res = evaluateMatch();
|
|
1772
|
-
if (res) finish(res);
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
timeoutTimer = setTimeout(function() {
|
|
1776
|
-
var finalRes = evaluateMatch();
|
|
1777
|
-
finish(finalRes || { matched: false, actual: lastActual });
|
|
1778
|
-
}, timeoutMs);
|
|
1779
|
-
fallbackInterval = setInterval(onChange, kind === "url" ? 50 : 120);
|
|
1780
|
-
if (typeof document !== "undefined") {
|
|
1781
|
-
document.addEventListener("input", onChange, true);
|
|
1782
|
-
document.addEventListener("change", onChange, true);
|
|
1783
|
-
document.addEventListener("focusin", onChange, true);
|
|
1784
|
-
document.addEventListener("focusout", onChange, true);
|
|
1785
|
-
}
|
|
1786
|
-
if (typeof window !== "undefined") {
|
|
1787
|
-
window.addEventListener("popstate", onChange);
|
|
1788
|
-
window.addEventListener("hashchange", onChange);
|
|
1789
|
-
}
|
|
1790
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1791
|
-
var root = document.documentElement || document.body || document;
|
|
1792
|
-
if (root) {
|
|
1793
|
-
observer = new MutationObserver(onChange);
|
|
1794
|
-
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
});
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
function fill(sel, val, opts) {
|
|
1801
|
-
opts = opts || {};
|
|
1802
|
-
var timeoutMs = Math.max(10, Math.round(opts.timeoutMs != null ? opts.timeoutMs : 5000));
|
|
1803
|
-
var checkHitTest = opts.checkHitTest !== undefined ? Boolean(opts.checkHitTest) : true;
|
|
1804
|
-
function writeValue(el) {
|
|
1805
|
-
if (el.isContentEditable) return false;
|
|
1806
|
-
if (typeof el.focus === "function") { try { el.focus(); } catch (e) {} }
|
|
1807
|
-
var tag = el.tagName;
|
|
1808
|
-
if (tag === "INPUT" || tag === "TEXTAREA") {
|
|
1809
|
-
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
1810
|
-
var proto = tag === "TEXTAREA"
|
|
1811
|
-
? (win.HTMLTextAreaElement && win.HTMLTextAreaElement.prototype)
|
|
1812
|
-
: (win.HTMLInputElement && win.HTMLInputElement.prototype);
|
|
1813
|
-
var desc = proto ? Object.getOwnPropertyDescriptor(proto, "value") : null;
|
|
1814
|
-
if (desc && typeof desc.set === "function") desc.set.call(el, val);
|
|
1815
|
-
else el.value = val;
|
|
1816
|
-
if (el._valueTracker && typeof el._valueTracker.setValue === "function") {
|
|
1817
|
-
try { el._valueTracker.setValue(val === "" ? " " : ""); } catch (e) {}
|
|
1818
|
-
}
|
|
1819
|
-
} else if (tag === "SELECT") {
|
|
1820
|
-
el.value = val;
|
|
1821
|
-
} else {
|
|
1822
|
-
el.value = val;
|
|
1823
|
-
}
|
|
1824
|
-
try { el.dispatchEvent(new InputEvent("input", { bubbles: true, cancelable: true, data: val, inputType: "insertText" })); }
|
|
1825
|
-
catch (e) { el.dispatchEvent(new Event("input", { bubbles: true, cancelable: true })); }
|
|
1826
|
-
el.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
|
|
1827
|
-
return true;
|
|
1828
|
-
}
|
|
1829
|
-
function findEditableNow() {
|
|
1830
|
-
if (!isAppReady()) return null;
|
|
1831
|
-
var hits = findAcrossRoots(sel);
|
|
1832
|
-
for (var i = hits.length - 1; i >= 0; i--) {
|
|
1833
|
-
var h = hits[i];
|
|
1834
|
-
var m = toMatch(h);
|
|
1835
|
-
if (!m.visible || !m.enabled) continue;
|
|
1836
|
-
ensureInViewport(h);
|
|
1837
|
-
if (checkHitTest && !isHitTestClear(h)) {
|
|
1838
|
-
scrollToUnobscure(h);
|
|
1839
|
-
if (!isHitTestClear(h)) continue;
|
|
1840
|
-
}
|
|
1841
|
-
return h.el;
|
|
1842
|
-
}
|
|
1843
|
-
return null;
|
|
1844
|
-
}
|
|
1845
|
-
function verifyAndRetryFill(attemptsLeft) {
|
|
1846
|
-
var el = findEditableNow();
|
|
1847
|
-
if (!el || el.isContentEditable) return Promise.resolve(false);
|
|
1848
|
-
if (!writeValue(el)) return Promise.resolve(false);
|
|
1849
|
-
return new Promise(function(resolve) {
|
|
1850
|
-
setTimeout(function() {
|
|
1851
|
-
var latest = findEditableNow() || el;
|
|
1852
|
-
if (latest && latest.isConnected && String(latest.value == null ? "" : latest.value) === val) {
|
|
1853
|
-
resolve(true);
|
|
1854
|
-
return;
|
|
1855
|
-
}
|
|
1856
|
-
if (attemptsLeft > 1) {
|
|
1857
|
-
verifyAndRetryFill(attemptsLeft - 1).then(resolve);
|
|
1858
|
-
} else {
|
|
1859
|
-
resolve(false);
|
|
1860
|
-
}
|
|
1861
|
-
}, 12);
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
var immEl = findEditableNow();
|
|
1865
|
-
if (immEl) {
|
|
1866
|
-
if (immEl.isContentEditable) return false;
|
|
1867
|
-
return verifyAndRetryFill(3);
|
|
1868
|
-
}
|
|
1869
|
-
return new Promise(function(resolve) {
|
|
1870
|
-
var done = false;
|
|
1871
|
-
var observer = null;
|
|
1872
|
-
var timeoutTimer = null;
|
|
1873
|
-
var fallbackInterval = null;
|
|
1874
|
-
var scheduled = false;
|
|
1875
|
-
var filling = false;
|
|
1876
|
-
function finish(ok) {
|
|
1877
|
-
if (done) return;
|
|
1878
|
-
done = true;
|
|
1879
|
-
if (observer) { try { observer.disconnect(); } catch (e) {} }
|
|
1880
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
1881
|
-
if (fallbackInterval) clearInterval(fallbackInterval);
|
|
1882
|
-
resolve(ok);
|
|
1883
|
-
}
|
|
1884
|
-
function onChange() {
|
|
1885
|
-
if (done || scheduled || filling) return;
|
|
1886
|
-
scheduled = true;
|
|
1887
|
-
Promise.resolve().then(function() {
|
|
1888
|
-
scheduled = false;
|
|
1889
|
-
if (done || filling) return;
|
|
1890
|
-
var target = findEditableNow();
|
|
1891
|
-
if (!target) return;
|
|
1892
|
-
if (target.isContentEditable) { finish(false); return; }
|
|
1893
|
-
filling = true;
|
|
1894
|
-
verifyAndRetryFill(3).then(function(ok) { finish(ok); });
|
|
1895
|
-
});
|
|
1896
|
-
}
|
|
1897
|
-
timeoutTimer = setTimeout(function() {
|
|
1898
|
-
if (filling) return;
|
|
1899
|
-
var target = findEditableNow();
|
|
1900
|
-
if (!target || target.isContentEditable) { finish(false); return; }
|
|
1901
|
-
filling = true;
|
|
1902
|
-
verifyAndRetryFill(2).then(function(ok) { finish(ok); });
|
|
1903
|
-
}, timeoutMs);
|
|
1904
|
-
fallbackInterval = setInterval(onChange, 40);
|
|
1905
|
-
if (typeof MutationObserver !== "undefined") {
|
|
1906
|
-
var root = document.documentElement || document.body || document;
|
|
1907
|
-
if (root) {
|
|
1908
|
-
observer = new MutationObserver(onChange);
|
|
1909
|
-
observer.observe(root, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
});
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
window.__spanaRt = {
|
|
1916
|
-
query: query,
|
|
1917
|
-
scrollIntoView: scrollIntoView,
|
|
1918
|
-
tap: tap,
|
|
1919
|
-
waitForSelector: waitForSelector,
|
|
1920
|
-
waitForHidden: waitForHidden,
|
|
1921
|
-
waitForMatch: waitForMatch,
|
|
1922
|
-
fill: fill
|
|
1923
|
-
};
|
|
1924
|
-
return true;
|
|
1925
|
-
})();`;
|
|
1926
|
-
function buildDomActionabilityDiagScript(selector) {
|
|
1927
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
1928
|
-
return `(function(sel) {
|
|
1929
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1930
|
-
var hits = findAcrossRoots(sel);
|
|
1931
|
-
if (hits.length === 0) return { found: false };
|
|
1932
|
-
var target = hits[hits.length - 1];
|
|
1933
|
-
var m = toMatch(target);
|
|
1934
|
-
if (!m.visible) return { found: true, visible: false, enabled: m.enabled };
|
|
1935
|
-
if (!m.enabled) return { found: true, visible: true, enabled: false };
|
|
1936
|
-
var blocker = getHitTestBlocker(target);
|
|
1937
|
-
return { found: true, visible: true, enabled: true, obstructedBy: blocker || undefined };
|
|
1938
|
-
})(${serialized})`;
|
|
1939
|
-
}
|
|
1940
|
-
function buildDomFindElementScript(selector) {
|
|
1941
|
-
const serialized = JSON.stringify(serializeSelectorForDom(selector));
|
|
1942
|
-
return `(function(sel) {
|
|
1943
|
-
${SHARED_DOM_TRAVERSAL_HELPERS}
|
|
1944
|
-
var hits = findAcrossRoots(sel);
|
|
1945
|
-
if (hits.length === 0) return null;
|
|
1946
|
-
return hits[hits.length - 1].el;
|
|
1947
|
-
})(${serialized})`;
|
|
1948
|
-
}
|
|
1949
|
-
function buildInjectedCallScript(method, ...args) {
|
|
1950
|
-
const serializedArgs = args.map((arg) => JSON.stringify(serializeSelectorForDom(arg))).join(",");
|
|
1951
|
-
return `window.__spanaRt?window.__spanaRt.${method}(${serializedArgs}):${JSON.stringify(SPANA_RUNTIME_MISSING_SENTINEL)}`;
|
|
1952
|
-
}
|
|
10
|
+
DriverError,
|
|
11
|
+
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
12
|
+
SPANA_RUNTIME_MISSING_SENTINEL,
|
|
13
|
+
buildDomFillScript,
|
|
14
|
+
buildDomQueryScript,
|
|
15
|
+
buildDomScrollIntoViewScript,
|
|
16
|
+
buildDomTapScript,
|
|
17
|
+
buildDomWaitForHiddenScript,
|
|
18
|
+
buildDomWaitForMatchScript,
|
|
19
|
+
buildDomWaitForSelectorScript,
|
|
20
|
+
buildEvaluateExpression,
|
|
21
|
+
buildInjectedCallScript
|
|
22
|
+
} from "./chunk-SGZMO456.js";
|
|
1953
23
|
|
|
1954
24
|
// src/core/target-matrix.ts
|
|
1955
25
|
var TARGET_CHANNEL_MATRIX = {
|
|
@@ -2651,6 +721,8 @@ var AndroidWebViewCdpChannel = class {
|
|
|
2651
721
|
allocatedByUs = false;
|
|
2652
722
|
activeSocketName = null;
|
|
2653
723
|
cdp = null;
|
|
724
|
+
routes = [];
|
|
725
|
+
enableInterception;
|
|
2654
726
|
constructor(options) {
|
|
2655
727
|
this.options = options;
|
|
2656
728
|
}
|
|
@@ -2709,7 +781,24 @@ var AndroidWebViewCdpChannel = class {
|
|
|
2709
781
|
fetchFn: this.options.fetchFn,
|
|
2710
782
|
createWebSocket: this.options.createWebSocket
|
|
2711
783
|
});
|
|
784
|
+
const cdp = this.cdp;
|
|
785
|
+
cdp.onEvent("Fetch.requestPaused", (params, sessionId) => {
|
|
786
|
+
const requestId = params?.requestId;
|
|
787
|
+
if (typeof requestId !== "string") return;
|
|
788
|
+
const route = this.routes.findLast(
|
|
789
|
+
(candidate) => candidate.matches(String(params?.request?.url ?? ""))
|
|
790
|
+
);
|
|
791
|
+
const resume = () => cdp.sendCommand("Fetch.continueRequest", { requestId }, sessionId);
|
|
792
|
+
const operation = route ? route.response ? cdp.sendCommand("Fetch.fulfillRequest", { requestId, ...route.response }, sessionId) : cdp.sendCommand(
|
|
793
|
+
"Fetch.failRequest",
|
|
794
|
+
{ requestId, errorReason: "BlockedByClient" },
|
|
795
|
+
sessionId
|
|
796
|
+
) : resume();
|
|
797
|
+
void operation.catch(() => route ? resume().catch(() => {
|
|
798
|
+
}) : void 0);
|
|
799
|
+
});
|
|
2712
800
|
await this.cdp.connect();
|
|
801
|
+
if (this.routes.length) await this.ensureInterception();
|
|
2713
802
|
} catch (error) {
|
|
2714
803
|
await this.disconnect();
|
|
2715
804
|
throw error;
|
|
@@ -2750,6 +839,60 @@ var AndroidWebViewCdpChannel = class {
|
|
|
2750
839
|
await this.connect();
|
|
2751
840
|
}
|
|
2752
841
|
await this.cdp.selectTarget(targetId);
|
|
842
|
+
this.enableInterception = void 0;
|
|
843
|
+
if (this.routes.length) await this.ensureInterception();
|
|
844
|
+
}
|
|
845
|
+
async ensureInterception() {
|
|
846
|
+
this.enableInterception ??= this.cdp.sendCommand("Fetch.enable", {
|
|
847
|
+
patterns: [{ urlPattern: "*" }]
|
|
848
|
+
});
|
|
849
|
+
try {
|
|
850
|
+
await this.enableInterception;
|
|
851
|
+
} catch (error) {
|
|
852
|
+
this.enableInterception = void 0;
|
|
853
|
+
throw error;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
async addRoute(matcher, response) {
|
|
857
|
+
if (!this.isConnected()) await this.connect();
|
|
858
|
+
await this.ensureInterception();
|
|
859
|
+
const regex = typeof matcher === "string" ? matcher.includes("*") ? new RegExp(
|
|
860
|
+
matcher.split(/(\*\*|\*)/).map(
|
|
861
|
+
(part) => part === "**" ? ".*" : part === "*" ? "[^/]*" : part.replaceAll(/[.+?^${}()|[\]\\]/g, "\\$&")
|
|
862
|
+
).join("")
|
|
863
|
+
) : void 0 : new RegExp(matcher.source, matcher.flags.replaceAll(/[gy]/g, ""));
|
|
864
|
+
this.routes.push({
|
|
865
|
+
matches: regex ? (url) => regex.test(url) : (url) => url.includes(matcher),
|
|
866
|
+
response
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
async mockNetwork(matcher, response) {
|
|
870
|
+
if (response.body !== void 0 && response.json !== void 0) {
|
|
871
|
+
throw new Error("mockNetwork() response cannot include both body and json.");
|
|
872
|
+
}
|
|
873
|
+
const headers = { ...response.headers };
|
|
874
|
+
const type = response.contentType ?? (response.json === void 0 ? void 0 : "application/json");
|
|
875
|
+
if (type && !Object.keys(headers).some((key) => key.toLowerCase() === "content-type")) {
|
|
876
|
+
headers["content-type"] = type;
|
|
877
|
+
}
|
|
878
|
+
await this.addRoute(matcher, {
|
|
879
|
+
responseCode: response.status ?? 200,
|
|
880
|
+
responseHeaders: Object.entries(headers).map(([name, value]) => ({ name, value })),
|
|
881
|
+
body: Buffer.from(
|
|
882
|
+
response.json !== void 0 ? JSON.stringify(response.json) : response.body ?? ""
|
|
883
|
+
).toString("base64")
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
async blockNetwork(matcher) {
|
|
887
|
+
await this.addRoute(matcher);
|
|
888
|
+
}
|
|
889
|
+
async clearNetworkMocks() {
|
|
890
|
+
this.routes.length = 0;
|
|
891
|
+
if (this.enableInterception && this.isConnected()) {
|
|
892
|
+
await this.enableInterception;
|
|
893
|
+
await this.cdp.sendCommand("Fetch.disable");
|
|
894
|
+
this.enableInterception = void 0;
|
|
895
|
+
}
|
|
2753
896
|
}
|
|
2754
897
|
async reload() {
|
|
2755
898
|
if (!this.isConnected()) {
|
|
@@ -2758,6 +901,7 @@ var AndroidWebViewCdpChannel = class {
|
|
|
2758
901
|
await this.cdp.reload();
|
|
2759
902
|
}
|
|
2760
903
|
async disconnect() {
|
|
904
|
+
this.enableInterception = void 0;
|
|
2761
905
|
if (this.cdp) {
|
|
2762
906
|
await this.cdp.disconnect();
|
|
2763
907
|
this.cdp = null;
|
|
@@ -3822,11 +1966,11 @@ function createSpanaBridgeChannel(options = {}) {
|
|
|
3822
1966
|
}
|
|
3823
1967
|
function createCompositeDomChannel(channels) {
|
|
3824
1968
|
const active = () => channels.find((c) => c.isConnected()) ?? channels[0];
|
|
3825
|
-
const ensureOneConnected = async () => {
|
|
3826
|
-
const already =
|
|
1969
|
+
const ensureOneConnected = async (candidates = channels, unavailableMessage = "No DOM channel available") => {
|
|
1970
|
+
const already = candidates.find((c) => c.isConnected());
|
|
3827
1971
|
if (already) return already;
|
|
3828
1972
|
let lastError;
|
|
3829
|
-
for (const ch of
|
|
1973
|
+
for (const ch of candidates) {
|
|
3830
1974
|
try {
|
|
3831
1975
|
await ch.connect();
|
|
3832
1976
|
return ch;
|
|
@@ -3834,7 +1978,7 @@ function createCompositeDomChannel(channels) {
|
|
|
3834
1978
|
lastError = err;
|
|
3835
1979
|
}
|
|
3836
1980
|
}
|
|
3837
|
-
throw lastError ?? new Error(
|
|
1981
|
+
throw lastError ?? new Error(unavailableMessage);
|
|
3838
1982
|
};
|
|
3839
1983
|
return {
|
|
3840
1984
|
get kind() {
|
|
@@ -3895,20 +2039,23 @@ function createCompositeDomChannel(channels) {
|
|
|
3895
2039
|
}
|
|
3896
2040
|
},
|
|
3897
2041
|
mockNetwork: async (matcher, response) => {
|
|
3898
|
-
const ch = await ensureOneConnected(
|
|
3899
|
-
|
|
3900
|
-
|
|
2042
|
+
const ch = await ensureOneConnected(
|
|
2043
|
+
channels.filter((c) => c.mockNetwork),
|
|
2044
|
+
"mockNetwork() requires a WebView with spana-bridge or Android WebView debugging enabled"
|
|
2045
|
+
);
|
|
3901
2046
|
await ch.mockNetwork(matcher, response);
|
|
3902
2047
|
},
|
|
3903
2048
|
blockNetwork: async (matcher) => {
|
|
3904
|
-
const ch = await ensureOneConnected(
|
|
3905
|
-
|
|
3906
|
-
|
|
2049
|
+
const ch = await ensureOneConnected(
|
|
2050
|
+
channels.filter((c) => c.blockNetwork),
|
|
2051
|
+
"blockNetwork() requires a WebView with spana-bridge or Android WebView debugging enabled"
|
|
2052
|
+
);
|
|
3907
2053
|
await ch.blockNetwork(matcher);
|
|
3908
2054
|
},
|
|
3909
2055
|
clearNetworkMocks: async () => {
|
|
3910
|
-
|
|
3911
|
-
|
|
2056
|
+
await Promise.all(
|
|
2057
|
+
channels.filter((ch) => ch.isConnected() || ch.kind === "cdp").map((ch) => ch.clearNetworkMocks?.())
|
|
2058
|
+
);
|
|
3912
2059
|
},
|
|
3913
2060
|
getConsoleLogs: async () => {
|
|
3914
2061
|
const ch = await ensureOneConnected();
|
|
@@ -4320,22 +2467,6 @@ function makeElectrobunDriver(options) {
|
|
|
4320
2467
|
}
|
|
4321
2468
|
|
|
4322
2469
|
export {
|
|
4323
|
-
ElementNotFoundError,
|
|
4324
|
-
TextMismatchError,
|
|
4325
|
-
WaitTimeoutError,
|
|
4326
|
-
DriverError,
|
|
4327
|
-
domMatchToElement,
|
|
4328
|
-
buildDomQueryScript,
|
|
4329
|
-
buildDomScrollIntoViewScript,
|
|
4330
|
-
buildDomTapScript,
|
|
4331
|
-
buildDomWaitForSelectorScript,
|
|
4332
|
-
buildDomWaitForHiddenScript,
|
|
4333
|
-
buildDomWaitForMatchScript,
|
|
4334
|
-
buildDomFillScript,
|
|
4335
|
-
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
4336
|
-
buildDomActionabilityDiagScript,
|
|
4337
|
-
buildDomFindElementScript,
|
|
4338
|
-
buildInjectedCallScript,
|
|
4339
2470
|
TARGET_CHANNEL_MATRIX,
|
|
4340
2471
|
resolveElectrobunEngine,
|
|
4341
2472
|
resolveTargetDescriptor,
|
|
@@ -4360,4 +2491,4 @@ export {
|
|
|
4360
2491
|
resolveElectrobunLaunchPlan,
|
|
4361
2492
|
makeElectrobunDriver
|
|
4362
2493
|
};
|
|
4363
|
-
//# sourceMappingURL=chunk-
|
|
2494
|
+
//# sourceMappingURL=chunk-WS2TVNMY.js.map
|