@whenessel/seql-js 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/seql-js.d.ts +2 -4
- package/dist/seql-js.js +802 -682
- package/dist/seql-js.js.map +1 -1
- package/dist/seql-js.umd.cjs +1 -1
- package/dist/seql-js.umd.cjs.map +1 -1
- package/package.json +2 -1
package/dist/seql-js.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ee = "1.0", se = 10, L = {
|
|
2
2
|
ANCHOR: 0.4,
|
|
3
3
|
PATH: 0.3,
|
|
4
4
|
TARGET: 0.2,
|
|
5
5
|
UNIQUENESS: 0.1
|
|
6
|
-
},
|
|
6
|
+
}, I = {
|
|
7
7
|
SEMANTIC_TAG: 0.5,
|
|
8
8
|
ROLE: 0.3,
|
|
9
9
|
ARIA_LABEL: 0.1,
|
|
@@ -12,9 +12,9 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
12
12
|
DEPTH_PENALTY_THRESHOLD: 5,
|
|
13
13
|
DEPTH_PENALTY_FACTOR: 0.05,
|
|
14
14
|
DEGRADED_SCORE: 0.3
|
|
15
|
-
},
|
|
15
|
+
}, ct = {
|
|
16
16
|
MIN_CONFIDENCE_FOR_SKIP: 0.7
|
|
17
|
-
},
|
|
17
|
+
}, Y = [
|
|
18
18
|
"form",
|
|
19
19
|
"main",
|
|
20
20
|
"nav",
|
|
@@ -22,7 +22,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
22
22
|
"article",
|
|
23
23
|
"footer",
|
|
24
24
|
"header"
|
|
25
|
-
],
|
|
25
|
+
], X = [
|
|
26
26
|
"form",
|
|
27
27
|
"navigation",
|
|
28
28
|
"main",
|
|
@@ -31,7 +31,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
31
31
|
"complementary",
|
|
32
32
|
"banner",
|
|
33
33
|
"search"
|
|
34
|
-
],
|
|
34
|
+
], lt = [
|
|
35
35
|
// HTML5 Semantic
|
|
36
36
|
"article",
|
|
37
37
|
"aside",
|
|
@@ -108,7 +108,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
108
108
|
"g",
|
|
109
109
|
"text",
|
|
110
110
|
"use"
|
|
111
|
-
],
|
|
111
|
+
], ht = [
|
|
112
112
|
"rect",
|
|
113
113
|
"path",
|
|
114
114
|
"circle",
|
|
@@ -122,7 +122,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
122
122
|
"defs",
|
|
123
123
|
"clipPath",
|
|
124
124
|
"mask"
|
|
125
|
-
],
|
|
125
|
+
], re = [
|
|
126
126
|
"aria-label",
|
|
127
127
|
"aria-labelledby",
|
|
128
128
|
"aria-describedby",
|
|
@@ -135,7 +135,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
135
135
|
"title",
|
|
136
136
|
"placeholder",
|
|
137
137
|
"alt"
|
|
138
|
-
],
|
|
138
|
+
], w = {
|
|
139
139
|
// Test attributes (highest priority)
|
|
140
140
|
"data-testid": 100,
|
|
141
141
|
"data-qa": 99,
|
|
@@ -162,7 +162,7 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
162
162
|
"data-*": 30,
|
|
163
163
|
// Any aria-* attribute (if not above)
|
|
164
164
|
"aria-*": 25
|
|
165
|
-
},
|
|
165
|
+
}, et = /* @__PURE__ */ new Set([
|
|
166
166
|
"id",
|
|
167
167
|
// handled separately
|
|
168
168
|
"class",
|
|
@@ -174,22 +174,39 @@ const Wt = "1.0", Bt = 10, L = {
|
|
|
174
174
|
"tabindex",
|
|
175
175
|
// can change
|
|
176
176
|
"contenteditable"
|
|
177
|
-
]),
|
|
177
|
+
]), ut = {
|
|
178
178
|
maxPathDepth: 10,
|
|
179
179
|
enableSvgFingerprint: !0,
|
|
180
180
|
confidenceThreshold: 0.1,
|
|
181
181
|
fallbackToBody: !0,
|
|
182
182
|
includeUtilityClasses: !1,
|
|
183
183
|
source: "dom-dsl"
|
|
184
|
-
},
|
|
184
|
+
}, dt = {
|
|
185
185
|
strictMode: !1,
|
|
186
186
|
enableFallback: !0,
|
|
187
187
|
maxCandidates: 20
|
|
188
188
|
};
|
|
189
|
-
function
|
|
190
|
-
return !!(/^[a-z]+-\d+$/i.test(n) || /^\d+$/.test(n) || /^:[a-z0-9]+:$/i.test(n) || /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(n) || /^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(n) && (/\d/.test(n) || /[A-Z]/.test(n)) || /^radix-/.test(n) || /^mui-\d+$/.test(n));
|
|
189
|
+
function D(n) {
|
|
190
|
+
return !!(/^[a-z]+-\d+$/i.test(n) || /^[a-z]+(-[a-z]+)+-\d+$/i.test(n) || /^[a-z]+(_[a-z]+)*_\d+$/i.test(n) || /^\d+$/.test(n) || /^:[a-z0-9]+:$/i.test(n) || /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(n) || /^[a-z]{1,3}[A-Za-z0-9]{8,}$/.test(n) && (/\d/.test(n) || /[A-Z]/.test(n)) || /^radix-/.test(n) || /^mui-\d+$/.test(n));
|
|
191
|
+
}
|
|
192
|
+
const B = /* @__PURE__ */ new Set([
|
|
193
|
+
"aria-labelledby",
|
|
194
|
+
"aria-describedby",
|
|
195
|
+
"aria-controls",
|
|
196
|
+
"aria-owns",
|
|
197
|
+
"aria-activedescendant",
|
|
198
|
+
"for",
|
|
199
|
+
"form",
|
|
200
|
+
"list",
|
|
201
|
+
"headers",
|
|
202
|
+
"aria-details",
|
|
203
|
+
"aria-errormessage",
|
|
204
|
+
"aria-flowto"
|
|
205
|
+
]);
|
|
206
|
+
function G(n) {
|
|
207
|
+
return n.trim().split(/\s+/).some((e) => D(e));
|
|
191
208
|
}
|
|
192
|
-
class
|
|
209
|
+
class ft {
|
|
193
210
|
constructor(t, e) {
|
|
194
211
|
this.maxDepth = t.maxPathDepth ?? 10, this.cache = e;
|
|
195
212
|
}
|
|
@@ -200,30 +217,30 @@ class ut {
|
|
|
200
217
|
*/
|
|
201
218
|
findAnchor(t) {
|
|
202
219
|
if (this.cache) {
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
return
|
|
220
|
+
const i = this.cache.getAnchor(t);
|
|
221
|
+
if (i !== void 0)
|
|
222
|
+
return i;
|
|
206
223
|
}
|
|
207
224
|
let e = t.parentElement, s = 0, r = null;
|
|
208
225
|
for (; e && s < this.maxDepth; ) {
|
|
209
226
|
if (e.tagName.toLowerCase() === "body")
|
|
210
227
|
return r || {
|
|
211
228
|
element: e,
|
|
212
|
-
score:
|
|
229
|
+
score: I.DEGRADED_SCORE,
|
|
213
230
|
tier: "C",
|
|
214
231
|
depth: s
|
|
215
232
|
};
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
const o = this.applyDepthPenalty(
|
|
233
|
+
const i = this.scoreAnchor(e);
|
|
234
|
+
if (i > 0) {
|
|
235
|
+
const o = this.applyDepthPenalty(i, s), l = this.getTier(e), u = { element: e, score: o, tier: l, depth: s };
|
|
219
236
|
if (l === "A")
|
|
220
|
-
return
|
|
221
|
-
(!r || o > r.score) && (r =
|
|
237
|
+
return u;
|
|
238
|
+
(!r || o > r.score) && (r = u);
|
|
222
239
|
}
|
|
223
240
|
e = e.parentElement, s++;
|
|
224
241
|
}
|
|
225
|
-
const
|
|
226
|
-
return this.cache && this.cache.setAnchor(t,
|
|
242
|
+
const a = r;
|
|
243
|
+
return this.cache && this.cache.setAnchor(t, a), a;
|
|
227
244
|
}
|
|
228
245
|
/**
|
|
229
246
|
* Scores an element as anchor candidate (without depth penalty)
|
|
@@ -233,20 +250,20 @@ class ut {
|
|
|
233
250
|
scoreAnchor(t) {
|
|
234
251
|
let e = 0;
|
|
235
252
|
const s = t.tagName.toLowerCase();
|
|
236
|
-
|
|
253
|
+
Y.includes(s) && (e += I.SEMANTIC_TAG);
|
|
237
254
|
const r = t.getAttribute("role");
|
|
238
|
-
r &&
|
|
239
|
-
const
|
|
240
|
-
return
|
|
255
|
+
r && X.includes(r) && (e += I.ROLE), (t.hasAttribute("aria-label") || t.hasAttribute("aria-labelledby")) && (e += I.ARIA_LABEL);
|
|
256
|
+
const a = t.id;
|
|
257
|
+
return a && !D(a) && (e += I.STABLE_ID), (t.hasAttribute("data-testid") || t.hasAttribute("data-qa") || t.hasAttribute("data-test")) && (e += I.TEST_MARKER), Math.min(e, 1);
|
|
241
258
|
}
|
|
242
259
|
/**
|
|
243
260
|
* Applies depth penalty to score
|
|
244
261
|
* Following SPECIFICATION.md §7: depthPenalty = (depth - threshold) * factor
|
|
245
262
|
*/
|
|
246
263
|
applyDepthPenalty(t, e) {
|
|
247
|
-
if (e <=
|
|
264
|
+
if (e <= I.DEPTH_PENALTY_THRESHOLD)
|
|
248
265
|
return t;
|
|
249
|
-
const s = (e -
|
|
266
|
+
const s = (e - I.DEPTH_PENALTY_THRESHOLD) * I.DEPTH_PENALTY_FACTOR;
|
|
250
267
|
return Math.max(0, t - s);
|
|
251
268
|
}
|
|
252
269
|
/**
|
|
@@ -254,13 +271,13 @@ class ut {
|
|
|
254
271
|
*/
|
|
255
272
|
getTier(t) {
|
|
256
273
|
const e = t.tagName.toLowerCase();
|
|
257
|
-
if (
|
|
274
|
+
if (Y.includes(e))
|
|
258
275
|
return "A";
|
|
259
276
|
const s = t.getAttribute("role");
|
|
260
|
-
return s &&
|
|
277
|
+
return s && X.includes(s) ? "B" : "C";
|
|
261
278
|
}
|
|
262
279
|
}
|
|
263
|
-
const
|
|
280
|
+
const gt = [
|
|
264
281
|
// CSS-in-JS
|
|
265
282
|
/^css-[a-z0-9]+$/i,
|
|
266
283
|
/^sc-[a-z0-9]+-\d+$/i,
|
|
@@ -280,7 +297,7 @@ const ft = [
|
|
|
280
297
|
/^_[a-z0-9]{5,}$/i,
|
|
281
298
|
/\d{5,}/
|
|
282
299
|
// 5+ digits in a row
|
|
283
|
-
],
|
|
300
|
+
], pt = [
|
|
284
301
|
// === FIX 4: Tailwind arbitrary values and variants (highest priority) ===
|
|
285
302
|
/^\[/,
|
|
286
303
|
// Any arbitrary value or variant starting with [ (e.g., [&_svg]:..., [mask-type:luminance])
|
|
@@ -314,6 +331,23 @@ const ft = [
|
|
|
314
331
|
// === Spacing (Tailwind) ===
|
|
315
332
|
/^(gap|space)-/,
|
|
316
333
|
/^[mp][trblxy]?-(\d+|auto|px)$/,
|
|
334
|
+
// === Negative Tailwind utilities (margins, positioning, transforms) ===
|
|
335
|
+
/^-[mp][trblxy]?-\d+$/,
|
|
336
|
+
// -m-4, -mt-2, -mx-4, -px-4, -py-2
|
|
337
|
+
/^-(top|right|bottom|left|inset)-\d+$/,
|
|
338
|
+
// -top-4, -bottom-6, -left-6, -inset-0
|
|
339
|
+
/^-z-\d+$/,
|
|
340
|
+
// -z-10, -z-20
|
|
341
|
+
/^-space-[xy]-\d+$/,
|
|
342
|
+
// -space-x-2, -space-y-4
|
|
343
|
+
/^-translate-[xy]-\d+$/,
|
|
344
|
+
// -translate-x-4, -translate-y-2
|
|
345
|
+
/^-rotate-\d+$/,
|
|
346
|
+
// -rotate-45, -rotate-90
|
|
347
|
+
/^-scale-\d+$/,
|
|
348
|
+
// -scale-50, -scale-75
|
|
349
|
+
/^-skew-[xy]-\d+$/,
|
|
350
|
+
// -skew-x-12, -skew-y-6
|
|
317
351
|
// === Sizing ===
|
|
318
352
|
/^(w|h|min-w|min-h|max-w|max-h|size)-/,
|
|
319
353
|
// === Colors & Styling ===
|
|
@@ -338,6 +372,7 @@ const ft = [
|
|
|
338
372
|
// animations
|
|
339
373
|
// === Overflow & Scrolling ===
|
|
340
374
|
/^(overflow|overscroll|scroll)-/,
|
|
375
|
+
/^object-(contain|cover|fill|none|scale-down)$/,
|
|
341
376
|
// === Interactivity ===
|
|
342
377
|
/^(cursor|pointer-events|select|resize)-/,
|
|
343
378
|
// === Visibility & Opacity ===
|
|
@@ -368,7 +403,7 @@ const ft = [
|
|
|
368
403
|
/^clearfix$/,
|
|
369
404
|
/^pull-(left|right)$/,
|
|
370
405
|
/^float-(left|right|none)$/
|
|
371
|
-
],
|
|
406
|
+
], mt = [
|
|
372
407
|
// === Navigation ===
|
|
373
408
|
/^(nav|menu|header|footer|sidebar|topbar|navbar|breadcrumb)/,
|
|
374
409
|
/(navigation|dropdown|megamenu)$/,
|
|
@@ -395,41 +430,41 @@ const ft = [
|
|
|
395
430
|
// === Status ===
|
|
396
431
|
/^(loading|pending|complete|failed|draft|published)/
|
|
397
432
|
];
|
|
398
|
-
function
|
|
399
|
-
return
|
|
433
|
+
function k(n) {
|
|
434
|
+
return gt.some((t) => t.test(n));
|
|
400
435
|
}
|
|
401
|
-
function
|
|
402
|
-
return n.length <= 2 || /^\d/.test(n) ? !0 :
|
|
436
|
+
function q(n) {
|
|
437
|
+
return n.length <= 2 || /^\d/.test(n) ? !0 : pt.some((t) => t.test(n));
|
|
403
438
|
}
|
|
404
|
-
function
|
|
405
|
-
return
|
|
439
|
+
function bt(n) {
|
|
440
|
+
return k(n) || q(n) ? !1 : mt.some((t) => t.test(n));
|
|
406
441
|
}
|
|
407
|
-
function
|
|
408
|
-
return !
|
|
442
|
+
function St(n) {
|
|
443
|
+
return !k(n) && !q(n);
|
|
409
444
|
}
|
|
410
|
-
function
|
|
411
|
-
return n.filter((t) =>
|
|
445
|
+
function N(n) {
|
|
446
|
+
return n.filter((t) => St(t));
|
|
412
447
|
}
|
|
413
|
-
function
|
|
414
|
-
if (
|
|
448
|
+
function yt(n) {
|
|
449
|
+
if (k(n) || q(n))
|
|
415
450
|
return 0;
|
|
416
451
|
let t = 0.5;
|
|
417
|
-
return
|
|
452
|
+
return bt(n) && (t = 0.8), n.length < 3 ? t *= 0.3 : n.length < 5 && (t *= 0.6), /\d/.test(n) && (t *= 0.7), Math.min(t, 1);
|
|
418
453
|
}
|
|
419
|
-
function
|
|
454
|
+
function At(n) {
|
|
420
455
|
const t = [], e = [];
|
|
421
456
|
for (const s of n)
|
|
422
|
-
|
|
457
|
+
q(s) || k(s) ? e.push(s) : t.push(s);
|
|
423
458
|
return { semantic: t, utility: e };
|
|
424
459
|
}
|
|
425
|
-
function
|
|
426
|
-
return
|
|
460
|
+
function K(n) {
|
|
461
|
+
return q(n) || k(n);
|
|
427
462
|
}
|
|
428
|
-
function
|
|
429
|
-
return
|
|
463
|
+
function ne(n) {
|
|
464
|
+
return yt(n);
|
|
430
465
|
}
|
|
431
|
-
const
|
|
432
|
-
class
|
|
466
|
+
const J = (n) => n.replace(/([#:.[\]@])/g, "\\$1");
|
|
467
|
+
class xt {
|
|
433
468
|
constructor(t, e) {
|
|
434
469
|
this.maxDepth = t.maxPathDepth ?? 10, this.cache = e;
|
|
435
470
|
}
|
|
@@ -442,10 +477,10 @@ class yt {
|
|
|
442
477
|
*/
|
|
443
478
|
buildPath(t, e, s) {
|
|
444
479
|
const r = [];
|
|
445
|
-
let
|
|
446
|
-
for (;
|
|
447
|
-
r.unshift(
|
|
448
|
-
const
|
|
480
|
+
let a = e.parentElement;
|
|
481
|
+
for (; a && a !== t && r.length < this.maxDepth; )
|
|
482
|
+
r.unshift(a), a = a.parentElement;
|
|
483
|
+
const i = r.length >= this.maxDepth && a !== t;
|
|
449
484
|
let o = this.filterNoise(r);
|
|
450
485
|
return o = this.ensureUniqueness(
|
|
451
486
|
r,
|
|
@@ -454,22 +489,22 @@ class yt {
|
|
|
454
489
|
e,
|
|
455
490
|
s
|
|
456
491
|
), {
|
|
457
|
-
path: o.map((
|
|
458
|
-
const
|
|
459
|
-
let
|
|
460
|
-
if (
|
|
461
|
-
const g = Array.from(
|
|
462
|
-
g !== -1 && (
|
|
492
|
+
path: o.map((u) => {
|
|
493
|
+
const d = u.parentElement;
|
|
494
|
+
let c;
|
|
495
|
+
if (d) {
|
|
496
|
+
const g = Array.from(d.children).indexOf(u);
|
|
497
|
+
g !== -1 && (c = g + 1);
|
|
463
498
|
}
|
|
464
499
|
return {
|
|
465
|
-
tag:
|
|
466
|
-
semantics: s.extract(
|
|
467
|
-
score: s.scoreElement(
|
|
468
|
-
nthChild:
|
|
500
|
+
tag: u.tagName.toLowerCase(),
|
|
501
|
+
semantics: s.extract(u),
|
|
502
|
+
score: s.scoreElement(u),
|
|
503
|
+
nthChild: c
|
|
469
504
|
};
|
|
470
505
|
}),
|
|
471
|
-
degraded:
|
|
472
|
-
degradationReason:
|
|
506
|
+
degraded: i,
|
|
507
|
+
degradationReason: i ? "path-depth-overflow" : void 0
|
|
473
508
|
};
|
|
474
509
|
}
|
|
475
510
|
/**
|
|
@@ -482,34 +517,34 @@ class yt {
|
|
|
482
517
|
* Ensures path uniqueness by adding nodes if needed
|
|
483
518
|
* Following SPECIFICATION.md §8 Disambiguation Algorithm
|
|
484
519
|
*/
|
|
485
|
-
ensureUniqueness(t, e, s, r,
|
|
486
|
-
const
|
|
520
|
+
ensureUniqueness(t, e, s, r, a) {
|
|
521
|
+
const i = this.buildTestSelector(s, e, r);
|
|
487
522
|
try {
|
|
488
523
|
const o = r.ownerDocument;
|
|
489
524
|
if (!o) return e;
|
|
490
525
|
let l;
|
|
491
526
|
if (this.cache) {
|
|
492
|
-
const
|
|
493
|
-
|
|
527
|
+
const d = this.cache.getSelectorResults(i);
|
|
528
|
+
d !== void 0 ? l = d : (l = Array.from(o.querySelectorAll(i)), this.cache.setSelectorResults(i, l));
|
|
494
529
|
} else
|
|
495
|
-
l = o.querySelectorAll(
|
|
530
|
+
l = o.querySelectorAll(i);
|
|
496
531
|
if (l.length <= 1)
|
|
497
532
|
return e;
|
|
498
|
-
const
|
|
499
|
-
for (const
|
|
500
|
-
if (
|
|
533
|
+
const u = t.filter((d) => !e.includes(d));
|
|
534
|
+
for (const d of u) {
|
|
535
|
+
if (a.scoreElement(d) < ct.MIN_CONFIDENCE_FOR_SKIP)
|
|
501
536
|
continue;
|
|
502
|
-
const
|
|
537
|
+
const h = this.insertNodeInOrder(e, d, t), g = this.buildTestSelector(s, h, r);
|
|
503
538
|
try {
|
|
504
|
-
let
|
|
539
|
+
let f;
|
|
505
540
|
if (this.cache) {
|
|
506
|
-
const
|
|
507
|
-
|
|
541
|
+
const p = this.cache.getSelectorResults(g);
|
|
542
|
+
p !== void 0 ? f = p : (f = Array.from(o.querySelectorAll(g)), this.cache.setSelectorResults(g, f));
|
|
508
543
|
} else
|
|
509
|
-
|
|
510
|
-
if (
|
|
511
|
-
return
|
|
512
|
-
|
|
544
|
+
f = o.querySelectorAll(g);
|
|
545
|
+
if (f.length === 1)
|
|
546
|
+
return h;
|
|
547
|
+
f.length < l.length && (e = h);
|
|
513
548
|
} catch {
|
|
514
549
|
}
|
|
515
550
|
}
|
|
@@ -522,11 +557,11 @@ class yt {
|
|
|
522
557
|
* Inserts node into path maintaining original order
|
|
523
558
|
*/
|
|
524
559
|
insertNodeInOrder(t, e, s) {
|
|
525
|
-
const r = s.indexOf(e),
|
|
526
|
-
let
|
|
527
|
-
for (let o = 0; o <
|
|
528
|
-
|
|
529
|
-
return
|
|
560
|
+
const r = s.indexOf(e), a = [...t];
|
|
561
|
+
let i = 0;
|
|
562
|
+
for (let o = 0; o < a.length && !(s.indexOf(a[o]) > r); o++)
|
|
563
|
+
i = o + 1;
|
|
564
|
+
return a.splice(i, 0, e), a;
|
|
530
565
|
}
|
|
531
566
|
/**
|
|
532
567
|
* Builds a test CSS selector from path
|
|
@@ -534,8 +569,8 @@ class yt {
|
|
|
534
569
|
buildTestSelector(t, e, s) {
|
|
535
570
|
const r = [];
|
|
536
571
|
r.push(this.elementToSelector(t));
|
|
537
|
-
for (const
|
|
538
|
-
r.push(this.elementToSelector(
|
|
572
|
+
for (const a of e)
|
|
573
|
+
r.push(this.elementToSelector(a));
|
|
539
574
|
return r.push(this.elementToSelector(s)), r.join(" ");
|
|
540
575
|
}
|
|
541
576
|
/**
|
|
@@ -543,9 +578,9 @@ class yt {
|
|
|
543
578
|
*/
|
|
544
579
|
elementToSelector(t) {
|
|
545
580
|
let e = t.tagName.toLowerCase();
|
|
546
|
-
t.id && !
|
|
581
|
+
t.id && !D(t.id) && (e += `#${J(t.id)}`);
|
|
547
582
|
for (const s of Array.from(t.classList))
|
|
548
|
-
|
|
583
|
+
K(s) || (e += `.${J(s)}`);
|
|
549
584
|
return e;
|
|
550
585
|
}
|
|
551
586
|
/**
|
|
@@ -559,7 +594,7 @@ class yt {
|
|
|
559
594
|
*/
|
|
560
595
|
shouldInclude(t) {
|
|
561
596
|
const e = t.tagName.toLowerCase();
|
|
562
|
-
return
|
|
597
|
+
return lt.includes(e) ? !0 : e === "div" || e === "span" ? this.hasSemanticFeatures(t) : !1;
|
|
563
598
|
}
|
|
564
599
|
/**
|
|
565
600
|
* Checks if element has meaningful semantic features
|
|
@@ -570,22 +605,22 @@ class yt {
|
|
|
570
605
|
if (s.name.startsWith("aria-")) return !0;
|
|
571
606
|
if (t.classList.length > 0) {
|
|
572
607
|
for (const s of Array.from(t.classList))
|
|
573
|
-
if (!
|
|
608
|
+
if (!K(s)) return !0;
|
|
574
609
|
}
|
|
575
610
|
if (t.hasAttribute("data-testid") || t.hasAttribute("data-qa") || t.hasAttribute("data-test"))
|
|
576
611
|
return !0;
|
|
577
612
|
const e = t.id;
|
|
578
|
-
return !!(e && !
|
|
613
|
+
return !!(e && !D(e));
|
|
579
614
|
}
|
|
580
615
|
}
|
|
581
|
-
function
|
|
616
|
+
function V(n) {
|
|
582
617
|
return n ? n.trim().replace(/[\n\t\r]/g, " ").replace(/\s+/g, " ") : "";
|
|
583
618
|
}
|
|
584
|
-
const
|
|
619
|
+
const Ct = {
|
|
585
620
|
preserveQueryForAbsolute: !0,
|
|
586
621
|
removeDynamicHashes: !0
|
|
587
622
|
};
|
|
588
|
-
function
|
|
623
|
+
function Tt(n) {
|
|
589
624
|
return n ? [
|
|
590
625
|
/\d{5,}/,
|
|
591
626
|
// 5+ digits
|
|
@@ -599,20 +634,110 @@ function xt(n) {
|
|
|
599
634
|
// UUID-like
|
|
600
635
|
].some((e) => e.test(n)) : !1;
|
|
601
636
|
}
|
|
602
|
-
function
|
|
637
|
+
function Et(n, t) {
|
|
603
638
|
if (!n) return n;
|
|
604
639
|
const e = n.startsWith("http://") || n.startsWith("https://");
|
|
605
640
|
let [s, r] = n.split("#");
|
|
606
|
-
const [
|
|
607
|
-
let o =
|
|
608
|
-
return e && t.preserveQueryForAbsolute &&
|
|
641
|
+
const [a, i] = s.split("?");
|
|
642
|
+
let o = a;
|
|
643
|
+
return e && t.preserveQueryForAbsolute && i && (o += `?${i}`), r && (t.removeDynamicHashes && Tt(r) || (o += `#${r}`)), o;
|
|
609
644
|
}
|
|
610
|
-
function
|
|
645
|
+
function _(n, t, e = {}) {
|
|
611
646
|
if (!t) return t;
|
|
612
|
-
const s = { ...
|
|
613
|
-
return n === "href" || n === "src" ?
|
|
647
|
+
const s = { ...Ct, ...e };
|
|
648
|
+
return n === "href" || n === "src" ? Et(t, s) : t;
|
|
614
649
|
}
|
|
615
|
-
|
|
650
|
+
const wt = [
|
|
651
|
+
"role",
|
|
652
|
+
"aria-label",
|
|
653
|
+
"aria-labelledby",
|
|
654
|
+
"aria-describedby",
|
|
655
|
+
"aria-controls",
|
|
656
|
+
"aria-owns",
|
|
657
|
+
"aria-level",
|
|
658
|
+
"aria-posinset",
|
|
659
|
+
"aria-setsize",
|
|
660
|
+
"aria-haspopup"
|
|
661
|
+
], vt = [
|
|
662
|
+
"aria-selected",
|
|
663
|
+
"aria-checked",
|
|
664
|
+
"aria-pressed",
|
|
665
|
+
"aria-expanded",
|
|
666
|
+
"aria-hidden",
|
|
667
|
+
"aria-disabled",
|
|
668
|
+
"aria-current",
|
|
669
|
+
"aria-busy",
|
|
670
|
+
"aria-invalid",
|
|
671
|
+
"aria-grabbed",
|
|
672
|
+
"aria-live",
|
|
673
|
+
"aria-atomic"
|
|
674
|
+
], $t = [
|
|
675
|
+
"data-state",
|
|
676
|
+
"data-active",
|
|
677
|
+
"data-inactive",
|
|
678
|
+
"data-selected",
|
|
679
|
+
"data-open",
|
|
680
|
+
"data-closed",
|
|
681
|
+
"data-visible",
|
|
682
|
+
"data-hidden",
|
|
683
|
+
"data-disabled",
|
|
684
|
+
"data-enabled",
|
|
685
|
+
"data-loading",
|
|
686
|
+
"data-error",
|
|
687
|
+
"data-success",
|
|
688
|
+
"data-highlighted",
|
|
689
|
+
"data-focused",
|
|
690
|
+
"data-hover",
|
|
691
|
+
"data-orientation",
|
|
692
|
+
"data-theme"
|
|
693
|
+
], Mt = [
|
|
694
|
+
"data-radix-",
|
|
695
|
+
"data-headlessui-",
|
|
696
|
+
"data-reach-",
|
|
697
|
+
"data-mui-",
|
|
698
|
+
"data-chakra-",
|
|
699
|
+
"data-mantine-",
|
|
700
|
+
"data-tw-"
|
|
701
|
+
], It = [
|
|
702
|
+
"data-testid",
|
|
703
|
+
"data-test-id",
|
|
704
|
+
"data-test",
|
|
705
|
+
"data-cy",
|
|
706
|
+
"data-qa",
|
|
707
|
+
"data-automation-id",
|
|
708
|
+
"data-id",
|
|
709
|
+
"data-component",
|
|
710
|
+
"data-entity-id",
|
|
711
|
+
"data-product-id",
|
|
712
|
+
"data-user-id"
|
|
713
|
+
], Rt = [
|
|
714
|
+
"id",
|
|
715
|
+
"name",
|
|
716
|
+
"type",
|
|
717
|
+
"placeholder",
|
|
718
|
+
"title",
|
|
719
|
+
"for",
|
|
720
|
+
"alt",
|
|
721
|
+
"href"
|
|
722
|
+
], Nt = [
|
|
723
|
+
"disabled",
|
|
724
|
+
"checked",
|
|
725
|
+
"selected",
|
|
726
|
+
"hidden",
|
|
727
|
+
"readonly",
|
|
728
|
+
"required",
|
|
729
|
+
"value"
|
|
730
|
+
], Dt = [
|
|
731
|
+
/^radix-/,
|
|
732
|
+
/^headlessui-/,
|
|
733
|
+
/^mui-/,
|
|
734
|
+
/:\w+:/
|
|
735
|
+
// matches :ru:, :r1:, etc.
|
|
736
|
+
];
|
|
737
|
+
function Ht(n, t) {
|
|
738
|
+
return wt.includes(n) ? !0 : vt.includes(n) || $t.includes(n) || Mt.some((e) => n.startsWith(e)) ? !1 : It.includes(n) || n.startsWith("data-") && n.endsWith("-id") ? !0 : n === "id" ? !Dt.some((e) => e.test(t)) : Rt.includes(n) ? !0 : Nt.includes(n) ? !1 : !!n.startsWith("data-");
|
|
739
|
+
}
|
|
740
|
+
class Pt {
|
|
616
741
|
constructor(t, e) {
|
|
617
742
|
this.includeUtilityClasses = t.includeUtilityClasses ?? !1, this.cache = e;
|
|
618
743
|
}
|
|
@@ -623,26 +748,26 @@ class Et {
|
|
|
623
748
|
*/
|
|
624
749
|
extract(t) {
|
|
625
750
|
if (this.cache) {
|
|
626
|
-
const
|
|
627
|
-
if (
|
|
628
|
-
return
|
|
751
|
+
const i = this.cache.getSemantics(t);
|
|
752
|
+
if (i !== void 0)
|
|
753
|
+
return i;
|
|
629
754
|
}
|
|
630
755
|
const e = {}, s = t.id;
|
|
631
|
-
if (s && !
|
|
632
|
-
const
|
|
756
|
+
if (s && !D(s) && (e.id = s), t.classList.length > 0) {
|
|
757
|
+
const i = Array.from(t.classList);
|
|
633
758
|
if (this.includeUtilityClasses)
|
|
634
|
-
e.classes =
|
|
759
|
+
e.classes = i;
|
|
635
760
|
else {
|
|
636
|
-
const { semantic: o } =
|
|
761
|
+
const { semantic: o } = At(i);
|
|
637
762
|
o.length > 0 && (e.classes = o);
|
|
638
763
|
}
|
|
639
764
|
}
|
|
640
765
|
const r = this.extractAttributes(t);
|
|
641
766
|
Object.keys(r).length > 0 && (e.attributes = r);
|
|
642
|
-
const
|
|
643
|
-
if (
|
|
644
|
-
const
|
|
645
|
-
|
|
767
|
+
const a = t.getAttribute("role");
|
|
768
|
+
if (a && (e.role = a), this.shouldExtractText(t)) {
|
|
769
|
+
const i = this.extractText(t);
|
|
770
|
+
i && (e.text = i);
|
|
646
771
|
}
|
|
647
772
|
return this.cache && this.cache.setSemantics(t, e), e;
|
|
648
773
|
}
|
|
@@ -662,7 +787,7 @@ class Et {
|
|
|
662
787
|
* @returns True if should be ignored
|
|
663
788
|
*/
|
|
664
789
|
shouldIgnoreAttribute(t) {
|
|
665
|
-
return !!(
|
|
790
|
+
return !!(et.has(t) || t.startsWith("on") || t.startsWith("ng-") || t.startsWith("_ng") || t.startsWith("data-reactid") || t.startsWith("data-react") || t.startsWith("data-v-"));
|
|
666
791
|
}
|
|
667
792
|
/**
|
|
668
793
|
* Gets attribute priority
|
|
@@ -670,7 +795,7 @@ class Et {
|
|
|
670
795
|
* @returns Priority number (higher = more priority)
|
|
671
796
|
*/
|
|
672
797
|
getAttributePriority(t) {
|
|
673
|
-
return
|
|
798
|
+
return w[t] !== void 0 ? w[t] : t.startsWith("data-") ? w["data-*"] : t.startsWith("aria-") ? w["aria-*"] : 0;
|
|
674
799
|
}
|
|
675
800
|
/**
|
|
676
801
|
* Checks if attribute value is dynamic (should be ignored)
|
|
@@ -697,9 +822,9 @@ class Et {
|
|
|
697
822
|
const e = {};
|
|
698
823
|
for (const s of Array.from(t.attributes)) {
|
|
699
824
|
const r = s.name;
|
|
700
|
-
if (this.shouldIgnoreAttribute(r) || this.getAttributePriority(r) === 0) continue;
|
|
701
|
-
const
|
|
702
|
-
!
|
|
825
|
+
if (this.shouldIgnoreAttribute(r) || !Ht(r, s.value) || B.has(r) && G(s.value) || this.getAttributePriority(r) === 0) continue;
|
|
826
|
+
const i = r === "href" || r === "src" ? _(r, s.value) : s.value;
|
|
827
|
+
!i || i.trim() === "" || this.isDynamicValue(i) || (e[r] = i);
|
|
703
828
|
}
|
|
704
829
|
return e;
|
|
705
830
|
}
|
|
@@ -709,12 +834,12 @@ class Et {
|
|
|
709
834
|
extractText(t) {
|
|
710
835
|
const e = this.getDirectTextContent(t);
|
|
711
836
|
if (!e) return null;
|
|
712
|
-
const s =
|
|
837
|
+
const s = V(e);
|
|
713
838
|
if (!s) return null;
|
|
714
|
-
const r = 100,
|
|
839
|
+
const r = 100, a = e.length > r ? e.slice(0, r) + "..." : e, i = s.length > r ? s.slice(0, r) + "..." : s;
|
|
715
840
|
return {
|
|
716
|
-
raw:
|
|
717
|
-
normalized:
|
|
841
|
+
raw: a,
|
|
842
|
+
normalized: i
|
|
718
843
|
};
|
|
719
844
|
}
|
|
720
845
|
/**
|
|
@@ -757,7 +882,7 @@ class Et {
|
|
|
757
882
|
].includes(e);
|
|
758
883
|
}
|
|
759
884
|
}
|
|
760
|
-
class
|
|
885
|
+
class _t {
|
|
761
886
|
/**
|
|
762
887
|
* Generates fingerprint for SVG element
|
|
763
888
|
* @param element - SVG element to fingerprint
|
|
@@ -772,10 +897,10 @@ class Tt {
|
|
|
772
897
|
const o = t.getAttribute("d");
|
|
773
898
|
o && (r.dHash = this.computePathHash(o));
|
|
774
899
|
} else ["circle", "rect", "ellipse", "line"].includes(s) && (r.geomHash = this.computeGeomHash(t, s));
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
return
|
|
900
|
+
const a = t.getAttribute("role");
|
|
901
|
+
a && (r.role = a);
|
|
902
|
+
const i = t.querySelector("title");
|
|
903
|
+
return i?.textContent && (r.titleText = i.textContent.trim()), r;
|
|
779
904
|
}
|
|
780
905
|
/**
|
|
781
906
|
* Computes hash from path data (first N commands)
|
|
@@ -808,7 +933,7 @@ class Tt {
|
|
|
808
933
|
* Normalizes path data for consistent hashing
|
|
809
934
|
*/
|
|
810
935
|
normalizePathData(t) {
|
|
811
|
-
return (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((r) => r.trim().replace(/(-?\d+\.?\d*)/g, (
|
|
936
|
+
return (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((r) => r.trim().replace(/(-?\d+\.?\d*)/g, (a) => parseFloat(a).toFixed(1))).join(" ");
|
|
812
937
|
}
|
|
813
938
|
/**
|
|
814
939
|
* Computes geometry hash for non-path shapes
|
|
@@ -821,19 +946,19 @@ class Tt {
|
|
|
821
946
|
break;
|
|
822
947
|
case "rect":
|
|
823
948
|
{
|
|
824
|
-
const r = parseFloat(t.getAttribute("width") ?? "0"),
|
|
825
|
-
r > 0 &&
|
|
949
|
+
const r = parseFloat(t.getAttribute("width") ?? "0"), a = parseFloat(t.getAttribute("height") ?? "0");
|
|
950
|
+
r > 0 && a > 0 && s.push(`ratio=${(r / a).toFixed(2)}`);
|
|
826
951
|
}
|
|
827
952
|
break;
|
|
828
953
|
case "ellipse":
|
|
829
954
|
{
|
|
830
|
-
const r = parseFloat(t.getAttribute("rx") ?? "0"),
|
|
831
|
-
r > 0 &&
|
|
955
|
+
const r = parseFloat(t.getAttribute("rx") ?? "0"), a = parseFloat(t.getAttribute("ry") ?? "0");
|
|
956
|
+
r > 0 && a > 0 && s.push(`ratio=${(r / a).toFixed(2)}`);
|
|
832
957
|
}
|
|
833
958
|
break;
|
|
834
959
|
case "line":
|
|
835
960
|
{
|
|
836
|
-
const r = parseFloat(t.getAttribute("x1") ?? "0"),
|
|
961
|
+
const r = parseFloat(t.getAttribute("x1") ?? "0"), a = parseFloat(t.getAttribute("y1") ?? "0"), i = parseFloat(t.getAttribute("x2") ?? "0"), o = parseFloat(t.getAttribute("y2") ?? "0"), l = Math.atan2(o - a, i - r);
|
|
837
962
|
s.push(`angle=${l.toFixed(2)}`);
|
|
838
963
|
}
|
|
839
964
|
break;
|
|
@@ -868,15 +993,15 @@ class Tt {
|
|
|
868
993
|
return Math.abs(e).toString(16).padStart(8, "0");
|
|
869
994
|
}
|
|
870
995
|
}
|
|
871
|
-
function
|
|
872
|
-
const e = n.anchor.score, s = n.path.length > 0 ? n.path.reduce((o, l) => o + l.score, 0) / n.path.length : 0.5, r = n.target.score,
|
|
873
|
-
return Math.max(0, Math.min(1,
|
|
996
|
+
function kt(n, t = 0) {
|
|
997
|
+
const e = n.anchor.score, s = n.path.length > 0 ? n.path.reduce((o, l) => o + l.score, 0) / n.path.length : 0.5, r = n.target.score, a = e * L.ANCHOR + s * L.PATH + r * L.TARGET + t * L.UNIQUENESS, i = n.anchor.degraded ? 0.2 : 0;
|
|
998
|
+
return Math.max(0, Math.min(1, a - i));
|
|
874
999
|
}
|
|
875
|
-
function
|
|
1000
|
+
function ae(n, t, e) {
|
|
876
1001
|
let s = 0.5;
|
|
877
1002
|
return t && (s += 0.2), e && (s += 0.15), s += Math.min(n * 0.05, 0.15), Math.min(s, 1);
|
|
878
1003
|
}
|
|
879
|
-
class
|
|
1004
|
+
class qt {
|
|
880
1005
|
constructor(t) {
|
|
881
1006
|
this.cache = /* @__PURE__ */ new Map(), this.maxSize = t;
|
|
882
1007
|
}
|
|
@@ -907,9 +1032,9 @@ class vt {
|
|
|
907
1032
|
return this.cache.size;
|
|
908
1033
|
}
|
|
909
1034
|
}
|
|
910
|
-
class
|
|
1035
|
+
class Lt {
|
|
911
1036
|
constructor(t = {}) {
|
|
912
|
-
this.eidCache = /* @__PURE__ */ new WeakMap(), this.selectorResultCache = new
|
|
1037
|
+
this.eidCache = /* @__PURE__ */ new WeakMap(), this.selectorResultCache = new qt(
|
|
913
1038
|
t.maxSelectorCacheSize ?? 1e3
|
|
914
1039
|
), this.anchorCache = /* @__PURE__ */ new WeakMap(), this.semanticsCache = /* @__PURE__ */ new WeakMap(), this.stats = {
|
|
915
1040
|
eidHits: 0,
|
|
@@ -1058,76 +1183,83 @@ class $t {
|
|
|
1058
1183
|
return s > 0 ? t / s : 0;
|
|
1059
1184
|
}
|
|
1060
1185
|
}
|
|
1061
|
-
function
|
|
1062
|
-
return new
|
|
1186
|
+
function Ot(n) {
|
|
1187
|
+
return new Lt(n);
|
|
1063
1188
|
}
|
|
1064
|
-
let
|
|
1065
|
-
function
|
|
1066
|
-
return
|
|
1189
|
+
let O = null;
|
|
1190
|
+
function Q() {
|
|
1191
|
+
return O || (O = Ot()), O;
|
|
1067
1192
|
}
|
|
1068
|
-
function
|
|
1069
|
-
|
|
1193
|
+
function ie() {
|
|
1194
|
+
O = null;
|
|
1070
1195
|
}
|
|
1071
|
-
function
|
|
1196
|
+
function Z(n, t = {}) {
|
|
1072
1197
|
if (!n || !n.ownerDocument || !n.isConnected)
|
|
1073
1198
|
return null;
|
|
1074
|
-
const e = { ...
|
|
1199
|
+
const e = { ...ut, ...t }, s = e.cache ?? Q(), r = s.getEID(n);
|
|
1075
1200
|
if (r !== void 0)
|
|
1076
1201
|
return r;
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
1202
|
+
const a = new ft(e, s), i = new xt(e, s), o = new Pt(e, s), l = new _t(), u = a.findAnchor(n);
|
|
1203
|
+
if (!u && !e.fallbackToBody)
|
|
1079
1204
|
return null;
|
|
1080
|
-
const
|
|
1081
|
-
if (!
|
|
1082
|
-
const
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1205
|
+
const d = u?.element ?? n.ownerDocument?.body ?? null;
|
|
1206
|
+
if (!d) return null;
|
|
1207
|
+
const c = !u || u.tier === "C", h = d.tagName.toLowerCase(), g = d.parentElement;
|
|
1208
|
+
let f;
|
|
1209
|
+
if (g && h !== "body" && h !== "html") {
|
|
1210
|
+
const T = Array.from(g.children).indexOf(d);
|
|
1211
|
+
T !== -1 && (f = T + 1);
|
|
1212
|
+
}
|
|
1213
|
+
const p = o.extract(d), m = {
|
|
1214
|
+
tag: d.tagName.toLowerCase(),
|
|
1215
|
+
semantics: p,
|
|
1216
|
+
score: u?.score ?? I.DEGRADED_SCORE,
|
|
1217
|
+
degraded: c,
|
|
1218
|
+
nthChild: f
|
|
1219
|
+
}, b = i.buildPath(
|
|
1220
|
+
d,
|
|
1089
1221
|
n,
|
|
1090
1222
|
o
|
|
1091
|
-
),
|
|
1092
|
-
e.enableSvgFingerprint &&
|
|
1093
|
-
const
|
|
1094
|
-
let
|
|
1095
|
-
if (
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
}
|
|
1099
|
-
const
|
|
1223
|
+
), y = o.extract(n);
|
|
1224
|
+
e.enableSvgFingerprint && zt(n) && (y.svg = l.fingerprint(n));
|
|
1225
|
+
const v = n.parentElement;
|
|
1226
|
+
let A;
|
|
1227
|
+
if (v) {
|
|
1228
|
+
const T = Array.from(v.children).indexOf(n);
|
|
1229
|
+
T !== -1 && (A = T + 1);
|
|
1230
|
+
}
|
|
1231
|
+
const S = {
|
|
1100
1232
|
tag: n.tagName.toLowerCase(),
|
|
1101
|
-
semantics:
|
|
1233
|
+
semantics: y,
|
|
1102
1234
|
score: o.scoreElement(n),
|
|
1103
|
-
nthChild:
|
|
1104
|
-
},
|
|
1235
|
+
nthChild: A
|
|
1236
|
+
}, $ = [], M = {
|
|
1105
1237
|
onMultiple: "best-score",
|
|
1106
1238
|
onMissing: "anchor-only",
|
|
1107
1239
|
maxDepth: 3
|
|
1108
|
-
},
|
|
1240
|
+
}, H = m.degraded || b.degraded, E = Ut(m.degraded, b), C = {
|
|
1109
1241
|
version: "1.0",
|
|
1110
|
-
anchor:
|
|
1111
|
-
path:
|
|
1112
|
-
target:
|
|
1113
|
-
constraints:
|
|
1114
|
-
fallback:
|
|
1242
|
+
anchor: m,
|
|
1243
|
+
path: b.path,
|
|
1244
|
+
target: S,
|
|
1245
|
+
constraints: $,
|
|
1246
|
+
fallback: M,
|
|
1115
1247
|
meta: {
|
|
1116
1248
|
confidence: 0,
|
|
1117
1249
|
// Calculated below
|
|
1118
1250
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1119
1251
|
generator: "dom-eid@1.0",
|
|
1120
1252
|
source: e.source,
|
|
1121
|
-
degraded:
|
|
1122
|
-
degradationReason:
|
|
1253
|
+
degraded: H,
|
|
1254
|
+
degradationReason: E
|
|
1123
1255
|
}
|
|
1124
1256
|
};
|
|
1125
|
-
return
|
|
1257
|
+
return C.meta.confidence = kt(C), C.meta.confidence < e.confidenceThreshold ? null : (s.setEID(n, C), C);
|
|
1126
1258
|
}
|
|
1127
|
-
function
|
|
1259
|
+
function zt(n) {
|
|
1128
1260
|
return n.namespaceURI === "http://www.w3.org/2000/svg" || n.tagName.toLowerCase() === "svg" || n instanceof SVGElement;
|
|
1129
1261
|
}
|
|
1130
|
-
function
|
|
1262
|
+
function Ut(n, t) {
|
|
1131
1263
|
if (n && t.degraded)
|
|
1132
1264
|
return "anchor-and-path-degraded";
|
|
1133
1265
|
if (n)
|
|
@@ -1135,67 +1267,67 @@ function Nt(n, t) {
|
|
|
1135
1267
|
if (t.degraded)
|
|
1136
1268
|
return t.degradationReason;
|
|
1137
1269
|
}
|
|
1138
|
-
class
|
|
1270
|
+
class st {
|
|
1139
1271
|
buildSelector(t, e) {
|
|
1140
1272
|
if (t.path.length === 0 && t.anchor.tag === t.target.tag && JSON.stringify(t.anchor.semantics) === JSON.stringify(t.target.semantics)) {
|
|
1141
|
-
const
|
|
1273
|
+
const c = this.buildNodeSelector(
|
|
1142
1274
|
t.target.tag,
|
|
1143
1275
|
t.target.semantics,
|
|
1144
1276
|
{ excludeClasses: !1 }
|
|
1145
1277
|
// Include classes for same-element case
|
|
1146
1278
|
);
|
|
1147
|
-
return e?.ensureUnique ? this.ensureUniqueSelector(
|
|
1279
|
+
return e?.ensureUnique ? this.ensureUniqueSelector(c, t, e) : c;
|
|
1148
1280
|
}
|
|
1149
|
-
const r = [],
|
|
1150
|
-
r.push(
|
|
1151
|
-
for (const
|
|
1152
|
-
let
|
|
1153
|
-
|
|
1281
|
+
const r = [], a = e?.ensureUnique ? this.ensureUniqueAnchor(t, e.root ?? document) : this.buildNodeSelector(t.anchor.tag, t.anchor.semantics);
|
|
1282
|
+
r.push(a);
|
|
1283
|
+
for (const c of t.path) {
|
|
1284
|
+
let h = this.buildNodeSelector(c.tag, c.semantics);
|
|
1285
|
+
c.nthChild !== void 0 && (["tr", "td", "th", "thead", "tbody", "tfoot"].includes(c.tag) ? h += `:nth-child(${c.nthChild})` : h += `:nth-child(${c.nthChild})`), r.push(h);
|
|
1154
1286
|
}
|
|
1155
|
-
let
|
|
1287
|
+
let i = this.buildNodeSelector(
|
|
1156
1288
|
t.target.tag,
|
|
1157
1289
|
t.target.semantics,
|
|
1158
1290
|
{ excludeClasses: e?.ensureUnique }
|
|
1159
1291
|
// Exclude classes initially if we need unique
|
|
1160
1292
|
);
|
|
1161
|
-
t.target.nthChild !== void 0 && (["tr", "td", "th", "thead", "tbody", "tfoot"].includes(t.target.tag) ?
|
|
1162
|
-
const o = this.isSvgChildElement(t.target.tag), l = t.path.some((
|
|
1163
|
-
let
|
|
1293
|
+
t.target.nthChild !== void 0 && (["tr", "td", "th", "thead", "tbody", "tfoot"].includes(t.target.tag) ? i += `:nth-child(${t.target.nthChild})` : i += `:nth-child(${t.target.nthChild})`), r.push(i);
|
|
1294
|
+
const o = this.isSvgChildElement(t.target.tag), l = t.path.some((c) => c.tag === "svg");
|
|
1295
|
+
let u;
|
|
1164
1296
|
if (o && l) {
|
|
1165
|
-
const
|
|
1166
|
-
if (
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1297
|
+
const c = t.path.findIndex((h) => h.tag === "svg");
|
|
1298
|
+
if (c !== -1) {
|
|
1299
|
+
const h = c + 1, g = r.slice(0, h + 1), f = r.slice(h + 1, -1), p = r[r.length - 1];
|
|
1300
|
+
f.length > 0 ? u = g.join(" ") + " > " + f.join(" > ") + " > " + p : u = g.join(" ") + " > " + p;
|
|
1169
1301
|
} else
|
|
1170
|
-
|
|
1302
|
+
u = r.join(" ");
|
|
1171
1303
|
} else
|
|
1172
|
-
|
|
1304
|
+
u = r.join(" ");
|
|
1173
1305
|
if (!e?.ensureUnique)
|
|
1174
|
-
return
|
|
1175
|
-
const
|
|
1176
|
-
if (
|
|
1306
|
+
return u;
|
|
1307
|
+
const d = this.querySelectorSafe(u, e.root ?? document);
|
|
1308
|
+
if (d.length === 1)
|
|
1177
1309
|
return {
|
|
1178
|
-
selector:
|
|
1310
|
+
selector: u,
|
|
1179
1311
|
isUnique: !0,
|
|
1180
|
-
usedNthOfType:
|
|
1312
|
+
usedNthOfType: u.includes(":nth-"),
|
|
1181
1313
|
extraClassesAdded: 0
|
|
1182
1314
|
};
|
|
1183
|
-
if (
|
|
1184
|
-
const
|
|
1315
|
+
if (d.length === 0 || d.length > 1) {
|
|
1316
|
+
const c = this.buildFullDomPathSelector(
|
|
1185
1317
|
t,
|
|
1186
1318
|
t.target.semantics,
|
|
1187
1319
|
e.root ?? document
|
|
1188
1320
|
);
|
|
1189
|
-
if (
|
|
1321
|
+
if (c && this.isUnique(c, e.root ?? document))
|
|
1190
1322
|
return {
|
|
1191
|
-
selector:
|
|
1323
|
+
selector: c,
|
|
1192
1324
|
isUnique: !0,
|
|
1193
|
-
usedNthOfType:
|
|
1325
|
+
usedNthOfType: c.includes(":nth-"),
|
|
1194
1326
|
extraClassesAdded: 0
|
|
1195
1327
|
};
|
|
1196
1328
|
}
|
|
1197
1329
|
return this.ensureUniqueSelector(
|
|
1198
|
-
|
|
1330
|
+
u,
|
|
1199
1331
|
t,
|
|
1200
1332
|
e
|
|
1201
1333
|
);
|
|
@@ -1212,11 +1344,11 @@ class tt {
|
|
|
1212
1344
|
* Ensures selector uniqueness by progressively adding classes and nth-of-type
|
|
1213
1345
|
*/
|
|
1214
1346
|
ensureUniqueSelector(t, e, s) {
|
|
1215
|
-
const r = s.root ?? document,
|
|
1216
|
-
let l = t,
|
|
1347
|
+
const r = s.root ?? document, a = s.maxClasses ?? 4, i = e.target.tag, o = e.target.semantics;
|
|
1348
|
+
let l = t, u = 0, d = !1;
|
|
1217
1349
|
if (this.querySelectorSafe(l, r).length === 0) {
|
|
1218
|
-
const
|
|
1219
|
-
if (
|
|
1350
|
+
const f = this.buildFullDomPathSelector(e, o, r);
|
|
1351
|
+
if (f && (l = f, this.isUnique(l, r)))
|
|
1220
1352
|
return {
|
|
1221
1353
|
selector: l,
|
|
1222
1354
|
isUnique: !0,
|
|
@@ -1231,33 +1363,33 @@ class tt {
|
|
|
1231
1363
|
usedNthOfType: !1,
|
|
1232
1364
|
extraClassesAdded: 0
|
|
1233
1365
|
};
|
|
1234
|
-
const
|
|
1235
|
-
for (let
|
|
1236
|
-
const
|
|
1237
|
-
if (l += `.${this.escapeCSS(
|
|
1366
|
+
const h = N(o.classes ?? []);
|
|
1367
|
+
for (let f = 0; f < Math.min(h.length, a); f++) {
|
|
1368
|
+
const p = h[f];
|
|
1369
|
+
if (l += `.${this.escapeCSS(p)}`, u++, this.isUnique(l, r))
|
|
1238
1370
|
return {
|
|
1239
1371
|
selector: l,
|
|
1240
1372
|
isUnique: !0,
|
|
1241
1373
|
usedNthOfType: !1,
|
|
1242
|
-
extraClassesAdded:
|
|
1374
|
+
extraClassesAdded: u
|
|
1243
1375
|
};
|
|
1244
1376
|
}
|
|
1245
1377
|
if (!this.isUnique(l, r)) {
|
|
1246
|
-
const
|
|
1247
|
-
if (
|
|
1378
|
+
const f = this.buildFullDomPathSelector(e, o, r);
|
|
1379
|
+
if (f && this.isUnique(f, r))
|
|
1248
1380
|
return {
|
|
1249
|
-
selector:
|
|
1381
|
+
selector: f,
|
|
1250
1382
|
isUnique: !0,
|
|
1251
|
-
usedNthOfType:
|
|
1252
|
-
extraClassesAdded:
|
|
1383
|
+
usedNthOfType: f.includes(":nth-of-type("),
|
|
1384
|
+
extraClassesAdded: u
|
|
1253
1385
|
};
|
|
1254
1386
|
}
|
|
1255
1387
|
const g = this.findNthElementByText(l, o, r);
|
|
1256
|
-
return g && (l += this.getNthSelector(g,
|
|
1388
|
+
return g && (l += this.getNthSelector(g, i), d = !0), {
|
|
1257
1389
|
selector: l,
|
|
1258
1390
|
isUnique: this.isUnique(l, r),
|
|
1259
|
-
usedNthOfType:
|
|
1260
|
-
extraClassesAdded:
|
|
1391
|
+
usedNthOfType: d,
|
|
1392
|
+
extraClassesAdded: u
|
|
1261
1393
|
};
|
|
1262
1394
|
}
|
|
1263
1395
|
/**
|
|
@@ -1265,29 +1397,29 @@ class tt {
|
|
|
1265
1397
|
* This handles cases where intermediate div/span elements were filtered out
|
|
1266
1398
|
*/
|
|
1267
1399
|
buildFullDomPathSelector(t, e, s) {
|
|
1268
|
-
const r = this.buildNodeSelector(t.anchor.tag, t.anchor.semantics),
|
|
1269
|
-
if (
|
|
1270
|
-
for (const
|
|
1400
|
+
const r = this.buildNodeSelector(t.anchor.tag, t.anchor.semantics), a = this.querySelectorSafe(r, s);
|
|
1401
|
+
if (a.length === 0) return null;
|
|
1402
|
+
for (const i of a) {
|
|
1271
1403
|
const o = this.findTargetWithinAnchor(
|
|
1272
|
-
|
|
1404
|
+
i,
|
|
1273
1405
|
t.target.tag,
|
|
1274
1406
|
e
|
|
1275
1407
|
);
|
|
1276
1408
|
if (o.length === 0) continue;
|
|
1277
|
-
const l = o.map((
|
|
1278
|
-
const
|
|
1279
|
-
return { element:
|
|
1409
|
+
const l = o.map((u) => {
|
|
1410
|
+
const d = this.scorePathMatch(u, i, t.path);
|
|
1411
|
+
return { element: u, score: d };
|
|
1280
1412
|
});
|
|
1281
|
-
l.sort((
|
|
1282
|
-
for (const { element:
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
|
|
1413
|
+
l.sort((u, d) => d.score - u.score);
|
|
1414
|
+
for (const { element: u } of l) {
|
|
1415
|
+
const d = this.buildPathFromAnchorToTarget(
|
|
1416
|
+
i,
|
|
1417
|
+
u,
|
|
1286
1418
|
t,
|
|
1287
1419
|
s
|
|
1288
1420
|
);
|
|
1289
|
-
if (
|
|
1290
|
-
return
|
|
1421
|
+
if (d && this.isUnique(d, s))
|
|
1422
|
+
return d;
|
|
1291
1423
|
}
|
|
1292
1424
|
}
|
|
1293
1425
|
return null;
|
|
@@ -1302,52 +1434,52 @@ class tt {
|
|
|
1302
1434
|
*/
|
|
1303
1435
|
scorePathMatch(t, e, s) {
|
|
1304
1436
|
const r = [];
|
|
1305
|
-
let
|
|
1306
|
-
for (;
|
|
1307
|
-
r.unshift(
|
|
1308
|
-
let
|
|
1437
|
+
let a = t.parentElement;
|
|
1438
|
+
for (; a && a !== e; )
|
|
1439
|
+
r.unshift(a), a = a.parentElement;
|
|
1440
|
+
let i = 0;
|
|
1309
1441
|
const o = Math.min(r.length, s.length);
|
|
1310
|
-
for (let
|
|
1311
|
-
const
|
|
1312
|
-
if (
|
|
1313
|
-
if (
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1442
|
+
for (let u = 0; u < o; u++) {
|
|
1443
|
+
const d = r[u], c = s[u];
|
|
1444
|
+
if (d.tagName.toLowerCase() === c.tag) {
|
|
1445
|
+
if (i += 10, c.nthChild !== void 0) {
|
|
1446
|
+
const h = d.parentElement;
|
|
1447
|
+
h && (Array.from(h.children).indexOf(d) + 1 === c.nthChild ? i += 20 : i -= 10);
|
|
1316
1448
|
}
|
|
1317
1449
|
} else
|
|
1318
|
-
|
|
1319
|
-
if (
|
|
1320
|
-
const
|
|
1321
|
-
(g) =>
|
|
1450
|
+
i -= 5;
|
|
1451
|
+
if (c.semantics.classes && c.semantics.classes.length > 0) {
|
|
1452
|
+
const h = c.semantics.classes.filter(
|
|
1453
|
+
(g) => d.classList.contains(g)
|
|
1322
1454
|
);
|
|
1323
|
-
|
|
1455
|
+
i += h.length * 2;
|
|
1324
1456
|
}
|
|
1325
|
-
if (
|
|
1326
|
-
const
|
|
1327
|
-
([g,
|
|
1457
|
+
if (c.semantics.attributes) {
|
|
1458
|
+
const h = Object.entries(c.semantics.attributes).filter(
|
|
1459
|
+
([g, f]) => d.getAttribute(g) === f
|
|
1328
1460
|
);
|
|
1329
|
-
|
|
1461
|
+
i += h.length * 3;
|
|
1330
1462
|
}
|
|
1331
1463
|
}
|
|
1332
1464
|
const l = Math.abs(r.length - s.length);
|
|
1333
|
-
return
|
|
1465
|
+
return i -= l * 2, i;
|
|
1334
1466
|
}
|
|
1335
1467
|
/**
|
|
1336
1468
|
* Finds target elements within an anchor by matching semantics
|
|
1337
1469
|
*/
|
|
1338
1470
|
findTargetWithinAnchor(t, e, s) {
|
|
1339
|
-
return Array.from(t.querySelectorAll(e)).filter((
|
|
1471
|
+
return Array.from(t.querySelectorAll(e)).filter((a) => {
|
|
1340
1472
|
if (s.text) {
|
|
1341
|
-
const
|
|
1342
|
-
if (!
|
|
1473
|
+
const i = a.textContent?.trim() || "", o = s.text.normalized;
|
|
1474
|
+
if (!i.includes(o) && !o.includes(i))
|
|
1343
1475
|
return !1;
|
|
1344
1476
|
}
|
|
1345
1477
|
return !!(s.classes && s.classes.length > 0 && s.classes.every(
|
|
1346
|
-
(o) =>
|
|
1478
|
+
(o) => a.classList.contains(o)
|
|
1347
1479
|
) || s.attributes && Object.entries(s.attributes).every(
|
|
1348
1480
|
([o, l]) => {
|
|
1349
|
-
const
|
|
1350
|
-
return o === "href" || o === "src" ?
|
|
1481
|
+
const u = a.getAttribute(o);
|
|
1482
|
+
return o === "href" || o === "src" ? _(o, u || "") === _(o, l) : u === l;
|
|
1351
1483
|
}
|
|
1352
1484
|
) || s.text);
|
|
1353
1485
|
});
|
|
@@ -1362,24 +1494,24 @@ class tt {
|
|
|
1362
1494
|
* @param root Root element for queries
|
|
1363
1495
|
* @returns Disambiguated selector part (e.g., "div[role='main']" or "div.sidebar" or "div:nth-of-type(3)")
|
|
1364
1496
|
*/
|
|
1365
|
-
disambiguateParent(t, e, s, r,
|
|
1497
|
+
disambiguateParent(t, e, s, r, a) {
|
|
1366
1498
|
if (s?.semantics?.attributes) {
|
|
1367
1499
|
const o = this.buildNodeSelector(e, s.semantics, {
|
|
1368
1500
|
excludeClasses: !0
|
|
1369
|
-
}), l = [...r, e].join(" > "),
|
|
1370
|
-
if (
|
|
1501
|
+
}), l = [...r, e].join(" > "), u = this.querySelectorSafe(l, a), d = [...r, o].join(" > "), c = this.querySelectorSafe(d, a);
|
|
1502
|
+
if (c.length > 0 && c.length < u.length)
|
|
1371
1503
|
return o;
|
|
1372
1504
|
}
|
|
1373
1505
|
if (s?.semantics?.classes) {
|
|
1374
|
-
const o =
|
|
1506
|
+
const o = N(s.semantics.classes);
|
|
1375
1507
|
if (o.length > 0) {
|
|
1376
|
-
const l = `${e}.${this.escapeCSS(o[0])}`,
|
|
1377
|
-
if (
|
|
1508
|
+
const l = `${e}.${this.escapeCSS(o[0])}`, u = [...r, e].join(" > "), d = this.querySelectorSafe(u, a), c = [...r, l].join(" > "), h = this.querySelectorSafe(c, a);
|
|
1509
|
+
if (h.length > 0 && h.length < d.length)
|
|
1378
1510
|
return l;
|
|
1379
1511
|
}
|
|
1380
1512
|
}
|
|
1381
|
-
const
|
|
1382
|
-
return
|
|
1513
|
+
const i = t.parentElement;
|
|
1514
|
+
return i && Array.from(i.children).filter(
|
|
1383
1515
|
(l) => l.tagName.toLowerCase() === e
|
|
1384
1516
|
).length > 1 ? `${e}${this.getNthSelector(t, e)}` : e;
|
|
1385
1517
|
}
|
|
@@ -1387,11 +1519,11 @@ class tt {
|
|
|
1387
1519
|
* Builds CSS selector path from anchor to target by traversing actual DOM
|
|
1388
1520
|
*/
|
|
1389
1521
|
buildPathFromAnchorToTarget(t, e, s, r) {
|
|
1390
|
-
const
|
|
1391
|
-
let
|
|
1392
|
-
for (;
|
|
1393
|
-
|
|
1394
|
-
if (
|
|
1522
|
+
const a = [];
|
|
1523
|
+
let i = e;
|
|
1524
|
+
for (; i && i !== t; )
|
|
1525
|
+
a.unshift(i), i = i.parentElement;
|
|
1526
|
+
if (i !== t)
|
|
1395
1527
|
return null;
|
|
1396
1528
|
const o = [
|
|
1397
1529
|
// ============================================================
|
|
@@ -1399,17 +1531,17 @@ class tt {
|
|
|
1399
1531
|
// Most flexible - no classes on target, only semantic attributes
|
|
1400
1532
|
// ============================================================
|
|
1401
1533
|
() => {
|
|
1402
|
-
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics),
|
|
1403
|
-
for (const
|
|
1404
|
-
|
|
1405
|
-
const g = [l, ...
|
|
1534
|
+
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), u = s.target.tag, d = s.target.semantics, c = [];
|
|
1535
|
+
for (const m of s.path)
|
|
1536
|
+
c.push(m.tag);
|
|
1537
|
+
const g = [l, ...c, u].filter(Boolean).join(" ");
|
|
1406
1538
|
if (this.isUnique(g, r))
|
|
1407
1539
|
return g;
|
|
1408
|
-
const
|
|
1540
|
+
const f = this.buildNodeSelector(u, d, {
|
|
1409
1541
|
excludeClasses: !0
|
|
1410
1542
|
// KEY: no classes on target in Strategy 0
|
|
1411
|
-
}),
|
|
1412
|
-
return this.isUnique(
|
|
1543
|
+
}), p = [l, ...c.slice(0, -1), f].join(" ");
|
|
1544
|
+
return this.isUnique(p, r) ? p : null;
|
|
1413
1545
|
},
|
|
1414
1546
|
// ============================================================
|
|
1415
1547
|
// Strategy 1: anchor > parent[attrs|class|nth] > target[attrs_only]
|
|
@@ -1418,31 +1550,31 @@ class tt {
|
|
|
1418
1550
|
// Target: ONLY attributes, NO classes
|
|
1419
1551
|
// ============================================================
|
|
1420
1552
|
() => {
|
|
1421
|
-
const l = [this.buildNodeSelector(s.anchor.tag, s.anchor.semantics)],
|
|
1422
|
-
let
|
|
1423
|
-
for (let
|
|
1424
|
-
const g =
|
|
1425
|
-
|
|
1553
|
+
const l = [this.buildNodeSelector(s.anchor.tag, s.anchor.semantics)], u = /* @__PURE__ */ new Map();
|
|
1554
|
+
let d = 0;
|
|
1555
|
+
for (let h = 0; h < a.length - 1; h++) {
|
|
1556
|
+
const g = a[h], f = g.tagName.toLowerCase();
|
|
1557
|
+
d < s.path.length && s.path[d].tag === f ? (u.set(g, s.path[d]), d++) : u.set(g, null);
|
|
1426
1558
|
}
|
|
1427
|
-
for (let
|
|
1428
|
-
const g =
|
|
1429
|
-
if (
|
|
1430
|
-
const
|
|
1559
|
+
for (let h = 0; h < a.length; h++) {
|
|
1560
|
+
const g = a[h], f = g.tagName.toLowerCase();
|
|
1561
|
+
if (h < a.length - 1) {
|
|
1562
|
+
const b = u.get(g) || null, y = this.disambiguateParent(g, f, b, l, r);
|
|
1431
1563
|
l.push(y);
|
|
1432
1564
|
continue;
|
|
1433
1565
|
}
|
|
1434
|
-
const
|
|
1566
|
+
const p = this.buildNodeSelector(
|
|
1435
1567
|
s.target.tag,
|
|
1436
1568
|
s.target.semantics,
|
|
1437
1569
|
{ excludeClasses: !0 }
|
|
1438
1570
|
// KEY: no classes on target
|
|
1439
|
-
),
|
|
1440
|
-
|
|
1441
|
-
(y) => y.tagName.toLowerCase() ===
|
|
1442
|
-
).length > 1 ? l.push(`${
|
|
1571
|
+
), m = g.parentElement;
|
|
1572
|
+
m && ["td", "th", "tr", "thead", "tbody", "tfoot"].includes(f) && Array.from(m.children).filter(
|
|
1573
|
+
(y) => y.tagName.toLowerCase() === f
|
|
1574
|
+
).length > 1 ? l.push(`${p}${this.getNthSelector(g, f)}`) : l.push(p);
|
|
1443
1575
|
}
|
|
1444
|
-
const
|
|
1445
|
-
return this.isUnique(
|
|
1576
|
+
const c = l.join(" > ");
|
|
1577
|
+
return this.isUnique(c, r) ? c : null;
|
|
1446
1578
|
},
|
|
1447
1579
|
// ============================================================
|
|
1448
1580
|
// Strategy 2: anchor parent[attrs|class|nth] target[attrs_only]
|
|
@@ -1451,48 +1583,48 @@ class tt {
|
|
|
1451
1583
|
// Target: ONLY attributes, NO classes
|
|
1452
1584
|
// ============================================================
|
|
1453
1585
|
() => {
|
|
1454
|
-
const
|
|
1455
|
-
for (let
|
|
1456
|
-
const
|
|
1457
|
-
if (this.querySelectorSafe(
|
|
1458
|
-
if (
|
|
1459
|
-
const A = this.buildNodeSelector(
|
|
1586
|
+
const u = [this.buildNodeSelector(s.anchor.tag, s.anchor.semantics)];
|
|
1587
|
+
for (let h = 0; h < a.length - 1; h++) {
|
|
1588
|
+
const f = a[h].tagName.toLowerCase(), p = s.path[h] || null, m = u.join(" ") + " " + f;
|
|
1589
|
+
if (this.querySelectorSafe(m, r).length > 1) {
|
|
1590
|
+
if (p?.semantics?.attributes) {
|
|
1591
|
+
const A = this.buildNodeSelector(f, p.semantics, {
|
|
1460
1592
|
excludeClasses: !0
|
|
1461
|
-
}),
|
|
1462
|
-
if (this.querySelectorSafe(
|
|
1463
|
-
|
|
1593
|
+
}), S = u.join(" ") + " " + A;
|
|
1594
|
+
if (this.querySelectorSafe(S, r).length === 1 || this.querySelectorSafe(S + " " + s.target.tag, r).length === 1) {
|
|
1595
|
+
u.push(A);
|
|
1464
1596
|
continue;
|
|
1465
1597
|
}
|
|
1466
1598
|
}
|
|
1467
|
-
if (
|
|
1468
|
-
const A =
|
|
1599
|
+
if (p?.semantics?.classes) {
|
|
1600
|
+
const A = N(p.semantics.classes);
|
|
1469
1601
|
if (A.length > 0) {
|
|
1470
|
-
const
|
|
1471
|
-
if (this.querySelectorSafe(
|
|
1472
|
-
|
|
1602
|
+
const S = `${f}.${this.escapeCSS(A[0])}`, $ = u.join(" ") + " " + S;
|
|
1603
|
+
if (this.querySelectorSafe($, r).length === 1 || this.querySelectorSafe($ + " " + s.target.tag, r).length === 1) {
|
|
1604
|
+
u.push(S);
|
|
1473
1605
|
continue;
|
|
1474
1606
|
}
|
|
1475
1607
|
}
|
|
1476
1608
|
}
|
|
1477
|
-
const y =
|
|
1478
|
-
if (
|
|
1479
|
-
(
|
|
1609
|
+
const y = a[h], v = y.parentElement;
|
|
1610
|
+
if (v && Array.from(v.children).filter(
|
|
1611
|
+
(S) => S.tagName.toLowerCase() === f
|
|
1480
1612
|
).length > 1) {
|
|
1481
|
-
|
|
1613
|
+
u.push(`${f}${this.getNthSelector(y, f)}`);
|
|
1482
1614
|
continue;
|
|
1483
1615
|
}
|
|
1484
1616
|
}
|
|
1485
|
-
|
|
1617
|
+
u.push(f);
|
|
1486
1618
|
}
|
|
1487
|
-
const
|
|
1619
|
+
const d = this.buildNodeSelector(
|
|
1488
1620
|
s.target.tag,
|
|
1489
1621
|
s.target.semantics,
|
|
1490
1622
|
{ excludeClasses: !0 }
|
|
1491
1623
|
// KEY: no classes on target
|
|
1492
1624
|
);
|
|
1493
|
-
|
|
1494
|
-
const
|
|
1495
|
-
return this.isUnique(
|
|
1625
|
+
u.push(d);
|
|
1626
|
+
const c = u.join(" ");
|
|
1627
|
+
return this.isUnique(c, r) ? c : null;
|
|
1496
1628
|
},
|
|
1497
1629
|
// ============================================================
|
|
1498
1630
|
// Strategy 3: anchor path target[attrs + 1_stable_class]
|
|
@@ -1500,18 +1632,18 @@ class tt {
|
|
|
1500
1632
|
// Only use this if attrs alone are not sufficient
|
|
1501
1633
|
// ============================================================
|
|
1502
1634
|
() => {
|
|
1503
|
-
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics),
|
|
1635
|
+
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), u = [];
|
|
1504
1636
|
for (const g of s.path)
|
|
1505
|
-
|
|
1506
|
-
if (
|
|
1637
|
+
u.push(g.tag);
|
|
1638
|
+
if (N(s.target.semantics.classes ?? []).length === 0)
|
|
1507
1639
|
return null;
|
|
1508
|
-
const
|
|
1640
|
+
const c = this.buildNodeSelector(
|
|
1509
1641
|
s.target.tag,
|
|
1510
1642
|
s.target.semantics,
|
|
1511
1643
|
{ maxClasses: 1 }
|
|
1512
1644
|
// KEY: ONE stable class only
|
|
1513
|
-
),
|
|
1514
|
-
return this.isUnique(
|
|
1645
|
+
), h = [l, ...u.slice(0, -1), c].join(" ");
|
|
1646
|
+
return this.isUnique(h, r) ? h : null;
|
|
1515
1647
|
},
|
|
1516
1648
|
// ============================================================
|
|
1517
1649
|
// Strategy 4: anchor path target[attrs]:nth-of-type(N)
|
|
@@ -1519,25 +1651,25 @@ class tt {
|
|
|
1519
1651
|
// Only use when all other strategies fail
|
|
1520
1652
|
// ============================================================
|
|
1521
1653
|
() => {
|
|
1522
|
-
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics),
|
|
1523
|
-
for (const
|
|
1524
|
-
|
|
1525
|
-
const
|
|
1526
|
-
if (!
|
|
1527
|
-
(
|
|
1654
|
+
const l = this.buildNodeSelector(s.anchor.tag, s.anchor.semantics), u = [];
|
|
1655
|
+
for (const p of s.path)
|
|
1656
|
+
u.push(p.tag);
|
|
1657
|
+
const d = a[a.length - 1], c = d.parentElement;
|
|
1658
|
+
if (!c || Array.from(c.children).filter(
|
|
1659
|
+
(p) => p.tagName.toLowerCase() === s.target.tag
|
|
1528
1660
|
).length <= 1) return null;
|
|
1529
1661
|
const g = this.buildNodeSelector(
|
|
1530
1662
|
s.target.tag,
|
|
1531
1663
|
s.target.semantics,
|
|
1532
1664
|
{ excludeClasses: !0 }
|
|
1533
1665
|
// No classes, just attrs + nth
|
|
1534
|
-
) + this.getNthSelector(
|
|
1535
|
-
return this.isUnique(
|
|
1666
|
+
) + this.getNthSelector(d, s.target.tag), f = [l, ...u.slice(0, -1), g].join(" ");
|
|
1667
|
+
return this.isUnique(f, r) ? f : null;
|
|
1536
1668
|
}
|
|
1537
1669
|
];
|
|
1538
1670
|
for (const l of o) {
|
|
1539
|
-
const
|
|
1540
|
-
if (
|
|
1671
|
+
const u = l();
|
|
1672
|
+
if (u) return u;
|
|
1541
1673
|
}
|
|
1542
1674
|
return null;
|
|
1543
1675
|
}
|
|
@@ -1550,27 +1682,12 @@ class tt {
|
|
|
1550
1682
|
buildElementSelector(t) {
|
|
1551
1683
|
const e = t.tagName.toLowerCase();
|
|
1552
1684
|
let s = e;
|
|
1553
|
-
if (t.id && !
|
|
1685
|
+
if (t.id && !D(t.id))
|
|
1554
1686
|
return `${e}#${this.escapeCSS(t.id)}`;
|
|
1555
|
-
const r = Array.from(t.classList),
|
|
1556
|
-
|
|
1557
|
-
const
|
|
1558
|
-
return
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Checks if ID is dynamic (generated)
|
|
1562
|
-
*/
|
|
1563
|
-
isDynamicId(t) {
|
|
1564
|
-
return [
|
|
1565
|
-
/^[a-f0-9]{8,}$/i,
|
|
1566
|
-
// hex hash
|
|
1567
|
-
/^\d{5,}$/,
|
|
1568
|
-
// numeric
|
|
1569
|
-
/^(r|react|ember|vue)[\d_]/i,
|
|
1570
|
-
// framework prefixes
|
|
1571
|
-
/:r\d+:$/
|
|
1572
|
-
// React 18 ID pattern
|
|
1573
|
-
].some((s) => s.test(t));
|
|
1687
|
+
const r = Array.from(t.classList), a = N(r);
|
|
1688
|
+
a.length > 0 && (s += a.slice(0, 2).map((o) => `.${this.escapeCSS(o)}`).join(""));
|
|
1689
|
+
const i = t.getAttribute("role");
|
|
1690
|
+
return i && (s += `[role="${this.escapeAttr(i)}"]`), s;
|
|
1574
1691
|
}
|
|
1575
1692
|
/**
|
|
1576
1693
|
* Safe querySelectorAll that doesn't throw
|
|
@@ -1590,11 +1707,11 @@ class tt {
|
|
|
1590
1707
|
const r = this.querySelectorSafe(t, s);
|
|
1591
1708
|
if (r.length <= 1) return null;
|
|
1592
1709
|
if (e.text) {
|
|
1593
|
-
const
|
|
1594
|
-
for (const
|
|
1595
|
-
const o =
|
|
1596
|
-
if (o ===
|
|
1597
|
-
return
|
|
1710
|
+
const a = e.text.normalized;
|
|
1711
|
+
for (const i of r) {
|
|
1712
|
+
const o = i.textContent?.trim() || "";
|
|
1713
|
+
if (o === a || o.includes(a) || a.includes(o))
|
|
1714
|
+
return i;
|
|
1598
1715
|
}
|
|
1599
1716
|
}
|
|
1600
1717
|
return null;
|
|
@@ -1615,10 +1732,10 @@ class tt {
|
|
|
1615
1732
|
getNthOfTypeIndex(t, e) {
|
|
1616
1733
|
const s = t.parentElement;
|
|
1617
1734
|
if (!s) return null;
|
|
1618
|
-
const
|
|
1619
|
-
(
|
|
1735
|
+
const a = Array.from(s.children).filter(
|
|
1736
|
+
(i) => i.tagName.toLowerCase() === e
|
|
1620
1737
|
).indexOf(t);
|
|
1621
|
-
return
|
|
1738
|
+
return a !== -1 ? a + 1 : null;
|
|
1622
1739
|
}
|
|
1623
1740
|
/**
|
|
1624
1741
|
* FIX 2: Ensures anchor selector is unique in the document
|
|
@@ -1632,29 +1749,34 @@ class tt {
|
|
|
1632
1749
|
if (this.isUnique(s, e))
|
|
1633
1750
|
return s;
|
|
1634
1751
|
if (r.classes && r.classes.length > 0) {
|
|
1635
|
-
const
|
|
1636
|
-
if (
|
|
1637
|
-
const o = `${s}.${this.escapeCSS(
|
|
1752
|
+
const i = N(r.classes);
|
|
1753
|
+
if (i.length > 0) {
|
|
1754
|
+
const o = `${s}.${this.escapeCSS(i[0])}`;
|
|
1638
1755
|
if (this.isUnique(o, e))
|
|
1639
1756
|
return o;
|
|
1640
1757
|
}
|
|
1641
1758
|
}
|
|
1642
1759
|
if (r.attributes) {
|
|
1643
|
-
const
|
|
1644
|
-
for (const { name: o, value: l } of
|
|
1645
|
-
const
|
|
1646
|
-
if (
|
|
1647
|
-
const
|
|
1648
|
-
if (this.isUnique(
|
|
1649
|
-
return
|
|
1760
|
+
const i = this.getSortedAttributes(r.attributes);
|
|
1761
|
+
for (const { name: o, value: l } of i) {
|
|
1762
|
+
const u = o === "href" || o === "src" ? _(o, l) : l;
|
|
1763
|
+
if (u) {
|
|
1764
|
+
const d = `${s}[${o}="${this.escapeAttr(u)}"]`;
|
|
1765
|
+
if (this.isUnique(d, e))
|
|
1766
|
+
return d;
|
|
1650
1767
|
}
|
|
1651
1768
|
}
|
|
1652
1769
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1770
|
+
if (t.anchor.nthChild !== void 0) {
|
|
1771
|
+
const i = `${s}:nth-child(${t.anchor.nthChild})`;
|
|
1772
|
+
if (this.isUnique(i, e))
|
|
1773
|
+
return i;
|
|
1774
|
+
}
|
|
1775
|
+
const a = Array.from(e.querySelectorAll(s));
|
|
1776
|
+
if (a.length > 1) {
|
|
1777
|
+
const i = this.findElementBySemantics(a, r);
|
|
1778
|
+
if (i) {
|
|
1779
|
+
const o = this.getNthOfTypeIndex(i, s);
|
|
1658
1780
|
if (o)
|
|
1659
1781
|
return `${s}:nth-of-type(${o})`;
|
|
1660
1782
|
}
|
|
@@ -1670,14 +1792,14 @@ class tt {
|
|
|
1670
1792
|
findElementBySemantics(t, e) {
|
|
1671
1793
|
return e.classes && e.classes.length > 0 || e.attributes && Object.keys(e.attributes).length > 0 || e.text ? t.find((r) => {
|
|
1672
1794
|
if (e.classes && e.classes.length > 0 && e.classes.every(
|
|
1673
|
-
(
|
|
1795
|
+
(i) => r.classList.contains(i)
|
|
1674
1796
|
) || e.attributes && Object.entries(e.attributes).every(
|
|
1675
|
-
([
|
|
1797
|
+
([i, o]) => r.getAttribute(i) === o
|
|
1676
1798
|
))
|
|
1677
1799
|
return !0;
|
|
1678
1800
|
if (e.text) {
|
|
1679
|
-
const
|
|
1680
|
-
if (
|
|
1801
|
+
const a = r.textContent?.trim() || "", i = e.text.normalized;
|
|
1802
|
+
if (a.includes(i) || i.includes(a))
|
|
1681
1803
|
return !0;
|
|
1682
1804
|
}
|
|
1683
1805
|
return !1;
|
|
@@ -1694,8 +1816,8 @@ class tt {
|
|
|
1694
1816
|
getNthSelector(t, e) {
|
|
1695
1817
|
const s = t.parentElement;
|
|
1696
1818
|
if (!s) return "";
|
|
1697
|
-
const r = Array.from(s.children),
|
|
1698
|
-
return ["tr", "td", "th", "thead", "tbody", "tfoot"].includes(e) ? `:nth-child(${
|
|
1819
|
+
const r = Array.from(s.children), a = r.indexOf(t) + 1;
|
|
1820
|
+
return ["tr", "td", "th", "thead", "tbody", "tfoot"].includes(e) ? `:nth-child(${a})` : `:nth-of-type(${r.filter((l) => l.tagName.toLowerCase() === e).indexOf(t) + 1})`;
|
|
1699
1821
|
}
|
|
1700
1822
|
/**
|
|
1701
1823
|
* Gets attribute priority for sorting
|
|
@@ -1703,7 +1825,7 @@ class tt {
|
|
|
1703
1825
|
* @returns Priority number (higher = more priority)
|
|
1704
1826
|
*/
|
|
1705
1827
|
getAttributePriority(t) {
|
|
1706
|
-
return
|
|
1828
|
+
return w[t] !== void 0 ? w[t] : t.startsWith("data-") ? w["data-*"] : t.startsWith("aria-") ? w["aria-*"] : 0;
|
|
1707
1829
|
}
|
|
1708
1830
|
/**
|
|
1709
1831
|
* Checks if attribute should be ignored
|
|
@@ -1711,7 +1833,7 @@ class tt {
|
|
|
1711
1833
|
* @returns True if should be ignored
|
|
1712
1834
|
*/
|
|
1713
1835
|
shouldIgnoreAttribute(t) {
|
|
1714
|
-
return !!(
|
|
1836
|
+
return !!(et.has(t) || t.startsWith("on") || t.startsWith("ng-") || t.startsWith("_ng") || t.startsWith("data-reactid") || t.startsWith("data-react") || t.startsWith("data-v-"));
|
|
1715
1837
|
}
|
|
1716
1838
|
/**
|
|
1717
1839
|
* Gets attributes sorted by priority
|
|
@@ -1719,7 +1841,7 @@ class tt {
|
|
|
1719
1841
|
* @returns Sorted array of attributes with priority
|
|
1720
1842
|
*/
|
|
1721
1843
|
getSortedAttributes(t) {
|
|
1722
|
-
return Object.entries(t).filter(([e]) => !this.shouldIgnoreAttribute(e)).map(([e, s]) => ({
|
|
1844
|
+
return Object.entries(t).filter(([e]) => !this.shouldIgnoreAttribute(e)).filter(([e, s]) => !B.has(e) || !G(s)).map(([e, s]) => ({
|
|
1723
1845
|
name: e,
|
|
1724
1846
|
value: s,
|
|
1725
1847
|
priority: this.getAttributePriority(e)
|
|
@@ -1734,15 +1856,15 @@ class tt {
|
|
|
1734
1856
|
if (e.id)
|
|
1735
1857
|
return r += `#${this.escapeCSS(e.id)}`, r;
|
|
1736
1858
|
if (e.attributes) {
|
|
1737
|
-
const
|
|
1738
|
-
for (const { name:
|
|
1739
|
-
const l =
|
|
1740
|
-
l && (r += `[${
|
|
1859
|
+
const a = this.getSortedAttributes(e.attributes);
|
|
1860
|
+
for (const { name: i, value: o } of a) {
|
|
1861
|
+
const l = i === "href" || i === "src" ? _(i, o) : o;
|
|
1862
|
+
l && (r += `[${i}="${this.escapeAttr(l)}"]`);
|
|
1741
1863
|
}
|
|
1742
1864
|
}
|
|
1743
1865
|
if (e.role && !e.attributes?.role && (r += `[role="${this.escapeAttr(e.role)}"]`), !s?.excludeClasses && e.classes && e.classes.length > 0) {
|
|
1744
|
-
const
|
|
1745
|
-
r +=
|
|
1866
|
+
const a = N(e.classes), i = s?.maxClasses !== void 0 ? a.slice(0, s.maxClasses) : a;
|
|
1867
|
+
r += i.map((o) => `.${this.escapeCSS(o)}`).join("");
|
|
1746
1868
|
}
|
|
1747
1869
|
return r;
|
|
1748
1870
|
}
|
|
@@ -1750,7 +1872,8 @@ class tt {
|
|
|
1750
1872
|
* Escapes special characters for CSS selector
|
|
1751
1873
|
*/
|
|
1752
1874
|
escapeCSS(t) {
|
|
1753
|
-
|
|
1875
|
+
let e = t;
|
|
1876
|
+
return e.startsWith("-") && (e = "\\-" + e.slice(1)), e = e.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, "\\$1"), e;
|
|
1754
1877
|
}
|
|
1755
1878
|
/**
|
|
1756
1879
|
* Escapes quotes for attribute values
|
|
@@ -1764,10 +1887,10 @@ class tt {
|
|
|
1764
1887
|
* @returns True if element is an SVG child
|
|
1765
1888
|
*/
|
|
1766
1889
|
isSvgChildElement(t) {
|
|
1767
|
-
return
|
|
1890
|
+
return ht.includes(t);
|
|
1768
1891
|
}
|
|
1769
1892
|
}
|
|
1770
|
-
class
|
|
1893
|
+
class Ft {
|
|
1771
1894
|
/**
|
|
1772
1895
|
* Filters elements that match the semantics
|
|
1773
1896
|
* @param elements - Candidate elements
|
|
@@ -1788,10 +1911,10 @@ class Dt {
|
|
|
1788
1911
|
* Prioritizes direct text nodes, but falls back to full textContent if no direct text
|
|
1789
1912
|
*/
|
|
1790
1913
|
matchText(t, e) {
|
|
1791
|
-
const
|
|
1792
|
-
if (!
|
|
1793
|
-
const
|
|
1794
|
-
return e.matchMode === "partial" ?
|
|
1914
|
+
const a = Array.from(t.childNodes).filter((o) => o.nodeType === Node.TEXT_NODE).map((o) => o.textContent?.trim() ?? "").join(" ") || (t.textContent?.trim() ?? "");
|
|
1915
|
+
if (!a) return !1;
|
|
1916
|
+
const i = V(a);
|
|
1917
|
+
return e.matchMode === "partial" ? i.includes(e.normalized) : i === e.normalized;
|
|
1795
1918
|
}
|
|
1796
1919
|
/**
|
|
1797
1920
|
* Matches attributes
|
|
@@ -1819,7 +1942,7 @@ class Dt {
|
|
|
1819
1942
|
* Computes simple path hash (matching SvgFingerprinter)
|
|
1820
1943
|
*/
|
|
1821
1944
|
computePathHash(t) {
|
|
1822
|
-
const r = (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((
|
|
1945
|
+
const r = (t.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/gi) ?? []).slice(0, 5).map((a) => a.trim().replace(/(-?\d+\.?\d*)/g, (i) => parseFloat(i).toFixed(1))).join(" ");
|
|
1823
1946
|
return this.simpleHash(r);
|
|
1824
1947
|
}
|
|
1825
1948
|
/**
|
|
@@ -1832,17 +1955,17 @@ class Dt {
|
|
|
1832
1955
|
s.push(`r=${t.getAttribute("r") ?? "0"}`);
|
|
1833
1956
|
break;
|
|
1834
1957
|
case "rect": {
|
|
1835
|
-
const r = parseFloat(t.getAttribute("width") ?? "0"),
|
|
1836
|
-
r > 0 &&
|
|
1958
|
+
const r = parseFloat(t.getAttribute("width") ?? "0"), a = parseFloat(t.getAttribute("height") ?? "0");
|
|
1959
|
+
r > 0 && a > 0 && s.push(`ratio=${(r / a).toFixed(2)}`);
|
|
1837
1960
|
break;
|
|
1838
1961
|
}
|
|
1839
1962
|
case "ellipse": {
|
|
1840
|
-
const r = parseFloat(t.getAttribute("rx") ?? "0"),
|
|
1841
|
-
r > 0 &&
|
|
1963
|
+
const r = parseFloat(t.getAttribute("rx") ?? "0"), a = parseFloat(t.getAttribute("ry") ?? "0");
|
|
1964
|
+
r > 0 && a > 0 && s.push(`ratio=${(r / a).toFixed(2)}`);
|
|
1842
1965
|
break;
|
|
1843
1966
|
}
|
|
1844
1967
|
case "line": {
|
|
1845
|
-
const r = parseFloat(t.getAttribute("x1") ?? "0"),
|
|
1968
|
+
const r = parseFloat(t.getAttribute("x1") ?? "0"), a = parseFloat(t.getAttribute("y1") ?? "0"), i = parseFloat(t.getAttribute("x2") ?? "0"), o = parseFloat(t.getAttribute("y2") ?? "0"), l = Math.atan2(o - a, i - r);
|
|
1846
1969
|
s.push(`angle=${l.toFixed(2)}`);
|
|
1847
1970
|
break;
|
|
1848
1971
|
}
|
|
@@ -1861,7 +1984,7 @@ class Dt {
|
|
|
1861
1984
|
return Math.abs(e).toString(16).padStart(8, "0");
|
|
1862
1985
|
}
|
|
1863
1986
|
}
|
|
1864
|
-
class
|
|
1987
|
+
class jt {
|
|
1865
1988
|
/**
|
|
1866
1989
|
* Applies a single constraint to candidates
|
|
1867
1990
|
* @param candidates - Current candidate elements
|
|
@@ -1942,21 +2065,21 @@ class Rt {
|
|
|
1942
2065
|
if (t === e) return 0;
|
|
1943
2066
|
if (t.length === 0) return e.length;
|
|
1944
2067
|
if (e.length === 0) return t.length;
|
|
1945
|
-
const s = Array.from({ length: e.length + 1 }, (r,
|
|
2068
|
+
const s = Array.from({ length: e.length + 1 }, (r, a) => a);
|
|
1946
2069
|
for (let r = 1; r <= t.length; r++) {
|
|
1947
|
-
let
|
|
1948
|
-
for (let
|
|
1949
|
-
const o = t[r - 1] === e[
|
|
1950
|
-
s[
|
|
2070
|
+
let a = r;
|
|
2071
|
+
for (let i = 1; i <= e.length; i++) {
|
|
2072
|
+
const o = t[r - 1] === e[i - 1] ? s[i - 1] : Math.min(s[i - 1], a, s[i]) + 1;
|
|
2073
|
+
s[i - 1] = a, a = o;
|
|
1951
2074
|
}
|
|
1952
|
-
s[e.length] =
|
|
2075
|
+
s[e.length] = a;
|
|
1953
2076
|
}
|
|
1954
2077
|
return s[e.length];
|
|
1955
2078
|
}
|
|
1956
2079
|
}
|
|
1957
|
-
class
|
|
2080
|
+
class Wt {
|
|
1958
2081
|
constructor() {
|
|
1959
|
-
this.cssGenerator = new
|
|
2082
|
+
this.cssGenerator = new st();
|
|
1960
2083
|
}
|
|
1961
2084
|
/**
|
|
1962
2085
|
* Handles fallback when resolution fails
|
|
@@ -1993,21 +2116,21 @@ class Ht {
|
|
|
1993
2116
|
fallbackToAnchor(t, e) {
|
|
1994
2117
|
const s = this.cssGenerator.buildAnchorSelector(t), r = e instanceof Document ? e : e.ownerDocument ?? e;
|
|
1995
2118
|
try {
|
|
1996
|
-
const
|
|
1997
|
-
if (
|
|
2119
|
+
const a = r.querySelector(s);
|
|
2120
|
+
if (a)
|
|
1998
2121
|
return {
|
|
1999
2122
|
status: "degraded-fallback",
|
|
2000
|
-
elements: [
|
|
2123
|
+
elements: [a],
|
|
2001
2124
|
warnings: ["Target not found, returning anchor"],
|
|
2002
2125
|
confidence: t.meta.confidence * 0.3,
|
|
2003
2126
|
meta: { degraded: !0, degradationReason: "anchor-fallback" }
|
|
2004
2127
|
};
|
|
2005
|
-
} catch (
|
|
2006
|
-
const
|
|
2128
|
+
} catch (a) {
|
|
2129
|
+
const i = a instanceof Error ? a.message : "Unknown selector error";
|
|
2007
2130
|
return {
|
|
2008
2131
|
status: "error",
|
|
2009
2132
|
elements: [],
|
|
2010
|
-
warnings: [`Invalid anchor selector: ${
|
|
2133
|
+
warnings: [`Invalid anchor selector: ${i}`],
|
|
2011
2134
|
confidence: 0,
|
|
2012
2135
|
meta: { degraded: !0, degradationReason: "invalid-anchor-selector" }
|
|
2013
2136
|
};
|
|
@@ -2055,10 +2178,10 @@ class Ht {
|
|
|
2055
2178
|
*/
|
|
2056
2179
|
selectBestScoring(t, e) {
|
|
2057
2180
|
const s = e.target.semantics;
|
|
2058
|
-
let r = t[0],
|
|
2059
|
-
for (const
|
|
2060
|
-
const o = this.scoreElementMatch(
|
|
2061
|
-
o >
|
|
2181
|
+
let r = t[0], a = -1;
|
|
2182
|
+
for (const i of t) {
|
|
2183
|
+
const o = this.scoreElementMatch(i, s);
|
|
2184
|
+
o > a && (a = o, r = i);
|
|
2062
2185
|
}
|
|
2063
2186
|
return {
|
|
2064
2187
|
status: "success",
|
|
@@ -2066,7 +2189,7 @@ class Ht {
|
|
|
2066
2189
|
warnings: [
|
|
2067
2190
|
`Multiple matches (${t.length}), selected best-scoring element`
|
|
2068
2191
|
],
|
|
2069
|
-
confidence: e.meta.confidence * (0.7 +
|
|
2192
|
+
confidence: e.meta.confidence * (0.7 + a * 0.2),
|
|
2070
2193
|
meta: { degraded: !0, degradationReason: "best-of-multiple" }
|
|
2071
2194
|
};
|
|
2072
2195
|
}
|
|
@@ -2078,61 +2201,61 @@ class Ht {
|
|
|
2078
2201
|
let s = 0, r = 0;
|
|
2079
2202
|
if (e.id && (r += 0.3, t.id === e.id && (s += 0.3)), e.classes && e.classes.length > 0) {
|
|
2080
2203
|
r += 0.25;
|
|
2081
|
-
const
|
|
2082
|
-
(o) =>
|
|
2204
|
+
const a = Array.from(t.classList), i = e.classes.filter(
|
|
2205
|
+
(o) => a.includes(o)
|
|
2083
2206
|
).length;
|
|
2084
|
-
s +=
|
|
2207
|
+
s += i / e.classes.length * 0.25;
|
|
2085
2208
|
}
|
|
2086
2209
|
if (e.attributes) {
|
|
2087
|
-
const
|
|
2088
|
-
if (
|
|
2210
|
+
const a = Object.entries(e.attributes);
|
|
2211
|
+
if (a.length > 0) {
|
|
2089
2212
|
r += 0.2;
|
|
2090
|
-
let
|
|
2091
|
-
for (const [o, l] of
|
|
2092
|
-
t.getAttribute(o) === l &&
|
|
2093
|
-
s +=
|
|
2213
|
+
let i = 0;
|
|
2214
|
+
for (const [o, l] of a)
|
|
2215
|
+
t.getAttribute(o) === l && i++;
|
|
2216
|
+
s += i / a.length * 0.2;
|
|
2094
2217
|
}
|
|
2095
2218
|
}
|
|
2096
2219
|
if (e.role && (r += 0.15, t.getAttribute("role") === e.role && (s += 0.15)), e.text) {
|
|
2097
2220
|
r += 0.1;
|
|
2098
|
-
const
|
|
2099
|
-
|
|
2221
|
+
const a = V(t.textContent);
|
|
2222
|
+
a === e.text.normalized ? s += 0.1 : a.includes(e.text.normalized) && (s += 0.05);
|
|
2100
2223
|
}
|
|
2101
2224
|
return r > 0 ? s / r : 0;
|
|
2102
2225
|
}
|
|
2103
2226
|
}
|
|
2104
|
-
function
|
|
2105
|
-
const s = { ...
|
|
2227
|
+
function Bt(n, t, e = {}) {
|
|
2228
|
+
const s = { ...dt, ...e }, r = new st(), a = new Ft(), i = new jt(), o = new Wt(), l = t instanceof Document ? t : t.ownerDocument ?? t, u = r.buildSelector(n, {
|
|
2106
2229
|
ensureUnique: !1,
|
|
2107
2230
|
root: l
|
|
2108
2231
|
});
|
|
2109
|
-
let
|
|
2232
|
+
let d;
|
|
2110
2233
|
try {
|
|
2111
|
-
|
|
2112
|
-
} catch (
|
|
2113
|
-
const
|
|
2234
|
+
d = Array.from(l.querySelectorAll(u));
|
|
2235
|
+
} catch (f) {
|
|
2236
|
+
const p = f instanceof Error ? f.message : "Unknown selector error";
|
|
2114
2237
|
return {
|
|
2115
2238
|
status: "error",
|
|
2116
2239
|
elements: [],
|
|
2117
2240
|
warnings: [
|
|
2118
|
-
`Invalid CSS selector: ${
|
|
2119
|
-
`Error: ${
|
|
2241
|
+
`Invalid CSS selector: ${u}`,
|
|
2242
|
+
`Error: ${p}`
|
|
2120
2243
|
],
|
|
2121
2244
|
confidence: 0,
|
|
2122
2245
|
meta: { degraded: !0, degradationReason: "invalid-selector" }
|
|
2123
2246
|
};
|
|
2124
2247
|
}
|
|
2125
|
-
|
|
2126
|
-
const
|
|
2127
|
-
if (
|
|
2248
|
+
d.length > s.maxCandidates && (d = d.slice(0, s.maxCandidates));
|
|
2249
|
+
const c = a.match(d, n.target.semantics);
|
|
2250
|
+
if (c.length === 1)
|
|
2128
2251
|
return {
|
|
2129
2252
|
status: "success",
|
|
2130
|
-
elements:
|
|
2253
|
+
elements: c,
|
|
2131
2254
|
warnings: [],
|
|
2132
2255
|
confidence: n.meta.confidence,
|
|
2133
2256
|
meta: { degraded: !1 }
|
|
2134
2257
|
};
|
|
2135
|
-
if (
|
|
2258
|
+
if (c.length === 0)
|
|
2136
2259
|
return s.enableFallback ? o.handleFallback(n, l) : {
|
|
2137
2260
|
status: "error",
|
|
2138
2261
|
elements: [],
|
|
@@ -2140,18 +2263,18 @@ function Pt(n, t, e = {}) {
|
|
|
2140
2263
|
confidence: 0,
|
|
2141
2264
|
meta: { degraded: !0, degradationReason: "not-found" }
|
|
2142
2265
|
};
|
|
2143
|
-
let
|
|
2144
|
-
const g =
|
|
2145
|
-
for (const
|
|
2146
|
-
if (
|
|
2266
|
+
let h = c;
|
|
2267
|
+
const g = Gt(n.constraints);
|
|
2268
|
+
for (const f of g) {
|
|
2269
|
+
if (h = i.applyConstraint(h, f), h.length === 1)
|
|
2147
2270
|
return {
|
|
2148
2271
|
status: "success",
|
|
2149
|
-
elements:
|
|
2272
|
+
elements: h,
|
|
2150
2273
|
warnings: [],
|
|
2151
2274
|
confidence: n.meta.confidence * 0.9,
|
|
2152
2275
|
meta: { degraded: !1 }
|
|
2153
2276
|
};
|
|
2154
|
-
if (
|
|
2277
|
+
if (h.length === 0)
|
|
2155
2278
|
return s.enableFallback ? o.handleFallback(n, l) : {
|
|
2156
2279
|
status: "error",
|
|
2157
2280
|
elements: [],
|
|
@@ -2162,16 +2285,16 @@ function Pt(n, t, e = {}) {
|
|
|
2162
2285
|
}
|
|
2163
2286
|
return s.strictMode ? {
|
|
2164
2287
|
status: "ambiguous",
|
|
2165
|
-
elements:
|
|
2166
|
-
warnings: [`Non-unique resolution: ${
|
|
2288
|
+
elements: h,
|
|
2289
|
+
warnings: [`Non-unique resolution: ${h.length} matches`],
|
|
2167
2290
|
confidence: n.meta.confidence * 0.7,
|
|
2168
2291
|
meta: { degraded: !0, degradationReason: "ambiguous" }
|
|
2169
|
-
} : o.handleAmbiguous(
|
|
2292
|
+
} : o.handleAmbiguous(h, n);
|
|
2170
2293
|
}
|
|
2171
|
-
function
|
|
2294
|
+
function Gt(n) {
|
|
2172
2295
|
return [...n].sort((t, e) => e.priority - t.priority);
|
|
2173
2296
|
}
|
|
2174
|
-
function
|
|
2297
|
+
function oe(n) {
|
|
2175
2298
|
const t = [], e = [];
|
|
2176
2299
|
if (n.version ? n.version !== "1.0" && e.push(`Unknown version: ${n.version}`) : t.push("Missing version field"), n.anchor ? (n.anchor.tag || t.push("Anchor missing tag"), typeof n.anchor.score != "number" && t.push("Anchor missing score"), n.anchor.semantics || t.push("Anchor missing semantics")) : t.push("Missing anchor field"), n.target ? (n.target.tag || t.push("Target missing tag"), typeof n.target.score != "number" && t.push("Target missing score"), n.target.semantics || t.push("Target missing semantics")) : t.push("Missing target field"), !Array.isArray(n.path))
|
|
2177
2300
|
t.push("Path must be an array");
|
|
@@ -2186,12 +2309,12 @@ function Yt(n) {
|
|
|
2186
2309
|
warnings: e
|
|
2187
2310
|
};
|
|
2188
2311
|
}
|
|
2189
|
-
function
|
|
2312
|
+
function ce(n) {
|
|
2190
2313
|
if (!n || typeof n != "object") return !1;
|
|
2191
2314
|
const t = n;
|
|
2192
2315
|
return typeof t.version == "string" && typeof t.anchor == "object" && Array.isArray(t.path) && typeof t.target == "object";
|
|
2193
2316
|
}
|
|
2194
|
-
const
|
|
2317
|
+
const rt = {
|
|
2195
2318
|
maxClasses: 2,
|
|
2196
2319
|
maxAttributes: 5,
|
|
2197
2320
|
includeText: !0,
|
|
@@ -2199,20 +2322,20 @@ const et = {
|
|
|
2199
2322
|
simplifyTarget: !0,
|
|
2200
2323
|
includeConstraints: !0
|
|
2201
2324
|
};
|
|
2202
|
-
function
|
|
2203
|
-
return n === "id" ? 101 :
|
|
2325
|
+
function tt(n) {
|
|
2326
|
+
return n === "id" ? 101 : w[n] !== void 0 ? w[n] : n.startsWith("data-") ? w["data-*"] : n.startsWith("aria-") ? w["aria-*"] : 0;
|
|
2204
2327
|
}
|
|
2205
|
-
function
|
|
2328
|
+
function Vt(n) {
|
|
2206
2329
|
return ["id", "data-testid", "data-qa", "data-cy", "href", "text", "role"].includes(n);
|
|
2207
2330
|
}
|
|
2208
|
-
function
|
|
2331
|
+
function Qt(n) {
|
|
2209
2332
|
return !!(/@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(n) || /(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/.test(n) || /\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/.test(n));
|
|
2210
2333
|
}
|
|
2211
|
-
function
|
|
2212
|
-
const e = { ...
|
|
2213
|
-
return `${s}: ${r} :: ${
|
|
2334
|
+
function Zt(n, t) {
|
|
2335
|
+
const e = { ...rt, ...t }, s = `v${n.version}`, r = U(n.anchor, !1, e), a = n.path.length > 0 ? n.path.map((l) => U(l, !1, e)).join(" > ") + " > " : "", i = U(n.target, !0, e), o = e.includeConstraints ? Xt(n) : "";
|
|
2336
|
+
return `${s}: ${r} :: ${a}${i}${o}`;
|
|
2214
2337
|
}
|
|
2215
|
-
function
|
|
2338
|
+
function Yt(n) {
|
|
2216
2339
|
n = n.trim();
|
|
2217
2340
|
const t = n.match(/^v(\d+(?:\.\d+)?)\s*:\s*/);
|
|
2218
2341
|
if (!t)
|
|
@@ -2224,21 +2347,21 @@ function _t(n) {
|
|
|
2224
2347
|
const r = s.match(/^(.+?)\s*::\s*/);
|
|
2225
2348
|
if (!r)
|
|
2226
2349
|
throw new Error('Invalid SEQL Selector: missing anchor separator "::"');
|
|
2227
|
-
const
|
|
2350
|
+
const a = r[1].trim();
|
|
2228
2351
|
s = s.slice(r[0].length);
|
|
2229
|
-
const
|
|
2352
|
+
const i = s.match(/\s*\{([^}]+)\}\s*$/);
|
|
2230
2353
|
let o = "";
|
|
2231
|
-
|
|
2232
|
-
const l = s.split(/\s*>\s*/).map((
|
|
2354
|
+
i && (o = i[1], s = s.slice(0, i.index));
|
|
2355
|
+
const l = s.split(/\s*>\s*/).map((m) => m.trim()).filter((m) => m);
|
|
2233
2356
|
if (l.length === 0)
|
|
2234
2357
|
throw new Error("Invalid SEQL Selector: missing target node");
|
|
2235
|
-
const
|
|
2358
|
+
const u = l[l.length - 1], d = l.slice(0, -1), c = F(a, !0), h = d.map((m) => F(m, !1)), g = F(u, !1), f = Kt(o);
|
|
2236
2359
|
return {
|
|
2237
2360
|
version: "1.0",
|
|
2238
|
-
anchor:
|
|
2239
|
-
path:
|
|
2361
|
+
anchor: c,
|
|
2362
|
+
path: h,
|
|
2240
2363
|
target: g,
|
|
2241
|
-
constraints:
|
|
2364
|
+
constraints: f,
|
|
2242
2365
|
fallback: {
|
|
2243
2366
|
onMultiple: "best-score",
|
|
2244
2367
|
onMissing: "anchor-only",
|
|
@@ -2253,45 +2376,42 @@ function _t(n) {
|
|
|
2253
2376
|
}
|
|
2254
2377
|
};
|
|
2255
2378
|
}
|
|
2256
|
-
function
|
|
2379
|
+
function U(n, t = !1, e = rt) {
|
|
2257
2380
|
const { tag: s, semantics: r } = n;
|
|
2258
|
-
let
|
|
2259
|
-
const
|
|
2381
|
+
let a = s;
|
|
2382
|
+
const i = [], o = { ...r.attributes };
|
|
2260
2383
|
r.id && (o.id = r.id), r.role && !o.role && (o.role = r.role);
|
|
2261
|
-
const l = Object.entries(o).map(([c,
|
|
2262
|
-
const
|
|
2263
|
-
return { name: c, value:
|
|
2264
|
-
}).filter((c) => ["style", "xmlns", "tabindex", "contenteditable"].includes(c.name) ? !1 : c.priority > 0 || c.name === "role" || c.name === "id");
|
|
2265
|
-
l.sort((c,
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
for (const { name: c, value:
|
|
2269
|
-
|
|
2270
|
-
if (e.includeText && r.text && !
|
|
2384
|
+
const l = Object.entries(o).map(([c, h]) => {
|
|
2385
|
+
const g = tt(c), f = c === "href" || c === "src" ? _(c, h) : h;
|
|
2386
|
+
return { name: c, value: f, priority: g };
|
|
2387
|
+
}).filter((c) => ["style", "xmlns", "tabindex", "contenteditable"].includes(c.name) || B.has(c.name) && G(c.value) ? !1 : c.priority > 0 || c.name === "role" || c.name === "id");
|
|
2388
|
+
l.sort((c, h) => h.priority - c.priority);
|
|
2389
|
+
const u = l.slice(0, e.maxAttributes);
|
|
2390
|
+
u.sort((c, h) => c.name.localeCompare(h.name));
|
|
2391
|
+
for (const { name: c, value: h } of u)
|
|
2392
|
+
i.push(`${c}="${j(h)}"`);
|
|
2393
|
+
if (e.includeText && r.text && !Qt(r.text.normalized)) {
|
|
2271
2394
|
const c = r.text.normalized;
|
|
2272
|
-
c.length > 0 && c.length <= e.maxTextLength &&
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
if (!(t && e.simplifyTarget && u) && c.length > 0) {
|
|
2284
|
-
const g = c.sort().slice(0, e.maxClasses);
|
|
2285
|
-
i += g.map((d) => `.${d}`).join("");
|
|
2395
|
+
c.length > 0 && c.length <= e.maxTextLength && i.push(`text="${j(c)}"`);
|
|
2396
|
+
}
|
|
2397
|
+
let d = i;
|
|
2398
|
+
if (i.length > 0 && (t && e.simplifyTarget && r.id && (d = i.filter((c) => {
|
|
2399
|
+
const h = c.split("=")[0];
|
|
2400
|
+
return tt(h) >= 60 || h === "text" || h === "id" || h === "role";
|
|
2401
|
+
})), d.length > 0 && d.sort((c, h) => c.localeCompare(h))), r.classes && r.classes.length > 0) {
|
|
2402
|
+
const c = N(r.classes), h = !!r.id || i.some((f) => f.startsWith("href=") || f.startsWith("data-testid=") || f.startsWith("text=") || f.startsWith("role="));
|
|
2403
|
+
if (!(t && e.simplifyTarget && h) && c.length > 0) {
|
|
2404
|
+
const f = c.sort().slice(0, e.maxClasses);
|
|
2405
|
+
a += f.map((p) => `.${p}`).join("");
|
|
2286
2406
|
}
|
|
2287
2407
|
}
|
|
2288
|
-
if ("nthChild" in n && n.nthChild) {
|
|
2289
|
-
const c = !!r.id || r.attributes && Object.keys(r.attributes).some(
|
|
2290
|
-
t && e.simplifyTarget && c || (
|
|
2408
|
+
if (d.length > 0 && (a += `[${d.join(",")}]`), "nthChild" in n && n.nthChild) {
|
|
2409
|
+
const c = !!r.id || r.attributes && Object.keys(r.attributes).some(Vt);
|
|
2410
|
+
t && e.simplifyTarget && c || (a += `#${n.nthChild}`);
|
|
2291
2411
|
}
|
|
2292
|
-
return
|
|
2412
|
+
return a;
|
|
2293
2413
|
}
|
|
2294
|
-
function
|
|
2414
|
+
function Xt(n) {
|
|
2295
2415
|
if (!n.constraints || n.constraints.length === 0)
|
|
2296
2416
|
return "";
|
|
2297
2417
|
const t = [];
|
|
@@ -2312,58 +2432,58 @@ function zt(n) {
|
|
|
2312
2432
|
}
|
|
2313
2433
|
return t.length === 0 ? "" : ` {${t.join(",")}}`;
|
|
2314
2434
|
}
|
|
2315
|
-
function
|
|
2435
|
+
function F(n, t) {
|
|
2316
2436
|
let e = n;
|
|
2317
2437
|
const s = {}, r = e.match(/^([a-z][a-z0-9-]*)/);
|
|
2318
2438
|
if (!r)
|
|
2319
2439
|
throw new Error(`Invalid node: missing tag name in "${n}"`);
|
|
2320
|
-
const
|
|
2321
|
-
e = e.slice(
|
|
2322
|
-
const
|
|
2440
|
+
const a = r[1];
|
|
2441
|
+
e = e.slice(a.length);
|
|
2442
|
+
const i = [];
|
|
2323
2443
|
let o;
|
|
2324
2444
|
for (; o = e.match(/^\.([a-zA-Z][a-zA-Z0-9-_]*)/); )
|
|
2325
|
-
|
|
2326
|
-
|
|
2445
|
+
i.push(o[1]), e = e.slice(o[0].length);
|
|
2446
|
+
i.length > 0 && (s.classes = i);
|
|
2327
2447
|
const l = e.match(/^\[([^\]]+)\]/);
|
|
2328
2448
|
if (l) {
|
|
2329
|
-
const
|
|
2330
|
-
for (const
|
|
2331
|
-
const
|
|
2332
|
-
if (
|
|
2333
|
-
const [,
|
|
2334
|
-
|
|
2449
|
+
const c = l[1], h = {}, g = Jt(c);
|
|
2450
|
+
for (const f of g) {
|
|
2451
|
+
const p = f.match(/^([a-z][a-z0-9-]*)(?:=|~=)"((?:[^"\\]|\\.)*)"/);
|
|
2452
|
+
if (p) {
|
|
2453
|
+
const [, m, b] = p;
|
|
2454
|
+
h[m] = nt(b);
|
|
2335
2455
|
}
|
|
2336
2456
|
}
|
|
2337
|
-
Object.keys(
|
|
2338
|
-
raw:
|
|
2339
|
-
normalized:
|
|
2340
|
-
}, delete
|
|
2341
|
-
}
|
|
2342
|
-
let
|
|
2343
|
-
const
|
|
2344
|
-
if (
|
|
2457
|
+
Object.keys(h).length > 0 && (h.text && (s.text = {
|
|
2458
|
+
raw: h.text,
|
|
2459
|
+
normalized: h.text
|
|
2460
|
+
}, delete h.text), h.id && (s.id = h.id, delete h.id), h.role && (s.role = h.role, delete h.role), Object.keys(h).length > 0 && (s.attributes = h)), e = e.slice(l[0].length);
|
|
2461
|
+
}
|
|
2462
|
+
let u;
|
|
2463
|
+
const d = e.match(/^#(\d+)/);
|
|
2464
|
+
if (d && (u = parseInt(d[1], 10), e = e.slice(d[0].length)), e.trim())
|
|
2345
2465
|
throw new Error(`Invalid node: unexpected content "${e}" in "${n}"`);
|
|
2346
2466
|
return t ? {
|
|
2347
|
-
tag:
|
|
2467
|
+
tag: a,
|
|
2348
2468
|
semantics: s,
|
|
2349
2469
|
score: 0.7,
|
|
2350
2470
|
degraded: !1
|
|
2351
2471
|
} : {
|
|
2352
|
-
tag:
|
|
2472
|
+
tag: a,
|
|
2353
2473
|
semantics: s,
|
|
2354
2474
|
score: 0.7,
|
|
2355
|
-
nthChild:
|
|
2475
|
+
nthChild: u
|
|
2356
2476
|
};
|
|
2357
2477
|
}
|
|
2358
|
-
function
|
|
2478
|
+
function Kt(n) {
|
|
2359
2479
|
if (!n.trim())
|
|
2360
2480
|
return [];
|
|
2361
2481
|
const t = [], e = n.split(",").map((s) => s.trim());
|
|
2362
2482
|
for (const s of e) {
|
|
2363
|
-
const [r,
|
|
2483
|
+
const [r, a] = s.split("=").map((i) => i.trim());
|
|
2364
2484
|
switch (r) {
|
|
2365
2485
|
case "unique":
|
|
2366
|
-
|
|
2486
|
+
a === "true" && t.push({
|
|
2367
2487
|
type: "uniqueness",
|
|
2368
2488
|
params: {
|
|
2369
2489
|
mode: "strict"
|
|
@@ -2375,17 +2495,17 @@ function Ft(n) {
|
|
|
2375
2495
|
t.push({
|
|
2376
2496
|
type: "position",
|
|
2377
2497
|
params: {
|
|
2378
|
-
strategy:
|
|
2498
|
+
strategy: a
|
|
2379
2499
|
},
|
|
2380
2500
|
priority: 70
|
|
2381
2501
|
});
|
|
2382
2502
|
break;
|
|
2383
2503
|
case "text":
|
|
2384
|
-
const
|
|
2504
|
+
const i = a.replace(/^"(.*)"$/, "$1");
|
|
2385
2505
|
t.push({
|
|
2386
2506
|
type: "text-proximity",
|
|
2387
2507
|
params: {
|
|
2388
|
-
reference:
|
|
2508
|
+
reference: nt(i),
|
|
2389
2509
|
maxDistance: 5
|
|
2390
2510
|
},
|
|
2391
2511
|
priority: 60
|
|
@@ -2395,34 +2515,34 @@ function Ft(n) {
|
|
|
2395
2515
|
}
|
|
2396
2516
|
return t;
|
|
2397
2517
|
}
|
|
2398
|
-
function
|
|
2518
|
+
function Jt(n) {
|
|
2399
2519
|
const t = [];
|
|
2400
2520
|
let e = "", s = !1;
|
|
2401
2521
|
for (let r = 0; r < n.length; r++) {
|
|
2402
|
-
const
|
|
2403
|
-
|
|
2522
|
+
const a = n[r];
|
|
2523
|
+
a === '"' && (r === 0 || n[r - 1] !== "\\") ? (s = !s, e += a) : a === "," && !s ? (e.trim() && t.push(e.trim()), e = "") : e += a;
|
|
2404
2524
|
}
|
|
2405
2525
|
return e.trim() && t.push(e.trim()), t;
|
|
2406
2526
|
}
|
|
2407
2527
|
function j(n) {
|
|
2408
2528
|
return n.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/>/g, "\\>").replace(/:/g, "\\:");
|
|
2409
2529
|
}
|
|
2410
|
-
function
|
|
2530
|
+
function nt(n) {
|
|
2411
2531
|
return n.replace(/\\\\/g, "\0").replace(/\\"/g, '"').replace(/\\>/g, ">").replace(/\\:/g, ":").replace(/\x00/g, "\\");
|
|
2412
2532
|
}
|
|
2413
|
-
function
|
|
2414
|
-
const s =
|
|
2415
|
-
return s ?
|
|
2533
|
+
function le(n, t, e) {
|
|
2534
|
+
const s = Z(n, t);
|
|
2535
|
+
return s ? Zt(s, e) : null;
|
|
2416
2536
|
}
|
|
2417
|
-
function
|
|
2537
|
+
function he(n, t, e) {
|
|
2418
2538
|
try {
|
|
2419
|
-
const s =
|
|
2420
|
-
return
|
|
2539
|
+
const s = Yt(n);
|
|
2540
|
+
return Bt(s, t, e).elements || [];
|
|
2421
2541
|
} catch (s) {
|
|
2422
2542
|
return console.error("Failed to resolve SEQL Selector:", s), [];
|
|
2423
2543
|
}
|
|
2424
2544
|
}
|
|
2425
|
-
const
|
|
2545
|
+
const te = /* @__PURE__ */ new Set([
|
|
2426
2546
|
"script",
|
|
2427
2547
|
"style",
|
|
2428
2548
|
"noscript",
|
|
@@ -2432,11 +2552,11 @@ const jt = /* @__PURE__ */ new Set([
|
|
|
2432
2552
|
"title"
|
|
2433
2553
|
]);
|
|
2434
2554
|
function W(n) {
|
|
2435
|
-
return n.id && !
|
|
2555
|
+
return n.id && !D(n.id) ? 3 : n.hasAttribute("role") || n.hasAttribute("aria-label") || n.hasAttribute("aria-labelledby") || n.hasAttribute("data-testid") || n.hasAttribute("data-qa") || n.hasAttribute("data-test") ? 2 : 1;
|
|
2436
2556
|
}
|
|
2437
|
-
function
|
|
2557
|
+
function at(n, t) {
|
|
2438
2558
|
const e = n.tagName.toLowerCase();
|
|
2439
|
-
return !!(
|
|
2559
|
+
return !!(te.has(e) || t && W(n) === 1 && ![
|
|
2440
2560
|
"form",
|
|
2441
2561
|
"main",
|
|
2442
2562
|
"nav",
|
|
@@ -2452,27 +2572,27 @@ function rt(n, t) {
|
|
|
2452
2572
|
"textarea"
|
|
2453
2573
|
].includes(e));
|
|
2454
2574
|
}
|
|
2455
|
-
function
|
|
2575
|
+
function it(n) {
|
|
2456
2576
|
return [...n].sort((t, e) => {
|
|
2457
2577
|
const s = W(t);
|
|
2458
2578
|
return W(e) - s;
|
|
2459
2579
|
});
|
|
2460
2580
|
}
|
|
2461
|
-
function
|
|
2581
|
+
function ue(n = {}) {
|
|
2462
2582
|
const t = performance.now(), {
|
|
2463
2583
|
root: e = typeof document < "u" ? document.body : void 0,
|
|
2464
2584
|
filter: s = "*",
|
|
2465
2585
|
limit: r = 1 / 0,
|
|
2466
|
-
onProgress:
|
|
2467
|
-
progressInterval:
|
|
2586
|
+
onProgress: a,
|
|
2587
|
+
progressInterval: i = 100,
|
|
2468
2588
|
skipNonSemantic: o = !0,
|
|
2469
2589
|
generatorOptions: l = {},
|
|
2470
|
-
cache:
|
|
2471
|
-
signal:
|
|
2590
|
+
cache: u,
|
|
2591
|
+
signal: d
|
|
2472
2592
|
} = n;
|
|
2473
2593
|
if (!e)
|
|
2474
2594
|
throw new Error("Root element or document is required");
|
|
2475
|
-
const
|
|
2595
|
+
const c = u ?? Q(), h = { ...l, cache: c };
|
|
2476
2596
|
let g;
|
|
2477
2597
|
try {
|
|
2478
2598
|
e instanceof Document, g = Array.from(e.querySelectorAll(s));
|
|
@@ -2491,148 +2611,148 @@ function te(n = {}) {
|
|
|
2491
2611
|
}
|
|
2492
2612
|
};
|
|
2493
2613
|
}
|
|
2494
|
-
const
|
|
2495
|
-
(
|
|
2496
|
-
),
|
|
2497
|
-
let
|
|
2498
|
-
const A =
|
|
2499
|
-
let
|
|
2500
|
-
for (let
|
|
2501
|
-
const
|
|
2502
|
-
if (
|
|
2503
|
-
|
|
2504
|
-
element:
|
|
2505
|
-
eid:
|
|
2614
|
+
const f = g.filter(
|
|
2615
|
+
(x) => !at(x, o)
|
|
2616
|
+
), m = it(f).slice(0, r), b = [], y = [];
|
|
2617
|
+
let v = 0;
|
|
2618
|
+
const A = m.length;
|
|
2619
|
+
let S = 0;
|
|
2620
|
+
for (let x = 0; x < m.length && !d?.aborted; x++) {
|
|
2621
|
+
const T = m[x], R = c.getEID(T);
|
|
2622
|
+
if (R)
|
|
2623
|
+
b.push({
|
|
2624
|
+
element: T,
|
|
2625
|
+
eid: R,
|
|
2506
2626
|
generationTimeMs: 0
|
|
2507
2627
|
// Cached, no generation time
|
|
2508
2628
|
});
|
|
2509
2629
|
else {
|
|
2510
2630
|
const z = performance.now();
|
|
2511
2631
|
try {
|
|
2512
|
-
const
|
|
2513
|
-
|
|
2514
|
-
element:
|
|
2515
|
-
eid:
|
|
2516
|
-
generationTimeMs:
|
|
2517
|
-
}) :
|
|
2518
|
-
} catch (
|
|
2632
|
+
const P = Z(T, h), ot = performance.now() - z;
|
|
2633
|
+
P ? b.push({
|
|
2634
|
+
element: T,
|
|
2635
|
+
eid: P,
|
|
2636
|
+
generationTimeMs: ot
|
|
2637
|
+
}) : v++;
|
|
2638
|
+
} catch (P) {
|
|
2519
2639
|
y.push({
|
|
2520
|
-
element:
|
|
2521
|
-
error:
|
|
2640
|
+
element: T,
|
|
2641
|
+
error: P instanceof Error ? P.message : String(P)
|
|
2522
2642
|
});
|
|
2523
2643
|
}
|
|
2524
2644
|
}
|
|
2525
|
-
|
|
2645
|
+
a && x - S >= i && (a(x + 1, A), S = x);
|
|
2526
2646
|
}
|
|
2527
|
-
|
|
2528
|
-
const
|
|
2647
|
+
a && a(A, A);
|
|
2648
|
+
const $ = performance.now() - t, M = c.getStats(), H = M.eidHits + M.eidMisses + M.selectorHits + M.selectorMisses, E = M.eidHits + M.selectorHits, C = H > 0 ? E / H : 0;
|
|
2529
2649
|
return {
|
|
2530
|
-
results:
|
|
2650
|
+
results: b,
|
|
2531
2651
|
failed: y,
|
|
2532
2652
|
stats: {
|
|
2533
2653
|
totalElements: A,
|
|
2534
|
-
successful:
|
|
2654
|
+
successful: b.length,
|
|
2535
2655
|
failed: y.length,
|
|
2536
|
-
skipped:
|
|
2537
|
-
totalTimeMs:
|
|
2538
|
-
avgTimePerElementMs:
|
|
2539
|
-
cacheHitRate:
|
|
2656
|
+
skipped: v,
|
|
2657
|
+
totalTimeMs: $,
|
|
2658
|
+
avgTimePerElementMs: b.length > 0 ? $ / b.length : 0,
|
|
2659
|
+
cacheHitRate: C
|
|
2540
2660
|
}
|
|
2541
2661
|
};
|
|
2542
2662
|
}
|
|
2543
|
-
function
|
|
2663
|
+
function de(n, t = {}) {
|
|
2544
2664
|
const e = performance.now(), {
|
|
2545
2665
|
limit: s = 1 / 0,
|
|
2546
2666
|
onProgress: r,
|
|
2547
|
-
progressInterval:
|
|
2548
|
-
skipNonSemantic:
|
|
2667
|
+
progressInterval: a = 100,
|
|
2668
|
+
skipNonSemantic: i = !0,
|
|
2549
2669
|
generatorOptions: o = {},
|
|
2550
2670
|
cache: l,
|
|
2551
|
-
signal:
|
|
2552
|
-
} = t,
|
|
2553
|
-
(
|
|
2554
|
-
),
|
|
2555
|
-
let
|
|
2556
|
-
const y =
|
|
2557
|
-
let
|
|
2558
|
-
for (let
|
|
2559
|
-
const
|
|
2560
|
-
if (
|
|
2561
|
-
|
|
2562
|
-
element:
|
|
2563
|
-
eid:
|
|
2671
|
+
signal: u
|
|
2672
|
+
} = t, d = l ?? Q(), c = { ...o, cache: d }, h = n.filter(
|
|
2673
|
+
(E) => !at(E, i)
|
|
2674
|
+
), f = it(h).slice(0, s), p = [], m = [];
|
|
2675
|
+
let b = 0;
|
|
2676
|
+
const y = f.length;
|
|
2677
|
+
let v = 0;
|
|
2678
|
+
for (let E = 0; E < f.length && !u?.aborted; E++) {
|
|
2679
|
+
const C = f[E], x = d.getEID(C);
|
|
2680
|
+
if (x)
|
|
2681
|
+
p.push({
|
|
2682
|
+
element: C,
|
|
2683
|
+
eid: x,
|
|
2564
2684
|
generationTimeMs: 0
|
|
2565
2685
|
});
|
|
2566
2686
|
else {
|
|
2567
|
-
const
|
|
2687
|
+
const T = performance.now();
|
|
2568
2688
|
try {
|
|
2569
|
-
const
|
|
2570
|
-
|
|
2571
|
-
element:
|
|
2572
|
-
eid:
|
|
2689
|
+
const R = Z(C, c), z = performance.now() - T;
|
|
2690
|
+
R ? p.push({
|
|
2691
|
+
element: C,
|
|
2692
|
+
eid: R,
|
|
2573
2693
|
generationTimeMs: z
|
|
2574
|
-
}) :
|
|
2575
|
-
} catch (
|
|
2576
|
-
|
|
2577
|
-
element:
|
|
2578
|
-
error:
|
|
2694
|
+
}) : b++;
|
|
2695
|
+
} catch (R) {
|
|
2696
|
+
m.push({
|
|
2697
|
+
element: C,
|
|
2698
|
+
error: R instanceof Error ? R.message : String(R)
|
|
2579
2699
|
});
|
|
2580
2700
|
}
|
|
2581
2701
|
}
|
|
2582
|
-
r &&
|
|
2702
|
+
r && E - v >= a && (r(E + 1, y), v = E);
|
|
2583
2703
|
}
|
|
2584
2704
|
r && r(y, y);
|
|
2585
|
-
const A = performance.now() - e,
|
|
2705
|
+
const A = performance.now() - e, S = d.getStats(), $ = S.eidHits + S.eidMisses + S.selectorHits + S.selectorMisses, M = S.eidHits + S.selectorHits, H = $ > 0 ? M / $ : 0;
|
|
2586
2706
|
return {
|
|
2587
|
-
results:
|
|
2588
|
-
failed:
|
|
2707
|
+
results: p,
|
|
2708
|
+
failed: m,
|
|
2589
2709
|
stats: {
|
|
2590
2710
|
totalElements: y,
|
|
2591
|
-
successful:
|
|
2592
|
-
failed:
|
|
2593
|
-
skipped:
|
|
2711
|
+
successful: p.length,
|
|
2712
|
+
failed: m.length,
|
|
2713
|
+
skipped: b,
|
|
2594
2714
|
totalTimeMs: A,
|
|
2595
|
-
avgTimePerElementMs:
|
|
2596
|
-
cacheHitRate:
|
|
2715
|
+
avgTimePerElementMs: p.length > 0 ? A / p.length : 0,
|
|
2716
|
+
cacheHitRate: H
|
|
2597
2717
|
}
|
|
2598
2718
|
};
|
|
2599
2719
|
}
|
|
2600
2720
|
export {
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2721
|
+
ft as AnchorFinder,
|
|
2722
|
+
jt as ConstraintsEvaluator,
|
|
2723
|
+
st as CssGenerator,
|
|
2724
|
+
ut as DEFAULT_GENERATOR_OPTIONS,
|
|
2725
|
+
dt as DEFAULT_RESOLVER_OPTIONS,
|
|
2726
|
+
Lt as EIDCache,
|
|
2727
|
+
ee as EID_VERSION,
|
|
2728
|
+
Wt as FallbackHandler,
|
|
2729
|
+
se as MAX_PATH_DEPTH,
|
|
2730
|
+
xt as PathBuilder,
|
|
2731
|
+
X as ROLE_ANCHOR_VALUES,
|
|
2732
|
+
Y as SEMANTIC_ANCHOR_TAGS,
|
|
2733
|
+
re as SEMANTIC_ATTRIBUTES,
|
|
2734
|
+
lt as SEMANTIC_TAGS,
|
|
2735
|
+
Pt as SemanticExtractor,
|
|
2736
|
+
Ft as SemanticsMatcher,
|
|
2737
|
+
_t as SvgFingerprinter,
|
|
2738
|
+
kt as calculateConfidence,
|
|
2739
|
+
ae as calculateElementScore,
|
|
2740
|
+
Ot as createEIDCache,
|
|
2741
|
+
At as filterClasses,
|
|
2742
|
+
Z as generateEID,
|
|
2743
|
+
ue as generateEIDBatch,
|
|
2744
|
+
de as generateEIDForElements,
|
|
2745
|
+
le as generateSEQL,
|
|
2746
|
+
ne as getClassScore,
|
|
2747
|
+
Q as getGlobalCache,
|
|
2748
|
+
ce as isEID,
|
|
2749
|
+
K as isUtilityClass,
|
|
2750
|
+
V as normalizeText,
|
|
2751
|
+
Yt as parseSEQL,
|
|
2752
|
+
ie as resetGlobalCache,
|
|
2753
|
+
Bt as resolve,
|
|
2754
|
+
he as resolveSEQL,
|
|
2755
|
+
Zt as stringifySEQL,
|
|
2756
|
+
oe as validateEID
|
|
2637
2757
|
};
|
|
2638
2758
|
//# sourceMappingURL=seql-js.js.map
|