GSAP (GreenSock Animation Platform): high-performance JavaScript animation for anything JavaScript can touch. 100% free, including every plugin.
JavaScript animationcanvasgsapjavascriptjavascript-libraryreactscrollscrolltriggerspringsvgweb-animations
Enhanced EaselPlugin to work with ColorMatrixFilter values like saturation, contrast, etc. in EaselJS
Jack Doyleaa23f6fccc44
diff --git a/src/minified/TweenMax.min.js b/src/minified/TweenMax.min.jsindex 555cfa3..e522c23 100755--- a/src/minified/TweenMax.min.js+++ b/src/minified/TweenMax.min.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.8.0* DATE: 2013-01-21* JavaScript (ActionScript 3 and 2 also available)diff --git a/src/minified/plugins/BezierPlugin.min.js b/src/minified/plugins/BezierPlugin.min.jsindex 96d5c17..e6da20b 100755--- a/src/minified/plugins/BezierPlugin.min.js+++ b/src/minified/plugins/BezierPlugin.min.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 0.9.0* DATE: 2013-01-21* JavaScript (also available in AS3 and AS2)diff --git a/src/minified/plugins/ColorPropsPlugin.min.js b/src/minified/plugins/ColorPropsPlugin.min.jsindex a6eb014..16877ad 100755--- a/src/minified/plugins/ColorPropsPlugin.min.js+++ b/src/minified/plugins/ColorPropsPlugin.min.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.0* DATE: 2012-06-08* JavaScriptdiff --git a/src/minified/plugins/EaselPlugin.min.js b/src/minified/plugins/EaselPlugin.min.jsindex c47679c..9cd61fc 100755--- a/src/minified/plugins/EaselPlugin.min.js+++ b/src/minified/plugins/EaselPlugin.min.js@@ -1,6 +1,6 @@-/**- * VERSION: beta 0.12- * DATE: 2013-01-13+/*!+ * VERSION: beta 0.1.3+ * DATE: 2013-01-26* JavaScript* UPDATES AND DOCS AT: http://www.greensock.com*@@ -10,4 +10,4 @@** @author: Jack Doyle, [email protected]**/-(window._gsQueue||(window._gsQueue=[])).push(function(){_gsDefine("plugins.EaselPlugin",["plugins.TweenPlugin"],function(e){var t=function(t,n){e.call(this,"easel",-1);this._overwriteProps.pop()},n=t.prototype=new e("easel",-1),r=/(\d|\.)+/g,i,s=["redMultiplier","greenMultiplier","blueMultiplier","alphaMultiplier","redOffset","greenOffset","blueOffset","alphaOffset"],o=function(e,t,n){if(!i){i=window.ColorFilter||window.createjs.ColorFilter;if(!i)throw"EaselPlugin error: The EaselJS ColorFilter JavaScript file wasn't loaded."}var r=e.filters||[],o=r.length,a,f,l,c,h;while(--o>-1)if(r[o]instanceof i){f=r[o];break}if(!f){f=new i;r.push(f);e.filters=r}l=f.clone();if(t.tint!=null){a=u(t.tint);c=t.tintAmount!=null?Number(t.tintAmount):1;l.redOffset=Number(a[0])*c;l.greenOffset=Number(a[1])*c;l.blueOffset=Number(a[2])*c;l.redMultiplier=l.greenMultiplier=l.blueMultiplier=1-c}else for(h in t)h!=="exposure"&&h!=="brightness"&&(l[h]=Number(t[h]));if(t.exposure!=null){l.redOffset=l.greenOffset=l.blueOffset=255*(Number(t.exposure)-1);l.redMultiplier=l.greenMultiplier=l.blueMultiplier=1}else if(t.brightness!=null){c=Number(t.brightness)-1;l.redOffset=l.greenOffset=l.blueOffset=c>0?c*255:0;l.redMultiplier=l.greenMultiplier=l.blueMultiplier=1-Math.abs(c)}o=8;while(--o>-1){h=s[o];f[h]!==l[h]&&n._addTween(f,h,f[h],l[h],"easel_colorFilter")}n._overwriteProps.push("easel_colorFilter");if(!e.cacheID)throw"EaselPlugin warning: for filters to display in EaselJS, you must call the object's cache() method first. "+e},u=function(e){if(e===""||e==null||e==="none")return a.transparent;if(a[e])return a[e];if(typeof e=="number")return[e>>16,e>>8&255,e&255];if(e.charAt(0)==="#"){e.length===4&&(e="#"+e.charAt(1)+e.charAt(1)+e.charAt(2)+e.charAt(2)+e.charAt(3)+e.charAt(3));e=parseInt(e.substr(1),16);return[e>>16,e>>8&255,e&255]}return e.match(r)||a.transparent},a={aqua:[0,255,255],lime:[0,255,0],silver:[192,192,192],black:[0,0,0],maroon:[128,0,0],teal:[0,128,128],blue:[0,0,255],navy:[0,0,128],white:[255,255,255],fuchsia:[255,0,255],olive:[128,128,0],yellow:[255,255,0],orange:[255,165,0],gray:[128,128,128],purple:[128,0,128],green:[0,128,0],red:[255,0,0],pink:[255,192,203],cyan:[0,255,255],transparent:[255,255,255,0]};n.constructor=t;t.API=2;n._onInitTween=function(e,t,n){this._target=e;var r,i,s;for(r in t)if(r==="colorFilter"||r==="tint"||r==="tintAmount"||r==="exposure"||r==="brightness"){if(!s){o(e,t.colorFilter||t,this);s=!0}}else if(e[r]!=null){this._firstPT=i={_next:this._firstPT,t:e,p:r,f:typeof e[r]=="function",n:r,pr:0,type:0};i.s=i.f?e[r.indexOf("set")||typeof e["get"+r.substr(3)]!="function"?r:"get"+r.substr(3)]():parseFloat(e[r]);i.c=typeof t[r]=="number"?t[r]-i.s:typeof t[r]=="string"?parseFloat(t[r].split("=").join("")):0;i._next&&(i._next._prev=i)}return!0};n.setRatio=function(e){var t=this._firstPT,n;while(t){n=t.c*e+t.s;t.r&&(n=n+(n>0?.5:-0.5)>>0);t.f?t.t[t.p](n):t.t[t.p]=n;t=t._next}this._target.cacheID&&this._target.updateCache()};e.activate([t]);return t},!0)});window._gsDefine&&_gsQueue.pop()();\ No newline at end of file+(window._gsQueue||(window._gsQueue=[])).push(function(){_gsDefine("plugins.EaselPlugin",["plugins.TweenPlugin"],function(a){var e,f,b=function(){a.call(this,"easel",-1),this._overwriteProps.pop()},c=b.prototype=new a("easel",-1),d=/(\d|\.)+/g,g=["redMultiplier","greenMultiplier","blueMultiplier","alphaMultiplier","redOffset","greenOffset","blueOffset","alphaOffset"],h=function(a,b,c){if(!e&&(e=window.ColorFilter||window.createjs.ColorFilter,!e))throw"EaselPlugin error: The EaselJS ColorFilter JavaScript file wasn't loaded.";for(var h,i,j,k,l,d=a.filters||[],f=d.length;--f>-1;)if(d[f]instanceof e){i=d[f];break}if(i||(i=new e,d.push(i),a.filters=d),j=i.clone(),null!=b.tint)h=s(b.tint),k=null!=b.tintAmount?Number(b.tintAmount):1,j.redOffset=Number(h[0])*k,j.greenOffset=Number(h[1])*k,j.blueOffset=Number(h[2])*k,j.redMultiplier=j.greenMultiplier=j.blueMultiplier=1-k;else for(l in b)"exposure"!==l&&"brightness"!==l&&(j[l]=Number(b[l]));for(null!=b.exposure?(j.redOffset=j.greenOffset=j.blueOffset=255*(Number(b.exposure)-1),j.redMultiplier=j.greenMultiplier=j.blueMultiplier=1):null!=b.brightness&&(k=Number(b.brightness)-1,j.redOffset=j.greenOffset=j.blueOffset=k>0?255*k:0,j.redMultiplier=j.greenMultiplier=j.blueMultiplier=1-Math.abs(k)),f=8;--f>-1;)l=g[f],i[l]!==j[l]&&c._addTween(i,l,i[l],j[l],"easel_colorFilter");if(c._overwriteProps.push("easel_colorFilter"),!a.cacheID)throw"EaselPlugin warning: for filters to display in EaselJS, you must call the object's cache() method first. "+a},i=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],j=.212671,k=.71516,l=.072169,m=function(a,b){if(!(a instanceof Array&&b instanceof Array))return b;var f,g,c=[],d=0,e=0;for(f=0;4>f;f++){for(g=0;5>g;g++)e=4===g?a[d+4]:0,c[d+g]=a[d]*b[g]+a[d+1]*b[g+5]+a[d+2]*b[g+10]+a[d+3]*b[g+15]+e;d+=5}return c},n=function(a,b){if(isNaN(b))return a;var c=1-b,d=c*j,e=c*k,f=c*l;return m([d+b,e,f,0,0,d,e+b,f,0,0,d,e,f+b,0,0,0,0,0,1,0],a)},o=function(a,b,c){isNaN(c)&&(c=1);var d=s(b),e=d[0]/255,f=d[1]/255,g=d[2]/255,h=1-c;return m([h+c*e*j,c*e*k,c*e*l,0,0,c*f*j,h+c*f*k,c*f*l,0,0,c*g*j,c*g*k,h+c*g*l,0,0,0,0,0,1,0],a)},p=function(a,b){if(isNaN(b))return a;b*=Math.PI/180;var c=Math.cos(b),d=Math.sin(b);return m([j+c*(1-j)+d*-j,k+c*-k+d*-k,l+c*-l+d*(1-l),0,0,j+c*-j+.143*d,k+c*(1-k)+.14*d,l+c*-l+d*-.283,0,0,j+c*-j+d*-(1-j),k+c*-k+d*k,l+c*(1-l)+d*l,0,0,0,0,0,1,0,0,0,0,0,1],a)},q=function(a,b){return isNaN(b)?a:(b+=.01,m([b,0,0,0,128*(1-b),0,b,0,0,128*(1-b),0,0,b,0,128*(1-b),0,0,0,1,0],a))},r=function(a,b,c){if(!f&&(f=window.ColorMatrixFilter||window.createjs.ColorMatrixFilter,!f))throw"EaselPlugin error: The EaselJS ColorMatrixFilter JavaScript file wasn't loaded.";for(var g,h,j,k,d=a.filters||[],e=d.length;--e>-1;)if(d[e]instanceof f){j=d[e];break}for(j||(j=new f(i.slice()),d.push(j),a.filters=d),k=j.clone(),h=g=k.matrix||i,null!=b.colorize&&(g=o(g,b.colorize,Number(b.colorizeAmount))),null!=b.contrast&&(g=q(g,Number(b.contrast))),null!=b.hue&&(g=p(g,Number(b.hue))),null!=b.saturation&&(g=n(g,Number(b.saturation))),e=g.length;--e>-1;)g[e]!==h[e]&&c._addTween(h,e,h[e],g[e],"easel_colorMatrixFilter");if(c._overwriteProps.push("easel_colorMatrixFilter"),!a.cacheID)throw"EaselPlugin warning: for filters to display in EaselJS, you must call the object's cache() method first. "+a;c._matrix=h},s=function(a){return""===a||null==a||"none"===a?t.transparent:t[a]?t[a]:"number"==typeof a?[a>>16,255&a>>8,255&a]:"#"===a.charAt(0)?(4===a.length&&(a="#"+a.charAt(1)+a.charAt(1)+a.charAt(2)+a.charAt(2)+a.charAt(3)+a.charAt(3)),a=parseInt(a.substr(1),16),[a>>16,255&a>>8,255&a]):a.match(d)||t.transparent},t={aqua:[0,255,255],lime:[0,255,0],silver:[192,192,192],black:[0,0,0],maroon:[128,0,0],teal:[0,128,128],blue:[0,0,255],navy:[0,0,128],white:[255,255,255],fuchsia:[255,0,255],olive:[128,128,0],yellow:[255,255,0],orange:[255,165,0],gray:[128,128,128],purple:[128,0,128],green:[0,128,0],red:[255,0,0],pink:[255,192,203],cyan:[0,255,255],transparent:[255,255,255,0]};return c.constructor=b,b.API=2,b.version="0.1.3",c._onInitTween=function(a,b){this._target=a;var d,e,f,g;for(d in b)"colorFilter"===d||"tint"===d||"tintAmount"===d||"exposure"===d||"brightness"===d?f||(h(a,b.colorFilter||b,this),f=!0):"saturation"===d||"contrast"===d||"hue"===d||"colorize"===d||"colorizeAmount"===d?g||(r(a,b.colorMatrixFilter||b,this),g=!0):null!=a[d]&&(this._firstPT=e={_next:this._firstPT,t:a,p:d,f:"function"==typeof a[d],n:d,pr:0,type:0},e.s=e.f?a[d.indexOf("set")||"function"!=typeof a["get"+d.substr(3)]?d:"get"+d.substr(3)]():parseFloat(a[d]),e.c="number"==typeof b[d]?b[d]-e.s:"string"==typeof b[d]?parseFloat(b[d].split("=").join("")):0,e._next&&(e._next._prev=e));return!0},c.setRatio=function(a){for(var d,b=this._firstPT,c=1e-6;b;)d=b.c*a+b.s,b.r?d=d+(d>0?.5:-.5)>>0:c>d&&d>-c&&(d=0),b.f?b.t[b.p](d):b.t[b.p]=d,b=b._next;this._target.cacheID&&this._target.updateCache()},a.activate([b]),b},!0)}),window._gsDefine&&_gsQueue.pop()();\ No newline at end of filediff --git a/src/minified/plugins/RoundPropsPlugin.min.js b/src/minified/plugins/RoundPropsPlugin.min.jsindex 5fa2e00..537d06d 100755--- a/src/minified/plugins/RoundPropsPlugin.min.js+++ b/src/minified/plugins/RoundPropsPlugin.min.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.31* DATE: 2012-11-19* JavaScript (ActionScript 3 and 2 also available)diff --git a/src/minified/plugins/ScrollToPlugin.min.js b/src/minified/plugins/ScrollToPlugin.min.jsindex 13e5041..0f4468c 100755--- a/src/minified/plugins/ScrollToPlugin.min.js+++ b/src/minified/plugins/ScrollToPlugin.min.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.521* DATE: 2013-01-16* JavaScriptdiff --git a/src/uncompressed/TweenMax.js b/src/uncompressed/TweenMax.jsindex cf2d570..8bcbf35 100755--- a/src/uncompressed/TweenMax.js+++ b/src/uncompressed/TweenMax.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.8.0* DATE: 2013-01-20* JavaScript (ActionScript 3 and 2 also available)diff --git a/src/uncompressed/plugins/BezierPlugin.js b/src/uncompressed/plugins/BezierPlugin.jsindex c9f6b10..a69b55a 100755--- a/src/uncompressed/plugins/BezierPlugin.js+++ b/src/uncompressed/plugins/BezierPlugin.js@@ -1,4 +1,4 @@-/**+/*!* VERSION: beta 1.161* DATE: 2013-01-16* JavaScript (also available in AS3 and AS2)diff --git a/src/uncompressed/plugins/EaselPlugin.js b/src/uncompressed/plugins/EaselPlugin.jsindex c14062d..15118cf 100755--- a/src/uncompressed/plugins/EaselPlugin.js+++ b/src/uncompressed/plugins/EaselPlugin.js@@ -1,6 +1,6 @@/**- * VERSION: beta 0.12- * DATE: 2013-01-13+ * VERSION: beta 0.1.3+ * DATE: 2013-01-26* JavaScript* UPDATES AND DOCS AT: http://www.greensock.com*@@ -20,7 +20,7 @@},p = EaselPlugin.prototype = new TweenPlugin("easel", -1),_numExp = /(\d|\.)+/g,- _ColorFilter,+ _ColorFilter, _ColorMatrixFilter,_colorProps = ["redMultiplier","greenMultiplier","blueMultiplier","alphaMultiplier","redOffset","greenOffset","blueOffset","alphaOffset"],@@ -80,6 +80,121 @@throw("EaselPlugin warning: for filters to display in EaselJS, you must call the object's cache() method first. "+t);}},++ _idMatrix = [1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],+ _lumR = 0.212671,+ _lumG = 0.715160,+ _lumB = 0.072169,++ _applyMatrix = function(m, m2) {+ if (!(m instanceof Array) || !(m2 instanceof Array)) {+ return m2;+ }+ var temp = [],+ i = 0,+ z = 0,+ y, x;+ for (y = 0; y < 4; y++) {+ for (x = 0; x < 5; x++) {+ z = (x === 4) ? m[i + 4] : 0;+ temp[i + x] = m[i] * m2[x] + m[i+1] * m2[x + 5] + m[i+2] * m2[x + 10] + m[i+3] * m2[x + 15] + z;+ }+ i += 5;+ }+ return temp;+ },++ _setSaturation = function(m, n) {+ if (isNaN(n)) {+ return m;+ }+ var inv = 1 - n,+ r = inv * _lumR,+ g = inv * _lumG,+ b = inv * _lumB;+ return _applyMatrix([r + n, g, b, 0, 0, r, g + n, b, 0, 0, r, g, b + n, 0, 0, 0, 0, 0, 1, 0], m);+ },++ _colorize = function(m, color, amount) {+ if (isNaN(amount)) {+ amount = 1;+ }+ var c = _parseColor(color),+ r = c[0] / 255,+ g = c[1] / 255,+ b = c[2] / 255,+ inv = 1 - amount;+ return _applyMatrix([inv + amount * r * _lumR, amount * r * _lumG, amount * r * _lumB, 0, 0, amount * g * _lumR, inv + amount * g * _lumG, amount * g * _lumB, 0, 0, amount * b * _lumR, amount * b * _lumG, inv + amount * b * _lumB, 0, 0, 0, 0, 0, 1, 0], m);+ },++ _setHue = function(m, n) {+ if (isNaN(n)) {+ return m;+ }+ n *= Math.PI / 180;+ var c = Math.cos(n),+ s = Math.sin(n);+ return _applyMatrix([(_lumR + (c * (1 - _lumR))) + (s * (-_lumR)), (_lumG + (c * (-_lumG))) + (s * (-_lumG)), (_lumB + (c * (-_lumB))) + (s * (1 - _lumB)), 0, 0, (_lumR + (c * (-_lumR))) + (s * 0.143), (_lumG + (c * (1 - _lumG))) + (s * 0.14), (_lumB + (c * (-_lumB))) + (s * -0.283), 0, 0, (_lumR + (c * (-_lumR))) + (s * (-(1 - _lumR))), (_lumG + (c * (-_lumG))) + (s * _lumG), (_lumB + (c * (1 - _lumB))) + (s * _lumB), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], m);+ },++ _setContrast = function(m, n) {+ if (isNaN(n)) {+ return m;+ }+ n += 0.01;+ return _applyMatrix([n,0,0,0,128 * (1 - n), 0,n,0,0,128 * (1 - n), 0,0,n,0,128 * (1 - n), 0,0,0,1,0], m);+ },++ _parseColorMatrixFilter = function(t, v, pg) {+ if (!_ColorMatrixFilter) {+ _ColorMatrixFilter = (window.ColorMatrixFilter || window.createjs.ColorMatrixFilter);+ if (!_ColorMatrixFilter) {+ throw("EaselPlugin error: The EaselJS ColorMatrixFilter JavaScript file wasn't loaded.");+ }+ }+ var filters = t.filters || [],+ i = filters.length,+ matrix, startMatrix, s, e, p;+ while (--i > -1) {+ if (filters[i] instanceof _ColorMatrixFilter) {+ s = filters[i];+ break;+ }+ }+ if (!s) {+ s = new _ColorMatrixFilter(_idMatrix.slice());+ filters.push(s);+ t.filters = filters;+ }+ e = s.clone();+ startMatrix = matrix = e.matrix || _idMatrix;+ if (v.colorize != null) {+ matrix = _colorize(matrix, v.colorize, Number(v.colorizeAmount));+ }+ if (v.contrast != null) {+ matrix = _setContrast(matrix, Number(v.contrast));+ }+ if (v.hue != null) {+ matrix = _setHue(matrix, Number(v.hue));+ }+ if (v.saturation != null) {+ matrix = _setSaturation(matrix, Number(v.saturation));+ }++ i = matrix.length;+ while (--i > -1) {+ if (matrix[i] !== startMatrix[i]) {+ pg._addTween(startMatrix, i, startMatrix[i], matrix[i], "easel_colorMatrixFilter");+ }+ }++ pg._overwriteProps.push("easel_colorMatrixFilter");+ if (!t.cacheID) {+ throw("EaselPlugin warning: for filters to display in EaselJS, you must call the object's cache() method first. "+t);+ }++ pg._matrix = startMatrix;+ },_parseColor = function(color) {if (color === "" || color == null || color === "none") {@@ -94,9 +209,8 @@}color = parseInt(color.substr(1), 16);return [color >> 16, (color >> 8) & 255, color & 255];- } else {- return color.match(_numExp) || _colorLookup.transparent;}+ return color.match(_numExp) || _colorLookup.transparent;},_colorLookup = {aqua:[0,255,255],lime:[0,255,0],@@ -121,18 +235,25 @@p.constructor = EaselPlugin;EaselPlugin.API = 2;+ EaselPlugin.version = "0.1.3";p._onInitTween = function(target, value, tween) {this._target = target;- var p, pt, tint;+ var p, pt, tint, colorMatrix;for (p in value) {-+if (p === "colorFilter" || p === "tint" || p === "tintAmount" || p === "exposure" || p === "brightness") {if (!tint) {_parseColorFilter(target, value.colorFilter || value, this);tint = true;}-++ } else if (p === "saturation" || p === "contrast" || p === "hue" || p === "colorize" || p === "colorizeAmount") {+ if (!colorMatrix) {+ _parseColorMatrixFilter(target, value.colorMatrixFilter || value, this);+ colorMatrix = true;+ }+} else if (target[p] != null) {this._firstPT = pt = {_next:this._firstPT, t:target, p:p, f:(typeof(target[p]) === "function"), n:p, pr:0, type:0};pt.s = (!pt.f) ? parseFloat(target[p]) : target[ ((p.indexOf("set") || typeof(target["get" + p.substr(3)]) !== "function") ? p : "get" + p.substr(3)) ]();@@ -149,11 +270,15 @@//gets called every time the tween updates, passing the new ratio (typically a value between 0 and 1, but not always (for example, if an Elastic.easeOut is used, the value can jump above 1 mid-tween). It will always start and 0 and end at 1.p.setRatio = function(v) {- var pt = this._firstPT, val;+ var pt = this._firstPT,+ min = 0.000001,+ val;while (pt) {val = pt.c * v + pt.s;if (pt.r) {val = (val + ((val > 0) ? 0.5 : -0.5)) >> 0; //about 4x faster than Math.round()+ } else if (val < min && val > -min) {+ val = 0;}if (pt.f) {pt.t[pt.p](val);