@mun-ui/ui 0.0.0-stage → 0.2.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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/dev-protocol.mjs +94 -0
  5. package/bin/formatter.mjs +109 -0
  6. package/bin/hot-reload.mjs +38 -0
  7. package/bin/mun.mjs +521 -0
  8. package/bin/native.mjs +133 -0
  9. package/bin/pnpm-workspace.mjs +58 -0
  10. package/bin/program-patch.mjs +104 -0
  11. package/bin/project.mjs +322 -0
  12. package/bin/watch.mjs +316 -0
  13. package/bin/workflow.mjs +261 -0
  14. package/dist/astro.d.ts +3 -0
  15. package/dist/astro.d.ts.map +1 -0
  16. package/dist/astro.js +3 -0
  17. package/dist/astro.js.map +1 -0
  18. package/dist/closures.d.ts +2 -0
  19. package/dist/closures.d.ts.map +1 -0
  20. package/dist/closures.js +2 -0
  21. package/dist/closures.js.map +1 -0
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.d.ts.map +1 -0
  24. package/dist/compiler/index.js +2 -0
  25. package/dist/compiler/index.js.map +1 -0
  26. package/dist/core.d.ts +3 -0
  27. package/dist/core.d.ts.map +1 -0
  28. package/dist/core.js +3 -0
  29. package/dist/core.js.map +1 -0
  30. package/dist/experimental.d.ts +2 -0
  31. package/dist/experimental.d.ts.map +1 -0
  32. package/dist/experimental.js +2 -0
  33. package/dist/experimental.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +3 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsx-dev-runtime.d.ts +2 -0
  39. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  40. package/dist/jsx-dev-runtime.js +2 -0
  41. package/dist/jsx-dev-runtime.js.map +1 -0
  42. package/dist/jsx-runtime.d.ts +2 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/jsx-runtime.js.map +1 -0
  46. package/dist/legacy.d.ts +3 -0
  47. package/dist/legacy.d.ts.map +1 -0
  48. package/dist/legacy.js +3 -0
  49. package/dist/legacy.js.map +1 -0
  50. package/dist/mun.d.ts +5 -0
  51. package/dist/mun.d.ts.map +1 -0
  52. package/dist/mun.js +4 -0
  53. package/dist/mun.js.map +1 -0
  54. package/dist/progressive-blur/index.d.ts +8 -0
  55. package/dist/progressive-blur/index.d.ts.map +1 -0
  56. package/dist/progressive-blur/index.js +8 -0
  57. package/dist/progressive-blur/index.js.map +1 -0
  58. package/dist/progressive-blur/plan.d.ts +3 -0
  59. package/dist/progressive-blur/plan.d.ts.map +1 -0
  60. package/dist/progressive-blur/plan.js +3 -0
  61. package/dist/progressive-blur/plan.js.map +1 -0
  62. package/dist/react-types.d.ts +2 -0
  63. package/dist/react-types.d.ts.map +1 -0
  64. package/dist/react-types.js +2 -0
  65. package/dist/react-types.js.map +1 -0
  66. package/dist/rendering-quality.d.ts +4 -0
  67. package/dist/rendering-quality.d.ts.map +1 -0
  68. package/dist/rendering-quality.js +4 -0
  69. package/dist/rendering-quality.js.map +1 -0
  70. package/dist/state.d.ts +2 -0
  71. package/dist/state.d.ts.map +1 -0
  72. package/dist/state.js +2 -0
  73. package/dist/state.js.map +1 -0
  74. package/dist/types.d.ts +2 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/vite.d.ts +2 -0
  79. package/dist/vite.d.ts.map +1 -0
  80. package/dist/vite.js +2 -0
  81. package/dist/vite.js.map +1 -0
  82. package/editors/install.mjs +102 -0
  83. package/editors/lsp/mun-lsp.mjs +123 -0
  84. package/editors/lsp/service.mjs +306 -0
  85. package/editors/lsp/source.mjs +58 -0
  86. package/editors/vscode/client.mjs +40 -0
  87. package/editors/vscode/dev-client.mjs +83 -0
  88. package/editors/vscode/discovery.mjs +46 -0
  89. package/editors/vscode/export.mjs +42 -0
  90. package/editors/vscode/extension.cjs +226 -0
  91. package/editors/vscode/language-configuration.json +15 -0
  92. package/editors/vscode/package.json +119 -0
  93. package/editors/vscode/protocol.mjs +29 -0
  94. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  95. package/native/Cargo.lock +3581 -0
  96. package/native/Cargo.toml +21 -0
  97. package/native/README.md +21 -0
  98. package/native/mun-native/Cargo.toml +23 -0
  99. package/native/mun-native/src/accessibility.rs +738 -0
  100. package/native/mun-native/src/dev.rs +604 -0
  101. package/native/mun-native/src/lib.rs +2676 -0
  102. package/native/mun-native/src/main.rs +204 -0
  103. package/native/mun-native/src/offscreen.rs +393 -0
  104. package/native/mun-native/src/rect.wgsl +63 -0
  105. package/native/mun-native/src/text.rs +310 -0
  106. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  107. package/native/mun-native/tests/stress.rs +408 -0
  108. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  109. package/native/mun-runtime/Cargo.toml +13 -0
  110. package/native/mun-runtime/src/accessibility.rs +193 -0
  111. package/native/mun-runtime/src/collection.rs +1073 -0
  112. package/native/mun-runtime/src/gesture.rs +1070 -0
  113. package/native/mun-runtime/src/input.rs +325 -0
  114. package/native/mun-runtime/src/ir.rs +782 -0
  115. package/native/mun-runtime/src/kinetics.rs +500 -0
  116. package/native/mun-runtime/src/layout.rs +173 -0
  117. package/native/mun-runtime/src/layout_cache.rs +209 -0
  118. package/native/mun-runtime/src/lib.rs +49 -0
  119. package/native/mun-runtime/src/motion.rs +1162 -0
  120. package/native/mun-runtime/src/retained.rs +574 -0
  121. package/native/mun-runtime/src/runtime.rs +7078 -0
  122. package/native/mun-runtime/src/scene.rs +530 -0
  123. package/native/mun-runtime/src/scroll.rs +521 -0
  124. package/native/mun-runtime/src/scroll_view.rs +220 -0
  125. package/native/mun-runtime/src/text_edit.rs +670 -0
  126. package/native/mun-runtime/src/timeline.rs +1534 -0
  127. package/native/mun-runtime/src/validate.rs +677 -0
  128. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  129. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  130. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  131. package/native/mun-runtime/tests/hot_update.rs +367 -0
  132. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  133. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  134. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  135. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  136. package/native/mun-runtime/tests/native_demo.rs +285 -0
  137. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  138. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  139. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  140. package/native/mun-runtime/tests/text_editing.rs +491 -0
  141. package/package.json +210 -3
  142. package/schemas/README.md +19 -0
  143. package/schemas/semantic-ui-ir-v1.schema.json +1972 -0
  144. package/templates/native/App.mun +15 -0
  145. package/templates/native/gitignore +3 -0
  146. package/templates/native/mun.toml +8 -0
  147. package/templates/project/gitignore +5 -0
  148. package/templates/project/index.html +13 -0
  149. package/templates/project/package.json +21 -0
  150. package/templates/project/src/App.mun +13 -0
  151. package/templates/project/src/index.css +21 -0
  152. package/templates/project/src/main.ts +5 -0
  153. package/templates/project/tsconfig.json +20 -0
  154. package/templates/project/vite.config.ts +6 -0
  155. package/templates/vite/src/App.css +134 -0
  156. package/templates/vite/src/App.tsx +91 -0
  157. package/templates/vite/src/index.css +23 -0
  158. package/templates/vite/vite.config.ts +10 -0
@@ -0,0 +1,285 @@
1
+ use mun_runtime::Runtime;
2
+
3
+ const PROGRAM: &str = include_str!("../../generated/NativeDemo.json");
4
+
5
+ fn parsed_program() -> serde_json::Value {
6
+ serde_json::from_str(PROGRAM).expect("parse compiler UI IR")
7
+ }
8
+
9
+ fn child_id(program: &serde_json::Value, index: usize) -> &str {
10
+ program["root"]["child"]["children"][index]["id"]
11
+ .as_str()
12
+ .expect("compiled semantic node identity")
13
+ }
14
+
15
+ fn demo_child_id(index: usize) -> String {
16
+ let program = parsed_program();
17
+ child_id(&program, index).to_owned()
18
+ }
19
+
20
+ fn panel_width(runtime: &Runtime) -> f32 {
21
+ let panel_id = demo_child_id(2);
22
+ runtime
23
+ .build_scene(640.0, 420.0)
24
+ .expect("build scene")
25
+ .rects
26
+ .iter()
27
+ .find(|item| item.id == panel_id)
28
+ .expect("animated panel")
29
+ .rect
30
+ .width
31
+ }
32
+
33
+ #[test]
34
+ fn state_transaction_drives_motion_layout_and_scene() {
35
+ let mut runtime = Runtime::from_json(PROGRAM).expect("load compiler UI IR");
36
+ let action_id = demo_child_id(1);
37
+ assert!((panel_width(&runtime) - 160.0).abs() < 0.01);
38
+
39
+ let transaction = runtime
40
+ .activate_action(&action_id)
41
+ .expect("activate semantic action");
42
+ assert_eq!(transaction.mutations.len(), 1);
43
+ let program: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse compiler UI IR");
44
+ let expanded_state = program["states"][0]["name"]
45
+ .as_str()
46
+ .expect("compiled state identity");
47
+ assert_eq!(transaction.mutations[0].state, expanded_state);
48
+ assert!(runtime.has_active_motion());
49
+
50
+ runtime.step(0.08);
51
+ let in_flight = panel_width(&runtime);
52
+ assert!(in_flight > 160.0 && in_flight < 320.0);
53
+
54
+ for _ in 0..360 {
55
+ runtime.step(1.0 / 120.0);
56
+ }
57
+
58
+ assert!((panel_width(&runtime) - 320.0).abs() < 0.05);
59
+ }
60
+
61
+ #[test]
62
+ fn accessibility_tree_tracks_semantics_focus_and_animated_layout() {
63
+ use mun_runtime::ir::AccessibilityRole;
64
+
65
+ let mut runtime = Runtime::from_json(PROGRAM).expect("load compiler UI IR");
66
+ let text_id = demo_child_id(0);
67
+ let action_id = demo_child_id(1);
68
+ let panel_id = demo_child_id(2);
69
+ let initial = runtime
70
+ .build_accessibility_tree(640.0, 420.0)
71
+ .expect("build accessibility tree");
72
+ assert_eq!(initial.root_id, "window-root");
73
+ assert_eq!(initial.focus_id, None);
74
+ assert_eq!(
75
+ initial.node("window-root").unwrap().role,
76
+ AccessibilityRole::Window
77
+ );
78
+ assert_eq!(
79
+ initial.node(&text_id).unwrap().label.as_deref(),
80
+ Some("Mün")
81
+ );
82
+ let action = initial.node(&action_id).expect("accessible action");
83
+ assert_eq!(action.role, AccessibilityRole::Button);
84
+ assert_eq!(action.label.as_deref(), Some("Toggle"));
85
+ assert!(action.enabled);
86
+ assert_eq!(action.action_id.as_deref(), Some(action_id.as_str()));
87
+ assert!((initial.node(&panel_id).unwrap().bounds.width - 160.0).abs() < 0.01);
88
+
89
+ assert!(runtime.focus_action(&action_id));
90
+ runtime
91
+ .activate_focused()
92
+ .expect("activate accessible action");
93
+ runtime.step(0.08);
94
+
95
+ let animated = runtime
96
+ .build_accessibility_tree(640.0, 420.0)
97
+ .expect("build animated accessibility tree");
98
+ assert_eq!(animated.focus_id.as_deref(), Some(action_id.as_str()));
99
+ assert!(animated.node(&action_id).unwrap().focused);
100
+ let width = animated.node(&panel_id).unwrap().bounds.width;
101
+ assert!(width > 160.0 && width < 320.0);
102
+ }
103
+
104
+ #[test]
105
+ fn disabled_semantic_action_cannot_activate_from_any_backend() {
106
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
107
+ let action_id = child_id(&value, 1).to_owned();
108
+ value["root"]["child"]["children"][1]["accessibility"]["enabled"] = serde_json::json!({
109
+ "kind": "literal",
110
+ "value": false
111
+ });
112
+ let json = serde_json::to_string(&value).expect("serialize disabled IR");
113
+ let mut runtime = Runtime::from_json(&json).expect("load disabled compiler UI IR");
114
+
115
+ let tree = runtime
116
+ .build_accessibility_tree(640.0, 420.0)
117
+ .expect("build disabled accessibility tree");
118
+ assert!(!tree.node(&action_id).expect("action node").enabled);
119
+ assert!(runtime.activate_action(&action_id).is_none());
120
+ assert!((panel_width(&runtime) - 160.0).abs() < 0.01);
121
+ }
122
+
123
+ #[test]
124
+ fn animation_value_trigger_must_change_before_target_motion_starts() {
125
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
126
+ let action_id = child_id(&value, 1).to_owned();
127
+ value["root"]["child"]["children"][2]["motion"][0]["trigger"] = serde_json::json!({
128
+ "kind": "literal",
129
+ "value": false
130
+ });
131
+ let json = serde_json::to_string(&value).expect("serialize fixed-trigger IR");
132
+ let mut runtime = Runtime::from_json(&json).expect("load fixed-trigger compiler UI IR");
133
+
134
+ runtime
135
+ .activate_action(&action_id)
136
+ .expect("toggle width state");
137
+ assert!(!runtime.has_active_motion());
138
+ assert!((panel_width(&runtime) - 320.0).abs() < 0.01);
139
+ }
140
+
141
+ #[test]
142
+ fn semantic_focus_traversal_skips_disabled_actions_and_wraps() {
143
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
144
+ let first_id = child_id(&value, 1).to_owned();
145
+ let first = value["root"]["child"]["children"][1].clone();
146
+
147
+ let mut disabled = first.clone();
148
+ disabled["id"] = serde_json::json!("action-disabled");
149
+ disabled["label"] = serde_json::json!("Disabled");
150
+ disabled["accessibility"]["enabled"] = serde_json::json!({
151
+ "kind": "literal",
152
+ "value": false
153
+ });
154
+
155
+ let mut second = first.clone();
156
+ second["id"] = serde_json::json!("action-second");
157
+ second["label"] = serde_json::json!("Second");
158
+
159
+ let children = value["root"]["child"]["children"]
160
+ .as_array_mut()
161
+ .expect("column children");
162
+ children.insert(2, disabled);
163
+ children.insert(3, second);
164
+
165
+ let json = serde_json::to_string(&value).expect("serialize focus IR");
166
+ let mut runtime = Runtime::from_json(&json).expect("load focus compiler UI IR");
167
+
168
+ assert_eq!(
169
+ runtime.focus_next_action(false).as_deref(),
170
+ Some(first_id.as_str())
171
+ );
172
+ assert_eq!(
173
+ runtime.focus_next_action(false).as_deref(),
174
+ Some("action-second")
175
+ );
176
+ assert_eq!(
177
+ runtime.focus_next_action(false).as_deref(),
178
+ Some(first_id.as_str())
179
+ );
180
+ assert_eq!(
181
+ runtime.focus_next_action(true).as_deref(),
182
+ Some("action-second")
183
+ );
184
+ assert!(!runtime.focus_action("action-disabled"));
185
+ assert_eq!(runtime.focused_action(), Some("action-second"));
186
+ }
187
+
188
+ #[test]
189
+ fn transaction_animation_is_fallback_for_dynamic_property_without_local_plan() {
190
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
191
+ let action_id = child_id(&value, 1).to_owned();
192
+ let panel_binding = &mut value["root"]["child"]["children"][2]["motion"][0];
193
+ let plan = panel_binding["plan"].take();
194
+ panel_binding
195
+ .as_object_mut()
196
+ .expect("motion binding")
197
+ .remove("plan");
198
+ value["root"]["child"]["children"][1]["action"]["transaction"] = serde_json::json!({
199
+ "animation": plan,
200
+ "disablesAnimations": false,
201
+ "isContinuous": false
202
+ });
203
+
204
+ let json = serde_json::to_string(&value).expect("serialize transaction IR");
205
+ let mut runtime = Runtime::from_json(&json).expect("load transaction IR");
206
+ let transaction = runtime
207
+ .activate_action(&action_id)
208
+ .expect("activate transaction action");
209
+ assert!(transaction.animation.is_some());
210
+ assert!(runtime.has_active_motion());
211
+
212
+ runtime.step(0.08);
213
+ let width = panel_width(&runtime);
214
+ assert!(width > 160.0 && width < 320.0);
215
+ }
216
+
217
+ #[test]
218
+ fn local_animation_override_wins_over_surrounding_transaction() {
219
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
220
+ let action_id = child_id(&value, 1).to_owned();
221
+ let mut delayed = value["root"]["child"]["children"][2]["motion"][0]["plan"].clone();
222
+ delayed["delayMs"] = serde_json::json!(1000.0);
223
+ value["root"]["child"]["children"][1]["action"]["transaction"] = serde_json::json!({
224
+ "animation": delayed,
225
+ "disablesAnimations": false,
226
+ "isContinuous": false
227
+ });
228
+
229
+ let json = serde_json::to_string(&value).expect("serialize override IR");
230
+ let mut runtime = Runtime::from_json(&json).expect("load override IR");
231
+ runtime
232
+ .activate_action(&action_id)
233
+ .expect("activate override action");
234
+ runtime.step(0.08);
235
+
236
+ assert!(
237
+ panel_width(&runtime) > 160.0,
238
+ "local spring must not inherit transaction delay"
239
+ );
240
+ }
241
+
242
+ #[test]
243
+ fn null_transaction_animation_snaps_property_without_local_override() {
244
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
245
+ let action_id = child_id(&value, 1).to_owned();
246
+ value["root"]["child"]["children"][2]["motion"][0]
247
+ .as_object_mut()
248
+ .expect("motion binding")
249
+ .remove("plan");
250
+ value["root"]["child"]["children"][1]["action"]["transaction"] = serde_json::json!({
251
+ "animation": null,
252
+ "disablesAnimations": false,
253
+ "isContinuous": false
254
+ });
255
+
256
+ let json = serde_json::to_string(&value).expect("serialize null transaction IR");
257
+ let mut runtime = Runtime::from_json(&json).expect("load null transaction IR");
258
+ let transaction = runtime
259
+ .activate_action(&action_id)
260
+ .expect("activate null transaction action");
261
+ assert!(transaction.animation.is_none());
262
+ assert!(!runtime.has_active_motion());
263
+ assert!((panel_width(&runtime) - 320.0).abs() < 0.01);
264
+ }
265
+
266
+ #[test]
267
+ fn disabling_transaction_suppresses_even_property_local_animation() {
268
+ let mut value: serde_json::Value = serde_json::from_str(PROGRAM).expect("parse demo IR");
269
+ let action_id = child_id(&value, 1).to_owned();
270
+ value["root"]["child"]["children"][1]["action"]["transaction"] = serde_json::json!({
271
+ "animation": value["root"]["child"]["children"][2]["motion"][0]["plan"].clone(),
272
+ "disablesAnimations": true,
273
+ "isContinuous": true
274
+ });
275
+
276
+ let json = serde_json::to_string(&value).expect("serialize disabled transaction IR");
277
+ let mut runtime = Runtime::from_json(&json).expect("load disabled transaction IR");
278
+ let transaction = runtime
279
+ .activate_action(&action_id)
280
+ .expect("activate disabled transaction action");
281
+ assert!(transaction.disables_animations);
282
+ assert!(transaction.is_continuous);
283
+ assert!(!runtime.has_active_motion());
284
+ assert!((panel_width(&runtime) - 320.0).abs() < 0.01);
285
+ }
@@ -0,0 +1,175 @@
1
+ use std::{env, fs};
2
+
3
+ use mun_runtime::Runtime;
4
+ use serde_json::Value;
5
+
6
+ fn approx(actual: f32, expected: f32) {
7
+ assert!(
8
+ (actual - expected).abs() < 0.01,
9
+ "expected {expected}, got {actual}"
10
+ );
11
+ }
12
+
13
+ fn color_approx(actual: [f32; 4], expected: [f32; 4]) {
14
+ for (actual, expected) in actual.into_iter().zip(expected) {
15
+ assert!(
16
+ (actual - expected).abs() < 0.001,
17
+ "expected color channel {expected}, got {actual}"
18
+ );
19
+ }
20
+ }
21
+
22
+ fn child(node: &Value, index: usize) -> &Value {
23
+ &node["children"][index]
24
+ }
25
+
26
+ #[test]
27
+ #[ignore = "run through scripts/test-native-ui.sh after compiling canonical .mun source"]
28
+ fn canonical_source_renders_stack_geometry_and_styles() {
29
+ let path =
30
+ env::var("MUN_NATIVE_UI_IR").expect("MUN_NATIVE_UI_IR must point at compiler-produced IR");
31
+ let source = fs::read_to_string(&path).expect("read compiler-produced UI IR");
32
+ let program: Value = serde_json::from_str(&source).expect("parse compiler-produced UI IR");
33
+
34
+ // SwiftUI layering: `.frame(240, 220).padding(10).background(c)` is a
35
+ // padding view (with the background) around a 240×220 frame around the
36
+ // VStack, which the frame centers.
37
+ let padded = &program["root"]["child"];
38
+ assert_eq!(padded["kind"], "overlay");
39
+ let framed = child(padded, 0);
40
+ assert_eq!(framed["kind"], "overlay");
41
+ let stack = child(framed, 0);
42
+ assert_eq!(stack["kind"], "column");
43
+ let row = child(stack, 0);
44
+ let overlay = child(stack, 1);
45
+ let text = child(stack, 2);
46
+ assert_eq!(row["kind"], "row");
47
+ assert_eq!(overlay["kind"], "overlay");
48
+ assert_eq!(text["kind"], "text");
49
+
50
+ let padded_id = padded["id"].as_str().expect("padding id");
51
+ let framed_id = framed["id"].as_str().expect("frame id");
52
+ let stack_id = stack["id"].as_str().expect("stack id");
53
+ let row_id = row["id"].as_str().expect("row id");
54
+ let red_id = child(row, 0)["id"].as_str().expect("red id");
55
+ let green_id = child(row, 1)["id"].as_str().expect("green id");
56
+ let overlay_id = overlay["id"].as_str().expect("overlay id");
57
+ let blue_id = child(overlay, 0)["id"].as_str().expect("blue id");
58
+ let small_id = child(overlay, 1)["id"].as_str().expect("small id");
59
+
60
+ let runtime = Runtime::from_json(&source).expect("load compiler-produced UI IR");
61
+ let accessibility = runtime
62
+ .build_accessibility_tree(640.0, 420.0)
63
+ .expect("build native layout/accessibility tree");
64
+ let bounds = |id: &str| accessibility.node(id).expect("node bounds").bounds;
65
+
66
+ // The fixed-size root is centered in the 640×420 window.
67
+ let padded_bounds = bounds(padded_id);
68
+ approx(padded_bounds.width, 260.0);
69
+ approx(padded_bounds.height, 240.0);
70
+ approx(padded_bounds.x, 190.0);
71
+ approx(padded_bounds.y, 90.0);
72
+ let framed_bounds = bounds(framed_id);
73
+ approx(framed_bounds.width, 240.0);
74
+ approx(framed_bounds.height, 220.0);
75
+ approx(framed_bounds.x, padded_bounds.x + 10.0);
76
+ approx(framed_bounds.y, padded_bounds.y + 10.0);
77
+
78
+ // The frame centers the VStack vertically.
79
+ let stack_bounds = bounds(stack_id);
80
+ approx(
81
+ stack_bounds.y - framed_bounds.y,
82
+ framed_bounds.y + framed_bounds.height - (stack_bounds.y + stack_bounds.height),
83
+ );
84
+
85
+ let row_bounds = bounds(row_id);
86
+ let red_bounds = bounds(red_id);
87
+ let green_bounds = bounds(green_id);
88
+ approx(row_bounds.width, 110.0);
89
+ approx(row_bounds.height, 30.0);
90
+ approx(
91
+ row_bounds.x - stack_bounds.x,
92
+ (stack_bounds.width - 110.0) / 2.0,
93
+ );
94
+ approx(row_bounds.y, stack_bounds.y);
95
+ approx(red_bounds.width, 40.0);
96
+ approx(red_bounds.height, 20.0);
97
+ approx(green_bounds.width, 60.0);
98
+ approx(green_bounds.height, 30.0);
99
+ approx(green_bounds.x - red_bounds.x, 50.0);
100
+ approx(
101
+ red_bounds.y + red_bounds.height,
102
+ green_bounds.y + green_bounds.height,
103
+ );
104
+
105
+ let overlay_bounds = bounds(overlay_id);
106
+ let blue_bounds = bounds(blue_id);
107
+ let small_bounds = bounds(small_id);
108
+ approx(overlay_bounds.width, 120.0);
109
+ approx(overlay_bounds.height, 80.0);
110
+ approx(
111
+ overlay_bounds.x - stack_bounds.x,
112
+ (stack_bounds.width - 120.0) / 2.0,
113
+ );
114
+ approx(overlay_bounds.y, row_bounds.y + row_bounds.height + 12.0);
115
+ approx(blue_bounds.x, overlay_bounds.x);
116
+ approx(blue_bounds.y, overlay_bounds.y);
117
+ approx(small_bounds.width, 40.0);
118
+ approx(small_bounds.height, 20.0);
119
+ approx(small_bounds.x, overlay_bounds.x + 40.0);
120
+ approx(small_bounds.y, overlay_bounds.y + 30.0);
121
+
122
+ let scene = runtime
123
+ .build_scene(640.0, 420.0)
124
+ .expect("build native scene");
125
+ let rect = |id: &str| {
126
+ scene
127
+ .rects
128
+ .iter()
129
+ .find(|item| item.id == id)
130
+ .unwrap_or_else(|| panic!("scene rect {id}"))
131
+ };
132
+
133
+ // The background was applied after the padding, so it covers it.
134
+ let padded_rect = rect(padded_id);
135
+ color_approx(
136
+ padded_rect.color.0,
137
+ [1.0 / 255.0, 2.0 / 255.0, 3.0 / 255.0, 1.0],
138
+ );
139
+ approx(padded_rect.rect.width, 260.0);
140
+ approx(padded_rect.rect.height, 240.0);
141
+
142
+ let red = rect(red_id);
143
+ color_approx(red.color.0, [1.0, 0.0, 0.0, 1.0]);
144
+ approx(red.corner_radius, 5.0);
145
+
146
+ let green = rect(green_id);
147
+ color_approx(green.color.0, [0.0, 1.0, 0.0, 0.5]);
148
+
149
+ let blue = rect(blue_id);
150
+ color_approx(
151
+ blue.color.0,
152
+ [
153
+ 0x11 as f32 / 255.0,
154
+ 0x22 as f32 / 255.0,
155
+ 0x33 as f32 / 255.0,
156
+ 1.0,
157
+ ],
158
+ );
159
+ approx(blue.corner_radius, 12.0);
160
+
161
+ let styled = scene
162
+ .texts
163
+ .iter()
164
+ .find(|item| item.text == "Styled")
165
+ .expect("styled text");
166
+ color_approx(
167
+ styled.color.0,
168
+ [
169
+ 0xAB as f32 / 255.0,
170
+ 0xCD as f32 / 255.0,
171
+ 0xEF as f32 / 255.0,
172
+ 1.0,
173
+ ],
174
+ );
175
+ }
@@ -0,0 +1,152 @@
1
+ //! Compiler-produced `examples/NativeSettingsPane.mun`: Toggle, Spacer,
2
+ //! Divider, SecureField, ProgressView and onAppear/onDisappear end to end.
3
+
4
+ use std::{env, fs};
5
+
6
+ use mun_runtime::{Runtime, ir::AccessibilityRole};
7
+ use serde_json::Value;
8
+
9
+ const WIDTH: f32 = 640.0;
10
+ const HEIGHT: f32 = 480.0;
11
+
12
+ fn approx(actual: f32, expected: f32) {
13
+ assert!(
14
+ (actual - expected).abs() < 0.01,
15
+ "expected {expected}, got {actual}"
16
+ );
17
+ }
18
+
19
+ fn state<'a>(program: &'a Value, suffix: &str) -> &'a str {
20
+ program["states"]
21
+ .as_array()
22
+ .expect("states")
23
+ .iter()
24
+ .find_map(|state| {
25
+ let name = state["name"].as_str()?;
26
+ name.ends_with(suffix).then_some(name)
27
+ })
28
+ .unwrap_or_else(|| panic!("state ending in {suffix}"))
29
+ }
30
+
31
+ #[test]
32
+ #[ignore = "run through scripts/verify-native-contracts.mjs after compiling canonical .mun source"]
33
+ fn settings_pane_controls_layout_and_lifecycle() {
34
+ let path = env::var("MUN_NATIVE_SETTINGS_IR")
35
+ .expect("MUN_NATIVE_SETTINGS_IR must point at compiler-produced IR");
36
+ let source = fs::read_to_string(&path).expect("read compiler-produced UI IR");
37
+ let program: Value = serde_json::from_str(&source).expect("parse UI IR");
38
+ let column = &program["root"]["child"]["children"][0];
39
+ let id = |node: &Value| node["id"].as_str().expect("id").to_owned();
40
+ let wifi_row = &column["children"][0];
41
+ let (wifi, wifi_spacer, wifi_value) = (
42
+ id(&wifi_row["children"][0]),
43
+ id(&wifi_row["children"][1]),
44
+ id(&wifi_row["children"][2]),
45
+ );
46
+ let divider = id(&column["children"][2]);
47
+ let password = id(&column["children"][3]);
48
+ let progress = id(&column["children"][4]);
49
+ let wifi_state = state(&program, "/wifi");
50
+ let visits = state(&program, "/visits");
51
+
52
+ let mut runtime = Runtime::from_json(&source).expect("load compiled IR");
53
+ let frame = runtime.build_frame(WIDTH, HEIGHT).expect("frame");
54
+ let bounds = |id: &str| {
55
+ frame
56
+ .accessibility
57
+ .nodes
58
+ .iter()
59
+ .find(|node| node.id == id)
60
+ .unwrap_or_else(|| panic!("accessibility node {id}"))
61
+ .clone()
62
+ };
63
+
64
+ // A Spacer makes its HStack fill the 420pt column and pushes the value
65
+ // text to the trailing edge; the Divider is a 1pt rule across the column.
66
+ let column_bounds = bounds(&id(column)).bounds;
67
+ approx(column_bounds.width, 420.0);
68
+ let row = bounds(&id(wifi_row)).bounds;
69
+ approx(row.width, 420.0);
70
+ let value = bounds(&wifi_value).bounds;
71
+ approx(value.x + value.width, row.x + row.width);
72
+ let spacer = bounds(&wifi_spacer).bounds;
73
+ assert!(spacer.width >= 8.0, "spacer keeps its minimum length");
74
+ let rule = bounds(&divider).bounds;
75
+ approx(rule.height, 1.0);
76
+ approx(rule.width, 420.0);
77
+
78
+ // Toggle: checkbox semantics, activation flips the bound Bool.
79
+ let toggle = bounds(&wifi);
80
+ assert_eq!(toggle.role, AccessibilityRole::CheckBox);
81
+ assert_eq!(toggle.checked, Some(false));
82
+ assert_eq!(toggle.action_id.as_deref(), Some(wifi.as_str()));
83
+
84
+ // SecureField: masked presentation; nothing of the value reaches AT.
85
+ let secure = bounds(&password);
86
+ assert_eq!(secure.role, AccessibilityRole::SecureTextField);
87
+ assert!(secure.value.is_none() && secure.text.is_none());
88
+ let presented = frame
89
+ .scene
90
+ .texts
91
+ .iter()
92
+ .find(|text| text.id == format!("{password}:text"))
93
+ .expect("secure text");
94
+ assert_eq!(presented.text, "\u{2022}".repeat(4));
95
+
96
+ // ProgressView: value 3 of total 4.
97
+ let bar = bounds(&progress);
98
+ assert_eq!(bar.role, AccessibilityRole::ProgressIndicator);
99
+ assert_eq!(bar.value.as_deref(), Some("75%"));
100
+ let rect = |suffix: &str| {
101
+ frame
102
+ .scene
103
+ .rects
104
+ .iter()
105
+ .find(|rect| rect.id == format!("{progress}:{suffix}"))
106
+ .unwrap_or_else(|| panic!("progress {suffix}"))
107
+ .rect
108
+ };
109
+ approx(rect("fill").width, rect("track").width * 0.75);
110
+
111
+ // Lifecycle runs once per presence change, never per frame.
112
+ let count = |runtime: &Runtime| {
113
+ runtime
114
+ .state_value(visits)
115
+ .and_then(Value::as_f64)
116
+ .expect("visits")
117
+ };
118
+ assert_eq!(count(&runtime), 0.0);
119
+ let transaction = runtime.activate_interactive(&wifi).expect("toggle on");
120
+ assert_eq!(runtime.state_value(wifi_state), Some(&Value::Bool(true)));
121
+ assert!(
122
+ transaction
123
+ .mutations
124
+ .iter()
125
+ .any(|mutation| mutation.state == visits),
126
+ "onAppear mutations belong to the transaction that caused the appearance"
127
+ );
128
+ for _ in 0..3 {
129
+ runtime.build_frame(WIDTH, HEIGHT).expect("frame");
130
+ runtime.step(1.0 / 60.0);
131
+ }
132
+ assert_eq!(count(&runtime), 1.0);
133
+ runtime.activate_interactive(&wifi).expect("toggle off");
134
+ assert_eq!(count(&runtime), 11.0);
135
+ let frame = runtime.build_frame(WIDTH, HEIGHT).expect("frame");
136
+ let toggle = frame
137
+ .accessibility
138
+ .nodes
139
+ .iter()
140
+ .find(|node| node.id == wifi)
141
+ .expect("toggle");
142
+ assert_eq!(toggle.checked, Some(false));
143
+ // Swift string interpolation renders through the runtime's number text.
144
+ assert!(
145
+ frame
146
+ .scene
147
+ .texts
148
+ .iter()
149
+ .any(|text| text.text == "Visits 11"),
150
+ "interpolated visit count"
151
+ );
152
+ }