You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
19 KiB
1 line
19 KiB
{"ast":null,"code":"import _asyncToGenerator from \"@babel/runtime/helpers/asyncToGenerator\";\nimport _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport { Platform } from 'expo-modules-core';\nimport { getAssetByID } from \"./AssetRegistry\";\nimport { selectAssetSource } from \"./AssetSources\";\nimport * as AssetUris from \"./AssetUris\";\nimport * as ImageAssets from \"./ImageAssets\";\nimport { getLocalAssetUri } from \"./LocalAssets\";\nimport { downloadAsync as _downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from \"./PlatformUtils\";\nimport resolveAssetSource from \"./resolveAssetSource\";\nexport var Asset = function () {\n function Asset(_ref) {\n var name = _ref.name,\n type = _ref.type,\n _ref$hash = _ref.hash,\n hash = _ref$hash === void 0 ? null : _ref$hash,\n uri = _ref.uri,\n width = _ref.width,\n height = _ref.height;\n _classCallCheck(this, Asset);\n this.hash = null;\n this.localUri = null;\n this.width = null;\n this.height = null;\n this.downloading = false;\n this.downloaded = false;\n this._downloadCallbacks = [];\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n _createClass(Asset, [{\n key: \"downloadAsync\",\n value: function () {\n var _downloadAsync2 = _asyncToGenerator(function* () {\n var _this = this;\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n yield new Promise(function (resolve, reject) {\n _this._downloadCallbacks.push({\n resolve: resolve,\n reject: reject\n });\n });\n return this;\n }\n this.downloading = true;\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n var _yield$ImageAssets$ge = yield ImageAssets.getImageInfoAsync(this.uri),\n width = _yield$ImageAssets$ge.width,\n height = _yield$ImageAssets$ge.height,\n name = _yield$ImageAssets$ge.name;\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = yield _downloadAsync(this.uri, this.hash, this.type, this.name);\n this.downloaded = true;\n this._downloadCallbacks.forEach(function (_ref2) {\n var resolve = _ref2.resolve;\n return resolve();\n });\n } catch (e) {\n this._downloadCallbacks.forEach(function (_ref3) {\n var reject = _ref3.reject;\n return reject(e);\n });\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n });\n function downloadAsync() {\n return _downloadAsync2.apply(this, arguments);\n }\n return downloadAsync;\n }()\n }], [{\n key: \"loadAsync\",\n value: function loadAsync(moduleId) {\n var moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map(function (moduleId) {\n return Asset.fromModule(moduleId).downloadAsync();\n }));\n }\n }, {\n key: \"fromModule\",\n value: function fromModule(virtualAssetModule) {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n var meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(\"Module \\\"\" + virtualAssetModule + \"\\\" is missing from the asset registry\");\n }\n if (!IS_ENV_WITH_UPDATES_ENABLED) {\n var _resolveAssetSource = resolveAssetSource(virtualAssetModule),\n uri = _resolveAssetSource.uri;\n var asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri: uri,\n width: meta.width,\n height: meta.height\n });\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n return Asset.fromMetadata(meta);\n }\n }, {\n key: \"fromMetadata\",\n value: function fromMetadata(meta) {\n var metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n var _selectAssetSource = selectAssetSource(meta),\n uri = _selectAssetSource.uri,\n hash = _selectAssetSource.hash;\n var asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: hash,\n uri: uri,\n width: meta.width,\n height: meta.height\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n }, {\n key: \"fromURI\",\n value: function fromURI(uri) {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n var type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n var extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n var asset = new Asset({\n name: '',\n type: type,\n hash: null,\n uri: uri\n });\n Asset.byUri[uri] = asset;\n return asset;\n }\n }]);\n return Asset;\n}();\nAsset.byHash = {};\nAsset.byUri = {};","map":{"version":3,"sources":["../src/Asset.ts"],"names":[],"mappings":";;;AAAA,SAAS,QAAQ,QAAQ,mBAAmB;AAE5C,SAAS,YAAY;AACrB,SAAwB,iBAAiB;AACzC,OAAO,KAAK,SAAS;AACrB,OAAO,KAAK,WAAW;AACvB,SAAS,gBAAgB;AACzB,SAAS,aAAa,IAAb,cAAa,EAAE,2BAA2B;AACnD,OAAO,kBAAkB;AAwBzB,WAAa,KAAK;EAsDhB,qBAA4E;IAAA,IAA9D,IAAI,QAAJ,IAAI;MAAE,IAAI,QAAJ,IAAI;MAAA,iBAAE,IAAI;MAAJ,IAAI,0BAAG,IAAI;MAAE,GAAG,QAAH,GAAG;MAAE,KAAK,QAAL,KAAK;MAAE,MAAM,QAAN,MAAM;IAAA;IAAA,KAhCzD,IAAI,GAAkB,IAAI;IAAA,KAY1B,QAAQ,GAAkB,IAAI;IAAA,KAK9B,KAAK,GAAkB,IAAI;IAAA,KAI3B,MAAM,GAAkB,IAAI;IAAA,KAE5B,WAAW,GAAY,KAAK;IAAA,KAE5B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MAEF,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK;MAExB,OAAO,KAAK;IACd;EAAC;EAAA;AAAA;AAlMU,KAAK,CAIT,MAAM,GAAG,CAAA,CAAE;AAJP,KAAK,CAQT,KAAK,GAAG,CAAA,CAAE","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport { getAssetByID } from './AssetRegistry';\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { downloadAsync, IS_ENV_WITH_UPDATES_ENABLED } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n// @needsAudit\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n /**\n * @private\n */\n static byHash = {};\n /**\n * @private\n */\n static byUri = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n name: string;\n /**\n * The extension of the asset filename.\n */\n type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer.\n */\n uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n height: number | null = null;\n // @docsMissing\n downloading: boolean = false;\n // @docsMissing\n downloaded: boolean = false;\n\n /**\n * @private\n */\n _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(virtualAssetModule: number | string): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_UPDATES_ENABLED) {\n const { uri } = resolveAssetSource(virtualAssetModule);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // TODO: FileSystem should probably support 'downloading' from drawable\n // resources But for now it doesn't (it only supports raw resources) and\n // React Native's Image works fine with drawable resource names for\n // images.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#assetlocaluri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type, this.name);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"} |