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AE,GAAG,EAChB,KAAK,EAAE;gBACL,cAAc;gBACd,GAAG,sBAAsB;gBACzB,GAAG,iBAAiB,CAAC,SAAS,CAAC;gBAC/B,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,GAAG,KAAK;aACT;YACD,aAAa;YACb,qDAAqD;YACrD,aAAa,EAAE,iCAAiC,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAClE,2BAA2B,CAAC,MAAM,EAAE,MAAM,CAAC,KAC3C,qBAAqB,CAAC,MAAM,CAAC,KAC7B,KAAK,GACT,CACD,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import React, { useEffect, Ref, useMemo } from 'react';\n\nimport ColorTintFilter, { getTintColorStyle } from './ColorTintFilter';\nimport { ImageWrapperProps } from './ImageWrapper.types';\nimport { getImageWrapperEventHandler } from './getImageWrapperEventHandler';\nimport { absoluteFilledPosition, getObjectPositionFromContentPositionObject } from './positioning';\nimport { SrcSetSource } from './useSourceSelection';\nimport { ImageNativeProps, ImageSource } from '../Image.types';\nimport { useBlurhash } from '../utils/blurhash/useBlurhash';\nimport { isBlurhashString, isThumbhashString } from '../utils/resolveSources';\nimport { thumbHashStringToDataURL } from '../utils/thumbhash/thumbhash';\n\nfunction getFetchPriorityFromImagePriority(priority: ImageNativeProps['priority'] = 'normal') {\n return priority && ['low', 'high'].includes(priority) ? priority : 'auto';\n}\n\nfunction getImgPropsFromSource(source: ImageSource | SrcSetSource | null | undefined) {\n if (source && 'srcset' in source) {\n return {\n srcSet: source.srcset,\n sizes: source.sizes,\n };\n }\n return {};\n}\n\nconst ImageWrapper = React.forwardRef(\n (\n {\n source,\n events,\n contentPosition,\n hashPlaceholderContentPosition,\n priority,\n style,\n hashPlaceholderStyle,\n tintColor,\n className,\n accessibilityLabel,\n ...props\n }: ImageWrapperProps,\n ref: Ref<HTMLImageElement>\n ) => {\n useEffect(() => {\n events?.onMount?.forEach((e) => e?.());\n }, []);\n\n const isBlurhash = isBlurhashString(source?.uri || '');\n const isThumbhash = isThumbhashString(source?.uri || '');\n const isHash = isBlurhash || isThumbhash;\n\n // Thumbhash uri always has to start with 'thumbhash:/'\n const thumbhash = source?.uri?.replace(/thumbhash:\\//, '');\n const thumbhashUri = useMemo(\n () => (isThumbhash ? thumbHashStringToDataURL(thumbhash ?? '') : null),\n [thumbhash]\n );\n\n const blurhashUri = useBlurhash(isBlurhash ? source?.uri : null, source?.width, source?.height);\n if (!source) {\n return null;\n }\n\n const objectPosition = getObjectPositionFromContentPositionObject(\n isHash ? hashPlaceholderContentPosition : contentPosition\n );\n\n const uri = isHash ? blurhashUri ?? thumbhashUri : source?.uri;\n\n return (\n <>\n <ColorTintFilter tintColor={tintColor} />\n <img\n ref={ref}\n alt={accessibilityLabel}\n className={className}\n src={uri || undefined}\n key={source?.uri}\n style={{\n objectPosition,\n ...absoluteFilledPosition,\n ...getTintColorStyle(tintColor),\n ...(isHash ? hashPlaceholderStyle : {}),\n ...style,\n }}\n // @ts-ignore\n // eslint-disable-next-line react/no-unknown-property\n fetchpriority={getFetchPriorityFromImagePriority(priority || 'normal')}\n {...getImageWrapperEventHandler(events, source)}\n {...getImgPropsFromSource(source)}\n {...props}\n />\n </>\n );\n }\n);\n\nexport default ImageWrapper;\n"]}