@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,202 @@
1
+ //! Desktop implementation of the Mün `HostServices` contract: a small,
2
+ //! path-based file-system service and a workspace service that hands paths
3
+ //! and URLs to the operating system. The runtime only sees JSON values.
4
+
5
+ use mun_runtime::HostServices;
6
+ use serde_json::{Value, json};
7
+ use std::{fs, path::PathBuf, process::Command};
8
+
9
+ #[derive(Default)]
10
+ pub struct DesktopHostServices;
11
+
12
+ fn text(arguments: &[Value], index: usize, role: &str) -> Result<String, String> {
13
+ match arguments.get(index) {
14
+ Some(Value::String(value)) => Ok(value.clone()),
15
+ Some(Value::Null) | None => Err(format!("missing {role} (argument {})", index + 1)),
16
+ Some(other) => Ok(match other {
17
+ Value::Number(number) => number.to_string(),
18
+ Value::Bool(flag) => flag.to_string(),
19
+ _ => return Err(format!("{role} must be text, got {other}")),
20
+ }),
21
+ }
22
+ }
23
+
24
+ fn home() -> Result<PathBuf, String> {
25
+ std::env::var_os("HOME")
26
+ .or_else(|| std::env::var_os("USERPROFILE"))
27
+ .map(PathBuf::from)
28
+ .ok_or_else(|| "no home directory is set".to_string())
29
+ }
30
+
31
+ /// Expand a leading `~` and resolve relative paths against the home directory
32
+ /// so a packaged app never depends on its launch directory.
33
+ fn resolve(path: &str) -> Result<PathBuf, String> {
34
+ let path = path.trim();
35
+ if path.is_empty() {
36
+ return Err("path is empty".to_string());
37
+ }
38
+ if path == "~" {
39
+ return home();
40
+ }
41
+ if let Some(rest) = path.strip_prefix("~/") {
42
+ return Ok(home()?.join(rest));
43
+ }
44
+ let path = PathBuf::from(path);
45
+ if path.is_absolute() {
46
+ Ok(path)
47
+ } else {
48
+ Ok(home()?.join(path))
49
+ }
50
+ }
51
+
52
+ fn path_string(path: &std::path::Path) -> String {
53
+ path.to_string_lossy().into_owned()
54
+ }
55
+
56
+ fn io(context: &str, path: &std::path::Path, error: std::io::Error) -> String {
57
+ format!("{context} {}: {error}", path.display())
58
+ }
59
+
60
+ fn list(path: &std::path::Path) -> Result<Value, String> {
61
+ let mut entries = Vec::new();
62
+ for entry in fs::read_dir(path).map_err(|error| io("cannot list", path, error))? {
63
+ let entry = entry.map_err(|error| io("cannot list", path, error))?;
64
+ let metadata = match entry.metadata() {
65
+ Ok(metadata) => metadata,
66
+ Err(_) => continue,
67
+ };
68
+ let name = entry.file_name().to_string_lossy().into_owned();
69
+ entries.push((
70
+ !metadata.is_dir(),
71
+ name.to_lowercase(),
72
+ json!({
73
+ "name": name,
74
+ "path": path_string(&entry.path()),
75
+ "isDirectory": metadata.is_dir(),
76
+ "size": metadata.len(),
77
+ "hidden": entry.file_name().to_string_lossy().starts_with('.'),
78
+ }),
79
+ ));
80
+ }
81
+ entries.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1)));
82
+ Ok(Value::Array(
83
+ entries.into_iter().map(|(_, _, value)| value).collect(),
84
+ ))
85
+ }
86
+
87
+ fn open_with_system(target: &str, reveal: bool) -> Result<Value, String> {
88
+ #[cfg(target_os = "macos")]
89
+ let mut command = {
90
+ let mut command = Command::new("open");
91
+ if reveal {
92
+ command.arg("-R");
93
+ }
94
+ command.arg(target);
95
+ command
96
+ };
97
+ #[cfg(target_os = "windows")]
98
+ let mut command = {
99
+ let mut command = Command::new("explorer");
100
+ if reveal {
101
+ command.arg(format!("/select,{target}"));
102
+ } else {
103
+ command.arg(target);
104
+ }
105
+ command
106
+ };
107
+ #[cfg(not(any(target_os = "macos", target_os = "windows")))]
108
+ let mut command = {
109
+ let mut command = Command::new("xdg-open");
110
+ let shown = if reveal {
111
+ std::path::Path::new(target)
112
+ .parent()
113
+ .map(path_string)
114
+ .unwrap_or_else(|| target.to_string())
115
+ } else {
116
+ target.to_string()
117
+ };
118
+ command.arg(shown);
119
+ command
120
+ };
121
+ command
122
+ .spawn()
123
+ .map(|_| Value::Null)
124
+ .map_err(|error| format!("cannot open {target}: {error}"))
125
+ }
126
+
127
+ impl HostServices for DesktopHostServices {
128
+ fn call(
129
+ &mut self,
130
+ service: &str,
131
+ operation: &str,
132
+ arguments: &[Value],
133
+ ) -> Result<Value, String> {
134
+ match (service, operation) {
135
+ ("files", "homeDirectory") => home().map(|path| Value::String(path_string(&path))),
136
+ ("files", "list") => list(&resolve(&text(arguments, 0, "a directory path")?)?),
137
+ ("files", "exists") => Ok(Value::Bool(
138
+ resolve(&text(arguments, 0, "a path")?)?.exists(),
139
+ )),
140
+ ("files", "readText") => {
141
+ let path = resolve(&text(arguments, 0, "a file path")?)?;
142
+ fs::read_to_string(&path)
143
+ .map(Value::String)
144
+ .map_err(|error| io("cannot read", &path, error))
145
+ }
146
+ ("files", "writeText") => {
147
+ let path = resolve(&text(arguments, 0, "a file path")?)?;
148
+ let contents = text(arguments, 1, "text to write")?;
149
+ if let Some(parent) = path.parent() {
150
+ fs::create_dir_all(parent)
151
+ .map_err(|error| io("cannot create", parent, error))?;
152
+ }
153
+ fs::write(&path, contents)
154
+ .map(|_| Value::Null)
155
+ .map_err(|error| io("cannot write", &path, error))
156
+ }
157
+ ("files", "createDirectory") => {
158
+ let path = resolve(&text(arguments, 0, "a directory path")?)?;
159
+ fs::create_dir_all(&path)
160
+ .map(|_| Value::Null)
161
+ .map_err(|error| io("cannot create", &path, error))
162
+ }
163
+ ("files", "remove") => {
164
+ let path = resolve(&text(arguments, 0, "a path")?)?;
165
+ let result = if path.is_dir() {
166
+ fs::remove_dir(&path)
167
+ } else {
168
+ fs::remove_file(&path)
169
+ };
170
+ result
171
+ .map(|_| Value::Null)
172
+ .map_err(|error| io("cannot remove", &path, error))
173
+ }
174
+ ("files", "parent") => {
175
+ let path = resolve(&text(arguments, 0, "a path")?)?;
176
+ Ok(Value::String(path_string(path.parent().unwrap_or(&path))))
177
+ }
178
+ ("files", "join") => {
179
+ let base = resolve(&text(arguments, 0, "a base path")?)?;
180
+ Ok(Value::String(path_string(&base.join(text(
181
+ arguments,
182
+ 1,
183
+ "a path component",
184
+ )?))))
185
+ }
186
+ ("workspace", "reveal") => {
187
+ let path = resolve(&text(arguments, 0, "a path")?)?;
188
+ open_with_system(&path_string(&path), true)
189
+ }
190
+ ("workspace", "open") => {
191
+ let target = text(arguments, 0, "a path or URL")?;
192
+ let target = if target.contains("://") {
193
+ target
194
+ } else {
195
+ path_string(&resolve(&target)?)
196
+ };
197
+ open_with_system(&target, false)
198
+ }
199
+ _ => Err(format!("unknown host service {service}.{operation}")),
200
+ }
201
+ }
202
+ }