(function () {
  var Node = {
    ELEMENT_NODE: 1,
    TEXT_NODE: 3,
    DOCUMENT_FRAGMENT_NODE: 11,
    DOCUMENT_NODE: 9,
  };
  var NodeFilter = { SHOW_TEXT: 4 };
  var VOID_TAGS = { area: 1, base: 1, br: 1, col: 1, embed: 1, hr: 1, img: 1, input: 1, link: 1, meta: 1, source: 1, wbr: 1 };

  function HTMLElement() {}
  function HTMLSelectElement() {}
  HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
  HTMLSelectElement.prototype.constructor = HTMLSelectElement;

  function decodeEntities(text) {
    return text
      .replace(/&lt;/g, "<")
      .replace(/&gt;/g, ">")
      .replace(/&quot;/g, '"')
      .replace(/&#39;/g, "'")
      .replace(/&nbsp;/g, " ")
      .replace(/&amp;/g, "&");
  }

  function encodeText(text) {
    return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  }

  function camelData(name) {
    return name.slice(5).replace(/-([a-z])/g, function (_, c) {
      return c.toUpperCase();
    });
  }

  function dataAttr(key) {
    return "data-" + String(key).replace(/[A-Z]/g, function (c) {
      return "-" + c.toLowerCase();
    });
  }

  function ClassList(el) {
    this._el = el;
  }
  ClassList.prototype._list = function () {
    return (this._el.getAttribute("class") || "").split(/\s+/).filter(Boolean);
  };
  ClassList.prototype._set = function (list) {
    this._el._setAttr("class", list.join(" "));
  };
  ClassList.prototype.add = function () {
    var list = this._list();
    for (var i = 0; i < arguments.length; i++) {
      if (list.indexOf(arguments[i]) < 0) list.push(arguments[i]);
    }
    this._set(list);
  };
  ClassList.prototype.remove = function () {
    var drop = Array.prototype.slice.call(arguments);
    this._set(this._list().filter(function (name) { return drop.indexOf(name) < 0; }));
  };
  ClassList.prototype.contains = function (name) {
    return this._list().indexOf(name) >= 0;
  };
  ClassList.prototype.toggle = function (name, force) {
    var has = this.contains(name);
    var on = force === undefined ? !has : !!force;
    if (on) this.add(name);
    else this.remove(name);
    return on;
  };

  function Style(el) {
    this._el = el;
    this._map = {};
  }
  Style.prototype._sync = function () {
    var parts = [];
    for (var k in this._map) parts.push(k + ": " + this._map[k]);
    this._el._setAttr("style", parts.join("; "));
  };

  function makeStyle(el) {
    var style = new Style(el);
    return new Proxy(style, {
      get: function (target, key) {
        if (key in target || typeof key !== "string") return target[key];
        return target._map[key] || "";
      },
      set: function (target, key, value) {
        if (typeof key === "string" && key[0] !== "_") {
          target._map[key] = String(value);
          target._sync();
          return true;
        }
        target[key] = value;
        return true;
      },
    });
  }

  function makeDataset(el) {
    return new Proxy(el, {
      get: function (_, key) {
        if (key === "hasOwnProperty") return function () { return Object.prototype.hasOwnProperty.apply(this, arguments); };
        var value = el.getAttribute(dataAttr(key));
        return value == null ? undefined : value;
      },
      set: function (_, key, value) {
        el.setAttribute(dataAttr(key), value);
        return true;
      },
      has: function (_, key) {
        return el.hasAttribute(dataAttr(key));
      },
      getOwnPropertyDescriptor: function (_, key) {
        if (!el.hasAttribute(dataAttr(key))) return undefined;
        return { configurable: true, enumerable: true, value: el.getAttribute(dataAttr(key)) };
      },
      ownKeys: function () {
        return el._attrNames().filter(function (name) { return name.indexOf("data-") === 0; }).map(camelData);
      },
    });
  }

  function fire(target, event) {
    var path = [];
    var node = target;
    while (node) {
      path.push(node);
      node = node.parentNode || node.parentElement;
    }
    path.reverse();
    event.target = target;
    for (var i = 0; i < path.length; i++) {
      if (path[i] === target) break;
      dispatchOn(path[i], event, true);
      if (event._stopped) return;
    }
    dispatchOn(target, event, true);
    dispatchOn(target, event, false);
    if (event._stopped || event.bubbles === false) return;
    for (var j = path.length - 2; j >= 0; j--) {
      if (event._stopped) return;
      dispatchOn(path[j], event, false);
    }
  }

  function dispatchOn(node, event, capture) {
    var list = (node.__listeners && node.__listeners[event.type]) || [];
    event.currentTarget = node;
    for (var i = 0; i < list.length; i++) {
      if (!!list[i].capture !== !!capture) continue;
      list[i].fn.call(node, event);
      if (event._stopped) return;
    }
  }

  function EventInit(type, init) {
    this.type = type;
    this.bubbles = !!(init && init.bubbles);
    this.cancelable = !!(init && init.cancelable);
    this.defaultPrevented = false;
    this._stopped = false;
    if (init) {
      for (var k in init) this[k] = init[k];
    }
  }
  EventInit.prototype.preventDefault = function () { this.defaultPrevented = true; };
  EventInit.prototype.stopPropagation = function () { this._stopped = true; };
  var _eventInit = EventInit;
  EventInit = function (type, init) {
    _eventInit.call(this, type, init);
    if (/^drag|drop/.test(type) && !this.dataTransfer) this.dataTransfer = new DataTransfer();
  };
  EventInit.prototype = _eventInit.prototype;

  function DataTransfer() {
    this._data = {};
    this.effectAllowed = "all";
    this.dropEffect = "none";
    this.types = [];
    this.files = [];
  }
  DataTransfer.prototype.setData = function (type, value) {
    if (globalThis.__failSetData) throw new Error("setData failed");
    this._data[type] = String(value);
    if (this.types.indexOf(type) < 0) this.types.push(type);
  };
  DataTransfer.prototype.getData = function (type) {
    if (globalThis.__failGetData) throw new Error("getData failed");
    return this._data[type] || "";
  };

  function baseEvent(type, init) {
    var event = new EventInit(type, init || { bubbles: true });
    if (/^drag|drop/.test(type) && !event.dataTransfer) event.dataTransfer = new DataTransfer();
    return event;
  }

  function nodeProto(nodeType) {
    var node = {
      nodeType: nodeType,
      parentNode: null,
      parentElement: null,
      childNodes: [],
      __listeners: {},
      appendChild: function (child) { return insertChild(this, child, null); },
      insertBefore: function (child, ref) { return insertChild(this, child, ref); },
      removeChild: function (child) {
        var idx = this.childNodes.indexOf(child);
        if (idx >= 0) this.childNodes.splice(idx, 1);
        child.parentNode = null;
        child.parentElement = null;
        return child;
      },
      replaceChild: function (next, prev) {
        var idx = this.childNodes.indexOf(prev);
        if (next.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
          var kids = next.childNodes.slice();
          if (idx < 0) return next;
          this.childNodes.splice(idx, 1);
          prev.parentNode = null;
          prev.parentElement = null;
          var ref = this.childNodes[idx] || null;
          for (var i = 0; i < kids.length; i++) this.insertBefore(kids[i], ref);
          return prev;
        }
        if (idx < 0) return next;
        this.childNodes.splice(idx, 1, next);
        prev.parentNode = null;
        prev.parentElement = null;
        next.parentNode = this;
        next.parentElement = this.nodeType === Node.ELEMENT_NODE ? this : this.parentElement;
        return prev;
      },
      addEventListener: function (type, fn, capture) {
        var list = this.__listeners[type] || (this.__listeners[type] = []);
        list.push({ fn: fn, capture: capture === true || (capture && capture.capture) });
      },
      removeEventListener: function (type, fn) {
        var list = this.__listeners[type] || [];
        this.__listeners[type] = list.filter(function (item) { return item.fn !== fn; });
      },
      dispatchEvent: function (event) {
        fire(this, event);
        return !event.defaultPrevented;
      },
      contains: function (other) {
        var node = other;
        while (node) {
          if (node === this) return true;
          node = node.parentNode;
        }
        return false;
      },
    };
    Object.defineProperty(node, "firstChild", {
      get: function () { return node.childNodes[0] || null; },
    });
    Object.defineProperty(node, "lastChild", {
      get: function () { return node.childNodes[node.childNodes.length - 1] || null; },
    });
    Object.defineProperty(node, "nextSibling", {
      get: function () {
        var parent = node.parentNode;
        if (!parent) return null;
        var index = parent.childNodes.indexOf(node);
        return index >= 0 ? parent.childNodes[index + 1] || null : null;
      },
    });
    Object.defineProperty(node, "previousSibling", {
      get: function () {
        var parent = node.parentNode;
        if (!parent) return null;
        var index = parent.childNodes.indexOf(node);
        return index > 0 ? parent.childNodes[index - 1] : null;
      },
    });
    return node;
  }

  function insertChild(parent, child, ref) {
    if (child.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
      var kids = child.childNodes.slice();
      for (var i = 0; i < kids.length; i++) insertChild(parent, kids[i], ref);
      return child;
    }
    if (child.parentNode) child.parentNode.removeChild(child);
    var idx = ref ? parent.childNodes.indexOf(ref) : parent.childNodes.length;
    if (idx < 0) idx = parent.childNodes.length;
    parent.childNodes.splice(idx, 0, child);
    child.parentNode = parent;
    child.parentElement = parent.nodeType === Node.ELEMENT_NODE ? parent : null;
    return child;
  }

  function createText(text) {
    var node = nodeProto(Node.TEXT_NODE);
    node.textContent = String(text);
    Object.defineProperty(node, "length", { get: function () { return node.textContent.length; } });
    node.cloneNode = function () { return createText(node.textContent); };
    return node;
  }

  function createFragment() {
    var node = nodeProto(Node.DOCUMENT_FRAGMENT_NODE);
    Object.defineProperty(node, "children", { get: function () { return node.childNodes.filter(function (n) { return n.nodeType === Node.ELEMENT_NODE; }); } });
    node.querySelector = function (sel) { return queryAll(node, sel)[0] || null; };
    node.querySelectorAll = function (sel) { return queryAll(node, sel); };
    node.cloneNode = function (deep) {
      var frag = createFragment();
      if (deep) node.childNodes.forEach(function (child) { frag.appendChild(child.cloneNode(true)); });
      return frag;
    };
    node.replaceChildren = function () {
      node.childNodes.splice(0, node.childNodes.length);
      for (var i = 0; i < arguments.length; i++) node.appendChild(arguments[i]);
    };
    return node;
  }

  function createElement(tag) {
    var el = nodeProto(Node.ELEMENT_NODE);
    el.tagName = String(tag || "div").toUpperCase();
    el._attrs = {};
    el.nodeName = el.tagName;
    el.ownerDocument = null;
    el.style = makeStyle(el);
    el.classList = new ClassList(el);
    el.dataset = makeDataset(el);
    el.childNodes = el.childNodes;
    Object.defineProperty(el, "children", { get: function () { return el.childNodes.filter(function (n) { return n.nodeType === Node.ELEMENT_NODE; }); } });
    Object.defineProperty(el, "id", {
      get: function () { return el.getAttribute("id") || ""; },
      set: function (value) { el.setAttribute("id", value); },
    });
    Object.defineProperty(el, "className", {
      get: function () { return el.getAttribute("class") || ""; },
      set: function (value) { el.setAttribute("class", value); },
    });
    Object.defineProperty(el, "textContent", {
      get: function () { return collectText(el); },
      set: function (value) {
        el.childNodes.splice(0, el.childNodes.length);
        if (value != null && value !== "") el.appendChild(createText(value));
      },
    });
    Object.defineProperty(el, "innerHTML", {
      get: function () { return serialize(el); },
      set: function (value) {
        if (el.tagName === "TEMPLATE") {
          el.content = createFragment();
          el.content.ownerDocument = el.ownerDocument;
          parseHTML(el.content, value || "");
        } else {
          el.childNodes.splice(0, el.childNodes.length);
          parseHTML(el, value || "");
        }
      },
    });
    Object.defineProperty(el, "value", {
      get: function () {
        if (el.tagName === "SELECT") return selectedOption(el).value;
        return el._value != null ? el._value : (el.getAttribute("value") || "");
      },
      set: function (value) {
        el._value = String(value);
        if (el.tagName === "SELECT") {
          el.children.forEach(function (opt, index) {
            opt.selected = opt.value === el._value || opt.textContent === el._value;
            if (opt.selected) el._selectedIndex = index;
          });
        }
      },
    });
    Object.defineProperty(el, "selectedIndex", {
      get: function () {
        var opts = el.children.filter(function (n) { return n.tagName === "OPTION"; });
        for (var i = 0; i < opts.length; i++) if (opts[i].selected) return i;
        return opts.length ? 0 : -1;
      },
    });
    Object.defineProperty(el, "options", {
      get: function () { return el.children.filter(function (n) { return n.tagName === "OPTION"; }); },
    });
    Object.defineProperty(el, "parentElement", {
      get: function () {
        var parent = el.parentNode;
        return parent && parent.nodeType === Node.ELEMENT_NODE ? parent : null;
      },
      set: function (value) { el.parentNode = value; },
    });
    el.checked = false;
    el.disabled = false;
    el.selected = false;
    el.open = false;
    el.hidden = false;
    el.draggable = false;
    el.files = [];
    el.selectionStart = 0;
    el.rows = 0;
    el.placeholder = "";
    el.type = "";
    el.width = 0;
    el.height = 0;
    el.alt = "";
    el._setAttr = function (name, value) { el._attrs[name] = String(value); };
    ["href", "src", "title"].forEach(function (name) {
      Object.defineProperty(el, name, {
        configurable: true,
        get: function () {
          var value = el.getAttribute(name);
          return value == null ? "" : value;
        },
        set: function (value) { el._setAttr(name, value == null ? "" : value); },
      });
    });
    if (el.tagName === "OPTION") {
      Object.defineProperty(el, "text", {
        get: function () { return el.textContent; },
        set: function (value) { el.textContent = value == null ? "" : String(value); },
      });
    }
    el._attrNames = function () { return Object.keys(el._attrs); };
    el.getAttribute = function (name) {
      var key = String(name).toLowerCase();
      return Object.prototype.hasOwnProperty.call(el._attrs, key) ? el._attrs[key] : null;
    };
    el.setAttribute = function (name, value) {
      var key = String(name).toLowerCase();
      el._attrs[key] = String(value);
      if (key === "value" && el._value == null) el._value = String(value);
      if (key === "type") el.type = String(value);
      if (key === "draggable") el.draggable = String(value) === "true";
      if (key === "disabled") el.disabled = true;
      if (key === "checked") el.checked = true;
      if (key === "open") el.open = true;
      if (key === "hidden") el.hidden = true;
      if (key === "selected") el.selected = true;
    };
    el.hasAttribute = function (name) { return el.getAttribute(name) != null; };
    el.removeAttribute = function (name) { delete el._attrs[String(name).toLowerCase()]; };
    el.querySelector = function (sel) { return queryAll(el, sel)[0] || null; };
    el.querySelectorAll = function (sel) { return queryAll(el, sel); };
    el.closest = function (sel) {
      var node = el;
      while (node && node.nodeType === Node.ELEMENT_NODE) {
        if (elementMatches(node, sel)) return node;
        node = node.parentElement;
      }
      return null;
    };
    el.matches = function (sel) { return elementMatches(el, sel); };
    el.remove = function () { if (el.parentNode) el.parentNode.removeChild(el); };
    el.replaceChildren = function () {
      while (el.childNodes.length) el.removeChild(el.childNodes[0]);
      for (var i = 0; i < arguments.length; i++) el.appendChild(arguments[i]);
    };
    el.cloneNode = function (deep) {
      var copy = createElement(el.tagName);
      copy.ownerDocument = el.ownerDocument;
      el._attrNames().forEach(function (name) { copy.setAttribute(name, el.getAttribute(name)); });
      copy._value = el._value;
      copy.checked = el.checked;
      copy.selected = el.selected;
      copy.disabled = el.disabled;
      copy.open = el.open;
      copy.hidden = el.hidden;
      copy.draggable = el.draggable;
      copy.type = el.type;
      if (el.tagName === "TEMPLATE") {
        copy.content = el.content.cloneNode(!!deep);
      } else if (deep) {
        el.childNodes.forEach(function (child) { copy.appendChild(child.cloneNode(true)); });
      }
      return copy;
    };
    el.click = function () { el.dispatchEvent(baseEvent("click", { bubbles: true })); };
    el.focus = function () {
      if (el.ownerDocument) el.ownerDocument.activeElement = el;
      el.dispatchEvent(baseEvent("focus", { bubbles: false }));
    };
    el.blur = function () { el.dispatchEvent(baseEvent("blur", { bubbles: false })); };
    el.select = function () { el.selectionStart = 0; };
    el.setSelectionRange = function (start) { el.selectionStart = start; };
    el.getBoundingClientRect = function () {
      var top = el._rectTop != null ? el._rectTop : 20;
      return { x: 0, y: top, left: 10, top: top, right: 210, bottom: top + 40, width: 200, height: 40 };
    };
    el.scrollIntoView = function () { globalThis.__lastScrolled = el; };
    if (el.tagName === "TEMPLATE") el.content = createFragment();
    if (el.tagName === "SELECT") Object.setPrototypeOf(el, HTMLSelectElement.prototype);
    return el;
  }

  function selectedOption(el) {
    var opts = el.options;
    function optionValue(opt) {
      if (opt._value != null) return String(opt._value);
      var attr = opt.getAttribute("value");
      return attr != null ? attr : opt.textContent;
    }
    for (var i = 0; i < opts.length; i++) if (opts[i].selected) return { value: optionValue(opts[i]), index: i };
    if (opts.length) return { value: optionValue(opts[0]), index: 0 };
    return { value: "", index: -1 };
  }

  function collectText(node) {
    if (node.nodeType === Node.TEXT_NODE) return node.textContent;
    return node.childNodes.map(collectText).join("");
  }

  function serialize(node) {
    return node.childNodes.map(function (child) {
      if (child.nodeType === Node.TEXT_NODE) return encodeText(child.textContent);
      var attrs = child._attrNames().map(function (name) {
        return " " + name + '="' + encodeText(child.getAttribute(name)) + '"';
      }).join("");
      if (VOID_TAGS[child.tagName.toLowerCase()]) return "<" + child.tagName.toLowerCase() + attrs + ">";
      return "<" + child.tagName.toLowerCase() + attrs + ">" + serialize(child) + "</" + child.tagName.toLowerCase() + ">";
    }).join("");
  }

  function parseHTML(parent, html) {
    var i = 0;
    function parse(stop) {
      while (i < html.length) {
        if (html.charAt(i) !== "<") {
          var next = html.indexOf("<", i);
          if (next < 0) next = html.length;
          var text = decodeEntities(html.slice(i, next));
          if (text) parentAppend(parent, createText(text));
          i = next;
          continue;
        }
        if (html.slice(i, i + 4) === "<!--") {
          i = html.indexOf("-->", i) + 3;
          continue;
        }
        if (html.slice(i, i + 2) === "</") {
          var closeEnd = html.indexOf(">", i);
          var closeName = html.slice(i + 2, closeEnd).trim().toLowerCase();
          i = closeEnd + 1;
          if (!stop || closeName === stop) return;
          continue;
        }
        var tagEnd = html.indexOf(">", i);
        var raw = html.slice(i + 1, tagEnd).trim();
        i = tagEnd + 1;
        var selfClose = /\/$/.test(raw);
        if (selfClose) raw = raw.slice(0, -1).trim();
        var bits = raw.match(/[^\s"'=]+(?:=(?:"[^"]*"|'[^']*'|[^\s"']+))?/g) || [];
        var tag = bits.shift().toLowerCase();
        var el = createElement(tag);
        el.ownerDocument = parent.ownerDocument || parent;
        bits.forEach(function (bit) { applyAttr(el, bit); });
        parentAppend(parent, el);
        if (!selfClose && !VOID_TAGS[tag]) {
          var saved = parent;
          parent = tag === "template" ? el.content : el;
          if (tag === "template") el.content.ownerDocument = el.ownerDocument;
          parse(tag);
          parent = saved;
        }
      }
    }
    parse(null);
  }

  function parentAppend(parent, child) {
    parent.appendChild(child);
  }

  function applyAttr(el, bit) {
    var eq = bit.indexOf("=");
    if (eq < 0) {
      el.setAttribute(bit, "");
      return;
    }
    var name = bit.slice(0, eq);
    var value = bit.slice(eq + 1);
    if ((value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') || (value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
      value = value.slice(1, -1);
    }
    el.setAttribute(name, decodeEntities(value));
  }

  function splitCommas(selector) {
    var parts = [];
    var buf = "";
    var depth = 0;
    for (var i = 0; i < selector.length; i++) {
      var c = selector.charAt(i);
      if (c === "[") depth++;
      else if (c === "]") depth--;
      else if (c === "," && depth === 0) {
        parts.push(buf);
        buf = "";
        continue;
      }
      buf += c;
    }
    if (buf.trim()) parts.push(buf);
    return parts;
  }

  function tokenize(selector) {
    var raw = [];
    var buf = "";
    var depth = 0;
    for (var i = 0; i < selector.length; i++) {
      var c = selector.charAt(i);
      if (c === "[") depth++;
      else if (c === "]") depth--;
      if (depth === 0 && (c === " " || c === ">")) {
        if (buf.trim()) raw.push(buf.trim());
        buf = "";
        if (c === ">") raw.push(">");
        continue;
      }
      buf += c;
    }
    if (buf.trim()) raw.push(buf.trim());
    var steps = [];
    var rel = "desc";
    raw.forEach(function (part) {
      if (part === ">") {
        rel = ">";
        return;
      }
      steps.push({ rel: rel, compound: part });
      rel = "desc";
    });
    return steps;
  }

  function matchesCompound(el, compound) {
    if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
    var rest = compound.trim();
    var tag = rest.match(/^[A-Za-z*][A-Za-z0-9-]*/);
    if (tag) {
      if (tag[0] !== "*" && el.tagName.toLowerCase() !== tag[0].toLowerCase()) return false;
      rest = rest.slice(tag[0].length);
    }
    if (rest.indexOf(":last-child") >= 0 || rest.indexOf(":first-child") >= 0) {
      var elementSiblings = ((el.parentNode && el.parentNode.childNodes) || []).filter(function (child) {
        return child.nodeType === Node.ELEMENT_NODE;
      });
      if (rest.indexOf(":last-child") >= 0 && elementSiblings[elementSiblings.length - 1] !== el) return false;
      if (rest.indexOf(":first-child") >= 0 && elementSiblings[0] !== el) return false;
      rest = rest.replace(/:(?:last|first)-child/g, "");
    }
    var parts = rest.match(/(\.[A-Za-z0-9_-]+|#[A-Za-z0-9_-]+|\[[^\]]+\])/g) || [];
    if (!tag && rest.replace(/(\.[A-Za-z0-9_-]+|#[A-Za-z0-9_-]+|\[[^\]]+\])/g, "")) return false;
    for (var i = 0; i < parts.length; i++) {
      var part = parts[i];
      if (part.charAt(0) === ".") {
        if (!el.classList.contains(part.slice(1))) return false;
      } else if (part.charAt(0) === "#") {
        if (el.id !== part.slice(1)) return false;
      } else {
        var inner = part.slice(1, -1);
        function unquote(value) {
          if ((value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') || (value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
            return value.slice(1, -1);
          }
          return value;
        }
        var star = inner.indexOf("*=");
        var caret = inner.indexOf("^=");
        var dollar = inner.indexOf("$=");
        var eq = inner.indexOf("=");
        if (star >= 0 || caret >= 0 || dollar >= 0) {
          var at = star >= 0 ? star : caret >= 0 ? caret : dollar;
          var kind = inner.charAt(at);
          var actual = el.getAttribute(inner.slice(0, at).trim()) || "";
          var expected = unquote(inner.slice(at + 2).trim());
          if (kind === "*" && actual.indexOf(expected) < 0) return false;
          if (kind === "^" && actual.indexOf(expected) !== 0) return false;
          if (kind === "$" && (expected === "" || actual.slice(-expected.length) !== expected)) return false;
        } else if (eq < 0) {
          if (!el.hasAttribute(inner.trim())) return false;
        } else if (el.getAttribute(inner.slice(0, eq).trim()) !== unquote(inner.slice(eq + 1).trim())) {
          return false;
        }
      }
    }
    return true;
  }

  function elementMatches(el, selector) {
    return splitCommas(selector).some(function (alt) {
      var steps = tokenize(alt);
      if (!steps.length || !matchesCompound(el, steps[steps.length - 1].compound)) return false;
      var node = el;
      for (var i = steps.length - 2; i >= 0; i--) {
        var rel = steps[i + 1].rel;
        if (rel === ">") {
          node = node.parentElement;
          if (!node || !matchesCompound(node, steps[i].compound)) return false;
        } else {
          node = node.parentElement;
          var found = false;
          while (node) {
            if (matchesCompound(node, steps[i].compound)) { found = true; break; }
            node = node.parentElement;
          }
          if (!found) return false;
        }
      }
      return true;
    });
  }

  function descendants(scope) {
    var out = [];
    function walk(node) {
      var kids = node.tagName === "TEMPLATE" ? [] : (node.children || node.childNodes || []);
      for (var i = 0; i < kids.length; i++) {
        if (kids[i].nodeType && kids[i].nodeType !== Node.ELEMENT_NODE) continue;
        out.push(kids[i]);
        walk(kids[i]);
      }
    }
    if (scope.nodeType === Node.DOCUMENT_NODE) {
      if (scope.documentElement) {
        out.push(scope.documentElement);
        walk(scope.documentElement);
      }
      return out;
    }
    walk(scope);
    return out;
  }

  function queryAll(scope, selector) {
    var found = [];
    splitCommas(selector).forEach(function (alt) {
      var steps = tokenize(alt);
      if (!steps.length) return;
      var nodes = descendants(scope).filter(function (el) { return matchesCompound(el, steps[0].compound); });
      for (var s = 1; s < steps.length; s++) {
        var next = [];
        nodes.forEach(function (el) {
          var pool = steps[s].rel === ">" ? el.children : descendants(el);
          pool.forEach(function (child) {
            if (matchesCompound(child, steps[s].compound)) next.push(child);
          });
        });
        nodes = next;
      }
      nodes.forEach(function (el) {
        if (found.indexOf(el) < 0) found.push(el);
      });
    });
    return found;
  }

  function createDocument() {
    var doc = nodeProto(Node.DOCUMENT_NODE);
    doc.nodeType = Node.DOCUMENT_NODE;
    doc.readyState = "complete";
    doc.activeElement = null;
    doc.documentElement = createElement("html");
    doc.head = createElement("head");
    doc.body = createElement("body");
    doc.documentElement.ownerDocument = doc;
    doc.head.ownerDocument = doc;
    doc.body.ownerDocument = doc;
    doc.documentElement.appendChild(doc.head);
    doc.documentElement.appendChild(doc.body);
    doc.documentElement.parentNode = doc;
    doc.createElement = function (tag) {
      var el = createElement(tag);
      el.ownerDocument = doc;
      if (el.content) el.content.ownerDocument = doc;
      return el;
    };
    doc.createTextNode = createText;
    doc.createDocumentFragment = createFragment;
    doc.createTreeWalker = function (root, what) {
      var nodes = [];
      function walk(node) {
        node.childNodes.forEach(function (child) {
          if (child.nodeType === Node.TEXT_NODE && (what & NodeFilter.SHOW_TEXT)) nodes.push(child);
          if (child.nodeType === Node.ELEMENT_NODE) walk(child);
        });
      }
      walk(root);
      var index = 0;
      return { nextNode: function () { return index < nodes.length ? nodes[index++] : null; }, currentNode: null };
    };
    doc.createRange = function () {
      var range = { _start: null, _end: null, _so: 0, _eo: 0 };
      range.setStart = function (node, off) { range._start = node; range._so = off; };
      range.setEnd = function (node, off) { range._end = node; range._eo = off; };
      range.surroundContents = function (span) {
        if (!range._start || range._start !== range._end || range._start.nodeType !== Node.TEXT_NODE) {
          throw new Error("InvalidStateError");
        }
        var text = range._start.textContent;
        var before = text.slice(0, range._so);
        var mid = text.slice(range._so, range._eo);
        var after = text.slice(range._eo);
        var parent = range._start.parentNode;
        var midNode = createText(mid);
        span.appendChild(midNode);
        if (before) parent.insertBefore(createText(before), range._start);
        parent.insertBefore(span, range._start);
        if (after) parent.insertBefore(createText(after), range._start);
        parent.removeChild(range._start);
      };
      return range;
    };
    doc.getElementById = function (id) {
      var all = descendants(doc);
      for (var i = 0; i < all.length; i++) if (all[i].id === id) return all[i];
      return null;
    };
    doc.querySelector = function (sel) { return queryAll(doc, sel)[0] || null; };
    doc.querySelectorAll = function (sel) { return queryAll(doc, sel); };
    return doc;
  }

  function AbortSignal() {
    this.aborted = false;
    this.__listeners = {};
    this.addEventListener = function (type, fn) {
      (this.__listeners[type] || (this.__listeners[type] = [])).push({ fn: fn, capture: false });
    };
  }
  function AbortController() {
    this.signal = new AbortSignal();
  }
  AbortController.prototype.abort = function () {
    if (this.signal.aborted) return;
    this.signal.aborted = true;
    fire(this.signal, baseEvent("abort", { bubbles: false }));
    (globalThis.__pending || []).slice().forEach(function (item) {
      if (item.signal === this.signal) item.reject(abortError());
    }, this);
  };
  function abortError() {
    var err = new Error("The operation was aborted");
    err.name = "AbortError";
    return err;
  }

  function responseOf(spec) {
    var body = spec.text != null ? spec.text : (spec.json != null ? JSON.stringify(spec.json) : "");
    return {
      ok: spec.status >= 200 && spec.status < 300,
      status: spec.status,
      statusText: spec.statusText || "",
      json: function () {
        if (spec.jsonError) return Promise.reject(new Error("invalid json"));
        return Promise.resolve(spec.json != null ? spec.json : JSON.parse(body || "null"));
      },
      text: function () { return Promise.resolve(body); },
    };
  }

  function matchRoute(url) {
    var routes = globalThis.__routes || [];
    var found = null;
    for (var i = 0; i < routes.length; i++) {
      if (url.indexOf(routes[i].url) >= 0) found = routes[i];
    }
    return found;
  }

  var document = createDocument();
  var location = {
    href: "http://127.0.0.1/",
    origin: "http://127.0.0.1",
    pathname: "/",
    search: "",
    hash: "",
    assign: function (url) { globalThis.__assigned = String(url); setLocation(url); },
    reload: function () { globalThis.__reloaded = true; },
  };
  Object.defineProperty(location, "hash", {
    get: function () { return location._hash || ""; },
    set: function (value) {
      var next = String(value || "");
      if (next && next.charAt(0) !== "#") next = "#" + next;
      location._hash = next;
      location.href = location.origin + location.pathname + location.search + next;
    },
  });
  function setLocation(url) {
    var abs = String(url);
    if (abs.charAt(0) === "/") abs = "http://127.0.0.1" + abs;
    if (abs.charAt(0) === "#") abs = location.origin + location.pathname + location.search + abs;
    var hash = "";
    var hashAt = abs.indexOf("#");
    if (hashAt >= 0) { hash = abs.slice(hashAt); abs = abs.slice(0, hashAt); }
    var q = abs.indexOf("?");
    var path = q >= 0 ? abs.slice(0, q) : abs;
    var search = q >= 0 ? abs.slice(q) : "";
    var origin = "http://127.0.0.1";
    var proto = path.indexOf("://");
    if (proto >= 0) {
      var slash = path.indexOf("/", proto + 3);
      origin = slash >= 0 ? path.slice(0, slash) : path;
      path = slash >= 0 ? path.slice(slash) : "/";
    }
    location.href = origin + path + search + hash;
    location.origin = origin;
    location.pathname = path || "/";
    location.search = search;
    location.hash = hash;
  }

  function encodeQuery(value) {
    return encodeURIComponent(String(value)).replace(/%20/g, "+");
  }
  function decodeQuery(value) {
    return decodeURIComponent(String(value).replace(/\+/g, " "));
  }
  function queryIterator(items) {
    var i = 0;
    var iter = {
      next: function () {
        if (i >= items.length) return { done: true };
        return { done: false, value: items[i++] };
      },
    };
    iter[Symbol.iterator] = function () { return this; };
    return iter;
  }
  function URLSearchParams(init) {
    this._pairs = [];
    if (init == null || init === "") return;
    if (typeof init === "string") {
      var raw = init.charAt(0) === "?" ? init.slice(1) : init;
      if (!raw) return;
      var parts = raw.split("&");
      for (var i = 0; i < parts.length; i++) {
        if (!parts[i]) continue;
        var eq = parts[i].indexOf("=");
        var key = eq >= 0 ? parts[i].slice(0, eq) : parts[i];
        var val = eq >= 0 ? parts[i].slice(eq + 1) : "";
        this._pairs.push([decodeQuery(key), decodeQuery(val)]);
      }
      return;
    }
    if (init instanceof URLSearchParams) {
      this._pairs = init._pairs.map(function (pair) { return pair.slice(); });
      return;
    }
    if (typeof init === "object") {
      for (var name in init) {
        if (Object.prototype.hasOwnProperty.call(init, name)) this._pairs.push([String(name), String(init[name])]);
      }
    }
  }
  URLSearchParams.prototype.append = function (name, value) {
    this._pairs.push([String(name), String(value)]);
  };
  URLSearchParams.prototype.set = function (name, value) {
    name = String(name);
    value = String(value);
    var replaced = false;
    var next = [];
    for (var i = 0; i < this._pairs.length; i++) {
      if (this._pairs[i][0] !== name) next.push(this._pairs[i]);
      else if (!replaced) {
        next.push([name, value]);
        replaced = true;
      }
    }
    if (!replaced) next.push([name, value]);
    this._pairs = next;
  };
  URLSearchParams.prototype.get = function (name) {
    name = String(name);
    for (var i = 0; i < this._pairs.length; i++) {
      if (this._pairs[i][0] === name) return this._pairs[i][1];
    }
    return null;
  };
  URLSearchParams.prototype.has = function (name) {
    return this.get(name) !== null;
  };
  URLSearchParams.prototype.delete = function (name) {
    name = String(name);
    this._pairs = this._pairs.filter(function (pair) { return pair[0] !== name; });
  };
  URLSearchParams.prototype.toString = function () {
    return this._pairs.map(function (pair) {
      return encodeQuery(pair[0]) + "=" + encodeQuery(pair[1]);
    }).join("&");
  };
  URLSearchParams.prototype.keys = function () {
    return queryIterator(this._pairs.map(function (pair) { return pair[0]; }));
  };
  URLSearchParams.prototype.entries = function () {
    return queryIterator(this._pairs.map(function (pair) { return pair.slice(); }));
  };
  URLSearchParams.prototype[Symbol.iterator] = function () { return this.entries(); };

  function URL(href) {
    this._parse(String(href));
  }
  URL.prototype._parse = function (abs) {
    var hash = "";
    var hashAt = abs.indexOf("#");
    if (hashAt >= 0) {
      hash = abs.slice(hashAt);
      abs = abs.slice(0, hashAt);
    }
    var q = abs.indexOf("?");
    var path = q >= 0 ? abs.slice(0, q) : abs;
    var search = q >= 0 ? abs.slice(q) : "";
    var origin = "";
    var proto = path.indexOf("://");
    if (proto >= 0) {
      var slash = path.indexOf("/", proto + 3);
      origin = slash >= 0 ? path.slice(0, slash) : path;
      path = slash >= 0 ? path.slice(slash) : "/";
    }
    this.origin = origin;
    this.pathname = path || "/";
    this.search = search;
    this.hash = hash;
    this.href = origin + this.pathname + search + hash;
    this._params = null;
  };
  URL.prototype.toString = function () { return this.href; };
  Object.defineProperty(URL.prototype, "searchParams", {
    get: function () {
      if (this._params) return this._params;
      var self = this;
      var params = new URLSearchParams(this.search);
      function sync() {
        var query = params.toString();
        self.search = query ? "?" + query : "";
        self.href = self.origin + self.pathname + self.search + (self.hash || "");
      }
      ["append", "set", "delete"].forEach(function (method) {
        var original = params[method];
        params[method] = function () {
          var result = original.apply(params, arguments);
          sync();
          return result;
        };
      });
      this._params = params;
      return params;
    },
  });

  if (typeof globalThis.URLSearchParams !== "function") globalThis.URLSearchParams = URLSearchParams;
  if (typeof globalThis.URL !== "function") globalThis.URL = URL;

  globalThis.Node = Node;
  globalThis.NodeFilter = NodeFilter;
  globalThis.HTMLElement = HTMLElement;
  globalThis.HTMLSelectElement = HTMLSelectElement;
  globalThis.Event = EventInit;
  globalThis.DataTransfer = DataTransfer;
  globalThis.AbortController = AbortController;
  globalThis.document = document;
  globalThis.window = globalThis;
  globalThis.__listeners = {};
  globalThis.addEventListener = function (type, fn, capture) {
    var list = globalThis.__listeners[type] || (globalThis.__listeners[type] = []);
    list.push({ fn: fn, capture: capture === true || (capture && capture.capture) });
  };
  globalThis.removeEventListener = function (type, fn) {
    var list = globalThis.__listeners[type] || [];
    globalThis.__listeners[type] = list.filter(function (item) { return item.fn !== fn; });
  };
  globalThis.dispatchEvent = function (event) {
    fire(globalThis, event);
    return !event.defaultPrevented;
  };
  globalThis.location = location;
  globalThis.history = { replaceState: function (_s, _t, url) { if (url != null) setLocation(url); } };
  globalThis.navigator = { clipboard: { writeText: function (text) { globalThis.__copied = text; return Promise.resolve(); } } };
  globalThis.scrollX = 0;
  globalThis.scrollY = 0;
  globalThis.__alerts = [];
  globalThis.__confirms = [];
  globalThis.__confirmYes = true;
  globalThis.__routes = [];
  globalThis.__pending = [];
  globalThis.__timers = [];
  globalThis.__raf = [];
  globalThis.__loaded = {};
  globalThis.__moduleCache = {};
  globalThis.__factories = {};
  globalThis.__preloaded = [];
  globalThis.__requests = [];
  globalThis.alert = function (msg) { globalThis.__alerts.push(String(msg)); };
  globalThis.confirm = function (msg) { globalThis.__confirms.push(String(msg)); return !!globalThis.__confirmYes; };
  globalThis.Image = function () {
    this.src = "";
    var img = this;
    Object.defineProperty(this, "src", {
      set: function (value) { img._src = String(value); globalThis.__preloaded.push(img._src); },
      get: function () { return img._src || ""; },
    });
  };
  globalThis.setTimeout = function (fn) {
    var id = globalThis.__timers.length + 1;
    globalThis.__timers.push({ id: id, fn: fn });
    return id;
  };
  globalThis.clearTimeout = function (id) {
    globalThis.__timers = globalThis.__timers.filter(function (item) { return item.id !== id; });
  };
  globalThis.requestAnimationFrame = function (fn) {
    globalThis.__raf.push(fn);
    return globalThis.__raf.length;
  };
  globalThis.fetch = function (url, opts) {
    opts = opts || {};
    globalThis.__requests.push({
      url: String(url),
      method: (opts && opts.method) || "GET",
      body: opts && opts.body != null ? String(opts.body) : null,
    });
    if (opts.signal && opts.signal.aborted) return Promise.reject(abortError());
    var spec = matchRoute(String(url));
    if (spec && spec.reject) return Promise.reject(new Error(String(spec.reject)));
    if (!spec || spec.hang) {
      return new Promise(function (resolve, reject) {
        var item = { url: String(url), resolve: resolve, reject: reject, signal: opts.signal };
        globalThis.__pending.push(item);
        if (opts.signal) {
          opts.signal.addEventListener("abort", function () { reject(abortError()); });
        }
      });
    }
    return Promise.resolve(responseOf(spec));
  };
  globalThis.__setHtml = function (html) {
    document.body.innerHTML = html;
  };
  globalThis.__setLocation = setLocation;
  globalThis.__tick = function () {
    var guard = 0;
    while ((globalThis.__timers.length || globalThis.__raf.length) && guard++ < 1000) {
      var timers = globalThis.__timers.splice(0, globalThis.__timers.length);
      var raf = globalThis.__raf.splice(0, globalThis.__raf.length);
      timers.forEach(function (item) { item.fn(); });
      raf.forEach(function (fn) { fn(); });
    }
  };
  globalThis.__fulfill = function (urlPart, spec) {
    var rest = [];
    globalThis.__pending.forEach(function (item) {
      if (item.url.indexOf(urlPart) >= 0) item.resolve(responseOf(spec));
      else rest.push(item);
    });
    globalThis.__pending = rest;
  };
  globalThis.__register = function (name, factory) { globalThis.__factories[name] = factory; };
  globalThis.__require = function (fromFile, spec) {
    var base = fromFile.split("/");
    base.pop();
    spec.split("/").forEach(function (part) {
      if (part === "." || part === "") return;
      base.push(part);
    });
    var name = base.join("/");
    if (globalThis.__moduleCache[name]) return globalThis.__moduleCache[name];
    var factory = globalThis.__factories[name];
    if (!factory) throw new Error("Unknown module " + name);
    var exports = {};
    globalThis.__moduleCache[name] = exports;
    factory(function (next) { return globalThis.__require(name, next); }, exports);
    globalThis.__loaded[name] = exports;
    return exports;
  };
  globalThis.__load = function (name) {
    return globalThis.__require("", "./" + name);
  };
  globalThis.__reset = function () {
    globalThis.__moduleCache = {};
    globalThis.__loaded = {};
    globalThis.__routes = [];
    globalThis.__pending = [];
    globalThis.__timers = [];
    globalThis.__raf = [];
    globalThis.__alerts = [];
    globalThis.__confirms = [];
    globalThis.__confirmYes = true;
    globalThis.__reloaded = false;
    globalThis.__assigned = null;
    globalThis.__copied = null;
    globalThis.__lastScrolled = null;
    globalThis.__preloaded = [];
    globalThis.__requests = [];
    globalThis.__listeners = {};
    delete globalThis.hljs;
    delete globalThis.Diff2HtmlUI;
    globalThis.__failSetData = false;
    globalThis.__failGetData = false;
    globalThis.atob = globalThis.__builtinAtob;
    globalThis.TextDecoder = globalThis.__builtinTextDecoder;
    globalThis.scrollX = 0;
    globalThis.scrollY = 0;
    document = createDocument();
    globalThis.document = document;
    document.__listeners = {};
    setLocation("http://127.0.0.1/");
    if (typeof showdown !== "undefined") globalThis.showdown = showdown;
  };

  if (typeof atob === "undefined") {
    globalThis.atob = function (value) {
      var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
      var str = String(value).replace(/=+$/, "");
      var out = "";
      var buffer = 0;
      var bits = 0;
      for (var i = 0; i < str.length; i++) {
        var idx = chars.indexOf(str.charAt(i));
        if (idx < 0) throw new Error("Invalid character");
        buffer = (buffer << 6) | idx;
        bits += 6;
        if (bits >= 8) {
          bits -= 8;
          out += String.fromCharCode((buffer >> bits) & 255);
        }
      }
      return out;
    };
  }
  (function () {
    var nativeAtob = globalThis.atob;
    globalThis.atob = function (value) {
      var str = String(value).replace(/[\t\n\f\r ]/g, "");
      if (/[^A-Za-z0-9+/=]/.test(str)) throw new Error("Invalid character");
      return nativeAtob(str);
    };
  })();
  if (typeof TextDecoder !== "function") {
    function Utf8Decoder() {}
    Utf8Decoder.prototype.decode = function (bytes) {
      var out = "";
      var i = 0;
      var list = bytes || [];
      while (i < list.length) {
        var c = list[i++];
        if (c < 128) {
          out += String.fromCharCode(c);
        } else if (c < 224) {
          out += String.fromCharCode(((c & 31) << 6) | (list[i++] & 63));
        } else if (c < 240) {
          out += String.fromCharCode(((c & 15) << 12) | ((list[i++] & 63) << 6) | (list[i++] & 63));
        } else {
          var point = ((c & 7) << 18) | ((list[i++] & 63) << 12) | ((list[i++] & 63) << 6) | (list[i++] & 63);
          point -= 65536;
          out += String.fromCharCode(55296 + (point >> 10), 56320 + (point & 1023));
        }
      }
      return out;
    };
    globalThis.TextDecoder = Utf8Decoder;
  }
  globalThis.__builtinAtob = globalThis.atob;
  globalThis.__builtinTextDecoder = globalThis.TextDecoder;
})();