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

from-to.js

v0.0.1

Published

A lightweight animation library that offers tween and spring animations, with a gzip compressed size of just 1kb.

Downloads

26

Readme

From To

Transitioning from one value to another.


"Why reinvent the wheel?"

Sometimes, all you need is an extremely lightweight package to transition from one value to another. It requires no bindings to DOM elements or framework-specific code. In such cases, popular animation libraries may come with additional features that are not necessary.

Install

pnpm install from-to.js

Usage

animate(from: Value, to: Value, options?: Options<Value>) => Controls

It supports transition animations for both numerical values and colors.

For example, you can use animate(0, 100) or animate([0, 0, 0], [100, 200, 300]) for transitioning numerical values or animate('#000', '#fff') for transitioning colors.

Transition

The transition type can be either tween or spring. The default transition type is tween.

tween

animate('#FF0000ff', '#8B00FFff', {
  type: 'tween',
  ease: 'ease',
  duration: 3,
})

ease: ease | liner | easeIn | easeOut | easeInOut

It can also handle transition animations for arrays in the format [number, number, number, number], allowing you to customize the transition curve.

duration: number

The transition duration is specified in seconds.

spring

animate(0, 200, {
  type: 'spring',
  stiffness: 100,
  damping: 10,
  mass: 1,
})

stiffness: number

The stiffness parameter defines the rigidity or intensity of the spring effect. A higher stiffness value will produce a more pronounced and rapid transition.

The default value is set to 100.

damping: number

The damping parameter controls the resistance or smoothness of the spring's movement. A higher damping value will result in a slower and smoother transition, while a lower damping value will allow for more oscillations.

The default value is set to 10.

mass: number

The mass parameter affects the inertia of the animation. A higher mass value results in slower acceleration and deceleration, creating a smoother and more gradual transition.

The default value is set to 1.

Lifecycles

The animation state will be updated through Lifecycles callbacks.

animate([0, 0], [200, 500], {
  onPlay() {
    // when the animation starts playing for the first time.
  },
  onUpdate([x, y]) {
    // You can update DOM state or perform similar actions here
    // every time the animation updates.
    element.style.transform = `translate(${x}px,${y}px)`
  },
  onComplete() {
    // when the animation completes its execution.
    // If loop is set to true, it will be triggered after each iteration.
  },
  onStop() {
    // When the animation is stopped
  },
})

Controls

const animation = animate(0, 200)

animation: thenable

A thenable object can be invoked using the then method, just like a Promise, and can also be used with await.

await animation

console.log('animation end')

animation.play: function

animation.play()

If autoplay is set to false, you need to call animation.play() to start the animation. When the animation is paused, calling play() will resume it. If the animation has ended or been canceled, calling play() will restart the animation.

animation.pause: funciton

animation.pause()

Pause the animation.

animation.stop: funciton

animation.stop()

Stop the animation.

animation.cancel()

Cancel the animation, Unlike the stop() method, canceling the animation will pass the initial values to the onUpdate callback.

Special Note

The algorithm for the spring animation in this library is sourced from the renowned animation library, framer-motion. I have utilized its algorithm in the code for this library.

License

MIT License


Made with ❤️‍🩹 in Chengdu