Skip to content

Imperative Timeline

The Timeline class lets you build animation sequences imperatively instead of with JSX. This is useful for dynamic or data-driven animations where the structure isn’t known at author time.

const tl = new Timeline(fps);
ParameterTypeDescription
fpsnumberFrames per second for the timeline
MethodSignatureDescription
playplay(type, id, opts?)Add an animation and advance the cursor past it
addadd(type, id, opts?)Add an animation at the current cursor without advancing
waitwait(seconds)Insert a pause (in seconds) at the current cursor
compilecompile()Returns { actions, totalFrames }
  • play — appends an animation sequentially. The cursor moves forward by its duration, so the next call starts after it finishes.
  • add — layers an animation at the current cursor position (parallel). The cursor does not move.
  • wait — advances the cursor by the given number of seconds (converted to frames using the timeline’s fps).
  • compile — finalizes the timeline and returns the list of actions with their computed start frames, plus the total frame count.
import { Player, useCurrentFrame, interpolate, Circle } from '@elucim/core';
function AnimatedCircle() {
const frame = useCurrentFrame();
const x = interpolate(frame, [0, 60], [100, 400], { easing: 'easeInOutCubic' });
return <Circle cx={x} cy={125} r={30} fill="#6c5ce7" />;
}
<Player width={500} height={250} fps={30} durationInFrames={90}>
<AnimatedCircle />
</Player>
import { Timeline } from 'elucim';
const tl = new Timeline(30);
tl.play('fadeIn', 'title', { duration: 30 });
tl.wait(0.5);
tl.play('draw', 'axis', { duration: 45 });
tl.add('fadeIn', 'label-x', { duration: 20 });
tl.add('fadeIn', 'label-y', { duration: 20 });
tl.wait(1);
tl.play('fadeOut', 'title', { duration: 30 });
const { actions, totalFrames } = tl.compile();
// actions: ordered list with { type, id, startFrame, opts }
// totalFrames: total length of the compiled timeline

In this example, label-x and label-y fade in concurrently (both added with add), while the rest of the sequence plays one step at a time.