svgedit/editor/svgcanvas.min.js

1 line
47 KiB
JavaScript
Raw Normal View History

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.inser