1 | {"version":3,"file":"focus-monitor.d.ts","sources":["focus-monitor.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA","sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Platform } from '@angular/cdk/platform';\nimport { ElementRef, EventEmitter, InjectionToken, NgZone, OnDestroy, AfterViewInit } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { InputModalityDetector } from '../input-modality/input-modality-detector';\nexport declare type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | null;\n/**\n * Corresponds to the options that can be passed to the native `focus` event.\n * via https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus\n */\nexport interface FocusOptions {\n /** Whether the browser should scroll to the element when it is focused. */\n preventScroll?: boolean;\n}\n/** Detection mode used for attributing the origin of a focus event. */\nexport declare const enum FocusMonitorDetectionMode {\n /**\n * Any mousedown, keydown, or touchstart event that happened in the previous\n * tick or the current tick will be used to assign a focus event's origin (to\n * either mouse, keyboard, or touch). This is the default option.\n */\n IMMEDIATE = 0,\n /**\n * A focus event's origin is always attributed to the last corresponding\n * mousedown, keydown, or touchstart event, no matter how long ago it occurred.\n */\n EVENTUAL = 1\n}\n/** Injectable service-level options for FocusMonitor. */\nexport interface FocusMonitorOptions {\n detectionMode?: FocusMonitorDetectionMode;\n}\n/** InjectionToken for FocusMonitorOptions. */\nexport declare const FOCUS_MONITOR_DEFAULT_OPTIONS: InjectionToken<FocusMonitorOptions>;\n/** Monitors mouse and keyboard events to determine the cause of focus events. */\nexport declare class FocusMonitor implements OnDestroy {\n private _ngZone;\n private _platform;\n private readonly _inputModalityDetector;\n /** The focus origin that the next focus event is a result of. */\n private _origin;\n /** The FocusOrigin of the last focus event tracked by the FocusMonitor. */\n private _lastFocusOrigin;\n /** Whether the window has just been focused. */\n private _windowFocused;\n /** The timeout id of the window focus timeout. */\n private _windowFocusTimeoutId;\n /** The timeout id of the origin clearing timeout. */\n private _originTimeoutId;\n /**\n * Whether the origin was determined via a touch interaction. Necessary as properly attributing\n * focus events to touch interactions requires special logic.\n */\n private _originFromTouchInteraction;\n /** Map of elements being monitored to their info. */\n private _elementInfo;\n /** The number of elements currently being monitored. */\n private _monitoredElementCount;\n /**\n * Keeps track of the root nodes to which we've currently bound a focus/blur handler,\n * as well as the number of monitored elements that they contain. We have to treat focus/blur\n * handlers differently from the rest of the events, because the browser won't emit events\n * to the document when focus moves inside of a shadow root.\n */\n private _rootNodeFocusListenerCount;\n /**\n * The specified detection mode, used for attributing the origin of a focus\n * event.\n */\n private readonly _detectionMode;\n /**\n * Event listener for `focus` events on the window.\n * Needs to be an arrow function in order to preserve the context when it gets bound.\n */\n private _windowFocusListener;\n /** Used to reference correct document/window */\n protected _document?: Document;\n /** Subject for stopping our InputModalityDetector subscription. */\n private readonly _stopInputModalityDetector;\n constructor(_ngZone: NgZone, _platform: Platform, _inputModalityDetector: InputModalityDetector, \n /** @breaking-change 11.0.0 make document required */\n document: any | null, options: FocusMonitorOptions | null);\n /**\n * Event listener for `focus` and 'blur' events on the document.\n * Needs to be an arrow function in order to preserve the context when it gets bound.\n */\n private _rootNodeFocusAndBlurListener;\n /**\n * Monitors focus on an element and applies appropriate CSS classes.\n * @param element The element to monitor\n * @param checkChildren Whether to count the element as focused when its children are focused.\n * @returns An observable that emits when the focus state of the element changes.\n * When the element is blurred, null will be emitted.\n */\n monitor(element: HTMLElement, checkChildren?: boolean): Observable<FocusOrigin>;\n /**\n * Monitors focus on an element and applies appropriate CSS classes.\n * @param element The element to monitor\n * @param checkChildren Whether to count the element as focused when its children are focused.\n * @returns An observable that emits when the focus state of the element changes.\n * When the element is blurred, null will be emitted.\n */\n monitor(element: ElementRef<HTMLElement>, checkChildren?: boolean): Observable<FocusOrigin>;\n /**\n * Stops monitoring an element and removes all focus classes.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: HTMLElement): void;\n /**\n * Stops monitoring an element and removes all focus classes.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: ElementRef<HTMLElement>): void;\n /**\n * Focuses the element via the specified focus origin.\n * @param element Element to focus.\n * @param origin Focus origin.\n * @param options Options that can be used to configure the focus behavior.\n */\n focusVia(element: HTMLElement, origin: FocusOrigin, options?: FocusOptions): void;\n /**\n * Focuses the element via the specified focus origin.\n * @param element Element to focus.\n * @param origin Focus origin.\n * @param options Options that can be used to configure the focus behavior.\n */\n focusVia(element: ElementRef<HTMLElement>, origin: FocusOrigin, options?: FocusOptions): void;\n ngOnDestroy(): void;\n /** Access injected document if available or fallback to global document reference */\n private _getDocument;\n /** Use defaultView of injected document if available or fallback to global window reference */\n private _getWindow;\n private _toggleClass;\n private _getFocusOrigin;\n /**\n * Returns whether the focus event should be attributed to touch. Recall that in IMMEDIATE mode, a\n * touch origin isn't immediately reset at the next tick (see _setOrigin). This means that when we\n * handle a focus event following a touch interaction, we need to determine whether (1) the focus\n * event was directly caused by the touch interaction or (2) the focus event was caused by a\n * subsequent programmatic focus call triggered by the touch interaction.\n * @param focusEventTarget The target of the focus event under examination.\n */\n private _shouldBeAttributedToTouch;\n /**\n * Sets the focus classes on the element based on the given focus origin.\n * @param element The element to update the classes on.\n * @param origin The focus origin.\n */\n private _setClasses;\n /**\n * Updates the focus origin. If we're using immediate detection mode, we schedule an async\n * function to clear the origin at the end of a timeout. The duration of the timeout depends on\n * the origin being set.\n * @param origin The origin to set.\n * @param isFromInteraction Whether we are setting the origin from an interaction event.\n */\n private _setOrigin;\n /**\n * Handles focus events on a registered element.\n * @param event The focus event.\n * @param element The monitored element.\n */\n private _onFocus;\n /**\n * Handles blur events on a registered element.\n * @param event The blur event.\n * @param element The monitored element.\n */\n _onBlur(event: FocusEvent, element: HTMLElement): void;\n private _emitOrigin;\n private _registerGlobalListeners;\n private _removeGlobalListeners;\n /** Updates all the state on an element once its focus origin has changed. */\n private _originChanged;\n /**\n * Collects the `MonitoredElementInfo` of a particular element and\n * all of its ancestors that have enabled `checkChildren`.\n * @param element Element from which to start the search.\n */\n private _getClosestElementsInfo;\n}\n/**\n * Directive that determines how a particular element was focused (via keyboard, mouse, touch, or\n * programmatically) and adds corresponding classes to the element.\n *\n * There are two variants of this directive:\n * 1) cdkMonitorElementFocus: does not consider an element to be focused if one of its children is\n * focused.\n * 2) cdkMonitorSubtreeFocus: considers an element focused if it or any of its children are focused.\n */\nexport declare class CdkMonitorFocus implements AfterViewInit, OnDestroy {\n private _elementRef;\n private _focusMonitor;\n private _monitorSubscription;\n readonly cdkFocusChange: EventEmitter<FocusOrigin>;\n constructor(_elementRef: ElementRef<HTMLElement>, _focusMonitor: FocusMonitor);\n ngAfterViewInit(): void;\n ngOnDestroy(): void;\n}\n"]} |
---|