/**
 * @license
 * Copyright 2016 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
(() => {
  var E, m, N;
  const l = Symbol(), g = Symbol(), I = Symbol(), v = Symbol(), S = Symbol(), T = Symbol(), u = Symbol(), t = Symbol(), e = Symbol(), i = Symbol(), r = Symbol(), a = Symbol(), c = Symbol();
  class _ {
    constructor() {
      this[E] = [], this[m] = [], this[N] = /* @__PURE__ */ new Set();
    }
    destructor() {
      this[e](this[I]);
      const n = this;
      n[l] = null, n[I] = null, n[g] = null;
    }
    get top() {
      const n = this[l];
      return n[n.length - 1] || null;
    }
    push(n) {
      !n || n === this.top || (this.remove(n), this[T](n), this[l].push(n));
    }
    remove(n) {
      const o = this[l].indexOf(n);
      return o === -1 ? !1 : (this[l].splice(o, 1), o === this[l].length && this[T](this.top), !0);
    }
    pop() {
      const n = this.top;
      return n && this.remove(n), n;
    }
    has(n) {
      return this[l].indexOf(n) !== -1;
    }
    /**
     * Sets `inert` to all document elements except the new top element, its
     * parents, and its distributed content.
     */
    [(E = l, m = I, N = g, T)](n) {
      const o = this[g], s = this[I];
      if (!n) {
        this[e](s), o.clear(), this[I] = [];
        return;
      }
      const d = this[i](n);
      if (d[d.length - 1].parentNode !== document.body)
        throw Error("Non-connected element cannot be a blocking element");
      this[I] = d;
      const b = this[r](n);
      if (!s.length) {
        this[t](d, b, o);
        return;
      }
      let f = s.length - 1, h = d.length - 1;
      for (; f > 0 && h > 0 && s[f] === d[h]; )
        f--, h--;
      s[f] !== d[h] && this[u](s[f], d[h]), f > 0 && this[e](s.slice(0, f)), h > 0 && this[t](d.slice(0, h), b, null);
    }
    /**
     * Swaps inertness between two sibling elements.
     * Sets the property `inert` over the attribute since the inert spec
     * doesn't specify if it should be reflected.
     * https://html.spec.whatwg.org/multipage/interaction.html#inert
     */
    [u](n, o) {
      const s = n[v];
      this[a](n) && !n.inert && (n.inert = !0, s.add(n)), s.has(o) && (o.inert = !1, s.delete(o)), o[S] = n[S], o[v] = s, n[S] = void 0, n[v] = void 0;
    }
    /**
     * Restores original inertness to the siblings of the elements.
     * Sets the property `inert` over the attribute since the inert spec
     * doesn't specify if it should be reflected.
     * https://html.spec.whatwg.org/multipage/interaction.html#inert
     */
    [e](n) {
      for (const o of n) {
        o[S].disconnect(), o[S] = void 0;
        const d = o[v];
        for (const b of d)
          b.inert = !1;
        o[v] = void 0;
      }
    }
    /**
     * Inerts the siblings of the elements except the elements to skip. Stores
     * the inerted siblings into the element's symbol `_siblingsToRestore`.
     * Pass `toKeepInert` to collect the already inert elements.
     * Sets the property `inert` over the attribute since the inert spec
     * doesn't specify if it should be reflected.
     * https://html.spec.whatwg.org/multipage/interaction.html#inert
     */
    [t](n, o, s) {
      for (const d of n) {
        const b = d.parentNode, f = b.children, h = /* @__PURE__ */ new Set();
        for (let R = 0; R < f.length; R++) {
          const M = f[R];
          M === d || !this[a](M) || o && o.has(M) || (s && M.inert ? s.add(M) : (M.inert = !0, h.add(M)));
        }
        d[v] = h;
        const k = new MutationObserver(this[c].bind(this));
        d[S] = k;
        let p = b;
        const y = p;
        y.__shady && y.host && (p = y.host), k.observe(p, {
          childList: !0
        });
      }
    }
    /**
     * Handles newly added/removed nodes by toggling their inertness.
     * It also checks if the current top Blocking Element has been removed,
     * notifying and removing it.
     */
    [c](n) {
      const o = this[I], s = this[g];
      for (const d of n) {
        const b = d.target.host || d.target, f = b === document.body ? o.length : o.indexOf(b), h = o[f - 1], k = h[v];
        for (let p = 0; p < d.removedNodes.length; p++) {
          const y = d.removedNodes[p];
          if (y === h) {
            console.info("Detected removal of the top Blocking Element."), this.pop();
            return;
          }
          k.has(y) && (y.inert = !1, k.delete(y));
        }
        for (let p = 0; p < d.addedNodes.length; p++) {
          const y = d.addedNodes[p];
          this[a](y) && (s && y.inert ? s.add(y) : (y.inert = !0, k.add(y)));
        }
      }
    }
    /**
     * Returns if the element is inertable.
     */
    [a](n) {
      return /^(style|template|script)$/.test(n.localName) === !1;
    }
    /**
     * Returns the list of newParents of an element, starting from element
     * (included) up to `document.body` (excluded).
     */
    [i](n) {
      const o = [];
      let s = n;
      for (; s && s !== document.body; ) {
        if (s.nodeType === Node.ELEMENT_NODE && o.push(s), s.assignedSlot) {
          for (; s = s.assignedSlot; )
            o.push(s);
          s = o.pop();
          continue;
        }
        s = s.parentNode || s.host;
      }
      return o;
    }
    /**
     * Returns the distributed children of the element's shadow root.
     * Returns null if the element doesn't have a shadow root.
     */
    [r](n) {
      const o = n.shadowRoot;
      if (!o)
        return null;
      const s = /* @__PURE__ */ new Set();
      let d, b, f;
      const h = o.querySelectorAll("slot");
      if (h.length && h[0].assignedNodes)
        for (d = 0; d < h.length; d++)
          for (f = h[d].assignedNodes({
            flatten: !0
          }), b = 0; b < f.length; b++)
            f[b].nodeType === Node.ELEMENT_NODE && s.add(f[b]);
      return s;
    }
  }
  document.$blockingElements = new _();
})();
var A = /* @__PURE__ */ function() {
  function E(m, N) {
    for (var l = 0; l < N.length; l++) {
      var g = N[l];
      g.enumerable = g.enumerable || !1, g.configurable = !0, "value" in g && (g.writable = !0), Object.defineProperty(m, g.key, g);
    }
  }
  return function(m, N, l) {
    return N && E(m.prototype, N), l && E(m, l), m;
  };
}();
function x(E, m) {
  if (!(E instanceof m))
    throw new TypeError("Cannot call a class as a function");
}
(function() {
  if (typeof window > "u" || typeof Element > "u")
    return;
  var E = Array.prototype.slice, m = Element.prototype.matches || Element.prototype.msMatchesSelector, N = ["a[href]", "area[href]", "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])", "button:not([disabled])", "details", "summary", "iframe", "object", "embed", "video", "[contenteditable]"].join(","), l = function() {
    function u(t, e) {
      x(this, u), this._inertManager = e, this._rootElement = t, this._managedNodes = /* @__PURE__ */ new Set(), this._rootElement.hasAttribute("aria-hidden") ? this._savedAriaHidden = this._rootElement.getAttribute("aria-hidden") : this._savedAriaHidden = null, this._rootElement.setAttribute("aria-hidden", "true"), this._makeSubtreeUnfocusable(this._rootElement), this._observer = new MutationObserver(this._onMutation.bind(this)), this._observer.observe(this._rootElement, { attributes: !0, childList: !0, subtree: !0 });
    }
    return A(u, [{
      key: "destructor",
      value: function() {
        this._observer.disconnect(), this._rootElement && (this._savedAriaHidden !== null ? this._rootElement.setAttribute("aria-hidden", this._savedAriaHidden) : this._rootElement.removeAttribute("aria-hidden")), this._managedNodes.forEach(function(e) {
          this._unmanageNode(e.node);
        }, this), this._observer = /** @type {?} */
        null, this._rootElement = /** @type {?} */
        null, this._managedNodes = /** @type {?} */
        null, this._inertManager = /** @type {?} */
        null;
      }
      /**
       * @return {!Set<!InertNode>} A copy of this InertRoot's managed nodes set.
       */
    }, {
      key: "_makeSubtreeUnfocusable",
      /**
       * @param {!Node} startNode
       */
      value: function(e) {
        var i = this;
        v(e, function(_) {
          return i._visitNode(_);
        });
        var r = document.activeElement;
        if (!document.body.contains(e)) {
          for (var a = e, c = void 0; a; ) {
            if (a.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
              c = /** @type {!ShadowRoot} */
              a;
              break;
            }
            a = a.parentNode;
          }
          c && (r = c.activeElement);
        }
        e.contains(r) && (r.blur(), r === document.activeElement && document.body.focus());
      }
      /**
       * @param {!Node} node
       */
    }, {
      key: "_visitNode",
      value: function(e) {
        if (e.nodeType === Node.ELEMENT_NODE) {
          var i = (
            /** @type {!HTMLElement} */
            e
          );
          i !== this._rootElement && i.hasAttribute("inert") && this._adoptInertRoot(i), (m.call(i, N) || i.hasAttribute("tabindex")) && this._manageNode(i);
        }
      }
      /**
       * Register the given node with this InertRoot and with InertManager.
       * @param {!Node} node
       */
    }, {
      key: "_manageNode",
      value: function(e) {
        var i = this._inertManager.register(e, this);
        this._managedNodes.add(i);
      }
      /**
       * Unregister the given node with this InertRoot and with InertManager.
       * @param {!Node} node
       */
    }, {
      key: "_unmanageNode",
      value: function(e) {
        var i = this._inertManager.deregister(e, this);
        i && this._managedNodes.delete(i);
      }
      /**
       * Unregister the entire subtree starting at `startNode`.
       * @param {!Node} startNode
       */
    }, {
      key: "_unmanageSubtree",
      value: function(e) {
        var i = this;
        v(e, function(r) {
          return i._unmanageNode(r);
        });
      }
      /**
       * If a descendant node is found with an `inert` attribute, adopt its managed nodes.
       * @param {!HTMLElement} node
       */
    }, {
      key: "_adoptInertRoot",
      value: function(e) {
        var i = this._inertManager.getInertRoot(e);
        i || (this._inertManager.setInert(e, !0), i = this._inertManager.getInertRoot(e)), i.managedNodes.forEach(function(r) {
          this._manageNode(r.node);
        }, this);
      }
      /**
       * Callback used when mutation observer detects subtree additions, removals, or attribute changes.
       * @param {!Array<!MutationRecord>} records
       * @param {!MutationObserver} self
       */
    }, {
      key: "_onMutation",
      value: function(e, i) {
        e.forEach(function(r) {
          var a = (
            /** @type {!HTMLElement} */
            r.target
          );
          if (r.type === "childList")
            E.call(r.addedNodes).forEach(function(_) {
              this._makeSubtreeUnfocusable(_);
            }, this), E.call(r.removedNodes).forEach(function(_) {
              this._unmanageSubtree(_);
            }, this);
          else if (r.type === "attributes") {
            if (r.attributeName === "tabindex")
              this._manageNode(a);
            else if (a !== this._rootElement && r.attributeName === "inert" && a.hasAttribute("inert")) {
              this._adoptInertRoot(a);
              var c = this._inertManager.getInertRoot(a);
              this._managedNodes.forEach(function(_) {
                a.contains(_.node) && c._manageNode(_.node);
              });
            }
          }
        }, this);
      }
    }, {
      key: "managedNodes",
      get: function() {
        return new Set(this._managedNodes);
      }
      /** @return {boolean} */
    }, {
      key: "hasSavedAriaHidden",
      get: function() {
        return this._savedAriaHidden !== null;
      }
      /** @param {?string} ariaHidden */
    }, {
      key: "savedAriaHidden",
      set: function(e) {
        this._savedAriaHidden = e;
      },
      get: function() {
        return this._savedAriaHidden;
      }
    }]), u;
  }(), g = function() {
    function u(t, e) {
      x(this, u), this._node = t, this._overrodeFocusMethod = !1, this._inertRoots = /* @__PURE__ */ new Set([e]), this._savedTabIndex = null, this._destroyed = !1, this.ensureUntabbable();
    }
    return A(u, [{
      key: "destructor",
      value: function() {
        if (this._throwIfDestroyed(), this._node && this._node.nodeType === Node.ELEMENT_NODE) {
          var e = (
            /** @type {!HTMLElement} */
            this._node
          );
          this._savedTabIndex !== null ? e.setAttribute("tabindex", this._savedTabIndex) : e.removeAttribute("tabindex"), this._overrodeFocusMethod && delete e.focus;
        }
        this._node = /** @type {?} */
        null, this._inertRoots = /** @type {?} */
        null, this._destroyed = !0;
      }
      /**
       * @type {boolean} Whether this object is obsolete because the managed node is no longer inert.
       * If the object has been destroyed, any attempt to access it will cause an exception.
       */
    }, {
      key: "_throwIfDestroyed",
      /**
       * Throw if user tries to access destroyed InertNode.
       */
      value: function() {
        if (this.destroyed)
          throw new Error("Trying to access destroyed InertNode");
      }
      /** @return {boolean} */
    }, {
      key: "ensureUntabbable",
      /** Save the existing tabindex value and make the node untabbable and unfocusable */
      value: function() {
        if (this.node.nodeType === Node.ELEMENT_NODE) {
          var e = (
            /** @type {!HTMLElement} */
            this.node
          );
          if (m.call(e, N)) {
            if (
              /** @type {!HTMLElement} */
              e.tabIndex === -1 && this.hasSavedTabIndex
            )
              return;
            e.hasAttribute("tabindex") && (this._savedTabIndex = /** @type {!HTMLElement} */
            e.tabIndex), e.setAttribute("tabindex", "-1"), e.nodeType === Node.ELEMENT_NODE && (e.focus = function() {
            }, this._overrodeFocusMethod = !0);
          } else e.hasAttribute("tabindex") && (this._savedTabIndex = /** @type {!HTMLElement} */
          e.tabIndex, e.removeAttribute("tabindex"));
        }
      }
      /**
       * Add another inert root to this inert node's set of managing inert roots.
       * @param {!InertRoot} inertRoot
       */
    }, {
      key: "addInertRoot",
      value: function(e) {
        this._throwIfDestroyed(), this._inertRoots.add(e);
      }
      /**
       * Remove the given inert root from this inert node's set of managing inert roots.
       * If the set of managing inert roots becomes empty, this node is no longer inert,
       * so the object should be destroyed.
       * @param {!InertRoot} inertRoot
       */
    }, {
      key: "removeInertRoot",
      value: function(e) {
        this._throwIfDestroyed(), this._inertRoots.delete(e), this._inertRoots.size === 0 && this.destructor();
      }
    }, {
      key: "destroyed",
      get: function() {
        return (
          /** @type {!InertNode} */
          this._destroyed
        );
      }
    }, {
      key: "hasSavedTabIndex",
      get: function() {
        return this._savedTabIndex !== null;
      }
      /** @return {!Node} */
    }, {
      key: "node",
      get: function() {
        return this._throwIfDestroyed(), this._node;
      }
      /** @param {?number} tabIndex */
    }, {
      key: "savedTabIndex",
      set: function(e) {
        this._throwIfDestroyed(), this._savedTabIndex = e;
      },
      get: function() {
        return this._throwIfDestroyed(), this._savedTabIndex;
      }
    }]), u;
  }(), I = function() {
    function u(t) {
      if (x(this, u), !t)
        throw new Error("Missing required argument; InertManager needs to wrap a document.");
      this._document = t, this._managedNodes = /* @__PURE__ */ new Map(), this._inertRoots = /* @__PURE__ */ new Map(), this._observer = new MutationObserver(this._watchForInert.bind(this)), S(t.head || t.body || t.documentElement), t.readyState === "loading" ? t.addEventListener("DOMContentLoaded", this._onDocumentLoaded.bind(this)) : this._onDocumentLoaded();
    }
    return A(u, [{
      key: "setInert",
      value: function(e, i) {
        if (i) {
          if (this._inertRoots.has(e))
            return;
          var r = new l(e, this);
          if (e.setAttribute("inert", ""), this._inertRoots.set(e, r), !this._document.body.contains(e))
            for (var a = e.parentNode; a; )
              a.nodeType === 11 && S(a), a = a.parentNode;
        } else {
          if (!this._inertRoots.has(e))
            return;
          var c = this._inertRoots.get(e);
          c.destructor(), this._inertRoots.delete(e), e.removeAttribute("inert");
        }
      }
      /**
       * Get the InertRoot object corresponding to the given inert root element, if any.
       * @param {!Node} element
       * @return {!InertRoot|undefined}
       */
    }, {
      key: "getInertRoot",
      value: function(e) {
        return this._inertRoots.get(e);
      }
      /**
       * Register the given InertRoot as managing the given node.
       * In the case where the node has a previously existing inert root, this inert root will
       * be added to its set of inert roots.
       * @param {!Node} node
       * @param {!InertRoot} inertRoot
       * @return {!InertNode} inertNode
       */
    }, {
      key: "register",
      value: function(e, i) {
        var r = this._managedNodes.get(e);
        return r !== void 0 ? r.addInertRoot(i) : r = new g(e, i), this._managedNodes.set(e, r), r;
      }
      /**
       * De-register the given InertRoot as managing the given inert node.
       * Removes the inert root from the InertNode's set of managing inert roots, and remove the inert
       * node from the InertManager's set of managed nodes if it is destroyed.
       * If the node is not currently managed, this is essentially a no-op.
       * @param {!Node} node
       * @param {!InertRoot} inertRoot
       * @return {?InertNode} The potentially destroyed InertNode associated with this node, if any.
       */
    }, {
      key: "deregister",
      value: function(e, i) {
        var r = this._managedNodes.get(e);
        return r ? (r.removeInertRoot(i), r.destroyed && this._managedNodes.delete(e), r) : null;
      }
      /**
       * Callback used when document has finished loading.
       */
    }, {
      key: "_onDocumentLoaded",
      value: function() {
        var e = E.call(this._document.querySelectorAll("[inert]"));
        e.forEach(function(i) {
          this.setInert(i, !0);
        }, this), this._observer.observe(this._document.body || this._document.documentElement, { attributes: !0, subtree: !0, childList: !0 });
      }
      /**
       * Callback used when mutation observer detects attribute changes.
       * @param {!Array<!MutationRecord>} records
       * @param {!MutationObserver} self
       */
    }, {
      key: "_watchForInert",
      value: function(e, i) {
        var r = this;
        e.forEach(function(a) {
          switch (a.type) {
            case "childList":
              E.call(a.addedNodes).forEach(function(w) {
                if (w.nodeType === Node.ELEMENT_NODE) {
                  var n = E.call(w.querySelectorAll("[inert]"));
                  m.call(w, "[inert]") && n.unshift(w), n.forEach(function(o) {
                    this.setInert(o, !0);
                  }, r);
                }
              }, r);
              break;
            case "attributes":
              if (a.attributeName !== "inert")
                return;
              var c = (
                /** @type {!HTMLElement} */
                a.target
              ), _ = c.hasAttribute("inert");
              r.setInert(c, _);
              break;
          }
        }, this);
      }
    }]), u;
  }();
  function v(u, t, e) {
    if (u.nodeType == Node.ELEMENT_NODE) {
      var i = (
        /** @type {!HTMLElement} */
        u
      );
      t && t(i);
      var r = (
        /** @type {!HTMLElement} */
        i.shadowRoot
      );
      if (r) {
        v(r, t);
        return;
      }
      if (i.localName == "content") {
        for (var a = (
          /** @type {!HTMLContentElement} */
          i
        ), c = a.getDistributedNodes ? a.getDistributedNodes() : [], _ = 0; _ < c.length; _++)
          v(c[_], t);
        return;
      }
      if (i.localName == "slot") {
        for (var w = (
          /** @type {!HTMLSlotElement} */
          i
        ), n = w.assignedNodes ? w.assignedNodes({ flatten: !0 }) : [], o = 0; o < n.length; o++)
          v(n[o], t);
        return;
      }
    }
    for (var s = u.firstChild; s != null; )
      v(s, t), s = s.nextSibling;
  }
  function S(u) {
    if (!u.querySelector("style#inert-style, link#inert-style")) {
      var t = document.createElement("style");
      t.setAttribute("id", "inert-style"), t.textContent = `
[inert] {
  pointer-events: none;
  cursor: default;
}

[inert], [inert] * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
`, u.appendChild(t);
    }
  }
  if (!HTMLElement.prototype.hasOwnProperty("inert")) {
    var T = new I(document);
    Object.defineProperty(HTMLElement.prototype, "inert", {
      enumerable: !0,
      /** @this {!HTMLElement} */
      get: function() {
        return this.hasAttribute("inert");
      },
      /** @this {!HTMLElement} */
      set: function(t) {
        T.setInert(this, t);
      }
    });
  }
})();
