@@ -173,7 +173,7 @@ export namespace katex {
173
173
const defaultVersion = "0.13.3" ;
174
174
let initialized : Promise < Katex > | undefined ;
175
175
let error : string | Event | undefined ;
176
- export const importKaTeX = async (
176
+ export const importKaTeX = (
177
177
version = defaultVersion ,
178
178
) : Promise < Katex > => {
179
179
const url =
@@ -183,21 +183,25 @@ export const importKaTeX = async (
183
183
if ( ! document . querySelector ( `script[src="${ url } "]` ) ) {
184
184
const script = document . createElement ( "script" ) ;
185
185
script . src = url ;
186
- await new Promise < void > ( ( resolve , reject ) => {
187
- script . onload = ( ) => resolve ( ) ;
186
+ initialized = new Promise < Katex > ( ( resolve , reject ) => {
187
+ // deno-lint-ignore no-window
188
+ script . onload = ( ) => resolve ( window . katex ) ;
188
189
script . onerror = ( e ) => {
189
190
error = e ;
190
191
reject ( e ) ;
191
192
} ;
192
193
document . head . append ( script ) ;
193
194
} ) ;
194
195
}
196
+ if ( initialized ) return initialized ;
195
197
196
198
return new Promise ( ( resolve ) => {
197
199
const id = setInterval ( ( ) => {
198
- if ( ! initialized ) return ;
200
+ // deno-lint-ignore no-window
201
+ if ( ! window . katex ) return ;
199
202
clearInterval ( id ) ;
200
- resolve ( initialized ) ;
203
+ // deno-lint-ignore no-window
204
+ resolve ( window . katex ) ;
201
205
} , 500 ) ;
202
206
} ) ;
203
207
} ;
0 commit comments