UNPKG

aha-svg

Version:

SVG Tools

48 lines (38 loc) 1.1 kB
## SVG 小工具 安装 : ``` npm i aha-svg ``` ### 使用 ``` // let svg = require('aha-svg') import svg,{ toElement,attrstringify,attrtoSvg} from 'aha-svg' //html <svg id="svg_main" width="300" height="300"></svg> let demo = `<rect />`; let ele = toElement(demo); console.log(ele.toLocaleString()); // [object SVGRectElement] let root = svg.selector("#svg_main"); console.log(root.target.toLocaleString()); // [object SVGSVGElement] svg .selector("#svg_main") .appendChild( svg .selector(ele) .x("25%") .y("25%") .border("yellow") .borderWidth(10) .width("50%") .height("50%") .styles("fill", "red").target ); ---------------------------------------------------------------- let svgRect=toElement('<rect/>') console.log(svgRect) console.log(svgRect.toLocaleString()) // "[object SVGRectElement]" attrtoSvg(svgRect,{width:100,height:100}) console.log(svgRect) // <rect width="100" height="100"/> let ats=attrstringify({width:100,height:100}) console.log(ats) // width="100" height="100" svgRect=toElement(`<rect ${ats}/>`) ```