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AM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE;QACrC,GAAG;YACD,IAAI,CAAC,qBAAqB,EAAE;gBAC1B,OAAO,CAAC,IAAI,CACV,6LAA6L,CAC9L,CAAC;gBACF,qBAAqB,GAAG,IAAI,CAAC;aAC9B;YACD,OAAO;gBACL,iBAAiB;gBACjB,QAAQ;gBACR,SAAS;gBACT,SAAS;aACV,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;CACJ","sourcesContent":["import { Asset } from 'expo-asset';\nimport Constants from 'expo-constants';\nimport { Platform } from '@unimodules/core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\n\n/**\n * A font source can be a URI, a module ID, or an Expo Asset.\n */\ntype FontSource = string | number | Asset;\n\nconst isWeb = Platform.OS === 'web';\nconst isInClient = !isWeb && Constants.appOwnership === 'expo';\nconst isInIOSStandalone = Constants.appOwnership === 'standalone' && Platform.OS === 'ios';\n\nconst loaded: { [name: string]: boolean } = {};\nconst loadPromises: { [name: string]: Promise<void> } = {};\n\nfunction fontFamilyNeedsScoping(name: string): boolean {\n return (\n (isInClient || isInIOSStandalone) &&\n !Constants.systemFonts.includes(name) &&\n name !== 'System' &&\n !name.includes(Constants.sessionId)\n );\n}\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 */\nexport function processFontFamily(name: string | null): string | null {\n if (!name || !fontFamilyNeedsScoping(name)) {\n return name;\n }\n\n if (!isLoaded(name)) {\n if (__DEV__) {\n if (isLoading(name)) {\n console.error(\n `You started loading the font \"${name}\", 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 \"${name}\" 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(name)}`;\n}\n\nexport function isLoaded(name: string): boolean {\n return loaded.hasOwnProperty(name);\n}\n\nexport function isLoading(name: string): boolean {\n return loadPromises.hasOwnProperty(name);\n}\n\nexport async function loadAsync(\n nameOrMap: string | { [name: string]: FontSource },\n source?: FontSource\n): Promise<void> {\n if (typeof nameOrMap === 'object') {\n const fontMap = nameOrMap;\n const names = Object.keys(fontMap);\n await Promise.all(names.map(name => loadAsync(name, fontMap[name])));\n return;\n }\n\n const name = nameOrMap;\n\n if (loaded[name]) {\n return;\n }\n\n if (loadPromises[name]) {\n return loadPromises[name];\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 if (!source) {\n throw new Error(`No source from which to load font \"${name}\"`);\n }\n const asset = _getAssetForSource(source);\n loadPromises[name] = (async () => {\n try {\n await _loadSingleFontAsync(name, asset);\n loaded[name] = true;\n } finally {\n delete loadPromises[name];\n }\n })();\n\n await loadPromises[name];\n}\n\nfunction _getAssetForSource(source: FontSource): Asset {\n if (source instanceof Asset) {\n return source;\n }\n\n if (!isWeb && typeof source === 'string') {\n return Asset.fromURI(source);\n }\n\n if (isWeb || typeof source === 'number') {\n return Asset.fromModule(source);\n }\n\n // @ts-ignore Error: Type 'string' is not assignable to type 'Asset'\n // We can't have a string here, we would have thrown an error if !isWeb\n // or returned Asset.fromModule if isWeb.\n return source;\n}\n\nasync function _loadSingleFontAsync(name: string, asset: Asset): Promise<void> {\n await asset.downloadAsync();\n if (!asset.downloaded) {\n throw new Error(`Failed to download asset for font \"${name}\"`);\n }\n await ExpoFontLoader.loadAsync(_getNativeFontName(name), asset.localUri);\n}\n\nfunction _getNativeFontName(name: string): string {\n if (fontFamilyNeedsScoping(name)) {\n return `${Constants.sessionId}-${name}`;\n } else {\n return name;\n }\n}\n\ndeclare var module: any;\n\nif (module && module.exports) {\n let wasImportWarningShown = false;\n // @ts-ignore: Temporarily define an export named \"Font\" for legacy compatibility\n Object.defineProperty(exports, 'Font', {\n get() {\n if (!wasImportWarningShown) {\n console.warn(\n `The syntax \"import { Font } from 'expo-font'\" is deprecated. Use \"import * as Font from 'expo-font'\" or import named exports instead. Support for the old syntax will be removed in SDK 33.`\n );\n wasImportWarningShown = true;\n }\n return {\n processFontFamily,\n isLoaded,\n isLoading,\n loadAsync,\n };\n },\n });\n}\n"]}
\No newline at end of file