import { Observable , filter , fromEvent , map , shareReplay , startWith } from "rxjs" ; import { getOptionalElement } from "~/browser" ; import { h } from "~/utilities" ; returns export function getLocationHash ( ) { return location . hash . substring ( 1 ) ; } param hash export function setLocationHash ( hash ) { const el = h ( "a" , { href : hash } ) ; el . addEventListener ( "click" , ev => ev . stopPropagation ( ) ) ; el . click ( ) ; } returns export function watchLocationHash ( ) { return fromEvent < HashChangeEvent > ( window , "hashchange" ) . pipe ( map ( getLocationHash ) , startWith ( getLocationHash ( ) ) , filter ( hash => hash . length > 0 ) , shareReplay ( 1 ) ) ; } returns export function watchLocationTarget ( ) { return watchLocationHash ( ) . pipe ( map ( id => getOptionalElement ( `[id="${ id }"]` ) ! ) , filter ( el => typeof el !== "undefined" ) ) ; }