if (!Element.prototype.matches) {
  Element.prototype.matches =
  // @ts-ignore
    Element.prototype.msMatchesSelector ||
    Element.prototype.webkitMatchesSelector;
}

if (!Element.prototype.closest) {
  Element.prototype.closest = function (s: any) {
    var el: Element | null = this;
    if (!document.documentElement.contains(el)) {
      return null;
    }

    do {
      if (el.matches(s)) {
        return el;
      }
      el = el.parentElement;
    } while (el !== null);
    return null;
  };
}
