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

351 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
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
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
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
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
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
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
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
Bogdan Chadkin
422fa142f2 Reuse plugin types for config 2022-11-11 12:50:33 +03:00
Bogdan Chadkin
6295c60fbf Rename cleanupIDs to cleanupIds for consistency with prefixIds 2022-10-23 11:54:48 +03:00
Bogdan Chadkin
53ed57c7e1 Expose typescript types 2022-10-17 00:10:39 +03:00
Bogdan Chadkin
5857816a5a Remove result.info.width and result.info.height 2022-10-10 01:32:12 +03:00
Bogdan Chadkin
420ae9d8a1 Throw SvgoParserError 2022-10-10 00:33:19 +03:00
Bogdan Chadkin
dd9cad1cf9 Add sortAttrs to default preset 2022-10-09 17:29:11 +03:00
Bogdan Chadkin
f649eabf6d Remove active flag in plugin config 2022-10-08 19:42:29 +03:00
Bogdan Chadkin
2d1c12c754 Remove returning ast from invoker 2022-10-08 19:16:18 +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
97553d83b6 Replace list of default plugins with default preset 2022-10-02 15:06:45 +03:00
Bogdan Chadkin
de5d68201b Drop full, perItem and perItemReverse plugin types 2022-10-02 14:53:34 +03:00
Bogdan Chadkin
acf103251c Fix encode without multipass 2022-10-02 13:15:29 +03:00
Bogdan Chadkin
d5a8555781 Drop node 10 require fallback when load config 2022-10-02 12:15:41 +03:00
Bogdan Chadkin
516c6e1fc1 Drop createContentItem from public api and JSAPI node wrappers 2022-10-02 12:00:44 +03:00
Bogdan Chadkin
50e836d5a4 Drop class list handler 2022-10-02 11:10:45 +03:00
Bogdan Chadkin
be458216a4 Drop all unused jsapi methods and fields 2022-10-02 09:55:08 +03:00
Bogdan Chadkin
783583538f Drop legacy JSAPI style handler 2022-10-02 00:24:43 +03:00
Bogdan Chadkin
bb590b8928 Drop extendDefaultPlugins 2022-10-02 00:17:16 +03:00
Raphael Boidol
2ea65860f0 Remove stable package in favor of native stable sort (#1681) 2022-10-01 21:21:09 +03:00
Bogdan Chadkin
b0d19ebd1b Update snapshot format 2022-10-01 16:27:41 +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
dfc5b982c9 Rename master branch to main 2021-12-25 15:09:34 +03:00
Kris Kowal
3a1c509b74 Fix extra newline at end of -o - output (#1237) 2021-12-23 14:16:48 +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
cb7e9be623 Add warning about enabling plugins in presets 2021-11-02 10:33:46 +03:00
Bogdan Chadkin
c7995035ef Load .cjs with require only (#1605)
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.
2021-10-30 01:31:36 +03:00
Bogdan Chadkin
d29cec48e3 Migrate to picocolors (#1606)
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.
2021-10-15 12:09:54 +03:00
Bogdan Chadkin
65b6bf4c16 Refactor svg stringifier (#1593)
- rewrote prototype class with functions
- covered with tsdoc
- added a few TODOs for v3
2021-10-07 14:06:55 +03:00
Bogdan Chadkin
7601b17ab5 Rename js2svg to stringifier 2021-10-01 14:44:17 +03:00
Bogdan Chadkin
203db9aaec Replace strip-ansi with --no-color flag (#1588)
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.
2021-09-30 14:39:12 +03:00
Bogdan Chadkin
6e23b9cf56 Cover svg parser with tsdoc (#1584)
Moved to lib/parser.js. The code will be slightly simpler
when JSAPI will be removed in v3.
2021-09-23 21:45:22 +03:00
Bogdan Chadkin
7111c52f96 Support es modules (#1583)
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
2021-09-23 21:44:55 +03:00
Bogdan Chadkin
4c6a091a90 Replace colorette with nanocolors (#1586)
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.
2021-09-23 21:44:40 +03:00
Bogdan Chadkin
79ceb09daf Avoid node.parentNode in style manager (#1576)
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.
2021-09-21 19:11:53 +03:00
Chris Wilkinson
1b56e70cc0 Fix config type (#1573) 2021-09-15 22:55:19 +03:00
Bogdan Chadkin
1c551a87c0 Refactor sortAttrs plugin (#1564)
- 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
2021-09-13 16:16:56 +03:00
Bogdan Chadkin
3d22a5b23d Refactor prefixIds (#1561)
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
2021-09-13 16:16:38 +03:00