import * as ReactDOM from "react-dom" ; export type ChildrenSelectorTuple = [ any , string ] ; const portals = [ ] ; function canUseDOM ( ) { return ! ! ( typeof window !== 'undefined' && window . document && window . document . createElement ) ; } export function createUniversalPortal ( children , selector ) { if ( ! canUseDOM ( ) ) { portals . push ( [ children , selector ] ) ; return null ; } return ( ReactDOM as any ) . createPortal ( children , document . querySelector ( selector ) ) ; } export function flushUniversalPortals ( ) { const copy = portals . slice ( ) ; portals . length = 0 ; return copy ; } export function removeUniversalPortals ( ) { if ( canUseDOM ( ) ) { Array . prototype . slice . call ( document . querySelectorAll ( "[data-react-universal-portal]" ) ) . forEach ( function ( node ) { node . remove ( ) ; } ) ; } }