1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

plugins/removeNonInheritableGroupAttrs: new plugin to fix #101

This commit is contained in:
deepsweet
2013-02-22 17:07:41 +02:00
parent f50b4f8ca8
commit f47220cff6
5 changed files with 45 additions and 5 deletions

View File

@ -0,0 +1,31 @@
'use strict';
var inheritableAttrs = require('./_collections').inheritableAttrs,
presentationAttrs = require('./_collections').attrsGroups.presentation,
excludedAttrs = ['display', 'opacity'];
/**
* Remove non-inheritable group's "presentation" attributes.
*
* @param {Object} item current iteration item
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.removeNonInheritableGroupAttrs = function(item) {
if (item.isElem('g')) {
item.eachAttr(function(attr) {
if (
presentationAttrs.indexOf(attr.name) !== -1 &&
excludedAttrs.indexOf(attr.name) === -1 &&
inheritableAttrs.indexOf(attr.name) === -1
) {
item.removeAttr(attr.name);
}
});
}
};