2017-01-25 11:22:19 +05:30
|
|
|
import webFont from 'webfontloader';
|
2019-12-08 00:32:00 +05:30
|
|
|
import logger from 'app/services/logger';
|
2017-01-25 11:22:19 +05:30
|
|
|
|
|
|
|
export default {
|
2019-11-27 14:33:32 +05:30
|
|
|
/**
|
|
|
|
* @param {Array} families
|
|
|
|
* @param {object} options
|
2019-12-07 16:58:52 +05:30
|
|
|
* @param {boolean} [options.external=false] - whether the font should be loaded from external source (e.g. google)
|
2019-11-27 14:33:32 +05:30
|
|
|
*
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2019-12-07 16:58:52 +05:30
|
|
|
load(
|
|
|
|
families: string[] = [],
|
|
|
|
options: {
|
|
|
|
external?: boolean;
|
|
|
|
} = {},
|
|
|
|
): Promise<void> {
|
|
|
|
let config: { [key: string]: any } = {
|
2019-11-27 14:33:32 +05:30
|
|
|
custom: { families },
|
|
|
|
};
|
2017-01-25 11:48:47 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (options.external) {
|
|
|
|
config = {
|
|
|
|
google: { families },
|
|
|
|
};
|
2017-01-25 11:22:19 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
return new Promise((resolve) =>
|
2019-11-27 14:33:32 +05:30
|
|
|
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
|
|
|
};
|