Skip to main content

ashlar_motion/
lib.rs

1//! Headless motion maths for ashlar: closed-form springs, curves, animated values that keep their
2//! velocity when retargeted, a reduced-motion policy per kind of value, OKLab/OKLCH colour and
3//! gesture helpers.
4//!
5//! No UI, no dependencies, no allocation; builds for `wasm32-unknown-unknown`. The UI layer
6//! (`ashlar-ui`) owns the clock and the frame requests; this crate only answers "where is this
7//! value at time t, and when does it stop?".
8//!
9//! ```
10//! use ashlar_motion::{Animated, Class, Curve, MotionPrefs, Spring};
11//!
12//! let prefs = MotionPrefs::DEFAULT;
13//! let mut x = Animated::new(0.0_f32, Class::Spatial);
14//! x.animate_to(100.0, Spring::new(0.3, 0.1).into(), 0.0, &prefs);
15//! let mid = x.sample(0.1);
16//! assert!(mid > 0.0 && mid < 110.0);
17//! // retarget mid-flight: starts from where it is, at the speed it has
18//! x.animate_to(-50.0, Curve::DEFAULT, 0.1, &prefs);
19//! assert_eq!(x.sample(0.1), mid);
20//! // settled values are exactly their target, and stop asking for frames
21//! assert_eq!(x.sample(x.settle_at()), -50.0);
22//! assert!(x.is_settled(x.settle_at()));
23//! ```
24
25mod animated;
26mod class;
27pub mod color;
28mod curve;
29mod easing;
30pub mod gesture;
31mod lanes;
32mod spring;
33pub mod tokens;
34
35pub use animated::{Animated, DEFAULT_PIXELS_PER_POINT};
36pub use class::{Class, Eps, MotionPrefs};
37pub use curve::Curve;
38pub use easing::Easing;
39pub use lanes::{Animatable, Edges, Lanes, MAX_LANES};
40pub use spring::{MAX_SETTLE, Spring};
41pub use tokens::Pair;