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

gm-easing

v1.4.4

Published

Fluent easing function provider.

Downloads

4

Readme

Easing / gm-easing

Fluent Easing function provider with built in Bezier Curve based easing functions and exact clones of CSS3 transition built-ins, plus the ability to use your own custom easing functions.

This module can be used for animations, audio and games and anything else.

Easing functions take a time value, t between 0 and 1 and return an eased time value.

Installation

Browserify/NPM

    $ npm install --save gm-easing
  var Easer = require('gm-easing').Easer;

API

.Easer()

// generate an easing function...
var easer = new Easer().using("ease-in");

// pass your delta (a value between 0 and 1) to the easer to get your eased value.
var easedDelta = easer( delta );

.generateAllSamples() Optimisation Considerations

CSS3 transition curve emulation relies on pre-generated samples. By default, after a CSS curve is used the first time, the samples are then cached. This could, on slower devices, cause a slight delay which can be avoided by generating the samples at some other time when your applications is not otherwise under any particular load.

// browserify:
require('gm-easing').generateAllSamples();
// component:
require('easing').generateAllSamples();

.presets

Returns the list of available presets.

.isPreset( name )

Returns true if name is a valid preset.

Easer API

Easer().using( "preset" )

Returns a function which takes an input ratio of 0 to 1 and returns the eased output ratio.

Use an easing preset. Choices are:

  • linear
  • ease - Replicates CSS3 default
  • ease-in - Replicates CSS3 ease-in
  • ease-out - Replicates CSS3 ease-out
  • ease-in-out - Replicates CSS3 ease-in-out
  • ease-in-back
  • ease-out-back
  • ease-in-out-back
  • ease-in-expo
  • ease-out-expo
  • ease-in-cubic
  • ease-out-cubic
var easer = new Easer().using('ease-in');
easer(0); // 0
easer(1); // 1
easer(0.5); // 0.3147198334560001

new Easer().usingCSS3Curve( c2.x, c2.y, c3.x, c3.y [, samples])

How CSS3 Curves work

Creates an easing function which emulates the behaviour of a custom CSS3 easing curve. Any CSS3 curve generator can generate compatible values for this, for example Ceaser.

Note that computing "y at x(t)" requires the building of a lookup table, although only once for any given curve. For the best performance it is better to generate an easing function using the same custom curve long before you intend to use it in an actual animation.

Optionally you can specify the number of samples required. By default 10,000 samples are generated which serves for most purposes but if you notice jerky movement for extremely long running animations then either use more samples (at the expense of more memory), use a Bezier Curve directly (without samples), or use a custom easing function.

var easer = new Easer().usingCSS3Curve(0.33,-0.305, 0.715,-0.155);
easer(0); // 0
easer(1); // 1
easer(0.5); // -0.06145341884495001

Note that, as with CSS3 transition-timing-functions, x must stay between 0 and 1 along the curve. It'll still run but it's kinda glitchy. In testing, real CSS3 transitions glitch out in exactly the same way.

new Easer().usingCustomCurve( curve )

How CSS3 Curves work

An easing function can be generated directly from any arbitrary Bezier Curve where the C1 and C4 are not limited to 0,0 and 1,1 respectively.

There is an important difference between this and using CSS3Curves: No samples are generated. Eased values are generated by computing the value of y at time on every call to the easing function. The x value is ignored.

The effects tend to be more subtle, but it is more efficent in terms of memory usage and there is no delay while samples are precomputed.

Curve data should be structured as an object containing and vector arrays: { c1 : [x, y], c2 : [x, y], c3 : [x, y], c4 : [x,y]}

var easer = new Easer().usingCustomCurve({ c1 : [0,0], c2 : [0.075,0.61], c3 : [0.36,0.93], c4 : [1,1]});
easer(0); // 0
easer(1); // 1
easer(0.5); //0.7025

### new Easer().usingCustomEaser( function )

Easer allows you to use your own easing functions. Any function will do, so long as it takes a value between 0 and 1 and returns some value useful to you. 
Mostly this is support implementations like [gm-tween](https://github.com/charlottegore/tween) that rely on a consistent easing interface but occasionally
want to offer developers the ability to implement their own easing functions.

```js
var easer = new Easer().usingCustomEaser( function (t){
  return 1 - t;
});
easer(0); // 1
easer(1); // 0
easer(0.5); // 0.5

License

MIT