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

@lucasdinonolte/animator

v0.0.1

Published

Utility package designed to make keyframe-like animations in code easier.

Downloads

3

Readme

Animator

Utility package designed to make keyframe-like animations in code easier.

Installation

npm install @lucasdinonolte/animator

Usage

Basic use case

import { transition } from '@lucasdinonolte/animator';

// transition returns a function that can be called for
// each frame of the animation with the tick value
const xPos = transition({
  from: 0,
  to: 100,
  // These can be frames or seconds, depending on what
  // you pass as the tick in the next step
  duration: 10,
  delay: 1,

  // Allows to set how often the transition should run
  // Defaults to 1
  iterationCount: 10,

  // Defines the direction of the animation
  // forward (0 -> 1)
  // runs the animation in the specified direction
  //
  // reverse (1 -> 0)
  // runs the animation in the reversed direction
  //
  // alternate (0 -> 1 -> 0 -> 1 -> ...)
  // runs the animation in alternating directions, starting
  // with a forwards run.
  //
  // alternateReverse (1 -> 0 -> -> 0 -> ...)
  // runs the animation in alternating directions, starting
  // with a reversed run.
  //
  // Defaults to forward
  direction: 'alternate',

  // Sets the easing curve of the transition. Accepts a custom
  // function or a string referring to one of the predefined
  // easing curves. See `src/easings.js` for a list of all
  // predefined easings.
  //
  // Defaults to linear
  easing: 'easeInOutExpo',
});

// The defined transition can then be called with a tick
// value. The tick value is a value that increases from
// animation frame to frame. Usually this will either be
// the current frame's number or a timestamp value.
const x = xPos(frameNumber);

Custom easing function

import { transition } from '@lucasdinonolte/animator';

const xPos = transition({
  from: 23,
  to: 123,
  duration: 2,

  // Easing functions are called with a linear t value below 0 and 1
  // and map this value to whatever easing curve you want to approximate
  //
  // The example below maps to a cubic curve
  easing: (t) => t * t * t,
});

Sequential Transition

import { sequentialTransition } from '@lucasdinonolte/animator';

const xPos = sequentialTransition(
  // The first argument passed to sequentialTransition
  // describes the original state of the animation
  {
    from: 0,

    // If set, this duration will be used as the default
    // for animation steps that don’t define their own
    // duration.
    duration: 60,

    // If set, this easing will be used as the default
    // for animation steps that don't define their own
    // easing.
    easing: 'easeInQuad',
  },
  // All following argument describe keyframes of the animation
  // This keyframe will animate to 10, the transition will take
  // 60 frames (assuming frames are used as the tick value) and
  // start at 10 frames.
  {
    to: 10,
    delay: 10,
    duration: 60,
  },
  // This keyframe will animation back to 0. The transition will
  // take 120 frames and will start 20 frames after the previous
  // transition has ended.
  {
    to: 0,
    delay: 20,
    duration: 120,
  },
);

Transition multiple values

// Transition allows you to interpolate between numbers, or arrays
// and object of numbers. When working with arrays and objects make
// sure the shape of from and to value matches.
const pos = transition({
  from: { x: 10, y: 20 },
  to: { x: 0, y: 100 },
  duration: 20,
});

const { x, y } = pos(10);