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,KAAK,CAAC,KAAK;YACvB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;SACpE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB,EAAE,WAAmB;QACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACtC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE;gBAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;aAClB;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { Platform, UnavailabilityError } from '@unimodules/core';\nimport invariant from 'invariant';\nimport { Dimensions } from 'react-native';\n\ntype PackagerAsset = {\n __packager_asset: boolean;\n fileSystemLocation: string;\n httpServerLocation: string;\n width?: number;\n height?: number;\n scales: number[];\n hash: string;\n name: string;\n type: string;\n};\n\nfunction getBasePath({ httpServerLocation }: PackagerAsset): string {\n if (httpServerLocation[0] === '/') {\n return httpServerLocation.substr(1);\n }\n return httpServerLocation;\n}\n\nexport type ResolvedAssetSource = {\n __packager_asset: boolean;\n width?: number;\n height?: number;\n uri: string;\n scale: number;\n};\n\nfunction getScale(): number {\n return Dimensions.get('window').scale;\n}\n\nfunction getScaledAssetPath(asset): string {\n const scale = AssetSourceResolver.pickScale(asset.scales, getScale());\n const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';\n const assetDir = getBasePath(asset);\n return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;\n}\n\nexport default class AssetSourceResolver {\n serverUrl?: string | null;\n // where the jsbundle is being run from\n jsbundleUrl?: string | null;\n // the asset to resolve\n asset: PackagerAsset;\n\n constructor(\n serverUrl: string | undefined | null,\n jsbundleUrl: string | undefined | null,\n asset: PackagerAsset\n ) {\n this.serverUrl = serverUrl;\n this.jsbundleUrl = jsbundleUrl;\n this.asset = asset;\n }\n isLoadedFromServer(): boolean {\n return !!this.serverUrl;\n }\n isLoadedFromFileSystem(): boolean {\n return !!(this.jsbundleUrl && this.jsbundleUrl.startsWith('file://'));\n }\n defaultAsset(): ResolvedAssetSource {\n if (this.isLoadedFromServer()) {\n return this.assetServerURL();\n }\n\n return this.scaledAssetURLNearBundle();\n }\n assetServerURL(): ResolvedAssetSource {\n invariant(!!this.serverUrl, 'need server to load from');\n return this.fromSource(\n this.serverUrl +\n getScaledAssetPath(this.asset) +\n '?platform=' +\n Platform.OS +\n '&hash=' +\n this.asset.hash\n );\n }\n scaledAssetPath(): ResolvedAssetSource {\n return this.fromSource(getScaledAssetPath(this.asset));\n }\n scaledAssetURLNearBundle(): ResolvedAssetSource {\n const path = this.jsbundleUrl || 'file://';\n return this.fromSource(path + getScaledAssetPath(this.asset));\n }\n resourceIdentifierWithoutScale(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'resourceIdentifierWithoutScale()');\n }\n drawableFolderInBundle(): ResolvedAssetSource {\n throw new UnavailabilityError('react-native', 'drawableFolderInBundle()');\n }\n fromSource(source: string): ResolvedAssetSource {\n return {\n __packager_asset: true,\n width: this.asset.width,\n height: this.asset.height,\n uri: source,\n scale: AssetSourceResolver.pickScale(this.asset.scales, getScale()),\n };\n }\n\n static pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n }\n}\n"]} |