@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,403 @@
1
+ use mun_runtime::{InputEvent, InputPoint, PointerId, Runtime, ScrollDelta, ScrollPhase};
2
+ use serde_json::{Value, json};
3
+ fn literal(value: impl Into<Value>) -> Value {
4
+ json!({"kind":"literal","value":value.into()})
5
+ }
6
+ fn action(id: &str) -> Value {
7
+ json!({"kind":"action","id":id,"label":id,"layout":{"width":literal(100),"height":literal(40)},"action":{"kind":"toggle-state","state":"flag"}})
8
+ }
9
+ fn scroll(id: &str, height: i32, children: Vec<Value>) -> Value {
10
+ json!({"kind":"scroll","id":id,"axis":"vertical","layout":{"width":literal(100),"height":literal(height)},"children":children})
11
+ }
12
+ /// Pins the content to the window's top-leading corner (SwiftUI centers a
13
+ /// fixed-size root), so the fixtures can use window coordinates directly.
14
+ fn top_leading(child: Value) -> Value {
15
+ json!({"kind":"overlay","id":"frame","alignment":"topLeading","layout":{"maxWidth":"infinity","maxHeight":"infinity"},"children":[child]})
16
+ }
17
+ fn runtime(child: Value) -> Runtime {
18
+ Runtime::from_json(&json!({"version":1,"sourceLanguage":"mun","entry":"Test","states":[{"name":"flag","initial":false}],"root":{"kind":"window","id":"window","title":"Test","child":top_leading(child)}}).to_string()).unwrap()
19
+ }
20
+ fn wheel(r: &mut Runtime, x: f32, y: f32, delta: f32) {
21
+ r.handle_input(
22
+ InputEvent::PointerMoved {
23
+ pointer: PointerId::MOUSE,
24
+ position: InputPoint::new(x, y),
25
+ },
26
+ 300.0,
27
+ 300.0,
28
+ )
29
+ .unwrap();
30
+ let outcome = r
31
+ .handle_input(
32
+ InputEvent::Scroll {
33
+ pointer: Some(PointerId::MOUSE),
34
+ delta: ScrollDelta::Pixels { x: 0.0, y: delta },
35
+ phase: ScrollPhase::Changed,
36
+ },
37
+ 300.0,
38
+ 300.0,
39
+ )
40
+ .unwrap();
41
+ assert!(outcome.needs_redraw);
42
+ }
43
+ #[test]
44
+ fn viewport_layout_extent_clipping_hit_test_and_accessibility_agree() {
45
+ let mut r = runtime(scroll(
46
+ "scroll",
47
+ 60,
48
+ vec![action("a"), action("b"), action("c")],
49
+ ));
50
+ let frame = r.build_frame(300.0, 300.0).unwrap();
51
+ assert_eq!(r.scroll_view("scroll").unwrap().extent[1], 120.0);
52
+ assert_eq!(frame.scene.action_at(20.0, 20.0), Some("a"));
53
+ assert_eq!(frame.scene.action_at(20.0, 70.0), None);
54
+ wheel(&mut r, 20.0, 20.0, -40.0);
55
+ let frame = r.build_frame(300.0, 300.0).unwrap();
56
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 40.0);
57
+ assert_eq!(frame.scene.action_at(20.0, 20.0), Some("b"));
58
+ assert_eq!(frame.accessibility.node("b").unwrap().bounds.y, 0.0);
59
+ assert_eq!(frame.accessibility.node("c").unwrap().bounds.height, 20.0);
60
+ assert_eq!(frame.scene.action_at(20.0, 70.0), None);
61
+ }
62
+ #[test]
63
+ fn nested_scroll_consumes_inner_then_routes_residual_to_outer() {
64
+ let mut r = runtime(scroll(
65
+ "outer",
66
+ 60,
67
+ vec![
68
+ scroll("inner", 40, vec![action("a"), action("b"), action("c")]),
69
+ action("d"),
70
+ action("e"),
71
+ ],
72
+ ));
73
+ wheel(&mut r, 20.0, 20.0, -90.0);
74
+ assert_eq!(r.scroll_view("inner").unwrap().offset[1], 80.0);
75
+ assert_eq!(r.scroll_view("outer").unwrap().offset[1], 10.0);
76
+ let frame = r.build_frame(300.0, 300.0).unwrap();
77
+ assert_eq!(frame.scene.action_at(20.0, 20.0), Some("c"));
78
+ assert_eq!(frame.scene.action_at(20.0, 35.0), Some("d"));
79
+ }
80
+ #[test]
81
+ fn conditional_removal_clamps_extent_and_resize_preserves_valid_offset() {
82
+ let branch = json!({"kind":"conditional","id":"branch","condition":{"kind":"state","state":"flag"},"then":[action("extra")],"otherwise":[]});
83
+ let mut r = runtime(scroll("scroll", 60, vec![action("a"), action("b"), branch]));
84
+ r.activate_action("a");
85
+ wheel(&mut r, 20.0, 20.0, -60.0);
86
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 60.0);
87
+ r.activate_action("a");
88
+ r.build_frame(300.0, 200.0).unwrap();
89
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 20.0);
90
+ assert!(
91
+ r.build_accessibility_tree(300.0, 200.0)
92
+ .unwrap()
93
+ .node("extra")
94
+ .is_none()
95
+ );
96
+ }
97
+
98
+ #[test]
99
+ fn keyboard_focus_reveals_offscreen_control_and_pointer_activates_scrolled_control() {
100
+ let mut r = runtime(scroll(
101
+ "scroll",
102
+ 60,
103
+ vec![action("a"), action("b"), action("c")],
104
+ ));
105
+ r.build_frame(300.0, 300.0).unwrap();
106
+ r.focus_next_action(false);
107
+ r.focus_next_action(false);
108
+ r.focus_next_action(false);
109
+ let frame = r.build_frame(300.0, 300.0).unwrap();
110
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 60.0);
111
+ assert_eq!(frame.accessibility.node("c").unwrap().bounds.height, 40.0);
112
+ assert_eq!(frame.scene.action_at(20.0, 30.0), Some("c"));
113
+ for event in [
114
+ InputEvent::PointerMoved {
115
+ pointer: PointerId::MOUSE,
116
+ position: InputPoint::new(20.0, 30.0),
117
+ },
118
+ InputEvent::PointerButton {
119
+ pointer: PointerId::MOUSE,
120
+ button: mun_runtime::PointerButton::Primary,
121
+ state: mun_runtime::ButtonState::Pressed,
122
+ },
123
+ InputEvent::PointerButton {
124
+ pointer: PointerId::MOUSE,
125
+ button: mun_runtime::PointerButton::Primary,
126
+ state: mun_runtime::ButtonState::Released,
127
+ },
128
+ ] {
129
+ r.handle_input(event, 300.0, 300.0).unwrap();
130
+ }
131
+ assert_eq!(r.state_value("flag").unwrap(), true);
132
+ }
133
+
134
+ #[test]
135
+ fn scroll_inside_stack_keeps_following_sibling_at_viewport_edge() {
136
+ let child = json!({"kind":"column","id":"stack","layout":{"maxWidth":"infinity"},"children":[scroll("scroll",60,vec![action("a"),action("b"),action("c")]),action("after")]});
137
+ let mut r = runtime(child);
138
+ // The flexible root column fills the 300pt window width and centers its 100pt children.
139
+ wheel(&mut r, 120.0, 20.0, -40.0);
140
+ let frame = r.build_frame(300.0, 300.0).unwrap();
141
+ assert_eq!(frame.accessibility.node("after").unwrap().bounds.x, 100.0);
142
+ assert_eq!(frame.accessibility.node("after").unwrap().bounds.y, 60.0);
143
+ assert_eq!(frame.scene.action_at(120.0, 75.0), Some("after"));
144
+ }
145
+
146
+ #[test]
147
+ fn resize_viewport_clamps_offsets_and_removal_discards_scroll_scope() {
148
+ let mut view = scroll("scroll", 60, vec![action("a"), action("b"), action("c")]);
149
+ view["layout"]["height"] = json!({"kind":"conditional","condition":{"kind":"state","state":"flag"},"then":literal(100),"otherwise":literal(60)});
150
+ let mut r = runtime(view);
151
+ wheel(&mut r, 20.0, 20.0, -60.0);
152
+ r.activate_action("a");
153
+ r.build_frame(300.0, 300.0).unwrap();
154
+ assert_eq!(r.scroll_view("scroll").unwrap().bounds.height, 100.0);
155
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 20.0);
156
+ let branch = json!({"kind":"conditional","id":"branch","condition":{"kind":"state","state":"flag"},"then":[],"otherwise":[scroll("gone",60,vec![action("x"),action("y")])]});
157
+ let mut r = runtime(branch);
158
+ r.build_frame(300.0, 300.0).unwrap();
159
+ assert!(r.scroll_view("gone").is_some());
160
+ r.activate_action("x");
161
+ r.build_frame(300.0, 300.0).unwrap();
162
+ assert!(r.scroll_view("gone").is_none());
163
+ assert!(r.focus_next_action(false).is_none());
164
+ }
165
+
166
+ #[test]
167
+ fn horizontal_scroll_and_line_input_use_logical_coordinates() {
168
+ let mut view = scroll("scroll", 40, vec![action("a"), action("b"), action("c")]);
169
+ view["axis"] = json!("horizontal");
170
+ let mut r = runtime(view);
171
+ r.handle_input(
172
+ InputEvent::PointerMoved {
173
+ pointer: PointerId::MOUSE,
174
+ position: InputPoint::new(20.0, 20.0),
175
+ },
176
+ 300.0,
177
+ 300.0,
178
+ )
179
+ .unwrap();
180
+ r.handle_input(
181
+ InputEvent::Scroll {
182
+ pointer: Some(PointerId::MOUSE),
183
+ delta: ScrollDelta::Lines { x: -2.0, y: 0.0 },
184
+ phase: ScrollPhase::Changed,
185
+ },
186
+ 300.0,
187
+ 300.0,
188
+ )
189
+ .unwrap();
190
+ let frame = r.build_frame(300.0, 300.0).unwrap();
191
+ assert_eq!(r.scroll_view("scroll").unwrap().offset[0], 64.0);
192
+ assert_eq!(frame.scene.action_at(70.0, 20.0), Some("b"));
193
+ assert_eq!(frame.scene.action_at(110.0, 20.0), None);
194
+ }
195
+
196
+ #[test]
197
+ fn duplicate_ids_inside_scroll_fail_before_layout() {
198
+ let program = json!({"version":1,"sourceLanguage":"mun","entry":"Test","states":[],"root":{"kind":"window","id":"window","title":"Test","child":top_leading(scroll("scroll",60,vec![action("same"),action("same")]))}});
199
+ assert!(
200
+ Runtime::from_json(&program.to_string())
201
+ .err()
202
+ .expect("duplicate rejected")
203
+ .to_string()
204
+ .contains("same")
205
+ );
206
+ }
207
+
208
+ fn press_key(r: &mut Runtime, logical: mun_runtime::LogicalKey) -> mun_runtime::InputOutcome {
209
+ r.handle_input(
210
+ InputEvent::Key {
211
+ logical,
212
+ physical: mun_runtime::PhysicalKey::Other,
213
+ state: mun_runtime::KeyState::Pressed,
214
+ repeat: false,
215
+ },
216
+ 300.0,
217
+ 300.0,
218
+ )
219
+ .unwrap()
220
+ }
221
+
222
+ fn offset(r: &Runtime, id: &str) -> f32 {
223
+ r.scroll_view(id).unwrap().offset[1]
224
+ }
225
+
226
+ fn pointer(r: &mut Runtime, event: InputEvent) {
227
+ r.handle_input(event, 300.0, 300.0).unwrap();
228
+ }
229
+
230
+ fn primary(state: mun_runtime::ButtonState) -> InputEvent {
231
+ InputEvent::PointerButton {
232
+ pointer: PointerId::MOUSE,
233
+ button: mun_runtime::PointerButton::Primary,
234
+ state,
235
+ }
236
+ }
237
+
238
+ fn moved(x: f32, y: f32) -> InputEvent {
239
+ InputEvent::PointerMoved {
240
+ pointer: PointerId::MOUSE,
241
+ position: InputPoint::new(x, y),
242
+ }
243
+ }
244
+
245
+ fn tall(id: &str, count: usize) -> Value {
246
+ scroll(
247
+ id,
248
+ 200,
249
+ (0..count)
250
+ .map(|index| action(&format!("{id}-{index}")))
251
+ .collect(),
252
+ )
253
+ }
254
+
255
+ #[test]
256
+ fn keyboard_scrolling_is_owned_by_the_focused_scroll_container() {
257
+ use mun_runtime::LogicalKey;
258
+ // 10 x 40pt actions in a 200pt viewport: max offset 200.
259
+ let mut r = runtime(tall("list", 10));
260
+ r.build_frame(300.0, 300.0).unwrap();
261
+ r.focus_action("list-0");
262
+ r.build_frame(300.0, 300.0).unwrap();
263
+ assert!(press_key(&mut r, LogicalKey::ArrowDown).needs_redraw);
264
+ assert_eq!(offset(&r, "list"), 40.0);
265
+ press_key(&mut r, LogicalKey::PageDown);
266
+ assert_eq!(
267
+ offset(&r, "list"),
268
+ 200.0,
269
+ "page = viewport - one line, clamped"
270
+ );
271
+ press_key(&mut r, LogicalKey::Home);
272
+ assert_eq!(offset(&r, "list"), 0.0);
273
+ press_key(&mut r, LogicalKey::End);
274
+ assert_eq!(offset(&r, "list"), 200.0);
275
+ assert!(
276
+ !press_key(&mut r, LogicalKey::PageDown).handled,
277
+ "already at end"
278
+ );
279
+ // Scrolling never moves semantic focus.
280
+ assert_eq!(r.focused_action(), Some("list-0"));
281
+ press_key(&mut r, LogicalKey::PageUp);
282
+ assert_eq!(offset(&r, "list"), 40.0);
283
+ }
284
+
285
+ #[test]
286
+ fn unfocused_keyboard_scrolling_targets_the_hovered_viewport() {
287
+ use mun_runtime::LogicalKey;
288
+ let mut r = runtime(tall("list", 10));
289
+ r.build_frame(300.0, 300.0).unwrap();
290
+ assert!(
291
+ !press_key(&mut r, LogicalKey::PageDown).handled,
292
+ "no focus, no hover"
293
+ );
294
+ pointer(&mut r, moved(20.0, 20.0));
295
+ press_key(&mut r, LogicalKey::PageDown);
296
+ assert_eq!(offset(&r, "list"), 160.0);
297
+ assert_eq!(r.focused_action(), None);
298
+ }
299
+
300
+ #[test]
301
+ fn nested_keyboard_scroll_routes_to_ancestor_when_inner_is_exhausted() {
302
+ use mun_runtime::LogicalKey;
303
+ let outer = json!({"kind":"scroll","id":"outer","axis":"vertical","layout":{"width":literal(120),"height":literal(150)},"children":[
304
+ tall("inner", 6), action("after-0"), action("after-1"), action("after-2")
305
+ ]});
306
+ let mut r = runtime(outer);
307
+ r.build_frame(300.0, 300.0).unwrap();
308
+ r.focus_action("inner-0");
309
+ r.build_frame(300.0, 300.0).unwrap();
310
+ press_key(&mut r, LogicalKey::End);
311
+ assert_eq!(offset(&r, "inner"), 40.0);
312
+ assert_eq!(offset(&r, "outer"), 0.0, "inner absorbed the movement");
313
+ press_key(&mut r, LogicalKey::ArrowDown);
314
+ assert_eq!(offset(&r, "outer"), 40.0, "residual routed to the ancestor");
315
+ }
316
+
317
+ #[test]
318
+ fn focus_reveal_through_nested_ancestors_is_minimal() {
319
+ let outer = json!({"kind":"scroll","id":"outer","axis":"vertical","layout":{"width":literal(120),"height":literal(150)},"children":[
320
+ action("before-0"), action("before-1"), tall("inner", 8)
321
+ ]});
322
+ let mut r = runtime(outer);
323
+ r.build_frame(300.0, 300.0).unwrap();
324
+ // inner viewport occupies outer content 80..280; target inner-6 sits at
325
+ // inner content 240..280.
326
+ r.focus_action("inner-6");
327
+ let frame = r.build_frame(300.0, 300.0).unwrap();
328
+ assert_eq!(offset(&r, "inner"), 80.0, "inner scrolls just enough");
329
+ assert_eq!(offset(&r, "outer"), 130.0, "outer scrolls just enough");
330
+ let bounds = frame.accessibility.node("inner-6").unwrap().bounds;
331
+ assert_eq!(
332
+ bounds.y + bounds.height,
333
+ 150.0,
334
+ "target touches the visible edge"
335
+ );
336
+ // Revealing an already visible control does not move anything.
337
+ r.focus_action("inner-5");
338
+ r.build_frame(300.0, 300.0).unwrap();
339
+ assert_eq!((offset(&r, "inner"), offset(&r, "outer")), (80.0, 130.0));
340
+ }
341
+
342
+ #[test]
343
+ fn scrollbar_presentation_drag_and_track_paging_are_semantic_scroll_operations() {
344
+ let mut r = runtime(
345
+ json!({"kind":"row","id":"stack","layout":{"alignment":"leading"},"children":[tall("list", 10), tall("short", 2)]}),
346
+ );
347
+ let scene = r.build_scene(300.0, 300.0).unwrap();
348
+ let thumb = scene
349
+ .rects
350
+ .iter()
351
+ .find(|item| item.id == "list:scrollbar-thumb")
352
+ .expect("overflowing viewport shows a thumb")
353
+ .rect;
354
+ assert!(
355
+ !scene
356
+ .rects
357
+ .iter()
358
+ .any(|item| item.id.starts_with("short:scrollbar")),
359
+ "content that fits has no scrollbar"
360
+ );
361
+ // Thumb ratio: 200/400 of a 196pt track.
362
+ assert!((thumb.height - 98.0).abs() < 0.01);
363
+
364
+ // Drag the thumb by half its travel -> half the offset range.
365
+ let (x, y) = (thumb.x + 3.0, thumb.y + 10.0);
366
+ pointer(&mut r, moved(x, y));
367
+ pointer(&mut r, primary(mun_runtime::ButtonState::Pressed));
368
+ assert_eq!(
369
+ r.focused_action(),
370
+ None,
371
+ "scrollbar presses never take focus"
372
+ );
373
+ pointer(&mut r, moved(x, y + 49.0));
374
+ assert!((offset(&r, "list") - 100.0).abs() < 0.01);
375
+ pointer(&mut r, primary(mun_runtime::ButtonState::Released));
376
+ assert_eq!(
377
+ r.state_value("flag").unwrap(),
378
+ false,
379
+ "no activation under the bar"
380
+ );
381
+
382
+ // Track press below the thumb pages forward.
383
+ let scene = r.build_scene(300.0, 300.0).unwrap();
384
+ let track = scene
385
+ .rects
386
+ .iter()
387
+ .find(|item| item.id == "list:scrollbar-track")
388
+ .unwrap()
389
+ .rect;
390
+ pointer(&mut r, moved(track.x + 3.0, track.y + track.height - 2.0));
391
+ pointer(&mut r, primary(mun_runtime::ButtonState::Pressed));
392
+ pointer(&mut r, primary(mun_runtime::ButtonState::Released));
393
+ assert_eq!(offset(&r, "list"), 200.0);
394
+ let thumb = r
395
+ .build_scene(300.0, 300.0)
396
+ .unwrap()
397
+ .rects
398
+ .into_iter()
399
+ .find(|item| item.id == "list:scrollbar-thumb")
400
+ .unwrap()
401
+ .rect;
402
+ assert!((thumb.y + thumb.height - (track.y + track.height)).abs() < 0.01);
403
+ }