This commit is contained in:
Xmader 2020-10-20 01:39:38 -04:00
parent ad2020f4c2
commit a342b7edec
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { fetchMscz } from './mscz'
import { fetchData } from './utils'
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.10/webmscore.js'
@ -25,11 +26,7 @@ const initFonts = () => {
// CJK (East Asian) characters will be rendered as "tofu" if there is no font
if (!fonts) {
fonts = Promise.all(
FONT_URLS.map(async (url) => {
const r = await fetch(url)
const data = await r.arrayBuffer()
return new Uint8Array(data)
}),
FONT_URLS.map(url => fetchData(url)),
)
}
}

View File

@ -13,6 +13,12 @@ export const getIndexPath = (id: number): string => {
return indexN.join('/')
}
export const fetchData = async (url: string, init?: RequestInit): Promise<Uint8Array> => {
const r = await fetch(url, init)
const data = await r.arrayBuffer()
return new Uint8Array(data)
}
export const waitForDocumentLoaded = (): Promise<void> => {
if (document.readyState !== 'complete') {
return new Promise(resolve => {