lupine.native.core 0.0.0-stage → 1.0.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 (284) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/apple/apple_host.h +136 -0
  4. package/apple/apple_host.mm +887 -0
  5. package/apple/camera.mm +287 -0
  6. package/apple/device.cmake +13 -0
  7. package/apple/device.mm +279 -0
  8. package/apple/geolocation.mm +81 -0
  9. package/apple/gl_view.mm +227 -0
  10. package/apple/module.h +63 -0
  11. package/apple/notifications.mm +90 -0
  12. package/apple/picture.mm +95 -0
  13. package/apple/text.mm +86 -0
  14. package/apple/web_storage.mm +58 -0
  15. package/apple/websocket.mm +81 -0
  16. package/bin/bundle.js +79 -0
  17. package/bin/deps.js +201 -0
  18. package/bin/docker.js +31 -0
  19. package/bin/doctor.js +148 -0
  20. package/bin/hermes.js +169 -0
  21. package/bin/icons.js +188 -0
  22. package/bin/lupine-native.js +376 -0
  23. package/bin/plugins.js +196 -0
  24. package/bin/png.js +164 -0
  25. package/bin/png.test.js +137 -0
  26. package/bin/test.js +242 -0
  27. package/bin/wine.js +40 -0
  28. package/cpp/CMakeLists.txt +56 -0
  29. package/cpp/hermes/PlatformUnicodeLite.cpp +45 -0
  30. package/cpp/hermes/unicode.h +17 -0
  31. package/cpp/lupine/audio.cpp +1399 -0
  32. package/cpp/lupine/engine.h +51 -0
  33. package/cpp/lupine/engine_jsi.cpp +176 -0
  34. package/cpp/lupine/engine_napi.cpp +269 -0
  35. package/cpp/lupine/engine_quickjs.cpp +323 -0
  36. package/cpp/lupine/files.cpp +132 -0
  37. package/cpp/lupine/gl.cpp +1027 -0
  38. package/cpp/lupine/gl.h +95 -0
  39. package/cpp/lupine/gl_api.h +149 -0
  40. package/cpp/lupine/host.h +105 -0
  41. package/cpp/lupine/miniaudio.c +8 -0
  42. package/cpp/lupine/modules.h +126 -0
  43. package/cpp/lupine/no_app_modules.cpp +3 -0
  44. package/cpp/lupine/no_plugins.cpp +3 -0
  45. package/cpp/lupine/path.h +33 -0
  46. package/cpp/lupine/process.cpp +375 -0
  47. package/cpp/lupine/runtime.cpp +684 -0
  48. package/cpp/lupine/runtime.h +90 -0
  49. package/cpp/lupine/value.h +43 -0
  50. package/cpp/qjsbc/CMakeLists.txt +6 -0
  51. package/cpp/qjsbc/main.c +29 -0
  52. package/cpp/quickjs/CMakeLists.txt +12 -0
  53. package/cpp/quickjs/slices.c +167 -0
  54. package/cpp/quickjs/slices.h +16 -0
  55. package/cpp/third_party/LICENSE +21 -0
  56. package/cpp/third_party/README.md +8 -0
  57. package/cpp/third_party/miniaudio/miniaudio.h +93468 -0
  58. package/cpp/third_party/yoga/yoga/CMakeLists.txt +41 -0
  59. package/cpp/third_party/yoga/yoga/YGConfig.cpp +92 -0
  60. package/cpp/third_party/yoga/yoga/YGConfig.h +158 -0
  61. package/cpp/third_party/yoga/yoga/YGEnums.cpp +302 -0
  62. package/cpp/third_party/yoga/yoga/YGEnums.h +162 -0
  63. package/cpp/third_party/yoga/yoga/YGMacros.h +101 -0
  64. package/cpp/third_party/yoga/yoga/YGNode.cpp +407 -0
  65. package/cpp/third_party/yoga/yoga/YGNode.h +373 -0
  66. package/cpp/third_party/yoga/yoga/YGNodeLayout.cpp +100 -0
  67. package/cpp/third_party/yoga/yoga/YGNodeLayout.h +43 -0
  68. package/cpp/third_party/yoga/yoga/YGNodeStyle.cpp +774 -0
  69. package/cpp/third_party/yoga/yoga/YGNodeStyle.h +243 -0
  70. package/cpp/third_party/yoga/yoga/YGPixelGrid.cpp +22 -0
  71. package/cpp/third_party/yoga/yoga/YGPixelGrid.h +29 -0
  72. package/cpp/third_party/yoga/yoga/YGValue.cpp +20 -0
  73. package/cpp/third_party/yoga/yoga/YGValue.h +83 -0
  74. package/cpp/third_party/yoga/yoga/Yoga.h +21 -0
  75. package/cpp/third_party/yoga/yoga/algorithm/AbsoluteLayout.cpp +595 -0
  76. package/cpp/third_party/yoga/yoga/algorithm/AbsoluteLayout.h +41 -0
  77. package/cpp/third_party/yoga/yoga/algorithm/Align.h +83 -0
  78. package/cpp/third_party/yoga/yoga/algorithm/Baseline.cpp +78 -0
  79. package/cpp/third_party/yoga/yoga/algorithm/Baseline.h +21 -0
  80. package/cpp/third_party/yoga/yoga/algorithm/BoundAxis.h +79 -0
  81. package/cpp/third_party/yoga/yoga/algorithm/Cache.cpp +121 -0
  82. package/cpp/third_party/yoga/yoga/algorithm/Cache.h +30 -0
  83. package/cpp/third_party/yoga/yoga/algorithm/CalculateLayout.cpp +2948 -0
  84. package/cpp/third_party/yoga/yoga/algorithm/CalculateLayout.h +60 -0
  85. package/cpp/third_party/yoga/yoga/algorithm/FlexDirection.h +120 -0
  86. package/cpp/third_party/yoga/yoga/algorithm/FlexLine.cpp +124 -0
  87. package/cpp/third_party/yoga/yoga/algorithm/FlexLine.h +75 -0
  88. package/cpp/third_party/yoga/yoga/algorithm/PixelGrid.cpp +168 -0
  89. package/cpp/third_party/yoga/yoga/algorithm/PixelGrid.h +29 -0
  90. package/cpp/third_party/yoga/yoga/algorithm/SizingMode.h +73 -0
  91. package/cpp/third_party/yoga/yoga/algorithm/TrailingPosition.h +44 -0
  92. package/cpp/third_party/yoga/yoga/config/Config.cpp +135 -0
  93. package/cpp/third_party/yoga/yoga/config/Config.h +92 -0
  94. package/cpp/third_party/yoga/yoga/debug/AssertFatal.cpp +54 -0
  95. package/cpp/third_party/yoga/yoga/debug/AssertFatal.h +29 -0
  96. package/cpp/third_party/yoga/yoga/debug/Log.cpp +107 -0
  97. package/cpp/third_party/yoga/yoga/debug/Log.h +34 -0
  98. package/cpp/third_party/yoga/yoga/enums/Align.h +49 -0
  99. package/cpp/third_party/yoga/yoga/enums/BoxSizing.h +40 -0
  100. package/cpp/third_party/yoga/yoga/enums/Dimension.h +40 -0
  101. package/cpp/third_party/yoga/yoga/enums/Direction.h +41 -0
  102. package/cpp/third_party/yoga/yoga/enums/Display.h +42 -0
  103. package/cpp/third_party/yoga/yoga/enums/Edge.h +47 -0
  104. package/cpp/third_party/yoga/yoga/enums/Errata.h +42 -0
  105. package/cpp/third_party/yoga/yoga/enums/ExperimentalFeature.h +40 -0
  106. package/cpp/third_party/yoga/yoga/enums/FlexDirection.h +42 -0
  107. package/cpp/third_party/yoga/yoga/enums/GridTrackType.h +43 -0
  108. package/cpp/third_party/yoga/yoga/enums/Gutter.h +41 -0
  109. package/cpp/third_party/yoga/yoga/enums/Justify.h +48 -0
  110. package/cpp/third_party/yoga/yoga/enums/LogLevel.h +44 -0
  111. package/cpp/third_party/yoga/yoga/enums/MeasureMode.h +41 -0
  112. package/cpp/third_party/yoga/yoga/enums/NodeType.h +40 -0
  113. package/cpp/third_party/yoga/yoga/enums/Overflow.h +41 -0
  114. package/cpp/third_party/yoga/yoga/enums/PhysicalEdge.h +21 -0
  115. package/cpp/third_party/yoga/yoga/enums/PositionType.h +41 -0
  116. package/cpp/third_party/yoga/yoga/enums/Unit.h +45 -0
  117. package/cpp/third_party/yoga/yoga/enums/Wrap.h +41 -0
  118. package/cpp/third_party/yoga/yoga/enums/YogaEnums.h +84 -0
  119. package/cpp/third_party/yoga/yoga/event/event.cpp +89 -0
  120. package/cpp/third_party/yoga/yoga/event/event.h +131 -0
  121. package/cpp/third_party/yoga/yoga/module.modulemap +21 -0
  122. package/cpp/third_party/yoga/yoga/node/CachedMeasurement.h +53 -0
  123. package/cpp/third_party/yoga/yoga/node/LayoutResults.cpp +48 -0
  124. package/cpp/third_party/yoga/yoga/node/LayoutResults.h +136 -0
  125. package/cpp/third_party/yoga/yoga/node/LayoutableChildren.h +148 -0
  126. package/cpp/third_party/yoga/yoga/node/Node.cpp +509 -0
  127. package/cpp/third_party/yoga/yoga/node/Node.h +372 -0
  128. package/cpp/third_party/yoga/yoga/numeric/Comparison.h +81 -0
  129. package/cpp/third_party/yoga/yoga/numeric/FloatOptional.h +84 -0
  130. package/cpp/third_party/yoga/yoga/style/GridLine.h +53 -0
  131. package/cpp/third_party/yoga/yoga/style/GridStyle.h +80 -0
  132. package/cpp/third_party/yoga/yoga/style/GridTrack.h +63 -0
  133. package/cpp/third_party/yoga/yoga/style/SmallValueBuffer.h +133 -0
  134. package/cpp/third_party/yoga/yoga/style/Style.h +932 -0
  135. package/cpp/third_party/yoga/yoga/style/StyleLength.h +121 -0
  136. package/cpp/third_party/yoga/yoga/style/StyleSizeLength.h +152 -0
  137. package/cpp/third_party/yoga/yoga/style/StyleValueHandle.h +114 -0
  138. package/cpp/third_party/yoga/yoga/style/StyleValuePool.h +194 -0
  139. package/docker/Dockerfile +19 -0
  140. package/docker/entry.sh +12 -0
  141. package/package.json +47 -4
  142. package/shells/android/app/build.gradle.kts +118 -0
  143. package/shells/android/app/src/main/AndroidManifest.xml +40 -0
  144. package/shells/android/app/src/main/cpp/CMakeLists.txt +24 -0
  145. package/shells/android/app/src/main/cpp/android_gl.cpp +125 -0
  146. package/shells/android/app/src/main/cpp/android_host.cpp +448 -0
  147. package/shells/android/app/src/main/cpp/android_unicode.cpp +67 -0
  148. package/shells/android/app/src/main/java/com/uuware/lupine/Barcodes.kt +43 -0
  149. package/shells/android/app/src/main/java/com/uuware/lupine/Box.kt +98 -0
  150. package/shells/android/app/src/main/java/com/uuware/lupine/Builtin.kt +4 -0
  151. package/shells/android/app/src/main/java/com/uuware/lupine/Camera.kt +343 -0
  152. package/shells/android/app/src/main/java/com/uuware/lupine/Device.kt +286 -0
  153. package/shells/android/app/src/main/java/com/uuware/lupine/Drawing.kt +364 -0
  154. package/shells/android/app/src/main/java/com/uuware/lupine/GLView.kt +71 -0
  155. package/shells/android/app/src/main/java/com/uuware/lupine/Geolocation.kt +84 -0
  156. package/shells/android/app/src/main/java/com/uuware/lupine/Input.kt +85 -0
  157. package/shells/android/app/src/main/java/com/uuware/lupine/Keys.kt +18 -0
  158. package/shells/android/app/src/main/java/com/uuware/lupine/Look.kt +170 -0
  159. package/shells/android/app/src/main/java/com/uuware/lupine/LupineHost.kt +810 -0
  160. package/shells/android/app/src/main/java/com/uuware/lupine/MainActivity.kt +152 -0
  161. package/shells/android/app/src/main/java/com/uuware/lupine/Module.kt +52 -0
  162. package/shells/android/app/src/main/java/com/uuware/lupine/Notifications.kt +103 -0
  163. package/shells/android/app/src/main/java/com/uuware/lupine/Picture.kt +119 -0
  164. package/shells/android/app/src/main/java/com/uuware/lupine/Services.kt +324 -0
  165. package/shells/android/app/src/main/java/com/uuware/lupine/Snap.kt +72 -0
  166. package/shells/android/app/src/main/java/com/uuware/lupine/TextLook.kt +180 -0
  167. package/shells/android/app/src/main/java/com/uuware/lupine/Views.kt +343 -0
  168. package/shells/android/app/src/main/java/com/uuware/lupine/WebSocket.kt +221 -0
  169. package/shells/android/app/src/main/java/com/uuware/lupine/WebStorage.kt +48 -0
  170. package/shells/android/app/src/main/res/drawable/notification.xml +3 -0
  171. package/shells/android/app/src/main/res/values/styles.xml +7 -0
  172. package/shells/android/app/src/main/res/values-night/styles.xml +3 -0
  173. package/shells/android/app/src/main/res/xml/files.xml +5 -0
  174. package/shells/android/app/src/prebuilt/java/com/uuware/lupine/Hermes.kt +11 -0
  175. package/shells/android/app/src/static/java/com/uuware/lupine/Hermes.kt +30 -0
  176. package/shells/android/build.gradle.kts +4 -0
  177. package/shells/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  178. package/shells/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  179. package/shells/android/gradle.properties +2 -0
  180. package/shells/android/gradlew +248 -0
  181. package/shells/android/gradlew.bat +98 -0
  182. package/shells/android/settings.gradle.kts +15 -0
  183. package/shells/ios/CMakeLists.txt +83 -0
  184. package/shells/ios/Info.plist.in +20 -0
  185. package/shells/ios/src/host.h +87 -0
  186. package/shells/ios/src/host.mm +1214 -0
  187. package/shells/ios/src/main.mm +155 -0
  188. package/shells/macos/CMakeLists.txt +82 -0
  189. package/shells/macos/Info.plist.in +21 -0
  190. package/shells/macos/src/desktop.mm +63 -0
  191. package/shells/macos/src/host.h +93 -0
  192. package/shells/macos/src/host.mm +1313 -0
  193. package/shells/macos/src/main.mm +148 -0
  194. package/shells/web/src/add-worker.ts +31 -0
  195. package/shells/web/src/css.ts +89 -0
  196. package/shells/web/src/device.ts +257 -0
  197. package/shells/web/src/dom-host.ts +433 -0
  198. package/shells/web/src/gl.ts +20 -0
  199. package/shells/web/src/index.ts +89 -0
  200. package/shells/web/src/picture.ts +28 -0
  201. package/shells/web/src/server.test.tsx +66 -0
  202. package/shells/web/src/server.ts +104 -0
  203. package/shells/web/src/services.ts +264 -0
  204. package/shells/web/src/web-storage.ts +4 -0
  205. package/shells/web/src/worker.ts +15 -0
  206. package/shells/web/tsconfig.json +16 -0
  207. package/shells/windows/CMakeLists.txt +90 -0
  208. package/shells/windows/mingw.cmake +11 -0
  209. package/shells/windows/src/app.manifest +13 -0
  210. package/shells/windows/src/app.rc +1 -0
  211. package/shells/windows/src/camera.cpp +327 -0
  212. package/shells/windows/src/desktop.cpp +103 -0
  213. package/shells/windows/src/device.cpp +205 -0
  214. package/shells/windows/src/device.h +59 -0
  215. package/shells/windows/src/drawing.cpp +285 -0
  216. package/shells/windows/src/drawing.h +47 -0
  217. package/shells/windows/src/embedded.cpp +304 -0
  218. package/shells/windows/src/embedded.h +29 -0
  219. package/shells/windows/src/geolocation.cpp +96 -0
  220. package/shells/windows/src/gl_view.cpp +214 -0
  221. package/shells/windows/src/gpu.cpp +423 -0
  222. package/shells/windows/src/gpu.h +87 -0
  223. package/shells/windows/src/host.cpp +954 -0
  224. package/shells/windows/src/host.h +197 -0
  225. package/shells/windows/src/input.cpp +707 -0
  226. package/shells/windows/src/main.cpp +215 -0
  227. package/shells/windows/src/module_view.h +35 -0
  228. package/shells/windows/src/notifications.cpp +159 -0
  229. package/shells/windows/src/pack.cpp +48 -0
  230. package/shells/windows/src/pack.h +16 -0
  231. package/shells/windows/src/paint.cpp +471 -0
  232. package/shells/windows/src/painter.cpp +792 -0
  233. package/shells/windows/src/painter.h +187 -0
  234. package/shells/windows/src/picture.cpp +83 -0
  235. package/shells/windows/src/selection.cpp +99 -0
  236. package/shells/windows/src/services.cpp +228 -0
  237. package/shells/windows/src/services.h +30 -0
  238. package/shells/windows/src/text.cpp +520 -0
  239. package/shells/windows/src/text.h +70 -0
  240. package/shells/windows/src/unicode.cpp +68 -0
  241. package/shells/windows/src/view.h +140 -0
  242. package/shells/windows/src/websocket.cpp +193 -0
  243. package/shells/windows/src/websocket.h +14 -0
  244. package/src/animation.test.tsx +195 -0
  245. package/src/animation.ts +290 -0
  246. package/src/api.ts +94 -0
  247. package/src/app-services.ts +108 -0
  248. package/src/audio.ts +355 -0
  249. package/src/canvas.test.tsx +212 -0
  250. package/src/canvas.ts +628 -0
  251. package/src/color.ts +42 -0
  252. package/src/components.ts +247 -0
  253. package/src/control-flow.ts +22 -0
  254. package/src/desktop.ts +29 -0
  255. package/src/device.test.tsx +128 -0
  256. package/src/device.ts +309 -0
  257. package/src/features.test.tsx +149 -0
  258. package/src/fonts.ts +16 -0
  259. package/src/gestures.ts +120 -0
  260. package/src/gl-constants.ts +81 -0
  261. package/src/gl.ts +508 -0
  262. package/src/globals.d.ts +124 -0
  263. package/src/host.ts +26 -0
  264. package/src/index.ts +35 -0
  265. package/src/jsx.ts +25 -0
  266. package/src/list.ts +55 -0
  267. package/src/native-globals.d.ts +43 -0
  268. package/src/native.ts +221 -0
  269. package/src/picture.ts +27 -0
  270. package/src/platform.ts +11 -0
  271. package/src/polyfills.ts +355 -0
  272. package/src/process.ts +59 -0
  273. package/src/refresh.ts +32 -0
  274. package/src/render.test.tsx +266 -0
  275. package/src/render.ts +363 -0
  276. package/src/style.ts +94 -0
  277. package/src/svg-draw.ts +306 -0
  278. package/src/svg.test.tsx +31 -0
  279. package/src/svg.ts +149 -0
  280. package/src/test-host.ts +57 -0
  281. package/src/three.ts +11 -0
  282. package/src/web-storage.ts +10 -0
  283. package/src/websocket.ts +100 -0
  284. package/tsconfig.json +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 uuware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # lupine.native.core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Native apps for **iOS, Android, macOS and Windows**, and the same app as a web page, from one TSX code base with the signals of [lupine.core](https://www.npmjs.com/package/lupine.core). The controls are those of each platform (UIKit, AppKit, Android views; Direct2D and DirectWrite on Windows; the DOM on the web); no virtual DOM, no web view, no compiler of its own.
4
+
5
+ ```tsx
6
+ import { Button, createSignal, Text, View } from 'lupine.native.core';
7
+ import { runApp } from 'lupine.native.core/native'; // on the web: 'lupine.native.core/web'
8
+
9
+ const App = () => {
10
+ const [count, setCount] = createSignal(0);
11
+ return (
12
+ <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12 }}>
13
+ <Text style={{ fontSize: 24 }}>{() => `count: ${count()}`}</Text>
14
+ <Button title='Add' onPress={() => setCount(count() + 1)} />
15
+ </View>
16
+ );
17
+ };
18
+
19
+ runApp(App);
20
+ ```
21
+
22
+ ```bash
23
+ npx lupine-native doctor # what is missing on this computer
24
+ npx lupine-native ios --app=. --run # also: android, macos, windows, web
25
+ npx lupine-native test macos --app=. # the app's own tests on a platform
26
+ npx lupine-native docker android --app=. # Android and Windows without installing their tools
27
+ ```
28
+
29
+ - **Standard components**: View, ScrollView, List, Text, TextInput, Button, Switch, Slider, Image, Canvas (2D), GL (WebGL 2, three.js as it is), Video, Camera, WebView; flexbox layout (Yoga), gestures, animations.
30
+ - **Platform functions**: files, fetch and WebSocket, Web Audio with low latency, the microphone, notifications, location, biometrics, sharing, the clipboard, windows and menus on desktops.
31
+ - **The engine is part of the program**: Hermes is built from source and linked in, the app is bytecode. A release build is 4 to 6 MB. QuickJS: `--engine=quickjs`.
32
+ - **JavaScript runs on the UI thread**: an event, what it changes and one layout are one step.
33
+
34
+ Components: [lupine.native.components](https://www.npmjs.com/package/lupine.native.components). SDKs: [lupine.native.plugins](https://www.npmjs.com/package/lupine.native.plugins). Documentation: https://uuware.github.io/lupine.js/en/native/overview
35
+
36
+ MIT. Part of [lupine.js](https://github.com/uuware/lupine.js).
@@ -0,0 +1,136 @@
1
+ // What iOS and macOS have in common: drawing with Core Graphics, images, network, storage.
2
+ #pragma once
3
+ #import <CoreGraphics/CoreGraphics.h>
4
+ #import <Foundation/Foundation.h>
5
+ #import <TargetConditionals.h>
6
+ #if TARGET_OS_OSX
7
+ #import <AppKit/AppKit.h>
8
+ #define LNFont NSFont
9
+ #define LNColor NSColor
10
+ #else
11
+ #import <UIKit/UIKit.h>
12
+ #define LNFont UIFont
13
+ #define LNColor UIColor
14
+ #endif
15
+
16
+ #import "module.h"
17
+
18
+ #include <lupine/host.h>
19
+ #include <lupine/runtime.h>
20
+
21
+ #include <string>
22
+ #include <unordered_map>
23
+ #include <vector>
24
+
25
+ @class AVPlayerItem;
26
+ // Tells when a video can be played (its size) or not (the error), as long as it lives.
27
+ @interface LNItemWatch : NSObject
28
+ - (instancetype)initWithItem:(AVPlayerItem*)item done:(void (^)(CGSize size, NSString* error))done;
29
+ @end
30
+
31
+ namespace lupine {
32
+
33
+ NSString* toNS(const Value& v);
34
+ std::string fromNS(NSString* s);
35
+ LNColor* toColor(const Value& v); // nil if it isn't a color
36
+ LNFont* makeFont(const std::string& family, double size, int weight, bool italic);
37
+ // fonts that the app has loaded; returns what is wrong, or nil
38
+ NSString* addFont(NSString* family, NSData* data);
39
+ LNFont* ownFont(const std::string& family, double size); // nil: none of them
40
+ int parseWeight(const std::string& weight);
41
+
42
+ struct GradientSpec {
43
+ double angle = 180; // degrees, as in CSS
44
+ std::vector<LNColor*> colors;
45
+ std::vector<double> stops;
46
+ };
47
+ bool parseGradient(const std::string& css, GradientSpec& out);
48
+ struct ShadowSpec {
49
+ double x = 0, y = 0, blur = 0;
50
+ LNColor* color = nil;
51
+ };
52
+ NSArray* contentTypes(const std::string& mimeTypes); // of UTType, all files if empty
53
+ bool parseShadow(const std::string& css, ShadowSpec& out);
54
+ // text with parts of different looks, see toSpans in src/components.ts
55
+ extern NSString* const kSpanAttribute; // NSNumber: the id of a part that can be pressed
56
+ extern NSString* const kBackAttribute; // the background of a part, for paintBacks
57
+ void paintBacks(NSAttributedString* text, CGSize size, int lines, CGPoint origin);
58
+ // the id of the part at a point of a text with this size, -1: none; lines 0: any number
59
+ int spanAt(NSAttributedString* text, CGSize size, int lines, CGPoint point);
60
+ NSAttributedString* parseSpans(const std::string& spans, LNFont* font, LNColor* color, const std::string& family, double size, int weight, bool italic);
61
+
62
+ // everything that decides how a text looks
63
+ struct TextLook {
64
+ std::string text, spans, family, align, decoration;
65
+ double size = 14, lineHeight = 0, letterSpacing = 0;
66
+ int weight = 400, lines = 0;
67
+ bool italic = false;
68
+ LNColor* color = nil;
69
+ LNFont* font() const { return makeFont(family, size, weight, italic); }
70
+ NSAttributedString* attributed() const;
71
+ // true if the property is one of these
72
+ bool set(const std::string& name, const Value& value);
73
+ };
74
+
75
+ // The commands of src/canvas.ts. The context has its origin at the top left.
76
+ struct Drawing {
77
+ std::vector<float> data;
78
+ NSArray<NSString*>* texts = @[];
79
+ bool layer = false; // clearing and blending must not reach what is behind the canvas
80
+ static Drawing make(const Bytes& bytes, const std::string& texts);
81
+ };
82
+ void paint(CGContextRef context, const Drawing& drawing);
83
+
84
+ // between Value and the objects of modules
85
+ id toObject(const Value& v);
86
+ Value fromObject(id o);
87
+
88
+ class AppleHost : public Host {
89
+ public:
90
+ AppleHost();
91
+ void attach(Runtime* runtime) { runtime_ = runtime; }
92
+ Runtime* runtime() const { return runtime_; }
93
+ // the app has started; a link for a module
94
+ void startModules();
95
+ bool openUrl(NSURL* url);
96
+ bool continueActivity(NSUserActivity* activity);
97
+ virtual LNPlatformController* controllerForModules() = 0;
98
+
99
+ Value callSync(const std::string& name, const Args& args) override;
100
+ void call(int call, const std::string& name, const Args& args) override;
101
+ void post(std::function<void()> task) override;
102
+ std::string directory(const std::string& kind) override;
103
+ bool decodeSound(const std::string& file, Sound& sound) override;
104
+ bool readAsset(const std::string& name, std::vector<uint8_t>& data) override;
105
+ std::shared_ptr<const uint8_t> mapAsset(const std::string& name, size_t& size) override;
106
+ void setTimer(int timer, double ms) override;
107
+ std::string language() override;
108
+ Value getItem(const std::string& key) override;
109
+ void setItem(const std::string& key, const Value& value) override;
110
+ void log(int level, const std::string& message) override;
111
+
112
+ // an Image component: answers with the picture (cached) or nil; on the main thread. headers: "Name: value" lines
113
+ static void loadImage(NSString* src, NSString* headers, void (^done)(CGImageRef image, NSString* error));
114
+ static NSDictionary<NSString*, NSString*>* parseHeaders(NSString* lines);
115
+
116
+ protected:
117
+ // platform functions that differ; false: no such function
118
+ virtual bool callPlatform(int call, const std::string& name, const Args& args) = 0;
119
+ virtual CGPoint positionInWindow(int node) = 0;
120
+ // a view of a module, or nil
121
+ LNPlatformView<LNModuleView>* moduleView(int node, const std::string& type);
122
+ void answer(int call, bool ok, Value value) {
123
+ if (runtime_) runtime_->answer(call, ok, value);
124
+ }
125
+ void emit(int node, const char* event, Value payload) {
126
+ if (runtime_) runtime_->dispatchEvent(node, event, payload);
127
+ }
128
+ Runtime* runtime_ = nullptr;
129
+
130
+ private:
131
+ void fetch(int call, const Args& args);
132
+ id<LNModuleHost> bridge_;
133
+ NSMutableDictionary<NSString*, LNModule*>* modules_; // by area
134
+ };
135
+
136
+ } // namespace lupine