2024-01-12 15:03:03 +08:00
|
|
|
export function getLineHeight(fontSize: number) {
|
|
|
|
return (fontSize + 8) / fontSize;
|
|
|
|
}
|
|
|
|
|
2022-03-22 09:37:37 +08:00
|
|
|
// https://zhuanlan.zhihu.com/p/32746810
|
2022-06-29 16:15:58 +08:00
|
|
|
export default function getFontSizes(base: number) {
|
2022-03-22 09:37:37 +08:00
|
|
|
const fontSizes = new Array(10).fill(null).map((_, index) => {
|
|
|
|
const i = index - 1;
|
2024-06-22 21:59:12 +08:00
|
|
|
const baseSize = base * Math.E ** (i / 5);
|
2022-03-22 09:37:37 +08:00
|
|
|
const intSize = index > 1 ? Math.floor(baseSize) : Math.ceil(baseSize);
|
|
|
|
|
|
|
|
// Convert to even
|
|
|
|
return Math.floor(intSize / 2) * 2;
|
|
|
|
});
|
|
|
|
|
|
|
|
fontSizes[1] = base;
|
|
|
|
|
2024-01-12 15:03:03 +08:00
|
|
|
return fontSizes.map((size) => ({
|
|
|
|
size,
|
|
|
|
lineHeight: getLineHeight(size),
|
|
|
|
}));
|
2022-03-22 09:37:37 +08:00
|
|
|
}
|