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,49 @@
1
+ ///
2
+ /// NitroRnRemoveImageBg-Swift-Cxx-Bridge.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 "NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridImageBackgroundRemoverSpecSwift.hpp"
12
+ #include "NitroRnRemoveImageBg-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
14
+
15
+ namespace margelo::nitro::rnremoveimagebg::bridge::swift {
16
+
17
+ // pragma MARK: std::function<void(const std::string& /* result */)>
18
+ Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
19
+ auto swiftClosure = NitroRnRemoveImageBg::Func_void_std__string::fromUnsafe(swiftClosureWrapper);
20
+ return [swiftClosure = std::move(swiftClosure)](const std::string& result) mutable -> void {
21
+ swiftClosure.call(result);
22
+ };
23
+ }
24
+
25
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
26
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
27
+ auto swiftClosure = NitroRnRemoveImageBg::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
28
+ return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
29
+ swiftClosure.call(error);
30
+ };
31
+ }
32
+
33
+ // pragma MARK: std::shared_ptr<HybridImageBackgroundRemoverSpec>
34
+ std::shared_ptr<HybridImageBackgroundRemoverSpec> create_std__shared_ptr_HybridImageBackgroundRemoverSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
35
+ NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx swiftPart = NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx::fromUnsafe(swiftUnsafePointer);
36
+ return std::make_shared<margelo::nitro::rnremoveimagebg::HybridImageBackgroundRemoverSpecSwift>(swiftPart);
37
+ }
38
+ void* NON_NULL get_std__shared_ptr_HybridImageBackgroundRemoverSpec_(std__shared_ptr_HybridImageBackgroundRemoverSpec_ cppType) {
39
+ std::shared_ptr<margelo::nitro::rnremoveimagebg::HybridImageBackgroundRemoverSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::rnremoveimagebg::HybridImageBackgroundRemoverSpecSwift>(cppType);
40
+ #ifdef NITRO_DEBUG
41
+ if (swiftWrapper == nullptr) [[unlikely]] {
42
+ throw std::runtime_error("Class \"HybridImageBackgroundRemoverSpec\" is not implemented in Swift!");
43
+ }
44
+ #endif
45
+ NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
46
+ return swiftPart.toUnsafe();
47
+ }
48
+
49
+ } // namespace margelo::nitro::rnremoveimagebg::bridge::swift
@@ -0,0 +1,111 @@
1
+ ///
2
+ /// NitroRnRemoveImageBg-Swift-Cxx-Bridge.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridImageBackgroundRemoverSpec` to properly resolve imports.
12
+ namespace margelo::nitro::rnremoveimagebg { class HybridImageBackgroundRemoverSpec; }
13
+
14
+ // Forward declarations of Swift defined types
15
+ // Forward declaration of `HybridImageBackgroundRemoverSpec_cxx` to properly resolve imports.
16
+ namespace NitroRnRemoveImageBg { class HybridImageBackgroundRemoverSpec_cxx; }
17
+
18
+ // Include C++ defined types
19
+ #include "HybridImageBackgroundRemoverSpec.hpp"
20
+ #include <NitroModules/Promise.hpp>
21
+ #include <NitroModules/PromiseHolder.hpp>
22
+ #include <NitroModules/Result.hpp>
23
+ #include <exception>
24
+ #include <functional>
25
+ #include <memory>
26
+ #include <string>
27
+
28
+ /**
29
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
30
+ * as well as helper functions to interact with those C++ types from Swift.
31
+ */
32
+ namespace margelo::nitro::rnremoveimagebg::bridge::swift {
33
+
34
+ // pragma MARK: std::shared_ptr<Promise<std::string>>
35
+ /**
36
+ * Specialized version of `std::shared_ptr<Promise<std::string>>`.
37
+ */
38
+ using std__shared_ptr_Promise_std__string__ = std::shared_ptr<Promise<std::string>>;
39
+ inline std::shared_ptr<Promise<std::string>> create_std__shared_ptr_Promise_std__string__() noexcept {
40
+ return Promise<std::string>::create();
41
+ }
42
+ inline PromiseHolder<std::string> wrap_std__shared_ptr_Promise_std__string__(std::shared_ptr<Promise<std::string>> promise) noexcept {
43
+ return PromiseHolder<std::string>(std::move(promise));
44
+ }
45
+
46
+ // pragma MARK: std::function<void(const std::string& /* result */)>
47
+ /**
48
+ * Specialized version of `std::function<void(const std::string&)>`.
49
+ */
50
+ using Func_void_std__string = std::function<void(const std::string& /* result */)>;
51
+ /**
52
+ * Wrapper class for a `std::function<void(const std::string& / * result * /)>`, this can be used from Swift.
53
+ */
54
+ class Func_void_std__string_Wrapper final {
55
+ public:
56
+ explicit Func_void_std__string_Wrapper(std::function<void(const std::string& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::string& /* result */)>>(std::move(func))) {}
57
+ inline void call(std::string result) const noexcept {
58
+ _function->operator()(result);
59
+ }
60
+ private:
61
+ std::unique_ptr<std::function<void(const std::string& /* result */)>> _function;
62
+ } SWIFT_NONCOPYABLE;
63
+ Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
64
+ inline Func_void_std__string_Wrapper wrap_Func_void_std__string(Func_void_std__string value) noexcept {
65
+ return Func_void_std__string_Wrapper(std::move(value));
66
+ }
67
+
68
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
69
+ /**
70
+ * Specialized version of `std::function<void(const std::exception_ptr&)>`.
71
+ */
72
+ using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
73
+ /**
74
+ * Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
75
+ */
76
+ class Func_void_std__exception_ptr_Wrapper final {
77
+ public:
78
+ explicit Func_void_std__exception_ptr_Wrapper(std::function<void(const std::exception_ptr& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::exception_ptr& /* error */)>>(std::move(func))) {}
79
+ inline void call(std::exception_ptr error) const noexcept {
80
+ _function->operator()(error);
81
+ }
82
+ private:
83
+ std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
84
+ } SWIFT_NONCOPYABLE;
85
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
86
+ inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
87
+ return Func_void_std__exception_ptr_Wrapper(std::move(value));
88
+ }
89
+
90
+ // pragma MARK: std::shared_ptr<HybridImageBackgroundRemoverSpec>
91
+ /**
92
+ * Specialized version of `std::shared_ptr<HybridImageBackgroundRemoverSpec>`.
93
+ */
94
+ using std__shared_ptr_HybridImageBackgroundRemoverSpec_ = std::shared_ptr<HybridImageBackgroundRemoverSpec>;
95
+ std::shared_ptr<HybridImageBackgroundRemoverSpec> create_std__shared_ptr_HybridImageBackgroundRemoverSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
96
+ void* NON_NULL get_std__shared_ptr_HybridImageBackgroundRemoverSpec_(std__shared_ptr_HybridImageBackgroundRemoverSpec_ cppType);
97
+
98
+ // pragma MARK: std::weak_ptr<HybridImageBackgroundRemoverSpec>
99
+ using std__weak_ptr_HybridImageBackgroundRemoverSpec_ = std::weak_ptr<HybridImageBackgroundRemoverSpec>;
100
+ inline std__weak_ptr_HybridImageBackgroundRemoverSpec_ weakify_std__shared_ptr_HybridImageBackgroundRemoverSpec_(const std::shared_ptr<HybridImageBackgroundRemoverSpec>& strong) noexcept { return strong; }
101
+
102
+ // pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
103
+ using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
104
+ inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
105
+ return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
106
+ }
107
+ inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
108
+ return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
109
+ }
110
+
111
+ } // namespace margelo::nitro::rnremoveimagebg::bridge::swift
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// NitroRnRemoveImageBg-Swift-Cxx-Umbrella.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridImageBackgroundRemoverSpec` to properly resolve imports.
12
+ namespace margelo::nitro::rnremoveimagebg { class HybridImageBackgroundRemoverSpec; }
13
+ // Forward declaration of `NativeRemoveBackgroundOptions` to properly resolve imports.
14
+ namespace margelo::nitro::rnremoveimagebg { struct NativeRemoveBackgroundOptions; }
15
+ // Forward declaration of `OutputFormat` to properly resolve imports.
16
+ namespace margelo::nitro::rnremoveimagebg { enum class OutputFormat; }
17
+
18
+ // Include C++ defined types
19
+ #include "HybridImageBackgroundRemoverSpec.hpp"
20
+ #include "NativeRemoveBackgroundOptions.hpp"
21
+ #include "OutputFormat.hpp"
22
+ #include <NitroModules/Promise.hpp>
23
+ #include <NitroModules/Result.hpp>
24
+ #include <exception>
25
+ #include <memory>
26
+ #include <string>
27
+
28
+ // C++ helpers for Swift
29
+ #include "NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp"
30
+
31
+ // Common C++ types used in Swift
32
+ #include <NitroModules/ArrayBufferHolder.hpp>
33
+ #include <NitroModules/AnyMapUtils.hpp>
34
+ #include <NitroModules/RuntimeError.hpp>
35
+ #include <NitroModules/DateToChronoDate.hpp>
36
+
37
+ // Forward declarations of Swift defined types
38
+ // Forward declaration of `HybridImageBackgroundRemoverSpec_cxx` to properly resolve imports.
39
+ namespace NitroRnRemoveImageBg { class HybridImageBackgroundRemoverSpec_cxx; }
40
+
41
+ // Include Swift defined types
42
+ #if __has_include("NitroRnRemoveImageBg-Swift.h")
43
+ // This header is generated by Xcode/Swift on every app build.
44
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroRnRemoveImageBg".
45
+ #include "NitroRnRemoveImageBg-Swift.h"
46
+ // Same as above, but used when building with frameworks (`use_frameworks`)
47
+ #elif __has_include(<NitroRnRemoveImageBg/NitroRnRemoveImageBg-Swift.h>)
48
+ #include <NitroRnRemoveImageBg/NitroRnRemoveImageBg-Swift.h>
49
+ #else
50
+ #error NitroRnRemoveImageBg's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroRnRemoveImageBg", and try building the app first.
51
+ #endif
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpecSwift.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 "HybridImageBackgroundRemoverSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::rnremoveimagebg {
11
+ } // namespace margelo::nitro::rnremoveimagebg
@@ -0,0 +1,82 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpecSwift.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
+ #include "HybridImageBackgroundRemoverSpec.hpp"
11
+
12
+ // Forward declaration of `HybridImageBackgroundRemoverSpec_cxx` to properly resolve imports.
13
+ namespace NitroRnRemoveImageBg { class HybridImageBackgroundRemoverSpec_cxx; }
14
+
15
+ // Forward declaration of `NativeRemoveBackgroundOptions` to properly resolve imports.
16
+ namespace margelo::nitro::rnremoveimagebg { struct NativeRemoveBackgroundOptions; }
17
+ // Forward declaration of `OutputFormat` to properly resolve imports.
18
+ namespace margelo::nitro::rnremoveimagebg { enum class OutputFormat; }
19
+
20
+ #include <string>
21
+ #include <NitroModules/Promise.hpp>
22
+ #include "NativeRemoveBackgroundOptions.hpp"
23
+ #include "OutputFormat.hpp"
24
+
25
+ #include "NitroRnRemoveImageBg-Swift-Cxx-Umbrella.hpp"
26
+
27
+ namespace margelo::nitro::rnremoveimagebg {
28
+
29
+ /**
30
+ * The C++ part of HybridImageBackgroundRemoverSpec_cxx.swift.
31
+ *
32
+ * HybridImageBackgroundRemoverSpecSwift (C++) accesses HybridImageBackgroundRemoverSpec_cxx (Swift), and might
33
+ * contain some additional bridging code for C++ <> Swift interop.
34
+ *
35
+ * Since this obviously introduces an overhead, I hope at some point in
36
+ * the future, HybridImageBackgroundRemoverSpec_cxx can directly inherit from the C++ class HybridImageBackgroundRemoverSpec
37
+ * to simplify the whole structure and memory management.
38
+ */
39
+ class HybridImageBackgroundRemoverSpecSwift: public virtual HybridImageBackgroundRemoverSpec {
40
+ public:
41
+ // Constructor from a Swift instance
42
+ explicit HybridImageBackgroundRemoverSpecSwift(const NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx& swiftPart):
43
+ HybridObject(HybridImageBackgroundRemoverSpec::TAG),
44
+ _swiftPart(swiftPart) { }
45
+
46
+ public:
47
+ // Get the Swift part
48
+ inline NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx& getSwiftPart() noexcept {
49
+ return _swiftPart;
50
+ }
51
+
52
+ public:
53
+ inline size_t getExternalMemorySize() noexcept override {
54
+ return _swiftPart.getMemorySize();
55
+ }
56
+ void dispose() noexcept override {
57
+ _swiftPart.dispose();
58
+ }
59
+ std::string toString() override {
60
+ return _swiftPart.toString();
61
+ }
62
+
63
+ public:
64
+ // Properties
65
+
66
+
67
+ public:
68
+ // Methods
69
+ inline std::shared_ptr<Promise<std::string>> removeBackground(const std::string& imagePath, const NativeRemoveBackgroundOptions& options) override {
70
+ auto __result = _swiftPart.removeBackground(imagePath, std::forward<decltype(options)>(options));
71
+ if (__result.hasError()) [[unlikely]] {
72
+ std::rethrow_exception(__result.error());
73
+ }
74
+ auto __value = std::move(__result.value());
75
+ return __value;
76
+ }
77
+
78
+ private:
79
+ NitroRnRemoveImageBg::HybridImageBackgroundRemoverSpec_cxx _swiftPart;
80
+ };
81
+
82
+ } // namespace margelo::nitro::rnremoveimagebg
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__exception_ptr.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
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ error: Error) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__exception_ptr {
16
+ public typealias bridge = margelo.nitro.rnremoveimagebg.bridge.swift
17
+
18
+ private let closure: (_ error: Error) -> Void
19
+
20
+ public init(_ closure: @escaping (_ error: Error) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(error: std.exception_ptr) -> Void {
26
+ self.closure(RuntimeError.from(cppError: error))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
45
+ return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__string.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
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ value: String) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__string {
16
+ public typealias bridge = margelo.nitro.rnremoveimagebg.bridge.swift
17
+
18
+ private let closure: (_ value: String) -> Void
19
+
20
+ public init(_ closure: @escaping (_ value: String) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(value: std.string) -> Void {
26
+ self.closure(String(value))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__string`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__string>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string {
45
+ return Unmanaged<Func_void_std__string>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpec.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
+ import Foundation
9
+ import NitroModules
10
+
11
+ /// See ``HybridImageBackgroundRemoverSpec``
12
+ public protocol HybridImageBackgroundRemoverSpec_protocol: HybridObject {
13
+ // Properties
14
+
15
+
16
+ // Methods
17
+ func removeBackground(imagePath: String, options: NativeRemoveBackgroundOptions) throws -> Promise<String>
18
+ }
19
+
20
+ public extension HybridImageBackgroundRemoverSpec_protocol {
21
+ /// Default implementation of ``HybridObject.toString``
22
+ func toString() -> String {
23
+ return "[HybridObject ImageBackgroundRemover]"
24
+ }
25
+ }
26
+
27
+ /// See ``HybridImageBackgroundRemoverSpec``
28
+ open class HybridImageBackgroundRemoverSpec_base {
29
+ private weak var cxxWrapper: HybridImageBackgroundRemoverSpec_cxx? = nil
30
+ public init() { }
31
+ public func getCxxWrapper() -> HybridImageBackgroundRemoverSpec_cxx {
32
+ #if DEBUG
33
+ guard self is HybridImageBackgroundRemoverSpec else {
34
+ fatalError("`self` is not a `HybridImageBackgroundRemoverSpec`! Did you accidentally inherit from `HybridImageBackgroundRemoverSpec_base` instead of `HybridImageBackgroundRemoverSpec`?")
35
+ }
36
+ #endif
37
+ if let cxxWrapper = self.cxxWrapper {
38
+ return cxxWrapper
39
+ } else {
40
+ let cxxWrapper = HybridImageBackgroundRemoverSpec_cxx(self as! HybridImageBackgroundRemoverSpec)
41
+ self.cxxWrapper = cxxWrapper
42
+ return cxxWrapper
43
+ }
44
+ }
45
+ }
46
+
47
+ /**
48
+ * A Swift base-protocol representing the ImageBackgroundRemover HybridObject.
49
+ * Implement this protocol to create Swift-based instances of ImageBackgroundRemover.
50
+ * ```swift
51
+ * class HybridImageBackgroundRemover : HybridImageBackgroundRemoverSpec {
52
+ * // ...
53
+ * }
54
+ * ```
55
+ */
56
+ public typealias HybridImageBackgroundRemoverSpec = HybridImageBackgroundRemoverSpec_protocol & HybridImageBackgroundRemoverSpec_base
@@ -0,0 +1,138 @@
1
+ ///
2
+ /// HybridImageBackgroundRemoverSpec_cxx.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
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridImageBackgroundRemoverSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridImageBackgroundRemoverSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::rnremoveimagebg::bridge::swift`)
23
+ * from `NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.rnremoveimagebg.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridImageBackgroundRemoverSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridImageBackgroundRemoverSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridImageBackgroundRemoverSpec_
37
+
38
+ /**
39
+ * Create a new `HybridImageBackgroundRemoverSpec_cxx` that wraps the given `HybridImageBackgroundRemoverSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridImageBackgroundRemoverSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridImageBackgroundRemoverSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridImageBackgroundRemoverSpec() -> any HybridImageBackgroundRemoverSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridImageBackgroundRemoverSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridImageBackgroundRemoverSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridImageBackgroundRemoverSpec_cxx {
70
+ return Unmanaged<HybridImageBackgroundRemoverSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridImageBackgroundRemoverSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridImageBackgroundRemoverSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridImageBackgroundRemoverSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridImageBackgroundRemoverSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+
118
+
119
+ // Methods
120
+ @inline(__always)
121
+ public final func removeBackground(imagePath: std.string, options: NativeRemoveBackgroundOptions) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
122
+ do {
123
+ let __result = try self.__implementation.removeBackground(imagePath: String(imagePath), options: options)
124
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
125
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
126
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
127
+ __result
128
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
129
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
130
+ return __promise
131
+ }()
132
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
133
+ } catch (let __error) {
134
+ let __exceptionPtr = __error.toCpp()
135
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// NativeRemoveBackgroundOptions.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
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Represents an instance of `NativeRemoveBackgroundOptions`, backed by a C++ struct.
13
+ */
14
+ public typealias NativeRemoveBackgroundOptions = margelo.nitro.rnremoveimagebg.NativeRemoveBackgroundOptions
15
+
16
+ public extension NativeRemoveBackgroundOptions {
17
+ private typealias bridge = margelo.nitro.rnremoveimagebg.bridge.swift
18
+
19
+ /**
20
+ * Create a new instance of `NativeRemoveBackgroundOptions`.
21
+ */
22
+ init(maxDimension: Double, format: OutputFormat, quality: Double) {
23
+ self.init(maxDimension, format, quality)
24
+ }
25
+
26
+ var maxDimension: Double {
27
+ @inline(__always)
28
+ get {
29
+ return self.__maxDimension
30
+ }
31
+ @inline(__always)
32
+ set {
33
+ self.__maxDimension = newValue
34
+ }
35
+ }
36
+
37
+ var format: OutputFormat {
38
+ @inline(__always)
39
+ get {
40
+ return self.__format
41
+ }
42
+ @inline(__always)
43
+ set {
44
+ self.__format = newValue
45
+ }
46
+ }
47
+
48
+ var quality: Double {
49
+ @inline(__always)
50
+ get {
51
+ return self.__quality
52
+ }
53
+ @inline(__always)
54
+ set {
55
+ self.__quality = newValue
56
+ }
57
+ }
58
+ }