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

608 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
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
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
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
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
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
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
2260aab8c1 Remove csso types from definitions 2022-11-18 11:56:38 +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
6295c60fbf Rename cleanupIDs to cleanupIds for consistency with prefixIds 2022-10-23 11:54:48 +03:00
Bogdan Chadkin
bc07c483c3 Remove prefix param from cleanupIDs plugin 2022-10-23 11:40:48 +03:00
Bogdan Chadkin
f5d1dd06cc Loosly cover with types convertPathData 2022-10-16 14:53:04 +03:00
Bogdan Chadkin
dd9cad1cf9 Add sortAttrs to default preset 2022-10-09 17:29:11 +03:00
Bogdan Chadkin
e6bd703b0a Remove unused active and type fields from plugins 2022-10-08 23:39:58 +03:00
Bogdan Chadkin
12272958db Upgrade csso and csstree 2022-10-08 14:57:57 +03:00
Bogdan Chadkin
075ab164f6 Store builtin plugins as an array 2022-10-02 22:58:02 +03:00
Bogdan Chadkin
954faf3c87 Remove default plugin.params support 2022-10-02 19:43:06 +03:00
Bogdan Chadkin
516c6e1fc1 Drop createContentItem from public api and JSAPI node wrappers 2022-10-02 12:00:44 +03:00
Raphael Boidol
2ea65860f0 Remove stable package in favor of native stable sort (#1681) 2022-10-01 21:21:09 +03:00
Liam Mitchell
1b88baa123 More helpful preset warnings (#1645)
* More helpful preset warnings

* Optimise
2022-02-07 12:22:14 +03:00
Bogdan Chadkin
da1d761b53 Refactor removeDimensions and removeXMLNS (#1640)
Migrated both to visitor api and tsdoc
2022-01-22 00:12:52 +03:00
Bogdan Chadkin
238d3bf600 Refactor convertStyleToAttrs (#1635)
Did not rewrite much, just migrated to tsdoc and visitor plugin api.
This plugin will be obsolete eventually.
2022-01-20 10:55:01 +03:00
Bogdan Chadkin
aaf1cfa5e7 Refactor removeNonInheritableGroupAttrs and moveGroupAttrsToElems (#1636)
Batched in one PR. Pretty simple changes. Just migrated to api and
added more safety checks for types.
2022-01-19 20:42:13 +03:00
Bogdan Chadkin
068db0e894 Refactor applyTransforms (#1637)
- 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
2022-01-19 20:41:10 +03:00
Rogier Slag
04abd6fc59 Correct typo in comment in removeDimensions plugin (#1633) 2021-12-28 16:15:55 +03:00
Bogdan Chadkin
dfc5b982c9 Rename master branch to main 2021-12-25 15:09:34 +03:00
Bogdan Chadkin
79d4babcaf Replace closestByName utility with visitSkip (#1613)
The last usage of closestByName utility based on node.parentNode
is removed here. One step closer to clean ast in v3.
2021-12-07 11:05:15 +03:00
Bogdan Chadkin
72b972261d Refactor inlineStyles (#1601)
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)
2021-10-30 01:31:52 +03:00
Devon Govett
2d6deeaf21 Remove xmlns:xlink in removeXMLNS plugin (#1508)
xmlns:xlink is also not required in SVGs embedded in HTML
2021-10-15 12:16:08 +03:00
Bogdan Chadkin
4377ea38c4 Refactor removeEmptyAttrs (#1594)
- migrated to visitor plugin api
- covered with tsdoc
2021-10-07 14:07:06 +03:00
Ilya Skriblovsky
6235264cf3 Fix prefixIds plugin to properly handle url()s in style="..." (#1592)
`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.
2021-09-30 14:40:40 +03:00
Bogdan Chadkin
543346ca97 Refactor moveElemsAttrsToGroup (#1574)
- migrated to visitor plugin api
- covered with tsdoc
- added more test cases
- restructured and simplified code
2021-09-23 21:52:46 +03:00