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

Keep hidden elements if any descendant enables visibility

This commit is contained in:
Bogdan Chadkin
2021-02-25 00:05:26 +03:00
parent 9d67586787
commit d06747abca
2 changed files with 23 additions and 1 deletions

View File

@ -52,7 +52,9 @@ exports.fn = function (item, params) {
// https://www.w3schools.com/cssref/pr_class_visibility.asp
if (
params.isHidden &&
item.hasAttr('visibility', 'hidden')
item.hasAttr('visibility', 'hidden') &&
// keep if any descendant enables visibility
item.querySelector('[visibility=visible]') == null
) return false;
// display="none"

View File

@ -0,0 +1,20 @@
<svg width="480" height="360" xmlns="http://www.w3.org/2000/svg">
<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" />
</g>
<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>
</svg>
@@@
<svg width="480" height="360" xmlns="http://www.w3.org/2000/svg">
<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>
</svg>

After

Width:  |  Height:  |  Size: 740 B