Skip to content

Commit 3e9ad5e

Browse files
authored
fix: collapseGroups does not move attributes atomically (#1930)
1 parent 6747e3a commit 3e9ad5e

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

plugins/collapseGroups.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { inheritableAttrs, elemsGroups } from './_collections.js';
22

33
/**
4+
* @typedef {import('../lib/types.js').XastElement} XastElement
45
* @typedef {import('../lib/types.js').XastNode} XastNode
56
*/
67

@@ -80,26 +81,30 @@ export const fn = () => {
8081
node.attributes.transform == null &&
8182
firstChild.attributes.transform == null))
8283
) {
84+
const newChildElemAttrs = { ...firstChild.attributes };
85+
8386
for (const [name, value] of Object.entries(node.attributes)) {
8487
// avoid copying to not conflict with animated attribute
8588
if (hasAnimatedAttr(firstChild, name)) {
8689
return;
8790
}
88-
if (firstChild.attributes[name] == null) {
89-
firstChild.attributes[name] = value;
91+
92+
if (newChildElemAttrs[name] == null) {
93+
newChildElemAttrs[name] = value;
9094
} else if (name === 'transform') {
91-
firstChild.attributes[name] =
92-
value + ' ' + firstChild.attributes[name];
93-
} else if (firstChild.attributes[name] === 'inherit') {
94-
firstChild.attributes[name] = value;
95+
newChildElemAttrs[name] = value + ' ' + newChildElemAttrs[name];
96+
} else if (newChildElemAttrs[name] === 'inherit') {
97+
newChildElemAttrs[name] = value;
9598
} else if (
96-
inheritableAttrs.has(name) === false &&
97-
firstChild.attributes[name] !== value
99+
!inheritableAttrs.has(name) &&
100+
newChildElemAttrs[name] !== value
98101
) {
99102
return;
100103
}
101-
delete node.attributes[name];
102104
}
105+
106+
node.attributes = {};
107+
firstChild.attributes = newChildElemAttrs;
103108
}
104109
}
105110

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Don't collapse group with a single child unless all attributes can be moved to the child.
2+
See issue #1928 for context.
3+
4+
===
5+
6+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88">
7+
<filter id="a">
8+
<feGaussianBlur stdDeviation="1"/>
9+
</filter>
10+
<g transform="matrix(0.6875,0,0,0.6875,20.34375,66.34375)" style="filter:url(#a)">
11+
<path d="M 33.346591,-83.471591 L -10.744318,-36.471591 L -10.49989,-32.5" style="fill-opacity:1"/>
12+
</g>
13+
</svg>
14+
15+
@@@
16+
17+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88">
18+
<filter id="a">
19+
<feGaussianBlur stdDeviation="1"/>
20+
</filter>
21+
<g transform="matrix(0.6875,0,0,0.6875,20.34375,66.34375)" style="filter:url(#a)">
22+
<path d="M 33.346591,-83.471591 L -10.744318,-36.471591 L -10.49989,-32.5" style="fill-opacity:1"/>
23+
</g>
24+
</svg>

0 commit comments

Comments
 (0)