feat(new tool): SVG Preview

This commit is contained in:
ShareVB committed 2025-12-14 20:37:36 +01:00
1 parent b700c2cfdd
commit bae6175c4b
2 files changed
+75

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
import { PictureInPicture } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'SVG Previewer',
path: '/svg-previewer',
description: 'Preview SVG files',
keywords: ['svg', 'previewer'],
component: () => import('./svg-previewer.vue'),
icon: PictureInPicture,
createdAt: new Date('2025-12-14'),
category: 'Images',
});
+62
View File
@@ -0,0 +1,62 @@
<script setup lang="ts">
const svgContent = ref<string | null>(null);
const backgroundColor = ref<string>('#ffffff');
function readAsTextAsync(file: File) {
return new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = () => resolve(reader.result?.toString() ?? '');
reader.onerror = error => reject(error);
});
}
async function onFileUploaded(uploadedFile: File) {
svgContent.value = await readAsTextAsync(uploadedFile);
}
</script>
<template>
<div style="padding: 16px;">
<c-file-upload
title="Upload a SVG File"
paste-image
accept=".svg"
mb-1
@file-upload="onFileUploaded"
/>
<c-input-text
v-model:value="svgContent"
title="Raw SVG Content:"
rows="6"
multiline
placeholder="Paste raw SVG content here..."
mb-1
/>
<n-form-item label="Select background:" label-placement="left" mb-1>
<NColorPicker v-model:value="backgroundColor" />
</n-form-item>
<NCard
title="SVG Preview"
style="margin-top: 16px; min-height: 300px;"
>
<div
v-if="svgContent"
:style="{
backgroundColor,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
overflow: 'auto',
}"
v-html="svgContent"
/>
<NEmpty v-else description="No SVG loaded yet" />
</NCard>
</div>
</template>