@nitro-mlkit/digital-ink 0.1.0-beta.0
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/LICENSE +21 -0
- package/NitroMLKitDigitalInk.podspec +34 -0
- package/README.md +67 -0
- package/android/CMakeLists.txt +12 -0
- package/android/build.gradle +77 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/kotlin/com/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizer.kt +84 -0
- package/android/src/main/kotlin/com/nitromlkit/digitalink/NitroMLKitDigitalInkPackage.kt +19 -0
- package/expo-module.config.json +9 -0
- package/ios/HybridDigitalInkRecognizer.swift +156 -0
- package/nitro.json +16 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMLKitDigitalInk+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroMLKitDigitalInk+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMLKitDigitalInkOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroMLKitDigitalInkOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JHybridDigitalInkRecognizerSpec.cpp +149 -0
- package/nitrogen/generated/android/c++/JHybridDigitalInkRecognizerSpec.hpp +67 -0
- package/nitrogen/generated/android/c++/JInkPoint.hpp +65 -0
- package/nitrogen/generated/android/c++/JInkStroke.hpp +78 -0
- package/nitrogen/generated/android/c++/JRecognitionCandidate.hpp +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizerSpec.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/InkPoint.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/InkStroke.kt +51 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/NitroMLKitDigitalInkOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/RecognitionCandidate.kt +56 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInk+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Bridge.hpp +265 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Umbrella.hpp +56 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInkAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroMLKitDigitalInkAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridDigitalInkRecognizerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridDigitalInkRecognizerSpecSwift.hpp +125 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_RecognitionCandidate_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridDigitalInkRecognizerSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridDigitalInkRecognizerSpec_cxx.swift +220 -0
- package/nitrogen/generated/ios/swift/InkPoint.swift +52 -0
- package/nitrogen/generated/ios/swift/InkStroke.swift +35 -0
- package/nitrogen/generated/ios/swift/RecognitionCandidate.swift +47 -0
- package/nitrogen/generated/shared/c++/HybridDigitalInkRecognizerSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridDigitalInkRecognizerSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/InkPoint.hpp +91 -0
- package/nitrogen/generated/shared/c++/InkStroke.hpp +85 -0
- package/nitrogen/generated/shared/c++/RecognitionCandidate.hpp +88 -0
- package/package.json +54 -0
- package/src/index.ts +19 -0
- package/src/specs/DigitalInkRecognizer.nitro.ts +51 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMLKitDigitalInkOnLoad.cpp
|
|
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
|
+
#ifndef BUILDING_NITROMLKITDIGITALINK_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroMLKitDigitalInkOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroMLKitDigitalInkOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridDigitalInkRecognizerSpec.hpp"
|
|
19
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
22
|
+
|
|
23
|
+
int initialize(JavaVM* vm) {
|
|
24
|
+
return facebook::jni::initialize(vm, []() {
|
|
25
|
+
::margelo::nitro::mlkit::digitalink::registerAllNatives();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
struct JHybridDigitalInkRecognizerSpecImpl: public jni::JavaClass<JHybridDigitalInkRecognizerSpecImpl, JHybridDigitalInkRecognizerSpec::JavaPart> {
|
|
30
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizer;";
|
|
31
|
+
static std::shared_ptr<JHybridDigitalInkRecognizerSpec> create() {
|
|
32
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridDigitalInkRecognizerSpecImpl::javaobject()>();
|
|
33
|
+
jni::local_ref<JHybridDigitalInkRecognizerSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
34
|
+
return javaPart->getJHybridDigitalInkRecognizerSpec();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
void registerAllNatives() {
|
|
39
|
+
using namespace margelo::nitro;
|
|
40
|
+
using namespace margelo::nitro::mlkit::digitalink;
|
|
41
|
+
|
|
42
|
+
// Register native JNI methods
|
|
43
|
+
margelo::nitro::mlkit::digitalink::JHybridDigitalInkRecognizerSpec::CxxPart::registerNatives();
|
|
44
|
+
|
|
45
|
+
// Register Nitro Hybrid Objects
|
|
46
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
47
|
+
"DigitalInkRecognizer",
|
|
48
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
49
|
+
return JHybridDigitalInkRecognizerSpecImpl::create();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMLKitDigitalInkOnLoad.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
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of NitroMLKitDigitalInk, 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.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroMLKitDigitalInk HybridObjects
|
|
26
|
+
* margelo::nitro::mlkit::digitalink::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridDigitalInkRecognizerSpec.cpp
|
|
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
|
+
#include "JHybridDigitalInkRecognizerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `RecognitionCandidate` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::mlkit::digitalink { struct RecognitionCandidate; }
|
|
12
|
+
// Forward declaration of `InkStroke` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::mlkit::digitalink { struct InkStroke; }
|
|
14
|
+
// Forward declaration of `InkPoint` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::mlkit::digitalink { struct InkPoint; }
|
|
16
|
+
|
|
17
|
+
#include "RecognitionCandidate.hpp"
|
|
18
|
+
#include <vector>
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
20
|
+
#include <NitroModules/JPromise.hpp>
|
|
21
|
+
#include "JRecognitionCandidate.hpp"
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <NitroModules/JUnit.hpp>
|
|
25
|
+
#include "InkStroke.hpp"
|
|
26
|
+
#include "JInkStroke.hpp"
|
|
27
|
+
#include "InkPoint.hpp"
|
|
28
|
+
#include "JInkPoint.hpp"
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
31
|
+
|
|
32
|
+
std::shared_ptr<JHybridDigitalInkRecognizerSpec> JHybridDigitalInkRecognizerSpec::JavaPart::getJHybridDigitalInkRecognizerSpec() {
|
|
33
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
34
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridDigitalInkRecognizerSpec>(hybridObject);
|
|
35
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
36
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridDigitalInkRecognizerSpec!");
|
|
37
|
+
}
|
|
38
|
+
return castHybridObject;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
jni::local_ref<JHybridDigitalInkRecognizerSpec::CxxPart::jhybriddata> JHybridDigitalInkRecognizerSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
42
|
+
return makeCxxInstance(jThis);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
std::shared_ptr<JHybridObject> JHybridDigitalInkRecognizerSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
46
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridDigitalInkRecognizerSpec::JavaPart>(javaPart);
|
|
47
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
48
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridDigitalInkRecognizerSpec::JavaPart!");
|
|
49
|
+
}
|
|
50
|
+
return std::make_shared<JHybridDigitalInkRecognizerSpec>(castJavaPart);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void JHybridDigitalInkRecognizerSpec::CxxPart::registerNatives() {
|
|
54
|
+
registerHybrid({
|
|
55
|
+
makeNativeMethod("initHybrid", JHybridDigitalInkRecognizerSpec::CxxPart::initHybrid),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Properties
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// Methods
|
|
63
|
+
std::shared_ptr<Promise<std::vector<RecognitionCandidate>>> JHybridDigitalInkRecognizerSpec::recognize(const std::vector<InkStroke>& strokes, const std::string& languageTag) {
|
|
64
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JArrayClass<JInkStroke>> /* strokes */, jni::alias_ref<jni::JString> /* languageTag */)>("recognize");
|
|
65
|
+
auto __result = method(_javaPart, [&](auto&& __input) {
|
|
66
|
+
size_t __size = __input.size();
|
|
67
|
+
jni::local_ref<jni::JArrayClass<JInkStroke>> __array = jni::JArrayClass<JInkStroke>::newArray(__size);
|
|
68
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
69
|
+
const auto& __element = __input[__i];
|
|
70
|
+
auto __elementJni = JInkStroke::fromCpp(__element);
|
|
71
|
+
__array->setElement(__i, *__elementJni);
|
|
72
|
+
}
|
|
73
|
+
return __array;
|
|
74
|
+
}(strokes), jni::make_jstring(languageTag));
|
|
75
|
+
return [&]() {
|
|
76
|
+
auto __promise = Promise<std::vector<RecognitionCandidate>>::create();
|
|
77
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
78
|
+
auto __result = jni::static_ref_cast<jni::JArrayClass<JRecognitionCandidate>>(__boxedResult);
|
|
79
|
+
__promise->resolve([&](auto&& __input) {
|
|
80
|
+
size_t __size = __input->size();
|
|
81
|
+
std::vector<RecognitionCandidate> __vector;
|
|
82
|
+
__vector.reserve(__size);
|
|
83
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
84
|
+
auto __element = __input->getElement(__i);
|
|
85
|
+
__vector.push_back(__element->toCpp());
|
|
86
|
+
}
|
|
87
|
+
return __vector;
|
|
88
|
+
}(__result));
|
|
89
|
+
});
|
|
90
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
91
|
+
jni::JniException __jniError(__throwable);
|
|
92
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
93
|
+
});
|
|
94
|
+
return __promise;
|
|
95
|
+
}();
|
|
96
|
+
}
|
|
97
|
+
std::shared_ptr<Promise<void>> JHybridDigitalInkRecognizerSpec::downloadModel(const std::string& languageTag) {
|
|
98
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* languageTag */)>("downloadModel");
|
|
99
|
+
auto __result = method(_javaPart, jni::make_jstring(languageTag));
|
|
100
|
+
return [&]() {
|
|
101
|
+
auto __promise = Promise<void>::create();
|
|
102
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
103
|
+
__promise->resolve();
|
|
104
|
+
});
|
|
105
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
106
|
+
jni::JniException __jniError(__throwable);
|
|
107
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
108
|
+
});
|
|
109
|
+
return __promise;
|
|
110
|
+
}();
|
|
111
|
+
}
|
|
112
|
+
std::shared_ptr<Promise<bool>> JHybridDigitalInkRecognizerSpec::isModelDownloaded(const std::string& languageTag) {
|
|
113
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* languageTag */)>("isModelDownloaded");
|
|
114
|
+
auto __result = method(_javaPart, jni::make_jstring(languageTag));
|
|
115
|
+
return [&]() {
|
|
116
|
+
auto __promise = Promise<bool>::create();
|
|
117
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
118
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
119
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
120
|
+
});
|
|
121
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
122
|
+
jni::JniException __jniError(__throwable);
|
|
123
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
124
|
+
});
|
|
125
|
+
return __promise;
|
|
126
|
+
}();
|
|
127
|
+
}
|
|
128
|
+
std::shared_ptr<Promise<void>> JHybridDigitalInkRecognizerSpec::deleteModel(const std::string& languageTag) {
|
|
129
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* languageTag */)>("deleteModel");
|
|
130
|
+
auto __result = method(_javaPart, jni::make_jstring(languageTag));
|
|
131
|
+
return [&]() {
|
|
132
|
+
auto __promise = Promise<void>::create();
|
|
133
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
134
|
+
__promise->resolve();
|
|
135
|
+
});
|
|
136
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
137
|
+
jni::JniException __jniError(__throwable);
|
|
138
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
139
|
+
});
|
|
140
|
+
return __promise;
|
|
141
|
+
}();
|
|
142
|
+
}
|
|
143
|
+
bool JHybridDigitalInkRecognizerSpec::isAvailable() {
|
|
144
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isAvailable");
|
|
145
|
+
auto __result = method(_javaPart);
|
|
146
|
+
return static_cast<bool>(__result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridDigitalInkRecognizerSpec.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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridDigitalInkRecognizerSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridDigitalInkRecognizerSpec: public virtual HybridDigitalInkRecognizerSpec, public virtual JHybridObject {
|
|
22
|
+
public:
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizerSpec;";
|
|
25
|
+
std::shared_ptr<JHybridDigitalInkRecognizerSpec> getJHybridDigitalInkRecognizerSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizerSpec$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
|
+
};
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
explicit JHybridDigitalInkRecognizerSpec(const jni::local_ref<JHybridDigitalInkRecognizerSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridDigitalInkRecognizerSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
41
|
+
~JHybridDigitalInkRecognizerSpec() override {
|
|
42
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
43
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridDigitalInkRecognizerSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
std::shared_ptr<Promise<std::vector<RecognitionCandidate>>> recognize(const std::vector<InkStroke>& strokes, const std::string& languageTag) override;
|
|
58
|
+
std::shared_ptr<Promise<void>> downloadModel(const std::string& languageTag) override;
|
|
59
|
+
std::shared_ptr<Promise<bool>> isModelDownloaded(const std::string& languageTag) override;
|
|
60
|
+
std::shared_ptr<Promise<void>> deleteModel(const std::string& languageTag) override;
|
|
61
|
+
bool isAvailable() override;
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
jni::global_ref<JHybridDigitalInkRecognizerSpec::JavaPart> _javaPart;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JInkPoint.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "InkPoint.hpp"
|
|
12
|
+
|
|
13
|
+
#include <optional>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "InkPoint" and the Kotlin data class "InkPoint".
|
|
21
|
+
*/
|
|
22
|
+
struct JInkPoint final: public jni::JavaClass<JInkPoint> {
|
|
23
|
+
public:
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/InkPoint;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct InkPoint by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
InkPoint toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldX = clazz->getField<double>("x");
|
|
35
|
+
double x = this->getFieldValue(fieldX);
|
|
36
|
+
static const auto fieldY = clazz->getField<double>("y");
|
|
37
|
+
double y = this->getFieldValue(fieldY);
|
|
38
|
+
static const auto fieldT = clazz->getField<jni::JDouble>("t");
|
|
39
|
+
jni::local_ref<jni::JDouble> t = this->getFieldValue(fieldT);
|
|
40
|
+
return InkPoint(
|
|
41
|
+
x,
|
|
42
|
+
y,
|
|
43
|
+
t != nullptr ? std::make_optional(t->value()) : std::nullopt
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
50
|
+
*/
|
|
51
|
+
[[maybe_unused]]
|
|
52
|
+
static jni::local_ref<JInkPoint::javaobject> fromCpp(const InkPoint& value) {
|
|
53
|
+
using JSignature = JInkPoint(double, double, jni::alias_ref<jni::JDouble>);
|
|
54
|
+
static const auto clazz = javaClassStatic();
|
|
55
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
56
|
+
return create(
|
|
57
|
+
clazz,
|
|
58
|
+
value.x,
|
|
59
|
+
value.y,
|
|
60
|
+
value.t.has_value() ? jni::JDouble::valueOf(value.t.value()) : nullptr
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JInkStroke.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "InkStroke.hpp"
|
|
12
|
+
|
|
13
|
+
#include "InkPoint.hpp"
|
|
14
|
+
#include "JInkPoint.hpp"
|
|
15
|
+
#include <optional>
|
|
16
|
+
#include <vector>
|
|
17
|
+
|
|
18
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
19
|
+
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The C++ JNI bridge between the C++ struct "InkStroke" and the Kotlin data class "InkStroke".
|
|
24
|
+
*/
|
|
25
|
+
struct JInkStroke final: public jni::JavaClass<JInkStroke> {
|
|
26
|
+
public:
|
|
27
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/InkStroke;";
|
|
28
|
+
|
|
29
|
+
public:
|
|
30
|
+
/**
|
|
31
|
+
* Convert this Java/Kotlin-based struct to the C++ struct InkStroke by copying all values to C++.
|
|
32
|
+
*/
|
|
33
|
+
[[maybe_unused]]
|
|
34
|
+
[[nodiscard]]
|
|
35
|
+
InkStroke toCpp() const {
|
|
36
|
+
static const auto clazz = javaClassStatic();
|
|
37
|
+
static const auto fieldPoints = clazz->getField<jni::JArrayClass<JInkPoint>>("points");
|
|
38
|
+
jni::local_ref<jni::JArrayClass<JInkPoint>> points = this->getFieldValue(fieldPoints);
|
|
39
|
+
return InkStroke(
|
|
40
|
+
[&](auto&& __input) {
|
|
41
|
+
size_t __size = __input->size();
|
|
42
|
+
std::vector<InkPoint> __vector;
|
|
43
|
+
__vector.reserve(__size);
|
|
44
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
45
|
+
auto __element = __input->getElement(__i);
|
|
46
|
+
__vector.push_back(__element->toCpp());
|
|
47
|
+
}
|
|
48
|
+
return __vector;
|
|
49
|
+
}(points)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
/**
|
|
55
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
56
|
+
*/
|
|
57
|
+
[[maybe_unused]]
|
|
58
|
+
static jni::local_ref<JInkStroke::javaobject> fromCpp(const InkStroke& value) {
|
|
59
|
+
using JSignature = JInkStroke(jni::alias_ref<jni::JArrayClass<JInkPoint>>);
|
|
60
|
+
static const auto clazz = javaClassStatic();
|
|
61
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
62
|
+
return create(
|
|
63
|
+
clazz,
|
|
64
|
+
[&](auto&& __input) {
|
|
65
|
+
size_t __size = __input.size();
|
|
66
|
+
jni::local_ref<jni::JArrayClass<JInkPoint>> __array = jni::JArrayClass<JInkPoint>::newArray(__size);
|
|
67
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
68
|
+
const auto& __element = __input[__i];
|
|
69
|
+
auto __elementJni = JInkPoint::fromCpp(__element);
|
|
70
|
+
__array->setElement(__i, *__elementJni);
|
|
71
|
+
}
|
|
72
|
+
return __array;
|
|
73
|
+
}(value.points)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JRecognitionCandidate.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "RecognitionCandidate.hpp"
|
|
12
|
+
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <string>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::mlkit::digitalink {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The C++ JNI bridge between the C++ struct "RecognitionCandidate" and the Kotlin data class "RecognitionCandidate".
|
|
22
|
+
*/
|
|
23
|
+
struct JRecognitionCandidate final: public jni::JavaClass<JRecognitionCandidate> {
|
|
24
|
+
public:
|
|
25
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/digitalink/RecognitionCandidate;";
|
|
26
|
+
|
|
27
|
+
public:
|
|
28
|
+
/**
|
|
29
|
+
* Convert this Java/Kotlin-based struct to the C++ struct RecognitionCandidate by copying all values to C++.
|
|
30
|
+
*/
|
|
31
|
+
[[maybe_unused]]
|
|
32
|
+
[[nodiscard]]
|
|
33
|
+
RecognitionCandidate toCpp() const {
|
|
34
|
+
static const auto clazz = javaClassStatic();
|
|
35
|
+
static const auto fieldText = clazz->getField<jni::JString>("text");
|
|
36
|
+
jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
|
|
37
|
+
static const auto fieldScore = clazz->getField<jni::JDouble>("score");
|
|
38
|
+
jni::local_ref<jni::JDouble> score = this->getFieldValue(fieldScore);
|
|
39
|
+
return RecognitionCandidate(
|
|
40
|
+
text->toStdString(),
|
|
41
|
+
score != nullptr ? std::make_optional(score->value()) : std::nullopt
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
/**
|
|
47
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
48
|
+
*/
|
|
49
|
+
[[maybe_unused]]
|
|
50
|
+
static jni::local_ref<JRecognitionCandidate::javaobject> fromCpp(const RecognitionCandidate& value) {
|
|
51
|
+
using JSignature = JRecognitionCandidate(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>);
|
|
52
|
+
static const auto clazz = javaClassStatic();
|
|
53
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
54
|
+
return create(
|
|
55
|
+
clazz,
|
|
56
|
+
jni::make_jstring(value.text),
|
|
57
|
+
value.score.has_value() ? jni::JDouble::valueOf(value.score.value()) : nullptr
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::mlkit::digitalink
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridDigitalInkRecognizerSpec.kt
|
|
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
|
+
package com.margelo.nitro.nitromlkit.digitalink
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
import com.margelo.nitro.core.HybridObject
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Kotlin class representing the DigitalInkRecognizer HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of DigitalInkRecognizer.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress(
|
|
23
|
+
"KotlinJniMissingFunction", "unused",
|
|
24
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
|
+
)
|
|
27
|
+
abstract class HybridDigitalInkRecognizerSpec: HybridObject() {
|
|
28
|
+
// Properties
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// Methods
|
|
32
|
+
@DoNotStrip
|
|
33
|
+
@Keep
|
|
34
|
+
abstract fun recognize(strokes: Array<InkStroke>, languageTag: String): Promise<Array<RecognitionCandidate>>
|
|
35
|
+
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
@Keep
|
|
38
|
+
abstract fun downloadModel(languageTag: String): Promise<Unit>
|
|
39
|
+
|
|
40
|
+
@DoNotStrip
|
|
41
|
+
@Keep
|
|
42
|
+
abstract fun isModelDownloaded(languageTag: String): Promise<Boolean>
|
|
43
|
+
|
|
44
|
+
@DoNotStrip
|
|
45
|
+
@Keep
|
|
46
|
+
abstract fun deleteModel(languageTag: String): Promise<Unit>
|
|
47
|
+
|
|
48
|
+
@DoNotStrip
|
|
49
|
+
@Keep
|
|
50
|
+
abstract fun isAvailable(): Boolean
|
|
51
|
+
|
|
52
|
+
// Default implementation of `HybridObject.toString()`
|
|
53
|
+
override fun toString(): String {
|
|
54
|
+
return "[HybridObject DigitalInkRecognizer]"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// C++ backing class
|
|
58
|
+
@DoNotStrip
|
|
59
|
+
@Keep
|
|
60
|
+
protected open class CxxPart(javaPart: HybridDigitalInkRecognizerSpec): HybridObject.CxxPart(javaPart) {
|
|
61
|
+
// C++ JHybridDigitalInkRecognizerSpec::CxxPart::initHybrid(...)
|
|
62
|
+
external override fun initHybrid(): HybridData
|
|
63
|
+
}
|
|
64
|
+
override fun createCxxPart(): CxxPart {
|
|
65
|
+
return CxxPart(this)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
companion object {
|
|
69
|
+
protected const val TAG = "HybridDigitalInkRecognizerSpec"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// InkPoint.kt
|
|
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
|
+
package com.margelo.nitro.nitromlkit.digitalink
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
import java.util.Objects
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the JavaScript object/struct "InkPoint".
|
|
17
|
+
*/
|
|
18
|
+
@DoNotStrip
|
|
19
|
+
@Keep
|
|
20
|
+
data class InkPoint(
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
val x: Double,
|
|
24
|
+
@DoNotStrip
|
|
25
|
+
@Keep
|
|
26
|
+
val y: Double,
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
@Keep
|
|
29
|
+
val t: Double?
|
|
30
|
+
) {
|
|
31
|
+
/* primary constructor */
|
|
32
|
+
|
|
33
|
+
override fun equals(other: Any?): Boolean {
|
|
34
|
+
if (this === other) return true
|
|
35
|
+
if (other !is InkPoint) return false
|
|
36
|
+
return Objects.deepEquals(this.x, other.x)
|
|
37
|
+
&& Objects.deepEquals(this.y, other.y)
|
|
38
|
+
&& Objects.deepEquals(this.t, other.t)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun hashCode(): Int {
|
|
42
|
+
return arrayOf<Any?>(
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
t
|
|
46
|
+
).contentDeepHashCode()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
companion object {
|
|
50
|
+
/**
|
|
51
|
+
* Constructor called from C++
|
|
52
|
+
*/
|
|
53
|
+
@DoNotStrip
|
|
54
|
+
@Keep
|
|
55
|
+
@Suppress("unused")
|
|
56
|
+
@JvmStatic
|
|
57
|
+
private fun fromCpp(x: Double, y: Double, t: Double?): InkPoint {
|
|
58
|
+
return InkPoint(x, y, t)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|