import { getPrefix } from './prefix' ; export interface BindHook { before ? : ( ) => void ; after ? : ( ) => void ; } export default function ( observer , hook ? ) { hook && typeof hook . before === 'function' && hook . before ( ) ; const prefix = getPrefix ( ) ; document . querySelectorAll < HTMLElement > ( `[${ prefix }name]` ) . forEach ( ( element ) => { const { top , height } = element . getBoundingClientRect ( ) ; element . style . setProperty ( `--${ prefix }top` , `${ top + window . scrollY }` ) ; element . style . setProperty ( `--${ prefix }height` , `${ height }` ) ; observer && observer . observe ( element ) ; } ) ; hook && typeof hook . after === 'function' && hook . after ( ) ; }