char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { IMAGE } from '$lib/constants' ; 2import { MimeTypeImage } from '$lib/enums' ; 3 4// heic requires a relatively large decoder, in order to reduce primary bundle size 5// we lazily load this decoder from a CDN when needed, and cache it for future conversions 6const HEIC_TO_CDN_URL = 'https://cdn.jsdelivr.net/npm/heic-to@1.5.2/dist/heic-to.js' ; 7 8interface HeicToModule { 9heicTo ( args :{ blob :Blob ; type :string ; quality ?:number }) :Promise < Blob >; 10} 11 12let modulePromise :Promise < HeicToModule > | null = null ; 13 14/** 15* Lazily load the heic-to decoder from the CDN and cache it 16* @returns Promise resolving to the heic-to module 17*/ 18function getHeicTo () :Promise < HeicToModule > { 19if ( ! modulePromise ) { 20modulePromise = import ( /* @vite-ignore */ HEIC_TO_CDN_URL ) as Promise < HeicToModule >; 21} 22 23return modulePromise ; 24} 25 26/** 27* Convert a HEIC/HEIF file to a compressed JPEG data URL 28* @param file - The HEIC/HEIF file to convert 29* @returns Promise resolving to JPEG data URL 30*/ 31export async function heicFileToJpegDataURL ( file :File | Blob ) :Promise < string > { 32const { heicTo} = await getHeicTo (); 33const jpegBlob = await heicTo ({ 34blob :file , 35quality :IMAGE . HEIC_JPEG_QUALITY , 36type :MimeTypeImage . JPEG 37}); 38 39return new Promise (( resolve , reject ) => { 40const reader = new FileReader (); 41 42reader . onload = () => resolve ( reader . result as string ); 43reader . onerror = () => reject ( reader . error ); 44reader . readAsDataURL ( jpegBlob ); 45}); 46} 47 48/** 49* Check if a MIME type represents a HEIC/HEIF image 50* @param mimeType - The MIME type to check 51* @returns True if the MIME type is image/heic or image/heif 52*/ 53export function isHeicMimeType ( mimeType :string ) :boolean { 54const normalized = mimeType . trim (). toLowerCase (); 55 56return normalized === MimeTypeImage . HEIC || normalized === MimeTypeImage . HEIF ; 57}