mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-19 14:42:58 +05:30
44 lines
908 B
TypeScript
44 lines
908 B
TypeScript
import webFont from 'webfontloader';
|
|
import logger from 'app/services/logger';
|
|
|
|
export default {
|
|
/**
|
|
* @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 },
|
|
};
|
|
|
|
if (options.external) {
|
|
config = {
|
|
google: { families },
|
|
};
|
|
}
|
|
|
|
return new Promise((resolve) =>
|
|
webFont.load({
|
|
classes: false,
|
|
active: resolve,
|
|
inactive() {
|
|
logger.warn('Failed loading the font', {
|
|
families,
|
|
});
|
|
resolve();
|
|
},
|
|
timeout: 2000,
|
|
...config,
|
|
}),
|
|
);
|
|
},
|
|
};
|