Skip to content

Commit

Permalink
feat(removeUnknownsAndDefaults): remove rx/ry = 0 from <rect>
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Nov 17, 2024
1 parent 8577c92 commit be6a694
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/removeUnknownsAndDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ export const fn = (root, params, info) => {
continue;
}

// Remove rx/ry = 0 from <rect>.
if (element.name === 'rect') {
switch (name) {
case 'rx':
case 'ry':
if (value.toString() === '0') {
const otherValue =
element.attributes[name === 'rx' ? 'ry' : 'rx'];
if (
otherValue === undefined ||
otherValue.toString() === '0'
) {
delete element.attributes[name];
continue;
}
}
}
}

// Only remove it if it is either
// (a) inheritable, and either
// -- a default value, and is not overriding the parent value, or
Expand Down
21 changes: 21 additions & 0 deletions test/plugins/removeUnknownsAndDefaults.33.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Remove rx/ry="0".

===

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<rect width="5" height="5" style="fill:blue" rx="0"/>
<rect y="6" width="5" height="5" style="fill:blue" rx="0" ry="0"/>
<rect y="12" width="5" height="5" style="fill:blue" rx="1" ry="0"/>
<rect y="18" width="5" height="5" style="fill:blue" ry="0"/>
<rect y="24" width="5" height="5" style="fill:blue" ry="1"/>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<rect width="5" height="5" style="fill:blue"/>
<rect y="6" width="5" height="5" style="fill:blue"/>
<rect y="12" width="5" height="5" style="fill:blue" rx="1" ry="0"/>
<rect y="18" width="5" height="5" style="fill:blue"/>
<rect y="24" width="5" height="5" style="fill:blue" ry="1"/>
</svg>

0 comments on commit be6a694

Please sign in to comment.