Ref https://github.com/svg/svgo/issues/1596
At the moment dynamic import may randomly fail with segfault.
To workaround this for some users .cjs extension is loaded
exclusively with require.
Ref https://github.com/ai/nanocolors#nano-colors
Nanocolors is deprecated in favour of picocolors to avoid drama.
All dependencies already migrated. Also fixed one vulnerability.
The main change is step away from named exports and dual modules
support in favour of smaller package.
nanocolors checks for --color and --no-color flags to force or disable
output coloring. Which can be used instead of strip-ansi package which
btw introduced vulnerability recently.
Ref https://github.com/svg/svgo/issues/1579
In config of course. Projects with type:module can now use modules to
export config
```js
export default {
plugins: []
}
```
Also added support for resolving svgo.config.mjs and svgo.config.cjs.
Moved loadConfig tests to svgo-node tests.
mjs test is skipped for now in node 10, just don't use modules there
Ref https://github.com/ai/nanocolors
Nanocolors is the new player in color libraries. And it's perfectly
packaged as all @ai packages. Colorette is already replaced even
in transitive dependencies.
node.parentNode will be removed in v3 along with JSAPI class wrapper on
each node.
Style manager uses it to find inherited styles. To workaround this
I collected all parents along with all styles. This constraints style
manager to work only with initial ast which should not be a problem as
each plagin execution is isolated.
- covered with tsdoc
- migrated to visitor plugin api
- slightly simplified (hope so) logic by avoiding loop over order array
in every compare function call
- rewrote tests
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
`os` package in js2svg module bothered me for a long time.
We had to hack rollup to mock it for browser.
Thanks to https://github.com/svg/svgo/pull/1546 we now can pass eol from
svgo-node entry point and simplify build.
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.
The logic is a little messy. Will be better when we drop node 12 support
and use optional chaining.
- migrated to visitor plugin api
- covered with types
- get rid from patching params as plugin state
- replaced many node.computedAttr() with style manager
- enabled and fixed removeNone param test (was merged as muted back in 2017)
- added ability to return null and not run visitor in plugins
- migrated to visitor plugin api; combination of enter and exit helped
to fit into single traverse
- got rid from the only node.clone() usage in the project so no need to
reimplement it
- the logic is a bit simplified
This should help to avoid node.parentNode and closestByName
in some cases by skiping visiting children of current node.
Works only in `enter` listener.