1.0.12 • Published 4 years ago

svg-vdom v1.0.12

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

svg-vdom

This is a util that parses SVG strings and uses DOM-like APIs to manipulate them.

中文版 | Change Logs

Installation and use

Install from npm

npm install svg-vdom -D

Install from yarn

yarn add svg-vdom -D

Use

import { parse, NodeType } from 'svg-vdom';
parse(`<?xml version="1.0" encoding="UTF-8"?>
<svg width="42px" height="42px" viewBox="0 0 42 42" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
	<title>square</title>
	<g id="Page-1" stroke="none" stroke-width="1" fill="currentColor" fill-rule="evenodd">
		<rect id="Rectangle-7" x="0" y="0" width="42" height="42"></rect>
	</g>
</svg>`).then(vdom => {
	console.log(vdom.childNodes.length); // 2
	console.log(vdom.querySelector('#Page-1')); // g#Page-1
	console.log(NodeType[vdom.nodeType]); // 'Document'
	console.log(vdom.toString());
});

Api

NameDescription
parseParse the SVG string to generate virtual-dom
NodeTypeEnum object of node type
ParentNodeThe class of the container node
TextNodeThe class of the text node
TagNodeThe class of the label node
stringifySVGStringify virtual-dom
stringifyNodeStringify a node
stringifyTagStringify a tag node
parseSelectorParse the selector string
selectorUnitCombinatorCSS selector combo symbol enumeration object
attrModifierCSS attribute selector equal sign enumeration object
matchSelectorGroupsDetermine whether a node matches the CSS selector group
matchSelectorsDetermine whether a node matches the CSS selector
matchSelectorDetermine whether a node matches the CSS selector unit
1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago