前言
先要弄颜色的转换,因为在后续的font-color,border-color,background-color,都会用到
颜色存的方式
export interface Color {
/**
* Hex string for alpha-red-green-blue e.g. FF00FF00
*/
argb?: string;
/**
* Choose a theme by index
*/
theme?: number;
}
color有三种可能,undefined,{argb:string}, { theme: 0-9}
argb
const tinytinycolor = require('tinytinycolor');
let colorOfArgb = 'FF00FF00';
tinytinycolor(colorOfArgb ).toHexString();
tinytinycolor 是一个颜色转换包,npmjs中去搜索
theme
function colorToHex(color: {theme: number, tint: number}) {
let res=[];
switch(color.theme) {
case 0:
res = {U:170, S: 0};
break;
case 1:
res = {U:170,S: 0};
break;
case 2:
res = {U: 0, S: 5};
break;
case 3:
res = {U: 152, S: 56};
break;
case 4:
res = {U: 148, S: 151};
break;
case 5:
res = {U: 17, S: 214};
break;
case 6:
res = {U: 165, S: 165};
break;
case 7:
res = {U: 32, S: 255};
break;
case 8:
res = {U: 68, S: 114};
break;
case 9:
res = {U: 112, S: 173};
break;
default:
res = {U: 170, S: 0};
break;
}
if(colorObj.tint > 0) {
return tinytinycolor({h: res[0], s: res[1], l: Math.abs(color.tint*100)}).toHexString();
} else {
return tinytinycolor({h: res[0], s: res[1], l: Math.abs((1 + color.tint)*100)}).toHexString();
}
}
颜色值就这些