This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-02 02:24:13 +03:00

45 lines
1.4 KiB
JavaScript

import { CodedError } from '@unimodules/core';
import ExpoFontLoader from './ExpoFontLoader';
import { FontDisplay } from './Font';
function uriFromFontSource(asset) {
if (typeof asset === 'string') {
return asset || null;
}
else if (typeof asset === 'object') {
return asset.uri || asset.localUri || null;
}
return null;
}
function displayFromFontSource(asset) {
return asset.display || FontDisplay.AUTO;
}
export function fontFamilyNeedsScoping(name) {
return false;
}
export function getAssetForSource(source) {
const uri = uriFromFontSource(source);
const display = displayFromFontSource(source);
if (!uri || typeof uri !== 'string') {
throwInvalidSourceError(uri);
}
return {
uri: uri,
display,
};
}
function throwInvalidSourceError(source) {
let type = typeof source;
if (type === 'object')
type = JSON.stringify(source, null, 2);
throw new CodedError(`ERR_FONT_SOURCE`, `Expected font asset of type \`string | FontResource | Asset\` (number is not supported on web) instead got: ${type}`);
}
export async function loadSingleFontAsync(name, input) {
if (typeof input !== 'object' || typeof input.uri !== 'string' || input.downloadAsync) {
throwInvalidSourceError(input);
}
await ExpoFontLoader.loadAsync(name, input);
}
export function getNativeFontName(name) {
return name;
}
//# sourceMappingURL=FontLoader.web.js.map