npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

animation-timelines

v0.0.4

Published

A collection of Custom AnimationTimeline for use with Web Animations.

Downloads

2,437

Readme

Animation Timelines

This is a collection of custom timelines to drive Web Animations similarly to the built-in AnimationTimeline.

Protocol

The protocol for a custom timeline is:

interface CustomTimeline {
  currentTime: number;
  animate(animation: Animation): () => void;
}

With AnimationTimeline built-in to the browser, you would pass them as arguments to an Animation like this:

const animation = new Animation(..., timeline);
// or
const animation = element.animate(..., { timeline });

That doesn't work with a custom timeline like the ones in this package. Instead, you pass the Animation to the animate(...) function like so:

const animation = new Animation(...);
timeline.animate(animation);
// or
const animation = element.animate(...);
timeline.animate(animation);

The delay and duration of the Animation can be used to configure the equivalent of rangeStart and rangeEnd.

const animation = element.animate(..., {
  delay: 25, // start at 25%
  duration: 75, // end at 75%
});
timeline.animate(animation);

The animate() function returns a clean up function which removes any internal listeners that the timeline might have registered while running the animation. This lets you free that memory after you no longer need the animation. This should be called when the target element of the animation is no longer used - not the source element of the events to the timeline.

const cleanup = timeline.animate();
...
cleanup();

This protocol is also supported by React with the startGestureTransition API.

startGestureTransition(timeline, ...);

ScrollTimeline

This is a "ponyfill" for the ScrollTimeline API. It can be used to drive an animation based on the current scroll position of an element, when the native one is not available.


interface ScrollTimeline extends CustomTimeline {
  new(options: {
    source: Element,
    axis?: 'block' | 'inline' | 'x' | 'y',
  }): ScrollTimeline;
  source: Element;
  axis: 'block' | 'inline' | 'x' | 'y';
}
import ScrollTimelinePolyfill from 'animation-timelines/scroll-timeline';

const timeline = new ScrollTimelinePolyfill({ source: element, axis: 'x' })
timeline.animate(animation);

The currentTime of the Animation spans 0 - 100 where 0 is when the scroll is at the beginning and 100 is when the scroll is at the end. Use delay and duration of the Animation to customize the start and end range.

ViewTimeline

This is a "ponyfill" for the ViewTimeline API. It can be used to drive an animation based on the current visibility of an element, when the native one is not available.

interface ViewTimeline extends ScrollTimeline {
  new(options: {
    subject: Element,
    axis?: 'block' | 'inline' | 'x' | 'y',
    inset?: 'auto' | number | ['auto' | number] | ['auto' | number, 'auto' | number],
  }): ViewTimeline;
  subject: Element;
  startOffset: number;
  endOffset: number;
}
import ViewTimelinePolyfill from 'animation-timelines/view-timeline';

const timeline = new ViewTimelinePolyfill({ subject: element, axis: 'x' })
timeline.animate(animation);

The currentTime of the Animation spans 0 - 100 where 0 is when the subject is about to enter the visible range and 100 is when the subject is about the exit the visible range. Use delay and duration of the Animation to customize the start and end range.

TouchPanTimeline

This drives an animation using a touch gestures on the "source" element to pan along one axis.

interface TouchPanTimeline extends CustomTimeline {
  new(options: {
    source: Element,
    axis?: 'block' | 'inline' | 'x' | 'y',
    touch?: TouchEvent,
    range?: number | [number, number],
    snap?: number | Array<number>,
    decelerationRate?: number,
  }): TouchPanTimeline;
  source: Element;
  axis: 'block' | 'inline' | 'x' | 'y';
  settled: Promise<void>;
}
import TouchPanTimeline from 'animation-timelines/touch-pan-timeline';

const timeline = new TouchPanTimeline({ source: element });
timeline.animate(animation);

The touch can be passed TouchEvent. It is used for where the origin point for the first touch should be considered. This lets the timeline be created after a touch sequence has already started. Such as if coordinating responders is necessary before starting it.

The range specifies, in pixels, what point should represent 0 on the timeline and what should point should represent 100. If a single number is specified it is considered the end range starting from zero. Note that the timeline can still overflow this range during the pan. fill: 'both' can be used on the Animation to clamp it.

The snap specifies, in pixels, an array of points which the pan should snap to before settling. If no snap is specified it'll stop after some momentum or if it ends up outside the range then it'll snap to the edge of the range.

The decelerationRate specifies how fast the momentum should slow down after release. Defaults to 0.998.

The currentTime of the Animation spans 0 - 100 where 0 represents the starting range and 100 represnts the end of the range. Use delay and duration of the Animation to customize the clamping start and end range of this animation.

You can read timeline.currentTime to get a value between 0 - 100 where in the range you're currently in. If you read it after the touchend event, you'll observe the optimistic time for what it'll be after momentum has finished. At this point it is still possible to "catch" the animation until it settles.

The settled property on the timeline contains a Promise which resolves after touch is released AND the momentum has finished moving. This is a good time to cancel the animation and clean up.

const cleanup = timeline.animate(animation);
await timeline.settled;
animation.cancel();
cleanup();