forked from surely-vue/surely-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemeConfig.ts
49 lines (48 loc) · 1.22 KB
/
themeConfig.ts
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
import less from 'less';
import { getThemeVariables } from 'ant-design-vue/dist/theme';
const themeConfig = [
{
theme: 'dark',
htmlThemeAttr: 'dark',
modifyVars: {
...getThemeVariables({ dark: true }),
'text-color': 'fade(@white, 65%)',
'gray-8': '@text-color',
'background-color-base': '#555',
'skeleton-color': 'rgba(0,0,0,0.8)',
},
},
];
const additionalData = async (content: string, filename: string): Promise<string> => {
const themePromises = themeConfig.map(async t => {
const { htmlThemeAttr, modifyVars = {} } = t;
const options = {
javascriptEnabled: true,
modifyVars,
relativeUrls: true,
filename,
};
try {
const { css } = await less.render(content, options);
let res = '';
if (htmlThemeAttr && css) {
res = `
[data-doc-theme=${htmlThemeAttr}] {
${css}
}
`;
}
return Promise.resolve(res);
} catch (error) {
return Promise.reject(content);
}
});
let res = content;
for (const themePromise of themePromises) {
const theme = await themePromise;
res += theme;
}
return res;
};
export default themeConfig;
export { themeConfig, additionalData };