Ref https://github.com/svg/svgo/issues/1499
- migrated to visitor plugin api
- covered with tsdoc
- made the plugin idempotent as requested a few times
Now even manually running svgo a few times will not duplicate
prefix in ids and classes
- run each plugin test twice to see which plugin need to run many times
ideally idempotent plugins will allow to get rid of multipass option in v3
Old SVGO errors were not very helpful. Packages like cssnano
(postcss-svgo) had to deal with a lot of issues which are hard to debug
with old errors.
```
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
```
New errors are more informative and may solve many struggles
```
Error: SvgoParserError: input.svg:2:29: Unquoted attribute value
1 | <svg viewBox="0 0 120 120">
> 2 | <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
| ^
3 | </svg>
4 |
```
Addresses #951
Adds the following options to js2svg and CLI:
- eol — can be set to `lf` or `crlf`. If unspecified, js2svg uses the
platform EOL.
- finalNewline — defaults to false. If true, js2svg ensures any SVG
output has a final newline.
Tests added to cover both options.
I saw complaints about `extendDefaultPlugins` api
- it cannot be used when svgo is installed globally
- it requires svgo to be installed when using svgo-loader or svgo-jsx
- it prevents using serializable config formats like json
In this diff I introduced the new plugin which is a bundle of all
default plugins.
```js
module.exports = {
plugins: [
'preset_default',
// or
{
name: 'preset_default',
floatPrecision: 4,
overrides: {
convertPathData: {
applyTransforms: false
}
}
}
]
}
```