phaser-wind 0.2.0 → 0.4.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.
- package/README.md +243 -215
- package/dist/components/column.d.ts +1 -0
- package/dist/components/column.d.ts.map +1 -0
- package/dist/components/column.js +7 -0
- package/dist/components/column.js.map +1 -0
- package/dist/core/color.d.ts +154 -0
- package/dist/core/color.d.ts.map +1 -0
- package/dist/core/color.js +205 -0
- package/dist/core/color.js.map +1 -0
- package/dist/core/color.spec.d.ts +2 -0
- package/dist/core/color.spec.d.ts.map +1 -0
- package/dist/core/color.spec.js +243 -0
- package/dist/core/color.spec.js.map +1 -0
- package/dist/core/font-size.d.ts +55 -0
- package/dist/core/font-size.d.ts.map +1 -0
- package/dist/core/font-size.js +63 -0
- package/dist/core/font-size.js.map +1 -0
- package/dist/core/font-size.spec.d.ts +2 -0
- package/dist/core/font-size.spec.d.ts.map +1 -0
- package/dist/core/font-size.spec.js +85 -0
- package/dist/core/font-size.spec.js.map +1 -0
- package/dist/core/font.d.ts +21 -0
- package/dist/core/font.d.ts.map +1 -0
- package/dist/core/font.js +37 -0
- package/dist/core/font.js.map +1 -0
- package/dist/core/font.spec.d.ts +2 -0
- package/dist/core/font.spec.d.ts.map +1 -0
- package/dist/core/font.spec.js +80 -0
- package/dist/core/font.spec.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/{color/pallete.d.ts → core/palette.d.ts} +2 -2
- package/dist/core/palette.d.ts.map +1 -0
- package/dist/{color/pallete.js → core/palette.js} +2 -2
- package/dist/core/palette.js.map +1 -0
- package/dist/core/radius.d.ts +29 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +38 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/radius.spec.d.ts +2 -0
- package/dist/core/radius.spec.d.ts.map +1 -0
- package/dist/core/radius.spec.js +56 -0
- package/dist/core/radius.spec.js.map +1 -0
- package/dist/core/shadow.d.ts +31 -0
- package/dist/core/shadow.d.ts.map +1 -0
- package/dist/core/shadow.js +33 -0
- package/dist/core/shadow.js.map +1 -0
- package/dist/core/shadow.spec.d.ts +2 -0
- package/dist/core/shadow.spec.d.ts.map +1 -0
- package/dist/core/shadow.spec.js +21 -0
- package/dist/core/shadow.spec.js.map +1 -0
- package/dist/core/spacing.d.ts +32 -0
- package/dist/core/spacing.d.ts.map +1 -0
- package/dist/core/spacing.js +70 -0
- package/dist/core/spacing.js.map +1 -0
- package/dist/core/spacing.spec.d.ts +2 -0
- package/dist/core/spacing.spec.d.ts.map +1 -0
- package/dist/core/spacing.spec.js +38 -0
- package/dist/core/spacing.spec.js.map +1 -0
- package/dist/exceptions.d.ts +1 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +2 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/font/index.d.ts +2 -2
- package/dist/font/index.d.ts.map +1 -1
- package/dist/font/index.js +2 -2
- package/dist/font/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +2 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/plugin.d.ts +71 -0
- package/dist/plugin/plugin.d.ts.map +1 -0
- package/dist/plugin/plugin.js +91 -0
- package/dist/plugin/plugin.js.map +1 -0
- package/dist/theme/theme-config.d.ts +44 -132
- package/dist/theme/theme-config.d.ts.map +1 -1
- package/dist/theme/theme-config.js +15 -52
- package/dist/theme/theme-config.js.map +1 -1
- package/dist/theme/theme-manager.d.ts +2 -95
- package/dist/theme/theme-manager.d.ts.map +1 -1
- package/dist/theme/theme-manager.js +3 -170
- package/dist/theme/theme-manager.js.map +1 -1
- package/dist/theme/type.d.ts +48 -0
- package/dist/theme/type.d.ts.map +1 -1
- package/dist/theme/type.js +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/is-valid-color.d.ts +13 -0
- package/dist/utils/is-valid-color.d.ts.map +1 -0
- package/dist/utils/is-valid-color.js +32 -0
- package/dist/utils/is-valid-color.js.map +1 -0
- package/dist/utils/is-valid-color.spec.d.ts +2 -0
- package/dist/utils/is-valid-color.spec.d.ts.map +1 -0
- package/dist/utils/is-valid-color.spec.js +82 -0
- package/dist/utils/is-valid-color.spec.js.map +1 -0
- package/package.json +6 -4
- package/dist/color/color-picker.d.ts +0 -23
- package/dist/color/color-picker.d.ts.map +0 -1
- package/dist/color/color-picker.js +0 -118
- package/dist/color/color-picker.js.map +0 -1
- package/dist/color/color-picker.spec.d.ts +0 -2
- package/dist/color/color-picker.spec.d.ts.map +0 -1
- package/dist/color/color-picker.spec.js +0 -60
- package/dist/color/color-picker.spec.js.map +0 -1
- package/dist/color/index.d.ts +0 -3
- package/dist/color/index.d.ts.map +0 -1
- package/dist/color/index.js +0 -3
- package/dist/color/index.js.map +0 -1
- package/dist/color/pallete.d.ts.map +0 -1
- package/dist/color/pallete.js.map +0 -1
- package/dist/examples/nested-theme-example.d.ts +0 -28
- package/dist/examples/nested-theme-example.d.ts.map +0 -1
- package/dist/examples/nested-theme-example.js +0 -313
- package/dist/examples/nested-theme-example.js.map +0 -1
- package/dist/examples/usage-example.d.ts +0 -17
- package/dist/examples/usage-example.d.ts.map +0 -1
- package/dist/examples/usage-example.js +0 -158
- package/dist/examples/usage-example.js.map +0 -1
- package/dist/font/font-picker.d.ts +0 -93
- package/dist/font/font-picker.d.ts.map +0 -1
- package/dist/font/font-picker.js +0 -212
- package/dist/font/font-picker.js.map +0 -1
- package/dist/font/font-size-picker.d.ts +0 -19
- package/dist/font/font-size-picker.d.ts.map +0 -1
- package/dist/font/font-size-picker.js +0 -24
- package/dist/font/font-size-picker.js.map +0 -1
- package/dist/font/font-size-picker.spec.d.ts +0 -2
- package/dist/font/font-size-picker.spec.d.ts.map +0 -1
- package/dist/font/font-size-picker.spec.js +0 -48
- package/dist/font/font-size-picker.spec.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=column.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/components/column.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// export class Column extends Phaser.GameObjects.Container {
|
|
3
|
+
// constructor(scene: Scene, x: number, y: number, width: number, height: number, children: GameObjects.Container[]) {
|
|
4
|
+
// super(scene, x, y, width, height);
|
|
5
|
+
// }
|
|
6
|
+
// }
|
|
7
|
+
//# sourceMappingURL=column.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column.js","sourceRoot":"","sources":["../../src/components/column.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,wHAAwH;AACxH,yCAAyC;AACzC,MAAM;AACN,IAAI"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { BaseThemeConfig } from '../theme';
|
|
2
|
+
import { palette } from './palette';
|
|
3
|
+
/**
|
|
4
|
+
* Available color families from the built-in palette.
|
|
5
|
+
* Matches Tailwind CSS color families.
|
|
6
|
+
*/
|
|
7
|
+
export type ColorKey = keyof typeof palette;
|
|
8
|
+
/**
|
|
9
|
+
* Available shade values for the color palette.
|
|
10
|
+
* Accepts string or numeric literal shades for convenience.
|
|
11
|
+
*/
|
|
12
|
+
export type ShadeKey = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | '950' | 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
13
|
+
/**
|
|
14
|
+
* Color token combining a color family and a shade.
|
|
15
|
+
* Also accepts special tokens `black` and `white`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* Color.rgb('blue-500') // => 'rgb(59, 130, 246)'
|
|
19
|
+
* Color.hex('black') // => 0x000000
|
|
20
|
+
*/
|
|
21
|
+
export type ColorToken = `${ColorKey}-${ShadeKey}` | 'black' | 'white';
|
|
22
|
+
/**
|
|
23
|
+
* Color utility API interface
|
|
24
|
+
* Provides methods to work with colors in different formats
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* API for resolving colors to RGB strings or Hex numbers.
|
|
28
|
+
* When parameterized with a theme type `T`, accepts either palette tokens or `keyof T`.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam T - Theme colors map (e.g. `{ primary: 'blue-500' }`)
|
|
31
|
+
* @example
|
|
32
|
+
* const c = createColor();
|
|
33
|
+
* c.rgb('red-500');
|
|
34
|
+
* c.hex('white');
|
|
35
|
+
*/
|
|
36
|
+
export type Color<T = BaseThemeConfig['colors']> = {
|
|
37
|
+
/** Get RGB string representation of a color */
|
|
38
|
+
rgb(color: ColorToken | keyof T): string;
|
|
39
|
+
/** Get hex number representation of a color */
|
|
40
|
+
hex(color: ColorToken | keyof T): number;
|
|
41
|
+
/** Get RGB string for slate color with specified shade */
|
|
42
|
+
slate(shade: ShadeKey): string;
|
|
43
|
+
/** Get RGB string for gray color with specified shade */
|
|
44
|
+
gray(shade: ShadeKey): string;
|
|
45
|
+
/** Get RGB string for zinc color with specified shade */
|
|
46
|
+
zinc(shade: ShadeKey): string;
|
|
47
|
+
/** Get RGB string for neutral color with specified shade */
|
|
48
|
+
neutral(shade: ShadeKey): string;
|
|
49
|
+
/** Get RGB string for stone color with specified shade */
|
|
50
|
+
stone(shade: ShadeKey): string;
|
|
51
|
+
/** Get RGB string for red color with specified shade */
|
|
52
|
+
red(shade: ShadeKey): string;
|
|
53
|
+
/** Get RGB string for orange color with specified shade */
|
|
54
|
+
orange(shade: ShadeKey): string;
|
|
55
|
+
/** Get RGB string for amber color with specified shade */
|
|
56
|
+
amber(shade: ShadeKey): string;
|
|
57
|
+
/** Get RGB string for yellow color with specified shade */
|
|
58
|
+
yellow(shade: ShadeKey): string;
|
|
59
|
+
/** Get RGB string for lime color with specified shade */
|
|
60
|
+
lime(shade: ShadeKey): string;
|
|
61
|
+
/** Get RGB string for green color with specified shade */
|
|
62
|
+
green(shade: ShadeKey): string;
|
|
63
|
+
/** Get RGB string for emerald color with specified shade */
|
|
64
|
+
emerald(shade: ShadeKey): string;
|
|
65
|
+
/** Get RGB string for teal color with specified shade */
|
|
66
|
+
teal(shade: ShadeKey): string;
|
|
67
|
+
/** Get RGB string for cyan color with specified shade */
|
|
68
|
+
cyan(shade: ShadeKey): string;
|
|
69
|
+
/** Get RGB string for sky color with specified shade */
|
|
70
|
+
sky(shade: ShadeKey): string;
|
|
71
|
+
/** Get RGB string for blue color with specified shade */
|
|
72
|
+
blue(shade: ShadeKey): string;
|
|
73
|
+
/** Get RGB string for indigo color with specified shade */
|
|
74
|
+
indigo(shade: ShadeKey): string;
|
|
75
|
+
/** Get RGB string for violet color with specified shade */
|
|
76
|
+
violet(shade: ShadeKey): string;
|
|
77
|
+
/** Get RGB string for purple color with specified shade */
|
|
78
|
+
purple(shade: ShadeKey): string;
|
|
79
|
+
/** Get RGB string for fuchsia color with specified shade */
|
|
80
|
+
fuchsia(shade: ShadeKey): string;
|
|
81
|
+
/** Get RGB string for pink color with specified shade */
|
|
82
|
+
pink(shade: ShadeKey): string;
|
|
83
|
+
/** Get RGB string for rose color with specified shade */
|
|
84
|
+
rose(shade: ShadeKey): string;
|
|
85
|
+
/** Get hex number for slate color with specified shade */
|
|
86
|
+
slateHex(shade: ShadeKey): number;
|
|
87
|
+
/** Get hex number for gray color with specified shade */
|
|
88
|
+
grayHex(shade: ShadeKey): number;
|
|
89
|
+
/** Get hex number for zinc color with specified shade */
|
|
90
|
+
zincHex(shade: ShadeKey): number;
|
|
91
|
+
/** Get hex number for neutral color with specified shade */
|
|
92
|
+
neutralHex(shade: ShadeKey): number;
|
|
93
|
+
/** Get hex number for stone color with specified shade */
|
|
94
|
+
stoneHex(shade: ShadeKey): number;
|
|
95
|
+
/** Get hex number for red color with specified shade */
|
|
96
|
+
redHex(shade: ShadeKey): number;
|
|
97
|
+
/** Get hex number for orange color with specified shade */
|
|
98
|
+
orangeHex(shade: ShadeKey): number;
|
|
99
|
+
/** Get hex number for amber color with specified shade */
|
|
100
|
+
amberHex(shade: ShadeKey): number;
|
|
101
|
+
/** Get hex number for yellow color with specified shade */
|
|
102
|
+
yellowHex(shade: ShadeKey): number;
|
|
103
|
+
/** Get hex number for lime color with specified shade */
|
|
104
|
+
limeHex(shade: ShadeKey): number;
|
|
105
|
+
/** Get hex number for green color with specified shade */
|
|
106
|
+
greenHex(shade: ShadeKey): number;
|
|
107
|
+
/** Get hex number for emerald color with specified shade */
|
|
108
|
+
emeraldHex(shade: ShadeKey): number;
|
|
109
|
+
/** Get hex number for teal color with specified shade */
|
|
110
|
+
tealHex(shade: ShadeKey): number;
|
|
111
|
+
/** Get hex number for cyan color with specified shade */
|
|
112
|
+
cyanHex(shade: ShadeKey): number;
|
|
113
|
+
/** Get hex number for sky color with specified shade */
|
|
114
|
+
skyHex(shade: ShadeKey): number;
|
|
115
|
+
/** Get hex number for blue color with specified shade */
|
|
116
|
+
blueHex(shade: ShadeKey): number;
|
|
117
|
+
/** Get hex number for indigo color with specified shade */
|
|
118
|
+
indigoHex(shade: ShadeKey): number;
|
|
119
|
+
/** Get hex number for violet color with specified shade */
|
|
120
|
+
violetHex(shade: ShadeKey): number;
|
|
121
|
+
/** Get hex number for purple color with specified shade */
|
|
122
|
+
purpleHex(shade: ShadeKey): number;
|
|
123
|
+
/** Get hex number for fuchsia color with specified shade */
|
|
124
|
+
fuchsiaHex(shade: ShadeKey): number;
|
|
125
|
+
/** Get hex number for pink color with specified shade */
|
|
126
|
+
pinkHex(shade: ShadeKey): number;
|
|
127
|
+
/** Get hex number for rose color with specified shade */
|
|
128
|
+
roseHex(shade: ShadeKey): number;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Factory that creates a color utility API based on the provided theme colors
|
|
132
|
+
* @param themeColors - Theme colors configuration
|
|
133
|
+
* @returns Color utility API instance
|
|
134
|
+
*/
|
|
135
|
+
/**
|
|
136
|
+
* Create a color API bound to an optional theme colors map.
|
|
137
|
+
* If a key exists in `themeColors`, it will be resolved to a palette token and then to RGB/Hex.
|
|
138
|
+
*
|
|
139
|
+
* @typeParam T - Theme colors map
|
|
140
|
+
* @param themeColors - Optional map of theme color tokens
|
|
141
|
+
* @example
|
|
142
|
+
* const c = createColor({ primary: 'blue-500' });
|
|
143
|
+
* c.rgb('primary'); // rgb(59, 130, 246)
|
|
144
|
+
*/
|
|
145
|
+
export declare const createColor: <T = BaseThemeConfig["colors"]>(themeColors: T) => Color<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Convenience instance using only the default palette tokens (no theme).
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* Color.rgb('emerald-400')
|
|
151
|
+
* Color.hex('black')
|
|
152
|
+
*/
|
|
153
|
+
export declare const Color: Color<Record<string, never>>;
|
|
154
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/core/color.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAChB,IAAI,GACJ,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,EAAE,GACF,GAAG,GACH,GAAG,GACH,GAAG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C,QAAQ,CAAC,EACvD,aAAa,CAAC,KACb,KAAK,CAAC,CAAC,CAiJT,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAEjB,CAAC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { isValidColor } from '../utils';
|
|
2
|
+
import { palette } from './palette';
|
|
3
|
+
/** Regular expression to match RGB color format */
|
|
4
|
+
const RGB_REGEX = /rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
|
|
5
|
+
/**
|
|
6
|
+
* Convert hex color value to number
|
|
7
|
+
* @param hexValue - Hex color value (e.g., '#ff0000')
|
|
8
|
+
* @returns Number representation of hex color
|
|
9
|
+
*/
|
|
10
|
+
const convertHexToNumber = (hexValue) => {
|
|
11
|
+
const hex = hexValue.slice(1);
|
|
12
|
+
if (hex.length === 3) {
|
|
13
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
14
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
15
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
16
|
+
return (r << 16) + (g << 8) + b;
|
|
17
|
+
}
|
|
18
|
+
return parseInt(hex, 16);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convert RGB color value to number
|
|
22
|
+
* @param rgbValue - RGB color value (e.g., 'rgb(255, 0, 0)')
|
|
23
|
+
* @returns Number representation of RGB color
|
|
24
|
+
* @throws {Error} If RGB format is invalid
|
|
25
|
+
*/
|
|
26
|
+
const convertRgbToNumber = (rgbValue) => {
|
|
27
|
+
const matches = rgbValue.match(RGB_REGEX);
|
|
28
|
+
if (!matches) {
|
|
29
|
+
throw new Error(`Invalid RGB format: ${rgbValue}`);
|
|
30
|
+
}
|
|
31
|
+
const r = parseInt(matches[1]);
|
|
32
|
+
const g = parseInt(matches[2]);
|
|
33
|
+
const b = parseInt(matches[3]);
|
|
34
|
+
return (r << 16) + (g << 8) + b;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Convert color value to number
|
|
38
|
+
* @param colorValue - Color value (e.g., '#ff0000' or 'rgb(255, 0, 0)')
|
|
39
|
+
* @returns Number representation of color
|
|
40
|
+
*/
|
|
41
|
+
const convertColorValueToNumber = (colorValue) => {
|
|
42
|
+
if (colorValue.startsWith('#')) {
|
|
43
|
+
return convertHexToNumber(colorValue);
|
|
44
|
+
}
|
|
45
|
+
return convertRgbToNumber(colorValue);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Factory that creates a color utility API based on the provided theme colors
|
|
49
|
+
* @param themeColors - Theme colors configuration
|
|
50
|
+
* @returns Color utility API instance
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Create a color API bound to an optional theme colors map.
|
|
54
|
+
* If a key exists in `themeColors`, it will be resolved to a palette token and then to RGB/Hex.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam T - Theme colors map
|
|
57
|
+
* @param themeColors - Optional map of theme color tokens
|
|
58
|
+
* @example
|
|
59
|
+
* const c = createColor({ primary: 'blue-500' });
|
|
60
|
+
* c.rgb('primary'); // rgb(59, 130, 246)
|
|
61
|
+
*/
|
|
62
|
+
export const createColor = (themeColors) => {
|
|
63
|
+
/**
|
|
64
|
+
* Get color value from theme configuration
|
|
65
|
+
* @param key - Color token or theme color key
|
|
66
|
+
* @returns Color value from theme or null if not found
|
|
67
|
+
*/
|
|
68
|
+
const getValueFromTheme = (key) => {
|
|
69
|
+
if (themeColors && key in themeColors) {
|
|
70
|
+
return themeColors[key];
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Get RGB string representation of a color
|
|
76
|
+
* @param color - Color token, theme color key or valid color string
|
|
77
|
+
* @returns RGB color string
|
|
78
|
+
* @throws {Error} If color token is not found
|
|
79
|
+
*/
|
|
80
|
+
const rgb = (color) => {
|
|
81
|
+
// Runtime supports direct CSS strings for flexibility, but
|
|
82
|
+
// the public type restricts to palette tokens or theme keys.
|
|
83
|
+
if (typeof color === 'string' && isValidColor(color)) {
|
|
84
|
+
return color;
|
|
85
|
+
}
|
|
86
|
+
const colorFromTheme = getValueFromTheme(color);
|
|
87
|
+
if (colorFromTheme) {
|
|
88
|
+
return rgb(colorFromTheme);
|
|
89
|
+
}
|
|
90
|
+
const parts = color.split('-');
|
|
91
|
+
if (parts.length === 2) {
|
|
92
|
+
const colorKey = parts[0];
|
|
93
|
+
const shade = parts[1];
|
|
94
|
+
const colorValue = palette[colorKey]?.[shade];
|
|
95
|
+
if (!colorValue) {
|
|
96
|
+
if (isValidColor(color)) {
|
|
97
|
+
return color;
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Color token "${colorKey}-${shade}" not found`);
|
|
100
|
+
}
|
|
101
|
+
return colorValue;
|
|
102
|
+
}
|
|
103
|
+
const colorValue = palette[color];
|
|
104
|
+
if (!colorValue) {
|
|
105
|
+
if (isValidColor(color)) {
|
|
106
|
+
return color;
|
|
107
|
+
}
|
|
108
|
+
throw new Error(`Color token "${color}" not found`);
|
|
109
|
+
}
|
|
110
|
+
return colorValue;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Get hex number representation of a color
|
|
114
|
+
* @param color - Color token, theme color key or valid color string
|
|
115
|
+
* @returns Hex color number
|
|
116
|
+
* @throws {Error} If color token is not found
|
|
117
|
+
*/
|
|
118
|
+
const hex = (color) => {
|
|
119
|
+
// See note in rgb()
|
|
120
|
+
if (typeof color === 'string' && isValidColor(color)) {
|
|
121
|
+
return convertColorValueToNumber(color);
|
|
122
|
+
}
|
|
123
|
+
const colorFromTheme = getValueFromTheme(color);
|
|
124
|
+
if (colorFromTheme) {
|
|
125
|
+
return hex(colorFromTheme);
|
|
126
|
+
}
|
|
127
|
+
const parts = color.split('-');
|
|
128
|
+
if (parts.length === 2) {
|
|
129
|
+
const colorKey = parts[0];
|
|
130
|
+
const shade = parts[1];
|
|
131
|
+
const colorValue = palette[colorKey]?.[shade];
|
|
132
|
+
if (!colorValue) {
|
|
133
|
+
if (isValidColor(color)) {
|
|
134
|
+
return convertColorValueToNumber(color);
|
|
135
|
+
}
|
|
136
|
+
throw new Error(`Color token "${colorKey}-${shade}" not found`);
|
|
137
|
+
}
|
|
138
|
+
return convertColorValueToNumber(colorValue);
|
|
139
|
+
}
|
|
140
|
+
const colorToConvert = palette[color];
|
|
141
|
+
if (isValidColor(colorToConvert)) {
|
|
142
|
+
return convertColorValueToNumber(colorToConvert);
|
|
143
|
+
}
|
|
144
|
+
throw new Error(`Color token "${color}" not found`);
|
|
145
|
+
};
|
|
146
|
+
const api = {
|
|
147
|
+
rgb,
|
|
148
|
+
hex,
|
|
149
|
+
slate: (shade) => rgb(`slate-${shade}`),
|
|
150
|
+
gray: (shade) => rgb(`gray-${shade}`),
|
|
151
|
+
zinc: (shade) => rgb(`zinc-${shade}`),
|
|
152
|
+
neutral: (shade) => rgb(`neutral-${shade}`),
|
|
153
|
+
stone: (shade) => rgb(`stone-${shade}`),
|
|
154
|
+
red: (shade) => rgb(`red-${shade}`),
|
|
155
|
+
orange: (shade) => rgb(`orange-${shade}`),
|
|
156
|
+
amber: (shade) => rgb(`amber-${shade}`),
|
|
157
|
+
yellow: (shade) => rgb(`yellow-${shade}`),
|
|
158
|
+
lime: (shade) => rgb(`lime-${shade}`),
|
|
159
|
+
green: (shade) => rgb(`green-${shade}`),
|
|
160
|
+
emerald: (shade) => rgb(`emerald-${shade}`),
|
|
161
|
+
teal: (shade) => rgb(`teal-${shade}`),
|
|
162
|
+
cyan: (shade) => rgb(`cyan-${shade}`),
|
|
163
|
+
sky: (shade) => rgb(`sky-${shade}`),
|
|
164
|
+
blue: (shade) => rgb(`blue-${shade}`),
|
|
165
|
+
indigo: (shade) => rgb(`indigo-${shade}`),
|
|
166
|
+
violet: (shade) => rgb(`violet-${shade}`),
|
|
167
|
+
purple: (shade) => rgb(`purple-${shade}`),
|
|
168
|
+
fuchsia: (shade) => rgb(`fuchsia-${shade}`),
|
|
169
|
+
pink: (shade) => rgb(`pink-${shade}`),
|
|
170
|
+
rose: (shade) => rgb(`rose-${shade}`),
|
|
171
|
+
slateHex: (shade) => hex(`slate-${shade}`),
|
|
172
|
+
grayHex: (shade) => hex(`gray-${shade}`),
|
|
173
|
+
zincHex: (shade) => hex(`zinc-${shade}`),
|
|
174
|
+
neutralHex: (shade) => hex(`neutral-${shade}`),
|
|
175
|
+
stoneHex: (shade) => hex(`stone-${shade}`),
|
|
176
|
+
redHex: (shade) => hex(`red-${shade}`),
|
|
177
|
+
orangeHex: (shade) => hex(`orange-${shade}`),
|
|
178
|
+
amberHex: (shade) => hex(`amber-${shade}`),
|
|
179
|
+
yellowHex: (shade) => hex(`yellow-${shade}`),
|
|
180
|
+
limeHex: (shade) => hex(`lime-${shade}`),
|
|
181
|
+
greenHex: (shade) => hex(`green-${shade}`),
|
|
182
|
+
emeraldHex: (shade) => hex(`emerald-${shade}`),
|
|
183
|
+
tealHex: (shade) => hex(`teal-${shade}`),
|
|
184
|
+
cyanHex: (shade) => hex(`cyan-${shade}`),
|
|
185
|
+
skyHex: (shade) => hex(`sky-${shade}`),
|
|
186
|
+
blueHex: (shade) => hex(`blue-${shade}`),
|
|
187
|
+
indigoHex: (shade) => hex(`indigo-${shade}`),
|
|
188
|
+
violetHex: (shade) => hex(`violet-${shade}`),
|
|
189
|
+
purpleHex: (shade) => hex(`purple-${shade}`),
|
|
190
|
+
fuchsiaHex: (shade) => hex(`fuchsia-${shade}`),
|
|
191
|
+
pinkHex: (shade) => hex(`pink-${shade}`),
|
|
192
|
+
roseHex: (shade) => hex(`rose-${shade}`),
|
|
193
|
+
};
|
|
194
|
+
return api;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Convenience instance using only the default palette tokens (no theme).
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* Color.rgb('emerald-400')
|
|
201
|
+
* Color.hex('black')
|
|
202
|
+
*/
|
|
203
|
+
// eslint-disable-next-line no-redeclare
|
|
204
|
+
export const Color = createColor({});
|
|
205
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/core/color.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,mDAAmD;AACnD,MAAM,SAAS,GAAG,gCAAgC,CAAC;AA8CnD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAU,EAAE;IACtD,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAU,EAAE;IACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAA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../src/core/color.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
/* eslint-disable max-lines-per-function */
|
|
3
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { createTheme } from '../theme';
|
|
5
|
+
import { createColor, Color as ColorDefault, } from './color';
|
|
6
|
+
const RED_500_RGB = 'rgb(239, 68, 68)';
|
|
7
|
+
const SLATE_50_RGB = 'rgb(248, 250, 252)';
|
|
8
|
+
const RED_500_TOKEN = 'red-500';
|
|
9
|
+
const SLATE_50_TOKEN = '50';
|
|
10
|
+
const BLUE_500_TOKEN = '500';
|
|
11
|
+
describe('ColorPicker', () => {
|
|
12
|
+
let color;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
const fakeTheme = createTheme({
|
|
15
|
+
colors: {
|
|
16
|
+
primary: 'red-500',
|
|
17
|
+
secondary: 'slate-50',
|
|
18
|
+
another: '#ff9887',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
color = createColor(fakeTheme);
|
|
22
|
+
});
|
|
23
|
+
describe('rgb method', () => {
|
|
24
|
+
it.each([
|
|
25
|
+
// slate
|
|
26
|
+
['slate-50', SLATE_50_RGB],
|
|
27
|
+
['slate-100', 'rgb(241, 245, 249)'],
|
|
28
|
+
['slate-200', 'rgb(226, 232, 240)'],
|
|
29
|
+
['slate-300', 'rgb(203, 213, 225)'],
|
|
30
|
+
['slate-400', 'rgb(148, 163, 184)'],
|
|
31
|
+
['slate-500', 'rgb(100, 116, 139)'],
|
|
32
|
+
['slate-600', 'rgb(71, 85, 105)'],
|
|
33
|
+
['slate-700', 'rgb(51, 65, 85)'],
|
|
34
|
+
['slate-800', 'rgb(30, 41, 59)'],
|
|
35
|
+
['slate-900', 'rgb(15, 23, 42)'],
|
|
36
|
+
['slate-950', 'rgb(2, 6, 23)'],
|
|
37
|
+
// gray
|
|
38
|
+
['gray-50', 'rgb(249, 250, 251)'],
|
|
39
|
+
['gray-100', 'rgb(243, 244, 246)'],
|
|
40
|
+
['gray-200', 'rgb(229, 231, 235)'],
|
|
41
|
+
['gray-300', 'rgb(209, 213, 219)'],
|
|
42
|
+
['gray-400', 'rgb(156, 163, 175)'],
|
|
43
|
+
['gray-500', 'rgb(107, 114, 128)'],
|
|
44
|
+
['gray-600', 'rgb(75, 85, 99)'],
|
|
45
|
+
['gray-700', 'rgb(55, 65, 81)'],
|
|
46
|
+
['gray-800', 'rgb(31, 41, 55)'],
|
|
47
|
+
['gray-900', 'rgb(17, 24, 39)'],
|
|
48
|
+
['gray-950', 'rgb(3, 7, 18)'],
|
|
49
|
+
// zinc
|
|
50
|
+
['zinc-50', 'rgb(250, 250, 250)'],
|
|
51
|
+
['zinc-100', 'rgb(244, 244, 245)'],
|
|
52
|
+
['zinc-200', 'rgb(228, 228, 231)'],
|
|
53
|
+
['zinc-300', 'rgb(212, 212, 216)'],
|
|
54
|
+
['zinc-400', 'rgb(161, 161, 170)'],
|
|
55
|
+
['zinc-500', 'rgb(113, 113, 122)'],
|
|
56
|
+
['zinc-600', 'rgb(82, 82, 91)'],
|
|
57
|
+
['zinc-700', 'rgb(63, 63, 70)'],
|
|
58
|
+
['zinc-800', 'rgb(39, 39, 42)'],
|
|
59
|
+
['zinc-900', 'rgb(24, 24, 27)'],
|
|
60
|
+
['zinc-950', 'rgb(9, 9, 11)'],
|
|
61
|
+
// red
|
|
62
|
+
['red-50', 'rgb(254, 242, 242)'],
|
|
63
|
+
['red-100', 'rgb(254, 226, 226)'],
|
|
64
|
+
['red-200', 'rgb(254, 202, 202)'],
|
|
65
|
+
['red-300', 'rgb(252, 165, 165)'],
|
|
66
|
+
['red-400', 'rgb(248, 113, 113)'],
|
|
67
|
+
['red-500', RED_500_RGB],
|
|
68
|
+
['red-600', 'rgb(220, 38, 38)'],
|
|
69
|
+
['red-700', 'rgb(185, 28, 28)'],
|
|
70
|
+
['red-800', 'rgb(153, 27, 27)'],
|
|
71
|
+
['red-900', 'rgb(127, 29, 29)'],
|
|
72
|
+
['red-950', 'rgb(69, 10, 10)'],
|
|
73
|
+
// blue
|
|
74
|
+
['blue-50', 'rgb(239, 246, 255)'],
|
|
75
|
+
['blue-100', 'rgb(219, 234, 254)'],
|
|
76
|
+
['blue-200', 'rgb(191, 219, 254)'],
|
|
77
|
+
['blue-300', 'rgb(147, 197, 253)'],
|
|
78
|
+
['blue-400', 'rgb(96, 165, 250)'],
|
|
79
|
+
['blue-500', 'rgb(59, 130, 246)'],
|
|
80
|
+
['blue-600', 'rgb(37, 99, 235)'],
|
|
81
|
+
['blue-700', 'rgb(29, 78, 216)'],
|
|
82
|
+
['blue-800', 'rgb(30, 64, 175)'],
|
|
83
|
+
['blue-900', 'rgb(30, 58, 138)'],
|
|
84
|
+
['blue-950', 'rgb(23, 37, 84)'],
|
|
85
|
+
// green
|
|
86
|
+
['green-50', 'rgb(240, 253, 244)'],
|
|
87
|
+
['green-100', 'rgb(220, 252, 231)'],
|
|
88
|
+
['green-200', 'rgb(187, 247, 208)'],
|
|
89
|
+
['green-300', 'rgb(134, 239, 172)'],
|
|
90
|
+
['green-400', 'rgb(74, 222, 128)'],
|
|
91
|
+
['green-500', 'rgb(34, 197, 94)'],
|
|
92
|
+
['green-600', 'rgb(22, 163, 74)'],
|
|
93
|
+
['green-700', 'rgb(21, 128, 61)'],
|
|
94
|
+
['green-800', 'rgb(22, 101, 52)'],
|
|
95
|
+
['green-900', 'rgb(20, 83, 45)'],
|
|
96
|
+
['green-950', 'rgb(5, 46, 22)'],
|
|
97
|
+
// special colors
|
|
98
|
+
['black', '#000'],
|
|
99
|
+
['white', '#fff'],
|
|
100
|
+
])('should convert %s to rgb %s', (colorToken, expected) => {
|
|
101
|
+
expect(color.rgb(colorToken)).toBe(expected);
|
|
102
|
+
});
|
|
103
|
+
// With stronger typing, direct CSS strings are not allowed by the type system.
|
|
104
|
+
// Runtime still supports them when needed, but they are intentionally not tested here.
|
|
105
|
+
it('should return the theme color when pass a token', () => {
|
|
106
|
+
const color = createColor({
|
|
107
|
+
primary: 'red-500',
|
|
108
|
+
secondary: 'slate-50',
|
|
109
|
+
});
|
|
110
|
+
expect(color.rgb('primary')).toBe('rgb(239, 68, 68)');
|
|
111
|
+
expect(color.rgb('secondary')).toBe('rgb(248, 250, 252)');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('default Color constant (no theme)', () => {
|
|
115
|
+
it('should resolve palette tokens via Color constant', () => {
|
|
116
|
+
expect(ColorDefault.rgb(RED_500_TOKEN)).toBe(RED_500_RGB);
|
|
117
|
+
expect(ColorDefault.slate(SLATE_50_TOKEN)).toBe(SLATE_50_RGB);
|
|
118
|
+
expect(ColorDefault.blueHex(BLUE_500_TOKEN)).toBe(0x3b82f6);
|
|
119
|
+
});
|
|
120
|
+
it('should throw for unknown tokens', () => {
|
|
121
|
+
expect(() => ColorDefault.rgb('unknown-123')).toThrow();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('hex method', () => {
|
|
125
|
+
it.each([
|
|
126
|
+
// slate
|
|
127
|
+
['slate-50', 0xf8fafc],
|
|
128
|
+
['slate-100', 0xf1f5f9],
|
|
129
|
+
['slate-200', 0xe2e8f0],
|
|
130
|
+
['slate-300', 0xcbd5e1],
|
|
131
|
+
['slate-400', 0x94a3b8],
|
|
132
|
+
['slate-500', 0x64748b],
|
|
133
|
+
['slate-600', 0x475569],
|
|
134
|
+
['slate-700', 0x334155],
|
|
135
|
+
['slate-800', 0x1e293b],
|
|
136
|
+
['slate-900', 0x0f172a],
|
|
137
|
+
['slate-950', 0x020617],
|
|
138
|
+
// gray
|
|
139
|
+
['gray-50', 0xf9fafb],
|
|
140
|
+
['gray-100', 0xf3f4f6],
|
|
141
|
+
['gray-200', 0xe5e7eb],
|
|
142
|
+
['gray-300', 0xd1d5db],
|
|
143
|
+
['gray-400', 0x9ca3af],
|
|
144
|
+
['gray-500', 0x6b7280],
|
|
145
|
+
['gray-600', 0x4b5563],
|
|
146
|
+
['gray-700', 0x374151],
|
|
147
|
+
['gray-800', 0x1f2937],
|
|
148
|
+
['gray-900', 0x111827],
|
|
149
|
+
['gray-950', 0x030712],
|
|
150
|
+
// zinc
|
|
151
|
+
['zinc-50', 0xfafafa],
|
|
152
|
+
['zinc-100', 0xf4f4f5],
|
|
153
|
+
['zinc-200', 0xe4e4e7],
|
|
154
|
+
['zinc-300', 0xd4d4d8],
|
|
155
|
+
['zinc-400', 0xa1a1aa],
|
|
156
|
+
['zinc-500', 0x71717a],
|
|
157
|
+
['zinc-600', 0x52525b],
|
|
158
|
+
['zinc-700', 0x3f3f46],
|
|
159
|
+
['zinc-800', 0x27272a],
|
|
160
|
+
['zinc-900', 0x18181b],
|
|
161
|
+
['zinc-950', 0x09090b],
|
|
162
|
+
// red
|
|
163
|
+
['red-50', 0xfef2f2],
|
|
164
|
+
['red-100', 0xfee2e2],
|
|
165
|
+
['red-200', 0xfecaca],
|
|
166
|
+
['red-300', 0xfca5a5],
|
|
167
|
+
['red-400', 0xf87171],
|
|
168
|
+
['red-500', 0xef4444],
|
|
169
|
+
['red-600', 0xdc2626],
|
|
170
|
+
['red-700', 0xb91c1c],
|
|
171
|
+
['red-800', 0x991b1b],
|
|
172
|
+
['red-900', 0x7f1d1d],
|
|
173
|
+
['red-950', 0x450a0a],
|
|
174
|
+
// blue
|
|
175
|
+
['blue-50', 0xeff6ff],
|
|
176
|
+
['blue-100', 0xdbeafe],
|
|
177
|
+
['blue-200', 0xbfdbfe],
|
|
178
|
+
['blue-300', 0x93c5fd],
|
|
179
|
+
['blue-400', 0x60a5fa],
|
|
180
|
+
['blue-500', 0x3b82f6],
|
|
181
|
+
['blue-600', 0x2563eb],
|
|
182
|
+
['blue-700', 0x1d4ed8],
|
|
183
|
+
['blue-800', 0x1e40af],
|
|
184
|
+
['blue-900', 0x1e3a8a],
|
|
185
|
+
['blue-950', 0x172554],
|
|
186
|
+
// green
|
|
187
|
+
['green-50', 0xf0fdf4],
|
|
188
|
+
['green-100', 0xdcfce7],
|
|
189
|
+
['green-200', 0xbbf7d0],
|
|
190
|
+
['green-300', 0x86efac],
|
|
191
|
+
['green-400', 0x4ade80],
|
|
192
|
+
['green-500', 0x22c55e],
|
|
193
|
+
['green-600', 0x16a34a],
|
|
194
|
+
['green-700', 0x15803d],
|
|
195
|
+
['green-800', 0x166534],
|
|
196
|
+
['green-900', 0x14532d],
|
|
197
|
+
['green-950', 0x052e16],
|
|
198
|
+
// special colors
|
|
199
|
+
['black', 0x000000],
|
|
200
|
+
['white', 0xffffff],
|
|
201
|
+
])('should convert %s to hex 0x%s', (colorToken, expected) => {
|
|
202
|
+
expect(color.hex(colorToken)).toBe(expected);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('error handling', () => {
|
|
206
|
+
it('should throw an error for invalid color token', () => {
|
|
207
|
+
expect(() => color.rgb('invalid-color')).toThrow('Color token "invalid-color" not found');
|
|
208
|
+
});
|
|
209
|
+
it('should throw an error for invalid shade', () => {
|
|
210
|
+
expect(() => color.rgb('red-999')).toThrow('Color token "red-999" not found');
|
|
211
|
+
});
|
|
212
|
+
it('should throw an error for invalid color key', () => {
|
|
213
|
+
expect(() => color.hex('purples-500')).toThrow('Color token "purples-500" not found');
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe('theme integration', () => {
|
|
217
|
+
const fakeTheme = createTheme({
|
|
218
|
+
colors: {
|
|
219
|
+
primary: 'red-500',
|
|
220
|
+
secondary: 'slate-50',
|
|
221
|
+
another: '#ff9887',
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
const color = createColor(fakeTheme.colors);
|
|
225
|
+
it('should resolve theme token with colors. prefix', () => {
|
|
226
|
+
expect(color.rgb('primary')).toBe(RED_500_RGB);
|
|
227
|
+
expect(color.rgb('secondary')).toBe(SLATE_50_RGB);
|
|
228
|
+
expect(color.rgb('another')).toBe('#ff9887');
|
|
229
|
+
});
|
|
230
|
+
it('should resolve theme token without colors. prefix', () => {
|
|
231
|
+
expect(color.rgb('primary')).toBe(RED_500_RGB);
|
|
232
|
+
expect(color.rgb('secondary')).toBe(SLATE_50_RGB);
|
|
233
|
+
});
|
|
234
|
+
it('should convert theme tokens to hex', () => {
|
|
235
|
+
expect(color.hex('primary')).toBe(0xef4444);
|
|
236
|
+
expect(color.hex('secondary')).toBe(0xf8fafc);
|
|
237
|
+
});
|
|
238
|
+
it('should throw an error if theme token is not found', () => {
|
|
239
|
+
expect(() => color.rgb('colors.not-found')).toThrow('Color token "colors.not-found" not found');
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
//# sourceMappingURL=color.spec.js.map
|