text: define(["exports","../polymer/polymer-legacy.js","./iron-overlay-backdrop.js","../iron-a11y-keys-behavior/iron-a11y-keys-behavior.js","../polymer/lib/legacy/polymer.dom.js","../polymer/lib/utils/gestures.js"],(function(e,r,t,a,s,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.IronOverlayManager=e.IronOverlayManagerClass=void 0,o=babelHelpers.interopRequireWildcard(o);
  /**
    @license
    Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
    This code may only be used under the BSD style license found at
    http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
    http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
    found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
    part of the polymer project is also subject to an additional IP rights grant
    found at http://polymer.github.io/PATENTS.txt
    */
  class IronOverlayManagerClass{constructor(){this._overlays=[],this._minimumZ=101,this._backdropElement=null,o.addListener(document.documentElement,"tap",(function(){})),document.addEventListener("tap",this._onCaptureClick.bind(this),!0),document.addEventListener("focus",this._onCaptureFocus.bind(this),!0),document.addEventListener("keydown",this._onCaptureKeyDown.bind(this),!0)}get backdropElement(){return this._backdropElement||(this._backdropElement=document.createElement("iron-overlay-backdrop")),this._backdropElement}get deepActiveElement(){var e=document.activeElement;for(e&&e instanceof Element!=!1||(e=document.body);e.root&&(0,s.dom)(e.root).activeElement;)e=(0,s.dom)(e.root).activeElement;return e}_bringOverlayAtIndexToFront(e){var r=this._overlays[e];if(r){var t=this._overlays.length-1,a=this._overlays[t];if(a&&this._shouldBeBehindOverlay(r,a)&&t--,!(e>=t)){var s=Math.max(this.currentOverlayZ(),this._minimumZ);for(this._getZ(r)<=s&&this._applyOverlayZ(r,s);e<t;)this._overlays[e]=this._overlays[e+1],e++;this._overlays[t]=r}}}addOrRemoveOverlay(e){e.opened?this.addOverlay(e):this.removeOverlay(e)}addOverlay(e){var r=this._overlays.indexOf(e);if(r>=0)return this._bringOverlayAtIndexToFront(r),void this.trackBackdrop();var t=this._overlays.length,a=this._overlays[t-1],s=Math.max(this._getZ(a),this._minimumZ),o=this._getZ(e);if(a&&this._shouldBeBehindOverlay(e,a)){this._applyOverlayZ(a,s),t--;var i=this._overlays[t-1];s=Math.max(this._getZ(i),this._minimumZ)}o<=s&&this._applyOverlayZ(e,s),this._overlays.splice(t,0,e),this.trackBackdrop()}removeOverlay(e){var r=this._overlays.indexOf(e);-1!==r&&(this._overlays.splice(r,1),this.trackBackdrop())}currentOverlay(){var e=this._overlays.length-1;return this._overlays[e]}currentOverlayZ(){return this._getZ(this.currentOverlay())}ensureMinimumZ(e){this._minimumZ=Math.max(this._minimumZ,e)}focusOverlay(){var e=this.currentOverlay();e&&e._applyFocus()}trackBackdrop(){var e=this._overlayWithBackdrop();(e||this._backdropElement)&&(this.backdropElement.style.zIndex=this._getZ(e)-1,this.backdropElement.opened=!!e,this.backdropElement.prepare())}getBackdrops(){for(var e=[],r=0;r<this._overlays.length;r++)this._overlays[r].withBackdrop&&e.push(this._overlays[r]);return e}backdropZ(){return this._getZ(this._overlayWithBackdrop())-1}_overlayWithBackdrop(){for(var e=this._overlays.length-1;e>=0;e--)if(this._overlays[e].withBackdrop)return this._overlays[e]}_getZ(e){var r=this._minimumZ;if(e){var t=Number(e.style.zIndex||window.getComputedStyle(e).zIndex);t==t&&(r=t)}return r}_setZ(e,r){e.style.zIndex=r}_applyOverlayZ(e,r){this._setZ(e,r+2)}_overlayInPath(e){e=e||[];for(var r=0;r<e.length;r++)if(e[r]._manager===this)return e[r]}_onCaptureClick(e){var r=this._overlays.length-1;if(-1!==r)for(var t,a=(0,s.dom)(e).path;(t=this._overlays[r])&&this._overlayInPath(a)!==t&&(t._onCaptureClick(e),t.allowClickThrough);)r--}_onCaptureFocus(e){var r=this.currentOverlay();r&&r._onCaptureFocus(e)}_onCaptureKeyDown(e){var r=this.currentOverlay();r&&(a.IronA11yKeysBehavior.keyboardEventMatchesKeys(e,"esc")?r._onCaptureEsc(e):a.IronA11yKeysBehavior.keyboardEventMatchesKeys(e,"tab")&&r._onCaptureTab(e))}_shouldBeBehindOverlay(e,r){return!e.alwaysOnTop&&r.alwaysOnTop}}e.IronOverlayManagerClass=IronOverlayManagerClass;const i=new IronOverlayManagerClass;e.IronOverlayManager=i}));