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.
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.
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">
- 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 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)