The code is taken from https://github.com/svg/svgo/pull/976, refactored
with new api, covered types and simplified.
Plugin has no dependencies so can be used without changing.
```
const inlineDefs = require('./inlineDefs.js');
module.exports = {
plugins: [
'preset-default',
inlineDefs
]
};
```
- applyTransforms is prepared to be a separate plugin, in v3 I will
remove it from convertPathData
- migrated to tsdoc
- removed optimisation with stroke-width inside id (still not idea how
it worked)
- added deoptimisation when id is on element to fix redefining in `<use>`
Note: review with hidden whitespaces
This is just initial thoughts. Feel free to suggest any changes.
Here are described only the new visitor plugins api. Old "full", "perItem", "perItemReverse" will be removed in v3. Old JSAPI class on every node will be also removed so nodes could be plain objects.
This is a big one
- got rid from another closestByName usage
- delegated removing empty defs elements to removeEmptyContainers plugin
- got rid from all css-tools usages (most inlineStyles code was there
for some reason)
- combined a few loops
- fixed useMqs option (I would remove it in v3 for simplicity as it
seems nobody use it)
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.
`prefixIds` plugin currently breaks url()-links inside `style` attributes:
```javascript
optimize(
`<g style="fill:url(#brush-id);stroke:url(#pen-id)"/>`,
{ plugins: ['prefixIds'] }
).data
```
will generate `<g style=""/>`. Seems like `prefixIds` assumes that attribute's whole value might be `url()`, but this is not the case for the `style` attribute.
This fix solves the issue by preserving all attribute's content other than #id inside url(). It also adds some more tests for the `prefixIds` plugin.
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.
- covered with tsdoc
- replace another closestByName usage with visitSkip symbol to skip
subtree instead of skipping element by ancestor
Better review with hidden whitespaces as most code just got bigger indent.
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.