@fusioncharts/core
Version:
JavaScript Data Visualisation Library
1 lines • 2.49 kB
JavaScript
exports.__esModule=true;exports.default=_default;function _default(R){var BLANK="",regStore=[{reg:/xmlns\=\"http\:\/\/www.w3.org\/2000\/svg\"/gi,repStr:""},{reg:/\r?\n|\r/g,repStr:BLANK},{reg:/^.*<svg /,repStr:'<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" '},{reg:/\/svg>.*$/,repStr:"/svg>"},{reg:/<desc\>[^<]*<\/desc\>/,repStr:BLANK},{reg:/zIndex="[^"]+"/g,repStr:BLANK},{reg:/url\((\\?[\'\"])[^#]+#/g,repStr:"url($1#"},{reg:/ href=/g,repStr:" xlink:href="},{reg:/(id|class|width|height)=([^" >]+)/g,repStr:'$1="$2"'},{reg:/:(path|rect)/g,repStr:"$1"},{reg:/<ima?ge? ([^\>]+?[^\/])\>/gi,repStr:"<image $1 />"},{reg:/<\/ima?ge?\>/g,repStr:BLANK},{reg:/style="([^"]+)"/g,repStr:function repStr(s){return s.toLowerCase()}},{reg:/NS\d+\:href=/g,repStr:"xlink:href="}],getStyleString=function getStyleString(obj){var styleString=JSON.stringify(obj);styleString=styleString.replace(/([a-z]+)([A-Z]+)([a-z]+)/g,(function(match,p1,p2,p3){return p1+"-"+p2.toLowerCase()+p3}));styleString=styleString.replace(/\"\,\"/g,'";"');styleString=styleString.replace(/\"/g," ");styleString=styleString=styleString.replace(/\{|\}/g,"");return styleString},injectStyleToSvg=function injectStyleToSvg(_svg,rules){var data,classSplit,classes,styleString,clsName,cls,svg=_svg,replceClassReg,replaceSvgStyles=function replaceSvgStyles(_match){var match=_match;if(match.match(/style\s*=/)){match=match.replace(/(style\s*=")([^"]+)/g,(function(__match,p1,p2){return p1+styleString+p2}))}else{match=match.replace(/class\s*="[^"]*"/i,(function(__match){return __match+' style="'+styleString+'" '}))}return match};for(data in rules){if(rules.hasOwnProperty(data)){classSplit=/\s+/;classes=data.split(classSplit);styleString=getStyleString(rules[data]);for(cls in classes){if(classes.hasOwnProperty(cls)){clsName=classes[cls].trim().replace(".","");replceClassReg=new RegExp("<[^>]+("+clsName+")[^>]+","g");svg=svg.replace(replceClassReg,replaceSvgStyles)}}}}return svg};if(R.svg){R.fn.toSVG=function(keepImages){var paper=this,svg=BLANK,regObj,i=0,ln=regStore.length;if(paper.canvas&&paper.canvas.parentNode){svg=paper.canvas.parentNode.innerHTML;for(;i<ln;i+=1){regObj=regStore[i];svg=svg.replace(regObj.reg,regObj.repStr)}if(paper._stylesheet&&paper._stylesheet.rules){svg=injectStyleToSvg(svg,paper._stylesheet.rules)}}if(!keepImages){svg=svg.replace(/<image[^\>]*\>/gi,(function(str){if(str.match(/href=\"data\:image/i)){return str}return BLANK}))}return svg}}}
;