@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.
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/bin/compile.mjs +38 -0
- package/bin/desktop.mjs +143 -0
- package/bin/dev-protocol.mjs +94 -0
- package/bin/formatter.mjs +109 -0
- package/bin/hot-reload.mjs +38 -0
- package/bin/mun.mjs +538 -0
- package/bin/native.mjs +133 -0
- package/bin/pnpm-workspace.mjs +58 -0
- package/bin/program-patch.mjs +104 -0
- package/bin/project.mjs +322 -0
- package/bin/watch.mjs +316 -0
- package/bin/workflow.mjs +261 -0
- package/dist/astro.d.ts +3 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -0
- package/dist/astro.js.map +1 -0
- package/dist/closures.d.ts +2 -0
- package/dist/closures.d.ts.map +1 -0
- package/dist/closures.js +2 -0
- package/dist/closures.js.map +1 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +2 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +2 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +3 -0
- package/dist/legacy.js.map +1 -0
- package/dist/mun.d.ts +5 -0
- package/dist/mun.d.ts.map +1 -0
- package/dist/mun.js +4 -0
- package/dist/mun.js.map +1 -0
- package/dist/progressive-blur/index.d.ts +8 -0
- package/dist/progressive-blur/index.d.ts.map +1 -0
- package/dist/progressive-blur/index.js +8 -0
- package/dist/progressive-blur/index.js.map +1 -0
- package/dist/progressive-blur/plan.d.ts +3 -0
- package/dist/progressive-blur/plan.d.ts.map +1 -0
- package/dist/progressive-blur/plan.js +3 -0
- package/dist/progressive-blur/plan.js.map +1 -0
- package/dist/react-types.d.ts +2 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +2 -0
- package/dist/react-types.js.map +1 -0
- package/dist/rendering-quality.d.ts +4 -0
- package/dist/rendering-quality.d.ts.map +1 -0
- package/dist/rendering-quality.js +4 -0
- package/dist/rendering-quality.js.map +1 -0
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +2 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/editors/install.mjs +102 -0
- package/editors/lsp/mun-lsp.mjs +123 -0
- package/editors/lsp/service.mjs +306 -0
- package/editors/lsp/source.mjs +58 -0
- package/editors/vscode/client.mjs +40 -0
- package/editors/vscode/dev-client.mjs +83 -0
- package/editors/vscode/discovery.mjs +46 -0
- package/editors/vscode/export.mjs +42 -0
- package/editors/vscode/extension.cjs +226 -0
- package/editors/vscode/language-configuration.json +15 -0
- package/editors/vscode/package.json +119 -0
- package/editors/vscode/protocol.mjs +29 -0
- package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
- package/native/Cargo.lock +3581 -0
- package/native/Cargo.toml +21 -0
- package/native/README.md +21 -0
- package/native/mun-native/Cargo.toml +23 -0
- package/native/mun-native/src/accessibility.rs +738 -0
- package/native/mun-native/src/dev.rs +604 -0
- package/native/mun-native/src/host_services.rs +202 -0
- package/native/mun-native/src/lib.rs +2843 -0
- package/native/mun-native/src/main.rs +204 -0
- package/native/mun-native/src/offscreen.rs +393 -0
- package/native/mun-native/src/rect.wgsl +63 -0
- package/native/mun-native/src/text.rs +401 -0
- package/native/mun-native/tests/offscreen_rendering.rs +161 -0
- package/native/mun-native/tests/stress.rs +408 -0
- package/native/mun-native/tests/window_lifecycle.rs +183 -0
- package/native/mun-runtime/Cargo.toml +13 -0
- package/native/mun-runtime/src/accessibility.rs +193 -0
- package/native/mun-runtime/src/collection.rs +1090 -0
- package/native/mun-runtime/src/gesture.rs +1070 -0
- package/native/mun-runtime/src/input.rs +325 -0
- package/native/mun-runtime/src/ir.rs +852 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +258 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +52 -0
- package/native/mun-runtime/src/motion.rs +1162 -0
- package/native/mun-runtime/src/retained.rs +574 -0
- package/native/mun-runtime/src/runtime.rs +7449 -0
- package/native/mun-runtime/src/scene.rs +567 -0
- package/native/mun-runtime/src/scroll.rs +521 -0
- package/native/mun-runtime/src/scroll_view.rs +220 -0
- package/native/mun-runtime/src/text_edit.rs +670 -0
- package/native/mun-runtime/src/timeline.rs +1534 -0
- package/native/mun-runtime/src/validate.rs +677 -0
- package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
- package/native/mun-runtime/tests/compiler_contract.rs +110 -0
- package/native/mun-runtime/tests/flexible_frames.rs +47 -0
- package/native/mun-runtime/tests/host_services.rs +107 -0
- package/native/mun-runtime/tests/hot_update.rs +367 -0
- package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
- package/native/mun-runtime/tests/ir_validation.rs +167 -0
- package/native/mun-runtime/tests/keyed_collections.rs +251 -0
- package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
- package/native/mun-runtime/tests/native_controls_style.rs +491 -0
- package/native/mun-runtime/tests/native_demo.rs +285 -0
- package/native/mun-runtime/tests/native_layout_style.rs +175 -0
- package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
- package/native/mun-runtime/tests/priority_proposals.rs +69 -0
- package/native/mun-runtime/tests/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/native/mun-runtime/tests/text_proposals.rs +42 -0
- package/native/mun-runtime/tests/typography.rs +63 -0
- package/package.json +213 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
- package/templates/desktop/gitignore +5 -0
- package/templates/desktop/package.json +10 -0
- package/templates/desktop/src-tauri/Cargo.toml +14 -0
- package/templates/desktop/src-tauri/build.rs +1 -0
- package/templates/desktop/src-tauri/capabilities/main.json +12 -0
- package/templates/desktop/src-tauri/icons/icon.icns +0 -0
- package/templates/desktop/src-tauri/icons/icon.ico +0 -0
- package/templates/desktop/src-tauri/icons/icon.png +0 -0
- package/templates/desktop/src-tauri/src/main.rs +2 -0
- package/templates/desktop/src-tauri/tauri.conf.json +42 -0
- package/templates/desktop/vite.config.ts +10 -0
- package/templates/native/App.mun +15 -0
- package/templates/native/gitignore +3 -0
- package/templates/native/mun.toml +8 -0
- package/templates/project/gitignore +5 -0
- package/templates/project/index.html +13 -0
- package/templates/project/package.json +24 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +30 -0
- package/templates/project/src/main.ts +5 -0
- package/templates/project/tsconfig.json +20 -0
- package/templates/project/vite.config.ts +6 -0
- package/templates/vite/src/App.css +134 -0
- package/templates/vite/src/App.tsx +91 -0
- package/templates/vite/src/index.css +23 -0
- 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
|
+
}
|