@cloudbase/cals 1.0.58-alpha.0 → 1.0.58-alpha.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/lib/utils/color-generator/core.d.ts +52 -0
- package/lib/utils/color-generator/core.d.ts.map +1 -0
- package/lib/utils/color-generator/core.js +63 -0
- package/lib/utils/color-generator/generate.d.ts +67 -0
- package/lib/utils/color-generator/generate.d.ts.map +1 -0
- package/lib/utils/color-generator/generate.js +100 -0
- package/lib/utils/color-generator/utils.d.ts +15 -0
- package/lib/utils/color-generator/utils.d.ts.map +1 -0
- package/lib/utils/color-generator/utils.js +38 -0
- package/lib/utils/dts/auto-generated.d.ts +1 -1
- package/lib/utils/dts/auto-generated.d.ts.map +1 -1
- package/lib/utils/dts/auto-generated.js +0 -6
- package/lib/utils/dts/index.d.ts +0 -3
- package/lib/utils/dts/index.d.ts.map +1 -1
- package/lib/utils/dts/index.js +2 -55
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +4 -1
- package/package.json +3 -2
- package/lib/utils/version-migrations/common.d.ts +0 -5
- package/lib/utils/version-migrations/common.d.ts.map +0 -1
- package/lib/utils/version-migrations/common.js +0 -29
- package/lib/utils/version-migrations/version4.d.ts +0 -3
- package/lib/utils/version-migrations/version4.d.ts.map +0 -1
- package/lib/utils/version-migrations/version4.js +0 -199
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
interface HSV {
|
|
2
|
+
h: number;
|
|
3
|
+
s: number;
|
|
4
|
+
v: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 获取色相
|
|
8
|
+
* @param hsv 主色 hsv
|
|
9
|
+
* @param i index
|
|
10
|
+
* @returns 色相
|
|
11
|
+
*/
|
|
12
|
+
export declare const getHue: (hsv: HSV, i: number, { isTop, hueStep, }: {
|
|
13
|
+
/** 是否为主色前(主色前为浅色)? */
|
|
14
|
+
isTop: boolean;
|
|
15
|
+
/** 色相阶梯 */
|
|
16
|
+
hueStep: number;
|
|
17
|
+
}) => number;
|
|
18
|
+
/**
|
|
19
|
+
* 获取饱和度
|
|
20
|
+
* 1-10 饱和度变化 => 饱和度从小到大
|
|
21
|
+
* @param hsv 主色 hsv
|
|
22
|
+
* @param i index
|
|
23
|
+
* @returns 饱和度
|
|
24
|
+
*/
|
|
25
|
+
export declare const getSaturation: (hsv: HSV, i: number, { isTop, topColorCount, topSaturationStep, bottomSaturationStep, }: {
|
|
26
|
+
/** 是否为主色前(主色前为浅色)? */
|
|
27
|
+
isTop: boolean;
|
|
28
|
+
/** 显示在主色前面的颜色个数 */
|
|
29
|
+
topColorCount: number;
|
|
30
|
+
/** 饱和度阶梯(主色前) */
|
|
31
|
+
topSaturationStep: number;
|
|
32
|
+
/** 饱和度阶梯(主色后) */
|
|
33
|
+
bottomSaturationStep: number;
|
|
34
|
+
}) => number;
|
|
35
|
+
/**
|
|
36
|
+
* 获取亮度
|
|
37
|
+
* HSV 中 V 控制纯色中混入黑色的量,量越大,黑色越少,亮度越高
|
|
38
|
+
* 1-10 亮度变化 => 亮度从大到小 => 亮度越来越小
|
|
39
|
+
* @param hsv 主色 hsv
|
|
40
|
+
* @param i index
|
|
41
|
+
* @returns 亮度
|
|
42
|
+
*/
|
|
43
|
+
export declare const getBrightness: (hsv: HSV, i: number, { isTop, topBrightnessStep, bottomBrightnessStep, }: {
|
|
44
|
+
/** 是否为主色前(主色前为浅色)? */
|
|
45
|
+
isTop: boolean;
|
|
46
|
+
/** 亮度阶梯(主色前) */
|
|
47
|
+
topBrightnessStep: number;
|
|
48
|
+
/** 亮度阶梯(主色后) */
|
|
49
|
+
bottomBrightnessStep: number;
|
|
50
|
+
}) => number;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/utils/color-generator/core.ts"],"names":[],"mappings":"AAAA,UAAU,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,QACZ,GAAG,KACL,MAAM;IAKP,sBAAsB;WACf,OAAO;IAEd,WAAW;aACF,MAAM;YAqBlB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,QACnB,GAAG,KACL,MAAM;IAOP,sBAAsB;WACf,OAAO;IAEd,mBAAmB;mBACJ,MAAM;IAErB,iBAAiB;uBACE,MAAM;IAEzB,iBAAiB;0BACK,MAAM;YAiB/B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QACnB,GAAG,KACL,MAAM;IAMP,sBAAsB;WACf,OAAO;IAEd,gBAAgB;uBACG,MAAM;IAEzB,gBAAgB;0BACM,MAAM;YAO/B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrightness = exports.getSaturation = exports.getHue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 获取色相
|
|
6
|
+
* @param hsv 主色 hsv
|
|
7
|
+
* @param i index
|
|
8
|
+
* @returns 色相
|
|
9
|
+
*/
|
|
10
|
+
const getHue = (hsv, i, { isTop, hueStep, }) => {
|
|
11
|
+
let hue;
|
|
12
|
+
// H: [60, 240] 为暖色调,其他为冷色调
|
|
13
|
+
if (Math.round(hsv.h) >= 60 && Math.round(hsv.h) <= 240) {
|
|
14
|
+
// 主色为冷色调
|
|
15
|
+
// 1-10 色相变化 => 色相从小到大 => 色相逆时针旋转 => 更冷
|
|
16
|
+
hue = isTop ? Math.round(hsv.h) - hueStep * i : Math.round(hsv.h) + hueStep * i;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// 主色为暖色调
|
|
20
|
+
// 1-10 色相变化 => 色相从大到小 => 色相顺时针旋转 => 更暖
|
|
21
|
+
hue = isTop ? Math.round(hsv.h) + hueStep * i : Math.round(hsv.h) - hueStep * i;
|
|
22
|
+
}
|
|
23
|
+
if (hue < 0 || hue >= 360) {
|
|
24
|
+
hue = Math.abs(Math.abs(hue) - 360);
|
|
25
|
+
}
|
|
26
|
+
return hue;
|
|
27
|
+
};
|
|
28
|
+
exports.getHue = getHue;
|
|
29
|
+
/**
|
|
30
|
+
* 获取饱和度
|
|
31
|
+
* 1-10 饱和度变化 => 饱和度从小到大
|
|
32
|
+
* @param hsv 主色 hsv
|
|
33
|
+
* @param i index
|
|
34
|
+
* @returns 饱和度
|
|
35
|
+
*/
|
|
36
|
+
const getSaturation = (hsv, i, { isTop, topColorCount, topSaturationStep, bottomSaturationStep, }) => {
|
|
37
|
+
// 不改变灰色的饱和度
|
|
38
|
+
if (hsv.h === 0 && hsv.s === 0) {
|
|
39
|
+
return hsv.s;
|
|
40
|
+
}
|
|
41
|
+
let saturation = isTop ? hsv.s - topSaturationStep * i : hsv.s + bottomSaturationStep * i;
|
|
42
|
+
saturation = Math.max(0.06, Math.min(saturation, 1));
|
|
43
|
+
// 主色前 1 个饱和度限制在 0.06-0.1 之间
|
|
44
|
+
if (isTop && i === topColorCount && saturation > 0.1) {
|
|
45
|
+
saturation = 0.1;
|
|
46
|
+
}
|
|
47
|
+
return Number(saturation.toFixed(2));
|
|
48
|
+
};
|
|
49
|
+
exports.getSaturation = getSaturation;
|
|
50
|
+
/**
|
|
51
|
+
* 获取亮度
|
|
52
|
+
* HSV 中 V 控制纯色中混入黑色的量,量越大,黑色越少,亮度越高
|
|
53
|
+
* 1-10 亮度变化 => 亮度从大到小 => 亮度越来越小
|
|
54
|
+
* @param hsv 主色 hsv
|
|
55
|
+
* @param i index
|
|
56
|
+
* @returns 亮度
|
|
57
|
+
*/
|
|
58
|
+
const getBrightness = (hsv, i, { isTop, topBrightnessStep, bottomBrightnessStep, }) => {
|
|
59
|
+
let value = isTop ? hsv.v + topBrightnessStep * i : hsv.v - bottomBrightnessStep * i;
|
|
60
|
+
value = Math.min(value, 1);
|
|
61
|
+
return Number(value.toFixed(2));
|
|
62
|
+
};
|
|
63
|
+
exports.getBrightness = getBrightness;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface GenerateColorPaletteOptions {
|
|
2
|
+
/** 主色对应的颜色值 */
|
|
3
|
+
primaryColor: string;
|
|
4
|
+
/**
|
|
5
|
+
* 显示在主色前面的颜色个数
|
|
6
|
+
* @default 4
|
|
7
|
+
*/
|
|
8
|
+
topColorCount?: number;
|
|
9
|
+
/**
|
|
10
|
+
* 饱和度阶梯(主色前)
|
|
11
|
+
* @default 0.16
|
|
12
|
+
*/
|
|
13
|
+
topSaturationStep?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 亮度阶梯(主色前)
|
|
16
|
+
* @default 0.05
|
|
17
|
+
*/
|
|
18
|
+
topBrightnessStep?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 显示在主色后面的颜色个数
|
|
21
|
+
* @default 2
|
|
22
|
+
*/
|
|
23
|
+
bottomColorCount?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 饱和度阶梯(主色后)
|
|
26
|
+
* @default 0.05
|
|
27
|
+
*/
|
|
28
|
+
bottomSaturationStep?: number;
|
|
29
|
+
/**
|
|
30
|
+
* 亮度阶梯(主色后)
|
|
31
|
+
* @default 0.15
|
|
32
|
+
*/
|
|
33
|
+
bottomBrightnessStep?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 色相阶梯
|
|
36
|
+
* @default 2
|
|
37
|
+
*/
|
|
38
|
+
hueStep?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 根据主色生成色板
|
|
42
|
+
* @link https://github.com/hd996/color-generate
|
|
43
|
+
* @link https://zhuanlan.zhihu.com/p/32422584
|
|
44
|
+
* @link https://github.com/ant-design/ant-design/blob/3.x-stable/components/style/color/colorPalette.less
|
|
45
|
+
*/
|
|
46
|
+
export declare const generateColorPalette: (opt: GenerateColorPaletteOptions) => string[];
|
|
47
|
+
/**
|
|
48
|
+
* 根据主色自动生成阶梯色
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateStepColors(option: {
|
|
51
|
+
/**
|
|
52
|
+
* 主色对应的颜色值
|
|
53
|
+
* @example 'rgb(0, 82, 217)'
|
|
54
|
+
*/
|
|
55
|
+
primaryColor: string;
|
|
56
|
+
/** 需要生成的阶梯色个数(>= 1) */
|
|
57
|
+
stepCount: number;
|
|
58
|
+
/**
|
|
59
|
+
* 主色基准值(1-based)
|
|
60
|
+
*
|
|
61
|
+
* *如果未指定 `primaryOrder`,则 `primaryOrder` 会根据传入的 `primaryColor` 及 `stepCount` 的取值自动计算*
|
|
62
|
+
*/
|
|
63
|
+
primaryOrder?: number;
|
|
64
|
+
}): {
|
|
65
|
+
stepColors: string[];
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/utils/color-generator/generate.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,2BAA2B;IAC1C,eAAe;IACf,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAuBD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,QAAS,2BAA2B,aAiEpE,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;;EA4BA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateStepColors = exports.generateColorPalette = void 0;
|
|
7
|
+
const tinycolor2_1 = __importDefault(require("tinycolor2"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const core_1 = require("./core");
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
topColorCount: 4,
|
|
12
|
+
topSaturationStep: 0.16,
|
|
13
|
+
topBrightnessStep: 0.05,
|
|
14
|
+
bottomColorCount: 2,
|
|
15
|
+
bottomSaturationStep: 0.05,
|
|
16
|
+
bottomBrightnessStep: 0.15,
|
|
17
|
+
hueStep: 2,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 根据主色生成色板
|
|
21
|
+
* @link https://github.com/hd996/color-generate
|
|
22
|
+
* @link https://zhuanlan.zhihu.com/p/32422584
|
|
23
|
+
* @link https://github.com/ant-design/ant-design/blob/3.x-stable/components/style/color/colorPalette.less
|
|
24
|
+
*/
|
|
25
|
+
const generateColorPalette = (opt) => {
|
|
26
|
+
const { primaryColor, topColorCount, topSaturationStep, topBrightnessStep, bottomColorCount, bottomSaturationStep, bottomBrightnessStep, hueStep, } = (0, utils_1.mergeProps)(defaultOptions, opt);
|
|
27
|
+
const colors = [];
|
|
28
|
+
const hsv = (0, tinycolor2_1.default)(primaryColor).toHsv();
|
|
29
|
+
// 主色前
|
|
30
|
+
for (let i = topColorCount; i > 0; i -= 1) {
|
|
31
|
+
const color = (0, tinycolor2_1.default)({
|
|
32
|
+
h: (0, core_1.getHue)(hsv, i, {
|
|
33
|
+
isTop: true,
|
|
34
|
+
hueStep,
|
|
35
|
+
}),
|
|
36
|
+
s: (0, core_1.getSaturation)(hsv, i, {
|
|
37
|
+
isTop: true,
|
|
38
|
+
topColorCount,
|
|
39
|
+
topSaturationStep,
|
|
40
|
+
bottomSaturationStep,
|
|
41
|
+
}),
|
|
42
|
+
v: (0, core_1.getBrightness)(hsv, i, {
|
|
43
|
+
isTop: true,
|
|
44
|
+
topBrightnessStep,
|
|
45
|
+
bottomBrightnessStep,
|
|
46
|
+
}),
|
|
47
|
+
}).toRgbString();
|
|
48
|
+
colors.push(color);
|
|
49
|
+
}
|
|
50
|
+
// 主色
|
|
51
|
+
colors.push((0, tinycolor2_1.default)(primaryColor).toRgbString());
|
|
52
|
+
// 主色后
|
|
53
|
+
for (let i = 1; i <= bottomColorCount; i += 1) {
|
|
54
|
+
const color = (0, tinycolor2_1.default)({
|
|
55
|
+
h: (0, core_1.getHue)(hsv, i, {
|
|
56
|
+
isTop: false,
|
|
57
|
+
hueStep,
|
|
58
|
+
}),
|
|
59
|
+
s: (0, core_1.getSaturation)(hsv, i, {
|
|
60
|
+
isTop: false,
|
|
61
|
+
topColorCount,
|
|
62
|
+
topSaturationStep,
|
|
63
|
+
bottomSaturationStep,
|
|
64
|
+
}),
|
|
65
|
+
v: (0, core_1.getBrightness)(hsv, i, {
|
|
66
|
+
isTop: false,
|
|
67
|
+
topBrightnessStep,
|
|
68
|
+
bottomBrightnessStep,
|
|
69
|
+
}),
|
|
70
|
+
}).toRgbString();
|
|
71
|
+
colors.push(color);
|
|
72
|
+
}
|
|
73
|
+
return colors;
|
|
74
|
+
};
|
|
75
|
+
exports.generateColorPalette = generateColorPalette;
|
|
76
|
+
/**
|
|
77
|
+
* 根据主色自动生成阶梯色
|
|
78
|
+
*/
|
|
79
|
+
function generateStepColors(option) {
|
|
80
|
+
var _a;
|
|
81
|
+
const { primaryColor } = option;
|
|
82
|
+
/** 阶梯色个数 (>= 1) */
|
|
83
|
+
const stepCount = Math.max(1, option.stepCount);
|
|
84
|
+
/** 主色基准值 (>= 1) */
|
|
85
|
+
const primaryOrder = Math.max(1, (_a = option.primaryOrder) !== null && _a !== void 0 ? _a :
|
|
86
|
+
// 根据颜色明度自动计算基准值 (范围:[1, stepCount])
|
|
87
|
+
Math.floor(1 + (stepCount - 1) * (1 - (0, utils_1.calculateLuminance)(primaryColor))));
|
|
88
|
+
/** 生成的阶梯色列表 */
|
|
89
|
+
const stepColors = (0, exports.generateColorPalette)({
|
|
90
|
+
primaryColor,
|
|
91
|
+
topColorCount: primaryOrder - 1,
|
|
92
|
+
topSaturationStep: 0.06 + 0.04 * (primaryOrder / stepCount),
|
|
93
|
+
topBrightnessStep: 0.05 + 0.05 * (primaryOrder / stepCount),
|
|
94
|
+
bottomColorCount: stepCount - primaryOrder,
|
|
95
|
+
bottomSaturationStep: 0.08 + 0.05 * ((stepCount - primaryOrder) / stepCount),
|
|
96
|
+
bottomBrightnessStep: 0.06 + 0.04 * ((stepCount - primaryOrder) / stepCount),
|
|
97
|
+
});
|
|
98
|
+
return { stepColors };
|
|
99
|
+
}
|
|
100
|
+
exports.generateStepColors = generateStepColors;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author yomeeliu
|
|
3
|
+
*/
|
|
4
|
+
export declare function mergeProps<A, B>(a: A, b: B): B & A;
|
|
5
|
+
export declare function mergeProps<A, B, C>(a: A, b: B, c: C): C & B & A;
|
|
6
|
+
/**
|
|
7
|
+
* @author yomeeliu
|
|
8
|
+
* 计算指定颜色的明度
|
|
9
|
+
*
|
|
10
|
+
* *返回 [0-1] 间的某个值*
|
|
11
|
+
*
|
|
12
|
+
* @link https://github.com/mattdesl/color-luminance/blob/master/index.js
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateLuminance(color: string): number;
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/color-generator/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACpD,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAajE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,UAS/C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.calculateLuminance = exports.mergeProps = void 0;
|
|
7
|
+
const assign_1 = __importDefault(require("lodash/assign"));
|
|
8
|
+
const assignWith_1 = __importDefault(require("lodash/assignWith"));
|
|
9
|
+
const isUndefined_1 = __importDefault(require("lodash/isUndefined"));
|
|
10
|
+
const tinycolor2_1 = __importDefault(require("tinycolor2"));
|
|
11
|
+
function mergeProps(...items) {
|
|
12
|
+
function customizer(objValue, srcValue) {
|
|
13
|
+
return (0, isUndefined_1.default)(srcValue) ? objValue : srcValue;
|
|
14
|
+
}
|
|
15
|
+
let ret = (0, assign_1.default)({}, items[0]);
|
|
16
|
+
for (let i = 1; i < items.length; i += 1) {
|
|
17
|
+
ret = (0, assignWith_1.default)(ret, items[i], customizer);
|
|
18
|
+
}
|
|
19
|
+
return ret;
|
|
20
|
+
}
|
|
21
|
+
exports.mergeProps = mergeProps;
|
|
22
|
+
/**
|
|
23
|
+
* @author yomeeliu
|
|
24
|
+
* 计算指定颜色的明度
|
|
25
|
+
*
|
|
26
|
+
* *返回 [0-1] 间的某个值*
|
|
27
|
+
*
|
|
28
|
+
* @link https://github.com/mattdesl/color-luminance/blob/master/index.js
|
|
29
|
+
*/
|
|
30
|
+
function calculateLuminance(color) {
|
|
31
|
+
const { r, g, b } = (0, tinycolor2_1.default)(color).toRgb();
|
|
32
|
+
const arr = [r, g, b].map((v) => {
|
|
33
|
+
v /= 255;
|
|
34
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow(((v + 0.055) / 1.055), 2.4);
|
|
35
|
+
});
|
|
36
|
+
return +(0.2126 * arr[0] + 0.7152 * arr[1] + 0.0722 * arr[2]).toFixed(2);
|
|
37
|
+
}
|
|
38
|
+
exports.calculateLuminance = calculateLuminance;
|