video / src /mv /fonts.ts
Ethscriptions's picture
v8:远光照亮整块路面并闪白;喷射气体改为自然粒子气体;新增动感歌词(LRC / 打轴工具,随导出)
71ce0f9 verified
Raw History Blame Contribute Delete
1.34 kB
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<void> | null = null
export function loadFonts(): Promise<void> {
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<void> | null = null
/** the full common-character set (GB2312, ~950 KB) is only fetched when lyrics are used */
export function ensureLyricFont(): Promise<void> {
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
}