diff --git a/docs/03-plugins/remove-hidden-elems.mdx b/docs/03-plugins/remove-hidden-elems.mdx
index 0dbb58694..52e10934c 100644
--- a/docs/03-plugins/remove-hidden-elems.mdx
+++ b/docs/03-plugins/remove-hidden-elems.mdx
@@ -10,6 +10,9 @@ svgo:
displayNone:
description: Removes elements where display
is none
.
default: true
+ noColor:
+ description: Removes shapes that aren't rendered in any way (no fill/stroke/markers).
+ default: true
opacity0:
description: Removes element where opacity
is 0
.
default: true
diff --git a/plugins/plugins-types.d.ts b/plugins/plugins-types.d.ts
index 1d4740e7b..5a0ea4dd8 100644
--- a/plugins/plugins-types.d.ts
+++ b/plugins/plugins-types.d.ts
@@ -159,6 +159,7 @@ type DefaultPlugins = {
removeHiddenElems: {
isHidden?: boolean;
displayNone?: boolean;
+ noColor?: boolean;
opacity0?: boolean;
circleR0?: boolean;
ellipseRX0?: boolean;
diff --git a/plugins/removeHiddenElems.js b/plugins/removeHiddenElems.js
index 75720a068..db46bf07e 100644
--- a/plugins/removeHiddenElems.js
+++ b/plugins/removeHiddenElems.js
@@ -27,6 +27,7 @@ exports.description =
* Remove hidden elements with disabled rendering:
* - display="none"
* - opacity="0"
+ * - shapes with no fill/stroke/markers
* - circle with zero radius
* - ellipse with zero x-axis or y-axis radius
* - rectangle with zero width or height
@@ -44,6 +45,7 @@ exports.fn = (root, params) => {
const {
isHidden = true,
displayNone = true,
+ noColor = true,
opacity0 = true,
circleR0 = true,
ellipseRX0 = true,
@@ -201,6 +203,27 @@ exports.fn = (root, params) => {
return;
}
+ // Shapes that aren't rendered in any way
+ if (
+ noColor &&
+ elemsGroups.shape.has(node.name) &&
+ computedStyle.fill &&
+ computedStyle.fill.type === 'static' &&
+ computedStyle.fill.value === 'none' &&
+ (computedStyle.stroke
+ ? computedStyle.stroke.type === 'static' &&
+ computedStyle.stroke.value === 'none'
+ : true) &&
+ !computedStyle['marker-start'] &&
+ !computedStyle['marker-mid'] &&
+ !computedStyle['marker-end'] &&
+ (parentNode.type !== 'element' ||
+ (parentNode.name !== 'defs' && parentNode.name !== 'clipPath'))
+ ) {
+ removeElement(node, parentNode);
+ return;
+ }
+
// Circles with zero radius
//
// https://www.w3.org/TR/SVG11/shapes.html#CircleElementRAttribute
diff --git a/test/plugins/removeHiddenElems.16.svg b/test/plugins/removeHiddenElems.16.svg
new file mode 100644
index 000000000..8b6a78bcf
--- /dev/null
+++ b/test/plugins/removeHiddenElems.16.svg
@@ -0,0 +1,11 @@
+Removes shape with no fill or stroke
+
+===
+
+
+
+@@@
+
+