@usertour/helpers 0.0.10 → 0.0.12
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/{chunk-7IK5Q5N2.js → chunk-UT6OPCUX.js} +14 -145
- package/dist/conditions.cjs +17 -407
- package/dist/conditions.d.cts +13 -3
- package/dist/conditions.d.ts +13 -3
- package/dist/conditions.js +7 -6
- package/dist/globals.d.cts +1 -1
- package/dist/globals.d.ts +1 -1
- package/dist/index.cjs +21 -474
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +24 -33
- package/package.json +8 -10
- package/dist/chunk-DEG6MTU7.js +0 -318
- package/dist/chunk-Y6FPPOKF.js +0 -28
- 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
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
finderV2
|
|
3
|
-
} from "./chunk-DEG6MTU7.js";
|
|
4
|
-
import {
|
|
5
|
-
off,
|
|
6
|
-
on
|
|
7
|
-
} from "./chunk-Y6FPPOKF.js";
|
|
8
|
-
import {
|
|
9
|
-
document,
|
|
10
|
-
location
|
|
11
|
-
} from "./chunk-H7VA3ML2.js";
|
|
12
1
|
import {
|
|
13
2
|
conditionsIsSame,
|
|
14
3
|
isMatchUrlPattern
|
|
15
4
|
} from "./chunk-FNQIIEWK.js";
|
|
16
5
|
|
|
17
6
|
// src/conditions.ts
|
|
18
|
-
import { computePosition, hide } from "@floating-ui/dom";
|
|
19
7
|
import {
|
|
20
8
|
BizEvents,
|
|
21
9
|
ContentDataType,
|
|
22
10
|
ContentConditionLogic,
|
|
23
11
|
Frequency,
|
|
24
12
|
FrequencyUnits,
|
|
25
|
-
ElementConditionLogic,
|
|
26
|
-
StringConditionLogic,
|
|
27
13
|
ContentPriority,
|
|
28
14
|
RulesType
|
|
29
15
|
} from "@usertour/types";
|
|
@@ -35,7 +21,6 @@ import {
|
|
|
35
21
|
isAfter,
|
|
36
22
|
isBefore
|
|
37
23
|
} from "date-fns";
|
|
38
|
-
var rulesTypes = Object.values(RulesType);
|
|
39
24
|
var PRIORITIES = [
|
|
40
25
|
ContentPriority.HIGHEST,
|
|
41
26
|
ContentPriority.HIGH,
|
|
@@ -43,6 +28,7 @@ var PRIORITIES = [
|
|
|
43
28
|
ContentPriority.LOW,
|
|
44
29
|
ContentPriority.LOWEST
|
|
45
30
|
];
|
|
31
|
+
var rulesTypes = Object.values(RulesType);
|
|
46
32
|
var isActiveRulesByCurrentPage = (rules) => {
|
|
47
33
|
const { excludes, includes } = rules.data;
|
|
48
34
|
if (location) {
|
|
@@ -84,129 +70,6 @@ var isActivedContentRulesCondition = (rules, contentSession) => {
|
|
|
84
70
|
}
|
|
85
71
|
return false;
|
|
86
72
|
};
|
|
87
|
-
var isVisible = async (el) => {
|
|
88
|
-
var _a, _b;
|
|
89
|
-
if (!((_a = document) == null ? void 0 : _a.body)) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
const { middlewareData } = await computePosition(el, document.body, {
|
|
93
|
-
strategy: "fixed",
|
|
94
|
-
middleware: [hide()]
|
|
95
|
-
});
|
|
96
|
-
if ((_b = middlewareData == null ? void 0 : middlewareData.hide) == null ? void 0 : _b.referenceHidden) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
};
|
|
101
|
-
var cache = /* @__PURE__ */ new Map();
|
|
102
|
-
var isClicked = (el) => {
|
|
103
|
-
if (cache.has(el)) {
|
|
104
|
-
return cache.get(el);
|
|
105
|
-
}
|
|
106
|
-
const onClick = () => {
|
|
107
|
-
cache.set(el, true);
|
|
108
|
-
off(el, "click", onClick);
|
|
109
|
-
};
|
|
110
|
-
on(el, "click", onClick);
|
|
111
|
-
cache.set(el, false);
|
|
112
|
-
return false;
|
|
113
|
-
};
|
|
114
|
-
var isActiveRulesByElement = async (rules) => {
|
|
115
|
-
const { data } = rules;
|
|
116
|
-
if (!document) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
const el = finderV2(data.elementData, document);
|
|
120
|
-
const isPresent = el ? await isVisible(el) : false;
|
|
121
|
-
const isDisabled = el ? el.disabled : false;
|
|
122
|
-
switch (data.logic) {
|
|
123
|
-
case ElementConditionLogic.PRESENT:
|
|
124
|
-
return isPresent;
|
|
125
|
-
case ElementConditionLogic.UNPRESENT:
|
|
126
|
-
return !isPresent;
|
|
127
|
-
case ElementConditionLogic.DISABLED:
|
|
128
|
-
return el && isDisabled;
|
|
129
|
-
case ElementConditionLogic.UNDISABLED:
|
|
130
|
-
return el && !isDisabled;
|
|
131
|
-
case ElementConditionLogic.CLICKED:
|
|
132
|
-
return el && isClicked(el);
|
|
133
|
-
case ElementConditionLogic.UNCLICKED:
|
|
134
|
-
return el && !isClicked(el);
|
|
135
|
-
default:
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
var isActiveRulesByTextInput = async (rules) => {
|
|
140
|
-
const {
|
|
141
|
-
data: { elementData, logic, value }
|
|
142
|
-
} = rules;
|
|
143
|
-
if (!document) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
const el = finderV2(elementData, document);
|
|
147
|
-
if (!el) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
const elValue = el.value;
|
|
151
|
-
switch (logic) {
|
|
152
|
-
case StringConditionLogic.IS:
|
|
153
|
-
return elValue === value;
|
|
154
|
-
case StringConditionLogic.NOT:
|
|
155
|
-
return elValue !== value;
|
|
156
|
-
case StringConditionLogic.CONTAINS:
|
|
157
|
-
return elValue.includes(value);
|
|
158
|
-
case StringConditionLogic.NOT_CONTAIN:
|
|
159
|
-
return !elValue.includes(value);
|
|
160
|
-
case StringConditionLogic.STARTS_WITH:
|
|
161
|
-
return elValue.startsWith(value);
|
|
162
|
-
case StringConditionLogic.ENDS_WITH:
|
|
163
|
-
return elValue.endsWith(value);
|
|
164
|
-
case StringConditionLogic.MATCH:
|
|
165
|
-
return elValue.search(value) !== -1;
|
|
166
|
-
case StringConditionLogic.UNMATCH:
|
|
167
|
-
return elValue.search(value) === -1;
|
|
168
|
-
case StringConditionLogic.ANY:
|
|
169
|
-
return true;
|
|
170
|
-
case StringConditionLogic.EMPTY:
|
|
171
|
-
return !elValue;
|
|
172
|
-
default:
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
var fillCache = /* @__PURE__ */ new Map();
|
|
177
|
-
var isActiveRulesByTextFill = async (rules) => {
|
|
178
|
-
const {
|
|
179
|
-
data: { elementData }
|
|
180
|
-
} = rules;
|
|
181
|
-
if (!document) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
const el = finderV2(elementData, document);
|
|
185
|
-
if (!el) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
189
|
-
const onKeyup = () => {
|
|
190
|
-
const cacheData = fillCache.get(el);
|
|
191
|
-
const data = { ...cacheData, timestamp: (/* @__PURE__ */ new Date()).getTime() };
|
|
192
|
-
fillCache.set(el, data);
|
|
193
|
-
};
|
|
194
|
-
if (fillCache.has(el)) {
|
|
195
|
-
const { timestamp, value, isActive: isActive2 } = fillCache.get(el);
|
|
196
|
-
if (isActive2) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
if (timestamp !== -1 && now - timestamp > 1e3 && value !== el.value) {
|
|
200
|
-
off(document, "click", onKeyup);
|
|
201
|
-
fillCache.set(el, { timestamp, value, isActive: true });
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
on(document, "keyup", onKeyup);
|
|
207
|
-
fillCache.set(el, { timestamp: -1, value: el.value, isActive: false });
|
|
208
|
-
return false;
|
|
209
|
-
};
|
|
210
73
|
var isValidRulesType = (type) => {
|
|
211
74
|
return rulesTypes.includes(type);
|
|
212
75
|
};
|
|
@@ -219,12 +82,6 @@ var isActiveRules = async (rules) => {
|
|
|
219
82
|
return isActiveRulesByCurrentPage(rules);
|
|
220
83
|
case RulesType.TIME:
|
|
221
84
|
return isActiveRulesByCurrentTime(rules);
|
|
222
|
-
case RulesType.ELEMENT:
|
|
223
|
-
return await isActiveRulesByElement(rules);
|
|
224
|
-
case RulesType.TEXT_INPUT:
|
|
225
|
-
return await isActiveRulesByTextInput(rules);
|
|
226
|
-
case RulesType.TEXT_FILL:
|
|
227
|
-
return await isActiveRulesByTextFill(rules);
|
|
228
85
|
default:
|
|
229
86
|
return rules.actived;
|
|
230
87
|
}
|
|
@@ -393,11 +250,21 @@ var findLatestEvent = (bizEvents) => {
|
|
|
393
250
|
);
|
|
394
251
|
return lastEvent;
|
|
395
252
|
};
|
|
253
|
+
var completeEventMapping = {
|
|
254
|
+
[ContentDataType.FLOW]: BizEvents.FLOW_COMPLETED,
|
|
255
|
+
[ContentDataType.LAUNCHER]: BizEvents.LAUNCHER_ACTIVATED,
|
|
256
|
+
[ContentDataType.CHECKLIST]: BizEvents.CHECKLIST_COMPLETED
|
|
257
|
+
};
|
|
396
258
|
var showEventMapping = {
|
|
397
259
|
[ContentDataType.FLOW]: BizEvents.FLOW_STEP_SEEN,
|
|
398
260
|
[ContentDataType.LAUNCHER]: BizEvents.LAUNCHER_SEEN,
|
|
399
261
|
[ContentDataType.CHECKLIST]: BizEvents.CHECKLIST_SEEN
|
|
400
262
|
};
|
|
263
|
+
var isDismissedEventMapping = {
|
|
264
|
+
[ContentDataType.FLOW]: BizEvents.FLOW_ENDED,
|
|
265
|
+
[ContentDataType.LAUNCHER]: BizEvents.LAUNCHER_DISMISSED,
|
|
266
|
+
[ContentDataType.CHECKLIST]: BizEvents.CHECKLIST_DISMISSED
|
|
267
|
+
};
|
|
401
268
|
var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
|
|
402
269
|
switch (unit) {
|
|
403
270
|
case FrequencyUnits.SECONDS: {
|
|
@@ -571,7 +438,7 @@ var wait = (seconds) => {
|
|
|
571
438
|
|
|
572
439
|
export {
|
|
573
440
|
PRIORITIES,
|
|
574
|
-
|
|
441
|
+
rulesTypes,
|
|
575
442
|
activedRulesConditions,
|
|
576
443
|
activedContentRulesConditions,
|
|
577
444
|
activedContentCondition,
|
|
@@ -581,6 +448,8 @@ export {
|
|
|
581
448
|
isHasActivedContents,
|
|
582
449
|
isSameContents,
|
|
583
450
|
findLatestEvent,
|
|
451
|
+
completeEventMapping,
|
|
452
|
+
isDismissedEventMapping,
|
|
584
453
|
checklistIsDimissed,
|
|
585
454
|
flowIsDismissed,
|
|
586
455
|
flowIsSeen,
|
package/dist/conditions.cjs
CHANGED
|
@@ -36,266 +36,22 @@ __export(conditions_exports, {
|
|
|
36
36
|
activedRulesConditions: () => activedRulesConditions,
|
|
37
37
|
checklistIsDimissed: () => checklistIsDimissed,
|
|
38
38
|
checklistIsSeen: () => checklistIsSeen,
|
|
39
|
+
completeEventMapping: () => completeEventMapping,
|
|
39
40
|
filterAutoStartContent: () => filterAutoStartContent,
|
|
40
41
|
findLatestEvent: () => findLatestEvent,
|
|
41
42
|
flowIsDismissed: () => flowIsDismissed,
|
|
42
43
|
flowIsSeen: () => flowIsSeen,
|
|
43
44
|
isActive: () => isActive,
|
|
44
45
|
isActiveContent: () => isActiveContent,
|
|
46
|
+
isDismissedEventMapping: () => isDismissedEventMapping,
|
|
45
47
|
isHasActivedContents: () => isHasActivedContents,
|
|
46
48
|
isSameContents: () => isSameContents,
|
|
47
49
|
isValidContent: () => isValidContent,
|
|
48
|
-
isVisible: () => isVisible,
|
|
49
50
|
parseUrlParams: () => parseUrlParams,
|
|
51
|
+
rulesTypes: () => rulesTypes,
|
|
50
52
|
wait: () => wait
|
|
51
53
|
});
|
|
52
54
|
module.exports = __toCommonJS(conditions_exports);
|
|
53
|
-
var import_dom = require("@floating-ui/dom");
|
|
54
|
-
|
|
55
|
-
// src/finderx.ts
|
|
56
|
-
var import_finder = require("@medv/finder");
|
|
57
|
-
var finderAttrs = [
|
|
58
|
-
"data-for",
|
|
59
|
-
"data-id",
|
|
60
|
-
"data-testid",
|
|
61
|
-
"data-test-id",
|
|
62
|
-
"for",
|
|
63
|
-
"id",
|
|
64
|
-
"name",
|
|
65
|
-
"placeholder",
|
|
66
|
-
"role"
|
|
67
|
-
];
|
|
68
|
-
var defaultConfig = {
|
|
69
|
-
idName: () => false,
|
|
70
|
-
className: () => false,
|
|
71
|
-
tagName: () => false,
|
|
72
|
-
attr: () => false,
|
|
73
|
-
seedMinLength: 1,
|
|
74
|
-
optimizedMinLength: 2,
|
|
75
|
-
threshold: 1e3,
|
|
76
|
-
maxNumberOfTries: 1e4
|
|
77
|
-
};
|
|
78
|
-
var finderConfigs = [
|
|
79
|
-
{
|
|
80
|
-
...defaultConfig,
|
|
81
|
-
tagName: () => true
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
...defaultConfig,
|
|
85
|
-
idName: () => true
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
...defaultConfig,
|
|
89
|
-
tagName: () => true,
|
|
90
|
-
attr: (name) => finderAttrs.includes(name)
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
...defaultConfig,
|
|
94
|
-
className: () => true,
|
|
95
|
-
attr: (name) => finderAttrs.includes(name)
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
...defaultConfig,
|
|
99
|
-
tagName: () => true,
|
|
100
|
-
idName: () => true,
|
|
101
|
-
className: () => true,
|
|
102
|
-
attr: () => false
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
...defaultConfig,
|
|
106
|
-
tagName: () => true,
|
|
107
|
-
idName: () => true,
|
|
108
|
-
className: () => true,
|
|
109
|
-
attr: (name) => finderAttrs.includes(name)
|
|
110
|
-
}
|
|
111
|
-
];
|
|
112
|
-
function getMaxDepth(node) {
|
|
113
|
-
if (node.parentNode) {
|
|
114
|
-
return getMaxDepth(node.parentNode);
|
|
115
|
-
}
|
|
116
|
-
return node.depth;
|
|
117
|
-
}
|
|
118
|
-
function queryNodeListBySelectors(selectors, rootDocument, removeRepeat = true) {
|
|
119
|
-
const nodes = [];
|
|
120
|
-
if (!selectors) {
|
|
121
|
-
return nodes;
|
|
122
|
-
}
|
|
123
|
-
for (const s of selectors) {
|
|
124
|
-
const els = rootDocument.querySelectorAll(s.replace(/\\\\/g, "\\"));
|
|
125
|
-
if (els && els.length > 0) {
|
|
126
|
-
nodes.push(...Array.from(els));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return removeRepeat ? [...new Set(nodes)] : nodes;
|
|
130
|
-
}
|
|
131
|
-
function findMostRecurringNode(nodes) {
|
|
132
|
-
const m = /* @__PURE__ */ new Map();
|
|
133
|
-
let finalNode = nodes[0];
|
|
134
|
-
let count = 0;
|
|
135
|
-
for (const node of nodes) {
|
|
136
|
-
const i = m.get(node) ? m.get(node) + 1 : 1;
|
|
137
|
-
m.set(node, i);
|
|
138
|
-
}
|
|
139
|
-
m.forEach((value, key) => {
|
|
140
|
-
if (value > count) {
|
|
141
|
-
count = value;
|
|
142
|
-
finalNode = key;
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
return finalNode;
|
|
146
|
-
}
|
|
147
|
-
function compareParentNode(node, el, rootDocument, isCompareSibings = false) {
|
|
148
|
-
let nodeParentNode = node.parentNode;
|
|
149
|
-
let elParentElement = el.parentElement;
|
|
150
|
-
const maxDepth = getMaxDepth(node);
|
|
151
|
-
const xresult = {
|
|
152
|
-
maxDepth,
|
|
153
|
-
failedDepth: 0,
|
|
154
|
-
success: true
|
|
155
|
-
};
|
|
156
|
-
while (nodeParentNode && elParentElement) {
|
|
157
|
-
if (elParentElement === rootDocument) {
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
if (elParentElement === document.body || elParentElement === document.documentElement || elParentElement.parentElement === document.body) {
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
const parentNodes = queryNodeListBySelectors(nodeParentNode.selectors, rootDocument);
|
|
164
|
-
const isMatchSibings = isCompareSibings ? compareSibingsNode(nodeParentNode, elParentElement, rootDocument) : true;
|
|
165
|
-
if (!parentNodes || parentNodes.length === 0 || !parentNodes.includes(elParentElement) || !isMatchSibings) {
|
|
166
|
-
xresult.failedDepth = nodeParentNode.depth;
|
|
167
|
-
xresult.success = false;
|
|
168
|
-
}
|
|
169
|
-
nodeParentNode = nodeParentNode.parentNode;
|
|
170
|
-
elParentElement = elParentElement.parentElement;
|
|
171
|
-
}
|
|
172
|
-
return xresult;
|
|
173
|
-
}
|
|
174
|
-
function compareSibingsNode(node, el, rootDocument) {
|
|
175
|
-
let isMatchNext = true;
|
|
176
|
-
let isMatchPrevious = true;
|
|
177
|
-
const { previousElementSelectors, nextElementSelectors } = node;
|
|
178
|
-
if (nextElementSelectors && nextElementSelectors.length > 0) {
|
|
179
|
-
const nextElementSiblings = queryNodeListBySelectors(nextElementSelectors, rootDocument);
|
|
180
|
-
isMatchNext = el.nextElementSibling && nextElementSiblings.includes(el.nextElementSibling);
|
|
181
|
-
}
|
|
182
|
-
if (previousElementSelectors && previousElementSelectors.length > 0) {
|
|
183
|
-
const previousElementSiblings = queryNodeListBySelectors(
|
|
184
|
-
previousElementSelectors,
|
|
185
|
-
rootDocument
|
|
186
|
-
);
|
|
187
|
-
isMatchPrevious = el.previousElementSibling && previousElementSiblings.includes(el.previousElementSibling);
|
|
188
|
-
}
|
|
189
|
-
return isMatchNext && isMatchPrevious;
|
|
190
|
-
}
|
|
191
|
-
function finderMostPrecisionElement(elements, node, rootDocument, precision) {
|
|
192
|
-
const successEls = [];
|
|
193
|
-
let failedData = {
|
|
194
|
-
el: null,
|
|
195
|
-
failedDepth: 0,
|
|
196
|
-
maxDepth: 0
|
|
197
|
-
};
|
|
198
|
-
for (const el of elements) {
|
|
199
|
-
const { success, failedDepth, maxDepth } = compareParentNode(node, el, rootDocument);
|
|
200
|
-
if (success) {
|
|
201
|
-
successEls.push(el);
|
|
202
|
-
} else if (!failedData.el || failedDepth > failedData.failedDepth) {
|
|
203
|
-
failedData = { el, failedDepth, maxDepth };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (successEls.length === 1) {
|
|
207
|
-
return successEls[0];
|
|
208
|
-
}
|
|
209
|
-
if (successEls.length > 1) {
|
|
210
|
-
let tempEl = successEls[0];
|
|
211
|
-
let tempFailedDepth = 0;
|
|
212
|
-
for (const el of successEls) {
|
|
213
|
-
const { success, failedDepth } = compareParentNode(node, el, rootDocument, true);
|
|
214
|
-
if (success) {
|
|
215
|
-
return el;
|
|
216
|
-
}
|
|
217
|
-
if (failedDepth > tempFailedDepth) {
|
|
218
|
-
tempFailedDepth = failedDepth;
|
|
219
|
-
tempEl = el;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return tempEl;
|
|
223
|
-
}
|
|
224
|
-
if (failedData.el) {
|
|
225
|
-
const { failedDepth, maxDepth, el } = failedData;
|
|
226
|
-
const rate = (failedDepth - 1) / maxDepth * 10;
|
|
227
|
-
if (rate >= precision) {
|
|
228
|
-
return el;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
function finderV2(target, root) {
|
|
234
|
-
const {
|
|
235
|
-
selectors,
|
|
236
|
-
content = "",
|
|
237
|
-
sequence = 0,
|
|
238
|
-
precision = "strict",
|
|
239
|
-
isDynamicContent = false,
|
|
240
|
-
customSelector = "",
|
|
241
|
-
type = "auto"
|
|
242
|
-
} = target;
|
|
243
|
-
if (type === "auto") {
|
|
244
|
-
const mapping = {
|
|
245
|
-
looser: 1,
|
|
246
|
-
loose: 3,
|
|
247
|
-
loosest: 5,
|
|
248
|
-
strict: 7,
|
|
249
|
-
stricter: 8,
|
|
250
|
-
strictest: 10
|
|
251
|
-
};
|
|
252
|
-
const el = finderX(selectors, root, mapping[precision]);
|
|
253
|
-
if (el) {
|
|
254
|
-
if (isDynamicContent && content && el.innerText !== content) {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
return el;
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
const sequenceMapping = {
|
|
261
|
-
"1st": 0,
|
|
262
|
-
"2st": 1,
|
|
263
|
-
"3st": 2,
|
|
264
|
-
"4st": 3,
|
|
265
|
-
"5st": 4
|
|
266
|
-
};
|
|
267
|
-
if (customSelector) {
|
|
268
|
-
const selector = customSelector.replace(/\\\\/g, "\\");
|
|
269
|
-
const els = root.querySelectorAll(selector);
|
|
270
|
-
if (els.length > 0) {
|
|
271
|
-
const el = els[sequenceMapping[sequence]] || els[0];
|
|
272
|
-
if (content && el.innerText.trim() !== content) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
return el;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
function finderX(node, root, precision = 10) {
|
|
282
|
-
if (!node || node.selectors.length === 0) {
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
const rootDocument = root || document;
|
|
286
|
-
const elements = [];
|
|
287
|
-
const nodeList = queryNodeListBySelectors(node.selectors, rootDocument, false);
|
|
288
|
-
if (!nodeList || nodeList.length === 0) {
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
if ([...new Set(nodeList)].length !== nodeList.length) {
|
|
292
|
-
const el = findMostRecurringNode(nodeList);
|
|
293
|
-
elements.push(el);
|
|
294
|
-
} else {
|
|
295
|
-
elements.push(...nodeList);
|
|
296
|
-
}
|
|
297
|
-
return finderMostPrecisionElement(elements, node, rootDocument, precision);
|
|
298
|
-
}
|
|
299
55
|
|
|
300
56
|
// src/condition.ts
|
|
301
57
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
@@ -416,36 +172,6 @@ var conditionsIsSame = (rr1, rr2) => {
|
|
|
416
172
|
// src/conditions.ts
|
|
417
173
|
var import_types = require("@usertour/types");
|
|
418
174
|
var import_date_fns = require("date-fns");
|
|
419
|
-
|
|
420
|
-
// src/globals.ts
|
|
421
|
-
var win = typeof window !== "undefined" ? window : void 0;
|
|
422
|
-
var global = typeof globalThis !== "undefined" ? globalThis : win;
|
|
423
|
-
var ArrayProto = Array.prototype;
|
|
424
|
-
var nativeForEach = ArrayProto.forEach;
|
|
425
|
-
var nativeIndexOf = ArrayProto.indexOf;
|
|
426
|
-
var navigator = global == null ? void 0 : global.navigator;
|
|
427
|
-
var document2 = global == null ? void 0 : global.document;
|
|
428
|
-
var location = global == null ? void 0 : global.location;
|
|
429
|
-
var fetch = global == null ? void 0 : global.fetch;
|
|
430
|
-
var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
|
|
431
|
-
var AbortController = global == null ? void 0 : global.AbortController;
|
|
432
|
-
var userAgent = navigator == null ? void 0 : navigator.userAgent;
|
|
433
|
-
var assignableWindow = win != null ? win : {};
|
|
434
|
-
|
|
435
|
-
// src/listener.ts
|
|
436
|
-
function on(obj, ...args) {
|
|
437
|
-
if (obj == null ? void 0 : obj.addEventListener) {
|
|
438
|
-
obj.addEventListener(...args);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
function off(obj, ...args) {
|
|
442
|
-
if (obj == null ? void 0 : obj.removeEventListener) {
|
|
443
|
-
obj.removeEventListener(...args);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// src/conditions.ts
|
|
448
|
-
var rulesTypes = Object.values(import_types.RulesType);
|
|
449
175
|
var PRIORITIES = [
|
|
450
176
|
import_types.ContentPriority.HIGHEST,
|
|
451
177
|
import_types.ContentPriority.HIGH,
|
|
@@ -453,6 +179,7 @@ var PRIORITIES = [
|
|
|
453
179
|
import_types.ContentPriority.LOW,
|
|
454
180
|
import_types.ContentPriority.LOWEST
|
|
455
181
|
];
|
|
182
|
+
var rulesTypes = Object.values(import_types.RulesType);
|
|
456
183
|
var isActiveRulesByCurrentPage = (rules) => {
|
|
457
184
|
const { excludes, includes } = rules.data;
|
|
458
185
|
if (location) {
|
|
@@ -494,129 +221,6 @@ var isActivedContentRulesCondition = (rules, contentSession) => {
|
|
|
494
221
|
}
|
|
495
222
|
return false;
|
|
496
223
|
};
|
|
497
|
-
var isVisible = async (el) => {
|
|
498
|
-
var _a, _b;
|
|
499
|
-
if (!((_a = document2) == null ? void 0 : _a.body)) {
|
|
500
|
-
return false;
|
|
501
|
-
}
|
|
502
|
-
const { middlewareData } = await (0, import_dom.computePosition)(el, document2.body, {
|
|
503
|
-
strategy: "fixed",
|
|
504
|
-
middleware: [(0, import_dom.hide)()]
|
|
505
|
-
});
|
|
506
|
-
if ((_b = middlewareData == null ? void 0 : middlewareData.hide) == null ? void 0 : _b.referenceHidden) {
|
|
507
|
-
return false;
|
|
508
|
-
}
|
|
509
|
-
return true;
|
|
510
|
-
};
|
|
511
|
-
var cache = /* @__PURE__ */ new Map();
|
|
512
|
-
var isClicked = (el) => {
|
|
513
|
-
if (cache.has(el)) {
|
|
514
|
-
return cache.get(el);
|
|
515
|
-
}
|
|
516
|
-
const onClick = () => {
|
|
517
|
-
cache.set(el, true);
|
|
518
|
-
off(el, "click", onClick);
|
|
519
|
-
};
|
|
520
|
-
on(el, "click", onClick);
|
|
521
|
-
cache.set(el, false);
|
|
522
|
-
return false;
|
|
523
|
-
};
|
|
524
|
-
var isActiveRulesByElement = async (rules) => {
|
|
525
|
-
const { data } = rules;
|
|
526
|
-
if (!document2) {
|
|
527
|
-
return false;
|
|
528
|
-
}
|
|
529
|
-
const el = finderV2(data.elementData, document2);
|
|
530
|
-
const isPresent = el ? await isVisible(el) : false;
|
|
531
|
-
const isDisabled = el ? el.disabled : false;
|
|
532
|
-
switch (data.logic) {
|
|
533
|
-
case import_types.ElementConditionLogic.PRESENT:
|
|
534
|
-
return isPresent;
|
|
535
|
-
case import_types.ElementConditionLogic.UNPRESENT:
|
|
536
|
-
return !isPresent;
|
|
537
|
-
case import_types.ElementConditionLogic.DISABLED:
|
|
538
|
-
return el && isDisabled;
|
|
539
|
-
case import_types.ElementConditionLogic.UNDISABLED:
|
|
540
|
-
return el && !isDisabled;
|
|
541
|
-
case import_types.ElementConditionLogic.CLICKED:
|
|
542
|
-
return el && isClicked(el);
|
|
543
|
-
case import_types.ElementConditionLogic.UNCLICKED:
|
|
544
|
-
return el && !isClicked(el);
|
|
545
|
-
default:
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
var isActiveRulesByTextInput = async (rules) => {
|
|
550
|
-
const {
|
|
551
|
-
data: { elementData, logic, value }
|
|
552
|
-
} = rules;
|
|
553
|
-
if (!document2) {
|
|
554
|
-
return false;
|
|
555
|
-
}
|
|
556
|
-
const el = finderV2(elementData, document2);
|
|
557
|
-
if (!el) {
|
|
558
|
-
return false;
|
|
559
|
-
}
|
|
560
|
-
const elValue = el.value;
|
|
561
|
-
switch (logic) {
|
|
562
|
-
case import_types.StringConditionLogic.IS:
|
|
563
|
-
return elValue === value;
|
|
564
|
-
case import_types.StringConditionLogic.NOT:
|
|
565
|
-
return elValue !== value;
|
|
566
|
-
case import_types.StringConditionLogic.CONTAINS:
|
|
567
|
-
return elValue.includes(value);
|
|
568
|
-
case import_types.StringConditionLogic.NOT_CONTAIN:
|
|
569
|
-
return !elValue.includes(value);
|
|
570
|
-
case import_types.StringConditionLogic.STARTS_WITH:
|
|
571
|
-
return elValue.startsWith(value);
|
|
572
|
-
case import_types.StringConditionLogic.ENDS_WITH:
|
|
573
|
-
return elValue.endsWith(value);
|
|
574
|
-
case import_types.StringConditionLogic.MATCH:
|
|
575
|
-
return elValue.search(value) !== -1;
|
|
576
|
-
case import_types.StringConditionLogic.UNMATCH:
|
|
577
|
-
return elValue.search(value) === -1;
|
|
578
|
-
case import_types.StringConditionLogic.ANY:
|
|
579
|
-
return true;
|
|
580
|
-
case import_types.StringConditionLogic.EMPTY:
|
|
581
|
-
return !elValue;
|
|
582
|
-
default:
|
|
583
|
-
return false;
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
var fillCache = /* @__PURE__ */ new Map();
|
|
587
|
-
var isActiveRulesByTextFill = async (rules) => {
|
|
588
|
-
const {
|
|
589
|
-
data: { elementData }
|
|
590
|
-
} = rules;
|
|
591
|
-
if (!document2) {
|
|
592
|
-
return false;
|
|
593
|
-
}
|
|
594
|
-
const el = finderV2(elementData, document2);
|
|
595
|
-
if (!el) {
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
599
|
-
const onKeyup = () => {
|
|
600
|
-
const cacheData = fillCache.get(el);
|
|
601
|
-
const data = { ...cacheData, timestamp: (/* @__PURE__ */ new Date()).getTime() };
|
|
602
|
-
fillCache.set(el, data);
|
|
603
|
-
};
|
|
604
|
-
if (fillCache.has(el)) {
|
|
605
|
-
const { timestamp, value, isActive: isActive2 } = fillCache.get(el);
|
|
606
|
-
if (isActive2) {
|
|
607
|
-
return true;
|
|
608
|
-
}
|
|
609
|
-
if (timestamp !== -1 && now - timestamp > 1e3 && value !== el.value) {
|
|
610
|
-
off(document2, "click", onKeyup);
|
|
611
|
-
fillCache.set(el, { timestamp, value, isActive: true });
|
|
612
|
-
return true;
|
|
613
|
-
}
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
on(document2, "keyup", onKeyup);
|
|
617
|
-
fillCache.set(el, { timestamp: -1, value: el.value, isActive: false });
|
|
618
|
-
return false;
|
|
619
|
-
};
|
|
620
224
|
var isValidRulesType = (type) => {
|
|
621
225
|
return rulesTypes.includes(type);
|
|
622
226
|
};
|
|
@@ -629,12 +233,6 @@ var isActiveRules = async (rules) => {
|
|
|
629
233
|
return isActiveRulesByCurrentPage(rules);
|
|
630
234
|
case import_types.RulesType.TIME:
|
|
631
235
|
return isActiveRulesByCurrentTime(rules);
|
|
632
|
-
case import_types.RulesType.ELEMENT:
|
|
633
|
-
return await isActiveRulesByElement(rules);
|
|
634
|
-
case import_types.RulesType.TEXT_INPUT:
|
|
635
|
-
return await isActiveRulesByTextInput(rules);
|
|
636
|
-
case import_types.RulesType.TEXT_FILL:
|
|
637
|
-
return await isActiveRulesByTextFill(rules);
|
|
638
236
|
default:
|
|
639
237
|
return rules.actived;
|
|
640
238
|
}
|
|
@@ -803,11 +401,21 @@ var findLatestEvent = (bizEvents) => {
|
|
|
803
401
|
);
|
|
804
402
|
return lastEvent;
|
|
805
403
|
};
|
|
404
|
+
var completeEventMapping = {
|
|
405
|
+
[import_types.ContentDataType.FLOW]: import_types.BizEvents.FLOW_COMPLETED,
|
|
406
|
+
[import_types.ContentDataType.LAUNCHER]: import_types.BizEvents.LAUNCHER_ACTIVATED,
|
|
407
|
+
[import_types.ContentDataType.CHECKLIST]: import_types.BizEvents.CHECKLIST_COMPLETED
|
|
408
|
+
};
|
|
806
409
|
var showEventMapping = {
|
|
807
410
|
[import_types.ContentDataType.FLOW]: import_types.BizEvents.FLOW_STEP_SEEN,
|
|
808
411
|
[import_types.ContentDataType.LAUNCHER]: import_types.BizEvents.LAUNCHER_SEEN,
|
|
809
412
|
[import_types.ContentDataType.CHECKLIST]: import_types.BizEvents.CHECKLIST_SEEN
|
|
810
413
|
};
|
|
414
|
+
var isDismissedEventMapping = {
|
|
415
|
+
[import_types.ContentDataType.FLOW]: import_types.BizEvents.FLOW_ENDED,
|
|
416
|
+
[import_types.ContentDataType.LAUNCHER]: import_types.BizEvents.LAUNCHER_DISMISSED,
|
|
417
|
+
[import_types.ContentDataType.CHECKLIST]: import_types.BizEvents.CHECKLIST_DISMISSED
|
|
418
|
+
};
|
|
811
419
|
var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
|
|
812
420
|
switch (unit) {
|
|
813
421
|
case import_types.FrequencyUnits.SECONDS: {
|
|
@@ -986,16 +594,18 @@ var wait = (seconds) => {
|
|
|
986
594
|
activedRulesConditions,
|
|
987
595
|
checklistIsDimissed,
|
|
988
596
|
checklistIsSeen,
|
|
597
|
+
completeEventMapping,
|
|
989
598
|
filterAutoStartContent,
|
|
990
599
|
findLatestEvent,
|
|
991
600
|
flowIsDismissed,
|
|
992
601
|
flowIsSeen,
|
|
993
602
|
isActive,
|
|
994
603
|
isActiveContent,
|
|
604
|
+
isDismissedEventMapping,
|
|
995
605
|
isHasActivedContents,
|
|
996
606
|
isSameContents,
|
|
997
607
|
isValidContent,
|
|
998
|
-
isVisible,
|
|
999
608
|
parseUrlParams,
|
|
609
|
+
rulesTypes,
|
|
1000
610
|
wait
|
|
1001
611
|
});
|