Spaces:
Paused
Paused
Download src/mv/fonts.ts from Ethscriptions/video: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/Ethscriptions/video/resolve/main/src/mv/fonts.ts
- Command line
-
hf download hf://spaces/Ethscriptions/video/src/mv/fonts.ts
-
curl -L -o fonts.ts https://huggingface.co/spaces/Ethscriptions/video/resolve/main/src/mv/fonts.ts
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 | |
| } | |