There are a few benefits of custom implementation
- csstree instead of css-what parser
- 9 less dependecies
- only standard features are supported (css-select has :parent from jquery)
- new implementation allows to get rid of parentNode
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
}
}
}
]
}
```
Ref #1476
The issue is that a path command may have multiple arcs, and the space optimization was only applied to the first one. Modified a test to check it.
Co-authored-by: Josep del Río <joseprio@fb.com>
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
Mocha doesn't have a lot of features provided by jest.
There is a great assertion library out of the box.
And the most cool feature is inline snapshots.
Mocha also hides errors which makes debugging a nightmare sometimes.
Wrapping each node with JSAPI class and passing parent to it is not
reliable. Parent may be changed but the reference will stay.
Here I wasn't able to detach comment from parent node for some reason.
Explicit parent node inferred while ast traverse is easier to debug and
work with. Eventually we will not need to wrap each node with JSAPI class.
computeStyle(node) in isolation is quite slow utility because it
collects style elements across whole document, parses and sort them.
In this diff I splitted it into `collectStylesheet(root)` and
`computeStyle(stylesheet, node)` which are easy integrate with new
visitor plugin api.
Remove 5 deps from production install:
`ansi-styles`, `supports-color`, `color-convert`, `has-flag`, `color-name`.
Also reduce deps when using PostCSS and SVGO together, since PostCSS
uses colorette.
Tested with `yarn install svgo`.
Visitor is a simple pattern which helps to avoid many type checks
and provide both "perItem" and "perItemReverse" functionality without
fragmentation.
The most important case is an ability to define state which in many
plugins specified either on module level or by polluting `params`.
In this diff I added visit and detachFromParent utilities and refactored
new mergeStyles plugin with it.
Also fixed bug when cdata content is merged into "text" node which is
not always valid.
A lot of new sources of regression tests may come and it's important to
make debug simpler.
Now regression-extract.js downloads and write svg files into
test/regression-fixtures. regression.js run each svg in this folder.
Mismatched svg diff is written into test/regression-diffs.