/
ncit
/
c4panelmodel
Обзор
Документация
Войти
/
ncit
/
c4panelmodel
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/lib/utils/exportImage.ts
43 строки
1 KB
ncit
feat: implement full IcePanel feature clone (Phases 1-8)
09 июн 2026, 11:13
09 июн 2026, 11:13
858c15a
Код
Авторство
О чём код?
/** * Export diagram as PNG using html-to-image (browser-side). */ export async function exportPng(element: HTMLElement, opts: { theme?: 'light' | 'dark'; scale?: number } = {}): Promise<Blob> { const { toPng } = await import('html-to-image'); const dataUrl = await toPng(element, { backgroundColor: opts.theme === 'dark' ? '#0f172a' : '#ffffff', pixelRatio: opts.scale ?? 2, cacheBust: true }); const res = await fetch(dataUrl); return res.blob(); } /** * Export diagram as SVG. */ export async function exportSvg(element: HTMLElement): Promise<string> { const { toSvg } = await import('html-to-image'); return toSvg(element, { cacheBust: true }); } /** * Download a blob as a file. */ export function downloadBlob(blob: Blob, filename: string) { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; a.click(); URL.revokeObjectURL(url); } /** * Download text content as a file. */ export function downloadText(text: string, filename: string, mimeType = 'text/plain') { const blob = new Blob([text], { type: mimeType }); downloadBlob(blob, filename); }