Skip to content

Commit

Permalink
feat(cleanupStyleAttributes): minify opacities in properties. (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 authored Nov 16, 2024
1 parent 810d78a commit 339f2e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/cleanupStyleAttributes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getStyleDeclarations } from '../lib/css-tools.js';
import { LengthOrPctValue } from '../lib/lengthOrPct.js';
import { OpacityValue } from '../lib/opacity.js';
import { writeStyleAttribute } from '../lib/svgo/tools.js';
import { visitSkip } from '../lib/xast.js';
import {
Expand Down Expand Up @@ -130,6 +131,14 @@ export const fn = (root, params, info) => {
newValue.value = minified;
}
break;
case 'fill-opacity':
case 'opacity':
case 'stop-opacity':
case 'stroke-opacity':
{
newValue.value = OpacityValue.getOpacityObj(v.value);
}
break;
}
newProperties.set(p, newValue);
}
Expand Down
21 changes: 21 additions & 0 deletions test/plugins/cleanupStyleAttributes.18.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Minify opacities.

===

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<rect width="20" height="6" style="fill:blue;fill-opacity:0.5"/>
<rect y="8" width="20" height="6" style="stroke:blue;stroke-opacity:0.2"/>
<g style="opacity:0.1">
<rect y="16" width="20" height="6"/>
</g>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
<rect width="20" height="6" style="fill:blue;fill-opacity:.5"/>
<rect y="8" width="20" height="6" style="stroke:blue;stroke-opacity:.2"/>
<g style="opacity:.1">
<rect y="16" width="20" height="6"/>
</g>
</svg>

0 comments on commit 339f2e3

Please sign in to comment.