ngx-bootstrap
Version:
Angular Bootstrap
32 lines • 12.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ngx-bootstrap/focus-trap",["exports","@angular/core","@angular/common","rxjs/operators"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self)["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"]["focus-trap"]={}),t.ng.core,t.ng.common,t.rxjs.operators)}(this,(function(t,e,n,r){"use strict";
/**
* @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
*/var o,i=function(){function t(){this._focusTrapStack=[]}return t.prototype.register=function(t){this._focusTrapStack=this._focusTrapStack.filter((function(e){return e!==t}));var e=this._focusTrapStack;e.length&&e[e.length-1]._disable(),e.push(t),t._enable()},t.prototype.deregister=function(t){t._disable();var e=this._focusTrapStack,n=e.indexOf(t);-1!==n&&(e.splice(n,1),e.length&&e[e.length-1]._enable())},t}();i.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new i},token:i,providedIn:"root"}),i.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}];try{o="undefined"!=typeof Intl&&Intl.v8BreakIterator}catch(t){o=!1}var s=function(t){this._platformId=t,this.isBrowser=this._platformId?n.isPlatformBrowser(this._platformId):"object"==typeof document&&!!document,this.EDGE=this.isBrowser&&/(edge)/i.test(navigator.userAgent),this.TRIDENT=this.isBrowser&&/(msie|trident)/i.test(navigator.userAgent),this.BLINK=this.isBrowser&&!(!window.chrome&&!o)&&"undefined"!=typeof CSS&&!this.EDGE&&!this.TRIDENT,this.WEBKIT=this.isBrowser&&/AppleWebKit/i.test(navigator.userAgent)&&!this.BLINK&&!this.EDGE&&!this.TRIDENT,this.IOS=this.isBrowser&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window),this.FIREFOX=this.isBrowser&&/(firefox|minefield)/i.test(navigator.userAgent),this.ANDROID=this.isBrowser&&/android/i.test(navigator.userAgent)&&!this.TRIDENT,this.SAFARI=this.isBrowser&&/safari/i.test(navigator.userAgent)&&this.WEBKIT};s.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new s(e.ɵɵinject(e.PLATFORM_ID))},token:s,providedIn:"root"}),s.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],s.ctorParameters=function(){return[{type:Object,decorators:[{type:e.Inject,args:[e.PLATFORM_ID]}]}]};
/**
* @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
*/
var a=function(){function t(t){this._platform=t}return t.prototype.isDisabled=function(t){return t.hasAttribute("disabled")},t.prototype.isVisible=function(t){return function(t){return!!(t.offsetWidth||t.offsetHeight||"function"==typeof t.getClientRects&&t.getClientRects().length)}(t)&&"visible"===getComputedStyle(t).visibility},t.prototype.isTabbable=function(t){if(!this._platform.isBrowser)return!1;var e,n=function(t){try{return t.frameElement}catch(t){return null}}((e=t).ownerDocument&&e.ownerDocument.defaultView||window);if(n){if(-1===u(n))return!1;if(!this.isVisible(n))return!1}var r=t.nodeName.toLowerCase(),o=u(t);return t.hasAttribute("contenteditable")?-1!==o:"iframe"!==r&&"object"!==r&&(!(this._platform.WEBKIT&&this._platform.IOS&&!function(t){var e=t.nodeName.toLowerCase(),n="input"===e&&t.type;return"text"===n||"password"===n||"select"===e||"textarea"===e}(t))&&("audio"===r?!!t.hasAttribute("controls")&&-1!==o:"video"===r?-1!==o&&(null!==o||(this._platform.FIREFOX||t.hasAttribute("controls"))):t.tabIndex>=0))},t.prototype.isFocusable=function(t,e){return function(t){if(function(t){return function(t){return"input"==t.nodeName.toLowerCase()}(t)&&"hidden"==t.type}(t))return!1;return function(t){var e=t.nodeName.toLowerCase();return"input"===e||"select"===e||"button"===e||"textarea"===e}(t)||function(t){return function(t){return"a"==t.nodeName.toLowerCase()}(t)&&t.hasAttribute("href")}(t)||t.hasAttribute("contenteditable")||c(t)}(t)&&!this.isDisabled(t)&&((null==e?void 0:e.ignoreVisibility)||this.isVisible(t))},t}();function c(t){if(!t.hasAttribute("tabindex")||void 0===t.tabIndex)return!1;var e=t.getAttribute("tabindex");return"-32768"!=e&&!(!e||isNaN(parseInt(e,10)))}function u(t){if(!c(t))return null;var e=parseInt(t.getAttribute("tabindex")||"",10);return isNaN(e)?-1:e}
/**
* @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
*/
function h(t){return null!=t&&""+t!="false"}
/**
* @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
*/a.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new a(e.ɵɵinject(s))},token:a,providedIn:"root"}),a.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],a.ctorParameters=function(){return[{type:s}]};var d=function(){function t(t,e,n,r,o){var i=this;void 0===o&&(o=!1),this._element=t,this._checker=e,this._ngZone=n,this._document=r,this._hasAttached=!1,this.startAnchorListener=function(){return i.focusLastTabbableElement()},this.endAnchorListener=function(){return i.focusFirstTabbableElement()},this._enabled=!0,o||this.attachAnchors()}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this._enabled=t,this._startAnchor&&this._endAnchor&&(this._toggleAnchorTabIndex(t,this._startAnchor),this._toggleAnchorTabIndex(t,this._endAnchor))},enumerable:!1,configurable:!0}),t.prototype.destroy=function(){var t=this._startAnchor,e=this._endAnchor;t&&(t.removeEventListener("focus",this.startAnchorListener),t.parentNode&&t.parentNode.removeChild(t)),e&&(e.removeEventListener("focus",this.endAnchorListener),e.parentNode&&e.parentNode.removeChild(e)),this._startAnchor=this._endAnchor=null,this._hasAttached=!1},t.prototype.attachAnchors=function(){var t=this;return!!this._hasAttached||(this._ngZone.runOutsideAngular((function(){t._startAnchor||(t._startAnchor=t._createAnchor(),t._startAnchor.addEventListener("focus",t.startAnchorListener)),t._endAnchor||(t._endAnchor=t._createAnchor(),t._endAnchor.addEventListener("focus",t.endAnchorListener))})),this._element.parentNode&&(this._element.parentNode.insertBefore(this._startAnchor,this._element),this._element.parentNode.insertBefore(this._endAnchor,this._element.nextSibling),this._hasAttached=!0),this._hasAttached)},t.prototype.focusInitialElementWhenReady=function(){var t=this;return new Promise((function(e){t._executeOnStable((function(){return e(t.focusInitialElement())}))}))},t.prototype.focusFirstTabbableElementWhenReady=function(){var t=this;return new Promise((function(e){t._executeOnStable((function(){return e(t.focusFirstTabbableElement())}))}))},t.prototype.focusLastTabbableElementWhenReady=function(){var t=this;return new Promise((function(e){t._executeOnStable((function(){return e(t.focusLastTabbableElement())}))}))},t.prototype._getRegionBoundary=function(t){for(var e=this._element.querySelectorAll("[cdk-focus-region-"+t+"], [cdkFocusRegion"+t+"], [cdk-focus-"+t+"]"),n=0;n<e.length;n++)e[n].hasAttribute("cdk-focus-"+t)?console.warn("Found use of deprecated attribute 'cdk-focus-"+t+"', use 'cdkFocusRegion"+t+"' instead. The deprecated attribute will be removed in 8.0.0.",e[n]):e[n].hasAttribute("cdk-focus-region-"+t)&&console.warn("Found use of deprecated attribute 'cdk-focus-region-"+t+"', use 'cdkFocusRegion"+t+"' instead. The deprecated attribute will be removed in 8.0.0.",e[n]);return"start"==t?e.length?e[0]:this._getFirstTabbableElement(this._element):e.length?e[e.length-1]:this._getLastTabbableElement(this._element)},t.prototype.focusInitialElement=function(){var t=this._element.querySelector("[cdk-focus-initial], [cdkFocusInitial]");if(t){if(t.hasAttribute("cdk-focus-initial")&&console.warn("Found use of deprecated attribute 'cdk-focus-initial', use 'cdkFocusInitial' instead. The deprecated attribute will be removed in 8.0.0",t),!this._checker.isFocusable(t)){var e=this._getFirstTabbableElement(t);return null==e||e.focus(),!!e}return t.focus(),!0}return this.focusFirstTabbableElement()},t.prototype.focusFirstTabbableElement=function(){var t=this._getRegionBoundary("start");return t&&t.focus(),!!t},t.prototype.focusLastTabbableElement=function(){var t=this._getRegionBoundary("end");return t&&t.focus(),!!t},t.prototype.hasAttached=function(){return this._hasAttached},t.prototype._getFirstTabbableElement=function(t){if(this._checker.isFocusable(t)&&this._checker.isTabbable(t))return t;for(var e=t.children||t.childNodes,n=0;n<e.length;n++){var r=e[n].nodeType===this._document.ELEMENT_NODE?this._getFirstTabbableElement(e[n]):null;if(r)return r}return null},t.prototype._getLastTabbableElement=function(t){if(this._checker.isFocusable(t)&&this._checker.isTabbable(t))return t;for(var e=t.children||t.childNodes,n=e.length-1;n>=0;n--){var r=e[n].nodeType===this._document.ELEMENT_NODE?this._getLastTabbableElement(e[n]):null;if(r)return r}return null},t.prototype._createAnchor=function(){var t=this._document.createElement("div");return this._toggleAnchorTabIndex(this._enabled,t),t.classList.add("cdk-visually-hidden"),t.classList.add("cdk-focus-trap-anchor"),t.setAttribute("aria-hidden","true"),t},t.prototype._toggleAnchorTabIndex=function(t,e){t?e.setAttribute("tabindex","0"):e.removeAttribute("tabindex")},t.prototype.toggleAnchors=function(t){this._startAnchor&&this._endAnchor&&(this._toggleAnchorTabIndex(t,this._startAnchor),this._toggleAnchorTabIndex(t,this._endAnchor))},t.prototype._executeOnStable=function(t){this._ngZone.isStable?t():this._ngZone.onStable.pipe(r.take(1)).subscribe(t)},t}(),l=function(){function t(t,e,n){this._checker=t,this._ngZone=e,this._document=n}return t.prototype.create=function(t,e){return void 0===e&&(e=!1),new d(t,this._checker,this._ngZone,this._document,e)},t}();l.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new l(e.ɵɵinject(a),e.ɵɵinject(e.NgZone),e.ɵɵinject(n.DOCUMENT))},token:l,providedIn:"root"}),l.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],l.ctorParameters=function(){return[{type:a},{type:e.NgZone},{type:void 0,decorators:[{type:e.Inject,args:[n.DOCUMENT]}]}]};var f=function(){function t(t,e,n){this._elementRef=t,this._focusTrapFactory=e,this._previouslyFocusedElement=null,this._autoCapture=!1,this._document=n,this.focusTrap=this._focusTrapFactory.create(this._elementRef.nativeElement,!0)}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this.focusTrap.enabled},set:function(t){this.focusTrap.enabled=h(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"autoCapture",{get:function(){return this._autoCapture},set:function(t){this._autoCapture=h(t)},enumerable:!1,configurable:!0}),t.prototype.ngOnDestroy=function(){this.focusTrap.destroy(),this._previouslyFocusedElement&&(this._previouslyFocusedElement.focus(),this._previouslyFocusedElement=null)},t.prototype.ngAfterContentInit=function(){this.focusTrap.attachAnchors(),this.autoCapture&&this._captureFocus()},t.prototype.ngDoCheck=function(){this.focusTrap.hasAttached()||this.focusTrap.attachAnchors()},t.prototype.ngOnChanges=function(t){var e=t.autoCapture;e&&!e.firstChange&&this.autoCapture&&this.focusTrap.hasAttached()&&this._captureFocus()},t.prototype._captureFocus=function(){this._previouslyFocusedElement=this._document.activeElement,this.focusTrap.focusInitialElementWhenReady()},t}();f.decorators=[{type:e.Directive,args:[{selector:"[focusTrap]",exportAs:"focusTrap"}]}],f.ctorParameters=function(){return[{type:e.ElementRef},{type:l},{type:void 0,decorators:[{type:e.Inject,args:[n.DOCUMENT]}]}]},f.propDecorators={enabled:[{type:e.Input,args:["cdkTrapFocus"]}],autoCapture:[{type:e.Input,args:["cdkTrapFocusAutoCapture"]}]};var p=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[i,s,a]}},t}();p.decorators=[{type:e.NgModule,args:[{imports:[n.CommonModule],declarations:[f],exports:[f]}]}],t.FocusTrap=d,t.FocusTrapDirective=f,t.FocusTrapModule=p,t.ɵa=l,t.ɵb=a,t.ɵc=s,t.ɵd=i,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-bootstrap-focus-trap.umd.min.js.map