@evolve.ui/theme-system 1.0.0 → 1.1.0

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.
@@ -0,0 +1,82 @@
1
+ import tinycolor from 'tinycolor2';
2
+
3
+ // https://github.com/bgrins/TinyColor
4
+
5
+ export const lighten = (percentAsInt: number, unprocessedColor: string): tinycolor.Instance => {
6
+ const color = tinycolor(unprocessedColor);
7
+ const amount = (percentAsInt * ((1 - color.toHsl().l) * 100)) / 100;
8
+ return color.lighten(amount);
9
+ };
10
+
11
+ export const darken = (percentAsInt: number, unprocessedColor: string): tinycolor.Instance => {
12
+ const color = tinycolor(unprocessedColor);
13
+ const amount = (percentAsInt * (color.toHsl().l * 100)) / 100;
14
+ return color.darken(amount);
15
+ };
16
+
17
+ // https://tailwindcss.com/docs/customizing-colors#using-custom-colors
18
+ const removeRGB = (color: string) => color.replace(/rgb\(|,|\)/g, '');
19
+
20
+ /**
21
+ * Generate a set of color steps from a base color. Base color becomes 500.
22
+ *
23
+ * @param color The color to generate the steps from
24
+ * @returns An array of 50, 100, 200, 300, 400, 500, 600, 700, 800, 900 color values.
25
+ */
26
+ export const generateNormalColorSteps = (color: string) => {
27
+ return [
28
+ removeRGB(lighten(95, color).toRgbString()),
29
+ removeRGB(lighten(85, color).toRgbString()),
30
+ removeRGB(lighten(70, color).toRgbString()),
31
+ removeRGB(lighten(40, color).toRgbString()),
32
+ removeRGB(lighten(20, color).toRgbString()),
33
+ removeRGB(tinycolor(color).toRgbString()),
34
+ removeRGB(darken(20, color).toRgbString()),
35
+ removeRGB(darken(40, color).toRgbString()),
36
+ removeRGB(darken(50, color).toRgbString()),
37
+ removeRGB(darken(70, color).toRgbString()),
38
+ ];
39
+ };
40
+
41
+ /**
42
+ * Generate a set of color steps from a base color. Base color becomes 500.
43
+ *
44
+ * @param color The color to generate the steps from
45
+ * @param isNeutral Whether the color is a neutral color to make surface-50 true white
46
+ * @returns An array of 50, 100, 200, 300, 400, 500, 600, 700, 800, 900 color values.
47
+ */
48
+ export const generateSurfaceColorSteps = (color: string, isNeutral: boolean = false) => {
49
+ return [
50
+ removeRGB(lighten(isNeutral ? 100 : 99, color).toRgbString()),
51
+ removeRGB(lighten(95, color).toRgbString()),
52
+ removeRGB(lighten(80, color).toRgbString()),
53
+ removeRGB(lighten(50, color).toRgbString()),
54
+ removeRGB(lighten(30, color).toRgbString()),
55
+ removeRGB(tinycolor(color).toRgbString()),
56
+ removeRGB(darken(20, color).toRgbString()),
57
+ removeRGB(darken(40, color).toRgbString()),
58
+ removeRGB(darken(50, color).toRgbString()),
59
+ removeRGB(darken(70, color).toRgbString()),
60
+ ];
61
+ };
62
+
63
+ export type Steps = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
64
+ export const steps: Steps[] = ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
65
+ export type StepObject = Record<Steps, string>;
66
+
67
+ export const colorStepArrayToObject = (colorStepArray: string[]): StepObject => {
68
+ return {
69
+ '100': colorStepArray[1],
70
+ '200': colorStepArray[2],
71
+ '300': colorStepArray[3],
72
+ '400': colorStepArray[4],
73
+ '50': colorStepArray[0],
74
+ '500': colorStepArray[5],
75
+ '600': colorStepArray[6],
76
+ '700': colorStepArray[7],
77
+ '800': colorStepArray[8],
78
+ '900': colorStepArray[9],
79
+ };
80
+ };
81
+
82
+ export { tinycolor };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * CSS variable wrapping utilities for Tailwind CSS configuration
3
+ *
4
+ * These utilities handle the conversion of CSS custom property names
5
+ * into proper var() references, with optional opacity support for
6
+ * Tailwind's alpha modifier syntax (e.g., `bg-primary-500/50`).
7
+ *
8
+ * @see https://tailwindcss.com/docs/customizing-colors#using-css-variables
9
+ * Internal reference: Hammer UI patterns
10
+ * Ported from the upstream theme system.
11
+ */
12
+
13
+ /** Wraps a CSS variable name in var() */
14
+ export const wrapVar = (value: string): string => `var(${value})`;
15
+
16
+ /** Wraps a CSS variable name in rgb(var()) */
17
+ export const wrapVarRgb = (value: string): string => `rgb(var(${value}))`;
18
+
19
+ /** Wraps a variable reference with a fixed percentage opacity */
20
+ export const wrapOpacity = (wrappedVariable: string, percentOpacity: number): string =>
21
+ `rgb(${wrappedVariable} / ${percentOpacity}%)`;
22
+
23
+ /** Wraps a variable reference with Tailwind's alpha-value placeholder for dynamic opacity */
24
+ export const wrapVariableOpacity = (wrappedVariable: string): string => `rgb(${wrappedVariable} / <alpha-value>)`;