diff --git a/src/lib/components/CardList.svelte b/src/lib/components/CardList.svelte index 21c9c2d..287c09d 100644 --- a/src/lib/components/CardList.svelte +++ b/src/lib/components/CardList.svelte @@ -2,17 +2,30 @@ import { t } from '$lib/translations'; import renderFileToCanvas from '$lib/file-renderer'; + /** + * @type {ArrayLike} + */ export let files = []; + + /** + * @type {HTMLElement} + */ + let errorMessageRef; let canvasRefs = []; let colorRefs = []; let stitchesRefs = []; let sizeRefs = []; - let errorMessageRef; let localizedStrings = { stitches: $t('viewer.stitches'), dimensions: $t('viewer.dimensions'), }; + /** + * Downloads a given HTMLCanvasElement as a PNG image. + * + * @param {HTMLCanvasElement} canvas - The canvas element to export as an image. + * @param {string} filename - The desired name of the downloaded file (extension will be replaced with `.png`). + */ const downloadCanvasAsImage = (canvas, filename) => { const image = canvas .toDataURL('image/png') @@ -24,9 +37,15 @@ link.click(); }; + /** + * Cliks the button to render the files when user press enter. + * + * @param {KeyboardEvent} evt - The event that triggered the language switch. + */ const onKeydown = (evt) => { if (evt.key === 'Enter') { - document.getElementById('download-button').click(); + const button = document.getElementById('download-button'); + if (button) button.click(); } }; @@ -44,8 +63,8 @@ id="download-button" role="button" tabindex="0" - on:keydown={onKeydown} - on:click={() => downloadCanvasAsImage(canvasRefs[i], file.name)} + onkeydown={onKeydown} + onclick={() => downloadCanvasAsImage(canvasRefs[i], file.name)} > {$t('viewer.download')} diff --git a/src/lib/components/Dropzone.svelte b/src/lib/components/Dropzone.svelte index 06c5efc..1edd827 100644 --- a/src/lib/components/Dropzone.svelte +++ b/src/lib/components/Dropzone.svelte @@ -11,6 +11,7 @@ +
export let title; + /** + * @type {ArrayLike} + */ export let files = []; export let isError = false; diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 2559f43..dedc67e 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -1,15 +1,28 @@