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
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
eb934b40f6 Serve svg for regressions and cache w3c test suite 2021-03-23 00:29:29 +03:00
7389bcddbf Override default floatPrecision with global
Ref https://github.com/svg/svgo/issues/1426

Previously extendDefaultPlugins incorrectly overrided global
floatPrecision.
2021-03-22 19:36:05 +03:00
d08815c1cd Implement simple node clone (#1450)
https://github.com/svg/svgo/pull/1279 faced some problems with node cloning.
In this diff I moved class/style live objects to JSAPI and made it non
enumerable to avoid deep cloning issues.

class list and style declaration classes are not longer need own clone
methods.
2021-03-22 18:55:08 +03:00
3d4adb6b04 Simplify number rendering and fix -0 in path
Ref https://github.com/svg/svgo/issues/1422
2021-03-22 14:38:06 +03:00
316a002299 Remove hasAttr and hasAttrLocal usages (#1447)
In most cases simple check for null is enough.
2021-03-22 01:24:59 +03:00
447f82ca6b Convert addAttributesToSVGElement to item plugin (#1448)
"full" plugins prevents from possible optimisation. We need to migrate
all plugins to "perItem" type and later implement visitor plugin api to
allow state.
2021-03-22 01:24:41 +03:00
13a0ad056b Specify --ignore-path for ESLint (#1443)
Otherwise, all files are included
2021-03-21 17:57:55 +03:00
e8d563c1f0 Fix invalid radix in cli (#1446) 2021-03-21 17:32:38 +03:00
bc5c4ea29c Add a test for removeXMLNS plugin (#1444) 2021-03-21 17:30:36 +03:00
3390df1186 removeOffCanvasPaths: Add one more test (#1445) 2021-03-21 13:30:20 +03:00
de0572c799 Update devDependencies (#1442)
* @types/mocha   ^8.2.1  →   ^8.2.2
* chai           ^4.3.0  →   ^4.3.4
* eslint        ^7.20.0  →  ^7.22.0
* mocha          ^8.3.0  →   ^8.3.2
* playwright     ^1.8.1  →   ^1.9.2
* rollup        ^2.39.0  →  ^2.42.1
* typescript     ^4.2.2  →   ^4.2.3
2021-03-21 10:30:09 +03:00
f44612e7a2 addClassesToSVGElement: add one more test (#1441) 2021-03-21 10:26:57 +03:00
65c733a42a Use charAt instead of charCodeAt when possible (#1440) 2021-03-20 21:50:06 +03:00
21d24006fd Remove the executable flag from files. (#1439) 2021-03-20 20:46:26 +03:00
b903de9554 test/config/_index.js: fix find usage (#1438) 2021-03-20 19:51:33 +03:00
e4ce31a287 Add fix script 2021-03-19 15:29:24 +03:00
4cacd9e676 Migrate ast traversing into xast module (#1434)
Replaced JSAPI methods with new utilities

- querySelectorAll(node, selector)
- querySelector(node, selector)
- matches(node, selector)
- closestByName(node, elementName)
- traverse(node, fn)

New traverse replaced many in-place implementations.
2021-03-19 11:06:41 +03:00
6f2f62c5ee Access attributes directly (#1433)
Got rid from `.attrs`, `.attr()` and `.addAttr()` usages
2021-03-18 18:53:20 +03:00
07928fc77e Replace removeAttr with delete operator (#1432)
delete operator is more explicit and not much harder to use.
2021-03-17 21:40:06 +03:00
8098ab7fb6 Replace attributes iterators with for/of (#1431)
These iterators allows to directly manipulate passed value
which does not let us to get rid from legacy "attrs" field.

Object.entries makes it easier to get an access to both attribute
name and value.
2021-03-17 12:50:16 +03:00
45d2b68a32 Move attrs polyfill into jsapi 2021-03-16 20:39:58 +03:00
604a9c5cdb Merge pull request #1428 from svg/refactor_apply_transforms
Refactor apply transforms
2021-03-16 01:31:26 +03:00
c925e4da0a Fix ts 2021-03-15 21:34:36 +03:00
61657433e1 Refactor apply transforms
- handle each command separately
- handle both relative and absolute commands
- moved into _applyTransforms.js to convert eventually into plugin
- apply transforms before converting into relative

These changes makes code independent and easy to work with.
2021-03-15 21:24:23 +03:00
c6254eb45d Merge pull request #1427 from svg/refactor-convert-to-relative
Refactor convertToRelative
2021-03-15 16:07:34 +03:00
92053c7ed8 Remove broken optimisation 2021-03-15 15:07:28 +03:00
a04b27a1df Refactor convertToRelative
Slight code simplification. Each command is processed exclusively
without assumtions. Removed moveto and closepath common coords
reference, handle in applyTransform instead. Rely on new path data
naming.
2021-03-15 13:41:12 +03:00
d27961745a Merge pull request #1420 from svg/xast-children
Convert element children to xast
2021-03-11 13:28:47 +03:00