1
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import type { ColorNeutralMapToken } from '../interface';
|
||||
export interface ColorMap {
|
||||
1: string;
|
||||
2: string;
|
||||
3: string;
|
||||
4: string;
|
||||
5: string;
|
||||
6: string;
|
||||
7: string;
|
||||
8: string;
|
||||
9: string;
|
||||
10: string;
|
||||
}
|
||||
export type GenerateColorMap = (baseColor: string) => ColorMap;
|
||||
export type GenerateNeutralColorMap = (bgBaseColor: string, textBaseColor: string, shadowColor?: string) => ColorNeutralMapToken;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import type { SeedToken, SizeMapToken } from '../../interface';
|
||||
export default function genSizeMapToken(token: SeedToken): SizeMapToken;
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
export default function genSizeMapToken(token) {
|
||||
const {
|
||||
sizeUnit,
|
||||
sizeStep
|
||||
} = token;
|
||||
const compactSizeStep = sizeStep - 2;
|
||||
return {
|
||||
sizeXXL: sizeUnit * (compactSizeStep + 10),
|
||||
sizeXL: sizeUnit * (compactSizeStep + 6),
|
||||
sizeLG: sizeUnit * (compactSizeStep + 2),
|
||||
sizeMD: sizeUnit * (compactSizeStep + 2),
|
||||
sizeMS: sizeUnit * (compactSizeStep + 1),
|
||||
size: sizeUnit * compactSizeStep,
|
||||
sizeSM: sizeUnit * compactSizeStep,
|
||||
sizeXS: sizeUnit * (compactSizeStep - 1),
|
||||
sizeXXS: sizeUnit * (compactSizeStep - 1)
|
||||
};
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
||||
import type { MapToken, SeedToken } from '../../interface';
|
||||
declare const derivative: DerivativeFunc<SeedToken, MapToken>;
|
||||
export default derivative;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import defaultAlgorithm from '../default';
|
||||
import genControlHeight from '../shared/genControlHeight';
|
||||
import genFontMapToken from '../shared/genFontMapToken';
|
||||
import genCompactSizeMapToken from './genCompactSizeMapToken';
|
||||
const derivative = (token, mapToken) => {
|
||||
const mergedMapToken = mapToken ?? defaultAlgorithm(token);
|
||||
const fontSize = mergedMapToken.fontSizeSM; // Smaller size font-size as base
|
||||
const controlHeight = mergedMapToken.controlHeight - 4;
|
||||
return {
|
||||
...mergedMapToken,
|
||||
...genCompactSizeMapToken(mapToken ?? token),
|
||||
// font
|
||||
...genFontMapToken(fontSize),
|
||||
// controlHeight
|
||||
controlHeight,
|
||||
...genControlHeight({
|
||||
...mergedMapToken,
|
||||
controlHeight
|
||||
})
|
||||
};
|
||||
};
|
||||
export default derivative;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare const getAlphaColor: (baseColor: string, alpha: number) => string;
|
||||
export declare const getSolidColor: (baseColor: string, brightness: number) => string;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { FastColor } from '@ant-design/fast-color';
|
||||
export const getAlphaColor = (baseColor, alpha) => new FastColor(baseColor).setA(alpha).toRgbString();
|
||||
export const getSolidColor = (baseColor, brightness) => {
|
||||
const instance = new FastColor(baseColor);
|
||||
return instance.lighten(brightness).toHexString();
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { GenerateColorMap, GenerateNeutralColorMap } from '../ColorMap';
|
||||
export declare const generateColorPalettes: GenerateColorMap;
|
||||
export declare const generateNeutralColorPalettes: GenerateNeutralColorMap;
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import { generate } from '@ant-design/colors';
|
||||
import { getAlphaColor, getSolidColor } from './colorAlgorithm';
|
||||
export const generateColorPalettes = baseColor => {
|
||||
const colors = generate(baseColor, {
|
||||
theme: 'dark'
|
||||
});
|
||||
return {
|
||||
1: colors[0],
|
||||
2: colors[1],
|
||||
3: colors[2],
|
||||
4: colors[3],
|
||||
5: colors[6],
|
||||
6: colors[5],
|
||||
7: colors[4],
|
||||
8: colors[6],
|
||||
9: colors[5],
|
||||
10: colors[4]
|
||||
};
|
||||
};
|
||||
export const generateNeutralColorPalettes = (bgBaseColor, textBaseColor, shadowColor) => {
|
||||
const colorBgBase = bgBaseColor || '#000';
|
||||
const colorTextBase = textBaseColor || '#fff';
|
||||
const colorShadow = shadowColor || 'rgba(255, 255, 255, 0.2)';
|
||||
return {
|
||||
colorBgBase,
|
||||
colorTextBase,
|
||||
colorShadow,
|
||||
colorText: getAlphaColor(colorTextBase, 0.85),
|
||||
colorTextSecondary: getAlphaColor(colorTextBase, 0.65),
|
||||
colorTextTertiary: getAlphaColor(colorTextBase, 0.45),
|
||||
colorTextQuaternary: getAlphaColor(colorTextBase, 0.25),
|
||||
colorFill: getAlphaColor(colorTextBase, 0.18),
|
||||
colorFillSecondary: getAlphaColor(colorTextBase, 0.12),
|
||||
colorFillTertiary: getAlphaColor(colorTextBase, 0.08),
|
||||
colorFillQuaternary: getAlphaColor(colorTextBase, 0.04),
|
||||
colorBgSolid: getAlphaColor(colorTextBase, 0.95),
|
||||
colorBgSolidHover: getAlphaColor(colorTextBase, 1),
|
||||
colorBgSolidActive: getAlphaColor(colorTextBase, 0.9),
|
||||
colorBgElevated: getSolidColor(colorBgBase, 12),
|
||||
colorBgContainer: getSolidColor(colorBgBase, 8),
|
||||
colorBgLayout: getSolidColor(colorBgBase, 0),
|
||||
colorBgSpotlight: getSolidColor(colorBgBase, 26),
|
||||
colorBgBlur: getAlphaColor(colorTextBase, 0.04),
|
||||
colorBorder: getSolidColor(colorBgBase, 26),
|
||||
colorBorderDisabled: getSolidColor(colorBgBase, 26),
|
||||
colorBorderSecondary: getSolidColor(colorBgBase, 19)
|
||||
};
|
||||
};
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
||||
import type { MapToken, SeedToken } from '../../interface';
|
||||
declare const derivative: DerivativeFunc<SeedToken, MapToken>;
|
||||
export default derivative;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import { generate } from '@ant-design/colors';
|
||||
import { PresetColors } from '../../interface/presetColors';
|
||||
import defaultAlgorithm from '../default';
|
||||
import { defaultPresetColors } from '../seed';
|
||||
import genColorMapToken from '../shared/genColorMapToken';
|
||||
import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
|
||||
const derivative = (token, mapToken) => {
|
||||
const colorPalettes = Object.keys(defaultPresetColors).map(colorKey => {
|
||||
const colors = generate(token[colorKey], {
|
||||
theme: 'dark'
|
||||
});
|
||||
return Array.from({
|
||||
length: 10
|
||||
}, () => 1).reduce((prev, _, i) => {
|
||||
prev[`${colorKey}-${i + 1}`] = colors[i];
|
||||
prev[`${colorKey}${i + 1}`] = colors[i];
|
||||
return prev;
|
||||
}, {});
|
||||
}).reduce((prev, cur) => {
|
||||
prev = {
|
||||
...prev,
|
||||
...cur
|
||||
};
|
||||
return prev;
|
||||
}, {});
|
||||
const mergedMapToken = mapToken ?? defaultAlgorithm(token);
|
||||
const colorMapToken = genColorMapToken(token, {
|
||||
generateColorPalettes,
|
||||
generateNeutralColorPalettes
|
||||
});
|
||||
const presetColorHoverActiveTokens = PresetColors.reduce((prev, colorKey) => {
|
||||
const colorBase = token[colorKey];
|
||||
if (colorBase) {
|
||||
const colorPalette = generateColorPalettes(colorBase);
|
||||
prev[`${colorKey}Hover`] = colorPalette[7];
|
||||
prev[`${colorKey}Active`] = colorPalette[5];
|
||||
}
|
||||
return prev;
|
||||
}, {});
|
||||
return {
|
||||
...mergedMapToken,
|
||||
// Dark tokens
|
||||
...colorPalettes,
|
||||
// Colors
|
||||
...colorMapToken,
|
||||
...presetColorHoverActiveTokens,
|
||||
// Customize selected item background color
|
||||
// https://github.com/ant-design/ant-design/issues/30524#issuecomment-871961867
|
||||
colorPrimaryBg: colorMapToken.colorPrimaryBorder,
|
||||
colorPrimaryBgHover: colorMapToken.colorPrimaryBorderHover
|
||||
};
|
||||
};
|
||||
export default derivative;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare const getAlphaColor: (baseColor: string, alpha: number) => string;
|
||||
export declare const getSolidColor: (baseColor: string, brightness: number) => string;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { FastColor } from '@ant-design/fast-color';
|
||||
export const getAlphaColor = (baseColor, alpha) => new FastColor(baseColor).setA(alpha).toRgbString();
|
||||
export const getSolidColor = (baseColor, brightness) => {
|
||||
const instance = new FastColor(baseColor);
|
||||
return instance.darken(brightness).toHexString();
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { GenerateColorMap, GenerateNeutralColorMap } from '../ColorMap';
|
||||
export declare const generateColorPalettes: GenerateColorMap;
|
||||
export declare const generateNeutralColorPalettes: GenerateNeutralColorMap;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { generate } from '@ant-design/colors';
|
||||
import { getAlphaColor, getSolidColor } from './colorAlgorithm';
|
||||
export const generateColorPalettes = baseColor => {
|
||||
const colors = generate(baseColor);
|
||||
return {
|
||||
1: colors[0],
|
||||
2: colors[1],
|
||||
3: colors[2],
|
||||
4: colors[3],
|
||||
5: colors[4],
|
||||
6: colors[5],
|
||||
7: colors[6],
|
||||
8: colors[4],
|
||||
9: colors[5],
|
||||
10: colors[6]
|
||||
};
|
||||
};
|
||||
export const generateNeutralColorPalettes = (bgBaseColor, textBaseColor, shadowColor) => {
|
||||
const colorBgBase = bgBaseColor || '#fff';
|
||||
const colorTextBase = textBaseColor || '#000';
|
||||
const colorShadow = shadowColor || '#000';
|
||||
return {
|
||||
colorBgBase,
|
||||
colorTextBase,
|
||||
colorShadow,
|
||||
colorText: getAlphaColor(colorTextBase, 0.88),
|
||||
colorTextSecondary: getAlphaColor(colorTextBase, 0.65),
|
||||
colorTextTertiary: getAlphaColor(colorTextBase, 0.45),
|
||||
colorTextQuaternary: getAlphaColor(colorTextBase, 0.25),
|
||||
colorFill: getAlphaColor(colorTextBase, 0.15),
|
||||
colorFillSecondary: getAlphaColor(colorTextBase, 0.06),
|
||||
colorFillTertiary: getAlphaColor(colorTextBase, 0.04),
|
||||
colorFillQuaternary: getAlphaColor(colorTextBase, 0.02),
|
||||
colorBgSolid: getAlphaColor(colorTextBase, 1),
|
||||
colorBgSolidHover: getAlphaColor(colorTextBase, 0.75),
|
||||
colorBgSolidActive: getAlphaColor(colorTextBase, 0.95),
|
||||
colorBgLayout: getSolidColor(colorBgBase, 4),
|
||||
colorBgContainer: getSolidColor(colorBgBase, 0),
|
||||
colorBgElevated: getSolidColor(colorBgBase, 0),
|
||||
colorBgSpotlight: getAlphaColor(colorTextBase, 0.85),
|
||||
colorBgBlur: 'transparent',
|
||||
colorBorder: getSolidColor(colorBgBase, 15),
|
||||
colorBorderDisabled: getSolidColor(colorBgBase, 15),
|
||||
colorBorderSecondary: getSolidColor(colorBgBase, 6)
|
||||
};
|
||||
};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { MapToken, SeedToken } from '../../interface';
|
||||
export default function derivative(token: SeedToken): MapToken;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { generate, presetPalettes, presetPrimaryColors } from '@ant-design/colors';
|
||||
import { defaultPresetColors } from '../seed';
|
||||
import genColorMapToken from '../shared/genColorMapToken';
|
||||
import genCommonMapToken from '../shared/genCommonMapToken';
|
||||
import genControlHeight from '../shared/genControlHeight';
|
||||
import genFontMapToken from '../shared/genFontMapToken';
|
||||
import genSizeMapToken from '../shared/genSizeMapToken';
|
||||
import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
|
||||
export default function derivative(token) {
|
||||
// pink is deprecated name of magenta, keep this for backwards compatibility
|
||||
presetPrimaryColors.pink = presetPrimaryColors.magenta;
|
||||
presetPalettes.pink = presetPalettes.magenta;
|
||||
const colorPalettes = Object.keys(defaultPresetColors).map(colorKey => {
|
||||
const colors = token[colorKey] === presetPrimaryColors[colorKey] ? presetPalettes[colorKey] : generate(token[colorKey]);
|
||||
return Array.from({
|
||||
length: 10
|
||||
}, () => 1).reduce((prev, _, i) => {
|
||||
prev[`${colorKey}-${i + 1}`] = colors[i];
|
||||
prev[`${colorKey}${i + 1}`] = colors[i];
|
||||
return prev;
|
||||
}, {});
|
||||
}).reduce((prev, cur) => {
|
||||
prev = {
|
||||
...prev,
|
||||
...cur
|
||||
};
|
||||
return prev;
|
||||
}, {});
|
||||
return {
|
||||
...token,
|
||||
...colorPalettes,
|
||||
// Colors
|
||||
...genColorMapToken(token, {
|
||||
generateColorPalettes,
|
||||
generateNeutralColorPalettes
|
||||
}),
|
||||
// Font
|
||||
...genFontMapToken(token.fontSize),
|
||||
// Size
|
||||
...genSizeMapToken(token),
|
||||
// Height
|
||||
...genControlHeight(token),
|
||||
// Others
|
||||
...genCommonMapToken(token)
|
||||
};
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const defaultTheme: import("@ant-design/cssinjs").Theme<any, any>;
|
||||
export default defaultTheme;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import { createTheme } from '@ant-design/cssinjs';
|
||||
import defaultDerivative from './index';
|
||||
const defaultTheme = createTheme(defaultDerivative);
|
||||
export default defaultTheme;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { PresetColorType, SeedToken } from '../internal';
|
||||
export declare const defaultPresetColors: PresetColorType;
|
||||
declare const seedToken: SeedToken;
|
||||
export default seedToken;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
export const defaultPresetColors = {
|
||||
blue: '#1677FF',
|
||||
purple: '#722ED1',
|
||||
cyan: '#13C2C2',
|
||||
green: '#52C41A',
|
||||
magenta: '#EB2F96',
|
||||
/**
|
||||
* @deprecated Use magenta instead
|
||||
*/
|
||||
pink: '#EB2F96',
|
||||
red: '#F5222D',
|
||||
orange: '#FA8C16',
|
||||
yellow: '#FADB14',
|
||||
volcano: '#FA541C',
|
||||
geekblue: '#2F54EB',
|
||||
gold: '#FAAD14',
|
||||
lime: '#A0D911'
|
||||
};
|
||||
const seedToken = {
|
||||
// preset color palettes
|
||||
...defaultPresetColors,
|
||||
// Color
|
||||
colorPrimary: '#1677ff',
|
||||
colorSuccess: '#52c41a',
|
||||
colorWarning: '#faad14',
|
||||
colorError: '#ff4d4f',
|
||||
colorInfo: '#1677ff',
|
||||
colorLink: '',
|
||||
colorTextBase: '',
|
||||
colorBgBase: '',
|
||||
// Font
|
||||
fontFamily: `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
|
||||
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
|
||||
'Noto Color Emoji'`,
|
||||
fontFamilyCode: `'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace`,
|
||||
fontSize: 14,
|
||||
// Line
|
||||
lineWidth: 1,
|
||||
lineType: 'solid',
|
||||
// Motion
|
||||
motionUnit: 0.1,
|
||||
motionBase: 0,
|
||||
motionEaseOutCirc: 'cubic-bezier(0.08, 0.82, 0.17, 1)',
|
||||
motionEaseInOutCirc: 'cubic-bezier(0.78, 0.14, 0.15, 0.86)',
|
||||
motionEaseOut: 'cubic-bezier(0.215, 0.61, 0.355, 1)',
|
||||
motionEaseInOut: 'cubic-bezier(0.645, 0.045, 0.355, 1)',
|
||||
motionEaseOutBack: 'cubic-bezier(0.12, 0.4, 0.29, 1.46)',
|
||||
motionEaseInBack: 'cubic-bezier(0.71, -0.46, 0.88, 0.6)',
|
||||
motionEaseInQuint: 'cubic-bezier(0.755, 0.05, 0.855, 0.06)',
|
||||
motionEaseOutQuint: 'cubic-bezier(0.23, 1, 0.32, 1)',
|
||||
// Radius
|
||||
borderRadius: 6,
|
||||
// Size
|
||||
sizeUnit: 4,
|
||||
sizeStep: 4,
|
||||
sizePopupArrow: 16,
|
||||
// Control Base
|
||||
controlHeight: 32,
|
||||
// zIndex
|
||||
zIndexBase: 0,
|
||||
zIndexPopupBase: 1000,
|
||||
// Image
|
||||
opacityImage: 1,
|
||||
// Wireframe
|
||||
wireframe: false,
|
||||
// Motion
|
||||
motion: true
|
||||
};
|
||||
export default seedToken;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { ColorMapToken, SeedToken } from '../../interface';
|
||||
import type { GenerateColorMap, GenerateNeutralColorMap } from '../ColorMap';
|
||||
interface PaletteGenerators {
|
||||
generateColorPalettes: GenerateColorMap;
|
||||
generateNeutralColorPalettes: GenerateNeutralColorMap;
|
||||
}
|
||||
export default function genColorMapToken(seed: SeedToken, { generateColorPalettes, generateNeutralColorPalettes }: PaletteGenerators): ColorMapToken;
|
||||
export {};
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
import { FastColor } from '@ant-design/fast-color';
|
||||
import { PresetColors } from '../../interface/presetColors';
|
||||
export default function genColorMapToken(seed, {
|
||||
generateColorPalettes,
|
||||
generateNeutralColorPalettes
|
||||
}) {
|
||||
const {
|
||||
colorSuccess: colorSuccessBase,
|
||||
colorWarning: colorWarningBase,
|
||||
colorError: colorErrorBase,
|
||||
colorInfo: colorInfoBase,
|
||||
colorPrimary: colorPrimaryBase,
|
||||
colorBgBase,
|
||||
colorTextBase
|
||||
} = seed;
|
||||
const primaryColors = generateColorPalettes(colorPrimaryBase);
|
||||
const successColors = generateColorPalettes(colorSuccessBase);
|
||||
const warningColors = generateColorPalettes(colorWarningBase);
|
||||
const errorColors = generateColorPalettes(colorErrorBase);
|
||||
const infoColors = generateColorPalettes(colorInfoBase);
|
||||
const neutralColors = generateNeutralColorPalettes(colorBgBase, colorTextBase);
|
||||
// Color Link
|
||||
const colorLink = seed.colorLink || seed.colorInfo;
|
||||
const linkColors = generateColorPalettes(colorLink);
|
||||
const colorErrorBgFilledHover = new FastColor(errorColors[1]).mix(new FastColor(errorColors[3]), 50).toHexString();
|
||||
const presetColorTokens = {};
|
||||
PresetColors.forEach(colorKey => {
|
||||
const colorBase = seed[colorKey];
|
||||
if (colorBase) {
|
||||
const colorPalette = generateColorPalettes(colorBase);
|
||||
presetColorTokens[`${colorKey}Hover`] = colorPalette[5];
|
||||
presetColorTokens[`${colorKey}Active`] = colorPalette[7];
|
||||
}
|
||||
});
|
||||
return {
|
||||
...neutralColors,
|
||||
colorPrimaryBg: primaryColors[1],
|
||||
colorPrimaryBgHover: primaryColors[2],
|
||||
colorPrimaryBorder: primaryColors[3],
|
||||
colorPrimaryBorderHover: primaryColors[4],
|
||||
colorPrimaryHover: primaryColors[5],
|
||||
colorPrimary: primaryColors[6],
|
||||
colorPrimaryActive: primaryColors[7],
|
||||
colorPrimaryTextHover: primaryColors[8],
|
||||
colorPrimaryText: primaryColors[9],
|
||||
colorPrimaryTextActive: primaryColors[10],
|
||||
colorSuccessBg: successColors[1],
|
||||
colorSuccessBgHover: successColors[2],
|
||||
colorSuccessBorder: successColors[3],
|
||||
colorSuccessBorderHover: successColors[4],
|
||||
colorSuccessHover: successColors[4],
|
||||
colorSuccess: successColors[6],
|
||||
colorSuccessActive: successColors[7],
|
||||
colorSuccessTextHover: successColors[8],
|
||||
colorSuccessText: successColors[9],
|
||||
colorSuccessTextActive: successColors[10],
|
||||
colorErrorBg: errorColors[1],
|
||||
colorErrorBgHover: errorColors[2],
|
||||
colorErrorBgFilledHover,
|
||||
colorErrorBgActive: errorColors[3],
|
||||
colorErrorBorder: errorColors[3],
|
||||
colorErrorBorderHover: errorColors[4],
|
||||
colorErrorHover: errorColors[5],
|
||||
colorError: errorColors[6],
|
||||
colorErrorActive: errorColors[7],
|
||||
colorErrorTextHover: errorColors[8],
|
||||
colorErrorText: errorColors[9],
|
||||
colorErrorTextActive: errorColors[10],
|
||||
colorWarningBg: warningColors[1],
|
||||
colorWarningBgHover: warningColors[2],
|
||||
colorWarningBorder: warningColors[3],
|
||||
colorWarningBorderHover: warningColors[4],
|
||||
colorWarningHover: warningColors[4],
|
||||
colorWarning: warningColors[6],
|
||||
colorWarningActive: warningColors[7],
|
||||
colorWarningTextHover: warningColors[8],
|
||||
colorWarningText: warningColors[9],
|
||||
colorWarningTextActive: warningColors[10],
|
||||
colorInfoBg: infoColors[1],
|
||||
colorInfoBgHover: infoColors[2],
|
||||
colorInfoBorder: infoColors[3],
|
||||
colorInfoBorderHover: infoColors[4],
|
||||
colorInfoHover: infoColors[4],
|
||||
colorInfo: infoColors[6],
|
||||
colorInfoActive: infoColors[7],
|
||||
colorInfoTextHover: infoColors[8],
|
||||
colorInfoText: infoColors[9],
|
||||
colorInfoTextActive: infoColors[10],
|
||||
colorLinkHover: linkColors[4],
|
||||
colorLink: linkColors[6],
|
||||
colorLinkActive: linkColors[7],
|
||||
...presetColorTokens,
|
||||
colorBgMask: new FastColor('#000').setA(0.45).toRgbString(),
|
||||
colorWhite: '#fff'
|
||||
};
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { CommonMapToken, SeedToken } from '../../interface';
|
||||
export default function genCommonMapToken(token: SeedToken): CommonMapToken;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import genRadius from './genRadius';
|
||||
export default function genCommonMapToken(token) {
|
||||
const {
|
||||
motionUnit,
|
||||
motionBase,
|
||||
borderRadius,
|
||||
lineWidth
|
||||
} = token;
|
||||
return {
|
||||
// motion
|
||||
motionDurationFast: `${(motionBase + motionUnit).toFixed(1)}s`,
|
||||
motionDurationMid: `${(motionBase + motionUnit * 2).toFixed(1)}s`,
|
||||
motionDurationSlow: `${(motionBase + motionUnit * 3).toFixed(1)}s`,
|
||||
// line
|
||||
lineWidthBold: lineWidth + 1,
|
||||
// radius
|
||||
...genRadius(borderRadius)
|
||||
};
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { HeightMapToken, SeedToken } from '../../interface';
|
||||
declare const genControlHeight: (token: SeedToken) => HeightMapToken;
|
||||
export default genControlHeight;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
const genControlHeight = token => {
|
||||
const {
|
||||
controlHeight
|
||||
} = token;
|
||||
return {
|
||||
controlHeightSM: controlHeight * 0.75,
|
||||
controlHeightXS: controlHeight * 0.5,
|
||||
controlHeightLG: controlHeight * 1.25
|
||||
};
|
||||
};
|
||||
export default genControlHeight;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { FontMapToken } from '../../interface';
|
||||
declare const genFontMapToken: (fontSize: number) => FontMapToken;
|
||||
export default genFontMapToken;
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import genFontSizes from './genFontSizes';
|
||||
const genFontMapToken = fontSize => {
|
||||
const fontSizePairs = genFontSizes(fontSize);
|
||||
const fontSizes = fontSizePairs.map(pair => pair.size);
|
||||
const lineHeights = fontSizePairs.map(pair => pair.lineHeight);
|
||||
const fontSizeMD = fontSizes[1];
|
||||
const fontSizeSM = fontSizes[0];
|
||||
const fontSizeLG = fontSizes[2];
|
||||
const lineHeight = lineHeights[1];
|
||||
const lineHeightSM = lineHeights[0];
|
||||
const lineHeightLG = lineHeights[2];
|
||||
return {
|
||||
fontSizeSM,
|
||||
fontSize: fontSizeMD,
|
||||
fontSizeLG,
|
||||
fontSizeXL: fontSizes[3],
|
||||
fontSizeHeading1: fontSizes[6],
|
||||
fontSizeHeading2: fontSizes[5],
|
||||
fontSizeHeading3: fontSizes[4],
|
||||
fontSizeHeading4: fontSizes[3],
|
||||
fontSizeHeading5: fontSizes[2],
|
||||
lineHeight,
|
||||
lineHeightLG,
|
||||
lineHeightSM,
|
||||
fontHeight: Math.round(lineHeight * fontSizeMD),
|
||||
fontHeightLG: Math.round(lineHeightLG * fontSizeLG),
|
||||
fontHeightSM: Math.round(lineHeightSM * fontSizeSM),
|
||||
lineHeightHeading1: lineHeights[6],
|
||||
lineHeightHeading2: lineHeights[5],
|
||||
lineHeightHeading3: lineHeights[4],
|
||||
lineHeightHeading4: lineHeights[3],
|
||||
lineHeightHeading5: lineHeights[2]
|
||||
};
|
||||
};
|
||||
export default genFontMapToken;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export declare function getLineHeight(fontSize: number): number;
|
||||
export default function getFontSizes(base: number): {
|
||||
size: number;
|
||||
lineHeight: number;
|
||||
}[];
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
export function getLineHeight(fontSize) {
|
||||
return (fontSize + 8) / fontSize;
|
||||
}
|
||||
// https://zhuanlan.zhihu.com/p/32746810
|
||||
export default function getFontSizes(base) {
|
||||
const fontSizes = Array.from({
|
||||
length: 10
|
||||
}).map((_, index) => {
|
||||
const i = index - 1;
|
||||
const baseSize = base * Math.E ** (i / 5);
|
||||
const intSize = index > 1 ? Math.floor(baseSize) : Math.ceil(baseSize);
|
||||
// Convert to even
|
||||
return Math.floor(intSize / 2) * 2;
|
||||
});
|
||||
fontSizes[1] = base;
|
||||
return fontSizes.map(size => ({
|
||||
size,
|
||||
lineHeight: getLineHeight(size)
|
||||
}));
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { MapToken } from '../../interface';
|
||||
declare const genRadius: (radiusBase: number) => Pick<MapToken, "borderRadiusXS" | "borderRadiusSM" | "borderRadiusLG" | "borderRadius" | "borderRadiusOuter">;
|
||||
export default genRadius;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
const genRadius = radiusBase => {
|
||||
let radiusLG = radiusBase;
|
||||
let radiusSM = radiusBase;
|
||||
let radiusXS = radiusBase;
|
||||
let radiusOuter = radiusBase;
|
||||
// radiusLG
|
||||
if (radiusBase < 6 && radiusBase >= 5) {
|
||||
radiusLG = radiusBase + 1;
|
||||
} else if (radiusBase < 16 && radiusBase >= 6) {
|
||||
radiusLG = radiusBase + 2;
|
||||
} else if (radiusBase >= 16) {
|
||||
radiusLG = 16;
|
||||
}
|
||||
// radiusSM
|
||||
if (radiusBase < 7 && radiusBase >= 5) {
|
||||
radiusSM = 4;
|
||||
} else if (radiusBase < 8 && radiusBase >= 7) {
|
||||
radiusSM = 5;
|
||||
} else if (radiusBase < 14 && radiusBase >= 8) {
|
||||
radiusSM = 6;
|
||||
} else if (radiusBase < 16 && radiusBase >= 14) {
|
||||
radiusSM = 7;
|
||||
} else if (radiusBase >= 16) {
|
||||
radiusSM = 8;
|
||||
}
|
||||
// radiusXS
|
||||
if (radiusBase < 6 && radiusBase >= 2) {
|
||||
radiusXS = 1;
|
||||
} else if (radiusBase >= 6) {
|
||||
radiusXS = 2;
|
||||
}
|
||||
// radiusOuter
|
||||
if (radiusBase > 4 && radiusBase < 8) {
|
||||
radiusOuter = 4;
|
||||
} else if (radiusBase >= 8) {
|
||||
radiusOuter = 6;
|
||||
}
|
||||
return {
|
||||
borderRadius: radiusBase,
|
||||
borderRadiusXS: radiusXS,
|
||||
borderRadiusSM: radiusSM,
|
||||
borderRadiusLG: radiusLG,
|
||||
borderRadiusOuter: radiusOuter
|
||||
};
|
||||
};
|
||||
export default genRadius;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { SeedToken, SizeMapToken } from '../../interface';
|
||||
export default function genSizeMapToken(token: SeedToken): SizeMapToken;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
export default function genSizeMapToken(token) {
|
||||
const {
|
||||
sizeUnit,
|
||||
sizeStep
|
||||
} = token;
|
||||
return {
|
||||
sizeXXL: sizeUnit * (sizeStep + 8),
|
||||
// 48
|
||||
sizeXL: sizeUnit * (sizeStep + 4),
|
||||
// 32
|
||||
sizeLG: sizeUnit * (sizeStep + 2),
|
||||
// 24
|
||||
sizeMD: sizeUnit * (sizeStep + 1),
|
||||
// 20
|
||||
sizeMS: sizeUnit * sizeStep,
|
||||
// 16
|
||||
size: sizeUnit * sizeStep,
|
||||
// 16
|
||||
sizeSM: sizeUnit * (sizeStep - 1),
|
||||
// 12
|
||||
sizeXS: sizeUnit * (sizeStep - 2),
|
||||
// 8
|
||||
sizeXXS: sizeUnit * (sizeStep - 3) // 4
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user