react-native-nitro-image-pipeline 1.2.0 → 1.2.1

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 (41) hide show
  1. package/README.md +72 -5
  2. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/HybridNitroImagePipeline.kt +17 -15
  3. package/android/src/main/java/com/margelo/nitro/nitroimagepipeline/transform/ResizeTransformation.kt +1 -2
  4. package/ios/HybridNitroImagePipeline.swift +54 -38
  5. package/ios/RoundedCornersProcessor.swift +1 -1
  6. package/lib/commonjs/NitroImagePipeline.js +9 -0
  7. package/lib/commonjs/NitroImagePipeline.js.map +1 -0
  8. package/lib/commonjs/PipelineImage.js +111 -0
  9. package/lib/commonjs/PipelineImage.js.map +1 -0
  10. package/lib/commonjs/index.js +40 -88
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/resizeForStyle.js +68 -0
  13. package/lib/commonjs/resizeForStyle.js.map +1 -0
  14. package/lib/commonjs/useImage.js +95 -0
  15. package/lib/commonjs/useImage.js.map +1 -0
  16. package/lib/module/NitroImagePipeline.js +5 -0
  17. package/lib/module/NitroImagePipeline.js.map +1 -0
  18. package/lib/module/PipelineImage.js +107 -0
  19. package/lib/module/PipelineImage.js.map +1 -0
  20. package/lib/module/index.js +4 -86
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/resizeForStyle.js +62 -0
  23. package/lib/module/resizeForStyle.js.map +1 -0
  24. package/lib/module/useImage.js +91 -0
  25. package/lib/module/useImage.js.map +1 -0
  26. package/lib/typescript/src/NitroImagePipeline.d.ts +3 -0
  27. package/lib/typescript/src/NitroImagePipeline.d.ts.map +1 -0
  28. package/lib/typescript/src/PipelineImage.d.ts +57 -0
  29. package/lib/typescript/src/PipelineImage.d.ts.map +1 -0
  30. package/lib/typescript/src/index.d.ts +5 -45
  31. package/lib/typescript/src/index.d.ts.map +1 -1
  32. package/lib/typescript/src/resizeForStyle.d.ts +30 -0
  33. package/lib/typescript/src/resizeForStyle.d.ts.map +1 -0
  34. package/lib/typescript/src/useImage.d.ts +53 -0
  35. package/lib/typescript/src/useImage.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/src/NitroImagePipeline.ts +6 -0
  38. package/src/PipelineImage.tsx +156 -0
  39. package/src/index.ts +9 -139
  40. package/src/resizeForStyle.ts +96 -0
  41. package/src/useImage.ts +149 -0
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useImage = useImage;
7
+ var _react = require("react");
8
+ var _NitroImagePipeline = require("./NitroImagePipeline");
9
+ /**
10
+ * A hook to asynchronously load an image from the
11
+ * given {@linkcode AsyncImageSource} into memory.
12
+ * @example
13
+ * ```ts
14
+ * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
15
+ * ```
16
+ */
17
+ function useImage({
18
+ url,
19
+ blur = 0,
20
+ cornerRadius = 0,
21
+ resize,
22
+ cache,
23
+ enabled = true
24
+ }) {
25
+ const [image, setImage] = (0, _react.useState)({
26
+ image: undefined,
27
+ error: undefined
28
+ });
29
+ const loadedUrlRef = (0, _react.useRef)(url);
30
+
31
+ // Split the option into primitives so an inline `{ topLeft: 24, ... }`
32
+ // literal (new identity every render) doesn't re-trigger the effect.
33
+ const isUniformRadius = typeof cornerRadius === 'number';
34
+ const uniformRadius = isUniformRadius ? cornerRadius : 0;
35
+ const {
36
+ topLeft = 0,
37
+ topRight = 0,
38
+ bottomLeft = 0,
39
+ bottomRight = 0
40
+ } = isUniformRadius ? {} : cornerRadius;
41
+ const resizeWidth = resize?.width ?? 0;
42
+ const resizeHeight = resize?.height ?? 0;
43
+ (0, _react.useEffect)(() => {
44
+ let cancelled = false;
45
+ // Only reset to the loading state when the URL changes; for same-URL
46
+ // param tweaks (blur/cornerRadius/cache) keep showing the current image
47
+ // until the new variant resolves, to avoid flashing empty.
48
+ if (loadedUrlRef.current !== url) {
49
+ loadedUrlRef.current = url;
50
+ setImage({
51
+ image: undefined,
52
+ error: undefined
53
+ });
54
+ }
55
+ if (enabled) {
56
+ (async () => {
57
+ try {
58
+ const result = await _NitroImagePipeline.NitroImagePipeline.loadImage(url, {
59
+ blur,
60
+ cornerRadius: isUniformRadius ? uniformRadius : {
61
+ topLeft,
62
+ topRight,
63
+ bottomLeft,
64
+ bottomRight
65
+ },
66
+ resize: resizeWidth > 0 && resizeHeight > 0 ? {
67
+ width: resizeWidth,
68
+ height: resizeHeight
69
+ } : undefined,
70
+ cache
71
+ });
72
+ if (!cancelled) {
73
+ setImage({
74
+ image: result,
75
+ error: undefined
76
+ });
77
+ }
78
+ } catch (e) {
79
+ const error = e instanceof Error ? e : new Error(`${e}`);
80
+ if (!cancelled) {
81
+ setImage({
82
+ image: undefined,
83
+ error: error
84
+ });
85
+ }
86
+ }
87
+ })();
88
+ }
89
+ return () => {
90
+ cancelled = true;
91
+ };
92
+ }, [url, blur, isUniformRadius, uniformRadius, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight, cache, enabled]);
93
+ return image;
94
+ }
95
+ //# sourceMappingURL=useImage.js.map
@@ -0,0 +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;EAC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;YACfL;UACF,CAAC,CAAC;UAEF,IAAI,CAACoB,SAAS,EAAE;YACdjB,QAAQ,CAAC;cAAED,KAAK,EAAEoB,MAAM;cAAEhB,KAAK,EAAED;YAAU,CAAC,CAAC;UAC/C;QACF,CAAC,CAAC,OAAOoB,CAAC,EAAE;UACV,MAAMnB,KAAK,GAAGmB,CAAC,YAAYC,KAAK,GAAGD,CAAC,GAAG,IAAIC,KAAK,CAAC,GAAGD,CAAC,EAAE,CAAC;UACxD,IAAI,CAACL,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,5 @@
1
+ "use strict";
2
+
3
+ import { NitroModules } from 'react-native-nitro-modules';
4
+ export const NitroImagePipeline = NitroModules.createHybridObject('NitroImagePipeline');
5
+ //# sourceMappingURL=NitroImagePipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NitroModules","NitroImagePipeline","createHybridObject"],"sourceRoot":"../../src","sources":["NitroImagePipeline.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAIzD,OAAO,MAAMC,kBAAkB,GAC7BD,YAAY,CAACE,kBAAkB,CAAyB,oBAAoB,CAAC","ignoreList":[]}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { PixelRatio } from 'react-native';
5
+ import { NativeNitroImage } from 'react-native-nitro-image';
6
+ import { cornerRadiusForStyle, resizeForLayout, resizeForStyle } from './resizeForStyle';
7
+ import { useImage } from './useImage';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ function sameSize(a, b) {
10
+ return a?.width === b?.width && a?.height === b?.height;
11
+ }
12
+ function scaleRadius(cornerRadius, scale) {
13
+ if (typeof cornerRadius === 'number') {
14
+ return cornerRadius * scale;
15
+ }
16
+ return {
17
+ topLeft: (cornerRadius.topLeft ?? 0) * scale,
18
+ topRight: (cornerRadius.topRight ?? 0) * scale,
19
+ bottomLeft: (cornerRadius.bottomLeft ?? 0) * scale,
20
+ bottomRight: (cornerRadius.bottomRight ?? 0) * scale
21
+ };
22
+ }
23
+
24
+ /**
25
+ * A `NativeNitroImage` that loads `url` through the pipeline at exactly the
26
+ * size it is displayed: the bitmap is resized to the view's size in points ×
27
+ * `PixelRatio.get()`, so `blur` and `cornerRadius` (both in points here) apply
28
+ * 1:1 to what is on screen and large sources are never decoded at full size.
29
+ *
30
+ * A numeric `width`/`height` in `style` starts loading immediately; otherwise
31
+ * (`'50%'`, `flex`, `aspectRatio`, …) loading waits for the first `onLayout`.
32
+ * If the layout size later changes, a new variant is loaded and swapped in
33
+ * without flashing. Without an explicit `cornerRadius` prop, `style`'s
34
+ * `borderRadius`-family properties are baked into the bitmap instead — no
35
+ * separate view-layer rounding needed.
36
+ * @example
37
+ * ```tsx
38
+ * <PipelineImage
39
+ * url="https://example.com/photo.jpg"
40
+ * style={{ width: 300, height: 200 }}
41
+ * cornerRadius={24}
42
+ * />
43
+ * ```
44
+ */
45
+ export function PipelineImage({
46
+ url,
47
+ blur = 0,
48
+ cornerRadius,
49
+ cache,
50
+ onLoad,
51
+ onError,
52
+ style,
53
+ onLayout,
54
+ ...viewProps
55
+ }) {
56
+ const scale = PixelRatio.get();
57
+ const styleSize = resizeForStyle(style);
58
+ const [layoutSize, setLayoutSize] = useState(undefined);
59
+ // A numeric style is what the caller declared, so it wins and starts the
60
+ // request a frame earlier; the measured layout is the fallback.
61
+ const resize = styleSize ?? layoutSize;
62
+ // Same precedence: an explicit prop wins over what style implies.
63
+ const effectiveCornerRadius = cornerRadius ?? cornerRadiusForStyle(style) ?? 0;
64
+ const {
65
+ image,
66
+ error
67
+ } = useImage({
68
+ url,
69
+ blur: blur * scale,
70
+ cornerRadius: scaleRadius(effectiveCornerRadius, scale),
71
+ cache,
72
+ resize,
73
+ enabled: resize !== undefined
74
+ });
75
+
76
+ // Latest callbacks in refs so inline arrow props don't re-fire the effects.
77
+ const onLoadRef = useRef(onLoad);
78
+ const onErrorRef = useRef(onError);
79
+ useEffect(() => {
80
+ onLoadRef.current = onLoad;
81
+ onErrorRef.current = onError;
82
+ });
83
+ useEffect(() => {
84
+ if (image) onLoadRef.current?.(image);
85
+ }, [image]);
86
+ useEffect(() => {
87
+ if (error) onErrorRef.current?.(error);
88
+ }, [error]);
89
+ const handleLayout = event => {
90
+ onLayout?.(event);
91
+ const {
92
+ width,
93
+ height
94
+ } = event.nativeEvent.layout;
95
+ const next = resizeForLayout(width, height);
96
+ // Always record it (even when a numeric style is in charge) so a later
97
+ // switch to a non-numeric style has a size to fall back on.
98
+ setLayoutSize(prev => sameSize(prev, next) ? prev : next);
99
+ };
100
+ return /*#__PURE__*/_jsx(NativeNitroImage, {
101
+ ...viewProps,
102
+ style: style,
103
+ onLayout: handleLayout,
104
+ image: image
105
+ });
106
+ }
107
+ //# sourceMappingURL=PipelineImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["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","get","styleSize","layoutSize","setLayoutSize","undefined","resize","effectiveCornerRadius","image","error","enabled","onLoadRef","onErrorRef","current","handleLayout","event","nativeEvent","layout","next","prev"],"sourceRoot":"../../src","sources":["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,KAAK,EAAEC,MAAM,CAAC;IAC3C;IACA;IACAoB,aAAa,CAAEe,IAAI,IAAMvC,QAAQ,CAACuC,IAAI,EAAED,IAAI,CAAC,GAAGC,IAAI,GAAGD,IAAK,CAAC;EAC/D,CAAC;EAED,oBACEvC,IAAA,CAACN,gBAAgB;IAAA,GACX2B,SAAS;IACbF,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEe,YAAa;IACvBN,KAAK,EAAEA;EAAM,CACd,CAAC;AAEN","ignoreList":[]}
@@ -1,89 +1,7 @@
1
1
  "use strict";
2
2
 
3
- import { useEffect, useRef, useState } from 'react';
4
- import { NitroModules } from 'react-native-nitro-modules';
5
- export const NitroImagePipeline = NitroModules.createHybridObject('NitroImagePipeline');
6
- /**
7
- * A hook to asynchronously load an image from the
8
- * given {@linkcode AsyncImageSource} into memory.
9
- * @example
10
- * ```ts
11
- * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
12
- * ```
13
- */
14
- export function useImage({
15
- url,
16
- blur = 0,
17
- cornerRadius = 0,
18
- resize,
19
- cache
20
- }) {
21
- const [image, setImage] = useState({
22
- image: undefined,
23
- error: undefined
24
- });
25
- const loadedUrlRef = useRef(url);
26
-
27
- // Split the option into primitives so an inline `{ topLeft: 24, ... }`
28
- // literal (new identity every render) doesn't re-trigger the effect.
29
- const isUniformRadius = typeof cornerRadius === 'number';
30
- const uniformRadius = isUniformRadius ? cornerRadius : 0;
31
- const {
32
- topLeft = 0,
33
- topRight = 0,
34
- bottomLeft = 0,
35
- bottomRight = 0
36
- } = isUniformRadius ? {} : cornerRadius;
37
- const resizeWidth = resize?.width ?? 0;
38
- const resizeHeight = resize?.height ?? 0;
39
- useEffect(() => {
40
- let cancelled = false;
41
- // Only reset to the loading state when the URL changes; for same-URL
42
- // param tweaks (blur/cornerRadius/cache) keep showing the current image
43
- // until the new variant resolves, to avoid flashing empty.
44
- if (loadedUrlRef.current !== url) {
45
- loadedUrlRef.current = url;
46
- setImage({
47
- image: undefined,
48
- error: undefined
49
- });
50
- }
51
- (async () => {
52
- try {
53
- const result = await NitroImagePipeline.loadImage(url, {
54
- blur,
55
- cornerRadius: isUniformRadius ? uniformRadius : {
56
- topLeft,
57
- topRight,
58
- bottomLeft,
59
- bottomRight
60
- },
61
- resize: resizeWidth > 0 && resizeHeight > 0 ? {
62
- width: resizeWidth,
63
- height: resizeHeight
64
- } : undefined,
65
- cache
66
- });
67
- if (!cancelled) {
68
- setImage({
69
- image: result,
70
- error: undefined
71
- });
72
- }
73
- } catch (e) {
74
- const error = e instanceof Error ? e : new Error(`${e}`);
75
- if (!cancelled) {
76
- setImage({
77
- image: undefined,
78
- error: error
79
- });
80
- }
81
- }
82
- })();
83
- return () => {
84
- cancelled = true;
85
- };
86
- }, [url, blur, isUniformRadius, uniformRadius, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight, cache]);
87
- return image;
88
- }
3
+ export { NitroImagePipeline } from './NitroImagePipeline';
4
+ export { PipelineImage } from './PipelineImage';
5
+ export { cornerRadiusForStyle, resizeForLayout, resizeForStyle } from './resizeForStyle';
6
+ export { useImage } from './useImage';
89
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","useState","NitroModules","NitroImagePipeline","createHybridObject","useImage","url","blur","cornerRadius","resize","cache","image","setImage","undefined","error","loadedUrlRef","isUniformRadius","uniformRadius","topLeft","topRight","bottomLeft","bottomRight","resizeWidth","width","resizeHeight","height","cancelled","current","result","loadImage","e","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,YAAY,QAAQ,4BAA4B;AAYzD,OAAO,MAAMC,kBAAkB,GAC7BD,YAAY,CAACE,kBAAkB,CAAyB,oBAAoB,CAAC;AAmB/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAC;EACvBC,GAAG;E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EG,MAAM,EAAED;UAAa,CAAC,GAC5CX,SAAS;UACfH;QACF,CAAC,CAAC;QAEF,IAAI,CAACgB,SAAS,EAAE;UACdd,QAAQ,CAAC;YAAED,KAAK,EAAEiB,MAAM;YAAEd,KAAK,EAAED;UAAU,CAAC,CAAC;QAC/C;MACF,CAAC,CAAC,OAAOiB,CAAC,EAAE;QACV,MAAMhB,KAAK,GAAGgB,CAAC,YAAYC,KAAK,GAAGD,CAAC,GAAG,IAAIC,KAAK,CAAC,GAAGD,CAAC,EAAE,CAAC;QACxD,IAAI,CAACJ,SAAS,EAAE;UACdd,QAAQ,CAAC;YAAED,KAAK,EAAEE,SAAS;YAAEC,KAAK,EAAEA;UAAM,CAAC,CAAC;QAC9C;MACF;IACF,CAAC,EAAE,CAAC;IAEJ,OAAO,MAAM;MACXY,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CACDpB,GAAG,EACHC,IAAI,EACJS,eAAe,EACfC,aAAa,EACbC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,WAAW,EACXC,WAAW,EACXE,YAAY,EACZd,KAAK,CACN,CAAC;EAEF,OAAOC,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"names":["NitroImagePipeline","PipelineImage","cornerRadiusForStyle","resizeForLayout","resizeForStyle","useImage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,aAAa,QAAiC,iBAAiB;AACxE,SACEC,oBAAoB,EACpBC,eAAe,EACfC,cAAc,QACT,kBAAkB;AAOzB,SAASC,QAAQ,QAAQ,YAAY","ignoreList":[]}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ import { PixelRatio, StyleSheet } from 'react-native';
4
+ /**
5
+ * Converts a layout size in points (dp) to the pipeline's `resize` option in
6
+ * whole bitmap pixels using `PixelRatio.getPixelSizeForLayoutSize`. Returns
7
+ * `undefined` unless both values are positive numbers.
8
+ */
9
+ export function resizeForLayout(width, height) {
10
+ if (typeof width !== 'number' || typeof height !== 'number') {
11
+ return undefined;
12
+ }
13
+ const pixelWidth = PixelRatio.getPixelSizeForLayoutSize(width);
14
+ const pixelHeight = PixelRatio.getPixelSizeForLayoutSize(height);
15
+ return pixelWidth > 0 && pixelHeight > 0 ? {
16
+ width: pixelWidth,
17
+ height: pixelHeight
18
+ } : undefined;
19
+ }
20
+
21
+ /**
22
+ * Derives the pipeline's `resize` option from a view style whose `width` and
23
+ * `height` are numeric points, so the bitmap matches the display size on
24
+ * every screen density:
25
+ * ```ts
26
+ * useImage({ url, resize: resizeForStyle(styles.image) });
27
+ * ```
28
+ * Arrays and registered styles are flattened. Returns `undefined` when either
29
+ * dimension is missing or not a number (`'50%'`, `'auto'`, flex-driven) —
30
+ * use `<PipelineImage>` for those, which measures the view instead.
31
+ */
32
+ export function resizeForStyle(style) {
33
+ const flat = StyleSheet.flatten(style);
34
+ return resizeForLayout(flat?.width, flat?.height);
35
+ }
36
+
37
+ /**
38
+ * Derives a `cornerRadius` option from a view style's `borderRadius` /
39
+ * `borderTopLeftRadius` / `borderTopRightRadius` / `borderBottomLeftRadius` /
40
+ * `borderBottomRightRadius`, in points. Per-corner properties override
41
+ * `borderRadius` for that corner; a corner with neither set stays square.
42
+ * Non-numeric values (percentages, animated values) are ignored, like
43
+ * {@linkcode resizeForStyle}. Returns `undefined` when none are set.
44
+ */
45
+ export function cornerRadiusForStyle(style) {
46
+ const flat = StyleSheet.flatten(style);
47
+ const base = typeof flat?.borderRadius === 'number' ? flat.borderRadius : undefined;
48
+ const topLeft = typeof flat?.borderTopLeftRadius === 'number' ? flat.borderTopLeftRadius : undefined;
49
+ const topRight = typeof flat?.borderTopRightRadius === 'number' ? flat.borderTopRightRadius : undefined;
50
+ const bottomLeft = typeof flat?.borderBottomLeftRadius === 'number' ? flat.borderBottomLeftRadius : undefined;
51
+ const bottomRight = typeof flat?.borderBottomRightRadius === 'number' ? flat.borderBottomRightRadius : undefined;
52
+ if (topLeft === undefined && topRight === undefined && bottomLeft === undefined && bottomRight === undefined) {
53
+ return base;
54
+ }
55
+ return {
56
+ topLeft: topLeft ?? base,
57
+ topRight: topRight ?? base,
58
+ bottomLeft: bottomLeft ?? base,
59
+ bottomRight: bottomRight ?? base
60
+ };
61
+ }
62
+ //# sourceMappingURL=resizeForStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PixelRatio","StyleSheet","resizeForLayout","width","height","undefined","pixelWidth","getPixelSizeForLayoutSize","pixelHeight","resizeForStyle","style","flat","flatten","cornerRadiusForStyle","base","borderRadius","topLeft","borderTopLeftRadius","topRight","borderTopRightRadius","bottomLeft","borderBottomLeftRadius","bottomRight","borderBottomRightRadius"],"sourceRoot":"../../src","sources":["resizeForStyle.ts"],"mappings":";;AAAA,SACEA,UAAU,EAEVC,UAAU,QAEL,cAAc;AAOrB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,KAAc,EACdC,MAAe,EACY;EAC3B,IAAI,OAAOD,KAAK,KAAK,QAAQ,IAAI,OAAOC,MAAM,KAAK,QAAQ,EAAE;IAC3D,OAAOC,SAAS;EAClB;EACA,MAAMC,UAAU,GAAGN,UAAU,CAACO,yBAAyB,CAACJ,KAAK,CAAC;EAC9D,MAAMK,WAAW,GAAGR,UAAU,CAACO,yBAAyB,CAACH,MAAM,CAAC;EAChE,OAAOE,UAAU,GAAG,CAAC,IAAIE,WAAW,GAAG,CAAC,GACpC;IAAEL,KAAK,EAAEG,UAAU;IAAEF,MAAM,EAAEI;EAAY,CAAC,GAC1CH,SAAS;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,cAAcA,CAC5BC,KAA2B,EACA;EAC3B,MAAMC,IAAI,GAAGV,UAAU,CAACW,OAAO,CAACF,KAAK,CAAC;EACtC,OAAOR,eAAe,CAACS,IAAI,EAAER,KAAK,EAAEQ,IAAI,EAAEP,MAAM,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,oBAAoBA,CAClCH,KAA2B,EACO;EAClC,MAAMC,IAAI,GAAGV,UAAU,CAACW,OAAO,CAACF,KAAK,CAAC;EACtC,MAAMI,IAAI,GACR,OAAOH,IAAI,EAAEI,YAAY,KAAK,QAAQ,GAAGJ,IAAI,CAACI,YAAY,GAAGV,SAAS;EACxE,MAAMW,OAAO,GACX,OAAOL,IAAI,EAAEM,mBAAmB,KAAK,QAAQ,GACzCN,IAAI,CAACM,mBAAmB,GACxBZ,SAAS;EACf,MAAMa,QAAQ,GACZ,OAAOP,IAAI,EAAEQ,oBAAoB,KAAK,QAAQ,GAC1CR,IAAI,CAACQ,oBAAoB,GACzBd,SAAS;EACf,MAAMe,UAAU,GACd,OAAOT,IAAI,EAAEU,sBAAsB,KAAK,QAAQ,GAC5CV,IAAI,CAACU,sBAAsB,GAC3BhB,SAAS;EACf,MAAMiB,WAAW,GACf,OAAOX,IAAI,EAAEY,uBAAuB,KAAK,QAAQ,GAC7CZ,IAAI,CAACY,uBAAuB,GAC5BlB,SAAS;EAEf,IACEW,OAAO,KAAKX,SAAS,IACrBa,QAAQ,KAAKb,SAAS,IACtBe,UAAU,KAAKf,SAAS,IACxBiB,WAAW,KAAKjB,SAAS,EACzB;IACA,OAAOS,IAAI;EACb;EAEA,OAAO;IACLE,OAAO,EAAEA,OAAO,IAAIF,IAAI;IACxBI,QAAQ,EAAEA,QAAQ,IAAIJ,IAAI;IAC1BM,UAAU,EAAEA,UAAU,IAAIN,IAAI;IAC9BQ,WAAW,EAAEA,WAAW,IAAIR;EAC9B,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { NitroImagePipeline } from './NitroImagePipeline';
5
+ /**
6
+ * A hook to asynchronously load an image from the
7
+ * given {@linkcode AsyncImageSource} into memory.
8
+ * @example
9
+ * ```ts
10
+ * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
11
+ * ```
12
+ */
13
+ export function useImage({
14
+ url,
15
+ blur = 0,
16
+ cornerRadius = 0,
17
+ resize,
18
+ cache,
19
+ enabled = true
20
+ }) {
21
+ const [image, setImage] = useState({
22
+ image: undefined,
23
+ error: undefined
24
+ });
25
+ const loadedUrlRef = useRef(url);
26
+
27
+ // Split the option into primitives so an inline `{ topLeft: 24, ... }`
28
+ // literal (new identity every render) doesn't re-trigger the effect.
29
+ const isUniformRadius = typeof cornerRadius === 'number';
30
+ const uniformRadius = isUniformRadius ? cornerRadius : 0;
31
+ const {
32
+ topLeft = 0,
33
+ topRight = 0,
34
+ bottomLeft = 0,
35
+ bottomRight = 0
36
+ } = isUniformRadius ? {} : cornerRadius;
37
+ const resizeWidth = resize?.width ?? 0;
38
+ const resizeHeight = resize?.height ?? 0;
39
+ useEffect(() => {
40
+ let cancelled = false;
41
+ // Only reset to the loading state when the URL changes; for same-URL
42
+ // param tweaks (blur/cornerRadius/cache) keep showing the current image
43
+ // until the new variant resolves, to avoid flashing empty.
44
+ if (loadedUrlRef.current !== url) {
45
+ loadedUrlRef.current = url;
46
+ setImage({
47
+ image: undefined,
48
+ error: undefined
49
+ });
50
+ }
51
+ if (enabled) {
52
+ (async () => {
53
+ try {
54
+ const result = await NitroImagePipeline.loadImage(url, {
55
+ blur,
56
+ cornerRadius: isUniformRadius ? uniformRadius : {
57
+ topLeft,
58
+ topRight,
59
+ bottomLeft,
60
+ bottomRight
61
+ },
62
+ resize: resizeWidth > 0 && resizeHeight > 0 ? {
63
+ width: resizeWidth,
64
+ height: resizeHeight
65
+ } : undefined,
66
+ cache
67
+ });
68
+ if (!cancelled) {
69
+ setImage({
70
+ image: result,
71
+ error: undefined
72
+ });
73
+ }
74
+ } catch (e) {
75
+ const error = e instanceof Error ? e : new Error(`${e}`);
76
+ if (!cancelled) {
77
+ setImage({
78
+ image: undefined,
79
+ error: error
80
+ });
81
+ }
82
+ }
83
+ })();
84
+ }
85
+ return () => {
86
+ cancelled = true;
87
+ };
88
+ }, [url, blur, isUniformRadius, uniformRadius, topLeft, topRight, bottomLeft, bottomRight, resizeWidth, resizeHeight, cache, enabled]);
89
+ return image;
90
+ }
91
+ //# sourceMappingURL=useImage.js.map
@@ -0,0 +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;E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C,IAAI,EACJU,eAAe,EACfC,aAAa,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,3 @@
1
+ import type { NitroImagePipeline as NitroImagePipelineSpec } from './specs/nitro-image-toolkit.nitro';
2
+ export declare const NitroImagePipeline: NitroImagePipelineSpec;
3
+ //# sourceMappingURL=NitroImagePipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NitroImagePipeline.d.ts","sourceRoot":"","sources":["../../../src/NitroImagePipeline.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,IAAI,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEtG,eAAO,MAAM,kBAAkB,wBACgD,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { type HostComponent } from 'react-native';
2
+ import { type Image, NativeNitroImage } from 'react-native-nitro-image';
3
+ import type { CacheOption, CornerRadii } from './specs/nitro-image-toolkit.nitro';
4
+ type ReactProps<T> = T extends HostComponent<infer P> ? P : never;
5
+ type NativeImageProps = ReactProps<typeof NativeNitroImage>;
6
+ export interface PipelineImageProps extends Omit<NativeImageProps, 'image'> {
7
+ /** URL of the image to load through the pipeline. */
8
+ url: string;
9
+ /**
10
+ * Gaussian blur sigma in **points** (density-independent). Unlike
11
+ * `useImage`/`loadImage`, where it is bitmap pixels, the component
12
+ * multiplies it by `PixelRatio.get()` so the same value looks the same on
13
+ * every device.
14
+ * @default 0
15
+ */
16
+ blur?: number;
17
+ /**
18
+ * Corner radius in **points** — a single number or per-corner radii.
19
+ * Converted to bitmap pixels with `PixelRatio.get()` and baked into the
20
+ * bitmap at the display size.
21
+ *
22
+ * When omitted, it's derived from `style`'s `borderRadius` /
23
+ * `borderTopLeftRadius` / `borderTopRightRadius` / `borderBottomLeftRadius`
24
+ * / `borderBottomRightRadius` instead — set this prop to override that.
25
+ * @default undefined (derived from `style`, or square corners if unset there)
26
+ */
27
+ cornerRadius?: number | CornerRadii;
28
+ cache?: CacheOption;
29
+ /** Called with the processed `Image` each time a new variant resolves. */
30
+ onLoad?: (image: Image) => void;
31
+ /** Called when loading fails. */
32
+ onError?: (error: Error) => void;
33
+ }
34
+ /**
35
+ * A `NativeNitroImage` that loads `url` through the pipeline at exactly the
36
+ * size it is displayed: the bitmap is resized to the view's size in points ×
37
+ * `PixelRatio.get()`, so `blur` and `cornerRadius` (both in points here) apply
38
+ * 1:1 to what is on screen and large sources are never decoded at full size.
39
+ *
40
+ * A numeric `width`/`height` in `style` starts loading immediately; otherwise
41
+ * (`'50%'`, `flex`, `aspectRatio`, …) loading waits for the first `onLayout`.
42
+ * If the layout size later changes, a new variant is loaded and swapped in
43
+ * without flashing. Without an explicit `cornerRadius` prop, `style`'s
44
+ * `borderRadius`-family properties are baked into the bitmap instead — no
45
+ * separate view-layer rounding needed.
46
+ * @example
47
+ * ```tsx
48
+ * <PipelineImage
49
+ * url="https://example.com/photo.jpg"
50
+ * style={{ width: 300, height: 200 }}
51
+ * cornerRadius={24}
52
+ * />
53
+ * ```
54
+ */
55
+ export declare function PipelineImage({ url, blur, cornerRadius, cache, onLoad, onError, style, onLayout, ...viewProps }: PipelineImageProps): import("react").JSX.Element;
56
+ export {};
57
+ //# sourceMappingURL=PipelineImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PipelineImage.d.ts","sourceRoot":"","sources":["../../../src/PipelineImage.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAOxE,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEZ,MAAM,mCAAmC,CAAC;AAG3C,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAClE,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACzE,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,iCAAiC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,GAAG,EACH,IAAQ,EACR,YAAY,EACZ,KAAK,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,QAAQ,EACR,GAAG,SAAS,EACb,EAAE,kBAAkB,+BAqDpB"}
@@ -1,46 +1,6 @@
1
- import type { Image } from 'react-native-nitro-image';
2
- import type { CacheOption, CornerRadii, NitroImagePipeline as NitroImagePipelineSpec, Options, ResizeOptions } from './specs/nitro-image-toolkit.nitro';
3
- export type { CacheOption, CornerRadii, Options, ResizeOptions };
4
- export declare const NitroImagePipeline: NitroImagePipelineSpec;
5
- type Result = {
6
- image: undefined;
7
- error: undefined;
8
- } | {
9
- image: Image;
10
- error: undefined;
11
- } | {
12
- image: undefined;
13
- error: Error;
14
- };
15
- /**
16
- * A hook to asynchronously load an image from the
17
- * given {@linkcode AsyncImageSource} into memory.
18
- * @example
19
- * ```ts
20
- * const { image, error } = useImage({ filePath: '/tmp/image.jpg' })
21
- * ```
22
- */
23
- export declare function useImage({ url, blur, cornerRadius, resize, cache, }: {
24
- url: string;
25
- /**
26
- * Gaussian blur strength, as the standard deviation (sigma) of the blur in
27
- * source-image pixels (of the resized bitmap when `resize` is set). Matches
28
- * across iOS and Android; roughly half of React Native's `blurRadius`.
29
- */
30
- blur?: number;
31
- /**
32
- * Corner radius in pixels of the loaded bitmap. Pass a single number for
33
- * uniform rounding, or per-corner radii (inline object literals are fine —
34
- * the hook compares the radii by value, not identity). Pair with `resize`
35
- * so the radii apply at the size you display instead of the source size.
36
- */
37
- cornerRadius?: number | CornerRadii;
38
- /**
39
- * Resize the bitmap to exactly this size in pixels (aspect-fill,
40
- * center-crop) before blur/rounding. Typically your display size in points
41
- * multiplied by `PixelRatio.get()`. Inline object literals are fine.
42
- */
43
- resize?: ResizeOptions;
44
- cache?: CacheOption;
45
- }): Result;
1
+ export { NitroImagePipeline } from './NitroImagePipeline';
2
+ export { PipelineImage, type PipelineImageProps } from './PipelineImage';
3
+ export { cornerRadiusForStyle, resizeForLayout, resizeForStyle, } from './resizeForStyle';
4
+ export type { CacheOption, CornerRadii, Options, ResizeOptions, } from './specs/nitro-image-toolkit.nitro';
5
+ export { useImage } from './useImage';
46
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,IAAI,sBAAsB,EAC5C,OAAO,EACP,aAAa,EACd,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;AAEjE,eAAO,MAAM,kBAAkB,wBACgD,CAAC;AAEhF,KAAK,MAAM,GAEP;IACE,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB,GAED;IACE,KAAK,EAAE,KAAK,CAAC;I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