import { Observable , combineLatest , delay , map , of , switchMap , withLatestFrom } from "rxjs" ; import { Viewport , watchToggle } from "~/browser" ; /**
 * Patch options
 */ interface PatchOptions { viewport$ : Observable < Viewport > ; tablet$ : Observable < boolean > ; } param options export function patchScrolllock ( { viewport$ , tablet$ } ) { combineLatest ( [ watchToggle ( "search" ) , tablet$ ] ) . pipe ( map ( ( [ active , tablet ] ) => active && ! tablet ) , switchMap ( active => of ( active ) . pipe ( delay ( active ? 400 : 100 ) ) ) , withLatestFrom ( viewport$ ) ) . subscribe ( ( [ active , { offset : { y } } ] ) => { if ( active ) { document . body . setAttribute ( "data-md-state" , "lock" ) ; document . body . style . top = `-${ y }px` ; } else { const value = - 1 * parseInt ( document . body . style . top , 10 ) ; document . body . removeAttribute ( "data-md-state" ) ; document . body . style . top = "" ; if ( value ) window . scrollTo ( 0 , value ) ; } } ) ; }