#87 svg button issue fixed (#89)

This commit is contained in:
Agriya Dev5
2021-04-19 23:32:01 +05:30
committed by GitHub
parent 600ae92db5
commit 8daae6dcdd

View File

@@ -159,7 +159,8 @@ export const svgToString = function (elem, indent) {
const nsuris = {}; const nsuris = {};
// Check elements for namespaces, add if found // Check elements for namespaces, add if found
const cElements = elem.querySelectorAll('*'); const csElements = elem.querySelectorAll('*');
const cElements = Array.prototype.slice.call(csElements);
cElements.push(elem); cElements.push(elem);
Array.prototype.forEach.call(cElements, function(el, i){ Array.prototype.forEach.call(cElements, function(el, i){
// const el = this; // const el = this;
@@ -169,13 +170,15 @@ export const svgToString = function (elem, indent) {
nsuris[uri] = true; nsuris[uri] = true;
out.push(' xmlns:' + nsMap[uri] + '="' + uri + '"'); out.push(' xmlns:' + nsMap[uri] + '="' + uri + '"');
} }
el.attributes.forEach(function(attr, i){ if(el.attributes.length > 0) {
const u = attr.namespaceURI; for (const [i, attr] of Object.entries(el.attributes)) {
if (u && !nsuris[u] && nsMap[u] !== 'xmlns' && nsMap[u] !== 'xml') { const u = attr.namespaceURI;
nsuris[u] = true; if (u && !nsuris[u] && nsMap[u] !== 'xmlns' && nsMap[u] !== 'xml') {
out.push(' xmlns:' + nsMap[u] + '="' + u + '"'); nsuris[u] = true;
out.push(' xmlns:' + nsMap[u] + '="' + u + '"');
}
} }
}); }
}); });
let i = attrs.length; let i = attrs.length;
@@ -1023,18 +1026,20 @@ export const removeUnusedDefElemsMethod = function () {
} }
} }
const defelems = defs.querySelectorAll('linearGradient, radialGradient, filter, marker, svg, symbol'); Array.prototype.forEach.call(defs, function(def, i){
i = defelems.length; const defelems = def.querySelectorAll('linearGradient, radialGradient, filter, marker, svg, symbol');
while (i--) { i = defelems.length;
const defelem = defelems[i]; while (i--) {
const {id} = defelem; const defelem = defelems[i];
if (!defelemUses.includes(id)) { const {id} = defelem;
// Not found, so remove (but remember) if (!defelemUses.includes(id)) {
svgContext_.setRemovedElements(id, defelem); // Not found, so remove (but remember)
defelem.remove(); svgContext_.setRemovedElements(id, defelem);
numRemoved++; defelem.remove();
numRemoved++;
}
} }
} });
return numRemoved; return numRemoved;
}; };