1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-03 05:42:32 +03:00
Commit Graph

1243 Commits

Author SHA1 Message Date
c9ecc384c7 Add descendants test and universal selector support 2021-08-23 19:24:04 +03:00
5bf41deb3c Support more attributes selectors 2021-08-23 16:54:35 +03:00
3ce763a2dc Add selectors list test 2021-08-23 14:37:04 +03:00
8dc2806bdc Move tests to selectAll 2021-08-23 14:30:09 +03:00
da63166afc Remove css-select 2021-08-23 14:30:09 +03:00
4da3ede37b Support matches and combinations 2021-08-23 14:30:09 +03:00
2d0d3e2889 Replace css-select with custom implementation
There are a few benefits of custom implementation

- csstree instead of css-what parser
- 9 less dependecies
- only standard features are supported (css-select has :parent from jquery)
- new implementation allows to get rid of parentNode
2021-08-23 14:30:09 +03:00
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
98c023bdb0 Drop node.class usages (#1533)
We are gonna remove everything outside of xast.
Here's dropped class prop.
2021-08-21 19:42:32 +03:00
e4918ccdd1 Covert removeHiddenElems with types (#1532)
Covered removeHiddenElems plugin and big part of our code
- path parser and stringifier
- style manager
2021-08-21 14:55:05 +03:00
1368f8dc93 Remove mention of deprecated extendDefaultPlugins. (#1529) 2021-08-15 22:55:29 +03:00
75ec2943b0 Update minor and patch dependencies (#1528)
* @rollup/plugin-node-resolve  ^11.2.0  →  ^11.2.1
* @types/jest                  ^27.0.0  →  ^27.0.1
* colorette                     ^1.2.2  →   ^1.3.0
* commander                     ^7.1.0  →   ^7.2.0
* css-tree                      ^1.1.2  →   ^1.1.3
* eslint                       ^7.22.0  →  ^7.32.0
* playwright                    ^1.9.2  →  ^1.14.0
* prettier                      ^2.2.1  →   ^2.3.2
* rollup                       ^2.42.1  →  ^2.56.2
* typescript                    ^4.2.3  →   ^4.3.5
2021-08-15 13:57:58 +03:00
9b8f13e911 Add plugin types (#1527)
Covered following plugins
- addAttributesToSVGElement.js 
- addClassesToSVGElement.js 
- cleanupAttrs.js 
- convertEllipseToCircle.js 
- removeAttributesBySelector.js 
- removeAttrs.js 
- removeComments.js 
- removeDesc.js 
- removeDoctype.js 
- removeElementsByAttr.js 
- removeEmptyText.js 
- removeMetadata.js 
- removeRasterImages.js 
- removeScriptElement.js 
- removeStyleElement.js 
- removeTitle.js 
- removeXMLProcInst.js
2021-08-15 13:52:41 +03:00
7ec255719c Refactor adhoc plugins with visitor api (#1526)
- addAttributesToSVGElement
- addClassesToSVGElement
- removeAttributesBySelector
- removeAttrs
- removeElementsByAttr
2021-08-14 16:48:39 +03:00
e6b441aca0 Convert cleanupListOfValues and cleanupNumericValues to visitor (#1521)
SLightly refactored
2021-08-14 16:48:32 +03:00
7b6e73048f moveElemsAttrsToGroup.js: fix missing return value in Array.every() (#1525) 2021-08-14 13:12:23 +03:00
11b2801bd5 CI: remove Node.js 15 and add 16 (#1523) 2021-08-14 13:10:06 +03:00
b41c6fe473 removeUselessStrokeAndFill.js: use String.startsWith() (#1522) 2021-08-14 13:09:57 +03:00
87ad664659 2.4.0 v2.4.0 2021-08-13 20:00:44 +03:00
07f8d606e0 Implement preset-default plugin (#1513)
I saw complaints about `extendDefaultPlugins` api

- it cannot be used when svgo is installed globally
- it requires svgo to be installed when using svgo-loader or svgo-jsx
- it prevents using serializable config formats like json

In this diff I introduced the new plugin which is a bundle of all
default plugins.

```js
module.exports = {
  plugins: [
    'preset_default',
    // or
    {
      name: 'preset_default',
      floatPrecision: 4,
      overrides: {
        convertPathData: {
          applyTransforms: false
        }
      }
    }
  ]
}
```
2021-08-13 19:07:08 +03:00
9e578b515a Reset current cursor on Z
Ref https://github.com/svg/svgo/issues/1510
2021-08-13 18:39:55 +03:00
179ca5c60f Remove the unused intersectArrays util (#1459) 2021-08-12 21:58:59 +03:00
efa518b23d Replace deprecated methods in jsAPI (#1479) 2021-08-12 21:53:22 +03:00
454b4277a3 Remove flag spaces for all arcs (#1484)
Ref #1476

The issue is that a path command may have multiple arcs, and the space optimization was only applied to the first one. Modified a test to check it.


Co-authored-by: Josep del Río <joseprio@fb.com>
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
2021-08-12 21:51:26 +03:00
9892e28a71 Refactor convertShapeToPath with visitor api (#1519)
This plugin also removes invalid polyline and polygon.
Looks like out of pluginn scope.
2021-08-12 21:21:38 +03:00
c3695ae533 Migrate to jest (#1520)
Mocha doesn't have a lot of features provided by jest.
There is a great assertion library out of the box.
And the most cool feature is inline snapshots.
Mocha also hides errors which makes debugging a nightmare sometimes.
2021-08-12 18:06:10 +03:00
862c43ec64 Drop examples folder 2021-08-12 15:51:13 +03:00
f00bd727b0 Refactor basic plugins with visitor api (#1518)
- cleanupAttrs
- convertEllipseToCircle
- removeDesc
- removeDoctype
- removeEmptyText
- removeMetadata
- removeRasterImages
- removeScriptElement
- removeStyleElement
- removeTitle
- removeXMLProcInst
2021-08-12 14:57:36 +03:00
35b7356ff0 Pass parent node to visitor (#1517)
Wrapping each node with JSAPI class and passing parent to it is not
reliable. Parent may be changed but the reference will stay.

Here I wasn't able to detach comment from parent node for some reason.
Explicit parent node inferred while ast traverse is easier to debug and
work with. Eventually we will not need to wrap each node with JSAPI class.
2021-08-12 13:05:09 +03:00
2c0c361074 Collect stylesheet once per plugin (#1456)
computeStyle(node) in isolation is quite slow utility because it
collects style elements across whole document, parses and sort them.

In this diff I splitted it into `collectStylesheet(root)` and
`computeStyle(stylesheet, node)` which are easy integrate with new
visitor plugin api.
2021-08-12 03:08:39 +03:00
69d01746cd Exclude test files from the npm package. (#1458) 2021-08-12 02:04:08 +03:00
19014a1113 add Oh My SVG to frontends (#1507)
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
2021-08-11 01:18:53 +03:00
9ae23e4cd5 Add SVG Gobbler to "Ways to use SVGO" (#1503)
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
2021-08-10 19:56:45 +03:00
0e71422c8d Add "another way to use SVGO" (#1501)
I've added a link to a free API to use SVGO. May be useful for somebody!

For transparency sake; I'm one of the creators of the API.
2021-08-10 19:53:30 +03:00
c4ae19e250 Replace chalk with colorette (#1511)
Remove 5 deps from production install:
`ansi-styles`, `supports-color`, `color-convert`, `has-flag`, `color-name`.

Also reduce deps when using PostCSS and SVGO together, since PostCSS
uses colorette.

Tested with `yarn install svgo`.
2021-08-04 18:40:33 +03:00
cef184cdaf Fix typo in README built-in plugins table 2021-06-26 10:49:52 +03:00
daf2f88ef3 2.3.1 v2.3.1 2021-06-26 10:47:00 +03:00
25d0f87e33 Upgrade css-select from ^3.1.2 to ^4.1.3 (#1485) 2021-06-26 10:43:36 +03:00
59876d894b Remove unused artifacts 2021-05-24 02:04:32 +03:00
68798ebb6c Mark convertStyleToAttrs as disabled in README (#1472) 2021-04-18 21:38:45 +03:00
3d79f57a10 Convert convertPathData to visitor 2021-03-29 11:01:13 +03:00
06110b4fc0 Convert mergePaths to visitor 2021-03-29 03:08:15 +03:00
368a67b70f Convert removeHiddenElems to visitor 2021-03-29 02:34:34 +03:00
17aaf3617f Cleanup collapseGroups tests 2021-03-28 20:23:39 +03:00
e381ccc132 2.3.0 v2.3.0 2021-03-28 13:59:48 +03:00
09aec376c6 Implement exclude pattern cli option (#1409)
* Implement exclude pattern cli option

* fix: support empty exclude folder

* chore: remove debug

* Update lib/svgo/coa.js

Co-authored-by: Toke Voltelen <tokevoltelen@gmail.com>

* style: update format

* Remove -e support

Co-authored-by: Toke Voltelen <tokevoltelen@gmail.com>
Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
2021-03-28 13:03:35 +03:00
e3f37ec4e6 Add mergeStyles to readme 2021-03-28 11:59:27 +03:00
27bef1a954 Add "visitor" plugins support (#1454)
Visitor is a simple pattern which helps to avoid many type checks
and provide both "perItem" and "perItemReverse" functionality without
fragmentation.

The most important case is an ability to define state which in many
plugins specified either on module level or by polluting `params`.

In this diff I added visit and detachFromParent utilities and refactored
new mergeStyles plugin with it.

Also fixed bug when cdata content is merged into "text" node which is
not always valid.
2021-03-28 11:20:17 +03:00
19c77d2398 Add mergeStyles plugin (#1381) 2021-03-27 16:59:56 +03:00
d89d36eace Split regression extracter and runner (#1451)
A lot of new sources of regression tests may come and it's important to
make debug simpler.

Now regression-extract.js downloads and write svg files into
test/regression-fixtures. regression.js run each svg in this folder.
Mismatched svg diff is written into test/regression-diffs.
2021-03-25 00:12:13 +03:00