@usertour/helpers 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/globals.d.cts +1 -1
- package/dist/globals.d.ts +1 -1
- package/dist/index.cjs +2 -913
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +17 -68
- package/package.json +7 -10
- package/dist/chunk-7IK5Q5N2.js +0 -591
- package/dist/chunk-DEG6MTU7.js +0 -318
- package/dist/chunk-Y6FPPOKF.js +0 -28
- package/dist/conditions.cjs +0 -1001
- package/dist/conditions.d.cts +0 -23
- package/dist/conditions.d.ts +0 -23
- package/dist/conditions.js +0 -45
- package/dist/finderx.cjs +0 -346
- package/dist/finderx.d.cts +0 -47
- package/dist/finderx.d.ts +0 -47
- package/dist/finderx.js +0 -15
- package/dist/listener.cjs +0 -68
- package/dist/listener.d.cts +0 -7
- package/dist/listener.d.ts +0 -7
- package/dist/listener.js +0 -16
package/dist/chunk-DEG6MTU7.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
// src/finderx.ts
|
|
2
|
-
import { finder as finderLib } from "@medv/finder";
|
|
3
|
-
var finderAttrs = [
|
|
4
|
-
"data-for",
|
|
5
|
-
"data-id",
|
|
6
|
-
"data-testid",
|
|
7
|
-
"data-test-id",
|
|
8
|
-
"for",
|
|
9
|
-
"id",
|
|
10
|
-
"name",
|
|
11
|
-
"placeholder",
|
|
12
|
-
"role"
|
|
13
|
-
];
|
|
14
|
-
var defaultConfig = {
|
|
15
|
-
idName: () => false,
|
|
16
|
-
className: () => false,
|
|
17
|
-
tagName: () => false,
|
|
18
|
-
attr: () => false,
|
|
19
|
-
seedMinLength: 1,
|
|
20
|
-
optimizedMinLength: 2,
|
|
21
|
-
threshold: 1e3,
|
|
22
|
-
maxNumberOfTries: 1e4
|
|
23
|
-
};
|
|
24
|
-
var finderConfigs = [
|
|
25
|
-
{
|
|
26
|
-
...defaultConfig,
|
|
27
|
-
tagName: () => true
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
...defaultConfig,
|
|
31
|
-
idName: () => true
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
...defaultConfig,
|
|
35
|
-
tagName: () => true,
|
|
36
|
-
attr: (name) => finderAttrs.includes(name)
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
...defaultConfig,
|
|
40
|
-
className: () => true,
|
|
41
|
-
attr: (name) => finderAttrs.includes(name)
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
...defaultConfig,
|
|
45
|
-
tagName: () => true,
|
|
46
|
-
idName: () => true,
|
|
47
|
-
className: () => true,
|
|
48
|
-
attr: () => false
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
...defaultConfig,
|
|
52
|
-
tagName: () => true,
|
|
53
|
-
idName: () => true,
|
|
54
|
-
className: () => true,
|
|
55
|
-
attr: (name) => finderAttrs.includes(name)
|
|
56
|
-
}
|
|
57
|
-
];
|
|
58
|
-
function getMaxDepth(node) {
|
|
59
|
-
if (node.parentNode) {
|
|
60
|
-
return getMaxDepth(node.parentNode);
|
|
61
|
-
}
|
|
62
|
-
return node.depth;
|
|
63
|
-
}
|
|
64
|
-
function queryNodeListBySelectors(selectors, rootDocument, removeRepeat = true) {
|
|
65
|
-
const nodes = [];
|
|
66
|
-
if (!selectors) {
|
|
67
|
-
return nodes;
|
|
68
|
-
}
|
|
69
|
-
for (const s of selectors) {
|
|
70
|
-
const els = rootDocument.querySelectorAll(s.replace(/\\\\/g, "\\"));
|
|
71
|
-
if (els && els.length > 0) {
|
|
72
|
-
nodes.push(...Array.from(els));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return removeRepeat ? [...new Set(nodes)] : nodes;
|
|
76
|
-
}
|
|
77
|
-
function findMostRecurringNode(nodes) {
|
|
78
|
-
const m = /* @__PURE__ */ new Map();
|
|
79
|
-
let finalNode = nodes[0];
|
|
80
|
-
let count = 0;
|
|
81
|
-
for (const node of nodes) {
|
|
82
|
-
const i = m.get(node) ? m.get(node) + 1 : 1;
|
|
83
|
-
m.set(node, i);
|
|
84
|
-
}
|
|
85
|
-
m.forEach((value, key) => {
|
|
86
|
-
if (value > count) {
|
|
87
|
-
count = value;
|
|
88
|
-
finalNode = key;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return finalNode;
|
|
92
|
-
}
|
|
93
|
-
function compareParentNode(node, el, rootDocument, isCompareSibings = false) {
|
|
94
|
-
let nodeParentNode = node.parentNode;
|
|
95
|
-
let elParentElement = el.parentElement;
|
|
96
|
-
const maxDepth = getMaxDepth(node);
|
|
97
|
-
const xresult = {
|
|
98
|
-
maxDepth,
|
|
99
|
-
failedDepth: 0,
|
|
100
|
-
success: true
|
|
101
|
-
};
|
|
102
|
-
while (nodeParentNode && elParentElement) {
|
|
103
|
-
if (elParentElement === rootDocument) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
if (elParentElement === document.body || elParentElement === document.documentElement || elParentElement.parentElement === document.body) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
const parentNodes = queryNodeListBySelectors(nodeParentNode.selectors, rootDocument);
|
|
110
|
-
const isMatchSibings = isCompareSibings ? compareSibingsNode(nodeParentNode, elParentElement, rootDocument) : true;
|
|
111
|
-
if (!parentNodes || parentNodes.length === 0 || !parentNodes.includes(elParentElement) || !isMatchSibings) {
|
|
112
|
-
xresult.failedDepth = nodeParentNode.depth;
|
|
113
|
-
xresult.success = false;
|
|
114
|
-
}
|
|
115
|
-
nodeParentNode = nodeParentNode.parentNode;
|
|
116
|
-
elParentElement = elParentElement.parentElement;
|
|
117
|
-
}
|
|
118
|
-
return xresult;
|
|
119
|
-
}
|
|
120
|
-
function compareSibingsNode(node, el, rootDocument) {
|
|
121
|
-
let isMatchNext = true;
|
|
122
|
-
let isMatchPrevious = true;
|
|
123
|
-
const { previousElementSelectors, nextElementSelectors } = node;
|
|
124
|
-
if (nextElementSelectors && nextElementSelectors.length > 0) {
|
|
125
|
-
const nextElementSiblings = queryNodeListBySelectors(nextElementSelectors, rootDocument);
|
|
126
|
-
isMatchNext = el.nextElementSibling && nextElementSiblings.includes(el.nextElementSibling);
|
|
127
|
-
}
|
|
128
|
-
if (previousElementSelectors && previousElementSelectors.length > 0) {
|
|
129
|
-
const previousElementSiblings = queryNodeListBySelectors(
|
|
130
|
-
previousElementSelectors,
|
|
131
|
-
rootDocument
|
|
132
|
-
);
|
|
133
|
-
isMatchPrevious = el.previousElementSibling && previousElementSiblings.includes(el.previousElementSibling);
|
|
134
|
-
}
|
|
135
|
-
return isMatchNext && isMatchPrevious;
|
|
136
|
-
}
|
|
137
|
-
function queryElementSelectors(input) {
|
|
138
|
-
const classes = Array.from(input.classList);
|
|
139
|
-
const selectors = [];
|
|
140
|
-
const configs = [...finderConfigs];
|
|
141
|
-
for (const className of classes) {
|
|
142
|
-
configs.push({
|
|
143
|
-
...defaultConfig,
|
|
144
|
-
className: (name) => {
|
|
145
|
-
if (classes.filter((cn) => cn !== className).includes(name)) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
for (const cfg of configs) {
|
|
154
|
-
selectors.push(finder(input, cfg));
|
|
155
|
-
}
|
|
156
|
-
} catch (_) {
|
|
157
|
-
return selectors;
|
|
158
|
-
}
|
|
159
|
-
return [...new Set(selectors)];
|
|
160
|
-
}
|
|
161
|
-
function parseSelectorsTree(input, parentNode, depth = 0) {
|
|
162
|
-
const selectors = queryElementSelectors(input);
|
|
163
|
-
if (selectors.length === 0) {
|
|
164
|
-
return parentNode;
|
|
165
|
-
}
|
|
166
|
-
const currentNode = {
|
|
167
|
-
previousElementSelectors: [],
|
|
168
|
-
nextElementSelectors: [],
|
|
169
|
-
selectors,
|
|
170
|
-
depth
|
|
171
|
-
};
|
|
172
|
-
if (input.previousElementSibling) {
|
|
173
|
-
currentNode.previousElementSelectors = queryElementSelectors(input.previousElementSibling);
|
|
174
|
-
}
|
|
175
|
-
if (input.nextElementSibling) {
|
|
176
|
-
currentNode.nextElementSelectors = queryElementSelectors(input.nextElementSibling);
|
|
177
|
-
}
|
|
178
|
-
if (parentNode === null) {
|
|
179
|
-
if (input.parentElement) {
|
|
180
|
-
parseSelectorsTree(input.parentElement, currentNode, depth + 1);
|
|
181
|
-
}
|
|
182
|
-
return currentNode;
|
|
183
|
-
}
|
|
184
|
-
parentNode.parentNode = currentNode;
|
|
185
|
-
if (input.parentElement) {
|
|
186
|
-
parseSelectorsTree(input.parentElement, currentNode, depth + 1);
|
|
187
|
-
}
|
|
188
|
-
return parentNode;
|
|
189
|
-
}
|
|
190
|
-
function finderMostPrecisionElement(elements, node, rootDocument, precision) {
|
|
191
|
-
const successEls = [];
|
|
192
|
-
let failedData = {
|
|
193
|
-
el: null,
|
|
194
|
-
failedDepth: 0,
|
|
195
|
-
maxDepth: 0
|
|
196
|
-
};
|
|
197
|
-
for (const el of elements) {
|
|
198
|
-
const { success, failedDepth, maxDepth } = compareParentNode(node, el, rootDocument);
|
|
199
|
-
if (success) {
|
|
200
|
-
successEls.push(el);
|
|
201
|
-
} else if (!failedData.el || failedDepth > failedData.failedDepth) {
|
|
202
|
-
failedData = { el, failedDepth, maxDepth };
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (successEls.length === 1) {
|
|
206
|
-
return successEls[0];
|
|
207
|
-
}
|
|
208
|
-
if (successEls.length > 1) {
|
|
209
|
-
let tempEl = successEls[0];
|
|
210
|
-
let tempFailedDepth = 0;
|
|
211
|
-
for (const el of successEls) {
|
|
212
|
-
const { success, failedDepth } = compareParentNode(node, el, rootDocument, true);
|
|
213
|
-
if (success) {
|
|
214
|
-
return el;
|
|
215
|
-
}
|
|
216
|
-
if (failedDepth > tempFailedDepth) {
|
|
217
|
-
tempFailedDepth = failedDepth;
|
|
218
|
-
tempEl = el;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return tempEl;
|
|
222
|
-
}
|
|
223
|
-
if (failedData.el) {
|
|
224
|
-
const { failedDepth, maxDepth, el } = failedData;
|
|
225
|
-
const rate = (failedDepth - 1) / maxDepth * 10;
|
|
226
|
-
if (rate >= precision) {
|
|
227
|
-
return el;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
function finder(input, options) {
|
|
233
|
-
return finderLib(input, options);
|
|
234
|
-
}
|
|
235
|
-
function parserX(input) {
|
|
236
|
-
return parseSelectorsTree(input, null);
|
|
237
|
-
}
|
|
238
|
-
function parserV2(element) {
|
|
239
|
-
var _a;
|
|
240
|
-
const content = (_a = element.innerText) != null ? _a : "";
|
|
241
|
-
const selectors = parseSelectorsTree(element, null);
|
|
242
|
-
const selectorsList = queryElementSelectors(element);
|
|
243
|
-
return { content, selectors, selectorsList };
|
|
244
|
-
}
|
|
245
|
-
function finderV2(target, root) {
|
|
246
|
-
const {
|
|
247
|
-
selectors,
|
|
248
|
-
content = "",
|
|
249
|
-
sequence = 0,
|
|
250
|
-
precision = "strict",
|
|
251
|
-
isDynamicContent = false,
|
|
252
|
-
customSelector = "",
|
|
253
|
-
type = "auto"
|
|
254
|
-
} = target;
|
|
255
|
-
if (type === "auto") {
|
|
256
|
-
const mapping = {
|
|
257
|
-
looser: 1,
|
|
258
|
-
loose: 3,
|
|
259
|
-
loosest: 5,
|
|
260
|
-
strict: 7,
|
|
261
|
-
stricter: 8,
|
|
262
|
-
strictest: 10
|
|
263
|
-
};
|
|
264
|
-
const el = finderX(selectors, root, mapping[precision]);
|
|
265
|
-
if (el) {
|
|
266
|
-
if (isDynamicContent && content && el.innerText !== content) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
return el;
|
|
270
|
-
}
|
|
271
|
-
} else {
|
|
272
|
-
const sequenceMapping = {
|
|
273
|
-
"1st": 0,
|
|
274
|
-
"2st": 1,
|
|
275
|
-
"3st": 2,
|
|
276
|
-
"4st": 3,
|
|
277
|
-
"5st": 4
|
|
278
|
-
};
|
|
279
|
-
if (customSelector) {
|
|
280
|
-
const selector = customSelector.replace(/\\\\/g, "\\");
|
|
281
|
-
const els = root.querySelectorAll(selector);
|
|
282
|
-
if (els.length > 0) {
|
|
283
|
-
const el = els[sequenceMapping[sequence]] || els[0];
|
|
284
|
-
if (content && el.innerText.trim() !== content) {
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
return el;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
function finderX(node, root, precision = 10) {
|
|
294
|
-
if (!node || node.selectors.length === 0) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
const rootDocument = root || document;
|
|
298
|
-
const elements = [];
|
|
299
|
-
const nodeList = queryNodeListBySelectors(node.selectors, rootDocument, false);
|
|
300
|
-
if (!nodeList || nodeList.length === 0) {
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
if ([...new Set(nodeList)].length !== nodeList.length) {
|
|
304
|
-
const el = findMostRecurringNode(nodeList);
|
|
305
|
-
elements.push(el);
|
|
306
|
-
} else {
|
|
307
|
-
elements.push(...nodeList);
|
|
308
|
-
}
|
|
309
|
-
return finderMostPrecisionElement(elements, node, rootDocument, precision);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export {
|
|
313
|
-
finder,
|
|
314
|
-
parserX,
|
|
315
|
-
parserV2,
|
|
316
|
-
finderV2,
|
|
317
|
-
finderX
|
|
318
|
-
};
|
package/dist/chunk-Y6FPPOKF.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
navigator,
|
|
3
|
-
win
|
|
4
|
-
} from "./chunk-H7VA3ML2.js";
|
|
5
|
-
|
|
6
|
-
// src/listener.ts
|
|
7
|
-
var noop = () => {
|
|
8
|
-
};
|
|
9
|
-
function on(obj, ...args) {
|
|
10
|
-
if (obj == null ? void 0 : obj.addEventListener) {
|
|
11
|
-
obj.addEventListener(...args);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function off(obj, ...args) {
|
|
15
|
-
if (obj == null ? void 0 : obj.removeEventListener) {
|
|
16
|
-
obj.removeEventListener(...args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
var isBrowser = typeof win !== "undefined";
|
|
20
|
-
var isNavigator = typeof navigator !== "undefined";
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
noop,
|
|
24
|
-
on,
|
|
25
|
-
off,
|
|
26
|
-
isBrowser,
|
|
27
|
-
isNavigator
|
|
28
|
-
};
|