/*!! * Canvas 2 Svg v1.0.19 * A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document. * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Author: * Kerry Liu * * Copyright (c) 2014 Gliffy Inc. */ !function(){"use strict";var t,e,r,i,s;function n(t,e){var r,i=Object.keys(e);for(r=0;r1?((r=i).width=arguments[0],r.height=arguments[1]):r=t||i,!(this instanceof e))return new e(r);this.width=r.width||i.width,this.height=r.height||i.height,this.enableMirroring=void 0!==r.enableMirroring?r.enableMirroring:i.enableMirroring,this.canvas=this,this.__document=r.document||document,r.ctx?this.__ctx=r.ctx:(this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d")),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},e.prototype.__createElement=function(t,e,r){void 0===e&&(e={});var i,s,n=this.__document.createElementNS("http://www.w3.org/2000/svg",t),a=Object.keys(e);for(r&&(n.setAttribute("fill","none"),n.setAttribute("stroke","none")),i=0;i0){"path"===this.__currentElement.nodeName&&(this.__currentElementsToStyle||(this.__currentElementsToStyle={element:e,children:[]}),this.__currentElementsToStyle.children.push(this.__currentElement),this.__applyCurrentDefaultPath());var r=this.__createElement("g");e.appendChild(r),this.__currentElement=r}var i=this.__currentElement.getAttribute("transform");i?i+=" ":i="",i+=t,this.__currentElement.setAttribute("transform",i)},e.prototype.scale=function(t,e){void 0===e&&(e=t),this.__addTransform(n("scale({x},{y})",{x:t,y:e}))},e.prototype.rotate=function(t){var e=180*t/Math.PI;this.__addTransform(n("rotate({angle},{cx},{cy})",{angle:e,cx:0,cy:0}))},e.prototype.translate=function(t,e){this.__addTransform(n("translate({x},{y})",{x:t,y:e}))},e.prototype.transform=function(t,e,r,i,s,a){this.__addTransform(n("matrix({a},{b},{c},{d},{e},{f})",{a:t,b:e,c:r,d:i,e:s,f:a}))},e.prototype.beginPath=function(){var t;this.__currentDefaultPath="",this.__currentPosition={},t=this.__createElement("path",{},!0),this.__closestGroupOrSvg().appendChild(t),this.__currentElement=t},e.prototype.__applyCurrentDefaultPath=function(){var t=this.__currentElement;"path"===t.nodeName?t.setAttribute("d",this.__currentDefaultPath):console.error("Attempted to apply path command to node",t.nodeName)},e.prototype.__addPathCommand=function(t){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=t},e.prototype.moveTo=function(t,e){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.__currentPosition={x:t,y:e},this.__addPathCommand(n("M {x} {y}",{x:t,y:e}))},e.prototype.closePath=function(){this.__currentDefaultPath&&this.__addPathCommand("Z")},e.prototype.lineTo=function(t,e){this.__currentPosition={x:t,y:e},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(n("L {x} {y}",{x:t,y:e})):this.__addPathCommand(n("M {x} {y}",{x:t,y:e}))},e.prototype.bezierCurveTo=function(t,e,r,i,s,a){this.__currentPosition={x:s,y:a},this.__addPathCommand(n("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:t,cp1y:e,cp2x:r,cp2y:i,x:s,y:a}))},e.prototype.quadraticCurveTo=function(t,e,r,i){this.__currentPosition={x:r,y:i},this.__addPathCommand(n("Q {cpx} {cpy} {x} {y}",{cpx:t,cpy:e,x:r,y:i}))};var h=function(t){var e=Math.sqrt(t[0]*t[0]+t[1]*t[1]);return[t[0]/e,t[1]/e]};e.prototype.arcTo=function(t,e,r,i,s){var n=this.__currentPosition&&this.__currentPosition.x,a=this.__currentPosition&&this.__currentPosition.y;if(void 0!==n&&void 0!==a){if(s<0)throw new Error("IndexSizeError: The radius provided ("+s+") is negative.");if(n===t&&a===e||t===r&&e===i||0===s)this.lineTo(t,e);else{var o=h([n-t,a-e]),l=h([r-t,i-e]);if(o[0]*l[1]!=o[1]*l[0]){var c=o[0]*l[0]+o[1]*l[1],p=Math.acos(Math.abs(c)),_=h([o[0]+l[0],o[1]+l[1]]),u=s/Math.sin(p/2),d=t+u*_[0],g=e+u*_[1],m=[-o[1],o[0]],f=[l[1],-l[0]],y=function(t){var e=t[0];return t[1]>=0?Math.acos(e):-Math.acos(e)},v=y(m),x=y(f);this.lineTo(d+m[0]*s,g+m[1]*s),this.arc(d,g,s,v,x)}else this.lineTo(t,e)}}},e.prototype.stroke=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},e.prototype.fill=function(){"path"===this.__currentElement.nodeName&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},e.prototype.rect=function(t,e,r,i){"path"!==this.__currentElement.nodeName&&this.beginPath(),this.moveTo(t,e),this.lineTo(t+r,e),this.lineTo(t+r,e+i),this.lineTo(t,e+i),this.lineTo(t,e),this.closePath()},e.prototype.fillRect=function(t,e,r,i){var s;s=this.__createElement("rect",{x:t,y:e,width:r,height:i},!0),this.__closestGroupOrSvg().appendChild(s),this.__currentElement=s,this.__applyStyleToCurrentElement("fill")},e.prototype.strokeRect=function(t,e,r,i){var s;s=this.__createElement("rect",{x:t,y:e,width:r,height:i},!0),this.__closestGroupOrSvg().appendChild(s),this.__currentElement=s,this.__applyStyleToCurrentElement("stroke")},e.prototype.__clearCanvas=function(){for(var t=this.__closestGroupOrSvg().getAttribute("transform"),e=this.__root.childNodes[1],r=e.childNodes,i=r.length-1;i>=0;i--)r[i]&&e.removeChild(r[i]);this.__currentElement=e,this.__groupStack=[],t&&this.__addTransform(t)},e.prototype.clearRect=function(t,e,r,i){if(0!==t||0!==e||r!==this.width||i!==this.height){var s,n=this.__closestGroupOrSvg();s=this.__createElement("rect",{x:t,y:e,width:r,height:i,fill:"#FFFFFF"},!0),n.appendChild(s)}else this.__clearCanvas()},e.prototype.createLinearGradient=function(t,e,i,s){var n=this.__createElement("linearGradient",{id:a(this.__ids),x1:t+"px",x2:i+"px",y1:e+"px",y2:s+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(n),new r(n,this)},e.prototype.createRadialGradient=function(t,e,i,s,n,o){var h=this.__createElement("radialGradient",{id:a(this.__ids),cx:s+"px",cy:n+"px",r:o+"px",fx:t+"px",fy:e+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(h),new r(h,this)},e.prototype.__parseFont=function(){var t=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\'\"\sa-z0-9]+?)\s*$/i.exec(this.font),e={style:t[1]||"normal",size:t[4]||"10px",family:t[6]||"sans-serif",weight:t[3]||"normal",decoration:t[2]||"normal",href:null};return"underline"===this.__fontUnderline&&(e.decoration="underline"),this.__fontHref&&(e.href=this.__fontHref),e},e.prototype.__wrapTextLink=function(t,e){if(t.href){var r=this.__createElement("a");return r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t.href),r.appendChild(e),r}return e},e.prototype.__applyText=function(t,e,r,i){var s,n,a=this.__parseFont(),h=this.__closestGroupOrSvg(),l=this.__createElement("text",{"font-family":a.family,"font-size":a.size,"font-style":a.style,"font-weight":a.weight,"text-decoration":a.decoration,x:e,y:r,"text-anchor":(s=this.textAlign,n={left:"start",right:"end",center:"middle",start:"start",end:"end"},n[s]||n.start),"dominant-baseline":o(this.textBaseline)},!0);l.appendChild(this.__document.createTextNode(t)),this.__currentElement=l,this.__applyStyleToCurrentElement(i),h.appendChild(this.__wrapTextLink(a,l))},e.prototype.fillText=function(t,e,r){this.__applyText(t,e,r,"fill")},e.prototype.strokeText=function(t,e,r){this.__applyText(t,e,r,"stroke")},e.prototype.measureText=function(t){return this.__ctx.font=this.font,this.__ctx.measureText(t)},e.prototype.arc=function(t,e,r,i,s,a){if(i!==s){(i%=2*Math.PI)===(s%=2*Math.PI)&&(s=(s+2*Math.PI-.001*(a?-1:1))%(2*Math.PI));var o=t+r*Math.cos(s),h=e+r*Math.sin(s),l=t+r*Math.cos(i),c=e+r*Math.sin(i),p=a?0:1,_=0,u=s-i;u<0&&(u+=2*Math.PI),_=a?u>Math.PI?0:1:u>Math.PI?1:0,this.lineTo(l,c),this.__addPathCommand(n("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:r,ry:r,xAxisRotation:0,largeArcFlag:_,sweepFlag:p,endX:o,endY:h})),this.__currentPosition={x:o,y:h}}},e.prototype.clip=function(){var t=this.__closestGroupOrSvg(),e=this.__createElement("clipPath"),r=a(this.__ids),i=this.__createElement("g");this.__applyCurrentDefaultPath(),t.removeChild(this.__currentElement),e.setAttribute("id",r),e.appendChild(this.__currentElement),this.__defs.appendChild(e),t.setAttribute("clip-path",n("url(#{id})",{id:r})),t.appendChild(i),this.__currentElement=i},e.prototype.drawImage=function(){var t,r,i,s,n,a,o,h,l,c,p,_,u,d=Array.prototype.slice.call(arguments),g=d[0],m=0,f=0;if(3===d.length)t=d[1],r=d[2],i=n=g.width,s=a=g.height;else if(5===d.length)t=d[1],r=d[2],i=d[3],s=d[4],n=g.width,a=g.height;else{if(9!==d.length)throw new Error("Invalid number of arguments passed to drawImage: "+arguments.length);m=d[1],f=d[2],n=d[3],a=d[4],t=d[5],r=d[6],i=d[7],s=d[8]}o=this.__closestGroupOrSvg(),this.__currentElement;var y="translate("+t+", "+r+")";if(g instanceof e){if((h=g.getSvg().cloneNode(!0)).childNodes&&h.childNodes.length>1){for(l=h.childNodes[0];l.childNodes.length;)u=l.childNodes[0].getAttribute("id"),this.__ids[u]=u,this.__defs.appendChild(l.childNodes[0]);if(c=h.childNodes[1]){var v,x=c.getAttribute("transform");v=x?x+" "+y:y,c.setAttribute("transform",v),o.appendChild(c)}}}else"CANVAS"!==g.nodeName&&"IMG"!==g.nodeName||((p=this.__createElement("image")).setAttribute("width",i),p.setAttribute("height",s),p.setAttribute("preserveAspectRatio","none"),(m||f||n!==g.width||a!==g.height)&&((_=this.__document.createElement("canvas")).width=i,_.height=s,_.getContext("2d").drawImage(g,m,f,n,a,0,0,i,s),g=_),p.setAttribute("transform",y),p.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===g.nodeName?g.toDataURL():g.getAttribute("src")),o.appendChild(p))},e.prototype.createPattern=function(t,r){var s,n=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),o=a(this.__ids);return n.setAttribute("id",o),n.setAttribute("width",t.width),n.setAttribute("height",t.height),"CANVAS"===t.nodeName||"IMG"===t.nodeName?((s=this.__document.createElementNS("http://www.w3.org/2000/svg","image")).setAttribute("width",t.width),s.setAttribute("height",t.height),s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","CANVAS"===t.nodeName?t.toDataURL():t.getAttribute("src")),n.appendChild(s),this.__defs.appendChild(n)):t instanceof e&&(n.appendChild(t.__root.childNodes[1]),this.__defs.appendChild(n)),new i(n,this)},e.prototype.setLineDash=function(t){t&&t.length>0?this.lineDash=t.join(","):this.lineDash=null},e.prototype.drawFocusRing=function(){},e.prototype.createImageData=function(){},e.prototype.getImageData=function(){},e.prototype.putImageData=function(){},e.prototype.globalCompositeOperation=function(){},e.prototype.setTransform=function(){},"object"==typeof window&&(window.C2S=e),"object"==typeof module&&"object"==typeof module.exports&&(module.exports=e)}();