@usertour/helpers 0.0.14 → 0.0.15

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
@@ -39,13 +39,9 @@ __export(src_exports, {
39
39
  ArrayProto: () => ArrayProto,
40
40
  XMLHttpRequest: () => XMLHttpRequest,
41
41
  absoluteUrl: () => absoluteUrl,
42
- activedContentRulesConditions: () => activedContentRulesConditions,
43
- activedRulesConditions: () => activedRulesConditions,
44
42
  assignableWindow: () => assignableWindow,
45
43
  autoStartConditions: () => autoStartConditions,
46
44
  buildConfig: () => buildConfig,
47
- checklistIsDimissed: () => checklistIsDimissed,
48
- checklistIsSeen: () => checklistIsSeen,
49
45
  cn: () => cn,
50
46
  conditionsIsSame: () => conditionsIsSame,
51
47
  convertSettings: () => convertSettings,
@@ -57,10 +53,6 @@ __export(src_exports, {
57
53
  document: () => document,
58
54
  evalCode: () => evalCode,
59
55
  fetch: () => fetch,
60
- filterAutoStartContent: () => filterAutoStartContent,
61
- findLatestEvent: () => findLatestEvent,
62
- flowIsDismissed: () => flowIsDismissed,
63
- flowIsSeen: () => flowIsSeen,
64
56
  formatDate: () => formatDate,
65
57
  generateAutoStateColors: () => generateAutoStateColors,
66
58
  getAuthToken: () => getAuthToken,
@@ -83,8 +75,6 @@ __export(src_exports, {
83
75
  hexToHSLString: () => hexToHSLString,
84
76
  hexToRGBStr: () => hexToRGBStr,
85
77
  hexToRgb: () => hexToRgb,
86
- isActive: () => isActive,
87
- isActiveRulesByCurrentTime: () => isActiveRulesByCurrentTime,
88
78
  isArray: () => isArray,
89
79
  isBoolean: () => isBoolean,
90
80
  isDark: () => isDark,
@@ -107,14 +97,12 @@ __export(src_exports, {
107
97
  isUint8Array: () => isUint8Array,
108
98
  isUndefined: () => isUndefined,
109
99
  isUrl: () => isUrl,
110
- isValidContent: () => isValidContent,
111
100
  isValidSelector: () => isValidSelector,
112
- location: () => location2,
101
+ location: () => location,
113
102
  mergeThemeDefaultSettings: () => mergeThemeDefaultSettings,
114
103
  nativeForEach: () => nativeForEach,
115
104
  nativeIndexOf: () => nativeIndexOf,
116
105
  navigator: () => navigator,
117
- parseUrlParams: () => parseUrlParams,
118
106
  removeAuthToken: () => removeAuthToken,
119
107
  setAuthToken: () => setAuthToken,
120
108
  storage: () => storage,
@@ -453,169 +441,8 @@ var convertToCssVars = (settings, type = "tooltip") => {
453
441
  return css;
454
442
  };
455
443
 
456
- // src/condition.ts
457
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
458
- var parseUrl = (url) => {
459
- const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
460
- if (!urlPatterns) {
461
- return null;
462
- }
463
- const [, , scheme = "", domain = "", path = "", , query = "", fragment = ""] = urlPatterns;
464
- return { scheme, domain, path, query, fragment };
465
- };
466
- var replaceWildcard = (input, s1, s2) => {
467
- const withSpecialWords = replaceSpecialWords(input);
468
- const withWildcard = withSpecialWords.replace(/\\\*/g, `${s1}*`);
469
- if (!s2) {
470
- return withWildcard;
471
- }
472
- return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
473
- };
474
- var replaceSpecialWords = (str) => {
475
- return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
476
- };
477
- var parsePattern = (pattern) => {
478
- if (!pattern || !pattern.trim()) {
479
- return null;
480
- }
481
- const _pattern = parseUrl(pattern);
482
- if (!_pattern) {
483
- console.error("Invalid URL pattern:", pattern);
484
- return null;
485
- }
486
- const { scheme, domain, path, query, fragment } = _pattern;
487
- const _scheme = scheme ? replaceSpecialWords(scheme) : "[a-z\\d]+";
488
- const _domain = domain ? replaceWildcard(domain, "[^/]", ".") : "[^/]*";
489
- const _fragment = fragment ? replaceWildcard(fragment, ".", "/") : "(#.*)?";
490
- const _path = path ? replaceWildcard(path, "[^?#]", "/") : "/[^?#]*";
491
- let _query = "(\\?[^#]*)?";
492
- if (query) {
493
- new URLSearchParams(query).forEach((value, key) => {
494
- const _str = value === "" ? "=?" : value === "*" ? "(=[^&#]*)?" : `=${replaceWildcard(value, "[^#]")}`;
495
- _query += `(?=.*[?&]${replaceSpecialWords(key)}${_str}([&#]|$))`;
496
- });
497
- _query += "\\?[^#]*";
498
- }
499
- return new RegExp(`^${_scheme}://${_domain}(:\\d+)?${_path}${_query}${_fragment}$`);
500
- };
501
- var isMatchUrlPattern = (_url, includes, excludes) => {
502
- const isMatchIncludesConditions = includes.length > 0 ? includes.some((_include) => {
503
- const reg = parsePattern(_include);
504
- if (reg) {
505
- return reg.test(_url);
506
- }
507
- return false;
508
- }) : true;
509
- const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
510
- const reg = parsePattern(_exclude);
511
- if (reg) {
512
- return reg.test(_url);
513
- }
514
- return false;
515
- }) : false;
516
- return isMatchIncludesConditions && !isMatchExcludesConditions;
517
- };
518
- var compareConditionsItem = (item1, item2) => {
519
- const { data = {}, ...others1 } = item1;
520
- const { data: data2 = {}, ...others2 } = item2;
521
- if (!(0, import_fast_deep_equal.default)(others2, others1)) {
522
- return false;
523
- }
524
- for (const key in data) {
525
- if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
526
- return false;
527
- }
528
- }
529
- return true;
530
- };
531
- var conditionsIsSame = (rr1, rr2) => {
532
- const r1 = [...rr1];
533
- const r2 = [...rr2];
534
- if (r1.length === 0 && r2.length === 0) {
535
- return true;
536
- }
537
- if (r1.length !== r2.length) {
538
- return false;
539
- }
540
- const group1 = r1.filter((item) => item.type === "group");
541
- const group2 = r2.filter((item) => item.type === "group");
542
- if (group1.length !== group2.length) {
543
- return false;
544
- }
545
- for (let index = 0; index < r1.length; index++) {
546
- const item1 = r1[index];
547
- const item2 = r2[index];
548
- if (!item1 || !item2) {
549
- return false;
550
- }
551
- if (item1.type === "group") {
552
- if (!item2.conditions) {
553
- return false;
554
- }
555
- const c1 = item1.conditions;
556
- const c2 = item2.conditions;
557
- if (item1.operators !== item2.operators) {
558
- return false;
559
- }
560
- if (!conditionsIsSame(c1, c2)) {
561
- return false;
562
- }
563
- } else {
564
- if (!compareConditionsItem(item1, item2)) {
565
- return false;
566
- }
567
- }
568
- }
569
- return true;
570
- };
571
-
572
- // src/content-settings.ts
573
- var import_types2 = require("@usertour/types");
574
- var import_deepmerge_ts2 = require("deepmerge-ts");
575
- var rulesSetting = {
576
- // frequency: {
577
- // frequency: Frequency.ONCE,
578
- // every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
579
- // atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
580
- // },
581
- startIfNotComplete: false,
582
- priority: import_types2.ContentPriority.MEDIUM,
583
- wait: 0
584
- };
585
- var hideRulesSetting = {};
586
- var defaultContentConfig = {
587
- enabledAutoStartRules: false,
588
- enabledHideRules: false,
589
- autoStartRules: [],
590
- hideRules: [],
591
- autoStartRulesSetting: rulesSetting,
592
- hideRulesSetting
593
- };
594
- var autoStartConditions = {
595
- ...defaultContentConfig,
596
- enabledAutoStartRules: true,
597
- autoStartRules: [
598
- {
599
- data: { excludes: [], includes: ["/*"] },
600
- type: "current-page",
601
- operators: "and"
602
- }
603
- ]
604
- };
605
- var buildConfig = (config) => {
606
- return {
607
- ...defaultContentConfig,
608
- ...config,
609
- autoStartRulesSetting: (0, import_deepmerge_ts2.deepmerge)(
610
- defaultContentConfig.autoStartRulesSetting,
611
- (config == null ? void 0 : config.autoStartRulesSetting) || {}
612
- ),
613
- hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
614
- };
615
- };
616
-
617
444
  // src/error.ts
618
- var import_types3 = require("@usertour/types");
445
+ var import_types2 = require("@usertour/types");
619
446
  var isValidSelector = (selector) => {
620
447
  if (!selector) {
621
448
  return false;
@@ -637,9 +464,9 @@ var getUserAttrError = (data, attributes) => {
637
464
  } else if ((data == null ? void 0 : data.logic) === "between" && (!(data == null ? void 0 : data.value) || !(data == null ? void 0 : data.value2))) {
638
465
  ret.showError = true;
639
466
  ret.errorInfo = "Please enter a value";
640
- } else if ((item == null ? void 0 : item.dataType) !== import_types3.AttributeDataType.Boolean) {
467
+ } else if ((item == null ? void 0 : item.dataType) !== import_types2.AttributeDataType.Boolean) {
641
468
  if (data.logic !== "any" && data.logic !== "empty") {
642
- if ((item == null ? void 0 : item.dataType) === import_types3.AttributeDataType.List) {
469
+ if ((item == null ? void 0 : item.dataType) === import_types2.AttributeDataType.List) {
643
470
  if (!data.listValues || data.listValues.length === 0) {
644
471
  ret.showError = true;
645
472
  ret.errorInfo = "Please enter a value";
@@ -777,10 +604,10 @@ var hasError = (conds, attributes) => {
777
604
  return false;
778
605
  };
779
606
  var errorActionHandlerMapping = {
780
- [import_types3.ContentActionsItemType.STEP_GOTO]: getStepError,
781
- [import_types3.ContentActionsItemType.PAGE_NAVIGATE]: getNavitateError,
782
- [import_types3.ContentActionsItemType.FLOW_START]: getContentError,
783
- [import_types3.ContentActionsItemType.JAVASCRIPT_EVALUATE]: getCodeError
607
+ [import_types2.ContentActionsItemType.STEP_GOTO]: getStepError,
608
+ [import_types2.ContentActionsItemType.PAGE_NAVIGATE]: getNavitateError,
609
+ [import_types2.ContentActionsItemType.FLOW_START]: getContentError,
610
+ [import_types2.ContentActionsItemType.JAVASCRIPT_EVALUATE]: getCodeError
784
611
  };
785
612
  var hasActionError = (conds) => {
786
613
  for (const cond of conds) {
@@ -824,7 +651,7 @@ var nativeForEach = ArrayProto.forEach;
824
651
  var nativeIndexOf = ArrayProto.indexOf;
825
652
  var navigator = global == null ? void 0 : global.navigator;
826
653
  var document = global == null ? void 0 : global.document;
827
- var location2 = global == null ? void 0 : global.location;
654
+ var location = global == null ? void 0 : global.location;
828
655
  var fetch = global == null ? void 0 : global.fetch;
829
656
  var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
830
657
  var AbortController = global == null ? void 0 : global.AbortController;
@@ -998,6 +825,8 @@ function isUrl(string) {
998
825
  }
999
826
 
1000
827
  // src/content.ts
828
+ var import_types3 = require("@usertour/types");
829
+ var import_deepmerge_ts2 = require("deepmerge-ts");
1001
830
  var isPublishedInAllEnvironments = (content, environmentList, version) => {
1002
831
  const isPublishedInAllEnvironments2 = environmentList == null ? void 0 : environmentList.every(
1003
832
  (env) => {
@@ -1020,6 +849,47 @@ var isPublishedAtLeastOneEnvironment = (content) => {
1020
849
  }
1021
850
  return false;
1022
851
  };
852
+ var rulesSetting = {
853
+ // frequency: {
854
+ // frequency: Frequency.ONCE,
855
+ // every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
856
+ // atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
857
+ // },
858
+ startIfNotComplete: false,
859
+ priority: import_types3.ContentPriority.MEDIUM,
860
+ wait: 0
861
+ };
862
+ var hideRulesSetting = {};
863
+ var defaultContentConfig = {
864
+ enabledAutoStartRules: false,
865
+ enabledHideRules: false,
866
+ autoStartRules: [],
867
+ hideRules: [],
868
+ autoStartRulesSetting: rulesSetting,
869
+ hideRulesSetting
870
+ };
871
+ var autoStartConditions = {
872
+ ...defaultContentConfig,
873
+ enabledAutoStartRules: true,
874
+ autoStartRules: [
875
+ {
876
+ data: { excludes: [], includes: ["/*"] },
877
+ type: "current-page",
878
+ operators: "and"
879
+ }
880
+ ]
881
+ };
882
+ var buildConfig = (config) => {
883
+ return {
884
+ ...defaultContentConfig,
885
+ ...config,
886
+ autoStartRulesSetting: (0, import_deepmerge_ts2.deepmerge)(
887
+ defaultContentConfig.autoStartRulesSetting,
888
+ (config == null ? void 0 : config.autoStartRulesSetting) || {}
889
+ ),
890
+ hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
891
+ };
892
+ };
1023
893
 
1024
894
  // src/utils.ts
1025
895
  var deepClone = (obj) => {
@@ -1100,360 +970,119 @@ var getRandomColor = () => {
1100
970
  };
1101
971
 
1102
972
  // src/conditions.ts
1103
- var import_types4 = require("@usertour/types");
1104
- var import_date_fns = require("date-fns");
1105
- var PRIORITIES = [
1106
- import_types4.ContentPriority.HIGHEST,
1107
- import_types4.ContentPriority.HIGH,
1108
- import_types4.ContentPriority.MEDIUM,
1109
- import_types4.ContentPriority.LOW,
1110
- import_types4.ContentPriority.LOWEST
1111
- ];
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);
973
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
974
+ var parseUrl = (url) => {
975
+ const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
976
+ if (!urlPatterns) {
977
+ return null;
1118
978
  }
1119
- return false;
1120
- };
1121
- var isActiveRulesByCurrentTime = (rules) => {
1122
- const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
1123
- const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
1124
- const endTime = /* @__PURE__ */ new Date(`${endDate} ${endDateHour}:${endDateMinute}:00`);
1125
- const now = /* @__PURE__ */ new Date();
1126
- if (!endDate) {
1127
- return (0, import_date_fns.isAfter)(now, startTime);
1128
- }
1129
- return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
979
+ const [, , scheme = "", domain = "", path = "", , query = "", fragment = ""] = urlPatterns;
980
+ return { scheme, domain, path, query, fragment };
1130
981
  };
1131
- var isActivedContentRulesCondition = (rules, contentSession) => {
1132
- const { contentId, logic } = rules.data;
1133
- const { latestSession, seenSessions, completedSessions } = contentSession;
1134
- if (!contentId || !logic || contentId !== contentSession.contentId) {
1135
- return false;
1136
- }
1137
- if (logic === import_types4.ContentConditionLogic.ACTIVED || logic === import_types4.ContentConditionLogic.UNACTIVED) {
1138
- if (!latestSession) {
1139
- return logic === import_types4.ContentConditionLogic.UNACTIVED;
1140
- }
1141
- const isActived = !(flowIsDismissed(latestSession) || checklistIsDimissed(latestSession));
1142
- return logic === import_types4.ContentConditionLogic.ACTIVED ? isActived : !isActived;
1143
- }
1144
- const isSeen = seenSessions > 0;
1145
- const isCompleted = completedSessions > 0;
1146
- if (logic === import_types4.ContentConditionLogic.SEEN || logic === import_types4.ContentConditionLogic.UNSEEN) {
1147
- return logic === import_types4.ContentConditionLogic.SEEN ? isSeen : !isSeen;
1148
- }
1149
- if (logic === import_types4.ContentConditionLogic.COMPLETED || logic === import_types4.ContentConditionLogic.UNCOMPLETED) {
1150
- return logic === import_types4.ContentConditionLogic.COMPLETED ? isCompleted : !isCompleted;
982
+ var replaceWildcard = (input, s1, s2) => {
983
+ const withSpecialWords = replaceSpecialWords(input);
984
+ const withWildcard = withSpecialWords.replace(/\\\*/g, `${s1}*`);
985
+ if (!s2) {
986
+ return withWildcard;
1151
987
  }
1152
- return false;
988
+ return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
1153
989
  };
1154
- var isValidRulesType = (type) => {
1155
- return rulesTypes.includes(type);
990
+ var replaceSpecialWords = (str) => {
991
+ return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
1156
992
  };
1157
- var isActiveRules = async (rules) => {
1158
- if (!isValidRulesType(rules.type)) {
1159
- return true;
993
+ var parsePattern = (pattern) => {
994
+ if (!pattern || !pattern.trim()) {
995
+ return null;
1160
996
  }
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;
997
+ const _pattern = parseUrl(pattern);
998
+ if (!_pattern) {
999
+ console.error("Invalid URL pattern:", pattern);
1000
+ return null;
1168
1001
  }
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
- }
1002
+ const { scheme, domain, path, query, fragment } = _pattern;
1003
+ const _scheme = scheme ? replaceSpecialWords(scheme) : "[a-z\\d]+";
1004
+ const _domain = domain ? replaceWildcard(domain, "[^/]", ".") : "[^/]*";
1005
+ const _fragment = fragment ? replaceWildcard(fragment, ".", "/") : "(#.*)?";
1006
+ const _path = path ? replaceWildcard(path, "[^?#]", "/") : "/[^?#]*";
1007
+ let _query = "(\\?[^#]*)?";
1008
+ if (query) {
1009
+ new URLSearchParams(query).forEach((value, key) => {
1010
+ const _str = value === "" ? "=?" : value === "*" ? "(=[^&#]*)?" : `=${replaceWildcard(value, "[^#]")}`;
1011
+ _query += `(?=.*[?&]${replaceSpecialWords(key)}${_str}([&#]|$))`;
1012
+ });
1013
+ _query += "\\?[^#]*";
1183
1014
  }
1184
- return rulesCondition;
1015
+ return new RegExp(`^${_scheme}://${_domain}(:\\d+)?${_path}${_query}${_fragment}$`);
1185
1016
  };
1186
- var activedContentRulesConditions = async (conditions, contents) => {
1187
- const rulesCondition = [...conditions];
1188
- for (let j = 0; j < rulesCondition.length; j++) {
1189
- const rules = rulesCondition[j];
1190
- if (rules.type !== "group") {
1191
- if (rules.type === import_types4.RulesType.CONTENT) {
1192
- const content = contents.find((c) => c.contentId === rules.data.contentId);
1193
- if (content) {
1194
- const contentSession = {
1195
- contentId: content.contentId,
1196
- latestSession: content.latestSession,
1197
- totalSessions: content.totalSessions,
1198
- dismissedSessions: content.dismissedSessions,
1199
- completedSessions: content.completedSessions,
1200
- seenSessions: content.seenSessions
1201
- };
1202
- rulesCondition[j].actived = isActivedContentRulesCondition(rules, contentSession);
1203
- }
1204
- }
1205
- } else if (rules.conditions) {
1206
- rulesCondition[j].conditions = await activedContentRulesConditions(
1207
- rules.conditions,
1208
- contents
1209
- );
1017
+ var isMatchUrlPattern = (_url, includes, excludes) => {
1018
+ const isMatchIncludesConditions = includes.length > 0 ? includes.some((_include) => {
1019
+ const reg = parsePattern(_include);
1020
+ if (reg) {
1021
+ return reg.test(_url);
1210
1022
  }
1211
- }
1212
- return rulesCondition;
1213
- };
1214
- var isActive = (autoStartRules) => {
1215
- if (!autoStartRules || autoStartRules.length === 0) {
1216
1023
  return false;
1217
- }
1218
- const operator = autoStartRules[0].operators;
1219
- const actives = autoStartRules.filter((rule) => {
1220
- if (!rule.conditions) {
1221
- return rule.actived;
1024
+ }) : true;
1025
+ const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
1026
+ const reg = parsePattern(_exclude);
1027
+ if (reg) {
1028
+ return reg.test(_url);
1222
1029
  }
1223
- return isActive(rule.conditions);
1224
- });
1225
- return operator === "and" ? actives.length === autoStartRules.length : actives.length > 0;
1226
- };
1227
- var isActiveContent = (content) => {
1228
- const { enabledAutoStartRules, autoStartRules } = content.config;
1229
- if (!enabledAutoStartRules || !isActive(autoStartRules)) {
1230
1030
  return false;
1231
- }
1232
- return true;
1233
- };
1234
- var priorityCompare = (a, b) => {
1235
- var _a, _b, _c, _d;
1236
- const a1 = (_b = (_a = a == null ? void 0 : a.config) == null ? void 0 : _a.autoStartRulesSetting) == null ? void 0 : _b.priority;
1237
- const a2 = (_d = (_c = b == null ? void 0 : b.config) == null ? void 0 : _c.autoStartRulesSetting) == null ? void 0 : _d.priority;
1238
- if (!a1 || !a2) {
1239
- return 0;
1240
- }
1241
- const index1 = PRIORITIES.indexOf(a1);
1242
- const index2 = PRIORITIES.indexOf(a2);
1243
- if (index1 > index2) {
1244
- return 1;
1245
- }
1246
- if (index1 < index2) {
1247
- return -1;
1248
- }
1249
- return 0;
1250
- };
1251
- var filterAutoStartContent = (contents, type) => {
1252
- return contents.filter((content) => {
1253
- const isActive2 = isActiveContent(content);
1254
- const isValid = isValidContent(content, contents);
1255
- return content.type === type && isActive2 && isValid;
1256
- }).sort(priorityCompare);
1031
+ }) : false;
1032
+ return isMatchIncludesConditions && !isMatchExcludesConditions;
1257
1033
  };
1258
- var getLatestEvent = (currentContent, contents, eventCodeName) => {
1259
- var _a;
1260
- const bizEvents = [];
1261
- const contentId = currentContent.id;
1262
- const contentType = currentContent.type;
1263
- for (let index = 0; index < contents.length; index++) {
1264
- const content = contents[index];
1265
- if (content.id === contentId || content.type !== contentType) {
1266
- continue;
1267
- }
1268
- const sessionBizEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
1269
- if (sessionBizEvents && sessionBizEvents.length > 0) {
1270
- bizEvents.push(...sessionBizEvents.filter((e) => {
1271
- var _a2;
1272
- return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === eventCodeName;
1273
- }));
1274
- }
1034
+ var compareConditionsItem = (item1, item2) => {
1035
+ const { data = {}, ...others1 } = item1;
1036
+ const { data: data2 = {}, ...others2 } = item2;
1037
+ if (!(0, import_fast_deep_equal.default)(others2, others1)) {
1038
+ return false;
1275
1039
  }
1276
- return findLatestEvent(bizEvents);
1277
- };
1278
- var findLatestEvent = (bizEvents) => {
1279
- const initialValue = bizEvents[0];
1280
- const lastEvent = bizEvents.reduce(
1281
- (accumulator, currentValue) => {
1282
- if ((0, import_date_fns.isAfter)(new Date(currentValue.createdAt), new Date(accumulator.createdAt))) {
1283
- return currentValue;
1284
- }
1285
- return accumulator;
1286
- },
1287
- initialValue
1288
- );
1289
- return lastEvent;
1290
- };
1291
- var completeEventMapping = {
1292
- [import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_COMPLETED,
1293
- [import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_ACTIVATED,
1294
- [import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_COMPLETED
1295
- };
1296
- var showEventMapping = {
1297
- [import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_STEP_SEEN,
1298
- [import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_SEEN,
1299
- [import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_SEEN
1300
- };
1301
- var isDismissedEventMapping = {
1302
- [import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_ENDED,
1303
- [import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_DISMISSED,
1304
- [import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_DISMISSED
1305
- };
1306
- var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
1307
- switch (unit) {
1308
- case import_types4.FrequencyUnits.SECONDS: {
1309
- if ((0, import_date_fns.differenceInSeconds)(dateLeft, dateRight) >= duration) {
1310
- return true;
1311
- }
1040
+ for (const key in data) {
1041
+ if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
1312
1042
  return false;
1313
1043
  }
1314
- case import_types4.FrequencyUnits.MINUTES:
1315
- if ((0, import_date_fns.differenceInMinutes)(dateLeft, dateRight) >= duration) {
1316
- return true;
1317
- }
1318
- return false;
1319
- case import_types4.FrequencyUnits.HOURS:
1320
- if ((0, import_date_fns.differenceInHours)(dateLeft, dateRight) >= duration) {
1321
- return true;
1322
- }
1323
- return false;
1324
- case import_types4.FrequencyUnits.DAYES:
1325
- if ((0, import_date_fns.differenceInDays)(dateLeft, dateRight) >= duration) {
1326
- return true;
1327
- }
1328
- return false;
1329
- default:
1330
- return false;
1331
1044
  }
1045
+ return true;
1332
1046
  };
1333
- var checklistIsDimissed = (latestSession) => {
1334
- var _a;
1335
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1336
- (event) => {
1337
- var _a2;
1338
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_DISMISSED;
1339
- }
1340
- );
1341
- };
1342
- var flowIsDismissed = (latestSession) => {
1343
- var _a;
1344
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find((event) => {
1345
- var _a2;
1346
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_ENDED;
1347
- });
1348
- };
1349
- var flowIsSeen = (latestSession) => {
1350
- var _a;
1351
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1352
- (event) => {
1353
- var _a2;
1354
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_STEP_SEEN;
1355
- }
1356
- );
1357
- };
1358
- var checklistIsSeen = (latestSession) => {
1359
- var _a;
1360
- return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
1361
- (event) => {
1362
- var _a2;
1363
- return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_SEEN;
1364
- }
1365
- );
1366
- };
1367
- var isValidContent = (content, contents) => {
1368
- var _a;
1369
- const now = /* @__PURE__ */ new Date();
1370
- if (content.type === import_types4.ContentDataType.FLOW) {
1371
- if (!content.steps || content.steps.length === 0) {
1372
- return false;
1373
- }
1374
- } else {
1375
- if (!content.data) {
1376
- return false;
1377
- }
1378
- }
1379
- if (!content.config.autoStartRulesSetting) {
1047
+ var conditionsIsSame = (rr1, rr2) => {
1048
+ const r1 = [...rr1];
1049
+ const r2 = [...rr2];
1050
+ if (r1.length === 0 && r2.length === 0) {
1380
1051
  return true;
1381
1052
  }
1382
- const { frequency, startIfNotComplete } = content.config.autoStartRulesSetting;
1383
- const completedSessions = content.completedSessions;
1384
- const dismissedSessions = content.dismissedSessions;
1385
- if (startIfNotComplete && completedSessions > 0) {
1053
+ if (r1.length !== r2.length) {
1386
1054
  return false;
1387
1055
  }
1388
- if (!frequency) {
1389
- return true;
1390
- }
1391
- const contentType = content.type;
1392
- const lastEventName = showEventMapping[contentType];
1393
- const lastEvent = getLatestEvent(content, contents, lastEventName);
1394
- const contentEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
1395
- if (lastEvent && frequency && frequency.atLeast && !isGreaterThenDuration(
1396
- now,
1397
- new Date(lastEvent.createdAt),
1398
- frequency.atLeast.unit,
1399
- frequency.atLeast.duration
1400
- )) {
1056
+ const group1 = r1.filter((item) => item.type === "group");
1057
+ const group2 = r2.filter((item) => item.type === "group");
1058
+ if (group1.length !== group2.length) {
1401
1059
  return false;
1402
1060
  }
1403
- if (frequency.frequency === import_types4.Frequency.ONCE) {
1404
- if (dismissedSessions > 0) {
1405
- return false;
1406
- }
1407
- return true;
1408
- }
1409
- const showEventName = showEventMapping[contentType];
1410
- const showEvents = contentEvents == null ? void 0 : contentEvents.filter(
1411
- (e) => {
1412
- var _a2, _b;
1413
- 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);
1414
- }
1415
- );
1416
- if (!showEvents || showEvents.length === 0) {
1417
- return true;
1418
- }
1419
- const lastShowEvent = findLatestEvent(showEvents);
1420
- const lastShowEventDate = new Date(lastShowEvent.createdAt);
1421
- if (frequency.frequency === import_types4.Frequency.MULTIPLE) {
1422
- if (frequency.every.times && dismissedSessions >= frequency.every.times) {
1423
- return false;
1424
- }
1425
- }
1426
- if (frequency.frequency === import_types4.Frequency.MULTIPLE || frequency.frequency === import_types4.Frequency.UNLIMITED) {
1427
- if (!isGreaterThenDuration(now, lastShowEventDate, frequency.every.unit, frequency.every.duration)) {
1061
+ for (let index = 0; index < r1.length; index++) {
1062
+ const item1 = r1[index];
1063
+ const item2 = r2[index];
1064
+ if (!item1 || !item2) {
1428
1065
  return false;
1429
1066
  }
1430
- }
1431
- return true;
1432
- };
1433
- var parseUrlParams = (url, paramName) => {
1434
- if (!url || !paramName) {
1435
- return null;
1436
- }
1437
- try {
1438
- const urlObj = new URL(url);
1439
- const searchParams = new URLSearchParams(urlObj.search);
1440
- if (searchParams.has(paramName)) {
1441
- return searchParams.get(paramName);
1442
- }
1443
- if (urlObj.hash) {
1444
- const hashSearch = urlObj.hash.split("?")[1];
1445
- if (hashSearch) {
1446
- const hashParams = new URLSearchParams(hashSearch);
1447
- if (hashParams.has(paramName)) {
1448
- return hashParams.get(paramName);
1449
- }
1067
+ if (item1.type === "group") {
1068
+ if (!item2.conditions) {
1069
+ return false;
1070
+ }
1071
+ const c1 = item1.conditions;
1072
+ const c2 = item2.conditions;
1073
+ if (item1.operators !== item2.operators) {
1074
+ return false;
1075
+ }
1076
+ if (!conditionsIsSame(c1, c2)) {
1077
+ return false;
1078
+ }
1079
+ } else {
1080
+ if (!compareConditionsItem(item1, item2)) {
1081
+ return false;
1450
1082
  }
1451
1083
  }
1452
- return null;
1453
- } catch (error) {
1454
- console.error("Error parsing URL:", error);
1455
- return null;
1456
1084
  }
1085
+ return true;
1457
1086
  };
1458
1087
  // Annotate the CommonJS export names for ESM import in node:
1459
1088
  0 && (module.exports = {
@@ -1461,13 +1090,9 @@ var parseUrlParams = (url, paramName) => {
1461
1090
  ArrayProto,
1462
1091
  XMLHttpRequest,
1463
1092
  absoluteUrl,
1464
- activedContentRulesConditions,
1465
- activedRulesConditions,
1466
1093
  assignableWindow,
1467
1094
  autoStartConditions,
1468
1095
  buildConfig,
1469
- checklistIsDimissed,
1470
- checklistIsSeen,
1471
1096
  cn,
1472
1097
  conditionsIsSame,
1473
1098
  convertSettings,
@@ -1479,10 +1104,6 @@ var parseUrlParams = (url, paramName) => {
1479
1104
  document,
1480
1105
  evalCode,
1481
1106
  fetch,
1482
- filterAutoStartContent,
1483
- findLatestEvent,
1484
- flowIsDismissed,
1485
- flowIsSeen,
1486
1107
  formatDate,
1487
1108
  generateAutoStateColors,
1488
1109
  getAuthToken,
@@ -1505,8 +1126,6 @@ var parseUrlParams = (url, paramName) => {
1505
1126
  hexToHSLString,
1506
1127
  hexToRGBStr,
1507
1128
  hexToRgb,
1508
- isActive,
1509
- isActiveRulesByCurrentTime,
1510
1129
  isArray,
1511
1130
  isBoolean,
1512
1131
  isDark,
@@ -1529,14 +1148,12 @@ var parseUrlParams = (url, paramName) => {
1529
1148
  isUint8Array,
1530
1149
  isUndefined,
1531
1150
  isUrl,
1532
- isValidContent,
1533
1151
  isValidSelector,
1534
1152
  location,
1535
1153
  mergeThemeDefaultSettings,
1536
1154
  nativeForEach,
1537
1155
  nativeIndexOf,
1538
1156
  navigator,
1539
- parseUrlParams,
1540
1157
  removeAuthToken,
1541
1158
  setAuthToken,
1542
1159
  storage,