Skip to main content

API Reference

Technical details and configuration options

Plugin Options

The plugin accepts an optional configuration object:

		import plugin from 'tw-easing-gradients';
 
// Default options
plugin({ stops: 15 });
	

Options

Option Type Default Description
stops number 15 Number of color stops in the gradient

How It Works

1. Easing Coordinates

The plugin uses cubic bezier easing functions to calculate color stop positions:

		const EASING_FUNCTIONS = {
	ease: [0.25, 0.1, 0.25, 1],
	'ease-in': [0.42, 0, 1, 1],
	'ease-out': [0, 0, 0.58, 1],
	'ease-in-out': [0.42, 0, 0.58, 1]
};
	

2. Color Interpolation

Colors are interpolated using CSS relative color syntax with oklch() for perceptually uniform results. The color-mix() function blends colors, then oklch(from ... l c h / alpha) extracts the final value for maximum color fidelity.

3. Generated CSS

For a utility like bg-ease-in-out-to-r, the plugin generates a linear-gradient with multiple color stops using relative color syntax.

Browser Support

Requires browsers with CSS relative color syntax support — available in all major browsers since September 2024.

Data on support for the css-relative-colors feature across major browsers from caniuse.com

Exported Functions

The plugin also exports utility functions for programmatic use:

getCoordinates(easing, stops)

Get easing coordinates for a given easing function:

		import { getCoordinates } from 'tw-easing-gradients';
 
const coords = getCoordinates('ease-in-out', 15);
// Returns: [{ x: 0, y: 0 }, { x: 0.081, y: 0.021 }, ...]
	

TypeScript

The plugin is written in TypeScript and includes full type definitions:

		import type {
	EasingFunction,
	Direction,
	Coordinate
} from 'tw-easing-gradients';
 
const easing: EasingFunction = 'ease-in-out';
const dir: Direction = 'br';
	

Next Steps