Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anymation

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anymation - npm Package Compare versions

Comparing version 0.2.1 to 0.4.0

110

index.js

@@ -6,6 +6,2 @@ 'use strict';

var defaultGetter = function(object, property) {
return object[property];
};
var defaultSetter = function(object, property, value) {

@@ -15,13 +11,33 @@ object[property] = value;

var linearEasing = function(t) {
return t;
var linearEasing = function(x) {
return x;
};
function updateProp(name, options, t) {
var obj = options.object,
setter = options.setter,
teased = options.easing(t);
if (options.discreteValues) {
// step values
var nValues = options.discreteValues.length;
var index = Math.floor(teased * nValues);
if (index >= nValues)
index = nValues-1;
setter(obj, name, options.discreteValues[index]);
}
else if (options.valueFn) {
setter(obj, name, options.valueFn(teased));
}
else if (options.tween) {
var start = options.tween[0], end = options.tween[1];
var newValue = start + teased * (end - start);
setter(obj, name, newValue);
}
}
var defaultOptions = {
object: null, // must provide
name: "anonymous",
duration: 1000,
props: {},
cancelable: true,
getter: defaultGetter,
setter: defaultSetter,

@@ -42,21 +58,30 @@ easing: linearEasing

this.startTime = now();
this.props = Object.create(null);
}
this.animationStartValues = {};
for (var key in this.props) {
var propVal = this.props[key], getter;
if (typeof propVal !== "object" || propVal === null || Array.isArray(propVal)) {
this.props[key] = {
value: this.props[key]
};
getter = this.getter;
}
else {
getter = propVal.getter || this.getter;
}
Animation.prototype = {
addProp: function(name, options) {
var fullOptions = extend({
object: this.object,
setter: this.setter,
easing: this.easing
}, options);
this.props[name] = fullOptions;
return this;
},
this.animationStartValues[key] = getter(this.object, key);
}
}
tween: function(name, from, to) {
return this.addProp(name, { tween: [from, to] });
},
Animation.prototype = {
discrete: function(name, array) {
return this.addProp(name, { discreteValues: array });
},
fn: function(name, fn) {
return this.addProp(name, { valueFn: fn});
},
update: function(timeNow) {

@@ -68,30 +93,7 @@ timeNow = timeNow || now();

var obj = this.object;
for (var key in this.props) {
var spec = this.props[key],
value = spec.value,
setter = spec.setter || this.setter,
easing = spec.easing|| this.easing,
teased = easing(t),
startValue;
if (Array.isArray(value)) {
// Specified step values
var nValues = value.length;
var index = Math.floor(teased * nValues);
if (index >= nValues)
index = nValues-1;
setter(obj, key, value[index]);
}
else if (typeof value === "function")
{
startValue = this.animationStartValues[key];
setter(obj, key, value(teased, startValue));
}
else if (Number.isFinite(value))
{
startValue = this.animationStartValues[key];
var newValue = startValue + teased * (value - startValue);
setter(obj, key, newValue);
}
var props = this.props;
for (var key in props) {
updateProp(key, props[key], t);
}
if (t === 1) {

@@ -103,4 +105,4 @@ this.done = true;

}
return true;
return true;
},

@@ -107,0 +109,0 @@

{
"name": "anymation",
"version": "0.2.1",
"version": "0.4.0",
"description": "Simple & easy animation/tweener",

@@ -34,3 +34,16 @@ "main": "index.js",

"url": "https://github.com/scottglz/anymation"
},
"testling": {
"files": "test/*.js",
"browsers": [
"ie/6..latest",
"chrome/22..latest",
"firefox/16..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6",
"ipad/6",
"android-browser/latest"
]
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc