accounts-frontend/packages/app/services/font.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-01-25 11:22:19 +05:30
import webFont from 'webfontloader';
import logger from 'app/services/logger';
2017-01-25 11:22:19 +05:30
export default {
2020-05-24 04:38:24 +05:30
/**
* @param {Array} families
* @param {object} options
* @param {boolean} [options.external=false] - whether the font should be loaded from external source (e.g. google)
*
* @returns {Promise}
*/
load(
families: string[] = [],
options: {
external?: boolean;
} = {},
): Promise<void> {
let config: { [key: string]: any } = {
custom: { families },
};
2017-01-25 11:48:47 +05:30
2020-05-24 04:38:24 +05:30
if (options.external) {
config = {
google: { families },
};
}
2020-05-24 04:38:24 +05:30
return new Promise((resolve) =>
webFont.load({
classes: false,
active: resolve,
inactive() {
logger.warn('Failed loading the font', {
families,
});
resolve();
},
timeout: 2000,
...config,
}),
);
},
2017-01-25 11:22:19 +05:30
};