genFontSizes.js 531 B

123456789101112131415161718
  1. // https://zhuanlan.zhihu.com/p/32746810
  2. export default function getFontSizes(base) {
  3. const fontSizes = new Array(10).fill(null).map((_, index) => {
  4. const i = index - 1;
  5. const baseSize = base * Math.pow(2.71828, i / 5);
  6. const intSize = index > 1 ? Math.floor(baseSize) : Math.ceil(baseSize);
  7. // Convert to even
  8. return Math.floor(intSize / 2) * 2;
  9. });
  10. fontSizes[1] = base;
  11. return fontSizes.map(size => {
  12. const height = size + 8;
  13. return {
  14. size,
  15. lineHeight: height / size
  16. };
  17. });
  18. }