@aviala-design/color 0.2.2 → 0.3.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 CHANGED
@@ -1,319 +1,322 @@
1
- # Aviala Design Color
2
-
3
- Aviala Design Color - A powerful color processing utility library.
4
-
5
- This library provides four core functionalities:
6
-
7
- 1. **Color Palette Generation**: Generate gradient swatches containing ten colors using algorithms, supporting both light and dark modes.
8
- 2. **Image Color Extraction**: Extract dominant colors from images for generating matching palettes or theme colors.
9
- 3. **Interface Color System**: Generate complete interface color systems based on primary colors, including semantic colors (success, warning, error, info).
10
- 4. **Theme Blending**: Advanced theme blending functionality based on HCT color space with multiple blending modes, supporting complete interface color system generation with brand customization.
11
-
12
- ## Usage
13
-
14
- ```bash
15
- npm i @arco-design/color
16
- ```
17
-
18
- ```js
19
- import {
20
- generate,
21
- getPresetColors,
22
- getRgbStr,
23
- extractColorFromImage,
24
- generateInterfaceColorSystem,
25
- generateThemePalette,
26
- blendInHct,
27
- rgbToHct,
28
- hctToRgb
29
- } from '@aviala-design/color';
30
-
31
- // Generate color palette
32
- console.log(generate('#123456'));
33
-
34
- // Get preset colors
35
- console.log(getPresetColors());
36
- // {
37
- // red: {...},
38
- // orangered: {...},
39
- // orange: {...},
40
- // gold: {...},
41
- // yellow: {...},
42
- // lime: {...},
43
- // green: {...},
44
- // cyan: {...},
45
- // blue: {...},
46
- // arcoblue: {...},
47
- // purple: {...},
48
- // pinkpurple: {...},
49
- // magenta: {...},
50
- // gray: {...}
51
- // }
52
-
53
- // Generate interface color system
54
- const colorSystem = generateInterfaceColorSystem('#3491FA');
55
- console.log(colorSystem.success); // Success colors
56
- console.log(colorSystem.warning); // Warning colors
57
- console.log(colorSystem.error); // Error colors
58
- console.log(colorSystem.info); // Info colors
59
-
60
- // Generate complete theme palette with brand customization
61
- const themePalette = generateThemePalette('#3491FA', {
62
- semanticColors: {
63
- success: '#00C853',
64
- warning: '#FF9800',
65
- error: '#F44336'
66
- },
67
- semanticBlendRatio: 0.1 // 10% brand influence on semantic colors
68
- });
69
- console.log(themePalette.control); // Control colors (primary, gray)
70
- console.log(themePalette.semantic); // Semantic colors with brand influence
71
- console.log(themePalette.theme); // Theme color variations
72
-
73
- // Theme blending
74
- const blended = blendInHct([64, 196, 255], [255, 87, 34], 'overlay', 0.5);
75
- console.log(blended); // Blended RGB color
76
- ```
77
-
78
- ## API
79
-
80
- ### generate(color: string, options: Object);
81
-
82
- #### options.index {number | 1-10}
83
-
84
- Index (starting from 1) of the gradient colors to be generated.
85
-
86
- #### options.list {boolean}
87
-
88
- Whether to generate color array containing the ten colors.
89
-
90
- #### options.dark
91
-
92
- Whether to generate colors for dark mode.
93
-
94
- #### options.format {'hex' | 'rgb' | 'hsl'}
95
-
96
- Color format.
97
- ### getPresetColors {Function}
98
-
99
- Contains 14 preset sets of colors.
100
-
101
- * `red`
102
- * `orangered`
103
- * `orange`
104
- * `gold`
105
- * `yellow`
106
- * `lime`
107
- * `green`
108
- * `cyan`
109
- * `blue`
110
- * `arcoblue`
111
- * `purple`
112
- * `pinkpurple`
113
- * `magenta`
114
- * `gray`
115
-
116
- ```js
117
- const { red } = getPresetColors();
118
-
119
- console.log(red.light);
120
- console.log(red.dark);
121
- console.log(red.primary);
122
- ```
123
-
124
- ### getRgbStr(color: string)
125
-
126
- For a given color, get the r, g, b value in string
127
-
128
- ```js
129
- getRgbStr('#F53F3F') // 245,63,63
130
- ```
131
-
132
- ### generateInterfaceColorSystem(primaryColor: string, options?: Object)
133
-
134
- Generate a complete interface color system based on a primary color, including semantic colors.
135
-
136
- **Parameters:**
137
- - `primaryColor`: string - Primary color in hex format (e.g., '#3491FA')
138
- - `options`: Object - Optional configuration
139
- - `successBase`: string - Custom success color base, defaults to green
140
- - `warningBase`: string - Custom warning color base, defaults to orange
141
- - `errorBase`: string - Custom error color base, defaults to red
142
- - `infoBase`: string - Custom info color base, defaults to blue
143
-
144
- **Returns:**
145
- - `Object` - Complete color system object
146
- - `primary`: string[] - Primary color palette (10 colors)
147
- - `success`: string[] - Success color palette (10 colors)
148
- - `warning`: string[] - Warning color palette (10 colors)
149
- - `error`: string[] - Error color palette (10 colors)
150
- - `info`: string[] - Info color palette (10 colors)
151
-
152
- ```js
153
- // Generate default interface color system
154
- const colorSystem = generateInterfaceColorSystem('#3491FA');
155
- console.log(colorSystem.primary); // Primary color palette
156
- console.log(colorSystem.success); // Success color palette
157
-
158
- // Custom semantic color bases
159
- const customColorSystem = generateInterfaceColorSystem('#3491FA', {
160
- successBase: '#00C853',
161
- warningBase: '#FF9800',
162
- errorBase: '#F44336',
163
- infoBase: '#2196F3'
164
- });
165
- ```
166
-
167
- ### generateThemePalette(themeColor: string, options?: Object)
168
-
169
- Generate a complete theme palette with advanced brand customization and semantic color blending.
170
-
171
- **Parameters:**
172
- - `themeColor`: string - Primary theme color in hex format
173
- - `options`: Object - Optional configuration
174
- - `semanticColors`: Object - Custom semantic color bases
175
- - `success`: string - Success color base
176
- - `warning`: string - Warning color base
177
- - `error`: string - Error color base
178
- - `info`: string - Info color base
179
- - `semanticBlendRatio`: number - Brand influence on semantic colors (0-1, default: 0.08)
180
- - `controlBlendRatio`: number - Brand influence on control colors (0-1, default: 0.05)
181
-
182
- **Returns:**
183
- - `Object` - Complete theme palette
184
- - `control`: Object - Control colors (primary, gray)
185
- - `semantic`: Object - Semantic colors with brand influence
186
- - `theme`: string[] - Theme color variations (10 colors)
187
-
188
- ```js
189
- // Basic theme palette
190
- const basicPalette = generateThemePalette('#3491FA');
191
-
192
- // Advanced customization with brand influence
193
- const brandPalette = generateThemePalette('#3491FA', {
194
- semanticColors: {
195
- success: '#00C853',
196
- warning: '#FF9800',
197
- error: '#F44336',
198
- info: '#2196F3'
199
- },
200
- semanticBlendRatio: 0.12, // 12% brand influence
201
- controlBlendRatio: 0.08 // 8% brand influence
202
- });
203
- console.log(brandPalette.semantic.success); // Brand-influenced success colors
204
- ```
205
-
206
- ### rgbToHct(rgb: number[])
207
-
208
- Convert RGB color to HCT color space.
209
-
210
- **Parameters:**
211
- - `rgb`: number[] - RGB color array [r, g, b], range 0-255
212
-
213
- **Returns:**
214
- - `number[]` - HCT color array [h, c, t], hue(0-360), chroma(0-100+), tone(0-100)
215
-
216
- ### hctToRgb(hct: number[])
217
-
218
- Convert HCT color to RGB color space.
219
-
220
- **Parameters:**
221
- - `hct`: number[] - HCT color array [h, c, t]
222
-
223
- **Returns:**
224
- - `number[]` - RGB color array [r, g, b], range 0-255
225
-
226
- ### blendInHct(color1: number[], color2: number[], mode: string, ratio: number)
227
-
228
- Blend two colors in HCT color space.
229
-
230
- **Parameters:**
231
- - `color1`: number[] - First color RGB array
232
- - `color2`: number[] - Second color RGB array
233
- - `mode`: string - Blend mode: 'multiply', 'screen', 'overlay', 'softLight'
234
- - `ratio`: number - Blend ratio, range 0-1
235
-
236
- **Returns:**
237
- - `number[]` - Blended RGB color array
238
-
239
- ```js
240
- // RGB to HCT conversion
241
- const hct = rgbToHct([64, 196, 255]);
242
- console.log(hct); // [200, 45, 80]
243
-
244
- // HCT to RGB conversion
245
- const rgb = hctToRgb([200, 45, 80]);
246
- console.log(rgb); // [64, 196, 255]
247
-
248
- // Color blending
249
- const blended = blendInHct(
250
- [64, 196, 255], // Blue
251
- [255, 87, 34], // Orange
252
- 'overlay', // Overlay mode
253
- 0.5 // 50% blend
254
- );
255
- console.log(blended); // Blended color
256
-
257
- // Different blend modes
258
- const multiply = blendInHct([255, 0, 0], [0, 255, 0], 'multiply', 0.5);
259
- const screen = blendInHct([255, 0, 0], [0, 255, 0], 'screen', 0.5);
260
- const softLight = blendInHct([255, 0, 0], [0, 255, 0], 'softLight', 0.5);
261
- ```
262
-
263
- ### extractColorFromImage(image: HTMLImageElement)
264
-
265
- Extract dominant color from a loaded image element.
266
-
267
- **Parameters:**
268
- - `image`: HTMLImageElement - Loaded image element
269
-
270
- **Returns:**
271
- - `Promise<string>` - Extracted dominant color (hex format)
272
-
273
- ```js
274
- const image = document.getElementById('myImage');
275
- extractColorFromImage(image).then(color => {
276
- console.log('Extracted color:', color);
277
- // Generate palette from extracted color
278
- const palette = generate(color, { list: true });
279
- });
280
- ```
281
-
282
- ### extractColorFromFile(file: File)
283
-
284
- Read image from file object and extract dominant color.
285
-
286
- **Parameters:**
287
- - `file`: File - Image file object
288
-
289
- **Returns:**
290
- - `Promise<string>` - Extracted dominant color (hex format)
291
-
292
- ```js
293
- // Use in file input event
294
- document.getElementById('fileInput').addEventListener('change', (event) => {
295
- const file = event.target.files[0];
296
- if (file) {
297
- extractColorFromFile(file).then(color => {
298
- console.log('Extracted color:', color);
299
- });
300
- }
301
- });
302
- ```
303
-
304
- ## Version History
305
-
306
- ### v0.2.0 (Latest)
307
- - Added interface color system functionality
308
- - ✨ Added HCT color space-based theme blending
309
- - 📚 Enhanced API documentation and examples
310
- - 🔧 Optimized code structure and performance
311
-
312
- ### v0.1.1
313
- - 🐛 Fixed edge cases in color palette generation
314
- - 📚 Updated documentation and examples
315
-
316
- ### v0.1.0
317
- - 🎉 Initial release
318
- - ✨ Color palette generation
319
- - ✨ Image color extraction
1
+ <!-- 当前版本: 0.3.0 | 最后同步: 2025/11/9 02:37:52 -->
2
+ # Aviala Design Color
3
+
4
+ ![npm version](https://img.shields.io/npm/v/@aviala-design/color) ![npm downloads](https://img.shields.io/npm/dm/@aviala-design/color) ![license](https://img.shields.io/npm/l/@aviala-design/color)
5
+
6
+ Aviala Design Color - A powerful color processing utility library.
7
+
8
+ This library provides four core functionalities:
9
+
10
+ 1. **Color Palette Generation**: Generate gradient swatches containing ten colors using algorithms, supporting both light and dark modes.
11
+ 2. **Image Color Extraction**: Extract dominant colors from images for generating matching palettes or theme colors.
12
+ 3. **Interface Color System**: Generate complete interface color systems based on primary colors, including semantic colors (success, warning, error, info).
13
+ 4. **Theme Blending**: Advanced theme blending functionality based on HCT color space with multiple blending modes, supporting complete interface color system generation with brand customization.
14
+
15
+ ## Usage
16
+
17
+ ```bash
18
+ npm i @aviala-design/color
19
+ ```
20
+
21
+ ```js
22
+ import {
23
+ generate,
24
+ getPresetColors,
25
+ getRgbStr,
26
+ extractColorFromImage,
27
+ generateInterfaceColorSystem,
28
+ generateThemePalette,
29
+ blendInHct,
30
+ rgbToHct,
31
+ hctToRgb
32
+ } from '@aviala-design/color';
33
+
34
+ // Generate color palette
35
+ console.log(generate('#123456'));
36
+
37
+ // Get preset colors
38
+ console.log(getPresetColors());
39
+ // {
40
+ // red: {...},
41
+ // orangered: {...},
42
+ // orange: {...},
43
+ // gold: {...},
44
+ // yellow: {...},
45
+ // lime: {...},
46
+ // green: {...},
47
+ // cyan: {...},
48
+ // blue: {...},
49
+ // arcoblue: {...},
50
+ // purple: {...},
51
+ // pinkpurple: {...},
52
+ // magenta: {...},
53
+ // gray: {...}
54
+ // }
55
+
56
+ // Generate interface color system
57
+ const colorSystem = generateInterfaceColorSystem('#3491FA');
58
+ console.log(colorSystem.success); // Success colors
59
+ console.log(colorSystem.warning); // Warning colors
60
+ console.log(colorSystem.error); // Error colors
61
+ console.log(colorSystem.info); // Info colors
62
+
63
+ // Generate complete theme palette with brand customization
64
+ const themePalette = generateThemePalette('#3491FA', {
65
+ semanticColors: {
66
+ success: '#00C853',
67
+ warning: '#FF9800',
68
+ error: '#F44336'
69
+ },
70
+ semanticBlendRatio: 0.1 // 10% brand influence on semantic colors
71
+ });
72
+ console.log(themePalette.control); // Control colors (primary, gray)
73
+ console.log(themePalette.semantic); // Semantic colors with brand influence
74
+ console.log(themePalette.theme); // Theme color variations
75
+
76
+ // Theme blending
77
+ const blended = blendInHct([64, 196, 255], [255, 87, 34], 'overlay', 0.5);
78
+ console.log(blended); // Blended RGB color
79
+ ```
80
+
81
+ ## API
82
+
83
+ ### generate(color: string, options: Object);
84
+
85
+ #### options.index {number | 1-10}
86
+
87
+ Index (starting from 1) of the gradient colors to be generated.
88
+
89
+ #### options.list {boolean}
90
+
91
+ Whether to generate color array containing the ten colors.
92
+
93
+ #### options.dark
94
+
95
+ Whether to generate colors for dark mode.
96
+
97
+ #### options.format {'hex' | 'rgb' | 'hsl'}
98
+
99
+ Color format.
100
+ ### getPresetColors {Function}
101
+
102
+ Contains 14 preset sets of colors.
103
+
104
+ * `red`
105
+ * `orangered`
106
+ * `orange`
107
+ * `gold`
108
+ * `yellow`
109
+ * `lime`
110
+ * `green`
111
+ * `cyan`
112
+ * `blue`
113
+ * `arcoblue`
114
+ * `purple`
115
+ * `pinkpurple`
116
+ * `magenta`
117
+ * `gray`
118
+
119
+ ```js
120
+ const { red } = getPresetColors();
121
+
122
+ console.log(red.light);
123
+ console.log(red.dark);
124
+ console.log(red.primary);
125
+ ```
126
+
127
+ ### getRgbStr(color: string)
128
+
129
+ For a given color, get the r, g, b value in string
130
+
131
+ ```js
132
+ getRgbStr('#F53F3F') // 245,63,63
133
+ ```
134
+
135
+ ### generateInterfaceColorSystem(primaryColor: string, options?: Object)
136
+
137
+ Generate a complete interface color system based on a primary color, including semantic colors.
138
+
139
+ **Parameters:**
140
+ - `primaryColor`: string - Primary color in hex format (e.g., '#3491FA')
141
+ - `options`: Object - Optional configuration
142
+ - `successBase`: string - Custom success color base, defaults to green
143
+ - `warningBase`: string - Custom warning color base, defaults to orange
144
+ - `errorBase`: string - Custom error color base, defaults to red
145
+ - `infoBase`: string - Custom info color base, defaults to blue
146
+
147
+ **Returns:**
148
+ - `Object` - Complete color system object
149
+ - `primary`: string[] - Primary color palette (10 colors)
150
+ - `success`: string[] - Success color palette (10 colors)
151
+ - `warning`: string[] - Warning color palette (10 colors)
152
+ - `error`: string[] - Error color palette (10 colors)
153
+ - `info`: string[] - Info color palette (10 colors)
154
+
155
+ ```js
156
+ // Generate default interface color system
157
+ const colorSystem = generateInterfaceColorSystem('#3491FA');
158
+ console.log(colorSystem.primary); // Primary color palette
159
+ console.log(colorSystem.success); // Success color palette
160
+
161
+ // Custom semantic color bases
162
+ const customColorSystem = generateInterfaceColorSystem('#3491FA', {
163
+ successBase: '#00C853',
164
+ warningBase: '#FF9800',
165
+ errorBase: '#F44336',
166
+ infoBase: '#2196F3'
167
+ });
168
+ ```
169
+
170
+ ### generateThemePalette(themeColor: string, options?: Object)
171
+
172
+ Generate a complete theme palette with advanced brand customization and semantic color blending.
173
+
174
+ **Parameters:**
175
+ - `themeColor`: string - Primary theme color in hex format
176
+ - `options`: Object - Optional configuration
177
+ - `semanticColors`: Object - Custom semantic color bases
178
+ - `success`: string - Success color base
179
+ - `warning`: string - Warning color base
180
+ - `error`: string - Error color base
181
+ - `info`: string - Info color base
182
+ - `semanticBlendRatio`: number - Brand influence on semantic colors (0-1, default: 0.08)
183
+ - `controlBlendRatio`: number - Brand influence on control colors (0-1, default: 0.05)
184
+
185
+ **Returns:**
186
+ - `Object` - Complete theme palette
187
+ - `control`: Object - Control colors (primary, gray)
188
+ - `semantic`: Object - Semantic colors with brand influence
189
+ - `theme`: string[] - Theme color variations (10 colors)
190
+
191
+ ```js
192
+ // Basic theme palette
193
+ const basicPalette = generateThemePalette('#3491FA');
194
+
195
+ // Advanced customization with brand influence
196
+ const brandPalette = generateThemePalette('#3491FA', {
197
+ semanticColors: {
198
+ success: '#00C853',
199
+ warning: '#FF9800',
200
+ error: '#F44336',
201
+ info: '#2196F3'
202
+ },
203
+ semanticBlendRatio: 0.12, // 12% brand influence
204
+ controlBlendRatio: 0.08 // 8% brand influence
205
+ });
206
+ console.log(brandPalette.semantic.success); // Brand-influenced success colors
207
+ ```
208
+
209
+ ### rgbToHct(rgb: number[])
210
+
211
+ Convert RGB color to HCT color space.
212
+
213
+ **Parameters:**
214
+ - `rgb`: number[] - RGB color array [r, g, b], range 0-255
215
+
216
+ **Returns:**
217
+ - `number[]` - HCT color array [h, c, t], hue(0-360), chroma(0-100+), tone(0-100)
218
+
219
+ ### hctToRgb(hct: number[])
220
+
221
+ Convert HCT color to RGB color space.
222
+
223
+ **Parameters:**
224
+ - `hct`: number[] - HCT color array [h, c, t]
225
+
226
+ **Returns:**
227
+ - `number[]` - RGB color array [r, g, b], range 0-255
228
+
229
+ ### blendInHct(color1: number[], color2: number[], mode: string, ratio: number)
230
+
231
+ Blend two colors in HCT color space.
232
+
233
+ **Parameters:**
234
+ - `color1`: number[] - First color RGB array
235
+ - `color2`: number[] - Second color RGB array
236
+ - `mode`: string - Blend mode: 'multiply', 'screen', 'overlay', 'softLight'
237
+ - `ratio`: number - Blend ratio, range 0-1
238
+
239
+ **Returns:**
240
+ - `number[]` - Blended RGB color array
241
+
242
+ ```js
243
+ // RGB to HCT conversion
244
+ const hct = rgbToHct([64, 196, 255]);
245
+ console.log(hct); // [200, 45, 80]
246
+
247
+ // HCT to RGB conversion
248
+ const rgb = hctToRgb([200, 45, 80]);
249
+ console.log(rgb); // [64, 196, 255]
250
+
251
+ // Color blending
252
+ const blended = blendInHct(
253
+ [64, 196, 255], // Blue
254
+ [255, 87, 34], // Orange
255
+ 'overlay', // Overlay mode
256
+ 0.5 // 50% blend
257
+ );
258
+ console.log(blended); // Blended color
259
+
260
+ // Different blend modes
261
+ const multiply = blendInHct([255, 0, 0], [0, 255, 0], 'multiply', 0.5);
262
+ const screen = blendInHct([255, 0, 0], [0, 255, 0], 'screen', 0.5);
263
+ const softLight = blendInHct([255, 0, 0], [0, 255, 0], 'softLight', 0.5);
264
+ ```
265
+
266
+ ### extractColorFromImage(image: HTMLImageElement)
267
+
268
+ Extract dominant color from a loaded image element.
269
+
270
+ **Parameters:**
271
+ - `image`: HTMLImageElement - Loaded image element
272
+
273
+ **Returns:**
274
+ - `Promise<string>` - Extracted dominant color (hex format)
275
+
276
+ ```js
277
+ const image = document.getElementById('myImage');
278
+ extractColorFromImage(image).then(color => {
279
+ console.log('Extracted color:', color);
280
+ // Generate palette from extracted color
281
+ const palette = generate(color, { list: true });
282
+ });
283
+ ```
284
+
285
+ ### extractColorFromFile(file: File)
286
+
287
+ Read image from file object and extract dominant color.
288
+
289
+ **Parameters:**
290
+ - `file`: File - Image file object
291
+
292
+ **Returns:**
293
+ - `Promise<string>` - Extracted dominant color (hex format)
294
+
295
+ ```js
296
+ // Use in file input event
297
+ document.getElementById('fileInput').addEventListener('change', (event) => {
298
+ const file = event.target.files[0];
299
+ if (file) {
300
+ extractColorFromFile(file).then(color => {
301
+ console.log('Extracted color:', color);
302
+ });
303
+ }
304
+ });
305
+ ```
306
+
307
+ ## Version History
308
+
309
+ ### v0.2.0 (Latest)
310
+ - Added interface color system functionality
311
+ - ✨ Added HCT color space-based theme blending
312
+ - 📚 Enhanced API documentation and examples
313
+ - 🔧 Optimized code structure and performance
314
+
315
+ ### v0.1.1
316
+ - 🐛 Fixed edge cases in color palette generation
317
+ - 📚 Updated documentation and examples
318
+
319
+ ### v0.1.0
320
+ - 🎉 Initial release
321
+ - ✨ Color palette generation
322
+ - ✨ Image color extraction