mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
feat(replacing tool): Mermaid Viewer and Exporter
Fix #1563 and replace #46
This commit is contained in:
commit
a76d7500e6
9 files changed
+240
-87
No files matched your search
Vendored
+1
-16
@@ -179,7 +179,6 @@ declare module '@vue/runtime-core' {
|
|||||||
IconMdiEye: typeof import('~icons/mdi/eye')['default']
|
IconMdiEye: typeof import('~icons/mdi/eye')['default']
|
||||||
IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default']
|
IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default']
|
||||||
IconMdiHeart: typeof import('~icons/mdi/heart')['default']
|
IconMdiHeart: typeof import('~icons/mdi/heart')['default']
|
||||||
IconMdiRefresh: typeof import('~icons/mdi/refresh')['default']
|
|
||||||
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
||||||
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
||||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||||
@@ -260,7 +259,7 @@ declare module '@vue/runtime-core' {
|
|||||||
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
||||||
MenuIconItem: typeof import('./src/components/MenuIconItem.vue')['default']
|
MenuIconItem: typeof import('./src/components/MenuIconItem.vue')['default']
|
||||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||||
MermaidPreviewer: typeof import('./src/tools/mermaid-previewer/mermaid-previewer.vue')['default']
|
MermaidExporter: typeof import('./src/tools/mermaid-exporter/mermaid-exporter.vue')['default']
|
||||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||||
MicTester: typeof import('./src/tools/mic-tester/mic-tester.vue')['default']
|
MicTester: typeof import('./src/tools/mic-tester/mic-tester.vue')['default']
|
||||||
MimeConverter: typeof import('./src/tools/mime-converter/mime-converter.vue')['default']
|
MimeConverter: typeof import('./src/tools/mime-converter/mime-converter.vue')['default']
|
||||||
@@ -270,19 +269,14 @@ declare module '@vue/runtime-core' {
|
|||||||
MorseConverter: typeof import('./src/tools/morse-converter/morse-converter.vue')['default']
|
MorseConverter: typeof import('./src/tools/morse-converter/morse-converter.vue')['default']
|
||||||
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
||||||
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
||||||
NA: typeof import('naive-ui')['NA']
|
|
||||||
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
||||||
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
||||||
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
NButton: typeof import('naive-ui')['NButton']
|
NButton: typeof import('naive-ui')['NButton']
|
||||||
NCard: typeof import('naive-ui')['NCard']
|
|
||||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
|
||||||
NCode: typeof import('naive-ui')['NCode']
|
NCode: typeof import('naive-ui')['NCode']
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
NDivider: typeof import('naive-ui')['NDivider']
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
@@ -290,22 +284,13 @@ declare module '@vue/runtime-core' {
|
|||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
NImage: typeof import('naive-ui')['NImage']
|
|
||||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NModal: typeof import('naive-ui')['NModal']
|
|
||||||
NP: typeof import('naive-ui')['NP']
|
|
||||||
NProgress: typeof import('naive-ui')['NProgress']
|
|
||||||
NRate: typeof import('naive-ui')['NRate']
|
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
NSlider: typeof import('naive-ui')['NSlider']
|
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
NSpace: typeof import('naive-ui')['NSpace']
|
||||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||||
NTable: typeof import('naive-ui')['NTable']
|
|
||||||
NTag: typeof import('naive-ui')['NTag']
|
|
||||||
NTimePicker: typeof import('naive-ui')['NTimePicker']
|
|
||||||
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
||||||
|
|||||||
+1
-1
@@ -202,6 +202,7 @@
|
|||||||
"mathjs": "^14.2.1",
|
"mathjs": "^14.2.1",
|
||||||
"md-editor-v3": "^4.21.3",
|
"md-editor-v3": "^4.21.3",
|
||||||
"memorystream": "^0.3.1",
|
"memorystream": "^0.3.1",
|
||||||
|
"mermaid": "^11.6.0",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"mitex-wasm": "^0.2.5",
|
"mitex-wasm": "^0.2.5",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
@@ -267,7 +268,6 @@
|
|||||||
"vue-i18n": "^9.14.3",
|
"vue-i18n": "^9.14.3",
|
||||||
"vue-markdown-render": "^2.2.1",
|
"vue-markdown-render": "^2.2.1",
|
||||||
"vue-mathjax-next": "^0.0.6",
|
"vue-mathjax-next": "^0.0.6",
|
||||||
"vue-mermaid-string": "^7.0.0",
|
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
"vue-shadow-dom": "^4.2.0",
|
"vue-shadow-dom": "^4.2.0",
|
||||||
"vue-tsc": "^1.8.1",
|
"vue-tsc": "^1.8.1",
|
||||||
|
|||||||
Generated
+3
-13
@@ -503,6 +503,9 @@ dependencies:
|
|||||||
memorystream:
|
memorystream:
|
||||||
specifier: ^0.3.1
|
specifier: ^0.3.1
|
||||||
version: 0.3.1
|
version: 0.3.1
|
||||||
|
mermaid:
|
||||||
|
specifier: ^11.6.0
|
||||||
|
version: 11.6.0
|
||||||
mime-types:
|
mime-types:
|
||||||
specifier: ^2.1.35
|
specifier: ^2.1.35
|
||||||
version: 2.1.35
|
version: 2.1.35
|
||||||
@@ -698,9 +701,6 @@ dependencies:
|
|||||||
vue-mathjax-next:
|
vue-mathjax-next:
|
||||||
specifier: ^0.0.6
|
specifier: ^0.0.6
|
||||||
version: 0.0.6
|
version: 0.0.6
|
||||||
vue-mermaid-string:
|
|
||||||
specifier: ^7.0.0
|
|
||||||
version: 7.0.0
|
|
||||||
vue-router:
|
vue-router:
|
||||||
specifier: ^4.1.6
|
specifier: ^4.1.6
|
||||||
version: 4.1.6(vue@3.3.4)
|
version: 4.1.6(vue@3.3.4)
|
||||||
@@ -18095,16 +18095,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-H4nZ8t31TmBJgiR6pHrOGz+RWhlw34d0yhD8fi8CnXoGOydGFreNH/Crd/9Jfd2IMSu/I0AC3ymT9D09JRMIrw==}
|
resolution: {integrity: sha512-H4nZ8t31TmBJgiR6pHrOGz+RWhlw34d0yhD8fi8CnXoGOydGFreNH/Crd/9Jfd2IMSu/I0AC3ymT9D09JRMIrw==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/vue-mermaid-string@7.0.0:
|
|
||||||
resolution: {integrity: sha512-bpOXTO6ppZ/hwHOkKJOUhRI98i5xZmroDXmyBSnUJC2IO1IsXZJE0EL+YleDs5EtuOH25Db4m7OVVkFgQaLYqg==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
dependencies:
|
|
||||||
mermaid: 11.6.0
|
|
||||||
nanoid: 5.0.9
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/vue-router@4.1.6(vue@3.3.4):
|
/vue-router@4.1.6(vue@3.3.4):
|
||||||
resolution: {integrity: sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ==}
|
resolution: {integrity: sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Markdown } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Mermaid exporter',
|
||||||
|
path: '/mermaid-exporter',
|
||||||
|
description: 'Convert Markdown (Mermaid) to image and allow to export to PNG, JPG & SVG',
|
||||||
|
keywords: ['mermaid', 'exporter', 'markdown', 'MD'],
|
||||||
|
component: () => import('./mermaid-exporter.vue'),
|
||||||
|
icon: Markdown,
|
||||||
|
createdAt: new Date('2025-04-11'),
|
||||||
|
category: 'Text',
|
||||||
|
redirectFrom: ['/mermaid-previewer'],
|
||||||
|
});
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('Mermaid Diagram Renderer', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto('/mermaid-exporter');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render the initial diagram', async ({ page }) => {
|
||||||
|
const diagramContainer = page.locator('.diagram-container svg');
|
||||||
|
await expect(diagramContainer).toBeVisible();
|
||||||
|
await expect(diagramContainer).toHaveAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update diagram when user edits Mermaid code', async ({ page }) => {
|
||||||
|
const input = page.getByLabel('Your Mermaid to convert:');
|
||||||
|
const updatedMermaid = `
|
||||||
|
graph LR
|
||||||
|
X[Start] --> Y{Working?}
|
||||||
|
Y -- Yes --> Z[Success!]
|
||||||
|
Y -- No --> W[Fix again!]
|
||||||
|
`;
|
||||||
|
await input.fill(updatedMermaid);
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
|
||||||
|
const svg = page.locator('.diagram-container svg');
|
||||||
|
await expect(svg).toContainText('Start');
|
||||||
|
await expect(svg).toContainText('Success!');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow exporting in SVG, PNG, and JPG', async ({ page }) => {
|
||||||
|
const formats = ['svg', 'png', 'jpg'];
|
||||||
|
|
||||||
|
for (const format of formats) {
|
||||||
|
const button = page.getByRole('button', { name: new RegExp(`Export as ${format}`, 'i') });
|
||||||
|
await expect(button).toBeVisible();
|
||||||
|
await button.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||||
|
import mermaid from 'mermaid';
|
||||||
|
|
||||||
|
mermaid.initialize({ startOnLoad: false });
|
||||||
|
|
||||||
|
const mermaidCode = ref<string>(`graph TD
|
||||||
|
A[Start] --> B{Is it working?}
|
||||||
|
B -- Yes --> C[Great!]
|
||||||
|
B -- No --> D[Fix it!]
|
||||||
|
`);
|
||||||
|
|
||||||
|
const mermaidContainer = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
async function renderMermaid(): Promise<void> {
|
||||||
|
if (mermaidContainer.value) {
|
||||||
|
mermaidContainer.value.innerHTML = '';
|
||||||
|
try {
|
||||||
|
mermaid.parse(mermaidCode.value);
|
||||||
|
const { svg } = await mermaid.render('graphDiv', mermaidCode.value);
|
||||||
|
mermaidContainer.value.innerHTML = svg;
|
||||||
|
}
|
||||||
|
catch (error: unknown) {
|
||||||
|
mermaidContainer.value.innerHTML = '<p class="error">Invalid Mermaid syntax</p>';
|
||||||
|
console.error('Mermaid error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(mermaidCode, () => {
|
||||||
|
nextTick(() => {
|
||||||
|
renderMermaid();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
renderMermaid();
|
||||||
|
});
|
||||||
|
|
||||||
|
function fixSvgSize(svg: string): string {
|
||||||
|
const match = svg.match(/viewBox="([\d\s.-]+)"/);
|
||||||
|
if (!match) {
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||||
|
const [minX, minY, width, height] = match[1].split(/\s+/).map(Number);
|
||||||
|
|
||||||
|
svg = svg.replace(/width="[^"]*"/, `width="${width}"`);
|
||||||
|
svg = svg.replace(/height="[^"]*"/, `height="${height}"`);
|
||||||
|
|
||||||
|
if (!/width="/.test(svg)) {
|
||||||
|
svg = svg.replace('<svg', `<svg width="${width}"`);
|
||||||
|
}
|
||||||
|
if (!/height="/.test(svg)) {
|
||||||
|
svg = svg.replace('<svg', `<svg height="${height}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportAs(format: 'svg' | 'png' | 'jpg'): void {
|
||||||
|
const container = mermaidContainer.value;
|
||||||
|
if (!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const svgElement = container.querySelector('svg');
|
||||||
|
if (!svgElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let svgData = new XMLSerializer().serializeToString(svgElement);
|
||||||
|
|
||||||
|
if (!svgData.includes('xmlns=')) {
|
||||||
|
svgData = svgData.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
|
||||||
|
}
|
||||||
|
|
||||||
|
svgData = fixSvgSize(svgData);
|
||||||
|
|
||||||
|
if (format === 'svg') {
|
||||||
|
const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = 'diagram.svg';
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = new Blob([svgData], { type: 'image/svg+xml' });
|
||||||
|
const reader = new FileReader();
|
||||||
|
const scaleFactor = 3;
|
||||||
|
|
||||||
|
reader.onloadend = () => {
|
||||||
|
const base64data = reader.result as string;
|
||||||
|
const image = new Image();
|
||||||
|
|
||||||
|
image.onload = () => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = image.width * scaleFactor;
|
||||||
|
canvas.height = image.height * scaleFactor;
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.setTransform(scaleFactor, 0, 0, scaleFactor, 0, 0);
|
||||||
|
ctx.drawImage(image, 0, 0);
|
||||||
|
|
||||||
|
const mime = format === 'png' ? 'image/png' : 'image/jpeg';
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.download = `diagram.${format}`;
|
||||||
|
link.href = canvas.toDataURL(mime);
|
||||||
|
link.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
image.src = base64data;
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsDataURL(blob);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div flex flex-col gap-2 md:flex-row>
|
||||||
|
<c-card title="Input Mermaid" mb-2 flex-1>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="mermaidCode"
|
||||||
|
class=""
|
||||||
|
multiline raw-text
|
||||||
|
placeholder="Write your Mermaid code here..."
|
||||||
|
rows="8"
|
||||||
|
autofocus
|
||||||
|
label="Your Mermaid to convert:"
|
||||||
|
/>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Preview" mb-2 flex-1>
|
||||||
|
<div flex justify-center class="diagram-container">
|
||||||
|
<div ref="mermaidContainer" />
|
||||||
|
</div>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
<div flex justify-center class="buttons">
|
||||||
|
<n-button @click="exportAs('png')">
|
||||||
|
Export as PNG
|
||||||
|
</n-button>
|
||||||
|
<n-button @click="exportAs('jpg')">
|
||||||
|
Export as JPG
|
||||||
|
</n-button>
|
||||||
|
<n-button @click="exportAs('svg')">
|
||||||
|
Export as SVG
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.diagram-container {
|
||||||
|
border: 1px solid var(--theme-default-color);
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: var(--theme-default-color);
|
||||||
|
overflow-x: auto;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: var(--theme-error-color);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { ChartPie } from '@vicons/tabler';
|
|
||||||
import { defineTool } from '../tool';
|
|
||||||
|
|
||||||
export const tool = defineTool({
|
|
||||||
name: 'Mermaid previewer',
|
|
||||||
path: '/mermaid-previewer',
|
|
||||||
description: 'Mermaid Diagrams Previewer',
|
|
||||||
keywords: ['mermaid', 'diagrams', 'previewer'],
|
|
||||||
component: () => import('./mermaid-previewer.vue'),
|
|
||||||
icon: ChartPie,
|
|
||||||
createdAt: new Date('2025-03-09'),
|
|
||||||
category: 'Text',
|
|
||||||
});
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import VueMermaidString from 'vue-mermaid-string';
|
|
||||||
import { useStyleStore } from '@/stores/style.store';
|
|
||||||
import useDebouncedRef from '@/composable/debouncedref';
|
|
||||||
|
|
||||||
const diagram = useDebouncedRef(`flowchart TD
|
|
||||||
A[Christmas] -->|Get money| B(Go shopping)
|
|
||||||
B --> C{Let me think}
|
|
||||||
C -->|One| D[Laptop]
|
|
||||||
C -->|Two| E[iPhone]
|
|
||||||
C -->|Three| F[fa:fa-car Car]
|
|
||||||
`, 500);
|
|
||||||
const styleStore = useStyleStore();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div flex flex-col gap-2 md:flex-row>
|
|
||||||
<c-card title="Input Mermaid" mb-2 flex-1>
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="diagram"
|
|
||||||
label="Mermaid Content"
|
|
||||||
multiline
|
|
||||||
placeholder="Put your mermaid content here..."
|
|
||||||
rows="15"
|
|
||||||
mb-2
|
|
||||||
/>
|
|
||||||
</c-card>
|
|
||||||
|
|
||||||
<c-card title="Preview" mb-2 flex-1>
|
|
||||||
<VueMermaidString class="mermaid-viewer" :value="diagram" :options="{ darkMode: styleStore.isDarkTheme }" />
|
|
||||||
</c-card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped lang="less">
|
|
||||||
::v-deep(.mermaid-viewer svg) {
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
display:block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
declare module "vue-mermaid-string" {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user