1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! Motion safety validation pass.
//!
//! Every animation must have a ReducedMotion alternative.
//! Missing ReducedMotion is a compile error — accessibility
//! is non-negotiable.
use crate::errors::{Diagnostic, Severity, ValidationResult};
use crate::index::NodeIndex;
use crate::ir::{ChildNode, VoceIr};
use crate::passes::ValidationPass;
pub struct MotionPass;
impl ValidationPass for MotionPass {
fn name(&self) -> &'static str {
"motion"
}
fn run(&self, ir: &VoceIr, _index: &NodeIndex, result: &mut ValidationResult) {
let root = match &ir.root {
Some(r) => r,
None => return,
};
if let Some(ref children) = root.children {
self.check_children(children, "/root/children", result);
}
}
}
impl MotionPass {
fn check_children(
&self,
children: &[ChildNode],
parent_path: &str,
result: &mut ValidationResult,
) {
for (i, child) in children.iter().enumerate() {
let path = format!("{parent_path}/{i}");
match child.type_name() {
// MOT001: AnimationTransition must have ReducedMotion
"AnimationTransition" => {
if let Some(anim) = child.as_type::<crate::ir::AnimationTransition>() {
if anim.reduced_motion.is_none() {
result.diagnostics.push(Diagnostic {
severity: Severity::Error,
code: "MOT001".to_string(),
message:
"AnimationTransition must have a reduced_motion alternative"
.to_string(),
node_path: path.clone(),
pass: self.name().to_string(),
hint: None,
});
}
// MOT004: Duration warning
if let Some(ref dur) = anim.duration {
if let Some(ms) = dur.get("ms").and_then(|v| v.as_f64()) {
if ms > 5000.0 {
result.diagnostics.push(Diagnostic {
severity: Severity::Warning,
code: "MOT004".to_string(),
message: format!("Animation duration is {ms}ms — consider shorter durations for better UX"),
node_path: path.clone(),
pass: self.name().to_string(),
hint: None,
});
}
}
}
}
}
// MOT002: Sequence must have ReducedMotion
"Sequence" => {
if let Some(seq) = child.as_type::<crate::ir::Sequence>() {
if seq.reduced_motion.is_none() {
result.diagnostics.push(Diagnostic {
severity: Severity::Error,
code: "MOT002".to_string(),
message: "Sequence must have a reduced_motion alternative"
.to_string(),
node_path: path.clone(),
pass: self.name().to_string(),
hint: None,
});
}
}
}
// MOT005: ScrollBinding must have ReducedMotion
"ScrollBinding" => {
if let Some(sb) = child.as_type::<crate::ir::ScrollBinding>() {
if sb.reduced_motion.is_none() {
result.diagnostics.push(Diagnostic {
severity: Severity::Error,
code: "MOT005".to_string(),
message: "ScrollBinding must have a reduced_motion alternative"
.to_string(),
node_path: path.clone(),
pass: self.name().to_string(),
hint: None,
});
}
}
}
// MOT003: PhysicsBody damping must be > 0
"PhysicsBody" => {
let damping = child
.value
.get("damping")
.and_then(|v| v.as_f64())
.unwrap_or(25.0);
if damping <= 0.0 {
result.diagnostics.push(Diagnostic {
severity: Severity::Error,
code: "MOT003".to_string(),
message:
"PhysicsBody damping must be > 0 to prevent infinite oscillation"
.to_string(),
node_path: path.clone(),
pass: self.name().to_string(),
hint: None,
});
}
}
_ => {}
}
if let Some(grandchildren) = child.children() {
self.check_children(&grandchildren, &format!("{path}/children"), result);
}
}
}
}