rn-remove-image-bg 0.0.30 → 0.0.32
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.
- package/nitrogen/generated/android/NitroRnRemoveImageBg+autolinking.cmake +1 -1
- package/nitrogen/generated/android/NitroRnRemoveImageBg+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroRnRemoveImageBgOnLoad.cpp +27 -17
- package/nitrogen/generated/android/NitroRnRemoveImageBgOnLoad.hpp +14 -5
- package/nitrogen/generated/android/c++/JHybridImageBackgroundRemoverSpec.cpp +21 -20
- package/nitrogen/generated/android/c++/JHybridImageBackgroundRemoverSpec.hpp +20 -22
- package/nitrogen/generated/android/c++/JNativeRemoveBackgroundOptions.hpp +1 -1
- package/nitrogen/generated/android/c++/JOutputFormat.hpp +3 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemoverSpec.kt +15 -18
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/NativeRemoveBackgroundOptions.kt +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/NitroRnRemoveImageBgOnLoad.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnremoveimagebg/OutputFormat.kt +3 -1
- package/nitrogen/generated/ios/NitroRnRemoveImageBg+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/NitroRnRemoveImageBg-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridImageBackgroundRemoverSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridImageBackgroundRemoverSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -2
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -2
- package/nitrogen/generated/ios/swift/HybridImageBackgroundRemoverSpec.swift +3 -4
- package/nitrogen/generated/ios/swift/HybridImageBackgroundRemoverSpec_cxx.swift +9 -2
- package/nitrogen/generated/ios/swift/NativeRemoveBackgroundOptions.swift +7 -26
- package/nitrogen/generated/ios/swift/OutputFormat.swift +1 -1
- package/nitrogen/generated/shared/c++/HybridImageBackgroundRemoverSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridImageBackgroundRemoverSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/NativeRemoveBackgroundOptions.hpp +19 -11
- package/nitrogen/generated/shared/c++/OutputFormat.hpp +1 -1
- package/package.json +15 -16
- package/lib/__tests__/cache.test.d.ts +0 -1
- package/lib/__tests__/cache.test.js +0 -87
- package/lib/__tests__/errors.test.d.ts +0 -1
- package/lib/__tests__/errors.test.js +0 -82
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# NitroRnRemoveImageBg+autolinking.cmake
|
|
3
3
|
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
# https://github.com/mrousavy/nitro
|
|
5
|
-
# Copyright ©
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
#
|
|
7
7
|
|
|
8
8
|
# This is a CMake file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroRnRemoveImageBg+autolinking.gradle
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroRnRemoveImageBgOnLoad.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#ifndef BUILDING_NITRORNREMOVEIMAGEBG_WITH_GENERATED_CMAKE_PROJECT
|
|
@@ -21,24 +21,34 @@
|
|
|
21
21
|
namespace margelo::nitro::rnremoveimagebg {
|
|
22
22
|
|
|
23
23
|
int initialize(JavaVM* vm) {
|
|
24
|
+
return facebook::jni::initialize(vm, []() {
|
|
25
|
+
::margelo::nitro::rnremoveimagebg::registerAllNatives();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
struct JHybridImageBackgroundRemoverSpecImpl: public jni::JavaClass<JHybridImageBackgroundRemoverSpecImpl, JHybridImageBackgroundRemoverSpec::JavaPart> {
|
|
30
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemover;";
|
|
31
|
+
static std::shared_ptr<JHybridImageBackgroundRemoverSpec> create() {
|
|
32
|
+
static auto constructorFn = javaClassStatic()->getConstructor<JHybridImageBackgroundRemoverSpecImpl::javaobject()>();
|
|
33
|
+
jni::local_ref<JHybridImageBackgroundRemoverSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
34
|
+
return javaPart->getJHybridImageBackgroundRemoverSpec();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
void registerAllNatives() {
|
|
24
39
|
using namespace margelo::nitro;
|
|
25
40
|
using namespace margelo::nitro::rnremoveimagebg;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
auto instance = object.create();
|
|
38
|
-
return instance->cthis()->shared();
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
});
|
|
41
|
+
|
|
42
|
+
// Register native JNI methods
|
|
43
|
+
margelo::nitro::rnremoveimagebg::JHybridImageBackgroundRemoverSpec::CxxPart::registerNatives();
|
|
44
|
+
|
|
45
|
+
// Register Nitro Hybrid Objects
|
|
46
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
47
|
+
"ImageBackgroundRemover",
|
|
48
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
49
|
+
return JHybridImageBackgroundRemoverSpecImpl::create();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
} // namespace margelo::nitro::rnremoveimagebg
|
|
@@ -2,24 +2,33 @@
|
|
|
2
2
|
/// NitroRnRemoveImageBgOnLoad.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
9
10
|
#include <NitroModules/NitroDefines.hpp>
|
|
10
11
|
|
|
11
12
|
namespace margelo::nitro::rnremoveimagebg {
|
|
12
13
|
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`)
|
|
18
|
+
* Register the native (C++) part of NitroRnRemoveImageBg, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
16
21
|
* Example:
|
|
17
22
|
* ```cpp (cpp-adapter.cpp)
|
|
18
23
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
-
* return
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroRnRemoveImageBg HybridObjects
|
|
26
|
+
* margelo::nitro::rnremoveimagebg::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
20
29
|
* }
|
|
21
30
|
* ```
|
|
22
31
|
*/
|
|
23
|
-
|
|
32
|
+
void registerAllNatives();
|
|
24
33
|
|
|
25
34
|
} // namespace margelo::nitro::rnremoveimagebg
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// JHybridImageBackgroundRemoverSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "JHybridImageBackgroundRemoverSpec.hpp"
|
|
@@ -22,30 +22,31 @@ namespace margelo::nitro::rnremoveimagebg { enum class OutputFormat; }
|
|
|
22
22
|
|
|
23
23
|
namespace margelo::nitro::rnremoveimagebg {
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
25
|
+
std::shared_ptr<JHybridImageBackgroundRemoverSpec> JHybridImageBackgroundRemoverSpec::JavaPart::getJHybridImageBackgroundRemoverSpec() {
|
|
26
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
27
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridImageBackgroundRemoverSpec>(hybridObject);
|
|
28
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
29
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridImageBackgroundRemoverSpec!");
|
|
30
|
+
}
|
|
31
|
+
return castHybridObject;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return method(_javaPart);
|
|
34
|
+
jni::local_ref<JHybridImageBackgroundRemoverSpec::CxxPart::jhybriddata> JHybridImageBackgroundRemoverSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
35
|
+
return makeCxxInstance(jThis);
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
std::shared_ptr<JHybridObject> JHybridImageBackgroundRemoverSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
39
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridImageBackgroundRemoverSpec::JavaPart>(javaPart);
|
|
40
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
41
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridImageBackgroundRemoverSpec::JavaPart!");
|
|
42
|
+
}
|
|
43
|
+
return std::make_shared<JHybridImageBackgroundRemoverSpec>(castJavaPart);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
void JHybridImageBackgroundRemoverSpec::CxxPart::registerNatives() {
|
|
47
|
+
registerHybrid({
|
|
48
|
+
makeNativeMethod("initHybrid", JHybridImageBackgroundRemoverSpec::CxxPart::initHybrid),
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// Properties
|
|
@@ -53,7 +54,7 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
53
54
|
|
|
54
55
|
// Methods
|
|
55
56
|
std::shared_ptr<Promise<std::string>> JHybridImageBackgroundRemoverSpec::removeBackground(const std::string& imagePath, const NativeRemoveBackgroundOptions& options) {
|
|
56
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* imagePath */, jni::alias_ref<JNativeRemoveBackgroundOptions> /* options */)>("removeBackground");
|
|
57
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* imagePath */, jni::alias_ref<JNativeRemoveBackgroundOptions> /* options */)>("removeBackground");
|
|
57
58
|
auto __result = method(_javaPart, jni::make_jstring(imagePath), JNativeRemoveBackgroundOptions::fromCpp(options));
|
|
58
59
|
return [&]() {
|
|
59
60
|
auto __promise = Promise<std::string>::create();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -18,33 +18,33 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
18
18
|
|
|
19
19
|
using namespace facebook;
|
|
20
20
|
|
|
21
|
-
class JHybridImageBackgroundRemoverSpec: public
|
|
22
|
-
public virtual HybridImageBackgroundRemoverSpec {
|
|
21
|
+
class JHybridImageBackgroundRemoverSpec: public virtual HybridImageBackgroundRemoverSpec, public virtual JHybridObject {
|
|
23
22
|
public:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
HybridBase
|
|
33
|
-
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemoverSpec;";
|
|
25
|
+
std::shared_ptr<JHybridImageBackgroundRemoverSpec> getJHybridImageBackgroundRemoverSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/rnremoveimagebg/HybridImageBackgroundRemoverSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
34
35
|
|
|
35
36
|
public:
|
|
37
|
+
explicit JHybridImageBackgroundRemoverSpec(const jni::local_ref<JHybridImageBackgroundRemoverSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridImageBackgroundRemoverSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
36
41
|
~JHybridImageBackgroundRemoverSpec() override {
|
|
37
42
|
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
43
|
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
public:
|
|
42
|
-
|
|
43
|
-
void dispose() noexcept override;
|
|
44
|
-
std::string toString() override;
|
|
45
|
-
|
|
46
|
-
public:
|
|
47
|
-
inline const jni::global_ref<JHybridImageBackgroundRemoverSpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
inline const jni::global_ref<JHybridImageBackgroundRemoverSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
48
|
return _javaPart;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -57,9 +57,7 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
57
57
|
std::shared_ptr<Promise<std::string>> removeBackground(const std::string& imagePath, const NativeRemoveBackgroundOptions& options) override;
|
|
58
58
|
|
|
59
59
|
private:
|
|
60
|
-
|
|
61
|
-
using HybridBase::HybridBase;
|
|
62
|
-
jni::global_ref<JHybridImageBackgroundRemoverSpec::javaobject> _javaPart;
|
|
60
|
+
jni::global_ref<JHybridImageBackgroundRemoverSpec::JavaPart> _javaPart;
|
|
63
61
|
};
|
|
64
62
|
|
|
65
63
|
} // namespace margelo::nitro::rnremoveimagebg
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// JOutputFormat.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -41,13 +41,12 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
41
41
|
[[maybe_unused]]
|
|
42
42
|
static jni::alias_ref<JOutputFormat> fromCpp(OutputFormat value) {
|
|
43
43
|
static const auto clazz = javaClassStatic();
|
|
44
|
-
static const auto fieldPNG = clazz->getStaticField<JOutputFormat>("PNG");
|
|
45
|
-
static const auto fieldWEBP = clazz->getStaticField<JOutputFormat>("WEBP");
|
|
46
|
-
|
|
47
44
|
switch (value) {
|
|
48
45
|
case OutputFormat::PNG:
|
|
46
|
+
static const auto fieldPNG = clazz->getStaticField<JOutputFormat>("PNG");
|
|
49
47
|
return clazz->getStaticFieldValue(fieldPNG);
|
|
50
48
|
case OutputFormat::WEBP:
|
|
49
|
+
static const auto fieldWEBP = clazz->getStaticField<JOutputFormat>("WEBP");
|
|
51
50
|
return clazz->getStaticFieldValue(fieldWEBP);
|
|
52
51
|
default:
|
|
53
52
|
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpec.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
package com.margelo.nitro.rnremoveimagebg
|
|
@@ -25,32 +25,29 @@ import com.margelo.nitro.core.HybridObject
|
|
|
25
25
|
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
26
|
)
|
|
27
27
|
abstract class HybridImageBackgroundRemoverSpec: HybridObject() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
init {
|
|
32
|
-
super.updateNative(mHybridData)
|
|
33
|
-
}
|
|
28
|
+
// Properties
|
|
29
|
+
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// Methods
|
|
32
|
+
@DoNotStrip
|
|
33
|
+
@Keep
|
|
34
|
+
abstract fun removeBackground(imagePath: String, options: NativeRemoveBackgroundOptions): Promise<String>
|
|
39
35
|
|
|
40
36
|
// Default implementation of `HybridObject.toString()`
|
|
41
37
|
override fun toString(): String {
|
|
42
38
|
return "[HybridObject ImageBackgroundRemover]"
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Methods
|
|
41
|
+
// C++ backing class
|
|
49
42
|
@DoNotStrip
|
|
50
43
|
@Keep
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
protected open class CxxPart(javaPart: HybridImageBackgroundRemoverSpec): HybridObject.CxxPart(javaPart) {
|
|
45
|
+
// C++ JHybridImageBackgroundRemoverSpec::CxxPart::initHybrid(...)
|
|
46
|
+
external override fun initHybrid(): HybridData
|
|
47
|
+
}
|
|
48
|
+
override fun createCxxPart(): CxxPart {
|
|
49
|
+
return CxxPart(this)
|
|
50
|
+
}
|
|
54
51
|
|
|
55
52
|
companion object {
|
|
56
53
|
protected const val TAG = "HybridImageBackgroundRemoverSpec"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NativeRemoveBackgroundOptions.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
package com.margelo.nitro.rnremoveimagebg
|
|
@@ -29,7 +29,7 @@ data class NativeRemoveBackgroundOptions(
|
|
|
29
29
|
) {
|
|
30
30
|
/* primary constructor */
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
companion object {
|
|
33
33
|
/**
|
|
34
34
|
* Constructor called from C++
|
|
35
35
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroRnRemoveImageBgOnLoad.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
package com.margelo.nitro.rnremoveimagebg
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// OutputFormat.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
package com.margelo.nitro.rnremoveimagebg
|
|
@@ -18,4 +18,6 @@ import com.facebook.proguard.annotations.DoNotStrip
|
|
|
18
18
|
enum class OutputFormat(@DoNotStrip @Keep val value: Int) {
|
|
19
19
|
PNG(0),
|
|
20
20
|
WEBP(1);
|
|
21
|
+
|
|
22
|
+
companion object
|
|
21
23
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# NitroRnRemoveImageBg+autolinking.rb
|
|
3
3
|
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
# https://github.com/mrousavy/nitro
|
|
5
|
-
# Copyright ©
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
#
|
|
7
7
|
|
|
8
8
|
# This is a Ruby script that adds all files generated by Nitrogen
|
|
@@ -52,7 +52,7 @@ def add_nitrogen_files(spec)
|
|
|
52
52
|
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
53
|
# Use C++ 20
|
|
54
54
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
-
# Enables C++ <-> Swift interop (by default it's only
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only ObjC)
|
|
56
56
|
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
57
|
# Enables stricter modular headers
|
|
58
58
|
"DEFINES_MODULE" => "YES",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroRnRemoveImageBg-Swift-Cxx-Bridge.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "NitroRnRemoveImageBg-Swift-Cxx-Bridge.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpecSwift.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridImageBackgroundRemoverSpecSwift.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpecSwift.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -53,6 +53,12 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
53
53
|
inline size_t getExternalMemorySize() noexcept override {
|
|
54
54
|
return _swiftPart.getMemorySize();
|
|
55
55
|
}
|
|
56
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
57
|
+
if (auto otherCast = std::dynamic_pointer_cast<HybridImageBackgroundRemoverSpecSwift>(other)) {
|
|
58
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
56
62
|
void dispose() noexcept override {
|
|
57
63
|
_swiftPart.dispose();
|
|
58
64
|
}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// Func_void_std__exception_ptr.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// Func_void_std__string.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpec.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/// See ``HybridImageBackgroundRemoverSpec``
|
|
@@ -30,14 +29,14 @@ open class HybridImageBackgroundRemoverSpec_base {
|
|
|
30
29
|
public init() { }
|
|
31
30
|
public func getCxxWrapper() -> HybridImageBackgroundRemoverSpec_cxx {
|
|
32
31
|
#if DEBUG
|
|
33
|
-
guard self is HybridImageBackgroundRemoverSpec else {
|
|
32
|
+
guard self is any HybridImageBackgroundRemoverSpec else {
|
|
34
33
|
fatalError("`self` is not a `HybridImageBackgroundRemoverSpec`! Did you accidentally inherit from `HybridImageBackgroundRemoverSpec_base` instead of `HybridImageBackgroundRemoverSpec`?")
|
|
35
34
|
}
|
|
36
35
|
#endif
|
|
37
36
|
if let cxxWrapper = self.cxxWrapper {
|
|
38
37
|
return cxxWrapper
|
|
39
38
|
} else {
|
|
40
|
-
let cxxWrapper = HybridImageBackgroundRemoverSpec_cxx(self as! HybridImageBackgroundRemoverSpec)
|
|
39
|
+
let cxxWrapper = HybridImageBackgroundRemoverSpec_cxx(self as! any HybridImageBackgroundRemoverSpec)
|
|
41
40
|
self.cxxWrapper = cxxWrapper
|
|
42
41
|
return cxxWrapper
|
|
43
42
|
}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpec_cxx.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -96,6 +95,14 @@ open class HybridImageBackgroundRemoverSpec_cxx {
|
|
|
96
95
|
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
96
|
}
|
|
98
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Compares this object with the given [other] object for reference equality.
|
|
100
|
+
*/
|
|
101
|
+
@inline(__always)
|
|
102
|
+
public func equals(other: HybridImageBackgroundRemoverSpec_cxx) -> Bool {
|
|
103
|
+
return self.__implementation === other.__implementation
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
/**
|
|
100
107
|
* Call dispose() on the Swift class.
|
|
101
108
|
* This _may_ be called manually from JS.
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// NativeRemoveBackgroundOptions.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -23,36 +22,18 @@ public extension NativeRemoveBackgroundOptions {
|
|
|
23
22
|
self.init(maxDimension, format, quality)
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
@inline(__always)
|
|
26
26
|
var maxDimension: Double {
|
|
27
|
-
|
|
28
|
-
get {
|
|
29
|
-
return self.__maxDimension
|
|
30
|
-
}
|
|
31
|
-
@inline(__always)
|
|
32
|
-
set {
|
|
33
|
-
self.__maxDimension = newValue
|
|
34
|
-
}
|
|
27
|
+
return self.__maxDimension
|
|
35
28
|
}
|
|
36
29
|
|
|
30
|
+
@inline(__always)
|
|
37
31
|
var format: OutputFormat {
|
|
38
|
-
|
|
39
|
-
get {
|
|
40
|
-
return self.__format
|
|
41
|
-
}
|
|
42
|
-
@inline(__always)
|
|
43
|
-
set {
|
|
44
|
-
self.__format = newValue
|
|
45
|
-
}
|
|
32
|
+
return self.__format
|
|
46
33
|
}
|
|
47
34
|
|
|
35
|
+
@inline(__always)
|
|
48
36
|
var quality: Double {
|
|
49
|
-
|
|
50
|
-
get {
|
|
51
|
-
return self.__quality
|
|
52
|
-
}
|
|
53
|
-
@inline(__always)
|
|
54
|
-
set {
|
|
55
|
-
self.__quality = newValue
|
|
56
|
-
}
|
|
37
|
+
return self.__quality
|
|
57
38
|
}
|
|
58
39
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridImageBackgroundRemoverSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridImageBackgroundRemoverSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NativeRemoveBackgroundOptions.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
#else
|
|
23
23
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
24
|
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
25
30
|
|
|
26
31
|
// Forward declaration of `OutputFormat` to properly resolve imports.
|
|
27
32
|
namespace margelo::nitro::rnremoveimagebg { enum class OutputFormat; }
|
|
@@ -33,7 +38,7 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
33
38
|
/**
|
|
34
39
|
* A struct which can be represented as a JavaScript object (NativeRemoveBackgroundOptions).
|
|
35
40
|
*/
|
|
36
|
-
struct NativeRemoveBackgroundOptions {
|
|
41
|
+
struct NativeRemoveBackgroundOptions final {
|
|
37
42
|
public:
|
|
38
43
|
double maxDimension SWIFT_PRIVATE;
|
|
39
44
|
OutputFormat format SWIFT_PRIVATE;
|
|
@@ -42,6 +47,9 @@ namespace margelo::nitro::rnremoveimagebg {
|
|
|
42
47
|
public:
|
|
43
48
|
NativeRemoveBackgroundOptions() = default;
|
|
44
49
|
explicit NativeRemoveBackgroundOptions(double maxDimension, OutputFormat format, double quality): maxDimension(maxDimension), format(format), quality(quality) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const NativeRemoveBackgroundOptions& lhs, const NativeRemoveBackgroundOptions& rhs) = default;
|
|
45
53
|
};
|
|
46
54
|
|
|
47
55
|
} // namespace margelo::nitro::rnremoveimagebg
|
|
@@ -54,16 +62,16 @@ namespace margelo::nitro {
|
|
|
54
62
|
static inline margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
55
63
|
jsi::Object obj = arg.asObject(runtime);
|
|
56
64
|
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"))
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxDimension"))),
|
|
66
|
+
JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "format"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "quality")))
|
|
60
68
|
);
|
|
61
69
|
}
|
|
62
70
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rnremoveimagebg::NativeRemoveBackgroundOptions& arg) {
|
|
63
71
|
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));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxDimension"), JSIConverter<double>::toJSI(runtime, arg.maxDimension));
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "format"), JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::toJSI(runtime, arg.format));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "quality"), JSIConverter<double>::toJSI(runtime, arg.quality));
|
|
67
75
|
return obj;
|
|
68
76
|
}
|
|
69
77
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -74,9 +82,9 @@ namespace margelo::nitro {
|
|
|
74
82
|
if (!nitro::isPlainObject(runtime, obj)) {
|
|
75
83
|
return false;
|
|
76
84
|
}
|
|
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;
|
|
85
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxDimension")))) return false;
|
|
86
|
+
if (!JSIConverter<margelo::nitro::rnremoveimagebg::OutputFormat>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "format")))) return false;
|
|
87
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "quality")))) return false;
|
|
80
88
|
return true;
|
|
81
89
|
}
|
|
82
90
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-remove-image-bg",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "rn-remove-image-bg",
|
|
5
5
|
"homepage": "https://github.com/a-eid/rn-remove-image-bg",
|
|
6
6
|
"main": "lib/index",
|
|
@@ -35,24 +35,15 @@
|
|
|
35
35
|
"*.podspec",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"scripts": {
|
|
39
|
-
"postinstall": "tsc || exit 0;",
|
|
40
|
-
"typecheck": "tsc --noEmit",
|
|
41
|
-
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
42
|
-
"typescript": "tsc",
|
|
43
|
-
"specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\"",
|
|
44
|
-
"prepare": "npm run typescript",
|
|
45
|
-
"test": "vitest run"
|
|
46
|
-
},
|
|
47
38
|
"author": "Ahmed Eid <a.eid@yandex.com> (https://github.com/a-eid)",
|
|
48
39
|
"license": "MIT",
|
|
49
40
|
"devDependencies": {
|
|
50
41
|
"@biomejs/biome": "^2.3.11",
|
|
51
|
-
"@types/react": "^19.
|
|
52
|
-
"nitrogen": "
|
|
53
|
-
"react": "19.
|
|
54
|
-
"react-native": "0.
|
|
55
|
-
"react-native-nitro-modules": "0.
|
|
42
|
+
"@types/react": "^19.2.0",
|
|
43
|
+
"nitrogen": "0.35.0",
|
|
44
|
+
"react": "19.2.0",
|
|
45
|
+
"react-native": "0.83.2",
|
|
46
|
+
"react-native-nitro-modules": "0.35.0",
|
|
56
47
|
"typescript": "^5.9.3",
|
|
57
48
|
"vitest": "^3.0.0"
|
|
58
49
|
},
|
|
@@ -67,5 +58,13 @@
|
|
|
67
58
|
"buffer": "^6.0.3",
|
|
68
59
|
"thumbhash": "^0.1.1",
|
|
69
60
|
"upng-js": "^2.1.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"postinstall": "tsc || exit 0;",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
66
|
+
"typescript": "tsc",
|
|
67
|
+
"specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\"",
|
|
68
|
+
"test": "vitest run"
|
|
70
69
|
}
|
|
71
|
-
}
|
|
70
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
// Mock expo-file-system before importing cache
|
|
3
|
-
vi.mock('expo-file-system/legacy', () => ({
|
|
4
|
-
cacheDirectory: '/mock/cache/',
|
|
5
|
-
getInfoAsync: vi.fn().mockResolvedValue({ exists: false }),
|
|
6
|
-
makeDirectoryAsync: vi.fn().mockResolvedValue(undefined),
|
|
7
|
-
readAsStringAsync: vi.fn().mockResolvedValue('{}'),
|
|
8
|
-
writeAsStringAsync: vi.fn().mockResolvedValue(undefined),
|
|
9
|
-
deleteAsync: vi.fn().mockResolvedValue(undefined),
|
|
10
|
-
}));
|
|
11
|
-
// Import after mocking
|
|
12
|
-
import { bgRemovalCache } from '../cache';
|
|
13
|
-
describe('BackgroundRemovalCache', () => {
|
|
14
|
-
beforeEach(async () => {
|
|
15
|
-
// Clear cache before each test
|
|
16
|
-
await bgRemovalCache.clear();
|
|
17
|
-
});
|
|
18
|
-
describe('hashOptions', () => {
|
|
19
|
-
it('should hash options to JSON string', () => {
|
|
20
|
-
const hash = bgRemovalCache.hashOptions({
|
|
21
|
-
format: 'PNG',
|
|
22
|
-
maxDimension: 1024,
|
|
23
|
-
quality: 100
|
|
24
|
-
});
|
|
25
|
-
expect(hash).toBe('{"format":"PNG","maxDimension":1024,"quality":100}');
|
|
26
|
-
});
|
|
27
|
-
it('should produce consistent hash regardless of key order', () => {
|
|
28
|
-
const hash1 = bgRemovalCache.hashOptions({ a: 1, b: 2 });
|
|
29
|
-
const hash2 = bgRemovalCache.hashOptions({ b: 2, a: 1 });
|
|
30
|
-
expect(hash1).toBe(hash2);
|
|
31
|
-
});
|
|
32
|
-
it('should exclude functions from hash', () => {
|
|
33
|
-
const hash = bgRemovalCache.hashOptions({
|
|
34
|
-
value: 1,
|
|
35
|
-
callback: () => { }
|
|
36
|
-
});
|
|
37
|
-
expect(hash).toBe('{"value":1}');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('size', () => {
|
|
41
|
-
it('should return 0 for empty cache', () => {
|
|
42
|
-
expect(bgRemovalCache.size).toBe(0);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('set and get', () => {
|
|
46
|
-
it('should store and retrieve cached results', async () => {
|
|
47
|
-
const path = 'file:///test/image.jpg';
|
|
48
|
-
const optionsHash = bgRemovalCache.hashOptions({ format: 'PNG' });
|
|
49
|
-
const resultPath = 'file:///cache/result.png';
|
|
50
|
-
bgRemovalCache.set(path, optionsHash, resultPath);
|
|
51
|
-
expect(bgRemovalCache.size).toBe(1);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('clear', () => {
|
|
55
|
-
it('should clear all cache entries', async () => {
|
|
56
|
-
bgRemovalCache.set('path1', 'hash1', 'result1');
|
|
57
|
-
bgRemovalCache.set('path2', 'hash2', 'result2');
|
|
58
|
-
expect(bgRemovalCache.size).toBe(2);
|
|
59
|
-
await bgRemovalCache.clear();
|
|
60
|
-
expect(bgRemovalCache.size).toBe(0);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe('getCacheDirectory', () => {
|
|
64
|
-
it('should return the cache directory path', () => {
|
|
65
|
-
const dir = bgRemovalCache.getCacheDirectory();
|
|
66
|
-
expect(dir).toContain('bg-removal');
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('configure', () => {
|
|
70
|
-
it('should allow updating cache configuration', () => {
|
|
71
|
-
bgRemovalCache.configure({
|
|
72
|
-
maxEntries: 100,
|
|
73
|
-
maxAgeMinutes: 60,
|
|
74
|
-
persistToDisk: true,
|
|
75
|
-
});
|
|
76
|
-
// Configuration applied - no error thrown
|
|
77
|
-
expect(true).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('prune', () => {
|
|
81
|
-
it('should return 0 when no entries are expired', () => {
|
|
82
|
-
bgRemovalCache.set('path', 'hash', 'result');
|
|
83
|
-
const removed = bgRemovalCache.prune();
|
|
84
|
-
expect(removed).toBe(0);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { BackgroundRemovalError, wrapNativeError } from '../errors';
|
|
3
|
-
describe('BackgroundRemovalError', () => {
|
|
4
|
-
describe('constructor', () => {
|
|
5
|
-
it('should create an error with message and code', () => {
|
|
6
|
-
const error = new BackgroundRemovalError('Test message', 'INVALID_PATH');
|
|
7
|
-
expect(error.message).toBe('Test message');
|
|
8
|
-
expect(error.code).toBe('INVALID_PATH');
|
|
9
|
-
expect(error.name).toBe('BackgroundRemovalError');
|
|
10
|
-
expect(error.originalError).toBeUndefined();
|
|
11
|
-
});
|
|
12
|
-
it('should preserve original error', () => {
|
|
13
|
-
const originalError = new Error('Original error');
|
|
14
|
-
const error = new BackgroundRemovalError('Wrapped', 'UNKNOWN', originalError);
|
|
15
|
-
expect(error.originalError).toBe(originalError);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('toUserMessage', () => {
|
|
19
|
-
it('should return user-friendly message for INVALID_PATH', () => {
|
|
20
|
-
const error = new BackgroundRemovalError('test', 'INVALID_PATH');
|
|
21
|
-
expect(error.toUserMessage()).toBe('The image path provided is invalid.');
|
|
22
|
-
});
|
|
23
|
-
it('should return user-friendly message for FILE_NOT_FOUND', () => {
|
|
24
|
-
const error = new BackgroundRemovalError('test', 'FILE_NOT_FOUND');
|
|
25
|
-
expect(error.toUserMessage()).toBe('The image file could not be found.');
|
|
26
|
-
});
|
|
27
|
-
it('should return user-friendly message for DECODE_FAILED', () => {
|
|
28
|
-
const error = new BackgroundRemovalError('test', 'DECODE_FAILED');
|
|
29
|
-
expect(error.toUserMessage()).toBe('The image could not be read. Please ensure it is a valid image file.');
|
|
30
|
-
});
|
|
31
|
-
it('should return user-friendly message for ML_PROCESSING_FAILED', () => {
|
|
32
|
-
const error = new BackgroundRemovalError('test', 'ML_PROCESSING_FAILED');
|
|
33
|
-
expect(error.toUserMessage()).toBe('Background removal failed. Please try with a different image.');
|
|
34
|
-
});
|
|
35
|
-
it('should return user-friendly message for SAVE_FAILED', () => {
|
|
36
|
-
const error = new BackgroundRemovalError('test', 'SAVE_FAILED');
|
|
37
|
-
expect(error.toUserMessage()).toBe('Could not save the processed image.');
|
|
38
|
-
});
|
|
39
|
-
it('should return user-friendly message for INVALID_OPTIONS', () => {
|
|
40
|
-
const error = new BackgroundRemovalError('test', 'INVALID_OPTIONS');
|
|
41
|
-
expect(error.toUserMessage()).toBe('Invalid options provided for background removal.');
|
|
42
|
-
});
|
|
43
|
-
it('should return default message for UNKNOWN', () => {
|
|
44
|
-
const error = new BackgroundRemovalError('test', 'UNKNOWN');
|
|
45
|
-
expect(error.toUserMessage()).toBe('An unexpected error occurred during background removal.');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe('wrapNativeError', () => {
|
|
50
|
-
it('should return same error if already BackgroundRemovalError', () => {
|
|
51
|
-
const error = new BackgroundRemovalError('test', 'INVALID_PATH');
|
|
52
|
-
const wrapped = wrapNativeError(error);
|
|
53
|
-
expect(wrapped).toBe(error);
|
|
54
|
-
});
|
|
55
|
-
it('should wrap string error', () => {
|
|
56
|
-
const wrapped = wrapNativeError('Something went wrong');
|
|
57
|
-
expect(wrapped).toBeInstanceOf(BackgroundRemovalError);
|
|
58
|
-
expect(wrapped.message).toBe('Something went wrong');
|
|
59
|
-
expect(wrapped.code).toBe('UNKNOWN');
|
|
60
|
-
});
|
|
61
|
-
it('should detect FILE_NOT_FOUND from message', () => {
|
|
62
|
-
const error = new Error('File does not exist at path');
|
|
63
|
-
const wrapped = wrapNativeError(error);
|
|
64
|
-
expect(wrapped.code).toBe('FILE_NOT_FOUND');
|
|
65
|
-
expect(wrapped.originalError).toBe(error);
|
|
66
|
-
});
|
|
67
|
-
it('should detect DECODE_FAILED from message', () => {
|
|
68
|
-
const error = new Error('Could not decode image');
|
|
69
|
-
const wrapped = wrapNativeError(error);
|
|
70
|
-
expect(wrapped.code).toBe('DECODE_FAILED');
|
|
71
|
-
});
|
|
72
|
-
it('should detect ML_PROCESSING_FAILED from message', () => {
|
|
73
|
-
const error = new Error('Failed to generate mask');
|
|
74
|
-
const wrapped = wrapNativeError(error);
|
|
75
|
-
expect(wrapped.code).toBe('ML_PROCESSING_FAILED');
|
|
76
|
-
});
|
|
77
|
-
it('should detect SAVE_FAILED from message', () => {
|
|
78
|
-
const error = new Error('Could not save output file');
|
|
79
|
-
const wrapped = wrapNativeError(error);
|
|
80
|
-
expect(wrapped.code).toBe('SAVE_FAILED');
|
|
81
|
-
});
|
|
82
|
-
});
|