/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** Injectable that ensures only the most recently enabled FocusTrap is active. */ export class FocusTrapManager { constructor() { // A stack of the FocusTraps on the page. Only the FocusTrap at the // top of the stack is active. this._focusTrapStack = []; } /** * Disables the FocusTrap at the top of the stack, and then pushes * the new FocusTrap onto the stack. */ register(focusTrap) { // Dedupe focusTraps that register multiple times. this._focusTrapStack = this._focusTrapStack.filter(ft => ft !== focusTrap); let stack = this._focusTrapStack; if (stack.length) { stack[stack.length - 1]._disable(); } stack.push(focusTrap); focusTrap._enable(); } /** * Removes the FocusTrap from the stack, and activates the * FocusTrap that is the new top of the stack. */ deregister(focusTrap) { focusTrap._disable(); const stack = this._focusTrapStack; const i = stack.indexOf(focusTrap); if (i !== -1) { stack.splice(i, 1); if (stack.length) { stack[stack.length - 1]._enable(); } } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FocusTrapManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FocusTrapManager, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: FocusTrapManager, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9jdXMtdHJhcC1tYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9hMTF5L2ZvY3VzLXRyYXAvZm9jdXMtdHJhcC1tYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Oz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