license import { DOCUMENT } from '@angular/common' ; import { Inject , Injectable , InjectionToken , OnDestroy , Optional , SkipSelf , } from '@angular/core' ; import { Platform } from '@angular/cdk/platform' ; /**
 * Whether we're in a testing environment.
 * TODO(crisbeto): remove this once we have an overlay testing module.
 */ const isTestEnvironment = typeof window !== 'undefined' && ! ! window && ! ! ( ( window as any ) . __karma__ || ( window as any ) . jasmine ) ; /** Container inside which all overlays will render. */ @ Injectable ( { providedIn : 'root' } ) export class OverlayContainer implements OnDestroy { protected _containerElement : HTMLElement ; protected _document : Document ; constructor ( @ Inject ( DOCUMENT ) document , deprecated breaking-change protected _platform ? ) { this . _document = document ; } ngOnDestroy ( ) { const container = this . _containerElement ; if ( container && container . parentNode ) { container . parentNode . removeChild ( container ) ; } } returns getContainerElement ( ) { if ( ! this . _containerElement ) { this . _createContainer ( ) ; } return this . _containerElement ; } /**
     * Create the overlay container element, which is simply a div
     * with the 'cdk-overlay-container' class on the document body.
     */ protected _createContainer ( ) { const isBrowser = this . _platform ? this . _platform . isBrowser : typeof window !== 'undefined' ; const containerClass = 'cdk-overlay-container' ; if ( isBrowser || isTestEnvironment ) { const oppositePlatformContainers = this . _document . querySelectorAll ( `.${ containerClass }[platform="server"], ` + `.${ containerClass }[platform="test"]` ) ; for ( let i = 0 ; i < oppositePlatformContainers . length ; i ++ ) { oppositePlatformContainers [ i ] . parentNode ! . removeChild ( oppositePlatformContainers [ i ] ) ; } } const container = this . _document . createElement ( 'div' ) ; container . classList . add ( containerClass ) ; if ( isTestEnvironment ) { container . setAttribute ( 'platform' , 'test' ) ; } else if ( ! isBrowser ) { container . setAttribute ( 'platform' , 'server' ) ; } this . _document . body . appendChild ( container ) ; this . _containerElement = container ; } } docs-private deprecated breaking-change export function OVERLAY_CONTAINER_PROVIDER_FACTORY ( parentContainer , _document ) { return parentContainer || new OverlayContainer ( _document ) ; } docs-private deprecated breaking-change export const OVERLAY_CONTAINER_PROVIDER = { provide : OverlayContainer , deps : [ [ new Optional ( ) , new SkipSelf ( ) , OverlayContainer ] , DOCUMENT as InjectionToken < any > ] , useFactory : OVERLAY_CONTAINER_PROVIDER_FACTORY } ;