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I,IAAI,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,OAAO,CAAkB,CAAC;KACpE;IACD,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAkB,CAAC;AACnE,CAAC","sourcesContent":["import { ImageNativeProps, ImageProps, ImageSource } from '../Image.types';\nimport resolveAssetSource from './resolveAssetSource';\nimport { resolveBlurhashString, resolveThumbhashString } from './resolveHashString';\n\nexport function isBlurhashString(str: string): boolean {\n  return /^(blurhash:\\/)?[\\w#$%*+,\\-.:;=?@[\\]^_{}|~]+(\\/[\\d.]+)*$/.test(str);\n}\n\n// Base64 strings will be recognized as blurhash by default (to keep compatibility),\n// interpret as thumbhash only if correct uri scheme is provided\nexport function isThumbhashString(str: string): boolean {\n  return str.startsWith('thumbhash:/');\n}\n\nfunction resolveSource(source?: ImageSource | string | number | null): ImageSource | null {\n  if (typeof source === 'string') {\n    if (isBlurhashString(source)) {\n      return resolveBlurhashString(source);\n    } else if (isThumbhashString(source)) {\n      return resolveThumbhashString(source);\n    }\n    return { uri: source };\n  }\n  if (typeof source === 'number') {\n    return resolveAssetSource(source);\n  }\n  if (typeof source === 'object' && (source?.blurhash || source?.thumbhash)) {\n    const { blurhash, thumbhash, ...restSource } = source;\n    const resolved = thumbhash\n      ? resolveThumbhashString(thumbhash)\n      : resolveBlurhashString(blurhash as string);\n    return {\n      ...resolved,\n      ...restSource,\n    };\n  }\n  return source ?? null;\n}\n\n/**\n * Resolves provided `source` prop to an array of objects expected by the native implementation.\n */\nexport function resolveSources(sources?: ImageProps['source']): ImageNativeProps['source'] {\n  if (Array.isArray(sources)) {\n    return sources.map(resolveSource).filter(Boolean) as ImageSource[];\n  }\n  return [resolveSource(sources)].filter(Boolean) as ImageSource[];\n}\n"]}