Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_CHxB9HNH9RXXboczwgIMk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"Cargo.toml": "Minor"
},
"note": "Add a per-state and per-requirement verification matrix to devup_feature_trace: Figma-vs-implementation state comparisons, requirement verdicts with scope and evidence, Figma data gaps that block design-match claims, change impact, a user review report and an ordered follow-up for unfinished verification",
"date": "2026-11-28T14:35:15.989000Z"
}
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_YpvjxS4lM2N45tl-Cz0qN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"Cargo.toml": "Minor"
},
"note": "Encode request-shaped UI motion criteria: sequential entrances, units, order and direction, disclosures, once-per-visit entrances, emphasis loops and reduced motion switched on mid-use, as guide rules, contract identifiers, ui_validate rules and runtime audit checks",
"date": "2026-11-28T15:33:47.462000Z"
}
308 changes: 308 additions & 0 deletions crates/devup-mcp-devup-ui/src/ui_validate/motion_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
//! Motion shapes a request fixes, proven from the source.
//!
//! The request itself is not visible here, so a sequential entrance is read
//! from the marker the implementation carries for it:
//! `data-reveal-sequence="sequential"` on the group (or `<RevealGroup
//! sequence="sequential">`, or a selector keyed on that attribute). Inside such
//! a group each unit must finish before the next starts.
//!
//! - `sequence-overlaps`: an item of a sequential group waits less per index
//! than its own animation lasts (`animationDelay: calc(var(--i) * 60ms)`
//! with `animationDuration: 400ms`, or `delay: i * 0.06` with
//! `duration: 0.4`), so items overlap where the request asked for one after
//! another. The short-stagger bound (`stagger-too-long`) does not apply
//! inside such a group: a step as long as the item is what it asks for.
//! - `sequence-animates-container`: the sequential group itself carries the
//! entrance, so every item moves at once with its parent.
//! - `disclosure-collapsed-focusable`: a panel collapsed by height
//! (`h`/`maxH`/`gridTemplateRows` switched to `0`) keeps focusable content
//! with nothing (`inert`, `hidden`, `visibility`, `display`) taking it out
//! of the tab order, so keyboard focus lands inside a closed panel.
//! - `disclosure-fixed-max-height`: the panel opens to a fixed `maxHeight`
//! rather than its content height, so the timing is wrong for short content
//! and long content is cut off.
//! - `disclosure-unmounts-form` (info): a panel with form fields renders only
//! while open (`open && <…><input/></…>`), so collapsing it discards what
//! was typed.
//!
//! The same pass records the first animation that repeats forever (an
//! emphasis loop): reduced motion must stop it as it stops an entrance.
use super::keyframes::{Bag, Declared};
use super::{Severity, Violation, attribute, expression, property, site, string};
use oxc_ast::ast::*;
use oxc_ast_visit::{Visit, walk};
use oxc_span::Span;

const HEIGHT_PROPS: &[&str] = &["h", "height", "maxH", "maxHeight", "gridTemplateRows"];
/// Present at all, these take content out of the tab order.
const HIDING_PROPS: &[&str] = &["inert", "hidden"];
/// These do when they switch with the state (`visibility={open ? … : 'hidden'}`).
const SWITCHED_PROPS: &[&str] = &["visibility", "display"];
const SEQUENTIAL_SELECTORS: &[&str] = &["data-reveal-sequence=\"sequential\"", "data-reveal-sequence='sequential'"];

#[derive(Default)]
pub(super) struct Contract {
pub findings: Vec<Violation>,
/// Source ranges of sequential groups: a long stagger there is asked for.
pub sequential: Vec<Span>,
pub first_repeat: Option<Span>,
}

impl Contract {
pub(super) fn in_sequence(&self, span: Span) -> bool {
self.sequential.iter().any(|group| group.start <= span.start && span.end <= group.end)
}
}

pub(super) fn collect(program: &Program<'_>, source: &str, declared: &Declared) -> Contract {
let mut visitor = Visitor { source, declared, contract: Contract::default(), depth: 0 };
visitor.visit_program(program);
visitor.contract
}

struct Visitor<'s, 'd> {
source: &'s str,
declared: &'d Declared,
contract: Contract,
/// Depth inside sequential groups.
depth: usize,
}

fn marks_sequence(node: &JSXOpeningElement<'_>) -> bool {
let named = |name: &str| attribute(node, name).and_then(string) == Some("sequential");
named("data-reveal-sequence")
|| (named("sequence") && node.name.get_identifier_name().is_some_and(|name| name.ends_with("Group")))
}

fn zero_like(expression: &Expression<'_>) -> bool {
match expression.get_inner_expression() {
Expression::NumericLiteral(number) => number.value == 0.0,
Expression::StringLiteral(text) => matches!(text.value.trim(), "0" | "0px" | "0fr" | "0%" | "0rem"),
_ => false,
}
}

/// A fixed length: `600`, `'1000px'`, `'40rem'`, `'100vh'`.
fn fixed_length(expression: &Expression<'_>) -> bool {
match expression.get_inner_expression() {
Expression::NumericLiteral(number) => number.value > 0.0,
Expression::StringLiteral(text) => {
let text = text.value.trim();
["px", "rem", "em", "vh"].iter().any(|unit| {
text.strip_suffix(unit).is_some_and(|number| number.parse::<f64>().is_ok_and(|value| value > 0.0))
})
}
_ => false,
}
}

/// `delay: i * 0.06` (either order): the per-item step, in seconds.
fn framer_step(object: &ObjectExpression<'_>) -> Option<(Span, f64)> {
let delay = object.properties.iter().find_map(|item| match item {
ObjectPropertyKind::ObjectProperty(entry) if entry.key.static_name().is_some_and(|key| key == "delay") => Some(&**entry),
_ => None,
})?;
let Expression::BinaryExpression(binary) = delay.value.get_inner_expression() else {
return None;
};
if binary.operator != BinaryOperator::Multiplication {
return None;
}
match (binary.left.get_inner_expression(), binary.right.get_inner_expression()) {
(Expression::NumericLiteral(number), other) | (other, Expression::NumericLiteral(number))
if !matches!(other, Expression::NumericLiteral(_)) =>
{
Some((delay.span, number.value))
}
_ => None,
}
}

/// What a subtree holds that matters to a collapsed panel.
#[derive(Default)]
struct Holds {
focusable: bool,
field: bool,
}

impl<'a> Visit<'a> for Holds {
fn visit_jsx_opening_element(&mut self, node: &JSXOpeningElement<'a>) {
let name = node.name.get_identifier_name().map(|name| name.to_string()).unwrap_or_default();
let field = matches!(name.as_str(), "input" | "textarea" | "select")
|| ["Input", "Textarea", "TextArea", "Select", "Field", "Checkbox", "Radio"].iter().any(|part| name.contains(part));
let control = matches!(name.as_str(), "button" | "summary")
|| ["Button", "Link", "Switch"].iter().any(|part| name.contains(part))
|| attribute(node, "href").is_some()
|| attribute(node, "tabIndex").is_some_and(|tab| string(tab) != Some("-1") && !expression(tab).is_some_and(|value| matches!(value, Expression::UnaryExpression(_))));
self.field |= field;
self.focusable |= field || control;
walk::walk_jsx_opening_element(self, node);
}
}

fn holds(children: &oxc_allocator::Vec<'_, JSXChild<'_>>) -> Holds {
let mut found = Holds::default();
for child in children {
found.visit_jsx_child(child);
}
found
}

/// Whether the element, or its only element child, takes the collapsed
/// content out of the tab order.
fn hides_collapsed(element: &JSXElement<'_>) -> bool {
let own = |node: &JSXOpeningElement<'_>| {
HIDING_PROPS.iter().any(|name| attribute(node, name).is_some())
|| SWITCHED_PROPS.iter().any(|name| matches!(attribute(node, name).and_then(expression), Some(Expression::ConditionalExpression(_))))
|| node.attributes.iter().any(|item| matches!(item, JSXAttributeItem::SpreadAttribute(_)))
};
if own(&element.opening_element) {
return true;
}
let mut children = element.children.iter().filter_map(|child| match child {
JSXChild::Element(inner) => Some(inner),
_ => None,
});
matches!((children.next(), children.next()), (Some(only), None) if own(&only.opening_element))
}

/// A condition named as a disclosure state: `open`, `isOpen`, `expanded`…
fn disclosure_condition(expression: &Expression<'_>) -> bool {
let name = match expression.get_inner_expression() {
Expression::Identifier(name) => name.name.as_str(),
Expression::StaticMemberExpression(member) => member.property.name.as_str(),
_ => return false,
}
.to_ascii_lowercase();
name.ends_with("open") || name.ends_with("expanded") || matches!(name.as_str(), "show" | "shown" | "isshown")
}

fn overlay(element: &JSXElement<'_>) -> bool {
element.opening_element.name.get_identifier_name().is_some_and(|name| {
["Modal", "Dialog", "Drawer", "Sheet", "Toast", "Tooltip"].iter().any(|part| name.contains(part)) || name == "dialog"
})
}

impl Visitor<'_, '_> {
fn report(&mut self, span: Span, rule: &'static str, severity: Severity, message: String, help: &'static str) {
self.contract.findings.push(site::violation(self.source, span, rule, severity, message, help));
}

fn overlaps(&mut self, span: Span, step: f64, duration: f64) {
if self.depth == 0 || step + 1e-9 >= duration {
return;
}
self.report(span, "sequence-overlaps", Severity::Warning,
format!("This sequential group starts each item {}ms after the previous one, while each item animates for {}ms, so items overlap.", (step * 1000.0).round(), (duration * 1000.0).round()),
"For a sequential entrance, start each unit when the previous one has finished: make the per-index delay at least the item's duration (for example calc(var(--reveal-index) * (400ms + var(--reveal-gap, 0ms)))), and shorten duration or gap if the whole sequence runs long. Overlap only when the request explicitly asks for it, and then drop the sequential marker.");
}

fn check_bag(&mut self, bag: &Bag<'_, '_>) {
if let Some(span) = bag.loop_span(self.declared) {
self.contract.first_repeat.get_or_insert(span);
}
if let (Some((span, step)), Some(duration)) = (bag.stagger_step(), bag.duration_seconds()) {
self.overlaps(span, step, duration);
}
}

fn check_disclosure(&mut self, element: &JSXElement<'_>) {
let node = &element.opening_element;
for name in HEIGHT_PROPS {
let Some(found) = attribute(node, name) else { continue };
let Some(Expression::ConditionalExpression(conditional)) = expression(found) else { continue };
let open = match (zero_like(&conditional.consequent), zero_like(&conditional.alternate)) {
(true, false) => &conditional.alternate,
(false, true) => &conditional.consequent,
_ => continue,
};
if name.starts_with("max") && fixed_length(open) {
self.report(found.span, "disclosure-fixed-max-height", Severity::Warning,
"This panel opens to a fixed max-height, not to its content height.".into(),
"Animate to the content's own height: gridTemplateRows from 0fr to 1fr with an inner overflow-hidden wrapper, height: auto with interpolate-size/calc-size, or the measured scrollHeight. Then short content is not timed for a tall box, long content is not cut off, and the elements below move with the real height.");
}
if !hides_collapsed(element) && holds(&element.children).focusable {
self.report(found.span, "disclosure-collapsed-focusable", Severity::Warning,
"This panel collapses to zero height but its links, buttons or fields stay in the tab order.".into(),
"Take the collapsed content out of the tab order: inert={!open} (or visibility hidden after the close transition ends, or hidden once closed). Keep the panel mounted so form values survive closing and reopening.");
}
return;
}
}
}

impl<'a> Visit<'a> for Visitor<'_, '_> {
fn visit_jsx_element(&mut self, node: &JSXElement<'a>) {
let sequence = marks_sequence(&node.opening_element);
if sequence {
self.contract.sequential.push(node.span);
let own = Bag::of_element(&node.opening_element);
let library = ["whileInView", "initial", "animate"].iter().find_map(|name| attribute(&node.opening_element, name)).map(|attribute| attribute.span);
let container = library.or_else(|| (own.declares_animation() && !own.loops()).then_some(node.opening_element.span));
if let Some(span) = container {
self.report(span, "sequence-animates-container", Severity::Warning,
"The sequential group itself carries the entrance, so all of its items move together with it.".into(),
"Leave the group still and animate each unit (card, row, step or section the request names) on its own, one after another. Animate the whole container only when the request asks for the group to enter as one.");
}
}
self.check_disclosure(node);
self.depth += usize::from(sequence);
walk::walk_jsx_element(self, node);
self.depth -= usize::from(sequence);
}

fn visit_jsx_opening_element(&mut self, node: &JSXOpeningElement<'a>) {
let bag = Bag::of_element(node);
self.check_bag(&bag);
// A motion library loop: `transition={{ repeat: Infinity }}`, unless
// all it animates is a rotation (a spinner).
let repeats = attribute(node, "transition").and_then(expression).is_some_and(|transition| {
matches!(transition, Expression::ObjectExpression(object) if matches!(property(object, "repeat"), Some(Expression::Identifier(name)) if name.name == "Infinity"))
});
let spins = attribute(node, "animate").and_then(expression).is_some_and(|animate| {
matches!(animate, Expression::ObjectExpression(object) if object.properties.len() == 1 && property(object, "rotate").is_some())
});
if repeats && !spins {
self.contract.first_repeat.get_or_insert(node.span);
}
walk::walk_jsx_opening_element(self, node);
}

fn visit_object_expression(&mut self, node: &ObjectExpression<'a>) {
self.check_bag(&Bag::of_object(node));
if let Some((span, step)) = framer_step(node)
&& let Some(Expression::NumericLiteral(duration)) = property(node, "duration")
{
self.overlaps(span, step, duration.value);
}
walk::walk_object_expression(self, node);
}

fn visit_object_property(&mut self, node: &ObjectProperty<'a>) {
let sequence = node.key.static_name().is_some_and(|key| SEQUENTIAL_SELECTORS.iter().any(|marker| key.contains(marker)));
if sequence {
self.contract.sequential.push(node.span);
}
self.depth += usize::from(sequence);
walk::walk_object_property(self, node);
self.depth -= usize::from(sequence);
}

fn visit_logical_expression(&mut self, node: &LogicalExpression<'a>) {
if node.operator == LogicalOperator::And
&& disclosure_condition(&node.left)
&& let Expression::JSXElement(element) = node.right.get_inner_expression()
&& !overlay(element)
&& holds(&element.children).field
{
self.report(node.span, "disclosure-unmounts-form", Severity::Info,
"This panel's form fields are rendered only while it is open, so closing it discards what was typed.".into(),
"For a dropdown or accordion that holds a form, keep the panel mounted and collapse it (height to 0 with inert while closed) so values survive closing and reopening. Leave it when the reset is intended.");
}
walk::walk_logical_expression(self, node);
}
}

#[cfg(test)]
#[path = "motion_contract_tests.rs"]
mod tests;
Loading
Loading