animation

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package animation provides the time model shared by CSS transitions and animations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation interface {
	Advance(time.Time) bool
}

Animation advances one animation to a frame timestamp. It reports whether it remains active after the frame.

type Clock

type Clock interface {
	Now() time.Time
}

Clock supplies the current animation time. Implementations must prefer a monotonic time source; Timeline additionally prevents observed time from moving backwards.

type CubicBezier

type CubicBezier struct {
	X1, Y1, X2, Y2 float64
}

CubicBezier is a CSS cubic-bezier easing function.

func NewCubicBezier

func NewCubicBezier(x1, y1, x2, y2 float64) (CubicBezier, error)

NewCubicBezier creates a curve whose x control points are valid CSS values.

func (CubicBezier) Transform

func (curve CubicBezier) Transform(progress float64, _ bool) float64

type EasingFunction

type EasingFunction interface {
	Transform(progress float64, before bool) float64
}

EasingFunction maps an input progress to an output progress.

type Linear

type Linear struct{}

Linear is the identity easing function.

func (Linear) Transform

func (Linear) Transform(progress float64, _ bool) float64

type Phase

type Phase uint8

Phase identifies where a sample lies relative to an effect's active time.

const (
	PhaseBefore Phase = iota
	PhaseActive
	PhaseAfter
)

type StepPosition

type StepPosition uint8

StepPosition selects where discontinuities occur in a steps() easing.

const (
	JumpStart StepPosition = iota
	JumpEnd
	JumpNone
	JumpBoth
)

type Steps

type Steps struct {
	Count    int
	Position StepPosition
}

Steps is a CSS step easing function.

func NewSteps

func NewSteps(count int, position StepPosition) (Steps, error)

NewSteps validates and creates a step easing function.

func (Steps) Transform

func (steps Steps) Transform(progress float64, before bool) float64

type SystemClock

type SystemClock struct{}

SystemClock supplies the process monotonic wall-clock time for production.

func (SystemClock) Now

func (SystemClock) Now() time.Time

type Timeline

type Timeline struct {
	// contains filtered or unexported fields
}

Timeline advances every registered animation against one shared clock.

func NewTimeline

func NewTimeline(clock Clock, requestFrame func()) *Timeline

NewTimeline creates an empty timeline driven by clock.

func (*Timeline) Active

func (t *Timeline) Active() bool

Active reports whether at least one animation needs another frame.

func (*Timeline) Add

func (t *Timeline) Add(animation Animation)

Add registers an animation for the next frame. Nil animations are ignored.

func (*Timeline) Tick

func (t *Timeline) Tick() time.Time

Tick samples the clock once and advances all active animations with the resulting timestamp. Finished animations are removed from the timeline.

type Timing

type Timing struct {
	Duration time.Duration
	Delay    time.Duration
	Easing   EasingFunction
}

Timing describes the duration, delay, and easing of one effect.

func NewTiming

func NewTiming(duration, delay time.Duration, easing EasingFunction) (Timing, error)

NewTiming validates and creates effect timing parameters.

func (Timing) Sample

func (timing Timing) Sample(start, current time.Time) TimingSample

Sample evaluates timing at current using start as the style-change time.

type TimingSample

type TimingSample struct {
	Phase    Phase
	Progress float64
}

TimingSample is the phase and eased progress at one timestamp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL