const BASE = import.meta.env.BASE_URL || './' export const asset = (p: string) => `${BASE.endsWith('/') ? BASE : BASE + '/'}${p}` const FONTS: [string, string][] = [ ['MV Neon', 'mvfonts/neon.woff2'], ['MV Black', 'mvfonts/black.woff2'], ['MV Latin', 'mvfonts/latin.woff2'], ] let loading: Promise | null = null export function loadFonts(): Promise { if (loading) return loading loading = Promise.all( FONTS.map(async ([family, url]) => { try { const f = new FontFace(family, `url(${asset(url)}) format("woff2")`) await f.load() document.fonts.add(f) } catch (e) { console.warn('font failed', family, e) } }), ).then(() => undefined) return loading } export const AUDIO_URL = asset('heijie.mp3') let lyricFont: Promise | null = null /** the full common-character set (GB2312, ~950 KB) is only fetched when lyrics are used */ export function ensureLyricFont(): Promise { if (lyricFont) return lyricFont lyricFont = (async () => { try { const f = new FontFace('MV Lyric', `url(${asset('mvfonts/lyric.woff2')}) format("woff2")`) await f.load() document.fonts.add(f) window.dispatchEvent(new Event('mv-lyrics')) } catch (e) { console.warn('lyric font failed', e) } })() return lyricFont }