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

deep-animator

v1.0.9

Published

deep object animation

Downloads

4

Readme

AnimatorJs

Object Animator animates any object - recursively. That is, it will animate entire object trees. It determines the current values of the target object and increments those values toward the destination values over a set duration. It features color animation, (At present, hex, rgb, rgba and CSS color-names), independent CSS transform animation, and a growing number of easings.

Usage (webpack)

import {ObjectAnimator} from 'deep-animator'
var animator = new ObjectAnimator()
animator.loadAnimation(animationPayload).animate()
//will start your animation. AnimationPayload described below.

How it works:

The animationPayload package is simple:

{
	src: {Object||Array} the object to be animated
	dest: {Object||Array} the object containing destination values. Must mirror the src
	duration: {number} time in milliseconds over which the animation should take place
	contour: {string} the easing desired
	preAnim: {function} callBack to execute before the animation takes place
	postAnim: {function} callBack to execute after the animation is finished
	preInc: {function} callback to execute before each animation frame render
	postInc: {function} callBack to execute after each animation frame render
	synchTransInc: {boolean} If truthy, animator will retrieve and synchronize the transform string before every frame (So that any other animations can also run on that transform). Otherwise it only synchs at the start of the animation.
}

Strings are parsed for numbers and incremented in place to their destinations, taking their destinations from corresponding destination strings.

Ex.

An animation taking

src: {str:'hello 12 world 24'}
dest:{str:'32 goodbye 54'}

would animate the src string to 'hello 32 world 54' 

Of course, numbers are animated as well.

CSS Colors are converted to rgba and incremented as above.

Nested objects/arrays can take any form. The dest object must mirror the src object, whether single or multi-level. Any dest value not having a corresponding src value will not be animated.

The animation is prepared by tracing out the dest object and looking for corresponding src objects. So the src object can be any size. The dest object determines the scope and depth of the animation.

Note: at present, style properties whose default is an empty string will not be animated without first initializing them.

CSS Transforms

Animate a transform property in this way:

anim({
  src:node.style,
  dest:{transform:'rotateY(5deg) translateX(5px)'}
})

If the transform property already contains the transforms you want to animate, the anim will synch up the values you animate with what's there, and the order does not matter.

node.style.transform='translateY(90%) rotateY(5deg) translateX(5px)'
anim({
	src:node.style,
	dest:{transform:'translateX(200px) translateY(50%)'}
})

will animate the transform property to

'translateY(50%) rotateY(5deg) translateX(200px)'

However, if the properties are not already there, they will be appended to the end of the transform string with default values, in the order they appear in the dest.transform string, and then animated to their destinations

If synchTransInc is set to true in the animation payload, anim will read the transform property before every frame. This is so that if there are other animations animating different transforms on the same node, they don't bump into one another.

Use

Simplest Use

if available, the ObjectAnimator package will put an 'anim' variable on the window. calling

var animName=anim(animationPayload)

will start and return the animation.

You may also get a shorthand constructor and store where you like:

var anim=new ObjectAnimator().getShorthand()
var animName=anim(animationPayload)

Otherwise,

var animator=new ObjectAnimator().loadAnimation(animationPayload).animate()  

will start and return your animation.

Synching Values From Separate Objects

You can synch objects together by creating a super object.

Say you wanted to animate node1.style.width together with node2.style.height. You would do it this way

anim({
  src:{
    node1:node1.style,
    node2:node2.style
   }
   dest:{
     node1:{width:'100%'}
     node2:{height:'50%'}
   }
)}

The src and dest must still be congruent.

Methods

stop()

stops the animation

Easings

  • linear
  • smooth-sine
  • smooth : speed weighted to the front of the animation
  • root :abrupt start, smooth end
  • para: smooth start abrupt end
  • boomerang :extends beyond destination and returns to destination

Advanced Behavior

ObjectAnimator is currently powering the animation method embedded in queueJS (npm i queue-conductor). The API of the animate function is identical (pass-through) to the API described above. Using the ObjectAnimator in the context of QueueJS opens a dynamic range of advanced behavior controls- stopping/starting, reversing, looping, alternating, delay, complex timelines and anything else one can think of.

Testing

Tests are run with mocha in the browser.

  • From the command line, navigate to the module folder.
  • Run webpack --config webpack.mocha_config.js
  • In your browser visit the subdirectory : dist/tests/run_tests.htm

Future Features

  • querySelector
  • application of the same destination to multiple objects
  • pre-packaged objects provided by queueJS for advanced animation behavior and control API

Easings

  • unlimited-point bezier curve
  • custom easing functions
  • spring parameters