license import { Inject , Injectable , NgZone } from '@angular/core' ; import { DOCUMENT } from '@angular/common' ; import { FocusTrap , InteractivityChecker } from '@angular/cdk/a11y' ; import { Observable , Subject } from 'rxjs' ; /** Value indicating whether focus left the target area before or after the enclosed elements. */ export const enum FocusEscapeNotifierDirection { START , END } /**
 * Like FocusTrap, but rather than trapping focus within a dom region, notifies subscribers when
 * focus leaves the region.
 */ export class FocusEscapeNotifier extends FocusTrap { private readonly _escapeSubject = new Subject < FocusEscapeNotifierDirection > ( ) ; constructor ( element , checker , ngZone , document ) { super ( element , checker , ngZone , document , true ) ; this . startAnchorListener = ( ) => { this . _escapeSubject . next ( FocusEscapeNotifierDirection . START ) ; return true ; } ; this . endAnchorListener = ( ) => { this . _escapeSubject . next ( FocusEscapeNotifierDirection . END ) ; return true ; } ; this . attachAnchors ( ) ; } escapes ( ) { return this . _escapeSubject ; } } /** Factory that allows easy instantiation of focus escape notifiers. */ @ Injectable ( { providedIn : 'root' } ) export class FocusEscapeNotifierFactory { private _document : Document ; constructor ( private _checker , private _ngZone , @ Inject ( DOCUMENT ) _document ) { this . _document = _document ; } param element returns create ( element ) { return new FocusEscapeNotifier ( element , this . _checker , this . _ngZone , this . _document ) ; } }