import '@dotnet/jsinterop' ; import './GlobalExports' ; import * as Environment from './Environment' ; import { monoPlatform } from './Platform/Mono/MonoPlatform' ; import { getAssemblyNameFromUrl } from './Platform/Url' ; import { renderBatch } from './Rendering/Renderer' ; import { SharedMemoryRenderBatch } from './Rendering/RenderBatch/SharedMemoryRenderBatch' ; import { Pointer } from './Platform/Platform' ; import { shouldAutoStart } from './BootCommon' ; import { setEventDispatcher } from './Rendering/RendererEventDispatcher' ; let started = false ; async function boot ( options ? ) { if ( started ) { throw new Error ( 'Blazor has already started.' ) ; } started = true ; setEventDispatcher ( ( eventDescriptor , eventArgs ) => DotNet . invokeMethodAsync ( 'Microsoft.AspNetCore.Blazor' , 'DispatchEvent' , eventDescriptor , JSON . stringify ( eventArgs ) ) ) ; const platform = Environment . setPlatform ( monoPlatform ) ; window [ 'Blazor' ] . platform = platform ; window [ 'Blazor' ] . _internal . renderBatch = ( browserRendererId , batchAddress ) => { renderBatch ( browserRendererId , new SharedMemoryRenderBatch ( batchAddress ) ) ; } ; window [ 'Blazor' ] . _internal . navigationManager . listenForNavigationEvents ( async ( uri , intercepted ) : Promise < void > => { await DotNet . invokeMethodAsync ( 'Microsoft.AspNetCore.Blazor' , 'NotifyLocationChanged' , uri , intercepted ) ; } ) ; const bootConfig = await fetchBootConfigAsync ( ) ; const embeddedResourcesPromise = loadEmbeddedResourcesAsync ( bootConfig ) ; if ( ! bootConfig . linkerEnabled ) { console . info ( 'Blazor is running in dev mode without IL stripping. To make the bundle size significantly smaller, publish the application or see https://go.microsoft.com/fwlink/?linkid=870414' ) ; } const loadAssemblyUrls = [ bootConfig . main ] . concat ( bootConfig . assemblyReferences ) . map ( filename => `_framework/_bin/${ filename }` ) ; try { await platform . start ( loadAssemblyUrls ) ; } catch ( ex ) { throw new Error ( `Failed to start platform. Reason: ${ ex }` ) ; } await embeddedResourcesPromise ; const mainAssemblyName = getAssemblyNameFromUrl ( bootConfig . main ) ; platform . callEntryPoint ( mainAssemblyName , bootConfig . entryPoint , [ ] ) ; } async function fetchBootConfigAsync ( ) { const bootConfigResponse = await fetch ( '_framework/blazor.boot.json' , { method : 'Get' , credentials : 'include' } ) ; return bootConfigResponse . json ( ) as Promise < BootJsonData > ; } function loadEmbeddedResourcesAsync ( bootConfig ) { const cssLoadingPromises = bootConfig . cssReferences . map ( cssReference => { const linkElement = document . createElement ( 'link' ) ; linkElement . rel = 'stylesheet' ; linkElement . href = cssReference ; return loadResourceFromElement ( linkElement ) ; } ) ; const jsLoadingPromises = bootConfig . jsReferences . map ( jsReference => { const scriptElement = document . createElement ( 'script' ) ; scriptElement . src = jsReference ; return loadResourceFromElement ( scriptElement ) ; } ) ; return Promise . all ( cssLoadingPromises . concat ( jsLoadingPromises ) ) ; } function loadResourceFromElement ( element ) { return new Promise ( ( resolve , reject ) => { element . onload = resolve ; element . onerror = reject ; document . head ! . appendChild ( element ) ; } ) ; } interface BootJsonData { main : string ; entryPoint : string ; assemblyReferences : string [ ] ; cssReferences : string [ ] ; jsReferences : string [ ] ; linkerEnabled : boolean ; } window [ 'Blazor' ] . start = boot ; if ( shouldAutoStart ( ) ) { boot ( ) ; }