@nayan-ui/engine 0.0.0-stage → 1.0.0-beta.3

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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/NayanEngine.podspec +28 -0
  3. package/README.md +210 -2
  4. package/lib/module/assets/AssetBytesCache.js +76 -0
  5. package/lib/module/assets/AssetCache.js +19 -0
  6. package/lib/module/assets/AssetLoader.js +52 -0
  7. package/lib/module/assets/CacheGeneration.js +7 -0
  8. package/lib/module/assets/IndexedDbCache.web.js +149 -0
  9. package/lib/module/assets/ProceduralCache.js +222 -0
  10. package/lib/module/assets/font.js +136 -0
  11. package/lib/module/assets/loft.js +142 -0
  12. package/lib/module/assets/model.js +74 -0
  13. package/lib/module/assets/modelling.js +254 -0
  14. package/lib/module/assets/shape.js +926 -0
  15. package/lib/module/assets/source.js +58 -0
  16. package/lib/module/assets/source.web.js +22 -0
  17. package/lib/module/assets/storage.js +4 -0
  18. package/lib/module/assets/storage.shared.js +36 -0
  19. package/lib/module/assets/storage.web.js +37 -0
  20. package/lib/module/assets/surface.js +47 -0
  21. package/lib/module/assets/texture.js +66 -0
  22. package/lib/module/drawing/DrawingCanvas.js +38 -0
  23. package/lib/module/drawing/DrawingCanvas.web.js +206 -0
  24. package/lib/module/drawing/DrawingDocument.js +256 -0
  25. package/lib/module/drawing/types.js +4 -0
  26. package/lib/module/globals.d.ts +12 -0
  27. package/lib/module/index.js +36 -0
  28. package/lib/module/input/Joystick.js +84 -0
  29. package/lib/module/input/Joystick.web.js +93 -0
  30. package/lib/module/input/keyboard.js +250 -0
  31. package/lib/module/media/audio-worklet.js +34 -0
  32. package/lib/module/media/audio.js +94 -0
  33. package/lib/module/media/haptics.js +82 -0
  34. package/lib/module/media/output.web.js +66 -0
  35. package/lib/module/native/BrowserEngine.js +551 -0
  36. package/lib/module/native/EngineBridge.js +4 -0
  37. package/lib/module/native/NativeNayanEngine.js +7 -0
  38. package/lib/module/native/NativeNayanEngine.web.js +62 -0
  39. package/lib/module/native/prepare.js +7 -0
  40. package/lib/module/native/prepare.web.js +17 -0
  41. package/lib/module/native/spec/NativeNayanEngine.js +17 -0
  42. package/lib/module/package.json +1 -0
  43. package/lib/module/render/GameView.js +249 -0
  44. package/lib/module/render/camera.js +34 -0
  45. package/lib/module/render/host.js +39 -0
  46. package/lib/module/render/host.web.js +104 -0
  47. package/lib/module/render/meshes.js +159 -0
  48. package/lib/module/render/quality.js +112 -0
  49. package/lib/module/render/responder.js +4 -0
  50. package/lib/module/render/responder.web.js +97 -0
  51. package/lib/module/render/touch.js +185 -0
  52. package/lib/module/types.js +30 -0
  53. package/lib/module/world/Scoreboard.js +143 -0
  54. package/lib/module/world/TransformBatch.js +126 -0
  55. package/lib/module/world/World.js +690 -0
  56. package/lib/module/world/desc.js +186 -0
  57. package/lib/module/world/effects.js +451 -0
  58. package/lib/module/world/quat.js +86 -0
  59. package/lib/module/world/types.js +4 -0
  60. package/lib/typescript/package.json +1 -0
  61. package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
  62. package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
  63. package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
  64. package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
  65. package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
  66. package/lib/typescript/src/assets/ProceduralCache.d.ts +33 -0
  67. package/lib/typescript/src/assets/font.d.ts +53 -0
  68. package/lib/typescript/src/assets/loft.d.ts +31 -0
  69. package/lib/typescript/src/assets/model.d.ts +48 -0
  70. package/lib/typescript/src/assets/modelling.d.ts +157 -0
  71. package/lib/typescript/src/assets/shape.d.ts +203 -0
  72. package/lib/typescript/src/assets/source.d.ts +10 -0
  73. package/lib/typescript/src/assets/source.web.d.ts +8 -0
  74. package/lib/typescript/src/assets/storage.d.ts +2 -0
  75. package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
  76. package/lib/typescript/src/assets/storage.web.d.ts +7 -0
  77. package/lib/typescript/src/assets/surface.d.ts +17 -0
  78. package/lib/typescript/src/assets/texture.d.ts +30 -0
  79. package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
  80. package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
  81. package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
  82. package/lib/typescript/src/drawing/types.d.ts +12 -0
  83. package/lib/typescript/src/index.d.ts +42 -0
  84. package/lib/typescript/src/input/Joystick.d.ts +20 -0
  85. package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
  86. package/lib/typescript/src/input/keyboard.d.ts +17 -0
  87. package/lib/typescript/src/media/audio.d.ts +46 -0
  88. package/lib/typescript/src/media/haptics.d.ts +22 -0
  89. package/lib/typescript/src/media/output.web.d.ts +4 -0
  90. package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
  91. package/lib/typescript/src/native/EngineBridge.d.ts +22 -0
  92. package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
  93. package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
  94. package/lib/typescript/src/native/prepare.d.ts +3 -0
  95. package/lib/typescript/src/native/prepare.web.d.ts +2 -0
  96. package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +182 -0
  97. package/lib/typescript/src/render/GameView.d.ts +95 -0
  98. package/lib/typescript/src/render/camera.d.ts +6 -0
  99. package/lib/typescript/src/render/host.d.ts +29 -0
  100. package/lib/typescript/src/render/host.web.d.ts +16 -0
  101. package/lib/typescript/src/render/meshes.d.ts +45 -0
  102. package/lib/typescript/src/render/quality.d.ts +46 -0
  103. package/lib/typescript/src/render/responder.d.ts +2 -0
  104. package/lib/typescript/src/render/responder.web.d.ts +40 -0
  105. package/lib/typescript/src/render/touch.d.ts +26 -0
  106. package/lib/typescript/src/types.d.ts +72 -0
  107. package/lib/typescript/src/world/Scoreboard.d.ts +65 -0
  108. package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
  109. package/lib/typescript/src/world/World.d.ts +199 -0
  110. package/lib/typescript/src/world/desc.d.ts +17 -0
  111. package/lib/typescript/src/world/effects.d.ts +156 -0
  112. package/lib/typescript/src/world/quat.d.ts +31 -0
  113. package/lib/typescript/src/world/types.d.ts +233 -0
  114. package/lib/web/audio-worklet.js +29 -0
  115. package/lib/web/engine_core_bg.wasm +0 -0
  116. package/lib/web/index.js +7974 -0
  117. package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
  118. package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
  119. package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
  120. package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
  121. package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
  122. package/lib/web/types/src/assets/ProceduralCache.d.ts +32 -0
  123. package/lib/web/types/src/assets/font.d.ts +52 -0
  124. package/lib/web/types/src/assets/loft.d.ts +30 -0
  125. package/lib/web/types/src/assets/model.d.ts +47 -0
  126. package/lib/web/types/src/assets/modelling.d.ts +156 -0
  127. package/lib/web/types/src/assets/shape.d.ts +202 -0
  128. package/lib/web/types/src/assets/source.d.ts +7 -0
  129. package/lib/web/types/src/assets/storage.d.ts +6 -0
  130. package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
  131. package/lib/web/types/src/assets/surface.d.ts +16 -0
  132. package/lib/web/types/src/assets/texture.d.ts +29 -0
  133. package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
  134. package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
  135. package/lib/web/types/src/drawing/types.d.ts +11 -0
  136. package/lib/web/types/src/index.d.ts +41 -0
  137. package/lib/web/types/src/input/Joystick.d.ts +12 -0
  138. package/lib/web/types/src/input/keyboard.d.ts +16 -0
  139. package/lib/web/types/src/media/audio.d.ts +45 -0
  140. package/lib/web/types/src/media/haptics.d.ts +21 -0
  141. package/lib/web/types/src/media/output.d.ts +3 -0
  142. package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
  143. package/lib/web/types/src/native/EngineBridge.d.ts +21 -0
  144. package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
  145. package/lib/web/types/src/native/prepare.d.ts +1 -0
  146. package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +181 -0
  147. package/lib/web/types/src/render/GameView.d.ts +94 -0
  148. package/lib/web/types/src/render/camera.d.ts +5 -0
  149. package/lib/web/types/src/render/host.d.ts +15 -0
  150. package/lib/web/types/src/render/meshes.d.ts +44 -0
  151. package/lib/web/types/src/render/quality.d.ts +45 -0
  152. package/lib/web/types/src/render/responder.d.ts +39 -0
  153. package/lib/web/types/src/render/touch.d.ts +25 -0
  154. package/lib/web/types/src/types.d.ts +71 -0
  155. package/lib/web/types/src/world/Scoreboard.d.ts +64 -0
  156. package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
  157. package/lib/web/types/src/world/World.d.ts +198 -0
  158. package/lib/web/types/src/world/desc.d.ts +16 -0
  159. package/lib/web/types/src/world/effects.d.ts +155 -0
  160. package/lib/web/types/src/world/quat.d.ts +30 -0
  161. package/lib/web/types/src/world/types.d.ts +232 -0
  162. package/native/android/CMakeLists.txt +34 -0
  163. package/native/android/NayanEngineSpec.h +15 -0
  164. package/native/android/build.gradle +26 -0
  165. package/native/android/codegen/CMakeLists.txt +3 -0
  166. package/native/android/proguard-rules.pro +2 -0
  167. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +234 -0
  168. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
  169. package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
  170. package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
  171. package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
  172. package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
  173. package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
  174. package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
  175. package/native/core/build/android/x86/libengine_core.a +0 -0
  176. package/native/core/build/android/x86_64/libengine_core.a +0 -0
  177. package/native/core/include/drawing-licenses.txt +58 -0
  178. package/native/core/include/engine_core.h +322 -0
  179. package/native/cpp/NayanEngineModule.cpp +827 -0
  180. package/native/cpp/NayanEngineModule.h +144 -0
  181. package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
  182. package/native/cpp/generated/NayanEngineSpecJSI.h +921 -0
  183. package/native/ios/NayanEngineProvider.h +5 -0
  184. package/native/ios/NayanEngineProvider.mm +21 -0
  185. package/native/ios/NayanEngineSurface.mm +223 -0
  186. package/native/scripts/check-package.mjs +39 -0
  187. package/package.json +162 -4
  188. package/react-native.config.js +18 -0
  189. package/src/native/spec/NativeNayanEngine.ts +226 -0
@@ -0,0 +1,5 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <ReactCommon/RCTTurboModule.h>
3
+
4
+ @interface NayanEngineProvider : NSObject <RCTModuleProvider>
5
+ @end
@@ -0,0 +1,21 @@
1
+ #import "NayanEngineProvider.h"
2
+
3
+ #import <ReactCommon/CallInvoker.h>
4
+ #import <ReactCommon/TurboModule.h>
5
+
6
+ #include "NayanEngineModule.h"
7
+ #include <engine_core.h>
8
+ #import <Foundation/Foundation.h>
9
+
10
+ @implementation NayanEngineProvider
11
+
12
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
13
+ (const facebook::react::ObjCTurboModule::InitParams &)params
14
+ {
15
+ NSURL *support = [[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] firstObject];
16
+ NSData *path = [support.path dataUsingEncoding:NSUTF8StringEncoding];
17
+ if (path != nil) engine_cache_directory(static_cast<const uint8_t *>(path.bytes), path.length);
18
+ return std::make_shared<facebook::react::NayanEngineModule>(params.jsInvoker);
19
+ }
20
+
21
+ @end
@@ -0,0 +1,223 @@
1
+ // The EngineSurface view: a CAMetalLayer the Rust renderer draws into with Metal. JS refers to it by
2
+ // `surfaceId`; frames are drawn from the JS thread by NativeNayanEngine.renderFrame.
3
+ #import <QuartzCore/CAMetalLayer.h>
4
+ #import <QuartzCore/CADisplayLink.h>
5
+ #import <React/RCTViewManager.h>
6
+ #import <UIKit/UIKit.h>
7
+
8
+ #include <engine_core.h>
9
+
10
+ @interface NayanEngineSurfaceView : UIView <UIGestureRecognizerDelegate>
11
+ @property (nonatomic, assign) NSInteger surfaceId;
12
+ @property (nonatomic, assign) NSInteger drawingId;
13
+ @property (nonatomic, assign) NSInteger drawingMode;
14
+ @property (nonatomic, assign) NSInteger drawingBackground;
15
+ @property (nonatomic, copy) RCTDirectEventBlock onDrawingChange;
16
+ @end
17
+
18
+ @implementation NayanEngineSurfaceView {
19
+ BOOL _attached;
20
+ CADisplayLink *_drawingClock;
21
+ UITouch *_drawingTouch;
22
+ UIPinchGestureRecognizer *_drawingPinch;
23
+ UIPanGestureRecognizer *_drawingPan;
24
+ CFTimeInterval _lastDrawingEvent;
25
+ }
26
+
27
+ + (Class)layerClass
28
+ {
29
+ return [CAMetalLayer class];
30
+ }
31
+
32
+ - (instancetype)initWithFrame:(CGRect)frame
33
+ {
34
+ if (self = [super initWithFrame:frame]) {
35
+ _surfaceId = -1;
36
+ _drawingId = -1;
37
+ _drawingBackground = 0xffffff;
38
+ self.multipleTouchEnabled = YES;
39
+ _drawingPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDrawing:)];
40
+ _drawingPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDrawing:)];
41
+ _drawingPinch.delegate = self;
42
+ _drawingPan.delegate = self;
43
+ _drawingPan.minimumNumberOfTouches = 2;
44
+ _drawingPinch.enabled = NO;
45
+ _drawingPan.enabled = NO;
46
+ [self addGestureRecognizer:_drawingPinch];
47
+ [self addGestureRecognizer:_drawingPan];
48
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopDrawingClock) name:UIApplicationWillResignActiveNotification object:nil];
49
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDrawingClock) name:UIApplicationDidBecomeActiveNotification object:nil];
50
+ self.layer.opaque = YES;
51
+ }
52
+ return self;
53
+ }
54
+
55
+ - (void)setSurfaceId:(NSInteger)surfaceId
56
+ {
57
+ if (surfaceId == _surfaceId) {
58
+ return;
59
+ }
60
+ [self detach];
61
+ _surfaceId = surfaceId;
62
+ [self attach];
63
+ }
64
+
65
+ - (void)attach
66
+ {
67
+ CGFloat scale = self.window.screen.scale ?: UIScreen.mainScreen.scale;
68
+ CGSize size = self.bounds.size;
69
+ if (_surfaceId < 0 || self.window == nil || size.width <= 0 || size.height <= 0) {
70
+ return;
71
+ }
72
+ self.layer.contentsScale = scale;
73
+ _attached = engine_render_attach(
74
+ (int32_t)_surfaceId, (__bridge void *)self.layer, (uint32_t)(size.width * scale), (uint32_t)(size.height * scale)) == 1;
75
+ if (_drawingId >= 0) engine_drawing_invalidate((int32_t)_drawingId);
76
+ [self startDrawingClock];
77
+ }
78
+
79
+ - (void)detach
80
+ {
81
+ [self stopDrawingClock];
82
+ if (_attached) {
83
+ engine_render_detach((int32_t)_surfaceId);
84
+ _attached = NO;
85
+ }
86
+ }
87
+
88
+ - (void)layoutSubviews
89
+ {
90
+ [super layoutSubviews];
91
+ [self attach];
92
+ }
93
+
94
+ - (void)didMoveToWindow
95
+ {
96
+ [super didMoveToWindow];
97
+ if (self.window == nil) {
98
+ [self detach];
99
+ } else {
100
+ [self attach];
101
+ }
102
+ }
103
+
104
+ - (void)dealloc
105
+ {
106
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
107
+ [self detach];
108
+ }
109
+
110
+ - (void)setDrawingId:(NSInteger)value {
111
+ if (_drawingId == value) return;
112
+ [self stopDrawingClock];
113
+ _drawingId = value;
114
+ _drawingPinch.enabled = value >= 0;
115
+ _drawingPan.enabled = value >= 0;
116
+ if (value >= 0) engine_drawing_invalidate((int32_t)value);
117
+ [self startDrawingClock];
118
+ }
119
+ - (void)setDrawingMode:(NSInteger)value {
120
+ if (_drawingTouch != nil) engine_drawing_touch((int32_t)_drawingId, 3, 0, 0, 1);
121
+ _drawingTouch = nil;
122
+ _drawingMode = value;
123
+ _drawingPan.minimumNumberOfTouches = value == 0 ? 2 : 1;
124
+ }
125
+ - (void)setDrawingBackground:(NSInteger)value {
126
+ _drawingBackground = value;
127
+ if (_drawingId >= 0) engine_drawing_invalidate((int32_t)_drawingId);
128
+ }
129
+ - (void)startDrawingClock {
130
+ if (_drawingClock != nil || _drawingId < 0 || self.window == nil || !_attached || UIApplication.sharedApplication.applicationState != UIApplicationStateActive) return;
131
+ _drawingClock = [CADisplayLink displayLinkWithTarget:self selector:@selector(presentDrawing)];
132
+ if (@available(iOS 15.0, *)) _drawingClock.preferredFrameRateRange = CAFrameRateRangeMake(30, 120, 120);
133
+ [_drawingClock addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
134
+ }
135
+ - (void)stopDrawingClock {
136
+ [_drawingClock invalidate];
137
+ _drawingClock = nil;
138
+ if (_drawingTouch != nil) {
139
+ CGPoint point = [_drawingTouch locationInView:self];
140
+ engine_drawing_touch((int32_t)_drawingId, 2, point.x, point.y, 1);
141
+ _drawingTouch = nil;
142
+ }
143
+ }
144
+ - (void)presentDrawing {
145
+ engine_drawing_present((int32_t)_drawingId, (int32_t)_surfaceId, self.bounds.size.width, self.bounds.size.height, (uint32_t)_drawingBackground);
146
+ CFTimeInterval now = CACurrentMediaTime();
147
+ if (_onDrawingChange != nil && now - _lastDrawingEvent >= 0.1) {
148
+ _lastDrawingEvent = now;
149
+ char *event = engine_drawing_take_event((int32_t)_drawingId);
150
+ if (event != nullptr) {
151
+ NSString *state = [NSString stringWithUTF8String:event];
152
+ engine_drawing_result_free(event);
153
+ _onDrawingChange(@{@"state": state ?: @"{}", @"documentId": @(_drawingId)});
154
+ }
155
+ }
156
+ }
157
+ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gesture { return _drawingTouch == nil || _drawingTouch.type != UITouchTypePencil; }
158
+ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)a shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)b { return YES; }
159
+ - (void)pinchDrawing:(UIPinchGestureRecognizer *)gesture {
160
+ if (gesture.state == UIGestureRecognizerStateChanged) {
161
+ engine_drawing_transform((int32_t)_drawingId, 0, 0, gesture.scale);
162
+ gesture.scale = 1;
163
+ }
164
+ }
165
+ - (void)panDrawing:(UIPanGestureRecognizer *)gesture {
166
+ if (gesture.state == UIGestureRecognizerStateChanged) {
167
+ CGPoint delta = [gesture translationInView:self];
168
+ engine_drawing_transform((int32_t)_drawingId, delta.x, delta.y, 1);
169
+ [gesture setTranslation:CGPointZero inView:self];
170
+ }
171
+ }
172
+ - (void)sampleDrawing:(UITouch *)touch phase:(int32_t)phase {
173
+ CGPoint point = [touch locationInView:self];
174
+ CGFloat pressure = touch.type == UITouchTypePencil && touch.maximumPossibleForce > 0 ? touch.force / touch.maximumPossibleForce : 1;
175
+ engine_drawing_touch((int32_t)_drawingId, phase, point.x, point.y, pressure);
176
+ }
177
+ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
178
+ if (_drawingId < 0) { [super touchesBegan:touches withEvent:event]; return; }
179
+ if (_drawingMode != 0 || _drawingTouch != nil) return;
180
+ UITouch *touch = touches.anyObject;
181
+ for (UITouch *candidate in touches) if (candidate.type == UITouchTypePencil) { touch = candidate; break; }
182
+ // A Pencil is tracked independently; fingers arriving during its stroke are palm touches.
183
+ if (touch.type != UITouchTypePencil && event.allTouches.count != 1) return;
184
+ _drawingTouch = touch;
185
+ [self sampleDrawing:touch phase:0];
186
+ }
187
+ - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
188
+ if (_drawingId < 0) { [super touchesMoved:touches withEvent:event]; return; }
189
+ if (_drawingTouch == nil || ![touches containsObject:_drawingTouch]) return;
190
+ NSArray<UITouch *> *samples = [event coalescedTouchesForTouch:_drawingTouch];
191
+ if (samples.count == 0) [self sampleDrawing:_drawingTouch phase:1];
192
+ else for (UITouch *sample in samples) [self sampleDrawing:sample phase:1];
193
+ }
194
+ - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
195
+ if (_drawingId < 0) { [super touchesEnded:touches withEvent:event]; return; }
196
+ if (_drawingTouch != nil && [touches containsObject:_drawingTouch]) { [self sampleDrawing:_drawingTouch phase:2]; _drawingTouch = nil; }
197
+ }
198
+ - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
199
+ if (_drawingId < 0) { [super touchesCancelled:touches withEvent:event]; return; }
200
+ if (_drawingTouch != nil && [touches containsObject:_drawingTouch]) { engine_drawing_touch((int32_t)_drawingId, 3, 0, 0, 1); _drawingTouch = nil; }
201
+ }
202
+
203
+ @end
204
+
205
+ @interface NayanEngineSurfaceManager : RCTViewManager
206
+ @end
207
+
208
+ @implementation NayanEngineSurfaceManager
209
+
210
+ RCT_EXPORT_MODULE(NayanEngineSurface)
211
+
212
+ - (UIView *)view
213
+ {
214
+ return [NayanEngineSurfaceView new];
215
+ }
216
+
217
+ RCT_EXPORT_VIEW_PROPERTY(surfaceId, NSInteger)
218
+ RCT_EXPORT_VIEW_PROPERTY(drawingId, NSInteger)
219
+ RCT_EXPORT_VIEW_PROPERTY(drawingMode, NSInteger)
220
+ RCT_EXPORT_VIEW_PROPERTY(drawingBackground, NSInteger)
221
+ RCT_EXPORT_VIEW_PROPERTY(onDrawingChange, RCTDirectEventBlock)
222
+
223
+ @end
@@ -0,0 +1,39 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const root = resolve(fileURLToPath(new URL('../..', import.meta.url)));
6
+ const metadata = JSON.parse(await readFile(resolve(root, 'package.json'), 'utf8'));
7
+ const required = new Set([
8
+ 'README.md',
9
+ 'NayanEngine.podspec',
10
+ 'react-native.config.js',
11
+ 'src/native/spec/NativeNayanEngine.ts',
12
+ 'native/cpp/generated/NayanEngineSpecJSI.h',
13
+ 'native/core/include/engine_core.h',
14
+ 'native/core/build/EngineCore.xcframework/Info.plist',
15
+ 'native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a',
16
+ 'native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a',
17
+ 'lib/web/engine_core_bg.wasm',
18
+ 'lib/web/audio-worklet.js'
19
+ ]);
20
+ for (const abi of ['arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86']) required.add(`native/core/build/android/${abi}/libengine_core.a`);
21
+ function exportedFiles(value) {
22
+ if (typeof value === 'string') required.add(value);
23
+ else for (const item of Object.values(value)) exportedFiles(item);
24
+ }
25
+ exportedFiles(metadata.exports);
26
+ const missing = [];
27
+ for (const path of required) {
28
+ try {
29
+ const info = await stat(resolve(root, path));
30
+ if (!info.isFile() || info.size === 0) missing.push(path);
31
+ } catch {
32
+ missing.push(path);
33
+ }
34
+ }
35
+ if (missing.length)
36
+ throw new Error(
37
+ `Engine package is incomplete:\n${missing.map((path) => ` ${path}`).join('\n')}\nBuild the native core on macOS and run engine:build before packing or publishing.`
38
+ );
39
+ console.error(`Verified ${required.size} required engine package files for ${metadata.version}.`);
package/package.json CHANGED
@@ -1,6 +1,164 @@
1
1
  {
2
2
  "name": "@nayan-ui/engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-beta.3",
4
+ "description": "Fast 3D game engine for React and React Native: Rust and wgpu rendering, Rapier physics, animation, particle effects, audio, haptics and drawing.",
5
+ "keywords": [
6
+ "3d",
7
+ "android",
8
+ "drawing",
9
+ "game-engine",
10
+ "ios",
11
+ "metal",
12
+ "nayan-ui",
13
+ "particles",
14
+ "physics",
15
+ "rapier",
16
+ "react",
17
+ "react-game-engine",
18
+ "react-native",
19
+ "react-native-game-engine",
20
+ "rust",
21
+ "vulkan",
22
+ "web",
23
+ "webassembly",
24
+ "webgl",
25
+ "webgpu",
26
+ "wgpu"
27
+ ],
28
+ "homepage": "https://www.nayanui.com/engine",
29
+ "bugs": {
30
+ "url": "https://github.com/ursnj/nayan-ui/issues"
31
+ },
32
+ "license": "MIT",
33
+ "author": "Niranjan Devasani <niranjan.devasani@gmail.com> (https://github.com/ursnj)",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/ursnj/nayan-ui.git"
37
+ },
38
+ "workspaces": [
39
+ "example"
40
+ ],
41
+ "files": [
42
+ "src/native/spec",
43
+ "lib",
44
+ "native/cpp",
45
+ "native/ios",
46
+ "native/android",
47
+ "*.podspec",
48
+ "react-native.config.js",
49
+ "native/core/include",
50
+ "native/core/build",
51
+ "!native/core/build/web",
52
+ "!**/.*",
53
+ "!**/*.map",
54
+ "!src/**/__tests__",
55
+ "native/scripts/check-package.mjs"
56
+ ],
57
+ "sideEffects": false,
58
+ "main": "./lib/module/index.js",
59
+ "browser": "./lib/web/index.js",
60
+ "types": "./lib/web/types/src/index.d.ts",
61
+ "exports": {
62
+ ".": {
63
+ "react-native": {
64
+ "source": "./src/index.ts",
65
+ "types": "./lib/typescript/src/index.d.ts",
66
+ "default": "./lib/module/index.js"
67
+ },
68
+ "react-native-strict-api": {
69
+ "source": "./src/index.ts",
70
+ "types": "./lib/typescript/src/index.d.ts",
71
+ "default": "./lib/module/index.js"
72
+ },
73
+ "browser": {
74
+ "types": "./lib/web/types/src/index.d.ts",
75
+ "default": "./lib/web/index.js"
76
+ },
77
+ "source": "./src/index.ts",
78
+ "types": "./lib/web/types/src/index.d.ts",
79
+ "default": "./lib/web/index.js"
80
+ },
81
+ "./package.json": "./package.json",
82
+ "./web": {
83
+ "types": "./lib/web/types/src/index.d.ts",
84
+ "default": "./lib/web/index.js"
85
+ }
86
+ },
87
+ "publishConfig": {
88
+ "registry": "https://registry.npmjs.org/"
89
+ },
90
+ "scripts": {
91
+ "example": "bun run --cwd example",
92
+ "clean": "del-cli lib",
93
+ "build": "bun run build:web && bob build",
94
+ "typecheck": "bun check && bun check -p tsconfig.test.json",
95
+ "core:test": "cargo test --manifest-path native/core/Cargo.toml",
96
+ "core:bench": "cargo run --release --example bench --manifest-path native/core/Cargo.toml",
97
+ "core:build": "native/core/scripts/build-ios.sh && native/core/scripts/build-android.sh",
98
+ "core:build:ios": "native/core/scripts/build-ios.sh",
99
+ "core:build:android": "native/core/scripts/build-android.sh",
100
+ "test": "bun test --isolate src",
101
+ "test:coverage": "bun test --isolate --coverage src native/tests && bun native/scripts/check-coverage.mjs",
102
+ "codegen": "node native/scripts/codegen-cxx.js",
103
+ "lint": "bun lint --no-script .",
104
+ "lint:fix": "bun lint --no-script --fix .",
105
+ "core:build:web": "native/core/scripts/build-web.sh",
106
+ "build:web": "bun run core:build:web && bun native/scripts/build-web.mjs",
107
+ "test:web": "bun test native/tests/web.test.ts",
108
+ "prepack": "node native/scripts/check-package.mjs"
109
+ },
110
+ "devDependencies": {
111
+ "@types/react": "~19.3.0",
112
+ "@types/react-dom": "^19.3.0",
113
+ "bun-types": "latest",
114
+ "del-cli": "^7.0.0",
115
+ "fake-indexeddb": "^6.2.6",
116
+ "happy-dom": "^21.0.4",
117
+ "react": "19.3.0",
118
+ "react-dom": "19.3.0",
119
+ "react-native": "0.88.0",
120
+ "react-native-builder-bob": "^0.43.1",
121
+ "typescript": "~6.0.3"
122
+ },
123
+ "peerDependencies": {
124
+ "expo-asset": "*",
125
+ "react": "*",
126
+ "react-native": "*"
127
+ },
128
+ "peerDependenciesMeta": {
129
+ "expo-asset": {
130
+ "optional": true
131
+ },
132
+ "react-native": {
133
+ "optional": true
134
+ }
135
+ },
136
+ "codegenConfig": {
137
+ "name": "NayanEngineSpec",
138
+ "type": "modules",
139
+ "jsSrcsDir": "src/native",
140
+ "ios": {
141
+ "modulesProvider": {
142
+ "NativeNayanEngine": "NayanEngineProvider"
143
+ }
144
+ }
145
+ },
146
+ "react-native-builder-bob": {
147
+ "source": "src",
148
+ "output": "lib",
149
+ "targets": [
150
+ [
151
+ "module",
152
+ {
153
+ "esm": true
154
+ }
155
+ ],
156
+ [
157
+ "typescript",
158
+ {
159
+ "project": "tsconfig.build.json"
160
+ }
161
+ ]
162
+ ]
163
+ }
164
+ }
@@ -0,0 +1,18 @@
1
+ // Autolinking. iOS uses NayanEngine.podspec; Android builds native/android/CMakeLists.txt into the app as a
2
+ // pure C++ TurboModule (the generated autolinking code instantiates NayanEngineModule).
3
+ module.exports = {
4
+ dependency: {
5
+ platforms: {
6
+ android: {
7
+ sourceDir: 'native/android',
8
+ // The EngineSurface view (native/android/src/main/java).
9
+ packageImportPath: 'import com.nayanui.engine.NayanEnginePackage;',
10
+ packageInstance: 'new NayanEnginePackage()',
11
+ cmakeListsPath: 'codegen/CMakeLists.txt',
12
+ cxxModuleCMakeListsModuleName: 'NayanEngine',
13
+ cxxModuleCMakeListsPath: 'CMakeLists.txt',
14
+ cxxModuleHeaderName: 'NayanEngineModule'
15
+ }
16
+ }
17
+ }
18
+ };