UNPKG

repoweaver

Version:

A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies

1 lines 8.47 kB
{"ast":null,"code":"import { Platform } from 'expo-modules-core';\nimport PixelRatio from \"react-native-web/dist/exports/PixelRatio\";\nimport NativeModules from \"react-native-web/dist/exports/NativeModules\";\nimport AssetSourceResolver from \"./AssetSourceResolver\";\nimport { getManifest2, manifestBaseUrl } from \"./PlatformUtils\";\nexport function selectAssetSource(meta) {\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex(s => s === scale);\n const hash = meta.fileHashes ? meta.fileHashes[index] ?? meta.fileHashes[0] : meta.hash;\n const uri = meta.fileUris ? meta.fileUris[index] ?? meta.fileUris[0] : meta.uri;\n if (uri) {\n return {\n uri: resolveUri(uri),\n hash\n };\n }\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: Platform.OS,\n hash: meta.hash\n });\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return {\n uri,\n hash\n };\n }\n const manifest2 = getManifest2();\n const devServerUrl = manifest2?.extra?.expoGo?.developer ? 'http://' + manifest2.extra.expoGo.debuggerHost : null;\n if (devServerUrl) {\n const baseUrl = new URL(meta.httpServerLocation + suffix, devServerUrl);\n baseUrl.searchParams.set('platform', Platform.OS);\n baseUrl.searchParams.set('hash', meta.hash);\n return {\n uri: baseUrl.href,\n hash\n };\n }\n if (NativeModules['ExponentKernel']) {\n return {\n uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`,\n hash\n };\n }\n return {\n uri: '',\n hash\n };\n}\nexport function resolveUri(uri) {\n return manifestBaseUrl ? new URL(uri, manifestBaseUrl).href : uri;\n}","map":{"version":3,"names":["Platform","PixelRatio","NativeModules","AssetSourceResolver","getManifest2","manifestBaseUrl","selectAssetSource","meta","scale","pickScale","scales","get","index","findIndex","s","hash","fileHashes","uri","fileUris","resolveUri","fileScale","fileExtension","type","encodeURIComponent","suffix","name","params","URLSearchParams","platform","OS","test","httpServerLocation","manifest2","devServerUrl","extra","expoGo","developer","debuggerHost","baseUrl","URL","searchParams","set","href"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/expo-asset/src/AssetSources.ts"],"sourcesContent":["import type { PackagerAsset } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\nimport { PixelRatio, NativeModules } from 'react-native';\n\nimport AssetSourceResolver from './AssetSourceResolver';\nimport { getManifest2, manifestBaseUrl } from './PlatformUtils';\n\n// @docsMissing\nexport type AssetMetadata = Pick<\n PackagerAsset,\n 'httpServerLocation' | 'name' | 'hash' | 'type' | 'scales' | 'width' | 'height'\n> & {\n uri?: string;\n fileHashes?: string[];\n fileUris?: string[];\n};\n\nexport type AssetSource = {\n uri: string;\n hash: string;\n};\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nexport function selectAssetSource(meta: AssetMetadata): AssetSource {\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? (meta.fileHashes[index] ?? meta.fileHashes[0]) : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? (meta.fileUris[index] ?? meta.fileUris[0]) : meta.uri;\n if (uri) {\n return { uri: resolveUri(uri), hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: Platform.OS,\n hash: meta.hash,\n });\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return { uri, hash };\n }\n\n // For assets during development using manifest2, we use the development server's URL origin\n const manifest2 = getManifest2();\n\n const devServerUrl = manifest2?.extra?.expoGo?.developer\n ? 'http://' + manifest2.extra.expoGo.debuggerHost\n : null;\n if (devServerUrl) {\n const baseUrl = new URL(meta.httpServerLocation + suffix, devServerUrl);\n\n baseUrl.searchParams.set('platform', Platform.OS);\n baseUrl.searchParams.set('hash', meta.hash);\n return {\n uri: baseUrl.href,\n hash,\n };\n }\n\n // Temporary fallback for loading assets in Expo Go home\n if (NativeModules['ExponentKernel']) {\n return { uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`, hash };\n }\n\n // In correctly configured apps, we arrive here if the asset is locally available on disk due to\n // being managed by expo-updates, and `getLocalAssetUri(hash)` must return a local URI for this\n // hash. Since the asset is local, we don't have a remote URL and specify an invalid URL (an empty\n // string) as a placeholder.\n return { uri: '', hash };\n}\n\n/**\n * Resolves the given URI to an absolute URI. If the given URI is already an absolute URI, it is\n * simply returned. Otherwise, if it is a relative URI, it is resolved relative to the manifest's\n * base URI.\n */\nexport function resolveUri(uri: string): string {\n // `manifestBaseUrl` is always an absolute URL or `null`.\n return manifestBaseUrl ? new URL(uri, manifestBaseUrl).href : uri;\n}\n"],"mappings":"AACA,SAASA,QAAQ,QAAQ,mBAAmB;AAAC,OAAAC,UAAA;AAAA,OAAAC,aAAA;AAG7C,OAAOC,mBAAmB;AAC1B,SAASC,YAAY,EAAEC,eAAe;AAuBtC,OAAM,SAAUC,iBAAiBA,CAACC,IAAmB;EAGnD,MAAMC,KAAK,GAAGL,mBAAmB,CAACM,SAAS,CAACF,IAAI,CAACG,MAAM,EAAET,UAAU,CAACU,GAAG,EAAE,CAAC;EAC1E,M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