license import { Directionality } from '@angular/cdk/bidi' ; import { DomPortalOutlet } from '@angular/cdk/portal' ; import { DOCUMENT , Location } from '@angular/common' ; import { ApplicationRef , ComponentFactoryResolver , Inject , Injectable , Injector , NgZone , Optional , } from '@angular/core' ; import { OverlayKeyboardDispatcher } from './keyboard/overlay-keyboard-dispatcher' ; import { OverlayConfig } from './overlay-config' ; import { OverlayContainer } from './overlay-container' ; import { OverlayRef } from './overlay-ref' ; import { OverlayPositionBuilder } from './position/overlay-position-builder' ; import { ScrollStrategyOptions } from './scroll/index' ; /** Next overlay unique ID. */ let nextUniqueId = 0 ; /**
 * Service to create Overlays. Overlays are dynamically added pieces of floating UI, meant to be
 * used as a low-level building block for other components. Dialogs, tooltips, menus,
 * selects, etc. can all be built using overlays. The service should primarily be used by authors
 * of re-usable components rather than developers building end-user applications.
 *
 * An overlay *is* a PortalOutlet, so any kind of Portal can be loaded into one.
 */ @ Injectable ( ) export class Overlay { private _appRef : ApplicationRef ; constructor ( /** Scrolling strategies that can be used when creating an overlay. */ public scrollStrategies , private _overlayContainer , private _componentFactoryResolver , private _positionBuilder , private _keyboardDispatcher , private _injector , private _ngZone , @ Inject ( DOCUMENT ) private _document , private _directionality , @ Optional ( ) private _location ? ) { } param config returns create ( config ? ) { const host = this . _createHostElement ( ) ; const pane = this . _createPaneElement ( host ) ; const portalOutlet = this . _createPortalOutlet ( pane ) ; const overlayConfig = new OverlayConfig ( config ) ; overlayConfig . direction = overlayConfig . direction || this . _directionality . value ; return new OverlayRef ( portalOutlet , host , pane , overlayConfig , this . _ngZone , this . _keyboardDispatcher , this . _document , this . _location ) ; } returns position ( ) { return this . _positionBuilder ; } returns private _createPaneElement ( host ) { const pane = this . _document . createElement ( 'div' ) ; pane . id = `cdk-overlay-${ nextUniqueId ++ }` ; pane . classList . add ( 'cdk-overlay-pane' ) ; host . appendChild ( pane ) ; return pane ; } returns private _createHostElement ( ) { const host = this . _document . createElement ( 'div' ) ; this . _overlayContainer . getContainerElement ( ) . appendChild ( host ) ; return host ; } param pane returns private _createPortalOutlet ( pane ) { if ( ! this . _appRef ) { this . _appRef = this . _injector . get < ApplicationRef > ( ApplicationRef ) ; } return new DomPortalOutlet ( pane , this . _componentFactoryResolver , this . _appRef , this . _injector ) ; } }