mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🚀 Add new /templates utility + add support for web components
This commit is contained in:
@@ -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}
|
||||
`;
|
||||
}
|
||||
};
|
||||
@@ -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 };
|
||||
}
|
||||
`;
|
||||
}
|
||||
@@ -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.' };
|
||||
}
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
export const getSvgContent = async (url: string | undefined) => {
|
||||
const response = await fetch(url || '');
|
||||
const content = await response.text();
|
||||
return content;
|
||||
};
|
||||
Reference in New Issue
Block a user