@aviala-design/color 0.2.0 → 0.2.1
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 +181 -4
- package/README.zh-CN.md +167 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Aviala Design Color
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Aviala Design Color - A powerful color processing utility library.
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
6
11
|
|
|
7
12
|
## Usage
|
|
8
13
|
|
|
@@ -11,10 +16,21 @@ npm i @arco-design/color
|
|
|
11
16
|
```
|
|
12
17
|
|
|
13
18
|
```js
|
|
14
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
generate,
|
|
21
|
+
getPresetColors,
|
|
22
|
+
getRgbStr,
|
|
23
|
+
extractColorFromImage,
|
|
24
|
+
generateInterfaceColorSystem,
|
|
25
|
+
blendInHct,
|
|
26
|
+
rgbToHct,
|
|
27
|
+
hctToRgb
|
|
28
|
+
} from '@aviala-design/color';
|
|
15
29
|
|
|
30
|
+
// Generate color palette
|
|
16
31
|
console.log(generate('#123456'));
|
|
17
32
|
|
|
33
|
+
// Get preset colors
|
|
18
34
|
console.log(getPresetColors());
|
|
19
35
|
// {
|
|
20
36
|
// red: {...},
|
|
@@ -32,6 +48,17 @@ console.log(getPresetColors());
|
|
|
32
48
|
// magenta: {...},
|
|
33
49
|
// gray: {...}
|
|
34
50
|
// }
|
|
51
|
+
|
|
52
|
+
// Generate interface color system
|
|
53
|
+
const colorSystem = generateInterfaceColorSystem('#3491FA');
|
|
54
|
+
console.log(colorSystem.success); // Success colors
|
|
55
|
+
console.log(colorSystem.warning); // Warning colors
|
|
56
|
+
console.log(colorSystem.error); // Error colors
|
|
57
|
+
console.log(colorSystem.info); // Info colors
|
|
58
|
+
|
|
59
|
+
// Theme blending
|
|
60
|
+
const blended = blendInHct([64, 196, 255], [255, 87, 34], 'overlay', 0.5);
|
|
61
|
+
console.log(blended); // Blended RGB color
|
|
35
62
|
```
|
|
36
63
|
|
|
37
64
|
## API
|
|
@@ -87,3 +114,153 @@ For a given color, get the r, g, b value in string
|
|
|
87
114
|
```js
|
|
88
115
|
getRgbStr('#F53F3F') // 245,63,63
|
|
89
116
|
```
|
|
117
|
+
|
|
118
|
+
### generateInterfaceColorSystem(primaryColor: string, options?: Object)
|
|
119
|
+
|
|
120
|
+
Generate a complete interface color system based on a primary color, including semantic colors.
|
|
121
|
+
|
|
122
|
+
**Parameters:**
|
|
123
|
+
- `primaryColor`: string - Primary color in hex format (e.g., '#3491FA')
|
|
124
|
+
- `options`: Object - Optional configuration
|
|
125
|
+
- `successBase`: string - Custom success color base, defaults to green
|
|
126
|
+
- `warningBase`: string - Custom warning color base, defaults to orange
|
|
127
|
+
- `errorBase`: string - Custom error color base, defaults to red
|
|
128
|
+
- `infoBase`: string - Custom info color base, defaults to blue
|
|
129
|
+
|
|
130
|
+
**Returns:**
|
|
131
|
+
- `Object` - Complete color system object
|
|
132
|
+
- `primary`: string[] - Primary color palette (10 colors)
|
|
133
|
+
- `success`: string[] - Success color palette (10 colors)
|
|
134
|
+
- `warning`: string[] - Warning color palette (10 colors)
|
|
135
|
+
- `error`: string[] - Error color palette (10 colors)
|
|
136
|
+
- `info`: string[] - Info color palette (10 colors)
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
// Generate default interface color system
|
|
140
|
+
const colorSystem = generateInterfaceColorSystem('#3491FA');
|
|
141
|
+
console.log(colorSystem.primary); // Primary color palette
|
|
142
|
+
console.log(colorSystem.success); // Success color palette
|
|
143
|
+
|
|
144
|
+
// Custom semantic color bases
|
|
145
|
+
const customColorSystem = generateInterfaceColorSystem('#3491FA', {
|
|
146
|
+
successBase: '#00C853',
|
|
147
|
+
warningBase: '#FF9800',
|
|
148
|
+
errorBase: '#F44336',
|
|
149
|
+
infoBase: '#2196F3'
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### rgbToHct(rgb: number[])
|
|
154
|
+
|
|
155
|
+
Convert RGB color to HCT color space.
|
|
156
|
+
|
|
157
|
+
**Parameters:**
|
|
158
|
+
- `rgb`: number[] - RGB color array [r, g, b], range 0-255
|
|
159
|
+
|
|
160
|
+
**Returns:**
|
|
161
|
+
- `number[]` - HCT color array [h, c, t], hue(0-360), chroma(0-100+), tone(0-100)
|
|
162
|
+
|
|
163
|
+
### hctToRgb(hct: number[])
|
|
164
|
+
|
|
165
|
+
Convert HCT color to RGB color space.
|
|
166
|
+
|
|
167
|
+
**Parameters:**
|
|
168
|
+
- `hct`: number[] - HCT color array [h, c, t]
|
|
169
|
+
|
|
170
|
+
**Returns:**
|
|
171
|
+
- `number[]` - RGB color array [r, g, b], range 0-255
|
|
172
|
+
|
|
173
|
+
### blendInHct(color1: number[], color2: number[], mode: string, ratio: number)
|
|
174
|
+
|
|
175
|
+
Blend two colors in HCT color space.
|
|
176
|
+
|
|
177
|
+
**Parameters:**
|
|
178
|
+
- `color1`: number[] - First color RGB array
|
|
179
|
+
- `color2`: number[] - Second color RGB array
|
|
180
|
+
- `mode`: string - Blend mode: 'multiply', 'screen', 'overlay', 'softLight'
|
|
181
|
+
- `ratio`: number - Blend ratio, range 0-1
|
|
182
|
+
|
|
183
|
+
**Returns:**
|
|
184
|
+
- `number[]` - Blended RGB color array
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
// RGB to HCT conversion
|
|
188
|
+
const hct = rgbToHct([64, 196, 255]);
|
|
189
|
+
console.log(hct); // [200, 45, 80]
|
|
190
|
+
|
|
191
|
+
// HCT to RGB conversion
|
|
192
|
+
const rgb = hctToRgb([200, 45, 80]);
|
|
193
|
+
console.log(rgb); // [64, 196, 255]
|
|
194
|
+
|
|
195
|
+
// Color blending
|
|
196
|
+
const blended = blendInHct(
|
|
197
|
+
[64, 196, 255], // Blue
|
|
198
|
+
[255, 87, 34], // Orange
|
|
199
|
+
'overlay', // Overlay mode
|
|
200
|
+
0.5 // 50% blend
|
|
201
|
+
);
|
|
202
|
+
console.log(blended); // Blended color
|
|
203
|
+
|
|
204
|
+
// Different blend modes
|
|
205
|
+
const multiply = blendInHct([255, 0, 0], [0, 255, 0], 'multiply', 0.5);
|
|
206
|
+
const screen = blendInHct([255, 0, 0], [0, 255, 0], 'screen', 0.5);
|
|
207
|
+
const softLight = blendInHct([255, 0, 0], [0, 255, 0], 'softLight', 0.5);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### extractColorFromImage(image: HTMLImageElement)
|
|
211
|
+
|
|
212
|
+
Extract dominant color from a loaded image element.
|
|
213
|
+
|
|
214
|
+
**Parameters:**
|
|
215
|
+
- `image`: HTMLImageElement - Loaded image element
|
|
216
|
+
|
|
217
|
+
**Returns:**
|
|
218
|
+
- `Promise<string>` - Extracted dominant color (hex format)
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
const image = document.getElementById('myImage');
|
|
222
|
+
extractColorFromImage(image).then(color => {
|
|
223
|
+
console.log('Extracted color:', color);
|
|
224
|
+
// Generate palette from extracted color
|
|
225
|
+
const palette = generate(color, { list: true });
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### extractColorFromFile(file: File)
|
|
230
|
+
|
|
231
|
+
Read image from file object and extract dominant color.
|
|
232
|
+
|
|
233
|
+
**Parameters:**
|
|
234
|
+
- `file`: File - Image file object
|
|
235
|
+
|
|
236
|
+
**Returns:**
|
|
237
|
+
- `Promise<string>` - Extracted dominant color (hex format)
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
// Use in file input event
|
|
241
|
+
document.getElementById('fileInput').addEventListener('change', (event) => {
|
|
242
|
+
const file = event.target.files[0];
|
|
243
|
+
if (file) {
|
|
244
|
+
extractColorFromFile(file).then(color => {
|
|
245
|
+
console.log('Extracted color:', color);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Version History
|
|
252
|
+
|
|
253
|
+
### v0.2.0 (Latest)
|
|
254
|
+
- ✨ Added interface color system functionality
|
|
255
|
+
- ✨ Added HCT color space-based theme blending
|
|
256
|
+
- 📚 Enhanced API documentation and examples
|
|
257
|
+
- 🔧 Optimized code structure and performance
|
|
258
|
+
|
|
259
|
+
### v0.1.1
|
|
260
|
+
- 🐛 Fixed edge cases in color palette generation
|
|
261
|
+
- 📚 Updated documentation and examples
|
|
262
|
+
|
|
263
|
+
### v0.1.0
|
|
264
|
+
- 🎉 Initial release
|
|
265
|
+
- ✨ Color palette generation
|
|
266
|
+
- ✨ Image color extraction
|
package/README.zh-CN.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# ArcoDesign Color
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Aviala Design Color - 一个强大的颜色处理工具库。
|
|
4
4
|
|
|
5
5
|
## 功能概述
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
本库提供四大核心功能:
|
|
8
8
|
|
|
9
9
|
1. **色盘生成**:根据给定颜色通过算法生成包含十个颜色的梯度色板,支持亮色模式和暗色模式。
|
|
10
10
|
2. **图片取色**:从图片中提取主色调,可用于生成与图片匹配的调色板或主题色。
|
|
11
|
+
3. **界面色彩系统**:基于主色生成完整的界面色彩系统,包括语义色彩(成功、警告、错误、信息)。
|
|
12
|
+
4. **主题混合**:基于 HCT 色彩空间的高级主题混合功能,支持多种混合模式。
|
|
11
13
|
|
|
12
14
|
## 安装
|
|
13
15
|
|
|
@@ -17,7 +19,16 @@ npm install @aviala-design/color```
|
|
|
17
19
|
## 基本使用
|
|
18
20
|
|
|
19
21
|
```js
|
|
20
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
generate,
|
|
24
|
+
getPresetColors,
|
|
25
|
+
getRgbStr,
|
|
26
|
+
extractColorFromImage,
|
|
27
|
+
generateInterfaceColorSystem,
|
|
28
|
+
blendInHct,
|
|
29
|
+
rgbToHct,
|
|
30
|
+
hctToRgb
|
|
31
|
+
} from '@aviala-design/color';
|
|
21
32
|
|
|
22
33
|
// 生成色盘
|
|
23
34
|
const colorPalette = generate('#3491FA', { list: true });
|
|
@@ -32,6 +43,17 @@ console.log(arcoblue.primary); // arco蓝的主色
|
|
|
32
43
|
// 获取RGB字符串
|
|
33
44
|
const rgbStr = getRgbStr('#F53F3F');
|
|
34
45
|
console.log(rgbStr); // 245,63,63
|
|
46
|
+
|
|
47
|
+
// 生成界面色彩系统
|
|
48
|
+
const colorSystem = generateInterfaceColorSystem('#3491FA');
|
|
49
|
+
console.log(colorSystem.success); // 成功色
|
|
50
|
+
console.log(colorSystem.warning); // 警告色
|
|
51
|
+
console.log(colorSystem.error); // 错误色
|
|
52
|
+
console.log(colorSystem.info); // 信息色
|
|
53
|
+
|
|
54
|
+
// 主题混合
|
|
55
|
+
const blended = blendInHct([64, 196, 255], [255, 87, 34], 'overlay', 0.5);
|
|
56
|
+
console.log(blended); // 混合后的RGB颜色
|
|
35
57
|
```
|
|
36
58
|
|
|
37
59
|
## API 详解
|
|
@@ -171,6 +193,109 @@ document.getElementById('fileInput').addEventListener('change', (event) => {
|
|
|
171
193
|
});
|
|
172
194
|
```
|
|
173
195
|
|
|
196
|
+
### 界面色彩系统功能
|
|
197
|
+
|
|
198
|
+
#### generateInterfaceColorSystem(primaryColor: string, options?: Object)
|
|
199
|
+
|
|
200
|
+
基于主色生成完整的界面色彩系统,包括语义色彩。
|
|
201
|
+
|
|
202
|
+
**参数:**
|
|
203
|
+
- `primaryColor`: string - 主色,支持十六进制格式(如 '#3491FA')
|
|
204
|
+
- `options`: Object - 可选配置项
|
|
205
|
+
- `successBase`: string - 自定义成功色基础色,默认为绿色
|
|
206
|
+
- `warningBase`: string - 自定义警告色基础色,默认为橙色
|
|
207
|
+
- `errorBase`: string - 自定义错误色基础色,默认为红色
|
|
208
|
+
- `infoBase`: string - 自定义信息色基础色,默认为蓝色
|
|
209
|
+
|
|
210
|
+
**返回值:**
|
|
211
|
+
- `Object` - 包含完整色彩系统的对象
|
|
212
|
+
- `primary`: string[] - 主色色盘(10个颜色)
|
|
213
|
+
- `success`: string[] - 成功色色盘(10个颜色)
|
|
214
|
+
- `warning`: string[] - 警告色色盘(10个颜色)
|
|
215
|
+
- `error`: string[] - 错误色色盘(10个颜色)
|
|
216
|
+
- `info`: string[] - 信息色色盘(10个颜色)
|
|
217
|
+
|
|
218
|
+
**示例:**
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// 生成默认界面色彩系统
|
|
222
|
+
const colorSystem = generateInterfaceColorSystem('#3491FA');
|
|
223
|
+
console.log(colorSystem.primary); // 主色色盘
|
|
224
|
+
console.log(colorSystem.success); // 成功色色盘
|
|
225
|
+
console.log(colorSystem.warning); // 警告色色盘
|
|
226
|
+
console.log(colorSystem.error); // 错误色色盘
|
|
227
|
+
console.log(colorSystem.info); // 信息色色盘
|
|
228
|
+
|
|
229
|
+
// 自定义语义色基础色
|
|
230
|
+
const customColorSystem = generateInterfaceColorSystem('#3491FA', {
|
|
231
|
+
successBase: '#00C853',
|
|
232
|
+
warningBase: '#FF9800',
|
|
233
|
+
errorBase: '#F44336',
|
|
234
|
+
infoBase: '#2196F3'
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 主题混合功能
|
|
239
|
+
|
|
240
|
+
#### rgbToHct(rgb: number[])
|
|
241
|
+
|
|
242
|
+
将 RGB 颜色转换为 HCT 色彩空间。
|
|
243
|
+
|
|
244
|
+
**参数:**
|
|
245
|
+
- `rgb`: number[] - RGB 颜色数组 [r, g, b],范围 0-255
|
|
246
|
+
|
|
247
|
+
**返回值:**
|
|
248
|
+
- `number[]` - HCT 颜色数组 [h, c, t],色相(0-360)、色度(0-100+)、色调(0-100)
|
|
249
|
+
|
|
250
|
+
#### hctToRgb(hct: number[])
|
|
251
|
+
|
|
252
|
+
将 HCT 颜色转换为 RGB 色彩空间。
|
|
253
|
+
|
|
254
|
+
**参数:**
|
|
255
|
+
- `hct`: number[] - HCT 颜色数组 [h, c, t]
|
|
256
|
+
|
|
257
|
+
**返回值:**
|
|
258
|
+
- `number[]` - RGB 颜色数组 [r, g, b],范围 0-255
|
|
259
|
+
|
|
260
|
+
#### blendInHct(color1: number[], color2: number[], mode: string, ratio: number)
|
|
261
|
+
|
|
262
|
+
在 HCT 色彩空间中混合两个颜色。
|
|
263
|
+
|
|
264
|
+
**参数:**
|
|
265
|
+
- `color1`: number[] - 第一个颜色的 RGB 数组
|
|
266
|
+
- `color2`: number[] - 第二个颜色的 RGB 数组
|
|
267
|
+
- `mode`: string - 混合模式,可选值:'multiply'、'screen'、'overlay'、'softLight'
|
|
268
|
+
- `ratio`: number - 混合比例,范围 0-1
|
|
269
|
+
|
|
270
|
+
**返回值:**
|
|
271
|
+
- `number[]` - 混合后的 RGB 颜色数组
|
|
272
|
+
|
|
273
|
+
**示例:**
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
// RGB 到 HCT 转换
|
|
277
|
+
const hct = rgbToHct([64, 196, 255]);
|
|
278
|
+
console.log(hct); // [200, 45, 80]
|
|
279
|
+
|
|
280
|
+
// HCT 到 RGB 转换
|
|
281
|
+
const rgb = hctToRgb([200, 45, 80]);
|
|
282
|
+
console.log(rgb); // [64, 196, 255]
|
|
283
|
+
|
|
284
|
+
// 颜色混合
|
|
285
|
+
const blended = blendInHct(
|
|
286
|
+
[64, 196, 255], // 蓝色
|
|
287
|
+
[255, 87, 34], // 橙色
|
|
288
|
+
'overlay', // 叠加模式
|
|
289
|
+
0.5 // 50% 混合
|
|
290
|
+
);
|
|
291
|
+
console.log(blended); // 混合后的颜色
|
|
292
|
+
|
|
293
|
+
// 不同混合模式示例
|
|
294
|
+
const multiply = blendInHct([255, 0, 0], [0, 255, 0], 'multiply', 0.5);
|
|
295
|
+
const screen = blendInHct([255, 0, 0], [0, 255, 0], 'screen', 0.5);
|
|
296
|
+
const softLight = blendInHct([255, 0, 0], [0, 255, 0], 'softLight', 0.5);
|
|
297
|
+
```
|
|
298
|
+
|
|
174
299
|
## 实现原理
|
|
175
300
|
|
|
176
301
|
### 色盘生成算法
|
|
@@ -190,3 +315,42 @@ document.getElementById('fileInput').addEventListener('change', (event) => {
|
|
|
190
315
|
2. **像素量化**:将RGB颜色空间从256^3种可能的颜色减少到16^3种
|
|
191
316
|
3. **颜色频率统计**:统计每种颜色的出现频率
|
|
192
317
|
4. **主色调提取**:过滤掉灰色和接近白色/黑色的颜色,选择出现频率最高的颜色
|
|
318
|
+
|
|
319
|
+
### 界面色彩系统算法
|
|
320
|
+
|
|
321
|
+
界面色彩系统基于色彩理论和无障碍访问性原则:
|
|
322
|
+
|
|
323
|
+
1. **语义色彩映射**:将功能语义(成功、警告、错误、信息)映射到合适的色相区域
|
|
324
|
+
2. **色彩调和**:确保生成的语义色彩与主色形成和谐的色彩关系
|
|
325
|
+
3. **对比度优化**:自动调整颜色的明度以满足 WCAG 无障碍访问标准
|
|
326
|
+
4. **一致性保证**:所有语义色彩使用相同的饱和度和明度调整算法
|
|
327
|
+
|
|
328
|
+
### 主题混合算法
|
|
329
|
+
|
|
330
|
+
主题混合功能基于 Material Design 3 的 HCT 色彩空间:
|
|
331
|
+
|
|
332
|
+
1. **HCT 色彩空间**:使用色相(Hue)、色度(Chroma)、色调(Tone)三个维度描述颜色
|
|
333
|
+
2. **感知均匀性**:HCT 空间在视觉感知上更加均匀,混合结果更自然
|
|
334
|
+
3. **多种混合模式**:
|
|
335
|
+
- **multiply**: 相乘混合,产生更深的颜色
|
|
336
|
+
- **screen**: 屏幕混合,产生更亮的颜色
|
|
337
|
+
- **overlay**: 叠加混合,结合相乘和屏幕的效果
|
|
338
|
+
- **softLight**: 柔光混合,产生柔和的混合效果
|
|
339
|
+
4. **比例控制**:支持精确的混合比例控制,实现渐进式颜色过渡
|
|
340
|
+
|
|
341
|
+
## 版本历史
|
|
342
|
+
|
|
343
|
+
### v0.2.0 (最新)
|
|
344
|
+
- ✨ 新增界面色彩系统功能
|
|
345
|
+
- ✨ 新增基于 HCT 色彩空间的主题混合功能
|
|
346
|
+
- 📚 完善 API 文档和使用示例
|
|
347
|
+
- 🔧 优化代码结构和性能
|
|
348
|
+
|
|
349
|
+
### v0.1.1
|
|
350
|
+
- 🐛 修复色盘生成的边界情况
|
|
351
|
+
- 📚 更新文档和示例
|
|
352
|
+
|
|
353
|
+
### v0.1.0
|
|
354
|
+
- 🎉 初始版本发布
|
|
355
|
+
- ✨ 色盘生成功能
|
|
356
|
+
- ✨ 图片取色功能
|