1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Commit Graph

1399 Commits

Author SHA1 Message Date
Seth Falco
4c2cc1bbdb feat(inlineStyles): remove redundant presentation attrs (#1829)
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.
2023-11-11 12:43:13 +00:00
Seth Falco
742cee1910 ci: use and run tests for node 20 (#1827) 2023-11-09 15:57:46 +00:00
Seth Falco
6d26482583 fix: skip keyframes with webkit prefix (#1826)
If an SVG features `keyframes` with the `-webkit` prefix, it would throw
an error before. This will treat them the same as regular `keyframes`.
2023-11-09 15:19:31 +00:00
Seth Falco
96fedb4855 chore: change link to homepage in package.json (#1824)
Change the link of the homepage from this Git repository (which is
already documented in `bugs` and `repository` to a link to the
documentation.
v3.0.3
2023-11-08 16:00:36 +00:00
Seth Falco
43df633348 docs: add documentation for all commands (#1808) 2023-11-07 23:43:09 +00:00
Seth Falco
5aad38bcc7 fix(inlineStyles): empty css block created empty attribute (#1823)
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.
2023-11-07 23:20:48 +00:00
Seth Falco
07c09199ed fix: remove hrefs for unconventional namespaces (#1820) 2023-11-04 15:17:15 +00:00
Seth Falco
e21e56060b feat(removeScriptElement): add all known event types (#1819)
Update the list of event attributes to include everything listed on MDN.
2023-11-04 14:07:29 +00:00
Seth Falco
e73ee2de96 fix(removeScriptElement): collapse a tag propertly (#1818) 2023-11-04 13:42:07 +00:00
Seth Falco
1df2e0fa39 fix(cleanupIds): skip generated ids for malformed references (#1817)
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
2023-11-04 12:56:20 +00:00
Seth Falco
a880505859 fix(removeScriptElement): remove link anchors with scripts (#1807) 2023-10-29 14:46:55 +00:00
Seth Falco
7de793c54a fix(removeComments): make preserving comments a param (#1812)
Converts the hard-coded exception to a param so users can override this
behavior to preserve custom patterns or drop the logic altogether.
2023-10-27 18:03:50 +01:00
Seth Falco
bf45a0225a fix(prefixIds): dynamic functions should produce same prefix for given id (#1814)
Reuse the same prefix if an ID is encountered multiple times.
2023-10-25 12:54:02 +01:00
Tanya Bouman
d4f0de0f5c README: image-webpack-loader -> image-minimizer-webpack-plugin (#1771) 2023-10-24 10:49:16 +01:00
Lehoczky Zoltán
999b2a17e0 chore: update postcss-svgo link (#1770) 2023-10-23 10:49:54 +01:00
Seth Falco
e56a338234 deps: update @babel/traverse (#1813)
Updates a vulnerable dependency, only impacting dev and CI.
2023-10-22 17:29:55 +01:00
Seth Falco
c51dcfa6bb fix: warn and do not crash on null plugin (#1803)
If we received null/undefined/empty plugins, instead of crashing, log a
warning and ignore them.
2023-10-22 14:11:34 +01:00
Seth Falco
6eac770ba5 feat: convert one stop gradients plugin (#1790)
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.
2023-10-22 13:53:39 +01:00
Seth Falco
3966c10565 refactor: create hasScripts util (#1809)
Introduces a hasScript utility which can be reused to consistently check for scripts, whereas before different plugins performed this check differently.
2023-10-22 10:58:03 +01:00
Seth Falco
e529c6674d fix(removeDesc): removeAny should be disabled by default (#1806)
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.
2023-10-04 11:45:06 +01:00
Seth Falco
027e110f9d chore: increment patch version (#1804) 2023-09-27 17:45:32 +01:00
Seth Falco
02c7a78536 fix(convertTransform): do not add redundant space between functions (#1802)
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.
2023-09-27 17:20:10 +01:00
Seth Falco
2539b9f4c6 fix(inlineStyles): remove all classes in multiclass selector (#1801)
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.
2023-09-27 17:19:46 +01:00
Seth Falco
b15da27af4 fix(minifyStyles): pass empty arrays for usage (#1800) 2023-09-25 23:13:54 +01:00
Seth Falco
197be56958 deps: update deps based on dependabot alerts (#1799)
* 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.
2023-09-25 21:32:55 +01:00
Alex
9a83ed43a2 GitHub Workflows security hardening (#1724)
Signed-off-by: Alex <aleksandrosansan@gmail.com>
2023-09-25 20:04:21 +01:00
Seth Falco
7e99c0bd49 fix(inlineStyles): case insensitive style props (#1797)
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.
2023-09-25 19:05:11 +01:00
Seth Falco
42f7752db1 fix(cleanupIds): handle when 2 ids referenced in one attr (#1795) 2023-09-25 19:04:31 +01:00
Seth Falco
f07e9de089 fix: resolve regression test for removeHiddenElems (#1793) 2023-09-25 19:04:06 +01:00
Seth Falco
078a09c19a fix(reusePaths): pass test-regression task (#1791)
Signed-off-by: Seth Falco <seth@falco.fun>
2023-09-25 19:03:42 +01:00
Seth Falco
82593c6134 test: update jest (#1792) 2023-09-24 17:50:38 +01:00
Abe Fehr
437c09b006 Add support for image/jpeg mimetype (#1742)
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>
2023-09-24 13:32:13 +01:00
Seth Falco
bd750ceebb fix(reusePaths): dont reuse id if referenced in href (#1784)
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.
2023-09-23 21:47:04 +01:00
Seth Falco
5f40d8bce4 fix(reusePaths): reuse defs tag if exists and remove redundant nodes (#1785) 2023-09-23 21:37:04 +01:00
Seth Falco
9f7894d7e9 test: add check for keyframe selector to (#1783)
Adds test for issue reported regarding keyframe selectors.
2023-09-23 16:57:42 +01:00
Seth Falco
59ab80eed2 test: fix regression testing action (#1788)
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>
2023-09-23 07:47:30 +01:00
ADTC
73f7002ab6 Refactor README to be easier to read through (#1731)
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_.
2023-02-16 01:31:28 +03:00
Marvin Hagemeister
aa5d667fcb Speed up stringifyNumber (#1717)
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">
2022-11-30 11:53:51 +03:00
Marvin Hagemeister
c641da2734 Speed up strongRound by avoiding string casting (#1716)
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">
2022-11-30 11:53:39 +03:00
Bogdan Chadkin
ae32acf514 3.0.2 v3.0.2 2022-11-18 19:46:18 +03:00
Bogdan Chadkin
2f8adced74 Upgrade css-tree types 2022-11-18 12:00:54 +03:00
Bogdan Chadkin
2260aab8c1 Remove csso types from definitions 2022-11-18 11:56:38 +03:00
Bogdan Chadkin
da8840c0e1 v3.0.1 v3.0.1 2022-11-11 13:21:59 +03:00
Bogdan Chadkin
8dda989fad Revert version plugin 2022-11-11 13:18:48 +03:00
Bogdan Chadkin
0f8aa5dffa Add version plugin to yarn 2022-11-11 13:15:52 +03:00
Bogdan Chadkin
216082c591 Remove unused json plugin 2022-11-11 13:11:54 +03:00
Andrew
dd70f34b67 fix: begin's attribute incorrectly modification (#1658)
Co-authored-by: Andrey Nelyubin <nelyubin_a_a@sunlight.net>
2022-11-11 12:57:15 +03:00
Bogdan Chadkin
422fa142f2 Reuse plugin types for config 2022-11-11 12:50:33 +03:00
Bogdan Chadkin
e2e65cfc1e Move plugin types into d.ts 2022-11-11 12:19:38 +03:00
Bogdan Chadkin
a40fa216b6 3.0.0 v3.0.0 2022-10-23 17:03:45 +03:00