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

plugins/moveElemsAttrsToGroup: merge split-level transforms instead of replacing (fix #10)

This commit is contained in:
deepsweet
2012-10-20 21:41:19 +03:00
parent b4141bdfef
commit 50b825d305
3 changed files with 26 additions and 1 deletions

View File

@ -29,6 +29,7 @@ exports.moveElemsAttrsToGroup = function(item, params) {
if (item.isElem('g') && !item.isEmpty() && item.content.length > 1) {
var intersection = {},
hasTransform = false,
every = item.content.every(function(g) {
if (g.elem && g.attrs) {
if (!Object.keys(intersection).length) {
@ -48,7 +49,15 @@ exports.moveElemsAttrsToGroup = function(item, params) {
item.content.forEach(function(g) {
for (var name in intersection) {
g.removeAttr(name);
item.addAttr(intersection[name]);
if (name === 'transform') {
if (!hasTransform) {
item.attr('transform').value += ' ' + intersection[name].value;
hasTransform = true;
}
} else {
item.addAttr(intersection[name]);
}
}
});
}