import { Book } from '../book' ; import { RegionGetter } from 'regionize/dist/types/types' ; const recoverFromRule = ( el , book , nextRegion ) => { let removed = el ; const parent = el . parentNode as HTMLElement ; if ( ! parent ) { throw Error ( "Can't recoverFromRule when element is unparented" ) ; } parent . removeChild ( removed ) ; let popped ; if ( book . currentPage . hasOverflowed ( ) ) { parent . appendChild ( el ) ; removed = parent ; if ( ! removed . parentNode ) { throw Error ( "Can't recoverFromRule when element is unparented" ) ; } removed . parentNode . removeChild ( removed ) ; popped = book . currentPage . flow . path . pop ( ) ; if ( book . currentPage . hasOverflowed ( ) ) { console . error ( 'Trying again didnt fix it' ) ; } else { } } const newRegion = nextRegion ( ) ; newRegion . currentElement . appendChild ( removed ) ; if ( popped ) newRegion . path . push ( popped ) ; } ; export default recoverFromRule ;