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

1 line
11 KiB
Plaintext

{"version":3,"file":"Font.js","sourceRoot":"","sources":["../src/Font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAA+C,MAAM,cAAc,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,GAAgC,EAAE,CAAC;AAC/C,MAAM,YAAY,GAAsC,EAAE,CAAC;AAE3D;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAyB;IACzD,IAAI,CAAC,UAAU,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE;QACtD,OAAO,UAAU,CAAC;KACnB;IAED,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACzB,IAAI,OAAO,EAAE;YACX,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE;gBACzB,OAAO,CAAC,KAAK,CACX,iCAAiC,UAAU;;qIAEgF,CAC5H,CAAC;aACH;iBAAM;gBACL,OAAO,CAAC,KAAK,CACX,eAAe,UAAU;;oEAEiC,CAC3D,CAAC;aACH;SACF;QAED,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,YAAY,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,OAAO,UAAU,IAAI,MAAM,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,UAAkB;IAC1C,OAAO,UAAU,IAAI,YAAY,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,K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,CAAC,CAAC;QACtF,OAAO;KACR;IAED,OAAO,MAAM,0BAA0B,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,KAAK,UAAU,0BAA0B,CACvC,UAAkB,EAClB,OAAkC;IAElC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACvB,OAAO;KACR;SAAM;QACL,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;KAC3B;IAED,+FAA+F;IAC/F,2FAA2F;IAC3F,iGAAiG;IACjG,wBAAwB;IAExB,MAAM,cAAc,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAErD,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,6BAA6B,CAAC,CAAC;KACxE;IAED,MAAM,cAAc,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,OAAO,EAAE,WAAW,EAA+C,CAAC","sourcesContent":["import { CodedError, UnavailabilityError } from '@unimodules/core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontDisplay, FontSource, FontResource, UnloadFontOptions } from './Font.types';\nimport {\n getAssetForSource,\n loadSingleFontAsync,\n fontFamilyNeedsScoping,\n getNativeFontName,\n} from './FontLoader';\n\nconst loaded: { [name: string]: boolean } = {};\nconst loadPromises: { [name: string]: Promise<void> } = {};\n\n/**\n * Used to transform font family names to the scoped name. This does not need to\n * be called in standalone or bare apps but it will return unscoped font family\n * names if it is called in those contexts.\n * note(brentvatne): at some point we may want to warn if this is called\n * outside of a managed app.\n *\n * @param fontFamily name to process\n * @returns a name processed for use with the [current workflow](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/)\n */\nexport function processFontFamily(fontFamily: string | null): string | null {\n if (!fontFamily || !fontFamilyNeedsScoping(fontFamily)) {\n return fontFamily;\n }\n\n if (!isLoaded(fontFamily)) {\n if (__DEV__) {\n if (isLoading(fontFamily)) {\n console.error(\n `You started loading the font \"${fontFamily}\", but used it before it finished loading.\\n\n- You need to wait for Font.loadAsync to complete before using the font.\\n\n- We recommend loading all fonts before rendering the app, and rendering only Expo.AppLoading while waiting for loading to complete.`\n );\n } else {\n console.error(\n `fontFamily \"${fontFamily}\" is not a system font and has not been loaded through Font.loadAsync.\\n\n- If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.\\n\n- If this is a custom font, be sure to load it with Font.loadAsync.`\n );\n }\n }\n\n return 'System';\n }\n\n return `ExpoFont-${getNativeFontName(fontFamily)}`;\n}\n\n/**\n * Synchronously detect if the font for `fontFamily` has finished loading\n *\n * @param fontFamily the name used to load the `FontResource`.\n * @returns `true` if the the font has fully loaded.\n */\nexport function isLoaded(fontFamily: string): boolean {\n return fontFamily in loaded;\n}\n\n/**\n * Synchronously detect if the font for `fontFamily` is still being loaded\n *\n * @param fontFamily the name used to load the `FontResource`.\n * @returns `true` if the the font is still loading.\n */\nexport function isLoading(fontFamily: string): boolean {\n return fontFamily in loadPromises;\n}\n\n/**\n * Natively load a font for use with Text elements.\n * @param fontFamilyOrFontMap string or map of values that can be used as the [`fontFamily`](https://reactnative.dev/docs/text#style) style prop with React Native Text elements.\n * @param source the font asset that should be loaded into the `fontFamily` namespace.\n */\nexport async function loadAsync(\n fontFamilyOrFontMap: string | { [fontFamily: string]: FontSource },\n source?: FontSource\n): Promise<void> {\n if (typeof fontFamilyOrFontMap === 'object') {\n if (source) {\n throw new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided source: ${source}. The second argument of \\`loadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n await Promise.all(names.map(name => loadFontInNamespaceAsync(name, fontMap[name])));\n return;\n }\n\n return await loadFontInNamespaceAsync(fontFamilyOrFontMap, source);\n}\n\nasync function loadFontInNamespaceAsync(\n fontFamily: string,\n source?: FontSource | null\n): Promise<void> {\n if (!source) {\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n `Cannot load null or undefined font source: { \"${fontFamily}\": ${source} }. Expected asset of type \\`FontSource\\` for fontFamily of name: \"${fontFamily}\"`\n );\n }\n\n if (loaded[fontFamily]) {\n return;\n }\n\n if (loadPromises[fontFamily]) {\n return loadPromises[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const asset = getAssetForSource(source);\n loadPromises[fontFamily] = (async () => {\n try {\n await loadSingleFontAsync(fontFamily, asset);\n loaded[fontFamily] = true;\n } finally {\n delete loadPromises[fontFamily];\n }\n })();\n\n await loadPromises[fontFamily];\n}\n\n/**\n * Unloads all of the custom fonts. This is used for testing.\n */\nexport async function unloadAllAsync(): Promise<void> {\n if (!ExpoFontLoader.unloadAllAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAllAsync');\n }\n\n if (Object.keys(loadPromises).length) {\n throw new CodedError(\n `ERR_UNLOAD`,\n `Cannot unload fonts while they're still loading: ${Object.keys(loadPromises).join(', ')}`\n );\n }\n\n for (const fontFamily of Object.keys(loaded)) {\n delete loaded[fontFamily];\n }\n\n await ExpoFontLoader.unloadAllAsync();\n}\n\n/**\n * Unload custom fonts matching the `fontFamily`s and display values provided.\n * Because fonts are automatically unloaded on every platform this is mostly used for testing.\n *\n * @param fontFamilyOrFontMap the names of the custom fonts that will be unloaded.\n * @param source when `fontFamilyOrFontMap` is a string, this should be the font source used to load the custom font originally.\n */\nexport async function unloadAsync(\n fontFamilyOrFontMap: string | { [fontFamily: string]: UnloadFontOptions },\n options?: UnloadFontOptions\n): Promise<void> {\n if (!ExpoFontLoader.unloadAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAsync');\n }\n if (typeof fontFamilyOrFontMap === 'object') {\n if (options) {\n throw new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided options: ${options}. The second argument of \\`unloadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n await Promise.all(names.map(name => unloadFontInNamespaceAsync(name, fontMap[name])));\n return;\n }\n\n return await unloadFontInNamespaceAsync(fontFamilyOrFontMap, options);\n}\n\nasync function unloadFontInNamespaceAsync(\n fontFamily: string,\n options?: UnloadFontOptions | null\n): Promise<void> {\n if (!loaded[fontFamily]) {\n return;\n } else {\n delete loaded[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const nativeFontName = getNativeFontName(fontFamily);\n\n if (!nativeFontName) {\n throw new CodedError(`ERR_FONT_FAMILY`, `Cannot unload an empty name`);\n }\n\n await ExpoFontLoader.unloadAsync(nativeFontName, options);\n}\n\nexport { FontDisplay, FontSource, FontResource, UnloadFontOptions };\n"]}