@usertour/helpers 0.0.53 → 0.0.55

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.
@@ -451,13 +451,13 @@ function hexToRgb(hex) {
451
451
  b: Number.parseInt(result[3], 16)
452
452
  } : null;
453
453
  }
454
- var isDark = (hex) => {
454
+ var isLight = (hex) => {
455
455
  const rgb = hexToRgb(hex);
456
456
  if (!rgb) {
457
457
  return null;
458
458
  }
459
459
  const { r, g, b } = rgb;
460
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
460
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
461
461
  return true;
462
462
  }
463
463
  return false;
@@ -2,10 +2,10 @@ import {
2
2
  evaluateRulesConditions,
3
3
  filterConditionsByType,
4
4
  isConditionsActived
5
- } from "../chunk-SIG4WTEF.js";
5
+ } from "../chunk-5BEUHZSY.js";
6
6
  import "../chunk-YYIGUZNZ.js";
7
7
  import "../chunk-PAESAL23.js";
8
- import "../chunk-3KG2HTZ3.js";
8
+ import "../chunk-7X2CUDBX.js";
9
9
  import "../chunk-KYDXF7SU.js";
10
10
  import "../chunk-JQWKLXW6.js";
11
11
  import "../chunk-GFH3VWOC.js";
@@ -61,13 +61,13 @@ function hexToRgb(hex) {
61
61
  b: Number.parseInt(result[3], 16)
62
62
  } : null;
63
63
  }
64
- var isDark = (hex) => {
64
+ var isLight = (hex) => {
65
65
  const rgb = hexToRgb(hex);
66
66
  if (!rgb) {
67
67
  return null;
68
68
  }
69
69
  const { r, g, b } = rgb;
70
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
70
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
71
71
  return true;
72
72
  }
73
73
  return false;
@@ -14,12 +14,12 @@ import {
14
14
  isQuestionElement,
15
15
  isRestrictedType,
16
16
  processQuestionElements
17
- } from "../chunk-2TMOS3DN.js";
17
+ } from "../chunk-KARDMYE2.js";
18
18
  import "../chunk-7ODE2AIC.js";
19
- import "../chunk-SIG4WTEF.js";
19
+ import "../chunk-5BEUHZSY.js";
20
20
  import "../chunk-YYIGUZNZ.js";
21
21
  import "../chunk-PAESAL23.js";
22
- import "../chunk-3KG2HTZ3.js";
22
+ import "../chunk-7X2CUDBX.js";
23
23
  import "../chunk-KYDXF7SU.js";
24
24
  import "../chunk-JQWKLXW6.js";
25
25
  import "../chunk-GFH3VWOC.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-YYIGUZNZ.js";
4
4
  import {
5
5
  cuid
6
- } from "./chunk-3KG2HTZ3.js";
6
+ } from "./chunk-7X2CUDBX.js";
7
7
  import {
8
8
  evaluateAttributeCondition
9
9
  } from "./chunk-KYDXF7SU.js";
@@ -31,13 +31,13 @@ function hexToRgb(hex) {
31
31
  b: Number.parseInt(result[3], 16)
32
32
  } : null;
33
33
  }
34
- var isDark = (hex) => {
34
+ var isLight = (hex) => {
35
35
  const rgb = hexToRgb(hex);
36
36
  if (!rgb) {
37
37
  return null;
38
38
  }
39
39
  const { r, g, b } = rgb;
40
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
40
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
41
41
  return true;
42
42
  }
43
43
  return false;
@@ -73,7 +73,7 @@ export {
73
73
  absoluteUrl,
74
74
  uuidV4,
75
75
  hexToRgb,
76
- isDark,
76
+ isLight,
77
77
  evalCode,
78
78
  getRandomColor
79
79
  };
@@ -0,0 +1,59 @@
1
+ // src/color.ts
2
+ import chroma from "chroma-js";
3
+ function hexToHSLString(hexColor) {
4
+ try {
5
+ const color = chroma(hexColor);
6
+ const [h, s, l] = color.hsl();
7
+ const hDeg = Math.round(h || 0);
8
+ const sPct = Math.round(s * 100);
9
+ const lPct = Math.round(l * 100);
10
+ return `${hDeg} ${sPct}% ${lPct}%`;
11
+ } catch (error) {
12
+ console.warn(`Failed to convert ${hexColor} to HSL string:`, error);
13
+ return "0 0% 0%";
14
+ }
15
+ }
16
+ var hexToRGBStr = (hex) => {
17
+ try {
18
+ const color = chroma(hex);
19
+ const [r, g, b] = color.rgb();
20
+ return `${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}`;
21
+ } catch (error) {
22
+ console.warn(`Failed to convert ${hex} to RGB string:`, error);
23
+ return "0, 0, 0";
24
+ }
25
+ };
26
+ function generateStateColors(baseColor, brandColor, options = {}) {
27
+ const {
28
+ brandHoverRatio = 0.175,
29
+ brandActiveRatio = 0.14,
30
+ lightHoverRatio = 0.11,
31
+ lightActiveRatio = 0.225
32
+ } = options;
33
+ const baseLuminance = chroma(baseColor).luminance();
34
+ const isBaseLight = baseLuminance > 0.8;
35
+ const isBaseDark = baseLuminance < 0.2;
36
+ const isBaseBrand = chroma.distance(baseColor, brandColor) < 10;
37
+ let hover;
38
+ let active;
39
+ if (isBaseBrand) {
40
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
41
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
42
+ } else if (isBaseLight) {
43
+ hover = chroma.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
44
+ active = chroma.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
45
+ } else if (isBaseDark) {
46
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
47
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
48
+ } else {
49
+ hover = chroma.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
50
+ active = chroma.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
51
+ }
52
+ return { hover, active };
53
+ }
54
+
55
+ export {
56
+ hexToHSLString,
57
+ hexToRGBStr,
58
+ generateStateColors
59
+ };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  regenerateConditionIds
3
- } from "./chunk-SIG4WTEF.js";
3
+ } from "./chunk-5BEUHZSY.js";
4
4
  import {
5
5
  cuid,
6
6
  uuidV4
7
- } from "./chunk-3KG2HTZ3.js";
7
+ } from "./chunk-7X2CUDBX.js";
8
8
  import {
9
9
  isArray,
10
10
  isEmptyString,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  hexToHSLString,
3
3
  hexToRGBStr
4
- } from "./chunk-VT24VOAZ.js";
4
+ } from "./chunk-BKX55CAI.js";
5
5
  import {
6
6
  isUndefined
7
7
  } from "./chunk-GFH3VWOC.js";
package/dist/color.cjs CHANGED
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/color.ts
31
31
  var color_exports = {};
32
32
  __export(color_exports, {
33
- generateAutoStateColors: () => generateAutoStateColors,
33
+ generateStateColors: () => generateStateColors,
34
34
  hexToHSLString: () => hexToHSLString,
35
35
  hexToRGBStr: () => hexToRGBStr
36
36
  });
@@ -59,26 +59,37 @@ var hexToRGBStr = (hex) => {
59
59
  return "0, 0, 0";
60
60
  }
61
61
  };
62
- function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activeRatio = 0.24) {
63
- const isBaseLight = (0, import_chroma_js.default)(baseColor).luminance() > 0.8;
62
+ function generateStateColors(baseColor, brandColor, options = {}) {
63
+ const {
64
+ brandHoverRatio = 0.175,
65
+ brandActiveRatio = 0.14,
66
+ lightHoverRatio = 0.11,
67
+ lightActiveRatio = 0.225
68
+ } = options;
69
+ const baseLuminance = (0, import_chroma_js.default)(baseColor).luminance();
70
+ const isBaseLight = baseLuminance > 0.8;
71
+ const isBaseDark = baseLuminance < 0.2;
64
72
  const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
65
73
  let hover;
66
74
  let active;
67
75
  if (isBaseBrand) {
68
- hover = import_chroma_js.default.mix(baseColor, "#fff", hoverRatio, "rgb").hex();
69
- active = import_chroma_js.default.mix(baseColor, "#fff", activeRatio, "rgb").hex();
76
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
77
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
70
78
  } else if (isBaseLight) {
71
- hover = import_chroma_js.default.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
72
- active = import_chroma_js.default.mix(baseColor, brandColor, activeRatio, "rgb").hex();
79
+ hover = import_chroma_js.default.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
80
+ active = import_chroma_js.default.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
81
+ } else if (isBaseDark) {
82
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
83
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
73
84
  } else {
74
- hover = import_chroma_js.default.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
75
- active = import_chroma_js.default.mix(baseColor, brandColor, activeRatio, "rgb").hex();
85
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
86
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
76
87
  }
77
88
  return { hover, active };
78
89
  }
79
90
  // Annotate the CommonJS export names for ESM import in node:
80
91
  0 && (module.exports = {
81
- generateAutoStateColors,
92
+ generateStateColors,
82
93
  hexToHSLString,
83
94
  hexToRGBStr
84
95
  });
package/dist/color.d.cts CHANGED
@@ -11,19 +11,44 @@ declare function hexToHSLString(hexColor: string): string;
11
11
  */
12
12
  declare const hexToRGBStr: (hex: string) => string;
13
13
  /**
14
- * Automatically generate hover and active colors based on baseColor and brandColor.
15
- * If baseColor is similar to brandColor, hover is mixed with white (LAB), active is darkened.
16
- * If baseColor is light (e.g., white), hover/active are mixed with brandColor (LAB).
17
- * Otherwise, hover is mixed with brandColor (LAB), active is darkened.
18
- * @param baseColor - The base color (e.g., button or content background)
19
- * @param brandColor - The brand color
20
- * @param hoverRatio - Mix ratio for hover state (default 0.15)
21
- * @param activeDarken - Darken factor for active state (default 0.12)
22
- * @returns An object with hover and active color hex strings
14
+ * Configuration options for state color generation
23
15
  */
24
- declare function generateAutoStateColors(baseColor: string, brandColor: string, hoverRatio?: number, activeRatio?: number): {
16
+ interface StateColorOptions {
17
+ /** Mix ratio for hover state when base is brand color (default 0.175) */
18
+ brandHoverRatio?: number;
19
+ /** Mix ratio for active/click state when base is brand color (default 0.14) */
20
+ brandActiveRatio?: number;
21
+ /** Mix ratio for hover state when base is light color (default 0.11) */
22
+ lightHoverRatio?: number;
23
+ /** Mix ratio for active/click state when base is light color (default 0.225) */
24
+ lightActiveRatio?: number;
25
+ }
26
+ /**
27
+ * Generate hover and active state colors based on base color and brand color.
28
+ *
29
+ * Logic:
30
+ * - Brand color base: hover = tint (mix with white), active = shade (mix with black)
31
+ * - Light color base (e.g., white): hover/active = mix with brand color
32
+ * - Dark color base: hover = tint (mix with white), active = shade (mix with black)
33
+ *
34
+ * @param baseColor - The base background color
35
+ * @param brandColor - The brand/primary color
36
+ * @param options - Optional configuration for mix ratios
37
+ * @returns Object containing hover and active color hex strings
38
+ *
39
+ * @example
40
+ * // Brand color button
41
+ * generateStateColors('#2563eb', '#2563eb');
42
+ * // Returns: { hover: '#4b7eee', active: '#2055c9' }
43
+ *
44
+ * @example
45
+ * // White background content
46
+ * generateStateColors('#ffffff', '#2563eb');
47
+ * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
48
+ */
49
+ declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
25
50
  hover: string;
26
51
  active: string;
27
52
  };
28
53
 
29
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr };
54
+ export { type StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.d.ts CHANGED
@@ -11,19 +11,44 @@ declare function hexToHSLString(hexColor: string): string;
11
11
  */
12
12
  declare const hexToRGBStr: (hex: string) => string;
13
13
  /**
14
- * Automatically generate hover and active colors based on baseColor and brandColor.
15
- * If baseColor is similar to brandColor, hover is mixed with white (LAB), active is darkened.
16
- * If baseColor is light (e.g., white), hover/active are mixed with brandColor (LAB).
17
- * Otherwise, hover is mixed with brandColor (LAB), active is darkened.
18
- * @param baseColor - The base color (e.g., button or content background)
19
- * @param brandColor - The brand color
20
- * @param hoverRatio - Mix ratio for hover state (default 0.15)
21
- * @param activeDarken - Darken factor for active state (default 0.12)
22
- * @returns An object with hover and active color hex strings
14
+ * Configuration options for state color generation
23
15
  */
24
- declare function generateAutoStateColors(baseColor: string, brandColor: string, hoverRatio?: number, activeRatio?: number): {
16
+ interface StateColorOptions {
17
+ /** Mix ratio for hover state when base is brand color (default 0.175) */
18
+ brandHoverRatio?: number;
19
+ /** Mix ratio for active/click state when base is brand color (default 0.14) */
20
+ brandActiveRatio?: number;
21
+ /** Mix ratio for hover state when base is light color (default 0.11) */
22
+ lightHoverRatio?: number;
23
+ /** Mix ratio for active/click state when base is light color (default 0.225) */
24
+ lightActiveRatio?: number;
25
+ }
26
+ /**
27
+ * Generate hover and active state colors based on base color and brand color.
28
+ *
29
+ * Logic:
30
+ * - Brand color base: hover = tint (mix with white), active = shade (mix with black)
31
+ * - Light color base (e.g., white): hover/active = mix with brand color
32
+ * - Dark color base: hover = tint (mix with white), active = shade (mix with black)
33
+ *
34
+ * @param baseColor - The base background color
35
+ * @param brandColor - The brand/primary color
36
+ * @param options - Optional configuration for mix ratios
37
+ * @returns Object containing hover and active color hex strings
38
+ *
39
+ * @example
40
+ * // Brand color button
41
+ * generateStateColors('#2563eb', '#2563eb');
42
+ * // Returns: { hover: '#4b7eee', active: '#2055c9' }
43
+ *
44
+ * @example
45
+ * // White background content
46
+ * generateStateColors('#ffffff', '#2563eb');
47
+ * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
48
+ */
49
+ declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
25
50
  hover: string;
26
51
  active: string;
27
52
  };
28
53
 
29
- export { generateAutoStateColors, hexToHSLString, hexToRGBStr };
54
+ export { type StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
- generateAutoStateColors,
2
+ generateStateColors,
3
3
  hexToHSLString,
4
4
  hexToRGBStr
5
- } from "./chunk-VT24VOAZ.js";
5
+ } from "./chunk-BKX55CAI.js";
6
6
  import "./chunk-XEO3YXBM.js";
7
7
  export {
8
- generateAutoStateColors,
8
+ generateStateColors,
9
9
  hexToHSLString,
10
10
  hexToRGBStr
11
11
  };
@@ -466,13 +466,13 @@ function hexToRgb(hex) {
466
466
  b: Number.parseInt(result[3], 16)
467
467
  } : null;
468
468
  }
469
- var isDark = (hex) => {
469
+ var isLight = (hex) => {
470
470
  const rgb = hexToRgb(hex);
471
471
  if (!rgb) {
472
472
  return null;
473
473
  }
474
474
  const { r, g, b } = rgb;
475
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
475
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
476
476
  return true;
477
477
  }
478
478
  return false;
@@ -8,10 +8,10 @@ import {
8
8
  isConditionsActived,
9
9
  isEqual,
10
10
  regenerateConditionIds
11
- } from "../chunk-SIG4WTEF.js";
11
+ } from "../chunk-5BEUHZSY.js";
12
12
  import "../chunk-YYIGUZNZ.js";
13
13
  import "../chunk-PAESAL23.js";
14
- import "../chunk-3KG2HTZ3.js";
14
+ import "../chunk-7X2CUDBX.js";
15
15
  import "../chunk-KYDXF7SU.js";
16
16
  import "../chunk-JQWKLXW6.js";
17
17
  import "../chunk-GFH3VWOC.js";
@@ -511,13 +511,13 @@ function hexToRgb(hex) {
511
511
  b: Number.parseInt(result[3], 16)
512
512
  } : null;
513
513
  }
514
- var isDark = (hex) => {
514
+ var isLight = (hex) => {
515
515
  const rgb = hexToRgb(hex);
516
516
  if (!rgb) {
517
517
  return null;
518
518
  }
519
519
  const { r, g, b } = rgb;
520
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
520
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
521
521
  return true;
522
522
  }
523
523
  return false;
@@ -9,13 +9,13 @@ import {
9
9
  isConditionsActived,
10
10
  isEqual,
11
11
  regenerateConditionIds
12
- } from "../chunk-SIG4WTEF.js";
12
+ } from "../chunk-5BEUHZSY.js";
13
13
  import {
14
14
  evaluateUrlCondition,
15
15
  isMatchUrlPattern
16
16
  } from "../chunk-YYIGUZNZ.js";
17
17
  import "../chunk-PAESAL23.js";
18
- import "../chunk-3KG2HTZ3.js";
18
+ import "../chunk-7X2CUDBX.js";
19
19
  import {
20
20
  evaluateAttributeCondition
21
21
  } from "../chunk-KYDXF7SU.js";
@@ -82,13 +82,13 @@ function hexToRgb(hex) {
82
82
  b: Number.parseInt(result[3], 16)
83
83
  } : null;
84
84
  }
85
- var isDark = (hex) => {
85
+ var isLight = (hex) => {
86
86
  const rgb = hexToRgb(hex);
87
87
  if (!rgb) {
88
88
  return null;
89
89
  }
90
90
  const { r, g, b } = rgb;
91
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
91
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
92
92
  return true;
93
93
  }
94
94
  return false;
@@ -14,12 +14,12 @@ import {
14
14
  isQuestionElement,
15
15
  isRestrictedType,
16
16
  processQuestionElements
17
- } from "./chunk-2TMOS3DN.js";
17
+ } from "./chunk-KARDMYE2.js";
18
18
  import "./chunk-7ODE2AIC.js";
19
- import "./chunk-SIG4WTEF.js";
19
+ import "./chunk-5BEUHZSY.js";
20
20
  import "./chunk-YYIGUZNZ.js";
21
21
  import "./chunk-PAESAL23.js";
22
- import "./chunk-3KG2HTZ3.js";
22
+ import "./chunk-7X2CUDBX.js";
23
23
  import "./chunk-KYDXF7SU.js";
24
24
  import "./chunk-JQWKLXW6.js";
25
25
  import "./chunk-GFH3VWOC.js";
@@ -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-UMC3BUA7.js";
6
+ import "./chunk-BKX55CAI.js";
7
7
  import "./chunk-GFH3VWOC.js";
8
8
  import "./chunk-XEO3YXBM.js";
9
9
  export {
package/dist/helper.cjs CHANGED
@@ -27,7 +27,7 @@ __export(helper_exports, {
27
27
  formatDate: () => formatDate,
28
28
  getRandomColor: () => getRandomColor,
29
29
  hexToRgb: () => hexToRgb,
30
- isDark: () => isDark,
30
+ isLight: () => isLight,
31
31
  uuidV4: () => uuidV4
32
32
  });
33
33
  module.exports = __toCommonJS(helper_exports);
@@ -63,13 +63,13 @@ function hexToRgb(hex) {
63
63
  b: Number.parseInt(result[3], 16)
64
64
  } : null;
65
65
  }
66
- var isDark = (hex) => {
66
+ var isLight = (hex) => {
67
67
  const rgb = hexToRgb(hex);
68
68
  if (!rgb) {
69
69
  return null;
70
70
  }
71
71
  const { r, g, b } = rgb;
72
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
72
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
73
73
  return true;
74
74
  }
75
75
  return false;
@@ -106,6 +106,6 @@ var getRandomColor = () => {
106
106
  formatDate,
107
107
  getRandomColor,
108
108
  hexToRgb,
109
- isDark,
109
+ isLight,
110
110
  uuidV4
111
111
  });
package/dist/helper.d.cts CHANGED
@@ -10,8 +10,14 @@ declare function hexToRgb(hex: string): {
10
10
  g: number;
11
11
  b: number;
12
12
  } | null;
13
- declare const isDark: (hex: string) => boolean | null;
13
+ /**
14
+ * Check if a color is light (needs dark text).
15
+ * Only very light colors (close to white) return true.
16
+ * @param hex - Hex color string
17
+ * @returns true if the color is very light (luminance > 250), false otherwise
18
+ */
19
+ declare const isLight: (hex: string) => boolean | null;
14
20
  declare const evalCode: (code: string) => any;
15
21
  declare const getRandomColor: () => string;
16
22
 
17
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 };
23
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 };
package/dist/helper.d.ts CHANGED
@@ -10,8 +10,14 @@ declare function hexToRgb(hex: string): {
10
10
  g: number;
11
11
  b: number;
12
12
  } | null;
13
- declare const isDark: (hex: string) => boolean | null;
13
+ /**
14
+ * Check if a color is light (needs dark text).
15
+ * Only very light colors (close to white) return true.
16
+ * @param hex - Hex color string
17
+ * @returns true if the color is very light (luminance > 250), false otherwise
18
+ */
19
+ declare const isLight: (hex: string) => boolean | null;
14
20
  declare const evalCode: (code: string) => any;
15
21
  declare const getRandomColor: () => string;
16
22
 
17
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 };
23
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 };
package/dist/helper.js CHANGED
@@ -6,9 +6,9 @@ import {
6
6
  formatDate,
7
7
  getRandomColor,
8
8
  hexToRgb,
9
- isDark,
9
+ isLight,
10
10
  uuidV4
11
- } from "./chunk-3KG2HTZ3.js";
11
+ } from "./chunk-7X2CUDBX.js";
12
12
  import "./chunk-XEO3YXBM.js";
13
13
  export {
14
14
  absoluteUrl,
@@ -18,6 +18,6 @@ export {
18
18
  formatDate,
19
19
  getRandomColor,
20
20
  hexToRgb,
21
- isDark,
21
+ isLight,
22
22
  uuidV4
23
23
  };
package/dist/index.cjs CHANGED
@@ -73,7 +73,7 @@ __export(src_exports, {
73
73
  filterConditionsByType: () => filterConditionsByType,
74
74
  filterNullAttributes: () => filterNullAttributes,
75
75
  formatDate: () => formatDate,
76
- generateAutoStateColors: () => generateAutoStateColors,
76
+ generateStateColors: () => generateStateColors,
77
77
  generateUniqueCopyName: () => generateUniqueCopyName,
78
78
  getAttributeType: () => getAttributeType,
79
79
  getAuthToken: () => getAuthToken,
@@ -101,7 +101,6 @@ __export(src_exports, {
101
101
  isBoolean: () => isBoolean,
102
102
  isClickableElement: () => isClickableElement,
103
103
  isConditionsActived: () => isConditionsActived,
104
- isDark: () => isDark,
105
104
  isDate: () => isDate,
106
105
  isDocument: () => isDocument,
107
106
  isEmptyObject: () => isEmptyObject,
@@ -110,6 +109,7 @@ __export(src_exports, {
110
109
  isFile: () => isFile,
111
110
  isFormData: () => isFormData,
112
111
  isFunction: () => isFunction,
112
+ isLight: () => isLight,
113
113
  isMatchUrlPattern: () => isMatchUrlPattern,
114
114
  isMissingRequiredData: () => isMissingRequiredData,
115
115
  isNull: () => isNull,
@@ -176,20 +176,31 @@ var hexToRGBStr = (hex) => {
176
176
  return "0, 0, 0";
177
177
  }
178
178
  };
179
- function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activeRatio = 0.24) {
180
- const isBaseLight = (0, import_chroma_js.default)(baseColor).luminance() > 0.8;
179
+ function generateStateColors(baseColor, brandColor, options = {}) {
180
+ const {
181
+ brandHoverRatio = 0.175,
182
+ brandActiveRatio = 0.14,
183
+ lightHoverRatio = 0.11,
184
+ lightActiveRatio = 0.225
185
+ } = options;
186
+ const baseLuminance = (0, import_chroma_js.default)(baseColor).luminance();
187
+ const isBaseLight = baseLuminance > 0.8;
188
+ const isBaseDark = baseLuminance < 0.2;
181
189
  const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
182
190
  let hover;
183
191
  let active;
184
192
  if (isBaseBrand) {
185
- hover = import_chroma_js.default.mix(baseColor, "#fff", hoverRatio, "rgb").hex();
186
- active = import_chroma_js.default.mix(baseColor, "#fff", activeRatio, "rgb").hex();
193
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
194
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
187
195
  } else if (isBaseLight) {
188
- hover = import_chroma_js.default.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
189
- active = import_chroma_js.default.mix(baseColor, brandColor, activeRatio, "rgb").hex();
196
+ hover = import_chroma_js.default.mix(baseColor, brandColor, lightHoverRatio, "rgb").hex();
197
+ active = import_chroma_js.default.mix(baseColor, brandColor, lightActiveRatio, "rgb").hex();
198
+ } else if (isBaseDark) {
199
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
200
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
190
201
  } else {
191
- hover = import_chroma_js.default.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
192
- active = import_chroma_js.default.mix(baseColor, brandColor, activeRatio, "rgb").hex();
202
+ hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
203
+ active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
193
204
  }
194
205
  return { hover, active };
195
206
  }
@@ -1229,13 +1240,13 @@ function hexToRgb(hex) {
1229
1240
  b: Number.parseInt(result[3], 16)
1230
1241
  } : null;
1231
1242
  }
1232
- var isDark = (hex) => {
1243
+ var isLight = (hex) => {
1233
1244
  const rgb = hexToRgb(hex);
1234
1245
  if (!rgb) {
1235
1246
  return null;
1236
1247
  }
1237
1248
  const { r, g, b } = rgb;
1238
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
1249
+ if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
1239
1250
  return true;
1240
1251
  }
1241
1252
  return false;
@@ -1950,7 +1961,7 @@ var duplicateStep = (step) => {
1950
1961
  filterConditionsByType,
1951
1962
  filterNullAttributes,
1952
1963
  formatDate,
1953
- generateAutoStateColors,
1964
+ generateStateColors,
1954
1965
  generateUniqueCopyName,
1955
1966
  getAttributeType,
1956
1967
  getAuthToken,
@@ -1978,7 +1989,6 @@ var duplicateStep = (step) => {
1978
1989
  isBoolean,
1979
1990
  isClickableElement,
1980
1991
  isConditionsActived,
1981
- isDark,
1982
1992
  isDate,
1983
1993
  isDocument,
1984
1994
  isEmptyObject,
@@ -1987,6 +1997,7 @@ var duplicateStep = (step) => {
1987
1997
  isFile,
1988
1998
  isFormData,
1989
1999
  isFunction,
2000
+ isLight,
1990
2001
  isMatchUrlPattern,
1991
2002
  isMissingRequiredData,
1992
2003
  isNull,
package/dist/index.d.cts CHANGED
@@ -7,8 +7,8 @@ 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';
11
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
10
+ export { StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
11
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, 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';
14
14
  export { convertTimeConditionLegacyToV2, evaluateTimeCondition, isTimeConditionDataLegacy, isTimeConditionDataV2, normalizeTimeConditionData } from './conditions/time.cjs';
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@ 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';
11
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
10
+ export { StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr } from './color.js';
11
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, 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';
14
14
  export { convertTimeConditionLegacyToV2, evaluateTimeCondition, isTimeConditionDataLegacy, isTimeConditionDataV2, normalizeTimeConditionData } from './conditions/time.js';
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  isQuestionElement,
39
39
  isRestrictedType,
40
40
  processQuestionElements
41
- } from "./chunk-2TMOS3DN.js";
41
+ } from "./chunk-KARDMYE2.js";
42
42
  import "./chunk-7ODE2AIC.js";
43
43
  import {
44
44
  allConditionsHaveIds,
@@ -50,7 +50,7 @@ import {
50
50
  isConditionsActived,
51
51
  isEqual,
52
52
  regenerateConditionIds
53
- } from "./chunk-SIG4WTEF.js";
53
+ } from "./chunk-5BEUHZSY.js";
54
54
  import {
55
55
  evaluateUrlCondition,
56
56
  isMatchUrlPattern
@@ -64,9 +64,9 @@ import {
64
64
  formatDate,
65
65
  getRandomColor,
66
66
  hexToRgb,
67
- isDark,
67
+ isLight,
68
68
  uuidV4
69
- } from "./chunk-3KG2HTZ3.js";
69
+ } from "./chunk-7X2CUDBX.js";
70
70
  import {
71
71
  evaluateAttributeCondition
72
72
  } from "./chunk-KYDXF7SU.js";
@@ -82,12 +82,12 @@ import {
82
82
  convertSettings,
83
83
  convertToCssVars,
84
84
  mergeThemeDefaultSettings
85
- } from "./chunk-OBKNA55U.js";
85
+ } from "./chunk-UMC3BUA7.js";
86
86
  import {
87
- generateAutoStateColors,
87
+ generateStateColors,
88
88
  hexToHSLString,
89
89
  hexToRGBStr
90
- } from "./chunk-VT24VOAZ.js";
90
+ } from "./chunk-BKX55CAI.js";
91
91
  import {
92
92
  getCodeError,
93
93
  getContentError,
@@ -185,7 +185,7 @@ export {
185
185
  filterConditionsByType,
186
186
  filterNullAttributes,
187
187
  formatDate,
188
- generateAutoStateColors,
188
+ generateStateColors,
189
189
  generateUniqueCopyName,
190
190
  getAttributeType,
191
191
  getAuthToken,
@@ -213,7 +213,6 @@ export {
213
213
  isBoolean,
214
214
  isClickableElement,
215
215
  isConditionsActived,
216
- isDark,
217
216
  isDate,
218
217
  isDocument,
219
218
  isEmptyObject,
@@ -222,6 +221,7 @@ export {
222
221
  isFile,
223
222
  isFormData,
224
223
  isFunction,
224
+ isLight,
225
225
  isMatchUrlPattern,
226
226
  isMissingRequiredData,
227
227
  isNull,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
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",
@@ -1,48 +0,0 @@
1
- // src/color.ts
2
- import chroma from "chroma-js";
3
- function hexToHSLString(hexColor) {
4
- try {
5
- const color = chroma(hexColor);
6
- const [h, s, l] = color.hsl();
7
- const hDeg = Math.round(h || 0);
8
- const sPct = Math.round(s * 100);
9
- const lPct = Math.round(l * 100);
10
- return `${hDeg} ${sPct}% ${lPct}%`;
11
- } catch (error) {
12
- console.warn(`Failed to convert ${hexColor} to HSL string:`, error);
13
- return "0 0% 0%";
14
- }
15
- }
16
- var hexToRGBStr = (hex) => {
17
- try {
18
- const color = chroma(hex);
19
- const [r, g, b] = color.rgb();
20
- return `${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}`;
21
- } catch (error) {
22
- console.warn(`Failed to convert ${hex} to RGB string:`, error);
23
- return "0, 0, 0";
24
- }
25
- };
26
- function generateAutoStateColors(baseColor, brandColor, hoverRatio = 0.12, activeRatio = 0.24) {
27
- const isBaseLight = chroma(baseColor).luminance() > 0.8;
28
- const isBaseBrand = chroma.distance(baseColor, brandColor) < 10;
29
- let hover;
30
- let active;
31
- if (isBaseBrand) {
32
- hover = chroma.mix(baseColor, "#fff", hoverRatio, "rgb").hex();
33
- active = chroma.mix(baseColor, "#fff", activeRatio, "rgb").hex();
34
- } else if (isBaseLight) {
35
- hover = chroma.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
36
- active = chroma.mix(baseColor, brandColor, activeRatio, "rgb").hex();
37
- } else {
38
- hover = chroma.mix(baseColor, brandColor, hoverRatio, "rgb").hex();
39
- active = chroma.mix(baseColor, brandColor, activeRatio, "rgb").hex();
40
- }
41
- return { hover, active };
42
- }
43
-
44
- export {
45
- hexToHSLString,
46
- hexToRGBStr,
47
- generateAutoStateColors
48
- };