mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
plugins/removeNonInheritableGroupAttrs: new plugin to fix #101
This commit is contained in:
@ -61,6 +61,10 @@ plugins:
|
|||||||
unknownAttrs: true
|
unknownAttrs: true
|
||||||
defaultAttrs: true
|
defaultAttrs: true
|
||||||
|
|
||||||
|
- name: removeNonInheritableGroupAttrs
|
||||||
|
active: true
|
||||||
|
type: perItem
|
||||||
|
|
||||||
- name: removeUselessStrokeAndFill
|
- name: removeUselessStrokeAndFill
|
||||||
active: true
|
active: true
|
||||||
type: perItem
|
type: perItem
|
||||||
|
@ -15,11 +15,6 @@ exports.elemsGroups = {
|
|||||||
|
|
||||||
exports.pathElems = ['path', 'glyph', 'missing-glyph'];
|
exports.pathElems = ['path', 'glyph', 'missing-glyph'];
|
||||||
|
|
||||||
// var defaults = exports.defaults = {
|
|
||||||
// 'externalResourcesRequired': 'false',
|
|
||||||
// 'xlink:type': 'simple'
|
|
||||||
// };
|
|
||||||
|
|
||||||
// http://www.w3.org/TR/SVG/intro.html#Definitions
|
// http://www.w3.org/TR/SVG/intro.html#Definitions
|
||||||
exports.attrsGroups = {
|
exports.attrsGroups = {
|
||||||
animationAddition: ['additive', 'accumulate'],
|
animationAddition: ['additive', 'accumulate'],
|
||||||
|
31
plugins/removeNonInheritableGroupAttrs.js
Normal file
31
plugins/removeNonInheritableGroupAttrs.js
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
5
test/plugins/removeNonInheritableGroupAttrs.01.orig.svg
Normal file
5
test/plugins/removeNonInheritableGroupAttrs.01.orig.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g class="test" clip-path="url(#clip1)" transform="rotate(45)" display="none" opacity="0.5" visibility="visible">
|
||||||
|
<path d="M0 0 L 10 20"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 208 B |
@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g class="test" transform="rotate(45)" display="none" opacity="0.5" visibility="visible">
|
||||||
|
<path d="M0 0 L 10 20"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 184 B |
Reference in New Issue
Block a user