mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
✨ Initial commit with Sveltekit + format files
This commit is contained in:
@@ -6,7 +6,7 @@ interface AngularComponentParams {
|
||||
export function getAngularCode(params: AngularComponentParams): string {
|
||||
const updatedSvgContent = params.svgContent.replace(
|
||||
/<svg([^>]*)>/,
|
||||
`<svg$1 [attr.width]="size.width" [attr.height]="size.height">`
|
||||
`<svg$1 [attr.width]="size.width" [attr.height]="size.height">`,
|
||||
);
|
||||
|
||||
return `
|
||||
|
||||
@@ -4,11 +4,11 @@ interface AstroComponentParams {
|
||||
|
||||
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(/\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, '');
|
||||
const cleanedAttrs = attrs.replace(/\s*\{?\.\.\.Astro\.props\}?\s*/i, "");
|
||||
return `<svg ${cleanedAttrs} {...Astro.props}>`;
|
||||
});
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ interface ReactComponentParams {
|
||||
}
|
||||
|
||||
export const getReactCode = async (
|
||||
params: ReactComponentParams
|
||||
params: ReactComponentParams,
|
||||
): Promise<{ data?: string; error?: string }> => {
|
||||
try {
|
||||
const getCode = await fetch('/api/svgs/svgr', {
|
||||
method: 'POST',
|
||||
const getCode = await fetch("/api/svgs/svgr", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(params)
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
const data = await getCode.json();
|
||||
return data;
|
||||
|
||||
@@ -3,7 +3,7 @@ interface SourceParams {
|
||||
}
|
||||
|
||||
export const getSource = async (params: SourceParams) => {
|
||||
const response = await fetch(params.url || '');
|
||||
const response = await fetch(params.url || "");
|
||||
const content = await response.text();
|
||||
return content;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { parseSvgContent } from '@/utils/parseSvgContent';
|
||||
import { parseSvgContent } from "@/utils/parseSvgContent";
|
||||
|
||||
interface SvelteComponentParams {
|
||||
lang: string;
|
||||
@@ -6,8 +6,11 @@ interface SvelteComponentParams {
|
||||
}
|
||||
|
||||
export const getSvelteCode = (params: SvelteComponentParams) => {
|
||||
const { templateContent, componentStyle } = parseSvgContent(params.content, 'Svelte');
|
||||
return `<script${params.lang ? ` lang="${params.lang}"` : ''}></script>
|
||||
const { templateContent, componentStyle } = parseSvgContent(
|
||||
params.content,
|
||||
"Svelte",
|
||||
);
|
||||
return `<script${params.lang ? ` lang="${params.lang}"` : ""}></script>
|
||||
${templateContent}
|
||||
|
||||
${componentStyle}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { parseSvgContent } from '@/utils/parseSvgContent';
|
||||
import { parseSvgContent } from "@/utils/parseSvgContent";
|
||||
|
||||
interface VueComponentParams {
|
||||
lang: string;
|
||||
@@ -6,8 +6,11 @@ interface VueComponentParams {
|
||||
}
|
||||
|
||||
export const getVueCode = (params: VueComponentParams) => {
|
||||
const { templateContent, componentStyle } = parseSvgContent(params.content, 'Vue');
|
||||
return `<script setup${params.lang ? ` lang="${params.lang}"` : ''}></script>
|
||||
const { templateContent, componentStyle } = parseSvgContent(
|
||||
params.content,
|
||||
"Vue",
|
||||
);
|
||||
return `<script setup${params.lang ? ` lang="${params.lang}"` : ""}></script>
|
||||
<template>
|
||||
${templateContent}
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user