animato/lib.rs
1//! # Animato
2//!
3//! > *Italian: animato — animated, lively, with life and movement.*
4//!
5//! A professional-grade, renderer-agnostic animation library for Rust.
6//! Zero mandatory dependencies. `no_std`-ready.
7//!
8//! Works everywhere: TUIs, Web (WASM), Bevy games, embedded targets, and native apps.
9//!
10//! ## Quick Start
11//!
12//! ```rust,ignore
13//! use animato::{Tween, Easing, Update};
14//!
15//! let mut tween = Tween::new(0.0_f32, 100.0)
16//! .duration(1.0)
17//! .easing(Easing::EaseOutCubic)
18//! .build();
19//!
20//! tween.update(1.0);
21//! assert_eq!(tween.value(), 100.0);
22//! assert!(tween.is_complete());
23//! ```
24//!
25//! ## Spring Physics
26//!
27//! ```rust,ignore
28//! use animato::{Spring, SpringConfig, Update};
29//!
30//! let mut spring = Spring::new(SpringConfig::wobbly());
31//! spring.set_target(200.0);
32//!
33//! while !spring.is_settled() {
34//! spring.update(1.0 / 60.0);
35//! }
36//! assert!((spring.position() - 200.0).abs() < 0.01);
37//! ```
38//!
39//! ## Input Physics
40//!
41//! ```rust,ignore
42//! use animato::{Inertia, InertiaConfig, Update};
43//!
44//! let mut inertia = Inertia::new(InertiaConfig::smooth());
45//! inertia.kick(800.0);
46//! while inertia.update(1.0 / 60.0) {}
47//! ```
48//!
49//! ## AnimationDriver
50//!
51//! ```rust,ignore
52//! use animato::{Tween, Easing, AnimationDriver, WallClock, Clock};
53//!
54//! let mut driver = AnimationDriver::new();
55//! let id = driver.add(
56//! Tween::new(0.0_f32, 1.0).duration(2.0).easing(Easing::EaseInOutSine).build()
57//! );
58//!
59//! let mut clock = WallClock::new();
60//! // In your loop: driver.tick(clock.delta());
61//! ```
62//!
63//! ## `no_std` Usage
64//!
65//! For `no_std` targets, depend on the sub-crates directly:
66//!
67//! ```toml
68//! [dependencies]
69//! animato-core = { version = "1.5", default-features = false }
70//! animato-tween = { version = "1.5", default-features = false }
71//! animato-spring = { version = "1.5", default-features = false }
72//! animato-physics = { version = "1.5", default-features = false }
73//! animato-color = { version = "1.5", default-features = false }
74//! ```
75//!
76//! ## Feature Flags
77//!
78//! | Feature | What it adds |
79//! |---------|-------------|
80//! | `default` | `std` + `tween` + `timeline` + `spring` + `driver` |
81//! | `std` | Wall clock, heap-backed types |
82//! | `tween` | [`Tween<T>`], [`KeyframeTrack<T>`], [`Loop`] |
83//! | `timeline` | [`Timeline`], [`Sequence`], [`stagger()`] |
84//! | `spring` | [`Spring`], [`SpringConfig`], [`SpringN<T>`] |
85//! | `path` | [`MotionPath`], [`MotionPathTween`], [`SvgPathParser`] |
86//! | `physics` | [`Inertia`], [`DragState`], [`GestureRecognizer`] |
87//! | `color` | [`InLab<T>`], [`InOklch<T>`], [`InLinear<T>`] |
88//! | `driver` | [`AnimationDriver`], all [`Clock`] variants |
89//! | `gpu` | [`GpuAnimationBatch`] for high-volume `Tween<f32>` batches |
90//! | `bevy` | [`AnimatoPlugin`], Bevy tween/spring wrapper components |
91//! | `wasm` | [`RafDriver`] for `requestAnimationFrame` loops |
92//! | `leptos` | Signal-backed Leptos hooks and components |
93//! | `dioxus` | Dioxus signal hooks, motion, presence, gestures, and native helpers |
94//! | `yew` | Yew hooks, CSS helpers, scroll, presence, FLIP lists, gestures, and agents |
95//! | `js` | WASM-to-NPM JavaScript bindings |
96//! | `tokio` | [`Timeline::wait()`] async completion waiting |
97//! | `serde` | `Serialize`/`Deserialize` on all public types |
98
99// ── Core — always present ────────────────────────────────────────────────────
100pub use animato_core::{
101 Angle, Animatable, Color, Easing, Interpolate, Mat4, Playable, Quaternion, Update,
102};
103
104// ── Serde convenience re-export ─────────────────────────────────────────────
105#[cfg(feature = "serde")]
106pub use serde::{Deserialize, Serialize};
107
108/// All free easing functions (`ease_out_cubic`, `cubic_bezier`, etc.) re-exported at crate root.
109///
110/// These are `#[inline]` free functions — use them when you want zero-overhead
111/// easing without the `Easing` enum indirection.
112pub mod easing {
113 pub use animato_core::easing::*;
114}
115
116// ── Tween ────────────────────────────────────────────────────────────────────
117#[cfg(feature = "tween")]
118pub use animato_tween::{
119 GridOrigin, Keyframe, KeyframeTrack, Loop, StaggerPattern, Tween, TweenBuilder, TweenSnapshot,
120 TweenState, Waveform, round_to, snap_to,
121};
122
123// ── Timeline ────────────────────────────────────────────────────────────────
124#[cfg(feature = "timeline")]
125pub use animato_timeline::{AnimationGroup, At, Sequence, Timeline, TimelineState, stagger};
126
127// ── Spring ───────────────────────────────────────────────────────────────────
128#[cfg(feature = "spring")]
129pub use animato_spring::{Integrator, Spring, SpringConfig};
130
131#[cfg(feature = "spring")]
132pub use animato_spring::SpringN;
133
134// ── Path ─────────────────────────────────────────────────────────────────────
135#[cfg(feature = "path")]
136pub use animato_path::{
137 CatmullRomSpline, CompoundPath, CubicBezierCurve, DrawSvg, DrawValues, EllipticalArc,
138 LineSegment, MorphPath, MotionPath, MotionPathTween, MotionPathTweenBuilder, PathCommand,
139 PathEvaluate, PathSegment, PolyPath, QuadBezier, SvgPathError, SvgPathParser, resample,
140};
141
142// ── Physics ─────────────────────────────────────────────────────────────────
143#[cfg(feature = "physics")]
144pub use animato_physics::{
145 DragAxis, DragConstraints, DragState, Gesture, GestureConfig, GestureRecognizer, Inertia,
146 InertiaBounds, InertiaConfig, InertiaN, PointerData, SwipeDirection,
147};
148
149// ── Color ───────────────────────────────────────────────────────────────────
150#[cfg(feature = "color")]
151pub use animato_color::{InLab, InLinear, InOklch};
152#[cfg(feature = "color")]
153pub use palette;
154
155// ── Driver ───────────────────────────────────────────────────────────────────
156#[cfg(feature = "driver")]
157pub use animato_driver::{
158 AnimationDriver, AnimationId, Clock, ManualClock, MockClock, ScrollClock, ScrollDriver,
159 WallClock,
160};
161
162#[cfg(all(feature = "driver", feature = "std"))]
163pub use animato_driver::{AnimationRecorder, RecordedSample, RecordedTrack, RecorderError};
164
165// ── GPU ──────────────────────────────────────────────────────────────────────
166#[cfg(feature = "gpu")]
167pub use animato_gpu::{GpuAnimationBatch, GpuBackend, GpuBatchError};
168
169// ── Bevy ─────────────────────────────────────────────────────────────────────
170#[cfg(feature = "bevy")]
171pub use animato_bevy::{
172 AnimationChannel, AnimationLabel, AnimatoPlugin, AnimatoSet, AnimatoSpring,
173 AnimatoSpringPlugin, AnimatoTween, AnimatoTweenPlugin, SpringSettled, TweenCompleted,
174};
175
176// ── WASM ─────────────────────────────────────────────────────────────────────
177#[cfg(feature = "wasm")]
178pub use animato_wasm::{RafDriver, ScrollSmoother};
179
180#[cfg(all(feature = "wasm-dom", target_arch = "wasm32"))]
181pub use animato_wasm::{
182 Draggable, FlipAnimation, FlipState, LayoutAnimator, Observer, ObserverEvent,
183 SharedElementTransition, SplitMode, SplitText,
184};
185
186// ── Leptos ──────────────────────────────────────────────────────────────────
187#[cfg(feature = "leptos")]
188pub mod leptos {
189 //! Leptos integration namespace.
190 pub use animato_leptos::*;
191}
192
193#[cfg(all(feature = "leptos", not(feature = "dioxus")))]
194pub use animato_leptos::*;
195
196#[cfg(feature = "dioxus")]
197pub mod dioxus {
198 //! Dioxus integration namespace.
199 pub use animato_dioxus::*;
200}
201
202#[cfg(all(feature = "dioxus", not(feature = "leptos")))]
203pub use animato_dioxus::*;
204
205// ── Yew ─────────────────────────────────────────────────────────────────────
206#[cfg(feature = "yew")]
207pub mod yew {
208 //! Yew integration namespace.
209 pub use animato_yew::*;
210}
211
212#[cfg(all(feature = "yew", not(feature = "leptos"), not(feature = "dioxus")))]
213pub use animato_yew::*;
214
215// ── JavaScript / NPM ────────────────────────────────────────────────────────
216#[cfg(feature = "js")]
217pub mod js {
218 //! JavaScript/WASM integration namespace.
219 pub use animato_js::*;
220}