Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skarab42/lw.svg-parser
SVG parser for LaserWeb.
https://github.com/skarab42/lw.svg-parser
Last synced: 15 days ago
JSON representation
SVG parser for LaserWeb.
- Host: GitHub
- URL: https://github.com/skarab42/lw.svg-parser
- Owner: skarab42
- License: mit
- Created: 2016-12-08T13:13:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-03T09:54:20.000Z (almost 8 years ago)
- Last Synced: 2024-05-21T11:29:17.185Z (6 months ago)
- Language: JavaScript
- Size: 870 KB
- Stars: 2
- Watchers: 2
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# lw.svg-parser
SVG parser for [LaserWeb/CNCWeb](https://github.com/LaserWeb/LaserWeb4).## Supported tags
```html
```## Features
- ViewBox, PreserveAspectRatio
- Clipping paths with [Clipper.js](https://sourceforge.net/projects/jsclipper/)
- Promise mechanism
- ES6 / UMD module## Demo
https://lautr3k.github.io/lw.svg-parser/dist/example/## Installation
Using NPM
```
npm install lw.svg-parser
```Using GIT
```
git clone https://github.com/lautr3k/lw.svg-parser.git
cd svg-parser
npm install
```Or download the last build from https://raw.githubusercontent.com/lautr3k/lw.svg-parser/master/dist/lw.svg-parser.js
```htmlvar parser = SVGParser.Parser();
```
## Settings (all are optional)
```javascript
let settings = {
includes: ['svg', 'g', 'defs', 'use', 'line', 'polyline', 'polygon', 'rect', 'circle', 'ellipse', 'path', 'title', 'desc', 'image', 'text'],
excludes: ['#text', '#comment'],
traceSettings: { // Arc, Bezier curves only
linear : true, // Linear trace mode
step : 0.01, // Step resolution if linear mode = false
resolution : 100, // Number of segments we use to approximate arc length
segmentLength: 1 // Segment length
},
onTag: tag => {} // Called after a tag is parsed
}
```## Usages
```javascript
import Parser from 'svg-parser'let parser = new Parser(settings)
// must be an raw XML string, XMLDocument, Element or File object
return parser.parse(input).then(tags => {
console.log('tags:', tags);
tags.forEach(tag => {
tag.getPaths() // return an array of Path objects (all contours + holes)
tag.getShapes() // return an array of ExPolygons objects from Clipper.js (filled shapes)
})
})
.catch(error => {
console.error('error:', error);
});
```After the main `` tag was parsed you can access this two properties on the parser instance :
```javascript
parser.editor // Editor info { name, version, fingerprint }
parser.document // Document info { width, height, viewBox }
// where viewBox is { x, y, width, height }
```