Skip to content

Commit

Permalink
fix: removeHiddenElems - treat <path> with opacity:0 as non-rendering…
Browse files Browse the repository at this point in the history
… node. (#1948)
  • Loading branch information
johnkenny54 committed Jan 29, 2024
1 parent 10e5e5e commit f7436c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/removeHiddenElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export const fn = (root, params) => {
computedStyle.opacity.type === 'static' &&
computedStyle.opacity.value === '0'
) {
if (node.name === 'path') {
nonRenderedNodes.set(node, parentNode);
return visitSkip;
}
removeElement(node, parentNode);
}
},
Expand Down
28 changes: 28 additions & 0 deletions test/plugins/removeHiddenElems.19.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Preserve referenced path, even when path has opacity=0.

===

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="path2" d="M200 200 l50 -300" style="opacity:0"/>
</defs>
<text style="font-size:24px;">
<textPath xlink:href="#path2">
this is path 2
</textPath>
</text>
<path id="path1" d="M200 200 l50 -300" style="opacity:0"/>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="path2" d="M200 200 l50 -300" style="opacity:0"/>
</defs>
<text style="font-size:24px;">
<textPath xlink:href="#path2">
this is path 2
</textPath>
</text>
</svg>

0 comments on commit f7436c7

Please sign in to comment.