Module animations
Web Animations (src/page/web_animations.odin): Element.animate, Animation, KeyframeEffect, document.timeline. The browser keeps each animation's state (start time, hold time, playback rate, pending play or pause, play state, replace state) and plays its keyframe effect on the style timeline (src/style/script_anim.odin) like a CSS animation; the engine keeps the JavaScript objects (the KeyframeEffect, the promises) and mirrors what the browser tells it (Animation_takeOps). Times are milliseconds on the document timeline; NaN stands for null (unresolved). "finish", "cancel" and "remove" are fired at the animation (AnimationPlaybackEvent: Event x = currentTime, y = timelineTime, NaN for null).
Exposed to: Window. Source: api/animations.widl.
Odin: import "wren:animations".
Types
handle Animation : Object
Checked by the browser on every call (lookup_Animation).
enum AnimationPlayState : i32
| member | value | |
|---|---|---|
Idle | 0 | |
Running | 1 | |
Paused | 2 | |
Finished | 3 |
enum AnimationReplaceState : i32
| member | value | |
|---|---|---|
Active | 0 | |
Removed | 1 | |
Persisted | 2 |
struct CssAnimationInfo
A CSS animation or transition among Animation_relevant's handles (src/page/web_animations_css.odin).
| field | type | |
|---|---|---|
kind | i32 | 0 not a CSS one (a script's), 1 CSSAnimation, 2 CSSTransition |
target | u64 | |
delay | f64 | |
duration | f64 | |
iterations | f64 |
Functions
Animation_create
Animation Animation_create(MicrotaskCallback notify, i32 user)new Animation(): no effect, on the document timeline. notify(user) runs as a microtask when there is something
to take (Animation_takeOps).
Host: Animation_create :: proc(c: ^Call, notify: u32, user: i32) -> u64
Animation_setEffect
void Animation_setEffect(Animation animation, optional Element target, string keyframes, f64 duration, f64 delay, f64 end_delay, f64 iterations, f64 iteration_start, i32 direction, i32 fill, string easing, i32 composite) raisesSets the animation's keyframe effect: its target (0: none), its keyframes packed by the engine (offsets computed: keyframes separated by U+001E, fields by U+001F: offset, easing, then property / value pairs), its timing (duration NaN: "auto"; direction and fill as the style engine's enums, fill "auto" as none) and composite operation (0 replace, 1 add, 2 accumulate). Type when an easing does not parse.
Raises: returns an Error (see web).
Host: Animation_setEffect :: proc(c: ^Call, animation: Api_Animation, target: Api_Element, keyframes: string, duration: f64, delay: f64, end_delay: f64, iterations: f64, iteration_start: f64, direction: i32, fill: i32, easing: string, composite: i32) -> Api_Error
Animation_clearEffect
void Animation_clearEffect(Animation animation)animation.effect = null
Host: Animation_clearEffect :: proc(c: ^Call, animation: Api_Animation)
Animation_setTimeline
void Animation_setTimeline(Animation animation, bool document_timeline)animation.timeline = document.timeline (true) or null (false).
Host: Animation_setTimeline :: proc(c: ^Call, animation: Api_Animation, document_timeline: bool)
Animation_play
void Animation_play(Animation animation) raisesplay(): Invalid_State to play backwards an effect that never ends.
Raises: returns an Error (see web).
Host: Animation_play :: proc(c: ^Call, animation: Api_Animation) -> Api_Error
Animation_pause
void Animation_pause(Animation animation) raisespause(): Invalid_State to pause before the start of an effect that never ends, backwards.
Raises: returns an Error (see web).
Host: Animation_pause :: proc(c: ^Call, animation: Api_Animation) -> Api_Error
Animation_finish
void Animation_finish(Animation animation) raisesfinish(): Invalid_State at a playback rate of 0, or forwards with an effect that never ends.
Raises: returns an Error (see web).
Host: Animation_finish :: proc(c: ^Call, animation: Api_Animation) -> Api_Error
Animation_cancel
void Animation_cancel(Animation animation)cancel()
Host: Animation_cancel :: proc(c: ^Call, animation: Api_Animation)
Animation_reverse
void Animation_reverse(Animation animation) raisesreverse(): Invalid_State without a timeline, or as play().
Raises: returns an Error (see web).
Host: Animation_reverse :: proc(c: ^Call, animation: Api_Animation) -> Api_Error
Animation_persist
void Animation_persist(Animation animation)persist()
Host: Animation_persist :: proc(c: ^Call, animation: Api_Animation)
Animation_commitStyles
void Animation_commitStyles(Animation animation) raisescommitStyles(): the effect's animated values written into the target's style attribute. No_Modification_Allowed without a target element, Invalid_State when it is not rendered.
Raises: returns an Error (see web).
Host: Animation_commitStyles :: proc(c: ^Call, animation: Api_Animation) -> Api_Error
Animation_updatePlaybackRate
void Animation_updatePlaybackRate(Animation animation, f64 rate)updatePlaybackRate(rate)
Host: Animation_updatePlaybackRate :: proc(c: ^Call, animation: Api_Animation, rate: f64)
Animation_playbackRate
f64 Animation_playbackRate(Animation animation)animation.playbackRate
Host: Animation_playbackRate :: proc(c: ^Call, animation: Api_Animation) -> f64
Animation_set_playbackRate
void Animation_set_playbackRate(Animation animation, f64 rate)animation.playbackRate = rate (the current time is kept)
Host: Animation_set_playbackRate :: proc(c: ^Call, animation: Api_Animation, rate: f64)
Animation_currentTime
f64 Animation_currentTime(Animation animation)animation.currentTime (NaN: null)
Host: Animation_currentTime :: proc(c: ^Call, animation: Api_Animation) -> f64
Animation_set_currentTime
void Animation_set_currentTime(Animation animation, f64 time) raisesanimation.currentTime = t: Type for null when the current time is resolved.
Raises: returns an Error (see web).
Host: Animation_set_currentTime :: proc(c: ^Call, animation: Api_Animation, time: f64) -> Api_Error
Animation_startTime
f64 Animation_startTime(Animation animation)animation.startTime (NaN: null)
Host: Animation_startTime :: proc(c: ^Call, animation: Api_Animation) -> f64
Animation_set_startTime
void Animation_set_startTime(Animation animation, f64 time)animation.startTime = t (NaN: null)
Host: Animation_set_startTime :: proc(c: ^Call, animation: Api_Animation, time: f64)
Animation_playState
AnimationPlayState Animation_playState(Animation animation)animation.playState
Host: Animation_playState :: proc(c: ^Call, animation: Api_Animation) -> Api_AnimationPlayState
Animation_replaceState
AnimationReplaceState Animation_replaceState(Animation animation)animation.replaceState
Host: Animation_replaceState :: proc(c: ^Call, animation: Api_Animation) -> Api_AnimationReplaceState
Animation_pending
bool Animation_pending(Animation animation)animation.pending
Host: Animation_pending :: proc(c: ^Call, animation: Api_Animation) -> bool
Animation_takeOps
string Animation_takeOps(Animation animation)What changed for the engine since the last call, one letter each, in order: r the ready promise is resolved, R it is rejected (AbortError) and replaced by a resolved one, n a new pending ready promise; f the finished promise is resolved, F it is rejected (AbortError) and replaced by a pending one, m a new pending finished promise; k / u the wrapper must be kept alive (the animation may still fire events or show its effect) / may go. Nothing is taken away: Animation_dropOps does once the engine applied them.
Host: Animation_takeOps :: proc(c: ^Call, animation: Api_Animation) -> string
Animation_dropOps
void Animation_dropOps(Animation animation, i32 count)The first count letters of Animation_takeOps were applied.
Host: Animation_dropOps :: proc(c: ^Call, animation: Api_Animation, count: i32)
AnimationPlaybackEvent_time
f64 AnimationPlaybackEvent_time(Event event, i32 which)AnimationPlaybackEvent of the browser: which 0 currentTime, 1 timelineTime (NaN: null).
Host: AnimationPlaybackEvent_time :: proc(c: ^Call, event: Api_Event, which: i32) -> f64
Animation_computedTiming
f64 Animation_computedTiming(Animation animation, i32 which)effect.getComputedTiming() of the animation's effect: which 0 localTime, 1 progress, 2 currentIteration; NaN: null.
Host: Animation_computedTiming :: proc(c: ^Call, animation: Api_Animation, which: i32) -> f64
Animation_relevant
bytes Animation_relevant(optional Node root, bool subtree)The relevant animations (Web Animations 1 §5.7) of root (with subtree: of it and its descendants), or of the
whole document when root is 0, in composite order: 8 bytes per handle.
Host: Animation_relevant :: proc(c: ^Call, root: Api_Node, subtree: bool) -> []u8
Animation_cssBind
CssAnimationInfo Animation_cssBind(Animation animation, MicrotaskCallback notify, i32 user)What a CSS animation or transition is, for its wrapper; notify(user) then runs as for Animation_create.
Host: Animation_cssBind :: proc(c: ^Call, animation: Api_Animation, notify: u32, user: i32) -> Api_CssAnimationInfo
Animation_cssName
string Animation_cssName(Animation animation)CSSAnimation.animationName / CSSTransition.transitionProperty ("" once it is gone).
Host: Animation_cssName :: proc(c: ^Call, animation: Api_Animation) -> string
DocumentTimeline_currentTime
f64 DocumentTimeline_currentTime()document.timeline.currentTime (NaN: null)
Host: DocumentTimeline_currentTime :: proc(c: ^Call) -> f64
Animation_validEasing
bool Animation_validEasing(string easing)Whether easing is an easing function (CSS Easing 2).
Host: Animation_validEasing :: proc(c: ^Call, easing: string) -> bool