react-native-nitro-image-pipeline 1.4.0 → 1.6.0

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 (72) hide show
  1. package/README.md +124 -8
  2. package/android/CMakeLists.txt +4 -0
  3. package/android/src/main/cpp/GaussianBlur.cpp +165 -0
  4. package/android/src/main/cpp/GaussianBlur.hpp +52 -0
  5. package/android/src/main/cpp/GaussianBlurJni.cpp +50 -0
  6. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt +167 -75
  7. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/PipelineImageLoader.kt +177 -0
  8. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/BlurTransformation.kt +36 -81
  9. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/HardwareBitmapTransformation.kt +45 -0
  10. package/ios/GaussianBlur.swift +48 -9
  11. package/ios/HybridNitroImagePipeline.swift +109 -41
  12. package/ios/PipelineImageLoader.swift +195 -0
  13. package/ios/RoundedCornersProcessor.swift +5 -0
  14. package/lib/commonjs/NativePipelineImage.js +72 -0
  15. package/lib/commonjs/NativePipelineImage.js.map +1 -0
  16. package/lib/commonjs/PipelineImage.js.map +1 -1
  17. package/lib/commonjs/index.js +27 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/resolveImageSource.js +89 -0
  20. package/lib/commonjs/resolveImageSource.js.map +1 -0
  21. package/lib/commonjs/useImage.js +8 -4
  22. package/lib/commonjs/useImage.js.map +1 -1
  23. package/lib/commonjs/usePipelineImageLoader.js +74 -0
  24. package/lib/commonjs/usePipelineImageLoader.js.map +1 -0
  25. package/lib/module/NativePipelineImage.js +68 -0
  26. package/lib/module/NativePipelineImage.js.map +1 -0
  27. package/lib/module/PipelineImage.js.map +1 -1
  28. package/lib/module/index.js +3 -0
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/resolveImageSource.js +83 -0
  31. package/lib/module/resolveImageSource.js.map +1 -0
  32. package/lib/module/useImage.js +8 -4
  33. package/lib/module/useImage.js.map +1 -1
  34. package/lib/module/usePipelineImageLoader.js +70 -0
  35. package/lib/module/usePipelineImageLoader.js.map +1 -0
  36. package/lib/typescript/src/NativePipelineImage.d.ts +71 -0
  37. package/lib/typescript/src/NativePipelineImage.d.ts.map +1 -0
  38. package/lib/typescript/src/PipelineImage.d.ts +7 -2
  39. package/lib/typescript/src/PipelineImage.d.ts.map +1 -1
  40. package/lib/typescript/src/index.d.ts +4 -1
  41. package/lib/typescript/src/index.d.ts.map +1 -1
  42. package/lib/typescript/src/resolveImageSource.d.ts +56 -0
  43. package/lib/typescript/src/resolveImageSource.d.ts.map +1 -0
  44. package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts +56 -1
  45. package/lib/typescript/src/specs/nitro-image-toolkit.nitro.d.ts.map +1 -1
  46. package/lib/typescript/src/useImage.d.ts +10 -4
  47. package/lib/typescript/src/useImage.d.ts.map +1 -1
  48. package/lib/typescript/src/usePipelineImageLoader.d.ts +17 -0
  49. package/lib/typescript/src/usePipelineImageLoader.d.ts.map +1 -0
  50. package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.cpp +13 -0
  51. package/nitrogen/generated/android/c++/JHybridNitroImagePipelineSpec.hpp +1 -0
  52. package/nitrogen/generated/android/c++/JViewOptions.hpp +77 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipelineSpec.kt +5 -0
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroimagepipeline/ViewOptions.kt +66 -0
  55. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.cpp +10 -0
  56. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Bridge.hpp +44 -0
  57. package/nitrogen/generated/ios/NitroImagePipeline-Swift-Cxx-Umbrella.hpp +8 -0
  58. package/nitrogen/generated/ios/c++/HybridNitroImagePipelineSpecSwift.hpp +14 -0
  59. package/nitrogen/generated/ios/swift/HybridNitroImagePipelineSpec.swift +1 -0
  60. package/nitrogen/generated/ios/swift/HybridNitroImagePipelineSpec_cxx.swift +15 -0
  61. package/nitrogen/generated/ios/swift/ViewOptions.swift +101 -0
  62. package/nitrogen/generated/shared/c++/HybridNitroImagePipelineSpec.cpp +1 -0
  63. package/nitrogen/generated/shared/c++/HybridNitroImagePipelineSpec.hpp +7 -0
  64. package/nitrogen/generated/shared/c++/ViewOptions.hpp +104 -0
  65. package/package.json +4 -3
  66. package/src/NativePipelineImage.tsx +108 -0
  67. package/src/PipelineImage.tsx +7 -2
  68. package/src/index.ts +12 -0
  69. package/src/resolveImageSource.ts +83 -0
  70. package/src/specs/nitro-image-toolkit.nitro.ts +57 -1
  71. package/src/useImage.ts +26 -15
  72. package/src/usePipelineImageLoader.ts +90 -0
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "NativePipelineImage", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _NativePipelineImage.NativePipelineImage;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "NitroImagePipeline", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -15,6 +21,12 @@ Object.defineProperty(exports, "PipelineImage", {
15
21
  return _PipelineImage.PipelineImage;
16
22
  }
17
23
  });
24
+ Object.defineProperty(exports, "UNREGISTERED_ASSET_URL", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _resolveImageSource.UNREGISTERED_ASSET_URL;
28
+ }
29
+ });
18
30
  Object.defineProperty(exports, "cornerRadiusForStyle", {
19
31
  enumerable: true,
20
32
  get: function () {
@@ -33,14 +45,29 @@ Object.defineProperty(exports, "resizeForStyle", {
33
45
  return _resizeForStyle.resizeForStyle;
34
46
  }
35
47
  });
48
+ Object.defineProperty(exports, "resolveImageUrl", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _resolveImageSource.resolveImageUrl;
52
+ }
53
+ });
36
54
  Object.defineProperty(exports, "useImage", {
37
55
  enumerable: true,
38
56
  get: function () {
39
57
  return _useImage.useImage;
40
58
  }
41
59
  });
60
+ Object.defineProperty(exports, "usePipelineImageLoader", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _usePipelineImageLoader.usePipelineImageLoader;
64
+ }
65
+ });
66
+ var _NativePipelineImage = require("./NativePipelineImage");
42
67
  var _NitroImagePipeline = require("./NitroImagePipeline");
43
68
  var _PipelineImage = require("./PipelineImage");
69
+ var _resolveImageSource = require("./resolveImageSource");
44
70
  var _resizeForStyle = require("./resizeForStyle");
45
71
  var _useImage = require("./useImage");
72
+ var _usePipelineImageLoader = require("./usePipelineImageLoader");
46
73
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_NitroImagePipeline","require","_PipelineImage","_resizeForStyle","_useImage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAKA,IAAAE,eAAA,GAAAF,OAAA;AAWA,IAAAG,SAAA,GAAAH,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_NativePipelineImage","require","_NitroImagePipeline","_PipelineImage","_resolveImageSource","_resizeForStyle","_useImage","_usePipelineImageLoader"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAKA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAKA,IAAAG,mBAAA,GAAAH,OAAA;AAKA,IAAAI,eAAA,GAAAJ,OAAA;AAYA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,uBAAA,GAAAN,OAAA","ignoreList":[]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UNREGISTERED_ASSET_URL = void 0;
7
+ exports.recyclingKeyFor = recyclingKeyFor;
8
+ exports.resolveImageUrl = resolveImageUrl;
9
+ exports.resolveImageUrlOrFallback = resolveImageUrlOrFallback;
10
+ var _reactNative = require("react-native");
11
+ /**
12
+ * What the pipeline can load: a URL string, or the id a `require()`d image
13
+ * asset evaluates to.
14
+ *
15
+ * As a string, `url` is passed to the native loader as-is. Accepted forms:
16
+ *
17
+ * - `https://` / `http://` — fetched over the network and cached on disk.
18
+ * - `file://` URLs and plain absolute paths (`/var/…/photo.jpg`) — read from
19
+ * the file system. The result is cached in memory only; there is nothing
20
+ * to gain from copying a local file into the disk cache.
21
+ * - Android also accepts `content://` URIs and, from a release build's
22
+ * resources, a bare drawable name — which is what `require()` resolves to
23
+ * there. iOS resolves `require()` to a `file://` URL into the app bundle.
24
+ *
25
+ * A `require('./photo.png')` is resolved with `Image.resolveAssetSource`, so
26
+ * it works the same in debug (streamed from Metro) and release (bundled).
27
+ */
28
+
29
+ /**
30
+ * Turns an {@linkcode ImageSource} into the URL string the native pipeline
31
+ * loads: strings pass through unchanged, a `require()`d asset is resolved via
32
+ * `Image.resolveAssetSource` (the scale-matched variant, like `<Image>`).
33
+ *
34
+ * The components and hooks call this for you; use it when calling
35
+ * `NitroImagePipeline.loadImage`/`preLoadImage` directly with a `require()`.
36
+ * @throws If `source` is a number that is not a registered asset.
37
+ * @example
38
+ * ```ts
39
+ * const image = await NitroImagePipeline.loadImage(
40
+ * resolveImageUrl(require('./photo.png')),
41
+ * { blur: 4 },
42
+ * );
43
+ * ```
44
+ */
45
+ function resolveImageUrl(source) {
46
+ if (typeof source === 'string') {
47
+ return source;
48
+ }
49
+ const resolved = _reactNative.Image.resolveAssetSource(source);
50
+ if (resolved == null) {
51
+ throw new Error(`Not a registered image asset: require() id ${source}`);
52
+ }
53
+ return resolved.uri;
54
+ }
55
+
56
+ /**
57
+ * A URL no loader can resolve, standing in for a `require()` id that is not
58
+ * a registered asset. Its scheme has no fetcher on either platform, so the
59
+ * request fails at load time — the same way a missing file does — instead of
60
+ * throwing from a component's render.
61
+ */
62
+ const UNREGISTERED_ASSET_URL = exports.UNREGISTERED_ASSET_URL = 'unregistered-asset://';
63
+
64
+ /**
65
+ * {@linkcode resolveImageUrl} for code that runs during render: an
66
+ * unregistered `require()` id yields {@linkcode UNREGISTERED_ASSET_URL} (and
67
+ * a warning in development) rather than throwing.
68
+ */
69
+ function resolveImageUrlOrFallback(source) {
70
+ try {
71
+ return resolveImageUrl(source);
72
+ } catch (error) {
73
+ if (__DEV__) {
74
+ console.warn(`[react-native-nitro-image-pipeline] ${error.message}`);
75
+ }
76
+ return UNREGISTERED_ASSET_URL;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * A stable, per-source `recyclingKey` for `<NativeNitroImage>`: the URL
82
+ * itself for strings, and a tag derived from the asset id for a `require()`
83
+ * (resolving it would cost an asset-registry lookup per render for nothing
84
+ * more than a distinct key).
85
+ */
86
+ function recyclingKeyFor(source) {
87
+ return typeof source === 'string' ? source : `asset:${source}`;
88
+ }
89
+ //# sourceMappingURL=resolveImageSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","resolveImageUrl","source","resolved","RNImage","resolveAssetSource","Error","uri","UNREGISTERED_ASSET_URL","exports","resolveImageUrlOrFallback","error","__DEV__","console","warn","message","recyclingKeyFor"],"sourceRoot":"../../src","sources":["resolveImageSource.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACC,MAAmB,EAAU;EAC3D,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EACA,MAAMC,QAAQ,GAAGC,kBAAO,CAACC,kBAAkB,CAACH,MAAM,CAAC;EACnD,IAAIC,QAAQ,IAAI,IAAI,EAAE;IACpB,MAAM,IAAIG,KAAK,CAAC,8CAA8CJ,MAAM,EAAE,CAAC;EACzE;EACA,OAAOC,QAAQ,CAACI,GAAG;AACrB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,uBAAuB;;AAE7D;AACA;AACA;AACA;AACA;AACO,SAASE,yBAAyBA,CAACR,MAAmB,EAAU;EACrE,IAAI;IACF,OAAOD,eAAe,CAACC,MAAM,CAAC;EAChC,CAAC,CAAC,OAAOS,KAAK,EAAE;IACd,IAAIC,OAAO,EAAE;MACXC,OAAO,CAACC,IAAI,CACV,uCAAwCH,KAAK,CAAWI,OAAO,EACjE,CAAC;IACH;IACA,OAAOP,sBAAsB;EAC/B;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,eAAeA,CAACd,MAAmB,EAAU;EAC3D,OAAO,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,SAASA,MAAM,EAAE;AAChE","ignoreList":[]}
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useImage = useImage;
7
7
  var _react = require("react");
8
8
  var _NitroImagePipeline = require("./NitroImagePipeline");
9
+ var _resolveImageSource = require("./resolveImageSource");
9
10
  /**
10
- * A hook to asynchronously load an image from the
11
- * given {@linkcode AsyncImageSource} into memory.
11
+ * A hook to asynchronously load an image from `url` through the pipeline
12
+ * into memory.
12
13
  * @example
13
14
  * ```ts
14
- * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
15
+ * const { image, error } = useImage({ url: 'https://example.com/photo.jpg' });
16
+ * const { image: logo } = useImage({ url: require('./logo.png') });
15
17
  * ```
16
18
  */
17
19
  function useImage({
@@ -55,7 +57,9 @@ function useImage({
55
57
  if (enabled) {
56
58
  (async () => {
57
59
  try {
58
- const result = await _NitroImagePipeline.NitroImagePipeline.loadImage(url, {
60
+ // Resolved inside the try so an unregistered `require()` id
61
+ // surfaces as the error state instead of throwing from the effect.
62
+ const result = await _NitroImagePipeline.NitroImagePipeline.loadImage((0, _resolveImageSource.resolveImageUrl)(url), {
59
63
  blur,
60
64
  cornerRadius: isUniformRadius ? uniformRadius : {
61
65
  topLeft,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_NitroImagePipeline","useImage","url","blur","cornerRadius","resize","cache","enabled","image","setImage","useState","undefined","error","loadedUrlRef","useRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","width","resizeHeight","height","useEffect","cancelled","current","result","NitroImagePipeline","loadImage","e","Error"],"sourceRoot":"../../src","sources":["useImage.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,mBAAA,GAAAD,OAAA;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC,MAAM;EACNC,KAAK;EACLC,OAAO,GAAG;AA+BZ,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAS;IACzCF,KAAK,EAAEG,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAG,IAAAC,aAAM,EAACZ,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMa,eAAe,GAAG,OAAOX,YAAY,KAAK,QAAQ;EACxD,MAAMY,aAAa,GAAGD,eAAe,GAAGX,YAAY,GAAG,CAAC;EACxD,MAAM;IACJa,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,W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AAC,CAAC;UAC9C;QACF;MACF,CAAC,EAAE,CAAC;IACN;IAEA,OAAO,MAAM;MACXc,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CACDxB,GAAG,EACHC,IAAI,EACJY,eAAe,EACfC,aAAa,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXC,WAAW,EACXE,YAAY,EACZjB,KAAK,EACLC,OAAO,CACR,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_NitroImagePipeline","_resolveImageSource","useImage","url","blur","cornerRadius","resize","cache","enabled","image","setImage","useState","undefined","error","loadedUrlRef","useRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","width","resizeHeight","height","useEffect","cancelled","current","result","NitroImagePipeline","loadImage","resolveImageUrl","e","Error"],"sourceRoot":"../../src","sources":["useImage.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC,MAAM;EACNC,KAAK;EACLC,OAAO,GAAG;AAmCZ,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAAS;IACzCF,KAAK,EAAEG,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAG,IAAAC,aAAM,EAACZ,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMa,eAAe,GAAG,OAAOX,YAAY,KAAK,QAAQ;EACxD,MAAMY,aAAa,GAAGD,eAAe,GAAGX,YAAY,GAAG,CAAC;EACxD,MAAM;IACJa,OAAO,GAAG,CAAC;IAC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N,SAAS,EAAE;YACdjB,QAAQ,CAAC;cAAED,KAAK,EAAEG,SAAS;cAAEC,KAAK,EAAEA;YAAM,CAAC,CAAC;UAC9C;QACF;MACF,CAAC,EAAE,CAAC;IACN;IAEA,OAAO,MAAM;MACXc,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CACDxB,GAAG,EACHC,IAAI,EACJY,eAAe,EACfC,aAAa,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXC,WAAW,EACXE,YAAY,EACZjB,KAAK,EACLC,OAAO,CACR,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePipelineImageLoader = usePipelineImageLoader;
7
+ var _react = require("react");
8
+ var _NitroImagePipeline = require("./NitroImagePipeline");
9
+ var _resolveImageSource = require("./resolveImageSource");
10
+ /**
11
+ * Creates (and memoizes) an {@linkcode ImageLoader} for `source` — a URL
12
+ * string or a `require()`d asset, see {@linkcode ImageSource} — to pass to
13
+ * `<NativeNitroImage image={...} />`. The view drives it entirely natively:
14
+ * the request starts when the view attaches — at the view's laid-out size,
15
+ * with no JS round trips — and is cancelled when it detaches. See
16
+ * {@linkcode NitroImagePipeline.createImageLoader}.
17
+ *
18
+ * `blur`/`cornerRadius` are in **points** (unlike `useImage`, where they are
19
+ * bitmap pixels); the screen scale is applied natively. Inline object
20
+ * literals are fine — options are compared by value, not identity.
21
+ */
22
+ function usePipelineImageLoader(source, options) {
23
+ // Split the options into primitives (like useImage does) so an inline
24
+ // literal — a new identity every render — doesn't recreate the loader;
25
+ // recreating it would re-trigger the native load.
26
+ const blur = options?.blur;
27
+ const cache = options?.cache;
28
+ const cornerRadius = options?.cornerRadius;
29
+ const isUniformRadius = typeof cornerRadius === 'number';
30
+ const uniformRadius = isUniformRadius ? cornerRadius : 0;
31
+ const hasCornerObject = !isUniformRadius && cornerRadius !== undefined;
32
+ const {
33
+ topLeft = 0,
34
+ topRight = 0,
35
+ bottomLeft = 0,
36
+ bottomRight = 0
37
+ } = isUniformRadius || cornerRadius === undefined ? {} : cornerRadius;
38
+ const resizeWidth = options?.resize?.width;
39
+ const resizeHeight = options?.resize?.height;
40
+ return (0, _react.useMemo)(() => {
41
+ // Runs during render, so an unregistered `require()` id must not throw:
42
+ // it becomes a URL the native loader fails on at load time instead.
43
+ const url = (0, _resolveImageSource.resolveImageUrlOrFallback)(source);
44
+ const cornerRadiusOption = isUniformRadius ? uniformRadius : hasCornerObject ? {
45
+ topLeft,
46
+ topRight,
47
+ bottomLeft,
48
+ bottomRight
49
+ } : undefined;
50
+ const stableOptions = {
51
+ blur,
52
+ cache,
53
+ cornerRadius: cornerRadiusOption,
54
+ resize: resizeWidth !== undefined && resizeHeight !== undefined ? {
55
+ width: resizeWidth,
56
+ height: resizeHeight
57
+ } : undefined
58
+ };
59
+ const loader = _NitroImagePipeline.NitroImagePipeline.createImageLoader(url, stableOptions);
60
+ // `NativeNitroImage` needs a way to tell two loader instances apart when
61
+ // diffing its `image` prop; tag the loader with what it will load (the
62
+ // same convention react-native-nitro-image's own loaders use).
63
+ Object.defineProperty(loader, '__source', {
64
+ enumerable: true,
65
+ configurable: true,
66
+ value: {
67
+ url,
68
+ options: stableOptions
69
+ }
70
+ });
71
+ return loader;
72
+ }, [source, blur, cache, isUniformRadius, uniformRadius, hasCornerObject, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight]);
73
+ }
74
+ //# sourceMappingURL=usePipelineImageLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_NitroImagePipeline","_resolveImageSource","usePipelineImageLoader","source","options","blur","cache","cornerRadius","isUniformRadius","uniformRadius","hasCornerObject","undefined","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","resize","width","resizeHeight","height","useMemo","url","resolveImageUrlOrFallback","cornerRadiusOption","stableOptions","loader","NitroImagePipeline","createImageLoader","Object","defineProperty","enumerable","configurable","value"],"sourceRoot":"../../src","sources":["usePipelineImageLoader.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,sBAAsBA,CACpCC,MAAmB,EACnBC,OAAqB,EACR;EACb;EACA;EACA;EACA,MAAMC,IAAI,GAAGD,OAAO,EAAEC,IAAI;EAC1B,MAAMC,KAAK,GAAGF,OAAO,EAAEE,KAAK;EAC5B,MAAMC,YAAY,GAAGH,OAAO,EAAEG,YAAY;EAC1C,MAAMC,eAAe,GAAG,OAAOD,YAAY,KAAK,QAAQ;EACxD,MAAME,aAAa,GAAGD,eAAe,GAAGD,YAAY,GAAG,CAAC;EACxD,MAAMG,eAAe,GAAG,CAACF,eAAe,IAAID,YAAY,KAAKI,SAAS;EACtE,MAAM;IACJC,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,WAAW,GAAG;EAChB,CAAC,GAAGP,eAAe,IAAID,YAAY,KAAKI,SAAS,GAAG,CAAC,CAAC,GAAGJ,YAAY;EACrE,MAAMS,WAAW,GAAGZ,OAAO,EAAEa,MAAM,EAAEC,KAAK;EAC1C,MAAMC,YAAY,GAAGf,OAAO,EAAEa,MAAM,EAAEG,MAAM;EAE5C,OAAO,IAAAC,cAAO,EAAC,MAAM;IACnB;IACA;IACA,MAAMC,GAAG,GAAG,IAAAC,6CAAyB,EAACpB,MAAM,CAAC;IAC7C,MAAMqB,kBAAoD,GAAGhB,eAAe,GACxEC,aAAa,GACbC,eAAe,GACb;MAAEE,OAAO;MAAEC,QAAQ;MAAEC,UAAU;MAAEC;IAAY,CAAC,GAC9CJ,SAAS;IACf,MAAMc,aAA0B,GAAG;MACjCpB,IAAI;MACJC,KAAK;MACLC,YAAY,EAAEiB,kBAAkB;MAChCP,MAAM,EACJD,WAAW,KAAKL,SAAS,IAAIQ,YAAY,KAAKR,SAAS,GACnD;QAAEO,KAAK,EAAEF,WAAW;QAAEI,MAAM,EAAED;MAAa,CAAC,GAC5CR;IACR,CAAC;IACD,MAAMe,MAAM,GAAGC,sCAAkB,CAACC,iBAAiB,CAACN,GAAG,EAAEG,aAAa,CAAC;IACvE;IACA;IACA;IACAI,MAAM,CAACC,cAAc,CAACJ,MAAM,EAAE,UAAU,EAAE;MACxCK,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,KAAK,EAAE;QAAEX,GAAG;QAAElB,OAAO,EAAEqB;MAAc;IACvC,CAAC,CAAC;IACF,OAAOC,MAAM;EACf,CAAC,EAAE,CACDvB,MAAM,EACNE,IAAI,EACJC,KAAK,EACLE,eAAe,EACfC,aAAa,EACbC,eAAe,EACfE,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXC,WAAW,EACXG,YAAY,CACb,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ import { forwardRef } from 'react';
4
+ import { NativeNitroImage } from 'react-native-nitro-image';
5
+ import { cornerRadiusForStyle } from './resizeForStyle';
6
+ import { recyclingKeyFor } from './resolveImageSource';
7
+ import { usePipelineImageLoader } from './usePipelineImageLoader';
8
+
9
+ /**
10
+ * The instance `<NativePipelineImage>` exposes through its `ref` — the
11
+ * underlying `NativeNitroImage` host view, with the usual native-view
12
+ * methods (`measure`, …).
13
+ */
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ /**
16
+ * The fully native-driven variant of `PipelineImage`: after the first render
17
+ * there is **zero JS work per image**. The native view starts the request
18
+ * when it attaches to the window — at its own laid-out size, so nothing
19
+ * waits for an `onLayout` round trip — and cancels it (releasing the bitmap)
20
+ * when it detaches, which makes off-screen list cells free. Loads go through
21
+ * the same pipeline and caches as `useImage`/`preLoadImage`.
22
+ *
23
+ * Compared to `PipelineImage`:
24
+ * - No `onLoad`/`onError` callbacks — the loaded `Image` never crosses into
25
+ * JS. Use `PipelineImage` (or `useImage`) when you need them.
26
+ * - The bitmap is loaded once at the size the view first has; if the view is
27
+ * resized later, the bitmap scales with it instead of reloading.
28
+ * @example
29
+ * ```tsx
30
+ * <NativePipelineImage
31
+ * url="https://example.com/photo.jpg"
32
+ * style={{ width: 300, height: 200, borderRadius: 24 }}
33
+ * blur={4}
34
+ * />
35
+ * ```
36
+ */
37
+ export const NativePipelineImage = /*#__PURE__*/forwardRef(function NativePipelineImage({
38
+ url,
39
+ blur,
40
+ cornerRadius,
41
+ cache,
42
+ resize,
43
+ style,
44
+ ...viewProps
45
+ }, ref) {
46
+ // Same precedence as PipelineImage: an explicit prop wins over style.
47
+ const effectiveCornerRadius = cornerRadius ?? cornerRadiusForStyle(style);
48
+ const loader = usePipelineImageLoader(url, {
49
+ blur,
50
+ cornerRadius: effectiveCornerRadius,
51
+ cache,
52
+ resize
53
+ });
54
+ return /*#__PURE__*/_jsx(NativeNitroImage
55
+ // Before the spread so a caller-provided recyclingKey wins.
56
+ , {
57
+ recyclingKey: recyclingKeyFor(url),
58
+ ...viewProps,
59
+ ref: ref,
60
+ style: style,
61
+ image: loader
62
+ });
63
+ });
64
+
65
+ // Reanimated and DevTools read the display name; the forwardRef wrapper
66
+ // would otherwise report as anonymous.
67
+ NativePipelineImage.displayName = 'NativePipelineImage';
68
+ //# sourceMappingURL=NativePipelineImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","NativeNitroImage","cornerRadiusForStyle","recyclingKeyFor","usePipelineImageLoader","jsx","_jsx","NativePipelineImage","url","blur","cornerRadius","cache","resize","style","viewProps","ref","effectiveCornerRadius","loader","recyclingKey","image","displayName"],"sourceRoot":"../../src","sources":["NativePipelineImage.tsx"],"mappings":";;AAAA,SAA4BA,UAAU,QAAQ,OAAO;AAErD,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAA2BC,eAAe,QAAQ,sBAAsB;AAMxE,SAASC,sBAAsB,QAAQ,0BAA0B;;AAKjE;AACA;AACA;AACA;AACA;AAJA,SAAAC,GAAA,IAAAC,IAAA;AAuCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,gBAAGP,UAAU,CAG3C,SAASO,mBAAmBA,CAC5B;EAAEC,GAAG;EAAEC,IAAI;EAAEC,YAAY;EAAEC,KAAK;EAAEC,MAAM;EAAEC,KAAK;EAAE,GAAGC;AAAU,CAAC,EAC/DC,GAAG,EACH;EACA;EACA,MAAMC,qBAAqB,GAAGN,YAAY,IAAIR,oBAAoB,CAACW,KAAK,CAAC;EACzE,MAAMI,MAAM,GAAGb,sBAAsB,CAACI,GAAG,EAAE;IACzCC,IAAI;IACJC,YAAY,EAAEM,qBAAqB;IACnCL,KAAK;IACLC;EACF,CAAC,CAAC;EAEF,oBACEN,IAAA,CAACL;EACC;EAAA;IACAiB,YAAY,EAAEf,eAAe,CAACK,GAAG,CAAE;IAAA,GAC/BM,SAAS;IACbC,GAAG,EAAEA,GAAI;IACTF,KAAK,EAAEA,KAAM;IACbM,KAAK,EAAEF;EAAO,CACf,CAAC;AAEN,CAAC,CAAC;;AAEF;AACA;AACAV,mBAAmB,CAACa,WAAW,GAAG,qBAAqB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","useEffect","useRef","useState","PixelRatio","NativeNitroImage","cornerRadiusForStyle","resizeForLayout","resizeForStyle","useImage","jsx","_jsx","sameSize","a","b","width","height","scaleRadius","cornerRadius","scale","topLeft","topRight","bottomLeft","bottomRight","PipelineImage","url","blur","cache","onLoad","onError","style","onLayout","viewProps","ref","get","styleSize","layoutSize","setLayoutSize","undefined","resize","effectiveCornerRadius","image","error","enabled","onLoadRef","onErrorRef","current","handleLayout","event","nativeEvent","layout","next","prev","displayName"],"sourceRoot":"../../src","sources":["PipelineImage.tsx"],"mappings":";;AAAA,SAEEA,UAAU,EACVC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAGEC,UAAU,QACL,cAAc;AACrB,SAAqBC,gBAAgB,QAAQ,0BAA0B;AAEvE,SACEC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,kBAAkB;AAMzB,SAASC,QAAQ,QAAQ,YAAY;;AAKrC;AACA;AACA;AACA;AACA;AAJA,SAAAC,GAAA,IAAAC,IAAA;AAoCA,SAASC,QAAQA,CAACC,CAAiB,EAAEC,CAAiB,EAAW;EAC/D,OAAOD,CAAC,EAAEE,KAAK,KAAKD,CAAC,EAAEC,KAAK,IAAIF,CAAC,EAAEG,MAAM,KAAKF,CAAC,EAAEE,MAAM;AACzD;AAEA,SAASC,WAAWA,CAClBC,YAAkC,EAClCC,KAAa,EACS;EACtB,IAAI,OAAOD,YAAY,KAAK,QAAQ,EAAE;IACpC,OAAOA,YAAY,GAAGC,KAAK;EAC7B;EACA,OAAO;IACLC,OAAO,EAAE,CAACF,YAAY,CAACE,OAAO,IAAI,CAAC,IAAID,KAAK;IAC5CE,QAAQ,EAAE,CAACH,YAAY,CAACG,QAAQ,IAAI,CAAC,IAAIF,KAAK;IAC9CG,UAAU,EAAE,CAACJ,YAAY,CAACI,UAAU,IAAI,CAAC,IAAIH,KAAK;IAClDI,WAAW,EAAE,CAACL,YAAY,CAACK,WAAW,IAAI,CAAC,IAAIJ;EACjD,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMK,aAAa,gBAAGxB,UAAU,CACrC,SAASwB,aAAaA,CACpB;EACEC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRR,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,KAAwB,IAAK;IACjDjB,QAAQ,GAAGiB,KAAK,CAAC;IACjB,MAAM;MAAEjC,KAAK;MAAEC;IAAO,CAAC,GAAGgC,KAAK,CAACC,WAAW,CAACC,MAAM;IAClD,MAAMC,IAAI,GAAG5C,eAAe,CAACQ,KAAK,EAAEC,MAAM,CAAC;IAC3C;IACA;IACAqB,aAAa,CAAEe,IAAI,IAAMxC,QAAQ,CAACwC,IAAI,EAAED,IAAI,CAAC,GAAGC,IAAI,GAAGD,IAAK,CAAC;EAC/D,CAAC;EAED,oBACExC,IAAA,CAACN,gBAAgB;IAAA,GACX2B,SAAS;IACbC,GAAG,EAAEA,GAAI;IACTH,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEgB,YAAa;IACvBN,KAAK,EAAEA;EAAM,CACd,CAAC;AAEN,CACF,CAAC;;AAED;AACA;AACAjB,aAAa,CAAC6B,WAAW,GAAG,eAAe","ignoreList":[]}
1
+ {"version":3,"names":["forwardRef","useEffect","useRef","useState","PixelRatio","NativeNitroImage","cornerRadiusForStyle","resizeForLayout","resizeForStyle","useImage","jsx","_jsx","sameSize","a","b","width","height","scaleRadius","cornerRadius","scale","topLeft","topRight","bottomLeft","bottomRight","PipelineImage","url","blur","cache","onLoad","onError","style","onLayout","viewProps","ref","get","styleSize","layoutSize","setLayoutSize","undefined","resize","effectiveCornerRadius","image","error","enabled","onLoadRef","onErrorRef","current","handleLayout","event","nativeEvent","layout","next","prev","displayName"],"sourceRoot":"../../src","sources":["PipelineImage.tsx"],"mappings":";;AAAA,SAEEA,UAAU,EACVC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAGEC,UAAU,QACL,cAAc;AACrB,SAAqBC,gBAAgB,QAAQ,0BAA0B;AAEvE,SACEC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,kBAAkB;AAOzB,SAASC,QAAQ,QAAQ,YAAY;;AAKrC;AACA;AACA;AACA;AACA;AAJA,SAAAC,GAAA,IAAAC,IA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C,GAAG,EAAEA,GAAI;IACTH,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEgB,YAAa;IACvBN,KAAK,EAAEA;EAAM,CACd,CAAC;AAEN,CACF,CAAC;;AAED;AACA;AACAjB,aAAa,CAAC6B,WAAW,GAAG,eAAe","ignoreList":[]}
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
 
3
+ export { NativePipelineImage } from './NativePipelineImage';
3
4
  export { NitroImagePipeline } from './NitroImagePipeline';
4
5
  export { PipelineImage } from './PipelineImage';
6
+ export { resolveImageUrl, UNREGISTERED_ASSET_URL } from './resolveImageSource';
5
7
  export { cornerRadiusForStyle, resizeForLayout, resizeForStyle } from './resizeForStyle';
6
8
  export { useImage } from './useImage';
9
+ export { usePipelineImageLoader } from './usePipelineImageLoader';
7
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NitroImagePipeline","PipelineImage","cornerRadiusForStyle","resizeForLayout","resizeForStyle","useImage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,sBAAsB;AACzD,SACEC,aAAa,QAGR,iBAAiB;AACxB,SACEC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,kBAAkB;AAOzB,SAASC,QAAQ,QAAQ,YAAY","ignoreList":[]}
1
+ {"version":3,"names":["NativePipelineImage","NitroImagePipeline","PipelineImage","resolveImageUrl","UNREGISTERED_ASSET_URL","cornerRadiusForStyle","resizeForLayout","resizeForStyle","useImage","usePipelineImageLoader"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,uBAAuB;AAC9B,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SACEC,aAAa,QAGR,iBAAiB;AACxB,SAEEC,eAAe,EACfC,sBAAsB,QACjB,sBAAsB;AAC7B,SACEC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,kBAAkB;AAQzB,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,sBAAsB,QAAQ,0BAA0B","ignoreList":[]}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ import { Image as RNImage } from 'react-native';
4
+
5
+ /**
6
+ * What the pipeline can load: a URL string, or the id a `require()`d image
7
+ * asset evaluates to.
8
+ *
9
+ * As a string, `url` is passed to the native loader as-is. Accepted forms:
10
+ *
11
+ * - `https://` / `http://` — fetched over the network and cached on disk.
12
+ * - `file://` URLs and plain absolute paths (`/var/…/photo.jpg`) — read from
13
+ * the file system. The result is cached in memory only; there is nothing
14
+ * to gain from copying a local file into the disk cache.
15
+ * - Android also accepts `content://` URIs and, from a release build's
16
+ * resources, a bare drawable name — which is what `require()` resolves to
17
+ * there. iOS resolves `require()` to a `file://` URL into the app bundle.
18
+ *
19
+ * A `require('./photo.png')` is resolved with `Image.resolveAssetSource`, so
20
+ * it works the same in debug (streamed from Metro) and release (bundled).
21
+ */
22
+
23
+ /**
24
+ * Turns an {@linkcode ImageSource} into the URL string the native pipeline
25
+ * loads: strings pass through unchanged, a `require()`d asset is resolved via
26
+ * `Image.resolveAssetSource` (the scale-matched variant, like `<Image>`).
27
+ *
28
+ * The components and hooks call this for you; use it when calling
29
+ * `NitroImagePipeline.loadImage`/`preLoadImage` directly with a `require()`.
30
+ * @throws If `source` is a number that is not a registered asset.
31
+ * @example
32
+ * ```ts
33
+ * const image = await NitroImagePipeline.loadImage(
34
+ * resolveImageUrl(require('./photo.png')),
35
+ * { blur: 4 },
36
+ * );
37
+ * ```
38
+ */
39
+ export function resolveImageUrl(source) {
40
+ if (typeof source === 'string') {
41
+ return source;
42
+ }
43
+ const resolved = RNImage.resolveAssetSource(source);
44
+ if (resolved == null) {
45
+ throw new Error(`Not a registered image asset: require() id ${source}`);
46
+ }
47
+ return resolved.uri;
48
+ }
49
+
50
+ /**
51
+ * A URL no loader can resolve, standing in for a `require()` id that is not
52
+ * a registered asset. Its scheme has no fetcher on either platform, so the
53
+ * request fails at load time — the same way a missing file does — instead of
54
+ * throwing from a component's render.
55
+ */
56
+ export const UNREGISTERED_ASSET_URL = 'unregistered-asset://';
57
+
58
+ /**
59
+ * {@linkcode resolveImageUrl} for code that runs during render: an
60
+ * unregistered `require()` id yields {@linkcode UNREGISTERED_ASSET_URL} (and
61
+ * a warning in development) rather than throwing.
62
+ */
63
+ export function resolveImageUrlOrFallback(source) {
64
+ try {
65
+ return resolveImageUrl(source);
66
+ } catch (error) {
67
+ if (__DEV__) {
68
+ console.warn(`[react-native-nitro-image-pipeline] ${error.message}`);
69
+ }
70
+ return UNREGISTERED_ASSET_URL;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * A stable, per-source `recyclingKey` for `<NativeNitroImage>`: the URL
76
+ * itself for strings, and a tag derived from the asset id for a `require()`
77
+ * (resolving it would cost an asset-registry lookup per render for nothing
78
+ * more than a distinct key).
79
+ */
80
+ export function recyclingKeyFor(source) {
81
+ return typeof source === 'string' ? source : `asset:${source}`;
82
+ }
83
+ //# sourceMappingURL=resolveImageSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Image","RNImage","resolveImageUrl","source","resolved","resolveAssetSource","Error","uri","UNREGISTERED_ASSET_URL","resolveImageUrlOrFallback","error","__DEV__","console","warn","message","recyclingKeyFor"],"sourceRoot":"../../src","sources":["resolveImageSource.ts"],"mappings":";;AAAA,SAASA,KAAK,IAAIC,OAAO,QAAQ,cAAc;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,MAAmB,EAAU;EAC3D,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EACA,MAAMC,QAAQ,GAAGH,OAAO,CAACI,kBAAkB,CAACF,MAAM,CAAC;EACnD,IAAIC,QAAQ,IAAI,IAAI,EAAE;IACpB,MAAM,IAAIE,KAAK,CAAC,8CAA8CH,MAAM,EAAE,CAAC;EACzE;EACA,OAAOC,QAAQ,CAACG,GAAG;AACrB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG,uBAAuB;;AAE7D;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CAACN,MAAmB,EAAU;EACrE,IAAI;IACF,OAAOD,eAAe,CAACC,MAAM,CAAC;EAChC,CAAC,CAAC,OAAOO,KAAK,EAAE;IACd,IAAIC,OAAO,EAAE;MACXC,OAAO,CAACC,IAAI,CACV,uCAAwCH,KAAK,CAAWI,OAAO,EACjE,CAAC;IACH;IACA,OAAON,sBAAsB;EAC/B;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,eAAeA,CAACZ,MAAmB,EAAU;EAC3D,OAAO,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,SAASA,MAAM,EAAE;AAChE","ignoreList":[]}
@@ -2,12 +2,14 @@
2
2
 
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { NitroImagePipeline } from './NitroImagePipeline';
5
+ import { resolveImageUrl } from './resolveImageSource';
5
6
  /**
6
- * A hook to asynchronously load an image from the
7
- * given {@linkcode AsyncImageSource} into memory.
7
+ * A hook to asynchronously load an image from `url` through the pipeline
8
+ * into memory.
8
9
  * @example
9
10
  * ```ts
10
- * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
11
+ * const { image, error } = useImage({ url: 'https://example.com/photo.jpg' });
12
+ * const { image: logo } = useImage({ url: require('./logo.png') });
11
13
  * ```
12
14
  */
13
15
  export function useImage({
@@ -51,7 +53,9 @@ export function useImage({
51
53
  if (enabled) {
52
54
  (async () => {
53
55
  try {
54
- const result = await NitroImagePipeline.loadImage(url, {
56
+ // Resolved inside the try so an unregistered `require()` id
57
+ // surfaces as the error state instead of throwing from the effect.
58
+ const result = await NitroImagePipeline.loadImage(resolveImageUrl(url), {
55
59
  blur,
56
60
  cornerRadius: isUniformRadius ? uniformRadius : {
57
61
  topLeft,
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","useState","NitroImagePipeline","useImage","url","blur","cornerRadius","resize","cache","enabled","image","setImage","undefined","error","loadedUrlRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","width","resizeHeight","height","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["useImage.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGnD,SAASC,kBAAkB,QAAQ,sBAAsB;AAwBzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC,MAAM;EACNC,KAAK;EACLC,OAAO,GAAG;AA+BZ,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGV,QAAQ,CAAS;IACzCS,KAAK,EAAEE,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAGd,MAAM,CAACI,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMW,eAAe,GAAG,OAAOT,YAAY,KAAK,QAAQ;EACxD,MAAMU,aAAa,GAAGD,eAAe,GAAGT,YAAY,GAAG,CAAC;EACxD,MAAM;IACJW,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,WAAW,GAAG;EAChB,CAAC,GAAGL,eAAe,GAAG,CAAC,CAAC,GAAGT,YAAY;EACvC,MAAMe,WAAW,GAAGd,MAAM,EAAEe,KAAK,IAAI,CAAC;EACtC,MAAMC,YAAY,GAAGhB,MAAM,EAAEiB,MAAM,IAAI,CAAC;EAExCzB,SAAS,CAAC,MAAM;IACd,I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W,EACXE,YAAY,EACZf,KAAK,EACLC,OAAO,CACR,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useRef","useState","NitroImagePipeline","resolveImageUrl","useImage","url","blur","cornerRadius","resize","cache","enabled","image","setImage","undefined","error","loadedUrlRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","width","resizeHeight","height","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["useImage.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGnD,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAA2BC,eAAe,QAAQ,sBAAsB;AAwBxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAC;EACvBC,GAAG;EACHC,IAAI,GAAG,CAAC;EACRC,YAAY,GAAG,CAAC;EAChBC,MAAM;EACNC,KAAK;EACLC,OAAO,GAAG;AAmCZ,CAAC,EAAU;EACT,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGX,QAAQ,CAAS;IACzCU,KAAK,EAAEE,SAAS;IAChBC,KAAK,EAAED;EACT,CAAC,CAAC;EACF,MAAME,YAAY,GAAGf,MAAM,CAACK,GAAG,CAAC;;EAEhC;EACA;EACA,MAAMW,eAAe,GAAG,OAAOT,YAAY,KAAK,QAAQ;EACxD,MAAMU,aAAa,GAAGD,eAAe,GAAGT,YAAY,GAAG,CAAC;EACxD,MAAM;IACJW,OAAO,GAAG,CAAC;IACXC,QAAQ,GAAG,CAAC;IACZC,UAAU,GAAG,CAAC;IACdC,WAAW,GAAG;EAChB,CAAC,GAAGL,eAAe,GAAG,CAAC,CAAC,GAAGT,YAAY;EACvC,MAAMe,WAAW,GAAGd,MAAM,EAAEe,KAAK,IAAI,CAAC;EACtC,MAAMC,YAAY,GAAGhB,MAAM,EAAEiB,MAAM,IAAI,CAAC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,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXC,WAAW,EACXE,YAAY,EACZf,KAAK,EACLC,OAAO,CACR,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ import { useMemo } from 'react';
4
+ import { NitroImagePipeline } from './NitroImagePipeline';
5
+ import { resolveImageUrlOrFallback } from './resolveImageSource';
6
+ /**
7
+ * Creates (and memoizes) an {@linkcode ImageLoader} for `source` — a URL
8
+ * string or a `require()`d asset, see {@linkcode ImageSource} — to pass to
9
+ * `<NativeNitroImage image={...} />`. The view drives it entirely natively:
10
+ * the request starts when the view attaches — at the view's laid-out size,
11
+ * with no JS round trips — and is cancelled when it detaches. See
12
+ * {@linkcode NitroImagePipeline.createImageLoader}.
13
+ *
14
+ * `blur`/`cornerRadius` are in **points** (unlike `useImage`, where they are
15
+ * bitmap pixels); the screen scale is applied natively. Inline object
16
+ * literals are fine — options are compared by value, not identity.
17
+ */
18
+ export function usePipelineImageLoader(source, options) {
19
+ // Split the options into primitives (like useImage does) so an inline
20
+ // literal — a new identity every render — doesn't recreate the loader;
21
+ // recreating it would re-trigger the native load.
22
+ const blur = options?.blur;
23
+ const cache = options?.cache;
24
+ const cornerRadius = options?.cornerRadius;
25
+ const isUniformRadius = typeof cornerRadius === 'number';
26
+ const uniformRadius = isUniformRadius ? cornerRadius : 0;
27
+ const hasCornerObject = !isUniformRadius && cornerRadius !== undefined;
28
+ const {
29
+ topLeft = 0,
30
+ topRight = 0,
31
+ bottomLeft = 0,
32
+ bottomRight = 0
33
+ } = isUniformRadius || cornerRadius === undefined ? {} : cornerRadius;
34
+ const resizeWidth = options?.resize?.width;
35
+ const resizeHeight = options?.resize?.height;
36
+ return useMemo(() => {
37
+ // Runs during render, so an unregistered `require()` id must not throw:
38
+ // it becomes a URL the native loader fails on at load time instead.
39
+ const url = resolveImageUrlOrFallback(source);
40
+ const cornerRadiusOption = isUniformRadius ? uniformRadius : hasCornerObject ? {
41
+ topLeft,
42
+ topRight,
43
+ bottomLeft,
44
+ bottomRight
45
+ } : undefined;
46
+ const stableOptions = {
47
+ blur,
48
+ cache,
49
+ cornerRadius: cornerRadiusOption,
50
+ resize: resizeWidth !== undefined && resizeHeight !== undefined ? {
51
+ width: resizeWidth,
52
+ height: resizeHeight
53
+ } : undefined
54
+ };
55
+ const loader = NitroImagePipeline.createImageLoader(url, stableOptions);
56
+ // `NativeNitroImage` needs a way to tell two loader instances apart when
57
+ // diffing its `image` prop; tag the loader with what it will load (the
58
+ // same convention react-native-nitro-image's own loaders use).
59
+ Object.defineProperty(loader, '__source', {
60
+ enumerable: true,
61
+ configurable: true,
62
+ value: {
63
+ url,
64
+ options: stableOptions
65
+ }
66
+ });
67
+ return loader;
68
+ }, [source, blur, cache, isUniformRadius, uniformRadius, hasCornerObject, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight]);
69
+ }
70
+ //# sourceMappingURL=usePipelineImageLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","NitroImagePipeline","resolveImageUrlOrFallback","usePipelineImageLoader","source","options","blur","cache","cornerRadius","isUniformRadius","uniformRadius","hasCornerObject","undefined","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","resize","width","resizeHeight","height","url","cornerRadiusOption","stableOptions","loader","createImageLoader","Object","defineProperty","enumerable","configurable","value"],"sourceRoot":"../../src","sources":["usePipelineImageLoader.ts"],"mappings":";;AAAA,SAASA,OAAO,QAAQ,OAAO;AAG/B,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAEEC,yBAAyB,QACpB,sBAAsB;AAM7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CACpCC,MAAmB,EACnBC,OAAqB,EACR;EACb;EACA;EACA;EACA,MAAMC,IAAI,GAAGD,OAAO,EAAEC,IAAI;EAC1B,MAAMC,KAAK,GAAG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