euv_core/platform/miniapp/struct.rs
1use super::*;
2
3/// Bounding geometry of the floating Mini-Program menu capsule button (`getMenuButtonBoundingClientRect`).
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct MiniAppCapsuleRect {
6 /// Top offset from screen top in logical dp.
7 #[get(type(copy))]
8 pub(crate) top: f32,
9 /// Right edge offset from screen left in logical dp.
10 #[get(type(copy))]
11 pub(crate) right: f32,
12 /// Bottom edge offset from screen top in logical dp.
13 #[get(type(copy))]
14 pub(crate) bottom: f32,
15 /// Left edge offset from screen left in logical dp.
16 #[get(type(copy))]
17 pub(crate) left: f32,
18 /// Capsule width in logical dp.
19 #[get(type(copy))]
20 pub(crate) width: f32,
21 /// Capsule height in logical dp.
22 #[get(type(copy))]
23 pub(crate) height: f32,
24}
25
26/// Normalized host device, window, status bar, safe-area, and capsule metrics across all Mini-Program vendors.
27#[derive(Clone, Data, Debug, PartialEq)]
28pub struct MiniAppSystemInfo {
29 /// Active super-app vendor runtime.
30 #[get(type(copy))]
31 pub(crate) vendor: MiniAppVendor,
32 /// Logical viewport width in dp.
33 #[get(type(copy))]
34 pub(crate) window_width: u32,
35 /// Logical viewport height in dp.
36 #[get(type(copy))]
37 pub(crate) window_height: u32,
38 /// Display pixel ratio (`devicePixelRatio`).
39 #[get(type(copy))]
40 pub(crate) pixel_ratio: f32,
41 /// OS status bar height in logical dp.
42 #[get(type(copy))]
43 pub(crate) status_bar_height: f32,
44 /// Raw safe-area insets reported by the host super-app.
45 #[get(type(copy))]
46 pub(crate) safe_area: SafeAreaInsets,
47 /// Floating capsule button bounding rect (`getMenuButtonBoundingClientRect`).
48 #[get(type(copy))]
49 pub(crate) capsule: MiniAppCapsuleRect,
50 /// Active super-app light/dark theme mode.
51 #[get(type(copy))]
52 pub(crate) theme: ThemeMode,
53 /// Active host BCP-47 language tag.
54 pub(crate) language: String,
55 /// Active `<canvas>` rendering mode (`Canvas2d`, `WebGl`, or `WebGl2`).
56 #[get(type(copy))]
57 pub(crate) canvas_mode: MiniAppCanvasMode,
58}
59
60/// Active Mini-Program canvas window record held by `MiniAppPlatform`.
61#[derive(Clone, Data, Debug)]
62pub struct MiniAppWindowRecord {
63 /// Window configuration snapshot.
64 pub(crate) config: WindowConfig,
65 /// Live window metrics including capsule-cleared safe-area insets.
66 #[get(type(copy))]
67 pub(crate) state: WindowState,
68 /// Registered host canvas identifier.
69 #[get(type(copy))]
70 pub(crate) canvas_id: u32,
71 /// Active rendering context mode.
72 #[get(type(copy))]
73 pub(crate) canvas_mode: MiniAppCanvasMode,
74 /// Last presented RGBA8 framebuffer snapshot.
75 pub(crate) last_frame: Framebuffer,
76 /// Total presented frames.
77 #[get(type(copy))]
78 pub(crate) present_count: u64,
79}
80
81/// Unified Rust/WASM Mini-Program host adapter abstracting WeChat, Alipay, Douyin, Baidu, QQ, Kuaishou, and HarmonyOS Atomic Service.
82#[derive(Clone, Data, Debug)]
83pub struct MiniAppPlatform {
84 /// Normalized host system info, viewport, status bar, and capsule geometry.
85 pub(crate) system_info: MiniAppSystemInfo,
86 /// Resolved safe-area insets accounting for both OS notches and the floating capsule pill.
87 #[get(type(copy))]
88 pub(crate) resolved_safe_area: SafeAreaInsets,
89 /// Monotonic window identifier allocator.
90 #[get(pub(crate), type(copy))]
91 #[get_mut(pub(crate))]
92 #[set(pub(crate))]
93 pub(crate) next_id: u64,
94 /// Primary Mini-Program canvas window handle, if created.
95 #[get(skip)]
96 pub(crate) primary_window: Option<WindowId>,
97 /// Active Mini-Program canvas windows indexed by `WindowId`.
98 pub(crate) windows: HashMap<WindowId, MiniAppWindowRecord>,
99 /// Multi-touch contact lifecycle tracker handling `touchstart`/`touchmove`/`touchend`/`touchcancel`.
100 pub(crate) touch_tracker: TouchPointerTracker,
101 /// Queued normalized `WindowEvent` and `SystemEvent`s awaiting `poll_events()`.
102 pub(crate) pending_events: Vec<WindowEvent>,
103 /// Outbound host bridge commands drained by the thin JS/ArkTS vendor shell.
104 pub(crate) outbound_commands: Vec<MiniAppHostCommand>,
105 /// In-memory mirrored sandbox storage backing `PlatformStorage`.
106 pub(crate) storage: HashMap<String, String>,
107 /// Active page navigation stack backing `PlatformNavigation`.
108 pub(crate) route_stack: Vec<String>,
109 /// Cached clipboard text synchronized with host clipboard API.
110 #[get(skip)]
111 pub(crate) clipboard: Option<String>,
112 /// Whether the host `requestAnimationFrame` pump is paused (`onHide`/`onUnload`).
113 #[get(type(copy))]
114 pub(crate) pump_paused: bool,
115}