From 3d8df74b4327f6cd6571f91046eacdfa04428bb9 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Wed, 15 Apr 2026 21:18:49 -0400 Subject: [PATCH] refactor(web): turn thumbhash action into Thumbhash component (#27741) refactor(web): extract thumbhash canvas into Thumbhash component Change-Id: If78955bed48b6e690df398e5e2ae61fb6a6a6964 --- web/src/lib/actions/thumbhash.ts | 29 -------------- web/src/lib/components/AdaptiveImage.svelte | 4 +- web/src/lib/components/Thumbhash.svelte | 40 +++++++++++++++++++ .../asset-viewer/photo-viewer.svelte | 7 +--- .../assets/thumbnail/thumbnail.svelte | 21 ++++------ 5 files changed, 51 insertions(+), 50 deletions(-) delete mode 100644 web/src/lib/actions/thumbhash.ts create mode 100644 web/src/lib/components/Thumbhash.svelte diff --git a/web/src/lib/actions/thumbhash.ts b/web/src/lib/actions/thumbhash.ts deleted file mode 100644 index 872d3d03bf..0000000000 --- a/web/src/lib/actions/thumbhash.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { decodeBase64 } from '$lib/utils'; -import { thumbHashToRGBA } from 'thumbhash'; - -/** - * Renders a thumbnail onto a canvas from a base64 encoded hash. - */ -export function thumbhash(canvas: HTMLCanvasElement, options: { base64ThumbHash: string }) { - render(canvas, options); - - return { - update(newOptions: { base64ThumbHash: string }) { - render(canvas, newOptions); - }, - }; -} - -const render = (canvas: HTMLCanvasElement, options: { base64ThumbHash: string }) => { - const ctx = canvas.getContext('2d'); - if (!ctx) { - return; - } - - const { w, h, rgba } = thumbHashToRGBA(decodeBase64(options.base64ThumbHash)); - const pixels = ctx.createImageData(w, h); - canvas.width = w; - canvas.height = h; - pixels.data.set(rgba); - ctx.putImageData(pixels, 0, 0); -}; diff --git a/web/src/lib/components/AdaptiveImage.svelte b/web/src/lib/components/AdaptiveImage.svelte index f60260bd05..ed574cbe39 100644 --- a/web/src/lib/components/AdaptiveImage.svelte +++ b/web/src/lib/components/AdaptiveImage.svelte @@ -1,9 +1,9 @@ + + diff --git a/web/src/lib/components/asset-viewer/photo-viewer.svelte b/web/src/lib/components/asset-viewer/photo-viewer.svelte index a3c560ef8d..da00980f08 100644 --- a/web/src/lib/components/asset-viewer/photo-viewer.svelte +++ b/web/src/lib/components/asset-viewer/photo-viewer.svelte @@ -1,9 +1,9 @@