char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { 2APPLE_DEVICES , 3BUILD_CONFIG , 4REGEX_PATTERNS , 5SPLASH_LINK 6} from '../src/lib/constants/pwa.constants' ; 7import { NEWLINE , TAB } from '../src/lib/constants/special-characters.constants' ; 8import { SplashOrientation } from '../src/lib/enums/splash.enums' ; 9import type { SplashDimensions } from '../src/lib/types' ; 10import { existsSync , readdirSync , readFileSync , writeFileSync } from 'node:fs' ; 11import { resolve } from 'path' ; 12import type { Plugin } from 'vite' ; 13 14let processed = false ; 15 16const OUTPUT_DIR = process . env . LLAMA_UI_OUT_DIR ?? BUILD_CONFIG . OUTPUT_DIR ; 17 18/** 19* Generate iOS splash screen <link> tags from generated apple-splash-*.png files. 20* Returns an array of HTML link strings to be injected into the page head. 21*/ 22export function generateSplashScreenLinks ( outDir :string ) :string [] { 23const files = readdirSync ( outDir ). filter (( f ) => f . match ( REGEX_PATTERNS . SPLASH_FILE )); 24 25if ( files . length === 0 ) return []; 26 27const dimMap = new Map < string , SplashDimensions >(); 28 29for ( const [ dims , spec ] of Object . entries ( APPLE_DEVICES )) { 30const [ w , h ] = dims . split ( 'x' ). map ( Number ); 31 32// logical-point dimensions 33dimMap . set ( ` ${ w } x ${ h } ` , { deviceH :spec . height , deviceW :spec . width , dpr :spec . dpr }); 34dimMap . set ( ` ${ h } x ${ w } ` , { deviceH :spec . height , deviceW :spec . width , dpr :spec . dpr }); 35// pixel dimensions (used by actual generated splash files) 36dimMap . set ( ` ${ w * spec . dpr } x ${ h * spec . dpr } ` , { 37deviceH :spec . height , 38deviceW :spec . width , 39dpr :spec . dpr 40}); 41dimMap . set ( ` ${ h * spec . dpr } x ${ w * spec . dpr } ` , { 42deviceH :spec . height , 43deviceW :spec . width , 44dpr :spec . dpr 45}); 46} 47 48const lightLinks :string [] = []; 49const darkLinks :string [] = []; 50 51for ( const file of files ) { 52const match = file . match ( REGEX_PATTERNS . SPLASH_FILE ); 53 54if ( ! match ) continue ; 55 56const orientation = match [ 1 ] as SplashOrientation ; 57const isDark = !! match [ 2 ]; 58const pixelW = parseInt ( match [ 3 ]); 59const pixelH = parseInt ( match [ 4 ]); 60const key = ` ${ pixelW } x ${ pixelH } ` ; 61const spec = dimMap . get ( key ); 62 63if ( ! spec ) { 64console . warn ( `Unknown splash screen dimensions: ${ key } ( ${ file } )` ); 65 66continue ; 67} 68 69const { deviceH, deviceW, dpr} = spec ; 70const media = `screen and (device-width: ${ deviceW } px) and (device-height: ${ deviceH } px) and (-webkit-device-pixel-ratio: ${ dpr } ) and (orientation: ${ orientation } )` ; 71const href = `./ ${ file } ` ; 72 73if ( isDark ) { 74darkLinks . push ( 75` ${ SPLASH_LINK . HTML } media=" ${ media } ${ SPLASH_LINK . DARK_MEDIA_SUFFIX } " href=" ${ href } ">` 76); 77} else { 78lightLinks . push ( ` ${ SPLASH_LINK . HTML } media=" ${ media } " href=" ${ href } ">` ); 79} 80} 81 82return [ ...lightLinks , ...darkLinks ]; 83} 84 85export function splashScreenPlugin () :Plugin { 86return { 87apply :'build' , 88closeBundle () { 89setTimeout (() => { 90try { 91if ( processed ) return ; 92 93processed = true ; 94 95const outDir = resolve ( OUTPUT_DIR ); 96const indexPath = resolve ( outDir , 'index.html' ); 97 98if ( ! existsSync ( indexPath )) return ; 99 100let content = readFileSync ( indexPath , 'utf-8' ); 101 102// Inject iOS splash screen <link> tags into <head>. 103// The @vite-pwa/assets-generator generates apple-splash-*.png files; 104// this scans them and creates the <link> tags SvelteKit needs. 105const splashLinks = generateSplashScreenLinks ( outDir ); 106 107if ( splashLinks . length > 0 ) { 108console . log ( `Generated ${ splashLinks . length } apple-splash link tags` ); 109const splashHtml = splashLinks . map (( l ) => TAB + TAB + l ). join ( NEWLINE ); 110 111content = content . replace ( 112REGEX_PATTERNS . HEAD_CLOSE , 113splashHtml + NEWLINE + TAB + TAB + '</head>' 114); 115} 116 117// Remove trailing \r from Windows line endings 118content = content . replace ( / \r / g , '' ); 119content = BUILD_CONFIG . GUIDE_COMMENT + NEWLINE + content ; 120 121writeFileSync ( indexPath , content , 'utf-8' ); 122console . log ( 'Updated index.html' ); 123} catch ( error ) { 124console . error ( 'Failed to process build output:' , error ); 125} 126}, 100 ); 127}, 128name :'llamacpp:splash-screen' 129}; 130}