mirror of
https://github.com/shadoll/sLogos.git
synced 2026-02-04 11:03:24 +00:00
feat: enhance SVG color application by removing existing fill attributes before adding new ones
This commit is contained in:
@@ -67,11 +67,13 @@ function applySvgColors(svgContent, colorSet, targets) {
|
|||||||
if (selector.startsWith('#')) {
|
if (selector.startsWith('#')) {
|
||||||
// ID selector - replace fill/stroke for specific element
|
// ID selector - replace fill/stroke for specific element
|
||||||
const elementId = selector.substring(1);
|
const elementId = selector.substring(1);
|
||||||
const idRegex = new RegExp(`(id="${elementId}"[^>]*?)fill="[^"]*"`, 'g');
|
|
||||||
modifiedSvg = modifiedSvg.replace(idRegex, `$1fill="${color}"`);
|
|
||||||
|
|
||||||
// If no fill attribute, add it
|
// First, remove any existing fill attributes for this element
|
||||||
const addFillRegex = new RegExp(`(id="${elementId}"[^>]*?)(?!.*fill=)([^>]*>)`, 'g');
|
const removeExistingFillRegex = new RegExp(`(id="${elementId}"[^>]*?)\\s*fill="[^"]*"`, 'g');
|
||||||
|
modifiedSvg = modifiedSvg.replace(removeExistingFillRegex, '$1');
|
||||||
|
|
||||||
|
// Then add the new fill attribute
|
||||||
|
const addFillRegex = new RegExp(`(id="${elementId}"[^>]*?)(\s*>)`, 'g');
|
||||||
modifiedSvg = modifiedSvg.replace(addFillRegex, `$1 fill="${color}"$2`);
|
modifiedSvg = modifiedSvg.replace(addFillRegex, `$1 fill="${color}"$2`);
|
||||||
} else {
|
} else {
|
||||||
// Default: replace all fill attributes (fallback)
|
// Default: replace all fill attributes (fallback)
|
||||||
|
|||||||
Reference in New Issue
Block a user