1
+ /**
2
+ * Converts a hex color string to RGB values.
3
+ *
4
+ * @param hex - Hex color string (e.g., "#FF5733")
5
+ * @returns Object with r, g, b numeric values
6
+ */
1
7
function hexToRGB ( hex : string ) {
2
8
const r = parseInt ( hex . slice ( 1 , 3 ) , 16 ) ;
3
9
const g = parseInt ( hex . slice ( 3 , 5 ) , 16 ) ;
4
10
const b = parseInt ( hex . slice ( 5 , 7 ) , 16 ) ;
5
11
return { r, g, b } ;
6
12
}
7
13
14
+ /**
15
+ * Converts RGB values to a hex color string.
16
+ *
17
+ * @param r - Red value (0-255)
18
+ * @param g - Green value (0-255)
19
+ * @param b - Blue value (0-255)
20
+ * @returns Hex color string (e.g., "#FF5733")
21
+ */
8
22
function rgbToHex ( r : number , g : number , b : number ) {
9
23
return '#' + ( ( 1 << 24 ) + ( r << 16 ) + ( g << 8 ) + b ) . toString ( 16 ) . slice ( 1 ) ;
10
24
}
11
25
26
+ /**
27
+ * Blends two hex colors by a specified step amount.
28
+ *
29
+ * @param colorA - First hex color
30
+ * @param colorB - Second hex color
31
+ * @param step - Blend ratio (0 = colorA, 1 = colorB)
32
+ * @returns Blended hex color
33
+ */
12
34
function mixColors ( colorA : string , colorB : string , step : number ) {
13
35
const colorARGB = hexToRGB ( colorA ) ;
14
36
const colorBRGB = hexToRGB ( colorB ) ;
@@ -23,6 +45,15 @@ function mixColors(colorA: string, colorB: string, step: number) {
23
45
const NEURAL_WHITE = '#FFFFFF' ;
24
46
const NEURAL_BLACK = '#0F161F' ;
25
47
48
+ /**
49
+ * Generates a complete shade palette from a base color.
50
+ *
51
+ * Creates lighter (W10-W100) and darker (B10-B100) variations by mixing
52
+ * the base color with neural white and black at different ratios.
53
+ *
54
+ * @param color - Base hex color to generate shades from
55
+ * @returns Object mapping shade keys to hex color values
56
+ */
26
57
export const generateShades = ( color : string ) => {
27
58
const shades : { [ key : string ] : string } = { '0' : color } ;
28
59
for ( let i = 1 ; i <= 9 ; i ++ ) {
0 commit comments