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 🙏

© 2024 – Pkg Stats / Ryan Hefner

optimo-animator

v1.2.9

Published

Animator

Downloads

19

Readme

Optimo Animator

Optimo animator is a lightweight Javascript animation library. The main goal of this project is to provide a set of classes to implement temporal animations in the browser. This library tries to be as low-level as possible in the sense that it provides the bare minimum to animate any kind of objects.

Animator class

The Animator class is responsible for running the animation loop and tracking time. The Animator class takes an array of Timelines as arguments for the constructor. In general, a project only needs one instance of Animator that can handle multiple Timelines.

const timeline = new Timeline([
  {
    duration: 3000,
    handler: (progress) => {
      // Do something here
    },
  },
]);

const animator = new Animator([timeline]);
animator.start();

The animator can be started and stopped as below:

const animator = new Animator([]);

animator.start();
animator.stop();

Additionally it can be used to evaluate a specific frame with computeFrameAt:

const animator = new Animator([]);

const time = 14325; // Milliseconds
animator.computeFrameAt(time);

Timeline class

The Timeline class is responsible for managing the steps. A timeline is basically a set of instructions that the animation should perform sequentially. The Timeline class takes an array of Steps as arguments for the constructor.

const circle = document.querySelector('.circle') as HTMLDivElement;

let sizeX = 100;
let sizeY = 100;

const sizeTimeline = new Timeline([
  {
    duration: 3000,
    onStart: () => {
      sizeX = 100;
      sizeY = 100;
      circle.style.width = `${sizeX}px`;
      circle.style.height = `${sizeY}px`;
    },
    handler: (progress) => {
      sizeX = 100 + progress * 300;
      circle.style.width = `${sizeX}px`;
    },
  },
  {
    duration: 4000,
    handler: (progress) => {
      sizeY = 100 + progress * 300;
      circle.style.height = `${sizeY}px`;
    },
  },
  {
    duration: 2000,
    handler: (progress) => {
      sizeX = 400 - progress * 300;
      sizeY = 400 - progress * 300;
      circle.style.width = `${sizeX}px`;
      circle.style.height = `${sizeY}px`;
    },
  },
]);

Step class

The Step class encapsulates the logic to be evaluated during an animation step. A step has a duration and a handler method which receives the current progress (number from 0 to 1) used to retrieve the stage the step is in. Each step is evaluated after the other and the handler method is evaluated for the duration of the step.

Additional methods can be defined in a step such as onStart and onEnd. onStart is executed each time the step is evaluated for the first time in a loop and onEnd when the step is evaluated for the last time in a loop.

{
  duration: 4000,
  onStart: () => {
    // Do something when the step is evaluated for the first time in the loop
  },
  onEnd: () => {
    // Do something when the step is evaluated for the last time in the loop
  },
  handler: (progress) => {
    // Do something during the whole step duration
    // `progress` goes from 0 to 1.
  },
},