feat: add svelte components

This commit is contained in:
2026-08-22 10:20:18 +05:00
parent 719bda2e22
commit c0225552e4
7 changed files with 552 additions and 0 deletions
@@ -0,0 +1,41 @@
<script lang="ts">
import { downloadBlob, encode } from '$lib/core/io';
import type { PixelImage } from '$lib/core/types';
import type { OutputFormat } from '$lib/registry';
let {
image,
format,
baseName,
params,
onError
}: {
image: PixelImage | null;
format?: OutputFormat;
baseName: string;
params: Record<string, unknown>;
onError?: (e: unknown) => void;
} = $props();
let busy = $state(false);
async function download() {
if (!image || !format || busy) return;
busy = true;
try {
const raw = format.qualityParamId ? params[format.qualityParamId] : undefined;
const quality =
typeof raw === 'number' ? Math.min(Math.max(raw, 1), 100) / 100 : undefined;
const blob = await encode(image, format.mime, quality);
downloadBlob(blob, `${baseName}.${format.ext}`);
} catch (e) {
onError?.(e);
} finally {
busy = false;
}
}
</script>
<button class="primary" onclick={download} disabled={!image || !format || busy}>
{busy ? 'Готовим файл…' : `Скачать .${format?.ext ?? 'png'}`}
</button>