SVGs can have the same presentation attribute declared redundantly in
both the node attributes and `<style>` tag.
This wouldn't break anything, but we can shave off a few more bytes by
dropping the attribute in this case.
When running this plugin on an SVG with an empty block in the CSS, it
would apply it to the matched elements by adding an empty `style`
attribute. See the test for an example.
This resolves that by just dropping the declaration if it's empty.
I also had some chores pending which were trivial individually, I opted
to incorporate them here as well.
* In JSDocs, use the nullable syntax as it's more concise and familiar
from TypeScript usage.
* discord → Discord (proper nouns should match capitalization)
* Use actions/checkout v4 instead of v2
Detects if a redundant linearGradient or radialGradient is used with
only a single stop, which effectively means a solid color.
If this is found, just remove the gradient and replace references to it
with the color of the first and only stop defined.
Introduces a hasScript utility which can be reused to consistently check for scripts, whereas before different plugins performed this check differently.
As the description of the plugin states, it should only remove the
description if we can see it's just editor attribution, since this
element is used for accessibility.
In general, accessibility is more important than optimizations, so while
I could update the documentation to reflect this behavior, I believe the
default should be changed back.
The space is optional between transform functions in the `transform`
attribute and similar properties. This just omits the space as a
micro-optimization.
This does not add new tests is the scenario is covered adequately in
existing tests.
Also refactors js2transform to avoid concatenating in a loop.
I'm currently profiling my build setup and noticed that
`stringifyNumber` pops up here and there. Instead of going with the
double regex replace approach, we'll go with the faster approach in
`removeLeadingZero`.
In total the changes in this PR speed up the build by about `0.9s` in my
project.
<img width="798" alt="stringifyNumber"
src="https://user-images.githubusercontent.com/1062408/204154146-ce67d0c9-faf2-40a1-8186-8d34caea74a5.png">
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