<commit_before>(function() {

  var supportCustomEvent = window.CustomEvent;
  if (!supportCustomEvent || typeof supportCustomEvent == 'object') {
    supportCustomEvent = function CustomEvent(event, x) {
      x = x || {};
      var ev = document.createEvent('CustomEvent');
      ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
      return ev;
    };
    supportCustomEvent.prototype = window.Event.prototype;
  }

  /**
   * Finds the nearest <dialog> from the passed element.
   *
   * @param {Element} el to search from
   * @return {HTMLDialogElement} dialog found
   */
  function findNearestDialog(el) {
    while (el) {
      if (el.nodeName == 'DIALOG') {
        return /** @type {HTMLDialogElement} */ (el);
      }
      el = el.parentElement;
    }
    return null;
  }

  /**
   * @param {!NodeList} nodeList to search
   * @param {Node} node to find
   * @return {boolean} whether node is inside nodeList
   */
  function inNodeList(nodeList, node) {
    for (var i = 0; i < nodeList.length; ++i) {
      if (nodeList[i] == node) {
        return true;
      }
    }
    return false;
  }

  /**
   * @param {!Element} dialog to upgrade
   * @constructor
   */
  function dialogPolyfillInfo(dialog) {
    this.dialog_ = dialog;
    this.open_ = dialog.hasAttribute('open');
    this.modal_ = false;
    this.replacedStyleTop_ = false;

    dialog.show = this.show.bind(this, false);
    dialog.showModal = this.show.bind(this, true);
    dialog.close = this.close.bind(this);

    Object.defineProperty(dialog, 'open', {
      set: this.setOpen.bind(this), get: this.getOpen.bind(this)
    });

    this.backdrop_ = document.createElement('div');
    this.backdrop_.className = 'backdrop';
    this.backdropClick_ = this.backdropClick_.bind(this);
  }

  dialogPolyfillInfo.prototype = {

    get dialog() {
      return this.dialog_;
    },

    /**
     * @param {boolean} value whether to open or close this dialog
     */
    setOpen: function(value) {
      if (value && !this.open_) {
        this.show(this.modal_);
      } else if (!value && this.open_) {
        this.close();
      }
    },

    /**
     * @return {boolean} whether this dialog is open
     */
    getOpen: function() {
      return this.open_;
    },

    /**
     * Handles clicks on the fake .backdrop element, redirecting them as if
     * they were on the dialog itself.
     *
     * @param {!Event} e to redirect
     */
    backdropClick_: function(e) {
      var redirectedEvent = document.createEvent('MouseEvents');
      redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window,
          e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey,
          e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
      this.dialog_.dispatchEvent(redirectedEvent);
      e.stopPropagation();
    },

    updateZIndex: function(dialogZ, backdropZ) {
      this.dialog_.style.zIndex = dialogZ;
      this.backdrop_.style.zIndex = backdropZ;
    },

    /**
     * Shows the dialog.
     *
     * @param {boolean} modal whether to display modal
     */
    show: function(modal) {
      if (this.open_) {
        if (modal) {
          throw 'Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.';
        }
        return;  // silently OK if we weren't asked to be shown modally
      }
      if (modal && !dialogPolyfill.dm.pushDialog(this)) {
        throw 'Failed to execute \'showModal\' on dialog: Too many modal dialogs open.';
      }

      this.open_ = true;
      this.modal_ = modal;
      this.dialog_.setAttribute('open', '');

      if (modal) {
        // Insert backdrop.
        this.backdrop_.addEventListener('click', this.backdropClick_);
        this.dialog_.parentNode.insertBefore(this.backdrop_,
            this.dialog_.nextSibling);

        // Find element with `autofocus` attribute or first form control.
        var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
        if (!target) {
          // TODO: technically this is 'any focusable area'
          var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
          var query = opts.map(function(el) {
            return el + ':not([disabled])';
          }).join(', ');
          target = this.dialog_.querySelector(query);
        }
        document.activeElement && document.activeElement.blur();
        target && target.focus();
      }

      if (dialogPolyfill.needsCentering(this.dialog_)) {
        dialogPolyfill.reposition(this.dialog_);
        this.replacedStyleTop_ = true;
      } else {
        this.replacedStyleTop_ = false;
      }
    },

    /**
     * Closes this HTMLDialogElement.
     *
     * @param {*=} opt_returnValue to use as the returnValue
     */
    close: function(opt_returnValue) {
      if (!this.open_) {
        throw 'InvalidStateError: close called on closed dialog';
      }
      this.open_ = false;
      this.dialog_.removeAttribute('open');

      // Leave returnValue untouched in case it was set directly on the element
      if (opt_returnValue !== undefined) {
        this.dialog_.returnValue = opt_returnValue;
      }

      // This won't match the native <dialog> exactly because if the user set
      // top on a centered polyfill dialog, that top gets thrown away when the
      // dialog is closed. Not sure it's possible to polyfill this perfectly.
      if (this.replacedStyleTop_) {
        this.dialog_.style.top = 'auto';
      }

      if (this.modal_) {<commit_msg>observe attribute changes where possible<commit_after>(function() {

  var supportCustomEvent = window.CustomEvent;
  if (!supportCustomEvent || typeof supportCustomEvent == 'object') {
    supportCustomEvent = function CustomEvent(event, x) {
      x = x || {};
      var ev = document.createEvent('CustomEvent');
      ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
      return ev;
    };
    supportCustomEvent.prototype = window.Event.prototype;
  }

  /**
   * Finds the nearest <dialog> from the passed element.
   *
   * @param {Element} el to search from
   * @return {HTMLDialogElement} dialog found
   */
  function findNearestDialog(el) {
    while (el) {
      if (el.nodeName == 'DIALOG') {
        return /** @type {HTMLDialogElement} */ (el);
      }
      el = el.parentElement;
    }
    return null;
  }

  /**
   * @param {!NodeList} nodeList to search
   * @param {Node} node to find
   * @return {boolean} whether node is inside nodeList
   */
  function inNodeList(nodeList, node) {
    for (var i = 0; i < nodeList.length; ++i) {
      if (nodeList[i] == node) {
        return true;
      }
    }
    return false;
  }

  /**
   * @param {!Element} dialog to upgrade
   * @constructor
   */
  function dialogPolyfillInfo(dialog) {
    this.dialog_ = dialog;
    this.open_ = dialog.hasAttribute('open');
    this.modal_ = false;
    this.replacedStyleTop_ = false;

    dialog.show = this.show.bind(this, false);
    dialog.showModal = this.show.bind(this, true);
    dialog.close = this.close.bind(this);

    if ('MutationObserver' in window) {
      var mo = new MutationObserver(function(mutations) {
        var any = mutations.some(function(m) {
          return 'open' == m.attributeName;
        });
        if (any) {
          this.setOpen(dialog.getAttribute('open') !== null);
        }
      }.bind(this));
      mo.observe(dialog, { attributes: true });
    }

    Object.defineProperty(dialog, 'open', {
      set: this.setOpen.bind(this), get: this.getOpen.bind(this)
    });

    this.backdrop_ = document.createElement('div');
    this.backdrop_.className = 'backdrop';
    this.backdropClick_ = this.backdropClick_.bind(this);
  }

  dialogPolyfillInfo.prototype = {

    get dialog() {
      return this.dialog_;
    },

    /**
     * @param {boolean} value whether to open or close this dialog
     */
    setOpen: function(value) {
      if (value && !this.open_) {
        this.show(this.modal_);
      } else if (!value && this.open_) {
        this.close();
      }
    },

    /**
     * @return {boolean} whether this dialog is open
     */
    getOpen: function() {
      return this.open_;
    },

    /**
     * Handles clicks on the fake .backdrop element, redirecting them as if
     * they were on the dialog itself.
     *
     * @param {!Event} e to redirect
     */
    backdropClick_: function(e) {
      var redirectedEvent = document.createEvent('MouseEvents');
      redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window,
          e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey,
          e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
      this.dialog_.dispatchEvent(redirectedEvent);
      e.stopPropagation();
    },

    updateZIndex: function(dialogZ, backdropZ) {
      this.dialog_.style.zIndex = dialogZ;
      this.backdrop_.style.zIndex = backdropZ;
    },

    /**
     * Shows the dialog.
     *
     * @param {boolean} modal whether to display modal
     */
    show: function(modal) {
      if (this.open_) {
        if (modal) {
          throw 'Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.';
        }
        return;  // silently OK if we weren't asked to be shown modally
      }
      if (modal && !dialogPolyfill.dm.pushDialog(this)) {
        throw 'Failed to execute \'showModal\' on dialog: Too many modal dialogs open.';
      }

      this.modal_ = modal;
      this.open_ = true;  // set open_ before attribute for observers
      if (this.dialog_.getAttribute('open') === null) {
        this.dialog_.setAttribute('open', '');  // allow user value of 'open'
      }

      if (modal) {
        // Insert backdrop.
        this.backdrop_.addEventListener('click', this.backdropClick_);
        this.dialog_.parentNode.insertBefore(this.backdrop_,
            this.dialog_.nextSibling);

        // Find element with `autofocus` attribute or first form control.
        var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
        if (!target) {
          // TODO: technically this is 'any focusable area'
          var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
          var query = opts.map(function(el) {
            return el + ':not([disabled])';
          }).join(', ');
          target = this.dialog_.querySelector(query);
        }
        document.activeElement && document.activeElement.blur();
        target && target.focus();
      }

      if (dialogPolyfill.needsCentering(this.dialog_)) {
        dialogPolyfill.reposition(this.dialog_);
        this.replacedStyleTop_ = true;
      } else {
        this.replacedStyleTop_ = false;
      }
    },

    /**
     * Closes this HTMLDialogElement.
     *
     * @param {*=} opt_returnValue to use as the returnValue
     */
    close: function(opt_returnValue) {
      if (!this.open_) {
        throw 'InvalidStateError: close called on closed dialog';
      }
      this.open_ = false;  // set open_ before attribute for observers
      this.dialog_.removeAttribute('open');

      // Leave returnValue untouched in case it was set directly on the element
      if (opt_returnValue !== undefined) {
        this.dialog_.returnValue = opt_returnValue;
      }

      // This won't match the native <dialog> exactly because if the user set
      // top on a centered polyfill dialog, that top gets thrown away when the
      // dialog is closed. Not sure it's possible to polyfill this perfectly.
      if (this.replacedStyleTop_) {
        this.dialog_.style.top = 'auto';
      }

      if (this.modal_) {
{'fraction_non_alphanumeric': 0.12707229533413092, 'fraction_numerical': 0.00017091095539224064, 'mean_word_length': 2.4000581057524695, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1632490', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3438, 'n_words': 894}