fix: recreate root <g> when __clearCanvas to remove all attributes

This commit is contained in:
Zeno Zeng 2021-06-06 01:30:40 +08:00
parent bcdc8df943
commit 3d96ae9391

View File

@ -473,6 +473,7 @@ module.exports = (function () {
ctx.prototype.getSvg = function () { ctx.prototype.getSvg = function () {
return this.__root; return this.__root;
}; };
/** /**
* Will generate a group tag. * Will generate a group tag.
*/ */
@ -484,6 +485,7 @@ module.exports = (function () {
this.__currentElement = group; this.__currentElement = group;
this.__stack.push(this.__getStyleState()); this.__stack.push(this.__getStyleState());
}; };
/** /**
* Sets current element to parent, or just root if already root * Sets current element to parent, or just root if already root
*/ */
@ -805,13 +807,9 @@ module.exports = (function () {
*/ */
ctx.prototype.__clearCanvas = function () { ctx.prototype.__clearCanvas = function () {
var rootGroup = this.__root.childNodes[1]; var rootGroup = this.__root.childNodes[1];
var childNodes = rootGroup.childNodes; this.__root.removeChild(rootGroup);
for (var i = childNodes.length - 1; i >= 0; i--) { this.__currentElement = this.__document.createElementNS("http://www.w3.org/2000/svg", "g");
if (childNodes[i]) { this.__root.appendChild(this.__currentElement);
rootGroup.removeChild(childNodes[i]);
}
}
this.__currentElement = rootGroup;
//reset __groupStack as all the child group nodes are all removed. //reset __groupStack as all the child group nodes are all removed.
this.__groupStack = []; this.__groupStack = [];
}; };