forked from svgdotjs/svg.import.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg.import.min.js
2 lines (2 loc) · 948 Bytes
/
svg.import.min.js
1
2
// svg.import.js 0.1 - Copyright (c) 2013 Wout Fierens - Licensed under the MIT license
SVG.extend(SVG.Container,{"import":function(e){var t=document.createElement("div");t.innerHTML=e.replace(/<(\w+)([^<]+?)\/>/g,"<$1$2></$1>");this._convertNodes(t.childNodes,this,0);t=null;return this},_convertNodes:function(e,t,n){var r,i,s,o,u;for(r=0,i=e.length;r<i;r++){var a,f,l=e[r],c={};f=l.nodeName.toLowerCase();u=l.attributes||[];for(s=u.length-1;s>=0;s--)c[u[s].nodeName]=u[s].nodeValue;switch(f){case"rect":case"circle":case"ellipse":a=t[f](0,0);break;case"line":a=t.line(0,0,0,0);break;case"text":case"path":case"polygon":case"polyline":a=t[f]();break;case"image":a=t.image(c["xlink:href"]);break;case"g":case"svg":if(f=="svg"&&n==0){this._convertNodes(l.childNodes,t,n+1);return t}else{a=t[f=="g"?"group":"nested"]();this._convertNodes(l.childNodes,a,n+1)}break}switch(f){case"circle":c.rx=c.r;c.ry=c.r;delete c.r;break}if(a)a.attr(c)}return t}});