@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,209 @@
1
+ //! Persistent Taffy tree reused across frames and compatible hot updates.
2
+ //!
3
+ //! Every frame the runtime still derives the complete layout input (style,
4
+ //! intrinsic measurement and children) of every live node from Mün semantics,
5
+ //! so nothing here can go stale: this module only diffs that input against the
6
+ //! retained Taffy nodes, keyed by semantic node id, and touches the nodes whose
7
+ //! input actually changed. Taffy's per-node layout cache then recomputes only
8
+ //! dirty nodes and their ancestors; an unchanged subtree is answered from cache.
9
+ use rustc_hash::FxHashMap;
10
+ use taffy::{TaffyError, prelude::*};
11
+
12
+ use crate::layout::IntrinsicSize;
13
+
14
+ pub(crate) type LayoutTree = TaffyTree<IntrinsicSize>;
15
+ /// Semantic node id -> retained layout node. Keys are long node-id strings
16
+ /// hashed for every node every frame, so a fast non-DoS hasher is used.
17
+ pub(crate) type LayoutNodes = FxHashMap<String, NodeId>;
18
+
19
+ /// Layout input of one node of the frame being built.
20
+ pub(crate) struct LayoutSpec<'a> {
21
+ pub id: &'a str,
22
+ pub style: Style,
23
+ /// Intrinsic size of a leaf; always `None` for a node with children.
24
+ pub context: Option<IntrinsicSize>,
25
+ /// Indices into the frame's spec list.
26
+ pub children: Vec<usize>,
27
+ }
28
+
29
+ /// Work done by one [`LayoutCache::sync`] (structural counters, deterministic
30
+ /// for a given sequence of frames).
31
+ #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
32
+ pub struct LayoutSyncStats {
33
+ pub live: usize,
34
+ pub created: usize,
35
+ pub removed: usize,
36
+ pub restyled: usize,
37
+ pub remeasured: usize,
38
+ pub rechildren: usize,
39
+ }
40
+
41
+ impl LayoutSyncStats {
42
+ /// Nodes whose own layout input changed this frame.
43
+ pub fn invalidated(&self) -> usize {
44
+ self.created + self.removed + self.restyled + self.remeasured + self.rechildren
45
+ }
46
+ }
47
+
48
+ pub(crate) struct LayoutCache {
49
+ pub taffy: LayoutTree,
50
+ pub nodes: LayoutNodes,
51
+ /// Window node proposing the window size to the root views.
52
+ wrapper: Option<NodeId>,
53
+ /// Nodes created for a semantic id already used in the same frame. Ids are
54
+ /// validated unique, so this stays empty; they are dropped next frame.
55
+ duplicates: Vec<NodeId>,
56
+ pub last_sync: LayoutSyncStats,
57
+ }
58
+
59
+ impl Default for LayoutCache {
60
+ fn default() -> Self {
61
+ Self {
62
+ taffy: TaffyTree::new(),
63
+ nodes: LayoutNodes::default(),
64
+ wrapper: None,
65
+ duplicates: Vec::new(),
66
+ last_sync: LayoutSyncStats::default(),
67
+ }
68
+ }
69
+ }
70
+
71
+ impl LayoutCache {
72
+ pub fn wrapper(&self) -> Option<NodeId> {
73
+ self.wrapper
74
+ }
75
+
76
+ /// Bring the retained tree in line with `specs` (children listed before
77
+ /// their parents) and the window `roots`.
78
+ pub fn sync(
79
+ &mut self,
80
+ specs: &[LayoutSpec<'_>],
81
+ roots: &[usize],
82
+ wrapper_style: Style,
83
+ ) -> Result<(), TaffyError> {
84
+ let mut stats = LayoutSyncStats {
85
+ live: specs.len(),
86
+ ..Default::default()
87
+ };
88
+ let mut previous = std::mem::take(&mut self.nodes);
89
+ self.nodes.reserve(specs.len());
90
+ let mut stale = std::mem::take(&mut self.duplicates);
91
+ let mut ids = Vec::with_capacity(specs.len());
92
+ for spec in specs {
93
+ let reused = if self.nodes.contains_key(spec.id) {
94
+ None
95
+ } else {
96
+ previous.remove_entry(spec.id)
97
+ };
98
+ let node = match reused {
99
+ Some((key, node)) => {
100
+ if self.taffy.style(node)? != &spec.style {
101
+ self.taffy.set_style(node, spec.style.clone())?;
102
+ self.invalidate(node)?;
103
+ stats.restyled += 1;
104
+ }
105
+ if self.taffy.get_node_context(node) != spec.context.as_ref() {
106
+ self.taffy.set_node_context(node, spec.context)?;
107
+ self.invalidate(node)?;
108
+ stats.remeasured += 1;
109
+ }
110
+ self.nodes.insert(key, node);
111
+ node
112
+ }
113
+ None => {
114
+ let node = match spec.context {
115
+ Some(context) => self
116
+ .taffy
117
+ .new_leaf_with_context(spec.style.clone(), context)?,
118
+ None => self.taffy.new_leaf(spec.style.clone())?,
119
+ };
120
+ stats.created += 1;
121
+ if self.nodes.contains_key(spec.id) {
122
+ self.duplicates.push(node);
123
+ } else {
124
+ self.nodes.insert(spec.id.to_owned(), node);
125
+ }
126
+ node
127
+ }
128
+ };
129
+ ids.push(node);
130
+ }
131
+
132
+ // Detach every stale node from its children first: a child may have
133
+ // moved to a live parent, and removing its old parent must not clear
134
+ // the new link.
135
+ stale.extend(previous.into_values());
136
+ stats.removed = stale.len();
137
+ for &node in &stale {
138
+ self.taffy.set_children(node, &[])?;
139
+ }
140
+ for node in stale {
141
+ if let Some(parent) = self.taffy.parent(node) {
142
+ self.invalidate(parent)?;
143
+ }
144
+ self.taffy.remove(node)?;
145
+ }
146
+
147
+ let mut children = Vec::new();
148
+ for (spec, &node) in specs.iter().zip(&ids) {
149
+ children.clear();
150
+ children.extend(spec.children.iter().map(|&child| ids[child]));
151
+ if self.set_children_if_changed(node, &children)? {
152
+ stats.rechildren += 1;
153
+ }
154
+ }
155
+
156
+ let wrapper = match self.wrapper {
157
+ Some(wrapper) => {
158
+ if self.taffy.style(wrapper)? != &wrapper_style {
159
+ self.taffy.set_style(wrapper, wrapper_style)?;
160
+ self.invalidate(wrapper)?;
161
+ }
162
+ wrapper
163
+ }
164
+ None => {
165
+ let wrapper = self.taffy.new_leaf(wrapper_style)?;
166
+ self.wrapper = Some(wrapper);
167
+ wrapper
168
+ }
169
+ };
170
+ children.clear();
171
+ children.extend(roots.iter().map(|&root| ids[root]));
172
+ self.set_children_if_changed(wrapper, &children)?;
173
+ self.last_sync = stats;
174
+ Ok(())
175
+ }
176
+
177
+ fn set_children_if_changed(
178
+ &mut self,
179
+ node: NodeId,
180
+ children: &[NodeId],
181
+ ) -> Result<bool, TaffyError> {
182
+ if self.taffy.child_ids(node).eq(children.iter().copied()) {
183
+ return Ok(false);
184
+ }
185
+ // A child moving here leaves its previous parent; that parent's layout
186
+ // depends on the child too.
187
+ for &child in children {
188
+ if let Some(parent) = self.taffy.parent(child).filter(|parent| *parent != node) {
189
+ self.invalidate(parent)?;
190
+ }
191
+ }
192
+ self.taffy.set_children(node, children)?;
193
+ self.invalidate(node)?;
194
+ Ok(true)
195
+ }
196
+
197
+ /// Clear the cached layout of `node` and of every ancestor. Taffy's own
198
+ /// propagation stops at a node whose cache is already empty; walking the
199
+ /// whole ancestor chain keeps an ancestor from answering from stale cache
200
+ /// even if some intermediate node was never laid out.
201
+ fn invalidate(&mut self, node: NodeId) -> Result<(), TaffyError> {
202
+ let mut current = Some(node);
203
+ while let Some(node) = current {
204
+ self.taffy.mark_dirty(node)?;
205
+ current = self.taffy.parent(node);
206
+ }
207
+ Ok(())
208
+ }
209
+ }
@@ -0,0 +1,49 @@
1
+ //! Mün's native semantic runtime.
2
+ //!
3
+ //! This crate consumes backend-neutral UI IR. It owns state, transactions,
4
+ //! motion channels, layout adaptation, and retained scene construction. GPU,
5
+ //! window-system, and accessibility adapters live outside these semantics.
6
+
7
+ pub mod accessibility;
8
+ pub mod collection;
9
+ pub mod gesture;
10
+ pub mod input;
11
+ pub mod ir;
12
+ pub mod layout;
13
+ pub mod layout_cache;
14
+ pub mod motion;
15
+ pub mod retained;
16
+ pub mod runtime;
17
+ pub mod scene;
18
+ pub mod scroll;
19
+ pub mod scroll_view;
20
+ pub mod text_edit;
21
+ pub mod timeline;
22
+ pub mod validate;
23
+
24
+ pub use accessibility::{AccessibilityBounds, AccessibilityNode, AccessibilityTree};
25
+ pub use gesture::{
26
+ DragAxis, DragAxisConstraint, DragCancelPlan, DragRecognizer, DragRecognizerConfig,
27
+ DragReleaseOptions, DragReleasePlan, DragSettleSpec, DragState, GestureAxisRelease,
28
+ GesturePhase, VelocityTracker, VelocityTrackerConfig, constrain_with_rubber_band,
29
+ constrained_drag_axis_value, nearest_snap, plan_drag_axis_cancel, plan_drag_axis_release,
30
+ rubber_band_distance,
31
+ };
32
+ pub use input::{
33
+ ButtonState, InputEvent, InputOutcome, InputPoint, KeyState, LogicalKey, Modifiers,
34
+ PhysicalKey, PointerButton, PointerId, ScrollDelta, ScrollPhase,
35
+ };
36
+ pub use layout::{FallbackIntrinsicMeasurer, IntrinsicMeasurer, IntrinsicSize, TextLineLayout};
37
+ pub use retained::{
38
+ RetainedIdentityKey, RetainedNode, RetainedNodeKind, RetainedNumberKey, RetainedReconciliation,
39
+ RetainedTree, RetainedTreeError,
40
+ };
41
+ pub use runtime::{
42
+ HotUpdateReport, HotUpdateTimings, ImeRequest, PlatformConventions, Runtime, RuntimeDiagnostic,
43
+ RuntimeFrame, RuntimeLoadError, SEMANTIC_UI_IR_VERSION, StateMutation, Transaction,
44
+ };
45
+ pub use scene::{Color, Rect, Scene};
46
+ pub use scroll::{
47
+ NestedScrollRouteResult, ScrollAxis, ScrollContainerState, ScrollMetrics, ScrollRange,
48
+ ScrollRouteResult, ScrollState, ScrollTracker, route_nested_content_delta,
49
+ };