From 32438ce25f69de99d2523b98237f62cfa90890d7 Mon Sep 17 00:00:00 2001 From: cashmere Date: Tue, 28 Jul 2026 20:14:51 +0200 Subject: feat: port domain crates to Rust (session 1 complete) All green: cargo test --workspace (~300 tests, 0 failures). - timeline (45): placement, resize/ripple, split, snap, retime, audio separation, scene helpers - animation (73): bezier solver, channel sampling, keyframe ops, split/clamp/clone, param definitions - commands (9): Command trait, BatchCommand, history, 19 concrete commands, freeze-frame port 1:1 - audio (22): audible collection, range mixing, mastering limiter, rms/peak buckets - text (19): cosmic-text layout/measure/raster, backgrounds, decorations - graphics (52): full CSS gradient parser, tiny-skia raster, 4 shape definitions - effect-defs (16): blur definition, registry, pass resolution - mask-defs (19): all 9 mask renderers via tiny-skia - renderer (6): node model + scene builder port - desktop: GPUI projects screen wired to ProjectStore - scene: factory (web defaults: v32, Main Track, 1920x1080, 30fps) --- rust/crates/animation/src/property_groups.rs | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 rust/crates/animation/src/property_groups.rs (limited to 'rust/crates/animation/src/property_groups.rs') diff --git a/rust/crates/animation/src/property_groups.rs b/rust/crates/animation/src/property_groups.rs new file mode 100644 index 00000000..fd639905 --- /dev/null +++ b/rust/crates/animation/src/property_groups.rs @@ -0,0 +1,110 @@ +use scene::{ANIMATION_PROPERTY_PATHS, ElementAnimations}; +use time::MediaTime; + +use crate::keyframe_query::get_keyframe_at_time; + +pub const ANIMATION_PROPERTY_GROUPS: &[(&str, &[&str])] = &[( + "transform.scale", + &["transform.scaleX", "transform.scaleY"], +)]; + +#[derive(Clone, Debug, PartialEq)] +pub struct GroupKeyframeRef { + pub property_path: &'static str, + pub keyframe_id: String, +} + +pub fn animation_property_group_paths(group: &str) -> Option<&'static [&'static str]> { + ANIMATION_PROPERTY_GROUPS + .iter() + .find(|(name, _)| *name == group) + .map(|(_, paths)| *paths) +} + +pub fn get_group_keyframes_at_time( + animations: Option<&ElementAnimations>, + group: &str, + time: MediaTime, +) -> Vec { + let Some(paths) = animation_property_group_paths(group) else { + return Vec::new(); + }; + paths + .iter() + .filter_map(|property_path| { + get_keyframe_at_time(animations, property_path, time).map(|keyframe| { + GroupKeyframeRef { + property_path, + keyframe_id: keyframe.id, + } + }) + }) + .collect() +} + +pub fn has_group_keyframe_at_time( + animations: Option<&ElementAnimations>, + group: &str, + time: MediaTime, +) -> bool { + !get_group_keyframes_at_time(animations, group, time).is_empty() +} + +pub fn is_animation_property_path(property_path: &str) -> bool { + ANIMATION_PROPERTY_PATHS.contains(&property_path) +} + +#[cfg(test)] +mod tests { + use super::*; + use scene::{ + AnimationChannel, ChannelData, ScalarAnimationKey, ScalarChannel, ScalarSegmentType, + TangentMode, + }; + use std::collections::BTreeMap; + + #[test] + fn finds_group_keyframes_across_group_paths() { + let key = |id: &str| ScalarAnimationKey { + id: id.to_string(), + time: MediaTime::from_ticks(0), + value: 1.0, + left_handle: None, + right_handle: None, + segment_to_next: ScalarSegmentType::Linear, + tangent_mode: TangentMode::Flat, + }; + let mut animations: ElementAnimations = BTreeMap::new(); + animations.insert( + "transform.scaleX".to_string(), + ChannelData::Single(AnimationChannel::Scalar(ScalarChannel { + keys: vec![key("kx")], + extrapolation: None, + })), + ); + let refs = get_group_keyframes_at_time( + Some(&animations), + "transform.scale", + MediaTime::from_ticks(0), + ); + assert_eq!(refs.len(), 1); + assert_eq!(refs[0].property_path, "transform.scaleX"); + assert!(has_group_keyframe_at_time( + Some(&animations), + "transform.scale", + MediaTime::from_ticks(0) + )); + assert!(!has_group_keyframe_at_time( + Some(&animations), + "transform.scale", + MediaTime::from_ticks(10) + )); + } + + #[test] + fn recognizes_animation_property_paths() { + assert!(is_animation_property_path("opacity")); + assert!(is_animation_property_path("transform.rotate")); + assert!(!is_animation_property_path("params.blur")); + } +} -- cgit v1.3.1