refactor
This commit is contained in:
parent
ad2020f4c2
commit
a342b7edec
2 changed files with 8 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import { fetchMscz } from './mscz'
|
import { fetchMscz } from './mscz'
|
||||||
|
import { fetchData } from './utils'
|
||||||
|
|
||||||
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.10/webmscore.js'
|
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
|
// CJK (East Asian) characters will be rendered as "tofu" if there is no font
|
||||||
if (!fonts) {
|
if (!fonts) {
|
||||||
fonts = Promise.all(
|
fonts = Promise.all(
|
||||||
FONT_URLS.map(async (url) => {
|
FONT_URLS.map(url => fetchData(url)),
|
||||||
const r = await fetch(url)
|
|
||||||
const data = await r.arrayBuffer()
|
|
||||||
return new Uint8Array(data)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,12 @@ export const getIndexPath = (id: number): string => {
|
||||||
return indexN.join('/')
|
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> => {
|
export const waitForDocumentLoaded = (): Promise<void> => {
|
||||||
if (document.readyState !== 'complete') {
|
if (document.readyState !== 'complete') {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
Loading…
Reference in a new issue