MorphSVGPlugin.min.js 12.3 KB
N2Require("MorphSVGPlugin",["GSAP"],[],function(t,e,r){var n,o,i="undefined"!=typeof n&&n.exports&&"undefined"!=typeof global?global:this||window;(i._gsQueue||(i._gsQueue=[])).push(function(){"use strict";var t=Math.PI/180,e=180/Math.PI,r=/[achlmqstvz]|(-?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/gi,n=/(?:(-|-=|\+=)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/gi,o=/(^[#\.]|[a-y][a-z])/gi,a=/[achlmqstvz]/gi,s=/[\+\-]?\d*\.?\d+e[\+\-]?\d+/gi,l=i._gsDefine.globals.TweenLite,h=function(t){i.console&&console.log(t)},u=function(e,r){var n,o,i,a,s,l,h=Math.ceil(Math.abs(r)/90),u=0,c=[];for(e*=t,r*=t,n=r/h,o=4/3*Math.sin(n/2)/(1+Math.cos(n/2)),l=0;h>l;l++)i=e+l*n,a=Math.cos(i),s=Math.sin(i),c[u++]=a-o*s,c[u++]=s+o*a,i+=n,a=Math.cos(i),s=Math.sin(i),c[u++]=a+o*s,c[u++]=s-o*a,c[u++]=a,c[u++]=s;return c},c=function(r,n,o,i,a,s,l,h,c){if(r!==h||n!==c){o=Math.abs(o),i=Math.abs(i);var f=a%360*t,g=Math.cos(f),p=Math.sin(f),d=(r-h)/2,v=(n-c)/2,b=g*d+p*v,M=-p*d+g*v,m=o*o,A=i*i,y=b*b,x=M*M,N=y/m+x/A;N>1&&(o=Math.sqrt(N)*o,i=Math.sqrt(N)*i,m=o*o,A=i*i);var z=s===l?-1:1,P=(m*A-m*x-A*y)/(m*x+A*y);0>P&&(P=0);var S=z*Math.sqrt(P),w=S*(o*M/i),T=S*-(i*b/o),G=(r+h)/2,L=(n+c)/2,q=G+(g*w-p*T),_=L+(p*w+g*T),I=(b-w)/o,Y=(M-T)/i,C=(-b-w)/o,B=(-M-T)/i,R=Math.sqrt(I*I+Y*Y),V=I;z=0>Y?-1:1;var X=z*Math.acos(V/R)*e;R=Math.sqrt((I*I+Y*Y)*(C*C+B*B)),V=I*C+Y*B,z=0>I*B-Y*C?-1:1;var j=z*Math.acos(V/R)*e;!l&&j>0?j-=360:l&&0>j&&(j+=360),j%=360,X%=360;var F,H,O,D=u(X,j),Q=g*o,E=p*o,U=p*-i,W=g*i,Z=D.length-2;for(F=0;Z>F;F+=2)H=D[F],O=D[F+1],D[F]=H*Q+O*U+q,D[F+1]=H*E+O*W+_;return D[D.length-2]=h,D[D.length-1]=c,D}},f=function(t){var e,n,o,i,a,l,u,f,g,p,d,v,b,M=(t+"").replace(s,function(t){var e=+t;return 1e-4>e&&e>-1e-4?0:e}).match(r)||[],m=[],A=0,y=0,x=M.length,N=2,z=0;if(!t||!isNaN(M[0])||isNaN(M[1]))return h("ERROR: malformed path data: "+t),m;for(e=0;x>e;e++)if(b=a,isNaN(M[e])?(a=M[e].toUpperCase(),l=a!==M[e]):e--,o=+M[e+1],i=+M[e+2],l&&(o+=A,i+=y),0===e&&(f=o,g=i),"M"===a)u&&u.length<8&&(m.length-=1,N=0),A=f=o,y=g=i,u=[o,i],z+=N,N=2,m.push(u),e+=2,a="L";else if("C"===a)u||(u=[0,0]),u[N++]=o,u[N++]=i,l||(A=y=0),u[N++]=A+1*M[e+3],u[N++]=y+1*M[e+4],u[N++]=A+=1*M[e+5],u[N++]=y+=1*M[e+6],e+=6;else if("S"===a)"C"===b||"S"===b?(p=A-u[N-4],d=y-u[N-3],u[N++]=A+p,u[N++]=y+d):(u[N++]=A,u[N++]=y),u[N++]=o,u[N++]=i,l||(A=y=0),u[N++]=A+=1*M[e+3],u[N++]=y+=1*M[e+4],e+=4;else if("Q"===a)p=o-A,d=i-y,u[N++]=A+2*p/3,u[N++]=y+2*d/3,l||(A=y=0),A+=1*M[e+3],y+=1*M[e+4],p=o-A,d=i-y,u[N++]=A+2*p/3,u[N++]=y+2*d/3,u[N++]=A,u[N++]=y,e+=4;else if("T"===a)p=A-u[N-4],d=y-u[N-3],u[N++]=A+p,u[N++]=y+d,p=A+1.5*p-o,d=y+1.5*d-i,u[N++]=o+2*p/3,u[N++]=i+2*d/3,u[N++]=A=o,u[N++]=y=i,e+=2;else if("H"===a)i=y,u[N++]=A+(o-A)/3,u[N++]=y+(i-y)/3,u[N++]=A+2*(o-A)/3,u[N++]=y+2*(i-y)/3,u[N++]=A=o,u[N++]=i,e+=1;else if("V"===a)i=o,o=A,l&&(i+=y-A),u[N++]=o,u[N++]=y+(i-y)/3,u[N++]=o,u[N++]=y+2*(i-y)/3,u[N++]=o,u[N++]=y=i,e+=1;else if("L"===a||"Z"===a)"Z"===a&&(o=f,i=g,u.closed=!0),("L"===a||Math.abs(A-o)>.5||Math.abs(y-i)>.5)&&(u[N++]=A+(o-A)/3,u[N++]=y+(i-y)/3,u[N++]=A+2*(o-A)/3,u[N++]=y+2*(i-y)/3,u[N++]=o,u[N++]=i,"L"===a&&(e+=2)),A=o,y=i;else if("A"===a){if(v=c(A,y,1*M[e+1],1*M[e+2],1*M[e+3],1*M[e+4],1*M[e+5],(l?A:0)+1*M[e+6],(l?y:0)+1*M[e+7]))for(n=0;n<v.length;n++)u[N++]=v[n];A=u[N-2],y=u[N-1],e+=7}else h("Error: malformed path data: "+t);return m.totalPoints=z+N,m},g=function(t,e){var r,n,o,i,a,s,l,h,u,c,f,g,p,d,v=0,b=.999999,M=t.length,m=e/((M-2)/6);for(p=2;M>p;p+=6)for(v+=m;v>b;)r=t[p-2],n=t[p-1],o=t[p],i=t[p+1],a=t[p+2],s=t[p+3],l=t[p+4],h=t[p+5],d=1/(Math.floor(v)+1),u=r+(o-r)*d,f=o+(a-o)*d,u+=(f-u)*d,f+=(a+(l-a)*d-f)*d,c=n+(i-n)*d,g=i+(s-i)*d,c+=(g-c)*d,g+=(s+(h-s)*d-g)*d,t.splice(p,4,r+(o-r)*d,n+(i-n)*d,u,c,u+(f-u)*d,c+(g-c)*d,f,g,a+(l-a)*d,s+(h-s)*d),p+=6,M+=6,v--;return t},p=function(t){var e,r,n,o,i="",a=t.length,s=100;for(r=0;a>r;r++){for(o=t[r],i+="M"+o[0]+","+o[1]+" C",e=o.length,n=2;e>n;n++)i+=(o[n++]*s|0)/s+","+(o[n++]*s|0)/s+" "+(o[n++]*s|0)/s+","+(o[n++]*s|0)/s+" "+(o[n++]*s|0)/s+","+(o[n]*s|0)/s+" ";o.closed&&(i+="z")}return i},d=function(t){for(var e=[],r=t.length-1,n=0;--r>-1;)e[n++]=t[r],e[n++]=t[r+1],r--;for(r=0;n>r;r++)t[r]=e[r];t.reversed=!t.reversed},v=function(t){var e,r=t.length,n=0,o=0;for(e=0;r>e;e++)n+=t[e++],o+=t[e];return[n/(r/2),o/(r/2)]},b=function(t){var e,r,n,o=t.length,i=t[0],a=i,s=t[1],l=s;for(n=6;o>n;n+=6)e=t[n],r=t[n+1],e>i?i=e:a>e&&(a=e),r>s?s=r:l>r&&(l=r);return t.centerX=(i+a)/2,t.centerY=(s+l)/2,t.size=(i-a)*(s-l)},M=function(t){for(var e,r,n,o,i,a=t.length,s=t[0][0],l=s,h=t[0][1],u=h;--a>-1;)for(i=t[a],e=i.length,o=6;e>o;o+=6)r=i[o],n=i[o+1],r>s?s=r:l>r&&(l=r),n>h?h=n:u>n&&(u=n);return t.centerX=(s+l)/2,t.centerY=(h+u)/2,t.size=(s-l)*(h-u)},m=function(t,e){return e.length-t.length},A=function(t,e){var r=t.size||b(t),n=e.size||b(e);return Math.abs(n-r)<(r+n)/20?e.centerX-t.centerX||e.centerY-t.centerY:n-r},y=function(t,e){var r,n,o=t.slice(0),i=t.length,a=i-2;for(e=0|e,r=0;i>r;r++)n=(r+e)%a,t[r++]=o[n],t[r]=o[n+1]},x=function(t,e,r,n,o){var i,a,s,l,h=t.length,u=0,c=h-2;for(r*=6,a=0;h>a;a+=6)i=(a+r)%c,l=t[i]-(e[a]-n),s=t[i+1]-(e[a+1]-o),u+=Math.sqrt(s*s+l*l);return u},N=function(t,e,r){var n,o,i,a=t.length,s=v(t),l=v(e),h=l[0]-s[0],u=l[1]-s[1],c=x(t,e,0,h,u),f=0;for(i=6;a>i;i+=6)o=x(t,e,i/6,h,u),c>o&&(c=o,f=i);if(r)for(n=t.slice(0),d(n),i=6;a>i;i+=6)o=x(n,e,i/6,h,u),c>o&&(c=o,f=-i);return f/6},z=function(t,e,r){for(var n,o,i,a,s,l,h=t.length,u=99999999999,c=0,f=0;--h>-1;)for(n=t[h],l=n.length,s=0;l>s;s+=6)o=n[s]-e,i=n[s+1]-r,a=Math.sqrt(o*o+i*i),u>a&&(u=a,c=n[s],f=n[s+1]);return[c,f]},P=function(t,e,r,n,o,i){var a,s,l,h,u,c=e.length,f=0,g=Math.min(t.size||b(t),e[r].size||b(e[r]))*n,p=999999999999,d=t.centerX+o,v=t.centerY+i;for(s=r;c>s&&(a=e[s].size||b(e[s]),!(g>a));s++)l=e[s].centerX-d,h=e[s].centerY-v,u=Math.sqrt(l*l+h*h),p>u&&(f=s,p=u);return u=e[f],e.splice(f,1),u},S=function(t,e,r,n){var o,i,a,s,l,u,c,f=e.length-t.length,p=f>0?e:t,v=f>0?t:e,x=0,S="complexity"===n?m:A,w="position"===n?0:"number"==typeof n?n:.8,T=v.length,G="object"==typeof r&&r.push?r.slice(0):[r],L="reverse"===G[0]||G[0]<0,q="log"===r;if(v[0]){if(p.length>1&&(t.sort(S),e.sort(S),u=p.size||M(p),u=v.size||M(v),u=p.centerX-v.centerX,c=p.centerY-v.centerY,S===A))for(T=0;T<v.length;T++)p.splice(T,0,P(v[T],p,T,w,u,c));if(f)for(0>f&&(f=-f),p[0].length>v[0].length&&g(v[0],(p[0].length-v[0].length)/6|0),T=v.length;f>x;)s=p[T].size||b(p[T]),a=z(v,p[T].centerX,p[T].centerY),s=a[0],l=a[1],v[T++]=[s,l,s,l,s,l,s,l],v.totalPoints+=8,x++;for(T=0;T<t.length;T++)o=e[T],i=t[T],f=o.length-i.length,0>f?g(o,-f/6|0):f>0&&g(i,f/6|0),L&&!i.reversed&&d(i),r=G[T]||0===G[T]?G[T]:"auto",r&&(i.closed||Math.abs(i[0]-i[i.length-2])<.5&&Math.abs(i[1]-i[i.length-1])<.5?"auto"===r||"log"===r?(G[T]=r=N(i,o,0===T),0>r&&(L=!0,d(i),r=-r),y(i,6*r)):"reverse"!==r&&(T&&0>r&&d(i),y(i,6*(0>r?-r:r))):!L&&("auto"===r&&Math.abs(o[0]-i[0])+Math.abs(o[1]-i[1])+Math.abs(o[o.length-2]-i[i.length-2])+Math.abs(o[o.length-1]-i[i.length-1])>Math.abs(o[0]-i[i.length-2])+Math.abs(o[1]-i[i.length-1])+Math.abs(o[o.length-2]-i[0])+Math.abs(o[o.length-1]-i[1])||r%2)?(d(i),G[T]=-1,L=!0):"auto"===r?G[T]=0:"reverse"===r&&(G[T]=-1),i.closed!==o.closed&&(i.closed=o.closed=!1));return q&&h("shapeIndex:["+G.join(",")+"]"),G}},w=function(t,e,r,n){var o=f(t[0]),i=f(t[1]);S(o,i,e||0===e?e:"auto",r)&&(t[0]=p(o),t[1]=p(i),("log"===n||n===!0)&&h('precompile:["'+t[0]+'","'+t[1]+'"]'))},T=function(t,e,r){return e||r||t||0===t?function(n){w(n,t,e,r)}:w},G=function(t,e){if(!e)return t;var r,o,i,a=t.match(n)||[],s=a.length,l="";for("reverse"===e?(o=s-1,r=-2):(o=(2*(parseInt(e,10)||0)+1+100*s)%s,r=2),i=0;s>i;i+=2)l+=a[o-1]+","+a[o]+" ",o=(o+r)%s;return l},L=function(t,e){var r,n,o,i,a,s,l,h=0,u=parseFloat(t[0]),c=parseFloat(t[1]),f=u+","+c+" ",g=.999999;for(o=t.length,r=.5*e/(.5*o-1),n=0;o-2>n;n+=2){if(h+=r,s=parseFloat(t[n+2]),l=parseFloat(t[n+3]),h>g)for(a=1/(Math.floor(h)+1),i=1;h>g;)f+=(u+(s-u)*a*i).toFixed(2)+","+(c+(l-c)*a*i).toFixed(2)+" ",h--,i++;f+=s+","+l+" ",u=s,c=l}return f},q=function(t){var e=t[0].match(n)||[],r=t[1].match(n)||[],o=r.length-e.length;o>0?t[0]=L(e,o):t[1]=L(r,-o)},_=function(t){return isNaN(t)?q:function(e){q(e),e[1]=G(e[1],parseInt(t,10))}},I=function(t,e){var r,n=i.document.createElementNS("http://www.w3.org/2000/svg","path"),o=Array.prototype.slice.call(t.attributes),a=o.length;for(e=","+e+",";--a>-1;)r=o[a].nodeName.toLowerCase(),-1===e.indexOf(","+r+",")&&n.setAttributeNS(null,r,o[a].nodeValue);return n},Y=function(t,e){var r,o,i,a,s,l,h,u,c,f,g,p,d,v,b,M,m,A,y,x,N,z=t.tagName.toLowerCase(),P=.552284749831;return"path"!==z&&t.getBBox?(l=I(t,"x,y,width,height,cx,cy,rx,ry,r,x1,x2,y1,y2,points"),"rect"===z?(a=+t.getAttribute("rx")||0,s=+t.getAttribute("ry")||0,o=+t.getAttribute("x")||0,i=+t.getAttribute("y")||0,f=(+t.getAttribute("width")||0)-2*a,g=(+t.getAttribute("height")||0)-2*s,a||s?(p=o+a*(1-P),d=o+a,v=d+f,b=v+a*P,M=v+a,m=i+s*(1-P),A=i+s,y=A+g,x=y+s*P,N=y+s,r="M"+M+","+A+" V"+y+" C"+[M,x,b,N,v,N,v-(v-d)/3,N,d+(v-d)/3,N,d,N,p,N,o,x,o,y,o,y-(y-A)/3,o,A+(y-A)/3,o,A,o,m,p,i,d,i,d+(v-d)/3,i,v-(v-d)/3,i,v,i,b,i,M,m,M,A].join(",")+"z"):r="M"+(o+f)+","+i+" v"+g+" h"+-f+" v"+-g+" h"+f+"z"):"circle"===z||"ellipse"===z?("circle"===z?(a=s=+t.getAttribute("r")||0,u=a*P):(a=+t.getAttribute("rx")||0,s=+t.getAttribute("ry")||0,u=s*P),o=+t.getAttribute("cx")||0,i=+t.getAttribute("cy")||0,h=a*P,r="M"+(o+a)+","+i+" C"+[o+a,i+u,o+h,i+s,o,i+s,o-h,i+s,o-a,i+u,o-a,i,o-a,i-u,o-h,i-s,o,i-s,o+h,i-s,o+a,i-u,o+a,i].join(",")+"z"):"line"===z?r="M"+(t.getAttribute("x1")||0)+","+(t.getAttribute("y1")||0)+" L"+(t.getAttribute("x2")||0)+","+(t.getAttribute("y2")||0):("polyline"===z||"polygon"===z)&&(c=(t.getAttribute("points")+"").match(n)||[],o=c.shift(),i=c.shift(),r="M"+o+","+i+" L"+c.join(","),"polygon"===z&&(r+=","+o+","+i+"z")),l.setAttribute("d",r),e&&t.parentNode&&(t.parentNode.insertBefore(l,t),t.parentNode.removeChild(t)),l):t},C=function(t,e,r){var i,a,s="string"==typeof t;return(!s||o.test(t)||(t.match(n)||[]).length<3)&&(i=s?l.selector(t):t&&t[0]?t:[t],i&&i[0]?(i=i[0],a=i.nodeName.toUpperCase(),e&&"PATH"!==a&&(i=Y(i,!1),a="PATH"),t=i.getAttribute("PATH"===a?"d":"points")||"",i===r&&(t=i.getAttributeNS(null,"data-original")||t)):(h("WARNING: invalid morph to: "+t),t=!1)),t},B="Use MorphSVGPlugin.convertToPath(elementOrSelectorText) to convert to a path before morphing.",R=i._gsDefine.plugin({propName:"morphSVG",API:2,global:!0,version:"0.8.11",init:function(t,e,r,n){var o,i,s,l,u;return"function"!=typeof t.setAttribute?!1:("function"==typeof e&&(e=e(n,t)),o=t.nodeName.toUpperCase(),u="POLYLINE"===o||"POLYGON"===o,"PATH"===o||u?(i="PATH"===o?"d":"points",("string"==typeof e||e.getBBox||e[0])&&(e={shape:e}),l=C(e.shape||e.d||e.points||"","d"===i,t),u&&a.test(l)?(h("WARNING: a <"+o+"> cannot accept path data. "+B),!1):(l&&(this._target=t,t.getAttributeNS(null,"data-original")||t.setAttributeNS(null,"data-original",t.getAttribute(i)),s=this._addTween(t,"setAttribute",t.getAttribute(i)+"",l+"","morphSVG",!1,i,"object"==typeof e.precompile?function(t){t[0]=e.precompile[0],t[1]=e.precompile[1]}:"d"===i?T(e.shapeIndex,e.map||R.defaultMap,e.precompile):_(e.shapeIndex)),s&&(this._overwriteProps.push("morphSVG"),s.end=l,s.endProp=i)),!0)):(h("WARNING: cannot morph a <"+o+"> SVG element. "+B),!1))},set:function(t){var e;if(this._super.setRatio.call(this,t),1===t)for(e=this._firstPT;e;)e.end&&this._target.setAttribute(e.endProp,e.end),e=e._next}});R.pathFilter=w,R.pointsFilter=q,R.subdivideRawBezier=g,R.defaultMap="size",R.pathDataToRawBezier=function(t){return f(C(t,!0))},R.equalizeSegmentQuantity=S,R.convertToPath=function(t,e){"string"==typeof t&&(t=l.selector(t));for(var r=t&&0!==t.length?t.length&&t[0]&&t[0].nodeType?Array.prototype.slice.call(t,0):[t]:[],n=r.length;--n>-1;)r[n]=Y(r[n],e!==!1);return r},R.pathDataToBezier=function(t,e){var r,n,o,i,a,s,h,u,c=f(C(t,!0))[0]||[],g=0;if(e=e||{},u=e.align||e.relative,i=e.matrix||[1,0,0,1,0,0],a=e.offsetX||0,s=e.offsetY||0,"relative"===u||u===!0?(a-=c[0]*i[0]+c[1]*i[2],s-=c[0]*i[1]+c[1]*i[3],g="+="):(a+=i[4],s+=i[5],u&&(u="string"==typeof u?l.selector(u):u&&u[0]?u:[u],u&&u[0]&&(h=u[0].getBBox()||{x:0,y:0},a-=h.x,s-=h.y))),r=[],o=c.length,i&&"1,0,0,1,0,0"!==i.join(","))for(n=0;o>n;n+=2)r.push({x:g+(c[n]*i[0]+c[n+1]*i[2]+a),y:g+(c[n]*i[1]+c[n+1]*i[3]+s)});else for(n=0;o>n;n+=2)r.push({x:g+(c[n]+a),y:g+(c[n+1]+s)});return r}}),i._gsDefine&&i._gsQueue.pop()(),function(t){"use strict";var e=function(){return(i.GreenSockGlobals||i)[t]};"undefined"!=typeof n&&n.exports?(require("../TweenLite.min.js"),n.exports=e()):"function"==typeof o&&o.amd&&o(["TweenLite"],e)}("MorphSVGPlugin")});