parallaxis/voices/js/plugins/BezierPlugin.min.js

27 lines
7.7 KiB
JavaScript
Raw Normal View History

/*!
* VERSION: beta 1.15
* DATE: 2012-12-14
* JavaScript (also available in AS3 and AS2)
* UPDATES AND DOCS AT: http://www.greensock.com
*
* Copyright (c) 2008-2013, GreenSock. All rights reserved.
* This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for
* Club GreenSock members, the software agreement that was issued with your membership.
*
* @author: Jack Doyle, jack@greensock.com
*/
(window._gsQueue||(window._gsQueue=[])).push(function(){_gsDefine("plugins.BezierPlugin",["plugins.TweenPlugin"],function(F){var z=function(){F.call(this,"bezier",-1);this._overwriteProps.pop();this._func={};this._round={}},E=z.prototype=new F("bezier",1),I=180/Math.PI,J=Math.PI/180,A=[],B=[],C=[],G={},D=function(a,c,g,p){this.a=a;this.b=c;this.c=g;this.d=p;this.da=p-a;this.ca=g-a;this.ba=c-a},K=z.bezierThrough=function(a,c,g,p,j,b){var d={},f=[],e,k,q;j="string"===typeof j?","+j+",":",x,y,z,left,top,right,bottom,marginTop,marginLeft,marginRight,marginBottom,paddingLeft,paddingTop,paddingRight,paddingBottom,backgroundPosition,backgroundPosition_y,";
null==c&&(c=1);for(k in a[0])f.push(k);A.length=B.length=C.length=0;for(e=f.length;-1<--e;){k=f[e];G[k]=-1!==j.indexOf(","+k+",");q=d;var s=k,n;n=a;var m=k,w=G[k],l=b,t=[],r=void 0,h=void 0,v=void 0,u=void 0,x=void 0,r=void 0;if(l){n=[l].concat(n);for(h=n.length;-1<--h;)if("string"===typeof(r=n[h][m]))"="===r.charAt(1)&&(n[h][m]=l[m]+Number(r.charAt(0)+r.substr(2)))}r=n.length-2;if(0>r)t[0]=new D(n[0][m],0,0,n[-1>r?0:1][m]);else{for(h=0;h<r;h++)v=n[h][m],u=n[h+1][m],t[h]=new D(v,0,0,u),w&&(x=n[h+
2][m],A[h]=(A[h]||0)+(u-v)*(u-v),B[h]=(B[h]||0)+(x-u)*(x-u));t[h]=new D(n[h][m],0,0,n[h+1][m])}n=t;q[s]=n}for(e=A.length;-1<--e;)A[e]=Math.sqrt(A[e]),B[e]=Math.sqrt(B[e]);if(!p){for(e=f.length;-1<--e;)if(G[k]){a=d[f[e]];q=a.length-1;for(j=0;j<q;j++)b=a[j+1].da/B[j]+a[j].da/A[j],C[j]=(C[j]||0)+b*b}for(e=C.length;-1<--e;)C[e]=Math.sqrt(C[e])}for(e=f.length;-1<--e;){k=f[e];a=d[k];j=c;b=g;q=p;k=G[k];s=a.length-1;n=0;for(var m=a[0].a,y=x=u=l=r=u=v=r=h=v=t=l=w=void 0,w=0;w<s;w++)h=a[n],l=h.a,t=h.d,v=a[n+
1].d,k?(u=A[w],x=B[w],y=0.25*(x+u)*j/(q?0.5:C[w]||0.5),r=t-(t-l)*(q?0.5*j:y/u),v=t+(v-t)*(q?0.5*j:y/x),u=t-(r+(v-r)*(3*u/(u+x)+0.5)/4)):(r=t-0.5*(t-l)*j,v=t+0.5*(v-t)*j,u=t-(r+v)/2),r+=u,v+=u,h.c=r,h.b=0!==w?m:m=h.a+0.6*(h.c-h.a),h.da=t-l,h.ca=r-l,h.ba=m-l,b?(l=H(l,m,r,t),a.splice(n,1,l[0],l[1],l[2],l[3]),n+=4):n++,m=v;h=a[n];h.b=m;h.c=m+0.4*(h.d-m);h.da=h.d-h.a;h.ca=h.c-h.a;h.ba=m-h.a;b&&(l=H(h.a,m,h.c,h.d),a.splice(n,1,l[0],l[1],l[2],l[3]))}return d},H=z.cubicToQuadratic=function(a,c,g,p){var j=
{a:a},b={},d={},f={c:p},e=(a+c)/2,k=(c+g)/2;g=(g+p)/2;c=(e+k)/2;var k=(k+g)/2,q=(k-c)/8;j.b=e+(a-e)/4;b.b=c+q;j.c=b.a=(j.b+b.b)/2;b.c=d.a=(c+k)/2;d.b=k-q;f.b=g+(p-g)/4;d.c=f.a=(d.b+f.b)/2;return[j,b,d,f]};z.quadraticToCubic=function(a,c,g){return new D(a,(2*c+a)/3,(2*c+g)/3,g)};E.constructor=z;z.API=2;z._cssRegister=function(){var a=window.com.greensock.plugins.CSSPlugin;if(a){var a=a._internals,c=a._parseToProxy,g=a._setPluginRatio,p=a.CSSPropTween;a._registerComplexSpecialProp("bezier",null,function(a,
b,d,f,e,k){b instanceof Array&&(b={values:b});k=new z;d=b.values;var q=d.length-1,s=[],n={},m,w,l;if(0>q)return e;for(m=0;m<=q;m++)l=c(a,d[m],f,e,k,q!==m),s[m]=l.end;for(w in b)n[w]=b[w];n.values=s;e=new p(a,"bezier",0,0,l.pt,2);e.data=l;e.plugin=k;e.setRatio=g;0===n.autoRotate&&(n.autoRotate=!0);n.autoRotate&&!(n.autoRotate instanceof Array)&&(m=!0===n.autoRotate?0:Number(n.autoRotate)*J,n.autoRotate=null!=l.end.left?[["left","top","rotation",m,!0]]:null!=l.end.x?[["x","y","rotation",m,!0]]:!1);
n.autoRotate&&(f._transform||f._enableTransforms(!1),l.autoRotate=f._target._gsTransform);k._onInitTween(l.proxy,n,f._tween);return e})}};E._onInitTween=function(a,c,g){this._target=a;c instanceof Array&&(c={values:c});this._props=[];this._timeRes=null==c.timeResolution?6:parseInt(c.timeResolution);var p=c.values||[],j={},b=p[0];g=c.autoRotate||g.vars.orientToBezier;var d,f,e;this._autoRotate=g?g instanceof Array?g:[["x","y","rotation",!0===g?0:Number(g)||0]]:null;for(d in b)this._props.push(d);for(b=
this._props.length;-1<--b;)d=this._props[b],this._overwriteProps.push(d),g=this._func[d]="function"===typeof a[d],j[d]=!g?parseFloat(a[d]):a[d.indexOf("set")||"function"!==typeof a["get"+d.substr(3)]?d:"get"+d.substr(3)](),e||j[d]!==p[0][d]&&(e=j);if("cubic"!==c.type&&"quadratic"!==c.type&&"soft"!==c.type)j=K(p,isNaN(c.curviness)?1:c.curviness,!1,"thruBasic"===c.type,c.correlate,e);else{g=(g=c.type)||"soft";c={};e="cubic"===g?3:2;g="soft"===g;var b=[],k,q,s,n,m,w,l,t,r;g&&j&&(p=[j].concat(p));if(null==
p||p.length<e+1)throw"invalid Bezier data";for(q in p[0])b.push(q);for(w=b.length;-1<--w;){q=b[w];c[q]=m=[];r=0;t=p.length;for(l=0;l<t;l++)k=null==j?p[l][q]:"string"===typeof(s=p[l][q])&&"="===s.charAt(1)?j[q]+Number(s.charAt(0)+s.substr(2)):Number(s),g&&1<l&&l<t-1&&(m[r++]=(k+m[r-2])/2),m[r++]=k;t=r-e+1;for(l=r=0;l<t;l+=e)k=m[l],q=m[l+1],s=m[l+2],n=2===e?0:m[l+3],m[r++]=s=3===e?new D(k,q,s,n):new D(k,(2*q+k)/3,(2*q+s)/3,s);m.length=r}j=c}this._beziers=j;this._segCount=this._beziers[d].length;if(this._timeRes){b=
this._beziers;d=this._timeRes;d=d>>0||6;j=[];q=[];p=s=0;c=d-1;e=[];g=[];for(f in b){k=b[f];m=j;w=d;l=1/w;t=k.length;for(var h=void 0,v=void 0,u=n=r=v=void 0,x=h=void 0,y=void 0,y=u=void 0;-1<--t;){u=k[t];v=u.a;r=u.d-v;n=u.c-v;u=u.b-v;v=0;for(x=1;x<=w;x++)h=l*x,y=1-h,h=v-(v=(h*h*r+3*y*(h*n+y*u))*h),y=t*w+x-1,m[y]=(m[y]||0)+h*h}}b=j.length;for(f=0;f<b;f++)s+=Math.sqrt(j[f]),k=f%d,g[k]=s,k===c&&(p+=s,k=f/d>>0,e[k]=g,q[k]=p,s=0,g=[]);this._length=p;this._lengths=q;this._segments=e;this._l1=this._li=this._s1=
this._si=0;this._l2=this._lengths[0];this._curSeg=this._segments[0];this._s2=this._curSeg[0];this._prec=1/this._curSeg.length}if(g=this._autoRotate){g[0]instanceof Array||(this._autoRotate=g=[g]);for(b=g.length;-1<--b;)for(f=0;3>f;f++)d=g[b][f],this._func[d]="function"===typeof a[d]?a[d.indexOf("set")||"function"!==typeof a["get"+d.substr(3)]?d:"get"+d.substr(3)]:!1}return!0};E.setRatio=function(a){var c=this._segCount,g=this._func,p=this._target,j,b,d,f,e;if(this._timeRes){j=this._lengths;f=this._curSeg;
a*=this._length;b=this._li;if(a>this._l2&&b<c-1){for(c-=1;b<c&&(this._l2=j[++b])<=a;);this._l1=j[b-1];this._li=b;this._curSeg=f=this._segments[b];this._s2=f[this._s1=this._si=0]}else if(a<this._l1&&0<b){for(;0<b&&(this._l1=j[--b])>=a;);0===b&&a<this._l1?this._l1=0:b++;this._l2=j[b];this._li=b;this._curSeg=f=this._segments[b];this._s1=f[(this._si=f.length-1)-1]||0;this._s2=f[this._si]}j=b;a-=this._l1;b=this._si;if(a>this._s2&&b<f.length-1){for(c=f.length-1;b<c&&(this._s2=f[++b])<=a;);this._s1=f[b-
1];this._si=b}else if(a<this._s1&&0<b){for(;0<b&&(this._s1=f[--b])>=a;);0===b&&a<this._s1?this._s1=0:b++;this._s2=f[b];this._si=b}f=(b+(a-this._s1)/(this._s2-this._s1))*this._prec}else j=0>a?0:1<=a?c-1:c*a>>0,f=(a-j*(1/c))*c;c=1-f;for(b=this._props.length;-1<--b;)if(a=this._props[b],d=this._beziers[a][j],e=(f*f*d.da+3*c*(f*d.ca+c*d.ba))*f+d.a,this._round[a]&&(e=e+(0<e?0.5:-0.5)>>0),g[a])p[a](e);else p[a]=e;if(this._autoRotate){var c=this._autoRotate,k,q,s,n,m;for(b=c.length;-1<--b;)a=c[b][2],n=c[b][3]||
0,m=!0===c[b][4]?1:I,d=this._beziers[c[b][0]][j],e=this._beziers[c[b][1]][j],k=d.a+(d.b-d.a)*f,q=d.b+(d.c-d.b)*f,k+=(q-k)*f,q+=(d.c+(d.d-d.c)*f-q)*f,d=e.a+(e.b-e.a)*f,s=e.b+(e.c-e.b)*f,d+=(s-d)*f,s+=(e.c+(e.d-e.c)*f-s)*f,e=Math.atan2(s-d,q-k)*m+n,g[a]?g[a].call(p,e):p[a]=e}};E._roundProps=function(a,c){for(var g=this._overwriteProps,p=g.length;-1<--p;)if(a[g[p]]||a.bezier||a.bezierThrough)this._round[g[p]]=c};E._kill=function(a){var c=this._props,g,p;for(g in this._beziers)if(g in a){delete this._beziers[g];
delete this._func[g];for(p=c.length;-1<--p;)c[p]===g&&c.splice(p,1)}return F.prototype._kill.call(this,a)};F.activate([z]);return z},!0)});window._gsDefine&&_gsQueue.pop()();