-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
62 lines (52 loc) · 2.19 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const tinycolor = require("tinycolor2");
const config = require('./src/common/config').CONFIG;
let res = '';
const mixColor = (front, back) => {
var rgbFront = tinycolor(front).toRgb();
var rgbBack = tinycolor(back).toRgb();
var alphaFront = rgbFront.a;
var mixR = alphaFront * rgbFront.r + (1 - alphaFront) * rgbBack.r;
var mixG = alphaFront * rgbFront.g + (1 - alphaFront) * rgbBack.g;
var mixB = alphaFront * rgbFront.b + (1 - alphaFront) * rgbBack.b;
var res = tinycolor({ r: mixR, g: mixG, b: mixB }).toHexString();
return res;
};
// 色轮
config.colorValue.forEach(item => {
res += `$sgb-${item.name.toLocaleLowerCase()}: ${item.value};\n`
});
res += '\n';
// 功能色
config.colorList.func.forEach(item => {
res += `$sgb-${item.name}: ${item.color};\n`
});
res += '\n';
// 主色辅助色
res += `$sgb-primary: ${config.colorList.primaryColor};\n`;
res += `$sgb-secondary: ${config.colorList.secondaryColor};\n`;
res += '\n';
// 文本字号
let remFontsize = '';
config.font.forEach(item => {
if (item.name === 'PCBody') {
remFontsize = item.fontSize;
res += `html { font-size: ${remFontsize}px };\n`
}
})
config.font.forEach(item => {
res += `$sgb-${item.name.toLocaleLowerCase()}: ${(item.fontSize / remFontsize).toFixed(7)}rem;\n`
})
// 文本色板 浅色前景色与白色混合,得出非半透明颜色,用于 bootstrap 计算文本黑白色的使用
res += '\n';
res += `$sgb-htmlBgColor: ${mixColor(config.colorList.htmlBgColor, '#fff')};\n`; // 6%
res += `$sgb-lightHoverBgColor: ${mixColor(config.colorList.lightHoverBgColor, '#fff')};\n`; // 10%
res += `$sgb-segmentLightTextColor: ${mixColor(config.colorList.segmentLightTextColor, '#fff')};\n`; // 12%
res += `$sgb-lightActiveBgColor: ${mixColor(config.colorList.lightActiveBgColor, '#fff')};\n`; // 20%
res += `$sgb-disableLightTextColor: ${mixColor(config.colorList.disableLightTextColor, '#fff')};\n`; // 38%
res += `$sgb-descLightTextColor: ${config.colorList.descLightTextColor};\n`; // 54%
res += `$sgb-baseLightTextColor: ${config.colorList.baseLightTextColor};\n`; // 87%
fs.writeFile('bootstrap/_sgb-variables.scss', res, (err) => {
if (err) throw err;
console.log('导出成功');
});