@usertour/helpers 0.0.13 → 0.0.14

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
@@ -40,6 +40,7 @@ __export(src_exports, {
40
40
  XMLHttpRequest: () => XMLHttpRequest,
41
41
  absoluteUrl: () => absoluteUrl,
42
42
  activedContentRulesConditions: () => activedContentRulesConditions,
43
+ activedRulesConditions: () => activedRulesConditions,
43
44
  assignableWindow: () => assignableWindow,
44
45
  autoStartConditions: () => autoStartConditions,
45
46
  buildConfig: () => buildConfig,
@@ -57,6 +58,7 @@ __export(src_exports, {
57
58
  evalCode: () => evalCode,
58
59
  fetch: () => fetch,
59
60
  filterAutoStartContent: () => filterAutoStartContent,
61
+ findLatestEvent: () => findLatestEvent,
60
62
  flowIsDismissed: () => flowIsDismissed,
61
63
  flowIsSeen: () => flowIsSeen,
62
64
  formatDate: () => formatDate,
@@ -81,6 +83,7 @@ __export(src_exports, {
81
83
  hexToHSLString: () => hexToHSLString,
82
84
  hexToRGBStr: () => hexToRGBStr,
83
85
  hexToRgb: () => hexToRgb,
86
+ isActive: () => isActive,
84
87
  isActiveRulesByCurrentTime: () => isActiveRulesByCurrentTime,
85
88
  isArray: () => isArray,
86
89
  isBoolean: () => isBoolean,
@@ -1107,6 +1110,14 @@ var PRIORITIES = [
1107
1110
  import_types4.ContentPriority.LOWEST
1108
1111
  ];
1109
1112
  var rulesTypes = Object.values(import_types4.RulesType);
1113
+ var isActiveRulesByCurrentPage = (rules) => {
1114
+ const { excludes, includes } = rules.data;
1115
+ if (location) {
1116
+ const href = location.href;
1117
+ return isMatchUrlPattern(href, includes, excludes);
1118
+ }
1119
+ return false;
1120
+ };
1110
1121
  var isActiveRulesByCurrentTime = (rules) => {
1111
1122
  const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
1112
1123
  const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
@@ -1140,6 +1151,38 @@ var isActivedContentRulesCondition = (rules, contentSession) => {
1140
1151
  }
1141
1152
  return false;
1142
1153
  };
1154
+ var isValidRulesType = (type) => {
1155
+ return rulesTypes.includes(type);
1156
+ };
1157
+ var isActiveRules = async (rules) => {
1158
+ if (!isValidRulesType(rules.type)) {
1159
+ return true;
1160
+ }
1161
+ switch (rules.type) {
1162
+ case import_types4.RulesType.CURRENT_PAGE:
1163
+ return isActiveRulesByCurrentPage(rules);
1164
+ case import_types4.RulesType.TIME:
1165
+ return isActiveRulesByCurrentTime(rules);
1166
+ default:
1167
+ return rules.actived;
1168
+ }
1169
+ };
1170
+ var activedRulesConditions = async (conditions, rewrite) => {
1171
+ const rulesCondition = [...conditions];
1172
+ for (let j = 0; j < rulesCondition.length; j++) {
1173
+ const rules = rulesCondition[j];
1174
+ if (rules.type !== "group") {
1175
+ if (rewrite == null ? void 0 : rewrite[rules.type]) {
1176
+ rulesCondition[j].actived = true;
1177
+ } else {
1178
+ rulesCondition[j].actived = await isActiveRules(rules);
1179
+ }
1180
+ } else if (rules.conditions) {
1181
+ rulesCondition[j].conditions = await activedRulesConditions(rules.conditions);
1182
+ }
1183
+ }
1184
+ return rulesCondition;
1185
+ };
1143
1186
  var activedContentRulesConditions = async (conditions, contents) => {
1144
1187
  const rulesCondition = [...conditions];
1145
1188
  for (let j = 0; j < rulesCondition.length; j++) {
@@ -1419,6 +1462,7 @@ var parseUrlParams = (url, paramName) => {
1419
1462
  XMLHttpRequest,
1420
1463
  absoluteUrl,
1421
1464
  activedContentRulesConditions,
1465
+ activedRulesConditions,
1422
1466
  assignableWindow,
1423
1467
  autoStartConditions,
1424
1468
  buildConfig,
@@ -1436,6 +1480,7 @@ var parseUrlParams = (url, paramName) => {
1436
1480
  evalCode,
1437
1481
  fetch,
1438
1482
  filterAutoStartContent,
1483
+ findLatestEvent,
1439
1484
  flowIsDismissed,
1440
1485
  flowIsSeen,
1441
1486
  formatDate,
@@ -1460,6 +1505,7 @@ var parseUrlParams = (url, paramName) => {
1460
1505
  hexToHSLString,
1461
1506
  hexToRGBStr,
1462
1507
  hexToRgb,
1508
+ isActive,
1463
1509
  isActiveRulesByCurrentTime,
1464
1510
  isArray,
1465
1511
  isBoolean,
package/dist/index.d.cts CHANGED
@@ -11,7 +11,7 @@ export { isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from '
11
11
  export { deepClone } from './utils.cjs';
12
12
  export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
13
13
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
14
- export { activedContentRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, flowIsDismissed, flowIsSeen, isActiveRulesByCurrentTime, isValidContent, parseUrlParams } from './conditions.cjs';
14
+ export { activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveRulesByCurrentTime, isValidContent, parseUrlParams } from './conditions.cjs';
15
15
  export { default as isEqual } from 'fast-deep-equal';
16
16
  import '@usertour/types';
17
17
  import './storage.cjs';
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from '
11
11
  export { deepClone } from './utils.js';
12
12
  export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
13
13
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
14
- export { activedContentRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, flowIsDismissed, flowIsSeen, isActiveRulesByCurrentTime, isValidContent, parseUrlParams } from './conditions.js';
14
+ export { activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveRulesByCurrentTime, isValidContent, parseUrlParams } from './conditions.js';
15
15
  export { default as isEqual } from 'fast-deep-equal';
16
16
  import '@usertour/types';
17
17
  import './storage.js';
package/dist/index.js CHANGED
@@ -41,11 +41,14 @@ import {
41
41
  } from "./chunk-H7VA3ML2.js";
42
42
  import {
43
43
  activedContentRulesConditions,
44
+ activedRulesConditions,
44
45
  checklistIsDimissed,
45
46
  checklistIsSeen,
46
47
  filterAutoStartContent,
48
+ findLatestEvent,
47
49
  flowIsDismissed,
48
50
  flowIsSeen,
51
+ isActive,
49
52
  isActiveRulesByCurrentTime,
50
53
  isValidContent,
51
54
  parseUrlParams
@@ -117,6 +120,7 @@ export {
117
120
  XMLHttpRequest,
118
121
  absoluteUrl,
119
122
  activedContentRulesConditions,
123
+ activedRulesConditions,
120
124
  assignableWindow,
121
125
  autoStartConditions,
122
126
  buildConfig,
@@ -134,6 +138,7 @@ export {
134
138
  evalCode,
135
139
  fetch,
136
140
  filterAutoStartContent,
141
+ findLatestEvent,
137
142
  flowIsDismissed,
138
143
  flowIsSeen,
139
144
  formatDate,
@@ -158,6 +163,7 @@ export {
158
163
  hexToHSLString,
159
164
  hexToRGBStr,
160
165
  hexToRgb,
166
+ isActive,
161
167
  isActiveRulesByCurrentTime,
162
168
  isArray,
163
169
  isBoolean,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",