Overview#
Implement CSS Animations Level 1: @keyframes rules and animation-* properties.
Requirements#
Parsing#
- Parse
@keyframesrules:- Named keyframes:
@keyframes slidein { from { ... } to { ... } } - Percentage stops:
@keyframes fade { 0% { ... } 50% { ... } 100% { ... } } - Multiple selectors per block:
0%, 100% { ... }
- Named keyframes:
- Parse
animationshorthand and longhand properties:animation-nameanimation-durationanimation-timing-function(same as transition timing functions)animation-delayanimation-iteration-count:<number>orinfiniteanimation-direction:normal,reverse,alternate,alternate-reverseanimation-fill-mode:none,forwards,backwards,bothanimation-play-state:running,paused
Animation Engine#
- Reuse the interpolation engine from CSS Transitions
- Compute current keyframe progress based on elapsed time, iteration count, and direction
- Interpolate between keyframe stops
- Apply fill modes (forwards: keep final state, backwards: apply 0% during delay)
Animation Management#
- Track active animations per element
- Handle animation start/restart when
animation-namechanges - Support pausing and resuming (
animation-play-state) - Fire animation events:
animationstart,animationend,animationiteration - Request animation frame repaints while animations are active
Integration#
- Extend CSS parser in
crates/css/for@keyframesandanimation-* - Store keyframes in stylesheet representation
- Connect animation tick to render loop
Dependencies#
- CSS Transitions (for the interpolation engine and timing functions)
Acceptance Criteria#
-
@keyframesrules parse correctly withfrom/toand percentage stops -
animation: slidein 1s ease-inapplies correctly -
animation-iteration-count: infiniteloops indefinitely -
animation-direction: alternatereverses on each iteration -
animation-fill-mode: forwardsretains final keyframe state - Pausing and resuming works
- Animation events fire at correct times
- All existing tests continue to pass
- New unit tests for keyframe parsing, animation timing, and fill modes