@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/conditions.d.cts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ContentPriority, RulesCondition, RulesType, SDKContent, BizEvent, BizSession } from '@usertour/types';
|
|
2
|
-
|
|
3
|
-
declare const PRIORITIES: ContentPriority[];
|
|
4
|
-
declare const isVisible: (el: HTMLElement) => Promise<boolean>;
|
|
5
|
-
type RewriteRulesCondition = Partial<Record<RulesType, boolean>>;
|
|
6
|
-
declare const activedRulesConditions: (conditions: RulesCondition[], rewrite?: RewriteRulesCondition) => Promise<RulesCondition[]>;
|
|
7
|
-
declare const activedContentRulesConditions: (conditions: RulesCondition[], contents: SDKContent[]) => Promise<RulesCondition[]>;
|
|
8
|
-
declare const activedContentCondition: (contents: SDKContent[]) => Promise<SDKContent[]>;
|
|
9
|
-
declare const isActive: (autoStartRules: RulesCondition[]) => boolean;
|
|
10
|
-
declare const isActiveContent: (content: SDKContent) => boolean;
|
|
11
|
-
declare const filterAutoStartContent: (contents: SDKContent[], type: string) => SDKContent[];
|
|
12
|
-
declare const isHasActivedContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
|
|
13
|
-
declare const isSameContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
|
|
14
|
-
declare const findLatestEvent: (bizEvents: BizEvent[]) => BizEvent;
|
|
15
|
-
declare const checklistIsDimissed: (latestSession?: BizSession) => BizEvent | undefined;
|
|
16
|
-
declare const flowIsDismissed: (latestSession?: BizSession) => BizEvent | undefined;
|
|
17
|
-
declare const flowIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
|
|
18
|
-
declare const checklistIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
|
|
19
|
-
declare const isValidContent: (content: SDKContent, contents: SDKContent[]) => boolean;
|
|
20
|
-
declare const parseUrlParams: (url: string, paramName: string) => string | null;
|
|
21
|
-
declare const wait: (seconds: number) => Promise<void>;
|
|
22
|
-
|
|
23
|
-
export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isHasActivedContents, isSameContents, isValidContent, isVisible, parseUrlParams, wait };
|
package/dist/conditions.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ContentPriority, RulesCondition, RulesType, SDKContent, BizEvent, BizSession } from '@usertour/types';
|
|
2
|
-
|
|
3
|
-
declare const PRIORITIES: ContentPriority[];
|
|
4
|
-
declare const isVisible: (el: HTMLElement) => Promise<boolean>;
|
|
5
|
-
type RewriteRulesCondition = Partial<Record<RulesType, boolean>>;
|
|
6
|
-
declare const activedRulesConditions: (conditions: RulesCondition[], rewrite?: RewriteRulesCondition) => Promise<RulesCondition[]>;
|
|
7
|
-
declare const activedContentRulesConditions: (conditions: RulesCondition[], contents: SDKContent[]) => Promise<RulesCondition[]>;
|
|
8
|
-
declare const activedContentCondition: (contents: SDKContent[]) => Promise<SDKContent[]>;
|
|
9
|
-
declare const isActive: (autoStartRules: RulesCondition[]) => boolean;
|
|
10
|
-
declare const isActiveContent: (content: SDKContent) => boolean;
|
|
11
|
-
declare const filterAutoStartContent: (contents: SDKContent[], type: string) => SDKContent[];
|
|
12
|
-
declare const isHasActivedContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
|
|
13
|
-
declare const isSameContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
|
|
14
|
-
declare const findLatestEvent: (bizEvents: BizEvent[]) => BizEvent;
|
|
15
|
-
declare const checklistIsDimissed: (latestSession?: BizSession) => BizEvent | undefined;
|
|
16
|
-
declare const flowIsDismissed: (latestSession?: BizSession) => BizEvent | undefined;
|
|
17
|
-
declare const flowIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
|
|
18
|
-
declare const checklistIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
|
|
19
|
-
declare const isValidContent: (content: SDKContent, contents: SDKContent[]) => boolean;
|
|
20
|
-
declare const parseUrlParams: (url: string, paramName: string) => string | null;
|
|
21
|
-
declare const wait: (seconds: number) => Promise<void>;
|
|
22
|
-
|
|
23
|
-
export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isHasActivedContents, isSameContents, isValidContent, isVisible, parseUrlParams, wait };
|
package/dist/conditions.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PRIORITIES,
|
|
3
|
-
activedContentCondition,
|
|
4
|
-
activedContentRulesConditions,
|
|
5
|
-
activedRulesConditions,
|
|
6
|
-
checklistIsDimissed,
|
|
7
|
-
checklistIsSeen,
|
|
8
|
-
filterAutoStartContent,
|
|
9
|
-
findLatestEvent,
|
|
10
|
-
flowIsDismissed,
|
|
11
|
-
flowIsSeen,
|
|
12
|
-
isActive,
|
|
13
|
-
isActiveContent,
|
|
14
|
-
isHasActivedContents,
|
|
15
|
-
isSameContents,
|
|
16
|
-
isValidContent,
|
|
17
|
-
isVisible,
|
|
18
|
-
parseUrlParams,
|
|
19
|
-
wait
|
|
20
|
-
} from "./chunk-7IK5Q5N2.js";
|
|
21
|
-
import "./chunk-DEG6MTU7.js";
|
|
22
|
-
import "./chunk-Y6FPPOKF.js";
|
|
23
|
-
import "./chunk-H7VA3ML2.js";
|
|
24
|
-
import "./chunk-FNQIIEWK.js";
|
|
25
|
-
import "./chunk-XEO3YXBM.js";
|
|
26
|
-
export {
|
|
27
|
-
PRIORITIES,
|
|
28
|
-
activedContentCondition,
|
|
29
|
-
activedContentRulesConditions,
|
|
30
|
-
activedRulesConditions,
|
|
31
|
-
checklistIsDimissed,
|
|
32
|
-
checklistIsSeen,
|
|
33
|
-
filterAutoStartContent,
|
|
34
|
-
findLatestEvent,
|
|
35
|
-
flowIsDismissed,
|
|
36
|
-
flowIsSeen,
|
|
37
|
-
isActive,
|
|
38
|
-
isActiveContent,
|
|
39
|
-
isHasActivedContents,
|
|
40
|
-
isSameContents,
|
|
41
|
-
isValidContent,
|
|
42
|
-
isVisible,
|
|
43
|
-
parseUrlParams,
|
|
44
|
-
wait
|
|
45
|
-
};
|
package/dist/finderx.cjs
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/finderx.ts
|
|
21
|
-
var finderx_exports = {};
|
|
22
|
-
__export(finderx_exports, {
|
|
23
|
-
finder: () => finder,
|
|
24
|
-
finderV2: () => finderV2,
|
|
25
|
-
finderX: () => finderX,
|
|
26
|
-
parserV2: () => parserV2,
|
|
27
|
-
parserX: () => parserX
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(finderx_exports);
|
|
30
|
-
var import_finder = require("@medv/finder");
|
|
31
|
-
var finderAttrs = [
|
|
32
|
-
"data-for",
|
|
33
|
-
"data-id",
|
|
34
|
-
"data-testid",
|
|
35
|
-
"data-test-id",
|
|
36
|
-
"for",
|
|
37
|
-
"id",
|
|
38
|
-
"name",
|
|
39
|
-
"placeholder",
|
|
40
|
-
"role"
|
|
41
|
-
];
|
|
42
|
-
var defaultConfig = {
|
|
43
|
-
idName: () => false,
|
|
44
|
-
className: () => false,
|
|
45
|
-
tagName: () => false,
|
|
46
|
-
attr: () => false,
|
|
47
|
-
seedMinLength: 1,
|
|
48
|
-
optimizedMinLength: 2,
|
|
49
|
-
threshold: 1e3,
|
|
50
|
-
maxNumberOfTries: 1e4
|
|
51
|
-
};
|
|
52
|
-
var finderConfigs = [
|
|
53
|
-
{
|
|
54
|
-
...defaultConfig,
|
|
55
|
-
tagName: () => true
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
...defaultConfig,
|
|
59
|
-
idName: () => true
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
...defaultConfig,
|
|
63
|
-
tagName: () => true,
|
|
64
|
-
attr: (name) => finderAttrs.includes(name)
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
...defaultConfig,
|
|
68
|
-
className: () => true,
|
|
69
|
-
attr: (name) => finderAttrs.includes(name)
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
...defaultConfig,
|
|
73
|
-
tagName: () => true,
|
|
74
|
-
idName: () => true,
|
|
75
|
-
className: () => true,
|
|
76
|
-
attr: () => false
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
...defaultConfig,
|
|
80
|
-
tagName: () => true,
|
|
81
|
-
idName: () => true,
|
|
82
|
-
className: () => true,
|
|
83
|
-
attr: (name) => finderAttrs.includes(name)
|
|
84
|
-
}
|
|
85
|
-
];
|
|
86
|
-
function getMaxDepth(node) {
|
|
87
|
-
if (node.parentNode) {
|
|
88
|
-
return getMaxDepth(node.parentNode);
|
|
89
|
-
}
|
|
90
|
-
return node.depth;
|
|
91
|
-
}
|
|
92
|
-
function queryNodeListBySelectors(selectors, rootDocument, removeRepeat = true) {
|
|
93
|
-
const nodes = [];
|
|
94
|
-
if (!selectors) {
|
|
95
|
-
return nodes;
|
|
96
|
-
}
|
|
97
|
-
for (const s of selectors) {
|
|
98
|
-
const els = rootDocument.querySelectorAll(s.replace(/\\\\/g, "\\"));
|
|
99
|
-
if (els && els.length > 0) {
|
|
100
|
-
nodes.push(...Array.from(els));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return removeRepeat ? [...new Set(nodes)] : nodes;
|
|
104
|
-
}
|
|
105
|
-
function findMostRecurringNode(nodes) {
|
|
106
|
-
const m = /* @__PURE__ */ new Map();
|
|
107
|
-
let finalNode = nodes[0];
|
|
108
|
-
let count = 0;
|
|
109
|
-
for (const node of nodes) {
|
|
110
|
-
const i = m.get(node) ? m.get(node) + 1 : 1;
|
|
111
|
-
m.set(node, i);
|
|
112
|
-
}
|
|
113
|
-
m.forEach((value, key) => {
|
|
114
|
-
if (value > count) {
|
|
115
|
-
count = value;
|
|
116
|
-
finalNode = key;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
return finalNode;
|
|
120
|
-
}
|
|
121
|
-
function compareParentNode(node, el, rootDocument, isCompareSibings = false) {
|
|
122
|
-
let nodeParentNode = node.parentNode;
|
|
123
|
-
let elParentElement = el.parentElement;
|
|
124
|
-
const maxDepth = getMaxDepth(node);
|
|
125
|
-
const xresult = {
|
|
126
|
-
maxDepth,
|
|
127
|
-
failedDepth: 0,
|
|
128
|
-
success: true
|
|
129
|
-
};
|
|
130
|
-
while (nodeParentNode && elParentElement) {
|
|
131
|
-
if (elParentElement === rootDocument) {
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
if (elParentElement === document.body || elParentElement === document.documentElement || elParentElement.parentElement === document.body) {
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
const parentNodes = queryNodeListBySelectors(nodeParentNode.selectors, rootDocument);
|
|
138
|
-
const isMatchSibings = isCompareSibings ? compareSibingsNode(nodeParentNode, elParentElement, rootDocument) : true;
|
|
139
|
-
if (!parentNodes || parentNodes.length === 0 || !parentNodes.includes(elParentElement) || !isMatchSibings) {
|
|
140
|
-
xresult.failedDepth = nodeParentNode.depth;
|
|
141
|
-
xresult.success = false;
|
|
142
|
-
}
|
|
143
|
-
nodeParentNode = nodeParentNode.parentNode;
|
|
144
|
-
elParentElement = elParentElement.parentElement;
|
|
145
|
-
}
|
|
146
|
-
return xresult;
|
|
147
|
-
}
|
|
148
|
-
function compareSibingsNode(node, el, rootDocument) {
|
|
149
|
-
let isMatchNext = true;
|
|
150
|
-
let isMatchPrevious = true;
|
|
151
|
-
const { previousElementSelectors, nextElementSelectors } = node;
|
|
152
|
-
if (nextElementSelectors && nextElementSelectors.length > 0) {
|
|
153
|
-
const nextElementSiblings = queryNodeListBySelectors(nextElementSelectors, rootDocument);
|
|
154
|
-
isMatchNext = el.nextElementSibling && nextElementSiblings.includes(el.nextElementSibling);
|
|
155
|
-
}
|
|
156
|
-
if (previousElementSelectors && previousElementSelectors.length > 0) {
|
|
157
|
-
const previousElementSiblings = queryNodeListBySelectors(
|
|
158
|
-
previousElementSelectors,
|
|
159
|
-
rootDocument
|
|
160
|
-
);
|
|
161
|
-
isMatchPrevious = el.previousElementSibling && previousElementSiblings.includes(el.previousElementSibling);
|
|
162
|
-
}
|
|
163
|
-
return isMatchNext && isMatchPrevious;
|
|
164
|
-
}
|
|
165
|
-
function queryElementSelectors(input) {
|
|
166
|
-
const classes = Array.from(input.classList);
|
|
167
|
-
const selectors = [];
|
|
168
|
-
const configs = [...finderConfigs];
|
|
169
|
-
for (const className of classes) {
|
|
170
|
-
configs.push({
|
|
171
|
-
...defaultConfig,
|
|
172
|
-
className: (name) => {
|
|
173
|
-
if (classes.filter((cn) => cn !== className).includes(name)) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
try {
|
|
181
|
-
for (const cfg of configs) {
|
|
182
|
-
selectors.push(finder(input, cfg));
|
|
183
|
-
}
|
|
184
|
-
} catch (_) {
|
|
185
|
-
return selectors;
|
|
186
|
-
}
|
|
187
|
-
return [...new Set(selectors)];
|
|
188
|
-
}
|
|
189
|
-
function parseSelectorsTree(input, parentNode, depth = 0) {
|
|
190
|
-
const selectors = queryElementSelectors(input);
|
|
191
|
-
if (selectors.length === 0) {
|
|
192
|
-
return parentNode;
|
|
193
|
-
}
|
|
194
|
-
const currentNode = {
|
|
195
|
-
previousElementSelectors: [],
|
|
196
|
-
nextElementSelectors: [],
|
|
197
|
-
selectors,
|
|
198
|
-
depth
|
|
199
|
-
};
|
|
200
|
-
if (input.previousElementSibling) {
|
|
201
|
-
currentNode.previousElementSelectors = queryElementSelectors(input.previousElementSibling);
|
|
202
|
-
}
|
|
203
|
-
if (input.nextElementSibling) {
|
|
204
|
-
currentNode.nextElementSelectors = queryElementSelectors(input.nextElementSibling);
|
|
205
|
-
}
|
|
206
|
-
if (parentNode === null) {
|
|
207
|
-
if (input.parentElement) {
|
|
208
|
-
parseSelectorsTree(input.parentElement, currentNode, depth + 1);
|
|
209
|
-
}
|
|
210
|
-
return currentNode;
|
|
211
|
-
}
|
|
212
|
-
parentNode.parentNode = currentNode;
|
|
213
|
-
if (input.parentElement) {
|
|
214
|
-
parseSelectorsTree(input.parentElement, currentNode, depth + 1);
|
|
215
|
-
}
|
|
216
|
-
return parentNode;
|
|
217
|
-
}
|
|
218
|
-
function finderMostPrecisionElement(elements, node, rootDocument, precision) {
|
|
219
|
-
const successEls = [];
|
|
220
|
-
let failedData = {
|
|
221
|
-
el: null,
|
|
222
|
-
failedDepth: 0,
|
|
223
|
-
maxDepth: 0
|
|
224
|
-
};
|
|
225
|
-
for (const el of elements) {
|
|
226
|
-
const { success, failedDepth, maxDepth } = compareParentNode(node, el, rootDocument);
|
|
227
|
-
if (success) {
|
|
228
|
-
successEls.push(el);
|
|
229
|
-
} else if (!failedData.el || failedDepth > failedData.failedDepth) {
|
|
230
|
-
failedData = { el, failedDepth, maxDepth };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (successEls.length === 1) {
|
|
234
|
-
return successEls[0];
|
|
235
|
-
}
|
|
236
|
-
if (successEls.length > 1) {
|
|
237
|
-
let tempEl = successEls[0];
|
|
238
|
-
let tempFailedDepth = 0;
|
|
239
|
-
for (const el of successEls) {
|
|
240
|
-
const { success, failedDepth } = compareParentNode(node, el, rootDocument, true);
|
|
241
|
-
if (success) {
|
|
242
|
-
return el;
|
|
243
|
-
}
|
|
244
|
-
if (failedDepth > tempFailedDepth) {
|
|
245
|
-
tempFailedDepth = failedDepth;
|
|
246
|
-
tempEl = el;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return tempEl;
|
|
250
|
-
}
|
|
251
|
-
if (failedData.el) {
|
|
252
|
-
const { failedDepth, maxDepth, el } = failedData;
|
|
253
|
-
const rate = (failedDepth - 1) / maxDepth * 10;
|
|
254
|
-
if (rate >= precision) {
|
|
255
|
-
return el;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
function finder(input, options) {
|
|
261
|
-
return (0, import_finder.finder)(input, options);
|
|
262
|
-
}
|
|
263
|
-
function parserX(input) {
|
|
264
|
-
return parseSelectorsTree(input, null);
|
|
265
|
-
}
|
|
266
|
-
function parserV2(element) {
|
|
267
|
-
var _a;
|
|
268
|
-
const content = (_a = element.innerText) != null ? _a : "";
|
|
269
|
-
const selectors = parseSelectorsTree(element, null);
|
|
270
|
-
const selectorsList = queryElementSelectors(element);
|
|
271
|
-
return { content, selectors, selectorsList };
|
|
272
|
-
}
|
|
273
|
-
function finderV2(target, root) {
|
|
274
|
-
const {
|
|
275
|
-
selectors,
|
|
276
|
-
content = "",
|
|
277
|
-
sequence = 0,
|
|
278
|
-
precision = "strict",
|
|
279
|
-
isDynamicContent = false,
|
|
280
|
-
customSelector = "",
|
|
281
|
-
type = "auto"
|
|
282
|
-
} = target;
|
|
283
|
-
if (type === "auto") {
|
|
284
|
-
const mapping = {
|
|
285
|
-
looser: 1,
|
|
286
|
-
loose: 3,
|
|
287
|
-
loosest: 5,
|
|
288
|
-
strict: 7,
|
|
289
|
-
stricter: 8,
|
|
290
|
-
strictest: 10
|
|
291
|
-
};
|
|
292
|
-
const el = finderX(selectors, root, mapping[precision]);
|
|
293
|
-
if (el) {
|
|
294
|
-
if (isDynamicContent && content && el.innerText !== content) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
return el;
|
|
298
|
-
}
|
|
299
|
-
} else {
|
|
300
|
-
const sequenceMapping = {
|
|
301
|
-
"1st": 0,
|
|
302
|
-
"2st": 1,
|
|
303
|
-
"3st": 2,
|
|
304
|
-
"4st": 3,
|
|
305
|
-
"5st": 4
|
|
306
|
-
};
|
|
307
|
-
if (customSelector) {
|
|
308
|
-
const selector = customSelector.replace(/\\\\/g, "\\");
|
|
309
|
-
const els = root.querySelectorAll(selector);
|
|
310
|
-
if (els.length > 0) {
|
|
311
|
-
const el = els[sequenceMapping[sequence]] || els[0];
|
|
312
|
-
if (content && el.innerText.trim() !== content) {
|
|
313
|
-
return null;
|
|
314
|
-
}
|
|
315
|
-
return el;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
function finderX(node, root, precision = 10) {
|
|
322
|
-
if (!node || node.selectors.length === 0) {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
const rootDocument = root || document;
|
|
326
|
-
const elements = [];
|
|
327
|
-
const nodeList = queryNodeListBySelectors(node.selectors, rootDocument, false);
|
|
328
|
-
if (!nodeList || nodeList.length === 0) {
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
if ([...new Set(nodeList)].length !== nodeList.length) {
|
|
332
|
-
const el = findMostRecurringNode(nodeList);
|
|
333
|
-
elements.push(el);
|
|
334
|
-
} else {
|
|
335
|
-
elements.push(...nodeList);
|
|
336
|
-
}
|
|
337
|
-
return finderMostPrecisionElement(elements, node, rootDocument, precision);
|
|
338
|
-
}
|
|
339
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
340
|
-
0 && (module.exports = {
|
|
341
|
-
finder,
|
|
342
|
-
finderV2,
|
|
343
|
-
finderX,
|
|
344
|
-
parserV2,
|
|
345
|
-
parserX
|
|
346
|
-
});
|
package/dist/finderx.d.cts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
root: Element;
|
|
3
|
-
idName: (name: string) => boolean;
|
|
4
|
-
className: (name: string) => boolean;
|
|
5
|
-
tagName: (name: string) => boolean;
|
|
6
|
-
attr: (name: string, value: string) => boolean;
|
|
7
|
-
seedMinLength: number;
|
|
8
|
-
optimizedMinLength: number;
|
|
9
|
-
threshold: number;
|
|
10
|
-
maxNumberOfTries: number;
|
|
11
|
-
};
|
|
12
|
-
type XNode = {
|
|
13
|
-
selectors: string[];
|
|
14
|
-
nextElementSelectors: string[];
|
|
15
|
-
previousElementSelectors: string[];
|
|
16
|
-
depth: number;
|
|
17
|
-
parentNode?: XNode | null;
|
|
18
|
-
};
|
|
19
|
-
type XData = {
|
|
20
|
-
node: XNode;
|
|
21
|
-
};
|
|
22
|
-
type XResult = {
|
|
23
|
-
maxDepth: number;
|
|
24
|
-
failedDepth: number;
|
|
25
|
-
success: boolean;
|
|
26
|
-
};
|
|
27
|
-
type Target = {
|
|
28
|
-
selectors?: any;
|
|
29
|
-
content?: string;
|
|
30
|
-
sequence?: string;
|
|
31
|
-
precision?: string;
|
|
32
|
-
isDynamicContent?: boolean;
|
|
33
|
-
customSelector?: string;
|
|
34
|
-
type?: string;
|
|
35
|
-
};
|
|
36
|
-
declare function finder(input: Element, options?: Partial<Options>): string;
|
|
37
|
-
declare function parserX(input: Element): XNode | null;
|
|
38
|
-
type TargetResult = {
|
|
39
|
-
content: string;
|
|
40
|
-
selectors: XNode | null;
|
|
41
|
-
selectorsList: string[];
|
|
42
|
-
};
|
|
43
|
-
declare function parserV2(element: HTMLElement): TargetResult;
|
|
44
|
-
declare function finderV2(target: Target, root: Element | Document): HTMLElement | null;
|
|
45
|
-
declare function finderX(node: XNode, root: Element | Document, precision?: number): Element | null;
|
|
46
|
-
|
|
47
|
-
export { type Options, type Target, type TargetResult, type XData, type XNode, type XResult, finder, finderV2, finderX, parserV2, parserX };
|
package/dist/finderx.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
root: Element;
|
|
3
|
-
idName: (name: string) => boolean;
|
|
4
|
-
className: (name: string) => boolean;
|
|
5
|
-
tagName: (name: string) => boolean;
|
|
6
|
-
attr: (name: string, value: string) => boolean;
|
|
7
|
-
seedMinLength: number;
|
|
8
|
-
optimizedMinLength: number;
|
|
9
|
-
threshold: number;
|
|
10
|
-
maxNumberOfTries: number;
|
|
11
|
-
};
|
|
12
|
-
type XNode = {
|
|
13
|
-
selectors: string[];
|
|
14
|
-
nextElementSelectors: string[];
|
|
15
|
-
previousElementSelectors: string[];
|
|
16
|
-
depth: number;
|
|
17
|
-
parentNode?: XNode | null;
|
|
18
|
-
};
|
|
19
|
-
type XData = {
|
|
20
|
-
node: XNode;
|
|
21
|
-
};
|
|
22
|
-
type XResult = {
|
|
23
|
-
maxDepth: number;
|
|
24
|
-
failedDepth: number;
|
|
25
|
-
success: boolean;
|
|
26
|
-
};
|
|
27
|
-
type Target = {
|
|
28
|
-
selectors?: any;
|
|
29
|
-
content?: string;
|
|
30
|
-
sequence?: string;
|
|
31
|
-
precision?: string;
|
|
32
|
-
isDynamicContent?: boolean;
|
|
33
|
-
customSelector?: string;
|
|
34
|
-
type?: string;
|
|
35
|
-
};
|
|
36
|
-
declare function finder(input: Element, options?: Partial<Options>): string;
|
|
37
|
-
declare function parserX(input: Element): XNode | null;
|
|
38
|
-
type TargetResult = {
|
|
39
|
-
content: string;
|
|
40
|
-
selectors: XNode | null;
|
|
41
|
-
selectorsList: string[];
|
|
42
|
-
};
|
|
43
|
-
declare function parserV2(element: HTMLElement): TargetResult;
|
|
44
|
-
declare function finderV2(target: Target, root: Element | Document): HTMLElement | null;
|
|
45
|
-
declare function finderX(node: XNode, root: Element | Document, precision?: number): Element | null;
|
|
46
|
-
|
|
47
|
-
export { type Options, type Target, type TargetResult, type XData, type XNode, type XResult, finder, finderV2, finderX, parserV2, parserX };
|
package/dist/finderx.js
DELETED
package/dist/listener.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/listener.ts
|
|
21
|
-
var listener_exports = {};
|
|
22
|
-
__export(listener_exports, {
|
|
23
|
-
isBrowser: () => isBrowser,
|
|
24
|
-
isNavigator: () => isNavigator,
|
|
25
|
-
noop: () => noop,
|
|
26
|
-
off: () => off,
|
|
27
|
-
on: () => on
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(listener_exports);
|
|
30
|
-
|
|
31
|
-
// src/globals.ts
|
|
32
|
-
var win = typeof window !== "undefined" ? window : void 0;
|
|
33
|
-
var global = typeof globalThis !== "undefined" ? globalThis : win;
|
|
34
|
-
var ArrayProto = Array.prototype;
|
|
35
|
-
var nativeForEach = ArrayProto.forEach;
|
|
36
|
-
var nativeIndexOf = ArrayProto.indexOf;
|
|
37
|
-
var navigator = global == null ? void 0 : global.navigator;
|
|
38
|
-
var document = global == null ? void 0 : global.document;
|
|
39
|
-
var location = global == null ? void 0 : global.location;
|
|
40
|
-
var fetch = global == null ? void 0 : global.fetch;
|
|
41
|
-
var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
|
|
42
|
-
var AbortController = global == null ? void 0 : global.AbortController;
|
|
43
|
-
var userAgent = navigator == null ? void 0 : navigator.userAgent;
|
|
44
|
-
var assignableWindow = win != null ? win : {};
|
|
45
|
-
|
|
46
|
-
// src/listener.ts
|
|
47
|
-
var noop = () => {
|
|
48
|
-
};
|
|
49
|
-
function on(obj, ...args) {
|
|
50
|
-
if (obj == null ? void 0 : obj.addEventListener) {
|
|
51
|
-
obj.addEventListener(...args);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function off(obj, ...args) {
|
|
55
|
-
if (obj == null ? void 0 : obj.removeEventListener) {
|
|
56
|
-
obj.removeEventListener(...args);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
var isBrowser = typeof win !== "undefined";
|
|
60
|
-
var isNavigator = typeof navigator !== "undefined";
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
isBrowser,
|
|
64
|
-
isNavigator,
|
|
65
|
-
noop,
|
|
66
|
-
off,
|
|
67
|
-
on
|
|
68
|
-
});
|
package/dist/listener.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
declare const noop: () => void;
|
|
2
|
-
declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, (...args: any[]) => void, ...any]): void;
|
|
3
|
-
declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, (...args: any[]) => void, ...any]): void;
|
|
4
|
-
declare const isBrowser: boolean;
|
|
5
|
-
declare const isNavigator: boolean;
|
|
6
|
-
|
|
7
|
-
export { isBrowser, isNavigator, noop, off, on };
|
package/dist/listener.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
declare const noop: () => void;
|
|
2
|
-
declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, (...args: any[]) => void, ...any]): void;
|
|
3
|
-
declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, (...args: any[]) => void, ...any]): void;
|
|
4
|
-
declare const isBrowser: boolean;
|
|
5
|
-
declare const isNavigator: boolean;
|
|
6
|
-
|
|
7
|
-
export { isBrowser, isNavigator, noop, off, on };
|
package/dist/listener.js
DELETED