Skip to main content

Overview

The Timeline animation system provides a powerful way to create complex animations in OpenTUI. It supports property animations, easing functions, looping, callbacks, and nested timelines.

Creating a Timeline

createTimeline()

Creates and registers a new timeline with the animation engine.
TimelineOptions
default:"{}"
Configuration options for the timeline
Timeline
A new Timeline instance registered with the animation engine

Timeline Class

add()

Adds an animation to the timeline at a specific start time.
any
required
The object or array of objects to animate. Can be any object with numeric properties.
AnimationOptions
required
Animation properties and options
number | string
default:"0"
When to start the animation in milliseconds from the timeline start
Timeline
Returns the timeline instance for method chaining

once()

Adds a one-time animation that starts at the current timeline position and is automatically removed when complete.
any
required
The object to animate
AnimationOptions
required
Animation properties (same as add() method)
Timeline
Returns the timeline instance for method chaining

call()

Adds a callback function to be executed at a specific time in the timeline.
() => void
required
Function to execute
number | string
default:"0"
When to execute the callback in milliseconds from the timeline start
Timeline
Returns the timeline instance for method chaining

sync()

Synchronizes another timeline to start at a specific time in this timeline.
Timeline
required
The timeline to synchronize
number
default:"0"
When to start the synchronized timeline in milliseconds
Timeline
Returns the timeline instance for method chaining

play()

Starts or resumes playback of the timeline.
Timeline
Returns the timeline instance for method chaining

pause()

Pauses playback of the timeline.
Timeline
Returns the timeline instance for method chaining

restart()

Restarts the timeline from the beginning.
Timeline
Returns the timeline instance for method chaining

update()

Manually updates the timeline by a delta time. This is typically called automatically by the animation engine.
number
required
Time elapsed in milliseconds since last update

Timeline Properties

number
Current playback position in milliseconds
boolean
Whether the timeline is currently playing
boolean
Whether the timeline has completed playback
number
Total duration of the timeline in milliseconds
boolean
Whether the timeline loops

Timeline Engine

The global animation engine manages all timelines and integrates with the renderer.

engine.attach()

Attaches the engine to a CLI renderer to synchronize with frame updates.
CliRenderer
required
The renderer to attach to

engine.register()

Manually registers a timeline with the engine.
Timeline
required
The timeline to register

engine.unregister()

Unregisters a timeline from the engine.
Timeline
required
The timeline to unregister

engine.clear()

Unregisters all timelines from the engine.

JSAnimation Interface

The animation object passed to onUpdate callbacks.
any[]
Array of objects being animated
number
Current progress of the animation (0-1), after easing is applied
number
Current timeline time in milliseconds
number
Time elapsed since last frame in milliseconds

Example: Complex Animation