🚀 Add new /templates utility + add support for web components

This commit is contained in:
pheralb
2025-02-26 16:59:52 +00:00
parent 63d2416274
commit dc22285088
14 changed files with 290 additions and 91 deletions
-21
View File
@@ -1,21 +0,0 @@
import { parseSvgContent } from './parseSvgContent';
export const componentTemplate = (lang: string, content: string, framework: 'Vue' | 'Svelte') => {
const { templateContent, componentStyle } = parseSvgContent(content, framework);
if (framework === 'Vue') {
return `<script setup${lang ? ` lang="${lang}"` : ''}></script>
<template>
${templateContent}
</template>
${componentStyle}
`;
} else {
return `<script${lang ? ` lang="${lang}"` : ''}></script>
${templateContent}
${componentStyle}
`;
}
};
-28
View File
@@ -1,28 +0,0 @@
export function generateAngularComponent(svgContent: string, componentName: string): string {
const updatedSvgContent = svgContent.replace(
/<svg([^>]*)>/,
`<svg$1 [attr.width]="size.width" [attr.height]="size.height">`
);
return `
/**
* -------------------------------------------------------------------------
* This Angular standalone component was generated by svgl.app
* 🧩 A beautiful library with SVG logos
* -------------------------------------------------------------------------
*/
import { Component, Input } from '@angular/core';
@Component({
selector: 'svg-${componentName}',
standalone: true,
template: \`
${updatedSvgContent.trim()}
\`,
})
export class ${componentName}Component {
@Input({ required: true }) size: { width: number; height: number };
}
`;
}
-23
View File
@@ -1,23 +0,0 @@
interface iComponentCode {
code: string;
name: string;
typescript: boolean;
}
export const getReactComponentCode = async (
params: iComponentCode
): Promise<{ data?: string; error?: string }> => {
try {
const getCode = await fetch('/api/svgs/svgr', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
});
const data = await getCode.json();
return data;
} catch (error) {
return { error: 'An error has ocurred. Try again.' };
}
};
-5
View File
@@ -1,5 +0,0 @@
export const getSvgContent = async (url: string | undefined) => {
const response = await fetch(url || '');
const content = await response.text();
return content;
};