intertween
Advanced tools
Comparing version 0.0.3 to 0.0.4
104
index.js
/** | ||
* @name InterTween | ||
* @description The lightweight, fastest, smartest, effecient value interpolator with no-dependecy, zero-configuration and relative interpolation | ||
* @author @dalisoft (https://github.com/dalisoft) | ||
* @author dalisoft (https://github.com/dalisoft) | ||
* @license MIT-License | ||
@@ -18,3 +18,3 @@ * First Release at 20 August 2017, by @dalisoft | ||
} | ||
(typeof(window) !== 'undefined' ? window : this, function (undefined) { | ||
(typeof(window) !== 'undefined' ? window : this, function () { | ||
@@ -68,3 +68,3 @@ // RegExp variables | ||
if (typeof e === 'number') { | ||
return e - s; | ||
return e; | ||
} else { | ||
@@ -75,9 +75,9 @@ var rv = relativeModes[e.substr(0, 2)], | ||
var e2 = e[0] + v; | ||
return (s + parseFloat(e2)) - s; | ||
return s + parseFloat(e2); | ||
} else if (rv === 2) { | ||
return (s * +v) - s; | ||
return s * +v; | ||
} else if (rv === 3) { | ||
return (s / +v) - s; | ||
return s / +v; | ||
} else if (rv === 4) { | ||
return (s * (+v / 100)) - s; | ||
return s * (+v / 100); | ||
} | ||
@@ -104,3 +104,3 @@ } | ||
var ev = s2n(e); | ||
var uv = unitTween(sv, ev); | ||
var uv = unitTween(sv, ev, d); | ||
if (uv) { | ||
@@ -158,11 +158,32 @@ return uv; | ||
function parseInterpolatables(sv, ev) { | ||
/*function parseInterpolatables(sv, ev) { | ||
var vs = []; | ||
for (var i = 0, len = ev.length; i < len; i++) { | ||
var t = ev[i]; | ||
vs[i] = mainTween(i === 0 ? sv : ev[i - 1], t); | ||
var e = ev[i]; | ||
vs[i] = mainTween(i === 0 ? sv : ev[i - 1], e); | ||
} | ||
return vs; | ||
} | ||
var lastItem = ev[ev.length - 1]; | ||
vs.push(mainTween(lastItem, lastItem)); | ||
var endLength = vs.length - 1; | ||
return function (t) { | ||
var totalTime = t * endLength; | ||
var roundedTime = Math.floor(totalTime); | ||
var elapsed = totalTime - roundedTime; | ||
var item = vs[roundedTime]; | ||
var interpolated = item(elapsed); | ||
return interpolated; | ||
}; | ||
}*/ | ||
function parseInterpolatables (sv, ev) { | ||
var vs = []; | ||
for (var i = 0, len = ev.length; i < len; i++) { | ||
var e = ev[i]; | ||
vs[i] = mainTween(i === 0 ? sv : ev[i - 1], e); | ||
} | ||
var lastItem = ev[ev.length - 1]; | ||
vs.push(mainTween(lastItem, lastItem)); | ||
return vs; | ||
} | ||
function arrayTween(sv, ev, d) { | ||
@@ -172,3 +193,3 @@ d = d !== undefined ? d : 10000; | ||
var rv = []; | ||
for (var i = 0, len = s.length; i < len; i++) { | ||
for (var i = 0, len = ev.length; i < len; i++) { | ||
var vs = s[i], | ||
@@ -178,6 +199,7 @@ ve = ev[i]; | ||
s[i] = vs === ve ? null : isArray(ve) ? | ||
isArray(vs) ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof ve === 'object' ? | ||
objectTween(vs, ve, d) : rv[i] !== null ? r2n( | ||
vs, ve) : typeof ve === 'string' ? | ||
isArray(vs) && ve.length === vs.length ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof ve === 'object' ? | ||
objectTween(vs, ve, d) : typeof ve === 'string' ? | ||
stringTween(vs, ve, d) : vs; | ||
ev[i] = rv[i] !== null ? r2n( | ||
vs, ve) : ve; | ||
} | ||
@@ -193,4 +215,4 @@ return function (t) { | ||
d : typeof a === 'function' ? a(t) : b; | ||
if (t === 1 && r !== null) { | ||
s[i] += b; | ||
if (r && t === 1) { | ||
s[i] = b; | ||
ev[i] = r2n(s[i], r); | ||
@@ -210,6 +232,15 @@ } | ||
var s = +sv[0], | ||
e = +ev[0] - s, | ||
u = ev[1]; | ||
e = +ev[0], | ||
u = ev[1], | ||
r = typeof ev[0] === 'string' && ev[0].indexOf('=') === 1 ? ev[0] : null; | ||
if (r) { | ||
e = r2n(s, e); | ||
} | ||
return function (t) { | ||
return ((((s + e * t) * d) | 0) / d) + u; | ||
var v = ((((s + (e - s) * t) * d) | 0) / d) + u; | ||
if (r && t === 1) { | ||
s = e; | ||
e = r2n(s, r); | ||
} | ||
return v; | ||
} | ||
@@ -225,3 +256,3 @@ } | ||
var s = {}; | ||
for (var i in sv) { | ||
for (var i in ev) { | ||
s[i] = sv[i]; | ||
@@ -232,9 +263,9 @@ var vs = s[i], | ||
s[i] = vs === ve ? null : isArray(ve) ? | ||
isArray(vs) ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof ve === 'object' ? | ||
objectTween(vs, ve, d) : rv[i] !== null ? r2n( | ||
vs, ve) : typeof ve === 'string' ? | ||
isArray(vs) && ve.length === vs.length ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof ve === 'object' ? | ||
objectTween(vs, ve, d) : typeof ve === 'string' ? | ||
stringTween(vs, ve, d) : vs; | ||
ev[i] = rv[i] !== null ? r2n(vs, ve) : ve; | ||
} | ||
return function (t) { | ||
for (var i in s) { | ||
for (var i in ev) { | ||
var a = s[i], | ||
@@ -247,4 +278,4 @@ b = ev[i], | ||
d : typeof a === 'function' ? a(t) : b; | ||
if (t === 1 && r !== null) { | ||
s[i] += b; | ||
if (r && t === 1) { | ||
s[i] = b; | ||
ev[i] = r2n(s[i], r); | ||
@@ -259,7 +290,16 @@ } | ||
d = d !== undefined ? d : 10000; | ||
return isArray(ev) ? isArray(sv) ? arrayTween(sv, ev, d) : parseInterpolatables(sv, ev) : isArray(sv) ? tweenThemTo(sv, ev) : typeof ev === 'object' ? | ||
var rv = typeof(ev) === 'string' && typeof sv === 'number' && ev.indexOf('=') === 1 ? ev : null; | ||
if (rv) { | ||
ev = r2n(sv, rv); | ||
} | ||
return isArray(ev) ? isArray(sv) && sv.length === ev.length ? arrayTween(sv, ev, d) : parseInterpolatables(sv, ev) : isArray(sv) ? tweenThemTo(sv, ev) : typeof ev === 'object' ? | ||
objectTween(sv, ev, d) : typeof ev === 'string' ? stringTween(sv, ev, d) : | ||
function (t) { | ||
return typeof ev === 'number' ? (((sv + (ev - sv) * t) * | ||
d) | 0) / d : sv; | ||
var vv = typeof ev === 'number' ? (((sv + (ev - sv) * t) * | ||
d) | 0) / d : sv | ||
if (rv && t === 1) { | ||
sv += ev; | ||
ev = r2n(sv, rv); | ||
} | ||
return vv; | ||
} | ||
@@ -266,0 +306,0 @@ } |
{ | ||
"name": "intertween", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "The lightweight, fastest, smartest, effecient value interpolator with no-dependecy, zero-configuration and relative interpolation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16812
4
280
0