@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.
- package/LICENSE +21 -0
- package/README.md +104 -2
- package/bin/compile.mjs +38 -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 +521 -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/lib.rs +2676 -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 +310 -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 +1073 -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 +782 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +173 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +49 -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 +7078 -0
- package/native/mun-runtime/src/scene.rs +530 -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/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/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/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/package.json +210 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +1972 -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 +21 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +21 -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,782 @@
|
|
|
1
|
+
use serde::Deserialize;
|
|
2
|
+
use serde_json::Value;
|
|
3
|
+
|
|
4
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
5
|
+
#[serde(rename_all = "camelCase")]
|
|
6
|
+
pub enum UiBinaryOperator {
|
|
7
|
+
Add,
|
|
8
|
+
Subtract,
|
|
9
|
+
Multiply,
|
|
10
|
+
Divide,
|
|
11
|
+
Modulo,
|
|
12
|
+
Equal,
|
|
13
|
+
NotEqual,
|
|
14
|
+
Less,
|
|
15
|
+
LessOrEqual,
|
|
16
|
+
Greater,
|
|
17
|
+
GreaterOrEqual,
|
|
18
|
+
And,
|
|
19
|
+
Or,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
23
|
+
#[serde(tag = "kind")]
|
|
24
|
+
pub enum UiExpression {
|
|
25
|
+
#[serde(rename = "literal")]
|
|
26
|
+
Literal { value: Value },
|
|
27
|
+
#[serde(rename = "state")]
|
|
28
|
+
State { state: String },
|
|
29
|
+
#[serde(rename = "not")]
|
|
30
|
+
Not { value: Box<UiExpression> },
|
|
31
|
+
#[serde(rename = "stringify")]
|
|
32
|
+
Stringify { value: Box<UiExpression> },
|
|
33
|
+
#[serde(rename = "binary")]
|
|
34
|
+
Binary {
|
|
35
|
+
operator: UiBinaryOperator,
|
|
36
|
+
left: Box<UiExpression>,
|
|
37
|
+
right: Box<UiExpression>,
|
|
38
|
+
},
|
|
39
|
+
#[serde(rename = "conditional")]
|
|
40
|
+
Conditional {
|
|
41
|
+
condition: Box<UiExpression>,
|
|
42
|
+
#[serde(rename = "then")]
|
|
43
|
+
then_value: Box<UiExpression>,
|
|
44
|
+
otherwise: Box<UiExpression>,
|
|
45
|
+
},
|
|
46
|
+
/// Current item (or field path inside it) of the enclosing `forEach`.
|
|
47
|
+
#[serde(rename = "item")]
|
|
48
|
+
Item {
|
|
49
|
+
#[serde(rename = "forEach")]
|
|
50
|
+
for_each: String,
|
|
51
|
+
#[serde(default)]
|
|
52
|
+
path: Vec<String>,
|
|
53
|
+
},
|
|
54
|
+
#[serde(rename = "record")]
|
|
55
|
+
Record {
|
|
56
|
+
fields: std::collections::BTreeMap<String, UiExpression>,
|
|
57
|
+
},
|
|
58
|
+
#[serde(rename = "count")]
|
|
59
|
+
Count { collection: Box<UiExpression> },
|
|
60
|
+
#[serde(rename = "filter")]
|
|
61
|
+
Filter {
|
|
62
|
+
collection: Box<UiExpression>,
|
|
63
|
+
path: Vec<String>,
|
|
64
|
+
operator: UiFilterOperator,
|
|
65
|
+
value: Box<UiExpression>,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
70
|
+
#[serde(rename_all = "camelCase")]
|
|
71
|
+
pub enum UiFilterOperator {
|
|
72
|
+
Equal,
|
|
73
|
+
NotEqual,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
77
|
+
#[serde(rename_all = "camelCase")]
|
|
78
|
+
pub struct UiState {
|
|
79
|
+
pub name: String,
|
|
80
|
+
pub initial: Value,
|
|
81
|
+
/// `forEach` template whose items each own an instance of this state.
|
|
82
|
+
#[serde(default)]
|
|
83
|
+
pub scope: Option<String>,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
87
|
+
#[serde(rename_all = "camelCase")]
|
|
88
|
+
pub enum AccessibilityRole {
|
|
89
|
+
Window,
|
|
90
|
+
Group,
|
|
91
|
+
Text,
|
|
92
|
+
Button,
|
|
93
|
+
TextField,
|
|
94
|
+
RadioGroup,
|
|
95
|
+
CheckBox,
|
|
96
|
+
ProgressIndicator,
|
|
97
|
+
/// One option of a radio group. Runtime-derived from `radioGroup` options;
|
|
98
|
+
/// never authored in the IR.
|
|
99
|
+
#[serde(skip_deserializing)]
|
|
100
|
+
RadioButton,
|
|
101
|
+
/// A `SecureField`. Runtime-derived from `textField` with `secure`.
|
|
102
|
+
#[serde(skip_deserializing)]
|
|
103
|
+
SecureTextField,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
107
|
+
#[serde(rename_all = "camelCase")]
|
|
108
|
+
pub struct AccessibilitySemantics {
|
|
109
|
+
pub role: AccessibilityRole,
|
|
110
|
+
#[serde(default)]
|
|
111
|
+
pub label: Option<String>,
|
|
112
|
+
#[serde(default)]
|
|
113
|
+
pub enabled: Option<UiExpression>,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
|
117
|
+
#[serde(rename_all = "lowercase")]
|
|
118
|
+
pub enum UiAlignment {
|
|
119
|
+
Leading,
|
|
120
|
+
Center,
|
|
121
|
+
Trailing,
|
|
122
|
+
Stretch,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
|
126
|
+
#[serde(rename_all = "camelCase")]
|
|
127
|
+
pub enum UiOverlayAlignment {
|
|
128
|
+
Center,
|
|
129
|
+
Leading,
|
|
130
|
+
Trailing,
|
|
131
|
+
Top,
|
|
132
|
+
Bottom,
|
|
133
|
+
TopLeading,
|
|
134
|
+
TopTrailing,
|
|
135
|
+
BottomLeading,
|
|
136
|
+
BottomTrailing,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
140
|
+
pub enum UiPaint {
|
|
141
|
+
Solid {
|
|
142
|
+
color: String,
|
|
143
|
+
},
|
|
144
|
+
LinearGradient {
|
|
145
|
+
start: String,
|
|
146
|
+
end: String,
|
|
147
|
+
start_point: UiOverlayAlignment,
|
|
148
|
+
end_point: UiOverlayAlignment,
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
impl<'de> Deserialize<'de> for UiPaint {
|
|
153
|
+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
154
|
+
where
|
|
155
|
+
D: serde::Deserializer<'de>,
|
|
156
|
+
{
|
|
157
|
+
#[derive(Deserialize)]
|
|
158
|
+
#[serde(tag = "kind")]
|
|
159
|
+
enum StructuredPaint {
|
|
160
|
+
#[serde(rename = "solid")]
|
|
161
|
+
Solid { color: String },
|
|
162
|
+
#[serde(rename = "linearGradient")]
|
|
163
|
+
LinearGradient {
|
|
164
|
+
start: String,
|
|
165
|
+
end: String,
|
|
166
|
+
#[serde(rename = "startPoint")]
|
|
167
|
+
start_point: UiOverlayAlignment,
|
|
168
|
+
#[serde(rename = "endPoint")]
|
|
169
|
+
end_point: UiOverlayAlignment,
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#[derive(Deserialize)]
|
|
174
|
+
#[serde(untagged)]
|
|
175
|
+
enum PaintWire {
|
|
176
|
+
LegacySolid(String),
|
|
177
|
+
Structured(StructuredPaint),
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
Ok(match PaintWire::deserialize(deserializer)? {
|
|
181
|
+
PaintWire::LegacySolid(color) => Self::Solid { color },
|
|
182
|
+
PaintWire::Structured(StructuredPaint::Solid { color }) => Self::Solid { color },
|
|
183
|
+
PaintWire::Structured(StructuredPaint::LinearGradient {
|
|
184
|
+
start,
|
|
185
|
+
end,
|
|
186
|
+
start_point,
|
|
187
|
+
end_point,
|
|
188
|
+
}) => Self::LinearGradient {
|
|
189
|
+
start,
|
|
190
|
+
end,
|
|
191
|
+
start_point,
|
|
192
|
+
end_point,
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
199
|
+
#[serde(rename_all = "camelCase")]
|
|
200
|
+
pub enum UiShapeKind {
|
|
201
|
+
Rectangle,
|
|
202
|
+
RoundedRectangle,
|
|
203
|
+
Circle,
|
|
204
|
+
Capsule,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
208
|
+
#[serde(rename_all = "camelCase")]
|
|
209
|
+
pub struct UiSelectionOption {
|
|
210
|
+
pub label: String,
|
|
211
|
+
pub value: Value,
|
|
212
|
+
#[serde(default)]
|
|
213
|
+
pub disabled: bool,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
|
|
217
|
+
#[serde(rename_all = "camelCase")]
|
|
218
|
+
pub struct UiLayout {
|
|
219
|
+
#[serde(default)]
|
|
220
|
+
pub width: Option<UiExpression>,
|
|
221
|
+
#[serde(default)]
|
|
222
|
+
pub height: Option<UiExpression>,
|
|
223
|
+
#[serde(default)]
|
|
224
|
+
pub padding: Option<UiPadding>,
|
|
225
|
+
#[serde(default)]
|
|
226
|
+
pub spacing: Option<f32>,
|
|
227
|
+
#[serde(default)]
|
|
228
|
+
pub alignment: Option<UiAlignment>,
|
|
229
|
+
#[serde(default)]
|
|
230
|
+
pub min_width: Option<f32>,
|
|
231
|
+
#[serde(default)]
|
|
232
|
+
pub max_width: Option<UiFrameBound>,
|
|
233
|
+
#[serde(default)]
|
|
234
|
+
pub min_height: Option<f32>,
|
|
235
|
+
#[serde(default)]
|
|
236
|
+
pub max_height: Option<UiFrameBound>,
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// Uniform padding or per-edge insets (leading/trailing follow layout direction).
|
|
240
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
|
241
|
+
#[serde(untagged)]
|
|
242
|
+
pub enum UiPadding {
|
|
243
|
+
Uniform(f32),
|
|
244
|
+
Edges {
|
|
245
|
+
top: f32,
|
|
246
|
+
leading: f32,
|
|
247
|
+
bottom: f32,
|
|
248
|
+
trailing: f32,
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
impl UiPadding {
|
|
253
|
+
/// `[top, leading, bottom, trailing]`.
|
|
254
|
+
pub fn edges(self) -> [f32; 4] {
|
|
255
|
+
match self {
|
|
256
|
+
Self::Uniform(value) => [value; 4],
|
|
257
|
+
Self::Edges {
|
|
258
|
+
top,
|
|
259
|
+
leading,
|
|
260
|
+
bottom,
|
|
261
|
+
trailing,
|
|
262
|
+
} => [top, leading, bottom, trailing],
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/// Upper bound of a flexible frame: a length or `"infinity"`.
|
|
268
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
|
269
|
+
#[serde(untagged)]
|
|
270
|
+
pub enum UiFrameBound {
|
|
271
|
+
Length(f32),
|
|
272
|
+
Unbounded(UiInfinity),
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
|
|
276
|
+
pub enum UiInfinity {
|
|
277
|
+
#[serde(rename = "infinity")]
|
|
278
|
+
Infinity,
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
impl UiFrameBound {
|
|
282
|
+
/// Finite maximum, if any (`None` for unbounded).
|
|
283
|
+
pub fn length(self) -> Option<f32> {
|
|
284
|
+
match self {
|
|
285
|
+
Self::Length(value) => Some(value),
|
|
286
|
+
Self::Unbounded(_) => None,
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
|
|
292
|
+
#[serde(rename_all = "camelCase")]
|
|
293
|
+
pub struct UiVisual {
|
|
294
|
+
#[serde(default)]
|
|
295
|
+
pub background: Option<UiPaint>,
|
|
296
|
+
#[serde(default)]
|
|
297
|
+
pub foreground: Option<UiPaint>,
|
|
298
|
+
#[serde(default)]
|
|
299
|
+
pub corner_radius: Option<f32>,
|
|
300
|
+
#[serde(default)]
|
|
301
|
+
pub opacity: Option<UiExpression>,
|
|
302
|
+
#[serde(default)]
|
|
303
|
+
pub translation_x: Option<UiExpression>,
|
|
304
|
+
#[serde(default)]
|
|
305
|
+
pub translation_y: Option<UiExpression>,
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq)]
|
|
309
|
+
#[serde(rename_all = "camelCase")]
|
|
310
|
+
pub enum MotionProperty {
|
|
311
|
+
Opacity,
|
|
312
|
+
TranslationX,
|
|
313
|
+
TranslationY,
|
|
314
|
+
ScaleX,
|
|
315
|
+
ScaleY,
|
|
316
|
+
Rotation,
|
|
317
|
+
ForegroundColor,
|
|
318
|
+
BackgroundColor,
|
|
319
|
+
BorderColor,
|
|
320
|
+
Width,
|
|
321
|
+
Height,
|
|
322
|
+
MinWidth,
|
|
323
|
+
MinHeight,
|
|
324
|
+
MaxWidth,
|
|
325
|
+
MaxHeight,
|
|
326
|
+
PaddingTop,
|
|
327
|
+
PaddingRight,
|
|
328
|
+
PaddingBottom,
|
|
329
|
+
PaddingLeft,
|
|
330
|
+
MarginTop,
|
|
331
|
+
MarginRight,
|
|
332
|
+
MarginBottom,
|
|
333
|
+
MarginLeft,
|
|
334
|
+
RowGap,
|
|
335
|
+
ColumnGap,
|
|
336
|
+
FontSize,
|
|
337
|
+
LineHeight,
|
|
338
|
+
LetterSpacing,
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
342
|
+
#[serde(tag = "kind")]
|
|
343
|
+
pub enum MotionExecutionPlan {
|
|
344
|
+
#[serde(rename = "spring")]
|
|
345
|
+
Spring {
|
|
346
|
+
omega: f32,
|
|
347
|
+
#[serde(rename = "dampingRatio")]
|
|
348
|
+
damping_ratio: f32,
|
|
349
|
+
#[serde(rename = "blendDuration")]
|
|
350
|
+
blend_duration: f32,
|
|
351
|
+
#[serde(rename = "delayMs")]
|
|
352
|
+
delay_ms: f32,
|
|
353
|
+
#[serde(rename = "repeatCount")]
|
|
354
|
+
repeat_count: Value,
|
|
355
|
+
autoreverses: bool,
|
|
356
|
+
},
|
|
357
|
+
#[serde(rename = "timing")]
|
|
358
|
+
Timing {
|
|
359
|
+
duration: f32,
|
|
360
|
+
curve: [f32; 4],
|
|
361
|
+
#[serde(rename = "delayMs")]
|
|
362
|
+
delay_ms: f32,
|
|
363
|
+
#[serde(rename = "repeatCount")]
|
|
364
|
+
repeat_count: Value,
|
|
365
|
+
autoreverses: bool,
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
370
|
+
#[serde(rename_all = "lowercase")]
|
|
371
|
+
pub enum TransitionEdge {
|
|
372
|
+
Top,
|
|
373
|
+
Bottom,
|
|
374
|
+
Leading,
|
|
375
|
+
Trailing,
|
|
376
|
+
Left,
|
|
377
|
+
Right,
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
381
|
+
#[serde(tag = "kind")]
|
|
382
|
+
pub enum TransitionEffect {
|
|
383
|
+
#[serde(rename = "opacity")]
|
|
384
|
+
Opacity,
|
|
385
|
+
#[serde(rename = "scale")]
|
|
386
|
+
Scale { scale: f32 },
|
|
387
|
+
#[serde(rename = "move")]
|
|
388
|
+
Move { edge: TransitionEdge, distance: f32 },
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
392
|
+
#[serde(rename_all = "camelCase")]
|
|
393
|
+
pub struct UiTransition {
|
|
394
|
+
#[serde(default)]
|
|
395
|
+
pub insertion: Vec<TransitionEffect>,
|
|
396
|
+
#[serde(default)]
|
|
397
|
+
pub removal: Vec<TransitionEffect>,
|
|
398
|
+
#[serde(default)]
|
|
399
|
+
pub animation: Option<MotionExecutionPlan>,
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
403
|
+
#[serde(rename_all = "camelCase")]
|
|
404
|
+
pub struct UiMotionBinding {
|
|
405
|
+
pub property: MotionProperty,
|
|
406
|
+
pub property_mask: u32,
|
|
407
|
+
pub value: UiExpression,
|
|
408
|
+
#[serde(default)]
|
|
409
|
+
pub trigger: Option<UiExpression>,
|
|
410
|
+
#[serde(default)]
|
|
411
|
+
pub plan: Option<MotionExecutionPlan>,
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
|
|
415
|
+
#[serde(rename_all = "camelCase")]
|
|
416
|
+
pub struct UiTransaction {
|
|
417
|
+
#[serde(default)]
|
|
418
|
+
pub animation: Option<MotionExecutionPlan>,
|
|
419
|
+
#[serde(default)]
|
|
420
|
+
pub disables_animations: bool,
|
|
421
|
+
#[serde(default)]
|
|
422
|
+
pub is_continuous: bool,
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/// Keyed collection mutation; items are addressed by key, never by index.
|
|
426
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
427
|
+
#[serde(tag = "operation", rename_all = "camelCase")]
|
|
428
|
+
pub enum UiCollectionOperation {
|
|
429
|
+
Insert {
|
|
430
|
+
index: UiExpression,
|
|
431
|
+
value: UiExpression,
|
|
432
|
+
},
|
|
433
|
+
Append {
|
|
434
|
+
value: UiExpression,
|
|
435
|
+
},
|
|
436
|
+
Remove {
|
|
437
|
+
key: UiExpression,
|
|
438
|
+
},
|
|
439
|
+
Move {
|
|
440
|
+
key: UiExpression,
|
|
441
|
+
offset: UiExpression,
|
|
442
|
+
},
|
|
443
|
+
Update {
|
|
444
|
+
key: UiExpression,
|
|
445
|
+
path: Vec<String>,
|
|
446
|
+
value: UiExpression,
|
|
447
|
+
},
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
451
|
+
#[serde(tag = "kind")]
|
|
452
|
+
pub enum UiAction {
|
|
453
|
+
#[serde(rename = "toggle-state")]
|
|
454
|
+
ToggleState {
|
|
455
|
+
state: String,
|
|
456
|
+
#[serde(default)]
|
|
457
|
+
transaction: Option<UiTransaction>,
|
|
458
|
+
},
|
|
459
|
+
#[serde(rename = "set-state")]
|
|
460
|
+
SetState {
|
|
461
|
+
state: String,
|
|
462
|
+
value: UiExpression,
|
|
463
|
+
#[serde(default)]
|
|
464
|
+
transaction: Option<UiTransaction>,
|
|
465
|
+
},
|
|
466
|
+
#[serde(rename = "collection")]
|
|
467
|
+
Collection {
|
|
468
|
+
state: String,
|
|
469
|
+
#[serde(rename = "keyPath")]
|
|
470
|
+
key_path: Vec<String>,
|
|
471
|
+
#[serde(flatten)]
|
|
472
|
+
operation: UiCollectionOperation,
|
|
473
|
+
#[serde(default)]
|
|
474
|
+
transaction: Option<UiTransaction>,
|
|
475
|
+
},
|
|
476
|
+
#[serde(rename = "sequence")]
|
|
477
|
+
Sequence {
|
|
478
|
+
actions: Vec<UiAction>,
|
|
479
|
+
#[serde(default)]
|
|
480
|
+
transaction: Option<UiTransaction>,
|
|
481
|
+
},
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
impl UiAction {
|
|
485
|
+
pub fn transaction(&self) -> Option<&UiTransaction> {
|
|
486
|
+
match self {
|
|
487
|
+
Self::ToggleState { transaction, .. }
|
|
488
|
+
| Self::SetState { transaction, .. }
|
|
489
|
+
| Self::Collection { transaction, .. }
|
|
490
|
+
| Self::Sequence { transaction, .. } => transaction.as_ref(),
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
|
|
496
|
+
#[serde(rename_all = "camelCase")]
|
|
497
|
+
pub struct NodeBase {
|
|
498
|
+
pub id: String,
|
|
499
|
+
#[serde(default)]
|
|
500
|
+
pub identity_key: Option<UiExpression>,
|
|
501
|
+
#[serde(default)]
|
|
502
|
+
pub layout: Option<UiLayout>,
|
|
503
|
+
#[serde(default)]
|
|
504
|
+
pub visual: Option<UiVisual>,
|
|
505
|
+
#[serde(default)]
|
|
506
|
+
pub accessibility: Option<AccessibilitySemantics>,
|
|
507
|
+
#[serde(default)]
|
|
508
|
+
pub motion: Vec<UiMotionBinding>,
|
|
509
|
+
#[serde(default)]
|
|
510
|
+
pub transition: Option<UiTransition>,
|
|
511
|
+
/// Actions run when the View starts or stops being semantically present
|
|
512
|
+
/// (an active conditional branch, a materialized collection item).
|
|
513
|
+
#[serde(default)]
|
|
514
|
+
pub lifecycle: Option<UiLifecycle>,
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
|
|
518
|
+
pub struct UiLifecycle {
|
|
519
|
+
#[serde(default)]
|
|
520
|
+
pub appear: Option<UiAction>,
|
|
521
|
+
#[serde(default)]
|
|
522
|
+
pub disappear: Option<UiAction>,
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
|
526
|
+
#[serde(rename_all = "lowercase")]
|
|
527
|
+
pub enum UiScrollAxis {
|
|
528
|
+
Vertical,
|
|
529
|
+
Horizontal,
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
533
|
+
#[serde(tag = "kind")]
|
|
534
|
+
pub enum UiNode {
|
|
535
|
+
#[serde(rename = "scroll")]
|
|
536
|
+
Scroll {
|
|
537
|
+
#[serde(flatten)]
|
|
538
|
+
base: NodeBase,
|
|
539
|
+
axis: UiScrollAxis,
|
|
540
|
+
children: Vec<UiNode>,
|
|
541
|
+
},
|
|
542
|
+
#[serde(rename = "column")]
|
|
543
|
+
Column {
|
|
544
|
+
#[serde(flatten)]
|
|
545
|
+
base: NodeBase,
|
|
546
|
+
children: Vec<UiNode>,
|
|
547
|
+
},
|
|
548
|
+
#[serde(rename = "row")]
|
|
549
|
+
Row {
|
|
550
|
+
#[serde(flatten)]
|
|
551
|
+
base: NodeBase,
|
|
552
|
+
children: Vec<UiNode>,
|
|
553
|
+
},
|
|
554
|
+
#[serde(rename = "overlay")]
|
|
555
|
+
Overlay {
|
|
556
|
+
#[serde(flatten)]
|
|
557
|
+
base: NodeBase,
|
|
558
|
+
#[serde(default)]
|
|
559
|
+
alignment: Option<UiOverlayAlignment>,
|
|
560
|
+
children: Vec<UiNode>,
|
|
561
|
+
},
|
|
562
|
+
#[serde(rename = "conditional")]
|
|
563
|
+
Conditional {
|
|
564
|
+
#[serde(flatten)]
|
|
565
|
+
base: NodeBase,
|
|
566
|
+
condition: UiExpression,
|
|
567
|
+
#[serde(rename = "then")]
|
|
568
|
+
then_nodes: Vec<UiNode>,
|
|
569
|
+
#[serde(default)]
|
|
570
|
+
otherwise: Vec<UiNode>,
|
|
571
|
+
},
|
|
572
|
+
/// Keyed dynamic children: `children` is instantiated per collection item.
|
|
573
|
+
/// The runtime materializes each instance (identity = template identity +
|
|
574
|
+
/// item key) before layout; materialized trees never contain this variant.
|
|
575
|
+
#[serde(rename = "forEach")]
|
|
576
|
+
ForEach {
|
|
577
|
+
#[serde(flatten)]
|
|
578
|
+
base: NodeBase,
|
|
579
|
+
collection: UiExpression,
|
|
580
|
+
#[serde(rename = "keyPath")]
|
|
581
|
+
key_path: Vec<String>,
|
|
582
|
+
children: Vec<UiNode>,
|
|
583
|
+
},
|
|
584
|
+
#[serde(rename = "text")]
|
|
585
|
+
Text {
|
|
586
|
+
#[serde(flatten)]
|
|
587
|
+
base: NodeBase,
|
|
588
|
+
value: UiExpression,
|
|
589
|
+
},
|
|
590
|
+
#[serde(rename = "panel")]
|
|
591
|
+
Panel {
|
|
592
|
+
#[serde(flatten)]
|
|
593
|
+
base: NodeBase,
|
|
594
|
+
#[serde(default)]
|
|
595
|
+
shape: Option<UiShapeKind>,
|
|
596
|
+
},
|
|
597
|
+
#[serde(rename = "textField")]
|
|
598
|
+
TextField {
|
|
599
|
+
#[serde(flatten)]
|
|
600
|
+
base: NodeBase,
|
|
601
|
+
state: String,
|
|
602
|
+
#[serde(default)]
|
|
603
|
+
placeholder: Option<String>,
|
|
604
|
+
/// A secure field: presented masked, not copyable, no IME.
|
|
605
|
+
#[serde(default)]
|
|
606
|
+
secure: bool,
|
|
607
|
+
},
|
|
608
|
+
/// A Bool control (macOS checkbox presentation).
|
|
609
|
+
#[serde(rename = "toggle")]
|
|
610
|
+
Toggle {
|
|
611
|
+
#[serde(flatten)]
|
|
612
|
+
base: NodeBase,
|
|
613
|
+
state: String,
|
|
614
|
+
label: String,
|
|
615
|
+
},
|
|
616
|
+
/// Determinate progress: `value` of `total` (default 1).
|
|
617
|
+
#[serde(rename = "progress")]
|
|
618
|
+
Progress {
|
|
619
|
+
#[serde(flatten)]
|
|
620
|
+
base: NodeBase,
|
|
621
|
+
value: UiExpression,
|
|
622
|
+
#[serde(default)]
|
|
623
|
+
total: Option<UiExpression>,
|
|
624
|
+
#[serde(default)]
|
|
625
|
+
label: Option<String>,
|
|
626
|
+
},
|
|
627
|
+
/// Flexible space along the containing stack's axis.
|
|
628
|
+
#[serde(rename = "spacer")]
|
|
629
|
+
Spacer {
|
|
630
|
+
#[serde(flatten)]
|
|
631
|
+
base: NodeBase,
|
|
632
|
+
#[serde(default, rename = "minLength")]
|
|
633
|
+
min_length: Option<f32>,
|
|
634
|
+
},
|
|
635
|
+
/// A separator line across the containing stack's axis.
|
|
636
|
+
#[serde(rename = "divider")]
|
|
637
|
+
Divider {
|
|
638
|
+
#[serde(flatten)]
|
|
639
|
+
base: NodeBase,
|
|
640
|
+
},
|
|
641
|
+
#[serde(rename = "radioGroup")]
|
|
642
|
+
RadioGroup {
|
|
643
|
+
#[serde(flatten)]
|
|
644
|
+
base: NodeBase,
|
|
645
|
+
state: String,
|
|
646
|
+
options: Vec<UiSelectionOption>,
|
|
647
|
+
},
|
|
648
|
+
#[serde(rename = "action")]
|
|
649
|
+
Action {
|
|
650
|
+
#[serde(flatten)]
|
|
651
|
+
base: NodeBase,
|
|
652
|
+
label: String,
|
|
653
|
+
action: UiAction,
|
|
654
|
+
},
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
impl UiNode {
|
|
658
|
+
pub fn base(&self) -> &NodeBase {
|
|
659
|
+
match self {
|
|
660
|
+
Self::Column { base, .. }
|
|
661
|
+
| Self::Row { base, .. }
|
|
662
|
+
| Self::Overlay { base, .. }
|
|
663
|
+
| Self::Conditional { base, .. }
|
|
664
|
+
| Self::ForEach { base, .. }
|
|
665
|
+
| Self::Text { base, .. }
|
|
666
|
+
| Self::Panel { base, .. }
|
|
667
|
+
| Self::Scroll { base, .. }
|
|
668
|
+
| Self::TextField { base, .. }
|
|
669
|
+
| Self::Toggle { base, .. }
|
|
670
|
+
| Self::Progress { base, .. }
|
|
671
|
+
| Self::Spacer { base, .. }
|
|
672
|
+
| Self::Divider { base, .. }
|
|
673
|
+
| Self::RadioGroup { base, .. }
|
|
674
|
+
| Self::Action { base, .. } => base,
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
pub fn children(&self) -> &[UiNode] {
|
|
679
|
+
match self {
|
|
680
|
+
Self::Column { children, .. }
|
|
681
|
+
| Self::Row { children, .. }
|
|
682
|
+
| Self::Overlay { children, .. }
|
|
683
|
+
| Self::Scroll { children, .. }
|
|
684
|
+
| Self::ForEach { children, .. } => children,
|
|
685
|
+
_ => &[],
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
691
|
+
#[serde(rename_all = "camelCase")]
|
|
692
|
+
pub struct UiWindow {
|
|
693
|
+
pub kind: String,
|
|
694
|
+
pub id: String,
|
|
695
|
+
pub title: String,
|
|
696
|
+
#[serde(default)]
|
|
697
|
+
pub identity_key: Option<UiExpression>,
|
|
698
|
+
#[serde(default)]
|
|
699
|
+
pub layout: Option<UiLayout>,
|
|
700
|
+
#[serde(default)]
|
|
701
|
+
pub visual: Option<UiVisual>,
|
|
702
|
+
#[serde(default)]
|
|
703
|
+
pub accessibility: Option<AccessibilitySemantics>,
|
|
704
|
+
#[serde(default)]
|
|
705
|
+
pub motion: Vec<UiMotionBinding>,
|
|
706
|
+
#[serde(default)]
|
|
707
|
+
pub transition: Option<UiTransition>,
|
|
708
|
+
pub child: UiNode,
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
|
712
|
+
#[serde(rename_all = "camelCase")]
|
|
713
|
+
pub struct UiProgram {
|
|
714
|
+
pub version: u32,
|
|
715
|
+
pub source_language: String,
|
|
716
|
+
pub entry: String,
|
|
717
|
+
pub states: Vec<UiState>,
|
|
718
|
+
pub root: UiWindow,
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
#[cfg(test)]
|
|
722
|
+
mod tests {
|
|
723
|
+
use super::*;
|
|
724
|
+
|
|
725
|
+
#[test]
|
|
726
|
+
fn node_base_preserves_semantic_identity_key() {
|
|
727
|
+
let node: UiNode = serde_json::from_value(serde_json::json!({
|
|
728
|
+
"kind": "text",
|
|
729
|
+
"id": "@node/entry/App/body/kind/text",
|
|
730
|
+
"identityKey": { "kind": "literal", "value": "hero" },
|
|
731
|
+
"value": { "kind": "literal", "value": "Hello" }
|
|
732
|
+
}))
|
|
733
|
+
.expect("semantic node");
|
|
734
|
+
|
|
735
|
+
match node.base().identity_key.as_ref() {
|
|
736
|
+
Some(UiExpression::Literal { value }) => assert_eq!(value, "hero"),
|
|
737
|
+
other => panic!("expected literal semantic identity key, received {other:?}"),
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
#[test]
|
|
742
|
+
fn window_preserves_full_semantic_node_base_metadata() {
|
|
743
|
+
let program: UiProgram = serde_json::from_value(serde_json::json!({
|
|
744
|
+
"version": 1,
|
|
745
|
+
"sourceLanguage": "mun",
|
|
746
|
+
"entry": "App",
|
|
747
|
+
"states": [],
|
|
748
|
+
"root": {
|
|
749
|
+
"kind": "window",
|
|
750
|
+
"id": "window-root",
|
|
751
|
+
"identityKey": { "kind": "state", "state": "window-key" },
|
|
752
|
+
"title": "Mün",
|
|
753
|
+
"visual": {
|
|
754
|
+
"opacity": { "kind": "literal", "value": 0.75 }
|
|
755
|
+
},
|
|
756
|
+
"motion": [{
|
|
757
|
+
"property": "opacity",
|
|
758
|
+
"propertyMask": 1,
|
|
759
|
+
"value": { "kind": "state", "state": "window-opacity" }
|
|
760
|
+
}],
|
|
761
|
+
"transition": {
|
|
762
|
+
"insertion": [{ "kind": "opacity" }],
|
|
763
|
+
"removal": [{ "kind": "opacity" }]
|
|
764
|
+
},
|
|
765
|
+
"child": {
|
|
766
|
+
"kind": "text",
|
|
767
|
+
"id": "label",
|
|
768
|
+
"value": { "kind": "literal", "value": "Hello" }
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}))
|
|
772
|
+
.expect("semantic program");
|
|
773
|
+
|
|
774
|
+
assert!(matches!(
|
|
775
|
+
program.root.identity_key,
|
|
776
|
+
Some(UiExpression::State { ref state }) if state == "window-key"
|
|
777
|
+
));
|
|
778
|
+
assert!(program.root.visual.is_some());
|
|
779
|
+
assert_eq!(program.root.motion.len(), 1);
|
|
780
|
+
assert!(program.root.transition.is_some());
|
|
781
|
+
}
|
|
782
|
+
}
|