mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
✨ Add support for Astro component
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
interface AstroComponentParams {
|
||||
svgContent: string;
|
||||
}
|
||||
|
||||
export function getAstroCode({ svgContent }: AstroComponentParams): string {
|
||||
const cleanedSvg = svgContent
|
||||
.replace(/\s*(width|height)="[^"]*"/gi, '')
|
||||
.replace(/\s*(width|height)='[^']*'/gi, '')
|
||||
.replace(/\s*(width|height)=\{[^}]*\}/gi, '')
|
||||
.replace(/<svg([^>]*)>/i, (match, attrs) => {
|
||||
const cleanedAttrs = attrs.replace(/\s*\{?\.\.\.Astro\.props\}?\s*/i, '');
|
||||
return `<svg ${cleanedAttrs} {...Astro.props}>`;
|
||||
});
|
||||
|
||||
return cleanedSvg.trim();
|
||||
}
|
||||
Reference in New Issue
Block a user