dispatch/client/js/modules/fonts.js

16 lines
449 B
JavaScript
Raw Normal View History

import { setCharWidth } from 'state/app';
import { stringWidth } from 'utils';
2020-05-18 23:29:22 +00:00
export default async function fonts({ store }) {
2018-03-25 00:34:41 +00:00
let { charWidth } = localStorage;
if (charWidth) {
store.dispatch(setCharWidth(parseFloat(charWidth)));
2020-05-18 23:29:22 +00:00
} else {
await document.fonts.load('16px Roboto Mono');
2020-05-18 23:29:22 +00:00
charWidth = stringWidth(' ', '16px Roboto Mono');
store.dispatch(setCharWidth(charWidth));
localStorage.charWidth = charWidth;
}
}