rn-remove-image-bg 0.0.10

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 (74) hide show
  1. package/NitroRnRemoveImageBg.podspec +33 -0
  2. package/README.md +386 -0
  3. package/android/CMakeLists.txt +28 -0
  4. package/android/build.gradle +142 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +3 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemover.kt +189 -0
  10. package/android/src/main/java/com/margelo/nitro/rnremoveimagebg/NitroRnRemoveImageBgPackage.kt +31 -0
  11. package/app.plugin.js +12 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/HybridImageBackgroundRemover.swift +224 -0
  14. package/ios/NitroRnRemoveImageBgOnLoad.mm +22 -0
  15. package/lib/ImageProcessing.d.ts +167 -0
  16. package/lib/ImageProcessing.js +323 -0
  17. package/lib/ImageProcessing.web.d.ts +80 -0
  18. package/lib/ImageProcessing.web.js +248 -0
  19. package/lib/__tests__/cache.test.d.ts +1 -0
  20. package/lib/__tests__/cache.test.js +87 -0
  21. package/lib/__tests__/errors.test.d.ts +1 -0
  22. package/lib/__tests__/errors.test.js +82 -0
  23. package/lib/cache.d.ts +72 -0
  24. package/lib/cache.js +228 -0
  25. package/lib/errors.d.ts +20 -0
  26. package/lib/errors.js +64 -0
  27. package/lib/index.d.ts +6 -0
  28. package/lib/index.js +9 -0
  29. package/lib/specs/Example.nitro.d.ts +0 -0
  30. package/lib/specs/Example.nitro.js +2 -0
  31. package/lib/specs/ImageBackgroundRemover.nitro.d.ts +41 -0
  32. package/lib/specs/ImageBackgroundRemover.nitro.js +1 -0
  33. package/nitro.json +17 -0
  34. package/nitrogen/generated/.gitattributes +1 -0
  35. package/nitrogen/generated/android/NitroRnRemoveImageBg+autolinking.cmake +81 -0
  36. package/nitrogen/generated/android/NitroRnRemoveImageBg+autolinking.gradle +27 -0
  37. package/nitrogen/generated/android/NitroRnRemoveImageBgOnLoad.cpp +44 -0
  38. package/nitrogen/generated/android/NitroRnRemoveImageBgOnLoad.hpp +25 -0
  39. package/nitrogen/generated/android/c++/JHybridImageBackgroundRemoverSpec.cpp +72 -0
  40. package/nitrogen/generated/android/c++/JHybridImageBackgroundRemoverSpec.hpp +65 -0
  41. package/nitrogen/generated/android/c++/JNativeRemoveBackgroundOptions.hpp +66 -0
  42. package/nitrogen/generated/android/c++/JOutputFormat.hpp +59 -0
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemoverSpec.kt +58 -0
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/NativeRemoveBackgroundOptions.kt +44 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/NitroRnRemoveImageBgOnLoad.kt +35 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/OutputFormat.kt +21 -0
  47. package/nitrogen/generated/ios/NitroRnRemoveImageBg+autolinking.rb +60 -0
  48. package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Bridge.cpp +49 -0
  49. package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp +111 -0
  50. package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Umbrella.hpp +51 -0
  51. package/nitrogen/generated/ios/c++/HybridImageBackgroundRemoverSpecSwift.cpp +11 -0
  52. package/nitrogen/generated/ios/c++/HybridImageBackgroundRemoverSpecSwift.hpp +82 -0
  53. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  54. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  55. package/nitrogen/generated/ios/swift/HybridImageBackgroundRemoverSpec.swift +56 -0
  56. package/nitrogen/generated/ios/swift/HybridImageBackgroundRemoverSpec_cxx.swift +138 -0
  57. package/nitrogen/generated/ios/swift/NativeRemoveBackgroundOptions.swift +58 -0
  58. package/nitrogen/generated/ios/swift/OutputFormat.swift +40 -0
  59. package/nitrogen/generated/shared/c++/HybridImageBackgroundRemoverSpec.cpp +21 -0
  60. package/nitrogen/generated/shared/c++/HybridImageBackgroundRemoverSpec.hpp +65 -0
  61. package/nitrogen/generated/shared/c++/NativeRemoveBackgroundOptions.hpp +84 -0
  62. package/nitrogen/generated/shared/c++/OutputFormat.hpp +76 -0
  63. package/package.json +104 -0
  64. package/react-native.config.js +16 -0
  65. package/src/ImageProcessing.ts +532 -0
  66. package/src/ImageProcessing.web.ts +342 -0
  67. package/src/__tests__/ImageProcessing.test.ts +278 -0
  68. package/src/__tests__/cache.test.ts +110 -0
  69. package/src/__tests__/errors.test.ts +117 -0
  70. package/src/cache.ts +305 -0
  71. package/src/errors.ts +93 -0
  72. package/src/index.ts +49 -0
  73. package/src/specs/Example.nitro.ts +1 -0
  74. package/src/specs/ImageBackgroundRemover.nitro.ts +49 -0
@@ -0,0 +1,40 @@
1
+ ///
2
+ /// OutputFormat.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /**
9
+ * Represents the JS union `OutputFormat`, backed by a C++ enum.
10
+ */
11
+ public typealias OutputFormat = margelo.nitro.rnremoveimagebg.OutputFormat
12
+
13
+ public extension OutputFormat {
14
+ /**
15
+ * Get a OutputFormat for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "PNG":
21
+ self = .png
22
+ case "WEBP":
23
+ self = .webp
24
+ default:
25
+ return nil
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Get the String value this OutputFormat represents.
31
+ */
32
+ var stringValue: String {
33
+ switch self {
34
+ case .png:
35
+ return "PNG"
36
+ case .webp:
37
+ return "WEBP"
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridImageBackgroundRemoverSpec.hpp"
9
+
10
+ namespace margelo::nitro::rnremoveimagebg {
11
+
12
+ void HybridImageBackgroundRemoverSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("removeBackground", &HybridImageBackgroundRemoverSpec::removeBackground);
18
+ });
19
+ }
20
+
21
+ } // namespace margelo::nitro::rnremoveimagebg
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `NativeRemoveBackgroundOptions` to properly resolve imports.
17
+ namespace margelo::nitro::rnremoveimagebg { struct NativeRemoveBackgroundOptions; }
18
+
19
+ #include <string>
20
+ #include <NitroModules/Promise.hpp>
21
+ #include "NativeRemoveBackgroundOptions.hpp"
22
+
23
+ namespace margelo::nitro::rnremoveimagebg {
24
+
25
+ using namespace margelo::nitro;
26
+
27
+ /**
28
+ * An abstract base class for `ImageBackgroundRemover`
29
+ * Inherit this class to create instances of `HybridImageBackgroundRemoverSpec` in C++.
30
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
31
+ * @example
32
+ * ```cpp
33
+ * class HybridImageBackgroundRemover: public HybridImageBackgroundRemoverSpec {
34
+ * public:
35
+ * HybridImageBackgroundRemover(...): HybridObject(TAG) { ... }
36
+ * // ...
37
+ * };
38
+ * ```
39
+ */
40
+ class HybridImageBackgroundRemoverSpec: public virtual HybridObject {
41
+ public:
42
+ // Constructor
43
+ explicit HybridImageBackgroundRemoverSpec(): HybridObject(TAG) { }
44
+
45
+ // Destructor
46
+ ~HybridImageBackgroundRemoverSpec() override = default;
47
+
48
+ public:
49
+ // Properties
50
+
51
+
52
+ public:
53
+ // Methods
54
+ virtual std::shared_ptr<Promise<std::string>> removeBackground(const std::string& imagePath, const NativeRemoveBackgroundOptions& options) = 0;
55
+
56
+ protected:
57
+ // Hybrid Setup
58
+ void loadHybridMethods() override;
59
+
60
+ protected:
61
+ // Tag for logging
62
+ static constexpr auto TAG = "ImageBackgroundRemover";
63
+ };
64
+
65
+ } // namespace margelo::nitro::rnremoveimagebg
@@ -0,0 +1,84 @@
1
+ ///
2
+ /// NativeRemoveBackgroundOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ // Forward declaration of `OutputFormat` to properly resolve imports.
27
+ namespace margelo::nitro::rnremoveimagebg { enum class OutputFormat; }
28
+
29
+ #include "OutputFormat.hpp"
30
+
31
+ namespace margelo::nitro::rnremoveimagebg {
32
+
33
+ /**
34
+ * A struct which can be represented as a JavaScript object (NativeRemoveBackgroundOptions).
35
+ */
36
+ struct NativeRemoveBackgroundOptions {
37
+ public:
38
+ double maxDimension SWIFT_PRIVATE;
39
+ OutputFormat format SWIFT_PRIVATE;
40
+ double quality SWIFT_PRIVATE;
41
+
42
+ public:
43
+ NativeRemoveBackgroundOptions() = default;
44
+ explicit NativeRemoveBackgroundOptions(double maxDimension, OutputFormat format, double quality): maxDimension(maxDimension), format(format), quality(quality) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::rnremoveimagebg
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ NativeRemoveBackgroundOptions <> JS NativeRemoveBackgroundOptions (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions> final {
54
+ static inline margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions(
57
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "maxDimension")),
58
+ JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::fromJSI(runtime, obj.getProperty(runtime, "format")),
59
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "quality"))
60
+ );
61
+ }
62
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions& arg) {
63
+ jsi::Object obj(runtime);
64
+ obj.setProperty(runtime, "maxDimension", JSIConverter<double>::toJSI(runtime, arg.maxDimension));
65
+ obj.setProperty(runtime, "format", JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::toJSI(runtime, arg.format));
66
+ obj.setProperty(runtime, "quality", JSIConverter<double>::toJSI(runtime, arg.quality));
67
+ return obj;
68
+ }
69
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
70
+ if (!value.isObject()) {
71
+ return false;
72
+ }
73
+ jsi::Object obj = value.getObject(runtime);
74
+ if (!nitro::isPlainObject(runtime, obj)) {
75
+ return false;
76
+ }
77
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "maxDimension"))) return false;
78
+ if (!JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::canConvert(runtime, obj.getProperty(runtime, "format"))) return false;
79
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "quality"))) return false;
80
+ return true;
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// OutputFormat.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::rnremoveimagebg {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (OutputFormat).
30
+ */
31
+ enum class OutputFormat {
32
+ PNG SWIFT_NAME(png) = 0,
33
+ WEBP SWIFT_NAME(webp) = 1,
34
+ } CLOSED_ENUM;
35
+
36
+ } // namespace margelo::nitro::rnremoveimagebg
37
+
38
+ namespace margelo::nitro {
39
+
40
+ // C++ OutputFormat <> JS OutputFormat (union)
41
+ template <>
42
+ struct JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat> final {
43
+ static inline margelo::nitro::rnremoveimagebg::OutputFormat fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
44
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
45
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
46
+ case hashString("PNG"): return margelo::nitro::rnremoveimagebg::OutputFormat::PNG;
47
+ case hashString("WEBP"): return margelo::nitro::rnremoveimagebg::OutputFormat::WEBP;
48
+ default: [[unlikely]]
49
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum OutputFormat - invalid value!");
50
+ }
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::rnremoveimagebg::OutputFormat arg) {
53
+ switch (arg) {
54
+ case margelo::nitro::rnremoveimagebg::OutputFormat::PNG: return JSIConverter<std::string>::toJSI(runtime, "PNG");
55
+ case margelo::nitro::rnremoveimagebg::OutputFormat::WEBP: return JSIConverter<std::string>::toJSI(runtime, "WEBP");
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert OutputFormat to JS - invalid value: "
58
+ + std::to_string(static_cast<int>(arg)) + "!");
59
+ }
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isString()) {
63
+ return false;
64
+ }
65
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
66
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
67
+ case hashString("PNG"):
68
+ case hashString("WEBP"):
69
+ return true;
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ };
75
+
76
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "rn-remove-image-bg",
3
+ "version": "0.0.10",
4
+ "description": "rn-remove-image-bg",
5
+ "homepage": "https://github.com/a-eid/rn-remove-image-bg",
6
+ "main": "lib/index",
7
+ "module": "lib/index",
8
+ "types": "lib/index.d.ts",
9
+ "react-native": "src/index",
10
+ "source": "src/index",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "import": "./lib/index.js",
15
+ "require": "./lib/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "src",
20
+ "react-native.config.js",
21
+ "lib",
22
+ "nitrogen",
23
+ "android/build.gradle",
24
+ "android/gradle.properties",
25
+ "android/fix-prefab.gradle",
26
+ "android/CMakeLists.txt",
27
+ "android/src",
28
+ "ios/**/*.h",
29
+ "ios/**/*.m",
30
+ "ios/**/*.mm",
31
+ "ios/**/*.cpp",
32
+ "ios/**/*.swift",
33
+ "app.plugin.js",
34
+ "nitro.json",
35
+ "*.podspec",
36
+ "README.md"
37
+ ],
38
+ "scripts": {
39
+ "postinstall": "tsc || exit 0;",
40
+ "typecheck": "tsc --noEmit",
41
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
43
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
44
+ "typescript": "tsc",
45
+ "specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\"",
46
+ "prepare": "npm run typescript",
47
+ "test": "vitest run"
48
+ },
49
+ "author": "Ahmed Eid <a.eid@yandex.com> (https://github.com/a-eid)",
50
+ "license": "MIT",
51
+ "devDependencies": {
52
+ "@react-native/eslint-config": "0.82.0",
53
+ "@biomejs/biome": "^2.3.11",
54
+ "@types/react": "^19.1.03",
55
+ "eslint": "^8.57.0",
56
+ "eslint-config-prettier": "^9.1.0",
57
+ "eslint-plugin-prettier": "^5.2.1",
58
+ "nitrogen": "*",
59
+ "react": "19.1.1",
60
+ "react-native": "0.82.0",
61
+ "react-native-nitro-modules": "0.31.10",
62
+ "typescript": "^5.8.3",
63
+ "vitest": "^3.0.0"
64
+ },
65
+ "peerDependencies": {
66
+ "react": "*",
67
+ "react-native": "*",
68
+ "react-native-nitro-modules": "0.31.10",
69
+ "expo-file-system": "*",
70
+ "expo-image-manipulator": "*"
71
+ },
72
+ "eslintConfig": {
73
+ "root": true,
74
+ "extends": [
75
+ "@react-native",
76
+ "prettier"
77
+ ],
78
+ "plugins": [
79
+ "prettier"
80
+ ],
81
+ "rules": {
82
+ "prettier/prettier": [
83
+ "warn",
84
+ {
85
+ "quoteProps": "consistent",
86
+ "singleQuote": true,
87
+ "tabWidth": 2,
88
+ "trailingComma": "es5",
89
+ "useTabs": false
90
+ }
91
+ ]
92
+ }
93
+ },
94
+ "eslintIgnore": [
95
+ "node_modules/",
96
+ "lib/"
97
+ ],
98
+ "dependencies": {
99
+ "@imgly/background-removal": "^1.7.0",
100
+ "buffer": "^6.0.3",
101
+ "thumbhash": "^0.1.1",
102
+ "upng-js": "^2.1.0"
103
+ }
104
+ }
@@ -0,0 +1,16 @@
1
+ // https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
2
+
3
+ module.exports = {
4
+ dependency: {
5
+ platforms: {
6
+ /**
7
+ * @type {import('@react-native-community/cli-types').IOSDependencyParams}
8
+ */
9
+ ios: {},
10
+ /**
11
+ * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
+ */
13
+ android: {},
14
+ },
15
+ },
16
+ };