removeHiddenElems
Default
Remove hidden or invisible elements from the document. This can be elements with 0 width and height defined, or elements that were just hidden with CSS.
This plugin ignores non-rendering elements, such as <clipPath> and <linearGradient>, which still apply regardless of styles, unless they are unused.
Refer to the parameters for the conditions this plugin looks for. All checks enabled by default.
Usage
- Basic
- Parameters
svgo.config.js
module.exports = {
plugins: [
"removeHiddenElems"
]
}
svgo.config.js
module.exports = {
plugins: [
{
name: "removeHiddenElems",
params: {
isHidden: true,
displayNone: true,
opacity0: true,
circleR0: true,
ellipseRX0: true,
ellipseRY0: true,
rectWidth0: true,
rectHeight0: true,
patternWidth0: true,
patternHeight0: true,
imageWidth0: true,
imageHeight0: true,
pathEmptyD: true,
polylineEmptyPoints: true,
polygonEmptyPoints: true
}
}
]
}
Parameters
isHiddenRemoves elements where
visibilityishidden, unless a child element hasvisibilityset tovisible.displayNoneRemoves elements where
displayisnone.opacity0Removes element where
opacityis0.circleR0ellipseRX0ellipseRY0rectWidth0rectHeight0Removes
heightis0.patternWidth0Removes
widthis0.patternHeight0Removes
heightis0.imageWidth0Removes
widthis0.imageHeight0Removes
heightis0.pathEmptyDRemove
marker.polylineEmptyPointsRemoves points defined.
polygonEmptyPointsRemoves points defined.
Demo
Live Editor
const svg = ` <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0 150 100 " width="150"> <!-- Created with love! --> <defs> <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/> </defs> <g> <use href="#circle" transform="skewX(16)"/> <rect id="useless" width="0" height="0" fill="#ff0000"/> </g> </svg> `; const svgoConfig = { js2svg: { indent: 2, pretty: true }, plugins: [ "removeHiddenElems" ] } render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...