@usertour/helpers 0.0.53 → 0.0.54

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  hexToHSLString,
3
3
  hexToRGBStr
4
- } from "./chunk-VT24VOAZ.js";
4
+ } from "./chunk-XMAPBUWT.js";
5
5
  import {
6
6
  isUndefined
7
7
  } from "./chunk-GFH3VWOC.js";
@@ -40,9 +40,38 @@ function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activ
40
40
  }
41
41
  return { hover, active };
42
42
  }
43
+ function generateStateColors(baseColor, brandColor, options = {}) {
44
+ const {
45
+ brandHoverRatio = 0.175,
46
+ brandActiveRatio = 0.14,
47
+ lightHoverRatio = 0.11,
48
+ lightActiveRatio = 0.225
49
+ } = options;
50
+ const baseLuminance = chroma(baseColor).luminance();
51
+ const isBaseLight = baseLuminance > 0.8;
52
+ const isBaseDark = baseLuminance < 0.2;
53
+ const isBaseBrand = chroma.distance(baseColor, brandColor) < 10;
54
+ let hover;
55
+ let active;
56
+ if (isBaseBrand) {
57
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
58
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
59
+ } else if (isBaseLight) {
60
+ hover = chroma.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
61
+ active = chroma.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
62
+ } else if (isBaseDark) {
63
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
64
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
65
+ } else {
66
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
67
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
68
+ }
69
+ return { hover, active };
70
+ }
43
71
 
44
72
  export {
45
73
  hexToHSLString,
46
74
  hexToRGBStr,
47
- generateAutoStateColors
75
+ generateAutoStateColors,
76
+ generateStateColors
48
77
  };
package/dist/color.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var color_exports = {};
32
32
  __export(color_exports, {
33
33
  generateAutoStateColors: () => generateAutoStateColors,
34
+ generateStateColors: () => generateStateColors,
34
35
  hexToHSLString: () => hexToHSLString,
35
36
  hexToRGBStr: () => hexToRGBStr
36
37
  });
@@ -76,9 +77,38 @@ function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activ
76
77
  }
77
78
  return { hover, active };
78
79
  }
80
+ function generateStateColors(baseColor, brandColor, options = {}) {
81
+ const {
82
+ brandHoverRatio = 0.175,
83
+ brandActiveRatio = 0.14,
84
+ lightHoverRatio = 0.11,
85
+ lightActiveRatio = 0.225
86
+ } = options;
87
+ const baseLuminance = (0, import_chroma_js.default)(baseColor).luminance();
88
+ const isBaseLight = baseLuminance > 0.8;
89
+ const isBaseDark = baseLuminance < 0.2;
90
+ const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
91
+ let hover;
92
+ let active;
93
+ if (isBaseBrand) {
94
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
95
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
96
+ } else if (isBaseLight) {
97
+ hover = import_chroma_js.default.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
98
+ active = import_chroma_js.default.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
99
+ } else if (isBaseDark) {
100
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
101
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
102
+ } else {
103
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
104
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
105
+ }
106
+ return { hover, active };
107
+ }
79
108
  // Annotate the CommonJS export names for ESM import in node:
80
109
  0 && (module.exports = {
81
110
  generateAutoStateColors,
111
+ generateStateColors,
82
112
  hexToHSLString,
83
113
  hexToRGBStr
84
114
  });
package/dist/color.d.cts CHANGED
@@ -20,10 +20,51 @@ declare const hexToRGBStr: (hex: string) => string;
20
20
  * @param hoverRatio - Mix ratio for hover state (default 0.15)
21
21
  * @param activeDarken - Darken factor for active state (default 0.12)
22
22
  * @returns An object with hover and active color hex strings
23
+ * @deprecated Use generateStateColors instead
23
24
  */
24
25
  declare function generateAutoStateColors(baseColor: string, brandColor: string, hoverRatio?: number, activeRatio?: number): {
25
26
  hover: string;
26
27
  active: string;
27
28
  };
29
+ /**
30
+ * Configuration options for state color generation
31
+ */
32
+ interface StateColorOptions {
33
+ /** Mix ratio for hover state when base is brand color (default 0.175) */
34
+ brandHoverRatio?: number;
35
+ /** Mix ratio for active/click state when base is brand color (default 0.14) */
36
+ brandActiveRatio?: number;
37
+ /** Mix ratio for hover state when base is light color (default 0.11) */
38
+ lightHoverRatio?: number;
39
+ /** Mix ratio for active/click state when base is light color (default 0.225) */
40
+ lightActiveRatio?: number;
41
+ }
42
+ /**
43
+ * Generate hover and active state colors based on base color and brand color.
44
+ *
45
+ * Logic:
46
+ * - Brand color base: hover = tint (mix with white), active = shade (mix with black)
47
+ * - Light color base (e.g., white): hover/active = mix with brand color
48
+ * - Dark color base: hover = tint (mix with white), active = shade (mix with black)
49
+ *
50
+ * @param baseColor - The base background color
51
+ * @param brandColor - The brand/primary color
52
+ * @param options - Optional configuration for mix ratios
53
+ * @returns Object containing hover and active color hex strings
54
+ *
55
+ * @example
56
+ * // Brand color button
57
+ * generateStateColors('#2563eb', '#2563eb');
58
+ * // Returns: { hover: '#4b7eee', active: '#2055c9' }
59
+ *
60
+ * @example
61
+ * // White background content
62
+ * generateStateColors('#ffffff', '#2563eb');
63
+ * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
64
+ */
65
+ declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
66
+ hover: string;
67
+ active: string;
68
+ };
28
69
 
29
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr };
70
+ export { type StateColorOptions, generateAutoStateColors, generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.d.ts CHANGED
@@ -20,10 +20,51 @@ declare const hexToRGBStr: (hex: string) => string;
20
20
  * @param hoverRatio - Mix ratio for hover state (default 0.15)
21
21
  * @param activeDarken - Darken factor for active state (default 0.12)
22
22
  * @returns An object with hover and active color hex strings
23
+ * @deprecated Use generateStateColors instead
23
24
  */
24
25
  declare function generateAutoStateColors(baseColor: string, brandColor: string, hoverRatio?: number, activeRatio?: number): {
25
26
  hover: string;
26
27
  active: string;
27
28
  };
29
+ /**
30
+ * Configuration options for state color generation
31
+ */
32
+ interface StateColorOptions {
33
+ /** Mix ratio for hover state when base is brand color (default 0.175) */
34
+ brandHoverRatio?: number;
35
+ /** Mix ratio for active/click state when base is brand color (default 0.14) */
36
+ brandActiveRatio?: number;
37
+ /** Mix ratio for hover state when base is light color (default 0.11) */
38
+ lightHoverRatio?: number;
39
+ /** Mix ratio for active/click state when base is light color (default 0.225) */
40
+ lightActiveRatio?: number;
41
+ }
42
+ /**
43
+ * Generate hover and active state colors based on base color and brand color.
44
+ *
45
+ * Logic:
46
+ * - Brand color base: hover = tint (mix with white), active = shade (mix with black)
47
+ * - Light color base (e.g., white): hover/active = mix with brand color
48
+ * - Dark color base: hover = tint (mix with white), active = shade (mix with black)
49
+ *
50
+ * @param baseColor - The base background color
51
+ * @param brandColor - The brand/primary color
52
+ * @param options - Optional configuration for mix ratios
53
+ * @returns Object containing hover and active color hex strings
54
+ *
55
+ * @example
56
+ * // Brand color button
57
+ * generateStateColors('#2563eb', '#2563eb');
58
+ * // Returns: { hover: '#4b7eee', active: '#2055c9' }
59
+ *
60
+ * @example
61
+ * // White background content
62
+ * generateStateColors('#ffffff', '#2563eb');
63
+ * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
64
+ */
65
+ declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
66
+ hover: string;
67
+ active: string;
68
+ };
28
69
 
29
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr };
70
+ export { type StateColorOptions, generateAutoStateColors, generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  generateAutoStateColors,
3
+ generateStateColors,
3
4
  hexToHSLString,
4
5
  hexToRGBStr
5
- } from "./chunk-VT24VOAZ.js";
6
+ } from "./chunk-XMAPBUWT.js";
6
7
  import "./chunk-XEO3YXBM.js";
7
8
  export {
8
9
  generateAutoStateColors,
10
+ generateStateColors,
9
11
  hexToHSLString,
10
12
  hexToRGBStr
11
13
  };
@@ -2,8 +2,8 @@ import {
2
2
  convertSettings,
3
3
  convertToCssVars,
4
4
  mergeThemeDefaultSettings
5
- } from "./chunk-OBKNA55U.js";
6
- import "./chunk-VT24VOAZ.js";
5
+ } from "./chunk-G73OLXRF.js";
6
+ import "./chunk-XMAPBUWT.js";
7
7
  import "./chunk-GFH3VWOC.js";
8
8
  import "./chunk-XEO3YXBM.js";
9
9
  export {
package/dist/index.cjs CHANGED
@@ -74,6 +74,7 @@ __export(src_exports, {
74
74
  filterNullAttributes: () => filterNullAttributes,
75
75
  formatDate: () => formatDate,
76
76
  generateAutoStateColors: () => generateAutoStateColors,
77
+ generateStateColors: () => generateStateColors,
77
78
  generateUniqueCopyName: () => generateUniqueCopyName,
78
79
  getAttributeType: () => getAttributeType,
79
80
  getAuthToken: () => getAuthToken,
@@ -193,6 +194,34 @@ function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activ
193
194
  }
194
195
  return { hover, active };
195
196
  }
197
+ function generateStateColors(baseColor, brandColor, options = {}) {
198
+ const {
199
+ brandHoverRatio = 0.175,
200
+ brandActiveRatio = 0.14,
201
+ lightHoverRatio = 0.11,
202
+ lightActiveRatio = 0.225
203
+ } = options;
204
+ const baseLuminance = (0, import_chroma_js.default)(baseColor).luminance();
205
+ const isBaseLight = baseLuminance > 0.8;
206
+ const isBaseDark = baseLuminance < 0.2;
207
+ const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
208
+ let hover;
209
+ let active;
210
+ if (isBaseBrand) {
211
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
212
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
213
+ } else if (isBaseLight) {
214
+ hover = import_chroma_js.default.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
215
+ active = import_chroma_js.default.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
216
+ } else if (isBaseDark) {
217
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
218
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
219
+ } else {
220
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
221
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
222
+ }
223
+ return { hover, active };
224
+ }
196
225
 
197
226
  // src/convert-settings.ts
198
227
  var import_deepmerge_ts = require("deepmerge-ts");
@@ -1951,6 +1980,7 @@ var duplicateStep = (step) => {
1951
1980
  filterNullAttributes,
1952
1981
  formatDate,
1953
1982
  generateAutoStateColors,
1983
+ generateStateColors,
1954
1984
  generateUniqueCopyName,
1955
1985
  getAttributeType,
1956
1986
  getAuthToken,
package/dist/index.d.cts CHANGED
@@ -7,7 +7,7 @@ export { isUrl } from './is-url.cjs';
7
7
  export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.cjs';
8
8
  export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.cjs';
9
9
  export { deepClone, parseUrlParams, wait } from './utils.cjs';
10
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
10
+ export { StateColorOptions, generateAutoStateColors, generateStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
11
11
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
12
12
  export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './conditions/condition.cjs';
13
13
  export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { isUrl } from './is-url.js';
7
7
  export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.js';
8
8
  export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.js';
9
9
  export { deepClone, parseUrlParams, wait } from './utils.js';
10
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
10
+ export { StateColorOptions, generateAutoStateColors, generateStateColors, hexToHSLString, hexToRGBStr } from './color.js';
11
11
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
12
12
  export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './conditions/condition.js';
13
13
  export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
package/dist/index.js CHANGED
@@ -82,12 +82,13 @@ import {
82
82
  convertSettings,
83
83
  convertToCssVars,
84
84
  mergeThemeDefaultSettings
85
- } from "./chunk-OBKNA55U.js";
85
+ } from "./chunk-G73OLXRF.js";
86
86
  import {
87
87
  generateAutoStateColors,
88
+ generateStateColors,
88
89
  hexToHSLString,
89
90
  hexToRGBStr
90
- } from "./chunk-VT24VOAZ.js";
91
+ } from "./chunk-XMAPBUWT.js";
91
92
  import {
92
93
  getCodeError,
93
94
  getContentError,
@@ -186,6 +187,7 @@ export {
186
187
  filterNullAttributes,
187
188
  formatDate,
188
189
  generateAutoStateColors,
190
+ generateStateColors,
189
191
  generateUniqueCopyName,
190
192
  getAttributeType,
191
193
  getAuthToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.53",
3
+ "version": "0.0.54",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@paralleldrive/cuid2": "^2.2.2",
32
- "@usertour/types": "^0.0.40",
32
+ "@usertour/types": "^0.0.42",
33
33
  "chroma-js": "^3.1.2",
34
34
  "class-variance-authority": "^0.4.0",
35
35
  "clsx": "^1.2.1",