1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-28 09:22:00 +03:00

new plugin cleanupEnableBackground

This commit is contained in:
deepsweet
2012-09-29 17:36:19 +04:00
parent 5ac7d69342
commit f8faa1f2f7
2 changed files with 42 additions and 0 deletions

3
.svgo
View File

@ -54,6 +54,9 @@
},{
"name": "removeViewBox",
"active": true
},{
"name": "cleanupEnableBackground",
"active": true
},{
"name": "removeHiddenElems",
"active": true,

View File

@ -0,0 +1,39 @@
var regEnableBackground = /^new\s0\s0\s(\d+)\s(\d+)$/,
container = require('./_collections').elems.container;
/**
* Remove or cleanup enable-background attr which coincides with a width/height box.
*
* @see http://www.w3.org/TR/SVG/filters.html#EnableBackgroundProperty
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.cleanupEnableBackground = function(item, params) {
if (
item.isElem(container) &&
item.hasAttr('enable-background') &&
item.hasAttr('width') &&
item.hasAttr('height')
) {
if (match = item.attr('enable-background').value.match(regEnableBackground)) {
if (
item.attr('width').value == match[1] &&
item.attr('height').value == match[2]
) {
if (item.isElem('svg')) {
item.removeAttr('enable-background');
} else {
item.attr('enable-background').value = 'new';
}
}
}
}
};