function getFileUrl ( ) { const stackTraceFrames = String ( new Error ( ) . stack ) . replace ( /^Error.*\n/ , '' ) . split ( '\n' ) ; if ( stackTraceFrames . length === 0 ) { console . error ( "Can't use relative paths to specify assets location because the source" + 'file location could not be determined (unexpected stack trace format' + ` "${ new Error ( ) . stack }").` ) ; return '' ; } let callerFrame = stackTraceFrames [ 1 ] ; let m = callerFrame . match ( /http.*\.ts[\?:]/ ) ; if ( m ) { callerFrame = stackTraceFrames [ 2 ] ; } m = callerFrame . match ( /(http.*(\.mjs|\.js))[\?:]/ ) ; if ( ! m ) { m = callerFrame . match ( /at (.*(\.ts))[\?:]/ ) ; if ( ! m ) { m = callerFrame . match ( /at (.*(\.mjs|\.js))[\?:]/ ) ; } } if ( ! m ) { console . error ( stackTraceFrames ) ; console . error ( "Can't use relative paths to specify assets location because the source " + 'file location could not be determined ' + `(unexpected location "${ callerFrame }").` ) ; return '' ; } return m [ 1 ] ; } export function resolveRelativeUrl ( url ) { let result = '' ; try { result = new URL ( url , gScriptUrl ) . toString ( ) ; } catch ( e ) { console . error ( `Invalid URL "${ url }" (relative to "${ gScriptUrl }")` ) ; } return result ; } const gScriptUrl = ( globalThis ?. document ?. currentScript as HTMLScriptElement ) ?. src || getFileUrl ( ) ;