generateModifyVars.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { resolve } from 'node:path'
  2. import { generate } from '@ant-design/colors'
  3. import { theme } from 'ant-design-vue/lib'
  4. import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken'
  5. import { primaryColor } from '../config/themeConfig'
  6. const { defaultAlgorithm, defaultSeed } = theme
  7. function generateAntColors(color: string, theme: 'default' | 'dark' = 'default') {
  8. return generate(color, {
  9. theme,
  10. })
  11. }
  12. /**
  13. * less global variable
  14. */
  15. export function generateModifyVars() {
  16. const palettes = generateAntColors(primaryColor)
  17. const primary = palettes[5]
  18. const primaryColorObj: Record<string, string> = {}
  19. for (let index = 0; index < 10; index++)
  20. primaryColorObj[`primary-${index + 1}`] = palettes[index]
  21. // const modifyVars = getThemeVariables();
  22. const mapToken = defaultAlgorithm(defaultSeed)
  23. const v3Token = convertLegacyToken(mapToken)
  24. return {
  25. ...v3Token,
  26. // reference: Avoid repeated references
  27. 'hack': `true; @import (reference) "${resolve('src/design/config.less')}";`,
  28. 'primary-color': primary,
  29. ...primaryColorObj,
  30. 'info-color': primary,
  31. 'processing-color': primary,
  32. 'success-color': '#55D187', // Success color
  33. 'error-color': '#ED6F6F', // False color
  34. 'warning-color': '#EFBD47', // Warning color
  35. 'font-size-base': '14px', // Main font size
  36. 'border-radius-base': '2px', // Component/float fillet
  37. 'link-color': primary, // Link color
  38. 'app-content-background': '#fafafa', // Link color
  39. }
  40. }