1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-31 07:44:22 +03:00
Commit Graph

298 Commits

Author SHA1 Message Date
04b2ae9a37 Implement path stringify (#1387)
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
2021-03-02 01:07:26 +03:00
4086e31334 Implement new path parser (#1378)
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.
2021-02-28 22:10:57 +03:00
71e47370bd Format lib with prettier (#1386)
Note: review with hidden whitespaces
2021-02-28 10:56:16 +03:00
0394bf0ea6 refactor: replace uses of for in (#1382)
Replace the uses of `for in` with `for of` and `Object.entries`/`Object.values`/`Object.keys`.

One case was further simplified by using a spread.
2021-02-27 23:17:30 +03:00
9de471a0f4 Handle nested textual tags
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.
2021-02-24 00:58:11 +03:00
9f084cc086 Preserve whitespace in elements containing text (#1220) 2021-02-23 18:25:30 +03:00
0021144d4e Fork sax (#1369)
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
2021-02-23 16:44:35 +03:00
a855b40ec5 Fail when specified config is wrong or json is specified 2021-02-22 23:50:42 +03:00
8d7cfa02c7 After ‘arcto’ path command(a or A) flags, spaces are no longer removed by default (#1353)
Co-authored-by: 壹丝 <jie.lijie@alibaba-inc.com>
2021-02-20 18:58:42 +03:00
ea82cc2880 Report parsing errors with filename 2021-02-20 00:59:54 +03:00
a7cc20bb43 Setup recommended eslint preset (#1345)
This is usually enough to prevent silly mistakes.
Formatting will be done by prettier after merging pull requests.
2021-02-19 15:26:07 +03:00
330e78b479 Fix reporting of config errors (#1342)
Errors are swallowed while resolving.
2021-02-19 12:11:35 +03:00
293fa1eed6 Fix new Buffer usage (#1341) 2021-02-19 02:31:06 +03:00
16cc8cf3a0 Added file detection for *.SVG files when working with folders (#1316)
Currently, files named *.SVG are not being detected under Windows because of the case-sensitivity. This commit includes these in addition to *.svg files.
2021-02-18 17:50:12 +03:00
082aee027d Fix plugins order (#1334)
Ref https://github.com/svg/svgo/issues/1333

While refactoring broke plugin order.
2021-02-18 17:46:28 +03:00
efa62c8e30 Fix multipass (#1332)
Ref https://github.com/svg/svgo/issues/1330 https://github.com/svg/svgo/issues/1148 https://github.com/svg/svgo/issues/1133 https://github.com/svg/svgo/pull/1227 https://github.com/svg/svgo/issues/985 https://github.com/svg/svgo/issues/943
Took tests from https://github.com/svg/svgo/pull/1177
2021-02-18 14:12:27 +03:00
0c85caa730 Fix 'ReferenceError: indent is not defined' (#1331) 2021-02-18 11:43:14 +03:00
d761decc0e Drop --enable and --disable flags 2021-02-16 19:17:53 +03:00
fd5e6406b1 Upgrade css-select 2021-02-16 19:14:20 +03:00
a6f14018ee Implement loadConfig utility (#1328)
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)`.
2021-02-16 19:11:13 +03:00
d273b26605 Provide es module bundle for browser (#1326)
The was a lot of requests to provide browser compatible module. In this
diff I added `svgo/dist/svgo.browser.js` bundle and tested it with
playwright.
2021-02-16 19:11:01 +03:00
b1dafc6780 Implement default plugins and plugins list extending 2021-02-15 22:20:05 +03:00
c9c7871e0d Simplify svgo api (#1325)
Dropped SVGO class and provided "optimize" function with svg and config
as inputs and "createContentItem".
2021-02-15 18:32:50 +03:00
225bfbb053 Move config processing into optimize 2021-02-15 16:57:01 +03:00
1b776ffea5 Simplify plugins configuration (#1324)
- 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: {}
+}
```
2021-02-15 14:30:09 +03:00
6cecd76f62 Remove config extending and full flag support 2021-02-15 13:12:29 +03:00
2965e8ccdb Drop plugin by path support and load builtins statically 2021-02-15 12:00:45 +03:00
a1c1b7f443 Remove json string as --config value support 2021-02-14 17:44:18 +03:00
cb14e3c0b3 Upgrade commander 2021-02-14 17:35:05 +03:00
1dc5ee3ee1 Make optimize synchronous (#1322)
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.
2021-02-14 14:59:50 +03:00
57aecc50ac Replace coa with commander (#1293)
Ref https://packagephobia.com/result?p=coa https://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".
2021-02-13 22:23:19 +03:00
1a35a58324 Replace util.promisify with fs.promises (#1290)
Node 10 add support for promisified fs methods.
https://nodejs.org/dist/latest-v10.x/docs/api/fs.html#fs_fs_promises_api

In this diff I replaced util.promisify package with the new methods.
Though this requires to bump end-of-life node versions.
2021-02-13 22:21:30 +03:00
4a08c6d039 Replace mkdirp with fs.mkdir with recursive flag (#1291)
Ref https://nodejs.org/dist/latest-v10.x/docs/api/fs.html#fs_fs_mkdir_path_options_callback

Node 10 add "recursive" flag support to fs.mkdir which behaves similar
to mkdirp package.

Though this requires to bump node support.
2021-02-13 21:46:15 +03:00
93170d3870 Drop object.values polyfill
Ref https://packagephobia.com/result?p=object.values

Object.values is supported since node 7. It can be removed with major
bump especially since it's quite heavy.
2020-10-02 23:16:51 +03:00
72db8ebbbf Change wording of API doc comment 2019-11-02 12:14:38 +03:00
99d9c3c13a Default info on SVGO.optimize API 2019-10-30 13:52:26 +03:00
71c7fe74b9 Add multipassCount to info object passed to the plugins.
Use info object to skip subsequent passes in prefixIds plugin to prevent unintended, multiple prefixing.
2019-10-29 22:50:59 +03:00
27cdeb7c1c Add a warning about plugin configuration error
Usual error by not proper YML syntax like #1115
2019-07-13 23:23:40 +03:00
ac34386466 Copy plugin params when initializing plugin by name 2019-07-13 22:52:56 +03:00
d3e91418aa Export config function to enable to use 2019-07-13 22:51:31 +03:00
3d6d8045d9 lib/config: load custom plugin defined via path in config 2019-07-13 22:48:35 +03:00
357de5f3ea lib/config: add setPluginActiveState function 2019-07-13 22:48:35 +03:00
8d0b9b8bf8 Fix typos 2019-07-13 16:22:33 +03:00
258fecfa6b Remove spaces after ‘arcto’ path command flags 2019-07-13 16:18:08 +03:00
fe0ecaf31e Updage changelog and documentation parts 2019-04-16 22:11:15 +03:00
eb0d66ab1b Replace colors dependency with chalk (#1061)
use 'chalk' for colors in console
2019-02-24 21:04:01 +03:00
f84bff3220 Support comma list of plugins for --disable, --enable options. (#1019)
support comma list of plugins for --disable, --enable options
2019-02-24 20:32:54 +03:00
d911f0f4c7 Option recursive (#837)
Add -recursive (-r) option
2019-02-24 19:54:59 +03:00
ee065be5a8 Fix indentation 2018-10-28 19:36:58 +03:00
5718ef276c Make default config behave as immutable 2018-10-28 19:35:37 +03:00