1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-28 19:20:51 +03:00

340 Commits

Author SHA1 Message Date
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
Bogdan Chadkin
23c7f48130 Move platform specific eol to svgo-node entry point (#1565)
`os` package in js2svg module bothered me for a long time.
We had to hack rollup to mock it for browser.

Thanks to https://github.com/svg/svgo/pull/1546 we now can pass eol from
svgo-node entry point and simplify build.
2021-09-12 16:40:21 +03:00
Bogdan Chadkin
77102ed096 Add better parser errors (#1553)
Old SVGO errors were not very helpful. Packages like cssnano
(postcss-svgo) had to deal with a lot of issues which are hard to debug
with old errors.

```
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
```

New errors are more informative and may solve many struggles

```
Error: SvgoParserError: input.svg:2:29: Unquoted attribute value

  1 | <svg viewBox="0 0 120 120">
> 2 |   <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
    |                             ^
  3 | </svg>
  4 |
```
2021-09-12 01:09:10 +03:00
Adaline Valentina Simonian
e8321f0c27 Allow choosing EOL and appending final newline (#1546)
Addresses #951

Adds the following options to js2svg and CLI:

- eol — can be set to `lf` or `crlf`. If unspecified, js2svg uses the
  platform EOL.
- finalNewline — defaults to false. If true, js2svg ensures any SVG
  output has a final newline.

Tests added to cover both options.
2021-09-11 21:08:01 +03:00
Bogdan Chadkin
6eb4524aef Refactor removeUnusedNS plugin (#1559)
- covered with types
- migrated to visitor plugin api
- dropped traverse utility which is replaced by visitor
2021-09-10 20:30:34 +03:00
Bogdan Chadkin
93143f32c1 Refactor removeUselessStrokeAndFill (#1549)
The logic is a little messy. Will be better when we drop node 12 support
and use optional chaining.

- migrated to visitor plugin api
- covered with types
- get rid from patching params as plugin state
- replaced many node.computedAttr() with style manager
- enabled and fixed removeNone param test (was merged as muted back in 2017)
- added ability to return null and not run visitor in plugins
2021-09-05 17:34:13 +03:00
Bogdan Chadkin
1e5236d813 Refactor reusePaths plugin (#1551)
- migrated to visitor plugin api; combination of enter and exit helped
  to fit into single traverse
- got rid from the only node.clone() usage in the project so no need to
  reimplement it
- the logic is a bit simplified
2021-09-01 15:47:04 +03:00
Bogdan Chadkin
6002f0bf65 Check types in path tests 2021-08-27 17:05:39 +03:00
Bogdan Chadkin
3ca57d1856 Add visitSkip symbol (#1547)
This should help to avoid node.parentNode and closestByName
in some cases by skiping visiting children of current node.

Works only in `enter` listener.
2021-08-27 17:01:29 +03:00
Bogdan Chadkin
1b02799e18 Cover convertTransform plugin with types (#1542)
In this diff covered convertTransform pluginn with types
and got rid from global state which made data flow more complex and
error prone.
2021-08-25 20:52:31 +03:00
Bogdan Chadkin
0ead871eed Cover with types numeric values plugins (#1541)
- cleanupNumericValues
- cleanupListOfValues
2021-08-24 14:57:09 +03:00
Bogdan Chadkin
6cb2f7034f Drop node.style usages (#1534)
Parsing inline styles with csstree in place is easier.
Caching does not add much value here.
2021-08-22 16:18:55 +03:00