@usertour/helpers 0.0.55 → 0.0.57

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,17 +451,6 @@ function hexToRgb(hex) {
451
451
  b: Number.parseInt(result[3], 16)
452
452
  } : null;
453
453
  }
454
- var isLight = (hex) => {
455
- const rgb = hexToRgb(hex);
456
- if (!rgb) {
457
- return null;
458
- }
459
- const { r, g, b } = rgb;
460
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
461
- return true;
462
- }
463
- return false;
464
- };
465
454
  var evalCode = (code) => {
466
455
  try {
467
456
  return eval(code);
@@ -2,10 +2,10 @@ import {
2
2
  evaluateRulesConditions,
3
3
  filterConditionsByType,
4
4
  isConditionsActived
5
- } from "../chunk-5BEUHZSY.js";
5
+ } from "../chunk-X6R6AH7G.js";
6
6
  import "../chunk-YYIGUZNZ.js";
7
7
  import "../chunk-PAESAL23.js";
8
- import "../chunk-7X2CUDBX.js";
8
+ import "../chunk-73OREOHT.js";
9
9
  import "../chunk-KYDXF7SU.js";
10
10
  import "../chunk-JQWKLXW6.js";
11
11
  import "../chunk-GFH3VWOC.js";
@@ -61,17 +61,6 @@ function hexToRgb(hex) {
61
61
  b: Number.parseInt(result[3], 16)
62
62
  } : null;
63
63
  }
64
- var isLight = (hex) => {
65
- const rgb = hexToRgb(hex);
66
- if (!rgb) {
67
- return null;
68
- }
69
- const { r, g, b } = rgb;
70
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
71
- return true;
72
- }
73
- return false;
74
- };
75
64
  var evalCode = (code) => {
76
65
  try {
77
66
  return eval(code);
@@ -14,12 +14,12 @@ import {
14
14
  isQuestionElement,
15
15
  isRestrictedType,
16
16
  processQuestionElements
17
- } from "../chunk-KARDMYE2.js";
17
+ } from "../chunk-RQ4UE7ZB.js";
18
18
  import "../chunk-7ODE2AIC.js";
19
- import "../chunk-5BEUHZSY.js";
19
+ import "../chunk-X6R6AH7G.js";
20
20
  import "../chunk-YYIGUZNZ.js";
21
21
  import "../chunk-PAESAL23.js";
22
- import "../chunk-7X2CUDBX.js";
22
+ import "../chunk-73OREOHT.js";
23
23
  import "../chunk-KYDXF7SU.js";
24
24
  import "../chunk-JQWKLXW6.js";
25
25
  import "../chunk-GFH3VWOC.js";
@@ -31,17 +31,6 @@ function hexToRgb(hex) {
31
31
  b: Number.parseInt(result[3], 16)
32
32
  } : null;
33
33
  }
34
- var isLight = (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 > 250) {
41
- return true;
42
- }
43
- return false;
44
- };
45
34
  var evalCode = (code) => {
46
35
  try {
47
36
  return eval(code);
@@ -73,7 +62,6 @@ export {
73
62
  absoluteUrl,
74
63
  uuidV4,
75
64
  hexToRgb,
76
- isLight,
77
65
  evalCode,
78
66
  getRandomColor
79
67
  };
@@ -0,0 +1,133 @@
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 hexToRgb(hex) {
27
+ if (!hex)
28
+ return [0, 0, 0];
29
+ if (hex.match(/^#[0-9a-f]{6}$/i)) {
30
+ return [
31
+ Number.parseInt(hex.substring(1, 3), 16),
32
+ Number.parseInt(hex.substring(3, 5), 16),
33
+ Number.parseInt(hex.substring(5, 7), 16)
34
+ ];
35
+ }
36
+ if (hex.match(/^#[0-9a-f]{3}$/i)) {
37
+ return [
38
+ Number.parseInt(hex.substring(1, 2).repeat(2), 16),
39
+ Number.parseInt(hex.substring(2, 3).repeat(2), 16),
40
+ Number.parseInt(hex.substring(3, 4).repeat(2), 16)
41
+ ];
42
+ }
43
+ return [0, 0, 0];
44
+ }
45
+ function rgbToHex([r, g, b]) {
46
+ const rHex = r.toString(16).padStart(2, "0");
47
+ const gHex = g.toString(16).padStart(2, "0");
48
+ const bHex = b.toString(16).padStart(2, "0");
49
+ return `#${rHex}${gHex}${bHex}`;
50
+ }
51
+ function rgbToHsl([r, g, b]) {
52
+ const rNorm = r / 255;
53
+ const gNorm = g / 255;
54
+ const bNorm = b / 255;
55
+ const max = Math.max(rNorm, gNorm, bNorm);
56
+ const min = Math.min(rNorm, gNorm, bNorm);
57
+ const l = (max + min) / 2;
58
+ let h = 0;
59
+ let s = 0;
60
+ if (max !== min) {
61
+ const d = max - min;
62
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
63
+ switch (max) {
64
+ case rNorm:
65
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
66
+ break;
67
+ case gNorm:
68
+ h = (bNorm - rNorm) / d + 2;
69
+ break;
70
+ default:
71
+ h = (rNorm - gNorm) / d + 4;
72
+ break;
73
+ }
74
+ h /= 6;
75
+ }
76
+ return [h, s, l];
77
+ }
78
+ function getLabLuminance([r, g, b]) {
79
+ function linearize(channel) {
80
+ const c = channel / 255;
81
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
82
+ }
83
+ const y = 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
84
+ function yToLabL(yVal) {
85
+ return yVal <= 216 / 24389 ? yVal * (24389 / 27) : yVal ** (1 / 3) * 116 - 16;
86
+ }
87
+ return Math.round(yToLabL(y) * 10) / 1e3;
88
+ }
89
+ function invertColor([r, g, b]) {
90
+ return [Math.round(255 - r), Math.round(255 - g), Math.round(255 - b)];
91
+ }
92
+ function mixRgb(color1, color2, ratio) {
93
+ return [
94
+ Math.max(0, Math.min(255, Math.round(color1[0] + (color2[0] - color1[0]) * ratio))),
95
+ Math.max(0, Math.min(255, Math.round(color1[1] + (color2[1] - color1[1]) * ratio))),
96
+ Math.max(0, Math.min(255, Math.round(color1[2] + (color2[2] - color1[2]) * ratio)))
97
+ ];
98
+ }
99
+ function calculateMixRatio(foreground, background) {
100
+ const fgLuminance = getLabLuminance(foreground);
101
+ const bgLuminance = getLabLuminance(background);
102
+ const minRatio = 0.05;
103
+ const baseRatio = (1 - (bgLuminance - fgLuminance)) / 2 * (0.18 - minRatio) + minRatio;
104
+ const luminanceSimilarity = 1 - Math.abs(bgLuminance - fgLuminance);
105
+ const adjustment = ((1 - baseRatio) * luminanceSimilarity) ** 4;
106
+ const finalRatio = baseRatio + adjustment;
107
+ return Math.round(finalRatio * 1e3) / 1e3;
108
+ }
109
+ function generateStateColors(backgroundColor, foregroundColor) {
110
+ const bgRgb = hexToRgb(backgroundColor);
111
+ const fgRgb = hexToRgb(foregroundColor);
112
+ const bgHsl = rgbToHsl(bgRgb);
113
+ const hoverRatio = calculateMixRatio(fgRgb, bgRgb);
114
+ let activeRatio = hoverRatio * 2;
115
+ let activeMixColor = fgRgb;
116
+ const midToneThreshold = 0.2;
117
+ if (bgHsl[2] > midToneThreshold && bgHsl[2] < 1 - midToneThreshold) {
118
+ activeMixColor = invertColor(fgRgb);
119
+ activeRatio = calculateMixRatio(activeMixColor, bgRgb);
120
+ }
121
+ const hoverRgb = mixRgb(bgRgb, fgRgb, hoverRatio);
122
+ const activeRgb = mixRgb(bgRgb, activeMixColor, activeRatio);
123
+ return {
124
+ hover: rgbToHex(hoverRgb),
125
+ active: rgbToHex(activeRgb)
126
+ };
127
+ }
128
+
129
+ export {
130
+ hexToHSLString,
131
+ hexToRGBStr,
132
+ generateStateColors
133
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  hexToHSLString,
3
3
  hexToRGBStr
4
- } from "./chunk-BKX55CAI.js";
4
+ } from "./chunk-FZFHBCB6.js";
5
5
  import {
6
6
  isUndefined
7
7
  } from "./chunk-GFH3VWOC.js";
@@ -9,7 +9,7 @@ import {
9
9
  // src/convert-settings.ts
10
10
  import { defaultSettings } from "@usertour/types";
11
11
  import { deepmerge } from "deepmerge-ts";
12
- var defaultFontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
12
+ var defaultFontFamily = '-apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
13
13
  var mergeThemeDefaultSettings = (settings) => {
14
14
  return deepmerge(defaultSettings, settings);
15
15
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  regenerateConditionIds
3
- } from "./chunk-5BEUHZSY.js";
3
+ } from "./chunk-X6R6AH7G.js";
4
4
  import {
5
5
  cuid,
6
6
  uuidV4
7
- } from "./chunk-7X2CUDBX.js";
7
+ } from "./chunk-73OREOHT.js";
8
8
  import {
9
9
  isArray,
10
10
  isEmptyString,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-YYIGUZNZ.js";
4
4
  import {
5
5
  cuid
6
- } from "./chunk-7X2CUDBX.js";
6
+ } from "./chunk-73OREOHT.js";
7
7
  import {
8
8
  evaluateAttributeCondition
9
9
  } from "./chunk-KYDXF7SU.js";
package/dist/color.cjs CHANGED
@@ -59,33 +59,107 @@ var hexToRGBStr = (hex) => {
59
59
  return "0, 0, 0";
60
60
  }
61
61
  };
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;
72
- const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
73
- let hover;
74
- let active;
75
- if (isBaseBrand) {
76
- hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
77
- active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
78
- } else if (isBaseLight) {
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();
84
- } else {
85
- hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
86
- active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
62
+ function hexToRgb(hex) {
63
+ if (!hex)
64
+ return [0, 0, 0];
65
+ if (hex.match(/^#[0-9a-f]{6}$/i)) {
66
+ return [
67
+ Number.parseInt(hex.substring(1, 3), 16),
68
+ Number.parseInt(hex.substring(3, 5), 16),
69
+ Number.parseInt(hex.substring(5, 7), 16)
70
+ ];
87
71
  }
88
- return { hover, active };
72
+ if (hex.match(/^#[0-9a-f]{3}$/i)) {
73
+ return [
74
+ Number.parseInt(hex.substring(1, 2).repeat(2), 16),
75
+ Number.parseInt(hex.substring(2, 3).repeat(2), 16),
76
+ Number.parseInt(hex.substring(3, 4).repeat(2), 16)
77
+ ];
78
+ }
79
+ return [0, 0, 0];
80
+ }
81
+ function rgbToHex([r, g, b]) {
82
+ const rHex = r.toString(16).padStart(2, "0");
83
+ const gHex = g.toString(16).padStart(2, "0");
84
+ const bHex = b.toString(16).padStart(2, "0");
85
+ return `#${rHex}${gHex}${bHex}`;
86
+ }
87
+ function rgbToHsl([r, g, b]) {
88
+ const rNorm = r / 255;
89
+ const gNorm = g / 255;
90
+ const bNorm = b / 255;
91
+ const max = Math.max(rNorm, gNorm, bNorm);
92
+ const min = Math.min(rNorm, gNorm, bNorm);
93
+ const l = (max + min) / 2;
94
+ let h = 0;
95
+ let s = 0;
96
+ if (max !== min) {
97
+ const d = max - min;
98
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
99
+ switch (max) {
100
+ case rNorm:
101
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
102
+ break;
103
+ case gNorm:
104
+ h = (bNorm - rNorm) / d + 2;
105
+ break;
106
+ default:
107
+ h = (rNorm - gNorm) / d + 4;
108
+ break;
109
+ }
110
+ h /= 6;
111
+ }
112
+ return [h, s, l];
113
+ }
114
+ function getLabLuminance([r, g, b]) {
115
+ function linearize(channel) {
116
+ const c = channel / 255;
117
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
118
+ }
119
+ const y = 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
120
+ function yToLabL(yVal) {
121
+ return yVal <= 216 / 24389 ? yVal * (24389 / 27) : yVal ** (1 / 3) * 116 - 16;
122
+ }
123
+ return Math.round(yToLabL(y) * 10) / 1e3;
124
+ }
125
+ function invertColor([r, g, b]) {
126
+ return [Math.round(255 - r), Math.round(255 - g), Math.round(255 - b)];
127
+ }
128
+ function mixRgb(color1, color2, ratio) {
129
+ return [
130
+ Math.max(0, Math.min(255, Math.round(color1[0] + (color2[0] - color1[0]) * ratio))),
131
+ Math.max(0, Math.min(255, Math.round(color1[1] + (color2[1] - color1[1]) * ratio))),
132
+ Math.max(0, Math.min(255, Math.round(color1[2] + (color2[2] - color1[2]) * ratio)))
133
+ ];
134
+ }
135
+ function calculateMixRatio(foreground, background) {
136
+ const fgLuminance = getLabLuminance(foreground);
137
+ const bgLuminance = getLabLuminance(background);
138
+ const minRatio = 0.05;
139
+ const baseRatio = (1 - (bgLuminance - fgLuminance)) / 2 * (0.18 - minRatio) + minRatio;
140
+ const luminanceSimilarity = 1 - Math.abs(bgLuminance - fgLuminance);
141
+ const adjustment = ((1 - baseRatio) * luminanceSimilarity) ** 4;
142
+ const finalRatio = baseRatio + adjustment;
143
+ return Math.round(finalRatio * 1e3) / 1e3;
144
+ }
145
+ function generateStateColors(backgroundColor, foregroundColor) {
146
+ const bgRgb = hexToRgb(backgroundColor);
147
+ const fgRgb = hexToRgb(foregroundColor);
148
+ const bgHsl = rgbToHsl(bgRgb);
149
+ const hoverRatio = calculateMixRatio(fgRgb, bgRgb);
150
+ let activeRatio = hoverRatio * 2;
151
+ let activeMixColor = fgRgb;
152
+ const midToneThreshold = 0.2;
153
+ if (bgHsl[2] > midToneThreshold && bgHsl[2] < 1 - midToneThreshold) {
154
+ activeMixColor = invertColor(fgRgb);
155
+ activeRatio = calculateMixRatio(activeMixColor, bgRgb);
156
+ }
157
+ const hoverRgb = mixRgb(bgRgb, fgRgb, hoverRatio);
158
+ const activeRgb = mixRgb(bgRgb, activeMixColor, activeRatio);
159
+ return {
160
+ hover: rgbToHex(hoverRgb),
161
+ active: rgbToHex(activeRgb)
162
+ };
89
163
  }
90
164
  // Annotate the CommonJS export names for ESM import in node:
91
165
  0 && (module.exports = {
package/dist/color.d.cts CHANGED
@@ -11,44 +11,42 @@ declare function hexToHSLString(hexColor: string): string;
11
11
  */
12
12
  declare const hexToRGBStr: (hex: string) => string;
13
13
  /**
14
- * Configuration options for state color generation
15
- */
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.
14
+ * Generate hover and active state colors based on background and foreground colors.
28
15
  *
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)
16
+ * Algorithm:
17
+ * 1. Calculate dynamic mix ratio based on Lab luminance difference
18
+ * 2. Hover = background mixed with foreground at calculated ratio
19
+ * 3. Active = background mixed with foreground (or its inverse) at 2x ratio
20
+ * 4. For mid-tone backgrounds (lightness 0.2-0.8), active uses inverted foreground
21
+ * to create more distinct visual feedback
33
22
  *
34
- * @param baseColor - The base background color
35
- * @param brandColor - The brand/primary color
36
- * @param options - Optional configuration for mix ratios
23
+ * @param backgroundColor - The base background color (hex)
24
+ * @param foregroundColor - The foreground/brand color to mix with (hex)
37
25
  * @returns Object containing hover and active color hex strings
38
26
  *
39
27
  * @example
40
- * // Brand color button
41
- * generateStateColors('#2563eb', '#2563eb');
42
- * // Returns: { hover: '#4b7eee', active: '#2055c9' }
28
+ * // Brand color button (green on green)
29
+ * generateStateColors('#65a30d', '#f8fafc');
30
+ * // Returns: { hover: '#86b643', active: '#5c940c' }
31
+ *
32
+ * @example
33
+ * // White background with blue brand
34
+ * generateStateColors('#ffffff', '#155eef');
35
+ * // Returns: { hover: '#e6eefd', active: '#ccdcfc' }
36
+ *
37
+ * @example
38
+ * // Pink background with green brand
39
+ * generateStateColors('#fecaca', '#65a30d');
40
+ * // Returns: { hover: '#cfbe90', active: '#a0b256' }
43
41
  *
44
42
  * @example
45
- * // White background content
46
- * generateStateColors('#ffffff', '#2563eb');
47
- * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
43
+ * // Green background with green brand (uses inverse for active)
44
+ * generateStateColors('#4ade80', '#65a30d');
45
+ * // Returns: { hover: '#55c753', active: '#61b8a1' }
48
46
  */
49
- declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
47
+ declare function generateStateColors(backgroundColor: string, foregroundColor: string): {
50
48
  hover: string;
51
49
  active: string;
52
50
  };
53
51
 
54
- export { type StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr };
52
+ export { generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.d.ts CHANGED
@@ -11,44 +11,42 @@ declare function hexToHSLString(hexColor: string): string;
11
11
  */
12
12
  declare const hexToRGBStr: (hex: string) => string;
13
13
  /**
14
- * Configuration options for state color generation
15
- */
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.
14
+ * Generate hover and active state colors based on background and foreground colors.
28
15
  *
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)
16
+ * Algorithm:
17
+ * 1. Calculate dynamic mix ratio based on Lab luminance difference
18
+ * 2. Hover = background mixed with foreground at calculated ratio
19
+ * 3. Active = background mixed with foreground (or its inverse) at 2x ratio
20
+ * 4. For mid-tone backgrounds (lightness 0.2-0.8), active uses inverted foreground
21
+ * to create more distinct visual feedback
33
22
  *
34
- * @param baseColor - The base background color
35
- * @param brandColor - The brand/primary color
36
- * @param options - Optional configuration for mix ratios
23
+ * @param backgroundColor - The base background color (hex)
24
+ * @param foregroundColor - The foreground/brand color to mix with (hex)
37
25
  * @returns Object containing hover and active color hex strings
38
26
  *
39
27
  * @example
40
- * // Brand color button
41
- * generateStateColors('#2563eb', '#2563eb');
42
- * // Returns: { hover: '#4b7eee', active: '#2055c9' }
28
+ * // Brand color button (green on green)
29
+ * generateStateColors('#65a30d', '#f8fafc');
30
+ * // Returns: { hover: '#86b643', active: '#5c940c' }
31
+ *
32
+ * @example
33
+ * // White background with blue brand
34
+ * generateStateColors('#ffffff', '#155eef');
35
+ * // Returns: { hover: '#e6eefd', active: '#ccdcfc' }
36
+ *
37
+ * @example
38
+ * // Pink background with green brand
39
+ * generateStateColors('#fecaca', '#65a30d');
40
+ * // Returns: { hover: '#cfbe90', active: '#a0b256' }
43
41
  *
44
42
  * @example
45
- * // White background content
46
- * generateStateColors('#ffffff', '#2563eb');
47
- * // Returns: { hover: '#e7eefd', active: '#cedcfb' }
43
+ * // Green background with green brand (uses inverse for active)
44
+ * generateStateColors('#4ade80', '#65a30d');
45
+ * // Returns: { hover: '#55c753', active: '#61b8a1' }
48
46
  */
49
- declare function generateStateColors(baseColor: string, brandColor: string, options?: StateColorOptions): {
47
+ declare function generateStateColors(backgroundColor: string, foregroundColor: string): {
50
48
  hover: string;
51
49
  active: string;
52
50
  };
53
51
 
54
- export { type StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr };
52
+ export { generateStateColors, hexToHSLString, hexToRGBStr };
package/dist/color.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  generateStateColors,
3
3
  hexToHSLString,
4
4
  hexToRGBStr
5
- } from "./chunk-BKX55CAI.js";
5
+ } from "./chunk-FZFHBCB6.js";
6
6
  import "./chunk-XEO3YXBM.js";
7
7
  export {
8
8
  generateStateColors,
@@ -466,17 +466,6 @@ function hexToRgb(hex) {
466
466
  b: Number.parseInt(result[3], 16)
467
467
  } : null;
468
468
  }
469
- var isLight = (hex) => {
470
- const rgb = hexToRgb(hex);
471
- if (!rgb) {
472
- return null;
473
- }
474
- const { r, g, b } = rgb;
475
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
476
- return true;
477
- }
478
- return false;
479
- };
480
469
  var evalCode = (code) => {
481
470
  try {
482
471
  return eval(code);
@@ -8,10 +8,10 @@ import {
8
8
  isConditionsActived,
9
9
  isEqual,
10
10
  regenerateConditionIds
11
- } from "../chunk-5BEUHZSY.js";
11
+ } from "../chunk-X6R6AH7G.js";
12
12
  import "../chunk-YYIGUZNZ.js";
13
13
  import "../chunk-PAESAL23.js";
14
- import "../chunk-7X2CUDBX.js";
14
+ import "../chunk-73OREOHT.js";
15
15
  import "../chunk-KYDXF7SU.js";
16
16
  import "../chunk-JQWKLXW6.js";
17
17
  import "../chunk-GFH3VWOC.js";
@@ -511,17 +511,6 @@ function hexToRgb(hex) {
511
511
  b: Number.parseInt(result[3], 16)
512
512
  } : null;
513
513
  }
514
- var isLight = (hex) => {
515
- const rgb = hexToRgb(hex);
516
- if (!rgb) {
517
- return null;
518
- }
519
- const { r, g, b } = rgb;
520
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
521
- return true;
522
- }
523
- return false;
524
- };
525
514
  var evalCode = (code) => {
526
515
  try {
527
516
  return eval(code);
@@ -9,13 +9,13 @@ import {
9
9
  isConditionsActived,
10
10
  isEqual,
11
11
  regenerateConditionIds
12
- } from "../chunk-5BEUHZSY.js";
12
+ } from "../chunk-X6R6AH7G.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-7X2CUDBX.js";
18
+ import "../chunk-73OREOHT.js";
19
19
  import {
20
20
  evaluateAttributeCondition
21
21
  } from "../chunk-KYDXF7SU.js";
@@ -82,17 +82,6 @@ function hexToRgb(hex) {
82
82
  b: Number.parseInt(result[3], 16)
83
83
  } : null;
84
84
  }
85
- var isLight = (hex) => {
86
- const rgb = hexToRgb(hex);
87
- if (!rgb) {
88
- return null;
89
- }
90
- const { r, g, b } = rgb;
91
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
92
- return true;
93
- }
94
- return false;
95
- };
96
85
  var evalCode = (code) => {
97
86
  try {
98
87
  return eval(code);
@@ -14,12 +14,12 @@ import {
14
14
  isQuestionElement,
15
15
  isRestrictedType,
16
16
  processQuestionElements
17
- } from "./chunk-KARDMYE2.js";
17
+ } from "./chunk-RQ4UE7ZB.js";
18
18
  import "./chunk-7ODE2AIC.js";
19
- import "./chunk-5BEUHZSY.js";
19
+ import "./chunk-X6R6AH7G.js";
20
20
  import "./chunk-YYIGUZNZ.js";
21
21
  import "./chunk-PAESAL23.js";
22
- import "./chunk-7X2CUDBX.js";
22
+ import "./chunk-73OREOHT.js";
23
23
  import "./chunk-KYDXF7SU.js";
24
24
  import "./chunk-JQWKLXW6.js";
25
25
  import "./chunk-GFH3VWOC.js";
@@ -74,7 +74,7 @@ var objHasOwn = ObjProto.hasOwnProperty;
74
74
  var isUndefined = (x) => x === void 0;
75
75
 
76
76
  // src/convert-settings.ts
77
- var defaultFontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
77
+ var defaultFontFamily = '-apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
78
78
  var mergeThemeDefaultSettings = (settings) => {
79
79
  return (0, import_deepmerge_ts.deepmerge)(import_types.defaultSettings, settings);
80
80
  };
@@ -2,8 +2,8 @@ import {
2
2
  convertSettings,
3
3
  convertToCssVars,
4
4
  mergeThemeDefaultSettings
5
- } from "./chunk-UMC3BUA7.js";
6
- import "./chunk-BKX55CAI.js";
5
+ } from "./chunk-IS56PYND.js";
6
+ import "./chunk-FZFHBCB6.js";
7
7
  import "./chunk-GFH3VWOC.js";
8
8
  import "./chunk-XEO3YXBM.js";
9
9
  export {
package/dist/helper.cjs CHANGED
@@ -27,7 +27,6 @@ __export(helper_exports, {
27
27
  formatDate: () => formatDate,
28
28
  getRandomColor: () => getRandomColor,
29
29
  hexToRgb: () => hexToRgb,
30
- isLight: () => isLight,
31
30
  uuidV4: () => uuidV4
32
31
  });
33
32
  module.exports = __toCommonJS(helper_exports);
@@ -63,17 +62,6 @@ function hexToRgb(hex) {
63
62
  b: Number.parseInt(result[3], 16)
64
63
  } : null;
65
64
  }
66
- var isLight = (hex) => {
67
- const rgb = hexToRgb(hex);
68
- if (!rgb) {
69
- return null;
70
- }
71
- const { r, g, b } = rgb;
72
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
73
- return true;
74
- }
75
- return false;
76
- };
77
65
  var evalCode = (code) => {
78
66
  try {
79
67
  return eval(code);
@@ -106,6 +94,5 @@ var getRandomColor = () => {
106
94
  formatDate,
107
95
  getRandomColor,
108
96
  hexToRgb,
109
- isLight,
110
97
  uuidV4
111
98
  });
package/dist/helper.d.cts CHANGED
@@ -10,14 +10,7 @@ declare function hexToRgb(hex: string): {
10
10
  g: number;
11
11
  b: number;
12
12
  } | 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;
20
13
  declare const evalCode: (code: string) => any;
21
14
  declare const getRandomColor: () => string;
22
15
 
23
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 };
16
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, uuidV4 };
package/dist/helper.d.ts CHANGED
@@ -10,14 +10,7 @@ declare function hexToRgb(hex: string): {
10
10
  g: number;
11
11
  b: number;
12
12
  } | 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;
20
13
  declare const evalCode: (code: string) => any;
21
14
  declare const getRandomColor: () => string;
22
15
 
23
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 };
16
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, uuidV4 };
package/dist/helper.js CHANGED
@@ -6,9 +6,8 @@ import {
6
6
  formatDate,
7
7
  getRandomColor,
8
8
  hexToRgb,
9
- isLight,
10
9
  uuidV4
11
- } from "./chunk-7X2CUDBX.js";
10
+ } from "./chunk-73OREOHT.js";
12
11
  import "./chunk-XEO3YXBM.js";
13
12
  export {
14
13
  absoluteUrl,
@@ -18,6 +17,5 @@ export {
18
17
  formatDate,
19
18
  getRandomColor,
20
19
  hexToRgb,
21
- isLight,
22
20
  uuidV4
23
21
  };
package/dist/index.cjs CHANGED
@@ -96,7 +96,7 @@ __export(src_exports, {
96
96
  hasMissingRequiredData: () => hasMissingRequiredData,
97
97
  hexToHSLString: () => hexToHSLString,
98
98
  hexToRGBStr: () => hexToRGBStr,
99
- hexToRgb: () => hexToRgb,
99
+ hexToRgb: () => hexToRgb2,
100
100
  isArray: () => isArray,
101
101
  isBoolean: () => isBoolean,
102
102
  isClickableElement: () => isClickableElement,
@@ -109,7 +109,6 @@ __export(src_exports, {
109
109
  isFile: () => isFile,
110
110
  isFormData: () => isFormData,
111
111
  isFunction: () => isFunction,
112
- isLight: () => isLight,
113
112
  isMatchUrlPattern: () => isMatchUrlPattern,
114
113
  isMissingRequiredData: () => isMissingRequiredData,
115
114
  isNull: () => isNull,
@@ -176,33 +175,107 @@ var hexToRGBStr = (hex) => {
176
175
  return "0, 0, 0";
177
176
  }
178
177
  };
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;
189
- const isBaseBrand = import_chroma_js.default.distance(baseColor, brandColor) < 10;
190
- let hover;
191
- let active;
192
- if (isBaseBrand) {
193
- hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
194
- active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
195
- } else if (isBaseLight) {
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();
201
- } else {
202
- hover = import_chroma_js.default.mix(baseColor, "#ffffff", brandHoverRatio, "rgb").hex();
203
- active = import_chroma_js.default.mix(baseColor, "#000000", brandActiveRatio, "rgb").hex();
178
+ function hexToRgb(hex) {
179
+ if (!hex)
180
+ return [0, 0, 0];
181
+ if (hex.match(/^#[0-9a-f]{6}$/i)) {
182
+ return [
183
+ Number.parseInt(hex.substring(1, 3), 16),
184
+ Number.parseInt(hex.substring(3, 5), 16),
185
+ Number.parseInt(hex.substring(5, 7), 16)
186
+ ];
187
+ }
188
+ if (hex.match(/^#[0-9a-f]{3}$/i)) {
189
+ return [
190
+ Number.parseInt(hex.substring(1, 2).repeat(2), 16),
191
+ Number.parseInt(hex.substring(2, 3).repeat(2), 16),
192
+ Number.parseInt(hex.substring(3, 4).repeat(2), 16)
193
+ ];
194
+ }
195
+ return [0, 0, 0];
196
+ }
197
+ function rgbToHex([r, g, b]) {
198
+ const rHex = r.toString(16).padStart(2, "0");
199
+ const gHex = g.toString(16).padStart(2, "0");
200
+ const bHex = b.toString(16).padStart(2, "0");
201
+ return `#${rHex}${gHex}${bHex}`;
202
+ }
203
+ function rgbToHsl([r, g, b]) {
204
+ const rNorm = r / 255;
205
+ const gNorm = g / 255;
206
+ const bNorm = b / 255;
207
+ const max = Math.max(rNorm, gNorm, bNorm);
208
+ const min = Math.min(rNorm, gNorm, bNorm);
209
+ const l = (max + min) / 2;
210
+ let h = 0;
211
+ let s = 0;
212
+ if (max !== min) {
213
+ const d = max - min;
214
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
215
+ switch (max) {
216
+ case rNorm:
217
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
218
+ break;
219
+ case gNorm:
220
+ h = (bNorm - rNorm) / d + 2;
221
+ break;
222
+ default:
223
+ h = (rNorm - gNorm) / d + 4;
224
+ break;
225
+ }
226
+ h /= 6;
227
+ }
228
+ return [h, s, l];
229
+ }
230
+ function getLabLuminance([r, g, b]) {
231
+ function linearize(channel) {
232
+ const c = channel / 255;
233
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
204
234
  }
205
- return { hover, active };
235
+ const y = 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
236
+ function yToLabL(yVal) {
237
+ return yVal <= 216 / 24389 ? yVal * (24389 / 27) : yVal ** (1 / 3) * 116 - 16;
238
+ }
239
+ return Math.round(yToLabL(y) * 10) / 1e3;
240
+ }
241
+ function invertColor([r, g, b]) {
242
+ return [Math.round(255 - r), Math.round(255 - g), Math.round(255 - b)];
243
+ }
244
+ function mixRgb(color1, color2, ratio) {
245
+ return [
246
+ Math.max(0, Math.min(255, Math.round(color1[0] + (color2[0] - color1[0]) * ratio))),
247
+ Math.max(0, Math.min(255, Math.round(color1[1] + (color2[1] - color1[1]) * ratio))),
248
+ Math.max(0, Math.min(255, Math.round(color1[2] + (color2[2] - color1[2]) * ratio)))
249
+ ];
250
+ }
251
+ function calculateMixRatio(foreground, background) {
252
+ const fgLuminance = getLabLuminance(foreground);
253
+ const bgLuminance = getLabLuminance(background);
254
+ const minRatio = 0.05;
255
+ const baseRatio = (1 - (bgLuminance - fgLuminance)) / 2 * (0.18 - minRatio) + minRatio;
256
+ const luminanceSimilarity = 1 - Math.abs(bgLuminance - fgLuminance);
257
+ const adjustment = ((1 - baseRatio) * luminanceSimilarity) ** 4;
258
+ const finalRatio = baseRatio + adjustment;
259
+ return Math.round(finalRatio * 1e3) / 1e3;
260
+ }
261
+ function generateStateColors(backgroundColor, foregroundColor) {
262
+ const bgRgb = hexToRgb(backgroundColor);
263
+ const fgRgb = hexToRgb(foregroundColor);
264
+ const bgHsl = rgbToHsl(bgRgb);
265
+ const hoverRatio = calculateMixRatio(fgRgb, bgRgb);
266
+ let activeRatio = hoverRatio * 2;
267
+ let activeMixColor = fgRgb;
268
+ const midToneThreshold = 0.2;
269
+ if (bgHsl[2] > midToneThreshold && bgHsl[2] < 1 - midToneThreshold) {
270
+ activeMixColor = invertColor(fgRgb);
271
+ activeRatio = calculateMixRatio(activeMixColor, bgRgb);
272
+ }
273
+ const hoverRgb = mixRgb(bgRgb, fgRgb, hoverRatio);
274
+ const activeRgb = mixRgb(bgRgb, activeMixColor, activeRatio);
275
+ return {
276
+ hover: rgbToHex(hoverRgb),
277
+ active: rgbToHex(activeRgb)
278
+ };
206
279
  }
207
280
 
208
281
  // src/convert-settings.ts
@@ -261,7 +334,7 @@ var isFile = (x) => {
261
334
  };
262
335
 
263
336
  // src/convert-settings.ts
264
- var defaultFontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
337
+ var defaultFontFamily = '-apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
265
338
  var mergeThemeDefaultSettings = (settings) => {
266
339
  return (0, import_deepmerge_ts.deepmerge)(import_types.defaultSettings, settings);
267
340
  };
@@ -1232,7 +1305,7 @@ function absoluteUrl(path) {
1232
1305
  var uuidV4 = () => {
1233
1306
  return (0, import_uuid.v4)();
1234
1307
  };
1235
- function hexToRgb(hex) {
1308
+ function hexToRgb2(hex) {
1236
1309
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1237
1310
  return result ? {
1238
1311
  r: Number.parseInt(result[1], 16),
@@ -1240,17 +1313,6 @@ function hexToRgb(hex) {
1240
1313
  b: Number.parseInt(result[3], 16)
1241
1314
  } : null;
1242
1315
  }
1243
- var isLight = (hex) => {
1244
- const rgb = hexToRgb(hex);
1245
- if (!rgb) {
1246
- return null;
1247
- }
1248
- const { r, g, b } = rgb;
1249
- if (r * 0.299 + g * 0.587 + b * 0.114 > 250) {
1250
- return true;
1251
- }
1252
- return false;
1253
- };
1254
1316
  var evalCode = (code) => {
1255
1317
  try {
1256
1318
  return eval(code);
@@ -1997,7 +2059,6 @@ var duplicateStep = (step) => {
1997
2059
  isFile,
1998
2060
  isFormData,
1999
2061
  isFunction,
2000
- isLight,
2001
2062
  isMatchUrlPattern,
2002
2063
  isMissingRequiredData,
2003
2064
  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 { StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
11
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 } from './helper.cjs';
10
+ export { generateStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
11
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, 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 { StateColorOptions, generateStateColors, hexToHSLString, hexToRGBStr } from './color.js';
11
- export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isLight, uuidV4 } from './helper.js';
10
+ export { generateStateColors, hexToHSLString, hexToRGBStr } from './color.js';
11
+ export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, 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-KARDMYE2.js";
41
+ } from "./chunk-RQ4UE7ZB.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-5BEUHZSY.js";
53
+ } from "./chunk-X6R6AH7G.js";
54
54
  import {
55
55
  evaluateUrlCondition,
56
56
  isMatchUrlPattern
@@ -64,9 +64,8 @@ import {
64
64
  formatDate,
65
65
  getRandomColor,
66
66
  hexToRgb,
67
- isLight,
68
67
  uuidV4
69
- } from "./chunk-7X2CUDBX.js";
68
+ } from "./chunk-73OREOHT.js";
70
69
  import {
71
70
  evaluateAttributeCondition
72
71
  } from "./chunk-KYDXF7SU.js";
@@ -82,12 +81,12 @@ import {
82
81
  convertSettings,
83
82
  convertToCssVars,
84
83
  mergeThemeDefaultSettings
85
- } from "./chunk-UMC3BUA7.js";
84
+ } from "./chunk-IS56PYND.js";
86
85
  import {
87
86
  generateStateColors,
88
87
  hexToHSLString,
89
88
  hexToRGBStr
90
- } from "./chunk-BKX55CAI.js";
89
+ } from "./chunk-FZFHBCB6.js";
91
90
  import {
92
91
  getCodeError,
93
92
  getContentError,
@@ -221,7 +220,6 @@ export {
221
220
  isFile,
222
221
  isFormData,
223
222
  isFunction,
224
- isLight,
225
223
  isMatchUrlPattern,
226
224
  isMissingRequiredData,
227
225
  isNull,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",
@@ -1,59 +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 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
- };