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.
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.
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`.
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.
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.
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.
"full" plugins prevents from possible optimisation. We need to migrate
all plugins to "perItem" type and later implement visitor plugin api to
allow state.
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.
- 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.
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.