Skip to main content
Animation utilities for creating smooth transitions and physics-based motion.

interpolate()

Maps an input value within a range to an output value.
const value = interpolate(input, inputRange, outputRange, options);
input
number
required
The value to interpolate
inputRange
number[]
required
Array of input values (must be strictly monotonically increasing, at least 2 elements)
outputRange
number[]
required
Array of output values (must match length of inputRange)
options
InterpolateOptions
Configuration options
value
number
The interpolated output value

Example

import { interpolate, Easing } from '@heliosvideo/core';

// Linear interpolation
const opacity = interpolate(
  frame,
  [0, 30],
  [0, 1]
);

// With easing
const scale = interpolate(
  frame,
  [0, 60],
  [0.5, 1.5],
  { easing: Easing.cubic.out }
);

// Multi-segment animation
const y = interpolate(
  frame,
  [0, 30, 60, 90],
  [0, 100, 100, 200]
);

// Clamping
const clamped = interpolate(
  frame,
  [0, 100],
  [0, 1],
  {
    extrapolateLeft: 'clamp',
    extrapolateRight: 'clamp'
  }
);

spring()

Calculates the value of a spring physics simulation at a specific frame.
const value = spring(options);
options
SpringOptions
required
Spring configuration
value
number
The calculated spring value at the given frame

Example

import { spring } from '@heliosvideo/core';

// Basic spring animation
const scale = spring({
  frame: currentFrame,
  fps: 30,
  from: 0,
  to: 1,
});

// Bouncy spring
const y = spring({
  frame: currentFrame,
  fps: 30,
  from: 0,
  to: 100,
  config: {
    mass: 1,
    stiffness: 200,
    damping: 5,
  },
});

// Stiff spring with no overshoot
const opacity = spring({
  frame: currentFrame,
  fps: 30,
  from: 0,
  to: 1,
  config: {
    stiffness: 300,
    damping: 30,
    overshootClamping: true,
  },
});

calculateSpringDuration()

Calculates the number of frames required for a spring to settle.
const duration = calculateSpringDuration(options, threshold);
options
Omit<SpringOptions, 'frame'>
required
Spring configuration (same as spring() but without frame)
threshold
number
default:"0.001"
Distance from target to consider settled
duration
number
Estimated duration in frames

Example

import { calculateSpringDuration } from '@heliosvideo/core';

const duration = calculateSpringDuration({
  fps: 30,
  from: 0,
  to: 1,
  config: {
    stiffness: 100,
    damping: 10,
  },
});

console.log(`Spring will settle in ${duration} frames`);

DEFAULT_SPRING_CONFIG

Default spring configuration values.
const DEFAULT_SPRING_CONFIG: Required<SpringConfig> = {
  mass: 1,
  stiffness: 100,
  damping: 10,
  overshootClamping: false,
};

Build docs developers (and LLMs) love