@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,193 @@
1
+ use crate::{ir::AccessibilityRole, runtime::Runtime};
2
+
3
+ #[derive(Clone, Copy, Debug, Default, PartialEq)]
4
+ pub struct AccessibilityBounds {
5
+ pub x: f32,
6
+ pub y: f32,
7
+ pub width: f32,
8
+ pub height: f32,
9
+ }
10
+
11
+ #[derive(Clone, Debug, PartialEq)]
12
+ pub struct AccessibilityNode {
13
+ pub id: String,
14
+ pub role: AccessibilityRole,
15
+ pub label: Option<String>,
16
+ /// Committed semantic value, separate from accessible name and preedit.
17
+ pub value: Option<String>,
18
+ pub enabled: bool,
19
+ pub focused: bool,
20
+ pub bounds: AccessibilityBounds,
21
+ pub children: Vec<String>,
22
+ pub action_id: Option<String>,
23
+ /// Radio option state; `None` for nodes that are not checkable.
24
+ pub checked: Option<bool>,
25
+ /// Editable single-line text geometry and selection (text fields only).
26
+ pub text: Option<AccessibleText>,
27
+ /// Scroll position of a scrollable viewport whose content overflows.
28
+ pub scroll: Option<AccessibleScroll>,
29
+ }
30
+
31
+ /// One line of committed text inside a text field, in assistive-technology
32
+ /// units. A "character" is an extended grapheme cluster: exactly one caret step
33
+ /// of the runtime editor, so screen-reader navigation never splits what the
34
+ /// editor treats as one character. Preedit text is never included.
35
+ #[derive(Clone, Debug, Default, PartialEq)]
36
+ pub struct AccessibleText {
37
+ pub id: String,
38
+ pub value: String,
39
+ /// UTF-8 byte length of each grapheme.
40
+ pub character_lengths: Vec<usize>,
41
+ /// Start of each grapheme along the line, relative to `bounds.x`.
42
+ pub character_positions: Vec<f32>,
43
+ pub character_widths: Vec<f32>,
44
+ /// Grapheme index at which each word starts.
45
+ pub word_starts: Vec<usize>,
46
+ /// Unclipped line box (scrolled with the field's horizontal text scroll).
47
+ pub bounds: AccessibilityBounds,
48
+ /// `(anchor, focus)` grapheme indices; present while the field is focused.
49
+ pub selection: Option<(usize, usize)>,
50
+ }
51
+
52
+ #[derive(Clone, Copy, Debug, Default, PartialEq)]
53
+ pub struct AccessibleScroll {
54
+ pub horizontal: bool,
55
+ pub offset: f32,
56
+ pub max: f32,
57
+ }
58
+
59
+ #[derive(Clone, Debug, PartialEq)]
60
+ pub struct AccessibilityTree {
61
+ pub root_id: String,
62
+ pub focus_id: Option<String>,
63
+ pub nodes: Vec<AccessibilityNode>,
64
+ }
65
+
66
+ impl AccessibilityTree {
67
+ pub fn node(&self, id: &str) -> Option<&AccessibilityNode> {
68
+ self.nodes.iter().find(|node| node.id == id)
69
+ }
70
+ }
71
+
72
+ #[derive(Clone, Debug, PartialEq)]
73
+ pub enum AccessibilityAction {
74
+ Activate,
75
+ Focus,
76
+ Blur,
77
+ /// Grapheme indices into the target field's committed text.
78
+ SetTextSelection {
79
+ anchor: usize,
80
+ focus: usize,
81
+ },
82
+ ReplaceSelectedText(String),
83
+ SetValue(String),
84
+ /// Scroll the target viewport by pages (negative = toward the start).
85
+ ScrollByPages(f32),
86
+ SetScrollOffset(f32),
87
+ /// Reveal the target node through every scrolling ancestor.
88
+ ScrollIntoView,
89
+ }
90
+
91
+ #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
92
+ pub struct AccessibilityActionOutcome {
93
+ pub handled: bool,
94
+ pub needs_redraw: bool,
95
+ pub focus_changed: bool,
96
+ pub activated: bool,
97
+ /// Text content or selection changed (IME state must be resynchronized).
98
+ pub edited: bool,
99
+ }
100
+
101
+ impl Runtime {
102
+ pub fn handle_accessibility_action(
103
+ &mut self,
104
+ target: &str,
105
+ action: AccessibilityAction,
106
+ ) -> AccessibilityActionOutcome {
107
+ let focus_before = self.focused_action().map(str::to_owned);
108
+ let mut outcome = AccessibilityActionOutcome::default();
109
+
110
+ match action {
111
+ AccessibilityAction::Activate => {
112
+ if self.focus_action(target) {
113
+ outcome.handled = true;
114
+ outcome.activated = self.activate_interactive(target).is_some();
115
+ }
116
+ }
117
+ AccessibilityAction::Focus => {
118
+ outcome.handled = self.focus_action(target);
119
+ }
120
+ AccessibilityAction::Blur => {
121
+ if self.focused_action() == Some(target) {
122
+ self.clear_focus();
123
+ outcome.handled = true;
124
+ }
125
+ }
126
+ AccessibilityAction::SetTextSelection { anchor, focus } => {
127
+ outcome.handled = self.accessible_select_text(target, anchor, focus);
128
+ outcome.edited = outcome.handled;
129
+ }
130
+ AccessibilityAction::ReplaceSelectedText(text) => {
131
+ outcome.handled = self.accessible_replace_text(target, &text, false);
132
+ outcome.edited = outcome.handled;
133
+ }
134
+ AccessibilityAction::SetValue(text) => {
135
+ outcome.handled = self.accessible_replace_text(target, &text, true);
136
+ outcome.edited = outcome.handled;
137
+ }
138
+ AccessibilityAction::ScrollByPages(pages) => {
139
+ outcome.handled =
140
+ self.accessible_scroll(target, |view| view.axis_offset() + pages * view.page());
141
+ }
142
+ AccessibilityAction::SetScrollOffset(offset) => {
143
+ outcome.handled = self.accessible_scroll(target, |_| offset);
144
+ }
145
+ AccessibilityAction::ScrollIntoView => {
146
+ outcome.handled = self.request_reveal(target);
147
+ }
148
+ }
149
+
150
+ outcome.focus_changed = self.focused_action() != focus_before.as_deref();
151
+ outcome.needs_redraw =
152
+ outcome.focus_changed || outcome.activated || outcome.edited || outcome.handled;
153
+ outcome
154
+ }
155
+ }
156
+
157
+ #[cfg(test)]
158
+ mod tests {
159
+ use super::*;
160
+ const ACCESSIBLE_ACTION: &str = r#"{"version":1,"sourceLanguage":"mun","entry":"AccessibilityActionTest","states":[{"name":"armed","initial":false}],"root":{"kind":"window","id":"root","title":"Accessibility","child":{"kind":"action","id":"primary","label":"Primary","action":{"kind":"toggle-state","state":"armed"}}}}"#;
161
+
162
+ #[test]
163
+ fn accessibility_activate_focuses_and_activates_semantic_action() {
164
+ let mut runtime = Runtime::from_json(ACCESSIBLE_ACTION).expect("valid accessible action");
165
+ let outcome = runtime.handle_accessibility_action("primary", AccessibilityAction::Activate);
166
+
167
+ assert!(outcome.handled);
168
+ assert!(outcome.focus_changed);
169
+ assert!(outcome.activated);
170
+ assert!(outcome.needs_redraw);
171
+ assert_eq!(runtime.focused_action(), Some("primary"));
172
+ }
173
+
174
+ #[test]
175
+ fn accessibility_focus_and_blur_share_runtime_focus_semantics() {
176
+ let mut runtime = Runtime::from_json(ACCESSIBLE_ACTION).expect("valid accessible action");
177
+
178
+ let focus = runtime.handle_accessibility_action("primary", AccessibilityAction::Focus);
179
+ assert!(focus.handled);
180
+ assert!(focus.focus_changed);
181
+ assert!(!focus.activated);
182
+
183
+ let blur = runtime.handle_accessibility_action("primary", AccessibilityAction::Blur);
184
+ assert!(blur.handled);
185
+ assert!(blur.focus_changed);
186
+ assert_eq!(runtime.focused_action(), None);
187
+
188
+ let stale = runtime.handle_accessibility_action("missing", AccessibilityAction::Focus);
189
+ assert!(!stale.handled);
190
+ assert!(!stale.focus_changed);
191
+ assert!(!stale.needs_redraw);
192
+ }
193
+ }