3b77a8a422a83133cf382ab304b67da3.json
6.87 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.setCustomSourceTransformer=setCustomSourceTransformer;exports.default=resolveAssetSource;exports.pickScale=void 0;var _NativeModules=_interopRequireDefault(require(\"react-native-web/dist/exports/NativeModules\"));var _AssetRegistry=require(\"./AssetRegistry\");var _AssetSourceResolver=_interopRequireDefault(require(\"./AssetSourceResolver\"));var _customSourceTransformer;var _serverURL;var _scriptURL;var _sourceCodeScriptURL;function getSourceCodeScriptURL(){if(_sourceCodeScriptURL){return _sourceCodeScriptURL;}var sourceCode=nativeExtensions&&nativeExtensions.SourceCode;if(!sourceCode){sourceCode=_NativeModules.default&&_NativeModules.default.SourceCode;}_sourceCodeScriptURL=sourceCode.scriptURL;return _sourceCodeScriptURL;}function getDevServerURL(){if(_serverURL===undefined){var sourceCodeScriptURL=getSourceCodeScriptURL();var match=sourceCodeScriptURL&&sourceCodeScriptURL.match(/^https?:\\/\\/.*?\\//);if(match){_serverURL=match[0];}else{_serverURL=null;}}return _serverURL;}function _coerceLocalScriptURL(scriptURL){if(scriptURL){if(scriptURL.startsWith('assets://')){return null;}scriptURL=scriptURL.substring(0,scriptURL.lastIndexOf('/')+1);if(!scriptURL.includes('://')){scriptURL='file://'+scriptURL;}}return null;}function getScriptURL(){if(_scriptURL===undefined){_scriptURL=_coerceLocalScriptURL(getSourceCodeScriptURL());}return _scriptURL;}function setCustomSourceTransformer(transformer){_customSourceTransformer=transformer;}function resolveAssetSource(source){if(typeof source==='object'){return source;}var asset=(0,_AssetRegistry.getAssetByID)(source);if(!asset){return undefined;}var resolver=new _AssetSourceResolver.default(getDevServerURL(),getScriptURL(),asset);if(_customSourceTransformer){return _customSourceTransformer(resolver);}return resolver.defaultAsset();}Object.defineProperty(resolveAssetSource,'setCustomSourceTransformer',{get:function get(){return setCustomSourceTransformer;}});var pickScale=_AssetSourceResolver.default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AAA,YAAT,EAAqB,CACnB,GAAI,UAAU,GAAK,SAAnB,CAA8B,CAC5B,UAAU,CAAG,qBAAqB,CAAC,sBAAsB,EAAvB,CAAlC,CACD,CACD,MAAO,CAAA,UAAP,CACD,CAEK,QAAU,CAAA,0BAAV,CACJ,WADI,CAC+D,CAEnE,wBAAwB,CAAG,WAA3B,CACD,CAMa,QAAU,CAAA,kBAAV,CAA6B,MAA7B,CAAwC,CACpD,GAAI,MAAO,CAAA,MAAP,GAAkB,QAAtB,CAAgC,CAC9B,MAAO,CAAA,MAAP,CACD,CAED,GAAM,CAAA,KAAK,CAAG,gCAAa,MAAb,CAAd,CACA,GAAI,CAAC,KAAL,CAAY,CACV,MAAO,CAAA,SAAP,CACD,CAED,GAAM,CAAA,QAAQ,CAAG,GAAI,6BAAJ,CAAwB,eAAe,EAAvC,CAA2C,YAAY,EAAvD,CAA2D,KAA3D,CAAjB,CACA,GAAI,wBAAJ,CAA8B,CAC5B,MAAO,CAAA,wBAAwB,CAAC,QAAD,CAA/B,CACD,CACD,MAAO,CAAA,QAAQ,CAAC,YAAT,EAAP,CACD,CAED,MAAM,CAAC,cAAP,CAAsB,kBAAtB,CAA0C,4BAA1C,CAAwE,CACtE,GADsE,eACnE,CACD,MAAO,CAAA,0BAAP,CACD,CAHqE,CAAxE,E,GAMe,CAAA,S,CAAc,4B,CAAd,S","sourcesContent":["import { NativeModules } from 'react-native';\nimport { getAssetByID } from './AssetRegistry';\n\nimport AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';\n\ndeclare var nativeExtensions: any;\n\nlet _customSourceTransformer;\nlet _serverURL: string | undefined | null;\nlet _scriptURL: string | undefined | null;\nlet _sourceCodeScriptURL: string | undefined | null;\n\nfunction getSourceCodeScriptURL(): string | undefined | null {\n if (_sourceCodeScriptURL) {\n return _sourceCodeScriptURL;\n }\n\n let sourceCode = nativeExtensions && nativeExtensions.SourceCode;\n if (!sourceCode) {\n sourceCode = NativeModules && NativeModules.SourceCode;\n }\n _sourceCodeScriptURL = sourceCode.scriptURL;\n return _sourceCodeScriptURL;\n}\n\nfunction getDevServerURL(): string | null {\n if (_serverURL === undefined) {\n const sourceCodeScriptURL = getSourceCodeScriptURL();\n const match = sourceCodeScriptURL && sourceCodeScriptURL.match(/^https?:\\/\\/.*?\\//);\n if (match) {\n // jsBundle was loaded from network\n _serverURL = match[0];\n } else {\n // jsBundle was loaded from file\n _serverURL = null;\n }\n }\n return _serverURL;\n}\n\nfunction _coerceLocalScriptURL(scriptURL: string | undefined | null): string | null {\n if (scriptURL) {\n if (scriptURL.startsWith('assets://')) {\n // android: running from within assets, no offline path to use\n return null;\n }\n scriptURL = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);\n if (!scriptURL.includes('://')) {\n // Add file protocol in case we have an absolute file path and not a URL.\n // This shouldn't really be necessary. scriptURL should be a URL.\n scriptURL = 'file://' + scriptURL;\n }\n }\n return null;\n}\n\nfunction getScriptURL(): string | null {\n if (_scriptURL === undefined) {\n _scriptURL = _coerceLocalScriptURL(getSourceCodeScriptURL());\n }\n return _scriptURL;\n}\n\nexport function setCustomSourceTransformer(\n transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource\n): void {\n _customSourceTransformer = transformer;\n}\n\n/**\n * `source` is either a number (opaque type returned by require('./foo.png'))\n * or an `ImageSource` like { uri: '<http location || file path>' }\n */\nexport default function resolveAssetSource(source: any): ResolvedAssetSource | undefined {\n if (typeof source === 'object') {\n return source;\n }\n\n const asset = getAssetByID(source);\n if (!asset) {\n return undefined;\n }\n\n const resolver = new AssetSourceResolver(getDevServerURL(), getScriptURL(), asset);\n if (_customSourceTransformer) {\n return _customSourceTransformer(resolver);\n }\n return resolver.defaultAsset();\n}\n\nObject.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {\n get() {\n return setCustomSourceTransformer;\n },\n});\n\nexport const { pickScale } = AssetSourceResolver;\n"],"sourceRoot":""},"metadata":{},"sourceType":"script"}