lupine.native.core 0.0.0-stage → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/apple/apple_host.h +136 -0
- package/apple/apple_host.mm +887 -0
- package/apple/camera.mm +287 -0
- package/apple/device.cmake +13 -0
- package/apple/device.mm +279 -0
- package/apple/geolocation.mm +81 -0
- package/apple/gl_view.mm +227 -0
- package/apple/module.h +63 -0
- package/apple/notifications.mm +90 -0
- package/apple/picture.mm +95 -0
- package/apple/text.mm +86 -0
- package/apple/web_storage.mm +58 -0
- package/apple/websocket.mm +81 -0
- package/bin/bundle.js +79 -0
- package/bin/deps.js +201 -0
- package/bin/docker.js +31 -0
- package/bin/doctor.js +148 -0
- package/bin/hermes.js +169 -0
- package/bin/icons.js +188 -0
- package/bin/lupine-native.js +376 -0
- package/bin/plugins.js +196 -0
- package/bin/png.js +164 -0
- package/bin/png.test.js +137 -0
- package/bin/test.js +242 -0
- package/bin/wine.js +40 -0
- package/cpp/CMakeLists.txt +56 -0
- package/cpp/hermes/PlatformUnicodeLite.cpp +45 -0
- package/cpp/hermes/unicode.h +17 -0
- package/cpp/lupine/audio.cpp +1399 -0
- package/cpp/lupine/engine.h +51 -0
- package/cpp/lupine/engine_jsi.cpp +176 -0
- package/cpp/lupine/engine_napi.cpp +269 -0
- package/cpp/lupine/engine_quickjs.cpp +323 -0
- package/cpp/lupine/files.cpp +132 -0
- package/cpp/lupine/gl.cpp +1027 -0
- package/cpp/lupine/gl.h +95 -0
- package/cpp/lupine/gl_api.h +149 -0
- package/cpp/lupine/host.h +105 -0
- package/cpp/lupine/miniaudio.c +8 -0
- package/cpp/lupine/modules.h +126 -0
- package/cpp/lupine/no_app_modules.cpp +3 -0
- package/cpp/lupine/no_plugins.cpp +3 -0
- package/cpp/lupine/path.h +33 -0
- package/cpp/lupine/process.cpp +375 -0
- package/cpp/lupine/runtime.cpp +684 -0
- package/cpp/lupine/runtime.h +90 -0
- package/cpp/lupine/value.h +43 -0
- package/cpp/qjsbc/CMakeLists.txt +6 -0
- package/cpp/qjsbc/main.c +29 -0
- package/cpp/quickjs/CMakeLists.txt +12 -0
- package/cpp/quickjs/slices.c +167 -0
- package/cpp/quickjs/slices.h +16 -0
- package/cpp/third_party/LICENSE +21 -0
- package/cpp/third_party/README.md +8 -0
- package/cpp/third_party/miniaudio/miniaudio.h +93468 -0
- package/cpp/third_party/yoga/yoga/CMakeLists.txt +41 -0
- package/cpp/third_party/yoga/yoga/YGConfig.cpp +92 -0
- package/cpp/third_party/yoga/yoga/YGConfig.h +158 -0
- package/cpp/third_party/yoga/yoga/YGEnums.cpp +302 -0
- package/cpp/third_party/yoga/yoga/YGEnums.h +162 -0
- package/cpp/third_party/yoga/yoga/YGMacros.h +101 -0
- package/cpp/third_party/yoga/yoga/YGNode.cpp +407 -0
- package/cpp/third_party/yoga/yoga/YGNode.h +373 -0
- package/cpp/third_party/yoga/yoga/YGNodeLayout.cpp +100 -0
- package/cpp/third_party/yoga/yoga/YGNodeLayout.h +43 -0
- package/cpp/third_party/yoga/yoga/YGNodeStyle.cpp +774 -0
- package/cpp/third_party/yoga/yoga/YGNodeStyle.h +243 -0
- package/cpp/third_party/yoga/yoga/YGPixelGrid.cpp +22 -0
- package/cpp/third_party/yoga/yoga/YGPixelGrid.h +29 -0
- package/cpp/third_party/yoga/yoga/YGValue.cpp +20 -0
- package/cpp/third_party/yoga/yoga/YGValue.h +83 -0
- package/cpp/third_party/yoga/yoga/Yoga.h +21 -0
- package/cpp/third_party/yoga/yoga/algorithm/AbsoluteLayout.cpp +595 -0
- package/cpp/third_party/yoga/yoga/algorithm/AbsoluteLayout.h +41 -0
- package/cpp/third_party/yoga/yoga/algorithm/Align.h +83 -0
- package/cpp/third_party/yoga/yoga/algorithm/Baseline.cpp +78 -0
- package/cpp/third_party/yoga/yoga/algorithm/Baseline.h +21 -0
- package/cpp/third_party/yoga/yoga/algorithm/BoundAxis.h +79 -0
- package/cpp/third_party/yoga/yoga/algorithm/Cache.cpp +121 -0
- package/cpp/third_party/yoga/yoga/algorithm/Cache.h +30 -0
- package/cpp/third_party/yoga/yoga/algorithm/CalculateLayout.cpp +2948 -0
- package/cpp/third_party/yoga/yoga/algorithm/CalculateLayout.h +60 -0
- package/cpp/third_party/yoga/yoga/algorithm/FlexDirection.h +120 -0
- package/cpp/third_party/yoga/yoga/algorithm/FlexLine.cpp +124 -0
- package/cpp/third_party/yoga/yoga/algorithm/FlexLine.h +75 -0
- package/cpp/third_party/yoga/yoga/algorithm/PixelGrid.cpp +168 -0
- package/cpp/third_party/yoga/yoga/algorithm/PixelGrid.h +29 -0
- package/cpp/third_party/yoga/yoga/algorithm/SizingMode.h +73 -0
- package/cpp/third_party/yoga/yoga/algorithm/TrailingPosition.h +44 -0
- package/cpp/third_party/yoga/yoga/config/Config.cpp +135 -0
- package/cpp/third_party/yoga/yoga/config/Config.h +92 -0
- package/cpp/third_party/yoga/yoga/debug/AssertFatal.cpp +54 -0
- package/cpp/third_party/yoga/yoga/debug/AssertFatal.h +29 -0
- package/cpp/third_party/yoga/yoga/debug/Log.cpp +107 -0
- package/cpp/third_party/yoga/yoga/debug/Log.h +34 -0
- package/cpp/third_party/yoga/yoga/enums/Align.h +49 -0
- package/cpp/third_party/yoga/yoga/enums/BoxSizing.h +40 -0
- package/cpp/third_party/yoga/yoga/enums/Dimension.h +40 -0
- package/cpp/third_party/yoga/yoga/enums/Direction.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/Display.h +42 -0
- package/cpp/third_party/yoga/yoga/enums/Edge.h +47 -0
- package/cpp/third_party/yoga/yoga/enums/Errata.h +42 -0
- package/cpp/third_party/yoga/yoga/enums/ExperimentalFeature.h +40 -0
- package/cpp/third_party/yoga/yoga/enums/FlexDirection.h +42 -0
- package/cpp/third_party/yoga/yoga/enums/GridTrackType.h +43 -0
- package/cpp/third_party/yoga/yoga/enums/Gutter.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/Justify.h +48 -0
- package/cpp/third_party/yoga/yoga/enums/LogLevel.h +44 -0
- package/cpp/third_party/yoga/yoga/enums/MeasureMode.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/NodeType.h +40 -0
- package/cpp/third_party/yoga/yoga/enums/Overflow.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/PhysicalEdge.h +21 -0
- package/cpp/third_party/yoga/yoga/enums/PositionType.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/Unit.h +45 -0
- package/cpp/third_party/yoga/yoga/enums/Wrap.h +41 -0
- package/cpp/third_party/yoga/yoga/enums/YogaEnums.h +84 -0
- package/cpp/third_party/yoga/yoga/event/event.cpp +89 -0
- package/cpp/third_party/yoga/yoga/event/event.h +131 -0
- package/cpp/third_party/yoga/yoga/module.modulemap +21 -0
- package/cpp/third_party/yoga/yoga/node/CachedMeasurement.h +53 -0
- package/cpp/third_party/yoga/yoga/node/LayoutResults.cpp +48 -0
- package/cpp/third_party/yoga/yoga/node/LayoutResults.h +136 -0
- package/cpp/third_party/yoga/yoga/node/LayoutableChildren.h +148 -0
- package/cpp/third_party/yoga/yoga/node/Node.cpp +509 -0
- package/cpp/third_party/yoga/yoga/node/Node.h +372 -0
- package/cpp/third_party/yoga/yoga/numeric/Comparison.h +81 -0
- package/cpp/third_party/yoga/yoga/numeric/FloatOptional.h +84 -0
- package/cpp/third_party/yoga/yoga/style/GridLine.h +53 -0
- package/cpp/third_party/yoga/yoga/style/GridStyle.h +80 -0
- package/cpp/third_party/yoga/yoga/style/GridTrack.h +63 -0
- package/cpp/third_party/yoga/yoga/style/SmallValueBuffer.h +133 -0
- package/cpp/third_party/yoga/yoga/style/Style.h +932 -0
- package/cpp/third_party/yoga/yoga/style/StyleLength.h +121 -0
- package/cpp/third_party/yoga/yoga/style/StyleSizeLength.h +152 -0
- package/cpp/third_party/yoga/yoga/style/StyleValueHandle.h +114 -0
- package/cpp/third_party/yoga/yoga/style/StyleValuePool.h +194 -0
- package/docker/Dockerfile +19 -0
- package/docker/entry.sh +12 -0
- package/package.json +47 -4
- package/shells/android/app/build.gradle.kts +118 -0
- package/shells/android/app/src/main/AndroidManifest.xml +40 -0
- package/shells/android/app/src/main/cpp/CMakeLists.txt +24 -0
- package/shells/android/app/src/main/cpp/android_gl.cpp +125 -0
- package/shells/android/app/src/main/cpp/android_host.cpp +448 -0
- package/shells/android/app/src/main/cpp/android_unicode.cpp +67 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Barcodes.kt +43 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Box.kt +98 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Builtin.kt +4 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Camera.kt +343 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Device.kt +286 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Drawing.kt +364 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/GLView.kt +71 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Geolocation.kt +84 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Input.kt +85 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Keys.kt +18 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Look.kt +170 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/LupineHost.kt +810 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/MainActivity.kt +152 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Module.kt +52 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Notifications.kt +103 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Picture.kt +119 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Services.kt +324 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Snap.kt +72 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/TextLook.kt +180 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/Views.kt +343 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/WebSocket.kt +221 -0
- package/shells/android/app/src/main/java/com/uuware/lupine/WebStorage.kt +48 -0
- package/shells/android/app/src/main/res/drawable/notification.xml +3 -0
- package/shells/android/app/src/main/res/values/styles.xml +7 -0
- package/shells/android/app/src/main/res/values-night/styles.xml +3 -0
- package/shells/android/app/src/main/res/xml/files.xml +5 -0
- package/shells/android/app/src/prebuilt/java/com/uuware/lupine/Hermes.kt +11 -0
- package/shells/android/app/src/static/java/com/uuware/lupine/Hermes.kt +30 -0
- package/shells/android/build.gradle.kts +4 -0
- package/shells/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/shells/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/shells/android/gradle.properties +2 -0
- package/shells/android/gradlew +248 -0
- package/shells/android/gradlew.bat +98 -0
- package/shells/android/settings.gradle.kts +15 -0
- package/shells/ios/CMakeLists.txt +83 -0
- package/shells/ios/Info.plist.in +20 -0
- package/shells/ios/src/host.h +87 -0
- package/shells/ios/src/host.mm +1214 -0
- package/shells/ios/src/main.mm +155 -0
- package/shells/macos/CMakeLists.txt +82 -0
- package/shells/macos/Info.plist.in +21 -0
- package/shells/macos/src/desktop.mm +63 -0
- package/shells/macos/src/host.h +93 -0
- package/shells/macos/src/host.mm +1313 -0
- package/shells/macos/src/main.mm +148 -0
- package/shells/web/src/add-worker.ts +31 -0
- package/shells/web/src/css.ts +89 -0
- package/shells/web/src/device.ts +257 -0
- package/shells/web/src/dom-host.ts +433 -0
- package/shells/web/src/gl.ts +20 -0
- package/shells/web/src/index.ts +89 -0
- package/shells/web/src/picture.ts +28 -0
- package/shells/web/src/server.test.tsx +66 -0
- package/shells/web/src/server.ts +104 -0
- package/shells/web/src/services.ts +264 -0
- package/shells/web/src/web-storage.ts +4 -0
- package/shells/web/src/worker.ts +15 -0
- package/shells/web/tsconfig.json +16 -0
- package/shells/windows/CMakeLists.txt +90 -0
- package/shells/windows/mingw.cmake +11 -0
- package/shells/windows/src/app.manifest +13 -0
- package/shells/windows/src/app.rc +1 -0
- package/shells/windows/src/camera.cpp +327 -0
- package/shells/windows/src/desktop.cpp +103 -0
- package/shells/windows/src/device.cpp +205 -0
- package/shells/windows/src/device.h +59 -0
- package/shells/windows/src/drawing.cpp +285 -0
- package/shells/windows/src/drawing.h +47 -0
- package/shells/windows/src/embedded.cpp +304 -0
- package/shells/windows/src/embedded.h +29 -0
- package/shells/windows/src/geolocation.cpp +96 -0
- package/shells/windows/src/gl_view.cpp +214 -0
- package/shells/windows/src/gpu.cpp +423 -0
- package/shells/windows/src/gpu.h +87 -0
- package/shells/windows/src/host.cpp +954 -0
- package/shells/windows/src/host.h +197 -0
- package/shells/windows/src/input.cpp +707 -0
- package/shells/windows/src/main.cpp +215 -0
- package/shells/windows/src/module_view.h +35 -0
- package/shells/windows/src/notifications.cpp +159 -0
- package/shells/windows/src/pack.cpp +48 -0
- package/shells/windows/src/pack.h +16 -0
- package/shells/windows/src/paint.cpp +471 -0
- package/shells/windows/src/painter.cpp +792 -0
- package/shells/windows/src/painter.h +187 -0
- package/shells/windows/src/picture.cpp +83 -0
- package/shells/windows/src/selection.cpp +99 -0
- package/shells/windows/src/services.cpp +228 -0
- package/shells/windows/src/services.h +30 -0
- package/shells/windows/src/text.cpp +520 -0
- package/shells/windows/src/text.h +70 -0
- package/shells/windows/src/unicode.cpp +68 -0
- package/shells/windows/src/view.h +140 -0
- package/shells/windows/src/websocket.cpp +193 -0
- package/shells/windows/src/websocket.h +14 -0
- package/src/animation.test.tsx +195 -0
- package/src/animation.ts +290 -0
- package/src/api.ts +94 -0
- package/src/app-services.ts +108 -0
- package/src/audio.ts +355 -0
- package/src/canvas.test.tsx +212 -0
- package/src/canvas.ts +628 -0
- package/src/color.ts +42 -0
- package/src/components.ts +247 -0
- package/src/control-flow.ts +22 -0
- package/src/desktop.ts +29 -0
- package/src/device.test.tsx +128 -0
- package/src/device.ts +309 -0
- package/src/features.test.tsx +149 -0
- package/src/fonts.ts +16 -0
- package/src/gestures.ts +120 -0
- package/src/gl-constants.ts +81 -0
- package/src/gl.ts +508 -0
- package/src/globals.d.ts +124 -0
- package/src/host.ts +26 -0
- package/src/index.ts +35 -0
- package/src/jsx.ts +25 -0
- package/src/list.ts +55 -0
- package/src/native-globals.d.ts +43 -0
- package/src/native.ts +221 -0
- package/src/picture.ts +27 -0
- package/src/platform.ts +11 -0
- package/src/polyfills.ts +355 -0
- package/src/process.ts +59 -0
- package/src/refresh.ts +32 -0
- package/src/render.test.tsx +266 -0
- package/src/render.ts +363 -0
- package/src/style.ts +94 -0
- package/src/svg-draw.ts +306 -0
- package/src/svg.test.tsx +31 -0
- package/src/svg.ts +149 -0
- package/src/test-host.ts +57 -0
- package/src/three.ts +11 -0
- package/src/web-storage.ts +10 -0
- package/src/websocket.ts +100 -0
- 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
|
-
#
|
|
1
|
+
# lupine.native.core
|
|
2
2
|
|
|
3
|
-
|
|
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
|