Ref https://github.com/svg/svgo/issues/32
Added `stringifyPathData` utility to produce small as possible path by
- matching leading moveto and line to commands (m -> l, M -> L)
- combining moveto and lineto commands
- avoiding space before decimal numbers if possible
Regexps are quite leaky for complex parsing. Regression tests caught
a few issues related to path parser.
In this diff I implemented the new spec-compliant parser which solves
2 regression cases and covers many edge cases hard to handle with
regexps.
This bug was also catched by regression tests. Single state was
overriden in opentag/closetag callbacks. Using stack state solved the
problem with nested textual tags.
Now many whitespaces bugs should go away.
There was a lot of PR with switching to another xml parser because sax
is not maintained for almost 4 years already.
Though switching parser to solve a few problems may introduce many new
bugs. This is why we decided to fork sax and maintain own version.
For initial release I removed node streams support which allows to get
rid from some magic in browser bundle build config and got rid from
String.fromCodePoint polyfill.
Forked package is here https://github.com/svg/sax
Currently, files named *.SVG are not being detected under Windows because of the case-sensitivity. This commit includes these in addition to *.svg files.
Ref https://github.com/svg/svgo/issues/1327
Config file now can only be js. `svgo.config.js` is searched by default.
Otherwise any js module specified in `--config` cli flag.
Config loader is exposed in entry point as `loadConfig(configFile, cwd)`.
- replaced named plugin object with "name" field
- dropped support for params in plugin object; use only params to pass plugin options
- dropped support for "boolean plugins"; use active field instead
```diff
-{
- pluginName: {
- fn,
- params: {},
- ...params
- }
-}
+{
+ name: 'pluginName',
+ fn,
+ params: {}
+}
```
Ref https://github.com/svg/svgo/issues/1015
Looks like `sax` is synchronous and we do not need to listen "end"
event. This allows to avoid all callbacks and make `optimize` method
synchronous.
Ref https://packagephobia.com/result?p=coahttps://packagephobia.com/result?p=commander
Coa was not updated for 2 years already and has outdated dependencies.
In this diff I replaced it with commander which has simpler syntax, none
dependencies and require arguments out of the box. Also array argument
is set syntactically which means more user-friendly "help".