genFontMapToken.uts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // import type { FontMapToken } from '../../interface';
  2. import { getFontSizes } from './genFontSizes';
  3. export const genFontMapToken = (fontSize : number | null) : UTSJSONObject => {
  4. if (fontSize == null) return {}
  5. const fontSizePairs = getFontSizes(fontSize);
  6. const fontSizes = fontSizePairs.map((pair) : number => pair.size);
  7. const lineHeights = fontSizePairs.map((pair) : number => pair.lineHeight);
  8. const fontSizeXS = fontSizes[0];
  9. const fontSizeSM = fontSizes[1];
  10. const fontSizeMD = fontSizes[3];
  11. const fontSizeLG = fontSizes[4];
  12. const lineHeight = lineHeights[2];
  13. const lineHeightSM = lineHeights[1];
  14. const lineHeightMD = lineHeights[3];
  15. const lineHeightLG = lineHeights[4];
  16. return {
  17. fontSize,
  18. fontSizeXS,
  19. fontSizeSM,
  20. fontSizeMD,
  21. fontSizeLG,
  22. fontSizeXL: fontSizes[5],
  23. fontSizeHeading1: fontSizes[7],
  24. fontSizeHeading2: fontSizes[6],
  25. fontSizeHeading3: fontSizes[5],
  26. fontSizeHeading4: fontSizes[4],
  27. fontSizeHeading5: fontSizes[3],
  28. lineHeight,
  29. lineHeightLG,
  30. lineHeightMD,
  31. lineHeightSM,
  32. fontHeight: Math.round(lineHeight * fontSizeMD),
  33. fontHeightLG: Math.round(lineHeightLG * fontSizeLG),
  34. fontHeightSM: Math.round(lineHeightSM * fontSizeSM),
  35. lineHeightHeading1: lineHeights[7],
  36. lineHeightHeading2: lineHeights[6],
  37. lineHeightHeading3: lineHeights[5],
  38. lineHeightHeading4: lineHeights[4],
  39. lineHeightHeading5: lineHeights[3],
  40. };
  41. };