eths / source /frontend /src /lib /live /fonts.ts
Ethscriptions's picture
Update: ≤3s WeChat-compatible live photos, sets 3 & 4 (fill-in-the-blank), in-browser maker tool
0daf81d verified
Raw History Blame Contribute Delete
1.3 kB
// Self-hosted fonts (no Google Fonts, works in mainland China).
const base = `${import.meta.env.BASE_URL}fonts/`
const FACES: [string, string, string][] = [
['LW SC', 'lw-sc-500.woff2', '500'],
['LW SC', 'lw-sc-700.woff2', '700'],
['LW Smiley', 'lw-smiley.woff2', '400'],
['LW Poppins', 'lw-poppins-800.woff2', '800'],
['LW Poppins', 'lw-poppins-600.woff2', '600'],
['LW IPA', 'lw-ipa-500.woff2', '500'],
]
export const FONT = {
sc: (w: number, px: number) => `${w} ${px}px "LW SC", "PingFang SC", "Microsoft YaHei", sans-serif`,
head: (px: number) => `400 ${px}px "LW Smiley", "LW SC", "PingFang SC", sans-serif`,
word: (px: number) => `800 ${px}px "LW Poppins", "Helvetica Neue", Arial, sans-serif`,
wordSemi: (px: number) => `600 ${px}px "LW Poppins", "Helvetica Neue", Arial, sans-serif`,
ipa: (px: number) => `500 ${px}px "LW IPA", "Lucida Sans Unicode", "Arial Unicode MS", sans-serif`,
}
let loading: Promise<void> | null = null
export function loadFonts(): Promise<void> {
if (loading) return loading
loading = Promise.all(
FACES.map(async ([family, file, weight]) => {
const f = new FontFace(family, `url(${base}${file})`, { weight, display: 'block' })
await f.load()
document.fonts.add(f)
}),
).then(() => undefined)
return loading
}