@svgflex/core 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svg-sanitizer.d.ts","sourceRoot":"","sources":["../../src/utils/svg-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"svg-sanitizer.d.ts","sourceRoot":"","sources":["../../src/utils/svg-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA+BxE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,GAAE,OAAe,GAAG,MAAM,CAqBtF"}
|
package/utils/svg-sanitizer.js
CHANGED
|
@@ -13,6 +13,15 @@ export function replaceColorsWithCurrentColor(svgContent) {
|
|
|
13
13
|
// Replace stroke attributes with hex colors, rgb, rgba, named colors, etc.
|
|
14
14
|
// But preserve stroke="none", stroke="transparent", stroke="currentColor", and stroke="url(...)"
|
|
15
15
|
result = result.replace(/stroke\s*=\s*["'](?!none["']|transparent["']|currentColor["']|url\()[^"']*["']/gi, 'stroke="currentColor"');
|
|
16
|
+
// Add fill="none" to path elements that have stroke but no fill attribute
|
|
17
|
+
// This prevents unwanted default fills on stroke-only paths
|
|
18
|
+
result = result.replace(/<path\s+([^>]*?\bstroke\s*=\s*["'][^"']*["'][^>]*?)(?!\s*fill\s*=)(\s*\/?>)/gi, (match, attributes, closing) => {
|
|
19
|
+
// Check if 'fill' attribute already exists anywhere in the attributes
|
|
20
|
+
if (!/\bfill\s*=/i.test(attributes)) {
|
|
21
|
+
return `<path ${attributes} fill="none"${closing}`;
|
|
22
|
+
}
|
|
23
|
+
return match;
|
|
24
|
+
});
|
|
16
25
|
return result;
|
|
17
26
|
}
|
|
18
27
|
/**
|