import "array-flat-polyfill" ; import "focus-visible" ; import "unfetch/polyfill" ; import "url-polyfill" ; import { EMPTY , NEVER , Subject , defer , delay , filter , map , merge , mergeWith , shareReplay , switchMap } from "rxjs" ; import { configuration , feature } from "./_" ; import { at , getOptionalElement , requestJSON , setToggle , watchDocument , watchKeyboard , watchLocation , watchLocationTarget , watchMedia , watchPrint , watchViewport } from "./browser" ; import { getComponentElement , getComponentElements , mountBackToTop , mountContent , mountDialog , mountHeader , mountHeaderTitle , mountPalette , mountSearch , mountSearchHiglight , mountSidebar , mountSource , mountTableOfContents , mountTabs , watchHeader , watchMain } from "./components" ; import { SearchIndex , setupClipboardJS , setupInstantLoading , setupVersionSelector } from "./integrations" ; import { patchIndeterminate , patchScrollfix , patchScrolllock } from "./patches" ; import "./polyfills" ; document . documentElement . classList . remove ( "no-js" ) ; document . documentElement . classList . add ( "js" ) ; const document$ = watchDocument ( ) ; const location$ = watchLocation ( ) ; const target$ = watchLocationTarget ( ) ; const keyboard$ = watchKeyboard ( ) ; const viewport$ = watchViewport ( ) ; const tablet$ = watchMedia ( "(min-width: 960px)" ) ; const screen$ = watchMedia ( "(min-width: 1220px)" ) ; const print$ = watchPrint ( ) ; const config = configuration ( ) ; const index$ = document . forms . namedItem ( "search" ) ? __search ?. index || requestJSON < SearchIndex > ( new URL ( "search/search_index.json" , config . base ) ) : NEVER ; const alert$ = new Subject < string > ( ) ; setupClipboardJS ( { alert$ } ) ; if ( feature ( "navigation.instant" ) ) setupInstantLoading ( { document$ , location$ , viewport$ } ) ; if ( config . version ?. provider === "mike" ) setupVersionSelector ( ) ; merge ( location$ , target$ ) . pipe ( delay ( 125 ) ) . subscribe ( ( ) => { setToggle ( "drawer" , false ) ; setToggle ( "search" , false ) ; } ) ; keyboard$ . pipe ( filter ( ( { mode } ) => mode === "global" ) ) . subscribe ( key => { switch ( key . type ) { case "p" : case "," : const prev = getOptionalElement ( "[href][rel=prev]" ) ; if ( typeof prev !== "undefined" ) prev . click ( ) ; break ; case "n" : case "." : const next = getOptionalElement ( "[href][rel=next]" ) ; if ( typeof next !== "undefined" ) next . click ( ) ; break ; } } ) ; patchIndeterminate ( { document$ , tablet$ } ) ; patchScrollfix ( { document$ } ) ; patchScrolllock ( { viewport$ , tablet$ } ) ; const header$ = watchHeader ( getComponentElement ( "header" ) , { viewport$ } ) ; const main$ = document$ . pipe ( map ( ( ) => getComponentElement ( "main" ) ) , switchMap ( el => watchMain ( el , { viewport$ , header$ } ) ) , shareReplay ( 1 ) ) ; const control$ = merge ( ... getComponentElements ( "dialog" ) . map ( el => mountDialog ( el , { alert$ } ) ) , ... getComponentElements ( "header" ) . map ( el => mountHeader ( el , { viewport$ , header$ , main$ } ) ) , ... getComponentElements ( "palette" ) . map ( el => mountPalette ( el ) ) , ... getComponentElements ( "search" ) . map ( el => mountSearch ( el , { index$ , keyboard$ } ) ) , ... getComponentElements ( "source" ) . map ( el => mountSource ( el ) ) ) ; const content$ = defer ( ( ) => merge ( ... getComponentElements ( "content" ) . map ( el => mountContent ( el , { target$ , print$ } ) ) , ... getComponentElements ( "content" ) . map ( el => feature ( "search.highlight" ) ? mountSearchHiglight ( el , { index$ , location$ } ) : EMPTY ) , ... getComponentElements ( "header-title" ) . map ( el => mountHeaderTitle ( el , { viewport$ , header$ } ) ) , ... getComponentElements ( "sidebar" ) . map ( el => el . getAttribute ( "data-md-type" ) === "navigation" ? at ( screen$ , ( ) => mountSidebar ( el , { viewport$ , header$ , main$ } ) ) : at ( tablet$ , ( ) => mountSidebar ( el , { viewport$ , header$ , main$ } ) ) ) , ... getComponentElements ( "tabs" ) . map ( el => mountTabs ( el , { viewport$ , header$ } ) ) , ... getComponentElements ( "toc" ) . map ( el => mountTableOfContents ( el , { viewport$ , header$ } ) ) , ... getComponentElements ( "top" ) . map ( el => mountBackToTop ( el , { viewport$ , header$ , main$ , target$ } ) ) ) ) ; const component$ = document$ . pipe ( switchMap ( ( ) => content$ ) , mergeWith ( control$ ) , shareReplay ( 1 ) ) ; component$ . subscribe ( ) ; window . document$ = document$ ; window . location$ = location$ ; window . target$ = target$ ; window . keyboard$ = keyboard$ ; window . viewport$ = viewport$ ; window . tablet$ = tablet$ ; window . screen$ = screen$ ; window . print$ = print$ ; window . alert$ = alert$ ; window . component$ = component$ ;