Merge pull request #591 from SVG-Edit/issues/546

master
JFH 2021-07-07 08:38:15 +02:00 committed by GitHub
commit 103bf1495d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View File

@ -571,16 +571,19 @@ export const pushGroupProperty = function (g, undoable) {
// Clone the group's filter
gfilter = drawing.copyElem(gfilter);
findDefs().append(gfilter);
// const filterElem = getRefElem(gfilter);
const blurElem = getFeGaussianBlur(gfilter);
// Change this in future for different filters
const suffix = (blurElem?.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
gfilter.id = elem.id + '_' + suffix;
elementContext_.changeSelectedAttribute('filter', 'url(#' + gfilter.id + ')', [ elem ]);
}
} else {
gfilter = getRefElem(elem.getAttribute('filter'));
}
// const filterElem = getRefElem(gfilter);
const blurElem = getFeGaussianBlur(gfilter);
// Change this in future for different filters
const suffix = (blurElem?.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
gfilter.id = elem.id + '_' + suffix;
elementContext_.changeSelectedAttribute('filter', 'url(#' + gfilter.id + ')', [ elem ]);
// Update blur value
if (cblur) {

View File

@ -368,6 +368,28 @@ export const setSvgString = function (xmlString, preventUndo) {
svgCanvas.embedImage(val);
}
});
// Duplicate id replace changes
const nodes = content.querySelectorAll('[id]');
const ids = {};
const totalNodes = nodes.length;
for(let i=0; i<totalNodes; i++) {
const currentId = nodes[i].id ? nodes[i].id : "undefined";
if(isNaN(ids[currentId])) {
ids[currentId] = 0;
}
ids[currentId]++;
}
Object.entries(ids).forEach(([ key, value ]) => {
if (value > 1) {
const nodes = content.querySelectorAll('[id="'+key+'"]');
for(let i=1; i<nodes.length; i++) {
nodes[i].setAttribute('id', svgCanvas.getNextId());
}
}
});
// Wrap child SVGs in group elements
const svgElements = content.querySelectorAll('svg');