web/cutout: fix canvas visibility

This commit is contained in:
wukko 2025-01-17 01:25:52 +06:00
parent 28eb9ebe5d
commit cc3e3be118
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -12,7 +12,6 @@
let draggedOver = false;
let file: File | undefined;
let result: ImageBitmap;
let imageContainer: HTMLElement;
let canvas: HTMLCanvasElement;
@ -20,7 +19,7 @@
let worker: Worker;
const renderImageToCanvas = () => {
const renderImageToCanvas = (result: ImageBitmap) => {
if (canvas && result) {
canvas.width = result.width;
canvas.height = result.height;
@ -40,8 +39,7 @@
const eventData = event.data.cobaltRemoveBgWorker;
if (eventData.result) {
state = "done";
result = eventData.result;
renderImageToCanvas();
renderImageToCanvas(eventData.result);
}
};
@ -53,7 +51,7 @@
};
const exportImage = async () => {
if (!result || !file) return;
if (!file) return;
const resultBlob = await new Promise<Blob>((resolve, reject) => {
canvas.toBlob(blob => {
@ -110,7 +108,7 @@
{/if}
{#if ["busy", "done"].includes(state)}
<div id="image-preview" bind:this={imageContainer}>
<div id="image-preview" bind:this={imageContainer} class={state}>
{#if state === "busy"}
<Skeleton width="100%" height="100%" class="big" />
{/if}
@ -175,6 +173,14 @@
box-shadow: var(--button-box-shadow);
}
#image-preview canvas {
display: none;
}
#image-preview.done canvas {
display: block;
}
.button-row {
display: flex;
flex-direction: row;