Skip to content

Commit 25bb588

Browse files
committed
Prune unneeded save/restore groups
1 parent 045413b commit 25bb588

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

canvas2svg.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@
472472
}
473473
}
474474

475-
return serialized;
475+
return serialized;
476476
};
477477

478478

@@ -504,6 +504,13 @@
504504
ctx.prototype.restore = function () {
505505
var element = this.__groupStack.pop();
506506
var state = this.__stack.pop();
507+
508+
/** Prune empty group created when running save/restore without any content **/
509+
var node = this.__currentElement
510+
if (node.nodeName === 'g' && !node.childNodes.length) {
511+
node.remove()
512+
}
513+
507514
this.__currentElementsToStyle = null;
508515
this.__currentElement = element || this.__root.childNodes[1];
509516
this.__applyStyleState(state);
@@ -1163,15 +1170,18 @@
11631170
* Generates a ClipPath from the clip command.
11641171
*/
11651172
ctx.prototype.clip = function () {
1173+
console.log(this.__currentPath)
1174+
if (!this.__currentPath) {
1175+
return;
1176+
}
1177+
11661178
applyCurrentDefaultPath.call(this, false);
11671179

11681180
var group = this.__closestGroupOrSvg(),
11691181
clipPath = this.__createElement("clipPath"),
11701182
id = randomString(this.__ids),
11711183
newGroup = this.__createElement("g");
11721184

1173-
this.__currentElement.remove();
1174-
11751185
clipPath.setAttribute("id", id);
11761186
clipPath.appendChild(this.__currentElement);
11771187

0 commit comments

Comments
 (0)