react-native-vision-camera-spoof-detector 1.1.0 → 1.1.11

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 (44) hide show
  1. package/.npmignore +16 -0
  2. package/README.md +103 -186
  3. package/android/CMakeLists.txt +29 -0
  4. package/android/build.gradle +26 -10
  5. package/android/fix-prefab.gradle +4 -0
  6. package/android/src/main/AndroidManifest.xml +1 -1
  7. package/android/src/main/cpp/CMakeLists.txt +18 -86
  8. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +80 -6
  9. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  10. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofModule.kt +55 -103
  11. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofPackage.kt +15 -8
  12. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactory.kt +15 -0
  13. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +111 -0
  14. package/index.js +22 -43
  15. package/nitro.json +20 -0
  16. package/nitrogen/generated/.gitattributes +1 -0
  17. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.cmake +81 -0
  18. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.gradle +27 -0
  19. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.cpp +58 -0
  20. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.hpp +34 -0
  21. package/nitrogen/generated/android/c++/JAntiSpoofingResult.hpp +77 -0
  22. package/nitrogen/generated/android/c++/JFunc_void_AntiSpoofingResult.hpp +78 -0
  23. package/nitrogen/generated/android/c++/JFunc_void_std__exception_ptr.hpp +76 -0
  24. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.cpp +75 -0
  25. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.hpp +63 -0
  26. package/nitrogen/generated/android/c++/JSize.hpp +61 -0
  27. package/nitrogen/generated/android/c++/JSpoofDetectorOutputOptions.hpp +91 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/AntiSpoofingResult.kt +76 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_AntiSpoofingResult.kt +78 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_std__exception_ptr.kt +78 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactorySpec.kt +57 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Size.kt +56 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/SpoofDetectorOutputOptions.kt +65 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/VisionCameraSpoofDetectorOnLoad.kt +35 -0
  35. package/nitrogen/generated/shared/c++/AntiSpoofingResult.hpp +103 -0
  36. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.cpp +21 -0
  37. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.hpp +67 -0
  38. package/nitrogen/generated/shared/c++/Size.hpp +87 -0
  39. package/nitrogen/generated/shared/c++/SpoofDetectorOutputOptions.hpp +98 -0
  40. package/package.json +10 -8
  41. package/src/specs/SpoofDetectorFactory.nitro.ts +23 -0
  42. package/android/src/main/assets/spoof_model_scale_2_7.tflite +0 -0
  43. package/android/src/main/assets/spoof_model_scale_4_0.tflite +0 -0
  44. /package/{android/src/main → lib}/assets/FaceAntiSpoofing.tflite +0 -0
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// Size.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 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
+ #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
30
+
31
+
32
+
33
+
34
+
35
+ namespace margelo::nitro::camera::spoofdetector {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (Size).
39
+ */
40
+ struct Size final {
41
+ public:
42
+ double width SWIFT_PRIVATE;
43
+ double height SWIFT_PRIVATE;
44
+
45
+ public:
46
+ Size() = default;
47
+ explicit Size(double width, double height): width(width), height(height) {}
48
+
49
+ public:
50
+ friend bool operator==(const Size& lhs, const Size& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::camera::spoofdetector
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ Size <> JS Size (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::camera::spoofdetector::Size> final {
60
+ static inline margelo::nitro::camera::spoofdetector::Size fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::camera::spoofdetector::Size(
63
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
64
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::Size& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
82
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,98 @@
1
+ ///
2
+ /// SpoofDetectorOutputOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 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
+ #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
30
+
31
+ // Forward declaration of `Size` to properly resolve imports.
32
+ namespace margelo::nitro::camera::spoofdetector { struct Size; }
33
+ // Forward declaration of `AntiSpoofingResult` to properly resolve imports.
34
+ namespace margelo::nitro::camera::spoofdetector { struct AntiSpoofingResult; }
35
+
36
+ #include "Size.hpp"
37
+ #include <optional>
38
+ #include "AntiSpoofingResult.hpp"
39
+ #include <functional>
40
+ #include <exception>
41
+
42
+ namespace margelo::nitro::camera::spoofdetector {
43
+
44
+ /**
45
+ * A struct which can be represented as a JavaScript object (SpoofDetectorOutputOptions).
46
+ */
47
+ struct SpoofDetectorOutputOptions final {
48
+ public:
49
+ std::optional<Size> targetResolution SWIFT_PRIVATE;
50
+ std::function<void(const AntiSpoofingResult& /* result */)> onResult SWIFT_PRIVATE;
51
+ std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError SWIFT_PRIVATE;
52
+
53
+ public:
54
+ SpoofDetectorOutputOptions() = default;
55
+ explicit SpoofDetectorOutputOptions(std::optional<Size> targetResolution, std::function<void(const AntiSpoofingResult& /* result */)> onResult, std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError): targetResolution(targetResolution), onResult(onResult), onError(onError) {}
56
+
57
+ public:
58
+ // SpoofDetectorOutputOptions is not equatable because these properties are not equatable: onResult, onError
59
+ };
60
+
61
+ } // namespace margelo::nitro::camera::spoofdetector
62
+
63
+ namespace margelo::nitro {
64
+
65
+ // C++ SpoofDetectorOutputOptions <> JS SpoofDetectorOutputOptions (object)
66
+ template <>
67
+ struct JSIConverter<margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions> final {
68
+ static inline margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
69
+ jsi::Object obj = arg.asObject(runtime);
70
+ return margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions(
71
+ JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"))),
72
+ JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult"))),
73
+ JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onError")))
74
+ );
75
+ }
76
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions& arg) {
77
+ jsi::Object obj(runtime);
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"), JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::toJSI(runtime, arg.targetResolution));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onResult"), JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::toJSI(runtime, arg.onResult));
80
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onError"), JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::toJSI(runtime, arg.onError));
81
+ return obj;
82
+ }
83
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
84
+ if (!value.isObject()) {
85
+ return false;
86
+ }
87
+ jsi::Object obj = value.getObject(runtime);
88
+ if (!nitro::isPlainObject(runtime, obj)) {
89
+ return false;
90
+ }
91
+ if (!JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution")))) return false;
92
+ if (!JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult")))) return false;
93
+ if (!JSIConverter<std::optional<std::function<void(const std::exception_ptr&)>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onError")))) return false;
94
+ return true;
95
+ }
96
+ };
97
+
98
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.1.0",
3
+ "version": "1.1.11",
4
4
  "description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
5
5
  "homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
@@ -28,13 +28,18 @@
28
28
  "types": "index.d.ts",
29
29
  "files": [
30
30
  "android/",
31
+ "lib/",
32
+ "src/",
33
+ "nitrogen/",
34
+ "nitro.json",
31
35
  "ios/",
36
+ ".npmignore",
32
37
  "CHANGELOG.md",
33
- "index.js",
34
38
  "index.d.ts",
35
- "README.md",
39
+ "index.js",
36
40
  "LICENSE",
37
- "react-native-vision-camera-spoof-detector.podspec"
41
+ "react-native-vision-camera-spoof-detector.podspec",
42
+ "README.md"
38
43
  ],
39
44
  "keywords": [
40
45
  "react-native",
@@ -56,8 +61,7 @@
56
61
  "peerDependencies": {
57
62
  "react": ">=16.8.0",
58
63
  "react-native": ">=0.60.0",
59
- "react-native-vision-camera": "^4.6.4 || ^5.0.0",
60
- "react-native-reanimated": "^3.0.0",
64
+ "react-native-vision-camera": "^5.0.0",
61
65
  "react-native-vision-camera-worklets": "^5.0.0",
62
66
  "react-native-worklets": "^0.12.0"
63
67
  },
@@ -69,8 +73,6 @@
69
73
  "devDependencies": {
70
74
  "react": "^18.2.0",
71
75
  "react-native": "^0.72.0",
72
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
73
- "@babel/plugin-proposal-optional-chaining": "^7.21.0",
74
76
  "typescript": "^5.0.0"
75
77
  },
76
78
  "engines": {
@@ -0,0 +1,23 @@
1
+ import type { CameraOutput, Size } from 'react-native-vision-camera'
2
+ import type { HybridObject } from 'react-native-nitro-modules'
3
+
4
+ export interface AntiSpoofingResult {
5
+ isLive: boolean
6
+ label: string
7
+ neuralNetworkScore: number
8
+ laplacianScore: number
9
+ combinedScore: number
10
+ confidence: number
11
+ }
12
+
13
+ export interface SpoofDetectorOutputOptions {
14
+ targetResolution?: Size
15
+ onResult: (result: AntiSpoofingResult) => void
16
+ onError?: (error: Error) => void
17
+ }
18
+
19
+ export interface SpoofDetectorFactory extends HybridObject<{
20
+ android: 'kotlin'
21
+ }> {
22
+ createSpoofDetectorOutput(options: SpoofDetectorOutputOptions): CameraOutput
23
+ }