web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

image-blob.svelte (833B)


      1 <script lang="ts">
      2     import type { IImageBlob } from "$lib/types/ui";
      3     import { fmt_cl, to_arr_buf } from "$lib/utils/app";
      4 
      5     let { basis }: { basis: IImageBlob } = $props();
      6 
      7     let img_src = $state<string | undefined>(undefined);
      8 
      9     $effect(() => {
     10         if (!basis.data) {
     11             img_src = undefined;
     12             return;
     13         }
     14         const url = URL.createObjectURL(
     15             new Blob([to_arr_buf(basis.data)], { type: "image/jpeg" })
     16         );
     17         img_src = url;
     18         return () => {
     19             URL.revokeObjectURL(url);
     20         };
     21     });
     22 </script>
     23 
     24 {#if img_src}
     25     <img
     26         id={basis?.id || null}
     27         class={`${fmt_cl(basis?.classes)}`}
     28         src={img_src}
     29         alt={basis?.alt || null}
     30         style="height: 100%; width: 100%; object-fit: cover; display: block;"
     31     />
     32 {/if}