@usertour/helpers 0.0.1

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.
Files changed (81) hide show
  1. package/README.md +68 -0
  2. package/dist/auth.cjs +161 -0
  3. package/dist/auth.d.cts +8 -0
  4. package/dist/auth.d.ts +8 -0
  5. package/dist/auth.js +15 -0
  6. package/dist/chunk-2AEGAICC.js +13 -0
  7. package/dist/chunk-3KG2HTZ3.js +79 -0
  8. package/dist/chunk-3ZGH3NRU.js +103 -0
  9. package/dist/chunk-64BFWPHJ.js +50 -0
  10. package/dist/chunk-BBPZYUJR.js +28 -0
  11. package/dist/chunk-FGFMTWFT.js +23 -0
  12. package/dist/chunk-FNQIIEWK.js +121 -0
  13. package/dist/chunk-FW54TSA3.js +41 -0
  14. package/dist/chunk-G5P7KULU.js +223 -0
  15. package/dist/chunk-GFH3VWOC.js +70 -0
  16. package/dist/chunk-H7VA3ML2.js +29 -0
  17. package/dist/chunk-USHOKNHQ.js +243 -0
  18. package/dist/chunk-VT24VOAZ.js +48 -0
  19. package/dist/chunk-XEO3YXBM.js +10 -0
  20. package/dist/chunk-ZNFXGN3M.js +25 -0
  21. package/dist/color.cjs +84 -0
  22. package/dist/color.d.cts +29 -0
  23. package/dist/color.d.ts +29 -0
  24. package/dist/color.js +11 -0
  25. package/dist/condition.cjs +157 -0
  26. package/dist/condition.d.cts +7 -0
  27. package/dist/condition.d.ts +7 -0
  28. package/dist/condition.js +11 -0
  29. package/dist/content-settings.cjs +76 -0
  30. package/dist/content-settings.d.cts +7 -0
  31. package/dist/content-settings.d.ts +7 -0
  32. package/dist/content-settings.js +11 -0
  33. package/dist/content.cjs +53 -0
  34. package/dist/content.d.cts +6 -0
  35. package/dist/content.d.ts +6 -0
  36. package/dist/content.js +9 -0
  37. package/dist/convert-settings.cjs +308 -0
  38. package/dist/convert-settings.d.cts +7 -0
  39. package/dist/convert-settings.d.ts +7 -0
  40. package/dist/convert-settings.js +13 -0
  41. package/dist/error.cjs +259 -0
  42. package/dist/error.d.cts +56 -0
  43. package/dist/error.d.ts +56 -0
  44. package/dist/error.js +37 -0
  45. package/dist/globals.cjs +64 -0
  46. package/dist/globals.d.cts +27 -0
  47. package/dist/globals.d.ts +27 -0
  48. package/dist/globals.js +29 -0
  49. package/dist/helper.cjs +111 -0
  50. package/dist/helper.d.cts +17 -0
  51. package/dist/helper.d.ts +17 -0
  52. package/dist/helper.js +23 -0
  53. package/dist/index.cjs +1165 -0
  54. package/dist/index.d.cts +18 -0
  55. package/dist/index.d.ts +18 -0
  56. package/dist/index.js +178 -0
  57. package/dist/is-url.cjs +49 -0
  58. package/dist/is-url.d.cts +14 -0
  59. package/dist/is-url.d.ts +14 -0
  60. package/dist/is-url.js +7 -0
  61. package/dist/settings.cjs +65 -0
  62. package/dist/settings.d.cts +5 -0
  63. package/dist/settings.d.ts +5 -0
  64. package/dist/settings.js +7 -0
  65. package/dist/storage.cjs +142 -0
  66. package/dist/storage.d.cts +25 -0
  67. package/dist/storage.d.ts +25 -0
  68. package/dist/storage.js +8 -0
  69. package/dist/type-utils.cjs +109 -0
  70. package/dist/type-utils.d.cts +18 -0
  71. package/dist/type-utils.d.ts +18 -0
  72. package/dist/type-utils.js +37 -0
  73. package/dist/utils.cjs +37 -0
  74. package/dist/utils.d.cts +8 -0
  75. package/dist/utils.d.ts +8 -0
  76. package/dist/utils.js +7 -0
  77. package/dist/vite-env.d.cjs +1 -0
  78. package/dist/vite-env.d.d.cts +1 -0
  79. package/dist/vite-env.d.d.ts +1 -0
  80. package/dist/vite-env.d.js +0 -0
  81. package/package.json +56 -0
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @usertour/helpers
2
+
3
+ Utility functions and helpers shared across the UserTour project.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @usertour/helpers
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { generateId, mergeDeep, formatColor } from '@usertour/helpers';
15
+
16
+ // Generate unique IDs
17
+ const id = generateId();
18
+
19
+ // Deep merge objects
20
+ const merged = mergeDeep(obj1, obj2);
21
+
22
+ // Format colors
23
+ const formattedColor = formatColor('#ff0000');
24
+ ```
25
+
26
+ ## Available Utilities
27
+
28
+ This package provides various utility functions for the UserTour project:
29
+
30
+ - **ID Generation**: Unique ID generation with cuid2
31
+ - **Object Utilities**: Deep merging, equality checking
32
+ - **Color Utilities**: Color formatting and manipulation with chroma-js
33
+ - **Class Utilities**: Class name merging with clsx and tailwind-merge
34
+ - **Type Utilities**: Type-safe utility functions
35
+ - **Validation**: Input validation helpers
36
+ - **Formatting**: Data formatting utilities
37
+
38
+ ## Dependencies
39
+
40
+ This package depends on:
41
+ - `@usertour-packages/types` - TypeScript type definitions
42
+ - `fast-deep-equal` - Deep equality checking
43
+ - `chroma-js` - Color manipulation
44
+ - `deepmerge-ts` - Type-safe deep merging
45
+ - `@paralleldrive/cuid2` - Unique ID generation
46
+ - `class-variance-authority` - Class name variants
47
+ - `clsx` - Conditional class names
48
+ - `tailwind-merge` - Tailwind class merging
49
+ - `uuid` - UUID generation
50
+
51
+ ## Development
52
+
53
+ This package is part of the UserTour monorepo. For development:
54
+
55
+ ```bash
56
+ # Install dependencies
57
+ pnpm install
58
+
59
+ # Build the package
60
+ pnpm build
61
+
62
+ # Watch for changes
63
+ pnpm dev
64
+ ```
65
+
66
+ ## License
67
+
68
+ AGPL-3.0
package/dist/auth.cjs ADDED
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+
25
+ // src/auth.ts
26
+ var auth_exports = {};
27
+ __export(auth_exports, {
28
+ getAuthToken: () => getAuthToken,
29
+ removeAuthToken: () => removeAuthToken,
30
+ setAuthToken: () => setAuthToken,
31
+ storage: () => storage
32
+ });
33
+ module.exports = __toCommonJS(auth_exports);
34
+
35
+ // src/globals.ts
36
+ var win = typeof window !== "undefined" ? window : void 0;
37
+ var global = typeof globalThis !== "undefined" ? globalThis : win;
38
+ var ArrayProto = Array.prototype;
39
+ var nativeForEach = ArrayProto.forEach;
40
+ var nativeIndexOf = ArrayProto.indexOf;
41
+ var navigator = global == null ? void 0 : global.navigator;
42
+ var document = global == null ? void 0 : global.document;
43
+ var location = global == null ? void 0 : global.location;
44
+ var fetch = global == null ? void 0 : global.fetch;
45
+ var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
46
+ var AbortController = global == null ? void 0 : global.AbortController;
47
+ var userAgent = navigator == null ? void 0 : navigator.userAgent;
48
+ var assignableWindow = win != null ? win : {};
49
+
50
+ // src/storage.ts
51
+ var AppStorage = class {
52
+ constructor(prefix, defaultExpire) {
53
+ __publicField(this, "prefix", "USERTOUR@0.0.1");
54
+ __publicField(this, "defaultExpire", 5);
55
+ __publicField(this, "setStorage", (type, key, inputValue, inputExpire = -1) => {
56
+ var _a, _b;
57
+ const value = inputValue === "" || inputValue === void 0 ? null : inputValue;
58
+ const expire = Number.isNaN(inputExpire) ? this.defaultExpire : inputExpire;
59
+ const data = {
60
+ value,
61
+ time: Date.now(),
62
+ expire
63
+ };
64
+ try {
65
+ const stringifyData = JSON.stringify(data);
66
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.setItem(this.autoAddPrefix(key), stringifyData);
67
+ } catch (e) {
68
+ console.error(`[APP_STORAGE] setStorage error: ${e}`);
69
+ }
70
+ });
71
+ __publicField(this, "getStorage", (type, key) => {
72
+ var _a, _b, _c, _d;
73
+ const prefixKey = this.autoAddPrefix(key);
74
+ if (!((_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.getItem(prefixKey))) {
75
+ return void 0;
76
+ }
77
+ let storage2 = void 0;
78
+ try {
79
+ const stringifyData = (_d = (_c = win) == null ? void 0 : _c[type]) == null ? void 0 : _d.getItem(prefixKey);
80
+ if (stringifyData === null || stringifyData === void 0) {
81
+ return void 0;
82
+ }
83
+ storage2 = JSON.parse(stringifyData);
84
+ } catch (e) {
85
+ console.error(`[APP_STORAGE] getStorage error: ${e}`);
86
+ return void 0;
87
+ }
88
+ const nowTime = Date.now();
89
+ if (storage2 === void 0) {
90
+ return void 0;
91
+ }
92
+ if (storage2.expire > -1 && storage2.expire * 60 * 1e3 < nowTime - storage2.time) {
93
+ this.removeStorage(type, key);
94
+ return void 0;
95
+ }
96
+ this.setStorage(type, key, storage2.value, storage2.expire);
97
+ return storage2.value;
98
+ });
99
+ __publicField(this, "clearStorage", (type) => {
100
+ var _a, _b;
101
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.clear();
102
+ });
103
+ __publicField(this, "removeStorage", (type, key) => {
104
+ var _a, _b;
105
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.removeItem(this.autoAddPrefix(key));
106
+ });
107
+ __publicField(this, "setLocalStorage", (key, value, expire) => {
108
+ this.setStorage("localStorage", key, value, expire);
109
+ });
110
+ __publicField(this, "getLocalStorage", (key) => {
111
+ return this.getStorage("localStorage", key);
112
+ });
113
+ __publicField(this, "clearLocalStorage", () => {
114
+ this.clearStorage("localStorage");
115
+ });
116
+ __publicField(this, "removeLocalStorage", (key) => {
117
+ this.removeStorage("localStorage", key);
118
+ });
119
+ __publicField(this, "setSessionStorage", (key, value, expire) => {
120
+ this.setStorage("sessionStorage", key, value, expire);
121
+ });
122
+ __publicField(this, "getSessionStorage", (key) => {
123
+ return this.getStorage("sessionStorage", key);
124
+ });
125
+ __publicField(this, "clearSessionStorage", () => {
126
+ this.clearStorage("sessionStorage");
127
+ });
128
+ __publicField(this, "removeSessionStorage", (key) => {
129
+ this.removeStorage("sessionStorage", key);
130
+ });
131
+ if (prefix !== void 0) {
132
+ this.prefix = prefix;
133
+ }
134
+ if (defaultExpire !== void 0) {
135
+ this.defaultExpire = defaultExpire;
136
+ }
137
+ }
138
+ autoAddPrefix(key) {
139
+ return `${this.prefix}/${key}`;
140
+ }
141
+ };
142
+
143
+ // src/auth.ts
144
+ var storage = new AppStorage("USERTOUR@0.0.1", 5);
145
+ var TOKEN_NAME = "token";
146
+ var getAuthToken = () => {
147
+ return storage.getLocalStorage(TOKEN_NAME);
148
+ };
149
+ var removeAuthToken = () => {
150
+ return storage.removeLocalStorage(TOKEN_NAME);
151
+ };
152
+ var setAuthToken = (token, expire) => {
153
+ storage.setLocalStorage(TOKEN_NAME, token, expire);
154
+ };
155
+ // Annotate the CommonJS export names for ESM import in node:
156
+ 0 && (module.exports = {
157
+ getAuthToken,
158
+ removeAuthToken,
159
+ setAuthToken,
160
+ storage
161
+ });
@@ -0,0 +1,8 @@
1
+ import { AppStorage } from './storage.cjs';
2
+
3
+ declare const storage: AppStorage;
4
+ declare const getAuthToken: () => string;
5
+ declare const removeAuthToken: () => void;
6
+ declare const setAuthToken: (token: string, expire: number) => void;
7
+
8
+ export { getAuthToken, removeAuthToken, setAuthToken, storage };
package/dist/auth.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { AppStorage } from './storage.js';
2
+
3
+ declare const storage: AppStorage;
4
+ declare const getAuthToken: () => string;
5
+ declare const removeAuthToken: () => void;
6
+ declare const setAuthToken: (token: string, expire: number) => void;
7
+
8
+ export { getAuthToken, removeAuthToken, setAuthToken, storage };
package/dist/auth.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ getAuthToken,
3
+ removeAuthToken,
4
+ setAuthToken,
5
+ storage
6
+ } from "./chunk-FGFMTWFT.js";
7
+ import "./chunk-3ZGH3NRU.js";
8
+ import "./chunk-H7VA3ML2.js";
9
+ import "./chunk-XEO3YXBM.js";
10
+ export {
11
+ getAuthToken,
12
+ removeAuthToken,
13
+ setAuthToken,
14
+ storage
15
+ };
@@ -0,0 +1,13 @@
1
+ // src/utils.ts
2
+ var deepClone = (obj) => {
3
+ try {
4
+ return structuredClone(obj);
5
+ } catch (error) {
6
+ console.warn("structuredClone failed, falling back to JSON method:", error);
7
+ return JSON.parse(JSON.stringify(obj));
8
+ }
9
+ };
10
+
11
+ export {
12
+ deepClone
13
+ };
@@ -0,0 +1,79 @@
1
+ // src/helper.ts
2
+ import { clsx } from "clsx";
3
+ import { twMerge } from "tailwind-merge";
4
+ import { v4 } from "uuid";
5
+ import { createId } from "@paralleldrive/cuid2";
6
+ function cn(...inputs) {
7
+ return twMerge(clsx(inputs));
8
+ }
9
+ var cuid = () => {
10
+ return createId();
11
+ };
12
+ function formatDate(input) {
13
+ const date = new Date(input);
14
+ return date.toLocaleDateString("en-US", {
15
+ month: "long",
16
+ day: "numeric",
17
+ year: "numeric"
18
+ });
19
+ }
20
+ function absoluteUrl(path) {
21
+ return `${path}`;
22
+ }
23
+ var uuidV4 = () => {
24
+ return v4();
25
+ };
26
+ function hexToRgb(hex) {
27
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
28
+ return result ? {
29
+ r: Number.parseInt(result[1], 16),
30
+ g: Number.parseInt(result[2], 16),
31
+ b: Number.parseInt(result[3], 16)
32
+ } : null;
33
+ }
34
+ var isDark = (hex) => {
35
+ const rgb = hexToRgb(hex);
36
+ if (!rgb) {
37
+ return null;
38
+ }
39
+ const { r, g, b } = rgb;
40
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
41
+ return true;
42
+ }
43
+ return false;
44
+ };
45
+ var evalCode = (code) => {
46
+ try {
47
+ return eval(code);
48
+ } catch (error) {
49
+ console.error("Usertour.js: Error evaluating code:", error);
50
+ return null;
51
+ }
52
+ };
53
+ var getRandomColor = () => {
54
+ const colors = [
55
+ "bg-red-500",
56
+ "bg-orange-500",
57
+ "bg-yellow-500",
58
+ "bg-green-500",
59
+ "bg-teal-500",
60
+ "bg-blue-500",
61
+ "bg-indigo-500",
62
+ "bg-purple-500",
63
+ "bg-pink-500",
64
+ "bg-rose-500"
65
+ ];
66
+ return colors[Math.floor(Math.random() * colors.length)];
67
+ };
68
+
69
+ export {
70
+ cn,
71
+ cuid,
72
+ formatDate,
73
+ absoluteUrl,
74
+ uuidV4,
75
+ hexToRgb,
76
+ isDark,
77
+ evalCode,
78
+ getRandomColor
79
+ };
@@ -0,0 +1,103 @@
1
+ import {
2
+ win
3
+ } from "./chunk-H7VA3ML2.js";
4
+ import {
5
+ __publicField
6
+ } from "./chunk-XEO3YXBM.js";
7
+
8
+ // src/storage.ts
9
+ var AppStorage = class {
10
+ constructor(prefix, defaultExpire) {
11
+ __publicField(this, "prefix", "USERTOUR@0.0.1");
12
+ __publicField(this, "defaultExpire", 5);
13
+ __publicField(this, "setStorage", (type, key, inputValue, inputExpire = -1) => {
14
+ var _a, _b;
15
+ const value = inputValue === "" || inputValue === void 0 ? null : inputValue;
16
+ const expire = Number.isNaN(inputExpire) ? this.defaultExpire : inputExpire;
17
+ const data = {
18
+ value,
19
+ time: Date.now(),
20
+ expire
21
+ };
22
+ try {
23
+ const stringifyData = JSON.stringify(data);
24
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.setItem(this.autoAddPrefix(key), stringifyData);
25
+ } catch (e) {
26
+ console.error(`[APP_STORAGE] setStorage error: ${e}`);
27
+ }
28
+ });
29
+ __publicField(this, "getStorage", (type, key) => {
30
+ var _a, _b, _c, _d;
31
+ const prefixKey = this.autoAddPrefix(key);
32
+ if (!((_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.getItem(prefixKey))) {
33
+ return void 0;
34
+ }
35
+ let storage = void 0;
36
+ try {
37
+ const stringifyData = (_d = (_c = win) == null ? void 0 : _c[type]) == null ? void 0 : _d.getItem(prefixKey);
38
+ if (stringifyData === null || stringifyData === void 0) {
39
+ return void 0;
40
+ }
41
+ storage = JSON.parse(stringifyData);
42
+ } catch (e) {
43
+ console.error(`[APP_STORAGE] getStorage error: ${e}`);
44
+ return void 0;
45
+ }
46
+ const nowTime = Date.now();
47
+ if (storage === void 0) {
48
+ return void 0;
49
+ }
50
+ if (storage.expire > -1 && storage.expire * 60 * 1e3 < nowTime - storage.time) {
51
+ this.removeStorage(type, key);
52
+ return void 0;
53
+ }
54
+ this.setStorage(type, key, storage.value, storage.expire);
55
+ return storage.value;
56
+ });
57
+ __publicField(this, "clearStorage", (type) => {
58
+ var _a, _b;
59
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.clear();
60
+ });
61
+ __publicField(this, "removeStorage", (type, key) => {
62
+ var _a, _b;
63
+ (_b = (_a = win) == null ? void 0 : _a[type]) == null ? void 0 : _b.removeItem(this.autoAddPrefix(key));
64
+ });
65
+ __publicField(this, "setLocalStorage", (key, value, expire) => {
66
+ this.setStorage("localStorage", key, value, expire);
67
+ });
68
+ __publicField(this, "getLocalStorage", (key) => {
69
+ return this.getStorage("localStorage", key);
70
+ });
71
+ __publicField(this, "clearLocalStorage", () => {
72
+ this.clearStorage("localStorage");
73
+ });
74
+ __publicField(this, "removeLocalStorage", (key) => {
75
+ this.removeStorage("localStorage", key);
76
+ });
77
+ __publicField(this, "setSessionStorage", (key, value, expire) => {
78
+ this.setStorage("sessionStorage", key, value, expire);
79
+ });
80
+ __publicField(this, "getSessionStorage", (key) => {
81
+ return this.getStorage("sessionStorage", key);
82
+ });
83
+ __publicField(this, "clearSessionStorage", () => {
84
+ this.clearStorage("sessionStorage");
85
+ });
86
+ __publicField(this, "removeSessionStorage", (key) => {
87
+ this.removeStorage("sessionStorage", key);
88
+ });
89
+ if (prefix !== void 0) {
90
+ this.prefix = prefix;
91
+ }
92
+ if (defaultExpire !== void 0) {
93
+ this.defaultExpire = defaultExpire;
94
+ }
95
+ }
96
+ autoAddPrefix(key) {
97
+ return `${this.prefix}/${key}`;
98
+ }
99
+ };
100
+
101
+ export {
102
+ AppStorage
103
+ };
@@ -0,0 +1,50 @@
1
+ // src/content-settings.ts
2
+ import { ContentPriority } from "@usertour/types";
3
+ import { deepmerge } from "deepmerge-ts";
4
+ var rulesSetting = {
5
+ // frequency: {
6
+ // frequency: Frequency.ONCE,
7
+ // every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
8
+ // atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
9
+ // },
10
+ startIfNotComplete: false,
11
+ priority: ContentPriority.MEDIUM,
12
+ wait: 0
13
+ };
14
+ var hideRulesSetting = {};
15
+ var defaultContentConfig = {
16
+ enabledAutoStartRules: false,
17
+ enabledHideRules: false,
18
+ autoStartRules: [],
19
+ hideRules: [],
20
+ autoStartRulesSetting: rulesSetting,
21
+ hideRulesSetting
22
+ };
23
+ var autoStartConditions = {
24
+ ...defaultContentConfig,
25
+ enabledAutoStartRules: true,
26
+ autoStartRules: [
27
+ {
28
+ data: { excludes: [], includes: ["/*"] },
29
+ type: "current-page",
30
+ operators: "and"
31
+ }
32
+ ]
33
+ };
34
+ var buildConfig = (config) => {
35
+ return {
36
+ ...defaultContentConfig,
37
+ ...config,
38
+ autoStartRulesSetting: deepmerge(
39
+ defaultContentConfig.autoStartRulesSetting,
40
+ (config == null ? void 0 : config.autoStartRulesSetting) || {}
41
+ ),
42
+ hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
43
+ };
44
+ };
45
+
46
+ export {
47
+ defaultContentConfig,
48
+ autoStartConditions,
49
+ buildConfig
50
+ };
@@ -0,0 +1,28 @@
1
+ // src/content.ts
2
+ var isPublishedInAllEnvironments = (content, environmentList, version) => {
3
+ const isPublishedInAllEnvironments2 = environmentList == null ? void 0 : environmentList.every(
4
+ (env) => {
5
+ var _a;
6
+ return (_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.find(
7
+ (item) => item.published && item.publishedVersionId === (version == null ? void 0 : version.id) && item.environment.id === env.id
8
+ );
9
+ }
10
+ );
11
+ const isPublishedInOneEnvironment = (content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId) === (version == null ? void 0 : version.id) && environmentList && (environmentList == null ? void 0 : environmentList.length) === 1;
12
+ return (content == null ? void 0 : content.contentOnEnvironments) && (content == null ? void 0 : content.contentOnEnvironments.length) > 0 ? Boolean(isPublishedInAllEnvironments2) : Boolean(isPublishedInOneEnvironment);
13
+ };
14
+ var isPublishedAtLeastOneEnvironment = (content) => {
15
+ var _a;
16
+ if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
17
+ return true;
18
+ }
19
+ if ((content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId)) {
20
+ return true;
21
+ }
22
+ return false;
23
+ };
24
+
25
+ export {
26
+ isPublishedInAllEnvironments,
27
+ isPublishedAtLeastOneEnvironment
28
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ AppStorage
3
+ } from "./chunk-3ZGH3NRU.js";
4
+
5
+ // src/auth.ts
6
+ var storage = new AppStorage("USERTOUR@0.0.1", 5);
7
+ var TOKEN_NAME = "token";
8
+ var getAuthToken = () => {
9
+ return storage.getLocalStorage(TOKEN_NAME);
10
+ };
11
+ var removeAuthToken = () => {
12
+ return storage.removeLocalStorage(TOKEN_NAME);
13
+ };
14
+ var setAuthToken = (token, expire) => {
15
+ storage.setLocalStorage(TOKEN_NAME, token, expire);
16
+ };
17
+
18
+ export {
19
+ storage,
20
+ getAuthToken,
21
+ removeAuthToken,
22
+ setAuthToken
23
+ };
@@ -0,0 +1,121 @@
1
+ // src/condition.ts
2
+ import isEqual from "fast-deep-equal";
3
+ var parseUrl = (url) => {
4
+ const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
5
+ if (!urlPatterns) {
6
+ return null;
7
+ }
8
+ const [, , scheme = "", domain = "", path = "", , query = "", fragment = ""] = urlPatterns;
9
+ return { scheme, domain, path, query, fragment };
10
+ };
11
+ var replaceWildcard = (input, s1, s2) => {
12
+ const withSpecialWords = replaceSpecialWords(input);
13
+ const withWildcard = withSpecialWords.replace(/\\\*/g, `${s1}*`);
14
+ if (!s2) {
15
+ return withWildcard;
16
+ }
17
+ return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
18
+ };
19
+ var replaceSpecialWords = (str) => {
20
+ return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
21
+ };
22
+ var parsePattern = (pattern) => {
23
+ if (!pattern || !pattern.trim()) {
24
+ return null;
25
+ }
26
+ const _pattern = parseUrl(pattern);
27
+ if (!_pattern) {
28
+ console.error("Invalid URL pattern:", pattern);
29
+ return null;
30
+ }
31
+ const { scheme, domain, path, query, fragment } = _pattern;
32
+ const _scheme = scheme ? replaceSpecialWords(scheme) : "[a-z\\d]+";
33
+ const _domain = domain ? replaceWildcard(domain, "[^/]", ".") : "[^/]*";
34
+ const _fragment = fragment ? replaceWildcard(fragment, ".", "/") : "(#.*)?";
35
+ const _path = path ? replaceWildcard(path, "[^?#]", "/") : "/[^?#]*";
36
+ let _query = "(\\?[^#]*)?";
37
+ if (query) {
38
+ new URLSearchParams(query).forEach((value, key) => {
39
+ const _str = value === "" ? "=?" : value === "*" ? "(=[^&#]*)?" : `=${replaceWildcard(value, "[^#]")}`;
40
+ _query += `(?=.*[?&]${replaceSpecialWords(key)}${_str}([&#]|$))`;
41
+ });
42
+ _query += "\\?[^#]*";
43
+ }
44
+ return new RegExp(`^${_scheme}://${_domain}(:\\d+)?${_path}${_query}${_fragment}$`);
45
+ };
46
+ var isMatchUrlPattern = (_url, includes, excludes) => {
47
+ const isMatchIncludesConditions = includes.length > 0 ? includes.some((_include) => {
48
+ const reg = parsePattern(_include);
49
+ if (reg) {
50
+ return reg.test(_url);
51
+ }
52
+ return false;
53
+ }) : true;
54
+ const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
55
+ const reg = parsePattern(_exclude);
56
+ if (reg) {
57
+ return reg.test(_url);
58
+ }
59
+ return false;
60
+ }) : false;
61
+ return isMatchIncludesConditions && !isMatchExcludesConditions;
62
+ };
63
+ var compareConditionsItem = (item1, item2) => {
64
+ const { data = {}, ...others1 } = item1;
65
+ const { data: data2 = {}, ...others2 } = item2;
66
+ if (!isEqual(others2, others1)) {
67
+ return false;
68
+ }
69
+ for (const key in data) {
70
+ if (!isEqual(data[key], data2[key])) {
71
+ return false;
72
+ }
73
+ }
74
+ return true;
75
+ };
76
+ var conditionsIsSame = (rr1, rr2) => {
77
+ const r1 = [...rr1];
78
+ const r2 = [...rr2];
79
+ if (r1.length === 0 && r2.length === 0) {
80
+ return true;
81
+ }
82
+ if (r1.length !== r2.length) {
83
+ return false;
84
+ }
85
+ const group1 = r1.filter((item) => item.type === "group");
86
+ const group2 = r2.filter((item) => item.type === "group");
87
+ if (group1.length !== group2.length) {
88
+ return false;
89
+ }
90
+ for (let index = 0; index < r1.length; index++) {
91
+ const item1 = r1[index];
92
+ const item2 = r2[index];
93
+ if (!item1 || !item2) {
94
+ return false;
95
+ }
96
+ if (item1.type === "group") {
97
+ if (!item2.conditions) {
98
+ return false;
99
+ }
100
+ const c1 = item1.conditions;
101
+ const c2 = item2.conditions;
102
+ if (item1.operators !== item2.operators) {
103
+ return false;
104
+ }
105
+ if (!conditionsIsSame(c1, c2)) {
106
+ return false;
107
+ }
108
+ } else {
109
+ if (!compareConditionsItem(item1, item2)) {
110
+ return false;
111
+ }
112
+ }
113
+ }
114
+ return true;
115
+ };
116
+
117
+ export {
118
+ isEqual,
119
+ isMatchUrlPattern,
120
+ conditionsIsSame
121
+ };