@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,530 @@
1
+ use std::collections::HashMap;
2
+
3
+ #[derive(Clone, Copy, Debug, Default, PartialEq)]
4
+ pub struct Rect {
5
+ pub x: f32,
6
+ pub y: f32,
7
+ pub width: f32,
8
+ pub height: f32,
9
+ }
10
+
11
+ impl Rect {
12
+ pub fn contains(self, x: f32, y: f32) -> bool {
13
+ x >= self.x && y >= self.y && x <= self.x + self.width && y <= self.y + self.height
14
+ }
15
+
16
+ pub fn intersection(self, other: Self) -> Self {
17
+ let left = self.x.max(other.x);
18
+ let top = self.y.max(other.y);
19
+ let right = (self.x + self.width).min(other.x + other.width);
20
+ let bottom = (self.y + self.height).min(other.y + other.height);
21
+ Self {
22
+ x: left,
23
+ y: top,
24
+ width: (right - left).max(0.0),
25
+ height: (bottom - top).max(0.0),
26
+ }
27
+ }
28
+ }
29
+
30
+ #[derive(Clone, Copy, Debug, PartialEq)]
31
+ pub struct SceneTransform {
32
+ pub scale_x: f32,
33
+ pub scale_y: f32,
34
+ pub translation_x: f32,
35
+ pub translation_y: f32,
36
+ }
37
+
38
+ impl Default for SceneTransform {
39
+ fn default() -> Self {
40
+ Self::IDENTITY
41
+ }
42
+ }
43
+
44
+ impl SceneTransform {
45
+ pub const IDENTITY: Self = Self {
46
+ scale_x: 1.0,
47
+ scale_y: 1.0,
48
+ translation_x: 0.0,
49
+ translation_y: 0.0,
50
+ };
51
+
52
+ pub const fn translation(x: f32, y: f32) -> Self {
53
+ Self {
54
+ translation_x: x,
55
+ translation_y: y,
56
+ ..Self::IDENTITY
57
+ }
58
+ }
59
+
60
+ pub const fn scale(scale_x: f32, scale_y: f32) -> Self {
61
+ Self {
62
+ scale_x,
63
+ scale_y,
64
+ ..Self::IDENTITY
65
+ }
66
+ }
67
+
68
+ pub fn scale_about(pivot_x: f32, pivot_y: f32, scale_x: f32, scale_y: f32) -> Self {
69
+ Self {
70
+ scale_x,
71
+ scale_y,
72
+ translation_x: pivot_x * (1.0 - scale_x),
73
+ translation_y: pivot_y * (1.0 - scale_y),
74
+ }
75
+ }
76
+
77
+ /// Composes a child-local transform under this parent transform.
78
+ ///
79
+ /// The returned transform applies `child` first, then `self`.
80
+ pub fn concat(self, child: Self) -> Self {
81
+ Self {
82
+ scale_x: self.scale_x * child.scale_x,
83
+ scale_y: self.scale_y * child.scale_y,
84
+ translation_x: self.translation_x + self.scale_x * child.translation_x,
85
+ translation_y: self.translation_y + self.scale_y * child.translation_y,
86
+ }
87
+ }
88
+
89
+ pub fn transform_point(self, x: f32, y: f32) -> (f32, f32) {
90
+ (
91
+ x * self.scale_x + self.translation_x,
92
+ y * self.scale_y + self.translation_y,
93
+ )
94
+ }
95
+
96
+ pub fn transform_rect(self, rect: Rect) -> Rect {
97
+ let (x0, y0) = self.transform_point(rect.x, rect.y);
98
+ let (x1, y1) = self.transform_point(rect.x + rect.width, rect.y + rect.height);
99
+ Rect {
100
+ x: x0.min(x1),
101
+ y: y0.min(y1),
102
+ width: (x1 - x0).abs(),
103
+ height: (y1 - y0).abs(),
104
+ }
105
+ }
106
+
107
+ pub fn inverse(self) -> Option<Self> {
108
+ if self.scale_x.abs() <= f32::EPSILON || self.scale_y.abs() <= f32::EPSILON {
109
+ return None;
110
+ }
111
+ Some(Self {
112
+ scale_x: self.scale_x.recip(),
113
+ scale_y: self.scale_y.recip(),
114
+ translation_x: -self.translation_x / self.scale_x,
115
+ translation_y: -self.translation_y / self.scale_y,
116
+ })
117
+ }
118
+
119
+ pub fn is_identity(self) -> bool {
120
+ self == Self::IDENTITY
121
+ }
122
+ }
123
+
124
+ #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
125
+ pub struct SceneTransformId(usize);
126
+
127
+ #[derive(Clone, Copy, Debug, PartialEq)]
128
+ pub struct SceneTransformNode {
129
+ pub parent: Option<SceneTransformId>,
130
+ pub local: SceneTransform,
131
+ }
132
+
133
+ #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
134
+ pub struct SceneClipId(usize);
135
+
136
+ #[derive(Clone, Copy, Debug, PartialEq)]
137
+ pub struct SceneClipNode {
138
+ pub parent: Option<SceneClipId>,
139
+ pub rect: Rect,
140
+ pub transform: Option<SceneTransformId>,
141
+ }
142
+
143
+ /// Renderer-neutral presentation transforms and clips layered over retained scene geometry.
144
+ ///
145
+ /// Primitive geometry remains in Taffy's logical scene space. Bindings associate
146
+ /// primitive IDs with transform/clip nodes; those nodes can inherit so subtree
147
+ /// presentation can be represented without baking scale, translation, or clipping
148
+ /// into semantic layout geometry or text metrics.
149
+ #[derive(Clone, Debug, Default)]
150
+ pub struct ScenePresentation {
151
+ transforms: Vec<SceneTransformNode>,
152
+ bindings: HashMap<String, SceneTransformId>,
153
+ clips: Vec<SceneClipNode>,
154
+ clip_bindings: HashMap<String, SceneClipId>,
155
+ }
156
+
157
+ impl ScenePresentation {
158
+ pub fn push_transform(
159
+ &mut self,
160
+ parent: Option<SceneTransformId>,
161
+ local: SceneTransform,
162
+ ) -> SceneTransformId {
163
+ if let Some(parent) = parent {
164
+ assert!(
165
+ parent.0 < self.transforms.len(),
166
+ "scene transform parent must already exist"
167
+ );
168
+ }
169
+ let id = SceneTransformId(self.transforms.len());
170
+ self.transforms.push(SceneTransformNode { parent, local });
171
+ id
172
+ }
173
+
174
+ pub fn bind(&mut self, primitive_id: impl Into<String>, transform: SceneTransformId) {
175
+ assert!(
176
+ transform.0 < self.transforms.len(),
177
+ "scene primitive cannot bind an unknown transform"
178
+ );
179
+ self.bindings.insert(primitive_id.into(), transform);
180
+ }
181
+
182
+ pub fn unbind(&mut self, primitive_id: &str) {
183
+ self.bindings.remove(primitive_id);
184
+ }
185
+
186
+ pub fn transform_for(&self, primitive_id: &str) -> SceneTransform {
187
+ self.bindings
188
+ .get(primitive_id)
189
+ .copied()
190
+ .map(|id| self.resolved_transform(id))
191
+ .unwrap_or(SceneTransform::IDENTITY)
192
+ }
193
+
194
+ pub fn resolved_transform(&self, transform: SceneTransformId) -> SceneTransform {
195
+ let node = self
196
+ .transforms
197
+ .get(transform.0)
198
+ .expect("scene primitive referenced an unknown transform");
199
+ match node.parent {
200
+ Some(parent) => self.resolved_transform(parent).concat(node.local),
201
+ None => node.local,
202
+ }
203
+ }
204
+
205
+ pub fn transformed_rect(&self, primitive_id: &str, rect: Rect) -> Rect {
206
+ self.transform_for(primitive_id).transform_rect(rect)
207
+ }
208
+
209
+ pub fn push_clip(
210
+ &mut self,
211
+ parent: Option<SceneClipId>,
212
+ rect: Rect,
213
+ transform: Option<SceneTransformId>,
214
+ ) -> SceneClipId {
215
+ if let Some(parent) = parent {
216
+ assert!(
217
+ parent.0 < self.clips.len(),
218
+ "scene clip parent must already exist"
219
+ );
220
+ }
221
+ if let Some(transform) = transform {
222
+ assert!(
223
+ transform.0 < self.transforms.len(),
224
+ "scene clip cannot reference an unknown transform"
225
+ );
226
+ }
227
+ let id = SceneClipId(self.clips.len());
228
+ self.clips.push(SceneClipNode {
229
+ parent,
230
+ rect,
231
+ transform,
232
+ });
233
+ id
234
+ }
235
+
236
+ pub fn bind_clip(&mut self, primitive_id: impl Into<String>, clip: SceneClipId) {
237
+ assert!(
238
+ clip.0 < self.clips.len(),
239
+ "scene primitive cannot bind an unknown clip"
240
+ );
241
+ self.clip_bindings.insert(primitive_id.into(), clip);
242
+ }
243
+
244
+ pub fn unbind_clip(&mut self, primitive_id: &str) {
245
+ self.clip_bindings.remove(primitive_id);
246
+ }
247
+
248
+ pub fn clip_for(&self, primitive_id: &str) -> Option<Rect> {
249
+ self.clip_bindings
250
+ .get(primitive_id)
251
+ .copied()
252
+ .map(|id| self.resolved_clip(id))
253
+ }
254
+
255
+ pub fn resolved_clip(&self, clip: SceneClipId) -> Rect {
256
+ let node = self
257
+ .clips
258
+ .get(clip.0)
259
+ .expect("scene primitive referenced an unknown clip");
260
+ let rect = node
261
+ .transform
262
+ .map(|transform| self.resolved_transform(transform).transform_rect(node.rect))
263
+ .unwrap_or(node.rect);
264
+ match node.parent {
265
+ Some(parent) => self.resolved_clip(parent).intersection(rect),
266
+ None => rect,
267
+ }
268
+ }
269
+
270
+ pub fn action_at<'a>(&self, scene: &'a Scene, x: f32, y: f32) -> Option<&'a str> {
271
+ scene
272
+ .actions
273
+ .iter()
274
+ .rev()
275
+ .find(|action| {
276
+ if let Some(clip) = self.clip_for(&action.id) {
277
+ if clip.width <= 0.0 || clip.height <= 0.0 || !clip.contains(x, y) {
278
+ return false;
279
+ }
280
+ }
281
+ let transform = self.transform_for(&action.id);
282
+ let Some(inverse) = transform.inverse() else {
283
+ return false;
284
+ };
285
+ let (local_x, local_y) = inverse.transform_point(x, y);
286
+ action.rect.contains(local_x, local_y)
287
+ })
288
+ .map(|action| action.id.as_str())
289
+ }
290
+
291
+ pub fn is_empty(&self) -> bool {
292
+ self.bindings.is_empty() && self.clip_bindings.is_empty()
293
+ }
294
+ }
295
+
296
+ #[derive(Clone, Copy, Debug, PartialEq)]
297
+ pub struct Color(pub [f32; 4]);
298
+
299
+ impl Color {
300
+ pub const WINDOW: Self = Self([0.075, 0.075, 0.09, 1.0]);
301
+ pub const TEXT: Self = Self([0.94, 0.94, 0.97, 1.0]);
302
+ pub const ACTION: Self = Self([0.18, 0.18, 0.22, 1.0]);
303
+ pub const ACTION_FOCUSED: Self = Self([0.28, 0.28, 0.34, 1.0]);
304
+ pub const ACCENT: Self = Self([0.36, 0.62, 1.0, 1.0]);
305
+ pub const SEPARATOR: Self = Self([1.0, 1.0, 1.0, 0.14]);
306
+ pub const SELECTION: Self = Self([0.36, 0.62, 1.0, 0.42]);
307
+ pub const SCROLLBAR_TRACK: Self = Self([1.0, 1.0, 1.0, 0.06]);
308
+ pub const SCROLLBAR_THUMB: Self = Self([1.0, 1.0, 1.0, 0.38]);
309
+
310
+ pub fn with_opacity(mut self, opacity: f32) -> Self {
311
+ self.0[3] *= opacity.clamp(0.0, 1.0);
312
+ self
313
+ }
314
+
315
+ pub fn parse(value: &str) -> Option<Self> {
316
+ let hex = value.strip_prefix('#')?;
317
+ let parse = |range: std::ops::Range<usize>| u8::from_str_radix(&hex[range], 16).ok();
318
+ match hex.len() {
319
+ 6 => Some(Self([
320
+ parse(0..2)? as f32 / 255.0,
321
+ parse(2..4)? as f32 / 255.0,
322
+ parse(4..6)? as f32 / 255.0,
323
+ 1.0,
324
+ ])),
325
+ 8 => Some(Self([
326
+ parse(0..2)? as f32 / 255.0,
327
+ parse(2..4)? as f32 / 255.0,
328
+ parse(4..6)? as f32 / 255.0,
329
+ parse(6..8)? as f32 / 255.0,
330
+ ])),
331
+ _ => None,
332
+ }
333
+ }
334
+ }
335
+
336
+ #[derive(Clone, Debug)]
337
+ pub struct SceneRect {
338
+ pub id: String,
339
+ pub rect: Rect,
340
+ pub color: Color,
341
+ pub corner_radius: f32,
342
+ }
343
+
344
+ #[derive(Clone, Copy, Debug, PartialEq)]
345
+ pub struct LinearGradient {
346
+ pub start: Color,
347
+ pub end: Color,
348
+ pub start_point: [f32; 2],
349
+ pub end_point: [f32; 2],
350
+ }
351
+
352
+ #[derive(Clone, Debug)]
353
+ pub struct SceneGradient {
354
+ pub id: String,
355
+ pub gradient: LinearGradient,
356
+ }
357
+
358
+ #[derive(Clone, Debug)]
359
+ pub struct SceneText {
360
+ pub id: String,
361
+ pub text: String,
362
+ pub x: f32,
363
+ pub y: f32,
364
+ pub font_size: f32,
365
+ pub color: Color,
366
+ }
367
+
368
+ #[derive(Clone, Debug)]
369
+ pub struct ActionHit {
370
+ pub id: String,
371
+ pub rect: Rect,
372
+ }
373
+
374
+ #[derive(Clone, Debug, Default)]
375
+ pub struct Scene {
376
+ pub presentation: ScenePresentation,
377
+ pub rects: Vec<SceneRect>,
378
+ pub gradients: Vec<SceneGradient>,
379
+ pub texts: Vec<SceneText>,
380
+ pub actions: Vec<ActionHit>,
381
+ }
382
+
383
+ impl Scene {
384
+ pub fn action_at(&self, x: f32, y: f32) -> Option<&str> {
385
+ self.presentation.action_at(self, x, y)
386
+ }
387
+
388
+ pub fn gradient_for(&self, id: &str) -> Option<&LinearGradient> {
389
+ self.gradients
390
+ .iter()
391
+ .rev()
392
+ .find(|item| item.id == id)
393
+ .map(|item| &item.gradient)
394
+ }
395
+ }
396
+
397
+ #[cfg(test)]
398
+ mod tests {
399
+ use super::*;
400
+
401
+ fn assert_point(actual: (f32, f32), expected: (f32, f32)) {
402
+ assert!(
403
+ (actual.0 - expected.0).abs() < 0.0001,
404
+ "{actual:?} != {expected:?}"
405
+ );
406
+ assert!(
407
+ (actual.1 - expected.1).abs() < 0.0001,
408
+ "{actual:?} != {expected:?}"
409
+ );
410
+ }
411
+
412
+ #[test]
413
+ fn transform_composition_applies_child_before_parent() {
414
+ let parent = SceneTransform {
415
+ scale_x: 2.0,
416
+ scale_y: 3.0,
417
+ translation_x: 4.0,
418
+ translation_y: -5.0,
419
+ };
420
+ let child = SceneTransform::translation(6.0, 7.0);
421
+ let combined = parent.concat(child);
422
+
423
+ assert_point(combined.transform_point(1.0, 2.0), (18.0, 22.0));
424
+ }
425
+
426
+ #[test]
427
+ fn nested_scene_transforms_resolve_in_hierarchy_order() {
428
+ let mut presentation = ScenePresentation::default();
429
+ let parent = presentation.push_transform(None, SceneTransform::scale(2.0, 3.0));
430
+ let child =
431
+ presentation.push_transform(Some(parent), SceneTransform::translation(5.0, 7.0));
432
+ presentation.bind("label", child);
433
+
434
+ assert_point(
435
+ presentation
436
+ .transform_for("label")
437
+ .transform_point(1.0, 2.0),
438
+ (12.0, 27.0),
439
+ );
440
+ }
441
+
442
+ #[test]
443
+ fn non_uniform_scale_about_pivot_keeps_pivot_fixed() {
444
+ let transform = SceneTransform::scale_about(10.0, 20.0, 2.0, 0.5);
445
+
446
+ assert_point(transform.transform_point(10.0, 20.0), (10.0, 20.0));
447
+ assert_point(transform.transform_point(11.0, 22.0), (12.0, 21.0));
448
+ }
449
+
450
+ #[test]
451
+ fn nested_scene_clips_intersect_in_presentation_space() {
452
+ let mut presentation = ScenePresentation::default();
453
+ let shifted = presentation.push_transform(None, SceneTransform::translation(10.0, 5.0));
454
+ let parent = presentation.push_clip(
455
+ None,
456
+ Rect {
457
+ x: 0.0,
458
+ y: 0.0,
459
+ width: 50.0,
460
+ height: 50.0,
461
+ },
462
+ None,
463
+ );
464
+ let child = presentation.push_clip(
465
+ Some(parent),
466
+ Rect {
467
+ x: 10.0,
468
+ y: 10.0,
469
+ width: 40.0,
470
+ height: 40.0,
471
+ },
472
+ Some(shifted),
473
+ );
474
+ presentation.bind_clip("label", child);
475
+
476
+ assert_eq!(
477
+ presentation.clip_for("label"),
478
+ Some(Rect {
479
+ x: 20.0,
480
+ y: 15.0,
481
+ width: 30.0,
482
+ height: 35.0,
483
+ })
484
+ );
485
+ }
486
+
487
+ #[test]
488
+ fn transformed_action_hit_testing_uses_presentation_geometry() {
489
+ let scene = Scene {
490
+ actions: vec![ActionHit {
491
+ id: "button".into(),
492
+ rect: Rect {
493
+ x: 10.0,
494
+ y: 20.0,
495
+ width: 30.0,
496
+ height: 20.0,
497
+ },
498
+ }],
499
+ ..Default::default()
500
+ };
501
+ let mut presentation = ScenePresentation::default();
502
+ let transform = presentation.push_transform(
503
+ None,
504
+ SceneTransform {
505
+ scale_x: 2.0,
506
+ scale_y: 0.5,
507
+ translation_x: 5.0,
508
+ translation_y: 3.0,
509
+ },
510
+ );
511
+ presentation.bind("button", transform);
512
+
513
+ assert_eq!(presentation.action_at(&scene, 45.0, 15.5), Some("button"));
514
+ assert_eq!(presentation.action_at(&scene, 4.0, 15.5), None);
515
+
516
+ let clip = presentation.push_clip(
517
+ None,
518
+ Rect {
519
+ x: 40.0,
520
+ y: 14.0,
521
+ width: 15.0,
522
+ height: 4.0,
523
+ },
524
+ None,
525
+ );
526
+ presentation.bind_clip("button", clip);
527
+ assert_eq!(presentation.action_at(&scene, 45.0, 15.5), Some("button"));
528
+ assert_eq!(presentation.action_at(&scene, 30.0, 15.5), None);
529
+ }
530
+ }