mirror of
https://github.com/svg/svgo.git
synced 2025-08-09 02:22:08 +03:00
plugins/moveElemsAttrsToGroup: merge split-level transforms instead of replacing (fix #10)
This commit is contained in:
@@ -29,6 +29,7 @@ exports.moveElemsAttrsToGroup = function(item, params) {
|
|||||||
if (item.isElem('g') && !item.isEmpty() && item.content.length > 1) {
|
if (item.isElem('g') && !item.isEmpty() && item.content.length > 1) {
|
||||||
|
|
||||||
var intersection = {},
|
var intersection = {},
|
||||||
|
hasTransform = false,
|
||||||
every = item.content.every(function(g) {
|
every = item.content.every(function(g) {
|
||||||
if (g.elem && g.attrs) {
|
if (g.elem && g.attrs) {
|
||||||
if (!Object.keys(intersection).length) {
|
if (!Object.keys(intersection).length) {
|
||||||
@@ -48,8 +49,16 @@ exports.moveElemsAttrsToGroup = function(item, params) {
|
|||||||
item.content.forEach(function(g) {
|
item.content.forEach(function(g) {
|
||||||
for (var name in intersection) {
|
for (var name in intersection) {
|
||||||
g.removeAttr(name);
|
g.removeAttr(name);
|
||||||
|
|
||||||
|
if (name === 'transform') {
|
||||||
|
if (!hasTransform) {
|
||||||
|
item.attr('transform').value += ' ' + intersection[name].value;
|
||||||
|
hasTransform = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
item.addAttr(intersection[name]);
|
item.addAttr(intersection[name]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
test/plugins/moveElemsAttrsToGroup.04.orig.svg
Normal file
8
test/plugins/moveElemsAttrsToGroup.04.orig.svg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g transform="rotate(45)">
|
||||||
|
<g transform="scale(2)" attr="val">
|
||||||
|
<path d="..."/>
|
||||||
|
</g>
|
||||||
|
<circle attr="val" transform="scale(2)"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 223 B |
8
test/plugins/moveElemsAttrsToGroup.04.should.svg
Normal file
8
test/plugins/moveElemsAttrsToGroup.04.should.svg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g transform="rotate(45) scale(2)" attr="val">
|
||||||
|
<g>
|
||||||
|
<path d="..."/>
|
||||||
|
</g>
|
||||||
|
<circle/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 179 B |
Reference in New Issue
Block a user