-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (40 loc) · 1002 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { pathParse, serializePath } = require('./lib/path_parse')
const SVGParser = require('convertpath')
const fs = require('fs')
const parse = SVGParser.parse('./test/test.svg', {
plugins: [
{
convertUseToGroup: true, // at first
},
{
convertShapeToPath: true,
},
{
removeGroups: true,
},
// {
// convertTransfromforPath: true,
// },
{
viewBoxTransform: true, // at last
}
],
size: 1024,
})
const paths = parse.getPathAttributes()
paths.forEach(item => {
if (item.d) {
const pathDatas = pathParse(item.d).relCairo({
round: 2,
transform: item.transform || '',
})
item.d = serializePath(pathDatas)
}
})
const svgStr = `<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
${
paths.map(item => `<path d="${item.d}" fill="${item.fill}" stroke="${item.stroke}" />`).join('')
}
</svg>
`
fs.writeFileSync('./test.svg', svgStr)