@mun-ui/ui 0.0.0-stage → 0.2.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.
Files changed (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/desktop.mjs +143 -0
  5. package/bin/dev-protocol.mjs +94 -0
  6. package/bin/formatter.mjs +109 -0
  7. package/bin/hot-reload.mjs +38 -0
  8. package/bin/mun.mjs +538 -0
  9. package/bin/native.mjs +133 -0
  10. package/bin/pnpm-workspace.mjs +58 -0
  11. package/bin/program-patch.mjs +104 -0
  12. package/bin/project.mjs +322 -0
  13. package/bin/watch.mjs +316 -0
  14. package/bin/workflow.mjs +261 -0
  15. package/dist/astro.d.ts +3 -0
  16. package/dist/astro.d.ts.map +1 -0
  17. package/dist/astro.js +3 -0
  18. package/dist/astro.js.map +1 -0
  19. package/dist/closures.d.ts +2 -0
  20. package/dist/closures.d.ts.map +1 -0
  21. package/dist/closures.js +2 -0
  22. package/dist/closures.js.map +1 -0
  23. package/dist/compiler/index.d.ts +2 -0
  24. package/dist/compiler/index.d.ts.map +1 -0
  25. package/dist/compiler/index.js +2 -0
  26. package/dist/compiler/index.js.map +1 -0
  27. package/dist/core.d.ts +3 -0
  28. package/dist/core.d.ts.map +1 -0
  29. package/dist/core.js +3 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/experimental.d.ts +2 -0
  32. package/dist/experimental.d.ts.map +1 -0
  33. package/dist/experimental.js +2 -0
  34. package/dist/experimental.js.map +1 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +3 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/jsx-dev-runtime.d.ts +2 -0
  40. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  41. package/dist/jsx-dev-runtime.js +2 -0
  42. package/dist/jsx-dev-runtime.js.map +1 -0
  43. package/dist/jsx-runtime.d.ts +2 -0
  44. package/dist/jsx-runtime.d.ts.map +1 -0
  45. package/dist/jsx-runtime.js +2 -0
  46. package/dist/jsx-runtime.js.map +1 -0
  47. package/dist/legacy.d.ts +3 -0
  48. package/dist/legacy.d.ts.map +1 -0
  49. package/dist/legacy.js +3 -0
  50. package/dist/legacy.js.map +1 -0
  51. package/dist/mun.d.ts +5 -0
  52. package/dist/mun.d.ts.map +1 -0
  53. package/dist/mun.js +4 -0
  54. package/dist/mun.js.map +1 -0
  55. package/dist/progressive-blur/index.d.ts +8 -0
  56. package/dist/progressive-blur/index.d.ts.map +1 -0
  57. package/dist/progressive-blur/index.js +8 -0
  58. package/dist/progressive-blur/index.js.map +1 -0
  59. package/dist/progressive-blur/plan.d.ts +3 -0
  60. package/dist/progressive-blur/plan.d.ts.map +1 -0
  61. package/dist/progressive-blur/plan.js +3 -0
  62. package/dist/progressive-blur/plan.js.map +1 -0
  63. package/dist/react-types.d.ts +2 -0
  64. package/dist/react-types.d.ts.map +1 -0
  65. package/dist/react-types.js +2 -0
  66. package/dist/react-types.js.map +1 -0
  67. package/dist/rendering-quality.d.ts +4 -0
  68. package/dist/rendering-quality.d.ts.map +1 -0
  69. package/dist/rendering-quality.js +4 -0
  70. package/dist/rendering-quality.js.map +1 -0
  71. package/dist/state.d.ts +2 -0
  72. package/dist/state.d.ts.map +1 -0
  73. package/dist/state.js +2 -0
  74. package/dist/state.js.map +1 -0
  75. package/dist/types.d.ts +2 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +2 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/vite.d.ts +2 -0
  80. package/dist/vite.d.ts.map +1 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/vite.js.map +1 -0
  83. package/editors/install.mjs +102 -0
  84. package/editors/lsp/mun-lsp.mjs +123 -0
  85. package/editors/lsp/service.mjs +306 -0
  86. package/editors/lsp/source.mjs +58 -0
  87. package/editors/vscode/client.mjs +40 -0
  88. package/editors/vscode/dev-client.mjs +83 -0
  89. package/editors/vscode/discovery.mjs +46 -0
  90. package/editors/vscode/export.mjs +42 -0
  91. package/editors/vscode/extension.cjs +226 -0
  92. package/editors/vscode/language-configuration.json +15 -0
  93. package/editors/vscode/package.json +119 -0
  94. package/editors/vscode/protocol.mjs +29 -0
  95. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  96. package/native/Cargo.lock +3581 -0
  97. package/native/Cargo.toml +21 -0
  98. package/native/README.md +21 -0
  99. package/native/mun-native/Cargo.toml +23 -0
  100. package/native/mun-native/src/accessibility.rs +738 -0
  101. package/native/mun-native/src/dev.rs +604 -0
  102. package/native/mun-native/src/host_services.rs +202 -0
  103. package/native/mun-native/src/lib.rs +2843 -0
  104. package/native/mun-native/src/main.rs +204 -0
  105. package/native/mun-native/src/offscreen.rs +393 -0
  106. package/native/mun-native/src/rect.wgsl +63 -0
  107. package/native/mun-native/src/text.rs +401 -0
  108. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  109. package/native/mun-native/tests/stress.rs +408 -0
  110. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  111. package/native/mun-runtime/Cargo.toml +13 -0
  112. package/native/mun-runtime/src/accessibility.rs +193 -0
  113. package/native/mun-runtime/src/collection.rs +1090 -0
  114. package/native/mun-runtime/src/gesture.rs +1070 -0
  115. package/native/mun-runtime/src/input.rs +325 -0
  116. package/native/mun-runtime/src/ir.rs +852 -0
  117. package/native/mun-runtime/src/kinetics.rs +500 -0
  118. package/native/mun-runtime/src/layout.rs +258 -0
  119. package/native/mun-runtime/src/layout_cache.rs +209 -0
  120. package/native/mun-runtime/src/lib.rs +52 -0
  121. package/native/mun-runtime/src/motion.rs +1162 -0
  122. package/native/mun-runtime/src/retained.rs +574 -0
  123. package/native/mun-runtime/src/runtime.rs +7449 -0
  124. package/native/mun-runtime/src/scene.rs +567 -0
  125. package/native/mun-runtime/src/scroll.rs +521 -0
  126. package/native/mun-runtime/src/scroll_view.rs +220 -0
  127. package/native/mun-runtime/src/text_edit.rs +670 -0
  128. package/native/mun-runtime/src/timeline.rs +1534 -0
  129. package/native/mun-runtime/src/validate.rs +677 -0
  130. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  131. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  132. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  133. package/native/mun-runtime/tests/host_services.rs +107 -0
  134. package/native/mun-runtime/tests/hot_update.rs +367 -0
  135. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  136. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  137. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  138. package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
  139. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  140. package/native/mun-runtime/tests/native_demo.rs +285 -0
  141. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  142. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  143. package/native/mun-runtime/tests/priority_proposals.rs +69 -0
  144. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  145. package/native/mun-runtime/tests/text_editing.rs +491 -0
  146. package/native/mun-runtime/tests/text_proposals.rs +42 -0
  147. package/native/mun-runtime/tests/typography.rs +63 -0
  148. package/package.json +213 -3
  149. package/schemas/README.md +19 -0
  150. package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
  151. package/templates/desktop/gitignore +5 -0
  152. package/templates/desktop/package.json +10 -0
  153. package/templates/desktop/src-tauri/Cargo.toml +14 -0
  154. package/templates/desktop/src-tauri/build.rs +1 -0
  155. package/templates/desktop/src-tauri/capabilities/main.json +12 -0
  156. package/templates/desktop/src-tauri/icons/icon.icns +0 -0
  157. package/templates/desktop/src-tauri/icons/icon.ico +0 -0
  158. package/templates/desktop/src-tauri/icons/icon.png +0 -0
  159. package/templates/desktop/src-tauri/src/main.rs +2 -0
  160. package/templates/desktop/src-tauri/tauri.conf.json +42 -0
  161. package/templates/desktop/vite.config.ts +10 -0
  162. package/templates/native/App.mun +15 -0
  163. package/templates/native/gitignore +3 -0
  164. package/templates/native/mun.toml +8 -0
  165. package/templates/project/gitignore +5 -0
  166. package/templates/project/index.html +13 -0
  167. package/templates/project/package.json +24 -0
  168. package/templates/project/src/App.mun +13 -0
  169. package/templates/project/src/index.css +30 -0
  170. package/templates/project/src/main.ts +5 -0
  171. package/templates/project/tsconfig.json +20 -0
  172. package/templates/project/vite.config.ts +6 -0
  173. package/templates/vite/src/App.css +134 -0
  174. package/templates/vite/src/App.tsx +91 -0
  175. package/templates/vite/src/index.css +23 -0
  176. package/templates/vite/vite.config.ts +10 -0
@@ -0,0 +1,408 @@
1
+ #![recursion_limit = "512"]
2
+ //! Retained-runtime stress: thousands of keyed rows with per-row state,
3
+ //! conditional churn, large text, frequent text-field edits, scrolling,
4
+ //! resizing, animation retargeting and keyed reorder/insert/remove.
5
+ //!
6
+ //! `bounded_resources_under_churn` runs in the normal suite and asserts that
7
+ //! nothing grows without bound. The measurement report runs explicitly:
8
+ //!
9
+ //! cargo test --release --manifest-path native/Cargo.toml -p mun-native \
10
+ //! --test stress -- --ignored --nocapture
11
+ //!
12
+ //! (`MUN_STRESS_ROWS=1000,3000` selects the collection sizes.)
13
+ use std::time::Instant;
14
+
15
+ use mun_native::{FrameTiming, OffscreenSession};
16
+ use mun_runtime::InputEvent;
17
+ use mun_runtime::input::{PointerId, ScrollDelta, ScrollPhase};
18
+ use mun_runtime::text_edit::TextEdit;
19
+ use serde_json::{Value, json};
20
+
21
+ const FOR_EACH: &str = "list";
22
+ const NOTE: &str = "@row/note";
23
+
24
+ fn literal(value: impl Into<Value>) -> Value {
25
+ json!({"kind": "literal", "value": value.into()})
26
+ }
27
+
28
+ fn item(path: &str) -> Value {
29
+ json!({"kind": "item", "forEach": FOR_EACH, "path": [path]})
30
+ }
31
+
32
+ fn program(rows: usize, large_text: usize) -> String {
33
+ let items: Vec<Value> = (0..rows)
34
+ .map(|i| json!({"id": format!("r{i}"), "title": format!("Row {i} 한국어 ✓"), "pinned": i % 3 == 0}))
35
+ .collect();
36
+ let row_action = |id: &str, operation: Value| {
37
+ let mut action = json!({"kind": "collection", "state": "rows", "keyPath": ["id"]});
38
+ action
39
+ .as_object_mut()
40
+ .unwrap()
41
+ .extend(operation.as_object().unwrap().clone());
42
+ json!({"kind": "action", "id": id, "label": id, "action": action,
43
+ "layout": {"width": literal(40), "height": literal(24)}})
44
+ };
45
+ let width = json!({"kind": "conditional", "condition": {"kind": "state", "state": "wide"},
46
+ "then": literal(300), "otherwise": literal(60)});
47
+ json!({
48
+ "version": 1, "sourceLanguage": "mun", "entry": "Stress",
49
+ "states": [
50
+ {"name": "rows", "initial": items},
51
+ {"name": "next", "initial": 0},
52
+ {"name": "wide", "initial": false},
53
+ {"name": "draft", "initial": ""},
54
+ {"name": NOTE, "initial": "", "scope": FOR_EACH}
55
+ ],
56
+ "root": {"kind": "window", "id": "window", "title": "Stress", "child": {
57
+ "kind": "column", "id": "stack", "layout": {"spacing": 4, "alignment": "leading"}, "children": [
58
+ {"kind": "textField", "id": "draft", "state": "draft",
59
+ "layout": {"width": literal(400), "height": literal(32)}},
60
+ {"kind": "action", "id": "grow", "label": "Grow", "action": {"kind": "toggle-state", "state": "wide",
61
+ "transaction": {"animation": {"kind": "timing", "duration": 0.3, "curve": [0, 0, 1, 1],
62
+ "delayMs": 0, "repeatCount": 1, "autoreverses": false},
63
+ "disablesAnimations": false, "isContinuous": false}}},
64
+ {"kind": "action", "id": "prepend", "label": "Prepend", "action": {"kind": "sequence", "actions": [
65
+ {"kind": "collection", "state": "rows", "keyPath": ["id"], "operation": "insert", "index": literal(0),
66
+ "value": {"kind": "record", "fields": {
67
+ "id": {"kind": "binary", "operator": "add", "left": literal("n"),
68
+ "right": {"kind": "stringify", "value": {"kind": "state", "state": "next"}}},
69
+ "title": literal("Inserted"), "pinned": literal(false)}}},
70
+ {"kind": "set-state", "state": "next", "value": {"kind": "binary", "operator": "add",
71
+ "left": {"kind": "state", "state": "next"}, "right": literal(1)}}
72
+ ]}},
73
+ {"kind": "panel", "id": "bar", "layout": {"width": width.clone(), "height": literal(8)},
74
+ "visual": {"background": "#63C8A2"},
75
+ "motion": [{"property": "width", "propertyMask": 512, "value": width}]},
76
+ {"kind": "text", "id": "large", "value": literal("Lorem ipsum 한국어 日本語 ".repeat(large_text / 24 + 1)),
77
+ "layout": {"width": literal(700), "height": literal(20)}},
78
+ {"kind": "scroll", "id": "scroll", "axis": "vertical",
79
+ "layout": {"width": literal(780), "height": literal(420)}, "children": [
80
+ {"kind": "column", "id": "rows-column", "layout": {"spacing": 2}, "children": [
81
+ {"kind": "forEach", "id": FOR_EACH, "collection": {"kind": "state", "state": "rows"},
82
+ "keyPath": ["id"], "children": [
83
+ {"kind": "row", "id": "row", "layout": {"spacing": 6}, "children": [
84
+ {"kind": "text", "id": "title", "value": item("title"),
85
+ "layout": {"width": literal(200)}},
86
+ {"kind": "textField", "id": "note", "state": NOTE,
87
+ "layout": {"width": literal(160), "height": literal(24)}},
88
+ {"kind": "conditional", "id": "pin", "condition": item("pinned"),
89
+ "then": [{"kind": "text", "id": "pinned", "value": literal("pinned")}],
90
+ "otherwise": []},
91
+ row_action("toggle", json!({"operation": "update", "key": item("id"),
92
+ "path": ["pinned"], "value": {"kind": "not", "value": item("pinned")}})),
93
+ row_action("up", json!({"operation": "move", "key": item("id"), "offset": literal(-1)})),
94
+ row_action("remove", json!({"operation": "remove", "key": item("id")}))
95
+ ]}
96
+ ]}
97
+ ]}
98
+ ]}
99
+ ]
100
+ }}
101
+ })
102
+ .to_string()
103
+ }
104
+
105
+ fn key(id: &str, row: &str) -> String {
106
+ format!("{id}[s:{row}]")
107
+ }
108
+
109
+ #[derive(Default)]
110
+ struct Phase {
111
+ name: &'static str,
112
+ frames: u32,
113
+ build_micros: Vec<u128>,
114
+ render_micros: Vec<u128>,
115
+ input_micros: Vec<u128>,
116
+ }
117
+
118
+ impl Phase {
119
+ fn frame(&mut self, timing: FrameTiming) {
120
+ self.frames += 1;
121
+ self.build_micros.push(timing.build_micros);
122
+ self.render_micros.push(timing.render_micros);
123
+ }
124
+ fn report(&mut self, session: &OffscreenSession) {
125
+ fn p(values: &mut [u128], q: f64) -> u128 {
126
+ if values.is_empty() {
127
+ return 0;
128
+ }
129
+ values.sort_unstable();
130
+ values[((values.len() - 1) as f64 * q).round() as usize]
131
+ }
132
+ let stats = session.renderer_stats();
133
+ let runtime = session.runtime();
134
+ println!(
135
+ "{:<22} frames {:>4} | build p50 {:>6}µs p95 {:>6}µs | render p50 {:>6}µs p95 {:>6}µs | input p50 {:>6}µs | retained {:>6} | scoped {:>5} | text buffers {:>5} | shaped {:>6} cached {:>5} | reshapes {:>6} | rect bytes {:>8}",
136
+ self.name,
137
+ self.frames,
138
+ p(&mut self.build_micros, 0.5),
139
+ p(&mut self.build_micros, 0.95),
140
+ p(&mut self.render_micros, 0.5),
141
+ p(&mut self.render_micros, 0.95),
142
+ p(&mut self.input_micros, 0.5),
143
+ runtime.retained_tree().len(),
144
+ runtime.scoped_state_count(),
145
+ stats.text_buffers,
146
+ session.shaped_line_count(),
147
+ session.cached_line_count(),
148
+ stats.text_reshapes,
149
+ stats.rect_vertex_capacity_bytes,
150
+ );
151
+ }
152
+ }
153
+
154
+ fn timed(phase: &mut Phase, session: &mut OffscreenSession, f: impl FnOnce(&mut OffscreenSession)) {
155
+ let start = Instant::now();
156
+ f(session);
157
+ phase.input_micros.push(start.elapsed().as_micros());
158
+ let timing = session.render().unwrap();
159
+ phase.frame(timing);
160
+ }
161
+
162
+ fn scroll(session: &mut OffscreenSession, dy: f32) {
163
+ session
164
+ .input(InputEvent::PointerMoved {
165
+ pointer: PointerId::MOUSE,
166
+ position: mun_runtime::input::InputPoint::new(300.0, 400.0),
167
+ })
168
+ .unwrap();
169
+ session
170
+ .input(InputEvent::Scroll {
171
+ pointer: Some(PointerId::MOUSE),
172
+ delta: ScrollDelta::Pixels { x: 0.0, y: dy },
173
+ phase: ScrollPhase::Changed,
174
+ })
175
+ .unwrap();
176
+ }
177
+
178
+ /// Run every workload once; returns the session for inspection.
179
+ fn workload(rows: usize, cycles: usize, report: bool) -> OffscreenSession {
180
+ let mut session = OffscreenSession::new(&program(rows, 20_000), 800.0, 600.0, 2.0).unwrap();
181
+ let mut phase = Phase {
182
+ name: "initial",
183
+ ..Default::default()
184
+ };
185
+ timed(&mut phase, &mut session, |_| {});
186
+ if report {
187
+ phase.report(&session);
188
+ }
189
+
190
+ let mut phase = Phase {
191
+ name: "steady",
192
+ ..Default::default()
193
+ };
194
+ for _ in 0..cycles {
195
+ timed(&mut phase, &mut session, |_| {});
196
+ }
197
+ if report {
198
+ phase.report(&session);
199
+ }
200
+
201
+ let mut phase = Phase {
202
+ name: "typing",
203
+ ..Default::default()
204
+ };
205
+ assert!(session.runtime_mut().focus_action("draft"));
206
+ for i in 0..cycles {
207
+ timed(&mut phase, &mut session, |s| {
208
+ s.input(InputEvent::TextEdit(TextEdit::Insert(if i % 2 == 0 {
209
+ "가".into()
210
+ } else {
211
+ "a".into()
212
+ })))
213
+ .unwrap();
214
+ });
215
+ }
216
+ if report {
217
+ phase.report(&session);
218
+ }
219
+
220
+ let mut phase = Phase {
221
+ name: "row notes",
222
+ ..Default::default()
223
+ };
224
+ for i in 0..cycles.min(rows) {
225
+ timed(&mut phase, &mut session, |s| {
226
+ assert!(s.runtime_mut().focus_action(&key("note", &format!("r{i}"))));
227
+ s.input(InputEvent::TextEdit(TextEdit::Insert(format!("note {i}"))))
228
+ .unwrap();
229
+ });
230
+ }
231
+ if report {
232
+ phase.report(&session);
233
+ }
234
+
235
+ let mut phase = Phase {
236
+ name: "scrolling",
237
+ ..Default::default()
238
+ };
239
+ for i in 0..cycles {
240
+ timed(&mut phase, &mut session, |s| {
241
+ scroll(s, if i < cycles / 2 { -120.0 } else { 120.0 })
242
+ });
243
+ }
244
+ if report {
245
+ phase.report(&session);
246
+ }
247
+
248
+ let mut phase = Phase {
249
+ name: "conditional churn",
250
+ ..Default::default()
251
+ };
252
+ for i in 0..cycles {
253
+ let row = format!("r{}", (i * 7) % rows);
254
+ timed(&mut phase, &mut session, |s| {
255
+ s.runtime_mut().activate_action(&key("toggle", &row));
256
+ });
257
+ }
258
+ if report {
259
+ phase.report(&session);
260
+ }
261
+
262
+ let mut phase = Phase {
263
+ name: "keyed insert/move/rm",
264
+ ..Default::default()
265
+ };
266
+ for i in 0..cycles {
267
+ timed(&mut phase, &mut session, |s| {
268
+ s.runtime_mut().activate_action("prepend");
269
+ s.runtime_mut()
270
+ .activate_action(&key("up", &format!("r{}", (i * 13 + 5) % rows)));
271
+ s.runtime_mut()
272
+ .activate_action(&key("remove", &format!("n{i}")));
273
+ });
274
+ }
275
+ if report {
276
+ phase.report(&session);
277
+ }
278
+
279
+ let mut phase = Phase {
280
+ name: "animation retarget",
281
+ ..Default::default()
282
+ };
283
+ for _ in 0..cycles {
284
+ timed(&mut phase, &mut session, |s| {
285
+ s.runtime_mut().activate_action("grow");
286
+ s.runtime_mut().step(1.0 / 60.0);
287
+ });
288
+ }
289
+ if report {
290
+ phase.report(&session);
291
+ }
292
+
293
+ let mut phase = Phase {
294
+ name: "resizing",
295
+ ..Default::default()
296
+ };
297
+ for i in 0..cycles {
298
+ let width = 700.0 + (i % 10) as f32 * 20.0;
299
+ timed(&mut phase, &mut session, |s| {
300
+ s.resize(width, 600.0, if i % 4 == 0 { 1.0 } else { 2.0 })
301
+ });
302
+ }
303
+ session.resize(800.0, 600.0, 2.0);
304
+ if report {
305
+ phase.report(&session);
306
+ }
307
+ session
308
+ }
309
+
310
+ #[test]
311
+ fn bounded_resources_under_churn() {
312
+ let rows = 300;
313
+ let mut session = workload(rows, 40, false);
314
+ let runtime = session.runtime();
315
+ // One live scoped note per live key; removed keys released their state.
316
+ assert_eq!(runtime.scoped_state_count(), rows);
317
+ assert_eq!(
318
+ runtime
319
+ .state_value("rows")
320
+ .and_then(Value::as_array)
321
+ .map(Vec::len),
322
+ Some(rows)
323
+ );
324
+ // Text buffers track live text identities, not history.
325
+ let frame = runtime.build_frame(800.0, 600.0).unwrap();
326
+ let texts = frame.scene.texts.len();
327
+ session.render().unwrap();
328
+ let stats = session.renderer_stats();
329
+ assert!(
330
+ stats.text_buffers <= texts,
331
+ "{} buffers for {texts} texts",
332
+ stats.text_buffers
333
+ );
334
+ // The shaping cache tracks the live text set, not history.
335
+ assert!(
336
+ session.cached_line_count() <= 2 * (texts + 64),
337
+ "{} cached lines",
338
+ session.cached_line_count()
339
+ );
340
+ // Steady frames neither reshape nor rebuild retained structure.
341
+ let reshapes = stats.text_reshapes;
342
+ for _ in 0..5 {
343
+ session.render().unwrap();
344
+ }
345
+ assert_eq!(session.renderer_stats().text_reshapes, reshapes);
346
+ assert!(session.runtime().last_reconciliation().is_empty());
347
+ // Window resizes and scale changes reshape nothing.
348
+ for (width, scale) in [(700.0, 2.0), (900.0, 1.0), (800.0, 2.0)] {
349
+ session.resize(width, 600.0, scale);
350
+ session.render().unwrap();
351
+ }
352
+ assert_eq!(session.renderer_stats().text_reshapes, reshapes);
353
+ // Steady frames hit the shaping cache: no measurement reshaping either.
354
+ let shaped = session.shaped_line_count();
355
+ session.render().unwrap();
356
+ session.render().unwrap();
357
+ assert_eq!(session.shaped_line_count(), shaped);
358
+ }
359
+
360
+ /// Rows scrolled out of the ScrollView are culled before GPU preparation, and
361
+ /// the framebuffer is identical to drawing everything.
362
+ #[test]
363
+ fn culling_offscreen_rows_leaves_pixels_unchanged() {
364
+ let mut session = OffscreenSession::new(&program(300, 200), 800.0, 600.0, 1.0).unwrap();
365
+ for dy in [0.0, -2400.0, -900.0] {
366
+ if dy != 0.0 {
367
+ scroll(&mut session, dy);
368
+ }
369
+ session.set_culling(true);
370
+ session.render().unwrap();
371
+ let culled = session.rgba().unwrap();
372
+ let skipped = session.renderer_stats().culled_primitives;
373
+ let primitives = {
374
+ let frame = session.runtime().build_frame(800.0, 600.0).unwrap();
375
+ frame.scene.rects.len() + frame.scene.texts.len()
376
+ };
377
+ // ~20 rows of 300 are visible; nearly everything else is skipped.
378
+ assert!(
379
+ skipped * 10 > primitives * 8,
380
+ "{skipped} of {primitives} culled after scrolling {dy}"
381
+ );
382
+ session.set_culling(false);
383
+ session.render().unwrap();
384
+ assert_eq!(session.renderer_stats().culled_primitives, 0);
385
+ assert!(
386
+ culled == session.rgba().unwrap(),
387
+ "culled frame differs after scrolling {dy}"
388
+ );
389
+ }
390
+ }
391
+
392
+ #[test]
393
+ #[ignore = "measurement report; run with --release --ignored --nocapture"]
394
+ fn stress_measurement_report() {
395
+ let rows: Vec<usize> = std::env::var("MUN_STRESS_ROWS")
396
+ .ok()
397
+ .map(|value| {
398
+ value
399
+ .split(',')
400
+ .filter_map(|rows| rows.trim().parse().ok())
401
+ .collect()
402
+ })
403
+ .unwrap_or_else(|| vec![1000, 3000]);
404
+ for rows in rows {
405
+ println!("--- {rows} keyed rows ---");
406
+ workload(rows, 120, true);
407
+ }
408
+ }
@@ -0,0 +1,183 @@
1
+ //! Deterministic display/window lifecycle checks through the production
2
+ //! renderer: scale changes, resizes, minimize/restore while editing,
3
+ //! scrolling and animating. Logical (runtime) geometry must stay coherent and
4
+ //! only the framebuffer mapping may change.
5
+ use mun_native::OffscreenSession;
6
+ use mun_runtime::InputEvent;
7
+ use mun_runtime::text_edit::{Composition, TextEdit};
8
+
9
+ const PROGRAM: &str = r##"{"version":1,"sourceLanguage":"mun","entry":"Life","states":[{"name":"name","initial":"한국어 text"},{"name":"wide","initial":false}],
10
+ "root":{"kind":"window","id":"window","title":"Life","child":{"kind":"column","id":"stack","layout":{"alignment":"leading","padding":10,"spacing":8,"maxWidth":"infinity","maxHeight":"infinity"},"visual":{"background":"#101018"},"children":[
11
+ {"kind":"textField","id":"field","state":"name","layout":{"width":{"kind":"literal","value":260},"height":{"kind":"literal","value":40}},"visual":{"background":"#202030"}},
12
+ {"kind":"action","id":"grow","label":"Grow","action":{"kind":"toggle-state","state":"wide","transaction":{"animation":{"kind":"timing","duration":0.4,"curve":[0,0,1,1],"delayMs":0,"repeatCount":1,"autoreverses":false},"disablesAnimations":false,"isContinuous":false}}},
13
+ {"kind":"panel","id":"bar","layout":{"width":{"kind":"conditional","condition":{"kind":"state","state":"wide"},"then":{"kind":"literal","value":240},"otherwise":{"kind":"literal","value":40}},"height":{"kind":"literal","value":20}},"visual":{"background":"#63C8A2"},
14
+ "motion":[{"property":"width","propertyMask":512,"value":{"kind":"conditional","condition":{"kind":"state","state":"wide"},"then":{"kind":"literal","value":240},"otherwise":{"kind":"literal","value":40}}}]},
15
+ {"kind":"scroll","id":"scroll","axis":"vertical","layout":{"width":{"kind":"literal","value":200},"height":{"kind":"literal","value":60}},"children":[
16
+ {"kind":"column","id":"rows","children":[
17
+ {"kind":"text","id":"r1","value":{"kind":"literal","value":"one"},"layout":{"height":{"kind":"literal","value":50}}},
18
+ {"kind":"text","id":"r2","value":{"kind":"literal","value":"two"},"layout":{"height":{"kind":"literal","value":50}}},
19
+ {"kind":"text","id":"r3","value":{"kind":"literal","value":"three"},"layout":{"height":{"kind":"literal","value":50}}}]}]}]}}}"##;
20
+
21
+ fn scene_rect(session: &OffscreenSession, id: &str, w: f32, h: f32) -> mun_runtime::Rect {
22
+ let frame = session.runtime().build_frame(w, h).unwrap();
23
+ frame
24
+ .scene
25
+ .rects
26
+ .iter()
27
+ .find(|item| item.id == id)
28
+ .unwrap_or_else(|| panic!("{id}"))
29
+ .rect
30
+ }
31
+
32
+ fn pixel(session: &OffscreenSession, rgba: &[u8], x: f32, y: f32, scale: f32) -> [u8; 4] {
33
+ let (width, height) = session.size();
34
+ let (px, py) = ((x * scale) as u32, (y * scale) as u32);
35
+ assert!(
36
+ px < width && py < height,
37
+ "pixel ({px},{py}) outside {width}x{height}"
38
+ );
39
+ let index = ((py * width + px) * 4) as usize;
40
+ [
41
+ rgba[index],
42
+ rgba[index + 1],
43
+ rgba[index + 2],
44
+ rgba[index + 3],
45
+ ]
46
+ }
47
+
48
+ fn compose(session: &mut OffscreenSession) {
49
+ assert!(session.runtime_mut().focus_action("field"));
50
+ session
51
+ .input(InputEvent::TextEdit(TextEdit::End { select: false }))
52
+ .unwrap();
53
+ session
54
+ .input(InputEvent::TextEdit(TextEdit::CompositionUpdate(
55
+ Composition {
56
+ text: "가".into(),
57
+ selection: None,
58
+ },
59
+ )))
60
+ .unwrap();
61
+ }
62
+
63
+ #[test]
64
+ fn display_scale_changes_while_composing_keep_logical_geometry_and_rescale_pixels() {
65
+ let (w, h) = (320.0, 220.0);
66
+ let mut session = OffscreenSession::new(PROGRAM, w, h, 1.0).unwrap();
67
+ compose(&mut session);
68
+ let caret = scene_rect(&session, "field:caret", w, h);
69
+ let ime_area = session.runtime().build_frame(w, h).unwrap().ime_cursor_area;
70
+ for scale in [1.0, 2.0, 1.5, 1.0] {
71
+ session.resize(w, h, scale);
72
+ assert_eq!(
73
+ session.size(),
74
+ ((w * scale).round() as u32, (h * scale).round() as u32)
75
+ );
76
+ session.render().unwrap();
77
+ let rgba = session.rgba().unwrap();
78
+ assert_eq!(
79
+ scene_rect(&session, "field:caret", w, h),
80
+ caret,
81
+ "logical caret at {scale}x"
82
+ );
83
+ assert_eq!(
84
+ session.runtime().build_frame(w, h).unwrap().ime_cursor_area,
85
+ ime_area
86
+ );
87
+ let [r, g, b, _] = pixel(
88
+ &session,
89
+ &rgba,
90
+ caret.x + caret.width * 0.5,
91
+ caret.y + 4.0,
92
+ scale,
93
+ );
94
+ assert!(
95
+ r > 170 && g > 170 && b > 170,
96
+ "caret pixel at {scale}x: {r} {g} {b}"
97
+ );
98
+ assert!(
99
+ session
100
+ .runtime()
101
+ .focused_text_editor()
102
+ .unwrap()
103
+ .composition()
104
+ .is_some(),
105
+ "composition survives display changes"
106
+ );
107
+ }
108
+ assert_eq!(
109
+ session.runtime().state_value("name").unwrap(),
110
+ "한국어 text가"
111
+ );
112
+ }
113
+
114
+ #[test]
115
+ fn minimize_and_restore_while_editing_scrolled_and_animating() {
116
+ let (w, h) = (320.0, 220.0);
117
+ let mut session = OffscreenSession::new(PROGRAM, w, h, 2.0).unwrap();
118
+ compose(&mut session);
119
+ // Scroll the nested viewport to its end, start an animation, then minimize.
120
+ session
121
+ .input(InputEvent::PointerMoved {
122
+ pointer: mun_runtime::input::PointerId::MOUSE,
123
+ position: mun_runtime::input::InputPoint::new(60.0, 160.0),
124
+ })
125
+ .unwrap();
126
+ session
127
+ .input(InputEvent::Scroll {
128
+ pointer: Some(mun_runtime::input::PointerId::MOUSE),
129
+ delta: mun_runtime::input::ScrollDelta::Pixels { x: 0.0, y: -500.0 },
130
+ phase: mun_runtime::input::ScrollPhase::Changed,
131
+ })
132
+ .unwrap();
133
+ let scrolled = scene_rect(&session, "scroll:scrollbar-thumb", w, h);
134
+ session.runtime_mut().activate_action("grow");
135
+ session.runtime_mut().step(0.1);
136
+ session.render().unwrap();
137
+ let mid = scene_rect(&session, "bar", w, h).width;
138
+ assert!(mid > 40.0 && mid < 240.0, "{mid}");
139
+
140
+ // Minimized: zero-sized framebuffer requests keep the previous surface and
141
+ // a zero logical size neither panics nor discards runtime state.
142
+ session.resize(0.0, 0.0, 2.0);
143
+ assert_eq!(session.size(), (640, 440));
144
+ session.runtime().build_frame(0.0, 0.0).unwrap();
145
+ session.runtime_mut().step(0.2);
146
+
147
+ session.resize(w, h, 2.0);
148
+ session.runtime_mut().step(0.2);
149
+ session.render().unwrap();
150
+ assert_eq!(scene_rect(&session, "bar", w, h).width, 240.0);
151
+ assert_eq!(
152
+ scene_rect(&session, "scroll:scrollbar-thumb", w, h),
153
+ scrolled
154
+ );
155
+ assert!(
156
+ session
157
+ .runtime()
158
+ .focused_text_editor()
159
+ .unwrap()
160
+ .composition()
161
+ .is_some()
162
+ );
163
+
164
+ // Growing the window cannot leave a scroll offset beyond the new maximum.
165
+ session.resize(w, 600.0, 2.0);
166
+ session.render().unwrap();
167
+ let thumb = scene_rect(&session, "scroll:scrollbar-thumb", w, 600.0);
168
+ let track = scene_rect(&session, "scroll:scrollbar-track", w, 600.0);
169
+ assert!(thumb.y + thumb.height <= track.y + track.height + 0.01);
170
+ }
171
+
172
+ #[test]
173
+ fn zero_sized_initial_window_defers_rendering_without_panicking() {
174
+ let mut session = OffscreenSession::new(PROGRAM, 0.0, 0.0, 2.0).unwrap();
175
+ session.resize(320.0, 220.0, 2.0);
176
+ session.render().unwrap();
177
+ let rgba = session.rgba().unwrap();
178
+ let [r, g, b, _] = pixel(&session, &rgba, 4.0, 210.0, 2.0);
179
+ assert!(
180
+ r.abs_diff(0x10) <= 2 && g.abs_diff(0x10) <= 2 && b.abs_diff(0x18) <= 2,
181
+ "{r} {g} {b}"
182
+ );
183
+ }
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "mun-runtime"
3
+ version.workspace = true
4
+ edition.workspace = true
5
+ license.workspace = true
6
+
7
+ [dependencies]
8
+ serde.workspace = true
9
+ serde_json.workspace = true
10
+ taffy.workspace = true
11
+ thiserror.workspace = true
12
+ rustc-hash = "2.1"
13
+ unicode-segmentation = "1.13"