@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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/NitroMLKitDigitalInk.podspec +34 -0
  3. package/README.md +67 -0
  4. package/android/CMakeLists.txt +12 -0
  5. package/android/build.gradle +77 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  8. package/android/src/main/kotlin/com/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizer.kt +84 -0
  9. package/android/src/main/kotlin/com/nitromlkit/digitalink/NitroMLKitDigitalInkPackage.kt +19 -0
  10. package/expo-module.config.json +9 -0
  11. package/ios/HybridDigitalInkRecognizer.swift +156 -0
  12. package/nitro.json +16 -0
  13. package/nitrogen/generated/.gitattributes +1 -0
  14. package/nitrogen/generated/android/NitroMLKitDigitalInk+autolinking.cmake +81 -0
  15. package/nitrogen/generated/android/NitroMLKitDigitalInk+autolinking.gradle +27 -0
  16. package/nitrogen/generated/android/NitroMLKitDigitalInkOnLoad.cpp +54 -0
  17. package/nitrogen/generated/android/NitroMLKitDigitalInkOnLoad.hpp +34 -0
  18. package/nitrogen/generated/android/c++/JHybridDigitalInkRecognizerSpec.cpp +149 -0
  19. package/nitrogen/generated/android/c++/JHybridDigitalInkRecognizerSpec.hpp +67 -0
  20. package/nitrogen/generated/android/c++/JInkPoint.hpp +65 -0
  21. package/nitrogen/generated/android/c++/JInkStroke.hpp +78 -0
  22. package/nitrogen/generated/android/c++/JRecognitionCandidate.hpp +62 -0
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/HybridDigitalInkRecognizerSpec.kt +71 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/InkPoint.kt +61 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/InkStroke.kt +51 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/NitroMLKitDigitalInkOnLoad.kt +35 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/digitalink/RecognitionCandidate.kt +56 -0
  28. package/nitrogen/generated/ios/NitroMLKitDigitalInk+autolinking.rb +62 -0
  29. package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Bridge.cpp +65 -0
  30. package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Bridge.hpp +265 -0
  31. package/nitrogen/generated/ios/NitroMLKitDigitalInk-Swift-Cxx-Umbrella.hpp +56 -0
  32. package/nitrogen/generated/ios/NitroMLKitDigitalInkAutolinking.mm +33 -0
  33. package/nitrogen/generated/ios/NitroMLKitDigitalInkAutolinking.swift +26 -0
  34. package/nitrogen/generated/ios/c++/HybridDigitalInkRecognizerSpecSwift.cpp +11 -0
  35. package/nitrogen/generated/ios/c++/HybridDigitalInkRecognizerSpecSwift.hpp +125 -0
  36. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  37. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  38. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  39. package/nitrogen/generated/ios/swift/Func_void_std__vector_RecognitionCandidate_.swift +46 -0
  40. package/nitrogen/generated/ios/swift/HybridDigitalInkRecognizerSpec.swift +59 -0
  41. package/nitrogen/generated/ios/swift/HybridDigitalInkRecognizerSpec_cxx.swift +220 -0
  42. package/nitrogen/generated/ios/swift/InkPoint.swift +52 -0
  43. package/nitrogen/generated/ios/swift/InkStroke.swift +35 -0
  44. package/nitrogen/generated/ios/swift/RecognitionCandidate.swift +47 -0
  45. package/nitrogen/generated/shared/c++/HybridDigitalInkRecognizerSpec.cpp +25 -0
  46. package/nitrogen/generated/shared/c++/HybridDigitalInkRecognizerSpec.hpp +73 -0
  47. package/nitrogen/generated/shared/c++/InkPoint.hpp +91 -0
  48. package/nitrogen/generated/shared/c++/InkStroke.hpp +85 -0
  49. package/nitrogen/generated/shared/c++/RecognitionCandidate.hpp +88 -0
  50. package/package.json +54 -0
  51. package/src/index.ts +19 -0
  52. package/src/specs/DigitalInkRecognizer.nitro.ts +51 -0
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// RecognitionCandidate.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `RecognitionCandidate`, backed by a C++ struct.
12
+ */
13
+ public typealias RecognitionCandidate = margelo.nitro.mlkit.digitalink.RecognitionCandidate
14
+
15
+ public extension RecognitionCandidate {
16
+ private typealias bridge = margelo.nitro.mlkit.digitalink.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `RecognitionCandidate`.
20
+ */
21
+ init(text: String, score: Double?) {
22
+ self.init(std.string(text), { () -> bridge.std__optional_double_ in
23
+ if let __unwrappedValue = score {
24
+ return bridge.create_std__optional_double_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }())
29
+ }
30
+
31
+ @inline(__always)
32
+ var text: String {
33
+ return String(self.__text)
34
+ }
35
+
36
+ @inline(__always)
37
+ var score: Double? {
38
+ return { () -> Double? in
39
+ if bridge.has_value_std__optional_double_(self.__score) {
40
+ let __unwrapped = bridge.get_std__optional_double_(self.__score)
41
+ return __unwrapped
42
+ } else {
43
+ return nil
44
+ }
45
+ }()
46
+ }
47
+ }
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// HybridDigitalInkRecognizerSpec.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 "HybridDigitalInkRecognizerSpec.hpp"
9
+
10
+ namespace margelo::nitro::mlkit::digitalink {
11
+
12
+ void HybridDigitalInkRecognizerSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("recognize", &HybridDigitalInkRecognizerSpec::recognize);
18
+ prototype.registerHybridMethod("downloadModel", &HybridDigitalInkRecognizerSpec::downloadModel);
19
+ prototype.registerHybridMethod("isModelDownloaded", &HybridDigitalInkRecognizerSpec::isModelDownloaded);
20
+ prototype.registerHybridMethod("deleteModel", &HybridDigitalInkRecognizerSpec::deleteModel);
21
+ prototype.registerHybridMethod("isAvailable", &HybridDigitalInkRecognizerSpec::isAvailable);
22
+ });
23
+ }
24
+
25
+ } // namespace margelo::nitro::mlkit::digitalink
@@ -0,0 +1,73 @@
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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `RecognitionCandidate` to properly resolve imports.
17
+ namespace margelo::nitro::mlkit::digitalink { struct RecognitionCandidate; }
18
+ // Forward declaration of `InkStroke` to properly resolve imports.
19
+ namespace margelo::nitro::mlkit::digitalink { struct InkStroke; }
20
+
21
+ #include "RecognitionCandidate.hpp"
22
+ #include <vector>
23
+ #include <NitroModules/Promise.hpp>
24
+ #include "InkStroke.hpp"
25
+ #include <string>
26
+
27
+ namespace margelo::nitro::mlkit::digitalink {
28
+
29
+ using namespace margelo::nitro;
30
+
31
+ /**
32
+ * An abstract base class for `DigitalInkRecognizer`
33
+ * Inherit this class to create instances of `HybridDigitalInkRecognizerSpec` in C++.
34
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
35
+ * @example
36
+ * ```cpp
37
+ * class HybridDigitalInkRecognizer: public HybridDigitalInkRecognizerSpec {
38
+ * public:
39
+ * HybridDigitalInkRecognizer(...): HybridObject(TAG) { ... }
40
+ * // ...
41
+ * };
42
+ * ```
43
+ */
44
+ class HybridDigitalInkRecognizerSpec: public virtual HybridObject {
45
+ public:
46
+ // Constructor
47
+ explicit HybridDigitalInkRecognizerSpec(): HybridObject(TAG) { }
48
+
49
+ // Destructor
50
+ ~HybridDigitalInkRecognizerSpec() override = default;
51
+
52
+ public:
53
+ // Properties
54
+
55
+
56
+ public:
57
+ // Methods
58
+ virtual std::shared_ptr<Promise<std::vector<RecognitionCandidate>>> recognize(const std::vector<InkStroke>& strokes, const std::string& languageTag) = 0;
59
+ virtual std::shared_ptr<Promise<void>> downloadModel(const std::string& languageTag) = 0;
60
+ virtual std::shared_ptr<Promise<bool>> isModelDownloaded(const std::string& languageTag) = 0;
61
+ virtual std::shared_ptr<Promise<void>> deleteModel(const std::string& languageTag) = 0;
62
+ virtual bool isAvailable() = 0;
63
+
64
+ protected:
65
+ // Hybrid Setup
66
+ void loadHybridMethods() override;
67
+
68
+ protected:
69
+ // Tag for logging
70
+ static constexpr auto TAG = "DigitalInkRecognizer";
71
+ };
72
+
73
+ } // namespace margelo::nitro::mlkit::digitalink
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// InkPoint.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
+ #include <optional>
34
+
35
+ namespace margelo::nitro::mlkit::digitalink {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (InkPoint).
39
+ */
40
+ struct InkPoint final {
41
+ public:
42
+ double x SWIFT_PRIVATE;
43
+ double y SWIFT_PRIVATE;
44
+ std::optional<double> t SWIFT_PRIVATE;
45
+
46
+ public:
47
+ InkPoint() = default;
48
+ explicit InkPoint(double x, double y, std::optional<double> t): x(x), y(y), t(t) {}
49
+
50
+ public:
51
+ friend bool operator==(const InkPoint& lhs, const InkPoint& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::mlkit::digitalink
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ InkPoint <> JS InkPoint (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::mlkit::digitalink::InkPoint> final {
61
+ static inline margelo::nitro::mlkit::digitalink::InkPoint fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::mlkit::digitalink::InkPoint(
64
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
65
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
66
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "t")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::digitalink::InkPoint& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "t"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.t));
74
+ return obj;
75
+ }
76
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
77
+ if (!value.isObject()) {
78
+ return false;
79
+ }
80
+ jsi::Object obj = value.getObject(runtime);
81
+ if (!nitro::isPlainObject(runtime, obj)) {
82
+ return false;
83
+ }
84
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false;
85
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false;
86
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "t")))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
@@ -0,0 +1,85 @@
1
+ ///
2
+ /// InkStroke.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 `InkPoint` to properly resolve imports.
32
+ namespace margelo::nitro::mlkit::digitalink { struct InkPoint; }
33
+
34
+ #include "InkPoint.hpp"
35
+ #include <vector>
36
+
37
+ namespace margelo::nitro::mlkit::digitalink {
38
+
39
+ /**
40
+ * A struct which can be represented as a JavaScript object (InkStroke).
41
+ */
42
+ struct InkStroke final {
43
+ public:
44
+ std::vector<InkPoint> points SWIFT_PRIVATE;
45
+
46
+ public:
47
+ InkStroke() = default;
48
+ explicit InkStroke(std::vector<InkPoint> points): points(points) {}
49
+
50
+ public:
51
+ friend bool operator==(const InkStroke& lhs, const InkStroke& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::mlkit::digitalink
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ InkStroke <> JS InkStroke (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::mlkit::digitalink::InkStroke> final {
61
+ static inline margelo::nitro::mlkit::digitalink::InkStroke fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::mlkit::digitalink::InkStroke(
64
+ JSIConverter<std::vector<margelo::nitro::mlkit::digitalink::InkPoint>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "points")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::digitalink::InkStroke& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "points"), JSIConverter<std::vector<margelo::nitro::mlkit::digitalink::InkPoint>>::toJSI(runtime, arg.points));
70
+ return obj;
71
+ }
72
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
73
+ if (!value.isObject()) {
74
+ return false;
75
+ }
76
+ jsi::Object obj = value.getObject(runtime);
77
+ if (!nitro::isPlainObject(runtime, obj)) {
78
+ return false;
79
+ }
80
+ if (!JSIConverter<std::vector<margelo::nitro::mlkit::digitalink::InkPoint>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "points")))) return false;
81
+ return true;
82
+ }
83
+ };
84
+
85
+ } // namespace margelo::nitro
@@ -0,0 +1,88 @@
1
+ ///
2
+ /// RecognitionCandidate.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
+ #include <string>
34
+ #include <optional>
35
+
36
+ namespace margelo::nitro::mlkit::digitalink {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (RecognitionCandidate).
40
+ */
41
+ struct RecognitionCandidate final {
42
+ public:
43
+ std::string text SWIFT_PRIVATE;
44
+ std::optional<double> score SWIFT_PRIVATE;
45
+
46
+ public:
47
+ RecognitionCandidate() = default;
48
+ explicit RecognitionCandidate(std::string text, std::optional<double> score): text(text), score(score) {}
49
+
50
+ public:
51
+ friend bool operator==(const RecognitionCandidate& lhs, const RecognitionCandidate& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::mlkit::digitalink
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ RecognitionCandidate <> JS RecognitionCandidate (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::mlkit::digitalink::RecognitionCandidate> final {
61
+ static inline margelo::nitro::mlkit::digitalink::RecognitionCandidate fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::mlkit::digitalink::RecognitionCandidate(
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
65
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "score")))
66
+ );
67
+ }
68
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::digitalink::RecognitionCandidate& arg) {
69
+ jsi::Object obj(runtime);
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "score"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.score));
72
+ return obj;
73
+ }
74
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
75
+ if (!value.isObject()) {
76
+ return false;
77
+ }
78
+ jsi::Object obj = value.getObject(runtime);
79
+ if (!nitro::isPlainObject(runtime, obj)) {
80
+ return false;
81
+ }
82
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
83
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "score")))) return false;
84
+ return true;
85
+ }
86
+ };
87
+
88
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@nitro-mlkit/digital-ink",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "High-performance on-device handwriting recognition for React Native — Google ML Kit + Nitro. Recognize ink strokes in 300+ languages, zero bridge overhead.",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "scripts": {
8
+ "codegen": "nitrogen",
9
+ "build": "tsc --noEmit"
10
+ },
11
+ "keywords": [
12
+ "react-native",
13
+ "nitro",
14
+ "mlkit",
15
+ "digital-ink",
16
+ "handwriting-recognition",
17
+ "ink",
18
+ "machine-learning",
19
+ "on-device",
20
+ "expo"
21
+ ],
22
+ "author": "pologonzalo",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/pologonzalo/react-native-nitro-mlkit",
27
+ "directory": "packages/digital-ink"
28
+ },
29
+ "peerDependencies": {
30
+ "expo-modules-core": "*",
31
+ "react": ">=18",
32
+ "react-native": ">=0.76",
33
+ "react-native-nitro-modules": ">=0.20"
34
+ },
35
+ "devDependencies": {
36
+ "expo-modules-core": "*",
37
+ "nitro-codegen": "*",
38
+ "react-native-nitro-modules": "*",
39
+ "typescript": "~5.9.0"
40
+ },
41
+ "files": [
42
+ "src",
43
+ "ios/**/*.swift",
44
+ "android/src",
45
+ "android/build.gradle",
46
+ "android/CMakeLists.txt",
47
+ "expo-module.config.json",
48
+ "nitrogen/generated",
49
+ "*.podspec",
50
+ "nitro.json",
51
+ "README.md",
52
+ "LICENSE"
53
+ ]
54
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ export { type DigitalInkRecognizer } from "./specs/DigitalInkRecognizer.nitro";
2
+ export type {
3
+ InkPoint,
4
+ InkStroke,
5
+ RecognitionCandidate,
6
+ } from "./specs/DigitalInkRecognizer.nitro";
7
+
8
+ import { Platform } from "react-native";
9
+ import { requireOptionalNativeModule } from "expo-modules-core";
10
+ import { NitroModules } from "react-native-nitro-modules";
11
+ import type { DigitalInkRecognizer } from "./specs/DigitalInkRecognizer.nitro";
12
+
13
+ if (Platform.OS === "android") {
14
+ requireOptionalNativeModule("NitroMLKitDigitalInk");
15
+ }
16
+
17
+ /** The shared DigitalInkRecognizer instance. */
18
+ export const NitroDigitalInk =
19
+ NitroModules.createHybridObject<DigitalInkRecognizer>("DigitalInkRecognizer");
@@ -0,0 +1,51 @@
1
+ import type { HybridObject } from "react-native-nitro-modules";
2
+
3
+ /** A single sampled point of a stroke, in your canvas' coordinate space. */
4
+ export interface InkPoint {
5
+ x: number;
6
+ y: number;
7
+ /**
8
+ * Optional timestamp in milliseconds (e.g. `Date.now()`), relative or
9
+ * absolute. Providing it improves recognition accuracy.
10
+ */
11
+ t?: number;
12
+ }
13
+
14
+ /** One continuous stroke (pen-down → pen-up), as its sampled points. */
15
+ export interface InkStroke {
16
+ points: InkPoint[];
17
+ }
18
+
19
+ /** A candidate transcription of the ink, best first. */
20
+ export interface RecognitionCandidate {
21
+ text: string;
22
+ /** Model score if the model provides one (may be undefined). */
23
+ score?: number;
24
+ }
25
+
26
+ /**
27
+ * On-device handwriting / drawing recognition powered by Google ML Kit.
28
+ * Feed it the strokes the user drew (points with optional timestamps) and a
29
+ * BCP-47 language tag; get back candidate transcriptions. The per-language
30
+ * model downloads at runtime on first use. All recognition is on-device.
31
+ */
32
+ export interface DigitalInkRecognizer extends HybridObject<{
33
+ ios: "swift";
34
+ android: "kotlin";
35
+ }> {
36
+ /**
37
+ * Recognize handwriting from ink strokes. `languageTag` is a tag ML Kit
38
+ * supports (e.g. "en-US", "es-ES", "fr-FR", "zh-Hani", "emoji"). Downloads the
39
+ * model on first use.
40
+ */
41
+ recognize(strokes: InkStroke[], languageTag: string): Promise<RecognitionCandidate[]>;
42
+
43
+ /** Download a language model ahead of time. */
44
+ downloadModel(languageTag: string): Promise<void>;
45
+ /** Whether a language model is already downloaded. */
46
+ isModelDownloaded(languageTag: string): Promise<boolean>;
47
+ /** Delete a downloaded language model. */
48
+ deleteModel(languageTag: string): Promise<void>;
49
+
50
+ isAvailable(): boolean;
51
+ }