export const getPageFromElement = ( target ) => { const node = target . closest ( '.page' ) ; if ( ! ( node instanceof HTMLElement ) ) { return null ; } const number = Number ( node . dataset . pageNumber ) ; return { node , number } ; } ; export const getPageFromRange = ( range ) => { const parentElement = range . startContainer . parentElement ; if ( ! ( parentElement instanceof HTMLElement ) ) { return ; } return getPageFromElement ( parentElement ) ; } ; export const getElementFromRange = ( range , className ) : HTMLElement | null => { const parentElement = range . startContainer . parentElement ; if ( ! ( parentElement instanceof HTMLElement ) ) { return null ; } const node = parentElement . closest ( `.${ className }` ) ; if ( ! ( node instanceof HTMLElement ) ) { return null ; } return node ; } ; export const findOrCreateContainerLayer = ( container , className ) => { let layer = container . querySelector ( `.${ className }` ) ; if ( ! layer ) { layer = document . createElement ( 'div' ) ; layer . className = className ; container . appendChild ( layer ) ; } return layer ; } ; export const findOrCreateLayer = ( viewer , pageNumber , layerName ) => { const page = viewer . current . getPageView ( pageNumber - 1 ) ; if ( ! page ) return null ; return findOrCreateContainerLayer ( page . div , layerName ) ; } ;