mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Implement style computing (#1399)
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.
This commit is contained in:
@ -1,11 +1,20 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.a { display: block; }
|
||||
</style>
|
||||
<g>
|
||||
<path display="none" d="..."/>
|
||||
<rect display="none" x="0" y="0" width="20" height="20" />
|
||||
<rect display="none" class="a" x="0" y="0" width="20" height="20" />
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
@@@
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<g/>
|
||||
<style>
|
||||
.a { display: block; }
|
||||
</style>
|
||||
<g>
|
||||
<rect display="none" class="a" x="0" y="0" width="20" height="20"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 466 B |
@ -1,11 +1,20 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.a { opacity: 0.5; }
|
||||
</style>
|
||||
<g>
|
||||
<path opacity="0" d="..."/>
|
||||
<rect opacity="0" x="0" y="0" width="20" height="20" />
|
||||
<rect opacity="0" class="a" x="0" y="0" width="20" height="20" />
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
@@@
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<g/>
|
||||
<style>
|
||||
.a { opacity: 0.5; }
|
||||
</style>
|
||||
<g>
|
||||
<rect opacity="0" class="a" x="0" y="0" width="20" height="20"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 164 B After Width: | Height: | Size: 453 B |
@ -1,4 +1,12 @@
|
||||
Keep invisible elements which have visibile ones inside
|
||||
and resolve styles
|
||||
|
||||
===
|
||||
|
||||
<svg width="480" height="360" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.a { visibility: visible; }
|
||||
</style>
|
||||
<rect x="96" y="96" width="96" height="96" fill="lime" />
|
||||
<g visibility="hidden">
|
||||
<rect x="96" y="96" width="96" height="96" fill="red" />
|
||||
@ -7,14 +15,19 @@
|
||||
<g visibility="hidden">
|
||||
<rect x="196" y="196" width="96" height="96" fill="lime" visibility="visible" />
|
||||
</g>
|
||||
<rect x="96" y="96" width="96" height="96" visibility="hidden" class="a" />
|
||||
</svg>
|
||||
|
||||
@@@
|
||||
|
||||
<svg width="480" height="360" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.a { visibility: visible; }
|
||||
</style>
|
||||
<rect x="96" y="96" width="96" height="96" fill="lime"/>
|
||||
<rect x="196.5" y="196.5" width="95" height="95" fill="red"/>
|
||||
<g visibility="hidden">
|
||||
<rect x="196" y="196" width="96" height="96" fill="lime" visibility="visible"/>
|
||||
</g>
|
||||
<rect x="96" y="96" width="96" height="96" visibility="hidden" class="a"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 740 B After Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user