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.
When running into a multi-class selector with `inlineStyles`, it would
only remove the first class of the selector instead of all of them.
This iterates the classes in the selector instead of only taking the
first. Also performs some minor refactors.
* Deduplicate dependencies in our `yarn.lock` file with `yarn dedupe`.
* Upgrade dependencies with Dependabot alerts with `yarn up -R {}`.
This only impacted devDependencies, and does nothing to our tests or
bundle sizes, etc.
Style property names are case-insensitive, for example `fill`, `FILL`,
and `FiLl` are all valid but refer to the same property. So when
inlining styles, we compare the lowercase strings and only use the last
instance of the property rather than embed them all.
In practice, this plugin does not work to remove embedded jpg images.
On further inspection, it's because the plugin is looking for
image/jpg, which I'm not even sure is a valid mimetype. Inkscape uses
image/jpeg as the mimetype for embedded JPG images.
Co-authored-by: Seth Falco <seth@falco.fun>
Fixes a bug where the reusePaths plugin would reuse the node ID that
it's optimizing, but that ID was also referenced in a href elsewhere
in the document, so it unintentionally applied the path to other nodes.
The regression-test GitHub Action was failing for all pull requests due
to not handling the gzipped archive properly.
This resolved it by piping the response body to zlib#createGunzip
first. Also updates the relevant dependencies.
Signed-off-by: Seth Falco <seth@falco.fun>
Co-authored-by: strarsis <strarsis@gmail.com>
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
Preview: https://github.com/ADTC/svgo/blob/patch-1/README.md
* Split up code blocks by moving text outside them. (This also ensures
that the Copy function makes sense. _See screenshot:_)
* <img width="380" alt="image"
src="https://user-images.githubusercontent.com/6047296/211246090-64749e5f-3f1e-413b-be39-a99fa2f1b425.png">
* Remove the redundant list of default plugins and refer to the table
instead.
* Sort the table of plugins alphabetically. (It's easier to scan for a
plugin.)
* _I suggest maintaining the sort when adding new items._
* Replace the enabled/disabled code in Default column with just Yes or
blank.
* Tabulate the "Other ways to use" section and remove redundant "as
a/an".
* Correct the word Donators to Donors.
* Add a new section called _Troubleshooting_.
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">
I'm currently profiling my build pipeline and noticed that the
`strongRound` function showed up a couple of times, followed immediately
with a bit of GC cleanup shortly after. We can speed up that function by
avoiding the string casting caused by `Number.prototype.toFixed()`.
In my project's build pipeline with lots of svg icons this saves about
1.4s in total.
<img width="792" alt="js-tools-strongRound"
src="https://user-images.githubusercontent.com/1062408/204393563-666be3e0-e0ee-4608-9b7d-9ea8352bd36b.png">