|
|
|
@ -1,9 +1,22 @@
|
|
|
|
|
import { FLFParser, FontLayoutManager } from '@figlet-ts/lib'
|
|
|
|
|
|
|
|
|
|
const fontCache: Record<string, string> = {}
|
|
|
|
|
|
|
|
|
|
async function loadFont(name: string) {
|
|
|
|
|
if (fontCache[name]) {
|
|
|
|
|
console.debug('getting font from cache:', name)
|
|
|
|
|
return fontCache[name]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.debug('loading non-cached font:', name)
|
|
|
|
|
try {
|
|
|
|
|
const font = await import(`./fonts/${name}.flf?raw`)
|
|
|
|
|
return font.default
|
|
|
|
|
const response = await fetch(`/fonts/${name}.flf`)
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const font = await response.text()
|
|
|
|
|
fontCache[name] = font
|
|
|
|
|
return font
|
|
|
|
|
}
|
|
|
|
|
throw new Error(`Failed to load or parse font! Response is ${response.status} - ${response.statusText}`)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Cannot load font', name, e)
|
|
|
|
|
}
|
|
|
|
|