@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/index.cjs CHANGED
@@ -37,17 +37,11 @@ var src_exports = {};
37
37
  __export(src_exports, {
38
38
  AbortController: () => AbortController,
39
39
  ArrayProto: () => ArrayProto,
40
- PRIORITIES: () => PRIORITIES,
41
40
  XMLHttpRequest: () => XMLHttpRequest,
42
41
  absoluteUrl: () => absoluteUrl,
43
- activedContentCondition: () => activedContentCondition,
44
- activedContentRulesConditions: () => activedContentRulesConditions,
45
- activedRulesConditions: () => activedRulesConditions,
46
42
  assignableWindow: () => assignableWindow,
47
43
  autoStartConditions: () => autoStartConditions,
48
44
  buildConfig: () => buildConfig,
49
- checklistIsDimissed: () => checklistIsDimissed,
50
- checklistIsSeen: () => checklistIsSeen,
51
45
  cn: () => cn,
52
46
  conditionsIsSame: () => conditionsIsSame,
53
47
  convertSettings: () => convertSettings,
@@ -56,16 +50,9 @@ __export(src_exports, {
56
50
  deepClone: () => deepClone,
57
51
  defaultContentConfig: () => defaultContentConfig,
58
52
  defaultStep: () => defaultStep,
59
- document: () => document2,
53
+ document: () => document,
60
54
  evalCode: () => evalCode,
61
55
  fetch: () => fetch,
62
- filterAutoStartContent: () => filterAutoStartContent,
63
- findLatestEvent: () => findLatestEvent,
64
- finder: () => finder,
65
- finderV2: () => finderV2,
66
- finderX: () => finderX,
67
- flowIsDismissed: () => flowIsDismissed,
68
- flowIsSeen: () => flowIsSeen,
69
56
  formatDate: () => formatDate,
70
57
  generateAutoStateColors: () => generateAutoStateColors,
71
58
  getAuthToken: () => getAuthToken,
@@ -88,8 +75,6 @@ __export(src_exports, {
88
75
  hexToHSLString: () => hexToHSLString,
89
76
  hexToRGBStr: () => hexToRGBStr,
90
77
  hexToRgb: () => hexToRgb,
91
- isActive: () => isActive,
92
- isActiveContent: () => isActiveContent,
93
78
  isArray: () => isArray,
94
79
  isBoolean: () => isBoolean,
95
80
  isDark: () => isDark,
@@ -101,7 +86,6 @@ __export(src_exports, {
101
86
  isFile: () => isFile,
102
87
  isFormData: () => isFormData,
103
88
  isFunction: () => isFunction,
104
- isHasActivedContents: () => isHasActivedContents,
105
89
  isMatchUrlPattern: () => isMatchUrlPattern,
106
90
  isNull: () => isNull,
107
91
  isNullish: () => isNullish,
@@ -109,28 +93,21 @@ __export(src_exports, {
109
93
  isObject: () => isObject,
110
94
  isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
111
95
  isPublishedInAllEnvironments: () => isPublishedInAllEnvironments,
112
- isSameContents: () => isSameContents,
113
96
  isString: () => isString,
114
97
  isUint8Array: () => isUint8Array,
115
98
  isUndefined: () => isUndefined,
116
99
  isUrl: () => isUrl,
117
- isValidContent: () => isValidContent,
118
100
  isValidSelector: () => isValidSelector,
119
- isVisible: () => isVisible,
120
101
  location: () => location,
121
102
  mergeThemeDefaultSettings: () => mergeThemeDefaultSettings,
122
103
  nativeForEach: () => nativeForEach,
123
104
  nativeIndexOf: () => nativeIndexOf,
124
105
  navigator: () => navigator,
125
- parseUrlParams: () => parseUrlParams,
126
- parserV2: () => parserV2,
127
- parserX: () => parserX,
128
106
  removeAuthToken: () => removeAuthToken,
129
107
  setAuthToken: () => setAuthToken,
130
108
  storage: () => storage,
131
109
  userAgent: () => userAgent,
132
110
  uuidV4: () => uuidV4,
133
- wait: () => wait,
134
111
  window: () => win
135
112
  });
136
113
  module.exports = __toCommonJS(src_exports);
@@ -834,7 +811,7 @@ var ArrayProto = Array.prototype;
834
811
  var nativeForEach = ArrayProto.forEach;
835
812
  var nativeIndexOf = ArrayProto.indexOf;
836
813
  var navigator = global == null ? void 0 : global.navigator;
837
- var document2 = global == null ? void 0 : global.document;
814
+ var document = global == null ? void 0 : global.document;
838
815
  var location = global == null ? void 0 : global.location;
839
816
  var fetch = global == null ? void 0 : global.fetch;
840
817
  var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
@@ -1109,886 +1086,15 @@ var getRandomColor = () => {
1109
1086
  ];
1110
1087
  return colors[Math.floor(Math.random() * colors.length)];
1111
1088
  };
1112
-
1113
- // src/conditions.ts
1114
- var import_dom = require("@floating-ui/dom");
1115
-
1116
- // src/finderx.ts
1117
- var import_finder = require("@medv/finder");
1118
- var finderAttrs = [
1119
- "data-for",
1120
- "data-id",
1121
- "data-testid",
1122
- "data-test-id",
1123
- "for",
1124
- "id",
1125
- "name",
1126
- "placeholder",
1127
- "role"
1128
- ];
1129
- var defaultConfig = {
1130
- idName: () => false,
1131
- className: () => false,
1132
- tagName: () => false,
1133
- attr: () => false,
1134
- seedMinLength: 1,
1135
- optimizedMinLength: 2,
1136
- threshold: 1e3,
1137
- maxNumberOfTries: 1e4
1138
- };
1139
- var finderConfigs = [
1140
- {
1141
- ...defaultConfig,
1142
- tagName: () => true
1143
- },
1144
- {
1145
- ...defaultConfig,
1146
- idName: () => true
1147
- },
1148
- {
1149
- ...defaultConfig,
1150
- tagName: () => true,
1151
- attr: (name) => finderAttrs.includes(name)
1152
- },
1153
- {
1154
- ...defaultConfig,
1155
- className: () => true,
1156
- attr: (name) => finderAttrs.includes(name)
1157
- },
1158
- {
1159
- ...defaultConfig,
1160
- tagName: () => true,
1161
- idName: () => true,
1162
- className: () => true,
1163
- attr: () => false
1164
- },
1165
- {
1166
- ...defaultConfig,
1167
- tagName: () => true,
1168
- idName: () => true,
1169
- className: () => true,
1170
- attr: (name) => finderAttrs.includes(name)
1171
- }
1172
- ];
1173
- function getMaxDepth(node) {
1174
- if (node.parentNode) {
1175
- return getMaxDepth(node.parentNode);
1176
- }
1177
- return node.depth;
1178
- }
1179
- function queryNodeListBySelectors(selectors, rootDocument, removeRepeat = true) {
1180
- const nodes = [];
1181
- if (!selectors) {
1182
- return nodes;
1183
- }
1184
- for (const s of selectors) {
1185
- const els = rootDocument.querySelectorAll(s.replace(/\\\\/g, "\\"));
1186
- if (els && els.length > 0) {
1187
- nodes.push(...Array.from(els));
1188
- }
1189
- }
1190
- return removeRepeat ? [...new Set(nodes)] : nodes;
1191
- }
1192
- function findMostRecurringNode(nodes) {
1193
- const m = /* @__PURE__ */ new Map();
1194
- let finalNode = nodes[0];
1195
- let count = 0;
1196
- for (const node of nodes) {
1197
- const i = m.get(node) ? m.get(node) + 1 : 1;
1198
- m.set(node, i);
1199
- }
1200
- m.forEach((value, key) => {
1201
- if (value > count) {
1202
- count = value;
1203
- finalNode = key;
1204
- }
1205
- });
1206
- return finalNode;
1207
- }
1208
- function compareParentNode(node, el, rootDocument, isCompareSibings = false) {
1209
- let nodeParentNode = node.parentNode;
1210
- let elParentElement = el.parentElement;
1211
- const maxDepth = getMaxDepth(node);
1212
- const xresult = {
1213
- maxDepth,
1214
- failedDepth: 0,
1215
- success: true
1216
- };
1217
- while (nodeParentNode && elParentElement) {
1218
- if (elParentElement === rootDocument) {
1219
- break;
1220
- }
1221
- if (elParentElement === document.body || elParentElement === document.documentElement || elParentElement.parentElement === document.body) {
1222
- break;
1223
- }
1224
- const parentNodes = queryNodeListBySelectors(nodeParentNode.selectors, rootDocument);
1225
- const isMatchSibings = isCompareSibings ? compareSibingsNode(nodeParentNode, elParentElement, rootDocument) : true;
1226
- if (!parentNodes || parentNodes.length === 0 || !parentNodes.includes(elParentElement) || !isMatchSibings) {
1227
- xresult.failedDepth = nodeParentNode.depth;
1228
- xresult.success = false;
1229
- }
1230
- nodeParentNode = nodeParentNode.parentNode;
1231
- elParentElement = elParentElement.parentElement;
1232
- }
1233
- return xresult;
1234
- }
1235
- function compareSibingsNode(node, el, rootDocument) {
1236
- let isMatchNext = true;
1237
- let isMatchPrevious = true;
1238
- const { previousElementSelectors, nextElementSelectors } = node;
1239
- if (nextElementSelectors && nextElementSelectors.length > 0) {
1240
- const nextElementSiblings = queryNodeListBySelectors(nextElementSelectors, rootDocument);
1241
- isMatchNext = el.nextElementSibling && nextElementSiblings.includes(el.nextElementSibling);
1242
- }
1243
- if (previousElementSelectors && previousElementSelectors.length > 0) {
1244
- const previousElementSiblings = queryNodeListBySelectors(
1245
- previousElementSelectors,
1246
- rootDocument
1247
- );
1248
- isMatchPrevious = el.previousElementSibling && previousElementSiblings.includes(el.previousElementSibling);
1249
- }
1250
- return isMatchNext && isMatchPrevious;
1251
- }
1252
- function queryElementSelectors(input) {
1253
- const classes = Array.from(input.classList);
1254
- const selectors = [];
1255
- const configs = [...finderConfigs];
1256
- for (const className of classes) {
1257
- configs.push({
1258
- ...defaultConfig,
1259
- className: (name) => {
1260
- if (classes.filter((cn2) => cn2 !== className).includes(name)) {
1261
- return false;
1262
- }
1263
- return true;
1264
- }
1265
- });
1266
- }
1267
- try {
1268
- for (const cfg of configs) {
1269
- selectors.push(finder(input, cfg));
1270
- }
1271
- } catch (_) {
1272
- return selectors;
1273
- }
1274
- return [...new Set(selectors)];
1275
- }
1276
- function parseSelectorsTree(input, parentNode, depth = 0) {
1277
- const selectors = queryElementSelectors(input);
1278
- if (selectors.length === 0) {
1279
- return parentNode;
1280
- }
1281
- const currentNode = {
1282
- previousElementSelectors: [],
1283
- nextElementSelectors: [],
1284
- selectors,
1285
- depth
1286
- };
1287
- if (input.previousElementSibling) {
1288
- currentNode.previousElementSelectors = queryElementSelectors(input.previousElementSibling);
1289
- }
1290
- if (input.nextElementSibling) {
1291
- currentNode.nextElementSelectors = queryElementSelectors(input.nextElementSibling);
1292
- }
1293
- if (parentNode === null) {
1294
- if (input.parentElement) {
1295
- parseSelectorsTree(input.parentElement, currentNode, depth + 1);
1296
- }
1297
- return currentNode;
1298
- }
1299
- parentNode.parentNode = currentNode;
1300
- if (input.parentElement) {
1301
- parseSelectorsTree(input.parentElement, currentNode, depth + 1);
1302
- }
1303
- return parentNode;
1304
- }
1305
- function finderMostPrecisionElement(elements, node, rootDocument, precision) {
1306
- const successEls = [];
1307
- let failedData = {
1308
- el: null,
1309
- failedDepth: 0,
1310
- maxDepth: 0
1311
- };
1312
- for (const el of elements) {
1313
- const { success, failedDepth, maxDepth } = compareParentNode(node, el, rootDocument);
1314
- if (success) {
1315
- successEls.push(el);
1316
- } else if (!failedData.el || failedDepth > failedData.failedDepth) {
1317
- failedData = { el, failedDepth, maxDepth };
1318
- }
1319
- }
1320
- if (successEls.length === 1) {
1321
- return successEls[0];
1322
- }
1323
- if (successEls.length > 1) {
1324
- let tempEl = successEls[0];
1325
- let tempFailedDepth = 0;
1326
- for (const el of successEls) {
1327
- const { success, failedDepth } = compareParentNode(node, el, rootDocument, true);
1328
- if (success) {
1329
- return el;
1330
- }
1331
- if (failedDepth > tempFailedDepth) {
1332
- tempFailedDepth = failedDepth;
1333
- tempEl = el;
1334
- }
1335
- }
1336
- return tempEl;
1337
- }
1338
- if (failedData.el) {
1339
- const { failedDepth, maxDepth, el } = failedData;
1340
- const rate = (failedDepth - 1) / maxDepth * 10;
1341
- if (rate >= precision) {
1342
- return el;
1343
- }
1344
- }
1345
- return null;
1346
- }
1347
- function finder(input, options) {
1348
- return (0, import_finder.finder)(input, options);
1349
- }
1350
- function parserX(input) {
1351
- return parseSelectorsTree(input, null);
1352
- }
1353
- function parserV2(element) {
1354
- var _a;
1355
- const content = (_a = element.innerText) != null ? _a : "";
1356
- const selectors = parseSelectorsTree(element, null);
1357
- const selectorsList = queryElementSelectors(element);
1358
- return { content, selectors, selectorsList };
1359
- }
1360
- function finderV2(target, root) {
1361
- const {
1362
- selectors,
1363
- content = "",
1364
- sequence = 0,
1365
- precision = "strict",
1366
- isDynamicContent = false,
1367
- customSelector = "",
1368
- type = "auto"
1369
- } = target;
1370
- if (type === "auto") {
1371
- const mapping = {
1372
- looser: 1,
1373
- loose: 3,
1374
- loosest: 5,
1375
- strict: 7,
1376
- stricter: 8,
1377
- strictest: 10
1378
- };
1379
- const el = finderX(selectors, root, mapping[precision]);
1380
- if (el) {
1381
- if (isDynamicContent && content && el.innerText !== content) {
1382
- return null;
1383
- }
1384
- return el;
1385
- }
1386
- } else {
1387
- const sequenceMapping = {
1388
- "1st": 0,
1389
- "2st": 1,
1390
- "3st": 2,
1391
- "4st": 3,
1392
- "5st": 4
1393
- };
1394
- if (customSelector) {
1395
- const selector = customSelector.replace(/\\\\/g, "\\");
1396
- const els = root.querySelectorAll(selector);
1397
- if (els.length > 0) {
1398
- const el = els[sequenceMapping[sequence]] || els[0];
1399
- if (content && el.innerText.trim() !== content) {
1400
- return null;
1401
- }
1402
- return el;
1403
- }
1404
- }
1405
- }
1406
- return null;
1407
- }
1408
- function finderX(node, root, precision = 10) {
1409
- if (!node || node.selectors.length === 0) {
1410
- return null;
1411
- }
1412
- const rootDocument = root || document;
1413
- const elements = [];
1414
- const nodeList = queryNodeListBySelectors(node.selectors, rootDocument, false);
1415
- if (!nodeList || nodeList.length === 0) {
1416
- return null;
1417
- }
1418
- if ([...new Set(nodeList)].length !== nodeList.length) {
1419
- const el = findMostRecurringNode(nodeList);
1420
- elements.push(el);
1421
- } else {
1422
- elements.push(...nodeList);
1423
- }
1424
- return finderMostPrecisionElement(elements, node, rootDocument, precision);
1425
- }
1426
-
1427
- // src/conditions.ts
1428
- var import_types4 = require("@usertour/types");
1429
- var import_date_fns = require("date-fns");
1430
-
1431
- // src/listener.ts
1432
- function on(obj, ...args) {
1433
- if (obj == null ? void 0 : obj.addEventListener) {
1434
- obj.addEventListener(...args);
1435
- }
1436
- }
1437
- function off(obj, ...args) {
1438
- if (obj == null ? void 0 : obj.removeEventListener) {
1439
- obj.removeEventListener(...args);
1440
- }
1441
- }
1442
-
1443
- // src/conditions.ts
1444
- var rulesTypes = Object.values(import_types4.RulesType);
1445
- var PRIORITIES = [
1446
- import_types4.ContentPriority.HIGHEST,
1447
- import_types4.ContentPriority.HIGH,
1448
- import_types4.ContentPriority.MEDIUM,
1449
- import_types4.ContentPriority.LOW,
1450
- import_types4.ContentPriority.LOWEST
1451
- ];
1452
- var isActiveRulesByCurrentPage = (rules) => {
1453
- const { excludes, includes } = rules.data;
1454
- if (location) {
1455
- const href = location.href;
1456
- return isMatchUrlPattern(href, includes, excludes);
1457
- }
1458
- return false;
1459
- };
1460
- var isActiveRulesByCurrentTime = (rules) => {
1461
- const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
1462
- const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
1463
- const endTime = /* @__PURE__ */ new Date(`${endDate} ${endDateHour}:${endDateMinute}:00`);
1464
- const now = /* @__PURE__ */ new Date();
1465
- if (!endDate) {
1466
- return (0, import_date_fns.isAfter)(now, startTime);
1467
- }
1468
- return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
1469
- };
1470
- var isActivedContentRulesCondition = (rules, contentSession) => {
1471
- const { contentId, logic } = rules.data;
1472
- const { latestSession, seenSessions, completedSessions } = contentSession;
1473
- if (!contentId || !logic || contentId !== contentSession.contentId) {
1474
- return false;
1475
- }
1476
- if (logic === import_types4.ContentConditionLogic.ACTIVED || logic === import_types4.ContentConditionLogic.UNACTIVED) {
1477
- if (!latestSession) {
1478
- return logic === import_types4.ContentConditionLogic.UNACTIVED;
1479
- }
1480
- const isActived = !(flowIsDismissed(latestSession) || checklistIsDimissed(latestSession));
1481
- return logic === import_types4.ContentConditionLogic.ACTIVED ? isActived : !isActived;
1482
- }
1483
- const isSeen = seenSessions > 0;
1484
- const isCompleted = completedSessions > 0;
1485
- if (logic === import_types4.ContentConditionLogic.SEEN || logic === import_types4.ContentConditionLogic.UNSEEN) {
1486
- return logic === import_types4.ContentConditionLogic.SEEN ? isSeen : !isSeen;
1487
- }
1488
- if (logic === import_types4.ContentConditionLogic.COMPLETED || logic === import_types4.ContentConditionLogic.UNCOMPLETED) {
1489
- return logic === import_types4.ContentConditionLogic.COMPLETED ? isCompleted : !isCompleted;
1490
- }
1491
- return false;
1492
- };
1493
- var isVisible = async (el) => {
1494
- var _a, _b;
1495
- if (!((_a = document2) == null ? void 0 : _a.body)) {
1496
- return false;
1497
- }
1498
- const { middlewareData } = await (0, import_dom.computePosition)(el, document2.body, {
1499
- strategy: "fixed",
1500
- middleware: [(0, import_dom.hide)()]
1501
- });
1502
- if ((_b = middlewareData == null ? void 0 : middlewareData.hide) == null ? void 0 : _b.referenceHidden) {
1503
- return false;
1504
- }
1505
- return true;
1506
- };
1507
- var cache = /* @__PURE__ */ new Map();
1508
- var isClicked = (el) => {
1509
- if (cache.has(el)) {
1510
- return cache.get(el);
1511
- }
1512
- const onClick = () => {
1513
- cache.set(el, true);
1514
- off(el, "click", onClick);
1515
- };
1516
- on(el, "click", onClick);
1517
- cache.set(el, false);
1518
- return false;
1519
- };
1520
- var isActiveRulesByElement = async (rules) => {
1521
- const { data } = rules;
1522
- if (!document2) {
1523
- return false;
1524
- }
1525
- const el = finderV2(data.elementData, document2);
1526
- const isPresent = el ? await isVisible(el) : false;
1527
- const isDisabled = el ? el.disabled : false;
1528
- switch (data.logic) {
1529
- case import_types4.ElementConditionLogic.PRESENT:
1530
- return isPresent;
1531
- case import_types4.ElementConditionLogic.UNPRESENT:
1532
- return !isPresent;
1533
- case import_types4.ElementConditionLogic.DISABLED:
1534
- return el && isDisabled;
1535
- case import_types4.ElementConditionLogic.UNDISABLED:
1536
- return el && !isDisabled;
1537
- case import_types4.ElementConditionLogic.CLICKED:
1538
- return el && isClicked(el);
1539
- case import_types4.ElementConditionLogic.UNCLICKED:
1540
- return el && !isClicked(el);
1541
- default:
1542
- return false;
1543
- }
1544
- };
1545
- var isActiveRulesByTextInput = async (rules) => {
1546
- const {
1547
- data: { elementData, logic, value }
1548
- } = rules;
1549
- if (!document2) {
1550
- return false;
1551
- }
1552
- const el = finderV2(elementData, document2);
1553
- if (!el) {
1554
- return false;
1555
- }
1556
- const elValue = el.value;
1557
- switch (logic) {
1558
- case import_types4.StringConditionLogic.IS:
1559
- return elValue === value;
1560
- case import_types4.StringConditionLogic.NOT:
1561
- return elValue !== value;
1562
- case import_types4.StringConditionLogic.CONTAINS:
1563
- return elValue.includes(value);
1564
- case import_types4.StringConditionLogic.NOT_CONTAIN:
1565
- return !elValue.includes(value);
1566
- case import_types4.StringConditionLogic.STARTS_WITH:
1567
- return elValue.startsWith(value);
1568
- case import_types4.StringConditionLogic.ENDS_WITH:
1569
- return elValue.endsWith(value);
1570
- case import_types4.StringConditionLogic.MATCH:
1571
- return elValue.search(value) !== -1;
1572
- case import_types4.StringConditionLogic.UNMATCH:
1573
- return elValue.search(value) === -1;
1574
- case import_types4.StringConditionLogic.ANY:
1575
- return true;
1576
- case import_types4.StringConditionLogic.EMPTY:
1577
- return !elValue;
1578
- default:
1579
- return false;
1580
- }
1581
- };
1582
- var fillCache = /* @__PURE__ */ new Map();
1583
- var isActiveRulesByTextFill = async (rules) => {
1584
- const {
1585
- data: { elementData }
1586
- } = rules;
1587
- if (!document2) {
1588
- return false;
1589
- }
1590
- const el = finderV2(elementData, document2);
1591
- if (!el) {
1592
- return false;
1593
- }
1594
- const now = (/* @__PURE__ */ new Date()).getTime();
1595
- const onKeyup = () => {
1596
- const cacheData = fillCache.get(el);
1597
- const data = { ...cacheData, timestamp: (/* @__PURE__ */ new Date()).getTime() };
1598
- fillCache.set(el, data);
1599
- };
1600
- if (fillCache.has(el)) {
1601
- const { timestamp, value, isActive: isActive2 } = fillCache.get(el);
1602
- if (isActive2) {
1603
- return true;
1604
- }
1605
- if (timestamp !== -1 && now - timestamp > 1e3 && value !== el.value) {
1606
- off(document2, "click", onKeyup);
1607
- fillCache.set(el, { timestamp, value, isActive: true });
1608
- return true;
1609
- }
1610
- return false;
1611
- }
1612
- on(document2, "keyup", onKeyup);
1613
- fillCache.set(el, { timestamp: -1, value: el.value, isActive: false });
1614
- return false;
1615
- };
1616
- var isValidRulesType = (type) => {
1617
- return rulesTypes.includes(type);
1618
- };
1619
- var isActiveRules = async (rules) => {
1620
- if (!isValidRulesType(rules.type)) {
1621
- return true;
1622
- }
1623
- switch (rules.type) {
1624
- case import_types4.RulesType.CURRENT_PAGE:
1625
- return isActiveRulesByCurrentPage(rules);
1626
- case import_types4.RulesType.TIME:
1627
- return isActiveRulesByCurrentTime(rules);
1628
- case import_types4.RulesType.ELEMENT:
1629
- return await isActiveRulesByElement(rules);
1630
- case import_types4.RulesType.TEXT_INPUT:
1631
- return await isActiveRulesByTextInput(rules);
1632
- case import_types4.RulesType.TEXT_FILL:
1633
- return await isActiveRulesByTextFill(rules);
1634
- default:
1635
- return rules.actived;
1636
- }
1637
- };
1638
- var activedRulesConditions = async (conditions, rewrite) => {
1639
- const rulesCondition = [...conditions];
1640
- for (let j = 0; j < rulesCondition.length; j++) {
1641
- const rules = rulesCondition[j];
1642
- if (rules.type !== "group") {
1643
- if (rewrite == null ? void 0 : rewrite[rules.type]) {
1644
- rulesCondition[j].actived = true;
1645
- } else {
1646
- rulesCondition[j].actived = await isActiveRules(rules);
1647
- }
1648
- } else if (rules.conditions) {
1649
- rulesCondition[j].conditions = await activedRulesConditions(rules.conditions);
1650
- }
1651
- }
1652
- return rulesCondition;
1653
- };
1654
- var activedContentRulesConditions = async (conditions, contents) => {
1655
- const rulesCondition = [...conditions];
1656
- for (let j = 0; j < rulesCondition.length; j++) {
1657
- const rules = rulesCondition[j];
1658
- if (rules.type !== "group") {
1659
- if (rules.type === import_types4.RulesType.CONTENT) {
1660
- const content = contents.find((c) => c.contentId === rules.data.contentId);
1661
- if (content) {
1662
- const contentSession = {
1663
- contentId: content.contentId,
1664
- latestSession: content.latestSession,
1665
- totalSessions: content.totalSessions,
1666
- dismissedSessions: content.dismissedSessions,
1667
- completedSessions: content.completedSessions,
1668
- seenSessions: content.seenSessions
1669
- };
1670
- rulesCondition[j].actived = isActivedContentRulesCondition(rules, contentSession);
1671
- }
1672
- }
1673
- } else if (rules.conditions) {
1674
- rulesCondition[j].conditions = await activedContentRulesConditions(
1675
- rules.conditions,
1676
- contents
1677
- );
1678
- }
1679
- }
1680
- return rulesCondition;
1681
- };
1682
- var activedContentCondition = async (contents) => {
1683
- const _contents = JSON.parse(JSON.stringify(contents));
1684
- for (let index = 0; index < _contents.length; index++) {
1685
- const content = _contents[index];
1686
- const { enabledAutoStartRules, autoStartRules, hideRules, enabledHideRules } = content.config;
1687
- if (enabledAutoStartRules && autoStartRules && autoStartRules.length > 0) {
1688
- content.config.autoStartRules = await activedRulesConditions(autoStartRules);
1689
- }
1690
- if (enabledHideRules && hideRules && hideRules.length > 0) {
1691
- content.config.hideRules = await activedRulesConditions(hideRules);
1692
- }
1693
- }
1694
- return _contents;
1695
- };
1696
- var isActive = (autoStartRules) => {
1697
- if (!autoStartRules || autoStartRules.length === 0) {
1698
- return false;
1699
- }
1700
- const operator = autoStartRules[0].operators;
1701
- const actives = autoStartRules.filter((rule) => {
1702
- if (!rule.conditions) {
1703
- return rule.actived;
1704
- }
1705
- return isActive(rule.conditions);
1706
- });
1707
- return operator === "and" ? actives.length === autoStartRules.length : actives.length > 0;
1708
- };
1709
- var isActiveContent = (content) => {
1710
- const { enabledAutoStartRules, autoStartRules } = content.config;
1711
- if (!enabledAutoStartRules || !isActive(autoStartRules)) {
1712
- return false;
1713
- }
1714
- return true;
1715
- };
1716
- var priorityCompare = (a, b) => {
1717
- var _a, _b, _c, _d;
1718
- const a1 = (_b = (_a = a == null ? void 0 : a.config) == null ? void 0 : _a.autoStartRulesSetting) == null ? void 0 : _b.priority;
1719
- const a2 = (_d = (_c = b == null ? void 0 : b.config) == null ? void 0 : _c.autoStartRulesSetting) == null ? void 0 : _d.priority;
1720
- if (!a1 || !a2) {
1721
- return 0;
1722
- }
1723
- const index1 = PRIORITIES.indexOf(a1);
1724
- const index2 = PRIORITIES.indexOf(a2);
1725
- if (index1 > index2) {
1726
- return 1;
1727
- }
1728
- if (index1 < index2) {
1729
- return -1;
1730
- }
1731
- return 0;
1732
- };
1733
- var filterAutoStartContent = (contents, type) => {
1734
- return contents.filter((content) => {
1735
- const isActive2 = isActiveContent(content);
1736
- const isValid = isValidContent(content, contents);
1737
- return content.type === type && isActive2 && isValid;
1738
- }).sort(priorityCompare);
1739
- };
1740
- var isHasActivedContents = (source, dest) => {
1741
- for (let index = 0; index < source.length; index++) {
1742
- const content1 = source[index];
1743
- const content2 = dest.find((c) => c.id === content1.id);
1744
- if (!content2) {
1745
- return true;
1746
- }
1747
- if (isActiveContent(content1) !== isActiveContent(content2)) {
1748
- return true;
1749
- }
1750
- }
1751
- return false;
1752
- };
1753
- var isSameContents = (source, dest) => {
1754
- if (!source || !dest || source.length !== dest.length) {
1755
- return false;
1756
- }
1757
- for (let index = 0; index < source.length; index++) {
1758
- const content1 = source[index];
1759
- const content2 = dest.find((c) => c.id === content1.id);
1760
- if (!content2) {
1761
- return false;
1762
- }
1763
- if (!conditionsIsSame(content1.config.autoStartRules, content2.config.autoStartRules)) {
1764
- return false;
1765
- }
1766
- }
1767
- return true;
1768
- };
1769
- var getLatestEvent = (currentContent, contents, eventCodeName) => {
1770
- var _a;
1771
- const bizEvents = [];
1772
- const contentId = currentContent.id;
1773
- const contentType = currentContent.type;
1774
- for (let index = 0; index < contents.length; index++) {
1775
- const content = contents[index];
1776
- if (content.id === contentId || content.type !== contentType) {
1777
- continue;
1778
- }
1779
- const sessionBizEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
1780
- if (sessionBizEvents && sessionBizEvents.length > 0) {
1781
- bizEvents.push(...sessionBizEvents.filter((e) => {
1782
- var _a2;
1783
- return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === eventCodeName;
1784
- }));
1785
- }
1786
- }
1787
- return findLatestEvent(bizEvents);
1788
- };
1789
- var findLatestEvent = (bizEvents) => {
1790
- const initialValue = bizEvents[0];
1791
- const lastEvent = bizEvents.reduce(
1792
- (accumulator, currentValue) => {
1793
- if ((0, import_date_fns.isAfter)(new Date(currentValue.createdAt), new Date(accumulator.createdAt))) {
1794
- return currentValue;
1795
- }
1796
- return accumulator;
1797
- },
1798
- initialValue
1799
- );
1800
- return lastEvent;
1801
- };
1802
- var showEventMapping = {
1803
- [import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_STEP_SEEN,
1804
- [import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_SEEN,
1805
- [import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_SEEN
1806
- };
1807
- var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
1808
- switch (unit) {
1809
- case import_types4.FrequencyUnits.SECONDS: {
1810
- if ((0, import_date_fns.differenceInSeconds)(dateLeft, dateRight) >= duration) {
1811
- return true;
1812
- }
1813
- return false;
1814
- }
1815
- case import_types4.FrequencyUnits.MINUTES:
1816
- if ((0, import_date_fns.differenceInMinutes)(dateLeft, dateRight) >= duration) {
1817
- return true;
1818
- }
1819
- return false;
1820
- case import_types4.FrequencyUnits.HOURS:
1821
- if ((0, import_date_fns.differenceInHours)(dateLeft, dateRight) >= duration) {
1822
- return true;
1823
- }
1824
- return false;
1825
- case import_types4.FrequencyUnits.DAYES:
1826
- if ((0, import_date_fns.differenceInDays)(dateLeft, dateRight) >= duration) {
1827
- return true;
1828
- }
1829
- return false;
1830
- default:
1831
- return false;
1832
- }
1833
- };
1834
- var checklistIsDimissed = (latestSession) => {
1835
- var _a;
1836
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1837
- (event) => {
1838
- var _a2;
1839
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_DISMISSED;
1840
- }
1841
- );
1842
- };
1843
- var flowIsDismissed = (latestSession) => {
1844
- var _a;
1845
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find((event) => {
1846
- var _a2;
1847
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_ENDED;
1848
- });
1849
- };
1850
- var flowIsSeen = (latestSession) => {
1851
- var _a;
1852
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1853
- (event) => {
1854
- var _a2;
1855
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_STEP_SEEN;
1856
- }
1857
- );
1858
- };
1859
- var checklistIsSeen = (latestSession) => {
1860
- var _a;
1861
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1862
- (event) => {
1863
- var _a2;
1864
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_SEEN;
1865
- }
1866
- );
1867
- };
1868
- var isValidContent = (content, contents) => {
1869
- var _a;
1870
- const now = /* @__PURE__ */ new Date();
1871
- if (content.type === import_types4.ContentDataType.FLOW) {
1872
- if (!content.steps || content.steps.length === 0) {
1873
- return false;
1874
- }
1875
- } else {
1876
- if (!content.data) {
1877
- return false;
1878
- }
1879
- }
1880
- if (!content.config.autoStartRulesSetting) {
1881
- return true;
1882
- }
1883
- const { frequency, startIfNotComplete } = content.config.autoStartRulesSetting;
1884
- const completedSessions = content.completedSessions;
1885
- const dismissedSessions = content.dismissedSessions;
1886
- if (startIfNotComplete && completedSessions > 0) {
1887
- return false;
1888
- }
1889
- if (!frequency) {
1890
- return true;
1891
- }
1892
- const contentType = content.type;
1893
- const lastEventName = showEventMapping[contentType];
1894
- const lastEvent = getLatestEvent(content, contents, lastEventName);
1895
- const contentEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
1896
- if (lastEvent && frequency && frequency.atLeast && !isGreaterThenDuration(
1897
- now,
1898
- new Date(lastEvent.createdAt),
1899
- frequency.atLeast.unit,
1900
- frequency.atLeast.duration
1901
- )) {
1902
- return false;
1903
- }
1904
- if (frequency.frequency === import_types4.Frequency.ONCE) {
1905
- if (dismissedSessions > 0) {
1906
- return false;
1907
- }
1908
- return true;
1909
- }
1910
- const showEventName = showEventMapping[contentType];
1911
- const showEvents = contentEvents == null ? void 0 : contentEvents.filter(
1912
- (e) => {
1913
- var _a2, _b;
1914
- return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === showEventName && (contentType === import_types4.ContentDataType.FLOW ? ((_b = e == null ? void 0 : e.data) == null ? void 0 : _b.flow_step_number) === 0 : true);
1915
- }
1916
- );
1917
- if (!showEvents || showEvents.length === 0) {
1918
- return true;
1919
- }
1920
- const lastShowEvent = findLatestEvent(showEvents);
1921
- const lastShowEventDate = new Date(lastShowEvent.createdAt);
1922
- if (frequency.frequency === import_types4.Frequency.MULTIPLE) {
1923
- if (frequency.every.times && dismissedSessions >= frequency.every.times) {
1924
- return false;
1925
- }
1926
- }
1927
- if (frequency.frequency === import_types4.Frequency.MULTIPLE || frequency.frequency === import_types4.Frequency.UNLIMITED) {
1928
- if (!isGreaterThenDuration(now, lastShowEventDate, frequency.every.unit, frequency.every.duration)) {
1929
- return false;
1930
- }
1931
- }
1932
- return true;
1933
- };
1934
- var parseUrlParams = (url, paramName) => {
1935
- if (!url || !paramName) {
1936
- return null;
1937
- }
1938
- try {
1939
- const urlObj = new URL(url);
1940
- const searchParams = new URLSearchParams(urlObj.search);
1941
- if (searchParams.has(paramName)) {
1942
- return searchParams.get(paramName);
1943
- }
1944
- if (urlObj.hash) {
1945
- const hashSearch = urlObj.hash.split("?")[1];
1946
- if (hashSearch) {
1947
- const hashParams = new URLSearchParams(hashSearch);
1948
- if (hashParams.has(paramName)) {
1949
- return hashParams.get(paramName);
1950
- }
1951
- }
1952
- }
1953
- return null;
1954
- } catch (error) {
1955
- console.error("Error parsing URL:", error);
1956
- return null;
1957
- }
1958
- };
1959
- var wait = (seconds) => {
1960
- if (typeof seconds !== "number" || Number.isNaN(seconds)) {
1961
- return Promise.reject(new Error("Invalid wait time: must be a number"));
1962
- }
1963
- if (seconds < 0) {
1964
- return Promise.reject(new Error("Invalid wait time: cannot be negative"));
1965
- }
1966
- if (seconds === 0) {
1967
- return Promise.resolve();
1968
- }
1969
- return new Promise((resolve, reject) => {
1970
- try {
1971
- setTimeout(resolve, seconds * 1e3);
1972
- } catch (error) {
1973
- reject(error);
1974
- }
1975
- });
1976
- };
1977
1089
  // Annotate the CommonJS export names for ESM import in node:
1978
1090
  0 && (module.exports = {
1979
1091
  AbortController,
1980
1092
  ArrayProto,
1981
- PRIORITIES,
1982
1093
  XMLHttpRequest,
1983
1094
  absoluteUrl,
1984
- activedContentCondition,
1985
- activedContentRulesConditions,
1986
- activedRulesConditions,
1987
1095
  assignableWindow,
1988
1096
  autoStartConditions,
1989
1097
  buildConfig,
1990
- checklistIsDimissed,
1991
- checklistIsSeen,
1992
1098
  cn,
1993
1099
  conditionsIsSame,
1994
1100
  convertSettings,
@@ -2000,13 +1106,6 @@ var wait = (seconds) => {
2000
1106
  document,
2001
1107
  evalCode,
2002
1108
  fetch,
2003
- filterAutoStartContent,
2004
- findLatestEvent,
2005
- finder,
2006
- finderV2,
2007
- finderX,
2008
- flowIsDismissed,
2009
- flowIsSeen,
2010
1109
  formatDate,
2011
1110
  generateAutoStateColors,
2012
1111
  getAuthToken,
@@ -2029,8 +1128,6 @@ var wait = (seconds) => {
2029
1128
  hexToHSLString,
2030
1129
  hexToRGBStr,
2031
1130
  hexToRgb,
2032
- isActive,
2033
- isActiveContent,
2034
1131
  isArray,
2035
1132
  isBoolean,
2036
1133
  isDark,
@@ -2042,7 +1139,6 @@ var wait = (seconds) => {
2042
1139
  isFile,
2043
1140
  isFormData,
2044
1141
  isFunction,
2045
- isHasActivedContents,
2046
1142
  isMatchUrlPattern,
2047
1143
  isNull,
2048
1144
  isNullish,
@@ -2050,27 +1146,20 @@ var wait = (seconds) => {
2050
1146
  isObject,
2051
1147
  isPublishedAtLeastOneEnvironment,
2052
1148
  isPublishedInAllEnvironments,
2053
- isSameContents,
2054
1149
  isString,
2055
1150
  isUint8Array,
2056
1151
  isUndefined,
2057
1152
  isUrl,
2058
- isValidContent,
2059
1153
  isValidSelector,
2060
- isVisible,
2061
1154
  location,
2062
1155
  mergeThemeDefaultSettings,
2063
1156
  nativeForEach,
2064
1157
  nativeIndexOf,
2065
1158
  navigator,
2066
- parseUrlParams,
2067
- parserV2,
2068
- parserX,
2069
1159
  removeAuthToken,
2070
1160
  setAuthToken,
2071
1161
  storage,
2072
1162
  userAgent,
2073
1163
  uuidV4,
2074
- wait,
2075
1164
  window
2076
1165
  });