@amazon-devices/expo-image 2.0.1758683737

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +285 -0
  3. package/CMakeLists.txt +91 -0
  4. package/LICENSE +7 -0
  5. package/README.kepler.md +123 -0
  6. package/README.md +54 -0
  7. package/THIRD_PARTY_NOTICES.txt +24 -0
  8. package/android/build.gradle +124 -0
  9. package/android/proguard-rules.pro +28 -0
  10. package/android/src/main/AndroidManifest.xml +15 -0
  11. package/android/src/main/java/expo/modules/image/Exceptions.kt +9 -0
  12. package/android/src/main/java/expo/modules/image/ExpoImageAppGlideModule.kt +19 -0
  13. package/android/src/main/java/expo/modules/image/ExpoImageModule.kt +192 -0
  14. package/android/src/main/java/expo/modules/image/ExpoImageView.kt +220 -0
  15. package/android/src/main/java/expo/modules/image/ExpoImageViewWrapper.kt +652 -0
  16. package/android/src/main/java/expo/modules/image/GlideModel.kt +73 -0
  17. package/android/src/main/java/expo/modules/image/ImageUtils.kt +50 -0
  18. package/android/src/main/java/expo/modules/image/ImageViewWrapperTarget.kt +313 -0
  19. package/android/src/main/java/expo/modules/image/ResourceIdHelper.kt +47 -0
  20. package/android/src/main/java/expo/modules/image/ThumbnailRequestCoordinatorExtension.kt +21 -0
  21. package/android/src/main/java/expo/modules/image/YogaUtils.kt +20 -0
  22. package/android/src/main/java/expo/modules/image/blurhash/BlurHashFetcher.kt +32 -0
  23. package/android/src/main/java/expo/modules/image/blurhash/BlurhashDecoder.kt +189 -0
  24. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoader.kt +30 -0
  25. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoaderFactory.kt +14 -0
  26. package/android/src/main/java/expo/modules/image/blurhash/BlurhashModule.kt +17 -0
  27. package/android/src/main/java/expo/modules/image/dataurls/Base64DataFetcher.kt +27 -0
  28. package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoader.kt +24 -0
  29. package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoaderFactory.kt +12 -0
  30. package/android/src/main/java/expo/modules/image/dataurls/Base64Module.kt +16 -0
  31. package/android/src/main/java/expo/modules/image/drawing/OutlineProvider.kt +201 -0
  32. package/android/src/main/java/expo/modules/image/enums/ContentFit.kt +89 -0
  33. package/android/src/main/java/expo/modules/image/enums/ImageCacheType.kt +14 -0
  34. package/android/src/main/java/expo/modules/image/enums/Priority.kt +15 -0
  35. package/android/src/main/java/expo/modules/image/events/GlideRequestListener.kt +64 -0
  36. package/android/src/main/java/expo/modules/image/events/OkHttpProgressListener.kt +26 -0
  37. package/android/src/main/java/expo/modules/image/okhttp/ExpoImageOkHttpClientGlideModule.kt +80 -0
  38. package/android/src/main/java/expo/modules/image/okhttp/GlideUrlWrapperLoader.kt +55 -0
  39. package/android/src/main/java/expo/modules/image/records/CachePolicy.kt +10 -0
  40. package/android/src/main/java/expo/modules/image/records/ContentPosition.kt +89 -0
  41. package/android/src/main/java/expo/modules/image/records/ImageTransition.kt +8 -0
  42. package/android/src/main/java/expo/modules/image/records/SourceMap.kt +160 -0
  43. package/android/src/main/java/expo/modules/image/records/events.kt +25 -0
  44. package/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt +33 -0
  45. package/android/src/main/java/expo/modules/image/svg/SVGDrawableTranscoder.kt +37 -0
  46. package/android/src/main/java/expo/modules/image/svg/SVGModule.kt +26 -0
  47. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashDecoder.kt +365 -0
  48. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashFetcher.kt +31 -0
  49. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoader.kt +26 -0
  50. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoaderFactory.kt +14 -0
  51. package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModule.kt +17 -0
  52. package/build/ExpoImage.d.ts +15 -0
  53. package/build/ExpoImage.d.ts.map +1 -0
  54. package/build/ExpoImage.js +75 -0
  55. package/build/ExpoImage.js.map +1 -0
  56. package/build/ExpoImage.kepler.d.ts +23 -0
  57. package/build/ExpoImage.kepler.d.ts.map +1 -0
  58. package/build/ExpoImage.kepler.js +71 -0
  59. package/build/ExpoImage.kepler.js.map +1 -0
  60. package/build/ExpoImage.web.d.ts +9 -0
  61. package/build/ExpoImage.web.d.ts.map +1 -0
  62. package/build/ExpoImage.web.js +90 -0
  63. package/build/ExpoImage.web.js.map +1 -0
  64. package/build/ExpoImageModules.d.ts +3 -0
  65. package/build/ExpoImageModules.d.ts.map +1 -0
  66. package/build/ExpoImageModules.js +4 -0
  67. package/build/ExpoImageModules.js.map +1 -0
  68. package/build/ExpoImageModules.kepler.d.ts +6 -0
  69. package/build/ExpoImageModules.kepler.d.ts.map +1 -0
  70. package/build/ExpoImageModules.kepler.js +5 -0
  71. package/build/ExpoImageModules.kepler.js.map +1 -0
  72. package/build/Image.d.ts +30 -0
  73. package/build/Image.d.ts.map +1 -0
  74. package/build/Image.js +49 -0
  75. package/build/Image.js.map +1 -0
  76. package/build/Image.types.d.ts +374 -0
  77. package/build/Image.types.d.ts.map +1 -0
  78. package/build/Image.types.js +2 -0
  79. package/build/Image.types.js.map +1 -0
  80. package/build/ImageBackground.d.ts +6 -0
  81. package/build/ImageBackground.d.ts.map +1 -0
  82. package/build/ImageBackground.js +13 -0
  83. package/build/ImageBackground.js.map +1 -0
  84. package/build/ImageViewNativeComponent.d.ts +20 -0
  85. package/build/ImageViewNativeComponent.d.ts.map +1 -0
  86. package/build/ImageViewNativeComponent.js +42 -0
  87. package/build/ImageViewNativeComponent.js.map +1 -0
  88. package/build/NativeImageLoaderKepler.d.ts +18 -0
  89. package/build/NativeImageLoaderKepler.d.ts.map +1 -0
  90. package/build/NativeImageLoaderKepler.js +3 -0
  91. package/build/NativeImageLoaderKepler.js.map +1 -0
  92. package/build/fabric/registerNativeComponent.d.ts +15 -0
  93. package/build/fabric/registerNativeComponent.d.ts.map +1 -0
  94. package/build/fabric/registerNativeComponent.js +47 -0
  95. package/build/fabric/registerNativeComponent.js.map +1 -0
  96. package/build/index.d.ts +4 -0
  97. package/build/index.d.ts.map +1 -0
  98. package/build/index.js +4 -0
  99. package/build/index.js.map +1 -0
  100. package/build/utils/AssetSourceResolver.web.d.ts +24 -0
  101. package/build/utils/AssetSourceResolver.web.d.ts.map +1 -0
  102. package/build/utils/AssetSourceResolver.web.js +67 -0
  103. package/build/utils/AssetSourceResolver.web.js.map +1 -0
  104. package/build/utils/blurhash/base83.d.ts +3 -0
  105. package/build/utils/blurhash/base83.d.ts.map +1 -0
  106. package/build/utils/blurhash/base83.js +103 -0
  107. package/build/utils/blurhash/base83.js.map +1 -0
  108. package/build/utils/blurhash/decode.d.ts +7 -0
  109. package/build/utils/blurhash/decode.d.ts.map +1 -0
  110. package/build/utils/blurhash/decode.js +92 -0
  111. package/build/utils/blurhash/decode.js.map +1 -0
  112. package/build/utils/blurhash/error.d.ts +4 -0
  113. package/build/utils/blurhash/error.d.ts.map +1 -0
  114. package/build/utils/blurhash/error.js +8 -0
  115. package/build/utils/blurhash/error.js.map +1 -0
  116. package/build/utils/blurhash/useBlurhash.d.ts +8 -0
  117. package/build/utils/blurhash/useBlurhash.d.ts.map +1 -0
  118. package/build/utils/blurhash/useBlurhash.js +64 -0
  119. package/build/utils/blurhash/useBlurhash.js.map +1 -0
  120. package/build/utils/blurhash/utils.d.ts +5 -0
  121. package/build/utils/blurhash/utils.d.ts.map +1 -0
  122. package/build/utils/blurhash/utils.js +21 -0
  123. package/build/utils/blurhash/utils.js.map +1 -0
  124. package/build/utils/resolveAssetSource.d.ts +3 -0
  125. package/build/utils/resolveAssetSource.d.ts.map +1 -0
  126. package/build/utils/resolveAssetSource.js +3 -0
  127. package/build/utils/resolveAssetSource.js.map +1 -0
  128. package/build/utils/resolveAssetSource.web.d.ts +9 -0
  129. package/build/utils/resolveAssetSource.web.d.ts.map +1 -0
  130. package/build/utils/resolveAssetSource.web.js +31 -0
  131. package/build/utils/resolveAssetSource.web.js.map +1 -0
  132. package/build/utils/resolveHashString.d.ts +14 -0
  133. package/build/utils/resolveHashString.d.ts.map +1 -0
  134. package/build/utils/resolveHashString.js +31 -0
  135. package/build/utils/resolveHashString.js.map +1 -0
  136. package/build/utils/resolveHashString.web.d.ts +20 -0
  137. package/build/utils/resolveHashString.web.d.ts.map +1 -0
  138. package/build/utils/resolveHashString.web.js +31 -0
  139. package/build/utils/resolveHashString.web.js.map +1 -0
  140. package/build/utils/resolveSources.d.ts +8 -0
  141. package/build/utils/resolveSources.d.ts.map +1 -0
  142. package/build/utils/resolveSources.js +45 -0
  143. package/build/utils/resolveSources.js.map +1 -0
  144. package/build/utils/thumbhash/thumbhash.d.ts +66 -0
  145. package/build/utils/thumbhash/thumbhash.d.ts.map +1 -0
  146. package/build/utils/thumbhash/thumbhash.js +338 -0
  147. package/build/utils/thumbhash/thumbhash.js.map +1 -0
  148. package/build/utils.d.ts +17 -0
  149. package/build/utils.d.ts.map +1 -0
  150. package/build/utils.js +85 -0
  151. package/build/utils.js.map +1 -0
  152. package/build/web/AnimationManager.d.ts +37 -0
  153. package/build/web/AnimationManager.d.ts.map +1 -0
  154. package/build/web/AnimationManager.js +155 -0
  155. package/build/web/AnimationManager.js.map +1 -0
  156. package/build/web/ColorTintFilter.d.ts +12 -0
  157. package/build/web/ColorTintFilter.d.ts.map +1 -0
  158. package/build/web/ColorTintFilter.js +30 -0
  159. package/build/web/ColorTintFilter.js.map +1 -0
  160. package/build/web/ImageWrapper.d.ts +5 -0
  161. package/build/web/ImageWrapper.d.ts.map +1 -0
  162. package/build/web/ImageWrapper.js +44 -0
  163. package/build/web/ImageWrapper.js.map +1 -0
  164. package/build/web/ImageWrapper.types.d.ts +29 -0
  165. package/build/web/ImageWrapper.types.d.ts.map +1 -0
  166. package/build/web/ImageWrapper.types.js +2 -0
  167. package/build/web/ImageWrapper.types.js.map +1 -0
  168. package/build/web/getImageWrapperEventHandler.d.ts +8 -0
  169. package/build/web/getImageWrapperEventHandler.d.ts.map +1 -0
  170. package/build/web/getImageWrapperEventHandler.js +25 -0
  171. package/build/web/getImageWrapperEventHandler.js.map +1 -0
  172. package/build/web/hooks.d.ts +13 -0
  173. package/build/web/hooks.d.ts.map +1 -0
  174. package/build/web/hooks.js +58 -0
  175. package/build/web/hooks.js.map +1 -0
  176. package/build/web/imageStyles.d.ts +2 -0
  177. package/build/web/imageStyles.d.ts.map +1 -0
  178. package/build/web/imageStyles.js +137 -0
  179. package/build/web/imageStyles.js.map +1 -0
  180. package/build/web/positioning.d.ts +11 -0
  181. package/build/web/positioning.d.ts.map +1 -0
  182. package/build/web/positioning.js +35 -0
  183. package/build/web/positioning.js.map +1 -0
  184. package/build/web/useSourceSelection.d.ts +14 -0
  185. package/build/web/useSourceSelection.d.ts.map +1 -0
  186. package/build/web/useSourceSelection.js +98 -0
  187. package/build/web/useSourceSelection.js.map +1 -0
  188. package/expo-module.config.json +9 -0
  189. package/ios/Blurhash.swift +326 -0
  190. package/ios/BlurhashLoader.swift +52 -0
  191. package/ios/ContentFit.swift +55 -0
  192. package/ios/ContentPosition.swift +108 -0
  193. package/ios/ExpoImage.podspec +30 -0
  194. package/ios/ImageCachePolicy.swift +24 -0
  195. package/ios/ImageCacheType.swift +21 -0
  196. package/ios/ImageModule.swift +127 -0
  197. package/ios/ImagePriority.swift +22 -0
  198. package/ios/ImageSource.swift +44 -0
  199. package/ios/ImageTransition.swift +67 -0
  200. package/ios/ImageUtils.swift +227 -0
  201. package/ios/ImageView.swift +469 -0
  202. package/ios/Loaders/PhotoLibraryAssetLoader.swift +146 -0
  203. package/ios/Thumbhash.swift +550 -0
  204. package/ios/ThumbhashLoader.swift +53 -0
  205. package/jest.config.js +3 -0
  206. package/kepler/ExpoImage.cpp +63 -0
  207. package/kepler/ExpoImage.h +29 -0
  208. package/kepler/ExpoImageCacheHandler.cpp +15 -0
  209. package/kepler/ExpoImageCacheHandler.h +28 -0
  210. package/kepler/ExpoImageComponent.cpp +579 -0
  211. package/kepler/ExpoImageComponent.h +199 -0
  212. package/kepler/ImageWrapper/BlurhashImageWrapper.cpp +37 -0
  213. package/kepler/ImageWrapper/BlurhashImageWrapper.h +23 -0
  214. package/kepler/ImageWrapper/CacheImageWrapper.cpp +80 -0
  215. package/kepler/ImageWrapper/CacheImageWrapper.h +41 -0
  216. package/kepler/ImageWrapper/HashImageWrapper.cpp +21 -0
  217. package/kepler/ImageWrapper/HashImageWrapper.h +22 -0
  218. package/kepler/ImageWrapper/ImageWrapper.cpp +24 -0
  219. package/kepler/ImageWrapper/ImageWrapper.h +33 -0
  220. package/kepler/ImageWrapper/LocalImageWrapper.cpp +61 -0
  221. package/kepler/ImageWrapper/LocalImageWrapper.h +30 -0
  222. package/kepler/ImageWrapper/ThumbhashImageWrapper.cpp +33 -0
  223. package/kepler/ImageWrapper/ThumbhashImageWrapper.h +20 -0
  224. package/kepler/KeplerImageViewComponent.h +64 -0
  225. package/kepler/KeplerInit.cpp +35 -0
  226. package/kepler/blurhash/common.h +32 -0
  227. package/kepler/blurhash/decode.cpp +187 -0
  228. package/kepler/blurhash/decode.h +58 -0
  229. package/kepler/contentposition/ImageContentPosition.cpp +86 -0
  230. package/kepler/contentposition/ImageContentPosition.h +48 -0
  231. package/kepler/enums/ImageContentFit.h +17 -0
  232. package/kepler/enums/ImagePriority.h +17 -0
  233. package/kepler/managers/ExpoImageManager.cpp +38 -0
  234. package/kepler/managers/ExpoImageManager.h +23 -0
  235. package/kepler/test/ExpoImage.cpp +73 -0
  236. package/kepler/test/ExpoImageComponent.cpp +290 -0
  237. package/kepler/test/blurhash/decode.cpp +39 -0
  238. package/kepler/test/contentposition/ImageContentPosition.cpp +100 -0
  239. package/kepler/test/managers/ExpoImageManager.cpp +39 -0
  240. package/kepler/test/thumbhash/decode.cpp +18 -0
  241. package/kepler/test/utils/LoaderDelegate.cpp +130 -0
  242. package/kepler/thumbhash/decode.cpp +166 -0
  243. package/kepler/thumbhash/decode.h +22 -0
  244. package/kepler/utils/PlaceholderImageLoaderDelegate.cpp +26 -0
  245. package/kepler/utils/PlaceholderImageLoaderDelegate.h +26 -0
  246. package/kepler/utils/PrefetchImageLoaderDelegate.cpp +55 -0
  247. package/kepler/utils/PrefetchImageLoaderDelegate.h +35 -0
  248. package/kepler/utils/SourceImageLoaderDelegate.cpp +47 -0
  249. package/kepler/utils/SourceImageLoaderDelegate.h +42 -0
  250. package/kepler/utils/SourceImageLoaderDelegateEmitter.cpp +15 -0
  251. package/kepler/utils/SourceImageLoaderDelegateEmitter.h +28 -0
  252. package/kepler-compatibility.json +8 -0
  253. package/package.json +1 -0
  254. package/react-native.config.js +22 -0
  255. package/src/ExpoImage.kepler.tsx +119 -0
  256. package/src/ExpoImage.tsx +119 -0
  257. package/src/ExpoImage.web.tsx +155 -0
  258. package/src/ExpoImageModules.kepler.ts +7 -0
  259. package/src/ExpoImageModules.ts +4 -0
  260. package/src/Image.tsx +82 -0
  261. package/src/Image.types.ts +450 -0
  262. package/src/ImageBackground.tsx +18 -0
  263. package/src/ImageViewNativeComponent.ts +59 -0
  264. package/src/NativeImageLoaderKepler.ts +22 -0
  265. package/src/fabric/registerNativeComponent.ts +70 -0
  266. package/src/index.ts +3 -0
  267. package/src/utils/AssetSourceResolver.web.ts +88 -0
  268. package/src/utils/blurhash/base83.ts +104 -0
  269. package/src/utils/blurhash/decode.ts +114 -0
  270. package/src/utils/blurhash/error.ts +7 -0
  271. package/src/utils/blurhash/useBlurhash.tsx +81 -0
  272. package/src/utils/blurhash/utils.ts +21 -0
  273. package/src/utils/resolveAssetSource.tsx +3 -0
  274. package/src/utils/resolveAssetSource.web.ts +40 -0
  275. package/src/utils/resolveHashString.tsx +36 -0
  276. package/src/utils/resolveHashString.web.tsx +33 -0
  277. package/src/utils/resolveSources.tsx +48 -0
  278. package/src/utils/thumbhash/thumbhash.ts +387 -0
  279. package/src/utils.ts +109 -0
  280. package/src/web/AnimationManager.tsx +224 -0
  281. package/src/web/ColorTintFilter.tsx +36 -0
  282. package/src/web/ImageWrapper.tsx +85 -0
  283. package/src/web/ImageWrapper.types.ts +36 -0
  284. package/src/web/getImageWrapperEventHandler.ts +29 -0
  285. package/src/web/hooks.ts +72 -0
  286. package/src/web/imageStyles.tsx +136 -0
  287. package/src/web/positioning.ts +48 -0
  288. package/src/web/useSourceSelection.ts +151 -0
  289. package/tsconfig.json +9 -0
@@ -0,0 +1,58 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { useBlurhash } from '../utils/blurhash/useBlurhash';
3
+ import { isThumbhashString } from '../utils/resolveSources';
4
+ import { thumbHashStringToDataURL } from '../utils/thumbhash/thumbhash';
5
+ export function useThumbhash(source) {
6
+ const isThumbhash = isThumbhashString(source?.uri || '');
7
+ const strippedThumbhashString = source?.uri?.replace(/thumbhash:\//, '') ?? '';
8
+ const thumbhashSource = useMemo(() => (isThumbhash ? { uri: thumbHashStringToDataURL(strippedThumbhashString) } : null), [strippedThumbhashString, isThumbhash]);
9
+ return thumbhashSource;
10
+ }
11
+ export function useImageHashes(source) {
12
+ const thumbhash = useThumbhash(source);
13
+ const blurhash = useBlurhash(source);
14
+ return useMemo(() => ({
15
+ resolvedSource: blurhash ?? thumbhash ?? source,
16
+ isImageHash: !!blurhash || !!thumbhash,
17
+ }), [blurhash, thumbhash]);
18
+ }
19
+ export function useHeaders(source, cachePolicy, onError) {
20
+ const [objectURL, setObjectURL] = useState(null);
21
+ useEffect(() => {
22
+ (async () => {
23
+ if (!source?.headers || !source.uri) {
24
+ return;
25
+ }
26
+ try {
27
+ const result = await fetch(source.uri, {
28
+ headers: source.headers,
29
+ cache: cachePolicy === 'none' ? 'no-cache' : 'default',
30
+ redirect: 'follow',
31
+ });
32
+ if (!result.ok) {
33
+ throw new Error(`Failed to fetch image: ${result.status} ${result.statusText}`);
34
+ }
35
+ const blob = await result.blob();
36
+ setObjectURL((prevObjURL) => {
37
+ if (prevObjURL) {
38
+ URL.revokeObjectURL(prevObjURL);
39
+ }
40
+ return URL.createObjectURL(blob);
41
+ });
42
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
+ }
44
+ catch (error) {
45
+ onError?.forEach((e) => e?.({ source }));
46
+ }
47
+ })();
48
+ }, [source]);
49
+ if (!source?.headers) {
50
+ return source;
51
+ }
52
+ if (!objectURL) {
53
+ // Avoid fetching a URL without headers if we have headers
54
+ return null;
55
+ }
56
+ return { ...source, uri: objectURL };
57
+ }
58
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/web/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIrD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExE,MAAM,UAAU,YAAY,CAAC,MAAsC;IACjE,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACzD,MAAM,uBAAuB,GAAG,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,wBAAwB,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EACvF,CAAC,uBAAuB,EAAE,WAAW,CAAC,CACvC,CAAC;IACF,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAsC;IACnE,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,WA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C,CAAC,CAAC,CAAC;gBACH,6DAA6D;YAC/D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,0DAA0D;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;AACvC,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from 'react';\n\nimport { OnErrorEvent } from './ImageWrapper.types';\nimport { ImageNativeProps, ImageSource } from '../Image.types';\nimport { useBlurhash } from '../utils/blurhash/useBlurhash';\nimport { isThumbhashString } from '../utils/resolveSources';\nimport { thumbHashStringToDataURL } from '../utils/thumbhash/thumbhash';\n\nexport function useThumbhash(source: ImageSource | null | undefined) {\n const isThumbhash = isThumbhashString(source?.uri || '');\n const strippedThumbhashString = source?.uri?.replace(/thumbhash:\\//, '') ?? '';\n const thumbhashSource = useMemo(\n () => (isThumbhash ? { uri: thumbHashStringToDataURL(strippedThumbhashString) } : null),\n [strippedThumbhashString, isThumbhash]\n );\n return thumbhashSource;\n}\n\nexport function useImageHashes(source: ImageSource | null | undefined) {\n const thumbhash = useThumbhash(source);\n const blurhash = useBlurhash(source);\n return useMemo(\n () => ({\n resolvedSource: blurhash ?? thumbhash ?? source,\n isImageHash: !!blurhash || !!thumbhash,\n }),\n [blurhash, thumbhash]\n );\n}\n\nexport function useHeaders(\n source: ImageSource | null | undefined,\n cachePolicy: ImageNativeProps['cachePolicy'],\n onError?: OnErrorEvent[]\n): ImageSource | null | undefined {\n const [objectURL, setObjectURL] = useState<string | null>(null);\n useEffect(() => {\n (async () => {\n if (!source?.headers || !source.uri) {\n return;\n }\n try {\n const result = await fetch(source.uri, {\n headers: source.headers,\n cache: cachePolicy === 'none' ? 'no-cache' : 'default',\n redirect: 'follow',\n });\n if (!result.ok) {\n throw new Error(`Failed to fetch image: ${result.status} ${result.statusText}`);\n }\n const blob = await result.blob();\n setObjectURL((prevObjURL) => {\n if (prevObjURL) {\n URL.revokeObjectURL(prevObjURL);\n }\n return URL.createObjectURL(blob);\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n onError?.forEach((e) => e?.({ source }));\n }\n })();\n }, [source]);\n if (!source?.headers) {\n return source;\n }\n if (!objectURL) {\n // Avoid fetching a URL without headers if we have headers\n return null;\n }\n return { ...source, uri: objectURL };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export default function loadStyle(): void;
2
+ //# sourceMappingURL=imageStyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageStyles.d.ts","sourceRoot":"","sources":["../../src/web/imageStyles.tsx"],"names":[],"mappings":"AAgIA,MAAM,CAAC,OAAO,UAAU,SAAS,SAOhC"}
@@ -0,0 +1,137 @@
1
+ const style = `
2
+ [data-expoimage] .cross-dissolve {
3
+ transition-property: opacity;
4
+ animation-fill-mode: forwards;
5
+ }
6
+ [data-expoimage] .cross-dissolve-start:not(.transitioning) {
7
+ opacity: 0;
8
+ }
9
+ [data-expoimage] .cross-dissolve-active {
10
+ opacity: 1;
11
+ }
12
+ [data-expoimage] .cross-dissolve-end {
13
+ opacity: 0;
14
+ }
15
+ [data-expoimage] .flip-from-left {
16
+ transition-property: transform, opacity;
17
+ transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
18
+ transform-origin: center;
19
+
20
+ }
21
+ [data-expoimage] .flip-from-left-container {
22
+ width: 100%;
23
+ height: 100%;
24
+ position: absolute;
25
+ left: 0;
26
+ top: 0;
27
+ perspective: 1000px;
28
+ }
29
+ [data-expoimage] .flip-from-left-start:not(.transitioning) {
30
+ transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);
31
+ opacity: 0;
32
+ }
33
+ [data-expoimage] .flip-from-left-active {
34
+ transform: translateZ(0px) rotateY(0) ;
35
+ opacity:1;
36
+ }
37
+ [data-expoimage] .flip-from-left-end {
38
+ transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);
39
+ opacity: 0;
40
+ }
41
+ [data-expoimage] .flip-from-right {
42
+ transition-property: transform, opacity;
43
+ transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
44
+ transform-origin: center;
45
+ }
46
+ [data-expoimage] .flip-from-right-container {
47
+ width: 100%;
48
+ height: 100%;
49
+ position: absolute;
50
+ left: 0;
51
+ top: 0;
52
+ perspective: 1000px;
53
+ }
54
+ [data-expoimage] .flip-from-right-start:not(.transitioning) {
55
+ transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);
56
+ opacity: 0;
57
+ }
58
+ [data-expoimage] .flip-from-right-active {
59
+ transform: translateZ(0px) rotateY(0) ;
60
+ opacity:1;
61
+ }
62
+ [data-expoimage] .flip-from-right-end {
63
+ transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);
64
+ opacity: 0;
65
+ }
66
+ [data-expoimage] .flip-from-top {
67
+ transition-property: transform, opacity;
68
+ transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
69
+ transform-origin: center;
70
+ }
71
+ [data-expoimage] .flip-from-top-container {
72
+ width: 100%;
73
+ height: 100%;
74
+ position: absolute;
75
+ left: 0;
76
+ top: 0;
77
+ perspective: 1000px;
78
+ }
79
+ [data-expoimage] .flip-from-top-start:not(.transitioning) {
80
+ transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(180deg);
81
+ opacity: 0;
82
+ }
83
+ [data-expoimage] .flip-from-top-active {
84
+ transform: translateZ(0px) rotateX(0) ;
85
+ opacity:1;
86
+ }
87
+ [data-expoimage] .flip-from-top-end {
88
+ transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(-180deg);
89
+ opacity: 0;
90
+ }
91
+ [data-expoimage] .flip-from-bottom {
92
+ transition-property: transform, opacity;
93
+ transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;
94
+ transform-origin: center;
95
+ }
96
+ [data-expoimage] .flip-from-bottom-container {
97
+ width: 100%;
98
+ height: 100%;
99
+ position: absolute;
100
+ left: 0;
101
+ top: 0;
102
+ perspective: 1000px;
103
+ }
104
+ [data-expoimage] .flip-from-bottom-start:not(.transitioning) {
105
+ transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(-180deg);
106
+ opacity: 0;
107
+ }
108
+ [data-expoimage] .flip-from-bottom-active {
109
+ transform: translateZ(0px) rotateX(0) ;
110
+ opacity:1;
111
+ }
112
+ [data-expoimage] .flip-from-bottom-end {
113
+ transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(180deg);
114
+ opacity: 0;
115
+ }
116
+ [data-expoimage] .image-timing-linear {
117
+ --expo-image-timing: linear;
118
+ }
119
+ [data-expoimage] .image-timing-ease-in {
120
+ --expo-image-timing: ease-in;
121
+ }
122
+ [data-expoimage] .image-timing-ease-out {
123
+ --expo-image-timing: ease-out;
124
+ }
125
+ [data-expoimage] .image-timing-ease-in-out {
126
+ --expo-image-timing: ease-in-out;
127
+ }
128
+ `;
129
+ export default function loadStyle() {
130
+ if (typeof document !== 'undefined') {
131
+ const styleTag = document.createElement('style');
132
+ styleTag.innerHTML = style;
133
+ styleTag.id = 'expo-image-styles';
134
+ document.head.appendChild(styleTag);
135
+ }
136
+ }
137
+ //# sourceMappingURL=imageStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageStyles.js","sourceRoot":"","sources":["../../src/web/imageStyles.tsx"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Hb,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACjD,QAAQ,CAAC,SAAS,GAAG,KAAK,CAAC;QAC3B,QAAQ,CAAC,EAAE,GAAG,mBAAmB,CAAC;QAClC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["const style = `\n[data-expoimage] .cross-dissolve {\n transition-property: opacity;\n animation-fill-mode: forwards;\n}\n[data-expoimage] .cross-dissolve-start:not(.transitioning) {\n opacity: 0;\n}\n[data-expoimage] .cross-dissolve-active {\n opacity: 1;\n}\n[data-expoimage] .cross-dissolve-end {\n opacity: 0;\n}\n[data-expoimage] .flip-from-left {\n transition-property: transform, opacity;\n transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;\n transform-origin: center;\n\n}\n[data-expoimage] .flip-from-left-container {\n width: 100%;\n height: 100%;\n position: absolute;\n left: 0;\n top: 0;\n perspective: 1000px;\n}\n[data-expoimage] .flip-from-left-start:not(.transitioning) {\n transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-left-active {\n transform: translateZ(0px) rotateY(0) ;\n opacity:1;\n}\n[data-expoimage] .flip-from-left-end {\n transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-right {\n transition-property: transform, opacity;\n transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;\n transform-origin: center;\n}\n[data-expoimage] .flip-from-right-container {\n width: 100%;\n height: 100%;\n position: absolute;\n left: 0;\n top: 0;\n perspective: 1000px;\n}\n[data-expoimage] .flip-from-right-start:not(.transitioning) {\n transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-right-active {\n transform: translateZ(0px) rotateY(0) ;\n opacity:1;\n}\n[data-expoimage] .flip-from-right-end {\n transform: translateZ(calc(var(--expo-image-width,1000px) * -1.25)) rotateY(-180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-top {\n transition-property: transform, opacity;\n transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;\n transform-origin: center;\n}\n[data-expoimage] .flip-from-top-container {\n width: 100%;\n height: 100%;\n position: absolute;\n left: 0;\n top: 0;\n perspective: 1000px;\n}\n[data-expoimage] .flip-from-top-start:not(.transitioning) {\n transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-top-active {\n transform: translateZ(0px) rotateX(0) ;\n opacity:1;\n}\n[data-expoimage] .flip-from-top-end {\n transform: translateZ(calc(var(--expo-image-height,1000px) * -1.5)) rotateX(-180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-bottom {\n transition-property: transform, opacity;\n transition-timing-function: var(--expo-image-timing,linear), steps(2, jump-none) !important;\n transform-origin: center;\n}\n[data-expoimage] .flip-from-bottom-container {\n width: 100%;\n height: 100%;\n position: absolute;\n left: 0;\n top: 0;\n perspective: 1000px;\n}\n[data-expoimage] .flip-from-bottom-start:not(.transitioning) {\n transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(-180deg);\n opacity: 0;\n}\n[data-expoimage] .flip-from-bottom-active {\n transform: translateZ(0px) rotateX(0) ;\n opacity:1;\n}\n[data-expoimage] .flip-from-bottom-end {\n transform: translateZ(calc(var(--expo-image-height,1000px) * -1.25)) rotateX(180deg);\n opacity: 0;\n}\n[data-expoimage] .image-timing-linear {\n --expo-image-timing: linear;\n}\n[data-expoimage] .image-timing-ease-in {\n --expo-image-timing: ease-in;\n}\n[data-expoimage] .image-timing-ease-out {\n --expo-image-timing: ease-out;\n}\n[data-expoimage] .image-timing-ease-in-out {\n --expo-image-timing: ease-in-out;\n}\n`;\nexport default function loadStyle() {\n if (typeof document !== 'undefined') {\n const styleTag = document.createElement('style');\n styleTag.innerHTML = style;\n styleTag.id = 'expo-image-styles';\n document.head.appendChild(styleTag);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { ImageContentPositionObject } from '../Image.types';
2
+ export declare function ensureValueIsWebUnits(value: string | number): string;
3
+ export declare const absoluteFilledPosition: {
4
+ readonly width: "100%";
5
+ readonly height: "100%";
6
+ readonly position: "absolute";
7
+ readonly left: 0;
8
+ readonly top: 0;
9
+ };
10
+ export declare function getObjectPositionFromContentPositionObject(contentPosition?: ImageContentPositionObject): string;
11
+ //# sourceMappingURL=positioning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positioning.d.ts","sourceRoot":"","sources":["../../src/web/positioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAA6B,MAAM,gBAAgB,CAAC;AAEvF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,UAM3D;AAID,eAAO,MAAM,sBAAsB;;;;;;CAMzB,CAAC;AAEX,wBAAgB,0CAA0C,CACxD,eAAe,CAAC,EAAE,0BAA0B,GAC3C,MAAM,CAyBR"}
@@ -0,0 +1,35 @@
1
+ export function ensureValueIsWebUnits(value) {
2
+ const trimmedValue = String(value).trim();
3
+ if (trimmedValue.endsWith('%')) {
4
+ return trimmedValue;
5
+ }
6
+ return `${trimmedValue}px`;
7
+ }
8
+ export const absoluteFilledPosition = {
9
+ width: '100%',
10
+ height: '100%',
11
+ position: 'absolute',
12
+ left: 0,
13
+ top: 0,
14
+ };
15
+ export function getObjectPositionFromContentPositionObject(contentPosition) {
16
+ const resolvedPosition = { ...contentPosition };
17
+ if (!resolvedPosition) {
18
+ return '50% 50%';
19
+ }
20
+ if (resolvedPosition.top == null && resolvedPosition.bottom == null) {
21
+ resolvedPosition.top = '50%';
22
+ }
23
+ if (resolvedPosition.left == null && resolvedPosition.right == null) {
24
+ resolvedPosition.left = '50%';
25
+ }
26
+ return (['top', 'bottom', 'left', 'right']
27
+ .map((key) => {
28
+ if (key in resolvedPosition) {
29
+ return `${key} ${ensureValueIsWebUnits(resolvedPosition[key])}`;
30
+ }
31
+ return '';
32
+ })
33
+ .join(' ') || '50% 50%');
34
+ }
35
+ //# sourceMappingURL=positioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positioning.js","sourceRoot":"","sources":["../../src/web/positioning.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CAAC,KAAsB;IAC1D,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,OAAO,GAAG,YAAY,IAAI,CAAC;AAC7B,CAAC;AAID,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;CACE,CAAC;AAEX,MAAM,UAAU,0CAA0C,CACxD,eAA4C;IAE5C,MAAM,gBAAgB,GAAG,EAAE,GAAG,eAAe,EAG5C,CAAC;IACF,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,gBAAgB,CAAC,GAAG,IAAI,IAAI,IAAI,gBAAgB,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;QACpE,gBAAgB,CAAC,GAAG,GAAG,KAAK,CAAC;IAC/B,CAAC;IACD,IAAI,gBAAgB,CAAC,IAAI,IAAI,IAAI,IAAI,gBAAgB,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACpE,gBAAgB,CAAC,IAAI,GAAG,KAAK,CAAC;IAChC,CAAC;IAED,OAAO,CACL,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC;SAC/B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,IAAI,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAC5B,OAAO,GAAG,GAAG,IAAI,qBAAqB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAClE,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAC1B,CAAC;AACJ,CAAC","sourcesContent":["import { ImageContentPositionObject, ImageContentPositionValue } from '../Image.types';\n\nexport function ensureValueIsWebUnits(value: string | number) {\n const trimmedValue = String(value).trim();\n if (trimmedValue.endsWith('%')) {\n return trimmedValue;\n }\n return `${trimmedValue}px`;\n}\n\ntype KeysOfUnion<T> = T extends T ? keyof T : never;\n\nexport const absoluteFilledPosition = {\n width: '100%',\n height: '100%',\n position: 'absolute',\n left: 0,\n top: 0,\n} as const;\n\nexport function getObjectPositionFromContentPositionObject(\n contentPosition?: ImageContentPositionObject\n): string {\n const resolvedPosition = { ...contentPosition } as Record<\n KeysOfUnion<ImageContentPositionObject>,\n ImageContentPositionValue\n >;\n if (!resolvedPosition) {\n return '50% 50%';\n }\n if (resolvedPosition.top == null && resolvedPosition.bottom == null) {\n resolvedPosition.top = '50%';\n }\n if (resolvedPosition.left == null && resolvedPosition.right == null) {\n resolvedPosition.left = '50%';\n }\n\n return (\n ['top', 'bottom', 'left', 'right']\n .map((key) => {\n if (key in resolvedPosition) {\n return `${key} ${ensureValueIsWebUnits(resolvedPosition[key])}`;\n }\n return '';\n })\n .join(' ') || '50% 50%'\n );\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { ImageProps, ImageSource } from '../Image.types';
2
+ export interface SrcSetSource extends ImageSource {
3
+ srcset: string;
4
+ sizes: string;
5
+ uri: string;
6
+ type: 'srcset';
7
+ }
8
+ type UseSourceSelectionReturn = {
9
+ containerRef: (element: HTMLDivElement) => void;
10
+ source: ImageSource | SrcSetSource | null;
11
+ };
12
+ export default function useSourceSelection(sources?: ImageSource[], responsivePolicy?: ImageProps['responsivePolicy'], measurementCallback?: (target: HTMLElement, size: DOMRect) => void): UseSourceSelectionReturn;
13
+ export {};
14
+ //# sourceMappingURL=useSourceSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSourceSelection.d.ts","sourceRoot":"","sources":["../../src/web/useSourceSelection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAoCzD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;CAChB;AAmDD,KAAK,wBAAwB,GAAG;IAC9B,YAAY,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,MAAM,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAAC;CAC3C,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,OAAO,CAAC,EAAE,WAAW,EAAE,EACvB,gBAAgB,GAAE,UAAU,CAAC,kBAAkB,CAAY,EAC3D,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GACjE,wBAAwB,CA8C1B"}
@@ -0,0 +1,98 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import { isBlurhashString, isThumbhashString } from '../utils/resolveSources';
3
+ function findBestSourceForSize(sources, size) {
4
+ if (sources?.length === 1) {
5
+ return sources[0];
6
+ }
7
+ return ([...(sources || [])]
8
+ // look for the smallest image that's still larger then a container
9
+ ?.map((source) => {
10
+ if (!size) {
11
+ return { source, penalty: 0, covers: false };
12
+ }
13
+ const { width, height } = typeof source === 'object' ? source : { width: null, height: null };
14
+ if (width == null || height == null) {
15
+ return { source, penalty: 0, covers: false };
16
+ }
17
+ if (width < size.width || height < size.height) {
18
+ return {
19
+ source,
20
+ penalty: Math.max(size.width - width, size.height - height),
21
+ covers: false,
22
+ };
23
+ }
24
+ return { source, penalty: (width - size.width) * (height - size.height), covers: true };
25
+ })
26
+ .sort((a, b) => a.penalty - b.penalty)
27
+ .sort((a, b) => Number(b.covers) - Number(a.covers))[0]?.source ?? null);
28
+ }
29
+ function getCSSMediaQueryForSource(source) {
30
+ return `(max-width: ${source.webMaxViewportWidth ?? source.width}px) ${source.width}px`;
31
+ }
32
+ function selectSource(sources, size, responsivePolicy) {
33
+ if (sources == null || sources.length === 0) {
34
+ return null;
35
+ }
36
+ if (sources.length === 1) {
37
+ return sources[0];
38
+ }
39
+ if (responsivePolicy !== 'static') {
40
+ return findBestSourceForSize(sources, size);
41
+ }
42
+ const staticSupportedSources = sources
43
+ .filter((s) => s.uri && s.width != null && !isBlurhashString(s.uri) && !isThumbhashString(s.uri))
44
+ .sort((a, b) => (a.webMaxViewportWidth ?? a.width ?? 0) - (b.webMaxViewportWidth ?? b.width ?? 0));
45
+ if (staticSupportedSources.length === 0) {
46
+ console.warn("You've set the `static` responsivePolicy but none of the sources have the `width` properties set. Make sure you set both `width` and `webMaxViewportWidth` for best results when using static responsiveness. Falling back to the `initial` policy.");
47
+ return findBestSourceForSize(sources, size);
48
+ }
49
+ const srcset = staticSupportedSources
50
+ ?.map((source) => `${source.uri} ${source.width}w`)
51
+ .join(', ');
52
+ const sizes = `${staticSupportedSources
53
+ ?.map(getCSSMediaQueryForSource)
54
+ .join(', ')}, ${staticSupportedSources[staticSupportedSources.length - 1]?.width}px`;
55
+ return {
56
+ srcset,
57
+ sizes,
58
+ uri: staticSupportedSources[staticSupportedSources.length - 1]?.uri ?? '',
59
+ type: 'srcset',
60
+ };
61
+ }
62
+ export default function useSourceSelection(sources, responsivePolicy = 'static', measurementCallback) {
63
+ const hasMoreThanOneSource = (sources?.length ?? 0) > 1;
64
+ // null - not calculated yet, DOMRect - size available
65
+ const [size, setSize] = useState(null);
66
+ const resizeObserver = useRef(null);
67
+ React.useEffect(() => {
68
+ return () => {
69
+ resizeObserver.current?.disconnect();
70
+ };
71
+ }, []);
72
+ const containerRef = React.useCallback((element) => {
73
+ // we can't short circuit here since we need to read the size for better animated transitions
74
+ if (!hasMoreThanOneSource && !measurementCallback) {
75
+ return;
76
+ }
77
+ const rect = element?.getBoundingClientRect();
78
+ measurementCallback?.(element, rect);
79
+ setSize(rect);
80
+ if (responsivePolicy === 'live') {
81
+ resizeObserver.current?.disconnect();
82
+ if (!element) {
83
+ return;
84
+ }
85
+ resizeObserver.current = new ResizeObserver((entries) => {
86
+ setSize(entries[0].contentRect);
87
+ measurementCallback?.(entries[0].target, entries[0].contentRect);
88
+ });
89
+ resizeObserver.current.observe(element);
90
+ }
91
+ }, [hasMoreThanOneSource, responsivePolicy]);
92
+ const source = selectSource(sources, size, responsivePolicy);
93
+ return React.useMemo(() => ({
94
+ containerRef,
95
+ source,
96
+ }), [source]);
97
+ }
98
+ //# sourceMappingURL=useSourceSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSourceSelection.js","sourceRoot":"","sources":["../../src/web/useSourceSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,SAAS,qBAAqB,CAC5B,OAAkC,EAClC,IAAoB;IAEpB,IAAI,OAAO,EAAE,MAAM,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AK,CAAC,WAAW,CACpC,CAAC,OAAuB,EAAE,EAAE;QAC1B,6FAA6F;QAC7F,IAAI,CAAC,oBAAoB,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAClD,OAAO;QACT,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,qBAAqB,EAAE,CAAC;QAC9C,mBAAmB,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEd,IAAI,gBAAgB,KAAK,MAAM,EAAE,CAAC;YAChC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO;YACT,CAAC;YACD,cAAc,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;gBACtD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;gBAChC,mBAAmB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAa,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,EACD,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CACzC,CAAC;IAEF,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAE7D,OAAO,KAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,YAAY;QACZ,MAAM;KACP,CAAC,EACF,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC","sourcesContent":["import React, { useState, useRef } from 'react';\n\nimport { ImageProps, ImageSource } from '../Image.types';\nimport { isBlurhashString, isThumbhashString } from '../utils/resolveSources';\n\nfunction findBestSourceForSize(\n sources: ImageSource[] | undefined,\n size: DOMRect | null\n): ImageSource | null {\n if (sources?.length === 1) {\n return sources[0];\n }\n return (\n [...(sources || [])]\n // look for the smallest image that's still larger then a container\n ?.map((source) => {\n if (!size) {\n return { source, penalty: 0, covers: false };\n }\n const { width, height } =\n typeof source === 'object' ? source : { width: null, height: null };\n if (width == null || height == null) {\n return { source, penalty: 0, covers: false };\n }\n if (width < size.width || height < size.height) {\n return {\n source,\n penalty: Math.max(size.width - width, size.height - height),\n covers: false,\n };\n }\n return { source, penalty: (width - size.width) * (height - size.height), covers: true };\n })\n .sort((a, b) => a.penalty - b.penalty)\n .sort((a, b) => Number(b.covers) - Number(a.covers))[0]?.source ?? null\n );\n}\n\nexport interface SrcSetSource extends ImageSource {\n srcset: string;\n sizes: string;\n // used as key and a fallback in case srcset is not supported\n uri: string;\n type: 'srcset';\n}\n\nfunction getCSSMediaQueryForSource(source: ImageSource) {\n return `(max-width: ${source.webMaxViewportWidth ?? source.width}px) ${source.width}px`;\n}\n\nfunction selectSource(\n sources: ImageSource[] | undefined,\n size: DOMRect | null,\n responsivePolicy: ImageProps['responsivePolicy']\n): ImageSource | SrcSetSource | null {\n if (sources == null || sources.length === 0) {\n return null;\n }\n\n if (sources.length === 1) {\n return sources[0];\n }\n\n if (responsivePolicy !== 'static') {\n return findBestSourceForSize(sources, size);\n }\n const staticSupportedSources = sources\n .filter(\n (s) => s.uri && s.width != null && !isBlurhashString(s.uri) && !isThumbhashString(s.uri)\n )\n .sort(\n (a, b) => (a.webMaxViewportWidth ?? a.width ?? 0) - (b.webMaxViewportWidth ?? b.width ?? 0)\n );\n\n if (staticSupportedSources.length === 0) {\n console.warn(\n \"You've set the `static` responsivePolicy but none of the sources have the `width` properties set. Make sure you set both `width` and `webMaxViewportWidth` for best results when using static responsiveness. Falling back to the `initial` policy.\"\n );\n return findBestSourceForSize(sources, size);\n }\n\n const srcset = staticSupportedSources\n ?.map((source) => `${source.uri} ${source.width}w`)\n .join(', ');\n const sizes = `${staticSupportedSources\n ?.map(getCSSMediaQueryForSource)\n .join(', ')}, ${staticSupportedSources[staticSupportedSources.length - 1]?.width}px`;\n return {\n srcset,\n sizes,\n uri: staticSupportedSources[staticSupportedSources.length - 1]?.uri ?? '',\n type: 'srcset',\n };\n}\n\ntype UseSourceSelectionReturn = {\n containerRef: (element: HTMLDivElement) => void;\n source: ImageSource | SrcSetSource | null;\n};\n\nexport default function useSourceSelection(\n sources?: ImageSource[],\n responsivePolicy: ImageProps['responsivePolicy'] = 'static',\n measurementCallback?: (target: HTMLElement, size: DOMRect) => void\n): UseSourceSelectionReturn {\n const hasMoreThanOneSource = (sources?.length ?? 0) > 1;\n // null - not calculated yet, DOMRect - size available\n const [size, setSize] = useState<null | DOMRect>(null);\n const resizeObserver = useRef<ResizeObserver | null>(null);\n\n React.useEffect(() => {\n return () => {\n resizeObserver.current?.disconnect();\n };\n }, []);\n\n const containerRef = React.useCallback(\n (element: HTMLDivElement) => {\n // we can't short circuit here since we need to read the size for better animated transitions\n if (!hasMoreThanOneSource && !measurementCallback) {\n return;\n }\n const rect = element?.getBoundingClientRect();\n measurementCallback?.(element, rect);\n setSize(rect);\n\n if (responsivePolicy === 'live') {\n resizeObserver.current?.disconnect();\n if (!element) {\n return;\n }\n resizeObserver.current = new ResizeObserver((entries) => {\n setSize(entries[0].contentRect);\n measurementCallback?.(entries[0].target as any, entries[0].contentRect);\n });\n resizeObserver.current.observe(element);\n }\n },\n [hasMoreThanOneSource, responsivePolicy]\n );\n\n const source = selectSource(sources, size, responsivePolicy);\n\n return React.useMemo(\n () => ({\n containerRef,\n source,\n }),\n [source]\n );\n}\n"]}
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["ios", "android"],
3
+ "ios": {
4
+ "modules": ["ImageModule"]
5
+ },
6
+ "android": {
7
+ "modules": ["expo.modules.image.ExpoImageModule"]
8
+ }
9
+ }