2022-06-21 17:17:19 +08:00
|
|
|
import { generate } from '@ant-design/colors';
|
2022-08-16 21:06:25 +08:00
|
|
|
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
2022-06-27 11:54:31 +08:00
|
|
|
import type { ColorPalettes, MapToken, PresetColorType, SeedToken } from '../../interface';
|
2022-06-24 11:11:42 +08:00
|
|
|
import { defaultPresetColors } from '../seed';
|
2022-06-29 16:15:58 +08:00
|
|
|
import genColorMapToken from '../shared/genColorMapToken';
|
2022-08-19 13:57:19 +08:00
|
|
|
import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
|
2022-10-25 17:04:36 +08:00
|
|
|
import defaultAlgorithm from '../default';
|
2022-06-21 17:17:19 +08:00
|
|
|
|
2022-08-16 21:06:25 +08:00
|
|
|
const derivative: DerivativeFunc<SeedToken, MapToken> = (token, mapToken) => {
|
2022-06-21 17:17:19 +08:00
|
|
|
const colorPalettes = Object.keys(defaultPresetColors)
|
|
|
|
.map((colorKey: keyof PresetColorType) => {
|
2022-06-24 11:11:42 +08:00
|
|
|
const colors = generate(token[colorKey], { theme: 'dark' });
|
2022-06-21 17:17:19 +08:00
|
|
|
|
|
|
|
return new Array(10).fill(1).reduce((prev, _, i) => {
|
|
|
|
prev[`${colorKey}-${i + 1}`] = colors[i];
|
|
|
|
return prev;
|
|
|
|
}, {}) as ColorPalettes;
|
|
|
|
})
|
|
|
|
.reduce((prev, cur) => {
|
|
|
|
prev = {
|
|
|
|
...prev,
|
|
|
|
...cur,
|
|
|
|
};
|
|
|
|
return prev;
|
|
|
|
}, {} as ColorPalettes);
|
|
|
|
|
2022-10-25 17:04:36 +08:00
|
|
|
const mergedMapToken = mapToken ?? defaultAlgorithm(token);
|
2022-08-16 21:06:25 +08:00
|
|
|
|
2022-10-25 17:04:36 +08:00
|
|
|
return {
|
|
|
|
...mergedMapToken,
|
2022-08-16 21:06:25 +08:00
|
|
|
|
|
|
|
// Dark tokens
|
2022-06-21 17:17:19 +08:00
|
|
|
...colorPalettes,
|
2022-06-29 16:15:58 +08:00
|
|
|
// Colors
|
2022-11-10 17:18:40 +08:00
|
|
|
...genColorMapToken(token, {
|
2022-08-19 13:57:19 +08:00
|
|
|
generateColorPalettes,
|
|
|
|
generateNeutralColorPalettes,
|
|
|
|
}),
|
2022-06-21 17:17:19 +08:00
|
|
|
};
|
2022-08-16 21:06:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default derivative;
|