@usecrow/client 0.1.28 → 0.1.29

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.
@@ -1,1379 +0,0 @@
1
- async function waitFor(e) {
2
- await new Promise((n) => setTimeout(n, e * 1e3));
3
- }
4
- async function movePointerToElement(e) {
5
- const n = e.getBoundingClientRect(), s = n.left + n.width / 2, i = n.top + n.height / 2;
6
- window.dispatchEvent(new CustomEvent("PageAgent::MovePointerTo", { detail: { x: s, y: i } })), await waitFor(0.3);
7
- }
8
- function getElementByIndex(e, n) {
9
- const s = e.get(n);
10
- if (!s)
11
- throw new Error(`No interactive element found at index ${n}`);
12
- const i = s.ref;
13
- if (!i)
14
- throw new Error(`Element at index ${n} does not have a reference`);
15
- if (!(i instanceof HTMLElement))
16
- throw new Error(`Element at index ${n} is not an HTMLElement`);
17
- return i;
18
- }
19
- let lastClickedElement = null;
20
- function blurLastClickedElement() {
21
- lastClickedElement && (lastClickedElement.blur(), lastClickedElement.dispatchEvent(
22
- new MouseEvent("mouseout", { bubbles: !0, cancelable: !0 })
23
- ), lastClickedElement = null);
24
- }
25
- async function clickElement(e) {
26
- blurLastClickedElement(), lastClickedElement = e, await scrollIntoViewIfNeeded(e), await movePointerToElement(e), window.dispatchEvent(new CustomEvent("PageAgent::ClickPointer")), await waitFor(0.1), e.dispatchEvent(new MouseEvent("mouseenter", { bubbles: !0, cancelable: !0 })), e.dispatchEvent(new MouseEvent("mouseover", { bubbles: !0, cancelable: !0 })), e.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, cancelable: !0 })), e.focus(), e.dispatchEvent(new MouseEvent("mouseup", { bubbles: !0, cancelable: !0 })), e.dispatchEvent(new MouseEvent("click", { bubbles: !0, cancelable: !0 })), await waitFor(0.1);
27
- }
28
- const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
29
- window.HTMLInputElement.prototype,
30
- "value"
31
- ).set, nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(
32
- window.HTMLTextAreaElement.prototype,
33
- "value"
34
- ).set;
35
- async function inputTextElement(e, n) {
36
- if (!(e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement))
37
- throw new Error("Element is not an input or textarea");
38
- await clickElement(e), e instanceof HTMLTextAreaElement ? nativeTextAreaValueSetter.call(e, n) : nativeInputValueSetter.call(e, n);
39
- const s = new Event("input", { bubbles: !0 });
40
- e.dispatchEvent(s), await waitFor(0.1), blurLastClickedElement();
41
- }
42
- async function selectOptionElement(e, n) {
43
- if (!(e instanceof HTMLSelectElement))
44
- throw new Error("Element is not a select element");
45
- const i = Array.from(e.options).find((w) => {
46
- var d;
47
- return ((d = w.textContent) == null ? void 0 : d.trim()) === n.trim();
48
- });
49
- if (!i)
50
- throw new Error(`Option with text "${n}" not found in select element`);
51
- e.value = i.value, e.dispatchEvent(new Event("change", { bubbles: !0 })), await waitFor(0.1);
52
- }
53
- async function scrollIntoViewIfNeeded(e) {
54
- const n = e;
55
- n.scrollIntoViewIfNeeded ? n.scrollIntoViewIfNeeded() : n.scrollIntoView({ behavior: "auto", block: "center", inline: "nearest" });
56
- }
57
- async function scrollVertically(e, n, s) {
58
- if (s) {
59
- const l = s;
60
- console.log(
61
- "[SCROLL DEBUG] Starting direct container scroll for element:",
62
- l.tagName
63
- );
64
- let h = l, T = !1, b = null, u = 0, f = 0;
65
- const N = n;
66
- for (; h && f < 10; ) {
67
- const D = window.getComputedStyle(h), z = /(auto|scroll|overlay)/.test(D.overflowY), O = h.scrollHeight > h.clientHeight;
68
- if (console.log(
69
- "[SCROLL DEBUG] Checking element:",
70
- h.tagName,
71
- "hasScrollableY:",
72
- z,
73
- "canScrollVertically:",
74
- O,
75
- "scrollHeight:",
76
- h.scrollHeight,
77
- "clientHeight:",
78
- h.clientHeight
79
- ), z && O) {
80
- const R = h.scrollTop, U = h.scrollHeight - h.clientHeight;
81
- let H = N / 3;
82
- H > 0 ? H = Math.min(H, U - R) : H = Math.max(H, -R), h.scrollTop = R + H;
83
- const B = h.scrollTop, _ = B - R;
84
- if (console.log(
85
- "[SCROLL DEBUG] Scroll attempt:",
86
- h.tagName,
87
- "before:",
88
- R,
89
- "after:",
90
- B,
91
- "delta:",
92
- _
93
- ), Math.abs(_) > 0.5) {
94
- T = !0, b = h, u = _, console.log(
95
- "[SCROLL DEBUG] Successfully scrolled container:",
96
- h.tagName,
97
- "delta:",
98
- _
99
- );
100
- break;
101
- }
102
- }
103
- if (h === document.body || h === document.documentElement)
104
- break;
105
- h = h.parentElement, f++;
106
- }
107
- return T ? `Scrolled container (${b == null ? void 0 : b.tagName}) by ${u}px` : `No scrollable container found for element (${l.tagName})`;
108
- }
109
- const i = n, w = (l) => l.clientHeight >= window.innerHeight * 0.5, d = (l) => l && /(auto|scroll|overlay)/.test(getComputedStyle(l).overflowY) && l.scrollHeight > l.clientHeight && w(l);
110
- let r = document.activeElement;
111
- for (; r && !d(r) && r !== document.body; ) r = r.parentElement;
112
- if (r = d(r) ? r : Array.from(document.querySelectorAll("*")).find(d) || document.scrollingElement || document.documentElement, r === document.scrollingElement || r === document.documentElement || r === document.body) {
113
- const l = window.scrollY, h = document.documentElement.scrollHeight - window.innerHeight;
114
- window.scrollBy(0, i);
115
- const T = window.scrollY, b = T - l;
116
- if (Math.abs(b) < 1)
117
- return i > 0 ? "⚠️ Already at the bottom of the page, cannot scroll down further." : "⚠️ Already at the top of the page, cannot scroll up further.";
118
- const u = i > 0 && T >= h - 1, f = i < 0 && T <= 1;
119
- return u ? `✅ Scrolled page by ${b}px. Reached the bottom of the page.` : f ? `✅ Scrolled page by ${b}px. Reached the top of the page.` : `✅ Scrolled page by ${b}px.`;
120
- } else {
121
- const l = r.scrollTop, h = r.scrollHeight - r.clientHeight;
122
- r.scrollBy({ top: i, behavior: "smooth" }), await waitFor(0.1);
123
- const T = r.scrollTop, b = T - l;
124
- if (Math.abs(b) < 1)
125
- return i > 0 ? `⚠️ Already at the bottom of container (${r.tagName}), cannot scroll down further.` : `⚠️ Already at the top of container (${r.tagName}), cannot scroll up further.`;
126
- const u = i > 0 && T >= h - 1, f = i < 0 && T <= 1;
127
- return u ? `✅ Scrolled container (${r.tagName}) by ${b}px. Reached the bottom.` : f ? `✅ Scrolled container (${r.tagName}) by ${b}px. Reached the top.` : `✅ Scrolled container (${r.tagName}) by ${b}px.`;
128
- }
129
- }
130
- async function scrollHorizontally(e, n, s) {
131
- if (s) {
132
- const l = s;
133
- console.log(
134
- "[SCROLL DEBUG] Starting direct container scroll for element:",
135
- l.tagName
136
- );
137
- let h = l, T = !1, b = null, u = 0, f = 0;
138
- const N = e ? n : -n;
139
- for (; h && f < 10; ) {
140
- const D = window.getComputedStyle(h), z = /(auto|scroll|overlay)/.test(D.overflowX), O = h.scrollWidth > h.clientWidth;
141
- if (console.log(
142
- "[SCROLL DEBUG] Checking element:",
143
- h.tagName,
144
- "hasScrollableX:",
145
- z,
146
- "canScrollHorizontally:",
147
- O,
148
- "scrollWidth:",
149
- h.scrollWidth,
150
- "clientWidth:",
151
- h.clientWidth
152
- ), z && O) {
153
- const R = h.scrollLeft, U = h.scrollWidth - h.clientWidth;
154
- let H = N / 3;
155
- H > 0 ? H = Math.min(H, U - R) : H = Math.max(H, -R), h.scrollLeft = R + H;
156
- const B = h.scrollLeft, _ = B - R;
157
- if (console.log(
158
- "[SCROLL DEBUG] Scroll attempt:",
159
- h.tagName,
160
- "before:",
161
- R,
162
- "after:",
163
- B,
164
- "delta:",
165
- _
166
- ), Math.abs(_) > 0.5) {
167
- T = !0, b = h, u = _, console.log(
168
- "[SCROLL DEBUG] Successfully scrolled container:",
169
- h.tagName,
170
- "delta:",
171
- _
172
- );
173
- break;
174
- }
175
- }
176
- if (h === document.body || h === document.documentElement)
177
- break;
178
- h = h.parentElement, f++;
179
- }
180
- return T ? `Scrolled container (${b == null ? void 0 : b.tagName}) horizontally by ${u}px` : `No horizontally scrollable container found for element (${l.tagName})`;
181
- }
182
- const i = e ? n : -n, w = (l) => l.clientWidth >= window.innerWidth * 0.5, d = (l) => l && /(auto|scroll|overlay)/.test(getComputedStyle(l).overflowX) && l.scrollWidth > l.clientWidth && w(l);
183
- let r = document.activeElement;
184
- for (; r && !d(r) && r !== document.body; ) r = r.parentElement;
185
- if (r = d(r) ? r : Array.from(document.querySelectorAll("*")).find(d) || document.scrollingElement || document.documentElement, r === document.scrollingElement || r === document.documentElement || r === document.body) {
186
- const l = window.scrollX, h = document.documentElement.scrollWidth - window.innerWidth;
187
- window.scrollBy(i, 0);
188
- const T = window.scrollX, b = T - l;
189
- if (Math.abs(b) < 1)
190
- return i > 0 ? "⚠️ Already at the right edge of the page, cannot scroll right further." : "⚠️ Already at the left edge of the page, cannot scroll left further.";
191
- const u = i > 0 && T >= h - 1, f = i < 0 && T <= 1;
192
- return u ? `✅ Scrolled page by ${b}px. Reached the right edge of the page.` : f ? `✅ Scrolled page by ${b}px. Reached the left edge of the page.` : `✅ Scrolled page horizontally by ${b}px.`;
193
- } else {
194
- const l = r.scrollLeft, h = r.scrollWidth - r.clientWidth;
195
- r.scrollBy({ left: i, behavior: "smooth" }), await waitFor(0.1);
196
- const T = r.scrollLeft, b = T - l;
197
- if (Math.abs(b) < 1)
198
- return i > 0 ? `⚠️ Already at the right edge of container (${r.tagName}), cannot scroll right further.` : `⚠️ Already at the left edge of container (${r.tagName}), cannot scroll left further.`;
199
- const u = i > 0 && T >= h - 1, f = i < 0 && T <= 1;
200
- return u ? `✅ Scrolled container (${r.tagName}) by ${b}px. Reached the right edge.` : f ? `✅ Scrolled container (${r.tagName}) by ${b}px. Reached the left edge.` : `✅ Scrolled container (${r.tagName}) horizontally by ${b}px.`;
201
- }
202
- }
203
- const VIEWPORT_EXPANSION = -1, domTree = (e = {
204
- doHighlightElements: !0,
205
- focusHighlightIndex: -1,
206
- viewportExpansion: 0,
207
- debugMode: !1,
208
- /**
209
- * @edit
210
- */
211
- /** @type {Element[]} */
212
- interactiveBlacklist: [],
213
- /** @type {Element[]} */
214
- interactiveWhitelist: [],
215
- highlightOpacity: 0.1,
216
- highlightLabelOpacity: 0.5
217
- }) => {
218
- const { interactiveBlacklist: n, interactiveWhitelist: s, highlightOpacity: i, highlightLabelOpacity: w } = e, { doHighlightElements: d, focusHighlightIndex: r, viewportExpansion: l, debugMode: h } = e;
219
- let T = 0;
220
- const b = /* @__PURE__ */ new WeakMap();
221
- function u(t, o) {
222
- !t || t.nodeType !== Node.ELEMENT_NODE || b.set(t, { ...b.get(t), ...o });
223
- }
224
- const f = {
225
- boundingRects: /* @__PURE__ */ new WeakMap(),
226
- clientRects: /* @__PURE__ */ new WeakMap(),
227
- computedStyles: /* @__PURE__ */ new WeakMap(),
228
- clearCache: () => {
229
- f.boundingRects = /* @__PURE__ */ new WeakMap(), f.clientRects = /* @__PURE__ */ new WeakMap(), f.computedStyles = /* @__PURE__ */ new WeakMap();
230
- }
231
- };
232
- function N(t) {
233
- if (!t) return null;
234
- if (f.boundingRects.has(t))
235
- return f.boundingRects.get(t);
236
- const o = t.getBoundingClientRect();
237
- return o && f.boundingRects.set(t, o), o;
238
- }
239
- function D(t) {
240
- if (!t) return null;
241
- if (f.computedStyles.has(t))
242
- return f.computedStyles.get(t);
243
- const o = window.getComputedStyle(t);
244
- return o && f.computedStyles.set(t, o), o;
245
- }
246
- function z(t) {
247
- if (!t) return null;
248
- if (f.clientRects.has(t))
249
- return f.clientRects.get(t);
250
- const o = t.getClientRects();
251
- return o && f.clientRects.set(t, o), o;
252
- }
253
- const O = {}, R = { current: 0 }, U = "playwright-highlight-container";
254
- function H(t, o, p = null) {
255
- if (!t) return o;
256
- const a = [];
257
- let c = null, x = 20, E = 16, I = null;
258
- try {
259
- let m = document.getElementById(U);
260
- m || (m = document.createElement("div"), m.id = U, m.style.position = "fixed", m.style.pointerEvents = "none", m.style.top = "0", m.style.left = "0", m.style.width = "100%", m.style.height = "100%", m.style.zIndex = "2147483640", m.style.backgroundColor = "transparent", document.body.appendChild(m));
261
- const $ = t.getClientRects();
262
- if (!$ || $.length === 0) return o;
263
- const A = [
264
- "#FF0000",
265
- "#00FF00",
266
- "#0000FF",
267
- "#FFA500",
268
- "#800080",
269
- "#008080",
270
- "#FF69B4",
271
- "#4B0082",
272
- "#FF4500",
273
- "#2E8B57",
274
- "#DC143C",
275
- "#4682B4"
276
- ], g = o % A.length;
277
- let y = A[g];
278
- const C = y + Math.floor(i * 255).toString(16).padStart(2, "0");
279
- y = y + Math.floor(w * 255).toString(16).padStart(2, "0");
280
- let M = { x: 0, y: 0 };
281
- if (p) {
282
- const k = p.getBoundingClientRect();
283
- M.x = k.left, M.y = k.top;
284
- }
285
- const V = document.createDocumentFragment();
286
- for (const k of $) {
287
- if (k.width === 0 || k.height === 0) continue;
288
- const S = document.createElement("div");
289
- S.style.position = "fixed", S.style.border = `2px solid ${y}`, S.style.backgroundColor = C, S.style.pointerEvents = "none", S.style.boxSizing = "border-box";
290
- const v = k.top + M.y, W = k.left + M.x;
291
- S.style.top = `${v}px`, S.style.left = `${W}px`, S.style.width = `${k.width}px`, S.style.height = `${k.height}px`, V.appendChild(S), a.push({ element: S, initialRect: k });
292
- }
293
- const G = $[0];
294
- if (w > 0) {
295
- c = document.createElement("div"), c.className = "playwright-highlight-label", c.style.position = "fixed", c.style.background = y, c.style.color = "white", c.style.padding = "1px 4px", c.style.borderRadius = "4px", c.style.fontSize = `${Math.min(12, Math.max(8, G.height / 2))}px`, c.textContent = o.toString(), x = c.offsetWidth > 0 ? c.offsetWidth : x, E = c.offsetHeight > 0 ? c.offsetHeight : E;
296
- const k = G.top + M.y, S = G.left + M.x;
297
- let v = k + 2, W = S + G.width - x - 2;
298
- (G.width < x + 4 || G.height < E + 4) && (v = k - E - 2, W = S + G.width - x, W < M.x && (W = S)), v = Math.max(0, Math.min(v, window.innerHeight - E)), W = Math.max(0, Math.min(W, window.innerWidth - x)), c.style.top = `${v}px`, c.style.left = `${W}px`, V.appendChild(c);
299
- }
300
- const j = ((k, S) => {
301
- let v = 0;
302
- return (...W) => {
303
- const P = performance.now();
304
- if (!(P - v < S))
305
- return v = P, k(...W);
306
- };
307
- })(() => {
308
- const k = t.getClientRects();
309
- let S = { x: 0, y: 0 };
310
- if (p) {
311
- const v = p.getBoundingClientRect();
312
- S.x = v.left, S.y = v.top;
313
- }
314
- if (a.forEach((v, W) => {
315
- if (W < k.length) {
316
- const P = k[W], Z = P.top + S.y, J = P.left + S.x;
317
- v.element.style.top = `${Z}px`, v.element.style.left = `${J}px`, v.element.style.width = `${P.width}px`, v.element.style.height = `${P.height}px`, v.element.style.display = P.width === 0 || P.height === 0 ? "none" : "block";
318
- } else
319
- v.element.style.display = "none";
320
- }), k.length < a.length)
321
- for (let v = k.length; v < a.length; v++)
322
- a[v].element.style.display = "none";
323
- if (c && k.length > 0) {
324
- const v = k[0], W = v.top + S.y, P = v.left + S.x;
325
- let Z = W + 2, J = P + v.width - x - 2;
326
- (v.width < x + 4 || v.height < E + 4) && (Z = W - E - 2, J = P + v.width - x, J < S.x && (J = P)), Z = Math.max(0, Math.min(Z, window.innerHeight - E)), J = Math.max(0, Math.min(J, window.innerWidth - x)), c.style.top = `${Z}px`, c.style.left = `${J}px`, c.style.display = "block";
327
- } else c && (c.style.display = "none");
328
- }, 16);
329
- return window.addEventListener("scroll", j, !0), window.addEventListener("resize", j), I = () => {
330
- window.removeEventListener("scroll", j, !0), window.removeEventListener("resize", j), a.forEach((k) => k.element.remove()), c && c.remove();
331
- }, m.appendChild(V), o + 1;
332
- } finally {
333
- I && (window._highlightCleanupFunctions = window._highlightCleanupFunctions || []).push(
334
- I
335
- );
336
- }
337
- }
338
- function B(t) {
339
- if (!t || t.nodeType !== Node.ELEMENT_NODE)
340
- return null;
341
- const o = D(t);
342
- if (!o) return null;
343
- const p = o.display;
344
- if (p === "inline" || p === "inline-block")
345
- return null;
346
- const a = o.overflowX, c = o.overflowY, x = a === "auto" || a === "scroll", E = c === "auto" || c === "scroll";
347
- if (!x && !E)
348
- return null;
349
- const I = t.scrollWidth - t.clientWidth, m = t.scrollHeight - t.clientHeight, $ = 4;
350
- if (I < $ && m < $ || !E && I < $ || !x && m < $)
351
- return null;
352
- const A = t.scrollTop, g = t.scrollLeft, y = t.scrollWidth - t.clientWidth - t.scrollLeft, C = t.scrollHeight - t.clientHeight - t.scrollTop, M = {
353
- top: A,
354
- right: y,
355
- bottom: C,
356
- left: g
357
- };
358
- return u(t, {
359
- scrollable: !0,
360
- scrollData: M
361
- }), M;
362
- }
363
- function _(t) {
364
- try {
365
- if (l === -1) {
366
- const E = t.parentElement;
367
- if (!E) return !1;
368
- try {
369
- return E.checkVisibility({
370
- checkOpacity: !0,
371
- checkVisibilityCSS: !0
372
- });
373
- } catch {
374
- const m = window.getComputedStyle(E);
375
- return m.display !== "none" && m.visibility !== "hidden" && m.opacity !== "0";
376
- }
377
- }
378
- const o = document.createRange();
379
- o.selectNodeContents(t);
380
- const p = o.getClientRects();
381
- if (!p || p.length === 0)
382
- return !1;
383
- let a = !1, c = !1;
384
- for (const E of p)
385
- if (E.width > 0 && E.height > 0 && (a = !0, !(E.bottom < -l || E.top > window.innerHeight + l || E.right < -l || E.left > window.innerWidth + l))) {
386
- c = !0;
387
- break;
388
- }
389
- if (!a || !c)
390
- return !1;
391
- const x = t.parentElement;
392
- if (!x) return !1;
393
- try {
394
- return x.checkVisibility({
395
- checkOpacity: !0,
396
- checkVisibilityCSS: !0
397
- });
398
- } catch {
399
- const I = window.getComputedStyle(x);
400
- return I.display !== "none" && I.visibility !== "hidden" && I.opacity !== "0";
401
- }
402
- } catch (o) {
403
- return console.warn("Error checking text node visibility:", o), !1;
404
- }
405
- }
406
- function ot(t) {
407
- if (!t || !t.tagName) return !1;
408
- const o = /* @__PURE__ */ new Set([
409
- "body",
410
- "div",
411
- "main",
412
- "article",
413
- "section",
414
- "nav",
415
- "header",
416
- "footer"
417
- ]), p = t.tagName.toLowerCase();
418
- return o.has(p) ? !0 : !(/* @__PURE__ */ new Set([
419
- "svg",
420
- "script",
421
- "style",
422
- "link",
423
- "meta",
424
- "noscript",
425
- "template"
426
- ])).has(p);
427
- }
428
- function X(t) {
429
- const o = D(t);
430
- return t.offsetWidth > 0 && t.offsetHeight > 0 && (o == null ? void 0 : o.visibility) !== "hidden" && (o == null ? void 0 : o.display) !== "none";
431
- }
432
- function L(t) {
433
- var C, M;
434
- if (!t || t.nodeType !== Node.ELEMENT_NODE || n.includes(t))
435
- return !1;
436
- if (s.includes(t))
437
- return !0;
438
- const o = t.tagName.toLowerCase(), p = D(t), a = /* @__PURE__ */ new Set([
439
- "pointer",
440
- // Link/clickable elements
441
- "move",
442
- // Movable elements
443
- "text",
444
- // Text selection
445
- "grab",
446
- // Grabbable elements
447
- "grabbing",
448
- // Currently grabbing
449
- "cell",
450
- // Table cell selection
451
- "copy",
452
- // Copy operation
453
- "alias",
454
- // Alias creation
455
- "all-scroll",
456
- // Scrollable content
457
- "col-resize",
458
- // Column resize
459
- "context-menu",
460
- // Context menu available
461
- "crosshair",
462
- // Precise selection
463
- "e-resize",
464
- // East resize
465
- "ew-resize",
466
- // East-west resize
467
- "help",
468
- // Help available
469
- "n-resize",
470
- // North resize
471
- "ne-resize",
472
- // Northeast resize
473
- "nesw-resize",
474
- // Northeast-southwest resize
475
- "ns-resize",
476
- // North-south resize
477
- "nw-resize",
478
- // Northwest resize
479
- "nwse-resize",
480
- // Northwest-southeast resize
481
- "row-resize",
482
- // Row resize
483
- "s-resize",
484
- // South resize
485
- "se-resize",
486
- // Southeast resize
487
- "sw-resize",
488
- // Southwest resize
489
- "vertical-text",
490
- // Vertical text selection
491
- "w-resize",
492
- // West resize
493
- "zoom-in",
494
- // Zoom in
495
- "zoom-out"
496
- // Zoom out
497
- ]), c = /* @__PURE__ */ new Set([
498
- "not-allowed",
499
- // Action not allowed
500
- "no-drop",
501
- // Drop not allowed
502
- "wait",
503
- // Processing
504
- "progress",
505
- // In progress
506
- "initial",
507
- // Initial value
508
- "inherit"
509
- // Inherited value
510
- //? Let's just include all potentially clickable elements that are not specifically blocked
511
- // 'none', // No cursor
512
- // 'default', // Default cursor
513
- // 'auto', // Browser default
514
- ]);
515
- function x(V) {
516
- return V.tagName.toLowerCase() === "html" ? !1 : !!(p != null && p.cursor && a.has(p.cursor));
517
- }
518
- if (x(t))
519
- return !0;
520
- const I = /* @__PURE__ */ new Set([
521
- "a",
522
- // Links
523
- "button",
524
- // Buttons
525
- "input",
526
- // All input types (text, checkbox, radio, etc.)
527
- "select",
528
- // Dropdown menus
529
- "textarea",
530
- // Text areas
531
- "details",
532
- // Expandable details
533
- "summary",
534
- // Summary element (clickable part of details)
535
- "label",
536
- // Form labels (often clickable)
537
- "option",
538
- // Select options
539
- "optgroup",
540
- // Option groups
541
- "fieldset",
542
- // Form fieldsets (can be interactive with legend)
543
- "legend"
544
- // Fieldset legends
545
- ]), m = /* @__PURE__ */ new Set([
546
- "disabled",
547
- // Standard disabled attribute
548
- // 'aria-disabled', // ARIA disabled state
549
- "readonly"
550
- // Read-only state
551
- // 'aria-readonly', // ARIA read-only state
552
- // 'aria-hidden', // Hidden from accessibility
553
- // 'hidden', // Hidden attribute
554
- // 'inert', // Inert attribute
555
- // 'aria-inert', // ARIA inert state
556
- // 'tabindex="-1"', // Removed from tab order
557
- // 'aria-hidden="true"' // Hidden from screen readers
558
- ]);
559
- if (I.has(o)) {
560
- if (p != null && p.cursor && c.has(p.cursor))
561
- return !1;
562
- for (const V of m)
563
- if (t.hasAttribute(V) || t.getAttribute(V) === "true" || t.getAttribute(V) === "")
564
- return !1;
565
- return !(t.disabled || t.readOnly || t.inert);
566
- }
567
- const $ = t.getAttribute("role"), A = t.getAttribute("aria-role");
568
- if (t.getAttribute("contenteditable") === "true" || t.isContentEditable || t.classList && (t.classList.contains("button") || t.classList.contains("dropdown-toggle") || t.getAttribute("data-index") || t.getAttribute("data-toggle") === "dropdown" || t.getAttribute("aria-haspopup") === "true"))
569
- return !0;
570
- const g = /* @__PURE__ */ new Set([
571
- "button",
572
- // Directly clickable element
573
- // 'link', // Clickable link
574
- "menu",
575
- // Menu container (ARIA menus)
576
- "menubar",
577
- // Menu bar container
578
- "menuitem",
579
- // Clickable menu item
580
- "menuitemradio",
581
- // Radio-style menu item (selectable)
582
- "menuitemcheckbox",
583
- // Checkbox-style menu item (toggleable)
584
- "radio",
585
- // Radio button (selectable)
586
- "checkbox",
587
- // Checkbox (toggleable)
588
- "tab",
589
- // Tab (clickable to switch content)
590
- "switch",
591
- // Toggle switch (clickable to change state)
592
- "slider",
593
- // Slider control (draggable)
594
- "spinbutton",
595
- // Number input with up/down controls
596
- "combobox",
597
- // Dropdown with text input
598
- "searchbox",
599
- // Search input field
600
- "textbox",
601
- // Text input field
602
- "listbox",
603
- // Selectable list
604
- "option",
605
- // Selectable option in a list
606
- "scrollbar"
607
- // Scrollable control
608
- ]);
609
- if (I.has(o) || $ && g.has($) || A && g.has(A)) return !0;
610
- try {
611
- if (typeof getEventListeners == "function") {
612
- const q = getEventListeners(t), nt = ["click", "mousedown", "mouseup", "dblclick"];
613
- for (const j of nt)
614
- if (q[j] && q[j].length > 0)
615
- return !0;
616
- }
617
- const V = ((M = (C = t == null ? void 0 : t.ownerDocument) == null ? void 0 : C.defaultView) == null ? void 0 : M.getEventListenersForNode) || window.getEventListenersForNode;
618
- if (typeof V == "function") {
619
- const q = V(t), nt = [
620
- "click",
621
- "mousedown",
622
- "mouseup",
623
- "keydown",
624
- "keyup",
625
- "submit",
626
- "change",
627
- "input",
628
- "focus",
629
- "blur"
630
- ];
631
- for (const j of nt)
632
- for (const k of q)
633
- if (k.type === j)
634
- return !0;
635
- }
636
- const G = ["onclick", "onmousedown", "onmouseup", "ondblclick"];
637
- for (const q of G)
638
- if (t.hasAttribute(q) || typeof t[q] == "function")
639
- return !0;
640
- } catch {
641
- }
642
- return !!B(t);
643
- }
644
- function et(t) {
645
- if (l === -1)
646
- return !0;
647
- const o = z(t);
648
- if (!o || o.length === 0)
649
- return !1;
650
- let p = !1;
651
- for (const m of o)
652
- if (m.width > 0 && m.height > 0 && !// Only check non-empty rects
653
- (m.bottom < -l || m.top > window.innerHeight + l || m.right < -l || m.left > window.innerWidth + l)) {
654
- p = !0;
655
- break;
656
- }
657
- if (!p)
658
- return !1;
659
- if (t.ownerDocument !== window.document)
660
- return !0;
661
- let c = Array.from(o).find((m) => m.width > 0 && m.height > 0);
662
- if (!c)
663
- return !1;
664
- const x = t.getRootNode();
665
- if (x instanceof ShadowRoot) {
666
- const m = c.left + c.width / 2, $ = c.top + c.height / 2;
667
- try {
668
- const A = x.elementFromPoint(m, $);
669
- if (!A) return !1;
670
- let g = A;
671
- for (; g && g !== x; ) {
672
- if (g === t) return !0;
673
- g = g.parentElement;
674
- }
675
- return !1;
676
- } catch {
677
- return !0;
678
- }
679
- }
680
- const E = 5;
681
- return [
682
- // Initially only this was used, but it was not enough
683
- { x: c.left + c.width / 2, y: c.top + c.height / 2 },
684
- { x: c.left + E, y: c.top + E },
685
- // top left
686
- // { x: rect.right - margin, y: rect.top + margin }, // top right
687
- // { x: rect.left + margin, y: rect.bottom - margin }, // bottom left
688
- { x: c.right - E, y: c.bottom - E }
689
- // bottom right
690
- ].some(({ x: m, y: $ }) => {
691
- try {
692
- const A = document.elementFromPoint(m, $);
693
- if (!A) return !1;
694
- let g = A;
695
- for (; g && g !== document.documentElement; ) {
696
- if (g === t) return !0;
697
- g = g.parentElement;
698
- }
699
- return !1;
700
- } catch {
701
- return !0;
702
- }
703
- });
704
- }
705
- function it(t, o) {
706
- if (o === -1)
707
- return !0;
708
- const p = t.getClientRects();
709
- if (!p || p.length === 0) {
710
- const a = N(t);
711
- return !a || a.width === 0 || a.height === 0 ? !1 : !(a.bottom < -o || a.top > window.innerHeight + o || a.right < -o || a.left > window.innerWidth + o);
712
- }
713
- for (const a of p)
714
- if (!(a.width === 0 || a.height === 0) && !(a.bottom < -o || a.top > window.innerHeight + o || a.right < -o || a.left > window.innerWidth + o))
715
- return !0;
716
- return !1;
717
- }
718
- function F(t) {
719
- if (!t || t.nodeType !== Node.ELEMENT_NODE) return !1;
720
- const o = t.tagName.toLowerCase();
721
- return (/* @__PURE__ */ new Set([
722
- "a",
723
- "button",
724
- "input",
725
- "select",
726
- "textarea",
727
- "details",
728
- "summary",
729
- "label"
730
- ])).has(o) ? !0 : t.hasAttribute("onclick") || t.hasAttribute("role") || t.hasAttribute("tabindex") || t.hasAttribute("aria-") || t.hasAttribute("data-action") || t.getAttribute("contenteditable") === "true";
731
- }
732
- const Y = /* @__PURE__ */ new Set([
733
- "a",
734
- "button",
735
- "input",
736
- "select",
737
- "textarea",
738
- "summary",
739
- "details",
740
- "label",
741
- "option"
742
- ]), K = /* @__PURE__ */ new Set([
743
- "button",
744
- "link",
745
- "menuitem",
746
- "menuitemradio",
747
- "menuitemcheckbox",
748
- "radio",
749
- "checkbox",
750
- "tab",
751
- "switch",
752
- "slider",
753
- "spinbutton",
754
- "combobox",
755
- "searchbox",
756
- "textbox",
757
- "listbox",
758
- "option",
759
- "scrollbar"
760
- ]);
761
- function tt(t) {
762
- if (!t || t.nodeType !== Node.ELEMENT_NODE || !X(t)) return !1;
763
- const o = t.hasAttribute("role") || t.hasAttribute("tabindex") || t.hasAttribute("onclick") || typeof t.onclick == "function", p = /\b(btn|clickable|menu|item|entry|link)\b/i.test(
764
- t.className || ""
765
- ), a = !!t.closest('button,a,[role="button"],.menu,.dropdown,.list,.toolbar'), c = [...t.children].some(X), x = t.parentElement && t.parentElement.isSameNode(document.body);
766
- return (L(t) || o || p) && c && a && !x;
767
- }
768
- function rt(t) {
769
- var a, c;
770
- if (!t || t.nodeType !== Node.ELEMENT_NODE)
771
- return !1;
772
- const o = t.tagName.toLowerCase(), p = t.getAttribute("role");
773
- if (o === "iframe" || Y.has(o) || p && K.has(p) || t.isContentEditable || t.getAttribute("contenteditable") === "true" || t.hasAttribute("data-testid") || t.hasAttribute("data-cy") || t.hasAttribute("data-test") || t.hasAttribute("onclick") || typeof t.onclick == "function")
774
- return !0;
775
- try {
776
- const x = ((c = (a = t == null ? void 0 : t.ownerDocument) == null ? void 0 : a.defaultView) == null ? void 0 : c.getEventListenersForNode) || window.getEventListenersForNode;
777
- if (typeof x == "function") {
778
- const I = x(t), m = [
779
- "click",
780
- "mousedown",
781
- "mouseup",
782
- "keydown",
783
- "keyup",
784
- "submit",
785
- "change",
786
- "input",
787
- "focus",
788
- "blur"
789
- ];
790
- for (const $ of m)
791
- for (const A of I)
792
- if (A.type === $)
793
- return !0;
794
- }
795
- if ([
796
- "onmousedown",
797
- "onmouseup",
798
- "onkeydown",
799
- "onkeyup",
800
- "onsubmit",
801
- "onchange",
802
- "oninput",
803
- "onfocus",
804
- "onblur"
805
- ].some((I) => t.hasAttribute(I)))
806
- return !0;
807
- } catch {
808
- }
809
- return !!tt(t);
810
- }
811
- function st(t, o, p, a) {
812
- if (!t.isInteractive) return !1;
813
- let c = !1;
814
- return a ? rt(o) ? c = !0 : c = !1 : c = !0, c && (t.isInViewport = it(o, l), (t.isInViewport || l === -1) && (t.highlightIndex = T++, d)) ? (r >= 0 ? r === t.highlightIndex && H(o, t.highlightIndex, p) : H(o, t.highlightIndex, p), !0) : !1;
815
- }
816
- function Q(t, o = null, p = !1) {
817
- var E, I, m, $, A;
818
- if (!t || t.id === U || t.nodeType !== Node.ELEMENT_NODE && t.nodeType !== Node.TEXT_NODE || !t || t.id === U || ((E = t.dataset) == null ? void 0 : E.browserUseIgnore) === "true" || t.getAttribute && t.getAttribute("aria-hidden") === "true")
819
- return null;
820
- if (t === document.body) {
821
- const g = {
822
- tagName: "body",
823
- attributes: {},
824
- xpath: "/body",
825
- children: []
826
- };
827
- for (const C of t.childNodes) {
828
- const M = Q(C, o, !1);
829
- M && g.children.push(M);
830
- }
831
- const y = `${R.current++}`;
832
- return O[y] = g, y;
833
- }
834
- if (t.nodeType !== Node.ELEMENT_NODE && t.nodeType !== Node.TEXT_NODE)
835
- return null;
836
- if (t.nodeType === Node.TEXT_NODE) {
837
- const g = (I = t.textContent) == null ? void 0 : I.trim();
838
- if (!g)
839
- return null;
840
- const y = t.parentElement;
841
- if (!y || y.tagName.toLowerCase() === "script")
842
- return null;
843
- const C = `${R.current++}`;
844
- return O[C] = {
845
- type: "TEXT_NODE",
846
- text: g,
847
- isVisible: _(t)
848
- }, C;
849
- }
850
- if (t.nodeType === Node.ELEMENT_NODE && !ot(t))
851
- return null;
852
- if (l !== -1 && !t.shadowRoot) {
853
- const g = N(t), y = D(t), C = y && (y.position === "fixed" || y.position === "sticky"), M = t.offsetWidth > 0 || t.offsetHeight > 0;
854
- if (!g || !C && !M && (g.bottom < -l || g.top > window.innerHeight + l || g.right < -l || g.left > window.innerWidth + l))
855
- return null;
856
- }
857
- const a = {
858
- tagName: t.tagName.toLowerCase(),
859
- attributes: {},
860
- /**
861
- * @edit no need for xpath
862
- */
863
- // xpath: getXPathTree(node, true),
864
- children: []
865
- };
866
- if (F(t) || t.tagName.toLowerCase() === "iframe" || t.tagName.toLowerCase() === "body") {
867
- const g = ((m = t.getAttributeNames) == null ? void 0 : m.call(t)) || [];
868
- for (const y of g) {
869
- const C = t.getAttribute(y);
870
- a.attributes[y] = C;
871
- }
872
- t.tagName.toLowerCase() === "input" && (t.type === "checkbox" || t.type === "radio") && (a.attributes.checked = t.checked ? "true" : "false");
873
- }
874
- let c = !1;
875
- if (t.nodeType === Node.ELEMENT_NODE && (a.isVisible = X(t), a.isVisible)) {
876
- a.isTopElement = et(t);
877
- const g = t.getAttribute("role"), y = g === "menu" || g === "menubar" || g === "listbox";
878
- (a.isTopElement || y) && (a.isInteractive = L(t), c = st(a, t, o, p), a.ref = t);
879
- }
880
- if (t.tagName) {
881
- const g = t.tagName.toLowerCase();
882
- if (g === "iframe")
883
- try {
884
- const y = t.contentDocument || (($ = t.contentWindow) == null ? void 0 : $.document);
885
- if (y)
886
- for (const C of y.childNodes) {
887
- const M = Q(C, t, !1);
888
- M && a.children.push(M);
889
- }
890
- } catch (y) {
891
- console.warn("Unable to access iframe:", y);
892
- }
893
- else if (t.isContentEditable || t.getAttribute("contenteditable") === "true" || t.id === "tinymce" || t.classList.contains("mce-content-body") || g === "body" && ((A = t.getAttribute("data-id")) != null && A.startsWith("mce_")))
894
- for (const y of t.childNodes) {
895
- const C = Q(y, o, c);
896
- C && a.children.push(C);
897
- }
898
- else {
899
- if (t.shadowRoot) {
900
- a.shadowRoot = !0;
901
- for (const y of t.shadowRoot.childNodes) {
902
- const C = Q(y, o, c);
903
- C && a.children.push(C);
904
- }
905
- }
906
- for (const y of t.childNodes) {
907
- const M = Q(y, o, c || p);
908
- M && a.children.push(M);
909
- }
910
- }
911
- }
912
- if (a.tagName === "a" && a.children.length === 0 && !a.attributes.href) {
913
- const g = N(t);
914
- if (!(g && g.width > 0 && g.height > 0 || t.offsetWidth > 0 || t.offsetHeight > 0))
915
- return null;
916
- }
917
- a.extra = b.get(t) || null;
918
- const x = `${R.current++}`;
919
- return O[x] = a, x;
920
- }
921
- const lt = Q(document.body);
922
- return f.clearCache(), { rootId: lt, map: O };
923
- }, newElementsCache = /* @__PURE__ */ new WeakMap();
924
- function getFlatTree(e) {
925
- const n = [];
926
- for (const d of e.interactiveBlacklist || [])
927
- typeof d == "function" ? n.push(d()) : n.push(d);
928
- const s = [];
929
- for (const d of e.interactiveWhitelist || [])
930
- typeof d == "function" ? s.push(d()) : s.push(d);
931
- const i = domTree({
932
- doHighlightElements: !0,
933
- debugMode: !0,
934
- focusHighlightIndex: -1,
935
- viewportExpansion: VIEWPORT_EXPANSION,
936
- interactiveBlacklist: n,
937
- interactiveWhitelist: s,
938
- highlightOpacity: e.highlightOpacity ?? 0,
939
- highlightLabelOpacity: e.highlightLabelOpacity ?? 0.1
940
- }), w = window.location.href;
941
- for (const d in i.map) {
942
- const r = i.map[d];
943
- if (r.isInteractive && r.ref) {
944
- const l = r.ref;
945
- newElementsCache.has(l) || (newElementsCache.set(l, w), r.isNew = !0);
946
- }
947
- }
948
- return i;
949
- }
950
- function flatTreeToString(e, n) {
951
- const s = [
952
- "title",
953
- "type",
954
- "checked",
955
- "name",
956
- "role",
957
- "value",
958
- "placeholder",
959
- "data-date-format",
960
- "alt",
961
- "aria-label",
962
- "aria-expanded",
963
- "data-state",
964
- "aria-checked",
965
- // @edit added for better form handling
966
- "id",
967
- "for",
968
- // for jump check
969
- "target",
970
- // absolute 定位的下拉菜单
971
- "aria-haspopup",
972
- "aria-controls",
973
- "aria-owns"
974
- ], i = [...n || [], ...s], w = (u, f) => u.length > f ? u.substring(0, f) + "..." : u, d = (u) => {
975
- const f = e.map[u];
976
- if (!f) return null;
977
- if (f.type === "TEXT_NODE") {
978
- const N = f;
979
- return {
980
- type: "text",
981
- text: N.text,
982
- isVisible: N.isVisible,
983
- parent: null,
984
- children: []
985
- };
986
- } else {
987
- const N = f, D = [];
988
- if (N.children)
989
- for (const z of N.children) {
990
- const O = d(z);
991
- O && (O.parent = null, D.push(O));
992
- }
993
- return {
994
- type: "element",
995
- tagName: N.tagName,
996
- attributes: N.attributes ?? {},
997
- isVisible: N.isVisible ?? !1,
998
- isInteractive: N.isInteractive ?? !1,
999
- isTopElement: N.isTopElement ?? !1,
1000
- isNew: N.isNew ?? !1,
1001
- highlightIndex: N.highlightIndex,
1002
- parent: null,
1003
- children: D,
1004
- extra: N.extra ?? {}
1005
- };
1006
- }
1007
- }, r = (u, f = null) => {
1008
- u.parent = f;
1009
- for (const N of u.children)
1010
- r(N, u);
1011
- }, l = d(e.rootId);
1012
- if (!l) return "";
1013
- r(l);
1014
- const h = (u) => {
1015
- let f = u.parent;
1016
- for (; f; ) {
1017
- if (f.type === "element" && f.highlightIndex !== void 0)
1018
- return !0;
1019
- f = f.parent;
1020
- }
1021
- return !1;
1022
- }, T = (u, f, N) => {
1023
- var O, R, U, H;
1024
- let D = f;
1025
- const z = " ".repeat(f);
1026
- if (u.type === "element") {
1027
- if (u.highlightIndex !== void 0) {
1028
- D += 1;
1029
- const B = getAllTextTillNextClickableElement(u);
1030
- let _ = "";
1031
- if (i.length > 0 && u.attributes) {
1032
- const L = {};
1033
- for (const F of i) {
1034
- const Y = u.attributes[F];
1035
- Y && Y.trim() !== "" && (L[F] = Y.trim());
1036
- }
1037
- const et = i.filter((F) => F in L);
1038
- if (et.length > 1) {
1039
- const F = /* @__PURE__ */ new Set(), Y = {};
1040
- for (const K of et) {
1041
- const tt = L[K];
1042
- tt.length > 5 && (tt in Y ? F.add(K) : Y[tt] = K);
1043
- }
1044
- for (const K of F)
1045
- delete L[K];
1046
- }
1047
- L.role === u.tagName && delete L.role;
1048
- const it = ["aria-label", "placeholder", "title"];
1049
- for (const F of it)
1050
- L[F] && L[F].toLowerCase().trim() === B.toLowerCase().trim() && delete L[F];
1051
- Object.keys(L).length > 0 && (_ = Object.entries(L).map(([F, Y]) => `${F}=${w(Y, 20)}`).join(" "));
1052
- }
1053
- const ot = u.isNew ? `*[${u.highlightIndex}]` : `[${u.highlightIndex}]`;
1054
- let X = `${z}${ot}<${u.tagName ?? ""}`;
1055
- if (_ && (X += ` ${_}`), u.extra && u.extra.scrollable) {
1056
- let L = "";
1057
- (O = u.extra.scrollData) != null && O.left && (L += `left=${u.extra.scrollData.left}, `), (R = u.extra.scrollData) != null && R.top && (L += `top=${u.extra.scrollData.top}, `), (U = u.extra.scrollData) != null && U.right && (L += `right=${u.extra.scrollData.right}, `), (H = u.extra.scrollData) != null && H.bottom && (L += `bottom=${u.extra.scrollData.bottom}`), X += ` data-scrollable="${L}"`;
1058
- }
1059
- if (B) {
1060
- const L = B.trim();
1061
- _ || (X += " "), X += `>${L}`;
1062
- } else _ || (X += " ");
1063
- X += " />", N.push(X);
1064
- }
1065
- for (const B of u.children)
1066
- T(B, D, N);
1067
- } else if (u.type === "text") {
1068
- if (h(u))
1069
- return;
1070
- u.parent && u.parent.type === "element" && u.parent.isVisible && u.parent.isTopElement && N.push(`${z}${u.text ?? ""}`);
1071
- }
1072
- }, b = [];
1073
- return T(l, 0, b), b.join(`
1074
- `);
1075
- }
1076
- const getAllTextTillNextClickableElement = (e, n = -1) => {
1077
- const s = [], i = (w, d) => {
1078
- if (!(n !== -1 && d > n) && !(w.type === "element" && w !== e && w.highlightIndex !== void 0)) {
1079
- if (w.type === "text" && w.text)
1080
- s.push(w.text);
1081
- else if (w.type === "element")
1082
- for (const r of w.children)
1083
- i(r, d + 1);
1084
- }
1085
- };
1086
- return i(e, 0), s.join(`
1087
- `).trim();
1088
- };
1089
- function getSelectorMap(e) {
1090
- const n = /* @__PURE__ */ new Map(), s = Object.keys(e.map);
1091
- for (const i of s) {
1092
- const w = e.map[i];
1093
- w.isInteractive && typeof w.highlightIndex == "number" && n.set(w.highlightIndex, w);
1094
- }
1095
- return n;
1096
- }
1097
- function getElementTextMap(e) {
1098
- const n = e.split(`
1099
- `).map((i) => i.trim()).filter((i) => i.length > 0), s = /* @__PURE__ */ new Map();
1100
- for (const i of n) {
1101
- const d = /^\[(\d+)\]<[^>]+>([^<]*)/.exec(i);
1102
- if (d) {
1103
- const r = parseInt(d[1], 10);
1104
- s.set(r, i);
1105
- }
1106
- }
1107
- return s;
1108
- }
1109
- function cleanUpHighlights() {
1110
- const e = window._highlightCleanupFunctions || [];
1111
- for (const n of e)
1112
- typeof n == "function" && n();
1113
- window._highlightCleanupFunctions = [];
1114
- }
1115
- window.addEventListener("popstate", () => {
1116
- cleanUpHighlights();
1117
- });
1118
- window.addEventListener("hashchange", () => {
1119
- cleanUpHighlights();
1120
- });
1121
- window.addEventListener("beforeunload", () => {
1122
- cleanUpHighlights();
1123
- });
1124
- const navigation = window.navigation;
1125
- if (navigation && typeof navigation.addEventListener == "function")
1126
- navigation.addEventListener("navigate", () => {
1127
- cleanUpHighlights();
1128
- });
1129
- else {
1130
- let e = window.location.href;
1131
- setInterval(() => {
1132
- window.location.href !== e && (e = window.location.href, cleanUpHighlights());
1133
- }, 500);
1134
- }
1135
- function getPageInfo() {
1136
- const e = window.innerWidth, n = window.innerHeight, s = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth || 0), i = Math.max(
1137
- document.documentElement.scrollHeight,
1138
- document.body.scrollHeight || 0
1139
- ), w = window.scrollX || window.pageXOffset || document.documentElement.scrollLeft || 0, d = window.scrollY || window.pageYOffset || document.documentElement.scrollTop || 0, r = Math.max(0, i - (window.innerHeight + d)), l = Math.max(0, s - (window.innerWidth + w));
1140
- return {
1141
- // Current viewport dimensions
1142
- viewport_width: e,
1143
- viewport_height: n,
1144
- // Total page dimensions
1145
- page_width: s,
1146
- page_height: i,
1147
- // Current scroll position
1148
- scroll_x: w,
1149
- scroll_y: d,
1150
- pixels_above: d,
1151
- pixels_below: r,
1152
- pages_above: n > 0 ? d / n : 0,
1153
- pages_below: n > 0 ? r / n : 0,
1154
- total_pages: n > 0 ? i / n : 0,
1155
- current_page_position: d / Math.max(1, i - n),
1156
- pixels_left: w,
1157
- pixels_right: l
1158
- };
1159
- }
1160
- function patchReact(e) {
1161
- const n = document.querySelectorAll(
1162
- '[data-reactroot], [data-reactid], [data-react-checksum], #root, #app, [id^="root-"], [id^="app-"], #adex-wrapper, #adex-root'
1163
- );
1164
- for (const s of n)
1165
- s.setAttribute("data-page-agent-not-interactive", "true");
1166
- }
1167
- class PageController extends EventTarget {
1168
- constructor(e = {}) {
1169
- super(), this.flatTree = null, this.selectorMap = /* @__PURE__ */ new Map(), this.elementTextMap = /* @__PURE__ */ new Map(), this.simplifiedHTML = "<EMPTY>", this.lastTimeUpdate = 0, this.isIndexed = !1, this.mask = null, this.maskReady = null, this.config = e, patchReact(), e.enableMask && this.initMask();
1170
- }
1171
- /**
1172
- * Initialize mask asynchronously (dynamic import to avoid CSS loading in Node)
1173
- */
1174
- initMask() {
1175
- this.maskReady === null && (this.maskReady = (async () => {
1176
- const { SimulatorMask: e } = await import("./SimulatorMask-74sRLkJv.js");
1177
- this.mask = new e();
1178
- })());
1179
- }
1180
- // ======= State Queries =======
1181
- /**
1182
- * Get current page URL
1183
- */
1184
- async getCurrentUrl() {
1185
- return window.location.href;
1186
- }
1187
- /**
1188
- * Get last tree update timestamp
1189
- */
1190
- async getLastUpdateTime() {
1191
- return this.lastTimeUpdate;
1192
- }
1193
- /**
1194
- * Get structured browser state for LLM consumption.
1195
- * Automatically calls updateTree() to refresh the DOM state.
1196
- */
1197
- async getBrowserState() {
1198
- const e = window.location.href, n = document.title, s = getPageInfo(), i = this.config.viewportExpansion ?? VIEWPORT_EXPANSION;
1199
- await this.updateTree();
1200
- const w = this.simplifiedHTML, d = `Current Page: [${n}](${e})`, r = `Page info: ${s.viewport_width}x${s.viewport_height}px viewport, ${s.page_width}x${s.page_height}px total page size, ${s.pages_above.toFixed(1)} pages above, ${s.pages_below.toFixed(1)} pages below, ${s.total_pages.toFixed(1)} total pages, at ${(s.current_page_position * 100).toFixed(0)}% of page`, l = i === -1 ? "Interactive elements from top layer of the current page (full page):" : "Interactive elements from top layer of the current page inside the viewport:", T = s.pixels_above > 4 && i !== -1 ? `... ${s.pixels_above} pixels above (${s.pages_above.toFixed(1)} pages) - scroll to see more ...` : "[Start of page]", b = `${d}
1201
- ${r}
1202
-
1203
- ${l}
1204
-
1205
- ${T}`, f = s.pixels_below > 4 && i !== -1 ? `... ${s.pixels_below} pixels below (${s.pages_below.toFixed(1)} pages) - scroll to see more ...` : "[End of page]";
1206
- return { url: e, title: n, header: b, content: w, footer: f };
1207
- }
1208
- // ======= DOM Tree Operations =======
1209
- /**
1210
- * Update DOM tree, returns simplified HTML for LLM.
1211
- * This is the main method to refresh the page state.
1212
- * Automatically bypasses mask during DOM extraction if enabled.
1213
- */
1214
- async updateTree() {
1215
- this.dispatchEvent(new Event("beforeUpdate")), this.lastTimeUpdate = Date.now(), this.mask && (this.mask.wrapper.style.pointerEvents = "none"), cleanUpHighlights();
1216
- const e = [
1217
- ...this.config.interactiveBlacklist || [],
1218
- ...document.querySelectorAll("[data-page-agent-not-interactive]").values()
1219
- ];
1220
- return this.flatTree = getFlatTree({
1221
- ...this.config,
1222
- interactiveBlacklist: e
1223
- }), this.simplifiedHTML = flatTreeToString(this.flatTree, this.config.include_attributes), this.selectorMap.clear(), this.selectorMap = getSelectorMap(this.flatTree), this.elementTextMap.clear(), this.elementTextMap = getElementTextMap(this.simplifiedHTML), this.isIndexed = !0, this.mask && (this.mask.wrapper.style.pointerEvents = "auto"), this.dispatchEvent(new Event("afterUpdate")), this.simplifiedHTML;
1224
- }
1225
- /**
1226
- * Clean up all element highlights
1227
- */
1228
- async cleanUpHighlights() {
1229
- cleanUpHighlights();
1230
- }
1231
- // ======= Element Actions =======
1232
- /**
1233
- * Ensure the tree has been indexed before any index-based operation.
1234
- * Throws if updateTree() hasn't been called yet.
1235
- */
1236
- assertIndexed() {
1237
- if (!this.isIndexed)
1238
- throw new Error("DOM tree not indexed yet. Can not perform actions on elements.");
1239
- }
1240
- /**
1241
- * Click element by index
1242
- */
1243
- async clickElement(e) {
1244
- try {
1245
- this.assertIndexed();
1246
- const n = getElementByIndex(this.selectorMap, e), s = this.elementTextMap.get(e);
1247
- return await clickElement(n), n instanceof HTMLAnchorElement && n.target === "_blank" ? {
1248
- success: !0,
1249
- message: `✅ Clicked element (${s ?? e}). ⚠️ Link opens in a new tab. You are not capable of reading new tabs.`
1250
- } : {
1251
- success: !0,
1252
- message: `✅ Clicked element (${s ?? e}).`
1253
- };
1254
- } catch (n) {
1255
- return {
1256
- success: !1,
1257
- message: `❌ Failed to click element: ${n}`
1258
- };
1259
- }
1260
- }
1261
- /**
1262
- * Input text into element by index
1263
- */
1264
- async inputText(e, n) {
1265
- try {
1266
- this.assertIndexed();
1267
- const s = getElementByIndex(this.selectorMap, e), i = this.elementTextMap.get(e);
1268
- return await inputTextElement(s, n), {
1269
- success: !0,
1270
- message: `✅ Input text (${n}) into element (${i ?? e}).`
1271
- };
1272
- } catch (s) {
1273
- return {
1274
- success: !1,
1275
- message: `❌ Failed to input text: ${s}`
1276
- };
1277
- }
1278
- }
1279
- /**
1280
- * Select dropdown option by index and option text
1281
- */
1282
- async selectOption(e, n) {
1283
- try {
1284
- this.assertIndexed();
1285
- const s = getElementByIndex(this.selectorMap, e), i = this.elementTextMap.get(e);
1286
- return await selectOptionElement(s, n), {
1287
- success: !0,
1288
- message: `✅ Selected option (${n}) in element (${i ?? e}).`
1289
- };
1290
- } catch (s) {
1291
- return {
1292
- success: !1,
1293
- message: `❌ Failed to select option: ${s}`
1294
- };
1295
- }
1296
- }
1297
- /**
1298
- * Scroll vertically
1299
- */
1300
- async scroll(e) {
1301
- try {
1302
- const { down: n, numPages: s, pixels: i, index: w } = e;
1303
- this.assertIndexed();
1304
- const d = i ?? s * (n ? 1 : -1) * window.innerHeight, r = w !== void 0 ? getElementByIndex(this.selectorMap, w) : null;
1305
- return {
1306
- success: !0,
1307
- message: await scrollVertically(n, d, r)
1308
- };
1309
- } catch (n) {
1310
- return {
1311
- success: !1,
1312
- message: `❌ Failed to scroll: ${n}`
1313
- };
1314
- }
1315
- }
1316
- /**
1317
- * Scroll horizontally
1318
- */
1319
- async scrollHorizontally(e) {
1320
- try {
1321
- const { right: n, pixels: s, index: i } = e;
1322
- this.assertIndexed();
1323
- const w = s * (n ? 1 : -1), d = i !== void 0 ? getElementByIndex(this.selectorMap, i) : null;
1324
- return {
1325
- success: !0,
1326
- message: await scrollHorizontally(n, w, d)
1327
- };
1328
- } catch (n) {
1329
- return {
1330
- success: !1,
1331
- message: `❌ Failed to scroll horizontally: ${n}`
1332
- };
1333
- }
1334
- }
1335
- /**
1336
- * Execute arbitrary JavaScript on the page
1337
- */
1338
- async executeJavascript(script) {
1339
- try {
1340
- const asyncFunction = eval(`(async () => { ${script} })`), result = await asyncFunction();
1341
- return {
1342
- success: !0,
1343
- message: `✅ Executed JavaScript. Result: ${result}`
1344
- };
1345
- } catch (e) {
1346
- return {
1347
- success: !1,
1348
- message: `❌ Error executing JavaScript: ${e}`
1349
- };
1350
- }
1351
- }
1352
- // ======= Mask Operations =======
1353
- /**
1354
- * Show the visual mask overlay.
1355
- * Only works after mask is setup.
1356
- */
1357
- async showMask() {
1358
- var e;
1359
- await this.maskReady, (e = this.mask) == null || e.show();
1360
- }
1361
- /**
1362
- * Hide the visual mask overlay.
1363
- * Only works after mask is setup.
1364
- */
1365
- async hideMask() {
1366
- var e;
1367
- await this.maskReady, (e = this.mask) == null || e.hide();
1368
- }
1369
- /**
1370
- * Dispose and clean up resources
1371
- */
1372
- dispose() {
1373
- var e;
1374
- cleanUpHighlights(), this.flatTree = null, this.selectorMap.clear(), this.elementTextMap.clear(), this.simplifiedHTML = "<EMPTY>", this.isIndexed = !1, (e = this.mask) == null || e.dispose(), this.mask = null;
1375
- }
1376
- }
1377
- export {
1378
- PageController
1379
- };