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