ht-svgtoshape.js 81 KB

123
  1. !function(G,R){"use strict";var K="ht",p=G[K],L=p.Default,E=L.getInternal();E.addMethod(L,{svgToShape:function(s,T){var B=new p.SvgConverter(T);return B.toShape(s)}});var k=p.Context2dProxy=function(g,o){var l=this;l.ctx=g,l.writer=o,l.$1A={a:1,b:0,c:0,d:1,tx:0,ty:0},l.$2A(),l.$3A=!0,l.$4A=16,l.$5A=[];for(var G in CanvasRenderingContext2D.prototype)if("webkitImageSmoothingEnabled"!==G){var N=g[G];if("function"==typeof N)l[G]=function(K,k){return function(){var p=k.apply(g,arguments);return l.handleFunc(K,p,arguments),p}}(G,N);else{var I=R.getOwnPropertyDescriptor(CanvasRenderingContext2D.prototype,G);if(!I.get&&!I.set)continue;!function(b){R.defineProperty(l,b,{get:function(){return g[b]},set:function(S){g[b]=S,l.handleSetter(b,S)}})}(G)}}};k.prototype={},k.prototype.constructor=k,k.prototype.handleFunc=function(L,H,A){var m=this;switch(L){case"save":m.$7A();break;case"restore":m.$8A();break;case"translate":m.$9A.apply(m,A);break;case"rotate":m.$AA.apply(m,A);break;case"scale":m.$BA.apply(m,A);break;case"setTransform":m.$CA.apply(m,A);break;case"transform":m.$DA.apply(m,A);break;case"fillText":case"strokeText":m.$EA(A[0],A[1],A[2],"fillText"===L);break;case"rect":m.$FA.apply(m,A);break;case"fill":m.$10A(!1);break;case"stroke":m.$10A(!0);break;case"moveTo":m.$11A(A[0],A[1]);break;case"lineTo":m.$12A(A[0],A[1]);break;case"beginPath":m.$13A();break;case"closePath":m.$14A();break;case"arc":m.$15A.apply(m,A);break;case"ellipse":m.$16A.apply(m,A);break;case"quadraticCurveTo":m.$17A([{x:A[0],y:A[1]}],A[2],A[3]);break;case"bezierCurveTo":m.$17A([{x:A[0],y:A[1]},{x:A[2],y:A[3]}],A[4],A[5]);break;case"createLinearGradient":H.points=A}},k.prototype.handleSetter=function(){},k.prototype.$7A=function(){var q=this,o={},Y=q.$1A;for(var v in Y)o[v]=Y[v];q.$5A.push(o)},k.prototype.$8A=function(){var Q=this;Q.$1A=Q.$5A.pop(),Q._transformUpdated()},k.prototype.$9A=function(U,$){if(0!==U||0!==$){var E=this,B=E.$1A,g=B.a,J=B.b,w=B.c,t=B.d;B.tx=g*U+w*$+B.tx,B.ty=J*U+t*$+B.ty,E._transformUpdated()}},k.prototype.$BA=function(I,y){if(1!==I||1!==y){var D=this,u=D.$1A;u.a*=I,u.b*=I,u.c*=y,u.d*=y,D._transformUpdated()}},k.prototype.$AA=function(P){var k=Math.cos(P),l=Math.sin(P),E=this,e=E.$1A,q=e.a,f=e.b,a=e.c,s=e.d;e.a=q*k+a*l,e.b=f*k+s*l,e.c=-q*l+a*k,e.d=-f*l+s*k,E._transformUpdated()},k.prototype.$CA=function(_,T,K,f,l,g){var s=this,A=s.$1A;A.a=_,A.b=T,A.c=K,A.d=f,A.tx=l,A.ty=g,s._transformUpdated()},k.prototype.$DA=function(U,w,A,I,y,h){var S=this,J=S.$1A,r=J.a,x=J.b,z=J.c,p=J.d;J.a=r*U+z*w,J.b=x*U+p*w,J.c=r*A+z*I,J.d=x*A+p*I,J.tx=r*y+z*h+J.tx,J.ty=x*y+p*h+J.ty,S._transformUpdated()},k.prototype._transformUpdated=function(){},k.prototype.$18A=function(){var $=this.$1A;return 0===$.b&&0===$.c?0:Math.atan2($.b,$.a)},k.prototype.$19A=function(){var n=this.$1A;return{x:Math.sqrt(n.a*n.a+n.c*n.c),y:Math.sqrt(n.b*n.b+n.d*n.d)}},k.prototype.$20A=function(P){var G=this.$1A,S=P.x,y=P.y;return{x:G.a*S+G.c*y+G.tx,y:G.b*S+G.d*y+G.ty}},k.prototype.$21A=function(F){for(var $=this,y=new Array(F.length),V=0,r=F.length;r>V;V++)y[V]=$.$20A(F[V]);return y},k.prototype.$22A=function(Y){var z=this.$1A;return Y*Math.max(Math.sqrt(z.c*z.c+z.d*z.d),Math.sqrt(z.a*z.a+z.b*z.b))},k.prototype.$23A=function(H,V){var f=H-V;return f>-1e-5&&1e-5>f},k.prototype.$EA=function(e,i,G,_){var E,d,b=this,w=b.ctx,n=w.font,c=_?w.fillStyle:w.strokeStyle,q=w.textAlign,f=w.textBaseline;"string"==typeof n&&(d=n.match(/\d+/),d&&(E=d[0],n=n.replace(/\d+/,b.$22A(E))));var Z=b.$18A();"alphabetic"===f?(f="bottom",G+=.25*w.measureText("e").width):"hanging"===f&&(f="top",G+=.2*w.measureText("e").width),b.writer.$2AA(e,b.$20A({x:i,y:G}),n,Z,q,f,c)},k.prototype.$FA=function(l,b,j,E){var p=this,T=p.$21A([{x:l,y:b},{x:l+j,y:b},{x:l+j,y:b+E},{x:l,y:b+E}]);p._path.push({type:"rect",points:T})},k.prototype.$11A=function(t,$){var n=this,z=n.$20A({x:t,y:$});n._headPoint=z,n._path.push({type:"moveTo",x:z.x,y:z.y})},k.prototype.$12A=function(x,L){var u=this,F=u.$20A({x:x,y:L});u._path.push({type:"lineTo",x:F.x,y:F.y})},k.prototype.$15A=function(U,h,A,e,j,$){this.$16A(U,h,A,A,0,e,j,$)},k.prototype.$16A=function(T,G,b,R,V,o,W,I){var v,K,A,e,y,d,r,f,k,Z,w,s,m,N,B,l=this,P=l.$19A(),n=l.$20A({x:T,y:G});d=Math.sin(V),r=Math.cos(V);var U=function(K){var k=b*Math.cos(-K),z=R*Math.sin(-K);return l.$20A({x:T+(r*k-d*z),y:G+(d*k+r*z)})},J=[],F=W;if(I)for(;F>=o;)F-=2*Math.PI;else for(;o>=F;)F+=2*Math.PI;for(Z=(F-o)/l.$4A,s=0;s<=l.$4A;s++)w=o+Z*s,m=U(-w),J.push(m);if(e=J[0],y=J[J.length-1],v=l.$24A(o,W,I),o=v.start,W=v.end,f=l.$23A(P.x,P.y),k=l.$23A(b,R),!l.$3A&&f&&k&&l.$23A(Math.abs(o-W),2*Math.PI))l._path.push({type:"circle",x:n.x,y:n.y,end:y,keyPoints:J,radius:b*P.x});else if(!l.$3A&&f&&k)K=l.$18A(),A=Math.cos(K),N=l.$1A.a*A<0,B=l.$1A.d*A<0,v=l.$25A(o,W,N,B),o=v.start-K,W=v.end-K,l._path.push({type:"arc",x:n.x,y:n.y,end:y,radius:b*P.x,startAngle:o,endAngle:W,keyPoints:J});else{if(l.$3A||!f){for(s=1;s<=l.$4A;s++)m=J[s],l._path.push({type:"lineTo",x:m.x,y:m.y});return}var H,c,X=U(0),M=U(Math.PI/2),$=function(z,t){var C=z.x-t.x,G=z.y-t.y;return Math.sqrt(C*C+G*G)},S=$(X,n),C=$(M,n);C>S?(c=S,S=C,C=c,H=M):H=X,K=l.$18A(),A=Math.cos(K),N=l.$1A.a*A<0,B=l.$1A.d*A<0,v=l.$25A(o-Math.PI/2,W-Math.PI/2,N,B),o=v.start,W=v.end,l._path.push({type:"ellipse",x:n.x,y:n.y,end:y,major:{x:H.x-n.x,y:H.y-n.y},ratio:C/S,startAngle:o,endAngle:W,keyPoints:J})}},k.prototype.$17A=function(L,Q,v){var g=this,E=g.$20A({x:Q,y:v});this._path.push({type:"bezier",x:E.x,y:E.y,ctrl:g.$21A(L)})},k.prototype.$13A=function(){this.$2A()},k.prototype.$14A=function(){var n=this,b=n._headPoint;b&&(n._path.push({type:"lineTo",x:b.x,y:b.y,subType:"closePath"}),n._headPoint=null,n._lastPoint=null)},k.prototype.$24A=function(n,R,l){n=-n,R=-R;var p,W=n%(2*Math.PI),b=R%(2*Math.PI);for(0>W&&(W+=2*Math.PI),0>b&&(b+=2*Math.PI),l||(p=W,W=b,b=p);W>=b;)b+=2*Math.PI;return{start:W,end:b}},k.prototype.$25A=function(k,A,w,C){var T;return(C||w)&&(w&&C?(k=Math.PI+k,A=Math.PI+A):(T=Math.PI*(w?1:2)-A,A=Math.PI*(w?1:2)-k,k=T)),{start:k,end:A}},k.prototype.$10A=function(g){var k=this,z=k._path;if(z.length){var a,x,W,c,R,C=[],o=[],q={stroke:g};for(g?(q.lineWidth=k.$22A(k.ctx.lineWidth),q.color=k.ctx.strokeStyle):q.color=k.ctx.fillStyle,"string"!=typeof q.color&&(q.color="#ff0000"),x=0,a=z.length;a>x;x++)switch(W=z[x],W.type){case"moveTo":k._lastPoint={x:W.x,y:W.y},C.push(k._lastPoint),o.push(1);break;case"lineTo":C.push({x:W.x,y:W.y}),o.push(2),k._lastPoint={x:W.x,y:W.y};break;case"rect":R=W.points,C.push({x:R[0].x,y:R[0].y},{x:R[1].x,y:R[1].y},{x:R[2].x,y:R[2].y},{x:R[3].x,y:R[3].y},{x:R[0].x,y:R[0].y}),o.push(2,2,2,2,2),k._lastPoint=W.points[0];break;case"circle":case"arc":case"ellipse":console.log("split to line",W.type);break;case"arcBegin":C.length&&o.length&&k.writer.$2BA(C,o,q),C=[],o=[];break;case"arcClose":k.writer.$2BA(C,o,q),C=[],o=[];break;case"bezier":if(c=k._lastPoint,!c)break;1===W.ctrl.length?(C.push({x:W.ctrl[0].x,y:W.ctrl[0].y},{x:W.x,y:W.y}),o.push(3)):(C.push({x:W.ctrl[0].x,y:W.ctrl[0].y},{x:W.ctrl[1].x,y:W.ctrl[1].y},{x:W.x,y:W.y}),o.push(4)),k._lastPoint={x:W.x,y:W.y};break;default:C.push({x:W.x,y:W.y}),o.push(2)}k.writer.$2BA(C,o,q)}},k.prototype.$2A=function(){var G=this;G._path=[],G._lastPoint=null,G._headPoint=null};var w=p.SvgConverter=function(W){var g=this;g.$26A(W||{}),g.$27A()};w.prototype={},w.prototype.constructor=w,w.prototype.$26A=function(p){var K,V=this;K=V.options={},K.size=p.size||512},w.prototype.$27A=function(){var U=this,H=document.createElement("canvas");H.width=H.height=U.options.size,H.style.width=H.style.height=U.options.size,U._canvas=H,U._segments=[]},w.prototype.toShape=function(r){var e=this,G=e._canvas;e._segments=[];var V=G.getContext;return G.getContext=function(L){return function(d){var r=L.apply(this,arguments);return"2d"===d&&(r=e.$28A(r)),r}}(G.getContext),canvg(e._canvas,r),G.getContext=V,e.write()},w.prototype.$28A=function(z){var v=this,e=new p.Context2dProxy(z,v);return e},w.prototype.write=function(){var M=this,p=M.options.size;return{width:p,height:p,comps:M._segments}},w.prototype.$29A=function(J){var M=this;M._segments.push(J)},w.prototype.$2AA=function(e,y,H,A,v,N,K){v=v||"left","start"===v?v="left":"end"===v&&(v="right"),"alphabetic"===N?N="bottom":"hanging"===N&&(N="top");var u=this;u.$29A({type:"text",color:K,text:e,rotation:A,rect:[y.x,y.y,0,0],align:v,vAlign:N,font:H})},w.prototype.$2BA=function(S,k,a){for(var M=this,E=[],d=0,K=S.length;K>d;d++){var v=S[d];E.push(v.x,v.y)}var q={type:"shape",points:E,segments:k};a.stroke?(q.borderColor=a.color,q.borderWidth=a.lineWidth,q.background=null):(q.borderColor=null,q.borderWidth=0,q.background=a.color,a.gradient&&(q.gradient=a.gradient,q.gradientColor=a.gradientColor)),M.$29A(q)},function(V){function z(P){this.ok=!1,"#"==P.charAt(0)&&(P=P.substr(1,6)),P=P.replace(/ /g,""),P=P.toLowerCase();var K={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslateblue:"8470ff",lightslategray:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"};for(var h in K)P==h&&(P=K[h]);for(var u=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(b){return[parseInt(b[1]),parseInt(b[2]),parseInt(b[3])]}},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(l){return[parseInt(l[1],16),parseInt(l[2],16),parseInt(l[3],16)]}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(R){return[parseInt(R[1]+R[1],16),parseInt(R[2]+R[2],16),parseInt(R[3]+R[3],16)]}}],j=0;j<u.length;j++){var R=u[j].re,b=u[j].process,H=R.exec(P);if(H){var y=b(H);this.r=y[0],this.g=y[1],this.b=y[2],this.ok=!0}}this.r=this.r<0||isNaN(this.r)?0:this.r>255?255:this.r,this.g=this.g<0||isNaN(this.g)?0:this.g>255?255:this.g,this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b,this.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},this.toHex=function(){var $=this.r.toString(16),f=this.g.toString(16),T=this.b.toString(16);return 1==$.length&&($="0"+$),1==f.length&&(f="0"+f),1==T.length&&(T="0"+T),"#"+$+f+T},this.getHelpXML=function(){for(var j=new Array,A=0;A<u.length;A++)for(var D=u[A].example,V=0;V<D.length;V++)j[j.length]=D[V];for(var _ in K)j[j.length]=_;var l=document.createElement("ul");l.setAttribute("id","rgbcolor-examples");for(var A=0;A<j.length;A++)try{var S=document.createElement("li"),k=new z(j[A]),x=document.createElement("div");x.style.cssText="margin: 3px; border: 1px solid black; background:"+k.toHex()+"; "+"color:"+k.toHex(),x.appendChild(document.createTextNode("test"));var h=document.createTextNode(" "+j[A]+" -> "+k.toRGB()+" -> "+k.toHex());S.appendChild(x),S.appendChild(h),l.appendChild(S)}catch(e){}return l}}"undefined"!=typeof define&&define.amd?define(function(){return z}):"undefined"!=typeof module&&module.exports&&(module.exports=z),V.RGBColor=z}("undefined"!=typeof G?G:this),function(m){function z(R){for(var V=R.data,e=4*R.width*R.height,q=0;e>q;q+=4){var p=V[q+3]/255;V[q]*=p,V[q+1]*=p,V[q+2]*=p}}function u(d){for(var p=d.data,K=4*d.width*d.height,Y=0;K>Y;Y+=4){var A=p[Y+3];0!=A&&(A=255/A,p[Y]*=A,p[Y+1]*=A,p[Y+2]*=A)}}function i(_,e,Y,p){var J=document.getElementById(_),z=J.naturalWidth,S=J.naturalHeight,i=document.getElementById(e);i.style.width=z+"px",i.style.height=S+"px",i.width=z,i.height=S;var y=i.getContext("2d");y.clearRect(0,0,z,S),y.drawImage(J,0,0),isNaN(Y)||1>Y||(p?N(e,0,0,z,S,Y):n(e,0,0,z,S,Y))}function N(E,P,k,F,a,o){if(!(isNaN(o)||1>o)){o|=0;var B,C=document.getElementById(E),l=C.getContext("2d");try{try{B=l.getImageData(P,k,F,a)}catch(r){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),B=l.getImageData(P,k,F,a)}catch(r){throw alert("Cannot access local image"),new Error("unable to access local image data: "+r)}}}catch(r){throw alert("Cannot access image"),new Error("unable to access image data: "+r)}z(B);var c,R,w,J,e,L,U,g,H,A,v,Q,G,m,O,N,K,M,_,T,i,j,W,X,D=B.data,t=o+o+1,n=F-1,d=a-1,y=o+1,x=y*(y+1)/2,p=new q,$=p;for(w=1;t>w;w++)if($=$.next=new q,w==y)var s=$;$.next=p;var I=null,h=null;U=L=0;var Z=S[o],f=b[o];for(R=0;a>R;R++){for(N=K=M=_=g=H=A=v=0,Q=y*(T=D[L]),G=y*(i=D[L+1]),m=y*(j=D[L+2]),O=y*(W=D[L+3]),g+=x*T,H+=x*i,A+=x*j,v+=x*W,$=p,w=0;y>w;w++)$.r=T,$.g=i,$.b=j,$.a=W,$=$.next;for(w=1;y>w;w++)J=L+((w>n?n:w)<<2),g+=($.r=T=D[J])*(X=y-w),H+=($.g=i=D[J+1])*X,A+=($.b=j=D[J+2])*X,v+=($.a=W=D[J+3])*X,N+=T,K+=i,M+=j,_+=W,$=$.next;for(I=p,h=s,c=0;F>c;c++)D[L]=g*Z>>f,D[L+1]=H*Z>>f,D[L+2]=A*Z>>f,D[L+3]=v*Z>>f,g-=Q,H-=G,A-=m,v-=O,Q-=I.r,G-=I.g,m-=I.b,O-=I.a,J=U+((J=c+o+1)<n?J:n)<<2,N+=I.r=D[J],K+=I.g=D[J+1],M+=I.b=D[J+2],_+=I.a=D[J+3],g+=N,H+=K,A+=M,v+=_,I=I.next,Q+=T=h.r,G+=i=h.g,m+=j=h.b,O+=W=h.a,N-=T,K-=i,M-=j,_-=W,h=h.next,L+=4;U+=F}for(c=0;F>c;c++){for(K=M=_=N=H=A=v=g=0,L=c<<2,Q=y*(T=D[L]),G=y*(i=D[L+1]),m=y*(j=D[L+2]),O=y*(W=D[L+3]),g+=x*T,H+=x*i,A+=x*j,v+=x*W,$=p,w=0;y>w;w++)$.r=T,$.g=i,$.b=j,$.a=W,$=$.next;for(e=F,w=1;o>=w;w++)L=e+c<<2,g+=($.r=T=D[L])*(X=y-w),H+=($.g=i=D[L+1])*X,A+=($.b=j=D[L+2])*X,v+=($.a=W=D[L+3])*X,N+=T,K+=i,M+=j,_+=W,$=$.next,d>w&&(e+=F);for(L=c,I=p,h=s,R=0;a>R;R++)J=L<<2,D[J]=g*Z>>f,D[J+1]=H*Z>>f,D[J+2]=A*Z>>f,D[J+3]=v*Z>>f,g-=Q,H-=G,A-=m,v-=O,Q-=I.r,G-=I.g,m-=I.b,O-=I.a,J=c+((J=R+y)<d?J:d)*F<<2,g+=N+=I.r=D[J],H+=K+=I.g=D[J+1],A+=M+=I.b=D[J+2],v+=_+=I.a=D[J+3],I=I.next,Q+=T=h.r,G+=i=h.g,m+=j=h.b,O+=W=h.a,N-=T,K-=i,M-=j,_-=W,h=h.next,L+=F}u(B),l.putImageData(B,P,k)}}function n(l,$,G,k,D,E){if(!(isNaN(E)||1>E)){E|=0;var K,A=document.getElementById(l),m=A.getContext("2d");try{try{K=m.getImageData($,G,k,D)}catch(f){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),K=m.getImageData($,G,k,D)}catch(f){throw alert("Cannot access local image"),new Error("unable to access local image data: "+f)}}}catch(f){throw alert("Cannot access image"),new Error("unable to access image data: "+f)}var I,e,T,Y,c,g,d,N,o,j,L,F,C,z,X,O,s,H,u,r,V=K.data,U=E+E+1,a=k-1,p=D-1,n=E+1,w=n*(n+1)/2,t=new q,J=t;for(T=1;U>T;T++)if(J=J.next=new q,T==n)var R=J;J.next=t;var y=null,Q=null;d=g=0;var v=S[E],Z=b[E];for(e=0;D>e;e++){for(z=X=O=N=o=j=0,L=n*(s=V[g]),F=n*(H=V[g+1]),C=n*(u=V[g+2]),N+=w*s,o+=w*H,j+=w*u,J=t,T=0;n>T;T++)J.r=s,J.g=H,J.b=u,J=J.next;for(T=1;n>T;T++)Y=g+((T>a?a:T)<<2),N+=(J.r=s=V[Y])*(r=n-T),o+=(J.g=H=V[Y+1])*r,j+=(J.b=u=V[Y+2])*r,z+=s,X+=H,O+=u,J=J.next;for(y=t,Q=R,I=0;k>I;I++)V[g]=N*v>>Z,V[g+1]=o*v>>Z,V[g+2]=j*v>>Z,N-=L,o-=F,j-=C,L-=y.r,F-=y.g,C-=y.b,Y=d+((Y=I+E+1)<a?Y:a)<<2,z+=y.r=V[Y],X+=y.g=V[Y+1],O+=y.b=V[Y+2],N+=z,o+=X,j+=O,y=y.next,L+=s=Q.r,F+=H=Q.g,C+=u=Q.b,z-=s,X-=H,O-=u,Q=Q.next,g+=4;d+=k}for(I=0;k>I;I++){for(X=O=z=o=j=N=0,g=I<<2,L=n*(s=V[g]),F=n*(H=V[g+1]),C=n*(u=V[g+2]),N+=w*s,o+=w*H,j+=w*u,J=t,T=0;n>T;T++)J.r=s,J.g=H,J.b=u,J=J.next;for(c=k,T=1;E>=T;T++)g=c+I<<2,N+=(J.r=s=V[g])*(r=n-T),o+=(J.g=H=V[g+1])*r,j+=(J.b=u=V[g+2])*r,z+=s,X+=H,O+=u,J=J.next,p>T&&(c+=k);for(g=I,y=t,Q=R,e=0;D>e;e++)Y=g<<2,V[Y]=N*v>>Z,V[Y+1]=o*v>>Z,V[Y+2]=j*v>>Z,N-=L,o-=F,j-=C,L-=y.r,F-=y.g,C-=y.b,Y=I+((Y=e+n)<p?Y:p)*k<<2,N+=z+=y.r=V[Y],o+=X+=y.g=V[Y+1],j+=O+=y.b=V[Y+2],y=y.next,L+=s=Q.r,F+=H=Q.g,C+=u=Q.b,z-=s,X-=H,O-=u,Q=Q.next,g+=k}m.putImageData(K,$,G)}}function q(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var S=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],b=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24],H={image:i,canvasRGBA:N,canvasRGB:n};"undefined"!=typeof define&&define.amd?define(function(){return H}):"undefined"!=typeof module&&module.exports&&(module.exports=H),m.stackBlur=H}("undefined"!=typeof G?G:this),function(o,X){"undefined"!=typeof define&&define.amd?define("canvgModule",["rgbcolor","stackblur"],X):"undefined"!=typeof module&&module.exports&&(module.exports=X(require("rgbcolor"),require("stackblur"))),o.canvg=X(o.RGBColor,o.stackBlur)}("undefined"!=typeof G?G:this,function(Q,M){function _(y){var R=[0,0,0],B=function(u,T){var D=y.match(u);null!=D&&(R[T]+=D.length,y=y.replace(u," "))};return y=y.replace(/:not\(([^\)]*)\)/g," $1 "),y=y.replace(/{[\s\S]*/gm," "),B(C,1),B(K,0),B(V,1),B(g,2),B(r,1),B(p,1),y=y.replace(/[\*\s\+>~]/g," "),y=y.replace(/[#\.]/g," "),B(U,2),R.join("")}function h($){var N={opts:$};N.FRAMERATE=30,N.MAX_VIRTUAL_PIXELS=3e4,N.log=function(){},1==N.opts.log&&"undefined"!=typeof console&&(N.log=function(H){console.log(H)}),N.init=function(f){var b=0;N.UniqueId=function(){return b++,"canvg"+b},N.Definitions={},N.Styles={},N.StylesSpecificity={},N.Animations=[],N.Images=[],N.ctx=f,N.ViewPort=new function(){this.viewPorts=[],this.Clear=function(){this.viewPorts=[]},this.SetCurrent=function(o,a){this.viewPorts.push({width:o,height:a})},this.RemoveCurrent=function(){this.viewPorts.pop()},this.Current=function(){return this.viewPorts[this.viewPorts.length-1]},this.width=function(){return this.Current().width},this.height=function(){return this.Current().height},this.ComputeSize=function(i){return null!=i&&"number"==typeof i?i:"x"==i?this.width():"y"==i?this.height():Math.sqrt(Math.pow(this.width(),2)+Math.pow(this.height(),2))/Math.sqrt(2)}}},N.init(),N.ImagesLoaded=function(){for(var V=0;V<N.Images.length;V++)if(!N.Images[V].loaded)return!1;return!0},N.trim=function(X){return X.replace(/^\s+|\s+$/g,"")},N.compressSpaces=function(T){return T.replace(/[\s\r\t\n]+/gm," ")},N.ajax=function(s){var F;return F=G.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),F?(F.open("GET",s,!1),F.send(null),F.responseText):null},N.parseXml=function(x){if("undefined"!=typeof Windows&&"undefined"!=typeof Windows.Data&&"undefined"!=typeof Windows.Data.Xml){var y=new Windows.Data.Xml.Dom.XmlDocument,O=new Windows.Data.Xml.Dom.XmlLoadSettings;return O.prohibitDtd=!1,y.loadXml(x,O),y}if(G.DOMParser){var k=new DOMParser;return k.parseFromString(x,"text/xml")}x=x.replace(/<!DOCTYPE svg[^>]*>/,"");var y=new ActiveXObject("Microsoft.XMLDOM");return y.async="false",y.loadXML(x),y},N.Property=function(c,X){this.name=c,this.value=X},N.Property.prototype.getValue=function(){return this.value},N.Property.prototype.hasValue=function(){return null!=this.value&&""!==this.value},N.Property.prototype.numValue=function(){if(!this.hasValue())return 0;var b=parseFloat(this.value);return(this.value+"").match(/%$/)&&(b/=100),b},N.Property.prototype.valueOrDefault=function(t){return this.hasValue()?this.value:t},N.Property.prototype.numValueOrDefault=function(j){return this.hasValue()?this.numValue():j},N.Property.prototype.addOpacity=function(y){var l=this.value;if(null!=y.value&&""!=y.value&&"string"==typeof this.value){var e=new Q(this.value);e.ok&&(l="rgba("+e.r+", "+e.g+", "+e.b+", "+y.numValue()+")")}return new N.Property(this.name,l)},N.Property.prototype.getDefinition=function(){var S=this.value.match(/#([^\)'"]+)/);return S&&(S=S[1]),S||(S=this.value),N.Definitions[S]},N.Property.prototype.isUrlDefinition=function(){return 0==this.value.indexOf("url(")},N.Property.prototype.getFillStyleDefinition=function(D,O){var w=this.getDefinition();if(null!=w&&w.createGradient)return w.createGradient(N.ctx,D,O);if(null!=w&&w.createPattern){if(w.getHrefAttribute().hasValue()){var e=w.attribute("patternTransform");w=w.getHrefAttribute().getDefinition(),e.hasValue()&&(w.attribute("patternTransform",!0).value=e.value)}return w.createPattern(N.ctx,D)}return null},N.Property.prototype.getDPI=function(){return 96},N.Property.prototype.getEM=function(e){var g=12,L=new N.Property("fontSize",N.Font.Parse(N.ctx.font).fontSize);return L.hasValue()&&(g=L.toPixels(e)),g},N.Property.prototype.getUnits=function(){var F=this.value+"";return F.replace(/[0-9\.\-]/g,"")},N.Property.prototype.toPixels=function(m,L){if(!this.hasValue())return 0;var b=this.value+"";if(b.match(/em$/))return this.numValue()*this.getEM(m);if(b.match(/ex$/))return this.numValue()*this.getEM(m)/2;if(b.match(/px$/))return this.numValue();if(b.match(/pt$/))return this.numValue()*this.getDPI(m)*(1/72);if(b.match(/pc$/))return 15*this.numValue();if(b.match(/cm$/))return this.numValue()*this.getDPI(m)/2.54;if(b.match(/mm$/))return this.numValue()*this.getDPI(m)/25.4;if(b.match(/in$/))return this.numValue()*this.getDPI(m);if(b.match(/%$/))return this.numValue()*N.ViewPort.ComputeSize(m);var a=this.numValue();return L&&1>a?a*N.ViewPort.ComputeSize(m):a},N.Property.prototype.toMilliseconds=function(){if(!this.hasValue())return 0;var M=this.value+"";return M.match(/s$/)?1e3*this.numValue():M.match(/ms$/)?this.numValue():this.numValue()},N.Property.prototype.toRadians=function(){if(!this.hasValue())return 0;var M=this.value+"";return M.match(/deg$/)?this.numValue()*(Math.PI/180):M.match(/grad$/)?this.numValue()*(Math.PI/200):M.match(/rad$/)?this.numValue():this.numValue()*(Math.PI/180)};var n={baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"};return N.Property.prototype.toTextBaseline=function(){return this.hasValue()?n[this.value]:null},N.Font=new function(){this.Styles="normal|italic|oblique|inherit",this.Variants="normal|small-caps|inherit",this.Weights="normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit",this.CreateFont=function(f,U,m,s,W,B){var S=null!=B?this.Parse(B):this.CreateFont("","","","","",N.ctx.font);return{fontFamily:W||S.fontFamily,fontSize:s||S.fontSize,fontStyle:f||S.fontStyle,fontWeight:m||S.fontWeight,fontVariant:U||S.fontVariant,toString:function(){return[this.fontStyle,this.fontVariant,this.fontWeight,this.fontSize,this.fontFamily].join(" ")}}};var V=this;this.Parse=function(Q){for(var O={},Y=N.trim(N.compressSpaces(Q||"")).split(" "),$={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1},n="",c=0;c<Y.length;c++)$.fontStyle||-1==V.Styles.indexOf(Y[c])?$.fontVariant||-1==V.Variants.indexOf(Y[c])?$.fontWeight||-1==V.Weights.indexOf(Y[c])?$.fontSize?"inherit"!=Y[c]&&(n+=Y[c]):("inherit"!=Y[c]&&(O.fontSize=Y[c].split("/")[0]),$.fontStyle=$.fontVariant=$.fontWeight=$.fontSize=!0):("inherit"!=Y[c]&&(O.fontWeight=Y[c]),$.fontStyle=$.fontVariant=$.fontWeight=!0):("inherit"!=Y[c]&&(O.fontVariant=Y[c]),$.fontStyle=$.fontVariant=!0):("inherit"!=Y[c]&&(O.fontStyle=Y[c]),$.fontStyle=!0);return""!=n&&(O.fontFamily=n),O}},N.ToNumberArray=function(W){for(var i=N.trim(N.compressSpaces((W||"").replace(/,/g," "))).split(" "),P=0;P<i.length;P++)i[P]=parseFloat(i[P]);return i},N.Point=function(m,I){this.x=m,this.y=I},N.Point.prototype.angleTo=function(z){return Math.atan2(z.y-this.y,z.x-this.x)},N.Point.prototype.applyTransform=function(v){var $=this.x*v[0]+this.y*v[2]+v[4],Y=this.x*v[1]+this.y*v[3]+v[5];this.x=$,this.y=Y},N.CreatePoint=function(W){var B=N.ToNumberArray(W);return new N.Point(B[0],B[1])},N.CreatePath=function(w){for(var A=N.ToNumberArray(w),O=[],L=0;L<A.length;L+=2)O.push(new N.Point(A[L],A[L+1]));return O},N.BoundingBox=function(K,P,C,j){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN,this.x=function(){return this.x1},this.y=function(){return this.y1},this.width=function(){return this.x2-this.x1},this.height=function(){return this.y2-this.y1},this.addPoint=function(z,w){null!=z&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=z,this.x2=z),z<this.x1&&(this.x1=z),z>this.x2&&(this.x2=z)),null!=w&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=w,this.y2=w),w<this.y1&&(this.y1=w),w>this.y2&&(this.y2=w))},this.addX=function(s){this.addPoint(s,null)},this.addY=function(y){this.addPoint(null,y)},this.addBoundingBox=function(R){this.addPoint(R.x1,R.y1),this.addPoint(R.x2,R.y2)},this.addQuadraticCurve=function(d,i,j,n,w,e){var k=d+2/3*(j-d),W=i+2/3*(n-i),l=k+1/3*(w-d),t=W+1/3*(e-i);this.addBezierCurve(d,i,k,l,W,t,w,e)},this.addBezierCurve=function(s,M,I,n,T,L,E,O){var R=[s,M],i=[I,n],H=[T,L],v=[E,O];this.addPoint(R[0],R[1]),this.addPoint(v[0],v[1]);for(var q=0;1>=q;q++){var k=function(g){return Math.pow(1-g,3)*R[q]+3*Math.pow(1-g,2)*g*i[q]+3*(1-g)*Math.pow(g,2)*H[q]+Math.pow(g,3)*v[q]},S=6*R[q]-12*i[q]+6*H[q],o=-3*R[q]+9*i[q]-9*H[q]+3*v[q],x=3*i[q]-3*R[q];if(0!=o){var N=Math.pow(S,2)-4*x*o;if(!(0>N)){var y=(-S+Math.sqrt(N))/(2*o);y>0&&1>y&&(0==q&&this.addX(k(y)),1==q&&this.addY(k(y)));var P=(-S-Math.sqrt(N))/(2*o);P>0&&1>P&&(0==q&&this.addX(k(P)),1==q&&this.addY(k(P)))}}else{if(0==S)continue;var U=-x/S;U>0&&1>U&&(0==q&&this.addX(k(U)),1==q&&this.addY(k(U)))}}},this.isPointInBox=function(c,G){return this.x1<=c&&c<=this.x2&&this.y1<=G&&G<=this.y2},this.addPoint(K,P),this.addPoint(C,j)},N.Transform=function(m){var p=this;this.Type={},this.Type.translate=function(Q){this.p=N.CreatePoint(Q),this.apply=function($){$.translate(this.p.x||0,this.p.y||0)},this.unapply=function(t){t.translate(-1*this.p.x||0,-1*this.p.y||0)},this.applyToPoint=function(g){g.applyTransform([1,0,0,1,this.p.x||0,this.p.y||0])}},this.Type.rotate=function(q){var $=N.ToNumberArray(q);this.angle=new N.Property("angle",$[0]),this.cx=$[1]||0,this.cy=$[2]||0,this.apply=function(E){E.translate(this.cx,this.cy),E.rotate(this.angle.toRadians()),E.translate(-this.cx,-this.cy)},this.unapply=function(f){f.translate(this.cx,this.cy),f.rotate(-1*this.angle.toRadians()),f.translate(-this.cx,-this.cy)},this.applyToPoint=function(R){var p=this.angle.toRadians();R.applyTransform([1,0,0,1,this.p.x||0,this.p.y||0]),R.applyTransform([Math.cos(p),Math.sin(p),-Math.sin(p),Math.cos(p),0,0]),R.applyTransform([1,0,0,1,-this.p.x||0,-this.p.y||0])}},this.Type.scale=function(K){this.p=N.CreatePoint(K),this.apply=function(e){e.scale(this.p.x||1,this.p.y||this.p.x||1)},this.unapply=function(o){o.scale(1/this.p.x||1,1/this.p.y||this.p.x||1)},this.applyToPoint=function(q){q.applyTransform([this.p.x||0,0,0,this.p.y||0,0,0])}},this.Type.matrix=function(T){this.m=N.ToNumberArray(T),this.apply=function(F){F.transform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},this.unapply=function(K){var X=this.m[0],L=this.m[2],j=this.m[4],i=this.m[1],h=this.m[3],r=this.m[5],I=0,O=0,k=1,P=1/(X*(h*k-r*O)-L*(i*k-r*I)+j*(i*O-h*I));K.transform(P*(h*k-r*O),P*(r*I-i*k),P*(j*O-L*k),P*(X*k-j*I),P*(L*r-j*h),P*(j*i-X*r))},this.applyToPoint=function(Z){Z.applyTransform(this.m)}},this.Type.SkewBase=function(g){this.base=p.Type.matrix,this.base(g),this.angle=new N.Property("angle",g)},this.Type.SkewBase.prototype=new this.Type.matrix,this.Type.skewX=function(X){this.base=p.Type.SkewBase,this.base(X),this.m=[1,0,Math.tan(this.angle.toRadians()),1,0,0]},this.Type.skewX.prototype=new this.Type.SkewBase,this.Type.skewY=function(s){this.base=p.Type.SkewBase,this.base(s),this.m=[1,Math.tan(this.angle.toRadians()),0,1,0,0]},this.Type.skewY.prototype=new this.Type.SkewBase,this.transforms=[],this.apply=function(V){for(var Y=0;Y<this.transforms.length;Y++)this.transforms[Y].apply(V)},this.unapply=function(d){for(var r=this.transforms.length-1;r>=0;r--)this.transforms[r].unapply(d)},this.applyToPoint=function(I){for(var q=0;q<this.transforms.length;q++)this.transforms[q].applyToPoint(I)};for(var _=N.trim(N.compressSpaces(m)).replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/),B=0;B<_.length;B++){var U=N.trim(_[B].split("(")[0]),G=_[B].split("(")[1].replace(")",""),M=this.Type[U];if("undefined"!=typeof M){var w=new M(G);w.type=U,this.transforms.push(w)}}},N.AspectRatio=function(f,Z,X,n,B,Q,w,V,a,G){Z=N.compressSpaces(Z),Z=Z.replace(/^defer\s/,"");var t=Z.split(" ")[0]||"xMidYMid",$=Z.split(" ")[1]||"meet",m=X/n,W=B/Q,h=Math.min(m,W),C=Math.max(m,W);"meet"==$&&(n*=h,Q*=h),"slice"==$&&(n*=C,Q*=C),a=new N.Property("refX",a),G=new N.Property("refY",G),a.hasValue()&&G.hasValue()?f.translate(-h*a.toPixels("x"),-h*G.toPixels("y")):(t.match(/^xMid/)&&("meet"==$&&h==W||"slice"==$&&C==W)&&f.translate(X/2-n/2,0),t.match(/YMid$/)&&("meet"==$&&h==m||"slice"==$&&C==m)&&f.translate(0,B/2-Q/2),t.match(/^xMax/)&&("meet"==$&&h==W||"slice"==$&&C==W)&&f.translate(X-n,0),t.match(/YMax$/)&&("meet"==$&&h==m||"slice"==$&&C==m)&&f.translate(0,B-Q)),"none"==t?f.scale(m,W):"meet"==$?f.scale(h,h):"slice"==$&&f.scale(C,C),f.translate(null==w?0:-w,null==V?0:-V)
  2. },N.Element={},N.EmptyProperty=new N.Property("EMPTY",""),N.Element.ElementBase=function(K){this.attributes={},this.styles={},this.stylesSpecificity={},this.children=[],this.attribute=function(V,T){var a=this.attributes[V];return null!=a?a:(1==T&&(a=new N.Property(V,""),this.attributes[V]=a),a||N.EmptyProperty)},this.getHrefAttribute=function(){for(var G in this.attributes)if("href"==G||G.match(/:href$/))return this.attributes[G];return N.EmptyProperty},this.style=function(j,f,p){var Y=this.styles[j];if(null!=Y)return Y;var z=this.attribute(j);if(null!=z&&z.hasValue())return this.styles[j]=z,z;if(1!=p){var G=this.parent;if(null!=G){var k=G.style(j);if(null!=k&&k.hasValue())return k}}return 1==f&&(Y=new N.Property(j,""),this.styles[j]=Y),Y||N.EmptyProperty},this.render=function(c){if("none"!=this.style("display").value&&"hidden"!=this.style("visibility").value){if(c.save(),this.style("mask").hasValue()){var M=this.style("mask").getDefinition();null!=M&&M.apply(c,this)}else if(this.style("filter").hasValue()){var l=this.style("filter").getDefinition();null!=l&&l.apply(c,this)}else this.setContext(c),this.renderChildren(c),this.clearContext(c);c.restore()}},this.setContext=function(){},this.clearContext=function(){},this.renderChildren=function(b){for(var W=0;W<this.children.length;W++)this.children[W].render(b)},this.addChild=function(U,u){var H=U;u&&(H=N.CreateElement(U)),H.parent=this,"title"!=H.type&&this.children.push(H)},this.addStylesFromStyleDefinition=function(){for(var _ in N.Styles)if("@"!=_[0]&&b(K,_)){var B=N.Styles[_],i=N.StylesSpecificity[_];if(null!=B)for(var F in B){var Z=this.stylesSpecificity[F];"undefined"==typeof Z&&(Z="000"),i>Z&&(this.styles[F]=B[F],this.stylesSpecificity[F]=i)}}};var n=new RegExp("^[A-Z-]+$"),X=function(p){return n.test(p)?p.toLowerCase():p};if(null!=K&&1==K.nodeType){for(var h=0;h<K.attributes.length;h++){var F=K.attributes[h],v=X(F.nodeName);this.attributes[v]=new N.Property(v,F.value)}if(this.addStylesFromStyleDefinition(),this.attribute("style").hasValue())for(var Y=this.attribute("style").value.split(";"),h=0;h<Y.length;h++)if(""!=N.trim(Y[h])){var c=Y[h].split(":"),d=N.trim(c[0]),q=N.trim(c[1]);this.styles[d]=new N.Property(d,q)}this.attribute("id").hasValue()&&null==N.Definitions[this.attribute("id").value]&&(N.Definitions[this.attribute("id").value]=this);for(var h=0;h<K.childNodes.length;h++){var k=K.childNodes[h];if(1==k.nodeType&&this.addChild(k,!0),this.captureTextNodes&&(3==k.nodeType||4==k.nodeType)){var x=k.value||k.text||k.textContent||"";""!=N.compressSpaces(x)&&this.addChild(new N.Element.tspan(k),!1)}}}},N.Element.RenderedElementBase=function(M){this.base=N.Element.ElementBase,this.base(M),this.setContext=function(u){if(this.style("fill").isUrlDefinition()){var v=this.style("fill").getFillStyleDefinition(this,this.style("fill-opacity"));null!=v&&(u.fillStyle=v)}else if(this.style("fill").hasValue()){var s=this.style("fill");"currentColor"==s.value&&(s.value=this.style("color").value),"inherit"!=s.value&&(u.fillStyle="none"==s.value?"rgba(0,0,0,0)":s.value)}if(this.style("fill-opacity").hasValue()){var s=new N.Property("fill",u.fillStyle);s=s.addOpacity(this.style("fill-opacity")),u.fillStyle=s.value}if(this.style("stroke").isUrlDefinition()){var v=this.style("stroke").getFillStyleDefinition(this,this.style("stroke-opacity"));null!=v&&(u.strokeStyle=v)}else if(this.style("stroke").hasValue()){var d=this.style("stroke");"currentColor"==d.value&&(d.value=this.style("color").value),"inherit"!=d.value&&(u.strokeStyle="none"==d.value?"rgba(0,0,0,0)":d.value)}if(this.style("stroke-opacity").hasValue()){var d=new N.Property("stroke",u.strokeStyle);d=d.addOpacity(this.style("stroke-opacity")),u.strokeStyle=d.value}if(this.style("stroke-width").hasValue()){var z=this.style("stroke-width").toPixels();u.lineWidth=0==z?.001:z}if(this.style("stroke-linecap").hasValue()&&(u.lineCap=this.style("stroke-linecap").value),this.style("stroke-linejoin").hasValue()&&(u.lineJoin=this.style("stroke-linejoin").value),this.style("stroke-miterlimit").hasValue()&&(u.miterLimit=this.style("stroke-miterlimit").value),this.style("stroke-dasharray").hasValue()&&"none"!=this.style("stroke-dasharray").value){var D=N.ToNumberArray(this.style("stroke-dasharray").value);"undefined"!=typeof u.setLineDash?u.setLineDash(D):"undefined"!=typeof u.webkitLineDash?u.webkitLineDash=D:"undefined"==typeof u.mozDash||1==D.length&&0==D[0]||(u.mozDash=D);var J=this.style("stroke-dashoffset").numValueOrDefault(1);"undefined"!=typeof u.lineDashOffset?u.lineDashOffset=J:"undefined"!=typeof u.webkitLineDashOffset?u.webkitLineDashOffset=J:"undefined"!=typeof u.mozDashOffset&&(u.mozDashOffset=J)}if("undefined"!=typeof u.font&&(u.font=N.Font.CreateFont(this.style("font-style").value,this.style("font-variant").value,this.style("font-weight").value,this.style("font-size").hasValue()?this.style("font-size").toPixels()+"px":"",this.style("font-family").value).toString()),this.style("transform",!1,!0).hasValue()){var b=new N.Transform(this.style("transform",!1,!0).value);b.apply(u)}if(this.style("clip-path",!1,!0).hasValue()){var r=this.style("clip-path",!1,!0).getDefinition();null!=r&&r.apply(u)}this.style("opacity").hasValue()&&(u.globalAlpha=this.style("opacity").numValue())}},N.Element.RenderedElementBase.prototype=new N.Element.ElementBase,N.Element.PathElementBase=function(Y){this.base=N.Element.RenderedElementBase,this.base(Y),this.path=function(e){return null!=e&&e.beginPath(),new N.BoundingBox},this.renderChildren=function(M){this.path(M),N.Mouse.checkPath(this,M),""!=M.fillStyle&&("inherit"!=this.style("fill-rule").valueOrDefault("inherit")?M.fill(this.style("fill-rule").value):M.fill()),""!=M.strokeStyle&&M.stroke();var r=this.getMarkers();if(null!=r){if(this.style("marker-start").isUrlDefinition()){var s=this.style("marker-start").getDefinition();s.render(M,r[0][0],r[0][1])}if(this.style("marker-mid").isUrlDefinition())for(var s=this.style("marker-mid").getDefinition(),R=1;R<r.length-1;R++)s.render(M,r[R][0],r[R][1]);if(this.style("marker-end").isUrlDefinition()){var s=this.style("marker-end").getDefinition();s.render(M,r[r.length-1][0],r[r.length-1][1])}}},this.getBoundingBox=function(){return this.path()},this.getMarkers=function(){return null}},N.Element.PathElementBase.prototype=new N.Element.RenderedElementBase,N.Element.svg=function(c){this.base=N.Element.RenderedElementBase,this.base(c),this.baseClearContext=this.clearContext,this.clearContext=function(C){this.baseClearContext(C),N.ViewPort.RemoveCurrent()},this.baseSetContext=this.setContext,this.setContext=function(i){i.strokeStyle="rgba(0,0,0,0)",i.lineCap="butt",i.lineJoin="miter",i.miterLimit=4,"undefined"!=typeof i.font&&"undefined"!=typeof G.getComputedStyle&&(i.font=G.getComputedStyle(i.canvas).getPropertyValue("font")),this.baseSetContext(i),this.attribute("x").hasValue()||(this.attribute("x",!0).value=0),this.attribute("y").hasValue()||(this.attribute("y",!0).value=0),i.translate(this.attribute("x").toPixels("x"),this.attribute("y").toPixels("y"));var $=N.ViewPort.width(),T=N.ViewPort.height();if(this.attribute("width").hasValue()||(this.attribute("width",!0).value="100%"),this.attribute("height").hasValue()||(this.attribute("height",!0).value="100%"),"undefined"==typeof this.root){$=this.attribute("width").toPixels("x"),T=this.attribute("height").toPixels("y");var t=0,d=0;this.attribute("refX").hasValue()&&this.attribute("refY").hasValue()&&(t=-this.attribute("refX").toPixels("x"),d=-this.attribute("refY").toPixels("y")),"visible"!=this.attribute("overflow").valueOrDefault("hidden")&&(i.beginPath(),i.moveTo(t,d),i.lineTo($,d),i.lineTo($,T),i.lineTo(t,T),i.closePath(),i.clip())}if(N.ViewPort.SetCurrent($,T),this.attribute("viewBox").hasValue()){var k=N.ToNumberArray(this.attribute("viewBox").value),F=k[0],D=k[1];$=k[2],T=k[3],N.AspectRatio(i,this.attribute("preserveAspectRatio").value,N.ViewPort.width(),$,N.ViewPort.height(),T,F,D,this.attribute("refX").value,this.attribute("refY").value),N.ViewPort.RemoveCurrent(),N.ViewPort.SetCurrent(k[2],k[3])}}},N.Element.svg.prototype=new N.Element.RenderedElementBase,N.Element.rect=function(W){this.base=N.Element.PathElementBase,this.base(W),this.path=function(P){var B=this.attribute("x").toPixels("x"),X=this.attribute("y").toPixels("y"),t=this.attribute("width").toPixels("x"),S=this.attribute("height").toPixels("y"),s=this.attribute("rx").toPixels("x"),J=this.attribute("ry").toPixels("y");return this.attribute("rx").hasValue()&&!this.attribute("ry").hasValue()&&(J=s),this.attribute("ry").hasValue()&&!this.attribute("rx").hasValue()&&(s=J),s=Math.min(s,t/2),J=Math.min(J,S/2),null!=P&&(P.beginPath(),P.moveTo(B+s,X),P.lineTo(B+t-s,X),P.quadraticCurveTo(B+t,X,B+t,X+J),P.lineTo(B+t,X+S-J),P.quadraticCurveTo(B+t,X+S,B+t-s,X+S),P.lineTo(B+s,X+S),P.quadraticCurveTo(B,X+S,B,X+S-J),P.lineTo(B,X+J),P.quadraticCurveTo(B,X,B+s,X),P.closePath()),new N.BoundingBox(B,X,B+t,X+S)}},N.Element.rect.prototype=new N.Element.PathElementBase,N.Element.circle=function(P){this.base=N.Element.PathElementBase,this.base(P),this.path=function(k){var V=this.attribute("cx").toPixels("x"),n=this.attribute("cy").toPixels("y"),g=this.attribute("r").toPixels();return null!=k&&(k.beginPath(),k.arc(V,n,g,0,2*Math.PI,!0),k.closePath()),new N.BoundingBox(V-g,n-g,V+g,n+g)}},N.Element.circle.prototype=new N.Element.PathElementBase,N.Element.ellipse=function(b){this.base=N.Element.PathElementBase,this.base(b),this.path=function(Z){var R=4*((Math.sqrt(2)-1)/3),L=this.attribute("rx").toPixels("x"),l=this.attribute("ry").toPixels("y"),s=this.attribute("cx").toPixels("x"),$=this.attribute("cy").toPixels("y");return null!=Z&&(Z.beginPath(),Z.moveTo(s,$-l),Z.bezierCurveTo(s+R*L,$-l,s+L,$-R*l,s+L,$),Z.bezierCurveTo(s+L,$+R*l,s+R*L,$+l,s,$+l),Z.bezierCurveTo(s-R*L,$+l,s-L,$+R*l,s-L,$),Z.bezierCurveTo(s-L,$-R*l,s-R*L,$-l,s,$-l),Z.closePath()),new N.BoundingBox(s-L,$-l,s+L,$+l)}},N.Element.ellipse.prototype=new N.Element.PathElementBase,N.Element.line=function(H){this.base=N.Element.PathElementBase,this.base(H),this.getPoints=function(){return[new N.Point(this.attribute("x1").toPixels("x"),this.attribute("y1").toPixels("y")),new N.Point(this.attribute("x2").toPixels("x"),this.attribute("y2").toPixels("y"))]},this.path=function(l){var m=this.getPoints();return null!=l&&(l.beginPath(),l.moveTo(m[0].x,m[0].y),l.lineTo(m[1].x,m[1].y)),new N.BoundingBox(m[0].x,m[0].y,m[1].x,m[1].y)},this.getMarkers=function(){var U=this.getPoints(),Y=U[0].angleTo(U[1]);return[[U[0],Y],[U[1],Y]]}},N.Element.line.prototype=new N.Element.PathElementBase,N.Element.polyline=function(Q){this.base=N.Element.PathElementBase,this.base(Q),this.points=N.CreatePath(this.attribute("points").value),this.path=function(V){var p=new N.BoundingBox(this.points[0].x,this.points[0].y);null!=V&&(V.beginPath(),V.moveTo(this.points[0].x,this.points[0].y));for(var k=1;k<this.points.length;k++)p.addPoint(this.points[k].x,this.points[k].y),null!=V&&V.lineTo(this.points[k].x,this.points[k].y);return p},this.getMarkers=function(){for(var c=[],Y=0;Y<this.points.length-1;Y++)c.push([this.points[Y],this.points[Y].angleTo(this.points[Y+1])]);return c.length>0&&c.push([this.points[this.points.length-1],c[c.length-1][1]]),c}},N.Element.polyline.prototype=new N.Element.PathElementBase,N.Element.polygon=function(r){this.base=N.Element.polyline,this.base(r),this.basePath=this.path,this.path=function(e){var w=this.basePath(e);return null!=e&&(e.lineTo(this.points[0].x,this.points[0].y),e.closePath()),w}},N.Element.polygon.prototype=new N.Element.polyline,N.Element.path=function(Q){this.base=N.Element.PathElementBase,this.base(Q);var s=this.attribute("d").value;s=s.replace(/,/gm," ");for(var X=0;2>X;X++)s=s.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm,"$1 $2");s=s.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm,"$1 $2"),s=s.replace(/([0-9])([+\-])/gm,"$1 $2");for(var X=0;2>X;X++)s=s.replace(/(\.[0-9]*)(\.)/gm,"$1 $2");s=s.replace(/([Aa](\s+[0-9]+){3})\s+([01])\s*([01])/gm,"$1 $3 $4 "),s=N.compressSpaces(s),s=N.trim(s),this.PathParser=new function(g){this.tokens=g.split(" "),this.reset=function(){this.i=-1,this.command="",this.previousCommand="",this.start=new N.Point(0,0),this.control=new N.Point(0,0),this.current=new N.Point(0,0),this.points=[],this.angles=[]},this.isEnd=function(){return this.i>=this.tokens.length-1},this.isCommandOrEnd=function(){return this.isEnd()?!0:null!=this.tokens[this.i+1].match(/^[A-Za-z]$/)},this.isRelativeCommand=function(){switch(this.command){case"m":case"l":case"h":case"v":case"c":case"s":case"q":case"t":case"a":case"z":return!0}return!1},this.getToken=function(){return this.i++,this.tokens[this.i]},this.getScalar=function(){return parseFloat(this.getToken())},this.nextCommand=function(){this.previousCommand=this.command,this.command=this.getToken()},this.getPoint=function(){var z=new N.Point(this.getScalar(),this.getScalar());return this.makeAbsolute(z)},this.getAsControlPoint=function(){var t=this.getPoint();return this.control=t,t},this.getAsCurrentPoint=function(){var D=this.getPoint();return this.current=D,D},this.getReflectedControlPoint=function(){if("c"!=this.previousCommand.toLowerCase()&&"s"!=this.previousCommand.toLowerCase()&&"q"!=this.previousCommand.toLowerCase()&&"t"!=this.previousCommand.toLowerCase())return this.current;var i=new N.Point(2*this.current.x-this.control.x,2*this.current.y-this.control.y);return i},this.makeAbsolute=function(J){return this.isRelativeCommand()&&(J.x+=this.current.x,J.y+=this.current.y),J},this.addMarker=function(c,B,R){null!=R&&this.angles.length>0&&null==this.angles[this.angles.length-1]&&(this.angles[this.angles.length-1]=this.points[this.points.length-1].angleTo(R)),this.addMarkerAngle(c,null==B?null:B.angleTo(c))},this.addMarkerAngle=function(X,Q){this.points.push(X),this.angles.push(Q)},this.getMarkerPoints=function(){return this.points},this.getMarkerAngles=function(){for(var q=0;q<this.angles.length;q++)if(null==this.angles[q])for(var D=q+1;D<this.angles.length;D++)if(null!=this.angles[D]){this.angles[q]=this.angles[D];break}return this.angles}}(s),this.path=function(V){var p=this.PathParser;p.reset();var g=new N.BoundingBox;for(null!=V&&V.beginPath();!p.isEnd();)switch(p.nextCommand(),p.command){case"M":case"m":var G=p.getAsCurrentPoint();for(p.addMarker(G),g.addPoint(G.x,G.y),null!=V&&V.moveTo(G.x,G.y),p.start=p.current;!p.isCommandOrEnd();){var G=p.getAsCurrentPoint();p.addMarker(G,p.start),g.addPoint(G.x,G.y),null!=V&&V.lineTo(G.x,G.y)}break;case"L":case"l":for(;!p.isCommandOrEnd();){var M=p.current,G=p.getAsCurrentPoint();p.addMarker(G,M),g.addPoint(G.x,G.y),null!=V&&V.lineTo(G.x,G.y)}break;case"H":case"h":for(;!p.isCommandOrEnd();){var o=new N.Point((p.isRelativeCommand()?p.current.x:0)+p.getScalar(),p.current.y);p.addMarker(o,p.current),p.current=o,g.addPoint(p.current.x,p.current.y),null!=V&&V.lineTo(p.current.x,p.current.y)}break;case"V":case"v":for(;!p.isCommandOrEnd();){var o=new N.Point(p.current.x,(p.isRelativeCommand()?p.current.y:0)+p.getScalar());p.addMarker(o,p.current),p.current=o,g.addPoint(p.current.x,p.current.y),null!=V&&V.lineTo(p.current.x,p.current.y)}break;case"C":case"c":for(;!p.isCommandOrEnd();){var S=p.current,X=p.getPoint(),k=p.getAsControlPoint(),T=p.getAsCurrentPoint();p.addMarker(T,k,X),g.addBezierCurve(S.x,S.y,X.x,X.y,k.x,k.y,T.x,T.y),null!=V&&V.bezierCurveTo(X.x,X.y,k.x,k.y,T.x,T.y)}break;case"S":case"s":for(;!p.isCommandOrEnd();){var S=p.current,X=p.getReflectedControlPoint(),k=p.getAsControlPoint(),T=p.getAsCurrentPoint();p.addMarker(T,k,X),g.addBezierCurve(S.x,S.y,X.x,X.y,k.x,k.y,T.x,T.y),null!=V&&V.bezierCurveTo(X.x,X.y,k.x,k.y,T.x,T.y)}break;case"Q":case"q":for(;!p.isCommandOrEnd();){var S=p.current,k=p.getAsControlPoint(),T=p.getAsCurrentPoint();p.addMarker(T,k,k),g.addQuadraticCurve(S.x,S.y,k.x,k.y,T.x,T.y),null!=V&&V.quadraticCurveTo(k.x,k.y,T.x,T.y)}break;case"T":case"t":for(;!p.isCommandOrEnd();){var S=p.current,k=p.getReflectedControlPoint();p.control=k;var T=p.getAsCurrentPoint();p.addMarker(T,k,k),g.addQuadraticCurve(S.x,S.y,k.x,k.y,T.x,T.y),null!=V&&V.quadraticCurveTo(k.x,k.y,T.x,T.y)}break;case"A":case"a":for(;!p.isCommandOrEnd();){var S=p.current,b=p.getScalar(),d=p.getScalar(),h=p.getScalar()*(Math.PI/180),U=p.getScalar(),C=p.getScalar(),T=p.getAsCurrentPoint(),r=new N.Point(Math.cos(h)*(S.x-T.x)/2+Math.sin(h)*(S.y-T.y)/2,-Math.sin(h)*(S.x-T.x)/2+Math.cos(h)*(S.y-T.y)/2),y=Math.pow(r.x,2)/Math.pow(b,2)+Math.pow(r.y,2)/Math.pow(d,2);y>1&&(b*=Math.sqrt(y),d*=Math.sqrt(y));var _=(U==C?-1:1)*Math.sqrt((Math.pow(b,2)*Math.pow(d,2)-Math.pow(b,2)*Math.pow(r.y,2)-Math.pow(d,2)*Math.pow(r.x,2))/(Math.pow(b,2)*Math.pow(r.y,2)+Math.pow(d,2)*Math.pow(r.x,2)));isNaN(_)&&(_=0);var E=new N.Point(_*b*r.y/d,_*-d*r.x/b),K=new N.Point((S.x+T.x)/2+Math.cos(h)*E.x-Math.sin(h)*E.y,(S.y+T.y)/2+Math.sin(h)*E.x+Math.cos(h)*E.y),f=function(z){return Math.sqrt(Math.pow(z[0],2)+Math.pow(z[1],2))},u=function(w,_){return(w[0]*_[0]+w[1]*_[1])/(f(w)*f(_))},s=function(U,y){return(U[0]*y[1]<U[1]*y[0]?-1:1)*Math.acos(u(U,y))},l=s([1,0],[(r.x-E.x)/b,(r.y-E.y)/d]),F=[(r.x-E.x)/b,(r.y-E.y)/d],v=[(-r.x-E.x)/b,(-r.y-E.y)/d],c=s(F,v);u(F,v)<=-1&&(c=Math.PI),u(F,v)>=1&&(c=0);var O=1-C?1:-1,D=l+O*(c/2),z=new N.Point(K.x+b*Math.cos(D),K.y+d*Math.sin(D));if(p.addMarkerAngle(z,D-O*Math.PI/2),p.addMarkerAngle(T,D-O*Math.PI),g.addPoint(T.x,T.y),null!=V){var u=b>d?b:d,L=b>d?1:b/d,x=b>d?d/b:1;V.translate(K.x,K.y),V.rotate(h),V.scale(L,x),V.arc(0,0,u,l,l+c,1-C),V.scale(1/L,1/x),V.rotate(-h),V.translate(-K.x,-K.y)}}break;case"Z":case"z":null!=V&&V.closePath(),p.current=p.start}return g},this.getMarkers=function(){for(var G=this.PathParser.getMarkerPoints(),D=this.PathParser.getMarkerAngles(),$=[],r=0;r<G.length;r++)$.push([G[r],D[r]]);return $}},N.Element.path.prototype=new N.Element.PathElementBase,N.Element.pattern=function(Q){this.base=N.Element.ElementBase,this.base(Q),this.createPattern=function(t){var f=this.attribute("width").toPixels("x",!0),z=this.attribute("height").toPixels("y",!0),o=new N.Element.svg;o.attributes.viewBox=new N.Property("viewBox",this.attribute("viewBox").value),o.attributes.width=new N.Property("width",f+"px"),o.attributes.height=new N.Property("height",z+"px"),o.attributes.transform=new N.Property("transform",this.attribute("patternTransform").value),o.children=this.children;var L=document.createElement("canvas");L.width=f,L.height=z;var X=L.getContext("2d");this.attribute("x").hasValue()&&this.attribute("y").hasValue()&&X.translate(this.attribute("x").toPixels("x",!0),this.attribute("y").toPixels("y",!0));for(var T=-1;1>=T;T++)for(var q=-1;1>=q;q++)X.save(),o.attributes.x=new N.Property("x",T*L.width),o.attributes.y=new N.Property("y",q*L.height),o.render(X),X.restore();var s=t.createPattern(L,"repeat");return s}},N.Element.pattern.prototype=new N.Element.ElementBase,N.Element.marker=function(p){this.base=N.Element.ElementBase,this.base(p),this.baseRender=this.render,this.render=function(x,W,Y){x.translate(W.x,W.y),"auto"==this.attribute("orient").valueOrDefault("auto")&&x.rotate(Y),"strokeWidth"==this.attribute("markerUnits").valueOrDefault("strokeWidth")&&x.scale(x.lineWidth,x.lineWidth),x.save();var q=new N.Element.svg;q.attributes.viewBox=new N.Property("viewBox",this.attribute("viewBox").value),q.attributes.refX=new N.Property("refX",this.attribute("refX").value),q.attributes.refY=new N.Property("refY",this.attribute("refY").value),q.attributes.width=new N.Property("width",this.attribute("markerWidth").value),q.attributes.height=new N.Property("height",this.attribute("markerHeight").value),q.attributes.fill=new N.Property("fill",this.attribute("fill").valueOrDefault("black")),q.attributes.stroke=new N.Property("stroke",this.attribute("stroke").valueOrDefault("none")),q.children=this.children,q.render(x),x.restore(),"strokeWidth"==this.attribute("markerUnits").valueOrDefault("strokeWidth")&&x.scale(1/x.lineWidth,1/x.lineWidth),"auto"==this.attribute("orient").valueOrDefault("auto")&&x.rotate(-Y),x.translate(-W.x,-W.y)}},N.Element.marker.prototype=new N.Element.ElementBase,N.Element.defs=function(b){this.base=N.Element.ElementBase,this.base(b),this.render=function(){}},N.Element.defs.prototype=new N.Element.ElementBase,N.Element.GradientBase=function(O){this.base=N.Element.ElementBase,this.base(O),this.stops=[];for(var h=0;h<this.children.length;h++){var B=this.children[h];"stop"==B.type&&this.stops.push(B)}this.getGradient=function(){},this.gradientUnits=function(){return this.attribute("gradientUnits").valueOrDefault("objectBoundingBox")},this.attributesToInherit=["gradientUnits"],this.inheritStopContainer=function(k){for(var B=0;B<this.attributesToInherit.length;B++){var D=this.attributesToInherit[B];!this.attribute(D).hasValue()&&k.attribute(D).hasValue()&&(this.attribute(D,!0).value=k.attribute(D).value)}},this.createGradient=function(u,v,W){var y=this;this.getHrefAttribute().hasValue()&&(y=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(y));var $=function(I){if(W.hasValue()){var O=new N.Property("color",I);return O.addOpacity(W).value}return I},i=this.getGradient(u,v);if(null==i)return $(y.stops[y.stops.length-1].color);for(var e=0;e<y.stops.length;e++)i.addColorStop(y.stops[e].offset,$(y.stops[e].color));if(this.attribute("gradientTransform").hasValue()){var m=N.ViewPort.viewPorts[0],n=new N.Element.rect;n.attributes.x=new N.Property("x",-N.MAX_VIRTUAL_PIXELS/3),n.attributes.y=new N.Property("y",-N.MAX_VIRTUAL_PIXELS/3),n.attributes.width=new N.Property("width",N.MAX_VIRTUAL_PIXELS),n.attributes.height=new N.Property("height",N.MAX_VIRTUAL_PIXELS);var U=new N.Element.g;U.attributes.transform=new N.Property("transform",this.attribute("gradientTransform").value),U.children=[n];var l=new N.Element.svg;l.attributes.x=new N.Property("x",0),l.attributes.y=new N.Property("y",0),l.attributes.width=new N.Property("width",m.width),l.attributes.height=new N.Property("height",m.height),l.children=[U];var o=document.createElement("canvas");o.width=m.width,o.height=m.height;var p=o.getContext("2d");return p.fillStyle=i,l.render(p),p.createPattern(o,"no-repeat")}return i}},N.Element.GradientBase.prototype=new N.Element.ElementBase,N.Element.linearGradient=function(G){this.base=N.Element.GradientBase,this.base(G),this.attributesToInherit.push("x1"),this.attributesToInherit.push("y1"),this.attributesToInherit.push("x2"),this.attributesToInherit.push("y2"),this.getGradient=function(e,T){var K="objectBoundingBox"==this.gradientUnits()?T.getBoundingBox():null;this.attribute("x1").hasValue()||this.attribute("y1").hasValue()||this.attribute("x2").hasValue()||this.attribute("y2").hasValue()||(this.attribute("x1",!0).value=0,this.attribute("y1",!0).value=0,this.attribute("x2",!0).value=1,this.attribute("y2",!0).value=0);var z="objectBoundingBox"==this.gradientUnits()?K.x()+K.width()*this.attribute("x1").numValue():this.attribute("x1").toPixels("x"),G="objectBoundingBox"==this.gradientUnits()?K.y()+K.height()*this.attribute("y1").numValue():this.attribute("y1").toPixels("y"),D="objectBoundingBox"==this.gradientUnits()?K.x()+K.width()*this.attribute("x2").numValue():this.attribute("x2").toPixels("x"),I="objectBoundingBox"==this.gradientUnits()?K.y()+K.height()*this.attribute("y2").numValue():this.attribute("y2").toPixels("y");return z==D&&G==I?null:e.createLinearGradient(z,G,D,I)}},N.Element.linearGradient.prototype=new N.Element.GradientBase,N.Element.radialGradient=function(G){this.base=N.Element.GradientBase,this.base(G),this.attributesToInherit.push("cx"),this.attributesToInherit.push("cy"),this.attributesToInherit.push("r"),this.attributesToInherit.push("fx"),this.attributesToInherit.push("fy"),this.getGradient=function($,K){var s=K.getBoundingBox();this.attribute("cx").hasValue()||(this.attribute("cx",!0).value="50%"),this.attribute("cy").hasValue()||(this.attribute("cy",!0).value="50%"),this.attribute("r").hasValue()||(this.attribute("r",!0).value="50%");var N="objectBoundingBox"==this.gradientUnits()?s.x()+s.width()*this.attribute("cx").numValue():this.attribute("cx").toPixels("x"),B="objectBoundingBox"==this.gradientUnits()?s.y()+s.height()*this.attribute("cy").numValue():this.attribute("cy").toPixels("y"),p=N,y=B;this.attribute("fx").hasValue()&&(p="objectBoundingBox"==this.gradientUnits()?s.x()+s.width()*this.attribute("fx").numValue():this.attribute("fx").toPixels("x")),this.attribute("fy").hasValue()&&(y="objectBoundingBox"==this.gradientUnits()?s.y()+s.height()*this.attribute("fy").numValue():this.attribute("fy").toPixels("y"));var h="objectBoundingBox"==this.gradientUnits()?(s.width()+s.height())/2*this.attribute("r").numValue():this.attribute("r").toPixels();return $.createRadialGradient(p,y,0,N,B,h)}},N.Element.radialGradient.prototype=new N.Element.GradientBase,N.Element.stop=function(D){this.base=N.Element.ElementBase,this.base(D),this.offset=this.attribute("offset").numValue(),this.offset<0&&(this.offset=0),this.offset>1&&(this.offset=1);var t=this.style("stop-color",!0);""===t.value&&(t.value="#000"),this.style("stop-opacity").hasValue()&&(t=t.addOpacity(this.style("stop-opacity"))),this.color=t.value},N.Element.stop.prototype=new N.Element.ElementBase,N.Element.AnimateBase=function(j){this.base=N.Element.ElementBase,this.base(j),N.Animations.push(this),this.duration=0,this.begin=this.attribute("begin").toMilliseconds(),this.maxDuration=this.begin+this.attribute("dur").toMilliseconds(),this.getProperty=function(){var Q=this.attribute("attributeType").value,x=this.attribute("attributeName").value;return"CSS"==Q?this.parent.style(x,!0):this.parent.attribute(x,!0)},this.initialValue=null,this.initialUnits="",this.removed=!1,this.calcValue=function(){return""},this.update=function(i){if(null==this.initialValue&&(this.initialValue=this.getProperty().value,this.initialUnits=this.getProperty().getUnits()),this.duration>this.maxDuration){if("indefinite"==this.attribute("repeatCount").value||"indefinite"==this.attribute("repeatDur").value)this.duration=0;else if("freeze"!=this.attribute("fill").valueOrDefault("remove")||this.frozen){if("remove"==this.attribute("fill").valueOrDefault("remove")&&!this.removed)return this.removed=!0,this.getProperty().value=this.parent.animationFrozen?this.parent.animationFrozenValue:this.initialValue,!0}else this.frozen=!0,this.parent.animationFrozen=!0,this.parent.animationFrozenValue=this.getProperty().value;return!1}this.duration=this.duration+i;var s=!1;if(this.begin<this.duration){var o=this.calcValue();if(this.attribute("type").hasValue()){var h=this.attribute("type").value;o=h+"("+o+")"}this.getProperty().value=o,s=!0}return s},this.from=this.attribute("from"),this.to=this.attribute("to"),this.values=this.attribute("values"),this.values.hasValue()&&(this.values.value=this.values.value.split(";")),this.progress=function(){var g={progress:(this.duration-this.begin)/(this.maxDuration-this.begin)};if(this.values.hasValue()){var D=g.progress*(this.values.value.length-1),Z=Math.floor(D),n=Math.ceil(D);g.from=new N.Property("from",parseFloat(this.values.value[Z])),g.to=new N.Property("to",parseFloat(this.values.value[n])),g.progress=(D-Z)/(n-Z)}else g.from=this.from,g.to=this.to;return g}},N.Element.AnimateBase.prototype=new N.Element.ElementBase,N.Element.animate=function(n){this.base=N.Element.AnimateBase,this.base(n),this.calcValue=function(){var t=this.progress(),W=t.from.numValue()+(t.to.numValue()-t.from.numValue())*t.progress;return W+this.initialUnits}},N.Element.animate.prototype=new N.Element.AnimateBase,N.Element.animateColor=function(g){this.base=N.Element.AnimateBase,this.base(g),this.calcValue=function(){var V=this.progress(),$=new Q(V.from.value),o=new Q(V.to.value);if($.ok&&o.ok){var t=$.r+(o.r-$.r)*V.progress,H=$.g+(o.g-$.g)*V.progress,m=$.b+(o.b-$.b)*V.progress;return"rgb("+parseInt(t,10)+","+parseInt(H,10)+","+parseInt(m,10)+")"}return this.attribute("from").value}},N.Element.animateColor.prototype=new N.Element.AnimateBase,N.Element.animateTransform=function(J){this.base=N.Element.AnimateBase,this.base(J),this.calcValue=function(){for(var E=this.progress(),u=N.ToNumberArray(E.from.value),z=N.ToNumberArray(E.to.value),j="",W=0;W<u.length;W++)j+=u[W]+(z[W]-u[W])*E.progress+" ";return j}},N.Element.animateTransform.prototype=new N.Element.animate,N.Element.font=function(U){this.base=N.Element.ElementBase,this.base(U),this.horizAdvX=this.attribute("horiz-adv-x").numValue(),this.isRTL=!1,this.isArabic=!1,this.fontFace=null,this.missingGlyph=null,this.glyphs=[];for(var z=0;z<this.children.length;z++){var $=this.children[z];"font-face"==$.type?(this.fontFace=$,$.style("font-family").hasValue()&&(N.Definitions[$.style("font-family").value]=this)):"missing-glyph"==$.type?this.missingGlyph=$:"glyph"==$.type&&(""!=$.arabicForm?(this.isRTL=!0,this.isArabic=!0,"undefined"==typeof this.glyphs[$.unicode]&&(this.glyphs[$.unicode]=[]),this.glyphs[$.unicode][$.arabicForm]=$):this.glyphs[$.unicode]=$)}},N.Element.font.prototype=new N.Element.ElementBase,N.Element.fontface=function(K){this.base=N.Element.ElementBase,this.base(K),this.ascent=this.attribute("ascent").value,this.descent=this.attribute("descent").value,this.unitsPerEm=this.attribute("units-per-em").numValue()},N.Element.fontface.prototype=new N.Element.ElementBase,N.Element.missingglyph=function(k){this.base=N.Element.path,this.base(k),this.horizAdvX=0},N.Element.missingglyph.prototype=new N.Element.path,N.Element.glyph=function(_){this.base=N.Element.path,this.base(_),this.horizAdvX=this.attribute("horiz-adv-x").numValue(),this.unicode=this.attribute("unicode").value,this.arabicForm=this.attribute("arabic-form").value},N.Element.glyph.prototype=new N.Element.path,N.Element.text=function($){this.captureTextNodes=!0,this.base=N.Element.RenderedElementBase,this.base($),this.baseSetContext=this.setContext,this.setContext=function(o){this.baseSetContext(o);var P=this.style("dominant-baseline").toTextBaseline();null==P&&(P=this.style("alignment-baseline").toTextBaseline()),null!=P&&(o.textBaseline=P)},this.getBoundingBox=function(){var r=this.attribute("x").toPixels("x"),y=this.attribute("y").toPixels("y"),H=this.parent.style("font-size").numValueOrDefault(N.Font.Parse(N.ctx.font).fontSize);return new N.BoundingBox(r,y-H,r+Math.floor(2*H/3)*this.children[0].getText().length,y)},this.renderChildren=function(B){this.x=this.attribute("x").toPixels("x"),this.y=this.attribute("y").toPixels("y"),this.attribute("dx").hasValue()&&(this.x+=this.attribute("dx").toPixels("x")),this.attribute("dy").hasValue()&&(this.y+=this.attribute("dy").toPixels("y")),this.x+=this.getAnchorDelta(B,this,0);for(var z=0;z<this.children.length;z++)this.renderChild(B,this,this,z)},this.getAnchorDelta=function(U,Y,i){var $=this.style("text-anchor").valueOrDefault("start");if("start"!=$){for(var V=0,Z=i;Z<Y.children.length;Z++){var g=Y.children[Z];if(Z>i&&g.attribute("x").hasValue())break;V+=g.measureTextRecursive(U)}return-1*("end"==$?V:V/2)}return 0},this.renderChild=function(d,T,Z,U){var $=Z.children[U];$.attribute("x").hasValue()?($.x=$.attribute("x").toPixels("x")+T.getAnchorDelta(d,Z,U),$.attribute("dx").hasValue()&&($.x+=$.attribute("dx").toPixels("x"))):($.attribute("dx").hasValue()&&(T.x+=$.attribute("dx").toPixels("x")),$.x=T.x),T.x=$.x+$.measureText(d),$.attribute("y").hasValue()?($.y=$.attribute("y").toPixels("y"),$.attribute("dy").hasValue()&&($.y+=$.attribute("dy").toPixels("y"))):($.attribute("dy").hasValue()&&(T.y+=$.attribute("dy").toPixels("y")),$.y=T.y),T.y=$.y,$.render(d);for(var U=0;U<$.children.length;U++)T.renderChild(d,T,$,U)}},N.Element.text.prototype=new N.Element.RenderedElementBase,N.Element.TextElementBase=function(d){this.base=N.Element.RenderedElementBase,this.base(d),this.getGlyph=function(j,b,n){var F=b[n],P=null;if(j.isArabic){var Y="isolated";(0==n||" "==b[n-1])&&n<b.length-2&&" "!=b[n+1]&&(Y="terminal"),n>0&&" "!=b[n-1]&&n<b.length-2&&" "!=b[n+1]&&(Y="medial"),n>0&&" "!=b[n-1]&&(n==b.length-1||" "==b[n+1])&&(Y="initial"),"undefined"!=typeof j.glyphs[F]&&(P=j.glyphs[F][Y],null==P&&"glyph"==j.glyphs[F].type&&(P=j.glyphs[F]))
  3. }else P=j.glyphs[F];return null==P&&(P=j.missingGlyph),P},this.renderChildren=function(Y){var j=this.parent.style("font-family").getDefinition();if(null==j)""!=Y.fillStyle&&Y.fillText(N.compressSpaces(this.getText()),this.x,this.y),""!=Y.strokeStyle&&Y.strokeText(N.compressSpaces(this.getText()),this.x,this.y);else{var R=this.parent.style("font-size").numValueOrDefault(N.Font.Parse(N.ctx.font).fontSize),l=this.parent.style("font-style").valueOrDefault(N.Font.Parse(N.ctx.font).fontStyle),W=this.getText();j.isRTL&&(W=W.split("").reverse().join(""));for(var p=N.ToNumberArray(this.parent.attribute("dx").value),h=0;h<W.length;h++){var w=this.getGlyph(j,W,h),O=R/j.fontFace.unitsPerEm;Y.translate(this.x,this.y),Y.scale(O,-O);var s=Y.lineWidth;Y.lineWidth=Y.lineWidth*j.fontFace.unitsPerEm/R,"italic"==l&&Y.transform(1,0,.4,1,0,0),w.render(Y),"italic"==l&&Y.transform(1,0,-.4,1,0,0),Y.lineWidth=s,Y.scale(1/O,-1/O),Y.translate(-this.x,-this.y),this.x+=R*(w.horizAdvX||j.horizAdvX)/j.fontFace.unitsPerEm,"undefined"==typeof p[h]||isNaN(p[h])||(this.x+=p[h])}}},this.getText=function(){},this.measureTextRecursive=function(H){for(var k=this.measureText(H),q=0;q<this.children.length;q++)k+=this.children[q].measureTextRecursive(H);return k},this.measureText=function(h){var k=this.parent.style("font-family").getDefinition();if(null!=k){var s=this.parent.style("font-size").numValueOrDefault(N.Font.Parse(N.ctx.font).fontSize),i=0,A=this.getText();k.isRTL&&(A=A.split("").reverse().join(""));for(var K=N.ToNumberArray(this.parent.attribute("dx").value),R=0;R<A.length;R++){var $=this.getGlyph(k,A,R);i+=($.horizAdvX||k.horizAdvX)*s/k.fontFace.unitsPerEm,"undefined"==typeof K[R]||isNaN(K[R])||(i+=K[R])}return i}var a=N.compressSpaces(this.getText());if(!h.measureText)return 10*a.length;h.save(),this.setContext(h);var H=h.measureText(a).width;return h.restore(),H}},N.Element.TextElementBase.prototype=new N.Element.RenderedElementBase,N.Element.tspan=function(I){this.captureTextNodes=!0,this.base=N.Element.TextElementBase,this.base(I),this.text=N.compressSpaces(I.value||I.text||I.textContent||""),this.getText=function(){return this.children.length>0?"":this.text}},N.Element.tspan.prototype=new N.Element.TextElementBase,N.Element.tref=function(m){this.base=N.Element.TextElementBase,this.base(m),this.getText=function(){var s=this.getHrefAttribute().getDefinition();return null!=s?s.children[0].getText():void 0}},N.Element.tref.prototype=new N.Element.TextElementBase,N.Element.a=function(p){this.base=N.Element.TextElementBase,this.base(p),this.hasText=p.childNodes.length>0;for(var B=0;B<p.childNodes.length;B++)3!=p.childNodes[B].nodeType&&(this.hasText=!1);this.text=this.hasText?p.childNodes[0].value:"",this.getText=function(){return this.text},this.baseRenderChildren=this.renderChildren,this.renderChildren=function(K){if(this.hasText){this.baseRenderChildren(K);var e=new N.Property("fontSize",N.Font.Parse(N.ctx.font).fontSize);N.Mouse.checkBoundingBox(this,new N.BoundingBox(this.x,this.y-e.toPixels("y"),this.x+this.measureText(K),this.y))}else if(this.children.length>0){var F=new N.Element.g;F.children=this.children,F.parent=this,F.render(K)}},this.onclick=function(){G.open(this.getHrefAttribute().value)},this.onmousemove=function(){N.ctx.canvas.style.cursor="pointer"}},N.Element.a.prototype=new N.Element.TextElementBase,N.Element.image=function(P){this.base=N.Element.RenderedElementBase,this.base(P);var E=this.getHrefAttribute().value;if(""!=E){var z=E.match(/\.svg$/);if(N.Images.push(this),this.loaded=!1,z)this.img=N.ajax(E),this.loaded=!0;else{this.img=document.createElement("img"),1==N.opts.useCORS&&(this.img.crossOrigin="Anonymous");var A=this;this.img.onload=function(){A.loaded=!0},this.img.onerror=function(){N.log('ERROR: image "'+E+'" not found'),A.loaded=!0},this.img.src=E}this.renderChildren=function(D){var R=this.attribute("x").toPixels("x"),_=this.attribute("y").toPixels("y"),n=this.attribute("width").toPixels("x"),Z=this.attribute("height").toPixels("y");0!=n&&0!=Z&&(D.save(),z?D.drawSvg(this.img,R,_,n,Z):(D.translate(R,_),N.AspectRatio(D,this.attribute("preserveAspectRatio").value,n,this.img.width,Z,this.img.height,0,0),D.drawImage(this.img,0,0)),D.restore())},this.getBoundingBox=function(){var B=this.attribute("x").toPixels("x"),O=this.attribute("y").toPixels("y"),E=this.attribute("width").toPixels("x"),V=this.attribute("height").toPixels("y");return new N.BoundingBox(B,O,B+E,O+V)}}},N.Element.image.prototype=new N.Element.RenderedElementBase,N.Element.g=function(x){this.base=N.Element.RenderedElementBase,this.base(x),this.getBoundingBox=function(){for(var L=new N.BoundingBox,z=0;z<this.children.length;z++)L.addBoundingBox(this.children[z].getBoundingBox());return L}},N.Element.g.prototype=new N.Element.RenderedElementBase,N.Element.symbol=function(v){this.base=N.Element.RenderedElementBase,this.base(v),this.render=function(){}},N.Element.symbol.prototype=new N.Element.RenderedElementBase,N.Element.style=function(J){this.base=N.Element.ElementBase,this.base(J);for(var S="",g=0;g<J.childNodes.length;g++)S+=J.childNodes[g].data;S=S.replace(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,""),S=N.compressSpaces(S);for(var Z=S.split("}"),g=0;g<Z.length;g++)if(""!=N.trim(Z[g]))for(var $=Z[g].split("{"),w=$[0].split(","),o=$[1].split(";"),k=0;k<w.length;k++){var P=N.trim(w[k]);if(""!=P){for(var F=N.Styles[P]||{},Y=0;Y<o.length;Y++){var U=o[Y].indexOf(":"),A=o[Y].substr(0,U),O=o[Y].substr(U+1,o[Y].length-U);null!=A&&null!=O&&(F[N.trim(A)]=new N.Property(N.trim(A),N.trim(O)))}if(N.Styles[P]=F,N.StylesSpecificity[P]=_(P),"@font-face"==P)for(var V=F["font-family"].value.replace(/"/g,""),Q=F.src.value.split(","),G=0;G<Q.length;G++)if(Q[G].indexOf('format("svg")')>0)for(var c=Q[G].indexOf("url"),v=Q[G].indexOf(")",c),H=Q[G].substr(c+5,v-c-6),l=N.parseXml(N.ajax(H)),p=l.getElementsByTagName("font"),m=0;m<p.length;m++){var u=N.CreateElement(p[m]);N.Definitions[V]=u}}}},N.Element.style.prototype=new N.Element.ElementBase,N.Element.use=function(X){this.base=N.Element.RenderedElementBase,this.base(X),this.baseSetContext=this.setContext,this.setContext=function(s){this.baseSetContext(s),this.attribute("x").hasValue()&&s.translate(this.attribute("x").toPixels("x"),0),this.attribute("y").hasValue()&&s.translate(0,this.attribute("y").toPixels("y"))};var O=this.getHrefAttribute().getDefinition();this.path=function(u){null!=O&&O.path(u)},this.getBoundingBox=function(){return null!=O?O.getBoundingBox():void 0},this.renderChildren=function(i){if(null!=O){var S=O;"symbol"==O.type&&(S=new N.Element.svg,S.type="svg",S.attributes.viewBox=new N.Property("viewBox",O.attribute("viewBox").value),S.attributes.preserveAspectRatio=new N.Property("preserveAspectRatio",O.attribute("preserveAspectRatio").value),S.attributes.overflow=new N.Property("overflow",O.attribute("overflow").value),S.children=O.children),"svg"==S.type&&(this.attribute("width").hasValue()&&(S.attributes.width=new N.Property("width",this.attribute("width").value)),this.attribute("height").hasValue()&&(S.attributes.height=new N.Property("height",this.attribute("height").value)));var P=S.parent;S.parent=null,S.render(i),S.parent=P}}},N.Element.use.prototype=new N.Element.RenderedElementBase,N.Element.mask=function(j){this.base=N.Element.ElementBase,this.base(j),this.apply=function(e,Z){var Q=this.attribute("x").toPixels("x"),$=this.attribute("y").toPixels("y"),T=this.attribute("width").toPixels("x"),E=this.attribute("height").toPixels("y");if(0==T&&0==E){for(var n=new N.BoundingBox,X=0;X<this.children.length;X++)n.addBoundingBox(this.children[X].getBoundingBox());var Q=Math.floor(n.x1),$=Math.floor(n.y1),T=Math.floor(n.width()),E=Math.floor(n.height())}var U=Z.attribute("mask").value;Z.attribute("mask").value="";var K=document.createElement("canvas");K.width=Q+T,K.height=$+E;var O=K.getContext("2d");if(this.renderChildren(O),K.width&&K.height){var y=document.createElement("canvas");y.width=Q+T,y.height=$+E;var S=y.getContext("2d");Z.render(S),S.globalCompositeOperation="destination-in",S.fillStyle=O.createPattern(K,"no-repeat"),S.fillRect(0,0,Q+T,$+E),e.fillStyle=S.createPattern(y,"no-repeat"),e.fillRect(0,0,Q+T,$+E),Z.attribute("mask").value=U}},this.render=function(){}},N.Element.mask.prototype=new N.Element.ElementBase,N.Element.clipPath=function(a){this.base=N.Element.ElementBase,this.base(a),this.apply=function(j){var S=CanvasRenderingContext2D.prototype.beginPath;CanvasRenderingContext2D.prototype.beginPath=function(){};var g=CanvasRenderingContext2D.prototype.closePath;CanvasRenderingContext2D.prototype.closePath=function(){},S.call(j);for(var n=0;n<this.children.length;n++){var l=this.children[n];if("undefined"!=typeof l.path){var W=null;l.style("transform",!1,!0).hasValue()&&(W=new N.Transform(l.style("transform",!1,!0).value),W.apply(j)),l.path(j),CanvasRenderingContext2D.prototype.closePath=g,W&&W.unapply(j)}}g.call(j),j.clip(),CanvasRenderingContext2D.prototype.beginPath=S,CanvasRenderingContext2D.prototype.closePath=g},this.render=function(){}},N.Element.clipPath.prototype=new N.Element.ElementBase,N.Element.filter=function(E){this.base=N.Element.ElementBase,this.base(E),this.apply=function(n,W){var D=W.getBoundingBox(),Y=Math.floor(D.x1),U=Math.floor(D.y1),K=Math.floor(D.width()),a=Math.floor(D.height()),x=W.style("filter").value;W.style("filter").value="";for(var h=0,k=0,r=0;r<this.children.length;r++){var S=this.children[r].extraFilterDistance||0;h=Math.max(h,S),k=Math.max(k,S)}var _=document.createElement("canvas");_.width=K+2*h,_.height=a+2*k;var A=_.getContext("2d");A.translate(-Y+h,-U+k),W.render(A);for(var r=0;r<this.children.length;r++)"function"==typeof this.children[r].apply&&this.children[r].apply(A,0,0,K+2*h,a+2*k);n.drawImage(_,0,0,K+2*h,a+2*k,Y-h,U-k,K+2*h,a+2*k),W.style("filter",!0).value=x},this.render=function(){}},N.Element.filter.prototype=new N.Element.ElementBase,N.Element.feMorphology=function(k){this.base=N.Element.ElementBase,this.base(k),this.apply=function(){}},N.Element.feMorphology.prototype=new N.Element.ElementBase,N.Element.feComposite=function(R){this.base=N.Element.ElementBase,this.base(R),this.apply=function(){}},N.Element.feComposite.prototype=new N.Element.ElementBase,N.Element.feColorMatrix=function(y){function t(o,H,R,x,G,N){return o[4*R*x+4*H+N]}function m(J,u,M,O,G,W,y){J[4*M*O+4*u+W]=y}function P(V,R){var Y=L[V];return Y*(0>Y?R-255:R)}this.base=N.Element.ElementBase,this.base(y);var L=N.ToNumberArray(this.attribute("values").value);switch(this.attribute("type").valueOrDefault("matrix")){case"saturate":var T=L[0];L=[.213+.787*T,.715-.715*T,.072-.072*T,0,0,.213-.213*T,.715+.285*T,.072-.072*T,0,0,.213-.213*T,.715-.715*T,.072+.928*T,0,0,0,0,0,1,0,0,0,0,0,1];break;case"hueRotate":var c=L[0]*Math.PI/180,b=function(V,O,d){return V+Math.cos(c)*O+Math.sin(c)*d};L=[b(.213,.787,-.213),b(.715,-.715,-.715),b(.072,-.072,.928),0,0,b(.213,-.213,.143),b(.715,.285,.14),b(.072,-.072,-.283),0,0,b(.213,-.213,-.787),b(.715,-.715,.715),b(.072,.928,.072),0,0,0,0,0,1,0,0,0,0,0,1];break;case"luminanceToAlpha":L=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.2125,.7154,.0721,0,0,0,0,0,0,1]}this.apply=function(d,Z,s,H,T){if(H&&T){for(var f=d.getImageData(0,0,H,T),s=0;T>s;s++)for(var Z=0;H>Z;Z++){var h=t(f.data,Z,s,H,T,0),O=t(f.data,Z,s,H,T,1),S=t(f.data,Z,s,H,T,2),G=t(f.data,Z,s,H,T,3);m(f.data,Z,s,H,T,0,P(0,h)+P(1,O)+P(2,S)+P(3,G)+P(4,1)),m(f.data,Z,s,H,T,1,P(5,h)+P(6,O)+P(7,S)+P(8,G)+P(9,1)),m(f.data,Z,s,H,T,2,P(10,h)+P(11,O)+P(12,S)+P(13,G)+P(14,1)),m(f.data,Z,s,H,T,3,P(15,h)+P(16,O)+P(17,S)+P(18,G)+P(19,1))}d.clearRect(0,0,H,T),d.putImageData(f,0,0)}}},N.Element.feColorMatrix.prototype=new N.Element.ElementBase,N.Element.feGaussianBlur=function(B){this.base=N.Element.ElementBase,this.base(B),this.blurRadius=Math.floor(this.attribute("stdDeviation").numValue()),this.extraFilterDistance=this.blurRadius,this.apply=function(S,v,n,h,q){return"undefined"==typeof M.canvasRGBA?(N.log("ERROR: StackBlur.js must be included for blur to work"),void 0):(S.canvas.id=N.UniqueId(),S.canvas.style.display="none",document.body.appendChild(S.canvas),M.canvasRGBA(S.canvas.id,v,n,h,q,this.blurRadius),document.body.removeChild(S.canvas),void 0)}},N.Element.feGaussianBlur.prototype=new N.Element.ElementBase,N.Element.title=function(){},N.Element.title.prototype=new N.Element.ElementBase,N.Element.desc=function(){},N.Element.desc.prototype=new N.Element.ElementBase,N.Element.MISSING=function(l){N.log("ERROR: Element '"+l.nodeName+"' not yet implemented.")},N.Element.MISSING.prototype=new N.Element.ElementBase,N.CreateElement=function(l){var w=l.nodeName.replace(/^[^:]+:/,"");w=w.replace(/\-/g,"");var X=null;return X="undefined"!=typeof N.Element[w]?new N.Element[w](l):new N.Element.MISSING(l),X.type=l.nodeName,X},N.load=function(p,w){N.loadXml(p,N.ajax(w))},N.loadXml=function(m,u){N.loadXmlDoc(m,N.parseXml(u))},N.loadXmlDoc=function(v,t){N.init(v);var M=function(H){for(var E=v.canvas;E;)H.x-=E.offsetLeft,H.y-=E.offsetTop,E=E.offsetParent;return G.scrollX&&(H.x+=G.scrollX),G.scrollY&&(H.y+=G.scrollY),H};1!=N.opts.ignoreMouse&&(v.canvas.onclick=function(Q){var h=M(new N.Point(null!=Q?Q.clientX:event.clientX,null!=Q?Q.clientY:event.clientY));N.Mouse.onclick(h.x,h.y)},v.canvas.onmousemove=function(P){var h=M(new N.Point(null!=P?P.clientX:event.clientX,null!=P?P.clientY:event.clientY));N.Mouse.onmousemove(h.x,h.y)});var i=N.CreateElement(t.documentElement);i.root=!0,i.addStylesFromStyleDefinition();var x=!0,K=function(){N.ViewPort.Clear(),v.canvas.parentNode&&N.ViewPort.SetCurrent(v.canvas.parentNode.clientWidth,v.canvas.parentNode.clientHeight),1!=N.opts.ignoreDimensions&&(i.style("width").hasValue()&&(v.canvas.width=i.style("width").toPixels("x"),v.canvas.style.width=v.canvas.width+"px"),i.style("height").hasValue()&&(v.canvas.height=i.style("height").toPixels("y"),v.canvas.style.height=v.canvas.height+"px"));var j=v.canvas.clientWidth||v.canvas.width,g=v.canvas.clientHeight||v.canvas.height;if(1==N.opts.ignoreDimensions&&i.style("width").hasValue()&&i.style("height").hasValue()&&(j=i.style("width").toPixels("x"),g=i.style("height").toPixels("y")),N.ViewPort.SetCurrent(j,g),null!=N.opts.offsetX&&(i.attribute("x",!0).value=N.opts.offsetX),null!=N.opts.offsetY&&(i.attribute("y",!0).value=N.opts.offsetY),null!=N.opts.scaleWidth||null!=N.opts.scaleHeight){var D=null,Q=null,I=N.ToNumberArray(i.attribute("viewBox").value);null!=N.opts.scaleWidth&&(i.attribute("width").hasValue()?D=i.attribute("width").toPixels("x")/N.opts.scaleWidth:isNaN(I[2])||(D=I[2]/N.opts.scaleWidth)),null!=N.opts.scaleHeight&&(i.attribute("height").hasValue()?Q=i.attribute("height").toPixels("y")/N.opts.scaleHeight:isNaN(I[3])||(Q=I[3]/N.opts.scaleHeight)),null==D&&(D=Q),null==Q&&(Q=D),i.attribute("width",!0).value=N.opts.scaleWidth,i.attribute("height",!0).value=N.opts.scaleHeight,i.style("transform",!0,!0).value+=" scale("+1/D+","+1/Q+")"}1!=N.opts.ignoreClear&&v.clearRect(0,0,j,g),i.render(v),x&&(x=!1,"function"==typeof N.opts.renderCallback&&N.opts.renderCallback(t))},w=!0;N.ImagesLoaded()&&(w=!1,K()),N.intervalID=setInterval(function(){var e=!1;if(w&&N.ImagesLoaded()&&(w=!1,e=!0),1!=N.opts.ignoreMouse&&(e|=N.Mouse.hasEvents()),1!=N.opts.ignoreAnimation)for(var u=0;u<N.Animations.length;u++)e|=N.Animations[u].update(1e3/N.FRAMERATE);"function"==typeof N.opts.forceRedraw&&1==N.opts.forceRedraw()&&(e=!0),e&&(K(),N.Mouse.runEvents())},1e3/N.FRAMERATE)},N.stop=function(){N.intervalID&&clearInterval(N.intervalID)},N.Mouse=new function(){this.events=[],this.hasEvents=function(){return 0!=this.events.length},this.onclick=function(M,i){this.events.push({type:"onclick",x:M,y:i,run:function(M){M.onclick&&M.onclick()}})},this.onmousemove=function(Q,u){this.events.push({type:"onmousemove",x:Q,y:u,run:function(V){V.onmousemove&&V.onmousemove()}})},this.eventElements=[],this.checkPath=function(q,I){for(var D=0;D<this.events.length;D++){var e=this.events[D];I.isPointInPath&&I.isPointInPath(e.x,e.y)&&(this.eventElements[D]=q)}},this.checkBoundingBox=function(K,N){for(var J=0;J<this.events.length;J++){var V=this.events[J];N.isPointInBox(V.x,V.y)&&(this.eventElements[J]=K)}},this.runEvents=function(){N.ctx.canvas.style.cursor="";for(var y=0;y<this.events.length;y++)for(var H=this.events[y],g=this.eventElements[y];g;)H.run(g),g=g.parent;this.events=[],this.eventElements=[]}},N}var b,T=function(g,s,H){if(null!=g||null!=s||null!=H){"string"==typeof g&&(g=document.getElementById(g)),null!=g.svg&&g.svg.stop();var Q=h(H||{});(1!=g.childNodes.length||"OBJECT"!=g.childNodes[0].nodeName)&&(g.svg=Q);var $=g.getContext("2d");"undefined"!=typeof s.documentElement?Q.loadXmlDoc($,s):"<"==s.substr(0,1)?Q.loadXml($,s):Q.load($,s)}else for(var J=document.querySelectorAll("svg"),X=0;X<J.length;X++){var p=J[X],F=document.createElement("canvas");F.width=p.clientWidth,F.height=p.clientHeight,p.parentNode.insertBefore(F,p),p.parentNode.removeChild(p);var c=document.createElement("div");c.appendChild(p),T(F,c.innerHTML)}};"undefined"!=typeof Element.prototype.matches?b=function(x,k){return x.matches(k)}:"undefined"!=typeof Element.prototype.webkitMatchesSelector?b=function(Y,w){return Y.webkitMatchesSelector(w)}:"undefined"!=typeof Element.prototype.mozMatchesSelector?b=function(U,s){return U.mozMatchesSelector(s)}:"undefined"!=typeof Element.prototype.msMatchesSelector?b=function(P,L){return P.msMatchesSelector(L)}:"undefined"!=typeof Element.prototype.oMatchesSelector?b=function(b,T){return b.oMatchesSelector(T)}:(("function"==typeof jQuery||"function"==typeof Zepto)&&(b=function(W,X){return $(W).is(X)}),"undefined"==typeof b&&(b=Sizzle.matchesSelector));var C=/(\[[^\]]+\])/g,K=/(#[^\s\+>~\.\[:]+)/g,V=/(\.[^\s\+>~\.\[:]+)/g,g=/(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,r=/(:[\w-]+\([^\)]*\))/gi,p=/(:[^\s\+>~\.\[:]+)/g,U=/([^\s\+>~\.\[:]+)/g;return"undefined"!=typeof CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.drawSvg=function(j,r,D,J,H,d){var f={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0,ignoreClear:!0,offsetX:r,offsetY:D,scaleWidth:J,scaleHeight:H};for(var x in d)d.hasOwnProperty(x)&&(f[x]=d[x]);T(this.canvas,j,f)}),T})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);