2024-07-04 17:25:40 +08:00
|
|
|
import { generate, presetPalettes, presetPrimaryColors } from '@ant-design/colors';
|
2024-04-01 15:49:45 +08:00
|
|
|
|
2024-06-22 23:57:39 +08:00
|
|
|
import type { 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';
|
|
|
|
import genCommonMapToken from '../shared/genCommonMapToken';
|
2024-04-01 15:49:45 +08:00
|
|
|
import genControlHeight from '../shared/genControlHeight';
|
2022-12-09 17:52:34 +08:00
|
|
|
import genFontMapToken from '../shared/genFontMapToken';
|
2024-04-01 15:49:45 +08:00
|
|
|
import genSizeMapToken from '../shared/genSizeMapToken';
|
|
|
|
import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
|
2022-06-21 17:17:19 +08:00
|
|
|
|
2022-06-27 11:54:31 +08:00
|
|
|
export default function derivative(token: SeedToken): MapToken {
|
2024-07-04 17:25:40 +08:00
|
|
|
// pink is deprecated name of magenta, keep this for backwards compatibility
|
|
|
|
presetPrimaryColors.pink = presetPrimaryColors.magenta;
|
|
|
|
presetPalettes.pink = presetPalettes.magenta;
|
2022-06-21 17:17:19 +08:00
|
|
|
const colorPalettes = Object.keys(defaultPresetColors)
|
2024-04-01 15:49:45 +08:00
|
|
|
.map((colorKey) => {
|
2024-07-04 17:25:40 +08:00
|
|
|
const colors =
|
|
|
|
token[colorKey as keyof PresetColorType] === presetPrimaryColors[colorKey]
|
|
|
|
? presetPalettes[colorKey]
|
|
|
|
: generate(token[colorKey as keyof PresetColorType]);
|
2022-06-21 17:17:19 +08:00
|
|
|
return new Array(10).fill(1).reduce((prev, _, i) => {
|
2023-12-04 20:07:20 +08:00
|
|
|
prev[`${colorKey}-${i + 1}`] = colors[i];
|
2023-03-05 20:49:26 +08:00
|
|
|
prev[`${colorKey}${i + 1}`] = colors[i];
|
2022-06-21 17:17:19 +08:00
|
|
|
return prev;
|
2024-06-22 23:57:39 +08:00
|
|
|
}, {});
|
2022-06-21 17:17:19 +08:00
|
|
|
})
|
2024-06-22 23:57:39 +08:00
|
|
|
.reduce((prev, cur) => {
|
|
|
|
// biome-ignore lint/style/noParameterAssign: it is a reduce
|
|
|
|
prev = { ...prev, ...cur };
|
|
|
|
return prev;
|
|
|
|
}, {});
|
2022-06-21 17:17:19 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
...token,
|
|
|
|
...colorPalettes,
|
2022-06-29 16:15:58 +08:00
|
|
|
// Colors
|
2022-08-19 13:57:19 +08:00
|
|
|
...genColorMapToken(token, {
|
|
|
|
generateColorPalettes,
|
|
|
|
generateNeutralColorPalettes,
|
|
|
|
}),
|
2022-12-09 17:52:34 +08:00
|
|
|
// Font
|
|
|
|
...genFontMapToken(token.fontSize),
|
2022-10-25 17:04:36 +08:00
|
|
|
// Size
|
|
|
|
...genSizeMapToken(token),
|
2022-11-01 15:06:38 +08:00
|
|
|
// Height
|
|
|
|
...genControlHeight(token),
|
2022-10-25 17:04:36 +08:00
|
|
|
// Others
|
2022-06-29 16:15:58 +08:00
|
|
|
...genCommonMapToken(token),
|
2022-06-21 17:17:19 +08:00
|
|
|
};
|
|
|
|
}
|