genFontSizes.js 628 B

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