@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/index.js CHANGED
@@ -1,6 +1,3 @@
1
- import {
2
- deepClone
3
- } from "./chunk-2AEGAICC.js";
4
1
  import {
5
2
  absoluteUrl,
6
3
  cn,
@@ -18,6 +15,9 @@ import {
18
15
  import {
19
16
  defaultStep
20
17
  } from "./chunk-FW54TSA3.js";
18
+ import {
19
+ deepClone
20
+ } from "./chunk-2AEGAICC.js";
21
21
  import {
22
22
  getAuthToken,
23
23
  removeAuthToken,
@@ -25,6 +25,20 @@ import {
25
25
  storage
26
26
  } from "./chunk-FGFMTWFT.js";
27
27
  import "./chunk-3ZGH3NRU.js";
28
+ import {
29
+ AbortController,
30
+ ArrayProto,
31
+ XMLHttpRequest,
32
+ assignableWindow,
33
+ document,
34
+ fetch,
35
+ location,
36
+ nativeForEach,
37
+ nativeIndexOf,
38
+ navigator,
39
+ userAgent,
40
+ win
41
+ } from "./chunk-H7VA3ML2.js";
28
42
  import {
29
43
  PRIORITIES,
30
44
  activedContentCondition,
@@ -32,41 +46,21 @@ import {
32
46
  activedRulesConditions,
33
47
  checklistIsDimissed,
34
48
  checklistIsSeen,
49
+ completeEventMapping,
35
50
  filterAutoStartContent,
36
51
  findLatestEvent,
37
52
  flowIsDismissed,
38
53
  flowIsSeen,
39
54
  isActive,
40
55
  isActiveContent,
56
+ isDismissedEventMapping,
41
57
  isHasActivedContents,
42
58
  isSameContents,
43
59
  isValidContent,
44
- isVisible,
45
60
  parseUrlParams,
61
+ rulesTypes,
46
62
  wait
47
- } from "./chunk-7IK5Q5N2.js";
48
- import {
49
- finder,
50
- finderV2,
51
- finderX,
52
- parserV2,
53
- parserX
54
- } from "./chunk-DEG6MTU7.js";
55
- import "./chunk-Y6FPPOKF.js";
56
- import {
57
- AbortController,
58
- ArrayProto,
59
- XMLHttpRequest,
60
- assignableWindow,
61
- document,
62
- fetch,
63
- location,
64
- nativeForEach,
65
- nativeIndexOf,
66
- navigator,
67
- userAgent,
68
- win
69
- } from "./chunk-H7VA3ML2.js";
63
+ } from "./chunk-UT6OPCUX.js";
70
64
  import {
71
65
  conditionsIsSame,
72
66
  isEqual,
@@ -143,6 +137,7 @@ export {
143
137
  checklistIsDimissed,
144
138
  checklistIsSeen,
145
139
  cn,
140
+ completeEventMapping,
146
141
  conditionsIsSame,
147
142
  convertSettings,
148
143
  convertToCssVars,
@@ -155,9 +150,6 @@ export {
155
150
  fetch,
156
151
  filterAutoStartContent,
157
152
  findLatestEvent,
158
- finder,
159
- finderV2,
160
- finderX,
161
153
  flowIsDismissed,
162
154
  flowIsSeen,
163
155
  formatDate,
@@ -188,6 +180,7 @@ export {
188
180
  isBoolean,
189
181
  isDark,
190
182
  isDate,
183
+ isDismissedEventMapping,
191
184
  isDocument,
192
185
  isEmptyObject,
193
186
  isEmptyString,
@@ -210,16 +203,14 @@ export {
210
203
  isUrl,
211
204
  isValidContent,
212
205
  isValidSelector,
213
- isVisible,
214
206
  location,
215
207
  mergeThemeDefaultSettings,
216
208
  nativeForEach,
217
209
  nativeIndexOf,
218
210
  navigator,
219
211
  parseUrlParams,
220
- parserV2,
221
- parserX,
222
212
  removeAuthToken,
213
+ rulesTypes,
223
214
  setAuthToken,
224
215
  storage,
225
216
  userAgent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",
@@ -26,24 +26,22 @@
26
26
  "prepublishOnly": "pnpm build"
27
27
  },
28
28
  "dependencies": {
29
- "@floating-ui/dom": "^1.4.4",
30
- "@medv/finder": "^3.1.0",
31
- "@paralleldrive/cuid2": "^2.2.2",
32
- "@usertour/types": "^0.0.5",
29
+ "@usertour/types": "^0.0.6",
30
+ "fast-deep-equal": "^3.1.3",
33
31
  "chroma-js": "^3.1.2",
32
+ "deepmerge-ts": "^7.1.3",
33
+ "@paralleldrive/cuid2": "^2.2.2",
34
34
  "class-variance-authority": "^0.4.0",
35
35
  "clsx": "^1.2.1",
36
- "date-fns": "^2.30.0",
37
- "deepmerge-ts": "^7.1.3",
38
- "fast-deep-equal": "^3.1.3",
39
36
  "tailwind-merge": "^1.13.2",
37
+ "date-fns": "^2.30.0",
40
38
  "uuid": "^9.0.1"
41
39
  },
42
40
  "devDependencies": {
43
- "@types/chroma-js": "^3.1.1",
44
- "@types/uuid": "^9.0.6",
45
41
  "@typescript-eslint/eslint-plugin": "^5.59.0",
46
42
  "@typescript-eslint/parser": "^5.59.0",
43
+ "@types/chroma-js": "^3.1.1",
44
+ "@types/uuid": "^9.0.6",
47
45
  "eslint": "^8.38.0",
48
46
  "typescript": "^5.0.2"
49
47
  },
@@ -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
- };
@@ -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
- };