1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00
Commit Graph

1315 Commits

Author SHA1 Message Date
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
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
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
d9102930ca Fix CI 2021-09-10 19:47:15 +03:00
f587aae1c2 Refactor removeEditorsNSData (#1557)
- covered with types
- migrated to visitor plugin api
- got rid from parseName utility in favour of simple string operations
2021-09-10 19:34:27 +03:00
298820b8d9 Refactor cleanupIDs (#1556)
I still did get how id generation works but data flow is clear now at
least.

- covered with types
- migrated to visitor plugin api
- got rid of traverse api
2021-09-05 17:35:37 +03:00
107922405a Refactor minifyStyles plugin (#1552)
- migrated to visitor plugin api
- covered with types
- get rid from "traverse" usage

Splitted the work to collecting and modifying when root exit.
2021-09-05 17:35:11 +03:00
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
fab4b255c7 Add xmlns:xlink in reusePaths plugin (#1555)
Ref https://github.com/svg/svgo/issues/1200
2021-09-03 20:57:01 +03:00
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
c80ffca0fb Update devDependencies (#1550)
* @rollup/plugin-commonjs      ^17.1.0  →  ^20.0.0
* @rollup/plugin-node-resolve  ^11.2.1  →  ^13.0.4
* jest                         ^27.0.6  →  ^27.1.0
* playwright                   ^1.14.0  →  ^1.14.1
* rollup                       ^2.56.2  →  ^2.56.3
* typescript                    ^4.3.5  →   ^4.4.2
2021-09-01 15:46:49 +03:00
cf03c2398d 2.5.0 v2.5.0 2021-08-28 12:15:56 +03:00
680e143daf Add transform-origin to presentation attributes
Ref https://github.com/svg/svgo/issues/1475
2021-08-27 23:39:51 +03:00
bc95263885 Refactor removeUnknownsAndDefaults (#1548)
- got rid from two computeAttr usages
- got rid from node.parentNode usages
- avoided mutating global _collections objects
- refactored with visitor api
- covered with types
- skip whole foreignObject subtree not only its children
2021-08-27 23:02:28 +03:00
5ad2d4a5f6 Refactor removeOffCanvasPaths plugin (#1545)
- refactored with visitor plugin api
- covered with types
- replaced parentNode traverse with visitSkip symbol
- replaced regex path parser with parsePathData
- get rid from global state which lead test case to invalid state
2021-08-27 17:15:18 +03:00
6002f0bf65 Check types in path tests 2021-08-27 17:05:39 +03:00
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
ac8edbaf41 Fix applying transform to arc with zero radius
Ref https://github.com/svg/svgo/issues/1500
2021-08-27 01:03:11 +03:00
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
cce036f285 Refactor convertColors (#1543)
- refactored with visitor plugin api
- covered with types
2021-08-25 20:52:21 +03:00
a228020329 Refactor defs plugins (#1544)
Refactored and covered with types following plugins

- removeUselessDefs
- sortDefsChildren
2021-08-25 20:52:07 +03:00
0ead871eed Cover with types numeric values plugins (#1541)
- cleanupNumericValues
- cleanupListOfValues
2021-08-24 14:57:09 +03:00
4082eca762 Refactor cleanupEnableBackground with visitor plugin api (#1540)
Slightly restructured plugin to do less work in case no filters used.
2021-08-24 14:20:23 +03:00
a2331a5dee removeViewBox and convertShapeToPath types and visitor (#1537)
- added types to convertShapeToPath
- refactored removeViewBox with visitor plugin api and got rid from one
  closestByName usage
2021-08-24 13:41:26 +03:00
74c383153e Cover mergePaths plugin with types (#1539)
- covered mergePaths plugin
- covered big path logic
2021-08-24 13:41:16 +03:00
b359730219 Drop unused bézier utilities 2021-08-24 03:01:03 +03:00
147d2dadd6 Refactor convertRelativeToAbsolute 2021-08-24 03:00:18 +03:00
539237ce87 Normalize path data structure (#1538)
Use modern path data structure in all plugins.
Will be easier to cover with types.
2021-08-24 00:01:18 +03:00
ecf855db50 Clarify how to enable/configure builtin plugins (#1531)
I just spent quite a while trying to upgrade to svgo 2.3 because I was thinking that all the configuration I was passing to `extendDefaultPlugins()` previously should now be in `preset-default` overrides. 

Just adding some examples of enabling other builtin plugins could clarify it? 

Maybe I was just being stupid, but a thought :)

Co-authored-by: Bogdan Chadkin <trysound@yandex.ru>
2021-08-23 23:16:36 +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