@bake-native/core 0.0.0 → 0.1.0-rc.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/THIRD_PARTY_NOTICES.txt +548 -0
- package/bake-prelude.js +189 -0
- package/batch-contract.json +21 -0
- package/batch-wire.js +674 -0
- package/close-watcher.js +137 -0
- package/compat.json +64 -0
- package/controls.css +108 -0
- package/determinism.js +175 -0
- package/devtools.d.ts +13 -0
- package/devtools.js +73 -0
- package/dialogs.js +59 -0
- package/direct-style.js +105 -0
- package/direct-table.js +261 -0
- package/dist/bake.mjs +2211 -0
- package/dist/build-BrSFpaK1.mjs +1 -0
- package/dist/build-tools-Dxyl6XAf.mjs +80 -0
- package/dist/build-vAPG2xQv.mjs +5516 -0
- package/dist/client-Cm7o6dQd.mjs +17544 -0
- package/dist/compiler.mjs +4 -0
- package/dist/config-B1W8gfZY.mjs +12 -0
- package/dist/dev-xZblYmDc.mjs +990 -0
- package/dist/direct-report-Bdda-k_Y.mjs +153 -0
- package/dist/direct-report-Du44nNWl.mjs +1 -0
- package/dist/index.d.mts +176 -0
- package/dist/index.mjs +1 -0
- package/dist/intl-ROnAp2qO.mjs +75 -0
- package/dist/jiti-stub-CKcaShwE.mjs +5 -0
- package/dist/native-views-BQ8TtbQj.mjs +8046 -0
- package/dist/octane/package.json +5 -0
- package/dist/package-D2aYD6A4.mjs +2789 -0
- package/dist/react/package.json +13 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/dist/run-BtyJGAQB.mjs +6632 -0
- package/dist/scope-8W2aIuQ9.mjs +262 -0
- package/dist/screens/BakeNativeScreen.native.ts +9 -0
- package/dist/screens/package.json +5 -0
- package/dom-exception.js +31 -0
- package/element-api.js +158 -0
- package/first-screen.js +30 -0
- package/fonts/Geist-Italic-Variable.ttf +0 -0
- package/fonts/Geist-Variable.ttf +0 -0
- package/fonts/GeistMono-Italic-Variable.ttf +0 -0
- package/fonts/GeistMono-Variable.ttf +0 -0
- package/fonts/OFL.txt +93 -0
- package/fonts/README.md +27 -0
- package/fonts/geist-italic.css +8 -0
- package/fonts/geist-mono-italic.css +8 -0
- package/fonts/geist-mono.css +8 -0
- package/fonts/geist.css +8 -0
- package/header-icons.json +53 -0
- package/host-runtime.js +521 -0
- package/image-props.js +17 -0
- package/index.d.ts +8 -0
- package/index.js +7 -0
- package/licenses/Apache-2.0.txt +73 -0
- package/locale-entry.d.ts +1 -0
- package/locale-entry.js +1 -0
- package/locale.d.ts +28 -0
- package/locale.js +124 -0
- package/markup-support.js +87 -0
- package/media-element.js +115 -0
- package/native-args-entry.js +2 -0
- package/native-args.d.ts +7 -0
- package/native-args.js +155 -0
- package/native-entry.js +1 -0
- package/native-globals.d.ts +166 -0
- package/native-scenarios.d.ts +17 -0
- package/native-scenarios.js +46 -0
- package/native-support.json +366 -0
- package/native.d.ts +52 -0
- package/native.js +237 -0
- package/package.json +143 -4
- package/page-elements.js +123 -0
- package/runtime-provides.json +412 -0
- package/safe-area.d.ts +1 -0
- package/safe-area.js +44 -0
- package/swift-ui/modifiers.js +176 -0
- package/tab-icons.js +62 -0
- package/templates/create/tabs/AGENTS.md +22 -0
- package/templates/create/tabs/README.md +43 -0
- package/templates/create/tabs/_gitignore +13 -0
- package/templates/create/tabs/android/app/build.gradle.kts +79 -0
- package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
- package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
- package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
- package/templates/create/tabs/android/build.gradle.kts +5 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/templates/create/tabs/android/gradle.properties +3 -0
- package/templates/create/tabs/android/gradlew +248 -0
- package/templates/create/tabs/android/settings.gradle.kts +47 -0
- package/templates/create/tabs/bake.config.ts +10 -0
- package/templates/create/tabs/ios/App/App.swift +30 -0
- package/templates/create/tabs/ios/build.sh +23 -0
- package/templates/create/tabs/ios/project.yml +57 -0
- package/templates/create/tabs/macos/Package.swift +24 -0
- package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
- package/templates/create/tabs/macos/build.sh +4 -0
- package/templates/create/tabs/package.json +23 -0
- package/templates/create/tabs/pnpm-workspace.yaml +6 -0
- package/templates/create/tabs/src/App.tsrx +92 -0
- package/templates/create/tabs/src/App.tsx +67 -0
- package/templates/create/tabs/src/styles.css +32 -0
- package/templates/create/tabs/tsconfig.json +5 -0
- package/templates/create/tabs/windows/Cargo.toml +29 -0
- package/templates/create/tabs/windows/build.rs +9 -0
- package/templates/create/tabs/windows/src/main.rs +52 -0
- package/templates/create/tabs/windows/src/shell.rs +316 -0
- package/templates/module/__NAME__.kt +20 -0
- package/templates/module/__NAME__.native.ts +24 -0
- package/templates/module/__NAME__.swift +25 -0
- package/templates/module/__NAME__.web.ts +13 -0
- package/templates/module/__NAME__Test.kt +26 -0
- package/templates/module/__NAME__Tests.swift +25 -0
- package/templates/module/__SNAKE__.rs +43 -0
- package/text.d.ts +20 -0
- package/text.js +100 -0
- package/transform-entry.js +1 -0
- package/transform.d.ts +15 -0
- package/transform.js +98 -0
- package/tsconfig.native.json +16 -0
- package/ui/scope.js +103 -0
- package/ui/swift.js +106 -0
- package/ui/ui.css +272 -0
- package/view-ref-writer.js +268 -0
- package/view-ref.d.ts +26 -0
- package/view-ref.js +85 -0
- package/views/Video.native.ts +68 -0
- package/views/generated/VideoViewAndroid.h +68 -0
- package/views/generated/VideoViewJSI.h +94 -0
- package/views/generated/VideoViewSpec.kt +113 -0
- package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
- package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
- package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
- package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
- package/views/generated/video_view_spec.rs +189 -0
- package/views.d.ts +24 -0
- package/views.js +45 -0
- package/virtual-window.js +35 -0
- package/visibility.js +75 -0
- package/web-crypto.js +84 -0
- package/web-fetch.js +1071 -0
- package/README.md +0 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
package dev.bakenative.views.generated
|
|
5
|
+
|
|
6
|
+
import android.view.View
|
|
7
|
+
import dev.bakenative.abi.ViewValue
|
|
8
|
+
import dev.bakenative.abi.ViewValueKind
|
|
9
|
+
import dev.bakenative.views.BakeNativeNativeView
|
|
10
|
+
import dev.bakenative.views.BakeNativePromise
|
|
11
|
+
import io.github.expo.kolibri.CalledFromNative
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The platform player behind the built-in <video> element (bake_core::media): AVPlayerLayer on iOS / macOS, MediaPlayer + TextureView on Android, Media Foundation in a child window on Windows. Internal: apps write <video>; the core turns its attributes, CSS and state into these props and the player's events into the element's DOM events. No system controls.
|
|
15
|
+
*
|
|
16
|
+
* Implement the view by extending this class: makeView(), the setters, the commands; call the
|
|
17
|
+
* emit functions. Generated: the typed decode of the core's ViewProps record (by slot), the change
|
|
18
|
+
* check, the typed event writer, and the command entry points the JSI host functions call through
|
|
19
|
+
* kolibri (`@CalledFromNative`, R8 keeps them and this class's name; VideoViewJSI.h).
|
|
20
|
+
*/
|
|
21
|
+
@CalledFromNative(by = "VideoViewJSI.h")
|
|
22
|
+
abstract class VideoViewSpec<V : View> : BakeNativeNativeView<V>("Video", "ae26a0af39526134") {
|
|
23
|
+
data class Failure(val code: String, val message: String)
|
|
24
|
+
data class Metadata(val duration: Double, val height: Double, val width: Double)
|
|
25
|
+
enum class Preload { AUTO, METADATA, NONE }
|
|
26
|
+
data class Progress(val currentTime: Double, val duration: Double)
|
|
27
|
+
|
|
28
|
+
// props (main thread; called only for values that changed, then propsUpdated)
|
|
29
|
+
open fun setAutoplay(view: V, value: Boolean) {}
|
|
30
|
+
open fun setFitHeight(view: V, value: Double?) {}
|
|
31
|
+
open fun setFitWidth(view: V, value: Double?) {}
|
|
32
|
+
open fun setFitX(view: V, value: Double?) {}
|
|
33
|
+
open fun setFitY(view: V, value: Double?) {}
|
|
34
|
+
open fun setLoop(view: V, value: Boolean) {}
|
|
35
|
+
open fun setMuted(view: V, value: Boolean) {}
|
|
36
|
+
open fun setPreload(view: V, value: Preload) {}
|
|
37
|
+
open fun setShowFrames(view: V, value: Boolean) {}
|
|
38
|
+
open fun setSource(view: V, value: String?) {}
|
|
39
|
+
open fun propsUpdated(view: V) {}
|
|
40
|
+
|
|
41
|
+
// commands (main thread; settle the promise once, from any thread)
|
|
42
|
+
open fun pause(view: V, promise: BakeNativePromise<Unit>) {
|
|
43
|
+
promise.reject("E_UNIMPLEMENTED", "Video.pause is not implemented")
|
|
44
|
+
}
|
|
45
|
+
open fun play(view: V, promise: BakeNativePromise<Unit>) {
|
|
46
|
+
promise.reject("E_UNIMPLEMENTED", "Video.play is not implemented")
|
|
47
|
+
}
|
|
48
|
+
open fun seek(view: V, seconds: Double, promise: BakeNativePromise<Unit>) {
|
|
49
|
+
promise.reject("E_UNIMPLEMENTED", "Video.seek is not implemented")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// events (any thread)
|
|
53
|
+
fun emitEnded(view: V) = emit(view, 0, emptyList())
|
|
54
|
+
fun emitError(view: V, event: Failure) = emit(view, 1, listOf(ViewValue(0, ViewValueKind.STRING, false, 0.0, event.code), ViewValue(1, ViewValueKind.STRING, false, 0.0, event.message)))
|
|
55
|
+
fun emitLoadedMetadata(view: V, event: Metadata) = emit(view, 2, listOf(ViewValue(0, ViewValueKind.NUMBER, false, event.duration, ""), ViewValue(1, ViewValueKind.NUMBER, false, event.height, ""), ViewValue(2, ViewValueKind.NUMBER, false, event.width, "")))
|
|
56
|
+
fun emitPause(view: V) = emit(view, 3, emptyList())
|
|
57
|
+
fun emitPlay(view: V) = emit(view, 4, emptyList())
|
|
58
|
+
fun emitTimeUpdate(view: V, event: Progress) = emit(view, 5, listOf(ViewValue(0, ViewValueKind.NUMBER, false, event.currentTime, ""), ViewValue(1, ViewValueKind.NUMBER, false, event.duration, "")))
|
|
59
|
+
|
|
60
|
+
// generated: the ViewProps values (by slot, copied from the record) -> typed setters
|
|
61
|
+
private data class Props(val autoplay: Boolean, val fitHeight: Double?, val fitWidth: Double?, val fitX: Double?, val fitY: Double?, val loop: Boolean, val muted: Boolean, val preload: Preload, val showFrames: Boolean, val source: String?)
|
|
62
|
+
final override fun apply(view: V, props: List<ViewValue>, first: Boolean) {
|
|
63
|
+
var autoplay: Boolean = false
|
|
64
|
+
var fitHeight: Double? = null
|
|
65
|
+
var fitWidth: Double? = null
|
|
66
|
+
var fitX: Double? = null
|
|
67
|
+
var fitY: Double? = null
|
|
68
|
+
var loop: Boolean = false
|
|
69
|
+
var muted: Boolean = false
|
|
70
|
+
var preload: Preload = Preload.AUTO
|
|
71
|
+
var showFrames: Boolean = false
|
|
72
|
+
var source: String? = null
|
|
73
|
+
for (value in props) {
|
|
74
|
+
when (value.slot) {
|
|
75
|
+
0 -> autoplay = (if (value.kind == ViewValueKind.BOOL) value.flag else null) ?: false
|
|
76
|
+
1 -> fitHeight = (if (value.kind == ViewValueKind.NUMBER) value.number else null)
|
|
77
|
+
2 -> fitWidth = (if (value.kind == ViewValueKind.NUMBER) value.number else null)
|
|
78
|
+
3 -> fitX = (if (value.kind == ViewValueKind.NUMBER) value.number else null)
|
|
79
|
+
4 -> fitY = (if (value.kind == ViewValueKind.NUMBER) value.number else null)
|
|
80
|
+
5 -> loop = (if (value.kind == ViewValueKind.BOOL) value.flag else null) ?: false
|
|
81
|
+
6 -> muted = (if (value.kind == ViewValueKind.BOOL) value.flag else null) ?: false
|
|
82
|
+
7 -> preload = (if (value.kind == ViewValueKind.NUMBER && value.number == value.number.toInt().toDouble()) Preload.entries.getOrNull(value.number.toInt()) else null) ?: Preload.AUTO
|
|
83
|
+
8 -> showFrames = (if (value.kind == ViewValueKind.BOOL) value.flag else null) ?: false
|
|
84
|
+
9 -> source = (if (value.kind == ViewValueKind.STRING) value.text else null)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
val next = Props(autoplay, fitHeight, fitWidth, fitX, fitY, loop, muted, preload, showFrames, source)
|
|
88
|
+
@Suppress("UNCHECKED_CAST") val last = state(view) as Props?
|
|
89
|
+
if (first || last?.autoplay != next.autoplay) setAutoplay(view, next.autoplay)
|
|
90
|
+
if (first || last?.fitHeight != next.fitHeight) setFitHeight(view, next.fitHeight)
|
|
91
|
+
if (first || last?.fitWidth != next.fitWidth) setFitWidth(view, next.fitWidth)
|
|
92
|
+
if (first || last?.fitX != next.fitX) setFitX(view, next.fitX)
|
|
93
|
+
if (first || last?.fitY != next.fitY) setFitY(view, next.fitY)
|
|
94
|
+
if (first || last?.loop != next.loop) setLoop(view, next.loop)
|
|
95
|
+
if (first || last?.muted != next.muted) setMuted(view, next.muted)
|
|
96
|
+
if (first || last?.preload != next.preload) setPreload(view, next.preload)
|
|
97
|
+
if (first || last?.showFrames != next.showFrames) setShowFrames(view, next.showFrames)
|
|
98
|
+
if (first || last?.source != next.source) setSource(view, next.source)
|
|
99
|
+
setState(view, next)
|
|
100
|
+
propsUpdated(view)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// generated: JSI host functions -> commands (called from C++ through kolibri)
|
|
104
|
+
@CalledFromNative
|
|
105
|
+
fun callPause(node: Long, promise: BakeNativePromise<Unit>) =
|
|
106
|
+
onMain(node, promise) { view -> pause(view, promise) }
|
|
107
|
+
@CalledFromNative
|
|
108
|
+
fun callPlay(node: Long, promise: BakeNativePromise<Unit>) =
|
|
109
|
+
onMain(node, promise) { view -> play(view, promise) }
|
|
110
|
+
@CalledFromNative
|
|
111
|
+
fun callSeek(node: Long, seconds: Double, promise: BakeNativePromise<Unit>) =
|
|
112
|
+
onMain(node, promise) { view -> seek(view, seconds, promise) }
|
|
113
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
#include "VideoViewJSIApple.h"
|
|
5
|
+
#include "../../VideoViewJSI.h"
|
|
6
|
+
|
|
7
|
+
namespace bake::views::video::apple {
|
|
8
|
+
namespace {
|
|
9
|
+
struct Impl final : ::bake::views::video::Commands {
|
|
10
|
+
Table t;
|
|
11
|
+
explicit Impl(Table table) : t(table) {}
|
|
12
|
+
~Impl() override {
|
|
13
|
+
if (t.release) t.release(t.ctx);
|
|
14
|
+
}
|
|
15
|
+
void pause(int64_t node, Promise promise) override {
|
|
16
|
+
if (auto *h = promise.release()) t.pause(t.ctx, node, h);
|
|
17
|
+
}
|
|
18
|
+
void play(int64_t node, Promise promise) override {
|
|
19
|
+
if (auto *h = promise.release()) t.play(t.ctx, node, h);
|
|
20
|
+
}
|
|
21
|
+
void seek(int64_t node, double seconds, Promise promise) override {
|
|
22
|
+
if (auto *h = promise.release()) t.seek(t.ctx, node, seconds, h);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
} // namespace
|
|
26
|
+
|
|
27
|
+
bool install(void *engine, Table table) {
|
|
28
|
+
auto impl = std::make_shared<Impl>(table);
|
|
29
|
+
auto *rt = static_cast<facebook::jsi::Runtime *>(bake_engine_jsi(static_cast<bake_engine *>(engine)));
|
|
30
|
+
if (!rt) return false;
|
|
31
|
+
// Nothing may unwind into Swift.
|
|
32
|
+
try {
|
|
33
|
+
::bake::views::video::install(*rt, impl);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (...) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
} // namespace bake::views::video::apple
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
// What VideoViewInterop.swift sees of the JSI glue: one C function pointer per command and the
|
|
5
|
+
// install call. C++ only (empty to C, so a plain-Swift client scanning the module sees nothing).
|
|
6
|
+
#pragma once
|
|
7
|
+
#ifdef __cplusplus
|
|
8
|
+
#include <cstddef>
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
|
|
11
|
+
namespace bake::views::video::apple {
|
|
12
|
+
|
|
13
|
+
/// Command entry points (JS thread). `promise` is an `bake_js_promise *` the callee owns and settles once.
|
|
14
|
+
struct Table {
|
|
15
|
+
void *ctx = nullptr;
|
|
16
|
+
/// Called once when the runtime drops the commands.
|
|
17
|
+
void (*release)(void *ctx) = nullptr;
|
|
18
|
+
void (*pause)(void *ctx, int64_t node, void *promise) = nullptr;
|
|
19
|
+
void (*play)(void *ctx, int64_t node, void *promise) = nullptr;
|
|
20
|
+
void (*seek)(void *ctx, int64_t node, double seconds, void *promise) = nullptr;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/// Installs native.$views.Video.* on the runtime of `engine` (an `bake_engine *`; JS thread, before
|
|
24
|
+
/// the bundle runs). Takes the table (released with it). False, with the table released, when it cannot.
|
|
25
|
+
bool install(void *engine, Table table);
|
|
26
|
+
|
|
27
|
+
} // namespace bake::views::video::apple
|
|
28
|
+
#endif
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
// The Swift <-> C++ interop half of VideoViewSpec: fills the C++ table VideoViewJSIApple.cpp
|
|
5
|
+
// calls (one C function per command, typed arguments, the promise handle) and installs the JSI host
|
|
6
|
+
// functions on a runtime. Compiled with `.interoperabilityMode(.Cxx)`; the C++ module is imported
|
|
7
|
+
// `internal`, so the module's public interface stays plain Swift.
|
|
8
|
+
internal import VideoViewJSI
|
|
9
|
+
|
|
10
|
+
enum VideoViewInterop {
|
|
11
|
+
/// The command closures (JS thread): node id, the arguments, the `bake_js_promise *` they own.
|
|
12
|
+
final class Entries: @unchecked Sendable {
|
|
13
|
+
let pause: @Sendable (Int64, UnsafeMutableRawPointer) -> Void
|
|
14
|
+
let play: @Sendable (Int64, UnsafeMutableRawPointer) -> Void
|
|
15
|
+
let seek: @Sendable (Int64, Double, UnsafeMutableRawPointer) -> Void
|
|
16
|
+
init(pause: @escaping @Sendable (Int64, UnsafeMutableRawPointer) -> Void, play: @escaping @Sendable (Int64, UnsafeMutableRawPointer) -> Void, seek: @escaping @Sendable (Int64, Double, UnsafeMutableRawPointer) -> Void) {
|
|
17
|
+
self.pause = pause
|
|
18
|
+
self.play = play
|
|
19
|
+
self.seek = seek
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// JS thread. False when `engine` is not an BakeNative runtime with a JS-thread invoker.
|
|
24
|
+
static func install(engine: UnsafeMutableRawPointer, pause: @escaping @Sendable (Int64, UnsafeMutableRawPointer) -> Void, play: @escaping @Sendable (Int64, UnsafeMutableRawPointer) -> Void, seek: @escaping @Sendable (Int64, Double, UnsafeMutableRawPointer) -> Void) -> Bool {
|
|
25
|
+
var table = bake.views.video.apple.Table()
|
|
26
|
+
table.ctx = Unmanaged.passRetained(Entries(pause: pause, play: play, seek: seek)).toOpaque()
|
|
27
|
+
table.release = { ctx in Unmanaged<Entries>.fromOpaque(ctx!).release() }
|
|
28
|
+
table.pause = { ctx, node, promise in
|
|
29
|
+
Unmanaged<Entries>.fromOpaque(ctx!).takeUnretainedValue().pause(node, promise!)
|
|
30
|
+
}
|
|
31
|
+
table.play = { ctx, node, promise in
|
|
32
|
+
Unmanaged<Entries>.fromOpaque(ctx!).takeUnretainedValue().play(node, promise!)
|
|
33
|
+
}
|
|
34
|
+
table.seek = { ctx, node, seconds, promise in
|
|
35
|
+
Unmanaged<Entries>.fromOpaque(ctx!).takeUnretainedValue().seek(node, seconds, promise!)
|
|
36
|
+
}
|
|
37
|
+
return bake.views.video.apple.install(engine, table)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
// Implement the view by subclassing VideoViewSpec: override makeView(), the setters, the
|
|
5
|
+
// commands, and call the emit methods. Everything else is generated: the typed decode of the
|
|
6
|
+
// core's ViewProps record (by slot, no JSON, no names), the change check, the typed event
|
|
7
|
+
// writer, and the command entry points the JSI host functions call through Swift <-> C++
|
|
8
|
+
// interop (VideoViewJSI.h -> VideoViewJSIApple.cpp -> VideoViewInterop.swift). Plain Swift:
|
|
9
|
+
// no Objective-C runtime, no registration by name.
|
|
10
|
+
//
|
|
11
|
+
// Threads: the class is @MainActor (makeView, the setters, propsUpdated and the command bodies run
|
|
12
|
+
// on main); the emit and call methods are nonisolated (any thread).
|
|
13
|
+
import BakeNativeNativeViews
|
|
14
|
+
#if canImport(BakeNativeApple)
|
|
15
|
+
@_spi(BakeNativeGenerated) import BakeNativeApple
|
|
16
|
+
#elseif canImport(BakeNativeKit)
|
|
17
|
+
@_spi(BakeNativeGenerated) import BakeNativeKit
|
|
18
|
+
#elseif canImport(BakeNativeAppKit)
|
|
19
|
+
@_spi(BakeNativeGenerated) import BakeNativeAppKit
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
/** The platform player behind the built-in <video> element (bake_core::media): AVPlayerLayer on iOS / macOS, MediaPlayer + TextureView on Android, Media Foundation in a child window on Windows. Internal: apps write <video>; the core turns its attributes, CSS and state into these props and the player's events into the element's DOM events. No system controls. */
|
|
23
|
+
open class VideoViewSpec<V: AnyObject>: BakeNativeNativeView<V> {
|
|
24
|
+
public struct Failure: Sendable, Equatable {
|
|
25
|
+
public var code: String
|
|
26
|
+
public var message: String
|
|
27
|
+
public init(code: String, message: String) {
|
|
28
|
+
self.code = code
|
|
29
|
+
self.message = message
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
public struct Metadata: Sendable, Equatable {
|
|
33
|
+
public var duration: Double
|
|
34
|
+
public var height: Double
|
|
35
|
+
public var width: Double
|
|
36
|
+
public init(duration: Double, height: Double, width: Double) {
|
|
37
|
+
self.duration = duration
|
|
38
|
+
self.height = height
|
|
39
|
+
self.width = width
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
public enum Preload: Int, Sendable, CaseIterable {
|
|
43
|
+
case auto = 0
|
|
44
|
+
case metadata = 1
|
|
45
|
+
case none = 2
|
|
46
|
+
}
|
|
47
|
+
public struct Progress: Sendable, Equatable {
|
|
48
|
+
public var currentTime: Double
|
|
49
|
+
public var duration: Double
|
|
50
|
+
public init(currentTime: Double, duration: Double) {
|
|
51
|
+
self.currentTime = currentTime
|
|
52
|
+
self.duration = duration
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
public nonisolated final override class var viewName: String { "Video" }
|
|
56
|
+
public nonisolated final override class var signature: String { "ae26a0af39526134" }
|
|
57
|
+
|
|
58
|
+
// MARK: props (main thread; called only for values that changed, then propsUpdated)
|
|
59
|
+
/** Start playing once the media can play (the player attaches after hydration, so never on the baked first frame). */
|
|
60
|
+
open func setAutoplay(_ view: V, _ value: Bool) {}
|
|
61
|
+
open func setFitHeight(_ view: V, _ value: Double?) {}
|
|
62
|
+
open func setFitWidth(_ view: V, _ value: Double?) {}
|
|
63
|
+
/** The picture's rect (CSS px, from the content box's top-left), from object-fit / object-position. It may overflow the box: the view clips it. Unset: the whole box. */
|
|
64
|
+
open func setFitX(_ view: V, _ value: Double?) {}
|
|
65
|
+
open func setFitY(_ view: V, _ value: Double?) {}
|
|
66
|
+
open func setLoop(_ view: V, _ value: Bool) {}
|
|
67
|
+
open func setMuted(_ view: V, _ value: Bool) {}
|
|
68
|
+
/** 'none': open the source only on play(). */
|
|
69
|
+
open func setPreload(_ view: V, _ value: Preload) {}
|
|
70
|
+
/** Show the picture once a frame is decoded. False while the core draws the poster (until the first play). */
|
|
71
|
+
open func setShowFrames(_ view: V, _ value: Bool) {}
|
|
72
|
+
/** The media URL as the host opens it: asset://<file> (a bundle asset), https: or a path next to the bundle. */
|
|
73
|
+
open func setSource(_ view: V, _ value: String?) {}
|
|
74
|
+
open func propsUpdated(_ view: V) {}
|
|
75
|
+
|
|
76
|
+
// MARK: commands (main thread; settle the promise once, from any thread)
|
|
77
|
+
open func pause(_ view: V, promise: BakeNativePromise<Void>) {
|
|
78
|
+
promise.rejectUnimplemented("Video.pause")
|
|
79
|
+
}
|
|
80
|
+
/** Starts playback; resolves once the player accepted it (before the media is ready, once it is). */
|
|
81
|
+
open func play(_ view: V, promise: BakeNativePromise<Void>) {
|
|
82
|
+
promise.rejectUnimplemented("Video.play")
|
|
83
|
+
}
|
|
84
|
+
/** Moves the playback position (currentTime = seconds); resolves once the frame there is shown. */
|
|
85
|
+
open func seek(_ view: V, seconds: Double, promise: BakeNativePromise<Void>) {
|
|
86
|
+
promise.rejectUnimplemented("Video.seek")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// MARK: events (any thread)
|
|
90
|
+
/** Playback reached the end (not while looping). */
|
|
91
|
+
public nonisolated final func emitEnded(_ view: V) { emit(view, event: 0, []) }
|
|
92
|
+
/** The media failed to load or play. */
|
|
93
|
+
public nonisolated final func emitError(_ view: V, _ event: Failure) {
|
|
94
|
+
emit(view, event: 1, [BakeViewValue(slot: 0, kind: .string, flag: false, number: 0, text: event.code), BakeViewValue(slot: 1, kind: .string, flag: false, number: 0, text: event.message)])
|
|
95
|
+
}
|
|
96
|
+
/** The media's duration (s) and natural size (px) are known. */
|
|
97
|
+
public nonisolated final func emitLoadedMetadata(_ view: V, _ event: Metadata) {
|
|
98
|
+
emit(view, event: 2, [BakeViewValue(slot: 0, kind: .number, flag: false, number: event.duration, text: ""), BakeViewValue(slot: 1, kind: .number, flag: false, number: event.height, text: ""), BakeViewValue(slot: 2, kind: .number, flag: false, number: event.width, text: "")])
|
|
99
|
+
}
|
|
100
|
+
/** Playback paused (pause(), or the end without loop: then onEnded follows). */
|
|
101
|
+
public nonisolated final func emitPause(_ view: V) { emit(view, event: 3, []) }
|
|
102
|
+
/** Playback started (play(), autoplay); a loop restarting is not a new play. */
|
|
103
|
+
public nonisolated final func emitPlay(_ view: V) { emit(view, event: 4, []) }
|
|
104
|
+
/** The playback position moved (at most every 250 ms; the last position always arrives). */
|
|
105
|
+
public nonisolated final func emitTimeUpdate(_ view: V, _ event: Progress) {
|
|
106
|
+
emit(view, event: 5, [BakeViewValue(slot: 0, kind: .number, flag: false, number: event.currentTime, text: ""), BakeViewValue(slot: 1, kind: .number, flag: false, number: event.duration, text: "")])
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// MARK: generated (the core's ViewProps record -> typed setters)
|
|
110
|
+
private struct Props: Equatable {
|
|
111
|
+
var autoplay: Bool
|
|
112
|
+
var fitHeight: Double?
|
|
113
|
+
var fitWidth: Double?
|
|
114
|
+
var fitX: Double?
|
|
115
|
+
var fitY: Double?
|
|
116
|
+
var loop: Bool
|
|
117
|
+
var muted: Bool
|
|
118
|
+
var preload: Preload
|
|
119
|
+
var showFrames: Bool
|
|
120
|
+
var source: String?
|
|
121
|
+
}
|
|
122
|
+
@_spi(BakeNativeGenerated) public final override func apply(_ view: V, _ props: [BakeViewValue], first: Bool) {
|
|
123
|
+
var next = Props(autoplay: false, fitHeight: nil, fitWidth: nil, fitX: nil, fitY: nil, loop: false, muted: false, preload: .auto, showFrames: false, source: nil)
|
|
124
|
+
for value in props {
|
|
125
|
+
switch value.slot {
|
|
126
|
+
case 0: next.autoplay = (value.kind == .bool ? value.flag : nil) ?? false
|
|
127
|
+
case 1: next.fitHeight = (value.kind == .number ? value.number : nil)
|
|
128
|
+
case 2: next.fitWidth = (value.kind == .number ? value.number : nil)
|
|
129
|
+
case 3: next.fitX = (value.kind == .number ? value.number : nil)
|
|
130
|
+
case 4: next.fitY = (value.kind == .number ? value.number : nil)
|
|
131
|
+
case 5: next.loop = (value.kind == .bool ? value.flag : nil) ?? false
|
|
132
|
+
case 6: next.muted = (value.kind == .bool ? value.flag : nil) ?? false
|
|
133
|
+
case 7: next.preload = (value.kind == .number ? Preload(rawValue: Int(value.number)) : nil) ?? .auto
|
|
134
|
+
case 8: next.showFrames = (value.kind == .bool ? value.flag : nil) ?? false
|
|
135
|
+
case 9: next.source = (value.kind == .string ? value.text : nil)
|
|
136
|
+
default: break
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
let last = state(view, as: Props.self)
|
|
140
|
+
if first || last?.autoplay != next.autoplay { setAutoplay(view, next.autoplay) }
|
|
141
|
+
if first || last?.fitHeight != next.fitHeight { setFitHeight(view, next.fitHeight) }
|
|
142
|
+
if first || last?.fitWidth != next.fitWidth { setFitWidth(view, next.fitWidth) }
|
|
143
|
+
if first || last?.fitX != next.fitX { setFitX(view, next.fitX) }
|
|
144
|
+
if first || last?.fitY != next.fitY { setFitY(view, next.fitY) }
|
|
145
|
+
if first || last?.loop != next.loop { setLoop(view, next.loop) }
|
|
146
|
+
if first || last?.muted != next.muted { setMuted(view, next.muted) }
|
|
147
|
+
if first || last?.preload != next.preload { setPreload(view, next.preload) }
|
|
148
|
+
if first || last?.showFrames != next.showFrames { setShowFrames(view, next.showFrames) }
|
|
149
|
+
if first || last?.source != next.source { setSource(view, next.source) }
|
|
150
|
+
setState(view, next)
|
|
151
|
+
propsUpdated(view)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// MARK: generated (JSI host functions -> commands; VideoViewJSI.h calls these through C++ interop)
|
|
155
|
+
public nonisolated final func callPause(node: Int64, promise: BakeNativePromise<Void>) {
|
|
156
|
+
onMain(node: node, promise: promise) { view in self.pause(view, promise: promise) }
|
|
157
|
+
}
|
|
158
|
+
public nonisolated final func callPlay(node: Int64, promise: BakeNativePromise<Void>) {
|
|
159
|
+
onMain(node: node, promise: promise) { view in self.play(view, promise: promise) }
|
|
160
|
+
}
|
|
161
|
+
public nonisolated final func callSeek(node: Int64, seconds: Double, promise: BakeNativePromise<Void>) {
|
|
162
|
+
onMain(node: node, promise: promise) { view in self.seek(view, seconds: seconds, promise: promise) }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/// Installs native.$views.Video.* on a new runtime (core thread, before the bundle runs).
|
|
166
|
+
public nonisolated final override func installCommands(engine: UnsafeMutableRawPointer) -> Bool {
|
|
167
|
+
VideoViewInterop.install(
|
|
168
|
+
engine: engine,
|
|
169
|
+
pause: { [weak self] node, handle in
|
|
170
|
+
let promise = BakeNativePromise<Void>(handle: handle)
|
|
171
|
+
guard let self else { return promise.rejectDetached("Video.pause") }
|
|
172
|
+
self.callPause(node: node, promise: promise)
|
|
173
|
+
},
|
|
174
|
+
play: { [weak self] node, handle in
|
|
175
|
+
let promise = BakeNativePromise<Void>(handle: handle)
|
|
176
|
+
guard let self else { return promise.rejectDetached("Video.play") }
|
|
177
|
+
self.callPlay(node: node, promise: promise)
|
|
178
|
+
},
|
|
179
|
+
seek: { [weak self] node, seconds, handle in
|
|
180
|
+
let promise = BakeNativePromise<Void>(handle: handle)
|
|
181
|
+
guard let self else { return promise.rejectDetached("Video.seek") }
|
|
182
|
+
self.callSeek(node: node, seconds: seconds, promise: promise)
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Generated by `bake native view gen` from Video.native.ts (signature ae26a0af39526134). Do not edit:
|
|
2
|
+
// change the spec and generate again. docs/design/native-views.md
|
|
3
|
+
|
|
4
|
+
//! The platform player behind the built-in <video> element (bake_core::media): AVPlayerLayer on iOS / macOS, MediaPlayer + TextureView on Android, Media Foundation in a child window on Windows. Internal: apps write <video>; the core turns its attributes, CSS and state into these props and the player's events into the element's DOM events. No system controls.: implement [`VideoView`] and register it with
|
|
5
|
+
//! `bake_runtime::native_views::ViewRegistry::register::<VideoSpec<YourView>>`. Generated: the typed
|
|
6
|
+
//! decode of the core's `ViewProps` record (by slot), the change check, the typed emitters and
|
|
7
|
+
//! the command entry points (called from the JSI host functions, VideoViewJSI.h).
|
|
8
|
+
#![allow(clippy::all, unused_variables, dead_code)]
|
|
9
|
+
|
|
10
|
+
use bake_runtime::native_views::{CommandArgs, Emitter, NativeView, Promise, ViewArg, ViewError};
|
|
11
|
+
|
|
12
|
+
pub const NAME: &str = "Video";
|
|
13
|
+
pub const SIGNATURE: &str = "ae26a0af39526134";
|
|
14
|
+
|
|
15
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
16
|
+
pub struct Failure {
|
|
17
|
+
pub code: String,
|
|
18
|
+
pub message: String,
|
|
19
|
+
}
|
|
20
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
21
|
+
pub struct Metadata {
|
|
22
|
+
pub duration: f64,
|
|
23
|
+
pub height: f64,
|
|
24
|
+
pub width: f64,
|
|
25
|
+
}
|
|
26
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
27
|
+
pub enum Preload {
|
|
28
|
+
Auto = 0,
|
|
29
|
+
Metadata = 1,
|
|
30
|
+
None = 2,
|
|
31
|
+
}
|
|
32
|
+
impl Preload {
|
|
33
|
+
pub fn from_index(i: f64) -> Option<Self> {
|
|
34
|
+
match i as i64 {
|
|
35
|
+
0 => Some(Self::Auto),
|
|
36
|
+
1 => Some(Self::Metadata),
|
|
37
|
+
2 => Some(Self::None),
|
|
38
|
+
_ => None,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
43
|
+
pub struct Progress {
|
|
44
|
+
pub current_time: f64,
|
|
45
|
+
pub duration: f64,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// The props, decoded (absent values are the spec defaults).
|
|
49
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
50
|
+
pub struct VideoProps {
|
|
51
|
+
pub autoplay: bool,
|
|
52
|
+
pub fit_height: Option<f64>,
|
|
53
|
+
pub fit_width: Option<f64>,
|
|
54
|
+
pub fit_x: Option<f64>,
|
|
55
|
+
pub fit_y: Option<f64>,
|
|
56
|
+
pub r#loop: bool,
|
|
57
|
+
pub muted: bool,
|
|
58
|
+
pub preload: Preload,
|
|
59
|
+
pub show_frames: bool,
|
|
60
|
+
pub source: Option<String>,
|
|
61
|
+
}
|
|
62
|
+
impl Default for VideoProps {
|
|
63
|
+
fn default() -> Self {
|
|
64
|
+
Self { autoplay: false, fit_height: None, fit_width: None, fit_x: None, fit_y: None, r#loop: false, muted: false, preload: Preload::Auto, show_frames: false, source: None }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
impl VideoProps {
|
|
68
|
+
/// From the `ViewProps` values in slot order.
|
|
69
|
+
pub fn decode(values: &[ViewArg]) -> Self {
|
|
70
|
+
let mut p = Self::default();
|
|
71
|
+
if let Some(v) = values.get(0).and_then(|v| match v { ViewArg::Bool(b) => Some(*b), _ => None }) { p.autoplay = v; }
|
|
72
|
+
if let Some(v) = values.get(1) { p.fit_height = match v { ViewArg::Number(n) => Some(*n), _ => None }; }
|
|
73
|
+
if let Some(v) = values.get(2) { p.fit_width = match v { ViewArg::Number(n) => Some(*n), _ => None }; }
|
|
74
|
+
if let Some(v) = values.get(3) { p.fit_x = match v { ViewArg::Number(n) => Some(*n), _ => None }; }
|
|
75
|
+
if let Some(v) = values.get(4) { p.fit_y = match v { ViewArg::Number(n) => Some(*n), _ => None }; }
|
|
76
|
+
if let Some(v) = values.get(5).and_then(|v| match v { ViewArg::Bool(b) => Some(*b), _ => None }) { p.r#loop = v; }
|
|
77
|
+
if let Some(v) = values.get(6).and_then(|v| match v { ViewArg::Bool(b) => Some(*b), _ => None }) { p.muted = v; }
|
|
78
|
+
if let Some(v) = values.get(7).and_then(|v| match v { ViewArg::Number(n) => Preload::from_index(*n), _ => None }) { p.preload = v; }
|
|
79
|
+
if let Some(v) = values.get(8).and_then(|v| match v { ViewArg::Bool(b) => Some(*b), _ => None }) { p.show_frames = v; }
|
|
80
|
+
if let Some(v) = values.get(9) { p.source = match v { ViewArg::Text(s) => Some(s.clone()), _ => None }; }
|
|
81
|
+
p
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Video: implement the setters and commands; `make_view` creates the platform view.
|
|
86
|
+
pub trait VideoView: Send + 'static {
|
|
87
|
+
type View: 'static;
|
|
88
|
+
fn make_view(&mut self, events: VideoEvents) -> Self::View;
|
|
89
|
+
fn set_autoplay(&mut self, view: &mut Self::View, value: bool) {}
|
|
90
|
+
fn set_fit_height(&mut self, view: &mut Self::View, value: Option<f64>) {}
|
|
91
|
+
fn set_fit_width(&mut self, view: &mut Self::View, value: Option<f64>) {}
|
|
92
|
+
fn set_fit_x(&mut self, view: &mut Self::View, value: Option<f64>) {}
|
|
93
|
+
fn set_fit_y(&mut self, view: &mut Self::View, value: Option<f64>) {}
|
|
94
|
+
fn set_loop(&mut self, view: &mut Self::View, value: bool) {}
|
|
95
|
+
fn set_muted(&mut self, view: &mut Self::View, value: bool) {}
|
|
96
|
+
fn set_preload(&mut self, view: &mut Self::View, value: Preload) {}
|
|
97
|
+
fn set_show_frames(&mut self, view: &mut Self::View, value: bool) {}
|
|
98
|
+
fn set_source(&mut self, view: &mut Self::View, value: Option<String>) {}
|
|
99
|
+
fn props_updated(&mut self, view: &mut Self::View) {}
|
|
100
|
+
fn pause(&mut self, view: &mut Self::View, promise: Promise<()>) {
|
|
101
|
+
promise.reject(ViewError::unimplemented("Video.pause"));
|
|
102
|
+
}
|
|
103
|
+
fn play(&mut self, view: &mut Self::View, promise: Promise<()>) {
|
|
104
|
+
promise.reject(ViewError::unimplemented("Video.play"));
|
|
105
|
+
}
|
|
106
|
+
fn seek(&mut self, view: &mut Self::View, seconds: f64, promise: Promise<()>) {
|
|
107
|
+
promise.reject(ViewError::unimplemented("Video.seek"));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// The view's typed events (any thread).
|
|
112
|
+
#[derive(Clone)]
|
|
113
|
+
pub struct VideoEvents(pub Emitter);
|
|
114
|
+
impl VideoEvents {
|
|
115
|
+
pub fn ended(&self) { self.0.emit(0, &[]); }
|
|
116
|
+
pub fn error(&self, event: &Failure) {
|
|
117
|
+
self.0.emit(1, &[ViewArg::Text(event.code.clone()), ViewArg::Text(event.message.clone())]);
|
|
118
|
+
}
|
|
119
|
+
pub fn loaded_metadata(&self, event: &Metadata) {
|
|
120
|
+
self.0.emit(2, &[ViewArg::Number(event.duration), ViewArg::Number(event.height), ViewArg::Number(event.width)]);
|
|
121
|
+
}
|
|
122
|
+
pub fn pause(&self) { self.0.emit(3, &[]); }
|
|
123
|
+
pub fn play(&self) { self.0.emit(4, &[]); }
|
|
124
|
+
pub fn time_update(&self, event: &Progress) {
|
|
125
|
+
self.0.emit(5, &[ViewArg::Number(event.current_time), ViewArg::Number(event.duration)]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// The generated half of the view: the registry drives it.
|
|
130
|
+
pub struct VideoSpec<T: VideoView> { pub imp: T }
|
|
131
|
+
impl<T: VideoView> NativeView for VideoSpec<T> {
|
|
132
|
+
type View = (T::View, VideoProps);
|
|
133
|
+
const NAME: &'static str = NAME;
|
|
134
|
+
const SIGNATURE: &'static str = SIGNATURE;
|
|
135
|
+
const COMMANDS: &'static [&'static str] = &["pause", "play", "seek"];
|
|
136
|
+
fn make_view(&mut self, emitter: Emitter) -> Self::View {
|
|
137
|
+
(self.imp.make_view(VideoEvents(emitter)), VideoProps::default())
|
|
138
|
+
}
|
|
139
|
+
fn apply(&mut self, view: &mut Self::View, values: &[ViewArg], first: bool) {
|
|
140
|
+
let next = VideoProps::decode(values);
|
|
141
|
+
let (v, last) = view;
|
|
142
|
+
if first || last.autoplay != next.autoplay { self.imp.set_autoplay(v, next.autoplay.clone()); }
|
|
143
|
+
if first || last.fit_height != next.fit_height { self.imp.set_fit_height(v, next.fit_height.clone()); }
|
|
144
|
+
if first || last.fit_width != next.fit_width { self.imp.set_fit_width(v, next.fit_width.clone()); }
|
|
145
|
+
if first || last.fit_x != next.fit_x { self.imp.set_fit_x(v, next.fit_x.clone()); }
|
|
146
|
+
if first || last.fit_y != next.fit_y { self.imp.set_fit_y(v, next.fit_y.clone()); }
|
|
147
|
+
if first || last.r#loop != next.r#loop { self.imp.set_loop(v, next.r#loop.clone()); }
|
|
148
|
+
if first || last.muted != next.muted { self.imp.set_muted(v, next.muted.clone()); }
|
|
149
|
+
if first || last.preload != next.preload { self.imp.set_preload(v, next.preload.clone()); }
|
|
150
|
+
if first || last.show_frames != next.show_frames { self.imp.set_show_frames(v, next.show_frames.clone()); }
|
|
151
|
+
if first || last.source != next.source { self.imp.set_source(v, next.source.clone()); }
|
|
152
|
+
*last = next;
|
|
153
|
+
self.imp.props_updated(v);
|
|
154
|
+
}
|
|
155
|
+
fn command(&mut self, view: &mut Self::View, command: usize, args: CommandArgs) {
|
|
156
|
+
match command {
|
|
157
|
+
0 => { let promise = args.promise(); self.imp.pause(&mut view.0, promise); }
|
|
158
|
+
1 => { let promise = args.promise(); self.imp.play(&mut view.0, promise); }
|
|
159
|
+
2 => { let seconds = match args.get(0).and_then(|a| match a { ViewArg::Number(n) => Some(*n), _ => None }) { Some(x) => x, None => return args.reject_type(0, "number") }; let promise = args.promise(); self.imp.seek(&mut view.0, seconds, promise); }
|
|
160
|
+
_ => args.reject_unknown(),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Rust hosts (Windows): the JSI host functions of VideoViewJSI.h (compiled with BAKE_VIEWS_RUST_HOST)
|
|
166
|
+
// convert their arguments and call these entry points, which post the typed call to the host's main
|
|
167
|
+
// thread (`ViewHost`); the host runs it on its `ViewRegistry` (`ViewCall::run`).
|
|
168
|
+
#[unsafe(no_mangle)]
|
|
169
|
+
pub unsafe extern "C" fn bake_view_video_pause(host: *const std::ffi::c_void, node: i64, promise: *mut std::ffi::c_void) {
|
|
170
|
+
unsafe { bake_runtime::native_views::ViewHost::enter(host, NAME, 0, node, vec![], promise) }
|
|
171
|
+
}
|
|
172
|
+
#[unsafe(no_mangle)]
|
|
173
|
+
pub unsafe extern "C" fn bake_view_video_play(host: *const std::ffi::c_void, node: i64, promise: *mut std::ffi::c_void) {
|
|
174
|
+
unsafe { bake_runtime::native_views::ViewHost::enter(host, NAME, 1, node, vec![], promise) }
|
|
175
|
+
}
|
|
176
|
+
#[unsafe(no_mangle)]
|
|
177
|
+
pub unsafe extern "C" fn bake_view_video_seek(host: *const std::ffi::c_void, node: i64, seconds: f64, promise: *mut std::ffi::c_void) {
|
|
178
|
+
unsafe { bake_runtime::native_views::ViewHost::enter(host, NAME, 2, node, vec![ViewArg::Number(seconds)], promise) }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
unsafe extern "C" {
|
|
182
|
+
fn bake_view_video_install(engine: *mut std::ffi::c_void, host: *const std::ffi::c_void, release: unsafe extern "C" fn(*const std::ffi::c_void)) -> bool;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// Installs native.$views.Video.* on a runtime (`Modules::on_engine`, the JS thread) for a Rust host whose
|
|
186
|
+
/// build compiles VideoViewJSI.h with BAKE_VIEWS_RUST_HOST. False when the engine is not an BakeNative one.
|
|
187
|
+
pub fn install_jsi(engine: *mut std::ffi::c_void, host: std::sync::Arc<bake_runtime::native_views::ViewHost>) -> bool {
|
|
188
|
+
unsafe { bake_view_video_install(engine, host.into_raw(), bake_runtime::native_views::ViewHost::release_raw) }
|
|
189
|
+
}
|
package/views.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Native views (docs/design/native-views.md): what every generated view component shares.
|
|
2
|
+
|
|
3
|
+
/** Box and global props of a native view: they style and label the box; the view never sees them. */
|
|
4
|
+
export interface BakeNativeViewBoxProps<R> {
|
|
5
|
+
class?: string;
|
|
6
|
+
style?: Record<string, string | number> | string;
|
|
7
|
+
id?: string;
|
|
8
|
+
hidden?: boolean;
|
|
9
|
+
/** Accessibility role of the box (default: the spec's `role`). */
|
|
10
|
+
role?: string;
|
|
11
|
+
'aria-label'?: string;
|
|
12
|
+
testID?: string;
|
|
13
|
+
'data-testid'?: string;
|
|
14
|
+
/** The view's commands (`<Name>Ref`). */
|
|
15
|
+
ref?: { current: R | null } | ((ref: R | null) => void);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Every view ref: `node` is the element (web) or the node handle (native). */
|
|
19
|
+
export interface BakeNativeViewRef {
|
|
20
|
+
readonly node: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Runs a view command on a mounted view (the generated refs call this). */
|
|
24
|
+
export declare function viewCommand(el: unknown, view: string, command: string, args: unknown[]): Promise<any>;
|