svgedit/editor/svgcanvas.min.js

1 line
47 KiB
JavaScript

if(!window.console){window.console=new function(){this.log=function(a){};this.dir=function(a){}}}var svgWhiteList={circle:["cx","cy","fill","fill-opacity","id","opacity","r","stroke","stroke-dasharray","stroke-opacity","stroke-width","transform"],defs:[],ellipse:["cx","cy","fill","fill-opacity","id","opacity","rx","ry","stroke","stroke-dasharray","stroke-opacity","stroke-width","transform"],line:["fill","fill-opacity","id","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-opacity","stroke-width","transform","x1","x2","y1","y2"],linearGradient:["id","gradientTransform","gradientUnits","spreadMethod","x1","x2","y1","y2"],path:["d","fill","fill-opacity","id","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-opacity","stroke-width","transform"],polygon:["id","fill","fill-opacity","id","opacity","points","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-opacity","stroke-width","transform"],polyline:["id","fill","fill-opacity","opacity","points","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-opacity","stroke-width","transform"],radialGradient:["id","cx","cy","fx","fy","gradientTransform","gradientUnits","r","spreadMethod"],rect:["fill","fill-opacity","height","id","opacity","rx","ry","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-opacity","stroke-width","transform","width","x","y"],stop:["id","offset","stop-color","stop-opacity"],svg:["id","height","transform","width","xmlns"],text:["fill","fill-opacity","font-family","font-size","font-style","font-weight","id","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-opacity","stroke-width","transform","text-anchor","x","y"],};function SvgCanvas(an){function V(at,c,au){this.elem=at;this.text=au?("Change "+at.tagName+" "+au):("Change "+at.tagName);this.newValues={};this.oldValues=c;for(attr in c){if(attr=="#text"){this.newValues[attr]=at.textContent}else{this.newValues[attr]=at.getAttribute(attr)}}this.apply=function(){for(attr in this.newValues){if(this.newValues[attr]){if(attr=="#text"){this.elem.textContent=this.newValues[attr]}else{this.elem.setAttribute(attr,this.newValues[attr])}}else{if(attr!="#text"){this.elem.textContent=""}else{this.elem.removeAttribute(attr)}}}if(attr!="transform"){var ay=n.getRotationAngle(at);if(ay){var ax=at.getBBox();var av=parseInt(ax.x+ax.width/2),az=parseInt(ax.y+ax.height/2);var aw=["rotate(",ay," ",av,",",az,")"].join("");if(aw!=at.getAttribute("transform")){at.setAttribute("transform",aw)}}}return true};this.unapply=function(){for(attr in this.oldValues){if(this.oldValues[attr]){if(attr=="#text"){this.elem.textContent=this.oldValues[attr]}else{this.elem.setAttribute(attr,this.oldValues[attr])}}else{if(attr=="#text"){this.elem.textContent=""}else{this.elem.removeAttribute(attr)}}}if(attr!="transform"){var ay=n.getRotationAngle(at);if(ay){var ax=at.getBBox();var av=parseInt(ax.x+ax.width/2),az=parseInt(ax.y+ax.height/2);var aw=["rotate(",ay," ",av,",",az,")"].join("");if(aw!=at.getAttribute("transform")){at.setAttribute("transform",aw)}}}return true};this.elements=function(){return[this.elem]}}function aq(c,at){this.elem=c;this.text=at||("Create "+c.tagName);this.parent=c.parentNode;this.apply=function(){this.elem=this.parent.insertBefore(this.elem,this.elem.nextSibling)};this.unapply=function(){this.parent=this.elem.parentNode;this.elem=this.elem.parentNode.removeChild(this.elem)};this.elements=function(){return[this.elem]}}function aa(at,c,au){this.elem=at;this.text=au||("Delete "+at.tagName);this.parent=c;this.apply=function(){this.parent=this.elem.parentNode;this.elem=this.parent.removeChild(this.elem)};this.unapply=function(){this.elem=this.parent.insertBefore(this.elem,this.elem.nextSibling)};this.elements=function(){return[this.elem]}}function K(at,au,c,av){this.elem=at;this.text=av?("Move "+at.tagName+" to "+av):("Move "+at.tagName+"top/bottom");this.oldNextSibling=au;this.oldParent=c;this.newNextSibling=at.nextSibling;this.newParent=at.parentNode;this.apply=function(){this.elem=this.newParent.insertBefore(this.elem,this.newNextSibling)};this.unapply=function(){this.elem=this.oldParent.insertBefore(this.elem,this.oldNextSibling)};this.elements=function(){return[this.elem]}}function H(c){this.text=c||"Batch Command";this.stack=[];this.apply=function(){var at=this.stack.length;for(var au=0;au<at;++au){this.stack[au].apply()}};this.unapply=function(){for(var at=this.stack.length-1;at>=0;at--){this.stack[at].unapply()}};this.elements=function(){var at=[];var aw=this.stack.length;while(aw--){var av=this.stack[aw].elements();var au=av.length;while(au--){if(at.indexOf(av[au])==-1){at.push(av[au])}}}return at};this.addSubCommand=function(at){this.stack.push(at)};this.isEmpty=function(){return this.stack.length==0}}function R(at,c){this.id=at;this.selectedElement=c;this.locked=true;this.reset=function(au){this.locked=true;this.selectedElement=au;this.resize();N.update();this.selectorGroup.setAttribute("display","inline")};this.selectorGroup=g({element:"g",attr:{id:("selectorGroup"+this.id)}});this.selectorRect=this.selectorGroup.appendChild(g({element:"rect",attr:{id:("selectedBox"+this.id),fill:"none",stroke:"blue","stroke-width":"1","stroke-dasharray":"5,5",width:1,height:1,style:"pointer-events:none"}}));this.selectorGrips={nw:null,n:null,ne:null,e:null,se:null,s:null,sw:null,w:null};this.rotateGripConnector=this.selectorGroup.appendChild(g({element:"line",attr:{id:("selectorGrip_rotate_connector_"+this.id),stroke:"blue","stroke-width":"1",}}));this.rotateGrip=this.selectorGroup.appendChild(g({element:"circle",attr:{id:("selectorGrip_rotate_"+this.id),fill:"lime",r:4,stroke:"blue","stroke-width":2}}));for(dir in this.selectorGrips){this.selectorGrips[dir]=this.selectorGroup.appendChild(g({element:"rect",attr:{id:("selectorGrip_"+dir+"_"+this.id),fill:"blue",width:6,height:6,style:("cursor:"+dir+"-resize"),"stroke-width":2,"pointer-events":"all",display:"none"}}));$("#"+this.selectorGrips[dir].id).mousedown(function(){aj="resize";af=this.id.substr(13,this.id.indexOf("_",13)-13)});$("#selectorGrip_rotate_"+at).mousedown(function(){aj="rotate"})}this.showGrips=function(au){var av=au?"inline":"none";this.rotateGrip.setAttribute("display",av);this.rotateGripConnector.setAttribute("display",av);var aw=this.selectedElement;if(aw&&aw.tagName=="text"){av="none"}for(dir in this.selectorGrips){this.selectorGrips[dir].setAttribute("display",av)}if(aw){this.updateGripCursors(n.getRotationAngle(aw))}};this.updateGripCursors=function(ax){var aw=[];var au=Math.round(ax/45);if(au<0){au+=8}for(dir in this.selectorGrips){aw.push(dir)}while(au>0){aw.push(aw.shift());au--}var av=0;for(dir in this.selectorGrips){this.selectorGrips[dir].setAttribute("style",("cursor:"+aw[av]+"-resize"));av++}};this.resize=function(aD){var au=this.selectorRect;var ax=this.selectorGrips;var aG=this.selectedElement;var aF=parseInt(aG.getAttribute("stroke-width"));var ay=1;if(!isNaN(aF)){ay+=aF/2}if(aG.tagName=="text"){ay+=2}var aE=n.getBBox(this.selectedElement);var av=aD||aE;var aH=av.x-ay,aC=av.y-ay,aA=av.width+(ay<<1),aI=av.height+(ay<<1);var aL=G.suspendRedraw(100);S(au,{x:aH,y:aC,width:aA,height:aI});var az={nw:[aH-3,aC-3],ne:[aH+aA-3,aC-3],sw:[aH-3,aC+aI-3],se:[aH+aA-3,aC+aI-3],n:[aH+aA/2-3,aC-3],w:[aH-3,aC+aI/2-3],e:[aH+aA-3,aC+aI/2-3],s:[aH+aA/2-3,aC+aI-3]};$.each(az,function(aM,aN){S(ax[aM],{x:aN[0],y:aN[1]})});S(this.rotateGripConnector,{x1:aH+aA/2,y1:aC-20,x2:aH+aA/2,y2:aC});S(this.rotateGrip,{cx:aH+aA/2,cy:aC-20});this.selectorGroup.setAttribute("transform","");this.selectorGroup.removeAttribute("transform");var aK=this.selectedElement;var aB=aK.getAttribute("transform");var aJ=n.getRotationAngle(aK);if(aJ){var aw=parseInt(aE.x+aE.width/2);cy=parseInt(aE.y+aE.height/2);this.selectorGroup.setAttribute("transform","rotate("+aJ+" "+aw+","+cy+")")}G.unsuspendRedraw(aL)};this.reset(c)}function ap(){this.selectorParentGroup=null;this.rubberBandBox=null;this.selectors=[];this.selectorMap={};var c=this;this.initGroup=function(){c.selectorParentGroup=g({element:"g",attr:{id:"selectorParentGroup"}});c.selectorMap={};c.selectors=[];c.rubberBandBox=null};this.requestSelector=function(au){if(au==null){return null}var av=this.selectors.length;if(typeof(this.selectorMap[au.id])=="object"){this.selectorMap[au.id].locked=true;return this.selectorMap[au.id]}for(var at=0;at<av;++at){if(this.selectors[at]&&!this.selectors[at].locked){this.selectors[at].locked=true;this.selectors[at].reset(au);this.selectorMap[au.id]=this.selectors[at];return this.selectors[at]}}this.selectors[av]=new R(av,au);this.selectorParentGroup.appendChild(this.selectors[av].selectorGroup);this.selectorMap[au.id]=this.selectors[av];return this.selectors[av]};this.releaseSelector=function(au){if(au==null){return}var ax=this.selectors.length;var av=this.selectorMap[au.id];for(var at=0;at<ax;++at){if(this.selectors[at]&&this.selectors[at]==av){if(av.locked==false){console.log("WARNING! selector was released but was already unlocked")}delete this.selectorMap[au.id];av.locked=false;av.selectedElement=null;av.showGrips(false);try{av.selectorGroup.setAttribute("display","none")}catch(aw){}break}}};this.update=function(){this.selectorParentGroup=G.appendChild(this.selectorParentGroup)};this.getRubberBandBox=function(){if(this.rubberBandBox==null){this.rubberBandBox=this.selectorParentGroup.appendChild(g({element:"rect",attr:{id:"selectorRubberBand",fill:"blue","fill-opacity":0.15,stroke:"blue","stroke-width":0.5,display:"none",style:"pointer-events:none"}}))}return this.rubberBandBox};this.initGroup()}var g=function(c){return n.updateElementFromJson(c)};var S=function(au,at,c){if(!c){c=0}var av=G.suspendRedraw(c);for(i in at){au.setAttributeNS(null,i,at[i])}G.unsuspendRedraw(av)};var x=function(c){var at=G.suspendRedraw(60);if(c.getAttribute("fill-opacity")=="1"){c.removeAttribute("fill-opacity")}if(c.getAttribute("opacity")=="1"){c.removeAttribute("opacity")}if(c.getAttribute("stroke")=="none"){c.removeAttribute("stroke")}if(c.getAttribute("stroke-dasharray")=="none"){c.removeAttribute("stroke-dasharray")}if(c.getAttribute("stroke-opacity")=="1"){c.removeAttribute("stroke-opacity")}if(c.getAttribute("stroke-width")=="1"){c.removeAttribute("stroke-width")}if(c.getAttribute("rx")=="0"){c.removeAttribute("rx")}if(c.getAttribute("ry")=="0"){c.removeAttribute("ry")}G.unsuspendRedraw(at)};this.updateElementFromJson=function(at){var c=E.getElementById(at.attr.id);if(c&&at.element!=c.tagName){G.removeChild(c);c=null}if(!c){c=E.createElementNS(al,at.element);G.appendChild(c)}S(c,at.attr,100);x(c);return c};var n=this;var W=an;var al="http://www.w3.org/2000/svg";var q="svg_";var E=an.ownerDocument;var G=E.createElementNS(al,"svg");G.setAttribute("width",640);G.setAttribute("height",480);G.setAttribute("id","svgroot");G.setAttribute("xmlns",al);W.appendChild(G);var T=E.createComment(" created with SVG-edit - http://svg-edit.googlecode.com/ ");G.appendChild(T);var am=null;var ar=false;var ad=1;var Z=null;var Y=null;var aj="select";var af="none";var j={shape:{fill:"#FF0000",fill_paint:null,fill_opacity:1,stroke:"#000000",stroke_paint:null,stroke_opacity:1,stroke_width:5,stroke_style:"none",opacity:1}};j.text=$.extend(true,{},j.shape);$.extend(j.text,{fill:"#000000",stroke_width:0,font_size:"12pt",font_family:"serif"});var e=j.shape;var A=j.text;var l=e;var ai=null;var C=null;var ag=null;var B=null;var v=null;var z=[];var w=-1;var s=null;var d=new Array(1);var P=new Array(1);var N=new ap();var O=null;var D={};var ae=0;var r=[];var h=[];var M=function(av){if(O==null){return null}if(!h.length){h=n.getVisibleElements(true)}var c=null;try{c=G.getIntersectionList(av,null)}catch(aw){}if(c==null||typeof(c.item)!="function"){c=[];var au=O.getBBox();var at=h.length;while(at--){if(Utils.rectsIntersect(au,h[at].bbox)){c.push(h[at].elem)}}}return c};var I=function(c){if(ae<r.length&&r.length>0){r=r.splice(0,ae)}r.push(c);ae=r.length};var ao=function(){if(D.getid){return b("getid",ad)}return q+ad};var U=function(){var c=ao();while(E.getElementById(c)){ad++;c=ao()}return c};var b=function(at,c){if(D[at]){return D[at](this,c)}};var ac=function(aw){if(aw.nodeType==3){aw.nodeValue=aw.nodeValue.replace(/^\s+|\s+$/g,"")}if(aw.nodeType!=1){return}var ax=aw.ownerDocument;var av=aw.parentNode;if(!ax||!av){return}var ay=svgWhiteList[aw.nodeName];if(ay!=undefined){var au=aw.attributes.length;while(au--){var at=aw.attributes.item(au).nodeName;if(ay.indexOf(at)==-1){aw.removeAttribute(at)}}au=aw.childNodes.length;while(au--){ac(aw.childNodes.item(au))}}else{var c=[];while(aw.hasChildNodes()){c.push(av.insertBefore(aw.firstChild,aw))}av.removeChild(aw);var au=c.length;while(au--){ac(c[au])}}};var Q=function(){var au=G.getElementsByTagNameNS(al,"defs");if(!au||!au.length){return}var aB=G.getElementsByTagNameNS(al,"*");var aw=[];$.each(aB,function(aC,aD){var aF=aD.getAttribute("fill");if(aF&&aF.indexOf("url(#")==0){aw.push(aF)}var aE=aD.getAttribute("stroke");if(aE&&aE.indexOf("url(#")==0){aw.push(aE)}});var ay=G.getElementsByTagNameNS(al,"linearGradient");var az=[];var av=ay.length;while(av--){var aA=ay[av];var c=aA.getAttribute("id");var ax="url(#"+c+")";if($.inArray(ax,aw)==-1){aA.parentNode.removeChild(aA)}}var av=au.length;while(av--){var at=au[av];if(!at.getElementsByTagNameNS(al,"*").length){at.parentNode.removeChild(at)}}};var p=function(au,at){var av=new Array();if(au){var aB=au.attributes;var ay;var aw;var az=au.childNodes;for(aw=0;aw<at;aw++){av.push(" ")}av.push("<");av.push(au.nodeName);for(aw=aB.length-1;aw>=0;aw--){ay=aB.item(aw);if(ay.nodeValue!=""){if(window.opera&&ay.nodeName=="opacity"&&/^\d+,\d+$/.test(ay.nodeValue)){ay.nodeValue=ay.nodeValue.replace(",",".")}av.push(" ");av.push(ay.nodeName);av.push('="');av.push(ay.nodeValue);av.push('"')}}if(au.hasChildNodes()){av.push(">");at++;var ax=false;for(aw=0;aw<az.length;aw++){var c=az.item(aw);if(c.id=="selectorParentGroup"){continue}switch(c.nodeType){case 1:av.push("\n");av.push(p(az.item(aw),at));break;case 3:var aA=c.nodeValue.replace(/^\s+|\s+$/g,"");if(aA!=""){ax=true;av.push(aA+"")}break;case 8:av.push("\n");av.push(new Array(at+1).join(" "));av.push("<!--");av.push(c.data);av.push("-->");break}}at--;if(!ax){av.push("\n");for(aw=0;aw<at;aw++){av.push(" ")}}av.push("</");av.push(au.nodeName);av.push(">")}else{av.push("/>")}}return av.join("")};var ab=function(){var av=(af=="none"?"position":"size");var c=new H(av);var at=d.length;while(at--){var au=ak(at);if(au){c.addSubCommand(au)}}if(!c.isEmpty()){I(c);b("changed",d)}};var J=[0,"z","m","m","l","l","c","c","q","q","a","a","l","l","l","l","s","s","t","t"];var ak=function(ba){var aQ=d[ba];if(aQ==null){return null}var aD=P[ba];var aA=n.getBBox(aQ);if(aA.x==aD.x&&aA.y==aD.y&&aA.width==aD.width&&aA.height==aD.height){return null}var a4=function(bf,bg){return{x:parseInt(((bf-aA.x)/aA.width)*aD.width+aD.x),y:parseInt(((bg-aA.y)/aA.height)*aD.height+aD.y)}};var aG=function(bf){return parseInt(bf*aD.width/aA.width)};var aP=function(bf){return parseInt(bf*aD.height/aA.height)};var aN={};var aH=n.getRotationAngle(aQ);var aX=document.getElementById("polypointgrip_container");if(aH){var ay=parseInt(aA.x+aA.width/2),ax=parseInt(aA.y+aA.height/2);var aM=null,aK=null;var at=false;var aY=aQ.transform.baseVal;var a1=aY.numberOfItems;while(a1--){var a6=aY.getItem(a1);if(a6.type==3){at=true;break}}if(at){var a7=aH*Math.PI/180;var av=aD.x-ay,au=aD.y-ax,a2=Math.sqrt(av*av+au*au),aJ=Math.atan2(au,av)+a7;var aw=a2*Math.cos(aJ)+ay,az=a2*Math.sin(aJ)+ax;av+=aD.width;au+=aD.height;a2=Math.sqrt(av*av+au*au);aJ=Math.atan2(au,av)+a7;var a5=a2*Math.cos(aJ)+ay,c=a2*Math.sin(aJ)+ax;aM=parseInt(aw+(a5-aw)/2);aK=parseInt(az+(c-az)/2);aD.x=parseInt(aM-aD.width/2),aD.y=parseInt(aK-aD.height/2)}else{var a9=aD.x-aA.x,a8=aD.y-aA.y;aM=ay+a9;aK=ax+a8}var bb=["rotate(",aH," ",aM,",",aK,")"].join("");aQ.setAttribute("transform",bb);if(aX){aX.setAttribute("transform",bb)}}else{aQ.setAttribute("transform","");aQ.removeAttribute("transform");if(aX){aX.setAttribute("transform","");aX.removeAttribute("transform")}}switch(aQ.tagName){case"polygon":case"polyline":aN.points=aQ.getAttribute("points");var aL=aQ.points;var aI=aL.numberOfItems;var a3="";for(var ba=0;ba<aI;++ba){var aC=aL.getItem(ba);aC=a4(aC.x,aC.y);a3+=aC.x+","+aC.y+" "}aQ.setAttributeNS(null,"points",a3);break;case"path":aN.d=aQ.getAttribute("d");var aB=aQ.pathSegList.getItem(0);var aT=aB.x,aS=aB.y;var aC=a4(aT,aS);var aR="M"+aC.x+","+aC.y;var aO=aQ.pathSegList;var aI=aO.numberOfItems;for(var ba=1;ba<aI;++ba){var aU=aO.getItem(ba);var a0=aU.x||0,aZ=aU.y||0,aF=aU.x1||0,be=aU.y1||0,aE=aU.x2||0,bc=aU.y2||0;var bd=aU.pathSegType;switch(bd){case 1:aR+="z";continue;case 2:case 4:case 12:case 14:case 18:a0-=aT;aZ-=aS;case 3:case 5:case 13:case 15:case 19:aT+=a0;aS+=aZ;aR+=[" ",J[bd],aG(a0),",",aP(aZ)].join("");break;case 6:a0-=aT;aF-=aT;aE-=aT;aZ-=aS;be-=aS;bc-=aS;case 7:aT+=a0;aS+=aZ;aR+=[" c",aG(aF),",",aP(be)," ",aG(aE),",",aP(bc)," ",aG(a0),",",aP(aZ)].join("");break;case 8:a0-=aT;aF-=aT;aZ-=aS;be-=aS;case 9:aT+=a0;aS+=aZ;aR+=[" q",aG(aF),",",aP(be)," ",aG(a0),",",aP(aZ)].join("");break;case 10:a0-=aT;aZ-=aS;case 11:aT+=a0;aS+=aZ;aR+=["a",aG(aU.r1),",",aP(aU.r2)," ",aU.angle," ",(aU.largeArcFlag?1:0)," ",(aU.sweepFlag?1:0)," ",aG(a0),",",aP(aZ)].join("");break;case 16:a0-=aT;aE-=aT;aZ-=aS;bc-=aS;case 17:aT+=a0;aS+=aZ;aR+=[" s",aG(aE),",",aP(bc)," ",aG(a0),",",aP(aZ)].join("");break}}aQ.setAttributeNS(null,"d",aR);break;case"line":aN.x1=aQ.getAttribute("x1");aN.y1=aQ.getAttribute("y1");aN.x2=aQ.getAttribute("x2");aN.y2=aQ.getAttribute("y2");var aW=a4(aN.x1,aN.y1),aV=a4(aN.x2,aN.y2);S(aQ,{x1:aW.x,y1:aW.y,x2:aV.x,y2:aV.y,},1000);break;case"circle":aN.cx=aQ.getAttribute("cx");aN.cy=aQ.getAttribute("cy");aN.r=aQ.getAttribute("r");var aC=a4(aN.cx,aN.cy);S(aQ,{cx:aC.x,cy:aC.y,r:parseInt(Math.min(aD.width/2,aD.height/2))},1000);break;case"ellipse":aN.cx=aQ.getAttribute("cx");aN.cy=aQ.getAttribute("cy");aN.rx=aQ.getAttribute("rx");aN.ry=aQ.getAttribute("ry");var aC=a4(aN.cx,aN.cy);S(aQ,{cx:aC.x,cy:aC.y,rx:aG(aN.rx),ry:aP(aN.ry)},1000);break;case"text":aN.x=aQ.getAttribute("x");aN.y=aQ.getAttribute("y");var aC=a4(aN.x,aN.y);S(aQ,{x:aC.x,y:aC.y},1000);break;case"rect":aN.x=aQ.getAttribute("x");aN.y=aQ.getAttribute("y");aN.width=aQ.getAttribute("width");aN.height=aQ.getAttribute("height");var aC=a4(aN.x,aN.y);S(aQ,{x:aC.x,y:aC.y,width:aG(aN.width),height:aP(aN.height)},1000);break;default:console.log("Unknown shape type: "+aQ.tagName);break}if(aN){return new V(aQ,aN)}};this.clearSelection=function(){if(d[0]==null){return}var c=d.length;for(var at=0;at<c;++at){var au=d[at];if(au==null){break}N.releaseSelector(au);d[at]=null;P[at]=null}b("selected",d)};this.addToSelection=function(c,aw){if(c.length==0){return}var at=0;while(at<d.length){if(d[at]==null){break}++at}var au=c.length;while(au--){var av=c[au];if(av.id.substr(0,13)=="selectorGrip_"){continue}if(d.indexOf(av)==-1){d[at]=av;P[at++]=this.getBBox(av);N.requestSelector(av);b("selected",d)}}if(aw){N.requestSelector(d[0]).showGrips(true)}};this.removeFromSelection=function(at){if(d[0]==null){return}if(at.length==0){return}var aw=new Array(d.length);var au=0;var c=d.length;for(var av=0;av<c;++av){var ax=d[av];if(ax){if(at.indexOf(ax)==-1){aw[au++]=ax}else{N.releaseSelector(ax)}}}d=aw};var o=function(at){var c=at.pageX-W.parentNode.offsetLeft+W.parentNode.scrollLeft;var az=at.pageY-W.parentNode.offsetTop+W.parentNode.scrollTop;if($.inArray(aj,["select","resize"])==-1){L()}Z=c;Y=az;switch(aj){case"select":ar=true;af="none";var au=at.target;var ay=au.nodeName.toLowerCase();if(ay!="div"&&ay!="svg"){if(d.indexOf(au)==-1){n.clearSelection();n.addToSelection([au]);v=null}}else{n.clearSelection();aj="multiselect";if(O==null){O=N.getRubberBandBox()}S(O,{x:Z,y:Y,width:0,height:0,display:"inline"},100)}break;case"resize":ar=true;Z=c;Y=az;break;case"fhellipse":case"fhrect":case"path":ar=true;Z=c;Y=az;am=c+","+az+" ";var aw=e.stroke_width==0?1:e.stroke_width;g({element:"polyline",attr:{points:am,id:U(),fill:"none",stroke:e.stroke,"stroke-width":aw,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,"stroke-linecap":"round","stroke-linejoin":"round",opacity:e.opacity/2}});ai=c;C=c;ag=az;B=az;break;case"square":case"rect":ar=true;Z=c;Y=az;g({element:"rect",attr:{x:c,y:az,width:0,height:0,id:U(),fill:e.fill,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity,opacity:e.opacity/2}});break;case"line":ar=true;var aw=e.stroke_width==0?1:e.stroke_width;g({element:"line",attr:{x1:c,y1:az,x2:c,y2:az,id:U(),stroke:e.stroke,"stroke-width":aw,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,fill:"none",opacity:e.opacity/2}});break;case"circle":ar=true;g({element:"circle",attr:{cx:c,cy:az,r:0,id:U(),fill:e.fill,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity,opacity:e.opacity/2}});break;case"ellipse":ar=true;g({element:"ellipse",attr:{cx:c,cy:az,rx:0,ry:0,id:U(),fill:e.fill,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity,opacity:e.opacity/2}});break;case"text":ar=true;var av=g({element:"text",attr:{x:c,y:az,id:U(),fill:A.fill,stroke:e.stroke,"stroke-width":A.stroke_width,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity,opacity:e.opacity,"font-size":A.font_size,"font-family":A.font_family,"text-anchor":"middle"}});av.textContent="text";break;case"poly":ar=true;break;case"polyedit":ar=true;s=v.getAttribute("d");var ax=at.target.id;if(ax.substr(0,14)=="polypointgrip_"){w=parseInt(ax.substr(14))}if(w==-1){n.clearSelection();n.setMode("multiselect");if(O==null){O=N.getRubberBandBox()}S(O,{x:Z,y:Y,width:0,height:0,display:"inline"},100)}break;case"rotate":ar=true;n.beginUndoableChange("transform",d);break;default:console.log("Unknown mode in mousedown: "+aj);break}};var u=function(aR){if(!ar){return}var aQ=d[0];var aW=aR.pageX-W.parentNode.offsetLeft+W.parentNode.scrollLeft;var aV=aR.pageY-W.parentNode.offsetTop+W.parentNode.scrollTop;var aM=E.getElementById(ao());switch(aj){case"select":if(d[0]!=null){var aw=aW-Z;var av=aV-Y;if(aw!=0||av!=0){var a3=["translate(",aw,",",av,")"].join("");var aJ=d.length;for(var a2=0;a2<aJ;++a2){var aQ=d[a2];if(aQ==null){break}var az=n.getBBox(aQ);P[a2].x=az.x+aw;P[a2].y=az.y+av;var aI=n.getRotationAngle(aQ);if(aI){var aP=parseInt(az.x+az.width/2),aO=parseInt(az.y+az.height/2);var aY=a3+[" rotate(",aI," ",aP,",",aO,")"].join("");var aX=Math.sqrt(aw*aw+av*av);var aK=Math.atan2(av,aw)-aI*Math.PI/180;aQ.setAttribute("transform",aY);az.x+=aX*Math.cos(aK);az.y+=aX*Math.sin(aK)}else{aQ.setAttribute("transform",a3);az.x+=aw;az.y+=av}N.requestSelector(aQ).resize(az)}}}break;case"multiselect":S(O,{x:Math.min(Z,aW),y:Math.min(Y,aV),width:Math.abs(aW-Z),height:Math.abs(aV-Y)},100);n.clearSelection();n.addToSelection(M());break;case"resize":var az=n.getBBox(aQ),ax=az.x,ay=az.y,c=az.width,at=az.height,aw=(aW-Z),av=(aV-Y);var aI=n.getRotationAngle(aQ);if(aI){var aX=Math.sqrt(aw*aw+av*av);var aK=Math.atan2(av,aw)-aI*Math.PI/180;aw=aX*Math.cos(aK);av=aX*Math.sin(aK)}if(af.indexOf("n")==-1&&af.indexOf("s")==-1){av=0}if(af.indexOf("e")==-1&&af.indexOf("w")==-1){aw=0}var a3=null;var a1=0,aZ=0;var aD=(at+av)/at,aE=(c+aw)/c;if(af.indexOf("n")!=-1){aD=(at-av)/at;aZ=at}if(af.indexOf("w")!=-1){aE=(c-aw)/c;a1=c}var a3=[" translate(",(ax+a1),",",(ay+aZ),") scale(",aE,",",aD,") translate(",-(ax+a1),",",-(ay+aZ),")"].join("");if(aI){var aP=parseInt(ax+c/2),aO=parseInt(ay+at/2);a3=["rotate(",aI," ",aP,",",aO,")",a3].join("")}aQ.setAttribute("transform",a3);var aG=P[0];aG.x=ax;aG.y=ay;if(a1){aG.x+=aw}if(aZ){aG.y+=av}aG.width=parseInt(c*aE);aG.height=parseInt(at*aD);if(aG.width<0){aG.width*=-1;if(af.indexOf("e")!=-1&&aE<0){aG.x=az.x-aG.width}else{aG.x-=aG.width}}if(aG.height<0){aG.height*=-1;if(af.indexOf("s")!=-1&&aD<0){aG.y=az.y-aG.height}else{aG.y-=aG.height}}N.requestSelector(aQ).resize(aG);break;case"text":S(aM,{x:aW,y:aV},1000);break;case"line":var aN=G.suspendRedraw(1000);aM.setAttributeNS(null,"x2",aW);aM.setAttributeNS(null,"y2",aV);G.unsuspendRedraw(aN);break;case"square":var aB=Math.max(Math.abs(aW-Z),Math.abs(aV-Y));S(aM,{width:aB,height:aB,x:Z<aW?Z:Z-aB,y:Y<aV?Y:Y-aB},1000);break;case"rect":S(aM,{width:Math.abs(aW-Z),height:Math.abs(aV-Y),x:Math.min(Z,aW),y:Math.min(Y,aV)},1000);break;case"circle":var aP=aM.getAttributeNS(null,"cx");var aO=aM.getAttributeNS(null,"cy");var au=Math.sqrt((aW-aP)*(aW-aP)+(aV-aO)*(aV-aO));aM.setAttributeNS(null,"r",au);break;case"ellipse":var aP=aM.getAttributeNS(null,"cx");var aO=aM.getAttributeNS(null,"cy");var aN=G.suspendRedraw(1000);aM.setAttributeNS(null,"rx",Math.abs(aW-aP));aM.setAttributeNS(null,"ry",Math.abs(aV-aO));G.unsuspendRedraw(aN);break;case"fhellipse":case"fhrect":ai=Math.min(aW,ai);C=Math.max(aW,C);ag=Math.min(aV,ag);B=Math.max(aV,B);case"path":Z=aW;Y=aV;am+=+aW+","+aV+" ";aM.setAttributeNS(null,"points",am);break;case"poly":var aF=document.getElementById("poly_stretch_line");if(aF){aF.setAttribute("x2",aW);aF.setAttribute("y2",aV)}break;case"polyedit":if(w!=-1&&v){var a2=w*2;var aI=n.getRotationAngle(v)*Math.PI/180;if(aI){var az=P[0];var aP=paresInt(az.x+az.width/2),aO=parseInt(az.y+az.height/2);var aw=aW-aP,av=aV-aO;var aX=Math.sqrt(aw*aw+av*av);var aK=Math.atan2(av,aw)-aI;aW=aP+aX*Math.cos(aK);aV=aO+aX*Math.sin(aK)}z[a2]=aW;z[a2+1]=aV;var aL=v.getAttribute("d");var a4=(aL[aL.length-1]=="z"||aL[aL.length-1]=="Z");var aJ=z.length/2;var aH=new Array(aJ+1);var aT=z[0],aS=z[1];aH[0]=["M",aT,",",aS].join("");for(var a0=1;a0<aJ;++a0){var aC=z[a0*2],aA=z[a0*2+1];aH[a0]=["l",parseInt(aC-aT),",",parseInt(aA-aS)].join("");aT=aC;aS=aA}if(a4){aH[aJ]="z"}v.setAttribute("d",aH.join(" "));var aU=document.getElementById("polypointgrip_"+w);if(aU){aU.setAttribute("cx",aW);aU.setAttribute("cy",aV)}}break;case"rotate":var az=n.getBBox(aQ),aP=parseInt(az.x+az.width/2),aO=parseInt(az.y+az.height/2);var aI=parseInt(((Math.atan2(aO-aV,aP-aW)*(180/Math.PI))-90)%360);n.setRotationAngle(aI<-180?(360+aI):aI,true);break;default:break}};var ah=function(){var at=z.length/2;while(at--){document.getElementById("polypointgrip_"+at).setAttribute("display","none")}var c=document.getElementById("poly_stretch_line");if(c){c.setAttribute("display","none")}};var a=function(){var c=z.length;for(var au=0;au<c;au+=2){var at=document.getElementById("polypointgrip_"+au/2);if(at){S(at,{cx:z[au],cy:z[au+1],display:"inline"})}else{f(z[au],z[au+1],au/2)}}var av=document.getElementById("polypointgrip_container");av.setAttribute("transform",v.getAttribute("transform"))};var f=function(c,ay,au){var ax=document.getElementById("polypointgrip_container");if(!ax){var av=document.getElementById("selectorParentGroup");ax=av.appendChild(document.createElementNS(al,"g"));ax.id="polypointgrip_container"}var aw=document.getElementById("polypointgrip_"+au);if(!aw){aw=document.createElementNS(al,"circle");S(aw,{id:"polypointgrip_"+au,display:"none",r:4,fill:"#0F0",stroke:"#00F","stroke-width":2,cursor:"move","pointer-events":"all"});aw=ax.appendChild(aw);var at=$("#polypointgrip_"+au);at.mouseover(function(){this.setAttribute("stroke","#F00")});at.mouseout(function(){this.setAttribute("stroke","#00F")})}S(aw,{cx:c,cy:ay,display:"inline",})};var k=function(aK){if(!ar){return}var aR=aK.pageX-W.parentNode.offsetLeft+W.parentNode.scrollLeft;var aQ=aK.pageY-W.parentNode.offsetTop+W.parentNode.scrollTop;ar=false;var aB=E.getElementById(ao());var au=false;switch(aj){case"resize":case"multiselect":if(O!=null){O.setAttribute("display","none");h=[]}aj="select";case"select":if(d[0]!=null){if(d[1]==null){var aJ=d[0];e.fill=aJ.getAttribute("fill");e.fill_opacity=aJ.getAttribute("fill-opacity");e.stroke=aJ.getAttribute("stroke");e.stroke_opacity=aJ.getAttribute("stroke-opacity");e.stroke_width=aJ.getAttribute("stroke-width");e.stroke_style=aJ.getAttribute("stroke-dasharray");if(aJ.tagName=="text"){A.font_size=aJ.getAttribute("font-size");A.font_family=aJ.getAttribute("font-family")}N.requestSelector(aJ).showGrips(true)}if(aR!=Z||aQ!=Y){ab();var aF=d.length;for(var a0=0;a0<aF;++a0){if(d[a0]==null){break}N.requestSelector(d[a0]).resize(P[a0])}}else{if(d[0].nodeName=="path"&&d[1]==null){var aS=aK.target;if(v==aS){aj="polyedit";z=[];var aI=aS.pathSegList;var aO=aI.getItem(0).x,aN=aI.getItem(0).y;z.push(aO);z.push(aN);var aF=aI.numberOfItems;for(var a0=1;a0<aF;++a0){var aY=aI.getItem(a0);var aR=aY.x,aQ=aY.y;if(aY.pathSegType==1){break}var a6=aY.pathSegType;if(a6==4){aO=aR;aN=aQ}else{if(a6==5){aO+=aR;aN+=aQ}}z.push(aO);z.push(aN)}n.clearSelection();P[0]=n.getBBox(v);a()}else{v=aS}}}}return;break;case"path":au=true;break;case"line":au=(aB.getAttribute("x1")!=aB.getAttribute("x2")||aB.getAttribute("y1")!=aB.getAttribute("y2"));break;case"square":case"rect":au=(aB.getAttribute("width")!=0||aB.getAttribute("height")!=0);break;case"circle":au=(aB.getAttribute("r")!=0);break;case"ellipse":au=(aB.getAttribute("rx")!=0||aB.getAttribute("ry")!=0);break;case"fhellipse":if((C-ai)>0&&(B-ag)>0){aB=g({element:"ellipse",attr:{cx:(ai+C)/2,cy:(ag+B)/2,rx:(C-ai)/2,ry:(B-ag)/2,id:ao(),fill:e.fill,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,opacity:e.opacity,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity}});b("changed",[aB]);au=true}break;case"fhrect":if((C-ai)>0&&(B-ag)>0){aB=g({element:"rect",attr:{x:ai,y:ag,width:(C-ai),height:(B-ag),id:ao(),fill:e.fill,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,opacity:e.opacity,"stroke-opacity":e.stroke_opacity,"fill-opacity":e.fill_opacity}});b("changed",[aB]);au=true}break;case"text":au=true;n.clearSelection();break;case"poly":aB=null;ar=true;var aH=document.getElementById("poly_stretch_line");if(!aH){aH=document.createElementNS(al,"line");S(aH,{id:"poly_stretch_line",stroke:"blue","stroke-width":"0.5"});aH=document.getElementById("selectorParentGroup").appendChild(aH)}aH.setAttribute("display","inline");if(z.length==0){z.push(aR);z.push(aQ);am="M"+aR+","+aQ+" ";g({element:"path",attr:{d:am,id:U(),fill:e.fill,"fill-opacity":e.fill_opacity,stroke:e.stroke,"stroke-width":e.stroke_width,"stroke-dasharray":e.stroke_style,"stroke-opacity":e.stroke_opacity,opacity:e.opacity/2}});S(aH,{x1:aR,y1:aQ,x2:aR,y2:aQ});f(aR,aQ,0)}else{var a0=z.length;var aL=6;var aA=false;while(a0){a0-=2;var az=z[a0],ay=z[a0+1];if(aR>=(az-aL)&&aR<=(az+aL)&&aQ>=(ay-aL)&&aQ<=(ay+aL)){aA=true;break}}var aM=E.getElementById(ao());if(aA){if(a0==0&&z.length>=6){aM.setAttribute("d",am+"z")}ah();aB=aM;z=[];ar=false}else{var aF=z.length;var aX=z[aF-2],aW=z[aF-1];z.push(aR);z.push(aQ);am+="l"+parseInt(aR-aX)+","+parseInt(aQ-aW)+" ";aM.setAttribute("d",am);S(aH,{x1:aR,y1:aQ,x2:aR,y2:aQ});f(aR,aQ,(z.length/2-1))}au=true}break;case"polyedit":au=true;aB=null;if(w!=-1){w=-1;var at=new H("Edit Poly");var a4={};a4.d=s;var aE=n.getRotationAngle(v)*Math.PI/180;if(aE){var ax=n.getBBox(v);var a2=P[0];var aV=parseInt(a2.x+a2.width/2),aU=parseInt(a2.y+a2.height/2),c=parseInt(ax.x+ax.width/2),a5=parseInt(ax.y+ax.height/2);var aw=c-aV,av=a5-aU;var aT=Math.sqrt(aw*aw+av*av);var aG=Math.atan2(av,aw)+aE;c=parseInt(aT*Math.cos(aG)+aV);a5=parseInt(aT*Math.sin(aG)+aU);var a0=z.length;while(a0){a0-=2;aw=z[a0]-aV;av=z[a0+1]-aU;aT=Math.sqrt(aw*aw+av*av);aG=Math.atan2(av,aw)+aE;z[a0]=aw=aT*Math.cos(aG)+aV;z[a0+1]=av=aT*Math.sin(aG)+aU;aw-=c;av-=a5;aT=Math.sqrt(aw*aw+av*av);aG=Math.atan2(av,aw)-aE;z[a0]=parseInt(aT*Math.cos(aG)+c);z[a0+1]=parseInt(aT*Math.sin(aG)+a5)}var aD=v.getAttribute("d");var a3=(aD[aD.length-1]=="z"||aD[aD.length-1]=="Z");var aF=z.length/2;var aC=new Array(aF+1);var aO=z[0],aN=z[1];aC[0]=["M",aO,",",aN].join("");S(document.getElementById("polypointgrip_0"),{cx:aO,cy:aN},100);for(var aZ=1;aZ<aF;++aZ){var az=z[aZ*2],ay=z[aZ*2+1];aC[aZ]=["l",parseInt(az-aO),",",parseInt(ay-aN)].join("");aO=az;aN=ay;S(document.getElementById("polypointgrip_"+aZ),{cx:az,cy:ay},100)}if(a3){aC[aF]="z"}v.setAttribute("d",aC.join(" "));ax=n.getBBox(v);P[0].x=ax.x;P[0].y=ax.y;P[0].width=ax.width;P[0].height=ax.height;var a1="rotate("+(aE*180/Math.PI)+" "+c+","+a5+")";a4.transform=v.getAttribute("rotate");v.setAttribute("transform",a1);var aP=document.getElementById("polypointgrip_container");if(aP){aP.setAttribute("transform",a1)}}at.addSubCommand(new V(v,a4,"poly points"));I(at);b("changed",[v])}else{aj="select";ah();n.clearSelection();n.addToSelection([aK.target])}break;case"rotate":au=true;aB=null;aj="select";var at=n.finishUndoableChange();if(!at.isEmpty()){I(at)}break;default:console.log("Unknown mode in mouseup: "+aj);break}if(!au&&aB!=null){aB.parentNode.removeChild(aB);aB=null}else{if(aB!=null){n.addedNew=true;aB.setAttribute("opacity",e.opacity);x(aB);N.update();n.addToSelection([aB],true);I(new aq(aB));b("changed",[aB])}}};this.open=function(c){b("opened",c)};this.save=function(){this.clearSelection();Q();var c='<?xml version="1.0" standalone="no"?>\n';c+=p(G,0);b("saved",c)};this.getSvgString=function(){Q();return p(G,0)};this.setSvgString=function(aw){try{var at=Utils.text2xml(aw);ac(at.documentElement);var c=new H("Change Source");N.selectorParentGroup=G.removeChild(N.selectorParentGroup);var au=W.removeChild(G);c.addSubCommand(new aa(au,W));G=W.appendChild(E.importNode(at.documentElement,true));c.addSubCommand(new aq(G));G.appendChild(N.selectorParentGroup);I(c);b("changed",[G])}catch(av){console.log(av);return false}return true};this.clear=function(){var at=G.childNodes;var c=G.childNodes.length;var au=0;z=[];this.clearSelection();for(var av=0;av<c;av++){if(at[au].nodeType==1){at[au].parentNode.removeChild(at[au])}else{au++}}X();N.initGroup();O=N.getRubberBandBox();b("cleared")};this.clearPoly=function(){ah();v=null;z=[]};this.getResolution=function(){return[G.getAttribute("width"),G.getAttribute("height")]};this.setResolution=function(c,ax){var at=G.getAttribute("width"),au=G.getAttribute("height");var av=G.suspendRedraw(1000);if(!c){n.clearSelection();var aw=G.getBBox();if(aw){c=aw.x+aw.width;ax=aw.y+aw.height}else{alert("No content to fit to");return}}G.setAttribute("width",c);G.setAttribute("height",ax);G.unsuspendRedraw(av);I(new V(G,{width:at,height:au},"resolution"));b("changed",[G])};this.getMode=function(){return aj};this.setMode=function(c){if(aj=="poly"&&z.length>0){var at=E.getElementById(ao());at.parentNode.removeChild(at);n.clearPoly();n.clearSelection();ar=false}else{if(aj=="polyedit"){n.clearPoly()}}l=(d[0]&&d[0].nodeName=="text")?A:e;aj=c};this.getStrokeColor=function(){return l.stroke};this.setStrokeColor=function(at,c){e.stroke=at;l.stroke_paint={type:"solidColor"};if(!c){this.changeSelectedAttribute("stroke",at)}else{this.changeSelectedAttributeNoUndo("stroke",at)}};this.getFillColor=function(){return l.fill};this.setFillColor=function(aw,at){l.fill=aw;l.fill_paint={type:"solidColor"};var c=[];var au=d.length;while(au--){var av=d[au];if(av&&av.tagName!="polyline"&&av.tagName!="line"){c.push(av)}}if(c.length>0){if(!at){this.changeSelectedAttribute("fill",aw,c)}else{this.changeSelectedAttributeNoUndo("fill",aw,c)}}};var y=function(){var c=G.getElementsByTagNameNS(al,"defs");if(c.length>0){c=c[0]}else{c=G.insertBefore(E.createElementNS(al,"defs"),G.firstChild.nextSibling)}return c};var L=function(){$.each(["stroke","fill"],function(au,av){if(!l[av+"_paint"]||l[av+"_paint"].type=="solidColor"){return}var ax=n[av+"Grad"];var aw=t(ax);var c=y();if(!aw){ax=c.appendChild(E.importNode(ax,true));ax.id=U()}else{ax=aw}var at=av=="fill"?"Fill":"Stroke";n["set"+at+"Color"]("url(#"+ax.id+")")})};var t=function(ax){var au=y();var ay=au.getElementsByTagNameNS(al,"linearGradient");var av=ay.length;while(av--){var az=ay.item(av);if(ax.getAttribute("x1")!=az.getAttribute("x1")||ax.getAttribute("y1")!=az.getAttribute("y1")||ax.getAttribute("x2")!=az.getAttribute("x2")||ax.getAttribute("y2")!=az.getAttribute("y2")){continue}var aA=ax.getElementsByTagNameNS(al,"stop");var aB=az.getElementsByTagNameNS(al,"stop");if(aA.length!=aB.length){continue}var at=aA.length;while(at--){var aw=aA.item(at);var c=aB.item(at);if(aw.getAttribute("offset")!=c.getAttribute("offset")||aw.getAttribute("stop-opacity")!=c.getAttribute("stop-opacity")||aw.getAttribute("stop-color")!=c.getAttribute("stop-color")){break}}if(at==-1){return az}}return null};this.setStrokePaint=function(at,c){var at=new $.jGraduate.Paint(at);this.setStrokeOpacity(at.alpha/100);l.stroke_paint=at;if(at.type=="solidColor"){this.setStrokeColor("#"+at.solidColor)}else{if(at.type=="linearGradient"){n.strokeGrad=at.linearGradient;if(c){L()}}else{}}};this.setFillPaint=function(at,c){var at=new $.jGraduate.Paint(at);this.setFillOpacity(at.alpha/100,true);l.fill_paint=at;if(at.type=="solidColor"){this.setFillColor("#"+at.solidColor)}else{if(at.type=="linearGradient"){n.fillGrad=at.linearGradient;if(c){L()}}else{}}};this.getStrokeWidth=function(){return l.stroke_width};this.setStrokeWidth=function(c){if(c==0&&$.inArray(aj,["line","path"])==-1){n.setStrokeWidth(1)}l.stroke_width=c;this.changeSelectedAttribute("stroke-width",c)};this.getStrokeStyle=function(){return e.stroke_style};this.setStrokeStyle=function(c){e.stroke_style=c;this.changeSelectedAttribute("stroke-dasharray",c)};this.getOpacity=function(){return e.opacity};this.setOpacity=function(c){e.opacity=c;this.changeSelectedAttribute("opacity",c)};this.getFillOpacity=function(){return e.fill_opacity};this.setFillOpacity=function(at,c){e.fill_opacity=at;if(!c){this.changeSelectedAttribute("fill-opacity",at)}else{this.changeSelectedAttributeNoUndo("fill-opacity",at)}};this.getStrokeOpacity=function(){return e.stroke_opacity};this.setStrokeOpacity=function(at,c){e.stroke_opacity=at;if(!c){this.changeSelectedAttribute("stroke-opacity",at)}else{this.changeSelectedAttributeNoUndo("stroke-opacity",at)}};this.getBBox=function(au){var at=au||d[0];if(au.nodeName=="text"&&at.textContent==""){at.textContent="a";var c=at.getBBox();at.textContent=""}else{var c=at.getBBox()}return c};this.getRotationAngle=function(aw){var av=aw||d[0];var ax=av.transform.baseVal;var au=ax.numberOfItems;var at=false;while(au--){var c=ax.getItem(au);if(c.type==4){return c.angle}}return 0};this.setRotationAngle=function(ay,at){var av=d[0];var ax=av.getBBox();var c=parseInt(ax.x+ax.width/2),az=parseInt(ax.y+ax.height/2);var au="rotate("+ay+" "+c+","+az+")";if(at){this.changeSelectedAttributeNoUndo("transform",au,d)}else{this.changeSelectedAttribute("transform",au,d)}var aw=document.getElementById("polypointgrip_container");if(av.nodeName=="path"&&aw){aw.setAttribute("transform",au)}N.requestSelector(d[0]).updateGripCursors(ay)};this.each=function(c){$(G).children().each(c)};this.bind=function(at,au){var c=D[at];D[at]=au;return c};this.setIdPrefix=function(c){q=c};this.getBold=function(){var c=d[0];if(c!=null&&c.tagName=="text"&&d[1]==null){return(c.getAttribute("font-weight")=="bold")}return false};this.setBold=function(c){var at=d[0];if(at!=null&&at.tagName=="text"&&d[1]==null){this.changeSelectedAttribute("font-weight",c?"bold":"normal")}};this.getItalic=function(){var c=d[0];if(c!=null&&c.tagName=="text"&&d[1]==null){return(c.getAttribute("font-style")=="italic")}return false};this.setItalic=function(c){var at=d[0];if(at!=null&&at.tagName=="text"&&d[1]==null){this.changeSelectedAttribute("font-style",c?"italic":"normal")}};this.getFontFamily=function(){return A.font_family};this.setFontFamily=function(c){A.font_family=c;this.changeSelectedAttribute("font-family",c)};this.getFontSize=function(){return A.font_size};this.setFontSize=function(c){A.font_size=c;this.changeSelectedAttribute("font-size",c)};this.getText=function(){var c=d[0];if(c==null){return""}return c.textContent};this.setTextContent=function(c){this.changeSelectedAttribute("#text",c)};this.setRectRadius=function(au){var c=d[0];if(c!=null&&c.tagName=="rect"){var at=c.getAttribute("rx");if(at!=au){c.setAttribute("rx",au);c.setAttribute("ry",au);I(new V(c,{rx:at,ry:at},"Radius"));b("changed",[c])}}};this.quickClone=function(c){if(navigator.userAgent.indexOf("Gecko/")==-1){return c}var at=c.cloneNode(true);c.parentNode.insertBefore(at,c);c.parentNode.removeChild(c);n.clearSelection();n.addToSelection([at],true);return at};var m=-1;var F=[];this.beginUndoableChange=function(av,at){var ay=++m;var au=at.length;var c=new Array(au),ax=new Array(au);while(au--){var aw=at[au];if(aw==null){continue}ax[au]=aw;c[au]=aw.getAttribute(av)}F[ay]={attrName:av,oldValues:c,elements:ax}};this.changeSelectedAttributeNoUndo=function(aB,at,c){var aA=G.suspendRedraw(1000);var c=c||d;var az=c.length;while(az--){var au=c[az];if(au==null){continue}var aC=aB=="#text"?au.textContent:au.getAttribute(aB);if(aC==null){aC=""}if(aC!=at){if(aB=="#text"){au.textContent=at;au=n.quickClone(au)}else{au.setAttribute(aB,at)}P[az]=this.getBBox(au);if(au.nodeName=="text"){if((at+"").indexOf("url")==0||$.inArray(aB,["font-size","font-family","x","y"])!=-1){au=n.quickClone(au)}}setTimeout(function(){N.requestSelector(au).resize(P[az])},0);var aw=n.getRotationAngle(au);if(aw&&aB!="transform"){var ax=parseInt(P[az].x+P[az].width/2),av=parseInt(P[az].y+P[az].height/2);var ay=["rotate(",aw," ",ax,",",av,")"].join("");if(ay!=au.getAttribute("transform")){au.setAttribute("transform",ay)}}}}G.unsuspendRedraw(aA);b("changed",c)};this.finishUndoableChange=function(){var ax=m--;var ay=F[ax];var au=ay.elements.length;var at=ay.attrName;var c=new H("Change "+at);while(au--){var aw=ay.elements[au];if(aw==null){continue}var av={};av[at]=ay.oldValues[au];if(av[at]!=aw.getAttribute(at)){c.addSubCommand(new V(aw,av,at))}}F[ax]=null;return c};this.changeSelectedAttribute=function(c,aw,au){var au=au||d;n.beginUndoableChange(c,au);var av=au.length;n.changeSelectedAttributeNoUndo(c,aw,au);var at=n.finishUndoableChange();if(!at.isEmpty()){I(at)}};$(W).mouseup(k);$(W).mousedown(o);$(W).mousemove(u);this.deleteSelectedElements=function(){var au=new H("Delete Elements");var at=d.length;var c=[];for(var aw=0;aw<at;++aw){var ay=d[aw];if(ay==null){break}var ax=ay.parentNode;var av=ay;N.releaseSelector(av);var az=ax.removeChild(av);c.push(ay);d[aw]=null;au.addSubCommand(new aa(az,ax))}if(!au.isEmpty()){I(au)}b("selected",c)};this.moveToTopSelectedElement=function(){var au=d[0];if(au!=null){var at=au;var c=at.parentNode;var av=at.nextSibling;if(av==N.selectorParentGroup){av=null}at=at.parentNode.appendChild(at);I(new K(at,av,c,"top"))}};this.moveToBottomSelectedElement=function(){var au=d[0];if(au!=null){var at=au;var c=at.parentNode;var aw=at.nextSibling;if(aw==N.selectorParentGroup){aw=null}var av=at.parentNode.firstChild.nextSibling;if(av.tagName=="defs"){av=av.nextSibling}at=at.parentNode.insertBefore(at,av);I(new K(at,aw,c,"bottom"))}};this.moveSelectedElements=function(av,at,c){var c=c||true;var au=new H("position");var aw=d.length;while(aw--){var ax=d[aw];if(ax!=null){P[aw]=this.getBBox(ax);if(av.constructor==Array){P[aw].x+=av[aw]}else{P[aw].x+=av}if(at.constructor==Array){P[aw].y+=at[aw]}else{P[aw].y+=at}var ay=ak(aw);if(ay){au.addSubCommand(ay)}N.requestSelector(ax).resize(P[aw])}}if(!au.isEmpty()){if(c){I(au)}b("changed",d)}};this.getVisibleElements=function(ax){var c=G.childNodes;var at=c.length;var az=[];while(at--){var aw=c[at];try{var av=n.getBBox(aw);if(aw.id!="selectorParentGroup"&&av){var au=ax?{elem:aw,bbox:av}:aw;az.push(au)}}catch(ay){}}return az};this.cycleElement=function(au){var ax=d[0];var av=false;var aw=this.getVisibleElements();if(ax==null){var c=au?aw.length-1:0;av=aw[c]}else{var at=aw.length;while(at--){if(aw[at]==ax){var c=au?at-1:at+1;if(c>=aw.length){c=0}else{if(c<0){c=aw.length-1}}av=aw[c];break}}}n.clearSelection();n.addToSelection([av],true);b("selected",d)};var X=function(){r=[];ae=0};this.getUndoStackSize=function(){return ae};this.getRedoStackSize=function(){return r.length-ae};this.getNextUndoCommandText=function(){if(ae>0){return r[ae-1].text}return""};this.getNextRedoCommandText=function(){if(ae<r.length){return r[ae].text}return""};this.undo=function(){if(ae>0){this.clearSelection();ah();var c=r[--ae];c.unapply();b("changed",c.elements())}};this.redo=function(){if(ae<r.length&&r.length>0){this.clearSelection();var c=r[ae++];c.apply();b("changed",c.elements())}};this.cloneSelectedElements=function(){var at=new H("Clone Elements");var c=d.length;for(var au=0;au<c;++au){var aw=d[au];if(aw==null){break}}var av=d.slice(0,au);this.clearSelection();var au=av.length;while(au--){var aw=av[au]=av[au].cloneNode(true);aw.removeAttribute("id");aw.id=U();G.appendChild(aw);at.addSubCommand(new aq(aw))}if(!at.isEmpty()){this.addToSelection(av);this.moveSelectedElements(20,20,false);I(at);b("selected",d)}};this.alignSelectedElements=function(ax,aE){var aA=[],aN=[];var az=Number.MAX_VALUE,ay=Number.MIN_VALUE,aw=Number.MAX_VALUE,av=Number.MIN_VALUE;var aJ=Number.MIN_VALUE,aP=Number.MIN_VALUE;var aR=d.length;if(!aR){return}for(var aQ=0;aQ<aR;++aQ){if(d[aQ]==null){break}var aS=d[aQ];aA[aQ]=this.getBBox(aS);aN[aQ]=this.getRotationAngle(aS)*Math.PI/180;if(aN[aQ]){var aL=Number.MAX_VALUE,aI=Number.MAX_VALUE,aK=Number.MIN_VALUE,aH=Number.MIN_VALUE;var au=parseInt(aA[aQ].x+aA[aQ].width/2),at=parseInt(aA[aQ].y+aA[aQ].height/2);var aT=[[aA[aQ].x-au,aA[aQ].y-at],[aA[aQ].x+aA[aQ].width-au,aA[aQ].y-at],[aA[aQ].x+aA[aQ].width-au,aA[aQ].y+aA[aQ].height-at],[aA[aQ].x-au,aA[aQ].y+aA[aQ].height-at]];var aO=4;while(aO--){var aD=aT[aO][0],aC=aT[aO][1],aM=Math.sqrt(aD*aD+aC*aC);var aB=Math.atan2(aC,aD)+aN[aQ];aD=parseInt(aM*Math.cos(aB)+au);aC=parseInt(aM*Math.sin(aB)+at);if(aD<aL){aL=aD}if(aC<aI){aI=aC}if(aD>aK){aK=aD}if(aC>aH){aH=aC}}aA[aQ].x=aL;aA[aQ].y=aI;aA[aQ].width=aK-aL;aA[aQ].height=aH-aI}switch(aE){case"smallest":if((ax=="l"||ax=="c"||ax=="r")&&(aJ==Number.MIN_VALUE||aJ>aA[aQ].width)||(ax=="t"||ax=="m"||ax=="b")&&(aP==Number.MIN_VALUE||aP>aA[aQ].height)){az=aA[aQ].x;aw=aA[aQ].y;ay=aA[aQ].x+aA[aQ].width;av=aA[aQ].y+aA[aQ].height;aJ=aA[aQ].width;aP=aA[aQ].height}break;case"largest":if((ax=="l"||ax=="c"||ax=="r")&&(aJ==Number.MIN_VALUE||aJ<aA[aQ].width)||(ax=="t"||ax=="m"||ax=="b")&&(aP==Number.MIN_VALUE||aP<aA[aQ].height)){az=aA[aQ].x;aw=aA[aQ].y;ay=aA[aQ].x+aA[aQ].width;av=aA[aQ].y+aA[aQ].height;aJ=aA[aQ].width;aP=aA[aQ].height}break;default:if(aA[aQ].x<az){az=aA[aQ].x}if(aA[aQ].y<aw){aw=aA[aQ].y}if(aA[aQ].x+aA[aQ].width>ay){ay=aA[aQ].x+aA[aQ].width}if(aA[aQ].y+aA[aQ].height>av){av=aA[aQ].y+aA[aQ].height}break}}if(aE=="page"){az=0;aw=0;ay=G.getAttribute("width");av=G.getAttribute("height")}var aG=new Array(aR);var aF=new Array(aR);for(var aQ=0;aQ<aR;++aQ){if(d[aQ]==null){break}var aS=d[aQ];var c=aA[aQ];aG[aQ]=0;aF[aQ]=0;switch(ax){case"l":aG[aQ]=az-c.x;break;case"c":aG[aQ]=(az+ay)/2-(c.x+c.width/2);break;case"r":aG[aQ]=ay-(c.x+c.width);break;case"t":aF[aQ]=aw-c.y;break;case"m":aF[aQ]=(aw+av)/2-(c.y+c.height/2);break;case"b":aF[aQ]=av-(c.y+c.height);break}}this.moveSelectedElements(aG,aF)}}var Utils={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode64:function(d){var b=new Array(Math.floor((d.length+2)/3)*4);var l,j,g;var k,h,f,e;var c=0,a=0;do{l=d.charCodeAt(c++);j=d.charCodeAt(c++);g=d.charCodeAt(c++);k=l>>2;h=((l&3)<<4)|(j>>4);f=((j&15)<<2)|(g>>6);e=g&63;if(isNaN(j)){f=e=64}else{if(isNaN(g)){e=64}}b[a++]=this._keyStr.charAt(k);b[a++]=this._keyStr.charAt(h);b[a++]=this._keyStr.charAt(f);b[a++]=this._keyStr.charAt(e)}while(c<d.length);return b.join("")},rectsIntersect:function(b,a){return a.x<(b.x+b.width)&&(a.x+a.width)>b.x&&a.y<(b.y+b.height)&&(a.y+a.height)>b.y},text2xml:function(b){var a;try{var d=($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser();d.async=false}catch(c){throw new Error("XML Parser could not be instantiated")}try{if($.browser.msie){a=(d.loadXML(b))?d:false}else{a=d.parseFromString(b,"text/xml")}}catch(c){throw new Error("Error parsing XML string")}return a}};