@hairy/palette 0.3.3 → 0.3.4
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/LICENSE +1 -1
- package/{index.cjs.js → dist/index.cjs.js} +14 -8
- package/{index.d.ts → dist/index.d.ts} +9 -9
- package/{index.esm.js → dist/index.esm.js} +2 -4
- package/package.json +13 -10
- package/src/index.ts +238 -0
- package/CHANGELOG.md +0 -31
- package/index.cjs.js.map +0 -7
- package/index.esm.js.map +0 -7
- package/index.iife.js +0 -142
- package/index.iife.js.map +0 -7
- package/index.iife.min.js +0 -2
- package/index.iife.min.js.map +0 -7
- package/index.md +0 -84
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-PRESENT
|
|
3
|
+
Copyright (c) 2019-PRESENT Hairyf<https://github.com/hairyf>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -16,12 +17,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
}
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
20
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
29
|
|
|
22
|
-
// index.ts
|
|
23
|
-
var
|
|
24
|
-
__export(
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
25
33
|
blend: () => blend,
|
|
26
34
|
brightness: () => brightness,
|
|
27
35
|
changeAlpha: () => changeAlpha,
|
|
@@ -34,7 +42,7 @@ __export(util_color_exports, {
|
|
|
34
42
|
rgbToHsv: () => rgbToHsv,
|
|
35
43
|
textToRgb: () => textToRgb
|
|
36
44
|
});
|
|
37
|
-
module.exports = __toCommonJS(
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
46
|
var import_colord = require("colord");
|
|
39
47
|
var import_a11y = __toESM(require("colord/plugins/a11y"));
|
|
40
48
|
var import_mix = __toESM(require("colord/plugins/mix"));
|
|
@@ -77,9 +85,8 @@ var brightnessStep2 = 15;
|
|
|
77
85
|
var lightColorCount = 5;
|
|
78
86
|
var darkColorCount = 4;
|
|
79
87
|
function colorPalette(color, index) {
|
|
80
|
-
if (typeof color !== "string" && (!color || color.r === void 0))
|
|
88
|
+
if (typeof color !== "string" && (!color || color.r === void 0))
|
|
81
89
|
throw new TypeError("Expected a string or a {r, g, b} object as color");
|
|
82
|
-
}
|
|
83
90
|
const rgb = typeof color === "string" ? textToRgb(color) : color;
|
|
84
91
|
const oldHsv = (0, import_colord.colord)(rgb).toHsv();
|
|
85
92
|
if (index === 6)
|
|
@@ -144,4 +151,3 @@ function value(hsv, i, isLight) {
|
|
|
144
151
|
rgbToHsv,
|
|
145
152
|
textToRgb
|
|
146
153
|
});
|
|
147
|
-
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as colord from 'colord';
|
|
2
2
|
import { RgbaColor, HsvaColor, AnyColor } from 'colord';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type RGBA = Record<'r' | 'g' | 'b' | 'a', number>;
|
|
5
|
+
type RGB = Record<'r' | 'g' | 'b', number> & {
|
|
6
6
|
a?: number;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
type HexColor = string;
|
|
9
|
+
type HSVA = Record<'h' | 's' | 'v' | 'a', number>;
|
|
10
|
+
type RGBA_TEXT = string;
|
|
11
|
+
type HEX_TEXT = string;
|
|
12
|
+
type HSVA_TEXT = string;
|
|
13
|
+
type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT;
|
|
14
|
+
type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
15
15
|
/**
|
|
16
16
|
* Converts a RGB/A color
|
|
17
17
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// index.ts
|
|
1
|
+
// src/index.ts
|
|
2
2
|
import { colord, extend } from "colord";
|
|
3
3
|
import a11yPlugin from "colord/plugins/a11y";
|
|
4
4
|
import mixPlugin from "colord/plugins/mix";
|
|
@@ -41,9 +41,8 @@ var brightnessStep2 = 15;
|
|
|
41
41
|
var lightColorCount = 5;
|
|
42
42
|
var darkColorCount = 4;
|
|
43
43
|
function colorPalette(color, index) {
|
|
44
|
-
if (typeof color !== "string" && (!color || color.r === void 0))
|
|
44
|
+
if (typeof color !== "string" && (!color || color.r === void 0))
|
|
45
45
|
throw new TypeError("Expected a string or a {r, g, b} object as color");
|
|
46
|
-
}
|
|
47
46
|
const rgb = typeof color === "string" ? textToRgb(color) : color;
|
|
48
47
|
const oldHsv = colord(rgb).toHsv();
|
|
49
48
|
if (index === 6)
|
|
@@ -107,4 +106,3 @@ export {
|
|
|
107
106
|
rgbToHsv,
|
|
108
107
|
textToRgb
|
|
109
108
|
};
|
|
110
|
-
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/palette",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.3.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
5
6
|
"publishConfig": {
|
|
6
|
-
"jsdelivr": "./index.iife.min.js"
|
|
7
|
+
"jsdelivr": "./dist/index.iife.min.js"
|
|
7
8
|
},
|
|
8
|
-
"
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
9
12
|
"dependencies": {
|
|
10
13
|
"colord": "^2.9.3"
|
|
11
14
|
},
|
|
12
15
|
"scripts": {
|
|
13
|
-
"build": "
|
|
16
|
+
"build": "ptsup src/index.ts --dts"
|
|
14
17
|
},
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"module": "./index.esm.js",
|
|
17
|
-
"unpkg": "./index.iife.min.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"module": "./dist/index.esm.js",
|
|
20
|
+
"unpkg": "./dist/index.iife.min.js",
|
|
18
21
|
"exports": {
|
|
19
22
|
".": {
|
|
20
|
-
"import": "./index.esm.js",
|
|
21
|
-
"require": "./index.cjs.js"
|
|
23
|
+
"import": "./dist/index.esm.js",
|
|
24
|
+
"require": "./dist/index.cjs.js"
|
|
22
25
|
},
|
|
23
26
|
"./*": "./*"
|
|
24
27
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/* eslint-disable no-void */
|
|
2
|
+
import type { AnyColor, HsvaColor, RgbaColor } from 'colord'
|
|
3
|
+
import { colord, extend } from 'colord'
|
|
4
|
+
import a11yPlugin from 'colord/plugins/a11y'
|
|
5
|
+
import mixPlugin from 'colord/plugins/mix'
|
|
6
|
+
|
|
7
|
+
extend([a11yPlugin, mixPlugin])
|
|
8
|
+
export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>
|
|
9
|
+
export type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }
|
|
10
|
+
export type HexColor = string
|
|
11
|
+
export type HSVA = Record<'h' | 's' | 'v' | 'a', number>
|
|
12
|
+
|
|
13
|
+
export type RGBA_TEXT = string
|
|
14
|
+
export type HEX_TEXT = string
|
|
15
|
+
export type HSVA_TEXT = string
|
|
16
|
+
export type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT
|
|
17
|
+
export type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts a RGB/A color
|
|
21
|
+
*
|
|
22
|
+
* Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
|
|
23
|
+
*
|
|
24
|
+
* to its HEX/A representation as a
|
|
25
|
+
*
|
|
26
|
+
* String (`#RRGGBB<AA>`).
|
|
27
|
+
*
|
|
28
|
+
* If Alpha channel is present in the original object it will be present also in the output.
|
|
29
|
+
*/
|
|
30
|
+
export function rgbToHex({ r, g, b, a }: RgbaColor): HexColor {
|
|
31
|
+
return colord({ r, g, b, a }).toHex()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Converts a HEX/A color
|
|
36
|
+
*
|
|
37
|
+
* String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)
|
|
38
|
+
*
|
|
39
|
+
* to its RGB/A representation as an
|
|
40
|
+
*
|
|
41
|
+
* Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).
|
|
42
|
+
*
|
|
43
|
+
* If Alpha channel is present in the original object it will be present also in the output.
|
|
44
|
+
*/
|
|
45
|
+
export function hexToRgb(hex: HexColor): RgbaColor {
|
|
46
|
+
return colord(hex).toRgb()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Converts a HEX/A color
|
|
51
|
+
*
|
|
52
|
+
* String (`#RRGGBB<AA>`)
|
|
53
|
+
*
|
|
54
|
+
* to its RGB/A representation as an
|
|
55
|
+
*
|
|
56
|
+
* Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .
|
|
57
|
+
*
|
|
58
|
+
* If Alpha channel is present in the original object it will be present also in the output.
|
|
59
|
+
*/
|
|
60
|
+
export function hsvToRgb({ h, s, v, a }: HsvaColor): RgbaColor {
|
|
61
|
+
return colord({ h, s, v, a }).toRgb()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts a RGB/A color
|
|
66
|
+
*
|
|
67
|
+
* Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
|
|
68
|
+
*
|
|
69
|
+
* to its HSV/A representation as an
|
|
70
|
+
*
|
|
71
|
+
* Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).
|
|
72
|
+
*
|
|
73
|
+
* If Alpha channel is present in the original object it will be present also in the output.
|
|
74
|
+
*/
|
|
75
|
+
export function rgbToHsv({ r, g, b, a }: RgbaColor): HsvaColor {
|
|
76
|
+
return colord({ r, b, g, a }).toHsv()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Converts a HEX/A color
|
|
81
|
+
*
|
|
82
|
+
* String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)
|
|
83
|
+
*
|
|
84
|
+
* to its RGB/A representation as an
|
|
85
|
+
*
|
|
86
|
+
* Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).
|
|
87
|
+
*
|
|
88
|
+
* If Alpha channel is present in the original object it will be present also in the output.
|
|
89
|
+
*/
|
|
90
|
+
export function textToRgb(str: AnyColor): RgbaColor {
|
|
91
|
+
return colord(str).toRgb()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).
|
|
96
|
+
*
|
|
97
|
+
* Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.
|
|
98
|
+
*/
|
|
99
|
+
export function lighten(color: AnyColor, percent: number) {
|
|
100
|
+
return colord(color).lighten(percent).toHex()
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.
|
|
104
|
+
*
|
|
105
|
+
* Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
|
|
106
|
+
*/
|
|
107
|
+
export function luminance(color: AnyColor) {
|
|
108
|
+
return colord(color).luminance()
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.
|
|
112
|
+
*
|
|
113
|
+
* Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
|
|
114
|
+
*/
|
|
115
|
+
export function brightness(color: AnyColor) {
|
|
116
|
+
return colord(color).brightness()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.
|
|
121
|
+
*
|
|
122
|
+
* Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.
|
|
123
|
+
*/
|
|
124
|
+
export function blend(fgColor: AnyColor, bgColor: AnyColor) {
|
|
125
|
+
return colord(fgColor).mix(bgColor)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Change color transparency
|
|
130
|
+
*/
|
|
131
|
+
export function changeAlpha(color: COLOR, alpha: number) {
|
|
132
|
+
return colord(color).alpha(alpha).toHex()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const hueStep = 2
|
|
136
|
+
const saturationStep = 16
|
|
137
|
+
const saturationStep2 = 5
|
|
138
|
+
const brightnessStep1 = 5
|
|
139
|
+
const brightnessStep2 = 15
|
|
140
|
+
const lightColorCount = 5
|
|
141
|
+
const darkColorCount = 4
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 根据颜色获取调色板颜色(从左至右颜色从浅到深,6为主色号)
|
|
145
|
+
* @param color - 颜色
|
|
146
|
+
* @param index - 调色板的对应的色号(6为主色号)
|
|
147
|
+
* @description 算法实现从ant-design调色板算法中借鉴 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less
|
|
148
|
+
*/
|
|
149
|
+
export function colorPalette(color: string | RgbaColor, index: PALETTE_INDEXES) {
|
|
150
|
+
if (typeof color !== 'string' && (!color || color.r === void 0))
|
|
151
|
+
throw new TypeError('Expected a string or a {r, g, b} object as color')
|
|
152
|
+
|
|
153
|
+
const rgb = typeof color === 'string' ? textToRgb(color) : color
|
|
154
|
+
const oldHsv = colord(rgb).toHsv()
|
|
155
|
+
|
|
156
|
+
if (index === 6)
|
|
157
|
+
return rgbToHex(rgb)
|
|
158
|
+
|
|
159
|
+
const light = index < 6
|
|
160
|
+
const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1
|
|
161
|
+
const newHsv = {
|
|
162
|
+
h: hue(oldHsv, i, light),
|
|
163
|
+
s: saturation(oldHsv, i, light),
|
|
164
|
+
v: value(oldHsv, i, light),
|
|
165
|
+
a: oldHsv.a,
|
|
166
|
+
}
|
|
167
|
+
return colord(newHsv).toHex()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 获取色相渐变
|
|
172
|
+
* @param hsv - hsv格式颜色值
|
|
173
|
+
* @param i - 与6的相对距离
|
|
174
|
+
* @param isLight - 是否是亮颜色
|
|
175
|
+
*/
|
|
176
|
+
function hue(hsv: HsvaColor, i: number, isLight: boolean) {
|
|
177
|
+
let hue: number
|
|
178
|
+
if (hsv.h >= 60 && hsv.h <= 240) {
|
|
179
|
+
// 冷色调
|
|
180
|
+
// 减淡变亮 色相顺时针旋转 更暖
|
|
181
|
+
// 加深变暗 色相逆时针旋转 更冷
|
|
182
|
+
hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// 暖色调
|
|
186
|
+
// 减淡变亮 色相逆时针旋转 更暖
|
|
187
|
+
// 加深变暗 色相顺时针旋转 更冷
|
|
188
|
+
hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i
|
|
189
|
+
}
|
|
190
|
+
if (hue < 0)
|
|
191
|
+
hue += 360
|
|
192
|
+
else if (hue >= 360)
|
|
193
|
+
hue -= 360
|
|
194
|
+
|
|
195
|
+
return hue
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 获取饱和度渐变
|
|
200
|
+
* @param hsv - hsv格式颜色值
|
|
201
|
+
* @param i - 与6的相对距离
|
|
202
|
+
* @param isLight - 是否是亮颜色
|
|
203
|
+
*/
|
|
204
|
+
function saturation(hsv: HsvaColor, i: number, isLight: boolean) {
|
|
205
|
+
let saturation: number
|
|
206
|
+
if (isLight)
|
|
207
|
+
saturation = hsv.s - saturationStep * i
|
|
208
|
+
else if (i === darkColorCount)
|
|
209
|
+
saturation = hsv.s + saturationStep
|
|
210
|
+
else saturation = hsv.s + saturationStep2 * i
|
|
211
|
+
|
|
212
|
+
if (saturation > 100)
|
|
213
|
+
saturation = 100
|
|
214
|
+
|
|
215
|
+
if (isLight && i === lightColorCount && saturation > 10)
|
|
216
|
+
saturation = 10
|
|
217
|
+
|
|
218
|
+
if (saturation < 6)
|
|
219
|
+
saturation = 6
|
|
220
|
+
|
|
221
|
+
return saturation
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 获取明度渐变
|
|
226
|
+
* @param hsv - hsv格式颜色值
|
|
227
|
+
* @param i - 与6的相对距离
|
|
228
|
+
* @param isLight - 是否是亮颜色
|
|
229
|
+
*/
|
|
230
|
+
function value(hsv: HsvaColor, i: number, isLight: boolean) {
|
|
231
|
+
let value: number
|
|
232
|
+
value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i
|
|
233
|
+
|
|
234
|
+
if (value > 100)
|
|
235
|
+
value = 100
|
|
236
|
+
|
|
237
|
+
return value
|
|
238
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# @hairy/palette
|
|
2
|
-
|
|
3
|
-
## 0.3.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- chore: update type error
|
|
8
|
-
|
|
9
|
-
## 0.3.1
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- fix: change alpha value error
|
|
14
|
-
|
|
15
|
-
## 0.3.0
|
|
16
|
-
|
|
17
|
-
### Minor Changes
|
|
18
|
-
|
|
19
|
-
- feat(alpha|palette): add palette and change alpha func
|
|
20
|
-
|
|
21
|
-
## 0.2.0
|
|
22
|
-
|
|
23
|
-
### Minor Changes
|
|
24
|
-
|
|
25
|
-
- fix dist not being packaged
|
|
26
|
-
|
|
27
|
-
## 0.1.0
|
|
28
|
-
|
|
29
|
-
### Minor Changes
|
|
30
|
-
|
|
31
|
-
- f1a05f4: hairy v2 public package publish all
|
package/index.cjs.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../index.ts"],
|
|
4
|
-
"sourcesContent": ["import { colord, extend, AnyColor, RgbaColor, HsvaColor } from 'colord'\r\nimport a11yPlugin from 'colord/plugins/a11y'\r\nimport mixPlugin from 'colord/plugins/mix'\r\n\r\nextend([a11yPlugin, mixPlugin])\r\nexport type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HexColor = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RgbaColor): HexColor {\r\n return colord({ r, g, b, a }).toHex()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HexColor): RgbaColor {\r\n return colord(hex).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HsvaColor): RgbaColor {\r\n return colord({ h, s, v, a }).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RgbaColor): HsvaColor {\r\n return colord({ r, b, g, a }).toHsv()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: AnyColor): RgbaColor {\r\n return colord(str).toRgb()\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: AnyColor, percent: number) {\r\n return colord(color).lighten(percent).toHex()\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminance(color: AnyColor) {\r\n return colord(color).luminance()\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: AnyColor) {\r\n return colord(color).brightness()\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.\r\n */\r\nexport function blend(fgColor: AnyColor, bgColor: AnyColor) {\r\n return colord(fgColor).mix(bgColor)\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n return colord(color).alpha(alpha).toHex()\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: string | RgbaColor, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = colord(rgb).toHsv()\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n return colord(newHsv).toHex()\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/index.esm.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../index.ts"],
|
|
4
|
-
"sourcesContent": ["import { colord, extend, AnyColor, RgbaColor, HsvaColor } from 'colord'\r\nimport a11yPlugin from 'colord/plugins/a11y'\r\nimport mixPlugin from 'colord/plugins/mix'\r\n\r\nextend([a11yPlugin, mixPlugin])\r\nexport type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HexColor = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RgbaColor): HexColor {\r\n return colord({ r, g, b, a }).toHex()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HexColor): RgbaColor {\r\n return colord(hex).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HsvaColor): RgbaColor {\r\n return colord({ h, s, v, a }).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RgbaColor): HsvaColor {\r\n return colord({ r, b, g, a }).toHsv()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: AnyColor): RgbaColor {\r\n return colord(str).toRgb()\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: AnyColor, percent: number) {\r\n return colord(color).lighten(percent).toHex()\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminance(color: AnyColor) {\r\n return colord(color).luminance()\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: AnyColor) {\r\n return colord(color).brightness()\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.\r\n */\r\nexport function blend(fgColor: AnyColor, bgColor: AnyColor) {\r\n return colord(fgColor).mix(bgColor)\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n return colord(color).alpha(alpha).toHex()\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: string | RgbaColor, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = colord(rgb).toHsv()\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n return colord(newHsv).toHex()\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/index.iife.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
var HairyPalette = (() => {
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined")
|
|
12
|
-
return require.apply(this, arguments);
|
|
13
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
-
});
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
-
for (let key of __getOwnPropNames(from))
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// index.ts
|
|
31
|
-
var util_color_exports = {};
|
|
32
|
-
__export(util_color_exports, {
|
|
33
|
-
blend: () => blend,
|
|
34
|
-
brightness: () => brightness,
|
|
35
|
-
changeAlpha: () => changeAlpha,
|
|
36
|
-
colorPalette: () => colorPalette,
|
|
37
|
-
hexToRgb: () => hexToRgb,
|
|
38
|
-
hsvToRgb: () => hsvToRgb,
|
|
39
|
-
lighten: () => lighten,
|
|
40
|
-
luminance: () => luminance,
|
|
41
|
-
rgbToHex: () => rgbToHex,
|
|
42
|
-
rgbToHsv: () => rgbToHsv,
|
|
43
|
-
textToRgb: () => textToRgb
|
|
44
|
-
});
|
|
45
|
-
var import_colord = __require("colord");
|
|
46
|
-
var import_a11y = __toESM(__require("colord/plugins/a11y"));
|
|
47
|
-
var import_mix = __toESM(__require("colord/plugins/mix"));
|
|
48
|
-
(0, import_colord.extend)([import_a11y.default, import_mix.default]);
|
|
49
|
-
function rgbToHex({ r, g, b, a }) {
|
|
50
|
-
return (0, import_colord.colord)({ r, g, b, a }).toHex();
|
|
51
|
-
}
|
|
52
|
-
function hexToRgb(hex) {
|
|
53
|
-
return (0, import_colord.colord)(hex).toRgb();
|
|
54
|
-
}
|
|
55
|
-
function hsvToRgb({ h, s, v, a }) {
|
|
56
|
-
return (0, import_colord.colord)({ h, s, v, a }).toRgb();
|
|
57
|
-
}
|
|
58
|
-
function rgbToHsv({ r, g, b, a }) {
|
|
59
|
-
return (0, import_colord.colord)({ r, b, g, a }).toHsv();
|
|
60
|
-
}
|
|
61
|
-
function textToRgb(str) {
|
|
62
|
-
return (0, import_colord.colord)(str).toRgb();
|
|
63
|
-
}
|
|
64
|
-
function lighten(color, percent) {
|
|
65
|
-
return (0, import_colord.colord)(color).lighten(percent).toHex();
|
|
66
|
-
}
|
|
67
|
-
function luminance(color) {
|
|
68
|
-
return (0, import_colord.colord)(color).luminance();
|
|
69
|
-
}
|
|
70
|
-
function brightness(color) {
|
|
71
|
-
return (0, import_colord.colord)(color).brightness();
|
|
72
|
-
}
|
|
73
|
-
function blend(fgColor, bgColor) {
|
|
74
|
-
return (0, import_colord.colord)(fgColor).mix(bgColor);
|
|
75
|
-
}
|
|
76
|
-
function changeAlpha(color, alpha) {
|
|
77
|
-
return (0, import_colord.colord)(color).alpha(alpha).toHex();
|
|
78
|
-
}
|
|
79
|
-
var hueStep = 2;
|
|
80
|
-
var saturationStep = 16;
|
|
81
|
-
var saturationStep2 = 5;
|
|
82
|
-
var brightnessStep1 = 5;
|
|
83
|
-
var brightnessStep2 = 15;
|
|
84
|
-
var lightColorCount = 5;
|
|
85
|
-
var darkColorCount = 4;
|
|
86
|
-
function colorPalette(color, index) {
|
|
87
|
-
if (typeof color !== "string" && (!color || color.r === void 0)) {
|
|
88
|
-
throw new TypeError("Expected a string or a {r, g, b} object as color");
|
|
89
|
-
}
|
|
90
|
-
const rgb = typeof color === "string" ? textToRgb(color) : color;
|
|
91
|
-
const oldHsv = (0, import_colord.colord)(rgb).toHsv();
|
|
92
|
-
if (index === 6)
|
|
93
|
-
return rgbToHex(rgb);
|
|
94
|
-
const light = index < 6;
|
|
95
|
-
const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
|
|
96
|
-
const newHsv = {
|
|
97
|
-
h: hue(oldHsv, i, light),
|
|
98
|
-
s: saturation(oldHsv, i, light),
|
|
99
|
-
v: value(oldHsv, i, light),
|
|
100
|
-
a: oldHsv.a
|
|
101
|
-
};
|
|
102
|
-
return (0, import_colord.colord)(newHsv).toHex();
|
|
103
|
-
}
|
|
104
|
-
function hue(hsv, i, isLight) {
|
|
105
|
-
let hue2;
|
|
106
|
-
if (hsv.h >= 60 && hsv.h <= 240) {
|
|
107
|
-
hue2 = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
|
|
108
|
-
} else {
|
|
109
|
-
hue2 = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
|
|
110
|
-
}
|
|
111
|
-
if (hue2 < 0)
|
|
112
|
-
hue2 += 360;
|
|
113
|
-
else if (hue2 >= 360)
|
|
114
|
-
hue2 -= 360;
|
|
115
|
-
return hue2;
|
|
116
|
-
}
|
|
117
|
-
function saturation(hsv, i, isLight) {
|
|
118
|
-
let saturation2;
|
|
119
|
-
if (isLight)
|
|
120
|
-
saturation2 = hsv.s - saturationStep * i;
|
|
121
|
-
else if (i === darkColorCount)
|
|
122
|
-
saturation2 = hsv.s + saturationStep;
|
|
123
|
-
else
|
|
124
|
-
saturation2 = hsv.s + saturationStep2 * i;
|
|
125
|
-
if (saturation2 > 100)
|
|
126
|
-
saturation2 = 100;
|
|
127
|
-
if (isLight && i === lightColorCount && saturation2 > 10)
|
|
128
|
-
saturation2 = 10;
|
|
129
|
-
if (saturation2 < 6)
|
|
130
|
-
saturation2 = 6;
|
|
131
|
-
return saturation2;
|
|
132
|
-
}
|
|
133
|
-
function value(hsv, i, isLight) {
|
|
134
|
-
let value2;
|
|
135
|
-
value2 = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
|
|
136
|
-
if (value2 > 100)
|
|
137
|
-
value2 = 100;
|
|
138
|
-
return value2;
|
|
139
|
-
}
|
|
140
|
-
return __toCommonJS(util_color_exports);
|
|
141
|
-
})();
|
|
142
|
-
//# sourceMappingURL=index.iife.js.map
|
package/index.iife.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../index.ts"],
|
|
4
|
-
"sourcesContent": ["import { colord, extend, AnyColor, RgbaColor, HsvaColor } from 'colord'\r\nimport a11yPlugin from 'colord/plugins/a11y'\r\nimport mixPlugin from 'colord/plugins/mix'\r\n\r\nextend([a11yPlugin, mixPlugin])\r\nexport type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HexColor = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RgbaColor): HexColor {\r\n return colord({ r, g, b, a }).toHex()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HexColor): RgbaColor {\r\n return colord(hex).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HsvaColor): RgbaColor {\r\n return colord({ h, s, v, a }).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RgbaColor): HsvaColor {\r\n return colord({ r, b, g, a }).toHsv()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: AnyColor): RgbaColor {\r\n return colord(str).toRgb()\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: AnyColor, percent: number) {\r\n return colord(color).lighten(percent).toHex()\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminance(color: AnyColor) {\r\n return colord(color).luminance()\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: AnyColor) {\r\n return colord(color).brightness()\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.\r\n */\r\nexport function blend(fgColor: AnyColor, bgColor: AnyColor) {\r\n return colord(fgColor).mix(bgColor)\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n return colord(color).alpha(alpha).toHex()\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: string | RgbaColor, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = colord(rgb).toHsv()\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n return colord(newHsv).toHex()\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/index.iife.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var HairyPalette=(()=>{var R=Object.create;var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var p=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var h=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},b=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of y(t))!A.call(o,u)&&u!==e&&l(o,u,{get:()=>t[u],enumerable:!(r=T(t,u))||r.enumerable});return o};var g=(o,t,e)=>(e=o!=null?R(E(o)):{},b(t||!o||!o.__esModule?l(e,"default",{value:o,enumerable:!0}):e,o)),v=o=>b(l({},"__esModule",{value:!0}),o);var q={};h(q,{blend:()=>G,brightness:()=>B,changeAlpha:()=>O,colorPalette:()=>L,hexToRgb:()=>S,hsvToRgb:()=>X,lighten:()=>d,luminance:()=>P,rgbToHex:()=>C,rgbToHsv:()=>_,textToRgb:()=>H});var n=p("colord"),x=g(p("colord/plugins/a11y")),f=g(p("colord/plugins/mix"));(0,n.extend)([x.default,f.default]);function C({r:o,g:t,b:e,a:r}){return(0,n.colord)({r:o,g:t,b:e,a:r}).toHex()}function S(o){return(0,n.colord)(o).toRgb()}function X({h:o,s:t,v:e,a:r}){return(0,n.colord)({h:o,s:t,v:e,a:r}).toRgb()}function _({r:o,g:t,b:e,a:r}){return(0,n.colord)({r:o,b:e,g:t,a:r}).toHsv()}function H(o){return(0,n.colord)(o).toRgb()}function d(o,t){return(0,n.colord)(o).lighten(t).toHex()}function P(o){return(0,n.colord)(o).luminance()}function B(o){return(0,n.colord)(o).brightness()}function G(o,t){return(0,n.colord)(o).mix(t)}function O(o,t){return(0,n.colord)(o).alpha(t).toHex()}var s=2,c=16,w=5,V=5,D=15,i=5,I=4;function L(o,t){if(typeof o!="string"&&(!o||o.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let e=typeof o=="string"?H(o):o,r=(0,n.colord)(e).toHsv();if(t===6)return C(e);let u=t<6,a=u?i+1-t:t-i-1,m={h:N(r,a,u),s:j(r,a,u),v:k(r,a,u),a:r.a};return(0,n.colord)(m).toHex()}function N(o,t,e){let r;return o.h>=60&&o.h<=240?r=e?o.h-s*t:o.h+s*t:r=e?o.h+s*t:o.h-s*t,r<0?r+=360:r>=360&&(r-=360),r}function j(o,t,e){let r;return e?r=o.s-c*t:t===I?r=o.s+c:r=o.s+w*t,r>100&&(r=100),e&&t===i&&r>10&&(r=10),r<6&&(r=6),r}function k(o,t,e){let r;return r=e?o.v+V*t:o.v-D*t,r>100&&(r=100),r}return v(q);})();
|
|
2
|
-
//# sourceMappingURL=index.iife.min.js.map
|
package/index.iife.min.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../index.ts"],
|
|
4
|
-
"sourcesContent": ["import { colord, extend, AnyColor, RgbaColor, HsvaColor } from 'colord'\r\nimport a11yPlugin from 'colord/plugins/a11y'\r\nimport mixPlugin from 'colord/plugins/mix'\r\n\r\nextend([a11yPlugin, mixPlugin])\r\nexport type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HexColor = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RgbaColor): HexColor {\r\n return colord({ r, g, b, a }).toHex()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HexColor): RgbaColor {\r\n return colord(hex).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HsvaColor): RgbaColor {\r\n return colord({ h, s, v, a }).toRgb()\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RgbaColor): HsvaColor {\r\n return colord({ r, b, g, a }).toHsv()\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: AnyColor): RgbaColor {\r\n return colord(str).toRgb()\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: AnyColor, percent: number) {\r\n return colord(color).lighten(percent).toHex()\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminance(color: AnyColor) {\r\n return colord(color).luminance()\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: AnyColor) {\r\n return colord(color).brightness()\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.\r\n */\r\nexport function blend(fgColor: AnyColor, bgColor: AnyColor) {\r\n return colord(fgColor).mix(bgColor)\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n return colord(color).alpha(alpha).toHex()\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: string | RgbaColor, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = colord(rgb).toHsv()\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n return colord(newHsv).toHex()\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HsvaColor, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
|
|
5
|
-
"mappings": "q2BAAA,kMAA+D,YAC/D,EAAuB,4BACvB,EAAsB,2BAEtB,aAAO,CAAC,UAAY,SAAS,CAAC,EAuBvB,WAAkB,CAAE,IAAG,IAAG,IAAG,KAA0B,CAC5D,MAAO,aAAO,CAAE,IAAG,IAAG,IAAG,GAAE,CAAC,EAAE,MAAM,CACtC,CAaO,WAAkB,EAA0B,CACjD,MAAO,aAAO,CAAG,EAAE,MAAM,CAC3B,CAaO,WAAkB,CAAE,IAAG,IAAG,IAAG,KAA2B,CAC7D,MAAO,aAAO,CAAE,IAAG,IAAG,IAAG,GAAE,CAAC,EAAE,MAAM,CACtC,CAaO,WAAkB,CAAE,IAAG,IAAG,IAAG,KAA2B,CAC7D,MAAO,aAAO,CAAE,IAAG,IAAG,IAAG,GAAE,CAAC,EAAE,MAAM,CACtC,CAaO,WAAmB,EAA0B,CAClD,MAAO,aAAO,CAAG,EAAE,MAAM,CAC3B,CAOO,WAAiB,EAAiB,EAAiB,CACxD,MAAO,aAAO,CAAK,EAAE,QAAQ,CAAO,EAAE,MAAM,CAC9C,CAMO,WAAmB,EAAiB,CACzC,MAAO,aAAO,CAAK,EAAE,UAAU,CACjC,CAMO,WAAoB,EAAiB,CAC1C,MAAO,aAAO,CAAK,EAAE,WAAW,CAClC,CAOO,WAAe,EAAmB,EAAmB,CAC1D,MAAO,aAAO,CAAO,EAAE,IAAI,CAAO,CACpC,CAKO,WAAqB,EAAc,EAAe,CACvD,MAAO,aAAO,CAAK,EAAE,MAAM,CAAK,EAAE,MAAM,CAC1C,CAEA,GAAM,GAAU,EACV,EAAiB,GACjB,EAAkB,EAClB,EAAkB,EAClB,EAAkB,GAClB,EAAkB,EAClB,EAAiB,EAQhB,WAAsB,EAA2B,EAAwB,CAC9E,GAAI,MAAO,IAAU,UAAa,EAAC,GAAS,EAAM,IAAM,QACtD,KAAM,IAAI,WAAU,kDAAkD,EAExE,GAAM,GAAM,MAAO,IAAU,SAAW,EAAU,CAAK,EAAI,EACrD,EAAS,aAAO,CAAG,EAAE,MAAM,EAEjC,GAAI,IAAU,EAAG,MAAO,GAAS,CAAG,EAEpC,GAAM,GAAQ,EAAQ,EAChB,EAAI,EAAQ,EAAkB,EAAI,EAAQ,EAAQ,EAAkB,EACpE,EAAS,CACb,EAAG,EAAI,EAAQ,EAAG,CAAK,EACvB,EAAG,EAAW,EAAQ,EAAG,CAAK,EAC9B,EAAG,EAAM,EAAQ,EAAG,CAAK,EACzB,EAAG,EAAO,CACZ,EACA,MAAO,aAAO,CAAM,EAAE,MAAM,CAC9B,CAQA,WAAa,EAAgB,EAAW,EAAkB,CACxD,GAAI,GACJ,MAAI,GAAI,GAAK,IAAM,EAAI,GAAK,IAI1B,EAAM,EAAU,EAAI,EAAI,EAAU,EAAI,EAAI,EAAI,EAAU,EAKxD,EAAM,EAAU,EAAI,EAAI,EAAU,EAAI,EAAI,EAAI,EAAU,EAE1D,AAAI,EAAM,EAAG,GAAO,IACX,GAAO,KAAK,IAAO,KAErB,CACT,CAQA,WAAoB,EAAgB,EAAW,EAAkB,CAC/D,GAAI,GACJ,MAAI,GAAS,EAAa,EAAI,EAAI,EAAiB,EAC9C,AAAI,IAAM,EAAgB,EAAa,EAAI,EAAI,EAC/C,EAAa,EAAI,EAAI,EAAkB,EAExC,EAAa,KAAK,GAAa,KAE/B,GAAW,IAAM,GAAmB,EAAa,IAAI,GAAa,IAElE,EAAa,GAAG,GAAa,GAE1B,CACT,CAQA,WAAe,EAAgB,EAAW,EAAkB,CAC1D,GAAI,GACJ,SAAQ,EAAU,EAAI,EAAI,EAAkB,EAAI,EAAI,EAAI,EAAkB,EAEtE,EAAQ,KAAK,GAAQ,KAElB,CACT",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/index.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
category: 'Universal Utils'
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Color Palette
|
|
6
|
-
|
|
7
|
-
颜色的处理、转换、计算
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
pnpm add -D @hairy/palette
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage Functions
|
|
16
|
-
|
|
17
|
-
### rgbToHex({ r, g, b, a })
|
|
18
|
-
Converts a RGB/A color
|
|
19
|
-
|
|
20
|
-
Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
|
|
21
|
-
|
|
22
|
-
to its HEX/A representation as a
|
|
23
|
-
|
|
24
|
-
If Alpha channel is present in the original object it will be present also in the output.
|
|
25
|
-
|
|
26
|
-
### hexToRgb(hex)
|
|
27
|
-
Converts a HEX/A color
|
|
28
|
-
|
|
29
|
-
String (`#RRGGBB<AA>`)
|
|
30
|
-
|
|
31
|
-
to its RGB/A representation as an
|
|
32
|
-
|
|
33
|
-
Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .
|
|
34
|
-
|
|
35
|
-
If Alpha channel is present in the original object it will be present also in the output.
|
|
36
|
-
|
|
37
|
-
### rgbToHsv({ r, g, b, a })
|
|
38
|
-
Converts a RGB/A color
|
|
39
|
-
|
|
40
|
-
Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
|
|
41
|
-
|
|
42
|
-
to its HSV/A representation as an
|
|
43
|
-
|
|
44
|
-
Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).
|
|
45
|
-
|
|
46
|
-
If Alpha channel is present in the original object it will be present also in the output.
|
|
47
|
-
|
|
48
|
-
### textToRgb(str)
|
|
49
|
-
Converts a HEX/A color
|
|
50
|
-
|
|
51
|
-
String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)
|
|
52
|
-
|
|
53
|
-
to its RGB/A representation as an
|
|
54
|
-
|
|
55
|
-
Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).
|
|
56
|
-
|
|
57
|
-
If Alpha channel is present in the original object it will be present also in the output.
|
|
58
|
-
|
|
59
|
-
### lighten(str, percent)
|
|
60
|
-
Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).
|
|
61
|
-
|
|
62
|
-
Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.
|
|
63
|
-
|
|
64
|
-
### luminosity(str)
|
|
65
|
-
Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.
|
|
66
|
-
|
|
67
|
-
Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
|
|
68
|
-
|
|
69
|
-
### brightness(str)
|
|
70
|
-
Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.
|
|
71
|
-
|
|
72
|
-
Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
|
|
73
|
-
|
|
74
|
-
### blend(fgColor, bgColor)
|
|
75
|
-
Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.
|
|
76
|
-
|
|
77
|
-
Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.
|
|
78
|
-
|
|
79
|
-
### changeAlpha(color, offset)
|
|
80
|
-
Increments or decrements the alpha of a string color.
|
|
81
|
-
|
|
82
|
-
Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.
|
|
83
|
-
|
|
84
|
-
###
|