From de9641224809e5149ff75ae0e5ba34fa8262b5d6 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 20 Dec 2025 19:07:10 +0100 Subject: [PATCH] fix: typescript errors --- src/App.vue | 32 +++++++++++++++++++------------- src/components/LucideIcon.vue | 1 + 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/App.vue b/src/App.vue index 180c33b..be5a9f4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -52,9 +52,9 @@ function openImage() { } const reader = new FileReader(); reader.onload = () => { - image.value.src = reader.result as string; + srcData.value = reader.result as string; }; - reader.readAsDataURL(input.value.files[0]); + reader.readAsDataURL(input.value.files[0] as Blob); } function imageOnLoad() { @@ -67,7 +67,8 @@ function imageOnLoad() { setTimeout(draw); } -function randomElement(items) { +function randomElement(items: T[]): T { + // @ts-expect-error: arbitrary type bullshit return items[Math.floor(Math.random() * items.length)]; } @@ -100,12 +101,12 @@ function newImage() { function download() { const link = document.createElement("a"); - link.download = "coverify.png"; - link.href = canvas.value.toDataURL(); + link.download = `coverify-${new Date().getTime()}.png`; + link.href = canvas.value?.toDataURL() ?? "#"; link.click(); } -function applyFilter(f: Filter, r: number, g: number, b: number) { +function applyFilter(f: Filter, r: number, g: number, b: number): [number, number, number] { switch (f) { case Filter.Gray: const gray = 0.21 * r + 0.72 * g + 0.07 * b; @@ -123,8 +124,11 @@ function applyFilter(f: Filter, r: number, g: number, b: number) { } function draw() { - const ctx = canvas.value?.getContext("2d"); - if (!ctx) { + if (!canvas.value) { + return; + } + const ctx = canvas.value.getContext("2d"); + if (!ctx || !image.value) { return; } canvas.value.width = targetSize.value; @@ -145,9 +149,9 @@ function draw() { ); const pixelData = imageData.data; for (let i = 0; i < pixelData.length; i += 4) { - const r1 = pixelData[i]; - const g1 = pixelData[i + 1]; - const b1 = pixelData[i + 2]; + const r1 = (pixelData[i] as number); + const g1 = (pixelData[i + 1] as number); + const b1 = (pixelData[i + 2] as number); const [r2, g2, b2] = applyFilter(filter.value, r1, g1, b1); @@ -159,7 +163,7 @@ function draw() { ctx.putImageData(imageData, 0, 0); - if (paPos.value !== PAPosition.None) { + if (paPos.value !== PAPosition.None && parentalAdvisory.value) { const paWidth = targetSize.value * paScale.value; const paHeight = paWidth * PA_RATIO; let padx = paMargin.value * targetSize.value; @@ -200,7 +204,7 @@ onMounted(() => { { + @@ -347,6 +352,7 @@ onMounted(() => { {{ (paMargin * 100).toFixed(0) }}% +
diff --git a/src/components/LucideIcon.vue b/src/components/LucideIcon.vue index 8f47247..5d66803 100644 --- a/src/components/LucideIcon.vue +++ b/src/components/LucideIcon.vue @@ -25,6 +25,7 @@ function kebab2camel(kebab: string): string { .join(""); } +// @ts-expect-error: cannot infer type of all exported data const icon = computed(() => icons[kebab2camel(props.name)]);