class ClassLoader { LoadImage ( URL ) { return new Promise ( ( resolve , reject ) => { const worker = this . createWorker ( ) ; worker . addEventListener ( "message" , ( evt ) => { if ( evt . data . err ) { reject ( ) ; } else { resolve ( evt . data ) ; } worker . terminate ( ) ; } ) ; worker . postMessage ( `${ window . location . href . replace ( /[^\\\/]*$/ , "" ) }${ URL }` ) ; } ) ; } private createWorker ( ) { return new Worker ( URL . createObjectURL ( new Blob ( [ `(function ${ this . worker })()` ] ) ) ) ; } private worker ( ) { const ctx = self as any ; ctx . addEventListener ( "message" , ( evt ) => { fetch ( evt . data ) . then ( response => response . blob ( ) ) . then ( blobData => { createImageBitmap ( blobData ) . then ( image => ctx . postMessage ( image ) ) ; } ) ; } ) ; } } export const Loader = new ClassLoader ( ) ;