@xpert-ai/chatkit-host-automation 0.3.4 → 0.3.5

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +505 -0
  2. package/dist/index.js +683 -387
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const tt = [
1
+ const it = [
2
2
  "host_page_snapshot",
3
3
  "host_page_click",
4
4
  "host_page_fill",
@@ -11,9 +11,9 @@ const tt = [
11
11
  "host_page_pointer",
12
12
  "host_page_screenshot",
13
13
  "host_page_wait_for"
14
- ], et = new Set(
15
- tt
16
- ), nt = [
14
+ ], rt = new Set(
15
+ it
16
+ ), st = [
17
17
  "a[href]",
18
18
  "button",
19
19
  "input",
@@ -28,17 +28,17 @@ const tt = [
28
28
  "[data-testid]",
29
29
  "[data-test-id]",
30
30
  "[data-qa]"
31
- ].join(","), $ = 100, ot = 1e4, rt = 6e4;
32
- function it(t) {
33
- return et.has(t);
31
+ ].join(","), X = 100, at = 1e4, ct = 6e4;
32
+ function lt(t) {
33
+ return rt.has(t);
34
34
  }
35
- function m(t) {
35
+ function T(t) {
36
36
  return t instanceof Document ? t : t.ownerDocument;
37
37
  }
38
- function H(t) {
39
- return m(t).defaultView ?? window;
38
+ function N(t) {
39
+ return T(t).defaultView ?? window;
40
40
  }
41
- function y(t) {
41
+ function m(t) {
42
42
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
43
43
  }
44
44
  function O(t, e) {
@@ -46,24 +46,38 @@ function O(t, e) {
46
46
  throw new Error(`${e} must be a non-empty string.`);
47
47
  return t;
48
48
  }
49
- function v(t) {
49
+ function x(t) {
50
50
  return typeof t == "string" && t.trim() ? t : void 0;
51
51
  }
52
- function st(t) {
52
+ function ut(t) {
53
+ return t === "viewport_normalized" ? "viewport_normalized" : "viewport-css-px";
54
+ }
55
+ function U(t, e) {
56
+ const n = z(e.x, "x"), o = z(e.y, "y");
57
+ if (ut(e.coordinateSpace) === "viewport_normalized") {
58
+ const i = N(t);
59
+ return {
60
+ x: Number((n * i.innerWidth).toFixed(3)),
61
+ y: Number((o * i.innerHeight).toFixed(3))
62
+ };
63
+ }
64
+ return { x: n, y: o };
65
+ }
66
+ function dt(t) {
53
67
  return typeof t == "number" && Number.isInteger(t) ? t : void 0;
54
68
  }
55
- function C(t, e) {
69
+ function z(t, e) {
56
70
  if (typeof t != "number" || !Number.isFinite(t))
57
71
  throw new Error(`${e} must be a finite number.`);
58
72
  return t;
59
73
  }
60
- function _(t) {
74
+ function k(t) {
61
75
  return typeof t == "number" && Number.isFinite(t) ? t : void 0;
62
76
  }
63
- function W(t, e) {
77
+ function Y(t, e) {
64
78
  return typeof t == "string" && e.includes(t) ? t : void 0;
65
79
  }
66
- function ct(t) {
80
+ function ft(t) {
67
81
  if (typeof t == "string")
68
82
  return [t];
69
83
  if (Array.isArray(t) && t.every((e) => typeof e == "string"))
@@ -74,50 +88,50 @@ function b(t) {
74
88
  const e = (t.textContent ?? "").replace(/\s+/g, " ").trim();
75
89
  return e ? e.slice(0, 160) : void 0;
76
90
  }
77
- function R(t) {
91
+ function P(t) {
78
92
  const e = Array.from(t.childNodes).filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
79
93
  return e ? e.slice(0, 160) : void 0;
80
94
  }
81
- function at(t) {
95
+ function F(t) {
82
96
  if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement)
83
97
  return t.value;
84
98
  }
85
- function G(t) {
99
+ function Q(t) {
86
100
  return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio");
87
101
  }
88
- function lt(t) {
102
+ function pt(t) {
89
103
  return t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? Array.from(t.labels ?? []) : [];
90
104
  }
91
- function ut(t, e) {
105
+ function ht(t, e) {
92
106
  var o;
93
- return (((o = t.getAttribute(e)) == null ? void 0 : o.trim().split(/\s+/)) ?? []).map((r) => t.ownerDocument.getElementById(r)).filter((r) => !!r).map((r) => b(r)).filter((r) => !!r);
107
+ return (((o = t.getAttribute(e)) == null ? void 0 : o.trim().split(/\s+/)) ?? []).map((i) => t.ownerDocument.getElementById(i)).filter((i) => !!i).map((i) => b(i)).filter((i) => !!i);
94
108
  }
95
- function ft(t) {
96
- const e = ut(t, "aria-labelledby");
109
+ function gt(t) {
110
+ const e = ht(t, "aria-labelledby");
97
111
  if (e.length > 0)
98
112
  return e.join(" ").slice(0, 160);
99
- const n = lt(t).map((o) => b(o)).filter((o) => !!o);
113
+ const n = pt(t).map((o) => b(o)).filter((o) => !!o);
100
114
  if (n.length > 0)
101
115
  return n.join(" ").slice(0, 160);
102
116
  }
103
- function dt(t) {
117
+ function bt(t) {
104
118
  const e = [];
105
119
  let n = t.nextSibling;
106
120
  for (; n; ) {
107
121
  if (n.nodeType === Node.TEXT_NODE) {
108
- const r = (n.textContent ?? "").replace(/\s+/g, " ").trim();
109
- r && e.push(r);
122
+ const i = (n.textContent ?? "").replace(/\s+/g, " ").trim();
123
+ i && e.push(i);
110
124
  } else {
111
125
  if (n.nodeType === Node.ELEMENT_NODE && n.tagName.toLowerCase() === "br")
112
126
  break;
113
127
  if (n.nodeType === Node.ELEMENT_NODE) {
114
- const r = n;
115
- if (r.matches(
128
+ const i = n;
129
+ if (i.matches(
116
130
  'input,textarea,select,button,a[href],[role="button"],[role="link"]'
117
131
  ))
118
132
  break;
119
- const c = b(r);
120
- c && e.push(c);
133
+ const s = b(i);
134
+ s && e.push(s);
121
135
  break;
122
136
  }
123
137
  }
@@ -128,94 +142,94 @@ function dt(t) {
128
142
  const o = e.join(" ").replace(/\s+/g, " ").trim();
129
143
  return o ? o.slice(0, 160) : void 0;
130
144
  }
131
- function X(t, e) {
145
+ function G(t, e) {
132
146
  var d;
133
147
  const n = t.ownerDocument, o = n.body;
134
148
  if (!o)
135
149
  return;
136
- const r = t.getBoundingClientRect();
137
- if (r.width <= 0 || r.height <= 0)
150
+ const i = t.getBoundingClientRect();
151
+ if (i.width <= 0 || i.height <= 0)
138
152
  return;
139
- const c = r.top + r.height / 2, i = [], s = n.createTreeWalker(o, NodeFilter.SHOW_ELEMENT);
140
- let a = s.nextNode();
141
- for (; a; ) {
142
- const l = a;
143
- if (l !== t && !l.contains(t) && B(l)) {
144
- const u = l.getBoundingClientRect(), f = R(l) ?? b(l);
153
+ const s = i.top + i.height / 2, r = [], a = n.createTreeWalker(o, NodeFilter.SHOW_ELEMENT);
154
+ let c = a.nextNode();
155
+ for (; c; ) {
156
+ const u = c;
157
+ if (u !== t && !u.contains(t) && j(u)) {
158
+ const l = u.getBoundingClientRect(), f = P(u) ?? b(u);
145
159
  if (f) {
146
- const h = u.top + u.height / 2, E = Math.abs(h - c) <= Math.max(28, r.height * 1.25), g = e === "left" ? r.left - u.right : u.left - r.right;
147
- E && g >= -8 && g <= 240 && i.push({
160
+ const p = l.top + l.height / 2, y = Math.abs(p - s) <= Math.max(28, i.height * 1.25), h = e === "left" ? i.left - l.right : l.left - i.right;
161
+ y && h >= -8 && h <= 240 && r.push({
148
162
  text: f,
149
- score: Math.abs(g) + Math.abs(h - c)
163
+ score: Math.abs(h) + Math.abs(p - s)
150
164
  });
151
165
  }
152
166
  }
153
- a = s.nextNode();
167
+ c = a.nextNode();
154
168
  }
155
- return (d = i.sort((l, u) => l.score - u.score)[0]) == null ? void 0 : d.text;
169
+ return (d = r.sort((u, l) => u.score - l.score)[0]) == null ? void 0 : d.text;
156
170
  }
157
- function z(t) {
171
+ function H(t) {
158
172
  if (!(t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement))
159
173
  return;
160
- const e = ft(t);
161
- return e || (G(t) ? X(t, "right") ?? dt(t) ?? N(t)[0] : X(t, "left") ?? N(t)[0]);
174
+ const e = gt(t);
175
+ return e || (Q(t) ? G(t, "right") ?? bt(t) ?? C(t)[0] : G(t, "left") ?? C(t)[0]);
162
176
  }
163
- function j(t, e) {
177
+ function K(t, e) {
164
178
  const n = e.trim().toLowerCase();
165
179
  return t instanceof HTMLInputElement && t.type === "radio" ? n === "radio" || n === "radio button" : t instanceof HTMLInputElement && t.type === "checkbox" ? n === "checkbox" || n === "check box" : t instanceof HTMLSelectElement ? n === "select" || n === "select menu" || n === "combobox" || n === "combo box" : !1;
166
180
  }
167
- function x(t) {
168
- const e = z(t), n = t.getAttribute("aria-label");
169
- if (n != null && n.trim() && !j(t, n))
181
+ function v(t) {
182
+ const e = H(t), n = t.getAttribute("aria-label");
183
+ if (n != null && n.trim() && !K(t, n))
170
184
  return n.trim();
171
185
  const o = t.getAttribute("title");
172
- if (o != null && o.trim() && !j(t, o))
186
+ if (o != null && o.trim() && !K(t, o))
173
187
  return o.trim();
174
188
  if (e)
175
189
  return e;
176
- const r = N(t)[0];
177
- return r || b(t);
190
+ const i = C(t)[0];
191
+ return i || b(t);
178
192
  }
179
- function B(t) {
180
- if (!(t instanceof HTMLElement || t instanceof SVGElement) || !T(t) || t.matches(
193
+ function j(t) {
194
+ if (!(t instanceof HTMLElement || t instanceof SVGElement) || !_(t) || t.matches(
181
195
  'input,textarea,select,button,a[href],[role="button"],[role="link"]'
182
196
  ))
183
197
  return !1;
184
- const e = R(t) ?? b(t);
198
+ const e = P(t) ?? b(t);
185
199
  return !!(e && e.length <= 120);
186
200
  }
187
- function ht(t) {
188
- var u;
189
- if (!G(t))
201
+ function Z(t) {
202
+ var l;
203
+ if (!Q(t))
190
204
  return;
191
205
  const e = t.closest("fieldset"), n = e == null ? void 0 : e.querySelector("legend"), o = n ? b(n) : void 0;
192
206
  if (o)
193
207
  return o;
194
- const r = t.ownerDocument, c = r.body;
195
- if (!c)
208
+ const i = t.ownerDocument, s = i.body;
209
+ if (!s)
196
210
  return;
197
- const i = t.getBoundingClientRect();
198
- if (i.width <= 0 || i.height <= 0)
211
+ const r = t.getBoundingClientRect();
212
+ if (r.width <= 0 || r.height <= 0)
199
213
  return;
200
- const s = i.left + i.width / 2, a = [], d = r.createTreeWalker(c, NodeFilter.SHOW_ELEMENT);
201
- let l = d.nextNode();
202
- for (; l; ) {
203
- const f = l;
204
- if (f !== t && !f.contains(t) && f.matches('legend,strong,b,[role="heading"],h1,h2,h3,h4,h5,h6') && B(f)) {
205
- const h = f.getBoundingClientRect(), E = R(f) ?? b(f);
206
- if (E && h.bottom <= i.top + 8) {
207
- const g = i.top - h.bottom, w = h.left + h.width / 2;
208
- g <= 160 && w >= i.left - 120 && w <= i.right + 320 && a.push({
209
- text: E,
210
- score: g + Math.abs(w - s) * 0.25
214
+ const a = r.left + r.width / 2, c = [], d = i.createTreeWalker(s, NodeFilter.SHOW_ELEMENT);
215
+ let u = d.nextNode();
216
+ for (; u; ) {
217
+ const f = u;
218
+ if (f !== t && !f.contains(t) && f.matches('legend,strong,b,[role="heading"],h1,h2,h3,h4,h5,h6') && j(f)) {
219
+ const p = f.getBoundingClientRect(), y = P(f) ?? b(f);
220
+ if (y && p.bottom <= r.top + 8) {
221
+ const h = r.top - p.bottom, E = p.left + p.width / 2;
222
+ h <= 160 && E >= r.left - 120 && E <= r.right + 320 && c.push({
223
+ text: y,
224
+ score: h + Math.abs(E - a) * 0.25
211
225
  });
212
226
  }
213
227
  }
214
- l = d.nextNode();
228
+ u = d.nextNode();
215
229
  }
216
- return (u = a.sort((f, h) => f.score - h.score)[0]) == null ? void 0 : u.text;
230
+ return (l = c.sort((f, p) => f.score - p.score)[0]) == null ? void 0 : l.text;
217
231
  }
218
- function gt(t) {
232
+ function yt(t) {
219
233
  if (!(t instanceof HTMLSelectElement))
220
234
  return;
221
235
  const e = Array.from(t.options).map((n) => ({
@@ -226,45 +240,45 @@ function gt(t) {
226
240
  }));
227
241
  return e.length ? e : void 0;
228
242
  }
229
- function pt(t) {
243
+ function Et(t) {
230
244
  if (!(t instanceof HTMLSelectElement))
231
245
  return;
232
246
  const e = t.selectedOptions[0], n = e ? (e.label || e.textContent || e.value).replace(/\s+/g, " ").trim() : void 0;
233
247
  return n ? n.slice(0, 160) : void 0;
234
248
  }
235
- function N(t) {
249
+ function C(t) {
236
250
  const e = t.ownerDocument, n = e.body;
237
251
  if (!n)
238
252
  return [];
239
253
  const o = t.getBoundingClientRect();
240
254
  if (o.width <= 0 || o.height <= 0)
241
255
  return [];
242
- const r = o.top + o.height / 2, c = o.left + o.width / 2, i = [], s = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
243
- let a = s.nextNode();
244
- for (; a; ) {
245
- const l = a;
246
- if (l !== t && !l.contains(t) && B(l)) {
247
- const u = l.getBoundingClientRect(), f = R(l) ?? b(l);
256
+ const i = o.top + o.height / 2, s = o.left + o.width / 2, r = [], a = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
257
+ let c = a.nextNode();
258
+ for (; c; ) {
259
+ const u = c;
260
+ if (u !== t && !u.contains(t) && j(u)) {
261
+ const l = u.getBoundingClientRect(), f = P(u) ?? b(u);
248
262
  if (f) {
249
- const h = u.top + u.height / 2, E = u.left + u.width / 2, g = u.right <= o.left + 12 && Math.abs(h - r) <= Math.max(28, o.height * 1.25), w = u.left >= o.right - 8 && u.left - o.right <= 240 && Math.abs(h - r) <= Math.max(28, o.height * 1.25), q = u.bottom <= o.top + 8 && o.top - u.bottom <= 80 && E >= o.left - 80 && E <= o.right + 80;
250
- if (g || w || q) {
251
- const Z = g ? o.left - u.right + Math.abs(h - r) : w ? u.left - o.right + Math.abs(h - r) : o.top - u.bottom + Math.abs(E - c);
252
- i.push({
263
+ const p = l.top + l.height / 2, y = l.left + l.width / 2, h = l.right <= o.left + 12 && Math.abs(p - i) <= Math.max(28, o.height * 1.25), E = l.left >= o.right - 8 && l.left - o.right <= 240 && Math.abs(p - i) <= Math.max(28, o.height * 1.25), W = l.bottom <= o.top + 8 && o.top - l.bottom <= 80 && y >= o.left - 80 && y <= o.right + 80;
264
+ if (h || E || W) {
265
+ const ot = h ? o.left - l.right + Math.abs(p - i) : E ? l.left - o.right + Math.abs(p - i) : o.top - l.bottom + Math.abs(y - s);
266
+ r.push({
253
267
  text: f,
254
- score: Z + (g ? 0 : w ? 5 : 100)
268
+ score: ot + (h ? 0 : E ? 5 : 100)
255
269
  });
256
270
  }
257
271
  }
258
272
  }
259
- a = s.nextNode();
273
+ c = a.nextNode();
260
274
  }
261
275
  const d = /* @__PURE__ */ new Set();
262
- return i.sort((l, u) => l.score - u.score).map((l) => l.text).filter((l) => d.has(l) ? !1 : (d.add(l), !0)).slice(0, 4);
276
+ return r.sort((u, l) => u.score - l.score).map((u) => u.text).filter((u) => d.has(u) ? !1 : (d.add(u), !0)).slice(0, 4);
263
277
  }
264
- function Et(t) {
278
+ function mt(t) {
265
279
  return t.getAttribute("data-testid") ?? t.getAttribute("data-test-id") ?? t.getAttribute("data-qa") ?? void 0;
266
280
  }
267
- function M(t) {
281
+ function S(t) {
268
282
  const e = t.getAttribute("role");
269
283
  if (e != null && e.trim())
270
284
  return e.trim();
@@ -288,65 +302,65 @@ function M(t) {
288
302
  return "textbox";
289
303
  }
290
304
  }
291
- function K(t) {
305
+ function tt(t) {
292
306
  return t instanceof HTMLButtonElement || t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? t.disabled || void 0 : t.getAttribute("aria-disabled") === "true" || void 0;
293
307
  }
294
- function bt(t) {
308
+ function wt(t) {
295
309
  return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio") ? t.checked : void 0;
296
310
  }
297
- function wt(t) {
298
- const e = k(t);
311
+ function vt(t) {
312
+ const e = A(t);
299
313
  if (!(e.width <= 0 || e.height <= 0))
300
314
  return {
301
315
  x: e.x + e.width / 2,
302
316
  y: e.y + e.height / 2
303
317
  };
304
318
  }
305
- function U(t) {
319
+ function V(t) {
306
320
  return {
307
321
  tag: t.tagName.toLowerCase(),
308
- role: M(t),
309
- name: x(t),
310
- selector: D(t)
322
+ role: S(t),
323
+ name: v(t),
324
+ selector: q(t)
311
325
  };
312
326
  }
313
- function T(t) {
327
+ function _(t) {
314
328
  if (!(t instanceof HTMLElement || t instanceof SVGElement) || t instanceof HTMLElement && t.hidden)
315
329
  return !1;
316
330
  const e = t.ownerDocument.defaultView, n = e == null ? void 0 : e.getComputedStyle(t);
317
331
  return !(n && (n.display === "none" || n.visibility === "hidden" || n.opacity === "0"));
318
332
  }
319
- function J(t) {
320
- return t.matches(nt) && T(t);
333
+ function et(t) {
334
+ return t.matches(st) && _(t);
321
335
  }
322
- function yt(t) {
323
- return K(t) !== !0;
336
+ function xt(t) {
337
+ return tt(t) !== !0;
324
338
  }
325
- function mt(t) {
339
+ function Tt(t) {
326
340
  var n;
327
- if (J(t))
341
+ if (et(t))
328
342
  return !0;
329
343
  if (!(t instanceof HTMLElement))
330
344
  return !1;
331
345
  const e = (n = t.ownerDocument.defaultView) == null ? void 0 : n.getComputedStyle(t);
332
- return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && T(t);
346
+ return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && _(t);
333
347
  }
334
- function k(t) {
335
- var c, i;
348
+ function A(t) {
349
+ var s, r;
336
350
  const e = t.getBoundingClientRect();
337
- let n = e.left, o = e.top, r = null;
351
+ let n = e.left, o = e.top, i = null;
338
352
  try {
339
- r = ((c = t.ownerDocument.defaultView) == null ? void 0 : c.frameElement) ?? null;
353
+ i = ((s = t.ownerDocument.defaultView) == null ? void 0 : s.frameElement) ?? null;
340
354
  } catch {
341
- r = null;
355
+ i = null;
342
356
  }
343
- for (; r; ) {
344
- const s = r.getBoundingClientRect();
345
- n += s.left, o += s.top;
357
+ for (; i; ) {
358
+ const a = i.getBoundingClientRect();
359
+ n += a.left, o += a.top;
346
360
  try {
347
- r = ((i = r.ownerDocument.defaultView) == null ? void 0 : i.frameElement) ?? null;
361
+ i = ((r = i.ownerDocument.defaultView) == null ? void 0 : r.frameElement) ?? null;
348
362
  } catch {
349
- r = null;
363
+ i = null;
350
364
  }
351
365
  }
352
366
  return {
@@ -356,21 +370,21 @@ function k(t) {
356
370
  height: e.height
357
371
  };
358
372
  }
359
- function D(t) {
373
+ function q(t) {
360
374
  const e = (o) => typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(o) : o.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
361
375
  if (t.id)
362
376
  return `#${e(t.id)}`;
363
377
  for (const o of ["data-testid", "data-test-id", "data-qa"]) {
364
- const r = t.getAttribute(o);
365
- if (r)
366
- return `[${o}="${e(r)}"]`;
378
+ const i = t.getAttribute(o);
379
+ if (i)
380
+ return `[${o}="${e(i)}"]`;
367
381
  }
368
382
  const n = t.getAttribute("name");
369
383
  return n ? `${t.tagName.toLowerCase()}[name="${e(
370
384
  n
371
385
  )}"]` : t.tagName.toLowerCase();
372
386
  }
373
- function vt(t) {
387
+ function _t(t) {
374
388
  const e = t.getBoundingClientRect();
375
389
  if (!(e.width <= 0 || e.height <= 0))
376
390
  return {
@@ -378,7 +392,7 @@ function vt(t) {
378
392
  y: e.top + e.height / 2
379
393
  };
380
394
  }
381
- function Q(t, e) {
395
+ function nt(t, e) {
382
396
  if (typeof t.elementsFromPoint == "function")
383
397
  return t.elementsFromPoint(e.x, e.y);
384
398
  if (typeof t.elementFromPoint != "function")
@@ -386,25 +400,25 @@ function Q(t, e) {
386
400
  const n = t.elementFromPoint(e.x, e.y);
387
401
  return n ? [n] : [];
388
402
  }
389
- function xt(t) {
403
+ function St(t) {
390
404
  return typeof t.elementsFromPoint == "function" || typeof t.elementFromPoint == "function";
391
405
  }
392
- function A(t, e) {
406
+ function R(t, e) {
393
407
  return t === e || t.contains(e);
394
408
  }
395
- function Tt(t) {
409
+ function kt(t) {
396
410
  let e = t;
397
411
  for (; e; ) {
398
- if (mt(e))
412
+ if (Tt(e))
399
413
  return e;
400
414
  e = e.parentElement;
401
415
  }
402
416
  return t;
403
417
  }
404
- function Y(t) {
418
+ function J(t) {
405
419
  return (t ?? "").replace(/\([^)]*\)/g, "").replace(/\s+/g, "").trim().toLowerCase();
406
420
  }
407
- function V(t) {
421
+ function B(t) {
408
422
  const e = t.getBoundingClientRect();
409
423
  if (e.width <= 0 || e.height <= 0)
410
424
  return;
@@ -416,100 +430,158 @@ function V(t) {
416
430
  { x: e.left + e.width / 2, y: e.top + Math.min(8, e.height / 2) },
417
431
  { x: e.left + e.width / 2, y: e.bottom - Math.min(8, e.height / 2) }
418
432
  ].find(
419
- (r) => Q(n, r).some(
420
- (c) => A(t, c) || A(c, t)
433
+ (i) => nt(n, i).some(
434
+ (s) => R(t, s) || R(s, t)
421
435
  )
422
436
  );
423
437
  }
424
438
  function Mt(t, e) {
425
- const n = t.getBoundingClientRect(), o = k(t);
439
+ const n = t.getBoundingClientRect(), o = A(t);
426
440
  return {
427
441
  x: e.x + o.x - n.left,
428
442
  y: e.y + o.y - n.top
429
443
  };
430
444
  }
431
- function _t(t, e) {
432
- var c;
433
- const n = M(e), o = Y(x(e));
434
- return o ? ((c = F(t).filter((i) => i !== e).filter((i) => {
435
- const s = M(i), a = Y(x(i));
436
- return n && s && n !== s ? !1 : a.includes(o) || o.includes(a);
437
- }).map((i) => ({
438
- candidate: i,
439
- point: V(i),
440
- rect: k(i)
445
+ function Lt(t, e) {
446
+ var s;
447
+ const n = S(e), o = J(v(e));
448
+ return o ? ((s = $(t).filter((r) => r !== e).filter((r) => {
449
+ const a = S(r), c = J(v(r));
450
+ return n && a && n !== a ? !1 : c.includes(o) || o.includes(c);
451
+ }).map((r) => ({
452
+ candidate: r,
453
+ point: B(r),
454
+ rect: A(r)
441
455
  })).filter(
442
- (i) => !!i.point
443
- ).sort((i, s) => s.rect.y - i.rect.y)[0]) == null ? void 0 : c.candidate) ?? null : null;
456
+ (r) => !!r.point
457
+ ).sort((r, a) => a.rect.y - r.rect.y)[0]) == null ? void 0 : s.candidate) ?? null : null;
444
458
  }
445
- function p(t) {
446
- const e = t.ownerDocument, n = vt(t), o = T(t) && !!n, r = yt(t), c = n ? Q(e, n) : [], i = c[0], s = !!(i && (A(t, i) || A(i, t)));
459
+ function g(t) {
460
+ const e = t.ownerDocument, n = _t(t), o = _(t) && !!n, i = xt(t), s = n ? nt(e, n) : [], r = s[0], a = !!(r && (R(t, r) || R(r, t)));
447
461
  return {
448
462
  visible: o,
449
- enabled: r,
450
- receivesEvents: s,
451
- actionable: o && r && s,
452
- center: wt(t),
453
- hitTarget: i,
454
- hitStack: c
463
+ enabled: i,
464
+ receivesEvents: a,
465
+ actionable: o && i && a,
466
+ center: vt(t),
467
+ hitTarget: r,
468
+ hitStack: s
455
469
  };
456
470
  }
457
- function St(t, e) {
458
- var s, a, d;
459
- const n = v(e.testId);
471
+ function Ct(t, e) {
472
+ var a, c, d;
473
+ const n = x(e.testId);
460
474
  if (n) {
461
- const l = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), u = t.querySelector(
462
- `[data-testid="${l}"],[data-test-id="${l}"],[data-qa="${l}"]`
475
+ const u = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), l = t.querySelector(
476
+ `[data-testid="${u}"],[data-test-id="${u}"],[data-qa="${u}"]`
463
477
  );
464
- if (u)
465
- return u;
466
- }
467
- const o = (s = v(e.role)) == null ? void 0 : s.toLowerCase(), r = (a = v(e.name)) == null ? void 0 : a.toLowerCase(), c = (d = v(e.text)) == null ? void 0 : d.toLowerCase();
468
- return !o && !r && !c ? null : F(t).find((l) => {
469
- var E, g, w;
470
- const u = (E = M(l)) == null ? void 0 : E.toLowerCase(), f = (g = x(l)) == null ? void 0 : g.toLowerCase(), h = (w = b(l)) == null ? void 0 : w.toLowerCase();
471
- return !(o && u !== o || r && !(f != null && f.includes(r)) || c && !(h != null && h.includes(c)));
478
+ if (l)
479
+ return l;
480
+ }
481
+ const o = (a = x(e.role)) == null ? void 0 : a.toLowerCase(), i = (c = x(e.name)) == null ? void 0 : c.toLowerCase(), s = (d = x(e.text)) == null ? void 0 : d.toLowerCase();
482
+ return !o && !i && !s ? null : $(t).find((u) => {
483
+ var y, h, E;
484
+ const l = (y = S(u)) == null ? void 0 : y.toLowerCase(), f = (h = v(u)) == null ? void 0 : h.toLowerCase(), p = (E = b(u)) == null ? void 0 : E.toLowerCase();
485
+ return !(o && l !== o || i && !(f != null && f.includes(i)) || s && !(p != null && p.includes(s)));
472
486
  }) ?? null;
473
487
  }
474
- function F(t) {
475
- const e = m(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
488
+ function At(t) {
489
+ return [
490
+ v(t),
491
+ H(t),
492
+ Z(t),
493
+ b(t),
494
+ F(t)
495
+ ].filter((e) => !!e).join(" ").toLowerCase();
496
+ }
497
+ function Nt(t, e) {
498
+ const n = e.trim().toLowerCase();
499
+ let o = t, i = 0;
500
+ for (; o && i < 5; ) {
501
+ const s = o.tagName.toLowerCase();
502
+ if (s === "body" || s === "html")
503
+ return !1;
504
+ if (At(o).includes(n))
505
+ return !0;
506
+ o = o.parentElement, i += 1;
507
+ }
508
+ return !1;
509
+ }
510
+ function Rt(t) {
511
+ if (!t || typeof t != "object" || Array.isArray(t))
512
+ return;
513
+ const e = t;
514
+ if (e.type === "field_contains" && typeof e.field == "string" && e.field.trim() && typeof e.value == "string")
515
+ return {
516
+ type: "field_contains",
517
+ field: e.field,
518
+ value: e.value
519
+ };
520
+ }
521
+ function Pt(t, e) {
522
+ const n = e.trim().toLowerCase();
523
+ return Array.from(t.querySelectorAll("input,textarea,select")).find(
524
+ (o) => [
525
+ H(o),
526
+ v(o),
527
+ o.getAttribute("name") ?? void 0,
528
+ o.getAttribute("placeholder") ?? void 0,
529
+ ...C(o)
530
+ ].some(
531
+ (s) => s == null ? void 0 : s.trim().toLowerCase().includes(n)
532
+ )
533
+ );
534
+ }
535
+ function Ht(t, e) {
536
+ if (!e)
537
+ return;
538
+ const n = Pt(t, e.field), o = n ? F(n) ?? "" : void 0;
539
+ return {
540
+ ...e,
541
+ ok: typeof o == "string" && o.toLowerCase().includes(e.value.toLowerCase()),
542
+ actual: o,
543
+ matchedField: n ? V(n) : void 0
544
+ };
545
+ }
546
+ function $(t) {
547
+ const e = t instanceof Element ? t.ownerDocument : T(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
476
548
  if (!n)
477
549
  return [];
478
- const o = [], r = (c) => {
479
- const i = e.createTreeWalker(c, NodeFilter.SHOW_ELEMENT);
480
- let s = i.nextNode();
481
- for (; s; ) {
482
- const a = s;
483
- J(a) && o.push(a);
484
- const d = a.shadowRoot;
485
- if (d && r(d), a instanceof HTMLIFrameElement)
550
+ const o = [], i = (s) => {
551
+ const r = e.createTreeWalker(s, NodeFilter.SHOW_ELEMENT);
552
+ let a = r.nextNode();
553
+ for (; a; ) {
554
+ const c = a;
555
+ et(c) && o.push(c);
556
+ const d = c.shadowRoot;
557
+ if (d && i(d), c instanceof HTMLIFrameElement)
486
558
  try {
487
- a.contentDocument && r(a.contentDocument);
559
+ c.contentDocument && i(c.contentDocument);
488
560
  } catch {
489
561
  }
490
- if (o.length >= $)
562
+ if (o.length >= X)
491
563
  return;
492
- s = i.nextNode();
564
+ a = r.nextNode();
493
565
  }
494
566
  };
495
- return r(n), o.slice(0, $);
567
+ return i(n), o.slice(0, X);
496
568
  }
497
- function Lt(t, e) {
498
- var r;
569
+ function Ot(t, e) {
570
+ var i;
499
571
  const n = Object.getPrototypeOf(t), o = Object.getOwnPropertyDescriptor(n, "value");
500
- (r = o == null ? void 0 : o.set) == null || r.call(t, e);
572
+ (i = o == null ? void 0 : o.set) == null || i.call(t, e);
501
573
  }
502
574
  function I(t) {
503
575
  t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 }));
504
576
  }
505
- function S(t) {
577
+ function M(t) {
506
578
  var e, n;
507
579
  (t instanceof HTMLElement || t instanceof SVGElement) && ((e = t.scrollIntoView) == null || e.call(t, { block: "center", inline: "center" })), t instanceof HTMLElement && ((n = t.focus) == null || n.call(t));
508
580
  }
509
581
  function L(t, e) {
510
582
  return typeof PointerEvent == "function" ? new PointerEvent(t, e) : new MouseEvent(t.replace("pointer", "mouse"), e);
511
583
  }
512
- class kt {
584
+ class It {
513
585
  constructor(e = {}) {
514
586
  this.options = e, this.refs = /* @__PURE__ */ new Map(), this.nextRef = 1;
515
587
  }
@@ -544,10 +616,10 @@ class kt {
544
616
  }
545
617
  }
546
618
  snapshot() {
547
- var c, i;
619
+ var s, r;
548
620
  this.refs.clear(), this.nextRef = 1;
549
- const e = this.getRoot(), n = m(e), o = H(e), r = F(e).map(
550
- (s) => this.snapshotElement(s)
621
+ const e = this.getRoot(), n = T(e), o = N(e), i = $(e).map(
622
+ (a) => this.snapshotElement(a)
551
623
  );
552
624
  return {
553
625
  url: o.location.href,
@@ -572,28 +644,28 @@ class kt {
572
644
  readyState: n.readyState,
573
645
  visibilityState: n.visibilityState,
574
646
  focusedElement: n.activeElement && n.activeElement !== n.body ? this.snapshotElementWithoutRef(n.activeElement) : void 0,
575
- selection: ((i = (c = n.getSelection) == null ? void 0 : c.call(n)) == null ? void 0 : i.toString()) || void 0
647
+ selection: ((r = (s = n.getSelection) == null ? void 0 : s.call(n)) == null ? void 0 : r.toString()) || void 0
576
648
  },
577
649
  navigation: this.getNavigationState(o),
578
650
  frames: this.getFrameState(n),
579
- accessibility: r.map((s) => ({
580
- ref: s.ref,
581
- role: s.role,
582
- name: s.name,
583
- value: s.value,
584
- disabled: s.disabled,
585
- checked: s.checked,
586
- focused: n.activeElement === this.refs.get(s.ref)
651
+ accessibility: i.map((a) => ({
652
+ ref: a.ref,
653
+ role: a.role,
654
+ name: a.name,
655
+ value: a.value,
656
+ disabled: a.disabled,
657
+ checked: a.checked,
658
+ focused: n.activeElement === this.refs.get(a.ref)
587
659
  })),
588
- elements: r
660
+ elements: i
589
661
  };
590
662
  }
591
663
  getRoot() {
592
664
  return this.options.root ?? document;
593
665
  }
594
666
  getNavigationState(e) {
595
- var o, r, c;
596
- const n = (c = (r = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : r.call(o, "navigation")) == null ? void 0 : c[0];
667
+ var o, i, s;
668
+ const n = (s = (i = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : i.call(o, "navigation")) == null ? void 0 : s[0];
597
669
  if (!(typeof PerformanceNavigationTiming != "function" || !(n instanceof PerformanceNavigationTiming)))
598
670
  return {
599
671
  type: n.type,
@@ -604,12 +676,12 @@ class kt {
604
676
  }
605
677
  getFrameState(e) {
606
678
  return Array.from(e.querySelectorAll("iframe")).map((n) => {
607
- var r, c;
608
- const o = k(n);
679
+ var i, s;
680
+ const o = A(n);
609
681
  try {
610
682
  return {
611
- url: (r = n.contentWindow) == null ? void 0 : r.location.href,
612
- title: (c = n.contentDocument) == null ? void 0 : c.title,
683
+ url: (i = n.contentWindow) == null ? void 0 : i.location.href,
684
+ title: (s = n.contentDocument) == null ? void 0 : s.title,
613
685
  sameOrigin: !0,
614
686
  rect: o
615
687
  };
@@ -630,159 +702,156 @@ class kt {
630
702
  return this.createElementSnapshot(e, "");
631
703
  }
632
704
  createElementSnapshot(e, n) {
633
- const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, r = p(e);
705
+ const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, i = g(e);
634
706
  return {
635
707
  ref: n,
636
708
  tag: e.tagName.toLowerCase(),
637
- role: M(e),
638
- name: x(e),
639
- label: z(e),
640
- groupLabel: ht(e),
709
+ role: S(e),
710
+ name: v(e),
711
+ label: H(e),
712
+ groupLabel: Z(e),
641
713
  text: b(e),
642
- nearbyText: N(e),
643
- testId: Et(e),
644
- value: at(e),
645
- selectedLabel: pt(e),
646
- options: gt(e),
714
+ nearbyText: C(e),
715
+ testId: mt(e),
716
+ value: F(e),
717
+ selectedLabel: Et(e),
718
+ options: yt(e),
647
719
  placeholder: o,
648
- selector: D(e),
649
- disabled: K(e),
650
- enabled: r.enabled,
651
- checked: bt(e),
652
- visible: r.visible,
653
- actionable: r.actionable,
654
- rect: k(e),
655
- center: r.center,
656
- hitTarget: r.hitTarget ? U(r.hitTarget) : void 0,
657
- hitStack: r.hitStack.slice(0, 5).map(U)
720
+ selector: q(e),
721
+ disabled: tt(e),
722
+ enabled: i.enabled,
723
+ checked: wt(e),
724
+ visible: i.visible,
725
+ actionable: i.actionable,
726
+ rect: A(e),
727
+ center: i.center,
728
+ hitTarget: i.hitTarget ? V(i.hitTarget) : void 0,
729
+ hitStack: i.hitStack.slice(0, 5).map(V)
658
730
  };
659
731
  }
660
732
  resolveElement(e) {
661
- const n = v(e.ref) ?? v(e.axRef);
733
+ const n = x(e.ref) ?? x(e.axRef);
662
734
  if (n) {
663
- const c = this.refs.get(n);
664
- if (!c)
735
+ const s = this.refs.get(n);
736
+ if (!s)
665
737
  throw new Error(`Unknown element ref: ${n}. Take a new snapshot.`);
666
- return c;
738
+ return s;
667
739
  }
668
- const o = v(e.selector);
740
+ const o = x(e.selector);
669
741
  if (o) {
670
- const c = this.getRoot().querySelector(o);
671
- if (!c)
742
+ const s = this.getRoot().querySelector(o);
743
+ if (!s)
672
744
  throw new Error(`No element matches selector: ${o}.`);
673
- return c;
745
+ return s;
674
746
  }
675
- const r = St(this.getRoot(), e);
676
- if (r)
677
- return r;
747
+ const i = Ct(this.getRoot(), e);
748
+ if (i)
749
+ return i;
678
750
  if (typeof e.x < "u" || typeof e.y < "u") {
679
- const c = {
680
- x: C(e.x, "x"),
681
- y: C(e.y, "y")
682
- }, i = m(this.getRoot()).elementFromPoint(
683
- c.x,
684
- c.y
751
+ const s = U(this.getRoot(), e), r = T(this.getRoot()).elementFromPoint(
752
+ s.x,
753
+ s.y
685
754
  );
686
- if (!i)
687
- throw new Error(`No element found at (${c.x}, ${c.y}).`);
688
- return i;
755
+ if (!r)
756
+ throw new Error(`No element found at (${s.x}, ${s.y}).`);
757
+ return r;
689
758
  }
690
759
  throw new Error(
691
760
  "Expected one of ref, selector, role/name/text/testId, or x/y."
692
761
  );
693
762
  }
694
763
  async click(e) {
695
- const n = y(e), o = this.resolveElement(n), r = p(o), i = (r.actionable ? null : _t(this.getRoot(), o)) ?? Tt(o);
696
- if (!V(i) && !r.actionable && xt(o.ownerDocument))
764
+ const n = m(e), o = this.resolveElement(n), i = g(o), r = (i.actionable ? null : Lt(this.getRoot(), o)) ?? kt(o);
765
+ if (!B(r) && !i.actionable && St(o.ownerDocument))
697
766
  throw new Error(
698
- `Target "${x(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events. Take a screenshot or use host_page_pointer coordinates.`
767
+ `Target "${v(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events. Take a screenshot or use host_page_pointer coordinates.`
699
768
  );
700
- S(i);
701
- const a = V(i), d = p(i), l = p(o), u = a ? Mt(i, a) : d.center ?? r.center;
702
- return u && await this.showVisualEffect({
769
+ M(r);
770
+ const c = B(r), d = g(r), u = g(o), l = c ? Mt(r, c) : d.center ?? i.center;
771
+ return l && await this.showVisualEffect({
703
772
  type: "click",
704
- point: u,
773
+ point: l,
705
774
  anchor: "target",
706
- target: i,
775
+ target: r,
707
776
  requested: o
708
- }), i instanceof HTMLElement ? i.click() : i.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), {
709
- clicked: this.describeElement(i),
777
+ }), r instanceof HTMLElement ? r.click() : r.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), {
778
+ clicked: this.describeElement(r),
710
779
  requested: this.describeElement(o),
711
- strategy: i === o ? "dom" : "semantic_visible_fallback",
712
- point: u,
780
+ strategy: r === o ? "dom" : "semantic_visible_fallback",
781
+ point: l,
713
782
  actionability: {
714
- visible: l.visible,
715
- enabled: l.enabled,
716
- receivesEvents: l.receivesEvents
783
+ visible: u.visible,
784
+ enabled: u.enabled,
785
+ receivesEvents: u.receivesEvents
717
786
  }
718
787
  };
719
788
  }
720
789
  async fill(e) {
721
- const n = y(e), o = O(n.value, "value"), r = this.resolveElement(n);
722
- if (S(r), r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement)
790
+ const n = m(e), o = O(n.value, "value"), i = this.resolveElement(n);
791
+ if (M(i), i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement)
723
792
  return await this.showVisualEffect({
724
793
  type: "fill",
725
- target: r,
726
- requested: r,
794
+ target: i,
795
+ requested: i,
727
796
  value: o,
728
797
  anchor: "target",
729
- point: p(r).center
730
- }), Lt(r, o), I(r), { filled: this.describeElement(r), value: o };
731
- if (r instanceof HTMLElement && r.isContentEditable)
798
+ point: g(i).center
799
+ }), Ot(i, o), I(i), { filled: this.describeElement(i), value: o };
800
+ if (i instanceof HTMLElement && i.isContentEditable)
732
801
  return await this.showVisualEffect({
733
802
  type: "fill",
734
- target: r,
735
- requested: r,
803
+ target: i,
804
+ requested: i,
736
805
  value: o,
737
806
  anchor: "target",
738
- point: p(r).center
739
- }), r.textContent = o, I(r), { filled: this.describeElement(r), value: o };
807
+ point: g(i).center
808
+ }), i.textContent = o, I(i), { filled: this.describeElement(i), value: o };
740
809
  throw new Error("Target element cannot be filled.");
741
810
  }
742
811
  async press(e) {
743
- const n = y(e), o = O(n.key, "key"), r = n.ref || n.selector || n.x !== void 0 && n.y !== void 0 ? this.resolveElement(n) : m(this.getRoot()).activeElement ?? m(this.getRoot()).body;
744
- if (!r)
812
+ const n = m(e), o = O(n.key, "key"), i = n.ref || n.selector || n.x !== void 0 && n.y !== void 0 ? this.resolveElement(n) : T(this.getRoot()).activeElement ?? T(this.getRoot()).body;
813
+ if (!i)
745
814
  throw new Error("No target element is available for key press.");
746
- S(r), await this.showVisualEffect({
815
+ M(i), await this.showVisualEffect({
747
816
  type: "press",
748
- target: r,
749
- requested: r,
817
+ target: i,
818
+ requested: i,
750
819
  key: o,
751
820
  anchor: "target",
752
- point: p(r).center
821
+ point: g(i).center
753
822
  });
754
- const c = { key: o, bubbles: !0, cancelable: !0 };
755
- return r.dispatchEvent(new KeyboardEvent("keydown", c)), o.length === 1 && r.dispatchEvent(new KeyboardEvent("keypress", c)), r.dispatchEvent(new KeyboardEvent("keyup", c)), { pressed: o, target: this.describeElement(r) };
823
+ const s = { key: o, bubbles: !0, cancelable: !0 };
824
+ return i.dispatchEvent(new KeyboardEvent("keydown", s)), o.length === 1 && i.dispatchEvent(new KeyboardEvent("keypress", s)), i.dispatchEvent(new KeyboardEvent("keyup", s)), { pressed: o, target: this.describeElement(i) };
756
825
  }
757
826
  async select(e) {
758
- const n = y(e), o = ct(n.values ?? n.value), r = this.resolveElement(n);
759
- if (!(r instanceof HTMLSelectElement))
827
+ const n = m(e), o = ft(n.values ?? n.value), i = this.resolveElement(n);
828
+ if (!(i instanceof HTMLSelectElement))
760
829
  throw new Error("Target element is not a select.");
761
- S(r);
762
- const c = new Set(o);
830
+ M(i);
831
+ const s = new Set(o);
763
832
  await this.showVisualEffect({
764
833
  type: "select",
765
- target: r,
766
- requested: r,
834
+ target: i,
835
+ requested: i,
767
836
  values: o,
768
837
  anchor: "target",
769
- point: p(r).center
838
+ point: g(i).center
770
839
  });
771
- for (const i of Array.from(r.options))
772
- i.selected = c.has(i.value);
773
- return I(r), {
774
- selected: Array.from(r.selectedOptions).map(
775
- (i) => i.value
840
+ for (const r of Array.from(i.options))
841
+ r.selected = s.has(r.value);
842
+ return I(i), {
843
+ selected: Array.from(i.selectedOptions).map(
844
+ (r) => r.value
776
845
  ),
777
- target: this.describeElement(r)
846
+ target: this.describeElement(i)
778
847
  };
779
848
  }
780
849
  async scroll(e) {
781
- var a, d, l, u;
782
- const n = y(e), o = n.x !== void 0 || n.y !== void 0 ? {
783
- x: _(n.x) ?? 0,
784
- y: _(n.y) ?? 0
785
- } : null, r = _(n.deltaX) ?? 0, c = _(n.deltaY) ?? 0, i = this.getRoot(), s = H(i);
850
+ var c, d, u, l;
851
+ const n = m(e), o = n.x !== void 0 || n.y !== void 0 ? {
852
+ x: k(n.x) ?? 0,
853
+ y: k(n.y) ?? 0
854
+ } : null, i = k(n.deltaX) ?? 0, s = k(n.deltaY) ?? 0, r = this.getRoot(), a = N(r);
786
855
  if (n.ref || n.selector || n.role || n.name || n.text || n.testId) {
787
856
  const f = this.resolveElement(n);
788
857
  if (!(f instanceof HTMLElement))
@@ -791,111 +860,124 @@ class kt {
791
860
  type: "scroll",
792
861
  target: f,
793
862
  requested: f,
794
- deltaX: r,
795
- deltaY: c,
863
+ deltaX: i,
864
+ deltaY: s,
796
865
  anchor: "target",
797
- point: p(f).center
798
- }), o ? (a = f.scrollTo) == null || a.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, r, c), {
866
+ point: g(f).center
867
+ }), o ? (c = f.scrollTo) == null || c.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, i, s), {
799
868
  scrolled: this.describeElement(f),
800
869
  scroll: { x: f.scrollLeft, y: f.scrollTop }
801
870
  };
802
871
  }
803
872
  return await this.showVisualEffect({
804
873
  type: "scroll",
805
- deltaX: r,
806
- deltaY: c,
874
+ deltaX: i,
875
+ deltaY: s,
807
876
  point: {
808
- x: s.innerWidth / 2,
809
- y: s.innerHeight / 2
877
+ x: a.innerWidth / 2,
878
+ y: a.innerHeight / 2
810
879
  }
811
- }), o ? (l = s.scrollTo) == null || l.call(s, o.x, o.y) : (u = s.scrollBy) == null || u.call(s, r, c), { scroll: { x: s.scrollX, y: s.scrollY } };
880
+ }), o ? (u = a.scrollTo) == null || u.call(a, o.x, o.y) : (l = a.scrollBy) == null || l.call(a, i, s), { scroll: { x: a.scrollX, y: a.scrollY } };
812
881
  }
813
882
  navigate(e) {
814
883
  if (this.options.allowNavigation === !1)
815
884
  throw new Error("Navigation is disabled for host page automation.");
816
- const n = y(e), o = this.getRoot(), r = H(o), c = O(n.url, "url"), i = new URL(c, r.location.href);
817
- if (i.protocol !== "http:" && i.protocol !== "https:")
885
+ const n = m(e), o = this.getRoot(), i = N(o), s = O(n.url, "url"), r = new URL(s, i.location.href);
886
+ if (r.protocol !== "http:" && r.protocol !== "https:")
818
887
  throw new Error("Navigation only supports HTTP(S) URLs.");
819
- return this.refs.clear(), r.location.assign(i.toString()), { navigated: i.toString() };
888
+ return this.refs.clear(), i.location.assign(r.toString()), { navigated: r.toString() };
820
889
  }
821
890
  async hover(e) {
822
- const n = y(e), o = this.resolveElement(n), r = p(o).center;
891
+ const n = m(e), o = this.resolveElement(n), i = g(o).center;
823
892
  return await this.showVisualEffect({
824
893
  type: "hover",
825
894
  target: o,
826
895
  requested: o,
827
896
  anchor: "target",
828
- point: r
897
+ point: i
829
898
  }), o.dispatchEvent(
830
899
  new MouseEvent("mouseover", {
831
900
  bubbles: !0,
832
901
  cancelable: !0,
833
- clientX: r == null ? void 0 : r.x,
834
- clientY: r == null ? void 0 : r.y
902
+ clientX: i == null ? void 0 : i.x,
903
+ clientY: i == null ? void 0 : i.y
835
904
  })
836
905
  ), o.dispatchEvent(
837
906
  new MouseEvent("mousemove", {
838
907
  bubbles: !0,
839
908
  cancelable: !0,
840
- clientX: r == null ? void 0 : r.x,
841
- clientY: r == null ? void 0 : r.y
909
+ clientX: i == null ? void 0 : i.x,
910
+ clientY: i == null ? void 0 : i.y
842
911
  })
843
- ), { hovered: this.describeElement(o), point: r };
912
+ ), { hovered: this.describeElement(o), point: i };
844
913
  }
845
914
  async focus(e) {
846
- const n = y(e), o = this.resolveElement(n);
847
- return S(o), await this.showVisualEffect({
915
+ const n = m(e), o = this.resolveElement(n);
916
+ return M(o), await this.showVisualEffect({
848
917
  type: "focus",
849
918
  target: o,
850
919
  requested: o,
851
920
  anchor: "target",
852
- point: p(o).center
921
+ point: g(o).center
853
922
  }), { focused: this.describeElement(o) };
854
923
  }
855
924
  async pointer(e) {
856
- const n = y(e), o = W(n.action, ["move", "down", "up", "click"]) ?? "click", r = st(n.button) ?? 0, c = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, i = c ? p(c).center : {
857
- x: C(n.x, "x"),
858
- y: C(n.y, "y")
859
- };
860
- if (!i)
925
+ const n = m(e), o = Y(n.action, ["move", "down", "up", "click"]) ?? "click", i = dt(n.button) ?? 0, s = typeof n.x < "u" || typeof n.y < "u", r = x(n.targetText);
926
+ if (o === "click" && s && !r)
927
+ throw new Error(
928
+ "Pointer coordinate clicks require targetText to avoid unintended navigation."
929
+ );
930
+ const a = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, c = a ? g(a).center : U(this.getRoot(), n);
931
+ if (!c)
861
932
  throw new Error("Target element has no clickable point.");
862
- const s = c ?? m(this.getRoot()).elementFromPoint(i.x, i.y);
863
- if (!s)
864
- throw new Error(`No element found at (${i.x}, ${i.y}).`);
865
- const a = {
933
+ const d = a ?? T(this.getRoot()).elementFromPoint(c.x, c.y);
934
+ if (!d)
935
+ throw new Error(`No element found at (${c.x}, ${c.y}).`);
936
+ const u = r ? Nt(d, r) : void 0;
937
+ if (r && !u)
938
+ throw new Error(
939
+ `Pointer target text mismatch: expected hit target to contain "${r}".`
940
+ );
941
+ const l = {
866
942
  bubbles: !0,
867
943
  cancelable: !0,
868
- clientX: i.x,
869
- clientY: i.y,
870
- button: r
944
+ clientX: c.x,
945
+ clientY: c.y,
946
+ button: i
871
947
  };
872
948
  return o === "move" ? (await this.showVisualEffect({
873
949
  type: "pointer",
874
950
  action: o,
875
951
  anchor: "point",
876
- point: i,
877
- target: s
878
- }), s.dispatchEvent(L("pointermove", a)), s.dispatchEvent(new MouseEvent("mousemove", a))) : o === "down" ? (await this.showVisualEffect({
952
+ point: c,
953
+ target: d
954
+ }), d.dispatchEvent(L("pointermove", l)), d.dispatchEvent(new MouseEvent("mousemove", l))) : o === "down" ? (await this.showVisualEffect({
879
955
  type: "pointer",
880
956
  action: o,
881
957
  anchor: "point",
882
- point: i,
883
- target: s
884
- }), s.dispatchEvent(L("pointerdown", a)), s.dispatchEvent(new MouseEvent("mousedown", a))) : o === "up" ? (await this.showVisualEffect({
958
+ point: c,
959
+ target: d
960
+ }), d.dispatchEvent(L("pointerdown", l)), d.dispatchEvent(new MouseEvent("mousedown", l))) : o === "up" ? (await this.showVisualEffect({
885
961
  type: "pointer",
886
962
  action: o,
887
963
  anchor: "point",
888
- point: i,
889
- target: s
890
- }), s.dispatchEvent(L("pointerup", a)), s.dispatchEvent(new MouseEvent("mouseup", a))) : (await this.showVisualEffect({
964
+ point: c,
965
+ target: d
966
+ }), d.dispatchEvent(L("pointerup", l)), d.dispatchEvent(new MouseEvent("mouseup", l))) : (await this.showVisualEffect({
891
967
  type: "click",
892
968
  anchor: "point",
893
- point: i,
894
- target: s
895
- }), s.dispatchEvent(L("pointerdown", a)), s.dispatchEvent(new MouseEvent("mousedown", a)), s.dispatchEvent(L("pointerup", a)), s.dispatchEvent(new MouseEvent("mouseup", a)), s instanceof HTMLElement ? s.click() : s.dispatchEvent(new MouseEvent("click", a))), {
969
+ point: c,
970
+ target: d
971
+ }), d.dispatchEvent(L("pointerdown", l)), d.dispatchEvent(new MouseEvent("mousedown", l)), d.dispatchEvent(L("pointerup", l)), d.dispatchEvent(new MouseEvent("mouseup", l)), d instanceof HTMLElement ? d.click() : d.dispatchEvent(new MouseEvent("click", l))), {
896
972
  pointer: o,
897
- point: i,
898
- target: this.describeElement(s)
973
+ point: c,
974
+ coordinateSpace: "viewport-css-px",
975
+ target: this.describeElement(d),
976
+ targetTextMatched: u,
977
+ expectedAfterClick: o === "click" ? Ht(
978
+ this.getRoot(),
979
+ Rt(n.expectedAfterClick)
980
+ ) : void 0
899
981
  };
900
982
  }
901
983
  screenshot() {
@@ -904,14 +986,14 @@ class kt {
904
986
  );
905
987
  }
906
988
  async showVisualEffect(e) {
907
- var n, o, r, c;
989
+ var n, o, i, s;
908
990
  try {
909
991
  await ((o = (n = this.options).showVisualEffect) == null ? void 0 : o.call(n, e));
910
992
  } catch {
911
993
  }
912
994
  if (!(e.type !== "click" || !e.point || !e.target || this.options.showVisualEffect))
913
995
  try {
914
- await ((c = (r = this.options).showClickEffect) == null ? void 0 : c.call(r, {
996
+ await ((s = (i = this.options).showClickEffect) == null ? void 0 : s.call(i, {
915
997
  point: e.point,
916
998
  target: e.target,
917
999
  requested: e.requested
@@ -920,31 +1002,31 @@ class kt {
920
1002
  }
921
1003
  }
922
1004
  async waitFor(e) {
923
- const n = y(e), o = W(n.state, [
1005
+ const n = m(e), o = Y(n.state, [
924
1006
  "attached",
925
1007
  "visible",
926
1008
  "hidden",
927
1009
  "detached"
928
- ]) ?? "visible", r = _(n.timeoutSeconds), c = Math.min(
929
- rt,
930
- Math.max(0, (r ?? ot / 1e3) * 1e3)
931
- ), i = Date.now(), s = this.tryResolveElement(n);
1010
+ ]) ?? "visible", i = k(n.timeoutSeconds), s = Math.min(
1011
+ ct,
1012
+ Math.max(0, (i ?? at / 1e3) * 1e3)
1013
+ ), r = Date.now(), a = this.tryResolveElement(n);
932
1014
  for (await this.showVisualEffect({
933
1015
  type: "wait_for",
934
1016
  state: o,
935
- target: s ?? void 0,
936
- requested: s ?? void 0,
937
- ...s ? { anchor: "target" } : {},
938
- point: s ? p(s).center : void 0
939
- }); Date.now() - i <= c; ) {
940
- const a = this.tryResolveElement(n);
941
- if (o === "attached" ? !!a : o === "detached" ? !a : o === "hidden" ? !a || !T(a) : !!(a && T(a)))
1017
+ target: a ?? void 0,
1018
+ requested: a ?? void 0,
1019
+ ...a ? { anchor: "target" } : {},
1020
+ point: a ? g(a).center : void 0
1021
+ }); Date.now() - r <= s; ) {
1022
+ const c = this.tryResolveElement(n);
1023
+ if (o === "attached" ? !!c : o === "detached" ? !c : o === "hidden" ? !c || !_(c) : !!(c && _(c)))
942
1024
  return {
943
1025
  waitedFor: o,
944
- elapsedMs: Date.now() - i,
945
- target: a ? this.describeElement(a) : void 0
1026
+ elapsedMs: Date.now() - r,
1027
+ target: c ? this.describeElement(c) : void 0
946
1028
  };
947
- await new Promise((l) => setTimeout(l, 100));
1029
+ await new Promise((u) => setTimeout(u, 100));
948
1030
  }
949
1031
  throw new Error(`Timed out waiting for target to become ${o}.`);
950
1032
  }
@@ -958,54 +1040,268 @@ class kt {
958
1040
  describeElement(e) {
959
1041
  return {
960
1042
  tag: e.tagName.toLowerCase(),
961
- role: M(e),
962
- name: x(e),
963
- selector: D(e)
1043
+ role: S(e),
1044
+ name: v(e),
1045
+ selector: q(e)
964
1046
  };
965
1047
  }
966
1048
  }
967
- function Ct(t) {
1049
+ function Dt(t) {
968
1050
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
969
1051
  }
970
- function Nt(t) {
1052
+ function Vt(t) {
971
1053
  return JSON.stringify(t);
972
1054
  }
973
- function P(t, e, n) {
1055
+ function D(t, e, n) {
974
1056
  return {
975
1057
  tool_call_id: t.tool_call_id ?? t.id,
976
1058
  name: t.name,
977
1059
  status: e,
978
- content: Nt(n)
1060
+ content: Vt(n)
979
1061
  };
980
1062
  }
981
- function At(t) {
1063
+ function qt(t) {
982
1064
  return t instanceof Error ? t.message : String(t);
983
1065
  }
984
- function Rt(t = {}) {
985
- const e = new kt(t);
1066
+ function jt(t = {}) {
1067
+ const e = new It(t);
986
1068
  return async (n) => {
987
- if (!it(n.name))
988
- return P(n, "error", {
1069
+ if (!lt(n.name))
1070
+ return D(n, "error", {
989
1071
  ok: !1,
990
1072
  error: `Unknown host page automation tool: ${n.name}`
991
1073
  });
992
1074
  try {
993
1075
  const o = await e.execute(
994
1076
  n.name,
995
- Ct(n.params)
1077
+ Dt(n.params)
996
1078
  );
997
- return P(n, "success", { ok: !0, result: o });
1079
+ return D(n, "success", { ok: !0, result: o });
998
1080
  } catch (o) {
999
- return P(n, "error", {
1081
+ return D(n, "error", {
1000
1082
  ok: !1,
1001
- error: At(o)
1083
+ error: qt(o)
1002
1084
  });
1003
1085
  }
1004
1086
  };
1005
1087
  }
1088
+ const w = {
1089
+ ref: {
1090
+ type: ["string", "number"],
1091
+ description: "Element ref from host_page_snapshot."
1092
+ },
1093
+ axRef: {
1094
+ type: ["string", "number"],
1095
+ description: "Accessibility ref from host_page_snapshot."
1096
+ },
1097
+ selector: {
1098
+ type: "string",
1099
+ description: "CSS selector for the target element."
1100
+ },
1101
+ testId: {
1102
+ type: "string",
1103
+ description: "data-testid, data-test-id, or data-qa value."
1104
+ },
1105
+ role: {
1106
+ type: "string",
1107
+ description: "Accessible role to match."
1108
+ },
1109
+ name: {
1110
+ type: "string",
1111
+ description: "Accessible name to match."
1112
+ },
1113
+ text: {
1114
+ type: "string",
1115
+ description: "Visible text to match."
1116
+ },
1117
+ x: {
1118
+ type: "number",
1119
+ description: "Viewport x coordinate."
1120
+ },
1121
+ y: {
1122
+ type: "number",
1123
+ description: "Viewport y coordinate."
1124
+ }
1125
+ }, Bt = {
1126
+ coordinateSpace: {
1127
+ type: "string",
1128
+ enum: ["viewport-css-px", "viewport_normalized"],
1129
+ description: "Coordinate space for x/y. Use viewport_normalized for screenshot-derived points."
1130
+ }
1131
+ }, Ft = {
1132
+ type: "object",
1133
+ properties: {
1134
+ type: {
1135
+ const: "field_contains",
1136
+ description: "Currently supported post-click expectation type."
1137
+ },
1138
+ field: {
1139
+ type: "string",
1140
+ description: "Field label/name expected to change after clicking."
1141
+ },
1142
+ value: {
1143
+ type: "string",
1144
+ description: "Expected substring in the field value after clicking."
1145
+ }
1146
+ },
1147
+ required: ["type", "field", "value"],
1148
+ additionalProperties: !1
1149
+ }, $t = {
1150
+ host_page_snapshot: {
1151
+ type: "object",
1152
+ properties: {},
1153
+ additionalProperties: !1
1154
+ },
1155
+ host_page_click: {
1156
+ type: "object",
1157
+ properties: {
1158
+ ...w
1159
+ },
1160
+ additionalProperties: !1
1161
+ },
1162
+ host_page_fill: {
1163
+ type: "object",
1164
+ properties: {
1165
+ ...w,
1166
+ value: {
1167
+ type: "string",
1168
+ description: "Text value to set on the target field."
1169
+ }
1170
+ },
1171
+ required: ["value"],
1172
+ additionalProperties: !1
1173
+ },
1174
+ host_page_press: {
1175
+ type: "object",
1176
+ properties: {
1177
+ ...w,
1178
+ key: {
1179
+ type: "string",
1180
+ description: "Keyboard key to press."
1181
+ }
1182
+ },
1183
+ required: ["key"],
1184
+ additionalProperties: !1
1185
+ },
1186
+ host_page_select: {
1187
+ type: "object",
1188
+ properties: {
1189
+ ...w,
1190
+ value: {
1191
+ type: ["string", "array"],
1192
+ description: "Select option value or values.",
1193
+ items: { type: "string" }
1194
+ },
1195
+ values: {
1196
+ type: ["string", "array"],
1197
+ description: "Select option values.",
1198
+ items: { type: "string" }
1199
+ }
1200
+ },
1201
+ additionalProperties: !1
1202
+ },
1203
+ host_page_scroll: {
1204
+ type: "object",
1205
+ properties: {
1206
+ ...w,
1207
+ deltaX: {
1208
+ type: "number",
1209
+ description: "Horizontal scroll delta."
1210
+ },
1211
+ deltaY: {
1212
+ type: "number",
1213
+ description: "Vertical scroll delta."
1214
+ }
1215
+ },
1216
+ additionalProperties: !1
1217
+ },
1218
+ host_page_navigate: {
1219
+ type: "object",
1220
+ properties: {
1221
+ url: {
1222
+ type: "string",
1223
+ description: "HTTP(S) URL to navigate to."
1224
+ }
1225
+ },
1226
+ required: ["url"],
1227
+ additionalProperties: !1
1228
+ },
1229
+ host_page_hover: {
1230
+ type: "object",
1231
+ properties: {
1232
+ ...w
1233
+ },
1234
+ additionalProperties: !1
1235
+ },
1236
+ host_page_focus: {
1237
+ type: "object",
1238
+ properties: {
1239
+ ...w
1240
+ },
1241
+ additionalProperties: !1
1242
+ },
1243
+ host_page_pointer: {
1244
+ type: "object",
1245
+ properties: {
1246
+ ...w,
1247
+ ...Bt,
1248
+ action: {
1249
+ type: "string",
1250
+ enum: ["move", "down", "up", "click"],
1251
+ description: "Pointer action. Defaults to click."
1252
+ },
1253
+ button: {
1254
+ type: ["string", "number"],
1255
+ description: "Mouse button."
1256
+ },
1257
+ clickCount: {
1258
+ type: "number",
1259
+ description: "Number of clicks for CDP mouse click."
1260
+ },
1261
+ targetText: {
1262
+ type: "string",
1263
+ description: "Required for explicit coordinate clicks. The actual hit target or near ancestor must contain this text."
1264
+ },
1265
+ expectedAfterClick: Ft
1266
+ },
1267
+ additionalProperties: !1
1268
+ },
1269
+ host_page_screenshot: {
1270
+ type: "object",
1271
+ properties: {
1272
+ format: {
1273
+ type: "string",
1274
+ enum: ["jpeg", "png"],
1275
+ description: "Screenshot image format."
1276
+ },
1277
+ quality: {
1278
+ type: "number",
1279
+ description: "JPEG quality from 1 to 100."
1280
+ }
1281
+ },
1282
+ additionalProperties: !1
1283
+ },
1284
+ host_page_wait_for: {
1285
+ type: "object",
1286
+ properties: {
1287
+ ...w,
1288
+ state: {
1289
+ type: "string",
1290
+ enum: ["attached", "visible", "hidden", "detached"],
1291
+ description: "Target state to wait for. Defaults to visible."
1292
+ },
1293
+ timeoutSeconds: {
1294
+ type: "number",
1295
+ description: "Maximum wait time in seconds."
1296
+ }
1297
+ },
1298
+ additionalProperties: !1
1299
+ }
1300
+ };
1006
1301
  export {
1007
- tt as HOST_PAGE_AUTOMATION_TOOL_NAMES,
1008
- kt as HostPageAutomationExecutor,
1009
- Rt as createHostPageAutomationClientToolHandler,
1010
- it as isHostPageAutomationToolName
1302
+ it as HOST_PAGE_AUTOMATION_TOOL_NAMES,
1303
+ $t as HOST_PAGE_AUTOMATION_TOOL_SCHEMAS,
1304
+ It as HostPageAutomationExecutor,
1305
+ jt as createHostPageAutomationClientToolHandler,
1306
+ lt as isHostPageAutomationToolName
1011
1307
  };