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

move or just leave transform attr from Group to the inner Path Elems (close #86)

This commit is contained in:
deepsweet
2013-01-18 14:16:27 +02:00
parent 79f62fd334
commit 30a3397a27
11 changed files with 120 additions and 18 deletions

View File

@ -0,0 +1,46 @@
'use strict';
var pathElems = require('./_collections.js').pathElems;
/**
* Move group attrs to the content elements.
*
* @example
* <g transform="scale(2)">
* <path transform="rotate(45)" d="M0,0 L10,20"/>
* <path transform="translate(10, 20)" d="M0,10 L20,30"/>
* </g>
* ⬇
* <g>
* <path transform="scale(2) rotate(45)" d="M0,0 L10,20"/>
* <path transform="scale(2) translate(10, 20)" d="M0,10 L20,30"/>
* </g>
*
* @param {Object} item current iteration item
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.moveGroupAttrsToElems = function(item) {
// move group transform attr to content's pathElems
if (
item.isElem('g') &&
item.hasAttr('transform') &&
!item.isEmpty() &&
item.content.every(function(inner) {
return inner.isElem(pathElems);
})
) {
item.content.forEach(function(inner) {
if (inner.hasAttr('transform')) {
inner.attr('transform').value = item.attr('transform').value + ' ' + inner.attr('transform').value;
} else {
inner.addAttr(item.attr('transform'));
}
});
item.removeAttr('transform');
}
};