A singleton holding all your animations, and a timestamp

pub opaque type Animations
pub type RequestedFrame
pub type TimeoutId


pub fn add(
  animations: Animations,
  name: String,
  start: Float,
  stop: Float,
  seconds: Float,
) -> Animations

Add an animation (linear interpolation) from start to stop, for seconds duration. The name should be unique, so the animation can be retrieved and evaluated by value() later. The animation is started when a subsequent command from effect() is returned by your lustre update() function; followed by a call to tick().

pub fn after(
  ms: Float,
  msg_after: fn(TimeoutId) -> a,
  msg_bell: a,
) -> Effect(a)
pub fn cancel(timeout_id: TimeoutId) -> Effect(a)
pub fn effect(
  animations: Animations,
  msg: fn(Float) -> a,
) -> Effect(a)

Returns effect.none() if none of the animations is running. Otherwise returns an opaque Effect that will cause msg(time) to be dispatched on a JavaScript requestAnimationFrame

pub fn new() -> Animations

Create an empty list of animations.

pub fn remove(animations: Animations, name: String) -> Animations

Remove an animation if it should stop before it is finished. If an animation runs to its end normally, you do not have to remove() it manually, will be automatically removed by tick().

pub fn request_animation_frame(msg: fn(Float) -> a) -> Effect(a)
pub fn tick(
  animations: Animations,
  time_offset: Float,
) -> Animations

When called for the first time on an animation, its start time is set to time-Offset. Its stop time then is the start time plus the duration.

When called for the first time for animations that have finished, they will be marked as such in the result. value() will return the stop value that you passed with add()

When called the second time for animations that have finished, they will be absent from the returned value.

pub fn value(
  animations: Animations,
  which: String,
  default: Float,
) -> Float

If the animation specified by which is not found, returns default. Otherwise, the interpolated value for the time passed to tick() is returned.

Search Document