@airisu-dev/react-native-live2d-skia 0.0.0-stage → 0.1.1

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/Live2dSkia.podspec +159 -0
  3. package/README.md +258 -2
  4. package/android/CMakeLists.txt +113 -0
  5. package/android/build.gradle +223 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  10. package/android/src/main/java/com/live2dskia/Live2dSkiaPackage.kt +20 -0
  11. package/app.plugin.js +2 -0
  12. package/cli/build/index.js +157 -0
  13. package/cpp/cubism/CubismCompat.hpp +26 -0
  14. package/cpp/cubism/CubismHelpers.hpp +27 -0
  15. package/cpp/cubism/CubismRendererStub.cpp +14 -0
  16. package/cpp/cubism/CubismSetup.cpp +54 -0
  17. package/cpp/cubism/CubismSetup.hpp +9 -0
  18. package/cpp/cubism/HeldParameterUpdater.hpp +25 -0
  19. package/cpp/cubism/Live2DUserModel.cpp +125 -0
  20. package/cpp/cubism/Live2DUserModel.hpp +57 -0
  21. package/cpp/cubism/Live2DUserModelAnimation.cpp +107 -0
  22. package/cpp/drawing/JsiUnwrap.hpp +25 -0
  23. package/cpp/drawing/MeshCache.cpp +75 -0
  24. package/cpp/drawing/MeshCache.hpp +45 -0
  25. package/cpp/drawing/SkiaDrawer.cpp +138 -0
  26. package/cpp/drawing/SkiaDrawer.hpp +42 -0
  27. package/cpp/hybrid/HybridLive2DModel.cpp +174 -0
  28. package/cpp/hybrid/HybridLive2DModel.hpp +64 -0
  29. package/cpp/hybrid/HybridLive2dSkia.cpp +10 -0
  30. package/cpp/hybrid/HybridLive2dSkia.hpp +11 -0
  31. package/ios/Bridge.h +8 -0
  32. package/nitro.json +20 -0
  33. package/nitrogen/generated/.gitattributes +1 -0
  34. package/nitrogen/generated/android/Live2dSkia+autolinking.cmake +82 -0
  35. package/nitrogen/generated/android/Live2dSkia+autolinking.gradle +27 -0
  36. package/nitrogen/generated/android/Live2dSkiaOnLoad.cpp +49 -0
  37. package/nitrogen/generated/android/Live2dSkiaOnLoad.hpp +34 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/live2dskia/Live2dSkiaOnLoad.kt +35 -0
  39. package/nitrogen/generated/ios/Live2dSkia+autolinking.rb +62 -0
  40. package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Bridge.cpp +17 -0
  41. package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Bridge.hpp +27 -0
  42. package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Umbrella.hpp +38 -0
  43. package/nitrogen/generated/ios/Live2dSkiaAutolinking.mm +35 -0
  44. package/nitrogen/generated/ios/Live2dSkiaAutolinking.swift +16 -0
  45. package/nitrogen/generated/shared/c++/DrawableData.hpp +116 -0
  46. package/nitrogen/generated/shared/c++/HybridLive2DModelSpec.cpp +39 -0
  47. package/nitrogen/generated/shared/c++/HybridLive2DModelSpec.hpp +86 -0
  48. package/nitrogen/generated/shared/c++/HybridLive2dSkiaSpec.cpp +21 -0
  49. package/nitrogen/generated/shared/c++/HybridLive2dSkiaSpec.hpp +66 -0
  50. package/nitrogen/generated/shared/c++/MotionPriority.hpp +80 -0
  51. package/package.json +149 -4
  52. package/plugin/build/index.d.ts +14 -0
  53. package/plugin/build/index.js +81 -0
  54. package/src/components/Live2D.tsx +131 -0
  55. package/src/components/index.ts +2 -0
  56. package/src/hooks/index.ts +8 -0
  57. package/src/hooks/useLive2DGesture.ts +140 -0
  58. package/src/hooks/useLive2DModel.ts +47 -0
  59. package/src/index.ts +5 -0
  60. package/src/loader/cubismJson.ts +23 -0
  61. package/src/loader/index.ts +9 -0
  62. package/src/loader/loadModel.ts +195 -0
  63. package/src/loader/modelContext.ts +80 -0
  64. package/src/loader/modelUrl.ts +112 -0
  65. package/src/native.ts +4 -0
  66. package/src/rendering/decodeImage.ts +12 -0
  67. package/src/rendering/drawer.ts +256 -0
  68. package/src/rendering/skia.ts +26 -0
  69. package/src/rendering/skiaTypes.ts +99 -0
  70. package/src/rendering/ticker/addToTicker.ts +52 -0
  71. package/src/rendering/ticker/constants.ts +11 -0
  72. package/src/rendering/ticker/frames.ts +35 -0
  73. package/src/rendering/ticker/index.ts +5 -0
  74. package/src/rendering/ticker/loop.ts +115 -0
  75. package/src/rendering/ticker/state.ts +65 -0
  76. package/src/rendering/ticker/stats.ts +36 -0
  77. package/src/rendering/ticker/types.ts +57 -0
  78. package/src/specs/react-native-live2d-skia.nitro.ts +88 -0
  79. package/src/utils/clock.ts +10 -0
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// Live2dSkiaAutolinking.mm
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 <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+
11
+ #import <type_traits>
12
+
13
+ #include "HybridLive2dSkia.hpp"
14
+
15
+ @interface Live2dSkiaAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation Live2dSkiaAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::live2dskia;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "Live2dSkia",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ static_assert(std::is_default_constructible_v<HybridLive2dSkia>,
28
+ "The HybridObject \"HybridLive2dSkia\" is not default-constructible! "
29
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
30
+ return std::make_shared<HybridLive2dSkia>();
31
+ }
32
+ );
33
+ }
34
+
35
+ @end
@@ -0,0 +1,16 @@
1
+ ///
2
+ /// Live2dSkiaAutolinking.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
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class Live2dSkiaAutolinking {
13
+ public typealias bridge = margelo.nitro.live2dskia.bridge.swift
14
+
15
+
16
+ }
@@ -0,0 +1,116 @@
1
+ ///
2
+ /// DrawableData.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 <vector>
34
+ #include <NitroModules/ArrayBuffer.hpp>
35
+
36
+ namespace margelo::nitro::live2dskia {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (DrawableData).
40
+ */
41
+ struct DrawableData final {
42
+ public:
43
+ double index SWIFT_PRIVATE;
44
+ bool visible SWIFT_PRIVATE;
45
+ double textureIndex SWIFT_PRIVATE;
46
+ double opacity SWIFT_PRIVATE;
47
+ double constantFlags SWIFT_PRIVATE;
48
+ std::vector<double> masks SWIFT_PRIVATE;
49
+ std::shared_ptr<ArrayBuffer> positions SWIFT_PRIVATE;
50
+ std::shared_ptr<ArrayBuffer> uvs SWIFT_PRIVATE;
51
+ std::shared_ptr<ArrayBuffer> indices SWIFT_PRIVATE;
52
+
53
+ public:
54
+ DrawableData() = default;
55
+ explicit DrawableData(double index, bool visible, double textureIndex, double opacity, double constantFlags, std::vector<double> masks, std::shared_ptr<ArrayBuffer> positions, std::shared_ptr<ArrayBuffer> uvs, std::shared_ptr<ArrayBuffer> indices): index(index), visible(visible), textureIndex(textureIndex), opacity(opacity), constantFlags(constantFlags), masks(masks), positions(positions), uvs(uvs), indices(indices) {}
56
+
57
+ public:
58
+ friend bool operator==(const DrawableData& lhs, const DrawableData& rhs) = default;
59
+ };
60
+
61
+ } // namespace margelo::nitro::live2dskia
62
+
63
+ namespace margelo::nitro {
64
+
65
+ // C++ DrawableData <> JS DrawableData (object)
66
+ template <>
67
+ struct JSIConverter<margelo::nitro::live2dskia::DrawableData> final {
68
+ static inline margelo::nitro::live2dskia::DrawableData fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
69
+ jsi::Object obj = arg.asObject(runtime);
70
+ return margelo::nitro::live2dskia::DrawableData(
71
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index"))),
72
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "visible"))),
73
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "textureIndex"))),
74
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "opacity"))),
75
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "constantFlags"))),
76
+ JSIConverter<std::vector<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masks"))),
77
+ JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "positions"))),
78
+ JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uvs"))),
79
+ JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "indices")))
80
+ );
81
+ }
82
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::live2dskia::DrawableData& arg) {
83
+ jsi::Object obj(runtime);
84
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "index"), JSIConverter<double>::toJSI(runtime, arg.index));
85
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "visible"), JSIConverter<bool>::toJSI(runtime, arg.visible));
86
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "textureIndex"), JSIConverter<double>::toJSI(runtime, arg.textureIndex));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "opacity"), JSIConverter<double>::toJSI(runtime, arg.opacity));
88
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "constantFlags"), JSIConverter<double>::toJSI(runtime, arg.constantFlags));
89
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "masks"), JSIConverter<std::vector<double>>::toJSI(runtime, arg.masks));
90
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "positions"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.positions));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "uvs"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.uvs));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "indices"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.indices));
93
+ return obj;
94
+ }
95
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
96
+ if (!value.isObject()) {
97
+ return false;
98
+ }
99
+ jsi::Object obj = value.getObject(runtime);
100
+ if (!nitro::isPlainObject(runtime, obj)) {
101
+ return false;
102
+ }
103
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index")))) return false;
104
+ if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "visible")))) return false;
105
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "textureIndex")))) return false;
106
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "opacity")))) return false;
107
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "constantFlags")))) return false;
108
+ if (!JSIConverter<std::vector<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masks")))) return false;
109
+ if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "positions")))) return false;
110
+ if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uvs")))) return false;
111
+ if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "indices")))) return false;
112
+ return true;
113
+ }
114
+ };
115
+
116
+ } // namespace margelo::nitro
@@ -0,0 +1,39 @@
1
+ ///
2
+ /// HybridLive2DModelSpec.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 "HybridLive2DModelSpec.hpp"
9
+
10
+ namespace margelo::nitro::live2dskia {
11
+
12
+ void HybridLive2DModelSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("canvasWidth", &HybridLive2DModelSpec::getCanvasWidth);
18
+ prototype.registerHybridGetter("canvasHeight", &HybridLive2DModelSpec::getCanvasHeight);
19
+ prototype.registerHybridGetter("originX", &HybridLive2DModelSpec::getOriginX);
20
+ prototype.registerHybridGetter("originY", &HybridLive2DModelSpec::getOriginY);
21
+ prototype.registerHybridGetter("pixelsPerUnit", &HybridLive2DModelSpec::getPixelsPerUnit);
22
+ prototype.registerHybridGetter("drawableCount", &HybridLive2DModelSpec::getDrawableCount);
23
+ prototype.registerHybridMethod("getDrawables", &HybridLive2DModelSpec::getDrawables);
24
+ prototype.registerHybridMethod("loadPhysics", &HybridLive2DModelSpec::loadPhysics);
25
+ prototype.registerHybridMethod("loadPose", &HybridLive2DModelSpec::loadPose);
26
+ prototype.registerHybridMethod("loadMotion", &HybridLive2DModelSpec::loadMotion);
27
+ prototype.registerHybridMethod("startMotion", &HybridLive2DModelSpec::startMotion);
28
+ prototype.registerHybridMethod("loadExpression", &HybridLive2DModelSpec::loadExpression);
29
+ prototype.registerHybridMethod("setExpression", &HybridLive2DModelSpec::setExpression);
30
+ prototype.registerHybridMethod("clearExpression", &HybridLive2DModelSpec::clearExpression);
31
+ prototype.registerHybridMethod("setParameter", &HybridLive2DModelSpec::setParameter);
32
+ prototype.registerHybridMethod("clearParameter", &HybridLive2DModelSpec::clearParameter);
33
+ prototype.registerHybridMethod("focus", &HybridLive2DModelSpec::focus);
34
+ prototype.registerHybridMethod("hitTest", &HybridLive2DModelSpec::hitTest);
35
+ prototype.registerHybridMethod("update", &HybridLive2DModelSpec::update);
36
+ });
37
+ }
38
+
39
+ } // namespace margelo::nitro::live2dskia
@@ -0,0 +1,86 @@
1
+ ///
2
+ /// HybridLive2DModelSpec.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 `DrawableData` to properly resolve imports.
17
+ namespace margelo::nitro::live2dskia { struct DrawableData; }
18
+ // Forward declaration of `MotionPriority` to properly resolve imports.
19
+ namespace margelo::nitro::live2dskia { enum class MotionPriority; }
20
+
21
+ #include "DrawableData.hpp"
22
+ #include <vector>
23
+ #include <string>
24
+ #include <optional>
25
+ #include "MotionPriority.hpp"
26
+
27
+ namespace margelo::nitro::live2dskia {
28
+
29
+ using namespace margelo::nitro;
30
+
31
+ /**
32
+ * An abstract base class for `Live2DModel`
33
+ * Inherit this class to create instances of `HybridLive2DModelSpec` in C++.
34
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
35
+ * @example
36
+ * ```cpp
37
+ * class HybridLive2DModel: public HybridLive2DModelSpec {
38
+ * public:
39
+ * HybridLive2DModel(...): HybridObject(TAG) { ... }
40
+ * // ...
41
+ * };
42
+ * ```
43
+ */
44
+ class HybridLive2DModelSpec: public virtual HybridObject {
45
+ public:
46
+ // Constructor
47
+ explicit HybridLive2DModelSpec(): HybridObject(TAG) { }
48
+
49
+ // Destructor
50
+ ~HybridLive2DModelSpec() override = default;
51
+
52
+ public:
53
+ // Properties
54
+ virtual double getCanvasWidth() = 0;
55
+ virtual double getCanvasHeight() = 0;
56
+ virtual double getOriginX() = 0;
57
+ virtual double getOriginY() = 0;
58
+ virtual double getPixelsPerUnit() = 0;
59
+ virtual double getDrawableCount() = 0;
60
+
61
+ public:
62
+ // Methods
63
+ virtual std::vector<DrawableData> getDrawables() = 0;
64
+ virtual void loadPhysics(const std::string& json) = 0;
65
+ virtual void loadPose(const std::string& json) = 0;
66
+ virtual void loadMotion(const std::string& group, double index, const std::string& json) = 0;
67
+ virtual bool startMotion(const std::string& group, std::optional<double> index, std::optional<MotionPriority> priority) = 0;
68
+ virtual void loadExpression(const std::string& name, const std::string& json) = 0;
69
+ virtual bool setExpression(const std::optional<std::string>& name) = 0;
70
+ virtual void clearExpression() = 0;
71
+ virtual void setParameter(const std::string& id, double value) = 0;
72
+ virtual void clearParameter(const std::string& id) = 0;
73
+ virtual void focus(double x, double y) = 0;
74
+ virtual std::vector<std::string> hitTest(double x, double y) = 0;
75
+ virtual void update(double deltaSeconds) = 0;
76
+
77
+ protected:
78
+ // Hybrid Setup
79
+ void loadHybridMethods() override;
80
+
81
+ protected:
82
+ // Tag for logging
83
+ static constexpr auto TAG = "Live2DModel";
84
+ };
85
+
86
+ } // namespace margelo::nitro::live2dskia
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// HybridLive2dSkiaSpec.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 "HybridLive2dSkiaSpec.hpp"
9
+
10
+ namespace margelo::nitro::live2dskia {
11
+
12
+ void HybridLive2dSkiaSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("loadModel", &HybridLive2dSkiaSpec::loadModel);
18
+ });
19
+ }
20
+
21
+ } // namespace margelo::nitro::live2dskia
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// HybridLive2dSkiaSpec.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 `HybridLive2DModelSpec` to properly resolve imports.
17
+ namespace margelo::nitro::live2dskia { class HybridLive2DModelSpec; }
18
+
19
+ #include <memory>
20
+ #include "HybridLive2DModelSpec.hpp"
21
+ #include <NitroModules/ArrayBuffer.hpp>
22
+ #include <string>
23
+
24
+ namespace margelo::nitro::live2dskia {
25
+
26
+ using namespace margelo::nitro;
27
+
28
+ /**
29
+ * An abstract base class for `Live2dSkia`
30
+ * Inherit this class to create instances of `HybridLive2dSkiaSpec` in C++.
31
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
32
+ * @example
33
+ * ```cpp
34
+ * class HybridLive2dSkia: public HybridLive2dSkiaSpec {
35
+ * public:
36
+ * HybridLive2dSkia(...): HybridObject(TAG) { ... }
37
+ * // ...
38
+ * };
39
+ * ```
40
+ */
41
+ class HybridLive2dSkiaSpec: public virtual HybridObject {
42
+ public:
43
+ // Constructor
44
+ explicit HybridLive2dSkiaSpec(): HybridObject(TAG) { }
45
+
46
+ // Destructor
47
+ ~HybridLive2dSkiaSpec() override = default;
48
+
49
+ public:
50
+ // Properties
51
+
52
+
53
+ public:
54
+ // Methods
55
+ virtual std::shared_ptr<HybridLive2DModelSpec> loadModel(const std::shared_ptr<ArrayBuffer>& moc, const std::string& settingsJson) = 0;
56
+
57
+ protected:
58
+ // Hybrid Setup
59
+ void loadHybridMethods() override;
60
+
61
+ protected:
62
+ // Tag for logging
63
+ static constexpr auto TAG = "Live2dSkia";
64
+ };
65
+
66
+ } // namespace margelo::nitro::live2dskia
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// MotionPriority.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/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::live2dskia {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (MotionPriority).
30
+ */
31
+ enum class MotionPriority {
32
+ IDLE SWIFT_NAME(idle) = 0,
33
+ NORMAL SWIFT_NAME(normal) = 1,
34
+ FORCE SWIFT_NAME(force) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::live2dskia
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ MotionPriority <> JS MotionPriority (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::live2dskia::MotionPriority> final {
44
+ static inline margelo::nitro::live2dskia::MotionPriority fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
45
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
46
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
47
+ case hashString("idle"): return margelo::nitro::live2dskia::MotionPriority::IDLE;
48
+ case hashString("normal"): return margelo::nitro::live2dskia::MotionPriority::NORMAL;
49
+ case hashString("force"): return margelo::nitro::live2dskia::MotionPriority::FORCE;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum MotionPriority - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::live2dskia::MotionPriority arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::live2dskia::MotionPriority::IDLE: return JSIConverter<std::string>::toJSI(runtime, "idle");
57
+ case margelo::nitro::live2dskia::MotionPriority::NORMAL: return JSIConverter<std::string>::toJSI(runtime, "normal");
58
+ case margelo::nitro::live2dskia::MotionPriority::FORCE: return JSIConverter<std::string>::toJSI(runtime, "force");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert MotionPriority to JS - invalid value: "
61
+ + std::to_string(static_cast<int>(arg)) + "!");
62
+ }
63
+ }
64
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
65
+ if (!value.isString()) {
66
+ return false;
67
+ }
68
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
69
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
70
+ case hashString("idle"):
71
+ case hashString("normal"):
72
+ case hashString("force"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,151 @@
1
1
  {
2
2
  "name": "@airisu-dev/react-native-live2d-skia",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "react-native-live2d-skia is a react native package built with Nitro",
5
+ "main": "src/index",
6
+ "types": "src/index",
7
+ "react-native": "src/index",
8
+ "source": "src/index",
9
+ "bin": {
10
+ "react-native-live2d-skia": "cli/build/index.js"
11
+ },
12
+ "scripts": {
13
+ "typecheck": "tsc --noEmit && tsc --noEmit -p plugin && tsc --noEmit -p cli",
14
+ "test": "bun test",
15
+ "verify:package": "bun scripts/verifyPackage.ts",
16
+ "clean": "git clean -dfX",
17
+ "build": "bun run typecheck && bob build && tsc -b plugin/tsconfig.build.json cli/tsconfig.build.json",
18
+ "codegen": "nitrogen --logLevel=debug",
19
+ "build:node": "tsc -b plugin/tsconfig.build.json cli/tsconfig.build.json",
20
+ "prepack": "bash ../../scripts/copy-readme.sh && tsc -b plugin/tsconfig.build.json cli/tsconfig.build.json"
21
+ },
22
+ "keywords": [
23
+ "react-native",
24
+ "react-native-live2d-skia"
25
+ ],
26
+ "files": [
27
+ "src",
28
+ "!**/*.test.ts",
29
+ "react-native.config.js",
30
+ "lib",
31
+ "nitrogen",
32
+ "cpp",
33
+ "nitro.json",
34
+ "android/build.gradle",
35
+ "android/fix-prefab.gradle",
36
+ "android/gradle.properties",
37
+ "android/CMakeLists.txt",
38
+ "android/src",
39
+ "ios/**/*.h",
40
+ "ios/**/*.m",
41
+ "ios/**/*.mm",
42
+ "ios/**/*.cpp",
43
+ "ios/**/*.swift",
44
+ "app.plugin.js",
45
+ "plugin/build",
46
+ "cli/build",
47
+ "*.podspec",
48
+ "README.md"
49
+ ],
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/airisu-dev/react-native-live2d-skia.git"
53
+ },
54
+ "author": "airisu-dev",
55
+ "license": "MIT",
56
+ "bugs": "https://github.com/airisu-dev/react-native-live2d-skia/issues",
57
+ "homepage": "https://github.com/airisu-dev/react-native-live2d-skia#readme",
58
+ "publishConfig": {
59
+ "access": "public",
60
+ "registry": "https://registry.npmjs.org/"
61
+ },
62
+ "devDependencies": {
63
+ "@types/bun": "^1.4.4",
64
+ "@types/node": "26.6.5",
65
+ "@types/react": "19.2.0",
66
+ "nitrogen": "^0.37.1",
67
+ "react": "19.2.3",
68
+ "react-native": "0.86.3",
69
+ "react-native-builder-bob": "^0.40.18",
70
+ "react-native-nitro-modules": "^0.37.1",
71
+ "typescript": "^6.0.3"
72
+ },
73
+ "peerDependencies": {
74
+ "expo": "*",
75
+ "expo-asset": "*",
76
+ "expo-file-system": "*",
77
+ "react": "*",
78
+ "react-native": "*",
79
+ "react-native-gesture-handler": "*",
80
+ "react-native-nitro-modules": "*",
81
+ "react-native-reanimated": "*",
82
+ "react-native-skia": ">=3.3.0",
83
+ "@shopify/react-native-skia": ">=2.10.0",
84
+ "react-native-worklets": "*"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "@shopify/react-native-skia": {
88
+ "optional": true
89
+ },
90
+ "react-native-skia": {
91
+ "optional": true
92
+ }
93
+ },
94
+ "eslintConfig": {
95
+ "root": true,
96
+ "extends": [
97
+ "@react-native",
98
+ "prettier"
99
+ ],
100
+ "plugins": [
101
+ "prettier"
102
+ ],
103
+ "rules": {
104
+ "prettier/prettier": [
105
+ "warn",
106
+ {
107
+ "quoteProps": "consistent",
108
+ "singleQuote": true,
109
+ "tabWidth": 2,
110
+ "trailingComma": "es5",
111
+ "useTabs": false
112
+ }
113
+ ]
114
+ }
115
+ },
116
+ "eslintIgnore": [
117
+ "node_modules/",
118
+ "lib/"
119
+ ],
120
+ "prettier": {
121
+ "quoteProps": "consistent",
122
+ "singleQuote": true,
123
+ "tabWidth": 2,
124
+ "trailingComma": "es5",
125
+ "useTabs": false,
126
+ "semi": false
127
+ },
128
+ "react-native-builder-bob": {
129
+ "source": "src",
130
+ "output": "lib",
131
+ "exclude": "**/{__tests__,__fixtures__,__mocks__}/**,**/*.test.ts",
132
+ "targets": [
133
+ "commonjs",
134
+ "module",
135
+ [
136
+ "typescript",
137
+ {
138
+ "project": "tsconfig.build.json"
139
+ }
140
+ ]
141
+ ]
142
+ },
143
+ "cubismSdk": {
144
+ "latest": "5-r.5",
145
+ "versions": {
146
+ "5-r.5": {
147
+ "sha256": "7ff3a4bbc19c0a8728965aa522ab77eb11b252916453e68a8a78d3b71188bb12"
148
+ }
149
+ }
150
+ }
151
+ }
@@ -0,0 +1,14 @@
1
+ import { type ConfigPlugin } from 'expo/config-plugins';
2
+ export interface Live2dSkiaPluginProps {
3
+ /** Cubism SDK for Native folder (the one with `cubism-info.yml`), relative to the app's root. */
4
+ cubismSdkPath: string;
5
+ }
6
+ export declare function nativeProperties(projectRoot: string, platformProjectRoot: string, sdkPath: string): {
7
+ "live2dSkia.cubismSdkPath": string;
8
+ "live2dSkia.skiaPackage": string;
9
+ };
10
+ export declare const withLive2dSkia: ConfigPlugin<Live2dSkiaPluginProps | undefined>;
11
+ export declare function skiaPackageOf(projectRoot: string): string;
12
+ export declare function warnIfMissing(sdkDir: string): void;
13
+ declare const _default: ConfigPlugin<Live2dSkiaPluginProps | undefined>;
14
+ export default _default;