SVGs can have the same presentation attribute declared redundantly in
both the node attributes and `<style>` tag.
This wouldn't break anything, but we can shave off a few more bytes by
dropping the attribute in this case.
When running this plugin on an SVG with an empty block in the CSS, it
would apply it to the matched elements by adding an empty `style`
attribute. See the test for an example.
This resolves that by just dropping the declaration if it's empty.
node.parentNode will be removed in v3 along with JSAPI class wrapper on
each node.
Style manager uses it to find inherited styles. To workaround this
I collected all parents along with all styles. This constraints style
manager to work only with initial ast which should not be a problem as
each plagin execution is isolated.
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.
There is a lot of attributes manipulation which is hard to remove at
once. In this diff I added `attributes` object and wrapped it as proxy
for `attrs` field.
Ref https://github.com/syntax-tree/xast
- added type: root | element
- renamed elem to name
- replaced "elem" property checks with check for correct type
Ref https://github.com/svg/svgo/issues/777
Currently a lot of optimisations are attributes specific and may be
broken because of inline or shared styles.
In this diff I'm trying to solve the problem with getComputedStyle
analog.
`computeStyle` collects attributes, shared css rules, inline styles
and inherited styles and checks whether they can be statically optimised
or left as deoptimisation.